@constructor-io/constructorio-node 4.6.1 → 4.6.2

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.2",
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'>[];
@@ -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
 
@@ -189,7 +194,9 @@ 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;
@@ -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
+ });