Skip to content

Commit b60d251

Browse files
authored
[service-utils] fix usageV2 caller (#6346)
1 parent 0595c37 commit b60d251

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

.changeset/social-icons-mix.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] fix usageV2 caller

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.");

packages/service-utils/src/node/usageV2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export class UsageV2Producer {
2828
*/
2929
producerName: string;
3030
/**
31-
* The environment the service is running in.
31+
* A comma-separated list of `host[:port]` Kafka servers.
3232
*/
33-
environment: "development" | "production";
33+
kafkaServers: string;
3434
/**
3535
* The product where usage is coming from.
3636
*/
@@ -41,7 +41,7 @@ export class UsageV2Producer {
4141
}) {
4242
this.kafkaProducer = new KafkaProducer({
4343
producerName: config.producerName,
44-
environment: config.environment,
44+
kafkaServers: config.kafkaServers,
4545
username: config.username,
4646
password: config.password,
4747
});

0 commit comments

Comments
 (0)