@thirdweb-dev/service-utils 0.8.8-nightly-cbfe9ec459b33884136ba23a87effd8ab4e99aeb-20250208050920 → 0.8.8-nightly-6f2f92ddea333679ff1962b2df0da4ecf43be966-20250209092734

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,39 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendUsageV2Events = sendUsageV2Events;
4
4
  /**
5
- * Send events to Kafka.
6
- * This method may throw. To call this non-blocking:
5
+ * Send usageV2 events from either internal services or public clients.
6
+ *
7
+ * Exactly one authentication method must be provided:
8
+ * - serviceKey: for internal services
9
+ * - thirdwebClientId: for public clients (MUST be the user's project)
10
+ * - thirdwebSecretKey: for public clients (MUST be the user's project)
7
11
  *
12
+ * This method may throw. To call this non-blocking:
8
13
  * ```ts
9
- * void sendUsageV2Events(events, {
10
- * environment: "production",
11
- * serviceKey: "..."
12
- * }).catch(console.error)
14
+ * void sendUsageV2Events(...).catch((e) => console.error(e))
13
15
  * ```
14
- *
15
- * @param events - The events to send.
16
- * @param options.environment - The environment the service is running in.
17
- * @param options.serviceKey - The service key required for authentication.
18
16
  */
19
17
  async function sendUsageV2Events(events, options) {
20
18
  const baseUrl = options.environment === "production"
21
19
  ? "https://u.thirdweb.com"
22
20
  : "https://u.thirdweb-dev.com";
23
- // Unauthed calls are routed to the /client path
21
+ // Determine endpoint and auth header based on provided credentials.
24
22
  let url;
25
- let headers;
23
+ const headers = { "Content-Type": "application/json" };
26
24
  if (options.serviceKey) {
27
25
  url = `${baseUrl}/usage-v2/${options.source}`;
28
- headers = {
29
- "Content-Type": "application/json",
30
- "x-service-api-key": options.serviceKey,
31
- };
26
+ headers["x-service-api-key"] = options.serviceKey;
32
27
  }
33
- else {
28
+ else if (options.thirdwebSecretKey) {
34
29
  url = `${baseUrl}/usage-v2/${options.source}/client`;
35
- headers = {
36
- "Content-Type": "application/json",
37
- };
30
+ headers["x-secret-key"] = options.thirdwebSecretKey;
31
+ }
32
+ else if (options.thirdwebClientId) {
33
+ url = `${baseUrl}/usage-v2/${options.source}/client`;
34
+ headers["x-client-id"] = options.thirdwebClientId;
35
+ }
36
+ else {
37
+ throw new Error("[UsageV2] No authentication method provided.");
38
38
  }
39
39
  const resp = await fetch(url, {
40
40
  method: "POST",
@@ -42,7 +42,7 @@ async function sendUsageV2Events(events, options) {
42
42
  body: JSON.stringify({ events }),
43
43
  });
44
44
  if (!resp.ok) {
45
- throw new Error(`[UsageV2] unexpected response ${resp.status}: ${await resp.text()}`);
45
+ throw new Error(`[UsageV2] Unexpected response ${resp.status}: ${await resp.text()}`);
46
46
  }
47
47
  resp.body?.cancel();
48
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":";;AAiBA,8CAyCC;AAxDD;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAAsB,EACtB,OAIC;IAED,MAAM,OAAO,GACX,OAAO,CAAC,WAAW,KAAK,YAAY;QAClC,CAAC,CAAC,wBAAwB;QAC1B,CAAC,CAAC,4BAA4B,CAAC;IAEnC,gDAAgD;IAChD,IAAI,GAAW,CAAC;IAChB,IAAI,OAAoB,CAAC;IACzB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,GAAG;YACR,cAAc,EAAE,kBAAkB;YAClC,mBAAmB,EAAE,OAAO,CAAC,UAAU;SACxC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,CAAC,MAAM,SAAS,CAAC;QACrD,OAAO,GAAG;YACR,cAAc,EAAE,kBAAkB;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE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O,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iCAAiC,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,CACrE,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;AACtB,CAAC"}
@@ -1,37 +1,37 @@
1
1
  /**
2
- * Send events to Kafka.
3
- * This method may throw. To call this non-blocking:
2
+ * Send usageV2 events from either internal services or public clients.
3
+ *
4
+ * Exactly one authentication method must be provided:
5
+ * - serviceKey: for internal services
6
+ * - thirdwebClientId: for public clients (MUST be the user's project)
7
+ * - thirdwebSecretKey: for public clients (MUST be the user's project)
4
8
  *
9
+ * This method may throw. To call this non-blocking:
5
10
  * ```ts
6
- * void sendUsageV2Events(events, {
7
- * environment: "production",
8
- * serviceKey: "..."
9
- * }).catch(console.error)
11
+ * void sendUsageV2Events(...).catch((e) => console.error(e))
10
12
  * ```
11
- *
12
- * @param events - The events to send.
13
- * @param options.environment - The environment the service is running in.
14
- * @param options.serviceKey - The service key required for authentication.
15
13
  */
16
14
  export async function sendUsageV2Events(events, options) {
17
15
  const baseUrl = options.environment === "production"
18
16
  ? "https://u.thirdweb.com"
19
17
  : "https://u.thirdweb-dev.com";
20
- // Unauthed calls are routed to the /client path
18
+ // Determine endpoint and auth header based on provided credentials.
21
19
  let url;
22
- let headers;
20
+ const headers = { "Content-Type": "application/json" };
23
21
  if (options.serviceKey) {
24
22
  url = `${baseUrl}/usage-v2/${options.source}`;
25
- headers = {
26
- "Content-Type": "application/json",
27
- "x-service-api-key": options.serviceKey,
28
- };
23
+ headers["x-service-api-key"] = options.serviceKey;
29
24
  }
30
- else {
25
+ else if (options.thirdwebSecretKey) {
31
26
  url = `${baseUrl}/usage-v2/${options.source}/client`;
32
- headers = {
33
- "Content-Type": "application/json",
34
- };
27
+ headers["x-secret-key"] = options.thirdwebSecretKey;
28
+ }
29
+ else if (options.thirdwebClientId) {
30
+ url = `${baseUrl}/usage-v2/${options.source}/client`;
31
+ headers["x-client-id"] = options.thirdwebClientId;
32
+ }
33
+ else {
34
+ throw new Error("[UsageV2] No authentication method provided.");
35
35
  }
36
36
  const resp = await fetch(url, {
37
37
  method: "POST",
@@ -39,7 +39,7 @@ export async function sendUsageV2Events(events, options) {
39
39
  body: JSON.stringify({ events }),
40
40
  });
41
41
  if (!resp.ok) {
42
- throw new Error(`[UsageV2] unexpected response ${resp.status}: ${await resp.text()}`);
42
+ throw new Error(`[UsageV2] Unexpected response ${resp.status}: ${await resp.text()}`);
43
43
  }
44
44
  resp.body?.cancel();
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAsB,EACtB,OAIC;IAED,MAAM,OAAO,GACX,OAAO,CAAC,WAAW,KAAK,YAAY;QAClC,CAAC,CAAC,wBAAwB;QAC1B,CAAC,CAAC,4BAA4B,CAAC;IAEnC,gDAAgD;IAChD,IAAI,GAAW,CAAC;IAChB,IAAI,OAAoB,CAAC;IACzB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,CAAC,MAAM,EAAE,CAAC;QAC9C,OAAO,GAAG;YACR,cAAc,EAAE,kBAAkB;Y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G,GAAG,GAAG,OAAO,aAAa,OAAO,CAAC,MAAM,SAAS,CAAC;QACrD,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACtD,CAAC;SAAM,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACpC,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,CAAC,MAAM,SAAS,CAAC;QACrD,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iCAAiC,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,CACrE,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;AACtB,CAAC"}
@@ -1,22 +1,33 @@
1
1
  import type { UsageV2Event, UsageV2Source } from "../core/usageV2.js";
2
+ type UsageV2Options = {
3
+ environment: "development" | "production";
4
+ source: UsageV2Source;
5
+ } & ({
6
+ serviceKey: string;
7
+ thirdwebClientId?: never;
8
+ thirdwebSecretKey?: never;
9
+ } | {
10
+ serviceKey?: never;
11
+ thirdwebClientId: string;
12
+ thirdwebSecretKey?: never;
13
+ } | {
14
+ serviceKey?: never;
15
+ thirdwebClientId?: never;
16
+ thirdwebSecretKey: string;
17
+ });
2
18
  /**
3
- * Send events to Kafka.
4
- * This method may throw. To call this non-blocking:
19
+ * Send usageV2 events from either internal services or public clients.
20
+ *
21
+ * Exactly one authentication method must be provided:
22
+ * - serviceKey: for internal services
23
+ * - thirdwebClientId: for public clients (MUST be the user's project)
24
+ * - thirdwebSecretKey: for public clients (MUST be the user's project)
5
25
  *
26
+ * This method may throw. To call this non-blocking:
6
27
  * ```ts
7
- * void sendUsageV2Events(events, {
8
- * environment: "production",
9
- * serviceKey: "..."
10
- * }).catch(console.error)
28
+ * void sendUsageV2Events(...).catch((e) => console.error(e))
11
29
  * ```
12
- *
13
- * @param events - The events to send.
14
- * @param options.environment - The environment the service is running in.
15
- * @param options.serviceKey - The service key required for authentication.
16
30
  */
17
- export declare function sendUsageV2Events(events: UsageV2Event[], options: {
18
- environment: "development" | "production";
19
- source: UsageV2Source;
20
- serviceKey?: string;
21
- }): Promise<void>;
31
+ export declare function sendUsageV2Events(events: UsageV2Event[], options: UsageV2Options): Promise<void>;
32
+ export {};
22
33
  //# sourceMappingURL=usageV2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEtE;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE;IACP,WAAW,EAAE,aAAa,GAAG,YAAY,CAAC;IAC1C,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,IAAI,CAAC,CAkCf"}
1
+ {"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEtE,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,aAAa,GAAG,YAAY,CAAC;IAC1C,MAAM,EAAE,aAAa,CAAC;CACvB,GAAG,CACA;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC;IAAC,iBAAiB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC3E;IAAE,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC3E;IAAE,UAAU,CAAC,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAC9E,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAmCf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.8.8-nightly-cbfe9ec459b33884136ba23a87effd8ab4e99aeb-20250208050920",
3
+ "version": "0.8.8-nightly-6f2f92ddea333679ff1962b2df0da4ecf43be966-20250209092734",
4
4
  "type": "module",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",