edited and commented Admin API, removed DataEvents class

This commit is contained in:
Ro 2021-06-22 13:18:16 -07:00
parent f7e3b3b55e
commit e40e566302
2 changed files with 107 additions and 34 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,12 @@
//** REQUEST TYPES **//
export const REQUEST_TYPE_POST = "POST";
export const REQUEST_TYPE_GET = "GET";
export const REQUEST_TYPE_PUT = "PUT";
export const REQUEST_TYPE_DELETE = "DELETE";
export const TASK_PAGE_CREATE = "createNewPage";
export const TASK_PAGE_EDIT = "editPage";
export const TASK_PAGE_DELETE = "deletePage";
//** POST CONTENT TYPES **//
export const CONTENT_TYPE_JSON = "json";
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
//** API URLS **//
export const API_STATUS = "/api/v1/status";
export const API_GET_NAV = "/api/settings/nav";
export const API_NEW_PAGE = "/api/v1/page/create";
@ -18,29 +18,46 @@ export const API_NAV_SYNC = "/api/v1/settings/nav-sync";
export const API_REINDEX_PAGES = "/api/v1/settings/reindex";
export const API_SEND_MAIL = "/api/v1/mailer";
export const API_LOGIN = "/api/v1/login";
//** API TASKS **//
export const AUTH_STATUS = "getAuthStatus";
export const API_ACCESS_GOOD = "apiConnected";
export const API_ACCESS_BAD = "apiNotConnected";
export const TASK_SETTINGS_WRITE = "writeSettings";
export const TASK_PUBLISH_SITE = "publishSite";
export const TASK_PAGE_CREATE = "createNewPage";
export const TASK_PAGE_EDIT = "editPage";
export const TASK_PAGE_DELETE = "deletePage";
export const TASK_SEND_MAIL = "sendMail";
export const TASK_REINDEX_PAGE = "reIndexPages";
import * as DataEvent from "../com/events/DataEvent";
export default class APIUtils {
//--------------------------
// constructor
//--------------------------
/**
* Fipamo Administration API
* Class for handling Fipamo dashboard tasks
*/
export default class FipamoAdminAPI {
/**
* @constructor
*/
constructor() {
this.percentComplete = 0;
this.token = null;
//checks backend to see if user is logged in
//and requests encrypted token for api calls
this._request(API_STATUS).then((response) => {
if (response.type === DataEvent.API_REQUEST_GOOD) {
if (response.type === API_ACCESS_GOOD) {
this.token = response.token;
} else {
//don't set token
}
});
}
//--------------------------
// public
//--------------------------
/**
* Method for retrieving user authorizing user login
* @param {object} data - json object that contains data for set up
* @property {string} handle - handle for site user
* @property {string} password - password for site user
*/
login(data) {
return new Promise((resolve, reject) => {
this._request(
@ -58,11 +75,31 @@ export default class APIUtils {
});
});
}
/**
* Method for saving settings
* @param {object} data - json object that contains settings data set on the front-end
* @property {string} global.base_url - base url for site
* @property {string} global.title - site title
* @property {string} global.descriptions - brief site summary
* @property {string} global.background - url for site feature image for header
* @property {boolean} global.private - privacy state for site [disabled]
* @property {boolean} global.renderOnSave - property for publishing site when page saved [disabled]
* @property {string} global.theme - current theme for site
* @property {boolean} global.externalAPI - toggle for external API access
* @property {string} member.handle - current member handle
* @property {string} member.email - current member email
* @property {string} email.active - current email protocol being used
* @property {string} email.smtp.domain - url of smtp service being
* @property {string} email.smtp.email - email account of smtp service
* @property {string} email.smtp.password - password for email of smtp service
* @property {string} email.mailgun.domain - mailgun domain url
* @property {string} email.mailgun.key - mailgun key
*/
syncSettings(data) {
return new Promise((resolve, reject) => {
this._request(
API_SETTINGS_SYNC,
DataEvent.API_SETTINGS_WRITE,
TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
data
@ -76,11 +113,16 @@ export default class APIUtils {
});
}
/**
* Method for retrieving user authorizing user login
* @param {object} data - json object that contains task
* @property {string} task - publishing task [deprecated]
*/
publishSite(data) {
return new Promise((resolve, reject) => {
this._request(
API_PUBLISH_PAGES,
DataEvent.API_RENDER_PAGES,
TASK_PUBLISH_SITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
data
@ -94,23 +136,41 @@ export default class APIUtils {
});
}
/**
* Method for handling page creating and editing
* @param {string} task - current page action
* @param {object} data - form object that contains info for current page being edited/created
* @property {string} id - sequence id for page
* @property {string} uuid - unique identifier for page
* @property {string} layout - current page layout
* @property {string} current_title - saved url save title for persistence when changing title
* @property {string} content - markdown body of page
* @property {string} title - current title of page
* @property {string} created - date page was created
* @property {string} slug - url safe string of page title
* @property {string} tags - comma separated list of tags
* @property {boolean} menu - property that indicates page is included in site menu
* @property {boolean} featured - property that indicates page is featured
* @property {boolean} published - property that indicates page is public
* @property {input} feature_image - main image for page
*/
pageActions(task, data) {
let url, event, content;
switch (task) {
case TASK_PAGE_CREATE:
url = API_NEW_PAGE;
event = DataEvent.API_PAGE_WRITE;
event = TASK_PAGE_CREATE;
content = CONTENT_TYPE_FORM;
break;
case TASK_PAGE_EDIT:
url = API_EDIT_PAGE;
event = DataEvent.API_PAGE_WRITE;
event = TASK_PAGE_EDIT;
content = CONTENT_TYPE_FORM;
break;
case TASK_PAGE_DELETE:
url = API_DELETE_PAGE;
event = DataEvent.API_PAGE_DELETE;
event = TASK_PAGE_DELETE;
content = CONTENT_TYPE_JSON;
break;
@ -129,11 +189,19 @@ export default class APIUtils {
});
}
/**
* Method for saving pages to be included in main site navigation
* @param {object} data - json object that contains items to be included in main site navigation
* @property {string} item.title - page title
* @property {string} item.slug - url safe title
* @property {string} item.uuid - unique identifier
* @property {string} item.path - directory path to associated markdown file
*/
syncNav(data) {
return new Promise((resolve, reject) => {
this._request(
API_NAV_SYNC,
DataEvent.API_SETTINGS_WRITE,
TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
data
@ -146,11 +214,16 @@ export default class APIUtils {
});
});
}
/**
* Method for sending mail
* @param {object} message - json object that contains items to be included in main site navigation
* @property {string} content - message to send
*/
sendMail(message) {
return new Promise((resolve, reject) => {
this._request(
API_SEND_MAIL,
DataEvent.SEND_MAIL,
TASK_SEND_MAIL,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
message
@ -163,12 +236,15 @@ export default class APIUtils {
});
});
}
handleReindex(data) {
/**
* Maintenance method to clean up page sequencing [disabled]
* @param {object} data - json object that contains items to be included in main site navigation
*/
reindexPages(data) {
return new Promise((resolve, reject) => {
this._request(
API_REINDEX_PAGES,
DataEvent.API_REINDEX_PAGES,
TASK_REINDEX_PAGE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
data
@ -208,14 +284,11 @@ export default class APIUtils {
};
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
if (
eventType === DataEvent.API_PAGE_WRITE ||
eventType === DataEvent.API_IMAGES_UPLOAD ||
eventType === DataEvent.API_SETTINGS_WRITE ||
eventType === DataEvent.API_PAGE_DELETE ||
eventType === DataEvent.API_RENDER_PAGES ||
eventType === DataEvent.API_BACKUP_CREATE ||
eventType === DataEvent.API_BACKUP_RESTORE ||
eventType === DataEvent.API_REINDEX_PAGES
eventType === TASK_SETTINGS_WRITE ||
eventType === TASK_PAGE_EDIT ||
eventType === TASK_PAGE_DELETE ||
eventType === TASK_PUBLISH_SITE ||
eventType === TASK_REINDEX_PAGE
)
request.setRequestHeader("fipamo-access-token", self.token);