Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercetools/csv-parser-orders

Package Overview
Dependencies
Maintainers
7
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/csv-parser-orders - npm Package Compare versions

Comparing version 1.4.4 to 1.4.5

83

lib/cli.js

@@ -1,37 +0,21 @@

'use strict';
"use strict";
var _fs = require('fs');
var _fs = _interopRequireDefault(require("fs"));
var _fs2 = _interopRequireDefault(_fs);
var _npmlog = _interopRequireDefault(require("npmlog"));
var _npmlog = require('npmlog');
var _prettyError = _interopRequireDefault(require("pretty-error"));
var _npmlog2 = _interopRequireDefault(_npmlog);
var _yargs = _interopRequireDefault(require("yargs"));
var _prettyError = require('pretty-error');
var _constants = _interopRequireDefault(require("./constants"));
var _prettyError2 = _interopRequireDefault(_prettyError);
var _lineItemState = _interopRequireDefault(require("./parsers/line-item-state"));
var _yargs = require('yargs');
var _addReturnInfo = _interopRequireDefault(require("./parsers/add-return-info"));
var _yargs2 = _interopRequireDefault(_yargs);
var _deliveries = _interopRequireDefault(require("./parsers/deliveries"));
var _constants = require('./constants');
var _package = require("../package.json");
var _constants2 = _interopRequireDefault(_constants);
var _lineItemState = require('./parsers/line-item-state');
var _lineItemState2 = _interopRequireDefault(_lineItemState);
var _addReturnInfo = require('./parsers/add-return-info');
var _addReturnInfo2 = _interopRequireDefault(_addReturnInfo);
var _deliveries = require('./parsers/deliveries');
var _deliveries2 = _interopRequireDefault(_deliveries);
var _package = require('../package.json');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -41,3 +25,3 @@

const args = _yargs2.default.usage(`\n
const args = _yargs.default.usage(`\n
Usage: $0 [options]

@@ -59,4 +43,3 @@ Convert commercetools order CSV data to JSON.`).showHelpOnFail(false).option('help', {

}).coerce('inputFile', arg => {
if (arg !== 'stdin') return _fs2.default.createReadStream(String(arg));
if (arg !== 'stdin') return _fs.default.createReadStream(String(arg));
return process.stdin;

@@ -68,27 +51,26 @@ }).option('outputFile', {

}).coerce('outputFile', arg => {
if (arg !== 'stdout') return _fs2.default.createWriteStream(String(arg));
if (arg !== 'stdout') return _fs.default.createWriteStream(String(arg));
return process.stdout;
}).option('batchSize', {
alias: 'b',
default: _constants2.default.standardOption.batchSize,
default: _constants.default.standardOption.batchSize,
describe: 'Number of CSV rows to handle simultaneously.'
}).option('delimiter', {
alias: 'd',
default: _constants2.default.standardOption.delimiter,
default: _constants.default.standardOption.delimiter,
describe: 'Used CSV delimiter.'
}).option('encoding', {
alias: 'e',
default: _constants2.default.standardOption.encoding,
default: _constants.default.standardOption.encoding,
describe: 'Used CSV encoding.'
}).option('strictMode', {
alias: 's',
default: _constants2.default.standardOption.strictMode,
default: _constants.default.standardOption.strictMode,
describe: 'Parse CSV strictly.'
}).option('logLevel', {
alias: 'l',
default: _constants2.default.standardOption.defaultLogLevel,
default: _constants.default.standardOption.defaultLogLevel,
describe: 'Logging level: error, warn, info or verbose.'
}).option('logFile', {
default: _constants2.default.standardOption.defaultLogFile,
default: _constants.default.standardOption.defaultLogFile,
describe: 'Path to file where to save logs.'

@@ -98,5 +80,4 @@ }).argv;

const logError = error => {
const errorFormatter = new _prettyError2.default();
if (_npmlog2.default.level === 'verbose') process.stderr.write(`ERR: ${errorFormatter.render(error)}`);else process.stderr.write(`ERR: ${error.message || error}`);
const errorFormatter = new _prettyError.default();
if (_npmlog.default.level === 'verbose') process.stderr.write(`ERR: ${errorFormatter.render(error)}`);else process.stderr.write(`ERR: ${error.message || error}`);
};

@@ -106,3 +87,2 @@

if (Array.isArray(errors)) errors.forEach(logError);else logError(errors);
process.exitCode = 1;

@@ -113,6 +93,6 @@ };

logger: {
error: _npmlog2.default.error.bind(undefined, ''),
warn: _npmlog2.default.warn.bind(undefined, ''),
info: _npmlog2.default.info.bind(undefined, ''),
verbose: _npmlog2.default.verbose.bind(undefined, '')
error: _npmlog.default.error.bind(void 0, ''),
warn: _npmlog.default.warn.bind(void 0, ''),
info: _npmlog.default.info.bind(void 0, ''),
verbose: _npmlog.default.verbose.bind(void 0, '')
},

@@ -126,12 +106,11 @@ csvConfig: {

if (args.outputFile === process.stdout) _npmlog2.default.stream = _fs2.default.createWriteStream(args.logFile);
if (args.outputFile === process.stdout) _npmlog.default.stream = _fs.default.createWriteStream(args.logFile);
const methodMapping = {
lineitemstate: config => new _lineItemState2.default(config),
returninfo: config => new _addReturnInfo2.default(config),
deliveries: config => new _deliveries2.default(config)
lineitemstate: config => new _lineItemState.default(config),
returninfo: config => new _addReturnInfo.default(config),
deliveries: config => new _deliveries.default(config) // Register error listener
// Register error listener
};args.outputFile.on('error', errorHandler);
};
args.outputFile.on('error', errorHandler);
args.inputFile.setEncoding(args.encoding);
methodMapping[args.type](getModuleConfig()).parse(args.inputFile, args.outputFile);

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,2 +6,3 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
const CONSTANTS = {

@@ -24,9 +25,9 @@ host: {

strictMode: true
}
} // Go through object because `freeze` works shallow
// Go through object because `freeze` works shallow
};Object.keys(CONSTANTS).forEach(key => {
};
Object.keys(CONSTANTS).forEach(key => {
Object.freeze(CONSTANTS[key]);
});
exports.default = CONSTANTS;
var _default = CONSTANTS;
exports.default = _default;

@@ -1,21 +0,15 @@

'use strict';
"use strict";
var _lineItemState = require('./parsers/line-item-state');
var _lineItemState = _interopRequireDefault(require("./parsers/line-item-state"));
var _lineItemState2 = _interopRequireDefault(_lineItemState);
var _addReturnInfo = _interopRequireDefault(require("./parsers/add-return-info"));
var _addReturnInfo = require('./parsers/add-return-info');
var _deliveries = _interopRequireDefault(require("./parsers/deliveries"));
var _addReturnInfo2 = _interopRequireDefault(_addReturnInfo);
var _deliveries = require('./parsers/deliveries');
var _deliveries2 = _interopRequireDefault(_deliveries);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
LineItemStateCsvParser: _lineItemState2.default,
AddReturnInfoCsvParser: _addReturnInfo2.default,
DeliveriesCsvParser: _deliveries2.default
LineItemStateCsvParser: _lineItemState.default,
AddReturnInfoCsvParser: _addReturnInfo.default,
DeliveriesCsvParser: _deliveries.default
};

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,17 +6,12 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _highland = require('highland');
var _highland = _interopRequireDefault(require("highland"));
var _highland2 = _interopRequireDefault(_highland);
var _lodash = require("lodash");
var _lodash = require('lodash');
var _csvParser = _interopRequireDefault(require("csv-parser"));
var _csvParser = require('csv-parser');
var _constants = _interopRequireDefault(require("../constants"));
var _csvParser2 = _interopRequireDefault(_csvParser);
var _constants = require('../constants');
var _constants2 = _interopRequireDefault(_constants);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -28,9 +23,7 @@

this.moduleName = moduleName;
this.csvConfig = (0, _lodash.defaults)(conf.csvConfig || {}, {
batchSize: _constants2.default.standardOption.batchSize,
delimiter: _constants2.default.standardOption.delimiter,
strictMode: _constants2.default.standardOption.strictMode
batchSize: _constants.default.standardOption.batchSize,
delimiter: _constants.default.standardOption.delimiter,
strictMode: _constants.default.standardOption.strictMode
});
this.logger = (0, _lodash.defaults)(conf.logger || {}, {

@@ -46,4 +39,3 @@ error: () => {},

let rowIndex = 1;
return (0, _highland2.default)(input).through((0, _csvParser2.default)({
return (0, _highland.default)(input).through((0, _csvParser.default)({
separator: this.csvConfig.delimiter,

@@ -57,3 +49,3 @@ strict: this.csvConfig.strictMode

rowIndex += 1;
}).flatMap(_highland2.default).flatMap(data => (0, _highland2.default)(this._processData(data))).stopOnError(err => {
}).flatMap(_highland.default).flatMap(data => (0, _highland.default)(this._processData(data))).stopOnError(err => {
this.logger.error(err);

@@ -65,4 +57,3 @@ return output.emit('error', err);

_getMissingHeaders(data) {
const headerDiff = (0, _lodash.difference)(_constants2.default.requiredHeaders[this.moduleName], Object.keys(data));
const headerDiff = (0, _lodash.difference)(_constants.default.requiredHeaders[this.moduleName], Object.keys(data));
return headerDiff;

@@ -74,3 +65,5 @@ }

}
}
exports.default = AbstractParser;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,16 +6,15 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _JSONStream = require('JSONStream');
require("core-js/modules/es6.promise");
var _JSONStream2 = _interopRequireDefault(_JSONStream);
var _JSONStream = _interopRequireDefault(require("JSONStream"));
var _lodash = require('lodash');
var _lodash = require("lodash");
var _abstractParser = require('./abstract-parser');
var _abstractParser = _interopRequireDefault(require("./abstract-parser"));
var _abstractParser2 = _interopRequireDefault(_abstractParser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class AddReturnInfoParser extends _abstractParser2.default {
class AddReturnInfoParser extends _abstractParser.default {
constructor(config) {

@@ -27,6 +26,7 @@ super(config, 'returnInfo');

this.logger.info('Starting Return Info CSV conversion');
this._streamInput(input, output).reduce([], AddReturnInfoParser._reduceOrders).stopOnError(err => {
this.logger.error(err);
return output.emit('error', err);
}).pipe(_JSONStream2.default.stringify(false)).pipe(output);
}).pipe(_JSONStream.default.stringify(false)).pipe(output);
}

@@ -38,4 +38,4 @@

const missingHeaders = this._getMissingHeaders(data);
if (missingHeaders.length) return Promise.reject(new Error(`Required headers missing: '${missingHeaders.join(',')}'`));
/**

@@ -56,2 +56,3 @@ * Sample returnInfo object that the API supports:

*/
const result = {

@@ -61,3 +62,4 @@ orderNumber: data.orderNumber,

returnTrackingId: data.returnTrackingId,
_returnId: data._returnId, // Internal value to group the returnInfo
_returnId: data._returnId,
// Internal value to group the returnInfo
returnDate: data.returnDate,

@@ -81,27 +83,22 @@ items: [{

*/
// push first order into final array
if (!allOrders.length) return allOrders.concat(currentOrder);
if (!allOrders.length) return allOrders.concat(currentOrder); // find order in final array with this orderNumber
// find order in final array with this orderNumber
const existingOrder = (0, _lodash.find)(allOrders, ['orderNumber', currentOrder.orderNumber]);
// if currentOrder (with this orderNumber) haven't been inserted yet
const existingOrder = (0, _lodash.find)(allOrders, ['orderNumber', currentOrder.orderNumber]); // if currentOrder (with this orderNumber) haven't been inserted yet
// push it directly into final array
if (!existingOrder) return allOrders.concat(currentOrder);
// if there is already an order with this orderNumber
if (!existingOrder) return allOrders.concat(currentOrder); // if there is already an order with this orderNumber
// get all returnInfos with same returnId
const existingReturnInfos = (0, _lodash.filter)(existingOrder.returnInfo, ['_returnId', currentOrder.returnInfo[0]._returnId]);
// if there is no returnInfo with this returnId push those from currentOrder
if (!existingReturnInfos.length) existingOrder.returnInfo.push(...currentOrder.returnInfo);
// else concat items from currentOrder
const existingReturnInfos = (0, _lodash.filter)(existingOrder.returnInfo, ['_returnId', currentOrder.returnInfo[0]._returnId]); // if there is no returnInfo with this returnId push those from currentOrder
if (!existingReturnInfos.length) existingOrder.returnInfo.push(...currentOrder.returnInfo); // else concat items from currentOrder
else existingReturnInfos.forEach(returnInfo => {
returnInfo.items.push(...currentOrder.returnInfo[0].items);
});
return allOrders;
}
}
exports.default = AddReturnInfoParser;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,32 +6,35 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
require("core-js/modules/es7.symbol.async-iterator");
var _lodash = require('lodash');
require("core-js/modules/es6.symbol");
var _lodash2 = _interopRequireDefault(_lodash);
require("core-js/modules/web.dom.iterable");
var _objectPath = require('object-path');
require("core-js/modules/es6.promise");
var _objectPath2 = _interopRequireDefault(_objectPath);
var _lodash = _interopRequireDefault(require("lodash"));
var _highland = require('highland');
var _objectPath = _interopRequireDefault(require("object-path"));
var _highland2 = _interopRequireDefault(_highland);
var _highland = _interopRequireDefault(require("highland"));
var _JSONStream = require('JSONStream');
var _JSONStream = _interopRequireDefault(require("JSONStream"));
var _JSONStream2 = _interopRequireDefault(_JSONStream);
var _constants = _interopRequireDefault(require("../constants"));
var _constants = require('../constants');
var _abstractParser = _interopRequireDefault(require("./abstract-parser"));
var _constants2 = _interopRequireDefault(_constants);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _abstractParser = require('./abstract-parser');
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
var _abstractParser2 = _interopRequireDefault(_abstractParser);
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
class DeliveriesParser extends _abstractParser2.default {
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
class DeliveriesParser extends _abstractParser.default {
constructor(config) {

@@ -43,16 +46,17 @@ super(config, 'deliveries');

this.logger.info('Starting Deliveries CSV conversion');
this._streamInput(input, output).reduce([], DeliveriesParser._groupByDeliveryId).stopOnError(err => {
this.logger.error(err);
return output.emit('error', err);
}).flatMap(data => (0, _highland2.default)(DeliveriesParser._cleanOrders(data))).pipe(_JSONStream2.default.stringify(false)).pipe(output);
}
}).flatMap(data => (0, _highland.default)(DeliveriesParser._cleanOrders(data))).pipe(_JSONStream.default.stringify(false)).pipe(output);
} // Take objectized CSV row and create an order object from it
// Take objectized CSV row and create an order object from it
_processData(data) {
this.logger.verbose('Processing data to CTP format');
const csvHeaders = Object.keys(data);
const headerDiff = _lodash2.default.difference(_constants2.default.requiredHeaders.deliveries, csvHeaders);
const headerDiff = _lodash.default.difference(_constants.default.requiredHeaders.deliveries, csvHeaders);
if (headerDiff.length) return Promise.reject(new Error(`Required headers missing: '${headerDiff.join(',')}'`));
/**

@@ -108,4 +112,4 @@ * Sample delivery object that the API supports

*/
// Basic delivery object with delivery item
// Basic delivery object with delivery item
const delivery = {

@@ -119,10 +123,10 @@ id: data['delivery.id'],

quantity: parseInt(data['item.quantity'], 10)
}]
}] // Add parcel info if it is present
// Add parcel info if it is present
};if (data['parcel.id']) {
};
if (data['parcel.id']) {
const parcel = DeliveriesParser._parseParcelInfo(data);
if (parcel.measurements && Object.keys(parcel.measurements).length !== 4) return Promise.reject(new Error('All measurement fields are mandatory'));
delivery.parcels = [parcel];

@@ -138,5 +142,5 @@ }

return Promise.resolve(order);
}
} // remove internal properties
// remove internal properties
static _cleanOrders(orders) {

@@ -148,5 +152,5 @@ orders.forEach(order => order.shippingInfo.deliveries.forEach(delivery => delivery.items.forEach(item => {

return [orders];
}
} // Will merge newOrder with orders in results array
// Will merge newOrder with orders in results array
static _groupByDeliveryId(results, newOrder) {

@@ -159,56 +163,44 @@ /*

*/
// if newOrder is the first record, just push it to the results
if (!results.length) return [newOrder];
if (!results.length) return [newOrder]; // find newOrder in results using its orderNumber
// find newOrder in results using its orderNumber
const existingOrder = results.find(order => order.orderNumber === newOrder.orderNumber);
if (!existingOrder) results.push(newOrder);else {
const oldDeliveries = existingOrder.shippingInfo.deliveries;
const newDelivery = newOrder.shippingInfo.deliveries[0];
const newDelivery = newOrder.shippingInfo.deliveries[0]; // find newDelivery in results using its id
// find newDelivery in results using its id
const existingDelivery = oldDeliveries.find(delivery => delivery.id === newDelivery.id);
const existingDelivery = oldDeliveries.find(delivery => delivery.id === newDelivery.id); // if this delivery is not yet in results array, insert it
// if this delivery is not yet in results array, insert it
if (!existingDelivery) oldDeliveries.push(newDelivery);else {
DeliveriesParser._mergeDeliveryItems(existingDelivery.items, newDelivery.items[0], existingDelivery);
DeliveriesParser._mergeDeliveryItems(existingDelivery.items, newDelivery.items[0], existingDelivery); // if delivery have parcels, merge them
// if delivery have parcels, merge them
if (newDelivery.parcels) DeliveriesParser._mergeDeliveryParcels(existingDelivery.parcels, newDelivery.parcels[0], existingDelivery);
}
}
return results;
}
} // merge delivery parcels to one array based on parcel.id field
// merge delivery parcels to one array based on parcel.id field
static _mergeDeliveryParcels(allParcels, newParcel, delivery) {
// try to find this parcel in array using parcel id
const duplicitParcel = allParcels.find(parcel => parcel.id === newParcel.id);
const duplicitParcel = allParcels.find(parcel => parcel.id === newParcel.id); // if this parcel item is not yet in array, insert it
// if this parcel item is not yet in array, insert it
if (!duplicitParcel) return allParcels.push(newParcel);
if (!duplicitParcel) return allParcels.push(newParcel); // if this parcel is already in array, check if parcels are equal
// if this parcel is already in array, check if parcels are equal
if (!_lodash2.default.isEqual(duplicitParcel, newParcel)) throw new Error(`Delivery with id '${delivery.id}' has a parcel with` + ` id '${newParcel.id}' which has different` + ` values across multiple rows.
if (!_lodash.default.isEqual(duplicitParcel, newParcel)) throw new Error(`Delivery with id '${delivery.id}' has a parcel with` + ` id '${newParcel.id}' which has different` + ` values across multiple rows.
Original parcel: '${JSON.stringify(duplicitParcel)}'
Invalid parcel: '${JSON.stringify(newParcel)}'`);
return allParcels;
}
} // merge delivery items to one array based on _groupId field
// merge delivery items to one array based on _groupId field
static _mergeDeliveryItems(allItems, newItem, delivery) {
const duplicitItem = allItems.find(item => item._groupId === newItem._groupId);
const duplicitItem = allItems.find(item => item._groupId === newItem._groupId); // if an item is not yet in array, insert it
// if an item is not yet in array, insert it
if (!duplicitItem) return allItems.push(newItem);
if (!duplicitItem) return allItems.push(newItem); // if this item is already in array, check if items are equal
// if this item is already in array, check if items are equal
if (!_lodash2.default.isEqual(duplicitItem, newItem)) throw new Error(`Delivery with id '${delivery.id}' has an item` + ` with itemGroupId '${newItem._groupId}' which has different` + ` values across multiple rows.
if (!_lodash.default.isEqual(duplicitItem, newItem)) throw new Error(`Delivery with id '${delivery.id}' has an item` + ` with itemGroupId '${newItem._groupId}' which has different` + ` values across multiple rows.
Original row: '${JSON.stringify(duplicitItem)}'
Invalid row: '${JSON.stringify(newItem)}'`);
return allItems;

@@ -230,27 +222,20 @@ }

};
const parcel = {
id: data['parcel.id']
id: data['parcel.id'] // Build parcel object
// Build parcel object
};Object.keys(data).forEach(fieldName => {
if (!transitionMap[fieldName]) return;
};
Object.keys(data).forEach(fieldName => {
if (!transitionMap[fieldName]) return; // All values are loaded as a string
// All values are loaded as a string
let fieldValue = data[fieldName];
let fieldValue = data[fieldName]; // do not set empty values
// do not set empty values
if (fieldValue === '') return;
if (fieldValue === '') return; // Cast measurements to Number
// Cast measurements to Number
if (/^measurements/.test(transitionMap[fieldName])) fieldValue = Number(fieldValue);
if (/^measurements/.test(transitionMap[fieldName])) fieldValue = Number(fieldValue); // Cast isReturn field to Boolean
// Cast isReturn field to Boolean
if (fieldName === 'parcel.isReturn') fieldValue = fieldValue === '1' || fieldValue.toLowerCase() === 'true';
if (fieldName === 'parcel.items') fieldValue = DeliveriesParser._parseParcelItems(fieldValue);
_objectPath2.default.set(parcel, transitionMap[fieldName], fieldValue);
_objectPath.default.set(parcel, transitionMap[fieldName], fieldValue);
});
return parcel;

@@ -261,8 +246,6 @@ }

if (!parcelItemsAsString) return [];
return parcelItemsAsString.split(';').map(parcelItemString => {
var _parcelItemString$spl = parcelItemString.split(':'),
_parcelItemString$spl2 = _slicedToArray(_parcelItemString$spl, 2);
const id = _parcelItemString$spl2[0],
const _parcelItemString$spl = parcelItemString.split(':'),
_parcelItemString$spl2 = _slicedToArray(_parcelItemString$spl, 2),
id = _parcelItemString$spl2[0],
quantity = _parcelItemString$spl2[1];

@@ -276,3 +259,5 @@

}
}
exports.default = DeliveriesParser;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,14 +6,13 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _JSONStream = require('JSONStream');
require("core-js/modules/es6.promise");
var _JSONStream2 = _interopRequireDefault(_JSONStream);
var _JSONStream = _interopRequireDefault(require("JSONStream"));
var _abstractParser = require('./abstract-parser');
var _abstractParser = _interopRequireDefault(require("./abstract-parser"));
var _abstractParser2 = _interopRequireDefault(_abstractParser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class LineItemStateParser extends _abstractParser2.default {
class LineItemStateParser extends _abstractParser.default {
constructor(config) {

@@ -25,14 +24,13 @@ super(config, 'lineItemState');

this.logger.info('Starting LineItemState CSV conversion');
this._streamInput(input, output).reduce([], LineItemStateParser._groupByOrderNumber).stopOnError(err => {
this.logger.error(err);
return output.emit('error', err);
}).flatMap(data => data).pipe(_JSONStream2.default.stringify()).pipe(output);
}
}).flatMap(data => data).pipe(_JSONStream.default.stringify()).pipe(output);
} // Will merge newLineItemState with lineItems in results array
// Will merge newLineItemState with lineItems in results array
static _groupByOrderNumber(results, newLineItemState) {
const existingItem = results.find(lineItem => lineItem.orderNumber === newLineItemState.orderNumber);
if (existingItem) existingItem.lineItems.push(...newLineItemState.lineItems);else results.push(newLineItemState);
return results;

@@ -45,4 +43,4 @@ }

const missingHeaders = this._getMissingHeaders(data);
if (missingHeaders.length) return Promise.reject(new Error(`Required headers missing: '${missingHeaders.join(',')}'`));
const state = {

@@ -53,5 +51,3 @@ quantity: parseInt(data.quantity, 10),

};
if (data._fromStateQty) state._fromStateQty = parseInt(data._fromStateQty, 10);
const result = {

@@ -66,3 +62,5 @@ orderNumber: data.orderNumber,

}
}
exports.default = LineItemStateParser;
{
"name": "@commercetools/csv-parser-orders",
"version": "1.4.4",
"version": "1.4.5",
"description": "Module that parses order csv to json",

@@ -34,3 +34,3 @@ "keywords": [

"scripts": {
"build": "babel src --out-dir lib"
"build": "babel src --out-dir lib --config-file '../../babel.config.js'"
},

@@ -37,0 +37,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc