diff --git a/.env b/.env index 29dda11a..d490ee35 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ ENV_BACKEND_URL="" ENV_LOGGING_URL="" +SDK_ENV="local" \ No newline at end of file diff --git a/README.md b/README.md index 4a3e2f8c..f1ea61b9 100644 --- a/README.md +++ b/README.md @@ -177,12 +177,12 @@ In the [`webpack.common.js`](./webpack.common.js) file, you would have to enable ```javascipt let logEndpoint = - sdkEnv === "prod" + SDK_ENV === "prod" ? "" : ""; // Set this to true to enable logging -let enableLogging = true; +let ENABLE_LOGGING = true; // Choose from DEBUG, INFO, WARNING, ERROR, SILENT let loggingLevel = "DEBUG"; diff --git a/package.json b/package.json index b4dd4415..df036abd 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,10 @@ }, "scripts": { "build": "webpack --config webpack.common.js", - "build:integ": "cross-env sdkEnv=integ enableLogging=false webpack --config webpack.common.js", + "build:integ": "cross-env webpack --config webpack.common.js", "build:playground": "npm run setup:playground && npm run build", - "build:prod": "cross-env sdkEnv=prod enableLogging=true webpack --config webpack.common.js", - "build:sandbox": "cross-env sdkEnv=sandbox enableLogging=true webpack --config webpack.common.js", + "build:prod": "cross-env webpack --config webpack.common.js", + "build:sandbox": "cross-env webpack --config webpack.common.js", "deploy-to-s3": "node ./scripts/pushToS3.js", "postinstall": "cd Hyperswitch-React-Demo-App && npm i", "prepare": "husky install", @@ -29,7 +29,7 @@ "re:format": "rescript format -all", "re:start": "rescript -w", "setup:playground": "npm run postinstall && cd Hyperswitch-React-Demo-App && node promptScript.js", - "start": "cross-env sdkEnv=local enableLogging=false webpack serve --config webpack.dev.js", + "start": "cross-env webpack serve --config webpack.dev.js", "start:playground": "npm run setup:playground && npm run start", "test": "cd cypress-tests && npm run cypress:run", "test:hooks": "npx eslint src/" diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res index 2758da9e..d8da64cd 100644 --- a/src/Payments/CardPayment.res +++ b/src/Payments/CardPayment.res @@ -125,6 +125,8 @@ let make = ( ~isGuestCustomer, ) + Console.log2(">>>> Logs Debug >>>>", (GlobalVars.enableLogging, GlobalVars.logEndpoint)) + let submitCallback = React.useCallback((ev: Window.event) => { let json = ev.data->safeParse let confirm = json->getDictFromJson->ConfirmType.itemToObjMapper diff --git a/webpack.common.js b/webpack.common.js index 18a9015f..7648cc0c 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -13,8 +13,8 @@ const AddReactDisplayNamePlugin = require("babel-plugin-add-react-displayname"); const getEnvVariable = (variable, defaultValue) => process.env[variable] ?? defaultValue; -const sdkEnv = getEnvVariable("sdkEnv", "local"); -const enableLogging = getEnvVariable("enableLogging", "false") === "true"; +const SDK_ENV = getEnvVariable("SDK_ENV", "local"); +const ENABLE_LOGGING = getEnvVariable("ENABLE_LOGGING", "false") === "true"; const envSdkUrl = getEnvVariable("ENV_SDK_URL", ""); const envBackendUrl = getEnvVariable("ENV_BACKEND_URL", ""); const envLoggingUrl = getEnvVariable("ENV_LOGGING_URL", ""); @@ -23,7 +23,7 @@ const repoVersion = require("./package.json").version; const majorVersion = "v" + repoVersion.split(".")[0]; const repoName = require("./package.json").name; const repoPublicPath = - sdkEnv === "local" ? "" : `/web/${repoVersion}/${majorVersion}`; + SDK_ENV === "local" ? "" : `/web/${repoVersion}/${majorVersion}`; const getSdkUrl = (env, customUrl) => { if (customUrl) return customUrl; @@ -36,9 +36,9 @@ const getSdkUrl = (env, customUrl) => { return urls[env] || urls.local; }; -const sdkUrl = getSdkUrl(sdkEnv, envSdkUrl); +const sdkUrl = getSdkUrl(SDK_ENV, envSdkUrl); const getEnvironmentDomain = (prodDomain, integDomain, defaultDomain) => { - switch (sdkEnv) { + switch (SDK_ENV) { case "prod": return prodDomain; case "integ": @@ -82,7 +82,7 @@ module.exports = (publicPath = "auto") => { logEndpoint: JSON.stringify(logEndpoint), sentryDSN: JSON.stringify(process.env.SENTRY_DSN), sentryScriptUrl: JSON.stringify(process.env.SENTRY_SCRIPT_URL), - enableLogging: enableLogging, + enableLogging: ENABLE_LOGGING, loggingLevel: JSON.stringify(loggingLevel), maxLogsPushedPerEventName: JSON.stringify(maxLogsPushedPerEventName), }), @@ -129,18 +129,18 @@ module.exports = (publicPath = "auto") => { } return { - mode: sdkEnv === "local" ? "development" : "production", - devtool: sdkEnv === "local" ? "eval-source-map" : "source-map", + mode: SDK_ENV === "local" ? "development" : "production", + devtool: SDK_ENV === "local" ? "eval-source-map" : "source-map", output: { path: - sdkEnv && sdkEnv !== "local" - ? path.resolve(__dirname, "dist", sdkEnv) + SDK_ENV && SDK_ENV !== "local" + ? path.resolve(__dirname, "dist", SDK_ENV) : path.resolve(__dirname, "dist"), clean: true, publicPath: `${repoPublicPath}/`, }, optimization: - sdkEnv === "local" + SDK_ENV === "local" ? {} : { sideEffects: true, diff --git a/webpack.dev.js b/webpack.dev.js index 95ea97ad..d878120c 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -3,7 +3,7 @@ require("dotenv").config(); const { merge } = require("webpack-merge"); const common = require("./webpack.common.js"); -const sdkEnv = process.env.sdkEnv ?? "local"; +const SDK_ENV = process.env.SDK_ENV ?? "local"; const endpointMap = { prod: "https://api.hyperswitch.io/payments", @@ -12,7 +12,7 @@ const endpointMap = { local: "https://sandbox.hyperswitch.io/payments", // Default or local environment endpoint }; -const backendEndPoint = endpointMap[sdkEnv] || endpointMap.local; +const backendEndPoint = endpointMap[SDK_ENV] || endpointMap.local; const devServer = { static: {