Skip to content

Commit 3d55ff1

Browse files
committed
fix: Fix usageV2 imports, allow sdk source
1 parent ca6c913 commit 3d55ff1

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

.changeset/small-moons-behave.md

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] fix: Add missing CompressionCodecs import

packages/service-utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
},
5353
"devDependencies": {
5454
"@cloudflare/workers-types": "4.20250129.0",
55-
"@types/lz4js": "^0.2.1",
5655
"@types/node": "22.13.0",
5756
"typescript": "5.7.3",
5857
"vitest": "3.0.4"

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { ServiceName } from "../node/index.js";
1+
import type { ServiceName } from "./services.js";
2+
3+
export type UsageV2Source = ServiceName | "sdk";
24

35
export interface UsageV2Event {
46
/**
@@ -53,6 +55,6 @@ export interface UsageV2Event {
5355
[key: string]: boolean | number | string | Date | null | undefined;
5456
}
5557

56-
export function getTopicName(productName: ServiceName) {
57-
return `usage_v2.raw_${productName}`;
58+
export function getTopicName(source: UsageV2Source) {
59+
return `usage_v2.raw_${source}`;
5860
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { randomUUID } from "node:crypto";
22
import { checkServerIdentity } from "node:tls";
33
import {
4-
CompressionCodecs,
54
CompressionTypes,
65
Kafka,
76
type Producer,
87
type ProducerConfig,
98
} from "kafkajs";
109
import { compress, decompress } from "lz4js";
11-
import type { ServiceName } from "../core/services.js";
12-
import { type UsageV2Event, getTopicName } from "../core/usageV2.js";
10+
import {
11+
type UsageV2Event,
12+
type UsageV2Source,
13+
getTopicName,
14+
} from "../core/usageV2.js";
15+
16+
// CompressionCodecs is not exported properly in kafkajs. Source: https://github.com/tulios/kafkajs/issues/1391
17+
import KafkaJS from "kafkajs";
18+
const { CompressionCodecs } = KafkaJS;
1319

1420
/**
1521
* Creates a UsageV2Producer which opens a persistent TCP connection.
@@ -40,9 +46,9 @@ export class UsageV2Producer {
4046
*/
4147
environment: "development" | "production";
4248
/**
43-
* The product "source" where usage is coming from.
49+
* The product where usage is coming from.
4450
*/
45-
productName: ServiceName;
51+
source: UsageV2Source;
4652
/**
4753
* Whether to compress the events.
4854
*/
@@ -54,7 +60,7 @@ export class UsageV2Producer {
5460
const {
5561
producerName,
5662
environment,
57-
productName,
63+
source,
5864
shouldCompress = true,
5965
username,
6066
password,
@@ -78,7 +84,7 @@ export class UsageV2Producer {
7884
},
7985
});
8086

81-
this.topic = getTopicName(productName);
87+
this.topic = getTopicName(source);
8288
this.compression = shouldCompress
8389
? CompressionTypes.LZ4
8490
: CompressionTypes.None;

0 commit comments

Comments
 (0)