@constructor-io/constructorio-node 4.2.1 → 4.3.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/package.json +12 -4
- package/src/.DS_Store +0 -0
- package/src/constructorio.js +2 -1
- package/src/modules/autocomplete.js +1 -2
- package/src/modules/browse.js +5 -6
- package/src/modules/catalog.js +62 -64
- package/src/modules/quizzes.js +7 -7
- package/src/modules/recommendations.js +2 -3
- package/src/modules/search.js +1 -2
- package/src/modules/tasks.js +2 -3
- package/src/modules/tracker.js +49 -13
- package/src/types/autocomplete.d.ts +56 -0
- package/src/types/browse.d.ts +140 -0
- package/src/types/catalog.d.ts +535 -0
- package/src/types/constructorio.d.ts +34 -0
- package/src/types/index.d.ts +277 -0
- package/src/types/quizzes.d.ts +73 -0
- package/src/types/recommendations.d.ts +64 -0
- package/src/types/search.d.ts +98 -0
- package/src/types/tasks.d.ts +70 -0
- package/src/types/tests/autocomplete.test-d.ts +59 -0
- package/src/types/tests/browse.test-d.ts +120 -0
- package/src/types/tests/catalog.test-d.ts +109 -0
- package/src/types/tests/quizzes.test-d.ts +82 -0
- package/src/types/tests/recommedations.test-d.ts +45 -0
- package/src/types/tests/search.test-d.ts +124 -0
- package/src/types/tests/tasks.test-d.ts +40 -0
- package/src/types/tracker.d.ts +203 -0
package/src/modules/tasks.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable object-curly-newline, no-underscore-dangle, max-len */
|
|
2
2
|
const qs = require('qs');
|
|
3
|
-
const nodeFetch = require('node-fetch').default;
|
|
4
3
|
const { AbortController } = require('node-abort-controller');
|
|
5
4
|
const helpers = require('../utils/helpers');
|
|
6
5
|
|
|
@@ -58,7 +57,7 @@ class Tasks {
|
|
|
58
57
|
getAllTasks(parameters = {}, networkParameters = {}) {
|
|
59
58
|
const queryParams = {};
|
|
60
59
|
let requestUrl;
|
|
61
|
-
const fetch =
|
|
60
|
+
const { fetch } = this.options;
|
|
62
61
|
const controller = new AbortController();
|
|
63
62
|
const { signal } = controller;
|
|
64
63
|
const headers = {
|
|
@@ -134,7 +133,7 @@ class Tasks {
|
|
|
134
133
|
*/
|
|
135
134
|
getTask(parameters = {}, networkParameters = {}) {
|
|
136
135
|
let requestUrl;
|
|
137
|
-
const fetch =
|
|
136
|
+
const { fetch } = this.options;
|
|
138
137
|
const controller = new AbortController();
|
|
139
138
|
const { signal } = controller;
|
|
140
139
|
const headers = {
|
package/src/modules/tracker.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* eslint-disable camelcase, no-underscore-dangle, no-unneeded-ternary, brace-style */
|
|
2
2
|
const qs = require('qs');
|
|
3
|
-
const nodeFetch = require('node-fetch').default;
|
|
4
3
|
const { AbortController } = require('node-abort-controller');
|
|
5
4
|
const EventEmitter = require('events');
|
|
6
5
|
const helpers = require('../utils/helpers');
|
|
@@ -79,7 +78,7 @@ function applyParamsAsString(parameters, userParameters, options) {
|
|
|
79
78
|
// Send request to server
|
|
80
79
|
function send(url, userParameters, networkParameters, method = 'GET', body = {}) { // eslint-disable-line max-params
|
|
81
80
|
let request;
|
|
82
|
-
const fetch =
|
|
81
|
+
const { fetch } = this.options;
|
|
83
82
|
const controller = new AbortController();
|
|
84
83
|
const { signal } = controller;
|
|
85
84
|
const headers = {};
|
|
@@ -273,6 +272,7 @@ class Tracker {
|
|
|
273
272
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
274
273
|
* @param {string} parameters.item_name - Product item name
|
|
275
274
|
* @param {string} parameters.item_id - Product item unique identifier
|
|
275
|
+
* @param {string} parameters.url - Current page URL
|
|
276
276
|
* @param {string} [parameters.variation_id] - Product item variation unique identifier
|
|
277
277
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
278
278
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -294,41 +294,57 @@ class Tracker {
|
|
|
294
294
|
* {
|
|
295
295
|
* item_name: 'Red T-Shirt',
|
|
296
296
|
* item_id: 'KMH876',
|
|
297
|
+
* url: 'https://constructor.io/product/KMH876',
|
|
297
298
|
* },
|
|
298
299
|
* );
|
|
299
300
|
*/
|
|
300
301
|
trackItemDetailLoad(parameters, userParameters, networkParameters = {}) {
|
|
301
302
|
// Ensure parameters are provided (required)
|
|
302
303
|
if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
const {
|
|
304
|
+
const requestPath = `${this.options.serviceUrl}/v2/behavioral_action/item_detail_load?`;
|
|
305
|
+
const bodyParams = {};
|
|
306
|
+
const {
|
|
307
|
+
item_name,
|
|
308
|
+
name,
|
|
309
|
+
item_id,
|
|
310
|
+
customer_id,
|
|
311
|
+
variation_id,
|
|
312
|
+
url,
|
|
313
|
+
} = parameters;
|
|
306
314
|
|
|
307
315
|
// Ensure support for both item_name and name as parameters
|
|
308
316
|
if (item_name) {
|
|
309
|
-
|
|
317
|
+
bodyParams.item_name = item_name;
|
|
310
318
|
} else if (name) {
|
|
311
|
-
|
|
319
|
+
bodyParams.item_name = name;
|
|
312
320
|
}
|
|
313
321
|
|
|
314
322
|
// Ensure support for both item_id and customer_id as parameters
|
|
315
323
|
if (item_id) {
|
|
316
|
-
|
|
324
|
+
bodyParams.item_id = item_id;
|
|
317
325
|
} else if (customer_id) {
|
|
318
|
-
|
|
326
|
+
bodyParams.item_id = customer_id;
|
|
319
327
|
}
|
|
320
328
|
|
|
321
329
|
if (variation_id) {
|
|
322
|
-
|
|
330
|
+
bodyParams.variation_id = variation_id;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (url) {
|
|
334
|
+
bodyParams.url = url;
|
|
323
335
|
}
|
|
324
336
|
|
|
325
|
-
const requestUrl = `${
|
|
337
|
+
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
338
|
+
const requestMethod = 'POST';
|
|
339
|
+
const requestBody = applyParams(bodyParams, userParameters, { ...this.options, requestMethod });
|
|
326
340
|
|
|
327
341
|
send.call(
|
|
328
342
|
this,
|
|
329
343
|
requestUrl,
|
|
330
344
|
userParameters,
|
|
331
345
|
networkParameters,
|
|
346
|
+
requestMethod,
|
|
347
|
+
requestBody,
|
|
332
348
|
);
|
|
333
349
|
|
|
334
350
|
return true;
|
|
@@ -606,6 +622,8 @@ class Tracker {
|
|
|
606
622
|
* @param {string} parameters.item_id - Product item unique identifier
|
|
607
623
|
* @param {string} [parameters.variation_id] - Product item variation unique identifier
|
|
608
624
|
* @param {string} [parameters.result_id] - Search result identifier (returned in response from Constructor)
|
|
625
|
+
* @param {string} [parameters.item_is_convertible] - Whether or not an item is available for a conversion
|
|
626
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
609
627
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
610
628
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
611
629
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -645,7 +663,16 @@ class Tracker {
|
|
|
645
663
|
if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
|
|
646
664
|
const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/click_through?`;
|
|
647
665
|
const queryParams = {};
|
|
648
|
-
const {
|
|
666
|
+
const {
|
|
667
|
+
item_name,
|
|
668
|
+
name,
|
|
669
|
+
item_id,
|
|
670
|
+
customer_id,
|
|
671
|
+
variation_id,
|
|
672
|
+
result_id,
|
|
673
|
+
item_is_convertible,
|
|
674
|
+
section,
|
|
675
|
+
} = parameters;
|
|
649
676
|
|
|
650
677
|
// Ensure support for both item_name and name as parameters
|
|
651
678
|
if (item_name) {
|
|
@@ -669,6 +696,14 @@ class Tracker {
|
|
|
669
696
|
queryParams.result_id = result_id;
|
|
670
697
|
}
|
|
671
698
|
|
|
699
|
+
if (typeof item_is_convertible === 'boolean') {
|
|
700
|
+
queryParams.item_is_convertible = item_is_convertible;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
if (section) {
|
|
704
|
+
queryParams.section = section;
|
|
705
|
+
}
|
|
706
|
+
|
|
672
707
|
const requestUrl = `${url}${applyParamsAsString(queryParams, userParameters, this.options)}`;
|
|
673
708
|
|
|
674
709
|
send.call(
|
|
@@ -915,6 +950,7 @@ class Tracker {
|
|
|
915
950
|
* @param {string} parameters.url - Current page URL
|
|
916
951
|
* @param {string} parameters.pod_id - Pod identifier
|
|
917
952
|
* @param {number} parameters.num_results_viewed - Number of results viewed
|
|
953
|
+
* @param {object[]} [parameters.items] - List of Product Item Objects
|
|
918
954
|
* @param {number} [parameters.result_count] - Total number of results
|
|
919
955
|
* @param {number} [parameters.result_page] - Page number of results
|
|
920
956
|
* @param {string} [parameters.result_id] - Recommendation result identifier (returned in response from Constructor)
|
|
@@ -1442,7 +1478,7 @@ class Tracker {
|
|
|
1442
1478
|
* @param {object} [userParameters] - Parameters relevant to the user request
|
|
1443
1479
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
1444
1480
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
1445
|
-
* @param {string} userParameters.userId - User ID, utilized to personalize results
|
|
1481
|
+
* @param {string} [userParameters.userId] - User ID, utilized to personalize results
|
|
1446
1482
|
* @param {string} [userParameters.segments] - User segments
|
|
1447
1483
|
* @param {object} [userParameters.testCells] - User test cells
|
|
1448
1484
|
* @param {string} [userParameters.originReferrer] - Client page URL (including path)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConstructorClientOptions,
|
|
3
|
+
NetworkParameters,
|
|
4
|
+
RequestFeature,
|
|
5
|
+
RequestFeatureVariant,
|
|
6
|
+
UserParameters,
|
|
7
|
+
} from '.';
|
|
8
|
+
|
|
9
|
+
export default Autocomplete;
|
|
10
|
+
|
|
11
|
+
export interface AutocompleteParameters {
|
|
12
|
+
numResults?: number;
|
|
13
|
+
filters?: Record<string, any>;
|
|
14
|
+
resultsPerSection?: Record<string, number>;
|
|
15
|
+
hiddenFields?: string[];
|
|
16
|
+
variationsMap?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare class Autocomplete {
|
|
20
|
+
constructor(options: ConstructorClientOptions);
|
|
21
|
+
|
|
22
|
+
options: ConstructorClientOptions;
|
|
23
|
+
|
|
24
|
+
getAutocompleteResults(
|
|
25
|
+
query: string,
|
|
26
|
+
parameters?: AutocompleteParameters,
|
|
27
|
+
userParameters?: UserParameters,
|
|
28
|
+
networkParameters?: NetworkParameters
|
|
29
|
+
): Promise<AutocompleteResponse>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Autocomplete results returned from server */
|
|
33
|
+
export interface AutocompleteResponse extends Record<string, any> {
|
|
34
|
+
request: Partial<AutocompleteRequestType>;
|
|
35
|
+
sections: Record<string, Section>;
|
|
36
|
+
result_id: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AutocompleteRequestType extends Record<string, any> {
|
|
40
|
+
num_results: number;
|
|
41
|
+
term: string;
|
|
42
|
+
query: string;
|
|
43
|
+
features: Partial<RequestFeature>;
|
|
44
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
45
|
+
searchandized_items: Record<string, any>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type Section = Partial<SectionItem>[];
|
|
49
|
+
|
|
50
|
+
export interface SectionItem extends Record<string, any> {
|
|
51
|
+
data: Record<string, any>;
|
|
52
|
+
is_slotted: boolean;
|
|
53
|
+
labels: Record<string, any>;
|
|
54
|
+
matched_terms: string[];
|
|
55
|
+
value: string;
|
|
56
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NetworkParameters,
|
|
3
|
+
UserParameters,
|
|
4
|
+
Collection,
|
|
5
|
+
ConstructorClientOptions,
|
|
6
|
+
Facet,
|
|
7
|
+
Feature,
|
|
8
|
+
Group,
|
|
9
|
+
RequestFeature,
|
|
10
|
+
RequestFeatureVariant,
|
|
11
|
+
ResultSources,
|
|
12
|
+
SortOption,
|
|
13
|
+
FmtOptions,
|
|
14
|
+
} from '.';
|
|
15
|
+
|
|
16
|
+
export default Browse;
|
|
17
|
+
|
|
18
|
+
export interface BrowseParameters {
|
|
19
|
+
page?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
resultsPerPage?: number;
|
|
22
|
+
filters?: Record<string, any>;
|
|
23
|
+
sortBy?: string;
|
|
24
|
+
sortOrder?: string;
|
|
25
|
+
section?: string;
|
|
26
|
+
fmtOptions?: FmtOptions;
|
|
27
|
+
hiddenFields?: string[];
|
|
28
|
+
hiddenFacets?: string[];
|
|
29
|
+
variationsMap?: Record<string, any>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare class Browse {
|
|
33
|
+
constructor(options: ConstructorClientOptions);
|
|
34
|
+
|
|
35
|
+
options: ConstructorClientOptions;
|
|
36
|
+
|
|
37
|
+
getBrowseResults(
|
|
38
|
+
filterName: string,
|
|
39
|
+
filterValue: string,
|
|
40
|
+
parameters?: BrowseParameters,
|
|
41
|
+
userParameters?: UserParameters,
|
|
42
|
+
networkParameters?: NetworkParameters
|
|
43
|
+
): Promise<GetBrowseResultsResponse>;
|
|
44
|
+
|
|
45
|
+
getBrowseResultsForItemIds(
|
|
46
|
+
itemIds: string[],
|
|
47
|
+
parameters?: BrowseParameters,
|
|
48
|
+
userParameters?: UserParameters,
|
|
49
|
+
networkParameters?: NetworkParameters
|
|
50
|
+
): Promise<GetBrowseResultsForItemIdsResponse>;
|
|
51
|
+
|
|
52
|
+
getBrowseGroups(
|
|
53
|
+
parameters?: Pick<BrowseParameters, 'filters' | 'section' | 'fmtOptions'>,
|
|
54
|
+
userParameters?: UserParameters,
|
|
55
|
+
networkParameters?: NetworkParameters
|
|
56
|
+
): Promise<GetBrowseGroupsResponse>;
|
|
57
|
+
|
|
58
|
+
getBrowseFacets(
|
|
59
|
+
parameters?: Pick<
|
|
60
|
+
BrowseParameters,
|
|
61
|
+
'page' | 'offset' | 'section' | 'fmtOptions' | 'resultsPerPage'
|
|
62
|
+
>,
|
|
63
|
+
userParameters?: UserParameters,
|
|
64
|
+
networkParameters?: NetworkParameters
|
|
65
|
+
): Promise<GetBrowseFacetsResponse>;
|
|
66
|
+
|
|
67
|
+
getBrowseFacetOptions(
|
|
68
|
+
facetName: string,
|
|
69
|
+
parameters?: Pick<BrowseParameters, 'section' | 'fmtOptions'>,
|
|
70
|
+
userParameters?: UserParameters,
|
|
71
|
+
networkParameters?: NetworkParameters
|
|
72
|
+
): Promise<GetBrowseFacetOptionsResponse>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Browse results returned from server */
|
|
76
|
+
interface BrowseResponse<ResponseType> extends Record<string, any> {
|
|
77
|
+
request?: Partial<BrowseRequestType>;
|
|
78
|
+
response?: Partial<ResponseType>;
|
|
79
|
+
result_id?: string;
|
|
80
|
+
ad_based?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type GetBrowseResultsResponse =
|
|
84
|
+
BrowseResponse<GetBrowseResultsResponseData>;
|
|
85
|
+
export type GetBrowseResultsForItemIdsResponse =
|
|
86
|
+
BrowseResponse<GetBrowseResultsResponseData>;
|
|
87
|
+
export type GetBrowseGroupsResponse = BrowseResponse<
|
|
88
|
+
Pick<
|
|
89
|
+
GetBrowseResultsResponseData,
|
|
90
|
+
'result_sources' | 'groups' | 'refined_content'
|
|
91
|
+
>
|
|
92
|
+
>;
|
|
93
|
+
export type GetBrowseFacetsResponse = BrowseResponse<
|
|
94
|
+
Pick<GetBrowseResultsResponseData, 'facets' | 'total_num_results'>
|
|
95
|
+
>;
|
|
96
|
+
export type GetBrowseFacetOptionsResponse = BrowseResponse<
|
|
97
|
+
Pick<GetBrowseResultsResponseData, 'facets'>
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
export interface GetBrowseResultsResponseData extends Record<string, any> {
|
|
101
|
+
result_sources: Partial<ResultSources>;
|
|
102
|
+
facets: Partial<Facet>[];
|
|
103
|
+
groups: Partial<Group>[];
|
|
104
|
+
results: Partial<BrowseResultData>[];
|
|
105
|
+
sort_options: Partial<SortOption>[];
|
|
106
|
+
refined_content: Record<string, any>[];
|
|
107
|
+
total_num_results: number;
|
|
108
|
+
features: Partial<Feature>[];
|
|
109
|
+
collection: Partial<Collection>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface BrowseResultData extends Record<string, any> {
|
|
113
|
+
matched_terms: string[];
|
|
114
|
+
data: {
|
|
115
|
+
id: string;
|
|
116
|
+
[key: string]: any;
|
|
117
|
+
};
|
|
118
|
+
value: string;
|
|
119
|
+
is_slotted: false;
|
|
120
|
+
labels: Record<string, any>;
|
|
121
|
+
variations: Record<string, any>[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface BrowseRequestType extends Record<string, any> {
|
|
125
|
+
browse_filter_name: string;
|
|
126
|
+
browse_filter_value: string;
|
|
127
|
+
filter_match_types: Record<string, any>;
|
|
128
|
+
filters: Record<string, any>;
|
|
129
|
+
fmt_options: Record<string, any>;
|
|
130
|
+
num_results_per_page: number;
|
|
131
|
+
page: number;
|
|
132
|
+
section: string;
|
|
133
|
+
sort_by: string;
|
|
134
|
+
sort_order: string;
|
|
135
|
+
term: string;
|
|
136
|
+
query: string;
|
|
137
|
+
features: Partial<RequestFeature>;
|
|
138
|
+
feature_variants: Partial<RequestFeatureVariant>;
|
|
139
|
+
searchandized_items: Record<string, any>;
|
|
140
|
+
}
|