@metamask-previews/core-backend 11.0.0-preview-ed70ef231 → 11.0.0-preview-ff2ab0583
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 +2 -1
- package/dist/api/shared-types.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
12
|
- Bump `uuid` from `^9.0.1` to `^11.1.1` ([#10243](https://github.com/MetaMask/core/pull/10243))
|
|
13
|
-
- Bump `@metamask/profile-sync-controller` from `^32.1.1` to `^
|
|
13
|
+
- Bump `@metamask/profile-sync-controller` from `^32.1.1` to `^33.0.0` ([#10348](https://github.com/MetaMask/core/pull/10348), [#10409](https://github.com/MetaMask/core/pull/10409), [#10418](https://github.com/MetaMask/core/pull/10418), [#10459](https://github.com/MetaMask/core/pull/10459))
|
|
14
14
|
- Bump `@tanstack/query-core` from `^5.62.16` to `^5.89.0` ([#9324](https://github.com/MetaMask/core/pull/9324))
|
|
15
15
|
- Bump `@metamask/keyring-controller` from `^28.0.0` to `^28.1.0` ([#10418](https://github.com/MetaMask/core/pull/10418))
|
|
16
16
|
- Bump `cockatiel` from `^3.1.2` to `^3.2.1` ([#10436](https://github.com/MetaMask/core/pull/10436))
|
|
17
|
+
- Bump `@metamask/account-tree-controller` from `^10.0.1` to `^11.0.0` ([#10459](https://github.com/MetaMask/core/pull/10459))
|
|
17
18
|
|
|
18
19
|
## [11.0.0]
|
|
19
20
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-types.js","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0LH;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAsB;IAEtB,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KA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EnB,GAAG,CAAS;IAEZ,IAAI,CAAU;IAEvB,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 * Optional overrides for the API base URLs. Any service not specified falls\n * back to the production URL in {@link API_URLS}. Useful for pointing\n * clients at dev/local backend environments (e.g. via client env vars).\n */\n apiUrls?: Partial<ApiUrls>;\n};\n\n/** Map of API service names to their base URLs. */\nexport type ApiUrls = { [Service in keyof typeof API_URLS]: string };\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.js","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0LH;;;;;;;;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,IAAI,CAAC;AACd,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,EAA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AAY,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;IACzB,MAAM,CAAS;IAEf,UAAU,CAAS;IAEnB,GAAG,CAAS;IAEZ,IAAI,CAAU;IAEvB,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 * Optional overrides for the API base URLs. Any service not specified falls\n * back to the production URL in {@link API_URLS}. Useful for pointing\n * clients at dev/local backend environments (e.g. via client env vars).\n */\n apiUrls?: Partial<ApiUrls>;\n};\n\n/** Map of API service names to their base URLs. */\nexport type ApiUrls = { [Service in keyof typeof API_URLS]: string };\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;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/core-backend",
|
|
3
|
-
"version": "11.0.0-preview-
|
|
3
|
+
"version": "11.0.0-preview-ff2ab0583",
|
|
4
4
|
"description": "Core backend services for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@metamask/account-tree-controller": "^
|
|
53
|
+
"@metamask/account-tree-controller": "^11.0.0",
|
|
54
54
|
"@metamask/controller-utils": "^13.0.0",
|
|
55
55
|
"@metamask/keyring-controller": "^28.1.0",
|
|
56
56
|
"@metamask/messenger": "^3.0.0",
|
|
57
|
-
"@metamask/profile-sync-controller": "^
|
|
57
|
+
"@metamask/profile-sync-controller": "^33.0.0",
|
|
58
58
|
"@metamask/remote-feature-flag-controller": "^7.0.0",
|
|
59
59
|
"@metamask/utils": "^12.0.0",
|
|
60
60
|
"@tanstack/query-core": "^5.89.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@metamask/auto-changelog": "^6.2.1",
|
|
67
67
|
"@types/jest": "^30.0.0",
|
|
68
68
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
69
|
-
"deepmerge": "^4.
|
|
69
|
+
"deepmerge": "^4.3.1",
|
|
70
70
|
"jest": "^30.4.2",
|
|
71
71
|
"jest-environment-jsdom": "^30.4.1",
|
|
72
72
|
"rimraf": "^6.1.3",
|