@constructor-io/constructorio-client-javascript 2.67.6 → 2.68.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/modules/quizzes.js +46 -0
- package/lib/types/quizzes.d.ts +18 -3
- 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>;
|
|
@@ -129,7 +137,7 @@ export interface BaseQuestion extends Record<string, any> {
|
|
|
129
137
|
export interface FilterValueQuestion extends BaseQuestion {
|
|
130
138
|
type: 'single_filter_value' |'multiple_filter_values';
|
|
131
139
|
filter_name: string;
|
|
132
|
-
options:
|
|
140
|
+
options: FilterQuestionOption[];
|
|
133
141
|
}
|
|
134
142
|
|
|
135
143
|
export interface SelectQuestion extends BaseQuestion {
|
|
@@ -151,8 +159,7 @@ export interface QuizResult extends Record<string, any> {
|
|
|
151
159
|
results_url: string;
|
|
152
160
|
}
|
|
153
161
|
|
|
154
|
-
export interface
|
|
155
|
-
id: number;
|
|
162
|
+
export interface BaseQuestionOption extends Record<string, any> {
|
|
156
163
|
value: string;
|
|
157
164
|
attribute: Nullable<{
|
|
158
165
|
name: string;
|
|
@@ -161,6 +168,14 @@ export interface QuestionOption extends Record<string, any> {
|
|
|
161
168
|
images?: Nullable<QuestionImages>;
|
|
162
169
|
}
|
|
163
170
|
|
|
171
|
+
export interface QuestionOption extends BaseQuestionOption {
|
|
172
|
+
id: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface FilterQuestionOption extends BaseQuestionOption {
|
|
176
|
+
id: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
164
179
|
export interface QuestionImages extends Record<string, any> {
|
|
165
180
|
primary_url?: Nullable<string>;
|
|
166
181
|
primary_alt?: Nullable<string>;
|
package/lib/version.js
CHANGED