From 0fcf8f4bbb40743ae549c8d3664737a4b227472d Mon Sep 17 00:00:00 2001 From: James Tsay Date: Thu, 9 Jan 2025 17:45:41 -0800 Subject: [PATCH 1/2] Add SUSI Light Block --- acrobat/blocks/susi-light/susi-light.css | 5 + acrobat/blocks/susi-light/susi-light.js | 125 ++++++++++++++++++ test/integration/susi-light/mocks/body.html | 6 + test/integration/susi-light/mocks/head.html | 2 + test/integration/susi-light/susi-light.int.js | 28 ++++ 5 files changed, 166 insertions(+) create mode 100644 acrobat/blocks/susi-light/susi-light.css create mode 100644 acrobat/blocks/susi-light/susi-light.js create mode 100644 test/integration/susi-light/mocks/body.html create mode 100644 test/integration/susi-light/mocks/head.html create mode 100644 test/integration/susi-light/susi-light.int.js diff --git a/acrobat/blocks/susi-light/susi-light.css b/acrobat/blocks/susi-light/susi-light.css new file mode 100644 index 00000000..ce4a7199 --- /dev/null +++ b/acrobat/blocks/susi-light/susi-light.css @@ -0,0 +1,5 @@ +/* preserving modal space for ux */ +.dialog-modal:has(.susi-light) { + width: 360px; + min-height: 462px; +} \ No newline at end of file diff --git a/acrobat/blocks/susi-light/susi-light.js b/acrobat/blocks/susi-light/susi-light.js new file mode 100644 index 00000000..08a99d7f --- /dev/null +++ b/acrobat/blocks/susi-light/susi-light.js @@ -0,0 +1,125 @@ +/* eslint-disable chai-friendly/no-unused-expressions */ +/* eslint-disable camelcase */ +/* eslint-disable compat/compat */ +/* eslint-disable no-underscore-dangle */ +import { setLibs, getEnv } from '../../scripts/utils.js'; + +const miloLibs = setLibs('/libs'); +const { createTag, loadScript, getConfig } = await import(`${miloLibs}/utils/utils.js`); + +const variant = 'standard'; +const isStage = ['stage', 'dev'].includes(getEnv()); + +const onRedirect = (e) => { + // eslint-disable-next-line no-console + console.log('redirecting to:', e.detail); + setTimeout(() => { + window.location.assign(e.detail); + // temporary solution: allows analytics to go thru + }, 100); +}; +const onError = (e) => { + window.lana?.log('on error:', e); +}; + +export function loadWrapper() { + const CDN_URL = `https://auth-light.identity${ + isStage ? '-stage' : '' + }.adobe.com/sentry/wrapper.js`; + return loadScript(CDN_URL); +} + +function getDestURL(url) { + let destURL; + try { + destURL = new URL(url); + } catch (err) { + window.lana?.log(`invalid redirect uri for susi-light: ${url}`); + destURL = new URL('https://www.adobe.com'); + } + if (isStage) { + destURL.hostname = 'www.stage.adobe.com'; + } + return destURL.toString(); +} + +export default async function init(el) { + const rows = el.querySelectorAll(':scope> div > div'); + const redirectUrl = rows[0]?.textContent?.trim().toLowerCase(); + const { client_id, redirect_uri } = window.adobeid; + const title = rows[2]?.textContent?.trim(); + const authParams = { + dt: false, + locale: getConfig().locale.ietf.toLowerCase(), + response_type: 'code', + client_id, + redirect_uri: redirectUrl || redirect_uri, + scope: 'AdobeID,openid', + }; + const destURL = getDestURL(redirectUrl); + const goDest = () => window.location.assign(destURL); + if (window.feds?.utilities?.imslib) { + const { imslib } = window.feds.utilities; + imslib.isReady() && imslib.isSignedInUser() && goDest(); + imslib.onReady().then(() => imslib.isSignedInUser() && goDest()); + } + el.innerHTML = ''; + await loadWrapper(); + const config = { consentProfile: 'free' }; + if (title) { + config.title = title; + } + const susi = createTag('susi-sentry-light'); + susi.authParams = authParams; + susi.authParams.redirect_uri = destURL; + susi.config = config; + if (isStage) susi.stage = 'true'; + susi.variant = variant; + function sendEventToAnalytics(type, eventName) { + const sendEvent = () => { + window._satellite.track('event', { + xdm: {}, + data: { + eventType: 'web.webinteraction.linkClicks', + web: { + webInteraction: { + name: eventName, + linkClicks: { value: 1 }, + type, + }, + }, + _adobe_corpnew: { + digitalData: { + primaryEvent: { + eventInfo: { + eventName, + client_id, + }, + }, + }, + }, + }, + }); + }; + if (window._satellite?.track) { + sendEvent(); + } else { + window.addEventListener( + 'alloy_sendEvent', + () => { + sendEvent(); + }, + { once: true }, + ); + } + } + + const onAnalytics = (e) => { + const { type, event } = e.detail; + sendEventToAnalytics(type, event); + }; + susi.addEventListener('redirect', onRedirect); + susi.addEventListener('on-error', onError); + susi.addEventListener('on-analytics', onAnalytics); + el.append(susi); +} diff --git a/test/integration/susi-light/mocks/body.html b/test/integration/susi-light/mocks/body.html new file mode 100644 index 00000000..8e4becd0 --- /dev/null +++ b/test/integration/susi-light/mocks/body.html @@ -0,0 +1,6 @@ +
+
+
https://www.adobe.com +
+
+
\ No newline at end of file diff --git a/test/integration/susi-light/mocks/head.html b/test/integration/susi-light/mocks/head.html new file mode 100644 index 00000000..cb46cf64 --- /dev/null +++ b/test/integration/susi-light/mocks/head.html @@ -0,0 +1,2 @@ + + diff --git a/test/integration/susi-light/susi-light.int.js b/test/integration/susi-light/susi-light.int.js new file mode 100644 index 00000000..5c35f328 --- /dev/null +++ b/test/integration/susi-light/susi-light.int.js @@ -0,0 +1,28 @@ +/* eslint-env mocha */ +/* eslint-disable no-unused-vars */ +import { readFile } from '@web/test-runner-commands'; +import { expect } from '@esm-bundle/chai'; +import { setLibs } from '../../../acrobat/scripts/utils.js'; + +const miloLibs = setLibs('/libs'); +const { setConfig } = await import(`${miloLibs}/utils/utils.js`); + +document.head.innerHTML = await readFile({ path: './mocks/head.html' }); +document.body.innerHTML = await readFile({ path: './mocks/body.html' }); + +describe('Susi-light', async () => { + before(async () => { + setConfig({ origin: '', locale: { ietf: 'en-us' } }); + window.adobeid = { client_id: 'test', redirect_uri: 'https://www.adobe.com' }; + const block = document.querySelector('.susi-light'); + const { default: init } = await import( + '../../../acrobat/blocks/susi-light/susi-light.js' + ); + init(block); + }); + + it('Susi-light gets decorated', () => { + const block = document.querySelector('.susi-light'); + expect(block).to.exist; + }); +}); From 8b9b2f1b798cbc1f04f581d335cce9ba0bdf4984 Mon Sep 17 00:00:00 2001 From: James Tsay Date: Thu, 9 Jan 2025 19:44:11 -0800 Subject: [PATCH 2/2] Update client_id --- acrobat/blocks/susi-light/susi-light.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acrobat/blocks/susi-light/susi-light.js b/acrobat/blocks/susi-light/susi-light.js index 08a99d7f..a1f71702 100644 --- a/acrobat/blocks/susi-light/susi-light.js +++ b/acrobat/blocks/susi-light/susi-light.js @@ -52,7 +52,7 @@ export default async function init(el) { dt: false, locale: getConfig().locale.ietf.toLowerCase(), response_type: 'code', - client_id, + client_id: 'AdobeExpressWeb', redirect_uri: redirectUrl || redirect_uri, scope: 'AdobeID,openid', };