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

@twec/ip-parser

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twec/ip-parser - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

lib/ip-parser-parse.js

102

lib/ip-parser.js
const etl = require('etl');
const parse = require('./ip-parser-parse');
const stringify = require('./ip-parser-stringify');
const containerHeader = require('./layouts/container_header');
const containerTrailer = require('./layouts/container_trailer');
const orderHeader = require('./layouts/order_header');
const orderDetail = require('./layouts/order_detail');
const orderTrailer = require('./layouts/order_trailer');
function parse(obj, layout) {
const objLayout = Object.keys(layout).reduce((acc, key) => {
if (key !== 'TYPE' && key !== 'POST_PROCESS') {
const e = layout[key];
let val = acc.text.slice(e.start, e.end || e.start + e.length).trim();
if (!val.length) return acc;
if (e.transform) val = e.transform(val);
if (val !== undefined) acc[key] = val;
}
return acc;
}, obj);
delete objLayout.text;
if (typeof layout.POST_PROCESS === 'function') {
return layout.POST_PROCESS(objLayout);
}
return objLayout;
}
function parseFileAsStream(filename) {
let currentContainer = null;
let currentOrder = null;
// eslint-disable-next-line no-console
console.log(filename);
const containers = etl
.file(filename)
.pipe(etl.split())
.pipe(
etl.map(async function mapLayout(line) {
const type = line.text.substr(0, 4);
if (type === containerHeader.TYPE) {
const parsed = parse(line, containerHeader);
if (parsed) {
currentContainer = parsed;
currentContainer.orders = [];
}
} else if (type === orderHeader.TYPE) {
const parsed = parse(line, orderHeader);
if (parsed) {
currentOrder = parsed;
currentOrder.lines = [];
}
} else if (type === orderDetail.TYPE) {
const parsed = parse(line, orderDetail);
if (parsed) {
currentOrder.lines.push(parsed);
}
} else if (type === orderTrailer.TYPE) {
const parsed = parse(line, orderTrailer);
if (parsed) {
const isSameShipGroup =
currentOrder.shipGroupPackageNumber ===
parsed.shipGroupPackageNumber;
const hasAllLines =
parsed.numberOfOrderDetailRecords === currentOrder.lines.length;
if (isSameShipGroup && hasAllLines) {
currentContainer.orders.push(currentOrder);
} else {
// TODO: Do something about the failed order here
// eslint-disable-next-line no-console
console.error('error1: ', currentOrder);
}
currentOrder = null;
}
} else if (type === containerTrailer.TYPE) {
const parsed = parse(line, containerTrailer);
if (parsed) {
if (
parsed.numberOfOrderHeaderRecords ===
currentContainer.orders.length
) {
this.push(currentContainer);
} else {
// TODO: Do something about the failed container here
// eslint-disable-next-line no-console
console.error('error2: ', currentContainer);
}
currentContainer = null;
}
}
}),
);
return containers;
return parse(etl.file(filename));
}
/**
*
*/
async function parseFile(filename) {

@@ -112,2 +17,3 @@ return parseFileAsStream(filename).promise();

parseFileAsStream,
stringify,
};

@@ -1,16 +0,34 @@

const { toInt, makeDate } = require('@twec/parser-utils');
const layout = {
// recordType: { start: 0, length: 4 },
dateOfRecordCreation: { start: 4, length: 8 },
timeOfRecordCreation: { start: 12, length: 4 },
transactionFormat: { start: 16, length: 8 },
sourceSystem: { start: 24, length: 12 },
targetSystem: { start: 36, length: 12 },
containerType: { start: 48, length: 4 },
containerReceiptStatus: { start: 52, length: 1 },
dateOfRecordCreation: {
start: 4,
length: 12,
type: 'datetime',
},
transactionFormat: {
start: 16,
length: 8,
default: 'V2.0.0.0',
},
sourceSystem: {
start: 24,
length: 12,
default: 'AS/400',
},
targetSystem: {
start: 36,
length: 12,
},
containerType: {
start: 48,
length: 4,
default: 'SHPN',
},
containerReceiptStatus: {
start: 52,
length: 1,
},
numberOfHeaderRecords: {
start: 53,
length: 9,
transform: toInt,
type: 'int',
},

@@ -20,3 +38,3 @@ numberOfDetailRecords: {

length: 9,
transform: toInt,
type: 'int',
},

@@ -26,14 +44,12 @@ r1SequenceNumber: {

length: 20,
transform: toInt,
type: 'int',
},
// reserveField2: { start: 91, length: 20 },
// reserveField3: { start: 111, length: 20 },
// reserveField4: { start: 131, length: 20 },
// reserveField5: { start: 151, length: 20 },
// reserveField6: { start: 171, length: 20 },
// reserveField7: { start: 191, length: 20 },
// reserveField8: { start: 211, length: 20 },
// reserveField9: { start: 231, length: 20 },
// reserveField10: { start: 251, length: 20 },
// endOfRecordIndicator: { start: 271, length: 1 },
reservedField1: {
start: 91,
length: 20,
},
endOfRecordIndicator: {
start: 271,
length: 1,
},
};

@@ -43,4 +59,2 @@

layout.POST_PROCESS = makeDate;
module.exports = layout;

@@ -1,18 +0,15 @@

const { toInt, makeDate } = require('@twec/parser-utils');
const layout = {
// recordType: {start: 0, length: 4},
dateOfRecordCreation: { start: 4, length: 8 },
timeOfRecordCreation: { start: 12, length: 4 },
numberOfOrderHeaderRecords: {
dateOfRecordCreation: { start: 4, length: 12, type: 'datetime' },
numberOfHeaderRecords: {
start: 16,
length: 9,
transform: toInt,
type: 'int',
},
numberOfOrderDetailRecords: {
numberOfDetailRecords: {
start: 25,
length: 9,
transform: toInt,
type: 'int',
},
// endOfRecordIndicator: {start: 34, length: 1},
endOfRecordIndicator: { start: 34, length: 1, default: '*' },
};

@@ -22,4 +19,2 @@

layout.POST_PROCESS = makeDate;
module.exports = layout;

@@ -1,7 +0,3 @@

const { toInt, toFloat, makeDate } = require('@twec/parser-utils');
const layout = {
// recordType: {start: 0, length: 4},
dateOfRecordCreation: { start: 4, length: 8 },
timeOfRecordCreation: { start: 12, length: 4 },
dateOfRecordCreation: { start: 4, length: 12, type: 'datetime' },
orderUPC: { start: 16, length: 18 },

@@ -14,3 +10,3 @@ primaryUPC: { start: 34, length: 18 },

length: 5,
transform: toFloat,
type: 'float',
},

@@ -20,3 +16,3 @@ skuWidthInInches: {

length: 5,
transform: toFloat,
type: 'float',
},

@@ -26,3 +22,3 @@ skuDepthInInches: {

length: 5,
transform: toFloat,
type: 'float',
},

@@ -32,10 +28,10 @@ skuWeight: {

length: 5,
transform: toFloat,
type: 'float',
},
pickedCartonLicensePlate: { start: 272, length: 20 },
configurtion: { start: 292, length: 10 },
divisionNumber: { start: 292, length: 10 },
quantityRequested: {
start: 302,
length: 5,
transform: toInt,
type: 'int',
},

@@ -45,3 +41,3 @@ quantityAllocated: {

length: 5,
transform: toInt,
type: 'int',
},

@@ -51,3 +47,3 @@ quantityDistributed: {

length: 5,
transform: toInt,
type: 'int',
},

@@ -57,3 +53,3 @@ quantityAcknowledged: {

length: 5,
transform: toInt,
type: 'int',
},

@@ -63,3 +59,3 @@ quantityShipped: {

length: 5,
transform: toInt,
type: 'int',
},

@@ -69,3 +65,3 @@ quantityReturned: {

length: 5,
transform: toInt,
type: 'int',
},

@@ -90,22 +86,10 @@ returnReason: { start: 332, length: 50 },

length: 10,
transform: toFloat,
type: 'float',
},
// futureUse1: {start: 543, length: 1},
// futureUse2: {start: 544, length: 1},
// futureUse3: {start: 545, length: 1},
// futureUse4: {start: 546, length: 2},
// futureUse5: {start: 548, length: 2},
// futureUse6: {start: 550, length: 5},
// futureUse7: {start: 555, length: 5},
// futureUse8: {start: 560, length: 8},
// futureUse9: {start: 568, length: 8},
// futureUse10: {start: 576, length: 10},
// futureUse11: {start: 586, length: 10},
// futureUse12: {start: 596, length: 10},
// futureUse13: {start: 606, length: 10},
// endOfRecordIndicator: {start: 616, length: 1},
carrierShippingCharges: { start: 606, length: 10, type: 'int' },
endOfRecordIndicator: { start: 616, length: 1, default: '*' },
itemCostAtTimeOfOrder: {
start: 617,
length: 10,
transform: toFloat,
type: 'float',
},

@@ -115,3 +99,3 @@ itemCostAtTimeOfShipment: {

length: 10,
transform: toFloat,
type: 'float',
},

@@ -121,14 +105,13 @@ shippingCarrier: { start: 637, length: 20 },

carrierTrackingNumber: { start: 677, length: 50 },
// itemFee1: { start: 727, length: 10 },
// itemFee2: { start: 737, length: 10 },
// itemFee3: { start: 747, length: 10 },
// itemDiscounts: { start: 757, length: 10 },
// itemRebate: { start: 767, length: 10 },
// itemSalesTax: { start: 777, length: 10 },
// newDetailReserveField1: { start: 787, length: 1 },
// newDetailReserveField2: { start: 788, length: 10 },
// newDetailReserveField3: { start: 798, length: 10 },
// newDetailReserveField4: { start: 808, length: 10 },
// newDetailReserveField5: { start: 818, length: 10 },
// newDetailReserveField6: { start: 828, length: 10 },
itemFee1: { start: 727, length: 10, type: 'int' },
itemFee2: { start: 737, length: 10, type: 'int' },
itemFee3: { start: 747, length: 10, type: 'int' },
itemDiscounts: { start: 757, length: 10, type: 'int' },
itemRebate: { start: 767, length: 10, type: 'int' },
itemSalesTax: { start: 777, length: 10, type: 'int' },
newHeaderReserveField1: { start: 787, length: 1 },
newHeaderReserveField2: { start: 788, length: 10 },
newHeaderReserveField3: { start: 798, length: 10 },
newHeaderReserveField4: { start: 808, length: 20 },
newHeaderReserveField5: { start: 828, length: 10 },
};

@@ -138,4 +121,2 @@

layout.POST_PROCESS = makeDate;
module.exports = layout;

@@ -1,13 +0,5 @@

const { toInt, toFloat, makeDate } = require('@twec/parser-utils');
const layout = {
// recordType: {start: 0, length: 4},
dateOfRecordCreation: { start: 4, length: 8 },
timeOfRecordCreation: { start: 12, length: 4 },
shipGroupPackageNumber: {
start: 16,
length: 20,
transform: toInt,
},
hostAllocation: { start: 36, length: 6 },
dateOfRecordCreation: { start: 4, length: 12, type: 'datetime' },
shipGroupPackageNumber: { start: 16, length: 20, type: 'int' },
hostAllocationOrdomsOrderNumber: { start: 36, length: 6 },
customerOrder: { start: 42, length: 20 },

@@ -17,12 +9,4 @@ orderType: { start: 62, length: 1 },

preSplitFlag: { start: 77, length: 1 },
shippingCost: {
start: 78,
length: 9.2,
transform: toFloat,
},
insuranceCost: {
start: 87,
length: 9.2,
transform: toFloat,
},
shippingCost: { start: 78, length: 9.2, type: 'float' },
insuranceCost: { start: 87, length: 9.2, type: 'float' },
shippingDepartmentCode: { start: 96, length: 4 },

@@ -51,9 +35,7 @@ billingCustomerName: { start: 100, length: 50 },

shippingTrackingNumber: { start: 589, length: 30 },
dateShipped: { start: 619, length: 8 },
timeShipped: { start: 627, length: 4 },
dateShipped: { start: 619, length: 12, type: 'datetime' },
specialDeliveryInstructions: { start: 631, length: 350 },
giftMessage: { start: 981, length: 200 },
giftWrap: { start: 1181, length: 1 },
dateOrderPlaced: { start: 1182, length: 8 },
timeOrderPlaced: { start: 1190, length: 4 },
dateOrderPlaced: { start: 1182, length: 12, type: 'datetime' },
orderExceptionStatus: { start: 1194, length: 1 },

@@ -69,12 +51,4 @@ reserveField1: { start: 1195, length: 20 },

carrierCodeRequiredFor856: { start: 1306, length: 2 },
ladingQuantity: {
start: 1308,
length: 4,
transform: toInt,
},
totalWeightOfTheShipment: {
start: 1312,
length: 10,
transform: toFloat,
},
ladingQuantity: { start: 1308, length: 4, type: 'int' },
totalWeightOfTheShipment: { start: 1312, length: 10, type: 'float' },
tradingPartner: { start: 1322, length: 5 },

@@ -92,23 +66,22 @@ shipFromName: { start: 1327, length: 50 },

length: 10,
transform: toFloat,
type: 'float',
},
kioskToStore: { start: 1489, length: 1 },
partialOrders: { start: 1490, length: 1 },
// futureUse1: {start: 1491, length: 2},
// futureUse2: {start: 1493, length: 2},
// futureUse3: {start: 1495, length: 5},
// futureUse4: {start: 1500, length: 5},
// futureUse5: {start: 1505, length: 8},
// futureUse6: {start: 1513, length: 8},
// futureUse7: {start: 1521, length: 10},
// futureUse8: {start: 1531, length: 10},
// futureUse9: {start: 1541, length: 10},
// futureUse10: {start: 1551, length: 10},
// endOfRecordIndicator: {start: 1561, length: 1},
futureUse1: { start: 1491, length: 2 },
futureUse2: { start: 1493, length: 2 },
futureUse3: { start: 1495, length: 5 },
futureUse4: { start: 1500, length: 5 },
futureUse5: { start: 1505, length: 8 },
futureUse6: { start: 1513, length: 8 },
futureUse7: { start: 1521, length: 10 },
futureUse8: { start: 1531, length: 10 },
futureUse9: { start: 1541, length: 10 },
futureUse10: { start: 1551, length: 10 },
endOfRecordIndicator: { start: 1561, length: 1 },
websiteAbbreviation: { start: 1562, length: 4 },
websiteFullSiteName: { start: 1666, length: 15 },
shippingChargedToCustomer: {
start: 1581,
length: 10,
transform: toFloat,
type: 'float',
},

@@ -118,3 +91,3 @@ handlingChargedToCustomer: {

length: 10,
transform: toFloat,
type: 'float',
},

@@ -124,3 +97,3 @@ totalItemCostOfCustomerOrder: {

length: 10,
transform: toFloat,
type: 'float',
},

@@ -130,3 +103,3 @@ totalItemRetailOfCustomerOrder: {

length: 10,
transform: toFloat,
type: 'float',
},

@@ -136,20 +109,17 @@ customerShippingCarrier: { start: 1621, length: 20 },

customerShippingServiceLevel: { start: 1661, length: 20 },
// totalFee1: {start: 1681, length: 10},
// totalFee2: {start: 1691, length: 10},
// totalFee3: {start: 1701, length: 10},
// totalDiscountPromotionsAmounts: {start: 1711, length: 10},
// totalRebateAmounts: {start: 1721, length: 10},
// salesTaxAmount: {start: 1731, length: 10},
// newHeaderReserveField1: {start: 1741, length: 1},
// newHeaderReserveField2: {start: 1742, length: 10},
// newHeaderReserveField3: {start: 1752, length: 10},
// newHeaderReserveField4: {start: 1762, length: 20},
// newHeaderReserveField5: {start: 1782, length: 10},
// newHeaderReserveField6: {start: 1792, length: 10},
totalFee1: { start: 1681, length: 10 },
totalFee2: { start: 1691, length: 10 },
totalFee3: { start: 1701, length: 10 },
totalDiscount: { start: 1711, length: 10 },
totalRebateAmount: { start: 1721, length: 10 },
salesTaxAmount: { start: 1731, length: 10 },
newHeaderReserveField1: { start: 1741, length: 1 },
newHeaderReserveField2: { start: 1742, length: 10 },
newHeaderReserveField3: { start: 1752, length: 10 },
newHeaderReserveField4: { start: 1762, length: 20 },
newHeaderReserveField5: { start: 1782, length: 10 },
newHeaderReserveField6: { start: 1792, length: 10 },
};
layout.TYPE = 'IFOH';
layout.POST_PROCESS = makeDate;
module.exports = layout;

@@ -1,11 +0,7 @@

const { toInt, makeDate } = require('@twec/parser-utils');
const layout = {
recordType: { start: 0, length: 4 },
dateOfRecordCreation: { start: 4, length: 8 },
timeOfRecordCreation: { start: 12, length: 4 },
dateOfRecordCreation: { start: 4, length: 12, type: 'datetime' },
numberOfOrderDetailRecords: {
start: 16,
length: 9,
transform: toInt,
type: 'int',
},

@@ -15,5 +11,5 @@ shipGroupPackageNumber: {

length: 20,
transform: toInt,
type: 'int',
},
endOfRecordIndicator: { start: 45, length: 1 },
endOfRecordIndicator: { start: 45, length: 1, default: '*' },
};

@@ -23,4 +19,2 @@

layout.POST_PROCESS = makeDate;
module.exports = layout;
{
"name": "@twec/ip-parser",
"version": "1.1.0",
"version": "2.0.0",
"description": "Parser for Island Pacific orders",

@@ -27,3 +27,6 @@ "keywords": [

"@twec/parser-utils": "^1.0.0",
"etl": "^0.6.6"
"date-fns-timezone": "^0.1.4",
"debug": "^4.1.1",
"etl": "^0.6.6",
"multistream": "^4.0.0"
},

@@ -30,0 +33,0 @@ "devDependencies": {

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