@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.
Files changed (134) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts +564 -0
  4. package/dist/client/billing/renewalAttach/internal/observation/freshActor.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js +103 -21
  6. package/dist/client/billing/renewalAttach/internal/observation/freshActor.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts +18 -1
  8. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js +54 -1
  10. package/dist/client/billing/renewalAttach/internal/observation/freshTransport.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts +4 -0
  12. package/dist/client/billing/renewalAttach/internal/observation/invocation.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/observation/invocation.js +1 -0
  14. package/dist/client/billing/renewalAttach/internal/observation/invocation.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts +4 -0
  16. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js +6 -1
  18. package/dist/client/billing/renewalAttach/internal/observation/readerAuthorization.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts +38 -0
  20. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js +172 -0
  22. package/dist/client/billing/renewalAttach/internal/observation/witnessAuthorization.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts +135 -0
  24. package/dist/client/billing/renewalAttach/internal/observation/witnessData.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/observation/witnessData.js +143 -0
  26. package/dist/client/billing/renewalAttach/internal/observation/witnessData.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts +85 -0
  28. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js +121 -0
  30. package/dist/client/billing/renewalAttach/internal/observation/witnessOperation.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts +44 -0
  32. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js +4 -0
  34. package/dist/client/billing/renewalAttach/internal/operations/witnessProfiles.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +1 -1
  36. package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +21 -21
  37. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +3 -3
  38. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
  39. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +84 -32
  40. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  41. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +26 -0
  42. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  43. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +84 -32
  44. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  45. package/dist/client/connect/payoutSyncTestHelpers.d.ts +26 -0
  46. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  47. package/dist/component/_generated/api.d.ts +24 -0
  48. package/dist/component/_generated/api.d.ts.map +1 -1
  49. package/dist/component/_generated/api.js.map +1 -1
  50. package/dist/component/_generated/component.d.ts +94 -10
  51. package/dist/component/_generated/component.d.ts.map +1 -1
  52. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  53. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  54. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  55. package/dist/component/balanceFunding/queries.d.ts +1 -1
  56. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  57. package/dist/component/earnings/triggers.d.ts +44 -0
  58. package/dist/component/earnings/triggers.d.ts.map +1 -1
  59. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  60. package/dist/component/renewalWitnesses/eligibility.d.ts +36 -0
  61. package/dist/component/renewalWitnesses/eligibility.d.ts.map +1 -0
  62. package/dist/component/renewalWitnesses/eligibility.js +60 -0
  63. package/dist/component/renewalWitnesses/eligibility.js.map +1 -0
  64. package/dist/component/renewalWitnesses/mutations.d.ts +45 -0
  65. package/dist/component/renewalWitnesses/mutations.d.ts.map +1 -0
  66. package/dist/component/renewalWitnesses/mutations.js +14 -0
  67. package/dist/component/renewalWitnesses/mutations.js.map +1 -0
  68. package/dist/component/renewalWitnesses/protocol.d.ts +75 -0
  69. package/dist/component/renewalWitnesses/protocol.d.ts.map +1 -0
  70. package/dist/component/renewalWitnesses/protocol.js +82 -0
  71. package/dist/component/renewalWitnesses/protocol.js.map +1 -0
  72. package/dist/component/renewalWitnesses/queries.d.ts +39 -0
  73. package/dist/component/renewalWitnesses/queries.d.ts.map +1 -0
  74. package/dist/component/renewalWitnesses/queries.js +11 -0
  75. package/dist/component/renewalWitnesses/queries.js.map +1 -0
  76. package/dist/component/renewalWitnesses/schema.d.ts +99 -0
  77. package/dist/component/renewalWitnesses/schema.d.ts.map +1 -0
  78. package/dist/component/renewalWitnesses/schema.js +36 -0
  79. package/dist/component/renewalWitnesses/schema.js.map +1 -0
  80. package/dist/component/renewalWitnesses/source.d.ts +22 -0
  81. package/dist/component/renewalWitnesses/source.d.ts.map +1 -0
  82. package/dist/component/renewalWitnesses/source.js +108 -0
  83. package/dist/component/renewalWitnesses/source.js.map +1 -0
  84. package/dist/component/schema.d.ts +42 -16
  85. package/dist/component/schema.js +2 -0
  86. package/dist/component/schema.js.map +1 -1
  87. package/dist/component/usage/allowance.fixtures.d.ts +42 -16
  88. package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
  89. package/dist/component/usageCredits/accounting.fixtures.d.ts +26 -0
  90. package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
  91. package/dist/shared/renewalWitness.d.ts +51 -0
  92. package/dist/shared/renewalWitness.d.ts.map +1 -0
  93. package/dist/shared/renewalWitness.js +127 -0
  94. package/dist/shared/renewalWitness.js.map +1 -0
  95. package/docs/renewal-witness-protocol.md +139 -0
  96. package/package.json +1 -1
  97. package/src/client/billing/renewalAttach/internal/observation/freshActor.ts +142 -19
  98. package/src/client/billing/renewalAttach/internal/observation/freshTransport.ts +90 -1
  99. package/src/client/billing/renewalAttach/internal/observation/invocation.ts +2 -0
  100. package/src/client/billing/renewalAttach/internal/observation/readerAuthorization.ts +6 -1
  101. package/src/client/billing/renewalAttach/internal/observation/witnessAcquisition.integration.test.ts +348 -0
  102. package/src/client/billing/renewalAttach/internal/observation/witnessActor.integration.test.ts +204 -0
  103. package/src/client/billing/renewalAttach/internal/observation/witnessAuthorization.ts +239 -0
  104. package/src/client/billing/renewalAttach/internal/observation/witnessCapabilities.integration.test.ts +231 -0
  105. package/src/client/billing/renewalAttach/internal/observation/witnessData.ts +189 -0
  106. package/src/client/billing/renewalAttach/internal/observation/witnessHistorical.integration.test.ts +98 -0
  107. package/src/client/billing/renewalAttach/internal/observation/witnessImmutable.integration.test.ts +78 -0
  108. package/src/client/billing/renewalAttach/internal/observation/witnessInvoice.integration.test.ts +85 -0
  109. package/src/client/billing/renewalAttach/internal/observation/witnessLifecycle.integration.test.ts +264 -0
  110. package/src/client/billing/renewalAttach/internal/observation/witnessOperation.ts +205 -0
  111. package/src/client/billing/renewalAttach/internal/observation/witnessProfile.integration.test.ts +93 -0
  112. package/src/client/billing/renewalAttach/internal/observation/witnessRPCControls.integration.test.ts +256 -0
  113. package/src/client/billing/renewalAttach/internal/operations/witnessProfiles.ts +58 -0
  114. package/src/client/billing/renewalAttach/internal/test-fixtures/invoiceObservation.ts +3 -1
  115. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +8 -0
  116. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +18 -7
  117. package/src/client/billing/renewalAttach/internal/test-fixtures/witnessHistory.ts +70 -0
  118. package/src/client/billing/renewalAttach/internal/test-fixtures/witnessObservation.ts +353 -0
  119. package/src/component/_generated/api.ts +24 -0
  120. package/src/component/_generated/component.ts +98 -10
  121. package/src/component/renewalOperations/configureJournal.fixtures.ts +25 -3
  122. package/src/component/renewalWitnesses/bounds.test.ts +204 -0
  123. package/src/component/renewalWitnesses/codec.test.ts +84 -0
  124. package/src/component/renewalWitnesses/controls.test.ts +250 -0
  125. package/src/component/renewalWitnesses/eligibility.ts +78 -0
  126. package/src/component/renewalWitnesses/mutations.ts +17 -0
  127. package/src/component/renewalWitnesses/protocol.test.ts +63 -0
  128. package/src/component/renewalWitnesses/protocol.ts +103 -0
  129. package/src/component/renewalWitnesses/queries.ts +11 -0
  130. package/src/component/renewalWitnesses/routes.test.ts +154 -0
  131. package/src/component/renewalWitnesses/schema.ts +36 -0
  132. package/src/component/renewalWitnesses/source.ts +157 -0
  133. package/src/component/schema.ts +2 -0
  134. package/src/shared/renewalWitness.ts +179 -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<
@@ -25,13 +25,32 @@ export function sevenConfigure(request: {
25
25
  return { scope, apiVersion, method, path, payload, key, firstDispatchedAt };
26
26
  }
27
27
  /** Complete synthetic constructor DATA only, without an Owner or provider call. */
28
- export async function configureJournalFixture() {
28
+ export async function configureJournalFixture(
29
+ options: { targetInterval?: "week"; sourcePadding?: string } = {},
30
+ ) {
29
31
  let fetches = 0;
30
32
  vi.stubGlobal("fetch", () => {
31
33
  fetches++;
32
34
  throw Error("UNEXPECTED_PROVIDER_CALL");
33
35
  });
34
36
  const baseline = makeConfigureReadNativeBaseline();
37
+ if (options.sourcePadding !== undefined)
38
+ Object.assign(baseline.original.originalBundle, {
39
+ witnessPadding: options.sourcePadding,
40
+ });
41
+ if (options.targetInterval) {
42
+ const prep = baseline.original.attachRequest.preparation;
43
+ Object.assign(prep.targetPrice.recurring, {
44
+ interval: options.targetInterval,
45
+ });
46
+ Object.assign(prep.subscription, { trial_start: null, trial_end: null });
47
+ baseline.original.originalBundle.wireTargetPrice = structuredClone(
48
+ prep.targetPrice,
49
+ );
50
+ baseline.original.originalBundle.wireSubscription = structuredClone(
51
+ prep.subscription,
52
+ );
53
+ }
35
54
  const attachRequest = structuredClone(baseline.original.attachRequest);
36
55
  const prepared = await c1(attachRequest.preparation);
37
56
  const attach = await c2({
@@ -126,8 +145,11 @@ export async function configureJournalFixture() {
126
145
  };
127
146
  }
128
147
 
129
- export async function configureComponentFixture(publishParent = true) {
130
- const h = await configureJournalFixture();
148
+ export async function configureComponentFixture(
149
+ publishParent = true,
150
+ options: { targetInterval?: "week"; sourcePadding?: string } = {},
151
+ ) {
152
+ const h = await configureJournalFixture(options);
131
153
  const { convexTest } = await import("convex-test");
132
154
  const { schema, modules } = await import("../../test.js");
133
155
  const { makeFunctionReference } = await import("convex/server");