@constructor-io/constructorio-node 4.4.7 → 4.5.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 +177 -129
- package/src/modules/tracker.js +311 -251
- package/src/utils/helpers.js +13 -0
package/src/modules/catalog.js
CHANGED
|
@@ -6,6 +6,7 @@ const FormData = require('form-data');
|
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const { Duplex } = require('stream');
|
|
8
8
|
const helpers = require('../utils/helpers');
|
|
9
|
+
const { toSnakeCaseKeys } = require('../utils/helpers');
|
|
9
10
|
|
|
10
11
|
// Create URL from supplied path and options
|
|
11
12
|
function createCatalogUrl(path, options, additionalQueryParams = {}, apiVersion = 'v1') {
|
|
@@ -24,6 +25,7 @@ function createCatalogUrl(path, options, additionalQueryParams = {}, apiVersion
|
|
|
24
25
|
|
|
25
26
|
queryParams.key = apiKey;
|
|
26
27
|
queryParams = helpers.cleanParams(queryParams);
|
|
28
|
+
queryParams = toSnakeCaseKeys(queryParams);
|
|
27
29
|
|
|
28
30
|
const queryString = qs.stringify(queryParams, { indices: false });
|
|
29
31
|
|
|
@@ -55,8 +57,8 @@ async function createQueryParamsAndFormData(parameters) {
|
|
|
55
57
|
const formData = new FormData();
|
|
56
58
|
|
|
57
59
|
if (parameters) {
|
|
58
|
-
const { section, notificationEmail, force, onMissing } = parameters;
|
|
59
|
-
let { items, variations, item_groups
|
|
60
|
+
const { section, notification_email, notificationEmail = notification_email, force, item_groups, onMissing } = parameters;
|
|
61
|
+
let { items, variations, itemGroups = item_groups } = parameters;
|
|
60
62
|
|
|
61
63
|
try {
|
|
62
64
|
// Convert items to buffer if passed as stream
|
|
@@ -211,7 +213,7 @@ class Catalog {
|
|
|
211
213
|
const { fetch } = this.options;
|
|
212
214
|
const controller = new AbortController();
|
|
213
215
|
const { signal } = controller;
|
|
214
|
-
const { items, section, force, notificationEmail } = parameters;
|
|
216
|
+
const { items, section, force, notification_email, notificationEmail = notification_email } = parameters;
|
|
215
217
|
const queryParams = {};
|
|
216
218
|
|
|
217
219
|
// Validate items is provided
|
|
@@ -293,7 +295,7 @@ class Catalog {
|
|
|
293
295
|
const { fetch } = this.options;
|
|
294
296
|
const controller = new AbortController();
|
|
295
297
|
const { signal } = controller;
|
|
296
|
-
const { items, section, force, notificationEmail } = parameters;
|
|
298
|
+
const { items, section, force, notification_email, notificationEmail = notification_email } = parameters;
|
|
297
299
|
const queryParams = {};
|
|
298
300
|
|
|
299
301
|
// Validate items is provided
|
|
@@ -365,7 +367,7 @@ class Catalog {
|
|
|
365
367
|
const { fetch } = this.options;
|
|
366
368
|
const controller = new AbortController();
|
|
367
369
|
const { signal } = controller;
|
|
368
|
-
const { items, section, force, notificationEmail } = parameters;
|
|
370
|
+
const { items, section, force, notification_email, notificationEmail = notification_email } = parameters;
|
|
369
371
|
const queryParams = {};
|
|
370
372
|
|
|
371
373
|
// Validate items is provided
|
|
@@ -524,7 +526,7 @@ class Catalog {
|
|
|
524
526
|
const { fetch } = this.options;
|
|
525
527
|
const controller = new AbortController();
|
|
526
528
|
const { signal } = controller;
|
|
527
|
-
const { section, force, notificationEmail, variations } = parameters;
|
|
529
|
+
const { section, force, notification_email, notificationEmail = notification_email, variations } = parameters;
|
|
528
530
|
const queryParams = {};
|
|
529
531
|
|
|
530
532
|
// Validate variations are provided
|
|
@@ -607,7 +609,7 @@ class Catalog {
|
|
|
607
609
|
const { fetch } = this.options;
|
|
608
610
|
const controller = new AbortController();
|
|
609
611
|
const { signal } = controller;
|
|
610
|
-
const { section, force, notificationEmail, variations } = parameters;
|
|
612
|
+
const { section, force, notification_email, notificationEmail = notification_email, variations } = parameters;
|
|
611
613
|
const queryParams = {};
|
|
612
614
|
|
|
613
615
|
// Validate variations are provided
|
|
@@ -680,7 +682,7 @@ class Catalog {
|
|
|
680
682
|
const { fetch } = this.options;
|
|
681
683
|
const controller = new AbortController();
|
|
682
684
|
const { signal } = controller;
|
|
683
|
-
const { section, force, notificationEmail, variations } = parameters;
|
|
685
|
+
const { section, force, notification_email, notificationEmail = notification_email, variations } = parameters;
|
|
684
686
|
const queryParams = {};
|
|
685
687
|
|
|
686
688
|
// Validate variations are provided
|
|
@@ -816,7 +818,7 @@ class Catalog {
|
|
|
816
818
|
* @param {object} parameters - Additional parameters for item group details
|
|
817
819
|
* @param {string} parameters.id - Item group ID
|
|
818
820
|
* @param {string} parameters.name - Item group name
|
|
819
|
-
* @param {string} [parameters.
|
|
821
|
+
* @param {string} [parameters.parentId] - Item group parent ID
|
|
820
822
|
* @param {object} [parameters.data] - JSON object with custom metadata attached with the item group
|
|
821
823
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
822
824
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -826,7 +828,7 @@ class Catalog {
|
|
|
826
828
|
* constructorio.catalog.addItemGroup({
|
|
827
829
|
* id: 'subcat_12891',
|
|
828
830
|
* name: 'Hoodies & Sweaters',
|
|
829
|
-
*
|
|
831
|
+
* parentId: 'cat_49203',
|
|
830
832
|
* });
|
|
831
833
|
*/
|
|
832
834
|
addItemGroup(parameters = {}, networkParameters = {}) {
|
|
@@ -847,7 +849,7 @@ class Catalog {
|
|
|
847
849
|
|
|
848
850
|
return fetch(requestUrl, {
|
|
849
851
|
method: 'PUT',
|
|
850
|
-
body: JSON.stringify(rest),
|
|
852
|
+
body: JSON.stringify(toSnakeCaseKeys(rest, false)),
|
|
851
853
|
headers: {
|
|
852
854
|
'Content-Type': 'application/json',
|
|
853
855
|
...helpers.createAuthHeader(this.options),
|
|
@@ -867,18 +869,18 @@ class Catalog {
|
|
|
867
869
|
*
|
|
868
870
|
* @function addItemGroups
|
|
869
871
|
* @param {object} parameters - Additional parameters for item group details
|
|
870
|
-
* @param {object[]} parameters.
|
|
872
|
+
* @param {object[]} parameters.itemGroups - A list of item groups
|
|
871
873
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
872
874
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
873
875
|
* @returns {Promise}
|
|
874
876
|
* @see https://docs.constructor.io/rest_api/item_groups
|
|
875
877
|
* @example
|
|
876
878
|
* constructorio.catalog.addItemGroups({
|
|
877
|
-
*
|
|
879
|
+
* itemGroups: [
|
|
878
880
|
* {
|
|
879
881
|
* id: 'subcat_12891',
|
|
880
882
|
* name: 'Hoodies & Sweaters',
|
|
881
|
-
*
|
|
883
|
+
* parentId: 'cat_49203',
|
|
882
884
|
* },
|
|
883
885
|
* {
|
|
884
886
|
* id: 'cat49203',
|
|
@@ -893,6 +895,11 @@ class Catalog {
|
|
|
893
895
|
const controller = new AbortController();
|
|
894
896
|
const { signal } = controller;
|
|
895
897
|
|
|
898
|
+
// Backwards Compatibility
|
|
899
|
+
const { item_groups, itemGroups = item_groups, ...rest } = parameters;
|
|
900
|
+
const params = { itemGroups, ...rest };
|
|
901
|
+
params.itemGroups = params.itemGroups.map((itemGroup) => toSnakeCaseKeys(itemGroup, false));
|
|
902
|
+
|
|
896
903
|
try {
|
|
897
904
|
requestUrl = createCatalogUrl('item_groups', this.options);
|
|
898
905
|
} catch (e) {
|
|
@@ -904,7 +911,7 @@ class Catalog {
|
|
|
904
911
|
|
|
905
912
|
return fetch(requestUrl, {
|
|
906
913
|
method: 'POST',
|
|
907
|
-
body: JSON.stringify(
|
|
914
|
+
body: JSON.stringify(toSnakeCaseKeys(params, false)),
|
|
908
915
|
headers: {
|
|
909
916
|
'Content-Type': 'application/json',
|
|
910
917
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1012,18 +1019,18 @@ class Catalog {
|
|
|
1012
1019
|
*
|
|
1013
1020
|
* @function addOrUpdateItemGroups
|
|
1014
1021
|
* @param {object} parameters - Additional parameters for item group details
|
|
1015
|
-
* @param {object[]} parameters.
|
|
1022
|
+
* @param {object[]} parameters.itemGroups - A list of item groups
|
|
1016
1023
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1017
1024
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1018
1025
|
* @returns {Promise}
|
|
1019
1026
|
* @see https://docs.constructor.io/rest_api/item_groups
|
|
1020
1027
|
* @example
|
|
1021
1028
|
* constructorio.catalog.addOrUpdateItemGroups({
|
|
1022
|
-
*
|
|
1029
|
+
* itemGroups: [
|
|
1023
1030
|
* {
|
|
1024
1031
|
* id: 'subcat_12891',
|
|
1025
1032
|
* name: 'Hoodies, Sweaters, & Jackets',
|
|
1026
|
-
*
|
|
1033
|
+
* parentId: 'cat_49203',
|
|
1027
1034
|
* },
|
|
1028
1035
|
* {
|
|
1029
1036
|
* id: 'cat49203',
|
|
@@ -1038,6 +1045,10 @@ class Catalog {
|
|
|
1038
1045
|
const controller = new AbortController();
|
|
1039
1046
|
const { signal } = controller;
|
|
1040
1047
|
|
|
1048
|
+
// Backwards Compatibility
|
|
1049
|
+
const { item_groups, itemGroups = item_groups, ...rest } = parameters;
|
|
1050
|
+
const params = { itemGroups, ...rest };
|
|
1051
|
+
params.itemGroups = params.itemGroups.map((config) => toSnakeCaseKeys(config));
|
|
1041
1052
|
try {
|
|
1042
1053
|
requestUrl = createCatalogUrl('item_groups', this.options);
|
|
1043
1054
|
} catch (e) {
|
|
@@ -1049,7 +1060,7 @@ class Catalog {
|
|
|
1049
1060
|
|
|
1050
1061
|
return fetch(requestUrl, {
|
|
1051
1062
|
method: 'PATCH',
|
|
1052
|
-
body: JSON.stringify(
|
|
1063
|
+
body: JSON.stringify(toSnakeCaseKeys(params)),
|
|
1053
1064
|
headers: {
|
|
1054
1065
|
'Content-Type': 'application/json',
|
|
1055
1066
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1071,7 +1082,7 @@ class Catalog {
|
|
|
1071
1082
|
* @param {object} parameters - Additional parameters for item group details
|
|
1072
1083
|
* @param {string} parameters.id - The group ID to update
|
|
1073
1084
|
* @param {string} [parameters.name] - Item group display name
|
|
1074
|
-
* @param {string} [parameters.
|
|
1085
|
+
* @param {string} [parameters.parentId] - Parent item group customer ID or null for root item groups
|
|
1075
1086
|
* @param {object} [parameters.data] - JSON object with custom metadata attached with the item group
|
|
1076
1087
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1077
1088
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1081,7 +1092,7 @@ class Catalog {
|
|
|
1081
1092
|
* constructorio.catalog.modifyItemGroup({
|
|
1082
1093
|
* id: 'subcat_12891',
|
|
1083
1094
|
* name: 'Hoodies, Sweaters & Jackets',
|
|
1084
|
-
*
|
|
1095
|
+
* parentId: 'cat_49203',
|
|
1085
1096
|
* data: {
|
|
1086
1097
|
* landing_image_url: '/images/hd_swtrs_jckts.jpg',
|
|
1087
1098
|
* },
|
|
@@ -1105,7 +1116,7 @@ class Catalog {
|
|
|
1105
1116
|
|
|
1106
1117
|
return fetch(requestUrl, {
|
|
1107
1118
|
method: 'PUT',
|
|
1108
|
-
body: JSON.stringify(rest),
|
|
1119
|
+
body: JSON.stringify(toSnakeCaseKeys(rest)),
|
|
1109
1120
|
headers: {
|
|
1110
1121
|
'Content-Type': 'application/json',
|
|
1111
1122
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1165,7 +1176,7 @@ class Catalog {
|
|
|
1165
1176
|
* @function addOneWaySynonym
|
|
1166
1177
|
* @param {object} parameters - Additional parameters for synonym details
|
|
1167
1178
|
* @param {string} parameters.phrase - Parent phrase
|
|
1168
|
-
* @param {string[]} parameters.
|
|
1179
|
+
* @param {string[]} parameters.childPhrases - Array of synonyms
|
|
1169
1180
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1170
1181
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1171
1182
|
* @returns {Promise}
|
|
@@ -1173,7 +1184,7 @@ class Catalog {
|
|
|
1173
1184
|
* @example
|
|
1174
1185
|
* constructorio.catalog.addOneWaySynonym({
|
|
1175
1186
|
* phrase: 'spices',
|
|
1176
|
-
*
|
|
1187
|
+
* childPhrases: [
|
|
1177
1188
|
* { phrase: 'pepper' },
|
|
1178
1189
|
* { phrase: 'cinnamon' },
|
|
1179
1190
|
* ],
|
|
@@ -1197,7 +1208,7 @@ class Catalog {
|
|
|
1197
1208
|
|
|
1198
1209
|
return fetch(requestUrl, {
|
|
1199
1210
|
method: 'POST',
|
|
1200
|
-
body: JSON.stringify(rest),
|
|
1211
|
+
body: JSON.stringify(toSnakeCaseKeys(rest)),
|
|
1201
1212
|
headers: {
|
|
1202
1213
|
'Content-Type': 'application/json',
|
|
1203
1214
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1218,7 +1229,7 @@ class Catalog {
|
|
|
1218
1229
|
* @function modifyOneWaySynonym
|
|
1219
1230
|
* @param {object} parameters - Additional parameters for synonym details
|
|
1220
1231
|
* @param {string} parameters.phrase - Parent phrase
|
|
1221
|
-
* @param {string[]} parameters.
|
|
1232
|
+
* @param {string[]} parameters.childPhrases - Array of synonyms
|
|
1222
1233
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1223
1234
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1224
1235
|
* @returns {Promise}
|
|
@@ -1226,7 +1237,7 @@ class Catalog {
|
|
|
1226
1237
|
* @example
|
|
1227
1238
|
* constructorio.catalog.modifyOneWaySynonym({
|
|
1228
1239
|
* phrase: 'spices',
|
|
1229
|
-
*
|
|
1240
|
+
* childPhrases: [
|
|
1230
1241
|
* { phrase: 'pepper' },
|
|
1231
1242
|
* { phrase: 'cinnamon' },
|
|
1232
1243
|
* { phrase: 'paprika' },
|
|
@@ -1251,7 +1262,7 @@ class Catalog {
|
|
|
1251
1262
|
|
|
1252
1263
|
return fetch(requestUrl, {
|
|
1253
1264
|
method: 'PUT',
|
|
1254
|
-
body: JSON.stringify(rest),
|
|
1265
|
+
body: JSON.stringify(toSnakeCaseKeys(rest)),
|
|
1255
1266
|
headers: {
|
|
1256
1267
|
'Content-Type': 'application/json',
|
|
1257
1268
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1319,7 +1330,7 @@ class Catalog {
|
|
|
1319
1330
|
*
|
|
1320
1331
|
* @function getOneWaySynonyms
|
|
1321
1332
|
* @param {object} [parameters] - Additional parameters for synonym details
|
|
1322
|
-
* @param {number} [parameters.
|
|
1333
|
+
* @param {number} [parameters.numResultsPerPage] - The number of synonym groups to return. Defaults to 100
|
|
1323
1334
|
* @param {number} [parameters.page] - The page of results to return. Defaults to 1
|
|
1324
1335
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1325
1336
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1327,7 +1338,7 @@ class Catalog {
|
|
|
1327
1338
|
* @see https://docs.constructor.io/rest_api/one_way_synonyms/retrieve_synonyms
|
|
1328
1339
|
* @example
|
|
1329
1340
|
* constructorio.catalog.getOneWaySynonyms({
|
|
1330
|
-
*
|
|
1341
|
+
* numResultsPerPage: 50,
|
|
1331
1342
|
* page: 2,
|
|
1332
1343
|
* });
|
|
1333
1344
|
*/
|
|
@@ -1339,7 +1350,7 @@ class Catalog {
|
|
|
1339
1350
|
const { signal } = controller;
|
|
1340
1351
|
|
|
1341
1352
|
if (parameters) {
|
|
1342
|
-
const { num_results_per_page
|
|
1353
|
+
const { num_results_per_page, numResultsPerPage = num_results_per_page, page } = parameters;
|
|
1343
1354
|
|
|
1344
1355
|
// Pull number of results per page from parameters
|
|
1345
1356
|
if (numResultsPerPage) {
|
|
@@ -1612,7 +1623,7 @@ class Catalog {
|
|
|
1612
1623
|
* @function getSynonymGroups
|
|
1613
1624
|
* @param {object} [parameters] - Additional parameters for synonym group details
|
|
1614
1625
|
* @param {string} [parameters.phrase] - The phrase for which all synonym groups containing it will be returned
|
|
1615
|
-
* @param {number} [parameters.
|
|
1626
|
+
* @param {number} [parameters.numResultsPerPage] - The number of synonym groups to return. Defaults to 100
|
|
1616
1627
|
* @param {number} [parameters.page] - The page of results to return. Defaults to 1
|
|
1617
1628
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1618
1629
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1621,7 +1632,7 @@ class Catalog {
|
|
|
1621
1632
|
* @example
|
|
1622
1633
|
* constructorio.catalog.modifySynonymGroup({
|
|
1623
1634
|
* phrase: '0% milk',
|
|
1624
|
-
*
|
|
1635
|
+
* numResultsPerPage: 50,
|
|
1625
1636
|
* page: 3,
|
|
1626
1637
|
* });
|
|
1627
1638
|
*/
|
|
@@ -1634,7 +1645,7 @@ class Catalog {
|
|
|
1634
1645
|
const { signal } = controller;
|
|
1635
1646
|
|
|
1636
1647
|
if (parameters) {
|
|
1637
|
-
const { num_results_per_page
|
|
1648
|
+
const { num_results_per_page, numResultsPerPage = num_results_per_page, page } = parameters;
|
|
1638
1649
|
|
|
1639
1650
|
// Pull number of results per page from parameters
|
|
1640
1651
|
if (numResultsPerPage) {
|
|
@@ -1759,9 +1770,9 @@ class Catalog {
|
|
|
1759
1770
|
* @param {object} parameters - Additional parameters for redirect rule details
|
|
1760
1771
|
* @param {string} parameters.url - Target URL returned when a match happens
|
|
1761
1772
|
* @param {object[]} parameters.matches - List of match definitions
|
|
1762
|
-
* @param {string} [parameters.
|
|
1763
|
-
* @param {string} [parameters.
|
|
1764
|
-
* @param {string[]} [parameters.
|
|
1773
|
+
* @param {string} [parameters.startTime] - Time at which rule begins to apply (ISO8601 format preferred)
|
|
1774
|
+
* @param {string} [parameters.endTime] - Time at which rule stops to apply (ISO8601 format preferred)
|
|
1775
|
+
* @param {string[]} [parameters.userSegments] - List of user segments
|
|
1765
1776
|
* @param {object} [parameters.metadata] - Object with arbitrary metadata
|
|
1766
1777
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1767
1778
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1772,11 +1783,11 @@ class Catalog {
|
|
|
1772
1783
|
* url: '/categories/cat_49203',
|
|
1773
1784
|
* matches: [{
|
|
1774
1785
|
* pattern: 'outerwear',
|
|
1775
|
-
*
|
|
1786
|
+
* matchType: 'EXACT'
|
|
1776
1787
|
* }],
|
|
1777
|
-
*
|
|
1778
|
-
*
|
|
1779
|
-
*
|
|
1788
|
+
* startTime: '2022-08-11T23:41:02.568Z',
|
|
1789
|
+
* endTime: '2022-08-20T23:41:02.568Z',
|
|
1790
|
+
* userSegments: ['US', 'Mobile'],
|
|
1780
1791
|
* metadata: {
|
|
1781
1792
|
* additional_data: 'additional string data',
|
|
1782
1793
|
* },
|
|
@@ -1787,6 +1798,10 @@ class Catalog {
|
|
|
1787
1798
|
const { fetch } = this.options;
|
|
1788
1799
|
const controller = new AbortController();
|
|
1789
1800
|
const { signal } = controller;
|
|
1801
|
+
let { matches } = parameters;
|
|
1802
|
+
|
|
1803
|
+
matches = matches.map((match) => toSnakeCaseKeys(match, false));
|
|
1804
|
+
const newParameters = { ...parameters, matches };
|
|
1790
1805
|
|
|
1791
1806
|
try {
|
|
1792
1807
|
requestUrl = createCatalogUrl('redirect_rules', this.options);
|
|
@@ -1799,7 +1814,7 @@ class Catalog {
|
|
|
1799
1814
|
|
|
1800
1815
|
return fetch(requestUrl, {
|
|
1801
1816
|
method: 'POST',
|
|
1802
|
-
body: JSON.stringify(
|
|
1817
|
+
body: JSON.stringify(toSnakeCaseKeys(newParameters, false)),
|
|
1803
1818
|
headers: {
|
|
1804
1819
|
'Content-Type': 'application/json',
|
|
1805
1820
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1822,9 +1837,9 @@ class Catalog {
|
|
|
1822
1837
|
* @param {string} parameters.id - Redirect rule ID
|
|
1823
1838
|
* @param {string} parameters.url - Target URL returned when a match happens
|
|
1824
1839
|
* @param {object[]} parameters.matches - List of match definitions
|
|
1825
|
-
* @param {string} [parameters.
|
|
1826
|
-
* @param {string} [parameters.
|
|
1827
|
-
* @param {string[]} [parameters.
|
|
1840
|
+
* @param {string} [parameters.startTime] - Time at which rule begins to apply (ISO8601 format preferred)
|
|
1841
|
+
* @param {string} [parameters.endTime] - Time at which rule stops to apply (ISO8601 format preferred)
|
|
1842
|
+
* @param {string[]} [parameters.userSegments] - List of user segments
|
|
1828
1843
|
* @param {object} [parameters.metadata] - Object with arbitrary metadata
|
|
1829
1844
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1830
1845
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1836,9 +1851,9 @@ class Catalog {
|
|
|
1836
1851
|
* url: '/categories/cat_49203',
|
|
1837
1852
|
* matches: [{
|
|
1838
1853
|
* pattern: 'outerwear',
|
|
1839
|
-
*
|
|
1854
|
+
* matchType: 'EXACT'
|
|
1840
1855
|
* }],
|
|
1841
|
-
*
|
|
1856
|
+
* userSegments: ['US', 'Mobile', 'Web'],
|
|
1842
1857
|
* metadata: {
|
|
1843
1858
|
* additional_data: 'additional string data',
|
|
1844
1859
|
* },
|
|
@@ -1850,6 +1865,10 @@ class Catalog {
|
|
|
1850
1865
|
const controller = new AbortController();
|
|
1851
1866
|
const { signal } = controller;
|
|
1852
1867
|
const { id, ...rest } = parameters;
|
|
1868
|
+
let { matches } = parameters;
|
|
1869
|
+
|
|
1870
|
+
matches = matches.map((match) => toSnakeCaseKeys(match, false));
|
|
1871
|
+
const newParameters = { ...rest, matches };
|
|
1853
1872
|
|
|
1854
1873
|
try {
|
|
1855
1874
|
requestUrl = createCatalogUrl(`redirect_rules/${id}`, this.options);
|
|
@@ -1862,7 +1881,7 @@ class Catalog {
|
|
|
1862
1881
|
|
|
1863
1882
|
return fetch(requestUrl, {
|
|
1864
1883
|
method: 'PUT',
|
|
1865
|
-
body: JSON.stringify(
|
|
1884
|
+
body: JSON.stringify(toSnakeCaseKeys(newParameters, false)),
|
|
1866
1885
|
headers: {
|
|
1867
1886
|
'Content-Type': 'application/json',
|
|
1868
1887
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1885,9 +1904,9 @@ class Catalog {
|
|
|
1885
1904
|
* @param {string} parameters.id - Redirect rule ID
|
|
1886
1905
|
* @param {string} parameters.url - Target URL returned when a match happens
|
|
1887
1906
|
* @param {object[]} parameters.matches - List of match definitions
|
|
1888
|
-
* @param {string} [parameters.
|
|
1889
|
-
* @param {string} [parameters.
|
|
1890
|
-
* @param {string[]} [parameters.
|
|
1907
|
+
* @param {string} [parameters.startTime] - Time at which rule begins to apply (ISO8601 format preferred)
|
|
1908
|
+
* @param {string} [parameters.endTime] - Time at which rule stops to apply (ISO8601 format preferred)
|
|
1909
|
+
* @param {string[]} [parameters.userSegments] - List of user segments
|
|
1891
1910
|
* @param {object} [parameters.metadata] - Object with arbitrary metadata
|
|
1892
1911
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1893
1912
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -1899,9 +1918,9 @@ class Catalog {
|
|
|
1899
1918
|
* url: '/categories/cat_49203',
|
|
1900
1919
|
* matches: [{
|
|
1901
1920
|
* pattern: 'outerwear',
|
|
1902
|
-
*
|
|
1921
|
+
* matchType: 'EXACT'
|
|
1903
1922
|
* }],
|
|
1904
|
-
*
|
|
1923
|
+
* userSegments: ['US', 'Mobile', 'Web'],
|
|
1905
1924
|
* });
|
|
1906
1925
|
*/
|
|
1907
1926
|
modifyRedirectRule(parameters = {}, networkParameters = {}) {
|
|
@@ -1910,6 +1929,10 @@ class Catalog {
|
|
|
1910
1929
|
const controller = new AbortController();
|
|
1911
1930
|
const { signal } = controller;
|
|
1912
1931
|
const { id, ...rest } = parameters;
|
|
1932
|
+
let { matches } = parameters;
|
|
1933
|
+
|
|
1934
|
+
matches = matches.map((match) => toSnakeCaseKeys(match, false));
|
|
1935
|
+
const newParameters = { ...rest, matches };
|
|
1913
1936
|
|
|
1914
1937
|
try {
|
|
1915
1938
|
requestUrl = createCatalogUrl(`redirect_rules/${id}`, this.options);
|
|
@@ -1922,7 +1945,7 @@ class Catalog {
|
|
|
1922
1945
|
|
|
1923
1946
|
return fetch(requestUrl, {
|
|
1924
1947
|
method: 'PATCH',
|
|
1925
|
-
body: JSON.stringify(
|
|
1948
|
+
body: JSON.stringify(toSnakeCaseKeys(newParameters)),
|
|
1926
1949
|
headers: {
|
|
1927
1950
|
'Content-Type': 'application/json',
|
|
1928
1951
|
...helpers.createAuthHeader(this.options),
|
|
@@ -1985,7 +2008,7 @@ class Catalog {
|
|
|
1985
2008
|
*
|
|
1986
2009
|
* @function getRedirectRules
|
|
1987
2010
|
* @param {object} [parameters] - Additional parameters for redirect rule details
|
|
1988
|
-
* @param {number} [parameters.
|
|
2011
|
+
* @param {number} [parameters.numResultsPerPage] - The number of rules to return. Defaults to 20
|
|
1989
2012
|
* @param {number} [parameters.page] - The page of redirect rules to return. Defaults to 1
|
|
1990
2013
|
* @param {string} [parameters.query] - Return redirect rules whose url or match pattern match the provided query
|
|
1991
2014
|
* @param {string} [parameters.status] - One of "current" (return redirect rules that are currently active), "pending" (return redirect rules that will become active in the future), and "expired" (return redirect rules that are not active anymore)
|
|
@@ -1995,7 +2018,7 @@ class Catalog {
|
|
|
1995
2018
|
* @see https://docs.constructor.io/rest_api/redirect_rules
|
|
1996
2019
|
* @example
|
|
1997
2020
|
* constructorio.catalog.getRedirectRules({
|
|
1998
|
-
*
|
|
2021
|
+
* numResultsPerPage: 50,
|
|
1999
2022
|
* page: 2,
|
|
2000
2023
|
* query: 'outerwear',
|
|
2001
2024
|
* status: 'active',
|
|
@@ -2009,7 +2032,7 @@ class Catalog {
|
|
|
2009
2032
|
const { signal } = controller;
|
|
2010
2033
|
|
|
2011
2034
|
if (parameters) {
|
|
2012
|
-
const { num_results_per_page
|
|
2035
|
+
const { num_results_per_page, numResultsPerPage = num_results_per_page, page, query, status } = parameters;
|
|
2013
2036
|
|
|
2014
2037
|
// Pull number of results per page from parameters
|
|
2015
2038
|
if (numResultsPerPage) {
|
|
@@ -2107,7 +2130,7 @@ class Catalog {
|
|
|
2107
2130
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2108
2131
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2109
2132
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
2110
|
-
* @param {file} [parameters.
|
|
2133
|
+
* @param {file} [parameters.itemGroups] - The CSV file with all new itemGroups
|
|
2111
2134
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2112
2135
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2113
2136
|
* @returns {Promise}
|
|
@@ -2115,10 +2138,10 @@ class Catalog {
|
|
|
2115
2138
|
* @example
|
|
2116
2139
|
* constructorio.catalog.replaceCatalog({
|
|
2117
2140
|
* section: 'Products',
|
|
2118
|
-
*
|
|
2141
|
+
* notificationEmail: 'notifications@example.com',
|
|
2119
2142
|
* items: itemsFileBufferOrStream,
|
|
2120
2143
|
* variations: variationsFileBufferOrStream,
|
|
2121
|
-
*
|
|
2144
|
+
* itemGroups: itemGroupsFileBufferOrStream,
|
|
2122
2145
|
* });
|
|
2123
2146
|
*/
|
|
2124
2147
|
async replaceCatalog(parameters = {}, networkParameters = {}) {
|
|
@@ -2159,7 +2182,7 @@ class Catalog {
|
|
|
2159
2182
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2160
2183
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2161
2184
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
2162
|
-
* @param {file} [parameters.
|
|
2185
|
+
* @param {file} [parameters.itemGroups] - The CSV file with all new itemGroups
|
|
2163
2186
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2164
2187
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2165
2188
|
* @returns {Promise}
|
|
@@ -2167,10 +2190,10 @@ class Catalog {
|
|
|
2167
2190
|
* @example
|
|
2168
2191
|
* constructorio.catalog.updateCatalog({
|
|
2169
2192
|
* section: 'Products',
|
|
2170
|
-
*
|
|
2193
|
+
* notificationEmail: 'notifications@example.com',
|
|
2171
2194
|
* items: itemsFileBufferOrStream,
|
|
2172
2195
|
* variations: variationsFileBufferOrStream,
|
|
2173
|
-
*
|
|
2196
|
+
* itemGroups: itemGroupsFileBufferOrStream,
|
|
2174
2197
|
* });
|
|
2175
2198
|
*/
|
|
2176
2199
|
async updateCatalog(parameters = {}, networkParameters = {}) {
|
|
@@ -2212,7 +2235,7 @@ class Catalog {
|
|
|
2212
2235
|
* @param {string} [parameters.onMissing] - Defines the strategy for handling items which are present in the file and missing in the system. IGNORE silently prevents adding them to the system, CREATE creates them, FAIL fails the ingestion in case of their presence. Defaults to FAIL
|
|
2213
2236
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2214
2237
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
2215
|
-
* @param {file} [parameters.
|
|
2238
|
+
* @param {file} [parameters.itemGroups] - The CSV file with all new itemGroups
|
|
2216
2239
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2217
2240
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2218
2241
|
* @returns {Promise}
|
|
@@ -2220,10 +2243,10 @@ class Catalog {
|
|
|
2220
2243
|
* @example
|
|
2221
2244
|
* constructorio.catalog.patchCatalog({
|
|
2222
2245
|
* section: 'Products',
|
|
2223
|
-
*
|
|
2246
|
+
* notificationEmail: 'notifications@example.com',
|
|
2224
2247
|
* items: itemsFileBufferOrStream,
|
|
2225
2248
|
* variations: variationsFileBufferOrStream,
|
|
2226
|
-
*
|
|
2249
|
+
* itemGroups: itemGroupsFileBufferOrStream,
|
|
2227
2250
|
* });
|
|
2228
2251
|
*/
|
|
2229
2252
|
async patchCatalog(parameters = {}, networkParameters = {}) {
|
|
@@ -2270,7 +2293,7 @@ class Catalog {
|
|
|
2270
2293
|
* @example
|
|
2271
2294
|
* constructorio.catalog.replaceCatalogUsingTarArchive({
|
|
2272
2295
|
* section: 'Products',
|
|
2273
|
-
*
|
|
2296
|
+
* notificationEmail: 'notifications@example.com',
|
|
2274
2297
|
* tarArchive: tarArchiveBufferOrStream,
|
|
2275
2298
|
* });
|
|
2276
2299
|
*/
|
|
@@ -2319,7 +2342,7 @@ class Catalog {
|
|
|
2319
2342
|
* @example
|
|
2320
2343
|
* constructorio.catalog.updateCatalogUsingTarArchive({
|
|
2321
2344
|
* section: 'Products',
|
|
2322
|
-
*
|
|
2345
|
+
* notificationEmail: 'notifications@example.com',
|
|
2323
2346
|
* tarArchive: tarArchiveBufferOrStream,
|
|
2324
2347
|
* });
|
|
2325
2348
|
*/
|
|
@@ -2370,7 +2393,7 @@ class Catalog {
|
|
|
2370
2393
|
* @example
|
|
2371
2394
|
* constructorio.catalog.patchCatalogUsingTarArchive({
|
|
2372
2395
|
* section: 'Products',
|
|
2373
|
-
*
|
|
2396
|
+
* notificationEmail: 'notifications@example.com',
|
|
2374
2397
|
* tarArchive: tarArchiveBufferOrStream,
|
|
2375
2398
|
* });
|
|
2376
2399
|
*/
|
|
@@ -2411,15 +2434,15 @@ class Catalog {
|
|
|
2411
2434
|
* @param {object} parameters - Additional parameters for facet configuration details
|
|
2412
2435
|
* @param {string} parameters.name - Unique facet name used to refer to the facet in your catalog
|
|
2413
2436
|
* @param {string} parameters.type - Type of facet. Must be one of multiple or range (numerical).
|
|
2414
|
-
* @param {string} [parameters.
|
|
2415
|
-
* @param {string} [parameters.
|
|
2416
|
-
* @param {boolean} [parameters.
|
|
2417
|
-
* @param {string} [parameters.
|
|
2418
|
-
* @param {string} [parameters.
|
|
2419
|
-
* @param {string} [parameters.
|
|
2420
|
-
* @param {number} [parameters.
|
|
2421
|
-
* @param {
|
|
2422
|
-
* @param {string} [parameters.
|
|
2437
|
+
* @param {string} [parameters.displayName] - The name of the facet presented to the end users. Defaults to null, in which case the name will be presented.
|
|
2438
|
+
* @param {string} [parameters.sortOrder] - Defines the criterion by which the options of this facet group are sorted. Must be one of relevance, value, numMatches. Defaults to relevance. Can be overridden by setting position attribute on facet options.
|
|
2439
|
+
* @param {boolean} [parameters.sortDescending] - Set to true if the options should be sorted in descending order, false to sort ascending. Default value is true if sortOrder is relevance and false for others.
|
|
2440
|
+
* @param {string} [parameters.rangeType] - Specifies how the range buckets are determined. Must be one of dynamic or static. Default value is null. Required if facet type is range and rangeFormat is options.
|
|
2441
|
+
* @param {string} [parameters.rangeFormat] - Determine wether the range facet is configured to displayed as a slider (with min/max values) or as a list of buckets. Must be one of boundaries (for sliders) or options (for buckets).
|
|
2442
|
+
* @param {string} [parameters.rangeInclusive] - Used to create inclusive buckets. Must be one of above (options have no upper bound), below (no lower bound), or null (if range options should not be inclusive).
|
|
2443
|
+
* @param {number} [parameters.bucketSize] - Specifies the size of generated buckets. Default is null. Either this or rangeLimits are required for facet type range, format options, and rangeType static
|
|
2444
|
+
* @param {json} [parameters.rangeLimits] - Defines the cut-off points for generating static range buckets. Should be a list of sorted numbers (i.e. [10, 25, 40]). Default value is null.
|
|
2445
|
+
* @param {string} [parameters.matchType] - Specifies the behavior of filters when multiple options of the same facet group are selected. Must be one of any, all, or none. Default value is any.
|
|
2423
2446
|
* @param {number} [parameters.position] - Slot facet groups to fixed positions. Default value is null.
|
|
2424
2447
|
* @param {boolean} [parameters.hidden] - Specifies whether the facet is hidden from users. Used for non-sensitive data that you don't want to show to end users. Default value is false.
|
|
2425
2448
|
* @param {boolean} [parameters.protected] - Specifies whether the facet is protected from users. Setting to true will require authentication to view the facet. Default value is false.
|
|
@@ -2434,9 +2457,9 @@ class Catalog {
|
|
|
2434
2457
|
* constructorio.catalog.addFacetConfiguration({
|
|
2435
2458
|
* name: 'color',
|
|
2436
2459
|
* type: 'multiple',
|
|
2437
|
-
*
|
|
2438
|
-
*
|
|
2439
|
-
*
|
|
2460
|
+
* displayName: 'Color',
|
|
2461
|
+
* sortOrder: 'value',
|
|
2462
|
+
* sortDescending: false,
|
|
2440
2463
|
* position: 1,
|
|
2441
2464
|
* });
|
|
2442
2465
|
*/
|
|
@@ -2460,7 +2483,7 @@ class Catalog {
|
|
|
2460
2483
|
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
2461
2484
|
return fetch(requestUrl, {
|
|
2462
2485
|
method: 'POST',
|
|
2463
|
-
body: JSON.stringify(rest),
|
|
2486
|
+
body: JSON.stringify(toSnakeCaseKeys(rest)),
|
|
2464
2487
|
headers: {
|
|
2465
2488
|
'Content-Type': 'application/json',
|
|
2466
2489
|
...helpers.createAuthHeader(this.options),
|
|
@@ -2481,7 +2504,7 @@ class Catalog {
|
|
|
2481
2504
|
* @function getFacetConfigurations
|
|
2482
2505
|
* @param {object} parameters - Additional parameters for retrieving facet configurations.
|
|
2483
2506
|
* @param {number} [parameters.page] - Page number you'd like to request. Defaults to 1.
|
|
2484
|
-
* @param {number} [parameters.
|
|
2507
|
+
* @param {number} [parameters.numResultsPerPage] - Number of facets per page in paginated response. Default value is 100.
|
|
2485
2508
|
* @param {string} [parameters.section] - The section in which your facet is defined. Default value is Products.
|
|
2486
2509
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2487
2510
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -2490,7 +2513,7 @@ class Catalog {
|
|
|
2490
2513
|
* @example
|
|
2491
2514
|
* constructorio.catalog.getFacetConfigurations({
|
|
2492
2515
|
* page: 2,
|
|
2493
|
-
*
|
|
2516
|
+
* numResultsPerPage: 50,
|
|
2494
2517
|
* });
|
|
2495
2518
|
*/
|
|
2496
2519
|
getFacetConfigurations(parameters = {}, networkParameters = {}) {
|
|
@@ -2498,10 +2521,19 @@ class Catalog {
|
|
|
2498
2521
|
const { fetch } = this.options;
|
|
2499
2522
|
const controller = new AbortController();
|
|
2500
2523
|
const { signal } = controller;
|
|
2524
|
+
const { num_results_per_page, numResultsPerPage = num_results_per_page, page } = parameters;
|
|
2501
2525
|
const additionalQueryParams = {
|
|
2502
2526
|
section: parameters.section || 'Products',
|
|
2503
2527
|
};
|
|
2504
2528
|
|
|
2529
|
+
if (numResultsPerPage) {
|
|
2530
|
+
additionalQueryParams.num_results_per_page = numResultsPerPage;
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
if (page) {
|
|
2534
|
+
additionalQueryParams.page = page;
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2505
2537
|
try {
|
|
2506
2538
|
requestUrl = createCatalogUrl('facets', this.options, additionalQueryParams);
|
|
2507
2539
|
} catch (e) {
|
|
@@ -2594,9 +2626,9 @@ class Catalog {
|
|
|
2594
2626
|
* {
|
|
2595
2627
|
* name: 'color',
|
|
2596
2628
|
* type: 'multiple',
|
|
2597
|
-
*
|
|
2598
|
-
*
|
|
2599
|
-
*
|
|
2629
|
+
* displayName: 'Color',
|
|
2630
|
+
* sortOrder: 'value',
|
|
2631
|
+
* sortDescending: false,
|
|
2600
2632
|
* position: 1,
|
|
2601
2633
|
* },
|
|
2602
2634
|
* {
|
|
@@ -2611,7 +2643,8 @@ class Catalog {
|
|
|
2611
2643
|
const { fetch } = this.options;
|
|
2612
2644
|
const controller = new AbortController();
|
|
2613
2645
|
const { signal } = controller;
|
|
2614
|
-
const { section, facetConfigurations } = parameters;
|
|
2646
|
+
const { section, facetConfigurations: facetConfigurationsRaw } = parameters;
|
|
2647
|
+
const facetConfigurations = facetConfigurationsRaw.map((config) => toSnakeCaseKeys(config));
|
|
2615
2648
|
const additionalQueryParams = {
|
|
2616
2649
|
section: section || 'Products',
|
|
2617
2650
|
};
|
|
@@ -2651,15 +2684,15 @@ class Catalog {
|
|
|
2651
2684
|
* @param {object} parameters - Additional parameters for facet configuration details
|
|
2652
2685
|
* @param {string} parameters.name - Unique facet name used to refer to the facet in your catalog
|
|
2653
2686
|
* @param {string} parameters.type - Type of facet. Must be one of multiple or range (numerical).
|
|
2654
|
-
* @param {string} [parameters.
|
|
2655
|
-
* @param {string} [parameters.
|
|
2656
|
-
* @param {boolean} [parameters.
|
|
2657
|
-
* @param {string} [parameters.
|
|
2658
|
-
* @param {string} [parameters.
|
|
2659
|
-
* @param {string} [parameters.
|
|
2660
|
-
* @param {number} [parameters.
|
|
2661
|
-
* @param {
|
|
2662
|
-
* @param {string} [parameters.
|
|
2687
|
+
* @param {string} [parameters.displayName] - The name of the facet presented to the end users. Defaults to null, in which case the name will be presented.
|
|
2688
|
+
* @param {string} [parameters.sortOrder] - Defines the criterion by which the options of this facet group are sorted. Must be one of relevance, value, numMatches. Defaults to relevance. Can be overridden by setting position attribute on facet options.
|
|
2689
|
+
* @param {boolean} [parameters.sortDescending] - Set to true if the options should be sorted in descending order, false to sort ascending. Default value is true if sortOrder is relevance and false for others.
|
|
2690
|
+
* @param {string} [parameters.rangeType] - Specifies how the range buckets are determined. Must be one of dynamic or static. Default value is null. Required if facet type is range and rangeFormat is options.
|
|
2691
|
+
* @param {string} [parameters.rangeFormat] - Determine wether the range facet is configured to displayed as a slider (with min/max values) or as a list of buckets. Must be one of boundaries (for sliders) or options (for buckets).
|
|
2692
|
+
* @param {string} [parameters.rangeInclusive] - Used to create inclusive buckets. Must be one of above (options have no upper bound), below (no lower bound), or null (if range options should not be inclusive).
|
|
2693
|
+
* @param {number} [parameters.bucketSize] - Specifies the size of generated buckets. Default is null. Either this or rangeLimits are required for facet type range, format options, and rangeType static
|
|
2694
|
+
* @param {json} [parameters.rangeLimits] - Defines the cut-off points for generating static range buckets. Should be a list of sorted numbers (i.e. [10, 25, 40]). Default value is null.
|
|
2695
|
+
* @param {string} [parameters.matchType] - Specifies the behavior of filters when multiple options of the same facet group are selected. Must be one of any, all, or none. Default value is any.
|
|
2663
2696
|
* @param {number} [parameters.position] - Slot facet groups to fixed positions. Default value is null.
|
|
2664
2697
|
* @param {boolean} [parameters.hidden] - Specifies whether the facet is hidden from users. Used for non-sensitive data that you don't want to show to end users. Default value is false.
|
|
2665
2698
|
* @param {boolean} [parameters.protected] - Specifies whether the facet is protected from users. Setting to true will require authentication to view the facet. Default value is false.
|
|
@@ -2674,9 +2707,9 @@ class Catalog {
|
|
|
2674
2707
|
* constructorio.catalog.replaceFacetConfiguration({
|
|
2675
2708
|
* name: 'color',
|
|
2676
2709
|
* type: 'multiple',
|
|
2677
|
-
*
|
|
2678
|
-
*
|
|
2679
|
-
*
|
|
2710
|
+
* displayName: 'Color',
|
|
2711
|
+
* sortOrder: 'value',
|
|
2712
|
+
* sortDescending: false,
|
|
2680
2713
|
* position: 1,
|
|
2681
2714
|
* });
|
|
2682
2715
|
*/
|
|
@@ -2701,7 +2734,7 @@ class Catalog {
|
|
|
2701
2734
|
|
|
2702
2735
|
return fetch(requestUrl, {
|
|
2703
2736
|
method: 'PUT',
|
|
2704
|
-
body: JSON.stringify({ name, ...rest }),
|
|
2737
|
+
body: JSON.stringify(toSnakeCaseKeys({ name, ...rest })),
|
|
2705
2738
|
headers: {
|
|
2706
2739
|
'Content-Type': 'application/json',
|
|
2707
2740
|
...helpers.createAuthHeader(this.options),
|
|
@@ -2723,15 +2756,15 @@ class Catalog {
|
|
|
2723
2756
|
* @param {object} parameters - Additional parameters for facet configuration details
|
|
2724
2757
|
* @param {string} parameters.name - Unique facet name used to refer to the facet in your catalog
|
|
2725
2758
|
* @param {string} parameters.type - Type of facet. Must be one of multiple or range (numerical).
|
|
2726
|
-
* @param {string} [parameters.
|
|
2727
|
-
* @param {string} [parameters.
|
|
2728
|
-
* @param {boolean} [parameters.
|
|
2729
|
-
* @param {string} [parameters.
|
|
2730
|
-
* @param {string} [parameters.
|
|
2731
|
-
* @param {string} [parameters.
|
|
2732
|
-
* @param {number} [parameters.
|
|
2733
|
-
* @param {
|
|
2734
|
-
* @param {string} [parameters.
|
|
2759
|
+
* @param {string} [parameters.displayName] - The name of the facet presented to the end users. Defaults to null, in which case the name will be presented.
|
|
2760
|
+
* @param {string} [parameters.sortOrder] - Defines the criterion by which the options of this facet group are sorted. Must be one of relevance, value, numMatches. Defaults to relevance. Can be overridden by setting position attribute on facet options.
|
|
2761
|
+
* @param {boolean} [parameters.sortDescending] - Set to true if the options should be sorted in descending order, false to sort ascending. Default value is true if sortOrder is relevance and false for others.
|
|
2762
|
+
* @param {string} [parameters.rangeType] - Specifies how the range buckets are determined. Must be one of dynamic or static. Default value is null. Required if facet type is range and rangeFormat is options.
|
|
2763
|
+
* @param {string} [parameters.rangeFormat] - Determine wether the range facet is configured to displayed as a slider (with min/max values) or as a list of buckets. Must be one of boundaries (for sliders) or options (for buckets).
|
|
2764
|
+
* @param {string} [parameters.rangeInclusive] - Used to create inclusive buckets. Must be one of above (options have no upper bound), below (no lower bound), or null (if range options should not be inclusive).
|
|
2765
|
+
* @param {number} [parameters.bucketSize] - Specifies the size of generated buckets. Default is null. Either this or rangeLimits are required for facet type range, format options, and rangeType static
|
|
2766
|
+
* @param {json} [parameters.rangeLimits] - Defines the cut-off points for generating static range buckets. Should be a list of sorted numbers (i.e. [10, 25, 40]). Default value is null.
|
|
2767
|
+
* @param {string} [parameters.matchType] - Specifies the behavior of filters when multiple options of the same facet group are selected. Must be one of any, all, or none. Default value is any.
|
|
2735
2768
|
* @param {number} [parameters.position] - Slot facet groups to fixed positions. Default value is null.
|
|
2736
2769
|
* @param {boolean} [parameters.hidden] - Specifies whether the facet is hidden from users. Used for non-sensitive data that you don't want to show to end users. Default value is false.
|
|
2737
2770
|
* @param {boolean} [parameters.protected] - Specifies whether the facet is protected from users. Setting to true will require authentication to view the facet. Default value is false.
|
|
@@ -2746,9 +2779,9 @@ class Catalog {
|
|
|
2746
2779
|
* constructorio.catalog.modifyFacetConfiguration({
|
|
2747
2780
|
* name: 'color',
|
|
2748
2781
|
* type: 'multiple',
|
|
2749
|
-
*
|
|
2750
|
-
*
|
|
2751
|
-
*
|
|
2782
|
+
* displayName: 'Color',
|
|
2783
|
+
* sortOrder: 'num_matches',
|
|
2784
|
+
* sortDescending: true,
|
|
2752
2785
|
* position: 1,
|
|
2753
2786
|
* });
|
|
2754
2787
|
*/
|
|
@@ -2773,7 +2806,7 @@ class Catalog {
|
|
|
2773
2806
|
|
|
2774
2807
|
return fetch(requestUrl, {
|
|
2775
2808
|
method: 'PATCH',
|
|
2776
|
-
body: JSON.stringify({ name, ...rest }),
|
|
2809
|
+
body: JSON.stringify(toSnakeCaseKeys({ name, ...rest })),
|
|
2777
2810
|
headers: {
|
|
2778
2811
|
'Content-Type': 'application/json',
|
|
2779
2812
|
...helpers.createAuthHeader(this.options),
|
|
@@ -2847,7 +2880,7 @@ class Catalog {
|
|
|
2847
2880
|
* @param {object} parameters - Additional parameters for facet option configuration details
|
|
2848
2881
|
* @param {string} parameters.facetGroupName - Unique facet name used to refer to the facet in your catalog
|
|
2849
2882
|
* @param {string} parameters.value - A unique value for the facet option
|
|
2850
|
-
* @param {string} [parameters.
|
|
2883
|
+
* @param {string} [parameters.displayName=null] - The name of the facet presented to the end users - if none is supplied, the value from name will be used
|
|
2851
2884
|
* @param {number} [parameters.position=null] - Slot facet groups to fixed positions
|
|
2852
2885
|
* @param {boolean} [parameters.hidden=false] - Specifies whether the facet option is hidden from users
|
|
2853
2886
|
* @param {object} [parameters.data={}] - Dictionary/Object with any extra facet data
|
|
@@ -2860,7 +2893,7 @@ class Catalog {
|
|
|
2860
2893
|
* constructorio.catalog.addFacetOptionConfiguration({
|
|
2861
2894
|
* facetGroupName: 'color',
|
|
2862
2895
|
* value: 'blue',
|
|
2863
|
-
*
|
|
2896
|
+
* displayName: 'Blue',
|
|
2864
2897
|
* position: 5,
|
|
2865
2898
|
* });
|
|
2866
2899
|
*/
|
|
@@ -2885,7 +2918,7 @@ class Catalog {
|
|
|
2885
2918
|
|
|
2886
2919
|
return fetch(requestUrl, {
|
|
2887
2920
|
method: 'POST',
|
|
2888
|
-
body: JSON.stringify(rest),
|
|
2921
|
+
body: JSON.stringify(toSnakeCaseKeys(rest)),
|
|
2889
2922
|
headers: {
|
|
2890
2923
|
'Content-Type': 'application/json',
|
|
2891
2924
|
...helpers.createAuthHeader(this.options),
|
|
@@ -2918,12 +2951,12 @@ class Catalog {
|
|
|
2918
2951
|
* facetOptionConfigurations: [
|
|
2919
2952
|
* {
|
|
2920
2953
|
* value: 'blue',
|
|
2921
|
-
*
|
|
2954
|
+
* displayName: 'Blue',
|
|
2922
2955
|
* position: 5,
|
|
2923
2956
|
* },
|
|
2924
2957
|
* {
|
|
2925
2958
|
* value: 'red',
|
|
2926
|
-
*
|
|
2959
|
+
* displayName: 'Red',
|
|
2927
2960
|
* position: 3,
|
|
2928
2961
|
* },
|
|
2929
2962
|
* ],
|
|
@@ -2934,7 +2967,8 @@ class Catalog {
|
|
|
2934
2967
|
const { fetch } = this.options;
|
|
2935
2968
|
const controller = new AbortController();
|
|
2936
2969
|
const { signal } = controller;
|
|
2937
|
-
const { facetGroupName, section, facetOptionConfigurations } = parameters;
|
|
2970
|
+
const { facetGroupName, section, facetOptionConfigurations: facetOptionConfigurationsRaw } = parameters;
|
|
2971
|
+
const facetOptionConfigurations = facetOptionConfigurationsRaw.map((config) => toSnakeCaseKeys(config));
|
|
2938
2972
|
const additionalQueryParams = {
|
|
2939
2973
|
section: section || 'Products',
|
|
2940
2974
|
};
|
|
@@ -2972,7 +3006,7 @@ class Catalog {
|
|
|
2972
3006
|
* @param {object} parameters - Additional parameters for facet option configuration details
|
|
2973
3007
|
* @param {string} parameters.facetGroupName - Unique facet name used to refer to the facet in your catalog
|
|
2974
3008
|
* @param {number} [parameters.page=1] - Page number you'd like to request
|
|
2975
|
-
* @param {number} [parameters.
|
|
3009
|
+
* @param {number} [parameters.numResultsPerPage=100] - Number of facets per page in paginated response
|
|
2976
3010
|
* @param {string} [parameters.section='Products'] - The section in which your facet is defined
|
|
2977
3011
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2978
3012
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -2982,7 +3016,7 @@ class Catalog {
|
|
|
2982
3016
|
* constructorio.catalog.getFacetOptionConfigurations({
|
|
2983
3017
|
* facetGroupName: 'color',
|
|
2984
3018
|
* page: 3,
|
|
2985
|
-
*
|
|
3019
|
+
* numResultsPerPage: 50
|
|
2986
3020
|
* });
|
|
2987
3021
|
*/
|
|
2988
3022
|
getFacetOptionConfigurations(parameters = {}, networkParameters = {}) {
|
|
@@ -2990,11 +3024,25 @@ class Catalog {
|
|
|
2990
3024
|
const { fetch } = this.options;
|
|
2991
3025
|
const controller = new AbortController();
|
|
2992
3026
|
const { signal } = controller;
|
|
2993
|
-
const {
|
|
3027
|
+
const {
|
|
3028
|
+
facetGroupName,
|
|
3029
|
+
section,
|
|
3030
|
+
num_results_per_page,
|
|
3031
|
+
numResultsPerPage = num_results_per_page,
|
|
3032
|
+
page,
|
|
3033
|
+
} = parameters;
|
|
2994
3034
|
const additionalQueryParams = {
|
|
2995
3035
|
section: section || 'Products',
|
|
2996
3036
|
};
|
|
2997
3037
|
|
|
3038
|
+
if (numResultsPerPage) {
|
|
3039
|
+
additionalQueryParams.num_results_per_page = numResultsPerPage;
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
if (page) {
|
|
3043
|
+
additionalQueryParams.page = page;
|
|
3044
|
+
}
|
|
3045
|
+
|
|
2998
3046
|
try {
|
|
2999
3047
|
requestUrl = createCatalogUrl(`facets/${facetGroupName}/options`, this.options, additionalQueryParams);
|
|
3000
3048
|
} catch (e) {
|
|
@@ -3080,7 +3128,7 @@ class Catalog {
|
|
|
3080
3128
|
* @param {object} parameters - Additional parameters for facet option configuration details
|
|
3081
3129
|
* @param {string} parameters.facetGroupName - Unique facet name used to refer to the facet in your catalog
|
|
3082
3130
|
* @param {string} parameters.value - A unique facet option value
|
|
3083
|
-
* @param {string} [parameters.
|
|
3131
|
+
* @param {string} [parameters.displayName=null] - The name of the facet presented to the end users - if none is supplied, the value from name will be used
|
|
3084
3132
|
* @param {number} [parameters.position=null] - Slot facet groups to fixed positions
|
|
3085
3133
|
* @param {boolean} [parameters.hidden=false] - Specifies whether the facet option is hidden from users
|
|
3086
3134
|
* @param {object} [parameters.data={}] - Dictionary/Object with any extra facet data
|
|
@@ -3093,7 +3141,7 @@ class Catalog {
|
|
|
3093
3141
|
* constructorio.catalog.replaceFacetOptionConfiguration({
|
|
3094
3142
|
* facetGroupName: 'color',
|
|
3095
3143
|
* value: 'blue',
|
|
3096
|
-
*
|
|
3144
|
+
* displayName: 'Midnight Blue',
|
|
3097
3145
|
* position: 9,
|
|
3098
3146
|
* });
|
|
3099
3147
|
*/
|
|
@@ -3118,7 +3166,7 @@ class Catalog {
|
|
|
3118
3166
|
|
|
3119
3167
|
return fetch(requestUrl, {
|
|
3120
3168
|
method: 'PUT',
|
|
3121
|
-
body: JSON.stringify({ value, ...rest }),
|
|
3169
|
+
body: JSON.stringify(toSnakeCaseKeys({ value, ...rest })),
|
|
3122
3170
|
headers: {
|
|
3123
3171
|
'Content-Type': 'application/json',
|
|
3124
3172
|
...helpers.createAuthHeader(this.options),
|
|
@@ -3140,7 +3188,7 @@ class Catalog {
|
|
|
3140
3188
|
* @param {object} parameters - Additional parameters for facet option configuration details
|
|
3141
3189
|
* @param {string} parameters.facetGroupName - Unique facet name used to refer to the facet in your catalog
|
|
3142
3190
|
* @param {string} parameters.value - A unique facet option value
|
|
3143
|
-
* @param {string} [parameters.
|
|
3191
|
+
* @param {string} [parameters.displayName=null] - The name of the facet presented to the end users - if none is supplied, the value from name will be used
|
|
3144
3192
|
* @param {number} [parameters.position=null] - Slot facet groups to fixed positions
|
|
3145
3193
|
* @param {boolean} [parameters.hidden=false] - Specifies whether the facet option is hidden from users
|
|
3146
3194
|
* @param {object} [parameters.data={}] - Dictionary/Object with any extra facet data
|
|
@@ -3153,7 +3201,7 @@ class Catalog {
|
|
|
3153
3201
|
* constructorio.catalog.modifyFacetOptionConfiguration({
|
|
3154
3202
|
* facetGroupName: 'color',
|
|
3155
3203
|
* value: 'blue',
|
|
3156
|
-
*
|
|
3204
|
+
* displayName: 'Midnight Blue',
|
|
3157
3205
|
* position: 9,
|
|
3158
3206
|
* });
|
|
3159
3207
|
*/
|
|
@@ -3178,7 +3226,7 @@ class Catalog {
|
|
|
3178
3226
|
|
|
3179
3227
|
return fetch(requestUrl, {
|
|
3180
3228
|
method: 'PATCH',
|
|
3181
|
-
body: JSON.stringify({ value, ...rest }),
|
|
3229
|
+
body: JSON.stringify(toSnakeCaseKeys({ value, ...rest })),
|
|
3182
3230
|
headers: {
|
|
3183
3231
|
'Content-Type': 'application/json',
|
|
3184
3232
|
...helpers.createAuthHeader(this.options),
|