Skip to content

Commit 47c9c43

Browse files
authored
[service-utils] trim project ID prefix (#6382)
1 parent 31dce55 commit 47c9c43

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/brown-onions-tickle.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] trim project ID prefix

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
} from "../core/usageV2.js";
77
import { KafkaProducer } from "./kafka.js";
88

9+
const TEAM_ID_PREFIX = "team_";
10+
const PROJECT_ID_PREFIX = "prj_";
11+
912
/**
1013
* Creates a UsageV2Producer which opens a persistent TCP connection.
1114
* This class is thread-safe so your service should re-use one instance.
@@ -65,9 +68,13 @@ export class UsageV2Producer {
6568
// Default to now.
6669
created_at: event.created_at ?? new Date(),
6770
// Remove the "team_" prefix, if any.
68-
team_id: event.team_id.startsWith("team_")
69-
? event.team_id.slice(5)
71+
team_id: event.team_id.startsWith(TEAM_ID_PREFIX)
72+
? event.team_id.slice(TEAM_ID_PREFIX.length)
7073
: event.team_id,
74+
// Remove the "prj_" prefix, if any.
75+
project_id: event.project_id?.startsWith(PROJECT_ID_PREFIX)
76+
? event.project_id.slice(PROJECT_ID_PREFIX.length)
77+
: event.project_id,
7178
}));
7279
await this.kafkaProducer.send(this.topic, parsedEvents);
7380
}

0 commit comments

Comments
 (0)