2020-06-19 16:27:12 +00:00
|
|
|
import API, { HttpMethod } from "./Api";
|
2019-10-29 12:02:58 +00:00
|
|
|
import { ApiResponse, GenericApiResponse, ResponseMeta } from "./ApiResponses";
|
2020-05-07 08:07:29 +00:00
|
|
|
import {
|
|
|
|
|
APIRequest,
|
|
|
|
|
DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
|
|
|
|
|
} from "constants/ApiConstants";
|
2019-10-29 12:02:58 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
2020-06-04 13:49:22 +00:00
|
|
|
import { RestAction } from "entities/Action";
|
2019-09-12 11:44:18 +00:00
|
|
|
|
|
|
|
|
export interface CreateActionRequest<T> extends APIRequest {
|
2019-11-07 09:32:38 +00:00
|
|
|
datasourceId: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
pageId: string;
|
|
|
|
|
name: string;
|
2019-09-16 10:37:38 +00:00
|
|
|
actionConfiguration: T;
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UpdateActionRequest<T> extends CreateActionRequest<T> {
|
2019-09-16 10:37:38 +00:00
|
|
|
actionId: string;
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 10:11:50 +00:00
|
|
|
export interface Property {
|
|
|
|
|
key: string;
|
2020-06-04 13:49:22 +00:00
|
|
|
value?: string;
|
2019-09-17 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-14 12:34:14 +00:00
|
|
|
export interface BodyFormData {
|
|
|
|
|
editable: boolean;
|
|
|
|
|
mandatory: boolean;
|
|
|
|
|
description: string;
|
|
|
|
|
key: string;
|
|
|
|
|
value?: string;
|
|
|
|
|
type: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 11:44:18 +00:00
|
|
|
export interface QueryConfig {
|
2019-09-16 10:37:38 +00:00
|
|
|
queryString: string;
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
export interface ActionCreateUpdateResponse extends ApiResponse {
|
2019-10-21 15:12:45 +00:00
|
|
|
id: string;
|
|
|
|
|
jsonPathKeys: Record<string, string>;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 20:27:39 +00:00
|
|
|
export type PaginationField = "PREV" | "NEXT";
|
2020-02-07 02:32:52 +00:00
|
|
|
|
2019-09-12 13:44:25 +00:00
|
|
|
export interface ExecuteActionRequest extends APIRequest {
|
2019-11-12 09:43:13 +00:00
|
|
|
action: Pick<RestAction, "id"> | Omit<RestAction, "id">;
|
2019-11-01 07:11:32 +00:00
|
|
|
params?: Property[];
|
2020-03-12 20:27:39 +00:00
|
|
|
paginationField?: PaginationField;
|
2019-09-12 13:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-05 07:50:30 +00:00
|
|
|
export interface ExecuteQueryRequest extends APIRequest {
|
|
|
|
|
action: Pick<RestAction, "id"> | Omit<RestAction, "id">;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 13:44:25 +00:00
|
|
|
export interface ExecuteActionResponse extends ApiResponse {
|
2019-09-16 10:37:38 +00:00
|
|
|
actionId: string;
|
|
|
|
|
data: any;
|
2019-09-12 13:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-19 16:27:12 +00:00
|
|
|
export interface ActionApiResponseReq {
|
|
|
|
|
headers: Record<string, string[]>;
|
|
|
|
|
body: object | null;
|
|
|
|
|
httpMethod: HttpMethod | "";
|
|
|
|
|
url: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
export interface ActionApiResponse {
|
2019-11-12 09:43:13 +00:00
|
|
|
responseMeta: ResponseMeta;
|
|
|
|
|
data: {
|
|
|
|
|
body: object;
|
|
|
|
|
headers: Record<string, string[]>;
|
2020-03-12 20:27:39 +00:00
|
|
|
statusCode: string;
|
2020-05-14 06:33:23 +00:00
|
|
|
isExecutionSuccess: boolean;
|
2020-06-19 16:27:12 +00:00
|
|
|
request: ActionApiResponseReq;
|
2019-11-12 09:43:13 +00:00
|
|
|
};
|
|
|
|
|
clientMeta: {
|
|
|
|
|
duration: string;
|
|
|
|
|
size: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ActionResponse {
|
|
|
|
|
body: object;
|
2019-10-29 12:02:58 +00:00
|
|
|
headers: Record<string, string[]>;
|
2020-06-19 17:33:02 +00:00
|
|
|
request?: ActionApiResponseReq;
|
2020-03-12 20:27:39 +00:00
|
|
|
statusCode: string;
|
2019-10-29 12:02:58 +00:00
|
|
|
duration: string;
|
|
|
|
|
size: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 09:54:40 +00:00
|
|
|
export interface MoveActionRequest {
|
|
|
|
|
action: RestAction;
|
|
|
|
|
destinationPageId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CopyActionRequest {
|
|
|
|
|
action: RestAction;
|
|
|
|
|
pageId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 10:23:19 +00:00
|
|
|
export interface UpdateActionNameRequest {
|
|
|
|
|
pageId: string;
|
|
|
|
|
layoutId: string;
|
|
|
|
|
newName: string;
|
|
|
|
|
oldName: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 10:11:50 +00:00
|
|
|
class ActionAPI extends API {
|
|
|
|
|
static url = "v1/actions";
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
static fetchAPI(id: string): AxiosPromise<GenericApiResponse<RestAction>> {
|
2019-10-21 15:12:45 +00:00
|
|
|
return API.get(`${ActionAPI.url}/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
static createAPI(
|
|
|
|
|
apiConfig: RestAction,
|
|
|
|
|
): AxiosPromise<ActionCreateUpdateResponse> {
|
2019-10-21 15:12:45 +00:00
|
|
|
return API.post(ActionAPI.url, apiConfig);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 15:24:27 +00:00
|
|
|
static fetchActions(
|
2020-01-24 09:54:40 +00:00
|
|
|
applicationId: string,
|
2019-12-11 15:24:27 +00:00
|
|
|
): AxiosPromise<GenericApiResponse<RestAction[]>> {
|
2020-01-24 09:54:40 +00:00
|
|
|
return API.get(ActionAPI.url, { applicationId });
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-15 13:01:35 +00:00
|
|
|
static fetchActionsForViewMode(
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<RestAction[]>> {
|
|
|
|
|
return API.get(`${ActionAPI.url}/view`, { applicationId });
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 12:16:49 +00:00
|
|
|
static fetchActionsByPageId(
|
|
|
|
|
pageId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<RestAction[]>> {
|
|
|
|
|
return API.get(ActionAPI.url, { pageId });
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
static updateAPI(
|
|
|
|
|
apiConfig: Partial<RestAction>,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<ActionCreateUpdateResponse> {
|
2019-12-16 08:49:10 +00:00
|
|
|
return API.put(`${ActionAPI.url}/${apiConfig.id}`, apiConfig);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-16 10:23:19 +00:00
|
|
|
static updateActionName(updateActionNameRequest: UpdateActionNameRequest) {
|
|
|
|
|
return API.put(ActionAPI.url + "/refactor", updateActionNameRequest);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
static deleteAction(id: string) {
|
|
|
|
|
return API.delete(`${ActionAPI.url}/${id}`);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static createQuery(
|
|
|
|
|
createQuery: CreateActionRequest<QueryConfig>,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<ActionCreateUpdateResponse> {
|
2019-09-17 10:11:50 +00:00
|
|
|
return API.post(ActionAPI.url, createQuery);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static updateQuery(
|
|
|
|
|
updateQuery: UpdateActionRequest<QueryConfig>,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<ActionCreateUpdateResponse> {
|
2019-09-17 10:11:50 +00:00
|
|
|
return API.post(ActionAPI.url, updateQuery);
|
2019-09-12 13:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static executeAction(
|
|
|
|
|
executeAction: ExecuteActionRequest,
|
2020-05-07 08:07:29 +00:00
|
|
|
timeout?: number,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<ActionApiResponse> {
|
2020-05-05 08:13:39 +00:00
|
|
|
return API.post(ActionAPI.url + "/execute", executeAction, undefined, {
|
2020-05-07 08:07:29 +00:00
|
|
|
timeout: timeout || DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
|
2020-05-05 08:13:39 +00:00
|
|
|
});
|
2019-09-16 10:37:38 +00:00
|
|
|
}
|
2020-01-24 09:54:40 +00:00
|
|
|
|
|
|
|
|
static moveAction(moveRequest: MoveActionRequest) {
|
2020-07-06 13:35:31 +00:00
|
|
|
return API.put(ActionAPI.url + "/move", moveRequest, undefined, {
|
|
|
|
|
timeout: DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
|
|
|
|
|
});
|
2020-01-24 09:54:40 +00:00
|
|
|
}
|
2020-05-05 07:50:30 +00:00
|
|
|
|
|
|
|
|
static executeQuery(executeAction: any): AxiosPromise<ActionApiResponse> {
|
|
|
|
|
return API.post(ActionAPI.url + "/execute", executeAction);
|
|
|
|
|
}
|
2019-09-12 12:19:46 +00:00
|
|
|
}
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
export default ActionAPI;
|