Skip to content

Commit cad9c74

Browse files
authored
[service-utils] Omit team_id for client usageV2 events (#6213)
1 parent 6f2f92d commit cad9c74

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

.changeset/fresh-weeks-deliver.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] Omit team_id for client usageV2 events

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { UsageV2Event, UsageV2Source } from "../core/usageV2.js";
1+
import type {
2+
ClientUsageV2Event,
3+
UsageV2Event,
4+
UsageV2Source,
5+
} from "../core/usageV2.js";
26

37
type UsageV2Options = {
48
environment: "development" | "production";
@@ -17,14 +21,18 @@ type UsageV2Options = {
1721
* - thirdwebClientId: for public clients (MUST be the user's project)
1822
* - thirdwebSecretKey: for public clients (MUST be the user's project)
1923
*
24+
* NOTE: `team_id` is required if `serviceKey` is provided.
25+
*
2026
* This method may throw. To call this non-blocking:
2127
* ```ts
2228
* void sendUsageV2Events(...).catch((e) => console.error(e))
2329
* ```
2430
*/
25-
export async function sendUsageV2Events(
26-
events: UsageV2Event[],
27-
options: UsageV2Options,
31+
export async function sendUsageV2Events<T extends UsageV2Options>(
32+
events: T extends { serviceKey: string }
33+
? UsageV2Event[]
34+
: ClientUsageV2Event[],
35+
options: T,
2836
): Promise<void> {
2937
const baseUrl =
3038
options.environment === "production"

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function getTopicName(source: UsageV2Source) {
1313
return `usage_v2.raw_${source}`;
1414
}
1515

16-
export interface UsageV2Event {
16+
export interface ClientUsageV2Event {
1717
/**
1818
* A unique identifier for the event. Defaults to a random UUID.
1919
* Useful if your service retries sending events.
@@ -27,10 +27,6 @@ export interface UsageV2Event {
2727
* The action of the event. Example: "upload"
2828
*/
2929
action: string;
30-
/**
31-
* The team ID.
32-
*/
33-
team_id: string;
3430
/**
3531
* The project ID, if available.
3632
*/
@@ -65,3 +61,10 @@ export interface UsageV2Event {
6561
*/
6662
[key: string]: boolean | number | string | Date | null | undefined;
6763
}
64+
65+
export interface UsageV2Event extends ClientUsageV2Event {
66+
/**
67+
* The team ID.
68+
*/
69+
team_id: string;
70+
}

0 commit comments

Comments
 (0)