@metamask-previews/controller-utils 11.6.0-preview-f15cb863 → 11.6.0-preview-29fe07c
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 +7 -0
- package/dist/constants.cjs +25 -7
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +20 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +20 -2
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +25 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/create-service-policy.cjs +8 -18
- package/dist/create-service-policy.cjs.map +1 -1
- package/dist/create-service-policy.d.cts +12 -19
- package/dist/create-service-policy.d.cts.map +1 -1
- package/dist/create-service-policy.d.mts +12 -19
- package/dist/create-service-policy.d.mts.map +1 -1
- package/dist/create-service-policy.mjs +7 -19
- package/dist/create-service-policy.mjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +14 -2
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +18 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +18 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +13 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Re-export `ConstantBackoff` and `ExponentialBackoff` from `cockatiel` ([#5492](https://github.com/MetaMask/core/pull/5492))
|
13
|
+
- These can be used to customize service policies
|
14
|
+
- Add optional `backoff` option to `createServicePolicy` ([#5492](https://github.com/MetaMask/core/pull/5492))
|
15
|
+
- This is mainly useful in tests to force the backoff strategy to be constant rather than exponential
|
16
|
+
|
10
17
|
## [11.6.0]
|
11
18
|
|
12
19
|
### Changed
|
package/dist/constants.cjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = exports.ApprovalType = exports.ORIGIN_METAMASK = exports.NFT_API_TIMEOUT = exports.NFT_API_VERSION = exports.NFT_API_BASE_URL = exports.OPENSEA_PROXY_URL = exports.BUILT_IN_NETWORKS = exports.TESTNET_TICKER_SYMBOLS = exports.ASSET_TYPES = exports.GWEI = exports.ERC1155_TOKEN_RECEIVER_INTERFACE_ID = exports.ERC1155_METADATA_URI_INTERFACE_ID = exports.ERC1155_INTERFACE_ID = exports.ERC721_ENUMERABLE_INTERFACE_ID = exports.ERC721_METADATA_INTERFACE_ID = exports.ERC721_INTERFACE_ID = exports.ERC20 = exports.ERC1155 = exports.ERC721 = exports.MAX_SAFE_CHAIN_ID = exports.GANACHE_CHAIN_ID = exports.IPFS_DEFAULT_GATEWAY_URL = exports.FALL_BACK_VS_CURRENCY = exports.RPC = void 0;
|
3
|
+
exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = exports.ApprovalType = exports.ORIGIN_METAMASK = exports.NFT_API_TIMEOUT = exports.NFT_API_VERSION = exports.NFT_API_BASE_URL = exports.OPENSEA_PROXY_URL = exports.BUILT_IN_NETWORKS = exports.BUILT_IN_CUSTOM_NETWORKS_RPC = exports.TESTNET_TICKER_SYMBOLS = exports.ASSET_TYPES = exports.GWEI = exports.ERC1155_TOKEN_RECEIVER_INTERFACE_ID = exports.ERC1155_METADATA_URI_INTERFACE_ID = exports.ERC1155_INTERFACE_ID = exports.ERC721_ENUMERABLE_INTERFACE_ID = exports.ERC721_METADATA_INTERFACE_ID = exports.ERC721_INTERFACE_ID = exports.ERC20 = exports.ERC1155 = exports.ERC721 = exports.MAX_SAFE_CHAIN_ID = exports.GANACHE_CHAIN_ID = exports.IPFS_DEFAULT_GATEWAY_URL = exports.FALL_BACK_VS_CURRENCY = exports.RPC = void 0;
|
4
4
|
const types_1 = require("./types.cjs");
|
5
5
|
exports.RPC = 'rpc';
|
6
6
|
exports.FALL_BACK_VS_CURRENCY = 'ETH';
|
@@ -39,6 +39,13 @@ exports.TESTNET_TICKER_SYMBOLS = {
|
|
39
39
|
SEPOLIA: 'SepoliaETH',
|
40
40
|
LINEA_GOERLI: 'LineaETH',
|
41
41
|
LINEA_SEPOLIA: 'LineaETH',
|
42
|
+
MEGAETH_TESTNET: 'MegaETH',
|
43
|
+
};
|
44
|
+
/**
|
45
|
+
* Map of all built-in custom networks to their RPC endpoints.
|
46
|
+
*/
|
47
|
+
exports.BUILT_IN_CUSTOM_NETWORKS_RPC = {
|
48
|
+
MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc',
|
42
49
|
};
|
43
50
|
/**
|
44
51
|
* Map of all build-in Infura networks to their network, ticker and chain IDs.
|
@@ -48,42 +55,49 @@ exports.BUILT_IN_NETWORKS = {
|
|
48
55
|
chainId: types_1.ChainId.goerli,
|
49
56
|
ticker: types_1.NetworksTicker.goerli,
|
50
57
|
rpcPrefs: {
|
51
|
-
blockExplorerUrl:
|
58
|
+
blockExplorerUrl: types_1.BlockExplorerUrl.goerli,
|
52
59
|
},
|
53
60
|
},
|
54
61
|
[types_1.NetworkType.sepolia]: {
|
55
62
|
chainId: types_1.ChainId.sepolia,
|
56
63
|
ticker: types_1.NetworksTicker.sepolia,
|
57
64
|
rpcPrefs: {
|
58
|
-
blockExplorerUrl:
|
65
|
+
blockExplorerUrl: types_1.BlockExplorerUrl.sepolia,
|
59
66
|
},
|
60
67
|
},
|
61
68
|
[types_1.NetworkType.mainnet]: {
|
62
69
|
chainId: types_1.ChainId.mainnet,
|
63
70
|
ticker: types_1.NetworksTicker.mainnet,
|
64
71
|
rpcPrefs: {
|
65
|
-
blockExplorerUrl:
|
72
|
+
blockExplorerUrl: types_1.BlockExplorerUrl.mainnet,
|
66
73
|
},
|
67
74
|
},
|
68
75
|
[types_1.NetworkType['linea-goerli']]: {
|
69
76
|
chainId: types_1.ChainId['linea-goerli'],
|
70
77
|
ticker: types_1.NetworksTicker['linea-goerli'],
|
71
78
|
rpcPrefs: {
|
72
|
-
blockExplorerUrl: '
|
79
|
+
blockExplorerUrl: types_1.BlockExplorerUrl['linea-goerli'],
|
73
80
|
},
|
74
81
|
},
|
75
82
|
[types_1.NetworkType['linea-sepolia']]: {
|
76
83
|
chainId: types_1.ChainId['linea-sepolia'],
|
77
84
|
ticker: types_1.NetworksTicker['linea-sepolia'],
|
78
85
|
rpcPrefs: {
|
79
|
-
blockExplorerUrl: '
|
86
|
+
blockExplorerUrl: types_1.BlockExplorerUrl['linea-sepolia'],
|
80
87
|
},
|
81
88
|
},
|
82
89
|
[types_1.NetworkType['linea-mainnet']]: {
|
83
90
|
chainId: types_1.ChainId['linea-mainnet'],
|
84
91
|
ticker: types_1.NetworksTicker['linea-mainnet'],
|
85
92
|
rpcPrefs: {
|
86
|
-
blockExplorerUrl:
|
93
|
+
blockExplorerUrl: types_1.BlockExplorerUrl['linea-mainnet'],
|
94
|
+
},
|
95
|
+
},
|
96
|
+
[types_1.NetworkType['megaeth-testnet']]: {
|
97
|
+
chainId: types_1.ChainId['megaeth-testnet'],
|
98
|
+
ticker: types_1.NetworksTicker['megaeth-testnet'],
|
99
|
+
rpcPrefs: {
|
100
|
+
blockExplorerUrl: types_1.BlockExplorerUrl['megaeth-testnet'],
|
87
101
|
},
|
88
102
|
},
|
89
103
|
[types_1.NetworkType.rpc]: {
|
@@ -126,6 +140,10 @@ var ApprovalType;
|
|
126
140
|
ApprovalType["WalletRequestPermissions"] = "wallet_requestPermissions";
|
127
141
|
ApprovalType["WatchAsset"] = "wallet_watchAsset";
|
128
142
|
})(ApprovalType || (exports.ApprovalType = ApprovalType = {}));
|
143
|
+
/**
|
144
|
+
* Mapping of chain IDs to their network names for ENS functionality.
|
145
|
+
* Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.
|
146
|
+
*/
|
129
147
|
exports.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = {
|
130
148
|
[types_1.ChainId.goerli]: types_1.BuiltInNetworkName.Goerli,
|
131
149
|
[types_1.ChainId.sepolia]: types_1.BuiltInNetworkName.Sepolia,
|
package/dist/constants.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,uCAMiB;AAEJ,QAAA,GAAG,GAAG,KAAK,CAAC;AACZ,QAAA,qBAAqB,GAAG,KAAK,CAAC;AAC9B,QAAA,wBAAwB,GAAG,mCAAmC,CAAC;AAE5E,cAAc;AACd,iDAAiD;AACpC,QAAA,gBAAgB,GAAG,OAAO,CAAC,CAAC,cAAc;AACvD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,gBAAgB,CAAC;AAElD,kBAAkB;AACL,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,OAAO,GAAG,SAAS,CAAC;AACpB,QAAA,KAAK,GAAG,OAAO,CAAC;AAE7B,sBAAsB;AACT,QAAA,mBAAmB,GAAG,YAAY,CAAC;AACnC,QAAA,4BAA4B,GAAG,YAAY,CAAC;AAC5C,QAAA,8BAA8B,GAAG,YAAY,CAAC;AAC9C,QAAA,oBAAoB,GAAG,YAAY,CAAC;AACpC,QAAA,iCAAiC,GAAG,YAAY,CAAC;AACjD,QAAA,mCAAmC,GAAG,YAAY,CAAC;AAEhE,QAAQ;AACK,QAAA,IAAI,GAAG,MAAM,CAAC;AAE3B,cAAc;AACD,QAAA,WAAW,GAAG;IACzB,MAAM,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A;IACvC,iDAAiC,CAAA;IACjC,kEAAkD,CAAA;IAClD,2CAA2B,CAAA;IAC3B,iCAAiB,CAAA;IACjB,gDAAgC,CAAA;IAChC,sEAAsD,CAAA;IACtD,gDAAgC,CAAA;AAClC,CAAC,EAnBW,YAAY,4BAAZ,YAAY,QAmBvB;AAED;;;GAGG;AACU,QAAA,mCAAmC,GAG5C;IACF,CAAC,eAAO,CAAC,MAAM,CAAC,EAAE,0BAAkB,CAAC,MAAM;IAC3C,CAAC,eAAO,CAAC,OAAO,CAAC,EAAE,0BAAkB,CAAC,OAAO;IAC7C,CAAC,eAAO,CAAC,OAAO,CAAC,EAAE,0BAAkB,CAAC,OAAO;IAC7C,CAAC,eAAO,CAAC,cAAc,CAAC,CAAC,EAAE,0BAAkB,CAAC,WAAW;IACzD,CAAC,eAAO,CAAC,eAAe,CAAC,CAAC,EAAE,0BAAkB,CAAC,YAAY;IAC3D,CAAC,eAAO,CAAC,eAAe,CAAC,CAAC,EAAE,0BAAkB,CAAC,YAAY;IAC3D,CAAC,eAAO,CAAC,MAAM,CAAC,EAAE,0BAAkB,CAAC,MAAM;CAC5C,CAAC","sourcesContent":["import {\n NetworkType,\n NetworksTicker,\n ChainId,\n BuiltInNetworkName,\n BlockExplorerUrl,\n} from './types';\n\nexport const RPC = 'rpc';\nexport const FALL_BACK_VS_CURRENCY = 'ETH';\nexport const IPFS_DEFAULT_GATEWAY_URL = 'https://cloudflare-ipfs.com/ipfs/';\n\n// NETWORKS ID\n// `toHex` not invoked to avoid cyclic dependency\nexport const GANACHE_CHAIN_ID = '0x539'; // toHex(1337)\n/**\n * The largest possible chain ID we can handle.\n * Explanation: https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553\n */\nexport const MAX_SAFE_CHAIN_ID = 4503599627370476;\n\n// TOKEN STANDARDS\nexport const ERC721 = 'ERC721';\nexport const ERC1155 = 'ERC1155';\nexport const ERC20 = 'ERC20';\n\n// TOKEN INTERFACE IDS\nexport const ERC721_INTERFACE_ID = '0x80ac58cd';\nexport const ERC721_METADATA_INTERFACE_ID = '0x5b5e139f';\nexport const ERC721_ENUMERABLE_INTERFACE_ID = '0x780e9d63';\nexport const ERC1155_INTERFACE_ID = '0xd9b67a26';\nexport const ERC1155_METADATA_URI_INTERFACE_ID = '0x0e89341c';\nexport const ERC1155_TOKEN_RECEIVER_INTERFACE_ID = '0x4e2312e0';\n\n// UNITS\nexport const GWEI = 'gwei';\n\n// ASSET TYPES\nexport const ASSET_TYPES = {\n NATIVE: 'NATIVE',\n TOKEN: 'TOKEN',\n NFT: 'NFT',\n UNKNOWN: 'UNKNOWN',\n};\n\n// TICKER SYMBOLS\nexport const TESTNET_TICKER_SYMBOLS = {\n GOERLI: 'GoerliETH',\n SEPOLIA: 'SepoliaETH',\n LINEA_GOERLI: 'LineaETH',\n LINEA_SEPOLIA: 'LineaETH',\n MEGAETH_TESTNET: 'MegaETH',\n};\n\n/**\n * Map of all built-in custom networks to their RPC endpoints.\n */\nexport const BUILT_IN_CUSTOM_NETWORKS_RPC = {\n MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc',\n};\n\n/**\n * Map of all build-in Infura networks to their network, ticker and chain IDs.\n */\nexport const BUILT_IN_NETWORKS = {\n [NetworkType.goerli]: {\n chainId: ChainId.goerli,\n ticker: NetworksTicker.goerli,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.goerli,\n },\n },\n [NetworkType.sepolia]: {\n chainId: ChainId.sepolia,\n ticker: NetworksTicker.sepolia,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.sepolia,\n },\n },\n [NetworkType.mainnet]: {\n chainId: ChainId.mainnet,\n ticker: NetworksTicker.mainnet,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.mainnet,\n },\n },\n [NetworkType['linea-goerli']]: {\n chainId: ChainId['linea-goerli'],\n ticker: NetworksTicker['linea-goerli'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-goerli'],\n },\n },\n [NetworkType['linea-sepolia']]: {\n chainId: ChainId['linea-sepolia'],\n ticker: NetworksTicker['linea-sepolia'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-sepolia'],\n },\n },\n [NetworkType['linea-mainnet']]: {\n chainId: ChainId['linea-mainnet'],\n ticker: NetworksTicker['linea-mainnet'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-mainnet'],\n },\n },\n [NetworkType['megaeth-testnet']]: {\n chainId: ChainId['megaeth-testnet'],\n ticker: NetworksTicker['megaeth-testnet'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['megaeth-testnet'],\n },\n },\n [NetworkType.rpc]: {\n chainId: undefined,\n blockExplorerUrl: undefined,\n ticker: undefined,\n rpcPrefs: undefined,\n },\n} as const;\n\n// APIs\nexport const OPENSEA_PROXY_URL =\n 'https://proxy.api.cx.metamask.io/opensea/v1/api/v2';\n\nexport const NFT_API_BASE_URL = 'https://nft.api.cx.metamask.io';\n\nexport const NFT_API_VERSION = '1';\n\nexport const NFT_API_TIMEOUT = 15000;\n\n// Default origin for controllers\nexport const ORIGIN_METAMASK = 'metamask';\n\n/**\n * Approval request types for various operations.\n * These types are used by different controllers to create and manage\n * approval requests consistently.\n */\nexport enum ApprovalType {\n AddEthereumChain = 'wallet_addEthereumChain',\n ConnectAccounts = 'connect_accounts',\n EthDecrypt = 'eth_decrypt',\n EthGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n EthSignTypedData = 'eth_signTypedData',\n PersonalSign = 'personal_sign',\n ResultError = 'result_error',\n ResultSuccess = 'result_success',\n SnapDialogAlert = 'snap_dialog:alert',\n SnapDialogConfirmation = 'snap_dialog:confirmation',\n SnapDialogPrompt = 'snap_dialog:prompt',\n SnapDialogDefault = 'snap_dialog',\n SwitchEthereumChain = 'wallet_switchEthereumChain',\n Transaction = 'transaction',\n Unlock = 'unlock',\n WalletConnect = 'wallet_connect',\n WalletRequestPermissions = 'wallet_requestPermissions',\n WatchAsset = 'wallet_watchAsset',\n}\n\n/**\n * Mapping of chain IDs to their network names for ENS functionality.\n * Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.\n */\nexport const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP: Record<\n string,\n BuiltInNetworkName\n> = {\n [ChainId.goerli]: BuiltInNetworkName.Goerli,\n [ChainId.sepolia]: BuiltInNetworkName.Sepolia,\n [ChainId.mainnet]: BuiltInNetworkName.Mainnet,\n [ChainId['linea-goerli']]: BuiltInNetworkName.LineaGoerli,\n [ChainId['linea-sepolia']]: BuiltInNetworkName.LineaSepolia,\n [ChainId['linea-mainnet']]: BuiltInNetworkName.LineaMainnet,\n [ChainId.aurora]: BuiltInNetworkName.Aurora,\n};\n"]}
|
package/dist/constants.d.cts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { NetworksTicker,
|
1
|
+
import { NetworksTicker, BuiltInNetworkName } from "./types.cjs";
|
2
2
|
export declare const RPC = "rpc";
|
3
3
|
export declare const FALL_BACK_VS_CURRENCY = "ETH";
|
4
4
|
export declare const IPFS_DEFAULT_GATEWAY_URL = "https://cloudflare-ipfs.com/ipfs/";
|
@@ -29,6 +29,13 @@ export declare const TESTNET_TICKER_SYMBOLS: {
|
|
29
29
|
SEPOLIA: string;
|
30
30
|
LINEA_GOERLI: string;
|
31
31
|
LINEA_SEPOLIA: string;
|
32
|
+
MEGAETH_TESTNET: string;
|
33
|
+
};
|
34
|
+
/**
|
35
|
+
* Map of all built-in custom networks to their RPC endpoints.
|
36
|
+
*/
|
37
|
+
export declare const BUILT_IN_CUSTOM_NETWORKS_RPC: {
|
38
|
+
MEGAETH_TESTNET: string;
|
32
39
|
};
|
33
40
|
/**
|
34
41
|
* Map of all build-in Infura networks to their network, ticker and chain IDs.
|
@@ -76,6 +83,13 @@ export declare const BUILT_IN_NETWORKS: {
|
|
76
83
|
readonly blockExplorerUrl: "https://lineascan.build";
|
77
84
|
};
|
78
85
|
};
|
86
|
+
readonly "megaeth-testnet": {
|
87
|
+
readonly chainId: "0x18c6";
|
88
|
+
readonly ticker: (typeof NetworksTicker)["megaeth-testnet"];
|
89
|
+
readonly rpcPrefs: {
|
90
|
+
readonly blockExplorerUrl: "https://megaexplorer.xyz";
|
91
|
+
};
|
92
|
+
};
|
79
93
|
readonly rpc: {
|
80
94
|
readonly chainId: undefined;
|
81
95
|
readonly blockExplorerUrl: undefined;
|
@@ -113,5 +127,9 @@ export declare enum ApprovalType {
|
|
113
127
|
WalletRequestPermissions = "wallet_requestPermissions",
|
114
128
|
WatchAsset = "wallet_watchAsset"
|
115
129
|
}
|
116
|
-
|
130
|
+
/**
|
131
|
+
* Mapping of chain IDs to their network names for ENS functionality.
|
132
|
+
* Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.
|
133
|
+
*/
|
134
|
+
export declare const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP: Record<string, BuiltInNetworkName>;
|
117
135
|
//# sourceMappingURL=constants.d.cts.map
|
package/dist/constants.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,kBAAkB,EAEnB,oBAAgB;AAEjB,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,eAAO,MAAM,wBAAwB,sCAAsC,CAAC;AAI5E,eAAO,MAAM,gBAAgB,UAAU,CAAC;AACxC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAGlD,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,KAAK,UAAU,CAAC;AAG7B,eA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AAC"}
|
package/dist/constants.d.mts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { NetworksTicker,
|
1
|
+
import { NetworksTicker, BuiltInNetworkName } from "./types.mjs";
|
2
2
|
export declare const RPC = "rpc";
|
3
3
|
export declare const FALL_BACK_VS_CURRENCY = "ETH";
|
4
4
|
export declare const IPFS_DEFAULT_GATEWAY_URL = "https://cloudflare-ipfs.com/ipfs/";
|
@@ -29,6 +29,13 @@ export declare const TESTNET_TICKER_SYMBOLS: {
|
|
29
29
|
SEPOLIA: string;
|
30
30
|
LINEA_GOERLI: string;
|
31
31
|
LINEA_SEPOLIA: string;
|
32
|
+
MEGAETH_TESTNET: string;
|
33
|
+
};
|
34
|
+
/**
|
35
|
+
* Map of all built-in custom networks to their RPC endpoints.
|
36
|
+
*/
|
37
|
+
export declare const BUILT_IN_CUSTOM_NETWORKS_RPC: {
|
38
|
+
MEGAETH_TESTNET: string;
|
32
39
|
};
|
33
40
|
/**
|
34
41
|
* Map of all build-in Infura networks to their network, ticker and chain IDs.
|
@@ -76,6 +83,13 @@ export declare const BUILT_IN_NETWORKS: {
|
|
76
83
|
readonly blockExplorerUrl: "https://lineascan.build";
|
77
84
|
};
|
78
85
|
};
|
86
|
+
readonly "megaeth-testnet": {
|
87
|
+
readonly chainId: "0x18c6";
|
88
|
+
readonly ticker: (typeof NetworksTicker)["megaeth-testnet"];
|
89
|
+
readonly rpcPrefs: {
|
90
|
+
readonly blockExplorerUrl: "https://megaexplorer.xyz";
|
91
|
+
};
|
92
|
+
};
|
79
93
|
readonly rpc: {
|
80
94
|
readonly chainId: undefined;
|
81
95
|
readonly blockExplorerUrl: undefined;
|
@@ -113,5 +127,9 @@ export declare enum ApprovalType {
|
|
113
127
|
WalletRequestPermissions = "wallet_requestPermissions",
|
114
128
|
WatchAsset = "wallet_watchAsset"
|
115
129
|
}
|
116
|
-
|
130
|
+
/**
|
131
|
+
* Mapping of chain IDs to their network names for ENS functionality.
|
132
|
+
* Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.
|
133
|
+
*/
|
134
|
+
export declare const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP: Record<string, BuiltInNetworkName>;
|
117
135
|
//# sourceMappingURL=constants.d.mts.map
|
package/dist/constants.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,kBAAkB,EAEnB,oBAAgB;AAEjB,eAAO,MAAM,GAAG,QAAQ,CAAC;AACzB,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,eAAO,MAAM,wBAAwB,sCAAsC,CAAC;AAI5E,eAAO,MAAM,gBAAgB,UAAU,CAAC;AACxC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAGlD,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,KAAK,UAAU,CAAC;AAG7B,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAChD,eAAO,MAAM,4BAA4B,eAAe,CAAC;AACzD,eAAO,MAAM,8BAA8B,eAAe,CAAC;AAC3D,eAAO,MAAM,oBAAoB,eAAe,CAAC;AACjD,eAAO,MAAM,iCAAiC,eAAe,CAAC;AAC9D,eAAO,MAAM,mCAAmC,eAAe,CAAC;AAGhE,eAAO,MAAM,IAAI,SAAS,CAAC;AAG3B,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC;AAGF,eAAO,MAAM,sBAAsB;;;;;;CAMlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,4BAA4B;;CAExC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDpB,CAAC;AAGX,eAAO,MAAM,iBAAiB,uDACwB,CAAC;AAEvD,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AAEjE,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAGrC,eAAO,MAAM,eAAe,aAAa,CAAC;AAE1C;;;;GAIG;AACH,oBAAY,YAAY;IACtB,gBAAgB,4BAA4B;IAC5C,eAAe,qBAAqB;IACpC,UAAU,gBAAgB;IAC1B,yBAAyB,+BAA+B;IACxD,gBAAgB,sBAAsB;IACtC,YAAY,kBAAkB;IAC9B,WAAW,iBAAiB;IAC5B,aAAa,mBAAmB;IAChC,eAAe,sBAAsB;IACrC,sBAAsB,6BAA6B;IACnD,gBAAgB,uBAAuB;IACvC,iBAAiB,gBAAgB;IACjC,mBAAmB,+BAA+B;IAClD,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,aAAa,mBAAmB;IAChC,wBAAwB,8BAA8B;IACtD,UAAU,sBAAsB;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,mCAAmC,EAAE,MAAM,CACtD,MAAM,EACN,kBAAkB,CASnB,CAAC"}
|
package/dist/constants.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { NetworkType, NetworksTicker, ChainId, BuiltInNetworkName } from "./types.mjs";
|
1
|
+
import { NetworkType, NetworksTicker, ChainId, BuiltInNetworkName, BlockExplorerUrl } from "./types.mjs";
|
2
2
|
export const RPC = 'rpc';
|
3
3
|
export const FALL_BACK_VS_CURRENCY = 'ETH';
|
4
4
|
export const IPFS_DEFAULT_GATEWAY_URL = 'https://cloudflare-ipfs.com/ipfs/';
|
@@ -36,6 +36,13 @@ export const TESTNET_TICKER_SYMBOLS = {
|
|
36
36
|
SEPOLIA: 'SepoliaETH',
|
37
37
|
LINEA_GOERLI: 'LineaETH',
|
38
38
|
LINEA_SEPOLIA: 'LineaETH',
|
39
|
+
MEGAETH_TESTNET: 'MegaETH',
|
40
|
+
};
|
41
|
+
/**
|
42
|
+
* Map of all built-in custom networks to their RPC endpoints.
|
43
|
+
*/
|
44
|
+
export const BUILT_IN_CUSTOM_NETWORKS_RPC = {
|
45
|
+
MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc',
|
39
46
|
};
|
40
47
|
/**
|
41
48
|
* Map of all build-in Infura networks to their network, ticker and chain IDs.
|
@@ -45,42 +52,49 @@ export const BUILT_IN_NETWORKS = {
|
|
45
52
|
chainId: ChainId.goerli,
|
46
53
|
ticker: NetworksTicker.goerli,
|
47
54
|
rpcPrefs: {
|
48
|
-
blockExplorerUrl:
|
55
|
+
blockExplorerUrl: BlockExplorerUrl.goerli,
|
49
56
|
},
|
50
57
|
},
|
51
58
|
[NetworkType.sepolia]: {
|
52
59
|
chainId: ChainId.sepolia,
|
53
60
|
ticker: NetworksTicker.sepolia,
|
54
61
|
rpcPrefs: {
|
55
|
-
blockExplorerUrl:
|
62
|
+
blockExplorerUrl: BlockExplorerUrl.sepolia,
|
56
63
|
},
|
57
64
|
},
|
58
65
|
[NetworkType.mainnet]: {
|
59
66
|
chainId: ChainId.mainnet,
|
60
67
|
ticker: NetworksTicker.mainnet,
|
61
68
|
rpcPrefs: {
|
62
|
-
blockExplorerUrl:
|
69
|
+
blockExplorerUrl: BlockExplorerUrl.mainnet,
|
63
70
|
},
|
64
71
|
},
|
65
72
|
[NetworkType['linea-goerli']]: {
|
66
73
|
chainId: ChainId['linea-goerli'],
|
67
74
|
ticker: NetworksTicker['linea-goerli'],
|
68
75
|
rpcPrefs: {
|
69
|
-
blockExplorerUrl: '
|
76
|
+
blockExplorerUrl: BlockExplorerUrl['linea-goerli'],
|
70
77
|
},
|
71
78
|
},
|
72
79
|
[NetworkType['linea-sepolia']]: {
|
73
80
|
chainId: ChainId['linea-sepolia'],
|
74
81
|
ticker: NetworksTicker['linea-sepolia'],
|
75
82
|
rpcPrefs: {
|
76
|
-
blockExplorerUrl: '
|
83
|
+
blockExplorerUrl: BlockExplorerUrl['linea-sepolia'],
|
77
84
|
},
|
78
85
|
},
|
79
86
|
[NetworkType['linea-mainnet']]: {
|
80
87
|
chainId: ChainId['linea-mainnet'],
|
81
88
|
ticker: NetworksTicker['linea-mainnet'],
|
82
89
|
rpcPrefs: {
|
83
|
-
blockExplorerUrl: '
|
90
|
+
blockExplorerUrl: BlockExplorerUrl['linea-mainnet'],
|
91
|
+
},
|
92
|
+
},
|
93
|
+
[NetworkType['megaeth-testnet']]: {
|
94
|
+
chainId: ChainId['megaeth-testnet'],
|
95
|
+
ticker: NetworksTicker['megaeth-testnet'],
|
96
|
+
rpcPrefs: {
|
97
|
+
blockExplorerUrl: BlockExplorerUrl['megaeth-testnet'],
|
84
98
|
},
|
85
99
|
},
|
86
100
|
[NetworkType.rpc]: {
|
@@ -123,6 +137,10 @@ export var ApprovalType;
|
|
123
137
|
ApprovalType["WalletRequestPermissions"] = "wallet_requestPermissions";
|
124
138
|
ApprovalType["WatchAsset"] = "wallet_watchAsset";
|
125
139
|
})(ApprovalType || (ApprovalType = {}));
|
140
|
+
/**
|
141
|
+
* Mapping of chain IDs to their network names for ENS functionality.
|
142
|
+
* Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.
|
143
|
+
*/
|
126
144
|
export const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP = {
|
127
145
|
[ChainId.goerli]: BuiltInNetworkName.Goerli,
|
128
146
|
[ChainId.sepolia]: BuiltInNetworkName.Sepolia,
|
package/dist/constants.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,EACd,OAAO,EACP,kBAAkB,
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,cAAc,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Z,YAAY,QAmBvB;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAG5C;IACF,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC,MAAM;IAC3C,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO;IAC7C,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO;IAC7C,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,EAAE,kBAAkB,CAAC,WAAW;IACzD,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,kBAAkB,CAAC,YAAY;IAC3D,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,kBAAkB,CAAC,YAAY;IAC3D,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC,MAAM;CAC5C,CAAC","sourcesContent":["import {\n NetworkType,\n NetworksTicker,\n ChainId,\n BuiltInNetworkName,\n BlockExplorerUrl,\n} from './types';\n\nexport const RPC = 'rpc';\nexport const FALL_BACK_VS_CURRENCY = 'ETH';\nexport const IPFS_DEFAULT_GATEWAY_URL = 'https://cloudflare-ipfs.com/ipfs/';\n\n// NETWORKS ID\n// `toHex` not invoked to avoid cyclic dependency\nexport const GANACHE_CHAIN_ID = '0x539'; // toHex(1337)\n/**\n * The largest possible chain ID we can handle.\n * Explanation: https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553\n */\nexport const MAX_SAFE_CHAIN_ID = 4503599627370476;\n\n// TOKEN STANDARDS\nexport const ERC721 = 'ERC721';\nexport const ERC1155 = 'ERC1155';\nexport const ERC20 = 'ERC20';\n\n// TOKEN INTERFACE IDS\nexport const ERC721_INTERFACE_ID = '0x80ac58cd';\nexport const ERC721_METADATA_INTERFACE_ID = '0x5b5e139f';\nexport const ERC721_ENUMERABLE_INTERFACE_ID = '0x780e9d63';\nexport const ERC1155_INTERFACE_ID = '0xd9b67a26';\nexport const ERC1155_METADATA_URI_INTERFACE_ID = '0x0e89341c';\nexport const ERC1155_TOKEN_RECEIVER_INTERFACE_ID = '0x4e2312e0';\n\n// UNITS\nexport const GWEI = 'gwei';\n\n// ASSET TYPES\nexport const ASSET_TYPES = {\n NATIVE: 'NATIVE',\n TOKEN: 'TOKEN',\n NFT: 'NFT',\n UNKNOWN: 'UNKNOWN',\n};\n\n// TICKER SYMBOLS\nexport const TESTNET_TICKER_SYMBOLS = {\n GOERLI: 'GoerliETH',\n SEPOLIA: 'SepoliaETH',\n LINEA_GOERLI: 'LineaETH',\n LINEA_SEPOLIA: 'LineaETH',\n MEGAETH_TESTNET: 'MegaETH',\n};\n\n/**\n * Map of all built-in custom networks to their RPC endpoints.\n */\nexport const BUILT_IN_CUSTOM_NETWORKS_RPC = {\n MEGAETH_TESTNET: 'https://carrot.megaeth.com/rpc',\n};\n\n/**\n * Map of all build-in Infura networks to their network, ticker and chain IDs.\n */\nexport const BUILT_IN_NETWORKS = {\n [NetworkType.goerli]: {\n chainId: ChainId.goerli,\n ticker: NetworksTicker.goerli,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.goerli,\n },\n },\n [NetworkType.sepolia]: {\n chainId: ChainId.sepolia,\n ticker: NetworksTicker.sepolia,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.sepolia,\n },\n },\n [NetworkType.mainnet]: {\n chainId: ChainId.mainnet,\n ticker: NetworksTicker.mainnet,\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl.mainnet,\n },\n },\n [NetworkType['linea-goerli']]: {\n chainId: ChainId['linea-goerli'],\n ticker: NetworksTicker['linea-goerli'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-goerli'],\n },\n },\n [NetworkType['linea-sepolia']]: {\n chainId: ChainId['linea-sepolia'],\n ticker: NetworksTicker['linea-sepolia'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-sepolia'],\n },\n },\n [NetworkType['linea-mainnet']]: {\n chainId: ChainId['linea-mainnet'],\n ticker: NetworksTicker['linea-mainnet'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['linea-mainnet'],\n },\n },\n [NetworkType['megaeth-testnet']]: {\n chainId: ChainId['megaeth-testnet'],\n ticker: NetworksTicker['megaeth-testnet'],\n rpcPrefs: {\n blockExplorerUrl: BlockExplorerUrl['megaeth-testnet'],\n },\n },\n [NetworkType.rpc]: {\n chainId: undefined,\n blockExplorerUrl: undefined,\n ticker: undefined,\n rpcPrefs: undefined,\n },\n} as const;\n\n// APIs\nexport const OPENSEA_PROXY_URL =\n 'https://proxy.api.cx.metamask.io/opensea/v1/api/v2';\n\nexport const NFT_API_BASE_URL = 'https://nft.api.cx.metamask.io';\n\nexport const NFT_API_VERSION = '1';\n\nexport const NFT_API_TIMEOUT = 15000;\n\n// Default origin for controllers\nexport const ORIGIN_METAMASK = 'metamask';\n\n/**\n * Approval request types for various operations.\n * These types are used by different controllers to create and manage\n * approval requests consistently.\n */\nexport enum ApprovalType {\n AddEthereumChain = 'wallet_addEthereumChain',\n ConnectAccounts = 'connect_accounts',\n EthDecrypt = 'eth_decrypt',\n EthGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n EthSignTypedData = 'eth_signTypedData',\n PersonalSign = 'personal_sign',\n ResultError = 'result_error',\n ResultSuccess = 'result_success',\n SnapDialogAlert = 'snap_dialog:alert',\n SnapDialogConfirmation = 'snap_dialog:confirmation',\n SnapDialogPrompt = 'snap_dialog:prompt',\n SnapDialogDefault = 'snap_dialog',\n SwitchEthereumChain = 'wallet_switchEthereumChain',\n Transaction = 'transaction',\n Unlock = 'unlock',\n WalletConnect = 'wallet_connect',\n WalletRequestPermissions = 'wallet_requestPermissions',\n WatchAsset = 'wallet_watchAsset',\n}\n\n/**\n * Mapping of chain IDs to their network names for ENS functionality.\n * Note: MegaETH-testnet is intentionally excluded from this mapping as it doesn't support ENS.\n */\nexport const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP: Record<\n string,\n BuiltInNetworkName\n> = {\n [ChainId.goerli]: BuiltInNetworkName.Goerli,\n [ChainId.sepolia]: BuiltInNetworkName.Sepolia,\n [ChainId.mainnet]: BuiltInNetworkName.Mainnet,\n [ChainId['linea-goerli']]: BuiltInNetworkName.LineaGoerli,\n [ChainId['linea-sepolia']]: BuiltInNetworkName.LineaSepolia,\n [ChainId['linea-mainnet']]: BuiltInNetworkName.LineaMainnet,\n [ChainId.aurora]: BuiltInNetworkName.Aurora,\n};\n"]}
|
@@ -1,9 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createServicePolicy = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_MAX_RETRIES = exports.handleWhen = exports.handleAll = exports.
|
3
|
+
exports.createServicePolicy = exports.DEFAULT_DEGRADED_THRESHOLD = exports.DEFAULT_CIRCUIT_BREAK_DURATION = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES = exports.DEFAULT_MAX_RETRIES = exports.handleWhen = exports.handleAll = exports.ExponentialBackoff = exports.ConstantBackoff = exports.CircuitState = exports.BrokenCircuitError = void 0;
|
4
4
|
const cockatiel_1 = require("cockatiel");
|
5
5
|
Object.defineProperty(exports, "BrokenCircuitError", { enumerable: true, get: function () { return cockatiel_1.BrokenCircuitError; } });
|
6
6
|
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return cockatiel_1.CircuitState; } });
|
7
|
+
Object.defineProperty(exports, "ExponentialBackoff", { enumerable: true, get: function () { return cockatiel_1.ExponentialBackoff; } });
|
8
|
+
Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return cockatiel_1.ConstantBackoff; } });
|
7
9
|
Object.defineProperty(exports, "handleAll", { enumerable: true, get: function () { return cockatiel_1.handleAll; } });
|
8
10
|
Object.defineProperty(exports, "handleWhen", { enumerable: true, get: function () { return cockatiel_1.handleWhen; } });
|
9
11
|
/**
|
@@ -43,21 +45,8 @@ exports.DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
43
45
|
* from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see
|
44
46
|
* there for more.
|
45
47
|
*
|
46
|
-
* @param options - The options to this function.
|
47
|
-
* @
|
48
|
-
* service should be re-invoked before giving up. Defaults to 3.
|
49
|
-
* @param options.retryFilterPolicy - The policy used to control when the
|
50
|
-
* service should be retried based on either the result of the servce or an
|
51
|
-
* error that it throws. For instance, you could use this to retry only certain
|
52
|
-
* errors. See `handleWhen` and friends from Cockatiel for more.
|
53
|
-
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
54
|
-
* service is allowed to fail before pausing further retries. Defaults to 12.
|
55
|
-
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
56
|
-
* pause retries of the action after the number of failures reaches
|
57
|
-
* `maxConsecutiveFailures`.
|
58
|
-
* @param options.degradedThreshold - The length of time (in milliseconds) that
|
59
|
-
* governs when the service is regarded as degraded (affecting when `onDegraded`
|
60
|
-
* is called). Defaults to 5 seconds.
|
48
|
+
* @param options - The options to this function. See
|
49
|
+
* {@link CreateServicePolicyOptions}.
|
61
50
|
* @returns The service policy.
|
62
51
|
* @example
|
63
52
|
* This function is designed to be used in the context of a service class like
|
@@ -91,14 +80,15 @@ exports.DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
91
80
|
* }
|
92
81
|
* ```
|
93
82
|
*/
|
94
|
-
function createServicePolicy(
|
83
|
+
function createServicePolicy(options = {}) {
|
84
|
+
const { maxRetries = exports.DEFAULT_MAX_RETRIES, retryFilterPolicy = cockatiel_1.handleAll, maxConsecutiveFailures = exports.DEFAULT_MAX_CONSECUTIVE_FAILURES, circuitBreakDuration = exports.DEFAULT_CIRCUIT_BREAK_DURATION, degradedThreshold = exports.DEFAULT_DEGRADED_THRESHOLD, backoff = new cockatiel_1.ExponentialBackoff(), } = options;
|
95
85
|
const retryPolicy = (0, cockatiel_1.retry)(retryFilterPolicy, {
|
96
86
|
// Note that although the option here is called "max attempts", it's really
|
97
87
|
// maximum number of *retries* (attempts past the initial attempt).
|
98
88
|
maxAttempts: maxRetries,
|
99
89
|
// Retries of the service will be executed following ever increasing delays,
|
100
90
|
// determined by a backoff formula.
|
101
|
-
backoff
|
91
|
+
backoff,
|
102
92
|
});
|
103
93
|
const onRetry = retryPolicy.onRetry.bind(retryPolicy);
|
104
94
|
const circuitBreakerPolicy = (0, cockatiel_1.circuitBreaker)(cockatiel_1.handleAll, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAWmB;AASI,mGAnBrB,8BAAkB,OAmBqB;AAAhC,6FAlBP,wBAAY,OAkBO;AAAsB,0FAbzC,qBAAS,OAayC;AAAE,2FAZpD,sBAAU,OAYoD;AAuEhE;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACU,QAAA,gCAAgC,GAAG,CAAC,CAAC,GAAG,2BAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACU,QAAA,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACU,QAAA,0BAA0B,GAAG,IAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,SAAgB,mBAAmB,CAAC,EAClC,UAAU,GAAG,2BAAmB,EAChC,iBAAiB,GAAG,qBAAS,EAC7B,sBAAsB,GAAG,wCAAgC,EACzD,oBAAoB,GAAG,sCAA8B,EACrD,iBAAiB,GAAG,kCAA0B,MAChB,EAAE;IAChC,MAAM,WAAW,GAAG,IAAA,iBAAK,EAAC,iBAAiB,EAAE;QAC3C,2EAA2E;QAC3E,mEAAmE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CAAC;AAzDD,kDAyDC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport { CircuitState, BrokenCircuitError, handleAll, handleWhen };\n\nexport type { CockatielEvent };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function.\n * @param options.maxRetries - The maximum number of times that a failing\n * service should be re-invoked before giving up. Defaults to 3.\n * @param options.retryFilterPolicy - The policy used to control when the\n * service should be retried based on either the result of the servce or an\n * error that it throws. For instance, you could use this to retry only certain\n * errors. See `handleWhen` and friends from Cockatiel for more.\n * @param options.maxConsecutiveFailures - The maximum number of times that the\n * service is allowed to fail before pausing further retries. Defaults to 12.\n * @param options.circuitBreakDuration - The length of time (in milliseconds) to\n * pause retries of the action after the number of failures reaches\n * `maxConsecutiveFailures`.\n * @param options.degradedThreshold - The length of time (in milliseconds) that\n * governs when the service is regarded as degraded (affecting when `onDegraded`\n * is called). Defaults to 5 seconds.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy({\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n}: CreateServicePolicyOptions = {}): ServicePolicy {\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff: new ExponentialBackoff(),\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maxConsecutiveFailures),\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter = new CockatielEventEmitter<void>();\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n onDegradedEventEmitter.emit();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n onDegradedEventEmitter.emit();\n }\n });\n const onDegraded = onDegradedEventEmitter.addListener;\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n return {\n ...policy,\n circuitBreakerPolicy,\n retryPolicy,\n onBreak,\n onDegraded,\n onRetry,\n };\n}\n"]}
|
1
|
+
{"version":3,"file":"create-service-policy.cjs","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":";;;AAAA,yCAYmB;AAWjB,mGAtBA,8BAAkB,OAsBA;AAClB,6FAtBA,wBAAY,OAsBA;AAEZ,mGArBA,8BAAkB,OAqBA;AADlB,gGAnBA,2BAAe,OAmBA;AAEf,0FAnBA,qBAAS,OAmBA;AACT,2FAnBA,sBAAU,OAmBA;AA8EZ;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;GAKG;AACU,QAAA,gCAAgC,GAAG,CAAC,CAAC,GAAG,2BAAmB,CAAC,GAAG,CAAC,CAAC;AAE9E;;;GAGG;AACU,QAAA,8BAA8B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D;;;GAGG;AACU,QAAA,0BAA0B,GAAG,IAAK,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,SAAgB,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EACJ,UAAU,GAAG,2BAAmB,EAChC,iBAAiB,GAAG,qBAAS,EAC7B,sBAAsB,GAAG,wCAAgC,EACzD,oBAAoB,GAAG,sCAA8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IAAA,gBAAI,EAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IAEvD,OAAO;QACL,GAAG,MAAM;QACT,oBAAoB;QACpB,WAAW;QACX,OAAO;QACP,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC;AA9DD,kDA8DC","sourcesContent":["import {\n BrokenCircuitError,\n CircuitState,\n EventEmitter as CockatielEventEmitter,\n ConsecutiveBreaker,\n ExponentialBackoff,\n ConstantBackoff,\n circuitBreaker,\n handleAll,\n handleWhen,\n retry,\n wrap,\n} from 'cockatiel';\nimport type {\n CircuitBreakerPolicy,\n Event as CockatielEvent,\n IBackoffFactory,\n IPolicy,\n Policy,\n RetryPolicy,\n} from 'cockatiel';\n\nexport {\n BrokenCircuitError,\n CircuitState,\n ConstantBackoff,\n ExponentialBackoff,\n handleAll,\n handleWhen,\n};\n\nexport type { CockatielEvent };\n\n/**\n * The options for `createServicePolicy`.\n */\nexport type CreateServicePolicyOptions = {\n /**\n * The backoff strategy to use. Mainly useful for testing so that a constant\n * backoff can be used when mocking timers. Defaults to an instance of\n * ExponentialBackoff.\n */\n backoff?: IBackoffFactory<unknown>;\n /**\n * The length of time (in milliseconds) to pause retries of the action after\n * the number of failures reaches `maxConsecutiveFailures`.\n */\n circuitBreakDuration?: number;\n /**\n * The length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\n degradedThreshold?: number;\n /**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries.\n */\n maxConsecutiveFailures?: number;\n /**\n * The maximum number of times that a failing service should be re-invoked\n * before giving up.\n */\n maxRetries?: number;\n /**\n * The policy used to control when the service should be retried based on\n * either the result of the service or an error that it throws. For instance,\n * you could use this to retry only certain errors. See `handleWhen` and\n * friends from Cockatiel for more.\n */\n retryFilterPolicy?: Policy;\n};\n\n/**\n * The service policy object.\n */\nexport type ServicePolicy = IPolicy & {\n /**\n * The Cockatiel circuit breaker policy that the service policy uses\n * internally.\n */\n circuitBreakerPolicy: CircuitBreakerPolicy;\n /**\n * The Cockatiel retry policy that the service policy uses internally.\n */\n retryPolicy: RetryPolicy;\n /**\n * A function which is called when the number of times that the service fails\n * in a row meets the set maximum number of consecutive failures.\n */\n onBreak: CircuitBreakerPolicy['onBreak'];\n /**\n * A function which is called in two circumstances: 1) when the service\n * succeeds before the maximum number of consecutive failures is reached, but\n * takes more time than the `degradedThreshold` to run, or 2) if the service\n * never succeeds before the retry policy gives up and before the maximum\n * number of consecutive failures has been reached.\n */\n onDegraded: CockatielEvent<void>;\n /**\n * A function which will be called by the retry policy each time the service\n * fails and the policy kicks off a timer to re-run the service. This is\n * primarily useful in tests where we are mocking timers.\n */\n onRetry: RetryPolicy['onRetry'];\n};\n\n/**\n * The maximum number of times that a failing service should be re-run before\n * giving up.\n */\nexport const DEFAULT_MAX_RETRIES = 3;\n\n/**\n * The maximum number of times that the service is allowed to fail before\n * pausing further retries. This is set to a value such that if given a\n * service that continually fails, the policy needs to be executed 3 times\n * before further retries are paused.\n */\nexport const DEFAULT_MAX_CONSECUTIVE_FAILURES = (1 + DEFAULT_MAX_RETRIES) * 3;\n\n/**\n * The default length of time (in milliseconds) to temporarily pause retries of\n * the service after enough consecutive failures.\n */\nexport const DEFAULT_CIRCUIT_BREAK_DURATION = 30 * 60 * 1000;\n\n/**\n * The default length of time (in milliseconds) that governs when the service is\n * regarded as degraded (affecting when `onDegraded` is called).\n */\nexport const DEFAULT_DEGRADED_THRESHOLD = 5_000;\n\n/**\n * Constructs an object exposing an `execute` method which, given a function —\n * hereafter called the \"service\" — will retry that service with ever increasing\n * delays until it succeeds. If the policy detects too many consecutive\n * failures, it will block further retries until a designated time period has\n * passed; this particular behavior is primarily designed for services that wrap\n * API calls so as not to make needless HTTP requests when the API is down and\n * to be able to recover when the API comes back up. In addition, hooks allow\n * for responding to certain events, one of which can be used to detect when an\n * HTTP request is performing slowly.\n *\n * Internally, this function makes use of the retry and circuit breaker policies\n * from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see\n * there for more.\n *\n * @param options - The options to this function. See\n * {@link CreateServicePolicyOptions}.\n * @returns The service policy.\n * @example\n * This function is designed to be used in the context of a service class like\n * this:\n * ``` ts\n * class Service {\n * constructor() {\n * this.#policy = createServicePolicy({\n * maxRetries: 3,\n * retryFilterPolicy: handleWhen((error) => {\n * return error.message.includes('oops');\n * }),\n * maxConsecutiveFailures: 3,\n * circuitBreakDuration: 5000,\n * degradedThreshold: 2000,\n * onBreak: () => {\n * console.log('Circuit broke');\n * },\n * onDegraded: () => {\n * console.log('Service is degraded');\n * },\n * });\n * }\n *\n * async fetch() {\n * return await this.#policy.execute(async () => {\n * const response = await fetch('https://some/url');\n * return await response.json();\n * });\n * }\n * }\n * ```\n */\nexport function createServicePolicy(\n options: CreateServicePolicyOptions = {},\n): ServicePolicy {\n const {\n maxRetries = DEFAULT_MAX_RETRIES,\n retryFilterPolicy = handleAll,\n maxConsecutiveFailures = DEFAULT_MAX_CONSECUTIVE_FAILURES,\n circuitBreakDuration = DEFAULT_CIRCUIT_BREAK_DURATION,\n degradedThreshold = DEFAULT_DEGRADED_THRESHOLD,\n backoff = new ExponentialBackoff(),\n } = options;\n\n const retryPolicy = retry(retryFilterPolicy, {\n // Note that although the option here is called \"max attempts\", it's really\n // maximum number of *retries* (attempts past the initial attempt).\n maxAttempts: maxRetries,\n // Retries of the service will be executed following ever increasing delays,\n // determined by a backoff formula.\n backoff,\n });\n const onRetry = retryPolicy.onRetry.bind(retryPolicy);\n\n const circuitBreakerPolicy = circuitBreaker(handleAll, {\n // While the circuit is open, any additional invocations of the service\n // passed to the policy (either via automatic retries or by manually\n // executing the policy again) will result in a BrokenCircuitError. This\n // will remain the case until `circuitBreakDuration` passes, after which the\n // service will be allowed to run again. If the service succeeds, the\n // circuit will close, otherwise it will remain open.\n halfOpenAfter: circuitBreakDuration,\n breaker: new ConsecutiveBreaker(maxConsecutiveFailures),\n });\n const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);\n\n const onDegradedEventEmitter = new CockatielEventEmitter<void>();\n retryPolicy.onGiveUp(() => {\n if (circuitBreakerPolicy.state === CircuitState.Closed) {\n onDegradedEventEmitter.emit();\n }\n });\n retryPolicy.onSuccess(({ duration }) => {\n if (\n circuitBreakerPolicy.state === CircuitState.Closed &&\n duration > degradedThreshold\n ) {\n onDegradedEventEmitter.emit();\n }\n });\n const onDegraded = onDegradedEventEmitter.addListener;\n\n // Every time the retry policy makes an attempt, it executes the circuit\n // breaker policy, which executes the service.\n const policy = wrap(retryPolicy, circuitBreakerPolicy);\n\n return {\n ...policy,\n circuitBreakerPolicy,\n retryPolicy,\n onBreak,\n onDegraded,\n onRetry,\n };\n}\n"]}
|
@@ -1,11 +1,17 @@
|
|
1
|
-
import { BrokenCircuitError, CircuitState, handleAll, handleWhen } from "cockatiel";
|
2
|
-
import type { CircuitBreakerPolicy, Event as CockatielEvent, IPolicy, Policy, RetryPolicy } from "cockatiel";
|
3
|
-
export { CircuitState,
|
1
|
+
import { BrokenCircuitError, CircuitState, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
|
2
|
+
import type { CircuitBreakerPolicy, Event as CockatielEvent, IBackoffFactory, IPolicy, Policy, RetryPolicy } from "cockatiel";
|
3
|
+
export { BrokenCircuitError, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
|
4
4
|
export type { CockatielEvent };
|
5
5
|
/**
|
6
6
|
* The options for `createServicePolicy`.
|
7
7
|
*/
|
8
8
|
export type CreateServicePolicyOptions = {
|
9
|
+
/**
|
10
|
+
* The backoff strategy to use. Mainly useful for testing so that a constant
|
11
|
+
* backoff can be used when mocking timers. Defaults to an instance of
|
12
|
+
* ExponentialBackoff.
|
13
|
+
*/
|
14
|
+
backoff?: IBackoffFactory<unknown>;
|
9
15
|
/**
|
10
16
|
* The length of time (in milliseconds) to pause retries of the action after
|
11
17
|
* the number of failures reaches `maxConsecutiveFailures`.
|
@@ -104,21 +110,8 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
104
110
|
* from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see
|
105
111
|
* there for more.
|
106
112
|
*
|
107
|
-
* @param options - The options to this function.
|
108
|
-
* @
|
109
|
-
* service should be re-invoked before giving up. Defaults to 3.
|
110
|
-
* @param options.retryFilterPolicy - The policy used to control when the
|
111
|
-
* service should be retried based on either the result of the servce or an
|
112
|
-
* error that it throws. For instance, you could use this to retry only certain
|
113
|
-
* errors. See `handleWhen` and friends from Cockatiel for more.
|
114
|
-
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
115
|
-
* service is allowed to fail before pausing further retries. Defaults to 12.
|
116
|
-
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
117
|
-
* pause retries of the action after the number of failures reaches
|
118
|
-
* `maxConsecutiveFailures`.
|
119
|
-
* @param options.degradedThreshold - The length of time (in milliseconds) that
|
120
|
-
* governs when the service is regarded as degraded (affecting when `onDegraded`
|
121
|
-
* is called). Defaults to 5 seconds.
|
113
|
+
* @param options - The options to this function. See
|
114
|
+
* {@link CreateServicePolicyOptions}.
|
122
115
|
* @returns The service policy.
|
123
116
|
* @example
|
124
117
|
* This function is designed to be used in the context of a service class like
|
@@ -152,5 +145,5 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
152
145
|
* }
|
153
146
|
* ```
|
154
147
|
*/
|
155
|
-
export declare function createServicePolicy(
|
148
|
+
export declare function createServicePolicy(options?: CreateServicePolicyOptions): ServicePolicy;
|
156
149
|
//# sourceMappingURL=create-service-policy.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,
|
1
|
+
{"version":3,"file":"create-service-policy.d.cts","sourceRoot":"","sources":["../src/create-service-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY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,eAAO,MAAM,0BAA0B,OAAQ,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CA4Df"}
|
@@ -1,11 +1,17 @@
|
|
1
|
-
import { BrokenCircuitError, CircuitState, handleAll, handleWhen } from "cockatiel";
|
2
|
-
import type { CircuitBreakerPolicy, Event as CockatielEvent, IPolicy, Policy, RetryPolicy } from "cockatiel";
|
3
|
-
export { CircuitState,
|
1
|
+
import { BrokenCircuitError, CircuitState, ExponentialBackoff, ConstantBackoff, handleAll, handleWhen } from "cockatiel";
|
2
|
+
import type { CircuitBreakerPolicy, Event as CockatielEvent, IBackoffFactory, IPolicy, Policy, RetryPolicy } from "cockatiel";
|
3
|
+
export { BrokenCircuitError, CircuitState, ConstantBackoff, ExponentialBackoff, handleAll, handleWhen, };
|
4
4
|
export type { CockatielEvent };
|
5
5
|
/**
|
6
6
|
* The options for `createServicePolicy`.
|
7
7
|
*/
|
8
8
|
export type CreateServicePolicyOptions = {
|
9
|
+
/**
|
10
|
+
* The backoff strategy to use. Mainly useful for testing so that a constant
|
11
|
+
* backoff can be used when mocking timers. Defaults to an instance of
|
12
|
+
* ExponentialBackoff.
|
13
|
+
*/
|
14
|
+
backoff?: IBackoffFactory<unknown>;
|
9
15
|
/**
|
10
16
|
* The length of time (in milliseconds) to pause retries of the action after
|
11
17
|
* the number of failures reaches `maxConsecutiveFailures`.
|
@@ -104,21 +110,8 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
104
110
|
* from the [Cockatiel](https://www.npmjs.com/package/cockatiel) library; see
|
105
111
|
* there for more.
|
106
112
|
*
|
107
|
-
* @param options - The options to this function.
|
108
|
-
* @
|
109
|
-
* service should be re-invoked before giving up. Defaults to 3.
|
110
|
-
* @param options.retryFilterPolicy - The policy used to control when the
|
111
|
-
* service should be retried based on either the result of the servce or an
|
112
|
-
* error that it throws. For instance, you could use this to retry only certain
|
113
|
-
* errors. See `handleWhen` and friends from Cockatiel for more.
|
114
|
-
* @param options.maxConsecutiveFailures - The maximum number of times that the
|
115
|
-
* service is allowed to fail before pausing further retries. Defaults to 12.
|
116
|
-
* @param options.circuitBreakDuration - The length of time (in milliseconds) to
|
117
|
-
* pause retries of the action after the number of failures reaches
|
118
|
-
* `maxConsecutiveFailures`.
|
119
|
-
* @param options.degradedThreshold - The length of time (in milliseconds) that
|
120
|
-
* governs when the service is regarded as degraded (affecting when `onDegraded`
|
121
|
-
* is called). Defaults to 5 seconds.
|
113
|
+
* @param options - The options to this function. See
|
114
|
+
* {@link CreateServicePolicyOptions}.
|
122
115
|
* @returns The service policy.
|
123
116
|
* @example
|
124
117
|
* This function is designed to be used in the context of a service class like
|
@@ -152,5 +145,5 @@ export declare const DEFAULT_DEGRADED_THRESHOLD = 5000;
|
|
152
145
|
* }
|
153
146
|
* ```
|
154
147
|
*/
|
155
|
-
export declare function createServicePolicy(
|
148
|
+
export declare function createServicePolicy(options?: CreateServicePolicyOptions): ServicePolicy;
|
156
149
|
//# sourceMappingURL=create-service-policy.d.mts.map
|