From 89667fccb3a32cb8aba31f850a32741670ecc404 Mon Sep 17 00:00:00 2001 From: Andrew Fischer Date: Fri, 27 Oct 2023 12:45:55 -0700 Subject: [PATCH] fix: remove global override of `fetch` Ticket: 1193 --- .changeset/wet-jars-attend.md | 6 ++++++ packages/near-api-js/src/connect.ts | 3 --- packages/providers/src/fetch_json.ts | 5 +---- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 .changeset/wet-jars-attend.md diff --git a/.changeset/wet-jars-attend.md b/.changeset/wet-jars-attend.md new file mode 100644 index 0000000000..96a008cc77 --- /dev/null +++ b/.changeset/wet-jars-attend.md @@ -0,0 +1,6 @@ +--- +"near-api-js": patch +"@near-js/providers": patch +--- + +fixes override of global fetch property diff --git a/packages/near-api-js/src/connect.ts b/packages/near-api-js/src/connect.ts index cc4f36e3fc..b35e2e0fea 100644 --- a/packages/near-api-js/src/connect.ts +++ b/packages/near-api-js/src/connect.ts @@ -25,11 +25,8 @@ import { readKeyFile } from './key_stores/unencrypted_file_system_keystore'; import { InMemoryKeyStore, MergeKeyStore } from './key_stores'; import { Near, NearConfig } from './near'; -import fetch from './utils/setup-node-fetch'; import { logWarning } from './utils'; -global.fetch = fetch; - export interface ConnectConfig extends NearConfig { /** * Initialize an {@link key_stores/in_memory_key_store!InMemoryKeyStore} by reading the file at keyPath. diff --git a/packages/providers/src/fetch_json.ts b/packages/providers/src/fetch_json.ts index 386143c14c..839df66e31 100644 --- a/packages/providers/src/fetch_json.ts +++ b/packages/providers/src/fetch_json.ts @@ -28,11 +28,8 @@ export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, js const response = await exponentialBackoff(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => { try { - if (!global.fetch) { - global.fetch = (await import('./fetch')).default; - } - const response = await global.fetch(connectionInfo.url, { + const response = await (global.fetch ?? (await import('./fetch')).default)(connectionInfo.url, { method: json ? 'POST' : 'GET', body: json ? json : undefined, headers: { ...connectionInfo.headers, 'Content-Type': 'application/json' }