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

producteca-sdk

Package Overview
Dependencies
Maintainers
3
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

producteca-sdk - npm Package Compare versions

Comparing version 0.0.29 to 0.0.33

build/syncer/adjustmentToNewProductTransformer.js

20

build/product.js

@@ -9,2 +9,5 @@ (function() {

function Product(properties) {
this.updateWith = __bind(this.updateWith, this);
this.toJSON = __bind(this.toJSON, this);
this.updatePrice = __bind(this.updatePrice, this);
this.firstVariation = __bind(this.firstVariation, this);

@@ -32,2 +35,19 @@ this.getVariationForAdjustment = __bind(this.getVariationForAdjustment, this);

Product.prototype.updatePrice = function(priceList, amount) {
return this.prices = _(this.prices).reject({
priceList: priceList
}).concat({
priceList: priceList,
amount: amount
}).value();
};
Product.prototype.toJSON = function() {
return _.omit(this, _.isFunction);
};
Product.prototype.updateWith = function(obj) {
return _.assign(this, obj);
};
return Product;

@@ -34,0 +54,0 @@

25

build/productecaApi.js

@@ -39,2 +39,4 @@ (function() {

this.createShipment = __bind(this.createShipment, this);
this.createProduct = __bind(this.createProduct, this);
this.updateProduct = __bind(this.updateProduct, this);
this.updatePrice = __bind(this.updatePrice, this);

@@ -114,15 +116,18 @@ this.updateStocks = __bind(this.updateStocks, this);

ProductecaApi.prototype.updatePrice = function(product, priceList, amount) {
var body, url;
body = {
prices: _(product.prices).reject({
priceList: priceList
}).concat({
priceList: priceList,
amount: amount
}).value()
};
product.updatePrice(priceList, amount);
return this.updateProduct(product);
};
ProductecaApi.prototype.updateProduct = function(product) {
var url;
url = "/products/" + product.id;
return this["return"](this.asyncClient.putAsync(url, body));
return this["return"](this.asyncClient.putAsync(url, _.omit(product.toJSON(), ["variations"])));
};
ProductecaApi.prototype.createProduct = function(product) {
var url;
url = "/products";
return this["return"](this.asyncClient.postAsync(url, product));
};
ProductecaApi.prototype.createShipment = function(salesOrderId, shipment) {

@@ -129,0 +134,0 @@ return this["return"](this.client.postAsync("/salesorders/" + salesOrderId + "/shipments", shipment));

13

build/syncer/adjustment.js

@@ -46,2 +46,3 @@ (function() {

function Adjustment(dto) {
this.productData = __bind(this.productData, this);
this._adaptStock = __bind(this._adaptStock, this);

@@ -90,5 +91,5 @@ this._adaptPrice = __bind(this._adaptPrice, this);

if (this.prices == null) {
return fn(this.price);
return [fn(this.price)];
}
return this.prices.forEach((function(_this) {
return this.prices.map((function(_this) {
return function(_arg) {

@@ -104,5 +105,5 @@ var priceList, value;

if (this.stocks == null) {
return fn(this.stock);
return [fn(this.stock)];
}
return this.stocks.forEach((function(_this) {
return this.stocks.map((function(_this) {
return function(_arg) {

@@ -124,2 +125,6 @@ var quantity, warehouse;

Adjustment.prototype.productData = function() {
return _.omit(_.omit(this, ['price', 'prices', 'stock', 'stocks', 'identifier', 'sku', 'name']), _.isFunction);
};
return Adjustment;

@@ -126,0 +131,0 @@

(function() {
var Q, Syncer, _,
var AdjustmentToNewProductTransformer, Q, Syncer, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -9,2 +9,4 @@

AdjustmentToNewProductTransformer = require("./adjustmentToNewProductTransformer");
module.exports = Syncer = (function() {

@@ -15,2 +17,4 @@ function Syncer(productecaApi, settings, products) {

this.products = products;
this._createProducts = __bind(this._createProducts, this);
this._shouldSyncProductData = __bind(this._shouldSyncProductData, this);
this._getProductsForAdjustments = __bind(this._getProductsForAdjustments, this);

@@ -20,4 +24,4 @@ this._getVariation = __bind(this._getVariation, this);

this._updateStock = __bind(this._updateStock, this);
this._updatePrice = __bind(this._updatePrice, this);
this._updateStocksAndPrices = __bind(this._updateStocksAndPrices, this);
this._updateProduct = __bind(this._updateProduct, this);
this._sync = __bind(this._sync, this);
this._joinAdjustmentsAndProducts = __bind(this._joinAdjustmentsAndProducts, this);

@@ -28,5 +32,9 @@ this.execute = __bind(this.execute, this);

Syncer.prototype.execute = function(adjustments) {
var adjustmentsAndProducts;
var adjustmentsAndProducts, promises;
adjustmentsAndProducts = this._joinAdjustmentsAndProducts(adjustments);
return (Q.allSettled(this._updateStocksAndPrices(adjustmentsAndProducts))).then((function(_this) {
promises = this._sync(adjustmentsAndProducts);
if (this.settings.createProducts) {
promises = promises.concat(this._createProducts(adjustmentsAndProducts.unlinked));
}
return (Q.allSettled(promises)).then((function(_this) {
return function(results) {

@@ -65,5 +73,5 @@ return _.mapValues(adjustmentsAndProducts, function(adjustmentsAndProducts) {

Syncer.prototype._updateStocksAndPrices = function(adjustmentsAndProducts) {
var syncPrices, syncStocks;
syncPrices = this.settings.synchro.prices;
Syncer.prototype._sync = function(adjustmentsAndProducts) {
var syncProducts, syncStocks;
syncProducts = this._shouldSyncProductData();
syncStocks = this.settings.synchro.stocks;

@@ -82,4 +90,4 @@ return adjustmentsAndProducts.linked.map((function(_this) {

return Q.all(_.flatten([
updateIf(syncPrices, function(p) {
return _this._updatePrice(it.adjustment, p);
updateIf(syncProducts, function(p) {
return _this._updateProduct(it.adjustment, p);
}), updateIf(syncStocks, function(p) {

@@ -98,12 +106,18 @@ return _this._updateStock(it.adjustment, p);

Syncer.prototype._updatePrice = function(adjustment, product) {
return adjustment.forEachPrice((function(_this) {
return function(price, priceList) {
if (priceList == null) {
priceList = _this.settings.priceList;
}
console.log("Updating price of ~" + adjustment.identifier + "(" + product.id + ") in priceList " + priceList + " with value $" + price + "...");
return _this.productecaApi.updatePrice(product, priceList, price);
};
})(this));
Syncer.prototype._updateProduct = function(adjustment, product) {
if (this.settings.synchro.prices) {
adjustment.forEachPrice((function(_this) {
return function(price, priceList) {
if (priceList == null) {
priceList = _this.settings.priceList;
}
console.log("Updating price of ~" + adjustment.identifier + "(" + product.id + ") in priceList " + priceList + " with value $" + price + "...");
return product.updatePrice(priceList, price);
};
})(this));
}
if (this.settings.synchro.data) {
product.updateWith(adjustment.productData());
}
return this.productecaApi.updateProduct(product);
};

@@ -174,2 +188,16 @@

Syncer.prototype._shouldSyncProductData = function() {
return this.settings.synchro.prices || this.settings.synchro.data;
};
Syncer.prototype._createProducts = function(unlinkeds) {
var transformer;
transformer = new AdjustmentToNewProductTransformer(this.settings);
return unlinkeds.map((function(_this) {
return function(unlinked) {
return _this.productecaApi.createProduct(transformer.transform(unlinked.adjustment));
};
})(this));
};
return Syncer;

@@ -176,0 +204,0 @@

@@ -23,3 +23,3 @@ (function() {

describe("Syncer", function() {
var campera, camperaVariable, client, syncer;
var adjustments, campera, camperaVariable, client, syncer;
client = null;

@@ -29,2 +29,3 @@ syncer = null;

camperaVariable = null;
adjustments = null;
beforeEach(function() {

@@ -34,3 +35,4 @@ var settings;

updateStocks: sinon.stub().returns(Q()),
updatePrice: sinon.stub().returns(Q())
updateProduct: sinon.stub().returns(Q()),
createProduct: sinon.stub().returns(Q())
};

@@ -83,3 +85,4 @@ campera = new Product({

prices: true,
stocks: true
stocks: true,
data: true
},

@@ -89,3 +92,3 @@ warehouse: "Villa Crespo",

};
return syncer = new Syncer(client, settings, [
syncer = new Syncer(client, settings, [
campera, camperaVariable, new Product({

@@ -106,28 +109,67 @@ id: 2,

]);
return adjustments = [
new Adjustment({
identifier: "CamperaRompeNocheNegra",
prices: [
{
priceList: "Precios Cuidados",
value: "30"
}, {
priceList: "Con Tarjeta de Crédito",
value: "90"
}
],
stocks: [
{
warehouse: "Villa Lugano",
quantity: 20
}
],
description: "Saraza",
notes: "Lalala"
}), new Adjustment({
identifier: "CamperaRompeNocheBlanca",
prices: [
{
priceList: "Default",
value: "99"
}
],
stocks: [
{
warehouse: "Palermo",
quantity: 38
}
]
})
];
});
describe("en el caso más completo (variantes - multi listaDePrecios / depósito)...", function() {
beforeEach(function() {
describe("los precios y los datos son independientes,", function() {
it("cuando actualizo solo los datos los precios no se modifican", function() {
syncer.settings.identifier = "barcode";
return syncer.execute([
syncer.settings.synchro = {
prices: false,
data: true
};
syncer.execute([
new Adjustment({
identifier: "CamperaRompeNocheNegra",
prices: [],
notes: "Lalala"
})
]);
client.updateProduct.getCall(0).args[0].toJSON().should.not.have.property('prices');
return client.updateProduct.getCall(0).args[0].toJSON().should.have.property('notes', 'Lalala');
});
return it("cuando actualizo solo los precios los datos no se modifican", function() {
syncer.settings.identifier = "barcode";
syncer.settings.synchro = {
prices: true,
data: false
};
syncer.execute([
new Adjustment({
identifier: "CamperaRompeNocheNegra",
prices: [
{
priceList: "Precios Cuidados",
value: "30"
}, {
priceList: "Con Tarjeta de Crédito",
value: "90"
}
],
stocks: [
{
warehouse: "Villa Lugano",
quantity: 20
}
]
}), new Adjustment({
identifier: "CamperaRompeNocheBlanca",
prices: [
{
priceList: "Default",

@@ -137,17 +179,64 @@ value: "99"

],
stocks: [
{
warehouse: "Palermo",
quantity: 38
}
]
notes: "Lalala"
})
]);
client.updateProduct.getCall(0).args[0].toJSON().prices.should.eql([
{
priceList: "Default",
amount: 99
}
]);
return client.updateProduct.getCall(0).args[0].toJSON().should.not.have.property('notes');
});
it("actualiza los precios", function() {
client.updatePrice.should.have.callCount(3);
client.updatePrice.should.have.been.calledWith(camperaVariable, "Precios Cuidados", 30);
client.updatePrice.should.have.been.calledWith(camperaVariable, "Con Tarjeta de Crédito", 90);
return client.updatePrice.should.have.been.calledWith(camperaVariable, "Default", 99);
});
describe("en el caso más completo (variantes - multi listaDePrecios / depósito)...", function() {
beforeEach(function() {
syncer.settings.identifier = "barcode";
return syncer.execute(adjustments);
});
it("actualiza los precios y los datos", function() {
var json;
client.updateProduct.should.have.callCount(2);
json = {
id: 1,
sku: "123456",
description: "Campera De Cuero Para Romper La Noche En Muchos Colores",
prices: [
{
priceList: "Precios Cuidados",
amount: 30
}, {
priceList: "Con Tarjeta de Crédito",
amount: 90
}, {
priceList: "Default",
amount: 99
}
],
variations: [
{
id: 2,
barcode: "CamperaRompeNocheNegra",
stocks: [
{
warehouse: "Villa Crespo",
quantity: 12
}
]
}, {
id: 4,
barcode: "CamperaRompeNocheBlanca",
stocks: [
{
warehouse: "Villa Crespo",
quantity: 16
}
]
}
],
description: "Saraza",
notes: "Lalala"
};
return client.updateProduct.getCall(0).args[0].toJSON().should.eql(json);
});
return it("actualiza los stocks", function() {

@@ -177,2 +266,52 @@ client.updateStocks.should.have.callCount(2);

});
describe("si hay adjustments de productos nuevos", function() {
beforeEach(function() {
syncer.settings.identifier = "barcode";
return adjustments.push(new Adjustment({
identifier: "NuevoProducto",
name: "Campera de lana para losers",
prices: [
{
priceList: "Default",
value: "555"
}
],
stocks: [
{
warehouse: "Palermo",
quantity: 11
}
]
}));
});
it("no crea productos si createProduct es false", function() {
syncer.settings.createProducts = false;
syncer.execute(adjustments);
return client.createProduct.should.not.have.been.called;
});
return it("crea productos si createProduct es true", function() {
syncer.settings.createProducts = true;
syncer.execute(adjustments);
return client.createProduct.should.have.been.calledWith({
description: "Campera de lana para losers",
prices: [
{
priceList: "Default",
amount: 555
}
],
variations: [
{
barcode: "NuevoProducto",
stocks: [
{
warehouse: "Palermo",
quantity: 11
}
]
}
]
});
});
});
describe("cuando los productos no tienen variantes...", function() {

@@ -228,5 +367,19 @@ var ajuste;

return it("para actualizar el precio", function() {
return client.updatePrice.should.have.been.calledWith(campera, "Meli", 25);
return client.updateProduct.should.have.been.calledWith(campera);
});
});
it("actualiza el producto si en las settings digo que quiero sincronizar precios", function() {
syncer.settings.synchro = {
prices: true
};
syncer.execute([ajuste]);
return client.updateProduct.called.should.be["true"];
});
it("actualiza el producto si en las settings digo que quiero sincronizar datos", function() {
syncer.settings.synchro = {
data: true
};
syncer.execute([ajuste]);
return client.updateProduct.called.should.be["true"];
});
it("si en las settings digo que no quiero sincronizar precios, no lo hace", function() {

@@ -238,5 +391,14 @@ syncer.settings.synchro = {

syncer.execute([ajuste]);
client.updatePrice.called.should.be["false"];
client.updateProduct.called.should.be["false"];
return client.updateStocks.called.should.be["true"];
});
it("si en las settings digo que no quiero sincronizar datos, no lo hace", function() {
syncer.settings.synchro = {
data: false,
stocks: true
};
syncer.execute([ajuste]);
client.updateProduct.called.should.be["false"];
return client.updateStocks.called.should.be["true"];
});
return it("si en las settings digo que no quiero sincronizar stocks, no lo hace", function() {

@@ -248,3 +410,3 @@ syncer.settings.synchro = {

syncer.execute([ajuste]);
client.updatePrice.called.should.be["true"];
client.updateProduct.called.should.be["true"];
return client.updateStocks.called.should.be["false"];

@@ -251,0 +413,0 @@ });

@@ -8,3 +8,3 @@ {

},
"version": "0.0.29",
"version": "0.0.33",
"main": "build/sdk.js",

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

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