UNPKG

manageengine-mdm

Version:

A TypeScript wrapper for the ManageEngine Mobile Device Manager Plus API

317 lines (316 loc) 12.4 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.DevicesAPI = void 0; const axios_1 = __importDefault(require("axios")); class DevicesAPI { constructor(baseUrl, authManager, accountsServer) { this.baseUrl = baseUrl; this.authManager = authManager; this.accountsServer = accountsServer; } getHeaders() { return __awaiter(this, void 0, void 0, function* () { const token = yield this.authManager.getValidToken(this.accountsServer); return { Authorization: `Zoho-oauthtoken ${token}`, 'Content-Type': 'application/json', }; }); } /** * Get a list of managed devices */ listDevices(params) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices`, { headers, params, }); return response.data; }); } /** * Get details of a specific device */ getDevice(deviceId, summary) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const params = summary ? { summary } : undefined; const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}`, { headers, params }); return response.data; }); } /** * Update device details */ updateDevice(deviceId, updateData) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.put(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}`, updateData, { headers }); return response.data; }); } /** * Get device summary */ getDeviceSummary(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/summary`, { headers }); return response.data; }); } /** * Get device certificates */ getDeviceCertificates(deviceId, expiry) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const params = expiry ? { expiry } : undefined; const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/certificates`, { headers, params }); return response.data; }); } /** * Get device restrictions */ getDeviceRestrictions(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/restrictions`, { headers }); return response.data; }); } /** * Get FileVault details */ getFileVaultDetails(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/filevault`, { headers }); return response.data; }); } /** * Get firmware details */ getFirmwareDetails(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/firmware`, { headers }); return response.data; }); } /** * Get firmware password */ getFirmwarePassword(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/firmware/password`, { headers }); return response.data; }); } /** * Get device locations */ getDeviceLocations(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/locations`, { headers }); return response.data; }); } /** * Get device locations with address */ getDeviceLocationsWithAddress(deviceId, exportBatchId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const params = exportBatchId ? { export_batch_id: exportBatchId } : undefined; const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/locations/address`, { headers, params }); return response.data; }); } /** * Request device location with address */ requestDeviceLocation(deviceId, data) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/locations/address`, data, { headers }); return response.data; }); } /** * Get device profiles */ getDeviceProfiles(deviceId, summary) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const params = summary ? { summary } : undefined; const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/profiles`, { headers, params }); return response.data; }); } /** * Associate profiles to device */ associateProfiles(deviceId, profileIds) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/profiles`, { profile_ids: profileIds }, { headers }); }); } /** * Disassociate profiles from device */ disassociateProfiles(deviceId, profileIds) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/profiles`, { headers, data: { profile_ids: profileIds }, }); }); } /** * Get device apps */ getDeviceApps(deviceId, params = { offset: 0, }) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/apps`, { headers, params }); return response.data; }); } /** * Associate apps to device */ associateApps(deviceId, appDetails, options = {}) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/apps`, JSON.stringify(Object.assign({ app_details: appDetails }, options)), { headers }); }); } /** * Disassociate apps from device */ disassociateApps(deviceId, appIds) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/apps`, { headers, data: JSON.stringify({ app_ids: appIds }), }); }); } /** * Get device actions */ getDeviceActions(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/actions`, { headers }); return response.data; }); } /** * Perform action on device */ performAction(deviceId, actionName, actionData) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/actions/${actionName}`, actionData, { headers }); }); } /** * Get device scan status */ getScanStatus(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/actions/scan/status`, { headers }); return response.data; }); } /** * Get device privacy settings */ getDevicePrivacy(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/privacy`, { headers }); return response.data; }); } /** * Execute bulk device command */ executeBulkCommand(commandName, request) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/actions/${commandName}`, request, { headers }); return response.data; }); } /** * Get command history for device */ getCommandHistory(deviceId, options = {}) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/commands`, { headers, params: options, }); return response.data; }); } /** * Get last initiated command status */ getRecentCommandStatus(deviceId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); const response = yield axios_1.default.get(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/commands/recent`, { headers }); return response.data; }); } /** * Perform Knox action on device */ performKnoxAction(deviceId, actionName) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/knox/${actionName}`, null, { headers }); }); } /** * Remove pending action */ removeAction(deviceId, actionName) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/devices/${deviceId}/actions/${actionName}`, { headers }); }); } } exports.DevicesAPI = DevicesAPI;