@thirdweb-dev/service-utils 0.8.11-nightly-47c9c43a875a81aa357ebf3c741f256c317c5cfd-20250301025507 → 0.8.11-nightly-879148f37e61f12e40bdfd8844189944a4df9f83-20250301054921
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.
- package/dist/cjs/cf-worker/usageV2.js +17 -18
- package/dist/cjs/cf-worker/usageV2.js.map +1 -1
- package/dist/esm/cf-worker/usageV2.js +16 -17
- package/dist/esm/cf-worker/usageV2.js.map +1 -1
- package/dist/types/cf-worker/usageV2.d.ts +7 -20
- package/dist/types/cf-worker/usageV2.d.ts.map +1 -1
- package/package.json +1 -1
@@ -1,41 +1,40 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.sendUsageV2Events = sendUsageV2Events;
|
4
|
+
const workers_types_1 = require("@cloudflare/workers-types");
|
5
|
+
const index_js_1 = require("./index.js");
|
4
6
|
/**
|
5
7
|
* Send usageV2 events from either internal services or public clients.
|
6
8
|
*
|
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)
|
11
|
-
*
|
12
|
-
* NOTE: `team_id` is required if `serviceKey` is provided.
|
13
|
-
*
|
14
9
|
* This method may throw. To call this non-blocking:
|
15
10
|
* ```ts
|
16
11
|
* void sendUsageV2Events(...).catch((e) => console.error(e))
|
17
12
|
* ```
|
18
13
|
*/
|
19
14
|
async function sendUsageV2Events(events, options) {
|
15
|
+
const { usageBaseUrl, source, authInput, serviceKey } = options;
|
16
|
+
const { clientId, secretKey } = await (0, index_js_1.extractAuthorizationData)(authInput);
|
17
|
+
// Forward headers from the origin request.
|
20
18
|
// Determine endpoint and auth header based on provided credentials.
|
21
19
|
let url;
|
22
|
-
const headers =
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
const headers = new workers_types_1.Headers(authInput.req.headers);
|
21
|
+
headers.set("Content-Type", "application/json");
|
22
|
+
if (serviceKey) {
|
23
|
+
// If a service key is provided, call the non-public usage endpoint.
|
24
|
+
url = `${usageBaseUrl}/usage-v2/${source}`;
|
25
|
+
headers.set("x-service-api-key", serviceKey);
|
26
26
|
}
|
27
|
-
else if (
|
28
|
-
url = `${
|
29
|
-
headers
|
27
|
+
else if (clientId) {
|
28
|
+
url = `${usageBaseUrl}/usage-v2/${source}/client`;
|
29
|
+
headers.set("x-client-id", clientId);
|
30
30
|
}
|
31
|
-
else if (
|
32
|
-
url = `${
|
33
|
-
headers["x-client-id"] = options.thirdwebClientId;
|
31
|
+
else if (secretKey) {
|
32
|
+
url = `${usageBaseUrl}/usage-v2/${source}/client`;
|
34
33
|
}
|
35
34
|
else {
|
36
35
|
throw new Error("[UsageV2] No authentication method provided.");
|
37
36
|
}
|
38
|
-
const resp = await fetch(url, {
|
37
|
+
const resp = await (0, workers_types_1.fetch)(url, {
|
39
38
|
method: "POST",
|
40
39
|
headers,
|
41
40
|
body: JSON.stringify({ events }),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":";;AAwBA,8CAsCC;AA9DD,6DAAyE;AAOzE,yCAAsD;AAStD;;;;;;;GAOG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAEwB,EACxB,OAAU;IAEV,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,mCAAwB,EAAC,SAAS,CAAC,CAAC;IAE1E,2CAA2C;IAC3C,oEAAoE;IACpE,IAAI,GAAW,CAAC;IAChB,MAAM,OAAO,GAAG,IAAI,uBAAO,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IAChD,IAAI,UAAU,EAAE,CAAC;QACf,oEAAoE;QACpE,GAAG,GAAG,GAAG,YAAY,aAAa,MAAM,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,QAAQ,EAAE,CAAC;QACpB,GAAG,GAAG,GAAG,YAAY,aAAa,MAAM,SAAS,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;SAAM,IAAI,SAAS,EAAE,CAAC;QACrB,GAAG,GAAG,GAAG,YAAY,aAAa,MAAM,SAAS,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAK,EAAC,GAAG,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO;QACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,CAAC,CAAC;IACH,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,33 +1,32 @@
|
|
1
|
+
import { Headers, fetch } from "@cloudflare/workers-types";
|
2
|
+
import { extractAuthorizationData } from "./index.js";
|
1
3
|
/**
|
2
4
|
* Send usageV2 events from either internal services or public clients.
|
3
5
|
*
|
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)
|
8
|
-
*
|
9
|
-
* NOTE: `team_id` is required if `serviceKey` is provided.
|
10
|
-
*
|
11
6
|
* This method may throw. To call this non-blocking:
|
12
7
|
* ```ts
|
13
8
|
* void sendUsageV2Events(...).catch((e) => console.error(e))
|
14
9
|
* ```
|
15
10
|
*/
|
16
11
|
export async function sendUsageV2Events(events, options) {
|
12
|
+
const { usageBaseUrl, source, authInput, serviceKey } = options;
|
13
|
+
const { clientId, secretKey } = await extractAuthorizationData(authInput);
|
14
|
+
// Forward headers from the origin request.
|
17
15
|
// Determine endpoint and auth header based on provided credentials.
|
18
16
|
let url;
|
19
|
-
const headers =
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
const headers = new Headers(authInput.req.headers);
|
18
|
+
headers.set("Content-Type", "application/json");
|
19
|
+
if (serviceKey) {
|
20
|
+
// If a service key is provided, call the non-public usage endpoint.
|
21
|
+
url = `${usageBaseUrl}/usage-v2/${source}`;
|
22
|
+
headers.set("x-service-api-key", serviceKey);
|
23
23
|
}
|
24
|
-
else if (
|
25
|
-
url = `${
|
26
|
-
headers
|
24
|
+
else if (clientId) {
|
25
|
+
url = `${usageBaseUrl}/usage-v2/${source}/client`;
|
26
|
+
headers.set("x-client-id", clientId);
|
27
27
|
}
|
28
|
-
else if (
|
29
|
-
url = `${
|
30
|
-
headers["x-client-id"] = options.thirdwebClientId;
|
28
|
+
else if (secretKey) {
|
29
|
+
url = `${usageBaseUrl}/usage-v2/${source}/client`;
|
31
30
|
}
|
32
31
|
else {
|
33
32
|
throw new Error("[UsageV2] No authentication method provided.");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"usageV2.js","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,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACjC,CAAC,CAAC;IACH,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,30 +1,17 @@
|
|
1
|
+
import { type Request } from "@cloudflare/workers-types";
|
2
|
+
import type { CoreAuthInput } from "../core/types.js";
|
1
3
|
import type { ClientUsageV2Event, UsageV2Event, UsageV2Source } from "../core/usageV2.js";
|
2
4
|
type UsageV2Options = {
|
3
5
|
usageBaseUrl: string;
|
4
6
|
source: UsageV2Source;
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
serviceKey?: never;
|
11
|
-
thirdwebClientId: string;
|
12
|
-
thirdwebSecretKey?: never;
|
13
|
-
} | {
|
14
|
-
serviceKey?: never;
|
15
|
-
thirdwebClientId?: never;
|
16
|
-
thirdwebSecretKey: string;
|
17
|
-
});
|
7
|
+
authInput: CoreAuthInput & {
|
8
|
+
req: Request;
|
9
|
+
};
|
10
|
+
serviceKey?: string;
|
11
|
+
};
|
18
12
|
/**
|
19
13
|
* Send usageV2 events from either internal services or public clients.
|
20
14
|
*
|
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)
|
25
|
-
*
|
26
|
-
* NOTE: `team_id` is required if `serviceKey` is provided.
|
27
|
-
*
|
28
15
|
* This method may throw. To call this non-blocking:
|
29
16
|
* ```ts
|
30
17
|
* void sendUsageV2Events(...).catch((e) => console.error(e))
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,OAAO,EAAS,MAAM,2BAA2B,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAG5B,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,aAAa,GAAG;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAC9D,MAAM,EAAE,CAAC,SAAS;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GACpC,YAAY,EAAE,GACd,kBAAkB,EAAE,EACxB,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thirdweb-dev/service-utils",
|
3
|
-
"version": "0.8.11-nightly-
|
3
|
+
"version": "0.8.11-nightly-879148f37e61f12e40bdfd8844189944a4df9f83-20250301054921",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|