Skip to content

Commit

Permalink
[MWPW-152549] Milo susi options (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai authored Oct 9, 2024
1 parent f92789e commit 63f4c98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
10 changes: 5 additions & 5 deletions events/scripts/constances.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
15 changes: 9 additions & 6 deletions events/scripts/content-update.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -7,6 +7,7 @@ import {
setMetadata,
getIcon,
readBlockConfig,
getSusiOptions,
getECCEnv,
} from './utils.js';

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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');
Expand All @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions events/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -74,7 +73,6 @@ const CONFIG = {
codeRoot: '/events',
contentRoot: '/events',
imsClientId: 'events-milo',
susiContexts: SUSI_CONTEXTS,
miloLibs: LIBS,
// imsScope: 'AdobeID,openid,gnav',
// geoRouting: 'off',
Expand All @@ -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';
Expand Down Expand Up @@ -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);

/*
* ------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions events/scripts/utils.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 63f4c98

Please sign in to comment.