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]

### 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
Expand Down
8 changes: 8 additions & 0 deletions Sources/ASCCommand/Commands/AgeRating/AgeRatingCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:))
Expand Down
13 changes: 13 additions & 0 deletions Sources/ASCKit/Apps/AppInfos/AgeRatingDeclaration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgeRatingDeclarationDocument>(
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<AgeRatingDeclarationDocument>(
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,
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Loading
Loading