Skip to content

Commit 20ff8a4

Browse files
add fingerprint to shopper insights
Co-authored-by: elizabethmv <[email protected]> Co-authored-by: Shane Brunson <[email protected]>
1 parent e67ac87 commit 20ff8a4

File tree

7 files changed

+850
-270
lines changed

7 files changed

+850
-270
lines changed

Diff for: src/api/shopper-insights/validation.js

-120
This file was deleted.

Diff for: src/api/shopper-insights/validation.test.js

-150
This file was deleted.

Diff for: src/lib/api.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* @flow */
2+
3+
import { getPartnerAttributionID, getSessionID } from "@paypal/sdk-client/src";
4+
import { inlineMemoize, request } from "@krakenjs/belter/src";
5+
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
6+
7+
import { HEADERS } from "../constants/api";
8+
9+
type RestAPIParams = {|
10+
method?: string,
11+
url: string,
12+
data: Object,
13+
accessToken: ?string,
14+
|};
15+
16+
export function callRestAPI({
17+
accessToken,
18+
method,
19+
url,
20+
data,
21+
}: RestAPIParams): ZalgoPromise<Object> {
22+
const partnerAttributionID = getPartnerAttributionID() || "";
23+
24+
if (!accessToken) {
25+
throw new Error(`No access token passed to API request ${url}`);
26+
}
27+
28+
const requestHeaders = {
29+
[HEADERS.AUTHORIZATION]: `Bearer ${accessToken}`,
30+
[HEADERS.CONTENT_TYPE]: `application/json`,
31+
[HEADERS.PARTNER_ATTRIBUTION_ID]: partnerAttributionID,
32+
[HEADERS.CLIENT_METADATA_ID]: getSessionID(),
33+
};
34+
35+
return request({
36+
method,
37+
url,
38+
headers: requestHeaders,
39+
json: data,
40+
}).then(({ status, body, headers: responseHeaders }) => {
41+
if (status >= 300) {
42+
const error = new Error(
43+
`${url} returned status ${status}\n\n${JSON.stringify(body)}`
44+
);
45+
46+
// $FlowFixMe
47+
error.response = { status, headers: responseHeaders, body };
48+
49+
throw error;
50+
}
51+
52+
return body;
53+
});
54+
}
55+
56+
export function callMemoizedRestAPI({
57+
accessToken,
58+
method,
59+
url,
60+
data,
61+
}: RestAPIParams): ZalgoPromise<Object> {
62+
return inlineMemoize(
63+
callMemoizedRestAPI,
64+
() => callRestAPI({ accessToken, method, url, data }),
65+
[accessToken, method, url, JSON.stringify(data)]
66+
);
67+
}

Diff for: src/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
export * from "./api";
34
export * from "./errors";
45
export * from "./isRTLLanguage";
56
export * from "./security";

0 commit comments

Comments
 (0)