AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(microsoft-outlook): show subfolders in the mail folder dropdown (#16192)
Kishan Parmar872f0a48b228
diff --git a/bun.lock b/bun.lockindex da875bc8a83..844c20030c6 100644--- a/bun.lock+++ b/bun.lock@@ -5890,7 +5890,7 @@},"packages/pieces/community/microsoft-outlook": {"name": "@activepieces/piece-microsoft-outlook",- "version": "0.7.0",+ "version": "0.7.1","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/packages/pieces/community/microsoft-outlook/package.json b/packages/pieces/community/microsoft-outlook/package.jsonindex 1eb059586aa..396af3a33fe 100644--- a/packages/pieces/community/microsoft-outlook/package.json+++ b/packages/pieces/community/microsoft-outlook/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-microsoft-outlook",- "version": "0.7.0",+ "version": "0.7.1","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","dependencies": {diff --git a/packages/pieces/community/microsoft-outlook/src/lib/common/props.ts b/packages/pieces/community/microsoft-outlook/src/lib/common/props.tsindex a9293394237..ed2b2c92df0 100644--- a/packages/pieces/community/microsoft-outlook/src/lib/common/props.ts+++ b/packages/pieces/community/microsoft-outlook/src/lib/common/props.ts@@ -2,6 +2,7 @@ import { OAuth2PropertyValue, Property, tryCatch } from '@activepieces/pieces-frimport { Client, PageCollection } from '@microsoft/microsoft-graph-client';import { MailFolder, Message } from '@microsoft/microsoft-graph-types';import { microsoftOutlookAuth } from './auth';+import { outlookAtomicCommon } from './atomic-common';import { outlookCommon } from './client';type DropdownParams = {@@ -117,9 +118,10 @@ export const mailFolderIdDropdown = (params: DropdownParams) =>const authValue = auth as OAuth2PropertyValue;const client = outlookCommon.createClient(authValue);+ const prefix = outlookCommon.mailboxPrefix(authValue);const { folders, failed } = await fetchAllFolders({client,- firstPageUrl: `${outlookCommon.mailboxPrefix(authValue)}/mailFolders?$top=100`,+ firstPageUrl: `${prefix}/mailFolders?$top=100&$select=${FOLDER_SELECT}`,});if (failed && folders.length === 0) {@@ -130,16 +132,74 @@ export const mailFolderIdDropdown = (params: DropdownParams) =>};}+ const tree = await folderTreeOptions({+ client,+ prefix,+ folders,+ parentPath: '',+ limit: MAX_FOLDERS,+ requestLimit: MAX_CHILD_FOLDER_REQUESTS,+ });return {disabled: false,- options: folders.map((folder) => ({- label: folder.displayName || 'Unnamed folder',- value: folder.id || '',- })),+ options: tree.options,+ placeholder: failed || tree.incomplete ? 'Not all folders could be loaded.' : undefined,};},});+async function folderTreeOptions({+ client,+ prefix,+ folders,+ parentPath,+ limit,+ requestLimit,+}: {+ client: Client;+ prefix: string;+ folders: MailFolder[];+ parentPath: string;+ limit: number;+ requestLimit: number;+}): Promise<FolderTree> {+ const options: FolderOption[] = [];+ let requests = 0;+ let incomplete = false;+ for (const [index, folder] of folders.entries()) {+ if (options.length >= limit) {+ return { options, requests, incomplete: true };+ }+ const label = `${parentPath}${folder.displayName || 'Unnamed folder'}`;+ options.push({ label, value: folder.id || '' });+ if (!folder.id || !folder.childFolderCount) {+ continue;+ }+ const subtreeLimit = limit - options.length - (folders.length - index - 1);+ if (requests >= requestLimit || subtreeLimit <= 0) {+ incomplete = true;+ continue;+ }+ requests++;+ const children = await fetchAllFolders({+ client,+ firstPageUrl: `${prefix}/mailFolders/${outlookAtomicCommon.encodeGraphId(folder.id)}/childFolders?$top=100&$select=${FOLDER_SELECT}`,+ });+ const subtree = await folderTreeOptions({+ client,+ prefix,+ folders: children.folders,+ parentPath: `${label} / `,+ limit: subtreeLimit,+ requestLimit: requestLimit - requests,+ });+ options.push(...subtree.options);+ requests += subtree.requests;+ incomplete = incomplete || children.failed || subtree.incomplete;+ }+ return { options, requests, incomplete };+}+async function fetchAllFolders({ client, firstPageUrl }: { client: Client; firstPageUrl: string }): Promise<FolderPages> {const folders: MailFolder[] = [];let nextLink: string | undefined = firstPageUrl;@@ -161,7 +221,22 @@ function draftLabel(message: Message): string {return firstRecipient ? `${subject} - to ${firstRecipient}` : subject;}+const FOLDER_SELECT = 'id,displayName,childFolderCount';+const MAX_FOLDERS = 2000;+const MAX_CHILD_FOLDER_REQUESTS = 100;+type FolderPages = {folders: MailFolder[];failed: boolean;};++type FolderTree = {+ options: FolderOption[];+ requests: number;+ incomplete: boolean;+};++type FolderOption = {+ label: string;+ value: string;+};