@constructor-io/constructorio-client-javascript 2.29.13 → 2.30.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/README.md +1 -1
- package/lib/constructorio.js +6 -2
- package/lib/modules/quizzes.js +28 -28
- package/package.json +1 -1
- package/lib/.DS_Store +0 -0
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ var constructorio = new ConstructorIOClient({
|
|
|
40
40
|
After instantiating an instance of the client, four modules will be exposed as properties to help retrieve data from Constructor.io: `search`, `browse`, `autocomplete`, `recommendations` and `tracker`.
|
|
41
41
|
|
|
42
42
|
#### Dispatched events
|
|
43
|
-
The `search`, `browse` and `
|
|
43
|
+
The `search`, `browse`, `recommendations` and `autocomplete` modules may dispatch custom events on `window` with response data when a request has been completed. The event name follows the following structure: `cio.client.[moduleName].[methodName].completed`. Example consuming code can be found below:
|
|
44
44
|
|
|
45
45
|
```javascript
|
|
46
46
|
window.addEventListener('cio.client.search.getSearchResults.completed', (event) => {
|
package/lib/constructorio.js
CHANGED
|
@@ -25,7 +25,9 @@ var EventDispatcher = require('./utils/event-dispatcher');
|
|
|
25
25
|
var helpers = require('./utils/helpers');
|
|
26
26
|
|
|
27
27
|
var _require = require('../package.json'),
|
|
28
|
-
packageVersion = _require.version;
|
|
28
|
+
packageVersion = _require.version;
|
|
29
|
+
|
|
30
|
+
var Quizzes = require('./modules/quizzes'); // Compute package version string
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
var computePackageVersion = function computePackageVersion() {
|
|
@@ -72,6 +74,7 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
72
74
|
* @property {object} autocomplete - Interface to {@link module:autocomplete}
|
|
73
75
|
* @property {object} recommendations - Interface to {@link module:recommendations}
|
|
74
76
|
* @property {object} tracker - Interface to {@link module:tracker}
|
|
77
|
+
* @property {object} quizzes - Interface to {@link module:quizzes}
|
|
75
78
|
* @returns {class}
|
|
76
79
|
*/
|
|
77
80
|
function ConstructorIO() {
|
|
@@ -142,7 +145,8 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
142
145
|
this.browse = new Browse(this.options);
|
|
143
146
|
this.autocomplete = new Autocomplete(this.options);
|
|
144
147
|
this.recommendations = new Recommendations(this.options);
|
|
145
|
-
this.tracker = new Tracker(this.options);
|
|
148
|
+
this.tracker = new Tracker(this.options);
|
|
149
|
+
this.quizzes = new Quizzes(this.options); // Dispatch initialization event
|
|
146
150
|
|
|
147
151
|
new EventDispatcher(options.eventDispatcher).queue('instantiated', this.options);
|
|
148
152
|
}
|
package/lib/modules/quizzes.js
CHANGED
|
@@ -66,7 +66,7 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
66
66
|
|
|
67
67
|
if (versionId) {
|
|
68
68
|
queryParams.version_id = versionId;
|
|
69
|
-
} // Pull a from parameters and transform
|
|
69
|
+
} // Pull a (answers) from parameters and transform
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
if (a) {
|
|
@@ -103,31 +103,31 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
103
103
|
this.eventDispatcher = new EventDispatcher(options.eventDispatcher);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
* Retrieve next
|
|
106
|
+
* Retrieve next question from API
|
|
107
107
|
*
|
|
108
|
-
* @function
|
|
109
|
-
* @description Retrieve next
|
|
110
|
-
* @param {string} id - The
|
|
108
|
+
* @function getNextQuestion
|
|
109
|
+
* @description Retrieve next question from Constructor.io API
|
|
110
|
+
* @param {string} id - The identifier of the quiz
|
|
111
111
|
* @param {string} [parameters] - Additional parameters to refine result set
|
|
112
|
-
* @param {string} [parameters.section] -
|
|
113
|
-
* @param {array} [parameters.a] - An array
|
|
114
|
-
* @param {string} [parameters.
|
|
112
|
+
* @param {string} [parameters.section] - Product catalog section
|
|
113
|
+
* @param {array} [parameters.a] - An array of answers in the format [[1,2],[1]]
|
|
114
|
+
* @param {string} [parameters.versionId] - Version identifier for the quiz
|
|
115
115
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
116
116
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
117
117
|
* @returns {Promise}
|
|
118
|
-
* @see https://
|
|
118
|
+
* @see https://docs.constructor.io/rest_api/quiz/using_quizzes/#answering-a-quiz
|
|
119
119
|
* @example
|
|
120
|
-
* constructorio.
|
|
120
|
+
* constructorio.quizzes.getNextQuestion('quizId', {
|
|
121
121
|
* a: [[1,2],[1]],
|
|
122
|
-
* section:
|
|
123
|
-
*
|
|
122
|
+
* section: '123',
|
|
123
|
+
* versionId: '123'
|
|
124
124
|
* });
|
|
125
125
|
*/
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
(0, _createClass2["default"])(Quizzes, [{
|
|
129
|
-
key: "
|
|
130
|
-
value: function
|
|
129
|
+
key: "getNextQuestion",
|
|
130
|
+
value: function getNextQuestion(quizId, parameters) {
|
|
131
131
|
var _this = this;
|
|
132
132
|
|
|
133
133
|
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -165,30 +165,30 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
* Retrieves filter expression and recommendation URL from given answers
|
|
168
|
+
* Retrieves filter expression and recommendation URL from given answers
|
|
169
169
|
*
|
|
170
|
-
* @function
|
|
170
|
+
* @function getQuizResults
|
|
171
171
|
* @description Retrieve quiz recommendation and filter expression from Constructor.io API
|
|
172
|
-
* @param {string} id - The
|
|
172
|
+
* @param {string} id - The identifier of the quiz
|
|
173
173
|
* @param {string} [parameters] - Additional parameters to refine result set
|
|
174
|
-
* @param {string} [parameters.section] -
|
|
175
|
-
* @param {array} [parameters.a] - An array
|
|
176
|
-
* @param {string} [parameters.
|
|
174
|
+
* @param {string} [parameters.section] - Product catalog section
|
|
175
|
+
* @param {array} [parameters.a] - An array of answers in the format [[1,2],[1]]
|
|
176
|
+
* @param {string} [parameters.versionId] - Specific version identifier for the quiz
|
|
177
177
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
178
178
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
179
179
|
* @returns {Promise}
|
|
180
|
-
* @see https://
|
|
180
|
+
* @see https://docs.constructor.io/rest_api/quiz/using_quizzes/#completing-the-quiz
|
|
181
181
|
* @example
|
|
182
|
-
* constructorio.
|
|
182
|
+
* constructorio.quizzes.getQuizResults('quizId', {
|
|
183
183
|
* a: [[1,2],[1]],
|
|
184
|
-
* section:
|
|
185
|
-
*
|
|
184
|
+
* section: '123',
|
|
185
|
+
* versionId: '123'
|
|
186
186
|
* });
|
|
187
187
|
*/
|
|
188
188
|
|
|
189
189
|
}, {
|
|
190
|
-
key: "
|
|
191
|
-
value: function
|
|
190
|
+
key: "getQuizResults",
|
|
191
|
+
value: function getQuizResults(quizId, parameters) {
|
|
192
192
|
var _this2 = this;
|
|
193
193
|
|
|
194
194
|
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -217,12 +217,12 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
217
217
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
218
218
|
}).then(function (json) {
|
|
219
219
|
if (json.version_id) {
|
|
220
|
-
_this2.eventDispatcher.queue('quizzes.
|
|
220
|
+
_this2.eventDispatcher.queue('quizzes.getQuizResults.completed', json);
|
|
221
221
|
|
|
222
222
|
return json;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
throw new Error('
|
|
225
|
+
throw new Error('getQuizResults response data is malformed');
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
}]);
|
package/package.json
CHANGED
package/lib/.DS_Store
DELETED
|
Binary file
|