@fantastic.dev/better-stripe 0.28.6 → 0.30.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 (222) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/MIGRATION.md +14 -0
  3. package/README.md +7 -1
  4. package/dist/client/connect/payoutActivationProof.d.ts.map +1 -1
  5. package/dist/client/connect/payoutActivationProof.js +88 -42
  6. package/dist/client/connect/payoutActivationProof.js.map +1 -1
  7. package/dist/client/connect/payoutAdoption.d.ts +3 -0
  8. package/dist/client/connect/payoutAdoption.d.ts.map +1 -1
  9. package/dist/client/connect/payoutAdoption.js +218 -183
  10. package/dist/client/connect/payoutAdoption.js.map +1 -1
  11. package/dist/client/connect/payoutAdoptionCollection.d.ts +21 -0
  12. package/dist/client/connect/payoutAdoptionCollection.d.ts.map +1 -0
  13. package/dist/client/connect/payoutAdoptionCollection.js +44 -0
  14. package/dist/client/connect/payoutAdoptionCollection.js.map +1 -0
  15. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +54 -14
  16. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  17. package/dist/client/connect/payoutCollectedInput.d.ts +110 -0
  18. package/dist/client/connect/payoutCollectedInput.d.ts.map +1 -0
  19. package/dist/client/connect/payoutCollectedInput.js +70 -0
  20. package/dist/client/connect/payoutCollectedInput.js.map +1 -0
  21. package/dist/client/connect/payoutExecution.d.ts +1 -0
  22. package/dist/client/connect/payoutExecution.d.ts.map +1 -1
  23. package/dist/client/connect/payoutExecution.js +94 -67
  24. package/dist/client/connect/payoutExecution.js.map +1 -1
  25. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +29 -7
  26. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  27. package/dist/client/connect/payoutExecutionTestHelpers.js +9 -6
  28. package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -1
  29. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +3745 -0
  30. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -0
  31. package/dist/client/connect/payoutLargeAdoptionTestHelpers.js +55 -0
  32. package/dist/client/connect/payoutLargeAdoptionTestHelpers.js.map +1 -0
  33. package/dist/client/connect/payoutOutcomeBatches.d.ts +5 -0
  34. package/dist/client/connect/payoutOutcomeBatches.d.ts.map +1 -0
  35. package/dist/client/connect/payoutOutcomeBatches.js +21 -0
  36. package/dist/client/connect/payoutOutcomeBatches.js.map +1 -0
  37. package/dist/client/connect/payoutPolicyState.d.ts +14 -0
  38. package/dist/client/connect/payoutPolicyState.d.ts.map +1 -0
  39. package/dist/client/connect/payoutPolicyState.js +19 -0
  40. package/dist/client/connect/payoutPolicyState.js.map +1 -0
  41. package/dist/client/connect/payoutPreview.d.ts +1 -0
  42. package/dist/client/connect/payoutPreview.d.ts.map +1 -1
  43. package/dist/client/connect/payoutPreview.js +31 -19
  44. package/dist/client/connect/payoutPreview.js.map +1 -1
  45. package/dist/client/connect/payoutQualification.d.ts +7 -1
  46. package/dist/client/connect/payoutQualification.d.ts.map +1 -1
  47. package/dist/client/connect/payoutQualification.js +34 -19
  48. package/dist/client/connect/payoutQualification.js.map +1 -1
  49. package/dist/client/connect/payoutReconciliation.d.ts +11 -6
  50. package/dist/client/connect/payoutReconciliation.d.ts.map +1 -1
  51. package/dist/client/connect/payoutReconciliation.js +62 -16
  52. package/dist/client/connect/payoutReconciliation.js.map +1 -1
  53. package/dist/client/connect/payoutResumableProof.d.ts +17 -0
  54. package/dist/client/connect/payoutResumableProof.d.ts.map +1 -0
  55. package/dist/client/connect/payoutResumableProof.js +25 -0
  56. package/dist/client/connect/payoutResumableProof.js.map +1 -0
  57. package/dist/client/connect/payoutSyncTestHelpers.d.ts +27 -7
  58. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  59. package/dist/client/connect/payoutWorker.d.ts.map +1 -1
  60. package/dist/client/connect/payoutWorker.js +4 -1
  61. package/dist/client/connect/payoutWorker.js.map +1 -1
  62. package/dist/client/connect/transferReceipt.d.ts +6 -2
  63. package/dist/client/connect/transferReceipt.d.ts.map +1 -1
  64. package/dist/client/connect/transferReceipt.js +3 -3
  65. package/dist/client/connect/transferReceipt.js.map +1 -1
  66. package/dist/client/costRecovery.d.ts +5 -0
  67. package/dist/client/costRecovery.d.ts.map +1 -1
  68. package/dist/client/costRecovery.js +5 -0
  69. package/dist/client/costRecovery.js.map +1 -1
  70. package/dist/client/payoutPolicy.d.ts +4 -0
  71. package/dist/client/payoutPolicy.d.ts.map +1 -1
  72. package/dist/client/payoutPolicy.js +24 -14
  73. package/dist/client/payoutPolicy.js.map +1 -1
  74. package/dist/component/_generated/component.d.ts +247 -0
  75. package/dist/component/_generated/component.d.ts.map +1 -1
  76. package/dist/component/costRecovery/mutations.js +1 -1
  77. package/dist/component/costRecovery/queries.d.ts +9 -0
  78. package/dist/component/costRecovery/queries.d.ts.map +1 -1
  79. package/dist/component/costRecovery/queries.js +20 -0
  80. package/dist/component/costRecovery/queries.js.map +1 -1
  81. package/dist/component/earnings/triggers.d.ts +28 -10
  82. package/dist/component/earnings/triggers.d.ts.map +1 -1
  83. package/dist/component/payoutPolicy/adoption.d.ts.map +1 -1
  84. package/dist/component/payoutPolicy/adoption.js +12 -7
  85. package/dist/component/payoutPolicy/adoption.js.map +1 -1
  86. package/dist/component/payoutPolicy/mutations.d.ts +12 -0
  87. package/dist/component/payoutPolicy/mutations.d.ts.map +1 -1
  88. package/dist/component/payoutPolicy/queries.d.ts +2 -0
  89. package/dist/component/payoutPolicy/queries.d.ts.map +1 -1
  90. package/dist/component/payoutPolicy/schema.d.ts +31 -7
  91. package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
  92. package/dist/component/payoutPolicy/schema.js +2 -0
  93. package/dist/component/payoutPolicy/schema.js.map +1 -1
  94. package/dist/component/payoutRelease/adoption.d.ts +9 -1
  95. package/dist/component/payoutRelease/adoption.d.ts.map +1 -1
  96. package/dist/component/payoutRelease/adoption.js +33 -16
  97. package/dist/component/payoutRelease/adoption.js.map +1 -1
  98. package/dist/component/payoutRelease/fees.d.ts.map +1 -1
  99. package/dist/component/payoutRelease/fees.js +7 -0
  100. package/dist/component/payoutRelease/fees.js.map +1 -1
  101. package/dist/component/payoutRelease/helpers.d.ts +4 -1
  102. package/dist/component/payoutRelease/helpers.d.ts.map +1 -1
  103. package/dist/component/payoutRelease/helpers.js +17 -10
  104. package/dist/component/payoutRelease/helpers.js.map +1 -1
  105. package/dist/component/payoutRelease/mutations.d.ts +79 -0
  106. package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
  107. package/dist/component/payoutRelease/mutations.js +38 -81
  108. package/dist/component/payoutRelease/mutations.js.map +1 -1
  109. package/dist/component/payoutRelease/outcome.d.ts +69 -0
  110. package/dist/component/payoutRelease/outcome.d.ts.map +1 -0
  111. package/dist/component/payoutRelease/outcome.js +94 -0
  112. package/dist/component/payoutRelease/outcome.js.map +1 -0
  113. package/dist/component/payoutRelease/planning.d.ts +4 -0
  114. package/dist/component/payoutRelease/planning.d.ts.map +1 -1
  115. package/dist/component/payoutRelease/planning.js +8 -3
  116. package/dist/component/payoutRelease/planning.js.map +1 -1
  117. package/dist/component/payoutRelease/preview.d.ts +2 -0
  118. package/dist/component/payoutRelease/preview.d.ts.map +1 -1
  119. package/dist/component/payoutRelease/preview.js +2 -0
  120. package/dist/component/payoutRelease/preview.js.map +1 -1
  121. package/dist/component/payoutRelease/queries.d.ts +13 -2
  122. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  123. package/dist/component/payoutRelease/queries.js +2 -0
  124. package/dist/component/payoutRelease/queries.js.map +1 -1
  125. package/dist/component/payoutRelease/schema.d.ts +17 -2
  126. package/dist/component/payoutRelease/schema.d.ts.map +1 -1
  127. package/dist/component/payoutRelease/schema.js +3 -0
  128. package/dist/component/payoutRelease/schema.js.map +1 -1
  129. package/dist/component/payoutSnapshots/adoption.d.ts +88 -0
  130. package/dist/component/payoutSnapshots/adoption.d.ts.map +1 -0
  131. package/dist/component/payoutSnapshots/adoption.js +49 -0
  132. package/dist/component/payoutSnapshots/adoption.js.map +1 -0
  133. package/dist/component/payoutSnapshots/financial.d.ts +47 -0
  134. package/dist/component/payoutSnapshots/financial.d.ts.map +1 -0
  135. package/dist/component/payoutSnapshots/financial.js +103 -0
  136. package/dist/component/payoutSnapshots/financial.js.map +1 -0
  137. package/dist/component/payoutSnapshots/liabilities.d.ts +7 -0
  138. package/dist/component/payoutSnapshots/liabilities.d.ts.map +1 -0
  139. package/dist/component/payoutSnapshots/liabilities.js +18 -0
  140. package/dist/component/payoutSnapshots/liabilities.js.map +1 -0
  141. package/dist/component/payoutSnapshots/localState.d.ts +22 -16
  142. package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
  143. package/dist/component/payoutSnapshots/localState.js +19 -7
  144. package/dist/component/payoutSnapshots/localState.js.map +1 -1
  145. package/dist/component/payoutSnapshots/mutations.d.ts +6 -0
  146. package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
  147. package/dist/component/payoutSnapshots/mutations.js +3 -1
  148. package/dist/component/payoutSnapshots/mutations.js.map +1 -1
  149. package/dist/component/payoutSnapshots/queries.d.ts +133 -0
  150. package/dist/component/payoutSnapshots/queries.d.ts.map +1 -0
  151. package/dist/component/payoutSnapshots/queries.js +86 -0
  152. package/dist/component/payoutSnapshots/queries.js.map +1 -0
  153. package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -1
  154. package/dist/component/payoutSnapshots/revisions.js +19 -0
  155. package/dist/component/payoutSnapshots/revisions.js.map +1 -1
  156. package/dist/component/payoutSnapshots/schema.d.ts +20 -6
  157. package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
  158. package/dist/component/payoutSnapshots/schema.js +5 -1
  159. package/dist/component/payoutSnapshots/schema.js.map +1 -1
  160. package/dist/component/payoutWorker/mutations.d.ts.map +1 -1
  161. package/dist/component/payoutWorker/mutations.js +3 -1
  162. package/dist/component/payoutWorker/mutations.js.map +1 -1
  163. package/dist/component/schema.d.ts +27 -7
  164. package/dist/react/workflows/payout-attempt-state.d.ts.map +1 -1
  165. package/dist/react/workflows/payout-attempt-state.js +3 -0
  166. package/dist/react/workflows/payout-attempt-state.js.map +1 -1
  167. package/dist/react/workflows/payout-progress-state.d.ts.map +1 -1
  168. package/dist/react/workflows/payout-progress-state.js +3 -0
  169. package/dist/react/workflows/payout-progress-state.js.map +1 -1
  170. package/docs/settlement.md +136 -24
  171. package/package.json +1 -1
  172. package/src/client/connect/payoutActivationProof.ts +123 -53
  173. package/src/client/connect/payoutAdoption.ts +299 -215
  174. package/src/client/connect/payoutAdoptionCollection.ts +78 -0
  175. package/src/client/connect/payoutAdoptionConcurrency.test.ts +266 -0
  176. package/src/client/connect/payoutCacheIdentity.test.ts +93 -0
  177. package/src/client/connect/payoutCollectedInput.ts +120 -0
  178. package/src/client/connect/payoutExecution.ts +116 -84
  179. package/src/client/connect/payoutExecutionTestHelpers.ts +19 -6
  180. package/src/client/connect/payoutLargeAdoption.test.ts +541 -0
  181. package/src/client/connect/payoutLargeAdoptionTestHelpers.ts +74 -0
  182. package/src/client/connect/payoutLargeHistory.test.ts +222 -0
  183. package/src/client/connect/payoutLiabilityVersion.test.ts +221 -0
  184. package/src/client/connect/payoutOutcomeBatches.test.ts +40 -0
  185. package/src/client/connect/payoutOutcomeBatches.ts +24 -0
  186. package/src/client/connect/payoutPolicyState.ts +36 -0
  187. package/src/client/connect/payoutPreview.ts +42 -24
  188. package/src/client/connect/payoutQualification.ts +68 -21
  189. package/src/client/connect/payoutReconciliation.ts +86 -7
  190. package/src/client/connect/payoutResumableProof.ts +41 -0
  191. package/src/client/connect/payoutWorker.ts +4 -1
  192. package/src/client/connect/transferReceipt.ts +3 -2
  193. package/src/client/connect/transferReceiptBaseline.test.ts +55 -0
  194. package/src/client/costRecovery.ts +8 -0
  195. package/src/client/payoutPolicy.ts +37 -23
  196. package/src/component/_generated/api.ts +10 -0
  197. package/src/component/_generated/component.ts +288 -0
  198. package/src/component/costRecovery/mutations.ts +1 -1
  199. package/src/component/costRecovery/queries.ts +21 -0
  200. package/src/component/payout-snapshots.test.ts +45 -1
  201. package/src/component/payoutPolicy/adoption.ts +20 -7
  202. package/src/component/payoutPolicy/schema.ts +2 -0
  203. package/src/component/payoutRelease/adoption.ts +57 -27
  204. package/src/component/payoutRelease/fees.ts +9 -0
  205. package/src/component/payoutRelease/helpers.ts +19 -11
  206. package/src/component/payoutRelease/mutations.ts +43 -96
  207. package/src/component/payoutRelease/outcome.ts +119 -0
  208. package/src/component/payoutRelease/planning.ts +11 -2
  209. package/src/component/payoutRelease/preview.ts +2 -0
  210. package/src/component/payoutRelease/queries.ts +2 -0
  211. package/src/component/payoutRelease/schema.ts +3 -0
  212. package/src/component/payoutSnapshots/adoption.ts +73 -0
  213. package/src/component/payoutSnapshots/financial.ts +134 -0
  214. package/src/component/payoutSnapshots/liabilities.ts +25 -0
  215. package/src/component/payoutSnapshots/localState.ts +24 -6
  216. package/src/component/payoutSnapshots/mutations.ts +10 -1
  217. package/src/component/payoutSnapshots/queries.ts +104 -0
  218. package/src/component/payoutSnapshots/revisions.ts +26 -0
  219. package/src/component/payoutSnapshots/schema.ts +5 -0
  220. package/src/component/payoutWorker/mutations.ts +3 -1
  221. package/src/react/workflows/payout-attempt-state.ts +6 -0
  222. package/src/react/workflows/payout-progress-state.ts +6 -0
@@ -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",
@@ -2731,6 +2738,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2731
2738
  accountId: string;
2732
2739
  adoption?: {
2733
2740
  claims: Array<{ fingerprint: string; operationKey: string }>;
2741
+ collectionKey?: string;
2734
2742
  observations: Array<{
2735
2743
  currency: string;
2736
2744
  ledgerFingerprint: string;
@@ -2741,6 +2749,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2741
2749
  transactionIds: Array<string>;
2742
2750
  }>;
2743
2751
  oldestHeldAt?: number;
2752
+ snapshotId?: string;
2744
2753
  };
2745
2754
  operationKey: string;
2746
2755
  ownerKey: string;
@@ -2751,6 +2760,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2751
2760
  accountId: string;
2752
2761
  adoption?: {
2753
2762
  claims: Array<{ fingerprint: string; operationKey: string }>;
2763
+ collectionKey?: string;
2754
2764
  observations: Array<{
2755
2765
  currency: string;
2756
2766
  ledgerFingerprint: string;
@@ -2761,6 +2771,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2761
2771
  transactionIds: Array<string>;
2762
2772
  }>;
2763
2773
  oldestHeldAt?: number;
2774
+ snapshotId?: string;
2764
2775
  };
2765
2776
  attempted?: boolean;
2766
2777
  country: string;
@@ -2847,6 +2858,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2847
2858
  accountId: string;
2848
2859
  adoption?: {
2849
2860
  claims: Array<{ fingerprint: string; operationKey: string }>;
2861
+ collectionKey?: string;
2850
2862
  observations: Array<{
2851
2863
  currency: string;
2852
2864
  ledgerFingerprint: string;
@@ -2857,6 +2869,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2857
2869
  transactionIds: Array<string>;
2858
2870
  }>;
2859
2871
  oldestHeldAt?: number;
2872
+ snapshotId?: string;
2860
2873
  };
2861
2874
  attempted?: boolean;
2862
2875
  country: string;
@@ -2905,6 +2918,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2905
2918
  accountId: string;
2906
2919
  adoption?: {
2907
2920
  claims: Array<{ fingerprint: string; operationKey: string }>;
2921
+ collectionKey?: string;
2908
2922
  observations: Array<{
2909
2923
  currency: string;
2910
2924
  ledgerFingerprint: string;
@@ -2915,6 +2929,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
2915
2929
  transactionIds: Array<string>;
2916
2930
  }>;
2917
2931
  oldestHeldAt?: number;
2932
+ snapshotId?: string;
2918
2933
  };
2919
2934
  attempted?: boolean;
2920
2935
  country: string;
@@ -3000,6 +3015,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3000
3015
  accountId: string;
3001
3016
  adoption?: {
3002
3017
  claims: Array<{ fingerprint: string; operationKey: string }>;
3018
+ collectionKey?: string;
3003
3019
  observations: Array<{
3004
3020
  currency: string;
3005
3021
  ledgerFingerprint: string;
@@ -3010,6 +3026,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3010
3026
  transactionIds: Array<string>;
3011
3027
  }>;
3012
3028
  oldestHeldAt?: number;
3029
+ snapshotId?: string;
3013
3030
  };
3014
3031
  country: string;
3015
3032
  expectedRevision: number;
@@ -3030,6 +3047,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3030
3047
  accountId: string;
3031
3048
  adoption?: {
3032
3049
  claims: Array<{ fingerprint: string; operationKey: string }>;
3050
+ collectionKey?: string;
3033
3051
  observations: Array<{
3034
3052
  currency: string;
3035
3053
  ledgerFingerprint: string;
@@ -3040,6 +3058,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3040
3058
  transactionIds: Array<string>;
3041
3059
  }>;
3042
3060
  oldestHeldAt?: number;
3061
+ snapshotId?: string;
3043
3062
  };
3044
3063
  attempted?: boolean;
3045
3064
  country: string;
@@ -3171,6 +3190,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3171
3190
  accountId: string;
3172
3191
  adoption?: {
3173
3192
  claims: Array<{ fingerprint: string; operationKey: string }>;
3193
+ collectionKey?: string;
3174
3194
  observations: Array<{
3175
3195
  currency: string;
3176
3196
  ledgerFingerprint: string;
@@ -3181,6 +3201,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3181
3201
  transactionIds: Array<string>;
3182
3202
  }>;
3183
3203
  oldestHeldAt?: number;
3204
+ snapshotId?: string;
3184
3205
  };
3185
3206
  attempted?: boolean;
3186
3207
  country: string;
@@ -3253,6 +3274,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3253
3274
  stripePayoutId: string;
3254
3275
  };
3255
3276
  }>;
3277
+ snapshotId?: string;
3256
3278
  },
3257
3279
  {
3258
3280
  claims: Array<{
@@ -3273,6 +3295,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3273
3295
  expectedRevision: number;
3274
3296
  feeRevision?: number;
3275
3297
  historical?: boolean;
3298
+ independentLiabilities?: number;
3299
+ liabilityRevision?: number;
3276
3300
  observations: Array<{
3277
3301
  currency: string;
3278
3302
  ledgerFingerprint: string;
@@ -3290,6 +3314,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3290
3314
  requestId: string;
3291
3315
  };
3292
3316
  returnTransactionId?: string;
3317
+ snapshotId?: string;
3293
3318
  status:
3294
3319
  | "reserved"
3295
3320
  | "submitted"
@@ -3324,6 +3349,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3324
3349
  expectedRevision: number;
3325
3350
  feeRevision?: number;
3326
3351
  historical?: boolean;
3352
+ independentLiabilities?: number;
3353
+ liabilityRevision?: number;
3327
3354
  observations: Array<{
3328
3355
  currency: string;
3329
3356
  ledgerFingerprint: string;
@@ -3341,6 +3368,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3341
3368
  requestId: string;
3342
3369
  };
3343
3370
  returnTransactionId?: string;
3371
+ snapshotId?: string;
3344
3372
  status:
3345
3373
  | "reserved"
3346
3374
  | "submitted"
@@ -3374,6 +3402,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3374
3402
  expectedRevision: number;
3375
3403
  feeRevision?: number;
3376
3404
  historical?: boolean;
3405
+ independentLiabilities?: number;
3406
+ liabilityRevision?: number;
3377
3407
  observations: Array<{
3378
3408
  currency: string;
3379
3409
  ledgerFingerprint: string;
@@ -3391,6 +3421,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3391
3421
  requestId: string;
3392
3422
  };
3393
3423
  returnTransactionId?: string;
3424
+ snapshotId?: string;
3394
3425
  status:
3395
3426
  | "reserved"
3396
3427
  | "submitted"
@@ -3411,6 +3442,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3411
3442
  destinationId?: string;
3412
3443
  expectedRevision: number;
3413
3444
  independentLiabilities: number;
3445
+ liabilityRevision?: number;
3414
3446
  observations: Array<{
3415
3447
  currency: string;
3416
3448
  ledgerFingerprint: string;
@@ -3423,6 +3455,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3423
3455
  operationKey: string;
3424
3456
  ownerKey: string;
3425
3457
  providerAvailable: number;
3458
+ snapshotId?: string;
3426
3459
  },
3427
3460
  | {
3428
3461
  _creationTime: number;
@@ -3442,6 +3475,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3442
3475
  expectedRevision: number;
3443
3476
  feeRevision?: number;
3444
3477
  historical?: boolean;
3478
+ independentLiabilities?: number;
3479
+ liabilityRevision?: number;
3445
3480
  observations: Array<{
3446
3481
  currency: string;
3447
3482
  ledgerFingerprint: string;
@@ -3459,6 +3494,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3459
3494
  requestId: string;
3460
3495
  };
3461
3496
  returnTransactionId?: string;
3497
+ snapshotId?: string;
3462
3498
  status:
3463
3499
  | "reserved"
3464
3500
  | "submitted"
@@ -3515,6 +3551,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3515
3551
  expectedRevision: number;
3516
3552
  feeRevision?: number;
3517
3553
  historical?: boolean;
3554
+ independentLiabilities?: number;
3555
+ liabilityRevision?: number;
3518
3556
  observations: Array<{
3519
3557
  currency: string;
3520
3558
  ledgerFingerprint: string;
@@ -3532,6 +3570,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3532
3570
  requestId: string;
3533
3571
  };
3534
3572
  returnTransactionId?: string;
3573
+ snapshotId?: string;
3535
3574
  status:
3536
3575
  | "reserved"
3537
3576
  | "submitted"
@@ -3543,6 +3582,76 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3543
3582
  },
3544
3583
  Name
3545
3584
  >;
3585
+ recordOutcomes: FunctionReference<
3586
+ "mutation",
3587
+ "internal",
3588
+ {
3589
+ accountId: string;
3590
+ outcomes: Array<{
3591
+ accountId: string;
3592
+ amount: number;
3593
+ currency: string;
3594
+ debitFee?: number;
3595
+ debitTransactionId?: string;
3596
+ operationKey: string;
3597
+ ownerKey: string;
3598
+ providerStatus:
3599
+ "pending" | "in_transit" | "paid" | "failed" | "canceled";
3600
+ returnFee?: number;
3601
+ returnTransactionId?: string;
3602
+ stripePayoutId: string;
3603
+ }>;
3604
+ ownerKey: string;
3605
+ },
3606
+ Array<{
3607
+ _creationTime: number;
3608
+ _id: string;
3609
+ accountId: string;
3610
+ allocations: Array<{
3611
+ amount: number;
3612
+ role?: "store" | "affiliate" | "other";
3613
+ stripeTransferId: string;
3614
+ }>;
3615
+ amount: number;
3616
+ attemptedAt?: number;
3617
+ currency: string;
3618
+ debitFee?: number;
3619
+ debitTransactionId?: string;
3620
+ destinationId?: string;
3621
+ expectedRevision: number;
3622
+ feeRevision?: number;
3623
+ historical?: boolean;
3624
+ independentLiabilities?: number;
3625
+ liabilityRevision?: number;
3626
+ observations: Array<{
3627
+ currency: string;
3628
+ ledgerFingerprint: string;
3629
+ matureNet: number;
3630
+ observedAt: number;
3631
+ pendingCredits: number;
3632
+ stripeTransferId: string;
3633
+ transactionIds: Array<string>;
3634
+ }>;
3635
+ operationKey: string;
3636
+ ownerKey: string;
3637
+ providerFee?: number;
3638
+ rejection?: {
3639
+ code: "balance_insufficient" | "amount_too_small";
3640
+ requestId: string;
3641
+ };
3642
+ returnTransactionId?: string;
3643
+ snapshotId?: string;
3644
+ status:
3645
+ | "reserved"
3646
+ | "submitted"
3647
+ | "paid"
3648
+ | "returned"
3649
+ | "canceled"
3650
+ | "rejected";
3651
+ stripePayoutId?: string;
3652
+ }>,
3653
+ Name
3654
+ >;
3546
3655
  recordRejection: FunctionReference<
3547
3656
  "mutation",
3548
3657
  "internal",
@@ -3571,6 +3680,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3571
3680
  expectedRevision: number;
3572
3681
  feeRevision?: number;
3573
3682
  historical?: boolean;
3683
+ independentLiabilities?: number;
3684
+ liabilityRevision?: number;
3574
3685
  observations: Array<{
3575
3686
  currency: string;
3576
3687
  ledgerFingerprint: string;
@@ -3588,6 +3699,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3588
3699
  requestId: string;
3589
3700
  };
3590
3701
  returnTransactionId?: string;
3702
+ snapshotId?: string;
3591
3703
  status:
3592
3704
  | "reserved"
3593
3705
  | "submitted"
@@ -3630,6 +3742,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3630
3742
  expectedRevision: number;
3631
3743
  feeRevision?: number;
3632
3744
  historical?: boolean;
3745
+ independentLiabilities?: number;
3746
+ liabilityRevision?: number;
3633
3747
  observations: Array<{
3634
3748
  currency: string;
3635
3749
  ledgerFingerprint: string;
@@ -3647,6 +3761,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3647
3761
  requestId: string;
3648
3762
  };
3649
3763
  returnTransactionId?: string;
3764
+ snapshotId?: string;
3650
3765
  status:
3651
3766
  | "reserved"
3652
3767
  | "submitted"
@@ -3694,6 +3809,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3694
3809
  expectedRevision: number;
3695
3810
  feeRevision?: number;
3696
3811
  historical?: boolean;
3812
+ independentLiabilities?: number;
3813
+ liabilityRevision?: number;
3697
3814
  observations: Array<{
3698
3815
  currency: string;
3699
3816
  ledgerFingerprint: string;
@@ -3711,6 +3828,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3711
3828
  requestId: string;
3712
3829
  };
3713
3830
  returnTransactionId?: string;
3831
+ snapshotId?: string;
3714
3832
  status:
3715
3833
  | "reserved"
3716
3834
  | "submitted"
@@ -3731,6 +3849,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3731
3849
  currency: string;
3732
3850
  expectedRevision: number;
3733
3851
  independentLiabilities: number;
3852
+ liabilityRevision?: number;
3734
3853
  observations: Array<{
3735
3854
  currency: string;
3736
3855
  ledgerFingerprint: string;
@@ -3742,6 +3861,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3742
3861
  }>;
3743
3862
  ownerKey: string;
3744
3863
  providerAvailable: number;
3864
+ snapshotId?: string;
3745
3865
  },
3746
3866
  | { amount: 0; reason: string; status: "held" }
3747
3867
  | {
@@ -3799,6 +3919,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3799
3919
  expectedRevision: number;
3800
3920
  feeRevision?: number;
3801
3921
  historical?: boolean;
3922
+ independentLiabilities?: number;
3923
+ liabilityRevision?: number;
3802
3924
  observations: Array<{
3803
3925
  currency: string;
3804
3926
  ledgerFingerprint: string;
@@ -3816,6 +3938,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3816
3938
  requestId: string;
3817
3939
  };
3818
3940
  returnTransactionId?: string;
3941
+ snapshotId?: string;
3819
3942
  status:
3820
3943
  | "reserved"
3821
3944
  | "submitted"
@@ -3868,6 +3991,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3868
3991
  accountId: string;
3869
3992
  allocationCount: number;
3870
3993
  allocationCursor?: string;
3994
+ boundOperationKey?: string;
3995
+ boundRiskRevision?: number;
3871
3996
  claimCount: number;
3872
3997
  claimCursor?: string;
3873
3998
  deferredPositiveChanges: boolean;
@@ -3918,6 +4043,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3918
4043
  accountId: string;
3919
4044
  allocationCount: number;
3920
4045
  allocationCursor?: string;
4046
+ boundOperationKey?: string;
4047
+ boundRiskRevision?: number;
3921
4048
  claimCount: number;
3922
4049
  claimCursor?: string;
3923
4050
  deferredPositiveChanges: boolean;
@@ -3968,6 +4095,8 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
3968
4095
  accountId: string;
3969
4096
  allocationCount: number;
3970
4097
  allocationCursor?: string;
4098
+ boundOperationKey?: string;
4099
+ boundRiskRevision?: number;
3971
4100
  claimCount: number;
3972
4101
  claimCursor?: string;
3973
4102
  deferredPositiveChanges: boolean;
@@ -4004,6 +4133,165 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
4004
4133
  Name
4005
4134
  >;
4006
4135
  };
4136
+ queries: {
4137
+ claims: FunctionReference<
4138
+ "query",
4139
+ "internal",
4140
+ {
4141
+ accountId: string;
4142
+ operationKey: string;
4143
+ ownerKey: string;
4144
+ paginationOpts: {
4145
+ cursor: string | null;
4146
+ endCursor?: string | null;
4147
+ id?: number;
4148
+ maximumBytesRead?: number;
4149
+ maximumRowsRead?: number;
4150
+ numItems: number;
4151
+ };
4152
+ },
4153
+ {
4154
+ continueCursor: string;
4155
+ isDone: boolean;
4156
+ page: Array<{
4157
+ _creationTime: number;
4158
+ _id: string;
4159
+ accountId: string;
4160
+ allocations: Array<{
4161
+ amount: number;
4162
+ role?: "store" | "affiliate" | "other";
4163
+ stripeTransferId: string;
4164
+ }>;
4165
+ amount: number;
4166
+ attemptedAt?: number;
4167
+ currency: string;
4168
+ debitFee?: number;
4169
+ debitTransactionId?: string;
4170
+ destinationId?: string;
4171
+ expectedRevision: number;
4172
+ feeRevision?: number;
4173
+ historical?: boolean;
4174
+ independentLiabilities?: number;
4175
+ liabilityRevision?: number;
4176
+ observations: Array<{
4177
+ currency: string;
4178
+ ledgerFingerprint: string;
4179
+ matureNet: number;
4180
+ observedAt: number;
4181
+ pendingCredits: number;
4182
+ stripeTransferId: string;
4183
+ transactionIds: Array<string>;
4184
+ }>;
4185
+ operationKey: string;
4186
+ ownerKey: string;
4187
+ providerFee?: number;
4188
+ rejection?: {
4189
+ code: "balance_insufficient" | "amount_too_small";
4190
+ requestId: string;
4191
+ };
4192
+ returnTransactionId?: string;
4193
+ snapshotId?: string;
4194
+ status:
4195
+ | "reserved"
4196
+ | "submitted"
4197
+ | "paid"
4198
+ | "returned"
4199
+ | "canceled"
4200
+ | "rejected";
4201
+ stripePayoutId?: string;
4202
+ }>;
4203
+ },
4204
+ Name
4205
+ >;
4206
+ get: FunctionReference<
4207
+ "query",
4208
+ "internal",
4209
+ { accountId: string; operationKey: string; ownerKey: string },
4210
+ {
4211
+ _creationTime: number;
4212
+ _id: string;
4213
+ accountId: string;
4214
+ allocationCount: number;
4215
+ allocationCursor?: string;
4216
+ boundOperationKey?: string;
4217
+ boundRiskRevision?: number;
4218
+ claimCount: number;
4219
+ claimCursor?: string;
4220
+ deferredPositiveChanges: boolean;
4221
+ expectedRevision: number;
4222
+ expiresAt: number;
4223
+ feeCount: number;
4224
+ feeCursor?: string;
4225
+ initialRevision: number;
4226
+ initialRiskRevision: number;
4227
+ observedRevision: number;
4228
+ operationKey: string;
4229
+ ownerKey: string;
4230
+ phase:
4231
+ | "sources"
4232
+ | "allocations"
4233
+ | "fees"
4234
+ | "claims"
4235
+ | "repair"
4236
+ | "check"
4237
+ | "local_ready"
4238
+ | "invalidated"
4239
+ | "discarding";
4240
+ policyMode?: string;
4241
+ policyOperationKey?: string;
4242
+ providerChanged: boolean;
4243
+ readOnly: boolean;
4244
+ reason?: string;
4245
+ riskRevision: number;
4246
+ sourceCount: number;
4247
+ sourceCursor?: string;
4248
+ sourceFence: number;
4249
+ step: number;
4250
+ } | null,
4251
+ Name
4252
+ >;
4253
+ sources: FunctionReference<
4254
+ "query",
4255
+ "internal",
4256
+ {
4257
+ accountId: string;
4258
+ operationKey: string;
4259
+ ownerKey: string;
4260
+ paginationOpts: {
4261
+ cursor: string | null;
4262
+ endCursor?: string | null;
4263
+ id?: number;
4264
+ maximumBytesRead?: number;
4265
+ maximumRowsRead?: number;
4266
+ numItems: number;
4267
+ };
4268
+ },
4269
+ {
4270
+ continueCursor: string;
4271
+ isDone: boolean;
4272
+ page: Array<{
4273
+ _creationTime: number;
4274
+ _id: string;
4275
+ amount: number;
4276
+ currency: string;
4277
+ destinationAccountId: string;
4278
+ metadata?: any;
4279
+ paymentId?: string;
4280
+ reinstatement?: boolean;
4281
+ reversalClaimedAmount?: number;
4282
+ reversalStatus?: "partially_reversed" | "fully_reversed";
4283
+ reversedAmount?: number;
4284
+ role?: "store" | "affiliate" | "other";
4285
+ sourceChargeId?: string;
4286
+ sourceInvoiceId?: string;
4287
+ status: "pending" | "paid" | "failed" | "reversed";
4288
+ stripeTransferId: string;
4289
+ totalsRecorded?: true;
4290
+ }>;
4291
+ },
4292
+ Name
4293
+ >;
4294
+ };
4007
4295
  };
4008
4296
  payoutSync: {
4009
4297
  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
+ });
@@ -1,9 +1,10 @@
1
1
  // @vitest-environment edge-runtime
2
2
  import { convexTest } from "convex-test";
3
3
  import { makeFunctionReference } from "convex/server";
4
- import { expect, it } from "vitest";
4
+ import { expect, it, vi } from "vitest";
5
5
  import type { Doc } from "./_generated/dataModel.js";
6
6
  import schema from "./schema.js";
7
+ import { cacheSource } from "./payoutSnapshots/localState.js";
7
8
  import { transferFingerprint } from "./payoutRelease/helpers.js";
8
9
  const modules = import.meta.glob("./**/*.*s");
9
10
  const m = (name: string) =>
@@ -393,3 +394,46 @@ it("retains a risk-journal continuation when changes exceed one page", async ()
393
394
  sourceCount: 1,
394
395
  });
395
396
  });
397
+
398
+ it("retains immutable primary source IDs in the disposable verification cache", async () => {
399
+ const s = await setup(2);
400
+ await s.finish(await s.begin());
401
+ const rows = await s.t.run(async (ctx) => ({
402
+ sources: await ctx.db.query("transfers").collect(),
403
+ cache: await ctx.db.query("payoutSnapshotSources").collect(),
404
+ }));
405
+ expect(rows.cache).toHaveLength(2);
406
+ for (const cached of rows.cache)
407
+ expect(
408
+ (cached as typeof cached & { transferDocId?: string }).transferDocId,
409
+ ).toBe(
410
+ rows.sources.find(
411
+ (row) => row.stripeTransferId === cached.stripeTransferId,
412
+ )!._id,
413
+ );
414
+ });
415
+
416
+ it("does not rewrite an unchanged source already cached in the same collection", async () => {
417
+ const s = await setup(2);
418
+ const started = await s.begin();
419
+ const h = await s.step(started.step);
420
+ await s.t.run(async (ctx) => {
421
+ const transfer = await ctx.db.query("transfers").first();
422
+ if (!transfer) throw Error("Missing source");
423
+ const patch = vi.spyOn(ctx.db, "patch");
424
+ await cacheSource(
425
+ ctx,
426
+ h,
427
+ transfer.stripeTransferId,
428
+ {
429
+ sourceCount: h.sourceCount,
430
+ allocationCount: h.allocationCount,
431
+ claimCount: h.claimCount,
432
+ feeCount: h.feeCount,
433
+ },
434
+ transfer,
435
+ );
436
+ expect(patch).not.toHaveBeenCalled();
437
+ patch.mockRestore();
438
+ });
439
+ });