@fantastic.dev/better-stripe 0.83.1 → 0.84.0
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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalV2/binding.d.ts +3 -0
- package/dist/client/billing/renewalV2/binding.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/binding.js +18 -0
- package/dist/client/billing/renewalV2/binding.js.map +1 -0
- package/dist/client/billing/renewalV2/index.d.ts +38 -0
- package/dist/client/billing/renewalV2/index.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/index.js +70 -0
- package/dist/client/billing/renewalV2/index.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/renewal.d.ts +2 -0
- package/dist/client/renewal.d.ts.map +1 -1
- package/dist/client/renewal.js +1 -0
- package/dist/client/renewal.js.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +68 -0
- package/package.json +1 -1
- package/src/client/billing/renewalV2/binding.ts +25 -0
- package/src/client/billing/renewalV2/index.test.ts +414 -0
- package/src/client/billing/renewalV2/index.ts +111 -0
- package/src/client/renewal.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -26,6 +26,12 @@
|
|
|
26
26
|
- Remove internal tracker references from public documentation and add a
|
|
27
27
|
regression check that prevents their reintroduction.
|
|
28
28
|
|
|
29
|
+
## [0.84.0](https://github.com/FantasticDevHQ/better-stripe/compare/v0.83.1...v0.84.0) (2026-10-28)
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
- add compact V2 renewal request bindings ([#404](https://github.com/FantasticDevHQ/better-stripe/issues/404)) ([a64a33c](https://github.com/FantasticDevHQ/better-stripe/commit/a64a33cabf0f0894d100ab72d5d7754643621df1))
|
|
34
|
+
|
|
29
35
|
## [0.83.1](https://github.com/FantasticDevHQ/better-stripe/compare/v0.83.0...v0.83.1) (2026-10-27)
|
|
30
36
|
|
|
31
37
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ billing, and Connect marketplaces. It provides checkout, subscriptions, webhook
|
|
|
5
5
|
syncing, marketplace fees and splits, payouts, refunds, and disputes, with React
|
|
6
6
|
hooks and headless UI components.
|
|
7
7
|
|
|
8
|
-
**Version**: `0.
|
|
8
|
+
**Version**: `0.84.0` <!-- x-release-please-version --> (pre-1.0). API may change between minor versions until 1.0.
|
|
9
9
|
|
|
10
10
|
Connect platforms use the default GA API version. Non-Connect merchants using
|
|
11
11
|
customer-only Accounts v2 need preview access and an explicit preview version.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalV2/binding.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,GAAG,gBAAgB,EACpC,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC,CAkBjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
2
|
+
/** Internal fixed-family encoding. This is consistency, not authorization. */
|
|
3
|
+
export async function renewalBindingV2(family, preimage) {
|
|
4
|
+
// Finish all input capture and canonical bytes before the first await.
|
|
5
|
+
const text = JSON.stringify(renewalSnapshot(["betterstripe-renewal-binding", 2, family, preimage]));
|
|
6
|
+
const bytes = new TextEncoder().encode(text);
|
|
7
|
+
if (bytes.byteLength > 500_000)
|
|
8
|
+
throw new Error("Renewal V2 binding exceeds its UTF-8 preimage budget.");
|
|
9
|
+
const subtle = globalThis.crypto?.subtle;
|
|
10
|
+
if (!subtle || typeof subtle.digest !== "function")
|
|
11
|
+
throw new Error("Renewal V2 requires Web Crypto SHA-256.");
|
|
12
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
13
|
+
if (!(digest instanceof ArrayBuffer) || digest.byteLength !== 32)
|
|
14
|
+
throw new Error("Renewal V2 received an invalid SHA-256 result.");
|
|
15
|
+
const hex = Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
16
|
+
return `${family}:v2:sha256:${hex}`;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalV2/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAoC,EACpC,QAAiB;IAEjB,uEAAuE;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CACzB,eAAe,CAAC,CAAC,8BAA8B,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CACvE,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,KAAK,CAAC,UAAU,GAAG,OAAO;QAC5B,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;IACzC,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU;QAChD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACrD,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC,IAAI,MAAM,CAAC,UAAU,KAAK,EAAE;QAC9D,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CACtD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CACnC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACX,OAAO,GAAG,MAAM,cAAc,GAAG,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type PrepareRenewalPriceReplacementOptions, type PreparedRenewalPriceReplacement } from "../renewalPriceReplacement.js";
|
|
2
|
+
export type PrepareRenewalPriceReplacementV2Options = PrepareRenewalPriceReplacementOptions;
|
|
3
|
+
export type PreparedRenewalPriceReplacementV2 = Omit<PreparedRenewalPriceReplacement, "version" | "requestIdentity"> & {
|
|
4
|
+
version: 2;
|
|
5
|
+
requestIdentity: {
|
|
6
|
+
key: string;
|
|
7
|
+
binding: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** Pure preparation. Protect retained full records under host authorization. */
|
|
11
|
+
export declare function prepareRenewalPriceReplacementV2(options: PrepareRenewalPriceReplacementV2Options): Promise<PreparedRenewalPriceReplacementV2>;
|
|
12
|
+
export type PrepareRenewalScheduleAttachmentV2Options = {
|
|
13
|
+
prepared: unknown;
|
|
14
|
+
apiVersion: string;
|
|
15
|
+
attachKey: string;
|
|
16
|
+
firstDispatchedAt: number;
|
|
17
|
+
};
|
|
18
|
+
export type PreparedRenewalScheduleAttachmentV2 = {
|
|
19
|
+
version: 2;
|
|
20
|
+
stage: "attach";
|
|
21
|
+
scope: "platform";
|
|
22
|
+
apiVersion: string;
|
|
23
|
+
logicalBinding: string;
|
|
24
|
+
method: "POST";
|
|
25
|
+
path: "/v1/subscription_schedules";
|
|
26
|
+
payload: {
|
|
27
|
+
from_subscription: string;
|
|
28
|
+
};
|
|
29
|
+
key: string;
|
|
30
|
+
firstDispatchedAt: number;
|
|
31
|
+
requestIdentity: {
|
|
32
|
+
key: string;
|
|
33
|
+
binding: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** Pure C2 request. No dispatch, receipt, provider qualification or V1 migration. */
|
|
37
|
+
export declare function prepareRenewalScheduleAttachmentV2(options: PrepareRenewalScheduleAttachmentV2Options): Promise<PreparedRenewalScheduleAttachmentV2>;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/billing/renewalV2/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,qCAAqC,EAC1C,KAAK,+BAA+B,EACrC,MAAM,+BAA+B,CAAC;AAMvC,MAAM,MAAM,uCAAuC,GACjD,qCAAqC,CAAC;AACxC,MAAM,MAAM,iCAAiC,GAAG,IAAI,CAClD,+BAA+B,EAC/B,SAAS,GAAG,iBAAiB,CAC9B,GAAG;IACF,OAAO,EAAE,CAAC,CAAC;IACX,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD,CAAC;AAEF,gFAAgF;AAChF,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,uCAAuC,GAC/C,OAAO,CAAC,iCAAiC,CAAC,CAY5C;AAED,MAAM,MAAM,yCAAyC,GAAG;IACtD,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AACF,MAAM,MAAM,mCAAmC,GAAG;IAChD,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD,CAAC;AAWF,qFAAqF;AACrF,wBAAsB,kCAAkC,CACtD,OAAO,EAAE,yCAAyC,GACjD,OAAO,CAAC,mCAAmC,CAAC,CAwC9C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { prepareRenewalPriceReplacement, } from "../renewalPriceReplacement.js";
|
|
3
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
4
|
+
import { supportedVersion, timestamp } from "../renewalAggregate/shared.js";
|
|
5
|
+
import { idempotencyOptions } from "../../core/idempotency.js";
|
|
6
|
+
import { renewalBindingV2 } from "./binding.js";
|
|
7
|
+
/** Pure preparation. Protect retained full records under host authorization. */
|
|
8
|
+
export async function prepareRenewalPriceReplacementV2(options) {
|
|
9
|
+
// Reuse the existing raw constructor's semantic checks, not a stored V1 claim.
|
|
10
|
+
const original = prepareRenewalPriceReplacement(renewalSnapshot(options));
|
|
11
|
+
const { status, preservation, requestIdentity, ...source } = original;
|
|
12
|
+
const bound = { ...source, version: 2 };
|
|
13
|
+
const binding = await renewalBindingV2("renewal", bound);
|
|
14
|
+
return {
|
|
15
|
+
...bound,
|
|
16
|
+
status,
|
|
17
|
+
preservation,
|
|
18
|
+
requestIdentity: { key: requestIdentity.key, binding },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const attachInput = z
|
|
22
|
+
.object({
|
|
23
|
+
prepared: z.unknown(),
|
|
24
|
+
apiVersion: z.string(),
|
|
25
|
+
attachKey: z.string(),
|
|
26
|
+
firstDispatchedAt: timestamp,
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
const record = z.record(z.string(), z.unknown());
|
|
30
|
+
/** Pure C2 request. No dispatch, receipt, provider qualification or V1 migration. */
|
|
31
|
+
export async function prepareRenewalScheduleAttachmentV2(options) {
|
|
32
|
+
// This detached capture includes every option and retained fact before await.
|
|
33
|
+
const args = attachInput.parse(renewalSnapshot(options));
|
|
34
|
+
supportedVersion(args.apiVersion);
|
|
35
|
+
const key = idempotencyOptions(args.attachKey)?.idempotencyKey;
|
|
36
|
+
if (!key)
|
|
37
|
+
throw new Error("Renewal V2 requires an explicit attachment key.");
|
|
38
|
+
const candidate = record.parse(args.prepared);
|
|
39
|
+
if (candidate.version !== 2)
|
|
40
|
+
throw new Error("Renewal V2 requires a V2 preparation.");
|
|
41
|
+
const source = record.parse(candidate.providerSnapshot);
|
|
42
|
+
const identity = record.parse(candidate.requestIdentity);
|
|
43
|
+
const rebuilt = await prepareRenewalPriceReplacementV2({
|
|
44
|
+
subscription: source.subscription,
|
|
45
|
+
targetPrice: source.targetPrice,
|
|
46
|
+
...(source.billingCustomer === undefined
|
|
47
|
+
? {}
|
|
48
|
+
: { billingCustomer: source.billingCustomer }),
|
|
49
|
+
expected: candidate.expected,
|
|
50
|
+
key: z.string().parse(identity.key),
|
|
51
|
+
});
|
|
52
|
+
if (JSON.stringify(renewalSnapshot(rebuilt)) !==
|
|
53
|
+
JSON.stringify(renewalSnapshot(candidate)))
|
|
54
|
+
throw new Error("Renewal V2 preparation does not match its full source.");
|
|
55
|
+
const request = {
|
|
56
|
+
version: 2,
|
|
57
|
+
stage: "attach",
|
|
58
|
+
scope: "platform",
|
|
59
|
+
apiVersion: args.apiVersion,
|
|
60
|
+
logicalBinding: rebuilt.requestIdentity.binding,
|
|
61
|
+
method: "POST",
|
|
62
|
+
path: "/v1/subscription_schedules",
|
|
63
|
+
payload: { from_subscription: rebuilt.expected.subscriptionId },
|
|
64
|
+
key,
|
|
65
|
+
firstDispatchedAt: args.firstDispatchedAt,
|
|
66
|
+
};
|
|
67
|
+
const binding = await renewalBindingV2("renewal-attach", request);
|
|
68
|
+
return { ...request, requestIdentity: { key, binding } };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/client/billing/renewalV2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,8BAA8B,GAG/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAYhD,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,OAAgD;IAEhD,+EAA+E;IAC/E,MAAM,QAAQ,GAAG,8BAA8B,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC;IACtE,MAAM,KAAK,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAU,EAAE,CAAC;IACjD,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO;QACL,GAAG,KAAK;QACR,MAAM;QACN,YAAY;QACZ,eAAe,EAAE,EAAE,GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE;KACvD,CAAC;AACJ,CAAC;AAqBD,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,iBAAiB,EAAE,SAAS;CAC7B,CAAC;KACD,MAAM,EAAE,CAAC;AACZ,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAEjD,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,OAAkD;IAElD,8EAA8E;IAC9E,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC/D,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,SAAS,CAAC,OAAO,KAAK,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,MAAM,gCAAgC,CAAC;QACrD,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QAChD,QAAQ,EACN,SAAS,CAAC,QAA6D;QACzE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;KACpC,CAAC,CAAC;IACH,IACE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAE1C,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,CAAU;QACnB,KAAK,EAAE,QAAiB;QACxB,KAAK,EAAE,UAAmB;QAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,OAAO;QAC/C,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,4BAAqC;QAC3C,OAAO,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,EAAE;QAC/D,GAAG;QACH,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;KAC1C,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAClE,OAAO,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC;AAC3D,CAAC"}
|
|
@@ -2360,6 +2360,14 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
|
|
|
2360
2360
|
preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
|
|
2361
2361
|
requestKey: string;
|
|
2362
2362
|
result?: {
|
|
2363
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2364
|
+
retryable: false;
|
|
2365
|
+
status: "conflict";
|
|
2366
|
+
} | {
|
|
2367
|
+
reason: "policy_invalid";
|
|
2368
|
+
retryable: false;
|
|
2369
|
+
status: "rejected";
|
|
2370
|
+
} | {
|
|
2363
2371
|
operation: {
|
|
2364
2372
|
accountId: string;
|
|
2365
2373
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2370,14 +2378,6 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
|
|
|
2370
2378
|
} | {
|
|
2371
2379
|
enabled: boolean;
|
|
2372
2380
|
status: "unchanged";
|
|
2373
|
-
} | {
|
|
2374
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2375
|
-
retryable: false;
|
|
2376
|
-
status: "conflict";
|
|
2377
|
-
} | {
|
|
2378
|
-
reason: "policy_invalid";
|
|
2379
|
-
retryable: false;
|
|
2380
|
-
status: "rejected";
|
|
2381
2381
|
} | {
|
|
2382
2382
|
reason: "provider_pending";
|
|
2383
2383
|
retryable: true;
|
|
@@ -2388,6 +2388,14 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
|
|
|
2388
2388
|
payload: import("convex/values").VString<string, "required">;
|
|
2389
2389
|
preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
|
|
2390
2390
|
result: import("convex/values").VUnion<{
|
|
2391
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2392
|
+
retryable: false;
|
|
2393
|
+
status: "conflict";
|
|
2394
|
+
} | {
|
|
2395
|
+
reason: "policy_invalid";
|
|
2396
|
+
retryable: false;
|
|
2397
|
+
status: "rejected";
|
|
2398
|
+
} | {
|
|
2391
2399
|
operation: {
|
|
2392
2400
|
accountId: string;
|
|
2393
2401
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2398,14 +2406,6 @@ export declare function setup(amounts?: number[], currency?: string): Promise<{
|
|
|
2398
2406
|
} | {
|
|
2399
2407
|
enabled: boolean;
|
|
2400
2408
|
status: "unchanged";
|
|
2401
|
-
} | {
|
|
2402
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
2403
|
-
retryable: false;
|
|
2404
|
-
status: "conflict";
|
|
2405
|
-
} | {
|
|
2406
|
-
reason: "policy_invalid";
|
|
2407
|
-
retryable: false;
|
|
2408
|
-
status: "rejected";
|
|
2409
2409
|
} | {
|
|
2410
2410
|
reason: "provider_pending";
|
|
2411
2411
|
retryable: true;
|
|
@@ -7215,6 +7215,14 @@ export declare function historical(currency?: string): Promise<{
|
|
|
7215
7215
|
preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
|
|
7216
7216
|
requestKey: string;
|
|
7217
7217
|
result?: {
|
|
7218
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7219
|
+
retryable: false;
|
|
7220
|
+
status: "conflict";
|
|
7221
|
+
} | {
|
|
7222
|
+
reason: "policy_invalid";
|
|
7223
|
+
retryable: false;
|
|
7224
|
+
status: "rejected";
|
|
7225
|
+
} | {
|
|
7218
7226
|
operation: {
|
|
7219
7227
|
accountId: string;
|
|
7220
7228
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -7225,14 +7233,6 @@ export declare function historical(currency?: string): Promise<{
|
|
|
7225
7233
|
} | {
|
|
7226
7234
|
enabled: boolean;
|
|
7227
7235
|
status: "unchanged";
|
|
7228
|
-
} | {
|
|
7229
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7230
|
-
retryable: false;
|
|
7231
|
-
status: "conflict";
|
|
7232
|
-
} | {
|
|
7233
|
-
reason: "policy_invalid";
|
|
7234
|
-
retryable: false;
|
|
7235
|
-
status: "rejected";
|
|
7236
7236
|
} | {
|
|
7237
7237
|
reason: "provider_pending";
|
|
7238
7238
|
retryable: true;
|
|
@@ -7243,6 +7243,14 @@ export declare function historical(currency?: string): Promise<{
|
|
|
7243
7243
|
payload: import("convex/values").VString<string, "required">;
|
|
7244
7244
|
preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
|
|
7245
7245
|
result: import("convex/values").VUnion<{
|
|
7246
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7247
|
+
retryable: false;
|
|
7248
|
+
status: "conflict";
|
|
7249
|
+
} | {
|
|
7250
|
+
reason: "policy_invalid";
|
|
7251
|
+
retryable: false;
|
|
7252
|
+
status: "rejected";
|
|
7253
|
+
} | {
|
|
7246
7254
|
operation: {
|
|
7247
7255
|
accountId: string;
|
|
7248
7256
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -7253,14 +7261,6 @@ export declare function historical(currency?: string): Promise<{
|
|
|
7253
7261
|
} | {
|
|
7254
7262
|
enabled: boolean;
|
|
7255
7263
|
status: "unchanged";
|
|
7256
|
-
} | {
|
|
7257
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7258
|
-
retryable: false;
|
|
7259
|
-
status: "conflict";
|
|
7260
|
-
} | {
|
|
7261
|
-
reason: "policy_invalid";
|
|
7262
|
-
retryable: false;
|
|
7263
|
-
status: "rejected";
|
|
7264
7264
|
} | {
|
|
7265
7265
|
reason: "provider_pending";
|
|
7266
7266
|
retryable: true;
|
|
@@ -2351,14 +2351,6 @@ export declare function large(count?: number, amount?: number): 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 large(count?: number, amount?: number): 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 large(count?: number, amount?: number): 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 large(count?: number, amount?: number): 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;
|
|
@@ -7207,14 +7207,6 @@ export declare function withHistory(count?: number, amount?: number): Promise<{
|
|
|
7207
7207
|
preparationId: import("convex/values").GenericId<"balanceFundingPreparations">;
|
|
7208
7208
|
requestKey: string;
|
|
7209
7209
|
result?: {
|
|
7210
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7211
|
-
retryable: false;
|
|
7212
|
-
status: "conflict";
|
|
7213
|
-
} | {
|
|
7214
|
-
reason: "policy_invalid";
|
|
7215
|
-
retryable: false;
|
|
7216
|
-
status: "rejected";
|
|
7217
|
-
} | {
|
|
7218
7210
|
operation: {
|
|
7219
7211
|
accountId: string;
|
|
7220
7212
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -7225,6 +7217,14 @@ export declare function withHistory(count?: number, amount?: number): Promise<{
|
|
|
7225
7217
|
} | {
|
|
7226
7218
|
enabled: boolean;
|
|
7227
7219
|
status: "unchanged";
|
|
7220
|
+
} | {
|
|
7221
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7222
|
+
retryable: false;
|
|
7223
|
+
status: "conflict";
|
|
7224
|
+
} | {
|
|
7225
|
+
reason: "policy_invalid";
|
|
7226
|
+
retryable: false;
|
|
7227
|
+
status: "rejected";
|
|
7228
7228
|
} | {
|
|
7229
7229
|
reason: "provider_pending";
|
|
7230
7230
|
retryable: true;
|
|
@@ -7235,14 +7235,6 @@ export declare function withHistory(count?: number, amount?: number): Promise<{
|
|
|
7235
7235
|
payload: import("convex/values").VString<string, "required">;
|
|
7236
7236
|
preparationId: import("convex/values").VId<import("convex/values").GenericId<"balanceFundingPreparations">, "required">;
|
|
7237
7237
|
result: import("convex/values").VUnion<{
|
|
7238
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7239
|
-
retryable: false;
|
|
7240
|
-
status: "conflict";
|
|
7241
|
-
} | {
|
|
7242
|
-
reason: "policy_invalid";
|
|
7243
|
-
retryable: false;
|
|
7244
|
-
status: "rejected";
|
|
7245
|
-
} | {
|
|
7246
7238
|
operation: {
|
|
7247
7239
|
accountId: string;
|
|
7248
7240
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -7253,6 +7245,14 @@ export declare function withHistory(count?: number, amount?: number): Promise<{
|
|
|
7253
7245
|
} | {
|
|
7254
7246
|
enabled: boolean;
|
|
7255
7247
|
status: "unchanged";
|
|
7248
|
+
} | {
|
|
7249
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
7250
|
+
retryable: false;
|
|
7251
|
+
status: "conflict";
|
|
7252
|
+
} | {
|
|
7253
|
+
reason: "policy_invalid";
|
|
7254
|
+
retryable: false;
|
|
7255
|
+
status: "rejected";
|
|
7256
7256
|
} | {
|
|
7257
7257
|
reason: "provider_pending";
|
|
7258
7258
|
retryable: true;
|
package/dist/client/renewal.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ export type { RenewalPriceReplacementExpected } from "./billing/renewalReplaceme
|
|
|
5
5
|
export { prepareRenewalScheduleAttachment } from "./billing/renewalAttach/request.js";
|
|
6
6
|
export type { PrepareRenewalScheduleAttachmentOptions, PreparedRenewalScheduleAttachment, } from "./billing/renewalAttach/request.js";
|
|
7
7
|
export type { ReadRenewalPriceReplacementContextOptions } from "./billing/renewalAttach/reader.js";
|
|
8
|
+
export { prepareRenewalPriceReplacementV2, prepareRenewalScheduleAttachmentV2, } from "./billing/renewalV2/index.js";
|
|
9
|
+
export type { PrepareRenewalPriceReplacementV2Options, PreparedRenewalPriceReplacementV2, PrepareRenewalScheduleAttachmentV2Options, PreparedRenewalScheduleAttachmentV2, } from "./billing/renewalV2/index.js";
|
|
8
10
|
//# sourceMappingURL=renewal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renewal.d.ts","sourceRoot":"","sources":["../../src/client/renewal.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,YAAY,EACV,qCAAqC,EACrC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,YAAY,EACV,uCAAuC,EACvC,iCAAiC,GAClC,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EAAE,yCAAyC,EAAE,MAAM,mCAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"renewal.d.ts","sourceRoot":"","sources":["../../src/client/renewal.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,YAAY,EACV,qCAAqC,EACrC,+BAA+B,GAChC,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AAC7F,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AACtF,YAAY,EACV,uCAAuC,EACvC,iCAAiC,GAClC,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EAAE,yCAAyC,EAAE,MAAM,mCAAmC,CAAC;AACnG,OAAO,EACL,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,uCAAuC,EACvC,iCAAiC,EACjC,yCAAyC,EACzC,mCAAmC,GACpC,MAAM,8BAA8B,CAAC"}
|
package/dist/client/renewal.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Public pure renewal preparation functions and their input/result types. */
|
|
2
2
|
export { prepareRenewalPriceReplacement } from "./billing/renewalPriceReplacement.js";
|
|
3
3
|
export { prepareRenewalScheduleAttachment } from "./billing/renewalAttach/request.js";
|
|
4
|
+
export { prepareRenewalPriceReplacementV2, prepareRenewalScheduleAttachmentV2, } from "./billing/renewalV2/index.js";
|
|
4
5
|
//# sourceMappingURL=renewal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renewal.js","sourceRoot":"","sources":["../../src/client/renewal.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAMtF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC"}
|
|
1
|
+
{"version":3,"file":"renewal.js","sourceRoot":"","sources":["../../src/client/renewal.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAMtF,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAMtF,OAAO,EACL,gCAAgC,EAChC,kCAAkC,GACnC,MAAM,8BAA8B,CAAC"}
|
|
@@ -22,6 +22,14 @@ export declare const begin: import("convex/server").RegisteredMutation<"public",
|
|
|
22
22
|
requestKey: string;
|
|
23
23
|
scopeKey: string;
|
|
24
24
|
}, Promise<{
|
|
25
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
26
|
+
retryable: false;
|
|
27
|
+
status: "conflict";
|
|
28
|
+
} | {
|
|
29
|
+
reason: "policy_invalid";
|
|
30
|
+
retryable: false;
|
|
31
|
+
status: "rejected";
|
|
32
|
+
} | {
|
|
25
33
|
operation: {
|
|
26
34
|
accountId: string;
|
|
27
35
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -32,14 +40,6 @@ export declare const begin: import("convex/server").RegisteredMutation<"public",
|
|
|
32
40
|
} | {
|
|
33
41
|
enabled: boolean;
|
|
34
42
|
status: "unchanged";
|
|
35
|
-
} | {
|
|
36
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
37
|
-
retryable: false;
|
|
38
|
-
status: "conflict";
|
|
39
|
-
} | {
|
|
40
|
-
reason: "policy_invalid";
|
|
41
|
-
retryable: false;
|
|
42
|
-
status: "rejected";
|
|
43
43
|
} | {
|
|
44
44
|
reason: "provider_pending";
|
|
45
45
|
retryable: true;
|
|
@@ -395,6 +395,14 @@ export declare const prepare: import("convex/server").RegisteredMutation<"public
|
|
|
395
395
|
requestKey: string;
|
|
396
396
|
scopeKey: string;
|
|
397
397
|
}, Promise<{
|
|
398
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
399
|
+
retryable: false;
|
|
400
|
+
status: "conflict";
|
|
401
|
+
} | {
|
|
402
|
+
reason: "policy_invalid";
|
|
403
|
+
retryable: false;
|
|
404
|
+
status: "rejected";
|
|
405
|
+
} | {
|
|
398
406
|
operation: {
|
|
399
407
|
accountId: string;
|
|
400
408
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -405,14 +413,6 @@ export declare const prepare: import("convex/server").RegisteredMutation<"public
|
|
|
405
413
|
} | {
|
|
406
414
|
enabled: boolean;
|
|
407
415
|
status: "unchanged";
|
|
408
|
-
} | {
|
|
409
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
410
|
-
retryable: false;
|
|
411
|
-
status: "conflict";
|
|
412
|
-
} | {
|
|
413
|
-
reason: "policy_invalid";
|
|
414
|
-
retryable: false;
|
|
415
|
-
status: "rejected";
|
|
416
416
|
} | {
|
|
417
417
|
reason: "provider_pending";
|
|
418
418
|
retryable: true;
|
|
@@ -2,6 +2,14 @@ import type { Infer } from "convex/values";
|
|
|
2
2
|
import type { MutationCtx } from "../_generated/server.js";
|
|
3
3
|
import { prepareArgs, finishPreparationArgs } from "./mutationValidators.js";
|
|
4
4
|
export declare function prepareHandler(ctx: MutationCtx, args: Infer<typeof prepareArgs>): Promise<{
|
|
5
|
+
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
6
|
+
retryable: false;
|
|
7
|
+
status: "conflict";
|
|
8
|
+
} | {
|
|
9
|
+
reason: "policy_invalid";
|
|
10
|
+
retryable: false;
|
|
11
|
+
status: "rejected";
|
|
12
|
+
} | {
|
|
5
13
|
operation: {
|
|
6
14
|
accountId: string;
|
|
7
15
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -12,14 +20,6 @@ export declare function prepareHandler(ctx: MutationCtx, args: Infer<typeof prep
|
|
|
12
20
|
} | {
|
|
13
21
|
enabled: boolean;
|
|
14
22
|
status: "unchanged";
|
|
15
|
-
} | {
|
|
16
|
-
reason: "identity_changed" | "revision_changed" | "scope_busy";
|
|
17
|
-
retryable: false;
|
|
18
|
-
status: "conflict";
|
|
19
|
-
} | {
|
|
20
|
-
reason: "policy_invalid";
|
|
21
|
-
retryable: false;
|
|
22
|
-
status: "rejected";
|
|
23
23
|
} | {
|
|
24
24
|
reason: "provider_pending";
|
|
25
25
|
retryable: true;
|
|
@@ -60,22 +60,6 @@ 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
|
-
} | {
|
|
79
63
|
operation: {
|
|
80
64
|
accountId: string;
|
|
81
65
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -92,6 +76,22 @@ export declare const workflowStartResult: import("convex/values").VUnion<{
|
|
|
92
76
|
version: number;
|
|
93
77
|
};
|
|
94
78
|
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;
|
|
@@ -2351,14 +2351,6 @@ 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
|
-
} | {
|
|
2362
2354
|
operation: {
|
|
2363
2355
|
accountId: string;
|
|
2364
2356
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2369,6 +2361,14 @@ export declare function setupCredits(): 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 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
|
-
} | {
|
|
2390
2382
|
operation: {
|
|
2391
2383
|
accountId: string;
|
|
2392
2384
|
operationId: import("convex/values").GenericId<"balanceFundingOperations">;
|
|
@@ -2397,6 +2389,14 @@ export declare function setupCredits(): 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;
|
|
@@ -144,3 +144,71 @@ redirects and broken connections can leave a remote outcome unknown; callers
|
|
|
144
144
|
must retain the original request identity rather than rotate or resend
|
|
145
145
|
automatically. These transport safeguards do not qualify a renewal provider
|
|
146
146
|
profile or authorize attachment, configuration or entitlement changes.
|
|
147
|
+
|
|
148
|
+
## Additive async V2 preparation
|
|
149
|
+
|
|
150
|
+
Use the explicitly named V2 functions when compact SHA-256 consistency bindings
|
|
151
|
+
are needed. Existing V1 functions and retained V1 records keep their current
|
|
152
|
+
format and synchronous behavior.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import {
|
|
156
|
+
prepareRenewalPriceReplacementV2,
|
|
157
|
+
prepareRenewalScheduleAttachmentV2,
|
|
158
|
+
} from "@fantastic.dev/better-stripe";
|
|
159
|
+
|
|
160
|
+
const preparedV2 = await prepareRenewalPriceReplacementV2({
|
|
161
|
+
subscription: context.subscription,
|
|
162
|
+
targetPrice: context.targetPrice,
|
|
163
|
+
billingCustomer: context.billingCustomer,
|
|
164
|
+
expected,
|
|
165
|
+
key: logicalKey,
|
|
166
|
+
});
|
|
167
|
+
const attachRequestV2 = await prepareRenewalScheduleAttachmentV2({
|
|
168
|
+
prepared: preparedV2,
|
|
169
|
+
apiVersion: context.apiVersion,
|
|
170
|
+
attachKey,
|
|
171
|
+
firstDispatchedAt,
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Both functions are pure. They perform no provider request, generate no key,
|
|
176
|
+
persist no record and establish no provider qualification. The V2 attachment
|
|
177
|
+
builder accepts only a complete V2 preparation. It reconstructs that preparation
|
|
178
|
+
from its full provider snapshot, expected selectors and retained logical key,
|
|
179
|
+
and compares the entire result before constructing the request. A matching
|
|
180
|
+
digest alone is insufficient. V1 preparations are rejected by this builder;
|
|
181
|
+
there is no automatic migration or fallback. Existing V1 projection, receipt
|
|
182
|
+
and configure consumers do not accept V2 records. This release adds preparation
|
|
183
|
+
and request construction only, without a V2 writer or receipt constructor.
|
|
184
|
+
|
|
185
|
+
V2 retains the same raw preparation semantic checks and bounded JSON policy as
|
|
186
|
+
V1. It adds a limit of 500,000 UTF-8 bytes on each exact encoded hash preimage,
|
|
187
|
+
including its domain tuple. A record can therefore fit V1's character limit
|
|
188
|
+
and exceed V2's byte limit. Inputs are captured before awaiting hashing; changes
|
|
189
|
+
to the original caller object during the await cannot change the result. Web
|
|
190
|
+
Crypto SHA-256 must be available. Missing or rejected digest operations fail
|
|
191
|
+
without an alternate algorithm or synchronous fallback.
|
|
192
|
+
|
|
193
|
+
For a fixed family, the hash input is the UTF-8 encoding of the current bounded
|
|
194
|
+
`renewalSnapshot` canonical copy followed by `JSON.stringify`, applied to
|
|
195
|
+
`["betterstripe-renewal-binding", 2, family, completePreimage]`. Object keys use
|
|
196
|
+
the existing ordering, including JavaScript's numeric-index enumeration;
|
|
197
|
+
arrays retain their order and negative zero serializes as zero. The output is
|
|
198
|
+
`family:v2:sha256:` followed by the full 64 lowercase hexadecimal digest.
|
|
199
|
+
Families are selected internally: `renewal` for preparation and
|
|
200
|
+
`renewal-attach` for the attachment request.
|
|
201
|
+
|
|
202
|
+
The preparation preimage contains version, platform scope, expected selectors,
|
|
203
|
+
quantity and complete provider snapshot. Its logical key is separately retained
|
|
204
|
+
and validated, as in V1; changing only that valid key does not change the
|
|
205
|
+
preparation digest. Hosts must protect original key lineage through immutable
|
|
206
|
+
authorization and storage. The attachment preimage binds its entire unsigned
|
|
207
|
+
request, including stage, scope, actual API version, logical binding, POST path,
|
|
208
|
+
complete payload, explicit attachment key and original first-dispatch time.
|
|
209
|
+
Neither digest authenticates a caller, proves provenance, acknowledges a POST
|
|
210
|
+
or guarantees provider replay. Hosts retain the complete original records.
|
|
211
|
+
|
|
212
|
+
These helpers retain ordinary provider and caller metadata within their JSON
|
|
213
|
+
limits. They do not redact, encrypt or certify that input or output is safe to
|
|
214
|
+
log. Do not place secrets in metadata, and protect retained full records.
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
2
|
+
|
|
3
|
+
/** Internal fixed-family encoding. This is consistency, not authorization. */
|
|
4
|
+
export async function renewalBindingV2(
|
|
5
|
+
family: "renewal" | "renewal-attach",
|
|
6
|
+
preimage: unknown,
|
|
7
|
+
): Promise<string> {
|
|
8
|
+
// Finish all input capture and canonical bytes before the first await.
|
|
9
|
+
const text = JSON.stringify(
|
|
10
|
+
renewalSnapshot(["betterstripe-renewal-binding", 2, family, preimage]),
|
|
11
|
+
);
|
|
12
|
+
const bytes = new TextEncoder().encode(text);
|
|
13
|
+
if (bytes.byteLength > 500_000)
|
|
14
|
+
throw new Error("Renewal V2 binding exceeds its UTF-8 preimage budget.");
|
|
15
|
+
const subtle = globalThis.crypto?.subtle;
|
|
16
|
+
if (!subtle || typeof subtle.digest !== "function")
|
|
17
|
+
throw new Error("Renewal V2 requires Web Crypto SHA-256.");
|
|
18
|
+
const digest = await subtle.digest("SHA-256", bytes);
|
|
19
|
+
if (!(digest instanceof ArrayBuffer) || digest.byteLength !== 32)
|
|
20
|
+
throw new Error("Renewal V2 received an invalid SHA-256 result.");
|
|
21
|
+
const hex = Array.from(new Uint8Array(digest), (byte) =>
|
|
22
|
+
byte.toString(16).padStart(2, "0"),
|
|
23
|
+
).join("");
|
|
24
|
+
return `${family}:v2:sha256:${hex}`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import { createHash, webcrypto } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
prepareRenewalPriceReplacementV2 as prepare,
|
|
5
|
+
prepareRenewalScheduleAttachmentV2 as attach,
|
|
6
|
+
} from "./index.js";
|
|
7
|
+
import { prepareRenewalPriceReplacement as legacy } from "../renewalPriceReplacement.js";
|
|
8
|
+
import { prepareRenewalScheduleAttachment as legacyAttach } from "../renewalAttach/request.js";
|
|
9
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
10
|
+
|
|
11
|
+
const apiVersion = "2026-09-30.endive";
|
|
12
|
+
const firstDispatchedAt = 1700000001;
|
|
13
|
+
const c = (v: unknown) => JSON.stringify(renewalSnapshot(v));
|
|
14
|
+
const digest = (family: string, v: unknown) =>
|
|
15
|
+
`${family}:v2:sha256:${createHash("sha256")
|
|
16
|
+
.update(c(["betterstripe-renewal-binding", 2, family, v]), "utf8")
|
|
17
|
+
.digest("hex")}`;
|
|
18
|
+
const unsigned = (p: any) => {
|
|
19
|
+
const {
|
|
20
|
+
status: _status,
|
|
21
|
+
preservation: _preservation,
|
|
22
|
+
requestIdentity: _requestIdentity,
|
|
23
|
+
...bound
|
|
24
|
+
} = p;
|
|
25
|
+
return bound;
|
|
26
|
+
};
|
|
27
|
+
const args = (prepared: any) => ({
|
|
28
|
+
prepared,
|
|
29
|
+
apiVersion,
|
|
30
|
+
attachKey: "attach:explicit",
|
|
31
|
+
firstDispatchedAt,
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
34
|
+
it("constructs exact C1 bytes and all original semantic facts", async () => {
|
|
35
|
+
const raw = input();
|
|
36
|
+
const old = legacy(raw);
|
|
37
|
+
const p = await prepare(raw);
|
|
38
|
+
expect(p).toEqual({
|
|
39
|
+
...old,
|
|
40
|
+
version: 2,
|
|
41
|
+
requestIdentity: {
|
|
42
|
+
key: old.requestIdentity.key,
|
|
43
|
+
binding: digest("renewal", { ...unsigned(old), version: 2 }),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
expect(old.version).toBe(1);
|
|
47
|
+
expect(old.requestIdentity.binding.startsWith("renewal:v1:")).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it("constructs exact complete C2 request, key and first-dispatch bytes", async () => {
|
|
50
|
+
const p: any = await prepare(input());
|
|
51
|
+
const r = await attach(args(p));
|
|
52
|
+
const { requestIdentity, ...body } = r;
|
|
53
|
+
expect(body).toEqual({
|
|
54
|
+
version: 2,
|
|
55
|
+
stage: "attach",
|
|
56
|
+
scope: "platform",
|
|
57
|
+
apiVersion,
|
|
58
|
+
logicalBinding: p.requestIdentity.binding,
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/v1/subscription_schedules",
|
|
61
|
+
payload: { from_subscription: "sub_original" },
|
|
62
|
+
key: "attach:explicit",
|
|
63
|
+
firstDispatchedAt,
|
|
64
|
+
});
|
|
65
|
+
expect(requestIdentity).toEqual({
|
|
66
|
+
key: body.key,
|
|
67
|
+
binding: digest("renewal-attach", body),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it.each([
|
|
71
|
+
"scope",
|
|
72
|
+
"version",
|
|
73
|
+
"status",
|
|
74
|
+
"preservation",
|
|
75
|
+
"quantity",
|
|
76
|
+
"expected",
|
|
77
|
+
"providerSnapshot",
|
|
78
|
+
"requestIdentity",
|
|
79
|
+
"extra",
|
|
80
|
+
])(
|
|
81
|
+
"rejects tampered retained prepared %s by full recomputation",
|
|
82
|
+
async (field) => {
|
|
83
|
+
const p: any = await prepare(input());
|
|
84
|
+
if (field === "scope") p.scope = "connected";
|
|
85
|
+
else if (field === "version") p.version = 1;
|
|
86
|
+
else if (field === "quantity") p.quantity = 99;
|
|
87
|
+
else if (field === "expected") p.expected.targetPriceId = "price_foreign";
|
|
88
|
+
else if (field === "providerSnapshot")
|
|
89
|
+
p.providerSnapshot.subscription.metadata.original = "changed";
|
|
90
|
+
else if (field === "requestIdentity")
|
|
91
|
+
p.requestIdentity.binding = "renewal:v2:sha256:" + "0".repeat(64);
|
|
92
|
+
else p[field] = "tampered";
|
|
93
|
+
await expect(attach(args(p))).rejects.toThrow();
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
it("does not adopt or migrate a V1 prepared record", async () => {
|
|
97
|
+
await expect(attach(args(legacy(input())))).rejects.toThrow();
|
|
98
|
+
});
|
|
99
|
+
it.each(["method", "path", "scope", "payload", "unexpected"])(
|
|
100
|
+
"rejects caller request override %s",
|
|
101
|
+
async (field) => {
|
|
102
|
+
const a: any = args(await prepare(input()));
|
|
103
|
+
a[field] = field === "method" ? "GET" : "override";
|
|
104
|
+
await expect(attach(a)).rejects.toThrow();
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
it.each(["apiVersion", "attachKey", "firstDispatchedAt"])(
|
|
108
|
+
"binds changed valid C2 %s or rejects unsupported values",
|
|
109
|
+
async (field) => {
|
|
110
|
+
const p: any = await prepare(input());
|
|
111
|
+
const a = args(p);
|
|
112
|
+
const original = await attach(a);
|
|
113
|
+
const changed: any = { ...a };
|
|
114
|
+
if (field === "apiVersion") {
|
|
115
|
+
changed.apiVersion = "2025-01-01.acacia";
|
|
116
|
+
await expect(attach(changed)).rejects.toThrow();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
changed[field] =
|
|
120
|
+
field === "attachKey" ? "attach:second" : firstDispatchedAt + 1;
|
|
121
|
+
expect((await attach(changed)).requestIdentity.binding).not.toBe(
|
|
122
|
+
original.requestIdentity.binding,
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
it.each(["", "\rkey", "x".repeat(256)])(
|
|
127
|
+
"rejects invalid attach key",
|
|
128
|
+
async (key) => {
|
|
129
|
+
await expect(
|
|
130
|
+
attach({ ...args(await prepare(input())), attachKey: key }),
|
|
131
|
+
).rejects.toThrow();
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
it("retains ordinary product metadata including PAN-like and credential-like text", async () => {
|
|
135
|
+
const raw = input();
|
|
136
|
+
raw.subscription.metadata = {
|
|
137
|
+
note: "4111111111111111",
|
|
138
|
+
client_secret: "ordinary synthetic metadata",
|
|
139
|
+
} as any;
|
|
140
|
+
const p = await prepare(raw);
|
|
141
|
+
expect(p.providerSnapshot.subscription.metadata).toEqual(
|
|
142
|
+
raw.subscription.metadata,
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
it("uses reviewed Unicode, numeric-index, escaping and negative-zero bytes", async () => {
|
|
146
|
+
const raw = input();
|
|
147
|
+
raw.subscription.metadata = {
|
|
148
|
+
"10": "ten",
|
|
149
|
+
"2": "two",
|
|
150
|
+
z: "雪😀\ud800",
|
|
151
|
+
a: '"\\\n',
|
|
152
|
+
zero: -0,
|
|
153
|
+
} as any;
|
|
154
|
+
const p = await prepare(raw);
|
|
155
|
+
expect(p.requestIdentity.binding).toBe(digest("renewal", unsigned(p)));
|
|
156
|
+
});
|
|
157
|
+
it.each(["target", "period", "quantity", "mode"])(
|
|
158
|
+
"retains V1 semantic rejection for invalid %s",
|
|
159
|
+
async (kind) => {
|
|
160
|
+
const raw = input();
|
|
161
|
+
if (kind === "target") raw.targetPrice.active = false;
|
|
162
|
+
else if (kind === "period")
|
|
163
|
+
raw.expected.periodEnd = raw.expected.periodStart;
|
|
164
|
+
else if (kind === "quantity") raw.subscription.items.data[0].quantity = 0;
|
|
165
|
+
else raw.targetPrice.livemode = true;
|
|
166
|
+
expect(() => legacy(raw)).toThrow();
|
|
167
|
+
await expect(prepare(raw)).rejects.toThrow();
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
it("captures before awaiting hash and never rereads live input", async () => {
|
|
171
|
+
let release!: () => void;
|
|
172
|
+
let entered!: () => void;
|
|
173
|
+
const started = new Promise<void>((r) => (entered = r));
|
|
174
|
+
const hold = new Promise<void>((r) => (release = r));
|
|
175
|
+
vi.stubGlobal("crypto", {
|
|
176
|
+
subtle: {
|
|
177
|
+
digest: async (name: any, bytes: any) => {
|
|
178
|
+
entered();
|
|
179
|
+
await hold;
|
|
180
|
+
return webcrypto.subtle.digest(name, bytes);
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
const raw = input();
|
|
185
|
+
const original = structuredClone(raw);
|
|
186
|
+
const pending = prepare(raw);
|
|
187
|
+
await Promise.race([started, pending]);
|
|
188
|
+
raw.subscription.metadata.original = "MUTATED";
|
|
189
|
+
raw.expected.targetPriceId = "price_foreign";
|
|
190
|
+
release();
|
|
191
|
+
const result = await pending;
|
|
192
|
+
expect(
|
|
193
|
+
(result.providerSnapshot.subscription.metadata as Record<string, unknown>)
|
|
194
|
+
.original,
|
|
195
|
+
).toBe(original.subscription.metadata.original);
|
|
196
|
+
expect(result.requestIdentity.binding).toBe(
|
|
197
|
+
digest("renewal", unsigned(result)),
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
it("captures full attach record before C1 verification awaits", async () => {
|
|
201
|
+
const p: any = await prepare(input());
|
|
202
|
+
let release!: () => void;
|
|
203
|
+
let entered!: () => void;
|
|
204
|
+
const started = new Promise<void>((r) => (entered = r));
|
|
205
|
+
const hold = new Promise<void>((r) => (release = r));
|
|
206
|
+
vi.stubGlobal("crypto", {
|
|
207
|
+
subtle: {
|
|
208
|
+
digest: async (name: any, bytes: any) => {
|
|
209
|
+
entered();
|
|
210
|
+
await hold;
|
|
211
|
+
return webcrypto.subtle.digest(name, bytes);
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
const a = args(p);
|
|
216
|
+
const pending = attach(a);
|
|
217
|
+
await Promise.race([started, pending]);
|
|
218
|
+
a.attachKey = "changed";
|
|
219
|
+
a.firstDispatchedAt++;
|
|
220
|
+
p.providerSnapshot.subscription.metadata.original = "changed";
|
|
221
|
+
release();
|
|
222
|
+
const r = await pending;
|
|
223
|
+
expect(r.key).toBe("attach:explicit");
|
|
224
|
+
expect(r.firstDispatchedAt).toBe(firstDispatchedAt);
|
|
225
|
+
});
|
|
226
|
+
it.each(["missing", "rejected"])(
|
|
227
|
+
"fails closed with %s WebCrypto and no fallback",
|
|
228
|
+
async (mode) => {
|
|
229
|
+
vi.stubGlobal(
|
|
230
|
+
"crypto",
|
|
231
|
+
mode === "missing"
|
|
232
|
+
? undefined
|
|
233
|
+
: {
|
|
234
|
+
subtle: {
|
|
235
|
+
digest: () =>
|
|
236
|
+
Promise.reject(new Error("synthetic digest refusal")),
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
await expect(prepare(input())).rejects.toThrow();
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
it("enforces UTF8 cap on exact domain tuple at 500000 bytes including domain overhead", async () => {
|
|
244
|
+
const raw = input();
|
|
245
|
+
raw.subscription.metadata = { pad: "" } as any;
|
|
246
|
+
const base = legacy(raw);
|
|
247
|
+
const overhead = Buffer.byteLength(
|
|
248
|
+
c([
|
|
249
|
+
"betterstripe-renewal-binding",
|
|
250
|
+
2,
|
|
251
|
+
"renewal",
|
|
252
|
+
{ ...unsigned(base), version: 2 },
|
|
253
|
+
]),
|
|
254
|
+
"utf8",
|
|
255
|
+
);
|
|
256
|
+
raw.subscription.metadata = { pad: "x".repeat(500000 - overhead) } as any;
|
|
257
|
+
let calls = 0;
|
|
258
|
+
vi.stubGlobal("crypto", {
|
|
259
|
+
subtle: {
|
|
260
|
+
digest: async (n: any, b: any) => {
|
|
261
|
+
calls++;
|
|
262
|
+
expect(b.byteLength).toBeLessThanOrEqual(500000);
|
|
263
|
+
return webcrypto.subtle.digest(n, b);
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
expect((await prepare(raw)).version).toBe(2);
|
|
268
|
+
expect(calls).toBe(1);
|
|
269
|
+
raw.subscription.metadata = { pad: "x".repeat(500001 - overhead) } as any;
|
|
270
|
+
await expect(prepare(raw)).rejects.toThrow();
|
|
271
|
+
expect(calls).toBe(1);
|
|
272
|
+
});
|
|
273
|
+
it("rejects multibyte preimage exceeding UTF8 cap before hashing while V1 character input fits", async () => {
|
|
274
|
+
const raw = input();
|
|
275
|
+
raw.subscription.metadata = { pad: "雪".repeat(170000) } as any;
|
|
276
|
+
expect(legacy(raw).version).toBe(1);
|
|
277
|
+
const spy = vi.fn();
|
|
278
|
+
vi.stubGlobal("crypto", { subtle: { digest: spy } });
|
|
279
|
+
await expect(prepare(raw)).rejects.toThrow();
|
|
280
|
+
expect(spy).not.toHaveBeenCalled();
|
|
281
|
+
});
|
|
282
|
+
it("keeps V1 attach output unchanged", () => {
|
|
283
|
+
const old = legacy(input());
|
|
284
|
+
expect(legacyAttach(args(old))).toMatchObject({
|
|
285
|
+
version: 1,
|
|
286
|
+
scope: "platform",
|
|
287
|
+
payload: { from_subscription: "sub_original" },
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("keeps logical preparation key separate from C1 digest", async () => {
|
|
292
|
+
const a = input();
|
|
293
|
+
const b = input();
|
|
294
|
+
b.key = "another:logical-key";
|
|
295
|
+
const x = await prepare(a),
|
|
296
|
+
y = await prepare(b);
|
|
297
|
+
expect(x.requestIdentity.binding).toBe(y.requestIdentity.binding);
|
|
298
|
+
expect(x.requestIdentity.key).not.toBe(y.requestIdentity.key);
|
|
299
|
+
});
|
|
300
|
+
it("exports additive V2 functions through the actual public SDK barrel", async () => {
|
|
301
|
+
const sdk = await import("../../index.js");
|
|
302
|
+
expect(sdk).toHaveProperty("prepareRenewalPriceReplacementV2", prepare);
|
|
303
|
+
expect(sdk).toHaveProperty("prepareRenewalScheduleAttachmentV2", attach);
|
|
304
|
+
expect(sdk.prepareRenewalPriceReplacement).toBe(legacy);
|
|
305
|
+
expect(sdk).not.toHaveProperty("renewalBindingV2");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it.each(["nonfinite", "cycle", "accessor", "sparse"])(
|
|
309
|
+
"rejects unsupported JSON %s before digest",
|
|
310
|
+
async (kind) => {
|
|
311
|
+
const raw = input() as any;
|
|
312
|
+
const spy = vi.fn();
|
|
313
|
+
vi.stubGlobal("crypto", { subtle: { digest: spy } });
|
|
314
|
+
if (kind === "nonfinite") raw.subscription.metadata = { n: Infinity };
|
|
315
|
+
else if (kind === "cycle") raw.subscription.metadata = raw;
|
|
316
|
+
else if (kind === "accessor") {
|
|
317
|
+
raw.subscription.metadata = {};
|
|
318
|
+
Object.defineProperty(raw.subscription.metadata, "danger", {
|
|
319
|
+
enumerable: true,
|
|
320
|
+
get() {
|
|
321
|
+
throw Error("getter must not execute");
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
} else raw.subscription.metadata = { a: new Array(2) };
|
|
325
|
+
await expect(prepare(raw)).rejects.toThrow();
|
|
326
|
+
expect(spy).not.toHaveBeenCalled();
|
|
327
|
+
},
|
|
328
|
+
);
|
|
329
|
+
it("does not perform network access in either public pure constructor", async () => {
|
|
330
|
+
const fetch = vi.fn(() => {
|
|
331
|
+
throw Error("network forbidden");
|
|
332
|
+
});
|
|
333
|
+
vi.stubGlobal("fetch", fetch);
|
|
334
|
+
const p: any = await prepare(input());
|
|
335
|
+
await attach(args(p));
|
|
336
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it.each(["", "\ninvalid", "k".repeat(256)])(
|
|
340
|
+
"keeps original logical-key validation",
|
|
341
|
+
async (key) => {
|
|
342
|
+
await expect(prepare({ ...input(), key })).rejects.toThrow();
|
|
343
|
+
},
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const expected = {
|
|
347
|
+
customerAccountId: "acct_buyer",
|
|
348
|
+
subscriptionId: "sub_original",
|
|
349
|
+
itemId: "si_original",
|
|
350
|
+
currentPriceId: "price_original",
|
|
351
|
+
currentProductId: "prod_original",
|
|
352
|
+
targetPriceId: "price_target",
|
|
353
|
+
targetProductId: "prod_other",
|
|
354
|
+
periodStart: 1700000000,
|
|
355
|
+
periodEnd: 1702592000,
|
|
356
|
+
livemode: false,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
function price(id = "price_original", product = "prod_original") {
|
|
360
|
+
return {
|
|
361
|
+
id,
|
|
362
|
+
product,
|
|
363
|
+
object: "price",
|
|
364
|
+
active: true,
|
|
365
|
+
livemode: false,
|
|
366
|
+
type: "recurring",
|
|
367
|
+
currency: "usd",
|
|
368
|
+
billing_scheme: "per_unit",
|
|
369
|
+
recurring: { interval: "month", interval_count: 1, usage_type: "licensed" },
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function input() {
|
|
373
|
+
return {
|
|
374
|
+
expected: structuredClone(expected),
|
|
375
|
+
key: "renewal:original-operation",
|
|
376
|
+
subscription: {
|
|
377
|
+
id: "sub_original",
|
|
378
|
+
object: "subscription",
|
|
379
|
+
customer_account: "acct_buyer",
|
|
380
|
+
status: "active",
|
|
381
|
+
currency: "usd",
|
|
382
|
+
livemode: false,
|
|
383
|
+
schedule: null,
|
|
384
|
+
cancel_at: null,
|
|
385
|
+
cancel_at_period_end: false,
|
|
386
|
+
pause_collection: null,
|
|
387
|
+
pending_update: null,
|
|
388
|
+
default_source: null,
|
|
389
|
+
payment_settings: {
|
|
390
|
+
payment_method_options: null,
|
|
391
|
+
payment_method_types: null,
|
|
392
|
+
save_default_payment_method: "off",
|
|
393
|
+
},
|
|
394
|
+
application_fee_percent: null,
|
|
395
|
+
trial_end: 1690000000,
|
|
396
|
+
items: {
|
|
397
|
+
has_more: false,
|
|
398
|
+
data: [
|
|
399
|
+
{
|
|
400
|
+
id: "si_original",
|
|
401
|
+
object: "subscription_item",
|
|
402
|
+
subscription: "sub_original",
|
|
403
|
+
current_period_start: expected.periodStart,
|
|
404
|
+
current_period_end: expected.periodEnd,
|
|
405
|
+
quantity: 3,
|
|
406
|
+
price: price(),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
metadata: { original: "keep" },
|
|
411
|
+
},
|
|
412
|
+
targetPrice: price("price_target", "prod_other"),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
prepareRenewalPriceReplacement,
|
|
4
|
+
type PrepareRenewalPriceReplacementOptions,
|
|
5
|
+
type PreparedRenewalPriceReplacement,
|
|
6
|
+
} from "../renewalPriceReplacement.js";
|
|
7
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
8
|
+
import { supportedVersion, timestamp } from "../renewalAggregate/shared.js";
|
|
9
|
+
import { idempotencyOptions } from "../../core/idempotency.js";
|
|
10
|
+
import { renewalBindingV2 } from "./binding.js";
|
|
11
|
+
|
|
12
|
+
export type PrepareRenewalPriceReplacementV2Options =
|
|
13
|
+
PrepareRenewalPriceReplacementOptions;
|
|
14
|
+
export type PreparedRenewalPriceReplacementV2 = Omit<
|
|
15
|
+
PreparedRenewalPriceReplacement,
|
|
16
|
+
"version" | "requestIdentity"
|
|
17
|
+
> & {
|
|
18
|
+
version: 2;
|
|
19
|
+
requestIdentity: { key: string; binding: string };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Pure preparation. Protect retained full records under host authorization. */
|
|
23
|
+
export async function prepareRenewalPriceReplacementV2(
|
|
24
|
+
options: PrepareRenewalPriceReplacementV2Options,
|
|
25
|
+
): Promise<PreparedRenewalPriceReplacementV2> {
|
|
26
|
+
// Reuse the existing raw constructor's semantic checks, not a stored V1 claim.
|
|
27
|
+
const original = prepareRenewalPriceReplacement(renewalSnapshot(options));
|
|
28
|
+
const { status, preservation, requestIdentity, ...source } = original;
|
|
29
|
+
const bound = { ...source, version: 2 as const };
|
|
30
|
+
const binding = await renewalBindingV2("renewal", bound);
|
|
31
|
+
return {
|
|
32
|
+
...bound,
|
|
33
|
+
status,
|
|
34
|
+
preservation,
|
|
35
|
+
requestIdentity: { key: requestIdentity.key, binding },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type PrepareRenewalScheduleAttachmentV2Options = {
|
|
40
|
+
prepared: unknown;
|
|
41
|
+
apiVersion: string;
|
|
42
|
+
attachKey: string;
|
|
43
|
+
firstDispatchedAt: number;
|
|
44
|
+
};
|
|
45
|
+
export type PreparedRenewalScheduleAttachmentV2 = {
|
|
46
|
+
version: 2;
|
|
47
|
+
stage: "attach";
|
|
48
|
+
scope: "platform";
|
|
49
|
+
apiVersion: string;
|
|
50
|
+
logicalBinding: string;
|
|
51
|
+
method: "POST";
|
|
52
|
+
path: "/v1/subscription_schedules";
|
|
53
|
+
payload: { from_subscription: string };
|
|
54
|
+
key: string;
|
|
55
|
+
firstDispatchedAt: number;
|
|
56
|
+
requestIdentity: { key: string; binding: string };
|
|
57
|
+
};
|
|
58
|
+
const attachInput = z
|
|
59
|
+
.object({
|
|
60
|
+
prepared: z.unknown(),
|
|
61
|
+
apiVersion: z.string(),
|
|
62
|
+
attachKey: z.string(),
|
|
63
|
+
firstDispatchedAt: timestamp,
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
const record = z.record(z.string(), z.unknown());
|
|
67
|
+
|
|
68
|
+
/** Pure C2 request. No dispatch, receipt, provider qualification or V1 migration. */
|
|
69
|
+
export async function prepareRenewalScheduleAttachmentV2(
|
|
70
|
+
options: PrepareRenewalScheduleAttachmentV2Options,
|
|
71
|
+
): Promise<PreparedRenewalScheduleAttachmentV2> {
|
|
72
|
+
// This detached capture includes every option and retained fact before await.
|
|
73
|
+
const args = attachInput.parse(renewalSnapshot(options));
|
|
74
|
+
supportedVersion(args.apiVersion);
|
|
75
|
+
const key = idempotencyOptions(args.attachKey)?.idempotencyKey;
|
|
76
|
+
if (!key) throw new Error("Renewal V2 requires an explicit attachment key.");
|
|
77
|
+
const candidate = record.parse(args.prepared);
|
|
78
|
+
if (candidate.version !== 2)
|
|
79
|
+
throw new Error("Renewal V2 requires a V2 preparation.");
|
|
80
|
+
const source = record.parse(candidate.providerSnapshot);
|
|
81
|
+
const identity = record.parse(candidate.requestIdentity);
|
|
82
|
+
const rebuilt = await prepareRenewalPriceReplacementV2({
|
|
83
|
+
subscription: source.subscription,
|
|
84
|
+
targetPrice: source.targetPrice,
|
|
85
|
+
...(source.billingCustomer === undefined
|
|
86
|
+
? {}
|
|
87
|
+
: { billingCustomer: source.billingCustomer }),
|
|
88
|
+
expected:
|
|
89
|
+
candidate.expected as PrepareRenewalPriceReplacementOptions["expected"],
|
|
90
|
+
key: z.string().parse(identity.key),
|
|
91
|
+
});
|
|
92
|
+
if (
|
|
93
|
+
JSON.stringify(renewalSnapshot(rebuilt)) !==
|
|
94
|
+
JSON.stringify(renewalSnapshot(candidate))
|
|
95
|
+
)
|
|
96
|
+
throw new Error("Renewal V2 preparation does not match its full source.");
|
|
97
|
+
const request = {
|
|
98
|
+
version: 2 as const,
|
|
99
|
+
stage: "attach" as const,
|
|
100
|
+
scope: "platform" as const,
|
|
101
|
+
apiVersion: args.apiVersion,
|
|
102
|
+
logicalBinding: rebuilt.requestIdentity.binding,
|
|
103
|
+
method: "POST" as const,
|
|
104
|
+
path: "/v1/subscription_schedules" as const,
|
|
105
|
+
payload: { from_subscription: rebuilt.expected.subscriptionId },
|
|
106
|
+
key,
|
|
107
|
+
firstDispatchedAt: args.firstDispatchedAt,
|
|
108
|
+
};
|
|
109
|
+
const binding = await renewalBindingV2("renewal-attach", request);
|
|
110
|
+
return { ...request, requestIdentity: { key, binding } };
|
|
111
|
+
}
|
package/src/client/renewal.ts
CHANGED
|
@@ -11,3 +11,13 @@ export type {
|
|
|
11
11
|
PreparedRenewalScheduleAttachment,
|
|
12
12
|
} from "./billing/renewalAttach/request.js";
|
|
13
13
|
export type { ReadRenewalPriceReplacementContextOptions } from "./billing/renewalAttach/reader.js";
|
|
14
|
+
export {
|
|
15
|
+
prepareRenewalPriceReplacementV2,
|
|
16
|
+
prepareRenewalScheduleAttachmentV2,
|
|
17
|
+
} from "./billing/renewalV2/index.js";
|
|
18
|
+
export type {
|
|
19
|
+
PrepareRenewalPriceReplacementV2Options,
|
|
20
|
+
PreparedRenewalPriceReplacementV2,
|
|
21
|
+
PrepareRenewalScheduleAttachmentV2Options,
|
|
22
|
+
PreparedRenewalScheduleAttachmentV2,
|
|
23
|
+
} from "./billing/renewalV2/index.js";
|