@upshiftfinance/sdk 0.0.0-stage → 0.1.0
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 +408 -2
- 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 +953 -0
- package/lib/abis/SwapRouter.js +1228 -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 +249 -0
- package/lib/adapters/evm/index.d.ts +539 -0
- package/lib/adapters/evm/index.js +656 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/confirm.d.ts +88 -0
- package/lib/adapters/solana/confirm.js +291 -0
- package/lib/adapters/solana/constants.d.ts +42 -0
- package/lib/adapters/solana/constants.js +59 -0
- package/lib/adapters/solana/getters.d.ts +42 -0
- package/lib/adapters/solana/getters.js +275 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +700 -0
- package/lib/adapters/solana/idl/vault-idl.js +2101 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.d.ts +795 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.js +1864 -0
- package/lib/adapters/solana/index.d.ts +372 -0
- package/lib/adapters/solana/index.js +459 -0
- package/lib/adapters/solana/pricing.d.ts +184 -0
- package/lib/adapters/solana/pricing.js +239 -0
- package/lib/adapters/solana/queue-hints.d.ts +29 -0
- package/lib/adapters/solana/queue-hints.js +59 -0
- package/lib/adapters/solana/queue.actions.d.ts +97 -0
- package/lib/adapters/solana/queue.actions.js +468 -0
- package/lib/adapters/solana/token-reads.d.ts +108 -0
- package/lib/adapters/solana/token-reads.js +145 -0
- package/lib/adapters/solana/types.d.ts +325 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +229 -0
- package/lib/adapters/solana/utils.js +773 -0
- package/lib/adapters/solana/vault.actions.d.ts +140 -0
- package/lib/adapters/solana/vault.actions.js +657 -0
- package/lib/adapters/solana/withdrawal-queue.d.ts +125 -0
- package/lib/adapters/solana/withdrawal-queue.js +301 -0
- package/lib/adapters/stellar/actions.d.ts +41 -0
- package/lib/adapters/stellar/actions.js +126 -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 +126 -0
- package/lib/adapters/stellar/index.js +187 -0
- package/lib/adapters/stellar/invocation.d.ts +55 -0
- package/lib/adapters/stellar/invocation.js +92 -0
- package/lib/adapters/stellar/soroban.d.ts +131 -0
- package/lib/adapters/stellar/soroban.js +617 -0
- package/lib/adapters/stellar/submit.d.ts +42 -0
- package/lib/adapters/stellar/submit.js +195 -0
- package/lib/adapters/stellar/types.d.ts +57 -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 +1 -0
- package/lib/adapters/sui/constants.js +9 -0
- package/lib/adapters/sui/getters.d.ts +24 -0
- package/lib/adapters/sui/getters.js +134 -0
- package/lib/adapters/sui/index.d.ts +53 -0
- package/lib/adapters/sui/index.js +96 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +115 -0
- package/lib/adapters/sui/types.d.ts +70 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +8 -0
- package/lib/adapters/sui/utils.js +17 -0
- package/lib/core/analytics/app-name.d.ts +27 -0
- package/lib/core/analytics/app-name.js +48 -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 +15 -0
- package/lib/core/analytics/constants.js +28 -0
- package/lib/core/analytics/env.d.ts +46 -0
- package/lib/core/analytics/env.js +147 -0
- package/lib/core/analytics/index.d.ts +39 -0
- package/lib/core/analytics/index.js +83 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +292 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +156 -0
- package/lib/core/analytics/metrics.d.ts +48 -0
- package/lib/core/analytics/metrics.js +142 -0
- package/lib/core/analytics/sanitize.d.ts +57 -0
- package/lib/core/analytics/sanitize.js +272 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +131 -0
- package/lib/core/analytics/sentry.d.ts +100 -0
- package/lib/core/analytics/sentry.js +696 -0
- package/lib/core/analytics/types.d.ts +55 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +55 -0
- package/lib/core/analytics/user-identity.js +218 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +159 -0
- package/lib/core/attribution.js +194 -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 +35 -0
- package/lib/core/base.class.d.ts +193 -0
- package/lib/core/base.class.js +163 -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 +162 -0
- package/lib/core/constants/core.js +281 -0
- package/lib/core/constants/swap-router.d.ts +180 -0
- package/lib/core/constants/swap-router.js +203 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +277 -0
- package/lib/core/constants/web3.d.ts +106 -0
- package/lib/core/constants/web3.js +251 -0
- package/lib/core/errors/index.d.ts +177 -0
- package/lib/core/errors/index.js +257 -0
- package/lib/core/fetcher.d.ts +237 -0
- package/lib/core/fetcher.js +1103 -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 +697 -0
- package/lib/core/helpers/chain-support.d.ts +98 -0
- package/lib/core/helpers/chain-support.js +139 -0
- package/lib/core/helpers/concurrency.d.ts +51 -0
- package/lib/core/helpers/concurrency.js +79 -0
- package/lib/core/helpers/core.d.ts +92 -0
- package/lib/core/helpers/core.js +368 -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 +61 -0
- package/lib/core/helpers/signer.js +184 -0
- package/lib/core/helpers/swap-router.d.ts +269 -0
- package/lib/core/helpers/swap-router.js +542 -0
- package/lib/core/helpers/vault-version.d.ts +24 -0
- package/lib/core/helpers/vault-version.js +83 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +241 -0
- package/lib/core/helpers/web3.d.ts +366 -0
- package/lib/core/helpers/web3.js +1034 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/curator-alert.d.ts +217 -0
- package/lib/core/logger/curator-alert.js +276 -0
- package/lib/core/logger/index.d.ts +99 -0
- package/lib/core/logger/index.js +163 -0
- package/lib/core/logger/slack.d.ts +49 -0
- package/lib/core/logger/slack.js +111 -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 +132 -0
- package/lib/evm/methods/crossChainVault.js +857 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +239 -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 +596 -0
- package/lib/main.js +681 -0
- package/lib/modules/api/fetcher.d.ts +108 -0
- package/lib/modules/api/fetcher.js +187 -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 +587 -0
- package/lib/modules/api/main.js +911 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +96 -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 +249 -0
- package/lib/modules/sub-accounts/main.js +211 -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 +84 -0
- package/lib/modules/vaults/adapter.helpers.js +202 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +357 -0
- package/lib/modules/vaults/getters.d.ts +1060 -0
- package/lib/modules/vaults/getters.js +4079 -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 +607 -0
- package/lib/modules/vaults/main.js +1687 -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 +406 -0
- package/lib/modules/vaults/read.actions.js +891 -0
- package/lib/modules/vaults/types.d.ts +149 -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 +153 -0
- package/lib/modules/vaults/utils.js +818 -0
- package/lib/modules/vaults/write.actions.d.ts +812 -0
- package/lib/modules/vaults/write.actions.js +2377 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +30154 -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 +50 -0
- package/lib/services/debank/utils.js +325 -0
- package/lib/services/layerzero/deposits.d.ts +55 -0
- package/lib/services/layerzero/deposits.js +174 -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 +33 -0
- package/lib/services/octavfi/fetcher.js +39 -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 +244 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +66 -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 +48 -0
- package/lib/services/subgraph/schema.js +87 -0
- package/lib/services/subgraph/vaults.d.ts +83 -0
- package/lib/services/subgraph/vaults.js +1282 -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/services/untangled/fetcher.d.ts +40 -0
- package/lib/services/untangled/fetcher.js +110 -0
- package/lib/services/untangled/index.d.ts +3 -0
- package/lib/services/untangled/index.js +20 -0
- package/lib/services/untangled/types.d.ts +83 -0
- package/lib/services/untangled/types.js +10 -0
- package/lib/services/untangled/utils.d.ts +91 -0
- package/lib/services/untangled/utils.js +339 -0
- package/lib/types/api.d.ts +498 -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 +150 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +84 -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 +886 -0
- package/lib/types/vaults.js +30 -0
- package/lib/types/web3.d.ts +81 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +730 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -3
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackApiCall = trackApiCall;
|
|
4
|
+
exports.trackNetworkSwitch = trackNetworkSwitch;
|
|
5
|
+
exports.trackKeyVerification = trackKeyVerification;
|
|
6
|
+
exports.getCacheStats = getCacheStats;
|
|
7
|
+
exports.resetCacheStats = resetCacheStats;
|
|
8
|
+
const chain_name_1 = require("./chain-name");
|
|
9
|
+
const sentry_runtime_1 = require("./sentry-runtime");
|
|
10
|
+
const sentry_1 = require("./sentry");
|
|
11
|
+
/**
|
|
12
|
+
* Track API response times and status.
|
|
13
|
+
*
|
|
14
|
+
* @param endpoint - The API endpoint called
|
|
15
|
+
* @param method - HTTP method used
|
|
16
|
+
* @param startTime - Start timestamp from performance.now()
|
|
17
|
+
* @param status - HTTP response status code (0 for network errors)
|
|
18
|
+
* @param server - Server identifier (production, staging, etc.)
|
|
19
|
+
*/
|
|
20
|
+
function trackApiCall(endpoint, method, startTime, status, server) {
|
|
21
|
+
if (!(0, sentry_1.isAnalyticsEnabled)())
|
|
22
|
+
return;
|
|
23
|
+
try {
|
|
24
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
25
|
+
if (!sdk)
|
|
26
|
+
return;
|
|
27
|
+
const duration = performance.now() - startTime;
|
|
28
|
+
// Normalize endpoint for aggregation (replace dynamic segments)
|
|
29
|
+
const normalizedEndpoint = normalizeEndpoint(endpoint);
|
|
30
|
+
// Add breadcrumb
|
|
31
|
+
sdk.addBreadcrumb({
|
|
32
|
+
category: 'api',
|
|
33
|
+
message: `${method} ${normalizedEndpoint}`,
|
|
34
|
+
level: status >= 400 || status === 0 ? 'error' : 'info',
|
|
35
|
+
data: {
|
|
36
|
+
endpoint: normalizedEndpoint,
|
|
37
|
+
method,
|
|
38
|
+
duration: Math.round(duration),
|
|
39
|
+
status,
|
|
40
|
+
server,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
sdk.setMeasurement('api.duration', duration, 'millisecond');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Silently fail - analytics should never break SDK
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Track chain/network switches for usage distribution analysis.
|
|
51
|
+
*
|
|
52
|
+
* @param chainId - The chain ID being switched to
|
|
53
|
+
*/
|
|
54
|
+
function trackNetworkSwitch(chainId) {
|
|
55
|
+
if (!(0, sentry_1.isAnalyticsEnabled)())
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
59
|
+
if (!sdk)
|
|
60
|
+
return;
|
|
61
|
+
const chainLabel = (0, chain_name_1.chainIdToTagValue)(chainId);
|
|
62
|
+
sdk.addBreadcrumb({
|
|
63
|
+
category: 'network',
|
|
64
|
+
message: `Switched to chain ${chainId} (${chainLabel})`,
|
|
65
|
+
level: 'info',
|
|
66
|
+
data: { chainId, chain: chainLabel },
|
|
67
|
+
});
|
|
68
|
+
sdk.setTag('sdk.chain', chainLabel);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Silently fail - analytics should never break SDK
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Track the outcome of an API-key verification check (e.g. `verifyUpshiftKey`).
|
|
76
|
+
* Records success/failure as a breadcrumb and a low-cardinality tag so
|
|
77
|
+
* verification failures are visible in the dashboard without leaking the key
|
|
78
|
+
* itself — callers must never pass the raw key value.
|
|
79
|
+
*
|
|
80
|
+
* @param keyType - Which key was verified (e.g. `'upshift'`)
|
|
81
|
+
* @param success - Whether the key was accepted
|
|
82
|
+
*/
|
|
83
|
+
function trackKeyVerification(keyType, success) {
|
|
84
|
+
if (!(0, sentry_1.isAnalyticsEnabled)())
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
88
|
+
if (!sdk)
|
|
89
|
+
return;
|
|
90
|
+
sdk.addBreadcrumb({
|
|
91
|
+
category: 'auth.verify',
|
|
92
|
+
message: `${keyType} key verification ${success ? 'succeeded' : 'failed'}`,
|
|
93
|
+
level: success ? 'info' : 'warning',
|
|
94
|
+
data: { keyType, success },
|
|
95
|
+
});
|
|
96
|
+
sdk.setTag('auth.last_verified_key_type', keyType);
|
|
97
|
+
sdk.setTag('auth.last_verification_result', success ? 'success' : 'failure');
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Silently fail - analytics should never break SDK
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Normalize endpoint URLs for aggregation.
|
|
105
|
+
* Replaces dynamic segments (addresses, IDs) with placeholders.
|
|
106
|
+
*
|
|
107
|
+
* @param endpoint - Raw endpoint URL
|
|
108
|
+
* @returns Normalized endpoint pattern
|
|
109
|
+
*/
|
|
110
|
+
function normalizeEndpoint(endpoint) {
|
|
111
|
+
return (endpoint
|
|
112
|
+
// Replace Ethereum addresses (0x + 40 hex chars)
|
|
113
|
+
.replace(/0x[a-fA-F0-9]{40}/g, ':address')
|
|
114
|
+
// Replace chain IDs (5+ digit numbers)
|
|
115
|
+
.replace(/\/\d{5,}/g, '/:chainId')
|
|
116
|
+
// Replace UUIDs
|
|
117
|
+
.replace(/[a-f0-9-]{36}/gi, ':uuid')
|
|
118
|
+
// Replace numeric IDs in paths
|
|
119
|
+
.replace(/\/\d+(?=\/|$)/g, '/:id'));
|
|
120
|
+
}
|
|
121
|
+
let cacheStats = { hits: 0, misses: 0, sets: 0 };
|
|
122
|
+
/**
|
|
123
|
+
* Cache statistics snapshot. The SDK never recorded cache hits, misses, or
|
|
124
|
+
* sets, so every field is always `0`.
|
|
125
|
+
*
|
|
126
|
+
* @deprecated Always returns zeros. Kept only for API compatibility and will
|
|
127
|
+
* be removed in the next major release; there is no replacement.
|
|
128
|
+
*/
|
|
129
|
+
function getCacheStats() {
|
|
130
|
+
return { ...cacheStats };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reset the cache statistics snapshot to zeros. The SDK never records any, so
|
|
134
|
+
* this has no observable effect.
|
|
135
|
+
*
|
|
136
|
+
* @deprecated Has no effect. Kept only for API compatibility and will be
|
|
137
|
+
* removed in the next major release; there is no replacement.
|
|
138
|
+
*/
|
|
139
|
+
function resetCacheStats() {
|
|
140
|
+
cacheStats = { hits: 0, misses: 0, sets: 0 };
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redact secrets from a free-form string (error messages, URLs, log lines).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* sanitizeString('Request failed: https://api.example.com/v1?api_key=abc123')
|
|
6
|
+
* // → 'Request failed: https://api.example.com/v1?api_key=[REDACTED]'
|
|
7
|
+
*/
|
|
8
|
+
export declare function sanitizeString(input: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Return a redacted clone of `err`. Preserves prototype (so `instanceof` checks
|
|
11
|
+
* keep working), `name`, all own properties (`code`, `status`, `correlationId`,
|
|
12
|
+
* …), and `cause`. Subclass constructors are NOT invoked — they may have
|
|
13
|
+
* positional signatures (`new UpshiftAuthError(code, message, opts)`) that would
|
|
14
|
+
* misalign if we naively passed the sanitized message as the first arg.
|
|
15
|
+
*
|
|
16
|
+
* Every write onto the clone goes through `Object.defineProperty` rather than
|
|
17
|
+
* assignment: the clone inherits `err`'s prototype, and some libraries make
|
|
18
|
+
* properties read-only there — `@solana/web3.js` defines `name` as non-writable
|
|
19
|
+
* on its error classes (`TransactionExpiredTimeoutError`, …). Assigning to an
|
|
20
|
+
* inherited non-writable property throws a `TypeError` in strict mode, which
|
|
21
|
+
* would escape from inside a caller's `catch` (e.g. `Logger.log.error`) and
|
|
22
|
+
* replace the error being reported. Defining an own property shadows the
|
|
23
|
+
* prototype's instead; each one is writable, configurable and enumerable,
|
|
24
|
+
* exactly as the plain assignment used to create it.
|
|
25
|
+
*
|
|
26
|
+
* @param err - Any caught value; non-`Error` values are returned unchanged.
|
|
27
|
+
* @returns A redacted clone for `Error` instances, otherwise `err` itself.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitizeError(err: unknown): unknown;
|
|
30
|
+
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|
|
31
|
+
export declare function sanitizeForLogging(input: unknown, depth?: number): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Compute a value-free structural signature for a list of arguments — used
|
|
34
|
+
* as the `sdk.argShape` Sentry tag so dashboards can count which overload of
|
|
35
|
+
* a method partners call without ingesting wallet addresses or other PII.
|
|
36
|
+
*
|
|
37
|
+
* Tokens: primitives keep their `typeof` name; 0x-prefixed strings narrow to
|
|
38
|
+
* `'address'` / `'tx-hash'` / `'hex'`; arrays render as `'array(<length>)'`;
|
|
39
|
+
* objects render as `'options{<sorted,keys>}'`, capped at 12 keys.
|
|
40
|
+
*
|
|
41
|
+
* @param args - The `arguments` array of an instrumented method.
|
|
42
|
+
* @returns Shape tokens, one per arg, in argument order.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* computeArgShape(['0xabc…ef', { vault: '0x…', chainId: 1 }])
|
|
46
|
+
* // → ['address', 'options{chainId,vault}']
|
|
47
|
+
*/
|
|
48
|
+
export declare function computeArgShape(args: unknown[]): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Sanitize method arguments for safe logging to Sentry.
|
|
51
|
+
* Removes sensitive data and truncates large values.
|
|
52
|
+
*/
|
|
53
|
+
export declare function sanitizeArgs(args: unknown[]): Record<string, unknown>;
|
|
54
|
+
/**
|
|
55
|
+
* Recursively sanitize an object, removing sensitive keys.
|
|
56
|
+
*/
|
|
57
|
+
export declare function sanitizeObject(obj: Record<string, unknown>, depth?: number): Record<string, unknown>;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeString = sanitizeString;
|
|
4
|
+
exports.sanitizeError = sanitizeError;
|
|
5
|
+
exports.sanitizeForLogging = sanitizeForLogging;
|
|
6
|
+
exports.computeArgShape = computeArgShape;
|
|
7
|
+
exports.sanitizeArgs = sanitizeArgs;
|
|
8
|
+
exports.sanitizeObject = sanitizeObject;
|
|
9
|
+
/** Keys that should never be sent to logging/observability sinks */
|
|
10
|
+
const SENSITIVE_KEYS = [
|
|
11
|
+
'apikey',
|
|
12
|
+
'api_key',
|
|
13
|
+
'apiKey',
|
|
14
|
+
'x-api-key',
|
|
15
|
+
'password',
|
|
16
|
+
'secret',
|
|
17
|
+
'token',
|
|
18
|
+
'bearer',
|
|
19
|
+
'authorization',
|
|
20
|
+
'proxy-authorization',
|
|
21
|
+
'cookie',
|
|
22
|
+
'set-cookie',
|
|
23
|
+
'privatekey',
|
|
24
|
+
'private_key',
|
|
25
|
+
'privateKey',
|
|
26
|
+
'mnemonic',
|
|
27
|
+
'seed',
|
|
28
|
+
// RPC endpoints can carry the API key in the path (e.g. Alchemy `/v2/<key>`),
|
|
29
|
+
// so a `sorobanRpcUrl` / `rpcUrl` argument must never reach telemetry. Matched
|
|
30
|
+
// as a substring, so it also covers `sorobanRpcUrls` and snake_case variants.
|
|
31
|
+
'rpcurl',
|
|
32
|
+
'rpc_url',
|
|
33
|
+
];
|
|
34
|
+
/** Regex patterns applied in order to scrub secrets from free-form strings. */
|
|
35
|
+
const STRING_REDACTION_PATTERNS = [
|
|
36
|
+
[/(authorization\s*[:=]\s*)(bearer|basic|token)\s+\S+/gi, '$1$2 [REDACTED]'],
|
|
37
|
+
[
|
|
38
|
+
/([?&](?:api[-_]?key|apikey|access[-_]?token|token|key|auth)=)[^&\s#]+/gi,
|
|
39
|
+
'$1[REDACTED]',
|
|
40
|
+
],
|
|
41
|
+
[/(gateway\.thegraph\.com\/api\/)[A-Za-z0-9]{20,}(\/)/g, '$1[REDACTED]$2'],
|
|
42
|
+
// Provider path-embedded API keys (e.g. Alchemy `…/v2/<key>`, Infura `…/v3/<key>`):
|
|
43
|
+
// a 16+ char token right after a `/vN/` segment is a key, not a resource path.
|
|
44
|
+
[/(\/v\d+\/)[A-Za-z0-9_-]{16,}/g, '$1[REDACTED]'],
|
|
45
|
+
[/eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g, '[REDACTED_JWT]'],
|
|
46
|
+
[/\bnpm_[A-Za-z0-9]{30,}\b/g, '[REDACTED_NPM_TOKEN]'],
|
|
47
|
+
// Stop value match at & # so adjacent query params aren't swallowed.
|
|
48
|
+
[
|
|
49
|
+
/(\b(?:api[-_]?key|apikey|password|secret|private[-_]?key|mnemonic|seed)\s*[:=]\s*)["']?[^\s"',;}&#]+["']?/gi,
|
|
50
|
+
'$1[REDACTED]',
|
|
51
|
+
],
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Redact secrets from a free-form string (error messages, URLs, log lines).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* sanitizeString('Request failed: https://api.example.com/v1?api_key=abc123')
|
|
58
|
+
* // → 'Request failed: https://api.example.com/v1?api_key=[REDACTED]'
|
|
59
|
+
*/
|
|
60
|
+
function sanitizeString(input) {
|
|
61
|
+
if (!input)
|
|
62
|
+
return input;
|
|
63
|
+
let out = input;
|
|
64
|
+
for (const [pattern, replacement] of STRING_REDACTION_PATTERNS) {
|
|
65
|
+
out = out.replace(pattern, replacement);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return a redacted clone of `err`. Preserves prototype (so `instanceof` checks
|
|
71
|
+
* keep working), `name`, all own properties (`code`, `status`, `correlationId`,
|
|
72
|
+
* …), and `cause`. Subclass constructors are NOT invoked — they may have
|
|
73
|
+
* positional signatures (`new UpshiftAuthError(code, message, opts)`) that would
|
|
74
|
+
* misalign if we naively passed the sanitized message as the first arg.
|
|
75
|
+
*
|
|
76
|
+
* Every write onto the clone goes through `Object.defineProperty` rather than
|
|
77
|
+
* assignment: the clone inherits `err`'s prototype, and some libraries make
|
|
78
|
+
* properties read-only there — `@solana/web3.js` defines `name` as non-writable
|
|
79
|
+
* on its error classes (`TransactionExpiredTimeoutError`, …). Assigning to an
|
|
80
|
+
* inherited non-writable property throws a `TypeError` in strict mode, which
|
|
81
|
+
* would escape from inside a caller's `catch` (e.g. `Logger.log.error`) and
|
|
82
|
+
* replace the error being reported. Defining an own property shadows the
|
|
83
|
+
* prototype's instead; each one is writable, configurable and enumerable,
|
|
84
|
+
* exactly as the plain assignment used to create it.
|
|
85
|
+
*
|
|
86
|
+
* @param err - Any caught value; non-`Error` values are returned unchanged.
|
|
87
|
+
* @returns A redacted clone for `Error` instances, otherwise `err` itself.
|
|
88
|
+
*/
|
|
89
|
+
function sanitizeError(err) {
|
|
90
|
+
if (!(err instanceof Error))
|
|
91
|
+
return err;
|
|
92
|
+
const safe = Object.create(Object.getPrototypeOf(err));
|
|
93
|
+
const define = (key, value) => Object.defineProperty(safe, key, {
|
|
94
|
+
value,
|
|
95
|
+
writable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
enumerable: true,
|
|
98
|
+
});
|
|
99
|
+
for (const key of Object.getOwnPropertyNames(err)) {
|
|
100
|
+
const value = err[key];
|
|
101
|
+
const redact = (key === 'message' || key === 'stack') && typeof value === 'string';
|
|
102
|
+
define(key, redact ? sanitizeString(value) : value);
|
|
103
|
+
}
|
|
104
|
+
if (!safe.message && typeof err.message === 'string') {
|
|
105
|
+
define('message', sanitizeString(err.message));
|
|
106
|
+
}
|
|
107
|
+
if (!safe.stack && typeof err.stack === 'string') {
|
|
108
|
+
define('stack', sanitizeString(err.stack));
|
|
109
|
+
}
|
|
110
|
+
define('name', err.name);
|
|
111
|
+
return safe;
|
|
112
|
+
}
|
|
113
|
+
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|
|
114
|
+
function sanitizeForLogging(input, depth = 0) {
|
|
115
|
+
if (input === null || input === undefined)
|
|
116
|
+
return input;
|
|
117
|
+
if (depth > 3)
|
|
118
|
+
return '[TRUNCATED]';
|
|
119
|
+
if (typeof input === 'string')
|
|
120
|
+
return sanitizeString(input);
|
|
121
|
+
if (typeof input === 'number' || typeof input === 'boolean')
|
|
122
|
+
return input;
|
|
123
|
+
if (input instanceof Error)
|
|
124
|
+
return sanitizeError(input);
|
|
125
|
+
if (Array.isArray(input)) {
|
|
126
|
+
return input.slice(0, 10).map((v) => sanitizeForLogging(v, depth + 1));
|
|
127
|
+
}
|
|
128
|
+
if (typeof input === 'object') {
|
|
129
|
+
return sanitizeObject(input, depth);
|
|
130
|
+
}
|
|
131
|
+
return `[${typeof input}]`;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Compute a value-free structural signature for a list of arguments — used
|
|
135
|
+
* as the `sdk.argShape` Sentry tag so dashboards can count which overload of
|
|
136
|
+
* a method partners call without ingesting wallet addresses or other PII.
|
|
137
|
+
*
|
|
138
|
+
* Tokens: primitives keep their `typeof` name; 0x-prefixed strings narrow to
|
|
139
|
+
* `'address'` / `'tx-hash'` / `'hex'`; arrays render as `'array(<length>)'`;
|
|
140
|
+
* objects render as `'options{<sorted,keys>}'`, capped at 12 keys.
|
|
141
|
+
*
|
|
142
|
+
* @param args - The `arguments` array of an instrumented method.
|
|
143
|
+
* @returns Shape tokens, one per arg, in argument order.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* computeArgShape(['0xabc…ef', { vault: '0x…', chainId: 1 }])
|
|
147
|
+
* // → ['address', 'options{chainId,vault}']
|
|
148
|
+
*/
|
|
149
|
+
function computeArgShape(args) {
|
|
150
|
+
return args.map((arg) => shapeOf(arg));
|
|
151
|
+
}
|
|
152
|
+
function shapeOf(value) {
|
|
153
|
+
if (value === null)
|
|
154
|
+
return 'null';
|
|
155
|
+
if (value === undefined)
|
|
156
|
+
return 'undefined';
|
|
157
|
+
const t = typeof value;
|
|
158
|
+
if (t === 'boolean' || t === 'number' || t === 'bigint' || t === 'function') {
|
|
159
|
+
return t;
|
|
160
|
+
}
|
|
161
|
+
if (t === 'string') {
|
|
162
|
+
const s = value;
|
|
163
|
+
if (/^0x[a-fA-F0-9]{40}$/.test(s))
|
|
164
|
+
return 'address';
|
|
165
|
+
if (/^0x[a-fA-F0-9]{64}$/.test(s))
|
|
166
|
+
return 'tx-hash';
|
|
167
|
+
if (/^0x[a-fA-F0-9]{6,}$/.test(s))
|
|
168
|
+
return 'hex';
|
|
169
|
+
return 'string';
|
|
170
|
+
}
|
|
171
|
+
if (Array.isArray(value)) {
|
|
172
|
+
return `array(${value.length})`;
|
|
173
|
+
}
|
|
174
|
+
if (t === 'object') {
|
|
175
|
+
const keys = Object.keys(value).sort();
|
|
176
|
+
const capped = keys.slice(0, 12);
|
|
177
|
+
const more = keys.length > 12 ? `,+${keys.length - 12}` : '';
|
|
178
|
+
return `options{${capped.join(',')}${more}}`;
|
|
179
|
+
}
|
|
180
|
+
return t;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Sanitize method arguments for safe logging to Sentry.
|
|
184
|
+
* Removes sensitive data and truncates large values.
|
|
185
|
+
*/
|
|
186
|
+
function sanitizeArgs(args) {
|
|
187
|
+
const sanitized = {};
|
|
188
|
+
args.forEach((arg, index) => {
|
|
189
|
+
const key = `arg${index}`;
|
|
190
|
+
if (arg === null || arg === undefined) {
|
|
191
|
+
sanitized[key] = arg;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (typeof arg === 'string') {
|
|
195
|
+
// Scrub embedded secrets, then truncate long strings.
|
|
196
|
+
const scrubbed = sanitizeString(arg);
|
|
197
|
+
sanitized[key] =
|
|
198
|
+
scrubbed.length > 100 ? `${scrubbed.substring(0, 100)}...` : scrubbed;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (typeof arg === 'number' || typeof arg === 'boolean') {
|
|
202
|
+
sanitized[key] = arg;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (typeof arg === 'object') {
|
|
206
|
+
sanitized[key] = sanitizeObject(arg);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// For functions or other types, just note the type
|
|
210
|
+
sanitized[key] = `[${typeof arg}]`;
|
|
211
|
+
});
|
|
212
|
+
return sanitized;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Recursively sanitize an object, removing sensitive keys.
|
|
216
|
+
*/
|
|
217
|
+
function sanitizeObject(obj, depth = 0) {
|
|
218
|
+
// Prevent deep recursion
|
|
219
|
+
if (depth > 3) {
|
|
220
|
+
return { _truncated: true };
|
|
221
|
+
}
|
|
222
|
+
const sanitized = {};
|
|
223
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
224
|
+
// Skip sensitive keys
|
|
225
|
+
if (SENSITIVE_KEYS.some((sk) => key.toLowerCase().includes(sk.toLowerCase()))) {
|
|
226
|
+
sanitized[key] = '[REDACTED]';
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (value === null || value === undefined) {
|
|
230
|
+
sanitized[key] = value;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (typeof value === 'string') {
|
|
234
|
+
// Check if value looks like a private key or sensitive data
|
|
235
|
+
if (value.length > 64 && /^[a-fA-F0-9]+$/.test(value)) {
|
|
236
|
+
sanitized[key] = '[REDACTED_HEX]';
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
// Scrub embedded secrets (API keys in URL paths/queries, bearer tokens,
|
|
240
|
+
// JWTs, …) from free-form values before truncating — key-name matching
|
|
241
|
+
// alone misses a secret carried inside a value under a benign key.
|
|
242
|
+
const scrubbedValue = sanitizeString(value);
|
|
243
|
+
sanitized[key] =
|
|
244
|
+
scrubbedValue.length > 100
|
|
245
|
+
? `${scrubbedValue.substring(0, 100)}...`
|
|
246
|
+
: scrubbedValue;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
250
|
+
sanitized[key] = value;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (Array.isArray(value)) {
|
|
254
|
+
sanitized[key] =
|
|
255
|
+
value.length > 10
|
|
256
|
+
? { _type: 'array', length: value.length, _truncated: true }
|
|
257
|
+
: value
|
|
258
|
+
.slice(0, 10)
|
|
259
|
+
.map((v) => typeof v === 'object' && v !== null
|
|
260
|
+
? sanitizeObject(v, depth + 1)
|
|
261
|
+
: v);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (typeof value === 'object') {
|
|
265
|
+
sanitized[key] = sanitizeObject(value, depth + 1);
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
sanitized[key] = `[${typeof value}]`;
|
|
269
|
+
}
|
|
270
|
+
return sanitized;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as SentryBrowser from '@sentry/browser';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the resolved Sentry SDK for the current runtime, or `null` if no
|
|
4
|
+
* SDK can be loaded. Idempotent and cached.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getSentrySDK(): typeof SentryBrowser | null;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the detected runtime label (`'browser'` | `'node'` | `'unknown'`).
|
|
9
|
+
* Used to set the `sdk.runtime` Sentry tag.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSentryRuntime(): 'browser' | 'node' | 'unknown';
|
|
12
|
+
/**
|
|
13
|
+
* Reset the cached SDK reference and runtime detection. Test-only.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resetSentryRuntime(): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSentrySDK = getSentrySDK;
|
|
4
|
+
exports.getSentryRuntime = getSentryRuntime;
|
|
5
|
+
exports.resetSentryRuntime = resetSentryRuntime;
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
let cachedSdk = null;
|
|
8
|
+
let detectedRuntime = 'unknown';
|
|
9
|
+
function detectRuntime() {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof window !== 'undefined' &&
|
|
12
|
+
typeof window.document !== 'undefined') {
|
|
13
|
+
return 'browser';
|
|
14
|
+
}
|
|
15
|
+
if (typeof process !== 'undefined' &&
|
|
16
|
+
process.versions?.node &&
|
|
17
|
+
typeof window === 'undefined') {
|
|
18
|
+
return 'node';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Property access on locked-down globals can throw in some sandboxes.
|
|
23
|
+
}
|
|
24
|
+
return 'unknown';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a CommonJS `require` that can load `@sentry/node` at runtime without
|
|
28
|
+
* letting bundlers statically pull it into browser bundles.
|
|
29
|
+
*
|
|
30
|
+
* Why not `new Function('return require')`: the `Function` constructor
|
|
31
|
+
* evaluates in the *global* scope, and in a CommonJS module `require` is a
|
|
32
|
+
* module-wrapper parameter, not a global. That probe therefore returned
|
|
33
|
+
* `null` in every real Node process (only the REPL and `node -e` expose a
|
|
34
|
+
* global `require`), so the SDK silently fell back to `@sentry/browser` on
|
|
35
|
+
* Node and process-level exception capture never engaged.
|
|
36
|
+
*
|
|
37
|
+
* Resolution order:
|
|
38
|
+
* 1. The module-scoped `require` of this (CommonJS-compiled) file. In Node
|
|
39
|
+
* and jest this is the real loader. Bundlers that target the browser
|
|
40
|
+
* either leave `require` undefined (Vite/Rollup → `typeof` guard → null)
|
|
41
|
+
* or substitute a stub that throws for unknown ids (webpack → caught by
|
|
42
|
+
* the caller → falls through to `@sentry/browser`). The call site passes
|
|
43
|
+
* the module id through a variable, so no bundler can statically resolve
|
|
44
|
+
* `@sentry/node`.
|
|
45
|
+
* 2. `module.createRequire(__filename)` via `process.getBuiltinModule`
|
|
46
|
+
* (Node ≥ 22.3) for hosts that rewrite `require` but keep `__filename`.
|
|
47
|
+
*
|
|
48
|
+
* @returns A `require`-compatible function, or `null` when none is reachable
|
|
49
|
+
* (browser bundles, locked-down sandboxes).
|
|
50
|
+
*/
|
|
51
|
+
function getNodeRequire() {
|
|
52
|
+
try {
|
|
53
|
+
if (typeof require === 'function') {
|
|
54
|
+
return require;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// `require` can be a throwing getter under some sandboxes.
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const getBuiltin = process.getBuiltinModule;
|
|
62
|
+
if (typeof getBuiltin === 'function' && typeof __filename === 'string') {
|
|
63
|
+
const mod = getBuiltin('module');
|
|
64
|
+
if (typeof mod?.createRequire === 'function') {
|
|
65
|
+
return mod.createRequire(__filename);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Not a Node runtime, or `module` is unavailable — fall through.
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function loadSentrySDK() {
|
|
75
|
+
if (cachedSdk)
|
|
76
|
+
return cachedSdk;
|
|
77
|
+
detectedRuntime = detectRuntime();
|
|
78
|
+
if (detectedRuntime === 'node') {
|
|
79
|
+
const nodeRequire = getNodeRequire();
|
|
80
|
+
if (nodeRequire) {
|
|
81
|
+
try {
|
|
82
|
+
cachedSdk = nodeRequire('@sentry/node');
|
|
83
|
+
return cachedSdk;
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
// Fall through to @sentry/browser, but surface it — running on Node
|
|
87
|
+
// without @sentry/node loses process-level exception capture.
|
|
88
|
+
logger_1.Logger.log.warn('analytics.runtime.sentry-node-missing', {
|
|
89
|
+
error: err instanceof Error ? err.message : String(err),
|
|
90
|
+
hint: 'Add @sentry/node to your dependencies for full Node telemetry coverage.',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
cachedSdk = require('@sentry/browser');
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
logger_1.Logger.log.warn('analytics.runtime.sentry-browser-missing', {
|
|
100
|
+
runtime: detectedRuntime,
|
|
101
|
+
error: err instanceof Error ? err.message : String(err),
|
|
102
|
+
});
|
|
103
|
+
cachedSdk = null;
|
|
104
|
+
}
|
|
105
|
+
return cachedSdk;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the resolved Sentry SDK for the current runtime, or `null` if no
|
|
109
|
+
* SDK can be loaded. Idempotent and cached.
|
|
110
|
+
*/
|
|
111
|
+
function getSentrySDK() {
|
|
112
|
+
return loadSentrySDK();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the detected runtime label (`'browser'` | `'node'` | `'unknown'`).
|
|
116
|
+
* Used to set the `sdk.runtime` Sentry tag.
|
|
117
|
+
*/
|
|
118
|
+
function getSentryRuntime() {
|
|
119
|
+
if (detectedRuntime === 'unknown') {
|
|
120
|
+
detectedRuntime = detectRuntime();
|
|
121
|
+
}
|
|
122
|
+
return detectedRuntime;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Reset the cached SDK reference and runtime detection. Test-only.
|
|
126
|
+
*/
|
|
127
|
+
function resetSentryRuntime() {
|
|
128
|
+
cachedSdk = null;
|
|
129
|
+
detectedRuntime = 'unknown';
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=sentry-runtime.js.map
|