edited and commented Admin API, removed DataEvents class

pull/84/head
Ro 3 years ago
parent f7e3b3b55e
commit e40e566302

File diff suppressed because one or more lines are too long

@ -1,12 +1,12 @@
//** REQUEST TYPES **//
export const REQUEST_TYPE_POST = "POST"; export const REQUEST_TYPE_POST = "POST";
export const REQUEST_TYPE_GET = "GET"; export const REQUEST_TYPE_GET = "GET";
export const REQUEST_TYPE_PUT = "PUT"; export const REQUEST_TYPE_PUT = "PUT";
export const REQUEST_TYPE_DELETE = "DELETE"; export const REQUEST_TYPE_DELETE = "DELETE";
export const TASK_PAGE_CREATE = "createNewPage"; //** POST CONTENT TYPES **//
export const TASK_PAGE_EDIT = "editPage";
export const TASK_PAGE_DELETE = "deletePage";
export const CONTENT_TYPE_JSON = "json"; export const CONTENT_TYPE_JSON = "json";
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
//** API URLS **//
export const API_STATUS = "/api/v1/status"; export const API_STATUS = "/api/v1/status";
export const API_GET_NAV = "/api/settings/nav"; export const API_GET_NAV = "/api/settings/nav";
export const API_NEW_PAGE = "/api/v1/page/create"; 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_REINDEX_PAGES = "/api/v1/settings/reindex";
export const API_SEND_MAIL = "/api/v1/mailer"; export const API_SEND_MAIL = "/api/v1/mailer";
export const API_LOGIN = "/api/v1/login"; export const API_LOGIN = "/api/v1/login";
//** API TASKS **//
export const AUTH_STATUS = "getAuthStatus"; 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 { * Fipamo Administration API
//-------------------------- * Class for handling Fipamo dashboard tasks
// constructor */
//--------------------------
export default class FipamoAdminAPI {
/**
* @constructor
*/
constructor() { constructor() {
this.percentComplete = 0; this.percentComplete = 0;
this.token = null; this.token = null;
//checks backend to see if user is logged in //checks backend to see if user is logged in
//and requests encrypted token for api calls //and requests encrypted token for api calls
this._request(API_STATUS).then((response) => { this._request(API_STATUS).then((response) => {
if (response.type === DataEvent.API_REQUEST_GOOD) { if (response.type === API_ACCESS_GOOD) {
this.token = response.token; this.token = response.token;
} else { } else {
//don't set token //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) { login(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( 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) { syncSettings(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( this._request(
API_SETTINGS_SYNC, API_SETTINGS_SYNC,
DataEvent.API_SETTINGS_WRITE, TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
data 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) { publishSite(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( this._request(
API_PUBLISH_PAGES, API_PUBLISH_PAGES,
DataEvent.API_RENDER_PAGES, TASK_PUBLISH_SITE,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
data 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) { pageActions(task, data) {
let url, event, content; let url, event, content;
switch (task) { switch (task) {
case TASK_PAGE_CREATE: case TASK_PAGE_CREATE:
url = API_NEW_PAGE; url = API_NEW_PAGE;
event = DataEvent.API_PAGE_WRITE; event = TASK_PAGE_CREATE;
content = CONTENT_TYPE_FORM; content = CONTENT_TYPE_FORM;
break; break;
case TASK_PAGE_EDIT: case TASK_PAGE_EDIT:
url = API_EDIT_PAGE; url = API_EDIT_PAGE;
event = DataEvent.API_PAGE_WRITE; event = TASK_PAGE_EDIT;
content = CONTENT_TYPE_FORM; content = CONTENT_TYPE_FORM;
break; break;
case TASK_PAGE_DELETE: case TASK_PAGE_DELETE:
url = API_DELETE_PAGE; url = API_DELETE_PAGE;
event = DataEvent.API_PAGE_DELETE; event = TASK_PAGE_DELETE;
content = CONTENT_TYPE_JSON; content = CONTENT_TYPE_JSON;
break; 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) { syncNav(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( this._request(
API_NAV_SYNC, API_NAV_SYNC,
DataEvent.API_SETTINGS_WRITE, TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
data 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) { sendMail(message) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( this._request(
API_SEND_MAIL, API_SEND_MAIL,
DataEvent.SEND_MAIL, TASK_SEND_MAIL,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
message 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) => { return new Promise((resolve, reject) => {
this._request( this._request(
API_REINDEX_PAGES, API_REINDEX_PAGES,
DataEvent.API_REINDEX_PAGES, TASK_REINDEX_PAGE,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_JSON, CONTENT_TYPE_JSON,
data data
@ -208,14 +284,11 @@ export default class APIUtils {
}; };
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) { if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
if ( if (
eventType === DataEvent.API_PAGE_WRITE || eventType === TASK_SETTINGS_WRITE ||
eventType === DataEvent.API_IMAGES_UPLOAD || eventType === TASK_PAGE_EDIT ||
eventType === DataEvent.API_SETTINGS_WRITE || eventType === TASK_PAGE_DELETE ||
eventType === DataEvent.API_PAGE_DELETE || eventType === TASK_PUBLISH_SITE ||
eventType === DataEvent.API_RENDER_PAGES || eventType === TASK_REINDEX_PAGE
eventType === DataEvent.API_BACKUP_CREATE ||
eventType === DataEvent.API_BACKUP_RESTORE ||
eventType === DataEvent.API_REINDEX_PAGES
) )
request.setRequestHeader("fipamo-access-token", self.token); request.setRequestHeader("fipamo-access-token", self.token);

Loading…
Cancel
Save