native-machine-id 0.0.13 → 0.1.0

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.
package/binding.gyp CHANGED
@@ -10,7 +10,7 @@
10
10
  'xcode_settings': {
11
11
  'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
12
12
  'CLANG_CXX_LIBRARY': 'libc++',
13
- 'MACOSX_DEPLOYMENT_TARGET': '10.7',
13
+ 'MACOSX_DEPLOYMENT_TARGET': '12.0',
14
14
  },
15
15
  'msvs_settings': {
16
16
  'VCCLCompilerTool': { 'ExceptionHandling': 1 },
@@ -0,0 +1,5 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod;
4
+ export const getMachineId = mod.getMachineId;
5
+ export const getMachineIdSync = mod.getMachineIdSync;
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=machine-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"machine-id.d.ts","sourceRoot":"","sources":["../../src/bin/machine-id.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,6 @@
1
+ declare const globalAny: any;
2
+ declare const approaches: {
3
+ name: string;
4
+ fn: () => any;
5
+ }[];
6
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAeA,QAAA,MAAM,SAAS,EAAE,GAAY,CAAC;AAY9B,QAAA,MAAM,UAAU;;;GAoBf,CAAC"}
package/dist/debug.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ console.log('Node.js version:', process.version);
3
+ console.log('Process type:', process.type || 'standard node');
4
+ console.log('Electron:', process.versions.electron || 'not running in Electron');
5
+ const globalAny = global;
6
+ console.log('BoxedNode features detected:', {
7
+ hasBoxednodeConfig: typeof globalAny.__boxednode_config !== 'undefined',
8
+ hasBoxednodeRequireMapper: typeof globalAny.__boxednode_require_mapper !== 'undefined',
9
+ hasOriginalRequire: typeof globalAny.__original_require !== 'undefined',
10
+ });
11
+ console.log('Module paths:', module.paths);
12
+ const approaches = [
13
+ { name: 'Standard require', fn: () => require('native_machine_id.node') },
14
+ { name: 'Bindings', fn: () => require('bindings')('native_machine_id') },
15
+ {
16
+ name: 'Relative path',
17
+ fn: () => require('../build/Release/native_machine_id.node'),
18
+ },
19
+ {
20
+ name: 'Dynamic path',
21
+ fn: () => require(require('path').join(__dirname, '..', 'build', 'Release', 'native_machine_id.node')),
22
+ },
23
+ ];
24
+ for (const approach of approaches) {
25
+ try {
26
+ const result = approach.fn();
27
+ console.log(`✅ ${approach.name} succeeded:`, {
28
+ hasMachineIdSync: typeof result.getMachineIdSync === 'function',
29
+ hasMachineIdAsync: typeof result.getMachineIdAsync === 'function',
30
+ });
31
+ }
32
+ catch (error) {
33
+ console.error(`❌ ${approach.name} failed:`, error.message);
34
+ }
35
+ }
36
+ try {
37
+ const { getMachineIdSync } = require('../dist/index.js');
38
+ const id = getMachineIdSync();
39
+ console.log('✅ getMachineIdSync returned:', id ? `${id.substring(0, 8)}...` : 'undefined');
40
+ }
41
+ catch (error) {
42
+ console.error('❌ getMachineIdSync failed:', error.message);
43
+ }
44
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":";AAOA,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AACjD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,IAAI,eAAe,CAAC,CAAC;AAC9D,OAAO,CAAC,GAAG,CACT,WAAW,EACX,OAAO,CAAC,QAAQ,CAAC,QAAQ,IAAI,yBAAyB,CACvD,CAAC;AAGF,MAAM,SAAS,GAAQ,MAAM,CAAC;AAC9B,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE;IAC1C,kBAAkB,EAAE,OAAO,SAAS,CAAC,kBAAkB,KAAK,WAAW;IACvE,yBAAyB,EACvB,OAAO,SAAS,CAAC,0BAA0B,KAAK,WAAW;IAC7D,kBAAkB,EAAE,OAAO,SAAS,CAAC,kBAAkB,KAAK,WAAW;CACxE,CAAC,CAAC;AAGH,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;AAG3C,MAAM,UAAU,GAAG;IACjB,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,EAAE;IACzE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,mBAAmB,CAAC,EAAE;IACxE;QACE,IAAI,EAAE,eAAe;QACrB,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,yCAAyC,CAAC;KAC7D;IACD;QACE,IAAI,EAAE,cAAc;QACpB,EAAE,EAAE,GAAG,EAAE,CACP,OAAO,CACL,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAClB,SAAS,EACT,IAAI,EACJ,O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AS,CAAC,CAQxD;AAMD,wBAAgB,gBAAgB,CAAC,EAAE,GAAW,EAAE,GAAE,mBAAwB,GACtE,MAAM,GACN,SAAS,CAQZ"}
package/dist/index.js CHANGED
@@ -1,11 +1,16 @@
1
- import bindings from 'bindings';
2
- import { createHash } from 'crypto';
3
- import { promisify } from 'util';
4
- const binding = bindings('native_machine_id');
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.getMachineIdSync = exports.getMachineId = void 0;
7
+ const bindings_1 = __importDefault(require("bindings"));
8
+ const crypto_1 = require("crypto");
9
+ const util_1 = require("util");
10
+ const binding = (0, bindings_1.default)('native_machine_id');
5
11
  function getMachineIdFromBindingSync() {
6
12
  try {
7
- const deviceId = binding.getMachineIdSync() || undefined;
8
- return deviceId;
13
+ return binding.getMachineIdSync() || undefined;
9
14
  }
10
15
  catch {
11
16
  return undefined;
@@ -13,25 +18,27 @@ function getMachineIdFromBindingSync() {
13
18
  }
14
19
  async function getMachineIdFromBindingAsync() {
15
20
  try {
16
- const deviceId = (await promisify(binding.getMachineIdAsync)()) || undefined;
21
+ const deviceId = (await (0, util_1.promisify)(binding.getMachineIdAsync)()) || undefined;
17
22
  return deviceId;
18
23
  }
19
24
  catch {
20
25
  return undefined;
21
26
  }
22
27
  }
23
- export async function getMachineId({ raw = false, } = {}) {
28
+ async function getMachineId({ raw = false, } = {}) {
24
29
  const machineId = await getMachineIdFromBindingAsync();
25
30
  if (!machineId || raw === true) {
26
31
  return machineId;
27
32
  }
28
- return createHash('sha256').update(machineId).digest('hex');
33
+ return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex');
29
34
  }
30
- export function getMachineIdSync({ raw = false } = {}) {
35
+ exports.getMachineId = getMachineId;
36
+ function getMachineIdSync({ raw = false } = {}) {
31
37
  const machineId = getMachineIdFromBindingSync();
32
38
  if (!machineId || raw === true) {
33
39
  return machineId;
34
40
  }
35
- return createHash('sha256').update(machineId).digest('hex');
41
+ return (0, crypto_1.createHash)('sha256').update(machineId).digest('hex');
36
42
  }
43
+ exports.getMachineIdSync = getMachineIdSync;
37
44
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,mCAAoC;AACpC,+BAAiC;AAEjC,MAAM,OAAO,GAAG,IAAA,kBAAQ,EAAC,mBAAmB,CAAC,CAAC;AAE9C,SAAS,2BAA2B;IAClC,IAAI;QACF,OAAO,OAAO,CAAC,gBAAgB,EAAE,IAAI,SAAS,CAAC;KAChD;IAAC,MAAM;QAEN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,KAAK,UAAU,4BAA4B;IACzC,IAAI;QACF,MAAM,QAAQ,GACZ,CAAC,MAAM,IAAA,gBAAS,EAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,IAAI,SAAS,CAAC;QAE9D,OAAO,QAAQ,CAAC;KACjB;IAAC,MAAM;QAEN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAWM,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,GAAG,KAAK,MACY,EAAE;IACzB,MAAM,SAAS,GAAG,MAAM,4BAA4B,EAAE,CAAC;IAEvD,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAVD,oCAUC;AAMD,SAAgB,gBAAgB,CAAC,EAAE,GAAG,GAAG,KAAK,KAA0B,EAAE;IAGxE,MAAM,SAAS,GAAG,2BAA2B,EAAE,CAAC;IAEhD,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QAC9B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAVD,4CAUC"}
package/package.json CHANGED
@@ -1,31 +1,33 @@
1
1
  {
2
2
  "name": "native-machine-id",
3
- "version": "0.0.13",
3
+ "version": "0.1.0",
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": "index.js",
5
+ "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "compile": "node-gyp rebuild",
8
+ "compile": "tsc -p tsconfig.json && node-gyp rebuild && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
9
9
  "bootstrap": "npm run compile",
10
10
  "pretest": "npm run compile",
11
- "install": "prebuild-install --runtime napi || node-gyp rebuild",
11
+ "install": "node-gyp rebuild",
12
12
  "test": "mocha",
13
13
  "test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
14
14
  "test-ci": "npm run test-cov",
15
15
  "lint": "eslint . && prettier --check .",
16
16
  "check": "npm run lint && npm run test",
17
17
  "prepublishOnly": "npm run compile",
18
- "benchmark": "node scripts/benchmark.js"
18
+ "benchmark": "ts-node scripts/benchmark.ts"
19
19
  },
20
20
  "author": "Compass Team <compass@mongodb.com>",
21
21
  "gypfile": true,
22
22
  "dependencies": {
23
23
  "bindings": "^1.5.0",
24
- "node-addon-api": "^4.3.0"
24
+ "node-addon-api": "^8.0.0"
25
25
  },
26
26
  "license": "Apache-2.0",
27
27
  "exports": {
28
- ".": "./index.js"
28
+ "require": "./dist/index.js",
29
+ "import": "./dist/.esm-wrapper.mjs",
30
+ "types": "./dist/index.d.ts"
29
31
  },
30
32
  "homepage": "https://github.com/mongodb-js/devtools-shared",
31
33
  "repository": {
@@ -34,24 +36,30 @@
34
36
  },
35
37
  "bugs": "https://jira.mongodb.org/projects/COMPASS/issues",
36
38
  "bin": {
37
- "native-machine-id": "bin/machine-id.js"
39
+ "native-machine-id": "dist/bin/machine-id.js"
38
40
  },
39
41
  "files": [
40
42
  "binding.cc",
41
43
  "binding.gyp",
42
- "index.js",
43
- "bin",
44
- "LICENSE",
45
- "dist/index.d.ts"
44
+ "dist",
45
+ "LICENSE"
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
- "chai": "^4.5.0",
51
+ "@mongodb-js/tsconfig-devtools": "^1.0.3",
52
+ "@types/chai": "^4.2.21",
53
+ "@types/mocha": "^9.1.1",
54
+ "@types/sinon-chai": "^3.2.5",
55
+ "@types/node": "^17.0.35",
52
56
  "eslint": "^7.25.0",
57
+ "gen-esm-wrapper": "^1.1.1",
53
58
  "mocha": "^8.4.0",
54
- "node-machine-id": "^1.1.12"
59
+ "chai": "^4.5.0",
60
+ "node-machine-id": "^1.1.12",
61
+ "typescript": "^5.0.4",
62
+ "ts-node": "^10.9.2"
55
63
  },
56
64
  "keywords": [
57
65
  "machine id",
package/bin/machine-id.js DELETED
@@ -1,9 +0,0 @@
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/index.js DELETED
@@ -1,67 +0,0 @@
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
- };