@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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +41 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js +378 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +44 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +251 -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/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/queries.d.ts +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/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 +180 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +560 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.ts +561 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +334 -0
- package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
- package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
- package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -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,569 @@
|
|
|
1
|
+
import { makeFunctionReference } from "convex/server";
|
|
2
|
+
import { getConvexSize, getDocumentSize } from "convex/values";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { canonicalJournalEvent } from "../../shared/renewalOperationJournal.js";
|
|
5
|
+
import {
|
|
6
|
+
canonical,
|
|
7
|
+
codecFixture,
|
|
8
|
+
componentFixture,
|
|
9
|
+
create,
|
|
10
|
+
load,
|
|
11
|
+
VALUE_LIMIT,
|
|
12
|
+
} from "./timingPolicy.fixtures.js";
|
|
13
|
+
|
|
14
|
+
const reserve = makeFunctionReference<"mutation">(
|
|
15
|
+
"renewalOperations/mutations:reserveAttempt",
|
|
16
|
+
);
|
|
17
|
+
const bind = makeFunctionReference<"mutation">(
|
|
18
|
+
"renewalOperations/mutations:bindInitialBasis",
|
|
19
|
+
);
|
|
20
|
+
// Fixed unsigned DATA, never an actual sampled clock/Owner or eligibility claim.
|
|
21
|
+
const basis = Object.freeze({
|
|
22
|
+
startWallMs: 1700000001000,
|
|
23
|
+
startNsDecimal: "1000000000",
|
|
24
|
+
workEndWallMs: 1700000005000,
|
|
25
|
+
workEndNsDecimal: "5000000000",
|
|
26
|
+
endWallMs: 1700000006000,
|
|
27
|
+
endNsDecimal: "6000000000",
|
|
28
|
+
});
|
|
29
|
+
const changedAnchor = Object.freeze({
|
|
30
|
+
...basis,
|
|
31
|
+
startNsDecimal: "1000000001",
|
|
32
|
+
workEndNsDecimal: "5000000001",
|
|
33
|
+
endNsDecimal: "6000000001",
|
|
34
|
+
});
|
|
35
|
+
const corruptBasis = Object.freeze({
|
|
36
|
+
...basis,
|
|
37
|
+
workEndNsDecimal: "5000000001",
|
|
38
|
+
});
|
|
39
|
+
const legacyBasis = Object.freeze({
|
|
40
|
+
startWallMs: basis.startWallMs,
|
|
41
|
+
startNs: basis.startNsDecimal,
|
|
42
|
+
workEndWallMs: basis.workEndWallMs,
|
|
43
|
+
workEndNs: basis.workEndNsDecimal,
|
|
44
|
+
endWallMs: basis.endWallMs,
|
|
45
|
+
endNs: basis.endNsDecimal,
|
|
46
|
+
});
|
|
47
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
48
|
+
|
|
49
|
+
async function boundOperation() {
|
|
50
|
+
const h = await codecFixture();
|
|
51
|
+
const { t, physical } = componentFixture();
|
|
52
|
+
expect(BigInt(basis.workEndNsDecimal)).toBe(
|
|
53
|
+
BigInt(basis.startNsDecimal) + 4000000000n,
|
|
54
|
+
);
|
|
55
|
+
expect(BigInt(basis.endNsDecimal)).toBe(
|
|
56
|
+
BigInt(basis.startNsDecimal) + 5000000000n,
|
|
57
|
+
);
|
|
58
|
+
const createArgs = {
|
|
59
|
+
authorizationScope: h.record.authorization.scope,
|
|
60
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
61
|
+
authorizationRevision: h.record.authorization.revision,
|
|
62
|
+
recordJSON: h.recordJSON,
|
|
63
|
+
};
|
|
64
|
+
expect(getConvexSize(createArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
65
|
+
expect(await physical()).toEqual({
|
|
66
|
+
operations: [],
|
|
67
|
+
attempts: [],
|
|
68
|
+
events: [],
|
|
69
|
+
payloads: [],
|
|
70
|
+
});
|
|
71
|
+
const created = await t.mutation(create, createArgs);
|
|
72
|
+
expect(created.status).toBe("created");
|
|
73
|
+
expect(getConvexSize(created)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
74
|
+
const queryArgs = { operationId: created.operationId };
|
|
75
|
+
expect(getConvexSize(queryArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
76
|
+
expect(await t.query(load, queryArgs)).toEqual({
|
|
77
|
+
recordVersion: 2,
|
|
78
|
+
operationId: created.operationId,
|
|
79
|
+
recordJSON: h.recordJSON,
|
|
80
|
+
revision: 0,
|
|
81
|
+
activeAttempt: null,
|
|
82
|
+
initialBasis: null,
|
|
83
|
+
});
|
|
84
|
+
const reserveArgs = {
|
|
85
|
+
operationId: created.operationId,
|
|
86
|
+
expectedRevision: 0,
|
|
87
|
+
stage: "attach" as const,
|
|
88
|
+
expectedRequestBinding: h.record.requestBinding,
|
|
89
|
+
recordJSON: h.recordJSON,
|
|
90
|
+
};
|
|
91
|
+
expect(getConvexSize(reserveArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
92
|
+
const acquired = await t.mutation(reserve, reserveArgs);
|
|
93
|
+
expect(acquired.disposition).toBe("acquired");
|
|
94
|
+
expect(getConvexSize(acquired)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
95
|
+
const before = await physical();
|
|
96
|
+
expect(before.operations).toHaveLength(1);
|
|
97
|
+
expect(before.attempts).toHaveLength(1);
|
|
98
|
+
expect(before.payloads).toHaveLength(1);
|
|
99
|
+
expect(before.events).toHaveLength(0);
|
|
100
|
+
const operation = before.operations[0];
|
|
101
|
+
const attempt = before.attempts[0];
|
|
102
|
+
const payload = before.payloads[0];
|
|
103
|
+
expect(operation).toMatchObject({
|
|
104
|
+
_id: created.operationId,
|
|
105
|
+
recordVersion: 2,
|
|
106
|
+
payloadId: payload._id,
|
|
107
|
+
requestBinding: h.record.requestBinding,
|
|
108
|
+
revision: 1,
|
|
109
|
+
state: "RESERVED",
|
|
110
|
+
activeAttemptId: attempt._id,
|
|
111
|
+
});
|
|
112
|
+
expect(payload).toMatchObject({
|
|
113
|
+
codecVersion: 1,
|
|
114
|
+
json: h.recordJSON,
|
|
115
|
+
owner: { kind: "operation", operationId: created.operationId },
|
|
116
|
+
});
|
|
117
|
+
expect(Object.prototype.hasOwnProperty.call(operation, "initialBasis")).toBe(
|
|
118
|
+
false,
|
|
119
|
+
);
|
|
120
|
+
const summary = {
|
|
121
|
+
recordVersion: 2,
|
|
122
|
+
operationId: created.operationId,
|
|
123
|
+
payloadId: payload._id,
|
|
124
|
+
authorizationScope: h.record.authorization.scope,
|
|
125
|
+
authorizationId: h.record.authorization.id,
|
|
126
|
+
authorizationRevision: h.record.authorization.revision,
|
|
127
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
128
|
+
requestBinding: h.record.requestBinding,
|
|
129
|
+
stage: "attach",
|
|
130
|
+
key: h.request.key,
|
|
131
|
+
apiVersion: h.request.apiVersion,
|
|
132
|
+
accountJSON: canonical(h.record.account),
|
|
133
|
+
timingPolicyJSON: canonical(h.record.timingPolicy),
|
|
134
|
+
firstDispatchedAt: h.request.firstDispatchedAt,
|
|
135
|
+
ordinal: 1,
|
|
136
|
+
preparedRevision: 0,
|
|
137
|
+
committedRevision: 1,
|
|
138
|
+
attemptId: attempt._id,
|
|
139
|
+
};
|
|
140
|
+
expect(acquired).toEqual({
|
|
141
|
+
disposition: "acquired",
|
|
142
|
+
previousRevision: 0,
|
|
143
|
+
committedRevision: 1,
|
|
144
|
+
reservation: { ...summary, recordJSON: h.recordJSON },
|
|
145
|
+
});
|
|
146
|
+
const { attemptId, ...fields } = summary;
|
|
147
|
+
expect(attempt).toEqual({
|
|
148
|
+
...fields,
|
|
149
|
+
_id: attemptId,
|
|
150
|
+
_creationTime: attempt._creationTime,
|
|
151
|
+
lastSequence: 0,
|
|
152
|
+
});
|
|
153
|
+
const reserved = await t.query(load, queryArgs);
|
|
154
|
+
expect(reserved).toEqual({
|
|
155
|
+
recordVersion: 2,
|
|
156
|
+
operationId: created.operationId,
|
|
157
|
+
recordJSON: h.recordJSON,
|
|
158
|
+
revision: 1,
|
|
159
|
+
activeAttempt: summary,
|
|
160
|
+
initialBasis: null,
|
|
161
|
+
});
|
|
162
|
+
expect(getConvexSize(reserved)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
163
|
+
const args = {
|
|
164
|
+
operationId: created.operationId,
|
|
165
|
+
attemptId: attempt._id,
|
|
166
|
+
policyJSON: canonical(h.record.timingPolicy),
|
|
167
|
+
basisJSON: canonical(basis),
|
|
168
|
+
};
|
|
169
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
170
|
+
const initialBasis = {
|
|
171
|
+
version: 1 as const,
|
|
172
|
+
attemptId: attempt._id,
|
|
173
|
+
sourcePayloadId: payload._id,
|
|
174
|
+
stage: "attach" as const,
|
|
175
|
+
policyJSON: args.policyJSON,
|
|
176
|
+
basisJSON: args.basisJSON,
|
|
177
|
+
};
|
|
178
|
+
const receipt = {
|
|
179
|
+
status: "bound",
|
|
180
|
+
operationId: created.operationId,
|
|
181
|
+
initialBasis,
|
|
182
|
+
};
|
|
183
|
+
const result = await t.mutation(bind, args);
|
|
184
|
+
expect(result).toEqual(receipt);
|
|
185
|
+
expect(getConvexSize(result)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
186
|
+
const boundRows = await physical();
|
|
187
|
+
expect(boundRows).toEqual({
|
|
188
|
+
...before,
|
|
189
|
+
operations: [{ ...operation, initialBasis }],
|
|
190
|
+
});
|
|
191
|
+
for (const rows of Object.values(boundRows)) {
|
|
192
|
+
for (const row of rows)
|
|
193
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
194
|
+
}
|
|
195
|
+
const loaded = await t.query(load, queryArgs);
|
|
196
|
+
expect(getConvexSize(loaded)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
197
|
+
expect(loaded).toEqual({ ...reserved, initialBasis });
|
|
198
|
+
expect(h.fetchCalls()).toBe(0);
|
|
199
|
+
return {
|
|
200
|
+
fixture: h,
|
|
201
|
+
t,
|
|
202
|
+
physical,
|
|
203
|
+
args,
|
|
204
|
+
queryArgs,
|
|
205
|
+
initialBasis,
|
|
206
|
+
receipt,
|
|
207
|
+
boundRows,
|
|
208
|
+
reservation: acquired.reservation,
|
|
209
|
+
loaded,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
it("BASISL01 returns the original canonical receipt for reordered duplicate DATA", async () => {
|
|
214
|
+
const h = await boundOperation();
|
|
215
|
+
const policyJSON = JSON.stringify(
|
|
216
|
+
Object.fromEntries(Object.entries(JSON.parse(h.args.policyJSON)).reverse()),
|
|
217
|
+
null,
|
|
218
|
+
2,
|
|
219
|
+
);
|
|
220
|
+
const basisJSON = JSON.stringify(
|
|
221
|
+
Object.fromEntries(Object.entries(JSON.parse(h.args.basisJSON)).reverse()),
|
|
222
|
+
null,
|
|
223
|
+
2,
|
|
224
|
+
);
|
|
225
|
+
expect(policyJSON).not.toBe(h.args.policyJSON);
|
|
226
|
+
expect(basisJSON).not.toBe(h.args.basisJSON);
|
|
227
|
+
expect(canonical(JSON.parse(policyJSON))).toBe(h.args.policyJSON);
|
|
228
|
+
expect(canonical(JSON.parse(basisJSON))).toBe(h.args.basisJSON);
|
|
229
|
+
const args = { ...h.args, policyJSON, basisJSON };
|
|
230
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
231
|
+
let targetFailed = false;
|
|
232
|
+
try {
|
|
233
|
+
const duplicate = await h.t.mutation(bind, args);
|
|
234
|
+
expect(getConvexSize(duplicate)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
235
|
+
expect(duplicate).toEqual(h.receipt);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
targetFailed = true;
|
|
238
|
+
throw error;
|
|
239
|
+
} finally {
|
|
240
|
+
try {
|
|
241
|
+
expect(await h.physical()).toEqual(h.boundRows);
|
|
242
|
+
expect(h.fixture.fetchCalls()).toBe(0);
|
|
243
|
+
} catch (inspectionError) {
|
|
244
|
+
if (!targetFailed) throw inspectionError;
|
|
245
|
+
console.info("BASISL01_READONLY_INSPECTION_FAILED");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("BASISL02 refuses a different mathematically valid anchor without rebinding", async () => {
|
|
251
|
+
expect(BigInt(changedAnchor.workEndNsDecimal)).toBe(
|
|
252
|
+
BigInt(changedAnchor.startNsDecimal) +
|
|
253
|
+
BigInt(changedAnchor.workEndWallMs - changedAnchor.startWallMs) *
|
|
254
|
+
1000000n,
|
|
255
|
+
);
|
|
256
|
+
expect(BigInt(changedAnchor.endNsDecimal)).toBe(
|
|
257
|
+
BigInt(changedAnchor.startNsDecimal) +
|
|
258
|
+
BigInt(changedAnchor.endWallMs - changedAnchor.startWallMs) * 1000000n,
|
|
259
|
+
);
|
|
260
|
+
const h = await boundOperation();
|
|
261
|
+
const args = { ...h.args, basisJSON: canonical(changedAnchor) };
|
|
262
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
263
|
+
let targetFailed = false;
|
|
264
|
+
try {
|
|
265
|
+
await expect(h.t.mutation(bind, args)).rejects.toThrow(
|
|
266
|
+
/^RENEWAL_JOURNAL_CONFLICT$/,
|
|
267
|
+
);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
targetFailed = true;
|
|
270
|
+
throw error;
|
|
271
|
+
} finally {
|
|
272
|
+
try {
|
|
273
|
+
expect(await h.physical()).toEqual(h.boundRows);
|
|
274
|
+
expect(h.fixture.fetchCalls()).toBe(0);
|
|
275
|
+
} catch (inspectionError) {
|
|
276
|
+
if (!targetFailed) throw inspectionError;
|
|
277
|
+
console.info("BASISL02_READONLY_INSPECTION_FAILED");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("BASISL03 refuses corrupted stored projection through load and duplicate bind", async () => {
|
|
283
|
+
const h = await boundOperation();
|
|
284
|
+
const corrupt = { ...h.initialBasis, basisJSON: canonical(corruptBasis) };
|
|
285
|
+
await h.t.run((ctx) =>
|
|
286
|
+
ctx.db.patch("renewalOperations", h.args.operationId, {
|
|
287
|
+
initialBasis: corrupt,
|
|
288
|
+
}),
|
|
289
|
+
);
|
|
290
|
+
const damaged = await h.physical();
|
|
291
|
+
expect(damaged).toEqual({
|
|
292
|
+
...h.boundRows,
|
|
293
|
+
operations: [{ ...h.boundRows.operations[0], initialBasis: corrupt }],
|
|
294
|
+
});
|
|
295
|
+
let targetFailed = false;
|
|
296
|
+
try {
|
|
297
|
+
const settled = await Promise.allSettled([
|
|
298
|
+
h.t.query(load, h.queryArgs),
|
|
299
|
+
h.t.mutation(bind, h.args),
|
|
300
|
+
]);
|
|
301
|
+
expect(settled).toEqual([
|
|
302
|
+
{
|
|
303
|
+
status: "rejected",
|
|
304
|
+
reason: expect.objectContaining({
|
|
305
|
+
message: "RENEWAL_JOURNAL_CONFLICT",
|
|
306
|
+
}),
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
status: "rejected",
|
|
310
|
+
reason: expect.objectContaining({
|
|
311
|
+
message: "RENEWAL_JOURNAL_CONFLICT",
|
|
312
|
+
}),
|
|
313
|
+
},
|
|
314
|
+
]);
|
|
315
|
+
} catch (error) {
|
|
316
|
+
targetFailed = true;
|
|
317
|
+
throw error;
|
|
318
|
+
} finally {
|
|
319
|
+
try {
|
|
320
|
+
expect(await h.physical()).toEqual(damaged);
|
|
321
|
+
expect(h.fixture.fetchCalls()).toBe(0);
|
|
322
|
+
} catch (inspectionError) {
|
|
323
|
+
if (!targetFailed) throw inspectionError;
|
|
324
|
+
console.info("BASISL03_READONLY_INSPECTION_FAILED");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it.each(["v2-prepared", "v1-prepared"] as const)(
|
|
330
|
+
"BASISL04 refuses a foreign descriptor on %s DATA",
|
|
331
|
+
async (kind) => {
|
|
332
|
+
const h = await boundOperation();
|
|
333
|
+
const candidate: Record<string, unknown> = {
|
|
334
|
+
...h.fixture.record,
|
|
335
|
+
logicalOperationId: "basis-lifecycle-B",
|
|
336
|
+
authorization: {
|
|
337
|
+
...h.fixture.record.authorization,
|
|
338
|
+
id: "basis-lifecycle-consent-B",
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
if (kind === "v1-prepared") {
|
|
342
|
+
candidate.schemaVersion = 1;
|
|
343
|
+
candidate.basis = legacyBasis;
|
|
344
|
+
delete candidate.timingPolicy;
|
|
345
|
+
}
|
|
346
|
+
const recordJSON = canonical(candidate);
|
|
347
|
+
const args = {
|
|
348
|
+
authorizationScope: h.fixture.record.authorization.scope,
|
|
349
|
+
logicalOperationId: "basis-lifecycle-B",
|
|
350
|
+
authorizationRevision: 1,
|
|
351
|
+
recordJSON,
|
|
352
|
+
};
|
|
353
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
354
|
+
const created = await h.t.mutation(create, args);
|
|
355
|
+
expect(created.status).toBe("created");
|
|
356
|
+
expect(getConvexSize(created)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
357
|
+
const queryArgs = { operationId: created.operationId };
|
|
358
|
+
expect(getConvexSize(queryArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
359
|
+
const clean = await h.t.query(load, queryArgs);
|
|
360
|
+
expect(getConvexSize(clean)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
361
|
+
expect(clean).toEqual({
|
|
362
|
+
...(kind === "v2-prepared"
|
|
363
|
+
? { recordVersion: 2, initialBasis: null }
|
|
364
|
+
: {}),
|
|
365
|
+
operationId: created.operationId,
|
|
366
|
+
recordJSON,
|
|
367
|
+
revision: 0,
|
|
368
|
+
activeAttempt: null,
|
|
369
|
+
});
|
|
370
|
+
const before = await h.physical();
|
|
371
|
+
expect(before.operations).toHaveLength(2);
|
|
372
|
+
expect(before.attempts).toHaveLength(1);
|
|
373
|
+
expect(before.payloads).toHaveLength(2);
|
|
374
|
+
expect(before.events).toHaveLength(0);
|
|
375
|
+
const operationB = before.operations.find(
|
|
376
|
+
(row) => row._id === created.operationId,
|
|
377
|
+
);
|
|
378
|
+
expect(operationB).toMatchObject({
|
|
379
|
+
_id: created.operationId,
|
|
380
|
+
revision: 0,
|
|
381
|
+
state: "PREPARED",
|
|
382
|
+
});
|
|
383
|
+
if (!operationB) throw Error("BASISL04_MISSING_REAL_OPERATION");
|
|
384
|
+
expect(
|
|
385
|
+
before.payloads.find((row) => row._id === operationB.payloadId),
|
|
386
|
+
).toMatchObject({
|
|
387
|
+
codecVersion: 1,
|
|
388
|
+
json: recordJSON,
|
|
389
|
+
owner: { kind: "operation", operationId: created.operationId },
|
|
390
|
+
});
|
|
391
|
+
const foreign = h.initialBasis;
|
|
392
|
+
expect(foreign.sourcePayloadId).not.toBe(operationB.payloadId);
|
|
393
|
+
await h.t.run((ctx) =>
|
|
394
|
+
ctx.db.patch("renewalOperations", created.operationId, {
|
|
395
|
+
initialBasis: foreign,
|
|
396
|
+
}),
|
|
397
|
+
);
|
|
398
|
+
const damaged = await h.physical();
|
|
399
|
+
expect(damaged).toEqual({
|
|
400
|
+
...before,
|
|
401
|
+
operations: before.operations.map((row) =>
|
|
402
|
+
row._id === created.operationId
|
|
403
|
+
? { ...row, initialBasis: foreign }
|
|
404
|
+
: row,
|
|
405
|
+
),
|
|
406
|
+
});
|
|
407
|
+
for (const rows of Object.values(damaged)) {
|
|
408
|
+
for (const row of rows)
|
|
409
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
410
|
+
}
|
|
411
|
+
const foreignArgs = { ...h.args, operationId: created.operationId };
|
|
412
|
+
expect(getConvexSize(foreignArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
413
|
+
let targetFailed = false;
|
|
414
|
+
try {
|
|
415
|
+
const settled = await Promise.allSettled([
|
|
416
|
+
h.t.query(load, queryArgs),
|
|
417
|
+
h.t.mutation(bind, foreignArgs),
|
|
418
|
+
]);
|
|
419
|
+
expect(settled).toEqual([
|
|
420
|
+
{
|
|
421
|
+
status: "rejected",
|
|
422
|
+
reason: expect.objectContaining({
|
|
423
|
+
message: "RENEWAL_JOURNAL_CONFLICT",
|
|
424
|
+
}),
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
status: "rejected",
|
|
428
|
+
reason: expect.objectContaining({
|
|
429
|
+
message: "RENEWAL_JOURNAL_CONFLICT",
|
|
430
|
+
}),
|
|
431
|
+
},
|
|
432
|
+
]);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
targetFailed = true;
|
|
435
|
+
throw error;
|
|
436
|
+
} finally {
|
|
437
|
+
try {
|
|
438
|
+
expect(await h.physical()).toEqual(damaged);
|
|
439
|
+
expect(h.fixture.fetchCalls()).toBe(0);
|
|
440
|
+
} catch (inspectionError) {
|
|
441
|
+
if (!targetFailed) throw inspectionError;
|
|
442
|
+
console.info("BASISL04_READONLY_INSPECTION_FAILED");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
const append = makeFunctionReference<"mutation">(
|
|
449
|
+
"renewalOperations/mutations:appendStageEvent",
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
it("APPENDB01 appends canonical event1 after actual basis binding and preserves its receipt", async () => {
|
|
453
|
+
const h = await boundOperation();
|
|
454
|
+
// Complete generic unsigned event DATA; no typed C10/provider/Owner claim.
|
|
455
|
+
const datum = {
|
|
456
|
+
event: "dispatch",
|
|
457
|
+
stage: "attach",
|
|
458
|
+
request: h.fixture.request,
|
|
459
|
+
};
|
|
460
|
+
const event = await canonicalJournalEvent(1, canonical(datum));
|
|
461
|
+
expect(JSON.parse(event.json)).toEqual(datum);
|
|
462
|
+
const args = {
|
|
463
|
+
reservation: h.reservation,
|
|
464
|
+
expectedSequence: 0,
|
|
465
|
+
event: {
|
|
466
|
+
sequence: event.sequence,
|
|
467
|
+
binding: event.binding,
|
|
468
|
+
dataJSON: event.json,
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
472
|
+
expect(await h.physical()).toEqual(h.boundRows);
|
|
473
|
+
let stable = h.boundRows;
|
|
474
|
+
let targetFailed = false;
|
|
475
|
+
try {
|
|
476
|
+
// Actual existing registered append is currently fenced for V2.
|
|
477
|
+
const appended = await h.t.mutation(append, args);
|
|
478
|
+
expect(getConvexSize(appended)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
479
|
+
const descriptor = {
|
|
480
|
+
operationId: h.args.operationId,
|
|
481
|
+
attemptId: h.args.attemptId,
|
|
482
|
+
stage: "attach",
|
|
483
|
+
sourcePayloadId: h.reservation.payloadId,
|
|
484
|
+
sequence: 1,
|
|
485
|
+
binding: event.binding,
|
|
486
|
+
payloadId: appended.payloadId,
|
|
487
|
+
eventId: appended.eventId,
|
|
488
|
+
};
|
|
489
|
+
expect(appended).toEqual({ ...descriptor, reservation: h.reservation });
|
|
490
|
+
const after = await h.physical();
|
|
491
|
+
stable = after;
|
|
492
|
+
expect(after.operations).toEqual(h.boundRows.operations);
|
|
493
|
+
expect(after.attempts).toEqual([
|
|
494
|
+
{ ...h.boundRows.attempts[0], lastSequence: 1 },
|
|
495
|
+
]);
|
|
496
|
+
expect(after.payloads).toHaveLength(2);
|
|
497
|
+
expect(after.events).toHaveLength(1);
|
|
498
|
+
expect(
|
|
499
|
+
after.payloads.find((row) => row._id === h.reservation.payloadId),
|
|
500
|
+
).toEqual(h.boundRows.payloads[0]);
|
|
501
|
+
const storedPayload = after.payloads.find(
|
|
502
|
+
(row) => row._id === appended.payloadId,
|
|
503
|
+
);
|
|
504
|
+
expect(storedPayload).toBeDefined();
|
|
505
|
+
if (!storedPayload) throw Error("APPENDB01_MISSING_REAL_PAYLOAD");
|
|
506
|
+
expect(storedPayload).toEqual({
|
|
507
|
+
_id: appended.payloadId,
|
|
508
|
+
_creationTime: storedPayload._creationTime,
|
|
509
|
+
codecVersion: 1,
|
|
510
|
+
json: event.json,
|
|
511
|
+
owner: {
|
|
512
|
+
kind: "event",
|
|
513
|
+
operationId: h.args.operationId,
|
|
514
|
+
attemptId: h.args.attemptId,
|
|
515
|
+
stage: "attach",
|
|
516
|
+
sequence: 1,
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
expect(after.events[0]).toEqual({
|
|
520
|
+
_id: appended.eventId,
|
|
521
|
+
_creationTime: after.events[0]._creationTime,
|
|
522
|
+
operationId: descriptor.operationId,
|
|
523
|
+
attemptId: descriptor.attemptId,
|
|
524
|
+
stage: descriptor.stage,
|
|
525
|
+
sourcePayloadId: descriptor.sourcePayloadId,
|
|
526
|
+
sequence: 1,
|
|
527
|
+
binding: descriptor.binding,
|
|
528
|
+
payloadId: descriptor.payloadId,
|
|
529
|
+
});
|
|
530
|
+
for (const rows of Object.values(after)) {
|
|
531
|
+
for (const row of rows)
|
|
532
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
533
|
+
}
|
|
534
|
+
const loaded = await h.t.query(load, h.queryArgs);
|
|
535
|
+
expect(getConvexSize(loaded)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
536
|
+
expect(loaded).toEqual(h.loaded);
|
|
537
|
+
const duplicateBasis = await h.t.mutation(bind, h.args);
|
|
538
|
+
expect(getConvexSize(duplicateBasis)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
539
|
+
expect(duplicateBasis).toEqual(h.receipt);
|
|
540
|
+
expect(await h.physical()).toEqual(after);
|
|
541
|
+
expect(canonical(h.fixture.record)).toBe(h.fixture.recordJSON);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
targetFailed = true;
|
|
544
|
+
console.info(
|
|
545
|
+
"APPENDB01_TARGET_ERROR",
|
|
546
|
+
error instanceof Error ? error.message : "NON_ERROR_THROW",
|
|
547
|
+
);
|
|
548
|
+
throw error;
|
|
549
|
+
} finally {
|
|
550
|
+
try {
|
|
551
|
+
const after = await h.physical();
|
|
552
|
+
console.info(
|
|
553
|
+
"APPENDB01_SETTLEMENT",
|
|
554
|
+
JSON.stringify({
|
|
555
|
+
physicalEqual: JSON.stringify(after) === JSON.stringify(stable),
|
|
556
|
+
rows: Object.fromEntries(
|
|
557
|
+
Object.entries(after).map(([key, rows]) => [key, rows.length]),
|
|
558
|
+
),
|
|
559
|
+
fetchCalls: h.fixture.fetchCalls(),
|
|
560
|
+
}),
|
|
561
|
+
);
|
|
562
|
+
expect(after).toEqual(stable);
|
|
563
|
+
expect(h.fixture.fetchCalls()).toBe(0);
|
|
564
|
+
} catch (inspectionError) {
|
|
565
|
+
if (!targetFailed) throw inspectionError;
|
|
566
|
+
console.info("APPENDB01_READONLY_INSPECTION_FAILED");
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
});
|