@fantastic.dev/better-stripe 0.79.1 → 0.80.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalPriceReplacement.d.ts +131 -0
  4. package/dist/client/billing/renewalPriceReplacement.d.ts.map +1 -0
  5. package/dist/client/billing/renewalPriceReplacement.js +90 -0
  6. package/dist/client/billing/renewalPriceReplacement.js.map +1 -0
  7. package/dist/client/billing/renewalReplacementSchema.d.ts +124 -0
  8. package/dist/client/billing/renewalReplacementSchema.d.ts.map +1 -0
  9. package/dist/client/billing/renewalReplacementSchema.js +121 -0
  10. package/dist/client/billing/renewalReplacementSchema.js.map +1 -0
  11. package/dist/client/billing/renewalReplacementSnapshot.d.ts +3 -0
  12. package/dist/client/billing/renewalReplacementSnapshot.d.ts.map +1 -0
  13. package/dist/client/billing/renewalReplacementSnapshot.js +69 -0
  14. package/dist/client/billing/renewalReplacementSnapshot.js.map +1 -0
  15. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  16. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  17. package/dist/client/index.d.ts +3 -0
  18. package/dist/client/index.d.ts.map +1 -1
  19. package/dist/client/index.js +1 -0
  20. package/dist/client/index.js.map +1 -1
  21. package/dist/client/usage/observationClient.d.ts +2 -2
  22. package/dist/client/usage/observationClient.d.ts.map +1 -1
  23. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  24. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  25. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  26. package/dist/component/earnings/triggers.d.ts +16 -16
  27. package/docs/client-api.md +5 -0
  28. package/docs/renewal-price-replacements.md +186 -0
  29. package/package.json +1 -1
  30. package/src/client/billing/renewal-price-replacement.test.ts +457 -0
  31. package/src/client/billing/renewalPriceReplacement.ts +127 -0
  32. package/src/client/billing/renewalReplacementSchema.ts +129 -0
  33. package/src/client/billing/renewalReplacementSnapshot.ts +85 -0
  34. package/src/client/index.ts +6 -0
@@ -0,0 +1,85 @@
1
+ /** A bounded JSON copy. Reject non-JSON values rather than silently dropping them. */
2
+ export function renewalSnapshot<T>(value: T): T {
3
+ const seen = new Set<object>();
4
+ let nodes = 0;
5
+ let characters = 500_000;
6
+ function charge(size: number) {
7
+ characters -= size;
8
+ if (characters < 0)
9
+ throw new Error("Renewal snapshot exceeds its JSON size budget.");
10
+ }
11
+ function copy(item: unknown, depth: number): unknown {
12
+ if (++nodes > 10_000 || depth > 40)
13
+ throw new Error("Renewal snapshot exceeds its JSON traversal budget.");
14
+ if (typeof item === "string") {
15
+ charge(item.length);
16
+ return item;
17
+ }
18
+ if (item === null || typeof item === "boolean") return item;
19
+ if (typeof item === "number" && Number.isFinite(item)) return item;
20
+ if (typeof item !== "object" || item === null || seen.has(item))
21
+ throw new Error("Renewal snapshot must contain finite JSON values.");
22
+ if (
23
+ !Array.isArray(item) &&
24
+ ![Object.prototype, null].includes(Object.getPrototypeOf(item))
25
+ )
26
+ throw new Error("Renewal snapshot must contain plain JSON objects.");
27
+ if (Array.isArray(item) && item.length > 10_000)
28
+ throw new Error(
29
+ "Renewal snapshot array is too large for its JSON budget.",
30
+ );
31
+ seen.add(item);
32
+ const entries: [string, unknown][] = [];
33
+ for (const key in item) {
34
+ const entry = Object.getOwnPropertyDescriptor(item, key);
35
+ if (!entry) continue;
36
+ if (!("value" in entry))
37
+ throw new Error("Renewal snapshot must contain JSON data properties.");
38
+ if (entries.length >= 10_000)
39
+ throw new Error(
40
+ "Renewal snapshot object exceeds its JSON traversal budget.",
41
+ );
42
+ charge(key.length);
43
+ entries.push([key, entry.value]);
44
+ }
45
+ if (
46
+ Object.getOwnPropertySymbols(item).some(
47
+ (key) => Object.getOwnPropertyDescriptor(item, key)?.enumerable,
48
+ )
49
+ )
50
+ throw new Error("Renewal snapshot must contain JSON data properties.");
51
+ let result: unknown;
52
+ if (Array.isArray(item)) {
53
+ if (
54
+ entries.some(
55
+ ([key]) =>
56
+ !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= item.length,
57
+ )
58
+ )
59
+ throw new Error(
60
+ "Renewal snapshot arrays must contain only JSON elements.",
61
+ );
62
+ result = Array.from({ length: item.length }, (_, index) => {
63
+ const entry = Object.getOwnPropertyDescriptor(item, String(index));
64
+ if (!entry || !("value" in entry))
65
+ throw new Error(
66
+ "Renewal snapshot must not contain sparse JSON arrays.",
67
+ );
68
+ return copy(entry.value, depth + 1);
69
+ });
70
+ } else {
71
+ result = Object.fromEntries(
72
+ entries
73
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
74
+ .map(([key, entry]) => [key, copy(entry, depth + 1)]),
75
+ );
76
+ }
77
+ seen.delete(item);
78
+ return result;
79
+ }
80
+ const normalized = copy(value, 0);
81
+ const serialized = JSON.stringify(normalized);
82
+ if (serialized.length > 500_000)
83
+ throw new Error("Renewal snapshot is too large.");
84
+ return JSON.parse(serialized) as T;
85
+ }
@@ -1,3 +1,9 @@
1
+ export { prepareRenewalPriceReplacement } from "./billing/renewalPriceReplacement.js";
2
+ export type {
3
+ PrepareRenewalPriceReplacementOptions,
4
+ PreparedRenewalPriceReplacement,
5
+ } from "./billing/renewalPriceReplacement.js";
6
+ export type { RenewalPriceReplacementExpected } from "./billing/renewalReplacementSchema.js";
1
7
  export { qualifyCapturedCheckoutPayment } from "./billing/capturedCheckoutPayment.js";
2
8
  export type {
3
9
  CapturedCheckoutPaymentExpected,