@zerodev/sdk 5.2.15 → 5.2.16

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.
@@ -1,34 +1,52 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFallbackKernelAccountClient = void 0;
4
- const createFallbackKernelAccountClient = (clients) => {
4
+ const createFallbackKernelAccountClient = (clients, onError) => {
5
+ function createFallbackMethod(prop) {
6
+ return async (...args) => {
7
+ for (let i = 0; i < clients.length; i++) {
8
+ try {
9
+ const method = Reflect.get(clients[i], prop);
10
+ if (typeof method === "function") {
11
+ return await method(...args);
12
+ }
13
+ }
14
+ catch (error) {
15
+ console.error(`Action ${String(prop)} failed with client ${clients[i].transport.url}, trying next if available.`);
16
+ if (onError !== undefined) {
17
+ await onError(error, clients[i].transport.url);
18
+ }
19
+ if (i === clients.length - 1) {
20
+ throw error;
21
+ }
22
+ }
23
+ }
24
+ };
25
+ }
5
26
  const proxyClient = new Proxy(clients[0], {
6
27
  get(_target, prop, receiver) {
7
- for (const client of clients) {
8
- const value = Reflect.get(client, prop, receiver);
9
- if (value !== undefined) {
10
- if (typeof value === "function") {
11
- return async (...args) => {
12
- for (let i = 0; i < clients.length; i++) {
13
- try {
14
- const method = Reflect.get(clients[i], prop, receiver);
15
- if (typeof method === "function") {
16
- return await method(...args);
17
- }
18
- }
19
- catch (error) {
20
- console.error(`Action ${String(prop)} failed with client ${client.transport.url}, trying next if available.`, error);
21
- if (i === clients.length - 1) {
22
- throw error;
23
- }
24
- }
25
- }
26
- };
28
+ if (prop === "extend") {
29
+ return (fn) => {
30
+ const modifications = fn(proxyClient);
31
+ for (const [key, modification] of Object.entries(modifications)) {
32
+ if (typeof modification === "function") {
33
+ ;
34
+ proxyClient[key] = async (...args) => {
35
+ return modification(...args);
36
+ };
37
+ }
38
+ else {
39
+ console.error(`Expected a function for modification of ${key}, but received type ${typeof modification}`);
40
+ }
27
41
  }
28
- return value;
29
- }
42
+ return proxyClient;
43
+ };
44
+ }
45
+ const value = Reflect.get(_target, prop, receiver);
46
+ if (typeof value === "function") {
47
+ return createFallbackMethod(prop);
30
48
  }
31
- return undefined;
49
+ return value;
32
50
  }
33
51
  });
34
52
  return proxyClient;
@@ -1 +1 @@
1
- {"version":3,"file":"fallbackKernelAccountClient.js","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":";;;AAKO,MAAM,iCAAiC,GAAG,CAM7C,OAEC,EACkE,EAAE;IACrE,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACtC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACvB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;gBACjD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBAEtB,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;wBAE9B,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;4BAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gCACtC,IAAI,CAAC;oCACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CACtB,OAAO,CAAC,CAAC,CAAC,EACV,IAAI,EACJ,QAAQ,CACX,CAAA;oCACD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;wCAE/B,OAAO,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;oCAChC,CAAC;gCACL,CAAC;gCAAC,OAAO,KAAK,EAAE,CAAC;oCACb,OAAO,CAAC,KAAK,CACT,UAAU,MAAM,CACZ,IAAI,CACP,uBACG,MAAM,CAAC,SAAS,CAAC,GACrB,6BAA6B,EAC7B,KAAK,CACR,CAAA;oCACD,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wCAC3B,MAAM,KAAK,CAAA;oCACf,CAAC;gCACL,CAAC;4BACL,CAAC;wBACL,CAAC,CAAA;oBACL,CAAC;oBAED,OAAO,KAAK,CAAA;gBAChB,CAAC;YACL,CAAC;YAED,OAAO,SAAS,CAAA;QACpB,CAAC;KACJ,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACtB,CAAC,CAAA;AAxDY,QAAA,iCAAiC,qCAwD7C"}
1
+ {"version":3,"file":"fallbackKernelAccountClient.js","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":";;;AAKO,MAAM,iCAAiC,GAAG,CAM7C,OAEC,EACD,OAA4D,EACO,EAAE;IAGrE,SAAS,oBAAoB,CAAC,IAAiB;QAE3C,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,CAAC;oBACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;oBAC5C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;wBAC/B,OAAO,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;oBAChC,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CACT,UAAU,MAAM,CAAC,IAAI,CAAC,uBAClB,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GACzB,6BAA6B,CAChC,CAAA;oBAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;wBACxB,MAAM,OAAO,CAAC,KAAc,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,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,CAAA;AA5EY,QAAA,iCAAiC,qCA4E7C"}
@@ -1,36 +1,57 @@
1
- export const createFallbackKernelAccountClient = (clients) => {
1
+ export const createFallbackKernelAccountClient = (clients, onError) => {
2
+ // Function to create a fallback method for a given property.
3
+ // This method will try each client in sequence until one succeeds or all fail.
4
+ function createFallbackMethod(prop) {
5
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
6
+ return async (...args) => {
7
+ for (let i = 0; i < clients.length; i++) {
8
+ try {
9
+ const method = Reflect.get(clients[i], prop);
10
+ if (typeof method === "function") {
11
+ return await method(...args);
12
+ }
13
+ }
14
+ catch (error) {
15
+ console.error(`Action ${String(prop)} failed with client ${clients[i].transport.url}, trying next if available.`);
16
+ // Call the error handler if provided.
17
+ if (onError !== undefined) {
18
+ await onError(error, clients[i].transport.url);
19
+ }
20
+ if (i === clients.length - 1) {
21
+ throw error;
22
+ }
23
+ }
24
+ }
25
+ };
26
+ }
2
27
  const proxyClient = new Proxy(clients[0], {
3
28
  get(_target, prop, receiver) {
4
- for (const client of clients) {
5
- const value = Reflect.get(client, prop, receiver);
6
- if (value !== undefined) {
7
- // If the property is a function, wrap it to add fallback logic
8
- if (typeof value === "function") {
9
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
- return async (...args) => {
11
- for (let i = 0; i < clients.length; i++) {
12
- try {
13
- const method = Reflect.get(clients[i], prop, receiver);
14
- if (typeof method === "function") {
15
- // Attempt to call the function on the current client
16
- return await method(...args);
17
- }
18
- }
19
- catch (error) {
20
- console.error(`Action ${String(prop)} failed with client ${client.transport.url}, trying next if available.`, error);
21
- if (i === clients.length - 1) {
22
- throw error;
23
- }
24
- }
25
- }
26
- };
29
+ if (prop === "extend") {
30
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
31
+ return (fn) => {
32
+ const modifications = fn(proxyClient);
33
+ for (const [key, modification] of Object.entries(modifications)) {
34
+ if (typeof modification === "function") {
35
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
36
+ ;
37
+ proxyClient[key] = async (
38
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
39
+ ...args) => {
40
+ return modification(...args);
41
+ };
42
+ }
43
+ else {
44
+ console.error(`Expected a function for modification of ${key}, but received type ${typeof modification}`);
45
+ }
27
46
  }
28
- // For non-function properties, return the first defined value found
29
- return value;
30
- }
47
+ return proxyClient;
48
+ };
49
+ }
50
+ const value = Reflect.get(_target, prop, receiver);
51
+ if (typeof value === "function") {
52
+ return createFallbackMethod(prop);
31
53
  }
32
- // If no clients have a defined value for the property, return undefined
33
- return undefined;
54
+ return value;
34
55
  }
35
56
  });
36
57
  return proxyClient;
@@ -1 +1 @@
1
- {"version":3,"file":"fallbackKernelAccountClient.js","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAM7C,OAEC,EACkE,EAAE;IACrE,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACtC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ;YACvB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;gBACjD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACtB,+DAA+D;oBAC/D,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC9B,4DAA4D;wBAC5D,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;4BAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gCACtC,IAAI,CAAC;oCACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CACtB,OAAO,CAAC,CAAC,CAAC,EACV,IAAI,EACJ,QAAQ,CACX,CAAA;oCACD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;wCAC/B,qDAAqD;wCACrD,OAAO,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;oCAChC,CAAC;gCACL,CAAC;gCAAC,OAAO,KAAK,EAAE,CAAC;oCACb,OAAO,CAAC,KAAK,CACT,UAAU,MAAM,CACZ,IAAI,CACP,uBACG,MAAM,CAAC,SAAS,CAAC,GACrB,6BAA6B,EAC7B,KAAK,CACR,CAAA;oCACD,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wCAC3B,MAAM,KAAK,CAAA;oCACf,CAAC;gCACL,CAAC;4BACL,CAAC;wBACL,CAAC,CAAA;oBACL,CAAC;oBACD,oEAAoE;oBACpE,OAAO,KAAK,CAAA;gBAChB,CAAC;YACL,CAAC;YACD,wEAAwE;YACxE,OAAO,SAAS,CAAA;QACpB,CAAC;KACJ,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACtB,CAAC,CAAA"}
1
+ {"version":3,"file":"fallbackKernelAccountClient.js","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAM7C,OAEC,EACD,OAA4D,EACO,EAAE;IACrE,6DAA6D;IAC7D,+EAA+E;IAC/E,SAAS,oBAAoB,CAAC,IAAiB;QAC3C,2DAA2D;QAC3D,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;YAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,CAAC;oBACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;oBAC5C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;wBAC/B,OAAO,MAAM,MAAM,CAAC,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B,OAAO,YAAY,EAAE,CAC7F,CAAA;wBACL,CAAC;oBACL,CAAC;oBACD,OAAO,WAAW,CAAA;gBACtB,CAAC,CAAA;YACL,CAAC;YAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;YAClD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;gBAC9B,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAA;YACrC,CAAC;YACD,OAAO,KAAK,CAAA;QAChB,CAAC;KACJ,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACtB,CAAC,CAAA"}
@@ -2,5 +2,5 @@ import type { EntryPoint } from "permissionless/types";
2
2
  import type { Chain, Transport } from "viem";
3
3
  import type { KernelSmartAccount } from "../accounts/index.js";
4
4
  import type { KernelAccountClient } from "./kernelAccountClient.js";
5
- export declare const createFallbackKernelAccountClient: <TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain | undefined, TSmartAccount extends KernelSmartAccount<TEntryPoint> | undefined>(clients: KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>[]) => KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>;
5
+ export declare const createFallbackKernelAccountClient: <TEntryPoint extends EntryPoint, TTransport extends Transport, TChain extends Chain | undefined, TSmartAccount extends KernelSmartAccount<TEntryPoint> | undefined>(clients: KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>[], onError?: ((error: Error, clientUrl: string) => Promise<void>) | undefined) => KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>;
6
6
  //# sourceMappingURL=fallbackKernelAccountClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fallbackKernelAccountClient.d.ts","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEnE,eAAO,MAAM,iCAAiC,4TAwD7C,CAAA"}
1
+ {"version":3,"file":"fallbackKernelAccountClient.d.ts","sourceRoot":"","sources":["../../clients/fallbackKernelAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEnE,eAAO,MAAM,iCAAiC,yQASxB,KAAK,aAAa,MAAM,KAAK,QAAQ,IAAI,CAAC,qFAmE/D,CAAA"}
@@ -11,50 +11,70 @@ export const createFallbackKernelAccountClient = <
11
11
  >(
12
12
  clients: Array<
13
13
  KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount>
14
- >
14
+ >,
15
+ onError?: (error: Error, clientUrl: string) => Promise<void>
15
16
  ): KernelAccountClient<TEntryPoint, TTransport, TChain, TSmartAccount> => {
17
+ // Function to create a fallback method for a given property.
18
+ // This method will try each client in sequence until one succeeds or all fail.
19
+ function createFallbackMethod(prop: PropertyKey) {
20
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
21
+ return async (...args: any[]) => {
22
+ for (let i = 0; i < clients.length; i++) {
23
+ try {
24
+ const method = Reflect.get(clients[i], prop)
25
+ if (typeof method === "function") {
26
+ return await method(...args)
27
+ }
28
+ } catch (error) {
29
+ console.error(
30
+ `Action ${String(prop)} failed with client ${
31
+ clients[i].transport.url
32
+ }, trying next if available.`
33
+ )
34
+ // Call the error handler if provided.
35
+ if (onError !== undefined) {
36
+ await onError(error as Error, clients[i].transport.url)
37
+ }
38
+ if (i === clients.length - 1) {
39
+ throw error
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+
16
46
  const proxyClient = new Proxy(clients[0], {
17
47
  get(_target, prop, receiver) {
18
- for (const client of clients) {
19
- const value = Reflect.get(client, prop, receiver)
20
- if (value !== undefined) {
21
- // If the property is a function, wrap it to add fallback logic
22
- if (typeof value === "function") {
23
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
24
- return async (...args: any[]) => {
25
- for (let i = 0; i < clients.length; i++) {
26
- try {
27
- const method = Reflect.get(
28
- clients[i],
29
- prop,
30
- receiver
31
- )
32
- if (typeof method === "function") {
33
- // Attempt to call the function on the current client
34
- return await method(...args)
35
- }
36
- } catch (error) {
37
- console.error(
38
- `Action ${String(
39
- prop
40
- )} failed with client ${
41
- client.transport.url
42
- }, trying next if available.`,
43
- error
44
- )
45
- if (i === clients.length - 1) {
46
- throw error
47
- }
48
- }
48
+ if (prop === "extend") {
49
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
50
+ return (fn: any) => {
51
+ const modifications = fn(proxyClient)
52
+ for (const [key, modification] of Object.entries(
53
+ modifications
54
+ )) {
55
+ if (typeof modification === "function") {
56
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
57
+ ;(proxyClient as any)[key] = async (
58
+ // biome-ignore lint/suspicious/noExplicitAny: expected any
59
+ ...args: any[]
60
+ ) => {
61
+ return modification(...args)
49
62
  }
63
+ } else {
64
+ console.error(
65
+ `Expected a function for modification of ${key}, but received type ${typeof modification}`
66
+ )
50
67
  }
51
68
  }
52
- // For non-function properties, return the first defined value found
53
- return value
69
+ return proxyClient
54
70
  }
55
71
  }
56
- // If no clients have a defined value for the property, return undefined
57
- return undefined
72
+
73
+ const value = Reflect.get(_target, prop, receiver)
74
+ if (typeof value === "function") {
75
+ return createFallbackMethod(prop)
76
+ }
77
+ return value
58
78
  }
59
79
  })
60
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.2.15",
3
+ "version": "5.2.16",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -9,13 +9,7 @@
9
9
  "type": "module",
10
10
  "sideEffects": false,
11
11
  "description": "A utility library for working with ERC-4337",
12
- "keywords": [
13
- "ethereum",
14
- "erc-4337",
15
- "eip-4337",
16
- "paymaster",
17
- "bundler"
18
- ],
12
+ "keywords": ["ethereum", "erc-4337", "eip-4337", "paymaster", "bundler"],
19
13
  "license": "MIT",
20
14
  "files": [
21
15
  "_esm",
@@ -91,30 +85,14 @@
91
85
  },
92
86
  "typesVersions": {
93
87
  "*": {
94
- "accounts": [
95
- "./_types/accounts/index.d.ts"
96
- ],
97
- "plugins": [
98
- "./_types/plugins/index.d.ts"
99
- ],
100
- "actions": [
101
- "./_types/actions/index.d.ts"
102
- ],
103
- "types": [
104
- "./_types/types/index.d.ts"
105
- ],
106
- "actions/kernel": [
107
- "./_types/actions/kernel/index.d.ts"
108
- ],
109
- "clients": [
110
- "./_types/clients/index.d.ts"
111
- ],
112
- "clients/kernel": [
113
- "./_types/clients/kernel/index.d.ts"
114
- ],
115
- "providers": [
116
- "./_types/providers/index.d.ts"
117
- ]
88
+ "accounts": ["./_types/accounts/index.d.ts"],
89
+ "plugins": ["./_types/plugins/index.d.ts"],
90
+ "actions": ["./_types/actions/index.d.ts"],
91
+ "types": ["./_types/types/index.d.ts"],
92
+ "actions/kernel": ["./_types/actions/kernel/index.d.ts"],
93
+ "clients": ["./_types/clients/index.d.ts"],
94
+ "clients/kernel": ["./_types/clients/kernel/index.d.ts"],
95
+ "providers": ["./_types/providers/index.d.ts"]
118
96
  }
119
97
  },
120
98
  "peerDependencies": {