@fantastic.dev/better-stripe 0.24.0 → 0.25.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 (147) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +7 -1
  3. package/dist/client/billing/checkout.d.ts +3 -43
  4. package/dist/client/billing/checkout.d.ts.map +1 -1
  5. package/dist/client/billing/checkout.js +5 -260
  6. package/dist/client/billing/checkout.js.map +1 -1
  7. package/dist/client/billing/checkoutRequest.d.ts +129 -0
  8. package/dist/client/billing/checkoutRequest.d.ts.map +1 -0
  9. package/dist/client/billing/checkoutRequest.js +263 -0
  10. package/dist/client/billing/checkoutRequest.js.map +1 -0
  11. package/dist/client/billing/preparedCheckout.d.ts +22 -0
  12. package/dist/client/billing/preparedCheckout.d.ts.map +1 -0
  13. package/dist/client/billing/preparedCheckout.js +86 -0
  14. package/dist/client/billing/preparedCheckout.js.map +1 -0
  15. package/dist/client/checkoutRequests.d.ts +80 -0
  16. package/dist/client/checkoutRequests.d.ts.map +1 -0
  17. package/dist/client/checkoutRequests.js +28 -0
  18. package/dist/client/checkoutRequests.js.map +1 -0
  19. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +464 -0
  20. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
  21. package/dist/client/connect/payoutCollection.d.ts +21 -0
  22. package/dist/client/connect/payoutCollection.d.ts.map +1 -0
  23. package/dist/client/connect/payoutCollection.js +47 -0
  24. package/dist/client/connect/payoutCollection.js.map +1 -0
  25. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +1805 -0
  26. package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -0
  27. package/dist/client/connect/payoutExecutionTestHelpers.js +194 -0
  28. package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -0
  29. package/dist/client/connect/payoutSyncTestHelpers.d.ts +232 -0
  30. package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
  31. package/dist/client/connect/payoutWorker.d.ts +48 -0
  32. package/dist/client/connect/payoutWorker.d.ts.map +1 -0
  33. package/dist/client/connect/payoutWorker.js +78 -0
  34. package/dist/client/connect/payoutWorker.js.map +1 -0
  35. package/dist/client/index.d.ts +4 -11
  36. package/dist/client/index.d.ts.map +1 -1
  37. package/dist/client/index.js +4 -9
  38. package/dist/client/index.js.map +1 -1
  39. package/dist/client/payoutPolicy.d.ts +67 -0
  40. package/dist/client/payoutPolicy.d.ts.map +1 -1
  41. package/dist/client/payoutPolicy.js +10 -0
  42. package/dist/client/payoutPolicy.js.map +1 -1
  43. package/dist/client/readContracts.d.ts +11 -1
  44. package/dist/client/readContracts.d.ts.map +1 -1
  45. package/dist/client/readContracts.js +10 -0
  46. package/dist/client/readContracts.js.map +1 -1
  47. package/dist/component/_generated/component.d.ts +293 -0
  48. package/dist/component/_generated/component.d.ts.map +1 -1
  49. package/dist/component/core/mutations.d.ts.map +1 -1
  50. package/dist/component/core/mutations.js +2 -0
  51. package/dist/component/core/mutations.js.map +1 -1
  52. package/dist/component/core/resetSafety.d.ts +4 -0
  53. package/dist/component/core/resetSafety.d.ts.map +1 -0
  54. package/dist/component/core/resetSafety.js +54 -0
  55. package/dist/component/core/resetSafety.js.map +1 -0
  56. package/dist/component/earnings/triggers.d.ts +418 -0
  57. package/dist/component/earnings/triggers.d.ts.map +1 -1
  58. package/dist/component/earnings/triggers.js +2 -0
  59. package/dist/component/earnings/triggers.js.map +1 -1
  60. package/dist/component/payoutPolicy/schema.d.ts +2 -0
  61. package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
  62. package/dist/component/payoutPolicy/schema.js +3 -1
  63. package/dist/component/payoutPolicy/schema.js.map +1 -1
  64. package/dist/component/payoutRelease/mutations.js +1 -1
  65. package/dist/component/payoutRelease/schema.d.ts +1 -0
  66. package/dist/component/payoutRelease/schema.d.ts.map +1 -1
  67. package/dist/component/payoutRelease/schema.js +1 -0
  68. package/dist/component/payoutRelease/schema.js.map +1 -1
  69. package/dist/component/payoutSnapshots/localState.d.ts +89 -0
  70. package/dist/component/payoutSnapshots/localState.d.ts.map +1 -0
  71. package/dist/component/payoutSnapshots/localState.js +186 -0
  72. package/dist/component/payoutSnapshots/localState.js.map +1 -0
  73. package/dist/component/payoutSnapshots/mutations.d.ts +108 -0
  74. package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -0
  75. package/dist/component/payoutSnapshots/mutations.js +263 -0
  76. package/dist/component/payoutSnapshots/mutations.js.map +1 -0
  77. package/dist/component/payoutSnapshots/revisions.d.ts +12 -0
  78. package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -0
  79. package/dist/component/payoutSnapshots/revisions.js +173 -0
  80. package/dist/component/payoutSnapshots/revisions.js.map +1 -0
  81. package/dist/component/payoutSnapshots/schema.d.ts +285 -0
  82. package/dist/component/payoutSnapshots/schema.d.ts.map +1 -0
  83. package/dist/component/payoutSnapshots/schema.js +108 -0
  84. package/dist/component/payoutSnapshots/schema.js.map +1 -0
  85. package/dist/component/payoutSnapshots/scope.d.ts +7 -0
  86. package/dist/component/payoutSnapshots/scope.d.ts.map +1 -0
  87. package/dist/component/payoutSnapshots/scope.js +8 -0
  88. package/dist/component/payoutSnapshots/scope.js.map +1 -0
  89. package/dist/component/payoutWorker/helpers.d.ts +30 -0
  90. package/dist/component/payoutWorker/helpers.d.ts.map +1 -0
  91. package/dist/component/payoutWorker/helpers.js +21 -0
  92. package/dist/component/payoutWorker/helpers.js.map +1 -0
  93. package/dist/component/payoutWorker/mutations.d.ts +68 -0
  94. package/dist/component/payoutWorker/mutations.d.ts.map +1 -0
  95. package/dist/component/payoutWorker/mutations.js +161 -0
  96. package/dist/component/payoutWorker/mutations.js.map +1 -0
  97. package/dist/component/payoutWorker/queries.d.ts +123 -0
  98. package/dist/component/payoutWorker/queries.d.ts.map +1 -0
  99. package/dist/component/payoutWorker/queries.js +61 -0
  100. package/dist/component/payoutWorker/queries.js.map +1 -0
  101. package/dist/component/payoutWorker/schema.d.ts +91 -0
  102. package/dist/component/payoutWorker/schema.d.ts.map +1 -0
  103. package/dist/component/payoutWorker/schema.js +27 -0
  104. package/dist/component/payoutWorker/schema.js.map +1 -0
  105. package/dist/component/schema.d.ts +232 -0
  106. package/dist/component/schema.js +10 -0
  107. package/dist/component/schema.js.map +1 -1
  108. package/docs/read-contracts.md +48 -0
  109. package/docs/settlement.md +128 -1
  110. package/package.json +1 -1
  111. package/src/client/billing/checkout.ts +11 -359
  112. package/src/client/billing/checkoutRequest.ts +362 -0
  113. package/src/client/billing/prepared-checkout.test.ts +430 -0
  114. package/src/client/billing/preparedCheckout.ts +143 -0
  115. package/src/client/checkoutRequests.ts +40 -0
  116. package/src/client/connect/payoutCollection.test.ts +74 -0
  117. package/src/client/connect/payoutCollection.ts +82 -0
  118. package/src/client/connect/payoutExecution.test.ts +1 -211
  119. package/src/client/connect/payoutExecutionTestHelpers.ts +213 -0
  120. package/src/client/connect/payoutWorker.test.ts +145 -0
  121. package/src/client/connect/payoutWorker.ts +144 -0
  122. package/src/client/index.ts +10 -21
  123. package/src/client/payoutPolicy.ts +26 -1
  124. package/src/client/readContracts.ts +23 -0
  125. package/src/component/_generated/api.ts +16 -0
  126. package/src/component/_generated/component.ts +361 -0
  127. package/src/component/core/mutations.ts +2 -0
  128. package/src/component/core/resetSafety.ts +67 -0
  129. package/src/component/earnings/triggers.ts +2 -0
  130. package/src/component/payout-reset-safety.test.ts +148 -0
  131. package/src/component/payout-revisions.test.ts +125 -0
  132. package/src/component/payout-snapshots.test.ts +395 -0
  133. package/src/component/payout-worker.test.ts +165 -0
  134. package/src/component/payoutPolicy/schema.ts +3 -1
  135. package/src/component/payoutRelease/mutations.ts +1 -1
  136. package/src/component/payoutRelease/schema.ts +1 -0
  137. package/src/component/payoutSnapshots/localState.ts +238 -0
  138. package/src/component/payoutSnapshots/mutations.ts +275 -0
  139. package/src/component/payoutSnapshots/revisions.ts +247 -0
  140. package/src/component/payoutSnapshots/schema.ts +125 -0
  141. package/src/component/payoutSnapshots/scope.ts +7 -0
  142. package/src/component/payoutWorker/helpers.ts +30 -0
  143. package/src/component/payoutWorker/mutations.ts +181 -0
  144. package/src/component/payoutWorker/queries.ts +64 -0
  145. package/src/component/payoutWorker/schema.ts +26 -0
  146. package/src/component/public.test.ts +2 -2
  147. package/src/component/schema.ts +18 -0
@@ -1,4 +1,233 @@
1
1
  declare const _default: import("convex/server").SchemaDefinition<{
2
+ payoutWorkerJobs: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
+ accountId: string;
4
+ cadenceMs: number;
5
+ completedGeneration?: number | undefined;
6
+ completedOperationKey?: string | undefined;
7
+ currency: string;
8
+ generation: number;
9
+ hasOperation: boolean;
10
+ lastAttemptAt?: number | undefined;
11
+ lastReason?: string | undefined;
12
+ leaseUntil?: number | undefined;
13
+ nextAttemptAt: number;
14
+ operationKey?: string | undefined;
15
+ ownerKey: string;
16
+ sequence: number;
17
+ }, {
18
+ accountId: import("convex/values").VString<string, "required">;
19
+ ownerKey: import("convex/values").VString<string, "required">;
20
+ currency: import("convex/values").VString<string, "required">;
21
+ generation: import("convex/values").VFloat64<number, "required">;
22
+ sequence: import("convex/values").VFloat64<number, "required">;
23
+ cadenceMs: import("convex/values").VFloat64<number, "required">;
24
+ nextAttemptAt: import("convex/values").VFloat64<number, "required">;
25
+ leaseUntil: import("convex/values").VFloat64<number | undefined, "optional">;
26
+ operationKey: import("convex/values").VString<string | undefined, "optional">;
27
+ hasOperation: import("convex/values").VBoolean<boolean, "required">;
28
+ lastReason: import("convex/values").VString<string | undefined, "optional">;
29
+ lastAttemptAt: import("convex/values").VFloat64<number | undefined, "optional">;
30
+ completedGeneration: import("convex/values").VFloat64<number | undefined, "optional">;
31
+ completedOperationKey: import("convex/values").VString<string | undefined, "optional">;
32
+ }, "required", "accountId" | "cadenceMs" | "completedGeneration" | "completedOperationKey" | "currency" | "generation" | "hasOperation" | "lastAttemptAt" | "lastReason" | "leaseUntil" | "nextAttemptAt" | "operationKey" | "ownerKey" | "sequence">, {
33
+ by_account_currency: ["accountId", "currency", "_creationTime"];
34
+ by_operation_pending: ["hasOperation", "nextAttemptAt", "_creationTime"];
35
+ }, {}, {}>;
36
+ payoutFinancialRevisions: import("convex/server").TableDefinition<import("convex/values").VObject<{
37
+ accountId: string;
38
+ revision: number;
39
+ riskRevision: number;
40
+ }, {
41
+ accountId: import("convex/values").VString<string, "required">;
42
+ revision: import("convex/values").VFloat64<number, "required">;
43
+ riskRevision: import("convex/values").VFloat64<number, "required">;
44
+ }, "required", "accountId" | "revision" | "riskRevision">, {
45
+ by_account: ["accountId", "_creationTime"];
46
+ }, {}, {}>;
47
+ payoutRiskEvents: import("convex/server").TableDefinition<import("convex/values").VObject<{
48
+ accountId: string;
49
+ key: string;
50
+ kind: "allocation" | "claim" | "fee" | "provider_payout" | "transfer";
51
+ removed?: boolean | undefined;
52
+ riskRevision: number;
53
+ }, {
54
+ accountId: import("convex/values").VString<string, "required">;
55
+ riskRevision: import("convex/values").VFloat64<number, "required">;
56
+ kind: import("convex/values").VUnion<"allocation" | "claim" | "fee" | "provider_payout" | "transfer", [import("convex/values").VLiteral<"transfer", "required">, import("convex/values").VLiteral<"provider_payout", "required">, import("convex/values").VLiteral<"allocation", "required">, import("convex/values").VLiteral<"claim", "required">, import("convex/values").VLiteral<"fee", "required">], "required", never>;
57
+ key: import("convex/values").VString<string, "required">;
58
+ removed: import("convex/values").VBoolean<boolean | undefined, "optional">;
59
+ }, "required", "accountId" | "key" | "kind" | "removed" | "riskRevision">, {
60
+ by_account_revision: ["accountId", "riskRevision", "_creationTime"];
61
+ }, {}, {}>;
62
+ payoutRiskRevisions: import("convex/server").TableDefinition<import("convex/values").VObject<{
63
+ accountId: string;
64
+ riskRevision: number;
65
+ }, {
66
+ accountId: import("convex/values").VString<string, "required">;
67
+ riskRevision: import("convex/values").VFloat64<number, "required">;
68
+ }, "required", "accountId" | "riskRevision">, {
69
+ by_account: ["accountId", "_creationTime"];
70
+ }, {}, {}>;
71
+ payoutSnapshots: import("convex/server").TableDefinition<import("convex/values").VObject<{
72
+ accountId: string;
73
+ allocationCount: number;
74
+ allocationCursor?: string | undefined;
75
+ claimCount: number;
76
+ claimCursor?: string | undefined;
77
+ deferredPositiveChanges: boolean;
78
+ expectedRevision: number;
79
+ expiresAt: number;
80
+ feeCount: number;
81
+ feeCursor?: string | undefined;
82
+ initialRevision: number;
83
+ initialRiskRevision: number;
84
+ observedRevision: number;
85
+ operationKey: string;
86
+ ownerKey: string;
87
+ phase: "allocations" | "check" | "claims" | "discarding" | "fees" | "invalidated" | "local_ready" | "repair" | "sources";
88
+ policyMode?: string | undefined;
89
+ policyOperationKey?: string | undefined;
90
+ providerChanged: boolean;
91
+ readOnly: boolean;
92
+ reason?: string | undefined;
93
+ riskRevision: number;
94
+ sourceCount: number;
95
+ sourceCursor?: string | undefined;
96
+ sourceFence: number;
97
+ step: number;
98
+ }, {
99
+ readOnly: import("convex/values").VBoolean<boolean, "required">;
100
+ accountId: import("convex/values").VString<string, "required">;
101
+ ownerKey: import("convex/values").VString<string, "required">;
102
+ operationKey: import("convex/values").VString<string, "required">;
103
+ expectedRevision: import("convex/values").VFloat64<number, "required">;
104
+ policyMode: import("convex/values").VString<string | undefined, "optional">;
105
+ policyOperationKey: import("convex/values").VString<string | undefined, "optional">;
106
+ phase: import("convex/values").VUnion<"allocations" | "check" | "claims" | "discarding" | "fees" | "invalidated" | "local_ready" | "repair" | "sources", [import("convex/values").VLiteral<"sources", "required">, import("convex/values").VLiteral<"allocations", "required">, import("convex/values").VLiteral<"fees", "required">, import("convex/values").VLiteral<"claims", "required">, import("convex/values").VLiteral<"repair", "required">, import("convex/values").VLiteral<"check", "required">, import("convex/values").VLiteral<"local_ready", "required">, import("convex/values").VLiteral<"invalidated", "required">, import("convex/values").VLiteral<"discarding", "required">], "required", never>;
107
+ step: import("convex/values").VFloat64<number, "required">;
108
+ sourceFence: import("convex/values").VFloat64<number, "required">;
109
+ sourceCursor: import("convex/values").VString<string | undefined, "optional">;
110
+ allocationCursor: import("convex/values").VString<string | undefined, "optional">;
111
+ feeCursor: import("convex/values").VString<string | undefined, "optional">;
112
+ claimCursor: import("convex/values").VString<string | undefined, "optional">;
113
+ initialRevision: import("convex/values").VFloat64<number, "required">;
114
+ initialRiskRevision: import("convex/values").VFloat64<number, "required">;
115
+ riskRevision: import("convex/values").VFloat64<number, "required">;
116
+ observedRevision: import("convex/values").VFloat64<number, "required">;
117
+ sourceCount: import("convex/values").VFloat64<number, "required">;
118
+ allocationCount: import("convex/values").VFloat64<number, "required">;
119
+ claimCount: import("convex/values").VFloat64<number, "required">;
120
+ feeCount: import("convex/values").VFloat64<number, "required">;
121
+ deferredPositiveChanges: import("convex/values").VBoolean<boolean, "required">;
122
+ providerChanged: import("convex/values").VBoolean<boolean, "required">;
123
+ expiresAt: import("convex/values").VFloat64<number, "required">;
124
+ reason: import("convex/values").VString<string | undefined, "optional">;
125
+ }, "required", "accountId" | "allocationCount" | "allocationCursor" | "claimCount" | "claimCursor" | "deferredPositiveChanges" | "expectedRevision" | "expiresAt" | "feeCount" | "feeCursor" | "initialRevision" | "initialRiskRevision" | "observedRevision" | "operationKey" | "ownerKey" | "phase" | "policyMode" | "policyOperationKey" | "providerChanged" | "readOnly" | "reason" | "riskRevision" | "sourceCount" | "sourceCursor" | "sourceFence" | "step">, {
126
+ by_account_phase: ["accountId", "phase", "_creationTime"];
127
+ by_operation: ["operationKey", "_creationTime"];
128
+ by_read_only: ["readOnly", "_creationTime"];
129
+ }, {}, {}>;
130
+ payoutSnapshotSources: import("convex/server").TableDefinition<import("convex/values").VObject<{
131
+ allocationCurrency?: string | undefined;
132
+ allocationPresent: boolean;
133
+ amount: number;
134
+ currency: string;
135
+ expectedPaid: number;
136
+ expectedReserved: number;
137
+ ledgerFingerprint: string;
138
+ needsCheck: boolean;
139
+ paidAmount: number;
140
+ reinstatement: boolean;
141
+ reservedAmount: number;
142
+ reversalClaimedAmount: number;
143
+ reversedAmount: number;
144
+ role?: string | undefined;
145
+ snapshotId: import("convex/values").GenericId<"payoutSnapshots">;
146
+ sourceChargeId?: string | undefined;
147
+ sourceCreatedAt: number;
148
+ status: string;
149
+ stripeTransferId: string;
150
+ }, {
151
+ snapshotId: import("convex/values").VId<import("convex/values").GenericId<"payoutSnapshots">, "required">;
152
+ stripeTransferId: import("convex/values").VString<string, "required">;
153
+ ledgerFingerprint: import("convex/values").VString<string, "required">;
154
+ sourceCreatedAt: import("convex/values").VFloat64<number, "required">;
155
+ currency: import("convex/values").VString<string, "required">;
156
+ amount: import("convex/values").VFloat64<number, "required">;
157
+ status: import("convex/values").VString<string, "required">;
158
+ role: import("convex/values").VString<string | undefined, "optional">;
159
+ sourceChargeId: import("convex/values").VString<string | undefined, "optional">;
160
+ reversedAmount: import("convex/values").VFloat64<number, "required">;
161
+ reversalClaimedAmount: import("convex/values").VFloat64<number, "required">;
162
+ reinstatement: import("convex/values").VBoolean<boolean, "required">;
163
+ allocationPresent: import("convex/values").VBoolean<boolean, "required">;
164
+ allocationCurrency: import("convex/values").VString<string | undefined, "optional">;
165
+ paidAmount: import("convex/values").VFloat64<number, "required">;
166
+ reservedAmount: import("convex/values").VFloat64<number, "required">;
167
+ expectedPaid: import("convex/values").VFloat64<number, "required">;
168
+ expectedReserved: import("convex/values").VFloat64<number, "required">;
169
+ needsCheck: import("convex/values").VBoolean<boolean, "required">;
170
+ }, "required", "allocationCurrency" | "allocationPresent" | "amount" | "currency" | "expectedPaid" | "expectedReserved" | "ledgerFingerprint" | "needsCheck" | "paidAmount" | "reinstatement" | "reservedAmount" | "reversalClaimedAmount" | "reversedAmount" | "role" | "snapshotId" | "sourceChargeId" | "sourceCreatedAt" | "status" | "stripeTransferId">, {
171
+ by_snapshot: ["snapshotId", "_creationTime"];
172
+ by_snapshot_check: ["snapshotId", "needsCheck", "_creationTime"];
173
+ by_snapshot_transfer: ["snapshotId", "stripeTransferId", "_creationTime"];
174
+ }, {}, {}>;
175
+ payoutSnapshotClaims: import("convex/server").TableDefinition<import("convex/values").VObject<{
176
+ allocations: {
177
+ amount: number;
178
+ role?: string | undefined;
179
+ stripeTransferId: string;
180
+ }[];
181
+ amount: number;
182
+ currency: string;
183
+ fingerprint: string;
184
+ historical?: boolean | undefined;
185
+ operationKey: string;
186
+ providerFee?: number | undefined;
187
+ snapshotId: import("convex/values").GenericId<"payoutSnapshots">;
188
+ status: string;
189
+ stripePayoutId?: string | undefined;
190
+ }, {
191
+ snapshotId: import("convex/values").VId<import("convex/values").GenericId<"payoutSnapshots">, "required">;
192
+ operationKey: import("convex/values").VString<string, "required">;
193
+ fingerprint: import("convex/values").VString<string, "required">;
194
+ currency: import("convex/values").VString<string, "required">;
195
+ amount: import("convex/values").VFloat64<number, "required">;
196
+ status: import("convex/values").VString<string, "required">;
197
+ stripePayoutId: import("convex/values").VString<string | undefined, "optional">;
198
+ historical: import("convex/values").VBoolean<boolean | undefined, "optional">;
199
+ providerFee: import("convex/values").VFloat64<number | undefined, "optional">;
200
+ allocations: import("convex/values").VArray<{
201
+ amount: number;
202
+ role?: string | undefined;
203
+ stripeTransferId: string;
204
+ }[], import("convex/values").VObject<{
205
+ amount: number;
206
+ role?: string | undefined;
207
+ stripeTransferId: string;
208
+ }, {
209
+ stripeTransferId: import("convex/values").VString<string, "required">;
210
+ amount: import("convex/values").VFloat64<number, "required">;
211
+ role: import("convex/values").VString<string | undefined, "optional">;
212
+ }, "required", "amount" | "role" | "stripeTransferId">, "required">;
213
+ }, "required", "allocations" | "amount" | "currency" | "fingerprint" | "historical" | "operationKey" | "providerFee" | "snapshotId" | "status" | "stripePayoutId">, {
214
+ by_snapshot: ["snapshotId", "_creationTime"];
215
+ by_snapshot_operation: ["snapshotId", "operationKey", "_creationTime"];
216
+ }, {}, {}>;
217
+ payoutSnapshotFees: import("convex/server").TableDefinition<import("convex/values").VObject<{
218
+ amount: number;
219
+ currency: string;
220
+ revision: number;
221
+ snapshotId: import("convex/values").GenericId<"payoutSnapshots">;
222
+ }, {
223
+ snapshotId: import("convex/values").VId<import("convex/values").GenericId<"payoutSnapshots">, "required">;
224
+ currency: import("convex/values").VString<string, "required">;
225
+ amount: import("convex/values").VFloat64<number, "required">;
226
+ revision: import("convex/values").VFloat64<number, "required">;
227
+ }, "required", "amount" | "currency" | "revision" | "snapshotId">, {
228
+ by_snapshot: ["snapshotId", "_creationTime"];
229
+ by_snapshot_currency: ["snapshotId", "currency", "_creationTime"];
230
+ }, {}, {}>;
2
231
  affiliateObligations: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
232
  accounted?: boolean | undefined;
4
233
  activeOperationId?: import("convex/values").GenericId<"affiliateRecoveryOperations"> | undefined;
@@ -355,6 +584,7 @@ declare const _default: import("convex/server").SchemaDefinition<{
355
584
  by_provider_payout: ["stripePayoutId", "_creationTime"];
356
585
  by_rejection_request: ["rejection.requestId", "_creationTime"];
357
586
  by_return_receipt: ["returnTransactionId", "_creationTime"];
587
+ by_status: ["status", "_creationTime"];
358
588
  }, {}, {}>;
359
589
  payoutSourceAllocations: import("convex/server").TableDefinition<import("convex/values").VObject<{
360
590
  accountId: string;
@@ -423,6 +653,8 @@ declare const _default: import("convex/server").SchemaDefinition<{
423
653
  }, "required", "accountId" | "country" | "holdDeadline" | "mode" | "operationKey" | "ownerKey" | "previousSchedule" | "previousSchedule.interval" | "previousSchedule.monthlyDays" | "previousSchedule.weeklyDays" | "revision" | "status" | "thresholds">, {
424
654
  by_account: ["accountId", "_creationTime"];
425
655
  by_deadline: ["holdDeadline", "_creationTime"];
656
+ by_mode_status: ["mode", "status", "_creationTime"];
657
+ by_status: ["status", "_creationTime"];
426
658
  }, {}, {}>;
427
659
  payoutPolicyOperations: import("convex/server").TableDefinition<import("convex/values").VObject<{
428
660
  accountId: string;
@@ -1,3 +1,5 @@
1
+ import { jobsTable as payoutWorkerJobsTable } from "./payoutWorker/schema.js";
2
+ import { financialRevisionsTable, riskEventsTable, riskRevisionsTable, snapshotsTable, snapshotSourcesTable, snapshotClaimsTable, snapshotFeesTable, } from "./payoutSnapshots/schema.js";
1
3
  import { claimsTable as payoutSyncClaimsTable } from "./payoutSync/schema.js";
2
4
  import { payoutReleasesTable as affiliatePayoutReleases, operationsTable as affiliateOperations, earningsTable as affiliateEarnings, offsetsTable as affiliateOffsets, balancesTable as affiliateBalances, } from "./affiliateRecovery/schema.js";
3
5
  import { affiliateObligationsTable, affiliateReversalReceiptsTable, } from "./settlement/clawbackSchema.js";
@@ -13,6 +15,14 @@ import { accountsTable } from "./core/schema";
13
15
  import { pricesTable, productsTable } from "./products/schema";
14
16
  import { webhookEventsTable } from "./webhooks/schema";
15
17
  export default defineSchema({
18
+ payoutWorkerJobs: payoutWorkerJobsTable,
19
+ payoutFinancialRevisions: financialRevisionsTable,
20
+ payoutRiskEvents: riskEventsTable,
21
+ payoutRiskRevisions: riskRevisionsTable,
22
+ payoutSnapshots: snapshotsTable,
23
+ payoutSnapshotSources: snapshotSourcesTable,
24
+ payoutSnapshotClaims: snapshotClaimsTable,
25
+ payoutSnapshotFees: snapshotFeesTable,
16
26
  affiliateObligations: affiliateObligationsTable,
17
27
  affiliateRecoveryOperations: affiliateOperations,
18
28
  affiliatePayoutReleases,
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EACL,mBAAmB,IAAI,uBAAuB,EAC9C,eAAe,IAAI,mBAAmB,EACtC,aAAa,IAAI,iBAAiB,EAClC,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,GACnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,gBAAgB,IAAI,sBAAsB,EAC1C,WAAW,IAAI,wBAAwB,EACvC,YAAY,IAAI,4BAA4B,GAC7C,MAAM,2BAA2B,CAAC;AACnC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C,cAAc,EAAE,mBAAmB;IACnC,cAAc,EAAE,WAAW;IAC3B,gBAAgB,EAAE,aAAa;IAC/B,cAAc,EAAE,WAAW;IAC3B,oBAAoB,EAAE,iBAAiB;IACvC,qBAAqB,EAAE,gBAAgB;IACvC,eAAe,EAAE,oBAAoB;IACrC,mBAAmB,EAAE,wBAAwB;IAC7C,OAAO;IACP,QAAQ,EAAE,aAAa;IAEvB,WAAW;IACX,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;IAEnB,UAAU;IACV,aAAa,EAAE,kBAAkB;IACjC,gBAAgB,EAAE,qBAAqB;IACvC,QAAQ,EAAE,aAAa;IAEvB,UAAU;IACV,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,YAAY;IACrB,iBAAiB,EAAE,sBAAsB;IACzC,OAAO,EAAE,YAAY;IACrB,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,cAAc;IACzB,mBAAmB,EAAE,wBAAwB;IAE7C,WAAW;IACX,aAAa,EAAE,kBAAkB;CAClC,CAAC,CAAC"}
@@ -174,6 +174,54 @@ Host apps should translate known codes into safe recovery instructions and a
174
174
  settings link. Do not log or blindly render raw provider messages. Authorize
175
175
  reads using the recipient's shared connected account.
176
176
 
177
+ ## Prepared Checkout requests
178
+
179
+ Use `betterStripe.checkoutRequests.prepare(ctx, options)` when a host purchase
180
+ intent must bind the exact provider request before creation or a plan change's
181
+ cancellation. Preparation performs only reads. It never provisions an account,
182
+ creates a Checkout Session or cancels a subscription. If a buyer needs a V2
183
+ customer account, register the host intent first, provision through the existing
184
+ package account operation with a stable account identity, then prepare using the
185
+ verified account reference.
186
+
187
+ Preparation returns a serializable versioned snapshot containing the final
188
+ `request`, component correlation `row`, captured rendering `options`, descriptor
189
+ and generated routing metadata. Persist the entire snapshot in the host's owned
190
+ intent before any subsequent provider write. The snapshot includes account or
191
+ customer email, server metadata, quantity, trial behavior, nested overrides and
192
+ resolved fees. Its contents may contain private data; do not return the snapshot
193
+ to a browser or log it.
194
+
195
+ Call `betterStripe.checkoutRequests.execute(ctx, { prepared, idempotencyKey })`
196
+ with that persisted snapshot and a stable intent-derived key. Execution validates
197
+ its correlation and deterministic rendering against the captured context, then
198
+ sends the stored request unchanged. It does not resolve current fee or descriptor
199
+ defaults. Necessary platform-price checks may still read the provider. If a key
200
+ was explicitly included during preparation, execution must use the same key.
201
+ Retries reuse the exact request and preserve the existing Checkout response shape
202
+ and component upsert. Missing or conflicting keys and inconsistent snapshots
203
+ fail before creation.
204
+
205
+ The host must authorize the buyer and catalog, bind the complete snapshot and key
206
+ immutably, validate fresh session eligibility and own recovery. Consistency
207
+ validation is not a signature or a replacement for host authorization. Never
208
+ accept a browser-supplied snapshot. An unknown provider outcome remains unknown;
209
+ use authoritative provider reads and saved references rather than blindly
210
+ recreating after an idempotency retention window. This API does not record paid
211
+ facts, award attribution, grant access or cancel a current plan automatically.
212
+
213
+ For a plan change, authorize and register the intent, prepare and bind a request
214
+ with no new trial, then perform any authorized cancellation before executing the
215
+ persisted request. Preserve cancellation and creation recovery separately. A
216
+ failed or lost response does not establish successful cancellation or payment.
217
+
218
+ The original `createCheckoutSession` uses the same maintained renderer and
219
+ submission path and retains its existing behavior. The prepared contract adds
220
+ strict correlation checks for the buyer, account and price and preserves
221
+ server-owned metadata and package-generated routing markers. Application React
222
+ callbacks remain authenticated host adapters. The package's unstyled React
223
+ checkout workflow and Vite example can use these callbacks with application styles.
224
+
177
225
  ## Publication and consumer acceptance
178
226
 
179
227
  A source merge does not activate an API in a published package. DOJO-908,
@@ -533,4 +533,131 @@ shorten the pending operation's deadline. `migration_required.adoptionReason`
533
533
  explains unknown history or an expired holding period. This flow does not enable
534
534
  Dashboard accounts with withdrawal bypasses, Global Payouts, unsupported source
535
535
  rails, unknown numeric provider floors or accounts beyond the current atomic
536
- snapshot bounds. It installs no host cron or UI.
536
+ snapshot bounds. Activation itself does not install a host cron or UI.
537
+
538
+ ## Automatic recipient worker
539
+
540
+ `stripe.payoutPolicy.worker` runs authorized custom policies from a host cron.
541
+ It invokes the maintained release and reconciliation APIs, including their live
542
+ schedule, source-maturity, history, fee and balance checks. A worker lease never
543
+ replaces the financial payout claim.
544
+
545
+ ```ts
546
+ const result = await stripe.payoutPolicy.worker.run(ctx, {
547
+ accountId,
548
+ ownerKey,
549
+ currency,
550
+ // Resolve all off-provider debts and reserves for this owner/currency first.
551
+ // Do not count Stripe receipt debits twice.
552
+ independentLiabilities,
553
+ cadenceMs: 300_000,
554
+ });
555
+ const job = await stripe.payoutPolicy.worker.get(ctx, {
556
+ accountId,
557
+ ownerKey,
558
+ currency,
559
+ });
560
+ // job.nextAttemptAt is the next application attempt, not a bank arrival date.
561
+ ```
562
+
563
+ The default retry cadence is five minutes; hosts can configure one minute to
564
+ one day. Concurrent callers share a ten-minute lease. A crashed worker resumes
565
+ the same operation ID. Unknown provider outcomes retain their attempted claim
566
+ and reconcile on later runs, including after a recipient opts out. They never
567
+ trigger a blind payout recreation. Expired worker leases permit observation
568
+ retries; they do not release monetary reservations. A generation check prevents
569
+ an older worker from replacing a newer worker's result. Completion replays keep
570
+ the original next attempt time.
571
+
572
+ Affiliate clawback debt, pending recoveries/restorations and competing affiliate
573
+ payout reservations hold fresh worker attempts with `affiliate_recovery_pending`.
574
+ The recipient claim boundary checks the same recovery lock again atomically
575
+ before reservation and immediately before the provider attempt. Existing unknown
576
+ attempts continue to reconcile even when new recovery debt arrives. Do not add
577
+ the same affiliate debt to `independentLiabilities` again; that option is for
578
+ separate host liabilities.
579
+
580
+ The host must page all four queues, using bounded pages and scheduling each
581
+ recipient/currency independently:
582
+
583
+ - `worker.policies(ctx, paginationOpts)` discovers ready custom policies.
584
+ - `worker.recovering(ctx, paginationOpts)` discovers retained operations,
585
+ including recipients who switched back to Stripe-managed payouts.
586
+ - `worker.changing(ctx, paginationOpts)` discovers pending schedule operations
587
+ to retry through `payoutPolicy.apply`.
588
+ - `payoutPolicy.due(ctx, paginationOpts)` discovers expired holding deadlines
589
+ to restore through `payoutPolicy.expire`.
590
+
591
+ Authorize the host's owner/account mapping before each action. Read outstanding
592
+ liabilities again before every attempt. In the example, uncollected seller cost
593
+ reservations remain withheld even while attached to an unpaid invoice. Confirmed
594
+ collections are already reflected in the store's transferred amount. Additional
595
+ host liability scopes must be included when adopting this worker in another app.
596
+
597
+ The example's `convex/crons.ts` installs a five-minute dispatcher. Its internal
598
+ actions in `convex/payoutWorkers.ts` page these queues and use the package APIs;
599
+ they do not call the Stripe SDK directly. Stripe-managed recipients continue to
600
+ use Stripe's automatic schedule. Custom activation still requires explicit
601
+ consent and verified exclusive payout control. The worker preserves the current
602
+ release/adoption history limits and reports held results when those limits are
603
+ exceeded. It does not yet consume the resumable local manifest described below.
604
+
605
+ These are server worker APIs, not manual withdrawal actions for a customer UI.
606
+ `worker.get` exposes the latest reason, attempt time and next application attempt
607
+ for an authorized host to display. Bank availability, pending funds and bank
608
+ arrival dates come from the recipient payout snapshot API.
609
+
610
+ ## Resumable local collections
611
+
612
+ An authorized host worker can collect the local recipient ledger in bounded
613
+ steps, retaining its cursor and step number across restarts:
614
+
615
+ ```ts
616
+ let state = await stripe.payoutPolicy.collectSnapshot(ctx, {
617
+ accountId,
618
+ ownerKey,
619
+ operationKey: collectionKey,
620
+ expectedRevision: policy?.revision ?? -1,
621
+ });
622
+ state = await stripe.payoutPolicy.collectSnapshot(ctx, {
623
+ accountId,
624
+ ownerKey,
625
+ operationKey: collectionKey,
626
+ expectedRevision: policy?.revision ?? -1,
627
+ expectedStep: state.step,
628
+ batchSize: 25,
629
+ });
630
+ ```
631
+
632
+ Repeat bounded calls until `phase` reaches `local_ready` or `invalidated`.
633
+ Duplicate step submissions preserve cursor progress. Sources, source allocations,
634
+ payout fees and payout claims are copied across pages, with no 100-row limit on the local
635
+ collection. New positive funding can be deferred to a later collection; refunds,
636
+ reservations, payouts and fees enter an ordered account risk journal. The worker
637
+ repairs changed entries and checks claim/source allocation rollups before local
638
+ completion. Missing journal events, orphaned sources and changed policy identity
639
+ stop collection with an explicit reason.
640
+
641
+ `local_ready` describes a read-only local manifest. Complete provider receipts,
642
+ provider history and monetary claim binding are still required before a payout.
643
+ These local APIs do not remove the current bounded release/adoption limits by
644
+ themselves. Provider-history continuation and scalable claim execution remain
645
+ under implementation.
646
+
647
+ After a read-only collection is no longer needed, repeatedly call
648
+ `discardSnapshot(ctx, { accountId, ownerKey, operationKey: collectionKey })` until
649
+ it returns `null`. Cleanup removes only collection caches. Read-only collection
650
+ leases last 24 hours. Financially bound collections reject read-only cleanup and
651
+ expiry; payout claims and their source reservations keep their own lifecycle.
652
+
653
+ ### Development reset safeguards
654
+
655
+ `clearAllTables` is a development/test utility. It rejects active or changing
656
+ payout schedules, unresolved reserved/submitted claims, financially bound
657
+ collections and known pending/in-transit provider payouts. The host must quiesce
658
+ provider writers and verify live provider state before invoking reset. Restore
659
+ schedules through the policy APIs and reconcile unresolved operations first.
660
+ Pending or unknown direct affiliate payouts and recovery operations also block
661
+ reset, preserving the receipts and obligations needed for reconciliation.
662
+ The guard preserves the restoration and payout records until that work is done.
663
+ Read-only cache collections can be cleared with the other development data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantastic.dev/better-stripe",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "A Convex component for Stripe V2 Accounts API integration.",
5
5
  "keywords": [
6
6
  "stripe",