-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): preview usecase #7330
Changes from 17 commits
0a89674
5e6754e
7b898d7
13806f1
02ba6e0
35e341b
4c8b0e3
472f610
8ad7d1c
ef47067
48f5434
660ac49
266a5ef
7a5899c
57c531d
2bdf193
6513589
e6a1720
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common'; | |
import { render as mailyRender } from '@maily-to/render'; | ||
import { Instrument, InstrumentUsecase } from '@novu/application-generic'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
import { Liquid } from 'liquidjs'; | ||
import { FullPayloadForRender, RenderCommand } from './render-command'; | ||
import { ExpandEmailEditorSchemaUsecase } from './expand-email-editor-schema.usecase'; | ||
import { emailStepControlZodSchema } from '../../../workflows-v2/shared'; | ||
|
@@ -21,10 +22,26 @@ export class RenderEmailOutputUsecase { | |
return { subject, body: '' }; | ||
} | ||
|
||
const expandedSchema = this.transformForAndShowLogic(body, renderCommand.fullPayloadForRender); | ||
const htmlRendered = await this.renderEmail(expandedSchema); | ||
const expandedMailyContent = this.transformForAndShowLogic(body, renderCommand.fullPayloadForRender); | ||
const parsedTipTap = await this.parseTipTapNodeByLiquid(expandedMailyContent, renderCommand); | ||
const renderedHtml = await this.renderEmail(parsedTipTap); | ||
|
||
return { subject, body: htmlRendered }; | ||
return { subject, body: renderedHtml }; | ||
} | ||
|
||
private async parseTipTapNodeByLiquid( | ||
value: TipTapNode, | ||
renderCommand: RenderEmailOutputCommand | ||
): Promise<TipTapNode> { | ||
const client = new Liquid(); | ||
const templateString = client.parse(JSON.stringify(value)); | ||
const parsedTipTap = await client.render(templateString, { | ||
payload: renderCommand.fullPayloadForRender.payload, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we can, but this refactor is focused on doing the minimum needed to make the code work with what we currently have. We'll try to avoid major changes as much as possible. The goal is to ensure the use cases—like sending a simple email, "show" component, then "for" components—work as expected with minimal refactoring. If that's not possible, we'll consider a bigger refactor. Once we have a working solution, we can refactor further if needed. One potential improvement could be flattening the data as you suggested. |
||
subscriber: renderCommand.fullPayloadForRender.subscriber, | ||
steps: renderCommand.fullPayloadForRender.steps, | ||
}); | ||
|
||
return JSON.parse(parsedTipTap); | ||
} | ||
|
||
@Instrument() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving all the variable calculations from start to end into the
buildLiquidJSVariable
function defined once either on the class or as a single util. That is combine line 122 and 133.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add an extra step of sanitization in the above function that caters for weird cases where the
variableName
ends with|
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, this transformation should happena cross all steps, not just email.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you refer to the
show
resolver, i totally agree, this was postponed until we have full show support.I love the idea but i believe we can postpone such sanitization because liquid js does not care about filter suffixes.

can you elaborate please what do you mean by this transformation