Skip to content

Commit

Permalink
fix(api-service): Add marks to tiptap zod schema (#7339)
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg authored Dec 23, 2024
1 parent c4c0b78 commit 569f827
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class HydrateEmailSchemaUseCase {
nestedForPlaceholders: {},
regularPlaceholdersToDefaultValue: {},
};
const emailEditorSchema: TipTapNode = TipTapSchema.parse(JSON.parse(command.emailEditor));

// TODO: Aligned Zod inferred type and TipTapNode to remove the need of a type assertion
const emailEditorSchema: TipTapNode = TipTapSchema.parse(JSON.parse(command.emailEditor)) as TipTapNode;
if (emailEditorSchema.content) {
this.transformContentInPlace(emailEditorSchema.content, command.fullPayloadForRender, placeholderAggregation);
}
Expand Down Expand Up @@ -226,12 +228,24 @@ export class HydrateEmailSchemaUseCase {
}
}

export const TipTapSchema = z.object({
type: z.string().optional(),
content: z.array(z.lazy(() => TipTapSchema)).optional(),
text: z.string().optional(),
attrs: z.record(z.unknown()).optional(),
});
export const TipTapSchema = z
.object({
type: z.string().optional(),
content: z.array(z.lazy(() => TipTapSchema)).optional(),
text: z.string().optional(),
marks: z
.array(
z
.object({
type: z.string(),
attrs: z.record(z.any()).optional(),
})
.passthrough()
)
.optional(),
attrs: z.record(z.unknown()).optional(),
})
.passthrough();

const buildLiquidJSDefault = (variableName: string, fallback?: string) =>
`{{ ${variableName}${fallback ? ` | default: '${fallback}'` : ''} }}`;

0 comments on commit 569f827

Please sign in to comment.