upshift-config 0.5.14
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/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './fetcher';
|
|
2
|
+
export * from './base.class';
|
|
3
|
+
export * from './attribution';
|
|
4
|
+
export * from './auth';
|
|
5
|
+
export * from './logger';
|
|
6
|
+
export * from './analytics';
|
|
7
|
+
export * from './version-check';
|
|
8
|
+
export * from './errors';
|
|
9
|
+
export * from './constants/adapters';
|
|
10
|
+
export * from './constants/core';
|
|
11
|
+
export * from './constants/web3';
|
|
12
|
+
export * from './constants/vaults';
|
|
13
|
+
export * from './constants/swap-router';
|
|
14
|
+
export * from './helpers/web3';
|
|
15
|
+
export * from './helpers/multicall';
|
|
16
|
+
export * from './helpers/vaults';
|
|
17
|
+
export * from './helpers/chain-error';
|
|
18
|
+
export * from './helpers/chain-support';
|
|
19
|
+
export * from './helpers/core';
|
|
20
|
+
export * from './helpers/adapters';
|
|
21
|
+
export * from './helpers/signer';
|
|
22
|
+
export * from './helpers/swap-router';
|
|
23
|
+
export * from './helpers/revert-decode';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fetcher"), exports);
|
|
18
|
+
__exportStar(require("./base.class"), exports);
|
|
19
|
+
__exportStar(require("./attribution"), exports);
|
|
20
|
+
__exportStar(require("./auth"), exports);
|
|
21
|
+
__exportStar(require("./logger"), exports);
|
|
22
|
+
__exportStar(require("./analytics"), exports);
|
|
23
|
+
__exportStar(require("./version-check"), exports);
|
|
24
|
+
__exportStar(require("./errors"), exports);
|
|
25
|
+
__exportStar(require("./constants/adapters"), exports);
|
|
26
|
+
__exportStar(require("./constants/core"), exports);
|
|
27
|
+
__exportStar(require("./constants/web3"), exports);
|
|
28
|
+
__exportStar(require("./constants/vaults"), exports);
|
|
29
|
+
__exportStar(require("./constants/swap-router"), exports);
|
|
30
|
+
__exportStar(require("./helpers/web3"), exports);
|
|
31
|
+
__exportStar(require("./helpers/multicall"), exports);
|
|
32
|
+
__exportStar(require("./helpers/vaults"), exports);
|
|
33
|
+
__exportStar(require("./helpers/chain-error"), exports);
|
|
34
|
+
__exportStar(require("./helpers/chain-support"), exports);
|
|
35
|
+
__exportStar(require("./helpers/core"), exports);
|
|
36
|
+
__exportStar(require("./helpers/adapters"), exports);
|
|
37
|
+
__exportStar(require("./helpers/signer"), exports);
|
|
38
|
+
__exportStar(require("./helpers/swap-router"), exports);
|
|
39
|
+
__exportStar(require("./helpers/revert-decode"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry-compatible logger shape — `@sentry/browser` can be passed directly.
|
|
3
|
+
*/
|
|
4
|
+
export type SDKLogger = {
|
|
5
|
+
setTag: (key: string, value: string) => void;
|
|
6
|
+
captureException: (err: unknown, context?: Record<string, any>) => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Minimal breadcrumb shape forwarded to the internal Sentry sink. Mirrors the
|
|
10
|
+
* subset of Sentry's `Breadcrumb` the SDK populates, kept local so the logger
|
|
11
|
+
* stays decoupled from `@sentry/*` — and, more importantly, so it never has to
|
|
12
|
+
* import the analytics layer (which imports the logger, and would otherwise
|
|
13
|
+
* form a cycle; see CLAUDE.md §9).
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface SDKBreadcrumb {
|
|
18
|
+
/** Breadcrumb grouping key. Always `'sdk.logger'` for logger-sourced crumbs. */
|
|
19
|
+
category: string;
|
|
20
|
+
/** Short, low-cardinality label — the call-site tag passed to `Logger.log.*`. */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Severity. Logger warnings map to `'warning'`. */
|
|
23
|
+
level: 'info' | 'warning' | 'error';
|
|
24
|
+
/** Already-sanitized structured context. */
|
|
25
|
+
data?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The SDK's own always-on Sentry sink, wired by `initializeSentry` when
|
|
29
|
+
* analytics is enabled and cleared by `resetAnalytics`. This is deliberately
|
|
30
|
+
* distinct from the integrator-pluggable {@link SDKLogger} / {@link ILogger}
|
|
31
|
+
* slots: those belong to the consuming application, this one is the SDK's
|
|
32
|
+
* internal bridge so its diagnostics reach the partner-usage dashboard without
|
|
33
|
+
* the integrator having to wire anything.
|
|
34
|
+
*
|
|
35
|
+
* Severity policy (implemented in `analytics/sentry.ts`): `error` is captured
|
|
36
|
+
* as a Sentry issue via `captureException`; `warn` becomes a breadcrumb that
|
|
37
|
+
* rides along with the next captured event. `info` is intentionally not
|
|
38
|
+
* forwarded — method-call breadcrumbs from `instrumentClass` already cover the
|
|
39
|
+
* happy path, and forwarding every info line would only add noise/cost.
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export interface SDKSentrySink {
|
|
44
|
+
/** Forward a (pre-sanitized) error to Sentry as an issue. */
|
|
45
|
+
captureException: (error: unknown, context?: Record<string, unknown>) => void;
|
|
46
|
+
/** Forward a (pre-sanitized) breadcrumb to the active Sentry scope. */
|
|
47
|
+
addBreadcrumb: (breadcrumb: SDKBreadcrumb) => void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Structured logger interface (debug/info/warn/error). Sanitization runs
|
|
51
|
+
* before any method here is invoked, so implementations needn't scrub secrets.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* Logger.setStructuredLogger({
|
|
55
|
+
* info: (tag, ctx) => pino.info({ tag, ...ctx }),
|
|
56
|
+
* warn: (tag, ctx) => pino.warn({ tag, ...ctx }),
|
|
57
|
+
* error: (tag, err, ctx) => pino.error({ tag, err, ...ctx }),
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export interface ILogger {
|
|
62
|
+
debug?: (tag: string, context?: Record<string, unknown>) => void;
|
|
63
|
+
info?: (tag: string, context?: Record<string, unknown>) => void;
|
|
64
|
+
warn?: (tag: string, context?: Record<string, unknown>) => void;
|
|
65
|
+
error: (tag: string, error: unknown, context?: Record<string, unknown>) => void;
|
|
66
|
+
}
|
|
67
|
+
declare function setLogger(customLogger: SDKLogger): void;
|
|
68
|
+
/** Plug in an `ILogger`. Independent of `setLogger`; pass `null` to clear. */
|
|
69
|
+
declare function setStructuredLogger(custom: ILogger | null): void;
|
|
70
|
+
declare function getLogger(): SDKLogger | null;
|
|
71
|
+
declare function getStructuredLogger(): ILogger | null;
|
|
72
|
+
/**
|
|
73
|
+
* Wire (or clear, with `null`) the SDK's internal Sentry sink. Called by
|
|
74
|
+
* `initializeSentry` after a successful Sentry init, and reset by
|
|
75
|
+
* `resetAnalytics`. Not part of the integrator-facing API — applications wire
|
|
76
|
+
* their own logging through {@link setLogger} / {@link setStructuredLogger}.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
declare function setSentrySink(sink: SDKSentrySink | null): void;
|
|
81
|
+
declare function setDevMode(devMode: boolean): void;
|
|
82
|
+
declare function isDevMode(): boolean;
|
|
83
|
+
declare const Logger: {
|
|
84
|
+
setLogger: typeof setLogger;
|
|
85
|
+
setStructuredLogger: typeof setStructuredLogger;
|
|
86
|
+
setSentrySink: typeof setSentrySink;
|
|
87
|
+
getLogger: typeof getLogger;
|
|
88
|
+
getStructuredLogger: typeof getStructuredLogger;
|
|
89
|
+
setDevMode: typeof setDevMode;
|
|
90
|
+
isDevMode: typeof isDevMode;
|
|
91
|
+
log: {
|
|
92
|
+
info: (tag: string, ...args: any[]) => void;
|
|
93
|
+
warn: (tag: string, ...args: any[]) => void;
|
|
94
|
+
error: (tag: string, error: unknown, context?: Record<string, any>) => void;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
import * as slack from './slack';
|
|
98
|
+
export { slack as Slack, Logger };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Logger = exports.Slack = void 0;
|
|
37
|
+
const sanitize_1 = require("../analytics/sanitize");
|
|
38
|
+
let logger = null;
|
|
39
|
+
let structuredLogger = null;
|
|
40
|
+
let sentrySink = null;
|
|
41
|
+
let isDev = false;
|
|
42
|
+
function setLogger(customLogger) {
|
|
43
|
+
logger = customLogger;
|
|
44
|
+
}
|
|
45
|
+
/** Plug in an `ILogger`. Independent of `setLogger`; pass `null` to clear. */
|
|
46
|
+
function setStructuredLogger(custom) {
|
|
47
|
+
structuredLogger = custom;
|
|
48
|
+
}
|
|
49
|
+
function getLogger() {
|
|
50
|
+
return logger;
|
|
51
|
+
}
|
|
52
|
+
function getStructuredLogger() {
|
|
53
|
+
return structuredLogger;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Wire (or clear, with `null`) the SDK's internal Sentry sink. Called by
|
|
57
|
+
* `initializeSentry` after a successful Sentry init, and reset by
|
|
58
|
+
* `resetAnalytics`. Not part of the integrator-facing API — applications wire
|
|
59
|
+
* their own logging through {@link setLogger} / {@link setStructuredLogger}.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
function setSentrySink(sink) {
|
|
64
|
+
sentrySink = sink;
|
|
65
|
+
}
|
|
66
|
+
function setDevMode(devMode) {
|
|
67
|
+
isDev = devMode;
|
|
68
|
+
}
|
|
69
|
+
function isDevMode() {
|
|
70
|
+
return isDev;
|
|
71
|
+
}
|
|
72
|
+
/** Internal logger: DEV mode → console; production → SDKLogger. Sanitized either way. */
|
|
73
|
+
const log = {
|
|
74
|
+
info: (tag, ...args) => {
|
|
75
|
+
const safeArgs = args.map((a) => (0, sanitize_1.sanitizeForLogging)(a));
|
|
76
|
+
if (isDev) {
|
|
77
|
+
console.log(`[${tag}]`, ...safeArgs);
|
|
78
|
+
}
|
|
79
|
+
structuredLogger?.info?.(tag, structuredContext(safeArgs));
|
|
80
|
+
},
|
|
81
|
+
warn: (tag, ...args) => {
|
|
82
|
+
const safeArgs = args.map((a) => (0, sanitize_1.sanitizeForLogging)(a));
|
|
83
|
+
if (isDev) {
|
|
84
|
+
console.warn(`[${tag}]`, ...safeArgs);
|
|
85
|
+
}
|
|
86
|
+
logger?.setTag('warning', tag);
|
|
87
|
+
structuredLogger?.warn?.(tag, structuredContext(safeArgs));
|
|
88
|
+
// Warnings ride along as breadcrumbs on the next captured event rather
|
|
89
|
+
// than becoming standalone issues — keeps Sentry volume bounded (see the
|
|
90
|
+
// severity policy on SDKSentrySink).
|
|
91
|
+
sentrySink?.addBreadcrumb({
|
|
92
|
+
category: 'sdk.logger',
|
|
93
|
+
level: 'warning',
|
|
94
|
+
message: tag,
|
|
95
|
+
data: structuredContext(safeArgs),
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
error: (tag, error, context) => {
|
|
99
|
+
const safeError = (0, sanitize_1.sanitizeError)(error);
|
|
100
|
+
const safeContext = context
|
|
101
|
+
? (0, sanitize_1.sanitizeForLogging)(context)
|
|
102
|
+
: undefined;
|
|
103
|
+
if (isDev) {
|
|
104
|
+
console.error(`[${tag}]`, safeError);
|
|
105
|
+
}
|
|
106
|
+
logger?.captureException(safeError, { tag, ...safeContext });
|
|
107
|
+
structuredLogger?.error(tag, safeError, safeContext);
|
|
108
|
+
// The SDK's own bridge to Sentry: errors become issues. `safeError` /
|
|
109
|
+
// `safeContext` are already sanitized above, so the sink forwards as-is.
|
|
110
|
+
sentrySink?.captureException(safeError, { tag, ...safeContext });
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Pino-friendly shape: if the first arg is a plain object, pass it through
|
|
115
|
+
* (with subsequent args as `extras`); otherwise wrap as `{ args }`.
|
|
116
|
+
*/
|
|
117
|
+
function structuredContext(args) {
|
|
118
|
+
if (args.length === 0)
|
|
119
|
+
return undefined;
|
|
120
|
+
const [first, ...rest] = args;
|
|
121
|
+
if (first &&
|
|
122
|
+
typeof first === 'object' &&
|
|
123
|
+
!Array.isArray(first) &&
|
|
124
|
+
!(first instanceof Error)) {
|
|
125
|
+
return rest.length === 0
|
|
126
|
+
? first
|
|
127
|
+
: { ...first, extras: rest };
|
|
128
|
+
}
|
|
129
|
+
return { args };
|
|
130
|
+
}
|
|
131
|
+
const Logger = {
|
|
132
|
+
setLogger,
|
|
133
|
+
setStructuredLogger,
|
|
134
|
+
setSentrySink,
|
|
135
|
+
getLogger,
|
|
136
|
+
getStructuredLogger,
|
|
137
|
+
setDevMode,
|
|
138
|
+
isDevMode,
|
|
139
|
+
log,
|
|
140
|
+
};
|
|
141
|
+
exports.Logger = Logger;
|
|
142
|
+
const slack = __importStar(require("./slack"));
|
|
143
|
+
exports.Slack = slack;
|
|
144
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default Slack webhook URL for logging errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_SLACK_WEBHOOK_URL = "T04CM84GAV6/B0A2DS3ST8C/FLtOA3Jna3FN7UO4DoGxHfhG";
|
|
5
|
+
declare function error(options: {
|
|
6
|
+
title: string;
|
|
7
|
+
error: string;
|
|
8
|
+
poolAddress: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
slackWebookUrl: string;
|
|
11
|
+
address?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
export declare const SLACK: {
|
|
14
|
+
error: typeof error;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SLACK = exports.DEFAULT_SLACK_WEBHOOK_URL = void 0;
|
|
4
|
+
const core_1 = require("../helpers/core");
|
|
5
|
+
const explorer_link_1 = require("../helpers/explorer-link");
|
|
6
|
+
const sanitize_1 = require("../analytics/sanitize");
|
|
7
|
+
/**
|
|
8
|
+
* The default Slack webhook URL for logging errors.
|
|
9
|
+
*/
|
|
10
|
+
exports.DEFAULT_SLACK_WEBHOOK_URL = 'T04CM84GAV6/B0A2DS3ST8C/FLtOA3Jna3FN7UO4DoGxHfhG';
|
|
11
|
+
function error(options) {
|
|
12
|
+
const { title, error, poolAddress, chainId, slackWebookUrl, address } = options;
|
|
13
|
+
if (!slackWebookUrl) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!error) {
|
|
17
|
+
console.error('#Slack.error: error is undefined');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!poolAddress) {
|
|
21
|
+
console.error('#Slack.error: poolAddress is undefined');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!title) {
|
|
25
|
+
console.error('#Slack.error: type is undefined');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!address) {
|
|
29
|
+
console.error('#Slack.error: address is undefined');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!chainId) {
|
|
33
|
+
console.error('#Slack.error: chainId is undefined');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
(async () => {
|
|
37
|
+
const webhookUrl = `https://hooks.slack.com/services/${slackWebookUrl}`;
|
|
38
|
+
const safeError = (0, sanitize_1.sanitizeString)(String(error));
|
|
39
|
+
const safeTitle = (0, sanitize_1.sanitizeString)(String(title));
|
|
40
|
+
const data = {
|
|
41
|
+
text: `*Error: ${safeTitle}*\n${new Date().toUTCString()}\n\nPool: [${(0, core_1.truncate)(poolAddress)}](${(0, explorer_link_1.explorerLink)(poolAddress, chainId, 'address')})\n\n\nError: ${safeError}`,
|
|
42
|
+
};
|
|
43
|
+
const res = await fetch(webhookUrl, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body: JSON.stringify(data),
|
|
46
|
+
signal: AbortSignal.timeout(5000),
|
|
47
|
+
});
|
|
48
|
+
if (res?.status === 200)
|
|
49
|
+
console.log('#Slack.error: successfully sent');
|
|
50
|
+
else
|
|
51
|
+
console.error('#Slack.error:', res.status, res.statusText);
|
|
52
|
+
})().catch((e) => console.error('#Slack.error:', (0, sanitize_1.sanitizeString)(String(e?.message ?? e))));
|
|
53
|
+
}
|
|
54
|
+
exports.SLACK = {
|
|
55
|
+
error,
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=slack.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IVaultMetadata } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetch vault metadata from the upshift API.
|
|
4
|
+
* Returns metadata including symbol, subgraph URL, and address for all vaults.
|
|
5
|
+
* @param options Request options including headers
|
|
6
|
+
* @returns Vault metadata object keyed by lowercase symbol
|
|
7
|
+
*/
|
|
8
|
+
export declare function fetchVaultMetadata(opts?: {
|
|
9
|
+
options?: {
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
}): Promise<IVaultMetadata>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVaultMetadata = fetchVaultMetadata;
|
|
4
|
+
const cache_1 = require("./cache");
|
|
5
|
+
const core_1 = require("./constants/core");
|
|
6
|
+
const logger_1 = require("./logger");
|
|
7
|
+
/**
|
|
8
|
+
* Fetch vault metadata from the upshift API.
|
|
9
|
+
* Returns metadata including symbol, subgraph URL, and address for all vaults.
|
|
10
|
+
* @param options Request options including headers
|
|
11
|
+
* @returns Vault metadata object keyed by lowercase symbol
|
|
12
|
+
*/
|
|
13
|
+
async function fetchVaultMetadata(opts) {
|
|
14
|
+
const { options } = opts || {};
|
|
15
|
+
try {
|
|
16
|
+
const cacheKey = 'vaults_metadata';
|
|
17
|
+
if (cache_1.CACHE.has(cacheKey)) {
|
|
18
|
+
return cache_1.CACHE.get(cacheKey);
|
|
19
|
+
}
|
|
20
|
+
const response = await fetch(`${core_1.WEBSERVER_URL['upshift']}${core_1.WEBSERVER_ENDPOINTS.upshift.vaults.metadata}`, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/json',
|
|
24
|
+
accept: 'application/json',
|
|
25
|
+
'x-request-client': 'august-sdk',
|
|
26
|
+
...options?.headers,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(`Failed to fetch vault metadata: ${response.statusText}`);
|
|
31
|
+
}
|
|
32
|
+
const metadata = await response.json();
|
|
33
|
+
cache_1.CACHE.set(cacheKey, metadata, { ttl: 10 * 60 * 1000 });
|
|
34
|
+
return metadata;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
logger_1.Logger.log.error('getVaultMetadata', e);
|
|
38
|
+
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
39
|
+
throw new Error(`#getVaultMetadata::${errorMessage}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=vault-metadata.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort version check that nudges integrators when a newer
|
|
3
|
+
* `@augustdigital/sdk` is available on npm.
|
|
4
|
+
*
|
|
5
|
+
* Design constraints (all kept narrow on purpose):
|
|
6
|
+
* - **No network call in production builds.** Most integrators ship the
|
|
7
|
+
* SDK to end users in the browser; surprise registry pings on user page
|
|
8
|
+
* loads are unacceptable. The check only fires when
|
|
9
|
+
* `NODE_ENV !== 'production'` (i.e. local dev / CI environments).
|
|
10
|
+
* - **Opt-out is supported in two places.** `AUGUST_SDK_DISABLE_VERSION_CHECK`
|
|
11
|
+
* env var (set in CI to silence noise) or `versionCheck: { enabled: false }`
|
|
12
|
+
* on the SDK constructor (programmatic opt-out, e.g. in your own libs
|
|
13
|
+
* that wrap the SDK).
|
|
14
|
+
* - **Fire-and-forget; never blocks construction.** The SDK constructor
|
|
15
|
+
* must return synchronously. We schedule the check on the microtask
|
|
16
|
+
* queue, abort after 5s, and swallow every error.
|
|
17
|
+
* - **Once per session.** A module-level guard prevents repeated registry
|
|
18
|
+
* hits when callers spin up multiple `AugustSDK` instances.
|
|
19
|
+
* - **No new dependency.** Semver comparison is a tiny hand-rolled helper
|
|
20
|
+
* rather than pulling in the `semver` package.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Compare two numeric-dotted version strings. Returns:
|
|
24
|
+
* - positive integer if `a > b`
|
|
25
|
+
* - negative integer if `a < b`
|
|
26
|
+
* - 0 if equal
|
|
27
|
+
*
|
|
28
|
+
* Pre-release suffixes (`-beta`, `-rc.1`) are stripped before comparison —
|
|
29
|
+
* we always treat any pre-release as equal to its base version. That keeps
|
|
30
|
+
* the comparison logic small and avoids false positives where an integrator
|
|
31
|
+
* on `4.27.4-beta.0` would otherwise be told to upgrade to the stable
|
|
32
|
+
* `4.27.3` they pre-released past.
|
|
33
|
+
*/
|
|
34
|
+
export declare function compareSemver(a: string, b: string): number;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration knob exposed on `IAugustBase.versionCheck`. Defaulting to
|
|
37
|
+
* enabled keeps the nudge in front of integrators who haven't read the docs;
|
|
38
|
+
* setting `enabled: false` is the explicit opt-out for libraries that wrap
|
|
39
|
+
* the SDK and want their own update strategy.
|
|
40
|
+
*/
|
|
41
|
+
export interface IVersionCheckConfig {
|
|
42
|
+
/** Set to `false` to disable the registry check entirely. Default: `true`. */
|
|
43
|
+
enabled?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Kick off a best-effort version check. Always returns synchronously.
|
|
47
|
+
*
|
|
48
|
+
* @param config - Optional config from `IAugustBase.versionCheck`
|
|
49
|
+
*/
|
|
50
|
+
export declare function runVersionCheck(config?: IVersionCheckConfig): void;
|
|
51
|
+
/**
|
|
52
|
+
* Testing hook — resets the module-level guard so the check can run again
|
|
53
|
+
* in a fresh test case. Not part of the public API surface; kept here so
|
|
54
|
+
* unit tests don't have to monkey-patch internals.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function _resetVersionCheckForTests(): void;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Best-effort version check that nudges integrators when a newer
|
|
4
|
+
* `@augustdigital/sdk` is available on npm.
|
|
5
|
+
*
|
|
6
|
+
* Design constraints (all kept narrow on purpose):
|
|
7
|
+
* - **No network call in production builds.** Most integrators ship the
|
|
8
|
+
* SDK to end users in the browser; surprise registry pings on user page
|
|
9
|
+
* loads are unacceptable. The check only fires when
|
|
10
|
+
* `NODE_ENV !== 'production'` (i.e. local dev / CI environments).
|
|
11
|
+
* - **Opt-out is supported in two places.** `AUGUST_SDK_DISABLE_VERSION_CHECK`
|
|
12
|
+
* env var (set in CI to silence noise) or `versionCheck: { enabled: false }`
|
|
13
|
+
* on the SDK constructor (programmatic opt-out, e.g. in your own libs
|
|
14
|
+
* that wrap the SDK).
|
|
15
|
+
* - **Fire-and-forget; never blocks construction.** The SDK constructor
|
|
16
|
+
* must return synchronously. We schedule the check on the microtask
|
|
17
|
+
* queue, abort after 5s, and swallow every error.
|
|
18
|
+
* - **Once per session.** A module-level guard prevents repeated registry
|
|
19
|
+
* hits when callers spin up multiple `AugustSDK` instances.
|
|
20
|
+
* - **No new dependency.** Semver comparison is a tiny hand-rolled helper
|
|
21
|
+
* rather than pulling in the `semver` package.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.compareSemver = compareSemver;
|
|
25
|
+
exports.runVersionCheck = runVersionCheck;
|
|
26
|
+
exports._resetVersionCheckForTests = _resetVersionCheckForTests;
|
|
27
|
+
/** Module-level guard — flips to true after the first attempt. */
|
|
28
|
+
let hasRunCheck = false;
|
|
29
|
+
/** Public package name on npm — also the registry-API path component. */
|
|
30
|
+
const NPM_PACKAGE = '@augustdigital/sdk';
|
|
31
|
+
const REGISTRY_URL = `https://registry.npmjs.org/${NPM_PACKAGE}/latest`;
|
|
32
|
+
/** Timeout for the registry request. 5s is generous; faster failures stay silent. */
|
|
33
|
+
const REQUEST_TIMEOUT_MS = 5_000;
|
|
34
|
+
/**
|
|
35
|
+
* Read the current installed SDK version from the generated `version.ts`
|
|
36
|
+
* shim. Returns `null` when running from source (the file is gitignored and
|
|
37
|
+
* only emitted at publish time) — that's the signal to skip the check, since
|
|
38
|
+
* we have nothing meaningful to compare against.
|
|
39
|
+
*/
|
|
40
|
+
function getInstalledVersion() {
|
|
41
|
+
try {
|
|
42
|
+
// The require path is resolved relative to the compiled .js location,
|
|
43
|
+
// so it picks up `core/analytics/version.js` when it exists.
|
|
44
|
+
const mod = require('./analytics/version');
|
|
45
|
+
const v = mod.SDK_VERSION;
|
|
46
|
+
if (!v || v === 'development')
|
|
47
|
+
return null;
|
|
48
|
+
return v;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Read an environment variable in a way that's safe in both Node and the
|
|
56
|
+
* browser. `process` is typically undefined in browser bundles; even when
|
|
57
|
+
* it's stubbed by a bundler, `process.env` may be a frozen object that
|
|
58
|
+
* throws on missing-key access in some setups — try/catch covers that too.
|
|
59
|
+
*/
|
|
60
|
+
function readEnv(name) {
|
|
61
|
+
try {
|
|
62
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
63
|
+
return process.env[name];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Bundlers occasionally throw on `process.env` access. Treat as unset.
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compare two numeric-dotted version strings. Returns:
|
|
73
|
+
* - positive integer if `a > b`
|
|
74
|
+
* - negative integer if `a < b`
|
|
75
|
+
* - 0 if equal
|
|
76
|
+
*
|
|
77
|
+
* Pre-release suffixes (`-beta`, `-rc.1`) are stripped before comparison —
|
|
78
|
+
* we always treat any pre-release as equal to its base version. That keeps
|
|
79
|
+
* the comparison logic small and avoids false positives where an integrator
|
|
80
|
+
* on `4.27.4-beta.0` would otherwise be told to upgrade to the stable
|
|
81
|
+
* `4.27.3` they pre-released past.
|
|
82
|
+
*/
|
|
83
|
+
function compareSemver(a, b) {
|
|
84
|
+
const stripPre = (v) => v.split('-')[0];
|
|
85
|
+
const parse = (v) => stripPre(v)
|
|
86
|
+
.split('.')
|
|
87
|
+
.map((part) => {
|
|
88
|
+
const n = Number.parseInt(part, 10);
|
|
89
|
+
return Number.isFinite(n) ? n : 0;
|
|
90
|
+
});
|
|
91
|
+
const aParts = parse(a);
|
|
92
|
+
const bParts = parse(b);
|
|
93
|
+
const len = Math.max(aParts.length, bParts.length);
|
|
94
|
+
for (let i = 0; i < len; i++) {
|
|
95
|
+
const av = aParts[i] ?? 0;
|
|
96
|
+
const bv = bParts[i] ?? 0;
|
|
97
|
+
if (av !== bv)
|
|
98
|
+
return av - bv;
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Kick off a best-effort version check. Always returns synchronously.
|
|
104
|
+
*
|
|
105
|
+
* @param config - Optional config from `IAugustBase.versionCheck`
|
|
106
|
+
*/
|
|
107
|
+
function runVersionCheck(config) {
|
|
108
|
+
if (hasRunCheck)
|
|
109
|
+
return;
|
|
110
|
+
hasRunCheck = true;
|
|
111
|
+
if (config?.enabled === false)
|
|
112
|
+
return;
|
|
113
|
+
// Skip in production builds. We treat *anything* other than "production"
|
|
114
|
+
// as eligible (development, test, staging) — those are the envs where a
|
|
115
|
+
// console warning is helpful, not annoying.
|
|
116
|
+
if (readEnv('NODE_ENV') === 'production')
|
|
117
|
+
return;
|
|
118
|
+
// Explicit env opt-out (useful in CI where the console output is noise).
|
|
119
|
+
if (readEnv('AUGUST_SDK_DISABLE_VERSION_CHECK'))
|
|
120
|
+
return;
|
|
121
|
+
const installed = getInstalledVersion();
|
|
122
|
+
// No version file = local development from source. Nothing to compare.
|
|
123
|
+
if (!installed)
|
|
124
|
+
return;
|
|
125
|
+
// `fetch` is guaranteed in Node 18+ and all modern browsers, but the SDK
|
|
126
|
+
// supports older Node deployments via the React/Telegram bot integration.
|
|
127
|
+
// Gracefully no-op when missing.
|
|
128
|
+
if (typeof fetch !== 'function')
|
|
129
|
+
return;
|
|
130
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
131
|
+
const timeoutId = controller
|
|
132
|
+
? setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
|
133
|
+
: null;
|
|
134
|
+
// Run on the microtask queue so construction stays synchronous. The void
|
|
135
|
+
// expression discards the promise — we explicitly don't await it.
|
|
136
|
+
void (async () => {
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch(REGISTRY_URL, {
|
|
139
|
+
signal: controller?.signal,
|
|
140
|
+
headers: { Accept: 'application/json' },
|
|
141
|
+
});
|
|
142
|
+
if (!res.ok)
|
|
143
|
+
return;
|
|
144
|
+
const body = (await res.json());
|
|
145
|
+
const latest = typeof body.version === 'string' ? body.version : null;
|
|
146
|
+
if (!latest)
|
|
147
|
+
return;
|
|
148
|
+
if (compareSemver(latest, installed) > 0) {
|
|
149
|
+
// Use console.warn so the message is visible at the default log
|
|
150
|
+
// level in most setups, but distinguishable from real errors. This is
|
|
151
|
+
// an integrator-facing nudge — Logger.log.warn would make it a
|
|
152
|
+
// prod-silent breadcrumb, defeating the purpose.
|
|
153
|
+
// biome-ignore lint/suspicious/noConsole: integrator-facing version nudge must surface in every environment; Logger.log.warn would make it a prod-silent breadcrumb.
|
|
154
|
+
console.warn([
|
|
155
|
+
`[${NPM_PACKAGE}] A newer version is available: ${installed} → ${latest}.`,
|
|
156
|
+
`Run \`pnpm up ${NPM_PACKAGE}\` (or your package manager's equivalent) to update.`,
|
|
157
|
+
`Silence this check with \`AUGUST_SDK_DISABLE_VERSION_CHECK=1\` or \`new AugustSDK({ versionCheck: { enabled: false }, ... })\`.`,
|
|
158
|
+
].join('\n'));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Network failure, aborted request, malformed JSON, frozen
|
|
163
|
+
// `console.warn`, etc. — every failure path stays silent. The check
|
|
164
|
+
// is purely an integrator-experience hint; it must never surface.
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
if (timeoutId)
|
|
168
|
+
clearTimeout(timeoutId);
|
|
169
|
+
}
|
|
170
|
+
})();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Testing hook — resets the module-level guard so the check can run again
|
|
174
|
+
* in a fresh test case. Not part of the public API surface; kept here so
|
|
175
|
+
* unit tests don't have to monkey-patch internals.
|
|
176
|
+
*
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
function _resetVersionCheckForTests() {
|
|
180
|
+
hasRunCheck = false;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=version-check.js.map
|