diff --git a/.env b/.env new file mode 100644 index 000000000..29dda11a9 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +ENV_BACKEND_URL="" +ENV_LOGGING_URL="" diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c9d5c4df..725aa586c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1242,4 +1242,4 @@ ### Features -* updated Readme ([427f8fd](https://github.com/juspay/hyperswitch-web/commit/427f8fd91be58fc63b0fa4ab326d562a4caaabab)) +* updated Readme ([427f8fd](https://github.com/juspay/hyperswitch-web/commit/427f8fd91be58fc63b0fa4ab326d562a4caaabab)) \ No newline at end of file diff --git a/README.md b/README.md index a1137a51e..77477bae7 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,21 @@ Ways to get started with Hyperswitch: Before you start the local setup, you will need an understanding of few keys - -### About Env Configs +### About Env Configs for Demo App -- `HYPERSWITCH_PUBLISHABLE_KEY` - Publishable key of your Hyperswitch Account. This key will start with `pk_dev_` for local development, `pk_snd_` for sandbox and `pk_prd_` for production. -- `HYPERSWITCH_SECRET_KEY` - API key of your Hyperswitch Account -- `HYPERSWITCH_SERVER_URL` - URL of your hosted Hyperswitch Backend server or you can use our Sandbox URL (https://sandbox.hyperswitch.io) or use your backend running locally (eg. http://localhost:8080). -- `HYPERSWITCH_CLIENT_URL` - URL of your hosted Hyperswitch SDK or you can use our Sandbox URL (https://beta.hyperswitch.io/v1) or use your app running locally (eg http://localhost:9050). +- **`HYPERSWITCH_PUBLISHABLE_KEY`:** The publishable key of your Hyperswitch account. This key will start with `pk_dev_` for local development, `pk_snd_` for sandbox, and `pk_prd_` for production. + +- **`HYPERSWITCH_SECRET_KEY`:** The API key of your Hyperswitch account. + +- **`HYPERSWITCH_SERVER_URL`:** The URL of your hosted Hyperswitch backend server. Alternatively, you can use our Sandbox URL (https://sandbox.hyperswitch.io) or specify your backend running locally (e.g., http://localhost:8080). + +- **`HYPERSWITCH_CLIENT_URL`:** The URL of your hosted Hyperswitch SDK. You can also use our Sandbox URL (https://beta.hyperswitch.io/v1) or specify your app running locally (e.g., http://localhost:9050). + +### About Env Configs for SDK + +- **`ENV_BACKEND_URL`:** Sets the endpoint for all the APIs used within the SDK to interact with the backend service. If you are running your own backend service, you can configure and specify its endpoint here for local setups. + +- **`ENV_LOGGING_URL`:** Specifies a custom logging endpoint where logs generated by the SDK can be sent. This allows you to view and manage logs according to your requirements. ### Setup Node diff --git a/webpack.common.js b/webpack.common.js index ce9579d0d..e0d800850 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -1,28 +1,31 @@ const webpack = require("webpack"); const path = require("path"); +const dotenv = require("dotenv").config(); const tailwindcss = require("tailwindcss"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const CopyPlugin = require("copy-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin"); -const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; +const BundleAnalyzerPlugin = + require("webpack-bundle-analyzer").BundleAnalyzerPlugin; const { sentryWebpackPlugin } = require("@sentry/webpack-plugin"); -const sdkEnv = process.env.sdkEnv; -const envSdkUrl = process.env.envSdkUrl; -const envBackendUrl = process.env.envBackendUrl; -const envLoggingUrl = process.env.envLoggingUrl; +const sdkEnv = process.env.sdkEnv ?? "local"; +const envSdkUrl = process.env.ENV_SDK_URL ?? ""; +const envBackendUrl = process.env.ENV_BACKEND_URL ?? ""; +const envLoggingUrl = process.env.ENV_LOGGING_URL ?? ""; //git rev-parse --abbrev-ref HEAD let repoVersion = require("./package.json").version; let majorVersion = "v" + repoVersion.split(".")[0]; let repoName = require("./package.json").name; -let repoPublicPath = sdkEnv === "local" ? "" : `/${repoVersion}/${majorVersion}`; +let repoPublicPath = + sdkEnv === "local" ? "" : `/${repoVersion}/${majorVersion}`; let sdkUrl; -if (envSdkUrl === undefined) { +if (envSdkUrl.length === 0) { sdkUrl = sdkEnv === "prod" ? "https://checkout.hyperswitch.io" @@ -36,7 +39,7 @@ if (envSdkUrl === undefined) { } let backendEndPoint; -if (envBackendUrl === undefined) { +if (envBackendUrl.length === 0) { backendEndPoint = sdkEnv === "prod" ? "https://checkout.hyperswitch.io/api" @@ -50,7 +53,7 @@ if (envBackendUrl === undefined) { } let confirmEndPoint; -if (envBackendUrl === undefined) { +if (envBackendUrl.length === 0) { confirmEndPoint = sdkEnv === "prod" ? "https://api.hyperswitch.io" @@ -64,7 +67,7 @@ if (envBackendUrl === undefined) { } let logEndpoint; -if (envLoggingUrl === undefined) { +if (envLoggingUrl.length === 0) { logEndpoint = sdkEnv === "prod" ? "https://api.hyperswitch.io/logs/sdk" @@ -98,6 +101,7 @@ module.exports = (publicPath = "auto") => { clean: true, publicPath: `${repoPublicPath}/`, }, + // TODO - Can be commented for faster build in local development optimization: { sideEffects: true, minimize: true, @@ -155,6 +159,7 @@ module.exports = (publicPath = "auto") => { // new webpack.HTMLInjectPlugin({ // publicPath: JSON.stringify(repoVersion), // }), + // TODO - Can be commented if sentry not needed. sentryWebpackPlugin({ org: "sentry", project: "hyperswitch-react-sdk", diff --git a/webpack.dev.js b/webpack.dev.js index d702a8003..993c77a9d 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -1,8 +1,8 @@ const path = require("path"); +const dotenv = require("dotenv").config(); const { merge } = require("webpack-merge"); const common = require("./webpack.common.js"); - -const sdkEnv = process.env.sdkEnv; +const sdkEnv = process.env.sdkEnv ?? "local"; let backendEndPoint = sdkEnv === "prod"