@fantastic.dev/better-stripe 0.91.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 +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.js +46 -56
- package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js +61 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/actor.js +25 -4
- package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.js +3 -2
- package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js +11 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +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 +562 -0
- 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 +562 -0
- 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/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/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- 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 +281 -0
- 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/docs/renewal-material-observation.md +32 -11
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/actor.ts +63 -52
- package/src/client/billing/renewalAttach/internal/configure/ownedContinuation.ts +56 -0
- package/src/client/billing/renewalAttach/internal/observation/actor.ts +46 -3
- package/src/client/billing/renewalAttach/internal/observation/capture.ts +3 -2
- package/src/client/billing/renewalAttach/internal/observation/configureAcknowledgement.ts +20 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACK.integration.test.ts +36 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKControls.integration.test.ts +48 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKLifecycle.integration.test.ts +44 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfiguredHistory.integration.test.ts +34 -0
- package/src/client/billing/renewalAttach/internal/observation/types.ts +5 -0
- 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/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +5 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +12 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDelegate.ts +38 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +8 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +10 -23
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKAssertions.ts +115 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKDeclarations.ts +141 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleAssertions.ts +74 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleDeclarations.ts +79 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleInstrumentation.ts +207 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleOperation.ts +494 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKOperation.ts +452 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryAssertions.ts +88 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryDeclarations.ts +170 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryNative.ts +99 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryOperation.ts +411 -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
|
+
}
|
|
@@ -207,7 +207,11 @@ export function assertConfigureACK(h: ConfigureWriteFixture, output: unknown) {
|
|
|
207
207
|
const slots = ackSlots(h);
|
|
208
208
|
assert.equal(
|
|
209
209
|
slots.length,
|
|
210
|
-
h.write.name === "defaults-null" ||
|
|
210
|
+
h.write.name === "defaults-null" ||
|
|
211
|
+
h.write.name === "defaults-object" ||
|
|
212
|
+
h.write.name === "configured-history" ||
|
|
213
|
+
h.write.name === "configured-history-onephase" ||
|
|
214
|
+
h.write.name === "configured-history-drift"
|
|
211
215
|
? 19
|
|
212
216
|
: 18,
|
|
213
217
|
);
|
package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configuredHistoryResponse } from "./observationConfiguredHistoryNative.js";
|
|
1
2
|
import {
|
|
2
3
|
declarePreflightCase,
|
|
3
4
|
deepFreeze,
|
|
@@ -101,7 +102,11 @@ export const writeCases = {
|
|
|
101
102
|
"retention-unsafe",
|
|
102
103
|
],
|
|
103
104
|
} as const;
|
|
104
|
-
export type WriteCase =
|
|
105
|
+
export type WriteCase =
|
|
106
|
+
| (typeof writeCases)[keyof typeof writeCases][number]
|
|
107
|
+
| "configured-history"
|
|
108
|
+
| "configured-history-onephase"
|
|
109
|
+
| "configured-history-drift";
|
|
105
110
|
|
|
106
111
|
export function declareConfigureWriteCase(name: WriteCase) {
|
|
107
112
|
const baseline = declarePreflightCase("positive");
|
|
@@ -133,6 +138,12 @@ export function declareConfigureWriteCase(name: WriteCase) {
|
|
|
133
138
|
response.default_settings = structuredClone(
|
|
134
139
|
baseline.schedule.default_settings,
|
|
135
140
|
);
|
|
141
|
+
if (
|
|
142
|
+
name === "configured-history" ||
|
|
143
|
+
name === "configured-history-onephase" ||
|
|
144
|
+
name === "configured-history-drift"
|
|
145
|
+
)
|
|
146
|
+
Object.assign(response, configuredHistoryResponse(baseline, name));
|
|
136
147
|
const oracleResponse = structuredClone(response);
|
|
137
148
|
if (name === "wrong-c9") response.id = "sub_sched_foreign";
|
|
138
149
|
if (name === "unsafe-body") response.opaque = "sk_live_SYNTHETIC_UNSAFE";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import type Stripe from "stripe";
|
|
3
|
+
import { data } from "./configurePreflightControls.js";
|
|
4
|
+
import type { WriteObservations } from "./configureWriteObservations.js";
|
|
5
|
+
import type { configureWriteBarriers } from "./configureWriteBarriers.js";
|
|
6
|
+
|
|
7
|
+
/** TEST-only extraction: original client/method/receiver/args/Promise remain unchanged. */
|
|
8
|
+
export function captureWriteTestDelegate(
|
|
9
|
+
client: Stripe,
|
|
10
|
+
method: Stripe["rawRequest"],
|
|
11
|
+
current: () => WriteObservations,
|
|
12
|
+
writeGates: ReturnType<typeof configureWriteBarriers>,
|
|
13
|
+
apiVersion: string,
|
|
14
|
+
) {
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
rawRequest(...args: unknown[]) {
|
|
17
|
+
const state = current();
|
|
18
|
+
state.trace.push("delegate:" + String(args[0]));
|
|
19
|
+
state.delegateArgs.push(args);
|
|
20
|
+
const options = data(args[3]);
|
|
21
|
+
assert.equal(options.apiVersion, apiVersion);
|
|
22
|
+
assert.equal(options.maxNetworkRetries, 0);
|
|
23
|
+
assert.equal(
|
|
24
|
+
Object.prototype.hasOwnProperty.call(options, "stripeAccount"),
|
|
25
|
+
false,
|
|
26
|
+
);
|
|
27
|
+
const promise = Reflect.apply(method, client, args) as Promise<unknown>;
|
|
28
|
+
state.originalPromises.push(promise);
|
|
29
|
+
writeGates.pending.push(
|
|
30
|
+
promise.then(
|
|
31
|
+
() => {},
|
|
32
|
+
() => {},
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
return promise;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -413,6 +413,14 @@ export async function configureWriteTestFamily(args: {
|
|
|
413
413
|
captureA,
|
|
414
414
|
captureB,
|
|
415
415
|
captureC,
|
|
416
|
+
fixedAOperation() {
|
|
417
|
+
return A.operation;
|
|
418
|
+
},
|
|
419
|
+
readFixedA(...values: unknown[]) {
|
|
420
|
+
return scope.run(bindings.A, () =>
|
|
421
|
+
Reflect.apply(delegates.A.rawRequest, delegates.A, values),
|
|
422
|
+
) as Promise<unknown>;
|
|
423
|
+
},
|
|
416
424
|
states,
|
|
417
425
|
currentObservations: () => scope.getStore()?.state ?? states.A,
|
|
418
426
|
covers(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { vi } from "vitest";
|
|
3
3
|
import { declaredEntries } from "./attachEntries.js";
|
|
4
|
+
import { captureWriteTestDelegate } from "./configureWriteDelegate.js";
|
|
4
5
|
import {
|
|
5
6
|
declarePreflightCase,
|
|
6
7
|
deepFreeze,
|
|
@@ -502,29 +503,13 @@ export async function configureWriteFixture(mode: WriteCase = "ack") {
|
|
|
502
503
|
writeGates,
|
|
503
504
|
);
|
|
504
505
|
installWriteDigestAccounting(writeGates);
|
|
505
|
-
const writeDelegate =
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
assert.equal(options.maxNetworkRetries, 0);
|
|
513
|
-
assert.equal(
|
|
514
|
-
Object.prototype.hasOwnProperty.call(options, "stripeAccount"),
|
|
515
|
-
false,
|
|
516
|
-
);
|
|
517
|
-
const promise = Reflect.apply(method, client, args) as Promise<unknown>;
|
|
518
|
-
state.originalPromises.push(promise);
|
|
519
|
-
writeGates.pending.push(
|
|
520
|
-
promise.then(
|
|
521
|
-
() => {},
|
|
522
|
-
() => {},
|
|
523
|
-
),
|
|
524
|
-
);
|
|
525
|
-
return promise;
|
|
526
|
-
},
|
|
527
|
-
});
|
|
506
|
+
const writeDelegate = captureWriteTestDelegate(
|
|
507
|
+
client,
|
|
508
|
+
method,
|
|
509
|
+
() => family?.currentObservations() ?? writeState,
|
|
510
|
+
writeGates,
|
|
511
|
+
write.baseline.apiVersion,
|
|
512
|
+
);
|
|
528
513
|
family = await configureWriteTestFamily({
|
|
529
514
|
declared: write,
|
|
530
515
|
declarations,
|
|
@@ -582,6 +567,8 @@ export async function configureWriteFixture(mode: WriteCase = "ack") {
|
|
|
582
567
|
expectedACK,
|
|
583
568
|
replayDeclaration: declareExpectedReplay(projected),
|
|
584
569
|
captureWriter: family.captureA,
|
|
570
|
+
fixedAOperation: family.fixedAOperation,
|
|
571
|
+
readFixedA: family.readFixedA,
|
|
585
572
|
captureReplayB: family.captureB,
|
|
586
573
|
captureReplayC: family.captureC,
|
|
587
574
|
replayStates: Object.freeze({ B: family.states.B, C: family.states.C }),
|