Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading