Skip to content

Commit

Permalink
dependency free getECCEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Sep 26, 2024
1 parent 47125db commit 7c413f1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { LIBS } from '../../../scripts/scripts.js';
import HtmlSanitizer from '../../../scripts/deps/html-sanitizer.js';
import { fetchThrottledMemoizedText } from '../../../scripts/utils.js';
import { fetchThrottledMemoizedText, getECCEnv } from '../../../scripts/utils.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);

Expand Down Expand Up @@ -35,7 +35,7 @@ async function loadPreview(component, templateId) {

let host;
if (window.location.href.includes('.hlx.')) {
host = window.location.origin.replace(window.location.hostname, `${window.miloConfig.eccEnv}--events-milo--adobecom.hlx.page`);
host = window.location.origin.replace(window.location.hostname, `${getECCEnv()}--events-milo--adobecom.hlx.page`);
} else {
host = window.location.origin;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { createVenue, replaceVenue } from '../../../scripts/esp-controller.js';
import BlockMediator from '../../../scripts/deps/block-mediator.min.js';
import { changeInputValue, getSecret } from '../../../scripts/utils.js';
import { changeInputValue, getECCEnv, getSecret } from '../../../scripts/utils.js';
import { buildErrorMessage } from '../form-handler.js';

function togglePrefillableFieldsHiddenState(component, showPrefilledFields) {
Expand All @@ -18,7 +18,7 @@ function togglePrefillableFieldsHiddenState(component, showPrefilledFields) {

async function loadGoogleMapsAPI(callback) {
const script = document.createElement('script');
const apiKey = await getSecret(`${window.miloConfig.eccEnv}-google-places-api`);
const apiKey = await getSecret(`${getECCEnv()}-google-places-api`);
script.src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=onGoogleMapsApiLoaded`;
script.async = true;
script.defer = true;
Expand Down
74 changes: 38 additions & 36 deletions ecc/scripts/esp-controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getECCEnv } from './utils.js';

export const getCaasTags = (() => {
let cache;
let promise;
Expand Down Expand Up @@ -85,7 +87,7 @@ export async function constructRequestOptions(method, body = null) {
export async function uploadImage(file, configs, tracker, imageId = null) {
await waitForAdobeIMS();

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const authToken = window.adobeIMS?.getAccessToken()?.token;

let respJson = null;
Expand Down Expand Up @@ -175,7 +177,7 @@ function convertToSpeaker(speaker) {

export async function deleteImage(configs, imageId) {
await waitForAdobeIMS();
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand All @@ -196,7 +198,7 @@ export async function deleteImage(configs, imageId) {
}

export async function createVenue(eventId, venueData) {
const { host } = getAPIConfig().esl[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esl[getECCEnv()];
const raw = JSON.stringify(venueData);
const options = await constructRequestOptions('POST', raw);

Expand All @@ -217,7 +219,7 @@ export async function createVenue(eventId, venueData) {
}

export async function replaceVenue(eventId, venueId, venueData) {
const { host } = getAPIConfig().esl[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esl[getECCEnv()];
const raw = JSON.stringify(venueData);
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -238,7 +240,7 @@ export async function replaceVenue(eventId, venueId, venueData) {
}

export async function createEvent(payload) {
const { host } = getAPIConfig().esl[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esl[getECCEnv()];
const raw = JSON.stringify({ ...payload, liveUpdate: false });
const options = await constructRequestOptions('POST', raw);

Expand All @@ -261,7 +263,7 @@ export async function createEvent(payload) {
export async function createSpeaker(profile, seriesId) {
const nSpeaker = convertToNSpeaker(profile);

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify({ ...nSpeaker, seriesId });
const options = await constructRequestOptions('POST', raw);

Expand All @@ -282,7 +284,7 @@ export async function createSpeaker(profile, seriesId) {
}

export async function createSponsor(sponsorData, seriesId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(sponsorData);
const options = await constructRequestOptions('POST', raw);

Expand All @@ -303,7 +305,7 @@ export async function createSponsor(sponsorData, seriesId) {
}

export async function updateSponsor(sponsorData, sponsorId, seriesId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(sponsorData);
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -324,7 +326,7 @@ export async function updateSponsor(sponsorData, sponsorId, seriesId) {
}

export async function addSponsorToEvent(sponsorData, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(sponsorData);
const options = await constructRequestOptions('POST', raw);

Expand All @@ -345,7 +347,7 @@ export async function addSponsorToEvent(sponsorData, eventId) {
}

export async function updateSponsorInEvent(sponsorData, sponsorId, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(sponsorData);
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -366,7 +368,7 @@ export async function updateSponsorInEvent(sponsorData, sponsorId, eventId) {
}

export async function removeSponsorFromEvent(sponsorId, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand All @@ -386,7 +388,7 @@ export async function removeSponsorFromEvent(sponsorId, eventId) {
}

export async function getSponsor(seriesId, sponsorId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -406,7 +408,7 @@ export async function getSponsor(seriesId, sponsorId) {
}

export async function getSponsors(seriesId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -426,7 +428,7 @@ export async function getSponsors(seriesId) {
}

export async function getSponsorImages(seriesId, sponsorId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -446,7 +448,7 @@ export async function getSponsorImages(seriesId, sponsorId) {
}

export async function addSpeakerToEvent(speakerData, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(speakerData);
const options = await constructRequestOptions('POST', raw);

Expand All @@ -467,7 +469,7 @@ export async function addSpeakerToEvent(speakerData, eventId) {
}

export async function updateSpeakerInEvent(speakerData, speakerId, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(speakerData);
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -488,7 +490,7 @@ export async function updateSpeakerInEvent(speakerData, speakerId, eventId) {
}

export async function removeSpeakerFromEvent(speakerId, eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand All @@ -509,7 +511,7 @@ export async function removeSpeakerFromEvent(speakerId, eventId) {

export async function updateSpeaker(profile, seriesId) {
const nSpeaker = convertToNSpeaker(profile);
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify({ ...nSpeaker, seriesId });
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -530,7 +532,7 @@ export async function updateSpeaker(profile, seriesId) {
}

export async function updateEvent(eventId, payload) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify({ ...payload, liveUpdate: false });
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -551,7 +553,7 @@ export async function updateEvent(eventId, payload) {
}

export async function publishEvent(eventId, payload) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify({ ...payload, published: true, liveUpdate: true });
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -572,7 +574,7 @@ export async function publishEvent(eventId, payload) {
}

export async function unpublishEvent(eventId, payload) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify({ ...payload, published: false, liveUpdate: true });
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -593,7 +595,7 @@ export async function unpublishEvent(eventId, payload) {
}

export async function deleteEvent(eventId) {
const { host } = getAPIConfig().esl[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esl[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand All @@ -614,7 +616,7 @@ export async function deleteEvent(eventId) {
}

export async function getEvents() {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -634,7 +636,7 @@ export async function getEvents() {
}

export async function getEvent(eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -654,7 +656,7 @@ export async function getEvent(eventId) {
}

export async function getVenue(eventId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -674,7 +676,7 @@ export async function getVenue(eventId) {
}

export async function getSpeaker(seriesId, speakerId) {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand Down Expand Up @@ -706,7 +708,7 @@ export async function getClouds() {
}

export async function getSeries() {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -728,7 +730,7 @@ export async function getSeries() {
export async function createAttendee(eventId, attendeeData) {
if (!eventId || !attendeeData) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(attendeeData);
const options = await constructRequestOptions('POST', raw);

Expand All @@ -751,7 +753,7 @@ export async function createAttendee(eventId, attendeeData) {
export async function updateAttendee(eventId, attendeeId, attendeeData) {
if (!eventId || !attendeeData) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const raw = JSON.stringify(attendeeData);
const options = await constructRequestOptions('PUT', raw);

Expand All @@ -774,7 +776,7 @@ export async function updateAttendee(eventId, attendeeId, attendeeData) {
export async function deleteAttendee(eventId, attendeeId) {
if (!eventId || !attendeeId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand All @@ -796,7 +798,7 @@ export async function deleteAttendee(eventId, attendeeId) {
export async function getEventAttendees(eventId) {
if (!eventId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -817,7 +819,7 @@ export async function getEventAttendees(eventId) {

export async function getAllEventAttendees(eventId) {
const recurGetAttendees = async (fullAttendeeArr = [], nextPageToken = null) => {
const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');
const fetchUrl = nextPageToken ? `${host}/v1/events/${eventId}/attendees?nextPageToken=${nextPageToken}` : `${host}/v1/events/${eventId}/attendees`;

Expand Down Expand Up @@ -849,7 +851,7 @@ export async function getAllEventAttendees(eventId) {
export async function getAttendee(eventId, attendeeId) {
if (!eventId || !attendeeId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -871,7 +873,7 @@ export async function getAttendee(eventId, attendeeId) {
export async function getSpeakers(seriesId) {
if (!seriesId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -893,7 +895,7 @@ export async function getSpeakers(seriesId) {
export async function getEventImages(eventId) {
if (!eventId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('GET');

try {
Expand All @@ -915,7 +917,7 @@ export async function getEventImages(eventId) {
export async function deleteSpeakerImage(speakerId, seriesId, imageId) {
if (!speakerId || !seriesId || !imageId) return false;

const { host } = getAPIConfig().esp[window.miloConfig.eccEnv];
const { host } = getAPIConfig().esp[getECCEnv()];
const options = await constructRequestOptions('DELETE');

try {
Expand Down
5 changes: 2 additions & 3 deletions ecc/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ export const LIBS = (() => {
}());

(async function loadPage() {
const { loadArea, setConfig, getConfig, updateConfig, loadLana } = await import(`${LIBS}/utils/utils.js`);
setConfig({ ...CONFIG, miloLibs: LIBS });
window.miloConfig = updateConfig({ ...getConfig(), eccEnv: getECCEnv(getConfig()) });
const { loadArea, setConfig, loadLana } = await import(`${LIBS}/utils/utils.js`);
window.miloConfig = setConfig({ ...CONFIG, miloLibs: LIBS });
await loadLana({ clientId: 'ecc-milo' });
await loadArea().then(() => {
lazyCaptureProfile();
Expand Down
Loading

0 comments on commit 7c413f1

Please sign in to comment.