@fantastic.dev/better-stripe 0.51.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 +20 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +210 -32
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +105 -16
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +178 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +89 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +5 -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/usage/client.d.ts +37 -0
- package/dist/client/usage/client.d.ts.map +1 -0
- package/dist/client/usage/client.js +59 -0
- package/dist/client/usage/client.js.map +1 -0
- package/dist/client/usage/records.d.ts +1 -1
- package/dist/client/usage/records.d.ts.map +1 -1
- package/dist/client/usage/records.js +1 -1
- package/dist/client/usage/records.js.map +1 -1
- 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 +10 -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 +141 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +224 -16
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/schema.d.ts +89 -0
- package/dist/component/schema.js +7 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/helpers.d.ts +13 -0
- package/dist/component/usage/helpers.d.ts.map +1 -0
- package/dist/component/usage/helpers.js +34 -0
- package/dist/component/usage/helpers.js.map +1 -0
- package/dist/component/usage/mutations.d.ts +14 -0
- package/dist/component/usage/mutations.d.ts.map +1 -0
- package/dist/component/usage/mutations.js +124 -0
- package/dist/component/usage/mutations.js.map +1 -0
- package/dist/component/usage/queries.d.ts +62 -0
- package/dist/component/usage/queries.d.ts.map +1 -0
- package/dist/component/usage/queries.js +65 -0
- package/dist/component/usage/queries.js.map +1 -0
- package/dist/component/usage/schema.d.ts +110 -0
- package/dist/component/usage/schema.d.ts.map +1 -0
- package/dist/component/usage/schema.js +54 -0
- package/dist/component/usage/schema.js.map +1 -0
- 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 +5 -1
- package/docs/metered-usage.md +2 -2
- package/docs/metering-setup.md +4 -1
- package/docs/usage-catalog.md +106 -0
- package/docs/usage-ledger.md +62 -0
- package/package.json +4 -2
- package/src/client/index.ts +12 -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/usage/client.ts +97 -0
- package/src/client/usage/ledger-client.test.ts +74 -0
- package/src/client/usage/records.ts +1 -1
- package/src/client/webhooks/processors.ts +2 -0
- package/src/component/_generated/api.ts +10 -0
- package/src/component/_generated/component.ts +184 -0
- package/src/component/schema.ts +12 -0
- package/src/component/usage/helpers.ts +33 -0
- package/src/component/usage/ledger.test.ts +310 -0
- package/src/component/usage/mutations.ts +139 -0
- package/src/component/usage/queries.ts +69 -0
- package/src/component/usage/schema.ts +65 -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,33 @@
|
|
|
1
|
+
export declare const get: import("convex/server").RegisteredQuery<"public", {
|
|
2
|
+
key: string;
|
|
3
|
+
kind: "meter" | "price";
|
|
4
|
+
scopeKey: string;
|
|
5
|
+
}, Promise<{
|
|
6
|
+
_creationTime: number;
|
|
7
|
+
_id: import("convex/values").GenericId<"usageCatalog">;
|
|
8
|
+
firstAttemptAt: number;
|
|
9
|
+
key: string;
|
|
10
|
+
kind: "meter" | "price";
|
|
11
|
+
observationJson?: string | undefined;
|
|
12
|
+
observedAt?: number | undefined;
|
|
13
|
+
providerId?: string | undefined;
|
|
14
|
+
scopeKey: string;
|
|
15
|
+
termsJson: string;
|
|
16
|
+
} | null>>;
|
|
17
|
+
export declare const getByProvider: import("convex/server").RegisteredQuery<"public", {
|
|
18
|
+
kind: "meter" | "price";
|
|
19
|
+
providerId: string;
|
|
20
|
+
scopeKey: string;
|
|
21
|
+
}, Promise<{
|
|
22
|
+
_creationTime: number;
|
|
23
|
+
_id: import("convex/values").GenericId<"usageCatalog">;
|
|
24
|
+
firstAttemptAt: number;
|
|
25
|
+
key: string;
|
|
26
|
+
kind: "meter" | "price";
|
|
27
|
+
observationJson?: string | undefined;
|
|
28
|
+
observedAt?: number | undefined;
|
|
29
|
+
providerId?: string | undefined;
|
|
30
|
+
scopeKey: string;
|
|
31
|
+
termsJson: string;
|
|
32
|
+
} | null>>;
|
|
33
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/usageCatalog/queries.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;UAad,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;UAaxB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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) => ctx.db
|
|
8
|
+
.query("usageCatalog")
|
|
9
|
+
.withIndex("by_scope_kind_key", (q) => q
|
|
10
|
+
.eq("scopeKey", args.scopeKey)
|
|
11
|
+
.eq("kind", args.kind)
|
|
12
|
+
.eq("key", args.key))
|
|
13
|
+
.unique(),
|
|
14
|
+
});
|
|
15
|
+
export const getByProvider = query({
|
|
16
|
+
args: { scopeKey: v.string(), kind, providerId: v.string() },
|
|
17
|
+
returns: v.union(doc, v.null()),
|
|
18
|
+
handler: async (ctx, args) => ctx.db
|
|
19
|
+
.query("usageCatalog")
|
|
20
|
+
.withIndex("by_scope_kind_provider", (q) => q
|
|
21
|
+
.eq("scopeKey", args.scopeKey)
|
|
22
|
+
.eq("kind", args.kind)
|
|
23
|
+
.eq("providerId", args.providerId))
|
|
24
|
+
.unique(),
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/usageCatalog/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACxC,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC;IACvB,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACrD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/B,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAC3B,GAAG,CAAC,EAAE;SACH,KAAK,CAAC,cAAc,CAAC;SACrB,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CACpC,CAAC;SACE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC;SAC7B,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;SACrB,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CACvB;SACA,MAAM,EAAE;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;IACjC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IAC5D,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/B,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAC3B,GAAG,CAAC,EAAE;SACH,KAAK,CAAC,cAAc,CAAC;SACrB,SAAS,CAAC,wBAAwB,EAAE,CAAC,CAAC,EAAE,EAAE,CACzC,CAAC;SACE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC;SAC7B,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;SACrB,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CACrC;SACA,MAAM,EAAE;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const kind: import("convex/values").VUnion<"meter" | "price", [import("convex/values").VLiteral<"meter", "required">, import("convex/values").VLiteral<"price", "required">], "required", never>;
|
|
2
|
+
export declare const fields: {
|
|
3
|
+
observedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
4
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
5
|
+
kind: import("convex/values").VUnion<"meter" | "price", [import("convex/values").VLiteral<"meter", "required">, import("convex/values").VLiteral<"price", "required">], "required", never>;
|
|
6
|
+
key: import("convex/values").VString<string, "required">;
|
|
7
|
+
termsJson: import("convex/values").VString<string, "required">;
|
|
8
|
+
firstAttemptAt: import("convex/values").VFloat64<number, "required">;
|
|
9
|
+
providerId: import("convex/values").VString<string | undefined, "optional">;
|
|
10
|
+
observationJson: import("convex/values").VString<string | undefined, "optional">;
|
|
11
|
+
};
|
|
12
|
+
export declare const doc: import("convex/values").VObject<{
|
|
13
|
+
_creationTime: number;
|
|
14
|
+
_id: import("convex/values").GenericId<"usageCatalog">;
|
|
15
|
+
firstAttemptAt: number;
|
|
16
|
+
key: string;
|
|
17
|
+
kind: "meter" | "price";
|
|
18
|
+
observationJson?: string | undefined;
|
|
19
|
+
observedAt?: number | undefined;
|
|
20
|
+
providerId?: string | undefined;
|
|
21
|
+
scopeKey: string;
|
|
22
|
+
termsJson: string;
|
|
23
|
+
}, {
|
|
24
|
+
observedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
25
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
26
|
+
kind: import("convex/values").VUnion<"meter" | "price", [import("convex/values").VLiteral<"meter", "required">, import("convex/values").VLiteral<"price", "required">], "required", never>;
|
|
27
|
+
key: import("convex/values").VString<string, "required">;
|
|
28
|
+
termsJson: import("convex/values").VString<string, "required">;
|
|
29
|
+
firstAttemptAt: import("convex/values").VFloat64<number, "required">;
|
|
30
|
+
providerId: import("convex/values").VString<string | undefined, "optional">;
|
|
31
|
+
observationJson: import("convex/values").VString<string | undefined, "optional">;
|
|
32
|
+
_id: import("convex/values").VId<import("convex/values").GenericId<"usageCatalog">, "required">;
|
|
33
|
+
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
34
|
+
}, "required", "_creationTime" | "_id" | "firstAttemptAt" | "key" | "kind" | "observationJson" | "observedAt" | "providerId" | "scopeKey" | "termsJson">;
|
|
35
|
+
export declare const usageCatalogTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
36
|
+
firstAttemptAt: number;
|
|
37
|
+
key: string;
|
|
38
|
+
kind: "meter" | "price";
|
|
39
|
+
observationJson?: string | undefined;
|
|
40
|
+
observedAt?: number | undefined;
|
|
41
|
+
providerId?: string | undefined;
|
|
42
|
+
scopeKey: string;
|
|
43
|
+
termsJson: string;
|
|
44
|
+
}, {
|
|
45
|
+
observedAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
46
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
47
|
+
kind: import("convex/values").VUnion<"meter" | "price", [import("convex/values").VLiteral<"meter", "required">, import("convex/values").VLiteral<"price", "required">], "required", never>;
|
|
48
|
+
key: import("convex/values").VString<string, "required">;
|
|
49
|
+
termsJson: import("convex/values").VString<string, "required">;
|
|
50
|
+
firstAttemptAt: import("convex/values").VFloat64<number, "required">;
|
|
51
|
+
providerId: import("convex/values").VString<string | undefined, "optional">;
|
|
52
|
+
observationJson: import("convex/values").VString<string | undefined, "optional">;
|
|
53
|
+
}, "required", "firstAttemptAt" | "key" | "kind" | "observationJson" | "observedAt" | "providerId" | "scopeKey" | "termsJson">, {
|
|
54
|
+
by_scope_kind_key: ["scopeKey", "kind", "key", "_creationTime"];
|
|
55
|
+
by_scope_kind_provider: ["scopeKey", "kind", "providerId", "_creationTime"];
|
|
56
|
+
}, {}, {}>;
|
|
57
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/usageCatalog/schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,sLAAkD,CAAC;AACpE,eAAO,MAAM,MAAM;;;;;;;;;CASlB,CAAC;AACF,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;wJAId,CAAC;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;UAEwC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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"]);
|
|
22
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/usageCatalog/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,IAAI;IACJ,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CACxC,CAAC;AACF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC;IACzB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,GAAG,MAAM;CACV,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC,MAAM,CAAC;KACjD,KAAK,CAAC,mBAAmB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;KACvD,KAAK,CAAC,wBAAwB,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC"}
|
package/docs/README.md
CHANGED
|
@@ -24,7 +24,7 @@ guide for your integration.
|
|
|
24
24
|
- [SetupIntent recovery](setup-intent-recovery.md).
|
|
25
25
|
- [Balance funding state](balance-funding-state.md) and [workflow](balance-funding-workflow.md).
|
|
26
26
|
- [Example balance funding cutover](example-balance-funding-cutover.md).
|
|
27
|
-
- [Metered usage investigation](metered-usage.md), provider comparison and acceptance requirements.
|
|
27
|
+
- [Metered usage investigation](metered-usage.md), provider comparison and acceptance requirements. Shared contracts, catalog provisioning and local usage acceptance are available; delivery and credit accounting are in progress.
|
|
28
28
|
|
|
29
29
|
## Marketplace, settlement, and recovery
|
|
30
30
|
|
|
@@ -56,3 +56,7 @@ covers sandbox configuration, checkout comparisons, and test flows.
|
|
|
56
56
|
|
|
57
57
|
Start with the [native Stripe setup guide](metering-setup.md), then read the
|
|
58
58
|
[shared contracts and sandbox evidence](metered-usage.md).
|
|
59
|
+
|
|
60
|
+
[Atomic usage ledger and scoped history](usage-ledger.md) describes acceptance and retention.
|
|
61
|
+
|
|
62
|
+
[Native usage catalog](usage-catalog.md) covers provisioning, immutable versions and typed price observations.
|
package/docs/metered-usage.md
CHANGED
|
@@ -348,8 +348,8 @@ normalized immutable terms and rejects changed replay on the original identity,
|
|
|
348
348
|
including time, currency, mapped customer and version. A transition must never
|
|
349
349
|
turn a prepaid consumption into a new pay-as-you-go charge.
|
|
350
350
|
|
|
351
|
-
These are shared contracts and host-boundary helpers.
|
|
352
|
-
delivery, correction and transition adapters
|
|
351
|
+
These are shared contracts and host-boundary helpers. The [atomic ledger](usage-ledger.md) implements acceptance and local history.
|
|
352
|
+
Catalog, delivery, correction and transition adapters follow in subsequent tickets.
|
|
353
353
|
|
|
354
354
|
`UsageContractPort` defines shared `record`, paginated `read`, `reconcile` and
|
|
355
355
|
`capabilities` requests/results for host adapters. `record` is an atomic local
|
package/docs/metering-setup.md
CHANGED
|
@@ -6,7 +6,8 @@ integrations, but Billing Meters APIs remain available. This project is building
|
|
|
6
6
|
native Stripe integration into the existing BetterStripe Convex component.
|
|
7
7
|
|
|
8
8
|
Current status: shared configuration/quantity helpers and repository sandbox probes
|
|
9
|
-
are implemented.
|
|
9
|
+
are implemented. Atomic recording and bounded local history are available through the
|
|
10
|
+
[usage ledger](usage-ledger.md). Durable provider delivery, allowance/credit
|
|
10
11
|
accounting and the three example UI flows are still under development. The probes
|
|
11
12
|
below verify provider behavior directly; they are not public BetterStripe billing
|
|
12
13
|
workflows. See [metered usage contracts and evidence](metered-usage.md).
|
|
@@ -181,3 +182,5 @@ Primary references:
|
|
|
181
182
|
- [Stripe meter event API](https://docs.stripe.com/api/billing/meter-event/create)
|
|
182
183
|
- [Stripe billing credits](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits)
|
|
183
184
|
- [Metronome quickstart](https://docs.metronome.com/guides/get-started/api-quickstart)
|
|
185
|
+
|
|
186
|
+
Use the [native catalog guide](usage-catalog.md) to provision versioned meters and prices through BetterStripe.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Provision the native usage catalog
|
|
2
|
+
|
|
3
|
+
BetterStripe uses Stripe Billing Meters and recurring metered Prices. No
|
|
4
|
+
Metronome account is required. Follow [sandbox setup](metering-setup.md) first.
|
|
5
|
+
These methods run in authenticated host actions. Resolve the account, test/live
|
|
6
|
+
mode, plan and product on the server, and authorize the caller before provisioning.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { defineUsagePlan } from "@fantastic.dev/better-stripe/usage";
|
|
10
|
+
|
|
11
|
+
const plan = defineUsagePlan({
|
|
12
|
+
key: "api-calls",
|
|
13
|
+
version: "v1",
|
|
14
|
+
model: "pay_as_you_go",
|
|
15
|
+
unit: { name: "call", precision: 0 },
|
|
16
|
+
rate: { currency: "usd", unitAmountDecimal: "2" },
|
|
17
|
+
});
|
|
18
|
+
const scope = { stripeAccountId: verifiedPlatformAccountId, livemode: false };
|
|
19
|
+
const meter = await stripe.ensureUsageMeter(ctx, {
|
|
20
|
+
scope,
|
|
21
|
+
plan,
|
|
22
|
+
eventName: "api_calls_v1",
|
|
23
|
+
displayName: "API calls v1",
|
|
24
|
+
});
|
|
25
|
+
const price = await stripe.ensureUsagePrice(ctx, {
|
|
26
|
+
scope,
|
|
27
|
+
plan,
|
|
28
|
+
meterId: meter.id,
|
|
29
|
+
stripeProductId: verifiedProductId,
|
|
30
|
+
lookupKey: "api_calls_v1_usd",
|
|
31
|
+
});
|
|
32
|
+
// price is a Convex-safe UsagePriceBinding with exact string amounts.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use `model: "included_overage"`, `includedQuantity: "1000"` and
|
|
36
|
+
`reset: "billing_period"` for monthly included units with overages. Stripe receives
|
|
37
|
+
a graduated free first tier and an infinite paid tier. Use `model: "prepaid"` and
|
|
38
|
+
`insufficientBalance: "reject"` for the prepaid catalog. Its recurring price charges
|
|
39
|
+
the configured rate, and payment-backed Billing Credit Grants offset eligible
|
|
40
|
+
charges. Provisioning this price does not fund credits or enforce a balance.
|
|
41
|
+
See the [implementation status](metered-usage.md) before enabling consumption.
|
|
42
|
+
|
|
43
|
+
Rates are decimal minor currency units per whole billable unit. With precision 2,
|
|
44
|
+
a rate of `"2"` becomes `"0.02"` per scaled provider unit. The adapter rejects more
|
|
45
|
+
than 12 provider decimal places rather than rounding. Included tier boundaries
|
|
46
|
+
must be exact positive safe integers after scaling. Monthly intervals, sum
|
|
47
|
+
aggregation, `stripe_customer_id` and `value` mappings are supported. Other
|
|
48
|
+
intervals, transformations and provider terms require an explicit adapter change.
|
|
49
|
+
|
|
50
|
+
The configured Stripe key must own `scope.stripeAccountId`. The adapter verifies
|
|
51
|
+
that account and the key's mode before writes. Connected-account headers are not
|
|
52
|
+
supported by these APIs. Restricted keys that cannot perform this verification
|
|
53
|
+
return `provider_unavailable`. A mismatch returns `unsupported_scope`.
|
|
54
|
+
|
|
55
|
+
## Immutable identities and recovery
|
|
56
|
+
|
|
57
|
+
A meter identity is scoped by account, mode, plan key and version. A price identity
|
|
58
|
+
uses the same account/mode plus its lookup key. Plan terms, event name, mappings,
|
|
59
|
+
product, price currency and rates cannot change under those identities. Use a new
|
|
60
|
+
version, event name and lookup key for changed terms. A provider resource cannot
|
|
61
|
+
be adopted into a second managed identity.
|
|
62
|
+
|
|
63
|
+
The component persists a creation intent before calling Stripe and uses a stable
|
|
64
|
+
idempotency key. Retries verify provider terms and repair a failed mirror write.
|
|
65
|
+
Pinned resources are retrieved by ID and never recreated when retrieval fails.
|
|
66
|
+
Unpinned meter discovery is bounded to 1,000 resources. Incomplete discovery,
|
|
67
|
+
ambiguous matches and conflicting terms stop provisioning.
|
|
68
|
+
|
|
69
|
+
Automatic creation stops 23 hours after the first intent. Stripe's idempotency
|
|
70
|
+
retention is finite. An absent result after that point returns
|
|
71
|
+
`unknown_create_outcome`; investigate the provider account and adopt the verified
|
|
72
|
+
existing meter rather than generating another event identity. Found matching
|
|
73
|
+
resources can still repair a mirror after this window. Do not delete intent rows
|
|
74
|
+
or change keys to retry an uncertain write.
|
|
75
|
+
|
|
76
|
+
## Lifecycle and reads
|
|
77
|
+
|
|
78
|
+
`adoptUsageMeter` accepts an exact provider meter ID plus the same configuration
|
|
79
|
+
as `ensureUsageMeter`. `getUsageMeterFromStripe` retrieves one ID.
|
|
80
|
+
`listStripeUsageMeters` accepts a page limit of 1–100 and optional cursor, and
|
|
81
|
+
returns `data`, `hasMore` and `cursor`. These provider methods require the same
|
|
82
|
+
verified scope. `deactivateUsageMeter` and `reactivateUsageMeter` operate only on
|
|
83
|
+
managed IDs and refresh their local observation.
|
|
84
|
+
|
|
85
|
+
Deactivation stops new usage ingestion for that meter. It does not migrate or
|
|
86
|
+
cancel existing subscriptions, settle prior usage or change immutable prices.
|
|
87
|
+
Review active subscriptions and queued delivery before deactivation. Explicitly
|
|
88
|
+
create and bind a new version when changing billing terms.
|
|
89
|
+
|
|
90
|
+
`getUsagePrice(ctx, { scope, lookupKey })` is a local query-compatible reader.
|
|
91
|
+
Its `available` result contains `observedAt` and a discriminated
|
|
92
|
+
`pricingMode: "metered"` binding, exact string amounts and explicit tiers. Missing,
|
|
93
|
+
pending and invalid observations return typed `unavailable` states. Reauthorize
|
|
94
|
+
every read. Cached observations do not prove fresh provider state or invoicing.
|
|
95
|
+
|
|
96
|
+
The legacy fixed-price mirror and its readers only represent fixed integer prices.
|
|
97
|
+
Webhook and bulk sync omit metered, tiered, transformed and decimal-only prices
|
|
98
|
+
instead of converting a null amount into zero. Use the scoped usage reader for
|
|
99
|
+
managed metered prices. Historical mirrors written by earlier package versions
|
|
100
|
+
are not automatically migrated; audit those records before relying on old data.
|
|
101
|
+
Existing fixed-price creation, adoption and readers retain their contracts.
|
|
102
|
+
|
|
103
|
+
Authoritative references: [Stripe meters](https://docs.stripe.com/api/billing/meter),
|
|
104
|
+
[usage-based prices](https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide),
|
|
105
|
+
[idempotency retention](https://docs.stripe.com/api/idempotent_requests), and
|
|
106
|
+
[Billing Credit Grant eligibility](https://docs.stripe.com/billing/subscriptions/usage-based/billing-credits).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Record usage atomically
|
|
2
|
+
|
|
3
|
+
`stripe.usage.record`, `get` and `read` are trusted host APIs. The host must
|
|
4
|
+
authenticate the actor, authorize the exact Stripe realm/payer/meter and resolve
|
|
5
|
+
the native customer, subscription, item and price from verified server state.
|
|
6
|
+
Use `authorizeUsageRecord` to run authorization and billable-activity policy before
|
|
7
|
+
calling the facade. Browser-supplied account IDs and prices are not authorization.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { authorizeUsageRecord } from "@fantastic.dev/better-stripe/usage";
|
|
11
|
+
|
|
12
|
+
// In a host mutation, resolve these from authenticated, persisted activity.
|
|
13
|
+
const receipt = await authorizeUsageRecord(ctx, policy, serverEvent, (event) =>
|
|
14
|
+
stripe.usage.record(ctx, { event, subscription: verifiedSubscription }),
|
|
15
|
+
);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Acceptance writes an immutable event, durable outbox row and retained-scope counter
|
|
19
|
+
in one Convex transaction. An optional `dispatch` handle schedules an internal
|
|
20
|
+
host action in that transaction. Create the handle on the server; never accept it
|
|
21
|
+
from a browser. Scheduling failure rolls back acceptance, counter changes and any
|
|
22
|
+
reservation commit. Without dispatch, the outbox stays queued for later delivery.
|
|
23
|
+
Recording does not contact Stripe or prove billing, aggregation or payment.
|
|
24
|
+
|
|
25
|
+
Use stable source-event IDs. Equal replay returns the original acceptance receipt,
|
|
26
|
+
including after the event's delivery window expires. A changed quantity, occurrence
|
|
27
|
+
time, mapped customer, plan/version, currency, price or subscription snapshot
|
|
28
|
+
conflicts. Realm, payer, meter and test/live mode are independent scopes. A source
|
|
29
|
+
ID reused in a different authorized scope is an independent event, not permission
|
|
30
|
+
to alter the original. Do not move activity between scopes to repair a failure.
|
|
31
|
+
|
|
32
|
+
Quantities use the shared exact decimal contract and integer scaled representation.
|
|
33
|
+
New occurrence times must be within Stripe's 35-day past/5-minute future window
|
|
34
|
+
and the immutable half-open subscription period. The price must match that
|
|
35
|
+
subscription binding. The component assigns acceptance time in Unix seconds.
|
|
36
|
+
Payloads are limited to 8 KiB and subscription snapshots to 2 KiB, measured as UTF-8.
|
|
37
|
+
No arbitrary event metadata, secret or user payload is accepted.
|
|
38
|
+
|
|
39
|
+
The default quota is 100,000 retained events per scope. A host may select a lower
|
|
40
|
+
`quota`, from 1 to 100,000. Exhaustion rejects new work and preserves history.
|
|
41
|
+
Replays do not consume quota. Export and reconcile bounded pages before planning
|
|
42
|
+
future archival; this implementation has no financial-history deletion API.
|
|
43
|
+
Do not clear the tables to reset a quota or repair unresolved usage.
|
|
44
|
+
|
|
45
|
+
Prepaid recording requires a matching component-owned reservation and atomically
|
|
46
|
+
commits it with the event. The scope, source ID, exact quantity and immutable plan
|
|
47
|
+
must match. No arbitrary reservation-creation API exists. Payment-backed grant and
|
|
48
|
+
reservation provisioning is implemented in the credit-accounting ticket; until
|
|
49
|
+
then the facade rejects prepaid events without such a reservation. Included-usage
|
|
50
|
+
snapshots use the same ledger; strict allowance reservations can use the same
|
|
51
|
+
atomic commit seam when allowance accounting is enabled.
|
|
52
|
+
|
|
53
|
+
`get(ctx, {scope, eventId})` returns null for a foreign scope or absent event.
|
|
54
|
+
`read(ctx, {scope, page: {period: {start, end}, limit, cursor}})` returns `events`,
|
|
55
|
+
`cursor` and `isDone`. It uses an indexed range and bounds pages to 1–100 events.
|
|
56
|
+
The acceptance receipt always records initial queued intent; the view's separate
|
|
57
|
+
`delivery` field reports current outbox state. Reauthorize every page. A complete
|
|
58
|
+
local page history does not establish complete provider aggregation or invoices.
|
|
59
|
+
|
|
60
|
+
This layer implements acceptance/history, not provider delivery or credit funding.
|
|
61
|
+
See [native setup](metering-setup.md), [shared contracts](metered-usage.md) and
|
|
62
|
+
[Stripe's native event windows](https://docs.stripe.com/api/billing/meter-event/create).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fantastic.dev/better-stripe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "A Convex component for Stripe V2 Accounts API integration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"stripe",
|
|
@@ -100,7 +100,9 @@
|
|
|
100
100
|
"docs/testing.md",
|
|
101
101
|
"docs/configuration.md",
|
|
102
102
|
"docs/architecture.md",
|
|
103
|
-
"docs/development.md"
|
|
103
|
+
"docs/development.md",
|
|
104
|
+
"docs/usage-ledger.md",
|
|
105
|
+
"docs/usage-catalog.md"
|
|
104
106
|
],
|
|
105
107
|
"scripts": {
|
|
106
108
|
"build": "tsc --project ./tsconfig.build.json && node scripts/check-public-exports.mjs",
|
package/src/client/index.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
export { UsageCatalogError } from "./usage/catalogTypes.js";
|
|
2
|
+
export type {
|
|
3
|
+
UsageCatalogScope,
|
|
4
|
+
UsageMeterOptions,
|
|
5
|
+
UsagePriceOptions,
|
|
6
|
+
} from "./usage/catalogTypes.js";
|
|
7
|
+
export type { UsagePriceBinding } from "./usage/catalogRead.js";
|
|
1
8
|
import * as setupIntentRead from "./billing/setup-intent-read.js";
|
|
9
|
+
import { UsageLedgerClient } from "./usage/client.js";
|
|
10
|
+
export type { RecordUsageOptions } from "./usage/client.js";
|
|
2
11
|
export type {
|
|
3
12
|
SetupIntentReadOptions,
|
|
4
13
|
SetupIntentObservation,
|
|
@@ -240,6 +249,9 @@ export type BetterStripeComponent = ComponentApi;
|
|
|
240
249
|
// BETTER STRIPE CLIENT
|
|
241
250
|
|
|
242
251
|
export class BetterStripe extends PaymentSourceClient {
|
|
252
|
+
get usage() {
|
|
253
|
+
return new UsageLedgerClient(this.component);
|
|
254
|
+
}
|
|
243
255
|
readonly stripeApiVersion: SupportedStripeApiVersion;
|
|
244
256
|
private _apiKey?: string;
|
|
245
257
|
private _triggers?: SyncTriggers;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { UsageCatalogError } from "../usage/catalogTypes.js";
|
|
2
|
+
import * as usageCatalog from "../usage/catalog.js";
|
|
3
|
+
import * as usageLifecycle from "../usage/catalogLifecycle.js";
|
|
4
|
+
import { getUsagePriceBinding } from "../usage/catalogRead.js";
|
|
1
5
|
import type Stripe from "stripe";
|
|
2
6
|
import { BillingPortalClient } from "../core/billingPortalClient.js";
|
|
3
7
|
import type { RunCtx } from "../helpers.js";
|
|
@@ -9,6 +13,79 @@ import * as catalog from "./catalog.js";
|
|
|
9
13
|
/** Catalog APIs inherited by BetterStripe. Host authorization remains required. */
|
|
10
14
|
export abstract class CatalogClient extends BillingPortalClient {
|
|
11
15
|
abstract get statementDescriptorSuffix(): string | undefined;
|
|
16
|
+
ensureUsageMeter(ctx: RunCtx, opts: usageCatalog.UsageMeterOptions) {
|
|
17
|
+
return usageCatalog.ensureUsageMeter(
|
|
18
|
+
this.stripe(),
|
|
19
|
+
this.component,
|
|
20
|
+
ctx,
|
|
21
|
+
opts,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
async ensureUsagePrice(ctx: RunCtx, opts: usageCatalog.UsagePriceOptions) {
|
|
25
|
+
await usageCatalog.ensureUsagePrice(
|
|
26
|
+
this.stripe(),
|
|
27
|
+
this.component,
|
|
28
|
+
ctx,
|
|
29
|
+
opts,
|
|
30
|
+
);
|
|
31
|
+
const binding = await getUsagePriceBinding(this.component, ctx, opts);
|
|
32
|
+
if (binding.status !== "available")
|
|
33
|
+
throw new UsageCatalogError(
|
|
34
|
+
"provider_unavailable",
|
|
35
|
+
"Native usage price mirror is unavailable",
|
|
36
|
+
);
|
|
37
|
+
return binding.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
adoptUsageMeter(
|
|
41
|
+
ctx: RunCtx,
|
|
42
|
+
opts: usageCatalog.UsageMeterOptions & { meterId: string },
|
|
43
|
+
) {
|
|
44
|
+
return usageLifecycle.adoptUsageMeter(
|
|
45
|
+
this.stripe(),
|
|
46
|
+
this.component,
|
|
47
|
+
ctx,
|
|
48
|
+
opts,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
getUsageMeterFromStripe(
|
|
52
|
+
_ctx: RunCtx,
|
|
53
|
+
opts: Parameters<typeof usageLifecycle.getUsageMeterFromStripe>[1],
|
|
54
|
+
) {
|
|
55
|
+
return usageLifecycle.getUsageMeterFromStripe(this.stripe(), opts);
|
|
56
|
+
}
|
|
57
|
+
listStripeUsageMeters(
|
|
58
|
+
_ctx: RunCtx,
|
|
59
|
+
opts: Parameters<typeof usageLifecycle.listStripeUsageMeters>[1],
|
|
60
|
+
) {
|
|
61
|
+
return usageLifecycle.listStripeUsageMeters(this.stripe(), opts);
|
|
62
|
+
}
|
|
63
|
+
deactivateUsageMeter(
|
|
64
|
+
ctx: RunCtx,
|
|
65
|
+
opts: { scope: usageCatalog.UsageCatalogScope; meterId: string },
|
|
66
|
+
) {
|
|
67
|
+
return usageLifecycle.setUsageMeterActive(
|
|
68
|
+
this.stripe(),
|
|
69
|
+
this.component,
|
|
70
|
+
ctx,
|
|
71
|
+
{ ...opts, active: false },
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
reactivateUsageMeter(
|
|
75
|
+
ctx: RunCtx,
|
|
76
|
+
opts: { scope: usageCatalog.UsageCatalogScope; meterId: string },
|
|
77
|
+
) {
|
|
78
|
+
return usageLifecycle.setUsageMeterActive(
|
|
79
|
+
this.stripe(),
|
|
80
|
+
this.component,
|
|
81
|
+
ctx,
|
|
82
|
+
{ ...opts, active: true },
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
getUsagePrice(ctx: RunCtx, opts: Parameters<typeof getUsagePriceBinding>[2]) {
|
|
86
|
+
return getUsagePriceBinding(this.component, ctx, opts);
|
|
87
|
+
}
|
|
88
|
+
|
|
12
89
|
async getStripePriceByLookupKey(
|
|
13
90
|
_ctx: RunCtx,
|
|
14
91
|
opts: { lookupKey: string },
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { expect, it, vi } from "vitest";
|
|
2
|
+
import type Stripe from "stripe";
|
|
3
|
+
import { syncAllProducts } from "./products.js";
|
|
4
|
+
import { processEvent } from "../webhooks/processors.js";
|
|
5
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
6
|
+
import type { WebhookContext } from "../webhooks/helpers.js";
|
|
7
|
+
|
|
8
|
+
it("does not project metered, tiered or decimal-only provider prices into fixed prices", async () => {
|
|
9
|
+
const runMutation = vi.fn();
|
|
10
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "product" });
|
|
11
|
+
const component = {
|
|
12
|
+
products: {
|
|
13
|
+
queries: {
|
|
14
|
+
getProductByStripeId: {
|
|
15
|
+
[Symbol.for("toReferencePath")]:
|
|
16
|
+
"betterStripe/products/queries/getProductByStripeId",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
mutations: {
|
|
20
|
+
upsertPrice: {
|
|
21
|
+
[Symbol.for("toReferencePath")]:
|
|
22
|
+
"betterStripe/products/mutations/upsertPrice",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
} as unknown as Component;
|
|
27
|
+
const ctx = { runMutation, runQuery } as unknown as RunCtx;
|
|
28
|
+
const prices = [
|
|
29
|
+
{
|
|
30
|
+
id: "price_metered",
|
|
31
|
+
unit_amount: 2,
|
|
32
|
+
recurring: { usage_type: "metered" },
|
|
33
|
+
},
|
|
34
|
+
{ id: "price_tiered", unit_amount: null, billing_scheme: "tiered" },
|
|
35
|
+
{ id: "price_decimal", unit_amount: null, unit_amount_decimal: "0.02" },
|
|
36
|
+
].map((price) => ({ product: "prod_1", ...price }));
|
|
37
|
+
const stripe = {
|
|
38
|
+
products: { list: () => (async function* () {})() },
|
|
39
|
+
prices: {
|
|
40
|
+
list: () =>
|
|
41
|
+
(async function* () {
|
|
42
|
+
yield* prices;
|
|
43
|
+
})(),
|
|
44
|
+
},
|
|
45
|
+
} as unknown as Stripe;
|
|
46
|
+
for (const price of prices) {
|
|
47
|
+
await processEvent(
|
|
48
|
+
{ stripe, component, ctx } as WebhookContext,
|
|
49
|
+
{
|
|
50
|
+
type: "price.created",
|
|
51
|
+
data: { object: price },
|
|
52
|
+
} as unknown as Stripe.Event,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
await syncAllProducts(stripe, component, ctx);
|
|
56
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
|
|
3
|
+
/** The legacy fixed-price mirror cannot express metered or tiered amounts. */
|
|
4
|
+
export function isFixedPrice(price: Stripe.Price): boolean {
|
|
5
|
+
return (
|
|
6
|
+
price.recurring?.usage_type !== "metered" &&
|
|
7
|
+
price.billing_scheme !== "tiered" &&
|
|
8
|
+
price.transform_quantity == null &&
|
|
9
|
+
typeof price.unit_amount === "number" &&
|
|
10
|
+
Number.isSafeInteger(price.unit_amount) &&
|
|
11
|
+
price.unit_amount >= 0
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFixedPrice } from "./fixedPrice.js";
|
|
1
2
|
import type Stripe from "stripe";
|
|
2
3
|
import { idempotencyOptions } from "../core/idempotency.js";
|
|
3
4
|
|
|
@@ -289,6 +290,7 @@ export async function syncAllProducts(
|
|
|
289
290
|
let pricesSynced = 0;
|
|
290
291
|
const productCache = new Map<string, { _id: string } | null>();
|
|
291
292
|
for await (const price of stripe.prices.list({ limit: 100 })) {
|
|
293
|
+
if (!isFixedPrice(price)) continue;
|
|
292
294
|
try {
|
|
293
295
|
const stripeProductId =
|
|
294
296
|
typeof price.product === "string" ? price.product : "";
|