baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
240 lines (239 loc) • 10.6 kB
JavaScript
"use strict";
/* globals module */
/**
* @module commerceClient
* @description Commerce Client provides an easy way to consume Commerce REST API end-points. In order to obtain a needed routes `commerceClient` uses `commerceRoute`.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var inversify_1 = require("inversify");
var httpApi_1 = require("../../httpApi");
var _1 = require("./");
var CommerceClient = /** @class */ (function () {
function CommerceClient(commerceCustomerClient, commerceInvoiceClient, commerceProductClient, commerceProductFilesClient, commerceProductSettingsClient, commercePaymentTransactionClient, commerceCouponClient, commerceCouponUseClient, lookup, commerceRoute, apiClient) {
this.commerceCustomerClient = commerceCustomerClient;
this.commerceInvoiceClient = commerceInvoiceClient;
this.commerceProductClient = commerceProductClient;
this.commerceProductFilesClient = commerceProductFilesClient;
this.commerceProductSettingsClient = commerceProductSettingsClient;
this.commercePaymentTransactionClient = commercePaymentTransactionClient;
this.commerceCouponClient = commerceCouponClient;
this.commerceCouponUseClient = commerceCouponUseClient;
this.lookup = lookup;
this.commerceRoute = commerceRoute;
this.apiClient = apiClient;
}
Object.defineProperty(CommerceClient.prototype, "customers", {
get: function () {
return this.commerceCustomerClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "invoices", {
get: function () {
return this.commerceInvoiceClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "products", {
get: function () {
return this.commerceProductClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "files", {
get: function () {
return this.commerceProductFilesClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "settings", {
get: function () {
return this.commerceProductSettingsClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "paymentTransactions", {
get: function () {
return this.commercePaymentTransactionClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "coupons", {
get: function () {
return this.commerceCouponClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "couponUses", {
get: function () {
return this.commerceCouponUseClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "lookups", {
get: function () {
return this.lookup;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CommerceClient.prototype, "routeDefinition", {
get: function () {
return this.commerceRoute;
},
enumerable: true,
configurable: true
});
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of commerce resources matching the given criteria.
* @method
* @example commerceClient.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',
customerId: '<customer-id>'
})
.then(function (collection) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.find = function (options) {
return this.apiClient.get(this.routeDefinition.find(options));
};
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns the commerce resource.
* @method
* @example commerceClient.get('<id>', {})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.get = function (id, options) {
return this.apiClient.get(this.commerceRoute.get(id, options));
};
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns the commerce resource.
* @method
* @example commerceClient.validateVAT({ countryCode: 'DE', vatId: 'DE999999999' })
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.validateVAT = function (countryCode, vatId) {
return this.apiClient.get(this.commerceRoute.validateVAT(countryCode, vatId));
};
/**
* Returns a promise that is resolved once the subscribe pre-process commerce action has been performed; this action performes pre-subscribe operations such as getting client tokens etc.
* @method
* @example commerceClient.preprocess({
systemName : '<system-name>',
productId : '<product-id>',
customerId: '<id>'
})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.preprocess = function (data) {
return this.apiClient.post(this.routeDefinition.preprocess(), this.routeDefinition.createParams(data));
};
/**
* Returns a promise that is resolved once the subscribe commerce action has been performed; this action creates a new commerce subscription resource.
* @method
* @example commerceClient.subscribe({
systemName : '<system-name>',
productId : '<product-id>',
customer: {
id: '<id>',
firstName: '<first-name>',
lastName: '<last-name>'
}
})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.subscribe = function (data) {
return this.apiClient.post(this.routeDefinition.subscribe(), this.routeDefinition.createParams(data));
};
/**
* Returns a promise that is resolved once the cancel subscription action has been performed. This action will remove a commerce subscription resource from the system if successfully completed. This route obtain routes from `commerceRoute` route template. Here is an example of how execute this action:
* @method
* @example commerceClient.cancel({
systemName: '<system-name>',
id: '<subscription-id>',
requestRefund: <true/false>,
refundAmount: <refund-amount>
})
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
CommerceClient.prototype.cancel = function (data) {
return this.apiClient.delete(this.routeDefinition.cancel(data));
};
CommerceClient = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(_1.TYPES.CommerceCustomerClient)),
tslib_1.__param(1, inversify_1.inject(_1.TYPES.CommerceInvoiceClient)),
tslib_1.__param(2, inversify_1.inject(_1.TYPES.CommerceProductClient)),
tslib_1.__param(3, inversify_1.inject(_1.TYPES.CommerceProductFilesClient)),
tslib_1.__param(4, inversify_1.inject(_1.TYPES.CommerceProductSettingsClient)),
tslib_1.__param(5, inversify_1.inject(_1.TYPES.CommercePaymentTransactionClient)),
tslib_1.__param(6, inversify_1.inject(_1.TYPES.CommerceCouponClient)),
tslib_1.__param(7, inversify_1.inject(_1.TYPES.CommerceCouponUseClient)),
tslib_1.__param(8, inversify_1.inject(_1.TYPES.Lookups)),
tslib_1.__param(9, inversify_1.inject(_1.TYPES.CommerceRoute)),
tslib_1.__param(10, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)),
tslib_1.__metadata("design:paramtypes", [_1.CommerceCustomerClient,
_1.CommerceInvoiceClient,
_1.CommerceProductClient,
_1.CommerceProductFilesClient,
_1.CommerceProductSettingsClient,
_1.CommercePaymentTransactionClient,
_1.CommerceCouponClient,
_1.CommerceCouponUseClient,
_1.Lookups,
_1.CommerceRoute,
httpApi_1.ApiClient])
], CommerceClient);
return CommerceClient;
}());
exports.CommerceClient = CommerceClient;
/**
* @copyright (c) 2017 Mono Ltd
* @license MIT
* @author Mono Ltd
* @overview
***Notes:**
- Refer to the [Baasic REST API](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points.
- All end-point objects are transformed by the associated route service.
*/