App env fixes
This commit is contained in:
parent
6011b440a8
commit
1de385a410
5 changed files with 54 additions and 28 deletions
|
@ -3,12 +3,8 @@ import short from "short-uuid";
|
||||||
import { v5 as uuidv5 } from "uuid";
|
import { v5 as uuidv5 } from "uuid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import {
|
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
||||||
_AvailabilityModel,
|
import { _DestinationCalendarModel, _EventTypeCustomInputModel, _EventTypeModel } from "@calcom/prisma/zod";
|
||||||
_DestinationCalendarModel,
|
|
||||||
_EventTypeCustomInputModel,
|
|
||||||
_EventTypeModel,
|
|
||||||
} from "@calcom/prisma/zod";
|
|
||||||
import { stringOrNumber } from "@calcom/prisma/zod-utils";
|
import { stringOrNumber } from "@calcom/prisma/zod-utils";
|
||||||
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
|
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
|
||||||
|
|
||||||
|
@ -128,7 +124,8 @@ export const eventTypesRouter = createProtectedRouter()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.DAILY_API_KEY) {
|
const appKeys = await getAppKeysFromSlug("dailyvideo");
|
||||||
|
if (typeof appKeys.api_key === "string") {
|
||||||
data.locations = [{ type: "integrations:daily" }];
|
data.locations = [{ type: "integrations:daily" }];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import _package from "./package.json";
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
name: "Tandem Video",
|
name: "Tandem Video",
|
||||||
description: _package.description,
|
description: _package.description,
|
||||||
installed: !!(process.env.TANDEM_CLIENT_ID && process.env.TANDEM_CLIENT_SECRET),
|
|
||||||
type: "tandem_video",
|
type: "tandem_video",
|
||||||
title: "Tandem Video",
|
title: "Tandem Video",
|
||||||
imageSrc: "/api/app-store/tandemvideo/icon.svg",
|
imageSrc: "/api/app-store/tandemvideo/icon.svg",
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
|
|
||||||
import { BASE_URL } from "@calcom/lib/constants";
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
const client_id = process.env.TANDEM_CLIENT_ID;
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
||||||
const TANDEM_BASE_URL = process.env.TANDEM_BASE_URL;
|
|
||||||
|
let client_id = "";
|
||||||
|
let base_url = "";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
|
@ -20,14 +22,20 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const redirect_uri = encodeURI(BASE_URL + "/api/integrations/tandemvideo/callback");
|
const appKeys = await getAppKeysFromSlug("tandem");
|
||||||
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
||||||
|
if (typeof appKeys.base_url === "string") base_url = appKeys.base_url;
|
||||||
|
if (!client_id) return res.status(400).json({ message: "Tandem client_id missing." });
|
||||||
|
if (!base_url) return res.status(400).json({ message: "Tandem base_url missing." });
|
||||||
|
|
||||||
|
const redirect_uri = encodeURI(WEBAPP_URL + "/api/integrations/tandemvideo/callback");
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
client_id,
|
client_id,
|
||||||
redirect_uri,
|
redirect_uri,
|
||||||
};
|
};
|
||||||
const query = stringify(params);
|
const query = stringify(params);
|
||||||
const url = `${TANDEM_BASE_URL}/oauth/approval?${query}`;
|
const url = `${base_url}/oauth/approval?${query}`;
|
||||||
res.status(200).json({ url });
|
res.status(200).json({ url });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
const client_id = process.env.TANDEM_CLIENT_ID as string;
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
||||||
const client_secret = process.env.TANDEM_CLIENT_SECRET as string;
|
|
||||||
const TANDEM_BASE_URL = (process.env.TANDEM_BASE_URL as string) || "https://tandem.chat";
|
let client_id = "";
|
||||||
|
let client_secret = "";
|
||||||
|
let base_url = "https://tandem.chat";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (!req.query.code) {
|
if (!req.query.code) {
|
||||||
|
@ -14,7 +16,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
|
|
||||||
const code = req.query.code as string;
|
const code = req.query.code as string;
|
||||||
|
|
||||||
const result = await fetch(`${TANDEM_BASE_URL}/api/v1/oauth/v2/token`, {
|
const appKeys = await getAppKeysFromSlug("tandem");
|
||||||
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
||||||
|
if (typeof appKeys.client_secret === "string") client_secret = appKeys.client_secret;
|
||||||
|
if (typeof appKeys.base_url === "string") base_url = appKeys.base_url;
|
||||||
|
if (!client_id) return res.status(400).json({ message: "Tandem client_id missing." });
|
||||||
|
if (!client_secret) return res.status(400).json({ message: "Tandem client_secret missing." });
|
||||||
|
if (!base_url) return res.status(400).json({ message: "Tandem base_url missing." });
|
||||||
|
|
||||||
|
const result = await fetch(`${base_url}/api/v1/oauth/v2/token`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@ -37,6 +47,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
create: {
|
create: {
|
||||||
type: "tandem_video",
|
type: "tandem_video",
|
||||||
key: responseBody,
|
key: responseBody,
|
||||||
|
appId: "tandem",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import { Credential } from "@prisma/client";
|
import { Credential } from "@prisma/client";
|
||||||
|
|
||||||
import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors";
|
import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors";
|
||||||
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||||
import type { PartialReference } from "@calcom/types/EventManager";
|
import type { PartialReference } from "@calcom/types/EventManager";
|
||||||
import type { VideoApiAdapter, VideoCallData } from "@calcom/types/VideoApiAdapter";
|
import type { VideoApiAdapter, VideoCallData } from "@calcom/types/VideoApiAdapter";
|
||||||
|
|
||||||
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
||||||
|
|
||||||
interface TandemToken {
|
interface TandemToken {
|
||||||
expires_in?: number;
|
expires_in?: number;
|
||||||
expiry_date: number;
|
expiry_date: number;
|
||||||
|
@ -14,16 +17,24 @@ interface TandemToken {
|
||||||
access_token: string;
|
access_token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const client_id = process.env.TANDEM_CLIENT_ID as string;
|
let client_id = "";
|
||||||
const client_secret = process.env.TANDEM_CLIENT_SECRET as string;
|
let client_secret = "";
|
||||||
const TANDEM_BASE_URL = process.env.TANDEM_BASE_URL as string;
|
let base_url = "";
|
||||||
|
|
||||||
|
const tandemAuth = async (credential: Credential) => {
|
||||||
|
const appKeys = await getAppKeysFromSlug("tandem");
|
||||||
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
||||||
|
if (typeof appKeys.client_secret === "string") client_secret = appKeys.client_secret;
|
||||||
|
if (typeof appKeys.base_url === "string") base_url = appKeys.base_url;
|
||||||
|
if (!client_id) throw new HttpError({ statusCode: 400, message: "Tandem client_id missing." });
|
||||||
|
if (!client_secret) throw new HttpError({ statusCode: 400, message: "Tandem client_secret missing." });
|
||||||
|
if (!base_url) throw new HttpError({ statusCode: 400, message: "Tandem base_url missing." });
|
||||||
|
|
||||||
const tandemAuth = (credential: Credential) => {
|
|
||||||
const credentialKey = credential.key as unknown as TandemToken;
|
const credentialKey = credential.key as unknown as TandemToken;
|
||||||
const isTokenValid = (token: TandemToken) => token && token.access_token && token.expiry_date < Date.now();
|
const isTokenValid = (token: TandemToken) => token && token.access_token && token.expiry_date < Date.now();
|
||||||
|
|
||||||
const refreshAccessToken = (refreshToken: string) => {
|
const refreshAccessToken = (refreshToken: string) => {
|
||||||
fetch(`${TANDEM_BASE_URL}/api/v1/oauth/v2/token`, {
|
fetch(`${base_url}/api/v1/oauth/v2/token`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
client_id,
|
client_id,
|
||||||
|
@ -95,9 +106,9 @@ const TandemVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
},
|
},
|
||||||
createMeeting: async (event: CalendarEvent): Promise<VideoCallData> => {
|
createMeeting: async (event: CalendarEvent): Promise<VideoCallData> => {
|
||||||
const accessToken = await auth.getToken();
|
const accessToken = await (await auth).getToken();
|
||||||
|
|
||||||
const result = await fetch(`${TANDEM_BASE_URL}/api/v1/meetings`, {
|
const result = await fetch(`${base_url}/api/v1/meetings`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
|
@ -110,9 +121,9 @@ const TandemVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteMeeting: async (uid: string): Promise<void> => {
|
deleteMeeting: async (uid: string): Promise<void> => {
|
||||||
const accessToken = await auth.getToken();
|
const accessToken = await (await auth).getToken();
|
||||||
|
|
||||||
await fetch(`${TANDEM_BASE_URL}/api/v1/meetings/${uid}`, {
|
await fetch(`${base_url}/api/v1/meetings/${uid}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
|
@ -123,9 +134,9 @@ const TandemVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateMeeting: async (bookingRef: PartialReference, event: CalendarEvent): Promise<VideoCallData> => {
|
updateMeeting: async (bookingRef: PartialReference, event: CalendarEvent): Promise<VideoCallData> => {
|
||||||
const accessToken = await auth.getToken();
|
const accessToken = await (await auth).getToken();
|
||||||
|
|
||||||
const result = await fetch(`${TANDEM_BASE_URL}/api/v1/meetings/${bookingRef.meetingId}`, {
|
const result = await fetch(`${base_url}/api/v1/meetings/${bookingRef.meetingId}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + accessToken,
|
Authorization: "Bearer " + accessToken,
|
||||||
|
|
Loading…
Reference in a new issue