@fantastic.dev/better-stripe 0.91.0 → 0.92.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 (60) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +6 -0
  4. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/configure/actor.js +46 -56
  6. package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts +3 -0
  8. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts.map +1 -0
  9. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js +61 -0
  10. package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js.map +1 -0
  11. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -1
  12. package/dist/client/billing/renewalAttach/internal/observation/actor.js +25 -4
  13. package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -1
  14. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/observation/capture.js +3 -2
  16. package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts +5 -0
  18. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js +11 -0
  20. package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +5 -0
  22. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -1
  24. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  25. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
  26. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  27. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  28. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  29. package/dist/component/payoutRelease/queries.d.ts +2 -2
  30. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  31. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  32. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  33. package/docs/renewal-material-observation.md +32 -11
  34. package/package.json +1 -1
  35. package/src/client/billing/renewalAttach/internal/configure/actor.ts +63 -52
  36. package/src/client/billing/renewalAttach/internal/configure/ownedContinuation.ts +56 -0
  37. package/src/client/billing/renewalAttach/internal/observation/actor.ts +46 -3
  38. package/src/client/billing/renewalAttach/internal/observation/capture.ts +3 -2
  39. package/src/client/billing/renewalAttach/internal/observation/configureAcknowledgement.ts +20 -0
  40. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACK.integration.test.ts +36 -0
  41. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKControls.integration.test.ts +48 -0
  42. package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKLifecycle.integration.test.ts +44 -0
  43. package/src/client/billing/renewalAttach/internal/observation/observationConfiguredHistory.integration.test.ts +34 -0
  44. package/src/client/billing/renewalAttach/internal/observation/types.ts +5 -0
  45. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +5 -1
  46. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +12 -1
  47. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDelegate.ts +38 -0
  48. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +8 -0
  49. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +10 -23
  50. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKAssertions.ts +115 -0
  51. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKDeclarations.ts +141 -0
  52. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleAssertions.ts +74 -0
  53. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleDeclarations.ts +79 -0
  54. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleInstrumentation.ts +207 -0
  55. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleOperation.ts +494 -0
  56. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKOperation.ts +452 -0
  57. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryAssertions.ts +88 -0
  58. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryDeclarations.ts +170 -0
  59. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryNative.ts +99 -0
  60. package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryOperation.ts +411 -0
@@ -0,0 +1,452 @@
1
+ import assert from "node:assert/strict";
2
+ import { vi } from "vitest";
3
+ import * as actualPublicAPI from "../../../renewalV2/index.js";
4
+ import * as publicObserver from "../../../renewalV2/observation.js";
5
+ import {
6
+ declareOptionalConfigureACK18,
7
+ declareOptionalConfigureACKCase,
8
+ type OptionalConfigureACKCase,
9
+ type OptionalConfigureACKControl,
10
+ } from "./observationConfigureACKDeclarations.js";
11
+ import { configureWriteFixture } from "./configureWriteOperation.js";
12
+ import { assertConfigureACK, ackSlots } from "./configureWriteAssertions.js";
13
+ import { assertFit } from "./configurePreflightAssertions.js";
14
+ import { data, deepFreeze } from "./configurePreflightControls.js";
15
+
16
+ /** Fixed first18 TEST chain. No production custody/context registrar is introduced. */
17
+ export async function optionalConfigureACK18Fixture() {
18
+ return setupOptionalConfigureACK("actual18-default-absent");
19
+ }
20
+ export async function optionalConfigureACKControlFixture(
21
+ controlCase: OptionalConfigureACKControl,
22
+ ) {
23
+ return setupOptionalConfigureACK(controlCase);
24
+ }
25
+ async function setupOptionalConfigureACK(
26
+ controlCase: OptionalConfigureACKCase,
27
+ ) {
28
+ const selected = declareOptionalConfigureACKCase(controlCase);
29
+ const declaration = selected.declaration;
30
+ if (controlCase === "actual18-default-absent")
31
+ assert.deepEqual(
32
+ declaration,
33
+ declareOptionalConfigureACK18(),
34
+ "ORIGINAL18_WHOLE_DECLARATION_PARITY",
35
+ );
36
+ const writer = await configureWriteFixture(selected.writerMode);
37
+ const pending: Promise<unknown>[] = [];
38
+ const calls: { method: string; path: string }[] = [];
39
+ const promises: Promise<unknown>[] = [];
40
+ const counters = {
41
+ source: 0,
42
+ target: 0,
43
+ coverage: 0,
44
+ observer: 0,
45
+ C6: 0,
46
+ C3: 0,
47
+ C9: 0,
48
+ lookup: 0,
49
+ };
50
+ const clean = async () => {
51
+ try {
52
+ await Promise.all(pending);
53
+ } finally {
54
+ vi.doUnmock("../configure/actor.js");
55
+ vi.doUnmock("../../../renewalV2/observation.js");
56
+ await writer.cleanup();
57
+ }
58
+ };
59
+ try {
60
+ assert.deepEqual(
61
+ writer.write,
62
+ declaration.writer,
63
+ "PREDECLARED_WRITER_RECIPE_PARITY",
64
+ );
65
+ const basis = writer.OWNER.basis;
66
+ const writerACK: unknown = await writer.captureWriter().invoke();
67
+ assertConfigureACK(writer, writerACK);
68
+ const expectedSlots = selected.writerMode === "ack" ? 18 : 19;
69
+ const expectedDefaultsPresent = expectedSlots === 19;
70
+ assert.equal(ackSlots(writer).length, expectedSlots);
71
+ const ack = data(writerACK);
72
+ assert.equal(
73
+ Object.prototype.hasOwnProperty.call(
74
+ data(ack.receipt),
75
+ "defaultSettingsBinding",
76
+ ),
77
+ expectedDefaultsPresent,
78
+ );
79
+ const rawReceipt = data(ack.rawReceipt);
80
+ assert.equal(
81
+ Object.prototype.hasOwnProperty.call(
82
+ data(rawReceipt.providerSnapshot),
83
+ "default_settings",
84
+ ),
85
+ expectedDefaultsPresent,
86
+ );
87
+ if (expectedDefaultsPresent) {
88
+ const defaults = data(rawReceipt.providerSnapshot).default_settings;
89
+ assert.deepEqual(defaults, declaration.writer.response.default_settings);
90
+ if (selected.writerMode === "defaults-null") assert.equal(defaults, null);
91
+ else assert(defaults !== null && typeof defaults === "object");
92
+ const defaultBinding = data(ack.receipt).defaultSettingsBinding;
93
+ assert.equal(
94
+ defaultBinding,
95
+ writer.expectedReceipt.defaultSettingsBinding,
96
+ );
97
+ assert(typeof defaultBinding === "string");
98
+ assert.match(
99
+ defaultBinding,
100
+ /^renewal-configured-defaults:v2:sha256:[0-9a-f]{64}$/,
101
+ );
102
+ }
103
+ assert.deepEqual(rawReceipt, writer.rawReceipt);
104
+ const phases = data(rawReceipt.providerSnapshot).phases;
105
+ assert(Array.isArray(phases));
106
+ assert.equal(phases.length, 1);
107
+ const actualOperation = writer.fixedAOperation();
108
+ assert.equal(actualOperation.owner, writer.OWNER);
109
+ assert.equal(
110
+ actualOperation.actualAttachAcknowledgement,
111
+ writer.acknowledgement,
112
+ );
113
+ const originalEntry = actualOperation.originalEntry;
114
+ const origin = actualOperation.originAssociation;
115
+ const source = await import("../operations/sourceOperations.js");
116
+ assert.equal(source.ORIGINAL_ORIGIN_ASSOCIATION, origin);
117
+ assert(source.COMPILED_INITIAL_ENTRIES.includes(originalEntry));
118
+ const writerBefore = Object.freeze({
119
+ records: writer.writeState.records.length,
120
+ posts: writer.writeState.calls.filter((row) => row.method === "POST")
121
+ .length,
122
+ c9: writer.writeState.explicitC9,
123
+ });
124
+ assert.deepEqual(writerBefore, { records: 3, posts: 1, c9: 1 });
125
+ const setupBefore = Object.freeze({
126
+ records: writer.state.records.length,
127
+ posts: writer.state.calls.filter((row) => row.method === "POST").length,
128
+ });
129
+ assert.deepEqual(setupBefore, { records: 3, posts: 1 });
130
+ const input = deepFreeze({
131
+ configuration: writer.expectedRecord.configuration,
132
+ reads: declaration.reads,
133
+ configureReceipt: rawReceipt,
134
+ });
135
+ const direct: unknown = await Reflect.apply(
136
+ publicObserver.inspectRenewalScheduleMaterialV2,
137
+ publicObserver,
138
+ [input],
139
+ );
140
+ assert.deepEqual(
141
+ direct,
142
+ declaration.expectedObservation,
143
+ "UNMODIFIED_PUBLIC_OBSERVER_UNKNOWN_PREREQUISITE",
144
+ );
145
+ const expectedOutput = deepFreeze({
146
+ status: "owned_observation_data",
147
+ observation: direct,
148
+ reads: declaration.reads,
149
+ observedAt: declaration.observedAt,
150
+ retainedConfigureAcknowledgement: "present",
151
+ operationalAuthority: false,
152
+ });
153
+ const prerequisites = {
154
+ record: assertFit(writer.expectedRecord),
155
+ actualACK: assertFit(writerACK),
156
+ rawReceipt: assertFit(rawReceipt),
157
+ publicInput: assertFit(input),
158
+ publicResult: assertFit(direct),
159
+ expectedOutput: assertFit(expectedOutput),
160
+ };
161
+ assert.equal(writer.OWNER.basis, basis);
162
+ vi.stubGlobal("fetch", async (value: unknown, init: RequestInit) => {
163
+ const row = declaration.rows[calls.length];
164
+ assert(row, "UNDECLARED_OPTIONAL_ACK_READ");
165
+ const url = new URL(String(value));
166
+ assert.equal(url.origin, "https://api.stripe.com");
167
+ assert.equal(url.pathname + url.search, row.path);
168
+ assert.equal(init.method, "GET");
169
+ assert.equal(init.body, undefined);
170
+ assert.equal(init.redirect, "error");
171
+ const headers = new Headers(init.headers);
172
+ assert.equal(
173
+ headers.get("stripe-version"),
174
+ declaration.writer.baseline.apiVersion,
175
+ );
176
+ assert.equal(headers.get("stripe-account"), null);
177
+ calls.push({ method: "GET", path: row.path });
178
+ return new Response(JSON.stringify(row.body), {
179
+ status: 200,
180
+ headers: {
181
+ "content-type": "application/json",
182
+ "request-id": "req_SYNTHETIC_OPTIONAL_ACK",
183
+ },
184
+ });
185
+ });
186
+ const readTransport = Object.freeze({
187
+ rawRequest(...args: unknown[]) {
188
+ writer.OWNER.check();
189
+ const row = declaration.rows[promises.length];
190
+ assert(row);
191
+ assert.deepEqual(args, ["GET", row.path, undefined, row.options]);
192
+ const promise = writer.readFixedA(...args);
193
+ promises.push(promise);
194
+ pending.push(
195
+ promise.then(
196
+ () => {},
197
+ () => {},
198
+ ),
199
+ );
200
+ return promise;
201
+ },
202
+ });
203
+ const observationEntry = Object.freeze({
204
+ originalEntry,
205
+ coversObservation(
206
+ record: unknown,
207
+ actualInput: unknown,
208
+ result: unknown,
209
+ ) {
210
+ counters.coverage++;
211
+ assert.deepEqual(record, writer.expectedRecord);
212
+ assert.deepEqual(actualInput, input);
213
+ assert.deepEqual(result, direct);
214
+ return true;
215
+ },
216
+ });
217
+ const operation = Object.freeze({
218
+ owner: writer.OWNER,
219
+ originAssociation: origin,
220
+ originalEntry,
221
+ observationEntry,
222
+ record: writer.expectedRecord,
223
+ actualAttachAcknowledgement: writer.acknowledgement,
224
+ readTransport,
225
+ configureAcknowledgement: writerACK,
226
+ configureOperation: actualOperation,
227
+ });
228
+ let sourceOperation: unknown = operation;
229
+ if (controlCase === "cloned-returnedACK")
230
+ sourceOperation = Object.freeze({
231
+ ...operation,
232
+ configureAcknowledgement: deepFreeze(structuredClone(writerACK)),
233
+ });
234
+ else if (controlCase === "foreign-operation")
235
+ sourceOperation = Object.freeze({
236
+ ...operation,
237
+ configureOperation: Object.freeze({
238
+ declared: "FOREIGN_CONFIGURE_OPERATION",
239
+ }),
240
+ });
241
+ else if (controlCase === "cloned-actual-operation")
242
+ sourceOperation = Object.freeze({
243
+ ...operation,
244
+ configureOperation: Object.freeze({ ...actualOperation }),
245
+ });
246
+ else if (controlCase === "raw-C9-input-instead-of-returnedACK")
247
+ sourceOperation = Object.freeze({
248
+ ...operation,
249
+ configureAcknowledgement: rawReceipt,
250
+ });
251
+ else if (controlCase === "own-ACK-undefined")
252
+ sourceOperation = Object.freeze({
253
+ ...operation,
254
+ configureAcknowledgement: undefined,
255
+ });
256
+ else if (controlCase === "own-ACK-null")
257
+ sourceOperation = Object.freeze({
258
+ ...operation,
259
+ configureAcknowledgement: null,
260
+ });
261
+ else if (
262
+ controlCase === "ACK-present-operation-absent" ||
263
+ controlCase === "operation-present-ACK-absent"
264
+ ) {
265
+ const omitted =
266
+ controlCase === "ACK-present-operation-absent"
267
+ ? "configureOperation"
268
+ : "configureAcknowledgement";
269
+ sourceOperation = Object.freeze(
270
+ Object.fromEntries(
271
+ Object.entries(operation).filter(([key]) => key !== omitted),
272
+ ),
273
+ );
274
+ }
275
+ const actualWriterActor = await import("../configure/actor.js");
276
+ const actualLookup = actualWriterActor.readOwnedConfigureAcknowledgement;
277
+ assert.equal(typeof actualLookup, "function");
278
+ vi.doMock("../configure/actor.js", () => ({
279
+ ...actualWriterActor,
280
+ readOwnedConfigureAcknowledgement(
281
+ this: unknown,
282
+ ...args: Parameters<typeof actualLookup>
283
+ ) {
284
+ counters.lookup++;
285
+ return Reflect.apply(actualLookup, this, args) as ReturnType<
286
+ typeof actualLookup
287
+ >;
288
+ },
289
+ }));
290
+ vi.doMock("../operations/sourceOperations.js", () => ({
291
+ ...source,
292
+ COMPILED_OBSERVATION_ENTRIES: Object.freeze([observationEntry]),
293
+ loadFixedObservationOperation() {
294
+ assert.equal(arguments.length, 0);
295
+ counters.source++;
296
+ return sourceOperation;
297
+ },
298
+ }));
299
+ const keep = <T>(promise: Promise<T>) => {
300
+ pending.push(
301
+ promise.then(
302
+ () => {},
303
+ () => {},
304
+ ),
305
+ );
306
+ return promise;
307
+ };
308
+ vi.doMock("../../../renewalV2/index.js", () => ({
309
+ ...actualPublicAPI,
310
+ projectRenewalConfigurationV2(
311
+ ...args: Parameters<
312
+ typeof actualPublicAPI.projectRenewalConfigurationV2
313
+ >
314
+ ) {
315
+ counters.C6++;
316
+ return keep(
317
+ Reflect.apply(
318
+ actualPublicAPI.projectRenewalConfigurationV2,
319
+ actualPublicAPI,
320
+ args,
321
+ ) as ReturnType<typeof actualPublicAPI.projectRenewalConfigurationV2>,
322
+ );
323
+ },
324
+ constructRenewalScheduleAttachmentReceiptV2(
325
+ ...args: Parameters<
326
+ typeof actualPublicAPI.constructRenewalScheduleAttachmentReceiptV2
327
+ >
328
+ ) {
329
+ counters.C3++;
330
+ return keep(
331
+ Reflect.apply(
332
+ actualPublicAPI.constructRenewalScheduleAttachmentReceiptV2,
333
+ actualPublicAPI,
334
+ args,
335
+ ) as ReturnType<
336
+ typeof actualPublicAPI.constructRenewalScheduleAttachmentReceiptV2
337
+ >,
338
+ );
339
+ },
340
+ constructRenewalConfigurationReceiptV2(
341
+ ...args: Parameters<
342
+ typeof actualPublicAPI.constructRenewalConfigurationReceiptV2
343
+ >
344
+ ) {
345
+ counters.C9++;
346
+ return keep(
347
+ Reflect.apply(
348
+ actualPublicAPI.constructRenewalConfigurationReceiptV2,
349
+ actualPublicAPI,
350
+ args,
351
+ ) as ReturnType<
352
+ typeof actualPublicAPI.constructRenewalConfigurationReceiptV2
353
+ >,
354
+ );
355
+ },
356
+ }));
357
+ vi.doMock("../../../renewalV2/observation.js", () => ({
358
+ ...publicObserver,
359
+ inspectRenewalScheduleMaterialV2(
360
+ ...args: Parameters<
361
+ typeof publicObserver.inspectRenewalScheduleMaterialV2
362
+ >
363
+ ) {
364
+ counters.observer++;
365
+ const promise = Reflect.apply(
366
+ publicObserver.inspectRenewalScheduleMaterialV2,
367
+ publicObserver,
368
+ args,
369
+ ) as ReturnType<typeof publicObserver.inspectRenewalScheduleMaterialV2>;
370
+ pending.push(
371
+ promise.then(
372
+ () => {},
373
+ () => {},
374
+ ),
375
+ );
376
+ return promise;
377
+ },
378
+ }));
379
+ const actor = await import("../observation/actor.js");
380
+ writer.OWNER.check();
381
+ assert.deepEqual(counters, {
382
+ source: 0,
383
+ target: 0,
384
+ coverage: 0,
385
+ observer: 0,
386
+ C6: 0,
387
+ C3: 0,
388
+ C9: 0,
389
+ lookup: 0,
390
+ });
391
+ assert.equal(calls.length, 0);
392
+ console.log(
393
+ JSON.stringify({
394
+ kind: "OPTIONAL_ACK18_ACTUAL_PREREQUISITES",
395
+ actualInitialACK: true,
396
+ actualWriterACK: true,
397
+ actualConfigureOperationPointer: true,
398
+ sameOriginalOwnerENTRYAndOrigin: true,
399
+ controlCase,
400
+ controlStage: selected.stage,
401
+ generatedSlots: expectedSlots,
402
+ originalClientAndPromisePath: true,
403
+ writerBefore,
404
+ setupBefore,
405
+ observationHTTP: 0,
406
+ directUnmodifiedObserver: direct,
407
+ prerequisites,
408
+ operationalAuthority: false,
409
+ }),
410
+ );
411
+ return {
412
+ declaration,
413
+ selected,
414
+ writer,
415
+ writerACK,
416
+ operation,
417
+ sourceOperation,
418
+ basis,
419
+ input,
420
+ expectedOutput,
421
+ writerBefore,
422
+ setupBefore,
423
+ calls,
424
+ promises,
425
+ counters,
426
+ capture() {
427
+ const handle = actor.captureOwnedRenewalObservationV2();
428
+ return Object.freeze({
429
+ invoke() {
430
+ counters.target++;
431
+ const promise = Reflect.apply(
432
+ handle.invoke,
433
+ handle,
434
+ [],
435
+ ) as ReturnType<typeof handle.invoke>;
436
+ pending.push(
437
+ promise.then(
438
+ () => {},
439
+ () => {},
440
+ ),
441
+ );
442
+ return promise;
443
+ },
444
+ });
445
+ },
446
+ cleanup: clean,
447
+ };
448
+ } catch (error) {
449
+ await clean();
450
+ throw error;
451
+ }
452
+ }
@@ -0,0 +1,88 @@
1
+ import assert from "node:assert/strict";
2
+ import { data } from "./configurePreflightControls.js";
3
+ import { assertFit } from "./configurePreflightAssertions.js";
4
+ import type { configuredHistoryFixture } from "./observationConfiguredHistoryOperation.js";
5
+
6
+ export function assertConfiguredHistoryResult(
7
+ h: Awaited<ReturnType<typeof configuredHistoryFixture>>,
8
+ output: unknown,
9
+ ) {
10
+ assert.deepEqual(output, h.expectedOutput);
11
+ const out = data(output);
12
+ assert.deepEqual(
13
+ Object.keys(out).sort(),
14
+ [
15
+ "status",
16
+ "observation",
17
+ "reads",
18
+ "observedAt",
19
+ "retainedConfigureAcknowledgement",
20
+ "operationalAuthority",
21
+ ].sort(),
22
+ );
23
+ assert.equal(out.retainedConfigureAcknowledgement, "present");
24
+ assert.equal(out.operationalAuthority, false);
25
+ assert.equal(h.counters.target, 1);
26
+ assert.equal(h.counters.source, 1);
27
+ assert.equal(h.counters.coverage, 1);
28
+ assert.equal(h.counters.observer, 1);
29
+ assert.equal(h.counters.C6, 1);
30
+ assert.equal(h.counters.C3, 1);
31
+ assert.equal(h.counters.C9, 1);
32
+ assert.equal(h.counters.lookup, 1);
33
+ assert.notEqual(output, h.expectedOutput);
34
+ assert.notEqual(out.reads, h.declaration.reads);
35
+ assert.notEqual(data(out.reads).schedule, h.declaration.reads.schedule);
36
+ assert.notEqual(out.observation, data(h.expectedOutput).observation);
37
+ assert.equal(h.writer.writeState.explicitC9, h.writerBefore.c9);
38
+ assert.equal(h.calls.length, 6);
39
+ assert.equal(h.promises.length, 6);
40
+ assert.deepEqual(
41
+ h.calls,
42
+ h.declaration.rows.map((row) => ({ method: "GET", path: row.path })),
43
+ );
44
+ assert.equal(h.writer.writeState.records.length, h.writerBefore.records);
45
+ assert.equal(
46
+ h.writer.writeState.calls.filter((row) => row.method === "POST").length,
47
+ h.writerBefore.posts,
48
+ );
49
+ assert.equal(h.writer.state.records.length, h.setupBefore.records);
50
+ assert.equal(
51
+ h.writer.state.calls.filter((row) => row.method === "POST").length,
52
+ h.setupBefore.posts,
53
+ );
54
+ assert.equal(h.writer.OWNER.basis, h.basis);
55
+ assert.equal(h.operation.configureOperation, h.writer.fixedAOperation());
56
+ assert.equal(h.operation.configureAcknowledgement, h.writerACK);
57
+ assert.equal(
58
+ h.operation.actualAttachAcknowledgement,
59
+ h.writer.acknowledgement,
60
+ );
61
+ assert.deepEqual(out.observation, h.declaration.expectedObservation);
62
+ const sample = h.finalSample();
63
+ assert(sample);
64
+ assert.equal(out.observedAt, Math.floor(sample.wallMs / 1000));
65
+ assert.equal(
66
+ h.writer.OWNER.check().nowSeconds,
67
+ Math.floor(sample.wallMs / 1000),
68
+ );
69
+ const subscription = data(data(out.reads).subscription);
70
+ assert.equal(
71
+ subscription.latest_invoice,
72
+ h.declaration.controlCase === "H07-active-invoice-I0-I1"
73
+ ? "in_successor"
74
+ : "in_original",
75
+ );
76
+ const items = data(subscription.items).data;
77
+ assert(Array.isArray(items) && items.length === 1);
78
+ assert.equal(data(data(items[0]).plan).object, "plan");
79
+ assert.deepEqual(data(out.reads).schedule, h.declaration.reads.schedule);
80
+ assertFit(output);
81
+ const frozen = (value: unknown) => {
82
+ if (value && typeof value === "object") {
83
+ assert(Object.isFrozen(value));
84
+ for (const child of Object.values(value)) frozen(child);
85
+ }
86
+ };
87
+ frozen(output);
88
+ }
@@ -0,0 +1,170 @@
1
+ import assert from "node:assert/strict";
2
+ import { declareConfigureWriteCase } from "./configureWriteDeclarations.js";
3
+ import { deepFreeze } from "./configurePreflightControls.js";
4
+ import { configuredHistoryLiveReads } from "./observationConfiguredHistoryNative.js";
5
+
6
+ export const configuredHistoryCases = [
7
+ "H01-pending",
8
+ "H02-active",
9
+ "H03-history-onephase",
10
+ "H04-history-opaque-drift",
11
+ "H05-live-target-end",
12
+ "H06-live-default-drift",
13
+ "H07-active-invoice-I0-I1",
14
+ "H08-active-unknown-metadata",
15
+ "H09-live-coupon-counter",
16
+ "H10-live-customer-sequence",
17
+ ] as const;
18
+ export type ConfiguredHistoryCase = (typeof configuredHistoryCases)[number];
19
+ const unsigned = {
20
+ acknowledgementEstablished: false,
21
+ authenticationEstablished: false,
22
+ providerQualificationRequired: true,
23
+ } as const;
24
+ /** Every complete writer/live raw scenario and exact result precedes all constructors. */
25
+ export function declareConfiguredHistoryCase(
26
+ controlCase: ConfiguredHistoryCase,
27
+ ) {
28
+ assert(
29
+ (configuredHistoryCases as readonly string[]).includes(controlCase),
30
+ "UNDECLARED_CONFIGURED_HISTORY_CASE",
31
+ );
32
+ const writerMode =
33
+ controlCase === "H03-history-onephase"
34
+ ? "configured-history-onephase"
35
+ : controlCase === "H04-history-opaque-drift"
36
+ ? "configured-history-drift"
37
+ : "configured-history";
38
+ const writer = declareConfigureWriteCase(writerMode);
39
+ const active =
40
+ controlCase === "H02-active" ||
41
+ controlCase === "H07-active-invoice-I0-I1" ||
42
+ controlCase === "H08-active-unknown-metadata";
43
+ const reads = configuredHistoryLiveReads(writer.baseline, active);
44
+ if (controlCase === "H05-live-target-end")
45
+ reads.schedule.phases[1]!.end_date++;
46
+ if (controlCase === "H06-live-default-drift")
47
+ Object.defineProperty(reads.schedule.default_settings, "description", {
48
+ value: "TEST_DECLARED_DEFAULT_DRIFT",
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ });
53
+ if (controlCase === "H07-active-invoice-I0-I1")
54
+ reads.subscription.latest_invoice = "in_successor";
55
+ if (controlCase === "H08-active-unknown-metadata")
56
+ reads.subscription.metadata.keep = "TEST_DECLARED_ACTIVE_DRIFT";
57
+ if (controlCase === "H09-live-coupon-counter")
58
+ reads.coupons[0]!.times_redeemed++;
59
+ if (controlCase === "H10-live-customer-sequence")
60
+ reads.billingCustomer.next_invoice_sequence++;
61
+ const results = {
62
+ "H01-pending": { ...unsigned, predicate: "pending_material_match" },
63
+ "H02-active": {
64
+ ...unsigned,
65
+ predicate: "current_target_material_match",
66
+ observedItemId: "si_successor",
67
+ nativePeriod: { start: 1771113600, end: 1773532800 },
68
+ },
69
+ "H03-history-onephase": {
70
+ ...unsigned,
71
+ predicate: "unknown",
72
+ reason: "configured_baseline_material_unproven",
73
+ },
74
+ "H04-history-opaque-drift": {
75
+ ...unsigned,
76
+ predicate: "conflict",
77
+ reason: "full_phase_or_default_read_drift",
78
+ },
79
+ "H05-live-target-end": {
80
+ ...unsigned,
81
+ predicate: "conflict",
82
+ reason: "configured_ack_full_baseline_drift",
83
+ },
84
+ "H06-live-default-drift": {
85
+ ...unsigned,
86
+ predicate: "conflict",
87
+ reason: "full_phase_or_default_read_drift",
88
+ },
89
+ "H07-active-invoice-I0-I1": {
90
+ ...unsigned,
91
+ predicate: "conflict",
92
+ reason: "effective_full_material_drift",
93
+ },
94
+ "H08-active-unknown-metadata": {
95
+ ...unsigned,
96
+ predicate: "conflict",
97
+ reason: "effective_full_material_drift",
98
+ },
99
+ "H09-live-coupon-counter": {
100
+ ...unsigned,
101
+ predicate: "conflict",
102
+ reason: "expanded_coupon_read_drift",
103
+ },
104
+ "H10-live-customer-sequence": {
105
+ ...unsigned,
106
+ predicate: "conflict",
107
+ reason: "billing_customer_full_read_drift",
108
+ },
109
+ };
110
+ const e = writer.baseline.original.attachRequest.preparation.expected;
111
+ const query = new URLSearchParams([
112
+ ["expand[0]", "discounts"],
113
+ ["expand[1]", "items.data.discounts"],
114
+ ["expand[2]", "items.data.price"],
115
+ ]);
116
+ const rows = [
117
+ {
118
+ resource: "schedule",
119
+ path:
120
+ "/v1/subscription_schedules/" + encodeURIComponent(reads.schedule.id),
121
+ body: reads.schedule,
122
+ },
123
+ {
124
+ resource: "subscription",
125
+ path:
126
+ "/v1/subscriptions/" +
127
+ encodeURIComponent(e.subscriptionId) +
128
+ "?" +
129
+ query,
130
+ body: reads.subscription,
131
+ },
132
+ {
133
+ resource: "price",
134
+ path: "/v1/prices/" + encodeURIComponent(e.targetPriceId),
135
+ body: reads.targetPrice,
136
+ },
137
+ {
138
+ resource: "customer",
139
+ path: "/v1/customers/" + encodeURIComponent(reads.billingCustomer.id),
140
+ body: reads.billingCustomer,
141
+ },
142
+ ...reads.coupons.map((coupon) => ({
143
+ resource: "coupon",
144
+ path: "/v1/coupons/" + encodeURIComponent(coupon.id),
145
+ body: coupon,
146
+ })),
147
+ ];
148
+ return deepFreeze({
149
+ controlCase,
150
+ writerMode,
151
+ writer,
152
+ reads,
153
+ historyPhaseCount: controlCase === "H03-history-onephase" ? 1 : 2,
154
+ expectedObservation: results[controlCase],
155
+ expectedWithoutReceipt: {
156
+ ...unsigned,
157
+ predicate: "unknown",
158
+ reason: "future_duration_not_bound",
159
+ },
160
+ observedAt: Math.floor(writer.writeAt / 1000),
161
+ rows: rows.map((row, i) => ({
162
+ ...row,
163
+ ordinal: i + 1,
164
+ options: {
165
+ apiVersion: writer.baseline.apiVersion,
166
+ maxNetworkRetries: 0 as const,
167
+ },
168
+ })),
169
+ } as const);
170
+ }