@metamask/core-backend 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +252 -1
- package/dist/AccountActivityService.cjs +1 -1
- package/dist/AccountActivityService.cjs.map +1 -1
- package/dist/AccountActivityService.mjs +1 -1
- package/dist/AccountActivityService.mjs.map +1 -1
- package/dist/BackendWebSocketService.cjs +5 -3
- package/dist/BackendWebSocketService.cjs.map +1 -1
- package/dist/BackendWebSocketService.d.cts +2 -2
- package/dist/BackendWebSocketService.d.cts.map +1 -1
- package/dist/BackendWebSocketService.d.mts +2 -2
- package/dist/BackendWebSocketService.d.mts.map +1 -1
- package/dist/BackendWebSocketService.mjs +5 -3
- package/dist/BackendWebSocketService.mjs.map +1 -1
- package/dist/api/ApiPlatformClient.cjs +177 -0
- package/dist/api/ApiPlatformClient.cjs.map +1 -0
- package/dist/api/ApiPlatformClient.d.cts +127 -0
- package/dist/api/ApiPlatformClient.d.cts.map +1 -0
- package/dist/api/ApiPlatformClient.d.mts +127 -0
- package/dist/api/ApiPlatformClient.d.mts.map +1 -0
- package/dist/api/ApiPlatformClient.mjs +172 -0
- package/dist/api/ApiPlatformClient.mjs.map +1 -0
- package/dist/api/accounts/client.cjs +492 -0
- package/dist/api/accounts/client.cjs.map +1 -0
- package/dist/api/accounts/client.d.cts +213 -0
- package/dist/api/accounts/client.d.cts.map +1 -0
- package/dist/api/accounts/client.d.mts +213 -0
- package/dist/api/accounts/client.d.mts.map +1 -0
- package/dist/api/accounts/client.mjs +488 -0
- package/dist/api/accounts/client.mjs.map +1 -0
- package/dist/api/accounts/index.cjs +9 -0
- package/dist/api/accounts/index.cjs.map +1 -0
- package/dist/api/accounts/index.d.cts +6 -0
- package/dist/api/accounts/index.d.cts.map +1 -0
- package/dist/api/accounts/index.d.mts +6 -0
- package/dist/api/accounts/index.d.mts.map +1 -0
- package/dist/api/accounts/index.mjs +5 -0
- package/dist/api/accounts/index.mjs.map +1 -0
- package/dist/api/accounts/types.cjs +7 -0
- package/dist/api/accounts/types.cjs.map +1 -0
- package/dist/api/accounts/types.d.cts +195 -0
- package/dist/api/accounts/types.d.cts.map +1 -0
- package/dist/api/accounts/types.d.mts +195 -0
- package/dist/api/accounts/types.d.mts.map +1 -0
- package/dist/api/accounts/types.mjs +6 -0
- package/dist/api/accounts/types.mjs.map +1 -0
- package/dist/api/base-client.cjs +149 -0
- package/dist/api/base-client.cjs.map +1 -0
- package/dist/api/base-client.d.cts +54 -0
- package/dist/api/base-client.d.cts.map +1 -0
- package/dist/api/base-client.d.mts +54 -0
- package/dist/api/base-client.d.mts.map +1 -0
- package/dist/api/base-client.mjs +143 -0
- package/dist/api/base-client.mjs.map +1 -0
- package/dist/api/index.cjs +35 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +18 -0
- package/dist/api/index.d.cts.map +1 -0
- package/dist/api/index.d.mts +18 -0
- package/dist/api/index.d.mts.map +1 -0
- package/dist/api/index.mjs +18 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/api/prices/client.cjs +521 -0
- package/dist/api/prices/client.cjs.map +1 -0
- package/dist/api/prices/client.d.cts +235 -0
- package/dist/api/prices/client.d.cts.map +1 -0
- package/dist/api/prices/client.d.mts +235 -0
- package/dist/api/prices/client.d.mts.map +1 -0
- package/dist/api/prices/client.mjs +517 -0
- package/dist/api/prices/client.mjs.map +1 -0
- package/dist/api/prices/index.cjs +9 -0
- package/dist/api/prices/index.cjs.map +1 -0
- package/dist/api/prices/index.d.cts +6 -0
- package/dist/api/prices/index.d.cts.map +1 -0
- package/dist/api/prices/index.d.mts +6 -0
- package/dist/api/prices/index.d.mts.map +1 -0
- package/dist/api/prices/index.mjs +5 -0
- package/dist/api/prices/index.mjs.map +1 -0
- package/dist/api/prices/types.cjs +7 -0
- package/dist/api/prices/types.cjs.map +1 -0
- package/dist/api/prices/types.d.cts +61 -0
- package/dist/api/prices/types.d.cts.map +1 -0
- package/dist/api/prices/types.d.mts +61 -0
- package/dist/api/prices/types.d.mts.map +1 -0
- package/dist/api/prices/types.mjs +6 -0
- package/dist/api/prices/types.mjs.map +1 -0
- package/dist/api/shared-types.cjs +93 -0
- package/dist/api/shared-types.cjs.map +1 -0
- package/dist/api/shared-types.d.cts +131 -0
- package/dist/api/shared-types.d.cts.map +1 -0
- package/dist/api/shared-types.d.mts +131 -0
- package/dist/api/shared-types.d.mts.map +1 -0
- package/dist/api/shared-types.mjs +87 -0
- package/dist/api/shared-types.mjs.map +1 -0
- package/dist/api/test-utils.cjs +70 -0
- package/dist/api/test-utils.cjs.map +1 -0
- package/dist/api/test-utils.d.cts +30 -0
- package/dist/api/test-utils.d.cts.map +1 -0
- package/dist/api/test-utils.d.mts +30 -0
- package/dist/api/test-utils.d.mts.map +1 -0
- package/dist/api/test-utils.mjs +64 -0
- package/dist/api/test-utils.mjs.map +1 -0
- package/dist/api/token/client.cjs +342 -0
- package/dist/api/token/client.cjs.map +1 -0
- package/dist/api/token/client.d.cts +193 -0
- package/dist/api/token/client.d.cts.map +1 -0
- package/dist/api/token/client.d.mts +193 -0
- package/dist/api/token/client.d.mts.map +1 -0
- package/dist/api/token/client.mjs +338 -0
- package/dist/api/token/client.mjs.map +1 -0
- package/dist/api/token/index.cjs +9 -0
- package/dist/api/token/index.cjs.map +1 -0
- package/dist/api/token/index.d.cts +6 -0
- package/dist/api/token/index.d.cts.map +1 -0
- package/dist/api/token/index.d.mts +6 -0
- package/dist/api/token/index.d.mts.map +1 -0
- package/dist/api/token/index.mjs +5 -0
- package/dist/api/token/index.mjs.map +1 -0
- package/dist/api/token/types.cjs +7 -0
- package/dist/api/token/types.cjs.map +1 -0
- package/dist/api/token/types.d.cts +75 -0
- package/dist/api/token/types.d.cts.map +1 -0
- package/dist/api/token/types.d.mts +75 -0
- package/dist/api/token/types.d.mts.map +1 -0
- package/dist/api/token/types.mjs +6 -0
- package/dist/api/token/types.mjs.map +1 -0
- package/dist/api/tokens/client.cjs +91 -0
- package/dist/api/tokens/client.cjs.map +1 -0
- package/dist/api/tokens/client.d.cts +45 -0
- package/dist/api/tokens/client.d.cts.map +1 -0
- package/dist/api/tokens/client.d.mts +45 -0
- package/dist/api/tokens/client.d.mts.map +1 -0
- package/dist/api/tokens/client.mjs +87 -0
- package/dist/api/tokens/client.mjs.map +1 -0
- package/dist/api/tokens/index.cjs +9 -0
- package/dist/api/tokens/index.cjs.map +1 -0
- package/dist/api/tokens/index.d.cts +6 -0
- package/dist/api/tokens/index.d.cts.map +1 -0
- package/dist/api/tokens/index.d.mts +6 -0
- package/dist/api/tokens/index.d.mts.map +1 -0
- package/dist/api/tokens/index.mjs +5 -0
- package/dist/api/tokens/index.mjs.map +1 -0
- package/dist/api/tokens/types.cjs +7 -0
- package/dist/api/tokens/types.cjs.map +1 -0
- package/dist/api/tokens/types.d.cts +83 -0
- package/dist/api/tokens/types.d.cts.map +1 -0
- package/dist/api/tokens/types.d.mts +83 -0
- package/dist/api/tokens/types.d.mts.map +1 -0
- package/dist/api/tokens/types.mjs +6 -0
- package/dist/api/tokens/types.mjs.map +1 -0
- package/dist/index.cjs +33 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +21 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/api/prices/types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * Prices API types for the API Platform Client.\n * API: price.api.cx.metamask.io\n */\n\n// ============================================================================\n// SPOT PRICES TYPES\n// ============================================================================\n\n/** V3 Spot prices response */\nexport type V3SpotPricesResponse = Record<\n string,\n {\n price: number;\n pricePercentChange1d?: number;\n marketCap?: number;\n totalVolume?: number;\n } | null\n>;\n\n/** CoinGecko spot price */\nexport type CoinGeckoSpotPrice = {\n id: string;\n price: number;\n marketCap?: number;\n allTimeHigh?: number;\n allTimeLow?: number;\n totalVolume?: number;\n high1d?: number;\n low1d?: number;\n circulatingSupply?: number;\n dilutedMarketCap?: number;\n marketCapPercentChange1d?: number;\n priceChange1d?: number;\n pricePercentChange1h?: number;\n pricePercentChange1d?: number;\n pricePercentChange7d?: number;\n pricePercentChange14d?: number;\n pricePercentChange30d?: number;\n pricePercentChange200d?: number;\n pricePercentChange1y?: number;\n};\n\n// ============================================================================\n// EXCHANGE RATES TYPES\n// ============================================================================\n\n/** Exchange rate info */\nexport type ExchangeRateInfo = {\n name: string;\n ticker: string;\n value: number;\n currencyType: 'crypto' | 'fiat';\n};\n\n/** Exchange rates response */\nexport type V1ExchangeRatesResponse = {\n [currency: string]: ExchangeRateInfo;\n};\n\n// ============================================================================\n// SUPPORTED NETWORKS TYPES\n// ============================================================================\n\n/** Price supported networks response */\nexport type PriceSupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: string[];\n};\n\n// ============================================================================\n// HISTORICAL PRICES TYPES\n// ============================================================================\n\n/** V1 Historical prices response */\nexport type V1HistoricalPricesResponse = {\n /** Array of price data points as [timestamp, price] tuples */\n prices: [number, number][];\n};\n\n/** V3 Historical prices response */\nexport type V3HistoricalPricesResponse = {\n prices: [number, number][];\n marketCaps?: [number, number][];\n totalVolumes?: [number, number][];\n};\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prices API types for the API Platform Client.
|
|
3
|
+
* API: price.api.cx.metamask.io
|
|
4
|
+
*/
|
|
5
|
+
/** V3 Spot prices response */
|
|
6
|
+
export type V3SpotPricesResponse = Record<string, {
|
|
7
|
+
price: number;
|
|
8
|
+
pricePercentChange1d?: number;
|
|
9
|
+
marketCap?: number;
|
|
10
|
+
totalVolume?: number;
|
|
11
|
+
} | null>;
|
|
12
|
+
/** CoinGecko spot price */
|
|
13
|
+
export type CoinGeckoSpotPrice = {
|
|
14
|
+
id: string;
|
|
15
|
+
price: number;
|
|
16
|
+
marketCap?: number;
|
|
17
|
+
allTimeHigh?: number;
|
|
18
|
+
allTimeLow?: number;
|
|
19
|
+
totalVolume?: number;
|
|
20
|
+
high1d?: number;
|
|
21
|
+
low1d?: number;
|
|
22
|
+
circulatingSupply?: number;
|
|
23
|
+
dilutedMarketCap?: number;
|
|
24
|
+
marketCapPercentChange1d?: number;
|
|
25
|
+
priceChange1d?: number;
|
|
26
|
+
pricePercentChange1h?: number;
|
|
27
|
+
pricePercentChange1d?: number;
|
|
28
|
+
pricePercentChange7d?: number;
|
|
29
|
+
pricePercentChange14d?: number;
|
|
30
|
+
pricePercentChange30d?: number;
|
|
31
|
+
pricePercentChange200d?: number;
|
|
32
|
+
pricePercentChange1y?: number;
|
|
33
|
+
};
|
|
34
|
+
/** Exchange rate info */
|
|
35
|
+
export type ExchangeRateInfo = {
|
|
36
|
+
name: string;
|
|
37
|
+
ticker: string;
|
|
38
|
+
value: number;
|
|
39
|
+
currencyType: 'crypto' | 'fiat';
|
|
40
|
+
};
|
|
41
|
+
/** Exchange rates response */
|
|
42
|
+
export type V1ExchangeRatesResponse = {
|
|
43
|
+
[currency: string]: ExchangeRateInfo;
|
|
44
|
+
};
|
|
45
|
+
/** Price supported networks response */
|
|
46
|
+
export type PriceSupportedNetworksResponse = {
|
|
47
|
+
fullSupport: string[];
|
|
48
|
+
partialSupport: string[];
|
|
49
|
+
};
|
|
50
|
+
/** V1 Historical prices response */
|
|
51
|
+
export type V1HistoricalPricesResponse = {
|
|
52
|
+
/** Array of price data points as [timestamp, price] tuples */
|
|
53
|
+
prices: [number, number][];
|
|
54
|
+
};
|
|
55
|
+
/** V3 Historical prices response */
|
|
56
|
+
export type V3HistoricalPricesResponse = {
|
|
57
|
+
prices: [number, number][];
|
|
58
|
+
marketCaps?: [number, number][];
|
|
59
|
+
totalVolumes?: [number, number][];
|
|
60
|
+
};
|
|
61
|
+
//# sourceMapp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E,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,QAAQ,GAAG,MAAM,CAAC;CACjC,CAAC;AAEF,8BAA8B;AAC9B,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACtC,CAAC;AAMF,wCAAwC;AACxC,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAMF,oCAAoC;AACpC,MAAM,MAAM,0BAA0B,GAAG;IACvC,8DAA8D;IAC9D,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CAC5B,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prices API types for the API Platform Client.
|
|
3
|
+
* API: price.api.cx.metamask.io
|
|
4
|
+
*/
|
|
5
|
+
/** V3 Spot prices response */
|
|
6
|
+
export type V3SpotPricesResponse = Record<string, {
|
|
7
|
+
price: number;
|
|
8
|
+
pricePercentChange1d?: number;
|
|
9
|
+
marketCap?: number;
|
|
10
|
+
totalVolume?: number;
|
|
11
|
+
} | null>;
|
|
12
|
+
/** CoinGecko spot price */
|
|
13
|
+
export type CoinGeckoSpotPrice = {
|
|
14
|
+
id: string;
|
|
15
|
+
price: number;
|
|
16
|
+
marketCap?: number;
|
|
17
|
+
allTimeHigh?: number;
|
|
18
|
+
allTimeLow?: number;
|
|
19
|
+
totalVolume?: number;
|
|
20
|
+
high1d?: number;
|
|
21
|
+
low1d?: number;
|
|
22
|
+
circulatingSupply?: number;
|
|
23
|
+
dilutedMarketCap?: number;
|
|
24
|
+
marketCapPercentChange1d?: number;
|
|
25
|
+
priceChange1d?: number;
|
|
26
|
+
pricePercentChange1h?: number;
|
|
27
|
+
pricePercentChange1d?: number;
|
|
28
|
+
pricePercentChange7d?: number;
|
|
29
|
+
pricePercentChange14d?: number;
|
|
30
|
+
pricePercentChange30d?: number;
|
|
31
|
+
pricePercentChange200d?: number;
|
|
32
|
+
pricePercentChange1y?: number;
|
|
33
|
+
};
|
|
34
|
+
/** Exchange rate info */
|
|
35
|
+
export type ExchangeRateInfo = {
|
|
36
|
+
name: string;
|
|
37
|
+
ticker: string;
|
|
38
|
+
value: number;
|
|
39
|
+
currencyType: 'crypto' | 'fiat';
|
|
40
|
+
};
|
|
41
|
+
/** Exchange rates response */
|
|
42
|
+
export type V1ExchangeRatesResponse = {
|
|
43
|
+
[currency: string]: ExchangeRateInfo;
|
|
44
|
+
};
|
|
45
|
+
/** Price supported networks response */
|
|
46
|
+
export type PriceSupportedNetworksResponse = {
|
|
47
|
+
fullSupport: string[];
|
|
48
|
+
partialSupport: string[];
|
|
49
|
+
};
|
|
50
|
+
/** V1 Historical prices response */
|
|
51
|
+
export type V1HistoricalPricesResponse = {
|
|
52
|
+
/** Array of price data points as [timestamp, price] tuples */
|
|
53
|
+
prices: [number, number][];
|
|
54
|
+
};
|
|
55
|
+
/** V3 Historical prices response */
|
|
56
|
+
export type V3HistoricalPricesResponse = {
|
|
57
|
+
prices: [number, number][];
|
|
58
|
+
marketCaps?: [number, number][];
|
|
59
|
+
totalVolumes?: [number, number][];
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/api/prices/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,8BAA8B;AAC9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AC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACtC,CAAC;AAMF,wCAAwC;AACxC,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAMF,oCAAoC;AACpC,MAAM,MAAM,0BAA0B,GAAG;IACvC,8DAA8D;IAC9D,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CAC5B,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/api/prices/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * Prices API types for the API Platform Client.\n * API: price.api.cx.metamask.io\n */\n\n// ============================================================================\n// SPOT PRICES TYPES\n// ============================================================================\n\n/** V3 Spot prices response */\nexport type V3SpotPricesResponse = Record<\n string,\n {\n price: number;\n pricePercentChange1d?: number;\n marketCap?: number;\n totalVolume?: number;\n } | null\n>;\n\n/** CoinGecko spot price */\nexport type CoinGeckoSpotPrice = {\n id: string;\n price: number;\n marketCap?: number;\n allTimeHigh?: number;\n allTimeLow?: number;\n totalVolume?: number;\n high1d?: number;\n low1d?: number;\n circulatingSupply?: number;\n dilutedMarketCap?: number;\n marketCapPercentChange1d?: number;\n priceChange1d?: number;\n pricePercentChange1h?: number;\n pricePercentChange1d?: number;\n pricePercentChange7d?: number;\n pricePercentChange14d?: number;\n pricePercentChange30d?: number;\n pricePercentChange200d?: number;\n pricePercentChange1y?: number;\n};\n\n// ============================================================================\n// EXCHANGE RATES TYPES\n// ============================================================================\n\n/** Exchange rate info */\nexport type ExchangeRateInfo = {\n name: string;\n ticker: string;\n value: number;\n currencyType: 'crypto' | 'fiat';\n};\n\n/** Exchange rates response */\nexport type V1ExchangeRatesResponse = {\n [currency: string]: ExchangeRateInfo;\n};\n\n// ============================================================================\n// SUPPORTED NETWORKS TYPES\n// ============================================================================\n\n/** Price supported networks response */\nexport type PriceSupportedNetworksResponse = {\n fullSupport: string[];\n partialSupport: string[];\n};\n\n// ============================================================================\n// HISTORICAL PRICES TYPES\n// ============================================================================\n\n/** V1 Historical prices response */\nexport type V1HistoricalPricesResponse = {\n /** Array of price data points as [timestamp, price] tuples */\n prices: [number, number][];\n};\n\n/** V3 Historical prices response */\nexport type V3HistoricalPricesResponse = {\n prices: [number, number][];\n marketCaps?: [number, number][];\n totalVolumes?: [number, number][];\n};\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared types, constants, and utilities for the API Platform Client.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpError = exports.shouldRetry = exports.calculateRetryDelay = exports.RETRY_CONFIG = exports.GC_TIMES = exports.STALE_TIMES = exports.API_URLS = void 0;
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// CONSTANTS
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/** API Base URLs */
|
|
11
|
+
exports.API_URLS = {
|
|
12
|
+
ACCOUNTS: 'https://accounts.api.cx.metamask.io',
|
|
13
|
+
PRICES: 'https://price.api.cx.metamask.io',
|
|
14
|
+
TOKEN: 'https://token.api.cx.metamask.io',
|
|
15
|
+
TOKENS: 'https://tokens.api.cx.metamask.io',
|
|
16
|
+
};
|
|
17
|
+
/** Stale times for different data types (ms) */
|
|
18
|
+
exports.STALE_TIMES = {
|
|
19
|
+
AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token
|
|
20
|
+
PRICES: 30 * 1000, // 30 seconds
|
|
21
|
+
BALANCES: 60 * 1000, // 1 minute
|
|
22
|
+
NETWORKS: 10 * 60 * 1000, // 10 minutes
|
|
23
|
+
SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes
|
|
24
|
+
TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes
|
|
25
|
+
TOKEN_LIST: 10 * 60 * 1000, // 10 minutes
|
|
26
|
+
EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes
|
|
27
|
+
TRENDING: 2 * 60 * 1000, // 2 minutes
|
|
28
|
+
TRANSACTIONS: 30 * 1000, // 30 seconds
|
|
29
|
+
DEFAULT: 30 * 1000, // 30 seconds
|
|
30
|
+
};
|
|
31
|
+
/** Garbage collection times (ms) */
|
|
32
|
+
exports.GC_TIMES = {
|
|
33
|
+
DEFAULT: 5 * 60 * 1000, // 5 minutes
|
|
34
|
+
EXTENDED: 30 * 60 * 1000, // 30 minutes
|
|
35
|
+
SHORT: 2 * 60 * 1000, // 2 minutes
|
|
36
|
+
};
|
|
37
|
+
/** Retry configuration */
|
|
38
|
+
exports.RETRY_CONFIG = {
|
|
39
|
+
MAX_RETRIES: 3,
|
|
40
|
+
BASE_DELAY: 1000,
|
|
41
|
+
MAX_DELAY: 5000,
|
|
42
|
+
};
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// HELPER FUNCTIONS
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
48
|
+
*
|
|
49
|
+
* @param attemptIndex - The current retry attempt (0-indexed).
|
|
50
|
+
* @returns The delay in milliseconds before the next retry.
|
|
51
|
+
*/
|
|
52
|
+
function calculateRetryDelay(attemptIndex) {
|
|
53
|
+
const delay = Math.min(exports.RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex, exports.RETRY_CONFIG.MAX_DELAY);
|
|
54
|
+
return delay / 2 + Math.random() * (delay / 2);
|
|
55
|
+
}
|
|
56
|
+
exports.calculateRetryDelay = calculateRetryDelay;
|
|
57
|
+
/**
|
|
58
|
+
* Determine if a failed request should be retried.
|
|
59
|
+
*
|
|
60
|
+
* @param failureCount - The number of failures so far (1 = first failure).
|
|
61
|
+
* @param error - The error from the failed request.
|
|
62
|
+
* @returns True if the request should be retried, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
function shouldRetry(failureCount, error) {
|
|
65
|
+
// Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)
|
|
66
|
+
if (failureCount > exports.RETRY_CONFIG.MAX_RETRIES) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (error instanceof Error && 'status' in error) {
|
|
70
|
+
const { status } = error;
|
|
71
|
+
// Don't retry 4xx except 429 (rate limit) and 408 (timeout)
|
|
72
|
+
if (status >= 400 && status < 500 && status !== 429 && status !== 408) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
exports.shouldRetry = shouldRetry;
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// HTTP ERROR
|
|
81
|
+
// ============================================================================
|
|
82
|
+
class HttpError extends Error {
|
|
83
|
+
constructor(message, status, statusText, url, body) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = 'HttpError';
|
|
86
|
+
this.status = status;
|
|
87
|
+
this.statusText = statusText;
|
|
88
|
+
this.url = url;
|
|
89
|
+
this.body = body;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.HttpError = HttpError;
|
|
93
|
+
//# sourceMappingURL=shared-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-types.cjs","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAmJH,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,oBAAo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n * Shared types, constants, and utilities for the API Platform Client.\n */\n\nimport type { QueryClient } from '@tanstack/query-core';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\n/**\n * Pagination info for paginated responses\n */\nexport type PageInfo = {\n count: number;\n hasNextPage: boolean;\n cursor?: string;\n};\n\n/**\n * Supported currencies for Price API\n */\nexport type SupportedCurrency =\n // Crypto\n | 'btc'\n | 'eth'\n | 'ltc'\n | 'bch'\n | 'bnb'\n | 'eos'\n | 'xrp'\n | 'xlm'\n | 'link'\n | 'dot'\n | 'yfi'\n // Fiat\n | 'usd'\n | 'aed'\n | 'ars'\n | 'aud'\n | 'bdt'\n | 'bhd'\n | 'bmd'\n | 'brl'\n | 'cad'\n | 'chf'\n | 'clp'\n | 'cny'\n | 'czk'\n | 'dkk'\n | 'eur'\n | 'gbp'\n | 'gel'\n | 'hkd'\n | 'huf'\n | 'idr'\n | 'ils'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'kwd'\n | 'lkr'\n | 'mmk'\n | 'mxn'\n | 'myr'\n | 'ngn'\n | 'nok'\n | 'nzd'\n | 'php'\n | 'pkr'\n | 'pln'\n | 'rub'\n | 'sar'\n | 'sek'\n | 'sgd'\n | 'thb'\n | 'try'\n | 'twd'\n | 'uah'\n | 'vef'\n | 'vnd'\n | 'zar';\n\n/**\n * Market data details from Price API spot-prices endpoint\n */\nexport type MarketDataDetails = {\n /** Current price in the requested currency */\n price: number;\n /** Currency code (e.g., 'ETH', 'USD') */\n currency: string;\n /** 24h price change amount */\n priceChange1d: number;\n /** 24h price change percentage */\n pricePercentChange1d: number;\n /** 1h price change percentage */\n pricePercentChange1h: number;\n /** 7d price change percentage */\n pricePercentChange7d: number;\n /** 14d price change percentage */\n pricePercentChange14d: number;\n /** 30d price change percentage */\n pricePercentChange30d: number;\n /** 200d price change percentage */\n pricePercentChange200d: number;\n /** 1y price change percentage */\n pricePercentChange1y: number;\n /** Market capitalization */\n marketCap: number;\n /** Market cap 24h change percentage */\n marketCapPercentChange1d: number;\n /** All-time high price */\n allTimeHigh: number;\n /** All-time low price */\n allTimeLow: number;\n /** 24h high price */\n high1d: number;\n /** 24h low price */\n low1d: number;\n /** Total trading volume */\n totalVolume: number;\n /** Circulating supply */\n circulatingSupply: number;\n /** Diluted market cap */\n dilutedMarketCap: number;\n};\n\n// ============================================================================\n// CLIENT OPTIONS\n// ============================================================================\n\nexport type ApiPlatformClientOptions = {\n /** Client product identifier (e.g., 'metamask-extension') */\n clientProduct: string;\n /** Optional client version */\n clientVersion?: string;\n /** Function to get bearer token for authenticated requests */\n getBearerToken?: () => Promise<string | undefined>;\n /** Optional custom QueryClient instance */\n queryClient?: QueryClient;\n};\n\nexport type FetchOptions = {\n /** Custom stale time (ms) */\n staleTime?: number;\n /** Custom GC time (ms) */\n gcTime?: number;\n};\n\n// ============================================================================\n// CONSTANTS\n// ============================================================================\n\n/** API Base URLs */\nexport const API_URLS = {\n ACCOUNTS: 'https://accounts.api.cx.metamask.io',\n PRICES: 'https://price.api.cx.metamask.io',\n TOKEN: 'https://token.api.cx.metamask.io',\n TOKENS: 'https://tokens.api.cx.metamask.io',\n} as const;\n\n/** Stale times for different data types (ms) */\nexport const STALE_TIMES = {\n AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token\n PRICES: 30 * 1000, // 30 seconds\n BALANCES: 60 * 1000, // 1 minute\n NETWORKS: 10 * 60 * 1000, // 10 minutes\n SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes\n TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes\n TOKEN_LIST: 10 * 60 * 1000, // 10 minutes\n EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes\n TRENDING: 2 * 60 * 1000, // 2 minutes\n TRANSACTIONS: 30 * 1000, // 30 seconds\n DEFAULT: 30 * 1000, // 30 seconds\n} as const;\n\n/** Garbage collection times (ms) */\nexport const GC_TIMES = {\n DEFAULT: 5 * 60 * 1000, // 5 minutes\n EXTENDED: 30 * 60 * 1000, // 30 minutes\n SHORT: 2 * 60 * 1000, // 2 minutes\n} as const;\n\n/** Retry configuration */\nexport const RETRY_CONFIG = {\n MAX_RETRIES: 3,\n BASE_DELAY: 1000,\n MAX_DELAY: 5_000,\n} as const;\n\n// ============================================================================\n// HELPER FUNCTIONS\n// ============================================================================\n\n/**\n * Calculate retry delay with exponential backoff and jitter.\n *\n * @param attemptIndex - The current retry attempt (0-indexed).\n * @returns The delay in milliseconds before the next retry.\n */\nexport function calculateRetryDelay(attemptIndex: number): number {\n const delay = Math.min(\n RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex,\n RETRY_CONFIG.MAX_DELAY,\n );\n return delay / 2 + Math.random() * (delay / 2);\n}\n\n/**\n * Determine if a failed request should be retried.\n *\n * @param failureCount - The number of failures so far (1 = first failure).\n * @param error - The error from the failed request.\n * @returns True if the request should be retried, false otherwise.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n // Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)\n if (failureCount > RETRY_CONFIG.MAX_RETRIES) {\n return false;\n }\n\n if (error instanceof Error && 'status' in error) {\n const { status } = error as { status: number };\n // Don't retry 4xx except 429 (rate limit) and 408 (timeout)\n if (status >= 400 && status < 500 && status !== 429 && status !== 408) {\n return false;\n }\n }\n return true;\n}\n\n// ============================================================================\n// HTTP ERROR\n// ============================================================================\n\nexport class HttpError extends Error {\n readonly status: number;\n\n readonly statusText: string;\n\n readonly url: string;\n\n readonly body: unknown;\n\n constructor(\n message: string,\n status: number,\n statusText: string,\n url: string,\n body?: unknown,\n ) {\n super(message);\n this.name = 'HttpError';\n this.status = status;\n this.statusText = statusText;\n this.url = url;\n this.body = body;\n }\n}\n"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types, constants, and utilities for the API Platform Client.
|
|
3
|
+
*/
|
|
4
|
+
import type { QueryClient } from "@tanstack/query-core";
|
|
5
|
+
/**
|
|
6
|
+
* Pagination info for paginated responses
|
|
7
|
+
*/
|
|
8
|
+
export type PageInfo = {
|
|
9
|
+
count: number;
|
|
10
|
+
hasNextPage: boolean;
|
|
11
|
+
cursor?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Supported currencies for Price API
|
|
15
|
+
*/
|
|
16
|
+
export type SupportedCurrency = 'btc' | 'eth' | 'ltc' | 'bch' | 'bnb' | 'eos' | 'xrp' | 'xlm' | 'link' | 'dot' | 'yfi' | 'usd' | 'aed' | 'ars' | 'aud' | 'bdt' | 'bhd' | 'bmd' | 'brl' | 'cad' | 'chf' | 'clp' | 'cny' | 'czk' | 'dkk' | 'eur' | 'gbp' | 'gel' | 'hkd' | 'huf' | 'idr' | 'ils' | 'inr' | 'jpy' | 'krw' | 'kwd' | 'lkr' | 'mmk' | 'mxn' | 'myr' | 'ngn' | 'nok' | 'nzd' | 'php' | 'pkr' | 'pln' | 'rub' | 'sar' | 'sek' | 'sgd' | 'thb' | 'try' | 'twd' | 'uah' | 'vef' | 'vnd' | 'zar';
|
|
17
|
+
/**
|
|
18
|
+
* Market data details from Price API spot-prices endpoint
|
|
19
|
+
*/
|
|
20
|
+
export type MarketDataDetails = {
|
|
21
|
+
/** Current price in the requested currency */
|
|
22
|
+
price: number;
|
|
23
|
+
/** Currency code (e.g., 'ETH', 'USD') */
|
|
24
|
+
currency: string;
|
|
25
|
+
/** 24h price change amount */
|
|
26
|
+
priceChange1d: number;
|
|
27
|
+
/** 24h price change percentage */
|
|
28
|
+
pricePercentChange1d: number;
|
|
29
|
+
/** 1h price change percentage */
|
|
30
|
+
pricePercentChange1h: number;
|
|
31
|
+
/** 7d price change percentage */
|
|
32
|
+
pricePercentChange7d: number;
|
|
33
|
+
/** 14d price change percentage */
|
|
34
|
+
pricePercentChange14d: number;
|
|
35
|
+
/** 30d price change percentage */
|
|
36
|
+
pricePercentChange30d: number;
|
|
37
|
+
/** 200d price change percentage */
|
|
38
|
+
pricePercentChange200d: number;
|
|
39
|
+
/** 1y price change percentage */
|
|
40
|
+
pricePercentChange1y: number;
|
|
41
|
+
/** Market capitalization */
|
|
42
|
+
marketCap: number;
|
|
43
|
+
/** Market cap 24h change percentage */
|
|
44
|
+
marketCapPercentChange1d: number;
|
|
45
|
+
/** All-time high price */
|
|
46
|
+
allTimeHigh: number;
|
|
47
|
+
/** All-time low price */
|
|
48
|
+
allTimeLow: number;
|
|
49
|
+
/** 24h high price */
|
|
50
|
+
high1d: number;
|
|
51
|
+
/** 24h low price */
|
|
52
|
+
low1d: number;
|
|
53
|
+
/** Total trading volume */
|
|
54
|
+
totalVolume: number;
|
|
55
|
+
/** Circulating supply */
|
|
56
|
+
circulatingSupply: number;
|
|
57
|
+
/** Diluted market cap */
|
|
58
|
+
dilutedMarketCap: number;
|
|
59
|
+
};
|
|
60
|
+
export type ApiPlatformClientOptions = {
|
|
61
|
+
/** Client product identifier (e.g., 'metamask-extension') */
|
|
62
|
+
clientProduct: string;
|
|
63
|
+
/** Optional client version */
|
|
64
|
+
clientVersion?: string;
|
|
65
|
+
/** Function to get bearer token for authenticated requests */
|
|
66
|
+
getBearerToken?: () => Promise<string | undefined>;
|
|
67
|
+
/** Optional custom QueryClient instance */
|
|
68
|
+
queryClient?: QueryClient;
|
|
69
|
+
};
|
|
70
|
+
export type FetchOptions = {
|
|
71
|
+
/** Custom stale time (ms) */
|
|
72
|
+
staleTime?: number;
|
|
73
|
+
/** Custom GC time (ms) */
|
|
74
|
+
gcTime?: number;
|
|
75
|
+
};
|
|
76
|
+
/** API Base URLs */
|
|
77
|
+
export declare const API_URLS: {
|
|
78
|
+
readonly ACCOUNTS: "https://accounts.api.cx.metamask.io";
|
|
79
|
+
readonly PRICES: "https://price.api.cx.metamask.io";
|
|
80
|
+
readonly TOKEN: "https://token.api.cx.metamask.io";
|
|
81
|
+
readonly TOKENS: "https://tokens.api.cx.metamask.io";
|
|
82
|
+
};
|
|
83
|
+
/** Stale times for different data types (ms) */
|
|
84
|
+
export declare const STALE_TIMES: {
|
|
85
|
+
readonly AUTH_TOKEN: number;
|
|
86
|
+
readonly PRICES: number;
|
|
87
|
+
readonly BALANCES: number;
|
|
88
|
+
readonly NETWORKS: number;
|
|
89
|
+
readonly SUPPORTED_NETWORKS: number;
|
|
90
|
+
readonly TOKEN_METADATA: number;
|
|
91
|
+
readonly TOKEN_LIST: number;
|
|
92
|
+
readonly EXCHANGE_RATES: number;
|
|
93
|
+
readonly TRENDING: number;
|
|
94
|
+
readonly TRANSACTIONS: number;
|
|
95
|
+
readonly DEFAULT: number;
|
|
96
|
+
};
|
|
97
|
+
/** Garbage collection times (ms) */
|
|
98
|
+
export declare const GC_TIMES: {
|
|
99
|
+
readonly DEFAULT: number;
|
|
100
|
+
readonly EXTENDED: number;
|
|
101
|
+
readonly SHORT: number;
|
|
102
|
+
};
|
|
103
|
+
/** Retry configuration */
|
|
104
|
+
export declare const RETRY_CONFIG: {
|
|
105
|
+
readonly MAX_RETRIES: 3;
|
|
106
|
+
readonly BASE_DELAY: 1000;
|
|
107
|
+
readonly MAX_DELAY: 5000;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
111
|
+
*
|
|
112
|
+
* @param attemptIndex - The current retry attempt (0-indexed).
|
|
113
|
+
* @returns The delay in milliseconds before the next retry.
|
|
114
|
+
*/
|
|
115
|
+
export declare function calculateRetryDelay(attemptIndex: number): number;
|
|
116
|
+
/**
|
|
117
|
+
* Determine if a failed request should be retried.
|
|
118
|
+
*
|
|
119
|
+
* @param failureCount - The number of failures so far (1 = first failure).
|
|
120
|
+
* @param error - The error from the failed request.
|
|
121
|
+
* @returns True if the request should be retried, false otherwise.
|
|
122
|
+
*/
|
|
123
|
+
export declare function shouldRetry(failureCount: number, error: unknown): boolean;
|
|
124
|
+
export declare class HttpError extends Error {
|
|
125
|
+
readonly status: number;
|
|
126
|
+
readonly statusText: string;
|
|
127
|
+
readonly url: string;
|
|
128
|
+
readonly body: unknown;
|
|
129
|
+
constructor(message: string, status: number, statusText: string, url: string, body?: unknown);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=shared-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-types.d.cts","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,6BAA6B;AAMxD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAEzB,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,KAAK,GACL,KAAK,GAEL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8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AoB;AACpB,eAAO,MAAM,QAAQ;;;;;CAKX,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,WAAW;;;;;;;;;;;;CAYd,CAAC;AAEX,oCAAoC;AACpC,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,0BAA0B;AAC1B,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAMX;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAczE;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO;CASjB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types, constants, and utilities for the API Platform Client.
|
|
3
|
+
*/
|
|
4
|
+
import type { QueryClient } from "@tanstack/query-core";
|
|
5
|
+
/**
|
|
6
|
+
* Pagination info for paginated responses
|
|
7
|
+
*/
|
|
8
|
+
export type PageInfo = {
|
|
9
|
+
count: number;
|
|
10
|
+
hasNextPage: boolean;
|
|
11
|
+
cursor?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Supported currencies for Price API
|
|
15
|
+
*/
|
|
16
|
+
export type SupportedCurrency = 'btc' | 'eth' | 'ltc' | 'bch' | 'bnb' | 'eos' | 'xrp' | 'xlm' | 'link' | 'dot' | 'yfi' | 'usd' | 'aed' | 'ars' | 'aud' | 'bdt' | 'bhd' | 'bmd' | 'brl' | 'cad' | 'chf' | 'clp' | 'cny' | 'czk' | 'dkk' | 'eur' | 'gbp' | 'gel' | 'hkd' | 'huf' | 'idr' | 'ils' | 'inr' | 'jpy' | 'krw' | 'kwd' | 'lkr' | 'mmk' | 'mxn' | 'myr' | 'ngn' | 'nok' | 'nzd' | 'php' | 'pkr' | 'pln' | 'rub' | 'sar' | 'sek' | 'sgd' | 'thb' | 'try' | 'twd' | 'uah' | 'vef' | 'vnd' | 'zar';
|
|
17
|
+
/**
|
|
18
|
+
* Market data details from Price API spot-prices endpoint
|
|
19
|
+
*/
|
|
20
|
+
export type MarketDataDetails = {
|
|
21
|
+
/** Current price in the requested currency */
|
|
22
|
+
price: number;
|
|
23
|
+
/** Currency code (e.g., 'ETH', 'USD') */
|
|
24
|
+
currency: string;
|
|
25
|
+
/** 24h price change amount */
|
|
26
|
+
priceChange1d: number;
|
|
27
|
+
/** 24h price change percentage */
|
|
28
|
+
pricePercentChange1d: number;
|
|
29
|
+
/** 1h price change percentage */
|
|
30
|
+
pricePercentChange1h: number;
|
|
31
|
+
/** 7d price change percentage */
|
|
32
|
+
pricePercentChange7d: number;
|
|
33
|
+
/** 14d price change percentage */
|
|
34
|
+
pricePercentChange14d: number;
|
|
35
|
+
/** 30d price change percentage */
|
|
36
|
+
pricePercentChange30d: number;
|
|
37
|
+
/** 200d price change percentage */
|
|
38
|
+
pricePercentChange200d: number;
|
|
39
|
+
/** 1y price change percentage */
|
|
40
|
+
pricePercentChange1y: number;
|
|
41
|
+
/** Market capitalization */
|
|
42
|
+
marketCap: number;
|
|
43
|
+
/** Market cap 24h change percentage */
|
|
44
|
+
marketCapPercentChange1d: number;
|
|
45
|
+
/** All-time high price */
|
|
46
|
+
allTimeHigh: number;
|
|
47
|
+
/** All-time low price */
|
|
48
|
+
allTimeLow: number;
|
|
49
|
+
/** 24h high price */
|
|
50
|
+
high1d: number;
|
|
51
|
+
/** 24h low price */
|
|
52
|
+
low1d: number;
|
|
53
|
+
/** Total trading volume */
|
|
54
|
+
totalVolume: number;
|
|
55
|
+
/** Circulating supply */
|
|
56
|
+
circulatingSupply: number;
|
|
57
|
+
/** Diluted market cap */
|
|
58
|
+
dilutedMarketCap: number;
|
|
59
|
+
};
|
|
60
|
+
export type ApiPlatformClientOptions = {
|
|
61
|
+
/** Client product identifier (e.g., 'metamask-extension') */
|
|
62
|
+
clientProduct: string;
|
|
63
|
+
/** Optional client version */
|
|
64
|
+
clientVersion?: string;
|
|
65
|
+
/** Function to get bearer token for authenticated requests */
|
|
66
|
+
getBearerToken?: () => Promise<string | undefined>;
|
|
67
|
+
/** Optional custom QueryClient instance */
|
|
68
|
+
queryClient?: QueryClient;
|
|
69
|
+
};
|
|
70
|
+
export type FetchOptions = {
|
|
71
|
+
/** Custom stale time (ms) */
|
|
72
|
+
staleTime?: number;
|
|
73
|
+
/** Custom GC time (ms) */
|
|
74
|
+
gcTime?: number;
|
|
75
|
+
};
|
|
76
|
+
/** API Base URLs */
|
|
77
|
+
export declare const API_URLS: {
|
|
78
|
+
readonly ACCOUNTS: "https://accounts.api.cx.metamask.io";
|
|
79
|
+
readonly PRICES: "https://price.api.cx.metamask.io";
|
|
80
|
+
readonly TOKEN: "https://token.api.cx.metamask.io";
|
|
81
|
+
readonly TOKENS: "https://tokens.api.cx.metamask.io";
|
|
82
|
+
};
|
|
83
|
+
/** Stale times for different data types (ms) */
|
|
84
|
+
export declare const STALE_TIMES: {
|
|
85
|
+
readonly AUTH_TOKEN: number;
|
|
86
|
+
readonly PRICES: number;
|
|
87
|
+
readonly BALANCES: number;
|
|
88
|
+
readonly NETWORKS: number;
|
|
89
|
+
readonly SUPPORTED_NETWORKS: number;
|
|
90
|
+
readonly TOKEN_METADATA: number;
|
|
91
|
+
readonly TOKEN_LIST: number;
|
|
92
|
+
readonly EXCHANGE_RATES: number;
|
|
93
|
+
readonly TRENDING: number;
|
|
94
|
+
readonly TRANSACTIONS: number;
|
|
95
|
+
readonly DEFAULT: number;
|
|
96
|
+
};
|
|
97
|
+
/** Garbage collection times (ms) */
|
|
98
|
+
export declare const GC_TIMES: {
|
|
99
|
+
readonly DEFAULT: number;
|
|
100
|
+
readonly EXTENDED: number;
|
|
101
|
+
readonly SHORT: number;
|
|
102
|
+
};
|
|
103
|
+
/** Retry configuration */
|
|
104
|
+
export declare const RETRY_CONFIG: {
|
|
105
|
+
readonly MAX_RETRIES: 3;
|
|
106
|
+
readonly BASE_DELAY: 1000;
|
|
107
|
+
readonly MAX_DELAY: 5000;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
111
|
+
*
|
|
112
|
+
* @param attemptIndex - The current retry attempt (0-indexed).
|
|
113
|
+
* @returns The delay in milliseconds before the next retry.
|
|
114
|
+
*/
|
|
115
|
+
export declare function calculateRetryDelay(attemptIndex: number): number;
|
|
116
|
+
/**
|
|
117
|
+
* Determine if a failed request should be retried.
|
|
118
|
+
*
|
|
119
|
+
* @param failureCount - The number of failures so far (1 = first failure).
|
|
120
|
+
* @param error - The error from the failed request.
|
|
121
|
+
* @returns True if the request should be retried, false otherwise.
|
|
122
|
+
*/
|
|
123
|
+
export declare function shouldRetry(failureCount: number, error: unknown): boolean;
|
|
124
|
+
export declare class HttpError extends Error {
|
|
125
|
+
readonly status: number;
|
|
126
|
+
readonly statusText: string;
|
|
127
|
+
readonly url: string;
|
|
128
|
+
readonly body: unknown;
|
|
129
|
+
constructor(message: string, status: number, statusText: string, url: string, body?: unknown);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=shared-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-types.d.mts","sourceRoot":"","sources":["../../src/api/shared-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,6BAA6B;AAMxD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,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,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAczE;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAGrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO;CASjB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types, constants, and utilities for the API Platform Client.
|
|
3
|
+
*/
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// CONSTANTS
|
|
6
|
+
// ============================================================================
|
|
7
|
+
/** API Base URLs */
|
|
8
|
+
export const API_URLS = {
|
|
9
|
+
ACCOUNTS: 'https://accounts.api.cx.metamask.io',
|
|
10
|
+
PRICES: 'https://price.api.cx.metamask.io',
|
|
11
|
+
TOKEN: 'https://token.api.cx.metamask.io',
|
|
12
|
+
TOKENS: 'https://tokens.api.cx.metamask.io',
|
|
13
|
+
};
|
|
14
|
+
/** Stale times for different data types (ms) */
|
|
15
|
+
export const STALE_TIMES = {
|
|
16
|
+
AUTH_TOKEN: 5 * 60 * 1000, // 5 minutes - cache the auth token
|
|
17
|
+
PRICES: 30 * 1000, // 30 seconds
|
|
18
|
+
BALANCES: 60 * 1000, // 1 minute
|
|
19
|
+
NETWORKS: 10 * 60 * 1000, // 10 minutes
|
|
20
|
+
SUPPORTED_NETWORKS: 30 * 60 * 1000, // 30 minutes
|
|
21
|
+
TOKEN_METADATA: 5 * 60 * 1000, // 5 minutes
|
|
22
|
+
TOKEN_LIST: 10 * 60 * 1000, // 10 minutes
|
|
23
|
+
EXCHANGE_RATES: 5 * 60 * 1000, // 5 minutes
|
|
24
|
+
TRENDING: 2 * 60 * 1000, // 2 minutes
|
|
25
|
+
TRANSACTIONS: 30 * 1000, // 30 seconds
|
|
26
|
+
DEFAULT: 30 * 1000, // 30 seconds
|
|
27
|
+
};
|
|
28
|
+
/** Garbage collection times (ms) */
|
|
29
|
+
export const GC_TIMES = {
|
|
30
|
+
DEFAULT: 5 * 60 * 1000, // 5 minutes
|
|
31
|
+
EXTENDED: 30 * 60 * 1000, // 30 minutes
|
|
32
|
+
SHORT: 2 * 60 * 1000, // 2 minutes
|
|
33
|
+
};
|
|
34
|
+
/** Retry configuration */
|
|
35
|
+
export const RETRY_CONFIG = {
|
|
36
|
+
MAX_RETRIES: 3,
|
|
37
|
+
BASE_DELAY: 1000,
|
|
38
|
+
MAX_DELAY: 5000,
|
|
39
|
+
};
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// HELPER FUNCTIONS
|
|
42
|
+
// ============================================================================
|
|
43
|
+
/**
|
|
44
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
45
|
+
*
|
|
46
|
+
* @param attemptIndex - The current retry attempt (0-indexed).
|
|
47
|
+
* @returns The delay in milliseconds before the next retry.
|
|
48
|
+
*/
|
|
49
|
+
export function calculateRetryDelay(attemptIndex) {
|
|
50
|
+
const delay = Math.min(RETRY_CONFIG.BASE_DELAY * 2 ** attemptIndex, RETRY_CONFIG.MAX_DELAY);
|
|
51
|
+
return delay / 2 + Math.random() * (delay / 2);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Determine if a failed request should be retried.
|
|
55
|
+
*
|
|
56
|
+
* @param failureCount - The number of failures so far (1 = first failure).
|
|
57
|
+
* @param error - The error from the failed request.
|
|
58
|
+
* @returns True if the request should be retried, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
export function shouldRetry(failureCount, error) {
|
|
61
|
+
// Allow up to MAX_RETRIES retries (e.g., MAX_RETRIES=3 means 4 total attempts)
|
|
62
|
+
if (failureCount > RETRY_CONFIG.MAX_RETRIES) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (error instanceof Error && 'status' in error) {
|
|
66
|
+
const { status } = error;
|
|
67
|
+
// Don't retry 4xx except 429 (rate limit) and 408 (timeout)
|
|
68
|
+
if (status >= 400 && status < 500 && status !== 429 && status !== 408) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// HTTP ERROR
|
|
76
|
+
// ============================================================================
|
|
77
|
+
export class HttpError extends Error {
|
|
78
|
+
constructor(message, status, statusText, url, body) {
|
|
79
|
+
super(message);
|
|
80
|
+
this.name = 'HttpError';
|
|
81
|
+
this.status = status;
|
|
82
|
+
this.statusText = statusText;
|
|
83
|
+
this.url = url;
|
|
84
|
+
this.body = body;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=shared-types.mjs.map
|