Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove global override of fetch #1194

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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