@fantastic.dev/better-stripe 0.41.0 → 0.43.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 (209) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +1 -1
  3. package/dist/client/balanceFundingWorkflow/client.d.ts +172 -0
  4. package/dist/client/balanceFundingWorkflow/client.d.ts.map +1 -0
  5. package/dist/client/balanceFundingWorkflow/client.js +289 -0
  6. package/dist/client/balanceFundingWorkflow/client.js.map +1 -0
  7. package/dist/client/billing/balanceFunding.d.ts +5 -0
  8. package/dist/client/billing/balanceFunding.d.ts.map +1 -1
  9. package/dist/client/billing/balanceFunding.js +30 -0
  10. package/dist/client/billing/balanceFunding.js.map +1 -1
  11. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +1388 -2
  12. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  13. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +710 -17
  14. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  15. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +1420 -34
  16. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  17. package/dist/client/connect/payoutSyncTestHelpers.d.ts +694 -1
  18. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  19. package/dist/client/costRecovery-invoices.d.ts +3 -2
  20. package/dist/client/costRecovery-invoices.d.ts.map +1 -1
  21. package/dist/client/costRecovery-invoices.js +10 -5
  22. package/dist/client/costRecovery-invoices.js.map +1 -1
  23. package/dist/client/costRecovery.d.ts +4 -2
  24. package/dist/client/costRecovery.d.ts.map +1 -1
  25. package/dist/client/costRecovery.js +2 -2
  26. package/dist/client/costRecovery.js.map +1 -1
  27. package/dist/client/index.d.ts +3 -0
  28. package/dist/client/index.d.ts.map +1 -1
  29. package/dist/client/index.js +4 -0
  30. package/dist/client/index.js.map +1 -1
  31. package/dist/client/processingCostReconciliation/client.d.ts +14 -0
  32. package/dist/client/processingCostReconciliation/client.d.ts.map +1 -0
  33. package/dist/client/processingCostReconciliation/client.js +35 -0
  34. package/dist/client/processingCostReconciliation/client.js.map +1 -0
  35. package/dist/client/processingCostReconciliation/contracts.d.ts +172 -0
  36. package/dist/client/processingCostReconciliation/contracts.d.ts.map +1 -0
  37. package/dist/client/processingCostReconciliation/contracts.js +55 -0
  38. package/dist/client/processingCostReconciliation/contracts.js.map +1 -0
  39. package/dist/client/processingCostReconciliation/invoiceFunding.d.ts +15 -0
  40. package/dist/client/processingCostReconciliation/invoiceFunding.d.ts.map +1 -0
  41. package/dist/client/processingCostReconciliation/invoiceFunding.js +195 -0
  42. package/dist/client/processingCostReconciliation/invoiceFunding.js.map +1 -0
  43. package/dist/client/processingCostReconciliation/provider.d.ts +9 -0
  44. package/dist/client/processingCostReconciliation/provider.d.ts.map +1 -0
  45. package/dist/client/processingCostReconciliation/provider.js +148 -0
  46. package/dist/client/processingCostReconciliation/provider.js.map +1 -0
  47. package/dist/client/settlement/processingCostHistory.d.ts +12 -0
  48. package/dist/client/settlement/processingCostHistory.d.ts.map +1 -0
  49. package/dist/client/settlement/processingCostHistory.js +20 -0
  50. package/dist/client/settlement/processingCostHistory.js.map +1 -0
  51. package/dist/client/settlement/processingCosts.d.ts +3 -0
  52. package/dist/client/settlement/processingCosts.d.ts.map +1 -1
  53. package/dist/client/settlement/processingCosts.js +27 -7
  54. package/dist/client/settlement/processingCosts.js.map +1 -1
  55. package/dist/component/_generated/api.d.ts +36 -0
  56. package/dist/component/_generated/api.d.ts.map +1 -1
  57. package/dist/component/_generated/api.js.map +1 -1
  58. package/dist/component/_generated/component.d.ts +988 -0
  59. package/dist/component/_generated/component.d.ts.map +1 -1
  60. package/dist/component/balanceFunding/helpers.d.ts +42 -0
  61. package/dist/component/balanceFunding/helpers.d.ts.map +1 -1
  62. package/dist/component/balanceFunding/internal/actions.d.ts +39 -0
  63. package/dist/component/balanceFunding/internal/actions.d.ts.map +1 -0
  64. package/dist/component/balanceFunding/internal/actions.js +80 -0
  65. package/dist/component/balanceFunding/internal/actions.js.map +1 -0
  66. package/dist/component/balanceFunding/internal/mutations.d.ts +55 -0
  67. package/dist/component/balanceFunding/internal/mutations.d.ts.map +1 -0
  68. package/dist/component/balanceFunding/internal/mutations.js +54 -0
  69. package/dist/component/balanceFunding/internal/mutations.js.map +1 -0
  70. package/dist/component/balanceFunding/internal/queries.d.ts +116 -0
  71. package/dist/component/balanceFunding/internal/queries.d.ts.map +1 -0
  72. package/dist/component/balanceFunding/internal/queries.js +35 -0
  73. package/dist/component/balanceFunding/internal/queries.js.map +1 -0
  74. package/dist/component/balanceFunding/internal/workflow.d.ts +10 -0
  75. package/dist/component/balanceFunding/internal/workflow.d.ts.map +1 -0
  76. package/dist/component/balanceFunding/internal/workflow.js +31 -0
  77. package/dist/component/balanceFunding/internal/workflow.js.map +1 -0
  78. package/dist/component/balanceFunding/lifecycleHandlers.d.ts +126 -0
  79. package/dist/component/balanceFunding/lifecycleHandlers.d.ts.map +1 -1
  80. package/dist/component/balanceFunding/mutations.d.ts +419 -16
  81. package/dist/component/balanceFunding/mutations.d.ts.map +1 -1
  82. package/dist/component/balanceFunding/mutations.js +24 -0
  83. package/dist/component/balanceFunding/mutations.js.map +1 -1
  84. package/dist/component/balanceFunding/preparationHandlers.d.ts +42 -0
  85. package/dist/component/balanceFunding/preparationHandlers.d.ts.map +1 -1
  86. package/dist/component/balanceFunding/queries.d.ts +78 -0
  87. package/dist/component/balanceFunding/queries.d.ts.map +1 -1
  88. package/dist/component/balanceFunding/queries.js +35 -0
  89. package/dist/component/balanceFunding/queries.js.map +1 -1
  90. package/dist/component/balanceFunding/receipt.d.ts +5 -0
  91. package/dist/component/balanceFunding/receipt.d.ts.map +1 -0
  92. package/dist/component/balanceFunding/receipt.js +37 -0
  93. package/dist/component/balanceFunding/receipt.js.map +1 -0
  94. package/dist/component/balanceFunding/schema.d.ts +506 -2
  95. package/dist/component/balanceFunding/schema.d.ts.map +1 -1
  96. package/dist/component/balanceFunding/schema.js +2 -0
  97. package/dist/component/balanceFunding/schema.js.map +1 -1
  98. package/dist/component/balanceFunding/stateHandlers.d.ts +42 -0
  99. package/dist/component/balanceFunding/stateHandlers.d.ts.map +1 -1
  100. package/dist/component/balanceFunding/workflowControl.d.ts +19 -0
  101. package/dist/component/balanceFunding/workflowControl.d.ts.map +1 -0
  102. package/dist/component/balanceFunding/workflowControl.js +149 -0
  103. package/dist/component/balanceFunding/workflowControl.js.map +1 -0
  104. package/dist/component/balanceFunding/workflowSchema.d.ts +356 -0
  105. package/dist/component/balanceFunding/workflowSchema.d.ts.map +1 -0
  106. package/dist/component/balanceFunding/workflowSchema.js +48 -0
  107. package/dist/component/balanceFunding/workflowSchema.js.map +1 -0
  108. package/dist/component/balanceFunding/workflowState.d.ts +157 -0
  109. package/dist/component/balanceFunding/workflowState.d.ts.map +1 -0
  110. package/dist/component/balanceFunding/workflowState.js +194 -0
  111. package/dist/component/balanceFunding/workflowState.js.map +1 -0
  112. package/dist/component/balanceFunding/workflowValidators.d.ts +306 -0
  113. package/dist/component/balanceFunding/workflowValidators.d.ts.map +1 -0
  114. package/dist/component/balanceFunding/workflowValidators.js +27 -0
  115. package/dist/component/balanceFunding/workflowValidators.js.map +1 -0
  116. package/dist/component/earnings/triggers.d.ts +388 -2
  117. package/dist/component/earnings/triggers.d.ts.map +1 -1
  118. package/dist/component/payoutRelease/queries.d.ts +2 -2
  119. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  120. package/dist/component/processingCostReconciliation/adoption.d.ts +29 -0
  121. package/dist/component/processingCostReconciliation/adoption.d.ts.map +1 -0
  122. package/dist/component/processingCostReconciliation/adoption.js +58 -0
  123. package/dist/component/processingCostReconciliation/adoption.js.map +1 -0
  124. package/dist/component/processingCostReconciliation/bridge.d.ts +45 -0
  125. package/dist/component/processingCostReconciliation/bridge.d.ts.map +1 -0
  126. package/dist/component/processingCostReconciliation/bridge.js +41 -0
  127. package/dist/component/processingCostReconciliation/bridge.js.map +1 -0
  128. package/dist/component/processingCostReconciliation/helpers.d.ts +327 -0
  129. package/dist/component/processingCostReconciliation/helpers.d.ts.map +1 -0
  130. package/dist/component/processingCostReconciliation/helpers.js +39 -0
  131. package/dist/component/processingCostReconciliation/helpers.js.map +1 -0
  132. package/dist/component/processingCostReconciliation/mutations.d.ts +303 -0
  133. package/dist/component/processingCostReconciliation/mutations.d.ts.map +1 -0
  134. package/dist/component/processingCostReconciliation/mutations.js +121 -0
  135. package/dist/component/processingCostReconciliation/mutations.js.map +1 -0
  136. package/dist/component/processingCostReconciliation/queries.d.ts +422 -0
  137. package/dist/component/processingCostReconciliation/queries.d.ts.map +1 -0
  138. package/dist/component/processingCostReconciliation/queries.js +19 -0
  139. package/dist/component/processingCostReconciliation/queries.js.map +1 -0
  140. package/dist/component/processingCostReconciliation/rollback.d.ts +21 -0
  141. package/dist/component/processingCostReconciliation/rollback.d.ts.map +1 -0
  142. package/dist/component/processingCostReconciliation/rollback.js +54 -0
  143. package/dist/component/processingCostReconciliation/rollback.js.map +1 -0
  144. package/dist/component/processingCostReconciliation/schema.d.ts +2460 -0
  145. package/dist/component/processingCostReconciliation/schema.d.ts.map +1 -0
  146. package/dist/component/processingCostReconciliation/schema.js +137 -0
  147. package/dist/component/processingCostReconciliation/schema.js.map +1 -0
  148. package/dist/component/processingCostReconciliation/steps.d.ts +306 -0
  149. package/dist/component/processingCostReconciliation/steps.d.ts.map +1 -0
  150. package/dist/component/processingCostReconciliation/steps.js +149 -0
  151. package/dist/component/processingCostReconciliation/steps.js.map +1 -0
  152. package/dist/component/processingCostReconciliation/validation.d.ts +13 -0
  153. package/dist/component/processingCostReconciliation/validation.d.ts.map +1 -0
  154. package/dist/component/processingCostReconciliation/validation.js +61 -0
  155. package/dist/component/processingCostReconciliation/validation.js.map +1 -0
  156. package/dist/component/processingCostReconciliation/workflow.d.ts +105 -0
  157. package/dist/component/processingCostReconciliation/workflow.d.ts.map +1 -0
  158. package/dist/component/processingCostReconciliation/workflow.js +33 -0
  159. package/dist/component/processingCostReconciliation/workflow.js.map +1 -0
  160. package/dist/component/schema.d.ts +694 -1
  161. package/dist/component/schema.js +2 -0
  162. package/dist/component/schema.js.map +1 -1
  163. package/package.json +1 -1
  164. package/src/client/balanceFundingWorkflow/capture.test.ts +144 -0
  165. package/src/client/balanceFundingWorkflow/client.ts +419 -0
  166. package/src/client/billing/balanceFunding.ts +50 -0
  167. package/src/client/costRecovery-invoices.ts +19 -4
  168. package/src/client/costRecovery.ts +4 -2
  169. package/src/client/index.ts +15 -0
  170. package/src/client/processingCostReconciliation/client.ts +75 -0
  171. package/src/client/processingCostReconciliation/contracts.ts +176 -0
  172. package/src/client/processingCostReconciliation/invoiceFunding.ts +270 -0
  173. package/src/client/processingCostReconciliation/invoiceProvider.test.ts +353 -0
  174. package/src/client/processingCostReconciliation/provider.test.ts +324 -0
  175. package/src/client/processingCostReconciliation/provider.ts +178 -0
  176. package/src/client/settlement/processingCostHistory.ts +31 -0
  177. package/src/client/settlement/processingCosts.ts +50 -15
  178. package/src/component/_generated/api.ts +36 -0
  179. package/src/component/_generated/component.ts +1094 -0
  180. package/src/component/balanceFunding/internal/actions.ts +107 -0
  181. package/src/component/balanceFunding/internal/mutations.ts +66 -0
  182. package/src/component/balanceFunding/internal/queries.ts +34 -0
  183. package/src/component/balanceFunding/internal/workflow.ts +49 -0
  184. package/src/component/balanceFunding/mutations.ts +34 -0
  185. package/src/component/balanceFunding/queries.ts +38 -0
  186. package/src/component/balanceFunding/receipt.ts +48 -0
  187. package/src/component/balanceFunding/schema.ts +2 -0
  188. package/src/component/balanceFunding/scopeLookup.test.ts +94 -0
  189. package/src/component/balanceFunding/workflow.fixtures.ts +366 -0
  190. package/src/component/balanceFunding/workflow.test.ts +552 -0
  191. package/src/component/balanceFunding/workflowControl.ts +198 -0
  192. package/src/component/balanceFunding/workflowSchema.ts +78 -0
  193. package/src/component/balanceFunding/workflowState.ts +285 -0
  194. package/src/component/balanceFunding/workflowValidators.ts +40 -0
  195. package/src/component/processingCostReconciliation/adoption.test.ts +206 -0
  196. package/src/component/processingCostReconciliation/adoption.ts +77 -0
  197. package/src/component/processingCostReconciliation/bridge.ts +50 -0
  198. package/src/component/processingCostReconciliation/helpers.ts +55 -0
  199. package/src/component/processingCostReconciliation/invoice.test.ts +152 -0
  200. package/src/component/processingCostReconciliation/mutations.ts +148 -0
  201. package/src/component/processingCostReconciliation/queries.ts +18 -0
  202. package/src/component/processingCostReconciliation/rollback.ts +72 -0
  203. package/src/component/processingCostReconciliation/schema.ts +191 -0
  204. package/src/component/processingCostReconciliation/state.test.ts +407 -0
  205. package/src/component/processingCostReconciliation/steps.ts +168 -0
  206. package/src/component/processingCostReconciliation/validation.ts +79 -0
  207. package/src/component/processingCostReconciliation/workflow.test.ts +329 -0
  208. package/src/component/processingCostReconciliation/workflow.ts +50 -0
  209. package/src/component/schema.ts +2 -0
@@ -0,0 +1,303 @@
1
+ export declare const start: import("convex/server").RegisteredMutation<"public", {
2
+ accountId: string;
3
+ claimKey: string;
4
+ currency: string;
5
+ definitionVersion: number;
6
+ expectedRevision: number;
7
+ importHook?: string | undefined;
8
+ maxAttempts: number;
9
+ policy: {
10
+ liability: {
11
+ disputeCosts: "all" | "none";
12
+ processingCosts: "all" | "none" | "uncovered";
13
+ };
14
+ rounding: "ceil" | "floor" | "nearest";
15
+ sellingFee: number;
16
+ };
17
+ projection?: string | undefined;
18
+ provider: string;
19
+ providerApiVersion: string;
20
+ requestKey: string;
21
+ retryDelayMs: number;
22
+ rollback?: {
23
+ expectedRevision: number;
24
+ groupKey: string;
25
+ } | undefined;
26
+ scopeKey: string;
27
+ source: {
28
+ customerAccountId: string;
29
+ gross: number;
30
+ invoiceId?: string | undefined;
31
+ kind: "sale";
32
+ paymentIntentId: string;
33
+ stripeAccountId?: string | undefined;
34
+ stripePriceId?: string | undefined;
35
+ stripeProductId?: string | undefined;
36
+ subscriptionId?: string | undefined;
37
+ } | {
38
+ gross: number;
39
+ groupKey: string;
40
+ kind: "invoice_recovery";
41
+ paymentIntentId: string;
42
+ };
43
+ }, Promise<{
44
+ readonly status: "conflict";
45
+ readonly reason: "identity_changed" | "revision_changed";
46
+ readonly retryable: false;
47
+ } | {
48
+ status: "completed";
49
+ result: {
50
+ claim: {
51
+ _creationTime: number;
52
+ _id: import("convex/values").GenericId<"recoveryClaims">;
53
+ accountId: string;
54
+ amountDue: number;
55
+ claimKey: string;
56
+ collectedAmount: number;
57
+ currency: string;
58
+ openingCollection?: {
59
+ amountDue: number;
60
+ collectedAmount: number;
61
+ operationKey: string;
62
+ revision: number;
63
+ } | undefined;
64
+ outstanding: number;
65
+ reservedAmount: number;
66
+ revision: number;
67
+ scopeKey: string;
68
+ sign: "negative" | "positive" | "zero";
69
+ sourceChargeId: string;
70
+ sourceGross: number;
71
+ sourceProcessingFee: number;
72
+ };
73
+ deficit: {
74
+ amountDue: number;
75
+ currency: string;
76
+ disputeLiability: number;
77
+ processingLiability: number;
78
+ retainedFee: number;
79
+ };
80
+ observation: {
81
+ currency: string;
82
+ disputeFees: number;
83
+ gross: number;
84
+ originalProcessingFee: number;
85
+ paymentIntentId: string;
86
+ principalReturned: number;
87
+ processingFee: number;
88
+ provenance: {
89
+ customerAccountId: string;
90
+ invoiceId: string;
91
+ invoicePaymentId: string;
92
+ recoveryInvoiceItemId?: string | undefined;
93
+ stripePriceId?: string | undefined;
94
+ stripeProductId?: string | undefined;
95
+ subscriptionId?: string | undefined;
96
+ };
97
+ sourceChargeId: string;
98
+ };
99
+ rollbackClaim?: {
100
+ _creationTime: number;
101
+ _id: import("convex/values").GenericId<"recoveryClaims">;
102
+ accountId: string;
103
+ amountDue: number;
104
+ claimKey: string;
105
+ collectedAmount: number;
106
+ currency: string;
107
+ openingCollection?: {
108
+ amountDue: number;
109
+ collectedAmount: number;
110
+ operationKey: string;
111
+ revision: number;
112
+ } | undefined;
113
+ outstanding: number;
114
+ reservedAmount: number;
115
+ revision: number;
116
+ scopeKey: string;
117
+ sign: "negative" | "positive" | "zero";
118
+ sourceChargeId: string;
119
+ sourceGross: number;
120
+ sourceProcessingFee: number;
121
+ } | undefined;
122
+ };
123
+ accountId: string;
124
+ currency: string;
125
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
126
+ scopeKey: string;
127
+ version: number;
128
+ } | {
129
+ accountId: string;
130
+ currency: string;
131
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
132
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
133
+ retryable: true;
134
+ scopeKey: string;
135
+ status: "not_ready";
136
+ version: number;
137
+ } | {
138
+ accountId: string;
139
+ currency: string;
140
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
141
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
142
+ retryable: false;
143
+ scopeKey: string;
144
+ status: "conflict";
145
+ version: number;
146
+ } | {
147
+ accountId: string;
148
+ currency: string;
149
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
150
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
151
+ retryable: false;
152
+ scopeKey: string;
153
+ status: "rejected";
154
+ version: number;
155
+ } | {
156
+ accountId: string;
157
+ currency: string;
158
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
159
+ reason: "history_incomplete" | "provider_outcome_unknown";
160
+ retryable: false;
161
+ scopeKey: string;
162
+ status: "unknown";
163
+ version: number;
164
+ } | {
165
+ status: "queued" | "running";
166
+ accountId: string;
167
+ currency: string;
168
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
169
+ scopeKey: string;
170
+ version: number;
171
+ }>>;
172
+ export declare const resume: import("convex/server").RegisteredMutation<"public", {
173
+ accountId: string;
174
+ currency: string;
175
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
176
+ scopeKey: string;
177
+ version: number;
178
+ }, Promise<{
179
+ status: "completed";
180
+ result: {
181
+ claim: {
182
+ _creationTime: number;
183
+ _id: import("convex/values").GenericId<"recoveryClaims">;
184
+ accountId: string;
185
+ amountDue: number;
186
+ claimKey: string;
187
+ collectedAmount: number;
188
+ currency: string;
189
+ openingCollection?: {
190
+ amountDue: number;
191
+ collectedAmount: number;
192
+ operationKey: string;
193
+ revision: number;
194
+ } | undefined;
195
+ outstanding: number;
196
+ reservedAmount: number;
197
+ revision: number;
198
+ scopeKey: string;
199
+ sign: "negative" | "positive" | "zero";
200
+ sourceChargeId: string;
201
+ sourceGross: number;
202
+ sourceProcessingFee: number;
203
+ };
204
+ deficit: {
205
+ amountDue: number;
206
+ currency: string;
207
+ disputeLiability: number;
208
+ processingLiability: number;
209
+ retainedFee: number;
210
+ };
211
+ observation: {
212
+ currency: string;
213
+ disputeFees: number;
214
+ gross: number;
215
+ originalProcessingFee: number;
216
+ paymentIntentId: string;
217
+ principalReturned: number;
218
+ processingFee: number;
219
+ provenance: {
220
+ customerAccountId: string;
221
+ invoiceId: string;
222
+ invoicePaymentId: string;
223
+ recoveryInvoiceItemId?: string | undefined;
224
+ stripePriceId?: string | undefined;
225
+ stripeProductId?: string | undefined;
226
+ subscriptionId?: string | undefined;
227
+ };
228
+ sourceChargeId: string;
229
+ };
230
+ rollbackClaim?: {
231
+ _creationTime: number;
232
+ _id: import("convex/values").GenericId<"recoveryClaims">;
233
+ accountId: string;
234
+ amountDue: number;
235
+ claimKey: string;
236
+ collectedAmount: number;
237
+ currency: string;
238
+ openingCollection?: {
239
+ amountDue: number;
240
+ collectedAmount: number;
241
+ operationKey: string;
242
+ revision: number;
243
+ } | undefined;
244
+ outstanding: number;
245
+ reservedAmount: number;
246
+ revision: number;
247
+ scopeKey: string;
248
+ sign: "negative" | "positive" | "zero";
249
+ sourceChargeId: string;
250
+ sourceGross: number;
251
+ sourceProcessingFee: number;
252
+ } | undefined;
253
+ };
254
+ accountId: string;
255
+ currency: string;
256
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
257
+ scopeKey: string;
258
+ version: number;
259
+ } | {
260
+ accountId: string;
261
+ currency: string;
262
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
263
+ reason: "fee_pending" | "history_incomplete" | "provider_pending";
264
+ retryable: true;
265
+ scopeKey: string;
266
+ status: "not_ready";
267
+ version: number;
268
+ } | {
269
+ accountId: string;
270
+ currency: string;
271
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
272
+ reason: "identity_changed" | "revision_changed" | "scope_busy";
273
+ retryable: false;
274
+ scopeKey: string;
275
+ status: "conflict";
276
+ version: number;
277
+ } | {
278
+ accountId: string;
279
+ currency: string;
280
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
281
+ reason: "currency_mismatch" | "invalid_scope" | "payment_not_payable" | "policy_invalid" | "unsupported_source";
282
+ retryable: false;
283
+ scopeKey: string;
284
+ status: "rejected";
285
+ version: number;
286
+ } | {
287
+ accountId: string;
288
+ currency: string;
289
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
290
+ reason: "history_incomplete" | "provider_outcome_unknown";
291
+ retryable: false;
292
+ scopeKey: string;
293
+ status: "unknown";
294
+ version: number;
295
+ } | {
296
+ status: "queued" | "running";
297
+ accountId: string;
298
+ currency: string;
299
+ operationId: import("convex/values").GenericId<"processingCostReconciliationOperations">;
300
+ scopeKey: string;
301
+ version: number;
302
+ }>>;
303
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/mutations.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFhB,CAAC;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CjB,CAAC"}
@@ -0,0 +1,121 @@
1
+ import { v } from "convex/values";
2
+ import { anyApi } from "convex/server";
3
+ import { mutation } from "../_generated/server.js";
4
+ import { startFields, safeStatus, failure, refFields } from "./schema.js";
5
+ import { executionWorkflow } from "../durableExecution/runtime.js";
6
+ import { calculateProcessingCostDeficit } from "../../client/processingCostDeficit/index.js";
7
+ import { validateScope } from "../costRecovery/helpers.js";
8
+ import { same } from "../recoveryWorkflow/helpers.js";
9
+ import { conflict, reference, status, read } from "./helpers.js";
10
+ const workflow = anyApi.processingCostReconciliation.workflow
11
+ .run;
12
+ export const start = mutation({
13
+ args: startFields,
14
+ returns: v.union(safeStatus, failure),
15
+ handler: async (ctx, args) => {
16
+ validateScope(args);
17
+ if (!args.requestKey ||
18
+ !args.claimKey ||
19
+ args.claimKey.startsWith("rollback:") ||
20
+ !args.source.paymentIntentId ||
21
+ !Number.isSafeInteger(args.expectedRevision) ||
22
+ args.expectedRevision < -1 ||
23
+ (args.rollback !== undefined &&
24
+ (!args.rollback.groupKey ||
25
+ !Number.isSafeInteger(args.rollback.expectedRevision) ||
26
+ args.rollback.expectedRevision < -1)) ||
27
+ (args.source.kind === "invoice_recovery" &&
28
+ (!args.rollback || args.rollback.groupKey !== args.source.groupKey)) ||
29
+ args.definitionVersion !== 1 ||
30
+ !/^\d{4}-\d{2}-\d{2}\.[a-z][a-z0-9_.-]*$/.test(args.providerApiVersion) ||
31
+ !Number.isSafeInteger(args.maxAttempts) ||
32
+ args.maxAttempts < 1 ||
33
+ args.maxAttempts > 20 ||
34
+ !Number.isSafeInteger(args.retryDelayMs) ||
35
+ args.retryDelayMs < 1 ||
36
+ args.retryDelayMs > 86400000)
37
+ throw new Error("Invalid processing-cost reconciliation policy.");
38
+ calculateProcessingCostDeficit({
39
+ currency: args.currency,
40
+ gross: args.source.gross,
41
+ ...args.policy,
42
+ processingFee: 0,
43
+ principalReturned: 0,
44
+ disputeFees: 0,
45
+ });
46
+ const prior = await ctx.db
47
+ .query("processingCostReconciliationOperations")
48
+ .withIndex("by_request", (q) => q.eq("requestKey", args.requestKey))
49
+ .unique();
50
+ if (prior) {
51
+ const binding = Object.fromEntries(Object.keys(startFields).map((k) => [
52
+ k,
53
+ prior[k],
54
+ ]));
55
+ if (!same(binding, args))
56
+ return conflict("identity_changed");
57
+ return status(prior);
58
+ }
59
+ const id = await ctx.db.insert("processingCostReconciliationOperations", {
60
+ ...args,
61
+ version: 1,
62
+ status: "queued",
63
+ });
64
+ const op = (await ctx.db.get("processingCostReconciliationOperations", id));
65
+ const canonical = await ctx.db
66
+ .query("processingCostReconciliationOperations")
67
+ .withIndex("by_payment_scope", (q) => q
68
+ .eq("accountId", args.accountId)
69
+ .eq("scopeKey", args.scopeKey)
70
+ .eq("currency", args.currency)
71
+ .eq("source.paymentIntentId", args.source.paymentIntentId))
72
+ .first();
73
+ if (canonical && canonical.claimKey !== args.claimKey) {
74
+ const failure = conflict("identity_changed");
75
+ await ctx.db.patch("processingCostReconciliationOperations", id, {
76
+ status: "conflict",
77
+ failure,
78
+ });
79
+ return { ...reference(op), ...failure };
80
+ }
81
+ const workflowId = await executionWorkflow.start(ctx, workflow, reference(op), { startAsync: true });
82
+ await ctx.db.patch("processingCostReconciliationOperations", id, {
83
+ workflowId,
84
+ });
85
+ return status(op);
86
+ },
87
+ });
88
+ export const resume = mutation({
89
+ args: refFields,
90
+ returns: safeStatus,
91
+ handler: async (ctx, args) => {
92
+ const op = await read(ctx, args);
93
+ if (op.result ||
94
+ (op.failure && ["conflict", "rejected"].includes(op.failure.status)))
95
+ return status(op);
96
+ const state = await executionWorkflow.status(ctx, op.workflowId);
97
+ if (state.type === "inProgress")
98
+ return status(op);
99
+ if (state.type === "failed") {
100
+ const last = (await executionWorkflow.listSteps(ctx, op.workflowId, {
101
+ order: "desc",
102
+ paginationOpts: { cursor: null, numItems: 1 },
103
+ })).page[0];
104
+ if (last?.name === "apply" && last.runResult?.kind === "failed") {
105
+ await executionWorkflow.restart(ctx, op.workflowId, {
106
+ from: last.stepNumber,
107
+ startAsync: true,
108
+ });
109
+ return status(op);
110
+ }
111
+ }
112
+ const workflowId = await executionWorkflow.start(ctx, workflow, reference(op), { startAsync: true });
113
+ await ctx.db.patch("processingCostReconciliationOperations", op._id, {
114
+ workflowId,
115
+ status: "queued",
116
+ failure: undefined,
117
+ });
118
+ return status((await ctx.db.get("processingCostReconciliationOperations", op._id)));
119
+ },
120
+ });
121
+ //# sourceMappingURL=mutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../../src/component/processingCostReconciliation/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,EAAE,MAAM,EAA0B,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,4BAA4B,CAAC,QAAQ;KAC1D,GAAgD,CAAC;AACpD,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,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