-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Completed maily hydration and expension logic with e2e tes…
…ting
- Loading branch information
Showing
17 changed files
with
1,263 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 31 additions & 26 deletions
57
apps/api/src/app/environments-v1/usecases/output-renderers/email-output-renderer.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,49 @@ | ||
import { EmailRenderOutput, TipTapNode } from '@novu/shared'; | ||
import { render } from '@maily-to/render'; | ||
import { z } from 'zod'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { render } from '@maily-to/render'; | ||
import { RenderCommand } from './render-command'; | ||
import { MasterPayload } from '../construct-framework-workflow'; | ||
import { ExpandEmailEditorSchemaUsecase } from './email-schema-expander.usecase'; | ||
import { HydrateEmailSchemaUseCase } from './hydrate-email-schema.usecase'; | ||
|
||
export class EmailOutputRendererCommand extends RenderCommand { | ||
masterPayload: MasterPayload; | ||
} | ||
|
||
@Injectable() | ||
export class EmailOutputRendererUsecase { | ||
constructor(private expendEmailEditorSchemaUseCase: ExpandEmailEditorSchemaUsecase) {} | ||
constructor( | ||
private expendEmailEditorSchemaUseCase: ExpandEmailEditorSchemaUsecase, | ||
private hydrateEmailSchemaUseCase: HydrateEmailSchemaUseCase // Inject the new use case | ||
) {} | ||
|
||
async execute(renderCommand: RenderCommand): Promise<EmailRenderOutput> { | ||
const parse = EmailStepControlSchema.parse(renderCommand.controlValues); | ||
const schema = parse.emailEditor as TipTapNode; | ||
const expandedSchema = this.expendEmailEditorSchemaUseCase.execute({ schema }); | ||
const html = await render(expandedSchema); | ||
async execute(renderCommand: EmailOutputRendererCommand): Promise<EmailRenderOutput> { | ||
const { emailEditor, subject } = EmailStepControlSchema.parse(renderCommand.controlValues); | ||
const emailSchemaHydrated = this.hydrate(emailEditor, renderCommand); | ||
const expandedSchema = this.transformForAndShowLogic(emailSchemaHydrated); | ||
const htmlRendered = await render(expandedSchema); | ||
|
||
return { subject: parse.subject, body: html }; | ||
return { subject, body: htmlRendered }; | ||
} | ||
} | ||
const emailContentSchema = z | ||
.object({ | ||
type: z.string(), | ||
content: z.array(z.lazy(() => emailContentSchema)).optional(), | ||
text: z.string().optional(), | ||
attr: z.record(z.unknown()).optional(), | ||
}) | ||
.strict(); | ||
|
||
const emailEditorSchema = z | ||
.object({ | ||
type: z.string(), | ||
content: z.array(emailContentSchema).optional(), | ||
text: z.string().optional(), | ||
attr: z.record(z.unknown()).optional(), | ||
}) | ||
.strict(); | ||
private transformForAndShowLogic(body: TipTapNode) { | ||
return this.expendEmailEditorSchemaUseCase.execute({ schema: body }); | ||
} | ||
|
||
private hydrate(emailEditor: string, renderCommand: EmailOutputRendererCommand) { | ||
const { hydratedEmailSchema } = this.hydrateEmailSchemaUseCase.execute({ | ||
emailEditor, | ||
masterPayload: renderCommand.masterPayload, | ||
}); | ||
|
||
return hydratedEmailSchema; | ||
} | ||
} | ||
|
||
export const EmailStepControlSchema = z | ||
.object({ | ||
emailEditor: emailEditorSchema, | ||
emailEditor: z.string(), | ||
subject: z.string(), | ||
}) | ||
.strict(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/api/src/app/environments-v1/usecases/output-renderers/hydrate-email-schema.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// New HydrateEmailSchemaUseCase class | ||
import { MasterPayload } from '../construct-framework-workflow'; | ||
|
||
export class HydrateEmailSchemaCommand { | ||
emailEditor: string; | ||
masterPayload: MasterPayload; | ||
} |
Oops, something went wrong.