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