@constructor-io/constructorio-client-javascript 2.38.0 → 2.39.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 +50 -0
- package/lib/types/quizzes.d.ts +26 -0
- package/package.json +2 -2
package/lib/modules/quizzes.js
CHANGED
|
@@ -223,6 +223,56 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
223
223
|
throw new Error('getQuizResults response data is malformed');
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Retrieves configuration for the results page of a particular quiz
|
|
229
|
+
*
|
|
230
|
+
* @function getQuizResultsConfig
|
|
231
|
+
* @description Retrieve quiz results page configuration from Constructor.io API
|
|
232
|
+
* @param {string} quizId - The identifier of the quiz
|
|
233
|
+
* @param {string} parameters - Additional parameters
|
|
234
|
+
* @param {string} [parameters.section] - Product catalog section
|
|
235
|
+
* @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.io/rest_api/quiz/using_quizzes/#quiz-versioning
|
|
236
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
237
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
238
|
+
* @returns {Promise}
|
|
239
|
+
* @example
|
|
240
|
+
* constructorio.quizzes.getQuizResultsConfig('quizId', {
|
|
241
|
+
* quizVersionId: '123',
|
|
242
|
+
* });
|
|
243
|
+
*/
|
|
244
|
+
}, {
|
|
245
|
+
key: "getQuizResultsConfig",
|
|
246
|
+
value: function getQuizResultsConfig(quizId, parameters) {
|
|
247
|
+
var _this3 = this;
|
|
248
|
+
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
249
|
+
var requestUrl;
|
|
250
|
+
var fetch = this.options.fetch;
|
|
251
|
+
var controller = new AbortController();
|
|
252
|
+
var signal = controller.signal;
|
|
253
|
+
try {
|
|
254
|
+
requestUrl = createQuizUrl(quizId, parameters, this.options, 'results_config');
|
|
255
|
+
} catch (e) {
|
|
256
|
+
return Promise.reject(e);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Handle network timeout if specified
|
|
260
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
261
|
+
return fetch(requestUrl, {
|
|
262
|
+
signal: signal
|
|
263
|
+
}).then(function (response) {
|
|
264
|
+
if (response.ok) {
|
|
265
|
+
return response.json();
|
|
266
|
+
}
|
|
267
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
268
|
+
}).then(function (json) {
|
|
269
|
+
if (json.quiz_version_id) {
|
|
270
|
+
_this3.eventDispatcher.queue('quizzes.getQuizResultsConfig.completed', json);
|
|
271
|
+
return json;
|
|
272
|
+
}
|
|
273
|
+
throw new Error('getQuizResultsConfig response data is malformed');
|
|
274
|
+
});
|
|
275
|
+
}
|
|
226
276
|
}]);
|
|
227
277
|
return Quizzes;
|
|
228
278
|
}();
|
package/lib/types/quizzes.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ declare class Quizzes {
|
|
|
44
44
|
parameters?: QuizzesResultsParameters,
|
|
45
45
|
networkParameters?: NetworkParameters
|
|
46
46
|
): Promise<QuizResultsResponse>;
|
|
47
|
+
|
|
48
|
+
getQuizResultsConfig(
|
|
49
|
+
quizId: string,
|
|
50
|
+
parameters?: Pick<QuizzesParameters, 'quizVersionId'>,
|
|
51
|
+
networkParameters?: NetworkParameters,
|
|
52
|
+
): Promise<QuizResultsConfigResponse>;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/* quizzes results returned from server */
|
|
@@ -147,3 +153,23 @@ export interface QuestionImages extends Record<string, any> {
|
|
|
147
153
|
secondary_url?: Nullable<string>;
|
|
148
154
|
secondary_alt?: Nullable<string>;
|
|
149
155
|
}
|
|
156
|
+
|
|
157
|
+
type ResultConfigFields = {
|
|
158
|
+
is_active: boolean;
|
|
159
|
+
text: Nullable<string>
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type ViewportResultsConfig = {
|
|
163
|
+
title: Nullable<ResultConfigFields>;
|
|
164
|
+
description: Nullable<ResultConfigFields>;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export interface QuizResultsConfig extends Record<string, any> {
|
|
168
|
+
desktop: ViewportResultsConfig;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface QuizResultsConfigResponse extends Record<string, any> {
|
|
172
|
+
results_config: QuizResultsConfig,
|
|
173
|
+
quiz_version_id: string;
|
|
174
|
+
quiz_id: string;
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-client-javascript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.39.1",
|
|
4
4
|
"description": "Constructor.io JavaScript client",
|
|
5
5
|
"main": "lib/constructorio.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"tsd": "^0.24.1"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@constructor-io/constructorio-id": "^2.4.
|
|
74
|
+
"@constructor-io/constructorio-id": "^2.4.17",
|
|
75
75
|
"crc-32": "^1.2.2",
|
|
76
76
|
"fetch-ponyfill": "^7.1.0",
|
|
77
77
|
"store2": "^2.14.2"
|