From af0683a872071e1f8b3782c83fcc1bc494b0c212 Mon Sep 17 00:00:00 2001 From: Nate Bierdeman Date: Thu, 2 May 2024 16:43:32 -0400 Subject: [PATCH 1/8] Get first render experiments --- .eslintrc.js | 2 +- src/declarations.js | 9 ++++----- src/global.js | 18 ++++-------------- src/global.test.js | 20 +++++++++----------- src/types.js | 4 ++++ test/globals.js | 5 ++--- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0916ba0e..7c0d7bed 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,6 +24,6 @@ module.exports = { // Experiment Variable __DISABLE_SET_COOKIE__: true, - __EXPERIMENTATION__: true, + __FIRST_RENDER_EXPERIMENTS__: true, }, }; diff --git a/src/declarations.js b/src/declarations.js index d8f1e1d6..ec5a706d 100644 --- a/src/declarations.js +++ b/src/declarations.js @@ -4,7 +4,7 @@ import { ENV, COMPONENTS, PROTOCOL } from "@paypal/sdk-constants/src"; // $FlowFixMe[toplevel-library-import] -import type { FundingEligibilityType } from "./types"; +import type { FundingEligibilityType, FirstRenderExperiments } from "./types"; declare var __PROTOCOL__: $Values; declare var __HOST__: string; @@ -33,7 +33,6 @@ declare var __FUNDING_ELIGIBILITY__: FundingEligibilityType; // Experiment Variable declare var __DISABLE_SET_COOKIE__: boolean; -declare var __EXPERIMENTATION__: {| - __EXPERIENCE__?: string, - __TREATMENT__?: string, -|}; + +// $FlowIgnore[value-as-type] +declare var __FIRST_RENDER_EXPERIMENTS__: FirstRenderExperiments; diff --git a/src/global.js b/src/global.js index 6cc19408..198b191e 100644 --- a/src/global.js +++ b/src/global.js @@ -9,7 +9,7 @@ import { } from "@paypal/sdk-constants/src"; import { isDevice } from "@krakenjs/belter/src"; -import type { Experimentation } from "./types"; +import type { FirstRenderExperiments } from "./types"; export function getSDKHost(): string { return __SDK_HOST__; @@ -122,19 +122,9 @@ export function getDisableSetCookie(): boolean { return false; } -export function getExperimentation(): Experimentation | null { - if (typeof __EXPERIMENTATION__ !== "undefined") { - if (__EXPERIMENTATION__) { - const experimation: Experimentation = {}; - if (__EXPERIMENTATION__.__EXPERIENCE__) { - experimation.experience = __EXPERIMENTATION__.__EXPERIENCE__; - } - if (__EXPERIMENTATION__.__TREATMENT__) { - experimation.treatment = __EXPERIMENTATION__.__TREATMENT__; - } - return experimation; - } +export function getFirstRenderExperiments(): FirstRenderExperiments | null { + if (typeof __FIRST_RENDER_EXPERIMENTS__ !== "undefined") { + return __FIRST_RENDER_EXPERIMENTS__; } - return null; } diff --git a/src/global.test.js b/src/global.test.js index fb88703a..784e935d 100644 --- a/src/global.test.js +++ b/src/global.test.js @@ -21,7 +21,7 @@ import { getVersion, getCorrelationID, getPlatform, - getExperimentation, + getFirstRenderExperiments, } from "./global"; describe(`globals cases`, () => { @@ -174,29 +174,27 @@ describe(`globals cases`, () => { }); it("should successfully get experimation value", () => { - window.__EXPERIMENTATION__ = { - __EXPERIENCE__: "1234, 4321", - __TREATMENT__: "8765,7890", + window.__FIRST_RENDER_EXPERIMENTS__ = { + firstRenderExperiment: true, }; const expectedResult = { - experience: "1234, 4321", - treatment: "8765,7890", + firstRenderExperiment: true, }; - const result = getExperimentation(); + const result = getFirstRenderExperiments(); expect(result).toEqual(expectedResult); }); it("should get experimation null value", () => { - window.__EXPERIMENTATION__ = null; + window.__FIRST_RENDER_EXPERIMENTS__ = null; const expectedResult = null; - const result = getExperimentation(); + const result = getFirstRenderExperiments(); expect(result).toEqual(expectedResult); }); it("should get experimation empty value", () => { - window.__EXPERIMENTATION__ = {}; + window.__FIRST_RENDER_EXPERIMENTS__ = {}; const expectedResult = {}; - const result = getExperimentation(); + const result = getFirstRenderExperiments(); expect(result).toEqual(expectedResult); }); }); diff --git a/src/types.js b/src/types.js index 5d86187d..a21278d3 100644 --- a/src/types.js +++ b/src/types.js @@ -21,3 +21,7 @@ export type GetExperimentation = { // eslint-disable-next-line flowtype/no-weak-types [any]: empty, }; + +export type FirstRenderExperiments = { + [key: string]: boolean, +}; diff --git a/test/globals.js b/test/globals.js index 318515f9..77e02edc 100644 --- a/test/globals.js +++ b/test/globals.js @@ -17,9 +17,8 @@ export const sdkClientTestGlobals = { __PAYPAL_API_DOMAIN__: "mock://sandbox.paypal.com", __COMPONENTS__: ["buttons"], __DISABLE_SET_COOKIE__: true, - __EXPERIMENTATION__: { - __EXPERIENCE__: "1122", - __TREATMENT__: "1234", + __FIRST_RENDER_EXPERIMENTS__: { + firstRenderExperiment: true, }, crypto: crypto.webcrypto, }; From b7fbbf4988b2aaf94490feaf9e95b766c5d92ed4 Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Wed, 29 May 2024 11:14:18 -0500 Subject: [PATCH 2/8] update version --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f216247c..da8b86a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paypal/sdk-client", - "version": "4.0.187", + "version": "4.0.188-alpha.0", "description": "Shared config between PayPal/Braintree.", "main": "index.js", "scripts": { @@ -20,8 +20,8 @@ "setup": "npm install && npm run flow-typed", "format": "prettier --write --ignore-unknown .", "format:check": "prettier --check .", - "test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run test:unit", - "webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress", + "test": "npm run format:check && npm run lint && npm run flow && npm run test:unit", + "webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack -- --progress", "test:unit:watch": "vitest --coverage", "test:unit": "vitest run --coverage", "prepublishOnly": "npm run babel", From 45b5629e8ce0549c1f898423edeeb4bba7936da9 Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Wed, 29 May 2024 15:24:29 -0500 Subject: [PATCH 3/8] add babel script to build command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da8b86a5..906da53a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "babel": "babel ./server --ignore=node_modules --out-dir ./server", - "build": "npm run test && npm run doc", + "build": "npm run test && npm run doc & npm run babel", "clean": "rimraf dist coverage", "debug": "cross-env NODE_ENV=debug", "doc": "esdoc", From d3b0880548bbf3df31c6971140bec7efddd52d5b Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Thu, 30 May 2024 15:36:39 -0500 Subject: [PATCH 4/8] put back getExperimentation functon and correct package version --- package.json | 2 +- src/global.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 906da53a..e445660c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paypal/sdk-client", - "version": "4.0.188-alpha.0", + "version": "4.0.189", "description": "Shared config between PayPal/Braintree.", "main": "index.js", "scripts": { diff --git a/src/global.js b/src/global.js index 198b191e..dc048b1e 100644 --- a/src/global.js +++ b/src/global.js @@ -122,6 +122,23 @@ export function getDisableSetCookie(): boolean { return false; } +export function getExperimentation(): Experimentation | null { + if (typeof __EXPERIMENTATION__ !== "undefined") { + if (__EXPERIMENTATION__) { + const experimentation: Experimentation = {}; + if (__EXPERIMENTATION__.__EXPERIENCE__) { + experimentation.experience = __EXPERIMENTATION__.__EXPERIENCE__; + } + if (__EXPERIMENTATION__.__TREATMENT__) { + experimentation.treatment = __EXPERIMENTATION__.__TREATMENT__; + } + return experimentation; + } + } + + return null; +} + export function getFirstRenderExperiments(): FirstRenderExperiments | null { if (typeof __FIRST_RENDER_EXPERIMENTS__ !== "undefined") { return __FIRST_RENDER_EXPERIMENTS__; From 4a645230dd49ea878a4052057b452e27fde97f40 Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Thu, 30 May 2024 15:45:46 -0500 Subject: [PATCH 5/8] add todo comment --- src/global.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/global.js b/src/global.js index dc048b1e..1acd3fbe 100644 --- a/src/global.js +++ b/src/global.js @@ -122,6 +122,7 @@ export function getDisableSetCookie(): boolean { return false; } +// TODO first-render-experiment-cleanup any thing using this function should use getFirstRenderExperiments export function getExperimentation(): Experimentation | null { if (typeof __EXPERIMENTATION__ !== "undefined") { if (__EXPERIMENTATION__) { From 10b3cf6a12a3a0c4da1233dbf44505b426b85e2d Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Mon, 3 Jun 2024 10:32:48 -0500 Subject: [PATCH 6/8] add back experimentaion runtime var --- .eslintrc.js | 2 ++ src/declarations.js | 6 ++++++ src/global.js | 2 +- src/global.test.js | 37 ++++++++++++++++++++++++++++++++++--- test/globals.js | 5 +++++ 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7c0d7bed..5d08a5dc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,6 +24,8 @@ module.exports = { // Experiment Variable __DISABLE_SET_COOKIE__: true, + // TODO first-render-experiment-cleanup + __EXPERIMENTATION__: true, __FIRST_RENDER_EXPERIMENTS__: true, }, }; diff --git a/src/declarations.js b/src/declarations.js index ec5a706d..c5bdfd2f 100644 --- a/src/declarations.js +++ b/src/declarations.js @@ -34,5 +34,11 @@ declare var __FUNDING_ELIGIBILITY__: FundingEligibilityType; // Experiment Variable declare var __DISABLE_SET_COOKIE__: boolean; +// TODO first-render-experiment-cleanup +declare var __EXPERIMENTATION__: {| + __EXPERIENCE__?: string, + __TREATMENT__?: string, +|}; + // $FlowIgnore[value-as-type] declare var __FIRST_RENDER_EXPERIMENTS__: FirstRenderExperiments; diff --git a/src/global.js b/src/global.js index 1acd3fbe..31a996ab 100644 --- a/src/global.js +++ b/src/global.js @@ -9,7 +9,7 @@ import { } from "@paypal/sdk-constants/src"; import { isDevice } from "@krakenjs/belter/src"; -import type { FirstRenderExperiments } from "./types"; +import type { Experimentation, FirstRenderExperiments } from "./types"; export function getSDKHost(): string { return __SDK_HOST__; diff --git a/src/global.test.js b/src/global.test.js index 784e935d..28ac040e 100644 --- a/src/global.test.js +++ b/src/global.test.js @@ -21,6 +21,7 @@ import { getVersion, getCorrelationID, getPlatform, + getExperimentation, getFirstRenderExperiments, } from "./global"; @@ -173,7 +174,37 @@ describe(`globals cases`, () => { expect(result).toEqual(window.__FUNDING_ELIGIBILITY__); }); - it("should successfully get experimation value", () => { + // TODO first-render-experiment-cleanup + it("should successfully get experimentation value", () => { + window.__EXPERIMENTATION__ = { + __EXPERIENCE__: "1234, 4321", + __TREATMENT__: "8765,7890", + }; + const expectedResult = { + experience: "1234, 4321", + treatment: "8765,7890", + }; + const result = getExperimentation(); + expect(result).toEqual(expectedResult); + }); + + // TODO first-render-experiment-cleanup + it("should get experimentation null value", () => { + window.__EXPERIMENTATION__ = null; + const expectedResult = null; + const result = getExperimentation(); + expect(result).toEqual(expectedResult); + }); + + // TODO first-render-experiment-cleanup + it("should get experimentation empty value", () => { + window.__EXPERIMENTATION__ = {}; + const expectedResult = {}; + const result = getExperimentation(); + expect(result).toEqual(expectedResult); + }); + + it("should successfully get first render experiment value", () => { window.__FIRST_RENDER_EXPERIMENTS__ = { firstRenderExperiment: true, }; @@ -184,14 +215,14 @@ describe(`globals cases`, () => { expect(result).toEqual(expectedResult); }); - it("should get experimation null value", () => { + it("should get first render experiment null value", () => { window.__FIRST_RENDER_EXPERIMENTS__ = null; const expectedResult = null; const result = getFirstRenderExperiments(); expect(result).toEqual(expectedResult); }); - it("should get experimation empty value", () => { + it("should get first render experiment empty value", () => { window.__FIRST_RENDER_EXPERIMENTS__ = {}; const expectedResult = {}; const result = getFirstRenderExperiments(); diff --git a/test/globals.js b/test/globals.js index 77e02edc..b78fc97b 100644 --- a/test/globals.js +++ b/test/globals.js @@ -17,6 +17,11 @@ export const sdkClientTestGlobals = { __PAYPAL_API_DOMAIN__: "mock://sandbox.paypal.com", __COMPONENTS__: ["buttons"], __DISABLE_SET_COOKIE__: true, + // TODO first-render-experiment-cleanup + __EXPERIMENTATION__: { + __EXPERIENCE__: "1122", + __TREATMENT__: "1234", + }, __FIRST_RENDER_EXPERIMENTS__: { firstRenderExperiment: true, }, From 185aa900a107edfb54c1a5143d6823fbde4b2d6d Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Mon, 3 Jun 2024 10:36:38 -0500 Subject: [PATCH 7/8] add cleanup comments --- src/types.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types.js b/src/types.js index a21278d3..ff4f7627 100644 --- a/src/types.js +++ b/src/types.js @@ -4,6 +4,7 @@ export const _TYPES = true; export * from "@paypal/sdk-constants/src/types"; +// TODO first-render-experiment-cleanup export type Experimentation = { experience?: string, treatment?: string, @@ -13,6 +14,7 @@ export type Experimentation = { [any]: empty, }; +// TODO first-render-experiment-cleanup export type GetExperimentation = { __EXPERIENCE__?: string, __TREATMENT__?: string, From 89561bfadd93058115f401bc5c6f84096a1cff7e Mon Sep 17 00:00:00 2001 From: Nikolaus Roman Date: Tue, 4 Jun 2024 16:54:34 -0500 Subject: [PATCH 8/8] remove empty object from getFirstRenderExperiments if global is undefined --- src/global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global.js b/src/global.js index 31a996ab..9f9e5a00 100644 --- a/src/global.js +++ b/src/global.js @@ -144,5 +144,5 @@ export function getFirstRenderExperiments(): FirstRenderExperiments | null { if (typeof __FIRST_RENDER_EXPERIMENTS__ !== "undefined") { return __FIRST_RENDER_EXPERIMENTS__; } - return null; + return {}; }