Skip to content

Commit 821caa6

Browse files
authored
fix: Fix usageV2 imports, allow sdk source (#6164)
1 parent 09e396d commit 821caa6

File tree

5 files changed

+49
-41
lines changed

5 files changed

+49
-41
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: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
},
2727
"typesVersions": {
2828
"*": {
29-
"node": [
30-
"./dist/types/node/index.d.ts"
31-
],
32-
"cf-worker": [
33-
"./dist/types/cf-worker/index.d.ts"
34-
]
29+
"node": ["./dist/types/node/index.d.ts"],
30+
"cf-worker": ["./dist/types/cf-worker/index.d.ts"]
3531
}
3632
},
3733
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/pay",
@@ -40,19 +36,17 @@
4036
"url": "https://github.com/thirdweb-dev/js/issues"
4137
},
4238
"author": "thirdweb eng <eng@thirdweb.com>",
43-
"files": [
44-
"dist/"
45-
],
39+
"files": ["dist/"],
4640
"sideEffects": false,
4741
"dependencies": {
4842
"aws4fetch": "1.0.20",
4943
"kafkajs": "2.2.4",
50-
"lz4js": "^0.2.0",
44+
"lz4js": "0.2.0",
5145
"zod": "3.24.1"
5246
},
5347
"devDependencies": {
5448
"@cloudflare/workers-types": "4.20250129.0",
55-
"@types/lz4js": "^0.2.1",
49+
"@types/lz4js": "0.2.1",
5650
"@types/node": "22.13.0",
5751
"typescript": "5.7.3",
5852
"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;

pnpm-lock.yaml

Lines changed: 21 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)