Skip to content

Commit

Permalink
switch to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
deetz99 committed Jan 13, 2025
1 parent 460eb0b commit 97233cc
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 100 deletions.
5 changes: 4 additions & 1 deletion strr-base-web/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default defineAppConfig({
},
sbcWebMsg: {
enable: true,
allowedRoutes: undefined
allowedRoutes: undefined,
genesysUrl: 'https://apps.cac1.pure.cloud/genesys-bootstrap/genesys.min.js',
genesysEnvironmentKey: 'prod-cac1',
genesysDeploymentKey: '56973fe6-5b18-4395-bd10-707243b2f680'
}
},
ui: {
Expand Down
59 changes: 59 additions & 0 deletions strr-base-web/app/middleware/enable-sbc-web-messenger.global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export default defineNuxtRouteMiddleware(async (to) => {
const { ldClient, getStoredFlag } = useConnectLaunchdarklyStore()
await ldClient?.waitUntilReady()
const enableSbcWebMsg = getStoredFlag('enable-sbc-web-messenger')
const msgConfig = useAppConfig().strrBaseLayer.sbcWebMsg

if (ldClient && enableSbcWebMsg && msgConfig.enable) {
const rtc = useRuntimeConfig().public
const genesysUrl = rtc.genesysUrl as string
const environmentKey = rtc.genesysEnvironmentKey as string
const deploymentKey = rtc.genesysDeploymentKey as string

const initWebMsg = () => {
window._genesysJs = 'Genesys'
window.Genesys = window.Genesys || function (...args: any) {
(window.Genesys.q = window.Genesys.q || []).push(args)
}
window.Genesys.t = Date.now()
window.Genesys.c = {
environment: environmentKey,
deploymentId: deploymentKey
}

const script = document.createElement('script')
script.async = true
script.src = genesysUrl
document.head.appendChild(script)
localStorage.removeItem('_actmu')
}

const removeWebMsg = () => {
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 isRouteAllowed = (path: string): boolean => {
if (msgConfig.allowedRoutes === undefined) {
return true
}
return msgConfig.allowedRoutes.some(route => path.includes(route))
}

if (isRouteAllowed(to.path)) {
console.log('init')

Check failure on line 51 in strr-base-web/app/middleware/enable-sbc-web-messenger.global.ts

View workflow job for this annotation

GitHub Actions / strr-base-web-ci / linting-pnpm (20, 9)

Unexpected console statement
initWebMsg()
} else {
// TODO: make this work
removeWebMsg()
console.log('remove')

Check failure on line 56 in strr-base-web/app/middleware/enable-sbc-web-messenger.global.ts

View workflow job for this annotation

GitHub Actions / strr-base-web-ci / linting-pnpm (20, 9)

Unexpected console statement
}
}
})
94 changes: 0 additions & 94 deletions strr-base-web/app/plugins/sbc-web-messenger.client.ts

This file was deleted.

10 changes: 8 additions & 2 deletions strr-base-web/app/types/strr-base-app-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ declare module 'nuxt/schema' {
},
sbcWebMsg: {
enable: boolean,
allowedRoutes: string[] | undefined
allowedRoutes: string[] | undefined,
genesysUrl: string,
genesysEnvironmentKey: string,
genesysDeploymentKey: string
}
}
}
Expand All @@ -44,7 +47,10 @@ declare module 'nuxt/schema' {
},
sbcWebMsg: {
enable: boolean,
allowedRoutes: string[] | undefined
allowedRoutes: string[] | undefined,
genesysUrl: string,
genesysEnvironmentKey: string,
genesysDeploymentKey: string
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions strr-base-web/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ export default defineNuxtConfig({
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,
genesysUrl: process.env.NUXT_GENESYS_URL,
genesysEnvironmentKey: process.env.NUXT_GENESYS_ENVIRONMENT_KEY,
genesysDeploymentKey: process.env.NUXT_GENESYS_DEPLOYMENT_KEY
genesysUrl: 'https://apps.cac1.pure.cloud/genesys-bootstrap/genesys.min.js',
genesysEnvironmentKey: 'prod-cac1',
genesysDeploymentKey: '1c8e851a-5bc8-4d50-bc7b-2f6365e04124'
// 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
Expand Down

0 comments on commit 97233cc

Please sign in to comment.