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

Submodule apps/api updated: 2449d90bcb...6124577bc2.
+2 -2
View File
@@ -11,15 +11,15 @@ import {
MoonIcon,
ViewGridIcon,
} from "@heroicons/react/solid";
import { UserPlan } from "@prisma/client";
import { SessionContextValue, signOut, useSession } from "next-auth/react";
import Link from "next/link";
import { useRouter } from "next/router";
import React, { Fragment, ReactNode, useEffect } from "react";
import toast, { Toaster } from "react-hot-toast";
import { Toaster } from "react-hot-toast";
import { useIsEmbed } from "@calcom/embed-core";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { UserPlan } from "@calcom/prisma/client";
import Button from "@calcom/ui/Button";
import Dropdown, {
DropdownMenuContent,
@@ -1,6 +1,6 @@
import { Attendee } from "@prisma/client";
import { TFunction } from "next-i18next";
import { Attendee } from "@calcom/prisma/client";
import { Person } from "@calcom/types/Calendar";
export const attendeeToPersonConversionType = (attendees: Attendee[], t: TFunction): Person[] => {
@@ -6,7 +6,6 @@ import utc from "dayjs/plugin/utc";
import { createEvent, DateArray, Person } from "ics";
import { getCancelLink } from "@calcom/lib/CalEventParser";
import { Attendee } from "@calcom/prisma/client";
import { CalendarEvent } from "@calcom/types/Calendar";
import {
+1 -3
View File
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client";
import { Prisma } from "@calcom/prisma/client";
import { Prisma, PrismaClient } from "@prisma/client";
async function getBooking(prisma: PrismaClient, uid: string) {
const booking = await prisma.booking.findFirst({
+1 -3
View File
@@ -1,6 +1,4 @@
import { useEffect } from "react";
import { UserPlan } from "@calcom/prisma/client";
import { UserPlan } from "@prisma/client";
/**
* TODO: It should be exposed at a single place.
+23 -1
View File
@@ -87,7 +87,7 @@ const nextConfig = {
];
},
async redirects() {
return [
const redirects = [
{
source: "/settings",
destination: "/settings/profile",
@@ -104,6 +104,28 @@ const nextConfig = {
permanent: false,
},
];
if (process.env.NEXT_PUBLIC_WEBAPP_URL === "https://app.cal.com") {
redirects.push(
{
source: "/apps/dailyvideo",
destination: "/apps/daily-video",
permanent: true,
},
{
source: "/apps/huddle01_video",
destination: "/apps/huddle01",
permanent: true,
},
{
source: "/apps/jitsi_video",
destination: "/apps/jitsi",
permanent: true,
}
);
}
return redirects;
},
};
+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` });
+14 -20
View File
@@ -1,13 +1,14 @@
import fs from "fs";
import matter from "gray-matter";
import { GetStaticPaths, GetStaticPathsResult, GetStaticPropsContext } from "next";
import { GetStaticPaths, GetStaticPropsContext } from "next";
import { MDXRemote } from "next-mdx-remote";
import { serialize } from "next-mdx-remote/serialize";
import Image from "next/image";
import Link from "next/link";
import path from "path";
import { getAppRegistry } from "@calcom/app-store/_appRegistry";
import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
import prisma from "@calcom/prisma";
import useMediaQuery from "@lib/hooks/useMediaQuery";
import { inferSSRProps } from "@lib/types/inferSSRProps";
@@ -68,11 +69,8 @@ function SingleAppPage({ data, source }: inferSSRProps<typeof getStaticProps>) {
}
export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
const appStore = getAppRegistry();
const paths = appStore.reduce((paths, app) => {
paths.push({ params: { slug: app.slug } });
return paths;
}, [] as GetStaticPathsResult<{ slug: string }>["paths"]);
const appStore = await prisma.app.findMany({ select: { slug: true } });
const paths = appStore.map(({ slug }) => ({ params: { slug } }));
return {
paths,
@@ -81,23 +79,19 @@ export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
};
export const getStaticProps = async (ctx: GetStaticPropsContext) => {
const appStore = getAppRegistry();
if (typeof ctx.params?.slug !== "string") return { notFound: true };
if (typeof ctx.params?.slug !== "string") {
return {
notFound: true,
};
}
const app = await prisma.app.findUnique({
where: { slug: ctx.params.slug },
});
const singleApp = appStore.find((app) => app.slug === ctx.params?.slug);
if (!app) return { notFound: true };
if (!singleApp) {
return {
notFound: true,
};
}
const singleApp = await getAppWithMetadata(app);
const appDirname = singleApp.type.replace("_", "");
if (!singleApp) return { notFound: true };
const appDirname = app.dirName;
const README_PATH = path.join(process.cwd(), "..", "..", `packages/app-store/${appDirname}/README.mdx`);
const postFilePath = path.join(README_PATH);
let source = "";
@@ -50,7 +50,7 @@ export default function Apps({ appStore }: InferGetStaticPropsType<typeof getSta
}
export const getStaticPaths = async () => {
const appStore = getAppRegistry();
const appStore = await getAppRegistry();
const paths = appStore.reduce((categories, app) => {
if (!categories.includes(app.category)) {
categories.push(app.category);
@@ -67,7 +67,7 @@ export const getStaticPaths = async () => {
export const getStaticProps = async () => {
return {
props: {
appStore: getAppRegistry(),
appStore: await getAppRegistry(),
},
};
};
+1 -1
View File
@@ -30,7 +30,7 @@ export default function Apps({ categories }: InferGetStaticPropsType<typeof getS
}
export const getStaticProps = async () => {
const appStore = getAppRegistry();
const appStore = await getAppRegistry();
const categories = appStore.reduce((c, app) => {
c[app.category] = c[app.category] ? c[app.category] + 1 : 1;
return c;
+1 -1
View File
@@ -24,7 +24,7 @@ export default function Apps({ appStore, categories }: InferGetStaticPropsType<t
}
export const getStaticProps = async () => {
const appStore = getAppRegistry();
const appStore = await getAppRegistry();
const categories = appStore.reduce((c, app) => {
c[app.category] = c[app.category] ? c[app.category] + 1 : 1;
return c;
+1 -21
View File
@@ -136,26 +136,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
};
})[0];
async function getBooking() {
return prisma.booking.findFirst({
where: {
uid: asStringOrThrow(context.query.rescheduleUid),
},
select: {
description: true,
attendees: {
select: {
email: true,
name: true,
},
},
},
});
}
type Booking = Prisma.PromiseReturnType<typeof getBooking>;
let booking: Booking | null = null;
const profile = {
name: user.name || user.username,
image: user.avatar,
@@ -173,7 +153,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
locationLabels: getLocationLabels(t),
profile,
eventType: eventTypeObject,
booking,
booking: null,
trpcState: ssr.dehydrate(),
isDynamicGroupBooking: false,
hasHashedBookingLink: true,
+2 -1
View File
@@ -29,7 +29,7 @@ import { FormattedNumber, IntlProvider } from "react-intl";
import { JSONObject } from "superjson/dist/types";
import { z } from "zod";
import { SelectGifInput } from "@calcom/app-store/giphyother/components";
import { SelectGifInput } from "@calcom/app-store/giphy/components";
import getApps, { getLocationOptions, hasIntegration } from "@calcom/app-store/utils";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import showToast from "@calcom/lib/notification";
@@ -2104,6 +2104,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
type: true,
key: true,
userId: true,
appId: true,
},
});
+1
View File
@@ -708,6 +708,7 @@ export async function getServerSideProps(context: NextPageContext) {
type: true,
key: true,
userId: true,
appId: true,
},
});
+1 -2
View File
@@ -1,8 +1,7 @@
import { UserPlan } from "@prisma/client";
import { GetServerSidePropsContext } from "next";
import { JSONObject } from "superjson/dist/types";
import { UserPlan } from "@calcom/prisma/client";
import { asStringOrNull } from "@lib/asStringOrNull";
import { getWorkingHours } from "@lib/availability";
import getBooking, { GetBookingType } from "@lib/getBooking";
+1
View File
@@ -55,6 +55,7 @@ async function getUserFromSession({
type: true,
key: true,
userId: true,
appId: true,
},
orderBy: {
id: "asc",
@@ -1,10 +1,9 @@
import { expect, it } from "@jest/globals";
import { Availability } from "@prisma/client";
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
import MockDate from "mockdate";
import { Availability } from "@calcom/prisma/client";
import { getAvailabilityFromSchedule } from "@lib/availability";
dayjs.extend(customParseFormat);