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:
1 parent
21867c9cd4
commit
6a27fb2959
68 files changed
+995
-1628
No files matched your search
@@ -0,0 +1,43 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "AppCategories" AS ENUM ('calendar', 'messaging', 'other', 'payment', 'video', 'web3');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Credential" ADD COLUMN "appId" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "App" (
|
||||
"slug" TEXT NOT NULL,
|
||||
"dirName" TEXT NOT NULL,
|
||||
"keys" JSONB,
|
||||
"categories" "AppCategories"[],
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "App_pkey" PRIMARY KEY ("slug")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "App_slug_key" ON "App"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "App_dirName_key" ON "App"("dirName");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Credential" ADD CONSTRAINT "Credential_appId_fkey" FOREIGN KEY ("appId") REFERENCES "App"("slug") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- Connects each saved Credential to their respective App
|
||||
UPDATE "Credential" SET "appId" = 'apple-calendar' WHERE "type" = 'apple_calendar';
|
||||
UPDATE "Credential" SET "appId" = 'caldav-calendar' WHERE "type" = 'caldav_calendar';
|
||||
UPDATE "Credential" SET "appId" = 'google-calendar' WHERE "type" = 'google_calendar';
|
||||
UPDATE "Credential" SET "appId" = 'google-meet' WHERE "type" = 'google_video';
|
||||
UPDATE "Credential" SET "appId" = 'office365-calendar' WHERE "type" = 'office365_calendar';
|
||||
UPDATE "Credential" SET "appId" = 'msteams' WHERE "type" = 'office365_video';
|
||||
UPDATE "Credential" SET "appId" = 'dailyvideo' WHERE "type" = 'daily_video';
|
||||
UPDATE "Credential" SET "appId" = 'tandem' WHERE "type" = 'tandem_video';
|
||||
UPDATE "Credential" SET "appId" = 'zoom' WHERE "type" = 'zoom_video';
|
||||
UPDATE "Credential" SET "appId" = 'jitsi' WHERE "type" = 'jitsi_video';
|
||||
UPDATE "Credential" SET "appId" = 'hubspot' WHERE "type" = 'hubspot_other_calendar';
|
||||
UPDATE "Credential" SET "appId" = 'wipe-my-cal' WHERE "type" = 'wipemycal_other';
|
||||
UPDATE "Credential" SET "appId" = 'huddle01' WHERE "type" = 'huddle01_video';
|
||||
UPDATE "Credential" SET "appId" = 'slack' WHERE "type" = 'slack_messaging';
|
||||
UPDATE "Credential" SET "appId" = 'stripe' WHERE "type" = 'stripe_payment';
|
||||
@@ -13,21 +13,22 @@
|
||||
"db-setup": "run-s db-up db-deploy db-seed",
|
||||
"db-studio": "yarn prisma studio",
|
||||
"db-up": "docker-compose up -d",
|
||||
"deploy": "yarn prisma migrate deploy",
|
||||
"deploy": "yarn prisma migrate deploy && yarn seed-app-store",
|
||||
"dx": "yarn db-setup",
|
||||
"generate-schemas": "prisma generate && prisma format",
|
||||
"postinstall": "yarn generate-schemas"
|
||||
"postinstall": "yarn generate-schemas",
|
||||
"seed-app-store": "ts-node --transpile-only ./seed-app-store.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prisma": "3.10.0",
|
||||
"prisma": "^3.13.0",
|
||||
"ts-node": "^10.6.0",
|
||||
"zod": "^3.14.4",
|
||||
"zod-prisma": "^0.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*",
|
||||
"@prisma/client": "^3.12.0"
|
||||
"@prisma/client": "^3.13.0"
|
||||
},
|
||||
"main": "index.ts",
|
||||
"types": "index.d.ts",
|
||||
@@ -37,6 +38,6 @@
|
||||
"zod-utils.ts"
|
||||
],
|
||||
"prisma": {
|
||||
"seed": "ts-node ./seed.ts"
|
||||
"seed": "ts-node --transpile-only ./seed.ts"
|
||||
}
|
||||
}
|
||||
@@ -77,11 +77,13 @@ model EventType {
|
||||
}
|
||||
|
||||
model Credential {
|
||||
id Int @id @default(autoincrement())
|
||||
id Int @id @default(autoincrement())
|
||||
type String
|
||||
key Json
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
|
||||
appId String?
|
||||
}
|
||||
|
||||
enum UserPlan {
|
||||
@@ -440,3 +442,26 @@ model Session {
|
||||
expires DateTime
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum AppCategories {
|
||||
calendar
|
||||
messaging
|
||||
other
|
||||
payment
|
||||
video
|
||||
web3
|
||||
}
|
||||
|
||||
model App {
|
||||
// The slug for the app store public page inside `/apps/[slug]`
|
||||
slug String @id @unique
|
||||
// The directory name for `/packages/app-store/[dirName]`
|
||||
dirName String @unique
|
||||
// Needed API Keys
|
||||
keys Json?
|
||||
// One or multiple categories to which this app belongs
|
||||
categories AppCategories[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
credentials Credential[]
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from ".";
|
||||
|
||||
require("dotenv").config({ path: "../../.env" });
|
||||
|
||||
async function createApp(
|
||||
slug: Prisma.AppCreateInput["slug"],
|
||||
/** The directory name for `/packages/app-store/[dirName]` */
|
||||
dirName: Prisma.AppCreateInput["dirName"],
|
||||
categories: Prisma.AppCreateInput["categories"],
|
||||
keys?: Prisma.AppCreateInput["keys"]
|
||||
) {
|
||||
await prisma.app.upsert({
|
||||
where: { slug },
|
||||
create: { slug, dirName, categories, keys },
|
||||
update: { dirName, categories, keys },
|
||||
});
|
||||
console.log(`📲 Upserted app: '${slug}'`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Calendar apps
|
||||
await createApp("apple-calendar", "applecalendar", ["calendar"]);
|
||||
await createApp("caldav-calendar", "caldavcalendar", ["calendar"]);
|
||||
try {
|
||||
const { client_secret, client_id, redirect_uris } = JSON.parse(process.env.GOOGLE_API_CREDENTIALS).web;
|
||||
await createApp("google-calendar", "googlecalendar", ["calendar"], {
|
||||
client_id,
|
||||
client_secret,
|
||||
redirect_uris,
|
||||
});
|
||||
await createApp("google-meet", "googlevideo", ["video"], { client_id, client_secret, redirect_uris });
|
||||
} catch (e) {
|
||||
if (e instanceof Error) console.error("Error adding google credentials to DB:", e.message);
|
||||
}
|
||||
if (process.env.MS_GRAPH_CLIENT_ID && process.env.MS_GRAPH_CLIENT_SECRET) {
|
||||
await createApp("office365-calendar", "office365calendar", ["calendar"], {
|
||||
client_id: process.env.MS_GRAPH_CLIENT_ID,
|
||||
client_secret: process.env.MS_GRAPH_CLIENT_SECRET,
|
||||
});
|
||||
await createApp("msteams", "office365video", ["video"]);
|
||||
}
|
||||
// Video apps
|
||||
if (process.env.DAILY_API_KEY) {
|
||||
await createApp("dailyvideo", "dailyvideo", ["video"], {
|
||||
api_key: process.env.DAILY_API_KEY,
|
||||
scale_plan: process.env.DAILY_SCALE_PLAN,
|
||||
});
|
||||
}
|
||||
if (process.env.TANDEM_CLIENT_ID && process.env.TANDEM_CLIENT_SECRET) {
|
||||
await createApp("tandem", "tandemvideo", ["video"], {
|
||||
client_id: process.env.TANDEM_CLIENT_ID as string,
|
||||
client_secret: process.env.TANDEM_CLIENT_SECRET as string,
|
||||
base_url: (process.env.TANDEM_BASE_URL as string) || "https://tandem.chat",
|
||||
});
|
||||
}
|
||||
if (process.env.ZOOM_CLIENT_ID && process.env.ZOOM_CLIENT_SECRET) {
|
||||
await createApp("zoom", "zoomvideo", ["video"], {
|
||||
client_id: process.env.ZOOM_CLIENT_ID,
|
||||
client_secret: process.env.ZOOM_CLIENT_SECRET,
|
||||
});
|
||||
}
|
||||
await createApp("jitsi", "jitsivideo", ["video"]);
|
||||
// Other apps
|
||||
if (process.env.HUBSPOT_CLIENT_ID && process.env.HUBSPOT_CLIENT_SECRET) {
|
||||
await createApp("hubspot", "hubspotothercalendar", ["other"], {
|
||||
client_id: process.env.HUBSPOT_CLIENT_ID,
|
||||
client_secret: process.env.HUBSPOT_CLIENT_SECRET,
|
||||
});
|
||||
}
|
||||
await createApp("wipe-my-cal", "wipemycalother", ["other"]);
|
||||
if (process.env.GIPHY_API_KEY) {
|
||||
await createApp("giphy", "giphy", ["other"], {
|
||||
api_key: process.env.GIPHY_API_KEY,
|
||||
});
|
||||
}
|
||||
// Web3 apps
|
||||
await createApp("huddle01", "huddle01video", ["web3", "video"]);
|
||||
// Messaging apps
|
||||
if (process.env.SLACK_CLIENT_ID && process.env.SLACK_CLIENT_SECRET && process.env.SLACK_SIGNING_SECRET) {
|
||||
await createApp("slack", "slackmessaging", ["messaging"], {
|
||||
client_id: process.env.SLACK_CLIENT_ID,
|
||||
client_secret: process.env.SLACK_CLIENT_SECRET,
|
||||
signing_secret: process.env.SLACK_SIGNING_SECRET,
|
||||
});
|
||||
}
|
||||
// Payment apps
|
||||
if (
|
||||
process.env.STRIPE_CLIENT_ID &&
|
||||
process.env.STRIPE_PRIVATE_KEY &&
|
||||
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY &&
|
||||
process.env.STRIPE_WEBHOOK_SECRET
|
||||
) {
|
||||
await createApp("stripe", "stripepayment", ["payment"], {
|
||||
client_id: process.env.STRIPE_CLIENT_ID,
|
||||
client_secret: process.env.STRIPE_PRIVATE_KEY,
|
||||
payment_fee_fixed: 10,
|
||||
payment_fee_percentage: 0.005,
|
||||
public_key: process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY,
|
||||
webhook_secret: process.env.STRIPE_WEBHOOK_SECRET,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
@@ -1,13 +1,14 @@
|
||||
import { MembershipRole, Prisma, PrismaClient, UserPlan } from "@prisma/client";
|
||||
import { MembershipRole, Prisma, UserPlan } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
import { uuid } from "short-uuid";
|
||||
|
||||
import { hashPassword } from "@calcom/lib/auth";
|
||||
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
|
||||
require("dotenv").config({ path: "../../.env" });
|
||||
import prisma from ".";
|
||||
import "./seed-app-store";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
require("dotenv").config({ path: "../../.env" });
|
||||
|
||||
async function createUserAndEventType(opts: {
|
||||
user: {
|
||||
|
||||
Reference in new issue
Block a user