@fantastic.dev/better-stripe 0.98.0 → 0.99.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 (93) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +6 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +1 -1
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
  10. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
  14. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +9 -11
  16. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +3 -380
  18. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +138 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +64 -139
  22. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
  26. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +2 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +6 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
  36. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -1
  37. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +3 -2
  38. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -1
  39. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
  43. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
  47. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
  48. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
  49. package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
  50. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
  51. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
  52. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
  53. package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
  54. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
  55. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
  56. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
  57. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
  58. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
  59. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
  60. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
  61. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
  62. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
  63. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  64. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  65. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  66. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  67. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  68. package/dist/component/earnings/triggers.d.ts +16 -16
  69. package/dist/component/payoutRelease/queries.d.ts +2 -2
  70. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  71. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  72. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  73. package/docs/renewal-context-reads.md +44 -3
  74. package/package.json +1 -1
  75. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +3 -3
  76. package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
  77. package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
  78. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +4 -498
  79. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +83 -160
  80. package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
  81. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +6 -0
  82. package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
  83. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +3 -2
  84. package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
  85. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
  86. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
  87. package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
  88. package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
  89. package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
  90. package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
  91. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
  92. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
  93. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +14 -1
@@ -19,7 +19,7 @@ import {
19
19
  } from "./types.js";
20
20
  import { equal } from "../../../renewalAggregate/shared.js";
21
21
  import { owned as legacyOwned, ownedForInitialLineage } from "./ownedAwait.js";
22
- import type { Diagnostics } from "./providerFailure.js";
22
+ import { captureActorFailureControl } from "./actorFailureControl.js";
23
23
  import { bindRawAcquisitionFromSource } from "../acquisition/ownedAcquisition.js";
24
24
  import { createAttachEventCompiler } from "../c10/attachEvents.js";
25
25
  import {
@@ -40,8 +40,51 @@ import { createInitialTransportForLineage } from "./fixedTransport.js";
40
40
  import { createInitialMaterialClassifiers } from "../material/classifiers.js";
41
41
  import { acquisitionForInitialLineage } from "../acquisition/ownedAcquisition.js";
42
42
  import { createInitialAttachEventCompiler } from "../c10/attachEvents.js";
43
+ import { journalWorkForInitialLineage } from "../producer/journalWorkFactory.js";
43
44
  type Pair = ReturnType<typeof createPair>;
44
45
 
46
+ type AttemptCustody = {
47
+ entry: unknown;
48
+ retainedPredicate: SourceMethod;
49
+ freshPredicate: SourceMethod;
50
+ originalRecord: unknown;
51
+ raw: ReturnType<typeof captureRetainedInput>["attachRequest"];
52
+ prepared: Awaited<ReturnType<typeof c1>>;
53
+ request: AttachRequest;
54
+ pair: Pair;
55
+ response: Readonly<{ body: unknown; status: number }> | null;
56
+ settled: boolean;
57
+ returnedACK: boolean;
58
+ reserved: boolean;
59
+ };
60
+ const attempts = new WeakMap<object, AttemptCustody>();
61
+ /** Consumes only actual settled attempt custody; stored DATA cannot register it. */
62
+ export function takeInitialRecoveryRecord(token: object) {
63
+ need(arguments.length === 1);
64
+ const owner = ownerForInitialLineage(token);
65
+ owner.check();
66
+ const attempt = attempts.get(token);
67
+ need(attempt && attempt.settled && !attempt.returnedACK && !attempt.reserved);
68
+ need(journalWorkForInitialLineage(token).idle());
69
+ const disposition = attempt.pair.transport.postDisposition();
70
+ need(
71
+ disposition === "REJECTED" ||
72
+ disposition === "FULFILLED_SAFE" ||
73
+ disposition === "FULFILLED_UNVERIFIED",
74
+ );
75
+ attempt.reserved = true;
76
+ return Object.freeze({
77
+ entry: attempt.entry,
78
+ retainedPredicate: attempt.retainedPredicate,
79
+ freshPredicate: attempt.freshPredicate,
80
+ originalRecord: attempt.originalRecord,
81
+ raw: attempt.raw,
82
+ prepared: attempt.prepared,
83
+ request: attempt.request,
84
+ response: attempt.response,
85
+ });
86
+ }
87
+
45
88
  /** Internal single-use actor. Empty class registry precedes every Source side effect. */
46
89
  export function captureInitialAttach() {
47
90
  need(arguments.length === 0);
@@ -96,6 +139,7 @@ function initialKernel(token: object | null) {
96
139
  input.observedAt,
97
140
  );
98
141
  };
142
+ let attempt: AttemptCustody | undefined;
99
143
  let pair: Pair | null = null,
100
144
  failureControl: FailureControl | null = null,
101
145
  postEligible = false;
@@ -168,7 +212,11 @@ function initialKernel(token: object | null) {
168
212
  OWNER.check();
169
213
  if (retained.status !== "classified")
170
214
  return refuse("retained_material_unsupported");
171
- const matches: { raw: unknown; fresh: SourceMethod }[] = [];
215
+ const matches: {
216
+ raw: unknown;
217
+ fresh: SourceMethod;
218
+ retained: SourceMethod;
219
+ }[] = [];
172
220
  for (const entry of ENTRIES) {
173
221
  OWNER.check();
174
222
  const retainedPredicate = sourceMethod(entry, "coversRetained"),
@@ -179,7 +227,11 @@ function initialKernel(token: object | null) {
179
227
  original.originalBundle,
180
228
  ]) === true
181
229
  )
182
- matches.push({ raw: entry, fresh: freshPredicate });
230
+ matches.push({
231
+ raw: entry,
232
+ fresh: freshPredicate,
233
+ retained: retainedPredicate,
234
+ });
183
235
  OWNER.check();
184
236
  }
185
237
  if (matches.length !== 1) return refuse("retained_class_not_unique");
@@ -202,163 +254,7 @@ function initialKernel(token: object | null) {
202
254
 
203
255
  const activePair = pair;
204
256
  // Only this invocation's pair and actual locally rebuilt C2 enter this capsule.
205
- const control = (() => {
206
- const capability = activePair.capability,
207
- takeQuarantine = capability.takeFulfilledQuarantine;
208
- Object.freeze(request.payload);
209
- Object.freeze(request.requestIdentity);
210
- Object.freeze(request);
211
- OWNER.check();
212
- type Token = {
213
- invocation: object;
214
- phase: "read" | "post";
215
- ordinal: number;
216
- request: AttachRequest;
217
- diagnostics: Diagnostics;
218
- };
219
- const tokens = new WeakMap<object, Token>(),
220
- invocation = Object.freeze({});
221
- let phase = "unused";
222
- const tokenValue = (error: unknown) =>
223
- error !== null &&
224
- (typeof error === "object" || typeof error === "function")
225
- ? tokens.get(error)
226
- : undefined;
227
- function consume(error: unknown, kind: "read" | "post") {
228
- OWNER.check();
229
- const value = tokenValue(error);
230
- if (
231
- error !== null &&
232
- (typeof error === "object" || typeof error === "function")
233
- )
234
- tokens.delete(error);
235
- if (
236
- !value ||
237
- value.invocation !== invocation ||
238
- value.phase !== kind ||
239
- phase !== (kind === "read" ? "failed" : "failed_post")
240
- )
241
- return null;
242
- phase = kind === "read" ? "consumed" : "consumed_post";
243
- const failure = Object.freeze({
244
- category: "provider_rejected",
245
- phase: kind,
246
- ordinal: value.ordinal,
247
- request: value.request,
248
- diagnostics: value.diagnostics,
249
- outcome: "unknown",
250
- operationalAuthority: false,
251
- });
252
- const out = Error("INITIAL_PROVIDER_REJECTED");
253
- Object.defineProperty(out, "failure", {
254
- value: failure,
255
- enumerable: false,
256
- writable: false,
257
- configurable: false,
258
- });
259
- return out;
260
- }
261
- return Object.freeze({
262
- takePostQuarantine(...args: unknown[]) {
263
- if (args.length !== 0) return null;
264
- return Reflect.apply(takeQuarantine, capability, []) as
265
- object | null;
266
- },
267
- begin() {
268
- OWNER.check();
269
- if (phase !== "unused") stop();
270
- if (capability.assertVirginAcquisition() !== true) {
271
- phase = "closed";
272
- stop();
273
- }
274
- OWNER.check();
275
- phase = "acquiring";
276
- },
277
- complete() {
278
- OWNER.check();
279
- if (phase !== "acquiring") stop();
280
- phase = "complete";
281
- },
282
- takeReadFailure() {
283
- OWNER.check();
284
- if (phase !== "acquiring") stop();
285
- const record = capability.consumeReadCatch();
286
- OWNER.check();
287
- if (record === null) {
288
- phase = "unsupported";
289
- return null;
290
- }
291
- need(
292
- record.phase === "read" &&
293
- Number.isSafeInteger(record.ordinal) &&
294
- record.ordinal >= 1 &&
295
- record.ordinal <= 43,
296
- );
297
- const token = Object.freeze(Object.create(null)) as object;
298
- tokens.set(
299
- token,
300
- Object.freeze({
301
- invocation,
302
- phase: "read",
303
- ordinal: record.ordinal,
304
- request,
305
- diagnostics: record.diagnostics,
306
- }),
307
- );
308
- phase = "failed";
309
- return token;
310
- },
311
- beginPost() {
312
- OWNER.check();
313
- if (phase !== "complete") stop();
314
- phase = "posting";
315
- },
316
- takePostFailure(actualReply: unknown) {
317
- OWNER.check();
318
- if (phase !== "posting") stop();
319
- const record = capability.consumePostCatch(actualReply);
320
- OWNER.check();
321
- if (record === null) {
322
- phase = "post_without_token";
323
- return null;
324
- }
325
- need(
326
- record.phase === "post" &&
327
- Number.isSafeInteger(record.ordinal) &&
328
- record.ordinal >= 1 &&
329
- record.ordinal <= 44,
330
- );
331
- const token = Object.freeze(Object.create(null)) as object;
332
- tokens.set(
333
- token,
334
- Object.freeze({
335
- invocation,
336
- phase: "post",
337
- ordinal: record.ordinal,
338
- request,
339
- diagnostics: record.diagnostics,
340
- }),
341
- );
342
- phase = "failed_post";
343
- return token;
344
- },
345
- forward(error: unknown) {
346
- OWNER.check();
347
- const value = tokenValue(error);
348
- return value &&
349
- value.invocation === invocation &&
350
- (phase === "failed" || phase === "failed_post")
351
- ? (error as object)
352
- : null;
353
- },
354
- consume(error: unknown) {
355
- return consume(error, "read");
356
- },
357
- consumePost(error: unknown) {
358
- return consume(error, "post");
359
- },
360
- });
361
- })();
257
+ const control = captureActorFailureControl(OWNER, activePair, request);
362
258
  OWNER.check();
363
259
  failureControl = control;
364
260
  const reader =
@@ -483,6 +379,28 @@ function initialKernel(token: object | null) {
483
379
  );
484
380
  OWNER.check();
485
381
  postEligible = true;
382
+ if (token !== null) {
383
+ attempt = {
384
+ entry: entry.raw,
385
+ retainedPredicate: entry.retained,
386
+ freshPredicate: entry.fresh,
387
+ originalRecord: {
388
+ originalRaw: original,
389
+ originalPrepared: prepared,
390
+ completeRequest: request,
391
+ retainedMaterial: retained.material,
392
+ },
393
+ raw,
394
+ prepared,
395
+ request,
396
+ pair: activePair,
397
+ response: null,
398
+ settled: false,
399
+ returnedACK: false,
400
+ reserved: false,
401
+ };
402
+ attempts.set(token, attempt);
403
+ }
486
404
  let postedOnce = false;
487
405
  const post = async () => {
488
406
  OWNER.check();
@@ -503,6 +421,8 @@ function initialKernel(token: object | null) {
503
421
  if (reply.outcome === "provider_rejected") stop();
504
422
  if (reply.outcome !== "fulfilled_safe") return uncertain();
505
423
  const body = reply.body;
424
+ if (attempt)
425
+ attempt.response = Object.freeze({ body, status: reply.statusCode });
506
426
  await owned(() =>
507
427
  compiler.response({
508
428
  event: "response",
@@ -537,6 +457,7 @@ function initialKernel(token: object | null) {
537
457
  const result = admitInitialOutput(receipt, prepared, request);
538
458
  OWNER.check();
539
459
  control.takePostQuarantine();
460
+ if (attempt) attempt.returnedACK = true;
540
461
  return result;
541
462
  } catch (error) {
542
463
  let live = false;
@@ -565,6 +486,8 @@ function initialKernel(token: object | null) {
565
486
  if (state === "NOT_STARTED") return refuse("post_not_started");
566
487
  }
567
488
  return stop();
489
+ } finally {
490
+ if (attempt) attempt.settled = true;
568
491
  }
569
492
  },
570
493
  });