2022-05-02 20:39:35 +00:00
|
|
|
import { Prisma } from "@prisma/client";
|
2022-06-07 06:13:32 +00:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
2022-05-02 20:39:35 +00:00
|
|
|
|
|
|
|
import prisma from ".";
|
|
|
|
|
2022-05-04 22:10:51 +00:00
|
|
|
require("dotenv").config({ path: "../../.env.appStore" });
|
2022-05-02 20:39:35 +00:00
|
|
|
|
|
|
|
async function createApp(
|
2022-05-06 17:21:30 +00:00
|
|
|
/** The App identifier in the DB also used for public page in `/apps/[slug]` */
|
2022-05-02 20:39:35 +00:00
|
|
|
slug: Prisma.AppCreateInput["slug"],
|
|
|
|
/** The directory name for `/packages/app-store/[dirName]` */
|
|
|
|
dirName: Prisma.AppCreateInput["dirName"],
|
|
|
|
categories: Prisma.AppCreateInput["categories"],
|
2022-05-04 04:06:20 +00:00
|
|
|
/** This is used so credentials gets linked to the correct app */
|
2022-05-02 22:02:45 +00:00
|
|
|
type: Prisma.CredentialCreateInput["type"],
|
2022-05-02 20:39:35 +00:00
|
|
|
keys?: Prisma.AppCreateInput["keys"]
|
|
|
|
) {
|
|
|
|
await prisma.app.upsert({
|
|
|
|
where: { slug },
|
|
|
|
create: { slug, dirName, categories, keys },
|
|
|
|
update: { dirName, categories, keys },
|
|
|
|
});
|
2022-05-02 22:02:45 +00:00
|
|
|
await prisma.credential.updateMany({
|
|
|
|
where: { type },
|
|
|
|
data: { appId: slug },
|
|
|
|
});
|
2022-05-02 20:39:35 +00:00
|
|
|
console.log(`📲 Upserted app: '${slug}'`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
// Calendar apps
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("apple-calendar", "applecalendar", ["calendar"], "apple_calendar");
|
|
|
|
await createApp("caldav-calendar", "caldavcalendar", ["calendar"], "caldav_calendar");
|
2022-06-13 22:12:27 +00:00
|
|
|
await createApp("exchange2013-calendar", "exchange2013calendar", ["calendar"], "exchange2013_calendar");
|
|
|
|
await createApp("exchange2016-calendar", "exchange2016calendar", ["calendar"], "exchange2016_calendar");
|
2022-05-02 20:39:35 +00:00
|
|
|
try {
|
|
|
|
const { client_secret, client_id, redirect_uris } = JSON.parse(process.env.GOOGLE_API_CREDENTIALS).web;
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("google-calendar", "googlecalendar", ["calendar"], "google_calendar", {
|
|
|
|
client_id,
|
|
|
|
client_secret,
|
|
|
|
redirect_uris,
|
|
|
|
});
|
|
|
|
await createApp("google-meet", "googlevideo", ["video"], "google_video", {
|
2022-05-02 20:39:35 +00:00
|
|
|
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) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("office365-calendar", "office365calendar", ["calendar"], "office365_calendar", {
|
2022-05-02 20:39:35 +00:00
|
|
|
client_id: process.env.MS_GRAPH_CLIENT_ID,
|
|
|
|
client_secret: process.env.MS_GRAPH_CLIENT_SECRET,
|
|
|
|
});
|
2022-05-13 12:20:50 +00:00
|
|
|
await createApp("msteams", "office365video", ["video"], "office365_video", {
|
|
|
|
client_id: process.env.MS_GRAPH_CLIENT_ID,
|
|
|
|
client_secret: process.env.MS_GRAPH_CLIENT_SECRET,
|
|
|
|
});
|
2022-05-02 20:39:35 +00:00
|
|
|
}
|
|
|
|
// Video apps
|
|
|
|
if (process.env.DAILY_API_KEY) {
|
2022-05-05 22:34:26 +00:00
|
|
|
await createApp("daily-video", "dailyvideo", ["video"], "daily_video", {
|
2022-05-02 20:39:35 +00:00
|
|
|
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) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("tandem", "tandemvideo", ["video"], "tandem_video", {
|
2022-05-02 20:39:35 +00:00
|
|
|
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) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("zoom", "zoomvideo", ["video"], "zoom_video", {
|
2022-05-02 20:39:35 +00:00
|
|
|
client_id: process.env.ZOOM_CLIENT_ID,
|
|
|
|
client_secret: process.env.ZOOM_CLIENT_SECRET,
|
|
|
|
});
|
|
|
|
}
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("jitsi", "jitsivideo", ["video"], "jitsi_video");
|
2022-05-02 20:39:35 +00:00
|
|
|
// Other apps
|
|
|
|
if (process.env.HUBSPOT_CLIENT_ID && process.env.HUBSPOT_CLIENT_SECRET) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("hubspot", "hubspotothercalendar", ["other"], "hubspot_other_calendar", {
|
2022-05-02 20:39:35 +00:00
|
|
|
client_id: process.env.HUBSPOT_CLIENT_ID,
|
|
|
|
client_secret: process.env.HUBSPOT_CLIENT_SECRET,
|
|
|
|
});
|
|
|
|
}
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("wipe-my-cal", "wipemycalother", ["other"], "wipemycal_other");
|
2022-05-02 20:39:35 +00:00
|
|
|
if (process.env.GIPHY_API_KEY) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("giphy", "giphy", ["other"], "giphy_other", {
|
2022-05-02 20:39:35 +00:00
|
|
|
api_key: process.env.GIPHY_API_KEY,
|
|
|
|
});
|
|
|
|
}
|
2022-05-04 04:06:20 +00:00
|
|
|
await createApp("space-booking", "spacebooking", ["other"], "spacebooking_other");
|
2022-05-06 17:21:30 +00:00
|
|
|
if (process.env.VITAL_API_KEY && process.env.VITAL_WEBHOOK_SECRET) {
|
|
|
|
await createApp("vital-automation", "vital", ["other"], "vital_other", {
|
|
|
|
mode: process.env.VITAL_DEVELOPMENT_MODE || "sandbox",
|
|
|
|
region: process.env.VITAL_REGION || "us",
|
|
|
|
api_key: process.env.VITAL_API_KEY,
|
|
|
|
webhook_secret: process.env.VITAL_WEBHOOK_SECRET,
|
|
|
|
});
|
|
|
|
}
|
2022-05-11 04:58:10 +00:00
|
|
|
|
|
|
|
if (process.env.ZAPIER_INVITE_LINK) {
|
|
|
|
await createApp("zapier", "zapier", ["other"], "zapier_other", {
|
|
|
|
invite_link: process.env.ZAPIER_INVITE_LINK,
|
|
|
|
});
|
|
|
|
}
|
2022-05-02 20:39:35 +00:00
|
|
|
// Web3 apps
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("huddle01", "huddle01video", ["web3", "video"], "huddle01_video");
|
|
|
|
await createApp("metamask", "metamask", ["web3"], "metamask_web3");
|
2022-05-02 20:39:35 +00:00
|
|
|
// Messaging apps
|
|
|
|
if (process.env.SLACK_CLIENT_ID && process.env.SLACK_CLIENT_SECRET && process.env.SLACK_SIGNING_SECRET) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("slack", "slackmessaging", ["messaging"], "slack_messaging", {
|
2022-05-02 20:39:35 +00:00
|
|
|
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
|
|
|
|
) {
|
2022-05-02 22:02:45 +00:00
|
|
|
await createApp("stripe", "stripepayment", ["payment"], "stripe_payment", {
|
2022-05-02 20:39:35 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2022-06-07 06:13:32 +00:00
|
|
|
|
|
|
|
const generatedApps = JSON.parse(
|
|
|
|
fs.readFileSync(path.join(__dirname, "seed-app-store.config.json"), "utf8")
|
|
|
|
);
|
|
|
|
for (let i = 0; i < generatedApps.length; i++) {
|
|
|
|
const generatedApp = generatedApps[i];
|
|
|
|
await createApp(generatedApp.slug, generatedApp.dirName, generatedApp.categories, generatedApp.type);
|
|
|
|
}
|
2022-05-02 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
|
|
|
})
|
|
|
|
.finally(async () => {
|
|
|
|
await prisma.$disconnect();
|
|
|
|
});
|