@openziti/ziti-sdk-nodejs 0.13.1 → 0.13.2

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
@@ -104,13 +104,13 @@ const on_resp_data = ( obj ) => {
104
104
 
105
105
  // Perform an HTTP GET request to a dark OpenZiti web service
106
106
  ziti.httpRequest(
107
- 'myDarkWebService',
108
- 'GET',
109
- '/', // path
107
+ 'myDarkWebService', // OpenZiti Service name or HTTP origin part of the URL
108
+ 'GET',
109
+ '/', // path part of the URL including query params
110
110
  ['Accept: application/json' ], // headers
111
- undefined, // optional on_req cb
112
- undefined, // optional on_req_data cb
113
- on_resp_data // optional on_resp_data cb
111
+ undefined, // optional on_req cb
112
+ undefined, // optional on_req_data cb
113
+ on_resp_data // optional on_resp_data cb
114
114
  );
115
115
 
116
116
  ```
@@ -48,7 +48,7 @@ const on_resp_data = ( obj ) => {
48
48
 
49
49
  const httpRequest = ( url, method, path, headers, on_req_cb, on_resp_cb, on_resp_data_cb ) => {
50
50
 
51
- console.log('httpRequest entered: ', url, method, headers);
51
+ console.log(`httpRequest entered: httpOrigin|serviceName: "${url}", method: "${method}", path: "${path}", headers: "${headers}"`);
52
52
 
53
53
  let _on_req_cb;
54
54
  let _on_resp_cb;
package/lib/init.js CHANGED
@@ -27,11 +27,8 @@ const init = ( identityPath ) => {
27
27
 
28
28
  let rc = ziti.ziti_init( identityPath, ( result ) => {
29
29
 
30
- setTimeout( () => {
31
-
32
30
  return resolve( result );
33
31
 
34
- }, 1000);
35
32
  });
36
33
 
37
34
  if (rc < 0) {
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.13.1",
4
+ "version": "0.13.2",
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",
@@ -726,9 +726,9 @@ void on_client(uv_work_t* req, int status) {
726
726
  /**
727
727
  * Initiate an HTTPS request
728
728
  *
729
- * @param {string} [0] serviceName | URL
729
+ * @param {string} [0] serviceName | url Ziti service name or HTTP origin
730
730
  * @param {string} [1] method
731
- * @param {string} [2] path
731
+ * @param {string} [2] path path part of the URL including query params
732
732
  * @param {string[]} [3] headers; Array of strings of the form "name:value"
733
733
  * @param {func} [4] JS on_req callback; This is invoked from 'on_client' function above
734
734
  * @param {func} [5] JS on_resp callback; This is invoked from 'on_resp' function above
package/src/ziti_init.c CHANGED
@@ -21,6 +21,8 @@ ziti_context ztx = NULL;
21
21
  typedef struct {
22
22
  napi_async_work work;
23
23
  napi_threadsafe_function tsfn;
24
+ int zitiContextEventStatus;
25
+ bool on_init_cb_invoked;
24
26
  } AddonData;
25
27
 
26
28
 
@@ -129,16 +131,8 @@ static void on_ziti_event(ziti_context _ztx, const ziti_event_t *event) {
129
131
  ZITI_NODEJS_LOG(ERROR, "Failed to connect to controller: %s", event->event.ctx.err);
130
132
  }
131
133
 
132
- // Initiate the call into the JavaScript callback.
133
- // The call into JavaScript will not have happened
134
- // when this function returns, but it will be queued.
135
- nstatus = napi_call_threadsafe_function(
136
- addon_data->tsfn,
137
- (void*) (long) event->event.ctx.ctrl_status,
138
- napi_tsfn_blocking);
139
- if (nstatus != napi_ok) {
140
- ZITI_NODEJS_LOG(ERROR, "Unable to napi_call_threadsafe_function");
141
- }
134
+ addon_data->zitiContextEventStatus = event->event.ctx.ctrl_status;
135
+
142
136
  break;
143
137
 
144
138
  case ZitiServiceEvent:
@@ -223,6 +217,15 @@ static void on_ziti_event(ziti_context _ztx, const ziti_event_t *event) {
223
217
  free(intercept);
224
218
  }
225
219
 
220
+ // Initiate the call into the JavaScript 'on_init' callback, now that we know about all the services
221
+ ZITI_NODEJS_LOG(DEBUG, "addon_data->on_init_cb_invoked %o", addon_data->on_init_cb_invoked);
222
+ if (!addon_data->on_init_cb_invoked) {
223
+ nstatus = napi_call_threadsafe_function(
224
+ addon_data->tsfn,
225
+ (void*) (long) addon_data->zitiContextEventStatus,
226
+ napi_tsfn_blocking);
227
+ addon_data->on_init_cb_invoked = true;
228
+ }
226
229
 
227
230
  break;
228
231
 
@@ -293,7 +296,7 @@ napi_value _ziti_init(napi_env env, const napi_callback_info info) {
293
296
  // Obtain ptr to JS callback function
294
297
  napi_value js_cb = args[1];
295
298
  napi_value work_name;
296
- AddonData* addon_data = malloc(sizeof(AddonData));
299
+ AddonData* addon_data = calloc(1, sizeof(AddonData));
297
300
 
298
301
  // Create a string to describe this asynchronous operation.
299
302
  status = napi_create_string_utf8(