@rebuy/rebuy 1.2.0 → 1.3.1
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/.git/logs/refs/heads/REB-2426/add-index.js +2 -2
- package/.git/refs/heads/REB-2426/add-index.js +1 -1
- package/api.js +18 -9
- package/client.js +22 -7
- package/geolocation.js +1 -1
- package/identity.js +1 -1
- package/package.json +1 -1
- package/session.js +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
0000000000000000000000000000000000000000
|
|
2
|
-
|
|
1
|
+
0000000000000000000000000000000000000000 145cb0c967aef90450c887bbaf2a9bf61a00577d Mike Reid <mike.reid@rebuyengine.com> 1658876468 -0600 branch: Created from HEAD
|
|
2
|
+
145cb0c967aef90450c887bbaf2a9bf61a00577d f5fedc7d3aea2600d58bfde5527d49f2b99d5abc Mike Reid <mike.reid@rebuyengine.com> 1658876497 -0600 commit: Fix: Include both named + default exports (for BC)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
f5fedc7d3aea2600d58bfde5527d49f2b99d5abc
|
package/api.js
CHANGED
|
@@ -7,9 +7,10 @@ const config = {
|
|
|
7
7
|
eventDomain: 'https://rebuyengine.com',
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const makeCall = async (method, path, data, origin) => {
|
|
10
|
+
const makeCall = async (method, path, data, origin, options = {}) => {
|
|
11
11
|
const url = `${origin}${path}`;
|
|
12
12
|
const requestUrl = new URL(url);
|
|
13
|
+
const fetchOptions = options?.fetch ?? {};
|
|
13
14
|
|
|
14
15
|
const requestData = {
|
|
15
16
|
key: config.key,
|
|
@@ -21,6 +22,7 @@ const makeCall = async (method, path, data, origin) => {
|
|
|
21
22
|
|
|
22
23
|
const requestObject = {
|
|
23
24
|
method,
|
|
25
|
+
...fetchOptions,
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
if (method == 'GET') {
|
|
@@ -33,7 +35,14 @@ const makeCall = async (method, path, data, origin) => {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const request = await fetch(requestUrl, requestObject);
|
|
36
|
-
|
|
38
|
+
const response = await request.json();
|
|
39
|
+
|
|
40
|
+
if (!request.ok && fetchOptions.strictErrors === true) {
|
|
41
|
+
const message = `An error has occurred: ${request.status}`;
|
|
42
|
+
throw new Error(message, { cause: response });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return response;
|
|
37
46
|
};
|
|
38
47
|
|
|
39
48
|
export class Api {
|
|
@@ -45,17 +54,17 @@ export class Api {
|
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
|
|
48
|
-
async callEvent(method, path, data) {
|
|
49
|
-
return await makeCall(method, path, data, config.eventDomain);
|
|
57
|
+
async callEvent(method, path, data, options = {}) {
|
|
58
|
+
return await makeCall(method, path, data, config.eventDomain, options);
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
async callCdn(method, path, data) {
|
|
53
|
-
return await makeCall(method, path, data, config.cdnDomain);
|
|
61
|
+
async callCdn(method, path, data, options = {}) {
|
|
62
|
+
return await makeCall(method, path, data, config.cdnDomain, options);
|
|
54
63
|
}
|
|
55
64
|
|
|
56
|
-
async callApi(method, path, data) {
|
|
57
|
-
return await makeCall(method, path, data, config.domain);
|
|
65
|
+
async callApi(method, path, data, options = {}) {
|
|
66
|
+
return await makeCall(method, path, data, config.domain, options);
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
export default
|
|
70
|
+
export default Api;
|
package/client.js
CHANGED
|
@@ -18,7 +18,11 @@ const trackEvent = async (eventData) => {
|
|
|
18
18
|
return await config.api.callEvent('POST', '/api/v1/analytics/event', eventData);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const makeCDNCall = async (endpoint, params, format, options = {}) => {
|
|
22
|
+
return await makeCall(endpoint, params, format, { ...options, cdn: true });
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const makeCall = async (endpoint, params, format, options = {}) => {
|
|
22
26
|
const query = {};
|
|
23
27
|
|
|
24
28
|
if (config.defaultParameters != null) {
|
|
@@ -33,11 +37,18 @@ const makeCall = async (endpoint, params, format) => {
|
|
|
33
37
|
Object.assign(query, params);
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
if (typeof options != 'object' || options == null) {
|
|
41
|
+
console.warn('Unsupported fetch options provided.', options);
|
|
42
|
+
options = {};
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
if (config.identity && config.identity.visitorId()) {
|
|
37
46
|
query.uuid = config.identity.visitorId();
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
|
|
49
|
+
// Origin or CDN?
|
|
50
|
+
const source = options.cdn ? 'callCdn' : 'callApi';
|
|
51
|
+
const response = await config.api[source]('GET', endpoint, query, options);
|
|
41
52
|
|
|
42
53
|
if (response.data && format == 'storefront') {
|
|
43
54
|
for (let i = 0; i < response.data.length; i++) {
|
|
@@ -74,12 +85,16 @@ export class RebuyClient {
|
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
87
|
|
|
77
|
-
async getData(endpoint, params) {
|
|
78
|
-
return await makeCall(endpoint, params);
|
|
88
|
+
async getData(endpoint, params, options = {}) {
|
|
89
|
+
return await makeCall(endpoint, params, null, options);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getDataFromCDN(endpoint, params, options = {}) {
|
|
93
|
+
return await makeCDNCall(endpoint, params, null, options);
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
async getStorefrontData(endpoint, params) {
|
|
82
|
-
return await makeCall(endpoint, params, 'storefront');
|
|
96
|
+
async getStorefrontData(endpoint, params, options = {}) {
|
|
97
|
+
return await makeCall(endpoint, params, 'storefront', options);
|
|
83
98
|
}
|
|
84
99
|
|
|
85
100
|
async trackProductViewed(data) {
|
|
@@ -103,4 +118,4 @@ export class RebuyClient {
|
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
|
|
106
|
-
export default
|
|
121
|
+
export default RebuyClient;
|
package/geolocation.js
CHANGED
package/identity.js
CHANGED
package/package.json
CHANGED
package/session.js
CHANGED