Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / calendar / getComponentFromCalendarEvent.ts
blob56b2fa66d881745fa0bd390a0f1c6daedec68e58
1 import type { CalendarEvent, SharedVcalVeventComponent } from '../interfaces/calendar';
2 import { CALENDAR_CARD_TYPE } from './constants';
3 import { unwrap } from './helper';
4 import { parse } from './vcal';
6 const { CLEAR_TEXT, SIGNED } = CALENDAR_CARD_TYPE;
8 const getComponentFromCalendarEvent = (eventData: CalendarEvent): SharedVcalVeventComponent => {
9     const unencryptedPart = eventData.SharedEvents.find(({ Type }) => [CLEAR_TEXT, SIGNED].includes(Type));
10     if (!unencryptedPart) {
11         throw new Error('Missing unencrypted part');
12     }
13     return parse(unwrap(unencryptedPart.Data)) as SharedVcalVeventComponent;
16 export default getComponentFromCalendarEvent;