@constructor-io/constructorio-node 4.6.1 → 4.6.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-node",
3
- "version": "4.6.1",
3
+ "version": "4.6.3",
4
4
  "description": "Constructor.io Node.js client",
5
5
  "main": "src/constructorio.js",
6
6
  "types": "src/types/constructorio.d.ts",
@@ -3312,6 +3312,170 @@ class Catalog {
3312
3312
  return helpers.throwHttpErrorFromResponse(new Error(), response);
3313
3313
  });
3314
3314
  }
3315
+
3316
+ /**
3317
+ * Retrieve metadata searchabilities
3318
+ *
3319
+ * @function retrieveSearchabilities
3320
+ * @param {object} [parameters] - Additional parameters for retrieving metadata searchabilities
3321
+ * @param {string} [parameters.name] - Name of metadata searchability. Providing this field would filter the results based on name
3322
+ * @param {number} [parameters.page] - The page number of the results. Can't be used together with 'offset'
3323
+ * @param {number} [parameters.offset] - The number of results to skip from the beginning. Can't be used together with 'page'
3324
+ * @param {number} [parameters.numResultsPerPage] - The number of searchability configurations to return. Defaults to 100
3325
+ * @param {object} [parameters.filters] - Filters the results based on name, exactSearchable or fuzzySearchable
3326
+ * @param {boolean} [parameters.searchable] - Retrieve only results which are either exactSearchable or fuzzySearchable
3327
+ * @param {string} [parameters.sortBy] - The criteria by which searchability configurations should be sorted. Defaults to no sorting. Valid criteria is name
3328
+ * @param {string} [parameters.sortOrder] - Either descending or ascending. The sort order by which searchability configurations should be sorted. Only valid in conjunction with sortBy
3329
+ * @param {string} [parameters.section] - The section in which the searchability is defined. Default value is Products
3330
+ * @param {object} [networkParameters] - Parameters relevant to the network request
3331
+ * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
3332
+ * @returns {Promise}
3333
+ * @see https://docs.constructor.io/rest_api/searchabilities/#retrieve-searchabilities
3334
+ * @example
3335
+ * constructorio.catalog.retrieveSearchabilities({
3336
+ * page: 2,
3337
+ * numResultsPerPage: 50,
3338
+ * filters: { exactSearchable: true }
3339
+ * });
3340
+ */
3341
+ retrieveSearchabilities(parameters = {}, networkParameters = {}) {
3342
+ let requestUrl;
3343
+ const { fetch } = this.options;
3344
+ const controller = new AbortController();
3345
+ const { signal } = controller;
3346
+ const { name, page, offset, numResultsPerPage, filters, searchable, sortBy, sortOrder, section = 'Products' } = parameters;
3347
+ const additionalQueryParams = {};
3348
+
3349
+ if (!helpers.isNil(page)) {
3350
+ additionalQueryParams.page = page;
3351
+ }
3352
+
3353
+ if (!helpers.isNil(offset)) {
3354
+ additionalQueryParams.offset = offset;
3355
+ }
3356
+
3357
+ if (!helpers.isNil(numResultsPerPage)) {
3358
+ additionalQueryParams.num_results_per_page = numResultsPerPage;
3359
+ }
3360
+
3361
+ if (filters) {
3362
+ additionalQueryParams.filters = toSnakeCaseKeys(filters);
3363
+ }
3364
+
3365
+ if (searchable) {
3366
+ additionalQueryParams.searchable = searchable;
3367
+ }
3368
+
3369
+ if (sortBy) {
3370
+ additionalQueryParams.sort_by = sortBy;
3371
+ }
3372
+
3373
+ if (sortOrder) {
3374
+ additionalQueryParams.sort_order = sortOrder;
3375
+ }
3376
+
3377
+ if (sortOrder) {
3378
+ additionalQueryParams.sort_order = sortOrder;
3379
+ }
3380
+
3381
+ if (section) {
3382
+ additionalQueryParams.section = section;
3383
+ }
3384
+
3385
+ if (name) {
3386
+ if (additionalQueryParams.filters) {
3387
+ additionalQueryParams.filters.name = name;
3388
+ } else {
3389
+ additionalQueryParams.filters = { name };
3390
+ }
3391
+ }
3392
+
3393
+ try {
3394
+ requestUrl = createCatalogUrl('searchabilities', this.options, additionalQueryParams);
3395
+ } catch (e) {
3396
+ return Promise.reject(e);
3397
+ }
3398
+
3399
+ // Handle network timeout if specified
3400
+ helpers.applyNetworkTimeout(this.options, networkParameters, controller);
3401
+
3402
+ return fetch(requestUrl, {
3403
+ method: 'GET',
3404
+ headers: {
3405
+ 'Content-Type': 'application/json',
3406
+ ...helpers.createAuthHeader(this.options),
3407
+ },
3408
+ signal,
3409
+ }).then((response) => {
3410
+ if (response.ok) {
3411
+ return response.json();
3412
+ }
3413
+
3414
+ return helpers.throwHttpErrorFromResponse(new Error(), response);
3415
+ });
3416
+ }
3417
+
3418
+ /**
3419
+ * Patch metadata searchabilities
3420
+ *
3421
+ * @function patchSearchabilities
3422
+ * @param {object} parameters - Additional parameters for patching metadata searchabilities
3423
+ * @param {object[]} parameters.searchabilities - Array of searchabilities. Additional information about the searchabilities schema can be found [here]{@link https://docs.constructor.io/rest_api/searchabilities/#patch-searchabilities}
3424
+ * @param {string} [parameters.section] - The section in which the searchability is defined. Default value is Products
3425
+ * @param {object} [networkParameters] - Parameters relevant to the network request
3426
+ * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
3427
+ * @returns {Promise}
3428
+ * @see https://docs.constructor.io/rest_api/searchabilities/#patch-searchabilities
3429
+ * @example
3430
+ * constructorio.catalog.patchSearchabilities({
3431
+ * searchabilities: [
3432
+ * {
3433
+ * name: 'style_id',
3434
+ * exactSearchable: true,
3435
+ * },
3436
+ * {
3437
+ * name: 'keywords',
3438
+ * fuzzySearchable: true,
3439
+ * },
3440
+ * ],
3441
+ * });
3442
+ */
3443
+ patchSearchabilities(parameters = {}, networkParameters = {}) {
3444
+ let requestUrl;
3445
+ const { fetch } = this.options;
3446
+ const controller = new AbortController();
3447
+ const { signal } = controller;
3448
+ const { searchabilities: searchabilitiesRaw, section = 'Products' } = parameters;
3449
+ const searchabilities = searchabilitiesRaw?.map((config) => toSnakeCaseKeys(config));
3450
+ const additionalQueryParams = {
3451
+ section,
3452
+ };
3453
+
3454
+ try {
3455
+ requestUrl = createCatalogUrl('searchabilities', this.options, additionalQueryParams);
3456
+ } catch (e) {
3457
+ return Promise.reject(e);
3458
+ }
3459
+
3460
+ // Handle network timeout if specified
3461
+ helpers.applyNetworkTimeout(this.options, networkParameters, controller);
3462
+
3463
+ return fetch(requestUrl, {
3464
+ method: 'PATCH',
3465
+ body: JSON.stringify({ searchabilities }),
3466
+ headers: {
3467
+ 'Content-Type': 'application/json',
3468
+ ...helpers.createAuthHeader(this.options),
3469
+ },
3470
+ signal,
3471
+ }).then((response) => {
3472
+ if (response.ok) {
3473
+ return response.json();
3474
+ }
3475
+
3476
+ return helpers.throwHttpErrorFromResponse(new Error(), response);
3477
+ });
3478
+ }
3315
3479
  }
3316
3480
 
3317
3481
  module.exports = Catalog;
@@ -10,6 +10,8 @@ import {
10
10
  RedirectRuleResponse,
11
11
  OneWaySynonymRelation,
12
12
  SynonymGroup,
13
+ SearchabilityConfiguration,
14
+ SearchabilityConfigurationResponse,
13
15
  } from '.';
14
16
 
15
17
  export default Catalog;
@@ -21,7 +23,9 @@ export interface CreateOrReplaceItemsParameters {
21
23
  section?: string;
22
24
  }
23
25
 
24
- export interface UpdateItemsParameters extends CreateOrReplaceItemsParameters {}
26
+ export interface UpdateItemsParameters extends CreateOrReplaceItemsParameters {
27
+ onMissing?: 'IGNORE' | 'CREATE' | 'FAIL';
28
+ }
25
29
 
26
30
  export interface DeleteItemsParameters {
27
31
  items: Pick<Item, 'id'>[];
@@ -44,7 +48,9 @@ export interface CreateOrReplaceVariationsParameters {
44
48
  }
45
49
 
46
50
  export interface UpdateVariationsParameters
47
- extends CreateOrReplaceVariationsParameters {}
51
+ extends CreateOrReplaceVariationsParameters {
52
+ onMissing?: 'IGNORE' | 'CREATE' | 'FAIL';
53
+ }
48
54
 
49
55
  export interface DeleteVariationsParameters {
50
56
  variations: Pick<Variation, 'id'>[];
@@ -64,12 +70,12 @@ export interface RetrieveVariationsParameters {
64
70
  export interface AddItemGroupParameters {
65
71
  id: string;
66
72
  name: string;
67
- parent_id?: string;
73
+ parentId?: string;
68
74
  data?: Record<string, any>;
69
75
  }
70
76
 
71
77
  export interface AddItemGroupsParameters {
72
- item_groups: ItemGroup[];
78
+ itemGroups: ItemGroup[];
73
79
  }
74
80
 
75
81
  export interface GetItemGroupParameters {
@@ -81,7 +87,7 @@ export interface AddOrUpdateItemGroupsParameters
81
87
 
82
88
  export interface AddOneWaySynonymParameters {
83
89
  phrase: string;
84
- child_phrases: string[];
90
+ childPhrases: string[];
85
91
  }
86
92
 
87
93
  export interface ModifyOneWaySynonymParameters
@@ -92,7 +98,7 @@ export interface GetOneWaySynonymParameters {
92
98
  }
93
99
 
94
100
  export interface GetOneWaySynonymsParameters {
95
- num_results_per_page?: number;
101
+ numResultsPerPage?: number;
96
102
  page?: number;
97
103
  }
98
104
 
@@ -105,7 +111,6 @@ export interface AddSynonymGroupParameters {
105
111
  }
106
112
 
107
113
  export interface ModifySynonymGroupParameters {
108
- id: number;
109
114
  synonyms: string[];
110
115
  }
111
116
 
@@ -115,7 +120,7 @@ export interface GetSynonymGroupParameters {
115
120
 
116
121
  export interface GetSynonymGroupsParameters {
117
122
  phrase?: string;
118
- num_results_per_page?: number;
123
+ numResultsPerPage?: number;
119
124
  page?: number;
120
125
  }
121
126
 
@@ -126,9 +131,9 @@ export interface RemoveSynonymGroupParameters {
126
131
  export interface AddRedirectRuleParameters {
127
132
  url: string;
128
133
  matches: RedirectRuleMatchObject[];
129
- start_time?: string;
130
- end_time?: string;
131
- user_segments?: string[];
134
+ startTime?: string;
135
+ endTime?: string;
136
+ userSegments?: string[];
132
137
  metadata?: Record<string, any>;
133
138
  }
134
139
 
@@ -147,7 +152,7 @@ export interface GetRedirectRuleParameters {
147
152
  }
148
153
 
149
154
  export interface GetRedirectRulesParameters {
150
- num_results_per_page?: number;
155
+ numResultsPerPage?: number;
151
156
  page?: number;
152
157
  query?: string;
153
158
  status?: string;
@@ -159,28 +164,28 @@ export interface RemoveRedirectRuleParameters {
159
164
 
160
165
  export interface ReplaceCatalogParameters {
161
166
  section: string;
162
- notification_email?: string;
167
+ notificationEmail?: string;
163
168
  force?: boolean;
164
169
  items?: File;
165
170
  variations?: File;
166
- item_groups?: File;
171
+ itemGroups?: File;
167
172
  }
168
173
 
169
174
  export interface UpdateCatalogParameters extends ReplaceCatalogParameters {}
170
175
 
171
176
  export interface PatchCatalogParameters {
172
177
  section: string;
173
- notification_email?: string;
178
+ notificationEmail?: string;
174
179
  force?: boolean;
175
180
  onMissing?: 'IGNORE' | 'CREATE' | 'FAIL';
176
181
  items?: File;
177
182
  variations?: File;
178
- item_groups?: File;
183
+ itemGroups?: File;
179
184
  }
180
185
 
181
186
  export interface ReplaceCatalogUsingTarArchiveParameters {
182
187
  section: string;
183
- notification_email?: string;
188
+ notificationEmail?: string;
184
189
  force?: boolean;
185
190
  tarArchive?: File;
186
191
  }
@@ -189,11 +194,13 @@ export interface UpdateCatalogUsingTarArchiveParameters
189
194
  extends ReplaceCatalogUsingTarArchiveParameters {}
190
195
 
191
196
  export interface PatchCatalogUsingTarArchiveParameters
192
- extends ReplaceCatalogUsingTarArchiveParameters {}
197
+ extends ReplaceCatalogUsingTarArchiveParameters {
198
+ onMissing?: 'IGNORE' | 'CREATE' | 'FAIL';
199
+ }
193
200
 
194
201
  export interface GetFacetConfigurationsParameters {
195
202
  page?: number;
196
- num_results_per_page?: number;
203
+ numResultsPerPage?: number;
197
204
  section?: string;
198
205
  }
199
206
 
@@ -225,7 +232,7 @@ export interface AddOrModifyFacetOptionConfigurationsParameters {
225
232
  export interface GetFacetOptionConfigurationsParameters {
226
233
  facetGroupName: string;
227
234
  page?: number;
228
- num_results_per_page?: number;
235
+ numResultsPerPage?: number;
229
236
  section?: string;
230
237
  }
231
238
 
@@ -244,6 +251,22 @@ export type ModifyFacetOptionConfigurationParameters = ReplaceFacetOptionConfigu
244
251
 
245
252
  export interface RemoveFacetOptionConfiguration extends GetFacetOptionConfigurationParameters {}
246
253
 
254
+ export interface RetrieveSearchabilitiesParameters {
255
+ name?: string;
256
+ page?: number;
257
+ offset?: number;
258
+ numResultsPerPage?: number;
259
+ filters?: Record<string, any>;
260
+ searchable?: boolean;
261
+ sortBy?: string;
262
+ sortOrder?: string;
263
+ section?: string;
264
+ }
265
+
266
+ export interface PatchSearchabilitiesParameters {
267
+ searchabilities: SearchabilityConfiguration[],
268
+ }
269
+
247
270
  declare class Catalog {
248
271
  constructor(options: ConstructorClientOptions);
249
272
 
@@ -579,4 +602,19 @@ declare class Catalog {
579
602
  parameters: RemoveFacetOptionConfiguration,
580
603
  networkParameters?: NetworkParameters
581
604
  ): Promise<FacetOptionConfiguration>;
605
+
606
+ retrieveSearchabilities(
607
+ parameters?: RetrieveSearchabilitiesParameters,
608
+ networkParameters?: NetworkParameters
609
+ ): Promise<{
610
+ searchabilities: SearchabilityConfigurationResponse[];
611
+ total_count: number;
612
+ }>;
613
+
614
+ patchSearchabilities(
615
+ parameters: PatchSearchabilitiesParameters,
616
+ networkParameters?: NetworkParameters
617
+ ): Promise<{
618
+ searchabilities: SearchabilityConfigurationResponse[];
619
+ }>;
582
620
  }
@@ -298,3 +298,23 @@ export type FilterExpressionRange = {
298
298
  };
299
299
 
300
300
  export type FilterExpressionRangeValue = ['-inf' | number, 'inf' | number];
301
+
302
+ export interface SearchabilityConfigurationResponse {
303
+ name: string;
304
+ fuzzy_searchable: boolean,
305
+ exact_searchable: boolean,
306
+ type: string,
307
+ displayable: boolean,
308
+ hidden: boolean,
309
+ created_at: string,
310
+ updated_at: string
311
+ }
312
+
313
+ export interface SearchabilityConfiguration {
314
+ name: string;
315
+ fuzzySearchable?: boolean,
316
+ exactSearchable?: boolean,
317
+ type?: string,
318
+ displayable?: boolean,
319
+ hidden?: boolean,
320
+ }
@@ -7,6 +7,7 @@ import {
7
7
  OneWaySynonymRelation,
8
8
  RedirectRuleResponse,
9
9
  Variation,
10
+ SearchabilityConfigurationResponse,
10
11
  } from '..';
11
12
 
12
13
  expectAssignable<Item>({
@@ -107,3 +108,14 @@ expectAssignable<FacetOptionConfiguration>({
107
108
  data: null,
108
109
  hidden: false,
109
110
  });
111
+
112
+ expectAssignable<SearchabilityConfigurationResponse>({
113
+ name: 'groups',
114
+ fuzzy_searchable: false,
115
+ exact_searchable: false,
116
+ type: 'string',
117
+ displayable: true,
118
+ hidden: false,
119
+ created_at: '2019-04-12T18:15:30',
120
+ updated_at: '2019-04-12T18:15:30',
121
+ });
@@ -35,9 +35,10 @@ declare class Tracker {
35
35
 
36
36
  trackItemDetailLoad(
37
37
  parameters: {
38
- item_name: string;
39
- item_id: string;
40
- variation_id?: string;
38
+ itemName: string;
39
+ itemId: string;
40
+ url: string;
41
+ variationId?: string;
41
42
  },
42
43
  userParameters?: TrackerUserParameters,
43
44
  networkParameters?: NetworkParameters
@@ -46,11 +47,11 @@ declare class Tracker {
46
47
  trackAutocompleteSelect(
47
48
  term: string,
48
49
  parameters: {
49
- original_query: string;
50
+ originalQuery: string;
50
51
  section: string;
51
52
  tr?: string;
52
- group_id?: string;
53
- display_name?: string;
53
+ groupId?: string;
54
+ displayName?: string;
54
55
  },
55
56
  userParameters?: TrackerUserParameters,
56
57
  networkParameters?: NetworkParameters
@@ -59,9 +60,9 @@ declare class Tracker {
59
60
  trackSearchSubmit(
60
61
  term: string,
61
62
  parameters: {
62
- original_query: string;
63
- group_id?: string;
64
- display_name?: string;
63
+ originalQuery: string;
64
+ groupId?: string;
65
+ displayName?: string;
65
66
  },
66
67
  userParameters?: TrackerUserParameters,
67
68
  networkParameters?: NetworkParameters
@@ -70,8 +71,8 @@ declare class Tracker {
70
71
  trackSearchResultsLoaded(
71
72
  term: string,
72
73
  parameters: {
73
- num_results: number;
74
- item_ids?: string[];
74
+ numResults: number;
75
+ itemIds?: string[];
75
76
  },
76
77
  userParameters?: TrackerUserParameters,
77
78
  networkParameters?: NetworkParameters
@@ -80,11 +81,11 @@ declare class Tracker {
80
81
  trackSearchResultClick(
81
82
  term: string,
82
83
  parameters: {
83
- item_name: string;
84
- item_id: string;
85
- variation_id?: string;
86
- result_id?: string;
87
- item_is_convertible?: string;
84
+ itemName: string;
85
+ itemId: string;
86
+ variationId?: string;
87
+ resultId?: string;
88
+ itemIsConvertible?: string;
88
89
  section?: string;
89
90
  },
90
91
  userParameters?: TrackerUserParameters,
@@ -94,14 +95,14 @@ declare class Tracker {
94
95
  trackConversion(
95
96
  term : string | null | undefined,
96
97
  parameters: {
97
- item_id: string;
98
+ itemId: string;
98
99
  revenue?: number;
99
- item_name?: string;
100
- variation_id?: string;
100
+ itemName?: string;
101
+ variationId?: string;
101
102
  type?: string;
102
- is_custom_type?: boolean;
103
- display_name?: string;
104
- result_id?: string;
103
+ isCustomType?: boolean;
104
+ displayName?: string;
105
+ resultId?: string;
105
106
  section?: string;
106
107
  },
107
108
  userParameters?: TrackerUserParameters,
@@ -112,7 +113,7 @@ declare class Tracker {
112
113
  parameters: {
113
114
  items: object[];
114
115
  revenue: number;
115
- order_id?: string;
116
+ orderId?: string;
116
117
  section?: string;
117
118
  },
118
119
  userParameters?: TrackerUserParameters,
@@ -122,12 +123,12 @@ declare class Tracker {
122
123
  trackRecommendationView(
123
124
  parameters: {
124
125
  url: string;
125
- pod_id: string;
126
- num_results_viewed: number;
126
+ podId: string;
127
+ numResultsViewed: number;
127
128
  items?: object[];
128
- result_count?: number;
129
- result_page?: number;
130
- result_id?: string;
129
+ resultCount?: number;
130
+ resultPage?: number;
131
+ resultId?: string;
131
132
  section?: string;
132
133
  },
133
134
  userParameters?: TrackerUserParameters,
@@ -136,17 +137,17 @@ declare class Tracker {
136
137
 
137
138
  trackRecommendationClick(
138
139
  parameters: {
139
- pod_id: string;
140
- strategy_id: string;
141
- item_id: string;
142
- item_name: string;
143
- variation_id?: string;
140
+ podId: string;
141
+ strategyId: string;
142
+ itemId: string;
143
+ itemName: string;
144
+ variationId?: string;
144
145
  section?: string;
145
- result_id?: string;
146
- result_count?: number;
147
- result_page?: number;
148
- result_position_on_page?: number;
149
- num_results_per_page?: number;
146
+ resultId?: string;
147
+ resultCount?: number;
148
+ resultPage?: number;
149
+ resultPositionOnPage?: number;
150
+ numResultsPerPage?: number;
150
151
  },
151
152
  userParameters?: TrackerUserParameters,
152
153
  networkParameters?: NetworkParameters
@@ -155,15 +156,15 @@ declare class Tracker {
155
156
  trackBrowseResultsLoaded(
156
157
  parameters: {
157
158
  url: string;
158
- filter_name: string;
159
- filter_value: string;
159
+ filterName: string;
160
+ filterValue: string;
160
161
  section?: string;
161
- result_count?: number;
162
- result_page?: number;
163
- result_id?: string;
164
- selected_filters?: object;
165
- sort_order?: string;
166
- sort_by?: string;
162
+ resultCount?: number;
163
+ resultPage?: number;
164
+ resultId?: string;
165
+ selectedFilters?: object;
166
+ sortOrder?: string;
167
+ sortBy?: string;
167
168
  items?: object[];
168
169
  },
169
170
  userParameters?: TrackerUserParameters,
@@ -172,17 +173,17 @@ declare class Tracker {
172
173
 
173
174
  trackBrowseResultClick(
174
175
  parameters: {
175
- filter_name: string;
176
- filter_value: string;
177
- item_id: string;
176
+ filterName: string;
177
+ filterValue: string;
178
+ itemId: string;
178
179
  section?: string;
179
- variation_id?: string;
180
- result_id?: string;
181
- result_count?: number;
182
- result_page?: number;
183
- result_position_on_page?: number;
184
- num_results_per_page?: number;
185
- selected_filters?: object;
180
+ variationId?: string;
181
+ resultId?: string;
182
+ resultCount?: number;
183
+ resultPage?: number;
184
+ resultPositionOnPage?: number;
185
+ numResultsPerPage?: number;
186
+ selectedFilters?: object;
186
187
  },
187
188
  userParameters?: TrackerUserParameters,
188
189
  networkParameters?: NetworkParameters
@@ -190,9 +191,9 @@ declare class Tracker {
190
191
 
191
192
  trackGenericResultClick(
192
193
  parameters: {
193
- item_id: string;
194
- item_name?: string;
195
- variation_id?: string;
194
+ itemId: string;
195
+ itemName?: string;
196
+ variationId?: string;
196
197
  section?: string;
197
198
  },
198
199
  userParameters?: TrackerUserParameters,