@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
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
captureInitialJournalSelection,
|
|
22
22
|
} from "../producer/classOwnedActionRoot.js";
|
|
23
23
|
import { readObservationInvocation } from "./invocation.js";
|
|
24
|
+
import { captureReaderQueryDATA } from "./readerAuthorization.js";
|
|
24
25
|
import { closed, freeze } from "../c10/ownData.js";
|
|
25
26
|
import {
|
|
26
27
|
baseReadRows,
|
|
@@ -47,6 +48,42 @@ const method = Object.getOwnPropertyDescriptor(
|
|
|
47
48
|
"rawRequest",
|
|
48
49
|
)?.value;
|
|
49
50
|
const nativeThen = Promise.prototype.then;
|
|
51
|
+
type Acquisition = Readonly<{
|
|
52
|
+
reads: ObservationReads;
|
|
53
|
+
invoiceContext: InvoiceContextV1 | null;
|
|
54
|
+
}>;
|
|
55
|
+
type TransportCell = Readonly<{
|
|
56
|
+
profile: FreshObservationProfile;
|
|
57
|
+
invoiceProfile: InvoiceObservationProfile | null;
|
|
58
|
+
guard(): void;
|
|
59
|
+
consume(): Acquisition;
|
|
60
|
+
}>;
|
|
61
|
+
const actualTransports = new WeakMap<object, TransportCell | null>();
|
|
62
|
+
/** Only the original factory registers this guard after actual SDK selection. */
|
|
63
|
+
export function readFreshObservationTransport(
|
|
64
|
+
token: object,
|
|
65
|
+
profile: FreshObservationProfile,
|
|
66
|
+
invoiceProfile: InvoiceObservationProfile | null,
|
|
67
|
+
) {
|
|
68
|
+
const cell = actualTransports.get(token);
|
|
69
|
+
freshNeed(
|
|
70
|
+
cell && cell.profile === profile && cell.invoiceProfile === invoiceProfile,
|
|
71
|
+
);
|
|
72
|
+
cell.guard();
|
|
73
|
+
return cell;
|
|
74
|
+
}
|
|
75
|
+
/** Returned DATA cannot register or replenish this once-consumed acquisition. */
|
|
76
|
+
export function consumeFreshObservationAcquisition(
|
|
77
|
+
token: object,
|
|
78
|
+
profile: FreshObservationProfile,
|
|
79
|
+
invoiceProfile: InvoiceObservationProfile | null,
|
|
80
|
+
) {
|
|
81
|
+
return readFreshObservationTransport(
|
|
82
|
+
token,
|
|
83
|
+
profile,
|
|
84
|
+
invoiceProfile,
|
|
85
|
+
).consume();
|
|
86
|
+
}
|
|
50
87
|
export function captureFreshObservationProfile(
|
|
51
88
|
root: object,
|
|
52
89
|
): FreshObservationProfile {
|
|
@@ -84,6 +121,9 @@ export function captureFreshGetTransport(
|
|
|
84
121
|
freshNeed(arguments.length === 2 || arguments.length === 3);
|
|
85
122
|
const state = readObservationInvocation(token),
|
|
86
123
|
captured = state.readCaptured();
|
|
124
|
+
freshNeed(!actualTransports.has(token));
|
|
125
|
+
// Reserve before any Source callback or SDK selection; failed setup stays unavailable.
|
|
126
|
+
actualTransports.set(token, null);
|
|
87
127
|
freshNeed(state.historyEntry === profile.historyEntry);
|
|
88
128
|
const covers = profile.coversObservation;
|
|
89
129
|
const invoiceAddress =
|
|
@@ -93,6 +133,7 @@ export function captureFreshGetTransport(
|
|
|
93
133
|
typeof createInvoiceAuthorization
|
|
94
134
|
> | null = null;
|
|
95
135
|
let invoiceUsed = false;
|
|
136
|
+
let completeInvoiceContext: InvoiceContextV1 | null = null;
|
|
96
137
|
function profileGuard() {
|
|
97
138
|
if (invoiceProfile) {
|
|
98
139
|
invoiceProfileGuard(invoiceProfile);
|
|
@@ -149,6 +190,53 @@ export function captureFreshGetTransport(
|
|
|
149
190
|
let ordinal = 0,
|
|
150
191
|
busy = false,
|
|
151
192
|
ended = false;
|
|
193
|
+
let acquisitionConsumed = false;
|
|
194
|
+
actualTransports.set(
|
|
195
|
+
token,
|
|
196
|
+
Object.freeze({
|
|
197
|
+
profile,
|
|
198
|
+
invoiceProfile,
|
|
199
|
+
guard,
|
|
200
|
+
consume() {
|
|
201
|
+
guard();
|
|
202
|
+
freshNeed(
|
|
203
|
+
!acquisitionConsumed &&
|
|
204
|
+
!busy &&
|
|
205
|
+
!ended &&
|
|
206
|
+
ordinal >= 4 &&
|
|
207
|
+
bodies.length === ordinal,
|
|
208
|
+
);
|
|
209
|
+
const reads: ObservationReads = {
|
|
210
|
+
schedule: bodies[0],
|
|
211
|
+
subscription: bodies[1],
|
|
212
|
+
targetPrice: bodies[2],
|
|
213
|
+
billingCustomer: bodies[3],
|
|
214
|
+
coupons: bodies.slice(4),
|
|
215
|
+
};
|
|
216
|
+
validateBaseRouting(captured.history.record, reads);
|
|
217
|
+
const ids = observationCouponIds(
|
|
218
|
+
captured.history.record,
|
|
219
|
+
reads.subscription,
|
|
220
|
+
);
|
|
221
|
+
freshNeed(ordinal === 4 + ids.length);
|
|
222
|
+
ids.forEach((id, index) =>
|
|
223
|
+
validateCoupon(captured.history.record, id, reads.coupons[index]),
|
|
224
|
+
);
|
|
225
|
+
freshNeed(
|
|
226
|
+
invoiceProfile === null
|
|
227
|
+
? !invoiceUsed
|
|
228
|
+
: completeInvoiceContext !== null,
|
|
229
|
+
);
|
|
230
|
+
const acquired = captureReaderQueryDATA({
|
|
231
|
+
reads,
|
|
232
|
+
invoiceContext: completeInvoiceContext,
|
|
233
|
+
});
|
|
234
|
+
acquisitionConsumed = true;
|
|
235
|
+
guard();
|
|
236
|
+
return acquired;
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
152
240
|
function expected() {
|
|
153
241
|
if (ordinal < 4) return base[ordinal];
|
|
154
242
|
const reads: ObservationReads = {
|
|
@@ -364,9 +452,10 @@ export function captureFreshGetTransport(
|
|
|
364
452
|
});
|
|
365
453
|
}
|
|
366
454
|
}
|
|
455
|
+
completeInvoiceContext = plan.context();
|
|
367
456
|
return Object.freeze({
|
|
368
457
|
status: "complete",
|
|
369
|
-
context:
|
|
458
|
+
context: completeInvoiceContext,
|
|
370
459
|
reason: null,
|
|
371
460
|
failure: null,
|
|
372
461
|
});
|
|
@@ -33,6 +33,7 @@ type CapturedHistory = Readonly<{
|
|
|
33
33
|
export interface ObservationInvocationState {
|
|
34
34
|
readonly binding: object;
|
|
35
35
|
readonly historyEntry: ObservationHistorySourceEntry;
|
|
36
|
+
readonly startedAt: Readonly<{ wallMs: number; ns: bigint }>;
|
|
36
37
|
guard(): void;
|
|
37
38
|
check(): { wallMs: number; ns: bigint };
|
|
38
39
|
close(): void;
|
|
@@ -273,6 +274,7 @@ export async function captureObservationInvocation(
|
|
|
273
274
|
Object.freeze({
|
|
274
275
|
binding,
|
|
275
276
|
historyEntry: entry,
|
|
277
|
+
startedAt: lifetime.startedAt,
|
|
276
278
|
guard() {
|
|
277
279
|
lifetime.check();
|
|
278
280
|
guard();
|
|
@@ -175,5 +175,10 @@ export function createObservationReaderLifetime() {
|
|
|
175
175
|
throw error;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
return Object.freeze({
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
startedAt: Object.freeze({ ...initial }),
|
|
180
|
+
check,
|
|
181
|
+
close,
|
|
182
|
+
owned,
|
|
183
|
+
});
|
|
179
184
|
}
|
package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import {
|
|
2
|
+
witnessControls,
|
|
3
|
+
prepareWitnessObservation,
|
|
4
|
+
readStoredWitness,
|
|
5
|
+
witnessFixtureOptions,
|
|
6
|
+
} from "../test-fixtures/witnessObservation.js";
|
|
7
|
+
import {
|
|
8
|
+
configureAdmissionCase,
|
|
9
|
+
admissionControls,
|
|
10
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
11
|
+
import {
|
|
12
|
+
captureObservationInvocation,
|
|
13
|
+
readObservationInvocation,
|
|
14
|
+
closeObservationInvocation,
|
|
15
|
+
} from "./invocation.js";
|
|
16
|
+
import * as transportAPI from "./freshTransport.js";
|
|
17
|
+
import { createWitnessOperation } from "./witnessOperation.js";
|
|
18
|
+
import {
|
|
19
|
+
baseReadRows,
|
|
20
|
+
observationCouponIds,
|
|
21
|
+
couponReadRow,
|
|
22
|
+
} from "./profile.js";
|
|
23
|
+
import { expect } from "vitest";
|
|
24
|
+
import assert from "node:assert/strict";
|
|
25
|
+
import type { FreshObservationProfile } from "../operations/sourceOperations.js";
|
|
26
|
+
|
|
27
|
+
configureAdmissionCase(
|
|
28
|
+
"supplied material and a live selected SDK cannot substitute for actual fresh GET acquisition",
|
|
29
|
+
prepareWitnessObservation,
|
|
30
|
+
async (h, prepared) => {
|
|
31
|
+
const before = h.calls.length;
|
|
32
|
+
await h.inAnotherAction(async (ctx) => {
|
|
33
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
34
|
+
actualActionCtx: ctx,
|
|
35
|
+
operationId: prepared.operationId,
|
|
36
|
+
parentOperationId: prepared.parentOperationId,
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
await readObservationInvocation(token).captureHistory();
|
|
40
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
41
|
+
token,
|
|
42
|
+
prepared.profile,
|
|
43
|
+
);
|
|
44
|
+
const supplied = {
|
|
45
|
+
...prepared.reads,
|
|
46
|
+
coupons: h.source.originalBundle.couponReads.map(
|
|
47
|
+
(row) => row.wireCoupon,
|
|
48
|
+
),
|
|
49
|
+
};
|
|
50
|
+
await expect(
|
|
51
|
+
(async () => {
|
|
52
|
+
const operation = Reflect.apply(createWitnessOperation, undefined, [
|
|
53
|
+
token,
|
|
54
|
+
prepared.captureProfile,
|
|
55
|
+
"retain",
|
|
56
|
+
prepared.scope.identity,
|
|
57
|
+
port.guard,
|
|
58
|
+
]);
|
|
59
|
+
return Reflect.apply(operation.retain, operation, [supplied, null]);
|
|
60
|
+
})(),
|
|
61
|
+
).rejects.toThrow();
|
|
62
|
+
const operation = createWitnessOperation(
|
|
63
|
+
token,
|
|
64
|
+
prepared.captureProfile,
|
|
65
|
+
"retain",
|
|
66
|
+
prepared.scope.identity,
|
|
67
|
+
);
|
|
68
|
+
await expect(operation.retain()).rejects.toThrow(
|
|
69
|
+
"FRESH_OBSERVATION_UNBOUND",
|
|
70
|
+
);
|
|
71
|
+
} finally {
|
|
72
|
+
closeObservationInvocation(token);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
expect(h.calls).toHaveLength(before);
|
|
76
|
+
expect(witnessControls.retainQueries).toBe(0);
|
|
77
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
78
|
+
},
|
|
79
|
+
witnessFixtureOptions,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
configureAdmissionCase(
|
|
83
|
+
"one invocation cannot mint a second transport or consume acquisition before its actual reads",
|
|
84
|
+
prepareWitnessObservation,
|
|
85
|
+
async (h, prepared) => {
|
|
86
|
+
const before = h.calls.length,
|
|
87
|
+
selectors = admissionControls.selectors;
|
|
88
|
+
await h.inAnotherAction(async (ctx) => {
|
|
89
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
90
|
+
actualActionCtx: ctx,
|
|
91
|
+
operationId: prepared.operationId,
|
|
92
|
+
parentOperationId: prepared.parentOperationId,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
await readObservationInvocation(token).captureHistory();
|
|
96
|
+
transportAPI.captureFreshGetTransport(token, prepared.profile);
|
|
97
|
+
expect(() =>
|
|
98
|
+
transportAPI.captureFreshGetTransport(token, prepared.profile),
|
|
99
|
+
).toThrow();
|
|
100
|
+
const consume = Reflect.get(
|
|
101
|
+
transportAPI,
|
|
102
|
+
"consumeFreshObservationAcquisition",
|
|
103
|
+
);
|
|
104
|
+
expect(typeof consume).toBe("function");
|
|
105
|
+
expect(() =>
|
|
106
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
107
|
+
).toThrow();
|
|
108
|
+
} finally {
|
|
109
|
+
closeObservationInvocation(token);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
expect(admissionControls.selectors).toBe(selectors + 1);
|
|
113
|
+
expect(h.calls).toHaveLength(before);
|
|
114
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
115
|
+
},
|
|
116
|
+
witnessFixtureOptions,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
configureAdmissionCase(
|
|
120
|
+
"only completed original transport bodies create a once-consumed acquisition receipt",
|
|
121
|
+
prepareWitnessObservation,
|
|
122
|
+
async (h, prepared) => {
|
|
123
|
+
const before = h.calls.length;
|
|
124
|
+
await h.inAnotherAction(async (ctx) => {
|
|
125
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
126
|
+
actualActionCtx: ctx,
|
|
127
|
+
operationId: prepared.operationId,
|
|
128
|
+
parentOperationId: prepared.parentOperationId,
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
const captured =
|
|
132
|
+
await readObservationInvocation(token).captureHistory();
|
|
133
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
134
|
+
token,
|
|
135
|
+
prepared.profile,
|
|
136
|
+
);
|
|
137
|
+
const bodies = [];
|
|
138
|
+
for (const row of baseReadRows(captured.history.record)) {
|
|
139
|
+
const result = await port.read(row);
|
|
140
|
+
assert(result.kind === "fulfilled");
|
|
141
|
+
bodies.push(result.body);
|
|
142
|
+
}
|
|
143
|
+
const consume = Reflect.get(
|
|
144
|
+
transportAPI,
|
|
145
|
+
"consumeFreshObservationAcquisition",
|
|
146
|
+
);
|
|
147
|
+
expect(typeof consume).toBe("function");
|
|
148
|
+
expect(() =>
|
|
149
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
150
|
+
).toThrow();
|
|
151
|
+
const coupons = [];
|
|
152
|
+
for (const id of observationCouponIds(
|
|
153
|
+
captured.history.record,
|
|
154
|
+
bodies[1],
|
|
155
|
+
)) {
|
|
156
|
+
const result = await port.read(couponReadRow(id, 5 + coupons.length));
|
|
157
|
+
assert(result.kind === "fulfilled");
|
|
158
|
+
coupons.push(result.body);
|
|
159
|
+
}
|
|
160
|
+
const receipt = Reflect.apply(consume, transportAPI, [
|
|
161
|
+
token,
|
|
162
|
+
prepared.profile,
|
|
163
|
+
null,
|
|
164
|
+
]);
|
|
165
|
+
expect(receipt.reads).toEqual({
|
|
166
|
+
schedule: bodies[0],
|
|
167
|
+
subscription: bodies[1],
|
|
168
|
+
targetPrice: bodies[2],
|
|
169
|
+
billingCustomer: bodies[3],
|
|
170
|
+
coupons,
|
|
171
|
+
});
|
|
172
|
+
expect(receipt.invoiceContext).toBeNull();
|
|
173
|
+
expect(() =>
|
|
174
|
+
Reflect.apply(consume, transportAPI, [token, prepared.profile, null]),
|
|
175
|
+
).toThrow();
|
|
176
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
177
|
+
} finally {
|
|
178
|
+
closeObservationInvocation(token);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
182
|
+
Array(6).fill("GET"),
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
witnessFixtureOptions,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
configureAdmissionCase(
|
|
189
|
+
"an invoice acquisition receipt requires the actual complete fenced invoice plan",
|
|
190
|
+
(h) => prepareWitnessObservation(h, false, true),
|
|
191
|
+
async (h, prepared) => {
|
|
192
|
+
const before = h.calls.length;
|
|
193
|
+
await h.inAnotherAction(async (ctx) => {
|
|
194
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
195
|
+
actualActionCtx: ctx,
|
|
196
|
+
operationId: prepared.operationId,
|
|
197
|
+
parentOperationId: prepared.parentOperationId,
|
|
198
|
+
});
|
|
199
|
+
try {
|
|
200
|
+
const captured =
|
|
201
|
+
await readObservationInvocation(token).captureHistory();
|
|
202
|
+
assert(prepared.captureProfile.invoiceProfile);
|
|
203
|
+
const port = transportAPI.captureFreshGetTransport(
|
|
204
|
+
token,
|
|
205
|
+
prepared.profile,
|
|
206
|
+
prepared.captureProfile.invoiceProfile,
|
|
207
|
+
);
|
|
208
|
+
const bodies = [];
|
|
209
|
+
for (const row of baseReadRows(captured.history.record)) {
|
|
210
|
+
const result = await port.read(row);
|
|
211
|
+
assert(result.kind === "fulfilled");
|
|
212
|
+
bodies.push(result.body);
|
|
213
|
+
}
|
|
214
|
+
let ordinal = 5;
|
|
215
|
+
for (const id of observationCouponIds(
|
|
216
|
+
captured.history.record,
|
|
217
|
+
bodies[1],
|
|
218
|
+
)) {
|
|
219
|
+
const result = await port.read(couponReadRow(id, ordinal++));
|
|
220
|
+
assert(result.kind === "fulfilled");
|
|
221
|
+
}
|
|
222
|
+
expect(() =>
|
|
223
|
+
transportAPI.consumeFreshObservationAcquisition(
|
|
224
|
+
token,
|
|
225
|
+
prepared.profile,
|
|
226
|
+
prepared.captureProfile.invoiceProfile,
|
|
227
|
+
),
|
|
228
|
+
).toThrow();
|
|
229
|
+
const result = await port.acquireInvoices();
|
|
230
|
+
expect(result.status).toBe("complete");
|
|
231
|
+
const receipt = transportAPI.consumeFreshObservationAcquisition(
|
|
232
|
+
token,
|
|
233
|
+
prepared.profile,
|
|
234
|
+
prepared.captureProfile.invoiceProfile,
|
|
235
|
+
);
|
|
236
|
+
expect(receipt.invoiceContext).toEqual(result.context);
|
|
237
|
+
expect(() =>
|
|
238
|
+
transportAPI.consumeFreshObservationAcquisition(
|
|
239
|
+
token,
|
|
240
|
+
prepared.profile,
|
|
241
|
+
prepared.captureProfile.invoiceProfile,
|
|
242
|
+
),
|
|
243
|
+
).toThrow();
|
|
244
|
+
} finally {
|
|
245
|
+
closeObservationInvocation(token);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
expect(h.calls.slice(before).map((c) => c.method)).toEqual(
|
|
249
|
+
Array(11).fill("GET"),
|
|
250
|
+
);
|
|
251
|
+
expect(await readStoredWitness(h, prepared)).toBeNull();
|
|
252
|
+
},
|
|
253
|
+
witnessFixtureOptions,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
configureAdmissionCase(
|
|
257
|
+
"reentrant Source qualification cannot mint a second transport before registration",
|
|
258
|
+
prepareWitnessObservation,
|
|
259
|
+
async (h, prepared) => {
|
|
260
|
+
const selectors = admissionControls.selectors,
|
|
261
|
+
before = h.calls.length;
|
|
262
|
+
await h.inAnotherAction(async (ctx) => {
|
|
263
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
264
|
+
actualActionCtx: ctx,
|
|
265
|
+
operationId: prepared.operationId,
|
|
266
|
+
parentOperationId: prepared.parentOperationId,
|
|
267
|
+
});
|
|
268
|
+
let entered = false,
|
|
269
|
+
nested: unknown = null,
|
|
270
|
+
nestedError: unknown = null;
|
|
271
|
+
const profile: FreshObservationProfile = Object.freeze({
|
|
272
|
+
...prepared.profile,
|
|
273
|
+
coversObservation() {
|
|
274
|
+
if (!entered) {
|
|
275
|
+
entered = true;
|
|
276
|
+
try {
|
|
277
|
+
nested = transportAPI.captureFreshGetTransport(token, profile);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
nestedError = error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return true;
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
admissionControls.observation.splice(
|
|
286
|
+
0,
|
|
287
|
+
admissionControls.observation.length,
|
|
288
|
+
profile,
|
|
289
|
+
);
|
|
290
|
+
try {
|
|
291
|
+
await readObservationInvocation(token).captureHistory();
|
|
292
|
+
transportAPI.captureFreshGetTransport(token, profile);
|
|
293
|
+
expect(nested).toBeNull();
|
|
294
|
+
expect(nestedError).toEqual(Error("FRESH_OBSERVATION_UNBOUND"));
|
|
295
|
+
} finally {
|
|
296
|
+
closeObservationInvocation(token);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
expect(admissionControls.selectors).toBe(selectors + 1);
|
|
300
|
+
expect(h.calls).toHaveLength(before);
|
|
301
|
+
},
|
|
302
|
+
witnessFixtureOptions,
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
configureAdmissionCase(
|
|
306
|
+
"failed transport qualification cannot reset the same invocation's acquisition attempt",
|
|
307
|
+
prepareWitnessObservation,
|
|
308
|
+
async (h, prepared) => {
|
|
309
|
+
const selectors = admissionControls.selectors;
|
|
310
|
+
await h.inAnotherAction(async (ctx) => {
|
|
311
|
+
const token = await captureObservationInvocation(h.sdk, {
|
|
312
|
+
actualActionCtx: ctx,
|
|
313
|
+
operationId: prepared.operationId,
|
|
314
|
+
parentOperationId: prepared.parentOperationId,
|
|
315
|
+
});
|
|
316
|
+
let fail = true,
|
|
317
|
+
qualifications = 0;
|
|
318
|
+
const profile: FreshObservationProfile = Object.freeze({
|
|
319
|
+
...prepared.profile,
|
|
320
|
+
coversObservation() {
|
|
321
|
+
qualifications++;
|
|
322
|
+
if (fail) throw Error("CONTROLLED_SOURCE_QUALIFICATION_FAILURE");
|
|
323
|
+
return true;
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
admissionControls.observation.splice(
|
|
327
|
+
0,
|
|
328
|
+
admissionControls.observation.length,
|
|
329
|
+
profile,
|
|
330
|
+
);
|
|
331
|
+
try {
|
|
332
|
+
await readObservationInvocation(token).captureHistory();
|
|
333
|
+
expect(() =>
|
|
334
|
+
transportAPI.captureFreshGetTransport(token, profile),
|
|
335
|
+
).toThrow("CONTROLLED_SOURCE_QUALIFICATION_FAILURE");
|
|
336
|
+
fail = false;
|
|
337
|
+
expect(() =>
|
|
338
|
+
transportAPI.captureFreshGetTransport(token, profile),
|
|
339
|
+
).toThrow("FRESH_OBSERVATION_UNBOUND");
|
|
340
|
+
expect(qualifications).toBe(1);
|
|
341
|
+
} finally {
|
|
342
|
+
closeObservationInvocation(token);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
346
|
+
},
|
|
347
|
+
witnessFixtureOptions,
|
|
348
|
+
);
|