Fixes/app store keys in db (#2651)

* Adds available apps

* Adds App Model

* WIP

* Updates seeder script

* Seeder fixes

* lowercase categories

* Upgrades prisma

* WIP

* WIP

* Hopefully fixes circular deps

* Type fixes

* Fixes seeder

* Adds migration to connect Credentials to Apps

* Updates app store callbacks

* Updates google credentials

* Uses dirName from DB

* Type fixes

* Update reschedule.ts

* Seeder fixes

* Fixes categories listing

* Update index.ts

* Update schema.prisma

* Updates dependencies

* Renames giphy app

* Uses dynamic imports for app metadata

* Fixes credentials error

* Uses dynamic import for api handlers

* Dynamic import fixes

* Allows for simple folder names in app store

* Squashes app migrations

* seeder fixes

* Fixes dyamic imports

* Update apiHandlers.tsx
This commit is contained in:
Omar López authored and GitHub committed 2022-05-02 14:39:35 -06:00
1 parent 21867c9cd4
commit 6a27fb2959
68 files changed
+995 -1628

No files matched your search

+4 -9
View File
@@ -1,7 +1,5 @@
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import appStore from "@calcom/app-store";
import { getSession } from "@lib/auth";
import { HttpError } from "@lib/core/http/error";
@@ -19,13 +17,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const appName = _appName.split("_").join(""); // Transform `zoom_video` to `zoomvideo`;
try {
// TODO: Find a way to dynamically import these modules
// const app = (await import(`@calcom/${appName}`)).default;
const app = appStore[appName as keyof typeof appStore];
if (!(app && "api" in app && apiEndpoint in app.api))
throw new HttpError({ statusCode: 404, message: `API handler not found` });
const handler = app.api[apiEndpoint as keyof typeof app.api] as NextApiHandler;
/* Absolute path didn't work */
const handlerMap = (await import("@calcom/app-store/apiHandlers")).default;
const handlers = await handlerMap[appName as keyof typeof handlerMap];
const handler = handlers[apiEndpoint as keyof typeof handlers] as NextApiHandler;
if (typeof handler !== "function")
throw new HttpError({ statusCode: 404, message: `API handler not found` });