manageengine-mdm
Version:
A TypeScript wrapper for the ManageEngine Mobile Device Manager Plus API
158 lines (157 loc) • 7.71 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManageEngineMDM = void 0;
const AuthManager_1 = require("./auth/AuthManager");
const DevicesAPI_1 = require("./devices/DevicesAPI");
const GroupsAPI_1 = require("./groups/GroupsAPI");
const FilesAPI_1 = require("./files/FilesAPI");
const ProfilesAPI_1 = require("./profiles/ProfilesAPI");
const AppsAPI_1 = require("./apps/AppsAPI");
const BlocklistAPI_1 = require("./blocklist/BlocklistAPI");
const DocsAPI_1 = require("./docs/DocsAPI");
const AnnouncementsAPI_1 = require("./announcements/AnnouncementsAPI");
const EnrollmentSettingsAPI_1 = require("./enrollment/EnrollmentSettingsAPI");
const UsersAPI_1 = require("./users/UsersAPI");
const ComplianceAPI_1 = require("./compliance/ComplianceAPI");
const ScheduledActionsAPI_1 = require("./scheduled/ScheduledActionsAPI");
const VppAPI_1 = require("./vpp/VppAPI");
__exportStar(require("./auth/types"), exports);
__exportStar(require("./devices/types"), exports);
__exportStar(require("./groups/types"), exports);
__exportStar(require("./files/types"), exports);
__exportStar(require("./profiles/types"), exports);
__exportStar(require("./apps/types"), exports);
__exportStar(require("./blocklist/types"), exports);
__exportStar(require("./docs/types"), exports);
__exportStar(require("./announcements/types"), exports);
__exportStar(require("./enrollment/types"), exports);
__exportStar(require("./users/types"), exports);
__exportStar(require("./compliance/types"), exports);
__exportStar(require("./scheduled/types"), exports);
__exportStar(require("./vpp/types"), exports);
class ManageEngineMDM {
constructor(config) {
this.authManager = new AuthManager_1.AuthManager(config);
}
/**
* Get the authorization URL that the user needs to visit to grant access
*/
getAuthorizationUrl(accessType = 'offline', prompt) {
return this.authManager.getAuthorizationUrl(accessType, prompt);
}
/**
* Initialize the client with an authorization code
* This must be called before using any API endpoints if you don't have a refresh token
*/
initialize(code, accountsServer) {
return __awaiter(this, void 0, void 0, function* () {
yield this.authManager.authenticateWithCode(code, accountsServer);
yield this.setupAPIs(accountsServer);
});
}
/**
* Initialize the client with a refresh token
* Use this if you already have a refresh token from a previous authentication
*/
initializeWithRefreshToken(refreshToken, accountsServer) {
return __awaiter(this, void 0, void 0, function* () {
yield this.authManager.authenticateWithRefreshToken(refreshToken, accountsServer);
yield this.setupAPIs(accountsServer);
});
}
/**
* Set up API instances after authentication
*/
setupAPIs(accountsServer) {
return __awaiter(this, void 0, void 0, function* () {
this.accountsServer = accountsServer;
const authState = yield this.authManager.getAuthState(accountsServer);
if (authState) {
this.devices = new DevicesAPI_1.DevicesAPI(authState.apiDomain, this.authManager, accountsServer);
this.groups = new GroupsAPI_1.GroupsAPI(authState.apiDomain, this.authManager, accountsServer);
this.files = new FilesAPI_1.FilesAPI(authState.apiDomain, this.authManager, accountsServer);
this.profiles = new ProfilesAPI_1.ProfilesAPI(authState.apiDomain, this.authManager, accountsServer);
this.apps = new AppsAPI_1.AppsAPI(authState.apiDomain, this.authManager, accountsServer);
this.blocklist = new BlocklistAPI_1.BlocklistAPI(authState.apiDomain, this.authManager, accountsServer);
this.docs = new DocsAPI_1.DocsAPI(authState.apiDomain, this.authManager, accountsServer);
this.announcements = new AnnouncementsAPI_1.AnnouncementsAPI(authState.apiDomain, this.authManager, accountsServer);
this.enrollment = new EnrollmentSettingsAPI_1.EnrollmentSettingsAPI(authState.apiDomain, this.authManager, accountsServer);
this.users = new UsersAPI_1.UsersAPI(authState.apiDomain, this.authManager, accountsServer);
this.compliance = new ComplianceAPI_1.ComplianceAPI(authState.apiDomain, this.authManager, accountsServer);
this.scheduledActions = new ScheduledActionsAPI_1.ScheduledActionsAPI(authState.apiDomain, this.authManager, accountsServer);
this.vpp = new VppAPI_1.VppAPI(authState.apiDomain, this.authManager, accountsServer);
}
});
}
/**
* Check if the client is authenticated
*/
isAuthenticated() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.accountsServer) {
return false;
}
const authState = yield this.authManager.getAuthState(this.accountsServer);
return authState !== undefined;
});
}
/**
* Get the current authentication state
*/
getAuthState() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.accountsServer) {
return undefined;
}
return this.authManager.getAuthState(this.accountsServer);
});
}
/**
* Clear the current authentication state
*/
clearAuthState() {
return __awaiter(this, void 0, void 0, function* () {
if (this.accountsServer) {
yield this.authManager.clearAuthState(this.accountsServer);
this.devices = undefined;
this.groups = undefined;
this.files = undefined;
this.profiles = undefined;
this.apps = undefined;
this.blocklist = undefined;
this.docs = undefined;
this.announcements = undefined;
this.enrollment = undefined;
this.users = undefined;
this.compliance = undefined;
this.scheduledActions = undefined;
this.vpp = undefined;
this.accountsServer = undefined;
}
});
}
}
exports.ManageEngineMDM = ManageEngineMDM;