@fantastic.dev/better-stripe 0.63.0 → 0.64.1

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 (175) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +21 -1
  3. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +550 -0
  4. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  5. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +275 -0
  6. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
  7. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +582 -32
  8. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
  9. package/dist/client/connect/payoutSyncTestHelpers.d.ts +291 -16
  10. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  11. package/dist/client/financialOwnership.d.ts +2 -2
  12. package/dist/client/financialOwnership.d.ts.map +1 -1
  13. package/dist/client/financialOwnership.js +2 -2
  14. package/dist/client/financialOwnership.js.map +1 -1
  15. package/dist/client/payoutRevisionMigration.d.ts +37 -0
  16. package/dist/client/payoutRevisionMigration.d.ts.map +1 -0
  17. package/dist/client/payoutRevisionMigration.js +49 -0
  18. package/dist/client/payoutRevisionMigration.js.map +1 -0
  19. package/dist/client/publicTypes.d.ts +2 -0
  20. package/dist/client/publicTypes.d.ts.map +1 -1
  21. package/dist/client/reversalObservations.d.ts +62 -0
  22. package/dist/client/reversalObservations.d.ts.map +1 -0
  23. package/dist/client/reversalObservations.js +79 -0
  24. package/dist/client/reversalObservations.js.map +1 -0
  25. package/dist/component/_generated/api.d.ts +28 -0
  26. package/dist/component/_generated/api.d.ts.map +1 -1
  27. package/dist/component/_generated/api.js.map +1 -1
  28. package/dist/component/_generated/component.d.ts +354 -0
  29. package/dist/component/_generated/component.d.ts.map +1 -1
  30. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  31. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  32. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  33. package/dist/component/connect/mutations.d.ts.map +1 -1
  34. package/dist/component/connect/mutations.js +2 -0
  35. package/dist/component/connect/mutations.js.map +1 -1
  36. package/dist/component/connect/reversalClaims.d.ts.map +1 -1
  37. package/dist/component/connect/reversalClaims.js +10 -1
  38. package/dist/component/connect/reversalClaims.js.map +1 -1
  39. package/dist/component/earnings/triggers.d.ts +408 -16
  40. package/dist/component/earnings/triggers.d.ts.map +1 -1
  41. package/dist/component/financialObservations/transferSchema.d.ts +1 -0
  42. package/dist/component/financialObservations/transferSchema.d.ts.map +1 -1
  43. package/dist/component/financialObservations/transferSchema.js +1 -0
  44. package/dist/component/financialObservations/transferSchema.js.map +1 -1
  45. package/dist/component/payoutRelease/queries.d.ts +2 -2
  46. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  47. package/dist/component/payoutRevisionJournal/mutations.d.ts +15 -0
  48. package/dist/component/payoutRevisionJournal/mutations.d.ts.map +1 -0
  49. package/dist/component/payoutRevisionJournal/mutations.js +11 -0
  50. package/dist/component/payoutRevisionJournal/mutations.js.map +1 -0
  51. package/dist/component/payoutRevisionJournal/schema.d.ts +45 -0
  52. package/dist/component/payoutRevisionJournal/schema.d.ts.map +1 -0
  53. package/dist/component/payoutRevisionJournal/schema.js +22 -0
  54. package/dist/component/payoutRevisionJournal/schema.js.map +1 -0
  55. package/dist/component/payoutRevisionJournal/state.d.ts +36 -0
  56. package/dist/component/payoutRevisionJournal/state.d.ts.map +1 -0
  57. package/dist/component/payoutRevisionJournal/state.js +111 -0
  58. package/dist/component/payoutRevisionJournal/state.js.map +1 -0
  59. package/dist/component/payoutRevisionMigration/mutations.d.ts +36 -0
  60. package/dist/component/payoutRevisionMigration/mutations.d.ts.map +1 -0
  61. package/dist/component/payoutRevisionMigration/mutations.js +126 -0
  62. package/dist/component/payoutRevisionMigration/mutations.js.map +1 -0
  63. package/dist/component/payoutRevisionMigration/queries.d.ts +38 -0
  64. package/dist/component/payoutRevisionMigration/queries.d.ts.map +1 -0
  65. package/dist/component/payoutRevisionMigration/queries.js +39 -0
  66. package/dist/component/payoutRevisionMigration/queries.js.map +1 -0
  67. package/dist/component/payoutRevisionMigration/schema.d.ts +115 -0
  68. package/dist/component/payoutRevisionMigration/schema.d.ts.map +1 -0
  69. package/dist/component/payoutRevisionMigration/schema.js +52 -0
  70. package/dist/component/payoutRevisionMigration/schema.js.map +1 -0
  71. package/dist/component/payoutSnapshots/legacyRevisionWriter.d.ts +4 -0
  72. package/dist/component/payoutSnapshots/legacyRevisionWriter.d.ts.map +1 -0
  73. package/dist/component/payoutSnapshots/legacyRevisionWriter.js +33 -0
  74. package/dist/component/payoutSnapshots/legacyRevisionWriter.js.map +1 -0
  75. package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -1
  76. package/dist/component/payoutSnapshots/revisions.js +23 -29
  77. package/dist/component/payoutSnapshots/revisions.js.map +1 -1
  78. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  79. package/dist/component/refundSync/mutations.d.ts +1 -1
  80. package/dist/component/refundSync/mutations.d.ts.map +1 -1
  81. package/dist/component/reversalObservations/capture.d.ts +6 -0
  82. package/dist/component/reversalObservations/capture.d.ts.map +1 -0
  83. package/dist/component/reversalObservations/capture.js +96 -0
  84. package/dist/component/reversalObservations/capture.js.map +1 -0
  85. package/dist/component/reversalObservations/indexSlice.d.ts +29 -0
  86. package/dist/component/reversalObservations/indexSlice.d.ts.map +1 -0
  87. package/dist/component/reversalObservations/indexSlice.js +101 -0
  88. package/dist/component/reversalObservations/indexSlice.js.map +1 -0
  89. package/dist/component/reversalObservations/integrity.d.ts +25 -0
  90. package/dist/component/reversalObservations/integrity.d.ts.map +1 -0
  91. package/dist/component/reversalObservations/integrity.js +19 -0
  92. package/dist/component/reversalObservations/integrity.js.map +1 -0
  93. package/dist/component/reversalObservations/mutations.d.ts +37 -0
  94. package/dist/component/reversalObservations/mutations.d.ts.map +1 -0
  95. package/dist/component/reversalObservations/mutations.js +181 -0
  96. package/dist/component/reversalObservations/mutations.js.map +1 -0
  97. package/dist/component/reversalObservations/pagination.d.ts +34 -0
  98. package/dist/component/reversalObservations/pagination.d.ts.map +1 -0
  99. package/dist/component/reversalObservations/pagination.js +31 -0
  100. package/dist/component/reversalObservations/pagination.js.map +1 -0
  101. package/dist/component/reversalObservations/queries.d.ts +221 -0
  102. package/dist/component/reversalObservations/queries.d.ts.map +1 -0
  103. package/dist/component/reversalObservations/queries.js +114 -0
  104. package/dist/component/reversalObservations/queries.js.map +1 -0
  105. package/dist/component/reversalObservations/references.d.ts +17 -0
  106. package/dist/component/reversalObservations/references.d.ts.map +1 -0
  107. package/dist/component/reversalObservations/references.js +95 -0
  108. package/dist/component/reversalObservations/references.js.map +1 -0
  109. package/dist/component/reversalObservations/schema.d.ts +525 -0
  110. package/dist/component/reversalObservations/schema.d.ts.map +1 -0
  111. package/dist/component/reversalObservations/schema.js +92 -0
  112. package/dist/component/reversalObservations/schema.js.map +1 -0
  113. package/dist/component/reversalObservations/selectors.d.ts +3 -0
  114. package/dist/component/reversalObservations/selectors.d.ts.map +1 -0
  115. package/dist/component/reversalObservations/selectors.js +8 -0
  116. package/dist/component/reversalObservations/selectors.js.map +1 -0
  117. package/dist/component/reversalObservations/state.d.ts +34 -0
  118. package/dist/component/reversalObservations/state.d.ts.map +1 -0
  119. package/dist/component/reversalObservations/state.js +34 -0
  120. package/dist/component/reversalObservations/state.js.map +1 -0
  121. package/dist/component/schema.d.ts +275 -0
  122. package/dist/component/schema.js +10 -0
  123. package/dist/component/schema.js.map +1 -1
  124. package/dist/component/usage/allowance.fixtures.d.ts +291 -16
  125. package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
  126. package/dist/component/usageCredits/accounting.fixtures.d.ts +275 -0
  127. package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
  128. package/docs/README.md +4 -1
  129. package/docs/client-api.md +6 -0
  130. package/docs/financial-observations.md +51 -8
  131. package/docs/payout-revision-migration.md +54 -0
  132. package/docs/react-workflows-audit.md +73 -2
  133. package/docs/usage-example.md +4 -0
  134. package/docs/usage-verification.md +117 -0
  135. package/package.json +4 -2
  136. package/src/client/financialOwnership.ts +2 -2
  137. package/src/client/payoutRevisionMigration.test.ts +40 -0
  138. package/src/client/payoutRevisionMigration.ts +96 -0
  139. package/src/client/publicTypes.ts +15 -0
  140. package/src/client/reversalObservations.test.ts +69 -0
  141. package/src/client/reversalObservations.ts +151 -0
  142. package/src/component/_generated/api.ts +28 -0
  143. package/src/component/_generated/component.ts +423 -0
  144. package/src/component/connect/mutations.ts +2 -0
  145. package/src/component/connect/reversalClaims.ts +13 -1
  146. package/src/component/financialObservations/transferSchema.ts +1 -0
  147. package/src/component/payoutRevisionJournal/mutations.ts +11 -0
  148. package/src/component/payoutRevisionJournal/schema.ts +34 -0
  149. package/src/component/payoutRevisionJournal/state.ts +141 -0
  150. package/src/component/payoutRevisionMigration/mutations.ts +135 -0
  151. package/src/component/payoutRevisionMigration/queries.ts +50 -0
  152. package/src/component/payoutRevisionMigration/schema.ts +51 -0
  153. package/src/component/payoutSnapshots/legacy-revisions.test.ts +246 -0
  154. package/src/component/payoutSnapshots/legacyRevisionWriter.ts +39 -0
  155. package/src/component/payoutSnapshots/revision-journal-callbacks.test.ts +160 -0
  156. package/src/component/payoutSnapshots/revision-journal-held.test.ts +94 -0
  157. package/src/component/payoutSnapshots/revision-journal.test.ts +310 -0
  158. package/src/component/payoutSnapshots/revision-migration.test.ts +128 -0
  159. package/src/component/payoutSnapshots/revisions.ts +22 -30
  160. package/src/component/reversalObservations/boundaries.test.ts +62 -0
  161. package/src/component/reversalObservations/capture-integrity.test.ts +119 -0
  162. package/src/component/reversalObservations/capture.ts +129 -0
  163. package/src/component/reversalObservations/continuation.test.ts +131 -0
  164. package/src/component/reversalObservations/indexSlice.ts +124 -0
  165. package/src/component/reversalObservations/integrity.ts +31 -0
  166. package/src/component/reversalObservations/lifecycle.test.ts +81 -0
  167. package/src/component/reversalObservations/mutations.ts +211 -0
  168. package/src/component/reversalObservations/pagination.ts +40 -0
  169. package/src/component/reversalObservations/provenance.test.ts +167 -0
  170. package/src/component/reversalObservations/queries.ts +121 -0
  171. package/src/component/reversalObservations/references.ts +134 -0
  172. package/src/component/reversalObservations/schema.ts +100 -0
  173. package/src/component/reversalObservations/selectors.ts +9 -0
  174. package/src/component/reversalObservations/state.ts +42 -0
  175. package/src/component/schema.ts +18 -0
@@ -6176,6 +6176,128 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
6176
6176
  >;
6177
6177
  };
6178
6178
  };
6179
+ payoutRevisionJournal: {
6180
+ mutations: {
6181
+ activateAccount: FunctionReference<
6182
+ "mutation",
6183
+ "internal",
6184
+ { accountId: string },
6185
+ {
6186
+ accountId: string;
6187
+ reason?:
6188
+ | "legacy_ambiguous"
6189
+ | "legacy_invalid"
6190
+ | "legacy_disagreement"
6191
+ | "representation_unavailable";
6192
+ status: "activated" | "unchanged" | "held";
6193
+ },
6194
+ Name
6195
+ >;
6196
+ };
6197
+ };
6198
+ payoutRevisionMigration: {
6199
+ mutations: {
6200
+ begin: FunctionReference<
6201
+ "mutation",
6202
+ "internal",
6203
+ { operationKey: string },
6204
+ {
6205
+ _creationTime: number;
6206
+ _id: string;
6207
+ activated: number;
6208
+ cursor: string | null;
6209
+ held: number;
6210
+ operationKey: string;
6211
+ phase: number;
6212
+ scanned: number;
6213
+ status: "running" | "finished";
6214
+ step: number;
6215
+ unchanged: number;
6216
+ visited: number;
6217
+ },
6218
+ Name
6219
+ >;
6220
+ resume: FunctionReference<
6221
+ "mutation",
6222
+ "internal",
6223
+ { expectedStep: number; jobId: string },
6224
+ {
6225
+ _creationTime: number;
6226
+ _id: string;
6227
+ activated: number;
6228
+ cursor: string | null;
6229
+ held: number;
6230
+ operationKey: string;
6231
+ phase: number;
6232
+ scanned: number;
6233
+ status: "running" | "finished";
6234
+ step: number;
6235
+ unchanged: number;
6236
+ visited: number;
6237
+ },
6238
+ Name
6239
+ >;
6240
+ };
6241
+ queries: {
6242
+ get: FunctionReference<
6243
+ "query",
6244
+ "internal",
6245
+ { jobId: string },
6246
+ {
6247
+ _creationTime: number;
6248
+ _id: string;
6249
+ activated: number;
6250
+ cursor: string | null;
6251
+ held: number;
6252
+ operationKey: string;
6253
+ phase: number;
6254
+ scanned: number;
6255
+ status: "running" | "finished";
6256
+ step: number;
6257
+ unchanged: number;
6258
+ visited: number;
6259
+ } | null,
6260
+ Name
6261
+ >;
6262
+ results: FunctionReference<
6263
+ "query",
6264
+ "internal",
6265
+ {
6266
+ jobId: string;
6267
+ paginationOpts: {
6268
+ cursor: string | null;
6269
+ endCursor?: string | null;
6270
+ id?: number;
6271
+ maximumBytesRead?: number;
6272
+ maximumRowsRead?: number;
6273
+ numItems: number;
6274
+ };
6275
+ },
6276
+ {
6277
+ continueCursor: string;
6278
+ isDone: boolean;
6279
+ page: Array<{
6280
+ _creationTime: number;
6281
+ _id: string;
6282
+ accountDigest: string;
6283
+ accountId?: string;
6284
+ jobId: string;
6285
+ reason?:
6286
+ | "legacy_ambiguous"
6287
+ | "legacy_invalid"
6288
+ | "legacy_disagreement"
6289
+ | "representation_unavailable";
6290
+ sourceId: string;
6291
+ sourceTable: string;
6292
+ status: "activated" | "unchanged" | "held";
6293
+ }>;
6294
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
6295
+ splitCursor?: string | null;
6296
+ },
6297
+ Name
6298
+ >;
6299
+ };
6300
+ };
6179
6301
  payoutSnapshots: {
6180
6302
  mutations: {
6181
6303
  advance: FunctionReference<
@@ -8129,6 +8251,307 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
8129
8251
  >;
8130
8252
  };
8131
8253
  };
8254
+ reversalObservations: {
8255
+ mutations: {
8256
+ resume: FunctionReference<
8257
+ "mutation",
8258
+ "internal",
8259
+ {
8260
+ batchSize?: number;
8261
+ expectedGeneration: number;
8262
+ operationId: string;
8263
+ },
8264
+ {
8265
+ coverage: "unknown";
8266
+ generation: number | null;
8267
+ observation: {
8268
+ _creationTime: number;
8269
+ _id: string;
8270
+ deleted: boolean;
8271
+ fingerprint: string;
8272
+ generation: number;
8273
+ indexTransferGeneration: number | null;
8274
+ indexedCount: number;
8275
+ isContradictory: boolean;
8276
+ latestIdentityFingerprint: string;
8277
+ latestPayloadId: string;
8278
+ legacy: boolean;
8279
+ nextIndex: number;
8280
+ operationDigest: string;
8281
+ originalFingerprint: string;
8282
+ originalIdentityFingerprint: string;
8283
+ originalOperationId: string;
8284
+ originalPayloadId: string;
8285
+ producer: "reversal_claim_lifecycle";
8286
+ producerVersion: 1;
8287
+ referenceFingerprints: Array<string>;
8288
+ sliceCount: number;
8289
+ sourceChargeDigest: string;
8290
+ sourceCreatedAt: number;
8291
+ status: "pending" | "validating" | "complete" | "held";
8292
+ } | null;
8293
+ transferGeneration: number | null;
8294
+ },
8295
+ Name
8296
+ >;
8297
+ };
8298
+ queries: {
8299
+ bucket: FunctionReference<
8300
+ "query",
8301
+ "internal",
8302
+ {
8303
+ bucketKey: string;
8304
+ paginationOpts: {
8305
+ cursor: string | null;
8306
+ endCursor?: string | null;
8307
+ id?: number;
8308
+ maximumBytesRead?: number;
8309
+ maximumRowsRead?: number;
8310
+ numItems: number;
8311
+ };
8312
+ },
8313
+ {
8314
+ continueCursor: string;
8315
+ coverage: "unknown";
8316
+ generation: number | null;
8317
+ isDone: boolean;
8318
+ page: Array<{
8319
+ _creationTime: number;
8320
+ _id: string;
8321
+ bucketDigest?: string;
8322
+ bucketKey?: string;
8323
+ generation: number;
8324
+ identityStatus: "matched" | "unknown" | "contradictory";
8325
+ observationId: string;
8326
+ orgId?: string;
8327
+ originalOperationId: string;
8328
+ ownerDigest?: string;
8329
+ ownershipStatus:
8330
+ "registered" | "unknown" | "ambiguous" | "contradictory";
8331
+ registrationId?: string;
8332
+ sliceIndex: number;
8333
+ transferGeneration: number | null;
8334
+ transferId?: string;
8335
+ userId?: string;
8336
+ }>;
8337
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
8338
+ splitCursor?: string | null;
8339
+ transferGeneration: number | null;
8340
+ },
8341
+ Name
8342
+ >;
8343
+ history: FunctionReference<
8344
+ "query",
8345
+ "internal",
8346
+ {
8347
+ paginationOpts: {
8348
+ cursor: string | null;
8349
+ endCursor?: string | null;
8350
+ id?: number;
8351
+ maximumBytesRead?: number;
8352
+ maximumRowsRead?: number;
8353
+ numItems: number;
8354
+ };
8355
+ selector: "operationId" | "sourceChargeId";
8356
+ value: string;
8357
+ },
8358
+ {
8359
+ continueCursor: string;
8360
+ coverage: "unknown";
8361
+ generation: number | null;
8362
+ isDone: boolean;
8363
+ page: Array<{
8364
+ _creationTime: number;
8365
+ _id: string;
8366
+ deleted: boolean;
8367
+ fingerprint: string;
8368
+ generation: number;
8369
+ indexTransferGeneration: number | null;
8370
+ indexedCount: number;
8371
+ isContradictory: boolean;
8372
+ latestIdentityFingerprint: string;
8373
+ latestPayloadId: string;
8374
+ legacy: boolean;
8375
+ nextIndex: number;
8376
+ operationDigest: string;
8377
+ originalFingerprint: string;
8378
+ originalIdentityFingerprint: string;
8379
+ originalOperationId: string;
8380
+ originalPayloadId: string;
8381
+ producer: "reversal_claim_lifecycle";
8382
+ producerVersion: 1;
8383
+ referenceFingerprints: Array<string>;
8384
+ sliceCount: number;
8385
+ sourceChargeDigest: string;
8386
+ sourceCreatedAt: number;
8387
+ status: "pending" | "validating" | "complete" | "held";
8388
+ }>;
8389
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
8390
+ splitCursor?: string | null;
8391
+ transferGeneration: number | null;
8392
+ },
8393
+ Name
8394
+ >;
8395
+ operation: FunctionReference<
8396
+ "query",
8397
+ "internal",
8398
+ { operationId: string },
8399
+ {
8400
+ coverage: "unknown";
8401
+ generation: number | null;
8402
+ observation: {
8403
+ _creationTime: number;
8404
+ _id: string;
8405
+ deleted: boolean;
8406
+ fingerprint: string;
8407
+ generation: number;
8408
+ indexTransferGeneration: number | null;
8409
+ indexedCount: number;
8410
+ isContradictory: boolean;
8411
+ latestIdentityFingerprint: string;
8412
+ latestPayloadId: string;
8413
+ legacy: boolean;
8414
+ nextIndex: number;
8415
+ operationDigest: string;
8416
+ originalFingerprint: string;
8417
+ originalIdentityFingerprint: string;
8418
+ originalOperationId: string;
8419
+ originalPayloadId: string;
8420
+ producer: "reversal_claim_lifecycle";
8421
+ producerVersion: 1;
8422
+ referenceFingerprints: Array<string>;
8423
+ sliceCount: number;
8424
+ sourceChargeDigest: string;
8425
+ sourceCreatedAt: number;
8426
+ status: "pending" | "validating" | "complete" | "held";
8427
+ } | null;
8428
+ transferGeneration: number | null;
8429
+ },
8430
+ Name
8431
+ >;
8432
+ owner: FunctionReference<
8433
+ "query",
8434
+ "internal",
8435
+ {
8436
+ orgId?: string;
8437
+ paginationOpts: {
8438
+ cursor: string | null;
8439
+ endCursor?: string | null;
8440
+ id?: number;
8441
+ maximumBytesRead?: number;
8442
+ maximumRowsRead?: number;
8443
+ numItems: number;
8444
+ };
8445
+ userId: string;
8446
+ },
8447
+ {
8448
+ continueCursor: string;
8449
+ coverage: "unknown";
8450
+ generation: number | null;
8451
+ isDone: boolean;
8452
+ page: Array<{
8453
+ _creationTime: number;
8454
+ _id: string;
8455
+ bucketDigest?: string;
8456
+ bucketKey?: string;
8457
+ generation: number;
8458
+ identityStatus: "matched" | "unknown" | "contradictory";
8459
+ observationId: string;
8460
+ orgId?: string;
8461
+ originalOperationId: string;
8462
+ ownerDigest?: string;
8463
+ ownershipStatus:
8464
+ "registered" | "unknown" | "ambiguous" | "contradictory";
8465
+ registrationId?: string;
8466
+ sliceIndex: number;
8467
+ transferGeneration: number | null;
8468
+ transferId?: string;
8469
+ userId?: string;
8470
+ }>;
8471
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
8472
+ splitCursor?: string | null;
8473
+ transferGeneration: number | null;
8474
+ },
8475
+ Name
8476
+ >;
8477
+ payload: FunctionReference<
8478
+ "query",
8479
+ "internal",
8480
+ { operationId: string; version: "original" | "latest" },
8481
+ {
8482
+ coverage: "unknown";
8483
+ generation: number | null;
8484
+ payload: {
8485
+ _creationTime: number;
8486
+ _id: string;
8487
+ commissionExposure?: {
8488
+ chargeAmount: number;
8489
+ disputeId?: string;
8490
+ disputeState?: "open" | "lost" | "won";
8491
+ finalized: boolean;
8492
+ kind: "refund" | "dispute";
8493
+ principal: number;
8494
+ refundId?: string;
8495
+ refundedPrincipal?: number;
8496
+ };
8497
+ operationId: string;
8498
+ slices: Array<{
8499
+ from: number;
8500
+ stripeTransferId: string;
8501
+ to: number;
8502
+ }>;
8503
+ sourceChargeId: string;
8504
+ } | null;
8505
+ transferGeneration: number | null;
8506
+ },
8507
+ Name
8508
+ >;
8509
+ slices: FunctionReference<
8510
+ "query",
8511
+ "internal",
8512
+ {
8513
+ operationId: string;
8514
+ paginationOpts: {
8515
+ cursor: string | null;
8516
+ endCursor?: string | null;
8517
+ id?: number;
8518
+ maximumBytesRead?: number;
8519
+ maximumRowsRead?: number;
8520
+ numItems: number;
8521
+ };
8522
+ },
8523
+ {
8524
+ continueCursor: string;
8525
+ coverage: "unknown";
8526
+ generation: number | null;
8527
+ isDone: boolean;
8528
+ page: Array<{
8529
+ _creationTime: number;
8530
+ _id: string;
8531
+ bucketDigest?: string;
8532
+ bucketKey?: string;
8533
+ generation: number;
8534
+ identityStatus: "matched" | "unknown" | "contradictory";
8535
+ observationId: string;
8536
+ orgId?: string;
8537
+ originalOperationId: string;
8538
+ ownerDigest?: string;
8539
+ ownershipStatus:
8540
+ "registered" | "unknown" | "ambiguous" | "contradictory";
8541
+ registrationId?: string;
8542
+ sliceIndex: number;
8543
+ transferGeneration: number | null;
8544
+ transferId?: string;
8545
+ userId?: string;
8546
+ }>;
8547
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
8548
+ splitCursor?: string | null;
8549
+ transferGeneration: number | null;
8550
+ },
8551
+ Name
8552
+ >;
8553
+ };
8554
+ };
8132
8555
  settlement: {
8133
8556
  mutations: {
8134
8557
  claimCommissionInvoice: FunctionReference<
@@ -1,3 +1,4 @@
1
+ import { captureReversal } from "../reversalObservations/capture.js";
1
2
  import { writeRefund } from "./refundWrites.js";
2
3
  import {
3
4
  deferTransferFacts,
@@ -412,6 +413,7 @@ export const releaseReversalClaim = mutation({
412
413
  op,
413
414
  plan.map((p) => p.legId),
414
415
  );
416
+ await captureReversal(ctx, op, true);
415
417
  await ctx.db.delete("transferReversalOps", op._id);
416
418
 
417
419
  return { released: true, rewound };
@@ -1,3 +1,4 @@
1
+ import { captureReversal } from "../reversalObservations/capture.js";
1
2
  import {
2
3
  deferTransferFacts,
3
4
  synchronousTransferFactLimit,
@@ -156,6 +157,12 @@ export const claimReversalSlicesDefinition = {
156
157
  commissionExposure: exposure,
157
158
  });
158
159
  }
160
+ await captureReversal(ctx, {
161
+ ...existingOp,
162
+ ...(existingOp.commissionExposure && exposure
163
+ ? { commissionExposure: exposure }
164
+ : {}),
165
+ });
159
166
  const slices = [];
160
167
  for (const s of existingOp.slices) {
161
168
  slices.push({
@@ -225,10 +232,15 @@ export const claimReversalSlicesDefinition = {
225
232
  : {}),
226
233
  });
227
234
 
235
+ const observedOperation = (await ctx.db.get(
236
+ "transferReversalOps",
237
+ operationId,
238
+ ))!;
239
+ await captureReversal(ctx, observedOperation, false, rows);
228
240
  if (slices.length > synchronousTransferFactLimit)
229
241
  await deferTransferFacts(
230
242
  ctx,
231
- (await ctx.db.get("transferReversalOps", operationId))!,
243
+ observedOperation,
232
244
  slices.map((s) => byId.get(s.stripeTransferId)!._id),
233
245
  "transfer_frontier_claim",
234
246
  );
@@ -28,6 +28,7 @@ export const transferObservationDoc = v.object({
28
28
  });
29
29
  export const transferObservationsTable = defineTable(transferFields)
30
30
  .index("by_transfer_id", ["transferId"])
31
+ .index("by_source_charge_id", ["sourceChargeId"])
31
32
  .index("by_bucket_key", ["bucketKey"])
32
33
  .index("by_owner", ["userId", "orgId"]);
33
34
  export const transferBatchFields = {
@@ -0,0 +1,11 @@
1
+ import { v } from "convex/values";
2
+ import { mutation } from "../_generated/server.js";
3
+ import { activateRevisionAccount } from "./state.js";
4
+ import { activationResult } from "./schema.js";
5
+
6
+ /** Trusted-host schema migration only. Authorize the account before calling. */
7
+ export const activateAccount = mutation({
8
+ args: { accountId: v.string() },
9
+ returns: activationResult,
10
+ handler: async (ctx, args) => activateRevisionAccount(ctx, args.accountId),
11
+ });
@@ -0,0 +1,34 @@
1
+ import { defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+
4
+ export const journalFields = {
5
+ accountId: v.string(),
6
+ revision: v.number(),
7
+ riskRevision: v.number(),
8
+ financialRiskRevision: v.number(),
9
+ financialPresent: v.boolean(),
10
+ fenceStream: v.boolean(),
11
+ kind: v.union(v.literal("baseline"), v.literal("bump")),
12
+ legacyFinancialId: v.optional(v.id("payoutFinancialRevisions")),
13
+ legacyRiskId: v.optional(v.id("payoutRiskRevisions")),
14
+ };
15
+ export const journalTable = defineTable(journalFields)
16
+ .index("by_account_revision", ["accountId", "revision"])
17
+ .index("by_account_fence_revision", ["accountId", "fenceStream", "revision"]);
18
+
19
+ export const activationResult = v.object({
20
+ accountId: v.string(),
21
+ status: v.union(
22
+ v.literal("activated"),
23
+ v.literal("unchanged"),
24
+ v.literal("held"),
25
+ ),
26
+ reason: v.optional(
27
+ v.union(
28
+ v.literal("legacy_ambiguous"),
29
+ v.literal("legacy_invalid"),
30
+ v.literal("legacy_disagreement"),
31
+ v.literal("representation_unavailable"),
32
+ ),
33
+ ),
34
+ });
@@ -0,0 +1,141 @@
1
+ import { convexToJson } from "convex/values";
2
+ import type { Doc } from "../_generated/dataModel.js";
3
+ import type { MutationCtx, QueryCtx } from "../_generated/server.js";
4
+ import { addSummaryAmounts as add } from "../earnings/arithmetic.js";
5
+
6
+ type Journal = Doc<"payoutRevisionJournal">;
7
+ function valid(row: Journal) {
8
+ return (
9
+ Number.isSafeInteger(row.revision) &&
10
+ Number.isSafeInteger(row.riskRevision) &&
11
+ Number.isSafeInteger(row.financialRiskRevision) &&
12
+ (row.kind === "baseline"
13
+ ? row.fenceStream &&
14
+ (row.financialPresent
15
+ ? !!row.legacyFinancialId &&
16
+ row.financialRiskRevision === row.riskRevision
17
+ : !row.legacyFinancialId &&
18
+ row.revision === 0 &&
19
+ row.financialRiskRevision === 0) &&
20
+ (!!row.legacyFinancialId ||
21
+ !!row.legacyRiskId ||
22
+ row.riskRevision === 0)
23
+ : row.financialPresent &&
24
+ row.financialRiskRevision === row.riskRevision &&
25
+ !row.legacyFinancialId &&
26
+ !row.legacyRiskId)
27
+ );
28
+ }
29
+
30
+ function validEdge(rows: Journal[], fenceOnly: boolean) {
31
+ const [next, previous] = rows;
32
+ if (!next) return true;
33
+ if (!previous) return next.kind === "baseline";
34
+ if (next.kind !== "bump" || next.revision <= previous.revision) return false;
35
+ return (
36
+ (fenceOnly || next.revision === add(previous.revision, 1)) &&
37
+ next.riskRevision === add(previous.riskRevision, next.fenceStream ? 1 : 0)
38
+ );
39
+ }
40
+
41
+ /** One indexed range. Immutable entries use the existing financial counter as order. */
42
+ export async function journalHead(
43
+ ctx: QueryCtx | MutationCtx,
44
+ accountId: string,
45
+ fenceOnly = false,
46
+ ) {
47
+ const rows = fenceOnly
48
+ ? await ctx.db
49
+ .query("payoutRevisionJournal")
50
+ .withIndex("by_account_fence_revision", (q) =>
51
+ q.eq("accountId", accountId).eq("fenceStream", true),
52
+ )
53
+ .order("desc")
54
+ .take(2)
55
+ : await ctx.db
56
+ .query("payoutRevisionJournal")
57
+ .withIndex("by_account_revision", (q) => q.eq("accountId", accountId))
58
+ .order("desc")
59
+ .take(2);
60
+ if (rows.some((row) => !valid(row)) || !validEdge(rows, fenceOnly))
61
+ throw new Error(
62
+ "Canonical payout revision journal is ambiguous or invalid.",
63
+ );
64
+ return rows[0] ?? null;
65
+ }
66
+
67
+ /** Activation never increments a financial counter or rewrites historical rows. */
68
+ export async function activateRevisionAccount(
69
+ ctx: MutationCtx,
70
+ accountId: string,
71
+ ) {
72
+ const held = (
73
+ reason:
74
+ | "legacy_ambiguous"
75
+ | "legacy_invalid"
76
+ | "legacy_disagreement"
77
+ | "representation_unavailable",
78
+ ) => ({ accountId, status: "held" as const, reason });
79
+ if (new TextEncoder().encode(accountId).length > 900_000)
80
+ return held("representation_unavailable");
81
+ if (await journalHead(ctx, accountId))
82
+ return { accountId, status: "unchanged" as const };
83
+ const financial = await ctx.db
84
+ .query("payoutFinancialRevisions")
85
+ .withIndex("by_account", (q) => q.eq("accountId", accountId))
86
+ .take(2);
87
+ const risk = await ctx.db
88
+ .query("payoutRiskRevisions")
89
+ .withIndex("by_account", (q) => q.eq("accountId", accountId))
90
+ .take(2);
91
+ if (financial.length > 1 || risk.length > 1) return held("legacy_ambiguous");
92
+ const row = financial[0];
93
+ const fence = risk[0];
94
+ const values = [
95
+ row?.revision ?? 0,
96
+ row?.riskRevision ?? 0,
97
+ fence?.riskRevision ?? 0,
98
+ ];
99
+ if (values.some((value) => !Number.isSafeInteger(value)))
100
+ return held("legacy_invalid");
101
+ if (row && fence && row.riskRevision !== fence.riskRevision)
102
+ return held("legacy_disagreement");
103
+ const baseline = {
104
+ accountId,
105
+ revision: row?.revision ?? 0,
106
+ riskRevision: fence?.riskRevision ?? row?.riskRevision ?? 0,
107
+ financialRiskRevision: row?.riskRevision ?? 0,
108
+ financialPresent: row !== undefined,
109
+ fenceStream: true,
110
+ kind: "baseline" as const,
111
+ ...(row ? { legacyFinancialId: row._id } : {}),
112
+ ...(fence ? { legacyRiskId: fence._id } : {}),
113
+ };
114
+ if (
115
+ new TextEncoder().encode(JSON.stringify(convexToJson(baseline))).length >
116
+ 900_000
117
+ )
118
+ return held("representation_unavailable");
119
+ await ctx.db.insert("payoutRevisionJournal", baseline);
120
+ return { accountId, status: "activated" as const };
121
+ }
122
+
123
+ /** The unchanged centralized callbacks supply the same increment and risk decision. */
124
+ export async function appendRevision(
125
+ ctx: MutationCtx,
126
+ head: Journal,
127
+ risk: boolean,
128
+ ) {
129
+ const revision = add(head.revision, 1);
130
+ const riskRevision = add(head.riskRevision, risk ? 1 : 0);
131
+ await ctx.db.insert("payoutRevisionJournal", {
132
+ accountId: head.accountId,
133
+ revision,
134
+ riskRevision,
135
+ financialRiskRevision: riskRevision,
136
+ financialPresent: true,
137
+ fenceStream: risk,
138
+ kind: "bump",
139
+ });
140
+ return { revision, riskRevision };
141
+ }