Skip to content

Commit 1cd9c22

Browse files
committed
feat: include actual price data in subscriptions_list_prices response
- Add include=subscriptionPricePoint to price API query - Build pricePointMap lookup from included resources - Enrich formatPrice() output with customerPrice and proceeds - Add SubscriptionPriceRelationships model for relationship parsing
1 parent d1725a7 commit 1cd9c22

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

Sources/asc-mcp/Models/Subscriptions/SubscriptionModels.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public struct SubscriptionLocalizationAttributes: Codable, Sendable {
6363
/// Subscription prices list response
6464
public struct ASCSubscriptionPricesResponse: Codable, Sendable {
6565
public let data: [ASCSubscriptionPrice]
66+
public let included: [ASCSubscriptionPricePoint]?
6667
public let links: ASCPagedDocumentLinks?
6768
}
6869

@@ -71,6 +72,16 @@ public struct ASCSubscriptionPrice: Codable, Sendable {
7172
public let type: String
7273
public let id: String
7374
public let attributes: SubscriptionPriceAttributes?
75+
public let relationships: SubscriptionPriceRelationships?
76+
}
77+
78+
/// Subscription price relationships
79+
public struct SubscriptionPriceRelationships: Codable, Sendable {
80+
public let subscriptionPricePoint: RelationshipData?
81+
82+
public struct RelationshipData: Codable, Sendable {
83+
public let data: ASCResourceIdentifier?
84+
}
7485
}
7586

7687
/// Subscription price attributes

Sources/asc-mcp/Workers/SubscriptionsWorker/SubscriptionsWorker+Handlers.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ extension SubscriptionsWorker {
414414
let parsed = parsePaginationUrl(nextUrl) {
415415
response = try await httpClient.get(parsed.path, parameters: parsed.parameters, as: ASCSubscriptionPricesResponse.self)
416416
} else {
417-
var queryParams: [String: String] = [:]
417+
var queryParams: [String: String] = [
418+
"include": "subscriptionPricePoint",
419+
"fields[subscriptionPricePoints]": "customerPrice,proceeds"
420+
]
418421

419422
if let limit = arguments["limit"]?.intValue {
420423
queryParams["limit"] = String(min(max(limit, 1), 200))
@@ -429,7 +432,15 @@ extension SubscriptionsWorker {
429432
)
430433
}
431434

432-
let prices = response.data.map { formatPrice($0) }
435+
// Build price point lookup from included resources
436+
var pricePointMap: [String: ASCSubscriptionPricePoint] = [:]
437+
if let included = response.included {
438+
for point in included {
439+
pricePointMap[point.id] = point
440+
}
441+
}
442+
443+
let prices = response.data.map { formatPrice($0, pricePointMap: pricePointMap) }
433444

434445
var result: [String: Any] = [
435446
"success": true,
@@ -694,13 +705,22 @@ extension SubscriptionsWorker {
694705
]
695706
}
696707

697-
private func formatPrice(_ price: ASCSubscriptionPrice) -> [String: Any] {
698-
return [
708+
private func formatPrice(_ price: ASCSubscriptionPrice, pricePointMap: [String: ASCSubscriptionPricePoint] = [:]) -> [String: Any] {
709+
var result: [String: Any] = [
699710
"id": price.id,
700711
"type": price.type,
701712
"startDate": price.attributes?.startDate.jsonSafe ?? NSNull(),
702713
"preserved": price.attributes?.preserved.jsonSafe ?? NSNull()
703714
]
715+
716+
// Enrich with price point data if available
717+
if let pricePointId = price.relationships?.subscriptionPricePoint?.data?.id,
718+
let pricePoint = pricePointMap[pricePointId] {
719+
result["customerPrice"] = pricePoint.attributes?.customerPrice.jsonSafe ?? NSNull()
720+
result["proceeds"] = pricePoint.attributes?.proceeds.jsonSafe ?? NSNull()
721+
}
722+
723+
return result
704724
}
705725

706726
private func formatPricePoint(_ point: ASCSubscriptionPricePoint) -> [String: Any] {

0 commit comments

Comments
 (0)