From 63f4c98033edfb918e727b94dfd46630e6cb8318 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 9 Oct 2024 14:34:43 -0500 Subject: [PATCH] [MWPW-152549] Milo susi options (#152) --- events/scripts/constances.js | 10 +++++----- events/scripts/content-update.js | 15 +++++++++------ events/scripts/scripts.js | 11 +++++------ events/scripts/utils.js | 12 ++++++++++++ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/events/scripts/constances.js b/events/scripts/constances.js index 41458d79..c888382d 100644 --- a/events/scripts/constances.js +++ b/events/scripts/constances.js @@ -1,8 +1,8 @@ export const META_REG = /\[\[(.*?)\]\]/g; export const ICON_REG = /@@(.*?)@@/g; -export const SUSI_CONTEXTS = { - local: 'v:2,s,bg:milo,51364e80-648b-11ef-9bf6-ad6724e2c153', - dev: 'v:2,s,bg:milo,51364e80-648b-11ef-9bf6-ad6724e2c153', - stage: 'v:2,s,bg:milo,51364e80-648b-11ef-9bf6-ad6724e2c153', - prod: 'v:2,s,bg:milo,b719a8b0-6ba6-11ef-933e-7f38920b05fd', +export const SUSI_OPTIONS = { + dctx_id: { + stage: 'v:2,s,bg:milo,51364e80-648b-11ef-9bf6-ad6724e2c153', + prod: 'v:2,s,bg:milo,b719a8b0-6ba6-11ef-933e-7f38920b05fd', + }, }; diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 8c1698ca..ac62d106 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -1,4 +1,4 @@ -import { ICON_REG, META_REG, SUSI_CONTEXTS } from './constances.js'; +import { ICON_REG, META_REG } from './constances.js'; import BlockMediator from './deps/block-mediator.min.js'; import { getEvent } from './esp-controller.js'; import { @@ -7,6 +7,7 @@ import { setMetadata, getIcon, readBlockConfig, + getSusiOptions, getECCEnv, } from './utils.js'; @@ -132,16 +133,17 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { } } -export function signIn() { +export function signIn(options) { if (typeof window.adobeIMS?.signIn !== 'function') { window?.lana.log({ message: 'IMS signIn method not available', tags: 'errorType=warn,module=gnav' }); return; } - window.adobeIMS?.signIn({ dctx_id: SUSI_CONTEXTS[getECCEnv()] }); + window.adobeIMS?.signIn(options); } async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { + const { getConfig } = await import(`${miloLibs}/utils/utils.js`); const resp = await getEvent(getMetadata('event-id')); if (!resp) { @@ -163,7 +165,7 @@ async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { rsvpBtn.el.setAttribute('tabindex', 0); rsvpBtn.el.addEventListener('click', (e) => { e.preventDefault(); - signIn(); + signIn(getSusiOptions(getConfig())); }); } } else if (profile) { @@ -175,7 +177,8 @@ async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { } } -export async function validatePageAndRedirect() { +export async function validatePageAndRedirect(miloLibs) { + const { getConfig } = await import(`${miloLibs}/utils/utils.js`); const env = getECCEnv(); const pagePublished = getMetadata('published') === 'true' || getMetadata('status') === 'live'; const invalidStagePage = env === 'stage' && window.location.hostname === 'www.stage.adobe.com' && !getMetadata('event-id'); @@ -192,7 +195,7 @@ export async function validatePageAndRedirect() { document.body.style.display = 'none'; BlockMediator.subscribe('imsProfile', ({ newValue }) => { if (newValue?.noProfile) { - signIn(); + signIn(getSusiOptions(getConfig())); } else if (!newValue.email?.toLowerCase().endsWith('@adobe.com')) { window.location.replace('/404'); } else { diff --git a/events/scripts/scripts.js b/events/scripts/scripts.js index da075256..4e0dc71c 100644 --- a/events/scripts/scripts.js +++ b/events/scripts/scripts.js @@ -12,10 +12,9 @@ import { lazyCaptureProfile } from './profile.js'; import autoUpdateContent, { getNonProdData, validatePageAndRedirect } from './content-update.js'; -import { setMetadata, getMetadata, getECCEnv, LIBS } from './utils.js'; -import { SUSI_CONTEXTS } from './constances.js'; +import { getSusiOptions, setMetadata, getMetadata, getECCEnv, LIBS } from './utils.js'; -const { loadArea, setConfig, getConfig, loadLana } = await import(`${LIBS}/utils/utils.js`); +const { loadArea, setConfig, updateConfig, getConfig, loadLana } = await import(`${LIBS}/utils/utils.js`); function decorateArea(area = document) { const parsePhotosData = () => { @@ -74,7 +73,6 @@ const CONFIG = { codeRoot: '/events', contentRoot: '/events', imsClientId: 'events-milo', - susiContexts: SUSI_CONTEXTS, miloLibs: LIBS, // imsScope: 'AdobeID,openid,gnav', // geoRouting: 'off', @@ -87,7 +85,8 @@ const CONFIG = { }, }; -setConfig({ ...CONFIG }); +const MILO_CONFIG = setConfig({ ...CONFIG }); +updateConfig({ ...MILO_CONFIG, signInContext: getSusiOptions(MILO_CONFIG) }); function renderWithNonProdMetadata() { const isEventDetailsPage = getMetadata('event-details-page') === 'yes'; @@ -125,7 +124,7 @@ decorateArea(); if (renderWithNonProdMetadata()) await fetchAndDecorateArea(); // Validate the page and redirect if is event-details-page -if (getMetadata('event-details-page') === 'yes') await validatePageAndRedirect(); +if (getMetadata('event-details-page') === 'yes') await validatePageAndRedirect(LIBS); /* * ------------------------------------------------------------ diff --git a/events/scripts/utils.js b/events/scripts/utils.js index baf14f94..9c117abe 100644 --- a/events/scripts/utils.js +++ b/events/scripts/utils.js @@ -1,3 +1,5 @@ +import { SUSI_OPTIONS } from './constances.js'; + export const LIBS = (() => { const { hostname, search } = window.location; if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return '/libs'; @@ -173,6 +175,16 @@ function toClassName(name) { : ''; } +export function getSusiOptions(conf) { + const { env: { name: envName } } = conf; + const susiOptions = Object.keys(SUSI_OPTIONS).reduce((opts, key) => { + opts[key] = SUSI_OPTIONS[key][envName] || SUSI_OPTIONS[key]; + return opts; + }, {}); + + return susiOptions; +} + export function readBlockConfig(block) { return [...block.querySelectorAll(':scope>div')].reduce((config, row) => { if (row.children) {