Skip to content

Commit

Permalink
Merge branch 'master' into biometric-handling-null
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes authored Oct 30, 2023
2 parents e9005e4 + 695220e commit b3617f9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .changeset/funny-jars-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@near-js/accounts": patch
"near-api-js": patch
"@near-js/providers": patch
"@near-js/utils": patch
---

add check for global 'process' object
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
2 changes: 1 addition & 1 deletion packages/accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class Account {
* @param beneficiaryId The NEAR account that will receive the remaining Ⓝ balance from the account being deleted
*/
async deleteAccount(beneficiaryId: string) {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log('Deleting an account does not automatically transfer NFTs and FTs to the beneficiary address. Ensure to transfer assets before deleting.');
}
return this.signAndSendTransaction({
Expand Down
5 changes: 1 addition & 4 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 Expand Up @@ -57,7 +54,7 @@ export async function connect(config: ConnectConfig): Promise<Near> {
keyPathStore,
config.keyStore || config.deps?.keyStore
], { writeKeyStoreIndex: 1 });
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log(`Loaded master account ${accountKeyFile[0]} key from ${config.keyPath} with public key = ${keyPair.getPublicKey()}`);
}
}
Expand Down
7 changes: 2 additions & 5 deletions packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ConnectionInfo {
headers?: { [key: string]: string | number };
}

const logWarning = (...args) => !process.env['NEAR_NO_LOGS'] && console.warn(...args);
const logWarning = (...args) => !(typeof process === 'object' && process.env['NEAR_NO_LOGS']) && console.warn(...args);

export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any> {
let connectionInfo: ConnectionInfo = { url: null };
Expand All @@ -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
2 changes: 1 addition & 1 deletion packages/providers/src/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class JsonRpcProvider extends Provider {
return response;
} catch (error) {
if (error.type === 'TimeoutError') {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.warn(`Retrying request to ${method} as it has timed out`, params);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/errors/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function logWarning(...args: any[]): void {
if (!process.env['NEAR_NO_LOGS']){
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])){
console.warn(...args);
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FinalExecutionOutcome } from '@near-js/types';

import { parseRpcError } from './errors';

const SUPPRESS_LOGGING = !!process.env.NEAR_NO_LOGS;
const SUPPRESS_LOGGING = !!(typeof process === 'object' && process.env.NEAR_NO_LOGS);

/**
* Parse and print details from a query execution response
Expand Down

0 comments on commit b3617f9

Please sign in to comment.