From e980158bf9bba69cf191ea510fd32bdadbfe084a Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Fri, 3 Nov 2023 15:31:27 -0400 Subject: [PATCH 01/31] demo axo component --- package.json | 1 + src/interface/axo.js | 7 +++++++ src/zoid/axo/component.jsx | 20 ++++++++++++++++++++ src/zoid/axo/index.js | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 src/interface/axo.js create mode 100644 src/zoid/axo/component.jsx create mode 100644 src/zoid/axo/index.js diff --git a/package.json b/package.json index 4993ffcc0d..3dade67ad4 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "@krakenjs/zoid": "^10.3.1", "@paypal/common-components": "^1.0.35", "@paypal/funding-components": "^1.0.31", + "@paypal/connect-loader-component": "^1.0.0", "@paypal/sdk-client": "^4.0.176", "@paypal/sdk-constants": "^1.0.133", "@paypal/sdk-logos": "^2.2.6" diff --git a/src/interface/axo.js b/src/interface/axo.js new file mode 100644 index 0000000000..1122901ca0 --- /dev/null +++ b/src/interface/axo.js @@ -0,0 +1,7 @@ +/* @flow */ +import type { LazyExport } from "../types"; +import { getAxoComponent, type AXOComponent } from "../zoid/axo"; + +export const AXO: LazyExport = { + __get__: getAxoComponent, +}; diff --git a/src/zoid/axo/component.jsx b/src/zoid/axo/component.jsx new file mode 100644 index 0000000000..2d048ceaf2 --- /dev/null +++ b/src/zoid/axo/component.jsx @@ -0,0 +1,20 @@ +/* @flow */ +/** @jsx node */ +/* eslint max-lines: 0 */ + +import { loadConnectScript } from "@paypal/connect-loader-component"; +import { getClientID, getClientMetadataID } from "@paypal/sdk-client/src"; +// eslint-disable-next-line flowtype/no-weak-types +export type AXOComponent = any; + +export function getAxoComponent(): AXOComponent { + const cmid = getClientMetadataID(); + const clientID = getClientID(); + // this will change to whatever options we received + // from the merchant + try { + return loadConnectScript({ cmid, clientID }); + } catch (error) { + return new Error(error); + } +} diff --git a/src/zoid/axo/index.js b/src/zoid/axo/index.js new file mode 100644 index 0000000000..c35c42e094 --- /dev/null +++ b/src/zoid/axo/index.js @@ -0,0 +1,3 @@ +/* @flow */ + +export * from "./component"; From 358c9d42bceaf60e8a71d3ccdf7be80f412720d2 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Mon, 6 Nov 2023 11:07:21 -0800 Subject: [PATCH 02/31] rename to connect, move code directly for now --- src/interface/axo.js | 7 ------- src/interface/connect.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) delete mode 100644 src/interface/axo.js create mode 100644 src/interface/connect.js diff --git a/src/interface/axo.js b/src/interface/axo.js deleted file mode 100644 index 1122901ca0..0000000000 --- a/src/interface/axo.js +++ /dev/null @@ -1,7 +0,0 @@ -/* @flow */ -import type { LazyExport } from "../types"; -import { getAxoComponent, type AXOComponent } from "../zoid/axo"; - -export const AXO: LazyExport = { - __get__: getAxoComponent, -}; diff --git a/src/interface/connect.js b/src/interface/connect.js new file mode 100644 index 0000000000..444b43e070 --- /dev/null +++ b/src/interface/connect.js @@ -0,0 +1,39 @@ +/* @flow */ +import type { LazyExport } from "../types"; +import { getAxoComponent, type AXOComponent } from "../zoid/axo"; +import { loadConnectScript } from "@paypal/connect-loader-component"; +import { + getClientID, + getClientMetadataID, + getUserIDToken, +} from "@paypal/sdk-client/src"; + +// eslint-disable-next-line flowtype/no-weak-types +export type AXOComponent = any; + +// TODO: What's the expected structure/approach for this interface. It's not a zoid +// scenario, so what do we return? +// -> Looks like it returns a function that accepts the props +// How do we define the input of merchant params here? +export const AXO: LazyExport = { + __get__: () => { + return async (merchantProps) => { + const cmid = getClientMetadataID(); + const clientID = getClientID(); + const userIdToken = getUserIDToken(); + // TODO: Sort out integration specifics for inputs + try { + const loadResult = await loadConnectScript(); + return window.braintree.connect.create({ + ...loadResult.metadata, + ...merchantProps, + cmid, + clientID, + userIdToken, + }); + } catch (error) { + return new Error(error); + } + }; + }, +}; From b6fa60d7ec481a5156c9bfbfaf4e4811ee1d24f3 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Mon, 6 Nov 2023 11:59:10 -0800 Subject: [PATCH 03/31] add connect interface unit test file --- src/interface/connect.test.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/interface/connect.test.js diff --git a/src/interface/connect.test.js b/src/interface/connect.test.js new file mode 100644 index 0000000000..e42ef48faa --- /dev/null +++ b/src/interface/connect.test.js @@ -0,0 +1 @@ +describe("connect.js", () => {}); From ccd3a0903657f120fadab11c8f168c7a6165a718 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Mon, 6 Nov 2023 15:14:15 -0800 Subject: [PATCH 04/31] remove axo zoid, unit tests --- src/interface/connect.js | 6 +-- src/interface/connect.test.js | 75 ++++++++++++++++++++++++++++++++++- src/zoid/axo/component.jsx | 20 ---------- src/zoid/axo/index.js | 3 -- 4 files changed, 77 insertions(+), 27 deletions(-) delete mode 100644 src/zoid/axo/component.jsx delete mode 100644 src/zoid/axo/index.js diff --git a/src/interface/connect.js b/src/interface/connect.js index 444b43e070..e3d019fc93 100644 --- a/src/interface/connect.js +++ b/src/interface/connect.js @@ -1,6 +1,4 @@ /* @flow */ -import type { LazyExport } from "../types"; -import { getAxoComponent, type AXOComponent } from "../zoid/axo"; import { loadConnectScript } from "@paypal/connect-loader-component"; import { getClientID, @@ -8,6 +6,8 @@ import { getUserIDToken, } from "@paypal/sdk-client/src"; +import type { LazyExport } from "../types"; + // eslint-disable-next-line flowtype/no-weak-types export type AXOComponent = any; @@ -15,7 +15,7 @@ export type AXOComponent = any; // scenario, so what do we return? // -> Looks like it returns a function that accepts the props // How do we define the input of merchant params here? -export const AXO: LazyExport = { +export const connect: LazyExport = { __get__: () => { return async (merchantProps) => { const cmid = getClientMetadataID(); diff --git a/src/interface/connect.test.js b/src/interface/connect.test.js index e42ef48faa..b7f3a11236 100644 --- a/src/interface/connect.test.js +++ b/src/interface/connect.test.js @@ -1 +1,74 @@ -describe("connect.js", () => {}); +/* @flow */ + +import { + getClientID, + getClientMetadataID, + getUserIDToken, +} from "@paypal/sdk-client/src"; +import { loadConnectScript } from "@paypal/connect-loader-component"; +import { describe, expect, test, vi } from "vitest"; + +import { connect } from "./connect"; + +describe("connect: LazyExport AXOComponent", () => { + beforeEach(() => { + window.braintree = { + connect: { + create: vi.fn(), + }, + }; + + vi.mock("@paypal/sdk-client/src", () => { + return { + getClientID: vi.fn(), + getClientMetadataID: vi.fn(), + getUserIDToken: vi.fn(), + }; + }); + + vi.mock("@paypal/connect-loader-component", () => { + return { + loadConnectScript: vi + .fn() + .mockResolvedValue({ metadata: { someData: "data" } }), + }; + }); + + getClientID.mockReturnValue("mock-client-id"); + getClientMetadataID.mockReturnValue("mock-cmid"); + getUserIDToken.mockReturnValue("mock-uid"); + }); + + test("loadConnectScript and window.braintree.connect.create are called with proper data", async () => { + const mockProps = { someProp: "value" }; + const result = connect.__get__(); + + await result(mockProps); + + expect(getClientID).toHaveBeenCalled(); + expect(getClientMetadataID).toHaveBeenCalled(); + expect(getUserIDToken).toHaveBeenCalled(); + expect(loadConnectScript).toHaveBeenCalled(); + + expect(window.braintree.connect.create).toHaveBeenCalledWith({ + someData: "data", + ...mockProps, + clientID: "mock-client-id", + cmid: "mock-cmid", + userIdToken: "mock-uid", + }); + }); + + test("loadConnectScript failure is handled", async () => { + const mockProps = { someProp: "value" }; + const errorMessage = "Something went wrong"; + // eslint-disable-next-line no-import-assign + loadConnectScript = vi.fn().mockRejectedValue(errorMessage); + + const result = connect.__get__(); + const error = await result(mockProps); + + expect(error).toBeInstanceOf(Error); + expect(error.message).toEqual(errorMessage); + }); +}); diff --git a/src/zoid/axo/component.jsx b/src/zoid/axo/component.jsx deleted file mode 100644 index 2d048ceaf2..0000000000 --- a/src/zoid/axo/component.jsx +++ /dev/null @@ -1,20 +0,0 @@ -/* @flow */ -/** @jsx node */ -/* eslint max-lines: 0 */ - -import { loadConnectScript } from "@paypal/connect-loader-component"; -import { getClientID, getClientMetadataID } from "@paypal/sdk-client/src"; -// eslint-disable-next-line flowtype/no-weak-types -export type AXOComponent = any; - -export function getAxoComponent(): AXOComponent { - const cmid = getClientMetadataID(); - const clientID = getClientID(); - // this will change to whatever options we received - // from the merchant - try { - return loadConnectScript({ cmid, clientID }); - } catch (error) { - return new Error(error); - } -} diff --git a/src/zoid/axo/index.js b/src/zoid/axo/index.js deleted file mode 100644 index c35c42e094..0000000000 --- a/src/zoid/axo/index.js +++ /dev/null @@ -1,3 +0,0 @@ -/* @flow */ - -export * from "./component"; From 055b030d28f1de8b5323e31cb9a50bc279b89922 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Mon, 6 Nov 2023 19:06:59 -0800 Subject: [PATCH 05/31] add route for connect module --- __sdk__.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/__sdk__.js b/__sdk__.js index 9dd73d4343..e4a93851fd 100644 --- a/__sdk__.js +++ b/__sdk__.js @@ -62,6 +62,9 @@ module.exports = { entry: "./src/interface/wallet", globals, }, + connect: { + entry: "./src/interface/connect", + }, // @deprecated - renamed to payment-fields to be removed fields: { entry: "./src/interface/fields", From ccb4b5f788ba826a5b1d0d346ae1b165a380a9ca Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Tue, 7 Nov 2023 09:53:14 -0800 Subject: [PATCH 06/31] refactor: move axo/connect under src --- __sdk__.js | 3 ++- src/connect/component.jsx | 33 +++++++++++++++++++++++++++++++++ src/connect/interface.js | 10 ++++++++++ src/interface/connect.js | 39 --------------------------------------- 4 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 src/connect/component.jsx create mode 100644 src/connect/interface.js delete mode 100644 src/interface/connect.js diff --git a/__sdk__.js b/__sdk__.js index e4a93851fd..0759a7714f 100644 --- a/__sdk__.js +++ b/__sdk__.js @@ -63,7 +63,8 @@ module.exports = { globals, }, connect: { - entry: "./src/interface/connect", + entry: "./src/connect/interface", + globals }, // @deprecated - renamed to payment-fields to be removed fields: { diff --git a/src/connect/component.jsx b/src/connect/component.jsx new file mode 100644 index 0000000000..521feb1250 --- /dev/null +++ b/src/connect/component.jsx @@ -0,0 +1,33 @@ +/* @flow */ +import { loadConnectScript } from "@paypal/connect-loader-component"; +import { + getClientID, + getClientMetadataID, + getUserIDToken, +} from "@paypal/sdk-client/src"; + +// eslint-disable-next-line flowtype/no-weak-types +export type ConnectComponent = any; + +// TODO: What's the expected structure/approach for this interface. It's not a zoid +// scenario, so what do we return? +// -> Looks like it returns a function that accepts the props +// How do we define the input of merchant params here? +export const getConnectComponent = async (merchantProps) => { + const cmid = getClientMetadataID(); + const clientID = getClientID(); + const userIdToken = getUserIDToken(); + // TODO: Sort out integration specifics for inputs + try { + const loadResult = await loadConnectScript(); + return window.braintree.connect.create({ + ...loadResult.metadata, + ...merchantProps, + cmid, + clientID, + userIdToken, + }); + } catch (error) { + return new Error(error); + } +}; diff --git a/src/connect/interface.js b/src/connect/interface.js new file mode 100644 index 0000000000..42705472cf --- /dev/null +++ b/src/connect/interface.js @@ -0,0 +1,10 @@ +/* @flow */ +/* eslint import/no-deprecated: 0 */ + +import type { LazyExport } from "../types"; + +import { getConnectComponent, type ConnectComponent } from "./component"; + +export const Connect: LazyExport = async (merchantProps) => { + return await getConnectComponent(merchantProps); +}; diff --git a/src/interface/connect.js b/src/interface/connect.js deleted file mode 100644 index e3d019fc93..0000000000 --- a/src/interface/connect.js +++ /dev/null @@ -1,39 +0,0 @@ -/* @flow */ -import { loadConnectScript } from "@paypal/connect-loader-component"; -import { - getClientID, - getClientMetadataID, - getUserIDToken, -} from "@paypal/sdk-client/src"; - -import type { LazyExport } from "../types"; - -// eslint-disable-next-line flowtype/no-weak-types -export type AXOComponent = any; - -// TODO: What's the expected structure/approach for this interface. It's not a zoid -// scenario, so what do we return? -// -> Looks like it returns a function that accepts the props -// How do we define the input of merchant params here? -export const connect: LazyExport = { - __get__: () => { - return async (merchantProps) => { - const cmid = getClientMetadataID(); - const clientID = getClientID(); - const userIdToken = getUserIDToken(); - // TODO: Sort out integration specifics for inputs - try { - const loadResult = await loadConnectScript(); - return window.braintree.connect.create({ - ...loadResult.metadata, - ...merchantProps, - cmid, - clientID, - userIdToken, - }); - } catch (error) { - return new Error(error); - } - }; - }, -}; From 699338fda28ff93ee2963d12532987557fc2a914 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Tue, 7 Nov 2023 16:48:17 -0800 Subject: [PATCH 07/31] update loader config --- src/connect/component.jsx | 22 +++++++++++++--------- src/connect/component.test.js | 0 src/connect/interface.test.js | 0 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 src/connect/component.test.js create mode 100644 src/connect/interface.test.js diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 521feb1250..8b75afbc9e 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -1,31 +1,35 @@ /* @flow */ -import { loadConnectScript } from "@paypal/connect-loader-component"; +import { loadAxo } from "@paypal/connect-loader-component"; import { getClientID, getClientMetadataID, getUserIDToken, + getSessionID, } from "@paypal/sdk-client/src"; -// eslint-disable-next-line flowtype/no-weak-types -export type ConnectComponent = any; - // TODO: What's the expected structure/approach for this interface. It's not a zoid // scenario, so what do we return? // -> Looks like it returns a function that accepts the props // How do we define the input of merchant params here? export const getConnectComponent = async (merchantProps) => { - const cmid = getClientMetadataID(); + const cmid = getClientMetadataID() ?? getSessionID(); const clientID = getClientID(); const userIdToken = getUserIDToken(); // TODO: Sort out integration specifics for inputs try { - const loadResult = await loadConnectScript(); - return window.braintree.connect.create({ + const loadResult = await loadAxo({ + client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, + minified: false, + }); + + return await window.braintree.connect.create({ ...loadResult.metadata, ...merchantProps, - cmid, + authorization: userIdToken, + deviceData: JSON.stringify({ + correlation_id: cmid, + }), clientID, - userIdToken, }); } catch (error) { return new Error(error); diff --git a/src/connect/component.test.js b/src/connect/component.test.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/connect/interface.test.js b/src/connect/interface.test.js new file mode 100644 index 0000000000..e69de29bb2 From d75daed1831f8f259a2b8e0be76b3d25a9470fc5 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Wed, 8 Nov 2023 13:56:26 -0800 Subject: [PATCH 08/31] proposed payload for PPCP AXO loader --- src/connect/component.jsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 8b75afbc9e..b80f042150 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -18,20 +18,25 @@ export const getConnectComponent = async (merchantProps) => { // TODO: Sort out integration specifics for inputs try { const loadResult = await loadAxo({ - client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, + client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, // this is currently supported for BT + sdkVersion: "", // PPCP proposal: string instead of function minified: false, }); - + // FPTI: sdkversion, fraudnet info return await window.braintree.connect.create({ - ...loadResult.metadata, - ...merchantProps, - authorization: userIdToken, - deviceData: JSON.stringify({ - correlation_id: cmid, - }), - clientID, + ...loadResult.metadata, // returns a localeURL for assets + ...merchantProps, // AXO specific props + ppcp: { + userIdToken, // + clientID, // + clientMetadataID: cmid, // + fraudnet: () => { + return ""; + }, // Pattern TBD + }, }); } catch (error) { + // FPTI Log here return new Error(error); } }; From 30bb926be9f68d67014dfa02a4838a81da0cccab Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Wed, 8 Nov 2023 11:15:24 -0800 Subject: [PATCH 09/31] removing sessionId default because we want to require that prop --- src/connect/component.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index b80f042150..51cf35e41c 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -12,7 +12,7 @@ import { // -> Looks like it returns a function that accepts the props // How do we define the input of merchant params here? export const getConnectComponent = async (merchantProps) => { - const cmid = getClientMetadataID() ?? getSessionID(); + const cmid = getClientMetadataID(); const clientID = getClientID(); const userIdToken = getUserIDToken(); // TODO: Sort out integration specifics for inputs From b43bfac572679399bba9c51ce0e041af2e2598cf Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Thu, 9 Nov 2023 10:59:20 -0800 Subject: [PATCH 10/31] couple test adjsutments --- src/interface/connect.test.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/interface/connect.test.js b/src/interface/connect.test.js index b7f3a11236..5c3c07a094 100644 --- a/src/interface/connect.test.js +++ b/src/interface/connect.test.js @@ -5,7 +5,7 @@ import { getClientMetadataID, getUserIDToken, } from "@paypal/sdk-client/src"; -import { loadConnectScript } from "@paypal/connect-loader-component"; +import { loadAxo } from "@paypal/connect-loader-component"; import { describe, expect, test, vi } from "vitest"; import { connect } from "./connect"; @@ -20,26 +20,26 @@ describe("connect: LazyExport AXOComponent", () => { vi.mock("@paypal/sdk-client/src", () => { return { - getClientID: vi.fn(), - getClientMetadataID: vi.fn(), - getUserIDToken: vi.fn(), + getClientID: vi.fn(() => "mock-client-id"), + getClientMetadataID: vi.fn(() => "mock-cmid"), + getUserIDToken: vi.fn(() => "mock-uid"), }; }); vi.mock("@paypal/connect-loader-component", () => { return { - loadConnectScript: vi - .fn() - .mockResolvedValue({ metadata: { someData: "data" } }), + loadAxo: vi.fn().mockResolvedValue({ metadata: { someData: "data" } }), }; }); - getClientID.mockReturnValue("mock-client-id"); - getClientMetadataID.mockReturnValue("mock-cmid"); - getUserIDToken.mockReturnValue("mock-uid"); + // getClientID.mockReturnValue("mock-client-id"); + // getClientMetadataID.mockReturnValue("mock-cmid"); + // getUserIDToken.mockReturnValue("mock-uid"); }); - test("loadConnectScript and window.braintree.connect.create are called with proper data", async () => { + test("loadAxo and window.braintree.connect.create are called with proper data", async () => { + const mockAxoMetadata = { someData: "data" }; + loadAxo.mockResolvedValue({ metadata: mockAxoMetadata }); const mockProps = { someProp: "value" }; const result = connect.__get__(); @@ -48,10 +48,10 @@ describe("connect: LazyExport AXOComponent", () => { expect(getClientID).toHaveBeenCalled(); expect(getClientMetadataID).toHaveBeenCalled(); expect(getUserIDToken).toHaveBeenCalled(); - expect(loadConnectScript).toHaveBeenCalled(); + expect(loadAxo).toHaveBeenCalled(); expect(window.braintree.connect.create).toHaveBeenCalledWith({ - someData: "data", + ...mockAxoMetadata, ...mockProps, clientID: "mock-client-id", cmid: "mock-cmid", @@ -59,11 +59,11 @@ describe("connect: LazyExport AXOComponent", () => { }); }); - test("loadConnectScript failure is handled", async () => { + test("loadAxo failure is handled", async () => { const mockProps = { someProp: "value" }; const errorMessage = "Something went wrong"; // eslint-disable-next-line no-import-assign - loadConnectScript = vi.fn().mockRejectedValue(errorMessage); + loadAxo = vi.fn().mockRejectedValue(errorMessage); const result = connect.__get__(); const error = await result(mockProps); From 97a6a06d9e03c6953c6998e998aae7922b2b6c0e Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Thu, 9 Nov 2023 13:57:54 -0800 Subject: [PATCH 11/31] add tests, cleanup --- src/connect/component.jsx | 2 +- src/connect/component.test.js | 74 +++++++++++++++++++++++++++++++++++ src/connect/interface.js | 2 +- src/connect/interface.test.js | 19 +++++++++ src/interface/connect.test.js | 74 ----------------------------------- 5 files changed, 95 insertions(+), 76 deletions(-) delete mode 100644 src/interface/connect.test.js diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 51cf35e41c..5e8b7343ec 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -4,7 +4,6 @@ import { getClientID, getClientMetadataID, getUserIDToken, - getSessionID, } from "@paypal/sdk-client/src"; // TODO: What's the expected structure/approach for this interface. It's not a zoid @@ -22,6 +21,7 @@ export const getConnectComponent = async (merchantProps) => { sdkVersion: "", // PPCP proposal: string instead of function minified: false, }); + // FPTI: sdkversion, fraudnet info return await window.braintree.connect.create({ ...loadResult.metadata, // returns a localeURL for assets diff --git a/src/connect/component.test.js b/src/connect/component.test.js index e69de29bb2..6260583000 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -0,0 +1,74 @@ +/* @flow */ + +import { + getClientID, + getClientMetadataID, + getUserIDToken, +} from "@paypal/sdk-client/src"; +import { loadAxo } from "@paypal/connect-loader-component"; +import { describe, expect, test, vi } from "vitest"; + +import { getConnectComponent } from "./component"; + +describe("getConnectComponent: returns ConnectComponent", () => { + const mockAxoMetadata = { someData: "data" }; + const mockProps = { someProp: "value" }; + beforeEach(() => { + window.braintree = { + connect: { + create: vi.fn(), + }, + }; + + vi.mock("@paypal/sdk-client/src", () => { + return { + getClientID: vi.fn(() => "mock-client-id"), + getClientMetadataID: vi.fn(() => "mock-cmid"), + getUserIDToken: vi.fn(() => "mock-uid"), + }; + }); + + vi.mock("@paypal/connect-loader-component", () => { + return { + loadAxo: vi.fn(), + }; + }); + + loadAxo.mockResolvedValue({ metadata: mockAxoMetadata }); + + // getClientID.mockReturnValue("mock-client-id"); + // getClientMetadataID.mockReturnValue("mock-cmid"); + // getUserIDToken.mockReturnValue("mock-uid"); + }); + + test("loadAxo and window.braintree.connect.create are called with proper data", async () => { + await getConnectComponent(mockProps); + + expect(getClientID).toHaveBeenCalled(); + expect(getClientMetadataID).toHaveBeenCalled(); + expect(getUserIDToken).toHaveBeenCalled(); + expect(loadAxo).toHaveBeenCalled(); + + expect(window.braintree.connect.create).toHaveBeenCalledWith({ + ...mockAxoMetadata, + ...mockProps, + ppcp: { + clientID: "mock-client-id", + clientMetadataID: "mock-cmid", + userIdToken: "mock-uid", + fraudnet: expect.any(Function), + }, + }); + }); + + test("loadAxo failure is handled", async () => { + const errorMessage = "Something went wrong"; + // eslint-disable-next-line no-import-assign + loadAxo = vi.fn().mockRejectedValue(errorMessage); + + const error = await getConnectComponent(mockProps); + + expect(error).toBeInstanceOf(Error); + expect(error.message).toEqual(errorMessage); + }); +}); diff --git a/src/connect/interface.js b/src/connect/interface.js index 42705472cf..deaaa82fa2 100644 --- a/src/connect/interface.js +++ b/src/connect/interface.js @@ -6,5 +6,5 @@ import type { LazyExport } from "../types"; import { getConnectComponent, type ConnectComponent } from "./component"; export const Connect: LazyExport = async (merchantProps) => { - return await getConnectComponent(merchantProps); + return getConnectComponent(merchantProps); }; diff --git a/src/connect/interface.test.js b/src/connect/interface.test.js index e69de29bb2..50918157ae 100644 --- a/src/connect/interface.test.js +++ b/src/connect/interface.test.js @@ -0,0 +1,19 @@ +/* @flow */ + +import { describe, expect, vi } from "vitest"; + +import { getConnectComponent } from "./component"; +import { Connect } from "./interface"; + +describe("interface.js", () => { + vi.mock("./component", () => { + return { + getConnectComponent: vi.fn(), + }; + }); + it("should call getConnectComponent with merchant props", async () => { + const merchantProps = { props: "someProps" }; + await Connect(merchantProps); + expect(getConnectComponent).toBeCalledWith(merchantProps); + }); +}); diff --git a/src/interface/connect.test.js b/src/interface/connect.test.js deleted file mode 100644 index 5c3c07a094..0000000000 --- a/src/interface/connect.test.js +++ /dev/null @@ -1,74 +0,0 @@ -/* @flow */ - -import { - getClientID, - getClientMetadataID, - getUserIDToken, -} from "@paypal/sdk-client/src"; -import { loadAxo } from "@paypal/connect-loader-component"; -import { describe, expect, test, vi } from "vitest"; - -import { connect } from "./connect"; - -describe("connect: LazyExport AXOComponent", () => { - beforeEach(() => { - window.braintree = { - connect: { - create: vi.fn(), - }, - }; - - vi.mock("@paypal/sdk-client/src", () => { - return { - getClientID: vi.fn(() => "mock-client-id"), - getClientMetadataID: vi.fn(() => "mock-cmid"), - getUserIDToken: vi.fn(() => "mock-uid"), - }; - }); - - vi.mock("@paypal/connect-loader-component", () => { - return { - loadAxo: vi.fn().mockResolvedValue({ metadata: { someData: "data" } }), - }; - }); - - // getClientID.mockReturnValue("mock-client-id"); - // getClientMetadataID.mockReturnValue("mock-cmid"); - // getUserIDToken.mockReturnValue("mock-uid"); - }); - - test("loadAxo and window.braintree.connect.create are called with proper data", async () => { - const mockAxoMetadata = { someData: "data" }; - loadAxo.mockResolvedValue({ metadata: mockAxoMetadata }); - const mockProps = { someProp: "value" }; - const result = connect.__get__(); - - await result(mockProps); - - expect(getClientID).toHaveBeenCalled(); - expect(getClientMetadataID).toHaveBeenCalled(); - expect(getUserIDToken).toHaveBeenCalled(); - expect(loadAxo).toHaveBeenCalled(); - - expect(window.braintree.connect.create).toHaveBeenCalledWith({ - ...mockAxoMetadata, - ...mockProps, - clientID: "mock-client-id", - cmid: "mock-cmid", - userIdToken: "mock-uid", - }); - }); - - test("loadAxo failure is handled", async () => { - const mockProps = { someProp: "value" }; - const errorMessage = "Something went wrong"; - // eslint-disable-next-line no-import-assign - loadAxo = vi.fn().mockRejectedValue(errorMessage); - - const result = connect.__get__(); - const error = await result(mockProps); - - expect(error).toBeInstanceOf(Error); - expect(error.message).toEqual(errorMessage); - }); -}); From 743e2ce3201033fce9ba11edd19674fc48c9cd6d Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Tue, 14 Nov 2023 09:15:47 -0800 Subject: [PATCH 12/31] update parameters supporting AXO modifications --- src/connect/component.jsx | 7 ++++--- src/connect/component.test.js | 3 +-- src/connect/interface.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 5e8b7343ec..d3e9ea532e 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -17,8 +17,8 @@ export const getConnectComponent = async (merchantProps) => { // TODO: Sort out integration specifics for inputs try { const loadResult = await loadAxo({ - client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, // this is currently supported for BT - sdkVersion: "", // PPCP proposal: string instead of function + // client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, // this is currently supported for BT + btSdkVersion: "3.97.3-connect-alpha.6.1", // PPCP proposal: string instead of function minified: false, }); @@ -26,7 +26,8 @@ export const getConnectComponent = async (merchantProps) => { return await window.braintree.connect.create({ ...loadResult.metadata, // returns a localeURL for assets ...merchantProps, // AXO specific props - ppcp: { + platformOptions: { + platform: "PPCP", userIdToken, // clientID, // clientMetadataID: cmid, // diff --git a/src/connect/component.test.js b/src/connect/component.test.js index 6260583000..f39521bda1 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -63,8 +63,7 @@ describe("getConnectComponent: returns ConnectComponent", () => { test("loadAxo failure is handled", async () => { const errorMessage = "Something went wrong"; - // eslint-disable-next-line no-import-assign - loadAxo = vi.fn().mockRejectedValue(errorMessage); + loadAxo.mockRejectedValue(errorMessage); const error = await getConnectComponent(mockProps); diff --git a/src/connect/interface.js b/src/connect/interface.js index deaaa82fa2..42705472cf 100644 --- a/src/connect/interface.js +++ b/src/connect/interface.js @@ -6,5 +6,5 @@ import type { LazyExport } from "../types"; import { getConnectComponent, type ConnectComponent } from "./component"; export const Connect: LazyExport = async (merchantProps) => { - return getConnectComponent(merchantProps); + return await getConnectComponent(merchantProps); }; From 0fa02c0ec82bad715351ef27f4a68047225e8c7d Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Tue, 14 Nov 2023 14:19:17 -0800 Subject: [PATCH 13/31] update axoloader version; fix lint,test,typecheck --- package.json | 2 +- src/connect/component.jsx | 7 +++++-- src/connect/component.test.js | 3 ++- src/connect/interface.js | 14 ++++++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 3dade67ad4..4e89d13526 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "@krakenjs/zoid": "^10.3.1", "@paypal/common-components": "^1.0.35", "@paypal/funding-components": "^1.0.31", - "@paypal/connect-loader-component": "^1.0.0", + "@paypal/connect-loader-component": "^1.1.0", "@paypal/sdk-client": "^4.0.176", "@paypal/sdk-constants": "^1.0.133", "@paypal/sdk-logos": "^2.2.6" diff --git a/src/connect/component.jsx b/src/connect/component.jsx index d3e9ea532e..43d8ccdf19 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -6,10 +6,13 @@ import { getUserIDToken, } from "@paypal/sdk-client/src"; +// eslint-disable-next-line flowtype/no-weak-types +export type ConnectComponent = any; // TODO: What's the expected structure/approach for this interface. It's not a zoid // scenario, so what do we return? // -> Looks like it returns a function that accepts the props // How do we define the input of merchant params here? +// $FlowFixMe export const getConnectComponent = async (merchantProps) => { const cmid = getClientMetadataID(); const clientID = getClientID(); @@ -17,8 +20,8 @@ export const getConnectComponent = async (merchantProps) => { // TODO: Sort out integration specifics for inputs try { const loadResult = await loadAxo({ - // client: { getVersion: () => "3.97.3-connect-alpha.6.1" }, // this is currently supported for BT - btSdkVersion: "3.97.3-connect-alpha.6.1", // PPCP proposal: string instead of function + platform: "PPCP", + btSdkVersion: "3.97.3-connect-alpha.6.1", minified: false, }); diff --git a/src/connect/component.test.js b/src/connect/component.test.js index f39521bda1..9377655e2b 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -52,7 +52,8 @@ describe("getConnectComponent: returns ConnectComponent", () => { expect(window.braintree.connect.create).toHaveBeenCalledWith({ ...mockAxoMetadata, ...mockProps, - ppcp: { + platformOptions: { + platform: "PPCP", clientID: "mock-client-id", clientMetadataID: "mock-cmid", userIdToken: "mock-uid", diff --git a/src/connect/interface.js b/src/connect/interface.js index 42705472cf..e574cbfbcb 100644 --- a/src/connect/interface.js +++ b/src/connect/interface.js @@ -1,10 +1,16 @@ +/* eslint-disable flowtype/no-weak-types */ /* @flow */ -/* eslint import/no-deprecated: 0 */ - -import type { LazyExport } from "../types"; +// flow-disable import { getConnectComponent, type ConnectComponent } from "./component"; -export const Connect: LazyExport = async (merchantProps) => { +type ConnectThing = (merchantProps: any) => ConnectComponent; +// $FlowFixMe +export const Connect: ConnectThing = async ( + merchantProps: any +): ConnectComponent => { + // $FlowFixMe return await getConnectComponent(merchantProps); }; + +/* eslint-enable flowtype/no-weak-types */ From 4990156730e9850c1a66da48baf2634d39b423b2 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Mon, 20 Nov 2023 14:21:17 -0800 Subject: [PATCH 14/31] pass metadata to loadAxo --- src/connect/component.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 43d8ccdf19..e9a350e60d 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -17,12 +17,14 @@ export const getConnectComponent = async (merchantProps) => { const cmid = getClientMetadataID(); const clientID = getClientID(); const userIdToken = getUserIDToken(); + const { metadata } = merchantProps; // TODO: Sort out integration specifics for inputs try { const loadResult = await loadAxo({ platform: "PPCP", btSdkVersion: "3.97.3-connect-alpha.6.1", minified: false, + metadata, }); // FPTI: sdkversion, fraudnet info From 15968cfc6e5435c4264c2d9d1085596ce5a1686b Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Mon, 20 Nov 2023 14:40:11 -0800 Subject: [PATCH 15/31] update package version for npm publish --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cdeb3e668..ae2f91f75f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paypal/checkout-components", - "version": "5.0.286", + "version": "5.0.288", "description": "PayPal Checkout components, for integrating checkout products.", "main": "index.js", "scripts": { From a61744abb2c2a5555f80667772f05d34047b6d74 Mon Sep 17 00:00:00 2001 From: Shraddha Shah Date: Mon, 27 Nov 2023 11:23:25 -0800 Subject: [PATCH 16/31] update type for Checkout Component --- src/connect/component.jsx | 2 -- src/connect/interface.js | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index e9a350e60d..29c70ad1fe 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -6,8 +6,6 @@ import { getUserIDToken, } from "@paypal/sdk-client/src"; -// eslint-disable-next-line flowtype/no-weak-types -export type ConnectComponent = any; // TODO: What's the expected structure/approach for this interface. It's not a zoid // scenario, so what do we return? // -> Looks like it returns a function that accepts the props diff --git a/src/connect/interface.js b/src/connect/interface.js index e574cbfbcb..208cfede13 100644 --- a/src/connect/interface.js +++ b/src/connect/interface.js @@ -2,11 +2,11 @@ /* @flow */ // flow-disable -import { getConnectComponent, type ConnectComponent } from "./component"; +import { getConnectComponent } from "./component"; -type ConnectThing = (merchantProps: any) => ConnectComponent; +type ConnectComponent = (merchantProps: any) => ConnectComponent; // $FlowFixMe -export const Connect: ConnectThing = async ( +export const Connect: ConnectComponent = async ( merchantProps: any ): ConnectComponent => { // $FlowFixMe From 3b4711bfa370a70430f055bc549e516773ce701f Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Mon, 27 Nov 2023 11:51:02 -0800 Subject: [PATCH 17/31] add some basic analytics --- src/connect/component.jsx | 70 ++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 29c70ad1fe..80bd1d5cf0 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -4,43 +4,89 @@ import { getClientID, getClientMetadataID, getUserIDToken, + getLogger, } from "@paypal/sdk-client/src"; -// TODO: What's the expected structure/approach for this interface. It's not a zoid -// scenario, so what do we return? -// -> Looks like it returns a function that accepts the props -// How do we define the input of merchant params here? +const sendCountMetric = ({ + dimensions, + event = "unused", + name, + value = 1, +}: {| + event?: string, + name: string, + value?: number, + dimensions: { + [string]: mixed, + }, + // $FlowIssue return type +|}) => + getLogger().metric({ + dimensions, + metricEventName: event, + metricNamespace: name, + metricValue: value, + metricType: "counter", + }); + // $FlowFixMe export const getConnectComponent = async (merchantProps) => { + sendCountMetric({ + name: "pp.app.paypal_sdk.connect.init.count", + }); + const cmid = getClientMetadataID(); const clientID = getClientID(); const userIdToken = getUserIDToken(); const { metadata } = merchantProps; - // TODO: Sort out integration specifics for inputs + + let loadResult = {}; try { - const loadResult = await loadAxo({ + loadResult = await loadAxo({ platform: "PPCP", btSdkVersion: "3.97.3-connect-alpha.6.1", minified: false, metadata, }); + } catch (error) { + sendCountMetric({ + name: "pp.app.paypal_sdk.connect.init.error.count", + event: "error", + dimensions: { + errorName: "connect_load_error", + }, + }); + } + try { // FPTI: sdkversion, fraudnet info - return await window.braintree.connect.create({ + const connect = await window.braintree.connect.create({ ...loadResult.metadata, // returns a localeURL for assets ...merchantProps, // AXO specific props platformOptions: { platform: "PPCP", - userIdToken, // - clientID, // - clientMetadataID: cmid, // + userIdToken, + clientID, + clientMetadataID: cmid, fraudnet: () => { return ""; - }, // Pattern TBD + }, }, }); + + sendCountMetric({ + name: "pp.app.paypal_sdk.connect.init.success.count", + event: "success", + }); + return connect; } catch (error) { - // FPTI Log here + sendCountMetric({ + name: "pp.app.paypal_sdk.connect.init.error.count", + event: "error", + dimensions: { + errorName: "connect_init_error", + }, + }); return new Error(error); } }; From 17698f3a4d762872f02b13995baa7ffae8fb4f29 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Mon, 27 Nov 2023 14:16:43 -0800 Subject: [PATCH 18/31] test second trycatch, loose metric tests, remove run for vitest --- package.json | 2 +- src/connect/component.jsx | 9 +++--- src/connect/component.test.js | 53 ++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index ae2f91f75f..a02550f39c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "release": "./scripts/publish.sh", "start": "npm run webpack -- --progress --watch", "test": "npm run format:check && npm run test:unit && npm run jest-ssr && npm run karma && npm run jest-screenshot", - "test:unit": "vitest run", + "test:unit": "vitest", "percy-screenshot": "npx playwright install && babel-node ./test/percy/server/createButtonConfigs.js && percy exec -- playwright test --config=./test/percy/playwright.config.js --reporter=dot --pass-with-no-tests", "typecheck": "npm run flow-typed && npm run flow", "version": "./scripts/version.sh", diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 80bd1d5cf0..2baa0679a5 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -56,10 +56,11 @@ export const getConnectComponent = async (merchantProps) => { errorName: "connect_load_error", }, }); + + throw new Error(error); } try { - // FPTI: sdkversion, fraudnet info const connect = await window.braintree.connect.create({ ...loadResult.metadata, // returns a localeURL for assets ...merchantProps, // AXO specific props @@ -68,9 +69,6 @@ export const getConnectComponent = async (merchantProps) => { userIdToken, clientID, clientMetadataID: cmid, - fraudnet: () => { - return ""; - }, }, }); @@ -78,6 +76,7 @@ export const getConnectComponent = async (merchantProps) => { name: "pp.app.paypal_sdk.connect.init.success.count", event: "success", }); + return connect; } catch (error) { sendCountMetric({ @@ -87,6 +86,6 @@ export const getConnectComponent = async (merchantProps) => { errorName: "connect_init_error", }, }); - return new Error(error); + throw new Error(error); } }; diff --git a/src/connect/component.test.js b/src/connect/component.test.js index 9377655e2b..20551b4ef4 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -4,41 +4,40 @@ import { getClientID, getClientMetadataID, getUserIDToken, + getLogger, } from "@paypal/sdk-client/src"; import { loadAxo } from "@paypal/connect-loader-component"; import { describe, expect, test, vi } from "vitest"; import { getConnectComponent } from "./component"; +vi.mock("@paypal/sdk-client/src", () => { + return { + getClientID: vi.fn(() => "mock-client-id"), + getClientMetadataID: vi.fn(() => "mock-cmid"), + getUserIDToken: vi.fn(() => "mock-uid"), + getLogger: vi.fn(() => ({ metric: vi.fn() })), + }; +}); + +vi.mock("@paypal/connect-loader-component", () => { + return { + loadAxo: vi.fn(), + }; +}); + describe("getConnectComponent: returns ConnectComponent", () => { const mockAxoMetadata = { someData: "data" }; const mockProps = { someProp: "value" }; beforeEach(() => { + vi.clearAllMocks(); window.braintree = { connect: { create: vi.fn(), }, }; - vi.mock("@paypal/sdk-client/src", () => { - return { - getClientID: vi.fn(() => "mock-client-id"), - getClientMetadataID: vi.fn(() => "mock-cmid"), - getUserIDToken: vi.fn(() => "mock-uid"), - }; - }); - - vi.mock("@paypal/connect-loader-component", () => { - return { - loadAxo: vi.fn(), - }; - }); - loadAxo.mockResolvedValue({ metadata: mockAxoMetadata }); - - // getClientID.mockReturnValue("mock-client-id"); - // getClientMetadataID.mockReturnValue("mock-cmid"); - // getUserIDToken.mockReturnValue("mock-uid"); }); test("loadAxo and window.braintree.connect.create are called with proper data", async () => { @@ -57,18 +56,28 @@ describe("getConnectComponent: returns ConnectComponent", () => { clientID: "mock-client-id", clientMetadataID: "mock-cmid", userIdToken: "mock-uid", - fraudnet: expect.any(Function), }, }); + expect(getLogger).toBeCalledTimes(2); }); test("loadAxo failure is handled", async () => { const errorMessage = "Something went wrong"; loadAxo.mockRejectedValue(errorMessage); - const error = await getConnectComponent(mockProps); + await expect(() => getConnectComponent(mockProps)).rejects.toThrow( + errorMessage + ); + expect(getLogger).toHaveBeenCalledTimes(2); + }); + + test("connect create failure is handled", async () => { + const expectedError = "create failed"; + window.braintree.connect.create.mockRejectedValue(expectedError); - expect(error).toBeInstanceOf(Error); - expect(error.message).toEqual(errorMessage); + await expect(() => getConnectComponent(mockProps)).rejects.toThrow( + expectedError + ); + expect(getLogger).toBeCalledTimes(2); }); }); From 1023547d8af9fe48e5a2eb715d2fef2e80783468 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Tue, 28 Nov 2023 09:29:53 -0800 Subject: [PATCH 19/31] fix flow and such --- src/connect/component.jsx | 2 ++ src/connect/component.test.js | 2 ++ test/declarations.js | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/connect/component.jsx b/src/connect/component.jsx index 2baa0679a5..4c616a5a9a 100644 --- a/src/connect/component.jsx +++ b/src/connect/component.jsx @@ -33,6 +33,7 @@ const sendCountMetric = ({ export const getConnectComponent = async (merchantProps) => { sendCountMetric({ name: "pp.app.paypal_sdk.connect.init.count", + dimensions: {}, }); const cmid = getClientMetadataID(); @@ -75,6 +76,7 @@ export const getConnectComponent = async (merchantProps) => { sendCountMetric({ name: "pp.app.paypal_sdk.connect.init.success.count", event: "success", + dimensions: {}, }); return connect; diff --git a/src/connect/component.test.js b/src/connect/component.test.js index 20551b4ef4..90478d9522 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -5,6 +5,7 @@ import { getClientMetadataID, getUserIDToken, getLogger, + getDebug, } from "@paypal/sdk-client/src"; import { loadAxo } from "@paypal/connect-loader-component"; import { describe, expect, test, vi } from "vitest"; @@ -17,6 +18,7 @@ vi.mock("@paypal/sdk-client/src", () => { getClientMetadataID: vi.fn(() => "mock-cmid"), getUserIDToken: vi.fn(() => "mock-uid"), getLogger: vi.fn(() => ({ metric: vi.fn() })), + getDebug: vi.fn(), }; }); diff --git a/test/declarations.js b/test/declarations.js index 721ee09b44..b93b617393 100644 --- a/test/declarations.js +++ b/test/declarations.js @@ -2,8 +2,11 @@ /* eslint import/unambiguous: 0 */ declare var jest; +declare var after: Function; declare var afterAll: Function; +declare var beforeAll: Function; declare var beforeEach: Function; +declare var afterEach: Function; declare var it: Function; declare var describe: Function; declare var test: Function; From 708c39075df8e0d992507bcf4bcee419454b78e2 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Tue, 28 Nov 2023 10:13:14 -0800 Subject: [PATCH 20/31] remove debug --- src/connect/component.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/connect/component.test.js b/src/connect/component.test.js index 90478d9522..20551b4ef4 100644 --- a/src/connect/component.test.js +++ b/src/connect/component.test.js @@ -5,7 +5,6 @@ import { getClientMetadataID, getUserIDToken, getLogger, - getDebug, } from "@paypal/sdk-client/src"; import { loadAxo } from "@paypal/connect-loader-component"; import { describe, expect, test, vi } from "vitest"; @@ -18,7 +17,6 @@ vi.mock("@paypal/sdk-client/src", () => { getClientMetadataID: vi.fn(() => "mock-cmid"), getUserIDToken: vi.fn(() => "mock-uid"), getLogger: vi.fn(() => ({ metric: vi.fn() })), - getDebug: vi.fn(), }; }); From 4ad56c0b5add217d09eb739f8c3778f771a1d1e1 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Tue, 28 Nov 2023 13:39:10 -0800 Subject: [PATCH 21/31] Update package.json Co-authored-by: elizabethmv <40329316+elizabethmv@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a02550f39c..59960c0d17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paypal/checkout-components", - "version": "5.0.288", + "version": "5.0.286", "description": "PayPal Checkout components, for integrating checkout products.", "main": "index.js", "scripts": { From 77afd1abff19cb96c53ad346ccf855b91c9817b3 Mon Sep 17 00:00:00 2001 From: Charlie Dibble Date: Tue, 28 Nov 2023 10:30:17 -0800 Subject: [PATCH 22/31] prettiered --- __sdk__.js | 2 +- dist/button.js | 2 +- dist/test/button.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__sdk__.js b/__sdk__.js index 0759a7714f..5cde8495f2 100644 --- a/__sdk__.js +++ b/__sdk__.js @@ -64,7 +64,7 @@ module.exports = { }, connect: { entry: "./src/connect/interface", - globals + globals, }, // @deprecated - renamed to payment-fields to be removed fields: { diff --git a/dist/button.js b/dist/button.js index 6d01f405c4..83bf7ec07a 100644 --- a/dist/button.js +++ b/dist/button.js @@ -1,2 +1,2 @@ /*! For license information please see button.js.LICENSE.txt */ -module.exports=function(n){var e={};function o(t){if(e[t])return e[t].exports;var r=e[t]={i:t,l:!1,exports:{}};return n[t].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=n,o.c=e,o.d=function(n,e,t){o.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:t})},o.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},o.t=function(n,e){if(1&e&&(n=o(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(o.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var r in n)o.d(t,r,function(e){return n[e]}.bind(null,r));return t},o.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return o.d(e,"a",e),e},o.o=function(n,e){return{}.hasOwnProperty.call(n,e)},o.p="",o(o.s=14)}([function(n,e,o){"use strict";n.exports=function(n){var e=[];return e.toString=function(){return this.map((function(e){var o=function(n,e){var o,t,r=n[1]||"",l=n[3];if(!l)return r;if(e&&"function"==typeof btoa){var a=(o=btoa(unescape(encodeURIComponent(JSON.stringify(l)))),t="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(o),"/*# ".concat(t," */")),i=l.sources.map((function(n){return"/*# sourceURL=".concat(l.sourceRoot||"").concat(n," */")}));return[r].concat(i).concat([a]).join("\n")}return[r].join("\n")}(e,n);return e[2]?"@media ".concat(e[2]," {").concat(o,"}"):o})).join("")},e.i=function(n,o,t){"string"==typeof n&&(n=[[null,n,""]]);var r={};if(t)for(var l=0;l1?new l(e):void 0}(this.component(this.props,this.children));if(e)return e.render(n)},e.render=function(n){return n(this)},e.renderChildren=function(n){return t(this.children,n)},n}();function u(n){for(var e=[],o=0;o2?o-2:0),l=2;l=0||(r[o]=n[o]);return r}var w={br:!0};function O(n){return n.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")}function T(n){var e=n.css,o=n.nonce,t=n.children;return s(f,null,s("style",{innerHTML:"string"==typeof e?e:e._getCss(),nonce:o}),t)}var M={AD:"AD",AE:"AE",AG:"AG",AI:"AI",AL:"AL",AM:"AM",AN:"AN",AO:"AO",AR:"AR",AT:"AT",AU:"AU",AW:"AW",AZ:"AZ",BA:"BA",BB:"BB",BE:"BE",BF:"BF",BG:"BG",BH:"BH",BI:"BI",BJ:"BJ",BM:"BM",BN:"BN",BO:"BO",BR:"BR",BS:"BS",BT:"BT",BW:"BW",BY:"BY",BZ:"BZ",CA:"CA",CD:"CD",CG:"CG",CH:"CH",CI:"CI",CK:"CK",CL:"CL",CM:"CM",CN:"CN",CO:"CO",CR:"CR",CV:"CV",CY:"CY",CZ:"CZ",DE:"DE",DJ:"DJ",DK:"DK",DM:"DM",DO:"DO",DZ:"DZ",EC:"EC",EE:"EE",EG:"EG",ER:"ER",ES:"ES",ET:"ET",FI:"FI",FJ:"FJ",FK:"FK",FM:"FM",FO:"FO",FR:"FR",GA:"GA",GB:"GB",GD:"GD",GE:"GE",GF:"GF",GI:"GI",GL:"GL",GM:"GM",GN:"GN",GP:"GP",GR:"GR",GT:"GT",GW:"GW",GY:"GY",HK:"HK",HN:"HN",HR:"HR",HU:"HU",ID:"ID",IE:"IE",IL:"IL",IN:"IN",IS:"IS",IT:"IT",JM:"JM",JO:"JO",JP:"JP",KE:"KE",KG:"KG",KH:"KH",KI:"KI",KM:"KM",KN:"KN",KR:"KR",KW:"KW",KY:"KY",KZ:"KZ",LA:"LA",LC:"LC",LI:"LI",LK:"LK",LS:"LS",LT:"LT",LU:"LU",LV:"LV",MA:"MA",MC:"MC",MD:"MD",ME:"ME",MG:"MG",MH:"MH",MK:"MK",ML:"ML",MN:"MN",MQ:"MQ",MR:"MR",MS:"MS",MT:"MT",MU:"MU",MV:"MV",MW:"MW",MX:"MX",MY:"MY",MZ:"MZ",NA:"NA",NC:"NC",NE:"NE",NF:"NF",NG:"NG",NI:"NI",NL:"NL",NO:"NO",NP:"NP",NR:"NR",NU:"NU",NZ:"NZ",OM:"OM",PA:"PA",PE:"PE",PF:"PF",PG:"PG",PH:"PH",PL:"PL",PM:"PM",PN:"PN",PT:"PT",PW:"PW",PY:"PY",QA:"QA",RE:"RE",RO:"RO",RS:"RS",RU:"RU",RW:"RW",SA:"SA",SB:"SB",SC:"SC",SE:"SE",SG:"SG",SH:"SH",SI:"SI",SJ:"SJ",SK:"SK",SL:"SL",SM:"SM",SN:"SN",SO:"SO",SR:"SR",ST:"ST",SV:"SV",SZ:"SZ",TC:"TC",TD:"TD",TG:"TG",TH:"TH",TJ:"TJ",TM:"TM",TN:"TN",TO:"TO",TR:"TR",TT:"TT",TV:"TV",TW:"TW",TZ:"TZ",UA:"UA",UG:"UG",US:"US",UY:"UY",VA:"VA",VC:"VC",VE:"VE",VG:"VG",VN:"VN",VU:"VU",WF:"WF",WS:"WS",YE:"YE",YT:"YT",ZA:"ZA",ZM:"ZM",ZW:"ZW"},A={AD:["en","fr","es","zh"],AE:["en","fr","es","zh","ar"],AG:["en","fr","es","zh"],AI:["en","fr","es","zh"],AL:["sq","en"],AM:["en","fr","es","zh"],AN:["en","fr","es","zh"],AO:["en","fr","es","zh"],AR:["es","en"],AT:["de","en"],AU:["en"],AW:["en","fr","es","zh"],AZ:["en","fr","es","zh"],BA:["en"],BB:["en","fr","es","zh"],BE:["en","nl","fr"],BF:["fr","en","es","zh"],BG:["bg","en"],BH:["ar","en","fr","es","zh"],BI:["fr","en","es","zh"],BJ:["fr","en","es","zh"],BM:["en","fr","es","zh"],BN:["ms","en"],BO:["es","en","fr","zh"],BR:["pt","en"],BS:["en","fr","es","zh"],BT:["en"],BW:["en","fr","es","zh"],BY:["en"],BZ:["en","es","fr","zh"],CA:["en","fr"],CD:["fr","en","es","zh"],CG:["en","fr","es","zh"],CH:["de","fr","en"],CI:["fr","en"],CK:["en","fr","es","zh"],CL:["es","en","fr","zh"],CM:["fr","en"],CN:["zh"],CO:["es","en","fr","zh"],CR:["es","en","fr","zh"],CV:["en","fr","es","zh"],CY:["en"],CZ:["cs","en"],DE:["de","en"],DJ:["fr","en","es","zh"],DK:["da","en"],DM:["en","fr","es","zh"],DO:["es","en","fr","zh"],DZ:["ar","en","fr","es","zh"],EC:["es","en","fr","zh"],EE:["et","en","ru"],EG:["ar","en","fr","es","zh"],ER:["en","fr","es","zh"],ES:["es","en"],ET:["en","fr","es","zh"],FI:["fi","en"],FJ:["en","fr","es","zh"],FK:["en","fr","es","zh"],FM:["en"],FO:["da","en","fr","es","zh"],FR:["fr","en"],GA:["fr","en","es","zh"],GB:["en"],GD:["en","fr","es","zh"],GE:["en","fr","es","zh"],GF:["en","fr","es","zh"],GI:["en","fr","es","zh"],GL:["da","en","fr","es","zh"],GM:["en","fr","es","zh"],GN:["fr","en","es","zh"],GP:["en","fr","es","zh"],GR:["el","en"],GT:["es","en","fr","zh"],GW:["en","fr","es","zh"],GY:["en","fr","es","zh"],HK:["en","zh_Hant","zh"],HN:["es","en","fr","zh"],HR:["en"],HU:["hu","en"],ID:["id","en"],IE:["en","fr","es","zh"],IL:["he","en"],IN:["en"],IS:["en"],IT:["it","en"],JM:["en","es","fr","zh"],JO:["ar","en","fr","es","zh"],JP:["ja","en"],KE:["en","fr","es","zh"],KG:["en","fr","es","zh"],KH:["en"],KI:["en","fr","es","zh"],KM:["fr","en","es","zh"],KN:["en","fr","es","zh"],KR:["ko","en"],KW:["ar","en","fr","es","zh"],KY:["en","fr","es","zh"],KZ:["en","fr","es","zh"],LA:["en"],LC:["en","fr","es","zh"],LI:["en","fr","es","zh"],LK:["si","en"],LS:["en","fr","es","zh"],LT:["lt","en","ru","zh"],LU:["en","de","fr","es","zh"],LV:["lv","en","ru"],MA:["ar","en","fr","es","zh"],MC:["fr","en"],MD:["en"],ME:["en"],MG:["en","fr","es","zh"],MH:["en","fr","es","zh"],MK:["en"],ML:["fr","en","es","zh"],MN:["en"],MQ:["en","fr","es","zh"],MR:["en","fr","es","zh"],MS:["en","fr","es","zh"],MT:["en"],MU:["en","fr","es","zh"],MV:["en"],MW:["en","fr","es","zh"],MX:["es","en"],MY:["ms","en"],MZ:["en","fr","es","zh"],NA:["en","fr","es","zh"],NC:["en","fr","es","zh"],NE:["fr","en","es","zh"],NF:["en","fr","es","zh"],NG:["en"],NI:["es","en","fr","zh"],NL:["nl","en"],NO:["no","en"],NP:["en"],NR:["en","fr","es","zh"],NU:["en","fr","es","zh"],NZ:["en","fr","es","zh"],OM:["ar","en","fr","es","zh"],PA:["es","en","fr","zh"],PE:["es","en","fr","zh"],PF:["en","fr","es","zh"],PG:["en","fr","es","zh"],PH:["tl","en"],PL:["pl","en"],PM:["en","fr","es","zh"],PN:["en","fr","es","zh"],PT:["pt","en"],PW:["en","fr","es","zh"],PY:["es","en"],QA:["en","fr","es","zh","ar"],RE:["en","fr","es","zh"],RO:["ro","en"],RS:["en","fr","es","zh"],RU:["ru","en"],RW:["fr","en","es","zh"],SA:["ar","en","fr","es","zh"],SB:["en","fr","es","zh"],SC:["fr","en","es","zh"],SE:["sv","en"],SG:["en"],SH:["en","fr","es","zh"],SI:["sl","en"],SJ:["en","fr","es","zh"],SK:["sk","en"],SL:["en","fr","es","zh"],SM:["en","fr","es","zh"],SN:["fr","en","es","zh"],SO:["en","fr","es","zh"],SR:["en","fr","es","zh"],ST:["en","fr","es","zh"],SV:["es","en","fr","zh"],SZ:["en","fr","es","zh"],TC:["en","fr","es","zh"],TD:["fr","en","es","zh"],TG:["fr","en","es","zh"],TH:["th","en"],TJ:["en","fr","es","zh"],TM:["en","fr","es","zh"],TN:["ar","en","fr","es","zh"],TO:["en"],TR:["tr","en"],TT:["en","fr","es","zh"],TV:["en","fr","es","zh"],TW:["zh_Hant","zh","en"],TZ:["en","fr","es","zh"],UA:["en","ru","fr","es","zh"],UG:["en","fr","es","zh"],US:["en","fr","es","zh"],UY:["es","en","fr","zh"],VA:["en","fr","es","zh"],VC:["en","fr","es","zh"],VE:["es","en","fr","zh"],VG:["en","fr","es","zh"],VN:["vi","en"],VU:["en","fr","es","zh"],WF:["en","fr","es","zh"],WS:["en"],YE:["ar","en","fr","es","zh"],YT:["en","fr","es","zh"],ZA:["en","fr","es","zh"],ZM:["en","fr","es","zh"],ZW:["en"]},E={LOCAL:"local",STAGE:"stage",SANDBOX:"sandbox",PRODUCTION:"production",TEST:"test"},x={PAYPAL:"paypal",VENMO:"venmo",APPLEPAY:"applepay",ITAU:"itau",CREDIT:"credit",PAYLATER:"paylater",CARD:"card",IDEAL:"ideal",SEPA:"sepa",BANCONTACT:"bancontact",GIROPAY:"giropay",SOFORT:"sofort",EPS:"eps",MYBANK:"mybank",P24:"p24",PAYU:"payu",BLIK:"blik",TRUSTLY:"trustly",OXXO:"oxxo",BOLETO:"boleto",BOLETOBANCARIO:"boletobancario",WECHATPAY:"wechatpay",MERCADOPAGO:"mercadopago",MULTIBANCO:"multibanco",SATISPAY:"satispay",PAIDY:"paidy"},H={DESKTOP:"desktop",MOBILE:"mobile"},B=[x.IDEAL,x.BANCONTACT,x.GIROPAY,x.SOFORT,x.EPS,x.MYBANK,x.P24,x.PAYU,x.BLIK,x.TRUSTLY,x.OXXO,x.BOLETO,x.BOLETOBANCARIO,x.WECHATPAY,x.MERCADOPAGO,x.MULTIBANCO,x.SATISPAY,x.PAIDY];function N(n,e){return(N=Object.setPrototypeOf||function(n,e){return n.__proto__=e,n})(n,e)}function F(n,e){n.prototype=Object.create(e.prototype),n.prototype.constructor=n,N(n,e)}function V(n){try{if(!n)return!1;if("undefined"!=typeof Promise&&n instanceof Promise)return!0;if("undefined"!=typeof window&&"function"==typeof window.Window&&n instanceof window.Window)return!1;if("undefined"!=typeof window&&"function"==typeof window.constructor&&n instanceof window.constructor)return!1;var e={}.toString;if(e){var o=e.call(n);if("[object Window]"===o||"[object global]"===o||"[object DOMWindow]"===o)return!1}if("function"==typeof n.then)return!0}catch(n){return!1}return!1}var P,S=[],R=[],k=0;function Z(){if(!k&&P){var n=P;P=null,n.resolve()}}function _(){k+=1}function U(){k-=1,Z()}var D=function(){function n(n){var e=this;if(this.resolved=void 0,this.rejected=void 0,this.errorHandled=void 0,this.value=void 0,this.error=void 0,this.handlers=void 0,this.dispatching=void 0,this.stack=void 0,this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],n){var o,t,r=!1,l=!1,a=!1;_();try{n((function(n){a?e.resolve(n):(r=!0,o=n)}),(function(n){a?e.reject(n):(l=!0,t=n)}))}catch(n){return U(),void this.reject(n)}U(),a=!0,r?this.resolve(o):l&&this.reject(t)}}var e=n.prototype;return e.resolve=function(n){if(this.resolved||this.rejected)return this;if(V(n))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=n,this.dispatch(),this},e.reject=function(n){var e=this;if(this.resolved||this.rejected)return this;if(V(n))throw new Error("Can not reject promise with another promise");if(!n){var o=n&&"function"==typeof n.toString?n.toString():{}.toString.call(n);n=new Error("Expected reject to be called with Error, got "+o)}return this.rejected=!0,this.error=n,this.errorHandled||setTimeout((function(){e.errorHandled||function(n,e){if(-1===S.indexOf(n)){S.push(n),setTimeout((function(){throw n}),1);for(var o=0;o>>0)+"__",function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var n=new WeakMap,e={};return Object.freeze(e),n.set(e,"__testvalue__"),"__testvalue__"===n.get(e)}catch(n){return!1}}())try{this.weakmap=new WeakMap}catch(n){}this.keys=[],this.values=[]}var e=n.prototype;return e._cleanupClosedWindows=function(){for(var n=this.weakmap,e=this.keys,o=0;o=3)return"stringifyError stack overflow";try{if(!e)return"";if("string"==typeof e)return e;if(e instanceof Error){var t=e&&e.stack,r=e&&e.message;if(t&&r)return-1!==t.indexOf(r)?t:r+"\n"+t;if(t)return t;if(r)return r}return e&&e.toString&&"function"==typeof e.toString?e.toString():{}.toString.call(e)}catch(e){return"Error while stringifying error: "+n(e,o+1)}}(o):"";return new Error('PayPal Payments SDK script not found on page! Expected to find