@paypal/checkout-components 5.0.289-alpha.0 → 5.0.289
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__sdk__.js +1 -1
- package/package.json +3 -2
- package/src/connect/component.jsx +50 -19
- package/src/connect/component.test.js +37 -22
- package/src/connect/interface.js +3 -3
- package/src/connect/sendCountMetric.js +25 -0
package/__sdk__.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paypal/checkout-components",
|
|
3
|
-
"version": "5.0.289
|
|
3
|
+
"version": "5.0.289",
|
|
4
4
|
"description": "PayPal Checkout components, for integrating checkout products.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"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",
|
|
34
34
|
"typecheck": "npm run flow-typed && npm run flow",
|
|
35
35
|
"version": "./scripts/version.sh",
|
|
36
|
+
"vitest": "vitest",
|
|
36
37
|
"webpack": "babel-node $(npm bin)/webpack",
|
|
37
38
|
"webpack-size": "npm run webpack -- --config webpack.config.size",
|
|
38
39
|
"prepare": "husky install",
|
|
@@ -109,7 +110,7 @@
|
|
|
109
110
|
"@krakenjs/zoid": "^10.3.1",
|
|
110
111
|
"@paypal/common-components": "^1.0.35",
|
|
111
112
|
"@paypal/funding-components": "^1.0.31",
|
|
112
|
-
"@paypal/connect-loader-component": "
|
|
113
|
+
"@paypal/connect-loader-component": "1.1.1",
|
|
113
114
|
"@paypal/sdk-client": "^4.0.176",
|
|
114
115
|
"@paypal/sdk-constants": "^1.0.133",
|
|
115
116
|
"@paypal/sdk-logos": "^2.2.6"
|
|
@@ -1,48 +1,79 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
import { loadAxo } from "@paypal/connect-loader-component";
|
|
3
|
+
import { stringifyError } from "@krakenjs/belter/src";
|
|
3
4
|
import {
|
|
4
5
|
getClientID,
|
|
5
6
|
getClientMetadataID,
|
|
6
7
|
getUserIDToken,
|
|
8
|
+
getLogger,
|
|
7
9
|
} from "@paypal/sdk-client/src";
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// TODO: What's the expected structure/approach for this interface. It's not a zoid
|
|
12
|
-
// scenario, so what do we return?
|
|
13
|
-
// -> Looks like it returns a function that accepts the props
|
|
14
|
-
// How do we define the input of merchant params here?
|
|
11
|
+
import { sendCountMetric } from "./sendCountMetric";
|
|
12
|
+
|
|
15
13
|
// $FlowFixMe
|
|
16
14
|
export const getConnectComponent = async (merchantProps) => {
|
|
15
|
+
sendCountMetric({
|
|
16
|
+
name: "pp.app.paypal_sdk.connect.init.count",
|
|
17
|
+
dimensions: {},
|
|
18
|
+
});
|
|
19
|
+
|
|
17
20
|
const cmid = getClientMetadataID();
|
|
18
21
|
const clientID = getClientID();
|
|
19
22
|
const userIdToken = getUserIDToken();
|
|
20
23
|
const { metadata } = merchantProps;
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
let loadResult = {};
|
|
22
26
|
try {
|
|
23
|
-
|
|
27
|
+
loadResult = await loadAxo({
|
|
24
28
|
platform: "PPCP",
|
|
25
29
|
btSdkVersion: "3.97.3-connect-alpha.6.1",
|
|
26
|
-
minified:
|
|
30
|
+
minified: true,
|
|
27
31
|
metadata,
|
|
28
32
|
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
sendCountMetric({
|
|
35
|
+
name: "pp.app.paypal_sdk.connect.init.error.count",
|
|
36
|
+
event: "error",
|
|
37
|
+
dimensions: {
|
|
38
|
+
errorName: "connect_load_error",
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
getLogger().error("load_axo_error", { err: stringifyError(error) });
|
|
43
|
+
|
|
44
|
+
throw new Error(error);
|
|
45
|
+
}
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
try {
|
|
48
|
+
const connect = await window.braintree.connect.create({
|
|
32
49
|
...loadResult.metadata, // returns a localeURL for assets
|
|
33
50
|
...merchantProps, // AXO specific props
|
|
34
51
|
platformOptions: {
|
|
35
52
|
platform: "PPCP",
|
|
36
|
-
userIdToken,
|
|
37
|
-
clientID,
|
|
38
|
-
clientMetadataID: cmid,
|
|
39
|
-
fraudnet: () => {
|
|
40
|
-
return "";
|
|
41
|
-
}, // Pattern TBD
|
|
53
|
+
userIdToken,
|
|
54
|
+
clientID,
|
|
55
|
+
clientMetadataID: cmid,
|
|
42
56
|
},
|
|
43
57
|
});
|
|
58
|
+
|
|
59
|
+
sendCountMetric({
|
|
60
|
+
name: "pp.app.paypal_sdk.connect.init.success.count",
|
|
61
|
+
event: "success",
|
|
62
|
+
dimensions: {},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return connect;
|
|
44
66
|
} catch (error) {
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
sendCountMetric({
|
|
68
|
+
name: "pp.app.paypal_sdk.connect.init.error.count",
|
|
69
|
+
event: "error",
|
|
70
|
+
dimensions: {
|
|
71
|
+
errorName: "connect_init_error",
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
getLogger().error("init_axo_error", { err: stringifyError(error) });
|
|
76
|
+
|
|
77
|
+
throw new Error(error);
|
|
47
78
|
}
|
|
48
79
|
};
|
|
@@ -9,36 +9,41 @@ import { loadAxo } from "@paypal/connect-loader-component";
|
|
|
9
9
|
import { describe, expect, test, vi } from "vitest";
|
|
10
10
|
|
|
11
11
|
import { getConnectComponent } from "./component";
|
|
12
|
+
import { sendCountMetric } from "./sendCountMetric";
|
|
13
|
+
|
|
14
|
+
vi.mock("@paypal/sdk-client/src", () => {
|
|
15
|
+
return {
|
|
16
|
+
getClientID: vi.fn(() => "mock-client-id"),
|
|
17
|
+
getClientMetadataID: vi.fn(() => "mock-cmid"),
|
|
18
|
+
getUserIDToken: vi.fn(() => "mock-uid"),
|
|
19
|
+
getLogger: vi.fn(() => ({ metric: vi.fn(), error: vi.fn() })),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
vi.mock("@paypal/connect-loader-component", () => {
|
|
24
|
+
return {
|
|
25
|
+
loadAxo: vi.fn(),
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
vi.mock("./sendCountMetric", () => {
|
|
30
|
+
return {
|
|
31
|
+
sendCountMetric: vi.fn(),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
12
34
|
|
|
13
35
|
describe("getConnectComponent: returns ConnectComponent", () => {
|
|
14
36
|
const mockAxoMetadata = { someData: "data" };
|
|
15
37
|
const mockProps = { someProp: "value" };
|
|
16
38
|
beforeEach(() => {
|
|
39
|
+
vi.clearAllMocks();
|
|
17
40
|
window.braintree = {
|
|
18
41
|
connect: {
|
|
19
42
|
create: vi.fn(),
|
|
20
43
|
},
|
|
21
44
|
};
|
|
22
45
|
|
|
23
|
-
vi.mock("@paypal/sdk-client/src", () => {
|
|
24
|
-
return {
|
|
25
|
-
getClientID: vi.fn(() => "mock-client-id"),
|
|
26
|
-
getClientMetadataID: vi.fn(() => "mock-cmid"),
|
|
27
|
-
getUserIDToken: vi.fn(() => "mock-uid"),
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
vi.mock("@paypal/connect-loader-component", () => {
|
|
32
|
-
return {
|
|
33
|
-
loadAxo: vi.fn(),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
|
|
37
46
|
loadAxo.mockResolvedValue({ metadata: mockAxoMetadata });
|
|
38
|
-
|
|
39
|
-
// getClientID.mockReturnValue("mock-client-id");
|
|
40
|
-
// getClientMetadataID.mockReturnValue("mock-cmid");
|
|
41
|
-
// getUserIDToken.mockReturnValue("mock-uid");
|
|
42
47
|
});
|
|
43
48
|
|
|
44
49
|
test("loadAxo and window.braintree.connect.create are called with proper data", async () => {
|
|
@@ -57,18 +62,28 @@ describe("getConnectComponent: returns ConnectComponent", () => {
|
|
|
57
62
|
clientID: "mock-client-id",
|
|
58
63
|
clientMetadataID: "mock-cmid",
|
|
59
64
|
userIdToken: "mock-uid",
|
|
60
|
-
fraudnet: expect.any(Function),
|
|
61
65
|
},
|
|
62
66
|
});
|
|
67
|
+
expect(sendCountMetric).toBeCalledTimes(2);
|
|
63
68
|
});
|
|
64
69
|
|
|
65
70
|
test("loadAxo failure is handled", async () => {
|
|
66
71
|
const errorMessage = "Something went wrong";
|
|
67
72
|
loadAxo.mockRejectedValue(errorMessage);
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
await expect(() => getConnectComponent(mockProps)).rejects.toThrow(
|
|
75
|
+
errorMessage
|
|
76
|
+
);
|
|
77
|
+
expect(sendCountMetric).toHaveBeenCalledTimes(2);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("connect create failure is handled", async () => {
|
|
81
|
+
const expectedError = "create failed";
|
|
82
|
+
window.braintree.connect.create.mockRejectedValue(expectedError);
|
|
70
83
|
|
|
71
|
-
expect(
|
|
72
|
-
|
|
84
|
+
await expect(() => getConnectComponent(mockProps)).rejects.toThrow(
|
|
85
|
+
expectedError
|
|
86
|
+
);
|
|
87
|
+
expect(sendCountMetric).toBeCalledTimes(2);
|
|
73
88
|
});
|
|
74
89
|
});
|
package/src/connect/interface.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/* @flow */
|
|
3
3
|
// flow-disable
|
|
4
4
|
|
|
5
|
-
import { getConnectComponent
|
|
5
|
+
import { getConnectComponent } from "./component";
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type ConnectComponent = (merchantProps: any) => ConnectComponent;
|
|
8
8
|
// $FlowFixMe
|
|
9
|
-
export const Connect:
|
|
9
|
+
export const Connect: ConnectComponent = async (
|
|
10
10
|
merchantProps: any
|
|
11
11
|
): ConnectComponent => {
|
|
12
12
|
// $FlowFixMe
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import { getLogger } from "@paypal/sdk-client/src";
|
|
3
|
+
|
|
4
|
+
// TODO: This will be pulled in to a shared sdk-client util
|
|
5
|
+
export const sendCountMetric = ({
|
|
6
|
+
dimensions,
|
|
7
|
+
event = "unused",
|
|
8
|
+
name,
|
|
9
|
+
value = 1,
|
|
10
|
+
}: {|
|
|
11
|
+
event?: string,
|
|
12
|
+
name: string,
|
|
13
|
+
value?: number,
|
|
14
|
+
dimensions: {
|
|
15
|
+
[string]: mixed,
|
|
16
|
+
},
|
|
17
|
+
// $FlowIssue return type
|
|
18
|
+
|}) =>
|
|
19
|
+
getLogger().metric({
|
|
20
|
+
dimensions,
|
|
21
|
+
metricEventName: event,
|
|
22
|
+
metricNamespace: name,
|
|
23
|
+
metricValue: value,
|
|
24
|
+
metricType: "counter",
|
|
25
|
+
});
|