-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MWPW-153962: Introduce maslibs query parameter #2544
Changes from 4 commits
dbf15b0
6e5d64f
ee41ef3
06733c0
a2f0a03
b7656eb
5230f70
8e265fb
0396a8a
58d71c0
f6da603
9f12583
8d6dc0b
8492f90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<script src="/libs/scripts/scripts.js" type="module" crossorigin="use-credentials"></script> | ||
<script src="/libs/scripts/scripts.js" type="module"></script> | ||
<link rel="stylesheet" href="/libs/styles/styles.css"/> | ||
<link rel="icon" href="data:," size="any"/> |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -122,6 +122,34 @@ | |||||||||||
let log; | ||||||||||||
let upgradeOffer = null; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Given a url, calculates the hostname of MAS platform. | ||||||||||||
* Supports, www prod, stage, local and feature branches. | ||||||||||||
* @param {string} hostname | ||||||||||||
* @param {string} maslibs | ||||||||||||
* @returns base url for mas platform | ||||||||||||
*/ | ||||||||||||
export function getMasBase(hostname, maslibs) { | ||||||||||||
narcis-radu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
let { baseUrl } = getMasBase; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would always be empty on the first pass, right? I think our pattern here is to expose a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used this pattern in the other functions in merch block. Thus, we can cache the calculated value, and erase it when needed (mostly in tests). Using a module scope variable makes testing harder. You need to provide a utility method to reset the module scope variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But still, on the first pass the baseUrl value would be empty and I don't see a reason why you would need to call the method multiple times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @narcis-radu it is not going to be called to many times but several times definitely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not happy with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, something like |
||||||||||||
if (baseUrl) return baseUrl; | ||||||||||||
baseUrl = 'https://www.adobe.com/mas'; | ||||||||||||
if (!maslibs) return baseUrl; | ||||||||||||
if (maslibs === 'stage') { | ||||||||||||
baseUrl = 'https://www.stage.adobe.com/mas'; | ||||||||||||
} else if (maslibs === 'local') { | ||||||||||||
baseUrl = 'http://localhost:8000'; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be that people use other ports. I, for example, am always using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 6456 is the Milo port to use with I proposed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't find any obvious tool using 8000 port so i'm good with it :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most of the quick local dev servers (e.g. python http.server) use 8000 as the default port and we might have some conflicts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for tacocat we used to use ports 9001-9008 for different modules. |
||||||||||||
} else { | ||||||||||||
const extension = /.live$/.test(hostname) ? 'live' : 'page'; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to revisit this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to discuss offline |
||||||||||||
if (/--/.test(maslibs)) { | ||||||||||||
baseUrl = `https://${maslibs}.hlx.${extension}`; | ||||||||||||
} else { | ||||||||||||
baseUrl = `https://${maslibs}--mas--adobecom.hlx.${extension}`; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about we make 'maslibs' work the same way as 'milolibs' do?
I know the latter is shorter but it involves an additional learning curve for devs and IMO is not worth the space it takes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During stage testing, I think just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i prefer mariia/milolibs's approach, yes :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||||||||||||
} | ||||||||||||
} | ||||||||||||
getMasBase.baseUrl = baseUrl; | ||||||||||||
return baseUrl; | ||||||||||||
} | ||||||||||||
|
||||||||||||
export async function polyfills() { | ||||||||||||
if (polyfills.promise) return polyfills.promise; | ||||||||||||
let isSupported = false; | ||||||||||||
|
@@ -326,15 +354,18 @@ | |||||||||||
} | ||||||||||||
|
||||||||||||
export async function getCheckoutAction(offers, options, imsSignedInPromise) { | ||||||||||||
const [downloadAction, upgradeAction, modalAction] = await Promise.all([ | ||||||||||||
getDownloadAction(options, imsSignedInPromise, offers), | ||||||||||||
getUpgradeAction(options, imsSignedInPromise, offers), | ||||||||||||
getModalAction(offers, options), | ||||||||||||
]).catch((e) => { | ||||||||||||
try { | ||||||||||||
await imsSignedInPromise; | ||||||||||||
const [downloadAction, upgradeAction, modalAction] = await Promise.all([ | ||||||||||||
getDownloadAction(options, imsSignedInPromise, offers), | ||||||||||||
getUpgradeAction(options, imsSignedInPromise, offers), | ||||||||||||
getModalAction(offers, options), | ||||||||||||
]); | ||||||||||||
return downloadAction || upgradeAction || modalAction; | ||||||||||||
} catch (e) { | ||||||||||||
log?.error('Failed to resolve checkout action', e); | ||||||||||||
return []; | ||||||||||||
}); | ||||||||||||
return downloadAction || upgradeAction || modalAction; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
|
@@ -349,7 +380,13 @@ | |||||||||||
const { env, commerce = {}, locale } = getConfig(); | ||||||||||||
commerce.priceLiteralsPromise = fetchLiterals(PRICE_LITERALS_URL); | ||||||||||||
initService.promise = initService.promise ?? polyfills().then(async () => { | ||||||||||||
const commerceLib = await import('../../deps/commerce.js'); | ||||||||||||
const { hostname, searchParams } = new URL(window.location.href); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't the method itself get the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will address this in a different PR. |
||||||||||||
const maslibs = searchParams.get('maslibs'); | ||||||||||||
let commerceLibPath = '../../deps/commerce.js'; | ||||||||||||
if (maslibs) { | ||||||||||||
commerceLibPath = `${getMasBase(hostname, maslibs)}/lib/commerce.js`; | ||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it but I find it harder to read. Most of the time, |
||||||||||||
const commerceLib = await import(commerceLibPath); | ||||||||||||
const service = await commerceLib.init(() => ({ | ||||||||||||
env, | ||||||||||||
commerce, | ||||||||||||
|
@@ -376,8 +413,9 @@ | |||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Checkout parameter can be set Merch link, code config (scripts.js) or be a default from tacocat. | ||||||||||||
* To get the default, 'undefinded' should be passed, empty string will trigger an error! | ||||||||||||
* Checkout parameter can be set on the merch link, | ||||||||||||
* code config (scripts.js) or be a default from tacocat. | ||||||||||||
* To get the default, 'undefined' should be passed, empty string will trigger an error! | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a lint change? (fine with me, just clarifying) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also typo: undefinded :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe |
||||||||||||
* | ||||||||||||
* clientId - code config -> default (adobe_com) | ||||||||||||
* workflow - merch link -> metadata -> default (UCv3) | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const mock = true; | ||
const init = () => ({ imsSignedInPromise: Promise.resolve(), mock }); | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { init }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the details, but this file was previously heavily cached and making changes to it lead to various issues. Are you certain this should be removed? Why do Milo's scripts interfere with Merch logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the use case to render a milo.adobe.com page with different commerce source, @yesil ? may be we could make that change a separate one as i feel like it's not going to be an easy one and we can still play around with most commerce pages on CC & DC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
crossorigin="use-credentials"
all the subsequent js module loaded by/libs/scripts/scripts.js
will be subject to CORS restrictions. Sincemaslibs
param will allow to load commerce.js from a different domain instead of libs/deps folder, this will fail. Withcrossorigin="use-credentials"
we cannot useAccess-Control-Allow-Origin:*
on commerce.js neither, it must be an explicit domain, without wildcards.I don't know changing this file will causes an immediate cache flush, but we don't need it immediately. We can start using it once CDN caches are naturally refreshed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@npeltier we have plenty of test pages under milo and we need the ability to test them with
maslibs="stage"
for example.I think for CC and DC we will be fine since they don't have this crossorigin restriction on the script module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we discussed this offline and agreed we can move this to a second one line PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this change in a separate PR: #2549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I made a mistake in my tests, will close #2549 for now.This PR is still good to go.