@account-kit/infra 4.61.0 → 4.62.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/dist/esm/alchemyTransport.d.ts +1 -1
- package/dist/esm/alchemyTransport.js +1 -1
- package/dist/esm/alchemyTransport.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/alchemyTransport.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/alchemyTransport.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -28,7 +28,7 @@ export type AlchemyTransport = AlchemyTransportBase & {
|
|
|
28
28
|
/**
|
|
29
29
|
* A type guard for the transport to determine if it is an Alchemy transport.
|
|
30
30
|
* Used in cases where we would like to do switching depending on the transport, where there used
|
|
31
|
-
* to be two clients for
|
|
31
|
+
* to be two clients for an alchemy and a non-alchemy, and with this switch we don't need the two seperate clients. *
|
|
32
32
|
*
|
|
33
33
|
* @param {Transport} transport The transport to check
|
|
34
34
|
* @param {Chain} chain Chain for the transport to run its function to return the transport config
|
|
@@ -26,7 +26,7 @@ const chainAgnosticMethods = [
|
|
|
26
26
|
/**
|
|
27
27
|
* A type guard for the transport to determine if it is an Alchemy transport.
|
|
28
28
|
* Used in cases where we would like to do switching depending on the transport, where there used
|
|
29
|
-
* to be two clients for
|
|
29
|
+
* to be two clients for an alchemy and a non-alchemy, and with this switch we don't need the two seperate clients. *
|
|
30
30
|
*
|
|
31
31
|
* @param {Transport} transport The transport to check
|
|
32
32
|
* @param {Chain} chain Chain for the transport to run its function to return the transport config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alchemyTransport.js","sourceRoot":"","sources":["../../src/alchemyTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,GAGN,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAA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C,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAAqB,EACG,EAAE;IAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC/B,MAAM,aAAa,GAAG,EAA4B,CAAC;QACnD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7B,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n ChainNotFoundError,\n ConnectionConfigSchema,\n split,\n type ConnectionConfig,\n type NoUndefined,\n} from \"@aa-sdk/core\";\nimport {\n createTransport,\n http,\n type Chain,\n type EIP1193RequestFn,\n type HttpTransportConfig,\n type PublicRpcSchema,\n type Transport,\n type TransportConfig,\n} from \"viem\";\nimport { mutateRemoveTrackingHeaders } from \"./alchemyTrackerHeaders.js\";\nimport type { AlchemyRpcSchema } from \"./client/types.js\";\nimport { AlchemyChainSchema } from \"./schema.js\";\nimport { VERSION } from \"./version.js\";\n\ntype Never<T> = T extends object\n ? {\n [K in keyof T]?: never;\n }\n : never;\n\ntype AlchemyConnectionConfig = ConnectionConfig;\n\ntype SplitTransportConfig = {\n alchemyConnection: AlchemyConnectionConfig;\n nodeRpcUrl: string;\n};\n\nconst alchemyMethods = [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"rundler_maxPriorityFeePerGas\",\n \"pm_getPaymasterData\",\n \"pm_getPaymasterStubData\",\n \"alchemy_requestGasAndPaymasterAndData\",\n];\n\nconst chainAgnosticMethods = [\n \"wallet_prepareCalls\",\n \"wallet_sendPreparedCalls\",\n \"wallet_requestAccount\",\n \"wallet_createAccount\",\n \"wallet_listAccounts\",\n \"wallet_createSession\",\n \"wallet_getCallsStatus\",\n];\n\nexport type AlchemyTransportConfig = (\n | (AlchemyConnectionConfig & Never<SplitTransportConfig>)\n | (SplitTransportConfig & Never<AlchemyConnectionConfig>)\n) & {\n /** The max number of times to retry. */\n retryCount?: TransportConfig[\"retryCount\"] | undefined;\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig[\"retryDelay\"] | undefined;\n fetchOptions?: NoUndefined<HttpTransportConfig[\"fetchOptions\"]>;\n};\n\ntype AlchemyTransportBase = Transport<\n \"alchemy\",\n {\n alchemyRpcUrl: string;\n fetchOptions?: AlchemyTransportConfig[\"fetchOptions\"];\n },\n EIP1193RequestFn<[...PublicRpcSchema, ...AlchemyRpcSchema]>\n>;\n\nexport type AlchemyTransport = AlchemyTransportBase & {\n updateHeaders(newHeaders: HeadersInit): void;\n config: AlchemyTransportConfig;\n dynamicFetchOptions: AlchemyTransportConfig[\"fetchOptions\"];\n};\n\n/**\n * A type guard for the transport to determine if it is an Alchemy transport.\n * Used in cases where we would like to do switching depending on the transport, where there used\n * to be two clients for a alchemy and a non alchemy, and with this switch we don't need the two seperate clients. *\n *\n * @param {Transport} transport The transport to check\n * @param {Chain} chain Chain for the transport to run its function to return the transport config\n * @returns {boolean} `true` if the transport is an Alchemy transport, otherwise `false`\n */\nexport function isAlchemyTransport(\n transport: Transport,\n chain: Chain,\n): transport is AlchemyTransport {\n return transport({ chain }).config.type === \"alchemy\";\n}\n\n/**\n * Creates an Alchemy transport with the specified configuration options.\n * When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt.\n * If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.\n *\n * @example\n * ### Basic Example\n * If the chain you're using is supported for both Bundler and Node RPCs, then you can do the following:\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * // NOTE: you can also pass in an rpcUrl or jwt here or rpcUrl and jwt\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * ### AA Only Chains\n * For AA-only chains, you need to specify the alchemyConnection and nodeRpcUrl since Alchemy only\n * handles the Bundler and Paymaster RPCs for these chains.\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * alchemyConnection: {\n * apiKey: \"your-api-key\",\n * },\n * nodeRpcUrl: \"https://zora.rpc.url\",\n * });\n * ```\n *\n * @param {AlchemyTransportConfig} config The configuration object for the Alchemy transport.\n * @param {number} config.retryDelay Optional The delay between retries, in milliseconds.\n * @param {number} config.retryCount Optional The number of retry attempts.\n * @param {string} [config.alchemyConnection] Optional Alchemy connection configuration (if this is passed in, nodeRpcUrl is required).\n * @param {string} [config.fetchOptions] Optional fetch options for HTTP requests.\n * @param {string} [config.nodeRpcUrl] Optional RPC URL for node (if this is passed in, alchemyConnection is required).\n * @param {string} [config.rpcUrl] Optional RPC URL.\n * @param {string} [config.apiKey] Optional API key for Alchemy.\n * @param {string} [config.jwt] Optional JSON Web Token for authorization.\n * @returns {AlchemyTransport} The configured Alchemy transport object.\n */\nexport function alchemy(config: AlchemyTransportConfig): AlchemyTransport {\n const { retryDelay, retryCount = 0 } = config;\n // we create a copy here in case we create a split transport down below\n // we don't want to add alchemy headers to 3rd party nodes\n const fetchOptions = { ...config.fetchOptions };\n\n const connectionConfig = ConnectionConfigSchema.parse(\n config.alchemyConnection ?? config,\n );\n\n const headersAsObject = convertHeadersToObject(fetchOptions.headers);\n\n // TODO: we probably should just log these headers during telemetry logging instead of doing this mutable header stuff\n fetchOptions.headers = {\n ...headersAsObject,\n \"Alchemy-AA-Sdk-Version\": VERSION,\n };\n\n if (connectionConfig.jwt != null || connectionConfig.apiKey != null) {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n Authorization: `Bearer ${\n connectionConfig.jwt ?? connectionConfig.apiKey\n }`,\n };\n }\n\n const transport: AlchemyTransportBase = (opts) => {\n const { chain: chain_ } = opts;\n if (!chain_) {\n throw new ChainNotFoundError();\n }\n const chain = AlchemyChainSchema.parse(chain_);\n\n const rpcUrl =\n connectionConfig.rpcUrl == null\n ? chain.rpcUrls.alchemy.http[0]\n : connectionConfig.rpcUrl;\n\n const chainAgnosticRpcUrl =\n connectionConfig.rpcUrl == null\n ? \"https://api.g.alchemy.com/v2\"\n : (connectionConfig.chainAgnosticUrl ?? connectionConfig.rpcUrl);\n\n const innerTransport = (() => {\n mutateRemoveTrackingHeaders(config?.fetchOptions?.headers);\n if (config.alchemyConnection && config.nodeRpcUrl) {\n return split({\n overrides: [\n {\n methods: alchemyMethods,\n transport: http(rpcUrl, { fetchOptions, retryCount }),\n },\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, {\n fetchOptions,\n retryCount,\n retryDelay,\n }),\n },\n ],\n fallback: http(config.nodeRpcUrl, {\n fetchOptions: config.fetchOptions,\n retryCount,\n retryDelay,\n }),\n });\n }\n\n return split({\n overrides: [\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, {\n fetchOptions,\n retryCount,\n retryDelay,\n }),\n },\n ],\n fallback: http(rpcUrl, { fetchOptions, retryCount, retryDelay }),\n });\n })();\n\n return createTransport(\n {\n key: \"alchemy\",\n name: \"Alchemy Transport\",\n request: innerTransport({\n ...opts,\n // Retries are already handled above within the split transport,\n // so `retryCount` must be 0 here for the expected behavior.\n retryCount: 0,\n }).request,\n // Retries are already handled above within the split transport,\n // so `retryCount` must be 0 here too for the expected behavior.\n retryCount: 0,\n retryDelay,\n type: \"alchemy\",\n },\n { alchemyRpcUrl: rpcUrl, fetchOptions },\n );\n };\n\n return Object.assign(transport, {\n dynamicFetchOptions: fetchOptions,\n updateHeaders(newHeaders_: HeadersInit) {\n const newHeaders = convertHeadersToObject(newHeaders_);\n\n fetchOptions.headers = {\n ...fetchOptions.headers,\n ...newHeaders,\n };\n },\n config,\n });\n}\n\nexport const convertHeadersToObject = (\n headers?: HeadersInit,\n): Record<string, string> => {\n if (!headers) {\n return {};\n }\n\n if (headers instanceof Headers) {\n const headersObject = {} as Record<string, string>;\n headers.forEach((value, key) => {\n headersObject[key] = value;\n });\n return headersObject;\n }\n\n if (Array.isArray(headers)) {\n return headers.reduce(\n (acc, header) => {\n acc[header[0]] = header[1];\n return acc;\n },\n {} as Record<string, string>,\n );\n }\n\n return headers;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"alchemyTransport.js","sourceRoot":"","sources":["../../src/alchemyTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,GAGN,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,IAAI,GAOL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,cAAc,GAAG;IACrB,uBAAuB;IACvB,8BAA8B;IAC9B,6BAA6B;IAC7B,4BAA4B;IAC5B,0BAA0B;IAC1B,8BAA8B;IAC9B,qBAAqB;IACrB,yBAAyB;IACzB,uCAAuC;CACxC,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,qBAAqB;IACrB,0BAA0B;IAC1B,uBAAuB;IACvB,sBAAsB;IACtB,qBAAqB;IACrB,sBAAsB;IACtB,uBAAuB;CAC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AAM,CACnB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC3B,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import {\n ChainNotFoundError,\n ConnectionConfigSchema,\n split,\n type ConnectionConfig,\n type NoUndefined,\n} from \"@aa-sdk/core\";\nimport {\n createTransport,\n http,\n type Chain,\n type EIP1193RequestFn,\n type HttpTransportConfig,\n type PublicRpcSchema,\n type Transport,\n type TransportConfig,\n} from \"viem\";\nimport { mutateRemoveTrackingHeaders } from \"./alchemyTrackerHeaders.js\";\nimport type { AlchemyRpcSchema } from \"./client/types.js\";\nimport { AlchemyChainSchema } from \"./schema.js\";\nimport { VERSION } from \"./version.js\";\n\ntype Never<T> = T extends object\n ? {\n [K in keyof T]?: never;\n }\n : never;\n\ntype AlchemyConnectionConfig = ConnectionConfig;\n\ntype SplitTransportConfig = {\n alchemyConnection: AlchemyConnectionConfig;\n nodeRpcUrl: string;\n};\n\nconst alchemyMethods = [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"rundler_maxPriorityFeePerGas\",\n \"pm_getPaymasterData\",\n \"pm_getPaymasterStubData\",\n \"alchemy_requestGasAndPaymasterAndData\",\n];\n\nconst chainAgnosticMethods = [\n \"wallet_prepareCalls\",\n \"wallet_sendPreparedCalls\",\n \"wallet_requestAccount\",\n \"wallet_createAccount\",\n \"wallet_listAccounts\",\n \"wallet_createSession\",\n \"wallet_getCallsStatus\",\n];\n\nexport type AlchemyTransportConfig = (\n | (AlchemyConnectionConfig & Never<SplitTransportConfig>)\n | (SplitTransportConfig & Never<AlchemyConnectionConfig>)\n) & {\n /** The max number of times to retry. */\n retryCount?: TransportConfig[\"retryCount\"] | undefined;\n /** The base delay (in ms) between retries. */\n retryDelay?: TransportConfig[\"retryDelay\"] | undefined;\n fetchOptions?: NoUndefined<HttpTransportConfig[\"fetchOptions\"]>;\n};\n\ntype AlchemyTransportBase = Transport<\n \"alchemy\",\n {\n alchemyRpcUrl: string;\n fetchOptions?: AlchemyTransportConfig[\"fetchOptions\"];\n },\n EIP1193RequestFn<[...PublicRpcSchema, ...AlchemyRpcSchema]>\n>;\n\nexport type AlchemyTransport = AlchemyTransportBase & {\n updateHeaders(newHeaders: HeadersInit): void;\n config: AlchemyTransportConfig;\n dynamicFetchOptions: AlchemyTransportConfig[\"fetchOptions\"];\n};\n\n/**\n * A type guard for the transport to determine if it is an Alchemy transport.\n * Used in cases where we would like to do switching depending on the transport, where there used\n * to be two clients for an alchemy and a non-alchemy, and with this switch we don't need the two seperate clients. *\n *\n * @param {Transport} transport The transport to check\n * @param {Chain} chain Chain for the transport to run its function to return the transport config\n * @returns {boolean} `true` if the transport is an Alchemy transport, otherwise `false`\n */\nexport function isAlchemyTransport(\n transport: Transport,\n chain: Chain,\n): transport is AlchemyTransport {\n return transport({ chain }).config.type === \"alchemy\";\n}\n\n/**\n * Creates an Alchemy transport with the specified configuration options.\n * When sending all traffic to Alchemy, you must pass in one of rpcUrl, apiKey, or jwt.\n * If you want to send Bundler and Paymaster traffic to Alchemy and Node traffic to a different RPC, you must pass in alchemyConnection and nodeRpcUrl.\n *\n * @example\n * ### Basic Example\n * If the chain you're using is supported for both Bundler and Node RPCs, then you can do the following:\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * // NOTE: you can also pass in an rpcUrl or jwt here or rpcUrl and jwt\n * apiKey: \"your-api-key\",\n * });\n * ```\n *\n * ### AA Only Chains\n * For AA-only chains, you need to specify the alchemyConnection and nodeRpcUrl since Alchemy only\n * handles the Bundler and Paymaster RPCs for these chains.\n * ```ts\n * import { alchemy } from \"@account-kit/infra\";\n *\n * const transport = alchemy({\n * alchemyConnection: {\n * apiKey: \"your-api-key\",\n * },\n * nodeRpcUrl: \"https://zora.rpc.url\",\n * });\n * ```\n *\n * @param {AlchemyTransportConfig} config The configuration object for the Alchemy transport.\n * @param {number} config.retryDelay Optional The delay between retries, in milliseconds.\n * @param {number} config.retryCount Optional The number of retry attempts.\n * @param {string} [config.alchemyConnection] Optional Alchemy connection configuration (if this is passed in, nodeRpcUrl is required).\n * @param {string} [config.fetchOptions] Optional fetch options for HTTP requests.\n * @param {string} [config.nodeRpcUrl] Optional RPC URL for node (if this is passed in, alchemyConnection is required).\n * @param {string} [config.rpcUrl] Optional RPC URL.\n * @param {string} [config.apiKey] Optional API key for Alchemy.\n * @param {string} [config.jwt] Optional JSON Web Token for authorization.\n * @returns {AlchemyTransport} The configured Alchemy transport object.\n */\nexport function alchemy(config: AlchemyTransportConfig): AlchemyTransport {\n const { retryDelay, retryCount = 0 } = config;\n // we create a copy here in case we create a split transport down below\n // we don't want to add alchemy headers to 3rd party nodes\n const fetchOptions = { ...config.fetchOptions };\n\n const connectionConfig = ConnectionConfigSchema.parse(\n config.alchemyConnection ?? config,\n );\n\n const headersAsObject = convertHeadersToObject(fetchOptions.headers);\n\n // TODO: we probably should just log these headers during telemetry logging instead of doing this mutable header stuff\n fetchOptions.headers = {\n ...headersAsObject,\n \"Alchemy-AA-Sdk-Version\": VERSION,\n };\n\n if (connectionConfig.jwt != null || connectionConfig.apiKey != null) {\n fetchOptions.headers = {\n ...fetchOptions.headers,\n Authorization: `Bearer ${\n connectionConfig.jwt ?? connectionConfig.apiKey\n }`,\n };\n }\n\n const transport: AlchemyTransportBase = (opts) => {\n const { chain: chain_ } = opts;\n if (!chain_) {\n throw new ChainNotFoundError();\n }\n const chain = AlchemyChainSchema.parse(chain_);\n\n const rpcUrl =\n connectionConfig.rpcUrl == null\n ? chain.rpcUrls.alchemy.http[0]\n : connectionConfig.rpcUrl;\n\n const chainAgnosticRpcUrl =\n connectionConfig.rpcUrl == null\n ? \"https://api.g.alchemy.com/v2\"\n : (connectionConfig.chainAgnosticUrl ?? connectionConfig.rpcUrl);\n\n const innerTransport = (() => {\n mutateRemoveTrackingHeaders(config?.fetchOptions?.headers);\n if (config.alchemyConnection && config.nodeRpcUrl) {\n return split({\n overrides: [\n {\n methods: alchemyMethods,\n transport: http(rpcUrl, { fetchOptions, retryCount }),\n },\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, {\n fetchOptions,\n retryCount,\n retryDelay,\n }),\n },\n ],\n fallback: http(config.nodeRpcUrl, {\n fetchOptions: config.fetchOptions,\n retryCount,\n retryDelay,\n }),\n });\n }\n\n return split({\n overrides: [\n {\n methods: chainAgnosticMethods,\n transport: http(chainAgnosticRpcUrl, {\n fetchOptions,\n retryCount,\n retryDelay,\n }),\n },\n ],\n fallback: http(rpcUrl, { fetchOptions, retryCount, retryDelay }),\n });\n })();\n\n return createTransport(\n {\n key: \"alchemy\",\n name: \"Alchemy Transport\",\n request: innerTransport({\n ...opts,\n // Retries are already handled above within the split transport,\n // so `retryCount` must be 0 here for the expected behavior.\n retryCount: 0,\n }).request,\n // Retries are already handled above within the split transport,\n // so `retryCount` must be 0 here too for the expected behavior.\n retryCount: 0,\n retryDelay,\n type: \"alchemy\",\n },\n { alchemyRpcUrl: rpcUrl, fetchOptions },\n );\n };\n\n return Object.assign(transport, {\n dynamicFetchOptions: fetchOptions,\n updateHeaders(newHeaders_: HeadersInit) {\n const newHeaders = convertHeadersToObject(newHeaders_);\n\n fetchOptions.headers = {\n ...fetchOptions.headers,\n ...newHeaders,\n };\n },\n config,\n });\n}\n\nexport const convertHeadersToObject = (\n headers?: HeadersInit,\n): Record<string, string> => {\n if (!headers) {\n return {};\n }\n\n if (headers instanceof Headers) {\n const headersObject = {} as Record<string, string>;\n headers.forEach((value, key) => {\n headersObject[key] = value;\n });\n return headersObject;\n }\n\n if (Array.isArray(headers)) {\n return headers.reduce(\n (acc, header) => {\n acc[header[0]] = header[1];\n return acc;\n },\n {} as Record<string, string>,\n );\n }\n\n return headers;\n};\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.62.0";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.62.0\";\n"]}
|
|
@@ -28,7 +28,7 @@ export type AlchemyTransport = AlchemyTransportBase & {
|
|
|
28
28
|
/**
|
|
29
29
|
* A type guard for the transport to determine if it is an Alchemy transport.
|
|
30
30
|
* Used in cases where we would like to do switching depending on the transport, where there used
|
|
31
|
-
* to be two clients for
|
|
31
|
+
* to be two clients for an alchemy and a non-alchemy, and with this switch we don't need the two seperate clients. *
|
|
32
32
|
*
|
|
33
33
|
* @param {Transport} transport The transport to check
|
|
34
34
|
* @param {Chain} chain Chain for the transport to run its function to return the transport config
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.62.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/infra",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.62.0",
|
|
4
4
|
"description": "adapters for @aa-sdk/core for interacting with alchemy services",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript-template": "*"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@aa-sdk/core": "^4.
|
|
52
|
-
"@account-kit/logging": "^4.
|
|
51
|
+
"@aa-sdk/core": "^4.62.0",
|
|
52
|
+
"@account-kit/logging": "^4.62.0",
|
|
53
53
|
"eventemitter3": "^5.0.1",
|
|
54
54
|
"zod": "^3.22.4"
|
|
55
55
|
},
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
69
69
|
},
|
|
70
70
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9306dd1e2921046dd3d6402b3a569c34f5b66130",
|
|
72
72
|
"optionalDependencies": {
|
|
73
73
|
"alchemy-sdk": "^3.0.0"
|
|
74
74
|
}
|
package/src/alchemyTransport.ts
CHANGED
|
@@ -84,7 +84,7 @@ export type AlchemyTransport = AlchemyTransportBase & {
|
|
|
84
84
|
/**
|
|
85
85
|
* A type guard for the transport to determine if it is an Alchemy transport.
|
|
86
86
|
* Used in cases where we would like to do switching depending on the transport, where there used
|
|
87
|
-
* to be two clients for
|
|
87
|
+
* to be two clients for an alchemy and a non-alchemy, and with this switch we don't need the two seperate clients. *
|
|
88
88
|
*
|
|
89
89
|
* @param {Transport} transport The transport to check
|
|
90
90
|
* @param {Chain} chain Chain for the transport to run its function to return the transport config
|
package/src/version.ts
CHANGED