From c33c00a3325cbfb63c485cf7a265b6ac5f600eb1 Mon Sep 17 00:00:00 2001 From: Liz Martinez <40329316+elizabethmv@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:55:42 -0600 Subject: [PATCH 1/2] Add SDK token for PayPal domain --- src/script.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/script.js b/src/script.js index 8f17f5c8..a3aa8f0a 100644 --- a/src/script.js +++ b/src/script.js @@ -37,6 +37,7 @@ import { import { getPath, getDefaultNamespace, getSDKHost } from "./global"; import { CLIENT_ID_ALIAS } from "./config"; import { getComputedLocales } from "./utils"; +import { isPayPalDomain } from "./domains"; type GetSDKScript = () => HTMLScriptElement; @@ -338,6 +339,10 @@ export function getUserExperienceFlow(): ?string { return getSDKAttribute(SDK_SETTINGS.USER_EXPERIENCE_FLOW); } +export function getSDKToken(): ?string { + return isPayPalDomain() ? getSDKAttribute(SDK_SETTINGS.SDK_TOKEN) : ""; +} + // whether in zoid window export function isChildWindow(): boolean { return Boolean(window.xprops); From c75e1aa0218c13a4465631e4ae63be139c3ca045 Mon Sep 17 00:00:00 2001 From: Liz Martinez <40329316+elizabethmv@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:58:54 -0600 Subject: [PATCH 2/2] Remove domain check --- src/script.js | 3 +-- test/client/scriptUtils.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index a3aa8f0a..5db986e1 100644 --- a/src/script.js +++ b/src/script.js @@ -37,7 +37,6 @@ import { import { getPath, getDefaultNamespace, getSDKHost } from "./global"; import { CLIENT_ID_ALIAS } from "./config"; import { getComputedLocales } from "./utils"; -import { isPayPalDomain } from "./domains"; type GetSDKScript = () => HTMLScriptElement; @@ -340,7 +339,7 @@ export function getUserExperienceFlow(): ?string { } export function getSDKToken(): ?string { - return isPayPalDomain() ? getSDKAttribute(SDK_SETTINGS.SDK_TOKEN) : ""; + return getSDKAttribute(SDK_SETTINGS.SDK_TOKEN); } // whether in zoid window diff --git a/test/client/scriptUtils.js b/test/client/scriptUtils.js index 5f529d84..e9d1dfa9 100644 --- a/test/client/scriptUtils.js +++ b/test/client/scriptUtils.js @@ -10,6 +10,7 @@ import { getCSPNonce, getEnableThreeDomainSecure, getUserExperienceFlow, + getSDKToken, isChildWindow, } from "../../src/script"; import { insertMockSDKScript } from "../../src"; @@ -162,6 +163,21 @@ describe(`script utils cases`, () => { } }); + it("getSDKToken should return a sdk-token string", () => { + insertMockSDKScript({ + attributes: { + "data-sdk-client-token": "sdk-token", + }, + }); + const result = getSDKToken(); + + if (result !== "sdk-token") { + throw new Error( + `should return the "sdk-token" word, but got: ${String(result)}` + ); + } + }); + it("getCSPNonce should return a data-csp-nonce string", () => { insertMockSDKScript({ attributes: {