New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

almex-sdk

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

almex-sdk - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

build/almexInboundsAdapter.js

131

build/almexApi.js
(function() {
var AlmexApi, AlmexOrdersAdapter, Promise, XmlBuilder, read, req, xml2js,
var AlmexApi, AlmexInboundsAdapter, AlmexOrdersAdapter, Promise, XmlBuilder, read, req, xml2js, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -17,2 +17,6 @@

AlmexInboundsAdapter = require("./almexInboundsAdapter");
_ = require("lodash");
module.exports = AlmexApi = (function() {

@@ -25,3 +29,5 @@ function AlmexApi(credentials, url) {

this._doRequest = __bind(this._doRequest, this);
this.adaptPurchaseOrder = __bind(this.adaptPurchaseOrder, this);
this.adaptSalesOrder = __bind(this.adaptSalesOrder, this);
this.createInputBean = __bind(this.createInputBean, this);
this.createOutputBean = __bind(this.createOutputBean, this);

@@ -34,13 +40,21 @@ this.getStocks = __bind(this.getStocks, this);

})(this);
this.requests = {
this.requests = _.mapValues({
createInputBean: {
endpoint: "CkWService"
},
createOutputBean: {
endpoint: "CkWService",
xml: auth(read("" + __dirname + "/resources/createOutputBean.xml", "utf-8"))
endpoint: "CkWService"
},
stocks: {
endpoint: "Jobs",
xml: auth(read("" + __dirname + "/resources/stocks.xml", "utf-8"))
endpoint: "Jobs"
}
};
}, (function(_this) {
return function(val, name) {
return _.assign(val, {
xml: auth(read("" + __dirname + "/resources/" + name + ".xml", "utf-8"))
});
};
})(this));
this.ordersAdapter = new AlmexOrdersAdapter();
this.inboundsAdapter = new AlmexInboundsAdapter();
}

@@ -54,14 +68,12 @@

AlmexApi.prototype.getStocks = function() {
return this._doRequest(this.requests.stocks).spread((function(_this) {
return function(response) {
return xml2js.parseStringAsync(response.body).then(function(xml) {
var stocks;
stocks = _this._getResult(xml, "ProductoInventarioMethod");
return stocks.map(function(it) {
return {
identifier: it.productoSku[0],
name: it.descripcion[0],
stock: it.cantidadInventario[0]
};
});
return this._doRequest(this.requests.stocks).then((function(_this) {
return function(xml) {
var stocks;
stocks = _this._getResult(xml, "ProductoInventarioMethod");
return stocks.map(function(it) {
return {
identifier: it.productoSku[0],
name: it.descripcion[0],
stock: it.cantidadInventario[0]
};
});

@@ -92,12 +104,10 @@ };

};
})(this)).spread((function(_this) {
return function(response) {
return xml2js.parseStringAsync(response.body).then(function(xml) {
var statusCode;
statusCode = _this._getResult(xml, "requestOutputBean")[0]._;
if (statusCode !== "OK") {
throw new Error(JSON.stringify(xml));
}
return xml;
});
})(this)).then((function(_this) {
return function(xml) {
var statusCode;
statusCode = _this._getResult(xml, "requestOutputBean")[0]._;
if (statusCode !== "OK") {
throw new Error(JSON.stringify(xml));
}
return xml;
};

@@ -109,5 +119,47 @@ })(this));

/*
Get the xml of an order.
Create an input bean
inbound = {
id: Number
date: Date
products: [
id: String
quantity: Number
description: String
(barcode: String) # optional
]
}
options = { log: false }
*/
AlmexApi.prototype.createInputBean = function(inbound, options) {
var inputBeanXml, request;
if (options == null) {
options = {};
}
inputBeanXml = this.adaptPurchaseOrder(inbound);
request = this.requests.createInputBean;
if (options.log != null) {
console.log(inputBeanXml);
}
return this._doRequest(request, (function(_this) {
return function() {
return inputBeanXml;
};
})(this)).then((function(_this) {
return function(xml) {
var statusCode;
statusCode = _this._getResult(xml, "requestInputBean")[0]._;
if (statusCode !== "OK") {
throw new Error(JSON.stringify(xml));
}
return xml;
};
})(this));
};
/*
Get the xml of a sales order.
*/
AlmexApi.prototype.adaptSalesOrder = function(order) {

@@ -119,2 +171,13 @@ var outputBean;

/*
Get the xml of a purchase order.
*/
AlmexApi.prototype.adaptPurchaseOrder = function(inbound) {
var inputBean;
inputBean = this.inboundsAdapter.getInputBean(inbound);
return new XmlBuilder(this.requests.createInputBean.xml).buildWith(inputBean);
};
AlmexApi.prototype._doRequest = function(request, adapt) {

@@ -136,3 +199,7 @@ var params;

};
return req.postAsync(params);
return req.postAsync(params).spread((function(_this) {
return function(response) {
return xml2js.parseStringAsync(response.body);
};
})(this));
};

@@ -148,3 +215,3 @@

if (result == null) {
throw new Error("Los web services de la vida, no son lo que yo esperaba, no son lo que yo creía, no son lo que imaginaba...");
throw new Error("Los web services de la vida, no son lo que yo esperaba, no son lo que yo creía, no son lo que imaginaba...\n" + JSON.stringify(xml));
}

@@ -151,0 +218,0 @@ return result;

(function() {
var AlmexOrdersAdapter, XmlBuilder,
var AlmexOrdersAdapter, XmlBuilder, moment,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -7,2 +7,4 @@

moment = require("moment");
module.exports = AlmexOrdersAdapter = (function() {

@@ -47,3 +49,3 @@ function AlmexOrdersAdapter() {

})(this)),
fechaEntrega: order.date.substr(0, order.date.indexOf("T"))
fechaEntrega: moment(order.date).format("YYYY-MM-DD")
};

@@ -50,0 +52,0 @@ };

@@ -8,7 +8,8 @@ {

},
"version": "0.0.13",
"version": "0.0.14",
"main": "build/almexApi.js",
"dependencies": {
"bluebird": "^2.3.11",
"lodash": "~2.4.1"
"lodash": "^3.10.0",
"moment": "^2.10.6"
},

@@ -15,0 +16,0 @@ "devDependencies": {

# almex-sdk
SDK of the Almex Web Services

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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