Add serverless function in twenty-cli (#14819)

- add serverlessFunction schema in twenty-cli
- add trigger schema in twenty-cli
- update serverless function code save and get
- sync serverless function
This commit is contained in:
martmull
2025-10-01 22:11:03 +02:00
committed by GitHub
parent 64dc726f50
commit 6fdd7894a1
47 changed files with 853 additions and 159 deletions
@@ -5,6 +5,8 @@ import {
AGENT_SCHEMA_URL,
APP_MANIFEST_SCHEMA_URL,
OBJECT_SCHEMA_URL,
SERVERLESS_FUNCTION_SCHEMA_URL,
TRIGGER_SCHEMA_URL,
} from '../constants/schemas';
export class SchemaValidationError extends Error {
@@ -31,7 +33,7 @@ const formatErrors = (errors: any[]): string => {
};
export const validateSchema = async (
schemaName: 'app-manifest' | 'agent' | 'object',
schemaName: 'appManifest' | 'agent' | 'object' | 'serverlessFunction',
manifest: any,
filePath?: string,
): Promise<void> => {
@@ -39,18 +41,19 @@ export const validateSchema = async (
allErrors: true,
verbose: true,
strict: false,
$data: true,
});
const schemaUrls = getSchemaUrls();
let schema;
for (const name of Object.keys(schemaUrls) as (keyof typeof schemaUrls)[]) {
const formattedName = name === 'appManifest' ? 'app-manifest' : name;
const schemasDir = path.join(__dirname, '../../schemas');
const schemaPath = path.join(schemasDir, `${formattedName}.schema.json`);
const schemaPath = path.join(schemasDir, `${name}.schema.json`);
ajv.addSchema(await fs.readJson(schemaPath));
if (formattedName === schemaName) {
if (name === schemaName) {
schema = ajv.getSchema(schemaUrls[name])?.schema;
}
}
@@ -71,8 +74,10 @@ export const validateSchema = async (
export const getSchemaUrls = () => {
return {
trigger: TRIGGER_SCHEMA_URL,
agent: AGENT_SCHEMA_URL,
object: OBJECT_SCHEMA_URL,
serverlessFunction: SERVERLESS_FUNCTION_SCHEMA_URL,
appManifest: APP_MANIFEST_SCHEMA_URL,
};
};