@nsshunt/stsfhirclient 1.0.65 → 1.0.66

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.
@@ -8,7 +8,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
8
8
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
9
  var __privateAdd = (obj, member, value2) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value2);
10
10
  var __privateSet = (obj, member, value2, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value2) : member.set(obj, value2), value2);
11
- var _socketUtils, _id, _options2, _clientName, _debug, _error, _info, _SetupWSSClient, _OnSocketConnected, _options3, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot, _fhirSocketClient, _LogDebugMessage, _LogErrorMessage, _HandleError, _InvokeResourceAPI, _TestMode, ___InvokeResourceAPI, _BuildQueryString;
11
+ var _socketUtils, _id, _options2, _clientName, _debug, _error, _info, _SetupWSSClient, _OnSocketConnected, _options3, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot, _fhirSocketClient, _LogDebugMessage, _LogErrorMessage, _HandleError, ___InvokeResourceAPI, _InvokeResourceAPI, _TestMode, _BuildQueryString;
12
12
  import axios from "axios";
13
13
  import { defaultLogger, Sleep, STSAxiosConfig } from "@nsshunt/stsutils";
14
14
  const byteToHex = [];
@@ -5380,10 +5380,33 @@ class FhirClient {
5380
5380
  } else {
5381
5381
  __privateGet(this, _LogDebugMessage).call(this, chalk.red(`AXIOS Error = [${axiosError}]`));
5382
5382
  }
5383
+ return responseCode;
5384
+ } else if (error.responseCode) {
5385
+ return error.responseCode;
5386
+ } else {
5387
+ return responseCode;
5383
5388
  }
5384
- return responseCode;
5385
5389
  });
5386
- __privateAdd(this, _InvokeResourceAPI, async (url2, httpVerb, domainResource, filters, searchParams, errorCb) => {
5390
+ __privateAdd(this, ___InvokeResourceAPI, async (metaData) => {
5391
+ try {
5392
+ const { url: url2, httpVerb, domainResource, filters } = metaData;
5393
+ if (__privateGet(this, _options3).testingMode) {
5394
+ await __privateGet(this, _TestMode).call(this, metaData);
5395
+ }
5396
+ const accessToken = await __privateGet(this, _options3).GetAccessToken();
5397
+ const requestConfig = new STSAxiosConfig(url2, httpVerb).withAuthHeaders(accessToken, __privateGet(this, _DUMMY_USER)).withData(filters ? filters : domainResource ? domainResource : void 0);
5398
+ if (isNode$1 && __privateGet(this, _options3).agentManager) {
5399
+ requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
5400
+ }
5401
+ return await axios(requestConfig.config);
5402
+ } catch (error) {
5403
+ throw {
5404
+ responseCode: __privateGet(this, _HandleError).call(this, error),
5405
+ error
5406
+ };
5407
+ }
5408
+ });
5409
+ __privateAdd(this, _InvokeResourceAPI, async (url2, httpVerb, domainResource, filters, searchParams) => {
5387
5410
  const id = v4();
5388
5411
  __privateGet(this, _invokeMethods)[id] = {
5389
5412
  id,
@@ -5393,33 +5416,45 @@ class FhirClient {
5393
5416
  httpVerb,
5394
5417
  domainResource,
5395
5418
  filters,
5396
- searchParams,
5397
- errorCb
5419
+ searchParams
5398
5420
  };
5399
5421
  const InvokeAPI = async (id2) => {
5400
5422
  const metadataRecord = __privateGet(this, _invokeMethods)[id2];
5401
5423
  let performRetry = false;
5402
- const returnData = await __privateGet(this, ___InvokeResourceAPI).call(this, metadataRecord, (statusCode, error) => {
5424
+ let returnData = null;
5425
+ let responseCode = null;
5426
+ let originalError;
5427
+ try {
5428
+ returnData = await __privateGet(this, ___InvokeResourceAPI).call(this, metadataRecord);
5429
+ } catch (error) {
5403
5430
  console.error(chalk.red(`#InvokeResourceAPI(): Error: [${error}], Attempt: [${metadataRecord.retries + 1}]`));
5404
- const noRetryIndex = __privateGet(this, _NoRetryStatusCodes).indexOf(statusCode);
5405
- if (noRetryIndex === -1) {
5406
- if (statusCode === StatusCodes.UNAUTHORIZED) {
5407
- console.error(chalk.red(`#InvokeResourceAPI(): Authentication error, resetting access_token (to null).`));
5408
- __privateGet(this, _options3).ResetAccessToken();
5409
- if (__privateGet(this, _options3).clientTelemetryEvents) {
5410
- __privateGet(this, _options3).clientTelemetryEvents.AuthenticationErrorInc();
5431
+ if (error) {
5432
+ originalError = error;
5433
+ if (error.responseCode) {
5434
+ responseCode = error.responseCode;
5435
+ const noRetryIndex = __privateGet(this, _NoRetryStatusCodes).indexOf(error.responseCode);
5436
+ if (noRetryIndex === -1) {
5437
+ if (error.responseCode === StatusCodes.UNAUTHORIZED) {
5438
+ console.error(chalk.red(`#InvokeResourceAPI(): Authentication error, resetting access_token (to null).`));
5439
+ __privateGet(this, _options3).ResetAccessToken();
5440
+ if (__privateGet(this, _options3).clientTelemetryEvents) {
5441
+ __privateGet(this, _options3).clientTelemetryEvents.AuthenticationErrorInc();
5442
+ }
5443
+ }
5444
+ if (isNode$1 && __privateGet(this, _options3).agentManager) {
5445
+ console.error(chalk.red(`#InvokeResourceAPI(): Resetting https agent (to null).`));
5446
+ __privateGet(this, _options3).agentManager.ResetAgent();
5447
+ }
5448
+ performRetry = true;
5411
5449
  }
5412
5450
  }
5413
- if (isNode$1 && __privateGet(this, _options3).agentManager) {
5414
- console.error(chalk.red(`#InvokeResourceAPI(): Resetting https agent (to null).`));
5415
- __privateGet(this, _options3).agentManager.ResetAgent();
5416
- }
5417
- performRetry = true;
5418
5451
  }
5419
- });
5452
+ }
5420
5453
  return {
5421
5454
  response: returnData,
5422
- retry: performRetry
5455
+ retry: performRetry,
5456
+ responseCode,
5457
+ originalError
5423
5458
  };
5424
5459
  };
5425
5460
  let retVal = null;
@@ -5440,49 +5475,41 @@ class FhirClient {
5440
5475
  }
5441
5476
  if (retVal) {
5442
5477
  if (retVal.retry === true) {
5443
- errorCb(new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${__privateGet(this, _invokeMethods)[id].retries}]`));
5478
+ const retries = __privateGet(this, _invokeMethods)[id].retries;
5444
5479
  delete __privateGet(this, _invokeMethods)[id];
5445
- return null;
5480
+ throw {
5481
+ responseCode: retVal.responseCode,
5482
+ error: new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${retries}], Original Error: [${retVal.originalError}]`)
5483
+ };
5446
5484
  } else {
5447
5485
  return retVal.response;
5448
5486
  }
5449
5487
  } else {
5450
- return null;
5451
- }
5452
- });
5453
- __privateAdd(this, _TestMode, (metaData, errorCb) => {
5454
- const { id, url: url2, httpVerb, filters, retries } = metaData;
5455
- if (retries < 1) {
5456
- errorCb(401, new Error(`Testing Error Only. Error Code: [401], Message ID: [${id}, url: [${url2}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
5457
- return true;
5458
- }
5459
- if (retries < 2) {
5460
- errorCb(500, new Error(`Testing Error Only. Error Code: [500], Message ID: [${id}, url: [${url2}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`));
5461
- return true;
5488
+ throw {
5489
+ responseCode: 500,
5490
+ error: new Error(`#InvokeResourceAPI(): Null returned from API call.`)
5491
+ };
5462
5492
  }
5463
- return false;
5464
5493
  });
5465
- __privateAdd(this, ___InvokeResourceAPI, async (metaData, errorCb) => {
5466
- try {
5467
- const { url: url2, httpVerb, domainResource, filters } = metaData;
5468
- if (__privateGet(this, _options3).testingMode) {
5469
- if (__privateGet(this, _TestMode).call(this, metaData, errorCb)) {
5470
- return null;
5471
- }
5494
+ __privateAdd(this, _TestMode, async (metaData) => {
5495
+ return new Promise((resolve, reject) => {
5496
+ const { id, url: url2, httpVerb, filters, retries } = metaData;
5497
+ if (retries < 1) {
5498
+ reject({
5499
+ responseCode: 401,
5500
+ error: new Error(`Testing Error Only. Error Code: [401], Message ID: [${id}, url: [${url2}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`)
5501
+ });
5472
5502
  }
5473
- const accessToken = await __privateGet(this, _options3).GetAccessToken();
5474
- const requestConfig = new STSAxiosConfig(url2, httpVerb).withAuthHeaders(accessToken, __privateGet(this, _DUMMY_USER)).withData(filters ? filters : domainResource ? domainResource : void 0);
5475
- if (isNode$1 && __privateGet(this, _options3).agentManager) {
5476
- requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
5503
+ if (retries < 2) {
5504
+ reject({
5505
+ responseCode: 500,
5506
+ error: new Error(`Testing Error Only. Error Code: [500], Message ID: [${id}, url: [${url2}], httpVerb: [${httpVerb}], filters: [${filters}], Retries: [${retries}]`)
5507
+ });
5477
5508
  }
5478
- return await axios(requestConfig.config);
5479
- } catch (error) {
5480
- const responseCode = __privateGet(this, _HandleError).call(this, error);
5481
- errorCb(responseCode, error);
5482
- return null;
5483
- }
5509
+ resolve(false);
5510
+ });
5484
5511
  });
5485
- __publicField(this, "GetResource", async (resource, id, filters, errorCb) => {
5512
+ __publicField(this, "GetResource", async (resource, id, filters) => {
5486
5513
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5487
5514
  const retVal = await __privateGet(this, _fhirSocketClient).GetResource(resource, id);
5488
5515
  if (retVal.status === StatusCodes.OK) {
@@ -5492,7 +5519,7 @@ class FhirClient {
5492
5519
  }
5493
5520
  } else {
5494
5521
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
5495
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, null, errorCb);
5522
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, null);
5496
5523
  if (response) {
5497
5524
  return response.data;
5498
5525
  } else {
@@ -5506,7 +5533,7 @@ class FhirClient {
5506
5533
  url2.search = searchParams.toString();
5507
5534
  return url2.toString();
5508
5535
  });
5509
- __publicField(this, "GetResources", async (resource, filters, searchParams, errorCb) => {
5536
+ __publicField(this, "GetResources", async (resource, filters, searchParams) => {
5510
5537
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5511
5538
  return __privateGet(this, _fhirSocketClient).GetResources(resource, searchParams);
5512
5539
  } else {
@@ -5514,7 +5541,7 @@ class FhirClient {
5514
5541
  if (searchParams) {
5515
5542
  url2 = __privateGet(this, _BuildQueryString).call(this, url2, searchParams);
5516
5543
  }
5517
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, searchParams, errorCb);
5544
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, searchParams);
5518
5545
  if (response) {
5519
5546
  return response.data;
5520
5547
  } else {
@@ -5522,23 +5549,21 @@ class FhirClient {
5522
5549
  }
5523
5550
  }
5524
5551
  });
5525
- __publicField(this, "CreateResource", async (resource, domainResource, errorCb) => {
5552
+ __publicField(this, "CreateResource", async (resource, domainResource) => {
5526
5553
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5527
5554
  const retVal = await __privateGet(this, _fhirSocketClient).CreateResource(resource, domainResource);
5528
5555
  if (retVal.status === StatusCodes.CREATED) {
5529
5556
  return retVal.value;
5530
5557
  } else {
5531
- errorCb(new Error(`CreateResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.CREATED}]`));
5532
5558
  return null;
5533
5559
  }
5534
5560
  } else {
5535
5561
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5536
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null, null, errorCb);
5562
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null, null);
5537
5563
  if (response) {
5538
5564
  if (response.status === StatusCodes.CREATED) {
5539
5565
  return response.data;
5540
5566
  } else {
5541
- errorCb(new Error(`CreateResource(): Invalid response status code: [${response.status}] expected: [${StatusCodes.CREATED}]`));
5542
5567
  return null;
5543
5568
  }
5544
5569
  } else {
@@ -5546,12 +5571,12 @@ class FhirClient {
5546
5571
  }
5547
5572
  }
5548
5573
  });
5549
- __publicField(this, "UpdateResource", async (resource, domainResource, errorCb) => {
5574
+ __publicField(this, "UpdateResource", async (resource, domainResource) => {
5550
5575
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5551
5576
  return __privateGet(this, _fhirSocketClient).UpdateResource(resource, domainResource);
5552
5577
  } else {
5553
5578
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
5554
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null, null, errorCb);
5579
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null, null);
5555
5580
  if (response) {
5556
5581
  return response.data;
5557
5582
  } else {
@@ -5559,12 +5584,12 @@ class FhirClient {
5559
5584
  }
5560
5585
  }
5561
5586
  });
5562
- __publicField(this, "UpdateResources", async (resource, domainResources, errorCb) => {
5587
+ __publicField(this, "UpdateResources", async (resource, domainResources) => {
5563
5588
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5564
5589
  return __privateGet(this, _fhirSocketClient).UpdateResources(resource, domainResources);
5565
5590
  } else {
5566
5591
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5567
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null, null, errorCb);
5592
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null, null);
5568
5593
  if (response) {
5569
5594
  return response.data;
5570
5595
  } else {
@@ -5572,12 +5597,12 @@ class FhirClient {
5572
5597
  }
5573
5598
  }
5574
5599
  });
5575
- __publicField(this, "PatchResource", async (resource, domainResource, errorCb) => {
5600
+ __publicField(this, "PatchResource", async (resource, domainResource) => {
5576
5601
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5577
5602
  return __privateGet(this, _fhirSocketClient).PatchResource(resource, domainResource);
5578
5603
  } else {
5579
5604
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
5580
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null, null, errorCb);
5605
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null, null);
5581
5606
  if (response) {
5582
5607
  return response.data;
5583
5608
  } else {
@@ -5585,12 +5610,12 @@ class FhirClient {
5585
5610
  }
5586
5611
  }
5587
5612
  });
5588
- __publicField(this, "PatchResources", async (resource, domainResources, errorCb) => {
5613
+ __publicField(this, "PatchResources", async (resource, domainResources) => {
5589
5614
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5590
5615
  return __privateGet(this, _fhirSocketClient).PatchResources(resource, domainResources);
5591
5616
  } else {
5592
5617
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5593
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null, null, errorCb);
5618
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null, null);
5594
5619
  if (response) {
5595
5620
  return response.data;
5596
5621
  } else {
@@ -5598,12 +5623,12 @@ class FhirClient {
5598
5623
  }
5599
5624
  }
5600
5625
  });
5601
- __publicField(this, "DeleteResource", async (resource, id, errorCb) => {
5626
+ __publicField(this, "DeleteResource", async (resource, id) => {
5602
5627
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5603
5628
  return __privateGet(this, _fhirSocketClient).DeleteResource(resource, id);
5604
5629
  } else {
5605
5630
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
5606
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null, null, errorCb);
5631
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null, null);
5607
5632
  if (response) {
5608
5633
  return response.data;
5609
5634
  } else {
@@ -5611,12 +5636,12 @@ class FhirClient {
5611
5636
  }
5612
5637
  }
5613
5638
  });
5614
- __publicField(this, "DeleteResources", async (resource, domainResources, errorCb) => {
5639
+ __publicField(this, "DeleteResources", async (resource, domainResources) => {
5615
5640
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5616
5641
  return __privateGet(this, _fhirSocketClient).DeleteResources(resource, domainResources);
5617
5642
  } else {
5618
5643
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5619
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null, null, errorCb);
5644
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null, null);
5620
5645
  if (response) {
5621
5646
  return response.data;
5622
5647
  } else {
@@ -5664,9 +5689,9 @@ _fhirSocketClient = new WeakMap();
5664
5689
  _LogDebugMessage = new WeakMap();
5665
5690
  _LogErrorMessage = new WeakMap();
5666
5691
  _HandleError = new WeakMap();
5692
+ ___InvokeResourceAPI = new WeakMap();
5667
5693
  _InvokeResourceAPI = new WeakMap();
5668
5694
  _TestMode = new WeakMap();
5669
- ___InvokeResourceAPI = new WeakMap();
5670
5695
  _BuildQueryString = new WeakMap();
5671
5696
  export {
5672
5697
  FhirClient