From 6e717d55edc580c97eaa9789f93b9ab3f1d80e75 Mon Sep 17 00:00:00 2001 From: slamhan Date: Sat, 28 Nov 2026 14:54:39 +0800 Subject: [PATCH] fix(age-rating): show and answer Shared Location and Dating and Relationships App Store Connect's age-rating questionnaire has sharedLocation and datingAndRelationships, but the SDK (4.6.2) doesn't model them, so `asc age-rating get` dropped them and `update` couldn't answer them. The repository now decodes and sends both beside the SDK's own types. - `asc age-rating update --shared-location --dating-and-relationships` - REST PATCH body keys isSharedLocation / isDatingAndRelationships Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 + .../Commands/AgeRating/AgeRatingCommand.swift | 8 +++ .../Web/Controllers/AgeRatingController.swift | 2 + .../Apps/AppInfos/AgeRatingDeclaration.swift | 13 +++++ .../AgeRatingDeclarationDocument.swift | 57 +++++++++++++++++++ .../SDKAgeRatingDeclarationRepository.swift | 35 +++++++----- .../AgeRating/AgeRatingUpdateTests.swift | 37 ++++++++++++ .../Controllers/AgeRatingRoutesTests.swift | 28 +++++++++ ...KAgeRatingDeclarationRepositoryTests.swift | 39 +++++++++++++ docs/commands.md | 4 +- docs/features/age-rating/README.md | 2 + 11 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 Sources/ASCKit/Apps/AppInfos/Internal/AgeRatingDeclarationDocument.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 197f2766..08853cd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- `asc age-rating get` and `update` show and answer the Shared Location and Dating and Relationships questions (`--shared-location`, `--dating-and-relationships`), over CLI and REST. → [docs](docs/features/age-rating/README.md) + --- ## [0.19.1] - 2026-11-24 diff --git a/Sources/ASCCommand/Commands/AgeRating/AgeRatingCommand.swift b/Sources/ASCCommand/Commands/AgeRating/AgeRatingCommand.swift index 0df6b8df..3223232f 100644 --- a/Sources/ASCCommand/Commands/AgeRating/AgeRatingCommand.swift +++ b/Sources/ASCCommand/Commands/AgeRating/AgeRatingCommand.swift @@ -85,6 +85,12 @@ struct AgeRatingUpdate: AsyncParsableCommand { @Option(name: .long, help: "Social media features are age restricted (true/false)") var socialMediaAgeRestricted: Bool? + @Option(name: .long, help: "Shares the user's location with other users (true/false)") + var sharedLocation: Bool? + + @Option(name: .long, help: "Contains dating or relationship features (true/false)") + var datingAndRelationships: Bool? + // Intensity flags (NONE/INFREQUENT_OR_MILD/FREQUENT_OR_INTENSE/INFREQUENT/FREQUENT) @Option(name: .long, help: "Alcohol, tobacco or drug use intensity") var alcoholTobaccoDrugs: ContentIntensity? @@ -159,6 +165,8 @@ struct AgeRatingUpdate: AsyncParsableCommand { update.isUserGeneratedContent = userGeneratedContent update.isSocialMedia = socialMedia update.isSocialMediaAgeRestricted = socialMediaAgeRestricted + update.isSharedLocation = sharedLocation + update.isDatingAndRelationships = datingAndRelationships update.alcoholTobaccoOrDrugUseOrReferences = alcoholTobaccoDrugs update.contests = contests update.gamblingSimulated = gamblingSimulated diff --git a/Sources/ASCCommand/Commands/Web/Controllers/AgeRatingController.swift b/Sources/ASCCommand/Commands/Web/Controllers/AgeRatingController.swift index dc3bc158..cc953372 100644 --- a/Sources/ASCCommand/Commands/Web/Controllers/AgeRatingController.swift +++ b/Sources/ASCCommand/Commands/Web/Controllers/AgeRatingController.swift @@ -38,6 +38,8 @@ struct AgeRatingController: Sendable { update.isUserGeneratedContent = json["isUserGeneratedContent"] as? Bool update.isSocialMedia = json["isSocialMedia"] as? Bool update.isSocialMediaAgeRestricted = json["isSocialMediaAgeRestricted"] as? Bool + update.isSharedLocation = json["isSharedLocation"] as? Bool + update.isDatingAndRelationships = json["isDatingAndRelationships"] as? Bool update.alcoholTobaccoOrDrugUseOrReferences = (json["alcoholTobaccoOrDrugUseOrReferences"] as? String).flatMap(ContentIntensity.init(rawValue:)) update.contests = (json["contests"] as? String).flatMap(ContentIntensity.init(rawValue:)) update.gamblingSimulated = (json["gamblingSimulated"] as? String).flatMap(ContentIntensity.init(rawValue:)) diff --git a/Sources/ASCKit/Apps/AppInfos/AgeRatingDeclaration.swift b/Sources/ASCKit/Apps/AppInfos/AgeRatingDeclaration.swift index e3f84f7a..d86ca4c3 100644 --- a/Sources/ASCKit/Apps/AppInfos/AgeRatingDeclaration.swift +++ b/Sources/ASCKit/Apps/AppInfos/AgeRatingDeclaration.swift @@ -46,6 +46,8 @@ public struct AgeRatingDeclaration: Sendable, Equatable, Identifiable { public let isUserGeneratedContent: Bool? public let isSocialMedia: Bool? public let isSocialMediaAgeRestricted: Bool? + public let isSharedLocation: Bool? + public let isDatingAndRelationships: Bool? // Content intensity ratings public let alcoholTobaccoOrDrugUseOrReferences: ContentIntensity? @@ -84,6 +86,8 @@ public struct AgeRatingDeclaration: Sendable, Equatable, Identifiable { isUserGeneratedContent: Bool? = nil, isSocialMedia: Bool? = nil, isSocialMediaAgeRestricted: Bool? = nil, + isSharedLocation: Bool? = nil, + isDatingAndRelationships: Bool? = nil, alcoholTobaccoOrDrugUseOrReferences: ContentIntensity? = nil, contests: ContentIntensity? = nil, gamblingSimulated: ContentIntensity? = nil, @@ -116,6 +120,8 @@ public struct AgeRatingDeclaration: Sendable, Equatable, Identifiable { self.isUserGeneratedContent = isUserGeneratedContent self.isSocialMedia = isSocialMedia self.isSocialMediaAgeRestricted = isSocialMediaAgeRestricted + self.isSharedLocation = isSharedLocation + self.isDatingAndRelationships = isDatingAndRelationships self.alcoholTobaccoOrDrugUseOrReferences = alcoholTobaccoOrDrugUseOrReferences self.contests = contests self.gamblingSimulated = gamblingSimulated @@ -189,6 +195,7 @@ extension AgeRatingDeclaration: Codable { case isMessagingAndChat, isParentalControls, isAgeAssurance case isUnrestrictedWebAccess, isUserGeneratedContent case isSocialMedia, isSocialMediaAgeRestricted + case isSharedLocation, isDatingAndRelationships case alcoholTobaccoOrDrugUseOrReferences, contests, gamblingSimulated case gunsOrOtherWeapons, medicalOrTreatmentInformation, profanityOrCrudeHumor case sexualContentGraphicAndNudity, sexualContentOrNudity, horrorOrFearThemes @@ -213,6 +220,8 @@ extension AgeRatingDeclaration: Codable { isUserGeneratedContent = try c.decodeIfPresent(Bool.self, forKey: .isUserGeneratedContent) isSocialMedia = try c.decodeIfPresent(Bool.self, forKey: .isSocialMedia) isSocialMediaAgeRestricted = try c.decodeIfPresent(Bool.self, forKey: .isSocialMediaAgeRestricted) + isSharedLocation = try c.decodeIfPresent(Bool.self, forKey: .isSharedLocation) + isDatingAndRelationships = try c.decodeIfPresent(Bool.self, forKey: .isDatingAndRelationships) alcoholTobaccoOrDrugUseOrReferences = try c.decodeIfPresent(ContentIntensity.self, forKey: .alcoholTobaccoOrDrugUseOrReferences) contests = try c.decodeIfPresent(ContentIntensity.self, forKey: .contests) gamblingSimulated = try c.decodeIfPresent(ContentIntensity.self, forKey: .gamblingSimulated) @@ -248,6 +257,8 @@ extension AgeRatingDeclaration: Codable { try c.encodeIfPresent(isUserGeneratedContent, forKey: .isUserGeneratedContent) try c.encodeIfPresent(isSocialMedia, forKey: .isSocialMedia) try c.encodeIfPresent(isSocialMediaAgeRestricted, forKey: .isSocialMediaAgeRestricted) + try c.encodeIfPresent(isSharedLocation, forKey: .isSharedLocation) + try c.encodeIfPresent(isDatingAndRelationships, forKey: .isDatingAndRelationships) try c.encodeIfPresent(alcoholTobaccoOrDrugUseOrReferences, forKey: .alcoholTobaccoOrDrugUseOrReferences) try c.encodeIfPresent(contests, forKey: .contests) try c.encodeIfPresent(gamblingSimulated, forKey: .gamblingSimulated) @@ -300,6 +311,8 @@ public struct AgeRatingDeclarationUpdate: Sendable { public var isUserGeneratedContent: Bool? public var isSocialMedia: Bool? public var isSocialMediaAgeRestricted: Bool? + public var isSharedLocation: Bool? + public var isDatingAndRelationships: Bool? public var alcoholTobaccoOrDrugUseOrReferences: ContentIntensity? public var contests: ContentIntensity? public var gamblingSimulated: ContentIntensity? diff --git a/Sources/ASCKit/Apps/AppInfos/Internal/AgeRatingDeclarationDocument.swift b/Sources/ASCKit/Apps/AppInfos/Internal/AgeRatingDeclarationDocument.swift new file mode 100644 index 00000000..1e5bff11 --- /dev/null +++ b/Sources/ASCKit/Apps/AppInfos/Internal/AgeRatingDeclarationDocument.swift @@ -0,0 +1,57 @@ +@preconcurrency import AppStoreConnect_Swift_SDK +import Foundation + +// The SDK (4.6.2) doesn't model the age-rating questions `sharedLocation` and +// `datingAndRelationships`, so asc reads and writes them beside the SDK's own types. +// Drop these once the SDK carries both attributes. + +/// An age rating declaration response: the SDK's view plus the questions it lacks. +struct AgeRatingDeclarationDocument: Decodable { + let response: AgeRatingDeclarationResponse + let sharedLocation: Bool? + let datingAndRelationships: Bool? + + init(_ response: AgeRatingDeclarationResponse, sharedLocation: Bool? = nil, datingAndRelationships: Bool? = nil) { + self.response = response + self.sharedLocation = sharedLocation + self.datingAndRelationships = datingAndRelationships + } + + init(from decoder: Decoder) throws { + response = try AgeRatingDeclarationResponse(from: decoder) + let answers = try UnmodeledAnswersDocument(from: decoder).data.attributes + sharedLocation = answers?.sharedLocation + datingAndRelationships = answers?.datingAndRelationships + } + + private struct UnmodeledAnswersDocument: Decodable { + struct Resource: Decodable { let attributes: UnmodeledAnswers? } + let data: Resource + } +} + +struct UnmodeledAnswers: Codable { + let sharedLocation: Bool? + let datingAndRelationships: Bool? +} + +/// A PATCH body: the SDK's attributes plus the questions it lacks, in one `attributes` object. +struct AgeRatingDeclarationUpdateBody: Encodable { + struct Resource: Encodable { + let type = "ageRatingDeclarations" + let id: String + let attributes: Attributes + } + + struct Attributes: Encodable { + let sdk: AgeRatingDeclarationUpdateRequest.Data.Attributes + let unmodeled: UnmodeledAnswers + + func encode(to encoder: Encoder) throws { + try sdk.encode(to: encoder) + try unmodeled.encode(to: encoder) + } + } + + let data: Resource +} diff --git a/Sources/ASCKit/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepository.swift b/Sources/ASCKit/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepository.swift index b40a1c3e..fe1de21f 100644 --- a/Sources/ASCKit/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepository.swift +++ b/Sources/ASCKit/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepository.swift @@ -9,30 +9,37 @@ public struct SDKAgeRatingDeclarationRepository: AgeRatingDeclarationRepository, } public func getDeclaration(appInfoId: String) async throws -> ASCKit.AgeRatingDeclaration { - let request = APIEndpoint.v1.appInfos.id(appInfoId).ageRatingDeclaration.get() - let response = try await client.request(request) - return mapDeclaration(response.data, appInfoId: appInfoId) + let sdk = APIEndpoint.v1.appInfos.id(appInfoId).ageRatingDeclaration.get() + let document = try await client.request(Request( + path: sdk.path, method: "GET", query: sdk.query, id: "appInfos_ageRatingDeclaration_getToOneRelated" + )) + return mapDeclaration(document, appInfoId: appInfoId) } public func updateDeclaration(id: String, update: ASCKit.AgeRatingDeclarationUpdate) async throws -> ASCKit.AgeRatingDeclaration { - let body = AgeRatingDeclarationUpdateRequest( - data: .init( - type: .ageRatingDeclarations, - id: id, - attributes: mapUpdateAttributes(update) + let body = AgeRatingDeclarationUpdateBody(data: .init( + id: id, + attributes: .init( + sdk: mapUpdateAttributes(update), + unmodeled: UnmodeledAnswers( + sharedLocation: update.isSharedLocation, + datingAndRelationships: update.isDatingAndRelationships + ) ) - ) - let request = APIEndpoint.v1.ageRatingDeclarations.id(id).patch(body) - let response = try await client.request(request) - return mapDeclaration(response.data, appInfoId: "") + )) + let document = try await client.request(Request( + path: "/v1/ageRatingDeclarations/\(id)", method: "PATCH", body: body, id: "ageRatingDeclarations_updateInstance" + )) + return mapDeclaration(document, appInfoId: "") } // MARK: - Mappers private func mapDeclaration( - _ sdk: AppStoreConnect_Swift_SDK.AgeRatingDeclaration, + _ document: AgeRatingDeclarationDocument, appInfoId: String ) -> ASCKit.AgeRatingDeclaration { + let sdk = document.response.data let a = sdk.attributes return ASCKit.AgeRatingDeclaration( id: sdk.id, @@ -48,6 +55,8 @@ public struct SDKAgeRatingDeclarationRepository: AgeRatingDeclarationRepository, isUserGeneratedContent: a?.isUserGeneratedContent, isSocialMedia: a?.isSocialMedia, isSocialMediaAgeRestricted: a?.isSocialMediaAgeRestricted, + isSharedLocation: document.sharedLocation, + isDatingAndRelationships: document.datingAndRelationships, alcoholTobaccoOrDrugUseOrReferences: mapIntensity(a?.alcoholTobaccoOrDrugUseOrReferences), contests: mapIntensity(a?.contests), gamblingSimulated: mapIntensity(a?.gamblingSimulated), diff --git a/Tests/ASCCommandTests/Commands/AgeRating/AgeRatingUpdateTests.swift b/Tests/ASCCommandTests/Commands/AgeRating/AgeRatingUpdateTests.swift index 214a6274..205fe615 100644 --- a/Tests/ASCCommandTests/Commands/AgeRating/AgeRatingUpdateTests.swift +++ b/Tests/ASCCommandTests/Commands/AgeRating/AgeRatingUpdateTests.swift @@ -176,4 +176,41 @@ struct AgeRatingUpdateTests { } """) } + @Test func `should save and show the shared location and dating answers`() async throws { + let mockRepo = MockAgeRatingDeclarationRepository() + given(mockRepo).updateDeclaration(id: .any, update: .any) + .willProduce { id, update in + AgeRatingDeclaration( + id: id, + appInfoId: "info-42", + isSharedLocation: update.isSharedLocation, + isDatingAndRelationships: update.isDatingAndRelationships + ) + } + + let cmd = try AgeRatingUpdate.parse([ + "--declaration-id", "decl-1", + "--shared-location", "false", + "--dating-and-relationships", "true", + "--pretty", + ]) + let output = try await cmd.execute(repo: mockRepo) + + #expect(output == """ + { + "data" : [ + { + "affordances" : { + "getAgeRating" : "asc age-rating get --app-info-id info-42", + "update" : "asc age-rating update --declaration-id decl-1" + }, + "appInfoId" : "info-42", + "id" : "decl-1", + "isDatingAndRelationships" : true, + "isSharedLocation" : false + } + ] + } + """) + } } diff --git a/Tests/ASCCommandTests/Commands/Web/Controllers/AgeRatingRoutesTests.swift b/Tests/ASCCommandTests/Commands/Web/Controllers/AgeRatingRoutesTests.swift index 2df17a33..412277e8 100644 --- a/Tests/ASCCommandTests/Commands/Web/Controllers/AgeRatingRoutesTests.swift +++ b/Tests/ASCCommandTests/Commands/Web/Controllers/AgeRatingRoutesTests.swift @@ -40,4 +40,32 @@ struct AgeRatingRoutesTests { #expect(declaration["isSocialMediaAgeRestricted"] as? Bool == true) #expect(declaration["developerAgeRatingInfoUrl"] as? String == "https://example.com/age") } + + @Test func `should save the shared location and dating answers over REST`() async throws { + let repo = MockAgeRatingDeclarationRepository() + given(repo).updateDeclaration(id: .value("decl-1"), update: .any).willProduce { id, update in + AgeRatingDeclaration( + id: id, + appInfoId: "info-1", + isSharedLocation: update.isSharedLocation, + isDatingAndRelationships: update.isDatingAndRelationships + ) + } + let router = Router(context: BasicWebSocketRequestContext.self) + AgeRatingController(repo: repo).addRoutes(to: router.group("/api/v1")) + + let body = #"{"isSharedLocation":false,"isDatingAndRelationships":true}"# + let response = try await Application(router: router).test(.router) { client in + try await client.execute( + uri: "/api/v1/age-rating/decl-1", + method: .patch, + body: ByteBuffer(string: body) + ) { String(buffer: $0.body) } + } + + let json = try #require(try JSONSerialization.jsonObject(with: Data(response.utf8)) as? [String: Any]) + let declaration = try #require((json["data"] as? [[String: Any]])?.first) + #expect(declaration["isSharedLocation"] as? Bool == false) + #expect(declaration["isDatingAndRelationships"] as? Bool == true) + } } diff --git a/Tests/ASCKitTests/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepositoryTests.swift b/Tests/ASCKitTests/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepositoryTests.swift index 2d230ccc..d5d6e883 100644 --- a/Tests/ASCKitTests/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepositoryTests.swift +++ b/Tests/ASCKitTests/Apps/AppInfos/Internal/SDKAgeRatingDeclarationRepositoryTests.swift @@ -230,4 +230,43 @@ struct SDKAgeRatingDeclarationRepositoryTests { #expect(attributes["socialMediaAgeRestricted"] as? Bool == true) #expect(attributes["developerAgeRatingInfoUrl"] as? String == "https://example.com/age") } + + // MARK: - Questions the SDK doesn't model yet (sharedLocation, datingAndRelationships) + + @Test func `should show the shared location and dating answers App Store Connect sends`() async throws { + let json = #"{"data":{"type":"ageRatingDeclarations","id":"decl-1","attributes":{"socialMedia":false,"sharedLocation":false,"datingAndRelationships":true}},"links":{"self":""}}"# + let stub = StubAPIClient() + stub.willReturn(try JSONDecoder().decode(AgeRatingDeclarationDocument.self, from: Data(json.utf8))) + + let result = try await SDKAgeRatingDeclarationRepository(client: stub).getDeclaration(appInfoId: "info-1") + + #expect(result.isSocialMedia == false) + #expect(result.isSharedLocation == false) + #expect(result.isDatingAndRelationships == true) + } + + @Test func `should send the shared location and dating answers to App Store Connect`() async throws { + let stub = StubAPIClient() + stub.willReturn(AgeRatingDeclarationResponse( + data: AgeRatingDeclaration(type: .ageRatingDeclarations, id: "decl-1"), + links: .init(this: "") + )) + var update = ASCKit.AgeRatingDeclarationUpdate() + update.isSocialMedia = false + update.isSharedLocation = false + update.isDatingAndRelationships = true + + _ = try await SDKAgeRatingDeclarationRepository(client: stub).updateDeclaration(id: "decl-1", update: update) + + let body = try #require(stub.requests.first?.body) + #expect(body == #"{"data":{"attributes":{"datingAndRelationships":true,"developerAgeRatingInfoUrl":null,"kidsAgeBand":null,"sharedLocation":false,"socialMedia":false},"id":"decl-1","type":"ageRatingDeclarations"}}"#) + } +} + +private extension StubAPIClient { + /// Fixtures are written with the SDK's response type; the repository decodes its own + /// document so it can also read the attributes the SDK lacks. + func willReturn(_ response: AgeRatingDeclarationResponse) { + willReturn(AgeRatingDeclarationDocument(response)) + } } diff --git a/docs/commands.md b/docs/commands.md index 5d7a8935..fca94045 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -2927,7 +2927,7 @@ asc age-rating get --app-info-id Update the age rating declaration ``` -asc age-rating update --declaration-id [--advertising ] [--gambling ] [--health-or-wellness-topics ] [--loot-box ] [--messaging-and-chat ] [--parental-controls ] [--age-assurance ] [--unrestricted-web-access ] [--user-generated-content ] [--social-media ] [--social-media-age-restricted ] [--alcohol-tobacco-drugs ] [--contests ] [--gambling-simulated ] [--guns-weapons ] [--medical-treatment ] [--profanity ] [--sexual-content-graphic ] [--sexual-content ] [--horror-fear ] [--mature-suggestive ] [--violence-cartoon ] [--violence-realistic-prolonged ] [--violence-realistic ] [--kids-age-band ] [--age-rating-override ] [--korea-age-rating-override ] [--grac-rating-classification-number ] [--developer-age-rating-info-url ] +asc age-rating update --declaration-id [--advertising ] [--gambling ] [--health-or-wellness-topics ] [--loot-box ] [--messaging-and-chat ] [--parental-controls ] [--age-assurance ] [--unrestricted-web-access ] [--user-generated-content ] [--social-media ] [--social-media-age-restricted ] [--shared-location ] [--dating-and-relationships ] [--alcohol-tobacco-drugs ] [--contests ] [--gambling-simulated ] [--guns-weapons ] [--medical-treatment ] [--profanity ] [--sexual-content-graphic ] [--sexual-content ] [--horror-fear ] [--mature-suggestive ] [--violence-cartoon ] [--violence-realistic-prolonged ] [--violence-realistic ] [--kids-age-band ] [--age-rating-override ] [--korea-age-rating-override ] [--grac-rating-classification-number ] [--developer-age-rating-info-url ] ``` | Flag | Required | Default | Description | @@ -2944,6 +2944,8 @@ asc age-rating update --declaration-id [--advertising `, and `--social-media-age-restricted ` when it's `true`. `asc versions check-readiness` reports unanswered questions. REST body keys are `isSocialMedia` and `isSocialMediaAgeRestricted`. +- `--shared-location ` and `--dating-and-relationships ` answer the Shared Location and Dating and Relationships questions (REST body keys `isSharedLocation`, `isDatingAndRelationships`). The SDK doesn't model them yet, so asc reads and writes them itself. +- A new app ("Set Up Age Ratings" on the web) has no saved questionnaire: Apple refuses the first `update` unless it answers every question at once, and names each missing attribute in a 409 `ENTITY_ERROR.ATTRIBUTE.REQUIRED`. - `--developer-age-rating-info-url` links your own age rating information (REST body key `developerAgeRatingInfoUrl`). - Known issue: the SDK always sends `kidsAgeBand` and `developerAgeRatingInfoUrl`, as `null` when unset, so check both after an update if your app uses them.