Skip to content

Commit

Permalink
Dev token in USP to help with local dev process (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai authored Oct 1, 2024
1 parent 300cdee commit e58dce7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion ecc/blocks/ecc-dashboard/ecc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions ecc/blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
generateToolTip,
camelToSentenceCase,
getEventPageHost,
getECCEnv,
} from '../../scripts/utils.js';
import {
createEvent,
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions ecc/scripts/esp-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;

Expand Down

0 comments on commit e58dce7

Please sign in to comment.