@fantastic.dev/better-stripe 0.87.0 → 0.88.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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAggregate/readMaterial.d.ts.map +1 -1
- package/dist/client/billing/renewalAggregate/readMaterial.js +4 -3
- package/dist/client/billing/renewalAggregate/readMaterial.js.map +1 -1
- package/dist/client/billing/renewalObservation/active-scheduled.d.ts +6 -0
- package/dist/client/billing/renewalObservation/active-scheduled.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/active-scheduled.js +37 -0
- package/dist/client/billing/renewalObservation/active-scheduled.js.map +1 -0
- package/dist/client/billing/renewalObservation/common.d.ts +47 -0
- package/dist/client/billing/renewalObservation/common.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/common.js +39 -0
- package/dist/client/billing/renewalObservation/common.js.map +1 -0
- package/dist/client/billing/renewalObservation/configured-baseline.d.ts +76 -0
- package/dist/client/billing/renewalObservation/configured-baseline.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/configured-baseline.js +26 -0
- package/dist/client/billing/renewalObservation/configured-baseline.js.map +1 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts +53 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.js +103 -0
- package/dist/client/billing/renewalObservation/coupon-discount-joins.js.map +1 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts +52 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.js +49 -0
- package/dist/client/billing/renewalObservation/invoice-tax-identity.js.map +1 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.d.ts +76 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.js +36 -0
- package/dist/client/billing/renewalObservation/pending-and-stage.js.map +1 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts +57 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.js +70 -0
- package/dist/client/billing/renewalObservation/phase-price-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/planProjection.d.ts +8 -0
- package/dist/client/billing/renewalObservation/planProjection.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/planProjection.js +150 -0
- package/dist/client/billing/renewalObservation/planProjection.js.map +1 -0
- package/dist/client/billing/renewalObservation/reference-catalog.d.ts +37 -0
- package/dist/client/billing/renewalObservation/reference-catalog.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/reference-catalog.js +109 -0
- package/dist/client/billing/renewalObservation/reference-catalog.js.map +1 -0
- package/dist/client/billing/renewalObservation/schedule-templates.d.ts +74 -0
- package/dist/client/billing/renewalObservation/schedule-templates.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/schedule-templates.js +72 -0
- package/dist/client/billing/renewalObservation/schedule-templates.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-context.d.ts +44 -0
- package/dist/client/billing/renewalObservation/scheduled-context.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-context.js +64 -0
- package/dist/client/billing/renewalObservation/scheduled-context.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.d.ts +53 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.js +95 -0
- package/dist/client/billing/renewalObservation/scheduled-identity.js.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts +59 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.js +29 -0
- package/dist/client/billing/renewalObservation/scheduled-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/settings-normalization.d.ts +54 -0
- package/dist/client/billing/renewalObservation/settings-normalization.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/settings-normalization.js +53 -0
- package/dist/client/billing/renewalObservation/settings-normalization.js.map +1 -0
- package/dist/client/billing/renewalObservation/stage-runner.d.ts +4 -0
- package/dist/client/billing/renewalObservation/stage-runner.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/stage-runner.js +34 -0
- package/dist/client/billing/renewalObservation/stage-runner.js.map +1 -0
- package/dist/client/billing/renewalObservation/weeklyPending.d.ts +13 -0
- package/dist/client/billing/renewalObservation/weeklyPending.d.ts.map +1 -0
- package/dist/client/billing/renewalObservation/weeklyPending.js +55 -0
- package/dist/client/billing/renewalObservation/weeklyPending.js.map +1 -0
- package/dist/client/billing/renewalPriceReplacement.d.ts.map +1 -1
- package/dist/client/billing/renewalPriceReplacement.js +7 -3
- package/dist/client/billing/renewalPriceReplacement.js.map +1 -1
- package/dist/client/billing/renewalV2/index.d.ts +383 -0
- package/dist/client/billing/renewalV2/index.d.ts.map +1 -1
- package/dist/client/billing/renewalV2/index.js +8 -3
- package/dist/client/billing/renewalV2/index.js.map +1 -1
- package/dist/client/billing/renewalV2/observation.d.ts +19 -0
- package/dist/client/billing/renewalV2/observation.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/observation.js +95 -0
- package/dist/client/billing/renewalV2/observation.js.map +1 -0
- package/dist/client/billing/renewalV2/observationInput.d.ts +77 -0
- package/dist/client/billing/renewalV2/observationInput.d.ts.map +1 -0
- package/dist/client/billing/renewalV2/observationInput.js +140 -0
- package/dist/client/billing/renewalV2/observationInput.js.map +1 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- 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/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/usage/allowance.fixtures.d.ts +16 -16
- package/docs/client-api.md +26 -0
- package/docs/renewal-context-reads.md +10 -0
- package/docs/renewal-material-observation.md +124 -0
- package/docs/renewal-phase-assembly.md +7 -0
- package/docs/renewal-price-replacements.md +3 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAggregate/readMaterial.ts +5 -3
- package/src/client/billing/renewalObservation/active-scheduled.ts +67 -0
- package/src/client/billing/renewalObservation/common.ts +83 -0
- package/src/client/billing/renewalObservation/configured-baseline.ts +55 -0
- package/src/client/billing/renewalObservation/coupon-discount-joins.ts +163 -0
- package/src/client/billing/renewalObservation/invoice-tax-identity.ts +65 -0
- package/src/client/billing/renewalObservation/pending-and-stage.ts +89 -0
- package/src/client/billing/renewalObservation/phase-price-normalization.ts +106 -0
- package/src/client/billing/renewalObservation/planProjection.ts +177 -0
- package/src/client/billing/renewalObservation/reference-catalog.ts +150 -0
- package/src/client/billing/renewalObservation/schedule-templates.ts +118 -0
- package/src/client/billing/renewalObservation/scheduled-context.ts +98 -0
- package/src/client/billing/renewalObservation/scheduled-identity.ts +175 -0
- package/src/client/billing/renewalObservation/scheduled-normalization.ts +49 -0
- package/src/client/billing/renewalObservation/settings-normalization.ts +60 -0
- package/src/client/billing/renewalObservation/stage-runner.ts +30 -0
- package/src/client/billing/renewalObservation/weeklyPending.ts +81 -0
- package/src/client/billing/renewalPriceReplacement.ts +7 -3
- package/src/client/billing/renewalV2/index.ts +14 -6
- package/src/client/billing/renewalV2/observation.boundary-review.test.ts +49 -0
- package/src/client/billing/renewalV2/observation.test.ts +334 -0
- package/src/client/billing/renewalV2/observation.ts +149 -0
- package/src/client/billing/renewalV2/observationInput.ts +167 -0
- package/src/client/billing/renewalV2/rawRetention.test.ts +293 -0
- package/src/client/renewal.ts +7 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { renewalSnapshot } from "../renewalReplacementSnapshot.js";
|
|
2
|
+
import { captureConfiguration } from "./configureInput.js";
|
|
3
|
+
import { captureConfigurationReceipt } from "./configureReceipt.js";
|
|
4
|
+
import type {
|
|
5
|
+
ProjectRenewalConfigurationV2Options,
|
|
6
|
+
ConstructRenewalConfigurationReceiptV2Options,
|
|
7
|
+
} from "./index.js";
|
|
8
|
+
export type RenewalScheduleMaterialReads = {
|
|
9
|
+
schedule: unknown;
|
|
10
|
+
subscription: unknown;
|
|
11
|
+
targetPrice: unknown;
|
|
12
|
+
billingCustomer: unknown;
|
|
13
|
+
coupons: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type InspectRenewalScheduleMaterialV2Options = {
|
|
16
|
+
configuration: ProjectRenewalConfigurationV2Options;
|
|
17
|
+
reads: RenewalScheduleMaterialReads;
|
|
18
|
+
configureReceipt?: ConstructRenewalConfigurationReceiptV2Options;
|
|
19
|
+
};
|
|
20
|
+
function stop(): never {
|
|
21
|
+
throw Error("Invalid raw renewal observation.");
|
|
22
|
+
}
|
|
23
|
+
function fields(
|
|
24
|
+
raw: unknown,
|
|
25
|
+
required: string[],
|
|
26
|
+
optional: string[] = [],
|
|
27
|
+
): Record<string, unknown> {
|
|
28
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) stop();
|
|
29
|
+
const p = Object.getPrototypeOf(raw);
|
|
30
|
+
if (p !== Object.prototype && p !== null) stop();
|
|
31
|
+
const keys = Reflect.ownKeys(raw);
|
|
32
|
+
if (
|
|
33
|
+
keys.some(
|
|
34
|
+
(k) => typeof k !== "string" || ![...required, ...optional].includes(k),
|
|
35
|
+
) ||
|
|
36
|
+
required.some((k) => !keys.includes(k))
|
|
37
|
+
)
|
|
38
|
+
stop();
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
keys.map((k) => {
|
|
41
|
+
const d = Object.getOwnPropertyDescriptor(raw, k);
|
|
42
|
+
if (!d || !d.enumerable || !("value" in d)) stop();
|
|
43
|
+
return [k, d.value];
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
/** No getters, toJSON, symbols or hidden properties are stripped on this new raw API. */
|
|
48
|
+
function strictCopy(raw: unknown) {
|
|
49
|
+
let nodes = 0,
|
|
50
|
+
characters = 0;
|
|
51
|
+
const seen = new Set<object>();
|
|
52
|
+
function copy(x: unknown, depth: number): unknown {
|
|
53
|
+
if (++nodes > 10000 || depth > 40) stop();
|
|
54
|
+
if (typeof x === "string") {
|
|
55
|
+
characters += x.length;
|
|
56
|
+
if (characters > 500000) stop();
|
|
57
|
+
return x;
|
|
58
|
+
}
|
|
59
|
+
if (x === null || typeof x === "boolean") return x;
|
|
60
|
+
if (typeof x === "number" && Number.isFinite(x)) return x;
|
|
61
|
+
if (!x || typeof x !== "object" || seen.has(x)) stop();
|
|
62
|
+
const array = Array.isArray(x);
|
|
63
|
+
if (!array) {
|
|
64
|
+
const p = Object.getPrototypeOf(x);
|
|
65
|
+
if (p !== Object.prototype && p !== null) stop();
|
|
66
|
+
}
|
|
67
|
+
seen.add(x);
|
|
68
|
+
const keys = Reflect.ownKeys(x);
|
|
69
|
+
const entries: [string, unknown][] = [];
|
|
70
|
+
const selected = new Map<PropertyKey, unknown>();
|
|
71
|
+
let length = 0;
|
|
72
|
+
if (array) {
|
|
73
|
+
const d = Object.getOwnPropertyDescriptor(x, "length");
|
|
74
|
+
if (
|
|
75
|
+
!d ||
|
|
76
|
+
!("value" in d) ||
|
|
77
|
+
!Number.isSafeInteger(d.value) ||
|
|
78
|
+
d.value < 0 ||
|
|
79
|
+
d.value > 10000
|
|
80
|
+
)
|
|
81
|
+
stop();
|
|
82
|
+
length = d.value;
|
|
83
|
+
}
|
|
84
|
+
for (const k of keys) {
|
|
85
|
+
if (array && k === "length") continue;
|
|
86
|
+
if (typeof k !== "string") stop();
|
|
87
|
+
const d = Object.getOwnPropertyDescriptor(x, k);
|
|
88
|
+
if (!d || !d.enumerable || !("value" in d)) stop();
|
|
89
|
+
characters += k.length;
|
|
90
|
+
if (characters > 500000) stop();
|
|
91
|
+
if (array && (!/^(0|[1-9][0-9]*)$/.test(k) || Number(k) >= length))
|
|
92
|
+
stop();
|
|
93
|
+
selected.set(k, d.value);
|
|
94
|
+
entries.push([k, copy(d.value, depth + 1)]);
|
|
95
|
+
}
|
|
96
|
+
const after = Reflect.ownKeys(x);
|
|
97
|
+
if (after.length !== keys.length || after.some((k, i) => k !== keys[i]))
|
|
98
|
+
stop();
|
|
99
|
+
for (const [k, value] of selected) {
|
|
100
|
+
const d = Object.getOwnPropertyDescriptor(x, k);
|
|
101
|
+
if (!d || !d.enumerable || !("value" in d) || !Object.is(d.value, value))
|
|
102
|
+
stop();
|
|
103
|
+
}
|
|
104
|
+
seen.delete(x);
|
|
105
|
+
if (array) {
|
|
106
|
+
if (entries.length !== length) stop();
|
|
107
|
+
const map = new Map(entries);
|
|
108
|
+
return Array.from({ length }, (_, i) => {
|
|
109
|
+
if (!map.has(String(i))) stop();
|
|
110
|
+
return map.get(String(i));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return Object.fromEntries(entries);
|
|
114
|
+
}
|
|
115
|
+
return copy(raw, 0);
|
|
116
|
+
}
|
|
117
|
+
function capture(raw: unknown) {
|
|
118
|
+
const original = fields(
|
|
119
|
+
raw,
|
|
120
|
+
["configuration", "reads"],
|
|
121
|
+
["configureReceipt"],
|
|
122
|
+
);
|
|
123
|
+
const captured = renewalSnapshot(strictCopy(original));
|
|
124
|
+
const root = fields(
|
|
125
|
+
captured,
|
|
126
|
+
["configuration", "reads"],
|
|
127
|
+
["configureReceipt"],
|
|
128
|
+
);
|
|
129
|
+
if (new TextEncoder().encode(JSON.stringify(captured)).byteLength > 500000)
|
|
130
|
+
stop();
|
|
131
|
+
const configuration = captureConfiguration(root.configuration),
|
|
132
|
+
reads = fields(root.reads, [
|
|
133
|
+
"schedule",
|
|
134
|
+
"subscription",
|
|
135
|
+
"targetPrice",
|
|
136
|
+
"billingCustomer",
|
|
137
|
+
"coupons",
|
|
138
|
+
]);
|
|
139
|
+
for (const body of [
|
|
140
|
+
reads.schedule,
|
|
141
|
+
reads.subscription,
|
|
142
|
+
reads.targetPrice,
|
|
143
|
+
reads.billingCustomer,
|
|
144
|
+
...(Array.isArray(reads.coupons) ? reads.coupons : []),
|
|
145
|
+
])
|
|
146
|
+
if (
|
|
147
|
+
body &&
|
|
148
|
+
typeof body === "object" &&
|
|
149
|
+
Object.prototype.hasOwnProperty.call(body, "lastResponse")
|
|
150
|
+
)
|
|
151
|
+
stop();
|
|
152
|
+
const configureReceipt = Object.prototype.hasOwnProperty.call(
|
|
153
|
+
root,
|
|
154
|
+
"configureReceipt",
|
|
155
|
+
)
|
|
156
|
+
? captureConfigurationReceipt(root.configureReceipt)
|
|
157
|
+
: undefined;
|
|
158
|
+
return { configuration, reads, configureReceipt };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function captureObservation(raw: unknown) {
|
|
162
|
+
try {
|
|
163
|
+
return capture(raw);
|
|
164
|
+
} catch {
|
|
165
|
+
stop();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import { webcrypto } from "node:crypto";
|
|
3
|
+
import * as sdk from "./index.js";
|
|
4
|
+
import { prepareRenewalPriceReplacement as legacy } from "../renewalPriceReplacement.js";
|
|
5
|
+
import { validateReadMaterial } from "../renewalAggregate/readMaterial.js";
|
|
6
|
+
import { fixture } from "../../../../tests/renewalAggregate/fixtures.js";
|
|
7
|
+
import {
|
|
8
|
+
at,
|
|
9
|
+
binding,
|
|
10
|
+
bound,
|
|
11
|
+
configuration,
|
|
12
|
+
expandedInput,
|
|
13
|
+
hash,
|
|
14
|
+
input,
|
|
15
|
+
own,
|
|
16
|
+
owns,
|
|
17
|
+
paths,
|
|
18
|
+
} from "../../../../tests/renewalAggregate/rawRetention.js";
|
|
19
|
+
|
|
20
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
21
|
+
it("records unaffected normal full-output vectors and independent C1 oracle", async () => {
|
|
22
|
+
const raw = input(),
|
|
23
|
+
old = legacy(raw),
|
|
24
|
+
p = await sdk.prepareRenewalPriceReplacementV2(raw);
|
|
25
|
+
expect(p.requestIdentity.binding).toBe(
|
|
26
|
+
binding("renewal", { ...bound(old), version: 2 }),
|
|
27
|
+
);
|
|
28
|
+
const c = configuration(),
|
|
29
|
+
receipt = await sdk.constructRenewalScheduleAttachmentReceiptV2(
|
|
30
|
+
c.attachReceipt,
|
|
31
|
+
),
|
|
32
|
+
projected = await sdk.projectRenewalConfigurationV2(c);
|
|
33
|
+
expect(projected.status).toBe("projected_configure_request");
|
|
34
|
+
expect({
|
|
35
|
+
legacy: hash(old),
|
|
36
|
+
prepared: hash(p),
|
|
37
|
+
receipt: hash(receipt),
|
|
38
|
+
configuration: hash(projected),
|
|
39
|
+
}).toEqual({
|
|
40
|
+
legacy: "ed0e7fe3641e216caf66fd225b1a7366a4a3ab7f2825448ec9fbbf697621e150",
|
|
41
|
+
prepared:
|
|
42
|
+
"4c27c7f4c0f4743d6a5ff3c76da42c024c4f2e29f6bc65b4ad29bb21dfdbc8d3",
|
|
43
|
+
receipt: "dd79636e1248efc8efad99737bcd156d322f3078aea7ecebf007f0d1d953b01c",
|
|
44
|
+
configuration:
|
|
45
|
+
"ef08ad09044c32eaa3152b3a7fe058a68f77edf704c3176ada86cd5c5c6179d8",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it.each(paths.map((path) => ({ path })))(
|
|
49
|
+
"retains and binds safe own proto at passthrough body $path",
|
|
50
|
+
async ({ path }) => {
|
|
51
|
+
const raw = expandedInput(),
|
|
52
|
+
body = at(raw, path as (string | number)[]);
|
|
53
|
+
own(body, "__proto__", { safe: "retained" });
|
|
54
|
+
const expected = {
|
|
55
|
+
subscription: raw.subscription,
|
|
56
|
+
targetPrice: raw.targetPrice,
|
|
57
|
+
billingCustomer: raw.billingCustomer,
|
|
58
|
+
};
|
|
59
|
+
const old = legacy(raw),
|
|
60
|
+
p = await sdk.prepareRenewalPriceReplacementV2(raw);
|
|
61
|
+
expect(old.providerSnapshot).toEqual(expected);
|
|
62
|
+
expect(p.providerSnapshot).toEqual(expected);
|
|
63
|
+
expect(
|
|
64
|
+
owns(at(p.providerSnapshot, path as (string | number)[]), "__proto__"),
|
|
65
|
+
).toBe(true);
|
|
66
|
+
expect(p.requestIdentity.binding).toBe(
|
|
67
|
+
binding("renewal", {
|
|
68
|
+
version: 2,
|
|
69
|
+
scope: "platform",
|
|
70
|
+
expected: raw.expected,
|
|
71
|
+
quantity: raw.subscription.items.data[0].quantity,
|
|
72
|
+
providerSnapshot: expected,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
own(body, "__proto__", { safe: "changed" });
|
|
76
|
+
expect(
|
|
77
|
+
(await sdk.prepareRenewalPriceReplacementV2(raw)).requestIdentity.binding,
|
|
78
|
+
).not.toBe(p.requestIdentity.binding);
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
it.each(["subscription", "targetPrice", "billingCustomer"])(
|
|
82
|
+
"same raw %s special key passes internal read eligibility",
|
|
83
|
+
(field) => {
|
|
84
|
+
const raw: any = input();
|
|
85
|
+
own(raw[field], "__proto__", { safe: "same" });
|
|
86
|
+
const f = fixture();
|
|
87
|
+
const prepared: any = {
|
|
88
|
+
expected: raw.expected,
|
|
89
|
+
quantity: raw.subscription.items.data[0].quantity,
|
|
90
|
+
providerSnapshot: {
|
|
91
|
+
subscription: raw.subscription,
|
|
92
|
+
targetPrice: raw.targetPrice,
|
|
93
|
+
billingCustomer: raw.billingCustomer,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const args = {
|
|
97
|
+
freshSubscription: structuredClone(raw.subscription),
|
|
98
|
+
targetPrice: structuredClone(raw.targetPrice),
|
|
99
|
+
billingCustomer: structuredClone(raw.billingCustomer),
|
|
100
|
+
apiVersion: f.preflightInput.apiVersion,
|
|
101
|
+
observedAt: f.preflightInput.observedAt,
|
|
102
|
+
};
|
|
103
|
+
expect(() => validateReadMaterial(args, prepared)).not.toThrow();
|
|
104
|
+
own(
|
|
105
|
+
(args as any)[field === "subscription" ? "freshSubscription" : field],
|
|
106
|
+
"__proto__",
|
|
107
|
+
{ safe: "drift" },
|
|
108
|
+
);
|
|
109
|
+
expect(() => validateReadMaterial(args, prepared)).toThrow();
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
it.each(["subscription", "targetPrice", "billingCustomer"])(
|
|
113
|
+
"C1 C3 C6 uses identical full raw %s and rejects fresh drift",
|
|
114
|
+
async (field) => {
|
|
115
|
+
const raw: any = input();
|
|
116
|
+
own(raw[field], "__proto__", { safe: "same" });
|
|
117
|
+
const c = configuration(raw);
|
|
118
|
+
expect((await sdk.projectRenewalConfigurationV2(c)).status).toBe(
|
|
119
|
+
"projected_configure_request",
|
|
120
|
+
);
|
|
121
|
+
own(
|
|
122
|
+
c[field === "subscription" ? "freshSubscription" : field],
|
|
123
|
+
"__proto__",
|
|
124
|
+
{ safe: "drift" },
|
|
125
|
+
);
|
|
126
|
+
expect((await sdk.projectRenewalConfigurationV2(c)).status).toBe(
|
|
127
|
+
"conflict",
|
|
128
|
+
);
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
it.each(["constructor", "prototype"])(
|
|
132
|
+
"retains safe own %s without prototype pollution",
|
|
133
|
+
async (key) => {
|
|
134
|
+
const raw: any = input();
|
|
135
|
+
for (const body of [raw.subscription, raw.targetPrice, raw.billingCustomer])
|
|
136
|
+
own(body, key, { prototype: { BTS313_POLLUTED: true } });
|
|
137
|
+
const p = await sdk.prepareRenewalPriceReplacementV2(raw);
|
|
138
|
+
expect(p.providerSnapshot.subscription[key]).toEqual(raw.subscription[key]);
|
|
139
|
+
expect(Object.getPrototypeOf(p.providerSnapshot.subscription)).toBe(
|
|
140
|
+
Object.prototype,
|
|
141
|
+
);
|
|
142
|
+
expect((Object.prototype as any).BTS313_POLLUTED).toBeUndefined();
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
it("keeps opaque unknown nested raw JSON and strict eligibility distinct", async () => {
|
|
146
|
+
const raw: any = input();
|
|
147
|
+
own(raw.subscription.metadata, "__proto__", { opaque: true });
|
|
148
|
+
raw.subscription.items.data[0].plan = { opaque: true };
|
|
149
|
+
own(raw.subscription.items.data[0].plan, "__proto__", { nested: true });
|
|
150
|
+
const p = await sdk.prepareRenewalPriceReplacementV2(raw);
|
|
151
|
+
expect(p.providerSnapshot.subscription.metadata).toEqual(
|
|
152
|
+
raw.subscription.metadata,
|
|
153
|
+
);
|
|
154
|
+
expect((p.providerSnapshot.subscription.items.data[0] as any).plan).toEqual(
|
|
155
|
+
raw.subscription.items.data[0].plan,
|
|
156
|
+
);
|
|
157
|
+
for (const key of ["__proto__", "constructor", "prototype"]) {
|
|
158
|
+
const invalid: any = input();
|
|
159
|
+
own(invalid.subscription.payment_settings, key, { extra: true });
|
|
160
|
+
await expect(
|
|
161
|
+
sdk.prepareRenewalPriceReplacementV2(invalid),
|
|
162
|
+
).rejects.toThrow();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
it("preserves Customer absence and rejects invalid present Customer", async () => {
|
|
166
|
+
const raw: any = input();
|
|
167
|
+
delete raw.billingCustomer;
|
|
168
|
+
expect(
|
|
169
|
+
owns(
|
|
170
|
+
(await sdk.prepareRenewalPriceReplacementV2(raw)).providerSnapshot,
|
|
171
|
+
"billingCustomer",
|
|
172
|
+
),
|
|
173
|
+
).toBe(false);
|
|
174
|
+
raw.billingCustomer = null;
|
|
175
|
+
await expect(sdk.prepareRenewalPriceReplacementV2(raw)).rejects.toThrow();
|
|
176
|
+
});
|
|
177
|
+
it("keeps C3 C4 complete Schedule bodies and C5 raw default preimage", async () => {
|
|
178
|
+
const c = configuration();
|
|
179
|
+
own(c.attachReceipt.providerSnapshot, "__proto__", { schedule: true });
|
|
180
|
+
own(c.schedule, "__proto__", { schedule: true });
|
|
181
|
+
const r = await sdk.constructRenewalScheduleAttachmentReceiptV2(
|
|
182
|
+
c.attachReceipt,
|
|
183
|
+
);
|
|
184
|
+
expect(owns(r.providerSnapshot, "__proto__")).toBe(true);
|
|
185
|
+
expect(r.providerSnapshot).toEqual(c.attachReceipt.providerSnapshot);
|
|
186
|
+
const projected = await sdk.projectRenewalConfigurationV2(c);
|
|
187
|
+
expect(projected.status).toBe("projected_configure_request");
|
|
188
|
+
if (projected.status !== "projected_configure_request")
|
|
189
|
+
throw Error("fixture");
|
|
190
|
+
expect(projected.baselineBinding).toBe(
|
|
191
|
+
binding("renewal-baseline", c.attachReceipt.providerSnapshot),
|
|
192
|
+
);
|
|
193
|
+
expect(projected.defaultSettingsBinding).toBe(
|
|
194
|
+
binding("renewal-defaults", c.schedule.default_settings),
|
|
195
|
+
);
|
|
196
|
+
own(c.schedule.default_settings, "__proto__", { unsupported: true });
|
|
197
|
+
c.attachReceipt.providerSnapshot = structuredClone(c.schedule);
|
|
198
|
+
expect((await sdk.projectRenewalConfigurationV2(c)).status).toBe(
|
|
199
|
+
"attached_unconfigured",
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
it("captures retained raw keys before WebCrypto await and leaves no live alias", async () => {
|
|
203
|
+
const raw: any = input();
|
|
204
|
+
own(raw.subscription, "__proto__", { value: "before" });
|
|
205
|
+
let release!: () => void, entered!: () => void;
|
|
206
|
+
const hold = new Promise<void>((r) => (release = r)),
|
|
207
|
+
started = new Promise<void>((r) => (entered = r));
|
|
208
|
+
vi.stubGlobal("crypto", {
|
|
209
|
+
subtle: {
|
|
210
|
+
digest: async (n: any, b: any) => {
|
|
211
|
+
entered();
|
|
212
|
+
await hold;
|
|
213
|
+
return webcrypto.subtle.digest(n, b);
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
const pending = sdk.prepareRenewalPriceReplacementV2(raw);
|
|
218
|
+
await Promise.race([started, pending]);
|
|
219
|
+
raw.subscription.__proto__.value = "after";
|
|
220
|
+
release();
|
|
221
|
+
const p = await pending;
|
|
222
|
+
expect((p.providerSnapshot.subscription as any).__proto__).toEqual({
|
|
223
|
+
value: "before",
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
it("does not turn custom prototypes/accessors or overbudget raw data into retained JSON", async () => {
|
|
227
|
+
for (const kind of ["prototype", "accessor", "budget"]) {
|
|
228
|
+
const raw: any = input();
|
|
229
|
+
if (kind === "prototype")
|
|
230
|
+
Object.setPrototypeOf(raw.subscription, { foreign: true });
|
|
231
|
+
else if (kind === "accessor")
|
|
232
|
+
Object.defineProperty(raw.subscription, "bad", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get() {
|
|
235
|
+
throw Error("must not invoke getter");
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
else own(raw.subscription, "__proto__", { pad: "x".repeat(500001) });
|
|
239
|
+
await expect(sdk.prepareRenewalPriceReplacementV2(raw)).rejects.toThrow();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
it("retained restored fields keep UTF8 hash caps and cannot adopt a stale binding", async () => {
|
|
243
|
+
const raw: any = input();
|
|
244
|
+
own(raw.subscription, "__proto__", { pad: "雪".repeat(170000) });
|
|
245
|
+
expect(legacy(raw).providerSnapshot.subscription).toEqual(raw.subscription);
|
|
246
|
+
const spy = vi.fn();
|
|
247
|
+
vi.stubGlobal("crypto", { subtle: { digest: spy } });
|
|
248
|
+
await expect(sdk.prepareRenewalPriceReplacementV2(raw)).rejects.toThrow();
|
|
249
|
+
expect(spy).not.toHaveBeenCalled();
|
|
250
|
+
vi.unstubAllGlobals();
|
|
251
|
+
const p: any = await sdk.prepareRenewalPriceReplacementV2(input());
|
|
252
|
+
own(p.providerSnapshot.subscription, "__proto__", { newRaw: true });
|
|
253
|
+
await expect(
|
|
254
|
+
sdk.prepareRenewalScheduleAttachmentV2({
|
|
255
|
+
prepared: p,
|
|
256
|
+
apiVersion: "2026-09-30.endive",
|
|
257
|
+
attachKey: "explicit:attach",
|
|
258
|
+
firstDispatchedAt: 1768867200,
|
|
259
|
+
}),
|
|
260
|
+
).rejects.toThrow();
|
|
261
|
+
});
|
|
262
|
+
it("C5 retains eligible opaque special keys inside validated expanded defaults", async () => {
|
|
263
|
+
const p: any = input();
|
|
264
|
+
p.subscription.default_payment_method = {
|
|
265
|
+
id: "pm_retained",
|
|
266
|
+
object: "payment_method",
|
|
267
|
+
customer: "cus_buyer",
|
|
268
|
+
customer_account: "acct_buyer",
|
|
269
|
+
livemode: false,
|
|
270
|
+
};
|
|
271
|
+
const c = configuration(p);
|
|
272
|
+
c.schedule.default_settings.default_payment_method = structuredClone(
|
|
273
|
+
p.subscription.default_payment_method,
|
|
274
|
+
);
|
|
275
|
+
own(c.schedule.default_settings.default_payment_method, "__proto__", {
|
|
276
|
+
safe: "one",
|
|
277
|
+
});
|
|
278
|
+
c.attachReceipt.providerSnapshot = structuredClone(c.schedule);
|
|
279
|
+
const first = await sdk.projectRenewalConfigurationV2(c);
|
|
280
|
+
expect(first.status).toBe("projected_configure_request");
|
|
281
|
+
if (first.status !== "projected_configure_request") throw Error("fixture");
|
|
282
|
+
expect(first.defaultSettingsBinding).toBe(
|
|
283
|
+
binding("renewal-defaults", c.schedule.default_settings),
|
|
284
|
+
);
|
|
285
|
+
own(c.schedule.default_settings.default_payment_method, "__proto__", {
|
|
286
|
+
safe: "two",
|
|
287
|
+
});
|
|
288
|
+
c.attachReceipt.providerSnapshot = structuredClone(c.schedule);
|
|
289
|
+
const second = await sdk.projectRenewalConfigurationV2(c);
|
|
290
|
+
expect(second.status).toBe("projected_configure_request");
|
|
291
|
+
if (second.status !== "projected_configure_request") throw Error("fixture");
|
|
292
|
+
expect(second.defaultSettingsBinding).not.toBe(first.defaultSettingsBinding);
|
|
293
|
+
});
|
package/src/client/renewal.ts
CHANGED
|
@@ -31,3 +31,10 @@ export type {
|
|
|
31
31
|
ConstructRenewalConfigurationReceiptV2Options,
|
|
32
32
|
RenewalConfigurationReceiptV2,
|
|
33
33
|
} from "./billing/renewalV2/index.js";
|
|
34
|
+
|
|
35
|
+
export { inspectRenewalScheduleMaterialV2 } from "./billing/renewalV2/observation.js";
|
|
36
|
+
export type {
|
|
37
|
+
InspectRenewalScheduleMaterialV2Options,
|
|
38
|
+
RenewalScheduleMaterialReads,
|
|
39
|
+
RenewalScheduleMaterialObservationV2,
|
|
40
|
+
} from "./billing/renewalV2/observation.js";
|