@fantastic.dev/better-stripe 0.60.0 → 0.60.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.
- package/CHANGELOG.md +6 -0
- package/README.md +3 -1
- 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 +26 -6
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +13 -3
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/usage/creditCapacity.d.ts.map +1 -1
- package/dist/client/usage/creditCapacity.js +7 -1
- package/dist/client/usage/creditCapacity.js.map +1 -1
- package/dist/client/usage/creditClient.d.ts +3 -0
- package/dist/client/usage/creditClient.d.ts.map +1 -1
- package/dist/client/usage/creditDelivery.d.ts.map +1 -1
- package/dist/client/usage/creditDelivery.js +4 -1
- package/dist/client/usage/creditDelivery.js.map +1 -1
- package/dist/client/usage/creditLifecycle.d.ts.map +1 -1
- package/dist/client/usage/creditLifecycle.js +2 -1
- package/dist/client/usage/creditLifecycle.js.map +1 -1
- package/dist/client/usage/creditNative.d.ts +3 -0
- package/dist/client/usage/creditNative.d.ts.map +1 -1
- package/dist/client/usage/creditNative.js +3 -0
- package/dist/client/usage/creditNative.js.map +1 -1
- package/dist/client/usage/creditProvider.d.ts.map +1 -1
- package/dist/client/usage/creditProvider.js +2 -1
- package/dist/client/usage/creditProvider.js.map +1 -1
- package/dist/client/usage/creditRead.d.ts +1 -0
- package/dist/client/usage/creditRead.d.ts.map +1 -1
- package/dist/client/usage/creditReconciliation.d.ts.map +1 -1
- package/dist/client/usage/creditReconciliation.js +11 -3
- package/dist/client/usage/creditReconciliation.js.map +1 -1
- package/dist/client/usage/creditSettlement.fixtures.d.ts +1 -0
- package/dist/client/usage/creditSettlement.fixtures.d.ts.map +1 -1
- package/dist/client/usage/creditTransport.fixtures.d.ts +1 -0
- package/dist/client/usage/creditTransport.fixtures.d.ts.map +1 -1
- package/dist/client/usage/creditTransport.fixtures.js +2 -1
- package/dist/client/usage/creditTransport.fixtures.js.map +1 -1
- package/dist/client/usage/subscriptionCancellation.d.ts.map +1 -1
- package/dist/client/usage/subscriptionCancellation.js +3 -2
- package/dist/client/usage/subscriptionCancellation.js.map +1 -1
- package/dist/client/usage/subscriptionCheckout.d.ts.map +1 -1
- package/dist/client/usage/subscriptionCheckout.js +3 -2
- package/dist/client/usage/subscriptionCheckout.js.map +1 -1
- package/dist/client/usage/subscriptionLifecycle.d.ts +1 -0
- package/dist/client/usage/subscriptionLifecycle.d.ts.map +1 -1
- package/dist/client/usage/subscriptionLifecycle.js +3 -2
- package/dist/client/usage/subscriptionLifecycle.js.map +1 -1
- package/dist/client/usage/subscriptionProvider.d.ts +2 -0
- package/dist/client/usage/subscriptionProvider.d.ts.map +1 -1
- package/dist/client/usage/subscriptionProvider.js +9 -2
- package/dist/client/usage/subscriptionProvider.js.map +1 -1
- package/dist/component/_generated/component.d.ts +21 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/earnings/triggers.d.ts +16 -6
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/schema.d.ts +13 -3
- package/dist/component/usage/allowance.fixtures.d.ts +4212 -0
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -0
- package/dist/component/usage/allowance.fixtures.js +67 -0
- package/dist/component/usage/allowance.fixtures.js.map +1 -0
- package/dist/component/usageCredits/accounting.fixtures.d.ts +4235 -0
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -0
- package/dist/component/usageCredits/accounting.fixtures.js +89 -0
- package/dist/component/usageCredits/accounting.fixtures.js.map +1 -0
- package/dist/component/usageCredits/helpers.d.ts +7 -0
- package/dist/component/usageCredits/helpers.d.ts.map +1 -1
- package/dist/component/usageCredits/helpers.js +5 -0
- package/dist/component/usageCredits/helpers.js.map +1 -1
- package/dist/component/usageCredits/mutations.d.ts +6 -0
- package/dist/component/usageCredits/mutations.d.ts.map +1 -1
- package/dist/component/usageCredits/mutations.js +70 -7
- package/dist/component/usageCredits/mutations.js.map +1 -1
- package/dist/component/usageCredits/purchase.d.ts +1 -0
- package/dist/component/usageCredits/purchase.d.ts.map +1 -1
- package/dist/component/usageCredits/queries.d.ts +10 -0
- package/dist/component/usageCredits/queries.d.ts.map +1 -1
- package/dist/component/usageCredits/schema.d.ts +24 -4
- package/dist/component/usageCredits/schema.d.ts.map +1 -1
- package/dist/component/usageCredits/schema.js +4 -0
- package/dist/component/usageCredits/schema.js.map +1 -1
- package/dist/component/usageSubscriptions/history.d.ts.map +1 -1
- package/dist/component/usageSubscriptions/history.js +3 -1
- package/dist/component/usageSubscriptions/history.js.map +1 -1
- package/dist/component/usageSubscriptions/mutations.d.ts +5 -0
- package/dist/component/usageSubscriptions/mutations.d.ts.map +1 -1
- package/dist/component/usageSubscriptions/mutations.js +19 -0
- package/dist/component/usageSubscriptions/mutations.js.map +1 -1
- package/dist/component/usageSubscriptions/queries.d.ts +2 -0
- package/dist/component/usageSubscriptions/queries.d.ts.map +1 -1
- package/dist/component/usageSubscriptions/schema.d.ts +7 -2
- package/dist/component/usageSubscriptions/schema.d.ts.map +1 -1
- package/dist/component/usageSubscriptions/schema.js +1 -0
- package/dist/component/usageSubscriptions/schema.js.map +1 -1
- package/docs/README.md +2 -0
- package/docs/usage-credits.md +6 -1
- package/docs/usage-security.md +130 -0
- package/package.json +2 -1
- package/src/client/usage/creditBackingIsolation.test.ts +110 -0
- package/src/client/usage/creditCapacity.test.ts +80 -1
- package/src/client/usage/creditCapacity.ts +10 -1
- package/src/client/usage/creditDelivery.ts +4 -0
- package/src/client/usage/creditLifecycle.ts +2 -0
- package/src/client/usage/creditNative.ts +5 -0
- package/src/client/usage/creditProofBounds.test.ts +187 -0
- package/src/client/usage/creditProvider.test.ts +74 -0
- package/src/client/usage/creditProvider.ts +2 -0
- package/src/client/usage/creditReconciliation.ts +18 -3
- package/src/client/usage/creditTransport.fixtures.ts +2 -1
- package/src/client/usage/subscriptionCancellation.ts +3 -2
- package/src/client/usage/subscriptionCheckout.ts +7 -2
- package/src/client/usage/subscriptionClient.test.ts +60 -1
- package/src/client/usage/subscriptionLifecycle.ts +3 -2
- package/src/client/usage/subscriptionProvider.ts +27 -3
- package/src/component/_generated/component.ts +40 -1
- package/src/component/usage/allowance.fixtures.ts +77 -0
- package/src/component/usage/allowance.test.ts +3 -66
- package/src/component/usage/allowanceBounds.test.ts +79 -0
- package/src/component/usage/historyIsolation.test.ts +124 -0
- package/src/component/usageCredits/accounting.fixtures.ts +96 -0
- package/src/component/usageCredits/accounting.test.ts +176 -82
- package/src/component/usageCredits/freshness.test.ts +33 -0
- package/src/component/usageCredits/helpers.ts +8 -0
- package/src/component/usageCredits/mutations.ts +83 -5
- package/src/component/usageCredits/quotas.test.ts +63 -0
- package/src/component/usageCredits/schema.ts +10 -0
- package/src/component/usageSubscriptions/history.test.ts +57 -0
- package/src/component/usageSubscriptions/history.ts +3 -1
- package/src/component/usageSubscriptions/mutations.ts +23 -0
- package/src/component/usageSubscriptions/schema.ts +1 -0
|
@@ -67,3 +67,60 @@ it("retains original and renewed snapshots, deduplicates replay and keeps newer
|
|
|
67
67
|
}),
|
|
68
68
|
).rejects.toThrow();
|
|
69
69
|
});
|
|
70
|
+
|
|
71
|
+
it("retains the newer projection when conflicting native observations have the same timestamp", async () => {
|
|
72
|
+
const t = convexTest(schema, modules),
|
|
73
|
+
now = Date.now();
|
|
74
|
+
const intent = await t.mutation(prepare, {
|
|
75
|
+
termsJson: JSON.stringify(request),
|
|
76
|
+
method: "direct",
|
|
77
|
+
});
|
|
78
|
+
const renewed = nativeSubscription();
|
|
79
|
+
renewed.items.data.forEach((item) => {
|
|
80
|
+
item.current_period_start = 1200;
|
|
81
|
+
item.current_period_end = 1800;
|
|
82
|
+
});
|
|
83
|
+
await t.mutation(save, {
|
|
84
|
+
key: intent.key,
|
|
85
|
+
nativeJson: JSON.stringify(renewed),
|
|
86
|
+
startedAt: now,
|
|
87
|
+
});
|
|
88
|
+
await t.mutation(save, {
|
|
89
|
+
key: intent.key,
|
|
90
|
+
nativeJson: JSON.stringify(nativeSubscription()),
|
|
91
|
+
startedAt: now,
|
|
92
|
+
});
|
|
93
|
+
const scope = {
|
|
94
|
+
stripeAccountId: "acct_platform",
|
|
95
|
+
customerAccount: "acct_buyer",
|
|
96
|
+
livemode: false,
|
|
97
|
+
};
|
|
98
|
+
const projection = await t.query(get, { scope, requestId: "signup1" });
|
|
99
|
+
expect(
|
|
100
|
+
JSON.parse(projection.viewJson).bindings[0].subscription.period.start,
|
|
101
|
+
).toBe(1200);
|
|
102
|
+
const page = await t.query(history, {
|
|
103
|
+
scope,
|
|
104
|
+
requestId: "signup1",
|
|
105
|
+
kind: "subscription",
|
|
106
|
+
paginationOpts: { numItems: 10, cursor: null },
|
|
107
|
+
});
|
|
108
|
+
expect(page.page).toHaveLength(2);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("reserves distinct ordered observations before native I/O in a concurrent clock tick", async () => {
|
|
112
|
+
const t = convexTest(schema, modules);
|
|
113
|
+
const intent = await t.mutation(prepare, {
|
|
114
|
+
termsJson: JSON.stringify(request),
|
|
115
|
+
method: "direct",
|
|
116
|
+
});
|
|
117
|
+
const begin = makeFunctionReference<"mutation">(
|
|
118
|
+
"usageSubscriptions/mutations:beginObservation",
|
|
119
|
+
);
|
|
120
|
+
const stamps = await Promise.all([
|
|
121
|
+
t.mutation(begin, { key: intent.key }),
|
|
122
|
+
t.mutation(begin, { key: intent.key }),
|
|
123
|
+
]);
|
|
124
|
+
expect(new Set(stamps).size).toBe(2);
|
|
125
|
+
expect(stamps.every(Number.isSafeInteger)).toBe(true);
|
|
126
|
+
});
|
|
@@ -58,7 +58,9 @@ export async function saveView(
|
|
|
58
58
|
view,
|
|
59
59
|
startedAt,
|
|
60
60
|
);
|
|
61
|
-
if ((intent.startedAt ?? -1)
|
|
61
|
+
if ((intent.startedAt ?? -1) >= startedAt && intent.viewJson)
|
|
62
|
+
return JSON.parse(intent.viewJson) as ReturnType<typeof subscriptionView>;
|
|
63
|
+
if ((intent.startedAt ?? -1) < startedAt)
|
|
62
64
|
await ctx.db.patch("usageSubscriptionIntents", intent._id, {
|
|
63
65
|
providerId: view.subscriptionId,
|
|
64
66
|
viewJson: JSON.stringify(view),
|
|
@@ -273,3 +273,26 @@ export const abandon = mutation({
|
|
|
273
273
|
return null;
|
|
274
274
|
},
|
|
275
275
|
});
|
|
276
|
+
|
|
277
|
+
/** Reserve a unique order before native I/O, including concurrent same-clock observations. */
|
|
278
|
+
export const beginObservation = mutation({
|
|
279
|
+
args: { key: v.string() },
|
|
280
|
+
returns: v.number(),
|
|
281
|
+
handler: async (ctx, args) => {
|
|
282
|
+
const intent = await ctx.db
|
|
283
|
+
.query("usageSubscriptionIntents")
|
|
284
|
+
.withIndex("by_key", (q) => q.eq("key", args.key))
|
|
285
|
+
.unique();
|
|
286
|
+
if (!intent) throw new Error("Subscription intent not found");
|
|
287
|
+
const startedAt = Math.max(
|
|
288
|
+
Date.now(),
|
|
289
|
+
(intent.startedAt ?? -1) + 1,
|
|
290
|
+
(intent.observationStartedAt ?? -1) + 1,
|
|
291
|
+
);
|
|
292
|
+
observationStart(startedAt);
|
|
293
|
+
await ctx.db.patch("usageSubscriptionIntents", intent._id, {
|
|
294
|
+
observationStartedAt: startedAt,
|
|
295
|
+
});
|
|
296
|
+
return startedAt;
|
|
297
|
+
},
|
|
298
|
+
});
|
|
@@ -11,6 +11,7 @@ export const intentFields = {
|
|
|
11
11
|
checkoutId: v.optional(v.string()),
|
|
12
12
|
viewJson: v.optional(v.string()),
|
|
13
13
|
startedAt: v.optional(v.number()),
|
|
14
|
+
observationStartedAt: v.optional(v.number()),
|
|
14
15
|
controlKey: v.optional(v.string()),
|
|
15
16
|
historyCount: v.optional(v.number()),
|
|
16
17
|
retiredAt: v.optional(v.number()),
|