@fantastic.dev/better-stripe 0.98.0 → 0.100.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/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 +146 -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 +90 -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/attachAcknowledgement.d.ts +10 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.js +49 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +4 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  33. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +12 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  35. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
  39. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
  40. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -1
  41. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +3 -2
  42. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -1
  43. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +13 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +109 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
  47. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
  48. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
  49. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
  50. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
  51. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
  52. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
  53. package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
  54. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
  55. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
  56. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
  57. package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
  58. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
  59. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +12 -0
  60. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
  61. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +96 -156
  62. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
  63. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
  64. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
  65. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
  66. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
  67. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  68. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
  69. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  70. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  71. package/dist/component/balanceFunding/queries.d.ts +1 -1
  72. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  73. package/docs/renewal-context-reads.md +67 -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 +110 -160
  80. package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
  81. package/src/client/billing/renewalAttach/internal/producer/attachAcknowledgement.ts +65 -0
  82. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +14 -0
  83. package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
  84. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +3 -2
  85. package/src/client/billing/renewalAttach/internal/producer/producerAcknowledgement.integration.test.ts +320 -0
  86. package/src/client/billing/renewalAttach/internal/producer/producerAcknowledgementControls.integration.test.ts +411 -0
  87. package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
  88. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
  89. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
  90. package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +143 -0
  91. package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
  92. package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
  93. package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
  94. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +146 -188
  95. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
  96. 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,75 @@ 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
+ returnedOutput?: unknown;
59
+ reserved: boolean;
60
+ };
61
+ const attempts = new WeakMap<object, AttemptCustody>();
62
+ /** Exact successful return only; retained journal DATA never populates this reader. */
63
+ export function readInitialAttachAcknowledgement(token: object) {
64
+ need(arguments.length === 1);
65
+ readInitialLineage(token);
66
+ const attempt = attempts.get(token);
67
+ if (!attempt?.returnedACK || !attempt.settled) return null;
68
+ const owner = ownerForInitialLineage(token);
69
+ owner.check();
70
+ const output = attempt.returnedOutput;
71
+ const receipt = closed(output, [
72
+ "status",
73
+ "operationalAuthority",
74
+ "receipt",
75
+ ]).receipt;
76
+ owner.check();
77
+ return Object.freeze({
78
+ originalEntry: attempt.entry,
79
+ retainedPredicate: attempt.retainedPredicate,
80
+ freshPredicate: attempt.freshPredicate,
81
+ output,
82
+ receipt,
83
+ });
84
+ }
85
+ /** Consumes only actual settled attempt custody; stored DATA cannot register it. */
86
+ export function takeInitialRecoveryRecord(token: object) {
87
+ need(arguments.length === 1);
88
+ const owner = ownerForInitialLineage(token);
89
+ owner.check();
90
+ const attempt = attempts.get(token);
91
+ need(attempt && attempt.settled && !attempt.returnedACK && !attempt.reserved);
92
+ need(journalWorkForInitialLineage(token).idle());
93
+ const disposition = attempt.pair.transport.postDisposition();
94
+ need(
95
+ disposition === "REJECTED" ||
96
+ disposition === "FULFILLED_SAFE" ||
97
+ disposition === "FULFILLED_UNVERIFIED",
98
+ );
99
+ attempt.reserved = true;
100
+ return Object.freeze({
101
+ entry: attempt.entry,
102
+ retainedPredicate: attempt.retainedPredicate,
103
+ freshPredicate: attempt.freshPredicate,
104
+ originalRecord: attempt.originalRecord,
105
+ raw: attempt.raw,
106
+ prepared: attempt.prepared,
107
+ request: attempt.request,
108
+ response: attempt.response,
109
+ });
110
+ }
111
+
45
112
  /** Internal single-use actor. Empty class registry precedes every Source side effect. */
46
113
  export function captureInitialAttach() {
47
114
  need(arguments.length === 0);
@@ -96,6 +163,7 @@ function initialKernel(token: object | null) {
96
163
  input.observedAt,
97
164
  );
98
165
  };
166
+ let attempt: AttemptCustody | undefined;
99
167
  let pair: Pair | null = null,
100
168
  failureControl: FailureControl | null = null,
101
169
  postEligible = false;
@@ -168,7 +236,11 @@ function initialKernel(token: object | null) {
168
236
  OWNER.check();
169
237
  if (retained.status !== "classified")
170
238
  return refuse("retained_material_unsupported");
171
- const matches: { raw: unknown; fresh: SourceMethod }[] = [];
239
+ const matches: {
240
+ raw: unknown;
241
+ fresh: SourceMethod;
242
+ retained: SourceMethod;
243
+ }[] = [];
172
244
  for (const entry of ENTRIES) {
173
245
  OWNER.check();
174
246
  const retainedPredicate = sourceMethod(entry, "coversRetained"),
@@ -179,7 +251,11 @@ function initialKernel(token: object | null) {
179
251
  original.originalBundle,
180
252
  ]) === true
181
253
  )
182
- matches.push({ raw: entry, fresh: freshPredicate });
254
+ matches.push({
255
+ raw: entry,
256
+ fresh: freshPredicate,
257
+ retained: retainedPredicate,
258
+ });
183
259
  OWNER.check();
184
260
  }
185
261
  if (matches.length !== 1) return refuse("retained_class_not_unique");
@@ -202,163 +278,7 @@ function initialKernel(token: object | null) {
202
278
 
203
279
  const activePair = pair;
204
280
  // 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
- })();
281
+ const control = captureActorFailureControl(OWNER, activePair, request);
362
282
  OWNER.check();
363
283
  failureControl = control;
364
284
  const reader =
@@ -483,6 +403,28 @@ function initialKernel(token: object | null) {
483
403
  );
484
404
  OWNER.check();
485
405
  postEligible = true;
406
+ if (token !== null) {
407
+ attempt = {
408
+ entry: entry.raw,
409
+ retainedPredicate: entry.retained,
410
+ freshPredicate: entry.fresh,
411
+ originalRecord: {
412
+ originalRaw: original,
413
+ originalPrepared: prepared,
414
+ completeRequest: request,
415
+ retainedMaterial: retained.material,
416
+ },
417
+ raw,
418
+ prepared,
419
+ request,
420
+ pair: activePair,
421
+ response: null,
422
+ settled: false,
423
+ returnedACK: false,
424
+ reserved: false,
425
+ };
426
+ attempts.set(token, attempt);
427
+ }
486
428
  let postedOnce = false;
487
429
  const post = async () => {
488
430
  OWNER.check();
@@ -503,6 +445,8 @@ function initialKernel(token: object | null) {
503
445
  if (reply.outcome === "provider_rejected") stop();
504
446
  if (reply.outcome !== "fulfilled_safe") return uncertain();
505
447
  const body = reply.body;
448
+ if (attempt)
449
+ attempt.response = Object.freeze({ body, status: reply.statusCode });
506
450
  await owned(() =>
507
451
  compiler.response({
508
452
  event: "response",
@@ -537,6 +481,10 @@ function initialKernel(token: object | null) {
537
481
  const result = admitInitialOutput(receipt, prepared, request);
538
482
  OWNER.check();
539
483
  control.takePostQuarantine();
484
+ if (attempt) {
485
+ attempt.returnedOutput = result;
486
+ attempt.returnedACK = true;
487
+ }
540
488
  return result;
541
489
  } catch (error) {
542
490
  let live = false;
@@ -565,6 +513,8 @@ function initialKernel(token: object | null) {
565
513
  if (state === "NOT_STARTED") return refuse("post_not_started");
566
514
  }
567
515
  return stop();
516
+ } finally {
517
+ if (attempt) attempt.settled = true;
568
518
  }
569
519
  },
570
520
  });