2
0

first commit

This commit is contained in:
2024-08-09 00:39:27 +02:00
commit 79688abe2e
5698 changed files with 497838 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import type { TaskHandler, TaskTypes } from "../tasker";
/**
* This is a map of all the tasks that the Tasker can handle.
* The keys are the TaskTypes and the values are the task handlers.
* The task handlers are imported dynamically to avoid circular dependencies.
*/
const tasks: Record<TaskTypes, () => Promise<TaskHandler>> = {
sendEmail: () => import("./sendEmail").then((module) => module.sendEmail),
sendWebhook: () => import("./sendWebook").then((module) => module.sendWebhook),
sendSms: () => Promise.resolve(() => Promise.reject(new Error("Not implemented"))),
};
export default tasks;

View File

@@ -0,0 +1,25 @@
import { z } from "zod";
const sendEmailPayloadSchema = z.object({
/** */
to: z.string(),
/** The email template to send */
template: z.string(),
payload: z.string(),
});
export async function sendEmail(payload: string): Promise<void> {
try {
const parsedPayload = sendEmailPayloadSchema.parse(JSON.parse(payload));
console.log(parsedPayload);
const emails = await import("@calcom/emails");
const email = emails[parsedPayload.template as keyof typeof emails];
if (!email) throw new Error("Invalid email template");
// @ts-expect-error - TODO bring back email type safety
await email(parsedPayload.to);
} catch (error) {
// ... handle error
console.error(error);
throw error;
}
}

View File

@@ -0,0 +1,29 @@
import { z } from "zod";
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
const sendWebhookPayloadSchema = z.object({
secretKey: z.string().nullable(),
triggerEvent: z.string(),
createdAt: z.string(),
webhook: z.object({
subscriberUrl: z.string().url(),
appId: z.string().nullable(),
payloadTemplate: z.string().nullable(),
}),
// TODO: Define the data schema
data: z.any(),
});
export async function sendWebhook(payload: string): Promise<void> {
try {
const { secretKey, triggerEvent, createdAt, webhook, data } = sendWebhookPayloadSchema.parse(
JSON.parse(payload)
);
await sendPayload(secretKey, triggerEvent, createdAt, webhook, data);
} catch (error) {
// ... handle error
console.error(error);
throw error;
}
}