@nsshunt/stsconfig 1.25.156 → 1.25.158
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/stsconfig.mjs +184 -0
- package/dist/stsconfig.mjs.map +1 -1
- package/dist/stsconfig.umd.js +185 -3
- package/dist/stsconfig.umd.js.map +1 -1
- package/package.json +1 -1
- package/types/agentManager.d.ts +1 -0
- package/types/agentManager.d.ts.map +1 -1
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/stsAxiosConfig.d.ts +10 -0
- package/types/stsAxiosConfig.d.ts.map +1 -0
package/dist/stsconfig.mjs
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
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);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
9
|
+
set _(value) {
|
|
10
|
+
__privateSet(obj, member, value, setter);
|
|
11
|
+
},
|
|
12
|
+
get _() {
|
|
13
|
+
return __privateGet(obj, member, getter);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
var _options, _httpAgent, _httpsAgent, _agentResetInterval, _requestCount, _SetupResetInterval, _GetAgentOptions, _url, _method, _headers, _data, _agentManager;
|
|
1
17
|
import * as fs from "node:fs";
|
|
2
18
|
import * as dotenv from "dotenv";
|
|
19
|
+
import http from "node:http";
|
|
20
|
+
import https from "node:https";
|
|
3
21
|
function getDefaultExportFromCjs(x) {
|
|
4
22
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
5
23
|
}
|
|
@@ -1648,9 +1666,175 @@ const envOptionsHandler = {
|
|
|
1648
1666
|
}
|
|
1649
1667
|
};
|
|
1650
1668
|
const goptions = new Proxy(envOptions, envOptionsHandler);
|
|
1669
|
+
class AgentManager {
|
|
1670
|
+
constructor(agentManagerOptions) {
|
|
1671
|
+
__privateAdd(this, _options);
|
|
1672
|
+
__privateAdd(this, _httpAgent, null);
|
|
1673
|
+
__privateAdd(this, _httpsAgent, null);
|
|
1674
|
+
__privateAdd(this, _agentResetInterval, null);
|
|
1675
|
+
__privateAdd(this, _requestCount, 0);
|
|
1676
|
+
__privateAdd(this, _SetupResetInterval, () => {
|
|
1677
|
+
__privateSet(this, _agentResetInterval, setTimeout(() => {
|
|
1678
|
+
this.ResetAgent();
|
|
1679
|
+
__privateGet(this, _SetupResetInterval).call(this);
|
|
1680
|
+
}, __privateGet(this, _options).agentResetInterval).unref());
|
|
1681
|
+
});
|
|
1682
|
+
__privateAdd(this, _GetAgentOptions, (https2) => {
|
|
1683
|
+
let options;
|
|
1684
|
+
if (__privateGet(this, _options).agentOptions) {
|
|
1685
|
+
options = {
|
|
1686
|
+
keepAlive: __privateGet(this, _options).agentOptions.keepAlive,
|
|
1687
|
+
maxSockets: __privateGet(this, _options).agentOptions.maxSockets,
|
|
1688
|
+
maxTotalSockets: __privateGet(this, _options).agentOptions.maxTotalSockets,
|
|
1689
|
+
maxFreeSockets: __privateGet(this, _options).agentOptions.maxFreeSockets,
|
|
1690
|
+
timeout: __privateGet(this, _options).agentOptions.timeout
|
|
1691
|
+
//@@ config
|
|
1692
|
+
};
|
|
1693
|
+
if (https2 === true) {
|
|
1694
|
+
options.rejectUnauthorized = __privateGet(this, _options).agentOptions.rejectUnauthorized;
|
|
1695
|
+
}
|
|
1696
|
+
} else {
|
|
1697
|
+
options = {
|
|
1698
|
+
keepAlive: process.env.NODE_ENV === "test" ? false : goptions.keepAlive,
|
|
1699
|
+
maxSockets: goptions.maxSockets,
|
|
1700
|
+
maxTotalSockets: goptions.maxTotalSockets,
|
|
1701
|
+
maxFreeSockets: goptions.maxFreeSockets,
|
|
1702
|
+
timeout: 3e4
|
|
1703
|
+
//@@ config
|
|
1704
|
+
};
|
|
1705
|
+
if (https2 === true) {
|
|
1706
|
+
options.rejectUnauthorized = goptions.isProduction;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
return options;
|
|
1710
|
+
});
|
|
1711
|
+
__privateSet(this, _options, agentManagerOptions);
|
|
1712
|
+
if (__privateGet(this, _options).agentResetInterval) {
|
|
1713
|
+
__privateGet(this, _SetupResetInterval).call(this);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
IncRequestCount() {
|
|
1717
|
+
__privateWrapper(this, _requestCount)._++;
|
|
1718
|
+
if (__privateGet(this, _options).agentResetCount) {
|
|
1719
|
+
if (__privateGet(this, _requestCount) % __privateGet(this, _options).agentResetCount === 0) {
|
|
1720
|
+
this.ResetAgent();
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
IsHttps(protocol) {
|
|
1725
|
+
if (protocol.toLowerCase().startsWith("https:")) {
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
return false;
|
|
1729
|
+
}
|
|
1730
|
+
GetAgent(protocol) {
|
|
1731
|
+
if (protocol.toLowerCase().startsWith("https:")) {
|
|
1732
|
+
if (__privateGet(this, _httpsAgent) === null) {
|
|
1733
|
+
__privateSet(this, _httpsAgent, new https.Agent(__privateGet(this, _GetAgentOptions).call(this, true)));
|
|
1734
|
+
}
|
|
1735
|
+
return __privateGet(this, _httpsAgent);
|
|
1736
|
+
} else if (protocol.toLowerCase().startsWith("http:")) {
|
|
1737
|
+
if (__privateGet(this, _httpAgent) === null) {
|
|
1738
|
+
__privateSet(this, _httpAgent, new http.Agent(__privateGet(this, _GetAgentOptions).call(this, false)));
|
|
1739
|
+
}
|
|
1740
|
+
return __privateGet(this, _httpAgent);
|
|
1741
|
+
} else {
|
|
1742
|
+
return null;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
ResetAgent() {
|
|
1746
|
+
__privateSet(this, _httpAgent, null);
|
|
1747
|
+
__privateSet(this, _httpsAgent, null);
|
|
1748
|
+
}
|
|
1749
|
+
/*
|
|
1750
|
+
url
|
|
1751
|
+
,method: 'post'
|
|
1752
|
+
,data: payload
|
|
1753
|
+
,headers: headers
|
|
1754
|
+
,httpsAgent: this.#agentManager.GetAgent(url)
|
|
1755
|
+
*/
|
|
1756
|
+
/*
|
|
1757
|
+
postgresContainer = await new GenericContainer("postgres")
|
|
1758
|
+
.withExposedPorts(5432)
|
|
1759
|
+
.withEnvironment({
|
|
1760
|
+
POSTGRES_PASSWORD: "postgres",
|
|
1761
|
+
//UV_THREADPOOL_SIZE: "64"
|
|
1762
|
+
})
|
|
1763
|
+
.withCommand(['-c', 'max_connections=20'])
|
|
1764
|
+
.start();
|
|
1765
|
+
*/
|
|
1766
|
+
Terminate() {
|
|
1767
|
+
if (__privateGet(this, _agentResetInterval)) {
|
|
1768
|
+
clearTimeout(__privateGet(this, _agentResetInterval));
|
|
1769
|
+
__privateSet(this, _agentResetInterval, null);
|
|
1770
|
+
}
|
|
1771
|
+
if (__privateGet(this, _httpAgent)) {
|
|
1772
|
+
__privateGet(this, _httpAgent).destroy();
|
|
1773
|
+
__privateSet(this, _httpAgent, null);
|
|
1774
|
+
}
|
|
1775
|
+
if (__privateGet(this, _httpsAgent)) {
|
|
1776
|
+
__privateGet(this, _httpsAgent).destroy();
|
|
1777
|
+
__privateSet(this, _httpsAgent, null);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
_options = new WeakMap();
|
|
1782
|
+
_httpAgent = new WeakMap();
|
|
1783
|
+
_httpsAgent = new WeakMap();
|
|
1784
|
+
_agentResetInterval = new WeakMap();
|
|
1785
|
+
_requestCount = new WeakMap();
|
|
1786
|
+
_SetupResetInterval = new WeakMap();
|
|
1787
|
+
_GetAgentOptions = new WeakMap();
|
|
1788
|
+
class STSAxiosConfig {
|
|
1789
|
+
constructor(url, method, headers) {
|
|
1790
|
+
__privateAdd(this, _url);
|
|
1791
|
+
__privateAdd(this, _method);
|
|
1792
|
+
__privateAdd(this, _headers);
|
|
1793
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1794
|
+
__privateAdd(this, _data);
|
|
1795
|
+
__privateAdd(this, _agentManager);
|
|
1796
|
+
__privateSet(this, _url, url);
|
|
1797
|
+
__privateSet(this, _method, method);
|
|
1798
|
+
__privateSet(this, _headers, headers);
|
|
1799
|
+
}
|
|
1800
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1801
|
+
withData(data) {
|
|
1802
|
+
__privateSet(this, _data, data);
|
|
1803
|
+
return this;
|
|
1804
|
+
}
|
|
1805
|
+
withAgentManager(agentManager) {
|
|
1806
|
+
__privateSet(this, _agentManager, agentManager);
|
|
1807
|
+
return this;
|
|
1808
|
+
}
|
|
1809
|
+
get config() {
|
|
1810
|
+
const retVal = {
|
|
1811
|
+
url: __privateGet(this, _url),
|
|
1812
|
+
method: __privateGet(this, _method),
|
|
1813
|
+
headers: __privateGet(this, _headers)
|
|
1814
|
+
};
|
|
1815
|
+
if (__privateGet(this, _agentManager) !== void 0) {
|
|
1816
|
+
if (__privateGet(this, _agentManager).IsHttps(__privateGet(this, _url))) {
|
|
1817
|
+
retVal.httpsAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
|
|
1818
|
+
} else {
|
|
1819
|
+
retVal.httpAgent = __privateGet(this, _agentManager).GetAgent(__privateGet(this, _url));
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
if (__privateGet(this, _data) !== void 0) {
|
|
1823
|
+
retVal.data = __privateGet(this, _data);
|
|
1824
|
+
}
|
|
1825
|
+
return retVal;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
_url = new WeakMap();
|
|
1829
|
+
_method = new WeakMap();
|
|
1830
|
+
_headers = new WeakMap();
|
|
1831
|
+
_data = new WeakMap();
|
|
1832
|
+
_agentManager = new WeakMap();
|
|
1651
1833
|
export {
|
|
1652
1834
|
$ResetOptions,
|
|
1653
1835
|
$ResetOptionsEx,
|
|
1836
|
+
AgentManager,
|
|
1837
|
+
STSAxiosConfig,
|
|
1654
1838
|
goptions
|
|
1655
1839
|
};
|
|
1656
1840
|
//# sourceMappingURL=stsconfig.mjs.map
|