Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .claude/skills/implement-feature/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ extension MyModel: AffordanceProviding {

Every `registerRoute(...)` call must be reachable from `RESTPathResolver.ensureInitialized()`. Add `_ = _yourRoutes` there. Forgetting this means `_links` silently resolves to `[:]` because the route table is empty when the protocol's `apiLinks` derivation runs in tests / fresh process state.

A child that is addressed under its parent by **both** ids (an App Compliance requirement id is the same on every app, so its row is `/iris/apps/:appId/compliance-requirements/:requirementId`) registers with `registerRoute(command:parentParam:parentSegment:segment:nestedResourceParam:)`.

### 3. Every domain model must

```swift
Expand Down Expand Up @@ -174,6 +176,8 @@ public func getAvailability(iapId: String) async throws -> ASCKit.InAppPurchaseA
}
```

**Fixtures are captured responses, never shapes guessed at** — including the empty case. Private services (iris, `ppm`) leave out empty values: an App Compliance app with no declarations answered `{}`, not `{"data": []}`, and a guessed `{"data": []}` fixture let that past every test. Record the captured shape in the feature's design doc and copy fixtures from there.

**Test these with `StubAPIClient.willReturn(_:)` once per response type.** The stub keys responses by `String(describing: T.self)`, so each `willReturn` for a different response type queues up the next call's return value. Adding a regression test that returns 175 entries proves pagination works.

---
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `asc iris app-compliance list` and `declare` answer an app's App Compliance page (China mainland Security Assessment, AI generated content), No or Yes with its evidence, over CLI and REST. → [docs](docs/features/app-compliance/README.md)

### Changed
- `asc versions submit` and `POST /api/v1/versions/:id/submit` refuse a version that can't be edited (e.g. Ready for Sale) before calling Apple, saying which states can go to review.
- **Breaking (library):** one `ASCKit` module (`import ASCKit`); 7 non-CRUD repositories take role names (`IrisAuthRepository` → `IrisSignIn`, …); `SubmissionRepository.submitVersion` → `AppStoreVersion.submitForReview(to:)`. → [design](docs/features/concept-folders/design.md)
Expand Down
4 changes: 4 additions & 0 deletions Sources/ASCCommand/ClientProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ struct ClientProvider {
ClientFactory().makeIrisResolutionCenterRepository()
}

static func makeIrisComplianceRepository() -> any IrisComplianceRepository {
ClientFactory().makeIrisComplianceRepository()
}

static func makeIrisCookieProvider() -> any IrisCookieProvider {
ClientFactory().makeIrisCookieProvider()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ArgumentParser
import ASCKit

/// `asc iris app-compliance` — the app's App Compliance page (China mainland Security
/// Assessment, AI generated content). Iris private API only: there is no public endpoint.
struct IrisAppComplianceCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "app-compliance",
abstract: "List and answer an app's App Compliance requirements (iris session)",
subcommands: [IrisAppComplianceList.self, IrisAppComplianceDeclare.self]
)
}

/// The Yes or No a developer gives on the command line or in a REST body.
enum DeclaredAnswerArgument: String, ExpressibleByArgument, CaseIterable {
case yes
case no

/// The answer for a requirement of `kind`: a No as it is, a Yes with that kind's evidence.
func answer(for kind: ComplianceKind, evidence: ComplianceEvidenceInput) throws -> ComplianceAnswer {
switch self {
case .no: return .notOffered
case .yes: return try ComplianceAnswer.offered(for: kind, evidence: evidence)
}
}
}

extension AIGCFiling.FilingType: ExpressibleByArgument {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import ArgumentParser
import Foundation
import ASCKit

struct IrisAppComplianceDeclare: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "declare",
abstract: "Answer an App Compliance requirement",
discussion: """
--answer no declares the app doesn't offer the regulated feature in the region (or it is \
disabled or geoblocked there). --answer yes sends the requirement's evidence:
Security Assessment: --proof <file> --report <file>
AI Generated or Synthetic Content: --filing-type llm|algorithm --filing-name <name> \
--filing-number <number> [--third-party-authorization <file> when third-party technology powers it]
Files are .doc, .docx, .jpeg, .jpg, .pdf or .png.
"""
)

@OptionGroup var globals: GlobalOptions

@Option(name: .long, help: "App ID")
var appId: String

@Option(name: .long, help: "Requirement ID, from `asc iris app-compliance list`")
var requirementId: String

@Option(name: .long, help: "yes or no")
var answer: DeclaredAnswerArgument

@Option(name: .long, help: "Security Assessment: the proof of a completed assessment (file)")
var proof: String?

@Option(name: .long, help: "Security Assessment: the assessment report (file)")
var report: String?

@Option(name: .long, help: "AIGC: llm or algorithm")
var filingType: AIGCFiling.FilingType?

@Option(name: .long, help: "AIGC: the LLM or algorithm name, as filed")
var filingName: String?

@Option(name: .long, help: "AIGC: the filing number")
var filingNumber: String?

@Option(name: .long, help: "AIGC: the authorization or usage agreement for third-party technology (file)")
var thirdPartyAuthorization: String?

func run() async throws {
print(try await execute(cookieProvider: ClientProvider.makeIrisCookieProvider(), repo: ClientProvider.makeIrisComplianceRepository()))
}

func execute(cookieProvider: any IrisCookieProvider, repo: any IrisComplianceRepository, affordanceMode: AffordanceMode = .cli) async throws -> String {
let session = try cookieProvider.resolveSession()
let requirement = try await repo.requirement(requirementId, appId: appId, session: session)
let declared = try await requirement.declare(try answer.answer(for: requirement.kind, evidence: try evidence()), session: session, repo: repo)
return try OutputFormatter(format: globals.outputFormat, pretty: globals.pretty).formatAgentItems([declared], affordanceMode: affordanceMode)
}

private func evidence() throws -> ComplianceEvidenceInput {
func read(_ path: String?) throws -> ComplianceFile? {
guard let path else { return nil }
let url = URL(fileURLWithPath: path)
return ComplianceFile(name: url.lastPathComponent, data: try Data(contentsOf: url))
}
return ComplianceEvidenceInput(
proof: try read(proof), report: try read(report),
filingType: filingType, filingName: filingName, filingNumber: filingNumber,
thirdPartyAuthorization: try read(thirdPartyAuthorization)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ArgumentParser
import ASCKit

struct IrisAppComplianceList: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List every App Compliance requirement for an app, answered or not"
)

@OptionGroup var globals: GlobalOptions

@Option(name: .long, help: "App ID")
var appId: String

func run() async throws {
print(try await execute(cookieProvider: ClientProvider.makeIrisCookieProvider(), repo: ClientProvider.makeIrisComplianceRepository()))
}

func execute(cookieProvider: any IrisCookieProvider, repo: any IrisComplianceRepository, affordanceMode: AffordanceMode = .cli) async throws -> String {
let rows = try await repo.listRequirements(session: try cookieProvider.resolveSession(), appId: appId)
return try OutputFormatter(format: globals.outputFormat, pretty: globals.pretty).formatAgentItems(rows, affordanceMode: affordanceMode)
}
}
1 change: 1 addition & 0 deletions Sources/ASCCommand/Commands/Iris/IrisCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct IrisCommand: AsyncParsableCommand {
IrisAppsCommand.self,
IrisIAPSubmissionsCommand.self,
IrisResolutionCenterCommand.self,
IrisAppComplianceCommand.self,
IrisAuthCommand.self,
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import ASCKit
import Foundation
import Hummingbird
import HummingbirdWebSocket

/// `GET /api/v1/iris/apps/:appId/compliance-requirements` — the app's App Compliance page.
/// `POST /api/v1/iris/apps/:appId/compliance-requirements/:requirementId/declare` with
/// `{"answer": "yes" | "no"}` — answers one. Iris private API only (browser-cookie auth).
struct IrisAppComplianceController: Sendable {
let cookieProvider: any IrisCookieProvider
let repo: any IrisComplianceRepository

private struct DeclareBody: Decodable {
struct File: Decodable {
let name: String
/// The file's bytes, base64-encoded.
let data: String
}

struct Evidence: Decodable {
let proof: File?
let report: File?
let filingType: String?
let filingName: String?
let filingNumber: String?
let thirdPartyAuthorization: File?
}

let answer: String
let evidence: Evidence?

func evidenceInput() -> ComplianceEvidenceInput {
func file(_ file: File?) -> ComplianceFile? {
file.flatMap { f in Data(base64Encoded: f.data).map { ComplianceFile(name: f.name, data: $0) } }
}
return ComplianceEvidenceInput(
proof: file(evidence?.proof), report: file(evidence?.report),
filingType: evidence?.filingType.flatMap(AIGCFiling.FilingType.init(rawValue:)),
filingName: evidence?.filingName, filingNumber: evidence?.filingNumber,
thirdPartyAuthorization: file(evidence?.thirdPartyAuthorization)
)
}
}

func addRoutes(to group: RouterGroup<BasicWebSocketRequestContext>) {
group.get("/iris/apps/:appId/compliance-requirements") { _, context -> Response in
guard let appId = context.parameters.get("appId") else { return jsonError("Missing appId") }
let session = try self.cookieProvider.resolveSession()
return try await self.answering { try restFormat(try await self.repo.listRequirements(session: session, appId: appId)) }
}

group.post("/iris/apps/:appId/compliance-requirements/:requirementId/declare") { request, context -> Response in
guard let appId = context.parameters.get("appId"),
let requirementId = context.parameters.get("requirementId") else { return jsonError("Missing appId or requirementId") }
let body = try? await request.decode(as: DeclareBody.self, context: context)
guard let body, let answer = DeclaredAnswerArgument(rawValue: body.answer.lowercased()) else {
return jsonError(#"answer must be "yes" or "no""#)
}
let session = try self.cookieProvider.resolveSession()
return try await self.answering {
let requirement = try await self.repo.requirement(requirementId, appId: appId, session: session)
let declared = try answer.answer(for: requirement.kind, evidence: body.evidenceInput())
return try restFormat(try await requirement.declare(declared, session: session, repo: self.repo))
}
}
}

/// A refusal the domain explains is answered with its own words and status.
private func answering(_ handler: () async throws -> Response) async throws -> Response {
do {
return try await handler()
} catch let error as ComplianceError {
switch error {
case .requirementNotFound: return jsonError(error.description, status: .notFound)
case .roleCannotEdit: return jsonError(error.description, status: .forbidden)
case .teamUnknown: return jsonError(error.description, status: .unauthorized)
case .notDeclarable, .readOnly: return jsonError(error.description, status: .conflict)
case .evidenceMissing, .evidenceMismatch, .fileTypeNotAllowed: return jsonError(error.description, status: .unprocessableContent)
case .formNotUnderstood: return jsonError(error.description, status: .conflict)
}
}
}
}
4 changes: 4 additions & 0 deletions Sources/ASCCommand/Commands/Web/RESTRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ enum RESTRoutes {
cookieProvider: ClientProvider.makeIrisCookieProvider(),
repo: ClientProvider.makeIrisResolutionCenterRepository()
).addRoutes(to: v1)
IrisAppComplianceController(
cookieProvider: ClientProvider.makeIrisCookieProvider(),
repo: ClientProvider.makeIrisComplianceRepository()
).addRoutes(to: v1)
if let subSubmissionRepo = try? ClientProvider.makeSubscriptionSubmissionRepository() {
SubscriptionSubmissionController(repo: subSubmissionRepo).addRoutes(to: v1)
}
Expand Down
Loading
Loading