@constructor-io/constructorio-client-javascript 2.37.4 → 2.39.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.
@@ -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
  }();
@@ -189,11 +189,14 @@ export interface Item extends Record<string, any> {
189
189
  labels: Record<string, unknown>;
190
190
  matched_terms: string[];
191
191
  data?: ItemData;
192
+ strategy?: { id: string };
193
+ variations?: { data?: ItemData, value: string }[]
192
194
  }
193
195
 
194
196
  export interface ItemData extends Record<string, any> {
195
197
  url?: string;
196
198
  id?: string;
199
+ variation_id?: string;
197
200
  image_url?: string;
198
201
  group_ids?: string[];
199
202
  groups?: Group[]
@@ -44,12 +44,17 @@ 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 */
50
56
  export interface NextQuestionResponse extends Record<string, any> {
51
57
  next_question: Question;
52
- is_last_question?: boolean;
53
58
  quiz_version_id?: string;
54
59
  quiz_id?: string;
55
60
  quiz_session_id?: string;
@@ -148,3 +153,23 @@ export interface QuestionImages extends Record<string, any> {
148
153
  secondary_url?: Nullable<string>;
149
154
  secondary_alt?: Nullable<string>;
150
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.37.4",
3
+ "version": "2.39.0",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "types": "lib/types/index.d.ts",