@dataggo/node-akeneo-api 1.4.0 → 1.5.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/dist/cjs/http-client.js +21 -7
- package/dist/mjs/http-client.js +21 -7
- package/package.json +1 -1
package/dist/cjs/http-client.js
CHANGED
|
@@ -41,13 +41,27 @@ const createConnectionHttpClient = (options) => {
|
|
|
41
41
|
const instance = axios_1.default.create(Object.assign(Object.assign(Object.assign({}, defaultConfig), (options.axiosOptions || {})), { baseURL }));
|
|
42
42
|
const base64Encoded = Buffer.from(`${clientId}:${secret}`).toString('base64');
|
|
43
43
|
const refreshAccessToken = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const maxRetries = 3;
|
|
45
|
+
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
46
|
+
try {
|
|
47
|
+
// eslint-disable-next-line no-await-in-loop
|
|
48
|
+
const tokenResult = yield axios_1.default.post(`${baseURL}${TOKEN_PATH}`, { grant_type: 'password', username, password }, {
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: `Basic ${base64Encoded}`,
|
|
51
|
+
},
|
|
52
|
+
timeout: 30000,
|
|
53
|
+
});
|
|
54
|
+
accessToken = tokenResult.data.access_token;
|
|
55
|
+
return accessToken;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (attempt === maxRetries)
|
|
59
|
+
throw error;
|
|
60
|
+
// eslint-disable-next-line no-await-in-loop
|
|
61
|
+
yield new Promise((resolve) => setTimeout(resolve, 200 * (Math.pow(2, attempt))));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw new Error('Failed to refresh access token');
|
|
51
65
|
});
|
|
52
66
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
53
67
|
// @ts-ignore
|
package/dist/mjs/http-client.js
CHANGED
|
@@ -30,13 +30,27 @@ export const createConnectionHttpClient = (options) => {
|
|
|
30
30
|
});
|
|
31
31
|
const base64Encoded = Buffer.from(`${clientId}:${secret}`).toString('base64');
|
|
32
32
|
const refreshAccessToken = async () => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
const maxRetries = 3;
|
|
34
|
+
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
|
|
35
|
+
try {
|
|
36
|
+
// eslint-disable-next-line no-await-in-loop
|
|
37
|
+
const tokenResult = await axios.post(`${baseURL}${TOKEN_PATH}`, { grant_type: 'password', username, password }, {
|
|
38
|
+
headers: {
|
|
39
|
+
Authorization: `Basic ${base64Encoded}`,
|
|
40
|
+
},
|
|
41
|
+
timeout: 30000,
|
|
42
|
+
});
|
|
43
|
+
accessToken = tokenResult.data.access_token;
|
|
44
|
+
return accessToken;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (attempt === maxRetries)
|
|
48
|
+
throw error;
|
|
49
|
+
// eslint-disable-next-line no-await-in-loop
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 200 * (2 ** attempt)));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error('Failed to refresh access token');
|
|
40
54
|
};
|
|
41
55
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
56
|
// @ts-ignore
|