native-machine-id 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { getMachineIdSync } = require('..');
5
+
6
+ const id = getMachineIdSync({ raw: process.argv.includes('--raw') }) || '';
7
+
8
+ // eslint-disable-next-line no-console
9
+ console.log(id);
package/dist/index.js CHANGED
@@ -1,42 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getMachineId = getMachineId;
7
- exports.getMachineIdSync = getMachineIdSync;
8
- const bindings_1 = __importDefault(require("bindings"));
9
- const crypto_1 = require("crypto");
10
- const path_1 = __importDefault(require("path"));
11
- const util_1 = require("util");
12
- const getBindings = () => {
13
- const tries = [
14
- () => (0, bindings_1.default)('native_machine_id'),
15
- () => require(path_1.default.join(__dirname, '../build/Release/native_machine_id.node')),
16
- () => require('../build/Release/native_machine_id.node'),
17
- () => require('./build/Release/native_machine_id.node'),
18
- () => require('../build/Debug/native_machine_id.node'),
19
- ];
20
- for (const tryBinding of tries) {
21
- try {
22
- return tryBinding();
23
- }
24
- catch (error) {
25
- console.error(error);
26
- }
27
- }
28
- throw new Error('Unable to load native machine ID bindings. Please ensure the module is built correctly. Tried: ' +
29
- JSON.stringify([
30
- path_1.default.resolve('../build/Release/native_machine_id.node'),
31
- path_1.default.resolve('../build/Debug/native_machine_id.node'),
32
- __dirname,
33
- process.cwd(),
34
- ]));
35
- };
36
- const binding = getBindings();
1
+ import bindings from 'bindings';
2
+ import { createHash } from 'crypto';
3
+ import { promisify } from 'util';
4
+ const binding = bindings('native_machine_id');
37
5
  function getMachineIdFromBindingSync() {
38
6
  try {
39
- return binding.getMachineIdSync() || undefined;
7
+ const deviceId = binding.getMachineIdSync() || undefined;
8
+ return deviceId;
40
9
  }
41
10
  catch {
42
11
  return undefined;
@@ -44,25 +13,25 @@ function getMachineIdFromBindingSync() {
44
13
  }
45
14
  async function getMachineIdFromBindingAsync() {
46
15
  try {
47
- const deviceId = (await (0, util_1.promisify)(binding.getMachineIdAsync)()) || undefined;
16
+ const deviceId = (await promisify(binding.getMachineIdAsync)()) || undefined;
48
17
  return deviceId;
49
18
  }
50
19
  catch {
51
20
  return undefined;
52
21
  }
53
22
  }
54
- async function getMachineId({ raw = false, } = {}) {
23
+ export async function getMachineId({ raw = false, } = {}) {
55
24
  const machineId = await getMachineIdFromBindingAsync();
56
25
  if (!machineId || raw === true) {
57
26
  return machineId;
58
27
  }
59
- return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex');
28
+ return createHash('sha256').update(machineId).digest('hex');
60
29
  }
61
- function getMachineIdSync({ raw = false } = {}) {
30
+ export function getMachineIdSync({ raw = false } = {}) {
62
31
  const machineId = getMachineIdFromBindingSync();
63
32
  if (!machineId || raw === true) {
64
33
  return machineId;
65
34
  }
66
- return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex');
35
+ return createHash('sha256').update(machineId).digest('hex');
67
36
  }
68
37
  //# sourceMappingURL=index.js.map
package/index.js ADDED
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ const bindings = require('bindings');
4
+ const crypto = require('crypto');
5
+ const util = require('util');
6
+
7
+ const binding = bindings('native_machine_id');
8
+
9
+ function getMachineIdFromBindingSync() {
10
+ try {
11
+ const deviceId = binding.getMachineIdSync() || undefined;
12
+ return deviceId;
13
+ } catch {
14
+ // If the binding fails, we can assume the machine ID is not available.
15
+ return undefined;
16
+ }
17
+ }
18
+
19
+ async function getMachineIdFromBindingAsync() {
20
+ try {
21
+ const deviceId =
22
+ (await util.promisify(binding.getMachineIdAsync)()) || undefined;
23
+ return deviceId;
24
+ } catch {
25
+ // If the binding fails, we can assume the machine ID is not available.
26
+ return undefined;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Get the machine ID for the current system
32
+ * @param {Object} options - Options for getting the machine ID
33
+ * @param {boolean} [options.raw=false] - If true, the machine ID will not be hashed with SHA256
34
+ * @returns {Promise<string|undefined>} A promise that resolves to the machine ID or `undefined` if not available
35
+ */
36
+ async function getMachineId(options = {}) {
37
+ const { raw = false } = options;
38
+ const machineId = await getMachineIdFromBindingAsync();
39
+
40
+ if (!machineId || raw === true) {
41
+ return machineId;
42
+ }
43
+
44
+ return crypto.createHash('sha256').update(machineId).digest('hex');
45
+ }
46
+
47
+ /**
48
+ * Get the machine ID for the current system synchronously
49
+ * @param {Object} options - Options for getting the machine ID
50
+ * @param {boolean} [options.raw=false] - If true, the machine ID will not be hashed with SHA256
51
+ * @returns {string|undefined} The machine ID or `undefined` if not available
52
+ */
53
+ function getMachineIdSync(options = {}) {
54
+ const { raw = false } = options;
55
+ const machineId = getMachineIdFromBindingSync();
56
+
57
+ if (!machineId || raw === true) {
58
+ return machineId;
59
+ }
60
+
61
+ return crypto.createHash('sha256').update(machineId).digest('hex');
62
+ }
63
+
64
+ module.exports = {
65
+ getMachineId,
66
+ getMachineIdSync,
67
+ };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "native-machine-id",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Native retrieval of a unique desktop machine ID without admin privileges or child processes. Faster and more reliable alternative to node-machine-id.",
5
- "main": "dist/index.js",
5
+ "main": "index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "compile": "tsc -p tsconfig.json && node-gyp rebuild && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
8
+ "compile": "node-gyp rebuild",
9
9
  "bootstrap": "npm run compile",
10
10
  "pretest": "npm run compile",
11
11
  "install": "prebuild-install --runtime napi || node-gyp rebuild",
@@ -15,7 +15,7 @@
15
15
  "lint": "eslint . && prettier --check .",
16
16
  "check": "npm run lint && npm run test",
17
17
  "prepublishOnly": "npm run compile",
18
- "benchmark": "ts-node scripts/benchmark.ts"
18
+ "benchmark": "node scripts/benchmark.js"
19
19
  },
20
20
  "author": "Compass Team <compass@mongodb.com>",
21
21
  "gypfile": true,
@@ -25,9 +25,7 @@
25
25
  },
26
26
  "license": "Apache-2.0",
27
27
  "exports": {
28
- "require": "./dist/index.js",
29
- "import": "./dist/.esm-wrapper.mjs",
30
- "types": "./dist/index.d.ts"
28
+ ".": "./index.js"
31
29
  },
32
30
  "homepage": "https://github.com/mongodb-js/devtools-shared",
33
31
  "repository": {
@@ -36,31 +34,24 @@
36
34
  },
37
35
  "bugs": "https://jira.mongodb.org/projects/COMPASS/issues",
38
36
  "bin": {
39
- "native-machine-id": "dist/bin/machine-id.js"
37
+ "native-machine-id": "bin/machine-id.js"
40
38
  },
41
39
  "files": [
42
40
  "binding.cc",
43
41
  "binding.gyp",
44
- "dist",
45
- "LICENSE"
42
+ "index.js",
43
+ "bin",
44
+ "LICENSE",
45
+ "dist/index.d.ts"
46
46
  ],
47
47
  "devDependencies": {
48
48
  "@mongodb-js/eslint-config-devtools": "0.9.11",
49
49
  "@mongodb-js/mocha-config-devtools": "^1.0.5",
50
50
  "@mongodb-js/prettier-config-devtools": "^1.0.2",
51
- "@mongodb-js/tsconfig-devtools": "^1.0.3",
52
- "@types/bindings": "^1.5.5",
53
- "@types/chai": "^4.2.21",
54
- "@types/mocha": "^9.1.1",
55
- "@types/node": "^17.0.35",
56
- "@types/sinon-chai": "^3.2.5",
57
51
  "chai": "^4.5.0",
58
52
  "eslint": "^7.25.0",
59
- "gen-esm-wrapper": "^1.1.1",
60
53
  "mocha": "^8.4.0",
61
- "node-machine-id": "^1.1.12",
62
- "ts-node": "^10.9.2",
63
- "typescript": "^5.0.4"
54
+ "node-machine-id": "^1.1.12"
64
55
  },
65
56
  "keywords": [
66
57
  "machine id",
@@ -1,5 +0,0 @@
1
- import mod from "./index.js";
2
-
3
- export default mod;
4
- export const getMachineId = mod.getMachineId;
5
- export const getMachineIdSync = mod.getMachineIdSync;
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=machine-id.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"machine-id.d.ts","sourceRoot":"","sources":["../../src/bin/machine-id.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const __1 = require("..");
5
- const id = (0, __1.getMachineIdSync)({ raw: process.argv.includes('--raw') }) || '';
6
- console.log(id);
7
- //# sourceMappingURL=machine-id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"machine-id.js","sourceRoot":"","sources":["../../src/bin/machine-id.ts"],"names":[],"mappings":";;;AACA,0BAAsC;AAEtC,MAAM,EAAE,GAAG,IAAA,oBAAgB,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;AAG3E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+DA,MAAM,MAAM,mBAAmB,GAAG;IAEhC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAMF,wBAAsB,YAAY,CAAC,EACjC,GAAW,GACZ,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAQxD;AAMD,wBAAgB,gBAAgB,CAAC,EAAE,GAAW,EAAE,GAAE,mBAAwB,GACtE,MAAM,GACN,SAAS,CAQZ"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAwEA,oCAUC;AAMD,4CAUC;AAlGD,wDAAgC;AAChC,mCAAoC;AACpC,gDAAwB;AACxB,+BAAiC;AAEjC,M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