@metamask-previews/core-backend 5.0.0-preview-cd0d0950 → 5.0.0-preview-91e0d8c4
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 +3 -12
- package/README.md +1 -252
- package/dist/index.cjs +4 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/api/ApiPlatformClient.cjs +0 -177
- package/dist/api/ApiPlatformClient.cjs.map +0 -1
- package/dist/api/ApiPlatformClient.d.cts +0 -127
- package/dist/api/ApiPlatformClient.d.cts.map +0 -1
- package/dist/api/ApiPlatformClient.d.mts +0 -127
- package/dist/api/ApiPlatformClient.d.mts.map +0 -1
- package/dist/api/ApiPlatformClient.mjs +0 -172
- package/dist/api/ApiPlatformClient.mjs.map +0 -1
- package/dist/api/accounts/client.cjs +0 -492
- package/dist/api/accounts/client.cjs.map +0 -1
- package/dist/api/accounts/client.d.cts +0 -213
- package/dist/api/accounts/client.d.cts.map +0 -1
- package/dist/api/accounts/client.d.mts +0 -213
- package/dist/api/accounts/client.d.mts.map +0 -1
- package/dist/api/accounts/client.mjs +0 -488
- package/dist/api/accounts/client.mjs.map +0 -1
- package/dist/api/accounts/index.cjs +0 -9
- package/dist/api/accounts/index.cjs.map +0 -1
- package/dist/api/accounts/index.d.cts +0 -6
- package/dist/api/accounts/index.d.cts.map +0 -1
- package/dist/api/accounts/index.d.mts +0 -6
- package/dist/api/accounts/index.d.mts.map +0 -1
- package/dist/api/accounts/index.mjs +0 -5
- package/dist/api/accounts/index.mjs.map +0 -1
- package/dist/api/accounts/types.cjs +0 -7
- package/dist/api/accounts/types.cjs.map +0 -1
- package/dist/api/accounts/types.d.cts +0 -195
- package/dist/api/accounts/types.d.cts.map +0 -1
- package/dist/api/accounts/types.d.mts +0 -195
- package/dist/api/accounts/types.d.mts.map +0 -1
- package/dist/api/accounts/types.mjs +0 -6
- package/dist/api/accounts/types.mjs.map +0 -1
- package/dist/api/base-client.cjs +0 -149
- package/dist/api/base-client.cjs.map +0 -1
- package/dist/api/base-client.d.cts +0 -54
- package/dist/api/base-client.d.cts.map +0 -1
- package/dist/api/base-client.d.mts +0 -54
- package/dist/api/base-client.d.mts.map +0 -1
- package/dist/api/base-client.mjs +0 -143
- package/dist/api/base-client.mjs.map +0 -1
- package/dist/api/index.cjs +0 -35
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.d.cts +0 -18
- package/dist/api/index.d.cts.map +0 -1
- package/dist/api/index.d.mts +0 -18
- package/dist/api/index.d.mts.map +0 -1
- package/dist/api/index.mjs +0 -18
- package/dist/api/index.mjs.map +0 -1
- package/dist/api/prices/client.cjs +0 -521
- package/dist/api/prices/client.cjs.map +0 -1
- package/dist/api/prices/client.d.cts +0 -235
- package/dist/api/prices/client.d.cts.map +0 -1
- package/dist/api/prices/client.d.mts +0 -235
- package/dist/api/prices/client.d.mts.map +0 -1
- package/dist/api/prices/client.mjs +0 -517
- package/dist/api/prices/client.mjs.map +0 -1
- package/dist/api/prices/index.cjs +0 -9
- package/dist/api/prices/index.cjs.map +0 -1
- package/dist/api/prices/index.d.cts +0 -6
- package/dist/api/prices/index.d.cts.map +0 -1
- package/dist/api/prices/index.d.mts +0 -6
- package/dist/api/prices/index.d.mts.map +0 -1
- package/dist/api/prices/index.mjs +0 -5
- package/dist/api/prices/index.mjs.map +0 -1
- package/dist/api/prices/types.cjs +0 -7
- package/dist/api/prices/types.cjs.map +0 -1
- package/dist/api/prices/types.d.cts +0 -61
- package/dist/api/prices/types.d.cts.map +0 -1
- package/dist/api/prices/types.d.mts +0 -61
- package/dist/api/prices/types.d.mts.map +0 -1
- package/dist/api/prices/types.mjs +0 -6
- package/dist/api/prices/types.mjs.map +0 -1
- package/dist/api/shared-types.cjs +0 -93
- package/dist/api/shared-types.cjs.map +0 -1
- package/dist/api/shared-types.d.cts +0 -131
- package/dist/api/shared-types.d.cts.map +0 -1
- package/dist/api/shared-types.d.mts +0 -131
- package/dist/api/shared-types.d.mts.map +0 -1
- package/dist/api/shared-types.mjs +0 -87
- package/dist/api/shared-types.mjs.map +0 -1
- package/dist/api/test-utils.cjs +0 -70
- package/dist/api/test-utils.cjs.map +0 -1
- package/dist/api/test-utils.d.cts +0 -30
- package/dist/api/test-utils.d.cts.map +0 -1
- package/dist/api/test-utils.d.mts +0 -30
- package/dist/api/test-utils.d.mts.map +0 -1
- package/dist/api/test-utils.mjs +0 -64
- package/dist/api/test-utils.mjs.map +0 -1
- package/dist/api/token/client.cjs +0 -342
- package/dist/api/token/client.cjs.map +0 -1
- package/dist/api/token/client.d.cts +0 -193
- package/dist/api/token/client.d.cts.map +0 -1
- package/dist/api/token/client.d.mts +0 -193
- package/dist/api/token/client.d.mts.map +0 -1
- package/dist/api/token/client.mjs +0 -338
- package/dist/api/token/client.mjs.map +0 -1
- package/dist/api/token/index.cjs +0 -9
- package/dist/api/token/index.cjs.map +0 -1
- package/dist/api/token/index.d.cts +0 -6
- package/dist/api/token/index.d.cts.map +0 -1
- package/dist/api/token/index.d.mts +0 -6
- package/dist/api/token/index.d.mts.map +0 -1
- package/dist/api/token/index.mjs +0 -5
- package/dist/api/token/index.mjs.map +0 -1
- package/dist/api/token/types.cjs +0 -7
- package/dist/api/token/types.cjs.map +0 -1
- package/dist/api/token/types.d.cts +0 -75
- package/dist/api/token/types.d.cts.map +0 -1
- package/dist/api/token/types.d.mts +0 -75
- package/dist/api/token/types.d.mts.map +0 -1
- package/dist/api/token/types.mjs +0 -6
- package/dist/api/token/types.mjs.map +0 -1
- package/dist/api/tokens/client.cjs +0 -91
- package/dist/api/tokens/client.cjs.map +0 -1
- package/dist/api/tokens/client.d.cts +0 -45
- package/dist/api/tokens/client.d.cts.map +0 -1
- package/dist/api/tokens/client.d.mts +0 -45
- package/dist/api/tokens/client.d.mts.map +0 -1
- package/dist/api/tokens/client.mjs +0 -87
- package/dist/api/tokens/client.mjs.map +0 -1
- package/dist/api/tokens/index.cjs +0 -9
- package/dist/api/tokens/index.cjs.map +0 -1
- package/dist/api/tokens/index.d.cts +0 -6
- package/dist/api/tokens/index.d.cts.map +0 -1
- package/dist/api/tokens/index.d.mts +0 -6
- package/dist/api/tokens/index.d.mts.map +0 -1
- package/dist/api/tokens/index.mjs +0 -5
- package/dist/api/tokens/index.mjs.map +0 -1
- package/dist/api/tokens/types.cjs +0 -7
- package/dist/api/tokens/types.cjs.map +0 -1
- package/dist/api/tokens/types.d.cts +0 -83
- package/dist/api/tokens/types.d.cts.map +0 -1
- package/dist/api/tokens/types.d.mts +0 -83
- package/dist/api/tokens/types.d.mts.map +0 -1
- package/dist/api/tokens/types.mjs +0 -6
- package/dist/api/tokens/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,22 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `ApiPlatformClient` for unified access to MetaMask backend APIs with TanStack Query caching ([#7658](https://github.com/MetaMask/core/pull/7658))
|
|
13
|
-
- Automatic request deduplication and intelligent caching
|
|
14
|
-
- Automatic retries with exponential backoff for transient failures
|
|
15
|
-
- Support for Accounts API, Price API, Token API, and Tokens API endpoints
|
|
16
|
-
- Export helper functions `shouldRetry` and `calculateRetryDelay` for custom retry logic
|
|
17
|
-
- Export API types for external consumers
|
|
18
|
-
|
|
19
10
|
### Changed
|
|
20
11
|
|
|
21
12
|
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
|
|
22
|
-
- Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209)
|
|
13
|
+
- Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209))
|
|
23
14
|
- The dependencies moved are:
|
|
24
|
-
- `@metamask/accounts-controller` (^35.0.
|
|
25
|
-
- `@metamask/keyring-controller` (^25.
|
|
15
|
+
- `@metamask/accounts-controller` (^35.0.0)
|
|
16
|
+
- `@metamask/keyring-controller` (^25.0.0)
|
|
26
17
|
- In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
|
|
27
18
|
- For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
|
|
28
19
|
- Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
|
package/README.md
CHANGED
|
@@ -19,17 +19,6 @@ Core backend services for MetaMask, serving as the data layer between Backend se
|
|
|
19
19
|
- [WebSocket Connection Management](#websocket-connection-management)
|
|
20
20
|
- [Connection Requirements](#connection-requirements)
|
|
21
21
|
- [Connection Behavior](#connection-behavior)
|
|
22
|
-
- [HTTP API](#http-api)
|
|
23
|
-
- [Overview](#overview)
|
|
24
|
-
- [Features](#features)
|
|
25
|
-
- [Quick Start](#quick-start-1)
|
|
26
|
-
- [API Clients](#api-clients)
|
|
27
|
-
- [AccountsApiClient](#accountsapiclient)
|
|
28
|
-
- [PricesApiClient](#pricesapiclient)
|
|
29
|
-
- [TokenApiClient](#tokenapiclient)
|
|
30
|
-
- [TokensApiClient](#tokensapiclient)
|
|
31
|
-
- [Configuration](#configuration)
|
|
32
|
-
- [Cache Management](#cache-management)
|
|
33
22
|
- [API Reference](#api-reference)
|
|
34
23
|
- [BackendWebSocketService](#backendwebsocketservice)
|
|
35
24
|
- [Constructor Options](#constructor-options)
|
|
@@ -55,8 +44,6 @@ npm install @metamask/core-backend
|
|
|
55
44
|
|
|
56
45
|
### Basic Usage
|
|
57
46
|
|
|
58
|
-
**WebSocket for Real-time Updates:**
|
|
59
|
-
|
|
60
47
|
```typescript
|
|
61
48
|
import {
|
|
62
49
|
BackendWebSocketService,
|
|
@@ -95,28 +82,6 @@ messenger.subscribe(
|
|
|
95
82
|
);
|
|
96
83
|
```
|
|
97
84
|
|
|
98
|
-
**HTTP API for REST Requests:**
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
import { ApiPlatformClient } from '@metamask/core-backend';
|
|
102
|
-
|
|
103
|
-
// Create API client
|
|
104
|
-
const apiClient = new ApiPlatformClient({
|
|
105
|
-
clientProduct: 'metamask-extension',
|
|
106
|
-
getBearerToken: async () => authController.getBearerToken(),
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Fetch data with automatic caching and deduplication
|
|
110
|
-
const balances = await apiClient.accounts.fetchV5MultiAccountBalances([
|
|
111
|
-
'eip155:1:0x742d35cc6634c0532925a3b8d40c4e0e2c6e4e6',
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
const prices = await apiClient.prices.fetchV3SpotPrices([
|
|
115
|
-
'eip155:1/slip44:60', // ETH
|
|
116
|
-
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC
|
|
117
|
-
]);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
85
|
### Integration with Controllers
|
|
121
86
|
|
|
122
87
|
```typescript
|
|
@@ -182,7 +147,7 @@ graph TD
|
|
|
182
147
|
|
|
183
148
|
subgraph "Transport Layer"
|
|
184
149
|
WSS[WebSocketService<br/>• Connection management<br/>• Automatic reconnection<br/>• Message routing<br/>• Subscription management]
|
|
185
|
-
HTTP[HTTP
|
|
150
|
+
HTTP[HTTP Service<br/>• REST API calls<br/>• Request/response handling<br/>• Error handling<br/>future]
|
|
186
151
|
end
|
|
187
152
|
end
|
|
188
153
|
end
|
|
@@ -379,222 +344,6 @@ The WebSocket connects when **ALL 3 conditions are true**:
|
|
|
379
344
|
- ✅ **Unexpected disconnects** (network issues, server restart) → Auto-reconnect
|
|
380
345
|
- ❌ **Manual disconnects** (app backgrounds, wallet locks, user signs out) → Stay disconnected
|
|
381
346
|
|
|
382
|
-
## HTTP API
|
|
383
|
-
|
|
384
|
-
### Overview
|
|
385
|
-
|
|
386
|
-
The HTTP API provides type-safe clients for accessing MetaMask backend REST APIs. It uses `@tanstack/query-core` for intelligent caching, request deduplication, and automatic retries.
|
|
387
|
-
|
|
388
|
-
**Available APIs:**
|
|
389
|
-
|
|
390
|
-
| API | Base URL | Purpose |
|
|
391
|
-
| ------------ | ----------------------------- | ---------------------------------------------- |
|
|
392
|
-
| **Accounts** | `accounts.api.cx.metamask.io` | Balances, transactions, NFTs, token discovery |
|
|
393
|
-
| **Prices** | `price.api.cx.metamask.io` | Spot prices, exchange rates, historical prices |
|
|
394
|
-
| **Token** | `token.api.cx.metamask.io` | Token metadata, trending, top gainers |
|
|
395
|
-
| **Tokens** | `tokens.api.cx.metamask.io` | Bulk asset operations, supported networks |
|
|
396
|
-
|
|
397
|
-
### Features
|
|
398
|
-
|
|
399
|
-
- ✅ **Automatic request deduplication** - Identical concurrent requests share a single network call
|
|
400
|
-
- ✅ **Intelligent caching** - Configurable stale times per data type (prices: 30s, balances: 1min, networks: 30min)
|
|
401
|
-
- ✅ **Automatic retries** - Exponential backoff with jitter, skips 4xx errors (except 429, 408)
|
|
402
|
-
- ✅ **Type safety** - Full TypeScript support with response types
|
|
403
|
-
- ✅ **Bearer token caching** - Auth tokens cached for 5 minutes
|
|
404
|
-
- ✅ **Unified client** - Single entry point or individual API clients
|
|
405
|
-
|
|
406
|
-
### Quick Start
|
|
407
|
-
|
|
408
|
-
```typescript
|
|
409
|
-
import {
|
|
410
|
-
ApiPlatformClient,
|
|
411
|
-
createApiPlatformClient,
|
|
412
|
-
} from '@metamask/core-backend';
|
|
413
|
-
|
|
414
|
-
// Create unified client
|
|
415
|
-
const client = new ApiPlatformClient({
|
|
416
|
-
clientProduct: 'metamask-extension',
|
|
417
|
-
clientVersion: '12.0.0',
|
|
418
|
-
getBearerToken: async () => authController.getBearerToken(),
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
// Access API methods through sub-clients
|
|
422
|
-
const networks = await client.accounts.fetchV2SupportedNetworks();
|
|
423
|
-
const balances = await client.accounts.fetchV5MultiAccountBalances([
|
|
424
|
-
'eip155:1:0x742d35cc6634c0532925a3b8d40c4e0e2c6e4e6',
|
|
425
|
-
]);
|
|
426
|
-
const prices = await client.prices.fetchV3SpotPrices([
|
|
427
|
-
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
428
|
-
]);
|
|
429
|
-
const tokenList = await client.token.fetchTokenList(1);
|
|
430
|
-
const assets = await client.tokens.fetchV3Assets([
|
|
431
|
-
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
432
|
-
]);
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
Or use individual clients:
|
|
436
|
-
|
|
437
|
-
```typescript
|
|
438
|
-
import { AccountsApiClient, PricesApiClient } from '@metamask/core-backend';
|
|
439
|
-
|
|
440
|
-
const accountsClient = new AccountsApiClient({
|
|
441
|
-
clientProduct: 'metamask-extension',
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
const pricesClient = new PricesApiClient({
|
|
445
|
-
clientProduct: 'metamask-extension',
|
|
446
|
-
getBearerToken: async () => token,
|
|
447
|
-
});
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
### API Clients
|
|
451
|
-
|
|
452
|
-
#### AccountsApiClient
|
|
453
|
-
|
|
454
|
-
Handles account-related operations including balances, transactions, NFTs, and token discovery.
|
|
455
|
-
|
|
456
|
-
| Method | Description |
|
|
457
|
-
| ------------------------------------------------------- | ------------------------------------------ |
|
|
458
|
-
| `fetchV1SupportedNetworks()` | Get supported networks (v1) |
|
|
459
|
-
| `fetchV2SupportedNetworks()` | Get supported networks (v2) |
|
|
460
|
-
| `fetchV2ActiveNetworks(accountIds, options?)` | Get active networks by CAIP-10 account IDs |
|
|
461
|
-
| `fetchV2Balances(address, options?)` | Get balances for single address |
|
|
462
|
-
| `fetchV2BalancesWithOptions(address, options?)` | Get balances with filters |
|
|
463
|
-
| `fetchV4MultiAccountBalances(addresses, options?)` | Get balances for multiple addresses |
|
|
464
|
-
| `fetchV5MultiAccountBalances(accountIds, options?)` | Get balances using CAIP-10 IDs |
|
|
465
|
-
| `fetchV1TransactionByHash(chainId, txHash, options?)` | Get transaction by hash |
|
|
466
|
-
| `fetchV1AccountTransactions(address, options?)` | Get account transactions |
|
|
467
|
-
| `fetchV4MultiAccountTransactions(accountIds, options?)` | Get multi-account transactions |
|
|
468
|
-
| `fetchV1AccountRelationship(chainId, from, to)` | Get address relationship |
|
|
469
|
-
| `fetchV2AccountNfts(address, options?)` | Get account NFTs |
|
|
470
|
-
| `fetchV2AccountTokens(address, options?)` | Get detected ERC20 tokens |
|
|
471
|
-
| `invalidateBalances()` | Invalidate all balance cache |
|
|
472
|
-
| `invalidateAccounts()` | Invalidate all account cache |
|
|
473
|
-
|
|
474
|
-
#### PricesApiClient
|
|
475
|
-
|
|
476
|
-
Handles price-related operations including spot prices, exchange rates, and historical data.
|
|
477
|
-
|
|
478
|
-
| Method | Description |
|
|
479
|
-
| ----------------------------------------------------------------------- | ------------------------------------------------ |
|
|
480
|
-
| `fetchPriceV1SupportedNetworks()` | Get price-supported networks (v1) |
|
|
481
|
-
| `fetchPriceV2SupportedNetworks()` | Get price-supported networks in CAIP format (v2) |
|
|
482
|
-
| `fetchV1ExchangeRates(baseCurrency)` | Get exchange rates for base currency |
|
|
483
|
-
| `fetchV1FiatExchangeRates()` | Get fiat exchange rates |
|
|
484
|
-
| `fetchV1CryptoExchangeRates()` | Get crypto exchange rates |
|
|
485
|
-
| `fetchV1SpotPricesByCoinIds(coinIds)` | Get spot prices by CoinGecko IDs |
|
|
486
|
-
| `fetchV1SpotPriceByCoinId(coinId, currency?)` | Get single coin spot price |
|
|
487
|
-
| `fetchV1TokenPrices(chainId, addresses, options?)` | Get token prices on chain |
|
|
488
|
-
| `fetchV1TokenPrice(chainId, address, currency?)` | Get single token price |
|
|
489
|
-
| `fetchV2SpotPrices(chainId, addresses, options?)` | Get spot prices with market data |
|
|
490
|
-
| `fetchV3SpotPrices(assetIds, options?)` | Get spot prices by CAIP-19 asset IDs |
|
|
491
|
-
| `fetchV1HistoricalPricesByCoinId(coinId, options?)` | Get historical prices by CoinGecko ID |
|
|
492
|
-
| `fetchV1HistoricalPricesByTokenAddresses(chainId, addresses, options?)` | Get historical prices for tokens |
|
|
493
|
-
| `fetchV1HistoricalPrices(chainId, address, options?)` | Get historical prices for single token |
|
|
494
|
-
| `fetchV3HistoricalPrices(chainId, assetType, options?)` | Get historical prices by CAIP-19 |
|
|
495
|
-
| `fetchV1HistoricalPriceGraphByCoinId(coinId, options?)` | Get price graph by CoinGecko ID |
|
|
496
|
-
| `fetchV1HistoricalPriceGraphByTokenAddress(chainId, address, options?)` | Get price graph by token address |
|
|
497
|
-
| `invalidatePrices()` | Invalidate all price cache |
|
|
498
|
-
|
|
499
|
-
#### TokenApiClient
|
|
500
|
-
|
|
501
|
-
Handles token metadata, lists, and trending/popular token discovery.
|
|
502
|
-
|
|
503
|
-
| Method | Description |
|
|
504
|
-
| -------------------------------------------------- | ------------------------------- |
|
|
505
|
-
| `fetchNetworks()` | Get all networks |
|
|
506
|
-
| `fetchNetworkByChainId(chainId)` | Get network by chain ID |
|
|
507
|
-
| `fetchTokenList(chainId, options?)` | Get token list for chain |
|
|
508
|
-
| `fetchV1TokenMetadata(chainId, address, options?)` | Get token metadata |
|
|
509
|
-
| `fetchTokenDescription(chainId, address)` | Get token description |
|
|
510
|
-
| `fetchV3TrendingTokens(chainIds, options?)` | Get trending tokens |
|
|
511
|
-
| `fetchV3TopGainers(chainIds, options?)` | Get top gainers/losers |
|
|
512
|
-
| `fetchV3PopularTokens(chainIds, options?)` | Get popular tokens |
|
|
513
|
-
| `fetchTopAssets(chainId)` | Get top assets for chain |
|
|
514
|
-
| `fetchV1SuggestedOccurrenceFloors()` | Get suggested occurrence floors |
|
|
515
|
-
|
|
516
|
-
#### TokensApiClient
|
|
517
|
-
|
|
518
|
-
Handles bulk token operations and supported network queries.
|
|
519
|
-
|
|
520
|
-
| Method | Description |
|
|
521
|
-
| --------------------------------- | ----------------------------------------------------------- |
|
|
522
|
-
| `fetchTokenV1SupportedNetworks()` | Get token-supported networks (v1) |
|
|
523
|
-
| `fetchTokenV2SupportedNetworks()` | Get token-supported networks with full/partial support (v2) |
|
|
524
|
-
| `fetchV3Assets(assetIds)` | Fetch assets by CAIP-19 IDs |
|
|
525
|
-
| `invalidateTokens()` | Invalidate all token cache |
|
|
526
|
-
|
|
527
|
-
### Configuration
|
|
528
|
-
|
|
529
|
-
```typescript
|
|
530
|
-
type ApiPlatformClientOptions = {
|
|
531
|
-
/** Client product identifier (e.g., 'metamask-extension', 'metamask-mobile') */
|
|
532
|
-
clientProduct: string;
|
|
533
|
-
/** Optional client version (default: '1.0.0') */
|
|
534
|
-
clientVersion?: string;
|
|
535
|
-
/** Function to get bearer token for authenticated requests */
|
|
536
|
-
getBearerToken?: () => Promise<string | undefined>;
|
|
537
|
-
/** Optional custom QueryClient instance for shared caching */
|
|
538
|
-
queryClient?: QueryClient;
|
|
539
|
-
};
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
**Default Stale Times:**
|
|
543
|
-
|
|
544
|
-
| Data Type | Stale Time |
|
|
545
|
-
| ------------------ | ---------- |
|
|
546
|
-
| Prices | 30 seconds |
|
|
547
|
-
| Balances | 1 minute |
|
|
548
|
-
| Transactions | 30 seconds |
|
|
549
|
-
| Networks | 10 minutes |
|
|
550
|
-
| Supported Networks | 30 minutes |
|
|
551
|
-
| Token Metadata | 5 minutes |
|
|
552
|
-
| Token List | 10 minutes |
|
|
553
|
-
| Exchange Rates | 5 minutes |
|
|
554
|
-
| Trending | 2 minutes |
|
|
555
|
-
| Auth Token | 5 minutes |
|
|
556
|
-
|
|
557
|
-
**Override Stale Time:**
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
// Use custom stale time for specific request
|
|
561
|
-
const balances = await client.accounts.fetchV5MultiAccountBalances(
|
|
562
|
-
accountIds,
|
|
563
|
-
{ networks: ['eip155:1'] },
|
|
564
|
-
{ staleTime: 10000 }, // 10 seconds
|
|
565
|
-
);
|
|
566
|
-
```
|
|
567
|
-
|
|
568
|
-
### Cache Management
|
|
569
|
-
|
|
570
|
-
```typescript
|
|
571
|
-
// Invalidate all caches
|
|
572
|
-
await client.invalidateAll();
|
|
573
|
-
|
|
574
|
-
// Invalidate auth token (on logout)
|
|
575
|
-
await client.invalidateAuthToken();
|
|
576
|
-
|
|
577
|
-
// Domain-specific invalidation
|
|
578
|
-
await client.accounts.invalidateBalances();
|
|
579
|
-
await client.prices.invalidatePrices();
|
|
580
|
-
await client.tokens.invalidateTokens();
|
|
581
|
-
|
|
582
|
-
// Clear all cached data
|
|
583
|
-
client.clear();
|
|
584
|
-
|
|
585
|
-
// Check if query is fetching
|
|
586
|
-
const isFetching = client.isFetching(['accounts', 'balances']);
|
|
587
|
-
|
|
588
|
-
// Access cached data directly
|
|
589
|
-
const cached = client.getCachedData(['accounts', 'balances', 'v5', { ... }]);
|
|
590
|
-
|
|
591
|
-
// Set cached data
|
|
592
|
-
client.setCachedData(queryKey, data);
|
|
593
|
-
|
|
594
|
-
// Access underlying QueryClient for advanced usage
|
|
595
|
-
const queryClient = client.queryClient;
|
|
596
|
-
```
|
|
597
|
-
|
|
598
347
|
## API Reference
|
|
599
348
|
|
|
600
349
|
### BackendWebSocketService
|
package/dist/index.cjs
CHANGED
|
@@ -1,40 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @file Backend platform services for MetaMask.
|
|
4
|
+
*/
|
|
3
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
// ============================================================================
|
|
6
|
-
// BACKEND WEBSOCKET SERVICE
|
|
7
|
-
// ============================================================================
|
|
6
|
+
exports.AccountActivityService = exports.BackendWebSocketService = void 0;
|
|
8
7
|
var BackendWebSocketService_1 = require("./BackendWebSocketService.cjs");
|
|
9
8
|
Object.defineProperty(exports, "BackendWebSocketService", { enumerable: true, get: function () { return BackendWebSocketService_1.BackendWebSocketService; } });
|
|
10
|
-
Object.defineProperty(exports, "getCloseReason", { enumerable: true, get: function () { return BackendWebSocketService_1.getCloseReason; } });
|
|
11
|
-
Object.defineProperty(exports, "WebSocketState", { enumerable: true, get: function () { return BackendWebSocketService_1.WebSocketState; } });
|
|
12
|
-
Object.defineProperty(exports, "WebSocketEventType", { enumerable: true, get: function () { return BackendWebSocketService_1.WebSocketEventType; } });
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// ACCOUNT ACTIVITY SERVICE
|
|
15
|
-
// ============================================================================
|
|
16
9
|
var AccountActivityService_1 = require("./AccountActivityService.cjs");
|
|
17
10
|
Object.defineProperty(exports, "AccountActivityService", { enumerable: true, get: function () { return AccountActivityService_1.AccountActivityService; } });
|
|
18
|
-
Object.defineProperty(exports, "ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS", { enumerable: true, get: function () { return AccountActivityService_1.ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS; } });
|
|
19
|
-
Object.defineProperty(exports, "ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS", { enumerable: true, get: function () { return AccountActivityService_1.ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS; } });
|
|
20
|
-
// ============================================================================
|
|
21
|
-
// API PLATFORM CLIENT
|
|
22
|
-
// ============================================================================
|
|
23
|
-
var api_1 = require("./api/index.cjs");
|
|
24
|
-
Object.defineProperty(exports, "ApiPlatformClient", { enumerable: true, get: function () { return api_1.ApiPlatformClient; } });
|
|
25
|
-
Object.defineProperty(exports, "createApiPlatformClient", { enumerable: true, get: function () { return api_1.createApiPlatformClient; } });
|
|
26
|
-
// Individual API clients
|
|
27
|
-
Object.defineProperty(exports, "AccountsApiClient", { enumerable: true, get: function () { return api_1.AccountsApiClient; } });
|
|
28
|
-
Object.defineProperty(exports, "PricesApiClient", { enumerable: true, get: function () { return api_1.PricesApiClient; } });
|
|
29
|
-
Object.defineProperty(exports, "TokenApiClient", { enumerable: true, get: function () { return api_1.TokenApiClient; } });
|
|
30
|
-
Object.defineProperty(exports, "TokensApiClient", { enumerable: true, get: function () { return api_1.TokensApiClient; } });
|
|
31
|
-
// Constants
|
|
32
|
-
Object.defineProperty(exports, "API_URLS", { enumerable: true, get: function () { return api_1.API_URLS; } });
|
|
33
|
-
Object.defineProperty(exports, "STALE_TIMES", { enumerable: true, get: function () { return api_1.STALE_TIMES; } });
|
|
34
|
-
Object.defineProperty(exports, "GC_TIMES", { enumerable: true, get: function () { return api_1.GC_TIMES; } });
|
|
35
|
-
// Helpers
|
|
36
|
-
Object.defineProperty(exports, "calculateRetryDelay", { enumerable: true, get: function () { return api_1.calculateRetryDelay; } });
|
|
37
|
-
Object.defineProperty(exports, "shouldRetry", { enumerable: true, get: function () { return api_1.shouldRetry; } });
|
|
38
|
-
// Errors
|
|
39
|
-
Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return api_1.HttpError; } });
|
|
40
11
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAyBH,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAchC,uEAAkE;AAAzD,gIAAA,sBAAsB,OAAA","sourcesContent":["/**\n * @file Backend platform services for MetaMask.\n */\n\n// Transaction and balance update types\nexport type {\n Transaction,\n Asset,\n Balance,\n Transfer,\n BalanceUpdate,\n AccountActivityMessage,\n} from './types';\n\n// WebSocket Service - following MetaMask Data Services pattern\nexport type {\n BackendWebSocketServiceOptions,\n WebSocketMessage,\n WebSocketConnectionInfo,\n WebSocketSubscription,\n BackendWebSocketServiceActions,\n BackendWebSocketServiceMessenger,\n BackendWebSocketServiceEvents,\n BackendWebSocketServiceConnectionStateChangedEvent,\n WebSocketState,\n WebSocketEventType,\n} from './BackendWebSocketService';\nexport { BackendWebSocketService } from './BackendWebSocketService';\n\n// Account Activity Service\nexport type {\n SubscriptionOptions,\n AccountActivityServiceOptions,\n AccountActivityServiceActions,\n AccountActivityServiceTransactionUpdatedEvent,\n AccountActivityServiceBalanceUpdatedEvent,\n AccountActivityServiceSubscriptionErrorEvent,\n AccountActivityServiceStatusChangedEvent,\n AccountActivityServiceEvents,\n AccountActivityServiceMessenger,\n} from './AccountActivityService';\nexport { AccountActivityService } from './AccountActivityService';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type { SystemNotificationData, SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AllowedActions as AccountActivityServiceAllowedActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AllowedEvents as AccountActivityServiceAllowedEvents, AccountActivityServiceMessenger, } from "./AccountActivityService.cjs";
|
|
1
|
+
/**
|
|
2
|
+
* @file Backend platform services for MetaMask.
|
|
3
|
+
*/
|
|
5
4
|
export type { Transaction, Asset, Balance, Transfer, BalanceUpdate, AccountActivityMessage, } from "./types.cjs";
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
5
|
+
export type { BackendWebSocketServiceOptions, WebSocketMessage, WebSocketConnectionInfo, WebSocketSubscription, BackendWebSocketServiceActions, BackendWebSocketServiceMessenger, BackendWebSocketServiceEvents, BackendWebSocketServiceConnectionStateChangedEvent, WebSocketState, WebSocketEventType, } from "./BackendWebSocketService.cjs";
|
|
6
|
+
export { BackendWebSocketService } from "./BackendWebSocketService.cjs";
|
|
7
|
+
export type { SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AccountActivityServiceMessenger, } from "./AccountActivityService.cjs";
|
|
8
|
+
export { AccountActivityService } from "./AccountActivityService.cjs";
|
|
8
9
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,WAAW,EACX,KAAK,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,sBAAsB,GACvB,oBAAgB;AAGjB,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,8BAA8B,EAC9B,gCAAgC,EAChC,6BAA6B,EAC7B,kDAAkD,EAClD,cAAc,EACd,kBAAkB,GACnB,sCAAkC;AACnC,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAGpE,YAAY,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,6CAA6C,EAC7C,yCAAyC,EACzC,4CAA4C,EAC5C,wCAAwC,EACxC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type { SystemNotificationData, SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AllowedActions as AccountActivityServiceAllowedActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AllowedEvents as AccountActivityServiceAllowedEvents, AccountActivityServiceMessenger, } from "./AccountActivityService.mjs";
|
|
1
|
+
/**
|
|
2
|
+
* @file Backend platform services for MetaMask.
|
|
3
|
+
*/
|
|
5
4
|
export type { Transaction, Asset, Balance, Transfer, BalanceUpdate, AccountActivityMessage, } from "./types.mjs";
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
5
|
+
export type { BackendWebSocketServiceOptions, WebSocketMessage, WebSocketConnectionInfo, WebSocketSubscription, BackendWebSocketServiceActions, BackendWebSocketServiceMessenger, BackendWebSocketServiceEvents, BackendWebSocketServiceConnectionStateChangedEvent, WebSocketState, WebSocketEventType, } from "./BackendWebSocketService.mjs";
|
|
6
|
+
export { BackendWebSocketService } from "./BackendWebSocketService.mjs";
|
|
7
|
+
export type { SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AccountActivityServiceMessenger, } from "./AccountActivityService.mjs";
|
|
8
|
+
export { AccountActivityService } from "./AccountActivityService.mjs";
|
|
8
9
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,WAAW,EACX,KAAK,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,sBAAsB,GACvB,oBAAgB;AAGjB,YAAY,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,8BAA8B,EAC9B,gCAAgC,EAChC,6BAA6B,EAC7B,kDAAkD,EAClD,cAAc,EACd,kBAAkB,GACnB,sCAAkC;AACnC,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAGpE,YAAY,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,6CAA6C,EAC7C,yCAAyC,EACzC,4CAA4C,EAC5C,wCAAwC,EACxC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// ACCOUNT ACTIVITY SERVICE
|
|
8
|
-
// ============================================================================
|
|
9
|
-
export { AccountActivityService, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS } from "./AccountActivityService.mjs";
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// API PLATFORM CLIENT
|
|
12
|
-
// ============================================================================
|
|
13
|
-
export { ApiPlatformClient, createApiPlatformClient,
|
|
14
|
-
// Individual API clients
|
|
15
|
-
AccountsApiClient, PricesApiClient, TokenApiClient, TokensApiClient,
|
|
16
|
-
// Constants
|
|
17
|
-
API_URLS, STALE_TIMES, GC_TIMES,
|
|
18
|
-
// Helpers
|
|
19
|
-
calculateRetryDelay, shouldRetry,
|
|
20
|
-
// Errors
|
|
21
|
-
HttpError } from "./api/index.mjs";
|
|
1
|
+
/**
|
|
2
|
+
* @file Backend platform services for MetaMask.
|
|
3
|
+
*/
|
|
4
|
+
export { BackendWebSocketService } from "./BackendWebSocketService.mjs";
|
|
5
|
+
export { AccountActivityService } from "./AccountActivityService.mjs";
|
|
22
6
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyBH,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AAcpE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC","sourcesContent":["/**\n * @file Backend platform services for MetaMask.\n */\n\n// Transaction and balance update types\nexport type {\n Transaction,\n Asset,\n Balance,\n Transfer,\n BalanceUpdate,\n AccountActivityMessage,\n} from './types';\n\n// WebSocket Service - following MetaMask Data Services pattern\nexport type {\n BackendWebSocketServiceOptions,\n WebSocketMessage,\n WebSocketConnectionInfo,\n WebSocketSubscription,\n BackendWebSocketServiceActions,\n BackendWebSocketServiceMessenger,\n BackendWebSocketServiceEvents,\n BackendWebSocketServiceConnectionStateChangedEvent,\n WebSocketState,\n WebSocketEventType,\n} from './BackendWebSocketService';\nexport { BackendWebSocketService } from './BackendWebSocketService';\n\n// Account Activity Service\nexport type {\n SubscriptionOptions,\n AccountActivityServiceOptions,\n AccountActivityServiceActions,\n AccountActivityServiceTransactionUpdatedEvent,\n AccountActivityServiceBalanceUpdatedEvent,\n AccountActivityServiceSubscriptionErrorEvent,\n AccountActivityServiceStatusChangedEvent,\n AccountActivityServiceEvents,\n AccountActivityServiceMessenger,\n} from './AccountActivityService';\nexport { AccountActivityService } from './AccountActivityService';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/core-backend",
|
|
3
|
-
"version": "5.0.0-preview-
|
|
3
|
+
"version": "5.0.0-preview-91e0d8c4",
|
|
4
4
|
"description": "Core backend services for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -48,13 +48,12 @@
|
|
|
48
48
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@metamask/accounts-controller": "^35.0.
|
|
51
|
+
"@metamask/accounts-controller": "^35.0.0",
|
|
52
52
|
"@metamask/controller-utils": "^11.18.0",
|
|
53
|
-
"@metamask/keyring-controller": "^25.
|
|
53
|
+
"@metamask/keyring-controller": "^25.0.0",
|
|
54
54
|
"@metamask/messenger": "^0.3.0",
|
|
55
55
|
"@metamask/profile-sync-controller": "^27.0.0",
|
|
56
56
|
"@metamask/utils": "^11.9.0",
|
|
57
|
-
"@tanstack/query-core": "^5.62.16",
|
|
58
57
|
"uuid": "^8.3.2"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|