@alchemy/common 0.0.0-alpha.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/LICENSE +21 -0
- package/dist/esm/actions/addBreadCrumb.d.ts +14 -0
- package/dist/esm/actions/addBreadCrumb.js +27 -0
- package/dist/esm/actions/addBreadCrumb.js.map +1 -0
- package/dist/esm/chains.d.ts +234 -0
- package/dist/esm/chains.js +113 -0
- package/dist/esm/chains.js.map +1 -0
- package/dist/esm/errors/AccountNotFoundError.d.ts +10 -0
- package/dist/esm/errors/AccountNotFoundError.js +19 -0
- package/dist/esm/errors/AccountNotFoundError.js.map +1 -0
- package/dist/esm/errors/BaseError.d.ts +23 -0
- package/dist/esm/errors/BaseError.js +40 -0
- package/dist/esm/errors/BaseError.js.map +1 -0
- package/dist/esm/errors/ChainNotFoundError.d.ts +11 -0
- package/dist/esm/errors/ChainNotFoundError.js +19 -0
- package/dist/esm/errors/ChainNotFoundError.js.map +1 -0
- package/dist/esm/errors/ConnectionConfigError.d.ts +13 -0
- package/dist/esm/errors/ConnectionConfigError.js +25 -0
- package/dist/esm/errors/ConnectionConfigError.js.map +1 -0
- package/dist/esm/errors/FetchError.d.ts +15 -0
- package/dist/esm/errors/FetchError.js +25 -0
- package/dist/esm/errors/FetchError.js.map +1 -0
- package/dist/esm/errors/InvalidRequestError.d.ts +13 -0
- package/dist/esm/errors/InvalidRequestError.js +22 -0
- package/dist/esm/errors/InvalidRequestError.js.map +1 -0
- package/dist/esm/errors/MethodUnsupportedError.d.ts +13 -0
- package/dist/esm/errors/MethodUnsupportedError.js +21 -0
- package/dist/esm/errors/MethodUnsupportedError.js.map +1 -0
- package/dist/esm/errors/ServerError.d.ts +15 -0
- package/dist/esm/errors/ServerError.js +25 -0
- package/dist/esm/errors/ServerError.js.map +1 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.js +27 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logging/config.d.ts +190 -0
- package/dist/esm/logging/config.js +279 -0
- package/dist/esm/logging/config.js.map +1 -0
- package/dist/esm/logging/index.d.ts +6 -0
- package/dist/esm/logging/index.js +5 -0
- package/dist/esm/logging/index.js.map +1 -0
- package/dist/esm/logging/local.d.ts +10 -0
- package/dist/esm/logging/local.js +35 -0
- package/dist/esm/logging/local.js.map +1 -0
- package/dist/esm/logging/logger.d.ts +80 -0
- package/dist/esm/logging/logger.js +111 -0
- package/dist/esm/logging/logger.js.map +1 -0
- package/dist/esm/logging/noop.d.ts +6 -0
- package/dist/esm/logging/noop.js +12 -0
- package/dist/esm/logging/noop.js.map +1 -0
- package/dist/esm/logging/sinks.d.ts +90 -0
- package/dist/esm/logging/sinks.js +111 -0
- package/dist/esm/logging/sinks.js.map +1 -0
- package/dist/esm/logging/types.d.ts +96 -0
- package/dist/esm/logging/types.js +2 -0
- package/dist/esm/logging/types.js.map +1 -0
- package/dist/esm/logging/utils.d.ts +7 -0
- package/dist/esm/logging/utils.js +21 -0
- package/dist/esm/logging/utils.js.map +1 -0
- package/dist/esm/rest/restClient.d.ts +34 -0
- package/dist/esm/rest/restClient.js +55 -0
- package/dist/esm/rest/restClient.js.map +1 -0
- package/dist/esm/rest/types.d.ts +24 -0
- package/dist/esm/rest/types.js +2 -0
- package/dist/esm/rest/types.js.map +1 -0
- package/dist/esm/tracing/traceHeader.d.ts +82 -0
- package/dist/esm/tracing/traceHeader.js +145 -0
- package/dist/esm/tracing/traceHeader.js.map +1 -0
- package/dist/esm/tracing/updateHeaders.d.ts +24 -0
- package/dist/esm/tracing/updateHeaders.js +61 -0
- package/dist/esm/tracing/updateHeaders.js.map +1 -0
- package/dist/esm/transport/alchemy.d.ts +110 -0
- package/dist/esm/transport/alchemy.js +164 -0
- package/dist/esm/transport/alchemy.js.map +1 -0
- package/dist/esm/transport/chainRegistry.d.ts +31 -0
- package/dist/esm/transport/chainRegistry.js +95 -0
- package/dist/esm/transport/chainRegistry.js.map +1 -0
- package/dist/esm/transport/connection.d.ts +20 -0
- package/dist/esm/transport/connection.js +2 -0
- package/dist/esm/transport/connection.js.map +1 -0
- package/dist/esm/transport/connectionSchema.d.ts +124 -0
- package/dist/esm/transport/connectionSchema.js +121 -0
- package/dist/esm/transport/connectionSchema.js.map +1 -0
- package/dist/esm/utils/assertNever.d.ts +8 -0
- package/dist/esm/utils/assertNever.js +12 -0
- package/dist/esm/utils/assertNever.js.map +1 -0
- package/dist/esm/utils/bigint.d.ts +24 -0
- package/dist/esm/utils/bigint.js +37 -0
- package/dist/esm/utils/bigint.js.map +1 -0
- package/dist/esm/utils/createEip1193HandlerFactory.d.ts +18 -0
- package/dist/esm/utils/createEip1193HandlerFactory.js +11 -0
- package/dist/esm/utils/createEip1193HandlerFactory.js.map +1 -0
- package/dist/esm/utils/headers.d.ts +7 -0
- package/dist/esm/utils/headers.js +29 -0
- package/dist/esm/utils/headers.js.map +1 -0
- package/dist/esm/utils/lowerAddress.d.ts +8 -0
- package/dist/esm/utils/lowerAddress.js +9 -0
- package/dist/esm/utils/lowerAddress.js.map +1 -0
- package/dist/esm/utils/raise.d.ts +8 -0
- package/dist/esm/utils/raise.js +14 -0
- package/dist/esm/utils/raise.js.map +1 -0
- package/dist/esm/utils/types.d.ts +10 -0
- package/dist/esm/utils/types.js +2 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +4 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/actions/addBreadCrumb.d.ts +15 -0
- package/dist/types/actions/addBreadCrumb.d.ts.map +1 -0
- package/dist/types/chains.d.ts +235 -0
- package/dist/types/chains.d.ts.map +1 -0
- package/dist/types/errors/AccountNotFoundError.d.ts +11 -0
- package/dist/types/errors/AccountNotFoundError.d.ts.map +1 -0
- package/dist/types/errors/BaseError.d.ts +24 -0
- package/dist/types/errors/BaseError.d.ts.map +1 -0
- package/dist/types/errors/ChainNotFoundError.d.ts +12 -0
- package/dist/types/errors/ChainNotFoundError.d.ts.map +1 -0
- package/dist/types/errors/ConnectionConfigError.d.ts +14 -0
- package/dist/types/errors/ConnectionConfigError.d.ts.map +1 -0
- package/dist/types/errors/FetchError.d.ts +16 -0
- package/dist/types/errors/FetchError.d.ts.map +1 -0
- package/dist/types/errors/InvalidRequestError.d.ts +14 -0
- package/dist/types/errors/InvalidRequestError.d.ts.map +1 -0
- package/dist/types/errors/MethodUnsupportedError.d.ts +14 -0
- package/dist/types/errors/MethodUnsupportedError.d.ts.map +1 -0
- package/dist/types/errors/ServerError.d.ts +16 -0
- package/dist/types/errors/ServerError.d.ts.map +1 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logging/config.d.ts +191 -0
- package/dist/types/logging/config.d.ts.map +1 -0
- package/dist/types/logging/index.d.ts +7 -0
- package/dist/types/logging/index.d.ts.map +1 -0
- package/dist/types/logging/local.d.ts +11 -0
- package/dist/types/logging/local.d.ts.map +1 -0
- package/dist/types/logging/logger.d.ts +81 -0
- package/dist/types/logging/logger.d.ts.map +1 -0
- package/dist/types/logging/noop.d.ts +7 -0
- package/dist/types/logging/noop.d.ts.map +1 -0
- package/dist/types/logging/sinks.d.ts +91 -0
- package/dist/types/logging/sinks.d.ts.map +1 -0
- package/dist/types/logging/types.d.ts +97 -0
- package/dist/types/logging/types.d.ts.map +1 -0
- package/dist/types/logging/utils.d.ts +8 -0
- package/dist/types/logging/utils.d.ts.map +1 -0
- package/dist/types/rest/restClient.d.ts +35 -0
- package/dist/types/rest/restClient.d.ts.map +1 -0
- package/dist/types/rest/types.d.ts +25 -0
- package/dist/types/rest/types.d.ts.map +1 -0
- package/dist/types/tracing/traceHeader.d.ts +83 -0
- package/dist/types/tracing/traceHeader.d.ts.map +1 -0
- package/dist/types/tracing/updateHeaders.d.ts +25 -0
- package/dist/types/tracing/updateHeaders.d.ts.map +1 -0
- package/dist/types/transport/alchemy.d.ts +111 -0
- package/dist/types/transport/alchemy.d.ts.map +1 -0
- package/dist/types/transport/chainRegistry.d.ts +32 -0
- package/dist/types/transport/chainRegistry.d.ts.map +1 -0
- package/dist/types/transport/connection.d.ts +21 -0
- package/dist/types/transport/connection.d.ts.map +1 -0
- package/dist/types/transport/connectionSchema.d.ts +125 -0
- package/dist/types/transport/connectionSchema.d.ts.map +1 -0
- package/dist/types/utils/assertNever.d.ts +9 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/bigint.d.ts +25 -0
- package/dist/types/utils/bigint.d.ts.map +1 -0
- package/dist/types/utils/createEip1193HandlerFactory.d.ts +19 -0
- package/dist/types/utils/createEip1193HandlerFactory.d.ts.map +1 -0
- package/dist/types/utils/headers.d.ts +8 -0
- package/dist/types/utils/headers.d.ts.map +1 -0
- package/dist/types/utils/lowerAddress.d.ts +9 -0
- package/dist/types/utils/lowerAddress.d.ts.map +1 -0
- package/dist/types/utils/raise.d.ts +9 -0
- package/dist/types/utils/raise.d.ts.map +1 -0
- package/dist/types/utils/types.d.ts +11 -0
- package/dist/types/utils/types.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/actions/addBreadCrumb.ts +38 -0
- package/src/chains.ts +118 -0
- package/src/errors/AccountNotFoundError.ts +16 -0
- package/src/errors/BaseError.ts +51 -0
- package/src/errors/ChainNotFoundError.ts +15 -0
- package/src/errors/ConnectionConfigError.ts +22 -0
- package/src/errors/FetchError.ts +21 -0
- package/src/errors/InvalidRequestError.ts +19 -0
- package/src/errors/MethodUnsupportedError.ts +17 -0
- package/src/errors/ServerError.ts +21 -0
- package/src/index.ts +60 -0
- package/src/logging/config.ts +365 -0
- package/src/logging/index.ts +20 -0
- package/src/logging/local.ts +39 -0
- package/src/logging/logger.ts +194 -0
- package/src/logging/noop.ts +13 -0
- package/src/logging/sinks.ts +115 -0
- package/src/logging/types.ts +111 -0
- package/src/logging/utils.ts +31 -0
- package/src/rest/restClient.ts +64 -0
- package/src/rest/types.ts +42 -0
- package/src/tracing/traceHeader.ts +154 -0
- package/src/tracing/updateHeaders.ts +66 -0
- package/src/transport/alchemy.ts +242 -0
- package/src/transport/chainRegistry.ts +115 -0
- package/src/transport/connection.ts +19 -0
- package/src/transport/connectionSchema.ts +145 -0
- package/src/utils/assertNever.ts +12 -0
- package/src/utils/bigint.ts +58 -0
- package/src/utils/createEip1193HandlerFactory.ts +25 -0
- package/src/utils/headers.ts +48 -0
- package/src/utils/lowerAddress.ts +10 -0
- package/src/utils/raise.ts +14 -0
- package/src/utils/types.ts +14 -0
- package/src/version.ts +3 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createClient, type Client } from "viem";
|
|
2
|
+
import { headersUpdate } from "../tracing/updateHeaders.js";
|
|
3
|
+
import {
|
|
4
|
+
alchemyTransport,
|
|
5
|
+
type AlchemyTransport,
|
|
6
|
+
} from "../transport/alchemy.js";
|
|
7
|
+
import { convertHeadersToObject } from "../utils/headers.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* TODO: need to figure out if there's a better way than this...
|
|
11
|
+
* This adds a tracing breadcrumb to the client during requests.
|
|
12
|
+
* It returns a basic client without the previously extended actions.
|
|
13
|
+
* That means you MUST use viem's `getAction` method within actions in case the action is being called from an action that attached a breadcrumb.
|
|
14
|
+
* That method works by taking a fallback, looking up the action on the client, if it finds it calls it, otherwise it calls the fallback.
|
|
15
|
+
*
|
|
16
|
+
* @param {Client<AlchemyTransport>} client a client using the alchemy transport
|
|
17
|
+
* @param {string} breadcrumb the breadcrumb to add to the tracing headers
|
|
18
|
+
* @returns {Client<AlchemyTransport>} a client with the transport updated to include the breadcrumb
|
|
19
|
+
*/
|
|
20
|
+
export function addBreadCrumb(
|
|
21
|
+
client: Client<AlchemyTransport>,
|
|
22
|
+
breadcrumb: string,
|
|
23
|
+
): Client<AlchemyTransport> {
|
|
24
|
+
const oldConfig = client.transport.config;
|
|
25
|
+
const dynamicFetchOptions = client.transport.fetchOptions;
|
|
26
|
+
const newTransport = alchemyTransport({ ...oldConfig });
|
|
27
|
+
newTransport.updateHeaders(
|
|
28
|
+
headersUpdate(breadcrumb)(
|
|
29
|
+
convertHeadersToObject(dynamicFetchOptions?.headers),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return createClient({
|
|
34
|
+
...client,
|
|
35
|
+
transport: newTransport,
|
|
36
|
+
chain: client.chain,
|
|
37
|
+
});
|
|
38
|
+
}
|
package/src/chains.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom chain definitions for Alchemy SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides chain definitions for networks not yet available in viem.
|
|
5
|
+
* For standard networks (Ethereum, Arbitrum, Base, etc.), import directly from "viem/chains".
|
|
6
|
+
* All chains work automatically with alchemyTransport via the internal registry lookup.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Standard chains - import from viem
|
|
11
|
+
* import { sepolia, arbitrum, base } from "viem/chains";
|
|
12
|
+
*
|
|
13
|
+
* // Custom chains - import from here
|
|
14
|
+
* import { worldChain, unichainMainnet } from "@alchemy/common/chains";
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
import { defineChain } from "viem";
|
|
18
|
+
|
|
19
|
+
export const fraxtalSepolia = defineChain({
|
|
20
|
+
id: 2523,
|
|
21
|
+
name: "Fraxtal Sepolia",
|
|
22
|
+
nativeCurrency: { name: "Frax Ether", symbol: "frxETH", decimals: 18 },
|
|
23
|
+
rpcUrls: {
|
|
24
|
+
default: {
|
|
25
|
+
http: ["https://rpc.testnet-sepolia.frax.com"],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
testnet: true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const openlootSepolia = defineChain({
|
|
32
|
+
id: 905905,
|
|
33
|
+
name: "Openloot Sepolia",
|
|
34
|
+
nativeCurrency: { name: "Openloot", symbol: "OL", decimals: 18 },
|
|
35
|
+
rpcUrls: {
|
|
36
|
+
default: {
|
|
37
|
+
http: ["https://openloot-sepolia.g.alchemy.com/v2"],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
blockExplorers: {
|
|
41
|
+
default: {
|
|
42
|
+
name: "Block Explorer",
|
|
43
|
+
url: "https://openloot-sepolia.explorer.alchemy.com",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
testnet: true,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const gensynTestnet = defineChain({
|
|
50
|
+
id: 685685,
|
|
51
|
+
name: "Gensyn Testnet",
|
|
52
|
+
nativeCurrency: { name: "eth", symbol: "eth", decimals: 18 },
|
|
53
|
+
rpcUrls: {
|
|
54
|
+
default: {
|
|
55
|
+
http: ["https://gensyn-testnet.g.alchemy.com/v2"],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
blockExplorers: {
|
|
59
|
+
default: {
|
|
60
|
+
name: "Block Explorer",
|
|
61
|
+
url: "https://gensyn-testnet.explorer.alchemy.com",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
testnet: true,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const riseTestnet = defineChain({
|
|
68
|
+
id: 11155931,
|
|
69
|
+
name: "Rise Testnet",
|
|
70
|
+
nativeCurrency: { name: "eth", symbol: "eth", decimals: 18 },
|
|
71
|
+
rpcUrls: {
|
|
72
|
+
default: {
|
|
73
|
+
http: ["https://rise-testnet.g.alchemy.com/v2"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
blockExplorers: {
|
|
77
|
+
default: {
|
|
78
|
+
name: "Block Explorer",
|
|
79
|
+
url: "https://explorer.testnet.riselabs.xyz",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
testnet: true,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const storyMainnet = defineChain({
|
|
86
|
+
id: 1514,
|
|
87
|
+
name: "Story Mainnet",
|
|
88
|
+
nativeCurrency: { name: "IP", symbol: "IP", decimals: 18 },
|
|
89
|
+
rpcUrls: {
|
|
90
|
+
default: {
|
|
91
|
+
http: ["https://story-mainnet.g.alchemy.com/v2"],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
blockExplorers: {
|
|
95
|
+
default: {
|
|
96
|
+
name: "Block Explorer",
|
|
97
|
+
url: "https://www.storyscan.io",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export const teaSepolia = defineChain({
|
|
103
|
+
id: 10218,
|
|
104
|
+
name: "Tea Sepolia",
|
|
105
|
+
nativeCurrency: { name: "TEA", symbol: "TEA", decimals: 18 },
|
|
106
|
+
rpcUrls: {
|
|
107
|
+
default: {
|
|
108
|
+
http: ["https://tea-sepolia.g.alchemy.com/v2"],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
blockExplorers: {
|
|
112
|
+
default: {
|
|
113
|
+
name: "Block Explorer",
|
|
114
|
+
url: "https://sepolia.tea.xyz/",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
testnet: true,
|
|
118
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This error is thrown when an account could not be found to execute a specific action. It extends the `BaseError` class.
|
|
5
|
+
*/
|
|
6
|
+
export class AccountNotFoundError extends BaseError {
|
|
7
|
+
override name = "AccountNotFoundError";
|
|
8
|
+
|
|
9
|
+
// TODO: extend this further using docs path as well
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for initializing an error message indicating that an account could not be found to execute the specified action.
|
|
13
|
+
*/ constructor() {
|
|
14
|
+
super("Could not find an Account to execute with this Action.");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseError as ViemBaseError } from "viem";
|
|
2
|
+
import { VERSION } from "../version.js";
|
|
3
|
+
|
|
4
|
+
type BaseErrorParameters = {
|
|
5
|
+
docsPath?: string;
|
|
6
|
+
docsSlug?: string;
|
|
7
|
+
metaMessages?: string[];
|
|
8
|
+
} & (
|
|
9
|
+
| {
|
|
10
|
+
cause?: never;
|
|
11
|
+
details?: string;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
cause: BaseError | Error;
|
|
15
|
+
details?: never;
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A custom error class that extends from `ViemBaseError`. This class allows for error messages to include links to relevant documentation based on provided `docsPath` and `docsSlug` parameters.
|
|
21
|
+
* This is based on on viem's BaseError type (obviously from the import and extend)
|
|
22
|
+
* we want the errors here to point to our docs if we supply a docsPath though
|
|
23
|
+
*/
|
|
24
|
+
export class BaseError extends ViemBaseError {
|
|
25
|
+
override name = "AlchemySDKError";
|
|
26
|
+
override version = VERSION;
|
|
27
|
+
|
|
28
|
+
constructor(shortMessage: string, args: BaseErrorParameters = {}) {
|
|
29
|
+
super(shortMessage, args);
|
|
30
|
+
|
|
31
|
+
const docsPath =
|
|
32
|
+
args.cause instanceof BaseError
|
|
33
|
+
? args.cause.docsPath || args.docsPath
|
|
34
|
+
: args.docsPath;
|
|
35
|
+
|
|
36
|
+
this.message = [
|
|
37
|
+
shortMessage || "An error occurred.",
|
|
38
|
+
"",
|
|
39
|
+
...(args.metaMessages ? [...args.metaMessages, ""] : []),
|
|
40
|
+
...(docsPath
|
|
41
|
+
? [
|
|
42
|
+
`Docs: https://www.alchemy.com/docs/wallets${docsPath}${
|
|
43
|
+
args.docsSlug ? `#${args.docsSlug}` : ""
|
|
44
|
+
}`,
|
|
45
|
+
]
|
|
46
|
+
: []),
|
|
47
|
+
...(this.details ? [`Details: ${this.details}`] : []),
|
|
48
|
+
`Version: ${this.version}`,
|
|
49
|
+
].join("\n");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error class representing a "Chain Not Found" error, typically thrown when no chain is supplied to the client.
|
|
5
|
+
*/
|
|
6
|
+
export class ChainNotFoundError extends BaseError {
|
|
7
|
+
override name = "ChainNotFoundError";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initializes a new instance of the error message with a default message indicating that no chain was supplied to the client.
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
super("No chain supplied to the client");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error class for connection configuration validation failures.
|
|
5
|
+
*/
|
|
6
|
+
export class ConnectionConfigError extends BaseError {
|
|
7
|
+
override name = "ConnectionConfigError";
|
|
8
|
+
|
|
9
|
+
// TODO: extend this further using docs path as well for debugging connection-related problems
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new ConnectionConfigError with details about the validation failure.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} [details] Optional details about the specific validation failure
|
|
15
|
+
*/
|
|
16
|
+
constructor(details?: string) {
|
|
17
|
+
const message = details
|
|
18
|
+
? `Invalid Alchemy connection configuration: ${details}`
|
|
19
|
+
: "Invalid Alchemy connection configuration";
|
|
20
|
+
super(message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error class representing a "Fetch Error" error, typically thrown when a fetch request fails.
|
|
5
|
+
*/
|
|
6
|
+
export class FetchError extends BaseError {
|
|
7
|
+
override name = "FetchError";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initializes a new instance of the error message with a default message indicating that no chain was supplied to the client.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} route - The route that failed to fetch.
|
|
13
|
+
* @param {string} method - The HTTP method that was used.
|
|
14
|
+
* @param {Error} cause - The cause of the error.
|
|
15
|
+
*/
|
|
16
|
+
constructor(route: string, method: string, cause?: Error) {
|
|
17
|
+
super(`[${method}] ${route} failed to fetch`, {
|
|
18
|
+
cause,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This error is thrown when an invalid request is made. It extends the `BaseError` class.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidRequestError extends BaseError {
|
|
7
|
+
override name = "InvalidRequestError";
|
|
8
|
+
|
|
9
|
+
// TODO: extend this further using docs path as well
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for initializing an InvalidRequestError.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} message - Optional error message. Defaults to "Invalid request" if not provided.
|
|
15
|
+
*/
|
|
16
|
+
constructor(message?: string) {
|
|
17
|
+
super(message || "Invalid request");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This error is thrown when an unknown method is called. It extends the `BaseError` class.
|
|
5
|
+
*/
|
|
6
|
+
export class MethodUnsupportedError extends BaseError {
|
|
7
|
+
override name = "MethodUnsupportedError";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor for initializing an error message indicating the method name that is unsupported.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} method - The name of the unsupported method
|
|
13
|
+
*/
|
|
14
|
+
constructor(method: string) {
|
|
15
|
+
super(`Unsupported method: ${method}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from "./BaseError.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error class representing a "Server Error" error, typically thrown when a server request fails.
|
|
5
|
+
*/
|
|
6
|
+
export class ServerError extends BaseError {
|
|
7
|
+
override name = "ServerError";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initializes a new instance of the error message with a default message indicating that no chain was supplied to the client.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} message - The error message.
|
|
13
|
+
* @param {number} status - The HTTP status code of the error.
|
|
14
|
+
* @param {Error} cause - The cause of the error.
|
|
15
|
+
*/
|
|
16
|
+
constructor(message: string, status: number, cause?: Error) {
|
|
17
|
+
super(`HTTP request failed with status ${status}: ${message}`, {
|
|
18
|
+
cause,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// http
|
|
2
|
+
export type * from "./rest/restClient.js";
|
|
3
|
+
export type * from "./rest/types.js";
|
|
4
|
+
export { AlchemyRestClient } from "./rest/restClient.js";
|
|
5
|
+
|
|
6
|
+
// transport
|
|
7
|
+
export type * from "./transport/alchemy.js";
|
|
8
|
+
export { alchemyTransport, isAlchemyTransport } from "./transport/alchemy.js";
|
|
9
|
+
|
|
10
|
+
// chain registry utilities
|
|
11
|
+
export {
|
|
12
|
+
getAlchemyRpcUrl,
|
|
13
|
+
isChainSupported,
|
|
14
|
+
getSupportedChainIds,
|
|
15
|
+
} from "./transport/chainRegistry.js";
|
|
16
|
+
|
|
17
|
+
// utils
|
|
18
|
+
export type * from "./utils/types.js";
|
|
19
|
+
export { assertNever } from "./utils/assertNever.js";
|
|
20
|
+
export { raise } from "./utils/raise.js";
|
|
21
|
+
export { bigIntMultiply } from "./utils/bigint.js";
|
|
22
|
+
export { lowerAddress } from "./utils/lowerAddress.js";
|
|
23
|
+
export { createEip1193HandlerFactory } from "./utils/createEip1193HandlerFactory.js";
|
|
24
|
+
|
|
25
|
+
// config
|
|
26
|
+
export type { AlchemyConnectionConfig } from "./transport/connectionSchema.js";
|
|
27
|
+
export {
|
|
28
|
+
AlchemyConnectionConfigSchema,
|
|
29
|
+
validateAlchemyConnectionConfig,
|
|
30
|
+
isAlchemyConnectionConfig,
|
|
31
|
+
} from "./transport/connectionSchema.js";
|
|
32
|
+
|
|
33
|
+
// errors
|
|
34
|
+
export { BaseError } from "./errors/BaseError.js";
|
|
35
|
+
export { ChainNotFoundError } from "./errors/ChainNotFoundError.js";
|
|
36
|
+
export { AccountNotFoundError } from "./errors/AccountNotFoundError.js";
|
|
37
|
+
export { ConnectionConfigError } from "./errors/ConnectionConfigError.js";
|
|
38
|
+
export { FetchError } from "./errors/FetchError.js";
|
|
39
|
+
export { ServerError } from "./errors/ServerError.js";
|
|
40
|
+
export { InvalidRequestError } from "./errors/InvalidRequestError.js";
|
|
41
|
+
export { MethodUnsupportedError } from "./errors/MethodUnsupportedError.js";
|
|
42
|
+
|
|
43
|
+
// actions
|
|
44
|
+
export type * from "./actions/addBreadCrumb.js";
|
|
45
|
+
export { addBreadCrumb } from "./actions/addBreadCrumb.js";
|
|
46
|
+
|
|
47
|
+
// chains (convenience exports for Alchemy-supported chains)
|
|
48
|
+
export * from "./chains.js";
|
|
49
|
+
|
|
50
|
+
// diagnostics logging
|
|
51
|
+
export { createLogger } from "./logging/logger.js";
|
|
52
|
+
export {
|
|
53
|
+
setGlobalLoggerConfig,
|
|
54
|
+
getGlobalLoggerConfig,
|
|
55
|
+
LogLevel,
|
|
56
|
+
isLevelEnabled,
|
|
57
|
+
isNamespaceEnabled,
|
|
58
|
+
} from "./logging/config.js";
|
|
59
|
+
export type { DiagnosticsLogger } from "./logging/logger.js";
|
|
60
|
+
export { InMemorySink } from "./logging/sinks.js";
|