@fantastic.dev/better-stripe 0.102.0 → 0.104.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 (65) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts +7 -0
  4. package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js +13 -1
  6. package/dist/client/billing/renewalAttach/internal/c10/appendAck.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts +23 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js +34 -2
  10. package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
  14. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
  16. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
  18. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
  20. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
  22. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
  24. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
  26. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +3 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +25 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +6 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +49 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts +16 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts.map +1 -0
  37. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js +117 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js.map +1 -0
  39. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  40. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  41. package/dist/component/balanceFunding/mutations.d.ts +27 -27
  42. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  43. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  44. package/dist/component/earnings/triggers.d.ts +16 -16
  45. package/dist/component/payoutRelease/queries.d.ts +2 -2
  46. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  47. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  48. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  49. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  50. package/docs/renewal-context-reads.md +72 -4
  51. package/package.json +1 -1
  52. package/src/client/billing/renewalAttach/internal/c10/appendAck.ts +17 -0
  53. package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +45 -2
  54. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
  55. package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
  56. package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
  57. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
  58. package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +40 -0
  59. package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +53 -0
  60. package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
  61. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannelControls.integration.test.ts +542 -0
  62. package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannels.integration.test.ts +321 -0
  63. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
  64. package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
  65. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +89 -5
@@ -108,8 +108,9 @@ const child = (node: Node, key: string): Node => {
108
108
  need(row);
109
109
  return row[1];
110
110
  };
111
- export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
112
- OWNER.check();
111
+ export function capturePreflightRecordDATA(
112
+ raw: unknown,
113
+ ): CapturedPreflightRecord {
113
114
  const captured = capture(raw, false);
114
115
  const configuration = freeze(
115
116
  materialize(child(captured.node, "configuration")),
@@ -117,7 +118,6 @@ export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
117
118
  originalBundle = freeze(
118
119
  materialize(child(captured.node, "originalBundle")),
119
120
  ) as Bundle;
120
- OWNER.check();
121
121
  return Object.freeze({ captured, configuration, originalBundle });
122
122
  }
123
123
 
@@ -125,3 +125,11 @@ export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
125
125
  export function capturePreflightOutput(value: unknown): CapturedRecord {
126
126
  return capture(value, true);
127
127
  }
128
+
129
+ /** Legacy Source wrapper; DATA capture alone grants no invocation custody. */
130
+ export function capturePreflightRecord(raw: unknown): CapturedPreflightRecord {
131
+ OWNER.check();
132
+ const captured = capturePreflightRecordDATA(raw);
133
+ OWNER.check();
134
+ return captured;
135
+ }
@@ -103,19 +103,17 @@ export function expectedSlots(
103
103
  ...Object.entries(record).filter(([k]) => k.startsWith("/request/")),
104
104
  ]);
105
105
  }
106
- export function verifyPreflightRecord(
106
+ export function verifyPreflightRecordDATA(
107
107
  captured: CapturedPreflightRecord,
108
108
  originalC6: ProjectedRenewalConfigurationV2,
109
109
  ackC3: RenewalScheduleAttachmentReceiptV2,
110
110
  ): PreflightRecord {
111
- OWNER.check();
112
111
  const expected = expectedSlots(originalC6, ackC3, false);
113
112
  for (const [path, value] of Object.entries(expected))
114
113
  need(captured.captured.slots.get(path) === value);
115
114
  const record = materialize(captured.captured.node) as PreflightRecord;
116
115
  need(equal(record.request, originalC6) && equal(record.attachReceipt, ackC3));
117
116
  verifyOriginalRaw(record, ackC3);
118
- OWNER.check();
119
117
  return freeze(record);
120
118
  }
121
119
  function association(value: unknown, id: string, configuration: Configuration) {
@@ -172,11 +170,10 @@ function verifyOriginalRaw(
172
170
  };
173
171
  rebuild(preconfigure);
174
172
  }
175
- export function verifyCurrentPreflight(
173
+ export function verifyCurrentPreflightDATA(
176
174
  record: PreflightRecord,
177
175
  evidence: CurrentEvidence,
178
176
  ) {
179
- OWNER.check();
180
177
  closed(evidence, ["bundle", "schedule", "observedAt"]);
181
178
  need(Number.isSafeInteger(evidence.observedAt) && evidence.observedAt >= 0);
182
179
  const c = record.configuration,
@@ -205,5 +202,23 @@ export function verifyCurrentPreflight(
205
202
  equal(b.derivedCouponJoins, o.derivedCouponJoins),
206
203
  );
207
204
  association(b.wireSubscription.schedule, record.attachReceipt.scheduleId, c);
205
+ }
206
+
207
+ export function verifyPreflightRecord(
208
+ captured: CapturedPreflightRecord,
209
+ originalC6: ProjectedRenewalConfigurationV2,
210
+ ackC3: RenewalScheduleAttachmentReceiptV2,
211
+ ): PreflightRecord {
212
+ OWNER.check();
213
+ const record = verifyPreflightRecordDATA(captured, originalC6, ackC3);
214
+ OWNER.check();
215
+ return record;
216
+ }
217
+ export function verifyCurrentPreflight(
218
+ record: PreflightRecord,
219
+ evidence: CurrentEvidence,
220
+ ): void {
221
+ OWNER.check();
222
+ verifyCurrentPreflightDATA(record, evidence);
208
223
  OWNER.check();
209
224
  }
@@ -0,0 +1,40 @@
1
+ import { readConfigureLineage } from "./configureLineage.js";
2
+ import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
3
+ import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
4
+ import {
5
+ requireConfigure,
6
+ checkOperationLoad,
7
+ checkEmptyConfigureHistory,
8
+ matchConfigureDATA,
9
+ } from "./configureJournalData.js";
10
+
11
+ /** Bounded read fence only, without an atomic lock against subsequent writes. */
12
+ export async function assertConfigurePreflightFrontier(token: object) {
13
+ requireConfigure(arguments.length === 1);
14
+ const lineage = readConfigureLineage(token),
15
+ work = journalWorkForConfigureLineage(token);
16
+ const owned = ownedAwaitForInitialLineage(lineage.parentToken);
17
+ async function checked<T>(call: () => T | PromiseLike<T>) {
18
+ readConfigureLineage(token);
19
+ requireConfigure(work.idle());
20
+ const reply = await owned(call);
21
+ readConfigureLineage(token);
22
+ requireConfigure(work.idle());
23
+ return reply;
24
+ }
25
+ checkOperationLoad(
26
+ await checked(() => lineage.journal.loadAuthorizedOperation()),
27
+ lineage.reservation,
28
+ lineage.parent.basisJSON,
29
+ );
30
+ matchConfigureDATA(
31
+ await checked(() => lineage.journal.readProviderAcknowledgement()),
32
+ null,
33
+ );
34
+ const history: unknown = await checked(() =>
35
+ lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
36
+ );
37
+ checkEmptyConfigureHistory(history, lineage.reservation);
38
+ requireConfigure(work.idle());
39
+ readConfigureLineage(token);
40
+ }
@@ -0,0 +1,53 @@
1
+ import { readConfigureLineage } from "./configureLineage.js";
2
+ import { requireConfigure } from "./configureJournalData.js";
3
+
4
+ const journals = new WeakMap<object, ReturnType<typeof construct>>();
5
+ function construct(token: object) {
6
+ const original = readConfigureLineage(token);
7
+ let pending = 0;
8
+ function gate() {
9
+ const current = readConfigureLineage(token);
10
+ requireConfigure(
11
+ current.journal === original.journal &&
12
+ current.originalReservation === original.originalReservation &&
13
+ current.owner === original.owner,
14
+ );
15
+ }
16
+ return Object.freeze({
17
+ captureSend() {
18
+ requireConfigure(arguments.length === 0);
19
+ gate();
20
+ // Original class-owned object custody; captured reservation DATA cannot send.
21
+ const send = original.journal.createC10Send(original.originalReservation);
22
+ return async (
23
+ record: Parameters<typeof send>[0],
24
+ ack: Parameters<typeof send>[1],
25
+ ) => {
26
+ gate();
27
+ pending++;
28
+ try {
29
+ await send(record, ack);
30
+ gate();
31
+ } finally {
32
+ pending--;
33
+ }
34
+ };
35
+ },
36
+ idle() {
37
+ requireConfigure(arguments.length === 0);
38
+ gate();
39
+ return pending === 0;
40
+ },
41
+ });
42
+ }
43
+ /** Actual RPC settlement is tracked independently of channel closure or timeout. */
44
+ export function journalWorkForConfigureLineage(token: object) {
45
+ requireConfigure(arguments.length === 1);
46
+ readConfigureLineage(token);
47
+ let work = journals.get(token);
48
+ if (!work) {
49
+ work = construct(token);
50
+ journals.set(token, work);
51
+ }
52
+ return work;
53
+ }
@@ -0,0 +1,170 @@
1
+ import { readConfigureLineage } from "./configureLineage.js";
2
+ import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
3
+ import { assertConfigurePreflightFrontier } from "./configureFrontier.js";
4
+ import { createAdmittedConfigureReadTransport } from "../operations/configureReadTransport.js";
5
+ import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
6
+ import {
7
+ projectRenewalConfigurationV2,
8
+ constructRenewalScheduleAttachmentReceiptV2,
9
+ } from "../../../renewalV2/index.js";
10
+ import {
11
+ verifyPreflightRecordDATA,
12
+ verifyCurrentPreflightDATA,
13
+ } from "../preflight/relations.js";
14
+ import { releasePreflightDATA } from "../preflight/output.js";
15
+ import { requireConfigure } from "./configureJournalData.js";
16
+ import { equal } from "../../../renewalAggregate/shared.js";
17
+ import type { PreflightOutput, PreflightRecord } from "../preflight/grammar.js";
18
+ import type { Bundle } from "../material/capture.js";
19
+
20
+ function matchesCurrentBundle(
21
+ value: unknown,
22
+ record: PreflightRecord,
23
+ ): value is Bundle {
24
+ return equal(value, {
25
+ ...record.originalBundle,
26
+ wireSubscription: record.configuration.freshSubscription,
27
+ });
28
+ }
29
+ const captures = new WeakSet<object>();
30
+ type PreflightView = Readonly<{
31
+ output: PreflightOutput;
32
+ originalEntry: unknown;
33
+ preflightEntry: unknown;
34
+ coversPreflight: unknown;
35
+ acknowledgement: ReturnType<
36
+ typeof createAdmittedConfigureReadTransport
37
+ >["acknowledgement"];
38
+ operationalAuthority: false;
39
+ }>;
40
+ const completions = new WeakMap<
41
+ object,
42
+ { view: PreflightView; guard: () => void }
43
+ >();
44
+ /** Actual admitted child only. This readonly consistency actor grants no write. */
45
+ export function captureAdmittedConfigurePreflight(token: object) {
46
+ requireConfigure(
47
+ typeof token === "object" && token !== null && !captures.has(token),
48
+ );
49
+ captures.add(token);
50
+ requireConfigure(arguments.length === 1);
51
+ const pair = createAdmittedConfigureReadTransport(token);
52
+ const lineage = readConfigureLineage(token),
53
+ owned = ownedAwaitForInitialLineage(lineage.parentToken);
54
+ let used = false,
55
+ closed = false;
56
+ function guard() {
57
+ requireConfigure(!closed);
58
+ try {
59
+ pair.guard();
60
+ } catch (error) {
61
+ closed = true;
62
+ throw error;
63
+ }
64
+ }
65
+ async function checked<T>(call: () => T | PromiseLike<T>) {
66
+ guard();
67
+ const result = await owned(call);
68
+ guard();
69
+ return result;
70
+ }
71
+ const actor = Object.freeze({
72
+ async invoke() {
73
+ requireConfigure(!used);
74
+ used = true;
75
+ requireConfigure(arguments.length === 0);
76
+ try {
77
+ guard();
78
+ await checked(() => assertConfigurePreflightFrontier(token));
79
+ const original = await checked(() =>
80
+ projectRenewalConfigurationV2(pair.retained.configuration),
81
+ );
82
+ requireConfigure(original.status === "projected_configure_request");
83
+ const ack = await checked(() =>
84
+ constructRenewalScheduleAttachmentReceiptV2(
85
+ pair.retained.configuration.attachReceipt,
86
+ ),
87
+ );
88
+ const record = verifyPreflightRecordDATA(pair.retained, original, ack);
89
+ await checked(() => assertConfigurePreflightFrontier(token));
90
+ guard();
91
+ const reader = createSelectedRawAcquisition(
92
+ lineage.owner,
93
+ pair.readTransport,
94
+ pair.scheduleId,
95
+ );
96
+ const acquired = await checked(() =>
97
+ reader.acquire(record.configuration.preparation.expected),
98
+ );
99
+ requireConfigure(acquired.ok);
100
+ requireConfigure(matchesCurrentBundle(acquired.bundle, record));
101
+ const evidence = Object.freeze({
102
+ bundle: acquired.bundle,
103
+ schedule: acquired.schedule,
104
+ observedAt: acquired.observedAt,
105
+ });
106
+ verifyCurrentPreflightDATA(record, evidence);
107
+ guard();
108
+ const configuration = {
109
+ ...record.configuration,
110
+ freshSubscription: evidence.bundle.wireSubscription,
111
+ targetPrice: evidence.bundle.wireTargetPrice,
112
+ ...(Object.prototype.hasOwnProperty.call(
113
+ record.configuration,
114
+ "billingCustomer",
115
+ )
116
+ ? { billingCustomer: evidence.bundle.wireBillingCustomer }
117
+ : {}),
118
+ schedule: evidence.schedule,
119
+ observedAt: evidence.observedAt,
120
+ };
121
+ const fresh = await checked(() =>
122
+ projectRenewalConfigurationV2(configuration),
123
+ );
124
+ requireConfigure(
125
+ fresh.status === "projected_configure_request" &&
126
+ equal(fresh, original) &&
127
+ equal(fresh, record.request),
128
+ );
129
+ requireConfigure(
130
+ Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
131
+ true,
132
+ );
133
+ guard();
134
+ const output = releasePreflightDATA(
135
+ record,
136
+ evidence,
137
+ fresh,
138
+ original,
139
+ ack,
140
+ );
141
+ await checked(() => assertConfigurePreflightFrontier(token));
142
+ guard();
143
+ completions.set(token, {
144
+ guard,
145
+ view: Object.freeze({
146
+ output,
147
+ originalEntry: pair.acknowledgement.originalEntry,
148
+ preflightEntry: pair.entry,
149
+ coversPreflight: pair.covers,
150
+ acknowledgement: pair.acknowledgement,
151
+ operationalAuthority: false as const,
152
+ }),
153
+ });
154
+ return output;
155
+ } catch (error) {
156
+ closed = true;
157
+ throw error;
158
+ }
159
+ },
160
+ });
161
+ return actor;
162
+ }
163
+ /** Actual completed return identity; copied output is never a registration input. */
164
+ export function readAdmittedConfigurePreflight(token: object) {
165
+ requireConfigure(arguments.length === 1);
166
+ const completed = completions.get(token);
167
+ requireConfigure(completed);
168
+ completed.guard();
169
+ return completed.view;
170
+ }