@openziti/ziti-sdk-nodejs 0.9.3 → 0.10.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 +2 -1
- package/lib/httpRequest.js +81 -0
- package/lib/httpRequestData.js +46 -0
- package/lib/setLogLevel.js +29 -0
- package/lib/ziti.js +3 -0
- package/package.json +1 -1
- package/src/utils.c +3 -2
- package/src/utils.h +15 -15
- package/src/ziti-add-on.c +2 -0
- package/src/ziti-nodejs.h +2 -0
- package/src/ziti_set_log_level.c +73 -0
package/binding.gyp
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"./src/ziti_init.c",
|
|
39
39
|
"./src/ziti_listen.c",
|
|
40
40
|
"./src/ziti_service_available.c",
|
|
41
|
+
"./src/ziti_set_log_level.c",
|
|
41
42
|
"./src/ziti_shutdown.c",
|
|
42
43
|
"./src/ziti_write.c",
|
|
43
44
|
"./src/ziti_websocket_connect.c",
|
|
@@ -106,7 +107,7 @@
|
|
|
106
107
|
"GCC_ENABLE_PASCAL_STRINGS": "NO", # No -mpascal-strings
|
|
107
108
|
"GCC_THREADSAFE_STATICS": "NO", # -fno-threadsafe-statics
|
|
108
109
|
"PREBINDING": "NO", # No -Wl,-prebind
|
|
109
|
-
"MACOSX_DEPLOYMENT_TARGET": "
|
|
110
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.14", # -mmacosx-version-min=10.14
|
|
110
111
|
"USE_HEADERMAP": "NO",
|
|
111
112
|
"OTHER_CFLAGS": [
|
|
112
113
|
"-fno-strict-aliasing",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* on_req()
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const on_req = ( obj ) => {
|
|
23
|
+
|
|
24
|
+
console.log('on_req entered: ', obj);
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* on_resp()
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
const on_resp = ( obj ) => {
|
|
33
|
+
|
|
34
|
+
console.log('on_resp entered: ', obj);
|
|
35
|
+
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* on_resp_data()
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
const on_resp_data = ( obj ) => {
|
|
43
|
+
|
|
44
|
+
console.log('on_resp_data entered: ', obj);
|
|
45
|
+
console.log('as string: ', obj.body.toString('utf8'));
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const httpRequest = ( url, method, headers, on_req_cb, on_resp_cb, on_resp_data_cb ) => {
|
|
50
|
+
|
|
51
|
+
console.log('httpRequest entered: ', url, method, headers);
|
|
52
|
+
|
|
53
|
+
let _on_req_cb;
|
|
54
|
+
let _on_resp_cb;
|
|
55
|
+
let _on_resp_data_cb;
|
|
56
|
+
|
|
57
|
+
if (typeof on_req_cb === 'undefined') {
|
|
58
|
+
_on_req_cb = on_req;
|
|
59
|
+
} else {
|
|
60
|
+
_on_req_cb = on_req_cb;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (typeof on_resp_cb === 'undefined') {
|
|
64
|
+
_on_resp_cb = on_resp;
|
|
65
|
+
} else {
|
|
66
|
+
_on_resp_cb = on_req_cb;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof on_resp_data_cb === 'undefined') {
|
|
70
|
+
_on_resp_data_cb = on_resp_data;
|
|
71
|
+
} else {
|
|
72
|
+
_on_resp_data_cb = on_resp_data_cb;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
ziti.Ziti_http_request( url, method, headers, _on_req_cb, _on_resp_cb, _on_resp_data_cb );
|
|
76
|
+
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
exports.httpRequest = httpRequest;
|
|
81
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* on_req_data()
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const on_req_data = ( obj ) => {
|
|
23
|
+
|
|
24
|
+
console.log('on_req_data entered: ', obj);
|
|
25
|
+
console.log('as string: ', obj.body.toString('utf8'));
|
|
26
|
+
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const httpRequestData = ( req, buffer, on_req_data_cb ) => {
|
|
30
|
+
|
|
31
|
+
console.log('httpRequestData entered: ', req, buffer);
|
|
32
|
+
|
|
33
|
+
let _on_req_data_cb;
|
|
34
|
+
|
|
35
|
+
if (typeof on_req_data_cb === 'undefined') {
|
|
36
|
+
_on_req_data_cb = on_req_data;
|
|
37
|
+
} else {
|
|
38
|
+
_on_req_data_cb = on_req_data_cb;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ziti.Ziti_http_request_data( req, buffer, _on_req_data_cb );
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
exports.httpRequestData = httpRequestData;
|
|
46
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* setLogLevel()
|
|
20
|
+
*
|
|
21
|
+
* @param {*} lvl
|
|
22
|
+
*/
|
|
23
|
+
const setLogLevel = ( lvl ) => {
|
|
24
|
+
|
|
25
|
+
ziti.ziti_set_log_level( lvl );
|
|
26
|
+
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.setLogLevel = setLogLevel;
|
package/lib/ziti.js
CHANGED
|
@@ -48,3 +48,6 @@ exports.express = require('./express').express;
|
|
|
48
48
|
exports.init = require('./init').init;
|
|
49
49
|
exports.listen = require('./listen').listen;
|
|
50
50
|
exports.write = require('./write').write;
|
|
51
|
+
exports.httpRequest = require('./httpRequest').httpRequest;
|
|
52
|
+
exports.httpRequestData = require('./httpRequestData').httpRequestData;
|
|
53
|
+
exports.setLogLevel = require('./setLogLevel').setLogLevel;
|
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.10.0",
|
|
5
5
|
"main": "./lib/ziti",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run build:init; npm run build:c-sdk; npm install --build-from-source --clang=1",
|
package/src/utils.c
CHANGED
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
#include <uv.h>
|
|
18
18
|
#include "utils.h"
|
|
19
|
+
#include <ziti/ziti_log.h>
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
#if !defined(BUILD_DATE)
|
|
@@ -43,7 +44,7 @@ limitations under the License.
|
|
|
43
44
|
#define ZITI_COMMIT sha
|
|
44
45
|
#endif
|
|
45
46
|
|
|
46
|
-
#define to_str(x) str(x)
|
|
47
|
+
// #define to_str(x) str(x)
|
|
47
48
|
#define str(x) #x
|
|
48
49
|
|
|
49
50
|
|
|
@@ -69,7 +70,7 @@ const char* ziti_nodejs_git_commit() {
|
|
|
69
70
|
return to_str(ZITI_COMMIT);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
int ziti_nodejs_debug_level =
|
|
73
|
+
int ziti_nodejs_debug_level = ZITI_LOG_DEFAULT_LEVEL;
|
|
73
74
|
FILE *ziti_nodejs_debug_out;
|
|
74
75
|
|
|
75
76
|
#if _WIN32
|
package/src/utils.h
CHANGED
|
@@ -44,21 +44,21 @@ extern FILE *ziti_nodejs_debug_out;
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
/// for windows compilation NOGDI needs to be set:
|
|
47
|
-
#define DEBUG_LEVELS(XX) \
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
enum DebugLevel {
|
|
58
|
-
#define _level(n) n,
|
|
59
|
-
|
|
60
|
-
#undef _level
|
|
61
|
-
};
|
|
47
|
+
// #define DEBUG_LEVELS(XX) \
|
|
48
|
+
// XX(NONE) \
|
|
49
|
+
// XX(ERROR) /*WINDOWS - see comment above wrt NOGDI*/ \
|
|
50
|
+
// XX(WARN) \
|
|
51
|
+
// XX(INFO) \
|
|
52
|
+
// XX(DEBUG) \
|
|
53
|
+
// XX(VERBOSE) \
|
|
54
|
+
// XX(TRACE)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// enum DebugLevel {
|
|
58
|
+
// #define _level(n) n,
|
|
59
|
+
// DEBUG_LEVELS(_level)
|
|
60
|
+
// #undef _level
|
|
61
|
+
// };
|
|
62
62
|
|
|
63
63
|
// #define container_of(ptr, type, member) ((type *) ((ptr) - offsetof(type, member)))
|
|
64
64
|
|
package/src/ziti-add-on.c
CHANGED
package/src/ziti-nodejs.h
CHANGED
|
@@ -30,6 +30,7 @@ limitations under the License.
|
|
|
30
30
|
#include <node_api.h>
|
|
31
31
|
|
|
32
32
|
#include <ziti/ziti.h>
|
|
33
|
+
#include <ziti/ziti_log.h>
|
|
33
34
|
#include "utils.h"
|
|
34
35
|
|
|
35
36
|
|
|
@@ -205,6 +206,7 @@ extern void expose_ziti_hello(napi_env env, napi_value exports);
|
|
|
205
206
|
extern void expose_ziti_init(napi_env env, napi_value exports);
|
|
206
207
|
extern void expose_ziti_listen(napi_env env, napi_value exports);
|
|
207
208
|
extern void expose_ziti_service_available(napi_env env, napi_value exports);
|
|
209
|
+
extern void expose_ziti_set_log_level(napi_env env, napi_value exports);
|
|
208
210
|
extern void expose_ziti_shutdown(napi_env env, napi_value exports);
|
|
209
211
|
extern void expose_ziti_write(napi_env env, napi_value exports);
|
|
210
212
|
extern void expose_ziti_https_request(napi_env env, napi_value exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "ziti-nodejs.h"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
napi_value _ziti_set_log_level(napi_env env, const napi_callback_info info) {
|
|
24
|
+
napi_status status;
|
|
25
|
+
napi_value jsRetval;
|
|
26
|
+
|
|
27
|
+
size_t argc = 1;
|
|
28
|
+
napi_value args[1];
|
|
29
|
+
status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
|
|
30
|
+
if (status != napi_ok) {
|
|
31
|
+
napi_throw_error(env, NULL, "Failed to parse arguments");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (argc < 1) {
|
|
35
|
+
napi_throw_error(env, "EINVAL", "Too few arguments");
|
|
36
|
+
return NULL;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
int64_t js_log_level;
|
|
40
|
+
status = napi_get_value_int64(env, args[0], &js_log_level);
|
|
41
|
+
if (status != napi_ok) {
|
|
42
|
+
napi_throw_error(env, NULL, "Failed to get logLevel");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ZITI_NODEJS_LOG(DEBUG, "js_log_level: %lld", js_log_level);
|
|
46
|
+
|
|
47
|
+
ziti_nodejs_debug_level = js_log_level;
|
|
48
|
+
ziti_log_set_level(js_log_level);
|
|
49
|
+
|
|
50
|
+
status = napi_create_int32(env, 0, &jsRetval);
|
|
51
|
+
if (status != napi_ok) {
|
|
52
|
+
napi_throw_error(env, NULL, "Unable to create return value");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return jsRetval;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
void expose_ziti_set_log_level(napi_env env, napi_value exports) {
|
|
60
|
+
napi_status status;
|
|
61
|
+
napi_value fn;
|
|
62
|
+
|
|
63
|
+
status = napi_create_function(env, NULL, 0, _ziti_set_log_level, NULL, &fn);
|
|
64
|
+
if (status != napi_ok) {
|
|
65
|
+
napi_throw_error(env, NULL, "Unable to wrap native function '_ziti_set_log_level");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
status = napi_set_named_property(env, exports, "ziti_set_log_level", fn);
|
|
69
|
+
if (status != napi_ok) {
|
|
70
|
+
napi_throw_error(env, NULL, "Unable to populate exports for 'ziti_set_log_level");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|