@nsshunt/stsutils 1.19.39 → 1.19.41

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.
@@ -1,26 +1,7 @@
1
1
  (function(global, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("ajv/dist/jtd.js")) : typeof define === "function" && define.amd ? define(["exports", "ajv/dist/jtd.js"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nsshunt/stsutils"] = {}, global.Ajv));
3
3
  })(this, function(exports2, Ajv) {
4
- "use strict";var __defProp = Object.defineProperty;
5
- var __typeError = (msg) => {
6
- throw TypeError(msg);
7
- };
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
11
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
12
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
14
- var __privateWrapper = (obj, member, setter, getter) => ({
15
- set _(value) {
16
- __privateSet(obj, member, value, setter);
17
- },
18
- get _() {
19
- return __privateGet(obj, member, getter);
20
- }
21
- });
22
-
23
- var _options, _url, _method, _headers, _data, _agentManager, _timeout, _withCredentials, _options2, _agentResetInterval, _requestCount, _httpAgent, _httpsAgent, _SetupResetInterval, _GetAgentOptions;
4
+ "use strict";
24
5
  function getDefaultExportFromCjs(x) {
25
6
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
26
7
  }
@@ -1556,9 +1537,9 @@ var __privateWrapper = (obj, member, setter, getter) => ({
1556
1537
  }
1557
1538
  }
1558
1539
  class STSOptionsBase {
1540
+ #options;
1559
1541
  constructor(options = null) {
1560
- __privateAdd(this, _options);
1561
- __privateSet(this, _options, options);
1542
+ this.#options = options;
1562
1543
  if (options !== null) {
1563
1544
  if (typeof options.validator === "undefined") ;
1564
1545
  else {
@@ -1567,10 +1548,9 @@ var __privateWrapper = (obj, member, setter, getter) => ({
1567
1548
  }
1568
1549
  }
1569
1550
  get options() {
1570
- return __privateGet(this, _options);
1551
+ return this.#options;
1571
1552
  }
1572
1553
  }
1573
- _options = new WeakMap();
1574
1554
  async function Sleep(milliseconds = 1e3) {
1575
1555
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
1576
1556
  }
@@ -1636,23 +1616,23 @@ var __privateWrapper = (obj, member, setter, getter) => ({
1636
1616
  return OIDCAddressClaim2;
1637
1617
  })(OIDCAddressClaim || {});
1638
1618
  class OAuth2ParameterErrorType {
1619
+ static NOT_EQUAL = {
1620
+ code: "STS_OAUTH2_ERR_0001",
1621
+ description: "Parameter values not equal."
1622
+ };
1623
+ static NOT_PRESENT = {
1624
+ code: "STS_OAUTH2_ERR_0002",
1625
+ description: "Parameter not provided."
1626
+ };
1627
+ static INVALID_FORMAT = {
1628
+ code: "STS_OAUTH2_ERR_0003",
1629
+ description: "Parameter value format invalid."
1630
+ };
1631
+ static EXPIRED = {
1632
+ code: "STS_OAUTH2_ERR_0004",
1633
+ description: "Parameter value expired."
1634
+ };
1639
1635
  }
1640
- __publicField(OAuth2ParameterErrorType, "NOT_EQUAL", {
1641
- code: "STS_OAUTH2_ERR_0001",
1642
- description: "Parameter values not equal."
1643
- });
1644
- __publicField(OAuth2ParameterErrorType, "NOT_PRESENT", {
1645
- code: "STS_OAUTH2_ERR_0002",
1646
- description: "Parameter not provided."
1647
- });
1648
- __publicField(OAuth2ParameterErrorType, "INVALID_FORMAT", {
1649
- code: "STS_OAUTH2_ERR_0003",
1650
- description: "Parameter value format invalid."
1651
- });
1652
- __publicField(OAuth2ParameterErrorType, "EXPIRED", {
1653
- code: "STS_OAUTH2_ERR_0004",
1654
- description: "Parameter value expired."
1655
- });
1656
1636
  function compareParameterTypes(source1, source2, authParameterTypes) {
1657
1637
  const errors = [];
1658
1638
  for (let i = 0; i < authParameterTypes.length; i++) {
@@ -1670,172 +1650,140 @@ var __privateWrapper = (obj, member, setter, getter) => ({
1670
1650
  return errors;
1671
1651
  }
1672
1652
  class STSAxiosConfig {
1653
+ #url;
1654
+ #method;
1655
+ #headers;
1656
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1657
+ #data;
1658
+ #agentManager;
1659
+ #timeout;
1660
+ #withCredentials;
1673
1661
  constructor(url, method, headers, timeout) {
1674
- __privateAdd(this, _url);
1675
- __privateAdd(this, _method);
1676
- __privateAdd(this, _headers);
1677
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1678
- __privateAdd(this, _data);
1679
- __privateAdd(this, _agentManager);
1680
- __privateAdd(this, _timeout);
1681
- __privateAdd(this, _withCredentials);
1682
- __privateSet(this, _url, url);
1683
- __privateSet(this, _method, method);
1662
+ this.#url = url;
1663
+ this.#method = method;
1684
1664
  if (headers !== void 0) {
1685
- __privateSet(this, _headers, headers);
1665
+ this.#headers = headers;
1686
1666
  }
1687
1667
  if (timeout !== void 0) {
1688
- __privateSet(this, _timeout, timeout);
1668
+ this.#timeout = timeout;
1689
1669
  }
1690
1670
  }
1691
1671
  withCookies(cookies) {
1692
- if (!__privateGet(this, _headers)) {
1693
- __privateSet(this, _headers, {});
1672
+ if (!this.#headers) {
1673
+ this.#headers = {};
1694
1674
  }
1695
- __privateGet(this, _headers)["Cookie"] = cookies.join("; ");
1675
+ this.#headers["Cookie"] = cookies.join("; ");
1696
1676
  return this;
1697
1677
  }
1698
1678
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1699
1679
  withData(data) {
1700
- __privateSet(this, _data, data);
1680
+ this.#data = data;
1701
1681
  return this;
1702
1682
  }
1703
1683
  // 'Content-Type': 'application/json'
1704
1684
  withAuthHeaders(accesssToken, stsUserId) {
1705
- if (!__privateGet(this, _headers)) {
1706
- __privateSet(this, _headers, {});
1685
+ if (!this.#headers) {
1686
+ this.#headers = {};
1707
1687
  }
1708
- __privateGet(this, _headers)["Content-Type"] = "application/json";
1709
- __privateGet(this, _headers)["Authorization"] = "Bearer " + accesssToken;
1688
+ this.#headers["Content-Type"] = "application/json";
1689
+ this.#headers["Authorization"] = "Bearer " + accesssToken;
1710
1690
  if (stsUserId) {
1711
- __privateGet(this, _headers)["x-sts_user_id"] = stsUserId;
1691
+ this.#headers["x-sts_user_id"] = stsUserId;
1712
1692
  }
1713
1693
  return this;
1714
1694
  }
1715
1695
  withHeaders(headers) {
1716
- __privateSet(this, _headers, headers);
1696
+ this.#headers = headers;
1717
1697
  return this;
1718
1698
  }
1719
1699
  withDefaultHeaders() {
1720
- if (!__privateGet(this, _headers)) {
1721
- __privateSet(this, _headers, {});
1700
+ if (!this.#headers) {
1701
+ this.#headers = {};
1722
1702
  }
1723
- __privateGet(this, _headers)["Content-Type"] = "application/json";
1703
+ this.#headers["Content-Type"] = "application/json";
1724
1704
  return this;
1725
1705
  }
1726
1706
  withCredentials() {
1727
- __privateSet(this, _withCredentials, true);
1707
+ this.#withCredentials = true;
1728
1708
  return this;
1729
1709
  }
1730
1710
  withTimeout(timeout) {
1731
- __privateSet(this, _timeout, timeout);
1711
+ this.#timeout = timeout;
1732
1712
  return this;
1733
1713
  }
1734
1714
  withAgentManager(agentManager) {
1735
- __privateSet(this, _agentManager, agentManager);
1715
+ this.#agentManager = agentManager;
1736
1716
  return this;
1737
1717
  }
1738
1718
  get config() {
1739
1719
  const retVal = {
1740
- url: __privateGet(this, _url),
1741
- method: __privateGet(this, _method)
1720
+ url: this.#url,
1721
+ method: this.#method
1742
1722
  };
1743
- if (__privateGet(this, _headers)) {
1744
- retVal.headers = __privateGet(this, _headers);
1723
+ if (this.#headers) {
1724
+ retVal.headers = this.#headers;
1745
1725
  }
1746
- if (__privateGet(this, _agentManager) !== void 0) {
1747
- if (__privateGet(this, _agentManager).IsHttps(__privateGet(this, _url))) {
1748
- retVal.httpsAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
1726
+ if (this.#agentManager !== void 0) {
1727
+ if (this.#agentManager.IsHttps(this.#url)) {
1728
+ retVal.httpsAgent = this.#agentManager.GetAgent(this.#url);
1749
1729
  } else {
1750
- retVal.httpAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
1730
+ retVal.httpAgent = this.#agentManager.GetAgent(this.#url);
1751
1731
  }
1752
1732
  }
1753
- if (__privateGet(this, _data) !== void 0) {
1754
- retVal.data = __privateGet(this, _data);
1733
+ if (this.#data !== void 0) {
1734
+ retVal.data = this.#data;
1755
1735
  }
1756
- if (__privateGet(this, _timeout) !== void 0) {
1757
- retVal.timeout = __privateGet(this, _timeout);
1736
+ if (this.#timeout !== void 0) {
1737
+ retVal.timeout = this.#timeout;
1758
1738
  }
1759
- if (__privateGet(this, _withCredentials) !== void 0 && __privateGet(this, _withCredentials) === true) {
1739
+ if (this.#withCredentials !== void 0 && this.#withCredentials === true) {
1760
1740
  retVal.withCredentials = true;
1761
1741
  }
1762
1742
  return retVal;
1763
1743
  }
1764
1744
  }
1765
- _url = new WeakMap();
1766
- _method = new WeakMap();
1767
- _headers = new WeakMap();
1768
- _data = new WeakMap();
1769
- _agentManager = new WeakMap();
1770
- _timeout = new WeakMap();
1771
- _withCredentials = new WeakMap();
1772
1745
  class AgentManager {
1746
+ #options;
1747
+ #agentResetInterval = null;
1748
+ #requestCount = 0;
1749
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1750
+ #httpAgent = void 0;
1751
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1752
+ #httpsAgent = void 0;
1773
1753
  constructor(agentManagerOptions) {
1774
- __privateAdd(this, _options2);
1775
- __privateAdd(this, _agentResetInterval, null);
1776
- __privateAdd(this, _requestCount, 0);
1777
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1778
- __privateAdd(this, _httpAgent);
1779
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1780
- __privateAdd(this, _httpsAgent);
1781
- __privateAdd(this, _SetupResetInterval, () => {
1782
- if (__privateGet(this, _options2).agentResetInterval && __privateGet(this, _options2).agentResetInterval > 0) {
1783
- __privateSet(this, _agentResetInterval, setTimeout(() => {
1784
- this.ResetAgent();
1785
- __privateGet(this, _SetupResetInterval).call(this);
1786
- }, __privateGet(this, _options2).agentResetInterval).unref());
1787
- }
1788
- });
1789
- __privateAdd(this, _GetAgentOptions, (https) => {
1790
- let options;
1791
- if (__privateGet(this, _options2).agentOptions) {
1792
- options = {
1793
- keepAlive: __privateGet(this, _options2).agentOptions.keepAlive,
1794
- maxSockets: __privateGet(this, _options2).agentOptions.maxSockets,
1795
- maxTotalSockets: __privateGet(this, _options2).agentOptions.maxTotalSockets,
1796
- maxFreeSockets: __privateGet(this, _options2).agentOptions.maxFreeSockets,
1797
- timeout: __privateGet(this, _options2).agentOptions.timeout
1798
- };
1799
- if (https === true) {
1800
- options.rejectUnauthorized = __privateGet(this, _options2).agentOptions.rejectUnauthorized;
1801
- }
1802
- } else {
1803
- options = {
1804
- keepAlive: true,
1805
- maxSockets: 10,
1806
- maxTotalSockets: 20,
1807
- maxFreeSockets: 256,
1808
- timeout: 3e4,
1809
- rejectUnauthorized: false
1810
- };
1811
- }
1812
- return options;
1813
- });
1814
- __privateSet(this, _options2, agentManagerOptions);
1815
- if (__privateGet(this, _options2).agentResetInterval) {
1816
- __privateGet(this, _SetupResetInterval).call(this);
1754
+ this.#options = agentManagerOptions;
1755
+ if (this.#options.agentResetInterval) {
1756
+ this.#SetupResetInterval();
1817
1757
  }
1818
1758
  }
1819
1759
  get agentResetInterval() {
1820
- return __privateGet(this, _options2).agentResetInterval;
1760
+ return this.#options.agentResetInterval;
1821
1761
  }
1822
1762
  set agentResetInterval(val) {
1823
- if (__privateGet(this, _agentResetInterval)) {
1824
- clearTimeout(__privateGet(this, _agentResetInterval));
1763
+ if (this.#agentResetInterval) {
1764
+ clearTimeout(this.#agentResetInterval);
1825
1765
  }
1826
- __privateGet(this, _options2).agentResetInterval = val;
1827
- __privateGet(this, _SetupResetInterval).call(this);
1766
+ this.#options.agentResetInterval = val;
1767
+ this.#SetupResetInterval();
1828
1768
  }
1829
1769
  get agentResetCount() {
1830
- return __privateGet(this, _options2).agentResetCount;
1770
+ return this.#options.agentResetCount;
1831
1771
  }
1832
1772
  set agentResetCount(val) {
1833
- __privateGet(this, _options2).agentResetCount = val;
1773
+ this.#options.agentResetCount = val;
1834
1774
  }
1775
+ #SetupResetInterval = () => {
1776
+ if (this.#options.agentResetInterval && this.#options.agentResetInterval > 0) {
1777
+ this.#agentResetInterval = setTimeout(() => {
1778
+ this.ResetAgent();
1779
+ this.#SetupResetInterval();
1780
+ }, this.#options.agentResetInterval).unref();
1781
+ }
1782
+ };
1835
1783
  IncRequestCount() {
1836
- __privateWrapper(this, _requestCount)._++;
1837
- if (__privateGet(this, _options2).agentResetCount) {
1838
- if (__privateGet(this, _requestCount) % __privateGet(this, _options2).agentResetCount === 0) {
1784
+ this.#requestCount++;
1785
+ if (this.#options.agentResetCount) {
1786
+ if (this.#requestCount % this.#options.agentResetCount === 0) {
1839
1787
  this.ResetAgent();
1840
1788
  }
1841
1789
  }
@@ -1846,48 +1794,66 @@ var __privateWrapper = (obj, member, setter, getter) => ({
1846
1794
  }
1847
1795
  return false;
1848
1796
  }
1797
+ #GetAgentOptions = (https) => {
1798
+ let options;
1799
+ if (this.#options.agentOptions) {
1800
+ options = {
1801
+ keepAlive: this.#options.agentOptions.keepAlive,
1802
+ maxSockets: this.#options.agentOptions.maxSockets,
1803
+ maxTotalSockets: this.#options.agentOptions.maxTotalSockets,
1804
+ maxFreeSockets: this.#options.agentOptions.maxFreeSockets,
1805
+ timeout: this.#options.agentOptions.timeout
1806
+ };
1807
+ if (https === true) {
1808
+ options.rejectUnauthorized = this.#options.agentOptions.rejectUnauthorized;
1809
+ }
1810
+ } else {
1811
+ options = {
1812
+ keepAlive: true,
1813
+ maxSockets: 10,
1814
+ maxTotalSockets: 20,
1815
+ maxFreeSockets: 256,
1816
+ timeout: 3e4,
1817
+ rejectUnauthorized: false
1818
+ };
1819
+ }
1820
+ return options;
1821
+ };
1849
1822
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1850
1823
  GetAgent(protocol) {
1851
1824
  if (protocol.toLowerCase().startsWith("https:")) {
1852
- if (!__privateGet(this, _httpsAgent)) {
1853
- __privateSet(this, _httpsAgent, __privateGet(this, _options2).httpsAgentFactory(__privateGet(this, _GetAgentOptions).call(this, true)));
1825
+ if (!this.#httpsAgent) {
1826
+ this.#httpsAgent = this.#options.httpsAgentFactory(this.#GetAgentOptions(true));
1854
1827
  }
1855
- return __privateGet(this, _httpsAgent);
1828
+ return this.#httpsAgent;
1856
1829
  } else if (protocol.toLowerCase().startsWith("http:")) {
1857
- if (!__privateGet(this, _httpAgent)) {
1858
- __privateSet(this, _httpAgent, __privateGet(this, _options2).httpAgentFactory(__privateGet(this, _GetAgentOptions).call(this, false)));
1830
+ if (!this.#httpAgent) {
1831
+ this.#httpAgent = this.#options.httpAgentFactory(this.#GetAgentOptions(false));
1859
1832
  }
1860
- return __privateGet(this, _httpAgent);
1833
+ return this.#httpAgent;
1861
1834
  } else {
1862
1835
  return null;
1863
1836
  }
1864
1837
  }
1865
1838
  ResetAgent() {
1866
- __privateSet(this, _httpAgent, null);
1867
- __privateSet(this, _httpsAgent, null);
1839
+ this.#httpAgent = null;
1840
+ this.#httpsAgent = null;
1868
1841
  }
1869
1842
  Terminate() {
1870
- if (__privateGet(this, _agentResetInterval)) {
1871
- clearTimeout(__privateGet(this, _agentResetInterval));
1872
- __privateSet(this, _agentResetInterval, null);
1843
+ if (this.#agentResetInterval) {
1844
+ clearTimeout(this.#agentResetInterval);
1845
+ this.#agentResetInterval = null;
1873
1846
  }
1874
- if (__privateGet(this, _httpAgent)) {
1875
- __privateGet(this, _httpAgent).destroy();
1876
- __privateSet(this, _httpAgent, null);
1847
+ if (this.#httpAgent) {
1848
+ this.#httpAgent.destroy();
1849
+ this.#httpAgent = null;
1877
1850
  }
1878
- if (__privateGet(this, _httpsAgent)) {
1879
- __privateGet(this, _httpsAgent).destroy();
1880
- __privateSet(this, _httpsAgent, null);
1851
+ if (this.#httpsAgent) {
1852
+ this.#httpsAgent.destroy();
1853
+ this.#httpsAgent = null;
1881
1854
  }
1882
1855
  }
1883
1856
  }
1884
- _options2 = new WeakMap();
1885
- _agentResetInterval = new WeakMap();
1886
- _requestCount = new WeakMap();
1887
- _httpAgent = new WeakMap();
1888
- _httpsAgent = new WeakMap();
1889
- _SetupResetInterval = new WeakMap();
1890
- _GetAgentOptions = new WeakMap();
1891
1857
  exports2.AddSchema = AddSchema;
1892
1858
  exports2.AgentManager = AgentManager;
1893
1859
  exports2.CheckValidChar = CheckValidChar;