@openziti/ziti-sdk-nodejs 0.14.0 → 0.14.1

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/README.md CHANGED
@@ -57,15 +57,20 @@ For more context on this SDK, you may be interested in this
57
57
  # Supported platforms
58
58
 
59
59
  The `@openziti/ziti-sdk-nodejs` module works with the following Node.js versions:
60
- - v12.x
61
- - v13.x
62
- - v14.x
63
- - v15.x
64
60
  - v16.x
65
- - v17.x
66
61
  - v18.x
62
+ - v19.x
63
+ - v20.x
64
+
65
+ The `@openziti/ziti-sdk-nodejs` module works with the following architectures:
66
+ - amd64
67
+ - arm64
68
+
69
+ The `@openziti/ziti-sdk-nodejs` module works with the following Operating Systems:
70
+ - macos
71
+ - linux
72
+ - windows
67
73
 
68
- Binaries for most Node versions and platforms are provided by default via [@mapbox/node-pre-gyp](https://github.com/mapbox/node-pre-gyp).
69
74
 
70
75
  # Installing
71
76
 
@@ -107,6 +112,7 @@ const on_resp_data = ( obj ) => {
107
112
  // Perform an HTTP GET request to a dark OpenZiti web service
108
113
  ziti.httpRequest(
109
114
  'myDarkWebService', // OpenZiti Service name or HTTP origin part of the URL
115
+ undefined, // schemeHostPort parm is mutually-exclusive with serviceName parm
110
116
  'GET',
111
117
  '/', // path part of the URL including query params
112
118
  ['Accept: application/json' ], // headers
@@ -221,4 +227,18 @@ for tracking bugs and feature requests and have limited bandwidth to address the
221
227
  - Participate in discussion on [Discourse](https://openziti.discourse.group/)
222
228
 
223
229
 
230
+ # Building from source on MacOS
231
+
232
+ ``` js
233
+ git clone https://github.com/microsoft/vcpkg.git
234
+ ./vcpkg/bootstrap-vcpkg.sh
235
+ export VCPKG_ROOT=`pwd`/vcpkg
236
+ brew install cmake
237
+ brew install ninja
238
+ brew install pkg-config
239
+ git clone https://github.com/openziti/ziti-sdk-nodejs.git
240
+ cd ziti-sdk-nodejs
241
+ npm run build
242
+ ```
243
+
224
244
  Copyright© NetFoundry, Inc.
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.14.0",
4
+ "version": "0.14.1",
5
5
  "main": "./lib/ziti",
6
6
  "scripts": {
7
7
  "build": "npm run build:init && npm run build:configure && npm run build:make",
@@ -606,12 +606,14 @@ void on_resp(tlsuv_http_resp_t *resp, void *data) {
606
606
  }
607
607
 
608
608
  // Initiate the call into the JavaScript callback. The call into JavaScript will not have happened when this function returns, but it will be queued.
609
- int rc = napi_call_threadsafe_function(
610
- addon_data->tsfn_on_resp,
611
- item,
612
- napi_tsfn_blocking);
613
- if (rc != napi_ok) {
614
- napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback");
609
+ if (addon_data->tsfn_on_resp != NULL) {
610
+ int rc = napi_call_threadsafe_function(
611
+ addon_data->tsfn_on_resp,
612
+ item,
613
+ napi_tsfn_blocking);
614
+ if (rc != napi_ok) {
615
+ napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback");
616
+ }
615
617
  }
616
618
 
617
619
  if (UV_EOF != resp->code) {
@@ -711,12 +713,14 @@ void on_client(uv_work_t* req, int status) {
711
713
  }
712
714
 
713
715
  // Initiate the call into the JavaScript callback. The call into JavaScript will not have happened when this function returns, but it will be queued.
714
- int rc = napi_call_threadsafe_function(
715
- addon_data->tsfn_on_req,
716
- addon_data,
717
- napi_tsfn_blocking);
718
- if (rc != napi_ok) {
719
- napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback");
716
+ if (addon_data->tsfn_on_req != NULL) {
717
+ int rc = napi_call_threadsafe_function(
718
+ addon_data->tsfn_on_req,
719
+ addon_data,
720
+ napi_tsfn_blocking);
721
+ if (rc != napi_ok) {
722
+ napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback");
723
+ }
720
724
  }
721
725
  }
722
726
 
@@ -908,73 +912,89 @@ napi_value _Ziti_http_request(napi_env env, const napi_callback_info info) {
908
912
 
909
913
  ZITI_NODEJS_LOG(DEBUG, "path: %s", addon_data->path);
910
914
 
915
+ HttpsReq* httpsReq = calloc(1, sizeof(HttpsReq));
916
+ addon_data->httpsReq = httpsReq;
917
+ httpsReq->addon_data = addon_data;
918
+
911
919
  // Obtain ptr to JS on_req callback function
912
920
  napi_value js_cb = args[5];
913
921
  napi_value work_name;
914
922
 
923
+ status = napi_typeof(env, args[5], &valuetype);
924
+ if (valuetype != napi_undefined) {
925
+ ZITI_NODEJS_LOG(DEBUG, "on_req callback is specified");
915
926
 
916
- HttpsReq* httpsReq = calloc(1, sizeof(HttpsReq));
917
- addon_data->httpsReq = httpsReq;
918
- httpsReq->addon_data = addon_data;
927
+ // Create a string to describe this asynchronous operation.
928
+ rc = napi_create_string_utf8(env, "on_req", NAPI_AUTO_LENGTH, &work_name);
929
+ if (rc != napi_ok) {
930
+ napi_throw_error(env, "EINVAL", "Failed to create string");
931
+ return NULL;
932
+ }
919
933
 
920
- // Create a string to describe this asynchronous operation.
921
- rc = napi_create_string_utf8(env, "on_req", NAPI_AUTO_LENGTH, &work_name);
922
- if (rc != napi_ok) {
923
- napi_throw_error(env, "EINVAL", "Failed to create string");
924
- return NULL;
934
+ // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn)
935
+ // which we can call from a worker thread.
936
+ rc = napi_create_threadsafe_function(
937
+ env,
938
+ js_cb,
939
+ NULL,
940
+ work_name,
941
+ 0,
942
+ 1,
943
+ NULL,
944
+ NULL,
945
+ NULL,
946
+ CallJs_on_req,
947
+ &(addon_data->tsfn_on_req)
948
+ );
949
+ ZITI_NODEJS_LOG(DEBUG, "2: %d", rc);
950
+ if (rc != napi_ok) {
951
+ napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function");
952
+ return NULL;
953
+ }
954
+ ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_req() : %p", addon_data->tsfn_on_req);
925
955
  }
926
-
927
- // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn)
928
- // which we can call from a worker thread.
929
- rc = napi_create_threadsafe_function(
930
- env,
931
- js_cb,
932
- NULL,
933
- work_name,
934
- 0,
935
- 1,
936
- NULL,
937
- NULL,
938
- NULL,
939
- CallJs_on_req,
940
- &(addon_data->tsfn_on_req)
941
- );
942
- if (rc != napi_ok) {
943
- napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function");
944
- return NULL;
956
+ else {
957
+ ZITI_NODEJS_LOG(DEBUG, "on_req callback is NOT specified");
945
958
  }
946
- ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_req() : %p", addon_data->tsfn_on_req);
947
959
 
948
960
  // Obtain ptr to JS on_resp callback function
949
961
  napi_value js_cb2 = args[6];
950
962
 
951
- // Create a string to describe this asynchronous operation.
952
- rc = napi_create_string_utf8(env, "on_resp", NAPI_AUTO_LENGTH, &work_name);
953
- if (rc != napi_ok) {
954
- napi_throw_error(env, "EINVAL", "Failed to create string");
955
- return NULL;
956
- }
963
+ status = napi_typeof(env, args[6], &valuetype);
964
+ if (valuetype != napi_undefined) {
965
+ ZITI_NODEJS_LOG(DEBUG, "on_resp callback is specified");
957
966
 
958
- // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn)
959
- // which we can call from a worker thread.
960
- rc = napi_create_threadsafe_function(
961
- env,
962
- js_cb2,
963
- NULL,
964
- work_name,
965
- 0,
966
- 1,
967
- NULL,
968
- NULL,
969
- NULL,
970
- CallJs_on_resp,
971
- &(addon_data->tsfn_on_resp)
972
- );
973
- if (rc != napi_ok) {
974
- napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function");
975
- return NULL;
967
+ // Create a string to describe this asynchronous operation.
968
+ rc = napi_create_string_utf8(env, "on_resp", NAPI_AUTO_LENGTH, &work_name);
969
+ if (rc != napi_ok) {
970
+ napi_throw_error(env, "EINVAL", "Failed to create string");
971
+ return NULL;
972
+ }
973
+
974
+ // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn)
975
+ // which we can call from a worker thread.
976
+ rc = napi_create_threadsafe_function(
977
+ env,
978
+ js_cb2,
979
+ NULL,
980
+ work_name,
981
+ 0,
982
+ 1,
983
+ NULL,
984
+ NULL,
985
+ NULL,
986
+ CallJs_on_resp,
987
+ &(addon_data->tsfn_on_resp)
988
+ );
989
+ if (rc != napi_ok) {
990
+ napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function");
991
+ return NULL;
992
+ }
993
+ ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_resp() : %p", addon_data->tsfn_on_resp);
994
+ }
995
+ else {
996
+ ZITI_NODEJS_LOG(DEBUG, "on_resp callback is NOT specified");
976
997
  }
977
- ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_resp() : %p", addon_data->tsfn_on_resp);
978
998
 
979
999
 
980
1000
  // Obtain ptr to JS on_resp_data callback function
package/src/ziti_init.c CHANGED
@@ -323,6 +323,8 @@ napi_value _ziti_init(napi_env env, const napi_callback_info info) {
323
323
  napi_throw_error(env, NULL, "Failed to napi_create_threadsafe_function");
324
324
  }
325
325
 
326
+ ziti_log_init(thread_loop, ZITI_LOG_DEFAULT_LEVEL, NULL);
327
+
326
328
  ziti_config cfg = {0};
327
329
 
328
330
  int rc = ziti_load_config(&cfg, config_file_name);