@constructor-io/constructorio-node 4.18.0 → 5.1.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/package.json +1 -1
- package/src/modules/catalog.js +103 -72
- package/src/modules/recommendations.js +16 -2
- package/src/modules/tracker.js +2 -2
- package/src/types/catalog.d.ts +18 -36
- package/src/types/recommendations.d.ts +4 -2
package/package.json
CHANGED
package/src/modules/catalog.js
CHANGED
|
@@ -210,7 +210,7 @@ class Catalog {
|
|
|
210
210
|
* ],
|
|
211
211
|
* });
|
|
212
212
|
*/
|
|
213
|
-
createOrReplaceItems(parameters = {}, networkParameters = {}) {
|
|
213
|
+
async createOrReplaceItems(parameters = {}, networkParameters = {}) {
|
|
214
214
|
let requestUrl;
|
|
215
215
|
const { fetch } = this.options;
|
|
216
216
|
const controller = new AbortController();
|
|
@@ -244,21 +244,27 @@ class Catalog {
|
|
|
244
244
|
// Handle network timeout if specified
|
|
245
245
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
247
|
+
try {
|
|
248
|
+
const response = await fetch(requestUrl, {
|
|
249
|
+
method: 'PUT',
|
|
250
|
+
body: JSON.stringify({ items }),
|
|
251
|
+
headers: {
|
|
252
|
+
'Content-Type': 'application/json',
|
|
253
|
+
...helpers.createAuthHeader(this.options),
|
|
254
|
+
},
|
|
255
|
+
signal,
|
|
256
|
+
});
|
|
257
|
+
|
|
256
258
|
if (response.ok) {
|
|
257
|
-
|
|
259
|
+
const body = await response.json();
|
|
260
|
+
|
|
261
|
+
return Promise.resolve(body);
|
|
258
262
|
}
|
|
259
263
|
|
|
260
264
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
261
|
-
})
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return Promise.reject(error);
|
|
267
|
+
}
|
|
262
268
|
}
|
|
263
269
|
|
|
264
270
|
/**
|
|
@@ -293,7 +299,7 @@ class Catalog {
|
|
|
293
299
|
* section: 'Products',
|
|
294
300
|
* });
|
|
295
301
|
*/
|
|
296
|
-
updateItems(parameters = {}, networkParameters = {}) {
|
|
302
|
+
async updateItems(parameters = {}, networkParameters = {}) {
|
|
297
303
|
let requestUrl;
|
|
298
304
|
const { fetch } = this.options;
|
|
299
305
|
const controller = new AbortController();
|
|
@@ -336,21 +342,26 @@ class Catalog {
|
|
|
336
342
|
// Handle network timeout if specified
|
|
337
343
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
338
344
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
try {
|
|
346
|
+
const response = await fetch(requestUrl, {
|
|
347
|
+
method: 'PATCH',
|
|
348
|
+
body: JSON.stringify({ items }),
|
|
349
|
+
headers: {
|
|
350
|
+
'Content-Type': 'application/json',
|
|
351
|
+
...helpers.createAuthHeader(this.options),
|
|
352
|
+
},
|
|
353
|
+
signal,
|
|
354
|
+
});
|
|
355
|
+
|
|
348
356
|
if (response.ok) {
|
|
349
|
-
|
|
357
|
+
const body = await response.json();
|
|
358
|
+
return Promise.resolve(body);
|
|
350
359
|
}
|
|
351
360
|
|
|
352
361
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
353
|
-
})
|
|
362
|
+
} catch (error) {
|
|
363
|
+
return Promise.reject(error);
|
|
364
|
+
}
|
|
354
365
|
}
|
|
355
366
|
|
|
356
367
|
/**
|
|
@@ -375,7 +386,7 @@ class Catalog {
|
|
|
375
386
|
* section: 'Products',
|
|
376
387
|
* });
|
|
377
388
|
*/
|
|
378
|
-
deleteItems(parameters = {}, networkParameters = {}) {
|
|
389
|
+
async deleteItems(parameters = {}, networkParameters = {}) {
|
|
379
390
|
let requestUrl;
|
|
380
391
|
const { fetch } = this.options;
|
|
381
392
|
const controller = new AbortController();
|
|
@@ -409,21 +420,26 @@ class Catalog {
|
|
|
409
420
|
// Handle network timeout if specified
|
|
410
421
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
411
422
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
try {
|
|
424
|
+
const response = await fetch(requestUrl, {
|
|
425
|
+
method: 'DELETE',
|
|
426
|
+
body: JSON.stringify({ items }),
|
|
427
|
+
headers: {
|
|
428
|
+
'Content-Type': 'application/json',
|
|
429
|
+
...helpers.createAuthHeader(this.options),
|
|
430
|
+
},
|
|
431
|
+
signal,
|
|
432
|
+
});
|
|
433
|
+
|
|
421
434
|
if (response.ok) {
|
|
422
|
-
|
|
435
|
+
const body = await response.json();
|
|
436
|
+
return Promise.resolve(body);
|
|
423
437
|
}
|
|
424
438
|
|
|
425
439
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
426
|
-
})
|
|
440
|
+
} catch (error) {
|
|
441
|
+
return Promise.reject(error);
|
|
442
|
+
}
|
|
427
443
|
}
|
|
428
444
|
|
|
429
445
|
/**
|
|
@@ -534,7 +550,7 @@ class Catalog {
|
|
|
534
550
|
* section: 'Products',
|
|
535
551
|
* });
|
|
536
552
|
*/
|
|
537
|
-
createOrReplaceVariations(parameters = {}, networkParameters = {}) {
|
|
553
|
+
async createOrReplaceVariations(parameters = {}, networkParameters = {}) {
|
|
538
554
|
let requestUrl;
|
|
539
555
|
const { fetch } = this.options;
|
|
540
556
|
const controller = new AbortController();
|
|
@@ -568,21 +584,26 @@ class Catalog {
|
|
|
568
584
|
// Handle network timeout if specified
|
|
569
585
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
570
586
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
587
|
+
try {
|
|
588
|
+
const response = await fetch(requestUrl, {
|
|
589
|
+
method: 'PUT',
|
|
590
|
+
body: JSON.stringify({ variations }),
|
|
591
|
+
headers: {
|
|
592
|
+
'Content-Type': 'application/json',
|
|
593
|
+
...helpers.createAuthHeader(this.options),
|
|
594
|
+
},
|
|
595
|
+
signal,
|
|
596
|
+
});
|
|
597
|
+
|
|
580
598
|
if (response.ok) {
|
|
581
|
-
|
|
599
|
+
const body = await response.json();
|
|
600
|
+
return Promise.resolve(body);
|
|
582
601
|
}
|
|
583
602
|
|
|
584
603
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
585
|
-
})
|
|
604
|
+
} catch (error) {
|
|
605
|
+
return Promise.reject(error);
|
|
606
|
+
}
|
|
586
607
|
}
|
|
587
608
|
|
|
588
609
|
/**
|
|
@@ -618,7 +639,7 @@ class Catalog {
|
|
|
618
639
|
* section: 'Products',
|
|
619
640
|
* });
|
|
620
641
|
*/
|
|
621
|
-
updateVariations(parameters = {}, networkParameters = {}) {
|
|
642
|
+
async updateVariations(parameters = {}, networkParameters = {}) {
|
|
622
643
|
let requestUrl;
|
|
623
644
|
const { fetch } = this.options;
|
|
624
645
|
const controller = new AbortController();
|
|
@@ -661,21 +682,26 @@ class Catalog {
|
|
|
661
682
|
// Handle network timeout if specified
|
|
662
683
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
663
684
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
685
|
+
try {
|
|
686
|
+
const response = await fetch(requestUrl, {
|
|
687
|
+
method: 'PATCH',
|
|
688
|
+
body: JSON.stringify({ variations }),
|
|
689
|
+
headers: {
|
|
690
|
+
'Content-Type': 'application/json',
|
|
691
|
+
...helpers.createAuthHeader(this.options),
|
|
692
|
+
},
|
|
693
|
+
signal,
|
|
694
|
+
});
|
|
695
|
+
|
|
673
696
|
if (response.ok) {
|
|
674
|
-
|
|
697
|
+
const body = await response.json();
|
|
698
|
+
return Promise.resolve(body);
|
|
675
699
|
}
|
|
676
700
|
|
|
677
701
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
678
|
-
})
|
|
702
|
+
} catch (error) {
|
|
703
|
+
return Promise.reject(error);
|
|
704
|
+
}
|
|
679
705
|
}
|
|
680
706
|
|
|
681
707
|
/**
|
|
@@ -700,7 +726,7 @@ class Catalog {
|
|
|
700
726
|
* section: 'Products',
|
|
701
727
|
* });
|
|
702
728
|
*/
|
|
703
|
-
deleteVariations(parameters = {}, networkParameters = {}) {
|
|
729
|
+
async deleteVariations(parameters = {}, networkParameters = {}) {
|
|
704
730
|
let requestUrl;
|
|
705
731
|
const { fetch } = this.options;
|
|
706
732
|
const controller = new AbortController();
|
|
@@ -734,21 +760,26 @@ class Catalog {
|
|
|
734
760
|
// Handle network timeout if specified
|
|
735
761
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
736
762
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
763
|
+
try {
|
|
764
|
+
const response = await fetch(requestUrl, {
|
|
765
|
+
method: 'DELETE',
|
|
766
|
+
body: JSON.stringify({ variations }),
|
|
767
|
+
headers: {
|
|
768
|
+
'Content-Type': 'application/json',
|
|
769
|
+
...helpers.createAuthHeader(this.options),
|
|
770
|
+
},
|
|
771
|
+
signal,
|
|
772
|
+
});
|
|
773
|
+
|
|
746
774
|
if (response.ok) {
|
|
747
|
-
|
|
775
|
+
const body = await response.json();
|
|
776
|
+
return Promise.resolve(body);
|
|
748
777
|
}
|
|
749
778
|
|
|
750
779
|
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
751
|
-
})
|
|
780
|
+
} catch (error) {
|
|
781
|
+
return Promise.reject(error);
|
|
782
|
+
}
|
|
752
783
|
}
|
|
753
784
|
|
|
754
785
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable object-curly-newline, no-param-reassign */
|
|
1
|
+
/* eslint-disable object-curly-newline, no-param-reassign, max-len */
|
|
2
2
|
const qs = require('qs');
|
|
3
3
|
const { AbortController } = require('node-abort-controller');
|
|
4
4
|
const helpers = require('../utils/helpers');
|
|
@@ -41,6 +41,7 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
|
|
|
41
41
|
const {
|
|
42
42
|
numResults,
|
|
43
43
|
itemIds,
|
|
44
|
+
variationId,
|
|
44
45
|
section,
|
|
45
46
|
term,
|
|
46
47
|
filters,
|
|
@@ -59,6 +60,18 @@ function createRecommendationsUrl(podId, parameters, userParameters, options) {
|
|
|
59
60
|
queryParams.item_id = itemIds;
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
if (variationId) {
|
|
64
|
+
if (!itemIds) {
|
|
65
|
+
throw new Error('itemIds is a required parameter for variationId');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (Array.isArray(itemIds) && !itemIds.length) {
|
|
69
|
+
throw new Error('At least one itemId is a required parameter for variationId');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
queryParams.variation_id = variationId;
|
|
73
|
+
}
|
|
74
|
+
|
|
62
75
|
// Pull section from parameters
|
|
63
76
|
if (section) {
|
|
64
77
|
queryParams.section = section;
|
|
@@ -119,7 +132,8 @@ class Recommendations {
|
|
|
119
132
|
* @function getRecommendations
|
|
120
133
|
* @param {string} podId - Pod identifier
|
|
121
134
|
* @param {object} [parameters] - Additional parameters to refine results
|
|
122
|
-
* @param {string|array} [parameters.itemIds] - Item ID(s) to retrieve recommendations for (strategy specific)
|
|
135
|
+
* @param {string|array} [parameters.itemIds] - Item ID(s) to retrieve recommendations for (strategy specific). Required for variationId
|
|
136
|
+
* @param {string} [parameters.variationId] - Variation ID to retrieve recommendations for (strategy specific)
|
|
123
137
|
* @param {number} [parameters.numResults] - The number of results to return
|
|
124
138
|
* @param {string} [parameters.section] - The section to return results from
|
|
125
139
|
* @param {string} [parameters.term] - The term to use to refine results (strategy specific)
|
package/src/modules/tracker.js
CHANGED
|
@@ -1076,7 +1076,7 @@ class Tracker {
|
|
|
1076
1076
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1077
1077
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1078
1078
|
* @returns {(true|Error)}
|
|
1079
|
-
* @description User
|
|
1079
|
+
* @description User viewed a set of recommendations
|
|
1080
1080
|
* @example
|
|
1081
1081
|
* constructorio.tracker.trackRecommendationView(
|
|
1082
1082
|
* {
|
|
@@ -1663,7 +1663,7 @@ class Tracker {
|
|
|
1663
1663
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1664
1664
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1665
1665
|
* @returns {(true|Error)}
|
|
1666
|
-
* @description User clicked a result that appeared
|
|
1666
|
+
* @description User clicked a result that appeared outside of the scope of search / browse / recommendations
|
|
1667
1667
|
* @example
|
|
1668
1668
|
* constructorio.tracker.trackGenericResultClick(
|
|
1669
1669
|
* {
|
package/src/types/catalog.d.ts
CHANGED
|
@@ -272,6 +272,12 @@ export interface PatchSearchabilitiesParameters {
|
|
|
272
272
|
section?: string;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
interface CatalogMutationResponse {
|
|
276
|
+
task_id: string;
|
|
277
|
+
task_status_path: string;
|
|
278
|
+
[key: string]: any;
|
|
279
|
+
}
|
|
280
|
+
|
|
275
281
|
declare class Catalog {
|
|
276
282
|
constructor(options: ConstructorClientOptions);
|
|
277
283
|
|
|
@@ -280,17 +286,17 @@ declare class Catalog {
|
|
|
280
286
|
createOrReplaceItems(
|
|
281
287
|
parameters: CreateOrReplaceItemsParameters,
|
|
282
288
|
networkParameters?: NetworkParameters
|
|
283
|
-
): Promise<
|
|
289
|
+
): Promise<CatalogMutationResponse>;
|
|
284
290
|
|
|
285
291
|
updateItems(
|
|
286
292
|
parameters: UpdateItemsParameters,
|
|
287
293
|
networkParameters?: NetworkParameters
|
|
288
|
-
): Promise<
|
|
294
|
+
): Promise<CatalogMutationResponse>;
|
|
289
295
|
|
|
290
296
|
deleteItems(
|
|
291
297
|
parameters: DeleteItemsParameters,
|
|
292
298
|
networkParameters?: NetworkParameters
|
|
293
|
-
): Promise<
|
|
299
|
+
): Promise<CatalogMutationResponse>;
|
|
294
300
|
|
|
295
301
|
retrieveItems(
|
|
296
302
|
parameters: RetrieveItemsParameters,
|
|
@@ -300,17 +306,17 @@ declare class Catalog {
|
|
|
300
306
|
createOrReplaceVariations(
|
|
301
307
|
parameters: CreateOrReplaceVariationsParameters,
|
|
302
308
|
networkParameters?: NetworkParameters
|
|
303
|
-
): Promise<
|
|
309
|
+
): Promise<CatalogMutationResponse>;
|
|
304
310
|
|
|
305
311
|
updateVariations(
|
|
306
312
|
parameters: UpdateVariationsParameters,
|
|
307
313
|
networkParameters?: NetworkParameters
|
|
308
|
-
): Promise<
|
|
314
|
+
): Promise<CatalogMutationResponse>;
|
|
309
315
|
|
|
310
316
|
deleteVariations(
|
|
311
317
|
parameters: DeleteVariationsParameters,
|
|
312
318
|
networkParameters?: NetworkParameters
|
|
313
|
-
): Promise<
|
|
319
|
+
): Promise<CatalogMutationResponse>;
|
|
314
320
|
|
|
315
321
|
retrieveVariations(
|
|
316
322
|
parameters: RetrieveVariationsParameters,
|
|
@@ -479,56 +485,32 @@ declare class Catalog {
|
|
|
479
485
|
replaceCatalog(
|
|
480
486
|
parameters: ReplaceCatalogParameters,
|
|
481
487
|
networkParameters?: NetworkParameters
|
|
482
|
-
): Promise<
|
|
483
|
-
task_id: string;
|
|
484
|
-
task_status_path: string;
|
|
485
|
-
[key: string]: any;
|
|
486
|
-
}>;
|
|
488
|
+
): Promise<CatalogMutationResponse>;
|
|
487
489
|
|
|
488
490
|
updateCatalog(
|
|
489
491
|
parameters: UpdateCatalogParameters,
|
|
490
492
|
networkParameters?: NetworkParameters
|
|
491
|
-
): Promise<
|
|
492
|
-
task_id: string;
|
|
493
|
-
task_status_path: string;
|
|
494
|
-
[key: string]: any;
|
|
495
|
-
}>;
|
|
493
|
+
): Promise<CatalogMutationResponse>;
|
|
496
494
|
|
|
497
495
|
patchCatalog(
|
|
498
496
|
parameters: PatchCatalogParameters,
|
|
499
497
|
networkParameters?: NetworkParameters
|
|
500
|
-
): Promise<
|
|
501
|
-
task_id: string;
|
|
502
|
-
task_status_path: string;
|
|
503
|
-
[key: string]: any;
|
|
504
|
-
}>;
|
|
498
|
+
): Promise<CatalogMutationResponse>;
|
|
505
499
|
|
|
506
500
|
replaceCatalogUsingTarArchive(
|
|
507
501
|
parameters: ReplaceCatalogUsingTarArchiveParameters,
|
|
508
502
|
networkParameters?: NetworkParameters
|
|
509
|
-
): Promise<
|
|
510
|
-
task_id: string;
|
|
511
|
-
task_status_path: string;
|
|
512
|
-
[key: string]: any;
|
|
513
|
-
}>;
|
|
503
|
+
): Promise<CatalogMutationResponse>;
|
|
514
504
|
|
|
515
505
|
updateCatalogUsingTarArchive(
|
|
516
506
|
parameters: UpdateCatalogUsingTarArchiveParameters,
|
|
517
507
|
networkParameters?: NetworkParameters
|
|
518
|
-
): Promise<
|
|
519
|
-
task_id: string;
|
|
520
|
-
task_status_path: string;
|
|
521
|
-
[key: string]: any;
|
|
522
|
-
}>;
|
|
508
|
+
): Promise<CatalogMutationResponse>;
|
|
523
509
|
|
|
524
510
|
patchCatalogUsingTarArchive(
|
|
525
511
|
parameters: PatchCatalogUsingTarArchiveParameters,
|
|
526
512
|
networkParameters?: NetworkParameters
|
|
527
|
-
): Promise<
|
|
528
|
-
task_id: string;
|
|
529
|
-
task_status_path: string;
|
|
530
|
-
[key: string]: any;
|
|
531
|
-
}>;
|
|
513
|
+
): Promise<CatalogMutationResponse>;
|
|
532
514
|
|
|
533
515
|
addFacetConfiguration(
|
|
534
516
|
parameters: FacetConfiguration,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ConstructorClientOptions, NetworkParameters, UserParameters, VariationsMap } from '.';
|
|
1
|
+
import { ConstructorClientOptions, NetworkParameters, UserParameters, VariationsMap, FilterExpression } from '.';
|
|
2
2
|
|
|
3
3
|
export default Recommendations;
|
|
4
4
|
|
|
5
5
|
export interface RecommendationsParameters {
|
|
6
6
|
itemIds?: string | string[];
|
|
7
|
+
variationId?: string;
|
|
7
8
|
numResults?: number;
|
|
8
9
|
section?: string;
|
|
9
10
|
term?: string;
|
|
@@ -39,7 +40,8 @@ export interface RecommendationsResponse extends Record<string, any> {
|
|
|
39
40
|
|
|
40
41
|
export interface RecommendationsRequestType extends Record<string, any> {
|
|
41
42
|
num_results: number;
|
|
42
|
-
item_id: string;
|
|
43
|
+
item_id: string | string[];
|
|
44
|
+
variation_id: string;
|
|
43
45
|
filters: {
|
|
44
46
|
group_id: string;
|
|
45
47
|
[key: string]: any;
|