From e58dce77f154e5e94844a081c5ee1b92dadbddf0 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 1 Oct 2024 16:45:08 -0500 Subject: [PATCH] Dev token in USP to help with local dev process (#241) --- .../attendee-management-table.js | 9 +++++++++ ecc/blocks/ecc-dashboard/ecc-dashboard.js | 10 +++++++++- ecc/blocks/form-handler/form-handler.js | 10 ++++++++++ ecc/scripts/esp-controller.js | 8 ++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ecc/blocks/attendee-management-table/attendee-management-table.js b/ecc/blocks/attendee-management-table/attendee-management-table.js index caa4f0c3..fa4abc1b 100644 --- a/ecc/blocks/attendee-management-table/attendee-management-table.js +++ b/ecc/blocks/attendee-management-table/attendee-management-table.js @@ -7,6 +7,7 @@ import { buildNoAccessScreen, camelToSentenceCase, readBlockConfig, + getECCEnv, } from '../../scripts/utils.js'; import BlockMediator from '../../scripts/deps/block-mediator.min.js'; import { SearchablePicker } from '../../components/searchable-picker/searchable-picker.js'; @@ -556,6 +557,14 @@ export default async function init(el) { const config = readBlockConfig(el); el.innerHTML = ''; buildLoadingScreen(el); + + const sp = new URLSearchParams(window.location.search); + const devToken = sp.get('devToken'); + if (devToken && getECCEnv() === 'dev') { + buildDashboard(el, config); + return; + } + const profile = BlockMediator.get('imsProfile'); if (profile) { diff --git a/ecc/blocks/ecc-dashboard/ecc-dashboard.js b/ecc/blocks/ecc-dashboard/ecc-dashboard.js index 85a920ef..101868c0 100644 --- a/ecc/blocks/ecc-dashboard/ecc-dashboard.js +++ b/ecc/blocks/ecc-dashboard/ecc-dashboard.js @@ -8,7 +8,7 @@ import { } from '../../scripts/esp-controller.js'; import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; import { LIBS } from '../../scripts/scripts.js'; -import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig } from '../../scripts/utils.js'; +import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig, getECCEnv } from '../../scripts/utils.js'; import { quickFilter } from '../form-handler/data-handler.js'; import BlockMediator from '../../scripts/deps/block-mediator.min.js'; @@ -705,6 +705,14 @@ export default async function init(el) { const config = readBlockConfig(el); el.innerHTML = ''; buildLoadingScreen(el); + + const sp = new URLSearchParams(window.location.search); + const devToken = sp.get('devToken'); + if (devToken && getECCEnv() === 'dev') { + buildDashboard(el, config); + return; + } + const profile = BlockMediator.get('imsProfile'); if (profile) { diff --git a/ecc/blocks/form-handler/form-handler.js b/ecc/blocks/form-handler/form-handler.js index 9ff3c8a4..ee73e6bd 100644 --- a/ecc/blocks/form-handler/form-handler.js +++ b/ecc/blocks/form-handler/form-handler.js @@ -6,6 +6,7 @@ import { generateToolTip, camelToSentenceCase, getEventPageHost, + getECCEnv, } from '../../scripts/utils.js'; import { createEvent, @@ -857,6 +858,15 @@ export default async function init(el) { ...promises, ]); + const sp = new URLSearchParams(window.location.search); + const devToken = sp.get('devToken'); + if (devToken && getECCEnv() === 'dev') { + buildECCForm(el).then(() => { + el.classList.remove('loading'); + }); + return; + } + const profile = BlockMediator.get('imsProfile'); if (profile) { diff --git a/ecc/scripts/esp-controller.js b/ecc/scripts/esp-controller.js index 0448017b..4f5d31e7 100644 --- a/ecc/scripts/esp-controller.js +++ b/ecc/scripts/esp-controller.js @@ -66,7 +66,9 @@ export async function constructRequestOptions(method, body = null) { await waitForAdobeIMS(); const headers = new Headers(); - const authToken = window.adobeIMS?.getAccessToken()?.token; + const sp = new URLSearchParams(window.location.search); + const devToken = sp.get('devToken'); + const authToken = devToken && getECCEnv() === 'dev' ? devToken : window.adobeIMS?.getAccessToken()?.token; if (!authToken) window.lana?.log('Error: Failed to get Adobe IMS auth token'); @@ -88,7 +90,9 @@ export async function uploadImage(file, configs, tracker, imageId = null) { await waitForAdobeIMS(); const { host } = getAPIConfig().esp[getECCEnv()]; - const authToken = window.adobeIMS?.getAccessToken()?.token; + const sp = new URLSearchParams(window.location.search); + const devToken = sp.get('devToken'); + const authToken = devToken && getECCEnv() === 'dev' ? devToken : window.adobeIMS?.getAccessToken()?.token; let respJson = null;