|
1 | 1 | /* eslint-disable no-param-reassign */
|
2 | 2 | import { render as mailyRender, JSONContent as MailyJSONContent } from '@maily-to/render';
|
3 | 3 | import { Injectable } from '@nestjs/common';
|
4 |
| -import { Liquid } from 'liquidjs'; |
5 | 4 | import { EmailRenderOutput } from '@novu/shared';
|
6 | 5 | import { InstrumentUsecase } from '@novu/application-generic';
|
| 6 | + |
7 | 7 | import { FullPayloadForRender, RenderCommand } from './render-command';
|
8 | 8 | import { WrapMailyInLiquidUseCase } from './maily-to-liquid/wrap-maily-in-liquid.usecase';
|
9 |
| -import { MAILY_ITERABLE_MARK, MailyAttrsEnum, MailyContentTypeEnum } from './maily-to-liquid/maily.types'; |
| 9 | +import { MAILY_ITERABLE_MARK, MailyAttrsEnum } from './maily-to-liquid/maily.types'; |
10 | 10 | import { parseLiquid } from '../../../shared/helpers/liquid';
|
| 11 | +import { hasShow, isRepeatNode, isVariableNode } from './maily-to-liquid/maily-utils'; |
11 | 12 |
|
12 | 13 | export class EmailOutputRendererCommand extends RenderCommand {}
|
13 | 14 |
|
@@ -88,15 +89,15 @@ export class EmailOutputRendererUsecase {
|
88 | 89 | while (queue.length > 0) {
|
89 | 90 | const current = queue.shift()!;
|
90 | 91 |
|
91 |
| - if (this.hasShow(current.node)) { |
| 92 | + if (hasShow(current.node)) { |
92 | 93 | await this.handleShowNode(current.node, variables, current.parent);
|
93 | 94 | }
|
94 | 95 |
|
95 |
| - if (this.isForNode(current.node)) { |
| 96 | + if (isRepeatNode(current.node)) { |
96 | 97 | await this.handleEachNode(current.node, variables, current.parent);
|
97 | 98 | }
|
98 | 99 |
|
99 |
| - if (this.isVariableNode(current.node)) { |
| 100 | + if (isVariableNode(current.node)) { |
100 | 101 | this.processVariableNodeTypes(current.node);
|
101 | 102 | }
|
102 | 103 |
|
@@ -156,23 +157,6 @@ export class EmailOutputRendererUsecase {
|
156 | 157 | node.text = node.attrs?.id || '';
|
157 | 158 | }
|
158 | 159 |
|
159 |
| - private isForNode( |
160 |
| - node: MailyJSONContent |
161 |
| - ): node is MailyJSONContent & { attrs: { [MailyAttrsEnum.EACH_KEY]: string } } { |
162 |
| - return !!( |
163 |
| - node.type === MailyContentTypeEnum.FOR && |
164 |
| - node.attrs && |
165 |
| - node.attrs[MailyAttrsEnum.EACH_KEY] !== undefined && |
166 |
| - typeof node.attrs[MailyAttrsEnum.EACH_KEY] === 'string' |
167 |
| - ); |
168 |
| - } |
169 |
| - |
170 |
| - private hasShow( |
171 |
| - node: MailyJSONContent |
172 |
| - ): node is MailyJSONContent & { attrs: { [MailyAttrsEnum.SHOW_IF_KEY]: string } } { |
173 |
| - return node.attrs?.[MailyAttrsEnum.SHOW_IF_KEY] !== undefined && node.attrs?.[MailyAttrsEnum.SHOW_IF_KEY] !== null; |
174 |
| - } |
175 |
| - |
176 | 160 | /**
|
177 | 161 | * For 'each' node, multiply the content by the number of items in the iterable array
|
178 | 162 | * and add indexes to the placeholders.
|
@@ -229,7 +213,7 @@ export class EmailOutputRendererUsecase {
|
229 | 213 | return nodes.map((node) => {
|
230 | 214 | const processedNode = { ...node };
|
231 | 215 |
|
232 |
| - if (this.isVariableNode(processedNode)) { |
| 216 | + if (isVariableNode(processedNode)) { |
233 | 217 | this.processVariableNodeTypes(processedNode);
|
234 | 218 |
|
235 | 219 | if (processedNode.text) {
|
@@ -257,15 +241,4 @@ export class EmailOutputRendererUsecase {
|
257 | 241 | return Boolean(normalized);
|
258 | 242 | }
|
259 | 243 | }
|
260 |
| - |
261 |
| - private isVariableNode( |
262 |
| - node: MailyJSONContent |
263 |
| - ): node is MailyJSONContent & { attrs: { [MailyAttrsEnum.ID]: string } } { |
264 |
| - return !!( |
265 |
| - node.type === MailyContentTypeEnum.VARIABLE && |
266 |
| - node.attrs && |
267 |
| - node.attrs[MailyAttrsEnum.ID] !== undefined && |
268 |
| - typeof node.attrs[MailyAttrsEnum.ID] === 'string' |
269 |
| - ); |
270 |
| - } |
271 | 244 | }
|
0 commit comments