@fantastic.dev/better-stripe 0.21.0 → 0.23.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 (107) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +8 -5
  3. package/dist/client/connect/payoutActivationProof.d.ts +16 -0
  4. package/dist/client/connect/payoutActivationProof.d.ts.map +1 -0
  5. package/dist/client/connect/payoutActivationProof.js +72 -0
  6. package/dist/client/connect/payoutActivationProof.js.map +1 -0
  7. package/dist/client/connect/payoutAdoption.d.ts +35 -0
  8. package/dist/client/connect/payoutAdoption.d.ts.map +1 -0
  9. package/dist/client/connect/payoutAdoption.js +230 -0
  10. package/dist/client/connect/payoutAdoption.js.map +1 -0
  11. package/dist/client/connect/payoutAdoptionAge.d.ts +19 -0
  12. package/dist/client/connect/payoutAdoptionAge.d.ts.map +1 -0
  13. package/dist/client/connect/payoutAdoptionAge.js +56 -0
  14. package/dist/client/connect/payoutAdoptionAge.js.map +1 -0
  15. package/dist/client/connect/payoutAdoptionAllocation.d.ts +24 -0
  16. package/dist/client/connect/payoutAdoptionAllocation.d.ts.map +1 -0
  17. package/dist/client/connect/payoutAdoptionAllocation.js +78 -0
  18. package/dist/client/connect/payoutAdoptionAllocation.js.map +1 -0
  19. package/dist/client/connect/payoutExecution.d.ts +34 -0
  20. package/dist/client/connect/payoutExecution.d.ts.map +1 -0
  21. package/dist/client/connect/payoutExecution.js +189 -0
  22. package/dist/client/connect/payoutExecution.js.map +1 -0
  23. package/dist/client/connect/payoutHistory.d.ts +22 -0
  24. package/dist/client/connect/payoutHistory.d.ts.map +1 -0
  25. package/dist/client/connect/payoutHistory.js +122 -0
  26. package/dist/client/connect/payoutHistory.js.map +1 -0
  27. package/dist/client/connect/payoutReconciliation.d.ts.map +1 -1
  28. package/dist/client/connect/payoutReconciliation.js +6 -2
  29. package/dist/client/connect/payoutReconciliation.js.map +1 -1
  30. package/dist/client/payoutPolicy.d.ts +10 -1
  31. package/dist/client/payoutPolicy.d.ts.map +1 -1
  32. package/dist/client/payoutPolicy.js +82 -7
  33. package/dist/client/payoutPolicy.js.map +1 -1
  34. package/dist/component/_generated/component.d.ts +269 -0
  35. package/dist/component/_generated/component.d.ts.map +1 -1
  36. package/dist/component/earnings/triggers.d.ts +40 -4
  37. package/dist/component/earnings/triggers.d.ts.map +1 -1
  38. package/dist/component/payoutPolicy/adoption.d.ts +9 -0
  39. package/dist/component/payoutPolicy/adoption.d.ts.map +1 -0
  40. package/dist/component/payoutPolicy/adoption.js +45 -0
  41. package/dist/component/payoutPolicy/adoption.js.map +1 -0
  42. package/dist/component/payoutPolicy/mutations.d.ts +96 -0
  43. package/dist/component/payoutPolicy/mutations.d.ts.map +1 -1
  44. package/dist/component/payoutPolicy/mutations.js +38 -5
  45. package/dist/component/payoutPolicy/mutations.js.map +1 -1
  46. package/dist/component/payoutPolicy/queries.d.ts +16 -0
  47. package/dist/component/payoutPolicy/queries.d.ts.map +1 -1
  48. package/dist/component/payoutPolicy/schema.d.ts +299 -2
  49. package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
  50. package/dist/component/payoutPolicy/schema.js +7 -0
  51. package/dist/component/payoutPolicy/schema.js.map +1 -1
  52. package/dist/component/payoutRelease/adoption.d.ts +269 -0
  53. package/dist/component/payoutRelease/adoption.d.ts.map +1 -0
  54. package/dist/component/payoutRelease/adoption.js +197 -0
  55. package/dist/component/payoutRelease/adoption.js.map +1 -0
  56. package/dist/component/payoutRelease/helpers.d.ts +4 -0
  57. package/dist/component/payoutRelease/helpers.d.ts.map +1 -1
  58. package/dist/component/payoutRelease/helpers.js +20 -0
  59. package/dist/component/payoutRelease/helpers.js.map +1 -1
  60. package/dist/component/payoutRelease/mutations.d.ts +87 -0
  61. package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
  62. package/dist/component/payoutRelease/mutations.js +13 -1
  63. package/dist/component/payoutRelease/mutations.js.map +1 -1
  64. package/dist/component/payoutRelease/observation.d.ts +18 -0
  65. package/dist/component/payoutRelease/observation.d.ts.map +1 -0
  66. package/dist/component/payoutRelease/observation.js +11 -0
  67. package/dist/component/payoutRelease/observation.js.map +1 -0
  68. package/dist/component/payoutRelease/queries.d.ts +74 -0
  69. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  70. package/dist/component/payoutRelease/queries.js +29 -0
  71. package/dist/component/payoutRelease/queries.js.map +1 -1
  72. package/dist/component/payoutRelease/schema.d.ts +13 -19
  73. package/dist/component/payoutRelease/schema.d.ts.map +1 -1
  74. package/dist/component/payoutRelease/schema.js +4 -9
  75. package/dist/component/payoutRelease/schema.js.map +1 -1
  76. package/dist/component/schema.d.ts +75 -2
  77. package/docs/settlement.md +181 -40
  78. package/package.json +1 -1
  79. package/src/client/connect/payoutActivationProof.ts +101 -0
  80. package/src/client/connect/payoutAdoption.test.ts +421 -0
  81. package/src/client/connect/payoutAdoption.ts +330 -0
  82. package/src/client/connect/payoutAdoptionAge.test.ts +89 -0
  83. package/src/client/connect/payoutAdoptionAge.ts +74 -0
  84. package/src/client/connect/payoutAdoptionAllocation.test.ts +132 -0
  85. package/src/client/connect/payoutAdoptionAllocation.ts +106 -0
  86. package/src/client/connect/payoutExecution.test.ts +504 -0
  87. package/src/client/connect/payoutExecution.ts +265 -0
  88. package/src/client/connect/payoutHistory.test.ts +145 -0
  89. package/src/client/connect/payoutHistory.ts +149 -0
  90. package/src/client/connect/payoutReconciliation.test.ts +29 -0
  91. package/src/client/connect/payoutReconciliation.ts +10 -2
  92. package/src/client/payoutPolicy.test.ts +16 -0
  93. package/src/client/payoutPolicy.ts +121 -5
  94. package/src/component/_generated/api.ts +6 -0
  95. package/src/component/_generated/component.ts +272 -1
  96. package/src/component/payout-adoption.test.ts +272 -0
  97. package/src/component/payout-policy-adoption.test.ts +131 -0
  98. package/src/component/payout-release-snapshot.test.ts +57 -0
  99. package/src/component/payoutPolicy/adoption.ts +76 -0
  100. package/src/component/payoutPolicy/mutations.ts +46 -3
  101. package/src/component/payoutPolicy/schema.ts +9 -0
  102. package/src/component/payoutRelease/adoption.ts +262 -0
  103. package/src/component/payoutRelease/helpers.ts +21 -0
  104. package/src/component/payoutRelease/mutations.ts +19 -1
  105. package/src/component/payoutRelease/observation.ts +10 -0
  106. package/src/component/payoutRelease/queries.ts +35 -0
  107. package/src/component/payoutRelease/schema.ts +4 -9
@@ -1,3 +1,14 @@
1
+ import { collectAdoptionProof } from "./connect/payoutActivationProof.js";
2
+ import {
3
+ adoptRecipientPayouts,
4
+ type PayoutAdoptionOptions,
5
+ } from "./connect/payoutAdoption.js";
6
+ export type * from "./connect/payoutAdoption.js";
7
+ import {
8
+ releaseRecipientPayout,
9
+ type PayoutReleaseOptions,
10
+ } from "./connect/payoutExecution.js";
11
+ export type * from "./connect/payoutExecution.js";
1
12
  import {
2
13
  reconcileRecipientPayout,
3
14
  type PayoutReconciliationOptions,
@@ -27,6 +38,7 @@ import {
27
38
  canonicalSchedule,
28
39
  canonicalThresholds,
29
40
  validateScope,
41
+ holdingDays,
30
42
  } from "../component/payoutPolicy/helpers.js";
31
43
  export type PayoutPolicy = Infer<typeof policyDoc>;
32
44
  export type PayoutPolicyOperation = Infer<typeof operationDoc>;
@@ -37,14 +49,18 @@ export type PayoutPolicyOptions = PayoutPolicyScope & {
37
49
  mode: PayoutPolicy["mode"];
38
50
  thresholds: PayoutPolicy["thresholds"];
39
51
  consent?: true;
52
+ /** Explicit funded-account adoption; historical payout mappings must already be imported. */
53
+ adoptExistingBalance?: true;
40
54
  };
41
55
  export type PayoutPolicyLimitation = {
42
56
  status: "unsupported" | "migration_required";
57
+ adoptionReason?: string;
43
58
  reason:
44
59
  | "provider_permission_denied"
45
60
  | "payout_control_unverified"
46
61
  | "country_unavailable"
47
62
  | "payouts_unavailable"
63
+ | "existing_payout_history"
48
64
  | "existing_balance"
49
65
  | "in_flight_payouts"
50
66
  | "existing_manual_schedule";
@@ -85,6 +101,18 @@ export class PayoutPolicyClient {
85
101
  private readonly component: Component,
86
102
  private readonly provider: () => Stripe,
87
103
  ) {}
104
+ adoptPayouts(ctx: RunCtx, opts: PayoutAdoptionOptions) {
105
+ return adoptRecipientPayouts(this.provider(), this.component, ctx, opts);
106
+ }
107
+ release(ctx: RunCtx, opts: PayoutReleaseOptions) {
108
+ return releaseRecipientPayout(
109
+ this.provider(),
110
+ this.component,
111
+ ctx,
112
+ opts,
113
+ () => this.verify(ctx, opts),
114
+ );
115
+ }
88
116
  reconcilePayout(ctx: RunCtx, opts: PayoutReconciliationOptions) {
89
117
  return reconcileRecipientPayout(this.provider(), this.component, ctx, opts);
90
118
  }
@@ -198,6 +226,15 @@ export class PayoutPolicyClient {
198
226
  if (payouts.has_more || payouts.data.length)
199
227
  return { status: "migration_required", reason: "in_flight_payouts" };
200
228
  }
229
+ const history = await stripe.payouts.list(
230
+ { limit: 1 },
231
+ { stripeAccount: scope.accountId },
232
+ );
233
+ if (history.has_more || history.data.length)
234
+ return {
235
+ status: "migration_required",
236
+ reason: "existing_payout_history",
237
+ };
201
238
  return null;
202
239
  }
203
240
  /** Persist restoration intent first. Existing mixed funds require explicit adoption; never infer ownership. */
@@ -236,7 +273,8 @@ export class PayoutPolicyClient {
236
273
  if (
237
274
  prior.mode !== opts.mode ||
238
275
  prior.expectedRevision !== opts.expectedRevision ||
239
- !equal(prior.thresholds, thresholds)
276
+ !equal(prior.thresholds, thresholds) ||
277
+ Boolean(prior.adoption) !== Boolean(opts.adoptExistingBalance)
240
278
  )
241
279
  throw new Error("Payout policy operation identity cannot be reused.");
242
280
  return { status: "prepared", operation: prior };
@@ -252,14 +290,48 @@ export class PayoutPolicyClient {
252
290
  policy?.country,
253
291
  );
254
292
  if ("status" in controls) return controls;
293
+ let adoption: PayoutPolicyOperation["adoption"];
294
+ if (
295
+ opts.adoptExistingBalance &&
296
+ (opts.mode !== "custom" || policy?.mode !== "stripe_managed")
297
+ )
298
+ throw new Error("Funded adoption requires an owned automatic policy.");
255
299
  if (opts.mode === "custom" && policy?.mode !== "custom") {
256
300
  if (controls.schedule.interval === "manual")
257
301
  return {
258
302
  status: "migration_required",
259
303
  reason: "existing_manual_schedule",
260
304
  };
261
- const migration = await this.migrationPreflight(opts);
262
- if (migration) return migration;
305
+ if (opts.adoptExistingBalance) {
306
+ const proof = await collectAdoptionProof(
307
+ this.provider(),
308
+ this.component,
309
+ ctx,
310
+ opts,
311
+ policy!.revision,
312
+ thresholds.map((t) => t.currency),
313
+ );
314
+ if (proof.status !== "verified")
315
+ return {
316
+ status: "migration_required",
317
+ reason: "existing_balance",
318
+ adoptionReason: proof.reason,
319
+ };
320
+ adoption = proof.proof;
321
+ if (
322
+ adoption.oldestHeldAt !== undefined &&
323
+ adoption.oldestHeldAt + holdingDays(controls.country) * 86400000 <=
324
+ Date.now()
325
+ )
326
+ return {
327
+ status: "migration_required",
328
+ reason: "existing_balance",
329
+ adoptionReason: "holding_deadline_expired",
330
+ };
331
+ } else {
332
+ const migration = await this.migrationPreflight(opts);
333
+ if (migration) return migration;
334
+ }
263
335
  }
264
336
  const operation = (await runMutationOrThrow(
265
337
  ctx,
@@ -274,6 +346,7 @@ export class PayoutPolicyClient {
274
346
  country: controls.country,
275
347
  observedSchedule: controls.schedule,
276
348
  observedAt,
349
+ ...(adoption ? { adoption } : {}),
277
350
  },
278
351
  )) as PayoutPolicyOperation;
279
352
  return { status: "prepared", operation };
@@ -288,6 +361,11 @@ export class PayoutPolicyClient {
288
361
  | { status: "canceled"; operation: PayoutPolicyOperation }
289
362
  | PayoutPolicyLimitation
290
363
  > {
364
+ args = {
365
+ accountId: args.accountId,
366
+ ownerKey: args.ownerKey,
367
+ operationKey: args.operationKey,
368
+ };
291
369
  const operation = await this.operation(ctx, args);
292
370
  if (!operation) throw new Error("Payout policy operation is unavailable.");
293
371
  if (operation.status === "complete") return { status: "ready", operation };
@@ -320,6 +398,13 @@ export class PayoutPolicyClient {
320
398
  if ("status" in controls) return controls;
321
399
  if (operation.mode === "custom" && controls.country !== operation.country)
322
400
  return { status: "schedule_drift" };
401
+ if (
402
+ operation.adoption &&
403
+ !operation.attempted &&
404
+ equal(controls.schedule, operation.targetSchedule)
405
+ )
406
+ return { status: "schedule_drift" };
407
+ let freshAdoption: PayoutPolicyOperation["adoption"];
323
408
  if (!equal(controls.schedule, operation.targetSchedule)) {
324
409
  if (!equal(controls.schedule, operation.observedSchedule))
325
410
  return { status: "schedule_drift" };
@@ -328,7 +413,38 @@ export class PayoutPolicyClient {
328
413
  !operation.attempted &&
329
414
  policy?.mode === "stripe_managed"
330
415
  ) {
331
- const migration = await this.migrationPreflight(args);
416
+ const result = operation.adoption
417
+ ? await collectAdoptionProof(
418
+ this.provider(),
419
+ this.component,
420
+ ctx,
421
+ args,
422
+ policy.revision,
423
+ operation.thresholds.map((t) => t.currency),
424
+ )
425
+ : null;
426
+ if (result?.status === "verified") freshAdoption = result.proof;
427
+ const ageExpired =
428
+ result?.status === "verified" &&
429
+ result.proof.oldestHeldAt !== undefined &&
430
+ result.proof.oldestHeldAt +
431
+ holdingDays(operation.country) * 86400000 <=
432
+ Date.now();
433
+ const migration: PayoutPolicyLimitation | null = ageExpired
434
+ ? {
435
+ status: "migration_required",
436
+ reason: "existing_balance",
437
+ adoptionReason: "holding_deadline_expired",
438
+ }
439
+ : result?.status === "held"
440
+ ? {
441
+ status: "migration_required",
442
+ reason: "existing_balance",
443
+ adoptionReason: result.reason,
444
+ }
445
+ : result
446
+ ? null
447
+ : await this.migrationPreflight(args);
332
448
  if (migration) {
333
449
  await runMutationOrThrow(
334
450
  ctx,
@@ -344,7 +460,7 @@ export class PayoutPolicyClient {
344
460
  await runMutationOrThrow(
345
461
  ctx,
346
462
  componentRef(this.component, "payoutPolicy/mutations/beginAttempt"),
347
- args,
463
+ { ...args, ...(freshAdoption ? { adoption: freshAdoption } : {}) },
348
464
  );
349
465
  try {
350
466
  await this.provider().balanceSettings.update(
@@ -34,13 +34,16 @@ import type * as lib_idempotency from "../lib/idempotency.js";
34
34
  import type * as lib_paymentSeller from "../lib/paymentSeller.js";
35
35
  import type * as lib_reversals from "../lib/reversals.js";
36
36
  import type * as lib_stripeFactory from "../lib/stripeFactory.js";
37
+ import type * as payoutPolicy_adoption from "../payoutPolicy/adoption.js";
37
38
  import type * as payoutPolicy_helpers from "../payoutPolicy/helpers.js";
38
39
  import type * as payoutPolicy_mutations from "../payoutPolicy/mutations.js";
39
40
  import type * as payoutPolicy_queries from "../payoutPolicy/queries.js";
41
+ import type * as payoutRelease_adoption from "../payoutRelease/adoption.js";
40
42
  import type * as payoutRelease_allocation from "../payoutRelease/allocation.js";
41
43
  import type * as payoutRelease_fees from "../payoutRelease/fees.js";
42
44
  import type * as payoutRelease_helpers from "../payoutRelease/helpers.js";
43
45
  import type * as payoutRelease_mutations from "../payoutRelease/mutations.js";
46
+ import type * as payoutRelease_observation from "../payoutRelease/observation.js";
44
47
  import type * as payoutRelease_queries from "../payoutRelease/queries.js";
45
48
  import type * as products_mutations from "../products/mutations.js";
46
49
  import type * as products_queries from "../products/queries.js";
@@ -86,13 +89,16 @@ const fullApi: ApiFromModules<{
86
89
  "lib/paymentSeller": typeof lib_paymentSeller;
87
90
  "lib/reversals": typeof lib_reversals;
88
91
  "lib/stripeFactory": typeof lib_stripeFactory;
92
+ "payoutPolicy/adoption": typeof payoutPolicy_adoption;
89
93
  "payoutPolicy/helpers": typeof payoutPolicy_helpers;
90
94
  "payoutPolicy/mutations": typeof payoutPolicy_mutations;
91
95
  "payoutPolicy/queries": typeof payoutPolicy_queries;
96
+ "payoutRelease/adoption": typeof payoutRelease_adoption;
92
97
  "payoutRelease/allocation": typeof payoutRelease_allocation;
93
98
  "payoutRelease/fees": typeof payoutRelease_fees;
94
99
  "payoutRelease/helpers": typeof payoutRelease_helpers;
95
100
  "payoutRelease/mutations": typeof payoutRelease_mutations;
101
+ "payoutRelease/observation": typeof payoutRelease_observation;
96
102
  "payoutRelease/queries": typeof payoutRelease_queries;
97
103
  "products/mutations": typeof products_mutations;
98
104
  "products/queries": typeof products_queries;
@@ -2199,11 +2199,41 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2199
2199
  beginAttempt: FunctionReference<
2200
2200
  "mutation",
2201
2201
  "internal",
2202
- { accountId: string; operationKey: string; ownerKey: string },
2202
+ {
2203
+ accountId: string;
2204
+ adoption?: {
2205
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2206
+ observations: Array<{
2207
+ currency: string;
2208
+ ledgerFingerprint: string;
2209
+ matureNet: number;
2210
+ observedAt: number;
2211
+ pendingCredits: number;
2212
+ stripeTransferId: string;
2213
+ transactionIds: Array<string>;
2214
+ }>;
2215
+ oldestHeldAt?: number;
2216
+ };
2217
+ operationKey: string;
2218
+ ownerKey: string;
2219
+ },
2203
2220
  {
2204
2221
  _creationTime: number;
2205
2222
  _id: string;
2206
2223
  accountId: string;
2224
+ adoption?: {
2225
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2226
+ observations: Array<{
2227
+ currency: string;
2228
+ ledgerFingerprint: string;
2229
+ matureNet: number;
2230
+ observedAt: number;
2231
+ pendingCredits: number;
2232
+ stripeTransferId: string;
2233
+ transactionIds: Array<string>;
2234
+ }>;
2235
+ oldestHeldAt?: number;
2236
+ };
2207
2237
  attempted?: boolean;
2208
2238
  country: string;
2209
2239
  expectedRevision: number;
@@ -2249,6 +2279,19 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2249
2279
  _creationTime: number;
2250
2280
  _id: string;
2251
2281
  accountId: string;
2282
+ adoption?: {
2283
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2284
+ observations: Array<{
2285
+ currency: string;
2286
+ ledgerFingerprint: string;
2287
+ matureNet: number;
2288
+ observedAt: number;
2289
+ pendingCredits: number;
2290
+ stripeTransferId: string;
2291
+ transactionIds: Array<string>;
2292
+ }>;
2293
+ oldestHeldAt?: number;
2294
+ };
2252
2295
  attempted?: boolean;
2253
2296
  country: string;
2254
2297
  expectedRevision: number;
@@ -2294,6 +2337,19 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2294
2337
  _creationTime: number;
2295
2338
  _id: string;
2296
2339
  accountId: string;
2340
+ adoption?: {
2341
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2342
+ observations: Array<{
2343
+ currency: string;
2344
+ ledgerFingerprint: string;
2345
+ matureNet: number;
2346
+ observedAt: number;
2347
+ pendingCredits: number;
2348
+ stripeTransferId: string;
2349
+ transactionIds: Array<string>;
2350
+ }>;
2351
+ oldestHeldAt?: number;
2352
+ };
2297
2353
  attempted?: boolean;
2298
2354
  country: string;
2299
2355
  expectedRevision: number;
@@ -2327,6 +2383,19 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2327
2383
  "internal",
2328
2384
  {
2329
2385
  accountId: string;
2386
+ adoption?: {
2387
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2388
+ observations: Array<{
2389
+ currency: string;
2390
+ ledgerFingerprint: string;
2391
+ matureNet: number;
2392
+ observedAt: number;
2393
+ pendingCredits: number;
2394
+ stripeTransferId: string;
2395
+ transactionIds: Array<string>;
2396
+ }>;
2397
+ oldestHeldAt?: number;
2398
+ };
2330
2399
  country: string;
2331
2400
  expectedRevision: number;
2332
2401
  mode: "stripe_managed" | "custom";
@@ -2344,6 +2413,19 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2344
2413
  _creationTime: number;
2345
2414
  _id: string;
2346
2415
  accountId: string;
2416
+ adoption?: {
2417
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2418
+ observations: Array<{
2419
+ currency: string;
2420
+ ledgerFingerprint: string;
2421
+ matureNet: number;
2422
+ observedAt: number;
2423
+ pendingCredits: number;
2424
+ stripeTransferId: string;
2425
+ transactionIds: Array<string>;
2426
+ }>;
2427
+ oldestHeldAt?: number;
2428
+ };
2347
2429
  attempted?: boolean;
2348
2430
  country: string;
2349
2431
  expectedRevision: number;
@@ -2444,6 +2526,19 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2444
2526
  _creationTime: number;
2445
2527
  _id: string;
2446
2528
  accountId: string;
2529
+ adoption?: {
2530
+ claims: Array<{ fingerprint: string; operationKey: string }>;
2531
+ observations: Array<{
2532
+ currency: string;
2533
+ ledgerFingerprint: string;
2534
+ matureNet: number;
2535
+ observedAt: number;
2536
+ pendingCredits: number;
2537
+ stripeTransferId: string;
2538
+ transactionIds: Array<string>;
2539
+ }>;
2540
+ oldestHeldAt?: number;
2541
+ };
2447
2542
  attempted?: boolean;
2448
2543
  country: string;
2449
2544
  expectedRevision: number;
@@ -2476,6 +2571,94 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2476
2571
  };
2477
2572
  payoutRelease: {
2478
2573
  mutations: {
2574
+ adoptHistoricalBatch: FunctionReference<
2575
+ "mutation",
2576
+ "internal",
2577
+ {
2578
+ accountId: string;
2579
+ expectedClaims: Array<{
2580
+ fingerprint: string;
2581
+ operationKey: string;
2582
+ }>;
2583
+ expectedRevision: number;
2584
+ observations: Array<{
2585
+ currency: string;
2586
+ ledgerFingerprint: string;
2587
+ matureNet: number;
2588
+ observedAt: number;
2589
+ pendingCredits: number;
2590
+ stripeTransferId: string;
2591
+ transactionIds: Array<string>;
2592
+ }>;
2593
+ ownerKey: string;
2594
+ payouts: Array<{
2595
+ allocations: Array<{
2596
+ amount: number;
2597
+ role?: "store" | "affiliate" | "other";
2598
+ stripeTransferId: string;
2599
+ }>;
2600
+ payout: {
2601
+ amount: number;
2602
+ created: number;
2603
+ currency: string;
2604
+ debitFee: number;
2605
+ debitTransactionId: string;
2606
+ destinationId: string;
2607
+ returnFee?: number;
2608
+ returnTransactionId?: string;
2609
+ status: "paid" | "returned";
2610
+ stripePayoutId: string;
2611
+ };
2612
+ }>;
2613
+ },
2614
+ {
2615
+ claims: Array<{
2616
+ _creationTime: number;
2617
+ _id: string;
2618
+ accountId: string;
2619
+ allocations: Array<{
2620
+ amount: number;
2621
+ role?: "store" | "affiliate" | "other";
2622
+ stripeTransferId: string;
2623
+ }>;
2624
+ amount: number;
2625
+ attemptedAt?: number;
2626
+ currency: string;
2627
+ debitFee?: number;
2628
+ debitTransactionId?: string;
2629
+ destinationId?: string;
2630
+ expectedRevision: number;
2631
+ feeRevision?: number;
2632
+ historical?: boolean;
2633
+ observations: Array<{
2634
+ currency: string;
2635
+ ledgerFingerprint: string;
2636
+ matureNet: number;
2637
+ observedAt: number;
2638
+ pendingCredits: number;
2639
+ stripeTransferId: string;
2640
+ transactionIds: Array<string>;
2641
+ }>;
2642
+ operationKey: string;
2643
+ ownerKey: string;
2644
+ providerFee?: number;
2645
+ rejection?: {
2646
+ code: "balance_insufficient" | "amount_too_small";
2647
+ requestId: string;
2648
+ };
2649
+ returnTransactionId?: string;
2650
+ status:
2651
+ | "reserved"
2652
+ | "submitted"
2653
+ | "paid"
2654
+ | "returned"
2655
+ | "canceled"
2656
+ | "rejected";
2657
+ stripePayoutId?: string;
2658
+ }>;
2659
+ },
2660
+ Name
2661
+ >;
2479
2662
  beginAttempt: FunctionReference<
2480
2663
  "mutation",
2481
2664
  "internal",
@@ -2494,8 +2677,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2494
2677
  currency: string;
2495
2678
  debitFee?: number;
2496
2679
  debitTransactionId?: string;
2680
+ destinationId?: string;
2497
2681
  expectedRevision: number;
2498
2682
  feeRevision?: number;
2683
+ historical?: boolean;
2499
2684
  observations: Array<{
2500
2685
  currency: string;
2501
2686
  ledgerFingerprint: string;
@@ -2542,8 +2727,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2542
2727
  currency: string;
2543
2728
  debitFee?: number;
2544
2729
  debitTransactionId?: string;
2730
+ destinationId?: string;
2545
2731
  expectedRevision: number;
2546
2732
  feeRevision?: number;
2733
+ historical?: boolean;
2547
2734
  observations: Array<{
2548
2735
  currency: string;
2549
2736
  ledgerFingerprint: string;
@@ -2578,6 +2765,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2578
2765
  {
2579
2766
  accountId: string;
2580
2767
  currency: string;
2768
+ destinationId?: string;
2581
2769
  expectedRevision: number;
2582
2770
  independentLiabilities: number;
2583
2771
  observations: Array<{
@@ -2607,8 +2795,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2607
2795
  currency: string;
2608
2796
  debitFee?: number;
2609
2797
  debitTransactionId?: string;
2798
+ destinationId?: string;
2610
2799
  expectedRevision: number;
2611
2800
  feeRevision?: number;
2801
+ historical?: boolean;
2612
2802
  observations: Array<{
2613
2803
  currency: string;
2614
2804
  ledgerFingerprint: string;
@@ -2678,8 +2868,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2678
2868
  currency: string;
2679
2869
  debitFee?: number;
2680
2870
  debitTransactionId?: string;
2871
+ destinationId?: string;
2681
2872
  expectedRevision: number;
2682
2873
  feeRevision?: number;
2874
+ historical?: boolean;
2683
2875
  observations: Array<{
2684
2876
  currency: string;
2685
2877
  ledgerFingerprint: string;
@@ -2732,8 +2924,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2732
2924
  currency: string;
2733
2925
  debitFee?: number;
2734
2926
  debitTransactionId?: string;
2927
+ destinationId?: string;
2735
2928
  expectedRevision: number;
2736
2929
  feeRevision?: number;
2930
+ historical?: boolean;
2737
2931
  observations: Array<{
2738
2932
  currency: string;
2739
2933
  ledgerFingerprint: string;
@@ -2789,8 +2983,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2789
2983
  currency: string;
2790
2984
  debitFee?: number;
2791
2985
  debitTransactionId?: string;
2986
+ destinationId?: string;
2792
2987
  expectedRevision: number;
2793
2988
  feeRevision?: number;
2989
+ historical?: boolean;
2794
2990
  observations: Array<{
2795
2991
  currency: string;
2796
2992
  ledgerFingerprint: string;
@@ -2851,8 +3047,10 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2851
3047
  currency: string;
2852
3048
  debitFee?: number;
2853
3049
  debitTransactionId?: string;
3050
+ destinationId?: string;
2854
3051
  expectedRevision: number;
2855
3052
  feeRevision?: number;
3053
+ historical?: boolean;
2856
3054
  observations: Array<{
2857
3055
  currency: string;
2858
3056
  ledgerFingerprint: string;
@@ -2882,6 +3080,79 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2882
3080
  },
2883
3081
  Name
2884
3082
  >;
3083
+ snapshot: FunctionReference<
3084
+ "query",
3085
+ "internal",
3086
+ { accountId: string; ownerKey: string },
3087
+ | { reason: "snapshot_limit"; status: "held" }
3088
+ | {
3089
+ claims: Array<{
3090
+ _creationTime: number;
3091
+ _id: string;
3092
+ accountId: string;
3093
+ allocations: Array<{
3094
+ amount: number;
3095
+ role?: "store" | "affiliate" | "other";
3096
+ stripeTransferId: string;
3097
+ }>;
3098
+ amount: number;
3099
+ attemptedAt?: number;
3100
+ currency: string;
3101
+ debitFee?: number;
3102
+ debitTransactionId?: string;
3103
+ destinationId?: string;
3104
+ expectedRevision: number;
3105
+ feeRevision?: number;
3106
+ historical?: boolean;
3107
+ observations: Array<{
3108
+ currency: string;
3109
+ ledgerFingerprint: string;
3110
+ matureNet: number;
3111
+ observedAt: number;
3112
+ pendingCredits: number;
3113
+ stripeTransferId: string;
3114
+ transactionIds: Array<string>;
3115
+ }>;
3116
+ operationKey: string;
3117
+ ownerKey: string;
3118
+ providerFee?: number;
3119
+ rejection?: {
3120
+ code: "balance_insufficient" | "amount_too_small";
3121
+ requestId: string;
3122
+ };
3123
+ returnTransactionId?: string;
3124
+ status:
3125
+ | "reserved"
3126
+ | "submitted"
3127
+ | "paid"
3128
+ | "returned"
3129
+ | "canceled"
3130
+ | "rejected";
3131
+ stripePayoutId?: string;
3132
+ }>;
3133
+ status: "ready";
3134
+ transfers: Array<{
3135
+ _creationTime: number;
3136
+ _id: string;
3137
+ amount: number;
3138
+ currency: string;
3139
+ destinationAccountId: string;
3140
+ metadata?: any;
3141
+ paymentId?: string;
3142
+ reinstatement?: boolean;
3143
+ reversalClaimedAmount?: number;
3144
+ reversalStatus?: "partially_reversed" | "fully_reversed";
3145
+ reversedAmount?: number;
3146
+ role?: "store" | "affiliate" | "other";
3147
+ sourceChargeId?: string;
3148
+ sourceInvoiceId?: string;
3149
+ status: "pending" | "paid" | "failed" | "reversed";
3150
+ stripeTransferId: string;
3151
+ totalsRecorded?: true;
3152
+ }>;
3153
+ },
3154
+ Name
3155
+ >;
2885
3156
  };
2886
3157
  };
2887
3158
  products: {