Skip to content

The open alternative to Salesforce, designed for AI.

1825 extensibility v1 see serverless logs using subscriptions in twnty cli or settings serverkess section (#16321)

martmull5e8fbc7c5cfb
diff --git a/packages/create-twenty-app/README.md b/packages/create-twenty-app/README.md
index ce7cd052f59..96b3c2c44aa 100644
--- a/packages/create-twenty-app/README.md
+++ b/packages/create-twenty-app/README.md
@@ -42,8 +42,14 @@ yarn dev
# Or run a one‑time sync
yarn sync
+# Watch your application's functions logs
+yarn logs
+
# Uninstall the application from the current workspace
yarn uninstall
+
+# Display commands' help
+yarn help
```
## What gets scaffolded
diff --git a/packages/create-twenty-app/package.json b/packages/create-twenty-app/package.json
index d387a360cbc..b520bbcb71a 100644
--- a/packages/create-twenty-app/package.json
+++ b/packages/create-twenty-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-twenty-app",
- "version": "0.1.0",
+ "version": "0.1.3",
"description": "Command-line interface to create Twenty application",
"main": "dist/cli.cjs",
"bin": "dist/cli.cjs",
diff --git a/packages/create-twenty-app/src/constants/base-application/README.md b/packages/create-twenty-app/src/constants/base-application/README.md
index 58bc619f4e5..6f50cba69c6 100644
--- a/packages/create-twenty-app/src/constants/base-application/README.md
+++ b/packages/create-twenty-app/src/constants/base-application/README.md
@@ -8,22 +8,14 @@ First, authenticate to your workspace:
yarn auth
```
-Then, run the development server:
+Then, install this app to your workspace:
```bash
-yarn dev
+yarn sync
```
Open your Twenty instance and go to `/settings/applications` section to see the result.
-You can start adding twenty entities by running
-
-```bash
-yarn create-entity
-```
-
-The application auto-updates as you edit the file.
-
## Learn More
To learn more about Twenty applications, take a look at the following resources:
diff --git a/packages/create-twenty-app/src/utils/app-template.ts b/packages/create-twenty-app/src/utils/app-template.ts
index 4310c9836f2..1ce01a31902 100644
--- a/packages/create-twenty-app/src/utils/app-template.ts
+++ b/packages/create-twenty-app/src/utils/app-template.ts
@@ -121,11 +121,13 @@ const createPackageJson = async ({
dev: 'twenty app dev',
generate: 'twenty app generate',
sync: 'twenty app sync',
+ logs: 'twenty app logs',
uninstall: 'twenty app uninstall',
+ help: 'twenty help',
auth: 'twenty auth login',
},
dependencies: {
- 'twenty-sdk': '0.1.2',
+ 'twenty-sdk': '0.1.3',
},
devDependencies: {
'@types/node': '^24.7.2',
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index 25d12b57fa8..dcc9d7bb4a5 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -3946,6 +3946,20 @@ export type ServerlessFunctionLayer = {
updatedAt: Scalars['DateTime'];
};
+export type ServerlessFunctionLogs = {
+ __typename?: 'ServerlessFunctionLogs';
+ /** Execution Logs */
+ logs: Scalars['String'];
+};
+
+export type ServerlessFunctionLogsInput = {
+ applicationId?: InputMaybe<Scalars['UUID']>;
+ applicationUniversalIdentifier?: InputMaybe<Scalars['UUID']>;
+ id?: InputMaybe<Scalars['UUID']>;
+ name?: InputMaybe<Scalars['String']>;
+ universalIdentifier?: InputMaybe<Scalars['UUID']>;
+};
+
export type SetupOidcSsoInput = {
clientID: Scalars['String'];
clientSecret: Scalars['String'];
@@ -4008,6 +4022,7 @@ export type SubmitFormStepInput = {
export type Subscription = {
__typename?: 'Subscription';
onDbEvent: OnDbEvent;
+ serverlessFunctionLogs: ServerlessFunctionLogs;
};
@@ -4015,6 +4030,11 @@ export type SubscriptionOnDbEventArgs = {
input: OnDbEventInput;
};
+
+export type SubscriptionServerlessFunctionLogsArgs = {
+ input: ServerlessFunctionLogsInput;
+};
+
export enum SubscriptionInterval {
Month = 'Month',
Year = 'Year'
diff --git a/packages/twenty-front/src/generated/graphql.ts b/packages/twenty-front/src/generated/graphql.ts
index 32d76a69377..10b89c09f8c 100644
--- a/packages/twenty-front/src/generated/graphql.ts
+++ b/packages/twenty-front/src/generated/graphql.ts
@@ -3783,6 +3783,20 @@ export type ServerlessFunctionLayer = {
updatedAt: Scalars['DateTime'];
};
+export type ServerlessFunctionLogs = {
+ __typename?: 'ServerlessFunctionLogs';
+ /** Execution Logs */
+ logs: Scalars['String'];
+};
+
+export type ServerlessFunctionLogsInput = {
+ applicationId?: InputMaybe<Scalars['UUID']>;
+ applicationUniversalIdentifier?: InputMaybe<Scalars['UUID']>;
+ id?: InputMaybe<Scalars['UUID']>;
+ name?: InputMaybe<Scalars['String']>;
+ universalIdentifier?: InputMaybe<Scalars['UUID']>;
+};
+
export type SetupOidcSsoInput = {
clientID: Scalars['String'];
clientSecret: Scalars['String'];
@@ -3845,6 +3859,7 @@ export type SubmitFormStepInput = {
export type Subscription = {
__typename?: 'Subscription';
onDbEvent: OnDbEvent;
+ serverlessFunctionLogs: ServerlessFunctionLogs;
};
@@ -3852,6 +3867,11 @@ export type SubscriptionOnDbEventArgs = {
input: OnDbEventInput;
};
+
+export type SubscriptionServerlessFunctionLogsArgs = {
+ input: ServerlessFunctionLogsInput;
+};
+
export enum SubscriptionInterval {
Month = 'Month',
Year = 'Year'
diff --git a/packages/twenty-front/src/modules/serverless-functions/components/ServerlessFunctionExecutionResult.tsx b/packages/twenty-front/src/modules/serverless-functions/components/ServerlessFunctionExecutionResult.tsx
index 65182f635d4..8e4c2205e6a 100644
--- a/packages/twenty-front/src/modules/serverless-functions/components/ServerlessFunctionExecutionResult.tsx
+++ b/packages/twenty-front/src/modules/serverless-functions/components/ServerlessFunctionExecutionResult.tsx
@@ -7,9 +7,11 @@ import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql'
export const ServerlessFunctionExecutionResult = ({
serverlessFunctionTestData,
+ maxHeight,
isTesting = false,
}: {
serverlessFunctionTestData: ServerlessFunctionTestData;
+ maxHeight?: number;
isTesting?: boolean;
}) => {
const result =
@@ -40,7 +42,10 @@ export const ServerlessFunctionExecutionResult = ({
<WorkflowStepExecutionResult
result={result}
language={serverlessFunctionTestData.language}
- height={serverlessFunctionTestData.height}
+ height={Math.min(
+ serverlessFunctionTestData.height,
+ maxHeight ?? serverlessFunctionTestData.height,
+ )}
status={status}
isTesting={isTesting}
loadingMessage="Running function"
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
index ea08012795d..b4701ffbb60 100644
--- a/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
+++ b/packages/twenty-front/src/modules/settings/serverless-functions/components/tabs/SettingsServerlessFunctionTestTab.tsx
@@ -6,6 +6,8 @@ import { useRecoilState } from 'recoil';
import { H2Title, IconPlayerPlay } from 'twenty-ui/display';
import { Button, CodeEditor, CoreEditorHeader } from 'twenty-ui/input';
import { Section } from 'twenty-ui/layout';
+import { InputLabel } from '@/ui/input/components/InputLabel';
+import { TextArea } from '@/ui/input/components/TextArea';
const StyledInputsContainer = styled.div`
display: flex;
@@ -38,6 +40,8 @@ export const SettingsServerlessFunctionTestTab = ({
}));
};
+ const testLogsTextAreaId = `${serverlessFunctionId}-test-logs`;
+
return (
<Section>
<H2Title
@@ -63,15 +67,29 @@ export const SettingsServerlessFunctionTestTab = ({
<CodeEditor
value={JSON.stringify(serverlessFunctionTestData.input, null, 4)}
language="json"
- height={200}
+ height={100}
onChange={onChange}
variant="with-header"
/>
</StyledCodeEditorContainer>
<ServerlessFunctionExecutionResult
serverlessFunctionTestData={serverlessFunctionTestData}
+ maxHeight={
+ serverlessFunctionTestData.output.logs.length > 0 ? 200 : undefined
+ }
isTesting={isTesting}
/>
+ {serverlessFunctionTestData.output.logs.length > 0 && (
+ <StyledCodeEditorContainer>
+ <InputLabel>Logs</InputLabel>
+ <TextArea
+ textAreaId={testLogsTextAreaId}
+ value={isTesting ? '' : serverlessFunctionTestData.output.logs}
+ maxRows={20}
+ disabled
+ />
+ </StyledCodeEditorContainer>
+ )}
</StyledInputsContainer>
</Section>
);
diff --git a/packages/twenty-sdk/package.json b/packages/twenty-sdk/package.json
index 6129bb72483..e1cf05e04c8 100644
--- a/packages/twenty-sdk/package.json
+++ b/packages/twenty-sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "twenty-sdk",
- "version": "0.1.2",
+ "version": "0.1.3",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
@@ -38,6 +38,7 @@
"dotenv": "^16.4.0",
"fs-extra": "^11.2.0",
"graphql": "^16.8.1",
+ "graphql-sse": "^2.5.4",
"inquirer": "^10.0.0",
"jsonc-parser": "^3.2.0",
"lodash.camelcase": "^4.3.0",
@@ -66,5 +67,8 @@
"engines": {
"node": "^24.5.0",
"yarn": "^4.0.2"
+ },
+ "typesVersions": {
+ "*": {}
}
}
diff --git a/packages/twenty-sdk/src/cli/commands/app-logs.command.ts b/packages/twenty-sdk/src/cli/commands/app-logs.command.ts
new file mode 100644
index 00000000000..b736c625229
--- /dev/null
+++ b/packages/twenty-sdk/src/cli/commands/app-logs.command.ts
@@ -0,0 +1,62 @@
+import chalk from 'chalk';
+import { CURRENT_EXECUTION_DIRECTORY } from '@/cli/constants/current-execution-directory';
+import { loadManifest } from '@/cli/utils/load-manifest';
+import { ApiService } from '@/cli/services/api.service';
+
+export class AppLogsCommand {
+ private apiService = new ApiService();
+
+ async execute({
+ appPath = CURRENT_EXECUTION_DIRECTORY,
+ functionUniversalIdentifier,
+ functionName,
+ }: {
+ appPath?: string;
+ functionUniversalIdentifier?: string;
+ functionName?: string;
+ }): Promise<void> {
+ try {
+ const { manifest } = await loadManifest(appPath);
+ this.logWatchInfo({
+ appName: manifest.application.displayName,
+ functionUniversalIdentifier,
+ functionName,
+ });
+ await this.apiService.subscribeToLogs({
+ applicationUniversalIdentifier:
+ manifest.application.universalIdentifier,
+ functionUniversalIdentifier,
+ functionName,
+ });
+ } catch (error) {
+ console.error(
+ chalk.red('Watch logs failed:'),
+ error instanceof Error ? error.message : error,
+ );
+ process.exit(1);
+ }
+ }
+
+ private logWatchInfo({
+ appName,
+ functionUniversalIdentifier,
+ functionName,
+ }: {
+ appName?: string;
+ functionUniversalIdentifier?: string;
+ functionName?: string;
+ }): void {
+ const appPath = appName ?? 'Twenty Application';
+
+ const functionIdentifier =
+ functionUniversalIdentifier || functionName
+ ? `function "${functionUniversalIdentifier || functionName}"`
+ : 'functions';
+
+ console.log(
+ chalk.blue(`🚀 Watching ${appPath} ${functionIdentifier} logs:`),
+ );
+
+ console.log('');
+ }
+}
diff --git a/packages/twenty-sdk/src/cli/commands/app.command.ts b/packages/twenty-sdk/src/cli/commands/app.command.ts
index 2f7e1178e2f..c7f2e20c492 100644
--- a/packages/twenty-sdk/src/cli/commands/app.command.ts
+++ b/packages/twenty-sdk/src/cli/commands/app.command.ts
@@ -10,6 +10,7 @@ import { AppDevCommand } from './app-dev.command';
import { AppSyncCommand } from './app-sync.command';
import { formatPath } from '../utils/format-path';
import { AppGenerateCommand } from './app-generate.command';
+import { AppLogsCommand } from '@/cli/commands/app-logs.command';
export class AppCommand {
private devCommand = new AppDevCommand();
@@ -17,6 +18,7 @@ export class AppCommand {
private uninstallCommand = new AppUninstallCommand();
private addCommand = new AppAddCommand();
private generateCommand = new AppGenerateCommand();
+ private logsCommand = new AppLogsCommand();
getCommand(): Command {
const appCommand = new Command('app');
@@ -110,6 +112,32 @@ export class AppCommand {
await this.generateCommand.execute(formatPath(appPath));
});
+ appCommand
+ .command('logs [appPath]')
+ .option(
+ '-u, --functionUniversalIdentifier <functionUniversalIdentifier>',
+ 'Only show logs for the function with this universal ID',
+ )
+ .option(
+ '-n, --functionName <functionName>',
+ 'Only show logs for the function with this name',
+ )
+ .description('Watch application function logs')
+ .action(
+ async (
+ appPath?: string,
+ options?: {
+ functionUniversalIdentifier?: string;
+ functionName?: string;
+ },
+ ) => {
+ await this.logsCommand.execute({
+ ...options,
+ appPath: formatPath(appPath),
+ });
+ },
+ );
+
return appCommand;
}
}
diff --git a/packages/twenty-sdk/src/cli/services/api.service.ts b/packages/twenty-sdk/src/cli/services/api.service.ts
index d77d7c9551b..3adde433f10 100644
--- a/packages/twenty-sdk/src/cli/services/api.service.ts
+++ b/packages/twenty-sdk/src/cli/services/api.service.ts
@@ -5,6 +5,7 @@ import {
getIntrospectionQuery,
printSchema,
} from 'graphql/index';
+import { createClient } from 'graphql-sse';
import {
type ApiResponse,
type AppManifest,
@@ -235,4 +236,53 @@ export class ApiService {
throw error;
}
}
+
+ async subscribeToLogs({
+ applicationUniversalIdentifier,
+ functionUniversalIdentifier,
+ functionName,
+ }: {
+ applicationUniversalIdentifier: string;
+ functionUniversalIdentifier?: string;
+ functionName?: string;
+ }) {
+ const twentyConfig = await this.configService.getConfig();
+
+ const wsClient = createClient({
+ url: twentyConfig.apiUrl + '/graphql',
+ headers: {
+ Authorization: `Bearer ${twentyConfig.apiKey}`,
+ 'Content-Type': 'application/json',
+ Accept: 'text/event-stream',
+ },
+ });
+
+ const query = `
+ subscription SubscribeToLogs($input: ServerlessFunctionLogsInput!) {
+ serverlessFunctionLogs(input: $input) {
+ logs
+ }
+ }
+ `;
+
+ const variables = {
+ input: {
+ applicationUniversalIdentifier,
+ universalIdentifier: functionUniversalIdentifier,
+ name: functionName,
+ },
+ };
+
+ wsClient.subscribe<{ serverlessFunctionLogs: { logs: string } }>(
+ {
+ query,
+ variables,
+ },
+ {
+ next: ({ data }) => console.log(data?.serverlessFunctionLogs.logs),
+ error: (err: unknown) => console.error(err),
+ complete: () => console.log('Completed'),
+ },
+ );
+ }
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/constants/serverless-function-logs-trigger.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/constants/serverless-function-logs-trigger.ts
new file mode 100644
index 00000000000..be8db977124
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/constants/serverless-function-logs-trigger.ts
@@ -0,0 +1 @@
+export const SERVERLESS_FUNCTION_LOGS_TRIGGER = 'serverlessFunctionLogs';
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.dto.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.dto.ts
new file mode 100644
index 00000000000..534d2eea928
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.dto.ts
@@ -0,0 +1,22 @@
+import { Field, HideField, ObjectType } from '@nestjs/graphql';
+
+@ObjectType('ServerlessFunctionLogs')
+export class ServerlessFunctionLogsDTO {
+ @Field({ description: 'Execution Logs' })
+ logs: string;
+
+ @HideField()
+ applicationUniversalIdentifier?: string;
+
+ @HideField()
+ applicationId?: string;
+
+ @HideField()
+ name?: string;
+
+ @HideField()
+ id?: string;
+
+ @HideField()
+ universalIdentifier?: string;
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.input.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.input.ts
new file mode 100644
index 00000000000..a77eedf0d5c
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.input.ts
@@ -0,0 +1,21 @@
+import { Field, InputType } from '@nestjs/graphql';
+
+import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
+
+@InputType('ServerlessFunctionLogsInput')
+export class ServerlessFunctionLogsInput {
+ @Field(() => UUIDScalarType, { nullable: true })
+ applicationId?: string;
+
+ @Field(() => UUIDScalarType, { nullable: true })
+ applicationUniversalIdentifier?: string;
+
+ @Field(() => String, { nullable: true })
+ name?: string;
+
+ @Field(() => UUIDScalarType, { nullable: true })
+ id?: string;
+
+ @Field(() => UUIDScalarType, { nullable: true })
+ universalIdentifier?: string;
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
index 920ea6a3fc7..c5dee29d806 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
@@ -23,6 +23,7 @@ import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverles
import { ServerlessFunctionV2Service } from 'src/engine/metadata-modules/serverless-function/services/serverless-function-v2.service';
import { WorkspaceFlatServerlessFunctionMapCacheService } from 'src/engine/metadata-modules/serverless-function/services/workspace-flat-serverless-function-map-cache.service';
import { WorkspaceMigrationV2Module } from 'src/engine/workspace-manager/workspace-migration-v2/workspace-migration-v2.module';
+import { SubscriptionsModule } from 'src/engine/subscriptions/subscriptions.module';
@Module({
imports: [
@@ -43,6 +44,7 @@ import { WorkspaceMigrationV2Module } from 'src/engine/workspace-manager/workspa
WorkspaceManyOrAllFlatEntityMapsCacheModule,
WorkspaceMigrationV2Module,
ServerlessFunctionLayerModule,
+ SubscriptionsModule,
],
providers: [
ServerlessFunctionService,
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
index b452d3bb6dc..c6b89f719af 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.resolver.ts
@@ -1,9 +1,11 @@
-import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';
-import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
+import { Inject, UseFilters, UseGuards, UsePipes } from '@nestjs/common';
+import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
import { InjectRepository } from '@nestjs/typeorm';
import graphqlTypeJson from 'graphql-type-json';
import { Repository } from 'typeorm';
+import { RedisPubSub } from 'graphql-redis-subscriptions';
+import { isDefined } from 'twenty-shared/utils';
import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
@@ -24,6 +26,9 @@ import { UpdateServerlessFunctionInput } from 'src/engine/metadata-modules/serve
import { ServerlessFunctionEntity } from 'src/engine/metadata-modules/serverless-function/serverless-function.entity';
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import { serverlessFunctionGraphQLApiExceptionHandler } from 'src/engine/metadata-modules/serverless-function/utils/serverless-function-graphql-api-exception-handler.utils';
+import { ServerlessFunctionLogsDTO } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.dto';
+import { ServerlessFunctionLogsInput } from 'src/engine/metadata-modules/serverless-function/dtos/serverless-function-logs.input';
+import { SERVERLESS_FUNCTION_LOGS_TRIGGER } from 'src/engine/metadata-modules/serverless-function/constants/serverless-function-logs-trigger';
@UseGuards(
WorkspaceAuthGuard,
@@ -38,6 +43,8 @@ export class ServerlessFunctionResolver {
private readonly serverlessFunctionService: ServerlessFunctionService,
@InjectRepository(ServerlessFunctionEntity)
private readonly serverlessFunctionRepository: Repository<ServerlessFunctionEntity>,
+ @Inject('PUB_SUB')
+ private readonly pubSub: RedisPubSub,
) {}
@Query(() => ServerlessFunctionDTO)
@@ -184,4 +191,42 @@ export class ServerlessFunctionResolver {
serverlessFunctionGraphQLApiExceptionHandler(error);
}
}
+
+ @Subscription(() => ServerlessFunctionLogsDTO, {
+ filter: (
+ payload: { serverlessFunctionLogs: ServerlessFunctionLogsDTO },
+ variables: { input: ServerlessFunctionLogsInput },
+ ) => {
+ const { serverlessFunctionLogs } = payload;
+ const {
+ id,
+ universalIdentifier,
+ applicationId,
+ applicationUniversalIdentifier,
+ name,
+ } = serverlessFunctionLogs;
+ const {
+ id: inputId,
+ universalIdentifier: inputUniversalIdentifier,
+ name: inputName,
+ applicationId: inputApplicationId,
+ applicationUniversalIdentifier: inputApplicationUniversalIdentifier,
+ } = variables.input;
+
+ return (
+ (!isDefined(inputId) || inputId === id) &&
+ (!isDefined(inputUniversalIdentifier) ||
+ inputUniversalIdentifier === universalIdentifier) &&
+ (!isDefined(inputName) || inputName === name) &&
+ (!isDefined(inputApplicationId) ||
+ inputApplicationId === applicationId) &&
+ (!isDefined(inputApplicationUniversalIdentifier) ||
+ inputApplicationUniversalIdentifier ===
+ applicationUniversalIdentifier)
+ );
+ },
+ })
+ serverlessFunctionLogs(@Args('input') _: ServerlessFunctionLogsInput) {
+ return this.pubSub.asyncIterator(SERVERLESS_FUNCTION_LOGS_TRIGGER);
+ }
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
index fe81e62b000..59796474a7e 100644
--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
@@ -1,4 +1,4 @@
-import { Injectable } from '@nestjs/common';
+import { Inject, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { join } from 'path';
@@ -6,6 +6,7 @@ import { join } from 'path';
import deepEqual from 'deep-equal';
import { isDefined } from 'twenty-shared/utils';
import { IsNull, Not, Repository } from 'typeorm';
+import { RedisPubSub } from 'graphql-redis-subscriptions';
import { FileStorageExceptionCode } from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';
import { type ServerlessExecuteResult } from 'src/engine/core-modules/serverless/drivers/interfaces/serverless-driver.interface';
@@ -31,6 +32,7 @@ import {
WorkflowVersionStepException,
WorkflowVersionStepExceptionCode,
} from 'src/modules/workflow/common/exceptions/workflow-version-step.exception';
+import { SERVERLESS_FUNCTION_LOGS_TRIGGER } from 'src/engine/metadata-modules/serverless-function/constants/serverless-function-logs-trigger';
@Injectable()
export class ServerlessFunctionService {
@@ -43,6 +45,8 @@ export class ServerlessFunctionService {
private readonly throttlerService: ThrottlerService,
private readonly twentyConfigService: TwentyConfigService,
private readonly auditService: AuditService,
+ @Inject('PUB_SUB')
+ private readonly pubSub: RedisPubSub,
) {}
async hasServerlessFunctionPublishedVersion(serverlessFunctionId: string) {
@@ -98,6 +102,7 @@ export class ServerlessFunctionService {
},
relations: [
'serverlessFunctionLayer',
+ 'application',
'application.applicationVariables',
],
});
@@ -113,6 +118,18 @@ export class ServerlessFunctionService {
console.log(resultServerlessFunction.logs);
}
+ await this.pubSub.publish(SERVERLESS_FUNCTION_LOGS_TRIGGER, {
+ serverlessFunctionLogs: {
+ logs: resultServerlessFunction.logs,
+ id: functionToExecute.id,
+ name: functionToExecute.name,
+ universalIdentifier: functionToExecute.universalIdentifier,
+ applicationId: functionToExecute.applicationId,
+ applicationUniversalIdentifier:
+ functionToExecute.application?.universalIdentifier,
+ },
+ });
+
this.auditService
.createContext({
workspaceId,
diff --git a/packages/twenty-server/src/engine/subscriptions/constants/on-db-event-trigger.ts b/packages/twenty-server/src/engine/subscriptions/constants/on-db-event-trigger.ts
new file mode 100644
index 00000000000..3be4f4d989e
--- /dev/null
+++ b/packages/twenty-server/src/engine/subscriptions/constants/on-db-event-trigger.ts
@@ -0,0 +1 @@
+export const ON_DB_EVENT_TRIGGER = 'onDbEvent';
diff --git a/packages/twenty-server/src/engine/subscriptions/subscriptions.resolver.ts b/packages/twenty-server/src/engine/subscriptions/subscriptions.resolver.ts
index 2e8e5170568..91628e1085b 100644
--- a/packages/twenty-server/src/engine/subscriptions/subscriptions.resolver.ts
+++ b/packages/twenty-server/src/engine/subscriptions/subscriptions.resolver.ts
@@ -11,6 +11,7 @@ import { UserAuthGuard } from 'src/engine/guards/user-auth.guard';
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
import { OnDbEventDTO } from 'src/engine/subscriptions/dtos/on-db-event.dto';
import { OnDbEventInput } from 'src/engine/subscriptions/dtos/on-db-event.input';
+import { ON_DB_EVENT_TRIGGER } from 'src/engine/subscriptions/constants/on-db-event-trigger';
@Resolver()
@UseGuards(WorkspaceAuthGuard, UserAuthGuard, NoPermissionGuard)
@@ -43,6 +44,6 @@ export class SubscriptionsResolver {
},
})
onDbEvent(@Args('input') _: OnDbEventInput) {
- return this.pubSub.asyncIterator('onDbEvent');
+ return this.pubSub.asyncIterator(ON_DB_EVENT_TRIGGER);
}
}
diff --git a/packages/twenty-server/src/engine/subscriptions/subscriptions.service.ts b/packages/twenty-server/src/engine/subscriptions/subscriptions.service.ts
index b709cb6ec62..46a14c04f64 100644
--- a/packages/twenty-server/src/engine/subscriptions/subscriptions.service.ts
+++ b/packages/twenty-server/src/engine/subscriptions/subscriptions.service.ts
@@ -5,6 +5,7 @@ import { RedisPubSub } from 'graphql-redis-subscriptions';
import { type ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event-batch.type';
import { transformEventToWebhookEvent } from 'src/engine/core-modules/webhook/utils/transform-event-to-webhook-event';
+import { ON_DB_EVENT_TRIGGER } from 'src/engine/subscriptions/constants/on-db-event-trigger';
@Injectable()
export class SubscriptionsService {
@@ -21,7 +22,7 @@ export class SubscriptionsService {
event: eventData,
});
- await this.pubSub.publish('onDbEvent', {
+ await this.pubSub.publish(ON_DB_EVENT_TRIGGER, {
onDbEvent: {
action: operation,
objectNameSingular: nameSingular,
diff --git a/yarn.lock b/yarn.lock
index 67c727aaf1b..bfd8b00e46f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -56111,6 +56111,7 @@ __metadata:
dotenv: "npm:^16.4.0"
fs-extra: "npm:^11.2.0"
graphql: "npm:^16.8.1"
+ graphql-sse: "npm:^2.5.4"
inquirer: "npm:^10.0.0"
jest: "npm:^29.5.0"
jsonc-parser: "npm:^3.2.0"