@nsshunt/stsutils 1.19.7 → 1.19.10

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.
@@ -11,8 +11,16 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
11
11
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
12
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
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
+ });
14
22
 
15
- var _options;
23
+ var _options, _url, _method, _headers, _data, _agentManager, _timeout, _withCredentials, _options2, _agentResetInterval, _requestCount, _httpAgent, _httpsAgent, _SetupResetInterval, _GetAgentOptions;
16
24
  function getDefaultExportFromCjs(x) {
17
25
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
18
26
  }
@@ -1628,7 +1636,227 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1628
1636
  }
1629
1637
  return errors;
1630
1638
  }
1639
+ class STSAxiosConfig {
1640
+ constructor(url, method, headers, timeout) {
1641
+ __privateAdd(this, _url);
1642
+ __privateAdd(this, _method);
1643
+ __privateAdd(this, _headers);
1644
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1645
+ __privateAdd(this, _data);
1646
+ __privateAdd(this, _agentManager);
1647
+ __privateAdd(this, _timeout);
1648
+ __privateAdd(this, _withCredentials);
1649
+ __privateSet(this, _url, url);
1650
+ __privateSet(this, _method, method);
1651
+ if (headers !== void 0) {
1652
+ __privateSet(this, _headers, headers);
1653
+ }
1654
+ if (timeout !== void 0) {
1655
+ __privateSet(this, _timeout, timeout);
1656
+ }
1657
+ }
1658
+ withCookies(cookies) {
1659
+ if (!__privateGet(this, _headers)) {
1660
+ __privateSet(this, _headers, {});
1661
+ }
1662
+ __privateGet(this, _headers)["Cookie"] = cookies.join("; ");
1663
+ return this;
1664
+ }
1665
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1666
+ withData(data) {
1667
+ __privateSet(this, _data, data);
1668
+ return this;
1669
+ }
1670
+ // 'Content-Type': 'application/json'
1671
+ withAuthHeaders(accesssToken, stsUserId) {
1672
+ if (!__privateGet(this, _headers)) {
1673
+ __privateSet(this, _headers, {});
1674
+ }
1675
+ __privateGet(this, _headers)["Content-Type"] = "application/json";
1676
+ __privateGet(this, _headers)["Authorization"] = "Bearer " + accesssToken;
1677
+ if (stsUserId) {
1678
+ __privateGet(this, _headers)["x-sts_user_id"] = stsUserId;
1679
+ }
1680
+ return this;
1681
+ }
1682
+ withHeaders(headers) {
1683
+ __privateSet(this, _headers, headers);
1684
+ return this;
1685
+ }
1686
+ withDefaultHeaders() {
1687
+ if (!__privateGet(this, _headers)) {
1688
+ __privateSet(this, _headers, {});
1689
+ }
1690
+ __privateGet(this, _headers)["Content-Type"] = "application/json";
1691
+ return this;
1692
+ }
1693
+ withCredentials() {
1694
+ __privateSet(this, _withCredentials, true);
1695
+ return this;
1696
+ }
1697
+ withTimeout(timeout) {
1698
+ __privateSet(this, _timeout, timeout);
1699
+ return this;
1700
+ }
1701
+ withAgentManager(agentManager) {
1702
+ __privateSet(this, _agentManager, agentManager);
1703
+ return this;
1704
+ }
1705
+ get config() {
1706
+ const retVal = {
1707
+ url: __privateGet(this, _url),
1708
+ method: __privateGet(this, _method)
1709
+ };
1710
+ if (__privateGet(this, _headers)) {
1711
+ retVal.headers = __privateGet(this, _headers);
1712
+ }
1713
+ if (__privateGet(this, _agentManager) !== void 0) {
1714
+ if (__privateGet(this, _agentManager).IsHttps(__privateGet(this, _url))) {
1715
+ retVal.httpsAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
1716
+ } else {
1717
+ retVal.httpAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
1718
+ }
1719
+ }
1720
+ if (__privateGet(this, _data) !== void 0) {
1721
+ retVal.data = __privateGet(this, _data);
1722
+ }
1723
+ if (__privateGet(this, _timeout) !== void 0) {
1724
+ retVal.timeout = __privateGet(this, _timeout);
1725
+ }
1726
+ if (__privateGet(this, _withCredentials) !== void 0 && __privateGet(this, _withCredentials) === true) {
1727
+ retVal.withCredentials = true;
1728
+ }
1729
+ return retVal;
1730
+ }
1731
+ }
1732
+ _url = new WeakMap();
1733
+ _method = new WeakMap();
1734
+ _headers = new WeakMap();
1735
+ _data = new WeakMap();
1736
+ _agentManager = new WeakMap();
1737
+ _timeout = new WeakMap();
1738
+ _withCredentials = new WeakMap();
1739
+ class AgentManager {
1740
+ constructor(agentManagerOptions) {
1741
+ __privateAdd(this, _options2);
1742
+ __privateAdd(this, _agentResetInterval, null);
1743
+ __privateAdd(this, _requestCount, 0);
1744
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1745
+ __privateAdd(this, _httpAgent);
1746
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1747
+ __privateAdd(this, _httpsAgent);
1748
+ __privateAdd(this, _SetupResetInterval, () => {
1749
+ if (__privateGet(this, _options2).agentResetInterval && __privateGet(this, _options2).agentResetInterval > 0) {
1750
+ __privateSet(this, _agentResetInterval, setTimeout(() => {
1751
+ this.ResetAgent();
1752
+ __privateGet(this, _SetupResetInterval).call(this);
1753
+ }, __privateGet(this, _options2).agentResetInterval).unref());
1754
+ }
1755
+ });
1756
+ __privateAdd(this, _GetAgentOptions, (https) => {
1757
+ let options;
1758
+ if (__privateGet(this, _options2).agentOptions) {
1759
+ options = {
1760
+ keepAlive: __privateGet(this, _options2).agentOptions.keepAlive,
1761
+ maxSockets: __privateGet(this, _options2).agentOptions.maxSockets,
1762
+ maxTotalSockets: __privateGet(this, _options2).agentOptions.maxTotalSockets,
1763
+ maxFreeSockets: __privateGet(this, _options2).agentOptions.maxFreeSockets,
1764
+ timeout: __privateGet(this, _options2).agentOptions.timeout
1765
+ };
1766
+ if (https === true) {
1767
+ options.rejectUnauthorized = __privateGet(this, _options2).agentOptions.rejectUnauthorized;
1768
+ }
1769
+ } else {
1770
+ options = {
1771
+ keepAlive: true,
1772
+ maxSockets: 10,
1773
+ maxTotalSockets: 20,
1774
+ maxFreeSockets: 256,
1775
+ timeout: 3e4,
1776
+ rejectUnauthorized: false
1777
+ };
1778
+ }
1779
+ return options;
1780
+ });
1781
+ __privateSet(this, _options2, agentManagerOptions);
1782
+ if (__privateGet(this, _options2).agentResetInterval) {
1783
+ __privateGet(this, _SetupResetInterval).call(this);
1784
+ }
1785
+ }
1786
+ get agentResetInterval() {
1787
+ return __privateGet(this, _options2).agentResetInterval;
1788
+ }
1789
+ set agentResetInterval(val) {
1790
+ if (__privateGet(this, _agentResetInterval)) {
1791
+ clearTimeout(__privateGet(this, _agentResetInterval));
1792
+ }
1793
+ __privateGet(this, _options2).agentResetInterval = val;
1794
+ __privateGet(this, _SetupResetInterval).call(this);
1795
+ }
1796
+ get agentResetCount() {
1797
+ return __privateGet(this, _options2).agentResetCount;
1798
+ }
1799
+ set agentResetCount(val) {
1800
+ __privateGet(this, _options2).agentResetCount = val;
1801
+ }
1802
+ IncRequestCount() {
1803
+ __privateWrapper(this, _requestCount)._++;
1804
+ if (__privateGet(this, _options2).agentResetCount) {
1805
+ if (__privateGet(this, _requestCount) % __privateGet(this, _options2).agentResetCount === 0) {
1806
+ this.ResetAgent();
1807
+ }
1808
+ }
1809
+ }
1810
+ IsHttps(protocol) {
1811
+ if (protocol.toLowerCase().startsWith("https:")) {
1812
+ return true;
1813
+ }
1814
+ return false;
1815
+ }
1816
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1817
+ GetAgent(protocol) {
1818
+ if (protocol.toLowerCase().startsWith("https:")) {
1819
+ if (!__privateGet(this, _httpsAgent)) {
1820
+ __privateSet(this, _httpsAgent, __privateGet(this, _options2).httpsAgentFactory(__privateGet(this, _GetAgentOptions).call(this, true)));
1821
+ }
1822
+ return __privateGet(this, _httpsAgent);
1823
+ } else if (protocol.toLowerCase().startsWith("http:")) {
1824
+ if (!__privateGet(this, _httpAgent)) {
1825
+ __privateSet(this, _httpAgent, __privateGet(this, _options2).httpAgentFactory(__privateGet(this, _GetAgentOptions).call(this, false)));
1826
+ }
1827
+ return __privateGet(this, _httpAgent);
1828
+ } else {
1829
+ return null;
1830
+ }
1831
+ }
1832
+ ResetAgent() {
1833
+ __privateSet(this, _httpAgent, null);
1834
+ __privateSet(this, _httpsAgent, null);
1835
+ }
1836
+ Terminate() {
1837
+ if (__privateGet(this, _agentResetInterval)) {
1838
+ clearTimeout(__privateGet(this, _agentResetInterval));
1839
+ __privateSet(this, _agentResetInterval, null);
1840
+ }
1841
+ if (__privateGet(this, _httpAgent)) {
1842
+ __privateGet(this, _httpAgent).destroy();
1843
+ __privateSet(this, _httpAgent, null);
1844
+ }
1845
+ if (__privateGet(this, _httpsAgent)) {
1846
+ __privateGet(this, _httpsAgent).destroy();
1847
+ __privateSet(this, _httpsAgent, null);
1848
+ }
1849
+ }
1850
+ }
1851
+ _options2 = new WeakMap();
1852
+ _agentResetInterval = new WeakMap();
1853
+ _requestCount = new WeakMap();
1854
+ _httpAgent = new WeakMap();
1855
+ _httpsAgent = new WeakMap();
1856
+ _SetupResetInterval = new WeakMap();
1857
+ _GetAgentOptions = new WeakMap();
1631
1858
  exports2.AddSchema = AddSchema;
1859
+ exports2.AgentManager = AgentManager;
1632
1860
  exports2.CheckValidChar = CheckValidChar;
1633
1861
  exports2.GetErrorPayload = GetErrorPayload;
1634
1862
  exports2.JestSleep = JestSleep;
@@ -1637,6 +1865,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1637
1865
  exports2.OAuth2ParameterType = OAuth2ParameterType;
1638
1866
  exports2.OIDCAddressClaim = OIDCAddressClaim;
1639
1867
  exports2.OIDCStandardClaim = OIDCStandardClaim;
1868
+ exports2.STSAxiosConfig = STSAxiosConfig;
1640
1869
  exports2.STSOptionsBase = STSOptionsBase;
1641
1870
  exports2.Sleep = Sleep;
1642
1871
  exports2.Validate = Validate;