@fantastic.dev/better-stripe 0.52.0 → 0.54.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 +12 -0
- package/README.md +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +160 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +80 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +160 -2
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +80 -1
- 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 +2 -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 +2 -2
- package/dist/client/usage/client.d.ts.map +1 -1
- package/dist/client/usage/client.js +3 -3
- package/dist/client/usage/client.js.map +1 -1
- package/dist/client/usage/deliveryClient.d.ts +64 -0
- package/dist/client/usage/deliveryClient.d.ts.map +1 -0
- package/dist/client/usage/deliveryClient.js +60 -0
- package/dist/client/usage/deliveryClient.js.map +1 -0
- package/dist/client/usage/deliveryProtocol.d.ts +130 -0
- package/dist/client/usage/deliveryProtocol.d.ts.map +1 -0
- package/dist/client/usage/deliveryProtocol.js +21 -0
- package/dist/client/usage/deliveryProtocol.js.map +1 -0
- package/dist/client/usage/deliveryProvider.d.ts +32 -0
- package/dist/client/usage/deliveryProvider.d.ts.map +1 -0
- package/dist/client/usage/deliveryProvider.js +127 -0
- package/dist/client/usage/deliveryProvider.js.map +1 -0
- package/dist/client/usage/index.d.ts +3 -0
- package/dist/client/usage/index.d.ts.map +1 -1
- package/dist/client/usage/index.js +1 -0
- package/dist/client/usage/index.js.map +1 -1
- package/dist/client/webhooks/handler.d.ts.map +1 -1
- package/dist/client/webhooks/handler.js +2 -1
- package/dist/client/webhooks/handler.js.map +1 -1
- package/dist/client/webhooks/meterErrors.d.ts +5 -0
- package/dist/client/webhooks/meterErrors.d.ts.map +1 -0
- package/dist/client/webhooks/meterErrors.js +98 -0
- package/dist/client/webhooks/meterErrors.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/client/webhooks/v2.d.ts.map +1 -1
- package/dist/client/webhooks/v2.js +5 -0
- package/dist/client/webhooks/v2.js.map +1 -1
- package/dist/component/_generated/api.d.ts +18 -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 +232 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/earnings/triggers.d.ts +150 -2
- 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/refundHistory/queries.d.ts +1 -1
- package/dist/component/schema.d.ts +80 -1
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/schema.d.ts +96 -1
- package/dist/component/usage/schema.d.ts.map +1 -1
- package/dist/component/usage/schema.js +11 -2
- package/dist/component/usage/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/dist/component/usageDelivery/bridge.d.ts +25 -0
- package/dist/component/usageDelivery/bridge.d.ts.map +1 -0
- package/dist/component/usageDelivery/bridge.js +45 -0
- package/dist/component/usageDelivery/bridge.js.map +1 -0
- package/dist/component/usageDelivery/fields.d.ts +78 -0
- package/dist/component/usageDelivery/fields.d.ts.map +1 -0
- package/dist/component/usageDelivery/fields.js +38 -0
- package/dist/component/usageDelivery/fields.js.map +1 -0
- package/dist/component/usageDelivery/helpers.d.ts +83 -0
- package/dist/component/usageDelivery/helpers.d.ts.map +1 -0
- package/dist/component/usageDelivery/helpers.js +63 -0
- package/dist/component/usageDelivery/helpers.js.map +1 -0
- package/dist/component/usageDelivery/mutations.d.ts +97 -0
- package/dist/component/usageDelivery/mutations.d.ts.map +1 -0
- package/dist/component/usageDelivery/mutations.js +153 -0
- package/dist/component/usageDelivery/mutations.js.map +1 -0
- package/dist/component/usageDelivery/queries.d.ts +113 -0
- package/dist/component/usageDelivery/queries.d.ts.map +1 -0
- package/dist/component/usageDelivery/queries.js +22 -0
- package/dist/component/usageDelivery/queries.js.map +1 -0
- package/dist/component/usageDelivery/schema.d.ts +79 -0
- package/dist/component/usageDelivery/schema.d.ts.map +1 -0
- package/dist/component/usageDelivery/schema.js +30 -0
- package/dist/component/usageDelivery/schema.js.map +1 -0
- package/dist/component/usageDelivery/steps.d.ts +85 -0
- package/dist/component/usageDelivery/steps.d.ts.map +1 -0
- package/dist/component/usageDelivery/steps.js +154 -0
- package/dist/component/usageDelivery/steps.js.map +1 -0
- package/dist/component/usageDelivery/workflow.d.ts +15 -0
- package/dist/component/usageDelivery/workflow.d.ts.map +1 -0
- package/dist/component/usageDelivery/workflow.js +28 -0
- package/dist/component/usageDelivery/workflow.js.map +1 -0
- package/docs/README.md +5 -1
- package/docs/metering-setup.md +3 -1
- package/docs/usage-catalog.md +106 -0
- package/docs/usage-delivery.md +143 -0
- package/package.json +4 -2
- package/src/client/index.ts +23 -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 +5 -2
- package/src/client/usage/deliveryClient.ts +130 -0
- package/src/client/usage/deliveryProtocol.ts +26 -0
- package/src/client/usage/deliveryProvider.test.ts +207 -0
- package/src/client/usage/deliveryProvider.ts +155 -0
- package/src/client/usage/index.ts +13 -0
- package/src/client/webhooks/handler.ts +2 -1
- package/src/client/webhooks/meterErrors.test.ts +164 -0
- package/src/client/webhooks/meterErrors.ts +118 -0
- package/src/client/webhooks/processors.ts +2 -0
- package/src/client/webhooks/v2.ts +5 -0
- package/src/component/_generated/api.ts +18 -0
- package/src/component/_generated/component.ts +380 -0
- package/src/component/schema.ts +8 -0
- package/src/component/usage/schema.ts +11 -2
- package/src/component/usageCatalog/mutations.ts +79 -0
- package/src/component/usageCatalog/queries.ts +32 -0
- package/src/component/usageCatalog/schema.ts +21 -0
- package/src/component/usageDelivery/bridge.ts +56 -0
- package/src/component/usageDelivery/concurrency.test.ts +62 -0
- package/src/component/usageDelivery/fields.ts +59 -0
- package/src/component/usageDelivery/helpers.ts +77 -0
- package/src/component/usageDelivery/mutations.ts +185 -0
- package/src/component/usageDelivery/queries.ts +25 -0
- package/src/component/usageDelivery/schema.ts +33 -0
- package/src/component/usageDelivery/steps.ts +171 -0
- package/src/component/usageDelivery/workflow.test.ts +402 -0
- package/src/component/usageDelivery/workflow.ts +36 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/component/usageCatalog/mutations.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;GA6BlB,CAAC;AACH,eAAO,MAAM,QAAQ;;;;;;iBAyCnB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { doc, kind } from "./schema.js";
|
|
4
|
+
function bounded(value, max) {
|
|
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) => q
|
|
18
|
+
.eq("scopeKey", args.scopeKey)
|
|
19
|
+
.eq("kind", args.kind)
|
|
20
|
+
.eq("key", args.key))
|
|
21
|
+
.unique();
|
|
22
|
+
if (existing) {
|
|
23
|
+
if (existing.termsJson !== args.termsJson)
|
|
24
|
+
throw new Error("Immutable usage catalog terms conflict");
|
|
25
|
+
return existing;
|
|
26
|
+
}
|
|
27
|
+
const id = await ctx.db.insert("usageCatalog", {
|
|
28
|
+
...args,
|
|
29
|
+
firstAttemptAt: Math.floor(Date.now() / 1000),
|
|
30
|
+
});
|
|
31
|
+
const result = await ctx.db.get("usageCatalog", id);
|
|
32
|
+
if (!result)
|
|
33
|
+
throw new Error("Usage catalog intent unavailable");
|
|
34
|
+
return result;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
export const complete = mutation({
|
|
38
|
+
args: {
|
|
39
|
+
scopeKey: v.string(),
|
|
40
|
+
kind,
|
|
41
|
+
key: v.string(),
|
|
42
|
+
providerId: v.string(),
|
|
43
|
+
observationJson: v.string(),
|
|
44
|
+
},
|
|
45
|
+
returns: v.null(),
|
|
46
|
+
handler: async (ctx, args) => {
|
|
47
|
+
bounded(args.providerId, 100);
|
|
48
|
+
bounded(args.observationJson, 8192);
|
|
49
|
+
const row = await ctx.db
|
|
50
|
+
.query("usageCatalog")
|
|
51
|
+
.withIndex("by_scope_kind_key", (q) => q
|
|
52
|
+
.eq("scopeKey", args.scopeKey)
|
|
53
|
+
.eq("kind", args.kind)
|
|
54
|
+
.eq("key", args.key))
|
|
55
|
+
.unique();
|
|
56
|
+
if (!row || (row.providerId && row.providerId !== args.providerId))
|
|
57
|
+
throw new Error("Usage catalog reassignment rejected");
|
|
58
|
+
const existing = await ctx.db
|
|
59
|
+
.query("usageCatalog")
|
|
60
|
+
.withIndex("by_scope_kind_provider", (q) => q
|
|
61
|
+
.eq("scopeKey", args.scopeKey)
|
|
62
|
+
.eq("kind", args.kind)
|
|
63
|
+
.eq("providerId", args.providerId))
|
|
64
|
+
.unique();
|
|
65
|
+
if (existing && existing._id !== row._id)
|
|
66
|
+
throw new Error("Usage catalog ownership conflict");
|
|
67
|
+
await ctx.db.patch("usageCatalog", row._id, {
|
|
68
|
+
providerId: args.providerId,
|
|
69
|
+
observationJson: args.observationJson,
|
|
70
|
+
observedAt: Math.floor(Date.now() / 1000),
|
|
71
|
+
});
|
|
72
|
+
return null;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../../src/component/usageCatalog/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,SAAS,OAAO,CAAC,KAAa,EAAE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AU,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;aAC1B,KAAK,CAAC,cAAc,CAAC;aACrB,SAAS,CAAC,wBAAwB,EAAE,CAAC,CAAC,EAAE,EAAE,CACzC,CAAC;aACE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC;aAC7B,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC;aACrB,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CACrC;aACA,MAAM,EAAE,CAAC;QACZ,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG;YACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,GAAG,EAAE;YAC1C,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;SAC1C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const invoke: import("convex/server").RegisteredAction<"internal", {
|
|
2
|
+
apiVersion: string;
|
|
3
|
+
attempt: number;
|
|
4
|
+
definitionVersion: 1;
|
|
5
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
6
|
+
identifier: string;
|
|
7
|
+
scope: {
|
|
8
|
+
customerAccount: string;
|
|
9
|
+
livemode: boolean;
|
|
10
|
+
meterId: string;
|
|
11
|
+
stripeAccountId: string;
|
|
12
|
+
};
|
|
13
|
+
}, Promise<{
|
|
14
|
+
created: number;
|
|
15
|
+
status: "accepted";
|
|
16
|
+
} | {
|
|
17
|
+
status: "rate_limited";
|
|
18
|
+
} | {
|
|
19
|
+
status: "unavailable";
|
|
20
|
+
} | {
|
|
21
|
+
status: "unknown";
|
|
22
|
+
} | {
|
|
23
|
+
status: "rejected";
|
|
24
|
+
}>>;
|
|
25
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/component/usageDelivery/bridge.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;GAuCjB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { anyApi } from "convex/server";
|
|
2
|
+
import { internalAction } from "../_generated/server.js";
|
|
3
|
+
import { request } from "./schema.js";
|
|
4
|
+
import { outcome } from "./fields.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const accepted = z.strictObject({
|
|
7
|
+
status: z.literal("accepted"),
|
|
8
|
+
created: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
9
|
+
});
|
|
10
|
+
const parsedOutcome = z.union([
|
|
11
|
+
accepted,
|
|
12
|
+
z.strictObject({
|
|
13
|
+
status: z.enum(["rate_limited", "unavailable", "unknown", "rejected"]),
|
|
14
|
+
}),
|
|
15
|
+
]);
|
|
16
|
+
export const invoke = internalAction({
|
|
17
|
+
args: request,
|
|
18
|
+
returns: outcome,
|
|
19
|
+
handler: async (ctx, args) => {
|
|
20
|
+
try {
|
|
21
|
+
const { outbox } = await ctx.runQuery(anyApi.usageDelivery.queries.saved, { scope: args.scope, eventId: args.eventId });
|
|
22
|
+
if (outbox.held)
|
|
23
|
+
return { status: "unavailable" };
|
|
24
|
+
if (!outbox.provider ||
|
|
25
|
+
outbox.attempts !== args.attempt ||
|
|
26
|
+
outbox.state !== "sending" ||
|
|
27
|
+
outbox.providerIdentifier !== args.identifier)
|
|
28
|
+
return { status: "unknown" };
|
|
29
|
+
const raw = await ctx.runAction(outbox.provider, args);
|
|
30
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
31
|
+
return { status: "unknown" };
|
|
32
|
+
const result = raw;
|
|
33
|
+
if (Object.keys(result).length !== Object.keys(args).length + 1 ||
|
|
34
|
+
Object.keys(args).some((key) => JSON.stringify(result[key]) !==
|
|
35
|
+
JSON.stringify(args[key])))
|
|
36
|
+
return { status: "unknown" };
|
|
37
|
+
const validated = parsedOutcome.safeParse(result.outcome);
|
|
38
|
+
return validated.success ? validated.data : { status: "unknown" };
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return { status: "unknown" };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -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IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const reason: import("convex/values").VUnion<"administrative_hold" | "delivery_window_expired" | "provider_outcome_unknown" | "provider_rejected" | "provider_unavailable" | "rate_limited" | "retry_exhausted" | "scope_busy", [import("convex/values").VLiteral<"rate_limited", "required">, import("convex/values").VLiteral<"provider_unavailable", "required">, import("convex/values").VLiteral<"provider_outcome_unknown", "required">, import("convex/values").VLiteral<"provider_rejected", "required">, import("convex/values").VLiteral<"retry_exhausted", "required">, import("convex/values").VLiteral<"delivery_window_expired", "required">, import("convex/values").VLiteral<"scope_busy", "required">, import("convex/values").VLiteral<"administrative_hold", "required">], "required", never>;
|
|
2
|
+
export { usageDeliveryOutcomeValidator as outcome } from "../../client/usage/deliveryProtocol.js";
|
|
3
|
+
export declare const deliveryFields: {
|
|
4
|
+
provider: import("convex/values").VString<string | undefined, "optional">;
|
|
5
|
+
workflowId: import("convex/values").VString<string | undefined, "optional">;
|
|
6
|
+
definitionVersion: import("convex/values").VLiteral<1 | undefined, "optional">;
|
|
7
|
+
firstSendAt: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
8
|
+
leaseUntil: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
9
|
+
held: import("convex/values").VBoolean<boolean | undefined, "optional">;
|
|
10
|
+
reason: import("convex/values").VUnion<"administrative_hold" | "delivery_window_expired" | "provider_outcome_unknown" | "provider_rejected" | "provider_unavailable" | "rate_limited" | "retry_exhausted" | "scope_busy" | undefined, [import("convex/values").VLiteral<"rate_limited", "required">, import("convex/values").VLiteral<"provider_unavailable", "required">, import("convex/values").VLiteral<"provider_outcome_unknown", "required">, import("convex/values").VLiteral<"provider_rejected", "required">, import("convex/values").VLiteral<"retry_exhausted", "required">, import("convex/values").VLiteral<"delivery_window_expired", "required">, import("convex/values").VLiteral<"scope_busy", "required">, import("convex/values").VLiteral<"administrative_hold", "required">], "optional", never>;
|
|
11
|
+
receipt: import("convex/values").VObject<{
|
|
12
|
+
created: number;
|
|
13
|
+
identifier: string;
|
|
14
|
+
} | undefined, {
|
|
15
|
+
identifier: import("convex/values").VString<string, "required">;
|
|
16
|
+
created: import("convex/values").VFloat64<number, "required">;
|
|
17
|
+
}, "optional", "created" | "identifier">;
|
|
18
|
+
};
|
|
19
|
+
export declare const locksTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
20
|
+
eventId?: import("convex/values").GenericId<"usageEvents"> | undefined;
|
|
21
|
+
key: string;
|
|
22
|
+
leaseUntil: number;
|
|
23
|
+
nextAttemptAt: number;
|
|
24
|
+
}, {
|
|
25
|
+
key: import("convex/values").VString<string, "required">;
|
|
26
|
+
eventId: import("convex/values").VId<import("convex/values").GenericId<"usageEvents"> | undefined, "optional">;
|
|
27
|
+
leaseUntil: import("convex/values").VFloat64<number, "required">;
|
|
28
|
+
nextAttemptAt: import("convex/values").VFloat64<number, "required">;
|
|
29
|
+
}, "required", "eventId" | "key" | "leaseUntil" | "nextAttemptAt">, {
|
|
30
|
+
by_key: ["key", "_creationTime"];
|
|
31
|
+
}, {}, {}>;
|
|
32
|
+
export declare const errorCode: import("convex/values").VUnion<"archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past", [import("convex/values").VLiteral<"meter_event_customer_not_found", "required">, import("convex/values").VLiteral<"meter_event_no_customer_defined", "required">, import("convex/values").VLiteral<"meter_event_dimension_count_too_high", "required">, import("convex/values").VLiteral<"archived_meter", "required">, import("convex/values").VLiteral<"timestamp_too_far_in_past", "required">, import("convex/values").VLiteral<"timestamp_in_future", "required">, import("convex/values").VLiteral<"meter_event_value_not_found", "required">, import("convex/values").VLiteral<"meter_event_invalid_value", "required">, import("convex/values").VLiteral<"no_meter", "required">], "required", never>;
|
|
33
|
+
export declare const errorFields: {
|
|
34
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
35
|
+
eventId: import("convex/values").VId<import("convex/values").GenericId<"usageEvents">, "required">;
|
|
36
|
+
providerEventId: import("convex/values").VString<string, "required">;
|
|
37
|
+
code: import("convex/values").VUnion<"archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past", [import("convex/values").VLiteral<"meter_event_customer_not_found", "required">, import("convex/values").VLiteral<"meter_event_no_customer_defined", "required">, import("convex/values").VLiteral<"meter_event_dimension_count_too_high", "required">, import("convex/values").VLiteral<"archived_meter", "required">, import("convex/values").VLiteral<"timestamp_too_far_in_past", "required">, import("convex/values").VLiteral<"timestamp_in_future", "required">, import("convex/values").VLiteral<"meter_event_value_not_found", "required">, import("convex/values").VLiteral<"meter_event_invalid_value", "required">, import("convex/values").VLiteral<"no_meter", "required">], "required", never>;
|
|
38
|
+
observedAt: import("convex/values").VFloat64<number, "required">;
|
|
39
|
+
dedupe: import("convex/values").VString<string, "required">;
|
|
40
|
+
};
|
|
41
|
+
export declare const errorDoc: import("convex/values").VObject<{
|
|
42
|
+
_creationTime: number;
|
|
43
|
+
_id: import("convex/values").GenericId<"usageDeliveryErrors">;
|
|
44
|
+
code: "archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past";
|
|
45
|
+
dedupe: string;
|
|
46
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
47
|
+
observedAt: number;
|
|
48
|
+
providerEventId: string;
|
|
49
|
+
scopeKey: string;
|
|
50
|
+
}, {
|
|
51
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
52
|
+
eventId: import("convex/values").VId<import("convex/values").GenericId<"usageEvents">, "required">;
|
|
53
|
+
providerEventId: import("convex/values").VString<string, "required">;
|
|
54
|
+
code: import("convex/values").VUnion<"archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past", [import("convex/values").VLiteral<"meter_event_customer_not_found", "required">, import("convex/values").VLiteral<"meter_event_no_customer_defined", "required">, import("convex/values").VLiteral<"meter_event_dimension_count_too_high", "required">, import("convex/values").VLiteral<"archived_meter", "required">, import("convex/values").VLiteral<"timestamp_too_far_in_past", "required">, import("convex/values").VLiteral<"timestamp_in_future", "required">, import("convex/values").VLiteral<"meter_event_value_not_found", "required">, import("convex/values").VLiteral<"meter_event_invalid_value", "required">, import("convex/values").VLiteral<"no_meter", "required">], "required", never>;
|
|
55
|
+
observedAt: import("convex/values").VFloat64<number, "required">;
|
|
56
|
+
dedupe: import("convex/values").VString<string, "required">;
|
|
57
|
+
_id: import("convex/values").VId<import("convex/values").GenericId<"usageDeliveryErrors">, "required">;
|
|
58
|
+
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
59
|
+
}, "required", "_creationTime" | "_id" | "code" | "dedupe" | "eventId" | "observedAt" | "providerEventId" | "scopeKey">;
|
|
60
|
+
export declare const errorsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
61
|
+
code: "archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past";
|
|
62
|
+
dedupe: string;
|
|
63
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
64
|
+
observedAt: number;
|
|
65
|
+
providerEventId: string;
|
|
66
|
+
scopeKey: string;
|
|
67
|
+
}, {
|
|
68
|
+
scopeKey: import("convex/values").VString<string, "required">;
|
|
69
|
+
eventId: import("convex/values").VId<import("convex/values").GenericId<"usageEvents">, "required">;
|
|
70
|
+
providerEventId: import("convex/values").VString<string, "required">;
|
|
71
|
+
code: import("convex/values").VUnion<"archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past", [import("convex/values").VLiteral<"meter_event_customer_not_found", "required">, import("convex/values").VLiteral<"meter_event_no_customer_defined", "required">, import("convex/values").VLiteral<"meter_event_dimension_count_too_high", "required">, import("convex/values").VLiteral<"archived_meter", "required">, import("convex/values").VLiteral<"timestamp_too_far_in_past", "required">, import("convex/values").VLiteral<"timestamp_in_future", "required">, import("convex/values").VLiteral<"meter_event_value_not_found", "required">, import("convex/values").VLiteral<"meter_event_invalid_value", "required">, import("convex/values").VLiteral<"no_meter", "required">], "required", never>;
|
|
72
|
+
observedAt: import("convex/values").VFloat64<number, "required">;
|
|
73
|
+
dedupe: import("convex/values").VString<string, "required">;
|
|
74
|
+
}, "required", "code" | "dedupe" | "eventId" | "observedAt" | "providerEventId" | "scopeKey">, {
|
|
75
|
+
by_dedupe: ["dedupe", "_creationTime"];
|
|
76
|
+
by_event: ["eventId", "_creationTime"];
|
|
77
|
+
}, {}, {}>;
|
|
78
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/component/usageDelivery/fields.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,owBASlB,CAAC;AACF,OAAO,EAAE,6BAA6B,IAAI,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAClG,eAAO,MAAM,cAAc;IACzB,QAAQ;IACR,UAAU;IACV,iBAAiB;IACjB,WAAW;IACX,UAAU;IACV,IAAI;IACJ,MAAM;IACN,OAAO;;;;;;;CAGR,CAAC;AACF,eAAO,MAAM,UAAU;;;;;;;;;;;;UAKI,CAAC;AAE5B,eAAO,MAAM,SAAS,i9BAUrB,CAAC;AACF,eAAO,MAAM,WAAW;IACtB,QAAQ;IACR,OAAO;IACP,eAAe;IACf,IAAI;IACJ,UAAU;IACV,MAAM;CACP,CAAC;AACF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;uHAInB,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;UAES,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export const reason = v.union(v.literal("rate_limited"), v.literal("provider_unavailable"), v.literal("provider_outcome_unknown"), v.literal("provider_rejected"), v.literal("retry_exhausted"), v.literal("delivery_window_expired"), v.literal("scope_busy"), v.literal("administrative_hold"));
|
|
4
|
+
export { usageDeliveryOutcomeValidator as outcome } from "../../client/usage/deliveryProtocol.js";
|
|
5
|
+
export const deliveryFields = {
|
|
6
|
+
provider: v.optional(v.string()),
|
|
7
|
+
workflowId: v.optional(v.string()),
|
|
8
|
+
definitionVersion: v.optional(v.literal(1)),
|
|
9
|
+
firstSendAt: v.optional(v.number()),
|
|
10
|
+
leaseUntil: v.optional(v.number()),
|
|
11
|
+
held: v.optional(v.boolean()),
|
|
12
|
+
reason: v.optional(reason),
|
|
13
|
+
receipt: v.optional(v.object({ identifier: v.string(), created: v.number() })),
|
|
14
|
+
};
|
|
15
|
+
export const locksTable = defineTable({
|
|
16
|
+
key: v.string(),
|
|
17
|
+
eventId: v.optional(v.id("usageEvents")),
|
|
18
|
+
leaseUntil: v.number(),
|
|
19
|
+
nextAttemptAt: v.number(),
|
|
20
|
+
}).index("by_key", ["key"]);
|
|
21
|
+
export const errorCode = v.union(v.literal("meter_event_customer_not_found"), v.literal("meter_event_no_customer_defined"), v.literal("meter_event_dimension_count_too_high"), v.literal("archived_meter"), v.literal("timestamp_too_far_in_past"), v.literal("timestamp_in_future"), v.literal("meter_event_value_not_found"), v.literal("meter_event_invalid_value"), v.literal("no_meter"));
|
|
22
|
+
export const errorFields = {
|
|
23
|
+
scopeKey: v.string(),
|
|
24
|
+
eventId: v.id("usageEvents"),
|
|
25
|
+
providerEventId: v.string(),
|
|
26
|
+
code: errorCode,
|
|
27
|
+
observedAt: v.number(),
|
|
28
|
+
dedupe: v.string(),
|
|
29
|
+
};
|
|
30
|
+
export const errorDoc = v.object({
|
|
31
|
+
_id: v.id("usageDeliveryErrors"),
|
|
32
|
+
_creationTime: v.number(),
|
|
33
|
+
...errorFields,
|
|
34
|
+
});
|
|
35
|
+
export const errorsTable = defineTable(errorFields)
|
|
36
|
+
.index("by_dedupe", ["dedupe"])
|
|
37
|
+
.index("by_event", ["eventId"]);
|
|
38
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/component/usageDelivery/fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAC3B,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,EACzB,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,EACjC,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,EACrC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAC9B,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAC5B,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,EACpC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EACvB,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CACjC,CAAC;AACF,OAAO,EAAE,6BAA6B,IAAI,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,UA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C,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAChC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,EACxC,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC,EACtC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CACtB,CAAC;AACF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC;IAC5B,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE;IAC3B,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,qBAAqB,CAAC;IAChC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,GAAG,WAAW;CACf,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC;KAChD,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC;KAC9B,KAAK,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { QueryCtx } from "../_generated/server.js";
|
|
2
|
+
import type { Doc, Id } from "../_generated/dataModel.js";
|
|
3
|
+
import type { UsageScope, PreparedUsageRecord } from "../../client/usage/records.js";
|
|
4
|
+
export declare function read(ctx: QueryCtx, args: {
|
|
5
|
+
scope: UsageScope;
|
|
6
|
+
eventId: Id<"usageEvents">;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
event: {
|
|
9
|
+
_creationTime: number;
|
|
10
|
+
_id: import("convex/values").GenericId<"usageEvents">;
|
|
11
|
+
acceptedAt: number;
|
|
12
|
+
identity: string;
|
|
13
|
+
occurredAt: number;
|
|
14
|
+
recordJson: string;
|
|
15
|
+
reservationId?: import("convex/values").GenericId<"usageReservations"> | undefined;
|
|
16
|
+
scopeKey: string;
|
|
17
|
+
subscriptionJson: string;
|
|
18
|
+
};
|
|
19
|
+
outbox: {
|
|
20
|
+
_creationTime: number;
|
|
21
|
+
_id: import("convex/values").GenericId<"usageOutbox">;
|
|
22
|
+
attempts: number;
|
|
23
|
+
definitionVersion?: 1 | undefined;
|
|
24
|
+
dispatch?: string | undefined;
|
|
25
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
26
|
+
firstSendAt?: number | undefined;
|
|
27
|
+
held?: boolean | undefined;
|
|
28
|
+
leaseUntil?: number | undefined;
|
|
29
|
+
nextAttemptAt: number;
|
|
30
|
+
provider?: string | undefined;
|
|
31
|
+
providerIdentifier: string;
|
|
32
|
+
reason?: "administrative_hold" | "delivery_window_expired" | "provider_outcome_unknown" | "provider_rejected" | "provider_unavailable" | "rate_limited" | "retry_exhausted" | "scope_busy" | undefined;
|
|
33
|
+
receipt?: {
|
|
34
|
+
created: number;
|
|
35
|
+
identifier: string;
|
|
36
|
+
} | undefined;
|
|
37
|
+
scopeKey: string;
|
|
38
|
+
state: "held" | "provider_accepted" | "queued" | "rejected" | "sending" | "unknown";
|
|
39
|
+
workflowId?: string | undefined;
|
|
40
|
+
};
|
|
41
|
+
record: PreparedUsageRecord;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function statusOf(outbox: Doc<"usageOutbox">): {
|
|
44
|
+
validationErrors: Array<{
|
|
45
|
+
providerEventId: string;
|
|
46
|
+
code: import("convex/values").Infer<typeof import("./fields.js").errorCode>;
|
|
47
|
+
observedAt: number;
|
|
48
|
+
}>;
|
|
49
|
+
validationHistoryComplete: boolean;
|
|
50
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
51
|
+
state: "held" | "provider_accepted" | "queued" | "rejected" | "sending" | "unknown";
|
|
52
|
+
attempts: number;
|
|
53
|
+
held: boolean;
|
|
54
|
+
reason: "administrative_hold" | "delivery_window_expired" | "provider_outcome_unknown" | "provider_rejected" | "provider_unavailable" | "rate_limited" | "retry_exhausted" | "scope_busy" | undefined;
|
|
55
|
+
providerIdentifier: string;
|
|
56
|
+
receipt: {
|
|
57
|
+
created: number;
|
|
58
|
+
identifier: string;
|
|
59
|
+
} | undefined;
|
|
60
|
+
};
|
|
61
|
+
export declare function lockKeys(record: PreparedUsageRecord): {
|
|
62
|
+
realm: string;
|
|
63
|
+
customer: string;
|
|
64
|
+
};
|
|
65
|
+
export declare function currentStatus(ctx: QueryCtx, outbox: Doc<"usageOutbox">): Promise<{
|
|
66
|
+
eventId: import("convex/values").GenericId<"usageEvents">;
|
|
67
|
+
state: "held" | "provider_accepted" | "queued" | "rejected" | "sending" | "unknown";
|
|
68
|
+
attempts: number;
|
|
69
|
+
held: boolean;
|
|
70
|
+
reason: "administrative_hold" | "delivery_window_expired" | "provider_outcome_unknown" | "provider_rejected" | "provider_unavailable" | "rate_limited" | "retry_exhausted" | "scope_busy" | undefined;
|
|
71
|
+
providerIdentifier: string;
|
|
72
|
+
receipt: {
|
|
73
|
+
created: number;
|
|
74
|
+
identifier: string;
|
|
75
|
+
} | undefined;
|
|
76
|
+
validationErrors: {
|
|
77
|
+
providerEventId: string;
|
|
78
|
+
code: "archived_meter" | "meter_event_customer_not_found" | "meter_event_dimension_count_too_high" | "meter_event_invalid_value" | "meter_event_no_customer_defined" | "meter_event_value_not_found" | "no_meter" | "timestamp_in_future" | "timestamp_too_far_in_past";
|
|
79
|
+
observedAt: number;
|
|
80
|
+
}[];
|
|
81
|
+
validationHistoryComplete: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/component/usageDelivery/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AAEvC,wBAAsB,IAAI,CACxB,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAab,mBAAmB;GAE9D;AACD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC;IAE/C,gBAAgB,EAAQ,KAAK,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,OAAO,eAAe,EAAE,KAAK,CACjC,cAAc,aAAa,EAAE,SAAS,CACvC,CAAC;QACF,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,yBAAyB;IACzB,OAAO;IACP,KAAK;IACL,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,kBAAkB;IAClB,OAAO;;;;EAEV;AACD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,mBAAmB;;;EAanD;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;GAiB5E"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { scopeKey } from "../usage/helpers.js";
|
|
2
|
+
export async function read(ctx, args) {
|
|
3
|
+
const event = await ctx.db.get("usageEvents", args.eventId);
|
|
4
|
+
if (!event || event.scopeKey !== scopeKey(args.scope))
|
|
5
|
+
throw new Error("Usage delivery scope unavailable");
|
|
6
|
+
const outbox = await ctx.db
|
|
7
|
+
.query("usageOutbox")
|
|
8
|
+
.withIndex("by_event", (q) => q.eq("eventId", event._id))
|
|
9
|
+
.unique();
|
|
10
|
+
if (!outbox)
|
|
11
|
+
throw new Error("Usage outbox unavailable");
|
|
12
|
+
return {
|
|
13
|
+
event,
|
|
14
|
+
outbox,
|
|
15
|
+
record: JSON.parse(event.recordJson),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function statusOf(outbox) {
|
|
19
|
+
return {
|
|
20
|
+
validationErrors: [],
|
|
21
|
+
validationHistoryComplete: true,
|
|
22
|
+
eventId: outbox.eventId,
|
|
23
|
+
state: outbox.state,
|
|
24
|
+
attempts: outbox.attempts,
|
|
25
|
+
held: outbox.held ?? false,
|
|
26
|
+
reason: outbox.reason,
|
|
27
|
+
providerIdentifier: outbox.providerIdentifier,
|
|
28
|
+
receipt: outbox.receipt,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function lockKeys(record) {
|
|
32
|
+
const realm = JSON.stringify([
|
|
33
|
+
record.scope.stripeAccountId,
|
|
34
|
+
record.scope.livemode,
|
|
35
|
+
]);
|
|
36
|
+
return {
|
|
37
|
+
realm,
|
|
38
|
+
customer: JSON.stringify([
|
|
39
|
+
realm,
|
|
40
|
+
record.binding.stripeCustomerId,
|
|
41
|
+
record.scope.meterId,
|
|
42
|
+
]),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export async function currentStatus(ctx, outbox) {
|
|
46
|
+
const errors = await ctx.db
|
|
47
|
+
.query("usageDeliveryErrors")
|
|
48
|
+
.withIndex("by_event", (q) => q.eq("eventId", outbox.eventId))
|
|
49
|
+
.order("desc")
|
|
50
|
+
.take(21);
|
|
51
|
+
return {
|
|
52
|
+
...statusOf(outbox),
|
|
53
|
+
validationErrors: errors
|
|
54
|
+
.slice(0, 20)
|
|
55
|
+
.map(({ providerEventId, code, observedAt }) => ({
|
|
56
|
+
providerEventId,
|
|
57
|
+
code,
|
|
58
|
+
observedAt,
|
|
59
|
+
})),
|
|
60
|
+
validationHistoryComplete: errors.length <= 20,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=helpers.js.map
|