From 81e830cbaa492f5e36da0286abe42440caa639cb Mon Sep 17 00:00:00 2001 From: elizabethmv <40329316+elizabethmv@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:08:11 -0600 Subject: [PATCH] Add SDK token (#172) --- src/script.js | 4 ++++ test/client/scriptUtils.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/script.js b/src/script.js index 8f17f5c8..5db986e1 100644 --- a/src/script.js +++ b/src/script.js @@ -338,6 +338,10 @@ export function getUserExperienceFlow(): ?string { return getSDKAttribute(SDK_SETTINGS.USER_EXPERIENCE_FLOW); } +export function getSDKToken(): ?string { + return getSDKAttribute(SDK_SETTINGS.SDK_TOKEN); +} + // whether in zoid window export function isChildWindow(): boolean { return Boolean(window.xprops); 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: {