yaas-sdk
Version:
Javascript YAAS SDK
549 lines (424 loc) • 24.1 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.YAAS_SDK = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _client = __webpack_require__(1);
var _cart = __webpack_require__(2);
var _coupon = __webpack_require__(4);
var _customer = __webpack_require__(5);
var _product = __webpack_require__(6);
var _salesorder = __webpack_require__(7);
var _serviceticket = __webpack_require__(8);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var YAAS_SDK = exports.YAAS_SDK = function () {
function YAAS_SDK(tenant, token) {
_classCallCheck(this, YAAS_SDK);
var client = new _client.YAAS_Client(token);
this.cart = new _cart.Cart(client, tenant);
this.coupon = new _coupon.Coupon(client, tenant);
this.customer = new _customer.Customer(client, tenant);
this.product = new _product.Product(client, tenant);
this.salesOrder = new _salesorder.SalesOrder(client, tenant);
this.serviceTicket = new _serviceticket.ServiceTicket(client, tenant);
}
_createClass(YAAS_SDK, null, [{
key: 'createWithCredentials',
value: function createWithCredentials(tenant, clientId, clientSecret, scope) {
return YAAS_SDK.getAccessTokenFromCredentials(clientId, clientSecret, scope).then(function (data) {
return new YAAS_SDK(tenant, data.access_token);
});
}
}, {
key: 'getAccessTokenFromCredentials',
value: function getAccessTokenFromCredentials(clientId, clientSecret, scope) {
var ep = 'https://api.yaas.io/hybris/oauth2/v1/token';
return _client.YAAS_Client.getAccessTokenFromCredentials(ep, clientId, clientSecret, scope);
}
}]);
return YAAS_SDK;
}();
//# sourceMappingURL=index.js.map
/***/ },
/* 1 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var YAAS_Client = exports.YAAS_Client = function () {
function YAAS_Client(token) {
_classCallCheck(this, YAAS_Client);
this.token = token;
}
_createClass(YAAS_Client, [{
key: 'ws',
value: function ws(path, method, query, body) {
return YAAS_Client.ws(path, method, query, body, this.token);
}
}], [{
key: 'ws',
value: function ws(path, method, query, body, token) {
var url = path;
var opts = {
method: (method || 'GET').toUpperCase(),
mode: 'cors',
credentials: 'omit',
headers: {}
};
if (query) {
var qs = [];
for (var i in query) {
qs.push(encodeURIComponent(i) + '=' + encodeURIComponent(query[i]));
}
if (qs.length) {
url += '?' + qs.join('&');
}
}
if (typeof body === 'string') {
opts.headers['Content-Type'] = 'application/x-www-form-urlencoded';
opts.body = body;
} else if ((typeof body === 'undefined' ? 'undefined' : _typeof(body)) === 'object') {
opts.headers['Content-Type'] = 'application/json';
opts.body = JSON.stringify(body);
}
if (token) {
opts.headers['Authorization'] = 'Bearer ' + token;
}
return fetch(url, opts).then(function (response) {
if (response.ok) {
if (response.headers.get('Content-Type') === 'application/json') {
return response.json();
} else {
return response.text();
}
} else {
throw response.status;
}
});
}
}, {
key: 'getAccessTokenFromCredentials',
value: function getAccessTokenFromCredentials(ep, clientId, clientSecret, scope) {
var body = ["grant_type=client_credentials", "scope=" + (scope && scope.join ? scope.join(' ') : scope || ''), "client_id=" + clientId, "client_secret=" + clientSecret].join('&');
return YAAS_Client.ws(ep, 'POST', null, body);
}
}]);
return YAAS_Client;
}();
//# sourceMappingURL=client.js.map
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Cart = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Cart = exports.Cart = function (_YAAS_API) {
_inherits(Cart, _YAAS_API);
function Cart(client, tenant) {
_classCallCheck(this, Cart);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Cart).call(this, client, tenant, 'https://api.yaas.io/hybris/cart/v1'));
}
_createClass(Cart, [{
key: 'query',
value: function query(opts) {
return this.ws('/carts', 'GET', opts);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/carts/' + id, 'GET', opts);
}
}]);
return Cart;
}(_api.YAAS_API);
//# sourceMappingURL=cart.js.map
/***/ },
/* 3 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var YAAS_API = exports.YAAS_API = function () {
function YAAS_API(client, tenant, baseURL) {
_classCallCheck(this, YAAS_API);
this.client = client;
this.tenant = tenant;
this.baseURL = baseURL;
}
_createClass(YAAS_API, [{
key: 'ws',
value: function ws(path, method, query, body) {
return this.client.ws(this.baseURL + '/' + this.tenant + path, method, query, body);
}
}]);
return YAAS_API;
}();
//# sourceMappingURL=api.js.map
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Coupon = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Coupon = exports.Coupon = function (_YAAS_API) {
_inherits(Coupon, _YAAS_API);
function Coupon(client, tenant) {
_classCallCheck(this, Coupon);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Coupon).call(this, client, tenant, 'https://api.yaas.io/hybris/coupon/v1'));
}
_createClass(Coupon, [{
key: 'query',
value: function query(opts) {
return this.ws('/coupons', 'GET', opts);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/coupons/' + id, 'GET', opts);
}
}]);
return Coupon;
}(_api.YAAS_API);
//# sourceMappingURL=coupon.js.map
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Customer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Customer = exports.Customer = function (_YAAS_API) {
_inherits(Customer, _YAAS_API);
function Customer(client, tenant) {
_classCallCheck(this, Customer);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Customer).call(this, client, tenant, 'https://api.yaas.io/hybris/customer/v1'));
}
_createClass(Customer, [{
key: 'query',
value: function query(opts) {
return this.ws('/customers', 'GET', opts);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/customers/' + id, 'GET', opts);
}
}, {
key: 'addresses',
value: function addresses(id, opts) {
return this.ws('/customers/' + id + '/addresses', 'GET', opts);
}
}, {
key: 'address',
value: function address(id, addrId, opts) {
return this.ws('/customers/' + id + '/addresses/' + addrId, 'GET', opts);
}
}]);
return Customer;
}(_api.YAAS_API);
//# sourceMappingURL=customer.js.map
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Product = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Product = exports.Product = function (_YAAS_API) {
_inherits(Product, _YAAS_API);
function Product(client, tenant) {
_classCallCheck(this, Product);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Product).call(this, client, tenant, 'https://api.yaas.io/hybris/product/v1'));
}
_createClass(Product, [{
key: 'query',
value: function query(opts) {
return this.ws('/products', 'GET', opts);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/products/' + id, 'GET', opts);
}
}]);
return Product;
}(_api.YAAS_API);
//# sourceMappingURL=product.js.map
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SalesOrder = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var SalesOrder = exports.SalesOrder = function (_YAAS_API) {
_inherits(SalesOrder, _YAAS_API);
function SalesOrder(client, tenant) {
_classCallCheck(this, SalesOrder);
return _possibleConstructorReturn(this, Object.getPrototypeOf(SalesOrder).call(this, client, tenant, 'https://api.yaas.io/hybris/order/v1'));
}
_createClass(SalesOrder, [{
key: 'query',
value: function query(opts) {
return this.ws('/salesorders', 'GET', opts);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/salesorders/' + id, 'GET', opts);
}
}]);
return SalesOrder;
}(_api.YAAS_API);
//# sourceMappingURL=salesorder.js.map
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ServiceTicket = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _api = __webpack_require__(3);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ServiceTicket = exports.ServiceTicket = function (_YAAS_API) {
_inherits(ServiceTicket, _YAAS_API);
function ServiceTicket(client, tenant) {
_classCallCheck(this, ServiceTicket);
return _possibleConstructorReturn(this, Object.getPrototypeOf(ServiceTicket).call(this, client, tenant, 'https://api.yaas.io/hybris/serviceticketmashup/v1'));
}
_createClass(ServiceTicket, [{
key: 'query',
value: function query(opts) {
return this.ws('/serviceTickets', 'GET', opts);
}
}, {
key: 'create',
value: function create(data, opts) {
return this.ws('/serviceTickets', 'POST', opts, data);
}
}, {
key: 'get',
value: function get(id, opts) {
return this.ws('/serviceTickets/' + id, 'GET', opts);
}
}, {
key: 'update',
value: function update(id, data, opts) {
return this.ws('/serviceTickets/' + id, 'PUT', opts, data);
}
}, {
key: 'remove',
value: function remove(id, opts) {
return this.ws('/serviceTickets/' + id, 'DELETE', opts);
}
}, {
key: 'priorities',
value: function priorities(opts) {
return this.ws('/serviceTicketPriorities', 'GET', opts);
}
}, {
key: 'types',
value: function types(opts) {
return this.ws('/serviceTicketTypes', 'GET', opts);
}
}, {
key: 'classifications',
value: function classifications(opts) {
return this.ws('/serviceTicketClassifications', 'GET', opts);
}
}]);
return ServiceTicket;
}(_api.YAAS_API);
//# sourceMappingURL=serviceticket.js.map
/***/ }
/******/ ])
});
;