Part of https://github.com/appsmithorg/appsmith/pull/33724. This is an effort to harden the server in terms of what request payloads are acceptable. **/test all** <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced API request payload handling for creating actions to include additional properties, improving data integrity and server-side validation. - **Improvements** - Refined data manipulation and payload structures in datasource-related API requests for better compatibility with server requirements. <!-- end of auto-generated comment: release notes by coderabbit.ai --><!-- This is an auto-generated comment: Cypress test results --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9626214547> > Commit: fe5db45aeb916b176aec3ded06f1a9da1bf08898 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9626214547&attempt=2&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank">Cypress dashboard</a>. > Tags: `` > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/Widgets/RTE/RichTextEditor3_spec.ts > <li>cypress/e2e/Regression/ClientSide/Widgets/RTE/RichTextEditor_1_spec.js > <li>cypress/e2e/Regression/ClientSide/Widgets/RTE/RichTextEditor_2_spec.js </ol> > <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">List of identified flaky tests</a>. <!-- end of auto-generated comment: Cypress test results -->
180 lines
5.3 KiB
TypeScript
180 lines
5.3 KiB
TypeScript
import { DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
|
|
import API from "api/Api";
|
|
import type { ApiResponse } from "./ApiResponses";
|
|
import type { AxiosPromise } from "axios";
|
|
|
|
import type { Datasource, DatasourceStorage } from "entities/Datasource";
|
|
export interface CreateDatasourceConfig {
|
|
name: string;
|
|
pluginId: string;
|
|
type?: string;
|
|
// key in the map representation of environment id of type string
|
|
datasourceStorages: Record<string, DatasourceStorage>;
|
|
//Passed for logging purposes.
|
|
appName?: string;
|
|
}
|
|
|
|
// type executeQueryData = Array<{ key?: string; value?: string }>;
|
|
type executeQueryData = Record<string, any>;
|
|
|
|
interface executeDatasourceQueryRequest {
|
|
datasourceId: string;
|
|
data?: executeQueryData;
|
|
}
|
|
|
|
class DatasourcesApi extends API {
|
|
static url = "v1/datasources";
|
|
|
|
static async fetchDatasources(
|
|
workspaceId: string,
|
|
): Promise<AxiosPromise<ApiResponse<Datasource[]>>> {
|
|
return API.get(DatasourcesApi.url + `?workspaceId=${workspaceId}`);
|
|
}
|
|
|
|
static async createDatasource(
|
|
datasourceConfig: Partial<Datasource>,
|
|
): Promise<any> {
|
|
// This here abomination is to remove several fields that are not accepted by the server.
|
|
for (const [name, storage] of Object.entries(
|
|
datasourceConfig.datasourceStorages || {},
|
|
)) {
|
|
datasourceConfig = {
|
|
...datasourceConfig,
|
|
isValid: undefined,
|
|
datasourceStorages: {
|
|
...datasourceConfig.datasourceStorages,
|
|
[name]: {
|
|
...storage,
|
|
isValid: undefined,
|
|
toastMessage: undefined,
|
|
datasourceConfiguration: {
|
|
...storage.datasourceConfiguration,
|
|
isValid: undefined,
|
|
connection: storage.datasourceConfiguration.connection && {
|
|
...storage.datasourceConfiguration.connection,
|
|
ssl: {
|
|
...storage.datasourceConfiguration.connection.ssl,
|
|
authTypeControl: undefined,
|
|
certificateType: undefined,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
} as any;
|
|
}
|
|
|
|
return API.post(DatasourcesApi.url, datasourceConfig);
|
|
}
|
|
|
|
// Api to test current environment datasource
|
|
static async testDatasource(
|
|
datasourceConfig: Partial<DatasourceStorage>,
|
|
pluginId: string,
|
|
workspaceId: string,
|
|
): Promise<any> {
|
|
const payload = {
|
|
...datasourceConfig,
|
|
pluginId,
|
|
workspaceId,
|
|
isValid: undefined,
|
|
toastMessage: undefined,
|
|
datasourceConfiguration: datasourceConfig.datasourceConfiguration && {
|
|
...datasourceConfig.datasourceConfiguration,
|
|
connection: datasourceConfig.datasourceConfiguration.connection && {
|
|
...datasourceConfig.datasourceConfiguration.connection,
|
|
ssl: {
|
|
...datasourceConfig.datasourceConfiguration.connection.ssl,
|
|
certificateType: undefined,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
return API.post(`${DatasourcesApi.url}/test`, payload, undefined, {
|
|
timeout: DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS,
|
|
});
|
|
}
|
|
|
|
// Api to update datasource name.
|
|
static async updateDatasource(
|
|
datasourceConfig: Partial<Datasource>,
|
|
id: string,
|
|
): Promise<any> {
|
|
return API.put(DatasourcesApi.url + `/${id}`, datasourceConfig);
|
|
}
|
|
|
|
// Api to update specific datasource storage/environment configuration
|
|
static async updateDatasourceStorage(
|
|
datasourceStorage: Partial<DatasourceStorage>,
|
|
): Promise<any> {
|
|
const payload = {
|
|
...datasourceStorage,
|
|
isValid: undefined,
|
|
toastMessage: undefined,
|
|
datasourceConfiguration: datasourceStorage.datasourceConfiguration && {
|
|
...datasourceStorage.datasourceConfiguration,
|
|
connection: datasourceStorage.datasourceConfiguration.connection && {
|
|
...datasourceStorage.datasourceConfiguration.connection,
|
|
ssl: {
|
|
...datasourceStorage.datasourceConfiguration.connection.ssl,
|
|
authTypeControl: undefined,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
return API.put(DatasourcesApi.url + `/datasource-storages`, payload);
|
|
}
|
|
|
|
static async deleteDatasource(id: string): Promise<any> {
|
|
return API.delete(DatasourcesApi.url + `/${id}`);
|
|
}
|
|
|
|
static async fetchDatasourceStructure(
|
|
id: string,
|
|
ignoreCache = false,
|
|
): Promise<any> {
|
|
return API.get(
|
|
DatasourcesApi.url + `/${id}/structure?ignoreCache=${ignoreCache}`,
|
|
);
|
|
}
|
|
|
|
static async fetchMockDatasources(): Promise<
|
|
AxiosPromise<ApiResponse<Datasource[]>>
|
|
> {
|
|
return API.get(DatasourcesApi.url + "/mocks");
|
|
}
|
|
|
|
static async addMockDbToDatasources(
|
|
name: string,
|
|
workspaceId: string,
|
|
pluginId: string,
|
|
packageName: string,
|
|
): Promise<any> {
|
|
return API.post(DatasourcesApi.url + `/mocks`, {
|
|
name,
|
|
workspaceId,
|
|
pluginId,
|
|
packageName,
|
|
});
|
|
}
|
|
|
|
static async executeDatasourceQuery({
|
|
data,
|
|
datasourceId,
|
|
}: executeDatasourceQueryRequest) {
|
|
return API.post(
|
|
DatasourcesApi.url + `/${datasourceId}` + `/schema-preview`,
|
|
data,
|
|
);
|
|
}
|
|
|
|
static async executeGoogleSheetsDatasourceQuery({
|
|
data,
|
|
datasourceId,
|
|
}: executeDatasourceQueryRequest) {
|
|
return API.post(DatasourcesApi.url + `/${datasourceId}` + `/trigger`, data);
|
|
}
|
|
}
|
|
|
|
export default DatasourcesApi;
|