@openziti/ziti-sdk-nodejs 0.24.1 → 0.25.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/CMakeLists.txt +4 -0
- package/lib/init.js +14 -7
- package/lib/{setLogLevel.js → logger.js} +8 -0
- package/lib/ziti.js +23 -20
- package/package.json +5 -7
- package/tests/addon.test.js +23 -0
- package/tests/context.test.mjs +91 -0
- package/tests/logger.test.mjs +24 -0
- package/tests/hello.js +0 -18
package/CMakeLists.txt
CHANGED
|
@@ -35,6 +35,10 @@ target_include_directories(${PROJECT_NAME}
|
|
|
35
35
|
PRIVATE ${CMAKE_JS_INC}
|
|
36
36
|
)
|
|
37
37
|
|
|
38
|
+
target_compile_definitions(${PROJECT_NAME}
|
|
39
|
+
PRIVATE ZITI_LOG_MODULE="ziti-njs"
|
|
40
|
+
)
|
|
41
|
+
|
|
38
42
|
if (WIN32)
|
|
39
43
|
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN32_LEAN_AND_MEAN)
|
|
40
44
|
endif (WIN32)
|
package/lib/init.js
CHANGED
|
@@ -19,17 +19,24 @@ limitations under the License.
|
|
|
19
19
|
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
try {
|
|
23
|
+
ziti.ziti_init( identityPath, ( result ) => {
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (result instanceof Error) {
|
|
26
|
+
return reject(result);
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
return resolve( result );
|
|
30
|
+
});
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
30
33
|
}
|
|
31
|
-
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
const shutdown = () => {
|
|
38
|
+
ziti.ziti_shutdown();
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
exports.init = init;
|
|
42
|
+
exports.shutdown = shutdown;
|
package/lib/ziti.js
CHANGED
|
@@ -21,27 +21,17 @@ limitations under the License.
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const logger = require('./logger');
|
|
25
|
+
|
|
26
|
+
function load_addon() {
|
|
27
|
+
try {
|
|
28
|
+
return require('../build/Debug/ziti_sdk_nodejs');
|
|
29
|
+
} catch {
|
|
30
|
+
return require('../build/Release/ziti_sdk_nodejs');
|
|
31
|
+
}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
importAll( require.context("../build/", true, /\.node$/) );
|
|
35
|
-
|
|
36
|
-
} else {
|
|
37
|
-
|
|
38
|
-
const binary = require('@mapbox/node-pre-gyp');
|
|
39
|
-
const path = require('path')
|
|
40
|
-
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), {debug: false});
|
|
41
|
-
|
|
42
|
-
binding = require(binding_path);
|
|
43
|
-
|
|
44
|
-
}
|
|
34
|
+
const binding = load_addon();
|
|
45
35
|
|
|
46
36
|
ziti = module.exports = exports = binding;
|
|
47
37
|
|
|
@@ -188,7 +178,20 @@ exports.listen = require('./listen').listen;
|
|
|
188
178
|
* @param {number} level - 0=NONE, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG, 5=TRACE
|
|
189
179
|
* @returns {void} No return value.
|
|
190
180
|
*/
|
|
191
|
-
exports.setLogLevel =
|
|
181
|
+
exports.setLogLevel = logger.setLogLevel;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Set the logger function.
|
|
185
|
+
*
|
|
186
|
+
* **Note**: passing log messages to your own logger
|
|
187
|
+
* function will likely have a negative impact on performance. Use with caution.
|
|
188
|
+
*
|
|
189
|
+
* @function setLogger
|
|
190
|
+
* @param {function} loggerFunc - A function that accepts a log message object
|
|
191
|
+
* with the following properties: { level, source, message }
|
|
192
|
+
* @returns {undefined} No return value.
|
|
193
|
+
*/
|
|
194
|
+
exports.setLogger = logger.setLogger;
|
|
192
195
|
|
|
193
196
|
/**
|
|
194
197
|
* Set the logging level.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openziti/ziti-sdk-nodejs",
|
|
3
3
|
"description": "A NodeJS-based SDK for delivering secure applications over a Ziti Network",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.25.0",
|
|
5
5
|
"main": "./lib/ziti",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run build:configure && npm run build:make",
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
"build:make": "cmake-js build",
|
|
12
12
|
"build:package": "node-pre-gyp package",
|
|
13
13
|
"clean": "cmake-js clean",
|
|
14
|
-
"test": "node tests
|
|
14
|
+
"test": "node --test --test-timeout=20000 tests/*.test.*js",
|
|
15
15
|
"install": "node-pre-gyp install || npm run build",
|
|
16
|
-
"publish": "node-pre-gyp package publish",
|
|
17
16
|
"docs": "jsdoc2md -t API_REFERENCE.hbs lib/*.js > API_REFERENCE.md"
|
|
18
17
|
},
|
|
19
18
|
"repository": {
|
|
@@ -23,9 +22,9 @@
|
|
|
23
22
|
"binary": {
|
|
24
23
|
"module_name": "ziti_sdk_nodejs",
|
|
25
24
|
"module_path": "./build/{configuration}/",
|
|
26
|
-
"remote_path": "./
|
|
25
|
+
"remote_path": "./openziti/ziti-sdk-nodejs/releases/download/{version}/",
|
|
27
26
|
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz",
|
|
28
|
-
"host": "https://
|
|
27
|
+
"host": "https://github.com"
|
|
29
28
|
},
|
|
30
29
|
"license": "Apache-2.0",
|
|
31
30
|
"licenses": [
|
|
@@ -39,14 +38,13 @@
|
|
|
39
38
|
"nodejs"
|
|
40
39
|
],
|
|
41
40
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
41
|
+
"node": ">=20.0.0"
|
|
43
42
|
},
|
|
44
43
|
"author": {
|
|
45
44
|
"name": "OpenZiti",
|
|
46
45
|
"url": "http://openziti.io"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"aws-sdk": "^2.1692.0",
|
|
50
48
|
"cmake-js": "^8.0.0",
|
|
51
49
|
"docdash": "^1.2.0",
|
|
52
50
|
"jsdoc": "^4.0.4",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const ziti = require("../ziti.js");
|
|
2
|
+
const assert = require("node:assert");
|
|
3
|
+
const test = require("node:test");
|
|
4
|
+
const suite = test.suite;
|
|
5
|
+
|
|
6
|
+
suite("Ziti SDK Addon Tests", () => {
|
|
7
|
+
test("ziti.exports tests", () => {
|
|
8
|
+
assert(typeof ziti.ziti_sdk_version === "function", "ziti_sdk_version should be a function");
|
|
9
|
+
assert(typeof ziti.enroll === "function", "ziti_enroll should be a function");
|
|
10
|
+
assert(typeof ziti.setLogger === "function", "ziti_set_logger should be a function");
|
|
11
|
+
|
|
12
|
+
})
|
|
13
|
+
test("ziti_sdk_version test", () => {
|
|
14
|
+
const result = ziti.ziti_sdk_version();
|
|
15
|
+
console.log("ziti_sdk_version() result is: ", result);
|
|
16
|
+
assert(result !== "", "ziti_sdk_version should not return an empty string");
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import ziti from "../ziti.js";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
const suite = test.suite;
|
|
5
|
+
|
|
6
|
+
ziti.setLogLevel(5)
|
|
7
|
+
|
|
8
|
+
suite("Ziti SDK Context Tests", { timeout: 30000 }, () => {
|
|
9
|
+
test.afterEach(() => {
|
|
10
|
+
ziti.ziti_shutdown()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("ziti.shutdown not fail", () => {
|
|
14
|
+
ziti.ziti_shutdown()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test("ziti.ziti_init with bad args", (done) => {
|
|
18
|
+
assert.throws(() => {
|
|
19
|
+
ziti.ziti_init()
|
|
20
|
+
}, {
|
|
21
|
+
message: "Too few arguments",
|
|
22
|
+
code: "EINVAL"
|
|
23
|
+
})
|
|
24
|
+
assert.throws(() => {
|
|
25
|
+
ziti.ziti_init("valid-config")
|
|
26
|
+
}, {
|
|
27
|
+
message: "Too few arguments",
|
|
28
|
+
code: "EINVAL"
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test("ziti.ziti_init with invalid config", (done) => {
|
|
33
|
+
assert.throws(() => {
|
|
34
|
+
ziti.ziti_init("not-a-valid-config", () => {
|
|
35
|
+
assert.fail("should not called")
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
message: "configuration not found",
|
|
40
|
+
code: 'EINVAL'
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
ziti.init("not-a-valid-config").then(
|
|
44
|
+
() => {
|
|
45
|
+
assert.fail("should not resolve")
|
|
46
|
+
},
|
|
47
|
+
(err) => {
|
|
48
|
+
assert.strictEqual(err.message, 'configuration not found')
|
|
49
|
+
assert.strictEqual(err.code, 'EINVAL')
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
assert.rejects(() => ziti.init("not-a-valid-config"),
|
|
53
|
+
{
|
|
54
|
+
code: 'EINVAL',
|
|
55
|
+
message: 'configuration not found'
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test("incomplete config", () => {
|
|
60
|
+
const cfg = {
|
|
61
|
+
id: {
|
|
62
|
+
cert: 'cert',
|
|
63
|
+
key: 'key',
|
|
64
|
+
ca: 'ca'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const cfgStr = JSON.stringify(cfg)
|
|
69
|
+
assert.throws(() => {
|
|
70
|
+
ziti.ziti_init(cfgStr, (err) => {
|
|
71
|
+
assert.fail("should not called")
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
assert.rejects(() => ziti.init(cfgStr), { message: 'configuration is invalid'})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test("complete but invalid config", async () => {
|
|
78
|
+
const cfg = {
|
|
79
|
+
ztAPI: "http://localhost:6262",
|
|
80
|
+
id: {
|
|
81
|
+
cert: 'cert',
|
|
82
|
+
key: 'key',
|
|
83
|
+
ca: 'ca'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const cfgStr = JSON.stringify(cfg)
|
|
88
|
+
await assert.rejects(() => ziti.init(cfgStr), { message: 'configuration is invalid'})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import ziti from "../ziti.js";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import assert from "node:assert";
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
|
|
6
|
+
test('setLogger test', async () => {
|
|
7
|
+
const messages = [];
|
|
8
|
+
ziti.setLogger(
|
|
9
|
+
(msg) => {
|
|
10
|
+
messages.push(msg);
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
ziti.setLogLevel(5);
|
|
15
|
+
await delay(1000);
|
|
16
|
+
assert(messages.length > 0, "Logger callback should have been called at least once");
|
|
17
|
+
assert(messages.some(msg => msg.message.includes("set log level")),
|
|
18
|
+
"Logger should contain log level set message"
|
|
19
|
+
);
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
package/tests/hello.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const bindings = require('bindings')('ziti_sdk_nodejs')
|
|
3
|
-
|
|
4
|
-
console.log(bindings)
|
|
5
|
-
const result = bindings.ziti_sdk_version();
|
|
6
|
-
console.log("ziti_sdk_version() result is: ", result);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const binary = require('@mapbox/node-pre-gyp');
|
|
11
|
-
const path = require('path')
|
|
12
|
-
// const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), {debug: true});
|
|
13
|
-
const binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
|
|
14
|
-
console.log("binding_path is: ", binding_path);
|
|
15
|
-
const ziti = require(binding_path);
|
|
16
|
-
console.log("ziti native addon is: \n", ziti);
|
|
17
|
-
require('assert').notEqual(result,"");
|
|
18
|
-
console.log("SUCCESS");
|