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 { NextApiRequest } from "next";
import { defaultResponder } from "@calcom/lib/server";
import checkSession from "../../_utils/auth";
import { checkInstalled } from "../../_utils/installation";
export async function getHandler(req: NextApiRequest) {
const session = checkSession(req);
await checkInstalled("sendgrid", session.user?.id);
return { url: "/apps/sendgrid/setup" };
}
export default defaultResponder(getHandler);

View File

@@ -0,0 +1,45 @@
import type { NextApiRequest } from "next";
import { symmetricEncrypt } from "@calcom/lib/crypto";
import { HttpError } from "@calcom/lib/http-error";
import logger from "@calcom/lib/logger";
import { defaultResponder } from "@calcom/lib/server";
import prisma from "@calcom/prisma";
import checkSession from "../../_utils/auth";
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
export async function getHandler(req: NextApiRequest) {
const session = checkSession(req);
const { api_key } = req.body;
if (!api_key) throw new HttpError({ statusCode: 400, message: "No Api Key provided to check" });
let encrypted;
try {
encrypted = symmetricEncrypt(JSON.stringify({ api_key }), process.env.CALENDSO_ENCRYPTION_KEY || "");
} catch (reason) {
logger.error("Could not add Sendgrid app", reason);
throw new HttpError({ statusCode: 500, message: "Invalid length - CALENDSO_ENCRYPTION_KEY" });
}
const data = {
type: "sendgrid_other_calendar",
key: { encrypted },
userId: session.user?.id,
appId: "sendgrid",
};
try {
await prisma.credential.create({
data,
});
} catch (reason) {
logger.error("Could not add Sendgrid app", reason);
throw new HttpError({ statusCode: 500, message: "Could not add Sendgrid app" });
}
return { url: getInstalledAppPath({ variant: "other", slug: "sendgrid" }) };
}
export default defaultResponder(getHandler);

View File

@@ -0,0 +1,6 @@
import { defaultHandler } from "@calcom/lib/server";
export default defaultHandler({
GET: import("./_getAdd"),
POST: import("./_postAdd"),
});

View File

@@ -0,0 +1,31 @@
import type { NextApiRequest } from "next";
import Sendgrid from "@calcom/lib/Sendgrid";
import { HttpError } from "@calcom/lib/http-error";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
import checkSession from "../../_utils/auth";
export async function getHandler(req: NextApiRequest) {
const { api_key } = req.body;
if (!api_key) throw new HttpError({ statusCode: 400, message: "No Api Key provoided to check" });
checkSession(req);
const sendgrid: Sendgrid = new Sendgrid(api_key);
try {
const usernameInfo = await sendgrid.username();
if (usernameInfo.username) {
return {};
} else {
throw new HttpError({ statusCode: 404 });
}
} catch (e) {
throw new HttpError({ statusCode: 500, message: e as string });
}
}
export default defaultHandler({
POST: Promise.resolve({ default: defaultResponder(getHandler) }),
});

View File

@@ -0,0 +1,2 @@
export { default as add } from "./add";
export { default as check } from "./check";