From 8f5c09888f92744e6e9a28a30d2d4b24f6b76f1e Mon Sep 17 00:00:00 2001 From: deetz99 Date: Fri, 10 Jan 2025 17:38:30 -0800 Subject: [PATCH 01/13] sbc messenger draft --- strr-base-web/app/app.config.ts | 4 + .../app/plugins/sbc-web-messenger.client.ts | 92 +++++++++++++++++++ .../app/types/strr-base-app-config.d.ts | 22 +++++ strr-base-web/nuxt.config.ts | 5 +- strr-host-pm-web/.env.example | 5 + strr-host-pm-web/app/app.config.ts | 4 + strr-host-pm-web/app/pages/application.vue | 1 - strr-host-pm-web/devops/vaults.env | 5 + strr-host-pm-web/nuxt.config.ts | 4 +- 9 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 strr-base-web/app/plugins/sbc-web-messenger.client.ts diff --git a/strr-base-web/app/app.config.ts b/strr-base-web/app/app.config.ts index 9b17c8d3e..8dbeb5107 100644 --- a/strr-base-web/app/app.config.ts +++ b/strr-base-web/app/app.config.ts @@ -20,6 +20,10 @@ export default defineAppConfig({ hrefRtcKey: '' } } + }, + sbcWebMsg: { + enable: true, + allowedRoutes: undefined } }, ui: { diff --git a/strr-base-web/app/plugins/sbc-web-messenger.client.ts b/strr-base-web/app/plugins/sbc-web-messenger.client.ts new file mode 100644 index 000000000..dfa82ce42 --- /dev/null +++ b/strr-base-web/app/plugins/sbc-web-messenger.client.ts @@ -0,0 +1,92 @@ +// TODO: get ld flag working, organize plugin, comments, test, etc +export default defineNuxtPlugin(async () => { + const { ldClient, getStoredFlag } = useConnectLaunchdarklyStore() + await ldClient?.waitUntilReady() + const rtc = useRuntimeConfig().public + const msgConfig = useAppConfig().strrBaseLayer.sbcWebMsg + + const ldFlag = getStoredFlag('enable-sbc-web-messenger') + + const genesysUrl = rtc.genesysUrl + const environmentKey = rtc.genesysEnvironmentKey + const deploymentKey = rtc.genesysDeploymentKey + + if (!genesysUrl || !environmentKey || !deploymentKey) { + console.warn('SBC Web Messenger configuration is incomplete. SBC Web Messenger will not be initialized.') + return + } + + const initGenesys = () => { + if (!msgConfig.enable || !ldFlag) { + console.warn('SBC Web Messenger has been disabled.') + return + } + + // prevent duplicate + if (window._genesysJs) { + console.warn('SBC Web Messenger has already been initialized.') + return + } + + // check if exists already + const scriptExists = document.querySelector(`script[src="${genesysUrl}"]`) + if (scriptExists) { + console.warn('Genesys script already exists in the document.') + return + } + + window._genesysJs = 'Genesys' + window.Genesys = window.Genesys || function () { + (window.Genesys.q = window.Genesys.q || []).push(arguments) + } + window.Genesys.t = Date.now() + window.Genesys.c = { + environment: 'prod-cac1', + deploymentId: '1c8e851a-5bc8-4d50-bc7b-2f6365e04124' + } + const ys = document.createElement('script') + ys.async = true + ys.src = genesysUrl + // ys.charset = 'utf-8'; // Deprecated + ys.onload = () => { + console.info('SBC Web Messenger script loaded successfully.') + } + ys.onerror = (error) => { + console.error('Failed to load SBC Web Messenger script:', error) + } + document.head.appendChild(ys) + localStorage.removeItem('_actmu') + } + + const removeGenesys = () => { + const script = document.querySelector(`script[src="${genesysUrl}"]`) + if (script) { + script.remove() + } + + // clean up // TODO: cleanup + // delete window.Genesys + // delete window._genesysJs + localStorage.removeItem('_actmu') + } + + const router = useRouter() + + const allowedRoutes = useAppConfig().strrBaseLayer.sbcWebMsg.allowedRoutes + + const isRouteAllowed = (path: string): boolean => { + if (allowedRoutes === undefined) { + return true + } + return allowedRoutes.some(route => path.includes(route)) + } + + router.beforeEach((to, from, next) => { + if (isRouteAllowed(to.path)) { + initGenesys() + } else { + removeGenesys() + } + next() + }) +}) diff --git a/strr-base-web/app/types/strr-base-app-config.d.ts b/strr-base-web/app/types/strr-base-app-config.d.ts index 8d74c326c..5a0ee348e 100644 --- a/strr-base-web/app/types/strr-base-app-config.d.ts +++ b/strr-base-web/app/types/strr-base-app-config.d.ts @@ -15,6 +15,10 @@ declare module 'nuxt/schema' { }, feeWidget?: { itemLabelTooltip: Record // typeCode + }, + sbcWebMsg: { + enable: boolean, + allowedRoutes: string[] | undefined } } } @@ -37,6 +41,24 @@ declare module 'nuxt/schema' { }, feeWidget?: { itemLabelTooltip: Record // typeCode + }, + sbcWebMsg: { + enable: boolean, + allowedRoutes: string[] | undefined + } + } + } +} + +declare global { + interface Window { + _genesysJs: string + Genesys: { + q?: any[] + t?: number + c?: { + environment: string + deploymentId: string } } } diff --git a/strr-base-web/nuxt.config.ts b/strr-base-web/nuxt.config.ts index 958fdfea3..a2e5aecf8 100644 --- a/strr-base-web/nuxt.config.ts +++ b/strr-base-web/nuxt.config.ts @@ -90,7 +90,10 @@ export default defineNuxtConfig({ version: `STRR Base UI v${process.env.npm_package_version}`, housingStrrUrl: process.env.NUXT_REGISTRY_HOME_URL, // TODO: update to NUXT_HOUSING_STRR_URL once we get the housing strr url set declineTosRedirectUrl: process.env.NUXT_DECLINE_TOS_REDIRECT_URL, - bcGovStrrUrl: process.env.NUXT_BCGOV_STRR_URL + bcGovStrrUrl: process.env.NUXT_BCGOV_STRR_URL, + genesysUrl: process.env.NUXT_GENESYS_URL, + genesysEnvironmentKey: process.env.NUXT_GENESYS_ENVIRONMENT_KEY, + genesysDeploymentKey: process.env.NUXT_GENESYS_DEPLOYMENT_KEY // set by layer - still required in .env // keycloakAuthUrl - NUXT_KEYCLOAK_AUTH_URL // keycloakClientId - NUXT_KEYCLOAK_CLIENTID diff --git a/strr-host-pm-web/.env.example b/strr-host-pm-web/.env.example index 9fc573b3f..2c00e523d 100644 --- a/strr-host-pm-web/.env.example +++ b/strr-host-pm-web/.env.example @@ -29,6 +29,11 @@ NUXT_BCGOV_STRR_URL="https://www.gov.bc.ca/STRRegistry" NUXT_DECLINE_TOS_REDIRECT_URL="https://www2.gov.bc.ca/gov/content/housing-tenancy/short-term-rentals/registry" NUXT_HOST_FEES_URL="https://www2.gov.bc.ca/gov/content/housing-tenancy/short-term-rentals/registry/host-registration#fees" +# sbc/genesys messenger +NUXT_GENESYS_URL="" +NUXT_GENESYS_ENVIRONMENT_KEY="" +NUXT_GENESYS_DEPLOYMENT_KEY="" + #vaults keycloak NUXT_KEYCLOAK_AUTH_URL="https://dev.loginproxy.gov.bc.ca/auth" NUXT_KEYCLOAK_REALM="bcregistry" diff --git a/strr-host-pm-web/app/app.config.ts b/strr-host-pm-web/app/app.config.ts index c8be20213..68719b593 100644 --- a/strr-host-pm-web/app/app.config.ts +++ b/strr-host-pm-web/app/app.config.ts @@ -55,6 +55,10 @@ export default defineAppConfig({ hrefRtcKey: 'hostFeesUrl' } }) + }, + sbcWebMsg: { + enable: true, + allowedRoutes: ['application', 'dashboard'] } }, ui: {} diff --git a/strr-host-pm-web/app/pages/application.vue b/strr-host-pm-web/app/pages/application.vue index 28ea27a46..487f615ff 100644 --- a/strr-host-pm-web/app/pages/application.vue +++ b/strr-host-pm-web/app/pages/application.vue @@ -1,6 +1,5 @@