@fantastic.dev/better-stripe 0.29.0 → 0.30.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.
- package/CHANGELOG.md +10 -0
- package/MIGRATION.md +8 -0
- package/README.md +3 -1
- package/dist/client/connect/payoutActivationProof.d.ts.map +1 -1
- package/dist/client/connect/payoutActivationProof.js +88 -42
- package/dist/client/connect/payoutActivationProof.js.map +1 -1
- package/dist/client/connect/payoutAdoption.d.ts +3 -0
- package/dist/client/connect/payoutAdoption.d.ts.map +1 -1
- package/dist/client/connect/payoutAdoption.js +218 -183
- package/dist/client/connect/payoutAdoption.js.map +1 -1
- package/dist/client/connect/payoutAdoptionCollection.d.ts +21 -0
- package/dist/client/connect/payoutAdoptionCollection.d.ts.map +1 -0
- package/dist/client/connect/payoutAdoptionCollection.js +44 -0
- package/dist/client/connect/payoutAdoptionCollection.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +26 -6
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +13 -3
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +3745 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.js +55 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.js.map +1 -0
- package/dist/client/connect/payoutOutcomeBatches.d.ts +5 -0
- package/dist/client/connect/payoutOutcomeBatches.d.ts.map +1 -0
- package/dist/client/connect/payoutOutcomeBatches.js +21 -0
- package/dist/client/connect/payoutOutcomeBatches.js.map +1 -0
- package/dist/client/connect/payoutPolicyState.d.ts +14 -0
- package/dist/client/connect/payoutPolicyState.d.ts.map +1 -0
- package/dist/client/connect/payoutPolicyState.js +19 -0
- package/dist/client/connect/payoutPolicyState.js.map +1 -0
- package/dist/client/connect/payoutQualification.js +1 -1
- package/dist/client/connect/payoutQualification.js.map +1 -1
- package/dist/client/connect/payoutReconciliation.d.ts +11 -6
- package/dist/client/connect/payoutReconciliation.d.ts.map +1 -1
- package/dist/client/connect/payoutReconciliation.js +62 -16
- package/dist/client/connect/payoutReconciliation.js.map +1 -1
- package/dist/client/connect/payoutResumableProof.d.ts +17 -0
- package/dist/client/connect/payoutResumableProof.d.ts.map +1 -0
- package/dist/client/connect/payoutResumableProof.js +25 -0
- package/dist/client/connect/payoutResumableProof.js.map +1 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +13 -3
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/transferReceipt.d.ts +6 -2
- package/dist/client/connect/transferReceipt.d.ts.map +1 -1
- package/dist/client/connect/transferReceipt.js +3 -3
- package/dist/client/connect/transferReceipt.js.map +1 -1
- package/dist/client/payoutPolicy.d.ts.map +1 -1
- package/dist/client/payoutPolicy.js +24 -14
- package/dist/client/payoutPolicy.js.map +1 -1
- package/dist/component/_generated/component.d.ts +72 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/earnings/triggers.d.ts +12 -4
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutPolicy/adoption.d.ts.map +1 -1
- package/dist/component/payoutPolicy/adoption.js +12 -7
- package/dist/component/payoutPolicy/adoption.js.map +1 -1
- package/dist/component/payoutPolicy/mutations.d.ts +12 -0
- package/dist/component/payoutPolicy/mutations.d.ts.map +1 -1
- package/dist/component/payoutPolicy/queries.d.ts +2 -0
- package/dist/component/payoutPolicy/queries.d.ts.map +1 -1
- package/dist/component/payoutPolicy/schema.d.ts +31 -7
- package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
- package/dist/component/payoutPolicy/schema.js +2 -0
- package/dist/component/payoutPolicy/schema.js.map +1 -1
- package/dist/component/payoutRelease/adoption.d.ts +3 -1
- package/dist/component/payoutRelease/adoption.d.ts.map +1 -1
- package/dist/component/payoutRelease/adoption.js +33 -16
- package/dist/component/payoutRelease/adoption.js.map +1 -1
- package/dist/component/payoutRelease/fees.d.ts.map +1 -1
- package/dist/component/payoutRelease/fees.js +7 -0
- package/dist/component/payoutRelease/fees.js.map +1 -1
- package/dist/component/payoutRelease/mutations.d.ts +59 -0
- package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
- package/dist/component/payoutRelease/mutations.js +25 -80
- package/dist/component/payoutRelease/mutations.js.map +1 -1
- package/dist/component/payoutRelease/outcome.d.ts +69 -0
- package/dist/component/payoutRelease/outcome.d.ts.map +1 -0
- package/dist/component/payoutRelease/outcome.js +94 -0
- package/dist/component/payoutRelease/outcome.js.map +1 -0
- package/dist/component/payoutRelease/planning.d.ts.map +1 -1
- package/dist/component/payoutRelease/planning.js +5 -2
- package/dist/component/payoutRelease/planning.js.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.js +2 -0
- package/dist/component/payoutRelease/queries.js.map +1 -1
- package/dist/component/payoutSnapshots/adoption.d.ts +88 -0
- package/dist/component/payoutSnapshots/adoption.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/adoption.js +49 -0
- package/dist/component/payoutSnapshots/adoption.js.map +1 -0
- package/dist/component/payoutSnapshots/financial.d.ts +31 -19
- package/dist/component/payoutSnapshots/financial.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/financial.js +28 -14
- package/dist/component/payoutSnapshots/financial.js.map +1 -1
- package/dist/component/payoutSnapshots/localState.d.ts +20 -16
- package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/localState.js +13 -4
- package/dist/component/payoutSnapshots/localState.js.map +1 -1
- package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/mutations.js +1 -1
- package/dist/component/payoutSnapshots/mutations.js.map +1 -1
- package/dist/component/payoutSnapshots/queries.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/queries.js +6 -4
- package/dist/component/payoutSnapshots/queries.js.map +1 -1
- package/dist/component/payoutSnapshots/schema.d.ts +5 -1
- package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/schema.js +2 -0
- package/dist/component/payoutSnapshots/schema.js.map +1 -1
- package/dist/component/schema.d.ts +13 -3
- package/docs/settlement.md +61 -8
- package/package.json +1 -1
- package/src/client/connect/payoutActivationProof.ts +123 -53
- package/src/client/connect/payoutAdoption.ts +299 -215
- package/src/client/connect/payoutAdoptionCollection.ts +78 -0
- package/src/client/connect/payoutAdoptionConcurrency.test.ts +266 -0
- package/src/client/connect/payoutCacheIdentity.test.ts +93 -0
- package/src/client/connect/payoutLargeAdoption.test.ts +541 -0
- package/src/client/connect/payoutLargeAdoptionTestHelpers.ts +74 -0
- package/src/client/connect/payoutOutcomeBatches.test.ts +40 -0
- package/src/client/connect/payoutOutcomeBatches.ts +24 -0
- package/src/client/connect/payoutPolicyState.ts +36 -0
- package/src/client/connect/payoutQualification.ts +10 -4
- package/src/client/connect/payoutReconciliation.ts +86 -7
- package/src/client/connect/payoutResumableProof.ts +41 -0
- package/src/client/connect/transferReceipt.ts +3 -2
- package/src/client/connect/transferReceiptBaseline.test.ts +55 -0
- package/src/client/payoutPolicy.ts +37 -23
- package/src/component/_generated/api.ts +4 -0
- package/src/component/_generated/component.ts +85 -0
- package/src/component/payout-snapshots.test.ts +45 -1
- package/src/component/payoutPolicy/adoption.ts +20 -7
- package/src/component/payoutPolicy/schema.ts +2 -0
- package/src/component/payoutRelease/adoption.ts +57 -27
- package/src/component/payoutRelease/fees.ts +9 -0
- package/src/component/payoutRelease/mutations.ts +26 -96
- package/src/component/payoutRelease/outcome.ts +119 -0
- package/src/component/payoutRelease/planning.ts +5 -2
- package/src/component/payoutRelease/queries.ts +2 -0
- package/src/component/payoutSnapshots/adoption.ts +73 -0
- package/src/component/payoutSnapshots/financial.ts +33 -20
- package/src/component/payoutSnapshots/localState.ts +17 -3
- package/src/component/payoutSnapshots/mutations.ts +8 -1
- package/src/component/payoutSnapshots/queries.ts +8 -6
- package/src/component/payoutSnapshots/schema.ts +2 -0
|
@@ -44,23 +44,29 @@ export async function collectedSources(
|
|
|
44
44
|
new Set(observations.map((o) => o.stripeTransferId)).size !== h.sourceCount
|
|
45
45
|
)
|
|
46
46
|
throw new Error("Financial payout collection membership is incomplete.");
|
|
47
|
+
const cachedRows = await ctx.db
|
|
48
|
+
.query("payoutSnapshotSources")
|
|
49
|
+
.withIndex("by_snapshot", (q) => q.eq("snapshotId", h._id))
|
|
50
|
+
.take(h.sourceCount + 1);
|
|
51
|
+
const byId = new Map(cachedRows.map((row) => [row.stripeTransferId, row]));
|
|
52
|
+
if (cachedRows.length !== h.sourceCount || byId.size !== h.sourceCount)
|
|
53
|
+
throw new Error("Financial payout collection membership is incomplete.");
|
|
47
54
|
const rows = new Map<string, Doc<"transfers">>();
|
|
55
|
+
const allocations = new Map<string, Doc<"payoutSourceAllocations"> | null>();
|
|
48
56
|
for (const o of observations) {
|
|
49
|
-
const cached =
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
q.eq("stripeTransferId", o.stripeTransferId),
|
|
59
|
-
)
|
|
60
|
-
.unique();
|
|
57
|
+
const cached = byId.get(o.stripeTransferId);
|
|
58
|
+
const row = cached?.transferDocId
|
|
59
|
+
? await ctx.db.get("transfers", cached.transferDocId)
|
|
60
|
+
: await ctx.db
|
|
61
|
+
.query("transfers")
|
|
62
|
+
.withIndex("by_stripe_transfer_id", (q) =>
|
|
63
|
+
q.eq("stripeTransferId", o.stripeTransferId),
|
|
64
|
+
)
|
|
65
|
+
.unique();
|
|
61
66
|
if (
|
|
62
67
|
!cached ||
|
|
63
68
|
!row ||
|
|
69
|
+
row.stripeTransferId !== o.stripeTransferId ||
|
|
64
70
|
cached.needsCheck ||
|
|
65
71
|
cached.ledgerFingerprint !== o.ledgerFingerprint ||
|
|
66
72
|
cached.expectedPaid !== cached.paidAmount ||
|
|
@@ -68,25 +74,32 @@ export async function collectedSources(
|
|
|
68
74
|
)
|
|
69
75
|
throw new Error("Financial payout collection source changed.");
|
|
70
76
|
if (h.readOnly) {
|
|
71
|
-
const
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
+
const knownAllocation = cached.allocationDocId
|
|
78
|
+
? await ctx.db.get("payoutSourceAllocations", cached.allocationDocId)
|
|
79
|
+
: null;
|
|
80
|
+
const allocation =
|
|
81
|
+
knownAllocation ??
|
|
82
|
+
(await ctx.db
|
|
83
|
+
.query("payoutSourceAllocations")
|
|
84
|
+
.withIndex("by_transfer", (q) =>
|
|
85
|
+
q.eq("stripeTransferId", o.stripeTransferId),
|
|
86
|
+
)
|
|
87
|
+
.unique());
|
|
77
88
|
if (
|
|
78
89
|
(allocation?.paidAmount ?? 0) !== cached.paidAmount ||
|
|
79
90
|
(allocation?.reservedAmount ?? 0) !== cached.reservedAmount ||
|
|
80
91
|
(allocation &&
|
|
81
|
-
(allocation.
|
|
92
|
+
(allocation.stripeTransferId !== o.stripeTransferId ||
|
|
93
|
+
allocation.accountId !== scope.accountId ||
|
|
82
94
|
allocation.ownerKey !== scope.ownerKey ||
|
|
83
95
|
allocation.currency !== o.currency))
|
|
84
96
|
)
|
|
85
97
|
throw new Error("Financial payout collection allocation changed.");
|
|
98
|
+
allocations.set(o.stripeTransferId, allocation);
|
|
86
99
|
}
|
|
87
100
|
rows.set(o.stripeTransferId, row);
|
|
88
101
|
}
|
|
89
|
-
return rows;
|
|
102
|
+
return { transfers: rows, allocations };
|
|
90
103
|
}
|
|
91
104
|
export async function bindCollection(
|
|
92
105
|
ctx: MutationCtx,
|
|
@@ -53,9 +53,14 @@ export async function cacheSource(
|
|
|
53
53
|
id: string,
|
|
54
54
|
counts: Counts,
|
|
55
55
|
provided?: Doc<"transfers">,
|
|
56
|
+
providedAllocation?: Doc<"payoutSourceAllocations">,
|
|
56
57
|
) {
|
|
58
|
+
const old = await sourceCache(ctx, h, id);
|
|
57
59
|
const row =
|
|
58
60
|
provided ??
|
|
61
|
+
(old?.transferDocId
|
|
62
|
+
? await ctx.db.get("transfers", old.transferDocId)
|
|
63
|
+
: null) ??
|
|
59
64
|
(await ctx.db
|
|
60
65
|
.query("transfers")
|
|
61
66
|
.withIndex("by_stripe_transfer_id", (q) => q.eq("stripeTransferId", id))
|
|
@@ -67,17 +72,20 @@ export async function cacheSource(
|
|
|
67
72
|
amount(row.amount);
|
|
68
73
|
amount(row.reversedAmount ?? 0);
|
|
69
74
|
amount(row.reversalClaimedAmount ?? 0);
|
|
70
|
-
const allocated = await sourceById(ctx, id);
|
|
75
|
+
const allocated = providedAllocation ?? (await sourceById(ctx, id));
|
|
71
76
|
if (
|
|
72
77
|
allocated &&
|
|
73
|
-
(allocated.
|
|
78
|
+
(allocated.stripeTransferId !== id ||
|
|
79
|
+
allocated.accountId !== h.accountId ||
|
|
80
|
+
allocated.ownerKey !== h.ownerKey)
|
|
74
81
|
)
|
|
75
82
|
throw new CollectionError("allocation_identity_changed");
|
|
76
|
-
const old = await sourceCache(ctx, h, id);
|
|
77
83
|
const allocationPresent = allocated !== null;
|
|
78
84
|
const fields = {
|
|
79
85
|
stripeTransferId: id,
|
|
80
86
|
ledgerFingerprint: transferFingerprint(row),
|
|
87
|
+
transferDocId: row._id,
|
|
88
|
+
allocationDocId: allocated?._id,
|
|
81
89
|
sourceCreatedAt: row._creationTime,
|
|
82
90
|
currency: row.currency,
|
|
83
91
|
amount: row.amount,
|
|
@@ -98,6 +106,12 @@ export async function cacheSource(
|
|
|
98
106
|
throw new CollectionError("allocation_removed");
|
|
99
107
|
if (!old.allocationPresent && allocationPresent)
|
|
100
108
|
counts.allocationCount = add(counts.allocationCount, 1);
|
|
109
|
+
if (
|
|
110
|
+
Object.entries(fields).every(
|
|
111
|
+
([key, value]) => old[key as keyof typeof fields] === value,
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
return old;
|
|
101
115
|
await ctx.db.patch("payoutSnapshotSources", old._id, fields);
|
|
102
116
|
return { ...old, ...fields };
|
|
103
117
|
}
|
|
@@ -139,7 +139,14 @@ export const advance = mutation({
|
|
|
139
139
|
.withIndex("by_account", (q) => q.eq("accountId", h!.accountId))
|
|
140
140
|
.paginate({ cursor: h.allocationCursor ?? null, numItems: batch });
|
|
141
141
|
for (const row of page.page)
|
|
142
|
-
await cacheSource(
|
|
142
|
+
await cacheSource(
|
|
143
|
+
ctx,
|
|
144
|
+
h,
|
|
145
|
+
row.stripeTransferId,
|
|
146
|
+
counts,
|
|
147
|
+
undefined,
|
|
148
|
+
row,
|
|
149
|
+
);
|
|
143
150
|
patch.allocationCursor = page.continueCursor;
|
|
144
151
|
patch.phase = page.isDone ? "fees" : "allocations";
|
|
145
152
|
} else if (h.phase === "fees") {
|
|
@@ -47,12 +47,14 @@ export const sources = query({
|
|
|
47
47
|
.paginate(args.paginationOpts);
|
|
48
48
|
const rows = [];
|
|
49
49
|
for (const cached of page.page) {
|
|
50
|
-
const row =
|
|
51
|
-
.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const row = cached.transferDocId
|
|
51
|
+
? await ctx.db.get("transfers", cached.transferDocId)
|
|
52
|
+
: await ctx.db
|
|
53
|
+
.query("transfers")
|
|
54
|
+
.withIndex("by_stripe_transfer_id", (q) =>
|
|
55
|
+
q.eq("stripeTransferId", cached.stripeTransferId),
|
|
56
|
+
)
|
|
57
|
+
.unique();
|
|
56
58
|
if (!row || transferFingerprint(row) !== cached.ledgerFingerprint)
|
|
57
59
|
throw new Error("Payout collection source changed.");
|
|
58
60
|
rows.push(row);
|
|
@@ -74,6 +74,8 @@ export const snapshotSourcesTable = defineTable({
|
|
|
74
74
|
snapshotId: v.id("payoutSnapshots"),
|
|
75
75
|
stripeTransferId: v.string(),
|
|
76
76
|
ledgerFingerprint: v.string(),
|
|
77
|
+
transferDocId: v.optional(v.id("transfers")),
|
|
78
|
+
allocationDocId: v.optional(v.id("payoutSourceAllocations")),
|
|
77
79
|
sourceCreatedAt: v.number(),
|
|
78
80
|
currency: v.string(),
|
|
79
81
|
amount: v.number(),
|