@fantastic.dev/better-stripe 0.97.0 → 0.98.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 (74) 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 +5 -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 +38 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts +11 -0
  8. package/dist/client/billing/renewalAttach/internal/material/classifiers.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/material/classifiers.js +57 -22
  10. package/dist/client/billing/renewalAttach/internal/material/classifiers.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +54 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +44 -37
  14. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts +21 -0
  16. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.d.ts.map +1 -0
  17. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js +36 -0
  18. package/dist/client/billing/renewalAttach/internal/operations/initialActorData.js.map +1 -0
  19. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +3 -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 +71 -46
  22. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +1 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -1
  25. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +17 -5
  26. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -1
  27. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts +35 -0
  28. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.d.ts.map +1 -0
  29. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js +46 -0
  30. package/dist/client/billing/renewalAttach/internal/operations/transportCapture.js.map +1 -0
  31. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +8 -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 +21 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  35. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
  36. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  37. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +3 -0
  38. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  39. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +65 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +161 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -0
  43. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +4 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -1
  45. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +24 -3
  46. package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -1
  47. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  48. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  49. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  50. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  51. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  52. package/dist/component/earnings/triggers.d.ts +16 -16
  53. package/dist/component/payoutRelease/queries.d.ts +2 -2
  54. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  55. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  56. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  57. package/docs/renewal-context-reads.md +35 -4
  58. package/package.json +1 -1
  59. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +42 -0
  60. package/src/client/billing/renewalAttach/internal/material/classifiers.ts +64 -22
  61. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +55 -48
  62. package/src/client/billing/renewalAttach/internal/operations/initialActorData.ts +41 -0
  63. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +91 -55
  64. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +23 -5
  65. package/src/client/billing/renewalAttach/internal/operations/transportCapture.ts +60 -0
  66. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +25 -0
  67. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +3 -0
  68. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +175 -0
  69. package/src/client/billing/renewalAttach/internal/producer/producerAcquisition.integration.test.ts +240 -0
  70. package/src/client/billing/renewalAttach/internal/producer/producerActor.integration.test.ts +526 -0
  71. package/src/client/billing/renewalAttach/internal/producer/producerMaterial.integration.test.ts +251 -0
  72. package/src/client/billing/renewalAttach/internal/producer/producerTransport.integration.test.ts +440 -0
  73. package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +29 -5
  74. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +100 -11
@@ -3,21 +3,45 @@ import { readInitialLineage } from "./lineageAuthority.js";
3
3
  import { ownerForInitialLineage } from "./ownerFactory.js";
4
4
  import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
5
5
 
6
+ function stockCall(token: object) {
7
+ const lineage = readInitialLineage(token);
8
+ const owner = ownerForInitialLineage(token);
9
+ return Object.freeze({
10
+ owner,
11
+ call(args: Parameters<Stripe["rawRequest"]>) {
12
+ return Reflect.apply(lineage.method, lineage.client, args) as ReturnType<
13
+ Stripe["rawRequest"]
14
+ >;
15
+ },
16
+ });
17
+ }
18
+
19
+ /** Transport kernels keep the original SDK promise and guard their continuation. */
20
+ export function captureInitialStockRawDelegate(
21
+ token: object,
22
+ ): Readonly<{ rawRequest: Stripe["rawRequest"] }> {
23
+ if (arguments.length !== 1) throw Error("INITIAL_OPERATION_UNBOUND");
24
+ const binding = stockCall(token);
25
+ return Object.freeze({
26
+ rawRequest(...args: Parameters<Stripe["rawRequest"]>) {
27
+ binding.owner.check();
28
+ return binding.call(args);
29
+ },
30
+ });
31
+ }
32
+
6
33
  /** Fixed selected client and original receiver; no replacement-client parameter. */
7
34
  export function stockDelegateForInitialLineage(token: object): Readonly<{
8
35
  rawRequest: Stripe["rawRequest"];
9
36
  }> {
10
- const lineage = readInitialLineage(token);
11
- const owner = ownerForInitialLineage(token);
37
+ const { owner, call } = stockCall(token);
12
38
  const owned = ownedAwaitForInitialLineage(token);
13
39
  return Object.freeze({
14
40
  rawRequest(
15
41
  ...args: Parameters<Stripe["rawRequest"]>
16
42
  ): ReturnType<Stripe["rawRequest"]> {
17
43
  owner.check();
18
- return owned(() =>
19
- Reflect.apply(lineage.method, lineage.client, args),
20
- ) as ReturnType<Stripe["rawRequest"]>;
44
+ return owned(() => call(args)) as ReturnType<Stripe["rawRequest"]>;
21
45
  },
22
46
  });
23
47
  }
@@ -14,6 +14,7 @@ import {
14
14
  codecFixture,
15
15
  } from "../../../../../component/renewalOperations/timingPolicy.fixtures.js";
16
16
  import { createClassActionOperationJournal } from "../operationJournal.js";
17
+ import type { RetainedInput } from "../material/capture.js";
17
18
  import {
18
19
  prepareRenewalPriceReplacementV2,
19
20
  prepareRenewalScheduleAttachmentV2,
@@ -35,6 +36,10 @@ export async function initialOperations(
35
36
  endWallMs?: number;
36
37
  afterBind?: () => Promise<void>;
37
38
  afterAppend?: () => Promise<void>;
39
+ afterRetain?: () => Promise<void>;
40
+ source?: RetainedInput;
41
+ sources?: readonly RetainedInput[];
42
+ keys?: readonly string[];
38
43
  } = {},
39
44
  ) {
40
45
  const h = await codecFixture();
@@ -76,16 +81,88 @@ export async function initialOperations(
76
81
  h.record.timingPolicy.workEndWallMs = options.workEndWallMs;
77
82
  if (options.endWallMs !== undefined)
78
83
  h.record.timingPolicy.endWallMs = options.endWallMs;
84
+ const source = options.source?.attachRequest ?? h.record.attachRequest;
85
+ const prepared = await prepareRenewalPriceReplacementV2(source.preparation);
86
+ const request = await prepareRenewalScheduleAttachmentV2({
87
+ prepared,
88
+ apiVersion: source.apiVersion,
89
+ attachKey: source.attachKey,
90
+ firstDispatchedAt: source.firstDispatchedAt,
91
+ });
92
+ const record = {
93
+ ...h.record,
94
+ attachRequest: source,
95
+ originalBundle: options.source?.originalBundle ?? h.record.originalBundle,
96
+ requestBinding: request.requestIdentity.binding,
97
+ dispatch: {
98
+ scope: request.scope,
99
+ apiVersion: request.apiVersion,
100
+ method: request.method,
101
+ path: request.path,
102
+ payload: request.payload,
103
+ key: request.key,
104
+ firstDispatchedAt: request.firstDispatchedAt,
105
+ },
106
+ timingPolicy: {
107
+ ...h.record.timingPolicy,
108
+ firstDispatchedAt: source.firstDispatchedAt,
109
+ periodStart: prepared.expected.periodStart,
110
+ periodEnd: prepared.expected.periodEnd,
111
+ },
112
+ };
113
+ assert(!options.sources || options.sources.length === count);
114
+ assert(!options.keys || options.keys.length === count);
115
+ const records = options.sources
116
+ ? await Promise.all(
117
+ options.sources.map(async (original) => {
118
+ const raw = original.attachRequest;
119
+ const prepared = await prepareRenewalPriceReplacementV2(
120
+ raw.preparation,
121
+ );
122
+ const request = await prepareRenewalScheduleAttachmentV2({
123
+ prepared,
124
+ apiVersion: raw.apiVersion,
125
+ attachKey: raw.attachKey,
126
+ firstDispatchedAt: raw.firstDispatchedAt,
127
+ });
128
+ return {
129
+ ...record,
130
+ attachRequest: raw,
131
+ originalBundle: original.originalBundle,
132
+ requestBinding: request.requestIdentity.binding,
133
+ dispatch: {
134
+ scope: request.scope,
135
+ apiVersion: request.apiVersion,
136
+ method: request.method,
137
+ path: request.path,
138
+ payload: request.payload,
139
+ key: request.key,
140
+ firstDispatchedAt: request.firstDispatchedAt,
141
+ },
142
+ timingPolicy: {
143
+ ...record.timingPolicy,
144
+ firstDispatchedAt: raw.firstDispatchedAt,
145
+ periodStart: prepared.expected.periodStart,
146
+ periodEnd: prepared.expected.periodEnd,
147
+ },
148
+ };
149
+ }),
150
+ )
151
+ : null;
79
152
  const sdk = new BetterStripe(components.betterStripe, {
80
153
  STRIPE_SECRET_KEY: "sk_test_invalid_owner_core",
81
154
  });
155
+ const sdks = options.keys?.map(
156
+ (key) =>
157
+ new BetterStripe(components.betterStripe, { STRIPE_SECRET_KEY: key }),
158
+ );
82
159
  const refs = components.betterStripe.renewalOperations;
83
160
  const host = {
84
161
  run: actionGeneric({
85
162
  args: {},
86
163
  handler: async (ctx): Promise<null> => {
87
164
  const runMutation = ctx.runMutation;
88
- if (options.afterBind || options.afterAppend)
165
+ if (options.afterBind || options.afterAppend || options.afterRetain)
89
166
  ctx.runMutation = async (ref, ...args) => {
90
167
  const result = await runMutation(ref, ...args);
91
168
  if (
@@ -102,35 +179,47 @@ export async function initialOperations(
102
179
  options.afterAppend
103
180
  )
104
181
  await options.afterAppend();
182
+ if (
183
+ getFunctionAddress(ref).reference?.endsWith(
184
+ "/retainProviderAcknowledgement",
185
+ ) &&
186
+ options.afterRetain
187
+ )
188
+ await options.afterRetain();
105
189
  return result;
106
190
  };
107
191
  await Promise.all(
108
192
  Array.from({ length: count }, async (_, index) => {
193
+ const current = records?.[index] ?? record;
194
+ const selectedSDK = sdks?.[index] ?? sdk;
109
195
  const logicalOperationId =
110
- h.record.logicalOperationId + "-owner-" + index;
111
- const recordJSON = canonical({ ...h.record, logicalOperationId });
196
+ current.logicalOperationId + "-owner-" + index;
197
+ const recordJSON = canonical({ ...current, logicalOperationId });
112
198
  const created = await ctx.runMutation(
113
199
  refs.mutations.createAuthorizedOperation,
114
200
  {
115
- authorizationScope: h.record.authorization.scope,
116
- authorizationRevision: h.record.authorization.revision,
201
+ authorizationScope: current.authorization.scope,
202
+ authorizationRevision: current.authorization.revision,
117
203
  logicalOperationId,
118
204
  recordJSON,
119
205
  },
120
206
  );
121
207
  assert(created.status === "created");
122
- const journal = await createClassActionOperationJournal(sdk, {
123
- actualActionCtx: ctx,
124
- operationId: created.operationId,
125
- });
208
+ const journal = await createClassActionOperationJournal(
209
+ selectedSDK,
210
+ {
211
+ actualActionCtx: ctx,
212
+ operationId: created.operationId,
213
+ },
214
+ );
126
215
  const fresh = await journal.reserveFreshAttempt({
127
216
  expectedRevision: 0,
128
217
  stage: "attach",
129
- expectedRequestBinding: h.record.requestBinding,
218
+ expectedRequestBinding: current.requestBinding,
130
219
  recordJSON,
131
220
  });
132
221
  assert(fresh.result.disposition === "acquired" && fresh.call);
133
- await work({ journal, fresh, sdk, index });
222
+ await work({ journal, fresh, sdk: selectedSDK, index });
134
223
  }),
135
224
  );
136
225
  return null;