MCPcopy
hub / github.com/dittofeed/dittofeed / contentController

Function contentController

packages/api/src/controllers/contentController.ts:62–654  ·  view source on GitHub ↗
(fastify: FastifyInstance)

Source from the content-addressed store, hash-verified

60
61// eslint-disable-next-line @typescript-eslint/require-await
62export default async function contentController(fastify: FastifyInstance) {
63 fastify.withTypeProvider<TypeBoxTypeProvider>().post(
64 "/templates/render",
65 {
66 schema: {
67 description: "Render message template.",
68 tags: ["Content"],
69 body: RenderMessageTemplateRequest,
70 response: {
71 200: RenderMessageTemplateResponse,
72 500: BaseMessageResponse,
73 },
74 },
75 },
76 async (request, reply) => {
77 const {
78 contents,
79 workspaceId,
80 subscriptionGroupId,
81 channel,
82 userProperties,
83 tags,
84 } = request.body;
85 const tagsWithMessageId: MessageTags = {
86 ...(tags ?? {}),
87 messageId: tags?.messageId ?? randomUUID(),
88 };
89
90 const secretNames = [SecretNames.Subscription];
91 if (channel === ChannelType.Webhook) {
92 secretNames.push(SecretNames.Webhook);
93 }
94
95 const secrets = (
96 await db().query.secret.findMany({
97 where: and(
98 eq(schema.secret.workspaceId, workspaceId),
99 inArray(schema.secret.name, secretNames),
100 ),
101 })
102 ).reduce((acc, secret) => {
103 acc.set(secret.name, secret);
104 return acc;
105 }, new Map<string, Secret>());
106
107 const templateSecrets: Record<string, string> = {};
108 const subscriptionSecret = secrets.get(SecretNames.Subscription)?.value;
109 if (subscriptionSecret) {
110 templateSecrets[SecretNames.Subscription] = subscriptionSecret;
111 }
112 const webhookSecret = secrets.get(SecretNames.Webhook)?.configValue;
113 if (webhookSecret) {
114 const validated = schemaValidateWithErr(webhookSecret, WebhookSecret);
115 if (validated.isErr()) {
116 return reply.status(500).send({
117 message: "Invalid webhook secret configuration",
118 });
119 }

Callers

nothing calls this directly

Calls 15

dbFunction · 0.90
schemaValidateWithErrFunction · 0.90
toMjmlFunction · 0.90
renderLiquidFunction · 0.90
unwrapFunction · 0.90
enrichMessageTemplateFunction · 0.90
upsertMessageTemplateFunction · 0.90
defaultEmailDefinitionFunction · 0.90
defaultSmsDefinitionFunction · 0.90
testTemplateFunction · 0.90
assertUnreachableFunction · 0.90
deleteMessageTemplateFunction · 0.90

Tested by

no test coverage detected