@fantastic.dev/better-stripe 0.92.0 → 0.94.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 (96) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +41 -0
  4. package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/operationJournal.js +378 -0
  6. package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +44 -0
  8. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +251 -0
  10. package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -0
  11. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +562 -0
  12. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  13. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +281 -0
  14. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  15. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +562 -0
  16. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  17. package/dist/client/connect/payoutSyncTestHelpers.d.ts +281 -0
  18. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  19. package/dist/client/index.d.ts +3 -2
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/index.js +16 -3
  22. package/dist/client/index.js.map +1 -1
  23. package/dist/component/_generated/api.d.ts +6 -0
  24. package/dist/component/_generated/api.d.ts.map +1 -1
  25. package/dist/component/_generated/api.js.map +1 -1
  26. package/dist/component/_generated/component.d.ts +406 -0
  27. package/dist/component/_generated/component.d.ts.map +1 -1
  28. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  29. package/dist/component/balanceFunding/queries.d.ts +1 -1
  30. package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
  31. package/dist/component/earnings/triggers.d.ts +294 -0
  32. package/dist/component/earnings/triggers.d.ts.map +1 -1
  33. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  34. package/dist/component/renewalOperations/helpers.d.ts +236 -0
  35. package/dist/component/renewalOperations/helpers.d.ts.map +1 -0
  36. package/dist/component/renewalOperations/helpers.js +457 -0
  37. package/dist/component/renewalOperations/helpers.js.map +1 -0
  38. package/dist/component/renewalOperations/mutations.d.ts +252 -0
  39. package/dist/component/renewalOperations/mutations.d.ts.map +1 -0
  40. package/dist/component/renewalOperations/mutations.js +340 -0
  41. package/dist/component/renewalOperations/mutations.js.map +1 -0
  42. package/dist/component/renewalOperations/queries.d.ts +163 -0
  43. package/dist/component/renewalOperations/queries.d.ts.map +1 -0
  44. package/dist/component/renewalOperations/queries.js +167 -0
  45. package/dist/component/renewalOperations/queries.js.map +1 -0
  46. package/dist/component/renewalOperations/schema.d.ts +1988 -0
  47. package/dist/component/renewalOperations/schema.d.ts.map +1 -0
  48. package/dist/component/renewalOperations/schema.js +227 -0
  49. package/dist/component/renewalOperations/schema.js.map +1 -0
  50. package/dist/component/schema.d.ts +281 -0
  51. package/dist/component/schema.js +5 -0
  52. package/dist/component/schema.js.map +1 -1
  53. package/dist/component/usage/allowance.fixtures.d.ts +281 -0
  54. package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
  55. package/dist/component/usageCredits/accounting.fixtures.d.ts +297 -16
  56. package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
  57. package/dist/shared/renewalOperationJournal.d.ts +43 -0
  58. package/dist/shared/renewalOperationJournal.d.ts.map +1 -0
  59. package/dist/shared/renewalOperationJournal.js +294 -0
  60. package/dist/shared/renewalOperationJournal.js.map +1 -0
  61. package/docs/renewal-context-reads.md +180 -0
  62. package/package.json +1 -1
  63. package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
  64. package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
  65. package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
  66. package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +560 -0
  67. package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
  68. package/src/client/billing/renewalAttach/internal/operationJournal.ts +561 -0
  69. package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +334 -0
  70. package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
  71. package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
  72. package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
  73. package/src/client/index.ts +24 -3
  74. package/src/component/_generated/api.ts +6 -0
  75. package/src/component/_generated/component.ts +450 -0
  76. package/src/component/renewalOperations/acknowledgement.fixtures.ts +552 -0
  77. package/src/component/renewalOperations/acknowledgement.test.ts +573 -0
  78. package/src/component/renewalOperations/acknowledgementReads.test.ts +442 -0
  79. package/src/component/renewalOperations/acknowledgementV2.test.ts +493 -0
  80. package/src/component/renewalOperations/acknowledgementV2Publication.test.ts +373 -0
  81. package/src/component/renewalOperations/basisBinding.test.ts +567 -0
  82. package/src/component/renewalOperations/basisLifecycle.test.ts +569 -0
  83. package/src/component/renewalOperations/boundHistory.test.ts +474 -0
  84. package/src/component/renewalOperations/helpers.ts +592 -0
  85. package/src/component/renewalOperations/historyReads.test.ts +595 -0
  86. package/src/component/renewalOperations/initialBasis.test.ts +578 -0
  87. package/src/component/renewalOperations/journal.test.ts +567 -0
  88. package/src/component/renewalOperations/mutations.ts +456 -0
  89. package/src/component/renewalOperations/payload.test.ts +589 -0
  90. package/src/component/renewalOperations/payloadEncoding.test.ts +592 -0
  91. package/src/component/renewalOperations/queries.ts +204 -0
  92. package/src/component/renewalOperations/schema.ts +268 -0
  93. package/src/component/renewalOperations/timingPolicy.fixtures.ts +193 -0
  94. package/src/component/renewalOperations/timingPolicy.test.ts +523 -0
  95. package/src/component/schema.ts +11 -0
  96. package/src/shared/renewalOperationJournal.ts +333 -0
@@ -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
+ });