From 95a26cecbab5c222fc37e9f54538fadf0b73e932 Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Mon, 24 Nov 2025 20:24:37 +0530 Subject: [PATCH] feat: Introduce PYLON_IDENTITY_SECRET environment variable (#9656) --- frontend/example.env | 1 + frontend/package.json | 2 ++ frontend/src/AppRoutes/index.tsx | 11 +++++++++++ frontend/webpack.config.js | 1 + frontend/webpack.config.prod.js | 1 + frontend/yarn.lock | 16 +++++++++++++--- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/frontend/example.env b/frontend/example.env index d875044f96..1e9109ceb9 100644 --- a/frontend/example.env +++ b/frontend/example.env @@ -3,5 +3,6 @@ BUNDLE_ANALYSER="true" FRONTEND_API_ENDPOINT="http://localhost:8080/" PYLON_APP_ID="pylon-app-id" APPCUES_APP_ID="appcess-app-id" +PYLON_IDENTITY_SECRET="pylon-identity-secret" CI="1" \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 5398666d49..a04a890755 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -83,6 +83,7 @@ "color": "^4.2.1", "color-alpha": "1.1.3", "cross-env": "^7.0.3", + "crypto-js": "4.2.0", "css-loader": "5.0.0", "css-minimizer-webpack-plugin": "5.0.1", "d3-hierarchy": "3.1.2", @@ -186,6 +187,7 @@ "@types/color": "^3.0.3", "@types/compression-webpack-plugin": "^9.0.0", "@types/copy-webpack-plugin": "^8.0.1", + "@types/crypto-js": "4.2.2", "@types/dompurify": "^2.4.0", "@types/event-source-polyfill": "^1.0.0", "@types/fontfaceobserver": "2.1.0", diff --git a/frontend/src/AppRoutes/index.tsx b/frontend/src/AppRoutes/index.tsx index 754646e6a5..b5ec3533b1 100644 --- a/frontend/src/AppRoutes/index.tsx +++ b/frontend/src/AppRoutes/index.tsx @@ -12,6 +12,8 @@ import { FeatureKeys } from 'constants/features'; import { LOCALSTORAGE } from 'constants/localStorage'; import ROUTES from 'constants/routes'; import AppLayout from 'container/AppLayout'; +import Hex from 'crypto-js/enc-hex'; +import HmacSHA256 from 'crypto-js/hmac-sha256'; import { KeyboardHotkeysProvider } from 'hooks/hotkeys/useKeyboardHotkeys'; import { useThemeConfig } from 'hooks/useDarkMode'; import { useGetTenantLicense } from 'hooks/useGetTenantLicense'; @@ -268,11 +270,20 @@ function App(): JSX.Element { !showAddCreditCardModal && (isCloudUser || isEnterpriseSelfHostedUser) ) { + const email = user.email || ''; + const secret = process.env.PYLON_IDENTITY_SECRET || ''; + let emailHash = ''; + + if (email && secret) { + emailHash = HmacSHA256(email, Hex.parse(secret)).toString(Hex); + } + window.pylon = { chat_settings: { app_id: process.env.PYLON_APP_ID, email: user.email, name: user.displayName || user.email, + email_hash: emailHash, }, }; } diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index 1fab72625a..ba68e0aee5 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -40,6 +40,7 @@ const plugins = [ FRONTEND_API_ENDPOINT: process.env.FRONTEND_API_ENDPOINT, WEBSOCKET_API_ENDPOINT: process.env.WEBSOCKET_API_ENDPOINT, PYLON_APP_ID: process.env.PYLON_APP_ID, + PYLON_IDENTITY_SECRET: process.env.PYLON_IDENTITY_SECRET, APPCUES_APP_ID: process.env.APPCUES_APP_ID, POSTHOG_KEY: process.env.POSTHOG_KEY, USERPILOT_KEY: process.env.USERPILOT_KEY, diff --git a/frontend/webpack.config.prod.js b/frontend/webpack.config.prod.js index 9cfe202cfa..30a84c9c88 100644 --- a/frontend/webpack.config.prod.js +++ b/frontend/webpack.config.prod.js @@ -50,6 +50,7 @@ const plugins = [ FRONTEND_API_ENDPOINT: process.env.FRONTEND_API_ENDPOINT, WEBSOCKET_API_ENDPOINT: process.env.WEBSOCKET_API_ENDPOINT, PYLON_APP_ID: process.env.PYLON_APP_ID, + PYLON_IDENTITY_SECRET: process.env.PYLON_IDENTITY_SECRET, APPCUES_APP_ID: process.env.APPCUES_APP_ID, POSTHOG_KEY: process.env.POSTHOG_KEY, USERPILOT_KEY: process.env.USERPILOT_KEY, diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 27afdaa129..9bb70126de 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -4685,6 +4685,11 @@ tapable "^2.0.0" webpack "^5.1.0" +"@types/crypto-js@4.2.2": + version "4.2.2" + resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.2.2.tgz#771c4a768d94eb5922cc202a3009558204df0cea" + integrity sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ== + "@types/d3-array@3.0.3": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.0.3.tgz#87d990bf504d14ad6b16766979d04e943c046dac" @@ -7742,6 +7747,11 @@ cross-spawn@7.0.5, cross-spawn@^6.0.5, cross-spawn@^7.0.1, cross-spawn@^7.0.2, c shebang-command "^2.0.0" which "^2.0.1" +crypto-js@4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" + integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== + css-box-model@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/css-box-model/-/css-box-model-1.2.1.tgz#59951d3b81fd6b2074a62d49444415b0d2b4d7c1" @@ -11242,9 +11252,9 @@ is-wsl@^3.1.0: is-inside-container "^1.0.0" is@^3.1.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/is/-/is-3.3.0.tgz#61cff6dd3c4193db94a3d62582072b44e5645d79" - integrity sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg== + version "3.3.2" + resolved "https://registry.yarnpkg.com/is/-/is-3.3.2.tgz#dfc285f4937f08564675f2f17cc6ac6cd2113ace" + integrity sha512-a2xr4E3s1PjDS8ORcGgXpWx6V+liNs+O3JRD2mb9aeugD7rtkkZ0zgLdYgw0tWsKhsdiezGYptSiMlVazCBTuQ== isarray@0.0.1: version "0.0.1"