diff --git a/README.md b/README.md index 8fcb073..7f8947c 100644 --- a/README.md +++ b/README.md @@ -57,15 +57,20 @@ For more context on this SDK, you may be interested in this # Supported platforms The `@openziti/ziti-sdk-nodejs` module works with the following Node.js versions: -- v12.x -- v13.x -- v14.x -- v15.x - v16.x -- v17.x - v18.x +- v19.x +- v20.x + +The `@openziti/ziti-sdk-nodejs` module works with the following architectures: +- amd64 +- arm64 + +The `@openziti/ziti-sdk-nodejs` module works with the following Operating Systems: +- macos +- linux +- windows -Binaries for most Node versions and platforms are provided by default via [@mapbox/node-pre-gyp](https://github.com/mapbox/node-pre-gyp). # Installing @@ -107,6 +112,7 @@ const on_resp_data = ( obj ) => { // Perform an HTTP GET request to a dark OpenZiti web service ziti.httpRequest( 'myDarkWebService', // OpenZiti Service name or HTTP origin part of the URL + undefined, // schemeHostPort parm is mutually-exclusive with serviceName parm 'GET', '/', // path part of the URL including query params ['Accept: application/json' ], // headers @@ -221,4 +227,18 @@ for tracking bugs and feature requests and have limited bandwidth to address the - Participate in discussion on [Discourse](https://openziti.discourse.group/) +# Building from source on MacOS + +``` js +git clone https://github.com/microsoft/vcpkg.git +./vcpkg/bootstrap-vcpkg.sh +export VCPKG_ROOT=`pwd`/vcpkg +brew install cmake +brew install ninja +brew install pkg-config +git clone https://github.com/openziti/ziti-sdk-nodejs.git +cd ziti-sdk-nodejs +npm run build +``` + Copyright© NetFoundry, Inc. diff --git a/package-lock.json b/package-lock.json index 74f48e9..6850e72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@openziti/ziti-sdk-nodejs", - "version": "0.14.0-dev", + "version": "0.14.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@openziti/ziti-sdk-nodejs", - "version": "0.14.0-dev", + "version": "0.14.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 81a8e38..4b417ce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@openziti/ziti-sdk-nodejs", "description": "A NodeJS-based SDK for delivering secure applications over a Ziti Network", - "version": "0.14.0", + "version": "0.14.1", "main": "./lib/ziti", "scripts": { "build": "npm run build:init && npm run build:configure && npm run build:make", diff --git a/src/Ziti_https_request.c b/src/Ziti_https_request.c index deb36e2..3cacfd1 100644 --- a/src/Ziti_https_request.c +++ b/src/Ziti_https_request.c @@ -606,12 +606,14 @@ void on_resp(tlsuv_http_resp_t *resp, void *data) { } // Initiate the call into the JavaScript callback. The call into JavaScript will not have happened when this function returns, but it will be queued. - int rc = napi_call_threadsafe_function( - addon_data->tsfn_on_resp, - item, - napi_tsfn_blocking); - if (rc != napi_ok) { - napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback"); + if (addon_data->tsfn_on_resp != NULL) { + int rc = napi_call_threadsafe_function( + addon_data->tsfn_on_resp, + item, + napi_tsfn_blocking); + if (rc != napi_ok) { + napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback"); + } } if (UV_EOF != resp->code) { @@ -711,12 +713,14 @@ void on_client(uv_work_t* req, int status) { } // Initiate the call into the JavaScript callback. The call into JavaScript will not have happened when this function returns, but it will be queued. - int rc = napi_call_threadsafe_function( - addon_data->tsfn_on_req, - addon_data, - napi_tsfn_blocking); - if (rc != napi_ok) { - napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback"); + if (addon_data->tsfn_on_req != NULL) { + int rc = napi_call_threadsafe_function( + addon_data->tsfn_on_req, + addon_data, + napi_tsfn_blocking); + if (rc != napi_ok) { + napi_throw_error(addon_data->env, "EINVAL", "failure to invoke JS callback"); + } } } @@ -908,73 +912,89 @@ napi_value _Ziti_http_request(napi_env env, const napi_callback_info info) { ZITI_NODEJS_LOG(DEBUG, "path: %s", addon_data->path); + HttpsReq* httpsReq = calloc(1, sizeof(HttpsReq)); + addon_data->httpsReq = httpsReq; + httpsReq->addon_data = addon_data; + // Obtain ptr to JS on_req callback function napi_value js_cb = args[5]; napi_value work_name; + status = napi_typeof(env, args[5], &valuetype); + if (valuetype != napi_undefined) { + ZITI_NODEJS_LOG(DEBUG, "on_req callback is specified"); - HttpsReq* httpsReq = calloc(1, sizeof(HttpsReq)); - addon_data->httpsReq = httpsReq; - httpsReq->addon_data = addon_data; + // Create a string to describe this asynchronous operation. + rc = napi_create_string_utf8(env, "on_req", NAPI_AUTO_LENGTH, &work_name); + if (rc != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to create string"); + return NULL; + } - // Create a string to describe this asynchronous operation. - rc = napi_create_string_utf8(env, "on_req", NAPI_AUTO_LENGTH, &work_name); - if (rc != napi_ok) { - napi_throw_error(env, "EINVAL", "Failed to create string"); - return NULL; + // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn) + // which we can call from a worker thread. + rc = napi_create_threadsafe_function( + env, + js_cb, + NULL, + work_name, + 0, + 1, + NULL, + NULL, + NULL, + CallJs_on_req, + &(addon_data->tsfn_on_req) + ); + ZITI_NODEJS_LOG(DEBUG, "2: %d", rc); + if (rc != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function"); + return NULL; + } + ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_req() : %p", addon_data->tsfn_on_req); } - - // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn) - // which we can call from a worker thread. - rc = napi_create_threadsafe_function( - env, - js_cb, - NULL, - work_name, - 0, - 1, - NULL, - NULL, - NULL, - CallJs_on_req, - &(addon_data->tsfn_on_req) - ); - if (rc != napi_ok) { - napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function"); - return NULL; + else { + ZITI_NODEJS_LOG(DEBUG, "on_req callback is NOT specified"); } - ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_req() : %p", addon_data->tsfn_on_req); // Obtain ptr to JS on_resp callback function napi_value js_cb2 = args[6]; - // Create a string to describe this asynchronous operation. - rc = napi_create_string_utf8(env, "on_resp", NAPI_AUTO_LENGTH, &work_name); - if (rc != napi_ok) { - napi_throw_error(env, "EINVAL", "Failed to create string"); - return NULL; - } + status = napi_typeof(env, args[6], &valuetype); + if (valuetype != napi_undefined) { + ZITI_NODEJS_LOG(DEBUG, "on_resp callback is specified"); - // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn) - // which we can call from a worker thread. - rc = napi_create_threadsafe_function( - env, - js_cb2, - NULL, - work_name, - 0, - 1, - NULL, - NULL, - NULL, - CallJs_on_resp, - &(addon_data->tsfn_on_resp) - ); - if (rc != napi_ok) { - napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function"); - return NULL; + // Create a string to describe this asynchronous operation. + rc = napi_create_string_utf8(env, "on_resp", NAPI_AUTO_LENGTH, &work_name); + if (rc != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to create string"); + return NULL; + } + + // Convert the callback retrieved from JavaScript into a thread-safe function (tsfn) + // which we can call from a worker thread. + rc = napi_create_threadsafe_function( + env, + js_cb2, + NULL, + work_name, + 0, + 1, + NULL, + NULL, + NULL, + CallJs_on_resp, + &(addon_data->tsfn_on_resp) + ); + if (rc != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to create threadsafe_function"); + return NULL; + } + ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_resp() : %p", addon_data->tsfn_on_resp); + } + else { + ZITI_NODEJS_LOG(DEBUG, "on_resp callback is NOT specified"); } - ZITI_NODEJS_LOG(DEBUG, "napi_create_threadsafe_function addon_data->tsfn_on_resp() : %p", addon_data->tsfn_on_resp); // Obtain ptr to JS on_resp_data callback function diff --git a/src/ziti_init.c b/src/ziti_init.c index a369fe1..99d8623 100644 --- a/src/ziti_init.c +++ b/src/ziti_init.c @@ -323,6 +323,8 @@ napi_value _ziti_init(napi_env env, const napi_callback_info info) { napi_throw_error(env, NULL, "Failed to napi_create_threadsafe_function"); } + ziti_log_init(thread_loop, ZITI_LOG_DEFAULT_LEVEL, NULL); + ziti_config cfg = {0}; int rc = ziti_load_config(&cfg, config_file_name);