Skip to content

Commit a9cd835

Browse files
committed
feat: use machineid library
1 parent f18b916 commit a9cd835

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"jest-environment-node": "^29.7.0",
4848
"jest-extended": "^4.0.2",
4949
"mongodb-runner": "^5.8.2",
50+
"native-machine-id": "^0.0.8",
5051
"openapi-types": "^12.1.3",
5152
"openapi-typescript": "^7.6.1",
5253
"prettier": "^3.5.3",

src/telemetry/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pkg from "../../package.json" with { type: "json" };
22
import config from "../config.js";
3+
import { getMachineIdSync } from 'native-machine-id';
34

45
/**
56
* Machine-specific metadata formatted for telemetry
67
*/
78
export const MACHINE_METADATA = Object.freeze({
8-
device_id: "id", // TODO: use @mongodb-js/machine-id
9+
device_id: getMachineIdSync(),
910
mcp_server_version: pkg.version,
1011
mcp_server_name: config.mcpServerName,
1112
platform: process.platform,

src/types/native-machine-id.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Type definitions for native-machine-id
3+
* Provides functionality to retrieve the machine ID of the current device.
4+
*/
5+
6+
declare module 'native-machine-id' {
7+
/**
8+
* Gets the machine ID synchronously.
9+
* @returns A string containing the machine ID.
10+
*/
11+
export function getMachineIdSync(): string;
12+
13+
/**
14+
* Gets the machine ID asynchronously.
15+
* @returns A Promise that resolves to a string containing the machine ID.
16+
*/
17+
export function getMachineId(): Promise<string>;
18+
19+
/**
20+
* Gets a machine ID that is based on the original ID but is "hashed" for privacy.
21+
* @param {string} [original] - The original ID to hash. If not provided, gets the machine ID first.
22+
* @param {string} [type='md5'] - The hashing algorithm to use.
23+
* @returns A Promise that resolves to a string containing the hashed machine ID.
24+
*/
25+
export function machineIdSync(original?: string, type?: string): string;
26+
27+
/**
28+
* Gets a machine ID that is based on the original ID but is "hashed" for privacy.
29+
* @param {string} [original] - The original ID to hash. If not provided, gets the machine ID first.
30+
* @param {string} [type='md5'] - The hashing algorithm to use.
31+
* @returns A Promise that resolves to a string containing the hashed machine ID.
32+
*/
33+
export function machineId(original?: string, type?: string): Promise<string>;
34+
}

0 commit comments

Comments
 (0)