@constructor-io/constructorio-client-javascript 2.67.6 → 2.68.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/lib/modules/quizzes.js +46 -0
- package/lib/types/quizzes.d.ts +8 -0
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/lib/modules/quizzes.js
CHANGED
|
@@ -276,6 +276,52 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
276
276
|
throw new Error('getQuizResultsConfig response data is malformed');
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Retrieves all questions for a particular quiz
|
|
282
|
+
*
|
|
283
|
+
* @function getQuizAllQuestions
|
|
284
|
+
* @description Retrieve all questions for a particular quiz from Constructor.io API
|
|
285
|
+
* @param {string} quizId - The identifier of the quiz
|
|
286
|
+
* @param {object} parameters - Additional parameters
|
|
287
|
+
* @param {string} [parameters.section] - Product catalog section
|
|
288
|
+
* @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes
|
|
289
|
+
* @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request or with getQuizResultsConfig and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes
|
|
290
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
291
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
292
|
+
* @returns {Promise}
|
|
293
|
+
* @example
|
|
294
|
+
* constructorio.quizzes.getQuizAllQuestions('quizId', {
|
|
295
|
+
* quizVersionId: '123',
|
|
296
|
+
* });
|
|
297
|
+
*/
|
|
298
|
+
}, {
|
|
299
|
+
key: "getQuizAllQuestions",
|
|
300
|
+
value: function getQuizAllQuestions(quizId, parameters) {
|
|
301
|
+
var _this4 = this;
|
|
302
|
+
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
303
|
+
var requestUrl;
|
|
304
|
+
var fetch = this.options.fetch;
|
|
305
|
+
var controller = new AbortController();
|
|
306
|
+
var signal = controller.signal;
|
|
307
|
+
try {
|
|
308
|
+
requestUrl = createQuizUrl(quizId, parameters, this.options, 'all_questions');
|
|
309
|
+
} catch (e) {
|
|
310
|
+
return Promise.reject(e);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Handle network timeout if specified
|
|
314
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
315
|
+
return fetch(requestUrl, {
|
|
316
|
+
signal: signal
|
|
317
|
+
}).then(helpers.convertResponseToJson).then(function (json) {
|
|
318
|
+
if (json.quiz_version_id) {
|
|
319
|
+
_this4.eventDispatcher.queue('quizzes.getQuizAllQuestions.completed', json);
|
|
320
|
+
return json;
|
|
321
|
+
}
|
|
322
|
+
throw new Error('getQuizAllQuestions response data is malformed');
|
|
323
|
+
});
|
|
324
|
+
}
|
|
279
325
|
}]);
|
|
280
326
|
}();
|
|
281
327
|
module.exports = Quizzes;
|
package/lib/types/quizzes.d.ts
CHANGED
|
@@ -68,6 +68,14 @@ export interface NextQuestionResponse extends Record<string, any> {
|
|
|
68
68
|
total_questions: number;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export interface AllQuestionsResponse extends Record<string, any> {
|
|
72
|
+
questions: Question[];
|
|
73
|
+
quiz_version_id?: string;
|
|
74
|
+
quiz_id?: string;
|
|
75
|
+
quiz_session_id?: string;
|
|
76
|
+
total_questions: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
export interface QuizResultsResponse extends Record<string, any> {
|
|
72
80
|
request?: {
|
|
73
81
|
filters?: Record<string, any>;
|
package/lib/version.js
CHANGED