From 695220e75bc43834a7700cfc5491a7eebd324947 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Mon, 30 Oct 2023 23:34:34 +0200 Subject: [PATCH] fix: add check for process global to exist (#1195) --- .changeset/funny-jars-camp.md | 8 ++++++++ packages/accounts/src/account.ts | 2 +- packages/near-api-js/src/connect.ts | 2 +- packages/providers/src/fetch_json.ts | 2 +- packages/providers/src/json-rpc-provider.ts | 2 +- packages/utils/src/errors/errors.ts | 2 +- packages/utils/src/logging.ts | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .changeset/funny-jars-camp.md diff --git a/.changeset/funny-jars-camp.md b/.changeset/funny-jars-camp.md new file mode 100644 index 0000000000..55be951fa8 --- /dev/null +++ b/.changeset/funny-jars-camp.md @@ -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 diff --git a/packages/accounts/src/account.ts b/packages/accounts/src/account.ts index 2206212a74..3ae6c38abd 100644 --- a/packages/accounts/src/account.ts +++ b/packages/accounts/src/account.ts @@ -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({ diff --git a/packages/near-api-js/src/connect.ts b/packages/near-api-js/src/connect.ts index b35e2e0fea..f46971eee1 100644 --- a/packages/near-api-js/src/connect.ts +++ b/packages/near-api-js/src/connect.ts @@ -54,7 +54,7 @@ export async function connect(config: ConnectConfig): Promise { 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()}`); } } diff --git a/packages/providers/src/fetch_json.ts b/packages/providers/src/fetch_json.ts index 839df66e31..bef1a029dc 100644 --- a/packages/providers/src/fetch_json.ts +++ b/packages/providers/src/fetch_json.ts @@ -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 { let connectionInfo: ConnectionInfo = { url: null }; diff --git a/packages/providers/src/json-rpc-provider.ts b/packages/providers/src/json-rpc-provider.ts index ed379a5a9a..540e89c27b 100644 --- a/packages/providers/src/json-rpc-provider.ts +++ b/packages/providers/src/json-rpc-provider.ts @@ -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; diff --git a/packages/utils/src/errors/errors.ts b/packages/utils/src/errors/errors.ts index d6c9c5bbc3..8173ea2e65 100644 --- a/packages/utils/src/errors/errors.ts +++ b/packages/utils/src/errors/errors.ts @@ -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); } } diff --git a/packages/utils/src/logging.ts b/packages/utils/src/logging.ts index 5024a7559f..4b134562b7 100644 --- a/packages/utils/src/logging.ts +++ b/packages/utils/src/logging.ts @@ -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