PromucFlow_constructor/app/client/src/api/ActionAPI.tsx

72 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-09-12 11:44:18 +00:00
import Api, { HttpMethod } from "./Api"
import { ApiResponse } from "./ApiResponses"
import { APIRequest } from './ApiRequests';
export interface CreateActionRequest<T> extends APIRequest {
resourceId: string
actionConfiguration: T
}
export interface UpdateActionRequest<T> extends CreateActionRequest<T> {
actionId: string
}
export interface APIConfig {
requestHeaders: Record<string, string>
method: HttpMethod
path: string
APIName: string
body: JSON
queryParams: Record<string, string>
}
export interface QueryConfig {
queryString: string
}
2019-09-12 12:19:46 +00:00
export interface ActionCreatedResponse extends ApiResponse {
actionId: string
2019-09-13 09:56:11 +00:00
dynamicBindingMap: Record<string, string>
2019-09-12 11:44:18 +00:00
}
2019-09-12 12:19:46 +00:00
export interface ActionUpdatedResponse extends ActionCreatedResponse {
2019-09-12 11:44:18 +00:00
}
2019-09-12 13:44:25 +00:00
export interface ExecuteActionRequest extends APIRequest {
actionId: string
2019-09-13 09:56:11 +00:00
dynamicBindingMap: Record<string, any>
2019-09-12 13:44:25 +00:00
}
export interface ExecuteActionResponse extends ApiResponse {
actionId: string
data: any
}
2019-09-12 11:44:18 +00:00
class ActionAPI extends Api {
static url = "/actions"
2019-09-12 12:19:46 +00:00
static createAPI(createAPI: CreateActionRequest<APIConfig>): Promise<ActionCreatedResponse> {
2019-09-12 11:44:18 +00:00
return Api.post(ActionAPI.url, createAPI)
}
2019-09-12 12:19:46 +00:00
static updateAPI(updateAPI: UpdateActionRequest<APIConfig>): Promise<ActionUpdatedResponse> {
2019-09-12 11:44:18 +00:00
return Api.post(ActionAPI.url, updateAPI)
}
2019-09-12 12:19:46 +00:00
static createQuery(createQuery: CreateActionRequest<QueryConfig>): Promise<ActionCreatedResponse> {
2019-09-12 11:44:18 +00:00
return Api.post(ActionAPI.url, createQuery)
}
2019-09-12 12:19:46 +00:00
static updateQuery(updateQuery: UpdateActionRequest<QueryConfig>): Promise<ActionUpdatedResponse> {
2019-09-12 11:44:18 +00:00
return Api.post(ActionAPI.url, updateQuery)
}
2019-09-12 13:44:25 +00:00
static executeAction(executeAction: ExecuteActionRequest): Promise<ActionUpdatedResponse> {
return Api.post(ActionAPI.url, executeAction)
}
2019-09-12 12:19:46 +00:00
}
2019-09-12 11:44:18 +00:00
export default ActionAPI