Skip to content

Commit 8dbbfdb

Browse files
committed
require url for cf workers too
1 parent ff18762 commit 8dbbfdb

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
} from "../core/usageV2.js";
66

77
type UsageV2Options = {
8-
environment: "development" | "production";
8+
usageBaseUrl: string;
99
source: UsageV2Source;
1010
} & (
1111
| { serviceKey: string; thirdwebClientId?: never; thirdwebSecretKey?: never }
@@ -34,23 +34,18 @@ export async function sendUsageV2Events<T extends UsageV2Options>(
3434
: ClientUsageV2Event[],
3535
options: T,
3636
): Promise<void> {
37-
const baseUrl =
38-
options.environment === "production"
39-
? "https://u.thirdweb.com"
40-
: "https://u.thirdweb-dev.com";
41-
4237
// Determine endpoint and auth header based on provided credentials.
4338
let url: string;
4439
const headers: HeadersInit = { "Content-Type": "application/json" };
4540

4641
if (options.serviceKey) {
47-
url = `${baseUrl}/usage-v2/${options.source}`;
42+
url = `${options.usageBaseUrl}/usage-v2/${options.source}`;
4843
headers["x-service-api-key"] = options.serviceKey;
4944
} else if (options.thirdwebSecretKey) {
50-
url = `${baseUrl}/usage-v2/${options.source}/client`;
45+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
5146
headers["x-secret-key"] = options.thirdwebSecretKey;
5247
} else if (options.thirdwebClientId) {
53-
url = `${baseUrl}/usage-v2/${options.source}/client`;
48+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
5449
headers["x-client-id"] = options.thirdwebClientId;
5550
} else {
5651
throw new Error("[UsageV2] No authentication method provided.");

0 commit comments

Comments
 (0)