2019-09-16 10:37:38 +00:00
|
|
|
import Api, { HttpMethod } from "./Api";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
|
|
|
|
import { APIRequest } from "./ApiRequests";
|
2019-09-12 11:44:18 +00:00
|
|
|
|
|
|
|
|
export interface CreateActionRequest<T> extends APIRequest {
|
2019-09-16 10:37:38 +00:00
|
|
|
resourceId: string;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface APIConfig {
|
2019-09-16 10:37:38 +00:00
|
|
|
requestHeaders: Record<string, string>;
|
|
|
|
|
method: HttpMethod;
|
|
|
|
|
path: string;
|
|
|
|
|
APIName: string;
|
|
|
|
|
body: JSON;
|
|
|
|
|
queryParams: Record<string, 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 {
|
|
|
|
|
actionId: string;
|
|
|
|
|
dynamicBindingMap: Record<string, string>;
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-12 13:44:25 +00:00
|
|
|
export interface ExecuteActionRequest extends APIRequest {
|
2019-09-16 10:37:38 +00:00
|
|
|
actionId: string;
|
|
|
|
|
dynamicBindingMap: Record<string, any>;
|
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
|
|
|
}
|
|
|
|
|
|
2019-09-12 11:44:18 +00:00
|
|
|
class ActionAPI extends Api {
|
2019-09-16 10:37:38 +00:00
|
|
|
static url = "/actions";
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static createAPI(
|
|
|
|
|
createAPI: CreateActionRequest<APIConfig>,
|
|
|
|
|
): Promise<ActionCreateUpdateResponse> {
|
|
|
|
|
return Api.post(ActionAPI.url, createAPI);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static updateAPI(
|
|
|
|
|
updateAPI: UpdateActionRequest<APIConfig>,
|
|
|
|
|
): Promise<ActionCreateUpdateResponse> {
|
|
|
|
|
return Api.post(ActionAPI.url, updateAPI);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
static createQuery(
|
|
|
|
|
createQuery: CreateActionRequest<QueryConfig>,
|
|
|
|
|
): Promise<ActionCreateUpdateResponse> {
|
|
|
|
|
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>,
|
|
|
|
|
): Promise<ActionCreateUpdateResponse> {
|
|
|
|
|
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,
|
|
|
|
|
): Promise<ActionCreateUpdateResponse> {
|
|
|
|
|
return Api.post(ActionAPI.url, 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;
|