@fantastic.dev/better-stripe 0.82.0 → 0.83.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/couponJoins.d.ts +23 -0
  4. package/dist/client/billing/renewalAttach/couponJoins.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/couponJoins.js +76 -0
  6. package/dist/client/billing/renewalAttach/couponJoins.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/index.d.ts +3 -0
  8. package/dist/client/billing/renewalAttach/index.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAttach/index.js +3 -0
  10. package/dist/client/billing/renewalAttach/index.js.map +1 -0
  11. package/dist/client/billing/renewalAttach/reader.d.ts +141 -0
  12. package/dist/client/billing/renewalAttach/reader.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/reader.js +77 -0
  14. package/dist/client/billing/renewalAttach/reader.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/request.d.ts +30 -0
  16. package/dist/client/billing/renewalAttach/request.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/request.js +39 -0
  18. package/dist/client/billing/renewalAttach/request.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/wireJson.d.ts +24 -0
  20. package/dist/client/billing/renewalAttach/wireJson.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/wireJson.js +51 -0
  22. package/dist/client/billing/renewalAttach/wireJson.js.map +1 -0
  23. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  24. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
  25. package/dist/client/helpers.d.ts.map +1 -1
  26. package/dist/client/helpers.js +2 -2
  27. package/dist/client/helpers.js.map +1 -1
  28. package/dist/client/index.d.ts +3 -5
  29. package/dist/client/index.d.ts.map +1 -1
  30. package/dist/client/index.js +3 -3
  31. package/dist/client/index.js.map +1 -1
  32. package/dist/client/renewal.d.ts +8 -0
  33. package/dist/client/renewal.d.ts.map +1 -0
  34. package/dist/client/renewal.js +4 -0
  35. package/dist/client/renewal.js.map +1 -0
  36. package/dist/client/renewalContextClient.d.ts +130 -0
  37. package/dist/client/renewalContextClient.d.ts.map +1 -0
  38. package/dist/client/renewalContextClient.js +10 -0
  39. package/dist/client/renewalContextClient.js.map +1 -0
  40. package/dist/client/singleAttemptHttpClient.d.ts +1 -1
  41. package/dist/client/singleAttemptHttpClient.d.ts.map +1 -1
  42. package/dist/client/singleAttemptHttpClient.js +1 -1
  43. package/dist/client/singleAttemptHttpClient.js.map +1 -1
  44. package/dist/client/strictStripeTransport.d.ts +4 -0
  45. package/dist/client/strictStripeTransport.d.ts.map +1 -0
  46. package/dist/client/strictStripeTransport.js +7 -0
  47. package/dist/client/strictStripeTransport.js.map +1 -0
  48. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  49. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  50. package/dist/component/payoutRelease/queries.d.ts +2 -2
  51. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  52. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  53. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  54. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  55. package/docs/renewal-context-reads.md +146 -0
  56. package/docs/renewal-price-replacements.md +55 -16
  57. package/package.json +1 -1
  58. package/src/client/billing/renewalAttach/couponEvidence.test.ts +103 -0
  59. package/src/client/billing/renewalAttach/couponJoins.ts +92 -0
  60. package/src/client/billing/renewalAttach/index.ts +9 -0
  61. package/src/client/billing/renewalAttach/reader.test.ts +409 -0
  62. package/src/client/billing/renewalAttach/reader.ts +125 -0
  63. package/src/client/billing/renewalAttach/request.ts +49 -0
  64. package/src/client/billing/renewalAttach/wireJson.test.ts +265 -0
  65. package/src/client/billing/renewalAttach/wireJson.ts +75 -0
  66. package/src/client/helpers.ts +2 -4
  67. package/src/client/index.ts +3 -8
  68. package/src/client/renewal.ts +13 -0
  69. package/src/client/renewalContextClient.ts +23 -0
  70. package/src/client/singleAttemptHttpClient.ts +1 -1
  71. package/src/client/strictStripeTransport.test.ts +73 -0
  72. package/src/client/strictStripeTransport.ts +11 -0
@@ -1 +1 @@
1
- {"version":3,"file":"singleAttemptHttpClient.d.ts","sourceRoot":"","sources":["../../src/client/singleAttemptHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAc5B,0EAA0E;AAC1E,qBAAa,uBAAwB,YAAW,MAAM,CAAC,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAArC,YAA6B,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAI;IAE5D,aAAa,IAAI,MAAM,CAEtB;IAEK,WAAW,CACf,GAAG,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,GACpD,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAgB9C;CACF;AAED,iFAAiF;AACjF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAahE"}
1
+ {"version":3,"file":"singleAttemptHttpClient.d.ts","sourceRoot":"","sources":["../../src/client/singleAttemptHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAc5B,4DAA4D;AAC5D,qBAAa,uBAAwB,YAAW,MAAM,CAAC,UAAU;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAArC,YAA6B,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAI;IAE5D,aAAa,IAAI,MAAM,CAEtB;IAEK,WAAW,CACf,GAAG,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,GACpD,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAgB9C;CACF;AAED,iFAAiF;AACjF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAahE"}
@@ -9,7 +9,7 @@ class SingleAttemptConnectionClosed extends Error {
9
9
  this.cause = cause;
10
10
  }
11
11
  }
12
- /** Portal-only adapter for Stripe's closed-connection retry exception. */
12
+ /** Guard for Stripe's closed-connection retry exception. */
13
13
  export class SingleAttemptHttpClient {
14
14
  delegate;
15
15
  constructor(delegate) {
@@ -1 +1 @@
1
- {"version":3,"file":"singleAttemptHttpClient.js","sourceRoot":"","sources":["../../src/client/singleAttemptHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,gFAAgF;AAChF,MAAM,6BAA8B,SAAQ,KAAK;IAEpC,aAAa;IACb,KAAK;IAFhB,YACW,aAAqB,EACrB,KAAc;QAEvB,KAAK,CACH,sHAAsH,CACvH,CAAC;6BALO,aAAa;qBACb,KAAK;IAKhB,CAAC;CACF;AAED,0EAA0E;AAC1E,MAAM,OAAO,uBAAuB;IACL,QAAQ;IAArC,YAA6B,QAA2B;wBAA3B,QAAQ;IAAsB,CAAC;IAE5D,aAAa;QACX,OAAO,kBAAkB,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,WAAW,CACf,GAAG,IAAkD;QAErD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,OAAO,KAAK,KAAK,QAAQ;gBACzB,KAAK,KAAK,IAAI;gBACd,MAAM,IAAI,KAAK;gBACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAC9B,MAAM,CAAC,UAAU,CAAC,6BAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAEpE,iEAAiE;gBACjE,wEAAwE;gBACxE,MAAM,IAAI,6BAA6B,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC7D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,KAAK,CAAC,MAAM,YAAY,6BAA6B;QAErD,OAAO;YACL,IAAI,EAAE,uBAAuB;YAC7B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,aAAa;YAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;SAC9B,CAAC;IACJ,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"singleAttemptHttpClient.js","sourceRoot":"","sources":["../../src/client/singleAttemptHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,gFAAgF;AAChF,MAAM,6BAA8B,SAAQ,KAAK;IAEpC,aAAa;IACb,KAAK;IAFhB,YACW,aAAqB,EACrB,KAAc;QAEvB,KAAK,CACH,sHAAsH,CACvH,CAAC;6BALO,aAAa;qBACb,KAAK;IAKhB,CAAC;CACF;AAED,4DAA4D;AAC5D,MAAM,OAAO,uBAAuB;IACL,QAAQ;IAArC,YAA6B,QAA2B;wBAA3B,QAAQ;IAAsB,CAAC;IAE5D,aAAa;QACX,OAAO,kBAAkB,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,WAAW,CACf,GAAG,IAAkD;QAErD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IACE,OAAO,KAAK,KAAK,QAAQ;gBACzB,KAAK,KAAK,IAAI;gBACd,MAAM,IAAI,KAAK;gBACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAC9B,MAAM,CAAC,UAAU,CAAC,6BAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAEpE,iEAAiE;gBACjE,wEAAwE;gBACxE,MAAM,IAAI,6BAA6B,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC7D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,QAAQ,IAAI,KAAK;QACjB,KAAK,CAAC,MAAM,YAAY,6BAA6B;QAErD,OAAO;YACL,IAAI,EAAE,uBAAuB;YAC7B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,aAAa;YAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;SAC9B,CAAC;IACJ,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,4 @@
1
+ import Stripe from "stripe";
2
+ /** No fetch redirect replay, plus the Stripe closed-connection retry guard. */
3
+ export declare function createSingleAttemptHttpClient(): Stripe.HttpClient;
4
+ //# sourceMappingURL=strictStripeTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strictStripeTransport.d.ts","sourceRoot":"","sources":["../../src/client/strictStripeTransport.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,+EAA+E;AAC/E,wBAAgB,6BAA6B,IAAI,MAAM,CAAC,UAAU,CAMjE"}
@@ -0,0 +1,7 @@
1
+ import Stripe from "stripe";
2
+ import { SingleAttemptHttpClient } from "./singleAttemptHttpClient.js";
3
+ /** No fetch redirect replay, plus the Stripe closed-connection retry guard. */
4
+ export function createSingleAttemptHttpClient() {
5
+ return new SingleAttemptHttpClient(Stripe.createFetchHttpClient((input, init) => fetch(input, { ...init, redirect: "error" })));
6
+ }
7
+ //# sourceMappingURL=strictStripeTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strictStripeTransport.js","sourceRoot":"","sources":["../../src/client/strictStripeTransport.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,+EAA+E;AAC/E,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,uBAAuB,CAChC,MAAM,CAAC,qBAAqB,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAC3C,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAC7C,CACF,CAAC;AACJ,CAAC"}
@@ -9,6 +9,17 @@ export declare const bridge: import("convex/server").RegisteredAction<"internal"
9
9
  stripeSubscriptionId: string;
10
10
  version: number;
11
11
  }, Promise<{
12
+ status: "ready";
13
+ value: {
14
+ customerAccount: string;
15
+ enabled?: boolean | undefined;
16
+ paymentMethodId: string | null;
17
+ paymentMethodTypes?: string[] | null | undefined;
18
+ phase: "apply" | "attach" | "create";
19
+ providerApiVersion: string;
20
+ stripeSubscriptionId: string;
21
+ };
22
+ } | {
12
23
  reason: "history_incomplete" | "provider_outcome_unknown";
13
24
  retryable: false;
14
25
  status: "unknown";
@@ -24,16 +35,5 @@ export declare const bridge: import("convex/server").RegisteredAction<"internal"
24
35
  reason: "provider_pending";
25
36
  retryable: true;
26
37
  status: "not_ready";
27
- } | {
28
- status: "ready";
29
- value: {
30
- customerAccount: string;
31
- enabled?: boolean | undefined;
32
- paymentMethodId: string | null;
33
- paymentMethodTypes?: string[] | null | undefined;
34
- phase: "apply" | "attach" | "create";
35
- providerApiVersion: string;
36
- stripeSubscriptionId: string;
37
- };
38
38
  }>>;
39
39
  //# sourceMappingURL=actions.d.ts.map
@@ -60,6 +60,22 @@ export declare const phaseRef: import("convex/values").VObject<{
60
60
  }, "required", "accountId" | "definitionVersion" | "operationId" | "phase" | "providerApiVersion" | "providerKey" | "scopeKey" | "stripeSubscriptionId" | "version">;
61
61
  export type FundingPhaseRef = Infer<typeof phaseRef>;
62
62
  export declare const workflowStartResult: import("convex/values").VUnion<{
63
+ reason: "history_incomplete" | "provider_outcome_unknown";
64
+ retryable: false;
65
+ status: "unknown";
66
+ } | {
67
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
68
+ retryable: false;
69
+ status: "conflict";
70
+ } | {
71
+ reason: "invalid_scope" | "policy_invalid" | "unsupported_source";
72
+ retryable: false;
73
+ status: "rejected";
74
+ } | {
75
+ reason: "provider_pending";
76
+ retryable: true;
77
+ status: "not_ready";
78
+ } | {
63
79
  operation: {
64
80
  accountId: string;
65
81
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -76,22 +92,6 @@ export declare const workflowStartResult: import("convex/values").VUnion<{
76
92
  version: number;
77
93
  };
78
94
  status: "canceled";
79
- } | {
80
- reason: "history_incomplete" | "provider_outcome_unknown";
81
- retryable: false;
82
- status: "unknown";
83
- } | {
84
- reason: "identity_changed" | "revision_changed" | "scope_busy";
85
- retryable: false;
86
- status: "conflict";
87
- } | {
88
- reason: "invalid_scope" | "policy_invalid" | "unsupported_source";
89
- retryable: false;
90
- status: "rejected";
91
- } | {
92
- reason: "provider_pending";
93
- retryable: true;
94
- status: "not_ready";
95
95
  }, [import("convex/values").VObject<{
96
96
  operation: {
97
97
  accountId: string;
@@ -163,10 +163,10 @@ export declare const snapshot: import("convex/server").RegisteredQuery<"public",
163
163
  accountId: string;
164
164
  ownerKey: string;
165
165
  }, Promise<{
166
- transfers?: undefined;
167
- claims?: undefined;
168
166
  status: "held";
169
167
  reason: "snapshot_limit";
168
+ transfers?: undefined;
169
+ claims?: undefined;
170
170
  } | {
171
171
  reason?: undefined;
172
172
  status: "ready";
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/payoutRelease/queries.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIlB,CAAC;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiBd,CAAC;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;;;;GAQf,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;YAsBE,MAAM;YAAmB,gBAAgB;;;;;YAS3C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE1B,CAAC"}
@@ -14,7 +14,7 @@ export declare function checkRollback(ctx: MutationCtx, op: Doc<"processingCostR
14
14
  readonly bindFunding?: undefined;
15
15
  } | {
16
16
  reason?: undefined;
17
- retryable?: undefined;
17
+ readonly retryable?: undefined;
18
18
  readonly status: "ready";
19
19
  readonly bindFunding: boolean;
20
20
  }>;
@@ -2351,14 +2351,6 @@ export declare function setupAllowance(): Promise<{
2351
2351
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2352
2352
  requestKey: string;
2353
2353
  result?: {
2354
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2355
- retryable: false;
2356
- status: "conflict";
2357
- } | {
2358
- reason: "policy_invalid";
2359
- retryable: false;
2360
- status: "rejected";
2361
- } | {
2362
2354
  operation: {
2363
2355
  accountId: string;
2364
2356
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2369,6 +2361,14 @@ export declare function setupAllowance(): Promise<{
2369
2361
  } | {
2370
2362
  enabled: boolean;
2371
2363
  status: "unchanged";
2364
+ } | {
2365
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2366
+ retryable: false;
2367
+ status: "conflict";
2368
+ } | {
2369
+ reason: "policy_invalid";
2370
+ retryable: false;
2371
+ status: "rejected";
2372
2372
  } | {
2373
2373
  reason: "provider_pending";
2374
2374
  retryable: true;
@@ -2379,14 +2379,6 @@ export declare function setupAllowance(): Promise<{
2379
2379
  payload: import("convex/values").VString<string, "required">;
2380
2380
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2381
2381
  result: import("convex/values").VUnion<{
2382
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2383
- retryable: false;
2384
- status: "conflict";
2385
- } | {
2386
- reason: "policy_invalid";
2387
- retryable: false;
2388
- status: "rejected";
2389
- } | {
2390
2382
  operation: {
2391
2383
  accountId: string;
2392
2384
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2397,6 +2389,14 @@ export declare function setupAllowance(): Promise<{
2397
2389
  } | {
2398
2390
  enabled: boolean;
2399
2391
  status: "unchanged";
2392
+ } | {
2393
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2394
+ retryable: false;
2395
+ status: "conflict";
2396
+ } | {
2397
+ reason: "policy_invalid";
2398
+ retryable: false;
2399
+ status: "rejected";
2400
2400
  } | {
2401
2401
  reason: "provider_pending";
2402
2402
  retryable: true;
@@ -2351,6 +2351,14 @@ export declare function setupCredits(): Promise<{
2351
2351
  preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
2352
2352
  requestKey: string;
2353
2353
  result?: {
2354
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2355
+ retryable: false;
2356
+ status: "conflict";
2357
+ } | {
2358
+ reason: "policy_invalid";
2359
+ retryable: false;
2360
+ status: "rejected";
2361
+ } | {
2354
2362
  operation: {
2355
2363
  accountId: string;
2356
2364
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2361,14 +2369,6 @@ export declare function setupCredits(): Promise<{
2361
2369
  } | {
2362
2370
  enabled: boolean;
2363
2371
  status: "unchanged";
2364
- } | {
2365
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2366
- retryable: false;
2367
- status: "conflict";
2368
- } | {
2369
- reason: "policy_invalid";
2370
- retryable: false;
2371
- status: "rejected";
2372
2372
  } | {
2373
2373
  reason: "provider_pending";
2374
2374
  retryable: true;
@@ -2379,6 +2379,14 @@ export declare function setupCredits(): Promise<{
2379
2379
  payload: import("convex/values").VString<string, "required">;
2380
2380
  preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
2381
2381
  result: import("convex/values").VUnion<{
2382
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
2383
+ retryable: false;
2384
+ status: "conflict";
2385
+ } | {
2386
+ reason: "policy_invalid";
2387
+ retryable: false;
2388
+ status: "rejected";
2389
+ } | {
2382
2390
  operation: {
2383
2391
  accountId: string;
2384
2392
  operationId: import("convex/values").GenericId<"balanceFundingOperations">;
@@ -2389,14 +2397,6 @@ export declare function setupCredits(): Promise<{
2389
2397
  } | {
2390
2398
  enabled: boolean;
2391
2399
  status: "unchanged";
2392
- } | {
2393
- reason: "identity_changed" | "revision_changed" | "scope_busy";
2394
- retryable: false;
2395
- status: "conflict";
2396
- } | {
2397
- reason: "policy_invalid";
2398
- retryable: false;
2399
- status: "rejected";
2400
2400
  } | {
2401
2401
  reason: "provider_pending";
2402
2402
  retryable: true;
@@ -0,0 +1,146 @@
1
+ # Renewal context reads and attachment request preparation
2
+
3
+ `BetterStripe.readRenewalPriceReplacementContext` reads the original provider
4
+ subscription, authorized target price and correlated billing Customer. Hosts
5
+ must authorize the caller and exact original selectors before invoking it on
6
+ the server. This method does not create or update provider resources, persist
7
+ operation ownership or establish financial preservation.
8
+
9
+ ```ts
10
+ const context = await betterStripe.readRenewalPriceReplacementContext(ctx, {
11
+ expected,
12
+ });
13
+ const prepared = prepareRenewalPriceReplacement({
14
+ subscription: context.subscription,
15
+ targetPrice: context.targetPrice,
16
+ billingCustomer: context.billingCustomer,
17
+ expected,
18
+ key: logicalKey,
19
+ });
20
+ const attachRequest = prepareRenewalScheduleAttachment({
21
+ prepared,
22
+ apiVersion: context.apiVersion,
23
+ attachKey,
24
+ firstDispatchedAt,
25
+ });
26
+ ```
27
+
28
+ The two preparation functions are pure exports. The host supplies and durably
29
+ retains the logical key, explicit attachment key, original first-dispatch time
30
+ and complete records under immutable authorization. An explicitly chosen attach
31
+ key may equal the logical key; no key is silently reused, derived or generated.
32
+ A future configure key must differ from the attachment key.
33
+
34
+ ## Fixed acquisition profile
35
+
36
+ The initial profile supports platform requests using the configured
37
+ `2026-09-30.endive` API and Stripe 23 read shapes. Other versions reject before
38
+ reading. The public class selects the maintained single-attempt client,
39
+ including protection against the SDK's closed-connection special retry; every
40
+ read also requests zero automatic retries. Failures remain visible. There is no
41
+ fallback expansion, alternate endpoint or stale cache after a failed read.
42
+
43
+ The method performs these planned GETs in order:
44
+
45
+ 1. Retrieve the exact subscription with `discounts`, `items.data.discounts`
46
+ and `items.data.price` expanded.
47
+ 2. Retrieve the exact target price.
48
+ 3. Retrieve the actual subscription's Customer, correlated to the authorized
49
+ customer-configured account and mode.
50
+ 4. Retrieve each distinct coupon referenced by the expanded subscription/item
51
+ discounts, in first-occurrence order. Each level is capped at 20 discounts,
52
+ so at most 40 coupon GETs follow the three original reads.
53
+
54
+ Discounts must be expanded and have an actual coupon source. There is no
55
+ Discount retrieval endpoint used here. The item path
56
+ `items.data.discounts.source.coupon` exceeds the provider's four-property
57
+ expansion limit. Explicit coupon GET joins are part of the initial read plan,
58
+ including when a coupon was already expanded. Same-ID undeleted coupon results
59
+ expand string references in the canonical context. If a coupon was already
60
+ expanded, its complete canonical JSON must equal the separate GET result.
61
+ Duration, applicability, unknown fields and ordered arrays must agree; object
62
+ key order does not matter. Minimal expanded references and original-only or
63
+ GET-only fields are conservatively rejected as unsupported read-shape drift.
64
+ The join never merges or overwrites existing full source facts. Repeated
65
+ references are each compared, even when their coupon GET is deduplicated.
66
+ Contradictory available mode facts reject before a coupon GET.
67
+
68
+ All other full JSON fields, array ordering and unknown provider data are
69
+ retained within the existing bounded snapshot policy. No missing values become
70
+ null or empty lists. The result records `readProfile: "renewal-context-v1"`, a
71
+ server observation time and `providerQualification: "required"`. It does not
72
+ promise that multiple reads were atomic or that a context remains fresh later.
73
+ A preparation supplied from a different expansion/read shape must not be
74
+ silently rebound to this profile during a future writer invocation.
75
+
76
+ A nonnull observed `subscription.schedule` is returned as an observation. It is
77
+ not adopted as an acknowledgement of attachment. The existing initial pure
78
+ preparation still requires an unattached original. A later explicit replay of
79
+ an unknown attachment result needs a distinct material-state guard permitting
80
+ the actual nonnull association while preserving the original retained snapshot.
81
+ This reader does not fabricate a null association to bypass that guard.
82
+
83
+ ## Bound request and remaining writer contract
84
+
85
+ The pure builder validates the retained logical preparation and explicit key.
86
+ It binds version, attach stage, platform scope, actual API version, logical
87
+ binding, method/path, complete payload `{ from_subscription: subscriptionId }`,
88
+ key and original first-dispatch time. It generates no phase, metadata, arbitrary
89
+ create option, receipt or provider acknowledgement.
90
+
91
+ No attachment writer is exposed by these helpers. There are currently no
92
+ accepted provider execution profiles. A positive structural preflight remains
93
+ insufficient to authorize a POST; callers cannot unlock one with a qualification
94
+ flag. Direct existing forever discount IDs are representable by the projection
95
+ helpers, while actual mirroring and preservation require separate provider
96
+ qualification. Empty discount reads do not prove suppression versus inheritance
97
+ and remain unsupported at projection preflight, even when the Customer has no
98
+ observed discount. Reading such facts does not qualify their transition.
99
+
100
+ A future writer must reacquire this full scoped context before its one POST.
101
+ Initial dispatch requires no attached schedule. Explicit lost-response replay
102
+ must use the same retained full request/key/time, permit a newly observed
103
+ nonnull association without adopting it by shape, and keep provider conflicts
104
+ visible. A local replay age limit below 24 hours cannot guarantee replay after
105
+ provider pruning. No retries, configure chaining or cancel/release rollback are
106
+ implemented here. A successful future attachment acknowledgement must remain
107
+ `attached_unconfigured`; target pending/effective states require separately
108
+ qualified configuration and observation.
109
+
110
+ See the [replacement contract](renewal-price-replacements.md) and
111
+ [phase assembly](renewal-phase-assembly.md) for baseline, replay and observation
112
+ boundaries. Read comparison is best effort and cannot exclude concurrent
113
+ Dashboard or other provider writers.
114
+
115
+ ## Wire JSON and transport status
116
+
117
+ Renewal reads use Stripe's public `rawRequest` for a fixed set of subscription,
118
+ Price, Customer and coupon GET endpoints. Each resource ID is encoded as one path
119
+ segment. Dot-only coupon IDs `.` and `..` are rejected before dispatch because
120
+ URL parsing would normalize them into different resource paths. The subscription's
121
+ fixed ordered expansion query is in the GET path,
122
+ with no GET body. Callers cannot supply endpoints, headers or expansion options.
123
+ The API version, platform scope and zero automatic network retries remain fixed.
124
+
125
+ Typed Stripe resource methods can convert decimal strings into SDK `Decimal`
126
+ objects. The raw request boundary preserves the parsed wire JSON instead,
127
+ including decimal string spelling, required native Plan fields and unknown
128
+ provider fields. The strict bounded JSON snapshot validator is unchanged. No
129
+ `Decimal.toString()` conversion, financial calculation or selective field
130
+ replacement makes unsupported evidence acceptable. This preserves JSON values,
131
+ not the original response whitespace or numeric token spelling.
132
+
133
+ A fulfilled SDK promise alone does not establish HTTP success. Each renewal
134
+ response must have actual successful transport status metadata. Fetch exposes
135
+ `lastResponse.status`; Node exposes `lastResponse.statusCode`. Missing, malformed,
136
+ contradictory or non-2xx metadata rejects the read. This nonenumerable transport
137
+ metadata stays outside the canonical provider body. Provider errors stay visible,
138
+ and these read checks do not acknowledge a schedule mutation.
139
+
140
+ The shared single-attempt client rejects fetch redirects as well as Stripe's
141
+ closed-connection retry exception. A 307 or 308 cannot silently replay a POST.
142
+ The ordinary client route keeps its existing transport behavior. Rejected
143
+ redirects and broken connections can leave a remote outcome unknown; callers
144
+ must retain the original request identity rather than rotate or resend
145
+ automatically. These transport safeguards do not qualify a renewal provider
146
+ profile or authorize attachment, configuration or entitlement changes.
@@ -169,25 +169,64 @@ field is not proof of a lossless provider transition. The configure mapper must
169
169
  resolve every applicable row before the first mutation; no response-object spread
170
170
  or extra `subscriptions.update` workaround is permitted.
171
171
 
172
- | Original setting | Required mapping or explicit unsupported boundary |
173
- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
174
- | Item and period | Verify complete single-item identity, expanded original price/product, quantity and item period. Keep current start/end and paid item unchanged; bind the target to that exact end. Metered/tiered or missing quantities need a separate supported contract. |
175
- | Null and inheritance | Preserve the distinction between schedule defaults, phase overrides and customer fallback. Extract expanded IDs. Send empty-string clears only for fields declared `Emptyable`; never universally turn null into omission, zero or an empty string. |
176
- | Discounts | Preserve existing discount IDs, order, duration and item/subscription precedence. Omission may inherit customer discounts; an explicit empty-string list suppresses inheritance. Re-redeeming a coupon can restart duration. Establish target-product eligibility and provenance before supporting a discounted transition. |
177
- | Tax | Project only writable enabled/liability values and tax-rate IDs at their original level. Do not copy read-only disabled reasons. Preserve manual versus automatic mode and liability scope; unresolved combinations reject. |
178
- | Trial | Retain historical dates. Active/future trials need an exact phase timeline plus proof of retained `trial_settings`. Never force `trial_end: now`, add a free phase or blindly resend past timestamps. |
179
- | Cancellation | `cancel_at` and `cancel_at_period_end` have no direct phase equivalents. Reject cancellation intent until an exact supported mapping exists. `end_behavior` is not a substitute, and must not clear the original intent. |
180
- | Payment method | Normalize an expanded method to its ID at the same defaults/phase level. Null may mean fallback and is not a writable clear in every location. Do not freeze a customer default into a new explicit override. |
181
- | Legacy sources and payment settings | No direct phase/default write for `default_source` or `payment_settings`. Absence of a write field does not prove Stripe loses the subscription value. Explicit nondefault cases need retained-field proof or fail before attachment; never translate a legacy source to a payment-method ID. |
182
- | Application fee | Phase/default fee writes have a connected-account prerequisite. Nonnull fee, including zero, is outside this platform contract until ownership and retention are qualified. Do not add a connected header or silently drop the fee. |
183
- | Routing | `transfer_data` and `on_behalf_of` are separate from fee ownership. Preserve destination/account IDs and exact percentage/omission semantics where supported. Do not infer zero/full transfer or compute financial splits. |
184
- | Invoice/collection | Preserve collection mode, due-day semantics, issuer/tax IDs and supported custom invoice fields at their original level. Auto-charge null days are not a writable null. Unknown issuer values and unsupported clear/inheritance cases reject. |
185
- | Anchor, billing mode and thresholds | A numeric subscription anchor cannot be copied into a phase enum. Prove unchanged current boundary and target-cadence behavior. Preserve migrated billing mode; map thresholds only when their effect on renewal is supported. No automatic anchor reset. |
186
- | Metadata and extra invoice items | Retain reserved and host metadata without turning subscription metadata into repeated phase-entry changes. Additional invoice items can charge again in a new phase; reject nonempty additions until no-duplicate semantics are supported. |
187
- | Other provider states | Pending updates/setup, pauses, managed billing and special schedules need explicit supported classification. Similar field names are not equivalent. A field missing from the phase schema is a verification gap, not proof it is discarded. |
172
+ | Original setting | Required mapping or explicit unsupported boundary |
173
+ | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
174
+ | Item and period | Verify complete single-item identity, expanded original price/product, quantity and item period. Keep current start/end and paid item unchanged; bind the target to that exact end. Metered/tiered or missing quantities need a separate supported contract. |
175
+ | Null and inheritance | Preserve the distinction between schedule defaults, phase overrides and customer fallback. Extract expanded IDs. Send empty-string clears only for fields declared `Emptyable`; never universally turn null into omission, zero or an empty string. |
176
+ | Discounts | Preserve existing discount IDs, order, duration and item/subscription precedence. Omission and provider empty-string clearing have different write semantics. Current empty discount reads do not prove historical suppression or inheritance; those contexts remain unsupported. Re-redeeming a coupon can restart duration. Establish target-product eligibility and provenance before supporting a discounted transition. |
177
+ | Tax | Project only writable enabled/liability values and tax-rate IDs at their original level. Do not copy read-only disabled reasons. Preserve manual versus automatic mode and liability scope; unresolved combinations reject. |
178
+ | Trial | Retain historical dates. Active/future trials need an exact phase timeline plus proof of retained `trial_settings`. Never force `trial_end: now`, add a free phase or blindly resend past timestamps. |
179
+ | Cancellation | `cancel_at` and `cancel_at_period_end` have no direct phase equivalents. Reject cancellation intent until an exact supported mapping exists. `end_behavior` is not a substitute, and must not clear the original intent. |
180
+ | Payment method | Normalize an expanded method to its ID at the same defaults/phase level. Null may mean fallback and is not a writable clear in every location. Do not freeze a customer default into a new explicit override. |
181
+ | Legacy sources and payment settings | No direct phase/default write for `default_source` or `payment_settings`. Absence of a write field does not prove Stripe loses the subscription value. Explicit nondefault cases need retained-field proof or fail before attachment; never translate a legacy source to a payment-method ID. |
182
+ | Application fee | Phase/default fee writes have a connected-account prerequisite. Nonnull fee, including zero, is outside this platform contract until ownership and retention are qualified. Do not add a connected header or silently drop the fee. |
183
+ | Routing | `transfer_data` and `on_behalf_of` are separate from fee ownership. Preserve destination/account IDs and exact percentage/omission semantics where supported. Do not infer zero/full transfer or compute financial splits. |
184
+ | Invoice/collection | Preserve collection mode, due-day semantics, issuer/tax IDs and supported custom invoice fields at their original level. Auto-charge null days are not a writable null. Unknown issuer values and unsupported clear/inheritance cases reject. |
185
+ | Anchor, billing mode and thresholds | A numeric subscription anchor cannot be copied into a phase enum. Prove unchanged current boundary and target-cadence behavior. Preserve migrated billing mode; map thresholds only when their effect on renewal is supported. No automatic anchor reset. |
186
+ | Metadata and extra invoice items | Retain reserved and host metadata without turning subscription metadata into repeated phase-entry changes. Additional invoice items can charge again in a new phase; reject nonempty additions until no-duplicate semantics are supported. |
187
+ | Other provider states | Pending updates/setup, pauses, managed billing and special schedules need explicit supported classification. Similar field names are not equivalent. A field missing from the phase schema is a verification gap, not proof it is discarded. |
188
188
 
189
189
  The completed mapper specification and recovery contract must independently fit
190
190
  the configure/reconciliation ticket's estimate before write implementation starts.
191
191
  Split further when needed, preserving the complete cross-product renewal outcome.
192
192
  Unsupported boundaries must remain visible to the host and in acceptance criteria.
193
193
  Controlled unit tests alone cannot qualify live preservation or consumer policy.
194
+
195
+ ## Provider context reads and retained attachment requests
196
+
197
+ The [renewal context reader](renewal-context-reads.md) acquires a fixed provider
198
+ read profile and prepares an immutable attachment request. It does not attach a
199
+ schedule. Provider qualification and the remaining attachment, configuration and
200
+ observation stages are still required before this becomes a usable replacement
201
+ workflow.
202
+
203
+ ## Unknown configuration outcomes and observation
204
+
205
+ A future explicit replay of an unknown configure result must retain the same
206
+ complete request, key and original first-dispatch time. It may dispatch only
207
+ while the freshly read owned schedule still equals the complete retained
208
+ preconfigure baseline, preserved defaults and original subscription material,
209
+ and elapsed time is less than 24 hours. This local limit is not permanent
210
+ provider replay assurance. A changed or already applied schedule is handed to
211
+ observation; it must not be reprojected into another initial request.
212
+
213
+ A provider GET is not a POST acknowledgement. Sufficient exact provider evidence
214
+ may eventually recover pending or effective state without an acknowledgement;
215
+ otherwise the outcome remains unknown. If a configure acknowledgement exists,
216
+ retain its complete canonical baseline and correlate subsequent observations
217
+ with it. Pending requires the exact future phase, original boundary, current
218
+ paid terms/defaults and linked buyer/subscription.
219
+ Effective state while the target phase is current requires a unique authorized
220
+ target item, matching quantity, currency, applicable period/settings and owned
221
+ phase/subscription relation. Do not require the old item ID to survive a price
222
+ transition. Before implementing this observer, define and independently review
223
+ fixed normalization covering the full retained desired request and
224
+ provider-computed phase-end/duration evidence. Context reading does not provide
225
+ that observer normalization.
226
+
227
+ Canceled, released or completed facts alone do not prove effectiveness. Manual
228
+ release, missing historical correlation, matching price or wall time leave
229
+ causal effectiveness unknown. Preserve acknowledged receipts through read
230
+ failure. No automatic replay, key rotation, stage chaining, cancel/release or
231
+ rollback follows an unknown result. Snapshot equality is not atomic provider
232
+ compare-and-swap or proof that other writers were excluded.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.82.0",
3
+ "version": "0.83.1",
4
4
  "description": "Convex component for Stripe Accounts v2, subscriptions, metered billing and Connect marketplaces, with React workflows.",
5
5
  "keywords": [
6
6
  "stripe",
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import Stripe from "stripe";
3
+ import { joinRenewalCoupons } from "./couponJoins.js";
4
+ const apiVersion = "2026-09-30.endive";
5
+ const baseline = {
6
+ id: "custom-offer",
7
+ object: "coupon",
8
+ livemode: false,
9
+ duration: "forever",
10
+ applies_to: { products: ["current", "target"] },
11
+ };
12
+ const expanded = (coupon: unknown, id = "di_original") => ({
13
+ discounts: [{ id, object: "discount", source: { type: "coupon", coupon } }],
14
+ });
15
+ function controlled(value: unknown) {
16
+ const calls: string[] = [];
17
+ const stripe = new Stripe("sk_test_SYNTHETIC", {
18
+ apiVersion,
19
+ maxNetworkRetries: 0,
20
+ httpClient: {
21
+ getClientName: () => "controlled-coupon-evidence",
22
+ async makeRequest(_host, _port, path, method) {
23
+ calls.push(`${method} ${path}`);
24
+ return {
25
+ getStatusCode: () => 200,
26
+ getHeaders: () => ({
27
+ "request-id": "req_synthetic",
28
+ "stripe-version": apiVersion,
29
+ }),
30
+ toJSON: async () => structuredClone(value),
31
+ getRawResponse: () => ({ statusCode: 200 }),
32
+ toStream: () => null,
33
+ } as unknown as Stripe.HttpClientResponse;
34
+ },
35
+ },
36
+ });
37
+ return {
38
+ calls,
39
+ join: (source: unknown, item: unknown = { discounts: [] }) =>
40
+ joinRenewalCoupons(
41
+ stripe,
42
+ source as Record<string, unknown>,
43
+ item as Record<string, unknown>,
44
+ false,
45
+ ),
46
+ };
47
+ }
48
+ describe("expanded coupon full evidence equality", () => {
49
+ it.each([
50
+ ["duration", { ...baseline, duration: "once" }, baseline],
51
+ [
52
+ "applicability",
53
+ { ...baseline, applies_to: { products: ["current"] } },
54
+ baseline,
55
+ ],
56
+ [
57
+ "original-only unknown fact",
58
+ { ...baseline, unknown_provider_fact: { retained: "original" } },
59
+ baseline,
60
+ ],
61
+ [
62
+ "minimal expanded reference",
63
+ { id: baseline.id, object: "coupon" },
64
+ baseline,
65
+ ],
66
+ [
67
+ "fresh-only unknown fact",
68
+ baseline,
69
+ { ...baseline, unknown_provider_fact: "fresh" },
70
+ ],
71
+ [
72
+ "ordered applicability",
73
+ { ...baseline, applies_to: { products: ["target", "current"] } },
74
+ baseline,
75
+ ],
76
+ ])(
77
+ "rejects %s drift instead of replacing original facts",
78
+ async (_label, original, fetched) => {
79
+ const h = controlled(fetched);
80
+ await expect(h.join(expanded(original))).rejects.toThrow();
81
+ expect(h.calls).toEqual(["GET /v1/coupons/custom-offer"]);
82
+ },
83
+ );
84
+ it("retains full equal unknown facts and tolerates object-key order", async () => {
85
+ const extra = { nested: ["retained", 0] };
86
+ const original = { ...baseline, unknown_provider_fact: extra };
87
+ const fetched = { unknown_provider_fact: extra, ...baseline };
88
+ const h = controlled(fetched);
89
+ const result = await h.join(expanded(original));
90
+ expect(result.subscriptionDiscounts[0].source.coupon).toEqual(original);
91
+ expect(h.calls).toHaveLength(1);
92
+ });
93
+ it("checks every expanded reference even when the coupon GET is deduplicated", async () => {
94
+ const h = controlled(baseline);
95
+ await expect(
96
+ h.join(
97
+ expanded(baseline),
98
+ expanded({ ...baseline, duration: "once" }, "di_item"),
99
+ ),
100
+ ).rejects.toThrow();
101
+ expect(h.calls).toHaveLength(1);
102
+ });
103
+ });