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/fresh-weeks-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/service-utils": patch
---

[service-utils] Omit team_id for client usageV2 events
16 changes: 12 additions & 4 deletions packages/service-utils/src/cf-worker/usageV2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { UsageV2Event, UsageV2Source } from "../core/usageV2.js";
import type {
ClientUsageV2Event,
UsageV2Event,
UsageV2Source,
} from "../core/usageV2.js";

type UsageV2Options = {
environment: "development" | "production";
Expand All @@ -17,14 +21,18 @@ type UsageV2Options = {
* - thirdwebClientId: for public clients (MUST be the user's project)
* - thirdwebSecretKey: for public clients (MUST be the user's project)
*
* NOTE: `team_id` is required if `serviceKey` is provided.
*
* This method may throw. To call this non-blocking:
* ```ts
* void sendUsageV2Events(...).catch((e) => console.error(e))
* ```
*/
export async function sendUsageV2Events(
events: UsageV2Event[],
options: UsageV2Options,
export async function sendUsageV2Events<T extends UsageV2Options>(
events: T extends { serviceKey: string }
? UsageV2Event[]
: ClientUsageV2Event[],
options: T,
): Promise<void> {
const baseUrl =
options.environment === "production"
Expand Down
13 changes: 8 additions & 5 deletions packages/service-utils/src/core/usageV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getTopicName(source: UsageV2Source) {
return `usage_v2.raw_${source}`;
}

export interface UsageV2Event {
export interface ClientUsageV2Event {
/**
* A unique identifier for the event. Defaults to a random UUID.
* Useful if your service retries sending events.
Expand All @@ -27,10 +27,6 @@ export interface UsageV2Event {
* The action of the event. Example: "upload"
*/
action: string;
/**
* The team ID.
*/
team_id: string;
/**
* The project ID, if available.
*/
Expand Down Expand Up @@ -65,3 +61,10 @@ export interface UsageV2Event {
*/
[key: string]: boolean | number | string | Date | null | undefined;
}

export interface UsageV2Event extends ClientUsageV2Event {
/**
* The team ID.
*/
team_id: string;
}
Loading