@paypal/checkout-components 5.0.297 → 5.0.299-alpha.0
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/README.md +4 -0
- package/dist/button.js +1 -1
- package/dist/test/button.js +1 -1
- package/package.json +4 -3
- package/src/api/shopper-insights/validation.js +8 -7
- package/src/api/shopper-insights/validation.test.js +3 -1
- package/src/connect/component.jsx +25 -30
- package/src/connect/component.test.js +2 -11
- package/src/constants/api.js +1 -2
- package/src/hosted-buttons/index.js +28 -26
- package/src/hosted-buttons/index.test.js +7 -4
- package/src/hosted-buttons/types.js +29 -7
- package/src/hosted-buttons/utils.js +93 -36
- package/src/hosted-buttons/utils.test.js +58 -6
- package/src/connect/sendCountMetric.js +0 -25
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
|
|
2
|
+
/* eslint-disable no-restricted-globals, promise/no-native */
|
|
3
3
|
import { test, expect, vi } from "vitest";
|
|
4
4
|
import { request } from "@krakenjs/belter/src";
|
|
5
|
-
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
7
|
buildHostedButtonCreateOrder,
|
|
9
8
|
buildHostedButtonOnApprove,
|
|
10
9
|
getHostedButtonDetails,
|
|
10
|
+
requestWithDPoP,
|
|
11
11
|
} from "./utils";
|
|
12
12
|
|
|
13
13
|
vi.mock("@krakenjs/belter/src", async () => {
|
|
@@ -62,7 +62,8 @@ const getHostedButtonDetailsResponse = {
|
|
|
62
62
|
test("getHostedButtonDetails", async () => {
|
|
63
63
|
// $FlowIssue
|
|
64
64
|
request.mockImplementationOnce(() =>
|
|
65
|
-
|
|
65
|
+
// eslint-disable-next-line compat/compat
|
|
66
|
+
Promise.resolve(getHostedButtonDetailsResponse)
|
|
66
67
|
);
|
|
67
68
|
await getHostedButtonDetails({
|
|
68
69
|
hostedButtonId,
|
|
@@ -77,6 +78,52 @@ test("getHostedButtonDetails", async () => {
|
|
|
77
78
|
expect.assertions(1);
|
|
78
79
|
});
|
|
79
80
|
|
|
81
|
+
test("requestWithDPoP", async () => {
|
|
82
|
+
const accessToken = window.crypto.randomUUID();
|
|
83
|
+
// $FlowIssue
|
|
84
|
+
request.mockImplementation(() =>
|
|
85
|
+
// eslint-disable-next-line compat/compat
|
|
86
|
+
Promise.resolve({
|
|
87
|
+
body: {
|
|
88
|
+
access_token: accessToken,
|
|
89
|
+
nonce: "123abc",
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
const options = {
|
|
94
|
+
method: "POST",
|
|
95
|
+
url: "https://example.com/",
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Basic ${accessToken}`,
|
|
98
|
+
},
|
|
99
|
+
body: "",
|
|
100
|
+
};
|
|
101
|
+
await requestWithDPoP(options);
|
|
102
|
+
expect(request).toHaveBeenCalledWith(
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
headers: expect.objectContaining({
|
|
105
|
+
// does not override the basic auth scheme
|
|
106
|
+
Authorization: expect.stringContaining(`Basic ${accessToken}`),
|
|
107
|
+
// but includes a DPoP jwt
|
|
108
|
+
DPoP: expect.any(String),
|
|
109
|
+
}),
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
options.headers.Authorization = `Bearer ${accessToken}`;
|
|
114
|
+
await requestWithDPoP(options);
|
|
115
|
+
expect(request).toHaveBeenCalledWith(
|
|
116
|
+
expect.objectContaining({
|
|
117
|
+
headers: expect.objectContaining({
|
|
118
|
+
// overrides the Bearer auth scheme
|
|
119
|
+
Authorization: expect.stringContaining(`DPoP ${accessToken}`),
|
|
120
|
+
// and includes a DPoP jwt
|
|
121
|
+
DPoP: expect.any(String),
|
|
122
|
+
}),
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
80
127
|
test("buildHostedButtonCreateOrder", async () => {
|
|
81
128
|
const createOrder = buildHostedButtonCreateOrder({
|
|
82
129
|
hostedButtonId,
|
|
@@ -85,7 +132,8 @@ test("buildHostedButtonCreateOrder", async () => {
|
|
|
85
132
|
|
|
86
133
|
// $FlowIssue
|
|
87
134
|
request.mockImplementation(() =>
|
|
88
|
-
|
|
135
|
+
// eslint-disable-next-line compat/compat
|
|
136
|
+
Promise.resolve({
|
|
89
137
|
body: {
|
|
90
138
|
link_id: hostedButtonId,
|
|
91
139
|
merchant_id: merchantId,
|
|
@@ -107,7 +155,8 @@ test("buildHostedButtonCreateOrder error handling", async () => {
|
|
|
107
155
|
|
|
108
156
|
// $FlowIssue
|
|
109
157
|
request.mockImplementation(() =>
|
|
110
|
-
|
|
158
|
+
// eslint-disable-next-line compat/compat
|
|
159
|
+
Promise.resolve({
|
|
111
160
|
body: {
|
|
112
161
|
name: "RESOURCE_NOT_FOUND",
|
|
113
162
|
},
|
|
@@ -133,7 +182,8 @@ describe("buildHostedButtonOnApprove", () => {
|
|
|
133
182
|
|
|
134
183
|
// $FlowIssue
|
|
135
184
|
request.mockImplementation(() =>
|
|
136
|
-
|
|
185
|
+
// eslint-disable-next-line compat/compat
|
|
186
|
+
Promise.resolve({
|
|
137
187
|
body: {},
|
|
138
188
|
})
|
|
139
189
|
);
|
|
@@ -150,3 +200,5 @@ describe("buildHostedButtonOnApprove", () => {
|
|
|
150
200
|
expect.assertions(1);
|
|
151
201
|
});
|
|
152
202
|
});
|
|
203
|
+
|
|
204
|
+
/* eslint-enable no-restricted-globals, promise/no-native */
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
});
|