@fantastic.dev/better-stripe 0.111.0 → 0.113.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 +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-example-authorization.md +74 -0
- 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 +28 -11
- 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
|
@@ -4,7 +4,6 @@ import { convexTest } from "convex-test";
|
|
|
4
4
|
import {
|
|
5
5
|
actionGeneric,
|
|
6
6
|
queryGeneric,
|
|
7
|
-
defineSchema,
|
|
8
7
|
makeFunctionReference,
|
|
9
8
|
getFunctionAddress,
|
|
10
9
|
type GenericActionCtx,
|
|
@@ -13,6 +12,11 @@ import {
|
|
|
13
12
|
import { BetterStripe } from "../../../../index.js";
|
|
14
13
|
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
15
14
|
import { modules, schema } from "../../../../../test.js";
|
|
15
|
+
import {
|
|
16
|
+
modules as exampleModules,
|
|
17
|
+
schema as exampleSchema,
|
|
18
|
+
} from "../../../../../../example/test.js";
|
|
19
|
+
import type { MutationCtx as ExampleMutationCtx } from "../../../../../../example/convex/_generated/server.js";
|
|
16
20
|
import {
|
|
17
21
|
canonical,
|
|
18
22
|
codecFixture,
|
|
@@ -33,8 +37,10 @@ export async function initialOperations(
|
|
|
33
37
|
sdk: BetterStripe;
|
|
34
38
|
index: number;
|
|
35
39
|
ctx: GenericActionCtx<GenericDataModel>;
|
|
40
|
+
runHost(work: (ctx: ExampleMutationCtx) => Promise<void>): Promise<void>;
|
|
36
41
|
inAnotherAction(
|
|
37
42
|
work: (ctx: GenericActionCtx<GenericDataModel>) => Promise<void>,
|
|
43
|
+
identity?: { subject: string; issuer: string; tokenIdentifier: string },
|
|
38
44
|
): Promise<void>;
|
|
39
45
|
}) => Promise<void>,
|
|
40
46
|
count = 1,
|
|
@@ -42,6 +48,8 @@ export async function initialOperations(
|
|
|
42
48
|
identity?: { subject: string; issuer: string; tokenIdentifier: string };
|
|
43
49
|
hostQuery?: ReturnType<typeof queryGeneric>;
|
|
44
50
|
hostInvoiceQuery?: ReturnType<typeof queryGeneric>;
|
|
51
|
+
hostWitnessRetainQuery?: ReturnType<typeof queryGeneric>;
|
|
52
|
+
hostWitnessReadQuery?: ReturnType<typeof queryGeneric>;
|
|
45
53
|
epochMs?: number;
|
|
46
54
|
workEndWallMs?: number;
|
|
47
55
|
endWallMs?: number;
|
|
@@ -184,6 +192,12 @@ export async function initialOperations(
|
|
|
184
192
|
...(options.hostInvoiceQuery
|
|
185
193
|
? { authorizeInvoices: options.hostInvoiceQuery }
|
|
186
194
|
: {}),
|
|
195
|
+
...(options.hostWitnessRetainQuery
|
|
196
|
+
? { authorizeWitnessRetention: options.hostWitnessRetainQuery }
|
|
197
|
+
: {}),
|
|
198
|
+
...(options.hostWitnessReadQuery
|
|
199
|
+
? { authorizeWitnessRead: options.hostWitnessReadQuery }
|
|
200
|
+
: {}),
|
|
187
201
|
secondary: actionGeneric({
|
|
188
202
|
args: { id: v.string() },
|
|
189
203
|
handler: async (ctx, args): Promise<null> => {
|
|
@@ -284,16 +298,19 @@ export async function initialOperations(
|
|
|
284
298
|
sdk: selectedSDK,
|
|
285
299
|
index,
|
|
286
300
|
ctx,
|
|
287
|
-
|
|
301
|
+
runHost: (work) => t.run(work),
|
|
302
|
+
async inAnotherAction(work, identity) {
|
|
288
303
|
const id = String(++secondaryId);
|
|
289
304
|
secondaryWork.set(id, work);
|
|
290
305
|
try {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
)
|
|
306
|
+
const ref = makeFunctionReference<
|
|
307
|
+
"action",
|
|
308
|
+
{ id: string },
|
|
309
|
+
null
|
|
310
|
+
>("initialOwner:secondary");
|
|
311
|
+
if (identity)
|
|
312
|
+
await t.withIdentity(identity).action(ref, { id });
|
|
313
|
+
else await ctx.runAction(ref, { id });
|
|
297
314
|
} finally {
|
|
298
315
|
secondaryWork.delete(id);
|
|
299
316
|
}
|
|
@@ -305,9 +322,9 @@ export async function initialOperations(
|
|
|
305
322
|
},
|
|
306
323
|
}),
|
|
307
324
|
};
|
|
308
|
-
const t = convexTest(
|
|
309
|
-
|
|
310
|
-
"./initialOwner.ts": async () => host,
|
|
325
|
+
const t = convexTest(exampleSchema, {
|
|
326
|
+
...exampleModules,
|
|
327
|
+
"./convex/initialOwner.ts": async () => host,
|
|
311
328
|
});
|
|
312
329
|
t.registerComponent("betterStripe", schema, modules);
|
|
313
330
|
await (options.identity ? t.withIdentity(options.identity) : t).action(
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
3
|
+
import { constructRenewalConfigurationReceiptV2 } from "../../../renewalV2/index.js";
|
|
4
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
5
|
+
import { canonicalConfigure } from "../../../../../component/renewalOperations/configureJournal.fixtures.js";
|
|
6
|
+
import type { prepareWitnessObservation } from "./witnessObservation.js";
|
|
7
|
+
|
|
8
|
+
/** Real later component retention, not a runtime/public provider ACK. */
|
|
9
|
+
export async function retainLaterWitnessC9(
|
|
10
|
+
h: Parameters<typeof prepareWitnessObservation>[0],
|
|
11
|
+
state: Awaited<ReturnType<typeof prepareWitnessObservation>>,
|
|
12
|
+
targetEndOffset = 0,
|
|
13
|
+
) {
|
|
14
|
+
const refs = components.betterStripe.renewalOperations;
|
|
15
|
+
const stage = state.full.configure;
|
|
16
|
+
assert(stage.attempt && "initialBasis" in state.full.parent.operation);
|
|
17
|
+
const basis = state.full.parent.operation.initialBasis;
|
|
18
|
+
assert(basis);
|
|
19
|
+
const record = JSON.parse(stage.operation.recordJSON);
|
|
20
|
+
const reservation = stage.attempt.reservation;
|
|
21
|
+
await h.ctx.runMutation(refs.mutations.bindInitialBasis, {
|
|
22
|
+
operationId: state.operationId,
|
|
23
|
+
attemptId: reservation.attemptId,
|
|
24
|
+
policyJSON: canonicalConfigure(record.timingPolicy),
|
|
25
|
+
basisJSON: basis.basisJSON,
|
|
26
|
+
});
|
|
27
|
+
const body = structuredClone(state.reads.schedule);
|
|
28
|
+
body.current_phase = structuredClone(
|
|
29
|
+
record.configureRecord.configuration.schedule.current_phase,
|
|
30
|
+
);
|
|
31
|
+
const phases = body.phases as Record<string, unknown>[];
|
|
32
|
+
phases[1].end_date = Number(phases[1].end_date) + targetEndOffset;
|
|
33
|
+
const transport = {
|
|
34
|
+
status: 200,
|
|
35
|
+
requestId: "req_controlled_later_witness_C9",
|
|
36
|
+
};
|
|
37
|
+
const rawReceipt = {
|
|
38
|
+
configuration: record.configureRecord.configuration,
|
|
39
|
+
actualDispatch: record.dispatch,
|
|
40
|
+
providerSnapshot: body,
|
|
41
|
+
transport,
|
|
42
|
+
};
|
|
43
|
+
const receipt = await constructRenewalConfigurationReceiptV2(rawReceipt);
|
|
44
|
+
const request = record.configureRecord.request;
|
|
45
|
+
const events = [
|
|
46
|
+
{ event: "dispatch", stage: "configure", request },
|
|
47
|
+
{ event: "response", stage: "configure", request, body, transport },
|
|
48
|
+
{ event: "receipt", stage: "configure", request, receipt },
|
|
49
|
+
];
|
|
50
|
+
for (const [index, event] of events.entries()) {
|
|
51
|
+
if (index === 2)
|
|
52
|
+
await h.ctx.runMutation(refs.mutations.retainProviderAcknowledgement, {
|
|
53
|
+
operationId: state.operationId,
|
|
54
|
+
attemptId: reservation.attemptId,
|
|
55
|
+
expectedSequence: 2,
|
|
56
|
+
receiptJSON: canonicalConfigure(receipt),
|
|
57
|
+
});
|
|
58
|
+
const sequence = index === 0 ? 1 : index === 1 ? 2 : 3;
|
|
59
|
+
const data = await canonicalJournalEvent(
|
|
60
|
+
sequence,
|
|
61
|
+
canonicalConfigure(event),
|
|
62
|
+
);
|
|
63
|
+
await h.ctx.runMutation(refs.mutations.appendStageEvent, {
|
|
64
|
+
reservation,
|
|
65
|
+
expectedSequence: index,
|
|
66
|
+
event: { sequence, binding: data.binding, dataJSON: data.json },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return { rawReceipt, receipt };
|
|
70
|
+
}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { makeFunctionReference, queryGeneric } from "convex/server";
|
|
3
|
+
import { v } from "convex/values";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import type { GenericActionCtx, GenericDataModel } from "convex/server";
|
|
7
|
+
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
8
|
+
import { prepareFreshObservation } from "./freshObservation.js";
|
|
9
|
+
import {
|
|
10
|
+
prepareInvoiceObservation,
|
|
11
|
+
authorizeInvoices,
|
|
12
|
+
} from "./invoiceObservation.js";
|
|
13
|
+
import { observerIdentity } from "./observationReader.js";
|
|
14
|
+
import type { WitnessScope } from "../operations/witnessProfiles.js";
|
|
15
|
+
import {
|
|
16
|
+
captureFreshWitnessRenewalObservation,
|
|
17
|
+
captureHistoricalWitnessRenewalObservation,
|
|
18
|
+
} from "../observation/freshActor.js";
|
|
19
|
+
|
|
20
|
+
const witnessControls = vi.hoisted(() => ({
|
|
21
|
+
captures: [] as unknown[],
|
|
22
|
+
readers: [] as unknown[],
|
|
23
|
+
scope: null as WitnessScope | null,
|
|
24
|
+
retainQueries: 0,
|
|
25
|
+
readQueries: 0,
|
|
26
|
+
denyRetain: false,
|
|
27
|
+
denyRead: false,
|
|
28
|
+
expiresAtMs: 0,
|
|
29
|
+
allowedReaders: [] as string[],
|
|
30
|
+
onRetainGrant: null as
|
|
31
|
+
null | ((grant: Record<string, unknown>, count: number) => void),
|
|
32
|
+
onReadGrant: null as
|
|
33
|
+
null | ((grant: Record<string, unknown>, count: number) => void),
|
|
34
|
+
}));
|
|
35
|
+
export { witnessControls };
|
|
36
|
+
vi.mock("../operations/witnessProfiles.js", () => ({
|
|
37
|
+
COMPILED_WITNESS_CAPTURE_ENTRIES: witnessControls.captures,
|
|
38
|
+
COMPILED_WITNESS_READ_ENTRIES: witnessControls.readers,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const identity = v.object({
|
|
42
|
+
componentScope: v.string(),
|
|
43
|
+
witnessId: v.string(),
|
|
44
|
+
parentOperationId: v.string(),
|
|
45
|
+
operationId: v.string(),
|
|
46
|
+
});
|
|
47
|
+
const scope = v.object({
|
|
48
|
+
identity,
|
|
49
|
+
providerScope: v.object({
|
|
50
|
+
mode: v.literal("platform"),
|
|
51
|
+
stripeAccount: v.null(),
|
|
52
|
+
livemode: v.boolean(),
|
|
53
|
+
customerAccountId: v.string(),
|
|
54
|
+
customerId: v.string(),
|
|
55
|
+
subscriptionId: v.string(),
|
|
56
|
+
scheduleId: v.string(),
|
|
57
|
+
}),
|
|
58
|
+
configureRequestBinding: v.string(),
|
|
59
|
+
observedItemId: v.string(),
|
|
60
|
+
nativePeriod: v.object({ start: v.number(), end: v.number() }),
|
|
61
|
+
});
|
|
62
|
+
const grantFields = {
|
|
63
|
+
scope,
|
|
64
|
+
tokenIdentifier: v.string(),
|
|
65
|
+
authorizationId: v.string(),
|
|
66
|
+
authorizationRevision: v.number(),
|
|
67
|
+
expiresAtMs: v.number(),
|
|
68
|
+
};
|
|
69
|
+
export const authorizeWitnessObservation = queryGeneric({
|
|
70
|
+
args: {
|
|
71
|
+
componentScope: v.string(),
|
|
72
|
+
parentOperationId: v.string(),
|
|
73
|
+
operationId: v.string(),
|
|
74
|
+
},
|
|
75
|
+
returns: v.union(
|
|
76
|
+
v.null(),
|
|
77
|
+
v.object({
|
|
78
|
+
componentScope: v.string(),
|
|
79
|
+
parentOperationId: v.string(),
|
|
80
|
+
operationId: v.string(),
|
|
81
|
+
tokenIdentifier: v.string(),
|
|
82
|
+
authorizationId: v.string(),
|
|
83
|
+
authorizationRevision: v.number(),
|
|
84
|
+
expiresAtMs: v.number(),
|
|
85
|
+
providerScope: v.object({
|
|
86
|
+
mode: v.literal("platform"),
|
|
87
|
+
stripeAccount: v.null(),
|
|
88
|
+
livemode: v.boolean(),
|
|
89
|
+
customerAccountId: v.string(),
|
|
90
|
+
subscriptionId: v.string(),
|
|
91
|
+
scheduleId: v.string(),
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
handler: async (ctx, args) => {
|
|
96
|
+
const who = await ctx.auth.getUserIdentity(),
|
|
97
|
+
expected = witnessControls.scope;
|
|
98
|
+
if (
|
|
99
|
+
!who ||
|
|
100
|
+
!witnessControls.allowedReaders.includes(who.tokenIdentifier) ||
|
|
101
|
+
!expected ||
|
|
102
|
+
args.componentScope !== expected.identity.componentScope ||
|
|
103
|
+
args.parentOperationId !== expected.identity.parentOperationId ||
|
|
104
|
+
args.operationId !== expected.identity.operationId
|
|
105
|
+
)
|
|
106
|
+
return null;
|
|
107
|
+
const p = expected.providerScope;
|
|
108
|
+
return {
|
|
109
|
+
...args,
|
|
110
|
+
tokenIdentifier: who.tokenIdentifier,
|
|
111
|
+
authorizationId: "test-witness-base",
|
|
112
|
+
authorizationRevision: 1,
|
|
113
|
+
expiresAtMs: witnessControls.expiresAtMs,
|
|
114
|
+
providerScope: {
|
|
115
|
+
mode: p.mode,
|
|
116
|
+
stripeAccount: p.stripeAccount,
|
|
117
|
+
livemode: p.livemode,
|
|
118
|
+
customerAccountId: p.customerAccountId,
|
|
119
|
+
subscriptionId: p.subscriptionId,
|
|
120
|
+
scheduleId: p.scheduleId,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
export const authorizeWitnessRetention = queryGeneric({
|
|
126
|
+
args: { capability: v.literal("renewal_witness_retain_v1"), scope },
|
|
127
|
+
returns: v.union(
|
|
128
|
+
v.null(),
|
|
129
|
+
v.object({
|
|
130
|
+
capability: v.literal("renewal_witness_retain_v1"),
|
|
131
|
+
...grantFields,
|
|
132
|
+
}),
|
|
133
|
+
),
|
|
134
|
+
handler: async (ctx, args) => {
|
|
135
|
+
witnessControls.retainQueries++;
|
|
136
|
+
const who = await ctx.auth.getUserIdentity();
|
|
137
|
+
if (
|
|
138
|
+
who?.tokenIdentifier !== observerIdentity.tokenIdentifier ||
|
|
139
|
+
witnessControls.denyRetain ||
|
|
140
|
+
!isDeepStrictEqual(args.scope, witnessControls.scope)
|
|
141
|
+
)
|
|
142
|
+
return null;
|
|
143
|
+
const grant = {
|
|
144
|
+
...args,
|
|
145
|
+
tokenIdentifier: who.tokenIdentifier,
|
|
146
|
+
authorizationId: "test-witness-retention",
|
|
147
|
+
authorizationRevision: 1,
|
|
148
|
+
expiresAtMs: witnessControls.expiresAtMs,
|
|
149
|
+
};
|
|
150
|
+
witnessControls.onRetainGrant?.(grant, witnessControls.retainQueries);
|
|
151
|
+
return grant;
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
export const authorizeWitnessRead = queryGeneric({
|
|
155
|
+
args: { capability: v.literal("renewal_witness_read_v1"), identity },
|
|
156
|
+
returns: v.union(
|
|
157
|
+
v.null(),
|
|
158
|
+
v.object({
|
|
159
|
+
capability: v.literal("renewal_witness_read_v1"),
|
|
160
|
+
...grantFields,
|
|
161
|
+
witnessRowId: v.string(),
|
|
162
|
+
payloadBinding: v.string(),
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
handler: async (ctx, args) => {
|
|
166
|
+
witnessControls.readQueries++;
|
|
167
|
+
const who = await ctx.auth.getUserIdentity();
|
|
168
|
+
if (
|
|
169
|
+
!who ||
|
|
170
|
+
!witnessControls.allowedReaders.includes(who.tokenIdentifier) ||
|
|
171
|
+
witnessControls.denyRead ||
|
|
172
|
+
!witnessControls.scope ||
|
|
173
|
+
!isDeepStrictEqual(args.identity, witnessControls.scope.identity)
|
|
174
|
+
)
|
|
175
|
+
return null;
|
|
176
|
+
const stored = await ctx.runQuery(
|
|
177
|
+
components.betterStripe.renewalWitnesses.queries.readAuthorizedWitness,
|
|
178
|
+
{ identity: args.identity },
|
|
179
|
+
);
|
|
180
|
+
if (!stored) return null;
|
|
181
|
+
const grant = {
|
|
182
|
+
capability: args.capability,
|
|
183
|
+
scope: structuredClone(witnessControls.scope),
|
|
184
|
+
tokenIdentifier: who.tokenIdentifier,
|
|
185
|
+
authorizationId: "test-witness-read",
|
|
186
|
+
authorizationRevision: 1,
|
|
187
|
+
expiresAtMs: witnessControls.expiresAtMs,
|
|
188
|
+
witnessRowId: stored.descriptor.witnessRowId,
|
|
189
|
+
payloadBinding: stored.descriptor.payloadBinding,
|
|
190
|
+
};
|
|
191
|
+
witnessControls.onReadGrant?.(grant, witnessControls.readQueries);
|
|
192
|
+
return grant;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
export async function prepareWitnessObservation(
|
|
197
|
+
h: Parameters<typeof prepareFreshObservation>[0],
|
|
198
|
+
retained = false,
|
|
199
|
+
withInvoices = false,
|
|
200
|
+
) {
|
|
201
|
+
witnessControls.retainQueries = 0;
|
|
202
|
+
witnessControls.readQueries = 0;
|
|
203
|
+
witnessControls.denyRetain = false;
|
|
204
|
+
witnessControls.denyRead = false;
|
|
205
|
+
witnessControls.allowedReaders.splice(
|
|
206
|
+
0,
|
|
207
|
+
witnessControls.allowedReaders.length,
|
|
208
|
+
observerIdentity.tokenIdentifier,
|
|
209
|
+
);
|
|
210
|
+
witnessControls.onRetainGrant = null;
|
|
211
|
+
witnessControls.onReadGrant = null;
|
|
212
|
+
const invoiceState = withInvoices
|
|
213
|
+
? await prepareInvoiceObservation(h, { retained })
|
|
214
|
+
: null;
|
|
215
|
+
const state =
|
|
216
|
+
invoiceState ??
|
|
217
|
+
(await prepareFreshObservation(h, { active: true, retained }));
|
|
218
|
+
const invoiceProfile = invoiceState?.invoiceProfile ?? null;
|
|
219
|
+
const record = JSON.parse(
|
|
220
|
+
state.full.configure.operation.recordJSON,
|
|
221
|
+
).configureRecord;
|
|
222
|
+
const scope: WitnessScope = {
|
|
223
|
+
identity: {
|
|
224
|
+
componentScope: state.entry.componentScope,
|
|
225
|
+
witnessId: "witness-fixed-native-period",
|
|
226
|
+
parentOperationId: state.parentOperationId,
|
|
227
|
+
operationId: state.operationId,
|
|
228
|
+
},
|
|
229
|
+
providerScope: {
|
|
230
|
+
mode: "platform",
|
|
231
|
+
stripeAccount: null,
|
|
232
|
+
livemode: false,
|
|
233
|
+
customerAccountId: "acct_buyer",
|
|
234
|
+
customerId: "cus_buyer",
|
|
235
|
+
subscriptionId: "sub_original",
|
|
236
|
+
scheduleId: "sub_sched_owned",
|
|
237
|
+
},
|
|
238
|
+
configureRequestBinding: record.request.requestIdentity.binding,
|
|
239
|
+
observedItemId: "si_successor",
|
|
240
|
+
nativePeriod: { start: 1771113600, end: 1771718400 },
|
|
241
|
+
};
|
|
242
|
+
witnessControls.scope = scope;
|
|
243
|
+
witnessControls.expiresAtMs = Date.now() + 60000;
|
|
244
|
+
const captureProfile = Object.freeze({
|
|
245
|
+
freshProfile: state.profile,
|
|
246
|
+
invoiceProfile,
|
|
247
|
+
authorizationQuery: makeFunctionReference<"query">(
|
|
248
|
+
"initialOwner:authorizeWitnessRetention",
|
|
249
|
+
),
|
|
250
|
+
});
|
|
251
|
+
const readProfile = Object.freeze({
|
|
252
|
+
freshProfile: state.profile,
|
|
253
|
+
invoiceProfile,
|
|
254
|
+
authorizationQuery: makeFunctionReference<"query">(
|
|
255
|
+
"initialOwner:authorizeWitnessRead",
|
|
256
|
+
),
|
|
257
|
+
});
|
|
258
|
+
witnessControls.captures.splice(
|
|
259
|
+
0,
|
|
260
|
+
witnessControls.captures.length,
|
|
261
|
+
captureProfile,
|
|
262
|
+
);
|
|
263
|
+
witnessControls.readers.splice(
|
|
264
|
+
0,
|
|
265
|
+
witnessControls.readers.length,
|
|
266
|
+
readProfile,
|
|
267
|
+
);
|
|
268
|
+
return {
|
|
269
|
+
...state,
|
|
270
|
+
scope,
|
|
271
|
+
captureProfile,
|
|
272
|
+
readProfile,
|
|
273
|
+
invoiceInventories: invoiceState?.inventories ?? null,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
type Harness = Parameters<typeof prepareWitnessObservation>[0];
|
|
278
|
+
type Prepared = Awaited<ReturnType<typeof prepareWitnessObservation>>;
|
|
279
|
+
type InvokeOptions = {
|
|
280
|
+
identity?: typeof observerIdentity;
|
|
281
|
+
before?: (ctx: GenericActionCtx<GenericDataModel>) => void;
|
|
282
|
+
};
|
|
283
|
+
export function witnessActorInput(
|
|
284
|
+
state: Prepared,
|
|
285
|
+
ctx: GenericActionCtx<GenericDataModel>,
|
|
286
|
+
) {
|
|
287
|
+
return {
|
|
288
|
+
actualActionCtx: ctx,
|
|
289
|
+
parentOperationId: state.parentOperationId,
|
|
290
|
+
operationId: state.operationId,
|
|
291
|
+
witnessId: state.scope.identity.witnessId,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
export async function invokeWitnessCapture(
|
|
295
|
+
h: Harness,
|
|
296
|
+
state: Prepared,
|
|
297
|
+
options: InvokeOptions = {},
|
|
298
|
+
) {
|
|
299
|
+
let output!: Awaited<
|
|
300
|
+
ReturnType<
|
|
301
|
+
Awaited<
|
|
302
|
+
ReturnType<typeof captureFreshWitnessRenewalObservation>
|
|
303
|
+
>["invoke"]
|
|
304
|
+
>
|
|
305
|
+
>;
|
|
306
|
+
await h.inAnotherAction(async (ctx) => {
|
|
307
|
+
options.before?.(ctx);
|
|
308
|
+
const actor = await captureFreshWitnessRenewalObservation(
|
|
309
|
+
h.sdk,
|
|
310
|
+
witnessActorInput(state, ctx),
|
|
311
|
+
);
|
|
312
|
+
output = await actor.invoke();
|
|
313
|
+
}, options.identity);
|
|
314
|
+
assert(output);
|
|
315
|
+
return output;
|
|
316
|
+
}
|
|
317
|
+
export async function invokeWitnessRead(
|
|
318
|
+
h: Harness,
|
|
319
|
+
state: Prepared,
|
|
320
|
+
options: InvokeOptions = {},
|
|
321
|
+
) {
|
|
322
|
+
let output!: Awaited<
|
|
323
|
+
ReturnType<
|
|
324
|
+
Awaited<
|
|
325
|
+
ReturnType<typeof captureHistoricalWitnessRenewalObservation>
|
|
326
|
+
>["invoke"]
|
|
327
|
+
>
|
|
328
|
+
>;
|
|
329
|
+
await h.inAnotherAction(async (ctx) => {
|
|
330
|
+
options.before?.(ctx);
|
|
331
|
+
const actor = await captureHistoricalWitnessRenewalObservation(
|
|
332
|
+
h.sdk,
|
|
333
|
+
witnessActorInput(state, ctx),
|
|
334
|
+
);
|
|
335
|
+
output = await actor.invoke();
|
|
336
|
+
}, options.identity);
|
|
337
|
+
assert(output);
|
|
338
|
+
return output;
|
|
339
|
+
}
|
|
340
|
+
export function readStoredWitness(h: Harness, state: Prepared) {
|
|
341
|
+
return h.ctx.runQuery(
|
|
342
|
+
components.betterStripe.renewalWitnesses.queries.readAuthorizedWitness,
|
|
343
|
+
{ identity: state.scope.identity },
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
export const witnessFixtureOptions = {
|
|
347
|
+
identity: observerIdentity,
|
|
348
|
+
hostQuery: authorizeWitnessObservation,
|
|
349
|
+
targetInterval: "week" as const,
|
|
350
|
+
hostWitnessRetainQuery: authorizeWitnessRetention,
|
|
351
|
+
hostWitnessReadQuery: authorizeWitnessRead,
|
|
352
|
+
hostInvoiceQuery: authorizeInvoices,
|
|
353
|
+
};
|
|
@@ -164,9 +164,21 @@ import type * as refundSync_mutations from "../refundSync/mutations.js";
|
|
|
164
164
|
import type * as refundSync_queries from "../refundSync/queries.js";
|
|
165
165
|
import type * as refundSync_routing from "../refundSync/routing.js";
|
|
166
166
|
import type * as refundSync_validators from "../refundSync/validators.js";
|
|
167
|
+
import type * as renewalOperations_attachValidation from "../renewalOperations/attachValidation.js";
|
|
168
|
+
import type * as renewalOperations_configureAcknowledgement from "../renewalOperations/configureAcknowledgement.js";
|
|
169
|
+
import type * as renewalOperations_configureParent from "../renewalOperations/configureParent.js";
|
|
170
|
+
import type * as renewalOperations_configureValidation from "../renewalOperations/configureValidation.js";
|
|
167
171
|
import type * as renewalOperations_helpers from "../renewalOperations/helpers.js";
|
|
168
172
|
import type * as renewalOperations_mutations from "../renewalOperations/mutations.js";
|
|
173
|
+
import type * as renewalOperations_operationContext from "../renewalOperations/operationContext.js";
|
|
169
174
|
import type * as renewalOperations_queries from "../renewalOperations/queries.js";
|
|
175
|
+
import type * as renewalOperations_stageAcknowledgement from "../renewalOperations/stageAcknowledgement.js";
|
|
176
|
+
import type * as renewalOperations_validationTypes from "../renewalOperations/validationTypes.js";
|
|
177
|
+
import type * as renewalWitnesses_eligibility from "../renewalWitnesses/eligibility.js";
|
|
178
|
+
import type * as renewalWitnesses_mutations from "../renewalWitnesses/mutations.js";
|
|
179
|
+
import type * as renewalWitnesses_protocol from "../renewalWitnesses/protocol.js";
|
|
180
|
+
import type * as renewalWitnesses_queries from "../renewalWitnesses/queries.js";
|
|
181
|
+
import type * as renewalWitnesses_source from "../renewalWitnesses/source.js";
|
|
170
182
|
import type * as reversalObservations_capture from "../reversalObservations/capture.js";
|
|
171
183
|
import type * as reversalObservations_indexSlice from "../reversalObservations/indexSlice.js";
|
|
172
184
|
import type * as reversalObservations_integrity from "../reversalObservations/integrity.js";
|
|
@@ -386,9 +398,21 @@ const fullApi: ApiFromModules<{
|
|
|
386
398
|
"refundSync/queries": typeof refundSync_queries;
|
|
387
399
|
"refundSync/routing": typeof refundSync_routing;
|
|
388
400
|
"refundSync/validators": typeof refundSync_validators;
|
|
401
|
+
"renewalOperations/attachValidation": typeof renewalOperations_attachValidation;
|
|
402
|
+
"renewalOperations/configureAcknowledgement": typeof renewalOperations_configureAcknowledgement;
|
|
403
|
+
"renewalOperations/configureParent": typeof renewalOperations_configureParent;
|
|
404
|
+
"renewalOperations/configureValidation": typeof renewalOperations_configureValidation;
|
|
389
405
|
"renewalOperations/helpers": typeof renewalOperations_helpers;
|
|
390
406
|
"renewalOperations/mutations": typeof renewalOperations_mutations;
|
|
407
|
+
"renewalOperations/operationContext": typeof renewalOperations_operationContext;
|
|
391
408
|
"renewalOperations/queries": typeof renewalOperations_queries;
|
|
409
|
+
"renewalOperations/stageAcknowledgement": typeof renewalOperations_stageAcknowledgement;
|
|
410
|
+
"renewalOperations/validationTypes": typeof renewalOperations_validationTypes;
|
|
411
|
+
"renewalWitnesses/eligibility": typeof renewalWitnesses_eligibility;
|
|
412
|
+
"renewalWitnesses/mutations": typeof renewalWitnesses_mutations;
|
|
413
|
+
"renewalWitnesses/protocol": typeof renewalWitnesses_protocol;
|
|
414
|
+
"renewalWitnesses/queries": typeof renewalWitnesses_queries;
|
|
415
|
+
"renewalWitnesses/source": typeof renewalWitnesses_source;
|
|
392
416
|
"reversalObservations/capture": typeof reversalObservations_capture;
|
|
393
417
|
"reversalObservations/indexSlice": typeof reversalObservations_indexSlice;
|
|
394
418
|
"reversalObservations/integrity": typeof reversalObservations_integrity;
|