@constructor-io/constructorio-node 5.4.0 → 5.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 +2 -2
- package/src/modules/catalog.js +373 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-node",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Constructor.io Node.js client",
|
|
5
5
|
"main": "src/constructorio.js",
|
|
6
6
|
"types": "src/types/constructorio.d.ts",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"form-data": "^4.0.0",
|
|
60
60
|
"node-abort-controller": "^3.0.0",
|
|
61
61
|
"node-fetch": "^3.3.2",
|
|
62
|
-
"qs": "6.
|
|
62
|
+
"qs": "6.14.1"
|
|
63
63
|
},
|
|
64
64
|
"tsd": {
|
|
65
65
|
"directory": "src/types/tests"
|
package/src/modules/catalog.js
CHANGED
|
@@ -884,8 +884,13 @@ class Catalog {
|
|
|
884
884
|
* name: 'Hoodies & Sweaters',
|
|
885
885
|
* parentId: 'cat_49203',
|
|
886
886
|
* });
|
|
887
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
888
|
+
* Use [createOrReplaceItemGroups]{@link module:catalog~createOrReplaceItemGroups} instead.
|
|
887
889
|
*/
|
|
888
890
|
addItemGroup(parameters = {}, networkParameters = {}) {
|
|
891
|
+
// eslint-disable-next-line no-console
|
|
892
|
+
console.warn('ConstructorIO: addItemGroup is deprecated and will be removed in the next major version. Use createOrReplaceItemGroups instead.');
|
|
893
|
+
|
|
889
894
|
let requestUrl;
|
|
890
895
|
const { fetch } = this.options;
|
|
891
896
|
const controller = new AbortController();
|
|
@@ -942,8 +947,13 @@ class Catalog {
|
|
|
942
947
|
* },
|
|
943
948
|
* ],
|
|
944
949
|
* });
|
|
950
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
951
|
+
* Use [createOrReplaceItemGroups]{@link module:catalog~createOrReplaceItemGroups} instead.
|
|
945
952
|
*/
|
|
946
953
|
addItemGroups(parameters = {}, networkParameters = {}) {
|
|
954
|
+
// eslint-disable-next-line no-console
|
|
955
|
+
console.warn('ConstructorIO: addItemGroups is deprecated and will be removed in the next major version. Use createOrReplaceItemGroups instead.');
|
|
956
|
+
|
|
947
957
|
let requestUrl;
|
|
948
958
|
const { fetch } = this.options;
|
|
949
959
|
const controller = new AbortController();
|
|
@@ -994,8 +1004,13 @@ class Catalog {
|
|
|
994
1004
|
* constructorio.catalog.getItemGroup({
|
|
995
1005
|
* id: 'subcat_12891',
|
|
996
1006
|
* });
|
|
1007
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
1008
|
+
* Use [retrieveItemGroup]{@link module:catalog~retrieveItemGroup} instead.
|
|
997
1009
|
*/
|
|
998
1010
|
getItemGroup(parameters = {}, networkParameters = {}) {
|
|
1011
|
+
// eslint-disable-next-line no-console
|
|
1012
|
+
console.warn('ConstructorIO: getItemGroup is deprecated and will be removed in the next major version. Use retrieveItemGroup instead.');
|
|
1013
|
+
|
|
999
1014
|
let requestUrl;
|
|
1000
1015
|
const { fetch } = this.options;
|
|
1001
1016
|
const controller = new AbortController();
|
|
@@ -1036,8 +1051,13 @@ class Catalog {
|
|
|
1036
1051
|
* @see https://docs.constructor.com/reference/catalog-item-groups
|
|
1037
1052
|
* @example
|
|
1038
1053
|
* constructorio.catalog.getItemGroups();
|
|
1054
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
1055
|
+
* Use [retrieveItemGroups]{@link module:catalog~retrieveItemGroups} instead.
|
|
1039
1056
|
*/
|
|
1040
1057
|
getItemGroups(networkParameters = {}) {
|
|
1058
|
+
// eslint-disable-next-line no-console
|
|
1059
|
+
console.warn('ConstructorIO: getItemGroups is deprecated and will be removed in the next major version. Use retrieveItemGroups instead.');
|
|
1060
|
+
|
|
1041
1061
|
let requestUrl;
|
|
1042
1062
|
const { fetch } = this.options;
|
|
1043
1063
|
const controller = new AbortController();
|
|
@@ -1092,8 +1112,13 @@ class Catalog {
|
|
|
1092
1112
|
* },
|
|
1093
1113
|
* ],
|
|
1094
1114
|
* });
|
|
1115
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
1116
|
+
* Use [createOrReplaceItemGroups]{@link module:catalog~createOrReplaceItemGroups} or [updateItemGroups]{@link module:catalog~updateItemGroups} instead.
|
|
1095
1117
|
*/
|
|
1096
1118
|
addOrUpdateItemGroups(parameters = {}, networkParameters = {}) {
|
|
1119
|
+
// eslint-disable-next-line no-console
|
|
1120
|
+
console.warn('ConstructorIO: addOrUpdateItemGroups is deprecated and will be removed in the next major version. Use createOrReplaceItemGroups or updateItemGroups instead.');
|
|
1121
|
+
|
|
1097
1122
|
let requestUrl;
|
|
1098
1123
|
const { fetch } = this.options;
|
|
1099
1124
|
const controller = new AbortController();
|
|
@@ -1151,8 +1176,13 @@ class Catalog {
|
|
|
1151
1176
|
* landing_image_url: '/images/hd_swtrs_jckts.jpg',
|
|
1152
1177
|
* },
|
|
1153
1178
|
* });
|
|
1179
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
1180
|
+
* Use [updateItemGroups]{@link module:catalog~updateItemGroups} instead.
|
|
1154
1181
|
*/
|
|
1155
1182
|
modifyItemGroup(parameters = {}, networkParameters = {}) {
|
|
1183
|
+
// eslint-disable-next-line no-console
|
|
1184
|
+
console.warn('ConstructorIO: modifyItemGroup is deprecated and will be removed in the next major version. Use updateItemGroups instead.');
|
|
1185
|
+
|
|
1156
1186
|
let requestUrl;
|
|
1157
1187
|
const { fetch } = this.options;
|
|
1158
1188
|
const controller = new AbortController();
|
|
@@ -1195,8 +1225,13 @@ class Catalog {
|
|
|
1195
1225
|
* @see https://docs.constructor.com/reference/catalog-item-groups
|
|
1196
1226
|
* @example
|
|
1197
1227
|
* constructorio.catalog.removeItemGroups();
|
|
1228
|
+
* @deprecated This method is deprecated and will be removed in the next major version.
|
|
1229
|
+
* Use [deleteItemGroups]{@link module:catalog~deleteItemGroups} instead.
|
|
1198
1230
|
*/
|
|
1199
1231
|
removeItemGroups(networkParameters = {}) {
|
|
1232
|
+
// eslint-disable-next-line no-console
|
|
1233
|
+
console.warn('ConstructorIO: removeItemGroups is deprecated and will be removed in the next major version. Use deleteItemGroups instead.');
|
|
1234
|
+
|
|
1200
1235
|
let requestUrl;
|
|
1201
1236
|
const { fetch } = this.options;
|
|
1202
1237
|
const controller = new AbortController();
|
|
@@ -1224,6 +1259,344 @@ class Catalog {
|
|
|
1224
1259
|
}).then((json) => json);
|
|
1225
1260
|
}
|
|
1226
1261
|
|
|
1262
|
+
/**
|
|
1263
|
+
* Retrieve all item groups, optionally filtered by ids.
|
|
1264
|
+
*
|
|
1265
|
+
* @function retrieveItemGroups
|
|
1266
|
+
* @param {object} [parameters] - Additional parameters for item group details
|
|
1267
|
+
* @param {string[]} [parameters.ids] - Item group IDs to filter by
|
|
1268
|
+
* @param {number} [parameters.numResultsPerPage=20] - The number of item groups to return (max 100)
|
|
1269
|
+
* @param {number} [parameters.page] - The page of results to return
|
|
1270
|
+
* @param {number} [parameters.offset] - The number of results to skip
|
|
1271
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1272
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1273
|
+
* @returns {Promise}
|
|
1274
|
+
* @see https://docs.constructor.com/reference/v2-item-groups-retrieve-item-groups
|
|
1275
|
+
* @example
|
|
1276
|
+
* constructorio.catalog.retrieveItemGroups();
|
|
1277
|
+
* @example
|
|
1278
|
+
* constructorio.catalog.retrieveItemGroups({
|
|
1279
|
+
* ids: ['group_1', 'group_2'],
|
|
1280
|
+
* numResultsPerPage: 50,
|
|
1281
|
+
* page: 1,
|
|
1282
|
+
* });
|
|
1283
|
+
*/
|
|
1284
|
+
retrieveItemGroups(parameters = {}, networkParameters = {}) {
|
|
1285
|
+
let requestUrl;
|
|
1286
|
+
const { fetch } = this.options;
|
|
1287
|
+
const controller = new AbortController();
|
|
1288
|
+
const { signal } = controller;
|
|
1289
|
+
const { ids, numResultsPerPage, page, offset } = parameters;
|
|
1290
|
+
const queryParams = {};
|
|
1291
|
+
|
|
1292
|
+
if (ids) {
|
|
1293
|
+
queryParams.id = ids;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
if (numResultsPerPage) {
|
|
1297
|
+
queryParams.num_results_per_page = numResultsPerPage;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
if (page && Number.isInteger(page) && page > 0) {
|
|
1301
|
+
queryParams.page = page;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
if (offset && Number.isInteger(offset) && offset > 0) {
|
|
1305
|
+
queryParams.offset = offset;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
try {
|
|
1309
|
+
requestUrl = createCatalogUrl('item_groups', this.options, queryParams, 'v2');
|
|
1310
|
+
} catch (e) {
|
|
1311
|
+
return Promise.reject(e);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// Handle network timeout if specified
|
|
1315
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
1316
|
+
|
|
1317
|
+
return fetch(requestUrl, {
|
|
1318
|
+
method: 'GET',
|
|
1319
|
+
headers: {
|
|
1320
|
+
'Content-Type': 'application/json',
|
|
1321
|
+
...helpers.createAuthHeader(this.options),
|
|
1322
|
+
},
|
|
1323
|
+
signal,
|
|
1324
|
+
}).then((response) => {
|
|
1325
|
+
if (response.ok) {
|
|
1326
|
+
return response.json();
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Retrieve an item group.
|
|
1335
|
+
*
|
|
1336
|
+
* @function retrieveItemGroup
|
|
1337
|
+
* @param {object} parameters - Additional parameters for item group details
|
|
1338
|
+
* @param {string} parameters.id - The item group ID to retrieve
|
|
1339
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1340
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1341
|
+
* @returns {Promise}
|
|
1342
|
+
* @see https://docs.constructor.com/reference/v2-item-groups-retrieve-item-group
|
|
1343
|
+
* @example
|
|
1344
|
+
* constructorio.catalog.retrieveItemGroup({
|
|
1345
|
+
* id: 'group_1',
|
|
1346
|
+
* });
|
|
1347
|
+
*/
|
|
1348
|
+
retrieveItemGroup(parameters = {}, networkParameters = {}) {
|
|
1349
|
+
let requestUrl;
|
|
1350
|
+
const { fetch } = this.options;
|
|
1351
|
+
const controller = new AbortController();
|
|
1352
|
+
const { signal } = controller;
|
|
1353
|
+
const { id } = parameters;
|
|
1354
|
+
|
|
1355
|
+
if (!id) {
|
|
1356
|
+
return Promise.reject(new Error('id is a required parameter'));
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
try {
|
|
1360
|
+
requestUrl = createCatalogUrl(`item_groups/${id}`, this.options, {}, 'v2', false);
|
|
1361
|
+
} catch (e) {
|
|
1362
|
+
return Promise.reject(e);
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// Handle network timeout if specified
|
|
1366
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
1367
|
+
|
|
1368
|
+
return fetch(requestUrl, {
|
|
1369
|
+
method: 'GET',
|
|
1370
|
+
headers: {
|
|
1371
|
+
'Content-Type': 'application/json',
|
|
1372
|
+
...helpers.createAuthHeader(this.options),
|
|
1373
|
+
},
|
|
1374
|
+
signal,
|
|
1375
|
+
}).then((response) => {
|
|
1376
|
+
if (response.ok) {
|
|
1377
|
+
return response.json();
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/**
|
|
1385
|
+
* Create item groups or replace the data of existing item groups. Returns an identifier for a background task.
|
|
1386
|
+
*
|
|
1387
|
+
* @function createOrReplaceItemGroups
|
|
1388
|
+
* @param {object} parameters - Additional parameters for item group details
|
|
1389
|
+
* @param {object[]} parameters.itemGroups - Array of item group objects you want to create or replace.
|
|
1390
|
+
* @param {boolean} [parameters.force=false] - A flag to process the catalog even if it will invalidate a large part of existing data. Defaults to false.
|
|
1391
|
+
* @param {string|string[]} [parameters.notificationEmail] - An email address or array of email addresses to receive an email notification in case the task fails
|
|
1392
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1393
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1394
|
+
* @returns {Promise}
|
|
1395
|
+
* @see https://docs.constructor.com/reference/v2-item-groups-create-or-replace-item-groups
|
|
1396
|
+
* @example
|
|
1397
|
+
* constructorio.catalog.createOrReplaceItemGroups({
|
|
1398
|
+
* itemGroups: [
|
|
1399
|
+
* {
|
|
1400
|
+
* id: 'group_1',
|
|
1401
|
+
* name: 'Shoes',
|
|
1402
|
+
* data: { url: '/shoes' },
|
|
1403
|
+
* parentIds: ['parent_group'],
|
|
1404
|
+
* },
|
|
1405
|
+
* {
|
|
1406
|
+
* id: 'group_2',
|
|
1407
|
+
* name: 'Apparel',
|
|
1408
|
+
* },
|
|
1409
|
+
* ],
|
|
1410
|
+
* });
|
|
1411
|
+
*/
|
|
1412
|
+
async createOrReplaceItemGroups(parameters = {}, networkParameters = {}) {
|
|
1413
|
+
let requestUrl;
|
|
1414
|
+
const { fetch } = this.options;
|
|
1415
|
+
const controller = new AbortController();
|
|
1416
|
+
const { signal } = controller;
|
|
1417
|
+
const { itemGroups, force, notificationEmail } = parameters;
|
|
1418
|
+
const queryParams = {};
|
|
1419
|
+
|
|
1420
|
+
// Validate itemGroups is provided
|
|
1421
|
+
if (!itemGroups || !Array.isArray(itemGroups)) {
|
|
1422
|
+
return Promise.reject(new Error('itemGroups is a required parameter of type array'));
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
if (force) {
|
|
1426
|
+
queryParams.force = force;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
if (notificationEmail) {
|
|
1430
|
+
queryParams.notification_email = notificationEmail;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
try {
|
|
1434
|
+
requestUrl = createCatalogUrl('item_groups', this.options, queryParams, 'v2');
|
|
1435
|
+
} catch (e) {
|
|
1436
|
+
return Promise.reject(e);
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// Handle network timeout if specified
|
|
1440
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
1441
|
+
|
|
1442
|
+
const response = await fetch(requestUrl, {
|
|
1443
|
+
method: 'PUT',
|
|
1444
|
+
body: JSON.stringify({ item_groups: itemGroups.map((itemGroup) => toSnakeCaseKeys(itemGroup, false)) }),
|
|
1445
|
+
headers: {
|
|
1446
|
+
'Content-Type': 'application/json',
|
|
1447
|
+
...helpers.createAuthHeader(this.options),
|
|
1448
|
+
},
|
|
1449
|
+
signal,
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
if (response.ok) {
|
|
1453
|
+
return response.json();
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Update existing item groups data. Data included in the request will be merged with data of the existing item groups.
|
|
1461
|
+
* Returns an identifier for a background task.
|
|
1462
|
+
*
|
|
1463
|
+
* @function updateItemGroups
|
|
1464
|
+
* @param {object} parameters - Additional parameters for item group details
|
|
1465
|
+
* @param {object[]} parameters.itemGroups - Array of item group objects you want to update.
|
|
1466
|
+
* @param {boolean} [parameters.force=false] - A flag to process the catalog even if it will invalidate a large part of existing data. Defaults to false.
|
|
1467
|
+
* @param {string|string[]} [parameters.notificationEmail] - An email address or array of email addresses to receive an email notification in case the task fails
|
|
1468
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1469
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1470
|
+
* @returns {Promise}
|
|
1471
|
+
* @see https://docs.constructor.com/reference/v2-item-groups-update-item-groups
|
|
1472
|
+
* @example
|
|
1473
|
+
* constructorio.catalog.updateItemGroups({
|
|
1474
|
+
* itemGroups: [
|
|
1475
|
+
* {
|
|
1476
|
+
* id: 'group_1',
|
|
1477
|
+
* name: 'Updated Shoes',
|
|
1478
|
+
* },
|
|
1479
|
+
* {
|
|
1480
|
+
* id: 'group_2',
|
|
1481
|
+
* data: { url: '/new-apparel' },
|
|
1482
|
+
* },
|
|
1483
|
+
* ],
|
|
1484
|
+
* });
|
|
1485
|
+
*/
|
|
1486
|
+
async updateItemGroups(parameters = {}, networkParameters = {}) {
|
|
1487
|
+
let requestUrl;
|
|
1488
|
+
const { fetch } = this.options;
|
|
1489
|
+
const controller = new AbortController();
|
|
1490
|
+
const { signal } = controller;
|
|
1491
|
+
const { itemGroups, force, notificationEmail } = parameters;
|
|
1492
|
+
const queryParams = {};
|
|
1493
|
+
|
|
1494
|
+
// Validate itemGroups is provided
|
|
1495
|
+
if (!itemGroups || !Array.isArray(itemGroups)) {
|
|
1496
|
+
return Promise.reject(new Error('itemGroups is a required parameter of type array'));
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
if (force) {
|
|
1500
|
+
queryParams.force = force;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
if (notificationEmail) {
|
|
1504
|
+
queryParams.notification_email = notificationEmail;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
try {
|
|
1508
|
+
requestUrl = createCatalogUrl('item_groups', this.options, queryParams, 'v2');
|
|
1509
|
+
} catch (e) {
|
|
1510
|
+
return Promise.reject(e);
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// Handle network timeout if specified
|
|
1514
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
1515
|
+
|
|
1516
|
+
const response = await fetch(requestUrl, {
|
|
1517
|
+
method: 'PATCH',
|
|
1518
|
+
body: JSON.stringify({ item_groups: itemGroups.map((itemGroup) => toSnakeCaseKeys(itemGroup, false)) }),
|
|
1519
|
+
headers: {
|
|
1520
|
+
'Content-Type': 'application/json',
|
|
1521
|
+
...helpers.createAuthHeader(this.options),
|
|
1522
|
+
},
|
|
1523
|
+
signal,
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
if (response.ok) {
|
|
1527
|
+
return response.json();
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* Delete item groups. Returns an identifier for a background task.
|
|
1535
|
+
*
|
|
1536
|
+
* @function deleteItemGroups
|
|
1537
|
+
* @param {object} parameters - Additional parameters for item group details
|
|
1538
|
+
* @param {object[]} parameters.itemGroups - Array of item group objects with id to delete
|
|
1539
|
+
* @param {boolean} [parameters.force=false] - A flag to process the catalog even if it will invalidate a large part of existing data. Defaults to false.
|
|
1540
|
+
* @param {string|string[]} [parameters.notificationEmail] - An email address or array of email addresses to receive an email notification in case the task fails
|
|
1541
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1542
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1543
|
+
* @returns {Promise}
|
|
1544
|
+
* @see https://docs.constructor.com/reference/v2-item-groups-delete-item-groups
|
|
1545
|
+
* @example
|
|
1546
|
+
* constructorio.catalog.deleteItemGroups({
|
|
1547
|
+
* itemGroups: [
|
|
1548
|
+
* { id: 'group_1' },
|
|
1549
|
+
* { id: 'group_2' },
|
|
1550
|
+
* ],
|
|
1551
|
+
* });
|
|
1552
|
+
*/
|
|
1553
|
+
async deleteItemGroups(parameters = {}, networkParameters = {}) {
|
|
1554
|
+
let requestUrl;
|
|
1555
|
+
const { fetch } = this.options;
|
|
1556
|
+
const controller = new AbortController();
|
|
1557
|
+
const { signal } = controller;
|
|
1558
|
+
const { itemGroups, force, notificationEmail } = parameters;
|
|
1559
|
+
const queryParams = {};
|
|
1560
|
+
|
|
1561
|
+
// Validate itemGroups is provided
|
|
1562
|
+
if (!itemGroups || !Array.isArray(itemGroups)) {
|
|
1563
|
+
return Promise.reject(new Error('itemGroups is a required parameter of type array'));
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
if (force) {
|
|
1567
|
+
queryParams.force = force;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
if (notificationEmail) {
|
|
1571
|
+
queryParams.notification_email = notificationEmail;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
try {
|
|
1575
|
+
requestUrl = createCatalogUrl('item_groups', this.options, queryParams, 'v2');
|
|
1576
|
+
} catch (e) {
|
|
1577
|
+
return Promise.reject(e);
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// Handle network timeout if specified
|
|
1581
|
+
helpers.applyNetworkTimeout(this.options, networkParameters, controller);
|
|
1582
|
+
|
|
1583
|
+
const response = await fetch(requestUrl, {
|
|
1584
|
+
method: 'DELETE',
|
|
1585
|
+
body: JSON.stringify({ item_groups: itemGroups.map((itemGroup) => toSnakeCaseKeys(itemGroup, false)) }),
|
|
1586
|
+
headers: {
|
|
1587
|
+
'Content-Type': 'application/json',
|
|
1588
|
+
...helpers.createAuthHeader(this.options),
|
|
1589
|
+
},
|
|
1590
|
+
signal,
|
|
1591
|
+
});
|
|
1592
|
+
|
|
1593
|
+
if (response.ok) {
|
|
1594
|
+
return response.json();
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
return helpers.throwHttpErrorFromResponse(new Error(), response);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1227
1600
|
/**
|
|
1228
1601
|
* Add a one way synonym
|
|
1229
1602
|
*
|