Skip to content

Commit f4f93e6

Browse files
authored
[service-utils] ESM imports for compression (#6139)
1 parent b693b78 commit f4f93e6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/service-utils": patch
3+
---
4+
5+
[service-utils] Update to ESM for compression typrse

packages/service-utils/src/node/usageV2.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { randomUUID } from "node:crypto";
22
import { checkServerIdentity } from "node:tls";
33
import {
4+
CompressionCodecs,
45
CompressionTypes,
56
Kafka,
67
type Producer,
@@ -10,10 +11,6 @@ import { compress, decompress } from "lz4js";
1011
import type { ServiceName } from "../core/services.js";
1112
import { type UsageV2Event, getTopicName } from "../core/usageV2.js";
1213

13-
// Import KafkaJS with CJS pattern (source: https://github.com/tulios/kafkajs/issues/1391)
14-
import KafkaJS from "kafkajs";
15-
const { CompressionCodecs } = KafkaJS;
16-
1714
/**
1815
* Creates a UsageV2Producer which opens a persistent TCP connection.
1916
* This class is thread-safe so your service should re-use one instance.
@@ -47,9 +44,9 @@ export class UsageV2Producer {
4744
*/
4845
productName: ServiceName;
4946
/**
50-
* The compression algorithm to use.
47+
* Whether to compress the events.
5148
*/
52-
compression?: CompressionTypes;
49+
shouldCompress?: boolean;
5350

5451
username: string;
5552
password: string;
@@ -58,7 +55,7 @@ export class UsageV2Producer {
5855
producerName,
5956
environment,
6057
productName,
61-
compression = CompressionTypes.LZ4,
58+
shouldCompress = true,
6259
username,
6360
password,
6461
} = config;
@@ -82,7 +79,9 @@ export class UsageV2Producer {
8279
});
8380

8481
this.topic = getTopicName(productName);
85-
this.compression = compression;
82+
this.compression = shouldCompress
83+
? CompressionTypes.LZ4
84+
: CompressionTypes.None;
8685
}
8786

8887
/**

0 commit comments

Comments
 (0)