Async import of the appStore packages (#8087)
This commit is contained in:
1 parent
bff28e5d6f
commit
e043a5efd8
12 files changed
+82
-107
No files matched your search
@@ -28,6 +28,7 @@ export const getCalendarCredentials = (credentials: Array<CredentialPayload>) =>
|
||||
const calendar = getCalendar(credential);
|
||||
return app.variant === "calendar" ? [{ integration: app, credential, calendar }] : [];
|
||||
});
|
||||
|
||||
return credentials.length ? credentials : [];
|
||||
});
|
||||
|
||||
@@ -43,8 +44,8 @@ export const getConnectedCalendars = async (
|
||||
const connectedCalendars = await Promise.all(
|
||||
calendarCredentials.map(async (item) => {
|
||||
try {
|
||||
const { calendar, integration, credential } = item;
|
||||
|
||||
const { integration, credential } = item;
|
||||
const calendar = await item.calendar;
|
||||
// Don't leak credentials to the client
|
||||
const credentialId = credential.id;
|
||||
if (!calendar) {
|
||||
@@ -138,7 +139,7 @@ export const getCachedResults = async (
|
||||
selectedCalendars: SelectedCalendar[]
|
||||
): Promise<EventBusyDate[][]> => {
|
||||
const calendarCredentials = withCredentials.filter((credential) => credential.type.endsWith("_calendar"));
|
||||
const calendars = calendarCredentials.map((credential) => getCalendar(credential));
|
||||
const calendars = await Promise.all(calendarCredentials.map((credential) => getCalendar(credential)));
|
||||
performance.mark("getBusyCalendarTimesStart");
|
||||
const results = calendars.map(async (c, i) => {
|
||||
/** Filter out nulls */
|
||||
@@ -229,7 +230,7 @@ export const createEvent = async (
|
||||
calEvent: CalendarEvent
|
||||
): Promise<EventResult<NewCalendarEventType>> => {
|
||||
const uid: string = getUid(calEvent);
|
||||
const calendar = getCalendar(credential);
|
||||
const calendar = await getCalendar(credential);
|
||||
let success = true;
|
||||
let calError: string | undefined = undefined;
|
||||
|
||||
@@ -280,7 +281,7 @@ export const updateEvent = async (
|
||||
externalCalendarId: string | null
|
||||
): Promise<EventResult<NewCalendarEventType>> => {
|
||||
const uid = getUid(calEvent);
|
||||
const calendar = getCalendar(credential);
|
||||
const calendar = await getCalendar(credential);
|
||||
let success = false;
|
||||
let calError: string | undefined = undefined;
|
||||
let calWarnings: string[] | undefined = [];
|
||||
@@ -326,12 +327,12 @@ export const updateEvent = async (
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteEvent = (
|
||||
export const deleteEvent = async (
|
||||
credential: CredentialPayload,
|
||||
uid: string,
|
||||
event: CalendarEvent
|
||||
): Promise<unknown> => {
|
||||
const calendar = getCalendar(credential);
|
||||
const calendar = await getCalendar(credential);
|
||||
if (calendar) {
|
||||
return calendar.deleteEvent(uid, event);
|
||||
}
|
||||
|
||||
@@ -485,8 +485,7 @@ export default class EventManager {
|
||||
id: oldCalendarEvent.credentialId,
|
||||
},
|
||||
});
|
||||
const calendar = getCalendar(calendarCredential);
|
||||
|
||||
const calendar = await getCalendar(calendarCredential);
|
||||
await calendar?.deleteEvent(oldCalendarEvent.uid, event, oldCalendarEvent.externalCalendarId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,25 @@ const log = logger.getChildLogger({ prefix: ["[lib] videoClient"] });
|
||||
const translator = short();
|
||||
|
||||
// factory
|
||||
const getVideoAdapters = (withCredentials: CredentialPayload[]): VideoApiAdapter[] =>
|
||||
withCredentials.reduce<VideoApiAdapter[]>((acc, cred) => {
|
||||
const getVideoAdapters = async (withCredentials: CredentialPayload[]): Promise<VideoApiAdapter[]> => {
|
||||
const videoAdapters: VideoApiAdapter[] = [];
|
||||
|
||||
for (const cred of withCredentials) {
|
||||
const appName = cred.type.split("_").join(""); // Transform `zoom_video` to `zoomvideo`;
|
||||
const app = appStore[appName as keyof typeof appStore];
|
||||
const app = await appStore[appName as keyof typeof appStore];
|
||||
|
||||
if (app && "lib" in app && "VideoApiAdapter" in app.lib) {
|
||||
const makeVideoApiAdapter = app.lib.VideoApiAdapter as VideoApiAdapterFactory;
|
||||
const videoAdapter = makeVideoApiAdapter(cred);
|
||||
acc.push(videoAdapter);
|
||||
return acc;
|
||||
videoAdapters.push(videoAdapter);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
const getBusyVideoTimes = (withCredentials: CredentialPayload[]) =>
|
||||
Promise.all(getVideoAdapters(withCredentials).map((c) => c?.getAvailability())).then((results) =>
|
||||
return videoAdapters;
|
||||
};
|
||||
|
||||
const getBusyVideoTimes = async (withCredentials: CredentialPayload[]) =>
|
||||
Promise.all((await getVideoAdapters(withCredentials)).map((c) => c?.getAvailability())).then((results) =>
|
||||
results.reduce((acc, availability) => acc.concat(availability), [] as (EventBusyDate | undefined)[])
|
||||
);
|
||||
|
||||
@@ -45,7 +49,7 @@ const createMeeting = async (credential: CredentialWithAppName, calEvent: Calend
|
||||
);
|
||||
}
|
||||
|
||||
const videoAdapters = getVideoAdapters([credential]);
|
||||
const videoAdapters = await getVideoAdapters([credential]);
|
||||
const [firstVideoAdapter] = videoAdapters;
|
||||
let createdMeeting;
|
||||
let returnObject: {
|
||||
@@ -104,7 +108,7 @@ const updateMeeting = async (
|
||||
|
||||
let success = true;
|
||||
|
||||
const [firstVideoAdapter] = getVideoAdapters([credential]);
|
||||
const [firstVideoAdapter] = await getVideoAdapters([credential]);
|
||||
const updatedMeeting =
|
||||
credential && bookingRef
|
||||
? await firstVideoAdapter?.updateMeeting(bookingRef, calEvent).catch(async (e) => {
|
||||
@@ -135,9 +139,9 @@ const updateMeeting = async (
|
||||
};
|
||||
};
|
||||
|
||||
const deleteMeeting = (credential: CredentialPayload, uid: string): Promise<unknown> => {
|
||||
const deleteMeeting = async (credential: CredentialPayload, uid: string): Promise<unknown> => {
|
||||
if (credential) {
|
||||
const videoAdapter = getVideoAdapters([credential])[0];
|
||||
const videoAdapter = (await getVideoAdapters([credential]))[0];
|
||||
// There are certain video apps with no video adapter defined. e.g. riverby,whereby
|
||||
if (videoAdapter) {
|
||||
return videoAdapter.deleteMeeting(uid);
|
||||
@@ -155,7 +159,7 @@ const createMeetingWithCalVideo = async (calEvent: CalendarEvent) => {
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
const [videoAdapter] = getVideoAdapters([
|
||||
const [videoAdapter] = await getVideoAdapters([
|
||||
{
|
||||
id: 0,
|
||||
appId: "daily-video",
|
||||
@@ -178,7 +182,7 @@ const getRecordingsOfCalVideoByRoomName = async (
|
||||
console.error("Error: Cal video provider is not installed.");
|
||||
return;
|
||||
}
|
||||
const [videoAdapter] = getVideoAdapters([
|
||||
const [videoAdapter] = await getVideoAdapters([
|
||||
{
|
||||
id: 0,
|
||||
appId: "daily-video",
|
||||
@@ -199,7 +203,7 @@ const getDownloadLinkOfCalVideoByRecordingId = async (recordingId: string) => {
|
||||
console.error("Error: Cal video provider is not installed.");
|
||||
return;
|
||||
}
|
||||
const [videoAdapter] = getVideoAdapters([
|
||||
const [videoAdapter] = await getVideoAdapters([
|
||||
{
|
||||
id: 0,
|
||||
appId: "daily-video",
|
||||
|
||||
Reference in new issue
Block a user