Skip to content

Commit

Permalink
fix: remove global override of fetch
Browse files Browse the repository at this point in the history
Ticket: 1193
  • Loading branch information
andrew-scott-fischer committed Oct 27, 2023
1 parent 53ba3f2 commit c1d9090
Show file tree
Hide file tree
Showing 4 changed files with 1,670 additions and 1,523 deletions.
6 changes: 6 additions & 0 deletions .changeset/wet-jars-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"near-api-js": patch
"@near-js/providers": patch
---

fixes override of global fetch property
3 changes: 0 additions & 3 deletions packages/near-api-js/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
Loading

0 comments on commit c1d9090

Please sign in to comment.