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