@fantastic.dev/better-stripe 0.92.0 → 0.93.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/producer/classOwnedActionRoot.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +113 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +594 -32
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +594 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +16 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +6 -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 +406 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +294 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/renewalOperations/helpers.d.ts +236 -0
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -0
- package/dist/component/renewalOperations/helpers.js +457 -0
- package/dist/component/renewalOperations/helpers.js.map +1 -0
- package/dist/component/renewalOperations/mutations.d.ts +252 -0
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -0
- package/dist/component/renewalOperations/mutations.js +340 -0
- package/dist/component/renewalOperations/mutations.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +163 -0
- package/dist/component/renewalOperations/queries.d.ts.map +1 -0
- package/dist/component/renewalOperations/queries.js +167 -0
- package/dist/component/renewalOperations/queries.js.map +1 -0
- package/dist/component/renewalOperations/schema.d.ts +1988 -0
- package/dist/component/renewalOperations/schema.d.ts.map +1 -0
- package/dist/component/renewalOperations/schema.js +227 -0
- package/dist/component/renewalOperations/schema.js.map +1 -0
- package/dist/component/schema.d.ts +281 -0
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +281 -0
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +297 -16
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.d.ts +43 -0
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -0
- package/dist/shared/renewalOperationJournal.js +294 -0
- package/dist/shared/renewalOperationJournal.js.map +1 -0
- package/docs/renewal-context-reads.md +152 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +380 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +155 -0
- package/src/client/index.ts +24 -3
- package/src/component/_generated/api.ts +6 -0
- package/src/component/_generated/component.ts +450 -0
- package/src/component/renewalOperations/acknowledgement.fixtures.ts +552 -0
- package/src/component/renewalOperations/acknowledgement.test.ts +573 -0
- package/src/component/renewalOperations/acknowledgementReads.test.ts +442 -0
- package/src/component/renewalOperations/acknowledgementV2.test.ts +493 -0
- package/src/component/renewalOperations/acknowledgementV2Publication.test.ts +373 -0
- package/src/component/renewalOperations/basisBinding.test.ts +567 -0
- package/src/component/renewalOperations/basisLifecycle.test.ts +569 -0
- package/src/component/renewalOperations/boundHistory.test.ts +474 -0
- package/src/component/renewalOperations/helpers.ts +592 -0
- package/src/component/renewalOperations/historyReads.test.ts +595 -0
- package/src/component/renewalOperations/initialBasis.test.ts +578 -0
- package/src/component/renewalOperations/journal.test.ts +567 -0
- package/src/component/renewalOperations/mutations.ts +456 -0
- package/src/component/renewalOperations/payload.test.ts +589 -0
- package/src/component/renewalOperations/payloadEncoding.test.ts +592 -0
- package/src/component/renewalOperations/queries.ts +204 -0
- package/src/component/renewalOperations/schema.ts +268 -0
- package/src/component/renewalOperations/timingPolicy.fixtures.ts +193 -0
- package/src/component/renewalOperations/timingPolicy.test.ts +523 -0
- package/src/component/schema.ts +11 -0
- package/src/shared/renewalOperationJournal.ts +333 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { convexTest } from "convex-test";
|
|
2
|
+
import {
|
|
3
|
+
actionGeneric,
|
|
4
|
+
mutationGeneric,
|
|
5
|
+
componentsGeneric,
|
|
6
|
+
defineSchema,
|
|
7
|
+
makeFunctionReference,
|
|
8
|
+
} from "convex/server";
|
|
9
|
+
import { getConvexSize, getDocumentSize, type ObjectType } from "convex/values";
|
|
10
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
11
|
+
import { modules, schema } from "../../../../test.js";
|
|
12
|
+
import { query as componentQuery } from "../../../../component/_generated/server.js";
|
|
13
|
+
import type { Doc } from "../../../../component/_generated/dataModel.js";
|
|
14
|
+
import {
|
|
15
|
+
creationArgs,
|
|
16
|
+
reserveArgs,
|
|
17
|
+
} from "../../../../component/renewalOperations/schema.js";
|
|
18
|
+
import {
|
|
19
|
+
canonical,
|
|
20
|
+
codecFixture,
|
|
21
|
+
VALUE_LIMIT,
|
|
22
|
+
} from "../../../../component/renewalOperations/timingPolicy.fixtures.js";
|
|
23
|
+
|
|
24
|
+
// TEST-only mounted references; never a production ComponentApi substitute.
|
|
25
|
+
const nested = componentsGeneric();
|
|
26
|
+
const createAction = makeFunctionReference<
|
|
27
|
+
"action",
|
|
28
|
+
ObjectType<typeof creationArgs>,
|
|
29
|
+
null
|
|
30
|
+
>("host:createAction");
|
|
31
|
+
const createMutation = makeFunctionReference<
|
|
32
|
+
"mutation",
|
|
33
|
+
ObjectType<typeof creationArgs>,
|
|
34
|
+
null
|
|
35
|
+
>("host:createMutation");
|
|
36
|
+
const reserveAction = makeFunctionReference<
|
|
37
|
+
"action",
|
|
38
|
+
ObjectType<typeof reserveArgs>,
|
|
39
|
+
null
|
|
40
|
+
>("host:reserveAction");
|
|
41
|
+
const reserveMutation = makeFunctionReference<
|
|
42
|
+
"mutation",
|
|
43
|
+
ObjectType<typeof reserveArgs>,
|
|
44
|
+
null
|
|
45
|
+
>("host:reserveMutation");
|
|
46
|
+
const cases = [
|
|
47
|
+
{ phase: "create", parent: "action", route: "host:createAction" },
|
|
48
|
+
{ phase: "create", parent: "mutation", route: "host:createMutation" },
|
|
49
|
+
{ phase: "reserve", parent: "action", route: "host:reserveAction" },
|
|
50
|
+
{ phase: "reserve", parent: "mutation", route: "host:reserveMutation" },
|
|
51
|
+
] as const;
|
|
52
|
+
type Physical = {
|
|
53
|
+
operations: Doc<"renewalOperations">[];
|
|
54
|
+
attempts: Doc<"renewalOperationAttempts">[];
|
|
55
|
+
events: Doc<"renewalOperationEvents">[];
|
|
56
|
+
payloads: Doc<"renewalOperationPayloads">[];
|
|
57
|
+
};
|
|
58
|
+
type Trace = { route: string; metadata: unknown; reply: unknown };
|
|
59
|
+
const parentStop = "JOURNAL_MECHANICAL_PARENT_STOP";
|
|
60
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
61
|
+
|
|
62
|
+
it.each(cases)(
|
|
63
|
+
"ACTION-MECHANICAL $phase under $parent has the declared transaction boundary",
|
|
64
|
+
async (scenario) => {
|
|
65
|
+
const h = await codecFixture();
|
|
66
|
+
const trace: Trace[] = [];
|
|
67
|
+
const host = {
|
|
68
|
+
createAction: actionGeneric({
|
|
69
|
+
args: creationArgs,
|
|
70
|
+
handler: async (ctx, args) => {
|
|
71
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
72
|
+
expect(metadata).toEqual({
|
|
73
|
+
name: "host:createAction",
|
|
74
|
+
componentPath: "",
|
|
75
|
+
type: "action",
|
|
76
|
+
visibility: "public",
|
|
77
|
+
});
|
|
78
|
+
const reply: unknown = await ctx.runMutation(
|
|
79
|
+
nested.betterStripe.renewalOperations.mutations
|
|
80
|
+
.createAuthorizedOperation,
|
|
81
|
+
args,
|
|
82
|
+
);
|
|
83
|
+
expect(reply).toMatchObject({ status: "created" });
|
|
84
|
+
trace.push({ route: "host:createAction", metadata, reply });
|
|
85
|
+
throw Error(parentStop);
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
createMutation: mutationGeneric({
|
|
89
|
+
args: creationArgs,
|
|
90
|
+
handler: async (ctx, args) => {
|
|
91
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
92
|
+
expect(metadata).toEqual({
|
|
93
|
+
name: "host:createMutation",
|
|
94
|
+
componentPath: "",
|
|
95
|
+
type: "mutation",
|
|
96
|
+
visibility: "public",
|
|
97
|
+
});
|
|
98
|
+
const reply: unknown = await ctx.runMutation(
|
|
99
|
+
nested.betterStripe.renewalOperations.mutations
|
|
100
|
+
.createAuthorizedOperation,
|
|
101
|
+
args,
|
|
102
|
+
);
|
|
103
|
+
expect(reply).toMatchObject({ status: "created" });
|
|
104
|
+
trace.push({ route: "host:createMutation", metadata, reply });
|
|
105
|
+
throw Error(parentStop);
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
reserveAction: actionGeneric({
|
|
109
|
+
args: reserveArgs,
|
|
110
|
+
handler: async (ctx, args) => {
|
|
111
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
112
|
+
expect(metadata).toEqual({
|
|
113
|
+
name: "host:reserveAction",
|
|
114
|
+
componentPath: "",
|
|
115
|
+
type: "action",
|
|
116
|
+
visibility: "public",
|
|
117
|
+
});
|
|
118
|
+
const reply: unknown = await ctx.runMutation(
|
|
119
|
+
nested.betterStripe.renewalOperations.mutations.reserveAttempt,
|
|
120
|
+
args,
|
|
121
|
+
);
|
|
122
|
+
expect(reply).toMatchObject({
|
|
123
|
+
disposition: "acquired",
|
|
124
|
+
previousRevision: 0,
|
|
125
|
+
committedRevision: 1,
|
|
126
|
+
});
|
|
127
|
+
trace.push({ route: "host:reserveAction", metadata, reply });
|
|
128
|
+
throw Error(parentStop);
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
reserveMutation: mutationGeneric({
|
|
132
|
+
args: reserveArgs,
|
|
133
|
+
handler: async (ctx, args) => {
|
|
134
|
+
const metadata = await ctx.meta.getFunctionMetadata();
|
|
135
|
+
expect(metadata).toEqual({
|
|
136
|
+
name: "host:reserveMutation",
|
|
137
|
+
componentPath: "",
|
|
138
|
+
type: "mutation",
|
|
139
|
+
visibility: "public",
|
|
140
|
+
});
|
|
141
|
+
const reply: unknown = await ctx.runMutation(
|
|
142
|
+
nested.betterStripe.renewalOperations.mutations.reserveAttempt,
|
|
143
|
+
args,
|
|
144
|
+
);
|
|
145
|
+
expect(reply).toMatchObject({
|
|
146
|
+
disposition: "acquired",
|
|
147
|
+
previousRevision: 0,
|
|
148
|
+
committedRevision: 1,
|
|
149
|
+
});
|
|
150
|
+
trace.push({ route: "host:reserveMutation", metadata, reply });
|
|
151
|
+
throw Error(parentStop);
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
const inspection = {
|
|
156
|
+
physical: componentQuery({
|
|
157
|
+
args: {},
|
|
158
|
+
handler: async (ctx): Promise<Physical> => ({
|
|
159
|
+
operations: await ctx.db.query("renewalOperations").take(3),
|
|
160
|
+
attempts: await ctx.db.query("renewalOperationAttempts").take(3),
|
|
161
|
+
events: await ctx.db.query("renewalOperationEvents").take(4),
|
|
162
|
+
payloads: await ctx.db.query("renewalOperationPayloads").take(6),
|
|
163
|
+
}),
|
|
164
|
+
}),
|
|
165
|
+
};
|
|
166
|
+
// The empty host API module is only convex-test's module-root sentinel.
|
|
167
|
+
// No generated file or journal function reference is fabricated by it.
|
|
168
|
+
const t = convexTest(defineSchema({}), {
|
|
169
|
+
"./_generated/api.ts": async () => ({}),
|
|
170
|
+
"./host.ts": async () => host,
|
|
171
|
+
});
|
|
172
|
+
expect(
|
|
173
|
+
Object.prototype.hasOwnProperty.call(
|
|
174
|
+
modules,
|
|
175
|
+
"./component/journalMechanical.ts",
|
|
176
|
+
),
|
|
177
|
+
).toBe(false);
|
|
178
|
+
t.registerComponent("betterStripe", schema, {
|
|
179
|
+
...modules,
|
|
180
|
+
"./component/journalMechanical.ts": async () => inspection,
|
|
181
|
+
});
|
|
182
|
+
const physical = async (): Promise<Physical> =>
|
|
183
|
+
t.query(nested.betterStripe.journalMechanical.physical, {});
|
|
184
|
+
expect(await physical()).toEqual({
|
|
185
|
+
operations: [],
|
|
186
|
+
attempts: [],
|
|
187
|
+
events: [],
|
|
188
|
+
payloads: [],
|
|
189
|
+
});
|
|
190
|
+
const createArgs: ObjectType<typeof creationArgs> = {
|
|
191
|
+
authorizationScope: h.record.authorization.scope,
|
|
192
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
193
|
+
authorizationRevision: h.record.authorization.revision,
|
|
194
|
+
recordJSON: h.recordJSON,
|
|
195
|
+
};
|
|
196
|
+
expect(getConvexSize(createArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
197
|
+
if (scenario.phase === "reserve") {
|
|
198
|
+
const created: unknown = await t.mutation(
|
|
199
|
+
nested.betterStripe.renewalOperations.mutations
|
|
200
|
+
.createAuthorizedOperation,
|
|
201
|
+
createArgs,
|
|
202
|
+
);
|
|
203
|
+
const prepared = await physical();
|
|
204
|
+
expect(prepared.operations).toHaveLength(1);
|
|
205
|
+
expect(prepared.payloads).toHaveLength(1);
|
|
206
|
+
expect(prepared.attempts).toHaveLength(0);
|
|
207
|
+
expect(prepared.events).toHaveLength(0);
|
|
208
|
+
const operationId = prepared.operations[0]._id;
|
|
209
|
+
expect(created).toEqual({ status: "created", operationId });
|
|
210
|
+
expect(
|
|
211
|
+
await t.query(
|
|
212
|
+
nested.betterStripe.renewalOperations.queries.loadAuthorizedOperation,
|
|
213
|
+
{ operationId },
|
|
214
|
+
),
|
|
215
|
+
).toEqual({
|
|
216
|
+
recordVersion: 2,
|
|
217
|
+
operationId,
|
|
218
|
+
recordJSON: h.recordJSON,
|
|
219
|
+
revision: 0,
|
|
220
|
+
activeAttempt: null,
|
|
221
|
+
initialBasis: null,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
const before = await physical();
|
|
225
|
+
const operation = before.operations[0];
|
|
226
|
+
let targetFailed = false;
|
|
227
|
+
let stable = before;
|
|
228
|
+
try {
|
|
229
|
+
if (scenario.phase === "create") {
|
|
230
|
+
const operationPromise =
|
|
231
|
+
scenario.parent === "action"
|
|
232
|
+
? t.action(createAction, createArgs)
|
|
233
|
+
: t.mutation(createMutation, createArgs);
|
|
234
|
+
await expect(operationPromise).rejects.toThrow(
|
|
235
|
+
new RegExp("^" + parentStop + "$"),
|
|
236
|
+
);
|
|
237
|
+
} else {
|
|
238
|
+
const args: ObjectType<typeof reserveArgs> = {
|
|
239
|
+
operationId: operation._id,
|
|
240
|
+
expectedRevision: 0,
|
|
241
|
+
stage: "attach",
|
|
242
|
+
expectedRequestBinding: h.record.requestBinding,
|
|
243
|
+
recordJSON: h.recordJSON,
|
|
244
|
+
};
|
|
245
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
246
|
+
const operationPromise =
|
|
247
|
+
scenario.parent === "action"
|
|
248
|
+
? t.action(reserveAction, args)
|
|
249
|
+
: t.mutation(reserveMutation, args);
|
|
250
|
+
await expect(operationPromise).rejects.toThrow(
|
|
251
|
+
new RegExp("^" + parentStop + "$"),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
expect(trace).toHaveLength(1);
|
|
255
|
+
expect(trace[0].route).toBe(scenario.route);
|
|
256
|
+
const after = await physical();
|
|
257
|
+
stable = after;
|
|
258
|
+
if (scenario.parent === "mutation") {
|
|
259
|
+
expect(after).toEqual(before);
|
|
260
|
+
} else if (scenario.phase === "create") {
|
|
261
|
+
expect({
|
|
262
|
+
operations: after.operations.length,
|
|
263
|
+
attempts: after.attempts.length,
|
|
264
|
+
events: after.events.length,
|
|
265
|
+
payloads: after.payloads.length,
|
|
266
|
+
}).toEqual({ operations: 1, attempts: 0, events: 0, payloads: 1 });
|
|
267
|
+
const row = after.operations[0];
|
|
268
|
+
const payload = after.payloads[0];
|
|
269
|
+
expect(row).toEqual({
|
|
270
|
+
_id: row._id,
|
|
271
|
+
_creationTime: row._creationTime,
|
|
272
|
+
recordVersion: 2,
|
|
273
|
+
authorizationScope: h.record.authorization.scope,
|
|
274
|
+
authorizationId: h.record.authorization.id,
|
|
275
|
+
authorizationRevision: h.record.authorization.revision,
|
|
276
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
277
|
+
requestBinding: h.record.requestBinding,
|
|
278
|
+
payloadId: payload._id,
|
|
279
|
+
revision: 0,
|
|
280
|
+
state: "PREPARED",
|
|
281
|
+
});
|
|
282
|
+
expect(payload).toEqual({
|
|
283
|
+
_id: payload._id,
|
|
284
|
+
_creationTime: payload._creationTime,
|
|
285
|
+
codecVersion: 1,
|
|
286
|
+
json: h.recordJSON,
|
|
287
|
+
owner: { kind: "operation", operationId: row._id },
|
|
288
|
+
});
|
|
289
|
+
expect(trace[0].reply).toEqual({
|
|
290
|
+
status: "created",
|
|
291
|
+
operationId: row._id,
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
expect({
|
|
295
|
+
operations: after.operations.length,
|
|
296
|
+
attempts: after.attempts.length,
|
|
297
|
+
events: after.events.length,
|
|
298
|
+
payloads: after.payloads.length,
|
|
299
|
+
}).toEqual({ operations: 1, attempts: 1, events: 0, payloads: 1 });
|
|
300
|
+
const attempt = after.attempts[0];
|
|
301
|
+
expect(after.operations).toEqual([
|
|
302
|
+
{
|
|
303
|
+
...operation,
|
|
304
|
+
revision: 1,
|
|
305
|
+
state: "RESERVED",
|
|
306
|
+
activeAttemptId: attempt._id,
|
|
307
|
+
},
|
|
308
|
+
]);
|
|
309
|
+
expect(after.payloads).toEqual(before.payloads);
|
|
310
|
+
expect(after.events).toEqual(before.events);
|
|
311
|
+
expect(attempt).toEqual({
|
|
312
|
+
_id: attempt._id,
|
|
313
|
+
_creationTime: attempt._creationTime,
|
|
314
|
+
operationId: operation._id,
|
|
315
|
+
payloadId: operation.payloadId,
|
|
316
|
+
recordVersion: 2,
|
|
317
|
+
stage: "attach",
|
|
318
|
+
authorizationScope: h.record.authorization.scope,
|
|
319
|
+
authorizationId: h.record.authorization.id,
|
|
320
|
+
authorizationRevision: h.record.authorization.revision,
|
|
321
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
322
|
+
requestBinding: h.record.requestBinding,
|
|
323
|
+
key: h.request.key,
|
|
324
|
+
apiVersion: h.request.apiVersion,
|
|
325
|
+
accountJSON: canonical(h.record.account),
|
|
326
|
+
timingPolicyJSON: canonical(h.record.timingPolicy),
|
|
327
|
+
firstDispatchedAt: h.request.firstDispatchedAt,
|
|
328
|
+
ordinal: 1,
|
|
329
|
+
preparedRevision: 0,
|
|
330
|
+
committedRevision: 1,
|
|
331
|
+
lastSequence: 0,
|
|
332
|
+
});
|
|
333
|
+
const { _id, _creationTime, lastSequence, ...fields } = attempt;
|
|
334
|
+
void _creationTime;
|
|
335
|
+
void lastSequence;
|
|
336
|
+
expect(trace[0].reply).toEqual({
|
|
337
|
+
disposition: "acquired",
|
|
338
|
+
previousRevision: 0,
|
|
339
|
+
committedRevision: 1,
|
|
340
|
+
reservation: { ...fields, attemptId: _id, recordJSON: h.recordJSON },
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
for (const rows of Object.values(after))
|
|
344
|
+
for (const row of rows) {
|
|
345
|
+
expect(Number.isFinite(row._creationTime)).toBe(true);
|
|
346
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
347
|
+
}
|
|
348
|
+
expect(getConvexSize(after)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
349
|
+
expect(canonical(h.record)).toBe(h.recordJSON);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
targetFailed = true;
|
|
352
|
+
throw error;
|
|
353
|
+
} finally {
|
|
354
|
+
try {
|
|
355
|
+
const after = await physical();
|
|
356
|
+
console.info(
|
|
357
|
+
"JOURNAL_ACTION_MECHANICAL_SETTLEMENT",
|
|
358
|
+
JSON.stringify({
|
|
359
|
+
phase: scenario.phase,
|
|
360
|
+
parent: scenario.parent,
|
|
361
|
+
childFulfillments: trace.length,
|
|
362
|
+
physicalEqual: JSON.stringify(after) === JSON.stringify(stable),
|
|
363
|
+
counts: {
|
|
364
|
+
operations: after.operations.length,
|
|
365
|
+
attempts: after.attempts.length,
|
|
366
|
+
events: after.events.length,
|
|
367
|
+
payloads: after.payloads.length,
|
|
368
|
+
},
|
|
369
|
+
fetchCalls: h.fetchCalls(),
|
|
370
|
+
}),
|
|
371
|
+
);
|
|
372
|
+
expect(after).toEqual(stable);
|
|
373
|
+
expect(h.fetchCalls()).toBe(0);
|
|
374
|
+
} catch (inspectionError) {
|
|
375
|
+
if (!targetFailed) throw inspectionError;
|
|
376
|
+
console.info("JOURNAL_ACTION_MECHANICAL_INSPECTION_FAILED");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { GenericActionCtx, GenericDataModel } from "convex/server";
|
|
2
|
+
import type { Id } from "../../../../../component/_generated/dataModel.js";
|
|
3
|
+
import type { Component } from "../../../../helpers.js";
|
|
4
|
+
import { RenewalContextClient } from "../../../../renewalContextClient.js";
|
|
5
|
+
|
|
6
|
+
export type ClassActionInput = Readonly<{
|
|
7
|
+
actualActionCtx: GenericActionCtx<GenericDataModel>;
|
|
8
|
+
operationId: Id<"renewalOperations">;
|
|
9
|
+
}>;
|
|
10
|
+
type Bootstrap = Readonly<{
|
|
11
|
+
prototype: object;
|
|
12
|
+
select: () => unknown;
|
|
13
|
+
enter: (input: ClassActionInput) => unknown;
|
|
14
|
+
}>;
|
|
15
|
+
type RootCell =
|
|
16
|
+
| Readonly<{ phase: "awaiting"; component: Component }>
|
|
17
|
+
| Readonly<{ phase: "ready"; component: Component; bootstrap: Bootstrap }>
|
|
18
|
+
| Readonly<{ phase: "failed" }>;
|
|
19
|
+
const roots = new WeakMap<object, RootCell>();
|
|
20
|
+
const pending = new WeakMap<object, Bootstrap>();
|
|
21
|
+
const finishing = new WeakSet<object>();
|
|
22
|
+
const bootstrapSymbol = Symbol("betterstripe-class-root-bootstrap");
|
|
23
|
+
export const CLASS_ROOT_CONSTRUCTION_PERMIT = Symbol(
|
|
24
|
+
"betterstripe-root-permit",
|
|
25
|
+
);
|
|
26
|
+
function rootUnbound(): never {
|
|
27
|
+
throw Error("CLASS_ACTION_ROOT_UNBOUND");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Internal neutral base; construction alone grants no operational authority. */
|
|
31
|
+
export abstract class ClassOwnedActionRoot extends RenewalContextClient {
|
|
32
|
+
protected constructor(
|
|
33
|
+
component: Component,
|
|
34
|
+
permit: typeof CLASS_ROOT_CONSTRUCTION_PERMIT,
|
|
35
|
+
) {
|
|
36
|
+
if (permit !== CLASS_ROOT_CONSTRUCTION_PERMIT) rootUnbound();
|
|
37
|
+
super(component);
|
|
38
|
+
roots.set(this, Object.freeze({ phase: "awaiting", component }));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected finishMaintainedRootConstruction(): void {
|
|
42
|
+
const cell = roots.get(this);
|
|
43
|
+
const bootstrap = pending.get(this);
|
|
44
|
+
const descriptor = Object.getOwnPropertyDescriptor(this, bootstrapSymbol);
|
|
45
|
+
if (
|
|
46
|
+
!cell ||
|
|
47
|
+
cell.phase !== "awaiting" ||
|
|
48
|
+
!finishing.has(this) ||
|
|
49
|
+
!bootstrap ||
|
|
50
|
+
!descriptor ||
|
|
51
|
+
!("value" in descriptor) ||
|
|
52
|
+
descriptor.value !== bootstrap ||
|
|
53
|
+
descriptor.enumerable ||
|
|
54
|
+
descriptor.writable ||
|
|
55
|
+
!descriptor.configurable
|
|
56
|
+
)
|
|
57
|
+
rootUnbound();
|
|
58
|
+
roots.set(
|
|
59
|
+
this,
|
|
60
|
+
Object.freeze({ phase: "ready", component: cell.component, bootstrap }),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const finalizerCandidate: unknown = Object.getOwnPropertyDescriptor(
|
|
65
|
+
ClassOwnedActionRoot.prototype,
|
|
66
|
+
"finishMaintainedRootConstruction",
|
|
67
|
+
)?.value;
|
|
68
|
+
if (typeof finalizerCandidate !== "function") rootUnbound();
|
|
69
|
+
const actualFinalizer = finalizerCandidate;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Called by the maintained constructor under trusted package-internal imports.
|
|
73
|
+
* Hostile code importing the private base and permit is outside this gate.
|
|
74
|
+
*/
|
|
75
|
+
export function finishClassRoot(actualRoot: object, raw: Bootstrap): void {
|
|
76
|
+
const cell = roots.get(actualRoot);
|
|
77
|
+
if (!cell || cell.phase !== "awaiting") rootUnbound();
|
|
78
|
+
try {
|
|
79
|
+
const keys = Reflect.ownKeys(raw);
|
|
80
|
+
const prototype = Object.getOwnPropertyDescriptor(raw, "prototype");
|
|
81
|
+
const select = Object.getOwnPropertyDescriptor(raw, "select");
|
|
82
|
+
const enter = Object.getOwnPropertyDescriptor(raw, "enter");
|
|
83
|
+
if (
|
|
84
|
+
keys.length !== 3 ||
|
|
85
|
+
!keys.every(
|
|
86
|
+
(key) =>
|
|
87
|
+
typeof key === "string" &&
|
|
88
|
+
["prototype", "select", "enter"].includes(key),
|
|
89
|
+
) ||
|
|
90
|
+
!prototype ||
|
|
91
|
+
!("value" in prototype) ||
|
|
92
|
+
!prototype.enumerable ||
|
|
93
|
+
prototype.value === null ||
|
|
94
|
+
typeof prototype.value !== "object" ||
|
|
95
|
+
!select ||
|
|
96
|
+
!("value" in select) ||
|
|
97
|
+
!select.enumerable ||
|
|
98
|
+
typeof select.value !== "function" ||
|
|
99
|
+
!enter ||
|
|
100
|
+
!("value" in enter) ||
|
|
101
|
+
!enter.enumerable ||
|
|
102
|
+
typeof enter.value !== "function" ||
|
|
103
|
+
roots.get(actualRoot) !== cell
|
|
104
|
+
)
|
|
105
|
+
rootUnbound();
|
|
106
|
+
// Values are captured before the temporary descriptor exists; none is called.
|
|
107
|
+
const bootstrap: Bootstrap = Object.freeze({
|
|
108
|
+
prototype: prototype.value,
|
|
109
|
+
select: select.value,
|
|
110
|
+
enter: enter.value,
|
|
111
|
+
});
|
|
112
|
+
pending.set(actualRoot, bootstrap);
|
|
113
|
+
Object.defineProperty(actualRoot, bootstrapSymbol, {
|
|
114
|
+
value: bootstrap,
|
|
115
|
+
enumerable: false,
|
|
116
|
+
writable: false,
|
|
117
|
+
configurable: true,
|
|
118
|
+
});
|
|
119
|
+
finishing.add(actualRoot);
|
|
120
|
+
Reflect.apply(actualFinalizer, actualRoot, []);
|
|
121
|
+
} catch {
|
|
122
|
+
roots.set(actualRoot, Object.freeze({ phase: "failed" }));
|
|
123
|
+
rootUnbound();
|
|
124
|
+
} finally {
|
|
125
|
+
finishing.delete(actualRoot);
|
|
126
|
+
pending.delete(actualRoot);
|
|
127
|
+
if (!Reflect.deleteProperty(actualRoot, bootstrapSymbol)) {
|
|
128
|
+
roots.set(actualRoot, Object.freeze({ phase: "failed" }));
|
|
129
|
+
rootUnbound();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** EMPTY profiles refuse before entry, client selection or Action reflection. */
|
|
135
|
+
export async function captureMaintainedActionSelection(
|
|
136
|
+
actualRoot: object,
|
|
137
|
+
_input: ClassActionInput,
|
|
138
|
+
): Promise<never> {
|
|
139
|
+
const cell = roots.get(actualRoot);
|
|
140
|
+
if (
|
|
141
|
+
!cell ||
|
|
142
|
+
cell.phase !== "ready" ||
|
|
143
|
+
Object.getPrototypeOf(actualRoot) !== cell.bootstrap.prototype
|
|
144
|
+
)
|
|
145
|
+
rootUnbound();
|
|
146
|
+
throw Error("CLASS_ACTION_PROFILE_UNBOUND");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Positive per-Action admission is not implemented by the inert bootstrap. */
|
|
150
|
+
export async function beginClassAction(
|
|
151
|
+
_actualRoot: object,
|
|
152
|
+
_input: ClassActionInput,
|
|
153
|
+
): Promise<never> {
|
|
154
|
+
return rootUnbound();
|
|
155
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -68,7 +68,13 @@ import type { CreateCheckoutSessionOptions } from "./billing/checkoutOptions.js"
|
|
|
68
68
|
export type { CreateCheckoutSessionOptions } from "./billing/checkoutOptions.js";
|
|
69
69
|
import * as intentsImpl from "./billing/intents.js";
|
|
70
70
|
export type * from "./billing/intents.js";
|
|
71
|
-
import {
|
|
71
|
+
import {
|
|
72
|
+
ClassOwnedActionRoot,
|
|
73
|
+
CLASS_ROOT_CONSTRUCTION_PERMIT,
|
|
74
|
+
finishClassRoot,
|
|
75
|
+
beginClassAction,
|
|
76
|
+
type ClassActionInput,
|
|
77
|
+
} from "./billing/renewalAttach/internal/producer/classOwnedActionRoot.js";
|
|
72
78
|
export type {
|
|
73
79
|
CreateBillingPortalConfigurationOptions,
|
|
74
80
|
RetrieveBillingPortalConfigurationOptions,
|
|
@@ -276,7 +282,7 @@ export type BetterStripeComponent = ComponentApi;
|
|
|
276
282
|
|
|
277
283
|
// BETTER STRIPE CLIENT
|
|
278
284
|
|
|
279
|
-
export class BetterStripe extends
|
|
285
|
+
export class BetterStripe extends ClassOwnedActionRoot {
|
|
280
286
|
get usage() {
|
|
281
287
|
return new UsageLedgerClient(this.component);
|
|
282
288
|
}
|
|
@@ -288,7 +294,7 @@ export class BetterStripe extends RenewalContextClient {
|
|
|
288
294
|
private _statementDescriptorSuffix?: string;
|
|
289
295
|
|
|
290
296
|
constructor(component: BetterStripeComponent, options?: BetterStripeOptions) {
|
|
291
|
-
super(component);
|
|
297
|
+
super(component, CLASS_ROOT_CONSTRUCTION_PERMIT);
|
|
292
298
|
this.stripeApiVersion = resolveStripeApiVersion(options?.stripeApiVersion);
|
|
293
299
|
this._apiKey = options?.STRIPE_SECRET_KEY;
|
|
294
300
|
this._triggers = options?.triggers;
|
|
@@ -304,6 +310,21 @@ export class BetterStripe extends RenewalContextClient {
|
|
|
304
310
|
options.statementDescriptorSuffix,
|
|
305
311
|
);
|
|
306
312
|
}
|
|
313
|
+
finishClassRoot(this, {
|
|
314
|
+
prototype: BetterStripe.prototype,
|
|
315
|
+
select: this.#selectRenewalClient,
|
|
316
|
+
enter: this.#enterRenewalAction,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
#selectRenewalClient(): Stripe {
|
|
321
|
+
return getStripeClient(this._apiKey!, this.stripeApiVersion, {
|
|
322
|
+
singleAttempt: true,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#enterRenewalAction(input: ClassActionInput) {
|
|
327
|
+
return beginClassAction(this, input);
|
|
307
328
|
}
|
|
308
329
|
|
|
309
330
|
/**
|
|
@@ -164,6 +164,9 @@ 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_helpers from "../renewalOperations/helpers.js";
|
|
168
|
+
import type * as renewalOperations_mutations from "../renewalOperations/mutations.js";
|
|
169
|
+
import type * as renewalOperations_queries from "../renewalOperations/queries.js";
|
|
167
170
|
import type * as reversalObservations_capture from "../reversalObservations/capture.js";
|
|
168
171
|
import type * as reversalObservations_indexSlice from "../reversalObservations/indexSlice.js";
|
|
169
172
|
import type * as reversalObservations_integrity from "../reversalObservations/integrity.js";
|
|
@@ -383,6 +386,9 @@ const fullApi: ApiFromModules<{
|
|
|
383
386
|
"refundSync/queries": typeof refundSync_queries;
|
|
384
387
|
"refundSync/routing": typeof refundSync_routing;
|
|
385
388
|
"refundSync/validators": typeof refundSync_validators;
|
|
389
|
+
"renewalOperations/helpers": typeof renewalOperations_helpers;
|
|
390
|
+
"renewalOperations/mutations": typeof renewalOperations_mutations;
|
|
391
|
+
"renewalOperations/queries": typeof renewalOperations_queries;
|
|
386
392
|
"reversalObservations/capture": typeof reversalObservations_capture;
|
|
387
393
|
"reversalObservations/indexSlice": typeof reversalObservations_indexSlice;
|
|
388
394
|
"reversalObservations/integrity": typeof reversalObservations_integrity;
|