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
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-privacy get`, `declare` and `publish` show, replace and publish an app's App Privacy label (Data Not Collected or the data it collects), so a submission is no longer refused over unpublished data usages; over CLI and REST. → [docs](docs/features/app-privacy/README.md) ([#46](https://github.com/tddworks/asc-cli/pull/46))

---

## [0.19.0] - 2026-11-19
Expand Down
4 changes: 4 additions & 0 deletions Sources/ASCCommand/ClientProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ struct ClientProvider {
ClientFactory().makeIrisComplianceRepository()
}

static func makeIrisAppPrivacyRepository() -> any IrisAppPrivacyRepository {
ClientFactory().makeIrisAppPrivacyRepository()
}

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

/// `asc iris app-privacy` — the app's App Privacy label ("nutrition label"). Iris private
/// API only: there is no public endpoint, yet App Review refuses a submission until it's published.
struct IrisAppPrivacyCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "app-privacy",
abstract: "Show, declare and publish an app's App Privacy label (iris session)",
subcommands: [IrisAppPrivacyGet.self, IrisAppPrivacyDeclare.self, IrisAppPrivacyPublish.self]
)
}

struct IrisAppPrivacyGet: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "get",
abstract: "Show what an app's privacy label declares and whether it is published"
)

@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.makeIrisAppPrivacyRepository()))
}

func execute(cookieProvider: any IrisCookieProvider, repo: any IrisAppPrivacyRepository, affordanceMode: AffordanceMode = .cli) async throws -> String {
let privacy = try await repo.fetchPrivacy(session: try cookieProvider.resolveSession(), appId: appId)
return try OutputFormatter(format: globals.outputFormat, pretty: globals.pretty).formatAgentItems([privacy], affordanceMode: affordanceMode)
}
}

struct IrisAppPrivacyPublish: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "publish",
abstract: "Publish an app's declared privacy label so it no longer blocks review"
)

@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.makeIrisAppPrivacyRepository()))
}

func execute(cookieProvider: any IrisCookieProvider, repo: any IrisAppPrivacyRepository, affordanceMode: AffordanceMode = .cli) async throws -> String {
let session = try cookieProvider.resolveSession()
let published = try await repo.fetchPrivacy(session: session, appId: appId).publish(session: session, repo: repo)
return try OutputFormatter(format: globals.outputFormat, pretty: globals.pretty).formatAgentItems([published], affordanceMode: affordanceMode)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import ArgumentParser
import Foundation
import ASCKit

struct IrisAppPrivacyDeclare: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "declare",
abstract: "Replace an app's privacy label (it stays a draft until `publish`)",
discussion: """
--not-collected declares the app collects no data. --file takes a JSON file listing what it collects:
{"collectedData": [{"category": "EMAIL_ADDRESS", "purposes": ["APP_FUNCTIONALITY"],
"isLinkedToYou": true, "isUsedToTrackYou": false}]}
the same shape `get` shows. The file may also be {"notCollected": true}.
"""
)

@OptionGroup var globals: GlobalOptions

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

@Flag(name: .long, help: "The app collects no data")
var notCollected = false

@Option(name: .long, help: "A JSON file of the data the app collects")
var file: String?

func validate() throws {
guard notCollected != (file != nil) else {
throw ValidationError("Give either --not-collected or --file <privacy.json>.")
}
}

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

func execute(cookieProvider: any IrisCookieProvider, repo: any IrisAppPrivacyRepository, affordanceMode: AffordanceMode = .cli) async throws -> String {
let declaration = try declaration()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
try declaration.validate() // refused before signing in or reaching Apple (law 6)
let session = try cookieProvider.resolveSession()
let declared = try await repo.fetchPrivacy(session: session, appId: appId).declare(declaration, session: session, repo: repo)
return try OutputFormatter(format: globals.outputFormat, pretty: globals.pretty).formatAgentItems([declared], affordanceMode: affordanceMode)
}

private func declaration() throws -> PrivacyDeclaration {
guard let file else { return .notCollected }
return try JSONDecoder().decode(PrivacyDeclaration.self, from: Data(contentsOf: URL(fileURLWithPath: file)))
}
}
1 change: 1 addition & 0 deletions Sources/ASCCommand/Commands/Iris/IrisCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct IrisCommand: AsyncParsableCommand {
IrisIAPSubmissionsCommand.self,
IrisResolutionCenterCommand.self,
IrisAppComplianceCommand.self,
IrisAppPrivacyCommand.self,
IrisAuthCommand.self,
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ASCKit
import Foundation
import Hummingbird
import HummingbirdWebSocket

/// `GET /api/v1/iris/apps/:appId/app-privacy` — the app's privacy label.
/// `POST /api/v1/iris/apps/:appId/app-privacy/declare` with `{"notCollected": true}` or
/// `{"collectedData": [...]}` — replaces it (a draft until published).
/// `POST /api/v1/iris/apps/:appId/app-privacy/publish` — makes it live.
/// Iris private API only (browser-cookie auth).
struct IrisAppPrivacyController: Sendable {
let cookieProvider: any IrisCookieProvider
let repo: any IrisAppPrivacyRepository

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

group.post("/iris/apps/:appId/app-privacy/declare") { request, context -> Response in
guard let appId = context.parameters.get("appId") else { return jsonError("Missing appId") }
let bytes = try await request.body.collect(upTo: 1_000_000)
guard let declaration = try? JSONDecoder().decode(PrivacyDeclaration.self, from: Data(buffer: bytes)) else {
return jsonError(#"Send either {"notCollected": true} or {"collectedData": [...]}"#)
}
return try await self.answering {
try declaration.validate() // refused before signing in or reaching Apple (law 6)
let session = try self.cookieProvider.resolveSession()
let privacy = try await self.repo.fetchPrivacy(session: session, appId: appId)
return try restFormat(try await privacy.declare(declaration, session: session, repo: self.repo))
}
}

group.post("/iris/apps/:appId/app-privacy/publish") { _, 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 {
let privacy = try await self.repo.fetchPrivacy(session: session, appId: appId)
return try restFormat(try await privacy.publish(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 AppPrivacyError {
switch error {
case .nothingDeclared: return jsonError(error.description, status: .conflict)
case .noDataTypes, .noPurposes, .unknownCategory, .unknownPurpose, .duplicateCategory, .duplicatePurpose:
return jsonError(error.description, status: .unprocessableContent)
}
}
}
}
4 changes: 4 additions & 0 deletions Sources/ASCCommand/Commands/Web/RESTRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ enum RESTRoutes {
cookieProvider: ClientProvider.makeIrisCookieProvider(),
repo: ClientProvider.makeIrisComplianceRepository()
).addRoutes(to: v1)
IrisAppPrivacyController(
cookieProvider: ClientProvider.makeIrisCookieProvider(),
repo: ClientProvider.makeIrisAppPrivacyRepository()
).addRoutes(to: v1)
if let subSubmissionRepo = try? ClientProvider.makeSubscriptionSubmissionRepository() {
SubscriptionSubmissionController(repo: subSubmissionRepo).addRoutes(to: v1)
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/ASCKit/Iris/AppPrivacy/AppPrivacy+RESTRoutes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// REST routes for App Privacy.
extension RESTPathResolver {
static let _appPrivacyRoutes: Void = {
// One label per app:
// `asc iris app-privacy get --app-id A` → GET /api/v1/iris/apps/A/app-privacy
// `… declare --app-id A` / `… publish …` → POST /api/v1/iris/apps/A/app-privacy/{declare|publish}
registerRoute(command: "iris app-privacy", parentParam: "app-id", parentSegment: "iris/apps", segment: "app-privacy")
}()
}
115 changes: 115 additions & 0 deletions Sources/ASCKit/Iris/AppPrivacy/AppPrivacy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/// An app's privacy label — the App Privacy page: "Data Not Collected" or the data types it
/// collects, and whether that answer is published. One per app; the aggregate.
public struct AppPrivacy: Sendable, Equatable {
/// Parent and identity: there is one label per app.
public let appId: String
public let dataCollection: DataCollection
public let isPublished: Bool
/// When it was last published (Apple's `lastPublished`); nil = never.
public let lastPublishedAt: String?

public init(appId: String, dataCollection: DataCollection, isPublished: Bool, lastPublishedAt: String?) {
self.appId = appId
self.dataCollection = dataCollection
self.isPublished = isPublished
self.lastPublishedAt = lastPublishedAt
}

/// The label Apple's rows make (law 1).
public init(appId: String, dataUsages: [DataUsage], isPublished: Bool, lastPublishedAt: String?) {
let collected = CollectedData.grouping(dataUsages)
let collection: DataCollection
if !collected.isEmpty {
collection = .collected(collected)
} else if dataUsages.contains(where: { $0.protection == .notCollected }) {
collection = .notCollected
} else {
collection = .notAnswered
}
self.init(appId: appId, dataCollection: collection, isPublished: isPublished, lastPublishedAt: lastPublishedAt)
}

public var isAnswered: Bool { dataCollection != .notAnswered }
public var isNotCollected: Bool { dataCollection == .notCollected }
/// App Review refuses a submission until the label is answered and published (law 7).
public var blocksSubmission: Bool { !(isAnswered && isPublished) }

/// Replaces the label with `declaration` (law 3). It stays a draft until published (law 4).
public func declare(_ declaration: PrivacyDeclaration, session: IrisSession, repo: any IrisAppPrivacyRepository) async throws -> AppPrivacy {
try declaration.validate()
let plan = DataUsagePlan(current: try await repo.listDataUsages(session: session, appId: appId), wanted: declaration)
for usage in plan.deletions {
try await repo.deleteDataUsage(session: session, dataUsageId: usage.id)
}
for entry in plan.creations {
try await repo.createDataUsage(session: session, appId: appId, entry: entry)
}
return try await repo.fetchPrivacy(session: session, appId: appId)
}

/// Makes the label live — only once something is declared (law 5).
public func publish(session: IrisSession, repo: any IrisAppPrivacyRepository) async throws -> AppPrivacy {
guard isAnswered else { throw AppPrivacyError.nothingDeclared(appId: appId) }
try await repo.publish(session: session, appId: appId)
return try await repo.fetchPrivacy(session: session, appId: appId)
}
}

extension AppPrivacy: Codable {
private enum CodingKeys: String, CodingKey {
case appId, dataCollection, collectedData, isAnswered, isPublished, blocksSubmission, lastPublishedAt
}

public init(from decoder: any Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let collection: DataCollection
switch try c.decode(String.self, forKey: .dataCollection) {
case "NOT_COLLECTED": collection = .notCollected
case "COLLECTED": collection = .collected(try c.decode([CollectedData].self, forKey: .collectedData))
default: collection = .notAnswered
}
self.init(
appId: try c.decode(String.self, forKey: .appId),
dataCollection: collection,
isPublished: try c.decode(Bool.self, forKey: .isPublished),
lastPublishedAt: try c.decodeIfPresent(String.self, forKey: .lastPublishedAt)
)
}

public func encode(to encoder: any Encoder) throws {
var c = encoder.container(keyedBy: CodingKeys.self)
try c.encode(appId, forKey: .appId)
try c.encode(dataCollection.wireValue, forKey: .dataCollection)
if case .collected(let data) = dataCollection {
try c.encode(data, forKey: .collectedData)
}
try c.encode(isAnswered, forKey: .isAnswered)
try c.encode(isPublished, forKey: .isPublished)
try c.encode(blocksSubmission, forKey: .blocksSubmission)
try c.encodeIfPresent(lastPublishedAt, forKey: .lastPublishedAt)
}
}

extension AppPrivacy: AffordanceProviding {
public var structuredAffordances: [Affordance] {
let app = ["app-id": appId]
var items = [
Affordance(key: "get", command: "iris app-privacy", action: "get", params: app),
Affordance(key: "declare", command: "iris app-privacy", action: "declare", params: app.merging(["file": "<privacy.json>"]) { $1 }),
]
if !isAnswered {
items.append(Affordance(key: "declareNotCollected", command: "iris app-privacy", action: "declare", params: app, flags: ["not-collected"]))
}
if isAnswered && !isPublished {
items.append(Affordance(key: "publish", command: "iris app-privacy", action: "publish", params: app))
}
return items
}
}

extension AppPrivacy: Presentable {
public static var tableHeaders: [String] { ["App ID", "Data Collection", "Published", "Blocks Submission"] }
public var tableRow: [String] {
[appId, dataCollection.wireValue, isPublished ? "yes" : "no", blocksSubmission ? "yes" : "no"]
}
}
34 changes: 34 additions & 0 deletions Sources/ASCKit/Iris/AppPrivacy/AppPrivacyError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation

public enum AppPrivacyError: Error, Equatable, Sendable, CustomStringConvertible, LocalizedError {
/// Publishing a label with nothing declared (law 5).
case nothingDeclared(appId: String)
/// `collectedData` is empty: that is "Data Not Collected", said another way.
case noDataTypes
case noPurposes(category: String)
case unknownCategory(String)
case unknownPurpose(String)
case duplicateCategory(String)
case duplicatePurpose(category: String, purpose: String)

public var description: String {
switch self {
case .nothingDeclared(let appId):
"App \(appId) has no privacy answers to publish. Declare them first: `asc iris app-privacy declare --app-id \(appId) --not-collected` or `--file <privacy.json>`."
case .noDataTypes:
"collectedData lists no data types. If the app collects nothing, declare --not-collected."
case .noPurposes(let category):
"\(category) needs at least one purpose."
case .unknownCategory(let category):
"\(category) isn't a data type App Privacy knows (e.g. EMAIL_ADDRESS, CRASH_DATA, DEVICE_ID)."
case .unknownPurpose(let purpose):
"\(purpose) isn't a purpose App Privacy knows: APP_FUNCTIONALITY, ANALYTICS, PRODUCT_PERSONALIZATION, DEVELOPERS_ADVERTISING, THIRD_PARTY_ADVERTISING or OTHER_PURPOSES."
case .duplicateCategory(let category):
"\(category) is declared twice; list each data type once with all its purposes."
case .duplicatePurpose(let category, let purpose):
"\(category) lists \(purpose) twice; list each purpose once."
}
}

public var errorDescription: String? { description }
}
Loading
Loading