@nsshunt/stsobservability 1.0.75 → 1.0.77

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.
@@ -17,7 +17,7 @@ var __privateWrapper = (obj, member, setter, getter) => ({
17
17
  return __privateGet(obj, member, getter);
18
18
  }
19
19
  });
20
- var _a, _label, _options2, _data2, _val, _interval, _timeoutComputeVelocity, _lastVelocity, _delta, _maxVelocity, _timerInterval, _copy, _velocity, _velocityVal, _valStack, _averageValStack, _maxAverageValStack, _maxAverageIterations, _valStackMaxLength, _valStackAverage, _timeStamp, _maxTimeDiff, _vaTimeDiff, _velocityTimeDiff, _autoComputeVelocity, _autoComputeVelocityTimeout, _countDiff, _timeDiff, _deltaCountDiff, _deltaTimeDif, _minTimeForReporting, _averageVelocity, _InstrumentVelocity_instances, ComputeVelocityByTimeDiff_fn, ComputeVelocity_fn, SetupAutoComputeVelocity_fn, GetVelocityStackAverage_fn, GetVal_fn, SetVal_fn, GetVelocity_fn, GetMaxVelocity_fn, GetDelta_fn, GetTimeStamp_fn, GetCountDiff_fn, GetTimeDiff_fn, GetDeltaCountDiff_fn, GetDeltaTimeDif_fn, GetAverageVelocity_fn, _histogramData, _val2, _copy2, _InstrumentHistogram_instances, GetVal_fn2, SetVal_fn2, GetHistogramData_fn, SetHistogramData_fn, _messages, _readPos, _maxSize, _copy3, _useLatestMessages, _consoleLogging, _instrumentLogging, _winstonLogging, _stsLogger, _InstrumentLog_instances, DumpToConsole_fn, GetVal_fn3, SetVal_fn3, _start, _copy4, _pauseVal, _InstrumentTimerGauge_instances, GetVal_fn4, SetVal_fn4, _val3, _maxval, _lastObservedValue, _timeSeriesList, _maxSampleSize, _timerInterval2, _observer, _min, _max, _observations, _total, _copy5, _InstrumentGauge_instances, GetVal_fn5, SetVal_fn5, GetMin_fn, GetMax_fn, GetAverage_fn, GetAndResetMaxVal_fn, NumberCompare_fn, GetPercentileData_fn, _val4, _copy6, _InstrumentObject_instances, GetVal_fn6, SetVal_fn6, _tinyEmitter, _RequestCompleted, _agentManager2, _inPublish, _observer2, _publishState, _publisherTransport, _PublishInstruments_instances, PublishTimeoutLoop_fn, UpdateState_fn, _instruments, _publisher, _PublishInstrumentController_instances, GetInstrument_fn, ProcessTelemetryCommand_fn, CreateInstrument_fn, CreateInstruments_fn, _kafkaLog, _maxLogLength, _socketSubscribeKeepAlive, _options3, _ObservabilityRESTAPISubscriber_instances, LogDebugMessage_fn, LogErrorMessage_fn, InvokeRESTAPI_fn, _GetData, SetupTimeout_fn, AddKeepAlive_fn, RemoveKeepAlive_fn, _messageWithAckPayloadRecords, _socket, _maxReties, _timeoutValue, _options4, _SocketIoMessageSender_instances, LogDebugMessage_fn2, GetSubscribeKeepAliveAckEventName_fn, _socketSubscribeKeepAlive2, _socket2, _options5, _socketIoMessageSender, _ObservabilitySocketIOSubscriber_instances, LogDebugMessage_fn3, LogErrorMessage_fn2, AddKeepAlive_fn2, RemoveKeepAlive_fn2, _observabilitySocketIOSubscriber, _subscriptions, _kafkaHelper, _serviceModel, _agentModel, _lambdaModel, _options6, _ObservabilitySubscriptionManager_instances, LogDebugMessage_fn4, LogErrorMessage_fn3, _options7, _sockets, _agentManager3, _SocketIoClientHelper_instances, LogDebugMessage_fn5, LogErrorMessage_fn4, EstablishSocketConnect_fn, _socketIoServerHelperOptions, _namespace, _SetupStandardEvents, _SetupConnectionMiddleware, _SetupMessageMiddleware;
20
+ var _a, _label, _options2, _data2, _val, _interval, _timeoutComputeVelocity, _lastVelocity, _delta, _maxVelocity, _timerInterval, _copy, _velocity, _velocityVal, _valStack, _averageValStack, _maxAverageValStack, _maxAverageIterations, _valStackMaxLength, _valStackAverage, _timeStamp, _maxTimeDiff, _vaTimeDiff, _velocityTimeDiff, _autoComputeVelocity, _autoComputeVelocityTimeout, _countDiff, _timeDiff, _deltaCountDiff, _deltaTimeDif, _minTimeForReporting, _averageVelocity, _InstrumentVelocity_instances, ComputeVelocityByTimeDiff_fn, ComputeVelocity_fn, SetupAutoComputeVelocity_fn, GetVelocityStackAverage_fn, GetVal_fn, SetVal_fn, GetVelocity_fn, GetMaxVelocity_fn, GetDelta_fn, GetTimeStamp_fn, GetCountDiff_fn, GetTimeDiff_fn, GetDeltaCountDiff_fn, GetDeltaTimeDif_fn, GetAverageVelocity_fn, _histogramData, _val2, _copy2, _InstrumentHistogram_instances, GetVal_fn2, SetVal_fn2, GetHistogramData_fn, SetHistogramData_fn, _messages, _readPos, _maxSize, _copy3, _useLatestMessages, _consoleLogging, _instrumentLogging, _winstonLogging, _stsLogger, _InstrumentLog_instances, DumpToConsole_fn, GetVal_fn3, SetVal_fn3, _start, _copy4, _pauseVal, _InstrumentTimerGauge_instances, GetVal_fn4, SetVal_fn4, _val3, _maxval, _lastObservedValue, _timeSeriesList, _maxSampleSize, _timerInterval2, _observer, _min, _max, _observations, _total, _copy5, _InstrumentGauge_instances, GetVal_fn5, SetVal_fn5, GetMin_fn, GetMax_fn, GetAverage_fn, GetAndResetMaxVal_fn, NumberCompare_fn, GetPercentileData_fn, _val4, _copy6, _InstrumentObject_instances, GetVal_fn6, SetVal_fn6, _tinyEmitter, _RequestCompleted, _agentManager2, _inPublish, _observer2, _publishState, _publisherTransport, _PublishInstruments_instances, PublishTimeoutLoop_fn, UpdateState_fn, _instruments, _publisher, _PublishInstrumentController_instances, GetInstrument_fn, ProcessTelemetryCommand_fn, CreateInstrument_fn, CreateInstruments_fn, _kafkaLog, _maxLogLength, _socketSubscribeKeepAlive, _options3, _agentManager3, _ObservabilityRESTAPISubscriber_instances, LogDebugMessage_fn, LogErrorMessage_fn, InvokeRESTAPI_fn, _GetData, SetupTimeout_fn, AddKeepAlive_fn, RemoveKeepAlive_fn, _messageWithAckPayloadRecords, _socket, _maxReties, _timeoutValue, _options4, _SocketIoMessageSender_instances, LogDebugMessage_fn2, GetSubscribeKeepAliveAckEventName_fn, _socketSubscribeKeepAlive2, _socket2, _options5, _socketIoMessageSender, _ObservabilitySocketIOSubscriber_instances, LogDebugMessage_fn3, LogErrorMessage_fn2, AddKeepAlive_fn2, RemoveKeepAlive_fn2, _observabilitySocketIOSubscriber, _subscriptions, _kafkaHelper, _serviceModel, _agentModel, _lambdaModel, _options6, _ObservabilitySubscriptionManager_instances, LogDebugMessage_fn4, LogErrorMessage_fn3, _options7, _sockets, _agentManager4, _SocketIoClientHelper_instances, LogDebugMessage_fn5, LogErrorMessage_fn4, EstablishSocketConnect_fn, _socketIoServerHelperOptions, _namespace, _SetupStandardEvents, _SetupConnectionMiddleware, _SetupMessageMiddleware;
21
21
  import _cloneDeep from "lodash.clonedeep";
22
22
  import isNode from "detect-node";
23
23
  import { STSOptionsBase } from "@nsshunt/stsutils";
@@ -4923,7 +4923,7 @@ var __privateWrapper2 = (obj, member, setter, getter) => ({
4923
4923
  return __privateGet2(obj, member, getter);
4924
4924
  }
4925
4925
  });
4926
- var _options, _httpAgent, _httpsAgent, _agentResetInterval, _requestCount, _SetupResetInterval, _GetAgentOptions, _url, _method, _headers, _data, _agentManager, _timeout;
4926
+ var _options, _httpAgent, _httpsAgent, _agentResetInterval, _requestCount, _SetupResetInterval, _GetAgentOptions, _url, _method, _headers, _data, _agentManager, _timeout, _withCredentials;
4927
4927
  var ansiStyles$1 = { exports: {} };
4928
4928
  var colorName;
4929
4929
  var hasRequiredColorName;
@@ -6564,10 +6564,12 @@ class AgentManager {
6564
6564
  __privateAdd2(this, _agentResetInterval, null);
6565
6565
  __privateAdd2(this, _requestCount, 0);
6566
6566
  __privateAdd2(this, _SetupResetInterval, () => {
6567
- __privateSet2(this, _agentResetInterval, setTimeout(() => {
6568
- this.ResetAgent();
6569
- __privateGet2(this, _SetupResetInterval).call(this);
6570
- }, __privateGet2(this, _options).agentResetInterval).unref());
6567
+ if (__privateGet2(this, _options).agentResetInterval && __privateGet2(this, _options).agentResetInterval > 0) {
6568
+ __privateSet2(this, _agentResetInterval, setTimeout(() => {
6569
+ this.ResetAgent();
6570
+ __privateGet2(this, _SetupResetInterval).call(this);
6571
+ }, __privateGet2(this, _options).agentResetInterval).unref());
6572
+ }
6571
6573
  });
6572
6574
  __privateAdd2(this, _GetAgentOptions, (https2) => {
6573
6575
  let options;
@@ -6603,6 +6605,22 @@ class AgentManager {
6603
6605
  __privateGet2(this, _SetupResetInterval).call(this);
6604
6606
  }
6605
6607
  }
6608
+ get agentResetInterval() {
6609
+ return __privateGet2(this, _options).agentResetInterval;
6610
+ }
6611
+ set agentResetInterval(val) {
6612
+ if (__privateGet2(this, _agentResetInterval)) {
6613
+ clearTimeout(__privateGet2(this, _agentResetInterval));
6614
+ }
6615
+ __privateGet2(this, _options).agentResetInterval = val;
6616
+ __privateGet2(this, _SetupResetInterval).call(this);
6617
+ }
6618
+ get agentResetCount() {
6619
+ return __privateGet2(this, _options).agentResetCount;
6620
+ }
6621
+ set agentResetCount(val) {
6622
+ __privateGet2(this, _options).agentResetCount = val;
6623
+ }
6606
6624
  IncRequestCount() {
6607
6625
  __privateWrapper2(this, _requestCount)._++;
6608
6626
  if (__privateGet2(this, _options).agentResetCount) {
@@ -6683,18 +6701,55 @@ class STSAxiosConfig {
6683
6701
  __privateAdd2(this, _data);
6684
6702
  __privateAdd2(this, _agentManager);
6685
6703
  __privateAdd2(this, _timeout);
6704
+ __privateAdd2(this, _withCredentials);
6686
6705
  __privateSet2(this, _url, url);
6687
6706
  __privateSet2(this, _method, method);
6688
- __privateSet2(this, _headers, headers);
6707
+ if (headers !== void 0) {
6708
+ __privateSet2(this, _headers, headers);
6709
+ }
6689
6710
  if (timeout !== void 0) {
6690
6711
  __privateSet2(this, _timeout, timeout);
6691
6712
  }
6692
6713
  }
6714
+ withCookies(cookies) {
6715
+ if (!__privateGet2(this, _headers)) {
6716
+ __privateSet2(this, _headers, {});
6717
+ }
6718
+ __privateGet2(this, _headers)["Cookie"] = cookies.join("; ");
6719
+ return this;
6720
+ }
6693
6721
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6694
6722
  withData(data) {
6695
6723
  __privateSet2(this, _data, data);
6696
6724
  return this;
6697
6725
  }
6726
+ // 'Content-Type': 'application/json'
6727
+ withAuthHeaders(accesssToken, stsUserId) {
6728
+ if (!__privateGet2(this, _headers)) {
6729
+ __privateSet2(this, _headers, {});
6730
+ }
6731
+ __privateGet2(this, _headers)["Content-Type"] = "application/json";
6732
+ __privateGet2(this, _headers)["Authorization"] = "Bearer " + accesssToken;
6733
+ if (stsUserId) {
6734
+ __privateGet2(this, _headers)["x-sts_user_id"] = stsUserId;
6735
+ }
6736
+ return this;
6737
+ }
6738
+ withHeaders(headers) {
6739
+ __privateSet2(this, _headers, headers);
6740
+ return this;
6741
+ }
6742
+ withDefaultHeaders() {
6743
+ if (!__privateGet2(this, _headers)) {
6744
+ __privateSet2(this, _headers, {});
6745
+ }
6746
+ __privateGet2(this, _headers)["Content-Type"] = "application/json";
6747
+ return this;
6748
+ }
6749
+ withCredentials() {
6750
+ __privateSet2(this, _withCredentials, true);
6751
+ return this;
6752
+ }
6698
6753
  withTimeout(timeout) {
6699
6754
  __privateSet2(this, _timeout, timeout);
6700
6755
  return this;
@@ -6706,9 +6761,11 @@ class STSAxiosConfig {
6706
6761
  get config() {
6707
6762
  const retVal = {
6708
6763
  url: __privateGet2(this, _url),
6709
- method: __privateGet2(this, _method),
6710
- headers: __privateGet2(this, _headers)
6764
+ method: __privateGet2(this, _method)
6711
6765
  };
6766
+ if (__privateGet2(this, _headers)) {
6767
+ retVal.headers = __privateGet2(this, _headers);
6768
+ }
6712
6769
  if (__privateGet2(this, _agentManager) !== void 0) {
6713
6770
  if (__privateGet2(this, _agentManager).IsHttps(__privateGet2(this, _url))) {
6714
6771
  retVal.httpsAgent = __privateGet2(this, _agentManager).GetAgent(__privateGet2(this, _url));
@@ -6722,6 +6779,9 @@ class STSAxiosConfig {
6722
6779
  if (__privateGet2(this, _timeout) !== void 0) {
6723
6780
  retVal.timeout = __privateGet2(this, _timeout);
6724
6781
  }
6782
+ if (__privateGet2(this, _withCredentials) !== void 0 && __privateGet2(this, _withCredentials) === true) {
6783
+ retVal.withCredentials = true;
6784
+ }
6725
6785
  return retVal;
6726
6786
  }
6727
6787
  }
@@ -6731,6 +6791,7 @@ _headers = /* @__PURE__ */ new WeakMap();
6731
6791
  _data = /* @__PURE__ */ new WeakMap();
6732
6792
  _agentManager = /* @__PURE__ */ new WeakMap();
6733
6793
  _timeout = /* @__PURE__ */ new WeakMap();
6794
+ _withCredentials = /* @__PURE__ */ new WeakMap();
6734
6795
  class PublishTransportRESTServer extends STSOptionsBase {
6735
6796
  constructor(options) {
6736
6797
  super(options);
@@ -6748,15 +6809,17 @@ class PublishTransportRESTServer extends STSOptionsBase {
6748
6809
  if (this.options.socketPath) {
6749
6810
  retVal = await axios({
6750
6811
  method: "post",
6751
- //data: payload,
6752
6812
  data: Buffer.from(encodedData),
6753
6813
  headers,
6754
- //httpsAgent: this.#httpsAgent,
6755
6814
  socketPath: this.options.socketPath
6756
6815
  });
6757
6816
  } else {
6758
- if (isNode && __privateGet(this, _agentManager2)) {
6759
- retVal = await axios(new STSAxiosConfig(this.options.url, "post", headers).withData(Buffer.from(encodedData)).withAgentManager(__privateGet(this, _agentManager2)).config);
6817
+ if (isNode) {
6818
+ if (__privateGet(this, _agentManager2)) {
6819
+ retVal = await axios(new STSAxiosConfig(this.options.url, "post", headers).withData(Buffer.from(encodedData)).withAgentManager(__privateGet(this, _agentManager2)).config);
6820
+ } else {
6821
+ retVal = await axios(new STSAxiosConfig(this.options.url, "post", headers).withData(Buffer.from(encodedData)).config);
6822
+ }
6760
6823
  } else {
6761
6824
  const blob = new Blob([encodedData], { type: "application/octet-stream" });
6762
6825
  retVal = await axios(new STSAxiosConfig(this.options.url, "post", headers).withData(blob).config);
@@ -7666,6 +7729,7 @@ class ObservabilityRESTAPISubscriber {
7666
7729
  __privateAdd(this, _options3);
7667
7730
  // This is required becuase each call to .bind create a new replica bound function - so we need the same instance for on/off event bindings.
7668
7731
  __publicField(this, "KeepAliveAckBoundFunction");
7732
+ __privateAdd(this, _agentManager3, null);
7669
7733
  __privateAdd(this, _GetData, async (subscription) => {
7670
7734
  try {
7671
7735
  const retVal = await __privateMethod(this, _ObservabilityRESTAPISubscriber_instances, InvokeRESTAPI_fn).call(this, subscription);
@@ -7682,6 +7746,9 @@ class ObservabilityRESTAPISubscriber {
7682
7746
  }
7683
7747
  });
7684
7748
  __privateSet(this, _options3, options);
7749
+ if (isNode && options.useAgentManager && options.useAgentManager === true) {
7750
+ __privateSet(this, _agentManager3, new AgentManager({}));
7751
+ }
7685
7752
  }
7686
7753
  SubscribeOne(subscription) {
7687
7754
  this.Subscribe([subscription]);
@@ -7710,6 +7777,7 @@ class ObservabilityRESTAPISubscriber {
7710
7777
  }
7711
7778
  _socketSubscribeKeepAlive = new WeakMap();
7712
7779
  _options3 = new WeakMap();
7780
+ _agentManager3 = new WeakMap();
7713
7781
  _ObservabilityRESTAPISubscriber_instances = new WeakSet();
7714
7782
  LogDebugMessage_fn = function(message) {
7715
7783
  __privateGet(this, _options3).logger.debug(message);
@@ -7786,25 +7854,13 @@ InvokeRESTAPI_fn = async function(subscription) {
7786
7854
  }
7787
7855
  if (url.localeCompare("") !== 0) {
7788
7856
  const endPointUrl = `${__privateGet(this, _options3).urlBase}${url}`;
7789
- const headers = {
7790
- "Content-Type": "application/json"
7791
- };
7792
7857
  let retVal;
7793
7858
  const start = performance.now();
7794
7859
  try {
7795
- if (isNode && __privateGet(this, _options3).agent) {
7796
- retVal = await axios({
7797
- url: endPointUrl,
7798
- method: "get",
7799
- headers,
7800
- httpsAgent: __privateGet(this, _options3).agent
7801
- });
7860
+ if (isNode && __privateGet(this, _agentManager3)) {
7861
+ retVal = await axios(new STSAxiosConfig(endPointUrl, "get").withDefaultHeaders().withAgentManager(__privateGet(this, _agentManager3)).config);
7802
7862
  } else {
7803
- retVal = await axios({
7804
- url: endPointUrl,
7805
- method: "get",
7806
- headers
7807
- });
7863
+ retVal = await axios(new STSAxiosConfig(endPointUrl, "get").withDefaultHeaders().config);
7808
7864
  }
7809
7865
  const end = performance.now();
7810
7866
  const diff = end - start;
@@ -8670,10 +8726,10 @@ class SocketIoClientHelper {
8670
8726
  __privateAdd(this, _SocketIoClientHelper_instances);
8671
8727
  __privateAdd(this, _options7);
8672
8728
  __privateAdd(this, _sockets, {});
8673
- __privateAdd(this, _agentManager3, null);
8729
+ __privateAdd(this, _agentManager4, null);
8674
8730
  __privateSet(this, _options7, options);
8675
8731
  if (isNode) {
8676
- __privateSet(this, _agentManager3, new AgentManager({
8732
+ __privateSet(this, _agentManager4, new AgentManager({
8677
8733
  agentOptions: __privateGet(this, _options7).agentOptions
8678
8734
  }));
8679
8735
  }
@@ -8700,7 +8756,7 @@ class SocketIoClientHelper {
8700
8756
  }
8701
8757
  _options7 = new WeakMap();
8702
8758
  _sockets = new WeakMap();
8703
- _agentManager3 = new WeakMap();
8759
+ _agentManager4 = new WeakMap();
8704
8760
  _SocketIoClientHelper_instances = new WeakSet();
8705
8761
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8706
8762
  LogDebugMessage_fn5 = function(message) {
@@ -8730,7 +8786,7 @@ EstablishSocketConnect_fn = function(name2, onConnectCallBack, socketEventsCallB
8730
8786
  socketOptions = {
8731
8787
  transports: ["websocket"],
8732
8788
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8733
- agent: (_a2 = __privateGet(this, _agentManager3)) == null ? void 0 : _a2.GetAgent(socketDetail.address)
8789
+ agent: (_a2 = __privateGet(this, _agentManager4)) == null ? void 0 : _a2.GetAgent(socketDetail.address)
8734
8790
  };
8735
8791
  } else {
8736
8792
  socketOptions = {