From d104afcee7949ef31347cf152b49fb5695f8c8c8 Mon Sep 17 00:00:00 2001 From: Sim Boon Long Date: Mon, 8 Nov 2021 16:33:46 +0800 Subject: [PATCH] fix: warn provider message (#208) --- package.json | 2 +- src/common/messages.ts | 1 + src/common/utils.ts | 6 ++---- src/verifiers/verificationBuilder.ts | 5 ++--- 4 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 src/common/messages.ts diff --git a/package.json b/package.json index 10d3ab73..8202f2a5 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "clean": "rm -rf dist/", "commit": "git-cz", "commit:retry": "npm run commit -- --retry", - "test": "jest", + "test": "NODE_OPTIONS=--max-old-space-size=2048 jest", "test:watch": "jest --watch", "lint": "eslint . --ext .ts --max-warnings 0", "lint:fix": "npm run lint -- --fix", diff --git a/src/common/messages.ts b/src/common/messages.ts new file mode 100644 index 00000000..533ffcb0 --- /dev/null +++ b/src/common/messages.ts @@ -0,0 +1 @@ +export const warnProvider = `You are falling back to oa-verify default configuration, which is not suitable for production environment. It is highly recommended that you configure and provide your own API key. Refer to https://github.com/Open-Attestation/oa-verify#provider`; diff --git a/src/common/utils.ts b/src/common/utils.ts index ec119365..d771f0d8 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -19,6 +19,7 @@ import { OpenAttestationEthereumDocumentStoreStatusCode, OpenAttestationEthereumTokenRegistryStatusCode, } from "../types/error"; +import { warnProvider } from "../common/messages"; export const getDefaultProvider = (options: VerificationBuilderOptionsWithNetwork): providers.Provider => { const network = options.network || process.env.PROVIDER_NETWORK || "homestead"; @@ -64,10 +65,7 @@ export const generateProvider = (options?: ProviderDetails): providers.Provider const url = options?.url || process.env.PROVIDER_ENDPOINT_URL || ""; const apiKey = options?.apiKey || (provider === "infura" && process.env.INFURA_API_KEY) || process.env.PROVIDER_API_KEY || ""; - !apiKey && - console.warn( - "You are using oa-verify default configuration for provider, which is not suitable for production environment. Please make sure that you configured the library correctly." - ); + !apiKey && console.warn(warnProvider); if (!!options && Object.keys(options).length === 1 && url) { return new providers.JsonRpcProvider(url); diff --git a/src/verifiers/verificationBuilder.ts b/src/verifiers/verificationBuilder.ts index 4b07c475..159bad24 100644 --- a/src/verifiers/verificationBuilder.ts +++ b/src/verifiers/verificationBuilder.ts @@ -7,6 +7,7 @@ import { DocumentsToVerify, } from "../types/core"; import { getProvider } from "../common/utils"; +import { warnProvider } from "../common/messages"; // keeping the following code for posterity. If we want the function below to return better types, we can use the following // type PromiseValue = T extends Promise ? U : never; @@ -29,9 +30,7 @@ export const verificationBuilder = >( !process.env.PROVIDER_API_KEY ) { displayWarning = false; - console.warn( - "You are using oa-verify default configuration, which is not suitable for production environment. Please make sure that you configured the library correctly." - ); + console.warn(warnProvider); } const verifierOptions: VerifierOptions = { provider: getProvider(builderOptions),