@snapshot-labs/snapshot.js 0.14.5 → 0.14.6
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/snapshot.cjs.js +290 -232
- package/dist/snapshot.esm.js +281 -223
- package/dist/snapshot.min.js +23 -23
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils.d.ts +36 -0
- package/package.json +1 -1
- package/src/sign/index.ts +1 -1
- package/src/utils.ts +70 -2
package/dist/src/index.d.ts
CHANGED
|
@@ -812,6 +812,7 @@ declare const _default: {
|
|
|
812
812
|
utils: {
|
|
813
813
|
call: typeof import("./utils").call;
|
|
814
814
|
multicall: typeof import("./multicall").multicall;
|
|
815
|
+
fetch: typeof import("./utils").fetch;
|
|
815
816
|
subgraphRequest: typeof import("./utils").subgraphRequest;
|
|
816
817
|
ipfsGet: typeof import("./utils").ipfsGet;
|
|
817
818
|
getUrl: typeof import("./utils").getUrl;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -16,6 +16,41 @@ interface Strategy {
|
|
|
16
16
|
export declare function call(provider: any, abi: any[], call: any[], options?: any): Promise<any>;
|
|
17
17
|
export declare function subgraphRequest(url: string, query: any, options?: any): Promise<any>;
|
|
18
18
|
export declare function getUrl(uri: any, gateway?: string): any;
|
|
19
|
+
interface FetchOptions extends RequestInit {
|
|
20
|
+
timeout?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Enhanced fetch with timeout support - drop-in replacement for native fetch
|
|
24
|
+
*
|
|
25
|
+
* @param url - The URL to fetch
|
|
26
|
+
* @param options - Fetch options with optional timeout
|
|
27
|
+
* @param options.timeout - Request timeout in milliseconds (default: 30000ms). Set to 0 to disable timeout.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise that resolves to the Response object
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} Throws timeout error if request exceeds the specified timeout duration
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Uses default 30s timeout
|
|
36
|
+
* const response = await fetch('https://api.example.com/data');
|
|
37
|
+
*
|
|
38
|
+
* // Custom 5s timeout
|
|
39
|
+
* const response = await fetch('https://api.example.com/data', { timeout: 5000 });
|
|
40
|
+
*
|
|
41
|
+
* // Disable timeout
|
|
42
|
+
* const response = await fetch('https://api.example.com/data', { timeout: 0 });
|
|
43
|
+
*
|
|
44
|
+
* // With additional fetch options
|
|
45
|
+
* const response = await fetch('https://api.example.com/data', {
|
|
46
|
+
* timeout: 10000,
|
|
47
|
+
* method: 'POST',
|
|
48
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
49
|
+
* body: JSON.stringify({ key: 'value' })
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function fetch(url: string, options?: FetchOptions): Promise<Response>;
|
|
19
54
|
export declare function getJSON(uri: any, options?: any): Promise<any>;
|
|
20
55
|
export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string): Promise<any>;
|
|
21
56
|
export declare function sendTransaction(web3: any, contractAddress: string, abi: any[], action: string, params: any[], overrides?: {}): Promise<any>;
|
|
@@ -43,6 +78,7 @@ export { getDelegatesBySpace, SNAPSHOT_SUBGRAPH_URL };
|
|
|
43
78
|
declare const _default: {
|
|
44
79
|
call: typeof call;
|
|
45
80
|
multicall: typeof multicall;
|
|
81
|
+
fetch: typeof fetch;
|
|
46
82
|
subgraphRequest: typeof subgraphRequest;
|
|
47
83
|
ipfsGet: typeof ipfsGet;
|
|
48
84
|
getUrl: typeof getUrl;
|
package/package.json
CHANGED
package/src/sign/index.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import crossFetch from 'cross-fetch';
|
|
2
2
|
import { Contract } from '@ethersproject/contracts';
|
|
3
3
|
import { getAddress, isAddress } from '@ethersproject/address';
|
|
4
4
|
import { parseUnits } from '@ethersproject/units';
|
|
@@ -314,9 +314,76 @@ export function getUrl(uri, gateway = gateways[0]) {
|
|
|
314
314
|
return uri;
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
interface FetchOptions extends RequestInit {
|
|
318
|
+
timeout?: number;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Enhanced fetch with timeout support - drop-in replacement for native fetch
|
|
323
|
+
*
|
|
324
|
+
* @param url - The URL to fetch
|
|
325
|
+
* @param options - Fetch options with optional timeout
|
|
326
|
+
* @param options.timeout - Request timeout in milliseconds (default: 30000ms). Set to 0 to disable timeout.
|
|
327
|
+
*
|
|
328
|
+
* @returns Promise that resolves to the Response object
|
|
329
|
+
*
|
|
330
|
+
* @throws {Error} Throws timeout error if request exceeds the specified timeout duration
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* // Uses default 30s timeout
|
|
335
|
+
* const response = await fetch('https://api.example.com/data');
|
|
336
|
+
*
|
|
337
|
+
* // Custom 5s timeout
|
|
338
|
+
* const response = await fetch('https://api.example.com/data', { timeout: 5000 });
|
|
339
|
+
*
|
|
340
|
+
* // Disable timeout
|
|
341
|
+
* const response = await fetch('https://api.example.com/data', { timeout: 0 });
|
|
342
|
+
*
|
|
343
|
+
* // With additional fetch options
|
|
344
|
+
* const response = await fetch('https://api.example.com/data', {
|
|
345
|
+
* timeout: 10000,
|
|
346
|
+
* method: 'POST',
|
|
347
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
348
|
+
* body: JSON.stringify({ key: 'value' })
|
|
349
|
+
* });
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
export async function fetch(
|
|
353
|
+
url: string,
|
|
354
|
+
options: FetchOptions = {}
|
|
355
|
+
): Promise<Response> {
|
|
356
|
+
const { timeout = 30000, ...fetchOptions } = options;
|
|
357
|
+
|
|
358
|
+
if (timeout > 0) {
|
|
359
|
+
const controller = new AbortController();
|
|
360
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
const response = await crossFetch(url, {
|
|
364
|
+
...fetchOptions,
|
|
365
|
+
signal: controller.signal
|
|
366
|
+
});
|
|
367
|
+
return response;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
370
|
+
throw new Error(`Request timeout after ${timeout}ms`);
|
|
371
|
+
}
|
|
372
|
+
throw error;
|
|
373
|
+
} finally {
|
|
374
|
+
clearTimeout(timeoutId);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
379
|
+
const { signal, ...cleanFetchOptions } = fetchOptions;
|
|
380
|
+
return crossFetch(url, cleanFetchOptions);
|
|
381
|
+
}
|
|
382
|
+
|
|
317
383
|
export async function getJSON(uri, options: any = {}) {
|
|
318
384
|
const url = getUrl(uri, options.gateways);
|
|
319
|
-
|
|
385
|
+
const response = await fetch(url, options);
|
|
386
|
+
return response.json();
|
|
320
387
|
}
|
|
321
388
|
|
|
322
389
|
export async function ipfsGet(
|
|
@@ -823,6 +890,7 @@ export { getDelegatesBySpace, SNAPSHOT_SUBGRAPH_URL };
|
|
|
823
890
|
export default {
|
|
824
891
|
call,
|
|
825
892
|
multicall,
|
|
893
|
+
fetch,
|
|
826
894
|
subgraphRequest,
|
|
827
895
|
ipfsGet,
|
|
828
896
|
getUrl,
|