@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.
Files changed (204) hide show
  1. package/lib/abis/ERC20_Bytes32.d.ts +4 -0
  2. package/lib/abis/ERC20_Bytes32.js +4 -0
  3. package/lib/abis/ERC4626.d.ts +1 -0
  4. package/lib/abis/ERC4626.js +1 -0
  5. package/lib/abis/ERC721.d.ts +1 -0
  6. package/lib/abis/ERC721.js +1 -0
  7. package/lib/abis/FeeOracle.js +1 -0
  8. package/lib/abis/LendingPool.js +1 -0
  9. package/lib/abis/LendingPoolV2.js +1 -0
  10. package/lib/abis/Multicall3.js +3 -0
  11. package/lib/abis/OFT.d.ts +20 -0
  12. package/lib/abis/OFT.js +20 -0
  13. package/lib/abis/SmartAccount.d.ts +1 -0
  14. package/lib/abis/SmartAccount.js +3 -0
  15. package/lib/abis/SwapRouter.d.ts +1 -0
  16. package/lib/abis/SwapRouter.js +1 -0
  17. package/lib/abis/UniversalSignatureValidator.js +3 -0
  18. package/lib/abis/index.d.ts +5 -0
  19. package/lib/abis/index.js +5 -0
  20. package/lib/adapters/evm/getters.d.ts +17 -2
  21. package/lib/adapters/evm/getters.js +35 -3
  22. package/lib/adapters/evm/index.d.ts +262 -0
  23. package/lib/adapters/evm/index.js +268 -1
  24. package/lib/adapters/evm/utils.d.ts +6 -0
  25. package/lib/adapters/evm/utils.js +7 -0
  26. package/lib/adapters/solana/constants.js +4 -1
  27. package/lib/adapters/solana/getters.d.ts +8 -0
  28. package/lib/adapters/solana/getters.js +21 -0
  29. package/lib/adapters/solana/idl/vault-idl.js +9 -0
  30. package/lib/adapters/solana/index.d.ts +55 -0
  31. package/lib/adapters/solana/index.js +57 -0
  32. package/lib/adapters/solana/utils.d.ts +28 -0
  33. package/lib/adapters/solana/utils.js +79 -4
  34. package/lib/adapters/solana/vault.actions.d.ts +19 -0
  35. package/lib/adapters/solana/vault.actions.js +47 -3
  36. package/lib/adapters/stellar/actions.d.ts +25 -0
  37. package/lib/adapters/stellar/actions.js +33 -0
  38. package/lib/adapters/stellar/constants.d.ts +26 -0
  39. package/lib/adapters/stellar/constants.js +29 -0
  40. package/lib/adapters/stellar/getters.d.ts +56 -0
  41. package/lib/adapters/stellar/getters.js +81 -0
  42. package/lib/adapters/stellar/index.d.ts +48 -0
  43. package/lib/adapters/stellar/index.js +48 -0
  44. package/lib/adapters/stellar/soroban.d.ts +20 -0
  45. package/lib/adapters/stellar/soroban.js +46 -0
  46. package/lib/adapters/stellar/submit.d.ts +12 -0
  47. package/lib/adapters/stellar/submit.js +19 -0
  48. package/lib/adapters/stellar/types.d.ts +27 -0
  49. package/lib/adapters/stellar/types.js +3 -0
  50. package/lib/adapters/stellar/utils.d.ts +10 -0
  51. package/lib/adapters/stellar/utils.js +10 -0
  52. package/lib/adapters/sui/getters.d.ts +6 -0
  53. package/lib/adapters/sui/getters.js +6 -0
  54. package/lib/adapters/sui/index.d.ts +15 -0
  55. package/lib/adapters/sui/index.js +15 -0
  56. package/lib/adapters/sui/transformer.d.ts +6 -0
  57. package/lib/adapters/sui/transformer.js +7 -0
  58. package/lib/adapters/sui/utils.d.ts +6 -0
  59. package/lib/adapters/sui/utils.js +6 -0
  60. package/lib/core/analytics/chain-name.d.ts +8 -0
  61. package/lib/core/analytics/chain-name.js +8 -0
  62. package/lib/core/analytics/constants.d.ts +4 -0
  63. package/lib/core/analytics/constants.js +4 -0
  64. package/lib/core/analytics/env.d.ts +25 -0
  65. package/lib/core/analytics/env.js +26 -0
  66. package/lib/core/analytics/index.d.ts +26 -0
  67. package/lib/core/analytics/index.js +35 -0
  68. package/lib/core/analytics/instrumentation.d.ts +26 -0
  69. package/lib/core/analytics/instrumentation.js +66 -2
  70. package/lib/core/analytics/method-taxonomy.d.ts +16 -0
  71. package/lib/core/analytics/method-taxonomy.js +18 -0
  72. package/lib/core/analytics/metrics.d.ts +23 -0
  73. package/lib/core/analytics/metrics.js +40 -0
  74. package/lib/core/analytics/sanitize.d.ts +38 -0
  75. package/lib/core/analytics/sanitize.js +46 -0
  76. package/lib/core/analytics/sentry-runtime.d.ts +11 -0
  77. package/lib/core/analytics/sentry-runtime.js +19 -0
  78. package/lib/core/analytics/sentry.d.ts +45 -0
  79. package/lib/core/analytics/sentry.js +115 -2
  80. package/lib/core/analytics/types.d.ts +27 -0
  81. package/lib/core/analytics/user-identity.d.ts +34 -0
  82. package/lib/core/analytics/user-identity.js +42 -0
  83. package/lib/core/analytics/version.d.ts +6 -1
  84. package/lib/core/analytics/version.js +6 -1
  85. package/lib/core/auth/verify.js +5 -0
  86. package/lib/core/base.class.d.ts +75 -0
  87. package/lib/core/base.class.js +56 -0
  88. package/lib/core/cache.d.ts +5 -0
  89. package/lib/core/cache.js +6 -0
  90. package/lib/core/constants/adapters.d.ts +15 -0
  91. package/lib/core/constants/adapters.js +28 -8
  92. package/lib/core/constants/core.d.ts +12 -1
  93. package/lib/core/constants/core.js +12 -0
  94. package/lib/core/constants/swap-router.d.ts +46 -0
  95. package/lib/core/constants/swap-router.js +50 -0
  96. package/lib/core/constants/vaults.d.ts +56 -0
  97. package/lib/core/constants/vaults.js +66 -1
  98. package/lib/core/constants/web3.d.ts +3 -0
  99. package/lib/core/constants/web3.js +18 -5
  100. package/lib/core/errors/index.d.ts +36 -0
  101. package/lib/core/errors/index.js +29 -0
  102. package/lib/core/fetcher.d.ts +134 -0
  103. package/lib/core/fetcher.js +191 -5
  104. package/lib/core/helpers/adapters.d.ts +9 -0
  105. package/lib/core/helpers/adapters.js +11 -0
  106. package/lib/core/helpers/chain-address.d.ts +10 -0
  107. package/lib/core/helpers/chain-address.js +11 -0
  108. package/lib/core/helpers/core.d.ts +42 -0
  109. package/lib/core/helpers/core.js +66 -1
  110. package/lib/core/helpers/explorer-link.d.ts +14 -0
  111. package/lib/core/helpers/explorer-link.js +14 -0
  112. package/lib/core/helpers/signer.d.ts +26 -0
  113. package/lib/core/helpers/signer.js +39 -0
  114. package/lib/core/helpers/swap-router.d.ts +32 -0
  115. package/lib/core/helpers/swap-router.js +32 -0
  116. package/lib/core/helpers/vault-version.d.ts +1 -0
  117. package/lib/core/helpers/vault-version.js +2 -0
  118. package/lib/core/helpers/vaults.d.ts +8 -0
  119. package/lib/core/helpers/vaults.js +22 -8
  120. package/lib/core/helpers/web3.d.ts +152 -0
  121. package/lib/core/helpers/web3.js +183 -6
  122. package/lib/core/logger/index.d.ts +55 -0
  123. package/lib/core/logger/index.js +19 -0
  124. package/lib/core/logger/slack.d.ts +3 -0
  125. package/lib/core/logger/slack.js +3 -0
  126. package/lib/core/vault-metadata.d.ts +6 -0
  127. package/lib/core/vault-metadata.js +6 -0
  128. package/lib/core/version-check.d.ts +52 -0
  129. package/lib/core/version-check.js +81 -0
  130. package/lib/evm/methods/crossChainVault.d.ts +90 -0
  131. package/lib/evm/methods/crossChainVault.js +186 -1
  132. package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
  133. package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
  134. package/lib/evm/methods/index.d.ts +1 -0
  135. package/lib/evm/methods/index.js +1 -0
  136. package/lib/evm/types/crossChain.d.ts +202 -0
  137. package/lib/evm/types/crossChain.js +11 -0
  138. package/lib/index.d.ts +16 -0
  139. package/lib/index.js +19 -0
  140. package/lib/main.d.ts +288 -5
  141. package/lib/main.js +305 -0
  142. package/lib/modules/api/index.d.ts +1 -0
  143. package/lib/modules/api/index.js +6 -0
  144. package/lib/modules/api/main.d.ts +52 -0
  145. package/lib/modules/api/main.js +130 -0
  146. package/lib/modules/sub-accounts/fetcher.d.ts +15 -0
  147. package/lib/modules/sub-accounts/fetcher.js +15 -0
  148. package/lib/modules/sub-accounts/main.d.ts +33 -0
  149. package/lib/modules/sub-accounts/main.js +38 -0
  150. package/lib/modules/sub-accounts/utils.d.ts +3 -0
  151. package/lib/modules/sub-accounts/utils.js +3 -0
  152. package/lib/modules/vaults/adapter.helpers.d.ts +18 -0
  153. package/lib/modules/vaults/adapter.helpers.js +34 -0
  154. package/lib/modules/vaults/fetcher.d.ts +20 -0
  155. package/lib/modules/vaults/fetcher.js +40 -3
  156. package/lib/modules/vaults/getters.d.ts +295 -0
  157. package/lib/modules/vaults/getters.js +552 -12
  158. package/lib/modules/vaults/index.d.ts +12 -0
  159. package/lib/modules/vaults/index.js +12 -0
  160. package/lib/modules/vaults/main.d.ts +292 -4
  161. package/lib/modules/vaults/main.js +379 -7
  162. package/lib/modules/vaults/read.actions.d.ts +168 -0
  163. package/lib/modules/vaults/read.actions.js +143 -0
  164. package/lib/modules/vaults/types.d.ts +34 -0
  165. package/lib/modules/vaults/utils/call-data-decoder.d.ts +47 -0
  166. package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
  167. package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
  168. package/lib/modules/vaults/utils/date-utils.js +47 -1
  169. package/lib/modules/vaults/utils.d.ts +70 -0
  170. package/lib/modules/vaults/utils.js +108 -5
  171. package/lib/modules/vaults/write.actions.d.ts +363 -3
  172. package/lib/modules/vaults/write.actions.js +364 -2
  173. package/lib/polyfills.js +2 -0
  174. package/lib/sdk.d.ts +23705 -0
  175. package/lib/services/coingecko/fetcher.d.ts +13 -0
  176. package/lib/services/coingecko/fetcher.js +17 -0
  177. package/lib/services/debank/fetcher.d.ts +14 -0
  178. package/lib/services/debank/fetcher.js +12 -0
  179. package/lib/services/debank/utils.js +17 -0
  180. package/lib/services/layerzero/deposits.d.ts +11 -0
  181. package/lib/services/layerzero/deposits.js +34 -11
  182. package/lib/services/layerzero/redeems.d.ts +10 -0
  183. package/lib/services/layerzero/redeems.js +13 -0
  184. package/lib/services/layerzero/utils.d.ts +8 -0
  185. package/lib/services/layerzero/utils.js +11 -0
  186. package/lib/services/octavfi/fetcher.d.ts +7 -0
  187. package/lib/services/octavfi/fetcher.js +25 -0
  188. package/lib/services/octavfi/utils.d.ts +12 -0
  189. package/lib/services/octavfi/utils.js +44 -10
  190. package/lib/services/subgraph/fetcher.js +4 -2
  191. package/lib/services/subgraph/vaults.d.ts +12 -0
  192. package/lib/services/subgraph/vaults.js +43 -2
  193. package/lib/services/swap-quotes/index.d.ts +71 -0
  194. package/lib/services/swap-quotes/index.js +25 -0
  195. package/lib/services/swap-quotes/paraswap.d.ts +17 -0
  196. package/lib/services/swap-quotes/paraswap.js +14 -0
  197. package/lib/types/pools.d.ts +3 -0
  198. package/lib/types/typed-contract.d.ts +64 -0
  199. package/lib/types/vaults.d.ts +139 -2
  200. package/lib/types/vaults.js +10 -0
  201. package/lib/types/web3.d.ts +8 -0
  202. package/lib/types/web3.js +1 -0
  203. package/lib/types/webserver.d.ts +45 -0
  204. package/package.json +6 -5
@@ -6,6 +6,7 @@ exports.sanitizeForLogging = sanitizeForLogging;
6
6
  exports.computeArgShape = computeArgShape;
7
7
  exports.sanitizeArgs = sanitizeArgs;
8
8
  exports.sanitizeObject = sanitizeObject;
9
+ /** Keys that should never be sent to logging/observability sinks */
9
10
  const SENSITIVE_KEYS = [
10
11
  'apikey',
11
12
  'api_key',
@@ -25,6 +26,7 @@ const SENSITIVE_KEYS = [
25
26
  'mnemonic',
26
27
  'seed',
27
28
  ];
29
+ /** Regex patterns applied in order to scrub secrets from free-form strings. */
28
30
  const STRING_REDACTION_PATTERNS = [
29
31
  [/(authorization\s*[:=]\s*)(bearer|basic|token)\s+\S+/gi, '$1$2 [REDACTED]'],
30
32
  [
@@ -34,11 +36,19 @@ const STRING_REDACTION_PATTERNS = [
34
36
  [/(gateway\.thegraph\.com\/api\/)[A-Za-z0-9]{20,}(\/)/g, '$1[REDACTED]$2'],
35
37
  [/eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g, '[REDACTED_JWT]'],
36
38
  [/\bnpm_[A-Za-z0-9]{30,}\b/g, '[REDACTED_NPM_TOKEN]'],
39
+ // Stop value match at & # so adjacent query params aren't swallowed.
37
40
  [
38
41
  /(\b(?:api[-_]?key|apikey|password|secret|private[-_]?key|mnemonic|seed)\s*[:=]\s*)["']?[^\s"',;}&#]+["']?/gi,
39
42
  '$1[REDACTED]',
40
43
  ],
41
44
  ];
45
+ /**
46
+ * Redact secrets from a free-form string (error messages, URLs, log lines).
47
+ *
48
+ * @example
49
+ * sanitizeString('Request failed: https://api.example.com/v1?api_key=abc123')
50
+ * // → 'Request failed: https://api.example.com/v1?api_key=[REDACTED]'
51
+ */
42
52
  function sanitizeString(input) {
43
53
  if (!input)
44
54
  return input;
@@ -48,6 +58,13 @@ function sanitizeString(input) {
48
58
  }
49
59
  return out;
50
60
  }
61
+ /**
62
+ * Return a redacted clone of `err`. Preserves prototype (so `instanceof` checks
63
+ * keep working), `name`, all own properties (`code`, `status`, `correlationId`,
64
+ * …), and `cause`. Subclass constructors are NOT invoked — they may have
65
+ * positional signatures (`new AugustAuthError(code, message, opts)`) that would
66
+ * misalign if we naively passed the sanitized message as the first arg.
67
+ */
51
68
  function sanitizeError(err) {
52
69
  if (!(err instanceof Error))
53
70
  return err;
@@ -73,6 +90,7 @@ function sanitizeError(err) {
73
90
  safe.name = err.name;
74
91
  return safe;
75
92
  }
93
+ /** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
76
94
  function sanitizeForLogging(input, depth = 0) {
77
95
  if (input === null || input === undefined)
78
96
  return input;
@@ -92,6 +110,22 @@ function sanitizeForLogging(input, depth = 0) {
92
110
  }
93
111
  return `[${typeof input}]`;
94
112
  }
113
+ /**
114
+ * Compute a value-free structural signature for a list of arguments — used
115
+ * as the `sdk.argShape` Sentry tag so dashboards can count which overload of
116
+ * a method partners call without ingesting wallet addresses or other PII.
117
+ *
118
+ * Tokens: primitives keep their `typeof` name; 0x-prefixed strings narrow to
119
+ * `'address'` / `'tx-hash'` / `'hex'`; arrays render as `'array(<length>)'`;
120
+ * objects render as `'options{<sorted,keys>}'`, capped at 12 keys.
121
+ *
122
+ * @param args - The `arguments` array of an instrumented method.
123
+ * @returns Shape tokens, one per arg, in argument order.
124
+ *
125
+ * @example
126
+ * computeArgShape(['0xabc…ef', { vault: '0x…', chainId: 1 }])
127
+ * // → ['address', 'options{chainId,vault}']
128
+ */
95
129
  function computeArgShape(args) {
96
130
  return args.map((arg) => shapeOf(arg));
97
131
  }
@@ -125,6 +159,10 @@ function shapeOf(value) {
125
159
  }
126
160
  return t;
127
161
  }
162
+ /**
163
+ * Sanitize method arguments for safe logging to Sentry.
164
+ * Removes sensitive data and truncates large values.
165
+ */
128
166
  function sanitizeArgs(args) {
129
167
  const sanitized = {};
130
168
  args.forEach((arg, index) => {
@@ -134,6 +172,7 @@ function sanitizeArgs(args) {
134
172
  return;
135
173
  }
136
174
  if (typeof arg === 'string') {
175
+ // Truncate long strings
137
176
  sanitized[key] = arg.length > 100 ? `${arg.substring(0, 100)}...` : arg;
138
177
  return;
139
178
  }
@@ -145,16 +184,22 @@ function sanitizeArgs(args) {
145
184
  sanitized[key] = sanitizeObject(arg);
146
185
  return;
147
186
  }
187
+ // For functions or other types, just note the type
148
188
  sanitized[key] = `[${typeof arg}]`;
149
189
  });
150
190
  return sanitized;
151
191
  }
192
+ /**
193
+ * Recursively sanitize an object, removing sensitive keys.
194
+ */
152
195
  function sanitizeObject(obj, depth = 0) {
196
+ // Prevent deep recursion
153
197
  if (depth > 3) {
154
198
  return { _truncated: true };
155
199
  }
156
200
  const sanitized = {};
157
201
  for (const [key, value] of Object.entries(obj)) {
202
+ // Skip sensitive keys
158
203
  if (SENSITIVE_KEYS.some((sk) => key.toLowerCase().includes(sk.toLowerCase()))) {
159
204
  sanitized[key] = '[REDACTED]';
160
205
  continue;
@@ -164,6 +209,7 @@ function sanitizeObject(obj, depth = 0) {
164
209
  continue;
165
210
  }
166
211
  if (typeof value === 'string') {
212
+ // Check if value looks like a private key or sensitive data
167
213
  if (value.length > 64 && /^[a-fA-F0-9]+$/.test(value)) {
168
214
  sanitized[key] = '[REDACTED_HEX]';
169
215
  continue;
@@ -1,4 +1,15 @@
1
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
+ */
2
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
+ */
3
11
  export declare function getSentryRuntime(): 'browser' | 'node' | 'unknown';
12
+ /**
13
+ * Reset the cached SDK reference and runtime detection. Test-only.
14
+ */
4
15
  export declare function resetSentryRuntime(): void;
@@ -19,11 +19,17 @@ function detectRuntime() {
19
19
  }
20
20
  }
21
21
  catch {
22
+ // Property access on locked-down globals can throw in some sandboxes.
22
23
  }
23
24
  return 'unknown';
24
25
  }
25
26
  function getNodeRequire() {
26
27
  try {
28
+ // `new Function` is opaque to bundler static analysis (keeps
29
+ // @sentry/node out of browser bundles) AND blocked by strict
30
+ // script-src CSPs without 'unsafe-eval'. The CSP-blocked path falls
31
+ // through to @sentry/browser — do NOT replace with a direct
32
+ // `require('@sentry/node')`, which breaks the browser bundle.
27
33
  const req = new Function('return typeof require === "function" ? require : null')();
28
34
  return typeof req === 'function' ? req : null;
29
35
  }
@@ -43,6 +49,8 @@ function loadSentrySDK() {
43
49
  return cachedSdk;
44
50
  }
45
51
  catch (err) {
52
+ // Fall through to @sentry/browser, but surface it — running on Node
53
+ // without @sentry/node loses process-level exception capture.
46
54
  logger_1.Logger.log.warn('analytics.runtime.sentry-node-missing', {
47
55
  error: err instanceof Error ? err.message : String(err),
48
56
  hint: 'Add @sentry/node to your dependencies for full Node telemetry coverage.',
@@ -62,15 +70,26 @@ function loadSentrySDK() {
62
70
  }
63
71
  return cachedSdk;
64
72
  }
73
+ /**
74
+ * Returns the resolved Sentry SDK for the current runtime, or `null` if no
75
+ * SDK can be loaded. Idempotent and cached.
76
+ */
65
77
  function getSentrySDK() {
66
78
  return loadSentrySDK();
67
79
  }
80
+ /**
81
+ * Returns the detected runtime label (`'browser'` | `'node'` | `'unknown'`).
82
+ * Used to set the `sdk.runtime` Sentry tag.
83
+ */
68
84
  function getSentryRuntime() {
69
85
  if (detectedRuntime === 'unknown') {
70
86
  detectedRuntime = detectRuntime();
71
87
  }
72
88
  return detectedRuntime;
73
89
  }
90
+ /**
91
+ * Reset the cached SDK reference and runtime detection. Test-only.
92
+ */
74
93
  function resetSentryRuntime() {
75
94
  cachedSdk = null;
76
95
  detectedRuntime = 'unknown';
@@ -1,12 +1,57 @@
1
1
  import type * as Sentry from '@sentry/browser';
2
2
  import { IEnv } from '../../types';
3
3
  import { IAnalyticsConfig } from './types';
4
+ /**
5
+ * Initialize Sentry with SDK-specific configuration. Idempotent: re-calls
6
+ * only refresh user identity and the cached API-key hash.
7
+ *
8
+ * @param config - Analytics configuration. Pass `tracesSampleRate` to
9
+ * override the Phase 1/2 default of `1.0`.
10
+ * @param environment - Current environment (DEV or PROD).
11
+ * @param walletAddress - Optional wallet address for user identification.
12
+ * @param apiKey - Optional API key (hashed for identification).
13
+ * @param appName - Optional app-name slug. Set as the global `app.name`
14
+ * tag on every event; falls back to `'unverified:anonymous'` when
15
+ * omitted.
16
+ */
4
17
  export declare function initializeSentry(config: IAnalyticsConfig, environment: IEnv, walletAddress?: string, apiKey?: string, appName?: string): void;
18
+ /**
19
+ * Update the current user identity in Sentry.
20
+ * Called when wallet address changes.
21
+ *
22
+ * @param walletAddress - New wallet address (or undefined to clear)
23
+ * @param environment - Current environment
24
+ */
5
25
  export declare function updateUser(walletAddress?: string, environment?: IEnv): void;
26
+ /**
27
+ * Clear wallet from user identity.
28
+ * Called when user disconnects wallet.
29
+ */
6
30
  export declare function clearUser(): void;
31
+ /**
32
+ * Check if analytics is enabled and initialized.
33
+ */
7
34
  export declare function isAnalyticsEnabled(): boolean;
35
+ /**
36
+ * Get the current Sentry instance for advanced usage.
37
+ * Returns null if analytics is disabled.
38
+ */
8
39
  export declare function getSentry(): typeof Sentry | null;
40
+ /**
41
+ * Reset analytics state (useful for testing).
42
+ */
9
43
  export declare function resetAnalytics(): void;
44
+ /**
45
+ * Capture an exception into Sentry with SDK-specific context. Use from
46
+ * top-level error handlers (CLI, middleware, unhandled rejections) to
47
+ * report failures that don't flow through the auto-instrumented method
48
+ * surface. No-ops when analytics is disabled.
49
+ *
50
+ * @param error - Thrown value. Non-Error values are wrapped.
51
+ * @param options - `surface` ('cli' | 'sdk' | 'react' | string), extra `tags`,
52
+ * `extra` data, and a `flushTimeoutMs` to await before resolving (needed
53
+ * in Node when the process is about to exit).
54
+ */
10
55
  export declare function captureSdkException(error: unknown, options?: {
11
56
  surface?: 'cli' | 'sdk' | 'react' | string;
12
57
  tags?: Record<string, string>;
@@ -12,18 +12,31 @@ const constants_1 = require("./constants");
12
12
  const env_1 = require("./env");
13
13
  const sentry_runtime_1 = require("./sentry-runtime");
14
14
  const user_identity_1 = require("./user-identity");
15
+ /** Track initialization state */
15
16
  let isInitialized = false;
17
+ /** Track if analytics is enabled */
16
18
  let isEnabled = true;
19
+ /** Current user identity */
17
20
  let currentIdentity = null;
21
+ /** Cached API key for identity updates */
18
22
  let cachedApiKey;
23
+ /**
24
+ * Get the SDK version from the generated version file.
25
+ * Falls back to 'development' if file doesn't exist (during local dev).
26
+ */
19
27
  function getSDKVersion() {
20
28
  try {
29
+ // version.ts is generated at publish time and gitignored
21
30
  return require('./version').SDK_VERSION || 'development';
22
31
  }
23
32
  catch {
33
+ // version.ts doesn't exist in dev - use fallback
24
34
  return 'development';
25
35
  }
26
36
  }
37
+ /**
38
+ * Check if running on localhost.
39
+ */
27
40
  function isLocalhost() {
28
41
  try {
29
42
  if (typeof window !== 'undefined' && window.location) {
@@ -37,25 +50,44 @@ function isLocalhost() {
37
50
  }
38
51
  }
39
52
  catch {
53
+ // Silently fail
40
54
  }
41
55
  return false;
42
56
  }
57
+ /**
58
+ * Safely set a Sentry tag. Silently fails on error.
59
+ */
43
60
  function safeSetTag(key, value) {
44
61
  try {
45
62
  const sdk = (0, sentry_runtime_1.getSentrySDK)();
46
63
  sdk?.setTag(key, value);
47
64
  }
48
65
  catch {
66
+ // Silently fail - analytics should never break SDK
49
67
  }
50
68
  }
69
+ /**
70
+ * Safely set Sentry user. Silently fails on error.
71
+ */
51
72
  function safeSetUser(user) {
52
73
  try {
53
74
  const sdk = (0, sentry_runtime_1.getSentrySDK)();
54
75
  sdk?.setUser(user);
55
76
  }
56
77
  catch {
78
+ // Silently fail - analytics should never break SDK
57
79
  }
58
80
  }
81
+ /**
82
+ * Build the SDK's internal Sentry sink — the bridge that forwards
83
+ * `Logger.log.*` output to the resolved Sentry SDK. Errors are captured as
84
+ * issues; warnings are recorded as breadcrumbs (see the severity policy on
85
+ * `SDKSentrySink`). The SDK reference is resolved lazily on each call so the
86
+ * sink tracks runtime swaps and stays correct under the test harness's mock.
87
+ *
88
+ * Every method is fully wrapped: a telemetry failure must never propagate back
89
+ * into the caller that was only trying to log.
90
+ */
59
91
  function createSentrySink() {
60
92
  return {
61
93
  captureException(error, context) {
@@ -64,9 +96,17 @@ function createSentrySink() {
64
96
  if (!sdk)
65
97
  return;
66
98
  sdk.withScope((scope) => {
99
+ // `beforeSend` drops any event not tagged as ours; the tag is global
100
+ // already, but set it on the scope defensively in case a future
101
+ // Sentry version starts withScope() from a clean slate.
67
102
  scope.setTag('sdk', 'august-digital');
68
103
  if (context) {
69
104
  for (const [key, value] of Object.entries(context)) {
105
+ // Promote the call-site label (e.g. 'getVault:loans') to a
106
+ // scoped tag for grouping/filtering. Cardinality is bounded by
107
+ // the number of Logger call sites (~150) and the tag is
108
+ // event-scoped, not a global sticky tag — so it does not run
109
+ // afoul of the bounded-tag rule in CLAUDE.md §8.4.
70
110
  if (key === 'tag' && typeof value === 'string') {
71
111
  scope.setTag('sdk.origin', value);
72
112
  }
@@ -80,6 +120,7 @@ function createSentrySink() {
80
120
  });
81
121
  }
82
122
  catch {
123
+ // Telemetry must never break the SDK.
83
124
  }
84
125
  },
85
126
  addBreadcrumb(breadcrumb) {
@@ -87,13 +128,31 @@ function createSentrySink() {
87
128
  (0, sentry_runtime_1.getSentrySDK)()?.addBreadcrumb(breadcrumb);
88
129
  }
89
130
  catch {
131
+ // Telemetry must never break the SDK.
90
132
  }
91
133
  },
92
134
  };
93
135
  }
136
+ /**
137
+ * Initialize Sentry with SDK-specific configuration. Idempotent: re-calls
138
+ * only refresh user identity and the cached API-key hash.
139
+ *
140
+ * @param config - Analytics configuration. Pass `tracesSampleRate` to
141
+ * override the Phase 1/2 default of `1.0`.
142
+ * @param environment - Current environment (DEV or PROD).
143
+ * @param walletAddress - Optional wallet address for user identification.
144
+ * @param apiKey - Optional API key (hashed for identification).
145
+ * @param appName - Optional app-name slug. Set as the global `app.name`
146
+ * tag on every event; falls back to `'unverified:anonymous'` when
147
+ * omitted.
148
+ */
94
149
  function initializeSentry(config, environment, walletAddress, apiKey, appName) {
150
+ // SDK construction runs this multiple times (base + adapter constructors).
151
+ // Short-circuit so the disable-reason logs only once per process.
95
152
  if (isInitialized) {
96
153
  if (isEnabled) {
154
+ // Refresh cached apiKey before updateUser — otherwise a second SDK
155
+ // instance built with a different key is attributed to the first hash.
97
156
  if (apiKey !== undefined && apiKey !== cachedApiKey) {
98
157
  cachedApiKey = apiKey;
99
158
  updateUser(walletAddress, environment);
@@ -105,6 +164,7 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
105
164
  }
106
165
  return;
107
166
  }
167
+ // Constructor config wins outright — no env override can re-enable it.
108
168
  if (config.enabled === false) {
109
169
  isEnabled = false;
110
170
  isInitialized = true;
@@ -140,6 +200,8 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
140
200
  try {
141
201
  const sdk = (0, sentry_runtime_1.getSentrySDK)();
142
202
  if (!sdk) {
203
+ // Both @sentry/node and @sentry/browser failed to resolve. Surface this
204
+ // because the alternative is silent telemetry loss.
143
205
  logger_1.Logger.log.warn('analytics.init.sentry-unavailable', {
144
206
  runtime: (0, sentry_runtime_1.getSentryRuntime)(),
145
207
  hint: 'Confirm @sentry/browser (or @sentry/node) is installed and reachable.',
@@ -147,6 +209,8 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
147
209
  isEnabled = false;
148
210
  return;
149
211
  }
212
+ // Clamp to Sentry's accepted [0, 1] so a typo'd rate doesn't silently
213
+ // reject the init.
150
214
  const rawSampleRate = typeof config.tracesSampleRate === 'number' &&
151
215
  Number.isFinite(config.tracesSampleRate)
152
216
  ? config.tracesSampleRate
@@ -154,6 +218,7 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
154
218
  const tracesSampleRate = Math.max(0, Math.min(1, rawSampleRate));
155
219
  sdk.init({
156
220
  dsn: constants_1.SENTRY_DSN,
221
+ // TODO(post-verified-partner): ramp default down to ~0.1.
157
222
  tracesSampleRate,
158
223
  enableTracing: true,
159
224
  environment: environment.toLowerCase(),
@@ -161,24 +226,36 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
161
226
  sendDefaultPii: true,
162
227
  integrations: [sdk.captureConsoleIntegration({ levels: ['error'] })],
163
228
  beforeSend(event) {
229
+ // Only send events tagged as SDK-related
164
230
  if (event.tags?.sdk !== 'august-digital') {
165
231
  return null;
166
232
  }
167
233
  return event;
168
234
  },
169
235
  beforeSendTransaction(transaction) {
236
+ // Always include transactions for performance tracking
170
237
  return transaction;
171
238
  },
172
239
  });
240
+ // Set initial user identity
173
241
  updateUser(walletAddress, environment);
242
+ // Set global SDK tags
174
243
  safeSetTag('sdk', 'august-digital');
175
244
  safeSetTag('sdk.version', getSDKVersion());
176
245
  safeSetTag('sdk.runtime', (0, sentry_runtime_1.getSentryRuntime)());
246
+ // `app.name` is the dimension we filter on in Sentry to attribute
247
+ // events to a specific consuming application — see SDK quickstart docs.
177
248
  if (appName) {
178
249
  safeSetTag('app.name', appName);
179
250
  }
251
+ // `unverified:` prefix until the backend API-key → partner-id endpoint exists.
180
252
  safeSetTag('partner.id', appName ? `unverified:${appName}` : 'unverified:anonymous');
181
253
  safeSetTag('partner.tier', 'unverified');
254
+ // Bridge the SDK's structured logger into Sentry now that the SDK is live.
255
+ // Without this, Logger.log.error/warn are no-ops in production (no
256
+ // SDKLogger/structured logger is wired by default), so SDK-internal
257
+ // diagnostics never reach the dashboard. Errors → issues, warns →
258
+ // breadcrumbs.
182
259
  logger_1.Logger.setSentrySink(createSentrySink());
183
260
  isInitialized = true;
184
261
  logger_1.Logger.log.info('analytics.initialized', {
@@ -194,6 +271,13 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
194
271
  isEnabled = false;
195
272
  }
196
273
  }
274
+ /**
275
+ * Update the current user identity in Sentry.
276
+ * Called when wallet address changes.
277
+ *
278
+ * @param walletAddress - New wallet address (or undefined to clear)
279
+ * @param environment - Current environment
280
+ */
197
281
  function updateUser(walletAddress, environment = 'PROD') {
198
282
  if (!isEnabled)
199
283
  return;
@@ -202,10 +286,10 @@ function updateUser(walletAddress, environment = 'PROD') {
202
286
  const userId = (0, user_identity_1.getUserId)(currentIdentity);
203
287
  safeSetUser({
204
288
  id: userId,
205
- username: userId,
289
+ username: userId, // Duplicate to username which is less likely to be filtered
206
290
  ip_address: '{{auto}}',
207
291
  data: {
208
- userId,
292
+ userId, // Also store in data for redundancy
209
293
  sessionId: currentIdentity.sessionId,
210
294
  fingerprint: currentIdentity.fingerprint,
211
295
  hasWallet: !!walletAddress,
@@ -216,8 +300,13 @@ function updateUser(walletAddress, environment = 'PROD') {
216
300
  });
217
301
  }
218
302
  catch {
303
+ // Silently fail
219
304
  }
220
305
  }
306
+ /**
307
+ * Clear wallet from user identity.
308
+ * Called when user disconnects wallet.
309
+ */
221
310
  function clearUser() {
222
311
  if (!isEnabled)
223
312
  return;
@@ -240,16 +329,27 @@ function clearUser() {
240
329
  });
241
330
  }
242
331
  catch {
332
+ // Silently fail
243
333
  }
244
334
  }
335
+ /**
336
+ * Check if analytics is enabled and initialized.
337
+ */
245
338
  function isAnalyticsEnabled() {
246
339
  return isEnabled && isInitialized;
247
340
  }
341
+ /**
342
+ * Get the current Sentry instance for advanced usage.
343
+ * Returns null if analytics is disabled.
344
+ */
248
345
  function getSentry() {
249
346
  if (!isAnalyticsEnabled())
250
347
  return null;
251
348
  return (0, sentry_runtime_1.getSentrySDK)();
252
349
  }
350
+ /**
351
+ * Reset analytics state (useful for testing).
352
+ */
253
353
  function resetAnalytics() {
254
354
  isInitialized = false;
255
355
  isEnabled = true;
@@ -258,6 +358,17 @@ function resetAnalytics() {
258
358
  logger_1.Logger.setSentrySink(null);
259
359
  (0, sentry_runtime_1.resetSentryRuntime)();
260
360
  }
361
+ /**
362
+ * Capture an exception into Sentry with SDK-specific context. Use from
363
+ * top-level error handlers (CLI, middleware, unhandled rejections) to
364
+ * report failures that don't flow through the auto-instrumented method
365
+ * surface. No-ops when analytics is disabled.
366
+ *
367
+ * @param error - Thrown value. Non-Error values are wrapped.
368
+ * @param options - `surface` ('cli' | 'sdk' | 'react' | string), extra `tags`,
369
+ * `extra` data, and a `flushTimeoutMs` to await before resolving (needed
370
+ * in Node when the process is about to exit).
371
+ */
261
372
  async function captureSdkException(error, options) {
262
373
  if (!isAnalyticsEnabled())
263
374
  return;
@@ -266,6 +377,7 @@ async function captureSdkException(error, options) {
266
377
  if (!sdk)
267
378
  return;
268
379
  sdk.withScope((scope) => {
380
+ // Required so `beforeSend` doesn't drop the event.
269
381
  scope.setTag('sdk', 'august-digital');
270
382
  if (options?.surface) {
271
383
  scope.setTag('sdk.surface', options.surface);
@@ -288,6 +400,7 @@ async function captureSdkException(error, options) {
288
400
  }
289
401
  }
290
402
  catch {
403
+ // Silently fail - analytics should never block error propagation
291
404
  }
292
405
  }
293
406
  //# sourceMappingURL=sentry.js.map
@@ -1,18 +1,45 @@
1
1
  import { IEnv } from '../../types';
2
+ /**
3
+ * Configuration for SDK analytics/telemetry.
4
+ * Analytics are enabled by default (opt-out model).
5
+ */
2
6
  export interface IAnalyticsConfig {
7
+ /** Set to false to disable analytics. Default: true */
3
8
  enabled?: boolean;
9
+ /**
10
+ * Sentry trace sample rate. Defaults to `1.0` for the Phase 1/2 rollout;
11
+ * values outside `[0, 1]` are clamped.
12
+ */
4
13
  tracesSampleRate?: number;
5
14
  }
15
+ /**
16
+ * User identity for analytics tracking.
17
+ * Multiple identifiers are used with priority: apiKeyHash > wallet > fingerprint > session
18
+ */
6
19
  export interface IUserIdentity {
20
+ /** SHA-256 hash prefix of API key (first 16 chars). Never stores raw key. */
7
21
  apiKeyHash?: string;
22
+ /** User's wallet address (lowercased) */
8
23
  walletAddress?: string;
24
+ /** Random UUID generated per SDK instance */
9
25
  sessionId: string;
26
+ /** Browser/environment fingerprint for cross-session tracking */
10
27
  fingerprint?: string;
28
+ /** Current environment */
11
29
  environment: IEnv;
30
+ /** Domain of the current environment */
12
31
  domain?: string;
13
32
  }
33
+ /**
34
+ * Metrics for tracking SDK method calls.
35
+ */
14
36
  export interface IMethodCallMetrics {
15
37
  method: string;
38
+ /**
39
+ * Coarse-grained category from {@link METHOD_CATEGORIES} — e.g. `'read.vault'`,
40
+ * `'write.deposit'`. Used to roll calls up in the partner-usage dashboard
41
+ * without having to enumerate every method name.
42
+ */
16
43
  category?: string;
17
44
  chainId?: number;
18
45
  duration: number;
@@ -1,7 +1,41 @@
1
1
  import { IEnv } from '../../types';
2
2
  import { IUserIdentity } from './types';
3
+ /**
4
+ * Mask an API key, keeping only the last 5 characters visible.
5
+ * Example: "abcdefghij12345" -> "**********12345"
6
+ *
7
+ * @param apiKey - The raw API key to mask
8
+ * @returns Masked API key with last 5 characters visible
9
+ */
3
10
  export declare function hashApiKey(apiKey: string): string;
11
+ /**
12
+ * Generate a session ID that persists for the SDK instance lifetime.
13
+ * Provides user continuity even when wallet is not connected.
14
+ *
15
+ * @returns UUID v4 session identifier
16
+ */
4
17
  export declare function getSessionId(): string;
18
+ /**
19
+ * Generate a browser/environment fingerprint for cross-session tracking.
20
+ * Falls back gracefully in different environments.
21
+ *
22
+ * @returns Base64 encoded fingerprint string or undefined if unavailable
23
+ */
5
24
  export declare function generateFingerprint(): string | undefined;
25
+ /**
26
+ * Create a composite user identity for analytics.
27
+ *
28
+ * @param apiKey - Optional API key (will be hashed, never stored raw)
29
+ * @param walletAddress - Optional wallet address
30
+ * @param environment - Current environment (DEV or PROD)
31
+ * @returns User identity object
32
+ */
6
33
  export declare function createUserIdentity(apiKey?: string, walletAddress?: string, environment?: IEnv): IUserIdentity;
34
+ /**
35
+ * Generate a unique user ID for Sentry from identity components.
36
+ * Priority: apiKeyHash > wallet > fingerprint > session
37
+ *
38
+ * @param identity - User identity object
39
+ * @returns Prefixed user ID string
40
+ */
7
41
  export declare function getUserId(identity: IUserIdentity): string;