@metamask-previews/core-backend 9.0.0-preview-abca9bcea → 9.0.0-preview-ec24abb79
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/CHANGELOG.md +1 -12
- package/dist/api/accounts/client.cjs +2 -20
- package/dist/api/accounts/client.cjs.map +1 -1
- package/dist/api/accounts/client.d.cts.map +1 -1
- package/dist/api/accounts/client.d.mts.map +1 -1
- package/dist/api/accounts/client.mjs +2 -20
- package/dist/api/accounts/client.mjs.map +1 -1
- package/dist/api/base-client.cjs +27 -53
- package/dist/api/base-client.cjs.map +1 -1
- package/dist/api/base-client.d.cts +0 -1
- package/dist/api/base-client.d.cts.map +1 -1
- package/dist/api/base-client.d.mts +0 -1
- package/dist/api/base-client.d.mts.map +1 -1
- package/dist/api/base-client.mjs +28 -54
- package/dist/api/base-client.mjs.map +1 -1
- package/dist/api/index.cjs +1 -2
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.cts +1 -1
- package/dist/api/index.d.cts.map +1 -1
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.mts.map +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/api/shared-types.cjs +3 -7
- package/dist/api/shared-types.cjs.map +1 -1
- package/dist/api/shared-types.d.cts +1 -20
- package/dist/api/shared-types.d.cts.map +1 -1
- package/dist/api/shared-types.d.mts +1 -20
- package/dist/api/shared-types.d.mts.map +1 -1
- package/dist/api/shared-types.mjs +2 -6
- package/dist/api/shared-types.mjs.map +1 -1
- package/dist/ws/AccountActivityService.cjs +3 -1
- package/dist/ws/AccountActivityService.cjs.map +1 -1
- package/dist/ws/AccountActivityService.d.cts.map +1 -1
- package/dist/ws/AccountActivityService.d.mts.map +1 -1
- package/dist/ws/AccountActivityService.mjs +3 -1
- package/dist/ws/AccountActivityService.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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AAC,CAAC;IAE1B,IAAI,IAAI,CAAC,gBAAgB,IAAI,CAAC,EAAE,CAAC;QAC/B,OAAO,MAAM,YAAY,CAAC;IAC5B,CAAC;IAED,IAAI,SAAoD,CAAC;IACzD,MAAM,cAAc,GAAG,IAAI,OAAO,CAAY,CAAC,OAAO,EAAE,EAAE;QACxD,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC;IAC5D,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAuEH,6CAA6C;AAC7C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/**\n * Base API Client - Shared HTTP functionality for all API clients.\n */\n\nimport { QueryClient } from '@tanstack/query-core';\nimport type { QueryKey } from '@tanstack/query-core';\n\nimport {\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n DEFAULT_AUTH_TOKEN_TIMEOUT,\n calculateRetryDelay,\n shouldRetry,\n HttpError,\n} from './shared-types.js';\nimport type { ApiPlatformClientOptions } from './shared-types.js';\n\n// Auth query keys - shared for token management across clients\nexport const authQueryKeys = {\n bearerToken: (): QueryKey => ['auth', 'bearerToken'],\n} as const;\n\nexport type { ApiPlatformClientOptions };\n\n/**\n * Internal fetch options for HTTP requests.\n */\nexport type InternalFetchOptions = {\n signal?: AbortSignal;\n params?: Record<\n string,\n string | string[] | number | number[] | boolean | undefined\n >;\n};\n\n/**\n * Base API Client with shared HTTP and caching functionality.\n * Extended by all specific API clients.\n */\nexport class BaseApiClient {\n protected readonly clientProduct: string;\n\n protected readonly clientVersion?: string;\n\n protected readonly getBearerToken?: () => Promise<string | undefined>;\n\n protected readonly authTokenTimeout: number;\n\n readonly #queryClientInstance: QueryClient;\n\n /**\n * Get the underlying QueryClient instance.\n * Exposed for cache management operations.\n *\n * @returns The QueryClient instance.\n */\n get queryClient(): QueryClient {\n return this.#queryClientInstance;\n }\n\n /**\n * Invalidate the cached auth token.\n * Call this when the user logs out or the token expires.\n *\n * Uses resetQueries() instead of invalidateQueries() to completely remove\n * the cached value, ensuring the next request fetches a fresh token immediately.\n */\n async invalidateAuthToken(): Promise<void> {\n await this.#queryClientInstance.resetQueries({\n queryKey: authQueryKeys.bearerToken(),\n });\n }\n\n constructor(options: ApiPlatformClientOptions) {\n this.clientProduct = options.clientProduct;\n this.clientVersion = options.clientVersion;\n this.getBearerToken = options.getBearerToken;\n this.authTokenTimeout =\n options.authTokenTimeout ?? DEFAULT_AUTH_TOKEN_TIMEOUT;\n\n this.#queryClientInstance =\n options.queryClient ??\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: STALE_TIMES.DEFAULT,\n gcTime: GC_TIMES.DEFAULT,\n retry: shouldRetry,\n retryDelay: calculateRetryDelay,\n refetchOnWindowFocus: false,\n networkMode: 'always',\n },\n },\n });\n }\n\n /**\n * Resolve the bearer token, giving up after `authTokenTimeout` so that a slow\n * token provider does not delay the request. When the wait times out the\n * request goes out unauthenticated (lower rate limit) while the in-flight\n * `fetchQuery` keeps resolving `getBearerToken` for later requests.\n *\n * @returns The bearer token, or undefined if unavailable in time.\n */\n async #fetchBearerToken(): Promise<string | undefined> {\n const { getBearerToken } = this;\n if (!getBearerToken) {\n return undefined;\n }\n\n // fetchQuery de-duplicates concurrent callers. staleTime is 0 so we do not\n // cache the JWT here — AuthenticationController already owns token lifetime.\n const tokenPromise = this.#queryClientInstance\n .fetchQuery({\n queryKey: authQueryKeys.bearerToken(),\n queryFn: async () => {\n const result = await getBearerToken();\n // Throw if no token - prevents caching null/undefined\n // so subsequent requests can retry (e.g., after user logs in)\n if (!result) {\n throw new Error('No bearer token available');\n }\n return result;\n },\n staleTime: 0,\n retry: false, // Don't retry auth failures\n })\n .catch(() => undefined);\n\n if (this.authTokenTimeout <= 0) {\n return await tokenPromise;\n }\n\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<undefined>((resolve) => {\n timeoutId = setTimeout(() => resolve(undefined), this.authTokenTimeout);\n });\n\n try {\n return await Promise.race([tokenPromise, timeoutPromise]);\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n /**\n * Internal HTTP fetch method with authentication and error handling.\n *\n * @param baseUrl - The base URL for the API.\n * @param path - The API endpoint path.\n * @param options - Optional fetch configuration.\n * @returns The parsed JSON response.\n */\n protected async fetch<ResponseType>(\n baseUrl: string,\n path: string,\n options?: InternalFetchOptions,\n ): Promise<ResponseType> {\n const url = new URL(path, baseUrl);\n\n if (options?.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) {\n continue;\n }\n if (Array.isArray(value)) {\n // Convert array values (including number[]) to comma-separated string\n url.searchParams.set(key, value.map(String).join(','));\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'x-metamask-clientproduct': this.clientProduct,\n };\n\n if (this.clientVersion) {\n headers['x-metamask-clientversion'] = this.clientVersion;\n }\n\n const token = await this.#fetchBearerToken();\n if (token) {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers,\n signal: options?.signal,\n });\n\n if (!response.ok) {\n let body: unknown;\n try {\n body = await response.json();\n } catch {\n // Response body is not JSON or is empty, leave body as undefined\n }\n throw new HttpError(\n `HTTP ${response.status}: ${response.statusText}`,\n response.status,\n response.statusText,\n url.toString(),\n body,\n );\n }\n\n return response.json() as Promise<ResponseType>;\n }\n}\n\n// Re-export constants for use by API clients\nexport { API_URLS, STALE_TIMES, GC_TIMES, HttpError };\n"]}
|
|
1
|
+
{"version":3,"file":"base-client.mjs","sourceRoot":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AAM,cAAc,EAAE,CAAC;wBACtC,sDAAsD;wBACtD,8DAA8D;wBAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;4BACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;wBAC/C,CAAC;wBACD,OAAO,MAAM,CAAC;oBAChB,CAAC;oBACD,SAAS,EAAE,WAAW,CAAC,UAAU;oBACjC,KAAK,EAAE,KAAK,EAAE,4BAA4B;iBAC3C,CAAC,CAAC;gBAEH,OAAO,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACP,oDAAoD;YACtD,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YAC3C,MAAM,EAAE,KAAK;YACb,OAAO;YACP,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,IAAI,IAAa,CAAC;YAClB,IAAI,CAAC;gBACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,iEAAiE;YACnE,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,EACjD,QAAQ,CAAC,MAAM,EACf,QAAQ,CAAC,UAAU,EACnB,GAAG,CAAC,QAAQ,EAAE,EACd,IAAI,CACL,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAA2B,CAAC;IAClD,CAAC;CACF;;AAED,6CAA6C;AAC7C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/**\n * Base API Client - Shared HTTP functionality for all API clients.\n */\n\nimport { QueryClient } from '@tanstack/query-core';\nimport type { QueryKey } from '@tanstack/query-core';\n\nimport {\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n calculateRetryDelay,\n shouldRetry,\n HttpError,\n} from './shared-types.js';\nimport type { ApiPlatformClientOptions } from './shared-types.js';\n\n// Auth query keys - shared for token management across clients\nexport const authQueryKeys = {\n bearerToken: (): QueryKey => ['auth', 'bearerToken'],\n} as const;\n\nexport type { ApiPlatformClientOptions };\n\n/**\n * Internal fetch options for HTTP requests.\n */\nexport type InternalFetchOptions = {\n signal?: AbortSignal;\n params?: Record<\n string,\n string | string[] | number | number[] | boolean | undefined\n >;\n};\n\n/**\n * Base API Client with shared HTTP and caching functionality.\n * Extended by all specific API clients.\n */\nexport class BaseApiClient {\n protected readonly clientProduct: string;\n\n protected readonly clientVersion?: string;\n\n protected readonly getBearerToken?: () => Promise<string | undefined>;\n\n readonly #queryClientInstance: QueryClient;\n\n /**\n * Get the underlying QueryClient instance.\n * Exposed for cache management operations.\n *\n * @returns The QueryClient instance.\n */\n get queryClient(): QueryClient {\n return this.#queryClientInstance;\n }\n\n /**\n * Invalidate the cached auth token.\n * Call this when the user logs out or the token expires.\n *\n * Uses resetQueries() instead of invalidateQueries() to completely remove\n * the cached value, ensuring the next request fetches a fresh token immediately.\n */\n async invalidateAuthToken(): Promise<void> {\n await this.#queryClientInstance.resetQueries({\n queryKey: authQueryKeys.bearerToken(),\n });\n }\n\n constructor(options: ApiPlatformClientOptions) {\n this.clientProduct = options.clientProduct;\n this.clientVersion = options.clientVersion;\n this.getBearerToken = options.getBearerToken;\n\n this.#queryClientInstance =\n options.queryClient ??\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: STALE_TIMES.DEFAULT,\n gcTime: GC_TIMES.DEFAULT,\n retry: shouldRetry,\n retryDelay: calculateRetryDelay,\n refetchOnWindowFocus: false,\n networkMode: 'always',\n },\n },\n });\n }\n\n /**\n * Internal HTTP fetch method with authentication and error handling.\n *\n * @param baseUrl - The base URL for the API.\n * @param path - The API endpoint path.\n * @param options - Optional fetch configuration.\n * @returns The parsed JSON response.\n */\n protected async fetch<ResponseType>(\n baseUrl: string,\n path: string,\n options?: InternalFetchOptions,\n ): Promise<ResponseType> {\n const url = new URL(path, baseUrl);\n\n if (options?.params) {\n for (const [key, value] of Object.entries(options.params)) {\n if (value === undefined) {\n continue;\n }\n if (Array.isArray(value)) {\n // Convert array values (including number[]) to comma-separated string\n url.searchParams.set(key, value.map(String).join(','));\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'x-metamask-clientproduct': this.clientProduct,\n };\n\n if (this.clientVersion) {\n headers['x-metamask-clientversion'] = this.clientVersion;\n }\n\n // Get bearer token using fetchQuery for automatic deduplication\n if (this.getBearerToken) {\n const queryKey = authQueryKeys.bearerToken();\n const { getBearerToken } = this;\n\n try {\n // fetchQuery handles caching and deduplicates concurrent requests\n const token = await this.#queryClientInstance.fetchQuery({\n queryKey,\n queryFn: async () => {\n const result = await getBearerToken();\n // Throw if no token - prevents caching null/undefined\n // so subsequent requests can retry (e.g., after user logs in)\n if (!result) {\n throw new Error('No bearer token available');\n }\n return result;\n },\n staleTime: STALE_TIMES.AUTH_TOKEN,\n retry: false, // Don't retry auth failures\n });\n\n headers.Authorization = `Bearer ${token}`;\n } catch {\n // No token available - continue without auth header\n }\n }\n\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers,\n signal: options?.signal,\n });\n\n if (!response.ok) {\n let body: unknown;\n try {\n body = await response.json();\n } catch {\n // Response body is not JSON or is empty, leave body as undefined\n }\n throw new HttpError(\n `HTTP ${response.status}: ${response.statusText}`,\n response.status,\n response.statusText,\n url.toString(),\n body,\n );\n }\n\n return response.json() as Promise<ResponseType>;\n }\n}\n\n// Re-export constants for use by API clients\nexport { API_URLS, STALE_TIMES, GC_TIMES, HttpError };\n"]}
|
package/dist/api/index.cjs
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
* Re-exports all types and clients from the API folder.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createApiPlatformClient = exports.ApiPlatformClient = exports.BaseApiClient = exports.TokensApiClient = exports.TokenApiClient = exports.PricesApiClient = exports.V6_DEFI_POSITION_TYPES = exports.AccountsApiClient = exports.HttpError = exports.shouldRetry = exports.getQueryOptionsOverrides = exports.calculateRetryDelay = exports.RETRY_CONFIG = exports.
|
|
7
|
+
exports.createApiPlatformClient = exports.ApiPlatformClient = exports.BaseApiClient = exports.TokensApiClient = exports.TokenApiClient = exports.PricesApiClient = exports.V6_DEFI_POSITION_TYPES = exports.AccountsApiClient = exports.HttpError = exports.shouldRetry = exports.getQueryOptionsOverrides = exports.calculateRetryDelay = exports.RETRY_CONFIG = exports.GC_TIMES = exports.STALE_TIMES = exports.API_URLS = void 0;
|
|
8
8
|
var shared_types_js_1 = require("./shared-types.cjs");
|
|
9
9
|
Object.defineProperty(exports, "API_URLS", { enumerable: true, get: function () { return shared_types_js_1.API_URLS; } });
|
|
10
10
|
Object.defineProperty(exports, "STALE_TIMES", { enumerable: true, get: function () { return shared_types_js_1.STALE_TIMES; } });
|
|
11
11
|
Object.defineProperty(exports, "GC_TIMES", { enumerable: true, get: function () { return shared_types_js_1.GC_TIMES; } });
|
|
12
|
-
Object.defineProperty(exports, "DEFAULT_AUTH_TOKEN_TIMEOUT", { enumerable: true, get: function () { return shared_types_js_1.DEFAULT_AUTH_TOKEN_TIMEOUT; } });
|
|
13
12
|
Object.defineProperty(exports, "RETRY_CONFIG", { enumerable: true, get: function () { return shared_types_js_1.RETRY_CONFIG; } });
|
|
14
13
|
Object.defineProperty(exports, "calculateRetryDelay", { enumerable: true, get: function () { return shared_types_js_1.calculateRetryDelay; } });
|
|
15
14
|
Object.defineProperty(exports, "getQueryOptionsOverrides", { enumerable: true, get: function () { return shared_types_js_1.getQueryOptionsOverrides; } });
|
package/dist/api/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,sDAS2B;AARzB,2GAAA,QAAQ,OAAA;AACR,8GAAA,WAAW,OAAA;AACX,2GAAA,QAAQ,OAAA;AACR,+GAAA,YAAY,OAAA;AACZ,sHAAA,mBAAmB,OAAA;AACnB,2HAAA,wBAAwB,OAAA;AACxB,8GAAA,WAAW,OAAA;AACX,4GAAA,SAAS,OAAA;AAGX,eAAe;AACf,iDAAgF;AAAvE,6GAAA,iBAAiB,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AA2BlD,aAAa;AACb,+CAAoD;AAA3C,2GAAA,eAAe,OAAA;AAWxB,YAAY;AACZ,8CAAkD;AAAzC,0GAAA,cAAc,OAAA;AAavB,aAAa;AACb,+CAAoD;AAA3C,2GAAA,eAAe,OAAA;AAOxB,cAAc;AACd,oDAAiD;AAAxC,+GAAA,aAAa,OAAA;AAGtB,uCAAuC;AACvC,gEAGgC;AAF9B,yHAAA,iBAAiB,OAAA;AACjB,+HAAA,uBAAuB,OAAA","sourcesContent":["/**\n * API barrel export.\n * Re-exports all types and clients from the API folder.\n */\n\n// Shared types and utilities\nexport type {\n PageInfo,\n SupportedCurrency,\n MarketDataDetails,\n ApiPlatformClientOptions,\n FetchOptions,\n} from './shared-types.js';\nexport {\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n RETRY_CONFIG,\n calculateRetryDelay,\n getQueryOptionsOverrides,\n shouldRetry,\n HttpError,\n} from './shared-types.js';\n\n// Accounts API\nexport { AccountsApiClient, V6_DEFI_POSITION_TYPES } from './accounts/index.js';\nexport type {\n V5BalanceItem,\n V5BalancesResponse,\n V2BalanceItem,\n V2BalancesResponse,\n V4BalancesResponse,\n V6VsCurrency,\n V6DeFiPositionType,\n V6BalanceMetadata,\n V6TokenMetadata,\n V6BalanceItem,\n V6BalancesResponse,\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n ValueTransfer,\n V1AccountRelationshipResult,\n NftItem,\n V2NftsResponse,\n TokenDiscoveryItem,\n V2TokensResponse,\n} from './accounts/index.js';\n\n// Prices API\nexport { PricesApiClient } from './prices/index.js';\nexport type {\n V3SpotPricesResponse,\n CoinGeckoSpotPrice,\n ExchangeRateInfo,\n V1ExchangeRatesResponse,\n PriceSupportedNetworksResponse,\n V1HistoricalPricesResponse,\n V3HistoricalPricesResponse,\n} from './prices/index.js';\n\n// Token API\nexport { TokenApiClient } from './token/index.js';\nexport type {\n TokenMetadata,\n V1TokenDescriptionResponse,\n NetworkInfo,\n TopAsset,\n TrendingSortBy,\n TrendingToken,\n TopGainersSortOption,\n TrendingSortOption,\n V1SuggestedOccurrenceFloorsResponse,\n} from './token/index.js';\n\n// Tokens API\nexport { TokensApiClient } from './tokens/index.js';\nexport type {\n V1TokenSupportedNetworksResponse,\n V2TokenSupportedNetworksResponse,\n V3AssetResponse,\n} from './tokens/index.js';\n\n// Base client\nexport { BaseApiClient } from './base-client.js';\nexport type { InternalFetchOptions } from './base-client.js';\n\n// API Platform Client (unified client)\nexport {\n ApiPlatformClient,\n createApiPlatformClient,\n} from './ApiPlatformClient.js';\n"]}
|
package/dist/api/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Re-exports all types and clients from the API folder.
|
|
4
4
|
*/
|
|
5
5
|
export type { PageInfo, SupportedCurrency, MarketDataDetails, ApiPlatformClientOptions, FetchOptions, } from "./shared-types.cjs";
|
|
6
|
-
export { API_URLS, STALE_TIMES, GC_TIMES,
|
|
6
|
+
export { API_URLS, STALE_TIMES, GC_TIMES, RETRY_CONFIG, calculateRetryDelay, getQueryOptionsOverrides, shouldRetry, HttpError, } from "./shared-types.cjs";
|
|
7
7
|
export { AccountsApiClient, V6_DEFI_POSITION_TYPES } from "./accounts/index.cjs";
|
|
8
8
|
export type { V5BalanceItem, V5BalancesResponse, V2BalanceItem, V2BalancesResponse, V4BalancesResponse, V6VsCurrency, V6DeFiPositionType, V6BalanceMetadata, V6TokenMetadata, V6BalanceItem, V6BalancesResponse, V1SupportedNetworksResponse, V2SupportedNetworksResponse, V2ActiveNetworksResponse, V1TransactionByHashResponse, V1AccountTransactionsResponse, V4MultiAccountTransactionsResponse, ValueTransfer, V1AccountRelationshipResult, NftItem, V2NftsResponse, TokenDiscoveryItem, V2TokensResponse, } from "./accounts/index.cjs";
|
|
9
9
|
export { PricesApiClient } from "./prices/index.cjs";
|
package/dist/api/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,YAAY,GACb,2BAA0B;AAC3B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,YAAY,GACb,2BAA0B;AAC3B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,SAAS,GACV,2BAA0B;AAG3B,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,6BAA4B;AAChF,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,6BAA6B,EAC7B,kCAAkC,EAClC,aAAa,EACb,2BAA2B,EAC3B,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,6BAA4B;AAG7B,OAAO,EAAE,eAAe,EAAE,2BAA0B;AACpD,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,8BAA8B,EAC9B,0BAA0B,EAC1B,0BAA0B,GAC3B,2BAA0B;AAG3B,OAAO,EAAE,cAAc,EAAE,0BAAyB;AAClD,YAAY,EACV,aAAa,EACb,0BAA0B,EAC1B,WAAW,EACX,QAAQ,EACR,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,mCAAmC,GACpC,0BAAyB;AAG1B,OAAO,EAAE,eAAe,EAAE,2BAA0B;AACpD,YAAY,EACV,gCAAgC,EAChC,gCAAgC,EAChC,eAAe,GAChB,2BAA0B;AAG3B,OAAO,EAAE,aAAa,EAAE,0BAAyB;AACjD,YAAY,EAAE,oBAAoB,EAAE,0BAAyB;AAG7D,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,gCAA+B"}
|
package/dist/api/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Re-exports all types and clients from the API folder.
|
|
4
4
|
*/
|
|
5
5
|
export type { PageInfo, SupportedCurrency, MarketDataDetails, ApiPlatformClientOptions, FetchOptions, } from "./shared-types.mjs";
|
|
6
|
-
export { API_URLS, STALE_TIMES, GC_TIMES,
|
|
6
|
+
export { API_URLS, STALE_TIMES, GC_TIMES, RETRY_CONFIG, calculateRetryDelay, getQueryOptionsOverrides, shouldRetry, HttpError, } from "./shared-types.mjs";
|
|
7
7
|
export { AccountsApiClient, V6_DEFI_POSITION_TYPES } from "./accounts/index.mjs";
|
|
8
8
|
export type { V5BalanceItem, V5BalancesResponse, V2BalanceItem, V2BalancesResponse, V4BalancesResponse, V6VsCurrency, V6DeFiPositionType, V6BalanceMetadata, V6TokenMetadata, V6BalanceItem, V6BalancesResponse, V1SupportedNetworksResponse, V2SupportedNetworksResponse, V2ActiveNetworksResponse, V1TransactionByHashResponse, V1AccountTransactionsResponse, V4MultiAccountTransactionsResponse, ValueTransfer, V1AccountRelationshipResult, NftItem, V2NftsResponse, TokenDiscoveryItem, V2TokensResponse, } from "./accounts/index.mjs";
|
|
9
9
|
export { PricesApiClient } from "./prices/index.mjs";
|
package/dist/api/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,YAAY,GACb,2BAA0B;AAC3B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,EACxB,YAAY,GACb,2BAA0B;AAC3B,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,SAAS,GACV,2BAA0B;AAG3B,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,6BAA4B;AAChF,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,6BAA6B,EAC7B,kCAAkC,EAClC,aAAa,EACb,2BAA2B,EAC3B,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GACjB,6BAA4B;AAG7B,OAAO,EAAE,eAAe,EAAE,2BAA0B;AACpD,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,8BAA8B,EAC9B,0BAA0B,EAC1B,0BAA0B,GAC3B,2BAA0B;AAG3B,OAAO,EAAE,cAAc,EAAE,0BAAyB;AAClD,YAAY,EACV,aAAa,EACb,0BAA0B,EAC1B,WAAW,EACX,QAAQ,EACR,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,mCAAmC,GACpC,0BAAyB;AAG1B,OAAO,EAAE,eAAe,EAAE,2BAA0B;AACpD,YAAY,EACV,gCAAgC,EAChC,gCAAgC,EAChC,eAAe,GAChB,2BAA0B;AAG3B,OAAO,EAAE,aAAa,EAAE,0BAAyB;AACjD,YAAY,EAAE,oBAAoB,EAAE,0BAAyB;AAG7D,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,gCAA+B"}
|
package/dist/api/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* API barrel export.
|
|
3
3
|
* Re-exports all types and clients from the API folder.
|
|
4
4
|
*/
|
|
5
|
-
export { API_URLS, STALE_TIMES, GC_TIMES,
|
|
5
|
+
export { API_URLS, STALE_TIMES, GC_TIMES, RETRY_CONFIG, calculateRetryDelay, getQueryOptionsOverrides, shouldRetry, HttpError } from "./shared-types.mjs";
|
|
6
6
|
// Accounts API
|
|
7
7
|
export { AccountsApiClient, V6_DEFI_POSITION_TYPES } from "./accounts/index.mjs";
|
|
8
8
|
// Prices API
|
package/dist/api/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,SAAS,EACV,2BAA0B;AAE3B,eAAe;AACf,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,6BAA4B;AA2BhF,aAAa;AACb,OAAO,EAAE,eAAe,EAAE,2BAA0B;AAWpD,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,0BAAyB;AAalD,aAAa;AACb,OAAO,EAAE,eAAe,EAAE,2BAA0B;AAOpD,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,0BAAyB;AAGjD,uCAAuC;AACvC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACxB,gCAA+B","sourcesContent":["/**\n * API barrel export.\n * Re-exports all types and clients from the API folder.\n */\n\n// Shared types and utilities\nexport type {\n PageInfo,\n SupportedCurrency,\n MarketDataDetails,\n ApiPlatformClientOptions,\n FetchOptions,\n} from './shared-types.js';\nexport {\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n RETRY_CONFIG,\n calculateRetryDelay,\n getQueryOptionsOverrides,\n shouldRetry,\n HttpError,\n} from './shared-types.js';\n\n// Accounts API\nexport { AccountsApiClient, V6_DEFI_POSITION_TYPES } from './accounts/index.js';\nexport type {\n V5BalanceItem,\n V5BalancesResponse,\n V2BalanceItem,\n V2BalancesResponse,\n V4BalancesResponse,\n V6VsCurrency,\n V6DeFiPositionType,\n V6BalanceMetadata,\n V6TokenMetadata,\n V6BalanceItem,\n V6BalancesResponse,\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n ValueTransfer,\n V1AccountRelationshipResult,\n NftItem,\n V2NftsResponse,\n TokenDiscoveryItem,\n V2TokensResponse,\n} from './accounts/index.js';\n\n// Prices API\nexport { PricesApiClient } from './prices/index.js';\nexport type {\n V3SpotPricesResponse,\n CoinGeckoSpotPrice,\n ExchangeRateInfo,\n V1ExchangeRatesResponse,\n PriceSupportedNetworksResponse,\n V1HistoricalPricesResponse,\n V3HistoricalPricesResponse,\n} from './prices/index.js';\n\n// Token API\nexport { TokenApiClient } from './token/index.js';\nexport type {\n TokenMetadata,\n V1TokenDescriptionResponse,\n NetworkInfo,\n TopAsset,\n TrendingSortBy,\n TrendingToken,\n TopGainersSortOption,\n TrendingSortOption,\n V1SuggestedOccurrenceFloorsResponse,\n} from './token/index.js';\n\n// Tokens API\nexport { TokensApiClient } from './tokens/index.js';\nexport type {\n V1TokenSupportedNetworksResponse,\n V2TokenSupportedNetworksResponse,\n V3AssetResponse,\n} from './tokens/index.js';\n\n// Base client\nexport { BaseApiClient } from './base-client.js';\nexport type { InternalFetchOptions } from './base-client.js';\n\n// API Platform Client (unified client)\nexport {\n ApiPlatformClient,\n createApiPlatformClient,\n} from './ApiPlatformClient.js';\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Shared types, constants, and utilities for the API Platform Client.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HttpError = exports.shouldRetry = exports.calculateRetryDelay = exports.RETRY_CONFIG = exports.GC_TIMES = exports.
|
|
6
|
+
exports.HttpError = exports.shouldRetry = exports.calculateRetryDelay = exports.RETRY_CONFIG = exports.GC_TIMES = exports.STALE_TIMES = exports.API_URLS = exports.getQueryOptionsOverrides = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Returns options with queryKey and queryFn omitted, for merging into
|
|
9
9
|
* get*QueryOptions return values without overwriting the client's queryKey/queryFn.
|
|
@@ -17,7 +17,7 @@ function getQueryOptionsOverrides(options) {
|
|
|
17
17
|
if (options === null || options === undefined) {
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
|
-
const { queryKey: _qk, queryFn: _qf,
|
|
20
|
+
const { queryKey: _qk, queryFn: _qf, ...rest } = options;
|
|
21
21
|
return rest;
|
|
22
22
|
}
|
|
23
23
|
exports.getQueryOptionsOverrides = getQueryOptionsOverrides;
|
|
@@ -33,6 +33,7 @@ exports.API_URLS = {
|
|
|
33
33
|
};
|
|
34
34
|
/** Stale times for different data types (ms) */
|
|
35
35
|
exports.STALE_TIMES = {
|
|
36
|
+
AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token
|
|
36
37
|
PRICES: 30 * 1000, // 30 seconds
|
|
37
38
|
BALANCES: 60 * 1000, // 1 minute
|
|
38
39
|
NETWORKS: 10 * 60 * 1000, // 10 minutes
|
|
@@ -44,11 +45,6 @@ exports.STALE_TIMES = {
|
|
|
44
45
|
TRANSACTIONS: 30 * 1000, // 30 seconds
|
|
45
46
|
DEFAULT: 30 * 1000, // 30 seconds
|
|
46
47
|
};
|
|
47
|
-
/**
|
|
48
|
-
* Default max time (ms) to wait for the bearer token before falling back to an
|
|
49
|
-
* unauthenticated request.
|
|
50
|
-
*/
|
|
51
|
-
exports.DEFAULT_AUTH_TOKEN_TIMEOUT = 500;
|
|
52
48
|
/** Garbage collection times (ms) */
|
|
53
49
|
exports.GC_TIMES = {
|
|
54
50
|
DEFAULT: 5 * 60 * 1000, // 5 minutes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-types.cjs","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAiLH;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CACtC,OAAsB;IAEtB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,EACJ,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,GAAG,EACZ,iBAAiB,EAAE,GAAG,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CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAvBD,8BAuBC","sourcesContent":["/**\n * Shared types, constants, and utilities for the API Platform Client.\n */\n\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/query-core';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\n/**\n * Pagination info for paginated responses\n */\nexport type PageInfo = {\n count: number;\n hasNextPage: boolean;\n cursor?: string;\n};\n\n/**\n * Supported currencies for Price API\n */\nexport type SupportedCurrency =\n // Crypto\n | 'btc'\n | 'eth'\n | 'ltc'\n | 'bch'\n | 'bnb'\n | 'eos'\n | 'xrp'\n | 'xlm'\n | 'link'\n | 'dot'\n | 'yfi'\n // Fiat\n | 'usd'\n | 'aed'\n | 'ars'\n | 'aud'\n | 'bdt'\n | 'bhd'\n | 'bmd'\n | 'brl'\n | 'cad'\n | 'chf'\n | 'clp'\n | 'cny'\n | 'czk'\n | 'dkk'\n | 'eur'\n | 'gbp'\n | 'gel'\n | 'hkd'\n | 'huf'\n | 'idr'\n | 'ils'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'kwd'\n | 'lkr'\n | 'mmk'\n | 'mxn'\n | 'myr'\n | 'ngn'\n | 'nok'\n | 'nzd'\n | 'php'\n | 'pkr'\n | 'pln'\n | 'rub'\n | 'sar'\n | 'sek'\n | 'sgd'\n | 'thb'\n | 'try'\n | 'twd'\n | 'uah'\n | 'vef'\n | 'vnd'\n | 'zar';\n\n/**\n * Market data details from Price API spot-prices endpoint\n */\nexport type MarketDataDetails = {\n /** Current price in the requested currency */\n price: number;\n /** Currency code (e.g., 'ETH', 'USD') */\n currency: string;\n /** 24h price change amount */\n priceChange1d: number;\n /** 24h price change percentage */\n pricePercentChange1d: number;\n /** 1h price change percentage */\n pricePercentChange1h: number;\n /** 7d price change percentage */\n pricePercentChange7d: number;\n /** 14d price change percentage */\n pricePercentChange14d: number;\n /** 30d price change percentage */\n pricePercentChange30d: number;\n /** 200d price change percentage */\n pricePercentChange200d: number;\n /** 1y price change percentage */\n pricePercentChange1y: number;\n /** Market capitalization */\n marketCap: number;\n /** Market cap 24h change percentage */\n marketCapPercentChange1d: number;\n /** All-time high price */\n allTimeHigh: number;\n /** All-time low price */\n allTimeLow: number;\n /** 24h high price */\n high1d: number;\n /** 24h low price */\n low1d: number;\n /** Total trading volume */\n totalVolume: number;\n /** Circulating supply */\n circulatingSupply: number;\n /** Diluted market cap */\n dilutedMarketCap: number;\n};\n\n// ============================================================================\n// CLIENT OPTIONS\n// ============================================================================\n\nexport type ApiPlatformClientOptions = {\n /** Client product identifier (e.g., 'metamask-extension') */\n clientProduct: string;\n /** Optional client version */\n clientVersion?: string;\n /** Function to get bearer token for authenticated requests */\n getBearerToken?: () => Promise<string | undefined>;\n /**\n * Max time (ms) to wait for `getBearerToken` before sending the request\n * unauthenticated. The token keeps resolving in the background and is used by\n * later requests. Set to `0` to always wait for the token.\n * Defaults to {@link DEFAULT_AUTH_TOKEN_TIMEOUT}.\n */\n authTokenTimeout?: number;\n /** Optional custom QueryClient instance */\n queryClient?: QueryClient;\n};\n\n/**\n * Options for API fetch and query methods.\n * Extends TanStack Query options (e.g. select, initialPageParam, retry) so callers\n * can pass them through to useQuery / useInfiniteQuery. queryKey and queryFn are\n * always set by the client and cannot be overridden.\n * staleTime and gcTime are explicitly number (not function) so that client defaults apply without type conflicts.\n */\nexport type FetchOptions = {\n /** Custom stale time (ms). */\n staleTime?: number;\n /** Custom GC time (ms). */\n gcTime?: number;\n /**\n * When true, bypass caching for this request: the client-side query cache is\n * skipped (stale time defaults to 0) and, on endpoints that support it, a\n * random `bypassServerCache` query param is appended so server-side HTTP caches\n * (keyed on the full URL) miss. Use sparingly — only when a hard refresh is\n * required, e.g. right after a transaction confirms.\n */\n bypassServerCache?: boolean;\n} & Partial<\n Omit<\n FetchQueryOptions<unknown, Error, unknown>,\n 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'\n >\n> & {\n /** Allowed for infinite query options (e.g. useInfiniteQuery). */\n initialPageParam?: unknown;\n };\n\n/**\n * Returns options with queryKey and queryFn omitted, for merging into\n * get*QueryOptions return values without overwriting the client's queryKey/queryFn.\n * Return type is intentionally loose so that spreading into FetchQueryOptions<T>\n * does not conflict with T-specific option types (e.g. select, staleTime).\n *\n * @param options - Optional FetchOptions from the caller.\n * @returns Options safe to spread into query options, or undefined.\n */\nexport function getQueryOptionsOverrides(\n options?: FetchOptions,\n): Record<string, unknown> | undefined {\n if (options === null || options === undefined) {\n return undefined;\n }\n const {\n queryKey: _qk,\n queryFn: _qf,\n bypassServerCache: _bc,\n ...rest\n } = options as FetchOptions & {\n queryKey?: unknown;\n queryFn?: unknown;\n };\n return rest as Record<string, unknown>;\n}\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\n/** API Base URLs */\nexport const API_URLS = {\n ACCOUNTS: 'https://accounts.api.cx.metamask.io',\n PRICES: 'https://price.api.cx.metamask.io',\n TOKEN: 'https://token.api.cx.metamask.io',\n TOKENS: 'https://tokens.api.cx.metamask.io',\n} as const;\n\n/** Stale times for different data types (ms) */\nexport const STALE_TIMES = {\n PRICES: 30 * 1000, // 30 seconds\n BALANCES: 60 * 1000, // 1 minute\n NETWORKS: 10 * 60 * 1000, // 10 minutes\n SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes\n TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes\n TOKEN_LIST: 10 * 60 * 1000, // 10 minutes\n EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes\n TRENDING: 2 * 60 * 1000, // 2 minutes\n TRANSACTIONS: 30 * 1000, // 30 seconds\n DEFAULT: 30 * 1000, // 30 seconds\n} as const;\n\n/**\n * Default max time (ms) to wait for the bearer token before falling back to an\n * unauthenticated request.\n */\nexport const DEFAULT_AUTH_TOKEN_TIMEOUT = 500;\n\n/** Garbage collection times (ms) */\nexport const GC_TIMES = {\n DEFAULT: 5 * 60 * 1000, // 5 minutes\n EXTENDED: 30 * 60 * 1000, // 30 minutes\n SHORT: 2 * 60 * 1000, // 2 minutes\n} as const;\n\n/** Retry configuration */\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 3,\n BASE_DELAY: 1000,\n MAX_DELAY: 5_000,\n} as const;\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\n/**\n * Calculate retry delay with exponential backoff and jitter.\n *\n * @param attemptIndex - The current retry attempt (0-indexed).\n * @returns The delay in milliseconds before the next retry.\n */\nexport function calculateRetryDelay(attemptIndex: number): number {\n const delay = Math.min(\n RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex,\n RETRY_CONFIG.MAX_DELAY,\n );\n return delay / 2 + Math.random() * (delay / 2);\n}\n\n/**\n * Determine if a failed request should be retried.\n *\n * @param failureCount - The number of failures so far (1 = first failure).\n * @param error - The error from the failed request.\n * @returns True if the request should be retried, false otherwise.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n // Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)\n if (failureCount > RETRY_CONFIG.MAX_RETRIES) {\n return false;\n }\n\n if (error instanceof Error && 'status' in error) {\n const { status } = error as { status: number };\n // Don't retry 4xx except 429 (rate limit) and 408 (timeout)\n if (status >= 400 && status < 500 && status !== 429 && status !== 408) {\n return false;\n }\n }\n return true;\n}\n\n// ============================================================================\n// HTTP ERROR\n// ============================================================================\n\nexport class HttpError extends Error {\n readonly status: number;\n\n readonly statusText: string;\n\n readonly url: string;\n\n readonly body: unknown;\n\n constructor(\n message: string,\n status: number,\n statusText: string,\n url: string,\n body?: unknown,\n ) {\n super(message);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared-types.cjs","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAkKH;;;;;;;;GAQ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,OAAe,EACf,MAAc,EACd,UAAkB,EAClB,GAAW,EACX,IAAc;QAEd,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAvBD,8BAuBC","sourcesContent":["/**\n * Shared types, constants, and utilities for the API Platform Client.\n */\n\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/query-core';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\n/**\n * Pagination info for paginated responses\n */\nexport type PageInfo = {\n count: number;\n hasNextPage: boolean;\n cursor?: string;\n};\n\n/**\n * Supported currencies for Price API\n */\nexport type SupportedCurrency =\n // Crypto\n | 'btc'\n | 'eth'\n | 'ltc'\n | 'bch'\n | 'bnb'\n | 'eos'\n | 'xrp'\n | 'xlm'\n | 'link'\n | 'dot'\n | 'yfi'\n // Fiat\n | 'usd'\n | 'aed'\n | 'ars'\n | 'aud'\n | 'bdt'\n | 'bhd'\n | 'bmd'\n | 'brl'\n | 'cad'\n | 'chf'\n | 'clp'\n | 'cny'\n | 'czk'\n | 'dkk'\n | 'eur'\n | 'gbp'\n | 'gel'\n | 'hkd'\n | 'huf'\n | 'idr'\n | 'ils'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'kwd'\n | 'lkr'\n | 'mmk'\n | 'mxn'\n | 'myr'\n | 'ngn'\n | 'nok'\n | 'nzd'\n | 'php'\n | 'pkr'\n | 'pln'\n | 'rub'\n | 'sar'\n | 'sek'\n | 'sgd'\n | 'thb'\n | 'try'\n | 'twd'\n | 'uah'\n | 'vef'\n | 'vnd'\n | 'zar';\n\n/**\n * Market data details from Price API spot-prices endpoint\n */\nexport type MarketDataDetails = {\n /** Current price in the requested currency */\n price: number;\n /** Currency code (e.g., 'ETH', 'USD') */\n currency: string;\n /** 24h price change amount */\n priceChange1d: number;\n /** 24h price change percentage */\n pricePercentChange1d: number;\n /** 1h price change percentage */\n pricePercentChange1h: number;\n /** 7d price change percentage */\n pricePercentChange7d: number;\n /** 14d price change percentage */\n pricePercentChange14d: number;\n /** 30d price change percentage */\n pricePercentChange30d: number;\n /** 200d price change percentage */\n pricePercentChange200d: number;\n /** 1y price change percentage */\n pricePercentChange1y: number;\n /** Market capitalization */\n marketCap: number;\n /** Market cap 24h change percentage */\n marketCapPercentChange1d: number;\n /** All-time high price */\n allTimeHigh: number;\n /** All-time low price */\n allTimeLow: number;\n /** 24h high price */\n high1d: number;\n /** 24h low price */\n low1d: number;\n /** Total trading volume */\n totalVolume: number;\n /** Circulating supply */\n circulatingSupply: number;\n /** Diluted market cap */\n dilutedMarketCap: number;\n};\n\n// ============================================================================\n// CLIENT OPTIONS\n// ============================================================================\n\nexport type ApiPlatformClientOptions = {\n /** Client product identifier (e.g., 'metamask-extension') */\n clientProduct: string;\n /** Optional client version */\n clientVersion?: string;\n /** Function to get bearer token for authenticated requests */\n getBearerToken?: () => Promise<string | undefined>;\n /** Optional custom QueryClient instance */\n queryClient?: QueryClient;\n};\n\n/**\n * Options for API fetch and query methods.\n * Extends TanStack Query options (e.g. select, initialPageParam, retry) so callers\n * can pass them through to useQuery / useInfiniteQuery. queryKey and queryFn are\n * always set by the client and cannot be overridden.\n * staleTime and gcTime are explicitly number (not function) so that client defaults apply without type conflicts.\n */\nexport type FetchOptions = {\n /** Custom stale time (ms). */\n staleTime?: number;\n /** Custom GC time (ms). */\n gcTime?: number;\n} & Partial<\n Omit<\n FetchQueryOptions<unknown, Error, unknown>,\n 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'\n >\n> & {\n /** Allowed for infinite query options (e.g. useInfiniteQuery). */\n initialPageParam?: unknown;\n };\n\n/**\n * Returns options with queryKey and queryFn omitted, for merging into\n * get*QueryOptions return values without overwriting the client's queryKey/queryFn.\n * Return type is intentionally loose so that spreading into FetchQueryOptions<T>\n * does not conflict with T-specific option types (e.g. select, staleTime).\n *\n * @param options - Optional FetchOptions from the caller.\n * @returns Options safe to spread into query options, or undefined.\n */\nexport function getQueryOptionsOverrides(\n options?: FetchOptions,\n): Record<string, unknown> | undefined {\n if (options === null || options === undefined) {\n return undefined;\n }\n const {\n queryKey: _qk,\n queryFn: _qf,\n ...rest\n } = options as FetchOptions & {\n queryKey?: unknown;\n queryFn?: unknown;\n };\n return rest as Record<string, unknown>;\n}\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\n/** API Base URLs */\nexport const API_URLS = {\n ACCOUNTS: 'https://accounts.api.cx.metamask.io',\n PRICES: 'https://price.api.cx.metamask.io',\n TOKEN: 'https://token.api.cx.metamask.io',\n TOKENS: 'https://tokens.api.cx.metamask.io',\n} as const;\n\n/** Stale times for different data types (ms) */\nexport const STALE_TIMES = {\n AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token\n PRICES: 30 * 1000, // 30 seconds\n BALANCES: 60 * 1000, // 1 minute\n NETWORKS: 10 * 60 * 1000, // 10 minutes\n SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes\n TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes\n TOKEN_LIST: 10 * 60 * 1000, // 10 minutes\n EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes\n TRENDING: 2 * 60 * 1000, // 2 minutes\n TRANSACTIONS: 30 * 1000, // 30 seconds\n DEFAULT: 30 * 1000, // 30 seconds\n} as const;\n\n/** Garbage collection times (ms) */\nexport const GC_TIMES = {\n DEFAULT: 5 * 60 * 1000, // 5 minutes\n EXTENDED: 30 * 60 * 1000, // 30 minutes\n SHORT: 2 * 60 * 1000, // 2 minutes\n} as const;\n\n/** Retry configuration */\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 3,\n BASE_DELAY: 1000,\n MAX_DELAY: 5_000,\n} as const;\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\n/**\n * Calculate retry delay with exponential backoff and jitter.\n *\n * @param attemptIndex - The current retry attempt (0-indexed).\n * @returns The delay in milliseconds before the next retry.\n */\nexport function calculateRetryDelay(attemptIndex: number): number {\n const delay = Math.min(\n RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex,\n RETRY_CONFIG.MAX_DELAY,\n );\n return delay / 2 + Math.random() * (delay / 2);\n}\n\n/**\n * Determine if a failed request should be retried.\n *\n * @param failureCount - The number of failures so far (1 = first failure).\n * @param error - The error from the failed request.\n * @returns True if the request should be retried, false otherwise.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n // Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)\n if (failureCount > RETRY_CONFIG.MAX_RETRIES) {\n return false;\n }\n\n if (error instanceof Error && 'status' in error) {\n const { status } = error as { status: number };\n // Don't retry 4xx except 429 (rate limit) and 408 (timeout)\n if (status >= 400 && status < 500 && status !== 429 && status !== 408) {\n return false;\n }\n }\n return true;\n}\n\n// ============================================================================\n// HTTP ERROR\n// ============================================================================\n\nexport class HttpError extends Error {\n readonly status: number;\n\n readonly statusText: string;\n\n readonly url: string;\n\n readonly body: unknown;\n\n constructor(\n message: string,\n status: number,\n statusText: string,\n url: string,\n body?: unknown,\n ) {\n super(message);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n"]}
|
|
@@ -64,13 +64,6 @@ export type ApiPlatformClientOptions = {
|
|
|
64
64
|
clientVersion?: string;
|
|
65
65
|
/** Function to get bearer token for authenticated requests */
|
|
66
66
|
getBearerToken?: () => Promise<string | undefined>;
|
|
67
|
-
/**
|
|
68
|
-
* Max time (ms) to wait for `getBearerToken` before sending the request
|
|
69
|
-
* unauthenticated. The token keeps resolving in the background and is used by
|
|
70
|
-
* later requests. Set to `0` to always wait for the token.
|
|
71
|
-
* Defaults to {@link DEFAULT_AUTH_TOKEN_TIMEOUT}.
|
|
72
|
-
*/
|
|
73
|
-
authTokenTimeout?: number;
|
|
74
67
|
/** Optional custom QueryClient instance */
|
|
75
68
|
queryClient?: QueryClient;
|
|
76
69
|
};
|
|
@@ -86,14 +79,6 @@ export type FetchOptions = {
|
|
|
86
79
|
staleTime?: number;
|
|
87
80
|
/** Custom GC time (ms). */
|
|
88
81
|
gcTime?: number;
|
|
89
|
-
/**
|
|
90
|
-
* When true, bypass caching for this request: the client-side query cache is
|
|
91
|
-
* skipped (stale time defaults to 0) and, on endpoints that support it, a
|
|
92
|
-
* random `bypassServerCache` query param is appended so server-side HTTP caches
|
|
93
|
-
* (keyed on the full URL) miss. Use sparingly — only when a hard refresh is
|
|
94
|
-
* required, e.g. right after a transaction confirms.
|
|
95
|
-
*/
|
|
96
|
-
bypassServerCache?: boolean;
|
|
97
82
|
} & Partial<Omit<FetchQueryOptions<unknown, Error, unknown>, 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'>> & {
|
|
98
83
|
/** Allowed for infinite query options (e.g. useInfiniteQuery). */
|
|
99
84
|
initialPageParam?: unknown;
|
|
@@ -117,6 +102,7 @@ export declare const API_URLS: {
|
|
|
117
102
|
};
|
|
118
103
|
/** Stale times for different data types (ms) */
|
|
119
104
|
export declare const STALE_TIMES: {
|
|
105
|
+
readonly AUTH_TOKEN: number;
|
|
120
106
|
readonly PRICES: number;
|
|
121
107
|
readonly BALANCES: number;
|
|
122
108
|
readonly NETWORKS: number;
|
|
@@ -128,11 +114,6 @@ export declare const STALE_TIMES: {
|
|
|
128
114
|
readonly TRANSACTIONS: number;
|
|
129
115
|
readonly DEFAULT: number;
|
|
130
116
|
};
|
|
131
|
-
/**
|
|
132
|
-
* Default max time (ms) to wait for the bearer token before falling back to an
|
|
133
|
-
* unauthenticated request.
|
|
134
|
-
*/
|
|
135
|
-
export declare const DEFAULT_AUTH_TOKEN_TIMEOUT = 500;
|
|
136
117
|
/** Garbage collection times (ms) */
|
|
137
118
|
export declare const GC_TIMES: {
|
|
138
119
|
readonly DEFAULT: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-types.d.cts","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,6BAA6B;AAM3E;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAEzB,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL,KAAK,GAEL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,kCAAkC;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AM,QAAQ;;;;;CAKX,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,WAAW;;;;;;;;;;;;CAYd,CAAC;AAEX,oCAAoC;AACpC,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,0BAA0B;AAC1B,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAMX;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAczE;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO;CASjB"}
|
|
@@ -64,13 +64,6 @@ export type ApiPlatformClientOptions = {
|
|
|
64
64
|
clientVersion?: string;
|
|
65
65
|
/** Function to get bearer token for authenticated requests */
|
|
66
66
|
getBearerToken?: () => Promise<string | undefined>;
|
|
67
|
-
/**
|
|
68
|
-
* Max time (ms) to wait for `getBearerToken` before sending the request
|
|
69
|
-
* unauthenticated. The token keeps resolving in the background and is used by
|
|
70
|
-
* later requests. Set to `0` to always wait for the token.
|
|
71
|
-
* Defaults to {@link DEFAULT_AUTH_TOKEN_TIMEOUT}.
|
|
72
|
-
*/
|
|
73
|
-
authTokenTimeout?: number;
|
|
74
67
|
/** Optional custom QueryClient instance */
|
|
75
68
|
queryClient?: QueryClient;
|
|
76
69
|
};
|
|
@@ -86,14 +79,6 @@ export type FetchOptions = {
|
|
|
86
79
|
staleTime?: number;
|
|
87
80
|
/** Custom GC time (ms). */
|
|
88
81
|
gcTime?: number;
|
|
89
|
-
/**
|
|
90
|
-
* When true, bypass caching for this request: the client-side query cache is
|
|
91
|
-
* skipped (stale time defaults to 0) and, on endpoints that support it, a
|
|
92
|
-
* random `bypassServerCache` query param is appended so server-side HTTP caches
|
|
93
|
-
* (keyed on the full URL) miss. Use sparingly — only when a hard refresh is
|
|
94
|
-
* required, e.g. right after a transaction confirms.
|
|
95
|
-
*/
|
|
96
|
-
bypassServerCache?: boolean;
|
|
97
82
|
} & Partial<Omit<FetchQueryOptions<unknown, Error, unknown>, 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'>> & {
|
|
98
83
|
/** Allowed for infinite query options (e.g. useInfiniteQuery). */
|
|
99
84
|
initialPageParam?: unknown;
|
|
@@ -117,6 +102,7 @@ export declare const API_URLS: {
|
|
|
117
102
|
};
|
|
118
103
|
/** Stale times for different data types (ms) */
|
|
119
104
|
export declare const STALE_TIMES: {
|
|
105
|
+
readonly AUTH_TOKEN: number;
|
|
120
106
|
readonly PRICES: number;
|
|
121
107
|
readonly BALANCES: number;
|
|
122
108
|
readonly NETWORKS: number;
|
|
@@ -128,11 +114,6 @@ export declare const STALE_TIMES: {
|
|
|
128
114
|
readonly TRANSACTIONS: number;
|
|
129
115
|
readonly DEFAULT: number;
|
|
130
116
|
};
|
|
131
|
-
/**
|
|
132
|
-
* Default max time (ms) to wait for the bearer token before falling back to an
|
|
133
|
-
* unauthenticated request.
|
|
134
|
-
*/
|
|
135
|
-
export declare const DEFAULT_AUTH_TOKEN_TIMEOUT = 500;
|
|
136
117
|
/** Garbage collection times (ms) */
|
|
137
118
|
export declare const GC_TIMES: {
|
|
138
119
|
readonly DEFAULT: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-types.d.mts","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBA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;;CAIf,CAAC;AAMX;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAczE;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO;CASjB"}
|
|
@@ -14,7 +14,7 @@ export function getQueryOptionsOverrides(options) {
|
|
|
14
14
|
if (options === null || options === undefined) {
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
|
-
const { queryKey: _qk, queryFn: _qf,
|
|
17
|
+
const { queryKey: _qk, queryFn: _qf, ...rest } = options;
|
|
18
18
|
return rest;
|
|
19
19
|
}
|
|
20
20
|
// ============================================================================
|
|
@@ -29,6 +29,7 @@ export const API_URLS = {
|
|
|
29
29
|
};
|
|
30
30
|
/** Stale times for different data types (ms) */
|
|
31
31
|
export const STALE_TIMES = {
|
|
32
|
+
AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token
|
|
32
33
|
PRICES: 30 * 1000, // 30 seconds
|
|
33
34
|
BALANCES: 60 * 1000, // 1 minute
|
|
34
35
|
NETWORKS: 10 * 60 * 1000, // 10 minutes
|
|
@@ -40,11 +41,6 @@ export const STALE_TIMES = {
|
|
|
40
41
|
TRANSACTIONS: 30 * 1000, // 30 seconds
|
|
41
42
|
DEFAULT: 30 * 1000, // 30 seconds
|
|
42
43
|
};
|
|
43
|
-
/**
|
|
44
|
-
* Default max time (ms) to wait for the bearer token before falling back to an
|
|
45
|
-
* unauthenticated request.
|
|
46
|
-
*/
|
|
47
|
-
export const DEFAULT_AUTH_TOKEN_TIMEOUT = 500;
|
|
48
44
|
/** Garbage collection times (ms) */
|
|
49
45
|
export const GC_TIMES = {
|
|
50
46
|
DEFAULT: 5 * 60 * 1000, // 5 minutes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-types.mjs","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiLH;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAsB;IAEtB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,EACJ,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,GAAG,EACZ,iBAAiB,EAAE,GAAG,EACtB,GAAG,IAAI,EACR,GAAG,OAGH,CAAC;IACF,OAAO,IAA+B,CAAC;AACzC,CAAC;AAED,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,oBAAoB;AACpB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,qCAAqC;IAC/C,MAAM,EAAE,kCAAkC;IAC1C,KAAK,EAAE,kCAAkC;IACzC,MAAM,EAAE,mCAAmC;CACnC,CAAC;AAEX,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,aAAa;IAChC,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,WAAW;IAChC,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;IACvC,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;IACjD,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;IAC3C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AC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;QAChD,MAAM,EAAE,MAAM,EAAE,GAAG,KAA2B,CAAC;QAC/C,4DAA4D;QAC5D,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,OAAO,SAAU,SAAQ,KAAK;IASlC,YACE,OAAe,EACf,MAAc,EACd,UAAkB,EAClB,GAAW,EACX,IAAc;QAEd,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["/**\n * Shared types, constants, and utilities for the API Platform Client.\n */\n\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/query-core';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\n/**\n * Pagination info for paginated responses\n */\nexport type PageInfo = {\n count: number;\n hasNextPage: boolean;\n cursor?: string;\n};\n\n/**\n * Supported currencies for Price API\n */\nexport type SupportedCurrency =\n // Crypto\n | 'btc'\n | 'eth'\n | 'ltc'\n | 'bch'\n | 'bnb'\n | 'eos'\n | 'xrp'\n | 'xlm'\n | 'link'\n | 'dot'\n | 'yfi'\n // Fiat\n | 'usd'\n | 'aed'\n | 'ars'\n | 'aud'\n | 'bdt'\n | 'bhd'\n | 'bmd'\n | 'brl'\n | 'cad'\n | 'chf'\n | 'clp'\n | 'cny'\n | 'czk'\n | 'dkk'\n | 'eur'\n | 'gbp'\n | 'gel'\n | 'hkd'\n | 'huf'\n | 'idr'\n | 'ils'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'kwd'\n | 'lkr'\n | 'mmk'\n | 'mxn'\n | 'myr'\n | 'ngn'\n | 'nok'\n | 'nzd'\n | 'php'\n | 'pkr'\n | 'pln'\n | 'rub'\n | 'sar'\n | 'sek'\n | 'sgd'\n | 'thb'\n | 'try'\n | 'twd'\n | 'uah'\n | 'vef'\n | 'vnd'\n | 'zar';\n\n/**\n * Market data details from Price API spot-prices endpoint\n */\nexport type MarketDataDetails = {\n /** Current price in the requested currency */\n price: number;\n /** Currency code (e.g., 'ETH', 'USD') */\n currency: string;\n /** 24h price change amount */\n priceChange1d: number;\n /** 24h price change percentage */\n pricePercentChange1d: number;\n /** 1h price change percentage */\n pricePercentChange1h: number;\n /** 7d price change percentage */\n pricePercentChange7d: number;\n /** 14d price change percentage */\n pricePercentChange14d: number;\n /** 30d price change percentage */\n pricePercentChange30d: number;\n /** 200d price change percentage */\n pricePercentChange200d: number;\n /** 1y price change percentage */\n pricePercentChange1y: number;\n /** Market capitalization */\n marketCap: number;\n /** Market cap 24h change percentage */\n marketCapPercentChange1d: number;\n /** All-time high price */\n allTimeHigh: number;\n /** All-time low price */\n allTimeLow: number;\n /** 24h high price */\n high1d: number;\n /** 24h low price */\n low1d: number;\n /** Total trading volume */\n totalVolume: number;\n /** Circulating supply */\n circulatingSupply: number;\n /** Diluted market cap */\n dilutedMarketCap: number;\n};\n\n// ============================================================================\n// CLIENT OPTIONS\n// ============================================================================\n\nexport type ApiPlatformClientOptions = {\n /** Client product identifier (e.g., 'metamask-extension') */\n clientProduct: string;\n /** Optional client version */\n clientVersion?: string;\n /** Function to get bearer token for authenticated requests */\n getBearerToken?: () => Promise<string | undefined>;\n /**\n * Max time (ms) to wait for `getBearerToken` before sending the request\n * unauthenticated. The token keeps resolving in the background and is used by\n * later requests. Set to `0` to always wait for the token.\n * Defaults to {@link DEFAULT_AUTH_TOKEN_TIMEOUT}.\n */\n authTokenTimeout?: number;\n /** Optional custom QueryClient instance */\n queryClient?: QueryClient;\n};\n\n/**\n * Options for API fetch and query methods.\n * Extends TanStack Query options (e.g. select, initialPageParam, retry) so callers\n * can pass them through to useQuery / useInfiniteQuery. queryKey and queryFn are\n * always set by the client and cannot be overridden.\n * staleTime and gcTime are explicitly number (not function) so that client defaults apply without type conflicts.\n */\nexport type FetchOptions = {\n /** Custom stale time (ms). */\n staleTime?: number;\n /** Custom GC time (ms). */\n gcTime?: number;\n /**\n * When true, bypass caching for this request: the client-side query cache is\n * skipped (stale time defaults to 0) and, on endpoints that support it, a\n * random `bypassServerCache` query param is appended so server-side HTTP caches\n * (keyed on the full URL) miss. Use sparingly — only when a hard refresh is\n * required, e.g. right after a transaction confirms.\n */\n bypassServerCache?: boolean;\n} & Partial<\n Omit<\n FetchQueryOptions<unknown, Error, unknown>,\n 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'\n >\n> & {\n /** Allowed for infinite query options (e.g. useInfiniteQuery). */\n initialPageParam?: unknown;\n };\n\n/**\n * Returns options with queryKey and queryFn omitted, for merging into\n * get*QueryOptions return values without overwriting the client's queryKey/queryFn.\n * Return type is intentionally loose so that spreading into FetchQueryOptions<T>\n * does not conflict with T-specific option types (e.g. select, staleTime).\n *\n * @param options - Optional FetchOptions from the caller.\n * @returns Options safe to spread into query options, or undefined.\n */\nexport function getQueryOptionsOverrides(\n options?: FetchOptions,\n): Record<string, unknown> | undefined {\n if (options === null || options === undefined) {\n return undefined;\n }\n const {\n queryKey: _qk,\n queryFn: _qf,\n bypassServerCache: _bc,\n ...rest\n } = options as FetchOptions & {\n queryKey?: unknown;\n queryFn?: unknown;\n };\n return rest as Record<string, unknown>;\n}\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\n/** API Base URLs */\nexport const API_URLS = {\n ACCOUNTS: 'https://accounts.api.cx.metamask.io',\n PRICES: 'https://price.api.cx.metamask.io',\n TOKEN: 'https://token.api.cx.metamask.io',\n TOKENS: 'https://tokens.api.cx.metamask.io',\n} as const;\n\n/** Stale times for different data types (ms) */\nexport const STALE_TIMES = {\n PRICES: 30 * 1000, // 30 seconds\n BALANCES: 60 * 1000, // 1 minute\n NETWORKS: 10 * 60 * 1000, // 10 minutes\n SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes\n TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes\n TOKEN_LIST: 10 * 60 * 1000, // 10 minutes\n EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes\n TRENDING: 2 * 60 * 1000, // 2 minutes\n TRANSACTIONS: 30 * 1000, // 30 seconds\n DEFAULT: 30 * 1000, // 30 seconds\n} as const;\n\n/**\n * Default max time (ms) to wait for the bearer token before falling back to an\n * unauthenticated request.\n */\nexport const DEFAULT_AUTH_TOKEN_TIMEOUT = 500;\n\n/** Garbage collection times (ms) */\nexport const GC_TIMES = {\n DEFAULT: 5 * 60 * 1000, // 5 minutes\n EXTENDED: 30 * 60 * 1000, // 30 minutes\n SHORT: 2 * 60 * 1000, // 2 minutes\n} as const;\n\n/** Retry configuration */\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 3,\n BASE_DELAY: 1000,\n MAX_DELAY: 5_000,\n} as const;\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\n/**\n * Calculate retry delay with exponential backoff and jitter.\n *\n * @param attemptIndex - The current retry attempt (0-indexed).\n * @returns The delay in milliseconds before the next retry.\n */\nexport function calculateRetryDelay(attemptIndex: number): number {\n const delay = Math.min(\n RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex,\n RETRY_CONFIG.MAX_DELAY,\n );\n return delay / 2 + Math.random() * (delay / 2);\n}\n\n/**\n * Determine if a failed request should be retried.\n *\n * @param failureCount - The number of failures so far (1 = first failure).\n * @param error - The error from the failed request.\n * @returns True if the request should be retried, false otherwise.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n // Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)\n if (failureCount > RETRY_CONFIG.MAX_RETRIES) {\n return false;\n }\n\n if (error instanceof Error && 'status' in error) {\n const { status } = error as { status: number };\n // Don't retry 4xx except 429 (rate limit) and 408 (timeout)\n if (status >= 400 && status < 500 && status !== 429 && status !== 408) {\n return false;\n }\n }\n return true;\n}\n\n// ============================================================================\n// HTTP ERROR\n// ============================================================================\n\nexport class HttpError extends Error {\n readonly status: number;\n\n readonly statusText: string;\n\n readonly url: string;\n\n readonly body: unknown;\n\n constructor(\n message: string,\n status: number,\n statusText: string,\n url: string,\n body?: unknown,\n ) {\n super(message);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared-types.mjs","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkKH;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAsB;IAEtB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,EACJ,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,GAAG,EACZ,GAAG,IAAI,EACR,GAAG,OAGH,CAAC;IACF,OAAO,IAA+B,CAAC;AACzC,CAAC;AAED,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,oBAAoB;AACpB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,qCAAqC;IAC/C,MAAM,EAAE,kCAAkC;IAC1C,KAAK,EAAE,kCAAkC;IACzC,MAAM,EAAE,mCAAmC;CACnC,CAAC;AAEX,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,mCAAmC;IAC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M,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB,EAAE,KAAc;IAC9D,+EAA+E;IAC/E,IAAI,YAAY,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;QAChD,MAAM,EAAE,MAAM,EAAE,GAAG,KAA2B,CAAC;QAC/C,4DAA4D;QAC5D,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,OAAO,SAAU,SAAQ,KAAK;IASlC,YACE,OAAe,EACf,MAAc,EACd,UAAkB,EAClB,GAAW,EACX,IAAc;QAEd,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF","sourcesContent":["/**\n * Shared types, constants, and utilities for the API Platform Client.\n */\n\nimport type { FetchQueryOptions, QueryClient } from '@tanstack/query-core';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\n/**\n * Pagination info for paginated responses\n */\nexport type PageInfo = {\n count: number;\n hasNextPage: boolean;\n cursor?: string;\n};\n\n/**\n * Supported currencies for Price API\n */\nexport type SupportedCurrency =\n // Crypto\n | 'btc'\n | 'eth'\n | 'ltc'\n | 'bch'\n | 'bnb'\n | 'eos'\n | 'xrp'\n | 'xlm'\n | 'link'\n | 'dot'\n | 'yfi'\n // Fiat\n | 'usd'\n | 'aed'\n | 'ars'\n | 'aud'\n | 'bdt'\n | 'bhd'\n | 'bmd'\n | 'brl'\n | 'cad'\n | 'chf'\n | 'clp'\n | 'cny'\n | 'czk'\n | 'dkk'\n | 'eur'\n | 'gbp'\n | 'gel'\n | 'hkd'\n | 'huf'\n | 'idr'\n | 'ils'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'kwd'\n | 'lkr'\n | 'mmk'\n | 'mxn'\n | 'myr'\n | 'ngn'\n | 'nok'\n | 'nzd'\n | 'php'\n | 'pkr'\n | 'pln'\n | 'rub'\n | 'sar'\n | 'sek'\n | 'sgd'\n | 'thb'\n | 'try'\n | 'twd'\n | 'uah'\n | 'vef'\n | 'vnd'\n | 'zar';\n\n/**\n * Market data details from Price API spot-prices endpoint\n */\nexport type MarketDataDetails = {\n /** Current price in the requested currency */\n price: number;\n /** Currency code (e.g., 'ETH', 'USD') */\n currency: string;\n /** 24h price change amount */\n priceChange1d: number;\n /** 24h price change percentage */\n pricePercentChange1d: number;\n /** 1h price change percentage */\n pricePercentChange1h: number;\n /** 7d price change percentage */\n pricePercentChange7d: number;\n /** 14d price change percentage */\n pricePercentChange14d: number;\n /** 30d price change percentage */\n pricePercentChange30d: number;\n /** 200d price change percentage */\n pricePercentChange200d: number;\n /** 1y price change percentage */\n pricePercentChange1y: number;\n /** Market capitalization */\n marketCap: number;\n /** Market cap 24h change percentage */\n marketCapPercentChange1d: number;\n /** All-time high price */\n allTimeHigh: number;\n /** All-time low price */\n allTimeLow: number;\n /** 24h high price */\n high1d: number;\n /** 24h low price */\n low1d: number;\n /** Total trading volume */\n totalVolume: number;\n /** Circulating supply */\n circulatingSupply: number;\n /** Diluted market cap */\n dilutedMarketCap: number;\n};\n\n// ============================================================================\n// CLIENT OPTIONS\n// ============================================================================\n\nexport type ApiPlatformClientOptions = {\n /** Client product identifier (e.g., 'metamask-extension') */\n clientProduct: string;\n /** Optional client version */\n clientVersion?: string;\n /** Function to get bearer token for authenticated requests */\n getBearerToken?: () => Promise<string | undefined>;\n /** Optional custom QueryClient instance */\n queryClient?: QueryClient;\n};\n\n/**\n * Options for API fetch and query methods.\n * Extends TanStack Query options (e.g. select, initialPageParam, retry) so callers\n * can pass them through to useQuery / useInfiniteQuery. queryKey and queryFn are\n * always set by the client and cannot be overridden.\n * staleTime and gcTime are explicitly number (not function) so that client defaults apply without type conflicts.\n */\nexport type FetchOptions = {\n /** Custom stale time (ms). */\n staleTime?: number;\n /** Custom GC time (ms). */\n gcTime?: number;\n} & Partial<\n Omit<\n FetchQueryOptions<unknown, Error, unknown>,\n 'queryKey' | 'queryFn' | 'staleTime' | 'gcTime'\n >\n> & {\n /** Allowed for infinite query options (e.g. useInfiniteQuery). */\n initialPageParam?: unknown;\n };\n\n/**\n * Returns options with queryKey and queryFn omitted, for merging into\n * get*QueryOptions return values without overwriting the client's queryKey/queryFn.\n * Return type is intentionally loose so that spreading into FetchQueryOptions<T>\n * does not conflict with T-specific option types (e.g. select, staleTime).\n *\n * @param options - Optional FetchOptions from the caller.\n * @returns Options safe to spread into query options, or undefined.\n */\nexport function getQueryOptionsOverrides(\n options?: FetchOptions,\n): Record<string, unknown> | undefined {\n if (options === null || options === undefined) {\n return undefined;\n }\n const {\n queryKey: _qk,\n queryFn: _qf,\n ...rest\n } = options as FetchOptions & {\n queryKey?: unknown;\n queryFn?: unknown;\n };\n return rest as Record<string, unknown>;\n}\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\n/** API Base URLs */\nexport const API_URLS = {\n ACCOUNTS: 'https://accounts.api.cx.metamask.io',\n PRICES: 'https://price.api.cx.metamask.io',\n TOKEN: 'https://token.api.cx.metamask.io',\n TOKENS: 'https://tokens.api.cx.metamask.io',\n} as const;\n\n/** Stale times for different data types (ms) */\nexport const STALE_TIMES = {\n AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token\n PRICES: 30 * 1000, // 30 seconds\n BALANCES: 60 * 1000, // 1 minute\n NETWORKS: 10 * 60 * 1000, // 10 minutes\n SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes\n TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes\n TOKEN_LIST: 10 * 60 * 1000, // 10 minutes\n EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes\n TRENDING: 2 * 60 * 1000, // 2 minutes\n TRANSACTIONS: 30 * 1000, // 30 seconds\n DEFAULT: 30 * 1000, // 30 seconds\n} as const;\n\n/** Garbage collection times (ms) */\nexport const GC_TIMES = {\n DEFAULT: 5 * 60 * 1000, // 5 minutes\n EXTENDED: 30 * 60 * 1000, // 30 minutes\n SHORT: 2 * 60 * 1000, // 2 minutes\n} as const;\n\n/** Retry configuration */\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 3,\n BASE_DELAY: 1000,\n MAX_DELAY: 5_000,\n} as const;\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\n/**\n * Calculate retry delay with exponential backoff and jitter.\n *\n * @param attemptIndex - The current retry attempt (0-indexed).\n * @returns The delay in milliseconds before the next retry.\n */\nexport function calculateRetryDelay(attemptIndex: number): number {\n const delay = Math.min(\n RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex,\n RETRY_CONFIG.MAX_DELAY,\n );\n return delay / 2 + Math.random() * (delay / 2);\n}\n\n/**\n * Determine if a failed request should be retried.\n *\n * @param failureCount - The number of failures so far (1 = first failure).\n * @param error - The error from the failed request.\n * @returns True if the request should be retried, false otherwise.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n // Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)\n if (failureCount > RETRY_CONFIG.MAX_RETRIES) {\n return false;\n }\n\n if (error instanceof Error && 'status' in error) {\n const { status } = error as { status: number };\n // Don't retry 4xx except 429 (rate limit) and 408 (timeout)\n if (status >= 400 && status < 500 && status !== 429 && status !== 408) {\n return false;\n }\n }\n return true;\n}\n\n// ============================================================================\n// HTTP ERROR\n// ============================================================================\n\nexport class HttpError extends Error {\n readonly status: number;\n\n readonly statusText: string;\n\n readonly url: string;\n\n readonly body: unknown;\n\n constructor(\n message: string,\n status: number,\n statusText: string,\n url: string,\n body?: unknown,\n ) {\n super(message);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n"]}
|
|
@@ -147,7 +147,9 @@ class AccountActivityService {
|
|
|
147
147
|
// Promise result intentionally not awaited
|
|
148
148
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
149
149
|
(connectionInfo) => __classPrivateFieldGet(this, _AccountActivityService_instances, "m", _AccountActivityService_handleWebSocketStateChange).call(this, connectionInfo));
|
|
150
|
-
__classPrivateFieldGet(this, _AccountActivityService_messenger, "f").subscribe(
|
|
150
|
+
__classPrivateFieldGet(this, _AccountActivityService_messenger, "f").subscribe(
|
|
151
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
152
|
+
'RemoteFeatureFlagController:stateChange',
|
|
151
153
|
// Promise result intentionally not awaited
|
|
152
154
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
153
155
|
async () => await __classPrivateFieldGet(this, _AccountActivityService_instances, "m", _AccountActivityService_handleFeatureFlagsStateChange).call(this),
|