@nsshunt/stsfhirclient 1.0.66 → 1.0.67

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, _InvokeResourceAPI, _TestMode, _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, _TestMode, ___InvokeResourceAPI, _BuildQueryString;
12
12
  import axios from "axios";
13
13
  import { defaultLogger, Sleep, STSAxiosConfig } from "@nsshunt/stsutils";
14
14
  const byteToHex = [];
@@ -5380,33 +5380,10 @@ 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;
5388
5383
  }
5384
+ return responseCode;
5389
5385
  });
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) => {
5386
+ __privateAdd(this, _InvokeResourceAPI, async (url2, httpVerb, domainResource, filters, searchParams, errorCb) => {
5410
5387
  const id = v4();
5411
5388
  __privateGet(this, _invokeMethods)[id] = {
5412
5389
  id,
@@ -5416,45 +5393,33 @@ class FhirClient {
5416
5393
  httpVerb,
5417
5394
  domainResource,
5418
5395
  filters,
5419
- searchParams
5396
+ searchParams,
5397
+ errorCb
5420
5398
  };
5421
5399
  const InvokeAPI = async (id2) => {
5422
5400
  const metadataRecord = __privateGet(this, _invokeMethods)[id2];
5423
5401
  let performRetry = false;
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) {
5402
+ const returnData = await __privateGet(this, ___InvokeResourceAPI).call(this, metadataRecord, (statusCode, error) => {
5430
5403
  console.error(chalk.red(`#InvokeResourceAPI(): Error: [${error}], Attempt: [${metadataRecord.retries + 1}]`));
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;
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();
5449
5411
  }
5450
5412
  }
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;
5451
5418
  }
5452
- }
5419
+ });
5453
5420
  return {
5454
5421
  response: returnData,
5455
- retry: performRetry,
5456
- responseCode,
5457
- originalError
5422
+ retry: performRetry
5458
5423
  };
5459
5424
  };
5460
5425
  let retVal = null;
@@ -5475,41 +5440,49 @@ class FhirClient {
5475
5440
  }
5476
5441
  if (retVal) {
5477
5442
  if (retVal.retry === true) {
5478
- const retries = __privateGet(this, _invokeMethods)[id].retries;
5443
+ errorCb(new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${__privateGet(this, _invokeMethods)[id].retries}]`));
5479
5444
  delete __privateGet(this, _invokeMethods)[id];
5480
- throw {
5481
- responseCode: retVal.responseCode,
5482
- error: new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${retries}], Original Error: [${retVal.originalError}]`)
5483
- };
5445
+ return null;
5484
5446
  } else {
5485
5447
  return retVal.response;
5486
5448
  }
5487
5449
  } else {
5488
- throw {
5489
- responseCode: 500,
5490
- error: new Error(`#InvokeResourceAPI(): Null returned from API call.`)
5491
- };
5450
+ return null;
5492
5451
  }
5493
5452
  });
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
- });
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;
5462
+ }
5463
+ return false;
5464
+ });
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
+ }
5502
5472
  }
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
- });
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);
5508
5477
  }
5509
- resolve(false);
5510
- });
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
+ }
5511
5484
  });
5512
- __publicField(this, "GetResource", async (resource, id, filters) => {
5485
+ __publicField(this, "GetResource", async (resource, id, filters, errorCb) => {
5513
5486
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5514
5487
  const retVal = await __privateGet(this, _fhirSocketClient).GetResource(resource, id);
5515
5488
  if (retVal.status === StatusCodes.OK) {
@@ -5519,7 +5492,7 @@ class FhirClient {
5519
5492
  }
5520
5493
  } else {
5521
5494
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
5522
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, null);
5495
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, null, errorCb);
5523
5496
  if (response) {
5524
5497
  return response.data;
5525
5498
  } else {
@@ -5533,7 +5506,7 @@ class FhirClient {
5533
5506
  url2.search = searchParams.toString();
5534
5507
  return url2.toString();
5535
5508
  });
5536
- __publicField(this, "GetResources", async (resource, filters, searchParams) => {
5509
+ __publicField(this, "GetResources", async (resource, filters, searchParams, errorCb) => {
5537
5510
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5538
5511
  return __privateGet(this, _fhirSocketClient).GetResources(resource, searchParams);
5539
5512
  } else {
@@ -5541,7 +5514,7 @@ class FhirClient {
5541
5514
  if (searchParams) {
5542
5515
  url2 = __privateGet(this, _BuildQueryString).call(this, url2, searchParams);
5543
5516
  }
5544
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, searchParams);
5517
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters, searchParams, errorCb);
5545
5518
  if (response) {
5546
5519
  return response.data;
5547
5520
  } else {
@@ -5549,21 +5522,23 @@ class FhirClient {
5549
5522
  }
5550
5523
  }
5551
5524
  });
5552
- __publicField(this, "CreateResource", async (resource, domainResource) => {
5525
+ __publicField(this, "CreateResource", async (resource, domainResource, errorCb) => {
5553
5526
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5554
5527
  const retVal = await __privateGet(this, _fhirSocketClient).CreateResource(resource, domainResource);
5555
5528
  if (retVal.status === StatusCodes.CREATED) {
5556
5529
  return retVal.value;
5557
5530
  } else {
5531
+ errorCb(new Error(`CreateResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.CREATED}]`));
5558
5532
  return null;
5559
5533
  }
5560
5534
  } else {
5561
5535
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5562
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null, null);
5536
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null, null, errorCb);
5563
5537
  if (response) {
5564
5538
  if (response.status === StatusCodes.CREATED) {
5565
5539
  return response.data;
5566
5540
  } else {
5541
+ errorCb(new Error(`CreateResource(): Invalid response status code: [${response.status}] expected: [${StatusCodes.CREATED}]`));
5567
5542
  return null;
5568
5543
  }
5569
5544
  } else {
@@ -5571,12 +5546,12 @@ class FhirClient {
5571
5546
  }
5572
5547
  }
5573
5548
  });
5574
- __publicField(this, "UpdateResource", async (resource, domainResource) => {
5549
+ __publicField(this, "UpdateResource", async (resource, domainResource, errorCb) => {
5575
5550
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5576
5551
  return __privateGet(this, _fhirSocketClient).UpdateResource(resource, domainResource);
5577
5552
  } else {
5578
5553
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
5579
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null, null);
5554
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null, null, errorCb);
5580
5555
  if (response) {
5581
5556
  return response.data;
5582
5557
  } else {
@@ -5584,12 +5559,12 @@ class FhirClient {
5584
5559
  }
5585
5560
  }
5586
5561
  });
5587
- __publicField(this, "UpdateResources", async (resource, domainResources) => {
5562
+ __publicField(this, "UpdateResources", async (resource, domainResources, errorCb) => {
5588
5563
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5589
5564
  return __privateGet(this, _fhirSocketClient).UpdateResources(resource, domainResources);
5590
5565
  } else {
5591
5566
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5592
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null, null);
5567
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null, null, errorCb);
5593
5568
  if (response) {
5594
5569
  return response.data;
5595
5570
  } else {
@@ -5597,12 +5572,12 @@ class FhirClient {
5597
5572
  }
5598
5573
  }
5599
5574
  });
5600
- __publicField(this, "PatchResource", async (resource, domainResource) => {
5575
+ __publicField(this, "PatchResource", async (resource, domainResource, errorCb) => {
5601
5576
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5602
5577
  return __privateGet(this, _fhirSocketClient).PatchResource(resource, domainResource);
5603
5578
  } else {
5604
5579
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
5605
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null, null);
5580
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null, null, errorCb);
5606
5581
  if (response) {
5607
5582
  return response.data;
5608
5583
  } else {
@@ -5610,12 +5585,12 @@ class FhirClient {
5610
5585
  }
5611
5586
  }
5612
5587
  });
5613
- __publicField(this, "PatchResources", async (resource, domainResources) => {
5588
+ __publicField(this, "PatchResources", async (resource, domainResources, errorCb) => {
5614
5589
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5615
5590
  return __privateGet(this, _fhirSocketClient).PatchResources(resource, domainResources);
5616
5591
  } else {
5617
5592
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5618
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null, null);
5593
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null, null, errorCb);
5619
5594
  if (response) {
5620
5595
  return response.data;
5621
5596
  } else {
@@ -5623,12 +5598,12 @@ class FhirClient {
5623
5598
  }
5624
5599
  }
5625
5600
  });
5626
- __publicField(this, "DeleteResource", async (resource, id) => {
5601
+ __publicField(this, "DeleteResource", async (resource, id, errorCb) => {
5627
5602
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5628
5603
  return __privateGet(this, _fhirSocketClient).DeleteResource(resource, id);
5629
5604
  } else {
5630
5605
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
5631
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null, null);
5606
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null, null, errorCb);
5632
5607
  if (response) {
5633
5608
  return response.data;
5634
5609
  } else {
@@ -5636,12 +5611,12 @@ class FhirClient {
5636
5611
  }
5637
5612
  }
5638
5613
  });
5639
- __publicField(this, "DeleteResources", async (resource, domainResources) => {
5614
+ __publicField(this, "DeleteResources", async (resource, domainResources, errorCb) => {
5640
5615
  if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
5641
5616
  return __privateGet(this, _fhirSocketClient).DeleteResources(resource, domainResources);
5642
5617
  } else {
5643
5618
  const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
5644
- const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null, null);
5619
+ const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null, null, errorCb);
5645
5620
  if (response) {
5646
5621
  return response.data;
5647
5622
  } else {
@@ -5689,9 +5664,9 @@ _fhirSocketClient = new WeakMap();
5689
5664
  _LogDebugMessage = new WeakMap();
5690
5665
  _LogErrorMessage = new WeakMap();
5691
5666
  _HandleError = new WeakMap();
5692
- ___InvokeResourceAPI = new WeakMap();
5693
5667
  _InvokeResourceAPI = new WeakMap();
5694
5668
  _TestMode = new WeakMap();
5669
+ ___InvokeResourceAPI = new WeakMap();
5695
5670
  _BuildQueryString = new WeakMap();
5696
5671
  export {
5697
5672
  FhirClient