baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
193 lines (192 loc) • 9.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/* globals module */
/**
* @module loginRoute
* @description Baasic Login Route Definition provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use Baasic Login Route Definition to obtain needed routes while other routes will be obtained through HAL. By convention, all route services use the same function names as their corresponding services.
*/
var inversify_1 = require("inversify");
var common_1 = require("../../common");
var contracts_1 = require("../../core/contracts");
var PermissionRoute = /** @class */ (function (_super) {
tslib_1.__extends(PermissionRoute, _super);
function PermissionRoute(appOptions) {
var _this = _super.call(this, appOptions) || this;
_this.appOptions = appOptions;
/**
* Find all route with route and query parameters.
*/
_this.findAllRoute = 'permissions/sections{?searchQuery,sort,embed,fields}';
/**
* Find route with route and query parameters.
**/
_this.findRoute = 'permissions/sections/{section}/{?searchQuery,sort,embed,fields}';
/**
* sectionsPolicies route and query parameters.
*/
_this.sectionsPoliciesRoute = 'permissions/sections/policies/{?sectionAbrvs,searchQuery,sort,embed,fields}';
/**
* Get actions route with route and query parameters.
**/
_this.getActionsRoute = 'permissions/actions/{?searchQuery,sort,embed,fields}';
/**
* Get roles route with route and query parameters.
**/
_this.getRolesRoute = 'lookups/roles/{?searchQuery,page,rpp,sort,embed,fields}';
/**
* Get users route with route and query parameters.
**/
_this.getUsersRoute = 'users/{?searchQuery,page,rpp,sort,embed,fields}';
/**
* Create route with route and query parameters.
**/
_this.createRoute = 'permissions/';
/**
* Remove route with route and query parameters.
**/
_this.removeRoute = 'permissions/sections/{section}/actions/{action}/{{operation}}/{{subject}}/';
return _this;
}
/**
* Parses find all route which can be expanded with additional options. Supported items are:
* - `searchQuery` - A string value used to identify access policy resources using the phrase search.
* - `sort` - A string used to set the access policy property to sort the result collection by.
* @method
* @example
permissionRoute.findAll(
{searchQuery: '<search-phrase>'}
);
**/
PermissionRoute.prototype.findAll = function (options) {
var opt = options || {};
return _super.prototype.baseFind.call(this, this.findAllRoute, this.utility.extend(opt));
};
/**
* Parses find route which can be expanded with additional options. Supported items are:
* - `section` - Section abbreviation which identifies part of the application for which security privileges can be retrieved and managed.
* - `searchQuery` - A string value used to identify access policy resources using the phrase search.
* - `sort` - A string used to set the access policy property to sort the result collection by.
* @method
* @example
permissionRoute.find(
'sectionName',
{searchQuery: '<search-phrase>'}
);
**/
PermissionRoute.prototype.find = function (section, options) {
var opt = options || {};
return _super.prototype.baseFind.call(this, this.findRoute, this.utility.extend({ section: section }, opt));
};
/**
* Parses getActions route which can be expanded with additional options. Supported items are:
* - `searchQuery` - A string value used to identify access action resources using the phrase search.
* - `sort` - A string used to set the access action property to sort the result collection by.
* @method
* @example
permissionRoute.getActions(
{searchQuery: '<search-phrase>'}
);
**/
PermissionRoute.prototype.getActions = function (options) {
var opt = options || {};
return _super.prototype.baseFind.call(this, this.getActionsRoute, opt);
};
/**
* Parses getRoles route which can be expanded with additional options. Supported items are:
* - `searchQuery` - A string value used to identify access policy resources using the phrase search.
* - `sort` - A string used to set the access policy property to sort the result collection by.
* - `page` - A value used to set the page number, i.e. to retrieve certain access policy subset from the storage.
* - `rpp` - A value used to limit the size of result set per page.
* @method
* @example
permissionRoute.getRoles(
{searchQuery: '<search-phrase>'}
);
**/
PermissionRoute.prototype.getRoles = function (options) {
var opt = options || {};
return _super.prototype.baseFind.call(this, this.getRolesRoute, opt);
};
/**
* Parses getUsers route which can be expanded with additional options. Supported items are:
* - `searchQuery` - A string value used to identify access policy resources using the phrase search.
* - `sort` - A string used to set the access policy property to sort the result collection by.
* - `page` - A value used to set the page number, i.e. to retrieve certain access policy subset from the storage.
* - `rpp` - A value used to limit the size of result set per page.
* @method
* @example
permissionRoute.getRoles(
{searchQuery: '<search-phrase>'}
);
**/
PermissionRoute.prototype.getUsers = function (options) {
var opt = options || {};
return _super.prototype.baseFind.call(this, this.getUsersRoute, opt);
};
/**
* Parses sectionsPoliciesRoute which can be expanded with additional options.
* - `searchQuery` - A string value used to identify access policy resources using the phrase search.
* - `sort` - A string used to set the access policy property to sort the result collection by.
* - `page` - A value used to set the page number, i.e. to retrieve certain access policy subset from the storage.
* - `rpp` - A value used to limit the size of result set per page.
* - `section` - Section abbreviation which identifies part of the application for which security privileges can be retrieved and managed.
* @param {string} sections - Comma-spearated list of section abbreviations that identify parts of the application for which security privileges can be retrieved and managed.
*/
PermissionRoute.prototype.findSectionsPolicies = function (sectionAbrvs, options) {
var opt = tslib_1.__assign({ sectionAbrvs: sectionAbrvs }, options);
return _super.prototype.baseFind.call(this, this.sectionsPoliciesRoute, opt);
};
/**
* Parses create permission route; this URI template doesn't expose any additional properties.
* @method
* @example permissionRoute.create({});
**/
PermissionRoute.prototype.create = function () {
return _super.prototype.baseCreate.call(this, this.createRoute);
};
/**
* Returns a promise that is resolved once the remove permission action has been performed. This action will remove a permission from the system, if completed successfully.
* @param data A permission object used to delete specified permission resource.
* @returns A promise that is resolved once the remove action has been performed.
* @method
* @example // Permission is a resource previously fetched using get action.
permissionClient.remove(permission)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
PermissionRoute.prototype.remove = function (data) {
var params = _super.prototype.deleteParams.call(this, data);
var action = data.actions[0];
var operation = '';
var subject = '';
if (data.role && data.role.length > 0) {
operation = 'Role';
subject = data.role;
}
else {
operation = 'User';
subject = data.userName;
}
var route = this.removeRoute.replace('{{operation}}', operation.toLowerCase() + 's').replace('{{subject}}', subject);
return _super.prototype.baseDelete.call(this, route, data, null, 'delete' + action.abrv + operation);
};
PermissionRoute = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(contracts_1.TYPES.IAppOptions)),
tslib_1.__metadata("design:paramtypes", [Object])
], PermissionRoute);
return PermissionRoute;
}(common_1.BaseRoute));
exports.PermissionRoute = PermissionRoute;
/**
* @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.
- [URI Template](https://github.com/Baasic/uritemplate-js) syntax enables expanding the Baasic route templates to Baasic REST URIs providing it with an object that contains URI parameters.
- All end-point objects are transformed by the associated route definition.
*/