@fantastic.dev/better-stripe 0.111.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 +6 -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 +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- 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/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- 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/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/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-witness-protocol.md +61 -10
- 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/renewalWitnesses/mutations.ts +17 -0
- package/src/component/renewalWitnesses/queries.ts +11 -0
- package/src/component/renewalWitnesses/routes.test.ts +154 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalWitnessJSON,
|
|
3
|
+
witnessNeed as need,
|
|
4
|
+
witnessObject as object,
|
|
5
|
+
witnessText as text,
|
|
6
|
+
type WitnessIdentity,
|
|
7
|
+
type WitnessPayload,
|
|
8
|
+
} from "../../../../../shared/renewalWitness.js";
|
|
9
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
10
|
+
import { inspectRenewalEvidenceV1 } from "../../../renewalObservation/evidence-v1.js";
|
|
11
|
+
import type { WitnessScope } from "../operations/witnessProfiles.js";
|
|
12
|
+
import { closed, freeze } from "../c10/ownData.js";
|
|
13
|
+
import { matchConfigureDATA } from "../producer/configureJournalData.js";
|
|
14
|
+
import type { ObservationInvocationState } from "./invocation.js";
|
|
15
|
+
import type { ObservationReads } from "./types.js";
|
|
16
|
+
import type { InvoiceContextV1 } from "../../../renewalObservation/evidence-v1-types.js";
|
|
17
|
+
|
|
18
|
+
function capturedStage(raw: unknown, parent: boolean) {
|
|
19
|
+
const stage = object(raw),
|
|
20
|
+
load = object(stage.operation);
|
|
21
|
+
const reservation = object(object(stage.attempt).reservation);
|
|
22
|
+
const { recordJSON: _recordJSON, ...summary } = reservation;
|
|
23
|
+
void _recordJSON;
|
|
24
|
+
const known = stage.acknowledgement;
|
|
25
|
+
return {
|
|
26
|
+
record: object(JSON.parse(text(load.recordJSON, 500000))),
|
|
27
|
+
reservation: summary,
|
|
28
|
+
acknowledgement:
|
|
29
|
+
known === null
|
|
30
|
+
? null
|
|
31
|
+
: {
|
|
32
|
+
retention: object(object(known).retention),
|
|
33
|
+
receipt: object(
|
|
34
|
+
JSON.parse(text(object(known).receiptJSON, 500000)),
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
...(parent ? { initialBasis: object(load.initialBasis) } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Called only inside the actual fresh actor, before its original lifetime closes. */
|
|
42
|
+
export function captureWitnessPayload(
|
|
43
|
+
state: ObservationInvocationState,
|
|
44
|
+
identity: WitnessIdentity,
|
|
45
|
+
reads: ObservationReads,
|
|
46
|
+
invoiceContext: InvoiceContextV1 | null,
|
|
47
|
+
) {
|
|
48
|
+
const captured = state.readCaptured(),
|
|
49
|
+
sample = state.check();
|
|
50
|
+
const snapshot = captured.history.snapshot;
|
|
51
|
+
const payload = renewalSnapshot({
|
|
52
|
+
version: 1,
|
|
53
|
+
kind: "renewal_witness_payload",
|
|
54
|
+
identity,
|
|
55
|
+
capturedSubject: captured.authorization.tokenIdentifier,
|
|
56
|
+
acquisition: {
|
|
57
|
+
observedAtMs: sample.wallMs,
|
|
58
|
+
elapsedWallMs: sample.wallMs - state.startedAt.wallMs,
|
|
59
|
+
elapsedNsDecimal: (sample.ns - state.startedAt.ns).toString(),
|
|
60
|
+
apiVersion: "2026-09-30.endive",
|
|
61
|
+
baseReadProfile: "endive-schedule-first-44-v1",
|
|
62
|
+
invoiceReadProfile:
|
|
63
|
+
invoiceContext === null ? null : "endive-pinned-invoices-fence-7-v1",
|
|
64
|
+
},
|
|
65
|
+
source: {
|
|
66
|
+
parent: capturedStage(snapshot.parent, true),
|
|
67
|
+
configure: capturedStage(snapshot.configure, false),
|
|
68
|
+
},
|
|
69
|
+
reads,
|
|
70
|
+
invoiceContext,
|
|
71
|
+
});
|
|
72
|
+
return canonicalWitnessJSON(JSON.stringify(payload)).json;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Recompute complete unsigned material and digest; a stored hash is not its own proof. */
|
|
76
|
+
export async function inspectWitnessPayload(raw: string) {
|
|
77
|
+
const canonical = canonicalWitnessJSON(raw),
|
|
78
|
+
payload = canonical.value;
|
|
79
|
+
const record = object(payload.source.configure.record.configureRecord);
|
|
80
|
+
const known = payload.source.configure.acknowledgement;
|
|
81
|
+
const configureReceipt =
|
|
82
|
+
known === null
|
|
83
|
+
? null
|
|
84
|
+
: {
|
|
85
|
+
configuration: record.configuration,
|
|
86
|
+
actualDispatch: payload.source.configure.record.dispatch,
|
|
87
|
+
providerSnapshot: known.receipt.providerSnapshot,
|
|
88
|
+
transport: known.receipt.transport,
|
|
89
|
+
};
|
|
90
|
+
const evidence = await inspectRenewalEvidenceV1({
|
|
91
|
+
version: 1,
|
|
92
|
+
apiVersion: "2026-09-30.endive",
|
|
93
|
+
configuration: record.configuration,
|
|
94
|
+
configureReceipt,
|
|
95
|
+
reads: payload.reads,
|
|
96
|
+
invoiceContext: payload.invoiceContext,
|
|
97
|
+
historicalSnapshot: null,
|
|
98
|
+
});
|
|
99
|
+
need(
|
|
100
|
+
evidence.identity &&
|
|
101
|
+
evidence.currentMaterial.predicate === "current_target_material_match",
|
|
102
|
+
);
|
|
103
|
+
if (payload.invoiceContext !== null)
|
|
104
|
+
need(evidence.invoiceEvidence.predicate === "invoice_lines_correlated");
|
|
105
|
+
const { identity } = evidence,
|
|
106
|
+
material = evidence.currentMaterial;
|
|
107
|
+
const scope: WitnessScope = freeze({
|
|
108
|
+
identity: payload.identity,
|
|
109
|
+
providerScope: {
|
|
110
|
+
mode: "platform",
|
|
111
|
+
stripeAccount: null,
|
|
112
|
+
livemode: identity.livemode,
|
|
113
|
+
customerAccountId: identity.customerAccountId,
|
|
114
|
+
customerId: identity.customerId,
|
|
115
|
+
subscriptionId: identity.subscriptionId,
|
|
116
|
+
scheduleId: identity.scheduleId,
|
|
117
|
+
},
|
|
118
|
+
configureRequestBinding: text(
|
|
119
|
+
object(object(record.request).requestIdentity).binding,
|
|
120
|
+
),
|
|
121
|
+
observedItemId: material.observedItemId,
|
|
122
|
+
nativePeriod: material.nativePeriod,
|
|
123
|
+
});
|
|
124
|
+
const digest = await crypto.subtle.digest(
|
|
125
|
+
"SHA-256",
|
|
126
|
+
new TextEncoder().encode("renewal-witness:v1\u0000" + canonical.json),
|
|
127
|
+
);
|
|
128
|
+
const hex = [...new Uint8Array(digest)]
|
|
129
|
+
.map((n) => n.toString(16).padStart(2, "0"))
|
|
130
|
+
.join("");
|
|
131
|
+
const payloadBinding = "renewal-witness:v1:sha256:" + hex;
|
|
132
|
+
const fields = freeze({
|
|
133
|
+
version: 1,
|
|
134
|
+
identity: payload.identity,
|
|
135
|
+
payloadBinding,
|
|
136
|
+
capturedSubject: payload.capturedSubject,
|
|
137
|
+
observedAtMs: payload.acquisition.observedAtMs,
|
|
138
|
+
customerAccountId: identity.customerAccountId,
|
|
139
|
+
customerId: identity.customerId,
|
|
140
|
+
livemode: identity.livemode,
|
|
141
|
+
subscriptionId: identity.subscriptionId,
|
|
142
|
+
scheduleId: identity.scheduleId,
|
|
143
|
+
observedItemId: material.observedItemId,
|
|
144
|
+
nativePeriod: material.nativePeriod,
|
|
145
|
+
operationalAuthority: false,
|
|
146
|
+
authenticationEstablished: false,
|
|
147
|
+
publicDeliveryEstablished: false,
|
|
148
|
+
providerQualificationRequired: true,
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
identity: freeze(evidence.identity),
|
|
152
|
+
payload,
|
|
153
|
+
payloadJSON: canonical.json,
|
|
154
|
+
scope,
|
|
155
|
+
fields,
|
|
156
|
+
historicalInput: {
|
|
157
|
+
configuration: record.configuration,
|
|
158
|
+
configureReceipt,
|
|
159
|
+
historicalSnapshot: {
|
|
160
|
+
reads: payload.reads,
|
|
161
|
+
invoiceContext: payload.invoiceContext,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export type InspectedWitness = Awaited<
|
|
167
|
+
ReturnType<typeof inspectWitnessPayload>
|
|
168
|
+
>;
|
|
169
|
+
export function checkedWitnessDescriptor(
|
|
170
|
+
raw: unknown,
|
|
171
|
+
admitted: InspectedWitness,
|
|
172
|
+
) {
|
|
173
|
+
const descriptor = closed(raw, [
|
|
174
|
+
...Object.keys(admitted.fields),
|
|
175
|
+
"witnessRowId",
|
|
176
|
+
]);
|
|
177
|
+
const witnessRowId = text(descriptor.witnessRowId);
|
|
178
|
+
matchConfigureDATA(descriptor, { ...admitted.fields, witnessRowId });
|
|
179
|
+
return freeze({ ...admitted.fields, witnessRowId });
|
|
180
|
+
}
|
|
181
|
+
export function checkWitnessC7(
|
|
182
|
+
payload: WitnessPayload,
|
|
183
|
+
state: ObservationInvocationState,
|
|
184
|
+
) {
|
|
185
|
+
matchConfigureDATA(
|
|
186
|
+
payload.source.configure.record.configureRecord,
|
|
187
|
+
state.readCaptured().history.record,
|
|
188
|
+
);
|
|
189
|
+
}
|
package/src/client/billing/renewalAttach/internal/observation/witnessHistorical.integration.test.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
prepareWitnessObservation,
|
|
3
|
+
invokeWitnessCapture,
|
|
4
|
+
invokeWitnessRead,
|
|
5
|
+
readStoredWitness,
|
|
6
|
+
witnessFixtureOptions,
|
|
7
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
8
|
+
import { retainLaterWitnessC9 } from "../test-fixtures/witnessHistory.js";
|
|
9
|
+
import { configureAdmissionCase } from "../test-fixtures/producerConfigureAdmission.js";
|
|
10
|
+
import { inspectHistoricalMaterialEvidenceV1 } from "../../../renewalObservation/evidence-material.js";
|
|
11
|
+
import { expect } from "vitest";
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
|
|
14
|
+
configureAdmissionCase(
|
|
15
|
+
"a captured-null witness does not inherit a later real C9 context",
|
|
16
|
+
prepareWitnessObservation,
|
|
17
|
+
async (h, state) => {
|
|
18
|
+
await invokeWitnessCapture(h, state);
|
|
19
|
+
const stored = await readStoredWitness(h, state);
|
|
20
|
+
assert(stored);
|
|
21
|
+
const payload = JSON.parse(stored.payloadJSON);
|
|
22
|
+
expect(payload.source.configure.acknowledgement).toBeNull();
|
|
23
|
+
const later = await retainLaterWitnessC9(h, state, 1);
|
|
24
|
+
const conflated = await inspectHistoricalMaterialEvidenceV1({
|
|
25
|
+
configuration: later.rawReceipt.configuration,
|
|
26
|
+
configureReceipt: later.rawReceipt,
|
|
27
|
+
historicalSnapshot: {
|
|
28
|
+
reads: payload.reads,
|
|
29
|
+
invoiceContext: payload.invoiceContext,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
expect(conflated.predicate).toBe("unknown");
|
|
33
|
+
const output = await invokeWitnessRead(h, state);
|
|
34
|
+
expect(output.history.configureReceipt).not.toBeNull();
|
|
35
|
+
expect(output.evidence?.currentMaterial.predicate).toBe("unknown");
|
|
36
|
+
expect(output.evidence?.historicalMaterial.predicate).toBe(
|
|
37
|
+
"snapshot_target_material_match",
|
|
38
|
+
);
|
|
39
|
+
expect(await readStoredWitness(h, state)).toEqual(stored);
|
|
40
|
+
},
|
|
41
|
+
witnessFixtureOptions,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
let rejectCurrentRead = false;
|
|
45
|
+
configureAdmissionCase(
|
|
46
|
+
"a first-GET provider rejection preserves only validated historical intent and material",
|
|
47
|
+
async (h) => {
|
|
48
|
+
rejectCurrentRead = false;
|
|
49
|
+
return prepareWitnessObservation(h);
|
|
50
|
+
},
|
|
51
|
+
async (h, state) => {
|
|
52
|
+
const captured = await invokeWitnessCapture(h, state);
|
|
53
|
+
assert(captured.evidence?.identity);
|
|
54
|
+
const stored = await readStoredWitness(h, state);
|
|
55
|
+
assert(stored);
|
|
56
|
+
const before = h.calls.length;
|
|
57
|
+
rejectCurrentRead = true;
|
|
58
|
+
const output = await invokeWitnessRead(h, state);
|
|
59
|
+
expect(output.status).toBe("observation_provider_rejected");
|
|
60
|
+
expect(output.reads).toBeNull();
|
|
61
|
+
expect(output.evidence?.currentMaterial.predicate).toBe("unknown");
|
|
62
|
+
expect(output.evidence?.lifecycle.predicate).toBe("unknown");
|
|
63
|
+
expect(output.evidence?.historicalMaterial.predicate).toBe(
|
|
64
|
+
"snapshot_target_material_match",
|
|
65
|
+
);
|
|
66
|
+
expect(output.evidence?.identity).toEqual(captured.evidence.identity);
|
|
67
|
+
expect(h.calls.slice(before)).toHaveLength(1);
|
|
68
|
+
expect(await readStoredWitness(h, state)).toEqual(stored);
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
...witnessFixtureOptions,
|
|
72
|
+
beforeFetch: async () => {
|
|
73
|
+
if (rejectCurrentRead) throw Error("CONTROLLED_FRESH_PROVIDER_FAILURE");
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
configureAdmissionCase(
|
|
79
|
+
"later terminal and settings drift cannot rewrite the retained active native snapshot",
|
|
80
|
+
prepareWitnessObservation,
|
|
81
|
+
async (h, state) => {
|
|
82
|
+
await invokeWitnessCapture(h, state);
|
|
83
|
+
const stored = await readStoredWitness(h, state);
|
|
84
|
+
assert(stored);
|
|
85
|
+
state.reads.schedule.status = "completed";
|
|
86
|
+
state.reads.schedule.current_phase = null;
|
|
87
|
+
state.reads.schedule.completed_at = state.scope.nativePeriod.end;
|
|
88
|
+
state.reads.subscription.cancel_at_period_end = true;
|
|
89
|
+
const output = await invokeWitnessRead(h, state);
|
|
90
|
+
expect(output.evidence?.lifecycle.providerStatus).toBe("completed");
|
|
91
|
+
expect(output.evidence?.currentMaterial.predicate).toBe("unknown");
|
|
92
|
+
expect(output.evidence?.historicalMaterial.predicate).toBe(
|
|
93
|
+
"snapshot_target_material_match",
|
|
94
|
+
);
|
|
95
|
+
expect(await readStoredWitness(h, state)).toEqual(stored);
|
|
96
|
+
},
|
|
97
|
+
witnessFixtureOptions,
|
|
98
|
+
);
|
package/src/client/billing/renewalAttach/internal/observation/witnessImmutable.integration.test.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
prepareWitnessObservation,
|
|
3
|
+
invokeWitnessCapture,
|
|
4
|
+
readStoredWitness,
|
|
5
|
+
witnessFixtureOptions,
|
|
6
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
7
|
+
import { configureAdmissionCase } from "../test-fixtures/producerConfigureAdmission.js";
|
|
8
|
+
import { getFunctionAddress } from "convex/server";
|
|
9
|
+
import { expect, vi } from "vitest";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
|
|
12
|
+
configureAdmissionCase(
|
|
13
|
+
"concurrent fresh invocations retain one immutable witness through two original RPCs",
|
|
14
|
+
prepareWitnessObservation,
|
|
15
|
+
async (h, state) => {
|
|
16
|
+
let mutations = 0;
|
|
17
|
+
const options: NonNullable<Parameters<typeof invokeWitnessCapture>[2]> = {
|
|
18
|
+
before(ctx) {
|
|
19
|
+
const original = ctx.runMutation;
|
|
20
|
+
Object.defineProperty(ctx, "runMutation", {
|
|
21
|
+
value: (...args: Parameters<typeof original>) => {
|
|
22
|
+
if (
|
|
23
|
+
getFunctionAddress(args[0]).reference?.endsWith(
|
|
24
|
+
"/retainAuthorizedWitness",
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
mutations++;
|
|
28
|
+
return original.apply(ctx, args);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const before = h.calls.length;
|
|
34
|
+
const [first, second] = await Promise.all([
|
|
35
|
+
invokeWitnessCapture(h, state, options),
|
|
36
|
+
invokeWitnessCapture(h, state, options),
|
|
37
|
+
]);
|
|
38
|
+
assert(
|
|
39
|
+
"witnessRetention" in first &&
|
|
40
|
+
first.witnessRetention?.status === "retained",
|
|
41
|
+
);
|
|
42
|
+
assert(
|
|
43
|
+
"witnessRetention" in second &&
|
|
44
|
+
second.witnessRetention?.status === "retained",
|
|
45
|
+
);
|
|
46
|
+
expect(second.witnessRetention).toEqual(first.witnessRetention);
|
|
47
|
+
expect((await readStoredWitness(h, state))?.descriptor).toEqual(
|
|
48
|
+
first.witnessRetention.descriptor,
|
|
49
|
+
);
|
|
50
|
+
expect(mutations).toBe(2);
|
|
51
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
52
|
+
Array(12).fill("GET"),
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
witnessFixtureOptions,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
configureAdmissionCase(
|
|
59
|
+
"a later valid capture conflicts under its original witness identity without overwrite or rotation",
|
|
60
|
+
prepareWitnessObservation,
|
|
61
|
+
async (h, state) => {
|
|
62
|
+
await invokeWitnessCapture(h, state);
|
|
63
|
+
const original = await readStoredWitness(h, state);
|
|
64
|
+
assert(original);
|
|
65
|
+
vi.setSystemTime(Date.now() + 1);
|
|
66
|
+
const output = await invokeWitnessCapture(h, state);
|
|
67
|
+
assert("witnessRetention" in output);
|
|
68
|
+
expect(output.witnessRetention).toEqual({
|
|
69
|
+
status: "conflict",
|
|
70
|
+
reason: "identity_changed",
|
|
71
|
+
});
|
|
72
|
+
expect(output.evidence?.currentMaterial.predicate).toBe(
|
|
73
|
+
"current_target_material_match",
|
|
74
|
+
);
|
|
75
|
+
expect(await readStoredWitness(h, state)).toEqual(original);
|
|
76
|
+
},
|
|
77
|
+
witnessFixtureOptions,
|
|
78
|
+
);
|
package/src/client/billing/renewalAttach/internal/observation/witnessInvoice.integration.test.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
witnessControls,
|
|
3
|
+
prepareWitnessObservation,
|
|
4
|
+
invokeWitnessCapture,
|
|
5
|
+
invokeWitnessRead,
|
|
6
|
+
readStoredWitness,
|
|
7
|
+
witnessFixtureOptions,
|
|
8
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
9
|
+
import { invoiceControls } from "../test-fixtures/invoiceObservation.js";
|
|
10
|
+
import { configureAdmissionCase } from "../test-fixtures/producerConfigureAdmission.js";
|
|
11
|
+
import { expect } from "vitest";
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
|
|
14
|
+
for (const retained of [false, true])
|
|
15
|
+
configureAdmissionCase(
|
|
16
|
+
"retains complete acquired invoice context with actual C9 " + retained,
|
|
17
|
+
(h) => prepareWitnessObservation(h, retained, true),
|
|
18
|
+
async (h, state) => {
|
|
19
|
+
assert(
|
|
20
|
+
state.invoiceInventories && Array.isArray(state.invoiceInventories),
|
|
21
|
+
);
|
|
22
|
+
const before = h.calls.length;
|
|
23
|
+
const output = await invokeWitnessCapture(h, state);
|
|
24
|
+
assert(
|
|
25
|
+
"witnessRetention" in output &&
|
|
26
|
+
output.witnessRetention?.status === "retained",
|
|
27
|
+
);
|
|
28
|
+
expect(output.evidence?.invoiceEvidence.predicate).toBe(
|
|
29
|
+
"invoice_lines_correlated",
|
|
30
|
+
);
|
|
31
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
32
|
+
Array(11).fill("GET"),
|
|
33
|
+
);
|
|
34
|
+
const stored = await readStoredWitness(h, state);
|
|
35
|
+
assert(stored);
|
|
36
|
+
const payload = JSON.parse(stored.payloadJSON);
|
|
37
|
+
const [original, current] = state.invoiceInventories;
|
|
38
|
+
expect(payload.invoiceContext).toEqual({
|
|
39
|
+
original: { invoice: original.invoice, linePages: [original.page] },
|
|
40
|
+
current: { invoice: current.invoice, linePages: [current.page] },
|
|
41
|
+
});
|
|
42
|
+
expect(payload.acquisition.invoiceReadProfile).toBe(
|
|
43
|
+
"endive-pinned-invoices-fence-7-v1",
|
|
44
|
+
);
|
|
45
|
+
expect(
|
|
46
|
+
payload.invoiceContext.current.linePages[0].data[0].pricing
|
|
47
|
+
.unit_amount_decimal,
|
|
48
|
+
).toBe(current.page.data[0].pricing.unit_amount_decimal);
|
|
49
|
+
expect(payload.source.configure.acknowledgement === null).toBe(!retained);
|
|
50
|
+
const baseOnlyRead = Object.freeze({
|
|
51
|
+
...state.readProfile,
|
|
52
|
+
invoiceProfile: null,
|
|
53
|
+
});
|
|
54
|
+
witnessControls.readers.splice(
|
|
55
|
+
0,
|
|
56
|
+
witnessControls.readers.length,
|
|
57
|
+
baseOnlyRead,
|
|
58
|
+
);
|
|
59
|
+
state.reads.subscription.cancel_at_period_end = true;
|
|
60
|
+
const later = await invokeWitnessRead(h, state);
|
|
61
|
+
expect(later.evidence?.currentMaterial.predicate).toBe("unknown");
|
|
62
|
+
expect(later.evidence?.invoiceEvidence.reason).toBe("not_supplied");
|
|
63
|
+
expect(later.evidence?.historicalMaterial.predicate).toBe(
|
|
64
|
+
"snapshot_target_material_match",
|
|
65
|
+
);
|
|
66
|
+
expect(await readStoredWitness(h, state)).toEqual(stored);
|
|
67
|
+
expect(h.calls.slice(before)).toHaveLength(17);
|
|
68
|
+
},
|
|
69
|
+
witnessFixtureOptions,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
configureAdmissionCase(
|
|
73
|
+
"invoice evidence permission alone cannot retain a witness",
|
|
74
|
+
(h) => prepareWitnessObservation(h, false, true),
|
|
75
|
+
async (h, state) => {
|
|
76
|
+
witnessControls.denyRetain = true;
|
|
77
|
+
const before = h.calls.length;
|
|
78
|
+
await expect(invokeWitnessCapture(h, state)).rejects.toThrow();
|
|
79
|
+
expect(invoiceControls.count).toBeGreaterThan(0);
|
|
80
|
+
expect(h.calls.slice(before)).toHaveLength(11);
|
|
81
|
+
expect(witnessControls.retainQueries).toBe(1);
|
|
82
|
+
expect(await readStoredWitness(h, state)).toBeNull();
|
|
83
|
+
},
|
|
84
|
+
witnessFixtureOptions,
|
|
85
|
+
);
|