@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,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level constants for controlling diagnostics output.
|
|
3
|
+
* Lower numeric values indicate higher priority (more restrictive filtering).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { LogLevel, setGlobalLoggerConfig } from "@alchemy/common";
|
|
8
|
+
*
|
|
9
|
+
* setGlobalLoggerConfig({ level: LogLevel.DEBUG });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const LogLevel: {
|
|
13
|
+
/** Critical errors only */
|
|
14
|
+
readonly ERROR: 0;
|
|
15
|
+
/** Warnings and errors */
|
|
16
|
+
readonly WARN: 1;
|
|
17
|
+
/** Informational messages, warnings, and errors */
|
|
18
|
+
readonly INFO: 2;
|
|
19
|
+
/** Debug messages and all above */
|
|
20
|
+
readonly DEBUG: 3;
|
|
21
|
+
/** All messages including verbose details */
|
|
22
|
+
readonly VERBOSE: 4;
|
|
23
|
+
};
|
|
24
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for redacting sensitive data in log output.
|
|
27
|
+
*/
|
|
28
|
+
export type RedactConfig = {
|
|
29
|
+
/** Predicate function to test if a key should be redacted. Returns true if the key should be redacted. */
|
|
30
|
+
keys?: (key: string) => boolean;
|
|
31
|
+
/** Function to replace redacted values. Defaults to returning "[REDACTED]". */
|
|
32
|
+
replacer?: (value: unknown, key?: string) => unknown;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for the diagnostics logging system.
|
|
36
|
+
* All properties are optional and will use sensible defaults if not provided.
|
|
37
|
+
*/
|
|
38
|
+
export type DiagnosticsConfig = {
|
|
39
|
+
/** Minimum log level to emit. Defaults to INFO in development, ERROR in production. */
|
|
40
|
+
level?: LogLevel;
|
|
41
|
+
/** Configuration for redacting sensitive data in logs. */
|
|
42
|
+
redact?: RedactConfig;
|
|
43
|
+
/** Array of sink functions to receive log entries. Defaults to console sink. */
|
|
44
|
+
sinks?: Array<(entry: LogEntry) => void>;
|
|
45
|
+
/** Disable telemetry headers in requests. Defaults to false. */
|
|
46
|
+
disableTelemetryHeaders?: boolean;
|
|
47
|
+
/** Array of exact namespace strings to allow. If undefined or empty, all namespaces are enabled. Example: ["aa-infra", "wallet-apis"] */
|
|
48
|
+
enabledNamespaces?: string[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Base context attached to all log entries from a logger instance.
|
|
52
|
+
*/
|
|
53
|
+
export type LoggerContextBase = {
|
|
54
|
+
/** Package name (e.g., "@alchemy/aa-infra") */
|
|
55
|
+
package: string;
|
|
56
|
+
/** Package version (e.g., "1.0.0") */
|
|
57
|
+
version: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A single log entry emitted by the diagnostics logger.
|
|
61
|
+
*/
|
|
62
|
+
export type LogEntry = {
|
|
63
|
+
/** Timestamp in milliseconds since epoch (Date.now()) */
|
|
64
|
+
ts: number;
|
|
65
|
+
/** Log level of this entry */
|
|
66
|
+
level: LogLevel;
|
|
67
|
+
/** Optional namespace for filtering/grouping (e.g., "aa-infra", "wallet-apis") */
|
|
68
|
+
namespace: string | undefined;
|
|
69
|
+
/** The log message */
|
|
70
|
+
message: string;
|
|
71
|
+
/** Optional structured data attached to this log entry */
|
|
72
|
+
data?: Record<string, unknown>;
|
|
73
|
+
/** Package context (name and version) */
|
|
74
|
+
context: LoggerContextBase;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Gets the current global logger configuration.
|
|
78
|
+
* If not yet initialized, returns default configuration based on environment.
|
|
79
|
+
*
|
|
80
|
+
* @returns {Required<DiagnosticsConfig>} The current global configuration with all fields populated
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { getGlobalLoggerConfig } from "@alchemy/common";
|
|
84
|
+
*
|
|
85
|
+
* const config = getGlobalLoggerConfig();
|
|
86
|
+
* console.log("Current log level:", config.level);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function getGlobalLoggerConfig(): Required<DiagnosticsConfig>;
|
|
90
|
+
/**
|
|
91
|
+
* Sets the global logger configuration.
|
|
92
|
+
* Partial configuration is supported - unspecified fields retain their current values.
|
|
93
|
+
*
|
|
94
|
+
* Configuration precedence (highest to lowest):
|
|
95
|
+
* 1. Explicit setGlobalLoggerConfig calls
|
|
96
|
+
* 2. ALCHEMY_LOG_LEVEL environment variable
|
|
97
|
+
* 3. Defaults (INFO in dev, ERROR in prod)
|
|
98
|
+
*
|
|
99
|
+
* @param {DiagnosticsConfig} cfg - Partial configuration to apply
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { setGlobalLoggerConfig, LogLevel } from "@alchemy/common";
|
|
103
|
+
*
|
|
104
|
+
* // Set log level only
|
|
105
|
+
* setGlobalLoggerConfig({ level: LogLevel.DEBUG });
|
|
106
|
+
*
|
|
107
|
+
* // Add custom sink
|
|
108
|
+
* setGlobalLoggerConfig({
|
|
109
|
+
* sinks: [(entry) => console.log(JSON.stringify(entry))]
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* // Filter to specific namespaces
|
|
113
|
+
* setGlobalLoggerConfig({
|
|
114
|
+
* enabledNamespaces: ["aa-infra", "wallet-apis"]
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function setGlobalLoggerConfig(cfg: DiagnosticsConfig): void;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a given log level is enabled based on current global configuration.
|
|
121
|
+
* Used internally by logger to short-circuit disabled log statements.
|
|
122
|
+
*
|
|
123
|
+
* @param {LogLevel} level - The log level to check
|
|
124
|
+
* @returns {boolean} True if the level is enabled (will be logged), false otherwise
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { isLevelEnabled, LogLevel } from "@alchemy/common";
|
|
128
|
+
*
|
|
129
|
+
* if (isLevelEnabled(LogLevel.DEBUG)) {
|
|
130
|
+
* // Perform expensive debug computation
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function isLevelEnabled(level: LogLevel): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if a given namespace is enabled based on current global configuration.
|
|
137
|
+
* Used internally by logger to short-circuit logs from disabled namespaces.
|
|
138
|
+
*
|
|
139
|
+
* @param {string | undefined} namespace - The namespace to check
|
|
140
|
+
* @returns {boolean} True if the namespace is enabled (will be logged), false otherwise
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { isNamespaceEnabled } from "@alchemy/common";
|
|
144
|
+
*
|
|
145
|
+
* if (isNamespaceEnabled("aa-infra")) {
|
|
146
|
+
* // This namespace is enabled
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function isNamespaceEnabled(namespace: string | undefined): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Redacts sensitive keys in an object based on global redaction configuration.
|
|
153
|
+
* Performs deep redaction by recursively processing nested objects and arrays.
|
|
154
|
+
* Default redaction includes: authorization, apiKey, jwt, privateKey, secret, password.
|
|
155
|
+
*
|
|
156
|
+
* @param {Record<string, unknown> | undefined} obj - The object to redact
|
|
157
|
+
* @returns {Record<string, unknown> | undefined} A new object with sensitive values redacted, or undefined if input was undefined
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { redactObject } from "@alchemy/common";
|
|
161
|
+
*
|
|
162
|
+
* const data = {
|
|
163
|
+
* apiKey: "secret123",
|
|
164
|
+
* userId: "user-456",
|
|
165
|
+
* nested: { secret: "hidden" }
|
|
166
|
+
* };
|
|
167
|
+
*
|
|
168
|
+
* const redacted = redactObject(data);
|
|
169
|
+
* // { apiKey: "[REDACTED]", userId: "user-456", nested: { secret: "[REDACTED]" } }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function redactObject(obj: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Default console sink for diagnostics logging.
|
|
175
|
+
* Routes log entries to appropriate console methods based on log level.
|
|
176
|
+
*
|
|
177
|
+
* Format: [HH:MM:SS.mmm] [package@version] message {data}
|
|
178
|
+
*
|
|
179
|
+
* @param {LogEntry} entry - The log entry to output
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { consoleSink, setGlobalLoggerConfig } from "@alchemy/common";
|
|
183
|
+
*
|
|
184
|
+
* // Console sink is used by default, but can be explicitly configured
|
|
185
|
+
* setGlobalLoggerConfig({
|
|
186
|
+
* sinks: [consoleSink]
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare function consoleSink(entry: LogEntry): void;
|
|
191
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/logging/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ;IACnB,2BAA2B;;IAE3B,0BAA0B;;IAE1B,mDAAmD;;IAEnD,mCAAmC;;IAEnC,6CAA6C;;CAErC,CAAC;AAGX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ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AgB,qBAAqB,IAAI,QAAQ,CAAC,iBAAiB,CAAC,CAGnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,CAalE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEvD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAezE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACvC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAsBrC;AAiDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAwBjD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createLogger, LogLevel, consoleSink } from "./logger.js";
|
|
2
|
+
export type { DiagnosticsLogger } from "./logger.js";
|
|
3
|
+
export { setGlobalLoggerConfig, getGlobalLoggerConfig, isLevelEnabled, isNamespaceEnabled, redactObject, } from "./config.js";
|
|
4
|
+
export type { LogEntry, DiagnosticsConfig, RedactConfig, LoggerContextBase, } from "./config.js";
|
|
5
|
+
export { InMemorySink } from "./sinks.js";
|
|
6
|
+
export type * from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/logging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,mBAAmB,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EventsSchema, InnerLogger, LoggerContext } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a local-only logger that outputs events to the console in development mode.
|
|
4
|
+
* This logger does not send data to external services and is safe for all environments.
|
|
5
|
+
*
|
|
6
|
+
* @template Schema - The events schema defining allowed events and their data structures
|
|
7
|
+
* @param {LoggerContext} context - Context information to attach to all events
|
|
8
|
+
* @returns {InnerLogger<Schema>} A logger instance that logs to console in dev mode
|
|
9
|
+
*/
|
|
10
|
+
export declare function createLocalLogger<Schema extends EventsSchema = []>(context: LoggerContext): InnerLogger<Schema>;
|
|
11
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/logging/local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3E;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,YAAY,GAAG,EAAE,EAChE,OAAO,EAAE,aAAa,GACrB,WAAW,CAAC,MAAM,CAAC,CAyBrB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { LogLevel, consoleSink, type LoggerContextBase } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Lazy message supplier function for expensive log computations.
|
|
4
|
+
* Only evaluated when the log level is enabled.
|
|
5
|
+
*
|
|
6
|
+
* @returns {[string, Record<string, unknown>?]} Tuple of [message, optional data]
|
|
7
|
+
*/
|
|
8
|
+
type MessageSupplier = () => [string, Record<string, unknown>?];
|
|
9
|
+
/**
|
|
10
|
+
* Diagnostics logger instance for developer-facing debugging output.
|
|
11
|
+
* Provides level-based logging (error, warn, info, debug, verbose) with structured data.
|
|
12
|
+
*/
|
|
13
|
+
export type DiagnosticsLogger = {
|
|
14
|
+
/** Log debug messages for development and troubleshooting */
|
|
15
|
+
debug: (msg: string | MessageSupplier, data?: Record<string, unknown>) => void;
|
|
16
|
+
/** Log informational messages for key operations */
|
|
17
|
+
info: (msg: string | MessageSupplier, data?: Record<string, unknown>) => void;
|
|
18
|
+
/** Log warnings for recoverable issues */
|
|
19
|
+
warn: (msg: string | MessageSupplier, data?: Record<string, unknown>) => void;
|
|
20
|
+
/** Log errors for failures */
|
|
21
|
+
error: (msg: string | MessageSupplier, data?: Record<string, unknown>) => void;
|
|
22
|
+
/** Log verbose details for very detailed tracing */
|
|
23
|
+
verbose: (msg: string | MessageSupplier, data?: Record<string, unknown>) => void;
|
|
24
|
+
/** Create a child logger with additional context merged into all log entries */
|
|
25
|
+
withContext: (extra: Record<string, unknown>) => DiagnosticsLogger;
|
|
26
|
+
/**
|
|
27
|
+
* Wrap a function to measure and log its execution time at DEBUG level.
|
|
28
|
+
* Supports both synchronous and asynchronous functions.
|
|
29
|
+
*
|
|
30
|
+
* @template TArgs - Function argument types
|
|
31
|
+
* @template TRet - Function return type
|
|
32
|
+
* @param name - Name for profiling logs
|
|
33
|
+
* @param func - Function to profile
|
|
34
|
+
* @returns Wrapped function that logs execution time
|
|
35
|
+
*/
|
|
36
|
+
profiled<TArgs extends any[], TRet>(name: string, func: (...args: TArgs) => TRet): (...args: TArgs) => TRet;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for creating a diagnostics logger instance.
|
|
40
|
+
*/
|
|
41
|
+
export type CreateLoggerParams = LoggerContextBase & {
|
|
42
|
+
/** Optional namespace for filtering/grouping (e.g., "aa-infra", "wallet-apis") */
|
|
43
|
+
namespace?: string;
|
|
44
|
+
/** Optional base context merged into all log entries from this logger */
|
|
45
|
+
baseContext?: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Creates a diagnostics logger instance for a package.
|
|
49
|
+
* Loggers emit structured log entries to configured sinks (default: console).
|
|
50
|
+
*
|
|
51
|
+
* All log methods support:
|
|
52
|
+
* - String messages: `logger.info("message", { data })`
|
|
53
|
+
* - Lazy suppliers: `logger.debug(() => ["expensive", computeData()])` (only evaluated when level enabled)
|
|
54
|
+
*
|
|
55
|
+
* @param {CreateLoggerParams} params - Logger configuration
|
|
56
|
+
* @returns {DiagnosticsLogger} A logger instance
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { createLogger } from "@alchemy/common";
|
|
60
|
+
*
|
|
61
|
+
* const logger = createLogger({
|
|
62
|
+
* package: "@alchemy/aa-infra",
|
|
63
|
+
* version: "1.0.0",
|
|
64
|
+
* namespace: "aa-infra"
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* logger.info("processing request", { chainId: 1 });
|
|
68
|
+
* logger.debug("detailed state", { userOp: op });
|
|
69
|
+
*
|
|
70
|
+
* // Child logger with additional context
|
|
71
|
+
* const childLogger = logger.withContext({ requestId: "123" });
|
|
72
|
+
* childLogger.info("step complete"); // includes requestId in all logs
|
|
73
|
+
*
|
|
74
|
+
* // Profile a function
|
|
75
|
+
* const sendWithProfiling = logger.profiled("sendUserOp", sendUserOp);
|
|
76
|
+
* await sendWithProfiling(op); // logs execution time at DEBUG level
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function createLogger(params: CreateLoggerParams): DiagnosticsLogger;
|
|
80
|
+
export { LogLevel, consoleSink };
|
|
81
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/logging/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CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,GAC7B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG;IACnD,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,iBAAiB,CAwF1E;AAED,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { InnerLogger } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* No-operation logger that discards all events.
|
|
4
|
+
* Used as a fallback when logger initialization fails or in disabled states.
|
|
5
|
+
*/
|
|
6
|
+
export declare const noopLogger: InnerLogger<any>;
|
|
7
|
+
//# sourceMappingURL=noop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop.d.ts","sourceRoot":"","sources":["../../../src/logging/noop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,GAAG,CAMvC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { LogEntry } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory sink for testing purposes.
|
|
4
|
+
* Captures all log entries in an array that can be inspected in tests.
|
|
5
|
+
*
|
|
6
|
+
* **Note:** This is primarily intended for testing SDK integrations.
|
|
7
|
+
* Most applications should use the default console sink.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { InMemorySink, setGlobalLoggerConfig, createLogger } from "@alchemy/common";
|
|
12
|
+
*
|
|
13
|
+
* // In tests
|
|
14
|
+
* const sink = new InMemorySink();
|
|
15
|
+
*
|
|
16
|
+
* setGlobalLoggerConfig({
|
|
17
|
+
* sinks: [sink.sink]
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const logger = createLogger({
|
|
21
|
+
* package: "@alchemy/aa-infra",
|
|
22
|
+
* version: "1.0.0",
|
|
23
|
+
* namespace: "aa-infra"
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* logger.info("test message");
|
|
27
|
+
*
|
|
28
|
+
* // Inspect captured logs
|
|
29
|
+
* expect(sink.count).toBe(1);
|
|
30
|
+
* expect(sink.latest()?.message).toBe("test message");
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class InMemorySink {
|
|
34
|
+
/**
|
|
35
|
+
* Array of captured log entries
|
|
36
|
+
*/
|
|
37
|
+
entries: LogEntry[];
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new InMemorySink instance.
|
|
40
|
+
* Binds the sink method to the instance for use as a callback.
|
|
41
|
+
*/
|
|
42
|
+
constructor();
|
|
43
|
+
/**
|
|
44
|
+
* The sink function to pass to setGlobalLoggerConfig.
|
|
45
|
+
* Captures log entries into the internal array.
|
|
46
|
+
*
|
|
47
|
+
* @param {LogEntry} entry - The log entry to capture
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
sink(entry: LogEntry): void;
|
|
51
|
+
/**
|
|
52
|
+
* Clear all captured entries
|
|
53
|
+
*
|
|
54
|
+
* @returns {void}
|
|
55
|
+
*/
|
|
56
|
+
clear(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get entries filtered by log level
|
|
59
|
+
*
|
|
60
|
+
* @param {number} level - The log level to filter by (LogLevel.ERROR, LogLevel.INFO, etc.)
|
|
61
|
+
* @returns {LogEntry[]} Array of log entries matching the specified level
|
|
62
|
+
*/
|
|
63
|
+
getByLevel(level: number): LogEntry[];
|
|
64
|
+
/**
|
|
65
|
+
* Get entries filtered by namespace
|
|
66
|
+
*
|
|
67
|
+
* @param {string} namespace - The namespace to filter by (e.g., "aa-infra", "wallet-apis")
|
|
68
|
+
* @returns {LogEntry[]} Array of log entries matching the specified namespace
|
|
69
|
+
*/
|
|
70
|
+
getByNamespace(namespace: string): LogEntry[];
|
|
71
|
+
/**
|
|
72
|
+
* Get entries filtered by message substring
|
|
73
|
+
*
|
|
74
|
+
* @param {string} substring - The substring to search for in log messages
|
|
75
|
+
* @returns {LogEntry[]} Array of log entries containing the substring in their message
|
|
76
|
+
*/
|
|
77
|
+
getByMessage(substring: string): LogEntry[];
|
|
78
|
+
/**
|
|
79
|
+
* Get the most recent log entry
|
|
80
|
+
*
|
|
81
|
+
* @returns {LogEntry | undefined} The latest log entry, or undefined if no entries have been captured
|
|
82
|
+
*/
|
|
83
|
+
latest(): LogEntry | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get the number of captured entries
|
|
86
|
+
*
|
|
87
|
+
* @returns {number} The total count of captured log entries
|
|
88
|
+
*/
|
|
89
|
+
get count(): number;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=sinks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sinks.d.ts","sourceRoot":"","sources":["../../../src/logging/sinks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,YAAY;IACvB;;OAEG;IACI,OAAO,EAAE,QAAQ,EAAE,CAAM;IAEhC;;;OAGG;;IAKH;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI3B;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE;IAIrC;;;;;OAKG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE;IAI7C;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,EAAE;IAI3C;;;;OAIG;IACH,MAAM,IAAI,QAAQ,GAAG,SAAS;IAI9B;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;CACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema definition for event logging.
|
|
3
|
+
* An array of event definitions with their names and optional data structures.
|
|
4
|
+
*/
|
|
5
|
+
export type EventsSchema = readonly {
|
|
6
|
+
EventName: string;
|
|
7
|
+
EventData?: Record<string, any>;
|
|
8
|
+
}[];
|
|
9
|
+
type Prettify<T> = {
|
|
10
|
+
[K in keyof T]: T[K];
|
|
11
|
+
} & {};
|
|
12
|
+
/**
|
|
13
|
+
* Type-safe parameters for tracking events based on the provided schema.
|
|
14
|
+
* Ensures event names and data structures match the schema definition.
|
|
15
|
+
* When no schema is provided, allows any event with optional data.
|
|
16
|
+
*
|
|
17
|
+
* @template Schema - The events schema to validate against
|
|
18
|
+
*/
|
|
19
|
+
export type TrackEventParameters<Schema extends EventsSchema> = Schema extends readonly [] ? {
|
|
20
|
+
name: string;
|
|
21
|
+
data?: any;
|
|
22
|
+
} : {
|
|
23
|
+
[K in keyof Schema]: Prettify<{
|
|
24
|
+
name: Schema[K]["EventName"];
|
|
25
|
+
} & ([undefined] extends [
|
|
26
|
+
Schema[K]["EventData"]
|
|
27
|
+
] ? {
|
|
28
|
+
data?: undefined;
|
|
29
|
+
} : {
|
|
30
|
+
data: Schema[K]["EventData"];
|
|
31
|
+
})>;
|
|
32
|
+
}[number];
|
|
33
|
+
/**
|
|
34
|
+
* Main event logger interface for type-safe event tracking and performance profiling.
|
|
35
|
+
*
|
|
36
|
+
* @template Schema - The events schema defining allowed events and their data structures
|
|
37
|
+
*/
|
|
38
|
+
export interface EventLogger<Schema extends EventsSchema = []> {
|
|
39
|
+
/**
|
|
40
|
+
* Tracks an event with type-safe validation against the schema.
|
|
41
|
+
*
|
|
42
|
+
* @param params - Event parameters including name and optional data
|
|
43
|
+
* @returns Promise that resolves when the event is tracked
|
|
44
|
+
*/
|
|
45
|
+
trackEvent(params: TrackEventParameters<Schema extends readonly [] ? [] : [...Schema, PerformanceEvent]>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Wraps a function to automatically track its execution time as a performance event.
|
|
48
|
+
*
|
|
49
|
+
* @template TArgs - Function argument types
|
|
50
|
+
* @template TRet - Function return type
|
|
51
|
+
* @param name - Name identifier for the profiled function
|
|
52
|
+
* @param func - Function to wrap with performance tracking
|
|
53
|
+
* @returns Wrapped function that tracks execution time
|
|
54
|
+
*/
|
|
55
|
+
profiled<TArgs extends any[], TRet>(name: string, func: (...args: TArgs) => TRet): (...args: TArgs) => TRet;
|
|
56
|
+
/** Internal properties for logger state and configuration */
|
|
57
|
+
_internal: {
|
|
58
|
+
/** Promise that resolves when logger is ready for use */
|
|
59
|
+
ready: Promise<unknown>;
|
|
60
|
+
/** Anonymous identifier for this logger instance */
|
|
61
|
+
anonId: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Internal logger interface without the profiled method.
|
|
66
|
+
* Used internally by different logger implementations.
|
|
67
|
+
*
|
|
68
|
+
* @template Schema - The events schema defining allowed events and their data structures
|
|
69
|
+
*/
|
|
70
|
+
export type InnerLogger<Schema extends EventsSchema> = Omit<EventLogger<Schema>, "profiled">;
|
|
71
|
+
/**
|
|
72
|
+
* Context information attached to all logged events.
|
|
73
|
+
* Provides metadata about the package and version generating events.
|
|
74
|
+
*/
|
|
75
|
+
export type LoggerContext = {
|
|
76
|
+
/** Name of the package generating events */
|
|
77
|
+
package: string;
|
|
78
|
+
/** Version of the package generating events */
|
|
79
|
+
version: string;
|
|
80
|
+
/** Additional context properties as key-value pairs */
|
|
81
|
+
[key: string]: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Built-in performance event schema for tracking function execution times.
|
|
85
|
+
* Automatically included in all event schemas for profiled function tracking.
|
|
86
|
+
*/
|
|
87
|
+
export type PerformanceEvent = {
|
|
88
|
+
EventName: "performance";
|
|
89
|
+
EventData: {
|
|
90
|
+
/** Execution time in milliseconds */
|
|
91
|
+
executionTimeMs: number;
|
|
92
|
+
/** Name of the function being profiled */
|
|
93
|
+
functionName: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/logging/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC,EAAE,CAAC;AAEJ,KAAK,QAAQ,CAAC,CAAC,IAAI;KAChB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAC;AAEP;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,MAAM,SAAS,YAAY,IAC1D,MAAM,SAAS,SAAS,EAAE,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,GAC5B;KACG,CAAC,IAAI,MAAM,MAAM,GAAG,QAAQ,CAC3B;QAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;KAAE,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS;QACtD,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;KACvB,GACG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAA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xB,0CAA0C;QAC1C,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects if the current environment is in development mode.
|
|
3
|
+
* Checks multiple common development environment indicators.
|
|
4
|
+
*
|
|
5
|
+
* @returns {boolean} True if running in development mode
|
|
6
|
+
*/
|
|
7
|
+
export declare function isClientDevMode(): boolean;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/logging/utils.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,eAAe,YAoB9B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RestRequestFn, RestRequestSchema } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for creating an AlchemyRestClient instance.
|
|
4
|
+
*/
|
|
5
|
+
export type AlchemyRestClientParams = {
|
|
6
|
+
/** API key for Alchemy authentication */
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/** JWT token for Alchemy authentication */
|
|
9
|
+
jwt?: string;
|
|
10
|
+
/** Custom URL (optional - defaults to Alchemy's chain-agnostic URL, but can be used to override it) */
|
|
11
|
+
url?: string;
|
|
12
|
+
/** Custom headers to be sent with requests */
|
|
13
|
+
headers?: HeadersInit;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A client for making requests to Alchemy's non-JSON-RPC endpoints.
|
|
17
|
+
*/
|
|
18
|
+
export declare class AlchemyRestClient<Schema extends RestRequestSchema> {
|
|
19
|
+
private readonly url;
|
|
20
|
+
private readonly headers;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of AlchemyRestClient.
|
|
23
|
+
*
|
|
24
|
+
* @param {AlchemyRestClientParams} params - The parameters for configuring the client, including API key, JWT, custom URL, and headers.
|
|
25
|
+
*/
|
|
26
|
+
constructor({ apiKey, jwt, url, headers }: AlchemyRestClientParams);
|
|
27
|
+
/**
|
|
28
|
+
* Makes an HTTP request to an Alchemy non-JSON-RPC endpoint.
|
|
29
|
+
*
|
|
30
|
+
* @param {RestRequestFn<Schema>} params - The parameters for the request
|
|
31
|
+
* @returns {Promise<unknown>} The response from the request
|
|
32
|
+
*/
|
|
33
|
+
request: RestRequestFn<Schema>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=restClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restClient.d.ts","sourceRoot":"","sources":["../../../src/rest/restClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAInE;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uGAAuG;IACvG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,iBAAiB,CAAC,MAAM,SAAS,iBAAiB;IAC7D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC;;;;OAIG;gBACS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,uBAAuB;IAKlE;;;;;OAKG;IACI,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAkBnC;CACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Prettify } from "viem";
|
|
2
|
+
export type RestRequestSchema = readonly {
|
|
3
|
+
Route: string;
|
|
4
|
+
Method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
|
|
5
|
+
Body?: unknown | undefined;
|
|
6
|
+
Response: unknown;
|
|
7
|
+
}[];
|
|
8
|
+
export type RestRequestParams<Schema extends RestRequestSchema | undefined = undefined> = Schema extends RestRequestSchema ? {
|
|
9
|
+
[K in keyof Schema]: Prettify<{
|
|
10
|
+
route: Schema[K] extends Schema[number] ? Schema[K]["Route"] : never;
|
|
11
|
+
method: Schema[K] extends Schema[number] ? Schema[K]["Method"] : never;
|
|
12
|
+
} & (Schema[K] extends Schema[number] ? Schema[K]["Body"] extends undefined ? {
|
|
13
|
+
body?: undefined;
|
|
14
|
+
} : {
|
|
15
|
+
body: Schema[K]["Body"];
|
|
16
|
+
} : never)>;
|
|
17
|
+
}[number] : {
|
|
18
|
+
route: string;
|
|
19
|
+
method: RestRequestSchema[number]["Method"];
|
|
20
|
+
body?: unknown | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type RestRequestFn<Schema extends RestRequestSchema | undefined = undefined> = <_parameters extends RestRequestParams<Schema> = RestRequestParams<Schema>, _returnType = Schema extends RestRequestSchema ? Extract<Schema[number], {
|
|
23
|
+
Route: _parameters["route"];
|
|
24
|
+
}>["Response"] : unknown>(params: _parameters) => Promise<_returnType>;
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rest/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAErC,MAAM,MAAM,iBAAiB,GAAG,SAAS;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACzE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;CACnB,EAAE,CAAC;AAEJ,MAAM,MAAM,iBAAiB,CAC3B,MAAM,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