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');
13 return parse(unwrap(unencryptedPart.Data)) as SharedVcalVeventComponent;
16 export default getComponentFromCalendarEvent;