@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.
58 lines (57 loc) • 2.46 kB
TypeScript
import { Client } from "@microsoft/microsoft-graph-client";
import { OutlookDeltaLinkRepository } from "../../repositories/outlook-delta-link.repository";
import { ResourceType } from "../../enums/resource-type.enum";
import { Event, Message } from "../../types";
import { UserIdConverterService } from "./user-id-converter.service";
import { GraphRateLimiterService } from "./graph-rate-limiter.service";
export interface DeltaItem {
lastModifiedDateTime?: string;
createdDateTime?: string;
id?: string;
"@removed"?: {
reason: "changed" | "deleted";
};
}
export type DeltaEvent = Event & DeltaItem;
export type DeltaMessage = Message & DeltaItem;
export interface DeltaResponse<T> {
"@odata.nextLink"?: string;
"@odata.deltaLink"?: string;
value: T[];
}
export declare class DeltaSyncError extends Error {
readonly code: string;
readonly statusCode: number;
constructor(message: string, code: string, statusCode: number);
}
export declare class DeltaSyncService {
private readonly deltaLinkRepository;
private readonly userIdConverter;
private readonly rateLimiter;
private readonly logger;
private readonly MAX_RETRIES;
private readonly RETRY_DELAY_MS;
constructor(deltaLinkRepository: OutlookDeltaLinkRepository, userIdConverter: UserIdConverterService, rateLimiter: GraphRateLimiterService);
private handleDeltaResponse;
private calculateTokenExpiry;
private handleReplays;
private sortDeltaItems;
private fetchEventDetailsWithConcurrencyLimit;
private fetchDeltaPagesCore;
private fetchAllDeltaPages;
fetchAndSortChanges(client: Client, requestUrl: string, externalUserId: string, forceReset?: boolean, dateRange?: {
startDate: Date;
endDate: Date;
}): Promise<DeltaItem[]>;
private is410Error;
streamDeltaChanges(client: Client, requestUrl: string, externalUserId: string, forceReset?: boolean, dateRange?: {
startDate: Date;
endDate: Date;
}, saveDeltaLink?: boolean): AsyncGenerator<DeltaItem[], string | null, unknown>;
initializeDeltaLink(client: Client, requestUrl: string, internalUserId: number, resourceType: ResourceType, dateRange?: {
startDate: Date;
endDate: Date;
}): Promise<DeltaItem[]>;
saveDeltaLink(internalUserId: number, resourceType: ResourceType, deltaLink: string): Promise<void>;
getDeltaLink<T>(response: DeltaResponse<T>): string | null;
}