-
Notifications
You must be signed in to change notification settings - Fork 576
/
Copy pathsecurity.js
41 lines (34 loc) · 1.05 KB
/
security.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* @flow */
import { isSameDomain } from "@krakenjs/cross-domain-utils/src";
import { supportsPopups } from "@krakenjs/belter/src";
import { getEnv, isPayPalDomain } from "@paypal/sdk-client/src";
import { ENV } from "@paypal/sdk-constants/src";
export function allowIframe(): boolean {
if (!isPayPalDomain()) {
throw new Error(
`Can only determine if iframe rendering is allowed on paypal domain`
);
}
if (!supportsPopups()) {
return true;
}
const parentComponentWindow = window.xprops && window.xprops.getParent();
if (parentComponentWindow && isSameDomain(parentComponentWindow)) {
return true;
}
return false;
}
/* eslint-disable no-confusing-arrow */
// $FlowIssue
export const protectedExport = (unprotectedExport) =>
isPayPalDomain() ? unprotectedExport : undefined;
/* eslint-enable no-confusing-arrow */
// $FlowIssue
export const localOrStageExport = (unprotectedExport) => {
const env = getEnv();
if (env === ENV.LOCAL || env === ENV.STAGE) {
return unprotectedExport;
} else {
return undefined;
}
};