Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function start(url : string) : ZalgoPromise {
const params = parseQuery(url.split('?')[1]);
const body = document.body;
if (!body) {
throw new Error(`No document body available to render to`);
}
return new ZalgoPromise((resolve, reject) => {
contingencyResolveFunction = resolve;
// $FlowFixMe
contingency.Component({
action: params.action,
xcomponent: '1',
flow: params.flow,
cart_id: params.cart_id,
onContingencyResult: (err, result) => {
const onLoad = () => {
if (!win) {
throw new Error(`Expecred win to be set`);
}
const [ stringUrl, stringQuery ] = currentUrl.split('?');
if (expectedUrl && stringUrl !== expectedUrl) {
throw new Error(`Expected url to be ${ expectedUrl }, got ${ stringUrl }`);
}
const query = parseQuery(stringQuery);
for (const key of expectedQuery) {
if (!query[key]) {
throw new Error(`Expected query param: ${ key }`);
}
}
onOpen({
win,
url: currentUrl,
query
});
};
}).then(res => {
if (!res.redirectUrl) {
throw new Error(`Expected native redirect url`);
}
const redirectQuery = parseQuery(res.redirectUrl.split('?')[1]);
if (!redirectQuery.sdkMeta) {
throw new Error(`Expected sdkMeta to be passed in url`);
}
if (!redirectQuery.sessionUID) {
throw new Error(`Expected sessionUID to be passed in url`);
}
if (!redirectQuery.pageUrl) {
throw new Error(`Expected pageUrl to be passed in url`);
}
if (!redirectQuery.buttonSessionID) {
throw new Error(`Expected sdkMeta to be passed in url`);
}
window.open = expect('windowOpen', (url) => {
window.open = windowOpen;
if (!url) {
throw new Error(`Expected url to be immediately passed to window.open`);
}
if (url.indexOf('/smart/checkout/native') === -1) {
throw new Error(`Expected paypal native url`);
}
const query = parseQuery(url.split('?')[1]);
const { sessionUID, pageUrl } = query;
if (!sessionUID) {
throw new Error(`Expected sessionUID to be passed in url`);
}
if (!pageUrl) {
throw new Error(`Expected pageUrl to be passed in url`);
}
win = {
location: {
href: url
},
closed: false,
close: avoid('close')
export function getSDKQueryParams() {
var script = getSDKScript();
return parseQuery(script.src.split('?')[1] || '');
}
export function getSDKQueryParams() : { [string] : string } {
const script = getSDKScript();
return parseQuery(script.src.split('?')[1] || '');
}