UNPKG

@checkfirst/nestjs-outlook

Version:

An opinionated NestJS module for Microsoft Outlook integration that provides easy access to Microsoft Graph API for emails, calendars, and more.

103 lines (102 loc) 5.37 kB
import { EventEmitter2 } from "@nestjs/event-emitter"; import { Client } from "@microsoft/microsoft-graph-client"; import { Event, Subscription, ChangeNotification } from "../../types"; import { MicrosoftAuthService } from "../auth/microsoft-auth.service"; import { OutlookWebhookSubscriptionRepository } from "../../repositories/outlook-webhook-subscription.repository"; import { OutlookDeltaLinkRepository } from "../../repositories/outlook-delta-link.repository"; import { MicrosoftOutlookConfig } from "../../interfaces/config/outlook-config.interface"; import { MicrosoftUser } from "../../entities/microsoft-user.entity"; import { Repository } from "typeorm"; import { DeltaSyncService } from "../shared/delta-sync.service"; import { UserIdConverterService } from "../shared/user-id-converter.service"; import { MicrosoftSubscriptionService } from "../subscription/microsoft-subscription.service"; import { OutlookWebhookSubscription } from "../../entities/outlook-webhook-subscription.entity"; import { GraphRateLimiterService } from "../shared/graph-rate-limiter.service"; export declare class CalendarService { private readonly microsoftAuthService; private readonly webhookSubscriptionRepository; private readonly eventEmitter; private readonly microsoftConfig; private readonly deltaLinkRepository; private readonly microsoftUserRepository; private readonly deltaSyncService; private readonly userIdConverter; private readonly subscriptionService; private readonly rateLimiter; private readonly logger; private readonly syncLocks; constructor(microsoftAuthService: MicrosoftAuthService, webhookSubscriptionRepository: OutlookWebhookSubscriptionRepository, eventEmitter: EventEmitter2, microsoftConfig: MicrosoftOutlookConfig, deltaLinkRepository: OutlookDeltaLinkRepository, microsoftUserRepository: Repository<MicrosoftUser>, deltaSyncService: DeltaSyncService, userIdConverter: UserIdConverterService, subscriptionService: MicrosoftSubscriptionService, rateLimiter: GraphRateLimiterService); getDefaultCalendarId(externalUserId: string): Promise<string>; createEvent(event: Partial<Event>, externalUserId: string, calendarId: string): Promise<{ event: Event; }>; updateEvent(eventId: string, updates: Partial<Event>, externalUserId: string, calendarId: string): Promise<{ event: Event; }>; deleteEvent(event: Partial<Event>, externalUserId: string, calendarId: string): Promise<void>; createBatchEvents(events: Partial<Event>[], externalUserId: string, calendarId: string): Promise<{ index: number; success: boolean; event?: Event; error?: string; }[]>; updateBatchEvents(updates: Array<{ eventId: string; updates: Partial<Event>; }>, externalUserId: string, calendarId: string): Promise<{ index: number; success: boolean; event?: Event; error?: string; }[]>; deleteBatchEvents(eventIds: string[], externalUserId: string, calendarId: string): Promise<{ id: string; success: boolean; error?: string; }[]>; createWebhookSubscription(externalUserId: string): Promise<Subscription>; renewWebhookSubscription(subscriptionId: string, internalUserId: number): Promise<Subscription>; getSubscription(subscriptionId: string): Promise<OutlookWebhookSubscription | null>; deleteWebhookSubscription(subscriptionId: string, userId: string | number): Promise<boolean>; getActiveSubscription(externalUserId: string): Promise<string | null>; renewSubscriptions(): Promise<void>; handleOutlookWebhook(notificationItem: ChangeNotification, useStreaming?: boolean): Promise<{ success: boolean; message: string; }>; fetchAndSortChanges(externalUserId: string, forceReset?: boolean, dateRange?: { startDate: Date; endDate: Date; }): Promise<Event[]>; private extractErrorDetails; streamCalendarChanges(externalUserId: string, forceReset?: boolean, dateRange?: { startDate: Date; endDate: Date; }, saveDeltaLink?: boolean): AsyncGenerator<Event[], string | null, unknown>; getAuthenticatedClient(externalUserId: string): Promise<Client>; saveDeltaLink(externalUserId: string, deltaLink: string): Promise<void>; getEventDetails(resource: string, externalUserId: string): Promise<Event | null>; getEventsBatch(eventIds: string[], externalUserId: string): Promise<Event[]>; private getEventsBatchInternal; private extractRetryAfterFromResponse; importEventsStream(externalUserId: string, options?: { startDate?: Date; endDate?: Date; batchSize?: number; }): AsyncGenerator<Event[], void, unknown>; handleOutlookWebhookV2(notificationItem: ChangeNotification): Promise<{ success: boolean; message: string; }>; getRecurringEventInstances(seriesMasterId: string, externalUserId: string, options?: { startDate?: Date; endDate?: Date; batchSize?: number; }): AsyncGenerator<Event[], void, unknown>; initializeDeltaSync(externalUserId: string): Promise<void>; private processChangesStreaming; private processChangesBuffering; private processDeltaEventChange; private validateWebhookSubscription; private buildRequestUrl; }