@augustdigital/sdk 8.3.1 → 8.5.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/lib/abis/ERC20_Bytes32.d.ts +4 -0
- package/lib/abis/ERC20_Bytes32.js +4 -0
- package/lib/abis/ERC4626.d.ts +1 -0
- package/lib/abis/ERC4626.js +1 -0
- package/lib/abis/ERC721.d.ts +1 -0
- package/lib/abis/ERC721.js +1 -0
- package/lib/abis/FeeOracle.js +1 -0
- package/lib/abis/LendingPool.js +1 -0
- package/lib/abis/LendingPoolV2.js +1 -0
- package/lib/abis/Multicall3.js +3 -0
- package/lib/abis/OFT.d.ts +20 -0
- package/lib/abis/OFT.js +20 -0
- package/lib/abis/SmartAccount.d.ts +1 -0
- package/lib/abis/SmartAccount.js +3 -0
- package/lib/abis/SwapRouter.d.ts +1 -0
- package/lib/abis/SwapRouter.js +1 -0
- package/lib/abis/UniversalSignatureValidator.js +3 -0
- package/lib/abis/index.d.ts +5 -0
- package/lib/abis/index.js +5 -0
- package/lib/adapters/evm/getters.d.ts +17 -2
- package/lib/adapters/evm/getters.js +35 -3
- package/lib/adapters/evm/index.d.ts +262 -0
- package/lib/adapters/evm/index.js +268 -1
- package/lib/adapters/evm/utils.d.ts +6 -0
- package/lib/adapters/evm/utils.js +7 -0
- package/lib/adapters/solana/constants.js +4 -1
- package/lib/adapters/solana/getters.d.ts +8 -0
- package/lib/adapters/solana/getters.js +21 -0
- package/lib/adapters/solana/idl/vault-idl.js +9 -0
- package/lib/adapters/solana/index.d.ts +55 -0
- package/lib/adapters/solana/index.js +57 -0
- package/lib/adapters/solana/utils.d.ts +28 -0
- package/lib/adapters/solana/utils.js +79 -4
- package/lib/adapters/solana/vault.actions.d.ts +19 -0
- package/lib/adapters/solana/vault.actions.js +47 -3
- package/lib/adapters/stellar/actions.d.ts +25 -0
- package/lib/adapters/stellar/actions.js +33 -0
- package/lib/adapters/stellar/constants.d.ts +26 -0
- package/lib/adapters/stellar/constants.js +29 -0
- package/lib/adapters/stellar/getters.d.ts +56 -0
- package/lib/adapters/stellar/getters.js +81 -0
- package/lib/adapters/stellar/index.d.ts +48 -0
- package/lib/adapters/stellar/index.js +48 -0
- package/lib/adapters/stellar/soroban.d.ts +20 -0
- package/lib/adapters/stellar/soroban.js +46 -0
- package/lib/adapters/stellar/submit.d.ts +12 -0
- package/lib/adapters/stellar/submit.js +19 -0
- package/lib/adapters/stellar/types.d.ts +27 -0
- package/lib/adapters/stellar/types.js +3 -0
- package/lib/adapters/stellar/utils.d.ts +10 -0
- package/lib/adapters/stellar/utils.js +10 -0
- package/lib/adapters/sui/getters.d.ts +6 -0
- package/lib/adapters/sui/getters.js +6 -0
- package/lib/adapters/sui/index.d.ts +15 -0
- package/lib/adapters/sui/index.js +15 -0
- package/lib/adapters/sui/transformer.d.ts +6 -0
- package/lib/adapters/sui/transformer.js +7 -0
- package/lib/adapters/sui/utils.d.ts +6 -0
- package/lib/adapters/sui/utils.js +6 -0
- package/lib/core/analytics/chain-name.d.ts +8 -0
- package/lib/core/analytics/chain-name.js +8 -0
- package/lib/core/analytics/constants.d.ts +4 -0
- package/lib/core/analytics/constants.js +4 -0
- package/lib/core/analytics/env.d.ts +25 -0
- package/lib/core/analytics/env.js +26 -0
- package/lib/core/analytics/index.d.ts +26 -0
- package/lib/core/analytics/index.js +35 -0
- package/lib/core/analytics/instrumentation.d.ts +26 -0
- package/lib/core/analytics/instrumentation.js +66 -2
- package/lib/core/analytics/method-taxonomy.d.ts +16 -0
- package/lib/core/analytics/method-taxonomy.js +18 -0
- package/lib/core/analytics/metrics.d.ts +23 -0
- package/lib/core/analytics/metrics.js +40 -0
- package/lib/core/analytics/sanitize.d.ts +38 -0
- package/lib/core/analytics/sanitize.js +46 -0
- package/lib/core/analytics/sentry-runtime.d.ts +11 -0
- package/lib/core/analytics/sentry-runtime.js +19 -0
- package/lib/core/analytics/sentry.d.ts +45 -0
- package/lib/core/analytics/sentry.js +115 -2
- package/lib/core/analytics/types.d.ts +27 -0
- package/lib/core/analytics/user-identity.d.ts +34 -0
- package/lib/core/analytics/user-identity.js +42 -0
- package/lib/core/analytics/version.d.ts +6 -1
- package/lib/core/analytics/version.js +6 -1
- package/lib/core/auth/verify.js +5 -0
- package/lib/core/base.class.d.ts +75 -0
- package/lib/core/base.class.js +56 -0
- package/lib/core/cache.d.ts +5 -0
- package/lib/core/cache.js +6 -0
- package/lib/core/constants/adapters.d.ts +15 -0
- package/lib/core/constants/adapters.js +28 -8
- package/lib/core/constants/core.d.ts +12 -1
- package/lib/core/constants/core.js +12 -0
- package/lib/core/constants/swap-router.d.ts +46 -0
- package/lib/core/constants/swap-router.js +50 -0
- package/lib/core/constants/vaults.d.ts +56 -0
- package/lib/core/constants/vaults.js +66 -1
- package/lib/core/constants/web3.d.ts +3 -0
- package/lib/core/constants/web3.js +18 -5
- package/lib/core/errors/index.d.ts +36 -0
- package/lib/core/errors/index.js +29 -0
- package/lib/core/fetcher.d.ts +134 -0
- package/lib/core/fetcher.js +191 -5
- package/lib/core/helpers/adapters.d.ts +9 -0
- package/lib/core/helpers/adapters.js +11 -0
- package/lib/core/helpers/chain-address.d.ts +10 -0
- package/lib/core/helpers/chain-address.js +11 -0
- package/lib/core/helpers/core.d.ts +42 -0
- package/lib/core/helpers/core.js +66 -1
- package/lib/core/helpers/explorer-link.d.ts +14 -0
- package/lib/core/helpers/explorer-link.js +14 -0
- package/lib/core/helpers/signer.d.ts +26 -0
- package/lib/core/helpers/signer.js +39 -0
- package/lib/core/helpers/swap-router.d.ts +32 -0
- package/lib/core/helpers/swap-router.js +32 -0
- package/lib/core/helpers/vault-version.d.ts +1 -0
- package/lib/core/helpers/vault-version.js +2 -0
- package/lib/core/helpers/vaults.d.ts +8 -0
- package/lib/core/helpers/vaults.js +22 -8
- package/lib/core/helpers/web3.d.ts +152 -0
- package/lib/core/helpers/web3.js +183 -6
- package/lib/core/logger/index.d.ts +55 -0
- package/lib/core/logger/index.js +19 -0
- package/lib/core/logger/slack.d.ts +3 -0
- package/lib/core/logger/slack.js +3 -0
- package/lib/core/vault-metadata.d.ts +6 -0
- package/lib/core/vault-metadata.js +6 -0
- package/lib/core/version-check.d.ts +52 -0
- package/lib/core/version-check.js +81 -0
- package/lib/evm/methods/crossChainVault.d.ts +90 -0
- package/lib/evm/methods/crossChainVault.js +186 -1
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +1 -0
- package/lib/evm/methods/index.js +1 -0
- package/lib/evm/types/crossChain.d.ts +202 -0
- package/lib/evm/types/crossChain.js +11 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +19 -0
- package/lib/main.d.ts +288 -5
- package/lib/main.js +305 -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 +52 -0
- package/lib/modules/api/main.js +130 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +15 -0
- package/lib/modules/sub-accounts/fetcher.js +15 -0
- package/lib/modules/sub-accounts/main.d.ts +33 -0
- package/lib/modules/sub-accounts/main.js +38 -0
- package/lib/modules/sub-accounts/utils.d.ts +3 -0
- package/lib/modules/sub-accounts/utils.js +3 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +18 -0
- package/lib/modules/vaults/adapter.helpers.js +34 -0
- package/lib/modules/vaults/fetcher.d.ts +20 -0
- package/lib/modules/vaults/fetcher.js +40 -3
- package/lib/modules/vaults/getters.d.ts +295 -0
- package/lib/modules/vaults/getters.js +552 -12
- package/lib/modules/vaults/index.d.ts +12 -0
- package/lib/modules/vaults/index.js +12 -0
- package/lib/modules/vaults/main.d.ts +292 -4
- package/lib/modules/vaults/main.js +379 -7
- package/lib/modules/vaults/read.actions.d.ts +168 -0
- package/lib/modules/vaults/read.actions.js +143 -0
- package/lib/modules/vaults/types.d.ts +34 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +47 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
- package/lib/modules/vaults/utils/date-utils.js +47 -1
- package/lib/modules/vaults/utils.d.ts +70 -0
- package/lib/modules/vaults/utils.js +108 -5
- package/lib/modules/vaults/write.actions.d.ts +363 -3
- package/lib/modules/vaults/write.actions.js +364 -2
- package/lib/polyfills.js +2 -0
- package/lib/sdk.d.ts +23705 -0
- package/lib/services/coingecko/fetcher.d.ts +13 -0
- package/lib/services/coingecko/fetcher.js +17 -0
- package/lib/services/debank/fetcher.d.ts +14 -0
- package/lib/services/debank/fetcher.js +12 -0
- package/lib/services/debank/utils.js +17 -0
- package/lib/services/layerzero/deposits.d.ts +11 -0
- package/lib/services/layerzero/deposits.js +34 -11
- package/lib/services/layerzero/redeems.d.ts +10 -0
- package/lib/services/layerzero/redeems.js +13 -0
- package/lib/services/layerzero/utils.d.ts +8 -0
- package/lib/services/layerzero/utils.js +11 -0
- package/lib/services/octavfi/fetcher.d.ts +7 -0
- package/lib/services/octavfi/fetcher.js +25 -0
- package/lib/services/octavfi/utils.d.ts +12 -0
- package/lib/services/octavfi/utils.js +44 -10
- package/lib/services/subgraph/fetcher.js +4 -2
- package/lib/services/subgraph/vaults.d.ts +12 -0
- package/lib/services/subgraph/vaults.js +43 -2
- package/lib/services/swap-quotes/index.d.ts +71 -0
- package/lib/services/swap-quotes/index.js +25 -0
- package/lib/services/swap-quotes/paraswap.d.ts +17 -0
- package/lib/services/swap-quotes/paraswap.js +14 -0
- package/lib/types/pools.d.ts +3 -0
- package/lib/types/typed-contract.d.ts +64 -0
- package/lib/types/vaults.d.ts +139 -2
- package/lib/types/vaults.js +10 -0
- package/lib/types/web3.d.ts +8 -0
- package/lib/types/web3.js +1 -0
- package/lib/types/webserver.d.ts +45 -0
- package/package.json +6 -5
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment-variable gates for analytics. Pure functions — safe to import
|
|
4
|
+
* anywhere, no Sentry side effects. Tested directly in `analytics.test.js`.
|
|
5
|
+
*/
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.readEnv = readEnv;
|
|
4
8
|
exports.isAnalyticsForcedOnViaEnv = isAnalyticsForcedOnViaEnv;
|
|
5
9
|
exports.isAnalyticsDisabledViaEnv = isAnalyticsDisabledViaEnv;
|
|
6
10
|
exports.isNodeDevOrTestEnv = isNodeDevOrTestEnv;
|
|
11
|
+
/**
|
|
12
|
+
* Read a process env var without crashing in browsers or in bundles where
|
|
13
|
+
* `process.env` is a frozen / proxied object that throws on missing keys.
|
|
14
|
+
*/
|
|
7
15
|
function readEnv(name) {
|
|
8
16
|
try {
|
|
9
17
|
if (typeof process !== 'undefined' && process.env) {
|
|
@@ -11,6 +19,7 @@ function readEnv(name) {
|
|
|
11
19
|
}
|
|
12
20
|
}
|
|
13
21
|
catch {
|
|
22
|
+
// Bundlers occasionally throw on `process.env` access. Treat as unset.
|
|
14
23
|
}
|
|
15
24
|
return undefined;
|
|
16
25
|
}
|
|
@@ -20,12 +29,29 @@ function isTruthyEnv(value) {
|
|
|
20
29
|
const v = value.toLowerCase();
|
|
21
30
|
return v === '1' || v === 'true' || v === 'yes' || v === 'on';
|
|
22
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* `AUGUST_SDK_FORCE_ANALYTICS=1` bypasses the dev/test and localhost gates.
|
|
34
|
+
* Used by our own smoke-test script and by partners deliberately exercising
|
|
35
|
+
* telemetry in a non-prod environment.
|
|
36
|
+
*/
|
|
23
37
|
function isAnalyticsForcedOnViaEnv() {
|
|
24
38
|
return isTruthyEnv(readEnv('AUGUST_SDK_FORCE_ANALYTICS'));
|
|
25
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* `AUGUST_SDK_DISABLE_ANALYTICS=1` is the env equivalent of passing
|
|
42
|
+
* `analytics: { enabled: false }`. Useful when partners can't easily plumb
|
|
43
|
+
* config through (CI runners, ops scripts).
|
|
44
|
+
*/
|
|
26
45
|
function isAnalyticsDisabledViaEnv() {
|
|
27
46
|
return isTruthyEnv(readEnv('AUGUST_SDK_DISABLE_ANALYTICS'));
|
|
28
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* True when `NODE_ENV` is `'development'` or `'test'`. The SDK auto-disables
|
|
50
|
+
* analytics in these environments so partners' local dev runs and Jest suites
|
|
51
|
+
* don't pollute the production Sentry project.
|
|
52
|
+
*
|
|
53
|
+
* `NODE_ENV` undefined / `'production'` / `'staging'` / anything else → false.
|
|
54
|
+
*/
|
|
29
55
|
function isNodeDevOrTestEnv() {
|
|
30
56
|
const env = readEnv('NODE_ENV');
|
|
31
57
|
return env === 'development' || env === 'test';
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics module for SDK usage tracking via Sentry.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - User identification (API key hash, wallet, fingerprint, session)
|
|
6
|
+
* - Method call tracking with timing
|
|
7
|
+
* - Cache hit/miss rate monitoring
|
|
8
|
+
* - API response time tracking
|
|
9
|
+
* - Chain/network usage distribution
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Analytics enabled by default
|
|
14
|
+
* const sdk = new AugustSDK({
|
|
15
|
+
* providers: { 1: 'https://...' },
|
|
16
|
+
* keys: { august: '...' },
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Opt-out of analytics
|
|
20
|
+
* const sdk = new AugustSDK({
|
|
21
|
+
* providers: { 1: 'https://...' },
|
|
22
|
+
* keys: { august: '...' },
|
|
23
|
+
* analytics: { enabled: false },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
1
27
|
export type { IAnalyticsConfig, IUserIdentity, IMethodCallMetrics, } from './types';
|
|
2
28
|
export { hashApiKey, getSessionId, generateFingerprint, createUserIdentity, getUserId, } from './user-identity';
|
|
3
29
|
export { initializeSentry, updateUser, clearUser, isAnalyticsEnabled, getSentry, resetAnalytics, captureSdkException, } from './sentry';
|
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Analytics module for SDK usage tracking via Sentry.
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - User identification (API key hash, wallet, fingerprint, session)
|
|
7
|
+
* - Method call tracking with timing
|
|
8
|
+
* - Cache hit/miss rate monitoring
|
|
9
|
+
* - API response time tracking
|
|
10
|
+
* - Chain/network usage distribution
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Analytics enabled by default
|
|
15
|
+
* const sdk = new AugustSDK({
|
|
16
|
+
* providers: { 1: 'https://...' },
|
|
17
|
+
* keys: { august: '...' },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Opt-out of analytics
|
|
21
|
+
* const sdk = new AugustSDK({
|
|
22
|
+
* providers: { 1: 'https://...' },
|
|
23
|
+
* keys: { august: '...' },
|
|
24
|
+
* analytics: { enabled: false },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.chainIdToTagValue = exports.getMethodCategory = exports.METHOD_CATEGORIES = exports.instrumentClass = exports.withSyncMethodTracking = exports.withMethodTracking = exports.computeArgShape = exports.sanitizeObject = exports.sanitizeArgs = exports.resetCacheStats = exports.getCacheStats = exports.trackNetworkSwitch = exports.trackApiCall = exports.isNodeDevOrTestEnv = exports.isAnalyticsForcedOnViaEnv = exports.isAnalyticsDisabledViaEnv = exports.readEnv = exports.getSentryRuntime = exports.getSentrySDK = exports.captureSdkException = exports.resetAnalytics = exports.getSentry = exports.isAnalyticsEnabled = exports.clearUser = exports.updateUser = exports.initializeSentry = exports.getUserId = exports.createUserIdentity = exports.generateFingerprint = exports.getSessionId = exports.hashApiKey = void 0;
|
|
30
|
+
// User identity utilities
|
|
4
31
|
var user_identity_1 = require("./user-identity");
|
|
5
32
|
Object.defineProperty(exports, "hashApiKey", { enumerable: true, get: function () { return user_identity_1.hashApiKey; } });
|
|
6
33
|
Object.defineProperty(exports, "getSessionId", { enumerable: true, get: function () { return user_identity_1.getSessionId; } });
|
|
7
34
|
Object.defineProperty(exports, "generateFingerprint", { enumerable: true, get: function () { return user_identity_1.generateFingerprint; } });
|
|
8
35
|
Object.defineProperty(exports, "createUserIdentity", { enumerable: true, get: function () { return user_identity_1.createUserIdentity; } });
|
|
9
36
|
Object.defineProperty(exports, "getUserId", { enumerable: true, get: function () { return user_identity_1.getUserId; } });
|
|
37
|
+
// Sentry core
|
|
10
38
|
var sentry_1 = require("./sentry");
|
|
11
39
|
Object.defineProperty(exports, "initializeSentry", { enumerable: true, get: function () { return sentry_1.initializeSentry; } });
|
|
12
40
|
Object.defineProperty(exports, "updateUser", { enumerable: true, get: function () { return sentry_1.updateUser; } });
|
|
@@ -15,30 +43,37 @@ Object.defineProperty(exports, "isAnalyticsEnabled", { enumerable: true, get: fu
|
|
|
15
43
|
Object.defineProperty(exports, "getSentry", { enumerable: true, get: function () { return sentry_1.getSentry; } });
|
|
16
44
|
Object.defineProperty(exports, "resetAnalytics", { enumerable: true, get: function () { return sentry_1.resetAnalytics; } });
|
|
17
45
|
Object.defineProperty(exports, "captureSdkException", { enumerable: true, get: function () { return sentry_1.captureSdkException; } });
|
|
46
|
+
// Isomorphic Sentry runtime resolver
|
|
18
47
|
var sentry_runtime_1 = require("./sentry-runtime");
|
|
19
48
|
Object.defineProperty(exports, "getSentrySDK", { enumerable: true, get: function () { return sentry_runtime_1.getSentrySDK; } });
|
|
20
49
|
Object.defineProperty(exports, "getSentryRuntime", { enumerable: true, get: function () { return sentry_runtime_1.getSentryRuntime; } });
|
|
50
|
+
// Env-variable gates
|
|
21
51
|
var env_1 = require("./env");
|
|
22
52
|
Object.defineProperty(exports, "readEnv", { enumerable: true, get: function () { return env_1.readEnv; } });
|
|
23
53
|
Object.defineProperty(exports, "isAnalyticsDisabledViaEnv", { enumerable: true, get: function () { return env_1.isAnalyticsDisabledViaEnv; } });
|
|
24
54
|
Object.defineProperty(exports, "isAnalyticsForcedOnViaEnv", { enumerable: true, get: function () { return env_1.isAnalyticsForcedOnViaEnv; } });
|
|
25
55
|
Object.defineProperty(exports, "isNodeDevOrTestEnv", { enumerable: true, get: function () { return env_1.isNodeDevOrTestEnv; } });
|
|
56
|
+
// Metrics tracking
|
|
26
57
|
var metrics_1 = require("./metrics");
|
|
27
58
|
Object.defineProperty(exports, "trackApiCall", { enumerable: true, get: function () { return metrics_1.trackApiCall; } });
|
|
28
59
|
Object.defineProperty(exports, "trackNetworkSwitch", { enumerable: true, get: function () { return metrics_1.trackNetworkSwitch; } });
|
|
29
60
|
Object.defineProperty(exports, "getCacheStats", { enumerable: true, get: function () { return metrics_1.getCacheStats; } });
|
|
30
61
|
Object.defineProperty(exports, "resetCacheStats", { enumerable: true, get: function () { return metrics_1.resetCacheStats; } });
|
|
62
|
+
// Sanitization utilities
|
|
31
63
|
var sanitize_1 = require("./sanitize");
|
|
32
64
|
Object.defineProperty(exports, "sanitizeArgs", { enumerable: true, get: function () { return sanitize_1.sanitizeArgs; } });
|
|
33
65
|
Object.defineProperty(exports, "sanitizeObject", { enumerable: true, get: function () { return sanitize_1.sanitizeObject; } });
|
|
34
66
|
Object.defineProperty(exports, "computeArgShape", { enumerable: true, get: function () { return sanitize_1.computeArgShape; } });
|
|
67
|
+
// Method instrumentation
|
|
35
68
|
var instrumentation_1 = require("./instrumentation");
|
|
36
69
|
Object.defineProperty(exports, "withMethodTracking", { enumerable: true, get: function () { return instrumentation_1.withMethodTracking; } });
|
|
37
70
|
Object.defineProperty(exports, "withSyncMethodTracking", { enumerable: true, get: function () { return instrumentation_1.withSyncMethodTracking; } });
|
|
38
71
|
Object.defineProperty(exports, "instrumentClass", { enumerable: true, get: function () { return instrumentation_1.instrumentClass; } });
|
|
72
|
+
// Method taxonomy
|
|
39
73
|
var method_taxonomy_1 = require("./method-taxonomy");
|
|
40
74
|
Object.defineProperty(exports, "METHOD_CATEGORIES", { enumerable: true, get: function () { return method_taxonomy_1.METHOD_CATEGORIES; } });
|
|
41
75
|
Object.defineProperty(exports, "getMethodCategory", { enumerable: true, get: function () { return method_taxonomy_1.getMethodCategory; } });
|
|
76
|
+
// Chain name helper
|
|
42
77
|
var chain_name_1 = require("./chain-name");
|
|
43
78
|
Object.defineProperty(exports, "chainIdToTagValue", { enumerable: true, get: function () { return chain_name_1.chainIdToTagValue; } });
|
|
44
79
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-order function to wrap SDK methods with performance tracking.
|
|
3
|
+
* Tracks method calls, timing, chain usage, and errors.
|
|
4
|
+
*
|
|
5
|
+
* @param methodName - Name of the method being wrapped
|
|
6
|
+
* @param method - The original async method
|
|
7
|
+
* @param getChainId - Function to get current chain ID
|
|
8
|
+
* @returns Wrapped method with tracking
|
|
9
|
+
*/
|
|
1
10
|
export declare function withMethodTracking<T extends (...args: unknown[]) => Promise<unknown>>(methodName: string, method: T, getChainId?: () => number | undefined): T;
|
|
11
|
+
/**
|
|
12
|
+
* Higher-order function to wrap synchronous SDK methods with tracking.
|
|
13
|
+
* Uses breadcrumbs for tracking since spans require async context.
|
|
14
|
+
*
|
|
15
|
+
* @param methodName - Name of the method being wrapped
|
|
16
|
+
* @param method - The original sync method
|
|
17
|
+
* @param getChainId - Function to get current chain ID
|
|
18
|
+
* @returns Wrapped method with tracking
|
|
19
|
+
*/
|
|
2
20
|
export declare function withSyncMethodTracking<T extends (...args: unknown[]) => unknown>(methodName: string, method: T, getChainId?: () => number | undefined): T;
|
|
21
|
+
/**
|
|
22
|
+
* Instrument all methods on a class instance with tracking.
|
|
23
|
+
* This auto-wraps all public methods (both async and sync) without boilerplate.
|
|
24
|
+
*
|
|
25
|
+
* @param instance - The class instance to instrument
|
|
26
|
+
* @param getChainId - Function to get current chain ID
|
|
27
|
+
* @returns The same instance with instrumented methods
|
|
28
|
+
*/
|
|
3
29
|
export declare function instrumentClass<T extends object>(instance: T, getChainId: () => number | undefined): T;
|
|
@@ -8,11 +8,23 @@ const method_taxonomy_1 = require("./method-taxonomy");
|
|
|
8
8
|
const sanitize_1 = require("./sanitize");
|
|
9
9
|
const sentry_runtime_1 = require("./sentry-runtime");
|
|
10
10
|
const sentry_1 = require("./sentry");
|
|
11
|
+
/**
|
|
12
|
+
* Higher-order function to wrap SDK methods with performance tracking.
|
|
13
|
+
* Tracks method calls, timing, chain usage, and errors.
|
|
14
|
+
*
|
|
15
|
+
* @param methodName - Name of the method being wrapped
|
|
16
|
+
* @param method - The original async method
|
|
17
|
+
* @param getChainId - Function to get current chain ID
|
|
18
|
+
* @returns Wrapped method with tracking
|
|
19
|
+
*/
|
|
11
20
|
function withMethodTracking(methodName, method, getChainId) {
|
|
12
21
|
return async function trackedMethod(...args) {
|
|
13
22
|
if (!(0, sentry_1.isAnalyticsEnabled)()) {
|
|
14
23
|
return method(...args);
|
|
15
24
|
}
|
|
25
|
+
// Resolve the SDK before the sanitize/shape/category work — when
|
|
26
|
+
// @sentry/node fails to resolve, every call would otherwise pay the
|
|
27
|
+
// hot-path cost only to discard the result below.
|
|
16
28
|
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
17
29
|
if (!sdk) {
|
|
18
30
|
return method(...args);
|
|
@@ -23,6 +35,7 @@ function withMethodTracking(methodName, method, getChainId) {
|
|
|
23
35
|
const sanitizedArgs = (0, sanitize_1.sanitizeArgs)(args);
|
|
24
36
|
const argShape = (0, sanitize_1.computeArgShape)(args);
|
|
25
37
|
try {
|
|
38
|
+
// Use Sentry's startSpan for performance tracking (v8 API)
|
|
26
39
|
return await sdk.startSpan({
|
|
27
40
|
op: 'sdk.method',
|
|
28
41
|
name: methodName,
|
|
@@ -30,6 +43,7 @@ function withMethodTracking(methodName, method, getChainId) {
|
|
|
30
43
|
chainId: chainId?.toString() || 'unknown',
|
|
31
44
|
'sdk.chain': (0, chain_name_1.chainIdToTagValue)(chainId),
|
|
32
45
|
'sdk.category': category,
|
|
46
|
+
// Joined to a string because Sentry span attributes are scalar.
|
|
33
47
|
'sdk.argShape': argShape.join('|'),
|
|
34
48
|
...sanitizedArgs,
|
|
35
49
|
},
|
|
@@ -37,8 +51,10 @@ function withMethodTracking(methodName, method, getChainId) {
|
|
|
37
51
|
try {
|
|
38
52
|
const result = await method(...args);
|
|
39
53
|
const duration = performance.now() - startTime;
|
|
54
|
+
// Record success metrics
|
|
40
55
|
span?.setAttribute('duration', Math.round(duration));
|
|
41
56
|
span?.setAttribute('success', true);
|
|
57
|
+
// Track method call
|
|
42
58
|
trackMethodCall(methodName, {
|
|
43
59
|
method: methodName,
|
|
44
60
|
category,
|
|
@@ -46,15 +62,17 @@ function withMethodTracking(methodName, method, getChainId) {
|
|
|
46
62
|
duration,
|
|
47
63
|
success: true,
|
|
48
64
|
}, { ...sanitizedArgs, argShape: argShape.join('|') });
|
|
49
|
-
span?.setStatus({ code: 1 });
|
|
65
|
+
span?.setStatus({ code: 1 }); // OK status
|
|
50
66
|
return result;
|
|
51
67
|
}
|
|
52
68
|
catch (error) {
|
|
53
69
|
const duration = performance.now() - startTime;
|
|
54
70
|
const errorType = error instanceof Error ? error.name : 'UnknownError';
|
|
71
|
+
// Record error metrics
|
|
55
72
|
span?.setAttribute('duration', Math.round(duration));
|
|
56
73
|
span?.setAttribute('success', false);
|
|
57
74
|
span?.setAttribute('error', error instanceof Error ? error.message : String(error));
|
|
75
|
+
// Track failed method call
|
|
58
76
|
trackMethodCall(methodName, {
|
|
59
77
|
method: methodName,
|
|
60
78
|
category,
|
|
@@ -63,24 +81,31 @@ function withMethodTracking(methodName, method, getChainId) {
|
|
|
63
81
|
success: false,
|
|
64
82
|
errorType,
|
|
65
83
|
}, { ...sanitizedArgs, argShape: argShape.join('|') });
|
|
66
|
-
span?.setStatus({ code: 2, message: errorType });
|
|
84
|
+
span?.setStatus({ code: 2, message: errorType }); // Error status
|
|
67
85
|
throw error;
|
|
68
86
|
}
|
|
69
87
|
});
|
|
70
88
|
}
|
|
71
89
|
catch (error) {
|
|
90
|
+
// If Sentry.startSpan fails, fall back to direct method call
|
|
91
|
+
// This ensures analytics never breaks SDK functionality
|
|
72
92
|
if (error instanceof Error && error.message?.includes('Sentry')) {
|
|
73
93
|
return method(...args);
|
|
74
94
|
}
|
|
95
|
+
// Re-throw the original method error
|
|
75
96
|
throw error;
|
|
76
97
|
}
|
|
77
98
|
};
|
|
78
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Track individual method calls as breadcrumbs and measurements.
|
|
102
|
+
*/
|
|
79
103
|
function trackMethodCall(methodName, metrics, args) {
|
|
80
104
|
try {
|
|
81
105
|
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
82
106
|
if (!sdk)
|
|
83
107
|
return;
|
|
108
|
+
// Add breadcrumb for method call
|
|
84
109
|
sdk.addBreadcrumb({
|
|
85
110
|
category: 'sdk.method',
|
|
86
111
|
message: methodName,
|
|
@@ -93,9 +118,12 @@ function trackMethodCall(methodName, metrics, args) {
|
|
|
93
118
|
...args,
|
|
94
119
|
},
|
|
95
120
|
});
|
|
121
|
+
// Set measurement for method duration
|
|
96
122
|
sdk.setMeasurement('sdk.method.duration', metrics.duration, 'millisecond');
|
|
123
|
+
// Counters: SUM(invocation) → total calls; SUM(error)/SUM(invocation) → error rate.
|
|
97
124
|
sdk.setMeasurement('sdk.method.invocation', 1, 'none');
|
|
98
125
|
sdk.setMeasurement('sdk.method.error', metrics.success ? 0 : 1, 'none');
|
|
126
|
+
// Update tags for filtering
|
|
99
127
|
sdk.setTag('sdk.last_method', methodName);
|
|
100
128
|
if (metrics.category) {
|
|
101
129
|
sdk.setTag('sdk.category', metrics.category);
|
|
@@ -106,20 +134,36 @@ function trackMethodCall(methodName, metrics, args) {
|
|
|
106
134
|
}
|
|
107
135
|
}
|
|
108
136
|
catch {
|
|
137
|
+
// Silently fail - analytics should never break SDK
|
|
109
138
|
}
|
|
110
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if a function is async (returns a Promise).
|
|
142
|
+
*/
|
|
111
143
|
function isAsyncMethod(fn) {
|
|
144
|
+
// Check if constructor name indicates async
|
|
112
145
|
if (fn.constructor.name === 'AsyncFunction') {
|
|
113
146
|
return true;
|
|
114
147
|
}
|
|
148
|
+
// Check if function body suggests async
|
|
115
149
|
const fnString = fn.toString();
|
|
116
150
|
return fnString.includes('__awaiter') || fnString.startsWith('async');
|
|
117
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Higher-order function to wrap synchronous SDK methods with tracking.
|
|
154
|
+
* Uses breadcrumbs for tracking since spans require async context.
|
|
155
|
+
*
|
|
156
|
+
* @param methodName - Name of the method being wrapped
|
|
157
|
+
* @param method - The original sync method
|
|
158
|
+
* @param getChainId - Function to get current chain ID
|
|
159
|
+
* @returns Wrapped method with tracking
|
|
160
|
+
*/
|
|
118
161
|
function withSyncMethodTracking(methodName, method, getChainId) {
|
|
119
162
|
return function trackedSyncMethod(...args) {
|
|
120
163
|
if (!(0, sentry_1.isAnalyticsEnabled)()) {
|
|
121
164
|
return method(...args);
|
|
122
165
|
}
|
|
166
|
+
// Same hot-path short-circuit as the async path.
|
|
123
167
|
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
124
168
|
if (!sdk) {
|
|
125
169
|
return method(...args);
|
|
@@ -132,6 +176,7 @@ function withSyncMethodTracking(methodName, method, getChainId) {
|
|
|
132
176
|
try {
|
|
133
177
|
const result = method(...args);
|
|
134
178
|
const duration = performance.now() - startTime;
|
|
179
|
+
// Track successful sync method call via breadcrumb
|
|
135
180
|
trackSyncMethodCall(methodName, {
|
|
136
181
|
method: methodName,
|
|
137
182
|
category,
|
|
@@ -144,6 +189,7 @@ function withSyncMethodTracking(methodName, method, getChainId) {
|
|
|
144
189
|
catch (error) {
|
|
145
190
|
const duration = performance.now() - startTime;
|
|
146
191
|
const errorType = error instanceof Error ? error.name : 'UnknownError';
|
|
192
|
+
// Track failed sync method call
|
|
147
193
|
trackSyncMethodCall(methodName, {
|
|
148
194
|
method: methodName,
|
|
149
195
|
category,
|
|
@@ -156,11 +202,15 @@ function withSyncMethodTracking(methodName, method, getChainId) {
|
|
|
156
202
|
}
|
|
157
203
|
};
|
|
158
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Track synchronous method calls as breadcrumbs.
|
|
207
|
+
*/
|
|
159
208
|
function trackSyncMethodCall(methodName, metrics, args) {
|
|
160
209
|
try {
|
|
161
210
|
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
162
211
|
if (!sdk)
|
|
163
212
|
return;
|
|
213
|
+
// Add breadcrumb for sync method call
|
|
164
214
|
sdk.addBreadcrumb({
|
|
165
215
|
category: 'sdk.sync_method',
|
|
166
216
|
message: methodName,
|
|
@@ -173,6 +223,7 @@ function trackSyncMethodCall(methodName, metrics, args) {
|
|
|
173
223
|
...args,
|
|
174
224
|
},
|
|
175
225
|
});
|
|
226
|
+
// Counters — sync calls attach to whatever span is active on the scope.
|
|
176
227
|
sdk.setMeasurement('sdk.method.invocation', 1, 'none');
|
|
177
228
|
sdk.setMeasurement('sdk.method.error', metrics.success ? 0 : 1, 'none');
|
|
178
229
|
sdk.setTag('sdk.last_sync_method', methodName);
|
|
@@ -185,12 +236,22 @@ function trackSyncMethodCall(methodName, metrics, args) {
|
|
|
185
236
|
}
|
|
186
237
|
}
|
|
187
238
|
catch {
|
|
239
|
+
// Silently fail - analytics should never break SDK
|
|
188
240
|
}
|
|
189
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Instrument all methods on a class instance with tracking.
|
|
244
|
+
* This auto-wraps all public methods (both async and sync) without boilerplate.
|
|
245
|
+
*
|
|
246
|
+
* @param instance - The class instance to instrument
|
|
247
|
+
* @param getChainId - Function to get current chain ID
|
|
248
|
+
* @returns The same instance with instrumented methods
|
|
249
|
+
*/
|
|
190
250
|
function instrumentClass(instance, getChainId) {
|
|
191
251
|
try {
|
|
192
252
|
const proto = Object.getPrototypeOf(instance);
|
|
193
253
|
const methodNames = Object.getOwnPropertyNames(proto).filter((name) => {
|
|
254
|
+
// Skip constructor and private methods
|
|
194
255
|
if (name === 'constructor' || name.startsWith('_'))
|
|
195
256
|
return false;
|
|
196
257
|
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
@@ -200,10 +261,12 @@ function instrumentClass(instance, getChainId) {
|
|
|
200
261
|
const original = instance[methodName];
|
|
201
262
|
if (typeof original === 'function') {
|
|
202
263
|
if (isAsyncMethod(original)) {
|
|
264
|
+
// Wrap async methods with span-based tracking
|
|
203
265
|
instance[methodName] =
|
|
204
266
|
withMethodTracking(methodName, original.bind(instance), getChainId);
|
|
205
267
|
}
|
|
206
268
|
else {
|
|
269
|
+
// Wrap sync methods with breadcrumb-based tracking
|
|
207
270
|
instance[methodName] =
|
|
208
271
|
withSyncMethodTracking(methodName, original.bind(instance), getChainId);
|
|
209
272
|
}
|
|
@@ -211,6 +274,7 @@ function instrumentClass(instance, getChainId) {
|
|
|
211
274
|
}
|
|
212
275
|
}
|
|
213
276
|
catch {
|
|
277
|
+
// Silently fail - analytics should never break SDK
|
|
214
278
|
}
|
|
215
279
|
return instance;
|
|
216
280
|
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical category for an SDK public method, used as the `sdk.category`
|
|
3
|
+
* Sentry tag so the partner-usage dashboard can roll calls up into
|
|
4
|
+
* `read.*` / `write.*` / `network` / `bridge` buckets.
|
|
5
|
+
*/
|
|
1
6
|
export type MethodCategory = 'read.vault' | 'read.position' | 'read.redemption' | 'read.price' | 'read.points' | 'read.subaccount' | 'read.staking' | 'read.layerzero' | 'read.solana' | 'read.stellar' | 'read.sui' | 'read.evm' | 'write.deposit' | 'write.redeem' | 'write.approve' | 'write.points' | 'write.stellar' | 'network' | 'bridge' | 'unknown';
|
|
7
|
+
/**
|
|
8
|
+
* Map of public SDK method names to their {@link MethodCategory}.
|
|
9
|
+
*
|
|
10
|
+
* Keys are unqualified because `instrumentClass` walks the prototype and
|
|
11
|
+
* surfaces them that way; the same name on multiple adapters (e.g.
|
|
12
|
+
* `vaultDeposit` on EVM, Solana, Stellar) shares the same category.
|
|
13
|
+
*/
|
|
2
14
|
export declare const METHOD_CATEGORIES: Readonly<Record<string, MethodCategory>>;
|
|
15
|
+
/**
|
|
16
|
+
* Look up the category for a method name, defaulting to `'unknown'` for
|
|
17
|
+
* methods not yet added to {@link METHOD_CATEGORIES}.
|
|
18
|
+
*/
|
|
3
19
|
export declare function getMethodCategory(methodName: string): MethodCategory;
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.METHOD_CATEGORIES = void 0;
|
|
4
4
|
exports.getMethodCategory = getMethodCategory;
|
|
5
|
+
/**
|
|
6
|
+
* Map of public SDK method names to their {@link MethodCategory}.
|
|
7
|
+
*
|
|
8
|
+
* Keys are unqualified because `instrumentClass` walks the prototype and
|
|
9
|
+
* surfaces them that way; the same name on multiple adapters (e.g.
|
|
10
|
+
* `vaultDeposit` on EVM, Solana, Stellar) shares the same category.
|
|
11
|
+
*/
|
|
5
12
|
exports.METHOD_CATEGORIES = {
|
|
6
13
|
getVault: 'read.vault',
|
|
7
14
|
getVaults: 'read.vault',
|
|
@@ -15,6 +22,8 @@ exports.METHOD_CATEGORIES = {
|
|
|
15
22
|
getVaultHistoricalTimeseries: 'read.vault',
|
|
16
23
|
getVaultSummary: 'read.vault',
|
|
17
24
|
getVaultPnl: 'read.vault',
|
|
25
|
+
getVaultUnrealizedPnlHistory: 'read.vault',
|
|
26
|
+
getLatestUnrealizedPnl: 'read.vault',
|
|
18
27
|
getVaultBorrowerHealthFactor: 'read.vault',
|
|
19
28
|
getYieldLastRealizedOn: 'read.vault',
|
|
20
29
|
getVaultPositions: 'read.position',
|
|
@@ -48,8 +57,13 @@ exports.METHOD_CATEGORIES = {
|
|
|
48
57
|
fetchUserTokenBalance: 'read.solana',
|
|
49
58
|
fetchUserShareBalance: 'read.solana',
|
|
50
59
|
fetchUserShareBalanceRaw: 'read.solana',
|
|
60
|
+
// submitTransaction broadcasts a signed Soroban tx — it mutates on-chain
|
|
61
|
+
// state and belongs in the write bucket even though Stellar adapter call
|
|
62
|
+
// shape mirrors the read helpers (returns a hash, takes signed XDR).
|
|
51
63
|
submitTransaction: 'write.stellar',
|
|
52
64
|
getUserPosition: 'read.stellar',
|
|
65
|
+
// convertToShares is a read-only Soroban simulation despite its mutative-
|
|
66
|
+
// sounding name — runs through queryContract, no broadcast.
|
|
53
67
|
convertToShares: 'read.stellar',
|
|
54
68
|
getEmberVaults: 'read.sui',
|
|
55
69
|
getEmberTVL: 'read.sui',
|
|
@@ -79,6 +93,10 @@ exports.METHOD_CATEGORIES = {
|
|
|
79
93
|
clearWallet: 'network',
|
|
80
94
|
setSigner: 'network',
|
|
81
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Look up the category for a method name, defaulting to `'unknown'` for
|
|
98
|
+
* methods not yet added to {@link METHOD_CATEGORIES}.
|
|
99
|
+
*/
|
|
82
100
|
function getMethodCategory(methodName) {
|
|
83
101
|
return exports.METHOD_CATEGORIES[methodName] ?? 'unknown';
|
|
84
102
|
}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregated cache statistics for monitoring.
|
|
3
|
+
*/
|
|
1
4
|
declare let cacheStats: {
|
|
2
5
|
hits: number;
|
|
3
6
|
misses: number;
|
|
4
7
|
sets: number;
|
|
5
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Track API response times and status.
|
|
11
|
+
*
|
|
12
|
+
* @param endpoint - The API endpoint called
|
|
13
|
+
* @param method - HTTP method used
|
|
14
|
+
* @param startTime - Start timestamp from performance.now()
|
|
15
|
+
* @param status - HTTP response status code (0 for network errors)
|
|
16
|
+
* @param server - Server identifier (production, staging, etc.)
|
|
17
|
+
*/
|
|
6
18
|
export declare function trackApiCall(endpoint: string, method: string, startTime: number, status: number, server: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Track chain/network switches for usage distribution analysis.
|
|
21
|
+
*
|
|
22
|
+
* @param chainId - The chain ID being switched to
|
|
23
|
+
*/
|
|
7
24
|
export declare function trackNetworkSwitch(chainId: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get current cache statistics.
|
|
27
|
+
*/
|
|
8
28
|
export declare function getCacheStats(): typeof cacheStats;
|
|
29
|
+
/**
|
|
30
|
+
* Reset cache statistics (useful for testing).
|
|
31
|
+
*/
|
|
9
32
|
export declare function resetCacheStats(): void;
|
|
10
33
|
export {};
|
|
@@ -7,11 +7,23 @@ exports.resetCacheStats = resetCacheStats;
|
|
|
7
7
|
const chain_name_1 = require("./chain-name");
|
|
8
8
|
const sentry_runtime_1 = require("./sentry-runtime");
|
|
9
9
|
const sentry_1 = require("./sentry");
|
|
10
|
+
/**
|
|
11
|
+
* Aggregated cache statistics for monitoring.
|
|
12
|
+
*/
|
|
10
13
|
let cacheStats = {
|
|
11
14
|
hits: 0,
|
|
12
15
|
misses: 0,
|
|
13
16
|
sets: 0,
|
|
14
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Track API response times and status.
|
|
20
|
+
*
|
|
21
|
+
* @param endpoint - The API endpoint called
|
|
22
|
+
* @param method - HTTP method used
|
|
23
|
+
* @param startTime - Start timestamp from performance.now()
|
|
24
|
+
* @param status - HTTP response status code (0 for network errors)
|
|
25
|
+
* @param server - Server identifier (production, staging, etc.)
|
|
26
|
+
*/
|
|
15
27
|
function trackApiCall(endpoint, method, startTime, status, server) {
|
|
16
28
|
if (!(0, sentry_1.isAnalyticsEnabled)())
|
|
17
29
|
return;
|
|
@@ -20,7 +32,9 @@ function trackApiCall(endpoint, method, startTime, status, server) {
|
|
|
20
32
|
if (!sdk)
|
|
21
33
|
return;
|
|
22
34
|
const duration = performance.now() - startTime;
|
|
35
|
+
// Normalize endpoint for aggregation (replace dynamic segments)
|
|
23
36
|
const normalizedEndpoint = normalizeEndpoint(endpoint);
|
|
37
|
+
// Add breadcrumb
|
|
24
38
|
sdk.addBreadcrumb({
|
|
25
39
|
category: 'api',
|
|
26
40
|
message: `${method} ${normalizedEndpoint}`,
|
|
@@ -33,13 +47,21 @@ function trackApiCall(endpoint, method, startTime, status, server) {
|
|
|
33
47
|
server,
|
|
34
48
|
},
|
|
35
49
|
});
|
|
50
|
+
// Set measurement for performance tracking
|
|
36
51
|
sdk.setMeasurement('api.duration', duration, 'millisecond');
|
|
52
|
+
// Update tags for filtering
|
|
37
53
|
sdk.setTag('api.last_endpoint', normalizedEndpoint);
|
|
38
54
|
sdk.setTag('api.server', server);
|
|
39
55
|
}
|
|
40
56
|
catch {
|
|
57
|
+
// Silently fail - analytics should never break SDK
|
|
41
58
|
}
|
|
42
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Track chain/network switches for usage distribution analysis.
|
|
62
|
+
*
|
|
63
|
+
* @param chainId - The chain ID being switched to
|
|
64
|
+
*/
|
|
43
65
|
function trackNetworkSwitch(chainId) {
|
|
44
66
|
if (!(0, sentry_1.isAnalyticsEnabled)())
|
|
45
67
|
return;
|
|
@@ -58,18 +80,36 @@ function trackNetworkSwitch(chainId) {
|
|
|
58
80
|
sdk.setTag('sdk.chain', chainLabel);
|
|
59
81
|
}
|
|
60
82
|
catch {
|
|
83
|
+
// Silently fail - analytics should never break SDK
|
|
61
84
|
}
|
|
62
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Normalize endpoint URLs for aggregation.
|
|
88
|
+
* Replaces dynamic segments (addresses, IDs) with placeholders.
|
|
89
|
+
*
|
|
90
|
+
* @param endpoint - Raw endpoint URL
|
|
91
|
+
* @returns Normalized endpoint pattern
|
|
92
|
+
*/
|
|
63
93
|
function normalizeEndpoint(endpoint) {
|
|
64
94
|
return (endpoint
|
|
95
|
+
// Replace Ethereum addresses (0x + 40 hex chars)
|
|
65
96
|
.replace(/0x[a-fA-F0-9]{40}/g, ':address')
|
|
97
|
+
// Replace chain IDs (5+ digit numbers)
|
|
66
98
|
.replace(/\/\d{5,}/g, '/:chainId')
|
|
99
|
+
// Replace UUIDs
|
|
67
100
|
.replace(/[a-f0-9-]{36}/gi, ':uuid')
|
|
101
|
+
// Replace numeric IDs in paths
|
|
68
102
|
.replace(/\/\d+(?=\/|$)/g, '/:id'));
|
|
69
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Get current cache statistics.
|
|
106
|
+
*/
|
|
70
107
|
function getCacheStats() {
|
|
71
108
|
return { ...cacheStats };
|
|
72
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Reset cache statistics (useful for testing).
|
|
112
|
+
*/
|
|
73
113
|
function resetCacheStats() {
|
|
74
114
|
cacheStats = { hits: 0, misses: 0, sets: 0 };
|
|
75
115
|
}
|
|
@@ -1,6 +1,44 @@
|
|
|
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
|
+
*/
|
|
1
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 AugustAuthError(code, message, opts)`) that would
|
|
14
|
+
* misalign if we naively passed the sanitized message as the first arg.
|
|
15
|
+
*/
|
|
2
16
|
export declare function sanitizeError(err: unknown): unknown;
|
|
17
|
+
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|
|
3
18
|
export declare function sanitizeForLogging(input: unknown, depth?: number): unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Compute a value-free structural signature for a list of arguments — used
|
|
21
|
+
* as the `sdk.argShape` Sentry tag so dashboards can count which overload of
|
|
22
|
+
* a method partners call without ingesting wallet addresses or other PII.
|
|
23
|
+
*
|
|
24
|
+
* Tokens: primitives keep their `typeof` name; 0x-prefixed strings narrow to
|
|
25
|
+
* `'address'` / `'tx-hash'` / `'hex'`; arrays render as `'array(<length>)'`;
|
|
26
|
+
* objects render as `'options{<sorted,keys>}'`, capped at 12 keys.
|
|
27
|
+
*
|
|
28
|
+
* @param args - The `arguments` array of an instrumented method.
|
|
29
|
+
* @returns Shape tokens, one per arg, in argument order.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* computeArgShape(['0xabc…ef', { vault: '0x…', chainId: 1 }])
|
|
33
|
+
* // → ['address', 'options{chainId,vault}']
|
|
34
|
+
*/
|
|
4
35
|
export declare function computeArgShape(args: unknown[]): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Sanitize method arguments for safe logging to Sentry.
|
|
38
|
+
* Removes sensitive data and truncates large values.
|
|
39
|
+
*/
|
|
5
40
|
export declare function sanitizeArgs(args: unknown[]): Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively sanitize an object, removing sensitive keys.
|
|
43
|
+
*/
|
|
6
44
|
export declare function sanitizeObject(obj: Record<string, unknown>, depth?: number): Record<string, unknown>;
|