@constructor-io/constructorio-client-javascript 2.34.9 → 2.35.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/lib/modules/quizzes.js +25 -5
- package/lib/types/index.d.ts +1 -1
- package/lib/types/quizzes.d.ts +60 -4
- package/lib/types/types.d.ts +126 -0
- package/package.json +1 -1
package/lib/modules/quizzes.js
CHANGED
|
@@ -46,14 +46,17 @@ 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
|
-
versionId = parameters.versionId
|
|
56
|
+
versionId = parameters.versionId,
|
|
57
|
+
page = parameters.page,
|
|
58
|
+
resultsPerPage = parameters.resultsPerPage,
|
|
59
|
+
filters = parameters.filters; // Pull section from parameters
|
|
57
60
|
|
|
58
61
|
if (section) {
|
|
59
62
|
queryParams.section = section;
|
|
@@ -71,6 +74,20 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
71
74
|
return (0, _toConsumableArray2["default"])(ans).join(',');
|
|
72
75
|
})
|
|
73
76
|
}));
|
|
77
|
+
} // Pull page from parameters
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if (!helpers.isNil(page)) {
|
|
81
|
+
queryParams.page = page;
|
|
82
|
+
} // Pull results per page from parameters
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (!helpers.isNil(resultsPerPage)) {
|
|
86
|
+
queryParams.num_results_per_page = resultsPerPage;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (filters) {
|
|
90
|
+
queryParams.filters = filters;
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
|
|
@@ -160,10 +177,13 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
160
177
|
* @function getQuizResults
|
|
161
178
|
* @description Retrieve quiz recommendation and filter expression from Constructor.io API
|
|
162
179
|
* @param {string} id - The identifier of the quiz
|
|
163
|
-
* @param {string}
|
|
180
|
+
* @param {string} parameters - Additional parameters to refine result set
|
|
181
|
+
* @param {array} parameters.answers - An array of answers in the format [[1,2],[1]]
|
|
164
182
|
* @param {string} [parameters.section] - Product catalog section
|
|
165
|
-
* @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]]
|
|
166
183
|
* @param {string} [parameters.versionId] - Specific version identifier for the quiz
|
|
184
|
+
* @param {number} [parameters.page] - The page number of the results
|
|
185
|
+
* @param {number} [parameters.resultsPerPage] - The number of results per page to return
|
|
186
|
+
* @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
|
|
167
187
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
168
188
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
169
189
|
* @returns {Promise}
|
|
@@ -188,7 +208,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
188
208
|
var signal = controller.signal;
|
|
189
209
|
|
|
190
210
|
try {
|
|
191
|
-
requestUrl = createQuizUrl(id, parameters, this.options, '
|
|
211
|
+
requestUrl = createQuizUrl(id, parameters, this.options, 'results');
|
|
192
212
|
} catch (e) {
|
|
193
213
|
return Promise.reject(e);
|
|
194
214
|
} // Handle network timeout if specified
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/quizzes.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
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
|
|
|
@@ -9,6 +20,13 @@ export interface QuizzesParameters {
|
|
|
9
20
|
versionId?: string;
|
|
10
21
|
}
|
|
11
22
|
|
|
23
|
+
export interface QuizzesResultsParameters extends QuizzesParameters {
|
|
24
|
+
answers: any[];
|
|
25
|
+
page?: number;
|
|
26
|
+
resultsPerPage?: number;
|
|
27
|
+
filters?: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
declare class Quizzes {
|
|
13
31
|
constructor(options: ConstructorClientOptions);
|
|
14
32
|
|
|
@@ -22,7 +40,7 @@ declare class Quizzes {
|
|
|
22
40
|
|
|
23
41
|
getQuizResults(
|
|
24
42
|
id: string,
|
|
25
|
-
parameters?:
|
|
43
|
+
parameters?: QuizzesResultsParameters,
|
|
26
44
|
networkParameters?: NetworkParameters
|
|
27
45
|
): Promise<QuizResultsResponse>;
|
|
28
46
|
}
|
|
@@ -33,9 +51,47 @@ export interface NextQuestionResponse extends Record<string, any> {
|
|
|
33
51
|
is_last_question?: boolean;
|
|
34
52
|
version_id?: string;
|
|
35
53
|
}
|
|
54
|
+
|
|
36
55
|
export interface QuizResultsResponse extends Record<string, any> {
|
|
37
|
-
|
|
38
|
-
|
|
56
|
+
request?: {
|
|
57
|
+
filters?: Record<string, any>;
|
|
58
|
+
fmt_options: Record<string, any>;
|
|
59
|
+
num_results_per_page: number;
|
|
60
|
+
page: number;
|
|
61
|
+
section: string;
|
|
62
|
+
sort_by: string;
|
|
63
|
+
sort_order: string;
|
|
64
|
+
features: Partial<RequestFeature>;
|
|
65
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
66
|
+
collection_filter_expression: FilterExpression;
|
|
67
|
+
term: string;
|
|
68
|
+
};
|
|
69
|
+
response?: {
|
|
70
|
+
result_sources: Partial<ResultSources>;
|
|
71
|
+
facets: Partial<Facet>[];
|
|
72
|
+
groups: Partial<Group>[];
|
|
73
|
+
results: Partial<QuizResultData>[];
|
|
74
|
+
sort_options: Partial<SortOption>[];
|
|
75
|
+
refined_content: Record<string, any>[];
|
|
76
|
+
total_num_results: number;
|
|
77
|
+
features: Partial<Feature>[];
|
|
78
|
+
};
|
|
79
|
+
result_id?: string;
|
|
80
|
+
version_id: string;
|
|
81
|
+
quiz_session_id: string;
|
|
82
|
+
quiz_id: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface QuizResultData extends Record<string, any> {
|
|
86
|
+
matched_terms: string[];
|
|
87
|
+
data: {
|
|
88
|
+
id: string;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
};
|
|
91
|
+
value: string;
|
|
92
|
+
is_slotted: false;
|
|
93
|
+
labels: Record<string, any>;
|
|
94
|
+
variations: Record<string, any>[];
|
|
39
95
|
}
|
|
40
96
|
|
|
41
97
|
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
|
+
|