Skip to content

Commit

Permalink
fix: warn provider message (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
simboonlong authored Nov 8, 2021
1 parent b056e0b commit d104afc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/common/messages.ts
Original file line number Diff line number Diff line change
@@ -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`;
6 changes: 2 additions & 4 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/verifiers/verificationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T extends Promise<infer U> ? U : never;
Expand All @@ -29,9 +30,7 @@ export const verificationBuilder = <T extends Verifier<any>>(
!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),
Expand Down

0 comments on commit d104afc

Please sign in to comment.