Skip to content

Commit 37e4530

Browse files
committed
fix(revenuecat): clear extendByDays default when expiryTimeMs is provided
Mirror the duration/endTimeMs fix from 8204e89: when expiryTimeMs is populated, clear extendByDays in the params mapper so the empty-string form value does not trip the XOR guard. Also harden the tool-level XOR checks in defer_google_subscription and grant_entitlement to treat empty strings as undefined for direct (non-block) callers.
1 parent 8204e89 commit 37e4530

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

apps/sim/blocks/blocks/revenuecat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ Return ONLY the numeric timestamp, no text.`,
403403
}
404404
if (params.expiryTimeMs !== undefined && params.expiryTimeMs !== '') {
405405
next.expiryTimeMs = Number(params.expiryTimeMs)
406+
next.extendByDays = undefined
406407
}
407408
if (params.introductoryPrice !== undefined && params.introductoryPrice !== '') {
408409
next.introductoryPrice = Number(params.introductoryPrice)

apps/sim/tools/revenuecat/defer_google_subscription.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const revenuecatDeferGoogleSubscriptionTool: ToolConfig<
6565
'Content-Type': 'application/json',
6666
}),
6767
body: (params) => {
68-
const hasExtend = params.extendByDays !== undefined
69-
const hasExpiry = params.expiryTimeMs !== undefined
68+
const hasExtend = params.extendByDays !== undefined && (params.extendByDays as unknown) !== ''
69+
const hasExpiry = params.expiryTimeMs !== undefined && (params.expiryTimeMs as unknown) !== ''
7070
if (!hasExtend && !hasExpiry) {
7171
throw new Error('Provide either extendByDays or expiryTimeMs to defer a subscription')
7272
}

apps/sim/tools/revenuecat/grant_entitlement.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ export const revenuecatGrantEntitlementTool: ToolConfig<
6767
'Content-Type': 'application/json',
6868
}),
6969
body: (params) => {
70-
if (!params.duration && params.endTimeMs === undefined) {
70+
const hasEnd = params.endTimeMs !== undefined && (params.endTimeMs as unknown) !== ''
71+
const hasDuration = Boolean(params.duration)
72+
if (!hasDuration && !hasEnd) {
7173
throw new Error('Provide either duration or endTimeMs to grant a promotional entitlement')
7274
}
73-
if (params.duration && params.endTimeMs !== undefined) {
75+
if (hasDuration && hasEnd) {
7476
throw new Error('Provide only one of duration or endTimeMs — they cannot be used together')
7577
}
7678
const body: Record<string, unknown> = {}
77-
if (params.endTimeMs !== undefined) body.end_time_ms = params.endTimeMs
78-
else if (params.duration) body.duration = params.duration
79-
if (params.startTimeMs !== undefined) body.start_time_ms = params.startTimeMs
79+
if (hasEnd) body.end_time_ms = params.endTimeMs
80+
else if (hasDuration) body.duration = params.duration
81+
if (params.startTimeMs !== undefined && (params.startTimeMs as unknown) !== '') {
82+
body.start_time_ms = params.startTimeMs
83+
}
8084
return body
8185
},
8286
},

0 commit comments

Comments
 (0)