@constructor-io/constructorio-client-javascript 2.45.0 → 2.46.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.
|
@@ -6,7 +6,7 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
6
6
|
/* eslint-disable object-curly-newline, no-underscore-dangle */
|
|
7
7
|
var EventDispatcher = require('../utils/event-dispatcher');
|
|
8
8
|
var _require = require('../utils/helpers'),
|
|
9
|
-
|
|
9
|
+
convertResponseToJson = _require.convertResponseToJson,
|
|
10
10
|
cleanParams = _require.cleanParams,
|
|
11
11
|
applyNetworkTimeout = _require.applyNetworkTimeout,
|
|
12
12
|
trimNonBreakingSpaces = _require.trimNonBreakingSpaces,
|
|
@@ -171,12 +171,7 @@ var Autocomplete = /*#__PURE__*/function () {
|
|
|
171
171
|
}
|
|
172
172
|
return fetch(requestUrl, {
|
|
173
173
|
signal: signal
|
|
174
|
-
}).then(function (
|
|
175
|
-
if (response.ok) {
|
|
176
|
-
return response.json();
|
|
177
|
-
}
|
|
178
|
-
return throwHttpErrorFromResponse(new Error(), response);
|
|
179
|
-
}).then(function (json) {
|
|
174
|
+
}).then(convertResponseToJson).then(function (json) {
|
|
180
175
|
if (json.sections) {
|
|
181
176
|
if (json.result_id) {
|
|
182
177
|
var sectionKeys = Object.keys(json.sections);
|
package/lib/modules/browse.js
CHANGED
|
@@ -267,12 +267,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
267
267
|
}
|
|
268
268
|
return fetch(requestUrl, {
|
|
269
269
|
signal: signal
|
|
270
|
-
}).then(function (
|
|
271
|
-
if (response.ok) {
|
|
272
|
-
return response.json();
|
|
273
|
-
}
|
|
274
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
275
|
-
}).then(function (json) {
|
|
270
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
276
271
|
if (json.response && json.response.results) {
|
|
277
272
|
if (json.result_id) {
|
|
278
273
|
// Append `result_id` to each result item
|
|
@@ -338,12 +333,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
338
333
|
}
|
|
339
334
|
return fetch(requestUrl, {
|
|
340
335
|
signal: signal
|
|
341
|
-
}).then(function (
|
|
342
|
-
if (response.ok) {
|
|
343
|
-
return response.json();
|
|
344
|
-
}
|
|
345
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
346
|
-
}).then(function (json) {
|
|
336
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
347
337
|
if (json.response && json.response.results) {
|
|
348
338
|
if (json.result_id) {
|
|
349
339
|
// Append `result_id` to each result item
|
|
@@ -401,12 +391,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
401
391
|
var requestUrl = "".concat(serviceUrl, "/browse/groups?").concat(queryString);
|
|
402
392
|
return fetch(requestUrl, {
|
|
403
393
|
signal: signal
|
|
404
|
-
}).then(function (
|
|
405
|
-
if (response.ok) {
|
|
406
|
-
return response.json();
|
|
407
|
-
}
|
|
408
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
409
|
-
}).then(function (json) {
|
|
394
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
410
395
|
if (json.response && json.response.groups) {
|
|
411
396
|
_this3.eventDispatcher.queue('browse.getBrowseGroups.completed', json);
|
|
412
397
|
return json;
|
|
@@ -456,12 +441,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
456
441
|
}
|
|
457
442
|
return fetch(requestUrl, {
|
|
458
443
|
signal: signal
|
|
459
|
-
}).then(function (
|
|
460
|
-
if (response.ok) {
|
|
461
|
-
return response.json();
|
|
462
|
-
}
|
|
463
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
464
|
-
}).then(function (json) {
|
|
444
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
465
445
|
if (json.response && json.response.facets) {
|
|
466
446
|
_this4.eventDispatcher.queue('browse.getBrowseFacets.completed', json);
|
|
467
447
|
return json;
|
|
@@ -510,12 +490,7 @@ var Browse = /*#__PURE__*/function () {
|
|
|
510
490
|
}
|
|
511
491
|
return fetch(requestUrl, {
|
|
512
492
|
signal: signal
|
|
513
|
-
}).then(function (
|
|
514
|
-
if (response.ok) {
|
|
515
|
-
return response.json();
|
|
516
|
-
}
|
|
517
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
518
|
-
}).then(function (json) {
|
|
493
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
519
494
|
if (json.response && json.response.facets) {
|
|
520
495
|
_this5.eventDispatcher.queue('browse.getBrowseFacetOptions.completed', json);
|
|
521
496
|
return json;
|
package/lib/modules/quizzes.js
CHANGED
|
@@ -167,12 +167,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
167
167
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
168
168
|
return fetch(requestUrl, {
|
|
169
169
|
signal: signal
|
|
170
|
-
}).then(function (
|
|
171
|
-
if (response.ok) {
|
|
172
|
-
return response.json();
|
|
173
|
-
}
|
|
174
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
175
|
-
}).then(function (json) {
|
|
170
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
176
171
|
if (json.quiz_version_id) {
|
|
177
172
|
_this.eventDispatcher.queue('quizzes.getQuizNextQuestion.completed', json);
|
|
178
173
|
return json;
|
|
@@ -228,12 +223,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
228
223
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
229
224
|
return fetch(requestUrl, {
|
|
230
225
|
signal: signal
|
|
231
|
-
}).then(function (
|
|
232
|
-
if (response.ok) {
|
|
233
|
-
return response.json();
|
|
234
|
-
}
|
|
235
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
236
|
-
}).then(function (json) {
|
|
226
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
237
227
|
if (json.quiz_version_id) {
|
|
238
228
|
_this2.eventDispatcher.queue('quizzes.getQuizResults.completed', json);
|
|
239
229
|
return json;
|
|
@@ -278,12 +268,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
278
268
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
279
269
|
return fetch(requestUrl, {
|
|
280
270
|
signal: signal
|
|
281
|
-
}).then(function (
|
|
282
|
-
if (response.ok) {
|
|
283
|
-
return response.json();
|
|
284
|
-
}
|
|
285
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
286
|
-
}).then(function (json) {
|
|
271
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
287
272
|
if (json.quiz_version_id) {
|
|
288
273
|
_this3.eventDispatcher.queue('quizzes.getQuizResultsConfig.completed', json);
|
|
289
274
|
return json;
|
|
@@ -161,12 +161,7 @@ var Recommendations = /*#__PURE__*/function () {
|
|
|
161
161
|
}
|
|
162
162
|
return fetch(requestUrl, {
|
|
163
163
|
signal: signal
|
|
164
|
-
}).then(function (
|
|
165
|
-
if (response.ok) {
|
|
166
|
-
return response.json();
|
|
167
|
-
}
|
|
168
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
169
|
-
}).then(function (json) {
|
|
164
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
170
165
|
if (json.response && json.response.results) {
|
|
171
166
|
if (json.result_id) {
|
|
172
167
|
// Append `result_id` to each result item
|
package/lib/modules/search.js
CHANGED
|
@@ -215,12 +215,7 @@ var Search = /*#__PURE__*/function () {
|
|
|
215
215
|
}
|
|
216
216
|
return fetch(requestUrl, {
|
|
217
217
|
signal: signal
|
|
218
|
-
}).then(function (
|
|
219
|
-
if (response.ok) {
|
|
220
|
-
return response.json();
|
|
221
|
-
}
|
|
222
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
223
|
-
}).then(function (json) {
|
|
218
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
224
219
|
// Search results
|
|
225
220
|
if (json.response && json.response.results) {
|
|
226
221
|
if (json.result_id) {
|
|
@@ -290,12 +285,7 @@ var Search = /*#__PURE__*/function () {
|
|
|
290
285
|
}
|
|
291
286
|
return fetch(requestUrl, {
|
|
292
287
|
signal: signal
|
|
293
|
-
}).then(function (
|
|
294
|
-
if (response.ok) {
|
|
295
|
-
return response.json();
|
|
296
|
-
}
|
|
297
|
-
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
298
|
-
}).then(function (json) {
|
|
288
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
299
289
|
// Search results
|
|
300
290
|
if (json.response && json.response.results) {
|
|
301
291
|
if (json.result_id) {
|
package/lib/utils/helpers.js
CHANGED
|
@@ -221,6 +221,16 @@ var utils = {
|
|
|
221
221
|
}
|
|
222
222
|
return obfuscatedUrl;
|
|
223
223
|
},
|
|
224
|
+
convertResponseToJson: function convertResponseToJson(response) {
|
|
225
|
+
if (response.ok) {
|
|
226
|
+
return response.json()["catch"](function () {
|
|
227
|
+
return response.text().then(function (responseText) {
|
|
228
|
+
throw new Error("Server responded with an invalid JSON object. Response code: ".concat(response.code, ", Response: ").concat(responseText));
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return utils.throwHttpErrorFromResponse(new Error(), response);
|
|
233
|
+
},
|
|
224
234
|
addHTTPSToString: function addHTTPSToString(url) {
|
|
225
235
|
if (typeof url !== 'string') {
|
|
226
236
|
return null;
|