@thirdweb-dev/service-utils 0.8.11-nightly-47c9c43a875a81aa357ebf3c741f256c317c5cfd-20250301025507 → 0.8.11-nightly-80ae08bd5a0b544f597abe490845ff9c21df2cf3-20250301121433
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/cjs/node/kafka.js +17 -14
- package/dist/cjs/node/kafka.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/esm/node/kafka.js +17 -14
- package/dist/esm/node/kafka.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/dist/types/node/kafka.d.ts +3 -1
- package/dist/types/node/kafka.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,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tB,CAAC"}
|
package/dist/cjs/node/kafka.js
CHANGED
@@ -22,11 +22,12 @@ class KafkaProducer {
|
|
22
22
|
writable: true,
|
23
23
|
value: void 0
|
24
24
|
});
|
25
|
-
|
25
|
+
// Use a promise to ensure `connect()` is called at most once.
|
26
|
+
Object.defineProperty(this, "connectPromise", {
|
26
27
|
enumerable: true,
|
27
28
|
configurable: true,
|
28
29
|
writable: true,
|
29
|
-
value:
|
30
|
+
value: void 0
|
30
31
|
});
|
31
32
|
const { producerName, kafkaServers, username, password, config } = options;
|
32
33
|
this.producer = new kafka_javascript_1.KafkaJS.Kafka({}).producer({
|
@@ -44,10 +45,17 @@ class KafkaProducer {
|
|
44
45
|
}
|
45
46
|
/**
|
46
47
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
48
|
+
*
|
49
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
47
50
|
*/
|
48
51
|
async connect() {
|
49
|
-
|
50
|
-
|
52
|
+
if (!this.connectPromise) {
|
53
|
+
this.connectPromise = this.producer.connect().catch((err) => {
|
54
|
+
this.connectPromise = undefined;
|
55
|
+
throw err;
|
56
|
+
});
|
57
|
+
}
|
58
|
+
await this.connectPromise;
|
51
59
|
}
|
52
60
|
/**
|
53
61
|
* Send messages to a Kafka topic.
|
@@ -60,9 +68,7 @@ class KafkaProducer {
|
|
60
68
|
* @param messages
|
61
69
|
*/
|
62
70
|
async send(topic, messages) {
|
63
|
-
|
64
|
-
await this.connect();
|
65
|
-
}
|
71
|
+
await this.connect();
|
66
72
|
await this.producer.send({
|
67
73
|
topic,
|
68
74
|
messages: messages.map((m) => ({
|
@@ -75,14 +81,11 @@ class KafkaProducer {
|
|
75
81
|
* Useful when shutting down the service to flush in-flight events.
|
76
82
|
*/
|
77
83
|
async disconnect() {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
await this.producer.disconnect();
|
82
|
-
}
|
83
|
-
catch { }
|
84
|
-
this.isConnected = false;
|
84
|
+
try {
|
85
|
+
await this.producer.flush();
|
86
|
+
await this.producer.disconnect();
|
85
87
|
}
|
88
|
+
catch { }
|
86
89
|
}
|
87
90
|
}
|
88
91
|
exports.KafkaProducer = KafkaProducer;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":";;;AAAA,qEAGwC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;
|
1
|
+
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":";;;AAAA,qEAGwC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAa,aAAa;IAKxB,YAAY,OAgBX;QApBO;;;;;WAA2B;QACnC,8DAA8D;QACtD;;;;;WAA+B;QAmBrC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3E,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC;YAC7C,WAAW,EAAE,YAAY;YACzB,mBAAmB,EAAE,YAAY;YACjC,mBAAmB,EAAE,UAAU;YAC/B,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,QAAQ;YACzB,eAAe,EAAE,QAAQ;YACzB,mBAAmB,EAAE,KAAK;YAC1B,0BAA0B,EAAE,IAAI;YAChC,uCAAuC;YACvC,GAAG,MAAM;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC1D,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;gBAChC,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CACR,KAAa,EACb,QAAmC;QAEnC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACvB,KAAK;YACL,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC7B,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;CACF;AAvFD,sCAuFC"}
|
@@ -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","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAOzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAStD;;;;;;;GAOG;AACH,MAAM,CAAC,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,wBAAw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21
21
|
});
|
22
|
-
|
22
|
+
// Use a promise to ensure `connect()` is called at most once.
|
23
|
+
Object.defineProperty(this, "connectPromise", {
|
23
24
|
enumerable: true,
|
24
25
|
configurable: true,
|
25
26
|
writable: true,
|
26
|
-
value:
|
27
|
+
value: void 0
|
27
28
|
});
|
28
29
|
const { producerName, kafkaServers, username, password, config } = options;
|
29
30
|
this.producer = new KafkaJS.Kafka({}).producer({
|
@@ -41,10 +42,17 @@ export class KafkaProducer {
|
|
41
42
|
}
|
42
43
|
/**
|
43
44
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
45
|
+
*
|
46
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
44
47
|
*/
|
45
48
|
async connect() {
|
46
|
-
|
47
|
-
|
49
|
+
if (!this.connectPromise) {
|
50
|
+
this.connectPromise = this.producer.connect().catch((err) => {
|
51
|
+
this.connectPromise = undefined;
|
52
|
+
throw err;
|
53
|
+
});
|
54
|
+
}
|
55
|
+
await this.connectPromise;
|
48
56
|
}
|
49
57
|
/**
|
50
58
|
* Send messages to a Kafka topic.
|
@@ -57,9 +65,7 @@ export class KafkaProducer {
|
|
57
65
|
* @param messages
|
58
66
|
*/
|
59
67
|
async send(topic, messages) {
|
60
|
-
|
61
|
-
await this.connect();
|
62
|
-
}
|
68
|
+
await this.connect();
|
63
69
|
await this.producer.send({
|
64
70
|
topic,
|
65
71
|
messages: messages.map((m) => ({
|
@@ -72,14 +78,11 @@ export class KafkaProducer {
|
|
72
78
|
* Useful when shutting down the service to flush in-flight events.
|
73
79
|
*/
|
74
80
|
async disconnect() {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
await this.producer.disconnect();
|
79
|
-
}
|
80
|
-
catch { }
|
81
|
-
this.isConnected = false;
|
81
|
+
try {
|
82
|
+
await this.producer.flush();
|
83
|
+
await this.producer.disconnect();
|
82
84
|
}
|
85
|
+
catch { }
|
83
86
|
}
|
84
87
|
}
|
85
88
|
//# sourceMappingURL=kafka.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAER,MAAM,gCAAgC,CAAC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;
|
1
|
+
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAER,MAAM,gCAAgC,CAAC;AAgBxC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IAKxB,YAAY,OAgBX;QApBO;;;;;WAA2B;QACnC,8DAA8D;QACtD;;;;;WAA+B;QAmBrC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3E,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC;YAC7C,WAAW,EAAE,YAAY;YACzB,mBAAmB,EAAE,YAAY;YACjC,mBAAmB,EAAE,UAAU;YAC/B,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,QAAQ;YACzB,eAAe,EAAE,QAAQ;YACzB,mBAAmB,EAAE,KAAK;YAC1B,0BAA0B,EAAE,IAAI;YAChC,uCAAuC;YACvC,GAAG,MAAM;SACV,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC1D,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;gBAChC,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,cAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CACR,KAAa,EACb,QAAmC;QAEnC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACvB,KAAK;YACL,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC7B,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;aACzB,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;CACF"}
|
@@ -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"}
|
@@ -23,7 +23,7 @@ export interface KafkaProducerSendOptions {
|
|
23
23
|
*/
|
24
24
|
export declare class KafkaProducer {
|
25
25
|
private producer;
|
26
|
-
private
|
26
|
+
private connectPromise?;
|
27
27
|
constructor(options: {
|
28
28
|
/**
|
29
29
|
* A descriptive name for your service. Example: "storage-server"
|
@@ -42,6 +42,8 @@ export declare class KafkaProducer {
|
|
42
42
|
});
|
43
43
|
/**
|
44
44
|
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
45
|
+
*
|
46
|
+
* A cached promise is used so this function is safe to call more than once and concurrently.
|
45
47
|
*/
|
46
48
|
connect(): Promise<void>;
|
47
49
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IAEvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAmB;
|
1
|
+
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IAEvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAmB;IAEnC,OAAO,CAAC,cAAc,CAAC,CAAgB;gBAE3B,OAAO,EAAE;QACnB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QAEjB;;WAEG;QACH,MAAM,CAAC,EAAE,oBAAoB,CAAC;KAC/B;IAiBD;;;;OAIG;IACG,OAAO;IAUb;;;;;;;;;OASG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAClC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;OAGG;IACG,UAAU;CAMjB"}
|
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-80ae08bd5a0b544f597abe490845ff9c21df2cf3-20250301121433",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|