@goplus123/core-api 1.1.3 → 1.1.4
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/index.cjs +477 -100
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.js +389 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10;// src/client/grpcClient.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;// src/client/grpcClient.ts
|
|
2
2
|
var _connect = require('@connectrpc/connect');
|
|
3
3
|
var _connectweb = require('@connectrpc/connect-web');
|
|
4
4
|
var _protobuf = require('@bufbuild/protobuf');
|
|
@@ -1550,10 +1550,12 @@ var WsApiError = (_class6 = class extends Error {
|
|
|
1550
1550
|
this.cause = options.cause;
|
|
1551
1551
|
}
|
|
1552
1552
|
}, _class6);
|
|
1553
|
-
var WsRpcClient = class {
|
|
1553
|
+
var WsRpcClient = (_class7 = class {
|
|
1554
1554
|
|
|
1555
1555
|
|
|
1556
|
-
|
|
1556
|
+
__init19() {this.adapters = exports.adapters = []}
|
|
1557
|
+
|
|
1558
|
+
constructor(ws, options = {}) {;_class7.prototype.__init19.call(this);
|
|
1557
1559
|
this.ws = ws;
|
|
1558
1560
|
this.options = {
|
|
1559
1561
|
defaultTimeout: _nullishCoalesce(options.defaultTimeout, () => ( 1e4)),
|
|
@@ -1566,6 +1568,78 @@ var WsRpcClient = class {
|
|
|
1566
1568
|
onError: options.onError
|
|
1567
1569
|
};
|
|
1568
1570
|
}
|
|
1571
|
+
addAdapter(adapter, options) {
|
|
1572
|
+
const prepend = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _166 => _166.prepend]), () => ( true));
|
|
1573
|
+
if (prepend) {
|
|
1574
|
+
this.adapters.unshift(adapter);
|
|
1575
|
+
} else {
|
|
1576
|
+
this.adapters.push(adapter);
|
|
1577
|
+
}
|
|
1578
|
+
return () => {
|
|
1579
|
+
this.adapters = this.adapters.filter((a) => a !== adapter);
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
clearAdapters() {
|
|
1583
|
+
this.adapters = [];
|
|
1584
|
+
}
|
|
1585
|
+
setDefaultAdapter(adapter) {
|
|
1586
|
+
this.defaultAdapter = adapter;
|
|
1587
|
+
}
|
|
1588
|
+
matchAdapter(match, service, functionName) {
|
|
1589
|
+
if (typeof match === "function") return match({ service, functionName });
|
|
1590
|
+
if (match.service !== void 0) {
|
|
1591
|
+
if (typeof match.service === "string") {
|
|
1592
|
+
if (match.service !== service) return false;
|
|
1593
|
+
} else if (!match.service.test(service)) {
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
if (match.functionName !== void 0) {
|
|
1598
|
+
if (typeof match.functionName === "string") {
|
|
1599
|
+
if (match.functionName !== functionName) return false;
|
|
1600
|
+
} else if (!match.functionName.test(functionName)) {
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
resolveAdapter(service, functionName) {
|
|
1607
|
+
for (const adapter of this.adapters) {
|
|
1608
|
+
if (this.matchAdapter(adapter.match, service, functionName)) return adapter;
|
|
1609
|
+
}
|
|
1610
|
+
if (this.defaultAdapter && this.matchAdapter(this.defaultAdapter.match, service, functionName)) {
|
|
1611
|
+
return this.defaultAdapter;
|
|
1612
|
+
}
|
|
1613
|
+
return void 0;
|
|
1614
|
+
}
|
|
1615
|
+
isOkWithAdapter(value, adapter) {
|
|
1616
|
+
if (_optionalChain([adapter, 'optionalAccess', _167 => _167.isSuccess])) return adapter.isSuccess(value);
|
|
1617
|
+
return this.isOk(value);
|
|
1618
|
+
}
|
|
1619
|
+
extractRequestIdWithAdapter(value, adapter) {
|
|
1620
|
+
const mapped = _optionalChain([adapter, 'optionalAccess', _168 => _168.getRequestId, 'optionalCall', _169 => _169(value)]);
|
|
1621
|
+
const normalized = this.normalizeString(mapped);
|
|
1622
|
+
if (normalized) return normalized;
|
|
1623
|
+
return this.extractRequestId(value);
|
|
1624
|
+
}
|
|
1625
|
+
extractCodeWithAdapter(value, adapter) {
|
|
1626
|
+
const mapped = _nullishCoalesce(_optionalChain([adapter, 'optionalAccess', _170 => _170.getBizCode, 'optionalCall', _171 => _171(value)]), () => ( _optionalChain([adapter, 'optionalAccess', _172 => _172.getCode, 'optionalCall', _173 => _173(value)])));
|
|
1627
|
+
const normalized = this.normalizeNumber(mapped);
|
|
1628
|
+
if (normalized !== void 0) return normalized;
|
|
1629
|
+
return this.extractCode(value);
|
|
1630
|
+
}
|
|
1631
|
+
extractStatusWithAdapter(value, adapter) {
|
|
1632
|
+
const mapped = _optionalChain([adapter, 'optionalAccess', _174 => _174.getStatus, 'optionalCall', _175 => _175(value)]);
|
|
1633
|
+
const normalized = this.normalizeNumber(mapped);
|
|
1634
|
+
if (normalized !== void 0) return normalized;
|
|
1635
|
+
return this.extractStatus(value);
|
|
1636
|
+
}
|
|
1637
|
+
getErrorMessageWithAdapter(value, adapter) {
|
|
1638
|
+
const mapped = _optionalChain([adapter, 'optionalAccess', _176 => _176.getMessage, 'optionalCall', _177 => _177(value)]);
|
|
1639
|
+
const normalized = this.normalizeString(mapped);
|
|
1640
|
+
if (normalized) return normalized;
|
|
1641
|
+
return this.getErrorMessage(value);
|
|
1642
|
+
}
|
|
1569
1643
|
normalizeNumber(value) {
|
|
1570
1644
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1571
1645
|
if (typeof value === "string") {
|
|
@@ -1606,7 +1680,7 @@ var WsRpcClient = class {
|
|
|
1606
1680
|
}
|
|
1607
1681
|
if (!value || typeof value !== "object") return void 0;
|
|
1608
1682
|
const anyValue = value;
|
|
1609
|
-
const id = _nullishCoalesce(anyValue.requestId, () => ( _optionalChain([anyValue, 'optionalAccess',
|
|
1683
|
+
const id = _nullishCoalesce(anyValue.requestId, () => ( _optionalChain([anyValue, 'optionalAccess', _178 => _178.data, 'optionalAccess', _179 => _179.requestId])));
|
|
1610
1684
|
return this.normalizeString(id);
|
|
1611
1685
|
}
|
|
1612
1686
|
extractCode(value) {
|
|
@@ -1655,10 +1729,10 @@ var WsRpcClient = class {
|
|
|
1655
1729
|
let res;
|
|
1656
1730
|
try {
|
|
1657
1731
|
res = await this.ws.request(functionName, service, finalPayload, {
|
|
1658
|
-
timeout: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1659
|
-
responseFunctionName: _optionalChain([options, 'optionalAccess',
|
|
1660
|
-
matchRequestId: _optionalChain([options, 'optionalAccess',
|
|
1661
|
-
filter: _optionalChain([options, 'optionalAccess',
|
|
1732
|
+
timeout: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _180 => _180.timeout]), () => ( this.options.defaultTimeout)),
|
|
1733
|
+
responseFunctionName: _optionalChain([options, 'optionalAccess', _181 => _181.responseFunctionName]),
|
|
1734
|
+
matchRequestId: _optionalChain([options, 'optionalAccess', _182 => _182.matchRequestId]),
|
|
1735
|
+
filter: _optionalChain([options, 'optionalAccess', _183 => _183.filter])
|
|
1662
1736
|
});
|
|
1663
1737
|
} catch (err) {
|
|
1664
1738
|
const wrapped = new WsApiError({
|
|
@@ -1666,32 +1740,36 @@ var WsRpcClient = class {
|
|
|
1666
1740
|
service,
|
|
1667
1741
|
functionName,
|
|
1668
1742
|
requestId,
|
|
1669
|
-
message: _optionalChain([err, 'optionalAccess',
|
|
1743
|
+
message: _optionalChain([err, 'optionalAccess', _184 => _184.message]),
|
|
1670
1744
|
cause: err
|
|
1671
1745
|
});
|
|
1672
1746
|
try {
|
|
1673
|
-
_optionalChain([this, 'access',
|
|
1747
|
+
_optionalChain([this, 'access', _185 => _185.options, 'access', _186 => _186.onError, 'optionalCall', _187 => _187(wrapped, { service, functionName, requestId })]);
|
|
1674
1748
|
} catch (e12) {
|
|
1675
1749
|
}
|
|
1676
1750
|
throw wrapped;
|
|
1677
1751
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1752
|
+
const adapter = this.resolveAdapter(service, functionName);
|
|
1753
|
+
if (!this.isOkWithAdapter(res, adapter)) {
|
|
1754
|
+
const responseRequestId = _nullishCoalesce(this.extractRequestIdWithAdapter(res, adapter), () => ( requestId));
|
|
1680
1755
|
const wrapped = new WsApiError({
|
|
1681
1756
|
kind: "biz_error",
|
|
1682
1757
|
service,
|
|
1683
1758
|
functionName,
|
|
1684
1759
|
requestId: responseRequestId,
|
|
1685
|
-
code: this.
|
|
1686
|
-
status: this.
|
|
1687
|
-
message: _nullishCoalesce(this.
|
|
1760
|
+
code: this.extractCodeWithAdapter(res, adapter),
|
|
1761
|
+
status: this.extractStatusWithAdapter(res, adapter),
|
|
1762
|
+
message: _nullishCoalesce(this.getErrorMessageWithAdapter(res, adapter), () => ( "Request failed"))
|
|
1688
1763
|
});
|
|
1689
1764
|
try {
|
|
1690
|
-
_optionalChain([this, 'access',
|
|
1765
|
+
_optionalChain([this, 'access', _188 => _188.options, 'access', _189 => _189.onError, 'optionalCall', _190 => _190(wrapped, { service, functionName, requestId: responseRequestId })]);
|
|
1691
1766
|
} catch (e13) {
|
|
1692
1767
|
}
|
|
1693
1768
|
throw wrapped;
|
|
1694
1769
|
}
|
|
1770
|
+
if (_optionalChain([adapter, 'optionalAccess', _191 => _191.unwrap])) {
|
|
1771
|
+
return adapter.unwrap(res);
|
|
1772
|
+
}
|
|
1695
1773
|
if (this.options.unwrapData && res && typeof res === "object" && "data" in res) {
|
|
1696
1774
|
return res.data;
|
|
1697
1775
|
}
|
|
@@ -1703,10 +1781,10 @@ var WsRpcClient = class {
|
|
|
1703
1781
|
let res;
|
|
1704
1782
|
try {
|
|
1705
1783
|
res = await this.ws.request(functionName, service, finalPayload, {
|
|
1706
|
-
timeout: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1707
|
-
responseFunctionName: _optionalChain([options, 'optionalAccess',
|
|
1708
|
-
matchRequestId: _optionalChain([options, 'optionalAccess',
|
|
1709
|
-
filter: _optionalChain([options, 'optionalAccess',
|
|
1784
|
+
timeout: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _192 => _192.timeout]), () => ( this.options.defaultTimeout)),
|
|
1785
|
+
responseFunctionName: _optionalChain([options, 'optionalAccess', _193 => _193.responseFunctionName]),
|
|
1786
|
+
matchRequestId: _optionalChain([options, 'optionalAccess', _194 => _194.matchRequestId]),
|
|
1787
|
+
filter: _optionalChain([options, 'optionalAccess', _195 => _195.filter])
|
|
1710
1788
|
});
|
|
1711
1789
|
} catch (err) {
|
|
1712
1790
|
const wrapped = new WsApiError({
|
|
@@ -1714,28 +1792,29 @@ var WsRpcClient = class {
|
|
|
1714
1792
|
service,
|
|
1715
1793
|
functionName,
|
|
1716
1794
|
requestId,
|
|
1717
|
-
message: _optionalChain([err, 'optionalAccess',
|
|
1795
|
+
message: _optionalChain([err, 'optionalAccess', _196 => _196.message]),
|
|
1718
1796
|
cause: err
|
|
1719
1797
|
});
|
|
1720
1798
|
try {
|
|
1721
|
-
_optionalChain([this, 'access',
|
|
1799
|
+
_optionalChain([this, 'access', _197 => _197.options, 'access', _198 => _198.onError, 'optionalCall', _199 => _199(wrapped, { service, functionName, requestId })]);
|
|
1722
1800
|
} catch (e14) {
|
|
1723
1801
|
}
|
|
1724
1802
|
throw wrapped;
|
|
1725
1803
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1804
|
+
const adapter = this.resolveAdapter(service, functionName);
|
|
1805
|
+
if (!this.isOkWithAdapter(res, adapter)) {
|
|
1806
|
+
const responseRequestId = _nullishCoalesce(this.extractRequestIdWithAdapter(res, adapter), () => ( requestId));
|
|
1728
1807
|
const wrapped = new WsApiError({
|
|
1729
1808
|
kind: "biz_error",
|
|
1730
1809
|
service,
|
|
1731
1810
|
functionName,
|
|
1732
1811
|
requestId: responseRequestId,
|
|
1733
|
-
code: this.
|
|
1734
|
-
status: this.
|
|
1735
|
-
message: _nullishCoalesce(this.
|
|
1812
|
+
code: this.extractCodeWithAdapter(res, adapter),
|
|
1813
|
+
status: this.extractStatusWithAdapter(res, adapter),
|
|
1814
|
+
message: _nullishCoalesce(this.getErrorMessageWithAdapter(res, adapter), () => ( "Request failed"))
|
|
1736
1815
|
});
|
|
1737
1816
|
try {
|
|
1738
|
-
_optionalChain([this, 'access',
|
|
1817
|
+
_optionalChain([this, 'access', _200 => _200.options, 'access', _201 => _201.onError, 'optionalCall', _202 => _202(wrapped, { service, functionName, requestId: responseRequestId })]);
|
|
1739
1818
|
} catch (e15) {
|
|
1740
1819
|
}
|
|
1741
1820
|
throw wrapped;
|
|
@@ -1780,7 +1859,7 @@ var WsRpcClient = class {
|
|
|
1780
1859
|
]);
|
|
1781
1860
|
return this.normalizeString(msg);
|
|
1782
1861
|
}
|
|
1783
|
-
};
|
|
1862
|
+
}, _class7);
|
|
1784
1863
|
|
|
1785
1864
|
// src/client/unifiedApiClient.ts
|
|
1786
1865
|
|
|
@@ -1790,6 +1869,7 @@ function isBizError(err) {
|
|
|
1790
1869
|
if (!err || typeof err !== "object") return false;
|
|
1791
1870
|
const anyErr = err;
|
|
1792
1871
|
if (anyErr.kind === "biz") return true;
|
|
1872
|
+
if (anyErr.name === "GrpcBizError") return true;
|
|
1793
1873
|
if (anyErr.name === "WsApiError") {
|
|
1794
1874
|
const hasCause = "cause" in anyErr && anyErr.cause != null;
|
|
1795
1875
|
const hasCodeOrStatus = typeof anyErr.code === "number" || typeof anyErr.status === "number";
|
|
@@ -1822,17 +1902,17 @@ function createAuthInterceptor(options) {
|
|
|
1822
1902
|
function createLogInterceptor(options) {
|
|
1823
1903
|
const level = _nullishCoalesce(options.level, () => ( "debug"));
|
|
1824
1904
|
const logger = options.logger;
|
|
1825
|
-
const log = level === "info" ? _optionalChain([logger, 'optionalAccess',
|
|
1905
|
+
const log = level === "info" ? _optionalChain([logger, 'optionalAccess', _203 => _203.info]) : _optionalChain([logger, 'optionalAccess', _204 => _204.debug]);
|
|
1826
1906
|
return (next) => async (ctx) => {
|
|
1827
1907
|
const startedAt = Date.now();
|
|
1828
|
-
_optionalChain([log, 'optionalCall',
|
|
1908
|
+
_optionalChain([log, 'optionalCall', _205 => _205("api.request", {
|
|
1829
1909
|
endpointId: ctx.endpoint.id,
|
|
1830
1910
|
transport: ctx.endpoint.transport,
|
|
1831
1911
|
meta: ctx.meta
|
|
1832
1912
|
})]);
|
|
1833
1913
|
try {
|
|
1834
1914
|
const res = await next(ctx);
|
|
1835
|
-
_optionalChain([log, 'optionalCall',
|
|
1915
|
+
_optionalChain([log, 'optionalCall', _206 => _206("api.response", {
|
|
1836
1916
|
endpointId: ctx.endpoint.id,
|
|
1837
1917
|
transport: ctx.endpoint.transport,
|
|
1838
1918
|
durationMs: Date.now() - startedAt,
|
|
@@ -1841,8 +1921,8 @@ function createLogInterceptor(options) {
|
|
|
1841
1921
|
return res;
|
|
1842
1922
|
} catch (err) {
|
|
1843
1923
|
const event = isBizError(err) ? "api.biz_error" : "api.transport_error";
|
|
1844
|
-
const report = isBizError(err) ? _nullishCoalesce(_optionalChain([logger, 'optionalAccess',
|
|
1845
|
-
_optionalChain([report, 'optionalCall',
|
|
1924
|
+
const report = isBizError(err) ? _nullishCoalesce(_optionalChain([logger, 'optionalAccess', _207 => _207.warn]), () => ( _optionalChain([logger, 'optionalAccess', _208 => _208.error]))) : _nullishCoalesce(_nullishCoalesce(_optionalChain([logger, 'optionalAccess', _209 => _209.error]), () => ( _optionalChain([logger, 'optionalAccess', _210 => _210.warn]))), () => ( _optionalChain([logger, 'optionalAccess', _211 => _211.info])));
|
|
1925
|
+
_optionalChain([report, 'optionalCall', _212 => _212(event, {
|
|
1846
1926
|
endpointId: ctx.endpoint.id,
|
|
1847
1927
|
transport: ctx.endpoint.transport,
|
|
1848
1928
|
durationMs: Date.now() - startedAt,
|
|
@@ -1855,6 +1935,25 @@ function createLogInterceptor(options) {
|
|
|
1855
1935
|
}
|
|
1856
1936
|
|
|
1857
1937
|
// src/client/unifiedApiClient.ts
|
|
1938
|
+
var GrpcBizError = (_class8 = class extends Error {
|
|
1939
|
+
__init20() {this.name = "GrpcBizError"}
|
|
1940
|
+
__init21() {this.kind = "biz"}
|
|
1941
|
+
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
|
|
1946
|
+
|
|
1947
|
+
constructor(options) {
|
|
1948
|
+
super(_nullishCoalesce(options.message, () => ( "gRPC request failed")));_class8.prototype.__init20.call(this);_class8.prototype.__init21.call(this);;
|
|
1949
|
+
this.endpointId = options.endpointId;
|
|
1950
|
+
this.serviceTypeName = options.serviceTypeName;
|
|
1951
|
+
this.methodName = options.methodName;
|
|
1952
|
+
this.code = options.code;
|
|
1953
|
+
this.status = options.status;
|
|
1954
|
+
this.raw = options.raw;
|
|
1955
|
+
}
|
|
1956
|
+
}, _class8);
|
|
1858
1957
|
function normalizeApiError(err, source) {
|
|
1859
1958
|
let endpoint;
|
|
1860
1959
|
let transport;
|
|
@@ -1880,7 +1979,7 @@ function normalizeApiError(err, source) {
|
|
|
1880
1979
|
}
|
|
1881
1980
|
if (endpoint.transport === "grpc") {
|
|
1882
1981
|
return {
|
|
1883
|
-
service: _optionalChain([endpoint, 'access',
|
|
1982
|
+
service: _optionalChain([endpoint, 'access', _213 => _213.grpc, 'access', _214 => _214.service, 'optionalAccess', _215 => _215.typeName]),
|
|
1884
1983
|
functionName: endpoint.grpc.methodName
|
|
1885
1984
|
};
|
|
1886
1985
|
}
|
|
@@ -1928,6 +2027,19 @@ function normalizeApiError(err, source) {
|
|
|
1928
2027
|
raw: err
|
|
1929
2028
|
};
|
|
1930
2029
|
}
|
|
2030
|
+
if (err instanceof GrpcBizError) {
|
|
2031
|
+
return {
|
|
2032
|
+
category,
|
|
2033
|
+
endpointId,
|
|
2034
|
+
transport: "grpc",
|
|
2035
|
+
service: _nullishCoalesce(err.serviceTypeName, () => ( fallback.service)),
|
|
2036
|
+
functionName: _nullishCoalesce(err.methodName, () => ( fallback.functionName)),
|
|
2037
|
+
code: err.code,
|
|
2038
|
+
status: err.status,
|
|
2039
|
+
message: _nullishCoalesce(err.message, () => ( "gRPC request failed")),
|
|
2040
|
+
raw: err.raw
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
1931
2043
|
const anyErr = err;
|
|
1932
2044
|
return {
|
|
1933
2045
|
category,
|
|
@@ -1935,13 +2047,13 @@ function normalizeApiError(err, source) {
|
|
|
1935
2047
|
transport,
|
|
1936
2048
|
service: fallback.service,
|
|
1937
2049
|
functionName: fallback.functionName,
|
|
1938
|
-
code: _optionalChain([anyErr, 'optionalAccess',
|
|
1939
|
-
status: typeof _optionalChain([anyErr, 'optionalAccess',
|
|
1940
|
-
message: _nullishCoalesce(_optionalChain([anyErr, 'optionalAccess',
|
|
2050
|
+
code: _optionalChain([anyErr, 'optionalAccess', _216 => _216.code]),
|
|
2051
|
+
status: typeof _optionalChain([anyErr, 'optionalAccess', _217 => _217.status]) === "number" ? anyErr.status : void 0,
|
|
2052
|
+
message: _nullishCoalesce(_optionalChain([anyErr, 'optionalAccess', _218 => _218.message]), () => ( (typeof err === "string" ? err : "Request failed"))),
|
|
1941
2053
|
raw: err
|
|
1942
2054
|
};
|
|
1943
2055
|
}
|
|
1944
|
-
var UnifiedApiClient = class {
|
|
2056
|
+
var UnifiedApiClient = (_class9 = class {
|
|
1945
2057
|
/**
|
|
1946
2058
|
* 统一调用入口:
|
|
1947
2059
|
* - 输入:EndpointSpec(来自 spec 层)+ request + meta
|
|
@@ -1955,12 +2067,31 @@ var UnifiedApiClient = class {
|
|
|
1955
2067
|
|
|
1956
2068
|
|
|
1957
2069
|
|
|
1958
|
-
|
|
2070
|
+
__init22() {this.grpcAdapters = []}
|
|
2071
|
+
|
|
2072
|
+
constructor(deps, options) {;_class9.prototype.__init22.call(this);
|
|
1959
2073
|
this.http = deps.http;
|
|
1960
2074
|
this.rpc = deps.rpc;
|
|
1961
2075
|
this.grpc = deps.grpc;
|
|
1962
|
-
this.callChain = composeInterceptors(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1963
|
-
this.onError = _optionalChain([options, 'optionalAccess',
|
|
2076
|
+
this.callChain = composeInterceptors(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _219 => _219.interceptors]), () => ( [])), (ctx) => this.dispatch(ctx));
|
|
2077
|
+
this.onError = _optionalChain([options, 'optionalAccess', _220 => _220.onError]);
|
|
2078
|
+
}
|
|
2079
|
+
addGrpcAdapter(adapter, options) {
|
|
2080
|
+
const prepend = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _221 => _221.prepend]), () => ( true));
|
|
2081
|
+
if (prepend) {
|
|
2082
|
+
this.grpcAdapters.unshift(adapter);
|
|
2083
|
+
} else {
|
|
2084
|
+
this.grpcAdapters.push(adapter);
|
|
2085
|
+
}
|
|
2086
|
+
return () => {
|
|
2087
|
+
this.grpcAdapters = this.grpcAdapters.filter((a) => a !== adapter);
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
clearGrpcAdapters() {
|
|
2091
|
+
this.grpcAdapters = [];
|
|
2092
|
+
}
|
|
2093
|
+
setGrpcDefaultAdapter(adapter) {
|
|
2094
|
+
this.grpcDefaultAdapter = adapter;
|
|
1964
2095
|
}
|
|
1965
2096
|
setErrorHandler(handler) {
|
|
1966
2097
|
this.onError = handler;
|
|
@@ -1999,16 +2130,16 @@ var UnifiedApiClient = class {
|
|
|
1999
2130
|
});
|
|
2000
2131
|
}
|
|
2001
2132
|
if (endpoint.transport === "ws") {
|
|
2002
|
-
const wsOptions = _optionalChain([ctx, 'access',
|
|
2133
|
+
const wsOptions = _optionalChain([ctx, 'access', _222 => _222.meta, 'optionalAccess', _223 => _223.wsOptions]);
|
|
2003
2134
|
return await this.rpc.request(
|
|
2004
2135
|
endpoint.ws.functionName,
|
|
2005
2136
|
endpoint.ws.service,
|
|
2006
2137
|
ctx.request,
|
|
2007
2138
|
{
|
|
2008
|
-
timeout: _nullishCoalesce(_optionalChain([wsOptions, 'optionalAccess',
|
|
2009
|
-
responseFunctionName: _nullishCoalesce(_optionalChain([wsOptions, 'optionalAccess',
|
|
2010
|
-
matchRequestId: _optionalChain([wsOptions, 'optionalAccess',
|
|
2011
|
-
filter: _optionalChain([wsOptions, 'optionalAccess',
|
|
2139
|
+
timeout: _nullishCoalesce(_optionalChain([wsOptions, 'optionalAccess', _224 => _224.timeout]), () => ( endpoint.ws.timeout)),
|
|
2140
|
+
responseFunctionName: _nullishCoalesce(_optionalChain([wsOptions, 'optionalAccess', _225 => _225.responseFunctionName]), () => ( endpoint.ws.responseFunctionName)),
|
|
2141
|
+
matchRequestId: _optionalChain([wsOptions, 'optionalAccess', _226 => _226.matchRequestId]),
|
|
2142
|
+
filter: _optionalChain([wsOptions, 'optionalAccess', _227 => _227.filter])
|
|
2012
2143
|
}
|
|
2013
2144
|
);
|
|
2014
2145
|
}
|
|
@@ -2019,12 +2150,142 @@ var UnifiedApiClient = class {
|
|
|
2019
2150
|
if (typeof method !== "function") {
|
|
2020
2151
|
throw new Error(`gRPC method not found: ${service.typeName}.${methodName}`);
|
|
2021
2152
|
}
|
|
2022
|
-
const callOptions = _optionalChain([ctx, 'access',
|
|
2153
|
+
const callOptions = _optionalChain([ctx, 'access', _228 => _228.meta, 'optionalAccess', _229 => _229.callOptions]);
|
|
2023
2154
|
const req = endpoint.grpc.requestSchema ? _protobuf.create.call(void 0, endpoint.grpc.requestSchema, _nullishCoalesce(ctx.request, () => ( {}))) : ctx.request;
|
|
2024
|
-
const headers = { ..._nullishCoalesce(_optionalChain([callOptions, 'optionalAccess',
|
|
2025
|
-
|
|
2155
|
+
const headers = { ..._nullishCoalesce(_optionalChain([callOptions, 'optionalAccess', _230 => _230.headers]), () => ( {})), ..._nullishCoalesce(ctx.headers, () => ( {})) };
|
|
2156
|
+
const res = await method(req, { ..._nullishCoalesce(callOptions, () => ( {})), headers });
|
|
2157
|
+
const adapter = this.resolveGrpcAdapter({
|
|
2158
|
+
endpointId: endpoint.id,
|
|
2159
|
+
serviceTypeName: service.typeName,
|
|
2160
|
+
methodName
|
|
2161
|
+
});
|
|
2162
|
+
if (!adapter) return res;
|
|
2163
|
+
if (!this.isGrpcOkWithAdapter(res, adapter)) {
|
|
2164
|
+
throw new GrpcBizError({
|
|
2165
|
+
endpointId: endpoint.id,
|
|
2166
|
+
serviceTypeName: service.typeName,
|
|
2167
|
+
methodName,
|
|
2168
|
+
code: this.extractGrpcCodeWithAdapter(res, adapter),
|
|
2169
|
+
status: this.extractGrpcStatusWithAdapter(res, adapter),
|
|
2170
|
+
message: _nullishCoalesce(this.getGrpcErrorMessageWithAdapter(res, adapter), () => ( "Request failed")),
|
|
2171
|
+
raw: res
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
if (adapter.unwrap) return adapter.unwrap(res);
|
|
2175
|
+
return res;
|
|
2026
2176
|
}
|
|
2027
|
-
|
|
2177
|
+
matchGrpcAdapter(match, ctx) {
|
|
2178
|
+
if (typeof match === "function") return match(ctx);
|
|
2179
|
+
if (match.endpointId !== void 0) {
|
|
2180
|
+
if (typeof match.endpointId === "string") {
|
|
2181
|
+
if (match.endpointId !== ctx.endpointId) return false;
|
|
2182
|
+
} else if (!match.endpointId.test(ctx.endpointId)) {
|
|
2183
|
+
return false;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
if (match.serviceTypeName !== void 0) {
|
|
2187
|
+
if (typeof match.serviceTypeName === "string") {
|
|
2188
|
+
if (match.serviceTypeName !== ctx.serviceTypeName) return false;
|
|
2189
|
+
} else if (!match.serviceTypeName.test(ctx.serviceTypeName)) {
|
|
2190
|
+
return false;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
if (match.methodName !== void 0) {
|
|
2194
|
+
if (typeof match.methodName === "string") {
|
|
2195
|
+
if (match.methodName !== ctx.methodName) return false;
|
|
2196
|
+
} else if (!match.methodName.test(ctx.methodName)) {
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
resolveGrpcAdapter(ctx) {
|
|
2203
|
+
for (const adapter of this.grpcAdapters) {
|
|
2204
|
+
if (this.matchGrpcAdapter(adapter.match, ctx)) return adapter;
|
|
2205
|
+
}
|
|
2206
|
+
if (this.grpcDefaultAdapter && this.matchGrpcAdapter(this.grpcDefaultAdapter.match, ctx)) {
|
|
2207
|
+
return this.grpcDefaultAdapter;
|
|
2208
|
+
}
|
|
2209
|
+
return void 0;
|
|
2210
|
+
}
|
|
2211
|
+
normalizeNumber(value) {
|
|
2212
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2213
|
+
if (typeof value === "string") {
|
|
2214
|
+
const trimmed = value.trim();
|
|
2215
|
+
if (!trimmed) return void 0;
|
|
2216
|
+
const asNumber = Number(trimmed);
|
|
2217
|
+
return Number.isFinite(asNumber) ? asNumber : void 0;
|
|
2218
|
+
}
|
|
2219
|
+
return void 0;
|
|
2220
|
+
}
|
|
2221
|
+
normalizeString(value) {
|
|
2222
|
+
if (typeof value === "string") {
|
|
2223
|
+
const trimmed = value.trim();
|
|
2224
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2225
|
+
}
|
|
2226
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
2227
|
+
return void 0;
|
|
2228
|
+
}
|
|
2229
|
+
pickField(value, keys) {
|
|
2230
|
+
if (!value || typeof value !== "object") return void 0;
|
|
2231
|
+
const anyValue = value;
|
|
2232
|
+
for (const key of keys) {
|
|
2233
|
+
if (anyValue[key] !== void 0) return anyValue[key];
|
|
2234
|
+
}
|
|
2235
|
+
return void 0;
|
|
2236
|
+
}
|
|
2237
|
+
isGrpcOk(value) {
|
|
2238
|
+
if (!value || typeof value !== "object") return true;
|
|
2239
|
+
const rawSuccess = this.pickField(value, ["success", "ok"]);
|
|
2240
|
+
if (rawSuccess !== void 0) {
|
|
2241
|
+
if (typeof rawSuccess === "boolean") return rawSuccess;
|
|
2242
|
+
if (typeof rawSuccess === "string") {
|
|
2243
|
+
const lowered = rawSuccess.trim().toLowerCase();
|
|
2244
|
+
if (lowered === "true") return true;
|
|
2245
|
+
if (lowered === "false") return false;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
const rawCode = this.pickField(value, ["code", "errCode", "errorCode", "resultCode"]);
|
|
2249
|
+
if (rawCode !== void 0) {
|
|
2250
|
+
const code = this.normalizeNumber(rawCode);
|
|
2251
|
+
return typeof code === "number" ? code === 0 || code === 200 : false;
|
|
2252
|
+
}
|
|
2253
|
+
const rawStatus = this.pickField(value, ["status", "statusCode", "httpStatus", "http_code"]);
|
|
2254
|
+
if (rawStatus !== void 0) {
|
|
2255
|
+
const status = this.normalizeNumber(rawStatus);
|
|
2256
|
+
return typeof status === "number" ? status === 0 || status === 200 : false;
|
|
2257
|
+
}
|
|
2258
|
+
return true;
|
|
2259
|
+
}
|
|
2260
|
+
isGrpcOkWithAdapter(value, adapter) {
|
|
2261
|
+
if (adapter.isSuccess) return adapter.isSuccess(value);
|
|
2262
|
+
return this.isGrpcOk(value);
|
|
2263
|
+
}
|
|
2264
|
+
extractGrpcCodeWithAdapter(value, adapter) {
|
|
2265
|
+
const mapped = _nullishCoalesce(_optionalChain([adapter, 'access', _231 => _231.getBizCode, 'optionalCall', _232 => _232(value)]), () => ( _optionalChain([adapter, 'access', _233 => _233.getCode, 'optionalCall', _234 => _234(value)])));
|
|
2266
|
+
const normalized = this.normalizeNumber(mapped);
|
|
2267
|
+
if (normalized !== void 0) return normalized;
|
|
2268
|
+
return this.normalizeNumber(
|
|
2269
|
+
this.pickField(value, ["code", "errCode", "errorCode", "resultCode"])
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
extractGrpcStatusWithAdapter(value, adapter) {
|
|
2273
|
+
const mapped = _optionalChain([adapter, 'access', _235 => _235.getStatus, 'optionalCall', _236 => _236(value)]);
|
|
2274
|
+
const normalized = this.normalizeNumber(mapped);
|
|
2275
|
+
if (normalized !== void 0) return normalized;
|
|
2276
|
+
return this.normalizeNumber(
|
|
2277
|
+
this.pickField(value, ["status", "statusCode", "httpStatus", "http_code"])
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
getGrpcErrorMessageWithAdapter(value, adapter) {
|
|
2281
|
+
const mapped = _optionalChain([adapter, 'access', _237 => _237.getMessage, 'optionalCall', _238 => _238(value)]);
|
|
2282
|
+
const normalized = this.normalizeString(mapped);
|
|
2283
|
+
if (normalized) return normalized;
|
|
2284
|
+
return this.normalizeString(
|
|
2285
|
+
this.pickField(value, ["message", "msg", "error", "errMsg", "errmsg", "errorMessage"])
|
|
2286
|
+
);
|
|
2287
|
+
}
|
|
2288
|
+
}, _class9);
|
|
2028
2289
|
|
|
2029
2290
|
// src/utils/adapters/web.ts
|
|
2030
2291
|
var webStorage = {
|
|
@@ -2058,7 +2319,7 @@ function createFetchGuid(storage, options) {
|
|
|
2058
2319
|
return () => fetchGuidWithStorage(storage, options);
|
|
2059
2320
|
}
|
|
2060
2321
|
function fetchGuidWithStorage(storage, options) {
|
|
2061
|
-
const key = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2322
|
+
const key = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _239 => _239.key]), () => ( defaultKey));
|
|
2062
2323
|
const current = safeGet(storage, key);
|
|
2063
2324
|
if (current) {
|
|
2064
2325
|
const unmasked = unmaskGuid(current);
|
|
@@ -2117,8 +2378,8 @@ function unmaskGuid(value) {
|
|
|
2117
2378
|
return hex.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
2118
2379
|
}
|
|
2119
2380
|
function formatGuid(guid, options) {
|
|
2120
|
-
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2121
|
-
const prefix = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2381
|
+
const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.format]), () => ( "uuid"));
|
|
2382
|
+
const prefix = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _241 => _241.prefix]), () => ( ""));
|
|
2122
2383
|
if (format === "uuid") return prefix + guid;
|
|
2123
2384
|
const hex = guid.replace(/-/g, "");
|
|
2124
2385
|
if (format === "hex") return prefix + hex;
|
|
@@ -2454,7 +2715,7 @@ function requestApi(args) {
|
|
|
2454
2715
|
return waitForSdkInit().then(() => requestApi(args));
|
|
2455
2716
|
}
|
|
2456
2717
|
const serviceInstance2 = serviceInstances[args.service];
|
|
2457
|
-
const method2 = _optionalChain([serviceInstance2, 'optionalAccess',
|
|
2718
|
+
const method2 = _optionalChain([serviceInstance2, 'optionalAccess', _242 => _242[args.functionName]]);
|
|
2458
2719
|
if (typeof method2 === "function") {
|
|
2459
2720
|
if (args.callOptions !== void 0) {
|
|
2460
2721
|
return method2(args.requestParam, args.callOptions);
|
|
@@ -2467,7 +2728,7 @@ function requestApi(args) {
|
|
|
2467
2728
|
throw new Error(`Endpoint not found: ${args.service}.${args.functionName} (http)`);
|
|
2468
2729
|
}
|
|
2469
2730
|
const serviceInstance = serviceInstances[args.service];
|
|
2470
|
-
const method = _optionalChain([serviceInstance, 'optionalAccess',
|
|
2731
|
+
const method = _optionalChain([serviceInstance, 'optionalAccess', _243 => _243[args.functionName]]);
|
|
2471
2732
|
if (typeof method === "function") {
|
|
2472
2733
|
if (args.callOptions !== void 0) {
|
|
2473
2734
|
return method(args.requestParam, args.callOptions);
|
|
@@ -2531,7 +2792,7 @@ function createLazyObject(loader) {
|
|
|
2531
2792
|
if (prop === "then") return void 0;
|
|
2532
2793
|
if (prop === "__load") return load;
|
|
2533
2794
|
return (...args) => load().then((obj) => {
|
|
2534
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
2795
|
+
const value = _optionalChain([obj, 'optionalAccess', _244 => _244[prop]]);
|
|
2535
2796
|
if (typeof value === "function") return value.apply(obj, args);
|
|
2536
2797
|
return value;
|
|
2537
2798
|
});
|
|
@@ -2579,8 +2840,8 @@ function detachNotifyRegistration(reg) {
|
|
|
2579
2840
|
}
|
|
2580
2841
|
function getWsSnapshot() {
|
|
2581
2842
|
return {
|
|
2582
|
-
readyState: _optionalChain([api, 'optionalAccess',
|
|
2583
|
-
isConnected: _optionalChain([api, 'optionalAccess',
|
|
2843
|
+
readyState: _optionalChain([api, 'optionalAccess', _245 => _245.ws]) ? api.ws.state : void 0,
|
|
2844
|
+
isConnected: _optionalChain([api, 'optionalAccess', _246 => _246.ws]) ? api.ws.isConnected : false,
|
|
2584
2845
|
status: wsStatusSnapshot
|
|
2585
2846
|
};
|
|
2586
2847
|
}
|
|
@@ -2593,8 +2854,8 @@ function clearWsStatusBridge() {
|
|
|
2593
2854
|
}
|
|
2594
2855
|
wsStatusOffs = [];
|
|
2595
2856
|
}
|
|
2596
|
-
var Pipeline = (
|
|
2597
|
-
|
|
2857
|
+
var Pipeline = (_class10 = class {constructor() { _class10.prototype.__init23.call(this); }
|
|
2858
|
+
__init23() {this.handlers = []}
|
|
2598
2859
|
use(handler) {
|
|
2599
2860
|
this.handlers.push(handler);
|
|
2600
2861
|
return () => {
|
|
@@ -2613,9 +2874,9 @@ var Pipeline = (_class7 = class {constructor() { _class7.prototype.__init19.call
|
|
|
2613
2874
|
};
|
|
2614
2875
|
return await next();
|
|
2615
2876
|
}
|
|
2616
|
-
},
|
|
2617
|
-
var ApiErrorCenter = (
|
|
2618
|
-
|
|
2877
|
+
}, _class10);
|
|
2878
|
+
var ApiErrorCenter = (_class11 = class {constructor() { _class11.prototype.__init24.call(this); }
|
|
2879
|
+
__init24() {this.pipeline = new Pipeline()}
|
|
2619
2880
|
use(handler) {
|
|
2620
2881
|
return this.pipeline.use(async (error, ctx, next) => {
|
|
2621
2882
|
try {
|
|
@@ -2634,7 +2895,7 @@ var ApiErrorCenter = (_class8 = class {constructor() { _class8.prototype.__init2
|
|
|
2634
2895
|
clear() {
|
|
2635
2896
|
this.pipeline.clear();
|
|
2636
2897
|
}
|
|
2637
|
-
},
|
|
2898
|
+
}, _class11);
|
|
2638
2899
|
var apiError = {
|
|
2639
2900
|
use(handler) {
|
|
2640
2901
|
const id = ++apiErrorRegistrationSeq;
|
|
@@ -2656,12 +2917,12 @@ var apiError = {
|
|
|
2656
2917
|
return apiErrorCenter.emit(error, source);
|
|
2657
2918
|
}
|
|
2658
2919
|
};
|
|
2659
|
-
var NotifyChannel = (
|
|
2660
|
-
constructor(type, wsNotify) {;
|
|
2920
|
+
var NotifyChannel = (_class12 = class {
|
|
2921
|
+
constructor(type, wsNotify) {;_class12.prototype.__init25.call(this);
|
|
2661
2922
|
this.type = type;
|
|
2662
2923
|
this.wsNotify = wsNotify;
|
|
2663
2924
|
}
|
|
2664
|
-
|
|
2925
|
+
__init25() {this.pipeline = new Pipeline()}
|
|
2665
2926
|
|
|
2666
2927
|
ensureAttached() {
|
|
2667
2928
|
if (!this.wsNotify) return;
|
|
@@ -2699,12 +2960,12 @@ var NotifyChannel = (_class9 = class {
|
|
|
2699
2960
|
}
|
|
2700
2961
|
this.pipeline.clear();
|
|
2701
2962
|
}
|
|
2702
|
-
},
|
|
2703
|
-
var NotifyCenter = (
|
|
2704
|
-
constructor(wsNotify) {;
|
|
2963
|
+
}, _class12);
|
|
2964
|
+
var NotifyCenter = (_class13 = class {
|
|
2965
|
+
constructor(wsNotify) {;_class13.prototype.__init26.call(this);
|
|
2705
2966
|
this.wsNotify = wsNotify;
|
|
2706
2967
|
}
|
|
2707
|
-
|
|
2968
|
+
__init26() {this.channels = /* @__PURE__ */ new Map()}
|
|
2708
2969
|
channel(type) {
|
|
2709
2970
|
const existing = this.channels.get(type);
|
|
2710
2971
|
if (existing) return existing;
|
|
@@ -2718,7 +2979,7 @@ var NotifyCenter = (_class10 = class {
|
|
|
2718
2979
|
}
|
|
2719
2980
|
this.channels.clear();
|
|
2720
2981
|
}
|
|
2721
|
-
},
|
|
2982
|
+
}, _class13);
|
|
2722
2983
|
function notify(type) {
|
|
2723
2984
|
const channel = {
|
|
2724
2985
|
use(handler) {
|
|
@@ -2728,7 +2989,7 @@ function notify(type) {
|
|
|
2728
2989
|
attachNotifyRegistration(type, reg);
|
|
2729
2990
|
return () => {
|
|
2730
2991
|
const map = notifyRegistrationsByType.get(type);
|
|
2731
|
-
const current = _optionalChain([map, 'optionalAccess',
|
|
2992
|
+
const current = _optionalChain([map, 'optionalAccess', _247 => _247.get, 'call', _248 => _248(id)]);
|
|
2732
2993
|
if (!map || !current) return;
|
|
2733
2994
|
detachNotifyRegistration(current);
|
|
2734
2995
|
map.delete(id);
|
|
@@ -2742,7 +3003,7 @@ function notify(type) {
|
|
|
2742
3003
|
attachNotifyRegistration(type, reg);
|
|
2743
3004
|
return () => {
|
|
2744
3005
|
const map = notifyRegistrationsByType.get(type);
|
|
2745
|
-
const current = _optionalChain([map, 'optionalAccess',
|
|
3006
|
+
const current = _optionalChain([map, 'optionalAccess', _249 => _249.get, 'call', _250 => _250(id)]);
|
|
2746
3007
|
if (!map || !current) return;
|
|
2747
3008
|
detachNotifyRegistration(current);
|
|
2748
3009
|
map.delete(id);
|
|
@@ -2764,13 +3025,121 @@ function notify(type) {
|
|
|
2764
3025
|
}
|
|
2765
3026
|
notifyRegistrationsByType.delete(type);
|
|
2766
3027
|
}
|
|
2767
|
-
_optionalChain([notifyCenter, 'optionalAccess',
|
|
3028
|
+
_optionalChain([notifyCenter, 'optionalAccess', _251 => _251.channel, 'call', _252 => _252(type), 'access', _253 => _253.destroy, 'call', _254 => _254()]);
|
|
2768
3029
|
}
|
|
2769
3030
|
};
|
|
2770
3031
|
return channel;
|
|
2771
3032
|
}
|
|
3033
|
+
var wsAdapterRegistrationSeq = 0;
|
|
3034
|
+
var wsAdapterRegistrations = /* @__PURE__ */ new Map();
|
|
3035
|
+
var wsDefaultAdapter;
|
|
3036
|
+
var wsAdapterRpc;
|
|
3037
|
+
function attachWsAdapterRegistration(reg) {
|
|
3038
|
+
if (!wsAdapterRpc) return;
|
|
3039
|
+
if (reg.off) reg.off();
|
|
3040
|
+
reg.off = wsAdapterRpc.addAdapter(reg.adapter, { prepend: reg.prepend });
|
|
3041
|
+
}
|
|
3042
|
+
function detachWsAdapterRegistration(reg) {
|
|
3043
|
+
if (reg.off) reg.off();
|
|
3044
|
+
reg.off = void 0;
|
|
3045
|
+
}
|
|
3046
|
+
function setWsAdapterRpc(next) {
|
|
3047
|
+
if (wsAdapterRpc === next) return;
|
|
3048
|
+
for (const reg of wsAdapterRegistrations.values()) {
|
|
3049
|
+
detachWsAdapterRegistration(reg);
|
|
3050
|
+
}
|
|
3051
|
+
wsAdapterRpc = next;
|
|
3052
|
+
if (!wsAdapterRpc) return;
|
|
3053
|
+
wsAdapterRpc.clearAdapters();
|
|
3054
|
+
wsAdapterRpc.setDefaultAdapter(wsDefaultAdapter);
|
|
3055
|
+
for (const reg of wsAdapterRegistrations.values()) {
|
|
3056
|
+
attachWsAdapterRegistration(reg);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
var adapters = {
|
|
3060
|
+
ws: {
|
|
3061
|
+
add(adapter, options) {
|
|
3062
|
+
const id = ++wsAdapterRegistrationSeq;
|
|
3063
|
+
const reg = { adapter, prepend: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _255 => _255.prepend]), () => ( true)) };
|
|
3064
|
+
wsAdapterRegistrations.set(id, reg);
|
|
3065
|
+
attachWsAdapterRegistration(reg);
|
|
3066
|
+
return () => {
|
|
3067
|
+
const current = wsAdapterRegistrations.get(id);
|
|
3068
|
+
if (!current) return;
|
|
3069
|
+
detachWsAdapterRegistration(current);
|
|
3070
|
+
wsAdapterRegistrations.delete(id);
|
|
3071
|
+
};
|
|
3072
|
+
},
|
|
3073
|
+
setDefault(adapter) {
|
|
3074
|
+
wsDefaultAdapter = adapter;
|
|
3075
|
+
_optionalChain([wsAdapterRpc, 'optionalAccess', _256 => _256.setDefaultAdapter, 'call', _257 => _257(adapter)]);
|
|
3076
|
+
},
|
|
3077
|
+
clear() {
|
|
3078
|
+
for (const reg of wsAdapterRegistrations.values()) {
|
|
3079
|
+
detachWsAdapterRegistration(reg);
|
|
3080
|
+
}
|
|
3081
|
+
wsAdapterRegistrations.clear();
|
|
3082
|
+
wsDefaultAdapter = void 0;
|
|
3083
|
+
_optionalChain([wsAdapterRpc, 'optionalAccess', _258 => _258.clearAdapters, 'call', _259 => _259()]);
|
|
3084
|
+
_optionalChain([wsAdapterRpc, 'optionalAccess', _260 => _260.setDefaultAdapter, 'call', _261 => _261(void 0)]);
|
|
3085
|
+
}
|
|
3086
|
+
},
|
|
3087
|
+
grpc: {
|
|
3088
|
+
add(adapter, options) {
|
|
3089
|
+
const id = ++grpcAdapterRegistrationSeq;
|
|
3090
|
+
const reg = { adapter, prepend: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _262 => _262.prepend]), () => ( true)) };
|
|
3091
|
+
grpcAdapterRegistrations.set(id, reg);
|
|
3092
|
+
attachGrpcAdapterRegistration(reg);
|
|
3093
|
+
return () => {
|
|
3094
|
+
const current = grpcAdapterRegistrations.get(id);
|
|
3095
|
+
if (!current) return;
|
|
3096
|
+
detachGrpcAdapterRegistration(current);
|
|
3097
|
+
grpcAdapterRegistrations.delete(id);
|
|
3098
|
+
};
|
|
3099
|
+
},
|
|
3100
|
+
setDefault(adapter) {
|
|
3101
|
+
grpcDefaultAdapter = adapter;
|
|
3102
|
+
_optionalChain([grpcAdapterClient, 'optionalAccess', _263 => _263.setGrpcDefaultAdapter, 'call', _264 => _264(adapter)]);
|
|
3103
|
+
},
|
|
3104
|
+
clear() {
|
|
3105
|
+
for (const reg of grpcAdapterRegistrations.values()) {
|
|
3106
|
+
detachGrpcAdapterRegistration(reg);
|
|
3107
|
+
}
|
|
3108
|
+
grpcAdapterRegistrations.clear();
|
|
3109
|
+
grpcDefaultAdapter = void 0;
|
|
3110
|
+
_optionalChain([grpcAdapterClient, 'optionalAccess', _265 => _265.clearGrpcAdapters, 'call', _266 => _266()]);
|
|
3111
|
+
_optionalChain([grpcAdapterClient, 'optionalAccess', _267 => _267.setGrpcDefaultAdapter, 'call', _268 => _268(void 0)]);
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
};
|
|
3115
|
+
var grpcAdapterRegistrationSeq = 0;
|
|
3116
|
+
var grpcAdapterRegistrations = /* @__PURE__ */ new Map();
|
|
3117
|
+
var grpcDefaultAdapter;
|
|
3118
|
+
var grpcAdapterClient;
|
|
3119
|
+
function attachGrpcAdapterRegistration(reg) {
|
|
3120
|
+
if (!grpcAdapterClient) return;
|
|
3121
|
+
if (reg.off) reg.off();
|
|
3122
|
+
reg.off = grpcAdapterClient.addGrpcAdapter(reg.adapter, { prepend: reg.prepend });
|
|
3123
|
+
}
|
|
3124
|
+
function detachGrpcAdapterRegistration(reg) {
|
|
3125
|
+
if (reg.off) reg.off();
|
|
3126
|
+
reg.off = void 0;
|
|
3127
|
+
}
|
|
3128
|
+
function setGrpcAdapterClient(next) {
|
|
3129
|
+
if (grpcAdapterClient === next) return;
|
|
3130
|
+
for (const reg of grpcAdapterRegistrations.values()) {
|
|
3131
|
+
detachGrpcAdapterRegistration(reg);
|
|
3132
|
+
}
|
|
3133
|
+
grpcAdapterClient = next;
|
|
3134
|
+
if (!grpcAdapterClient) return;
|
|
3135
|
+
grpcAdapterClient.clearGrpcAdapters();
|
|
3136
|
+
grpcAdapterClient.setGrpcDefaultAdapter(grpcDefaultAdapter);
|
|
3137
|
+
for (const reg of grpcAdapterRegistrations.values()) {
|
|
3138
|
+
attachGrpcAdapterRegistration(reg);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
2772
3141
|
function destroySDK() {
|
|
2773
|
-
if (_optionalChain([api, 'optionalAccess',
|
|
3142
|
+
if (_optionalChain([api, 'optionalAccess', _269 => _269.ws])) {
|
|
2774
3143
|
try {
|
|
2775
3144
|
api.ws.disconnect();
|
|
2776
3145
|
} catch (e) {
|
|
@@ -2785,12 +3154,17 @@ function destroySDK() {
|
|
|
2785
3154
|
reg.off = void 0;
|
|
2786
3155
|
}
|
|
2787
3156
|
}
|
|
3157
|
+
for (const reg of wsAdapterRegistrations.values()) {
|
|
3158
|
+
reg.off = void 0;
|
|
3159
|
+
}
|
|
2788
3160
|
api = void 0;
|
|
2789
3161
|
resetRoutingState();
|
|
2790
|
-
_optionalChain([apiErrorCenter, 'optionalAccess',
|
|
3162
|
+
_optionalChain([apiErrorCenter, 'optionalAccess', _270 => _270.clear, 'call', _271 => _271()]);
|
|
2791
3163
|
apiErrorCenter = void 0;
|
|
2792
|
-
_optionalChain([notifyCenter, 'optionalAccess',
|
|
3164
|
+
_optionalChain([notifyCenter, 'optionalAccess', _272 => _272.destroy, 'call', _273 => _273()]);
|
|
2793
3165
|
notifyCenter = void 0;
|
|
3166
|
+
setWsAdapterRpc(void 0);
|
|
3167
|
+
setGrpcAdapterClient(void 0);
|
|
2794
3168
|
clearWsStatusBridge();
|
|
2795
3169
|
wsStatusSnapshot = void 0;
|
|
2796
3170
|
}
|
|
@@ -2805,19 +3179,19 @@ function initSDK(config) {
|
|
|
2805
3179
|
});
|
|
2806
3180
|
resetRoutingState();
|
|
2807
3181
|
setRequestApiInitWaitMs(_nullishCoalesce(config.requestApiInitWaitMs, () => ( 1e4)));
|
|
2808
|
-
setTransportState({ hasHttp: !!config.http, hasWs: !!config.ws, hasGrpc: !!_optionalChain([config, 'access',
|
|
3182
|
+
setTransportState({ hasHttp: !!config.http, hasWs: !!config.ws, hasGrpc: !!_optionalChain([config, 'access', _274 => _274.grpc, 'optionalAccess', _275 => _275.baseUrl]) });
|
|
2809
3183
|
setDefaultTransport(_nullishCoalesce(config.defaultTransport, () => ( "auto")));
|
|
2810
3184
|
schedulePreload(rebuildEndpointRegistry);
|
|
2811
|
-
_optionalChain([config, 'access',
|
|
3185
|
+
_optionalChain([config, 'access', _276 => _276.logger, 'optionalAccess', _277 => _277.info, 'optionalCall', _278 => _278("sdk.initialized", {
|
|
2812
3186
|
hasHttp: !!config.http,
|
|
2813
3187
|
hasWs: !!config.ws,
|
|
2814
3188
|
hasGrpc: !!config.grpc
|
|
2815
3189
|
})]);
|
|
2816
|
-
const sdk = { apiError, notify };
|
|
3190
|
+
const sdk = { apiError, notify, adapters };
|
|
2817
3191
|
apiErrorCenter = new ApiErrorCenter();
|
|
2818
3192
|
if (config.onApiError) {
|
|
2819
3193
|
apiErrorCenter.use((error, _ctx, next) => {
|
|
2820
|
-
_optionalChain([config, 'access',
|
|
3194
|
+
_optionalChain([config, 'access', _279 => _279.onApiError, 'optionalCall', _280 => _280(error)]);
|
|
2821
3195
|
return next();
|
|
2822
3196
|
});
|
|
2823
3197
|
}
|
|
@@ -2838,38 +3212,38 @@ function initSDK(config) {
|
|
|
2838
3212
|
};
|
|
2839
3213
|
wsStatusOffs.push(
|
|
2840
3214
|
api.ws.on("__open__" /* OPEN */, () => {
|
|
2841
|
-
emitStatus({ state: "connected", readyState: _optionalChain([api, 'optionalAccess',
|
|
3215
|
+
emitStatus({ state: "connected", readyState: _optionalChain([api, 'optionalAccess', _281 => _281.ws, 'optionalAccess', _282 => _282.state]) });
|
|
2842
3216
|
})
|
|
2843
3217
|
);
|
|
2844
3218
|
wsStatusOffs.push(
|
|
2845
3219
|
api.ws.on("__close__" /* CLOSE */, (e) => {
|
|
2846
3220
|
emitStatus({
|
|
2847
3221
|
state: "disconnected",
|
|
2848
|
-
code: _optionalChain([e, 'optionalAccess',
|
|
2849
|
-
reason: _optionalChain([e, 'optionalAccess',
|
|
2850
|
-
readyState: _optionalChain([api, 'optionalAccess',
|
|
3222
|
+
code: _optionalChain([e, 'optionalAccess', _283 => _283.code]),
|
|
3223
|
+
reason: _optionalChain([e, 'optionalAccess', _284 => _284.reason]),
|
|
3224
|
+
readyState: _optionalChain([api, 'optionalAccess', _285 => _285.ws, 'optionalAccess', _286 => _286.state])
|
|
2851
3225
|
});
|
|
2852
3226
|
})
|
|
2853
3227
|
);
|
|
2854
3228
|
wsStatusOffs.push(
|
|
2855
3229
|
api.ws.on("__error__" /* ERROR */, (e) => {
|
|
2856
|
-
emitStatus({ state: "error", error: e, readyState: _optionalChain([api, 'optionalAccess',
|
|
3230
|
+
emitStatus({ state: "error", error: e, readyState: _optionalChain([api, 'optionalAccess', _287 => _287.ws, 'optionalAccess', _288 => _288.state]) });
|
|
2857
3231
|
})
|
|
2858
3232
|
);
|
|
2859
3233
|
wsStatusOffs.push(
|
|
2860
3234
|
api.ws.on("__reconnecting__" /* RECONNECTING */, (e) => {
|
|
2861
3235
|
emitStatus({
|
|
2862
3236
|
state: "reconnecting",
|
|
2863
|
-
attempt: _optionalChain([e, 'optionalAccess',
|
|
2864
|
-
maxRetries: _optionalChain([e, 'optionalAccess',
|
|
2865
|
-
interval: _optionalChain([e, 'optionalAccess',
|
|
2866
|
-
readyState: _optionalChain([api, 'optionalAccess',
|
|
3237
|
+
attempt: _optionalChain([e, 'optionalAccess', _289 => _289.attempt]),
|
|
3238
|
+
maxRetries: _optionalChain([e, 'optionalAccess', _290 => _290.maxRetries]),
|
|
3239
|
+
interval: _optionalChain([e, 'optionalAccess', _291 => _291.interval]),
|
|
3240
|
+
readyState: _optionalChain([api, 'optionalAccess', _292 => _292.ws, 'optionalAccess', _293 => _293.state])
|
|
2867
3241
|
});
|
|
2868
3242
|
})
|
|
2869
3243
|
);
|
|
2870
3244
|
wsStatusOffs.push(
|
|
2871
3245
|
api.ws.on("__reconnect_failed__" /* RECONNECT_FAILED */, () => {
|
|
2872
|
-
emitStatus({ state: "reconnect_failed", readyState: _optionalChain([api, 'optionalAccess',
|
|
3246
|
+
emitStatus({ state: "reconnect_failed", readyState: _optionalChain([api, 'optionalAccess', _294 => _294.ws, 'optionalAccess', _295 => _295.state]) });
|
|
2873
3247
|
})
|
|
2874
3248
|
);
|
|
2875
3249
|
emitStatus({
|
|
@@ -2889,6 +3263,7 @@ function initSDK(config) {
|
|
|
2889
3263
|
void apiErrorCenter.emit(apiErr, "ws");
|
|
2890
3264
|
}
|
|
2891
3265
|
});
|
|
3266
|
+
setWsAdapterRpc(rpc);
|
|
2892
3267
|
if (config.ws) {
|
|
2893
3268
|
sdk.rpc = rpc;
|
|
2894
3269
|
setRpcClient(rpc);
|
|
@@ -2905,13 +3280,14 @@ function initSDK(config) {
|
|
|
2905
3280
|
void apiErrorCenter.emit(error, "unified");
|
|
2906
3281
|
},
|
|
2907
3282
|
interceptors: [
|
|
2908
|
-
..._optionalChain([config, 'access',
|
|
3283
|
+
..._optionalChain([config, 'access', _296 => _296.auth, 'optionalAccess', _297 => _297.getToken]) ? [createAuthInterceptor({ getToken: config.auth.getToken })] : [],
|
|
2909
3284
|
...config.logger ? [createLogInterceptor({ logger: config.logger, level: "debug" })] : []
|
|
2910
3285
|
]
|
|
2911
3286
|
}
|
|
2912
3287
|
);
|
|
3288
|
+
setGrpcAdapterClient(sdk.client);
|
|
2913
3289
|
setUnifiedClient(sdk.client);
|
|
2914
|
-
if (_optionalChain([config, 'access',
|
|
3290
|
+
if (_optionalChain([config, 'access', _298 => _298.grpc, 'optionalAccess', _299 => _299.baseUrl])) {
|
|
2915
3291
|
const legacyPromise = Promise.resolve().then(() => _interopRequireWildcard(require("./legacy-CO3UUF6P.cjs"))).then((m) => m.createLegacyServices(api.grpc));
|
|
2916
3292
|
const loadLegacy = () => legacyPromise;
|
|
2917
3293
|
sdk.auth = createLazyObject(
|
|
@@ -3036,11 +3412,11 @@ function createApiServiceClient(service) {
|
|
|
3036
3412
|
return requestApi({
|
|
3037
3413
|
service,
|
|
3038
3414
|
functionName: prop,
|
|
3039
|
-
transport: _optionalChain([normalized, 'optionalAccess',
|
|
3415
|
+
transport: _optionalChain([normalized, 'optionalAccess', _300 => _300.transport]),
|
|
3040
3416
|
requestParam: payload,
|
|
3041
|
-
wsOptions: _optionalChain([normalized, 'optionalAccess',
|
|
3042
|
-
callOptions: _optionalChain([normalized, 'optionalAccess',
|
|
3043
|
-
meta: _optionalChain([normalized, 'optionalAccess',
|
|
3417
|
+
wsOptions: _optionalChain([normalized, 'optionalAccess', _301 => _301.wsOptions]),
|
|
3418
|
+
callOptions: _optionalChain([normalized, 'optionalAccess', _302 => _302.callOptions]),
|
|
3419
|
+
meta: _optionalChain([normalized, 'optionalAccess', _303 => _303.meta])
|
|
3044
3420
|
});
|
|
3045
3421
|
});
|
|
3046
3422
|
};
|
|
@@ -3062,5 +3438,6 @@ function createApiServiceClient(service) {
|
|
|
3062
3438
|
|
|
3063
3439
|
|
|
3064
3440
|
|
|
3065
|
-
|
|
3441
|
+
|
|
3442
|
+
exports.adapters = adapters; exports.apiError = apiError; exports.callApi = requestApi; exports.createFetchGuid = createFetchGuid; exports.destroySDK = destroySDK; exports.fetchGuid = fetchGuid; exports.getSDK = getSDK; exports.getWsSnapshot = getWsSnapshot; exports.initSDK = initSDK; exports.notify = notify; exports.requestApi = requestApi; exports.requestApiSpec = requestApi; exports.setUniqueKeyStorage = setUniqueKeyStorage; exports.webStorage = webStorage;
|
|
3066
3443
|
//# sourceMappingURL=index.cjs.map
|