@fantastic.dev/better-stripe 0.23.1 → 0.24.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 (287) hide show
  1. package/CHANGELOG.md +26 -2
  2. package/README.md +40 -5
  3. package/dist/client/affiliateRecovery/disputes.d.ts +18 -0
  4. package/dist/client/affiliateRecovery/disputes.d.ts.map +1 -0
  5. package/dist/client/affiliateRecovery/disputes.js +33 -0
  6. package/dist/client/affiliateRecovery/disputes.js.map +1 -0
  7. package/dist/client/affiliateRecovery/engine.d.ts +29 -0
  8. package/dist/client/affiliateRecovery/engine.d.ts.map +1 -0
  9. package/dist/client/affiliateRecovery/engine.js +116 -0
  10. package/dist/client/affiliateRecovery/engine.js.map +1 -0
  11. package/dist/client/affiliateRecovery/payoutGate.d.ts +24 -0
  12. package/dist/client/affiliateRecovery/payoutGate.d.ts.map +1 -0
  13. package/dist/client/affiliateRecovery/payoutGate.js +30 -0
  14. package/dist/client/affiliateRecovery/payoutGate.js.map +1 -0
  15. package/dist/client/affiliateRecovery/provider.d.ts +14 -0
  16. package/dist/client/affiliateRecovery/provider.d.ts.map +1 -0
  17. package/dist/client/affiliateRecovery/provider.js +96 -0
  18. package/dist/client/affiliateRecovery/provider.js.map +1 -0
  19. package/dist/client/affiliateRecovery/review.d.ts +28 -0
  20. package/dist/client/affiliateRecovery/review.d.ts.map +1 -0
  21. package/dist/client/affiliateRecovery/review.js +86 -0
  22. package/dist/client/affiliateRecovery/review.js.map +1 -0
  23. package/dist/client/affiliateRecovery/validators.d.ts +402 -0
  24. package/dist/client/affiliateRecovery/validators.d.ts.map +1 -0
  25. package/dist/client/affiliateRecovery/validators.js +27 -0
  26. package/dist/client/affiliateRecovery/validators.js.map +1 -0
  27. package/dist/client/affiliateRecovery.d.ts +131 -0
  28. package/dist/client/affiliateRecovery.d.ts.map +1 -0
  29. package/dist/client/affiliateRecovery.js +69 -0
  30. package/dist/client/affiliateRecovery.js.map +1 -0
  31. package/dist/client/connect/commissionReceipts.d.ts +4 -0
  32. package/dist/client/connect/commissionReceipts.d.ts.map +1 -0
  33. package/dist/client/connect/commissionReceipts.js +17 -0
  34. package/dist/client/connect/commissionReceipts.js.map +1 -0
  35. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +536 -2
  36. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  37. package/dist/client/connect/payoutSync.d.ts +32 -0
  38. package/dist/client/connect/payoutSync.d.ts.map +1 -0
  39. package/dist/client/connect/payoutSync.js +48 -0
  40. package/dist/client/connect/payoutSync.js.map +1 -0
  41. package/dist/client/connect/payoutSyncTestHelpers.d.ts +1509 -0
  42. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -0
  43. package/dist/client/connect/payoutSyncTestHelpers.js +62 -0
  44. package/dist/client/connect/payoutSyncTestHelpers.js.map +1 -0
  45. package/dist/client/connect/payoutSyncValidation.d.ts +16 -0
  46. package/dist/client/connect/payoutSyncValidation.d.ts.map +1 -0
  47. package/dist/client/connect/payoutSyncValidation.js +54 -0
  48. package/dist/client/connect/payoutSyncValidation.js.map +1 -0
  49. package/dist/client/connect/payouts.d.ts +3 -1
  50. package/dist/client/connect/payouts.d.ts.map +1 -1
  51. package/dist/client/connect/payouts.js +45 -12
  52. package/dist/client/connect/payouts.js.map +1 -1
  53. package/dist/client/connect/refundPrincipal.d.ts +4 -0
  54. package/dist/client/connect/refundPrincipal.d.ts.map +1 -0
  55. package/dist/client/connect/refundPrincipal.js +21 -0
  56. package/dist/client/connect/refundPrincipal.js.map +1 -0
  57. package/dist/client/connect/reversalExecution.d.ts +47 -0
  58. package/dist/client/connect/reversalExecution.d.ts.map +1 -0
  59. package/dist/client/connect/reversalExecution.js +84 -0
  60. package/dist/client/connect/reversalExecution.js.map +1 -0
  61. package/dist/client/connect/transfers.d.ts +8 -4
  62. package/dist/client/connect/transfers.d.ts.map +1 -1
  63. package/dist/client/connect/transfers.js +52 -57
  64. package/dist/client/connect/transfers.js.map +1 -1
  65. package/dist/client/index.d.ts +29 -9
  66. package/dist/client/index.d.ts.map +1 -1
  67. package/dist/client/index.js +9 -6
  68. package/dist/client/index.js.map +1 -1
  69. package/dist/client/readContracts.d.ts +8 -0
  70. package/dist/client/readContracts.d.ts.map +1 -1
  71. package/dist/client/readContracts.js +7 -0
  72. package/dist/client/readContracts.js.map +1 -1
  73. package/dist/client/settlement/execution.d.ts.map +1 -1
  74. package/dist/client/settlement/execution.js +30 -3
  75. package/dist/client/settlement/execution.js.map +1 -1
  76. package/dist/client/settlement/reconciliation.d.ts.map +1 -1
  77. package/dist/client/settlement/reconciliation.js +16 -2
  78. package/dist/client/settlement/reconciliation.js.map +1 -1
  79. package/dist/client/webhooks/disputeRecovery.d.ts +4 -0
  80. package/dist/client/webhooks/disputeRecovery.d.ts.map +1 -0
  81. package/dist/client/webhooks/disputeRecovery.js +40 -0
  82. package/dist/client/webhooks/disputeRecovery.js.map +1 -0
  83. package/dist/client/webhooks/processors.d.ts.map +1 -1
  84. package/dist/client/webhooks/processors.js +14 -29
  85. package/dist/client/webhooks/processors.js.map +1 -1
  86. package/dist/component/_generated/component.d.ts +560 -0
  87. package/dist/component/_generated/component.d.ts.map +1 -1
  88. package/dist/component/affiliateEarnings/mutations.d.ts +22 -0
  89. package/dist/component/affiliateEarnings/mutations.d.ts.map +1 -0
  90. package/dist/component/affiliateEarnings/mutations.js +160 -0
  91. package/dist/component/affiliateEarnings/mutations.js.map +1 -0
  92. package/dist/component/affiliatePayouts/mutations.d.ts +25 -0
  93. package/dist/component/affiliatePayouts/mutations.d.ts.map +1 -0
  94. package/dist/component/affiliatePayouts/mutations.js +104 -0
  95. package/dist/component/affiliatePayouts/mutations.js.map +1 -0
  96. package/dist/component/affiliatePayouts/queries.d.ts +23 -0
  97. package/dist/component/affiliatePayouts/queries.d.ts.map +1 -0
  98. package/dist/component/affiliatePayouts/queries.js +23 -0
  99. package/dist/component/affiliatePayouts/queries.js.map +1 -0
  100. package/dist/component/affiliatePayouts/recipientGuard.d.ts +12 -0
  101. package/dist/component/affiliatePayouts/recipientGuard.d.ts.map +1 -0
  102. package/dist/component/affiliatePayouts/recipientGuard.js +26 -0
  103. package/dist/component/affiliatePayouts/recipientGuard.js.map +1 -0
  104. package/dist/component/affiliateRecovery/accounting.d.ts +28 -0
  105. package/dist/component/affiliateRecovery/accounting.d.ts.map +1 -0
  106. package/dist/component/affiliateRecovery/accounting.js +71 -0
  107. package/dist/component/affiliateRecovery/accounting.js.map +1 -0
  108. package/dist/component/affiliateRecovery/mutations.d.ts +65 -0
  109. package/dist/component/affiliateRecovery/mutations.d.ts.map +1 -0
  110. package/dist/component/affiliateRecovery/mutations.js +250 -0
  111. package/dist/component/affiliateRecovery/mutations.js.map +1 -0
  112. package/dist/component/affiliateRecovery/queries.d.ts +305 -0
  113. package/dist/component/affiliateRecovery/queries.d.ts.map +1 -0
  114. package/dist/component/affiliateRecovery/queries.js +113 -0
  115. package/dist/component/affiliateRecovery/queries.js.map +1 -0
  116. package/dist/component/affiliateRecovery/schema.d.ts +171 -0
  117. package/dist/component/affiliateRecovery/schema.d.ts.map +1 -0
  118. package/dist/component/affiliateRecovery/schema.js +71 -0
  119. package/dist/component/affiliateRecovery/schema.js.map +1 -0
  120. package/dist/component/connect/mutations.d.ts +36 -23
  121. package/dist/component/connect/mutations.d.ts.map +1 -1
  122. package/dist/component/connect/mutations.js +11 -151
  123. package/dist/component/connect/mutations.js.map +1 -1
  124. package/dist/component/connect/payoutWrites.d.ts +21 -0
  125. package/dist/component/connect/payoutWrites.d.ts.map +1 -0
  126. package/dist/component/connect/payoutWrites.js +19 -0
  127. package/dist/component/connect/payoutWrites.js.map +1 -0
  128. package/dist/component/connect/queries.d.ts +10 -0
  129. package/dist/component/connect/queries.d.ts.map +1 -1
  130. package/dist/component/connect/queries.js +3 -40
  131. package/dist/component/connect/queries.js.map +1 -1
  132. package/dist/component/connect/reversalClaims.d.ts +169 -0
  133. package/dist/component/connect/reversalClaims.d.ts.map +1 -0
  134. package/dist/component/connect/reversalClaims.js +176 -0
  135. package/dist/component/connect/reversalClaims.js.map +1 -0
  136. package/dist/component/connect/reversalDiagnostics.d.ts +59 -0
  137. package/dist/component/connect/reversalDiagnostics.d.ts.map +1 -0
  138. package/dist/component/connect/reversalDiagnostics.js +50 -0
  139. package/dist/component/connect/reversalDiagnostics.js.map +1 -0
  140. package/dist/component/connect/reversalReceipts.d.ts +27 -0
  141. package/dist/component/connect/reversalReceipts.d.ts.map +1 -0
  142. package/dist/component/connect/reversalReceipts.js +85 -0
  143. package/dist/component/connect/reversalReceipts.js.map +1 -0
  144. package/dist/component/connect/schema.d.ts +31 -1
  145. package/dist/component/connect/schema.d.ts.map +1 -1
  146. package/dist/component/connect/schema.js +3 -1
  147. package/dist/component/connect/schema.js.map +1 -1
  148. package/dist/component/connect/validators.d.ts +49 -1
  149. package/dist/component/connect/validators.d.ts.map +1 -1
  150. package/dist/component/connect/validators.js +2 -0
  151. package/dist/component/connect/validators.js.map +1 -1
  152. package/dist/component/earnings/triggers.d.ts +454 -2
  153. package/dist/component/earnings/triggers.d.ts.map +1 -1
  154. package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
  155. package/dist/component/payoutRelease/mutations.js +6 -0
  156. package/dist/component/payoutRelease/mutations.js.map +1 -1
  157. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  158. package/dist/component/payoutRelease/queries.js +3 -1
  159. package/dist/component/payoutRelease/queries.js.map +1 -1
  160. package/dist/component/payoutSync/helpers.d.ts +44 -0
  161. package/dist/component/payoutSync/helpers.d.ts.map +1 -0
  162. package/dist/component/payoutSync/helpers.js +60 -0
  163. package/dist/component/payoutSync/helpers.js.map +1 -0
  164. package/dist/component/payoutSync/mutations.d.ts +51 -0
  165. package/dist/component/payoutSync/mutations.d.ts.map +1 -0
  166. package/dist/component/payoutSync/mutations.js +88 -0
  167. package/dist/component/payoutSync/mutations.js.map +1 -0
  168. package/dist/component/payoutSync/queries.d.ts +16 -0
  169. package/dist/component/payoutSync/queries.d.ts.map +1 -0
  170. package/dist/component/payoutSync/queries.js +11 -0
  171. package/dist/component/payoutSync/queries.js.map +1 -0
  172. package/dist/component/payoutSync/schema.d.ts +46 -0
  173. package/dist/component/payoutSync/schema.d.ts.map +1 -0
  174. package/dist/component/payoutSync/schema.js +22 -0
  175. package/dist/component/payoutSync/schema.js.map +1 -0
  176. package/dist/component/payoutSync/validators.d.ts +137 -0
  177. package/dist/component/payoutSync/validators.d.ts.map +1 -0
  178. package/dist/component/payoutSync/validators.js +19 -0
  179. package/dist/component/payoutSync/validators.js.map +1 -0
  180. package/dist/component/schema.d.ts +268 -1
  181. package/dist/component/schema.js +11 -0
  182. package/dist/component/schema.js.map +1 -1
  183. package/dist/component/settlement/clawbackSchema.d.ts +161 -0
  184. package/dist/component/settlement/clawbackSchema.d.ts.map +1 -0
  185. package/dist/component/settlement/clawbackSchema.js +73 -0
  186. package/dist/component/settlement/clawbackSchema.js.map +1 -0
  187. package/dist/component/settlement/clawbacks.d.ts +55 -0
  188. package/dist/component/settlement/clawbacks.d.ts.map +1 -0
  189. package/dist/component/settlement/clawbacks.js +146 -0
  190. package/dist/component/settlement/clawbacks.js.map +1 -0
  191. package/dist/component/settlement/mutations.d.ts +16 -0
  192. package/dist/component/settlement/mutations.d.ts.map +1 -1
  193. package/dist/component/settlement/mutations.js +48 -0
  194. package/dist/component/settlement/mutations.js.map +1 -1
  195. package/dist/component/settlement/queries.d.ts +53 -0
  196. package/dist/component/settlement/queries.d.ts.map +1 -1
  197. package/dist/component/settlement/queries.js +26 -0
  198. package/dist/component/settlement/queries.js.map +1 -1
  199. package/dist/react/workflows/AffiliateRecovery.d.ts +46 -0
  200. package/dist/react/workflows/AffiliateRecovery.d.ts.map +1 -0
  201. package/dist/react/workflows/AffiliateRecovery.js +84 -0
  202. package/dist/react/workflows/AffiliateRecovery.js.map +1 -0
  203. package/dist/react/workflows/index.d.ts +2 -0
  204. package/dist/react/workflows/index.d.ts.map +1 -1
  205. package/dist/react/workflows/index.js +1 -0
  206. package/dist/react/workflows/index.js.map +1 -1
  207. package/dist/testing/affiliate-recovery.d.ts +10 -0
  208. package/dist/testing/affiliate-recovery.d.ts.map +1 -0
  209. package/dist/testing/affiliate-recovery.js +126 -0
  210. package/dist/testing/affiliate-recovery.js.map +1 -0
  211. package/dist/testing/index.d.ts +2 -0
  212. package/dist/testing/index.d.ts.map +1 -1
  213. package/dist/testing/index.js +1 -0
  214. package/dist/testing/index.js.map +1 -1
  215. package/docs/affiliate-clawbacks.md +306 -0
  216. package/docs/read-contracts.md +40 -5
  217. package/docs/settlement.md +17 -0
  218. package/package.json +2 -1
  219. package/src/client/affiliateRecovery/disputes.ts +62 -0
  220. package/src/client/affiliateRecovery/engine.ts +196 -0
  221. package/src/client/affiliateRecovery/payoutGate.ts +65 -0
  222. package/src/client/affiliateRecovery/provider.ts +127 -0
  223. package/src/client/affiliateRecovery/review.ts +117 -0
  224. package/src/client/affiliateRecovery/validators.ts +38 -0
  225. package/src/client/affiliateRecovery.ts +173 -0
  226. package/src/client/connect/commissionReceipts.test.ts +157 -0
  227. package/src/client/connect/commissionReceipts.ts +23 -0
  228. package/src/client/connect/payoutSync.test.ts +313 -0
  229. package/src/client/connect/payoutSync.ts +93 -0
  230. package/src/client/connect/payoutSyncTestHelpers.ts +82 -0
  231. package/src/client/connect/payoutSyncValidation.ts +74 -0
  232. package/src/client/connect/payouts.ts +75 -15
  233. package/src/client/connect/refundPrincipal.test.ts +46 -0
  234. package/src/client/connect/refundPrincipal.ts +26 -0
  235. package/src/client/connect/reversalExecution.ts +130 -0
  236. package/src/client/connect/transfers.test.ts +3 -3
  237. package/src/client/connect/transfers.ts +93 -92
  238. package/src/client/index.ts +20 -18
  239. package/src/client/readContracts.ts +12 -0
  240. package/src/client/settlement/execution.test.ts +5 -0
  241. package/src/client/settlement/execution.ts +50 -3
  242. package/src/client/settlement/reconciliation.ts +20 -2
  243. package/src/client/webhooks/disputeRecovery.ts +74 -0
  244. package/src/client/webhooks/processors.test.ts +36 -53
  245. package/src/client/webhooks/processors.ts +18 -31
  246. package/src/component/_generated/api.ts +34 -0
  247. package/src/component/_generated/component.ts +696 -1
  248. package/src/component/affiliate-clawbacks.test.ts +370 -0
  249. package/src/component/affiliate-component-pagination.test.ts +83 -0
  250. package/src/component/affiliate-direct-payout.test.ts +160 -0
  251. package/src/component/affiliate-recovery-lifecycle.test.ts +587 -0
  252. package/src/component/affiliateEarnings/mutations.ts +196 -0
  253. package/src/component/affiliatePayouts/mutations.ts +121 -0
  254. package/src/component/affiliatePayouts/queries.ts +28 -0
  255. package/src/component/affiliatePayouts/recipientGuard.ts +42 -0
  256. package/src/component/affiliateRecovery/accounting.ts +111 -0
  257. package/src/component/affiliateRecovery/mutations.ts +275 -0
  258. package/src/component/affiliateRecovery/queries.ts +138 -0
  259. package/src/component/affiliateRecovery/schema.ts +86 -0
  260. package/src/component/connect/mutations.ts +13 -190
  261. package/src/component/connect/payoutWrites.ts +25 -0
  262. package/src/component/connect/queries.ts +4 -47
  263. package/src/component/connect/reversalClaims.ts +232 -0
  264. package/src/component/connect/reversalDiagnostics.ts +61 -0
  265. package/src/component/connect/reversalReceipts.ts +147 -0
  266. package/src/component/connect/schema.ts +3 -3
  267. package/src/component/connect/validators.ts +2 -0
  268. package/src/component/payout-recovery-integration.test.ts +172 -0
  269. package/src/component/payout-sync.test.ts +117 -0
  270. package/src/component/payoutRelease/mutations.ts +9 -0
  271. package/src/component/payoutRelease/queries.ts +3 -1
  272. package/src/component/payoutSync/helpers.ts +86 -0
  273. package/src/component/payoutSync/mutations.ts +102 -0
  274. package/src/component/payoutSync/queries.ts +10 -0
  275. package/src/component/payoutSync/schema.ts +25 -0
  276. package/src/component/payoutSync/validators.ts +21 -0
  277. package/src/component/schema.ts +20 -0
  278. package/src/component/settlement/clawbackSchema.ts +78 -0
  279. package/src/component/settlement/clawbacks.ts +233 -0
  280. package/src/component/settlement/mutations.ts +54 -0
  281. package/src/component/settlement/queries.ts +35 -0
  282. package/src/component/summary-arithmetic.test.ts +9 -4
  283. package/src/react/workflows/AffiliateRecovery.test.tsx +106 -0
  284. package/src/react/workflows/AffiliateRecovery.tsx +273 -0
  285. package/src/react/workflows/index.ts +9 -0
  286. package/src/testing/affiliate-recovery.ts +137 -0
  287. package/src/testing/index.ts +2 -0
@@ -0,0 +1,113 @@
1
+ import { paginator } from "convex-helpers/server/pagination";
2
+ import schema from "../schema.js";
3
+ import { paginationOptsValidator, paginationResultValidator, } from "convex/server";
4
+ import { v } from "convex/values";
5
+ import { query } from "../_generated/server.js";
6
+ import { obligationFields } from "../settlement/clawbackSchema.js";
7
+ import { balanceFields, operationFields, earningFields } from "./schema.js";
8
+ export const obligationDoc = v.object({
9
+ ...obligationFields,
10
+ _id: v.id("affiliateObligations"),
11
+ _creationTime: v.number(),
12
+ });
13
+ export const getObligation = query({
14
+ args: { obligationId: v.id("affiliateObligations") },
15
+ returns: v.union(obligationDoc, v.null()),
16
+ handler: (ctx, args) => ctx.db.get("affiliateObligations", args.obligationId),
17
+ });
18
+ export const chargeObligations = query({
19
+ args: { sourceChargeId: v.string() },
20
+ returns: v.array(obligationDoc),
21
+ handler: async (ctx, args) => {
22
+ const rows = await ctx.db
23
+ .query("affiliateObligations")
24
+ .withIndex("by_charge", (q) => q.eq("sourceChargeId", args.sourceChargeId))
25
+ .take(1001);
26
+ if (rows.length > 1000)
27
+ throw new Error("Affiliate charge recovery limit exceeded.");
28
+ return rows;
29
+ },
30
+ });
31
+ export const getEarning = query({
32
+ args: { sourceChargeId: v.string(), affiliateAccountId: v.string() },
33
+ returns: v.union(v.object({
34
+ ...earningFields,
35
+ _id: v.id("affiliateEarnings"),
36
+ _creationTime: v.number(),
37
+ }), v.null()),
38
+ handler: (ctx, args) => ctx.db
39
+ .query("affiliateEarnings")
40
+ .withIndex("by_charge_affiliate", (q) => q
41
+ .eq("sourceChargeId", args.sourceChargeId)
42
+ .eq("affiliateAccountId", args.affiliateAccountId))
43
+ .unique(),
44
+ });
45
+ export const recoverySnapshot = query({
46
+ args: {
47
+ affiliateAccountId: v.string(),
48
+ currency: v.string(),
49
+ paginationOpts: paginationOptsValidator,
50
+ },
51
+ returns: v.object({
52
+ balance: v.union(v.object({
53
+ ...balanceFields,
54
+ _id: v.id("affiliateRecoveryBalances"),
55
+ _creationTime: v.number(),
56
+ }), v.null()),
57
+ obligations: paginationResultValidator(obligationDoc),
58
+ }),
59
+ handler: async (ctx, args) => ({
60
+ balance: await ctx.db
61
+ .query("affiliateRecoveryBalances")
62
+ .withIndex("by_affiliate_currency", (q) => q
63
+ .eq("affiliateAccountId", args.affiliateAccountId)
64
+ .eq("currency", args.currency))
65
+ .unique(),
66
+ obligations: await paginator(ctx.db, schema)
67
+ .query("affiliateObligations")
68
+ .withIndex("by_affiliate_currency", (q) => q
69
+ .eq("affiliateAccountId", args.affiliateAccountId)
70
+ .eq("currency", args.currency))
71
+ .paginate({
72
+ ...args.paginationOpts,
73
+ numItems: Math.min(100, args.paginationOpts.numItems),
74
+ }),
75
+ }),
76
+ });
77
+ export const operationHistory = query({
78
+ args: {
79
+ obligationId: v.id("affiliateObligations"),
80
+ paginationOpts: paginationOptsValidator,
81
+ },
82
+ returns: paginationResultValidator(v.object({
83
+ ...operationFields,
84
+ _id: v.id("affiliateRecoveryOperations"),
85
+ _creationTime: v.number(),
86
+ })),
87
+ handler: (ctx, args) => paginator(ctx.db, schema)
88
+ .query("affiliateRecoveryOperations")
89
+ .withIndex("by_obligation", (q) => q.eq("obligationId", args.obligationId))
90
+ .paginate({
91
+ ...args.paginationOpts,
92
+ numItems: Math.min(100, args.paginationOpts.numItems),
93
+ }),
94
+ });
95
+ export const pendingOperations = query({
96
+ args: {
97
+ paginationOpts: paginationOptsValidator,
98
+ state: v.union(v.literal("pending"), v.literal("unknown")),
99
+ },
100
+ returns: paginationResultValidator(v.object({
101
+ ...operationFields,
102
+ _id: v.id("affiliateRecoveryOperations"),
103
+ _creationTime: v.number(),
104
+ })),
105
+ handler: (ctx, args) => paginator(ctx.db, schema)
106
+ .query("affiliateRecoveryOperations")
107
+ .withIndex("by_state", (q) => q.eq("state", args.state))
108
+ .paginate({
109
+ ...args.paginationOpts,
110
+ numItems: Math.min(50, args.paginationOpts.numItems),
111
+ }),
112
+ });
113
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/affiliateRecovery/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,GAAG,gBAAgB;IACnB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC;IACjC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;IACjC,IAAI,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC,EAAE;IACpD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzC,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,YAAY,CAAC;CAC9E,CAA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IACD,OAAO,EAAE,yBAAyB,CAChC,CAAC,CAAC,MAAM,CAAC;QACP,GAAG,eAAe;QAClB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,6BAA6B,CAAC;QACxC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;KAC1B,CAAC,CACH;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CACrB,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC;SACtB,KAAK,CAAC,6BAA6B,CAAC;SACpC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;SACvD,QAAQ,CAAC;QACR,GAAG,IAAI,CAAC,cAAc;QACtB,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;KACrD,CAAC;CACP,CAAC,CAAC"}
@@ -0,0 +1,171 @@
1
+ export declare const recoveryState: import("convex/values").VUnion<"canceled" | "failed" | "insufficient_balance" | "pending" | "succeeded" | "unknown" | "unsupported", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"insufficient_balance", "required">, import("convex/values").VLiteral<"unsupported", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"succeeded", "required">, import("convex/values").VLiteral<"canceled", "required">], "required", never>;
2
+ export declare const operationFields: {
3
+ obligationId: import("convex/values").VId<import("convex/values").GenericId<"affiliateObligations">, "required">;
4
+ sourceEventId: import("convex/values").VString<string | undefined, "optional">;
5
+ kind: import("convex/values").VUnion<"recovery" | "restoration", [import("convex/values").VLiteral<"recovery", "required">, import("convex/values").VLiteral<"restoration", "required">], "required", never>;
6
+ amount: import("convex/values").VFloat64<number, "required">;
7
+ state: import("convex/values").VUnion<"canceled" | "failed" | "insufficient_balance" | "pending" | "succeeded" | "unknown" | "unsupported", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"insufficient_balance", "required">, import("convex/values").VLiteral<"unsupported", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"succeeded", "required">, import("convex/values").VLiteral<"canceled", "required">], "required", never>;
8
+ receiptId: import("convex/values").VString<string | undefined, "optional">;
9
+ error: import("convex/values").VString<string | undefined, "optional">;
10
+ attempted: import("convex/values").VBoolean<boolean, "required">;
11
+ providerBaseline: import("convex/values").VFloat64<number | undefined, "optional">;
12
+ createdAt: import("convex/values").VFloat64<number, "required">;
13
+ };
14
+ export declare const operationsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
15
+ amount: number;
16
+ attempted: boolean;
17
+ createdAt: number;
18
+ error?: string | undefined;
19
+ kind: "recovery" | "restoration";
20
+ obligationId: import("convex/values").GenericId<"affiliateObligations">;
21
+ providerBaseline?: number | undefined;
22
+ receiptId?: string | undefined;
23
+ sourceEventId?: string | undefined;
24
+ state: "canceled" | "failed" | "insufficient_balance" | "pending" | "succeeded" | "unknown" | "unsupported";
25
+ }, {
26
+ obligationId: import("convex/values").VId<import("convex/values").GenericId<"affiliateObligations">, "required">;
27
+ sourceEventId: import("convex/values").VString<string | undefined, "optional">;
28
+ kind: import("convex/values").VUnion<"recovery" | "restoration", [import("convex/values").VLiteral<"recovery", "required">, import("convex/values").VLiteral<"restoration", "required">], "required", never>;
29
+ amount: import("convex/values").VFloat64<number, "required">;
30
+ state: import("convex/values").VUnion<"canceled" | "failed" | "insufficient_balance" | "pending" | "succeeded" | "unknown" | "unsupported", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"insufficient_balance", "required">, import("convex/values").VLiteral<"unsupported", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"succeeded", "required">, import("convex/values").VLiteral<"canceled", "required">], "required", never>;
31
+ receiptId: import("convex/values").VString<string | undefined, "optional">;
32
+ error: import("convex/values").VString<string | undefined, "optional">;
33
+ attempted: import("convex/values").VBoolean<boolean, "required">;
34
+ providerBaseline: import("convex/values").VFloat64<number | undefined, "optional">;
35
+ createdAt: import("convex/values").VFloat64<number, "required">;
36
+ }, "required", "amount" | "attempted" | "createdAt" | "error" | "kind" | "obligationId" | "providerBaseline" | "receiptId" | "sourceEventId" | "state">, {
37
+ by_obligation: ["obligationId", "_creationTime"];
38
+ by_state: ["state", "_creationTime"];
39
+ }, {}, {}>;
40
+ export declare const earningFields: {
41
+ sourceChargeId: import("convex/values").VString<string, "required">;
42
+ affiliateAccountId: import("convex/values").VString<string, "required">;
43
+ currency: import("convex/values").VString<string, "required">;
44
+ originalCommission: import("convex/values").VFloat64<number, "required">;
45
+ withheldAmount: import("convex/values").VFloat64<number, "required">;
46
+ releaseAmount: import("convex/values").VFloat64<number, "required">;
47
+ sourceInvoiceId: import("convex/values").VString<string | undefined, "optional">;
48
+ paymentIntentId: import("convex/values").VString<string | undefined, "optional">;
49
+ stripeTransferId: import("convex/values").VString<string | undefined, "optional">;
50
+ status: import("convex/values").VUnion<"paid" | "reserved", [import("convex/values").VLiteral<"reserved", "required">, import("convex/values").VLiteral<"paid", "required">], "required", never>;
51
+ };
52
+ export declare const earningsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
53
+ affiliateAccountId: string;
54
+ currency: string;
55
+ originalCommission: number;
56
+ paymentIntentId?: string | undefined;
57
+ releaseAmount: number;
58
+ sourceChargeId: string;
59
+ sourceInvoiceId?: string | undefined;
60
+ status: "paid" | "reserved";
61
+ stripeTransferId?: string | undefined;
62
+ withheldAmount: number;
63
+ }, {
64
+ sourceChargeId: import("convex/values").VString<string, "required">;
65
+ affiliateAccountId: import("convex/values").VString<string, "required">;
66
+ currency: import("convex/values").VString<string, "required">;
67
+ originalCommission: import("convex/values").VFloat64<number, "required">;
68
+ withheldAmount: import("convex/values").VFloat64<number, "required">;
69
+ releaseAmount: import("convex/values").VFloat64<number, "required">;
70
+ sourceInvoiceId: import("convex/values").VString<string | undefined, "optional">;
71
+ paymentIntentId: import("convex/values").VString<string | undefined, "optional">;
72
+ stripeTransferId: import("convex/values").VString<string | undefined, "optional">;
73
+ status: import("convex/values").VUnion<"paid" | "reserved", [import("convex/values").VLiteral<"reserved", "required">, import("convex/values").VLiteral<"paid", "required">], "required", never>;
74
+ }, "required", "affiliateAccountId" | "currency" | "originalCommission" | "paymentIntentId" | "releaseAmount" | "sourceChargeId" | "sourceInvoiceId" | "status" | "stripeTransferId" | "withheldAmount">, {
75
+ by_affiliate_currency: ["affiliateAccountId", "currency", "_creationTime"];
76
+ by_charge_affiliate: ["sourceChargeId", "affiliateAccountId", "_creationTime"];
77
+ }, {}, {}>;
78
+ export declare const offsetsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
79
+ amount: number;
80
+ earningId: import("convex/values").GenericId<"affiliateEarnings">;
81
+ obligationId: import("convex/values").GenericId<"affiliateObligations">;
82
+ }, {
83
+ earningId: import("convex/values").VId<import("convex/values").GenericId<"affiliateEarnings">, "required">;
84
+ obligationId: import("convex/values").VId<import("convex/values").GenericId<"affiliateObligations">, "required">;
85
+ amount: import("convex/values").VFloat64<number, "required">;
86
+ }, "required", "amount" | "earningId" | "obligationId">, {
87
+ by_earning: ["earningId", "_creationTime"];
88
+ by_obligation: ["obligationId", "_creationTime"];
89
+ }, {}, {}>;
90
+ export declare const balanceFields: {
91
+ activePayoutKey: import("convex/values").VString<string | undefined, "optional">;
92
+ pendingPayoutAmount: import("convex/values").VFloat64<number | undefined, "optional">;
93
+ affiliateAccountId: import("convex/values").VString<string, "required">;
94
+ currency: import("convex/values").VString<string, "required">;
95
+ originalCommission: import("convex/values").VFloat64<number, "required">;
96
+ recoveredAmount: import("convex/values").VFloat64<number, "required">;
97
+ offsetAmount: import("convex/values").VFloat64<number, "required">;
98
+ restoredAmount: import("convex/values").VFloat64<number, "required">;
99
+ outstandingDebt: import("convex/values").VFloat64<number, "required">;
100
+ reservedRecovery: import("convex/values").VFloat64<number, "required">;
101
+ reservedRestoration: import("convex/values").VFloat64<number, "required">;
102
+ restorationDue: import("convex/values").VFloat64<number, "required">;
103
+ withheldAmount: import("convex/values").VFloat64<number, "required">;
104
+ netPayable: import("convex/values").VFloat64<number, "required">;
105
+ };
106
+ export declare const balancesTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
107
+ activePayoutKey?: string | undefined;
108
+ affiliateAccountId: string;
109
+ currency: string;
110
+ netPayable: number;
111
+ offsetAmount: number;
112
+ originalCommission: number;
113
+ outstandingDebt: number;
114
+ pendingPayoutAmount?: number | undefined;
115
+ recoveredAmount: number;
116
+ reservedRecovery: number;
117
+ reservedRestoration: number;
118
+ restorationDue: number;
119
+ restoredAmount: number;
120
+ withheldAmount: number;
121
+ }, {
122
+ activePayoutKey: import("convex/values").VString<string | undefined, "optional">;
123
+ pendingPayoutAmount: import("convex/values").VFloat64<number | undefined, "optional">;
124
+ affiliateAccountId: import("convex/values").VString<string, "required">;
125
+ currency: import("convex/values").VString<string, "required">;
126
+ originalCommission: import("convex/values").VFloat64<number, "required">;
127
+ recoveredAmount: import("convex/values").VFloat64<number, "required">;
128
+ offsetAmount: import("convex/values").VFloat64<number, "required">;
129
+ restoredAmount: import("convex/values").VFloat64<number, "required">;
130
+ outstandingDebt: import("convex/values").VFloat64<number, "required">;
131
+ reservedRecovery: import("convex/values").VFloat64<number, "required">;
132
+ reservedRestoration: import("convex/values").VFloat64<number, "required">;
133
+ restorationDue: import("convex/values").VFloat64<number, "required">;
134
+ withheldAmount: import("convex/values").VFloat64<number, "required">;
135
+ netPayable: import("convex/values").VFloat64<number, "required">;
136
+ }, "required", "activePayoutKey" | "affiliateAccountId" | "currency" | "netPayable" | "offsetAmount" | "originalCommission" | "outstandingDebt" | "pendingPayoutAmount" | "recoveredAmount" | "reservedRecovery" | "reservedRestoration" | "restorationDue" | "restoredAmount" | "withheldAmount">, {
137
+ by_affiliate_currency: ["affiliateAccountId", "currency", "_creationTime"];
138
+ }, {}, {}>;
139
+ export declare const payoutReleaseFields: {
140
+ affiliateAccountId: import("convex/values").VString<string, "required">;
141
+ currency: import("convex/values").VString<string, "required">;
142
+ operationKey: import("convex/values").VString<string, "required">;
143
+ amount: import("convex/values").VFloat64<number, "required">;
144
+ minimumAmount: import("convex/values").VFloat64<number, "required">;
145
+ state: import("convex/values").VUnion<"failed" | "pending" | "submitted" | "unknown", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"submitted", "required">, import("convex/values").VLiteral<"failed", "required">], "required", never>;
146
+ stripePayoutId: import("convex/values").VString<string | undefined, "optional">;
147
+ createdAt: import("convex/values").VFloat64<number, "required">;
148
+ };
149
+ export declare const payoutReleasesTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
150
+ affiliateAccountId: string;
151
+ amount: number;
152
+ createdAt: number;
153
+ currency: string;
154
+ minimumAmount: number;
155
+ operationKey: string;
156
+ state: "failed" | "pending" | "submitted" | "unknown";
157
+ stripePayoutId?: string | undefined;
158
+ }, {
159
+ affiliateAccountId: import("convex/values").VString<string, "required">;
160
+ currency: import("convex/values").VString<string, "required">;
161
+ operationKey: import("convex/values").VString<string, "required">;
162
+ amount: import("convex/values").VFloat64<number, "required">;
163
+ minimumAmount: import("convex/values").VFloat64<number, "required">;
164
+ state: import("convex/values").VUnion<"failed" | "pending" | "submitted" | "unknown", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"submitted", "required">, import("convex/values").VLiteral<"failed", "required">], "required", never>;
165
+ stripePayoutId: import("convex/values").VString<string | undefined, "optional">;
166
+ createdAt: import("convex/values").VFloat64<number, "required">;
167
+ }, "required", "affiliateAccountId" | "amount" | "createdAt" | "currency" | "minimumAmount" | "operationKey" | "state" | "stripePayoutId">, {
168
+ by_key: ["operationKey", "_creationTime"];
169
+ by_state: ["state", "_creationTime"];
170
+ }, {}, {}>;
171
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/affiliateRecovery/schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,6jBAQzB,CAAC;AACF,eAAO,MAAM,eAAe;IAC1B,YAAY;IACZ,aAAa;IACb,IAAI;IACJ,MAAM;IACN,KAAK;IACL,SAAS;IACT,KAAK;IACL,SAAS;IACT,gBAAgB;IAChB,SAAS;CACV,CAAC;AACF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;UAEG,CAAC;AAChC,eAAO,MAAM,aAAa;IACxB,cAAc;IACd,kBAAkB;IAClB,QAAQ;IACR,kBAAkB;IAClB,cAAc;IACd,aAAa;IACb,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,MAAM;CACP,CAAC;AACF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;UAE2C,CAAC;AACtE,eAAO,MAAM,YAAY;;;;;;;;;;;UAMkB,CAAC;AAC5C,eAAO,MAAM,aAAa;IACxB,eAAe;IACf,mBAAmB;IACnB,kBAAkB;IAClB,QAAQ;IACR,kBAAkB;IAClB,eAAe;IACf,YAAY;IACZ,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,mBAAmB;IACnB,cAAc;IACd,cAAc;IACd,UAAU;CACX,CAAC;AACF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAGzB,CAAC;AACF,eAAO,MAAM,mBAAmB;IAC9B,kBAAkB;IAClB,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,aAAa;IACb,KAAK;IAML,cAAc;IACd,SAAS;CACV,CAAC;AACF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;UAED,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ export const recoveryState = v.union(v.literal("pending"), v.literal("unknown"), v.literal("insufficient_balance"), v.literal("unsupported"), v.literal("failed"), v.literal("succeeded"), v.literal("canceled"));
4
+ export const operationFields = {
5
+ obligationId: v.id("affiliateObligations"),
6
+ sourceEventId: v.optional(v.string()),
7
+ kind: v.union(v.literal("recovery"), v.literal("restoration")),
8
+ amount: v.number(),
9
+ state: recoveryState,
10
+ receiptId: v.optional(v.string()),
11
+ error: v.optional(v.string()),
12
+ attempted: v.boolean(),
13
+ providerBaseline: v.optional(v.number()),
14
+ createdAt: v.number(),
15
+ };
16
+ export const operationsTable = defineTable(operationFields)
17
+ .index("by_obligation", ["obligationId"])
18
+ .index("by_state", ["state"]);
19
+ export const earningFields = {
20
+ sourceChargeId: v.string(),
21
+ affiliateAccountId: v.string(),
22
+ currency: v.string(),
23
+ originalCommission: v.number(),
24
+ withheldAmount: v.number(),
25
+ releaseAmount: v.number(),
26
+ sourceInvoiceId: v.optional(v.string()),
27
+ paymentIntentId: v.optional(v.string()),
28
+ stripeTransferId: v.optional(v.string()),
29
+ status: v.union(v.literal("reserved"), v.literal("paid")),
30
+ };
31
+ export const earningsTable = defineTable(earningFields)
32
+ .index("by_charge_affiliate", ["sourceChargeId", "affiliateAccountId"])
33
+ .index("by_affiliate_currency", ["affiliateAccountId", "currency"]);
34
+ export const offsetsTable = defineTable({
35
+ earningId: v.id("affiliateEarnings"),
36
+ obligationId: v.id("affiliateObligations"),
37
+ amount: v.number(),
38
+ })
39
+ .index("by_earning", ["earningId"])
40
+ .index("by_obligation", ["obligationId"]);
41
+ export const balanceFields = {
42
+ activePayoutKey: v.optional(v.string()),
43
+ pendingPayoutAmount: v.optional(v.number()),
44
+ affiliateAccountId: v.string(),
45
+ currency: v.string(),
46
+ originalCommission: v.number(),
47
+ recoveredAmount: v.number(),
48
+ offsetAmount: v.number(),
49
+ restoredAmount: v.number(),
50
+ outstandingDebt: v.number(),
51
+ reservedRecovery: v.number(),
52
+ reservedRestoration: v.number(),
53
+ restorationDue: v.number(),
54
+ withheldAmount: v.number(),
55
+ netPayable: v.number(),
56
+ };
57
+ export const balancesTable = defineTable(balanceFields).index("by_affiliate_currency", ["affiliateAccountId", "currency"]);
58
+ export const payoutReleaseFields = {
59
+ affiliateAccountId: v.string(),
60
+ currency: v.string(),
61
+ operationKey: v.string(),
62
+ amount: v.number(),
63
+ minimumAmount: v.number(),
64
+ state: v.union(v.literal("pending"), v.literal("unknown"), v.literal("submitted"), v.literal("failed")),
65
+ stripePayoutId: v.optional(v.string()),
66
+ createdAt: v.number(),
67
+ };
68
+ export const payoutReleasesTable = defineTable(payoutReleaseFields)
69
+ .index("by_key", ["operationKey"])
70
+ .index("by_state", ["state"]);
71
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/affiliateRecovery/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAClC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,EACjC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,EACxB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EACtB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CACtB,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC;IAC1C,aAAa,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,UAA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AE,CAAC,CAAC,MAAM,EAAE;IAC1B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC,KAAK,CAC3D,uBAAuB,EACvB,CAAC,oBAAoB,EAAE,UAAU,CAAC,CACnC,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,KAAK,EAAE,CAAC,CAAC,KAAK,CACZ,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EACtB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CACpB;IACD,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACtC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,mBAAmB,CAAC;KAChE,KAAK,CAAC,QAAQ,EAAE,CAAC,cAAc,CAAC,CAAC;KACjC,KAAK,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC"}
@@ -99,29 +99,18 @@ export declare const upsertTransfer: import("convex/server").RegisteredMutation<
99
99
  * is the new cumulative total (matches Stripe's `Transfer.amount_reversed`).
100
100
  */
101
101
  export declare const recordTransferReversal: import("convex/server").RegisteredMutation<"public", {
102
- reversedAmount: number;
103
102
  stripeTransferId: string;
103
+ reversedAmount: number;
104
+ receipt?: {
105
+ stripeReversalId: string;
106
+ operationId: string;
107
+ amount: number;
108
+ };
104
109
  }, Promise<null>>;
105
- /**
106
- * Atomically claim reversal slices for one operation (a dispute or refund
107
- * clawback) BEFORE any money moves (BTS-63). Runs in a single transaction, so
108
- * concurrent operations serialize here instead of racing between the ledger
109
- * read and the Stripe call:
110
- *
111
- * - First claim for an `operationId`: computes slices against each leg's
112
- * claim frontier (`max(reversedAmount, reversalClaimedAmount)`), advances
113
- * the frontier, and records the slices — atomically. A concurrent distinct
114
- * operation claiming the same target gets an EMPTY claim, not a duplicate.
115
- * - Any later call with the same `operationId` (webhook redelivery, retry
116
- * after a partial failure) replays the recorded slices verbatim, so the
117
- * caller re-sends byte-identical Stripe params under the same idempotency
118
- * keys no matter how the ledger moved in between.
119
- *
120
- * Each returned slice carries the leg's current CONFIRMED `reversedAmount` so
121
- * the executor can skip slices whose money already moved and was recorded.
122
- */
123
110
  export declare const claimReversalSlices: import("convex/server").RegisteredMutation<"public", {
124
- mode: {
111
+ operationId: string;
112
+ sourceChargeId: string;
113
+ mode: import("convex/values").Infer<import("convex/values").VUnion<{
125
114
  kind: "full";
126
115
  } | {
127
116
  kind: "percent";
@@ -133,13 +122,37 @@ export declare const claimReversalSlices: import("convex/server").RegisteredMuta
133
122
  amountRefunded: number;
134
123
  chargeAmount: number;
135
124
  kind: "fraction";
136
- };
137
- operationId: string;
138
- sourceChargeId: string;
125
+ }, [import("convex/values").VObject<{
126
+ kind: "full";
127
+ }, {
128
+ kind: import("convex/values").VLiteral<"full", "required">;
129
+ }, "required", "kind">, import("convex/values").VObject<{
130
+ kind: "percent";
131
+ percent: number;
132
+ }, {
133
+ kind: import("convex/values").VLiteral<"percent", "required">;
134
+ percent: import("convex/values").VFloat64<number, "required">;
135
+ }, "required", "kind" | "percent">, import("convex/values").VObject<{
136
+ amount: number;
137
+ kind: "amount";
138
+ }, {
139
+ kind: import("convex/values").VLiteral<"amount", "required">;
140
+ amount: import("convex/values").VFloat64<number, "required">;
141
+ }, "required", "amount" | "kind">, import("convex/values").VObject<{
142
+ amountRefunded: number;
143
+ chargeAmount: number;
144
+ kind: "fraction";
145
+ }, {
146
+ kind: import("convex/values").VLiteral<"fraction", "required">;
147
+ chargeAmount: import("convex/values").VFloat64<number, "required">;
148
+ amountRefunded: import("convex/values").VFloat64<number, "required">;
149
+ }, "required", "amountRefunded" | "chargeAmount" | "kind">], "required", "amount" | "amountRefunded" | "chargeAmount" | "kind" | "percent">>;
150
+ commissionExposure?: import("convex/values").Infer<typeof import("../settlement/clawbackSchema.js").commissionExposureValidator>;
139
151
  }, Promise<{
140
152
  replay: boolean;
141
153
  slices: {
142
154
  confirmed: number;
155
+ commissionTracked?: boolean | undefined;
143
156
  from: number;
144
157
  stripeTransferId: string;
145
158
  to: number;
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/connect/mutations.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;iBA6FxB,CAAC;AAIH,eAAO,MAAM,YAAY;;;;;;;;;;;iBAkCvB,CAAC;AAIH,eAAO,MAAM,YAAY;;;;;;;;;;;iBAiEvB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB;;;;iBAwDjC,CAAC;AAIH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;iBAsBxB,CAAC;AAIH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;iBAmCzB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;iBAqCjC,CAAC;AAcH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;GA0F9B,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;0BA+EM,MAAM;YAAM,MAAM;;GAWvD,CAAC"}
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/conn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