@interopio/manager-api
v4.0.7
Published
Provides a minimal higher-level wrapper around io.Manager Server API
Maintainers
Keywords
Readme
Overview
Provides a minimal wrapper around io.Manager REST APIs to simplify the process of fetching and modifying data stored in io.Manager Server by JavaScript applications.
Changelog
The changelog can be found here: Changelog
Usage
There are two types of APIs exposed by the package:
- AdminAPI - used to fetch or modify any type of data stored in io.Manager Server
- ClientAPI - used to fetch data specific to a single user (e.g. user's applications and layouts); allows updating entities that are owned by the user.
Initialization
Initialization is similar for both APIs. You should provide an options object that has two required properties:
baseUrlwhich is the Server API endpoint.authcontains the authentication on the specific authentication.
import { AdminAPI, ClientAPI } from '@interopio/manager-api';
const admin = new AdminAPI({
baseUrl: `http://localhost:3465/`,
auth: {
token: {
bearer: this.auth?.token,
},
},
});
const client = new ClientAPI({
baseUrl: `http://localhost:3465/`,
auth: {
token: {
bearer: this.auth?.token,
},
},
});Adding Extra Headers
You can add extra headers to be sent with each request by using the headers property of the options object.
const admin = new AdminAPI({
baseUrl: `http://localhost:3465/`,
auth: {
token: {
bearer: this.auth?.token,
},
},
headers: {
'X-Extra-Header': 'value',
},
});Transforming responses
You can transform incoming responses using the transformResponse method. This method is called with the response object and should return the transformed response.
const admin = new AdminAPI({
baseUrl: `http://localhost:3465/`,
auth: {
token: {
bearer: this.auth?.token,
},
},
transformResponse: (data, headers, status) => {
const responseType = header['content-type'];
if (
responseType &&
responseType.includes('application/json') &&
typeof data === 'string'
) {
return this.parse(data);
} else {
return data;
}
},
});AdminAPI
The AdminAPI allows you to manage any type of entity stored by the server. Operations are exposed as methods attached to sub-properties of the API object. For example, to fetch all applications, you would call the admin.apps.getAll() method.
apps- Manage Applications;apps2- Manage Applications;groups- Manage Groups;users- Manage Users;layouts- Manage Layouts;layouts2- Manage Layouts;commands- Manage Commands;sessions- Manage Sessions;machines- Manage Machines;crashes- Manage Crashes;feedbacks- Manage Feedbacks;prefs- Manage Prefs;audit- Manage AuditAPI;server- Manage ServerAPI;systemConfig- Manage SystemConfigAPI;schemas- Manage SchemaAPI;
ClientAPI
The operations in the ClientAPI work in the context of a single user.
