import { CalendarEvent } from "./calendarClient"; import { v5 as uuidv5 } from "uuid"; import short from "short-uuid"; import { stripHtml } from "./emails/helpers"; const translator = short(); export default class CalEventParser { protected calEvent: CalendarEvent; protected maybeUid: string; constructor(calEvent: CalendarEvent, maybeUid: string = null) { this.calEvent = calEvent; this.maybeUid = maybeUid; } /** * Returns a link to reschedule the given booking. */ public getRescheduleLink(): string { return process.env.BASE_URL + "/reschedule/" + this.getUid(); } /** * Returns a link to cancel the given booking. */ public getCancelLink(): string { return process.env.BASE_URL + "/cancel/" + this.getUid(); } /** * Returns a unique identifier for the given calendar event. */ public getUid(): string { return this.maybeUid ?? translator.fromUUID(uuidv5(JSON.stringify(this.calEvent), uuidv5.URL)); } /** * Returns a footer section with links to change the event (as HTML). */ public getChangeEventFooterHtml(): string { return `

Need to make a change? Cancel or reschedule

`; } /** * Returns a footer section with links to change the event (as plain text). */ public getChangeEventFooter(): string { return stripHtml(this.getChangeEventFooterHtml()); } /** * Returns an extended description with all important information (as HTML). * * @protected */ public getRichDescriptionHtml(): string { // This odd indentation is necessary because otherwise the leading tabs will be applied into the event description. return ( ` Event Type:
${this.calEvent.type}
Invitee Email:
${this.calEvent.attendees[0].email}
` + (this.calEvent.location ? `Location:
${this.calEvent.location}
` : "") + `Invitee Time Zone:
${this.calEvent.attendees[0].timeZone}
Additional notes:
${this.calEvent.description}
` + this.getChangeEventFooterHtml() ); } /** * Returns an extended description with all important information (as plain text). * * @protected */ public getRichDescription(): string { return stripHtml(this.getRichDescriptionHtml()); } /** * Returns a calendar event with rich description. */ public asRichEvent(): CalendarEvent { const eventCopy: CalendarEvent = { ...this.calEvent }; eventCopy.description = this.getRichDescriptionHtml(); return eventCopy; } /** * Returns a calendar event with rich description as plain text. */ public asRichEventPlain(): CalendarEvent { const eventCopy: CalendarEvent = { ...this.calEvent }; eventCopy.description = this.getRichDescription(); return eventCopy; } }