@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.
Files changed (115) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalObservation/active-scheduled.d.ts +6 -0
  4. package/dist/client/billing/renewalObservation/active-scheduled.d.ts.map +1 -0
  5. package/dist/client/billing/renewalObservation/active-scheduled.js +37 -0
  6. package/dist/client/billing/renewalObservation/active-scheduled.js.map +1 -0
  7. package/dist/client/billing/renewalObservation/common.d.ts +47 -0
  8. package/dist/client/billing/renewalObservation/common.d.ts.map +1 -0
  9. package/dist/client/billing/renewalObservation/common.js +39 -0
  10. package/dist/client/billing/renewalObservation/common.js.map +1 -0
  11. package/dist/client/billing/renewalObservation/configured-baseline.d.ts +76 -0
  12. package/dist/client/billing/renewalObservation/configured-baseline.d.ts.map +1 -0
  13. package/dist/client/billing/renewalObservation/configured-baseline.js +26 -0
  14. package/dist/client/billing/renewalObservation/configured-baseline.js.map +1 -0
  15. package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts +53 -0
  16. package/dist/client/billing/renewalObservation/coupon-discount-joins.d.ts.map +1 -0
  17. package/dist/client/billing/renewalObservation/coupon-discount-joins.js +103 -0
  18. package/dist/client/billing/renewalObservation/coupon-discount-joins.js.map +1 -0
  19. package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts +52 -0
  20. package/dist/client/billing/renewalObservation/invoice-tax-identity.d.ts.map +1 -0
  21. package/dist/client/billing/renewalObservation/invoice-tax-identity.js +49 -0
  22. package/dist/client/billing/renewalObservation/invoice-tax-identity.js.map +1 -0
  23. package/dist/client/billing/renewalObservation/pending-and-stage.d.ts +76 -0
  24. package/dist/client/billing/renewalObservation/pending-and-stage.d.ts.map +1 -0
  25. package/dist/client/billing/renewalObservation/pending-and-stage.js +36 -0
  26. package/dist/client/billing/renewalObservation/pending-and-stage.js.map +1 -0
  27. package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts +57 -0
  28. package/dist/client/billing/renewalObservation/phase-price-normalization.d.ts.map +1 -0
  29. package/dist/client/billing/renewalObservation/phase-price-normalization.js +70 -0
  30. package/dist/client/billing/renewalObservation/phase-price-normalization.js.map +1 -0
  31. package/dist/client/billing/renewalObservation/planProjection.d.ts +8 -0
  32. package/dist/client/billing/renewalObservation/planProjection.d.ts.map +1 -0
  33. package/dist/client/billing/renewalObservation/planProjection.js +150 -0
  34. package/dist/client/billing/renewalObservation/planProjection.js.map +1 -0
  35. package/dist/client/billing/renewalObservation/reference-catalog.d.ts +37 -0
  36. package/dist/client/billing/renewalObservation/reference-catalog.d.ts.map +1 -0
  37. package/dist/client/billing/renewalObservation/reference-catalog.js +109 -0
  38. package/dist/client/billing/renewalObservation/reference-catalog.js.map +1 -0
  39. package/dist/client/billing/renewalObservation/schedule-templates.d.ts +74 -0
  40. package/dist/client/billing/renewalObservation/schedule-templates.d.ts.map +1 -0
  41. package/dist/client/billing/renewalObservation/schedule-templates.js +72 -0
  42. package/dist/client/billing/renewalObservation/schedule-templates.js.map +1 -0
  43. package/dist/client/billing/renewalObservation/scheduled-context.d.ts +44 -0
  44. package/dist/client/billing/renewalObservation/scheduled-context.d.ts.map +1 -0
  45. package/dist/client/billing/renewalObservation/scheduled-context.js +64 -0
  46. package/dist/client/billing/renewalObservation/scheduled-context.js.map +1 -0
  47. package/dist/client/billing/renewalObservation/scheduled-identity.d.ts +53 -0
  48. package/dist/client/billing/renewalObservation/scheduled-identity.d.ts.map +1 -0
  49. package/dist/client/billing/renewalObservation/scheduled-identity.js +95 -0
  50. package/dist/client/billing/renewalObservation/scheduled-identity.js.map +1 -0
  51. package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts +59 -0
  52. package/dist/client/billing/renewalObservation/scheduled-normalization.d.ts.map +1 -0
  53. package/dist/client/billing/renewalObservation/scheduled-normalization.js +29 -0
  54. package/dist/client/billing/renewalObservation/scheduled-normalization.js.map +1 -0
  55. package/dist/client/billing/renewalObservation/settings-normalization.d.ts +54 -0
  56. package/dist/client/billing/renewalObservation/settings-normalization.d.ts.map +1 -0
  57. package/dist/client/billing/renewalObservation/settings-normalization.js +53 -0
  58. package/dist/client/billing/renewalObservation/settings-normalization.js.map +1 -0
  59. package/dist/client/billing/renewalObservation/stage-runner.d.ts +4 -0
  60. package/dist/client/billing/renewalObservation/stage-runner.d.ts.map +1 -0
  61. package/dist/client/billing/renewalObservation/stage-runner.js +34 -0
  62. package/dist/client/billing/renewalObservation/stage-runner.js.map +1 -0
  63. package/dist/client/billing/renewalObservation/weeklyPending.d.ts +13 -0
  64. package/dist/client/billing/renewalObservation/weeklyPending.d.ts.map +1 -0
  65. package/dist/client/billing/renewalObservation/weeklyPending.js +55 -0
  66. package/dist/client/billing/renewalObservation/weeklyPending.js.map +1 -0
  67. package/dist/client/billing/renewalV2/index.d.ts +383 -0
  68. package/dist/client/billing/renewalV2/index.d.ts.map +1 -1
  69. package/dist/client/billing/renewalV2/index.js +8 -3
  70. package/dist/client/billing/renewalV2/index.js.map +1 -1
  71. package/dist/client/billing/renewalV2/observation.d.ts +19 -0
  72. package/dist/client/billing/renewalV2/observation.d.ts.map +1 -0
  73. package/dist/client/billing/renewalV2/observation.js +95 -0
  74. package/dist/client/billing/renewalV2/observation.js.map +1 -0
  75. package/dist/client/billing/renewalV2/observationInput.d.ts +77 -0
  76. package/dist/client/billing/renewalV2/observationInput.d.ts.map +1 -0
  77. package/dist/client/billing/renewalV2/observationInput.js +140 -0
  78. package/dist/client/billing/renewalV2/observationInput.js.map +1 -0
  79. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  80. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  81. package/dist/client/renewal.d.ts +2 -0
  82. package/dist/client/renewal.d.ts.map +1 -1
  83. package/dist/client/renewal.js +1 -0
  84. package/dist/client/renewal.js.map +1 -1
  85. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  86. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  87. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  88. package/dist/component/earnings/triggers.d.ts +16 -16
  89. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  90. package/docs/client-api.md +26 -0
  91. package/docs/renewal-material-observation.md +124 -0
  92. package/docs/renewal-price-replacements.md +3 -0
  93. package/package.json +1 -1
  94. package/src/client/billing/renewalObservation/active-scheduled.ts +67 -0
  95. package/src/client/billing/renewalObservation/common.ts +83 -0
  96. package/src/client/billing/renewalObservation/configured-baseline.ts +55 -0
  97. package/src/client/billing/renewalObservation/coupon-discount-joins.ts +163 -0
  98. package/src/client/billing/renewalObservation/invoice-tax-identity.ts +65 -0
  99. package/src/client/billing/renewalObservation/pending-and-stage.ts +89 -0
  100. package/src/client/billing/renewalObservation/phase-price-normalization.ts +106 -0
  101. package/src/client/billing/renewalObservation/planProjection.ts +177 -0
  102. package/src/client/billing/renewalObservation/reference-catalog.ts +150 -0
  103. package/src/client/billing/renewalObservation/schedule-templates.ts +118 -0
  104. package/src/client/billing/renewalObservation/scheduled-context.ts +98 -0
  105. package/src/client/billing/renewalObservation/scheduled-identity.ts +175 -0
  106. package/src/client/billing/renewalObservation/scheduled-normalization.ts +49 -0
  107. package/src/client/billing/renewalObservation/settings-normalization.ts +60 -0
  108. package/src/client/billing/renewalObservation/stage-runner.ts +30 -0
  109. package/src/client/billing/renewalObservation/weeklyPending.ts +81 -0
  110. package/src/client/billing/renewalV2/index.ts +14 -6
  111. package/src/client/billing/renewalV2/observation.boundary-review.test.ts +49 -0
  112. package/src/client/billing/renewalV2/observation.test.ts +334 -0
  113. package/src/client/billing/renewalV2/observation.ts +149 -0
  114. package/src/client/billing/renewalV2/observationInput.ts +167 -0
  115. 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
+ }
@@ -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";