2023-08-14 12:02:29 -03:00
|
|
|
import type { AppCategories } from "@prisma/client";
|
2022-03-23 19:00:30 -03:00
|
|
|
|
2023-01-18 19:30:25 -03:00
|
|
|
// If you import this file on any app it should produce circular dependency
|
|
|
|
// import appStore from "./index";
|
|
|
|
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
2023-02-16 19:39:57 -03:00
|
|
|
import type { EventLocationType } from "@calcom/app-store/locations";
|
2023-10-10 01:16:04 -03:00
|
|
|
import logger from "@calcom/lib/logger";
|
|
|
|
import { getPiiFreeCredential } from "@calcom/lib/piiFreeData";
|
|
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
2022-08-25 21:48:50 -03:00
|
|
|
import type { App, AppMeta } from "@calcom/types/App";
|
2023-09-14 13:53:58 -03:00
|
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
2022-03-23 19:00:30 -03:00
|
|
|
|
2023-02-17 16:53:31 -03:00
|
|
|
export * from "./_utils/getEventTypeAppData";
|
|
|
|
|
2023-01-21 13:52:21 -03:00
|
|
|
type LocationOption = {
|
|
|
|
label: string;
|
|
|
|
value: EventLocationType["type"];
|
|
|
|
icon?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
};
|
|
|
|
|
2022-04-14 23:04:21 -03:00
|
|
|
const ALL_APPS_MAP = Object.keys(appStoreMetadata).reduce((store, key) => {
|
2023-01-18 19:30:25 -03:00
|
|
|
const metadata = appStoreMetadata[key as keyof typeof appStoreMetadata] as AppMeta;
|
2023-04-26 08:03:34 -03:00
|
|
|
|
2023-01-18 19:30:25 -03:00
|
|
|
store[key] = metadata;
|
|
|
|
|
2022-09-02 16:00:41 -03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
//@ts-ignore
|
|
|
|
delete store[key]["/*"];
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
//@ts-ignore
|
|
|
|
delete store[key]["__createdUsingCli"];
|
2022-03-23 19:00:30 -03:00
|
|
|
return store;
|
2022-08-25 21:48:50 -03:00
|
|
|
}, {} as Record<string, AppMeta>);
|
2022-03-23 19:00:30 -03:00
|
|
|
|
2023-09-14 13:53:58 -03:00
|
|
|
export type CredentialDataWithTeamName = CredentialPayload & {
|
2023-08-02 00:54:28 -03:00
|
|
|
team?: {
|
|
|
|
name: string;
|
|
|
|
} | null;
|
|
|
|
};
|
2023-03-07 19:37:56 -03:00
|
|
|
|
2023-08-02 00:54:28 -03:00
|
|
|
export const ALL_APPS = Object.values(ALL_APPS_MAP);
|
2022-11-24 08:53:29 -03:00
|
|
|
|
2022-03-23 19:00:30 -03:00
|
|
|
/**
|
2022-04-14 23:24:27 -03:00
|
|
|
* This should get all available apps to the user based on his saved
|
2022-03-23 19:00:30 -03:00
|
|
|
* credentials, this should also get globally available apps.
|
|
|
|
*/
|
2023-08-02 00:54:28 -03:00
|
|
|
function getApps(credentials: CredentialDataWithTeamName[], filterOnCredentials?: boolean) {
|
2023-08-01 08:10:52 -03:00
|
|
|
const apps = ALL_APPS.reduce((reducedArray, appMeta) => {
|
|
|
|
const appCredentials = credentials.filter((credential) => credential.type === appMeta.type);
|
|
|
|
|
|
|
|
if (filterOnCredentials && !appCredentials.length && !appMeta.isGlobal) return reducedArray;
|
|
|
|
|
2023-01-21 13:52:21 -03:00
|
|
|
let locationOption: LocationOption | null = null;
|
2022-03-23 19:00:30 -03:00
|
|
|
|
|
|
|
/** If the app is a globally installed one, let's inject it's key */
|
|
|
|
if (appMeta.isGlobal) {
|
2023-10-10 01:16:04 -03:00
|
|
|
const credential = {
|
2023-07-06 18:39:33 -03:00
|
|
|
id: 0,
|
2022-03-23 19:00:30 -03:00
|
|
|
type: appMeta.type,
|
2022-10-14 13:24:43 -03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-03-23 19:00:30 -03:00
|
|
|
key: appMeta.key!,
|
2023-07-06 18:39:33 -03:00
|
|
|
userId: 0,
|
2023-09-14 13:53:58 -03:00
|
|
|
user: { email: "" },
|
2023-08-02 00:54:28 -03:00
|
|
|
teamId: null,
|
2022-05-02 17:39:35 -03:00
|
|
|
appId: appMeta.slug,
|
2022-12-07 18:47:02 -03:00
|
|
|
invalid: false,
|
2023-08-02 00:54:28 -03:00
|
|
|
team: {
|
|
|
|
name: "Global",
|
|
|
|
},
|
2023-10-10 01:16:04 -03:00
|
|
|
};
|
|
|
|
logger.debug(
|
|
|
|
`${appMeta.type} is a global app, injecting credential`,
|
|
|
|
safeStringify(getPiiFreeCredential(credential))
|
|
|
|
);
|
|
|
|
appCredentials.push(credential);
|
2022-03-23 19:00:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Check if app has location option AND add it if user has credentials for it */
|
2023-08-01 08:10:52 -03:00
|
|
|
if (appCredentials.length > 0 && appMeta?.appData?.location) {
|
2022-03-23 19:00:30 -03:00
|
|
|
locationOption = {
|
2022-08-25 21:48:50 -03:00
|
|
|
value: appMeta.appData.location.type,
|
|
|
|
label: appMeta.appData.location.label || "No label set",
|
2022-03-23 19:00:30 -03:00
|
|
|
disabled: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-01 08:10:52 -03:00
|
|
|
const credential: (typeof appCredentials)[number] | null = appCredentials[0] || null;
|
|
|
|
|
|
|
|
reducedArray.push({
|
2022-03-23 19:00:30 -03:00
|
|
|
...appMeta,
|
|
|
|
/**
|
|
|
|
* @deprecated use `credentials`
|
|
|
|
*/
|
|
|
|
credential,
|
2023-08-01 08:10:52 -03:00
|
|
|
credentials: appCredentials,
|
2022-03-23 19:00:30 -03:00
|
|
|
/** Option to display in `location` field while editing event types */
|
|
|
|
locationOption,
|
2023-08-01 08:10:52 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
return reducedArray;
|
2023-08-02 00:54:28 -03:00
|
|
|
}, [] as (App & { credential: CredentialDataWithTeamName; credentials: CredentialDataWithTeamName[]; locationOption: LocationOption | null })[]);
|
2022-03-23 19:00:30 -03:00
|
|
|
|
|
|
|
return apps;
|
|
|
|
}
|
|
|
|
|
2022-12-07 18:47:02 -03:00
|
|
|
export function getLocalAppMetadata() {
|
|
|
|
return ALL_APPS;
|
|
|
|
}
|
|
|
|
|
2022-03-23 19:00:30 -03:00
|
|
|
export function hasIntegrationInstalled(type: App["type"]): boolean {
|
|
|
|
return ALL_APPS.some((app) => app.type === type && !!app.installed);
|
|
|
|
}
|
|
|
|
|
2022-04-26 01:20:13 -03:00
|
|
|
export function getAppName(name: string): string | null {
|
|
|
|
return ALL_APPS_MAP[name as keyof typeof ALL_APPS_MAP]?.name ?? null;
|
2022-03-23 19:00:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getAppType(name: string): string {
|
|
|
|
const type = ALL_APPS_MAP[name as keyof typeof ALL_APPS_MAP].type;
|
|
|
|
|
|
|
|
if (type.endsWith("_calendar")) {
|
|
|
|
return "Calendar";
|
|
|
|
}
|
|
|
|
if (type.endsWith("_payment")) {
|
|
|
|
return "Payment";
|
|
|
|
}
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2023-02-15 12:42:49 -03:00
|
|
|
export function getAppFromSlug(slug: string | undefined): AppMeta | undefined {
|
|
|
|
return ALL_APPS.find((app) => app.slug === slug);
|
|
|
|
}
|
|
|
|
|
2023-03-06 07:53:35 -03:00
|
|
|
export function getAppFromLocationValue(type: string): AppMeta | undefined {
|
|
|
|
return ALL_APPS.find((app) => app?.appData?.location?.type === type);
|
|
|
|
}
|
|
|
|
|
2023-08-02 00:54:28 -03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param appCategories - from app metadata
|
|
|
|
* @param concurrentMeetings - from app metadata
|
|
|
|
* @returns - true if app supports team install
|
|
|
|
*/
|
2023-11-15 09:29:41 -03:00
|
|
|
export function doesAppSupportTeamInstall({
|
|
|
|
appCategories,
|
|
|
|
concurrentMeetings = undefined,
|
|
|
|
isPaid,
|
|
|
|
}: {
|
|
|
|
appCategories: string[];
|
|
|
|
concurrentMeetings: boolean | undefined;
|
|
|
|
isPaid: boolean;
|
|
|
|
}) {
|
|
|
|
// Paid apps can't be installed on team level - That isn't supported
|
|
|
|
if (isPaid) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-02 00:54:28 -03:00
|
|
|
return !appCategories.some(
|
2023-08-14 12:02:29 -03:00
|
|
|
(category) =>
|
|
|
|
category === "calendar" ||
|
|
|
|
(defaultVideoAppCategories.includes(category as AppCategories) && !concurrentMeetings)
|
2023-08-02 00:54:28 -03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-14 12:02:29 -03:00
|
|
|
export const defaultVideoAppCategories: AppCategories[] = [
|
|
|
|
"conferencing",
|
|
|
|
"messaging",
|
|
|
|
// Legacy name for conferencing
|
|
|
|
"video",
|
|
|
|
];
|
|
|
|
|
2022-03-23 19:00:30 -03:00
|
|
|
export default getApps;
|