Skip to content

Commit

Permalink
[service-utils] trim project ID prefix (#6382)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Mar 1, 2025
1 parent 31dce55 commit 47c9c43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-onions-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/service-utils": patch
---

[service-utils] trim project ID prefix
11 changes: 9 additions & 2 deletions packages/service-utils/src/node/usageV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
} from "../core/usageV2.js";
import { KafkaProducer } from "./kafka.js";

const TEAM_ID_PREFIX = "team_";
const PROJECT_ID_PREFIX = "prj_";

/**
* Creates a UsageV2Producer which opens a persistent TCP connection.
* This class is thread-safe so your service should re-use one instance.
Expand Down Expand Up @@ -65,9 +68,13 @@ export class UsageV2Producer {
// Default to now.
created_at: event.created_at ?? new Date(),
// Remove the "team_" prefix, if any.
team_id: event.team_id.startsWith("team_")
? event.team_id.slice(5)
team_id: event.team_id.startsWith(TEAM_ID_PREFIX)
? event.team_id.slice(TEAM_ID_PREFIX.length)
: event.team_id,
// Remove the "prj_" prefix, if any.
project_id: event.project_id?.startsWith(PROJECT_ID_PREFIX)
? event.project_id.slice(PROJECT_ID_PREFIX.length)
: event.project_id,
}));
await this.kafkaProducer.send(this.topic, parsedEvents);
}
Expand Down

0 comments on commit 47c9c43

Please sign in to comment.