@fantastic.dev/better-stripe 0.93.0 → 0.95.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 (57) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +47 -0
  4. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/operationJournal.js +388 -0
  6. package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +24 -5
  8. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +182 -4
  10. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +13 -0
  12. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +43 -0
  14. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +32 -0
  16. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +105 -0
  18. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts +3 -0
  20. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js +59 -0
  22. package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts +11 -0
  24. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +121 -0
  26. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +6 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +16 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -0
  31. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  32. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  33. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  34. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  35. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  36. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  37. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  38. package/docs/renewal-context-reads.md +57 -5
  39. package/package.json +1 -1
  40. package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
  41. package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
  42. package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
  43. package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +181 -1
  44. package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
  45. package/src/client/billing/renewalAttach/internal/operationJournal.ts +573 -0
  46. package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +246 -8
  47. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +58 -0
  48. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +161 -0
  49. package/src/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.ts +54 -0
  50. package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +124 -0
  51. package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
  52. package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
  53. package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
  54. package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +457 -0
  55. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +23 -0
  56. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialDeclarations.ts +5 -0
  57. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +80 -0
@@ -0,0 +1,323 @@
1
+ import assert from "node:assert/strict";
2
+ import { BetterStripe } from "../../../../index.js";
3
+ import { components } from "../../../../../../example/convex/_generated/api.js";
4
+ import { captureMaintainedActionSelection } from "./classOwnedActionRoot.js";
5
+ import {
6
+ createClassActionOperationJournal,
7
+ consumeClassReservation,
8
+ } from "../operationJournal.js";
9
+ import { convexTest } from "convex-test";
10
+ import {
11
+ actionGeneric,
12
+ componentsGeneric,
13
+ defineSchema,
14
+ makeFunctionReference,
15
+ type FunctionReturnType,
16
+ } from "convex/server";
17
+ import { getConvexSize, getDocumentSize, v } from "convex/values";
18
+ import { afterEach, expect, it, vi } from "vitest";
19
+ import { modules, schema } from "../../../../../test.js";
20
+ import { query } from "../../../../../component/_generated/server.js";
21
+ import type { Doc } from "../../../../../component/_generated/dataModel.js";
22
+ import {
23
+ canonical,
24
+ codecFixture,
25
+ VALUE_LIMIT,
26
+ } from "../../../../../component/renewalOperations/timingPolicy.fixtures.js";
27
+ const refs = components.betterStripe.renewalOperations;
28
+ const nested = componentsGeneric();
29
+ const route = makeFunctionReference<"action", { operationId: string }, null>(
30
+ "winningConcurrent:run",
31
+ );
32
+ type Reserved = FunctionReturnType<typeof refs.mutations.reserveAttempt>;
33
+ type Physical = {
34
+ operations: Doc<"renewalOperations">[];
35
+ attempts: Doc<"renewalOperationAttempts">[];
36
+ events: Doc<"renewalOperationEvents">[];
37
+ payloads: Doc<"renewalOperationPayloads">[];
38
+ };
39
+ const inspection = {
40
+ physical: query({
41
+ args: {},
42
+ handler: async (ctx): Promise<Physical> => ({
43
+ operations: await ctx.db.query("renewalOperations").take(4),
44
+ attempts: await ctx.db.query("renewalOperationAttempts").take(4),
45
+ events: await ctx.db.query("renewalOperationEvents").take(4),
46
+ payloads: await ctx.db.query("renewalOperationPayloads").take(5),
47
+ }),
48
+ }),
49
+ };
50
+ afterEach(() => vi.unstubAllGlobals());
51
+
52
+ it("WINNING-CONCURRENT isolates two actual Action call handles on one SDK", async () => {
53
+ const h = await codecFixture();
54
+ const logicalIds = [
55
+ h.record.logicalOperationId,
56
+ h.record.logicalOperationId + "-winning-concurrent",
57
+ ];
58
+ const records = [
59
+ h.recordJSON,
60
+ canonical({ ...h.record, logicalOperationId: logicalIds[1] }),
61
+ ];
62
+ const sdk = new BetterStripe(components.betterStripe, {
63
+ STRIPE_SECRET_KEY: "sk_test_invalid_winning_concurrent",
64
+ });
65
+ const descriptor = Object.getOwnPropertyDescriptor(sdk, "_apiKey");
66
+ assert(descriptor && "value" in descriptor && descriptor.configurable);
67
+ let selectorReads = 0;
68
+ Object.defineProperty(sdk, "_apiKey", {
69
+ configurable: true,
70
+ enumerable: descriptor.enumerable,
71
+ get() {
72
+ selectorReads++;
73
+ throw Error("CONCURRENT_SELECTOR_TOUCHED");
74
+ },
75
+ });
76
+ try {
77
+ const expected = new Map<string, string>();
78
+ const replies: Reserved[] = [];
79
+ const tags = new Set<object>();
80
+ const calls = new Set<object>();
81
+ let captured = 0;
82
+ let release = () => {};
83
+ const bothCaptured = new Promise<void>((resolve) => {
84
+ release = resolve;
85
+ });
86
+ let timer: ReturnType<typeof setTimeout> | undefined;
87
+ const host = {
88
+ run: actionGeneric({
89
+ args: { operationId: v.string() },
90
+ handler: async (ctx, args): Promise<null> => {
91
+ expect(await ctx.meta.getFunctionMetadata()).toEqual({
92
+ name: "winningConcurrent:run",
93
+ componentPath: "",
94
+ type: "action",
95
+ visibility: "public",
96
+ });
97
+ const recordJSON = expected.get(args.operationId);
98
+ assert(recordJSON);
99
+ expect(
100
+ await ctx.runQuery(refs.queries.loadAuthorizedOperation, args),
101
+ ).toEqual({
102
+ recordVersion: 2,
103
+ ...args,
104
+ recordJSON,
105
+ revision: 0,
106
+ activeAttempt: null,
107
+ initialBasis: null,
108
+ });
109
+ await expect(
110
+ captureMaintainedActionSelection(sdk, {
111
+ actualActionCtx: ctx,
112
+ operationId: args.operationId,
113
+ }),
114
+ ).rejects.toThrow(/^CLASS_ACTION_PROFILE_UNBOUND$/);
115
+ const journal = await createClassActionOperationJournal(sdk, {
116
+ actualActionCtx: ctx,
117
+ operationId: args.operationId,
118
+ });
119
+ expect((await journal.loadAuthorizedOperation())?.recordJSON).toBe(
120
+ recordJSON,
121
+ );
122
+ captured++;
123
+ if (captured === 2) release();
124
+ await Promise.race([bothCaptured, timeout]);
125
+ const fresh = await journal.reserveFreshAttempt({
126
+ expectedRevision: 0,
127
+ stage: "attach",
128
+ expectedRequestBinding: h.record.requestBinding,
129
+ recordJSON,
130
+ });
131
+ assert(fresh.result.disposition === "acquired");
132
+ replies.push(fresh.result);
133
+ const reservation = fresh.result.reservation;
134
+ expect(reservation.operationId).toBe(args.operationId);
135
+ expect(reservation.recordJSON).toBe(recordJSON);
136
+ expect(
137
+ await ctx.runQuery(refs.queries.readAttempt, {
138
+ ...args,
139
+ attemptId: reservation.attemptId,
140
+ }),
141
+ ).toEqual({ reservation, events: [] });
142
+ expect(getConvexSize(fresh.result)).toBeLessThanOrEqual(VALUE_LIMIT);
143
+ expect(fresh.call).not.toBeNull();
144
+ assert(fresh.call !== null);
145
+ const call = fresh.call;
146
+ calls.add(call);
147
+ const consumed = consumeClassReservation(call, journal);
148
+ expect(consumed.reservation).toBe(reservation);
149
+ tags.add(consumed.tag);
150
+ expect(() => consumeClassReservation(call, journal)).toThrow(
151
+ /^CLASS_JOURNAL_CALL_UNBOUND$/,
152
+ );
153
+ expect(selectorReads).toBe(0);
154
+ return null;
155
+ },
156
+ }),
157
+ };
158
+ const t = convexTest(defineSchema({}), {
159
+ "./_generated/api.ts": async () => ({}),
160
+ "./winningConcurrent.ts": async () => host,
161
+ });
162
+ expect(
163
+ Object.prototype.hasOwnProperty.call(
164
+ modules,
165
+ "./component/winningConcurrentInspection.ts",
166
+ ),
167
+ ).toBe(false);
168
+ t.registerComponent("betterStripe", schema, {
169
+ ...modules,
170
+ "./component/winningConcurrentInspection.ts": async () => inspection,
171
+ });
172
+ const physical = async (): Promise<Physical> =>
173
+ t.query(nested.betterStripe.winningConcurrentInspection.physical, {});
174
+ expect(await physical()).toEqual({
175
+ operations: [],
176
+ attempts: [],
177
+ events: [],
178
+ payloads: [],
179
+ });
180
+ const ids: string[] = [];
181
+ for (let index = 0; index < records.length; index++) {
182
+ const created = await t.mutation(
183
+ refs.mutations.createAuthorizedOperation,
184
+ {
185
+ authorizationScope: h.record.authorization.scope,
186
+ authorizationRevision: h.record.authorization.revision,
187
+ logicalOperationId: logicalIds[index],
188
+ recordJSON: records[index],
189
+ },
190
+ );
191
+ assert(created.status === "created");
192
+ ids.push(created.operationId);
193
+ expected.set(created.operationId, records[index]);
194
+ }
195
+ expect(new Set(ids).size).toBe(2);
196
+ const before = await physical();
197
+ expect({
198
+ operations: before.operations.length,
199
+ attempts: before.attempts.length,
200
+ events: before.events.length,
201
+ payloads: before.payloads.length,
202
+ }).toEqual({ operations: 2, attempts: 0, events: 0, payloads: 2 });
203
+ for (const operation of before.operations) {
204
+ expect(operation).toMatchObject({
205
+ recordVersion: 2,
206
+ state: "PREPARED",
207
+ revision: 0,
208
+ });
209
+ const source = before.payloads.find(
210
+ (row) => row._id === operation.payloadId,
211
+ );
212
+ assert(source);
213
+ expect(source.json).toBe(expected.get(operation._id));
214
+ expect(source.owner).toEqual({
215
+ kind: "operation",
216
+ operationId: operation._id,
217
+ });
218
+ }
219
+ let stable = before;
220
+ let failed = false;
221
+ const timeout = new Promise<never>((_, reject) => {
222
+ timer = setTimeout(
223
+ () => reject(Error("WINNING_CONCURRENT_CAPTURE_STOP")),
224
+ 1000,
225
+ );
226
+ });
227
+ try {
228
+ const settled = await Promise.allSettled(
229
+ ids.map((operationId) => t.action(route, { operationId })),
230
+ );
231
+ const originalFailure = settled.find(
232
+ (result) => result.status === "rejected",
233
+ );
234
+ try {
235
+ const after = await physical();
236
+ expect(after.operations).toHaveLength(2);
237
+ expect(after.attempts).toHaveLength(replies.length);
238
+ expect(after.events).toEqual([]);
239
+ expect(after.payloads).toEqual(before.payloads);
240
+ for (const original of before.operations) {
241
+ const reply = replies.find(
242
+ (result) =>
243
+ result.disposition === "acquired" &&
244
+ result.reservation.operationId === original._id,
245
+ );
246
+ if (!reply) {
247
+ expect(
248
+ after.operations.find((row) => row._id === original._id),
249
+ ).toEqual(original);
250
+ continue;
251
+ }
252
+ assert(reply.disposition === "acquired");
253
+ const reservation = reply.reservation;
254
+ expect(
255
+ after.operations.find((row) => row._id === original._id),
256
+ ).toEqual({
257
+ ...original,
258
+ state: "RESERVED",
259
+ revision: 1,
260
+ activeAttemptId: reservation.attemptId,
261
+ });
262
+ const actualAttempt = after.attempts.find(
263
+ (row) => row._id === reservation.attemptId,
264
+ );
265
+ assert(actualAttempt);
266
+ const { attemptId, recordJSON: _recordJSON, ...fields } = reservation;
267
+ expect(actualAttempt).toEqual({
268
+ ...fields,
269
+ _id: attemptId,
270
+ _creationTime: actualAttempt._creationTime,
271
+ lastSequence: 0,
272
+ });
273
+ }
274
+ for (const rows of Object.values(after))
275
+ for (const row of rows)
276
+ expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
277
+ stable = after;
278
+ } catch (error) {
279
+ if (originalFailure?.status === "rejected") {
280
+ console.info("WINNING_CONCURRENT_INSPECTION_FAILED");
281
+ throw originalFailure.reason;
282
+ }
283
+ throw error;
284
+ }
285
+ if (originalFailure?.status === "rejected") throw originalFailure.reason;
286
+ expect(settled.map((result) => result.status)).toEqual([
287
+ "fulfilled",
288
+ "fulfilled",
289
+ ]);
290
+ expect(captured).toBe(2);
291
+ expect(replies).toHaveLength(2);
292
+ expect(calls.size).toBe(2);
293
+ expect(tags.size).toBe(2);
294
+ } catch (error) {
295
+ failed = true;
296
+ throw error;
297
+ } finally {
298
+ if (timer !== undefined) clearTimeout(timer);
299
+ try {
300
+ expect(await physical()).toEqual(stable);
301
+ expect(selectorReads).toBe(0);
302
+ expect(h.fetchCalls()).toBe(0);
303
+ console.info(
304
+ "WINNING_CONCURRENT_SETTLEMENT",
305
+ JSON.stringify({
306
+ captured,
307
+ replies: replies.length,
308
+ calls: calls.size,
309
+ tags: tags.size,
310
+ physicalEqual: true,
311
+ selectorReads,
312
+ fetchCalls: 0,
313
+ }),
314
+ );
315
+ } catch (error) {
316
+ if (!failed) throw error;
317
+ console.info("WINNING_CONCURRENT_FINAL_INSPECTION_FAILED");
318
+ }
319
+ }
320
+ } finally {
321
+ Object.defineProperty(sdk, "_apiKey", descriptor);
322
+ }
323
+ });
@@ -0,0 +1,301 @@
1
+ import assert from "node:assert/strict";
2
+ import { BetterStripe } from "../../../../index.js";
3
+ import { components } from "../../../../../../example/convex/_generated/api.js";
4
+ import { captureMaintainedActionSelection } from "./classOwnedActionRoot.js";
5
+ import { createClassActionOperationJournal } from "../operationJournal.js";
6
+ import { convexTest } from "convex-test";
7
+ import {
8
+ actionGeneric,
9
+ componentsGeneric,
10
+ defineSchema,
11
+ makeFunctionReference,
12
+ type FunctionReturnType,
13
+ } from "convex/server";
14
+ import { getConvexSize, getDocumentSize, v } from "convex/values";
15
+ import { afterEach, expect, it, vi } from "vitest";
16
+ import { modules, schema } from "../../../../../test.js";
17
+ import { query } from "../../../../../component/_generated/server.js";
18
+ import type { Doc } from "../../../../../component/_generated/dataModel.js";
19
+ import {
20
+ canonical,
21
+ codecFixture,
22
+ VALUE_LIMIT,
23
+ } from "../../../../../component/renewalOperations/timingPolicy.fixtures.js";
24
+
25
+ const refs = components.betterStripe.renewalOperations;
26
+ const nested = componentsGeneric();
27
+ type Loaded = FunctionReturnType<typeof refs.queries.loadAuthorizedOperation>;
28
+ const call = makeFunctionReference<
29
+ "action",
30
+ { operationId: string },
31
+ { direct: Loaded; actual: Loaded }
32
+ >("classJournal:initial");
33
+ type Physical = {
34
+ operations: Doc<"renewalOperations">[];
35
+ attempts: Doc<"renewalOperationAttempts">[];
36
+ events: Doc<"renewalOperationEvents">[];
37
+ payloads: Doc<"renewalOperationPayloads">[];
38
+ };
39
+ const inspection = {
40
+ physical: query({
41
+ args: {},
42
+ handler: async (ctx): Promise<Physical> => ({
43
+ operations: await ctx.db.query("renewalOperations").take(4),
44
+ attempts: await ctx.db.query("renewalOperationAttempts").take(4),
45
+ events: await ctx.db.query("renewalOperationEvents").take(4),
46
+ payloads: await ctx.db.query("renewalOperationPayloads").take(5),
47
+ }),
48
+ }),
49
+ };
50
+ afterEach(() => vi.unstubAllGlobals());
51
+
52
+ it("CLASS-JOURNAL01 binds the actual SDK and registered Action before journal DATA load", async () => {
53
+ // Complete source/policy/unknown fields are declared by maintained offline codecFixture.
54
+ // Probe is a separate logical operation; target remains PREPARED throughout.
55
+ const h = await codecFixture();
56
+ const probeLogicalId = h.record.logicalOperationId + "-class-journal-probe";
57
+ const probeJSON = canonical({
58
+ ...h.record,
59
+ logicalOperationId: probeLogicalId,
60
+ });
61
+ const sdk = new BetterStripe(components.betterStripe, {
62
+ STRIPE_SECRET_KEY: "sk_test_invalid_class_journal_fixture",
63
+ });
64
+ expect(sdk).toBeInstanceOf(BetterStripe);
65
+ expect(Object.getPrototypeOf(sdk)).toBe(BetterStripe.prototype);
66
+ expect(Object.getOwnPropertySymbols(sdk)).toEqual([]);
67
+ const keyDescriptor = Object.getOwnPropertyDescriptor(sdk, "_apiKey");
68
+ assert(
69
+ keyDescriptor && "value" in keyDescriptor && keyDescriptor.configurable,
70
+ );
71
+ let selectorReads = 0;
72
+ Object.defineProperty(sdk, "_apiKey", {
73
+ configurable: true,
74
+ enumerable: keyDescriptor.enumerable,
75
+ get() {
76
+ selectorReads++;
77
+ throw Error("CLASS_JOURNAL_SELECTOR_TOUCHED");
78
+ },
79
+ });
80
+ try {
81
+ const progress = { action: 0, operationalRefused: 0, direct: 0, target: 0 };
82
+ const host = {
83
+ initial: actionGeneric({
84
+ args: { operationId: v.string() },
85
+ handler: async (
86
+ ctx,
87
+ args,
88
+ ): Promise<FunctionReturnType<typeof call>> => {
89
+ progress.action++;
90
+ const metadata = {
91
+ name: "classJournal:initial",
92
+ componentPath: "",
93
+ type: "action",
94
+ visibility: "public",
95
+ };
96
+ expect(await ctx.meta.getFunctionMetadata()).toEqual(metadata);
97
+ const direct = await ctx.runQuery(
98
+ refs.queries.loadAuthorizedOperation,
99
+ args,
100
+ );
101
+ expect(direct).toEqual({
102
+ recordVersion: 2,
103
+ ...args,
104
+ recordJSON: h.recordJSON,
105
+ revision: 0,
106
+ activeAttempt: null,
107
+ initialBasis: null,
108
+ });
109
+ expect(getConvexSize(direct)).toBeLessThanOrEqual(VALUE_LIMIT);
110
+ progress.direct++;
111
+ // Existing operational bridge remains genuinely EMPTY; no qualifier flag.
112
+ await expect(
113
+ captureMaintainedActionSelection(sdk, {
114
+ actualActionCtx: ctx,
115
+ operationId: args.operationId,
116
+ }),
117
+ ).rejects.toThrow(/^CLASS_ACTION_PROFILE_UNBOUND$/);
118
+ progress.operationalRefused++;
119
+ const clone = Object.create(Object.getPrototypeOf(sdk));
120
+ await expect(
121
+ captureMaintainedActionSelection(clone, {
122
+ actualActionCtx: ctx,
123
+ operationId: args.operationId,
124
+ }),
125
+ ).rejects.toThrow(/^CLASS_ACTION_ROOT_UNBOUND$/);
126
+ expect(
127
+ await ctx.runQuery(
128
+ nested.betterStripe.classJournalInspection.physical,
129
+ {},
130
+ ),
131
+ ).toEqual(before);
132
+ expect(await ctx.meta.getFunctionMetadata()).toEqual(metadata);
133
+ const journal = await createClassActionOperationJournal(sdk, {
134
+ actualActionCtx: ctx,
135
+ operationId: args.operationId,
136
+ });
137
+ progress.target++;
138
+ // First narrow missing class-journal factory NULL seam; not a missing import/ref.
139
+ expect(journal).not.toBeNull();
140
+ assert(journal !== null);
141
+ expect(Object.isFrozen(journal)).toBe(true);
142
+ const actual = await journal.loadAuthorizedOperation();
143
+ expect(actual).toEqual(direct);
144
+ // A working journal binding still cannot unlock operational selection.
145
+ await expect(
146
+ captureMaintainedActionSelection(sdk, {
147
+ actualActionCtx: ctx,
148
+ operationId: args.operationId,
149
+ }),
150
+ ).rejects.toThrow(/^CLASS_ACTION_PROFILE_UNBOUND$/);
151
+ return { direct, actual };
152
+ },
153
+ }),
154
+ };
155
+ const t = convexTest(defineSchema({}), {
156
+ "./_generated/api.ts": async () => ({}),
157
+ "./classJournal.ts": async () => host,
158
+ });
159
+ expect(
160
+ Object.prototype.hasOwnProperty.call(
161
+ modules,
162
+ "./component/classJournalInspection.ts",
163
+ ),
164
+ ).toBe(false);
165
+ t.registerComponent("betterStripe", schema, {
166
+ ...modules,
167
+ "./component/classJournalInspection.ts": async () => inspection,
168
+ });
169
+ const physical = async (): Promise<Physical> =>
170
+ t.query(nested.betterStripe.classJournalInspection.physical, {});
171
+ expect(await physical()).toEqual({
172
+ operations: [],
173
+ attempts: [],
174
+ events: [],
175
+ payloads: [],
176
+ });
177
+ const createInput = {
178
+ authorizationScope: h.record.authorization.scope,
179
+ authorizationRevision: h.record.authorization.revision,
180
+ logicalOperationId: h.record.logicalOperationId,
181
+ recordJSON: h.recordJSON,
182
+ };
183
+ const probe = await t.mutation(refs.mutations.createAuthorizedOperation, {
184
+ ...createInput,
185
+ logicalOperationId: probeLogicalId,
186
+ recordJSON: probeJSON,
187
+ });
188
+ assert(probe.status === "created");
189
+ const probeArgs = { operationId: probe.operationId };
190
+ const acquired = await t.mutation(refs.mutations.reserveAttempt, {
191
+ ...probeArgs,
192
+ expectedRevision: 0,
193
+ stage: "attach",
194
+ expectedRequestBinding: h.record.requestBinding,
195
+ recordJSON: probeJSON,
196
+ });
197
+ assert(acquired.disposition === "acquired");
198
+ expect(acquired.reservation.recordJSON).toBe(probeJSON);
199
+ const existing = await t.mutation(refs.mutations.reserveAttempt, {
200
+ ...probeArgs,
201
+ expectedRevision: 0,
202
+ stage: "attach",
203
+ expectedRequestBinding: h.record.requestBinding,
204
+ recordJSON: probeJSON,
205
+ });
206
+ expect(existing).toEqual({
207
+ disposition: "existing",
208
+ committedRevision: 1,
209
+ reservation: acquired.reservation,
210
+ });
211
+ const created = await t.mutation(
212
+ refs.mutations.createAuthorizedOperation,
213
+ createInput,
214
+ );
215
+ assert(created.status === "created");
216
+ const args = { operationId: created.operationId };
217
+ const expected = {
218
+ recordVersion: 2,
219
+ ...args,
220
+ recordJSON: h.recordJSON,
221
+ revision: 0,
222
+ activeAttempt: null,
223
+ initialBasis: null,
224
+ };
225
+ expect(await t.query(refs.queries.loadAuthorizedOperation, args)).toEqual(
226
+ expected,
227
+ );
228
+ const before = await physical();
229
+ expect({
230
+ operations: before.operations.length,
231
+ attempts: before.attempts.length,
232
+ events: before.events.length,
233
+ payloads: before.payloads.length,
234
+ }).toEqual({ operations: 2, attempts: 1, events: 0, payloads: 2 });
235
+ const target = before.operations.find(
236
+ (row) => row._id === created.operationId,
237
+ );
238
+ assert(target);
239
+ expect(target).toMatchObject({
240
+ recordVersion: 2,
241
+ state: "PREPARED",
242
+ revision: 0,
243
+ });
244
+ expect(target.activeAttemptId).toBeUndefined();
245
+ expect(target.knownAcknowledgement).toBeUndefined();
246
+ const source = before.payloads.find((row) => row._id === target.payloadId);
247
+ assert(source);
248
+ expect(source.json).toBe(h.recordJSON);
249
+ expect(source.owner).toEqual({ kind: "operation", ...args });
250
+ const probeSource = before.payloads.find(
251
+ (row) => row._id === acquired.reservation.payloadId,
252
+ );
253
+ assert(probeSource);
254
+ expect(probeSource.json).toBe(probeJSON);
255
+ expect(probeSource.owner).toEqual({ kind: "operation", ...probeArgs });
256
+ for (const rows of Object.values(before))
257
+ for (const row of rows)
258
+ expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
259
+ expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
260
+ let failed = false;
261
+ try {
262
+ const result = await t.action(call, args);
263
+ expect(progress).toEqual({
264
+ action: 1,
265
+ operationalRefused: 1,
266
+ direct: 1,
267
+ target: 1,
268
+ });
269
+ expect(result).toEqual({ direct: expected, actual: expected });
270
+ expect(getConvexSize(result)).toBeLessThanOrEqual(VALUE_LIMIT);
271
+ } catch (error) {
272
+ failed = true;
273
+ throw error;
274
+ } finally {
275
+ try {
276
+ expect(await physical()).toEqual(before);
277
+ expect(
278
+ await t.query(refs.queries.loadAuthorizedOperation, args),
279
+ ).toEqual(expected);
280
+ expect(h.fetchCalls()).toBe(0);
281
+ expect(selectorReads).toBe(0);
282
+ expect(Object.getOwnPropertySymbols(sdk)).toEqual([]);
283
+ console.info(
284
+ "CLASS_JOURNAL01_SETTLEMENT",
285
+ JSON.stringify({
286
+ ...progress,
287
+ physicalEqual: true,
288
+ targetPrepared: true,
289
+ selectorReads,
290
+ fetchCalls: 0,
291
+ }),
292
+ );
293
+ } catch (error) {
294
+ if (!failed) throw error;
295
+ console.info("CLASS_JOURNAL01_INSPECTION_FAILED");
296
+ }
297
+ }
298
+ } finally {
299
+ Object.defineProperty(sdk, "_apiKey", keyDescriptor);
300
+ }
301
+ });