@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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +564 -0
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +103 -21
- package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +18 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +54 -1
- package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +6 -1
- package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts +38 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js +172 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts +135 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.js +143 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts +85 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js +121 -0
- package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js +4 -0
- package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +21 -21
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +3 -3
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +84 -32
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +26 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +84 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +26 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +24 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +94 -10
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +44 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/renewalWitnesses/eligibility.d.ts +36 -0
- package/dist/component/renewalWitnesses/eligibility.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/eligibility.js +60 -0
- package/dist/component/renewalWitnesses/eligibility.js.map +1 -0
- package/dist/component/renewalWitnesses/mutations.d.ts +45 -0
- package/dist/component/renewalWitnesses/mutations.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/mutations.js +14 -0
- package/dist/component/renewalWitnesses/mutations.js.map +1 -0
- package/dist/component/renewalWitnesses/protocol.d.ts +75 -0
- package/dist/component/renewalWitnesses/protocol.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/protocol.js +82 -0
- package/dist/component/renewalWitnesses/protocol.js.map +1 -0
- package/dist/component/renewalWitnesses/queries.d.ts +39 -0
- package/dist/component/renewalWitnesses/queries.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/queries.js +11 -0
- package/dist/component/renewalWitnesses/queries.js.map +1 -0
- package/dist/component/renewalWitnesses/schema.d.ts +99 -0
- package/dist/component/renewalWitnesses/schema.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/schema.js +36 -0
- package/dist/component/renewalWitnesses/schema.js.map +1 -0
- package/dist/component/renewalWitnesses/source.d.ts +22 -0
- package/dist/component/renewalWitnesses/source.d.ts.map +1 -0
- package/dist/component/renewalWitnesses/source.js +108 -0
- package/dist/component/renewalWitnesses/source.js.map +1 -0
- package/dist/component/schema.d.ts +42 -16
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +42 -16
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +26 -0
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
- package/dist/shared/renewalWitness.d.ts +51 -0
- package/dist/shared/renewalWitness.d.ts.map +1 -0
- package/dist/shared/renewalWitness.js +127 -0
- package/dist/shared/renewalWitness.js.map +1 -0
- package/docs/renewal-witness-protocol.md +139 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +142 -19
- package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +90 -1
- package/src/client/billing/renewalAttach/internal/observation/invocation.ts +2 -0
- package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +6 -1
- package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts +348 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessActor.integration.test.ts +204 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessAuthorization.ts +239 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessCapabilities.integration.test.ts +231 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessData.ts +189 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessHistorical.integration.test.ts +98 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessImmutable.integration.test.ts +78 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessInvoice.integration.test.ts +85 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessLifecycle.integration.test.ts +264 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessOperation.ts +205 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessProfile.integration.test.ts +93 -0
- package/src/client/billing/renewalAttach/internal/observation/witnessRPCControls.integration.test.ts +256 -0
- package/src/client/billing/renewalAttach/internal/operations/witnessProfiles.ts +58 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/invoiceObservation.ts +3 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +8 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +18 -7
- package/src/client/billing/renewalAttach/internal/test-fixtures/witnessHistory.ts +70 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/witnessObservation.ts +353 -0
- package/src/component/_generated/api.ts +24 -0
- package/src/component/_generated/component.ts +98 -10
- package/src/component/renewalOperations/configureJournal.fixtures.ts +25 -3
- package/src/component/renewalWitnesses/bounds.test.ts +204 -0
- package/src/component/renewalWitnesses/codec.test.ts +84 -0
- package/src/component/renewalWitnesses/controls.test.ts +250 -0
- package/src/component/renewalWitnesses/eligibility.ts +78 -0
- package/src/component/renewalWitnesses/mutations.ts +17 -0
- package/src/component/renewalWitnesses/protocol.test.ts +63 -0
- package/src/component/renewalWitnesses/protocol.ts +103 -0
- package/src/component/renewalWitnesses/queries.ts +11 -0
- package/src/component/renewalWitnesses/routes.test.ts +154 -0
- package/src/component/renewalWitnesses/schema.ts +36 -0
- package/src/component/renewalWitnesses/source.ts +157 -0
- package/src/component/schema.ts +2 -0
- 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
|
+
}
|