@metamask-previews/core-backend 5.1.1-preview-27e39dd44 → 5.1.1-preview-d7935cb09
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 +23 -0
- package/README.md +60 -55
- package/dist/ApiPlatformClientService-method-action-types.cjs +7 -0
- package/dist/ApiPlatformClientService-method-action-types.cjs.map +1 -0
- package/dist/ApiPlatformClientService-method-action-types.d.cts +21 -0
- package/dist/ApiPlatformClientService-method-action-types.d.cts.map +1 -0
- package/dist/ApiPlatformClientService-method-action-types.d.mts +21 -0
- package/dist/ApiPlatformClientService-method-action-types.d.mts.map +1 -0
- package/dist/ApiPlatformClientService-method-action-types.mjs +6 -0
- package/dist/ApiPlatformClientService-method-action-types.mjs.map +1 -0
- package/dist/ApiPlatformClientService.cjs +82 -0
- package/dist/ApiPlatformClientService.cjs.map +1 -0
- package/dist/ApiPlatformClientService.d.cts +86 -0
- package/dist/ApiPlatformClientService.d.cts.map +1 -0
- package/dist/ApiPlatformClientService.d.mts +86 -0
- package/dist/ApiPlatformClientService.d.mts.map +1 -0
- package/dist/ApiPlatformClientService.mjs +78 -0
- package/dist/ApiPlatformClientService.mjs.map +1 -0
- package/dist/api/accounts/client.cjs +358 -163
- package/dist/api/accounts/client.cjs.map +1 -1
- package/dist/api/accounts/client.d.cts +198 -12
- package/dist/api/accounts/client.d.cts.map +1 -1
- package/dist/api/accounts/client.d.mts +198 -12
- package/dist/api/accounts/client.d.mts.map +1 -1
- package/dist/api/accounts/client.mjs +359 -164
- package/dist/api/accounts/client.mjs.map +1 -1
- package/dist/api/index.cjs +2 -1
- 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/prices/client.cjs +398 -140
- package/dist/api/prices/client.cjs.map +1 -1
- package/dist/api/prices/client.d.cts +215 -3
- package/dist/api/prices/client.d.cts.map +1 -1
- package/dist/api/prices/client.d.mts +215 -3
- package/dist/api/prices/client.d.mts.map +1 -1
- package/dist/api/prices/client.mjs +398 -140
- package/dist/api/prices/client.mjs.map +1 -1
- package/dist/api/shared-types.cjs +18 -1
- package/dist/api/shared-types.cjs.map +1 -1
- package/dist/api/shared-types.d.cts +23 -3
- package/dist/api/shared-types.d.cts.map +1 -1
- package/dist/api/shared-types.d.mts +23 -3
- package/dist/api/shared-types.d.mts.map +1 -1
- package/dist/api/shared-types.mjs +16 -0
- package/dist/api/shared-types.mjs.map +1 -1
- package/dist/api/token/client.cjs +232 -77
- package/dist/api/token/client.cjs.map +1 -1
- package/dist/api/token/client.d.cts +165 -0
- package/dist/api/token/client.d.cts.map +1 -1
- package/dist/api/token/client.d.mts +165 -0
- package/dist/api/token/client.d.mts.map +1 -1
- package/dist/api/token/client.mjs +232 -77
- package/dist/api/token/client.mjs.map +1 -1
- package/dist/api/tokens/client.cjs +64 -23
- package/dist/api/tokens/client.cjs.map +1 -1
- package/dist/api/tokens/client.d.cts +24 -0
- package/dist/api/tokens/client.d.cts.map +1 -1
- package/dist/api/tokens/client.d.mts +24 -0
- package/dist/api/tokens/client.d.mts.map +1 -1
- package/dist/api/tokens/client.mjs +64 -23
- package/dist/api/tokens/client.mjs.map +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ 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 `ApiPlatformClientService` to expose `ApiPlatformClient` via the messenger without a controller ([#7928](https://github.com/MetaMask/core/pull/7928))
|
|
13
|
+
- Consumers call `messenger.call('ApiPlatformClientService:getApiPlatformClient')` to obtain the shared client for accounts, prices, token, and tokens APIs
|
|
14
|
+
- Export TanStack Query options for all API endpoints via `get*QueryOptions` helpers ([#7928](https://github.com/MetaMask/core/pull/7928))
|
|
15
|
+
- Each fetch method (e.g. `fetchV5MultiAccountBalances`) has a corresponding `get*QueryOptions` (e.g. `getV5MultiAccountBalancesQueryOptions`) returning the same options object used internally
|
|
16
|
+
- Enables reuse with `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, and other TanStack Query APIs
|
|
17
|
+
- Extend `FetchOptions` to allow TanStack Query options (e.g. `select`, `initialPageParam`, `retry`, `initialData`) to be passed through to `get*QueryOptions` and merged into the returned query options
|
|
18
|
+
- Export `getQueryOptionsOverrides` helper for stripping `queryKey`/`queryFn` from options when merging
|
|
19
|
+
- All API clients (accounts, prices, token, tokens) merge user overrides first, then apply `staleTime`/`gcTime` defaults so cache timing is consistent and extra options (e.g. `select`) are preserved
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- **BREAKING:** Merge `fetchV2BalancesWithOptions` into `fetchV2Balances` ([#7928](https://github.com/MetaMask/core/pull/7928))
|
|
24
|
+
- `fetchV2Balances(address, queryOptions?, options?)` now accepts the full query options: `networks`, `filterSupportedTokens`, `includeTokenAddresses`, `includeStakedAssets`
|
|
25
|
+
- `getV2BalancesQueryOptions` accepts the same full query options for use with TanStack Query
|
|
26
|
+
- `fetchV2BalancesWithOptions` and `getV2BalancesWithOptionsQueryOptions` have been removed; use `fetchV2Balances` and `getV2BalancesQueryOptions` with the desired options instead
|
|
27
|
+
- **BREAKING:** Align v4 multi-account transactions with API ([#7928](https://github.com/MetaMask/core/pull/7928))
|
|
28
|
+
- First parameter renamed from `accountIds` to `accountAddresses` in `fetchV4MultiAccountTransactions` and `getV4MultiAccountTransactionsQueryOptions`
|
|
29
|
+
- Query options now include: `startTimestamp`, `endTimestamp`, `limit`, `after`, `before`, `maxLogsPerTx`, `lang` in addition to `networks`, `cursor`, `sortDirection`, `includeLogs`, `includeTxMetadata`
|
|
30
|
+
- `includeValueTransfers` has been removed from the options (not in API spec)
|
|
31
|
+
- Accounts, prices, and tokens clients: `fetch*` and `get*QueryOptions` now short-circuit on empty required inputs (e.g. empty address, empty account IDs or asset lists) and return empty results without calling the API ([#7928](https://github.com/MetaMask/core/pull/7928))
|
|
32
|
+
|
|
10
33
|
## [5.1.1]
|
|
11
34
|
|
|
12
35
|
### Changed
|
package/README.md
CHANGED
|
@@ -449,80 +449,85 @@ const pricesClient = new PricesApiClient({
|
|
|
449
449
|
|
|
450
450
|
### API Clients
|
|
451
451
|
|
|
452
|
+
Optional parameters: `options` is `FetchOptions` (e.g. `staleTime`, `gcTime`). `queryOptions` are API-specific filters (e.g. `networks`, `cursor`). Each `fetch*` method has a matching `get*QueryOptions` that returns the TanStack Query options object for use with `useQuery`, `useInfiniteQuery`, `useSuspenseQuery`, etc.
|
|
453
|
+
|
|
452
454
|
#### AccountsApiClient
|
|
453
455
|
|
|
454
456
|
Handles account-related operations including balances, transactions, NFTs, and token discovery.
|
|
455
457
|
|
|
456
|
-
| Method
|
|
457
|
-
|
|
|
458
|
-
| `fetchV1SupportedNetworks()`
|
|
459
|
-
| `fetchV2SupportedNetworks()`
|
|
460
|
-
| `fetchV2ActiveNetworks(accountIds, options?)`
|
|
461
|
-
| `fetchV2Balances(address, options?)`
|
|
462
|
-
| `
|
|
463
|
-
| `
|
|
464
|
-
| `
|
|
465
|
-
| `
|
|
466
|
-
| `
|
|
467
|
-
| `
|
|
468
|
-
| `
|
|
469
|
-
| `
|
|
470
|
-
| `
|
|
471
|
-
| `invalidateBalances()`
|
|
472
|
-
| `invalidateAccounts()`
|
|
458
|
+
| Method | Description |
|
|
459
|
+
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
460
|
+
| `fetchV1SupportedNetworks(options?)` | Get supported networks (v1) |
|
|
461
|
+
| `fetchV2SupportedNetworks(options?)` | Get supported networks (v2) |
|
|
462
|
+
| `fetchV2ActiveNetworks(accountIds, queryOptions?, options?)` | Get active networks by CAIP-10 account IDs |
|
|
463
|
+
| `fetchV2Balances(address, queryOptions?, options?)` | Get balances for single address (supports networks, filterSupportedTokens, includeTokenAddresses, includeStakedAssets) |
|
|
464
|
+
| `fetchV4MultiAccountBalances(addresses, queryOptions?, options?)` | Get balances for multiple addresses |
|
|
465
|
+
| `fetchV5MultiAccountBalances(accountIds, queryOptions?, options?)` | Get balances using CAIP-10 IDs |
|
|
466
|
+
| `fetchV1TransactionByHash(chainId, txHash, queryOptions?, options?)` | Get transaction by hash |
|
|
467
|
+
| `fetchV1AccountTransactions(address, queryOptions?, options?)` | Get account transactions |
|
|
468
|
+
| `fetchV4MultiAccountTransactions(accountAddresses, queryOptions?, options?)` | Get multi-account transactions |
|
|
469
|
+
| `fetchV1AccountRelationship(chainId, from, to, options?)` | Get address relationship |
|
|
470
|
+
| `fetchV2AccountNfts(address, queryOptions?, options?)` | Get account NFTs |
|
|
471
|
+
| `fetchV2AccountTokens(address, queryOptions?, options?)` | Get detected ERC20 tokens |
|
|
472
|
+
| `getV1SupportedNetworksQueryOptions(options?)` … `getV2AccountTokensQueryOptions(...)` | Return TanStack Query options for each fetch (use with useQuery, useInfiniteQuery, etc.) |
|
|
473
|
+
| `invalidateBalances()` | Invalidate all balance cache |
|
|
474
|
+
| `invalidateAccounts()` | Invalidate all account cache |
|
|
473
475
|
|
|
474
476
|
#### PricesApiClient
|
|
475
477
|
|
|
476
478
|
Handles price-related operations including spot prices, exchange rates, and historical data.
|
|
477
479
|
|
|
478
|
-
| Method
|
|
479
|
-
|
|
|
480
|
-
| `fetchPriceV1SupportedNetworks()`
|
|
481
|
-
| `fetchPriceV2SupportedNetworks()`
|
|
482
|
-
| `fetchV1ExchangeRates(baseCurrency)`
|
|
483
|
-
| `fetchV1FiatExchangeRates()`
|
|
484
|
-
| `fetchV1CryptoExchangeRates()`
|
|
485
|
-
| `fetchV1SpotPricesByCoinIds(coinIds)`
|
|
486
|
-
| `fetchV1SpotPriceByCoinId(coinId, currency?)`
|
|
487
|
-
| `fetchV1TokenPrices(chainId, addresses, options?)`
|
|
488
|
-
| `fetchV1TokenPrice(chainId, address, currency?)`
|
|
489
|
-
| `fetchV2SpotPrices(chainId, addresses, options?)`
|
|
490
|
-
| `fetchV3SpotPrices(assetIds, options?)`
|
|
491
|
-
| `fetchV1HistoricalPricesByCoinId(coinId, options?)`
|
|
492
|
-
| `fetchV1HistoricalPricesByTokenAddresses(chainId, addresses, options?)`
|
|
493
|
-
| `fetchV1HistoricalPrices(chainId, address, options?)`
|
|
494
|
-
| `fetchV3HistoricalPrices(chainId, assetType, options?)`
|
|
495
|
-
| `fetchV1HistoricalPriceGraphByCoinId(coinId, options?)`
|
|
496
|
-
| `fetchV1HistoricalPriceGraphByTokenAddress(chainId, address, options?)`
|
|
497
|
-
| `
|
|
480
|
+
| Method | Description |
|
|
481
|
+
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
|
|
482
|
+
| `fetchPriceV1SupportedNetworks(options?)` | Get price-supported networks (v1) |
|
|
483
|
+
| `fetchPriceV2SupportedNetworks(options?)` | Get price-supported networks in CAIP format (v2) |
|
|
484
|
+
| `fetchV1ExchangeRates(baseCurrency, options?)` | Get exchange rates for base currency |
|
|
485
|
+
| `fetchV1FiatExchangeRates(options?)` | Get fiat exchange rates |
|
|
486
|
+
| `fetchV1CryptoExchangeRates(options?)` | Get crypto exchange rates |
|
|
487
|
+
| `fetchV1SpotPricesByCoinIds(coinIds, options?)` | Get spot prices by CoinGecko IDs |
|
|
488
|
+
| `fetchV1SpotPriceByCoinId(coinId, currency?, options?)` | Get single coin spot price |
|
|
489
|
+
| `fetchV1TokenPrices(chainId, addresses, queryOptions?, options?)` | Get token prices on chain |
|
|
490
|
+
| `fetchV1TokenPrice(chainId, address, currency?, options?)` | Get single token price |
|
|
491
|
+
| `fetchV2SpotPrices(chainId, addresses, queryOptions?, options?)` | Get spot prices with market data |
|
|
492
|
+
| `fetchV3SpotPrices(assetIds, queryOptions?, options?)` | Get spot prices by CAIP-19 asset IDs |
|
|
493
|
+
| `fetchV1HistoricalPricesByCoinId(coinId, queryOptions?, options?)` | Get historical prices by CoinGecko ID |
|
|
494
|
+
| `fetchV1HistoricalPricesByTokenAddresses(chainId, addresses, queryOptions?, options?)` | Get historical prices for tokens |
|
|
495
|
+
| `fetchV1HistoricalPrices(chainId, address, queryOptions?, options?)` | Get historical prices for single token |
|
|
496
|
+
| `fetchV3HistoricalPrices(chainId, assetType, queryOptions?, options?)` | Get historical prices by CAIP-19 |
|
|
497
|
+
| `fetchV1HistoricalPriceGraphByCoinId(coinId, queryOptions?, options?)` | Get price graph by CoinGecko ID |
|
|
498
|
+
| `fetchV1HistoricalPriceGraphByTokenAddress(chainId, address, queryOptions?, options?)` | Get price graph by token address |
|
|
499
|
+
| `getPriceV1SupportedNetworksQueryOptions(options?)` … `getV1HistoricalPriceGraphByTokenAddressQueryOptions(...)` | Return TanStack Query options for each fetch |
|
|
500
|
+
| `invalidatePrices()` | Invalidate all price cache |
|
|
498
501
|
|
|
499
502
|
#### TokenApiClient
|
|
500
503
|
|
|
501
504
|
Handles token metadata, lists, and trending/popular token discovery.
|
|
502
505
|
|
|
503
|
-
| Method
|
|
504
|
-
|
|
|
505
|
-
| `fetchNetworks()`
|
|
506
|
-
| `fetchNetworkByChainId(chainId)`
|
|
507
|
-
| `fetchTokenList(chainId, options?)`
|
|
508
|
-
| `fetchV1TokenMetadata(chainId, address, options?)`
|
|
509
|
-
| `fetchTokenDescription(chainId, address)`
|
|
510
|
-
| `fetchV3TrendingTokens(chainIds, options?)`
|
|
511
|
-
| `fetchV3TopGainers(chainIds, options?)`
|
|
512
|
-
| `fetchV3PopularTokens(chainIds, options?)`
|
|
513
|
-
| `fetchTopAssets(chainId)`
|
|
514
|
-
| `fetchV1SuggestedOccurrenceFloors()`
|
|
506
|
+
| Method | Description |
|
|
507
|
+
| --------------------------------------------------------------------------------------- | -------------------------------------------- |
|
|
508
|
+
| `fetchNetworks(options?)` | Get all networks |
|
|
509
|
+
| `fetchNetworkByChainId(chainId, options?)` | Get network by chain ID |
|
|
510
|
+
| `fetchTokenList(chainId, queryOptions?, options?)` | Get token list for chain |
|
|
511
|
+
| `fetchV1TokenMetadata(chainId, address, queryOptions?, options?)` | Get token metadata |
|
|
512
|
+
| `fetchTokenDescription(chainId, address, options?)` | Get token description |
|
|
513
|
+
| `fetchV3TrendingTokens(chainIds, queryOptions?, options?)` | Get trending tokens |
|
|
514
|
+
| `fetchV3TopGainers(chainIds, queryOptions?, options?)` | Get top gainers/losers |
|
|
515
|
+
| `fetchV3PopularTokens(chainIds, queryOptions?, options?)` | Get popular tokens |
|
|
516
|
+
| `fetchTopAssets(chainId, options?)` | Get top assets for chain |
|
|
517
|
+
| `fetchV1SuggestedOccurrenceFloors(options?)` | Get suggested occurrence floors |
|
|
518
|
+
| `getNetworksQueryOptions(options?)` … `getV1SuggestedOccurrenceFloorsQueryOptions(...)` | Return TanStack Query options for each fetch |
|
|
515
519
|
|
|
516
520
|
#### TokensApiClient
|
|
517
521
|
|
|
518
522
|
Handles bulk token operations and supported network queries.
|
|
519
523
|
|
|
520
|
-
| Method
|
|
521
|
-
|
|
|
522
|
-
| `fetchTokenV1SupportedNetworks()`
|
|
523
|
-
| `fetchTokenV2SupportedNetworks()`
|
|
524
|
-
| `fetchV3Assets(assetIds)`
|
|
525
|
-
| `
|
|
524
|
+
| Method | Description |
|
|
525
|
+
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
|
|
526
|
+
| `fetchTokenV1SupportedNetworks(options?)` | Get token-supported networks (v1) |
|
|
527
|
+
| `fetchTokenV2SupportedNetworks(options?)` | Get token-supported networks with full/partial support (v2) |
|
|
528
|
+
| `fetchV3Assets(assetIds, queryOptions?, fetchOptions?)` | Fetch assets by CAIP-19 IDs |
|
|
529
|
+
| `getTokenV1SupportedNetworksQueryOptions(options?)` … `getV3AssetsQueryOptions(...)` | Return TanStack Query options for each fetch |
|
|
530
|
+
| `invalidateTokens()` | Invalidate all token cache |
|
|
526
531
|
|
|
527
532
|
### Configuration
|
|
528
533
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=ApiPlatformClientService-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService-method-action-types.cjs","sourceRoot":"","sources":["../src/ApiPlatformClientService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ApiPlatformClientService } from './ApiPlatformClientService';\n\n/**\n * Returns the shared ApiPlatformClient instance.\n *\n * Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.\n *\n * @returns The ApiPlatformClient instance (accounts, prices, token, tokens).\n */\nexport type ApiPlatformClientServiceGetApiPlatformClientAction = {\n type: `ApiPlatformClientService:getApiPlatformClient`;\n handler: ApiPlatformClientService['getApiPlatformClient'];\n};\n\n/**\n * Union of all ApiPlatformClientService action types.\n */\nexport type ApiPlatformClientServiceMethodActions =\n ApiPlatformClientServiceGetApiPlatformClientAction;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { ApiPlatformClientService } from "./ApiPlatformClientService.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Returns the shared ApiPlatformClient instance.
|
|
8
|
+
*
|
|
9
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
10
|
+
*
|
|
11
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
12
|
+
*/
|
|
13
|
+
export type ApiPlatformClientServiceGetApiPlatformClientAction = {
|
|
14
|
+
type: `ApiPlatformClientService:getApiPlatformClient`;
|
|
15
|
+
handler: ApiPlatformClientService['getApiPlatformClient'];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Union of all ApiPlatformClientService action types.
|
|
19
|
+
*/
|
|
20
|
+
export type ApiPlatformClientServiceMethodActions = ApiPlatformClientServiceGetApiPlatformClientAction;
|
|
21
|
+
//# sourceMappingURL=ApiPlatformClientService-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService-method-action-types.d.cts","sourceRoot":"","sources":["../src/ApiPlatformClientService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAE3E;;;;;;GAMG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { ApiPlatformClientService } from "./ApiPlatformClientService.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Returns the shared ApiPlatformClient instance.
|
|
8
|
+
*
|
|
9
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
10
|
+
*
|
|
11
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
12
|
+
*/
|
|
13
|
+
export type ApiPlatformClientServiceGetApiPlatformClientAction = {
|
|
14
|
+
type: `ApiPlatformClientService:getApiPlatformClient`;
|
|
15
|
+
handler: ApiPlatformClientService['getApiPlatformClient'];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Union of all ApiPlatformClientService action types.
|
|
19
|
+
*/
|
|
20
|
+
export type ApiPlatformClientServiceMethodActions = ApiPlatformClientServiceGetApiPlatformClientAction;
|
|
21
|
+
//# sourceMappingURL=ApiPlatformClientService-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService-method-action-types.d.mts","sourceRoot":"","sources":["../src/ApiPlatformClientService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAE3E;;;;;;GAMG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,kDAAkD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService-method-action-types.mjs","sourceRoot":"","sources":["../src/ApiPlatformClientService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ApiPlatformClientService } from './ApiPlatformClientService';\n\n/**\n * Returns the shared ApiPlatformClient instance.\n *\n * Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.\n *\n * @returns The ApiPlatformClient instance (accounts, prices, token, tokens).\n */\nexport type ApiPlatformClientServiceGetApiPlatformClientAction = {\n type: `ApiPlatformClientService:getApiPlatformClient`;\n handler: ApiPlatformClientService['getApiPlatformClient'];\n};\n\n/**\n * Union of all ApiPlatformClientService action types.\n */\nexport type ApiPlatformClientServiceMethodActions =\n ApiPlatformClientServiceGetApiPlatformClientAction;\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ApiPlatformClientService_messenger, _ApiPlatformClientService_client;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ApiPlatformClientService = exports.apiPlatformClientServiceName = void 0;
|
|
16
|
+
const api_1 = require("./api/index.cjs");
|
|
17
|
+
// === GENERAL ===
|
|
18
|
+
/**
|
|
19
|
+
* The name of the {@link ApiPlatformClientService}, used to namespace the
|
|
20
|
+
* service's actions and events.
|
|
21
|
+
*/
|
|
22
|
+
exports.apiPlatformClientServiceName = 'ApiPlatformClientService';
|
|
23
|
+
// === MESSENGER ===
|
|
24
|
+
const MESSENGER_EXPOSED_METHODS = ['getApiPlatformClient'];
|
|
25
|
+
// === SERVICE DEFINITION ===
|
|
26
|
+
/**
|
|
27
|
+
* Service that provides access to {@link ApiPlatformClient} via the messenger.
|
|
28
|
+
*
|
|
29
|
+
* Consumers obtain the client by calling the `ApiPlatformClientService:getApiPlatformClient`
|
|
30
|
+
* action, then use it for accounts, prices, token, and tokens API calls.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Messenger } from '@metamask/messenger';
|
|
36
|
+
* import {
|
|
37
|
+
* ApiPlatformClientService,
|
|
38
|
+
* type ApiPlatformClientServiceActions,
|
|
39
|
+
* type ApiPlatformClientServiceEvents,
|
|
40
|
+
* } from '@metamask/core-backend';
|
|
41
|
+
*
|
|
42
|
+
* const rootMessenger = new Messenger<'Root', ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents>({ namespace: 'Root' });
|
|
43
|
+
* const serviceMessenger = new Messenger<
|
|
44
|
+
* 'ApiPlatformClientService',
|
|
45
|
+
* ApiPlatformClientServiceActions,
|
|
46
|
+
* ApiPlatformClientServiceEvents,
|
|
47
|
+
* typeof rootMessenger
|
|
48
|
+
* >({ namespace: 'ApiPlatformClientService', parent: rootMessenger });
|
|
49
|
+
*
|
|
50
|
+
* new ApiPlatformClientService({
|
|
51
|
+
* messenger: serviceMessenger,
|
|
52
|
+
* clientProduct: 'metamask-extension',
|
|
53
|
+
* getBearerToken: async () => token,
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* const client = rootMessenger.call('ApiPlatformClientService:getApiPlatformClient');
|
|
57
|
+
* const balances = await client.accounts.fetchV5MultiAccountBalances(accountIds);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
class ApiPlatformClientService {
|
|
61
|
+
constructor({ messenger, ...clientOptions }) {
|
|
62
|
+
_ApiPlatformClientService_messenger.set(this, void 0);
|
|
63
|
+
_ApiPlatformClientService_client.set(this, void 0);
|
|
64
|
+
this.name = exports.apiPlatformClientServiceName;
|
|
65
|
+
__classPrivateFieldSet(this, _ApiPlatformClientService_messenger, messenger, "f");
|
|
66
|
+
__classPrivateFieldSet(this, _ApiPlatformClientService_client, new api_1.ApiPlatformClient(clientOptions), "f");
|
|
67
|
+
__classPrivateFieldGet(this, _ApiPlatformClientService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the shared ApiPlatformClient instance.
|
|
71
|
+
*
|
|
72
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
73
|
+
*
|
|
74
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
75
|
+
*/
|
|
76
|
+
getApiPlatformClient() {
|
|
77
|
+
return __classPrivateFieldGet(this, _ApiPlatformClientService_client, "f");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ApiPlatformClientService = ApiPlatformClientService;
|
|
81
|
+
_ApiPlatformClientService_messenger = new WeakMap(), _ApiPlatformClientService_client = new WeakMap();
|
|
82
|
+
//# sourceMappingURL=ApiPlatformClientService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService.cjs","sourceRoot":"","sources":["../src/ApiPlatformClientService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,yCAA0C;AAI1C,kBAAkB;AAElB;;;GAGG;AACU,QAAA,4BAA4B,GAAG,0BAA0B,CAAC;AAEvE,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,sBAAsB,CAAU,CAAC;AA2CpE,6BAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAa,wBAAwB;IAOnC,YAAY,EACV,SAAS,EACT,GAAG,aAAa,EACgB;QAPzB,sDAA8C;QAE9C,mDAA2B;QAMlC,IAAI,CAAC,IAAI,GAAG,oCAA4B,CAAC;QACzC,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,oCAAW,IAAI,uBAAiB,CAAC,aAAa,CAAC,MAAA,CAAC;QAEpD,uBAAA,IAAI,2CAAW,CAAC,4BAA4B,CAC1C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,oBAAoB;QAClB,OAAO,uBAAA,IAAI,wCAAQ,CAAC;IACtB,CAAC;CACF;AA/BD,4DA+BC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\nimport { ApiPlatformClient } from './api';\nimport type { ApiPlatformClientOptions } from './api';\nimport type { ApiPlatformClientServiceMethodActions } from './ApiPlatformClientService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ApiPlatformClientService}, used to namespace the\n * service's actions and events.\n */\nexport const apiPlatformClientServiceName = 'ApiPlatformClientService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['getApiPlatformClient'] as const;\n\n/**\n * Actions that {@link ApiPlatformClientService} exposes to other consumers.\n */\nexport type ApiPlatformClientServiceActions =\n ApiPlatformClientServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ApiPlatformClientServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ApiPlatformClientService} exposes to other consumers.\n */\nexport type ApiPlatformClientServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ApiPlatformClientService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ApiPlatformClientService}.\n */\nexport type ApiPlatformClientServiceMessenger = Messenger<\n typeof apiPlatformClientServiceName,\n ApiPlatformClientServiceActions | AllowedActions,\n ApiPlatformClientServiceEvents | AllowedEvents\n>;\n\n// === SERVICE OPTIONS ===\n\n/**\n * Options for constructing {@link ApiPlatformClientService}.\n */\nexport type ApiPlatformClientServiceOptions = {\n /** The messenger suited for this service. */\n messenger: ApiPlatformClientServiceMessenger;\n} & ApiPlatformClientOptions;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Service that provides access to {@link ApiPlatformClient} via the messenger.\n *\n * Consumers obtain the client by calling the `ApiPlatformClientService:getApiPlatformClient`\n * action, then use it for accounts, prices, token, and tokens API calls.\n *\n * @example\n *\n * ```ts\n * import { Messenger } from '@metamask/messenger';\n * import {\n * ApiPlatformClientService,\n * type ApiPlatformClientServiceActions,\n * type ApiPlatformClientServiceEvents,\n * } from '@metamask/core-backend';\n *\n * const rootMessenger = new Messenger<'Root', ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents>({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'ApiPlatformClientService',\n * ApiPlatformClientServiceActions,\n * ApiPlatformClientServiceEvents,\n * typeof rootMessenger\n * >({ namespace: 'ApiPlatformClientService', parent: rootMessenger });\n *\n * new ApiPlatformClientService({\n * messenger: serviceMessenger,\n * clientProduct: 'metamask-extension',\n * getBearerToken: async () => token,\n * });\n *\n * const client = rootMessenger.call('ApiPlatformClientService:getApiPlatformClient');\n * const balances = await client.accounts.fetchV5MultiAccountBalances(accountIds);\n * ```\n */\nexport class ApiPlatformClientService {\n readonly name: typeof apiPlatformClientServiceName;\n\n readonly #messenger: ApiPlatformClientServiceMessenger;\n\n readonly #client: ApiPlatformClient;\n\n constructor({\n messenger,\n ...clientOptions\n }: ApiPlatformClientServiceOptions) {\n this.name = apiPlatformClientServiceName;\n this.#messenger = messenger;\n this.#client = new ApiPlatformClient(clientOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns the shared ApiPlatformClient instance.\n *\n * Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.\n *\n * @returns The ApiPlatformClient instance (accounts, prices, token, tokens).\n */\n getApiPlatformClient(): ApiPlatformClient {\n return this.#client;\n }\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
|
+
import { ApiPlatformClient } from "./api/index.cjs";
|
|
3
|
+
import type { ApiPlatformClientOptions } from "./api/index.cjs";
|
|
4
|
+
import type { ApiPlatformClientServiceMethodActions } from "./ApiPlatformClientService-method-action-types.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* The name of the {@link ApiPlatformClientService}, used to namespace the
|
|
7
|
+
* service's actions and events.
|
|
8
|
+
*/
|
|
9
|
+
export declare const apiPlatformClientServiceName = "ApiPlatformClientService";
|
|
10
|
+
/**
|
|
11
|
+
* Actions that {@link ApiPlatformClientService} exposes to other consumers.
|
|
12
|
+
*/
|
|
13
|
+
export type ApiPlatformClientServiceActions = ApiPlatformClientServiceMethodActions;
|
|
14
|
+
/**
|
|
15
|
+
* Actions from other messengers that {@link ApiPlatformClientServiceMessenger} calls.
|
|
16
|
+
*/
|
|
17
|
+
type AllowedActions = never;
|
|
18
|
+
/**
|
|
19
|
+
* Events that {@link ApiPlatformClientService} exposes to other consumers.
|
|
20
|
+
*/
|
|
21
|
+
export type ApiPlatformClientServiceEvents = never;
|
|
22
|
+
/**
|
|
23
|
+
* Events from other messengers that {@link ApiPlatformClientService} subscribes to.
|
|
24
|
+
*/
|
|
25
|
+
type AllowedEvents = never;
|
|
26
|
+
/**
|
|
27
|
+
* The messenger which is restricted to actions and events accessed by
|
|
28
|
+
* {@link ApiPlatformClientService}.
|
|
29
|
+
*/
|
|
30
|
+
export type ApiPlatformClientServiceMessenger = Messenger<typeof apiPlatformClientServiceName, ApiPlatformClientServiceActions | AllowedActions, ApiPlatformClientServiceEvents | AllowedEvents>;
|
|
31
|
+
/**
|
|
32
|
+
* Options for constructing {@link ApiPlatformClientService}.
|
|
33
|
+
*/
|
|
34
|
+
export type ApiPlatformClientServiceOptions = {
|
|
35
|
+
/** The messenger suited for this service. */
|
|
36
|
+
messenger: ApiPlatformClientServiceMessenger;
|
|
37
|
+
} & ApiPlatformClientOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Service that provides access to {@link ApiPlatformClient} via the messenger.
|
|
40
|
+
*
|
|
41
|
+
* Consumers obtain the client by calling the `ApiPlatformClientService:getApiPlatformClient`
|
|
42
|
+
* action, then use it for accounts, prices, token, and tokens API calls.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { Messenger } from '@metamask/messenger';
|
|
48
|
+
* import {
|
|
49
|
+
* ApiPlatformClientService,
|
|
50
|
+
* type ApiPlatformClientServiceActions,
|
|
51
|
+
* type ApiPlatformClientServiceEvents,
|
|
52
|
+
* } from '@metamask/core-backend';
|
|
53
|
+
*
|
|
54
|
+
* const rootMessenger = new Messenger<'Root', ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents>({ namespace: 'Root' });
|
|
55
|
+
* const serviceMessenger = new Messenger<
|
|
56
|
+
* 'ApiPlatformClientService',
|
|
57
|
+
* ApiPlatformClientServiceActions,
|
|
58
|
+
* ApiPlatformClientServiceEvents,
|
|
59
|
+
* typeof rootMessenger
|
|
60
|
+
* >({ namespace: 'ApiPlatformClientService', parent: rootMessenger });
|
|
61
|
+
*
|
|
62
|
+
* new ApiPlatformClientService({
|
|
63
|
+
* messenger: serviceMessenger,
|
|
64
|
+
* clientProduct: 'metamask-extension',
|
|
65
|
+
* getBearerToken: async () => token,
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* const client = rootMessenger.call('ApiPlatformClientService:getApiPlatformClient');
|
|
69
|
+
* const balances = await client.accounts.fetchV5MultiAccountBalances(accountIds);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare class ApiPlatformClientService {
|
|
73
|
+
#private;
|
|
74
|
+
readonly name: typeof apiPlatformClientServiceName;
|
|
75
|
+
constructor({ messenger, ...clientOptions }: ApiPlatformClientServiceOptions);
|
|
76
|
+
/**
|
|
77
|
+
* Returns the shared ApiPlatformClient instance.
|
|
78
|
+
*
|
|
79
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
80
|
+
*
|
|
81
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
82
|
+
*/
|
|
83
|
+
getApiPlatformClient(): ApiPlatformClient;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=ApiPlatformClientService.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService.d.cts","sourceRoot":"","sources":["../src/ApiPlatformClientService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,iBAAiB,EAAE,wBAAc;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAc;AACtD,OAAO,KAAK,EAAE,qCAAqC,EAAE,2DAAuD;AAI5G;;;GAGG;AACH,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AAMvE;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,qCAAqC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEnD;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,4BAA4B,EACnC,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAIF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,6CAA6C;IAC7C,SAAS,EAAE,iCAAiC,CAAC;CAC9C,GAAG,wBAAwB,CAAC;AAI7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,wBAAwB;;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,4BAA4B,CAAC;gBAMvC,EACV,SAAS,EACT,GAAG,aAAa,EACjB,EAAE,+BAA+B;IAWlC;;;;;;OAMG;IACH,oBAAoB,IAAI,iBAAiB;CAG1C"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
|
+
import { ApiPlatformClient } from "./api/index.mjs";
|
|
3
|
+
import type { ApiPlatformClientOptions } from "./api/index.mjs";
|
|
4
|
+
import type { ApiPlatformClientServiceMethodActions } from "./ApiPlatformClientService-method-action-types.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* The name of the {@link ApiPlatformClientService}, used to namespace the
|
|
7
|
+
* service's actions and events.
|
|
8
|
+
*/
|
|
9
|
+
export declare const apiPlatformClientServiceName = "ApiPlatformClientService";
|
|
10
|
+
/**
|
|
11
|
+
* Actions that {@link ApiPlatformClientService} exposes to other consumers.
|
|
12
|
+
*/
|
|
13
|
+
export type ApiPlatformClientServiceActions = ApiPlatformClientServiceMethodActions;
|
|
14
|
+
/**
|
|
15
|
+
* Actions from other messengers that {@link ApiPlatformClientServiceMessenger} calls.
|
|
16
|
+
*/
|
|
17
|
+
type AllowedActions = never;
|
|
18
|
+
/**
|
|
19
|
+
* Events that {@link ApiPlatformClientService} exposes to other consumers.
|
|
20
|
+
*/
|
|
21
|
+
export type ApiPlatformClientServiceEvents = never;
|
|
22
|
+
/**
|
|
23
|
+
* Events from other messengers that {@link ApiPlatformClientService} subscribes to.
|
|
24
|
+
*/
|
|
25
|
+
type AllowedEvents = never;
|
|
26
|
+
/**
|
|
27
|
+
* The messenger which is restricted to actions and events accessed by
|
|
28
|
+
* {@link ApiPlatformClientService}.
|
|
29
|
+
*/
|
|
30
|
+
export type ApiPlatformClientServiceMessenger = Messenger<typeof apiPlatformClientServiceName, ApiPlatformClientServiceActions | AllowedActions, ApiPlatformClientServiceEvents | AllowedEvents>;
|
|
31
|
+
/**
|
|
32
|
+
* Options for constructing {@link ApiPlatformClientService}.
|
|
33
|
+
*/
|
|
34
|
+
export type ApiPlatformClientServiceOptions = {
|
|
35
|
+
/** The messenger suited for this service. */
|
|
36
|
+
messenger: ApiPlatformClientServiceMessenger;
|
|
37
|
+
} & ApiPlatformClientOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Service that provides access to {@link ApiPlatformClient} via the messenger.
|
|
40
|
+
*
|
|
41
|
+
* Consumers obtain the client by calling the `ApiPlatformClientService:getApiPlatformClient`
|
|
42
|
+
* action, then use it for accounts, prices, token, and tokens API calls.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { Messenger } from '@metamask/messenger';
|
|
48
|
+
* import {
|
|
49
|
+
* ApiPlatformClientService,
|
|
50
|
+
* type ApiPlatformClientServiceActions,
|
|
51
|
+
* type ApiPlatformClientServiceEvents,
|
|
52
|
+
* } from '@metamask/core-backend';
|
|
53
|
+
*
|
|
54
|
+
* const rootMessenger = new Messenger<'Root', ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents>({ namespace: 'Root' });
|
|
55
|
+
* const serviceMessenger = new Messenger<
|
|
56
|
+
* 'ApiPlatformClientService',
|
|
57
|
+
* ApiPlatformClientServiceActions,
|
|
58
|
+
* ApiPlatformClientServiceEvents,
|
|
59
|
+
* typeof rootMessenger
|
|
60
|
+
* >({ namespace: 'ApiPlatformClientService', parent: rootMessenger });
|
|
61
|
+
*
|
|
62
|
+
* new ApiPlatformClientService({
|
|
63
|
+
* messenger: serviceMessenger,
|
|
64
|
+
* clientProduct: 'metamask-extension',
|
|
65
|
+
* getBearerToken: async () => token,
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* const client = rootMessenger.call('ApiPlatformClientService:getApiPlatformClient');
|
|
69
|
+
* const balances = await client.accounts.fetchV5MultiAccountBalances(accountIds);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare class ApiPlatformClientService {
|
|
73
|
+
#private;
|
|
74
|
+
readonly name: typeof apiPlatformClientServiceName;
|
|
75
|
+
constructor({ messenger, ...clientOptions }: ApiPlatformClientServiceOptions);
|
|
76
|
+
/**
|
|
77
|
+
* Returns the shared ApiPlatformClient instance.
|
|
78
|
+
*
|
|
79
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
80
|
+
*
|
|
81
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
82
|
+
*/
|
|
83
|
+
getApiPlatformClient(): ApiPlatformClient;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=ApiPlatformClientService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiPlatformClientService.d.mts","sourceRoot":"","sources":["../src/ApiPlatformClientService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,iBAAiB,EAAE,wBAAc;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAc;AACtD,OAAO,KAAK,EAAE,qCAAqC,EAAE,2DAAuD;AAI5G;;;GAGG;AACH,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AAMvE;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,qCAAqC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEnD;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,4BAA4B,EACnC,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAIF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,6CAA6C;IAC7C,SAAS,EAAE,iCAAiC,CAAC;CAC9C,GAAG,wBAAwB,CAAC;AAI7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,wBAAwB;;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,4BAA4B,CAAC;gBAMvC,EACV,SAAS,EACT,GAAG,aAAa,EACjB,EAAE,+BAA+B;IAWlC;;;;;;OAMG;IACH,oBAAoB,IAAI,iBAAiB;CAG1C"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ApiPlatformClientService_messenger, _ApiPlatformClientService_client;
|
|
13
|
+
import { ApiPlatformClient } from "./api/index.mjs";
|
|
14
|
+
// === GENERAL ===
|
|
15
|
+
/**
|
|
16
|
+
* The name of the {@link ApiPlatformClientService}, used to namespace the
|
|
17
|
+
* service's actions and events.
|
|
18
|
+
*/
|
|
19
|
+
export const apiPlatformClientServiceName = 'ApiPlatformClientService';
|
|
20
|
+
// === MESSENGER ===
|
|
21
|
+
const MESSENGER_EXPOSED_METHODS = ['getApiPlatformClient'];
|
|
22
|
+
// === SERVICE DEFINITION ===
|
|
23
|
+
/**
|
|
24
|
+
* Service that provides access to {@link ApiPlatformClient} via the messenger.
|
|
25
|
+
*
|
|
26
|
+
* Consumers obtain the client by calling the `ApiPlatformClientService:getApiPlatformClient`
|
|
27
|
+
* action, then use it for accounts, prices, token, and tokens API calls.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { Messenger } from '@metamask/messenger';
|
|
33
|
+
* import {
|
|
34
|
+
* ApiPlatformClientService,
|
|
35
|
+
* type ApiPlatformClientServiceActions,
|
|
36
|
+
* type ApiPlatformClientServiceEvents,
|
|
37
|
+
* } from '@metamask/core-backend';
|
|
38
|
+
*
|
|
39
|
+
* const rootMessenger = new Messenger<'Root', ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents>({ namespace: 'Root' });
|
|
40
|
+
* const serviceMessenger = new Messenger<
|
|
41
|
+
* 'ApiPlatformClientService',
|
|
42
|
+
* ApiPlatformClientServiceActions,
|
|
43
|
+
* ApiPlatformClientServiceEvents,
|
|
44
|
+
* typeof rootMessenger
|
|
45
|
+
* >({ namespace: 'ApiPlatformClientService', parent: rootMessenger });
|
|
46
|
+
*
|
|
47
|
+
* new ApiPlatformClientService({
|
|
48
|
+
* messenger: serviceMessenger,
|
|
49
|
+
* clientProduct: 'metamask-extension',
|
|
50
|
+
* getBearerToken: async () => token,
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const client = rootMessenger.call('ApiPlatformClientService:getApiPlatformClient');
|
|
54
|
+
* const balances = await client.accounts.fetchV5MultiAccountBalances(accountIds);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class ApiPlatformClientService {
|
|
58
|
+
constructor({ messenger, ...clientOptions }) {
|
|
59
|
+
_ApiPlatformClientService_messenger.set(this, void 0);
|
|
60
|
+
_ApiPlatformClientService_client.set(this, void 0);
|
|
61
|
+
this.name = apiPlatformClientServiceName;
|
|
62
|
+
__classPrivateFieldSet(this, _ApiPlatformClientService_messenger, messenger, "f");
|
|
63
|
+
__classPrivateFieldSet(this, _ApiPlatformClientService_client, new ApiPlatformClient(clientOptions), "f");
|
|
64
|
+
__classPrivateFieldGet(this, _ApiPlatformClientService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the shared ApiPlatformClient instance.
|
|
68
|
+
*
|
|
69
|
+
* Use this via the messenger: `messenger.call('ApiPlatformClientService:getApiPlatformClient')`.
|
|
70
|
+
*
|
|
71
|
+
* @returns The ApiPlatformClient instance (accounts, prices, token, tokens).
|
|
72
|
+
*/
|
|
73
|
+
getApiPlatformClient() {
|
|
74
|
+
return __classPrivateFieldGet(this, _ApiPlatformClientService_client, "f");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_ApiPlatformClientService_messenger = new WeakMap(), _ApiPlatformClientService_client = new WeakMap();
|
|
78
|
+
//# sourceMappingURL=ApiPlatformClientService.mjs.map
|