
* 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
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import prisma from "@calcom/prisma";
|
|
import { App } from "@calcom/types/App";
|
|
|
|
export async function getAppWithMetadata(app: { dirName: string }) {
|
|
let appMetadata: App | null = null;
|
|
try {
|
|
appMetadata = (await import(`./${app.dirName}/_metadata`)).default as App;
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
console.error(`No metadata found for: "${app.dirName}". Message:`, error.message);
|
|
}
|
|
return null;
|
|
}
|
|
if (!appMetadata) return null;
|
|
// Let's not leak api keys to the front end
|
|
const { key, ...metadata } = appMetadata;
|
|
return metadata;
|
|
}
|
|
|
|
/** Mainly to use in listings for the frontend, use in getStaticProps or getServerSideProps */
|
|
export async function getAppRegistry() {
|
|
const dbApps = await prisma.app.findMany({ select: { dirName: true, slug: true, categories: true } });
|
|
const apps = [] as Omit<App, "key">[];
|
|
for await (const dbapp of dbApps) {
|
|
const app = await getAppWithMetadata(dbapp);
|
|
if (!app) continue;
|
|
// Skip if app isn't installed
|
|
/* This is now handled from the DB */
|
|
// if (!app.installed) return apps;
|
|
apps.push(app);
|
|
}
|
|
return apps;
|
|
}
|