@constructor-io/constructorio-client-javascript 2.30.1 → 2.32.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/autocomplete.js +0 -2
- package/lib/modules/browse.js +0 -2
- package/lib/modules/quizzes.js +16 -18
- package/lib/modules/recommendations.js +1 -5
- package/lib/modules/search.js +1 -2
- package/lib/types/autocomplete.d.ts +67 -0
- package/lib/types/browse.d.ts +133 -0
- package/lib/types/constructorio.d.ts +29 -0
- package/lib/types/event-dispatcher.d.ts +13 -0
- package/lib/types/recommendations.d.ts +77 -0
- package/lib/types/search.d.ts +109 -0
- package/lib/types/tracker.d.ts +162 -0
- package/lib/types/types.d.ts +126 -0
- package/lib/utils/helpers.js +1 -1
- package/lib/utils/request-queue.js +0 -2
- package/package.json +7 -5
package/lib/modules/browse.js
CHANGED
|
@@ -17,8 +17,6 @@ var qs = require('qs');
|
|
|
17
17
|
|
|
18
18
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
19
19
|
|
|
20
|
-
var Promise = require('es6-promise');
|
|
21
|
-
|
|
22
20
|
var EventDispatcher = require('../utils/event-dispatcher');
|
|
23
21
|
|
|
24
22
|
var helpers = require('../utils/helpers'); // Create query params from parameters and options
|
package/lib/modules/quizzes.js
CHANGED
|
@@ -13,8 +13,6 @@ var qs = require('qs');
|
|
|
13
13
|
|
|
14
14
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
15
15
|
|
|
16
|
-
var Promise = require('es6-promise');
|
|
17
|
-
|
|
18
16
|
var EventDispatcher = require('../utils/event-dispatcher');
|
|
19
17
|
|
|
20
18
|
var helpers = require('../utils/helpers'); // Create URL from supplied quizId and parameters
|
|
@@ -50,13 +48,13 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
50
48
|
throw new Error('quizId is a required parameter of type string');
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
if (path === 'finalize' && ((0, _typeof2["default"])(parameters.
|
|
54
|
-
throw new Error('
|
|
51
|
+
if (path === 'finalize' && ((0, _typeof2["default"])(parameters.answers) !== 'object' || !Array.isArray(parameters.answers) || parameters.answers.length === 0)) {
|
|
52
|
+
throw new Error('answers is a required parameter of type array');
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
if (parameters) {
|
|
58
56
|
var section = parameters.section,
|
|
59
|
-
|
|
57
|
+
answers = parameters.answers,
|
|
60
58
|
versionId = parameters.versionId; // Pull section from parameters
|
|
61
59
|
|
|
62
60
|
if (section) {
|
|
@@ -66,11 +64,11 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
66
64
|
|
|
67
65
|
if (versionId) {
|
|
68
66
|
queryParams.version_id = versionId;
|
|
69
|
-
} // Pull
|
|
67
|
+
} // Pull answers from parameters.answers and transform
|
|
70
68
|
|
|
71
69
|
|
|
72
|
-
if (
|
|
73
|
-
|
|
70
|
+
if (answers) {
|
|
71
|
+
answers.forEach(function (ans) {
|
|
74
72
|
answersParamString += "&".concat(qs.stringify({
|
|
75
73
|
a: ans
|
|
76
74
|
}, {
|
|
@@ -105,20 +103,20 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
105
103
|
/**
|
|
106
104
|
* Retrieve next question from API
|
|
107
105
|
*
|
|
108
|
-
* @function
|
|
106
|
+
* @function getQuizNextQuestion
|
|
109
107
|
* @description Retrieve next question from Constructor.io API
|
|
110
108
|
* @param {string} id - The identifier of the quiz
|
|
111
109
|
* @param {string} [parameters] - Additional parameters to refine result set
|
|
112
110
|
* @param {string} [parameters.section] - Product catalog section
|
|
113
|
-
* @param {array} [parameters.
|
|
111
|
+
* @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]]
|
|
114
112
|
* @param {string} [parameters.versionId] - Version identifier for the quiz
|
|
115
113
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
116
114
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
117
115
|
* @returns {Promise}
|
|
118
116
|
* @see https://docs.constructor.io/rest_api/quiz/using_quizzes/#answering-a-quiz
|
|
119
117
|
* @example
|
|
120
|
-
* constructorio.quizzes.
|
|
121
|
-
*
|
|
118
|
+
* constructorio.quizzes.getQuizNextQuestion('quizId', {
|
|
119
|
+
* answers: [[1,2],[1]],
|
|
122
120
|
* section: '123',
|
|
123
121
|
* versionId: '123'
|
|
124
122
|
* });
|
|
@@ -126,8 +124,8 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
126
124
|
|
|
127
125
|
|
|
128
126
|
(0, _createClass2["default"])(Quizzes, [{
|
|
129
|
-
key: "
|
|
130
|
-
value: function
|
|
127
|
+
key: "getQuizNextQuestion",
|
|
128
|
+
value: function getQuizNextQuestion(quizId, parameters) {
|
|
131
129
|
var _this = this;
|
|
132
130
|
|
|
133
131
|
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -156,12 +154,12 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
156
154
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
157
155
|
}).then(function (json) {
|
|
158
156
|
if (json.version_id) {
|
|
159
|
-
_this.eventDispatcher.queue('quizzes.
|
|
157
|
+
_this.eventDispatcher.queue('quizzes.getQuizNextQuestion.completed', json);
|
|
160
158
|
|
|
161
159
|
return json;
|
|
162
160
|
}
|
|
163
161
|
|
|
164
|
-
throw new Error('
|
|
162
|
+
throw new Error('getQuizNextQuestion response data is malformed');
|
|
165
163
|
});
|
|
166
164
|
}
|
|
167
165
|
/**
|
|
@@ -172,7 +170,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
172
170
|
* @param {string} id - The identifier of the quiz
|
|
173
171
|
* @param {string} [parameters] - Additional parameters to refine result set
|
|
174
172
|
* @param {string} [parameters.section] - Product catalog section
|
|
175
|
-
* @param {array} [parameters.
|
|
173
|
+
* @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]]
|
|
176
174
|
* @param {string} [parameters.versionId] - Specific version identifier for the quiz
|
|
177
175
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
178
176
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -180,7 +178,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
180
178
|
* @see https://docs.constructor.io/rest_api/quiz/using_quizzes/#completing-the-quiz
|
|
181
179
|
* @example
|
|
182
180
|
* constructorio.quizzes.getQuizResults('quizId', {
|
|
183
|
-
*
|
|
181
|
+
* answers: [[1,2],[1]],
|
|
184
182
|
* section: '123',
|
|
185
183
|
* versionId: '123'
|
|
186
184
|
* });
|
|
@@ -6,13 +6,10 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
6
6
|
|
|
7
7
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
8
|
|
|
9
|
-
/* eslint-disable object-curly-newline, no-param-reassign */
|
|
10
9
|
var qs = require('qs');
|
|
11
10
|
|
|
12
11
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
13
12
|
|
|
14
|
-
var Promise = require('es6-promise');
|
|
15
|
-
|
|
16
13
|
var EventDispatcher = require('../utils/event-dispatcher');
|
|
17
14
|
|
|
18
15
|
var helpers = require('../utils/helpers'); // Create URL from supplied parameters
|
|
@@ -152,8 +149,6 @@ var Recommendations = /*#__PURE__*/function () {
|
|
|
152
149
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
153
150
|
}
|
|
154
151
|
|
|
155
|
-
parameters = parameters || {};
|
|
156
|
-
|
|
157
152
|
try {
|
|
158
153
|
requestUrl = createRecommendationsUrl(podId, parameters, this.options);
|
|
159
154
|
} catch (e) {
|
|
@@ -173,6 +168,7 @@ var Recommendations = /*#__PURE__*/function () {
|
|
|
173
168
|
if (json.result_id) {
|
|
174
169
|
// Append `result_id` to each result item
|
|
175
170
|
json.response.results.forEach(function (result) {
|
|
171
|
+
// eslint-disable-next-line no-param-reassign
|
|
176
172
|
result.result_id = json.result_id;
|
|
177
173
|
});
|
|
178
174
|
}
|
package/lib/modules/search.js
CHANGED
|
@@ -15,8 +15,6 @@ var qs = require('qs');
|
|
|
15
15
|
|
|
16
16
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
17
17
|
|
|
18
|
-
var Promise = require('es6-promise');
|
|
19
|
-
|
|
20
18
|
var EventDispatcher = require('../utils/event-dispatcher');
|
|
21
19
|
|
|
22
20
|
var helpers = require('../utils/helpers'); // Create URL from supplied query (term) and parameters
|
|
@@ -244,6 +242,7 @@ var Search = /*#__PURE__*/function () {
|
|
|
244
242
|
// Search results
|
|
245
243
|
if (json.response && json.response.results) {
|
|
246
244
|
if (json.result_id) {
|
|
245
|
+
// Append `result_id` to each result item
|
|
247
246
|
json.response.results.forEach(function (result) {
|
|
248
247
|
// eslint-disable-next-line no-param-reassign
|
|
249
248
|
result.result_id = json.result_id;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConstructorClientOptions,
|
|
3
|
+
RequestFeature,
|
|
4
|
+
RequestFeatureVariant,
|
|
5
|
+
} from "./types";
|
|
6
|
+
import EventDispatcher from "./event-dispatcher";
|
|
7
|
+
|
|
8
|
+
/***************
|
|
9
|
+
*
|
|
10
|
+
* Autocomplete
|
|
11
|
+
*
|
|
12
|
+
***************/
|
|
13
|
+
export = Autocomplete;
|
|
14
|
+
|
|
15
|
+
interface IAutocompleteParameters {
|
|
16
|
+
numResults: number;
|
|
17
|
+
filters: Record<string, any>;
|
|
18
|
+
resultsPerSection: Record<string, number>;
|
|
19
|
+
hiddenFields: string[];
|
|
20
|
+
variationsMap: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare class Autocomplete {
|
|
24
|
+
constructor(options: ConstructorClientOptions);
|
|
25
|
+
options: ConstructorClientOptions;
|
|
26
|
+
eventDispatcher: EventDispatcher;
|
|
27
|
+
|
|
28
|
+
getAutocompleteResults(
|
|
29
|
+
query: string,
|
|
30
|
+
parameters?: IAutocompleteParameters,
|
|
31
|
+
networkParameters?: {
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
): Promise<Autocomplete.AutocompleteResponse>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/***********
|
|
38
|
+
*
|
|
39
|
+
* Autocomplete results returned from server
|
|
40
|
+
*
|
|
41
|
+
***********/
|
|
42
|
+
declare namespace Autocomplete {
|
|
43
|
+
export interface AutocompleteResponse extends Record<string, any> {
|
|
44
|
+
request: Partial<Request>;
|
|
45
|
+
sections: Record<string, Section>;
|
|
46
|
+
result_id: string;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface Request extends Record<string, any> {
|
|
51
|
+
num_results: number;
|
|
52
|
+
term: string;
|
|
53
|
+
query: string;
|
|
54
|
+
features: Partial<RequestFeature>;
|
|
55
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
56
|
+
searchandized_items: Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type Section = Partial<SectionItem>[]
|
|
60
|
+
|
|
61
|
+
interface SectionItem extends Record<string, any> {
|
|
62
|
+
data: Record<string, any>;
|
|
63
|
+
is_slotted: boolean;
|
|
64
|
+
labels: Record<string, any>;
|
|
65
|
+
matched_terms: string[];
|
|
66
|
+
value: string;
|
|
67
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Collection, ConstructorClientOptions, ErrorData, Facet, Feature, Group, RequestFeature, RequestFeatureVariant, ResultSources, SortOption } from "./types";
|
|
2
|
+
import EventDispatcher from "./event-dispatcher";
|
|
3
|
+
|
|
4
|
+
/*********
|
|
5
|
+
*
|
|
6
|
+
* Browse
|
|
7
|
+
*
|
|
8
|
+
*********/
|
|
9
|
+
export = Browse;
|
|
10
|
+
|
|
11
|
+
interface IBrowseParameters {
|
|
12
|
+
page?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
resultsPerPage?: number;
|
|
15
|
+
filters?: Record<string, any>;
|
|
16
|
+
sortBy?: string;
|
|
17
|
+
sortOrder?: string;
|
|
18
|
+
section?: string;
|
|
19
|
+
fmtOptions?: object;
|
|
20
|
+
preFilterExpression: Record<string, any>;
|
|
21
|
+
hiddenFields?: string[];
|
|
22
|
+
hiddenFacets?: string[];
|
|
23
|
+
variationsMap?: Record<string, any>;
|
|
24
|
+
qs?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare class Browse {
|
|
28
|
+
constructor(options: ConstructorClientOptions);
|
|
29
|
+
options: ConstructorClientOptions;
|
|
30
|
+
eventDispatcher: EventDispatcher;
|
|
31
|
+
|
|
32
|
+
getBrowseResults(
|
|
33
|
+
filterName: string,
|
|
34
|
+
filterValue: string,
|
|
35
|
+
parameters?: IBrowseParameters,
|
|
36
|
+
networkParameters?: {
|
|
37
|
+
timeout?: number;
|
|
38
|
+
}
|
|
39
|
+
): Promise<Browse.GetBrowseResultsResponse>;
|
|
40
|
+
|
|
41
|
+
getBrowseResultsForItemIds(
|
|
42
|
+
itemIds: string[],
|
|
43
|
+
parameters?: Omit<IBrowseParameters, "preFilterExpression" | "preFilterExpression">,
|
|
44
|
+
networkParameters?: {
|
|
45
|
+
timeout?: number;
|
|
46
|
+
}
|
|
47
|
+
): Promise<Browse.GetBrowseResultsForItemIdsResponse>;
|
|
48
|
+
|
|
49
|
+
getBrowseGroups(
|
|
50
|
+
parameters: Pick<IBrowseParameters, "filters" | "section" | "fmtOptions">,
|
|
51
|
+
networkParameters?: {
|
|
52
|
+
timeout?: number;
|
|
53
|
+
}
|
|
54
|
+
): Promise<Browse.GetBrowseGroupsResponse>;
|
|
55
|
+
|
|
56
|
+
getBrowseFacets(
|
|
57
|
+
parameters?: Pick<IBrowseParameters, "page" | "offset" | "section" | "fmtOptions"| "resultsPerPage">,
|
|
58
|
+
networkParameters?: {
|
|
59
|
+
timeout?: number;
|
|
60
|
+
}
|
|
61
|
+
): Promise<Browse.GetBrowseFacetsResponse>;
|
|
62
|
+
|
|
63
|
+
getBrowseFacetOptions(
|
|
64
|
+
facetName: string,
|
|
65
|
+
parameters?: Pick<IBrowseParameters, "section" | "fmtOptions">,
|
|
66
|
+
networkParameters?: {
|
|
67
|
+
timeout?: number;
|
|
68
|
+
}
|
|
69
|
+
): Promise<Browse.GetBrowseFacetOptionsResponse>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/***********
|
|
73
|
+
*
|
|
74
|
+
* Browse results returned from server
|
|
75
|
+
*
|
|
76
|
+
***********/
|
|
77
|
+
declare namespace Browse {
|
|
78
|
+
export type GetBrowseResultsResponse = BrowseResponse<GetBrowseResultsResponseData>;
|
|
79
|
+
export type GetBrowseResultsForItemIdsResponse = BrowseResponse<GetBrowseResultsResponseData>;
|
|
80
|
+
export type GetBrowseGroupsResponse = BrowseResponse<Pick<GetBrowseResultsResponseData, "result_sources" | "groups" | "refined_content">>;
|
|
81
|
+
export type GetBrowseFacetsResponse = BrowseResponse<Pick<GetBrowseResultsResponseData, "facets" | "total_num_results">>;
|
|
82
|
+
export type GetBrowseFacetOptionsResponse = BrowseResponse<Pick<GetBrowseResultsResponseData, "facets">>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface BrowseResponse<ResponseType> extends Record<string, any> {
|
|
86
|
+
request?: Partial<Request>;
|
|
87
|
+
response?: Partial<ResponseType>;
|
|
88
|
+
result_id?: string;
|
|
89
|
+
ad_based?: boolean;
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface GetBrowseResultsResponseData extends Record<string, any> {
|
|
94
|
+
result_sources: Partial<ResultSources>;
|
|
95
|
+
facets: Partial<Facet>[];
|
|
96
|
+
groups: Partial<Group>[];
|
|
97
|
+
results: Partial<BrowseResultData>[];
|
|
98
|
+
sort_options: Partial<SortOption>[];
|
|
99
|
+
refined_content: Record<string, any>[];
|
|
100
|
+
total_num_results: number;
|
|
101
|
+
features: Partial<Feature>[];
|
|
102
|
+
collection: Partial<Collection>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface BrowseResultData extends Record<string, any> {
|
|
106
|
+
matched_terms: string[];
|
|
107
|
+
data: {
|
|
108
|
+
id: string;
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
};
|
|
111
|
+
value: string;
|
|
112
|
+
is_slotted: false;
|
|
113
|
+
labels: Record<string, any>;
|
|
114
|
+
variations: Record<string, any>[];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface Request extends Record<string, any> {
|
|
118
|
+
browse_filter_name: string;
|
|
119
|
+
browse_filter_value: string;
|
|
120
|
+
filter_match_types: Record<string, any>,
|
|
121
|
+
filters: Record<string, any>,
|
|
122
|
+
fmt_options: Record<string, any>,
|
|
123
|
+
num_results_per_page: number;
|
|
124
|
+
page: number,
|
|
125
|
+
section: string,
|
|
126
|
+
sort_by: string,
|
|
127
|
+
sort_order: string,
|
|
128
|
+
term: string;
|
|
129
|
+
query: string;
|
|
130
|
+
features: Partial<RequestFeature>;
|
|
131
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
132
|
+
searchandized_items: Record<string, any>;
|
|
133
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Search from "./search";
|
|
2
|
+
import Browse from "./browse";
|
|
3
|
+
import Autocomplete from "./autocomplete";
|
|
4
|
+
import Recommendations from "./recommendations";
|
|
5
|
+
import Tracker from "./tracker";
|
|
6
|
+
import { ConstructorClientOptions } from "./types";
|
|
7
|
+
|
|
8
|
+
export = ConstructorIO;
|
|
9
|
+
|
|
10
|
+
/*********************
|
|
11
|
+
*
|
|
12
|
+
* Constructor client
|
|
13
|
+
*
|
|
14
|
+
*********************/
|
|
15
|
+
declare class ConstructorIO {
|
|
16
|
+
constructor(options: ConstructorClientOptions);
|
|
17
|
+
private options: ConstructorClientOptions;
|
|
18
|
+
search: Search;
|
|
19
|
+
browse: Browse;
|
|
20
|
+
autocomplete: Autocomplete;
|
|
21
|
+
recommendations: Recommendations;
|
|
22
|
+
tracker: Tracker;
|
|
23
|
+
|
|
24
|
+
setClientOptions(options: ConstructorClientOptions): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare namespace ConstructorIO {
|
|
28
|
+
export { Tracker }
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConstructorClientOptions } from "./types";
|
|
2
|
+
|
|
3
|
+
export = EventDispatcher;
|
|
4
|
+
|
|
5
|
+
declare class EventDispatcher {
|
|
6
|
+
constructor(options: ConstructorClientOptions);
|
|
7
|
+
events: { name: string; data: Record<string, any> }[];
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
waitForBeacon: boolean;
|
|
10
|
+
active: boolean;
|
|
11
|
+
queue(name: string, data: Record<string, any>): void;
|
|
12
|
+
dispatchEvents(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ConstructorClientOptions, ErrorData } from "./types";
|
|
2
|
+
import EventDispatcher from "./event-dispatcher";
|
|
3
|
+
|
|
4
|
+
/******************
|
|
5
|
+
*
|
|
6
|
+
* Recommendations
|
|
7
|
+
*
|
|
8
|
+
*****************/
|
|
9
|
+
export = Recommendations;
|
|
10
|
+
|
|
11
|
+
interface RecommendationsParameters {
|
|
12
|
+
itemIds?: string | string[];
|
|
13
|
+
numResults?: number;
|
|
14
|
+
section?: string;
|
|
15
|
+
term?: string;
|
|
16
|
+
filters?: Record<string, any>;
|
|
17
|
+
variationsMap?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class Recommendations {
|
|
21
|
+
constructor(options: ConstructorClientOptions);
|
|
22
|
+
options: ConstructorClientOptions;
|
|
23
|
+
eventDispatcher: EventDispatcher;
|
|
24
|
+
|
|
25
|
+
getRecommendations(
|
|
26
|
+
podId: string,
|
|
27
|
+
parameters?: RecommendationsParameters,
|
|
28
|
+
networkParameters?: {
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
): Promise<Recommendations.RecommendationsResponse>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/***********
|
|
35
|
+
*
|
|
36
|
+
* Recommendations results returned from server
|
|
37
|
+
*
|
|
38
|
+
***********/
|
|
39
|
+
declare namespace Recommendations {
|
|
40
|
+
export interface RecommendationsResponse extends Record<string, any> {
|
|
41
|
+
request: Partial<Request>;
|
|
42
|
+
response: Partial<Response>;
|
|
43
|
+
result_id: string;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Request extends Record<string, any> {
|
|
48
|
+
num_results: number;
|
|
49
|
+
item_id: string;
|
|
50
|
+
filters: {
|
|
51
|
+
group_id: string;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
pod_id: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface Response extends Record<string, any> {
|
|
58
|
+
results: Partial<Result>;
|
|
59
|
+
total_num_results: number;
|
|
60
|
+
pod: {
|
|
61
|
+
id:string;
|
|
62
|
+
display_name: string;
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface Result extends Record<string, any> {
|
|
68
|
+
matched_terms: string[];
|
|
69
|
+
data: Record<string, any>;
|
|
70
|
+
value: string;
|
|
71
|
+
is_slotted: boolean;
|
|
72
|
+
labels: Record<string, any>;
|
|
73
|
+
strategy: {
|
|
74
|
+
id: string;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConstructorClientOptions,
|
|
3
|
+
ErrorData,
|
|
4
|
+
Facet,
|
|
5
|
+
Feature,
|
|
6
|
+
FmtOption,
|
|
7
|
+
Group,
|
|
8
|
+
RequestFeature,
|
|
9
|
+
RequestFeatureVariant,
|
|
10
|
+
ResultSources,
|
|
11
|
+
SortOption,
|
|
12
|
+
} from "./types";
|
|
13
|
+
import EventDispatcher from "./event-dispatcher";
|
|
14
|
+
|
|
15
|
+
/***********
|
|
16
|
+
*
|
|
17
|
+
* SEARCH
|
|
18
|
+
*
|
|
19
|
+
***********/
|
|
20
|
+
|
|
21
|
+
export = Search;
|
|
22
|
+
|
|
23
|
+
interface SearchParameters {
|
|
24
|
+
page?: number;
|
|
25
|
+
resultsPerPage?: number;
|
|
26
|
+
filters?: Record<string, any>;
|
|
27
|
+
sortBy?: string;
|
|
28
|
+
sortOrder?: string;
|
|
29
|
+
section?: string;
|
|
30
|
+
fmtOptions?: Record<string, any>;
|
|
31
|
+
hiddenFields?: string[];
|
|
32
|
+
hiddenFacets?: string[];
|
|
33
|
+
variationsMap?: Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
declare class Search {
|
|
36
|
+
constructor(options: ConstructorClientOptions);
|
|
37
|
+
options: ConstructorClientOptions;
|
|
38
|
+
eventDispatcher: EventDispatcher;
|
|
39
|
+
getSearchResults(
|
|
40
|
+
query: string,
|
|
41
|
+
parameters?: SearchParameters,
|
|
42
|
+
networkParameters?: {
|
|
43
|
+
timeout?: number;
|
|
44
|
+
}
|
|
45
|
+
): Promise<Search.SearchResponse>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/***********
|
|
49
|
+
*
|
|
50
|
+
* search results returned from server
|
|
51
|
+
*
|
|
52
|
+
***********/
|
|
53
|
+
interface Response extends Record<string, any> {
|
|
54
|
+
result_sources: Partial<ResultSources>;
|
|
55
|
+
facets: Partial<Facet>[];
|
|
56
|
+
groups: Partial<Group>[];
|
|
57
|
+
results: Partial<Result>[];
|
|
58
|
+
sort_options: Partial<SortOption>[];
|
|
59
|
+
refined_content: Record<string, any>[];
|
|
60
|
+
total_num_results: number;
|
|
61
|
+
features: Partial<Feature>[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface Request extends Record<string, any> {
|
|
65
|
+
page: number;
|
|
66
|
+
num_results_per_page: number;
|
|
67
|
+
section: string;
|
|
68
|
+
blacklist_rules: boolean;
|
|
69
|
+
term: string;
|
|
70
|
+
fmt_options: Partial<FmtOption>;
|
|
71
|
+
sort_by: string;
|
|
72
|
+
sort_order: string;
|
|
73
|
+
features: Partial<RequestFeature>;
|
|
74
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
75
|
+
searchandized_items: Record<string, any>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface Result extends Record<string, any> {
|
|
79
|
+
matched_terms: string[];
|
|
80
|
+
data: {
|
|
81
|
+
id: string;
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
};
|
|
84
|
+
value: string;
|
|
85
|
+
is_slotted: false;
|
|
86
|
+
labels: Record<string, any>;
|
|
87
|
+
variations: Record<string, any>[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare namespace Search {
|
|
91
|
+
export interface SearchResponse {
|
|
92
|
+
request: Partial<Request>;
|
|
93
|
+
response: Partial<Response | Redirect>;
|
|
94
|
+
result_id: string;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface Redirect extends Record<string, any> {
|
|
99
|
+
redirect: {
|
|
100
|
+
data: {
|
|
101
|
+
match_id: number;
|
|
102
|
+
rule_id: number;
|
|
103
|
+
url: string;
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
};
|
|
106
|
+
matched_terms: string[];
|
|
107
|
+
matched_user_segments: string[];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { ConstructorClientOptions } from "./types";
|
|
2
|
+
import EventEmitter = require("events");
|
|
3
|
+
import RequestQueue = require("../utils/request-queue");
|
|
4
|
+
|
|
5
|
+
export = Tracker;
|
|
6
|
+
|
|
7
|
+
/******************
|
|
8
|
+
*
|
|
9
|
+
* Tracker
|
|
10
|
+
*
|
|
11
|
+
*****************/
|
|
12
|
+
declare class Tracker {
|
|
13
|
+
constructor(options: ConstructorClientOptions);
|
|
14
|
+
private options: ConstructorClientOptions;
|
|
15
|
+
private eventemitter: EventEmitter;
|
|
16
|
+
private requests: RequestQueue;
|
|
17
|
+
|
|
18
|
+
trackSessionStart(networkParameters?: {
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}): (true | Error);
|
|
21
|
+
|
|
22
|
+
trackInputFocus(networkParameters?: {
|
|
23
|
+
timeout?: number;
|
|
24
|
+
}): (true | Error);
|
|
25
|
+
|
|
26
|
+
trackItemDetailLoad(parameters: {
|
|
27
|
+
item_name: string;
|
|
28
|
+
item_id: string;
|
|
29
|
+
variation_id?: string;
|
|
30
|
+
}, networkParameters?: {
|
|
31
|
+
timeout?: number;
|
|
32
|
+
}): (true | Error);
|
|
33
|
+
|
|
34
|
+
trackAutocompleteSelect(term: string, parameters: {
|
|
35
|
+
original_query: string;
|
|
36
|
+
section: string;
|
|
37
|
+
tr?: string;
|
|
38
|
+
group_id?: string;
|
|
39
|
+
display_name?: string;
|
|
40
|
+
}, networkParameters?: {
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}): (true | Error);
|
|
43
|
+
|
|
44
|
+
trackSearchSubmit(term: string, parameters: {
|
|
45
|
+
original_query: string;
|
|
46
|
+
group_id?: string;
|
|
47
|
+
display_name?: string;
|
|
48
|
+
}, networkParameters?: {
|
|
49
|
+
timeout?: number;
|
|
50
|
+
}): (true | Error);
|
|
51
|
+
|
|
52
|
+
trackSearchResultsLoaded(term: string, parameters: {
|
|
53
|
+
num_results: number;
|
|
54
|
+
item_ids?: string[];
|
|
55
|
+
}, networkParameters?: {
|
|
56
|
+
timeout?: number;
|
|
57
|
+
}): (true | Error);
|
|
58
|
+
|
|
59
|
+
trackSearchResultClick(term: string, parameters: {
|
|
60
|
+
item_name: string;
|
|
61
|
+
item_id: string;
|
|
62
|
+
variation_id?: string;
|
|
63
|
+
result_id?: string;
|
|
64
|
+
item_is_convertible?: string;
|
|
65
|
+
}, networkParameters?: {
|
|
66
|
+
timeout?: number;
|
|
67
|
+
}): (true | Error);
|
|
68
|
+
|
|
69
|
+
trackConversion(term?: string, parameters: {
|
|
70
|
+
item_id: string;
|
|
71
|
+
revenue?: number;
|
|
72
|
+
item_name?: string;
|
|
73
|
+
variation_id?: string;
|
|
74
|
+
type?: string;
|
|
75
|
+
is_custom_type?: boolean;
|
|
76
|
+
display_name?: string;
|
|
77
|
+
result_id?: string;
|
|
78
|
+
section?: string;
|
|
79
|
+
}, networkParameters?: {
|
|
80
|
+
timeout?: number;
|
|
81
|
+
}): (true | Error);
|
|
82
|
+
|
|
83
|
+
trackPurchase(parameters: {
|
|
84
|
+
items: object[];
|
|
85
|
+
revenue: number;
|
|
86
|
+
order_id?: string;
|
|
87
|
+
section?: string;
|
|
88
|
+
}, networkParameters?: {
|
|
89
|
+
timeout?: number;
|
|
90
|
+
}): (true | Error);
|
|
91
|
+
|
|
92
|
+
trackRecommendationView(parameters: {
|
|
93
|
+
url: string;
|
|
94
|
+
pod_id: string;
|
|
95
|
+
num_results_viewed: number;
|
|
96
|
+
items?: object[];
|
|
97
|
+
result_count?: number;
|
|
98
|
+
result_page?: number;
|
|
99
|
+
result_id?: string;
|
|
100
|
+
section?: string;
|
|
101
|
+
}, networkParameters?: {
|
|
102
|
+
timeout?: number;
|
|
103
|
+
}): (true | Error);
|
|
104
|
+
|
|
105
|
+
trackRecommendationClick(parameters: {
|
|
106
|
+
pod_id: string;
|
|
107
|
+
strategy_id: string;
|
|
108
|
+
item_id: string;
|
|
109
|
+
variation_id?: string;
|
|
110
|
+
section?: string;
|
|
111
|
+
result_id?: string;
|
|
112
|
+
result_count?: number;
|
|
113
|
+
result_page?: number;
|
|
114
|
+
result_position_on_page?: number;
|
|
115
|
+
num_results_per_page?: number;
|
|
116
|
+
}, networkParameters?: {
|
|
117
|
+
timeout?: number;
|
|
118
|
+
}): (true | Error);
|
|
119
|
+
|
|
120
|
+
trackBrowseResultsLoaded(parameters: {
|
|
121
|
+
url: string;
|
|
122
|
+
filter_name: string;
|
|
123
|
+
filter_value: string;
|
|
124
|
+
section?: string;
|
|
125
|
+
result_count?: number;
|
|
126
|
+
result_page?: number;
|
|
127
|
+
result_id?: string;
|
|
128
|
+
selected_filters?: object;
|
|
129
|
+
sort_order?: string;
|
|
130
|
+
sort_by?: string;
|
|
131
|
+
items?: object[];
|
|
132
|
+
}, networkParameters?: {
|
|
133
|
+
timeout?: number;
|
|
134
|
+
}): (true | Error);
|
|
135
|
+
|
|
136
|
+
trackBrowseResultClick(parameters: {
|
|
137
|
+
filter_name: string;
|
|
138
|
+
filter_value: string;
|
|
139
|
+
item_id: string;
|
|
140
|
+
section?: string;
|
|
141
|
+
variation_id?: string;
|
|
142
|
+
result_id?: string;
|
|
143
|
+
result_count?: number;
|
|
144
|
+
result_page?: number;
|
|
145
|
+
result_position_on_page?: number;
|
|
146
|
+
num_results_per_page?: number;
|
|
147
|
+
selected_filters?: object;
|
|
148
|
+
}, networkParameters?: {
|
|
149
|
+
timeout?: number;
|
|
150
|
+
}): (true | Error);
|
|
151
|
+
|
|
152
|
+
trackGenericResultClick(parameters: {
|
|
153
|
+
item_id: string;
|
|
154
|
+
item_name?: string;
|
|
155
|
+
variation_id?: string;
|
|
156
|
+
section?: string;
|
|
157
|
+
}, networkParameters?: {
|
|
158
|
+
timeout?: number;
|
|
159
|
+
}): (true | Error);
|
|
160
|
+
|
|
161
|
+
on(messageType: string, callback: Function): (true | Error);
|
|
162
|
+
}
|
|
@@ -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
|
+
|
package/lib/utils/helpers.js
CHANGED
|
@@ -143,7 +143,7 @@ var utils = {
|
|
|
143
143
|
var controller = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
144
144
|
var optionsTimeout = options && options.networkParameters && options.networkParameters.timeout;
|
|
145
145
|
var networkParametersTimeout = networkParameters && networkParameters.timeout;
|
|
146
|
-
var timeout =
|
|
146
|
+
var timeout = networkParametersTimeout || optionsTimeout;
|
|
147
147
|
|
|
148
148
|
if (typeof timeout === 'number' && controller) {
|
|
149
149
|
setTimeout(function () {
|
|
@@ -9,8 +9,6 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
9
9
|
/* eslint-disable brace-style, no-unneeded-ternary */
|
|
10
10
|
var fetchPonyfill = require('fetch-ponyfill');
|
|
11
11
|
|
|
12
|
-
var Promise = require('es6-promise');
|
|
13
|
-
|
|
14
12
|
var store = require('./store');
|
|
15
13
|
|
|
16
14
|
var HumanityCheck = require('./humanity-check');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-client-javascript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
4
4
|
"description": "Constructor.io JavaScript client",
|
|
5
5
|
"main": "lib/constructorio.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,12 +9,16 @@
|
|
|
9
9
|
"check-lisc": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT'",
|
|
10
10
|
"lint": "eslint 'src/**/*.js' 'spec/**/*.js'",
|
|
11
11
|
"test": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha ./spec/*",
|
|
12
|
+
"test:parallel": "npm run compile && mkdir -p test && cp -rf lib/* test && mocha --parallel ./spec/*",
|
|
12
13
|
"test:src": "mkdir -p test && cp -rf src/* test && mocha ./spec/*",
|
|
14
|
+
"test:src:parallel": "mkdir -p test && cp -rf src/* test && mocha --parallel ./spec/*",
|
|
13
15
|
"test:bundled": "npm run bundle && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha ./spec/*",
|
|
16
|
+
"test:bundled:parallel": "npm run bundle && BUNDLED=true PACKAGE_VERSION=$(echo $npm_package_version) mocha --parallel ./spec/*",
|
|
14
17
|
"test:all": "npm run test && npm run test:bundled",
|
|
18
|
+
"test:all:parallel": "npm run test:parallel && npm run test:bundled:parallel",
|
|
15
19
|
"precoverage": "rm -rf ./coverage && rm -rf ./.nyc_output",
|
|
16
20
|
"coverage": "nyc --all --reporter=html npm run test:src",
|
|
17
|
-
"postcoverage": "
|
|
21
|
+
"postcoverage": "open coverage/index.html && rm -rf test",
|
|
18
22
|
"docs": "jsdoc --configure ./.jsdoc.json ./README.md --recurse ./src --destination ./docs",
|
|
19
23
|
"compile": "babel src/ -d lib/",
|
|
20
24
|
"prepublish": "npm run compile",
|
|
@@ -56,17 +60,15 @@
|
|
|
56
60
|
"minami": "^1.2.3",
|
|
57
61
|
"mocha": "^9.1.3",
|
|
58
62
|
"nyc": "^15.1.0",
|
|
59
|
-
"serve": "^13.0.2",
|
|
60
63
|
"sinon": "^7.5.0",
|
|
61
64
|
"sinon-chai": "^3.7.0"
|
|
62
65
|
},
|
|
63
66
|
"dependencies": {
|
|
64
67
|
"@constructor-io/constructorio-id": "^2.4.10",
|
|
65
68
|
"crc-32": "^1.2.2",
|
|
66
|
-
"es6-promise": "^4.2.8",
|
|
67
69
|
"events": "^3.0.0",
|
|
68
70
|
"fetch-ponyfill": "^7.1.0",
|
|
69
|
-
"qs": "6.
|
|
71
|
+
"qs": "6.9.7",
|
|
70
72
|
"store2": "^2.14.2"
|
|
71
73
|
},
|
|
72
74
|
"peerDependencies": {
|