UNPKG

revbits-cip-integration

Version:
291 lines (290 loc) 12.8 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCIP = void 0; const notifications_api_1 = __importDefault(require("./apis/notifications.api")); const permissions_api_1 = __importDefault(require("./apis/permissions.api")); const roles_api_1 = __importDefault(require("./apis/roles.api")); const users_api_1 = __importDefault(require("./apis/users.api")); const helpers_1 = require("./utils/helpers"); const cip_helpers_1 = require("./utils/cip-helpers"); class BaseCIP { constructor(cipBaseUrl, cipSocketPostfix, platform, platformPrivKey, options = {}, socketCallback) { this.cipBaseUrl = cipBaseUrl; this.cipSocketPostfix = cipSocketPostfix; this.platform = platform; this.platformPrivKey = platformPrivKey; this.options = options; this.socketCallback = socketCallback; this.validateParams(); } getUserApi(actor) { return actor ? new users_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options, actor) : new users_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options); } getRoleApi(actor) { return actor ? new roles_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options, actor) : new roles_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options); } getPermissionApi(actor) { return actor ? new permissions_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options, actor) : new permissions_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options); } getNotificationApi(actor) { return actor ? new notifications_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options, actor) : new notifications_api_1.default(this.cipBaseUrl, this.platform, this.platformPrivKey, this.options); } getUsers(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).getAll(requestData); }); } getIteratedUsers(cb, requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { yield (0, cip_helpers_1.iteratePages)((page) => __awaiter(this, void 0, void 0, function* () { const _requestData = Object.assign(Object.assign({}, (requestData || {})), { page }); return yield this.getUserApi(actor).getAll(_requestData); }), cb); }); } getUser(id, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).getOne(id); }); } getUserByUsername(username, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).getOne('', username); }); } createUser(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).create(requestData); }); } createBulkUsers(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { (0, helpers_1.validateBulkRecordsCount)(requestData.users); return this.getUserApi(actor).createBulk(requestData); }); } updateUser(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).update(requestData); }); } updateBulkUsers(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).bulkUpdate(requestData); }); } uploadAvatar(filePath, actor = null) { return __awaiter(this, void 0, void 0, function* () { (0, helpers_1.validateActor)(actor); return this.getUserApi(actor).uploadAvatar(filePath); }); } deleteUser(id, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).delete(id); }); } checkUsersExistenceByUsernames(usernames, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).checkUsersExistenceByUsernames(usernames); }); } checkUsersExistenceByIds(ids, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).checkUsersExistenceByIds(ids); }); } restoreUser(id, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).restore(id); }); } getCipUrlsConfig(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).getCipUrlsConfig(); }); } createInventory(data, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).createInventory(data); }); } getRoles(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).getAll(requestData); }); } getIteratedRoles(cb, requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { yield (0, cip_helpers_1.iteratePages)((page) => __awaiter(this, void 0, void 0, function* () { const _requestData = Object.assign(Object.assign({}, (requestData || {})), { page }); return yield this.getRoleApi(actor).getAll(_requestData); }), cb); }); } getRole(id, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).getOne(id); }); } createRole(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).create(requestData); }); } createBulkRoles(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { (0, helpers_1.validateBulkRecordsCount)(requestData.roles); return this.getRoleApi(actor).createBulk(requestData); }); } updateRole(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).update(requestData); }); } updateBulkRoles(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).bulkUpdate(requestData); }); } deleteRole(id, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).delete(id); }); } checkRolesExistenceByNames(names, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).checkRolesExistenceByNames(names); }); } checkRolesExistenceByIds(ids, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getRoleApi(actor).checkRolesExistenceByIds(ids); }); } getPermissions(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getPermissionApi(actor).getAll(); }); } getPermission(key, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getPermissionApi(actor).getOne(key); }); } syncPermissions(data, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getPermissionApi(actor).sync(data); }); } deletePermission(key, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getPermissionApi(actor).delete(key); }); } deletePlatformPermissions(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getPermissionApi(actor).deletePlatformPermissions(); }); } getNotifications(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getAll(requestData); }); } getNotification(platformNotificationId, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getOne(platformNotificationId); }); } createNotification(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).create(requestData); }); } createBulkNotifications(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { (0, helpers_1.validateBulkRecordsCount)(requestData.notifications); return this.getNotificationApi(actor).createBulk(requestData); }); } updateBulkNotificationsData(requestData, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).updateBulkData(requestData); }); } readNotification(platformNotificationId, appname, actor) { return __awaiter(this, void 0, void 0, function* () { (0, helpers_1.validateActor)(actor); return this.getNotificationApi(actor).read(platformNotificationId, appname); }); } deleteNotification(platformNotificationId, appname, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).delete(platformNotificationId, appname); }); } getPlatformsConfig(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getPlatformsConfig(); }); } getUserAccessConfig(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getUserAccessConfig(); }); } getAllPlatformsNotifications(data, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getAllPlatformsNotifications(data); }); } getAllPlatformsUnreadNotificationsCount(data, actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getNotificationApi(actor).getAllPlatformsUnreadNotificationsCount(data); }); } logout(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).logout(); }); } updateDashboard(actor = null) { return __awaiter(this, void 0, void 0, function* () { return this.getUserApi(actor).updateDashboard(); }); } validateParams() { (0, helpers_1.validateRequiredParams)(['cipBaseUrl', 'cipSocketPostfix', 'platform', 'platformPrivKey'], this); (0, helpers_1.verifyVariableType)(this.cipBaseUrl, 'string', 'cipBaseUrl'); (0, helpers_1.verifyVariableType)(this.cipSocketPostfix, 'string', 'cipSocketPostfix'); (0, helpers_1.verifyVariableType)(this.platform, 'string', 'platform'); (0, helpers_1.verifyVariableType)(this.platformPrivKey, 'string', 'platformPrivKey'); (0, helpers_1.verifyVariableType)(this.options, 'object', 'options'); if (this.socketCallback) { (0, helpers_1.verifyVariableType)(this.socketCallback, 'function', 'socketCallback'); } } } exports.BaseCIP = BaseCIP;