Skip to content

Commit

Permalink
[service-utils] fix usageV2 caller (#6346)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Feb 26, 2025
1 parent 0595c37 commit b60d251
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/social-icons-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/service-utils": patch
---

[service-utils] fix usageV2 caller
13 changes: 4 additions & 9 deletions packages/service-utils/src/cf-worker/usageV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "../core/usageV2.js";

type UsageV2Options = {
environment: "development" | "production";
usageBaseUrl: string;
source: UsageV2Source;
} & (
| { serviceKey: string; thirdwebClientId?: never; thirdwebSecretKey?: never }
Expand Down Expand Up @@ -34,23 +34,18 @@ export async function sendUsageV2Events<T extends UsageV2Options>(
: ClientUsageV2Event[],
options: T,
): Promise<void> {
const baseUrl =
options.environment === "production"
? "https://u.thirdweb.com"
: "https://u.thirdweb-dev.com";

// Determine endpoint and auth header based on provided credentials.
let url: string;
const headers: HeadersInit = { "Content-Type": "application/json" };

if (options.serviceKey) {
url = `${baseUrl}/usage-v2/${options.source}`;
url = `${options.usageBaseUrl}/usage-v2/${options.source}`;
headers["x-service-api-key"] = options.serviceKey;
} else if (options.thirdwebSecretKey) {
url = `${baseUrl}/usage-v2/${options.source}/client`;
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
headers["x-secret-key"] = options.thirdwebSecretKey;
} else if (options.thirdwebClientId) {
url = `${baseUrl}/usage-v2/${options.source}/client`;
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
headers["x-client-id"] = options.thirdwebClientId;
} else {
throw new Error("[UsageV2] No authentication method provided.");
Expand Down
6 changes: 3 additions & 3 deletions packages/service-utils/src/node/usageV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export class UsageV2Producer {
*/
producerName: string;
/**
* The environment the service is running in.
* A comma-separated list of `host[:port]` Kafka servers.
*/
environment: "development" | "production";
kafkaServers: string;
/**
* The product where usage is coming from.
*/
Expand All @@ -41,7 +41,7 @@ export class UsageV2Producer {
}) {
this.kafkaProducer = new KafkaProducer({
producerName: config.producerName,
environment: config.environment,
kafkaServers: config.kafkaServers,
username: config.username,
password: config.password,
});
Expand Down

0 comments on commit b60d251

Please sign in to comment.