@fantastic.dev/better-stripe 0.52.0 → 0.53.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 +6 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +44 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +22 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +44 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +22 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/products/catalogClient.d.ts +23 -0
- package/dist/client/products/catalogClient.d.ts.map +1 -1
- package/dist/client/products/catalogClient.js +32 -0
- package/dist/client/products/catalogClient.js.map +1 -1
- package/dist/client/products/fixedPrice.d.ts +4 -0
- package/dist/client/products/fixedPrice.d.ts.map +1 -0
- package/dist/client/products/fixedPrice.js +10 -0
- package/dist/client/products/fixedPrice.js.map +1 -0
- package/dist/client/products/products.d.ts.map +1 -1
- package/dist/client/products/products.js +3 -0
- package/dist/client/products/products.js.map +1 -1
- package/dist/client/usage/catalog.d.ts +7 -0
- package/dist/client/usage/catalog.d.ts.map +1 -0
- package/dist/client/usage/catalog.js +55 -0
- package/dist/client/usage/catalog.js.map +1 -0
- package/dist/client/usage/catalogLifecycle.d.ts +25 -0
- package/dist/client/usage/catalogLifecycle.d.ts.map +1 -0
- package/dist/client/usage/catalogLifecycle.js +64 -0
- package/dist/client/usage/catalogLifecycle.js.map +1 -0
- package/dist/client/usage/catalogMath.d.ts +3 -0
- package/dist/client/usage/catalogMath.d.ts.map +1 -0
- package/dist/client/usage/catalogMath.js +21 -0
- package/dist/client/usage/catalogMath.js.map +1 -0
- package/dist/client/usage/catalogPrices.d.ts +5 -0
- package/dist/client/usage/catalogPrices.d.ts.map +1 -0
- package/dist/client/usage/catalogPrices.js +178 -0
- package/dist/client/usage/catalogPrices.js.map +1 -0
- package/dist/client/usage/catalogRead.d.ts +25 -0
- package/dist/client/usage/catalogRead.d.ts.map +1 -0
- package/dist/client/usage/catalogRead.js +71 -0
- package/dist/client/usage/catalogRead.js.map +1 -0
- package/dist/client/usage/catalogTypes.d.ts +97 -0
- package/dist/client/usage/catalogTypes.d.ts.map +1 -0
- package/dist/client/usage/catalogTypes.js +106 -0
- package/dist/client/usage/catalogTypes.js.map +1 -0
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +3 -0
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/component/_generated/api.d.ts +4 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +62 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/earnings/triggers.d.ts +46 -0
- package/dist/component/earnings/triggers.d.ts.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/schema.d.ts +22 -0
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usageCatalog/mutations.d.ts +25 -0
- package/dist/component/usageCatalog/mutations.d.ts.map +1 -0
- package/dist/component/usageCatalog/mutations.js +75 -0
- package/dist/component/usageCatalog/mutations.js.map +1 -0
- package/dist/component/usageCatalog/queries.d.ts +33 -0
- package/dist/component/usageCatalog/queries.d.ts.map +1 -0
- package/dist/component/usageCatalog/queries.js +26 -0
- package/dist/component/usageCatalog/queries.js.map +1 -0
- package/dist/component/usageCatalog/schema.d.ts +57 -0
- package/dist/component/usageCatalog/schema.d.ts.map +1 -0
- package/dist/component/usageCatalog/schema.js +22 -0
- package/dist/component/usageCatalog/schema.js.map +1 -0
- package/docs/README.md +3 -1
- package/docs/metering-setup.md +2 -0
- package/docs/usage-catalog.md +106 -0
- package/package.json +3 -2
- package/src/client/index.ts +7 -0
- package/src/client/products/catalogClient.ts +77 -0
- package/src/client/products/fixedPrice.test.ts +57 -0
- package/src/client/products/fixedPrice.ts +13 -0
- package/src/client/products/products.ts +2 -0
- package/src/client/usage/catalog.test.ts +464 -0
- package/src/client/usage/catalog.ts +117 -0
- package/src/client/usage/catalogLifecycle.ts +128 -0
- package/src/client/usage/catalogMath.test.ts +13 -0
- package/src/client/usage/catalogMath.ts +22 -0
- package/src/client/usage/catalogPrices.ts +251 -0
- package/src/client/usage/catalogRead.ts +98 -0
- package/src/client/usage/catalogTypes.ts +170 -0
- package/src/client/webhooks/processors.ts +2 -0
- package/src/component/_generated/api.ts +4 -0
- package/src/component/_generated/component.ts +78 -0
- package/src/component/schema.ts +2 -0
- package/src/component/usageCatalog/mutations.ts +79 -0
- package/src/component/usageCatalog/queries.ts +32 -0
- package/src/component/usageCatalog/schema.ts +21 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { doc, kind } from "./schema.js";
|
|
4
|
+
function bounded(value: string, max: number) {
|
|
5
|
+
if (!value || new TextEncoder().encode(value).length > max)
|
|
6
|
+
throw new Error("Invalid usage catalog size");
|
|
7
|
+
}
|
|
8
|
+
export const prepare = mutation({
|
|
9
|
+
args: { scopeKey: v.string(), kind, key: v.string(), termsJson: v.string() },
|
|
10
|
+
returns: doc,
|
|
11
|
+
handler: async (ctx, args) => {
|
|
12
|
+
bounded(args.scopeKey, 256);
|
|
13
|
+
bounded(args.key, 512);
|
|
14
|
+
bounded(args.termsJson, 8192);
|
|
15
|
+
const existing = await ctx.db
|
|
16
|
+
.query("usageCatalog")
|
|
17
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
18
|
+
q
|
|
19
|
+
.eq("scopeKey", args.scopeKey)
|
|
20
|
+
.eq("kind", args.kind)
|
|
21
|
+
.eq("key", args.key),
|
|
22
|
+
)
|
|
23
|
+
.unique();
|
|
24
|
+
if (existing) {
|
|
25
|
+
if (existing.termsJson !== args.termsJson)
|
|
26
|
+
throw new Error("Immutable usage catalog terms conflict");
|
|
27
|
+
return existing;
|
|
28
|
+
}
|
|
29
|
+
const id = await ctx.db.insert("usageCatalog", {
|
|
30
|
+
...args,
|
|
31
|
+
firstAttemptAt: Math.floor(Date.now() / 1000),
|
|
32
|
+
});
|
|
33
|
+
const result = await ctx.db.get("usageCatalog", id);
|
|
34
|
+
if (!result) throw new Error("Usage catalog intent unavailable");
|
|
35
|
+
return result;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
export const complete = mutation({
|
|
39
|
+
args: {
|
|
40
|
+
scopeKey: v.string(),
|
|
41
|
+
kind,
|
|
42
|
+
key: v.string(),
|
|
43
|
+
providerId: v.string(),
|
|
44
|
+
observationJson: v.string(),
|
|
45
|
+
},
|
|
46
|
+
returns: v.null(),
|
|
47
|
+
handler: async (ctx, args) => {
|
|
48
|
+
bounded(args.providerId, 100);
|
|
49
|
+
bounded(args.observationJson, 8192);
|
|
50
|
+
const row = await ctx.db
|
|
51
|
+
.query("usageCatalog")
|
|
52
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
53
|
+
q
|
|
54
|
+
.eq("scopeKey", args.scopeKey)
|
|
55
|
+
.eq("kind", args.kind)
|
|
56
|
+
.eq("key", args.key),
|
|
57
|
+
)
|
|
58
|
+
.unique();
|
|
59
|
+
if (!row || (row.providerId && row.providerId !== args.providerId))
|
|
60
|
+
throw new Error("Usage catalog reassignment rejected");
|
|
61
|
+
const existing = await ctx.db
|
|
62
|
+
.query("usageCatalog")
|
|
63
|
+
.withIndex("by_scope_kind_provider", (q) =>
|
|
64
|
+
q
|
|
65
|
+
.eq("scopeKey", args.scopeKey)
|
|
66
|
+
.eq("kind", args.kind)
|
|
67
|
+
.eq("providerId", args.providerId),
|
|
68
|
+
)
|
|
69
|
+
.unique();
|
|
70
|
+
if (existing && existing._id !== row._id)
|
|
71
|
+
throw new Error("Usage catalog ownership conflict");
|
|
72
|
+
await ctx.db.patch("usageCatalog", row._id, {
|
|
73
|
+
providerId: args.providerId,
|
|
74
|
+
observationJson: args.observationJson,
|
|
75
|
+
observedAt: Math.floor(Date.now() / 1000),
|
|
76
|
+
});
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { kind, doc } from "./schema.js";
|
|
4
|
+
export const get = query({
|
|
5
|
+
args: { scopeKey: v.string(), kind, key: v.string() },
|
|
6
|
+
returns: v.union(doc, v.null()),
|
|
7
|
+
handler: async (ctx, args) =>
|
|
8
|
+
ctx.db
|
|
9
|
+
.query("usageCatalog")
|
|
10
|
+
.withIndex("by_scope_kind_key", (q) =>
|
|
11
|
+
q
|
|
12
|
+
.eq("scopeKey", args.scopeKey)
|
|
13
|
+
.eq("kind", args.kind)
|
|
14
|
+
.eq("key", args.key),
|
|
15
|
+
)
|
|
16
|
+
.unique(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const getByProvider = query({
|
|
20
|
+
args: { scopeKey: v.string(), kind, providerId: v.string() },
|
|
21
|
+
returns: v.union(doc, v.null()),
|
|
22
|
+
handler: async (ctx, args) =>
|
|
23
|
+
ctx.db
|
|
24
|
+
.query("usageCatalog")
|
|
25
|
+
.withIndex("by_scope_kind_provider", (q) =>
|
|
26
|
+
q
|
|
27
|
+
.eq("scopeKey", args.scopeKey)
|
|
28
|
+
.eq("kind", args.kind)
|
|
29
|
+
.eq("providerId", args.providerId),
|
|
30
|
+
)
|
|
31
|
+
.unique(),
|
|
32
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export const kind = v.union(v.literal("meter"), v.literal("price"));
|
|
4
|
+
export const fields = {
|
|
5
|
+
observedAt: v.optional(v.number()),
|
|
6
|
+
scopeKey: v.string(),
|
|
7
|
+
kind,
|
|
8
|
+
key: v.string(),
|
|
9
|
+
termsJson: v.string(),
|
|
10
|
+
firstAttemptAt: v.number(),
|
|
11
|
+
providerId: v.optional(v.string()),
|
|
12
|
+
observationJson: v.optional(v.string()),
|
|
13
|
+
};
|
|
14
|
+
export const doc = v.object({
|
|
15
|
+
_id: v.id("usageCatalog"),
|
|
16
|
+
_creationTime: v.number(),
|
|
17
|
+
...fields,
|
|
18
|
+
});
|
|
19
|
+
export const usageCatalogTable = defineTable(fields)
|
|
20
|
+
.index("by_scope_kind_key", ["scopeKey", "kind", "key"])
|
|
21
|
+
.index("by_scope_kind_provider", ["scopeKey", "kind", "providerId"]);
|