@constructor-io/constructorio-client-javascript 2.34.9 → 2.35.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 +44 -14
- package/lib/types/index.d.ts +1 -1
- package/lib/types/quizzes.d.ts +64 -5
- package/lib/types/types.d.ts +126 -0
- package/package.json +1 -1
package/lib/modules/quizzes.js
CHANGED
|
@@ -46,22 +46,31 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
46
46
|
throw new Error('quizId is a required parameter of type string');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
if (path === '
|
|
49
|
+
if (path === 'results' && ((0, _typeof2["default"])(parameters.answers) !== 'object' || !Array.isArray(parameters.answers) || parameters.answers.length === 0)) {
|
|
50
50
|
throw new Error('answers is a required parameter of type array');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (parameters) {
|
|
54
54
|
var section = parameters.section,
|
|
55
55
|
answers = parameters.answers,
|
|
56
|
-
|
|
56
|
+
quizSessionId = parameters.quizSessionId,
|
|
57
|
+
quizVersionId = parameters.quizVersionId,
|
|
58
|
+
page = parameters.page,
|
|
59
|
+
resultsPerPage = parameters.resultsPerPage,
|
|
60
|
+
filters = parameters.filters; // Pull section from parameters
|
|
57
61
|
|
|
58
62
|
if (section) {
|
|
59
63
|
queryParams.section = section;
|
|
60
|
-
} // Pull
|
|
64
|
+
} // Pull quiz_version_id from parameters
|
|
61
65
|
|
|
62
66
|
|
|
63
|
-
if (
|
|
64
|
-
queryParams.
|
|
67
|
+
if (quizVersionId) {
|
|
68
|
+
queryParams.quiz_version_id = quizVersionId;
|
|
69
|
+
} // Pull quiz_session_id from parameters
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if (quizSessionId) {
|
|
73
|
+
queryParams.quiz_session_id = quizSessionId;
|
|
65
74
|
} // Pull a (answers) from parameters and transform
|
|
66
75
|
|
|
67
76
|
|
|
@@ -71,6 +80,20 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
71
80
|
return (0, _toConsumableArray2["default"])(ans).join(',');
|
|
72
81
|
})
|
|
73
82
|
}));
|
|
83
|
+
} // Pull page from parameters
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (!helpers.isNil(page)) {
|
|
87
|
+
queryParams.page = page;
|
|
88
|
+
} // Pull results per page from parameters
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (!helpers.isNil(resultsPerPage)) {
|
|
92
|
+
queryParams.num_results_per_page = resultsPerPage;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (filters) {
|
|
96
|
+
queryParams.filters = filters;
|
|
74
97
|
}
|
|
75
98
|
}
|
|
76
99
|
|
|
@@ -103,7 +126,8 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
103
126
|
* @param {string} [parameters] - Additional parameters to refine result set
|
|
104
127
|
* @param {string} [parameters.section] - Product catalog section
|
|
105
128
|
* @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]]
|
|
106
|
-
* @param {string} [parameters.
|
|
129
|
+
* @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
|
|
130
|
+
* @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session 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-sessions
|
|
107
131
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
108
132
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
109
133
|
* @returns {Promise}
|
|
@@ -112,7 +136,8 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
112
136
|
* constructorio.quizzes.getQuizNextQuestion('quizId', {
|
|
113
137
|
* answers: [[1,2],[1]],
|
|
114
138
|
* section: '123',
|
|
115
|
-
*
|
|
139
|
+
* quizVersionId: '123',
|
|
140
|
+
* quizSessionId: '1234',
|
|
116
141
|
* });
|
|
117
142
|
*/
|
|
118
143
|
|
|
@@ -145,7 +170,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
145
170
|
|
|
146
171
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
147
172
|
}).then(function (json) {
|
|
148
|
-
if (json.
|
|
173
|
+
if (json.quiz_version_id) {
|
|
149
174
|
_this.eventDispatcher.queue('quizzes.getQuizNextQuestion.completed', json);
|
|
150
175
|
|
|
151
176
|
return json;
|
|
@@ -160,10 +185,14 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
160
185
|
* @function getQuizResults
|
|
161
186
|
* @description Retrieve quiz recommendation and filter expression from Constructor.io API
|
|
162
187
|
* @param {string} id - The identifier of the quiz
|
|
163
|
-
* @param {string}
|
|
188
|
+
* @param {string} parameters - Additional parameters to refine result set
|
|
189
|
+
* @param {array} parameters.answers - An array of answers in the format [[1,2],[1]]
|
|
164
190
|
* @param {string} [parameters.section] - Product catalog section
|
|
165
|
-
* @param {
|
|
166
|
-
* @param {string} [parameters.
|
|
191
|
+
* @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
|
|
192
|
+
* @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session 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-sessions
|
|
193
|
+
* @param {number} [parameters.page] - The page number of the results
|
|
194
|
+
* @param {number} [parameters.resultsPerPage] - The number of results per page to return
|
|
195
|
+
* @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
|
|
167
196
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
168
197
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
169
198
|
* @returns {Promise}
|
|
@@ -172,7 +201,8 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
172
201
|
* constructorio.quizzes.getQuizResults('quizId', {
|
|
173
202
|
* answers: [[1,2],[1]],
|
|
174
203
|
* section: '123',
|
|
175
|
-
*
|
|
204
|
+
* quizVersionId: '123',
|
|
205
|
+
* quizSessionId: '234'
|
|
176
206
|
* });
|
|
177
207
|
*/
|
|
178
208
|
|
|
@@ -188,7 +218,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
188
218
|
var signal = controller.signal;
|
|
189
219
|
|
|
190
220
|
try {
|
|
191
|
-
requestUrl = createQuizUrl(id, parameters, this.options, '
|
|
221
|
+
requestUrl = createQuizUrl(id, parameters, this.options, 'results');
|
|
192
222
|
} catch (e) {
|
|
193
223
|
return Promise.reject(e);
|
|
194
224
|
} // Handle network timeout if specified
|
|
@@ -204,7 +234,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
204
234
|
|
|
205
235
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
206
236
|
}).then(function (json) {
|
|
207
|
-
if (json.
|
|
237
|
+
if (json.quiz_version_id) {
|
|
208
238
|
_this2.eventDispatcher.queue('quizzes.getQuizResults.completed', json);
|
|
209
239
|
|
|
210
240
|
return json;
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/quizzes.d.ts
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { Nullable } from './index.d';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ConstructorClientOptions,
|
|
4
|
+
Facet,
|
|
5
|
+
Feature,
|
|
6
|
+
Group,
|
|
7
|
+
NetworkParameters,
|
|
8
|
+
RequestFeature,
|
|
9
|
+
RequestFeatureVariant,
|
|
10
|
+
SortOption,
|
|
11
|
+
FilterExpression,
|
|
12
|
+
ResultSources,
|
|
13
|
+
} from '.';
|
|
3
14
|
|
|
4
15
|
export default Quizzes;
|
|
5
16
|
|
|
6
17
|
export interface QuizzesParameters {
|
|
7
18
|
section?: string;
|
|
8
19
|
answers?: any[];
|
|
9
|
-
|
|
20
|
+
quizVersionId?: string;
|
|
21
|
+
quizSessionId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface QuizzesResultsParameters extends QuizzesParameters {
|
|
25
|
+
answers: any[];
|
|
26
|
+
page?: number;
|
|
27
|
+
resultsPerPage?: number;
|
|
28
|
+
filters?: Record<string, any>;
|
|
10
29
|
}
|
|
11
30
|
|
|
12
31
|
declare class Quizzes {
|
|
@@ -22,7 +41,7 @@ declare class Quizzes {
|
|
|
22
41
|
|
|
23
42
|
getQuizResults(
|
|
24
43
|
id: string,
|
|
25
|
-
parameters?:
|
|
44
|
+
parameters?: QuizzesResultsParameters,
|
|
26
45
|
networkParameters?: NetworkParameters
|
|
27
46
|
): Promise<QuizResultsResponse>;
|
|
28
47
|
}
|
|
@@ -32,10 +51,50 @@ export interface NextQuestionResponse extends Record<string, any> {
|
|
|
32
51
|
next_question: Question;
|
|
33
52
|
is_last_question?: boolean;
|
|
34
53
|
version_id?: string;
|
|
54
|
+
quiz_id?: string;
|
|
55
|
+
quiz_session_id?: string;
|
|
35
56
|
}
|
|
57
|
+
|
|
36
58
|
export interface QuizResultsResponse extends Record<string, any> {
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
request?: {
|
|
60
|
+
filters?: Record<string, any>;
|
|
61
|
+
fmt_options: Record<string, any>;
|
|
62
|
+
num_results_per_page: number;
|
|
63
|
+
page: number;
|
|
64
|
+
section: string;
|
|
65
|
+
sort_by: string;
|
|
66
|
+
sort_order: string;
|
|
67
|
+
features: Partial<RequestFeature>;
|
|
68
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
69
|
+
collection_filter_expression: FilterExpression;
|
|
70
|
+
term: string;
|
|
71
|
+
};
|
|
72
|
+
response?: {
|
|
73
|
+
result_sources: Partial<ResultSources>;
|
|
74
|
+
facets: Partial<Facet>[];
|
|
75
|
+
groups: Partial<Group>[];
|
|
76
|
+
results: Partial<QuizResultData>[];
|
|
77
|
+
sort_options: Partial<SortOption>[];
|
|
78
|
+
refined_content: Record<string, any>[];
|
|
79
|
+
total_num_results: number;
|
|
80
|
+
features: Partial<Feature>[];
|
|
81
|
+
};
|
|
82
|
+
result_id?: string;
|
|
83
|
+
quiz_version_id: string;
|
|
84
|
+
quiz_session_id: string;
|
|
85
|
+
quiz_id: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface QuizResultData extends Record<string, any> {
|
|
89
|
+
matched_terms: string[];
|
|
90
|
+
data: {
|
|
91
|
+
id: string;
|
|
92
|
+
[key: string]: any;
|
|
93
|
+
};
|
|
94
|
+
value: string;
|
|
95
|
+
is_slotted: false;
|
|
96
|
+
labels: Record<string, any>;
|
|
97
|
+
variations: Record<string, any>[];
|
|
39
98
|
}
|
|
40
99
|
|
|
41
100
|
export type Question = SelectQuestion | OpenQuestion | CoverQuestion
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import EventDispatcher from './event-dispatcher';
|
|
2
|
+
|
|
3
|
+
export interface ConstructorClientOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
serviceUrl?: string;
|
|
7
|
+
// session id is of type string in jsdocs but of type number in code usage
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
clientId?: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
segments?: string[];
|
|
12
|
+
testCells?: Record<string, string>;
|
|
13
|
+
fetch?: any;
|
|
14
|
+
trackingSendDelay?: number;
|
|
15
|
+
sendTrackingEvents?: boolean;
|
|
16
|
+
sendReferrerWithTrackingEvents?: boolean;
|
|
17
|
+
eventDispatcher?: EventDispatcher;
|
|
18
|
+
beaconMode?: boolean;
|
|
19
|
+
networkParameters?: {
|
|
20
|
+
timeout: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RequestFeature extends Record<string, any> {
|
|
25
|
+
query_items: boolean;
|
|
26
|
+
auto_generated_refined_query_rules: boolean;
|
|
27
|
+
manual_searchandizing: boolean;
|
|
28
|
+
personalization: boolean;
|
|
29
|
+
filter_items: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RequestFeatureVariant extends Record<string, any> {
|
|
33
|
+
query_items: string;
|
|
34
|
+
auto_generated_refined_query_rules: string;
|
|
35
|
+
manual_searchandizing: string | null;
|
|
36
|
+
personalization: string;
|
|
37
|
+
filter_items: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ErrorData = {
|
|
41
|
+
message: string;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export interface ResultSources extends Record<string, any> {
|
|
46
|
+
token_match: { count: number; [key: string]: any };
|
|
47
|
+
embeddings_match: { count: number; [key: string]: any };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SortOption extends Record<string, any> {
|
|
51
|
+
sort_by: string;
|
|
52
|
+
display_name: string;
|
|
53
|
+
sort_order: string;
|
|
54
|
+
status: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Feature extends Record<string, any> {
|
|
58
|
+
feature_name: string;
|
|
59
|
+
display_name: string;
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
variant: {
|
|
62
|
+
name: string;
|
|
63
|
+
display_name: string;
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface FmtOption extends Record<string, any> {
|
|
69
|
+
groups_start: string;
|
|
70
|
+
groups_max_depth: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type Facet = RangeFacet | OptionFacet;
|
|
74
|
+
|
|
75
|
+
export interface BaseFacet extends Record<string, any> {
|
|
76
|
+
data: Record<string, any>;
|
|
77
|
+
status: Record<string, any>;
|
|
78
|
+
display_name: string;
|
|
79
|
+
name: string;
|
|
80
|
+
hidden: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface RangeFacet extends BaseFacet, Record<string, any> {
|
|
84
|
+
max: number;
|
|
85
|
+
min: number;
|
|
86
|
+
type: "range";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface OptionFacet extends BaseFacet, Record<string, any> {
|
|
90
|
+
options: FacetOption[];
|
|
91
|
+
type: "multiple" | "single" | "hierarchical";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface FacetOption extends Record<string, any> {
|
|
95
|
+
count: number;
|
|
96
|
+
display_name: string;
|
|
97
|
+
value: string;
|
|
98
|
+
options?: FacetOption[];
|
|
99
|
+
range?: ["-inf" | number, "inf" | number];
|
|
100
|
+
status: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface Group extends BaseGroup, Record<string, any> {
|
|
104
|
+
count: number;
|
|
105
|
+
data: Record<string, any>;
|
|
106
|
+
parents: BaseGroup[];
|
|
107
|
+
children: Group[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface Collection extends Record<string, any> {
|
|
111
|
+
collection_id: string,
|
|
112
|
+
display_name: string,
|
|
113
|
+
data: Record<string, any>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface BaseGroup extends Record<string, any> {
|
|
117
|
+
display_name: string;
|
|
118
|
+
group_id: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface FmtOptions extends Record<string, any> {
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type Nullable<T> = T | null;
|
|
126
|
+
|