Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/web/utils/outlook/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type AuthOptions = {
export class OutlookClient {
private readonly client: Client;
private readonly accessToken: string;
private folderIdCache: Record<string, string> | null = null;

constructor(accessToken: string) {
this.accessToken = accessToken;
Expand All @@ -45,6 +46,14 @@ export class OutlookClient {
return this.accessToken;
}

getFolderIdCache(): Record<string, string> | null {
return this.folderIdCache;
}

setFolderIdCache(cache: Record<string, string>): void {
this.folderIdCache = cache;
}

// Helper methods for common operations
async getUserProfile(): Promise<User> {
return await this.client
Expand Down
12 changes: 6 additions & 6 deletions apps/web/utils/outlook/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export function hasUnquotedParentFolderId(query: string): boolean {
return /\bparentFolderId\b/.test(cleanedQuery);
}

// Cache for folder IDs
let folderIdCache: Record<string, string> | null = null;

// Well-known folder names in Outlook that are consistent across all languages
export const WELL_KNOWN_FOLDERS = {
inbox: "inbox",
Expand All @@ -79,7 +76,8 @@ export const WELL_KNOWN_FOLDERS = {
} as const;

export async function getFolderIds(client: OutlookClient) {
if (folderIdCache) return folderIdCache;
const cachedFolderIds = client.getFolderIdCache();
if (cachedFolderIds) return cachedFolderIds;

// First get the well-known folders
const wellKnownFolders = await Promise.all(
Expand All @@ -101,15 +99,17 @@ export async function getFolderIds(client: OutlookClient) {
}),
);

folderIdCache = wellKnownFolders.reduce(
const userFolderIds = wellKnownFolders.reduce(
(acc, [key, id]) => {
if (id) acc[key] = id;
return acc;
},
{} as Record<string, string>,
);

return folderIdCache;
client.setFolderIdCache(userFolderIds);

return userFolderIds;
}

function getOutlookLabels(
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.17.42
v2.17.43
Loading