@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,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;
|
|
@@ -8392,7 +8392,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8392
8392
|
recordJSON: string;
|
|
8393
8393
|
recordVersion: 2;
|
|
8394
8394
|
requestBinding: string;
|
|
8395
|
-
stage: "attach";
|
|
8395
|
+
stage: "attach" | "configure";
|
|
8396
8396
|
timingPolicyJSON: string;
|
|
8397
8397
|
};
|
|
8398
8398
|
},
|
|
@@ -8441,7 +8441,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8441
8441
|
recordJSON: string;
|
|
8442
8442
|
recordVersion: 2;
|
|
8443
8443
|
requestBinding: string;
|
|
8444
|
-
stage: "attach";
|
|
8444
|
+
stage: "attach" | "configure";
|
|
8445
8445
|
timingPolicyJSON: string;
|
|
8446
8446
|
};
|
|
8447
8447
|
sequence: 1 | 2 | 3;
|
|
@@ -8465,7 +8465,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8465
8465
|
basisJSON: string;
|
|
8466
8466
|
policyJSON: string;
|
|
8467
8467
|
sourcePayloadId: string;
|
|
8468
|
-
stage: "attach";
|
|
8468
|
+
stage: "attach" | "configure";
|
|
8469
8469
|
version: 1;
|
|
8470
8470
|
};
|
|
8471
8471
|
operationId: string;
|
|
@@ -8540,7 +8540,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8540
8540
|
recordJSON: string;
|
|
8541
8541
|
recordVersion: 2;
|
|
8542
8542
|
requestBinding: string;
|
|
8543
|
-
stage: "attach";
|
|
8543
|
+
stage: "attach" | "configure";
|
|
8544
8544
|
timingPolicyJSON: string;
|
|
8545
8545
|
};
|
|
8546
8546
|
}
|
|
@@ -8586,7 +8586,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8586
8586
|
recordJSON: string;
|
|
8587
8587
|
recordVersion: 2;
|
|
8588
8588
|
requestBinding: string;
|
|
8589
|
-
stage: "attach";
|
|
8589
|
+
stage: "attach" | "configure";
|
|
8590
8590
|
timingPolicyJSON: string;
|
|
8591
8591
|
};
|
|
8592
8592
|
}
|
|
@@ -8613,7 +8613,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8613
8613
|
responsePayloadId: string;
|
|
8614
8614
|
schemaVersion: 1;
|
|
8615
8615
|
sourcePayloadId: string;
|
|
8616
|
-
stage: "attach";
|
|
8616
|
+
stage: "attach" | "configure";
|
|
8617
8617
|
status: "retained";
|
|
8618
8618
|
},
|
|
8619
8619
|
Name
|
|
@@ -8651,7 +8651,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8651
8651
|
preparedRevision: 0;
|
|
8652
8652
|
recordVersion: 2;
|
|
8653
8653
|
requestBinding: string;
|
|
8654
|
-
stage: "attach";
|
|
8654
|
+
stage: "attach" | "configure";
|
|
8655
8655
|
timingPolicyJSON: string;
|
|
8656
8656
|
};
|
|
8657
8657
|
initialBasis: null | {
|
|
@@ -8659,7 +8659,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8659
8659
|
basisJSON: string;
|
|
8660
8660
|
policyJSON: string;
|
|
8661
8661
|
sourcePayloadId: string;
|
|
8662
|
-
stage: "attach";
|
|
8662
|
+
stage: "attach" | "configure";
|
|
8663
8663
|
version: 1;
|
|
8664
8664
|
};
|
|
8665
8665
|
operationId: string;
|
|
@@ -8747,7 +8747,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8747
8747
|
recordJSON: string;
|
|
8748
8748
|
recordVersion: 2;
|
|
8749
8749
|
requestBinding: string;
|
|
8750
|
-
stage: "attach";
|
|
8750
|
+
stage: "attach" | "configure";
|
|
8751
8751
|
timingPolicyJSON: string;
|
|
8752
8752
|
};
|
|
8753
8753
|
},
|
|
@@ -8770,7 +8770,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8770
8770
|
responsePayloadId: string;
|
|
8771
8771
|
schemaVersion: 1;
|
|
8772
8772
|
sourcePayloadId: string;
|
|
8773
|
-
stage: "attach";
|
|
8773
|
+
stage: "attach" | "configure";
|
|
8774
8774
|
status: "retained";
|
|
8775
8775
|
};
|
|
8776
8776
|
},
|
|
@@ -8795,6 +8795,94 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
8795
8795
|
>;
|
|
8796
8796
|
};
|
|
8797
8797
|
};
|
|
8798
|
+
renewalWitnesses: {
|
|
8799
|
+
mutations: {
|
|
8800
|
+
retainAuthorizedWitness: FunctionReference<
|
|
8801
|
+
"mutation",
|
|
8802
|
+
"internal",
|
|
8803
|
+
{
|
|
8804
|
+
identity: {
|
|
8805
|
+
componentScope: string;
|
|
8806
|
+
operationId: string;
|
|
8807
|
+
parentOperationId: string;
|
|
8808
|
+
witnessId: string;
|
|
8809
|
+
};
|
|
8810
|
+
payloadJSON: string;
|
|
8811
|
+
},
|
|
8812
|
+
| {
|
|
8813
|
+
descriptor: {
|
|
8814
|
+
authenticationEstablished: false;
|
|
8815
|
+
capturedSubject: string;
|
|
8816
|
+
customerAccountId: string;
|
|
8817
|
+
customerId: string;
|
|
8818
|
+
identity: {
|
|
8819
|
+
componentScope: string;
|
|
8820
|
+
operationId: string;
|
|
8821
|
+
parentOperationId: string;
|
|
8822
|
+
witnessId: string;
|
|
8823
|
+
};
|
|
8824
|
+
livemode: boolean;
|
|
8825
|
+
nativePeriod: { end: number; start: number };
|
|
8826
|
+
observedAtMs: number;
|
|
8827
|
+
observedItemId: string;
|
|
8828
|
+
operationalAuthority: false;
|
|
8829
|
+
payloadBinding: string;
|
|
8830
|
+
providerQualificationRequired: true;
|
|
8831
|
+
publicDeliveryEstablished: false;
|
|
8832
|
+
scheduleId: string;
|
|
8833
|
+
subscriptionId: string;
|
|
8834
|
+
version: 1;
|
|
8835
|
+
witnessRowId: string;
|
|
8836
|
+
};
|
|
8837
|
+
status: "retained";
|
|
8838
|
+
}
|
|
8839
|
+
| { reason: "identity_changed"; status: "conflict" },
|
|
8840
|
+
Name
|
|
8841
|
+
>;
|
|
8842
|
+
};
|
|
8843
|
+
queries: {
|
|
8844
|
+
readAuthorizedWitness: FunctionReference<
|
|
8845
|
+
"query",
|
|
8846
|
+
"internal",
|
|
8847
|
+
{
|
|
8848
|
+
identity: {
|
|
8849
|
+
componentScope: string;
|
|
8850
|
+
operationId: string;
|
|
8851
|
+
parentOperationId: string;
|
|
8852
|
+
witnessId: string;
|
|
8853
|
+
};
|
|
8854
|
+
},
|
|
8855
|
+
null | {
|
|
8856
|
+
descriptor: {
|
|
8857
|
+
authenticationEstablished: false;
|
|
8858
|
+
capturedSubject: string;
|
|
8859
|
+
customerAccountId: string;
|
|
8860
|
+
customerId: string;
|
|
8861
|
+
identity: {
|
|
8862
|
+
componentScope: string;
|
|
8863
|
+
operationId: string;
|
|
8864
|
+
parentOperationId: string;
|
|
8865
|
+
witnessId: string;
|
|
8866
|
+
};
|
|
8867
|
+
livemode: boolean;
|
|
8868
|
+
nativePeriod: { end: number; start: number };
|
|
8869
|
+
observedAtMs: number;
|
|
8870
|
+
observedItemId: string;
|
|
8871
|
+
operationalAuthority: false;
|
|
8872
|
+
payloadBinding: string;
|
|
8873
|
+
providerQualificationRequired: true;
|
|
8874
|
+
publicDeliveryEstablished: false;
|
|
8875
|
+
scheduleId: string;
|
|
8876
|
+
subscriptionId: string;
|
|
8877
|
+
version: 1;
|
|
8878
|
+
witnessRowId: string;
|
|
8879
|
+
};
|
|
8880
|
+
payloadJSON: string;
|
|
8881
|
+
},
|
|
8882
|
+
Name
|
|
8883
|
+
>;
|
|
8884
|
+
};
|
|
8885
|
+
};
|
|
8798
8886
|
reversalObservations: {
|
|
8799
8887
|
mutations: {
|
|
8800
8888
|
resume: FunctionReference<
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { descriptor, identity } from "./schema.js";
|
|
4
|
+
import { retainWitness } from "./protocol.js";
|
|
5
|
+
|
|
6
|
+
/** Trusted host component API. Host authorization and live capture remain separate requirements. */
|
|
7
|
+
export const retainAuthorizedWitness = mutation({
|
|
8
|
+
args: { identity, payloadJSON: v.string() },
|
|
9
|
+
returns: v.union(
|
|
10
|
+
v.object({ status: v.literal("retained"), descriptor }),
|
|
11
|
+
v.object({
|
|
12
|
+
status: v.literal("conflict"),
|
|
13
|
+
reason: v.literal("identity_changed"),
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
handler: retainWitness,
|
|
17
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { descriptor, identity } from "./schema.js";
|
|
4
|
+
import { readWitness } from "./protocol.js";
|
|
5
|
+
|
|
6
|
+
/** Trusted host component API. A fresh host read grant must precede any external release. */
|
|
7
|
+
export const readAuthorizedWitness = query({
|
|
8
|
+
args: { identity },
|
|
9
|
+
returns: v.union(v.null(), v.object({ descriptor, payloadJSON: v.string() })),
|
|
10
|
+
handler: (ctx, args) => readWitness(ctx, args.identity),
|
|
11
|
+
});
|