diff --git a/services/workflows-service/prisma/migrations/20241009122132_removed_unused_schema/migration.sql b/services/workflows-service/prisma/migrations/20241009122132_removed_unused_schema/migration.sql new file mode 100644 index 0000000000..b7b04b8926 --- /dev/null +++ b/services/workflows-service/prisma/migrations/20241009122132_removed_unused_schema/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the column `backend` on the `WorkflowDefinition` table. All the data in the column will be lost. + - You are about to drop the column `supportedPlatforms` on the `WorkflowDefinition` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "WorkflowDefinition" DROP COLUMN "backend", +DROP COLUMN "supportedPlatforms"; diff --git a/services/workflows-service/prisma/schema.prisma b/services/workflows-service/prisma/schema.prisma index fea1f16525..53bc867618 100644 --- a/services/workflows-service/prisma/schema.prisma +++ b/services/workflows-service/prisma/schema.prisma @@ -180,11 +180,9 @@ model WorkflowDefinition { contextSchema Json? documentsSchema Json? config Json? - supportedPlatforms Json? extensions Json? variant String @default("DEFAULT") - backend Json? persistStates Json? submitStates Json? diff --git a/services/workflows-service/src/filter/dtos/temp-zod-schemas.ts b/services/workflows-service/src/filter/dtos/temp-zod-schemas.ts index b052e1fd02..5182740df7 100644 --- a/services/workflows-service/src/filter/dtos/temp-zod-schemas.ts +++ b/services/workflows-service/src/filter/dtos/temp-zod-schemas.ts @@ -215,9 +215,7 @@ export const WorkflowDefinitionWhereInput = z.lazy(() => version: z.union([IntFilterSchema, z.number()]).optional(), definitionType: zStringFilterStringUnion.optional(), definition: z.unknown().optional(), - supportedPlatforms: z.unknown().optional(), extensions: z.unknown().optional(), - backend: z.unknown().optional(), persistStates: z.unknown().optional(), submitStates: z.unknown().optional(), createdAt: zDateTimeFilterDateStringUnion.optional(), @@ -235,9 +233,7 @@ export const WorkflowDefinitionWhereInputSchema = z.object({ version: IntFilterSchema.optional(), definitionType: zStringFilterStringUnion.optional(), definition: z.unknown().optional(), - supportedPlatforms: z.unknown().optional(), extensions: z.unknown().optional(), - backend: z.unknown().optional(), persistStates: z.unknown().optional(), submitStates: z.unknown().optional(), createdAt: zDateTimeFilterDateStringUnion.optional(), @@ -288,9 +284,7 @@ export const WorkflowDefinitionSelectSchema = z.object({ version: z.boolean().optional(), definitionType: z.boolean().optional(), definition: z.boolean().optional(), - supportedPlatforms: z.boolean().optional(), extensions: z.boolean().optional(), - backend: z.boolean().optional(), persistStates: z.boolean().optional(), submitStates: z.boolean().optional(), createdAt: z.boolean().optional(), diff --git a/services/workflows-service/src/workflow/dtos/workflow-definition-create.ts b/services/workflows-service/src/workflow/dtos/workflow-definition-create.ts index 19cb0389c0..33a5ada84b 100644 --- a/services/workflows-service/src/workflow/dtos/workflow-definition-create.ts +++ b/services/workflows-service/src/workflow/dtos/workflow-definition-create.ts @@ -73,11 +73,6 @@ export class WorkflowDefinitionCreateDto { @IsObject() config?: Record | null; - @ApiProperty({ required: false, type: Array, nullable: true }) - @IsOptional() - @IsArray() - supportedPlatforms?: unknown[] | null; - @ApiProperty({ required: false, type: Object, nullable: true }) @IsOptional() @IsObject() @@ -88,11 +83,6 @@ export class WorkflowDefinitionCreateDto { @IsString() variant?: string; - @ApiProperty({ required: false, type: Object, nullable: true }) - @IsOptional() - @IsObject() - backend?: Record | null; - @ApiProperty({ required: false, type: Array, nullable: true }) @IsOptional() @IsArray() diff --git a/services/workflows-service/src/workflow/workflow-definition.model.ts b/services/workflows-service/src/workflow/workflow-definition.model.ts index 08f50bb814..05ed57e052 100644 --- a/services/workflows-service/src/workflow/workflow-definition.model.ts +++ b/services/workflows-service/src/workflow/workflow-definition.model.ts @@ -1,15 +1,14 @@ -import { UserModel } from '@/user/user.model'; import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; import { IsArray, + IsBoolean, IsDate, IsNotEmptyObject, IsNumber, IsObject, IsOptional, IsString, - ValidateNested, } from 'class-validator'; import type { JsonValue } from 'type-fest'; @@ -17,13 +16,35 @@ export class WorkflowDefinitionModel { @IsString() id!: string; - @ApiProperty({ - required: true, - type: () => UserModel, - }) - @ValidateNested() - @Type(() => UserModel) - user?: UserModel; + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + crossEnvKey?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + projectId?: string; + + @ApiProperty({ required: false, type: Boolean }) + @IsOptional() + @IsBoolean() + isPublic?: boolean; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + displayName?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + reviewMachineId?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + variant?: string; @ApiProperty({ required: true, @@ -67,7 +88,7 @@ export class WorkflowDefinitionModel { }) @IsObject() @IsOptional() - context?: JsonValue; + contextSchema?: JsonValue; @ApiProperty({ required: false, @@ -75,15 +96,15 @@ export class WorkflowDefinitionModel { }) @IsObject() @IsOptional() - config?: JsonValue; + documentsSchema?: JsonValue; @ApiProperty({ required: false, type: 'object', }) - @IsNotEmptyObject() + @IsObject() @IsOptional() - extensions?: JsonValue; + config?: JsonValue; @ApiProperty({ required: false, @@ -91,7 +112,7 @@ export class WorkflowDefinitionModel { }) @IsNotEmptyObject() @IsOptional() - backend?: JsonValue; + extensions?: JsonValue; @ApiProperty({ required: false, @@ -113,6 +134,11 @@ export class WorkflowDefinitionModel { @Type(() => Date) createdAt!: Date; + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + createdBy?: string; + @IsDate() @Type(() => Date) updatedAt!: Date; diff --git a/services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts b/services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts index c7ae76dcd1..1340b32625 100644 --- a/services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts +++ b/services/workflows-service/src/workflow/workflow-runtime-list-item.model.ts @@ -2,7 +2,16 @@ import { IsNullable } from '@/common/decorators/is-nullable.decorator'; import { ApiProperty } from '@nestjs/swagger'; import { WorkflowRuntimeDataStatus } from '@prisma/client'; import { Expose } from 'class-transformer'; -import { IsDate, IsJSON, IsNotEmptyObject, IsString, ValidateNested } from 'class-validator'; +import { + IsArray, + IsDate, + IsJSON, + IsNotEmptyObject, + IsNumber, + IsOptional, + IsString, + ValidateNested, +} from 'class-validator'; export class WorkflowAssignee { @Expose() @@ -22,6 +31,55 @@ export class WorkflowRuntimeListItemModel { @IsString() id!: string; + @Expose() + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + projectId?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsNullable() + @IsString() + salesforceObjectName?: string | null; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsNullable() + @IsString() + salesforceRecordId?: string | null; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsNullable() + @IsString() + parentRuntimeDataId?: string | null; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + endUserId?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + businessId?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + assigneeId?: string; + + @ApiProperty({ required: false, type: String }) + @IsOptional() + @IsString() + uiDefinitionId?: string; + + @ApiProperty({ required: false, type: Number }) + @IsOptional() + @IsNumber() + workflowDefinitionVersion?: number; + @Expose() @ApiProperty() @IsString() @@ -47,6 +105,11 @@ export class WorkflowRuntimeListItemModel { @IsJSON() context!: JSON; + @Expose() + @ApiProperty() + @IsJSON() + config!: JSON; + @Expose() @IsNullable() @IsString() @@ -54,8 +117,16 @@ export class WorkflowRuntimeListItemModel { @Expose() @IsNullable() + @IsOptional() + @IsArray() + @IsString({ each: true }) + tags?: string[] | null; + + @Expose() + @IsNullable() + @IsOptional() @ValidateNested() - assignee!: WorkflowAssignee | null; + assignee?: WorkflowAssignee | null; @Expose() @IsString() @@ -75,4 +146,9 @@ export class WorkflowRuntimeListItemModel { @ApiProperty() @IsDate() updatedAt!: Date; + + @ApiProperty() + @IsOptional() + @IsDate() + assignedAt?: Date; } diff --git a/services/workflows-service/src/workflow/workflow.controller.external.ts b/services/workflows-service/src/workflow/workflow.controller.external.ts index b721fdb4f0..e578e0a1ef 100644 --- a/services/workflows-service/src/workflow/workflow.controller.external.ts +++ b/services/workflows-service/src/workflow/workflow.controller.external.ts @@ -5,7 +5,7 @@ import * as common from '@nestjs/common'; import { HttpStatus, NotFoundException, Query, Res } from '@nestjs/common'; import * as swagger from '@nestjs/swagger'; import { ApiOkResponse, ApiResponse } from '@nestjs/swagger'; -import { WorkflowRuntimeData } from '@prisma/client'; +import type { WorkflowRuntimeData } from '@prisma/client'; // import * as nestAccessControl from 'nest-access-control'; import { WorkflowTokenService } from '@/auth/workflow-token/workflow-token.service'; import { putPluginsExampleResponse } from '@/workflow/workflow-controller-examples'; @@ -36,7 +36,6 @@ import { WorkflowDefinitionWhereUniqueInput, WorkflowDefinitionWhereUniqueInputSchema, } from './dtos/workflow-where-unique-input'; -import { RunnableWorkflowData } from './types'; import { WorkflowDefinitionModel } from './workflow-definition.model'; import { WorkflowService } from './workflow.service'; import { Validate } from 'ballerine-nestjs-typebox'; @@ -45,6 +44,7 @@ import { type Static, Type } from '@sinclair/typebox'; import { defaultContextSchema } from '@ballerine/common'; import { WorkflowRunSchema } from './schemas/workflow-run'; import { ValidationError } from '@/errors'; +import { WorkflowRuntimeListItemModel } from '@/workflow/workflow-runtime-list-item.model'; export const WORKFLOW_TAG = 'Workflows'; @swagger.ApiBearerAuth() @@ -181,14 +181,14 @@ export class WorkflowControllerExternal { } @common.Get('/:id') - @swagger.ApiOkResponse({ type: WorkflowDefinitionModel }) + @swagger.ApiOkResponse({ type: WorkflowRuntimeListItemModel }) @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) @swagger.ApiForbiddenResponse({ type: errors.ForbiddenException }) @UseCustomerAuthGuard() async getRunnableWorkflowDataById( @common.Param() params: WorkflowDefinitionWhereUniqueInput, @ProjectIds() projectIds: TProjectIds, - ): Promise { + ): Promise { const workflowRuntimeData = await this.service.getWorkflowRuntimeDataById( params.id, {}, @@ -199,16 +199,7 @@ export class WorkflowControllerExternal { throw new NotFoundException(`No resource with id [${params.id}] was found`); } - const workflowDefinition = await this.service.getWorkflowDefinitionById( - workflowRuntimeData.workflowDefinitionId, - {}, - projectIds, - ); - - return { - workflowDefinition, - workflowRuntimeData, - }; + return workflowRuntimeData; } // PATCH /workflows/:id diff --git a/services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts b/services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts index 329ae1a462..94cdbc7f85 100644 --- a/services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts +++ b/services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts @@ -1,10 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { CallHandler, ExecutionContext, HttpStatus, INestApplication } from '@nestjs/common'; +import { HttpStatus, INestApplication } from '@nestjs/common'; import request from 'supertest'; -// import { ACGuard } from 'nest-access-control'; import { ACLModule } from '@/common/access-control/acl.module'; -// import { AclFilterResponseInterceptor } from '@/common/access-control/interceptors/acl-filter-response.interceptor'; -// import { AclValidateRequestInterceptor } from '@/common/access-control/interceptors/acl-validate-request.interceptor'; import { WorkflowControllerExternal } from './workflow.controller.external'; import { WorkflowService } from './workflow.service'; import { EventEmitter2 } from '@nestjs/event-emitter'; @@ -16,24 +13,6 @@ import { WorkflowDefinitionService } from '@/workflow-defintion/workflow-definit import { AppLoggerService } from '@/common/app-logger/app-logger.service'; import { PrismaService } from '@/prisma/prisma.service'; import { WinstonLogger } from '@/common/utils/winston-logger/winston-logger'; -// import { AclFilterResponseInterceptor } from '@/common/access-control/interceptors/acl-filter-response.interceptor'; - -const acGuard = { - canActivate: () => { - return true; - }, -}; - -const aclFilterResponseInterceptor = { - intercept: (_context: ExecutionContext, next: CallHandler) => { - return next.handle(); - }, -}; -const aclValidateRequestInterceptor = { - intercept: (_context: ExecutionContext, next: CallHandler) => { - return next.handle(); - }, -}; describe('Workflow (external)', () => { let app: INestApplication; @@ -164,10 +143,7 @@ describe('Workflow (external)', () => { .get(`${'/external/workflows'}/abcde`) .set('authorization', 'Bearer secret') .expect(HttpStatus.OK) - .expect({ - workflowDefinition: { id: 'a' }, - workflowRuntimeData: { state: { id: 'b' } }, - }); + .expect({ state: { id: 'b' } }); }); afterAll(async () => { diff --git a/services/workflows-service/src/workflow/workflow.controller.internal.ts b/services/workflows-service/src/workflow/workflow.controller.internal.ts index 0ead1a5050..f94061bf22 100644 --- a/services/workflows-service/src/workflow/workflow.controller.internal.ts +++ b/services/workflows-service/src/workflow/workflow.controller.internal.ts @@ -379,7 +379,6 @@ export class WorkflowControllerInternal { definition: true, definitionType: true, - backend: true, extensions: true, persistStates: true, diff --git a/services/workflows-service/src/workflow/workflow.service.ts b/services/workflows-service/src/workflow/workflow.service.ts index 9246a1d183..1028e86d1b 100644 --- a/services/workflows-service/src/workflow/workflow.service.ts +++ b/services/workflows-service/src/workflow/workflow.service.ts @@ -153,7 +153,6 @@ export class WorkflowService { version: true, definition: true, definitionType: true, - backend: true, extensions: true, persistStates: true, submitStates: true, @@ -166,9 +165,7 @@ export class WorkflowService { contextSchema: data.contextSchema as InputJsonValue, documentsSchema: data.documentsSchema as InputJsonValue, config: data.config as InputJsonValue, - supportedPlatforms: data.supportedPlatforms as InputJsonValue, extensions: data.extensions as InputJsonValue, - backend: data.backend as InputJsonValue, persistStates: data.persistStates as InputJsonValue, submitStates: data.submitStates as InputJsonValue, }, @@ -193,9 +190,7 @@ export class WorkflowService { definition: true, contextSchema: true, config: true, - supportedPlatforms: true, extensions: true, - backend: true, persistStates: true, submitStates: true, }; @@ -705,7 +700,6 @@ export class WorkflowService { version: true, definition: true, definitionType: true, - backend: true, extensions: true, persistStates: true, submitStates: true,