@fantastic.dev/better-stripe 0.110.0 → 0.112.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 (134) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +564 -0
  4. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +103 -21
  6. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +18 -1
  8. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +54 -1
  10. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +4 -0
  12. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/observation/invocation.js +1 -0
  14. package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +4 -0
  16. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +6 -1
  18. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts +38 -0
  20. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js +172 -0
  22. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts +135 -0
  24. package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/observation/witnessData.js +143 -0
  26. package/dist/client/billing/renewalAttach/internal/observation/witnessData.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts +85 -0
  28. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js +121 -0
  30. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts +44 -0
  32. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js +4 -0
  34. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +1 -1
  36. package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +21 -21
  37. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +3 -3
  38. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
  39. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +84 -32
  40. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  41. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +26 -0
  42. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  43. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +84 -32
  44. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  45. package/dist/client/connect/payoutSyncTestHelpers.d.ts +26 -0
  46. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  47. package/dist/component/_generated/api.d.ts +24 -0
  48. package/dist/component/_generated/api.d.ts.map +1 -1
  49. package/dist/component/_generated/api.js.map +1 -1
  50. package/dist/component/_generated/component.d.ts +94 -10
  51. package/dist/component/_generated/component.d.ts.map +1 -1
  52. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  53. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  54. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  55. package/dist/component/balanceFunding/queries.d.ts +1 -1
  56. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  57. package/dist/component/earnings/triggers.d.ts +44 -0
  58. package/dist/component/earnings/triggers.d.ts.map +1 -1
  59. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  60. package/dist/component/renewalWitnesses/eligibility.d.ts +36 -0
  61. package/dist/component/renewalWitnesses/eligibility.d.ts.map +1 -0
  62. package/dist/component/renewalWitnesses/eligibility.js +60 -0
  63. package/dist/component/renewalWitnesses/eligibility.js.map +1 -0
  64. package/dist/component/renewalWitnesses/mutations.d.ts +45 -0
  65. package/dist/component/renewalWitnesses/mutations.d.ts.map +1 -0
  66. package/dist/component/renewalWitnesses/mutations.js +14 -0
  67. package/dist/component/renewalWitnesses/mutations.js.map +1 -0
  68. package/dist/component/renewalWitnesses/protocol.d.ts +75 -0
  69. package/dist/component/renewalWitnesses/protocol.d.ts.map +1 -0
  70. package/dist/component/renewalWitnesses/protocol.js +82 -0
  71. package/dist/component/renewalWitnesses/protocol.js.map +1 -0
  72. package/dist/component/renewalWitnesses/queries.d.ts +39 -0
  73. package/dist/component/renewalWitnesses/queries.d.ts.map +1 -0
  74. package/dist/component/renewalWitnesses/queries.js +11 -0
  75. package/dist/component/renewalWitnesses/queries.js.map +1 -0
  76. package/dist/component/renewalWitnesses/schema.d.ts +99 -0
  77. package/dist/component/renewalWitnesses/schema.d.ts.map +1 -0
  78. package/dist/component/renewalWitnesses/schema.js +36 -0
  79. package/dist/component/renewalWitnesses/schema.js.map +1 -0
  80. package/dist/component/renewalWitnesses/source.d.ts +22 -0
  81. package/dist/component/renewalWitnesses/source.d.ts.map +1 -0
  82. package/dist/component/renewalWitnesses/source.js +108 -0
  83. package/dist/component/renewalWitnesses/source.js.map +1 -0
  84. package/dist/component/schema.d.ts +42 -16
  85. package/dist/component/schema.js +2 -0
  86. package/dist/component/schema.js.map +1 -1
  87. package/dist/component/usage/allowance.fixtures.d.ts +42 -16
  88. package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
  89. package/dist/component/usageCredits/accounting.fixtures.d.ts +26 -0
  90. package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
  91. package/dist/shared/renewalWitness.d.ts +51 -0
  92. package/dist/shared/renewalWitness.d.ts.map +1 -0
  93. package/dist/shared/renewalWitness.js +127 -0
  94. package/dist/shared/renewalWitness.js.map +1 -0
  95. package/docs/renewal-witness-protocol.md +139 -0
  96. package/package.json +1 -1
  97. package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +142 -19
  98. package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +90 -1
  99. package/src/client/billing/renewalAttach/internal/observation/invocation.ts +2 -0
  100. package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +6 -1
  101. package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts +348 -0
  102. package/src/client/billing/renewalAttach/internal/observation/witnessActor.integration.test.ts +204 -0
  103. package/src/client/billing/renewalAttach/internal/observation/witnessAuthorization.ts +239 -0
  104. package/src/client/billing/renewalAttach/internal/observation/witnessCapabilities.integration.test.ts +231 -0
  105. package/src/client/billing/renewalAttach/internal/observation/witnessData.ts +189 -0
  106. package/src/client/billing/renewalAttach/internal/observation/witnessHistorical.integration.test.ts +98 -0
  107. package/src/client/billing/renewalAttach/internal/observation/witnessImmutable.integration.test.ts +78 -0
  108. package/src/client/billing/renewalAttach/internal/observation/witnessInvoice.integration.test.ts +85 -0
  109. package/src/client/billing/renewalAttach/internal/observation/witnessLifecycle.integration.test.ts +264 -0
  110. package/src/client/billing/renewalAttach/internal/observation/witnessOperation.ts +205 -0
  111. package/src/client/billing/renewalAttach/internal/observation/witnessProfile.integration.test.ts +93 -0
  112. package/src/client/billing/renewalAttach/internal/observation/witnessRPCControls.integration.test.ts +256 -0
  113. package/src/client/billing/renewalAttach/internal/operations/witnessProfiles.ts +58 -0
  114. package/src/client/billing/renewalAttach/internal/test-fixtures/invoiceObservation.ts +3 -1
  115. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +8 -0
  116. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +18 -7
  117. package/src/client/billing/renewalAttach/internal/test-fixtures/witnessHistory.ts +70 -0
  118. package/src/client/billing/renewalAttach/internal/test-fixtures/witnessObservation.ts +353 -0
  119. package/src/component/_generated/api.ts +24 -0
  120. package/src/component/_generated/component.ts +98 -10
  121. package/src/component/renewalOperations/configureJournal.fixtures.ts +25 -3
  122. package/src/component/renewalWitnesses/bounds.test.ts +204 -0
  123. package/src/component/renewalWitnesses/codec.test.ts +84 -0
  124. package/src/component/renewalWitnesses/controls.test.ts +250 -0
  125. package/src/component/renewalWitnesses/eligibility.ts +78 -0
  126. package/src/component/renewalWitnesses/mutations.ts +17 -0
  127. package/src/component/renewalWitnesses/protocol.test.ts +63 -0
  128. package/src/component/renewalWitnesses/protocol.ts +103 -0
  129. package/src/component/renewalWitnesses/queries.ts +11 -0
  130. package/src/component/renewalWitnesses/routes.test.ts +154 -0
  131. package/src/component/renewalWitnesses/schema.ts +36 -0
  132. package/src/component/renewalWitnesses/source.ts +157 -0
  133. package/src/component/schema.ts +2 -0
  134. package/src/shared/renewalWitness.ts +179 -0
@@ -0,0 +1,179 @@
1
+ import { renewalSnapshot } from "../client/billing/renewalReplacementSnapshot.js";
2
+ import type { ObservationReads } from "../client/billing/renewalAttach/internal/observation/types.js";
3
+ import type { InvoiceContextV1 } from "../client/billing/renewalObservation/evidence-v1-types.js";
4
+
5
+ export function witnessStop(): never {
6
+ throw Error("RENEWAL_WITNESS_INVALID");
7
+ }
8
+ export function witnessNeed(value: unknown): asserts value {
9
+ if (!value) witnessStop();
10
+ }
11
+ export function witnessObject(raw: unknown): Record<string, unknown> {
12
+ witnessNeed(raw !== null && typeof raw === "object" && !Array.isArray(raw));
13
+ return raw as Record<string, unknown>;
14
+ }
15
+ export function witnessClosed(raw: unknown, keys: readonly string[]) {
16
+ const value = witnessObject(raw),
17
+ actual = Object.keys(value);
18
+ witnessNeed(
19
+ actual.length === keys.length && actual.every((key) => keys.includes(key)),
20
+ );
21
+ return value;
22
+ }
23
+ export function witnessText(raw: unknown, max = 255): string {
24
+ witnessNeed(typeof raw === "string" && raw.length > 0 && raw.length <= max);
25
+ return raw;
26
+ }
27
+ export type WitnessIdentity = Readonly<{
28
+ componentScope: string;
29
+ witnessId: string;
30
+ parentOperationId: string;
31
+ operationId: string;
32
+ }>;
33
+ export function witnessIdentity(raw: unknown): WitnessIdentity {
34
+ const value = witnessClosed(raw, [
35
+ "componentScope",
36
+ "witnessId",
37
+ "parentOperationId",
38
+ "operationId",
39
+ ]);
40
+ const identity = {
41
+ componentScope: witnessText(value.componentScope),
42
+ witnessId: witnessText(value.witnessId),
43
+ parentOperationId: witnessText(value.parentOperationId),
44
+ operationId: witnessText(value.operationId),
45
+ };
46
+ witnessNeed(identity.operationId !== identity.parentOperationId);
47
+ return identity;
48
+ }
49
+ export type WitnessAcknowledgement = Readonly<{
50
+ retention: Record<string, unknown>;
51
+ receipt: Record<string, unknown>;
52
+ }>;
53
+ export type WitnessStage = Readonly<{
54
+ record: Record<string, unknown>;
55
+ reservation: Record<string, unknown>;
56
+ acknowledgement: WitnessAcknowledgement | null;
57
+ }>;
58
+ export type WitnessPayload = Readonly<{
59
+ version: 1;
60
+ kind: "renewal_witness_payload";
61
+ identity: WitnessIdentity;
62
+ capturedSubject: string;
63
+ acquisition: Readonly<{
64
+ observedAtMs: number;
65
+ elapsedWallMs: number;
66
+ elapsedNsDecimal: string;
67
+ apiVersion: "2026-09-30.endive";
68
+ baseReadProfile: "endive-schedule-first-44-v1";
69
+ invoiceReadProfile: "endive-pinned-invoices-fence-7-v1" | null;
70
+ }>;
71
+ source: Readonly<{
72
+ parent: WitnessStage & Readonly<{ initialBasis: Record<string, unknown> }>;
73
+ configure: WitnessStage;
74
+ }>;
75
+ reads: ObservationReads;
76
+ invoiceContext: InvoiceContextV1 | null;
77
+ }>;
78
+ function acknowledgement(raw: unknown): WitnessAcknowledgement | null {
79
+ if (raw === null) return null;
80
+ const value = witnessClosed(raw, ["retention", "receipt"]);
81
+ return {
82
+ retention: witnessObject(value.retention),
83
+ receipt: witnessObject(value.receipt),
84
+ };
85
+ }
86
+ function stage(raw: unknown, parent: boolean) {
87
+ const value = witnessClosed(raw, [
88
+ "record",
89
+ "reservation",
90
+ "acknowledgement",
91
+ ...(parent ? ["initialBasis"] : []),
92
+ ]);
93
+ return {
94
+ record: witnessObject(value.record),
95
+ reservation: witnessObject(value.reservation),
96
+ acknowledgement: acknowledgement(value.acknowledgement),
97
+ ...(parent ? { initialBasis: witnessObject(value.initialBasis) } : {}),
98
+ };
99
+ }
100
+ /** Complete canonical JSON only. This admits DATA, not capture/authentication authority. */
101
+ export function canonicalWitnessJSON(
102
+ raw: string,
103
+ ): Readonly<{ json: string; value: WitnessPayload }> {
104
+ witnessNeed(
105
+ typeof raw === "string" &&
106
+ raw.length <= 500000 &&
107
+ new TextEncoder().encode(raw).length <= 500000,
108
+ );
109
+ const copy: unknown = renewalSnapshot(JSON.parse(raw));
110
+ witnessNeed(JSON.stringify(copy) === raw);
111
+ const value = witnessClosed(copy, [
112
+ "version",
113
+ "kind",
114
+ "identity",
115
+ "capturedSubject",
116
+ "acquisition",
117
+ "source",
118
+ "reads",
119
+ "invoiceContext",
120
+ ]);
121
+ witnessNeed(value.version === 1 && value.kind === "renewal_witness_payload");
122
+ witnessIdentity(value.identity);
123
+ witnessText(value.capturedSubject, 2048);
124
+ const acquired = witnessClosed(value.acquisition, [
125
+ "observedAtMs",
126
+ "elapsedWallMs",
127
+ "elapsedNsDecimal",
128
+ "apiVersion",
129
+ "baseReadProfile",
130
+ "invoiceReadProfile",
131
+ ]);
132
+ witnessNeed(
133
+ typeof acquired.observedAtMs === "number" &&
134
+ Number.isSafeInteger(acquired.observedAtMs) &&
135
+ acquired.observedAtMs >= 0,
136
+ );
137
+ witnessNeed(
138
+ typeof acquired.elapsedWallMs === "number" &&
139
+ Number.isSafeInteger(acquired.elapsedWallMs) &&
140
+ acquired.elapsedWallMs >= 0 &&
141
+ acquired.elapsedWallMs < 30000 &&
142
+ acquired.observedAtMs - acquired.elapsedWallMs >= 0,
143
+ );
144
+ witnessNeed(
145
+ typeof acquired.elapsedNsDecimal === "string" &&
146
+ /^(0|[1-9][0-9]{0,10})$/.test(acquired.elapsedNsDecimal) &&
147
+ BigInt(acquired.elapsedNsDecimal) < 30000000000n,
148
+ );
149
+ witnessNeed(
150
+ acquired.apiVersion === "2026-09-30.endive" &&
151
+ acquired.baseReadProfile === "endive-schedule-first-44-v1",
152
+ );
153
+ witnessNeed(
154
+ value.invoiceContext === null
155
+ ? acquired.invoiceReadProfile === null
156
+ : acquired.invoiceReadProfile === "endive-pinned-invoices-fence-7-v1",
157
+ );
158
+ const source = witnessClosed(value.source, ["parent", "configure"]);
159
+ witnessNeed(stage(source.parent, true).acknowledgement !== null);
160
+ stage(source.configure, false);
161
+ const reads = witnessClosed(value.reads, [
162
+ "schedule",
163
+ "subscription",
164
+ "targetPrice",
165
+ "billingCustomer",
166
+ "coupons",
167
+ ]);
168
+ for (const name of [
169
+ "schedule",
170
+ "subscription",
171
+ "targetPrice",
172
+ "billingCustomer",
173
+ ])
174
+ witnessObject(reads[name]);
175
+ witnessNeed(Array.isArray(reads.coupons));
176
+ if (value.invoiceContext !== null)
177
+ witnessClosed(value.invoiceContext, ["original", "current"]);
178
+ return Object.freeze({ json: raw, value: copy as WitnessPayload });
179
+ }