Skip to content

Commit f1e9159

Browse files
committed
[service-utils] unauthed UsageV2 route
1 parent 7b2a1a3 commit f1e9159

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

.changeset/metal-crabs-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/service-utils": patch
3+
---
4+
5+
[service-utils] Allow client-side usageV2 reporting

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ export async function sendUsageV2Events(
2828
? "https://u.thirdweb.com"
2929
: "https://u.thirdweb-dev.com";
3030

31-
const headers: HeadersInit = {
32-
"Content-Type": "application/json",
33-
};
31+
// Unauthed calls are routed to the /client path
32+
let url: string;
33+
let headers: HeadersInit;
3434
if (options.serviceKey) {
35-
headers["x-service-api-key"] = options.serviceKey;
35+
url = `${baseUrl}/usage-v2/${options.source}`;
36+
headers = {
37+
"Content-Type": "application/json",
38+
"x-service-api-key": options.serviceKey,
39+
};
40+
} else {
41+
url = `${baseUrl}/usage-v2/${options.source}/client`;
42+
headers = {
43+
"Content-Type": "application/json",
44+
};
3645
}
3746

38-
const resp = await fetch(`${baseUrl}/usage-v2/${options.source}`, {
47+
const resp = await fetch(url, {
3948
method: "POST",
4049
headers,
4150
body: JSON.stringify({ events }),

0 commit comments

Comments
 (0)