@fantastic.dev/better-stripe 0.28.6 → 0.29.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 (136) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/MIGRATION.md +6 -0
  3. package/README.md +5 -1
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +28 -8
  5. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  6. package/dist/client/connect/payoutCollectedInput.d.ts +110 -0
  7. package/dist/client/connect/payoutCollectedInput.d.ts.map +1 -0
  8. package/dist/client/connect/payoutCollectedInput.js +70 -0
  9. package/dist/client/connect/payoutCollectedInput.js.map +1 -0
  10. package/dist/client/connect/payoutExecution.d.ts +1 -0
  11. package/dist/client/connect/payoutExecution.d.ts.map +1 -1
  12. package/dist/client/connect/payoutExecution.js +94 -67
  13. package/dist/client/connect/payoutExecution.js.map +1 -1
  14. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -4
  15. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  16. package/dist/client/connect/payoutExecutionTestHelpers.js +9 -6
  17. package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -1
  18. package/dist/client/connect/payoutPreview.d.ts +1 -0
  19. package/dist/client/connect/payoutPreview.d.ts.map +1 -1
  20. package/dist/client/connect/payoutPreview.js +31 -19
  21. package/dist/client/connect/payoutPreview.js.map +1 -1
  22. package/dist/client/connect/payoutQualification.d.ts +7 -1
  23. package/dist/client/connect/payoutQualification.d.ts.map +1 -1
  24. package/dist/client/connect/payoutQualification.js +34 -19
  25. package/dist/client/connect/payoutQualification.js.map +1 -1
  26. package/dist/client/connect/payoutSyncTestHelpers.d.ts +14 -4
  27. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  28. package/dist/client/connect/payoutWorker.d.ts.map +1 -1
  29. package/dist/client/connect/payoutWorker.js +4 -1
  30. package/dist/client/connect/payoutWorker.js.map +1 -1
  31. package/dist/client/costRecovery.d.ts +5 -0
  32. package/dist/client/costRecovery.d.ts.map +1 -1
  33. package/dist/client/costRecovery.js +5 -0
  34. package/dist/client/costRecovery.js.map +1 -1
  35. package/dist/client/payoutPolicy.d.ts +4 -0
  36. package/dist/client/payoutPolicy.d.ts.map +1 -1
  37. package/dist/component/_generated/component.d.ts +175 -0
  38. package/dist/component/_generated/component.d.ts.map +1 -1
  39. package/dist/component/costRecovery/mutations.js +1 -1
  40. package/dist/component/costRecovery/queries.d.ts +9 -0
  41. package/dist/component/costRecovery/queries.d.ts.map +1 -1
  42. package/dist/component/costRecovery/queries.js +20 -0
  43. package/dist/component/costRecovery/queries.js.map +1 -1
  44. package/dist/component/earnings/triggers.d.ts +16 -6
  45. package/dist/component/earnings/triggers.d.ts.map +1 -1
  46. package/dist/component/payoutRelease/adoption.d.ts +6 -0
  47. package/dist/component/payoutRelease/adoption.d.ts.map +1 -1
  48. package/dist/component/payoutRelease/helpers.d.ts +4 -1
  49. package/dist/component/payoutRelease/helpers.d.ts.map +1 -1
  50. package/dist/component/payoutRelease/helpers.js +17 -10
  51. package/dist/component/payoutRelease/helpers.js.map +1 -1
  52. package/dist/component/payoutRelease/mutations.d.ts +20 -0
  53. package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
  54. package/dist/component/payoutRelease/mutations.js +14 -2
  55. package/dist/component/payoutRelease/mutations.js.map +1 -1
  56. package/dist/component/payoutRelease/planning.d.ts +4 -0
  57. package/dist/component/payoutRelease/planning.d.ts.map +1 -1
  58. package/dist/component/payoutRelease/planning.js +4 -2
  59. package/dist/component/payoutRelease/planning.js.map +1 -1
  60. package/dist/component/payoutRelease/preview.d.ts +2 -0
  61. package/dist/component/payoutRelease/preview.d.ts.map +1 -1
  62. package/dist/component/payoutRelease/preview.js +2 -0
  63. package/dist/component/payoutRelease/preview.js.map +1 -1
  64. package/dist/component/payoutRelease/queries.d.ts +11 -0
  65. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  66. package/dist/component/payoutRelease/schema.d.ts +17 -2
  67. package/dist/component/payoutRelease/schema.d.ts.map +1 -1
  68. package/dist/component/payoutRelease/schema.js +3 -0
  69. package/dist/component/payoutRelease/schema.js.map +1 -1
  70. package/dist/component/payoutSnapshots/financial.d.ts +35 -0
  71. package/dist/component/payoutSnapshots/financial.d.ts.map +1 -0
  72. package/dist/component/payoutSnapshots/financial.js +89 -0
  73. package/dist/component/payoutSnapshots/financial.js.map +1 -0
  74. package/dist/component/payoutSnapshots/liabilities.d.ts +7 -0
  75. package/dist/component/payoutSnapshots/liabilities.d.ts.map +1 -0
  76. package/dist/component/payoutSnapshots/liabilities.js +18 -0
  77. package/dist/component/payoutSnapshots/liabilities.js.map +1 -0
  78. package/dist/component/payoutSnapshots/localState.d.ts +2 -0
  79. package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
  80. package/dist/component/payoutSnapshots/localState.js +6 -3
  81. package/dist/component/payoutSnapshots/localState.js.map +1 -1
  82. package/dist/component/payoutSnapshots/mutations.d.ts +6 -0
  83. package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
  84. package/dist/component/payoutSnapshots/mutations.js +2 -0
  85. package/dist/component/payoutSnapshots/mutations.js.map +1 -1
  86. package/dist/component/payoutSnapshots/queries.d.ts +133 -0
  87. package/dist/component/payoutSnapshots/queries.d.ts.map +1 -0
  88. package/dist/component/payoutSnapshots/queries.js +84 -0
  89. package/dist/component/payoutSnapshots/queries.js.map +1 -0
  90. package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -1
  91. package/dist/component/payoutSnapshots/revisions.js +19 -0
  92. package/dist/component/payoutSnapshots/revisions.js.map +1 -1
  93. package/dist/component/payoutSnapshots/schema.d.ts +15 -5
  94. package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
  95. package/dist/component/payoutSnapshots/schema.js +3 -1
  96. package/dist/component/payoutSnapshots/schema.js.map +1 -1
  97. package/dist/component/payoutWorker/mutations.d.ts.map +1 -1
  98. package/dist/component/payoutWorker/mutations.js +3 -1
  99. package/dist/component/payoutWorker/mutations.js.map +1 -1
  100. package/dist/component/schema.d.ts +14 -4
  101. package/dist/react/workflows/payout-attempt-state.d.ts.map +1 -1
  102. package/dist/react/workflows/payout-attempt-state.js +3 -0
  103. package/dist/react/workflows/payout-attempt-state.js.map +1 -1
  104. package/dist/react/workflows/payout-progress-state.d.ts.map +1 -1
  105. package/dist/react/workflows/payout-progress-state.js +3 -0
  106. package/dist/react/workflows/payout-progress-state.js.map +1 -1
  107. package/docs/settlement.md +75 -16
  108. package/package.json +1 -1
  109. package/src/client/connect/payoutCollectedInput.ts +120 -0
  110. package/src/client/connect/payoutExecution.ts +116 -84
  111. package/src/client/connect/payoutExecutionTestHelpers.ts +19 -6
  112. package/src/client/connect/payoutLargeHistory.test.ts +222 -0
  113. package/src/client/connect/payoutLiabilityVersion.test.ts +221 -0
  114. package/src/client/connect/payoutPreview.ts +42 -24
  115. package/src/client/connect/payoutQualification.ts +62 -21
  116. package/src/client/connect/payoutWorker.ts +4 -1
  117. package/src/client/costRecovery.ts +8 -0
  118. package/src/component/_generated/api.ts +6 -0
  119. package/src/component/_generated/component.ts +203 -0
  120. package/src/component/costRecovery/mutations.ts +1 -1
  121. package/src/component/costRecovery/queries.ts +21 -0
  122. package/src/component/payoutRelease/helpers.ts +19 -11
  123. package/src/component/payoutRelease/mutations.ts +18 -1
  124. package/src/component/payoutRelease/planning.ts +7 -1
  125. package/src/component/payoutRelease/preview.ts +2 -0
  126. package/src/component/payoutRelease/schema.ts +3 -0
  127. package/src/component/payoutSnapshots/financial.ts +121 -0
  128. package/src/component/payoutSnapshots/liabilities.ts +25 -0
  129. package/src/component/payoutSnapshots/localState.ts +7 -3
  130. package/src/component/payoutSnapshots/mutations.ts +2 -0
  131. package/src/component/payoutSnapshots/queries.ts +102 -0
  132. package/src/component/payoutSnapshots/revisions.ts +26 -0
  133. package/src/component/payoutSnapshots/schema.ts +3 -0
  134. package/src/component/payoutWorker/mutations.ts +3 -1
  135. package/src/react/workflows/payout-attempt-state.ts +6 -0
  136. package/src/react/workflows/payout-progress-state.ts +6 -0
@@ -63,8 +63,11 @@ import type * as payoutRelease_planning from "../payoutRelease/planning.js";
63
63
  import type * as payoutRelease_preview from "../payoutRelease/preview.js";
64
64
  import type * as payoutRelease_progress from "../payoutRelease/progress.js";
65
65
  import type * as payoutRelease_queries from "../payoutRelease/queries.js";
66
+ import type * as payoutSnapshots_financial from "../payoutSnapshots/financial.js";
67
+ import type * as payoutSnapshots_liabilities from "../payoutSnapshots/liabilities.js";
66
68
  import type * as payoutSnapshots_localState from "../payoutSnapshots/localState.js";
67
69
  import type * as payoutSnapshots_mutations from "../payoutSnapshots/mutations.js";
70
+ import type * as payoutSnapshots_queries from "../payoutSnapshots/queries.js";
68
71
  import type * as payoutSnapshots_revisions from "../payoutSnapshots/revisions.js";
69
72
  import type * as payoutSnapshots_scope from "../payoutSnapshots/scope.js";
70
73
  import type * as payoutSync_helpers from "../payoutSync/helpers.js";
@@ -149,8 +152,11 @@ const fullApi: ApiFromModules<{
149
152
  "payoutRelease/preview": typeof payoutRelease_preview;
150
153
  "payoutRelease/progress": typeof payoutRelease_progress;
151
154
  "payoutRelease/queries": typeof payoutRelease_queries;
155
+ "payoutSnapshots/financial": typeof payoutSnapshots_financial;
156
+ "payoutSnapshots/liabilities": typeof payoutSnapshots_liabilities;
152
157
  "payoutSnapshots/localState": typeof payoutSnapshots_localState;
153
158
  "payoutSnapshots/mutations": typeof payoutSnapshots_mutations;
159
+ "payoutSnapshots/queries": typeof payoutSnapshots_queries;
154
160
  "payoutSnapshots/revisions": typeof payoutSnapshots_revisions;
155
161
  "payoutSnapshots/scope": typeof payoutSnapshots_scope;
156
162
  "payoutSync/helpers": typeof payoutSync_helpers;
@@ -2689,6 +2689,13 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2689
2689
  },
2690
2690
  Name
2691
2691
  >;
2692
+ payoutQuote: FunctionReference<
2693
+ "query",
2694
+ "internal",
2695
+ { accountId: string; currency: string; scopeKey: string },
2696
+ { independentLiabilities: number; liabilityRevision: number },
2697
+ Name
2698
+ >;
2692
2699
  reservation: FunctionReference<
2693
2700
  "query",
2694
2701
  "internal",
@@ -3273,6 +3280,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3273
3280
  expectedRevision: number;
3274
3281
  feeRevision?: number;
3275
3282
  historical?: boolean;
3283
+ independentLiabilities?: number;
3284
+ liabilityRevision?: number;
3276
3285
  observations: Array<{
3277
3286
  currency: string;
3278
3287
  ledgerFingerprint: string;
@@ -3290,6 +3299,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3290
3299
  requestId: string;
3291
3300
  };
3292
3301
  returnTransactionId?: string;
3302
+ snapshotId?: string;
3293
3303
  status:
3294
3304
  | "reserved"
3295
3305
  | "submitted"
@@ -3324,6 +3334,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3324
3334
  expectedRevision: number;
3325
3335
  feeRevision?: number;
3326
3336
  historical?: boolean;
3337
+ independentLiabilities?: number;
3338
+ liabilityRevision?: number;
3327
3339
  observations: Array<{
3328
3340
  currency: string;
3329
3341
  ledgerFingerprint: string;
@@ -3341,6 +3353,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3341
3353
  requestId: string;
3342
3354
  };
3343
3355
  returnTransactionId?: string;
3356
+ snapshotId?: string;
3344
3357
  status:
3345
3358
  | "reserved"
3346
3359
  | "submitted"
@@ -3374,6 +3387,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3374
3387
  expectedRevision: number;
3375
3388
  feeRevision?: number;
3376
3389
  historical?: boolean;
3390
+ independentLiabilities?: number;
3391
+ liabilityRevision?: number;
3377
3392
  observations: Array<{
3378
3393
  currency: string;
3379
3394
  ledgerFingerprint: string;
@@ -3391,6 +3406,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3391
3406
  requestId: string;
3392
3407
  };
3393
3408
  returnTransactionId?: string;
3409
+ snapshotId?: string;
3394
3410
  status:
3395
3411
  | "reserved"
3396
3412
  | "submitted"
@@ -3411,6 +3427,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3411
3427
  destinationId?: string;
3412
3428
  expectedRevision: number;
3413
3429
  independentLiabilities: number;
3430
+ liabilityRevision?: number;
3414
3431
  observations: Array<{
3415
3432
  currency: string;
3416
3433
  ledgerFingerprint: string;
@@ -3423,6 +3440,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3423
3440
  operationKey: string;
3424
3441
  ownerKey: string;
3425
3442
  providerAvailable: number;
3443
+ snapshotId?: string;
3426
3444
  },
3427
3445
  | {
3428
3446
  _creationTime: number;
@@ -3442,6 +3460,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3442
3460
  expectedRevision: number;
3443
3461
  feeRevision?: number;
3444
3462
  historical?: boolean;
3463
+ independentLiabilities?: number;
3464
+ liabilityRevision?: number;
3445
3465
  observations: Array<{
3446
3466
  currency: string;
3447
3467
  ledgerFingerprint: string;
@@ -3459,6 +3479,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3459
3479
  requestId: string;
3460
3480
  };
3461
3481
  returnTransactionId?: string;
3482
+ snapshotId?: string;
3462
3483
  status:
3463
3484
  | "reserved"
3464
3485
  | "submitted"
@@ -3515,6 +3536,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3515
3536
  expectedRevision: number;
3516
3537
  feeRevision?: number;
3517
3538
  historical?: boolean;
3539
+ independentLiabilities?: number;
3540
+ liabilityRevision?: number;
3518
3541
  observations: Array<{
3519
3542
  currency: string;
3520
3543
  ledgerFingerprint: string;
@@ -3532,6 +3555,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3532
3555
  requestId: string;
3533
3556
  };
3534
3557
  returnTransactionId?: string;
3558
+ snapshotId?: string;
3535
3559
  status:
3536
3560
  | "reserved"
3537
3561
  | "submitted"
@@ -3571,6 +3595,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3571
3595
  expectedRevision: number;
3572
3596
  feeRevision?: number;
3573
3597
  historical?: boolean;
3598
+ independentLiabilities?: number;
3599
+ liabilityRevision?: number;
3574
3600
  observations: Array<{
3575
3601
  currency: string;
3576
3602
  ledgerFingerprint: string;
@@ -3588,6 +3614,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3588
3614
  requestId: string;
3589
3615
  };
3590
3616
  returnTransactionId?: string;
3617
+ snapshotId?: string;
3591
3618
  status:
3592
3619
  | "reserved"
3593
3620
  | "submitted"
@@ -3630,6 +3657,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3630
3657
  expectedRevision: number;
3631
3658
  feeRevision?: number;
3632
3659
  historical?: boolean;
3660
+ independentLiabilities?: number;
3661
+ liabilityRevision?: number;
3633
3662
  observations: Array<{
3634
3663
  currency: string;
3635
3664
  ledgerFingerprint: string;
@@ -3647,6 +3676,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3647
3676
  requestId: string;
3648
3677
  };
3649
3678
  returnTransactionId?: string;
3679
+ snapshotId?: string;
3650
3680
  status:
3651
3681
  | "reserved"
3652
3682
  | "submitted"
@@ -3694,6 +3724,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3694
3724
  expectedRevision: number;
3695
3725
  feeRevision?: number;
3696
3726
  historical?: boolean;
3727
+ independentLiabilities?: number;
3728
+ liabilityRevision?: number;
3697
3729
  observations: Array<{
3698
3730
  currency: string;
3699
3731
  ledgerFingerprint: string;
@@ -3711,6 +3743,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3711
3743
  requestId: string;
3712
3744
  };
3713
3745
  returnTransactionId?: string;
3746
+ snapshotId?: string;
3714
3747
  status:
3715
3748
  | "reserved"
3716
3749
  | "submitted"
@@ -3731,6 +3764,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3731
3764
  currency: string;
3732
3765
  expectedRevision: number;
3733
3766
  independentLiabilities: number;
3767
+ liabilityRevision?: number;
3734
3768
  observations: Array<{
3735
3769
  currency: string;
3736
3770
  ledgerFingerprint: string;
@@ -3742,6 +3776,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3742
3776
  }>;
3743
3777
  ownerKey: string;
3744
3778
  providerAvailable: number;
3779
+ snapshotId?: string;
3745
3780
  },
3746
3781
  | { amount: 0; reason: string; status: "held" }
3747
3782
  | {
@@ -3799,6 +3834,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3799
3834
  expectedRevision: number;
3800
3835
  feeRevision?: number;
3801
3836
  historical?: boolean;
3837
+ independentLiabilities?: number;
3838
+ liabilityRevision?: number;
3802
3839
  observations: Array<{
3803
3840
  currency: string;
3804
3841
  ledgerFingerprint: string;
@@ -3816,6 +3853,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3816
3853
  requestId: string;
3817
3854
  };
3818
3855
  returnTransactionId?: string;
3856
+ snapshotId?: string;
3819
3857
  status:
3820
3858
  | "reserved"
3821
3859
  | "submitted"
@@ -3868,6 +3906,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3868
3906
  accountId: string;
3869
3907
  allocationCount: number;
3870
3908
  allocationCursor?: string;
3909
+ boundOperationKey?: string;
3910
+ boundRiskRevision?: number;
3871
3911
  claimCount: number;
3872
3912
  claimCursor?: string;
3873
3913
  deferredPositiveChanges: boolean;
@@ -3918,6 +3958,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3918
3958
  accountId: string;
3919
3959
  allocationCount: number;
3920
3960
  allocationCursor?: string;
3961
+ boundOperationKey?: string;
3962
+ boundRiskRevision?: number;
3921
3963
  claimCount: number;
3922
3964
  claimCursor?: string;
3923
3965
  deferredPositiveChanges: boolean;
@@ -3968,6 +4010,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3968
4010
  accountId: string;
3969
4011
  allocationCount: number;
3970
4012
  allocationCursor?: string;
4013
+ boundOperationKey?: string;
4014
+ boundRiskRevision?: number;
3971
4015
  claimCount: number;
3972
4016
  claimCursor?: string;
3973
4017
  deferredPositiveChanges: boolean;
@@ -4004,6 +4048,165 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
4004
4048
  Name
4005
4049
  >;
4006
4050
  };
4051
+ queries: {
4052
+ claims: FunctionReference<
4053
+ "query",
4054
+ "internal",
4055
+ {
4056
+ accountId: string;
4057
+ operationKey: string;
4058
+ ownerKey: string;
4059
+ paginationOpts: {
4060
+ cursor: string | null;
4061
+ endCursor?: string | null;
4062
+ id?: number;
4063
+ maximumBytesRead?: number;
4064
+ maximumRowsRead?: number;
4065
+ numItems: number;
4066
+ };
4067
+ },
4068
+ {
4069
+ continueCursor: string;
4070
+ isDone: boolean;
4071
+ page: Array<{
4072
+ _creationTime: number;
4073
+ _id: string;
4074
+ accountId: string;
4075
+ allocations: Array<{
4076
+ amount: number;
4077
+ role?: "store" | "affiliate" | "other";
4078
+ stripeTransferId: string;
4079
+ }>;
4080
+ amount: number;
4081
+ attemptedAt?: number;
4082
+ currency: string;
4083
+ debitFee?: number;
4084
+ debitTransactionId?: string;
4085
+ destinationId?: string;
4086
+ expectedRevision: number;
4087
+ feeRevision?: number;
4088
+ historical?: boolean;
4089
+ independentLiabilities?: number;
4090
+ liabilityRevision?: number;
4091
+ observations: Array<{
4092
+ currency: string;
4093
+ ledgerFingerprint: string;
4094
+ matureNet: number;
4095
+ observedAt: number;
4096
+ pendingCredits: number;
4097
+ stripeTransferId: string;
4098
+ transactionIds: Array<string>;
4099
+ }>;
4100
+ operationKey: string;
4101
+ ownerKey: string;
4102
+ providerFee?: number;
4103
+ rejection?: {
4104
+ code: "balance_insufficient" | "amount_too_small";
4105
+ requestId: string;
4106
+ };
4107
+ returnTransactionId?: string;
4108
+ snapshotId?: string;
4109
+ status:
4110
+ | "reserved"
4111
+ | "submitted"
4112
+ | "paid"
4113
+ | "returned"
4114
+ | "canceled"
4115
+ | "rejected";
4116
+ stripePayoutId?: string;
4117
+ }>;
4118
+ },
4119
+ Name
4120
+ >;
4121
+ get: FunctionReference<
4122
+ "query",
4123
+ "internal",
4124
+ { accountId: string; operationKey: string; ownerKey: string },
4125
+ {
4126
+ _creationTime: number;
4127
+ _id: string;
4128
+ accountId: string;
4129
+ allocationCount: number;
4130
+ allocationCursor?: string;
4131
+ boundOperationKey?: string;
4132
+ boundRiskRevision?: number;
4133
+ claimCount: number;
4134
+ claimCursor?: string;
4135
+ deferredPositiveChanges: boolean;
4136
+ expectedRevision: number;
4137
+ expiresAt: number;
4138
+ feeCount: number;
4139
+ feeCursor?: string;
4140
+ initialRevision: number;
4141
+ initialRiskRevision: number;
4142
+ observedRevision: number;
4143
+ operationKey: string;
4144
+ ownerKey: string;
4145
+ phase:
4146
+ | "sources"
4147
+ | "allocations"
4148
+ | "fees"
4149
+ | "claims"
4150
+ | "repair"
4151
+ | "check"
4152
+ | "local_ready"
4153
+ | "invalidated"
4154
+ | "discarding";
4155
+ policyMode?: string;
4156
+ policyOperationKey?: string;
4157
+ providerChanged: boolean;
4158
+ readOnly: boolean;
4159
+ reason?: string;
4160
+ riskRevision: number;
4161
+ sourceCount: number;
4162
+ sourceCursor?: string;
4163
+ sourceFence: number;
4164
+ step: number;
4165
+ } | null,
4166
+ Name
4167
+ >;
4168
+ sources: FunctionReference<
4169
+ "query",
4170
+ "internal",
4171
+ {
4172
+ accountId: string;
4173
+ operationKey: string;
4174
+ ownerKey: string;
4175
+ paginationOpts: {
4176
+ cursor: string | null;
4177
+ endCursor?: string | null;
4178
+ id?: number;
4179
+ maximumBytesRead?: number;
4180
+ maximumRowsRead?: number;
4181
+ numItems: number;
4182
+ };
4183
+ },
4184
+ {
4185
+ continueCursor: string;
4186
+ isDone: boolean;
4187
+ page: Array<{
4188
+ _creationTime: number;
4189
+ _id: string;
4190
+ amount: number;
4191
+ currency: string;
4192
+ destinationAccountId: string;
4193
+ metadata?: any;
4194
+ paymentId?: string;
4195
+ reinstatement?: boolean;
4196
+ reversalClaimedAmount?: number;
4197
+ reversalStatus?: "partially_reversed" | "fully_reversed";
4198
+ reversedAmount?: number;
4199
+ role?: "store" | "affiliate" | "other";
4200
+ sourceChargeId?: string;
4201
+ sourceInvoiceId?: string;
4202
+ status: "pending" | "paid" | "failed" | "reversed";
4203
+ stripeTransferId: string;
4204
+ totalsRecorded?: true;
4205
+ }>;
4206
+ },
4207
+ Name
4208
+ >;
4209
+ };
4007
4210
  };
4008
4211
  payoutSync: {
4009
4212
  mutations: {
@@ -1,7 +1,7 @@
1
1
  import { importOpeningClaim } from "./imports.js";
2
2
  import { getGroup, integer } from "./helpers.js";
3
3
  import { v } from "convex/values";
4
- import { mutation } from "../_generated/server.js";
4
+ import { mutation } from "../earnings/triggers.js";
5
5
  import { recordClaim, rollbackClaim } from "./claims.js";
6
6
  import { reserveGroup, sealGroup } from "./reservations.js";
7
7
  import { finishGroup } from "./completion.js";
@@ -1,3 +1,4 @@
1
+ import { riskRevision } from "../payoutSnapshots/revisions.js";
1
2
  import { paginator } from "convex-helpers/server/pagination";
2
3
  import schema from "../schema.js";
3
4
  import { paginationOptsValidator } from "convex/server";
@@ -88,3 +89,23 @@ export const claim = query({
88
89
  .withIndex("by_key", (q) => q.eq("claimKey", args.claimKey))
89
90
  .unique(),
90
91
  });
92
+
93
+ /** Amount and account version come from the same database snapshot. Host authorizes this scope. */
94
+ export const payoutQuote = query({
95
+ args: scopeFields,
96
+ returns: v.object({
97
+ independentLiabilities: v.number(),
98
+ liabilityRevision: v.number(),
99
+ }),
100
+ handler: async (ctx, args) => {
101
+ validateScope(args);
102
+ const balance = await readBalance(ctx, args);
103
+ const amount = (balance?.amountDue ?? 0) - (balance?.collectedAmount ?? 0);
104
+ if (!Number.isSafeInteger(amount))
105
+ throw new Error("Invalid payout recovery liability.");
106
+ return {
107
+ independentLiabilities: Math.max(0, amount),
108
+ liabilityRevision: await riskRevision(ctx, args.accountId),
109
+ };
110
+ },
111
+ });
@@ -72,24 +72,29 @@ export async function checkSnapshot(
72
72
  observations: Infer<typeof observation>[],
73
73
  fresh: boolean,
74
74
  freshCurrency?: string,
75
+ membership?: Map<string, Doc<"transfers">>,
75
76
  ) {
76
- const rows = await ctx.db
77
- .query("transfers")
78
- .withIndex("by_destination_account_id", (q) =>
79
- q.eq("destinationAccountId", accountId),
80
- )
81
- .take(101);
77
+ const rows = membership
78
+ ? [...membership.values()]
79
+ : await ctx.db
80
+ .query("transfers")
81
+ .withIndex("by_destination_account_id", (q) =>
82
+ q.eq("destinationAccountId", accountId),
83
+ )
84
+ .take(101);
82
85
  if (
83
- rows.length > 100 ||
86
+ (!membership && rows.length > 100) ||
84
87
  observations.length !== rows.length ||
85
88
  new Set(observations.map((o) => o.stripeTransferId)).size !== rows.length
86
89
  )
87
90
  throw new Error("Payout source snapshot is incomplete or duplicated.");
88
91
  const byId = new Map(rows.map((row) => [row.stripeTransferId, row]));
89
- const allocated = await ctx.db
90
- .query("payoutSourceAllocations")
91
- .withIndex("by_account", (q) => q.eq("accountId", accountId))
92
- .take(101);
92
+ const allocated = membership
93
+ ? []
94
+ : await ctx.db
95
+ .query("payoutSourceAllocations")
96
+ .withIndex("by_account", (q) => q.eq("accountId", accountId))
97
+ .take(101);
93
98
  if (
94
99
  allocated.length > 100 ||
95
100
  allocated.some((source) => !byId.has(source.stripeTransferId))
@@ -179,6 +184,9 @@ export function payoutClaimFingerprint(c: Doc<"payoutReleaseClaims">) {
179
184
  c.ownerKey,
180
185
  c.operationKey,
181
186
  c.historical ?? false,
187
+ c.snapshotId,
188
+ c.liabilityRevision,
189
+ c.independentLiabilities,
182
190
  c.currency,
183
191
  c.amount,
184
192
  c.status,
@@ -1,3 +1,8 @@
1
+ import {
2
+ collectedSources,
3
+ bindCollection,
4
+ retireCollection,
5
+ } from "../payoutSnapshots/financial.js";
1
6
  import {
2
7
  reserveRecoveryGuard,
3
8
  releaseRecoveryGuard,
@@ -43,6 +48,8 @@ export const claim = mutation({
43
48
  providerAvailable: v.number(),
44
49
  independentLiabilities: v.number(),
45
50
  observations: v.array(observation),
51
+ snapshotId: v.optional(v.id("payoutSnapshots")),
52
+ liabilityRevision: v.optional(v.number()),
46
53
  },
47
54
  returns: v.union(claimDoc, held),
48
55
  handler: async (ctx, args) => {
@@ -106,10 +113,17 @@ export const claim = mutation({
106
113
  ...(args.destinationId ? { destinationId: args.destinationId } : {}),
107
114
  allocations: plan.allocations,
108
115
  observations: args.observations,
116
+ independentLiabilities: args.independentLiabilities,
117
+ ...(args.snapshotId ? { snapshotId: args.snapshotId } : {}),
118
+ ...(args.liabilityRevision === undefined
119
+ ? {}
120
+ : { liabilityRevision: args.liabilityRevision }),
109
121
  feeRevision: fees?.revision ?? 0,
110
122
  status: "reserved",
111
123
  });
112
- return (await ctx.db.get("payoutReleaseClaims", id))!;
124
+ const claim = (await ctx.db.get("payoutReleaseClaims", id))!;
125
+ await bindCollection(ctx, claim);
126
+ return claim;
113
127
  },
114
128
  });
115
129
  export const beginAttempt = mutation({
@@ -130,11 +144,13 @@ export const beginAttempt = mutation({
130
144
  claim.observations,
131
145
  true,
132
146
  claim.currency,
147
+ await collectedSources(ctx, claim, claim.observations),
133
148
  );
134
149
  await reserveRecoveryGuard(ctx, claim, claim.amount);
135
150
  await ctx.db.patch("payoutReleaseClaims", claim._id, {
136
151
  attemptedAt: Date.now(),
137
152
  });
153
+ await retireCollection(ctx, claim);
138
154
  return (await ctx.db.get("payoutReleaseClaims", claim._id))!;
139
155
  },
140
156
  });
@@ -151,6 +167,7 @@ export const cancelUnattempted = mutation({
151
167
  throw new Error("An attempted payout claim cannot be canceled.");
152
168
  if (claim.status === "canceled") return claim;
153
169
  await moveAllocations(ctx, claim, "release");
170
+ await retireCollection(ctx, claim);
154
171
  await releaseRecoveryGuard(ctx, claim);
155
172
  await ctx.db.patch("payoutReleaseClaims", claim._id, {
156
173
  status: "canceled",
@@ -1,3 +1,5 @@
1
+ import { collectedSources } from "../payoutSnapshots/financial.js";
2
+ import type { Id } from "../_generated/dataModel.js";
1
3
  import type { Infer } from "convex/values";
2
4
  import type { MutationCtx, QueryCtx } from "../_generated/server.js";
3
5
  import type { policyDoc } from "../payoutPolicy/schema.js";
@@ -14,6 +16,9 @@ export async function readPayoutPlan(
14
16
  ownerKey: string;
15
17
  currency: string;
16
18
  observations: Infer<typeof observation>[];
19
+ snapshotId?: Id<"payoutSnapshots">;
20
+ operationKey?: string;
21
+ liabilityRevision?: number;
17
22
  providerAvailable: number;
18
23
  independentLiabilities: number;
19
24
  },
@@ -27,6 +32,7 @@ export async function readPayoutPlan(
27
32
  args.observations,
28
33
  true,
29
34
  args.currency,
35
+ await collectedSources(ctx, args, args.observations),
30
36
  );
31
37
  const sources: PayoutFundingSource[] = [];
32
38
  for (const observation of args.observations) {
@@ -46,7 +52,7 @@ export async function readPayoutPlan(
46
52
  });
47
53
  }
48
54
  const fees = await readFees(ctx, args);
49
- await assertAllocationTotals(ctx, args, sources);
55
+ if (!args.snapshotId) await assertAllocationTotals(ctx, args, sources);
50
56
  const minimumWaived = waiveApplicationMinimum(policy, Date.now());
51
57
  const plan = planRecipientPayout({
52
58
  currency: args.currency,
@@ -14,6 +14,8 @@ export const previewFields = {
14
14
  providerAvailable: v.number(),
15
15
  independentLiabilities: v.number(),
16
16
  observations: v.array(observation),
17
+ snapshotId: v.optional(v.id("payoutSnapshots")),
18
+ liabilityRevision: v.optional(v.number()),
17
19
  };
18
20
  const held = v.object({
19
21
  status: v.literal("held"),
@@ -13,6 +13,9 @@ export const allocation = v.object({
13
13
  export const claimFields = {
14
14
  ...scopeFields,
15
15
  historical: v.optional(v.boolean()),
16
+ snapshotId: v.optional(v.id("payoutSnapshots")),
17
+ liabilityRevision: v.optional(v.number()),
18
+ independentLiabilities: v.optional(v.number()),
16
19
  operationKey: v.string(),
17
20
  expectedRevision: v.number(),
18
21
  currency: v.string(),