@apihawk/billia-sdk
Version:
The ApiHawk Billia SDK
132 lines (131 loc) • 4.71 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const billia_sdk_service_base_1 = require("../lib/billia-sdk-service-base");
class BilliaSDKSystem extends billia_sdk_service_base_1.BilliaSDKServiceBase {
/**
* Fetches the Billia system settings.
*/
getSystemSettings() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.api.call({
url: '/system/settings',
method: 'GET',
headers: {
Accept: 'application/hal+json',
'Content-Type': 'application/json'
}
});
const systemSettings = response._embedded.settings[0];
return systemSettings;
});
}
/**
* Fetches the Billia supported languages.
*/
getSystemLanguages() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.api.call({
url: '/system/language',
method: 'GET',
headers: {
Accept: 'application/hal+json',
'Content-Type': 'application/json'
}
});
const languages = response._embedded.system_language.map((lang) => {
lang.default = lang.default === '1' ? true : false;
return lang;
});
return languages;
});
}
/**
* Lists all enabled system countries.
*
* @returns {Promise<ISystemCountry[]>}
*/
getCountries() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.api.call({
url: '/system/country',
method: 'GET',
headers: {
Accept: 'application/hal+json',
'Content-Type': 'application/json'
},
query: { page_size: -1, order: [{ field: 'nicename', sort: 'ASC' }] }
});
const countries = response._embedded.country;
// we need to filter out non-enabled countries
// and unnecessary properties
return countries
.filter((c) => Number(c.status) === 1)
.map((c) => {
const country = {
iso: c.iso,
nicename: c.nicename,
phonecode: c.phonecode
};
return country;
});
});
}
/**
* Get branding
* @param {string} component
* @returns {Promise<any>}
*/
getBrandingSimple(component) {
return __awaiter(this, void 0, void 0, function* () {
let url = '/system/branding';
if (component) {
url += `/${component}`;
}
return this.api
.call({
url,
method: 'GET',
headers: {
Accept: 'application/hal+json',
'Content-Type': 'application/json'
}
})
.then((branding) => {
if (component) {
return Promise.resolve(branding.value);
}
else {
return Promise.resolve(branding._embedded.system_branding.reduce((acc, item) => {
acc[item.component] = item.value;
return acc;
}, {}));
}
});
});
}
/**
* Get currencies
* @returns {Promise}
*/
getSystemCurrencies() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.api.call({
url: '/billing/supported-currency',
method: 'GET',
headers: {
Accept: 'application/hal+json',
'Content-Type': 'application/json'
}
});
});
}
}
exports.BilliaSDKSystem = BilliaSDKSystem;