import API from "api/Api"; import type { AxiosPromise } from "axios"; import type { JSCollection } from "entities/JSCollection"; import type { ApiResponse } from "api/ApiResponses"; import type { Variable, JSAction } from "entities/JSCollection"; import type { PluginType } from "entities/Action"; import type { FetchActionsPayload } from "api/ActionAPI"; import type { ActionContextTypeInterface } from "@appsmith/entities/Engine/actionHelpers"; export type JSCollectionCreateUpdateResponse = ApiResponse & { id: string; }; export interface MoveJSCollectionRequest { collectionId: string; destinationPageId: string; name: string; } export interface UpdateJSObjectNameRequest { pageId?: string; actionCollectionId: string; layoutId?: string; newName: string; oldName: string; moduleId?: string; contextType?: ActionContextTypeInterface; } export interface CreateJSCollectionRequest { name: string; pageId: string; workspaceId: string; pluginId: string; body: string; variables: Array; actions: Array>; applicationId: string; pluginType: PluginType; workflowId?: string; contextType?: ActionContextTypeInterface; moduleId?: string; } export interface SetFunctionPropertyPayload { action: JSAction; propertyName: string; value: any; } export interface RefactorAction { pageId: string; actionId: string; newName: string; oldName: string; collectionName: string; } export interface RefactorActionRequest extends RefactorAction { layoutId: string; } export interface UpdateCollectionActionNameRequest extends RefactorActionRequest { actionCollection: JSCollection; } class JSActionAPI extends API { static url = "v1/collections/actions"; static async fetchJSCollections( payload: FetchActionsPayload, ): Promise>> { return API.get(JSActionAPI.url, payload); } static async createJSCollection( jsConfig: CreateJSCollectionRequest, ): Promise> { return API.post(JSActionAPI.url, jsConfig); } static async copyJSCollection( jsConfig: Partial, ): Promise> { return API.post(JSActionAPI.url, jsConfig); } static async updateJSCollection( jsConfig: JSCollection, ): Promise> { const jsAction = Object.assign({}, jsConfig); return API.put(`${JSActionAPI.url}/${jsAction.id}`, jsAction); } static async deleteJSCollection(id: string) { return API.delete(`${JSActionAPI.url}/${id}`); } static async moveJSCollection(moveRequest: MoveJSCollectionRequest) { return API.put(JSActionAPI.url + "/move", moveRequest); } static async fetchJSCollectionsByPageId( pageId: string, ): Promise>> { return API.get(JSActionAPI.url, { pageId }); } static async fetchJSCollectionsForViewMode( applicationId: string, ): Promise>> { return API.get(`${JSActionAPI.url}/view`, { applicationId }); } static async updateJSCollectionOrActionName( updateJSObjectNameRequest: UpdateJSObjectNameRequest, ) { return API.put(JSActionAPI.url + "/refactor", updateJSObjectNameRequest); } static async updateJSCollectionActionRefactor( updateJSCollectionActionName: UpdateCollectionActionNameRequest, ) { return API.put( JSActionAPI.url + "/refactorAction", updateJSCollectionActionName, ); } } export default JSActionAPI;