UNPKG

manageengine-mdm

Version:

A TypeScript wrapper for the ManageEngine Mobile Device Manager Plus API

171 lines (170 loc) 6.99 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.ProfilesAPI = void 0; const axios_1 = __importDefault(require("axios")); class ProfilesAPI { 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 all profiles */ listProfiles() { 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/profiles`, { headers }); return response.data; }); } /** * Create a new profile */ createProfile(profile) { 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/profiles`, profile, { headers }); return response.data; }); } /** * Delete or trash profiles. First call moves to trash, second call deletes permanently. */ deleteProfiles(request) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/profiles`, { headers, data: request, }); }); } /** * Get details of a specific profile */ getProfile(profileId) { 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/profiles/${profileId}`, { headers }); return response.data; }); } /** * Update a profile's details */ updateProfile(profileId, profile) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.put(`${this.baseUrl}/api/v1/mdm/profiles/${profileId}`, profile, { headers }); }); } /** * Get list of payloads in a profile */ getProfilePayloads(profileId) { 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/profiles/${profileId}/payloads`, { headers }); return response.data; }); } /** * Get payload details for a specific payload type */ getPayloadDetails(profileId, payloadName) { 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/profiles/${profileId}/payloads/${payloadName}`, { headers }); return response.data; }); } /** * Add a new payload to a profile */ addPayload(profileId, payloadName, config) { 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/profiles/${profileId}/payloads/${payloadName}`, JSON.stringify(config), { headers }); return response.data; }); } /** * Remove a payload type from a profile */ removePayload(profileId, payloadName) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/profiles/${profileId}/payloads/${payloadName}`, { headers }); }); } /** * Get details of a specific payload item */ getPayloadItem(profileId, payloadName, payloadId) { 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/profiles/${profileId}/payloads/${payloadName}/${payloadId}`, { headers }); return response.data; }); } /** * Update a payload item */ updatePayloadItem(profileId, payloadName, payloadId, config) { 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/profiles/${profileId}/payloads/${payloadName}/payloaditems/${payloadId}`, JSON.stringify(config), { headers }); return response.data; }); } /** * Remove a payload item */ removePayloadItem(profileId, payloadName, payloadId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.delete(`${this.baseUrl}/api/v1/mdm/profiles/${profileId}/payloads/${payloadName}/${payloadId}`, { headers }); }); } /** * Publish a profile */ publishProfile(profileId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.post(`${this.baseUrl}/api/v1/mdm/profiles/${profileId}/publish`, null, { headers }); }); } /** * Update a profile to all devices and groups */ updateProfileToAll(profileId) { return __awaiter(this, void 0, void 0, function* () { const headers = yield this.getHeaders(); yield axios_1.default.put(`${this.baseUrl}/api/v1/mdm/profiles/${profileId}/update_all`, null, { headers }); }); } } exports.ProfilesAPI = ProfilesAPI;