File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed
packages/service-utils/src/cf-worker Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @thirdweb-dev/service-utils " : patch
3+ ---
4+
5+ [ service-utils] Allow client-side usageV2 reporting
Original file line number Diff line number Diff line change 1- import type { ServiceName } from "../core/services.js" ;
2- import type { UsageV2Event } from "../core/usageV2.js" ;
1+ import type { UsageV2Event , UsageV2Source } from "../core/usageV2.js" ;
32
43/**
54 * Send events to Kafka.
@@ -20,21 +19,34 @@ export async function sendUsageV2Events(
2019 events : UsageV2Event [ ] ,
2120 options : {
2221 environment : "development" | "production" ;
23- productName : ServiceName ;
24- serviceKey : string ;
22+ source : UsageV2Source ;
23+ serviceKey ? : string ;
2524 } ,
2625) : Promise < void > {
2726 const baseUrl =
2827 options . environment === "production"
2928 ? "https://u.thirdweb.com"
3029 : "https://u.thirdweb-dev.com" ;
3130
32- const resp = await fetch ( `${ baseUrl } /usage-v2/${ options . productName } ` , {
33- method : "POST" ,
34- headers : {
31+ // Unauthed calls are routed to the /client path
32+ let url : string ;
33+ let headers : HeadersInit ;
34+ if ( options . serviceKey ) {
35+ url = `${ baseUrl } /usage-v2/${ options . source } ` ;
36+ headers = {
3537 "Content-Type" : "application/json" ,
3638 "x-service-api-key" : options . serviceKey ,
37- } ,
39+ } ;
40+ } else {
41+ url = `${ baseUrl } /usage-v2/${ options . source } /client` ;
42+ headers = {
43+ "Content-Type" : "application/json" ,
44+ } ;
45+ }
46+
47+ const resp = await fetch ( url , {
48+ method : "POST" ,
49+ headers,
3850 body : JSON . stringify ( { events } ) ,
3951 } ) ;
4052
You can’t perform that action at this time.
0 commit comments