@fantastic.dev/better-stripe 0.33.0 → 0.35.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 (314) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +30 -1
  3. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +522 -2
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  5. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +261 -1
  6. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  7. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +522 -2
  8. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  9. package/dist/client/connect/payoutSyncTestHelpers.d.ts +261 -1
  10. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  11. package/dist/client/connect/refundCommandEvidence.d.ts +14 -0
  12. package/dist/client/connect/refundCommandEvidence.d.ts.map +1 -0
  13. package/dist/client/connect/refundCommandEvidence.js +20 -0
  14. package/dist/client/connect/refundCommandEvidence.js.map +1 -0
  15. package/dist/client/connect/refundCommandNormalization.d.ts +11 -0
  16. package/dist/client/connect/refundCommandNormalization.d.ts.map +1 -0
  17. package/dist/client/connect/refundCommandNormalization.js +12 -0
  18. package/dist/client/connect/refundCommandNormalization.js.map +1 -0
  19. package/dist/client/core/accountClosures.d.ts +15 -0
  20. package/dist/client/core/accountClosures.d.ts.map +1 -0
  21. package/dist/client/core/accountClosures.js +10 -0
  22. package/dist/client/core/accountClosures.js.map +1 -0
  23. package/dist/client/core/accounts.d.ts.map +1 -1
  24. package/dist/client/core/accounts.js +15 -23
  25. package/dist/client/core/accounts.js.map +1 -1
  26. package/dist/client/core/personalAccountMapping.d.ts +8 -0
  27. package/dist/client/core/personalAccountMapping.d.ts.map +1 -0
  28. package/dist/client/core/personalAccountMapping.js +11 -0
  29. package/dist/client/core/personalAccountMapping.js.map +1 -0
  30. package/dist/client/financialObservations.d.ts +42 -0
  31. package/dist/client/financialObservations.d.ts.map +1 -0
  32. package/dist/client/financialObservations.js +58 -0
  33. package/dist/client/financialObservations.js.map +1 -0
  34. package/dist/client/financialOwnership.d.ts +52 -0
  35. package/dist/client/financialOwnership.d.ts.map +1 -0
  36. package/dist/client/financialOwnership.js +72 -0
  37. package/dist/client/financialOwnership.js.map +1 -0
  38. package/dist/client/index.d.ts +57 -4
  39. package/dist/client/index.d.ts.map +1 -1
  40. package/dist/client/index.js +15 -2
  41. package/dist/client/index.js.map +1 -1
  42. package/dist/client/observationPagination.d.ts +10 -0
  43. package/dist/client/observationPagination.d.ts.map +1 -0
  44. package/dist/client/observationPagination.js +12 -0
  45. package/dist/client/observationPagination.js.map +1 -0
  46. package/dist/client/publicTypes.d.ts +10 -0
  47. package/dist/client/publicTypes.d.ts.map +1 -0
  48. package/dist/client/publicTypes.js +2 -0
  49. package/dist/client/publicTypes.js.map +1 -0
  50. package/dist/client/readContracts.d.ts +29 -0
  51. package/dist/client/readContracts.d.ts.map +1 -1
  52. package/dist/client/readContracts.js +10 -0
  53. package/dist/client/readContracts.js.map +1 -1
  54. package/dist/client/transferObservations.d.ts +59 -0
  55. package/dist/client/transferObservations.d.ts.map +1 -0
  56. package/dist/client/transferObservations.js +82 -0
  57. package/dist/client/transferObservations.js.map +1 -0
  58. package/dist/component/_generated/component.d.ts +594 -0
  59. package/dist/component/_generated/component.d.ts.map +1 -1
  60. package/dist/component/accountClosure/helpers.d.ts +18 -0
  61. package/dist/component/accountClosure/helpers.d.ts.map +1 -0
  62. package/dist/component/accountClosure/helpers.js +18 -0
  63. package/dist/component/accountClosure/helpers.js.map +1 -0
  64. package/dist/component/accountClosure/mutations.d.ts +20 -0
  65. package/dist/component/accountClosure/mutations.d.ts.map +1 -0
  66. package/dist/component/accountClosure/mutations.js +55 -0
  67. package/dist/component/accountClosure/mutations.js.map +1 -0
  68. package/dist/component/accountClosure/queries.d.ts +34 -0
  69. package/dist/component/accountClosure/queries.d.ts.map +1 -0
  70. package/dist/component/accountClosure/queries.js +36 -0
  71. package/dist/component/accountClosure/queries.js.map +1 -0
  72. package/dist/component/accountClosure/schema.d.ts +46 -0
  73. package/dist/component/accountClosure/schema.d.ts.map +1 -0
  74. package/dist/component/accountClosure/schema.js +20 -0
  75. package/dist/component/accountClosure/schema.js.map +1 -0
  76. package/dist/component/affiliateRecovery/mutations.d.ts.map +1 -1
  77. package/dist/component/affiliateRecovery/mutations.js +4 -1
  78. package/dist/component/affiliateRecovery/mutations.js.map +1 -1
  79. package/dist/component/connect/mutations.d.ts.map +1 -1
  80. package/dist/component/connect/mutations.js +18 -2
  81. package/dist/component/connect/mutations.js.map +1 -1
  82. package/dist/component/connect/queries.d.ts +8 -0
  83. package/dist/component/connect/queries.d.ts.map +1 -1
  84. package/dist/component/connect/reversalClaims.d.ts.map +1 -1
  85. package/dist/component/connect/reversalClaims.js +7 -1
  86. package/dist/component/connect/reversalClaims.js.map +1 -1
  87. package/dist/component/connect/reversalReceipts.d.ts.map +1 -1
  88. package/dist/component/connect/reversalReceipts.js +2 -0
  89. package/dist/component/connect/reversalReceipts.js.map +1 -1
  90. package/dist/component/connect/schema.d.ts +11 -1
  91. package/dist/component/connect/schema.d.ts.map +1 -1
  92. package/dist/component/connect/schema.js +9 -1
  93. package/dist/component/connect/schema.js.map +1 -1
  94. package/dist/component/connect/validators.d.ts +9 -1
  95. package/dist/component/connect/validators.d.ts.map +1 -1
  96. package/dist/component/connect/validators.js +2 -0
  97. package/dist/component/connect/validators.js.map +1 -1
  98. package/dist/component/core/mutations.d.ts.map +1 -1
  99. package/dist/component/core/mutations.js +5 -0
  100. package/dist/component/core/mutations.js.map +1 -1
  101. package/dist/component/core/personalAccountMapping.d.ts +95 -0
  102. package/dist/component/core/personalAccountMapping.d.ts.map +1 -0
  103. package/dist/component/core/personalAccountMapping.js +54 -0
  104. package/dist/component/core/personalAccountMapping.js.map +1 -0
  105. package/dist/component/core/queries.d.ts +27 -0
  106. package/dist/component/core/queries.d.ts.map +1 -1
  107. package/dist/component/core/queries.js +7 -0
  108. package/dist/component/core/queries.js.map +1 -1
  109. package/dist/component/earnings/triggers.d.ts +468 -2
  110. package/dist/component/earnings/triggers.d.ts.map +1 -1
  111. package/dist/component/earnings/triggers.js +7 -1
  112. package/dist/component/earnings/triggers.js.map +1 -1
  113. package/dist/component/financialObservations/continuation.d.ts +7 -0
  114. package/dist/component/financialObservations/continuation.d.ts.map +1 -0
  115. package/dist/component/financialObservations/continuation.js +131 -0
  116. package/dist/component/financialObservations/continuation.js.map +1 -0
  117. package/dist/component/financialObservations/generations.d.ts +6 -0
  118. package/dist/component/financialObservations/generations.d.ts.map +1 -0
  119. package/dist/component/financialObservations/generations.js +46 -0
  120. package/dist/component/financialObservations/generations.js.map +1 -0
  121. package/dist/component/financialObservations/mutations.d.ts +62 -0
  122. package/dist/component/financialObservations/mutations.d.ts.map +1 -0
  123. package/dist/component/financialObservations/mutations.js +69 -0
  124. package/dist/component/financialObservations/mutations.js.map +1 -0
  125. package/dist/component/financialObservations/queries.d.ts +307 -0
  126. package/dist/component/financialObservations/queries.d.ts.map +1 -0
  127. package/dist/component/financialObservations/queries.js +219 -0
  128. package/dist/component/financialObservations/queries.js.map +1 -0
  129. package/dist/component/financialObservations/schema.d.ts +182 -0
  130. package/dist/component/financialObservations/schema.d.ts.map +1 -0
  131. package/dist/component/financialObservations/schema.js +53 -0
  132. package/dist/component/financialObservations/schema.js.map +1 -0
  133. package/dist/component/financialObservations/settlement.d.ts +7 -0
  134. package/dist/component/financialObservations/settlement.d.ts.map +1 -0
  135. package/dist/component/financialObservations/settlement.js +118 -0
  136. package/dist/component/financialObservations/settlement.js.map +1 -0
  137. package/dist/component/financialObservations/settlementHelpers.d.ts +46 -0
  138. package/dist/component/financialObservations/settlementHelpers.d.ts.map +1 -0
  139. package/dist/component/financialObservations/settlementHelpers.js +70 -0
  140. package/dist/component/financialObservations/settlementHelpers.js.map +1 -0
  141. package/dist/component/financialObservations/transferBatches.d.ts +12 -0
  142. package/dist/component/financialObservations/transferBatches.d.ts.map +1 -0
  143. package/dist/component/financialObservations/transferBatches.js +76 -0
  144. package/dist/component/financialObservations/transferBatches.js.map +1 -0
  145. package/dist/component/financialObservations/transferContinuation.d.ts +5 -0
  146. package/dist/component/financialObservations/transferContinuation.d.ts.map +1 -0
  147. package/dist/component/financialObservations/transferContinuation.js +35 -0
  148. package/dist/component/financialObservations/transferContinuation.js.map +1 -0
  149. package/dist/component/financialObservations/transferContinuationState.d.ts +8 -0
  150. package/dist/component/financialObservations/transferContinuationState.d.ts.map +1 -0
  151. package/dist/component/financialObservations/transferContinuationState.js +69 -0
  152. package/dist/component/financialObservations/transferContinuationState.js.map +1 -0
  153. package/dist/component/financialObservations/transferContinuationSteps.d.ts +5 -0
  154. package/dist/component/financialObservations/transferContinuationSteps.d.ts.map +1 -0
  155. package/dist/component/financialObservations/transferContinuationSteps.js +174 -0
  156. package/dist/component/financialObservations/transferContinuationSteps.js.map +1 -0
  157. package/dist/component/financialObservations/transferHelpers.d.ts +18 -0
  158. package/dist/component/financialObservations/transferHelpers.d.ts.map +1 -0
  159. package/dist/component/financialObservations/transferHelpers.js +37 -0
  160. package/dist/component/financialObservations/transferHelpers.js.map +1 -0
  161. package/dist/component/financialObservations/transferReferenceSchema.d.ts +56 -0
  162. package/dist/component/financialObservations/transferReferenceSchema.d.ts.map +1 -0
  163. package/dist/component/financialObservations/transferReferenceSchema.js +21 -0
  164. package/dist/component/financialObservations/transferReferenceSchema.js.map +1 -0
  165. package/dist/component/financialObservations/transferSchema.d.ts +237 -0
  166. package/dist/component/financialObservations/transferSchema.d.ts.map +1 -0
  167. package/dist/component/financialObservations/transferSchema.js +65 -0
  168. package/dist/component/financialObservations/transferSchema.js.map +1 -0
  169. package/dist/component/financialObservations/transfers.d.ts +7 -0
  170. package/dist/component/financialObservations/transfers.d.ts.map +1 -0
  171. package/dist/component/financialObservations/transfers.js +79 -0
  172. package/dist/component/financialObservations/transfers.js.map +1 -0
  173. package/dist/component/financialOwnership/helpers.d.ts +37 -0
  174. package/dist/component/financialOwnership/helpers.d.ts.map +1 -0
  175. package/dist/component/financialOwnership/helpers.js +76 -0
  176. package/dist/component/financialOwnership/helpers.js.map +1 -0
  177. package/dist/component/financialOwnership/mutations.d.ts +28 -0
  178. package/dist/component/financialOwnership/mutations.d.ts.map +1 -0
  179. package/dist/component/financialOwnership/mutations.js +74 -0
  180. package/dist/component/financialOwnership/mutations.js.map +1 -0
  181. package/dist/component/financialOwnership/queries.d.ts +57 -0
  182. package/dist/component/financialOwnership/queries.d.ts.map +1 -0
  183. package/dist/component/financialOwnership/queries.js +50 -0
  184. package/dist/component/financialOwnership/queries.js.map +1 -0
  185. package/dist/component/financialOwnership/schema.d.ts +140 -0
  186. package/dist/component/financialOwnership/schema.d.ts.map +1 -0
  187. package/dist/component/financialOwnership/schema.js +35 -0
  188. package/dist/component/financialOwnership/schema.js.map +1 -0
  189. package/dist/component/payoutRelease/queries.d.ts +2 -2
  190. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  191. package/dist/component/refundHistory/commandBinding.d.ts +17 -0
  192. package/dist/component/refundHistory/commandBinding.d.ts.map +1 -0
  193. package/dist/component/refundHistory/commandBinding.js +41 -0
  194. package/dist/component/refundHistory/commandBinding.js.map +1 -0
  195. package/dist/component/refundHistory/commandEvidence.d.ts +50 -0
  196. package/dist/component/refundHistory/commandEvidence.d.ts.map +1 -0
  197. package/dist/component/refundHistory/commandEvidence.js +54 -0
  198. package/dist/component/refundHistory/commandEvidence.js.map +1 -0
  199. package/dist/component/refundHistory/commandEvidenceValidator.d.ts +89 -0
  200. package/dist/component/refundHistory/commandEvidenceValidator.d.ts.map +1 -0
  201. package/dist/component/refundHistory/commandEvidenceValidator.js +8 -0
  202. package/dist/component/refundHistory/commandEvidenceValidator.js.map +1 -0
  203. package/dist/component/refundHistory/commandFields.d.ts +8 -0
  204. package/dist/component/refundHistory/commandFields.d.ts.map +1 -0
  205. package/dist/component/refundHistory/commandFields.js +9 -0
  206. package/dist/component/refundHistory/commandFields.js.map +1 -0
  207. package/dist/component/refundHistory/mutations.d.ts +8 -0
  208. package/dist/component/refundHistory/mutations.d.ts.map +1 -0
  209. package/dist/component/refundHistory/mutations.js +25 -0
  210. package/dist/component/refundHistory/mutations.js.map +1 -0
  211. package/dist/component/refundHistory/queries.d.ts +51 -0
  212. package/dist/component/refundHistory/queries.d.ts.map +1 -1
  213. package/dist/component/refundHistory/queries.js +14 -0
  214. package/dist/component/refundHistory/queries.js.map +1 -1
  215. package/dist/component/schema.d.ts +261 -1
  216. package/dist/component/schema.js +14 -0
  217. package/dist/component/schema.js.map +1 -1
  218. package/dist/component/settlement/mutations.d.ts.map +1 -1
  219. package/dist/component/settlement/mutations.js +5 -1
  220. package/dist/component/settlement/mutations.js.map +1 -1
  221. package/dist/shared/refundCommandScope.d.ts +10 -0
  222. package/dist/shared/refundCommandScope.d.ts.map +1 -0
  223. package/dist/shared/refundCommandScope.js +9 -0
  224. package/dist/shared/refundCommandScope.js.map +1 -0
  225. package/docs/financial-observations.md +159 -0
  226. package/docs/financial-ownership.md +54 -0
  227. package/docs/personal-account-mapping.md +54 -0
  228. package/docs/refund-command-evidence.md +49 -0
  229. package/package.json +6 -2
  230. package/src/client/connect/refundCommandEvidence.ts +41 -0
  231. package/src/client/connect/refundCommandNormalization.ts +28 -0
  232. package/src/client/core/account-close-orchestration.test.ts +131 -0
  233. package/src/client/core/account-closure.test.ts +317 -0
  234. package/src/client/core/accountClosures.ts +37 -0
  235. package/src/client/core/accounts.test.ts +0 -111
  236. package/src/client/core/accounts.ts +24 -29
  237. package/src/client/core/personal-account-mapping.test.ts +71 -0
  238. package/src/client/core/personalAccountMapping.ts +23 -0
  239. package/src/client/financialObservations.test.ts +109 -0
  240. package/src/client/financialObservations.ts +106 -0
  241. package/src/client/financialOwnership.test.ts +80 -0
  242. package/src/client/financialOwnership.ts +116 -0
  243. package/src/client/index.ts +38 -35
  244. package/src/client/observationPagination.ts +11 -0
  245. package/src/client/publicTypes.ts +72 -0
  246. package/src/client/readContracts.ts +21 -0
  247. package/src/client/refund-command-evidence.test.ts +68 -0
  248. package/src/client/refund-command-normalization.test.ts +61 -0
  249. package/src/client/transferContinuation.test.ts +94 -0
  250. package/src/client/transferObservations.test.ts +98 -0
  251. package/src/client/transferObservations.ts +180 -0
  252. package/src/component/_generated/api.ts +52 -0
  253. package/src/component/_generated/component.ts +716 -0
  254. package/src/component/accountClosure/helpers.ts +21 -0
  255. package/src/component/accountClosure/mutations.ts +56 -0
  256. package/src/component/accountClosure/queries.ts +43 -0
  257. package/src/component/accountClosure/schema.ts +20 -0
  258. package/src/component/affiliateRecovery/mutations.ts +10 -1
  259. package/src/component/connect/mutations.ts +29 -2
  260. package/src/component/connect/reversalClaims.ts +19 -1
  261. package/src/component/connect/reversalReceipts.ts +2 -0
  262. package/src/component/connect/schema.ts +9 -1
  263. package/src/component/connect/validators.ts +2 -0
  264. package/src/component/core/mutations.ts +3 -0
  265. package/src/component/core/personal-account-mapping.test.ts +173 -0
  266. package/src/component/core/personalAccountMapping.ts +81 -0
  267. package/src/component/core/queries.ts +11 -0
  268. package/src/component/core/reset.test.ts +8 -1
  269. package/src/component/earnings/earnings-totals.test.ts +14 -10
  270. package/src/component/earnings/triggers.ts +9 -1
  271. package/src/component/financialObservations/continuation.test.ts +445 -0
  272. package/src/component/financialObservations/continuation.ts +159 -0
  273. package/src/component/financialObservations/generations.ts +53 -0
  274. package/src/component/financialObservations/mutations.ts +75 -0
  275. package/src/component/financialObservations/observation-boundaries.test.ts +466 -0
  276. package/src/component/financialObservations/queries.ts +246 -0
  277. package/src/component/financialObservations/schema.ts +68 -0
  278. package/src/component/financialObservations/settlement-observations.test.ts +86 -0
  279. package/src/component/financialObservations/settlement.ts +142 -0
  280. package/src/component/financialObservations/settlementHelpers.ts +92 -0
  281. package/src/component/financialObservations/transfer-batches.test.ts +61 -0
  282. package/src/component/financialObservations/transfer-boundaries.test.ts +116 -0
  283. package/src/component/financialObservations/transfer-continuation-guards.test.ts +428 -0
  284. package/src/component/financialObservations/transfer-continuation.test.ts +154 -0
  285. package/src/component/financialObservations/transfer-observations.test.ts +212 -0
  286. package/src/component/financialObservations/transfer-overflow.test.ts +181 -0
  287. package/src/component/financialObservations/transfer-writers.test.ts +162 -0
  288. package/src/component/financialObservations/transferBatches.ts +96 -0
  289. package/src/component/financialObservations/transferContinuation.ts +53 -0
  290. package/src/component/financialObservations/transferContinuationState.ts +85 -0
  291. package/src/component/financialObservations/transferContinuationSteps.ts +232 -0
  292. package/src/component/financialObservations/transferHelpers.ts +38 -0
  293. package/src/component/financialObservations/transferReferenceSchema.ts +20 -0
  294. package/src/component/financialObservations/transferSchema.ts +74 -0
  295. package/src/component/financialObservations/transfers.ts +99 -0
  296. package/src/component/financialOwnership/financial-ownership.test.ts +102 -0
  297. package/src/component/financialOwnership/helpers.ts +98 -0
  298. package/src/component/financialOwnership/mutations.ts +83 -0
  299. package/src/component/financialOwnership/ownership-boundaries.test.ts +308 -0
  300. package/src/component/financialOwnership/queries.ts +65 -0
  301. package/src/component/financialOwnership/schema.ts +35 -0
  302. package/src/component/refundHistory/command-evidence.test.ts +288 -0
  303. package/src/component/refundHistory/command-normalization-resource.test.ts +77 -0
  304. package/src/component/refundHistory/command-normalization.test.ts +229 -0
  305. package/src/component/refundHistory/command-provenance.test.ts +59 -0
  306. package/src/component/refundHistory/commandBinding.ts +54 -0
  307. package/src/component/refundHistory/commandEvidence.ts +71 -0
  308. package/src/component/refundHistory/commandEvidenceValidator.ts +18 -0
  309. package/src/component/refundHistory/commandFields.ts +9 -0
  310. package/src/component/refundHistory/mutations.ts +33 -0
  311. package/src/component/refundHistory/queries.ts +15 -0
  312. package/src/component/schema.ts +24 -0
  313. package/src/component/settlement/mutations.ts +5 -1
  314. package/src/shared/refundCommandScope.ts +19 -0
@@ -0,0 +1,219 @@
1
+ import { transferReferenceDoc } from "./transferReferenceSchema.js";
2
+ import { transferReaderState } from "./transferBatches.js";
3
+ import { transferObservationDoc, transferBatchDoc } from "./transferSchema.js";
4
+ import { paginationOptsValidator, paginationResultValidator, } from "convex/server";
5
+ import { paginator } from "convex-helpers/server/pagination";
6
+ import { v } from "convex/values";
7
+ import { query } from "../_generated/server.js";
8
+ import { assertOwner, assertSelector } from "../financialOwnership/helpers.js";
9
+ import { ownerFields } from "../financialOwnership/schema.js";
10
+ import schema from "../schema.js";
11
+ import { bucketScope, observationGeneration, ownerScope, } from "./generations.js";
12
+ import { legDoc, sourceDoc } from "./schema.js";
13
+ const transferReadFields = {
14
+ coverage: v.literal("unknown"),
15
+ producerGeneration: v.union(v.number(), v.null()),
16
+ hasDeferredWork: v.boolean(),
17
+ };
18
+ export const source = query({
19
+ args: { allocationId: v.id("settlementAllocations") },
20
+ returns: v.object({
21
+ coverage: v.literal("unknown"),
22
+ observation: v.union(v.null(), sourceDoc),
23
+ }),
24
+ handler: async (ctx, args) => {
25
+ const rows = await ctx.db
26
+ .query("financialSourceObservations")
27
+ .withIndex("by_allocation_id", (q) => q.eq("allocationId", args.allocationId))
28
+ .take(2);
29
+ return {
30
+ coverage: "unknown",
31
+ observation: rows.length === 1 &&
32
+ Number.isSafeInteger(rows[0].generation) &&
33
+ rows[0].generation >= 1
34
+ ? rows[0]
35
+ : null,
36
+ };
37
+ },
38
+ });
39
+ const result = v.object({
40
+ ...paginationResultValidator(legDoc).fields,
41
+ coverage: v.literal("unknown"),
42
+ generation: v.union(v.number(), v.null()),
43
+ });
44
+ function assertPageSize(numItems) {
45
+ if (!Number.isInteger(numItems) || numItems < 1 || numItems > 100)
46
+ throw new Error("Observation page size must be between 1 and 100");
47
+ }
48
+ /** Trusted host boundary; exact keys do not authorize end-user access. */
49
+ export const bucket = query({
50
+ args: { bucketKey: v.string(), paginationOpts: paginationOptsValidator },
51
+ returns: result,
52
+ handler: async (ctx, args) => {
53
+ assertSelector(args.bucketKey);
54
+ assertPageSize(args.paginationOpts.numItems);
55
+ const page = await paginator(ctx.db, schema)
56
+ .query("financialSourceLegs")
57
+ .withIndex("by_bucket_key", (q) => q.eq("bucketKey", args.bucketKey))
58
+ .order("desc")
59
+ .paginate({
60
+ ...args.paginationOpts,
61
+ maximumRowsRead: 200,
62
+ maximumBytesRead: 1_000_000,
63
+ });
64
+ return {
65
+ ...page,
66
+ coverage: "unknown",
67
+ generation: await observationGeneration(ctx, bucketScope(args.bucketKey)),
68
+ };
69
+ },
70
+ });
71
+ export const owner = query({
72
+ args: { ...ownerFields, paginationOpts: paginationOptsValidator },
73
+ returns: result,
74
+ handler: async (ctx, args) => {
75
+ assertOwner(args);
76
+ assertPageSize(args.paginationOpts.numItems);
77
+ const page = await paginator(ctx.db, schema)
78
+ .query("financialSourceLegs")
79
+ .withIndex("by_owner", (q) => q.eq("userId", args.userId).eq("orgId", args.orgId))
80
+ .order("desc")
81
+ .paginate({
82
+ ...args.paginationOpts,
83
+ maximumRowsRead: 200,
84
+ maximumBytesRead: 1_000_000,
85
+ });
86
+ return {
87
+ ...page,
88
+ coverage: "unknown",
89
+ generation: await observationGeneration(ctx, ownerScope(args.userId, args.orgId)),
90
+ };
91
+ },
92
+ });
93
+ export const transfer = query({
94
+ args: { transferId: v.id("transfers") },
95
+ returns: v.object({
96
+ ...transferReadFields,
97
+ observation: v.union(transferObservationDoc, v.null()),
98
+ }),
99
+ handler: async (ctx, args) => {
100
+ const rows = await ctx.db
101
+ .query("financialTransferObservations")
102
+ .withIndex("by_transfer_id", (q) => q.eq("transferId", args.transferId))
103
+ .take(2);
104
+ const row = rows.length === 1 ? rows[0] : null;
105
+ return {
106
+ ...(await transferReaderState(ctx)),
107
+ observation: row && Number.isSafeInteger(row.generation) && row.generation >= 1
108
+ ? row
109
+ : null,
110
+ };
111
+ },
112
+ });
113
+ export const transferBatches = query({
114
+ args: { operationId: v.string(), paginationOpts: paginationOptsValidator },
115
+ returns: v.object({
116
+ ...paginationResultValidator(transferBatchDoc).fields,
117
+ coverage: v.literal("unknown"),
118
+ hasDeferredWork: v.boolean(),
119
+ producerGeneration: v.union(v.number(), v.null()),
120
+ }),
121
+ handler: async (ctx, args) => {
122
+ assertSelector(args.operationId);
123
+ assertPageSize(args.paginationOpts.numItems);
124
+ const page = await paginator(ctx.db, schema)
125
+ .query("financialTransferBatches")
126
+ .withIndex("by_operation_id", (q) => q.eq("operationId", args.operationId))
127
+ .order("desc")
128
+ .paginate({
129
+ ...args.paginationOpts,
130
+ maximumRowsRead: 200,
131
+ maximumBytesRead: 1_000_000,
132
+ });
133
+ return { ...page, ...(await transferReaderState(ctx)) };
134
+ },
135
+ });
136
+ const transferPageResult = v.object({
137
+ ...paginationResultValidator(transferObservationDoc).fields,
138
+ ...transferReadFields,
139
+ generation: v.union(v.number(), v.null()),
140
+ });
141
+ export const transferBucket = query({
142
+ args: { bucketKey: v.string(), paginationOpts: paginationOptsValidator },
143
+ returns: transferPageResult,
144
+ handler: async (ctx, args) => {
145
+ assertSelector(args.bucketKey);
146
+ assertPageSize(args.paginationOpts.numItems);
147
+ const page = await paginator(ctx.db, schema)
148
+ .query("financialTransferObservations")
149
+ .withIndex("by_bucket_key", (q) => q.eq("bucketKey", args.bucketKey))
150
+ .order("desc")
151
+ .paginate({
152
+ ...args.paginationOpts,
153
+ maximumRowsRead: 200,
154
+ maximumBytesRead: 1_000_000,
155
+ });
156
+ return {
157
+ ...page,
158
+ ...(await transferReaderState(ctx)),
159
+ generation: await observationGeneration(ctx, bucketScope(args.bucketKey)),
160
+ };
161
+ },
162
+ });
163
+ export const transferOwner = query({
164
+ args: { ...ownerFields, paginationOpts: paginationOptsValidator },
165
+ returns: transferPageResult,
166
+ handler: async (ctx, args) => {
167
+ assertOwner(args);
168
+ assertPageSize(args.paginationOpts.numItems);
169
+ const page = await paginator(ctx.db, schema)
170
+ .query("financialTransferObservations")
171
+ .withIndex("by_owner", (q) => q.eq("userId", args.userId).eq("orgId", args.orgId))
172
+ .order("desc")
173
+ .paginate({
174
+ ...args.paginationOpts,
175
+ maximumRowsRead: 200,
176
+ maximumBytesRead: 1_000_000,
177
+ });
178
+ return {
179
+ ...page,
180
+ ...(await transferReaderState(ctx)),
181
+ generation: await observationGeneration(ctx, ownerScope(args.userId, args.orgId)),
182
+ };
183
+ },
184
+ });
185
+ export const transferReferences = query({
186
+ args: {
187
+ batchId: v.id("financialTransferBatches"),
188
+ paginationOpts: paginationOptsValidator,
189
+ },
190
+ returns: v.object({
191
+ ...paginationResultValidator(transferReferenceDoc).fields,
192
+ ...transferReadFields,
193
+ }),
194
+ handler: async (ctx, args) => {
195
+ assertPageSize(args.paginationOpts.numItems);
196
+ const page = await paginator(ctx.db, schema)
197
+ .query("financialTransferBatchReferences")
198
+ .withIndex("by_batch_position", (q) => q.eq("batchId", args.batchId))
199
+ .order("asc")
200
+ .paginate({
201
+ ...args.paginationOpts,
202
+ maximumRowsRead: 200,
203
+ maximumBytesRead: 1_000_000,
204
+ });
205
+ return { ...page, ...(await transferReaderState(ctx)) };
206
+ },
207
+ });
208
+ export const transferBatch = query({
209
+ args: { batchId: v.id("financialTransferBatches") },
210
+ returns: v.object({
211
+ ...transferReadFields,
212
+ batch: v.union(transferBatchDoc, v.null()),
213
+ }),
214
+ handler: async (ctx, args) => ({
215
+ ...(await transferReaderState(ctx)),
216
+ batch: await ctx.db.get("financialTransferBatches", args.batchId),
217
+ }),
218
+ });
219
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/financialObservations/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,kCA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QAAQ,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC;aACzC,KAAK,CAAC,kCAAkC,CAAC;aACzC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;aACpE,KAAK,CAAC,KAAK,CAAC;aACZ,QAAQ,CAAC;YACR,GAAG,IAAI,CAAC,cAAc;YACtB,eAAe,EAAE,GAAG;YACpB,gBAAgB,EAAE,SAAS;SAC5B,CAAC,CAAC;QACL,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,MAAM,mBAAmB,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAC1D,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;IACjC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,0BAA0B,CAAC,EAAE;IACnD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,GAAG,kBAAkB;QACrB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;KAC3C,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC7B,GAAG,CAAC,MAAM,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACnC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,OAAO,CAAC;KAClE,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,182 @@
1
+ export declare const sourceFields: {
2
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
3
+ sourceChargeId: import("convex/values").VString<string, "required">;
4
+ producer: import("convex/values").VLiteral<"settlement_allocation", "required">;
5
+ producerVersion: import("convex/values").VLiteral<1, "required">;
6
+ fingerprint: import("convex/values").VString<string, "required">;
7
+ observedFingerprint: import("convex/values").VString<string, "required">;
8
+ ownershipFingerprint: import("convex/values").VString<string, "required">;
9
+ generation: import("convex/values").VFloat64<number, "required">;
10
+ legCount: import("convex/values").VFloat64<number, "required">;
11
+ indexedLegCount: import("convex/values").VFloat64<number, "required">;
12
+ isOverflow: import("convex/values").VBoolean<boolean, "required">;
13
+ isContradictory: import("convex/values").VBoolean<boolean, "required">;
14
+ continuation: import("convex/values").VObject<{
15
+ nextLeg: number;
16
+ state: "complete" | "held" | "indexing" | "validating";
17
+ validatedLegs: number;
18
+ } | undefined, {
19
+ state: import("convex/values").VUnion<"complete" | "held" | "indexing" | "validating", [import("convex/values").VLiteral<"indexing", "required">, import("convex/values").VLiteral<"validating", "required">, import("convex/values").VLiteral<"complete", "required">, import("convex/values").VLiteral<"held", "required">], "required", never>;
20
+ nextLeg: import("convex/values").VFloat64<number, "required">;
21
+ validatedLegs: import("convex/values").VFloat64<number, "required">;
22
+ }, "optional", "nextLeg" | "state" | "validatedLegs">;
23
+ };
24
+ export declare const sourceDoc: import("convex/values").VObject<{
25
+ _creationTime: number;
26
+ _id: import("convex/values").GenericId<"financialSourceObservations">;
27
+ allocationId: import("convex/values").GenericId<"settlementAllocations">;
28
+ continuation?: {
29
+ nextLeg: number;
30
+ state: "complete" | "held" | "indexing" | "validating";
31
+ validatedLegs: number;
32
+ } | undefined;
33
+ fingerprint: string;
34
+ generation: number;
35
+ indexedLegCount: number;
36
+ isContradictory: boolean;
37
+ isOverflow: boolean;
38
+ legCount: number;
39
+ observedFingerprint: string;
40
+ ownershipFingerprint: string;
41
+ producer: "settlement_allocation";
42
+ producerVersion: 1;
43
+ sourceChargeId: string;
44
+ }, {
45
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
46
+ sourceChargeId: import("convex/values").VString<string, "required">;
47
+ producer: import("convex/values").VLiteral<"settlement_allocation", "required">;
48
+ producerVersion: import("convex/values").VLiteral<1, "required">;
49
+ fingerprint: import("convex/values").VString<string, "required">;
50
+ observedFingerprint: import("convex/values").VString<string, "required">;
51
+ ownershipFingerprint: import("convex/values").VString<string, "required">;
52
+ generation: import("convex/values").VFloat64<number, "required">;
53
+ legCount: import("convex/values").VFloat64<number, "required">;
54
+ indexedLegCount: import("convex/values").VFloat64<number, "required">;
55
+ isOverflow: import("convex/values").VBoolean<boolean, "required">;
56
+ isContradictory: import("convex/values").VBoolean<boolean, "required">;
57
+ continuation: import("convex/values").VObject<{
58
+ nextLeg: number;
59
+ state: "complete" | "held" | "indexing" | "validating";
60
+ validatedLegs: number;
61
+ } | undefined, {
62
+ state: import("convex/values").VUnion<"complete" | "held" | "indexing" | "validating", [import("convex/values").VLiteral<"indexing", "required">, import("convex/values").VLiteral<"validating", "required">, import("convex/values").VLiteral<"complete", "required">, import("convex/values").VLiteral<"held", "required">], "required", never>;
63
+ nextLeg: import("convex/values").VFloat64<number, "required">;
64
+ validatedLegs: import("convex/values").VFloat64<number, "required">;
65
+ }, "optional", "nextLeg" | "state" | "validatedLegs">;
66
+ _id: import("convex/values").VId<import("convex/values").GenericId<"financialSourceObservations">, "required">;
67
+ _creationTime: import("convex/values").VFloat64<number, "required">;
68
+ }, "required", "_creationTime" | "_id" | "allocationId" | "continuation" | "continuation.nextLeg" | "continuation.state" | "continuation.validatedLegs" | "fingerprint" | "generation" | "indexedLegCount" | "isContradictory" | "isOverflow" | "legCount" | "observedFingerprint" | "ownershipFingerprint" | "producer" | "producerVersion" | "sourceChargeId">;
69
+ export declare const sourceObservationsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
70
+ allocationId: import("convex/values").GenericId<"settlementAllocations">;
71
+ continuation?: {
72
+ nextLeg: number;
73
+ state: "complete" | "held" | "indexing" | "validating";
74
+ validatedLegs: number;
75
+ } | undefined;
76
+ fingerprint: string;
77
+ generation: number;
78
+ indexedLegCount: number;
79
+ isContradictory: boolean;
80
+ isOverflow: boolean;
81
+ legCount: number;
82
+ observedFingerprint: string;
83
+ ownershipFingerprint: string;
84
+ producer: "settlement_allocation";
85
+ producerVersion: 1;
86
+ sourceChargeId: string;
87
+ }, {
88
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
89
+ sourceChargeId: import("convex/values").VString<string, "required">;
90
+ producer: import("convex/values").VLiteral<"settlement_allocation", "required">;
91
+ producerVersion: import("convex/values").VLiteral<1, "required">;
92
+ fingerprint: import("convex/values").VString<string, "required">;
93
+ observedFingerprint: import("convex/values").VString<string, "required">;
94
+ ownershipFingerprint: import("convex/values").VString<string, "required">;
95
+ generation: import("convex/values").VFloat64<number, "required">;
96
+ legCount: import("convex/values").VFloat64<number, "required">;
97
+ indexedLegCount: import("convex/values").VFloat64<number, "required">;
98
+ isOverflow: import("convex/values").VBoolean<boolean, "required">;
99
+ isContradictory: import("convex/values").VBoolean<boolean, "required">;
100
+ continuation: import("convex/values").VObject<{
101
+ nextLeg: number;
102
+ state: "complete" | "held" | "indexing" | "validating";
103
+ validatedLegs: number;
104
+ } | undefined, {
105
+ state: import("convex/values").VUnion<"complete" | "held" | "indexing" | "validating", [import("convex/values").VLiteral<"indexing", "required">, import("convex/values").VLiteral<"validating", "required">, import("convex/values").VLiteral<"complete", "required">, import("convex/values").VLiteral<"held", "required">], "required", never>;
106
+ nextLeg: import("convex/values").VFloat64<number, "required">;
107
+ validatedLegs: import("convex/values").VFloat64<number, "required">;
108
+ }, "optional", "nextLeg" | "state" | "validatedLegs">;
109
+ }, "required", "allocationId" | "continuation" | "continuation.nextLeg" | "continuation.state" | "continuation.validatedLegs" | "fingerprint" | "generation" | "indexedLegCount" | "isContradictory" | "isOverflow" | "legCount" | "observedFingerprint" | "ownershipFingerprint" | "producer" | "producerVersion" | "sourceChargeId">, {
110
+ by_allocation_id: ["allocationId", "_creationTime"];
111
+ }, {}, {}>;
112
+ export declare const legFields: {
113
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
114
+ sourceChargeId: import("convex/values").VString<string, "required">;
115
+ legIndex: import("convex/values").VFloat64<number, "required">;
116
+ bucketKey: import("convex/values").VString<string, "required">;
117
+ role: import("convex/values").VUnion<"affiliate" | "other" | "store", [import("convex/values").VLiteral<"store", "required">, import("convex/values").VLiteral<"affiliate", "required">, import("convex/values").VLiteral<"other", "required">], "required", never>;
118
+ registrationId: import("convex/values").VId<import("convex/values").GenericId<"financialOwnership"> | undefined, "optional">;
119
+ userId: import("convex/values").VString<string | undefined, "optional">;
120
+ orgId: import("convex/values").VString<string | undefined, "optional">;
121
+ ownershipStatus: import("convex/values").VUnion<"ambiguous" | "contradictory" | "registered" | "unknown", [import("convex/values").VLiteral<"registered", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"ambiguous", "required">, import("convex/values").VLiteral<"contradictory", "required">], "required", never>;
122
+ };
123
+ export declare const legDoc: import("convex/values").VObject<{
124
+ _creationTime: number;
125
+ _id: import("convex/values").GenericId<"financialSourceLegs">;
126
+ allocationId: import("convex/values").GenericId<"settlementAllocations">;
127
+ bucketKey: string;
128
+ legIndex: number;
129
+ orgId?: string | undefined;
130
+ ownershipStatus: "ambiguous" | "contradictory" | "registered" | "unknown";
131
+ registrationId?: import("convex/values").GenericId<"financialOwnership"> | undefined;
132
+ role: "affiliate" | "other" | "store";
133
+ sourceChargeId: string;
134
+ userId?: string | undefined;
135
+ }, {
136
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
137
+ sourceChargeId: import("convex/values").VString<string, "required">;
138
+ legIndex: import("convex/values").VFloat64<number, "required">;
139
+ bucketKey: import("convex/values").VString<string, "required">;
140
+ role: import("convex/values").VUnion<"affiliate" | "other" | "store", [import("convex/values").VLiteral<"store", "required">, import("convex/values").VLiteral<"affiliate", "required">, import("convex/values").VLiteral<"other", "required">], "required", never>;
141
+ registrationId: import("convex/values").VId<import("convex/values").GenericId<"financialOwnership"> | undefined, "optional">;
142
+ userId: import("convex/values").VString<string | undefined, "optional">;
143
+ orgId: import("convex/values").VString<string | undefined, "optional">;
144
+ ownershipStatus: import("convex/values").VUnion<"ambiguous" | "contradictory" | "registered" | "unknown", [import("convex/values").VLiteral<"registered", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"ambiguous", "required">, import("convex/values").VLiteral<"contradictory", "required">], "required", never>;
145
+ _id: import("convex/values").VId<import("convex/values").GenericId<"financialSourceLegs">, "required">;
146
+ _creationTime: import("convex/values").VFloat64<number, "required">;
147
+ }, "required", "_creationTime" | "_id" | "allocationId" | "bucketKey" | "legIndex" | "orgId" | "ownershipStatus" | "registrationId" | "role" | "sourceChargeId" | "userId">;
148
+ export declare const sourceLegsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
149
+ allocationId: import("convex/values").GenericId<"settlementAllocations">;
150
+ bucketKey: string;
151
+ legIndex: number;
152
+ orgId?: string | undefined;
153
+ ownershipStatus: "ambiguous" | "contradictory" | "registered" | "unknown";
154
+ registrationId?: import("convex/values").GenericId<"financialOwnership"> | undefined;
155
+ role: "affiliate" | "other" | "store";
156
+ sourceChargeId: string;
157
+ userId?: string | undefined;
158
+ }, {
159
+ allocationId: import("convex/values").VId<import("convex/values").GenericId<"settlementAllocations">, "required">;
160
+ sourceChargeId: import("convex/values").VString<string, "required">;
161
+ legIndex: import("convex/values").VFloat64<number, "required">;
162
+ bucketKey: import("convex/values").VString<string, "required">;
163
+ role: import("convex/values").VUnion<"affiliate" | "other" | "store", [import("convex/values").VLiteral<"store", "required">, import("convex/values").VLiteral<"affiliate", "required">, import("convex/values").VLiteral<"other", "required">], "required", never>;
164
+ registrationId: import("convex/values").VId<import("convex/values").GenericId<"financialOwnership"> | undefined, "optional">;
165
+ userId: import("convex/values").VString<string | undefined, "optional">;
166
+ orgId: import("convex/values").VString<string | undefined, "optional">;
167
+ ownershipStatus: import("convex/values").VUnion<"ambiguous" | "contradictory" | "registered" | "unknown", [import("convex/values").VLiteral<"registered", "required">, import("convex/values").VLiteral<"unknown", "required">, import("convex/values").VLiteral<"ambiguous", "required">, import("convex/values").VLiteral<"contradictory", "required">], "required", never>;
168
+ }, "required", "allocationId" | "bucketKey" | "legIndex" | "orgId" | "ownershipStatus" | "registrationId" | "role" | "sourceChargeId" | "userId">, {
169
+ by_allocation_id_and_leg_index: ["allocationId", "legIndex", "_creationTime"];
170
+ by_bucket_key: ["bucketKey", "_creationTime"];
171
+ by_owner: ["userId", "orgId", "_creationTime"];
172
+ }, {}, {}>;
173
+ export declare const observationGenerationsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
174
+ generation: number;
175
+ scopeKey: string;
176
+ }, {
177
+ scopeKey: import("convex/values").VString<string, "required">;
178
+ generation: import("convex/values").VFloat64<number, "required">;
179
+ }, "required", "generation" | "scopeKey">, {
180
+ by_scope_key: ["scopeKey", "_creationTime"];
181
+ }, {}, {}>;
182
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/financialObservations/schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY;IACvB,YAAY;IACZ,cAAc;IACd,QAAQ;IACR,eAAe;IACf,WAAW;IACX,mBAAmB;IACnB,oBAAoB;IACpB,UAAU;IACV,QAAQ;IACR,eAAe;IACf,UAAU;IACV,eAAe;IACf,YAAY;;;;;;;;;CAYb,CAAC;AACF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gWAIpB,CAAC;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAGnC,CAAC;AACF,eAAO,MAAM,SAAS;IACpB,YAAY;IACZ,cAAc;IACd,QAAQ;IACR,SAAS;IACT,IAAI;IACJ,cAAc;IACd,MAAM;IACN,KAAK;IACL,eAAe;CAMhB,CAAC;AACF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;2KAIjB,CAAC;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;UAGa,CAAC;AAC1C,eAAO,MAAM,2BAA2B;;;;;;;;UAGF,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { splitRecipientRoleValidator } from "../lib/fees.js";
4
+ export const sourceFields = {
5
+ allocationId: v.id("settlementAllocations"),
6
+ sourceChargeId: v.string(),
7
+ producer: v.literal("settlement_allocation"),
8
+ producerVersion: v.literal(1),
9
+ fingerprint: v.string(),
10
+ observedFingerprint: v.string(),
11
+ ownershipFingerprint: v.string(),
12
+ generation: v.number(),
13
+ legCount: v.number(),
14
+ indexedLegCount: v.number(),
15
+ isOverflow: v.boolean(),
16
+ isContradictory: v.boolean(),
17
+ continuation: v.optional(v.object({
18
+ state: v.union(v.literal("indexing"), v.literal("validating"), v.literal("complete"), v.literal("held")),
19
+ nextLeg: v.number(),
20
+ validatedLegs: v.number(),
21
+ })),
22
+ };
23
+ export const sourceDoc = v.object({
24
+ ...sourceFields,
25
+ _id: v.id("financialSourceObservations"),
26
+ _creationTime: v.number(),
27
+ });
28
+ export const sourceObservationsTable = defineTable(sourceFields).index("by_allocation_id", ["allocationId"]);
29
+ export const legFields = {
30
+ allocationId: v.id("settlementAllocations"),
31
+ sourceChargeId: v.string(),
32
+ legIndex: v.number(),
33
+ bucketKey: v.string(),
34
+ role: splitRecipientRoleValidator,
35
+ registrationId: v.optional(v.id("financialOwnership")),
36
+ userId: v.optional(v.string()),
37
+ orgId: v.optional(v.string()),
38
+ ownershipStatus: v.union(v.literal("registered"), v.literal("unknown"), v.literal("ambiguous"), v.literal("contradictory")),
39
+ };
40
+ export const legDoc = v.object({
41
+ ...legFields,
42
+ _id: v.id("financialSourceLegs"),
43
+ _creationTime: v.number(),
44
+ });
45
+ export const sourceLegsTable = defineTable(legFields)
46
+ .index("by_allocation_id_and_leg_index", ["allocationId", "legIndex"])
47
+ .index("by_bucket_key", ["bucketKey"])
48
+ .index("by_owner", ["userId", "orgId"]);
49
+ export const observationGenerationsTable = defineTable({
50
+ scopeKey: v.string(),
51
+ generation: v.number(),
52
+ }).index("by_scope_key", ["scopeKey"]);
53
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/financialObservations/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAE7D,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC;IAC3C,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC;IAC5C,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE;IAC/B,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE;IAC3B,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;IACvB,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE;IAC5B,YAAY,EAAE,CAAC,CAAC,QAAQ,CACtB,CAAC,CAAC,MAAM,CAAC;QACP,KAAK,EAAE,CAAC,CAAC,KAAK,CACZ,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EACrB,CAAC,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,CAAC,CAC3B;CACF,CAAC;AACF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,GAAG,SAAS;IACZ,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,qBAAqB,CAAC;IAChC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,SAAS,CAAC;KAClD,KAAK,CAAC,gCAAgC,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;KACrE,KAAK,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC;KACrC,KAAK,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,2BAA2B,GAAG,WAAW,CAAC;IACrD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Doc } from "../_generated/dataModel.js";
2
+ import type { MutationCtx } from "../_generated/server.js";
3
+ /** Larger allocations require explicit bounded continuation; aggregate coverage stays UNKNOWN. */
4
+ export declare const synchronousSettlementLegLimit = 100;
5
+ /** Persist diagnostic provenance in the SAME raw mutation; never mutate the financial source. */
6
+ export declare function observeSettlementAllocation(ctx: MutationCtx, row: Doc<"settlementAllocations">): Promise<void>;
7
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../../../src/component/financialObservations/settlement.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAU3D,kGAAkG;AAClG,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAGjD,iGAAiG;AACjG,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,GAAG,CAAC,uBAAuB,CAAC,iBA0HlC"}
@@ -0,0 +1,118 @@
1
+ import { generateIdempotencyKey } from "../lib/idempotency.js";
2
+ import { hasInvalidLegIdentity, invalidate, legOwnership, settlementFingerprint, } from "./settlementHelpers.js";
3
+ /** Larger allocations require explicit bounded continuation; aggregate coverage stays UNKNOWN. */
4
+ export const synchronousSettlementLegLimit = 100;
5
+ /** Persist diagnostic provenance in the SAME raw mutation; never mutate the financial source. */
6
+ export async function observeSettlementAllocation(ctx, row) {
7
+ const markers = await ctx.db
8
+ .query("financialSourceObservations")
9
+ .withIndex("by_allocation_id", (q) => q.eq("allocationId", row._id))
10
+ .take(2);
11
+ if (markers.length > 1)
12
+ return;
13
+ const prior = markers[0];
14
+ const oldLegs = await ctx.db
15
+ .query("financialSourceLegs")
16
+ .withIndex("by_allocation_id_and_leg_index", (q) => q.eq("allocationId", row._id))
17
+ .take(synchronousSettlementLegLimit + 1);
18
+ const fingerprint = await settlementFingerprint(row);
19
+ const sources = await ctx.db
20
+ .query("settlementAllocations")
21
+ .withIndex("by_source_charge", (q) => q.eq("sourceChargeId", row.sourceChargeId))
22
+ .take(2);
23
+ const isContinuedOverflow = prior?.isOverflow === true && prior.continuation !== undefined;
24
+ const hasInvalidLegs = hasInvalidLegIdentity(row, oldLegs) ||
25
+ (prior !== undefined &&
26
+ ((!isContinuedOverflow && prior.indexedLegCount !== oldLegs.length) ||
27
+ (!prior.isOverflow &&
28
+ !prior.isContradictory &&
29
+ (prior.legCount !== row.transfers.length ||
30
+ oldLegs.length !== row.transfers.length))));
31
+ const isContradictory = hasInvalidLegs ||
32
+ sources.length !== 1 ||
33
+ sources[0]?._id !== row._id ||
34
+ prior?.isContradictory === true ||
35
+ (prior !== undefined && prior.fingerprint !== fingerprint) ||
36
+ (oldLegs.length > synchronousSettlementLegLimit && !isContinuedOverflow);
37
+ const isOverflow = row.transfers.length > synchronousSettlementLegLimit;
38
+ const legs = [];
39
+ if (!isOverflow && !isContradictory)
40
+ for (const [legIndex, leg] of row.transfers.entries()) {
41
+ const previous = oldLegs.find((l) => l.legIndex === legIndex);
42
+ legs.push({
43
+ allocationId: row._id,
44
+ sourceChargeId: row.sourceChargeId,
45
+ legIndex,
46
+ bucketKey: leg.destinationAccountId,
47
+ role: leg.role,
48
+ ...(await legOwnership(ctx, leg.destinationAccountId, previous)),
49
+ });
50
+ }
51
+ if (isContinuedOverflow && !isContradictory)
52
+ return;
53
+ const ownershipFingerprint = await generateIdempotencyKey("settlement-leg-ownership-v1", { legs });
54
+ if (prior &&
55
+ prior.observedFingerprint === fingerprint &&
56
+ prior.ownershipFingerprint === ownershipFingerprint &&
57
+ prior.isContradictory === isContradictory &&
58
+ prior.isOverflow === isOverflow)
59
+ return;
60
+ const generation = (prior?.generation ?? 0) + 1;
61
+ if (!Number.isSafeInteger(generation) ||
62
+ generation < 1 ||
63
+ (prior && prior.generation < 1)) {
64
+ if (prior && prior.generation !== 0) {
65
+ await ctx.db.patch("financialSourceObservations", prior._id, {
66
+ generation: 0,
67
+ isContradictory: true,
68
+ });
69
+ await invalidate(ctx, oldLegs);
70
+ }
71
+ return;
72
+ }
73
+ if (!isOverflow && !isContradictory)
74
+ for (const leg of legs) {
75
+ const existing = oldLegs.find((l) => l.legIndex === leg.legIndex);
76
+ if (existing)
77
+ await ctx.db.patch("financialSourceLegs", existing._id, leg);
78
+ else
79
+ await ctx.db.insert("financialSourceLegs", leg);
80
+ }
81
+ if (isContradictory && !hasInvalidLegs)
82
+ for (const leg of oldLegs)
83
+ await ctx.db.patch("financialSourceLegs", leg._id, {
84
+ ownershipStatus: "contradictory",
85
+ });
86
+ const fields = {
87
+ allocationId: row._id,
88
+ sourceChargeId: prior?.sourceChargeId ?? row.sourceChargeId,
89
+ producer: "settlement_allocation",
90
+ producerVersion: 1,
91
+ fingerprint: prior?.fingerprint ?? fingerprint,
92
+ observedFingerprint: fingerprint,
93
+ ownershipFingerprint,
94
+ generation,
95
+ legCount: row.transfers.length,
96
+ indexedLegCount: isContinuedOverflow
97
+ ? prior.indexedLegCount
98
+ : isOverflow || isContradictory
99
+ ? oldLegs.length
100
+ : legs.length,
101
+ ...(prior?.continuation && isContradictory
102
+ ? {
103
+ continuation: {
104
+ ...prior.continuation,
105
+ state: "held",
106
+ },
107
+ }
108
+ : {}),
109
+ isOverflow,
110
+ isContradictory,
111
+ };
112
+ if (prior)
113
+ await ctx.db.patch("financialSourceObservations", prior._id, fields);
114
+ else
115
+ await ctx.db.insert("financialSourceObservations", fields);
116
+ await invalidate(ctx, [...oldLegs, ...legs]);
117
+ }
118
+ //# sourceMappingURL=settlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.js","sourceRoot":"","sources":["../../../src/component/financialObservations/settlement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,YAAY,EACZ,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAGhC,kGAAkG;AAClG,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAGjD,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,GAAgB,EAChB,GAAiC;IAEjC,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,EAAE;SACzB,KAAK,CAAC,6BAA6B,CAAC;SACpC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;SACnE,IAAI,CAAC,CAAC,CAAC,CAAC;IACX,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;I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