This repository has been archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from afirlejczyk/feature/magento1-client
Magento1 vsbridge client.
- Loading branch information
Showing
27 changed files
with
912 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class AbstractAddressProxy { | ||
constructor(config, req) { | ||
this._config = config | ||
this._request = req | ||
} | ||
|
||
list (customerToken) { | ||
throw new Error('AbstractAddressProxy::list must be implemented for specific platform') | ||
} | ||
update (customerToken, addressData) { | ||
throw new Error('AbstractAddressProxy::update must be implemented for specific platform') | ||
} | ||
get (customerToken, addressId) { | ||
throw new Error('AbstractAddressProxy::get must be implemented for specific platform') | ||
} | ||
delete (customerToken, addressData) { | ||
throw new Error('AbstractAddressProxy::delete must be implemented for specific platform') | ||
} | ||
} | ||
|
||
export default AbstractAddressProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AbstractContactProxy { | ||
submit (formData) { | ||
throw new Error('AbstractContactProxy::check must be implemented for specific platform') | ||
} | ||
} | ||
|
||
module.exports = AbstractContactProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AbstractNewsletterProxy { | ||
subscribe (emailAddress) { | ||
} | ||
|
||
unsubscribe (customerToken) { | ||
} | ||
} | ||
|
||
module.exports = AbstractNewsletterProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AbstractStockAlertProxy { | ||
constructor(config, req) { | ||
this._config = config | ||
this._request = req | ||
} | ||
subscribe (customerToken, productId, emailAddress) { | ||
throw new Error('AbstractContactProxy::subscribe must be implemented for specific platform') | ||
} | ||
} | ||
|
||
export default AbstractStockAlertProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AbstractWishlistProxy { | ||
pull (customerToken) { | ||
throw new Error('AbstractWishlistProxy::pull must be implemented for specific platform') | ||
} | ||
update (customerToken, wishListItem) { | ||
throw new Error('AbstractWishlistProxy::update must be implemented for specific platform') | ||
} | ||
delete (customerToken, wishListItem) { | ||
throw new Error('AbstractWishlistProxy::delete must be implemented for specific platform') | ||
} | ||
} | ||
|
||
module.exports = AbstractWishlistProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import AbstractAddressProxy from '../abstract/address' | ||
import {multiStoreConfig} from "./util"; | ||
import {Magento1Client} from "./module"; | ||
|
||
class AddressProxy extends AbstractAddressProxy { | ||
constructor (config, req){ | ||
super(config, req) | ||
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req)); | ||
} | ||
list (customerToken) { | ||
return this.api.address.list(customerToken) | ||
} | ||
update (customerToken, addressData) { | ||
return this.api.address.update(customerToken, addressData); | ||
} | ||
get (customerToken, addressId) { | ||
return this.api.address.get(customerToken, addressId) | ||
} | ||
delete (customerToken, addressData) { | ||
return this.api.address.delete(customerToken, addressData) | ||
} | ||
} | ||
|
||
module.exports = AddressProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import AbstractCartProxy from '../abstract/cart'; | ||
import { multiStoreConfig } from './util'; | ||
import { Magento1Client } from './module/index'; | ||
|
||
class CartProxy extends AbstractCartProxy { | ||
constructor (config, req){ | ||
super(config, req) | ||
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req)); | ||
} | ||
create (customerToken) { | ||
return this.api.cart.create(customerToken); | ||
} | ||
update (customerToken, cartId, cartItem) { | ||
return this.api.cart.update(customerToken, cartId, cartItem); | ||
} | ||
delete (customerToken, cartId, cartItem) { | ||
return this.api.cart.delete(customerToken, cartId, cartItem); | ||
} | ||
pull (customerToken, cartId, params) { | ||
return this.api.cart.pull(customerToken, cartId, params); | ||
} | ||
totals (customerToken, cartId, params) { | ||
return this.api.cart.totals(customerToken, cartId, params); | ||
} | ||
getShippingMethods (customerToken, cartId, address) { | ||
return this.api.cart.shippingMethods(customerToken, cartId, address); | ||
} | ||
getPaymentMethods (customerToken, cartId) { | ||
return this.api.cart.paymentMethods(customerToken, cartId); | ||
} | ||
setShippingInformation (customerToken, cartId, address) { | ||
return this.api.cart.shippingInformation(customerToken, cartId, address); | ||
} | ||
collectTotals (customerToken, cartId, shippingMethod) { | ||
return this.api.cart.collectTotals(customerToken, cartId, shippingMethod); | ||
} | ||
applyCoupon (customerToken, cartId, coupon) { | ||
return this.api.cart.applyCoupon(customerToken, cartId, coupon); | ||
} | ||
deleteCoupon (customerToken, cartId) { | ||
return this.api.cart.deleteCoupon(customerToken, cartId); | ||
} | ||
getCoupon (customerToken, cartId) { | ||
return this.api.cart.getCoupon(customerToken, cartId); | ||
} | ||
} | ||
|
||
module.exports = CartProxy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import AbstractContactProxy from '../abstract/contact'; | ||
import { multiStoreConfig } from './util'; | ||
import { Magento1Client } from './module/index'; | ||
|
||
class ContactProxy extends AbstractContactProxy { | ||
constructor (config, req){ | ||
super(config, req) | ||
this.api = Magento1Client(multiStoreConfig(config.magento1.api, req)); | ||
} | ||
submit (form) { | ||
return this.api.contact.submit(form); | ||
} | ||
} | ||
|
||
module.exports = ContactProxy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const RestClient = require('./lib/rest_client').RestClient; | ||
const user = require('./lib/user'); | ||
const cart = require('./lib/cart'); | ||
const stock = require('./lib/stock'); | ||
const contact = require('./lib/contact'); | ||
const wishlist = require('./lib/wishlist'); | ||
const stockAlert = require('./lib/stock_alert'); | ||
const newsletter = require('./lib/newsletter'); | ||
const address = require('./lib/address'); | ||
|
||
const MAGENTO_API_VERSION = 'V1'; | ||
|
||
module.exports.Magento1Client = function (options) { | ||
let instance = { | ||
addMethods (key, module) { | ||
let client = RestClient(options); | ||
if (module) { | ||
if (this[key]) | ||
this[key] = Object.assign(this[key], module(client)); | ||
else | ||
this[key] = module(client); | ||
} | ||
} | ||
}; | ||
|
||
options.version = MAGENTO_API_VERSION; | ||
|
||
let client = RestClient(options); | ||
|
||
instance.user = user(client); | ||
instance.cart = cart(client); | ||
instance.stock = stock(client); | ||
instance.contact = contact(client); | ||
instance.wishlist = wishlist(client); | ||
instance.stockAlert = stockAlert(client); | ||
instance.newsletter = newsletter(client); | ||
instance.address = address(client); | ||
|
||
return instance; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = function (restClient) { | ||
let module = {}; | ||
let url = 'address/'; | ||
function getResponse(data){ | ||
if (data.code === 200){ | ||
return data.result; | ||
} | ||
|
||
return false; | ||
} | ||
module.list = function (customerToken) { | ||
url += `list?token=${customerToken}` | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
}, | ||
module.update = function (customerToken, addressData) { | ||
url += `update?token=${customerToken}` | ||
return restClient.post(url, {address: addressData}).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.get = function (customerToken, addressId) { | ||
url += `get?token=${customerToken}&addressId=${addressId}` | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.delete = function (customerToken, addressData) { | ||
url += `delete?token=${customerToken}` | ||
return restClient.post(url, {address: addressData}).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
return module; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
function isNumeric(val) { | ||
return Number(parseFloat(val)).toString() === val; | ||
} | ||
|
||
module.exports = function (restClient) { | ||
let module = {}; | ||
const urlPrefix = 'cart/'; | ||
let url = urlPrefix; | ||
function getResponse(data){ | ||
if(data.code === 200){ | ||
return data.result; | ||
} | ||
return false; | ||
} | ||
module.create = (customerToken) => { | ||
url += `create?token=${customerToken}`; | ||
return restClient.post(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.update = (customerToken, cartId, cartItem) => { | ||
url += `update?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.post(url, { cartItem: cartItem }).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.applyCoupon = (customerToken, cartId, coupon) => { | ||
url += `applyCoupon?token=${customerToken}&cartId=${cartId}&coupon=${coupon}`; | ||
return restClient.post(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.deleteCoupon = (customerToken, cartId) => { | ||
url += `deleteCoupon?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.post(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.delete = (customerToken, cartId, cartItem) => { | ||
url += `delete?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.post(url, { cartItem: cartItem }).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.pull = (customerToken, cartId) => { | ||
url += `pull?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.totals = (customerToken, cartId) => { | ||
url += `totals?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.shippingInformation = (customerToken, cartId, body) => { | ||
url += `totals?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.post(url, body).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.shippingMethods = (customerToken, cartId, address) => { | ||
url += `shippingMethods?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.post(url, { address: address }).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.paymentMethods = (customerToken, cartId) => { | ||
url += `paymentMethods?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
module.getCoupon = (customerToken, cartId) => { | ||
url += `coupon?token=${customerToken}&cartId=${cartId}`; | ||
return restClient.get(url).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
} | ||
return module; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function (restClient) { | ||
let module = {}; | ||
const urlPrefix = 'contact/'; | ||
let url = urlPrefix; | ||
function getResponse(data){ | ||
if(data.code === 200){ | ||
return data.result; | ||
} | ||
return false; | ||
} | ||
module.submit = (form) => { | ||
url += `submit`; | ||
return restClient.post(url, {form}).then((data)=> { | ||
return getResponse(data); | ||
}); | ||
}; | ||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var winston = require('winston'); | ||
|
||
winston.emitErrs = true; | ||
|
||
var logger = new winston.Logger({ | ||
transports: [ | ||
new winston.transports.Console({ | ||
level: 'debug', | ||
handleExceptions: true, | ||
json: false, | ||
colorize: true | ||
}) | ||
], | ||
exitOnError: false | ||
}); | ||
|
||
logger.info('Winston logging library initialized.'); | ||
|
||
module.exports = logger; |
Oops, something went wrong.