Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
}).then(({ body }) : string => {
logOrderResponse(body.id);
if (body && body.id) {
return body.id;
}
throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
});
}
const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();
on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
proxyRest = data;
});
if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
send(parentWin, PROXY_REST, { createAccessToken, createOrder })
.catch(() => {
// pass
});
}
// $FlowFixMe
var distance = ref.distance;
if (distance) {
result = getNthParentFromTop(window, distance);
} else {
result = getParent(window);
}
}
if (type === WINDOW_REFERENCES.GLOBAL) {
// $FlowFixMe
var uid = ref.uid;
var ancestor = getAncestor(window);
if (ancestor) {
for (var _i2 = 0, _getAllFramesInWindow2 = getAllFramesInWindow(ancestor), _length2 = _getAllFramesInWindow2 == null ? 0 : _getAllFramesInWindow2.length; _i2 < _length2; _i2++) {
var frame = _getAllFramesInWindow2[_i2];
var global = globalFor(frame);
if (global && global.windows && global.windows[uid]) {
result = global.windows[uid];
break;
}
}
}
}
if (!result) {
throw new Error('Unable to find ' + type + ' window');
return globalStore('builtinListeners').getOrSet('helloListener', () => {
const listener = listenForHello({ on });
const parent = getAncestor();
if (parent) {
sayHello(parent, { send }).catch(noop);
}
return listener;
});
}
getParentComponentWindow(ref : WindowRef) : CrossDomainWindowType {
const { type } = ref;
if (type === WINDOW_REFERENCES.OPENER) {
return assertExists('opener', getOpener(window));
} else if (type === WINDOW_REFERENCES.PARENT && typeof ref.distance === 'number') {
return assertExists('parent', getNthParentFromTop(window, ref.distance));
} else if (type === WINDOW_REFERENCES.GLOBAL && ref.uid && typeof ref.uid === 'string') {
const { uid } = ref;
const ancestor = getAncestor(window);
if (!ancestor) {
throw new Error(`Can not find ancestor window`);
}
for (const frame of getAllFramesInWindow(ancestor)) {
if (isSameDomain(frame)) {
const global = getGlobal(frame);
if (global && global.windows && global.windows[uid]) {
return global.windows[uid];
}
}
}
}
export function sendToParent(name : string, data : ?Object, options : ?RequestOptionsType) : ZalgoPromise {
let win = getAncestor();
if (!win) {
return new ZalgoPromise((resolve, reject) => reject(new Error('Window does not have a parent')));
}
return send(win, name, data, options);
}
export function sendToParent(name, data, options) {
var win = getAncestor();
if (!win) {
return new ZalgoPromise(function (resolve, reject) {
return reject(new Error('Window does not have a parent'));
});
}
return _send(win, name, data, options);
}
export function initOnReady() {
onHello(function (_ref3) {
var source = _ref3.source,
origin = _ref3.origin;
var promise = global.readyPromises.get(source) || new ZalgoPromise();
promise.resolve({ origin: origin });
global.readyPromises.set(source, promise);
});
var parent = getAncestor();
if (parent) {
sayHello(parent)['catch'](noop);
}
}