@fantastic.dev/better-stripe 0.85.0 → 0.86.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 (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAggregate/configure.d.ts.map +1 -1
  4. package/dist/client/billing/renewalAggregate/configure.js +4 -56
  5. package/dist/client/billing/renewalAggregate/configure.js.map +1 -1
  6. package/dist/client/billing/renewalAggregate/configureMaterial.d.ts +29 -0
  7. package/dist/client/billing/renewalAggregate/configureMaterial.d.ts.map +1 -0
  8. package/dist/client/billing/renewalAggregate/configureMaterial.js +63 -0
  9. package/dist/client/billing/renewalAggregate/configureMaterial.js.map +1 -0
  10. package/dist/client/billing/renewalAggregate/phases.d.ts +2 -2
  11. package/dist/client/billing/renewalAggregate/phases.d.ts.map +1 -1
  12. package/dist/client/billing/renewalAggregate/phases.js.map +1 -1
  13. package/dist/client/billing/renewalAggregate/preflight.d.ts +1 -118
  14. package/dist/client/billing/renewalAggregate/preflight.d.ts.map +1 -1
  15. package/dist/client/billing/renewalAggregate/preflight.js +3 -118
  16. package/dist/client/billing/renewalAggregate/preflight.js.map +1 -1
  17. package/dist/client/billing/renewalAggregate/readMaterial.d.ts +335 -0
  18. package/dist/client/billing/renewalAggregate/readMaterial.d.ts.map +1 -0
  19. package/dist/client/billing/renewalAggregate/readMaterial.js +121 -0
  20. package/dist/client/billing/renewalAggregate/readMaterial.js.map +1 -0
  21. package/dist/client/billing/renewalV2/binding.d.ts +1 -1
  22. package/dist/client/billing/renewalV2/binding.d.ts.map +1 -1
  23. package/dist/client/billing/renewalV2/binding.js.map +1 -1
  24. package/dist/client/billing/renewalV2/configureInput.d.ts +45 -0
  25. package/dist/client/billing/renewalV2/configureInput.d.ts.map +1 -0
  26. package/dist/client/billing/renewalV2/configureInput.js +69 -0
  27. package/dist/client/billing/renewalV2/configureInput.js.map +1 -0
  28. package/dist/client/billing/renewalV2/index.d.ts +21 -0
  29. package/dist/client/billing/renewalV2/index.d.ts.map +1 -1
  30. package/dist/client/billing/renewalV2/index.js +80 -1
  31. package/dist/client/billing/renewalV2/index.js.map +1 -1
  32. package/dist/client/billing/renewalV2/receipt.d.ts +1 -0
  33. package/dist/client/billing/renewalV2/receipt.d.ts.map +1 -1
  34. package/dist/client/billing/renewalV2/receipt.js +3 -3
  35. package/dist/client/billing/renewalV2/receipt.js.map +1 -1
  36. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  37. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  38. package/dist/client/renewal.d.ts +2 -2
  39. package/dist/client/renewal.d.ts.map +1 -1
  40. package/dist/client/renewal.js +1 -1
  41. package/dist/client/renewal.js.map +1 -1
  42. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  43. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  44. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  45. package/dist/component/earnings/triggers.d.ts +16 -16
  46. package/dist/component/payoutRelease/queries.d.ts +2 -2
  47. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  48. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  49. package/docs/renewal-context-reads.md +6 -2
  50. package/docs/renewal-phase-assembly.md +73 -0
  51. package/package.json +1 -1
  52. package/src/client/billing/renewalAggregate/configure.ts +12 -79
  53. package/src/client/billing/renewalAggregate/configureMaterial.ts +122 -0
  54. package/src/client/billing/renewalAggregate/phases.ts +2 -2
  55. package/src/client/billing/renewalAggregate/preflight.ts +6 -161
  56. package/src/client/billing/renewalAggregate/readMaterial.ts +173 -0
  57. package/src/client/billing/renewalV2/binding.ts +7 -1
  58. package/src/client/billing/renewalV2/configure.test.ts +362 -0
  59. package/src/client/billing/renewalV2/configureInput.ts +84 -0
  60. package/src/client/billing/renewalV2/index.ts +124 -0
  61. package/src/client/billing/renewalV2/receipt.ts +3 -3
  62. package/src/client/renewal.ts +4 -0
@@ -10,13 +10,23 @@ import {
10
10
  timestamp,
11
11
  resourceId,
12
12
  equal,
13
+ conflict,
14
+ failure,
15
+ type Failure,
13
16
  } from "../renewalAggregate/shared.js";
17
+ import { validateReadMaterial } from "../renewalAggregate/readMaterial.js";
18
+ import {
19
+ configureMaterial,
20
+ validateConfigureStart,
21
+ } from "../renewalAggregate/configureMaterial.js";
22
+ import type { ProjectedRenewalConfiguration } from "../renewalAggregate/configure.js";
14
23
  import { idempotencyOptions } from "../../core/idempotency.js";
15
24
  import { renewalBindingV2 } from "./binding.js";
16
25
  import {
17
26
  captureAttachmentReceipt,
18
27
  assertAttachmentIdentity,
19
28
  } from "./receipt.js";
29
+ import { captureConfiguration } from "./configureInput.js";
20
30
 
21
31
  export type PrepareRenewalPriceReplacementV2Options =
22
32
  PrepareRenewalPriceReplacementOptions;
@@ -212,3 +222,117 @@ export async function constructRenewalScheduleAttachmentReceiptV2(
212
222
  binding: await renewalBindingV2("renewal-attach-receipt", receipt),
213
223
  };
214
224
  }
225
+
226
+ export type ProjectRenewalConfigurationV2Options = {
227
+ preparation: PrepareRenewalPriceReplacementV2Options;
228
+ /** Raw attachment inputs, not a stored receipt or caller verification handle. */
229
+ attachReceipt: ConstructRenewalScheduleAttachmentReceiptV2Options;
230
+ freshSubscription: unknown;
231
+ targetPrice: unknown;
232
+ billingCustomer?: unknown;
233
+ schedule: unknown;
234
+ apiVersion: string;
235
+ observedAt: number;
236
+ firstDispatchedAt: number;
237
+ configureKey: string;
238
+ };
239
+ export type ProjectedRenewalConfigurationV2 = Omit<
240
+ ProjectedRenewalConfiguration,
241
+ "version"
242
+ > & { version: 2 };
243
+ export type RenewalConfigurationProjectionFailure = Failure;
244
+
245
+ /** Pure raw-only configuration candidate; provider qualification remains required. */
246
+ export async function projectRenewalConfigurationV2(
247
+ options: ProjectRenewalConfigurationV2Options,
248
+ ): Promise<
249
+ ProjectedRenewalConfigurationV2 | RenewalConfigurationProjectionFailure
250
+ > {
251
+ const args = captureConfiguration(options);
252
+ let ownedScheduleId: string | undefined;
253
+ try {
254
+ if (!equal(args.preparation, args.attachReceipt.attachRequest.preparation))
255
+ conflict("invalid_prepared_binding");
256
+ let prepared: PreparedRenewalPriceReplacementV2;
257
+ try {
258
+ prepared = await prepareRenewalPriceReplacementV2({
259
+ ...args.preparation,
260
+ expected: args.preparation
261
+ .expected as PrepareRenewalPriceReplacementOptions["expected"],
262
+ });
263
+ } catch {
264
+ conflict("invalid_prepared_binding");
265
+ }
266
+ let receipt: RenewalScheduleAttachmentReceiptV2;
267
+ try {
268
+ receipt = await constructRenewalScheduleAttachmentReceiptV2(
269
+ args.attachReceipt as ConstructRenewalScheduleAttachmentReceiptV2Options,
270
+ );
271
+ } catch {
272
+ conflict("invalid_attach_receipt_binding");
273
+ }
274
+ if (
275
+ receipt.logicalBinding !== prepared.requestIdentity.binding ||
276
+ receipt.request.logicalBinding !== prepared.requestIdentity.binding ||
277
+ receipt.request.apiVersion !== args.apiVersion ||
278
+ receipt.request.payload.from_subscription !==
279
+ prepared.expected.subscriptionId ||
280
+ receipt.subscriptionId !== prepared.expected.subscriptionId ||
281
+ receipt.customerAccountId !== prepared.expected.customerAccountId ||
282
+ receipt.livemode !== prepared.expected.livemode ||
283
+ receipt.request.firstDispatchedAt > args.observedAt
284
+ )
285
+ conflict("invalid_attach_receipt_binding");
286
+ ownedScheduleId = receipt.scheduleId;
287
+ const key = validateConfigureStart(args, receipt);
288
+ const reads = validateReadMaterial(args, prepared, receipt.scheduleId);
289
+ const { schedule, payload } = configureMaterial(
290
+ // Unlike V1's record parser, retain every own key of the captured body.
291
+ z
292
+ .custom<Record<string, unknown>>(
293
+ (value) =>
294
+ value !== null &&
295
+ typeof value === "object" &&
296
+ !Array.isArray(value),
297
+ )
298
+ .parse(args.schedule),
299
+ prepared,
300
+ receipt,
301
+ reads,
302
+ );
303
+ const request = {
304
+ version: 2 as const,
305
+ stage: "configure" as const,
306
+ scope: "platform" as const,
307
+ apiVersion: args.apiVersion,
308
+ logicalBinding: prepared.requestIdentity.binding,
309
+ scheduleId: receipt.scheduleId,
310
+ method: "POST" as const,
311
+ path: `/v1/subscription_schedules/${receipt.scheduleId}`,
312
+ key,
313
+ payload,
314
+ firstDispatchedAt: args.firstDispatchedAt,
315
+ attachReceiptBinding: receipt.binding,
316
+ baselineBinding: await renewalBindingV2(
317
+ "renewal-baseline",
318
+ receipt.providerSnapshot,
319
+ ),
320
+ defaultSettingsBinding: await renewalBindingV2(
321
+ "renewal-defaults",
322
+ schedule.default_settings,
323
+ ),
324
+ };
325
+ return renewalSnapshot({
326
+ ...request,
327
+ status: "projected_configure_request" as const,
328
+ providerQualification: "required" as const,
329
+ profile: reads.profile,
330
+ requestIdentity: {
331
+ key,
332
+ binding: await renewalBindingV2("renewal-configure", request),
333
+ },
334
+ });
335
+ } catch (error) {
336
+ return failure(error, ownedScheduleId);
337
+ }
338
+ }
@@ -66,7 +66,7 @@ function ownData(raw: unknown, required: string[], optional: string[] = []) {
66
66
  }
67
67
  return result;
68
68
  }
69
- function closed(raw: unknown) {
69
+ export function validateAttachmentReceiptFields(raw: unknown) {
70
70
  const root = ownData(raw, [
71
71
  "attachRequest",
72
72
  "actualDispatch",
@@ -95,10 +95,10 @@ function closed(raw: unknown) {
95
95
  ownData(wire.payload, ["from_subscription"]);
96
96
  }
97
97
  export function captureAttachmentReceipt(raw: unknown) {
98
- closed(raw);
98
+ validateAttachmentReceiptFields(raw);
99
99
  const captured = renewalSnapshot(raw);
100
100
  // Recheck the detached object: hostile reflection can mutate the live source.
101
- closed(captured);
101
+ validateAttachmentReceiptFields(captured);
102
102
  return input.parse(captured);
103
103
  }
104
104
 
@@ -15,6 +15,7 @@ export {
15
15
  prepareRenewalPriceReplacementV2,
16
16
  prepareRenewalScheduleAttachmentV2,
17
17
  constructRenewalScheduleAttachmentReceiptV2,
18
+ projectRenewalConfigurationV2,
18
19
  } from "./billing/renewalV2/index.js";
19
20
  export type {
20
21
  PrepareRenewalPriceReplacementV2Options,
@@ -23,4 +24,7 @@ export type {
23
24
  PreparedRenewalScheduleAttachmentV2,
24
25
  ConstructRenewalScheduleAttachmentReceiptV2Options,
25
26
  RenewalScheduleAttachmentReceiptV2,
27
+ ProjectRenewalConfigurationV2Options,
28
+ ProjectedRenewalConfigurationV2,
29
+ RenewalConfigurationProjectionFailure,
26
30
  } from "./billing/renewalV2/index.js";