diff --git a/ecc/blocks/attendee-management-table/attendee-management-table.js b/ecc/blocks/attendee-management-table/attendee-management-table.js index da21c865..8547d80b 100644 --- a/ecc/blocks/attendee-management-table/attendee-management-table.js +++ b/ecc/blocks/attendee-management-table/attendee-management-table.js @@ -1,7 +1,7 @@ /* eslint-disable max-len */ import { getAllEventAttendees, getEvents } from '../../scripts/esp-controller.js'; -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; -import { DEV_MODE, LIBS, MILO_CONFIG } from '../../scripts/scripts.js'; +import { ALLOWED_ACCOUNT_TYPES, DEV_MODE } from '../../constants/constants.js'; +import { LIBS } from '../../scripts/scripts.js'; import { getIcon, buildNoAccessScreen, @@ -563,7 +563,7 @@ export default async function init(el) { buildLoadingScreen(el); const profile = BlockMediator.get('imsProfile'); - if (devMode === 'true' && ['stage', 'local'].includes(MILO_CONFIG.env.name)) { + if (devMode === 'true' && ['stage', 'local'].includes(window.miloConfig.env.name)) { buildDashboard(el, config); return; } diff --git a/ecc/blocks/ecc-dashboard/ecc-dashboard.js b/ecc/blocks/ecc-dashboard/ecc-dashboard.js index bc81fe88..3d888109 100644 --- a/ecc/blocks/ecc-dashboard/ecc-dashboard.js +++ b/ecc/blocks/ecc-dashboard/ecc-dashboard.js @@ -6,8 +6,8 @@ import { publishEvent, unpublishEvent, } from '../../scripts/esp-controller.js'; -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; -import { LIBS, MILO_CONFIG, DEV_MODE } from '../../scripts/scripts.js'; +import { ALLOWED_ACCOUNT_TYPES, DEV_MODE } from '../../constants/constants.js'; +import { LIBS } from '../../scripts/scripts.js'; import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig } from '../../scripts/utils.js'; import { quickFilter } from '../form-handler/data-handler.js'; import BlockMediator from '../../scripts/deps/block-mediator.min.js'; @@ -709,7 +709,7 @@ export default async function init(el) { buildLoadingScreen(el); const profile = BlockMediator.get('imsProfile'); - if (DEV_MODE === true && ['stage', 'local'].includes(MILO_CONFIG.env.name)) { + if (DEV_MODE === true && ['stage', 'local'].includes(window.miloConfig.env.name)) { buildDashboard(el, config); return; } diff --git a/ecc/blocks/form-handler/controllers/terms-conditions-component-controller.js b/ecc/blocks/form-handler/controllers/terms-conditions-component-controller.js index 1e776f0c..31c6ff7d 100644 --- a/ecc/blocks/form-handler/controllers/terms-conditions-component-controller.js +++ b/ecc/blocks/form-handler/controllers/terms-conditions-component-controller.js @@ -1,10 +1,8 @@ /* eslint-disable no-unused-vars */ -import { ECC_ENV, LIBS } from '../../../scripts/scripts.js'; +import { LIBS } from '../../../scripts/scripts.js'; import HtmlSanitizer from '../../../scripts/deps/html-sanitizer.js'; -import { fetchThrottledMemoizedText, getEventPageHost } from '../../../scripts/utils.js'; -import { getFilteredCachedResponse } from '../data-handler.js'; +import { fetchThrottledMemoizedText } from '../../../scripts/utils.js'; -const { customFetch } = await import(`${LIBS}/utils/helpers.js`); const { createTag } = await import(`${LIBS}/utils/utils.js`); function buildTerms(terms) { @@ -37,7 +35,7 @@ async function loadPreview(component, templateId) { let host; if (window.location.href.includes('.hlx.')) { - host = window.location.origin.replace(window.location.hostname, `${ECC_ENV}--events-milo--adobecom.hlx.page`); + host = window.location.origin.replace(window.location.hostname, `${window.miloConfig.eccEnv}--events-milo--adobecom.hlx.page`); } else { host = window.location.origin; } diff --git a/ecc/blocks/form-handler/controllers/venue-info-component-controller.js b/ecc/blocks/form-handler/controllers/venue-info-component-controller.js index ac0be972..ee316e95 100644 --- a/ecc/blocks/form-handler/controllers/venue-info-component-controller.js +++ b/ecc/blocks/form-handler/controllers/venue-info-component-controller.js @@ -1,7 +1,6 @@ /* eslint-disable no-unused-vars */ import { createVenue, replaceVenue } from '../../../scripts/esp-controller.js'; import BlockMediator from '../../../scripts/deps/block-mediator.min.js'; -import { ECC_ENV } from '../../../scripts/scripts.js'; import { changeInputValue, getSecret } from '../../../scripts/utils.js'; import { buildErrorMessage } from '../form-handler.js'; @@ -19,7 +18,7 @@ function togglePrefillableFieldsHiddenState(component, showPrefilledFields) { async function loadGoogleMapsAPI(callback) { const script = document.createElement('script'); - const apiKey = await getSecret(`${ECC_ENV}-google-places-api`); + const apiKey = await getSecret(`${window.miloConfig.eccEnv}-google-places-api`); script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=onGoogleMapsApiLoaded`; script.async = true; script.defer = true; diff --git a/ecc/blocks/form-handler/form-handler.js b/ecc/blocks/form-handler/form-handler.js index bb898551..ba3d9077 100644 --- a/ecc/blocks/form-handler/form-handler.js +++ b/ecc/blocks/form-handler/form-handler.js @@ -1,5 +1,5 @@ -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; -import { LIBS, MILO_CONFIG, DEV_MODE } from '../../scripts/scripts.js'; +import { ALLOWED_ACCOUNT_TYPES, DEV_MODE } from '../../constants/constants.js'; +import { LIBS } from '../../scripts/scripts.js'; import { getIcon, buildNoAccessScreen, @@ -859,7 +859,7 @@ export default async function init(el) { const profile = BlockMediator.get('imsProfile'); - if (DEV_MODE === true && ['stage', 'local'].includes(MILO_CONFIG.env.name)) { + if (DEV_MODE === true && ['stage', 'local'].includes(window.miloConfig.env.name)) { buildECCForm(el).then(() => { el.classList.remove('loading'); }); diff --git a/ecc/constants/constants.js b/ecc/constants/constants.js index 939a98e8..9b8b6e08 100644 --- a/ecc/constants/constants.js +++ b/ecc/constants/constants.js @@ -1,2 +1,3 @@ export const LINK_REGEX = '^https:\\/\\/[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,63}(:[0-9]{1,5})?(\\/.*)?$'; export const ALLOWED_ACCOUNT_TYPES = ['type3', 'type2e']; +export const DEV_MODE = new URLSearchParams(window.location.search).has('devMode'); diff --git a/ecc/scripts/esp-controller.js b/ecc/scripts/esp-controller.js index 256f19e3..1fdfc399 100644 --- a/ecc/scripts/esp-controller.js +++ b/ecc/scripts/esp-controller.js @@ -1,5 +1,3 @@ -import { ECC_ENV } from './scripts.js'; - export const getCaasTags = (() => { let cache; let promise; @@ -87,7 +85,7 @@ export async function constructRequestOptions(method, body = null) { export async function uploadImage(file, configs, tracker, imageId = null) { await waitForAdobeIMS(); - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const authToken = window.adobeIMS?.getAccessToken()?.token; let respJson = null; @@ -177,7 +175,7 @@ function convertToSpeaker(speaker) { export async function deleteImage(configs, imageId) { await waitForAdobeIMS(); - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { @@ -198,7 +196,7 @@ export async function deleteImage(configs, imageId) { } export async function createVenue(eventId, venueData) { - const { host } = getAPIConfig().esl[ECC_ENV]; + const { host } = getAPIConfig().esl[window.miloConfig.eccEnv]; const raw = JSON.stringify(venueData); const options = await constructRequestOptions('POST', raw); @@ -219,7 +217,7 @@ export async function createVenue(eventId, venueData) { } export async function replaceVenue(eventId, venueId, venueData) { - const { host } = getAPIConfig().esl[ECC_ENV]; + const { host } = getAPIConfig().esl[window.miloConfig.eccEnv]; const raw = JSON.stringify(venueData); const options = await constructRequestOptions('PUT', raw); @@ -240,7 +238,7 @@ export async function replaceVenue(eventId, venueId, venueData) { } export async function createEvent(payload) { - const { host } = getAPIConfig().esl[ECC_ENV]; + const { host } = getAPIConfig().esl[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...payload, liveUpdate: false }); const options = await constructRequestOptions('POST', raw); @@ -263,7 +261,7 @@ export async function createEvent(payload) { export async function createSpeaker(profile, seriesId) { const nSpeaker = convertToNSpeaker(profile); - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...nSpeaker, seriesId }); const options = await constructRequestOptions('POST', raw); @@ -284,7 +282,7 @@ export async function createSpeaker(profile, seriesId) { } export async function createSponsor(sponsorData, seriesId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(sponsorData); const options = await constructRequestOptions('POST', raw); @@ -305,7 +303,7 @@ export async function createSponsor(sponsorData, seriesId) { } export async function updateSponsor(sponsorData, sponsorId, seriesId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(sponsorData); const options = await constructRequestOptions('PUT', raw); @@ -326,7 +324,7 @@ export async function updateSponsor(sponsorData, sponsorId, seriesId) { } export async function addSponsorToEvent(sponsorData, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(sponsorData); const options = await constructRequestOptions('POST', raw); @@ -347,7 +345,7 @@ export async function addSponsorToEvent(sponsorData, eventId) { } export async function updateSponsorInEvent(sponsorData, sponsorId, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(sponsorData); const options = await constructRequestOptions('PUT', raw); @@ -368,7 +366,7 @@ export async function updateSponsorInEvent(sponsorData, sponsorId, eventId) { } export async function removeSponsorFromEvent(sponsorId, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { @@ -388,7 +386,7 @@ export async function removeSponsorFromEvent(sponsorId, eventId) { } export async function getSponsor(seriesId, sponsorId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -408,7 +406,7 @@ export async function getSponsor(seriesId, sponsorId) { } export async function getSponsors(seriesId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -428,7 +426,7 @@ export async function getSponsors(seriesId) { } export async function getSponsorImages(seriesId, sponsorId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -448,7 +446,7 @@ export async function getSponsorImages(seriesId, sponsorId) { } export async function addSpeakerToEvent(speakerData, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(speakerData); const options = await constructRequestOptions('POST', raw); @@ -469,7 +467,7 @@ export async function addSpeakerToEvent(speakerData, eventId) { } export async function updateSpeakerInEvent(speakerData, speakerId, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(speakerData); const options = await constructRequestOptions('PUT', raw); @@ -490,7 +488,7 @@ export async function updateSpeakerInEvent(speakerData, speakerId, eventId) { } export async function removeSpeakerFromEvent(speakerId, eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { @@ -511,7 +509,7 @@ export async function removeSpeakerFromEvent(speakerId, eventId) { export async function updateSpeaker(profile, seriesId) { const nSpeaker = convertToNSpeaker(profile); - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...nSpeaker, seriesId }); const options = await constructRequestOptions('PUT', raw); @@ -532,7 +530,7 @@ export async function updateSpeaker(profile, seriesId) { } export async function updateEvent(eventId, payload) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...payload, liveUpdate: false }); const options = await constructRequestOptions('PUT', raw); @@ -553,7 +551,7 @@ export async function updateEvent(eventId, payload) { } export async function publishEvent(eventId, payload) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...payload, published: true, liveUpdate: true }); const options = await constructRequestOptions('PUT', raw); @@ -574,7 +572,7 @@ export async function publishEvent(eventId, payload) { } export async function unpublishEvent(eventId, payload) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify({ ...payload, published: false, liveUpdate: true }); const options = await constructRequestOptions('PUT', raw); @@ -595,7 +593,7 @@ export async function unpublishEvent(eventId, payload) { } export async function deleteEvent(eventId) { - const { host } = getAPIConfig().esl[ECC_ENV]; + const { host } = getAPIConfig().esl[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { @@ -616,7 +614,7 @@ export async function deleteEvent(eventId) { } export async function getEvents() { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -636,7 +634,7 @@ export async function getEvents() { } export async function getEvent(eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -656,7 +654,7 @@ export async function getEvent(eventId) { } export async function getVenue(eventId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -676,7 +674,7 @@ export async function getVenue(eventId) { } export async function getSpeaker(seriesId, speakerId) { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -708,7 +706,7 @@ export async function getClouds() { } export async function getSeries() { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -730,7 +728,7 @@ export async function getSeries() { export async function createAttendee(eventId, attendeeData) { if (!eventId || !attendeeData) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(attendeeData); const options = await constructRequestOptions('POST', raw); @@ -753,7 +751,7 @@ export async function createAttendee(eventId, attendeeData) { export async function updateAttendee(eventId, attendeeId, attendeeData) { if (!eventId || !attendeeData) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const raw = JSON.stringify(attendeeData); const options = await constructRequestOptions('PUT', raw); @@ -776,7 +774,7 @@ export async function updateAttendee(eventId, attendeeId, attendeeData) { export async function deleteAttendee(eventId, attendeeId) { if (!eventId || !attendeeId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { @@ -798,7 +796,7 @@ export async function deleteAttendee(eventId, attendeeId) { export async function getEventAttendees(eventId) { if (!eventId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -819,7 +817,7 @@ export async function getEventAttendees(eventId) { export async function getAllEventAttendees(eventId) { const recurGetAttendees = async (fullAttendeeArr = [], nextPageToken = null) => { - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); const fetchUrl = nextPageToken ? `${host}/v1/events/${eventId}/attendees?nextPageToken=${nextPageToken}` : `${host}/v1/events/${eventId}/attendees`; @@ -851,7 +849,7 @@ export async function getAllEventAttendees(eventId) { export async function getAttendee(eventId, attendeeId) { if (!eventId || !attendeeId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -873,7 +871,7 @@ export async function getAttendee(eventId, attendeeId) { export async function getSpeakers(seriesId) { if (!seriesId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -895,7 +893,7 @@ export async function getSpeakers(seriesId) { export async function getEventImages(eventId) { if (!eventId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('GET'); try { @@ -917,7 +915,7 @@ export async function getEventImages(eventId) { export async function deleteSpeakerImage(speakerId, seriesId, imageId) { if (!speakerId || !seriesId || !imageId) return false; - const { host } = getAPIConfig().esp[ECC_ENV]; + const { host } = getAPIConfig().esp[window.miloConfig.eccEnv]; const options = await constructRequestOptions('DELETE'); try { diff --git a/ecc/scripts/scripts.js b/ecc/scripts/scripts.js index 3662372e..59af7042 100644 --- a/ecc/scripts/scripts.js +++ b/ecc/scripts/scripts.js @@ -162,12 +162,11 @@ export const LIBS = (() => { }); }()); -const { loadArea, setConfig, loadLana } = await import(`${LIBS}/utils/utils.js`); -export const MILO_CONFIG = setConfig({ ...CONFIG, miloLibs: LIBS }); -export const ECC_ENV = getECCEnv(MILO_CONFIG); -export const DEV_MODE = new URLSearchParams(window.location.search).has('devMode'); - (async function loadPage() { + const { loadArea, setConfig, getConfig, updateConfig, loadLana } = await import(`${LIBS}/utils/utils.js`); + window.miloConfig = setConfig({ ...CONFIG, miloLibs: LIBS }); + const eccEnv = getECCEnv(getConfig()); + window.miloConfig = updateConfig({ ...getConfig(), eccEnv }); await loadLana({ clientId: 'ecc-milo' }); await loadArea().then(() => { lazyCaptureProfile(); diff --git a/ecc/scripts/utils.js b/ecc/scripts/utils.js index f171fd06..8c7f2697 100644 --- a/ecc/scripts/utils.js +++ b/ecc/scripts/utils.js @@ -1,4 +1,4 @@ -import { MILO_CONFIG, LIBS, ECC_ENV } from './scripts.js'; +import { LIBS } from './scripts.js'; const { createTag } = await import(`${LIBS}/utils/utils.js`); @@ -7,7 +7,7 @@ let secretCache = []; export function getIcon(tag) { const img = document.createElement('img'); img.className = `icon icon-${tag}`; - img.src = `${MILO_CONFIG.codeRoot}/icons/${tag}.svg`; + img.src = `${window.miloConfig.codeRoot}/icons/${tag}.svg`; img.alt = tag; return img; @@ -58,7 +58,7 @@ export function convertTo24HourFormat(timeStr) { export function getEventPageHost() { if (window.location.href.includes('.hlx.')) { - return window.location.origin.replace(window.location.hostname, `${ECC_ENV}--events-milo--adobecom.hlx.page`); + return window.location.origin.replace(window.location.hostname, `${window.miloConfig.eccEnv}--events-milo--adobecom.hlx.page`); } return window.location.origin;