UNPKG

wallee

Version:
311 lines (310 loc) 14.2 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserAccountRoleService = void 0; const Promise = require("bluebird"); const axios = require("axios"); const HMACAuthentication_1 = require("../auth/HMACAuthentication"); const ObjectSerializer_1 = require("../serializers/ObjectSerializer"); const ClientError_1 = require("../models/ClientError"); const ServerError_1 = require("../models/ServerError"); class UserAccountRoleService { constructor(configuration) { this._basePath = 'https://app-wallee.com:443/api'; this._defaultHeaders = {}; this._useQuerystring = false; this._timeout = 25; this._defaultAuthentication = new HMACAuthentication_1.HMACAuthentication(configuration).apply; this._defaultHeaders = configuration.default_headers; this.setTimeout(configuration.timeout); } /** * Set timeout in seconds. Default timeout: 25 seconds * @param {number} timeout */ set timeout(timeout) { this.setTimeout(timeout); } setTimeout(timeout) { if (timeout !== undefined) { if (!Number.isInteger(timeout)) { throw new Error('Timeout value has to be integer'); } if (timeout) { this._timeout = timeout; } else { throw new Error('Timeout value has to be greater than 0'); } } } set basePath(basePath) { this._basePath = basePath; } get basePath() { return this._basePath; } setDefaultAuthentication(auth) { this._defaultAuthentication = auth; } getVersion() { if (typeof (process) !== 'undefined' && process && process.version) { return 'node ' + process.version; } else { return 'unknown'; } } /** * This operation grants the role to the given user with in the given account. * @summary Add Role * @param userId The id of the user to whom the role is assigned. * @param accountId The account to which the role is mapped. * @param roleId The role which is mapped to the user and account. * @param appliesOnSubaccount Whether the role applies only on subaccount. * @param {*} [options] Override http request options. */ addRole(userId, accountId, roleId, appliesOnSubaccount, options = {}) { const url = '/user-account-role/addRole'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'userId' is not null or undefined if (userId === null || userId === undefined) { throw new Error('Required parameter userId was null or undefined when calling addRole.'); } // verify required parameter 'accountId' is not null or undefined if (accountId === null || accountId === undefined) { throw new Error('Required parameter accountId was null or undefined when calling addRole.'); } // verify required parameter 'roleId' is not null or undefined if (roleId === null || roleId === undefined) { throw new Error('Required parameter roleId was null or undefined when calling addRole.'); } if (userId !== undefined) { queryParams['userId'] = ObjectSerializer_1.ObjectSerializer.serialize(userId, "number"); } if (accountId !== undefined) { queryParams['accountId'] = ObjectSerializer_1.ObjectSerializer.serialize(accountId, "number"); } if (roleId !== undefined) { queryParams['roleId'] = ObjectSerializer_1.ObjectSerializer.serialize(roleId, "number"); } if (appliesOnSubaccount !== undefined) { queryParams['appliesOnSubaccount'] = ObjectSerializer_1.ObjectSerializer.serialize(appliesOnSubaccount, "boolean"); } headers['Content-Type'] = 'application/json'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'POST', baseURL: this._basePath, headers, params: queryParams, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "UserAccountRole"); return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; /** * List all the roles that are assigned to the given user in the given account. * @summary List Roles * @param userId The id of the user to whom the role is assigned. * @param accountId The account to which the role is mapped. * @param {*} [options] Override http request options. */ list(userId, accountId, options = {}) { const url = '/user-account-role/list'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'userId' is not null or undefined if (userId === null || userId === undefined) { throw new Error('Required parameter userId was null or undefined when calling list.'); } // verify required parameter 'accountId' is not null or undefined if (accountId === null || accountId === undefined) { throw new Error('Required parameter accountId was null or undefined when calling list.'); } if (userId !== undefined) { queryParams['userId'] = ObjectSerializer_1.ObjectSerializer.serialize(userId, "number"); } if (accountId !== undefined) { queryParams['accountId'] = ObjectSerializer_1.ObjectSerializer.serialize(accountId, "number"); } headers['Content-Type'] = 'application/json'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'POST', baseURL: this._basePath, headers, params: queryParams, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; body = ObjectSerializer_1.ObjectSerializer.deserialize(success.data, "Array<UserAccountRole>"); return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; /** * This operation removes the specified user account role. * @summary Remove Role * @param id The id of user account role which should be removed * @param {*} [options] Override http request options. */ removeRole(id, options = {}) { const url = '/user-account-role/removeRole'; let queryParams = {}; let headers = Object.assign({}, this._defaultHeaders); // verify required parameter 'id' is not null or undefined if (id === null || id === undefined) { throw new Error('Required parameter id was null or undefined when calling removeRole.'); } if (id !== undefined) { queryParams['id'] = ObjectSerializer_1.ObjectSerializer.serialize(id, "number"); } headers['Content-Type'] = 'application/json'; Object.assign(headers, options.headers); let defaultHeaders = { "x-meta-sdk-version": "4.7.0", "x-meta-sdk-language": "typescript", "x-meta-sdk-provider": "wallee", "x-meta-sdk-language-version": this.getVersion(), }; Object.assign(headers, defaultHeaders); let requestConfig = { url, method: 'POST', baseURL: this._basePath, headers, params: queryParams, timeout: this._timeout * 1000, responseType: 'json', }; const axiosInstance = axios.default.create(); axiosInstance.interceptors.request.use(this._defaultAuthentication); return new Promise((resolve, reject) => { axiosInstance.request(requestConfig) .then(success => { let body; return resolve({ response: success.request.res, body: body }); }, failure => { var _a, _b, _c, _d, _e; let errorObject; if ((_a = failure.response) === null || _a === void 0 ? void 0 : _a.status) { if (failure.response.status >= 400 && failure.response.status <= 499) { errorObject = new ClientError_1.ClientError(); } else if (failure.response.status >= 500 && failure.response.status <= 599) { errorObject = new ServerError_1.ServerError(); } else { errorObject = new Object(); } } else { errorObject = new Object(); } return reject({ errorType: errorObject.constructor.name, date: (new Date()).toDateString(), statusCode: ((_b = failure.response) === null || _b === void 0 ? void 0 : _b.status) && isNaN(failure.response.status) ? String(failure.response.status) : "Unknown", statusMessage: ((_c = failure.response) === null || _c === void 0 ? void 0 : _c.statusText) != null ? failure.response.statusText : "Unknown", body: (_d = failure.response) === null || _d === void 0 ? void 0 : _d.data, response: (_e = failure.response) === null || _e === void 0 ? void 0 : _e.request.res }); }) .catch(error => { return reject(error); }); }); } ; } exports.UserAccountRoleService = UserAccountRoleService;