@fantastic.dev/better-stripe 0.87.0 → 0.88.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/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/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-material-observation.md +124 -0
- package/docs/renewal-price-replacements.md +3 -0
- package/package.json +1 -1
- 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/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/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
|
+
}
|
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";
|