Skip to content

Commit 7b2a1a3

Browse files
committed
[service-utils] chore: Enable client-side usageV2 reporting
1 parent fecd3a6 commit 7b2a1a3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

packages/service-utils/src/cf-worker/usageV2.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ServiceName } from "../core/services.js";
2-
import type { UsageV2Event } from "../core/usageV2.js";
1+
import type { UsageV2Event, UsageV2Source } from "../core/usageV2.js";
32

43
/**
54
* Send events to Kafka.
@@ -20,21 +19,25 @@ export async function sendUsageV2Events(
2019
events: UsageV2Event[],
2120
options: {
2221
environment: "development" | "production";
23-
productName: ServiceName;
24-
serviceKey: string;
22+
source: UsageV2Source;
23+
serviceKey?: string;
2524
},
2625
): Promise<void> {
2726
const baseUrl =
2827
options.environment === "production"
2928
? "https://u.thirdweb.com"
3029
: "https://u.thirdweb-dev.com";
3130

32-
const resp = await fetch(`${baseUrl}/usage-v2/${options.productName}`, {
31+
const headers: HeadersInit = {
32+
"Content-Type": "application/json",
33+
};
34+
if (options.serviceKey) {
35+
headers["x-service-api-key"] = options.serviceKey;
36+
}
37+
38+
const resp = await fetch(`${baseUrl}/usage-v2/${options.source}`, {
3339
method: "POST",
34-
headers: {
35-
"Content-Type": "application/json",
36-
"x-service-api-key": options.serviceKey,
37-
},
40+
headers,
3841
body: JSON.stringify({ events }),
3942
});
4043

0 commit comments

Comments
 (0)