@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,164 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { expect, it, vi } from "vitest";
|
|
3
|
+
import type { Component } from "../helpers.js";
|
|
4
|
+
import type { WebhookActionCtx } from "../types.js";
|
|
5
|
+
import { componentsGeneric } from "convex/server";
|
|
6
|
+
import { STRIPE_API_VERSION } from "../constants.js";
|
|
7
|
+
const fixture = vi.hoisted(() => ({ stripe: undefined as unknown }));
|
|
8
|
+
vi.mock("./helpers.js", async (importOriginal) => ({
|
|
9
|
+
...(await importOriginal<typeof import("./helpers.js")>()),
|
|
10
|
+
getStripeClient: () => fixture.stripe,
|
|
11
|
+
}));
|
|
12
|
+
import { handleWebhookRequest } from "./handler.js";
|
|
13
|
+
it("verifies and fetches v1 meter thin events without the snapshot parser", async () => {
|
|
14
|
+
const body = JSON.stringify({
|
|
15
|
+
id: "evt_meter_error",
|
|
16
|
+
object: "v2.core.event",
|
|
17
|
+
type: "v1.billing.meter.error_report_triggered",
|
|
18
|
+
livemode: false,
|
|
19
|
+
related_object: { id: "mtr_calls", type: "billing.meter" },
|
|
20
|
+
});
|
|
21
|
+
const parse = vi.fn().mockResolvedValue({});
|
|
22
|
+
const full = {
|
|
23
|
+
id: "evt_meter_error",
|
|
24
|
+
type: "v1.billing.meter.error_report_triggered",
|
|
25
|
+
livemode: false,
|
|
26
|
+
related_object: { id: "mtr_calls", type: "billing.meter" },
|
|
27
|
+
data: {
|
|
28
|
+
reason: {
|
|
29
|
+
error_types: [
|
|
30
|
+
{
|
|
31
|
+
code: "meter_event_invalid_value",
|
|
32
|
+
sample_errors: [
|
|
33
|
+
{
|
|
34
|
+
error_message: "private raw error",
|
|
35
|
+
request: { idempotency_key: "bs_usage_event" },
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
fixture.stripe = {
|
|
44
|
+
parseEventNotificationAsync: parse,
|
|
45
|
+
v2: { core: { events: { retrieve: vi.fn().mockResolvedValue(full) } } },
|
|
46
|
+
accounts: { retrieve: vi.fn().mockResolvedValue({ id: "acct_platform" }) },
|
|
47
|
+
balance: { retrieve: vi.fn().mockResolvedValue({ livemode: false }) },
|
|
48
|
+
webhooks: {
|
|
49
|
+
constructEventAsync: vi.fn().mockRejectedValue(new Error("Wrong parser")),
|
|
50
|
+
},
|
|
51
|
+
} as unknown as Stripe;
|
|
52
|
+
const runMutation = vi.fn(async (_ref, args) =>
|
|
53
|
+
typeof args.stripeEventId === "string" && args.eventType
|
|
54
|
+
? "inserted"
|
|
55
|
+
: { matched: 1, unattributed: 0, truncated: false },
|
|
56
|
+
);
|
|
57
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as WebhookActionCtx;
|
|
58
|
+
const response = await handleWebhookRequest(
|
|
59
|
+
ctx,
|
|
60
|
+
new Request("https://example.test/webhook", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: { "stripe-signature": "verified-fixture" },
|
|
63
|
+
body,
|
|
64
|
+
}),
|
|
65
|
+
componentsGeneric().betterStripe as unknown as Component,
|
|
66
|
+
{
|
|
67
|
+
stripeSecretKey: "sk_test_fixture",
|
|
68
|
+
webhookSecret: "whsec_snapshot",
|
|
69
|
+
webhookSecretV2: "whsec_thin",
|
|
70
|
+
stripeApiVersion: STRIPE_API_VERSION,
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
expect(response.status).toBe(200);
|
|
74
|
+
expect(parse).toHaveBeenCalledWith(body, "verified-fixture", "whsec_thin");
|
|
75
|
+
const report = runMutation.mock.calls.find(([, args]) => args.samples)?.[1];
|
|
76
|
+
expect(report).toMatchObject({
|
|
77
|
+
stripeAccountId: "acct_platform",
|
|
78
|
+
livemode: false,
|
|
79
|
+
meterId: "mtr_calls",
|
|
80
|
+
samples: [
|
|
81
|
+
{ identifier: "bs_usage_event", code: "meter_event_invalid_value" },
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
expect(JSON.stringify(report)).not.toContain("private raw error");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it.each(["event", "account", "balance"])(
|
|
88
|
+
"sanitizes %s retrieval errors before webhook history and logs",
|
|
89
|
+
async (failing) => {
|
|
90
|
+
const privateError = new Error("PRIVATE_PROVIDER_MARKER");
|
|
91
|
+
fixture.stripe = {
|
|
92
|
+
parseEventNotificationAsync: vi.fn().mockResolvedValue({}),
|
|
93
|
+
v2: {
|
|
94
|
+
core: {
|
|
95
|
+
events: {
|
|
96
|
+
retrieve: vi
|
|
97
|
+
.fn()
|
|
98
|
+
.mockImplementation(() =>
|
|
99
|
+
failing === "event"
|
|
100
|
+
? Promise.reject(privateError)
|
|
101
|
+
: Promise.resolve({}),
|
|
102
|
+
),
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
accounts: {
|
|
107
|
+
retrieve: vi
|
|
108
|
+
.fn()
|
|
109
|
+
.mockImplementation(() =>
|
|
110
|
+
failing === "account"
|
|
111
|
+
? Promise.reject(privateError)
|
|
112
|
+
: Promise.resolve({ id: "acct_platform" }),
|
|
113
|
+
),
|
|
114
|
+
},
|
|
115
|
+
balance: {
|
|
116
|
+
retrieve: vi
|
|
117
|
+
.fn()
|
|
118
|
+
.mockImplementation(() =>
|
|
119
|
+
failing === "balance"
|
|
120
|
+
? Promise.reject(privateError)
|
|
121
|
+
: Promise.resolve({ livemode: false }),
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const runMutation = vi.fn(async (_ref, args) =>
|
|
126
|
+
args.eventType ? "inserted" : null,
|
|
127
|
+
);
|
|
128
|
+
const logged = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
129
|
+
try {
|
|
130
|
+
const response = await handleWebhookRequest(
|
|
131
|
+
{ runMutation, runQuery: vi.fn() } as unknown as WebhookActionCtx,
|
|
132
|
+
new Request("https://example.test/webhook", {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: { "stripe-signature": "fixture" },
|
|
135
|
+
body: JSON.stringify({
|
|
136
|
+
id: "evt_private",
|
|
137
|
+
type: "v1.billing.meter.error_report_triggered",
|
|
138
|
+
livemode: false,
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
componentsGeneric().betterStripe as unknown as Component,
|
|
142
|
+
{
|
|
143
|
+
stripeSecretKey: "sk_test_fixture",
|
|
144
|
+
webhookSecret: "whsec_snapshot",
|
|
145
|
+
webhookSecretV2: "whsec_thin",
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
expect(response.status).toBe(500);
|
|
149
|
+
expect(JSON.stringify(runMutation.mock.calls)).not.toContain(
|
|
150
|
+
"PRIVATE_PROVIDER_MARKER",
|
|
151
|
+
);
|
|
152
|
+
expect(
|
|
153
|
+
logged.mock.calls
|
|
154
|
+
.flat()
|
|
155
|
+
.map((value) =>
|
|
156
|
+
value instanceof Error ? value.message : String(value),
|
|
157
|
+
)
|
|
158
|
+
.join(" "),
|
|
159
|
+
).not.toContain("PRIVATE_PROVIDER_MARKER");
|
|
160
|
+
} finally {
|
|
161
|
+
logged.mockRestore();
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { componentRef, type WebhookContext } from "./helpers.js";
|
|
3
|
+
import type { V2ThinEvent } from "../types.js";
|
|
4
|
+
const types = [
|
|
5
|
+
"v1.billing.meter.error_report_triggered",
|
|
6
|
+
"v1.billing.meter.no_meter_found",
|
|
7
|
+
] as const;
|
|
8
|
+
export const isMeterErrorEvent = (type: string) =>
|
|
9
|
+
types.some((value) => value === type);
|
|
10
|
+
const codes = new Set([
|
|
11
|
+
"meter_event_customer_not_found",
|
|
12
|
+
"meter_event_no_customer_defined",
|
|
13
|
+
"meter_event_dimension_count_too_high",
|
|
14
|
+
"archived_meter",
|
|
15
|
+
"timestamp_too_far_in_past",
|
|
16
|
+
"timestamp_in_future",
|
|
17
|
+
"meter_event_value_not_found",
|
|
18
|
+
"meter_event_invalid_value",
|
|
19
|
+
"no_meter",
|
|
20
|
+
]);
|
|
21
|
+
const reportSchema = z.object({
|
|
22
|
+
id: z.string(),
|
|
23
|
+
type: z.enum(types),
|
|
24
|
+
livemode: z.boolean(),
|
|
25
|
+
related_object: z.object({ id: z.string().optional() }).nullish(),
|
|
26
|
+
data: z.object({
|
|
27
|
+
reason: z.object({
|
|
28
|
+
error_types: z
|
|
29
|
+
.array(
|
|
30
|
+
z.object({
|
|
31
|
+
code: z.string(),
|
|
32
|
+
sample_errors: z
|
|
33
|
+
.array(
|
|
34
|
+
z.object({
|
|
35
|
+
request: z
|
|
36
|
+
.object({
|
|
37
|
+
identifier: z.string().optional(),
|
|
38
|
+
idempotency_key: z.string().optional(),
|
|
39
|
+
})
|
|
40
|
+
.optional(),
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
.optional(),
|
|
44
|
+
}),
|
|
45
|
+
)
|
|
46
|
+
.max(1000),
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
async function processMeterErrorEvent(
|
|
51
|
+
whCtx: WebhookContext,
|
|
52
|
+
thin: V2ThinEvent,
|
|
53
|
+
): Promise<void> {
|
|
54
|
+
const { stripe, ctx, component } = whCtx;
|
|
55
|
+
const [raw, account, balance] = await Promise.all([
|
|
56
|
+
stripe.v2.core.events.retrieve(thin.id),
|
|
57
|
+
stripe.accounts.retrieve(null),
|
|
58
|
+
stripe.balance.retrieve(),
|
|
59
|
+
]);
|
|
60
|
+
const parsed = reportSchema.safeParse(raw);
|
|
61
|
+
if (
|
|
62
|
+
!parsed.success ||
|
|
63
|
+
parsed.data.id !== thin.id ||
|
|
64
|
+
parsed.data.type !== thin.type ||
|
|
65
|
+
parsed.data.livemode !== balance.livemode ||
|
|
66
|
+
thin.livemode !== balance.livemode ||
|
|
67
|
+
(thin.context && thin.context !== account.id)
|
|
68
|
+
)
|
|
69
|
+
throw new Error("Native usage error report scope unavailable");
|
|
70
|
+
const report = parsed.data,
|
|
71
|
+
samples: Array<{ identifier: string; code: string }> = [];
|
|
72
|
+
let truncated = false;
|
|
73
|
+
for (const type of report.data.reason.error_types) {
|
|
74
|
+
if (!codes.has(type.code)) {
|
|
75
|
+
truncated = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const error of type.sample_errors ?? []) {
|
|
79
|
+
const identifier =
|
|
80
|
+
error.request?.identifier ?? error.request?.idempotency_key;
|
|
81
|
+
if (
|
|
82
|
+
!identifier ||
|
|
83
|
+
!/^bs_usage_[a-zA-Z0-9_]+$/.test(identifier) ||
|
|
84
|
+
identifier.length > 100
|
|
85
|
+
) {
|
|
86
|
+
truncated = true;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (samples.length >= 100) {
|
|
90
|
+
truncated = true;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
samples.push({ identifier, code: type.code });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await ctx.runMutation(
|
|
97
|
+
componentRef(component, "usageDelivery/mutations/recordErrorReport"),
|
|
98
|
+
{
|
|
99
|
+
stripeAccountId: account.id,
|
|
100
|
+
livemode: report.livemode,
|
|
101
|
+
providerEventId: report.id,
|
|
102
|
+
meterId: report.related_object?.id,
|
|
103
|
+
samples,
|
|
104
|
+
truncated,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function handleMeterErrorEvent(
|
|
110
|
+
whCtx: WebhookContext,
|
|
111
|
+
thin: V2ThinEvent,
|
|
112
|
+
): Promise<void> {
|
|
113
|
+
try {
|
|
114
|
+
await processMeterErrorEvent(whCtx, thin);
|
|
115
|
+
} catch {
|
|
116
|
+
throw new Error("Native usage error report unavailable");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFixedPrice } from "../products/fixedPrice.js";
|
|
1
2
|
import { handleRefundEvent } from "./refundDelivery.js";
|
|
2
3
|
import { handlePayoutEvent } from "./payoutReconciliation.js";
|
|
3
4
|
import { reconcileDisputeMoney } from "./disputeRecovery.js";
|
|
@@ -157,6 +158,7 @@ async function handlePriceEvent(
|
|
|
157
158
|
whCtx: WebhookContext,
|
|
158
159
|
price: Stripe.Price,
|
|
159
160
|
): Promise<void> {
|
|
161
|
+
if (!isFixedPrice(price)) return;
|
|
160
162
|
const { ctx, component, stripe } = whCtx;
|
|
161
163
|
const stripeProductId: string =
|
|
162
164
|
typeof price.product === "string"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isMeterErrorEvent, handleMeterErrorEvent } from "./meterErrors.js";
|
|
1
2
|
import { STRIPE_CUSTOMER_PREVIEW_API_VERSION } from "../apiVersion.js";
|
|
2
3
|
import type Stripe from "stripe";
|
|
3
4
|
|
|
@@ -44,6 +45,10 @@ export async function handleV2Event(
|
|
|
44
45
|
thinEvent: V2ThinEvent,
|
|
45
46
|
): Promise<string | null> {
|
|
46
47
|
const { stripe } = whCtx;
|
|
48
|
+
if (isMeterErrorEvent(thinEvent.type)) {
|
|
49
|
+
await handleMeterErrorEvent(whCtx, thinEvent);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
47
52
|
|
|
48
53
|
if (!thinEvent.type.startsWith("v2.core.account")) {
|
|
49
54
|
console.info(`[better-stripe] Unhandled V2 event type: ${thinEvent.type}`);
|
|
@@ -165,6 +165,15 @@ import type * as settlement_queries from "../settlement/queries.js";
|
|
|
165
165
|
import type * as usage_helpers from "../usage/helpers.js";
|
|
166
166
|
import type * as usage_mutations from "../usage/mutations.js";
|
|
167
167
|
import type * as usage_queries from "../usage/queries.js";
|
|
168
|
+
import type * as usageCatalog_mutations from "../usageCatalog/mutations.js";
|
|
169
|
+
import type * as usageCatalog_queries from "../usageCatalog/queries.js";
|
|
170
|
+
import type * as usageDelivery_bridge from "../usageDelivery/bridge.js";
|
|
171
|
+
import type * as usageDelivery_fields from "../usageDelivery/fields.js";
|
|
172
|
+
import type * as usageDelivery_helpers from "../usageDelivery/helpers.js";
|
|
173
|
+
import type * as usageDelivery_mutations from "../usageDelivery/mutations.js";
|
|
174
|
+
import type * as usageDelivery_queries from "../usageDelivery/queries.js";
|
|
175
|
+
import type * as usageDelivery_steps from "../usageDelivery/steps.js";
|
|
176
|
+
import type * as usageDelivery_workflow from "../usageDelivery/workflow.js";
|
|
168
177
|
import type * as webhooks_mutations from "../webhooks/mutations.js";
|
|
169
178
|
import type * as webhooks_queries from "../webhooks/queries.js";
|
|
170
179
|
import type * as webhooks_validators from "../webhooks/validators.js";
|
|
@@ -334,6 +343,15 @@ const fullApi: ApiFromModules<{
|
|
|
334
343
|
"usage/helpers": typeof usage_helpers;
|
|
335
344
|
"usage/mutations": typeof usage_mutations;
|
|
336
345
|
"usage/queries": typeof usage_queries;
|
|
346
|
+
"usageCatalog/mutations": typeof usageCatalog_mutations;
|
|
347
|
+
"usageCatalog/queries": typeof usageCatalog_queries;
|
|
348
|
+
"usageDelivery/bridge": typeof usageDelivery_bridge;
|
|
349
|
+
"usageDelivery/fields": typeof usageDelivery_fields;
|
|
350
|
+
"usageDelivery/helpers": typeof usageDelivery_helpers;
|
|
351
|
+
"usageDelivery/mutations": typeof usageDelivery_mutations;
|
|
352
|
+
"usageDelivery/queries": typeof usageDelivery_queries;
|
|
353
|
+
"usageDelivery/steps": typeof usageDelivery_steps;
|
|
354
|
+
"usageDelivery/workflow": typeof usageDelivery_workflow;
|
|
337
355
|
"webhooks/mutations": typeof webhooks_mutations;
|
|
338
356
|
"webhooks/queries": typeof webhooks_queries;
|
|
339
357
|
"webhooks/validators": typeof webhooks_validators;
|