@thirdweb-dev/service-utils 0.8.10-nightly-ddbacd100c972f2fcc8633e15d89ae99e10ea5f6-20250226000332 → 0.8.10-nightly-b60d251cd72f72080c3a8d8039bad330a7cda344-20250226053758
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 +3 -6
- package/dist/cjs/cf-worker/usageV2.js.map +1 -1
- package/dist/cjs/core/usageV2.js +8 -1
- package/dist/cjs/core/usageV2.js.map +1 -1
- package/dist/cjs/node/kafka.js +38 -67
- package/dist/cjs/node/kafka.js.map +1 -1
- package/dist/cjs/node/usageV2.js +9 -8
- package/dist/cjs/node/usageV2.js.map +1 -1
- package/dist/esm/cf-worker/usageV2.js +3 -6
- package/dist/esm/cf-worker/usageV2.js.map +1 -1
- package/dist/esm/core/usageV2.js +8 -1
- package/dist/esm/core/usageV2.js.map +1 -1
- package/dist/esm/node/kafka.js +38 -67
- package/dist/esm/node/kafka.js.map +1 -1
- package/dist/esm/node/usageV2.js +9 -8
- package/dist/esm/node/usageV2.js.map +1 -1
- package/dist/types/cf-worker/usageV2.d.ts +1 -1
- package/dist/types/cf-worker/usageV2.d.ts.map +1 -1
- package/dist/types/core/usageV2.d.ts +4 -0
- package/dist/types/core/usageV2.d.ts.map +1 -1
- package/dist/types/node/kafka.d.ts +18 -11
- package/dist/types/node/kafka.d.ts.map +1 -1
- package/dist/types/node/usageV2.d.ts +7 -12
- package/dist/types/node/usageV2.d.ts.map +1 -1
- package/package.json +6 -8
@@ -17,22 +17,19 @@ exports.sendUsageV2Events = sendUsageV2Events;
|
|
17
17
|
* ```
|
18
18
|
*/
|
19
19
|
async function sendUsageV2Events(events, options) {
|
20
|
-
const baseUrl = options.environment === "production"
|
21
|
-
? "https://u.thirdweb.com"
|
22
|
-
: "https://u.thirdweb-dev.com";
|
23
20
|
// Determine endpoint and auth header based on provided credentials.
|
24
21
|
let url;
|
25
22
|
const headers = { "Content-Type": "application/json" };
|
26
23
|
if (options.serviceKey) {
|
27
|
-
url = `${
|
24
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}`;
|
28
25
|
headers["x-service-api-key"] = options.serviceKey;
|
29
26
|
}
|
30
27
|
else if (options.thirdwebSecretKey) {
|
31
|
-
url = `${
|
28
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
|
32
29
|
headers["x-secret-key"] = options.thirdwebSecretKey;
|
33
30
|
}
|
34
31
|
else if (options.thirdwebClientId) {
|
35
|
-
url = `${
|
32
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
|
36
33
|
headers["x-client-id"] = options.thirdwebClientId;
|
37
34
|
}
|
38
35
|
else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":";;AA8BA,
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":";;AA8BA,8CAmCC;AAlDD;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAEwB,EACxB,OAAU;IAEV,oEAAoE;IACpE,IAAI,GAAW,CAAC;IAChB,MAAM,OAAO,GAAgB,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;IAEpE,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,GAAG,GAAG,GAAG,OAAO,CAAC,YAAY,aAAa,OAAO,CAAC,MAAM,EAAE,CAAC;QAC3D,OAAO,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IACpD,CAAC;SAAM,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACrC,GAAG,GAAG,GAAG,OAAO,CAAC,YAAY,aAAa,OAAO,CAAC,MAAM,SAAS,CAAC;QAClE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC;IACtD,CAAC;SAAM,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACpC,GAAG,GAAG,GAAG,OAAO,CAAC,YAAY,aAAa,OAAO,CAAC,MAAM,SAAS,CAAC;QAClE,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"}
|
package/dist/cjs/core/usageV2.js
CHANGED
@@ -13,6 +13,13 @@ exports.USAGE_V2_SOURCES = [
|
|
13
13
|
"wallet",
|
14
14
|
];
|
15
15
|
function getTopicName(source) {
|
16
|
-
|
16
|
+
switch (source) {
|
17
|
+
// Some sources are sent from clients and are written to an "untrusted" table.
|
18
|
+
case "sdk":
|
19
|
+
case "engine":
|
20
|
+
return `usage_v2.untrusted_raw_${source}`;
|
21
|
+
default:
|
22
|
+
return `usage_v2.raw_${source}`;
|
23
|
+
}
|
17
24
|
}
|
18
25
|
//# sourceMappingURL=usageV2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":";;;AAWA,
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":";;;AAWA,oCASC;AApBY,QAAA,gBAAgB,GAAG;IAC9B,SAAS;IACT,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,KAAK;IACL,KAAK;IACL,SAAS;IACT,QAAQ;CACA,CAAC;AAEX,SAAgB,YAAY,CAAC,MAAqB;IAChD,QAAQ,MAAM,EAAE,CAAC;QACf,8EAA8E;QAC9E,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,0BAA0B,MAAM,EAAE,CAAC;QAC5C;YACE,OAAO,gBAAgB,MAAM,EAAE,CAAC;IACpC,CAAC;AACH,CAAC"}
|
package/dist/cjs/node/kafka.js
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.KafkaProducer = void 0;
|
4
|
-
const
|
5
|
-
const kafkajs_1 = require("kafkajs");
|
6
|
-
const lz4js_1 = require("lz4js");
|
7
|
-
// CompressionCodecs is not exported properly in kafkajs. Source: https://github.com/tulios/kafkajs/issues/1391
|
8
|
-
const kafkajs_2 = require("kafkajs");
|
9
|
-
const { CompressionCodecs } = kafkajs_2.default;
|
4
|
+
const kafka_javascript_1 = require("@confluentinc/kafka-javascript");
|
10
5
|
/**
|
11
6
|
* Creates a KafkaProducer which opens a persistent TCP connection.
|
12
7
|
* This class is thread-safe so your service should re-use one instance.
|
@@ -20,87 +15,59 @@ const { CompressionCodecs } = kafkajs_2.default;
|
|
20
15
|
* ```
|
21
16
|
*/
|
22
17
|
class KafkaProducer {
|
23
|
-
constructor(
|
24
|
-
Object.defineProperty(this, "kafka", {
|
25
|
-
enumerable: true,
|
26
|
-
configurable: true,
|
27
|
-
writable: true,
|
28
|
-
value: void 0
|
29
|
-
});
|
18
|
+
constructor(options) {
|
30
19
|
Object.defineProperty(this, "producer", {
|
31
20
|
enumerable: true,
|
32
21
|
configurable: true,
|
33
22
|
writable: true,
|
34
|
-
value:
|
23
|
+
value: void 0
|
35
24
|
});
|
36
|
-
Object.defineProperty(this, "
|
25
|
+
Object.defineProperty(this, "isConnected", {
|
37
26
|
enumerable: true,
|
38
27
|
configurable: true,
|
39
28
|
writable: true,
|
40
|
-
value:
|
29
|
+
value: false
|
41
30
|
});
|
42
|
-
const { producerName,
|
43
|
-
this.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
mechanism: "plain",
|
55
|
-
username,
|
56
|
-
password,
|
57
|
-
},
|
31
|
+
const { producerName, kafkaServers, username, password, config } = options;
|
32
|
+
this.producer = new kafka_javascript_1.KafkaJS.Kafka({}).producer({
|
33
|
+
"client.id": producerName,
|
34
|
+
"bootstrap.servers": kafkaServers,
|
35
|
+
"security.protocol": "sasl_ssl",
|
36
|
+
"sasl.mechanisms": "PLAIN",
|
37
|
+
"sasl.username": username,
|
38
|
+
"sasl.password": password,
|
39
|
+
"compression.codec": "lz4",
|
40
|
+
"allow.auto.create.topics": true,
|
41
|
+
// All configuration can be overridden.
|
42
|
+
...config,
|
58
43
|
});
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
return Buffer.from(compressed);
|
67
|
-
},
|
68
|
-
// biome-ignore lint/style/noRestrictedGlobals: kafkajs expects a Buffer
|
69
|
-
decompress: (buffer) => {
|
70
|
-
const decompressed = (0, lz4js_1.decompress)(buffer);
|
71
|
-
// biome-ignore lint/style/noRestrictedGlobals: kafkajs expects a Buffer
|
72
|
-
return Buffer.from(decompressed);
|
73
|
-
},
|
74
|
-
});
|
75
|
-
}
|
76
|
-
else {
|
77
|
-
this.compression = kafkajs_1.CompressionTypes.None;
|
78
|
-
}
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
47
|
+
*/
|
48
|
+
async connect() {
|
49
|
+
await this.producer.connect();
|
50
|
+
this.isConnected = true;
|
79
51
|
}
|
80
52
|
/**
|
81
53
|
* Send messages to a Kafka topic.
|
82
54
|
* This method may throw. To call this non-blocking:
|
55
|
+
* ```ts
|
56
|
+
* void kafka.send(topic, events).catch((e) => console.error(e))
|
57
|
+
* ```
|
58
|
+
*
|
83
59
|
* @param topic
|
84
60
|
* @param messages
|
85
|
-
* @param configOverrides
|
86
61
|
*/
|
87
|
-
async send(topic, messages
|
88
|
-
if (!this.
|
89
|
-
|
90
|
-
allowAutoTopicCreation: options?.allowAutoTopicCreation ?? false,
|
91
|
-
maxInFlightRequests: options?.maxInFlightRequests ?? 2000,
|
92
|
-
retry: { retries: options?.retries ?? 5 },
|
93
|
-
});
|
94
|
-
await this.producer.connect();
|
62
|
+
async send(topic, messages) {
|
63
|
+
if (!this.isConnected) {
|
64
|
+
await this.connect();
|
95
65
|
}
|
96
66
|
await this.producer.send({
|
97
67
|
topic,
|
98
68
|
messages: messages.map((m) => ({
|
99
69
|
value: JSON.stringify(m),
|
100
70
|
})),
|
101
|
-
compression: this.compression,
|
102
|
-
acks: options?.acks ?? -1, // Default: All brokers must acknowledge
|
103
|
-
timeout: options?.timeout ?? 10_000, // Default: 10 seconds
|
104
71
|
});
|
105
72
|
}
|
106
73
|
/**
|
@@ -108,9 +75,13 @@ class KafkaProducer {
|
|
108
75
|
* Useful when shutting down the service to flush in-flight events.
|
109
76
|
*/
|
110
77
|
async disconnect() {
|
111
|
-
if (this.
|
112
|
-
|
113
|
-
|
78
|
+
if (this.isConnected) {
|
79
|
+
try {
|
80
|
+
await this.producer.flush();
|
81
|
+
await this.producer.disconnect();
|
82
|
+
}
|
83
|
+
catch { }
|
84
|
+
this.isConnected = false;
|
114
85
|
}
|
115
86
|
}
|
116
87
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../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IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AApFD,sCAoFC"}
|
package/dist/cjs/node/usageV2.js
CHANGED
@@ -32,8 +32,7 @@ class UsageV2Producer {
|
|
32
32
|
});
|
33
33
|
this.kafkaProducer = new kafka_js_1.KafkaProducer({
|
34
34
|
producerName: config.producerName,
|
35
|
-
|
36
|
-
shouldCompress: config.shouldCompress,
|
35
|
+
kafkaServers: config.kafkaServers,
|
37
36
|
username: config.username,
|
38
37
|
password: config.password,
|
39
38
|
});
|
@@ -42,23 +41,25 @@ class UsageV2Producer {
|
|
42
41
|
/**
|
43
42
|
* Send usageV2 events.
|
44
43
|
* This method may throw. To call this non-blocking:
|
44
|
+
* ```ts
|
45
|
+
* void usageV2.sendEvents(events).catch((e) => console.error(e))
|
46
|
+
* ```
|
47
|
+
*
|
45
48
|
* @param events
|
46
49
|
*/
|
47
|
-
async sendEvents(events
|
48
|
-
/**
|
49
|
-
* Reference: https://kafka.js.org/docs/producing#producing-messages
|
50
|
-
*/
|
51
|
-
options) {
|
50
|
+
async sendEvents(events) {
|
52
51
|
const parsedEvents = events.map((event) => ({
|
53
52
|
...event,
|
53
|
+
// Default to a generated UUID.
|
54
54
|
id: event.id ?? (0, node_crypto_1.randomUUID)(),
|
55
|
+
// Default to now.
|
55
56
|
created_at: event.created_at ?? new Date(),
|
56
57
|
// Remove the "team_" prefix, if any.
|
57
58
|
team_id: event.team_id.startsWith("team_")
|
58
59
|
? event.team_id.slice(5)
|
59
60
|
: event.team_id,
|
60
61
|
}));
|
61
|
-
await this.kafkaProducer.send(this.topic, parsedEvents
|
62
|
+
await this.kafkaProducer.send(this.topic, parsedEvents);
|
62
63
|
}
|
63
64
|
/**
|
64
65
|
* Disconnects UsageV2Producer.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,mDAI4B;AAC5B,
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,mDAI4B;AAC5B,yCAA2C;AAE3C;;;;;;;;;;;GAWG;AACH,MAAa,eAAe;IAI1B,YAAY,MAgBX;QAnBO;;;;;WAA6B;QAC7B;;;;;WAAc;QAmBpB,IAAI,CAAC,aAAa,GAAG,IAAI,wBAAa,CAAC;YACrC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,IAAA,yBAAY,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,UAAU,CAAC,MAAsB;QACrC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAC1C,GAAG,KAAK;YACR,+BAA+B;YAC/B,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,IAAA,wBAAU,GAAE;YAC5B,kBAAkB;YAClB,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE;YAC1C,qCAAqC;YACrC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;gBACxC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBACxB,CAAC,CAAC,KAAK,CAAC,OAAO;SAClB,CAAC,CAAC,CAAC;QACJ,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;CACF;AA7DD,0CA6DC"}
|
@@ -14,22 +14,19 @@
|
|
14
14
|
* ```
|
15
15
|
*/
|
16
16
|
export async function sendUsageV2Events(events, options) {
|
17
|
-
const baseUrl = options.environment === "production"
|
18
|
-
? "https://u.thirdweb.com"
|
19
|
-
: "https://u.thirdweb-dev.com";
|
20
17
|
// Determine endpoint and auth header based on provided credentials.
|
21
18
|
let url;
|
22
19
|
const headers = { "Content-Type": "application/json" };
|
23
20
|
if (options.serviceKey) {
|
24
|
-
url = `${
|
21
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}`;
|
25
22
|
headers["x-service-api-key"] = options.serviceKey;
|
26
23
|
}
|
27
24
|
else if (options.thirdwebSecretKey) {
|
28
|
-
url = `${
|
25
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
|
29
26
|
headers["x-secret-key"] = options.thirdwebSecretKey;
|
30
27
|
}
|
31
28
|
else if (options.thirdwebClientId) {
|
32
|
-
url = `${
|
29
|
+
url = `${options.usageBaseUrl}/usage-v2/${options.source}/client`;
|
33
30
|
headers["x-client-id"] = options.thirdwebClientId;
|
34
31
|
}
|
35
32
|
else {
|
@@ -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,MAEwB,EACxB,OAAU;IAEV,
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"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AI,EAAE,MAAM,EAAE,CAAC;AACtB,CAAC"}
|
package/dist/esm/core/usageV2.js
CHANGED
@@ -9,6 +9,13 @@ export const USAGE_V2_SOURCES = [
|
|
9
9
|
"wallet",
|
10
10
|
];
|
11
11
|
export function getTopicName(source) {
|
12
|
-
|
12
|
+
switch (source) {
|
13
|
+
// Some sources are sent from clients and are written to an "untrusted" table.
|
14
|
+
case "sdk":
|
15
|
+
case "engine":
|
16
|
+
return `usage_v2.untrusted_raw_${source}`;
|
17
|
+
default:
|
18
|
+
return `usage_v2.raw_${source}`;
|
19
|
+
}
|
13
20
|
}
|
14
21
|
//# sourceMappingURL=usageV2.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,KAAK;IACL,KAAK;IACL,SAAS;IACT,QAAQ;CACA,CAAC;AAEX,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,OAAO,gBAAgB,MAAM,EAAE,CAAC;
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,KAAK;IACL,KAAK;IACL,SAAS;IACT,QAAQ;CACA,CAAC;AAEX,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,QAAQ,MAAM,EAAE,CAAC;QACf,8EAA8E;QAC9E,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,0BAA0B,MAAM,EAAE,CAAC;QAC5C;YACE,OAAO,gBAAgB,MAAM,EAAE,CAAC;IACpC,CAAC;AACH,CAAC"}
|
package/dist/esm/node/kafka.js
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import { CompressionTypes, Kafka } from "kafkajs";
|
3
|
-
import { compress, decompress } from "lz4js";
|
4
|
-
// CompressionCodecs is not exported properly in kafkajs. Source: https://github.com/tulios/kafkajs/issues/1391
|
5
|
-
import KafkaJS from "kafkajs";
|
6
|
-
const { CompressionCodecs } = KafkaJS;
|
1
|
+
import { KafkaJS, } from "@confluentinc/kafka-javascript";
|
7
2
|
/**
|
8
3
|
* Creates a KafkaProducer which opens a persistent TCP connection.
|
9
4
|
* This class is thread-safe so your service should re-use one instance.
|
@@ -17,87 +12,59 @@ const { CompressionCodecs } = KafkaJS;
|
|
17
12
|
* ```
|
18
13
|
*/
|
19
14
|
export class KafkaProducer {
|
20
|
-
constructor(
|
21
|
-
Object.defineProperty(this, "kafka", {
|
22
|
-
enumerable: true,
|
23
|
-
configurable: true,
|
24
|
-
writable: true,
|
25
|
-
value: void 0
|
26
|
-
});
|
15
|
+
constructor(options) {
|
27
16
|
Object.defineProperty(this, "producer", {
|
28
17
|
enumerable: true,
|
29
18
|
configurable: true,
|
30
19
|
writable: true,
|
31
|
-
value:
|
20
|
+
value: void 0
|
32
21
|
});
|
33
|
-
Object.defineProperty(this, "
|
22
|
+
Object.defineProperty(this, "isConnected", {
|
34
23
|
enumerable: true,
|
35
24
|
configurable: true,
|
36
25
|
writable: true,
|
37
|
-
value:
|
26
|
+
value: false
|
38
27
|
});
|
39
|
-
const { producerName,
|
40
|
-
this.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
mechanism: "plain",
|
52
|
-
username,
|
53
|
-
password,
|
54
|
-
},
|
28
|
+
const { producerName, kafkaServers, username, password, config } = options;
|
29
|
+
this.producer = new KafkaJS.Kafka({}).producer({
|
30
|
+
"client.id": producerName,
|
31
|
+
"bootstrap.servers": kafkaServers,
|
32
|
+
"security.protocol": "sasl_ssl",
|
33
|
+
"sasl.mechanisms": "PLAIN",
|
34
|
+
"sasl.username": username,
|
35
|
+
"sasl.password": password,
|
36
|
+
"compression.codec": "lz4",
|
37
|
+
"allow.auto.create.topics": true,
|
38
|
+
// All configuration can be overridden.
|
39
|
+
...config,
|
55
40
|
});
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return Buffer.from(compressed);
|
64
|
-
},
|
65
|
-
// biome-ignore lint/style/noRestrictedGlobals: kafkajs expects a Buffer
|
66
|
-
decompress: (buffer) => {
|
67
|
-
const decompressed = decompress(buffer);
|
68
|
-
// biome-ignore lint/style/noRestrictedGlobals: kafkajs expects a Buffer
|
69
|
-
return Buffer.from(decompressed);
|
70
|
-
},
|
71
|
-
});
|
72
|
-
}
|
73
|
-
else {
|
74
|
-
this.compression = CompressionTypes.None;
|
75
|
-
}
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Connects the producer. Can be called explicitly at the start of your service, or will be called automatically when sending messages.
|
44
|
+
*/
|
45
|
+
async connect() {
|
46
|
+
await this.producer.connect();
|
47
|
+
this.isConnected = true;
|
76
48
|
}
|
77
49
|
/**
|
78
50
|
* Send messages to a Kafka topic.
|
79
51
|
* This method may throw. To call this non-blocking:
|
52
|
+
* ```ts
|
53
|
+
* void kafka.send(topic, events).catch((e) => console.error(e))
|
54
|
+
* ```
|
55
|
+
*
|
80
56
|
* @param topic
|
81
57
|
* @param messages
|
82
|
-
* @param configOverrides
|
83
58
|
*/
|
84
|
-
async send(topic, messages
|
85
|
-
if (!this.
|
86
|
-
|
87
|
-
allowAutoTopicCreation: options?.allowAutoTopicCreation ?? false,
|
88
|
-
maxInFlightRequests: options?.maxInFlightRequests ?? 2000,
|
89
|
-
retry: { retries: options?.retries ?? 5 },
|
90
|
-
});
|
91
|
-
await this.producer.connect();
|
59
|
+
async send(topic, messages) {
|
60
|
+
if (!this.isConnected) {
|
61
|
+
await this.connect();
|
92
62
|
}
|
93
63
|
await this.producer.send({
|
94
64
|
topic,
|
95
65
|
messages: messages.map((m) => ({
|
96
66
|
value: JSON.stringify(m),
|
97
67
|
})),
|
98
|
-
compression: this.compression,
|
99
|
-
acks: options?.acks ?? -1, // Default: All brokers must acknowledge
|
100
|
-
timeout: options?.timeout ?? 10_000, // Default: 10 seconds
|
101
68
|
});
|
102
69
|
}
|
103
70
|
/**
|
@@ -105,9 +72,13 @@ export class KafkaProducer {
|
|
105
72
|
* Useful when shutting down the service to flush in-flight events.
|
106
73
|
*/
|
107
74
|
async disconnect() {
|
108
|
-
if (this.
|
109
|
-
|
110
|
-
|
75
|
+
if (this.isConnected) {
|
76
|
+
try {
|
77
|
+
await this.producer.flush();
|
78
|
+
await this.producer.disconnect();
|
79
|
+
}
|
80
|
+
catch { }
|
81
|
+
this.isConnected = false;
|
111
82
|
}
|
112
83
|
}
|
113
84
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,
|
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;IAIxB,YAAY,OAgBX;QAnBO;;;;;WAA2B;QAC3B;;;;mBAAc,KAAK;WAAC;QAmB1B,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;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CACR,KAAa,EACb,QAAmC;QAEnC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;QAED,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,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
|
package/dist/esm/node/usageV2.js
CHANGED
@@ -29,8 +29,7 @@ export class UsageV2Producer {
|
|
29
29
|
});
|
30
30
|
this.kafkaProducer = new KafkaProducer({
|
31
31
|
producerName: config.producerName,
|
32
|
-
|
33
|
-
shouldCompress: config.shouldCompress,
|
32
|
+
kafkaServers: config.kafkaServers,
|
34
33
|
username: config.username,
|
35
34
|
password: config.password,
|
36
35
|
});
|
@@ -39,23 +38,25 @@ export class UsageV2Producer {
|
|
39
38
|
/**
|
40
39
|
* Send usageV2 events.
|
41
40
|
* This method may throw. To call this non-blocking:
|
41
|
+
* ```ts
|
42
|
+
* void usageV2.sendEvents(events).catch((e) => console.error(e))
|
43
|
+
* ```
|
44
|
+
*
|
42
45
|
* @param events
|
43
46
|
*/
|
44
|
-
async sendEvents(events
|
45
|
-
/**
|
46
|
-
* Reference: https://kafka.js.org/docs/producing#producing-messages
|
47
|
-
*/
|
48
|
-
options) {
|
47
|
+
async sendEvents(events) {
|
49
48
|
const parsedEvents = events.map((event) => ({
|
50
49
|
...event,
|
50
|
+
// Default to a generated UUID.
|
51
51
|
id: event.id ?? randomUUID(),
|
52
|
+
// Default to now.
|
52
53
|
created_at: event.created_at ?? new Date(),
|
53
54
|
// Remove the "team_" prefix, if any.
|
54
55
|
team_id: event.team_id.startsWith("team_")
|
55
56
|
? event.team_id.slice(5)
|
56
57
|
: event.team_id,
|
57
58
|
}));
|
58
|
-
await this.kafkaProducer.send(this.topic, parsedEvents
|
59
|
+
await this.kafkaProducer.send(this.topic, parsedEvents);
|
59
60
|
}
|
60
61
|
/**
|
61
62
|
* Disconnects UsageV2Producer.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAGL,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,
|
1
|
+
{"version":3,"file":"usageV2.js","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAGL,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;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,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,KAAK,cAAc,GAAG;IACpB,
|
1
|
+
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/cf-worker/usageV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,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;;;;;;;;;;;;;;GAcG;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,CA8Bf"}
|
@@ -43,6 +43,10 @@ export interface ClientUsageV2Event {
|
|
43
43
|
* The product version, if available.
|
44
44
|
*/
|
45
45
|
product_version?: string;
|
46
|
+
/**
|
47
|
+
* The event version. Defaults to 1.
|
48
|
+
*/
|
49
|
+
version?: number;
|
46
50
|
/**
|
47
51
|
* An object of arbitrary key-value pairs.
|
48
52
|
* Values can be boolean, number, string, Date, or null.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,wFASnB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9D,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,
|
1
|
+
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/core/usageV2.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,wFASnB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9D,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,UASjD;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,EAAE,CAAC,EAAE,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;IACzD;;OAEG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CACpE;AAED,MAAM,WAAW,YAAa,SAAQ,kBAAkB;IACtD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { type ProducerGlobalConfig } from "@confluentinc/kafka-javascript";
|
1
2
|
/**
|
2
3
|
* Reference: https://kafka.js.org/docs/producing#producing-messages
|
3
4
|
*/
|
@@ -21,33 +22,39 @@ export interface KafkaProducerSendOptions {
|
|
21
22
|
* ```
|
22
23
|
*/
|
23
24
|
export declare class KafkaProducer {
|
24
|
-
private kafka;
|
25
25
|
private producer;
|
26
|
-
private
|
27
|
-
constructor(
|
26
|
+
private isConnected;
|
27
|
+
constructor(options: {
|
28
28
|
/**
|
29
29
|
* A descriptive name for your service. Example: "storage-server"
|
30
30
|
*/
|
31
31
|
producerName: string;
|
32
32
|
/**
|
33
|
-
*
|
33
|
+
* A comma-separated list of `host[:port]` Kafka servers.
|
34
34
|
*/
|
35
|
-
|
36
|
-
/**
|
37
|
-
* Whether to compress the events.
|
38
|
-
*/
|
39
|
-
shouldCompress?: boolean;
|
35
|
+
kafkaServers: string;
|
40
36
|
username: string;
|
41
37
|
password: string;
|
38
|
+
/**
|
39
|
+
* Configuration for the Kafka producer.
|
40
|
+
*/
|
41
|
+
config?: ProducerGlobalConfig;
|
42
42
|
});
|
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
|
+
connect(): Promise<void>;
|
43
47
|
/**
|
44
48
|
* Send messages to a Kafka topic.
|
45
49
|
* This method may throw. To call this non-blocking:
|
50
|
+
* ```ts
|
51
|
+
* void kafka.send(topic, events).catch((e) => console.error(e))
|
52
|
+
* ```
|
53
|
+
*
|
46
54
|
* @param topic
|
47
55
|
* @param messages
|
48
|
-
* @param configOverrides
|
49
56
|
*/
|
50
|
-
send(topic: string, messages: Record<string, unknown>[]
|
57
|
+
send(topic: string, messages: Record<string, unknown>[]): Promise<void>;
|
51
58
|
/**
|
52
59
|
* Disconnects KafkaProducer.
|
53
60
|
* Useful when shutting down the service to flush in-flight events.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../../src/node/kafka.ts"],"names":[],"mappings":"
|
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;IACnC,OAAO,CAAC,WAAW,CAAS;gBAEhB,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;;OAEG;IACG,OAAO;IAKb;;;;;;;;;OASG;IACG,IAAI,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAClC,OAAO,CAAC,IAAI,CAAC;IAahB;;;OAGG;IACG,UAAU;CASjB"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { type UsageV2Event, type UsageV2Source } from "../core/usageV2.js";
|
2
|
-
import { type KafkaProducerSendOptions } from "./kafka.js";
|
3
2
|
/**
|
4
3
|
* Creates a UsageV2Producer which opens a persistent TCP connection.
|
5
4
|
* This class is thread-safe so your service should re-use one instance.
|
@@ -21,30 +20,26 @@ export declare class UsageV2Producer {
|
|
21
20
|
*/
|
22
21
|
producerName: string;
|
23
22
|
/**
|
24
|
-
*
|
23
|
+
* A comma-separated list of `host[:port]` Kafka servers.
|
25
24
|
*/
|
26
|
-
|
25
|
+
kafkaServers: string;
|
27
26
|
/**
|
28
27
|
* The product where usage is coming from.
|
29
28
|
*/
|
30
29
|
source: UsageV2Source;
|
31
|
-
/**
|
32
|
-
* Whether to compress the events.
|
33
|
-
*/
|
34
|
-
shouldCompress?: boolean;
|
35
30
|
username: string;
|
36
31
|
password: string;
|
37
32
|
});
|
38
33
|
/**
|
39
34
|
* Send usageV2 events.
|
40
35
|
* This method may throw. To call this non-blocking:
|
36
|
+
* ```ts
|
37
|
+
* void usageV2.sendEvents(events).catch((e) => console.error(e))
|
38
|
+
* ```
|
39
|
+
*
|
41
40
|
* @param events
|
42
41
|
*/
|
43
|
-
sendEvents(events: UsageV2Event[]
|
44
|
-
/**
|
45
|
-
* Reference: https://kafka.js.org/docs/producing#producing-messages
|
46
|
-
*/
|
47
|
-
options?: KafkaProducerSendOptions): Promise<void>;
|
42
|
+
sendEvents(events: UsageV2Event[]): Promise<void>;
|
48
43
|
/**
|
49
44
|
* Disconnects UsageV2Producer.
|
50
45
|
* Useful when shutting down the service to flush in-flight events.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"usageV2.d.ts","sourceRoot":"","sources":["../../../src/node/usageV2.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,KAAK,CAAS;gBAEV,MAAM,EAAE;QAClB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;QACrB;;WAEG;QACH,MAAM,EAAE,aAAa,CAAC;QAEtB,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB;IAUD;;;;;;;;OAQG;IACG,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAevD;;;OAGG;IACG,UAAU;CAGjB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thirdweb-dev/service-utils",
|
3
|
-
"version": "0.8.10-nightly-
|
3
|
+
"version": "0.8.10-nightly-b60d251cd72f72080c3a8d8039bad330a7cda344-20250226053758",
|
4
4
|
"type": "module",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -45,17 +45,15 @@
|
|
45
45
|
],
|
46
46
|
"sideEffects": false,
|
47
47
|
"dependencies": {
|
48
|
+
"@confluentinc/kafka-javascript": "^1.2.0",
|
48
49
|
"aws4fetch": "1.0.20",
|
49
|
-
"
|
50
|
-
"lz4js": "0.2.0",
|
51
|
-
"zod": "3.24.1"
|
50
|
+
"zod": "3.24.2"
|
52
51
|
},
|
53
52
|
"devDependencies": {
|
54
|
-
"@cloudflare/workers-types": "4.
|
55
|
-
"@types/
|
56
|
-
"@types/node": "22.13.0",
|
53
|
+
"@cloudflare/workers-types": "4.20250224.0",
|
54
|
+
"@types/node": "22.13.5",
|
57
55
|
"typescript": "5.7.3",
|
58
|
-
"vitest": "3.0.
|
56
|
+
"vitest": "3.0.7"
|
59
57
|
},
|
60
58
|
"scripts": {
|
61
59
|
"format": "biome format ./src --write",
|