* Abstract app category navigation * Send key schema to frontend Co-authored-by: Omar López <zomars@users.noreply.github.com> * Render keys for apps on admin * Add enabled col for apps * Save app keys to DB * Add checks for admin role * Abstract setup components * Add AdminAppsList to setup wizard * Migrate to v10 tRPC * Default hide keys * Display enabled apps * Merge branch 'main' into admin-apps-ui * Toggle calendars * WIP * Add params and include AppCategoryNavigation * Refactor getEnabledApps * Add warning for disabling apps * Fallback to cal video when a video app is disabled * WIP send disabled email * Send email to all users of event types with payment app * Disable Stripe when app is disabled * Disable apps in event types * Send email to users on disabled apps * Send email based on what app was disabled * WIP type fix * Disable navigation to apps list if already setup * UI import fixes * Waits for session data before redirecting * Updates admin seeded password To comply with admin password requirements * Update yarn.lock * Flex fixes * Adds admin middleware * Clean up * WIP * WIP * NTS * Add dirName to app metadata * Upsert app if not in db * Upsert app if not in db * Add dirName to app metadata * Add keys to app packages w/ keys * Merge with main * Toggle show keys & on enable * Fix empty keys * Fix lark calendar metadata * Fix some type errors * Fix Lark metadata & check for category when upserting * More type fixes * Fix types & add keys to google cal * WIP * WIP * WIP * More type fixes * Fix type errors * Fix type errors * More type fixes * More type fixes * More type fixes * Feedback * Fixes default value * Feedback * Migrate credential invalid col default value "false" * Upsert app on saving keys * Clean up * Validate app keys on frontend * Add nonempty to app keys schemas * Add web3 * Listlocale filter on categories / category * Grab app metadata via category or categories * Show empty screen if no apps are enabled * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Replace .nonempty() w/ .min(1) * Fix type error * Address feedback * Draft Google Meet install button * Add install button and warning dialog * WIP * WIP * Display warning when Meet is selected * Display Google Meet warning on email to organizer * Fix email * Fix type errors * Fix type error * Add connected account component * Add warning message * Address comments * Address feedback * Clean up & add MeetLocationType * Use useApp hook * Translate to new API approach * Remove console.log * Refactor * Fix missing backup Cal video link * WIP * Address feedback * Update submodules * Feedback * Submodule sync Co-authored-by: Omar López <zomars@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <peer@cal.com>
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from "next";
|
|
import type { Session } from "next-auth";
|
|
|
|
import getInstalledAppPath from "@calcom/app-store/_utils/getInstalledAppPath";
|
|
import { getSession } from "@calcom/lib/auth";
|
|
import { deriveAppDictKeyFromType } from "@calcom/lib/deriveAppDictKeyFromType";
|
|
import prisma from "@calcom/prisma";
|
|
import type { AppDeclarativeHandler, AppHandler } from "@calcom/types/AppHandler";
|
|
|
|
import { HttpError } from "@lib/core/http/error";
|
|
|
|
const defaultIntegrationAddHandler = async ({
|
|
slug,
|
|
supportsMultipleInstalls,
|
|
appType,
|
|
user,
|
|
createCredential,
|
|
}: {
|
|
slug: string;
|
|
supportsMultipleInstalls: boolean;
|
|
appType: string;
|
|
user?: Session["user"];
|
|
createCredential: AppDeclarativeHandler["createCredential"];
|
|
}) => {
|
|
if (!user?.id) {
|
|
throw new HttpError({ statusCode: 401, message: "You must be logged in to do this" });
|
|
}
|
|
if (!supportsMultipleInstalls) {
|
|
const alreadyInstalled = await prisma.credential.findFirst({
|
|
where: {
|
|
appId: slug,
|
|
userId: user.id,
|
|
},
|
|
});
|
|
if (alreadyInstalled) {
|
|
throw new Error("App is already installed");
|
|
}
|
|
}
|
|
await createCredential({ user: user, appType, slug });
|
|
};
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
// Check that user is authenticated
|
|
req.session = await getSession({ req });
|
|
|
|
const { args } = req.query;
|
|
|
|
if (!Array.isArray(args)) {
|
|
return res.status(404).json({ message: `API route not found` });
|
|
}
|
|
|
|
const [appName, apiEndpoint] = args;
|
|
try {
|
|
/* Absolute path didn't work */
|
|
const handlerMap = (await import("@calcom/app-store/apps.server.generated")).apiHandlers;
|
|
|
|
const handlerKey = deriveAppDictKeyFromType(appName, handlerMap);
|
|
const handlers = await handlerMap[handlerKey as keyof typeof handlerMap];
|
|
const handler = handlers[apiEndpoint as keyof typeof handlers] as AppHandler;
|
|
let redirectUrl = "/apps/installed";
|
|
if (typeof handler === "undefined")
|
|
throw new HttpError({ statusCode: 404, message: `API handler not found` });
|
|
|
|
if (typeof handler === "function") {
|
|
await handler(req, res);
|
|
} else {
|
|
await defaultIntegrationAddHandler({ user: req.session?.user, ...handler });
|
|
redirectUrl = handler.redirect?.url || getInstalledAppPath(handler);
|
|
res.json({ url: redirectUrl, newTab: handler.redirect?.newTab });
|
|
}
|
|
return res.status(200);
|
|
} catch (error) {
|
|
console.error(error);
|
|
|
|
if (error instanceof HttpError) {
|
|
return res.status(error.statusCode).json({ message: error.message });
|
|
}
|
|
if (error instanceof Error) {
|
|
return res.status(400).json({ message: error.message });
|
|
}
|
|
return res.status(404).json({ message: `API handler not found` });
|
|
}
|
|
};
|
|
|
|
export default handler;
|