Fix env not optional + serverless logging (#15186)

Several fixes after discussing with @BOHEUS 
- set applicationManifest env key optional
- fix server local serverless function logging (introduces a new env
variable `SERVERLESS_LOGS_ENABLED` defaulting to false)
This commit is contained in:
martmull
2025-10-20 15:06:26 +02:00
committed by GitHub
parent 3d7f332f80
commit 11564f135e
11 changed files with 145 additions and 91 deletions
@@ -1,8 +1,4 @@
import {
ForbiddenException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
@@ -16,11 +12,11 @@ import {
} from 'src/engine/metadata-modules/route-trigger/route-trigger.entity';
import { AccessTokenService } from 'src/engine/core-modules/auth/token/services/access-token.service';
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
import {
AuthException,
AuthExceptionCode,
} from 'src/engine/core-modules/auth/auth.exception';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
import {
RouteTriggerException,
RouteTriggerExceptionCode,
} from 'src/engine/metadata-modules/route-trigger/exceptions/route-trigger.exception';
@Injectable()
export class RouteTriggerService {
@@ -51,9 +47,9 @@ export class RouteTriggerService {
assertIsDefinedOrThrow(
workspace,
new AuthException(
new RouteTriggerException(
'Workspace not found',
AuthExceptionCode.WORKSPACE_NOT_FOUND,
RouteTriggerExceptionCode.WORKSPACE_NOT_FOUND,
),
);
@@ -81,7 +77,10 @@ export class RouteTriggerService {
}
}
throw new NotFoundException('No Route trigger found');
throw new RouteTriggerException(
'No Route trigger found',
RouteTriggerExceptionCode.TRIGGER_NOT_FOUND,
);
}
private async validateWorkspaceFromRequest({
@@ -95,11 +94,17 @@ export class RouteTriggerService {
await this.accessTokenService.validateTokenByRequest(request);
if (!isDefined(workspace)) {
throw new NotFoundException('Workspace not found');
throw new RouteTriggerException(
'Workspace not found',
RouteTriggerExceptionCode.WORKSPACE_NOT_FOUND,
);
}
if (workspace.id !== workspaceId) {
throw new ForbiddenException('Invalid Workspace');
throw new RouteTriggerException(
'You are not authorized',
RouteTriggerExceptionCode.FORBIDDEN_EXCEPTION,
);
}
}
@@ -133,11 +138,25 @@ export class RouteTriggerService {
...routeTriggerWithPathParams.pathParams,
};
return await this.serverlessFunctionService.executeOneServerlessFunction(
routeTriggerWithPathParams.routeTrigger.serverlessFunction.id,
routeTriggerWithPathParams.routeTrigger.workspaceId,
executionParams,
'draft',
);
const result =
await this.serverlessFunctionService.executeOneServerlessFunction(
routeTriggerWithPathParams.routeTrigger.serverlessFunction.id,
routeTriggerWithPathParams.routeTrigger.workspaceId,
executionParams,
'draft',
);
if (!isDefined(result)) {
return result;
}
if (result.error) {
throw new RouteTriggerException(
result.error.errorMessage,
RouteTriggerExceptionCode.SERVERLESS_FUNCTION_EXECUTION_ERROR,
);
}
return result.data;
}
}