@constructor-io/constructorio-node 4.4.6 → 4.4.7
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 +28 -10
- package/src/types/catalog.d.ts +1 -0
package/package.json
CHANGED
package/src/modules/catalog.js
CHANGED
|
@@ -55,7 +55,7 @@ async function createQueryParamsAndFormData(parameters) {
|
|
|
55
55
|
const formData = new FormData();
|
|
56
56
|
|
|
57
57
|
if (parameters) {
|
|
58
|
-
const { section, notificationEmail, force } = parameters;
|
|
58
|
+
const { section, notificationEmail, force, onMissing } = parameters;
|
|
59
59
|
let { items, variations, item_groups: itemGroups } = parameters;
|
|
60
60
|
|
|
61
61
|
try {
|
|
@@ -92,6 +92,16 @@ async function createQueryParamsAndFormData(parameters) {
|
|
|
92
92
|
queryParams.force = force;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
// Pull onMissing from parameters
|
|
96
|
+
if (onMissing) {
|
|
97
|
+
// Validate onMissing parameter
|
|
98
|
+
if (onMissing && !['FAIL', 'IGNORE', 'CREATE'].includes(onMissing)) {
|
|
99
|
+
throw new Error('onMissing must be one of FAIL, IGNORE, or CREATE');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
queryParams.on_missing = onMissing;
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
// Pull items from parameters
|
|
96
106
|
if (items) {
|
|
97
107
|
formData.append('items', items, {
|
|
@@ -119,9 +129,15 @@ async function createQueryParamsAndFormData(parameters) {
|
|
|
119
129
|
|
|
120
130
|
async function addTarArchiveToFormData(parameters, formData, operation, apiKey) {
|
|
121
131
|
try {
|
|
122
|
-
const { section } = parameters;
|
|
132
|
+
const { section, onMissing } = parameters;
|
|
133
|
+
const onMissingParameter = onMissing && onMissing !== 'FAIL' ? onMissing.toLowerCase() : '';
|
|
123
134
|
let { tarArchive } = parameters;
|
|
124
135
|
|
|
136
|
+
// Validate onMissing parameter
|
|
137
|
+
if (onMissing && !['FAIL', 'IGNORE', 'CREATE'].includes(onMissing)) {
|
|
138
|
+
throw new Error('onMissing must be one of FAIL, IGNORE, or CREATE');
|
|
139
|
+
}
|
|
140
|
+
|
|
125
141
|
// Convert tarArchive to buffer if passed as stream
|
|
126
142
|
if (tarArchive instanceof fs.ReadStream || tarArchive instanceof Duplex) {
|
|
127
143
|
tarArchive = await convertToBuffer(tarArchive);
|
|
@@ -135,7 +151,7 @@ async function addTarArchiveToFormData(parameters, formData, operation, apiKey)
|
|
|
135
151
|
.replace('T', '-')
|
|
136
152
|
.replace(/:/g, '-')
|
|
137
153
|
.slice(0, 19);
|
|
138
|
-
const filename = `${apiKey}_${section}_${operation}_${formattedDateTime}.tar.gz`;
|
|
154
|
+
const filename = `${apiKey}_${section}_${operation}${onMissingParameter}_${formattedDateTime}.tar.gz`;
|
|
139
155
|
|
|
140
156
|
formData.append(filename, tarArchive, {
|
|
141
157
|
filename,
|
|
@@ -2087,7 +2103,7 @@ class Catalog {
|
|
|
2087
2103
|
* @function replaceCatalog
|
|
2088
2104
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2089
2105
|
* @param {string} parameters.section - The section to update
|
|
2090
|
-
* @param {string} [parameters.
|
|
2106
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2091
2107
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2092
2108
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2093
2109
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
@@ -2139,7 +2155,7 @@ class Catalog {
|
|
|
2139
2155
|
* @function updateCatalog
|
|
2140
2156
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2141
2157
|
* @param {string} parameters.section - The section to update
|
|
2142
|
-
* @param {string} [parameters.
|
|
2158
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2143
2159
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2144
2160
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2145
2161
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
@@ -2191,8 +2207,9 @@ class Catalog {
|
|
|
2191
2207
|
* @function patchCatalog
|
|
2192
2208
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2193
2209
|
* @param {string} parameters.section - The section to update
|
|
2194
|
-
* @param {string} [parameters.
|
|
2210
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2195
2211
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2212
|
+
* @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
|
|
2196
2213
|
* @param {file} [parameters.items] - The CSV file with all new items
|
|
2197
2214
|
* @param {file} [parameters.variations] - The CSV file with all new variations
|
|
2198
2215
|
* @param {file} [parameters.item_groups] - The CSV file with all new item_groups
|
|
@@ -2243,7 +2260,7 @@ class Catalog {
|
|
|
2243
2260
|
* @function replaceCatalogUsingTarArchive
|
|
2244
2261
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2245
2262
|
* @param {string} parameters.section - The section to update
|
|
2246
|
-
* @param {string} [parameters.
|
|
2263
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2247
2264
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2248
2265
|
* @param {file} [parameters.tarArchive] - The tar file that includes csv files
|
|
2249
2266
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
@@ -2292,7 +2309,7 @@ class Catalog {
|
|
|
2292
2309
|
* @function updateCatalogUsingTarArchive
|
|
2293
2310
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2294
2311
|
* @param {string} parameters.section - The section to update
|
|
2295
|
-
* @param {string} [parameters.
|
|
2312
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2296
2313
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2297
2314
|
* @param {file} [parameters.tarArchive] - The tar file that includes csv files
|
|
2298
2315
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
@@ -2342,8 +2359,9 @@ class Catalog {
|
|
|
2342
2359
|
* @function patchCatalogUsingTarArchive
|
|
2343
2360
|
* @param {object} parameters - Additional parameters for catalog details
|
|
2344
2361
|
* @param {string} parameters.section - The section to update
|
|
2345
|
-
* @param {string} [parameters.
|
|
2362
|
+
* @param {string} [parameters.notificationEmail] - An email address to receive an email notification if the task fails
|
|
2346
2363
|
* @param {boolean} [parameters.force=false] - Process the catalog even if it will invalidate a large number of existing items
|
|
2364
|
+
* @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
|
|
2347
2365
|
* @param {file} [parameters.tarArchive] - The tar file that includes csv files
|
|
2348
2366
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2349
2367
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
@@ -2363,7 +2381,7 @@ class Catalog {
|
|
|
2363
2381
|
const controller = new AbortController();
|
|
2364
2382
|
const { signal } = controller;
|
|
2365
2383
|
const { queryParams, formData } = await createQueryParamsAndFormData(parameters);
|
|
2366
|
-
const formDataWithTarArchive = await addTarArchiveToFormData(parameters, formData, '
|
|
2384
|
+
const formDataWithTarArchive = await addTarArchiveToFormData(parameters, formData, 'patchdelta', apiKey);
|
|
2367
2385
|
const requestUrl = createCatalogUrl('catalog', this.options, { ...queryParams, patch_delta: true });
|
|
2368
2386
|
|
|
2369
2387
|
// Handle network timeout if specified
|