sfmc-sdk 0.5.0 → 0.5.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/lib/auth.js +2 -2
- package/lib/rest.js +6 -3
- package/lib/soap.js +6 -3
- package/package.json +6 -6
- package/test/rest.test.js +23 -1
- package/test/utils.js +1 -1
package/lib/auth.js
CHANGED
|
@@ -154,17 +154,17 @@ module.exports = class Auth {
|
|
|
154
154
|
}
|
|
155
155
|
if (Boolean(forceRefresh) || _isExpired(this.authObject)) {
|
|
156
156
|
try {
|
|
157
|
+
remainingAttempts--;
|
|
157
158
|
this.authObject = await _requestToken(this.authObject);
|
|
158
159
|
} catch (ex) {
|
|
159
160
|
if (
|
|
160
161
|
this.options.retryOnConnectionError &&
|
|
161
|
-
remainingAttempts &&
|
|
162
|
+
remainingAttempts > 0 &&
|
|
162
163
|
isConnectionError(ex.code)
|
|
163
164
|
) {
|
|
164
165
|
if (this.options?.eventHandlers?.onConnectionError) {
|
|
165
166
|
this.options.eventHandlers.onConnectionError(ex, remainingAttempts);
|
|
166
167
|
}
|
|
167
|
-
remainingAttempts--;
|
|
168
168
|
return this.getAccessToken(forceRefresh, remainingAttempts);
|
|
169
169
|
} else {
|
|
170
170
|
throw ex;
|
package/lib/rest.js
CHANGED
|
@@ -175,21 +175,24 @@ module.exports = class Rest {
|
|
|
175
175
|
requestOptions.headers = {
|
|
176
176
|
Authorization: `Bearer ` + this.auth.authObject.access_token,
|
|
177
177
|
};
|
|
178
|
+
remainingAttempts--;
|
|
178
179
|
const res = await axios(requestOptions);
|
|
179
180
|
return res.data;
|
|
180
181
|
} catch (ex) {
|
|
181
182
|
if (
|
|
182
183
|
this.options.retryOnConnectionError &&
|
|
183
|
-
remainingAttempts &&
|
|
184
|
+
remainingAttempts > 0 &&
|
|
184
185
|
isConnectionError(ex.code)
|
|
185
186
|
) {
|
|
186
|
-
|
|
187
|
+
if (this.options?.eventHandlers?.onConnectionError) {
|
|
188
|
+
this.options.eventHandlers.onConnectionError(ex, remainingAttempts);
|
|
189
|
+
}
|
|
187
190
|
return this._apiRequest(requestOptions, remainingAttempts);
|
|
188
191
|
} else if (ex.response && ex.response.status === 401 && remainingAttempts) {
|
|
189
192
|
// force refresh due to url related issue
|
|
190
193
|
await this.auth.getAccessToken(true);
|
|
191
194
|
//only retry once on refresh since there should be no reason for this token to be invalid
|
|
192
|
-
return this._apiRequest(requestOptions,
|
|
195
|
+
return this._apiRequest(requestOptions, 1);
|
|
193
196
|
} else {
|
|
194
197
|
throw ex;
|
|
195
198
|
}
|
package/lib/soap.js
CHANGED
|
@@ -367,15 +367,18 @@ module.exports = class Soap {
|
|
|
367
367
|
this.options.eventHandlers.logRequest(requestOptions);
|
|
368
368
|
}
|
|
369
369
|
let response;
|
|
370
|
+
remainingAttempts--;
|
|
370
371
|
try {
|
|
371
372
|
response = await axios(requestOptions);
|
|
372
373
|
} catch (ex) {
|
|
373
374
|
if (
|
|
374
375
|
this.options.retryOnConnectionError &&
|
|
375
|
-
remainingAttempts &&
|
|
376
|
+
remainingAttempts > 0 &&
|
|
376
377
|
isConnectionError(ex.code)
|
|
377
378
|
) {
|
|
378
|
-
|
|
379
|
+
if (this.options?.eventHandlers?.onConnectionError) {
|
|
380
|
+
this.options.eventHandlers.onConnectionError(ex, remainingAttempts);
|
|
381
|
+
}
|
|
379
382
|
return this._apiRequest(options, remainingAttempts);
|
|
380
383
|
} else if (ex.response) {
|
|
381
384
|
// if the response is received, then continue parsing and check for errors later
|
|
@@ -403,7 +406,7 @@ module.exports = class Soap {
|
|
|
403
406
|
// force refresh due to url related issue
|
|
404
407
|
await this.auth.getAccessToken(true);
|
|
405
408
|
// set to no more retries as after token refresh it should always work
|
|
406
|
-
return this._apiRequest(options,
|
|
409
|
+
return this._apiRequest(options, 1);
|
|
407
410
|
} else {
|
|
408
411
|
throw ex;
|
|
409
412
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sfmc-sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Libarary to simplify SFMC requests with updated dependencies and less overhead",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"author": "Doug Midgley <douglasmidgley@gmail.com>",
|
|
16
16
|
"license": "BSD-3-Clause",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"axios": "^0.26.
|
|
19
|
-
"fast-xml-parser": "4.0.
|
|
18
|
+
"axios": "^0.26.1",
|
|
19
|
+
"fast-xml-parser": "4.0.7",
|
|
20
20
|
"p-limit": "3.1.0"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"assert": "2.0.0",
|
|
35
35
|
"axios-mock-adapter": "1.20.0",
|
|
36
36
|
"chai": "4.3.6",
|
|
37
|
-
"eslint-config-prettier": "8.
|
|
38
|
-
"eslint-plugin-jsdoc": "
|
|
37
|
+
"eslint-config-prettier": "8.5.0",
|
|
38
|
+
"eslint-plugin-jsdoc": "38.0.8",
|
|
39
39
|
"eslint-plugin-mocha": "10.0.3",
|
|
40
40
|
"eslint-plugin-prettier": "4.0.0",
|
|
41
|
-
"mocha": "9.2.
|
|
41
|
+
"mocha": "9.2.2",
|
|
42
42
|
"nyc": "15.1.0",
|
|
43
43
|
"prettier-eslint": "13.0.0",
|
|
44
44
|
"sinon": "13.0.1"
|
package/test/rest.test.js
CHANGED
|
@@ -250,7 +250,7 @@ describe('rest', () => {
|
|
|
250
250
|
assert.lengthOf(mock.history.get, 2);
|
|
251
251
|
return;
|
|
252
252
|
});
|
|
253
|
-
it('FAILED RETRY: should return error, after 2 connection errors', async () => {
|
|
253
|
+
it('FAILED RETRY: should return error, after 2 connection timeout errors', async () => {
|
|
254
254
|
//given
|
|
255
255
|
const { journeysPage1 } = resources;
|
|
256
256
|
mock.onGet(journeysPage1.url).timeout();
|
|
@@ -265,6 +265,28 @@ describe('rest', () => {
|
|
|
265
265
|
assert.lengthOf(mock.history.post, 1);
|
|
266
266
|
assert.lengthOf(mock.history.get, 2);
|
|
267
267
|
|
|
268
|
+
return;
|
|
269
|
+
});
|
|
270
|
+
it('FAILED RETRY: should return error, after 2 ECONNRESET errors', async () => {
|
|
271
|
+
//given
|
|
272
|
+
const { journeysPage1 } = resources;
|
|
273
|
+
|
|
274
|
+
mock.onGet(journeysPage1.url).reply((res) => {
|
|
275
|
+
const connectionError = new Error();
|
|
276
|
+
connectionError.code = 'ECONNRESET';
|
|
277
|
+
throw connectionError;
|
|
278
|
+
});
|
|
279
|
+
// when
|
|
280
|
+
try {
|
|
281
|
+
await defaultSdk().rest.get('interaction/v1/interactions?$pageSize=5&$page=1');
|
|
282
|
+
assert.fail();
|
|
283
|
+
} catch (ex) {
|
|
284
|
+
// then
|
|
285
|
+
assert.isTrue(isConnectionError(ex.code));
|
|
286
|
+
}
|
|
287
|
+
assert.lengthOf(mock.history.post, 1);
|
|
288
|
+
assert.lengthOf(mock.history.get, 2);
|
|
289
|
+
|
|
268
290
|
return;
|
|
269
291
|
});
|
|
270
292
|
});
|