UNPKG

@pipedream/microsoft_outlook

Version:

Pipedream Microsoft Outlook Components

93 lines (89 loc) 3.61 kB
import microsoftOutlook from "../../microsoft_outlook.app.mjs"; export default { key: "microsoft_outlook-list-shared-folders", name: "List Shared Folders", description: "Retrieves mail folders from a shared or delegated mailbox. Returns each folder's `id`, `displayName`, `parentFolderId`, `childFolderCount`, `totalItemCount`, and `unreadItemCount`. **Use this action to resolve a shared mailbox folder display name to its ID** — set `Display Name` to filter by exact name. Use **Get Shared Folder** instead when you already have the folder ID. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders?view=graph-rest-1.0&tabs=http)", version: "0.0.2", type: "action", annotations: { destructiveHint: false, openWorldHint: true, readOnlyHint: true, }, props: { microsoftOutlook, userId: { propDefinition: [ microsoftOutlook, "userId", ], }, displayName: { type: "string", label: "Display Name", description: "Filter to folders whose display name exactly matches this value. Use this to resolve a known folder name to its ID. Applied server-side when `Include Subfolders` is `false`; applied client-side when `true`.", optional: true, }, maxResults: { propDefinition: [ microsoftOutlook, "maxResults", ], description: "Maximum number of folders to return (default: 100). For name-based lookups when the total folder count is unknown, raise this value or set `Include Subfolders` to `true`. Graph API maximum is 999 per page.", }, includeSubfolders: { type: "boolean", label: "Include Subfolders", description: "If `true`, recursively includes all subfolders at every nesting level. Set to `true` when searching for a folder by display name if you don't know whether it is a top-level folder. Default is `false`, which returns only top-level folders.", optional: true, default: false, }, includeHiddenFolders: { type: "boolean", label: "Include Hidden Folders", description: "If `true`, includes hidden system folders (e.g. `AllItems`, `RecoverableItemsDeletions`, `SearchFolders`, `Clutter`). Set to `true` only when specifically looking for a system or hidden folder. Default is `false`.", optional: true, default: false, }, }, async run({ $ }) { let folders = []; if (this.includeSubfolders) { folders = await this.microsoftOutlook.listSharedFolders({ userId: this.userId, params: { $top: 999, includeHiddenFolders: this.includeHiddenFolders, }, }); if (this.displayName) { folders = folders.filter(({ displayName }) => displayName === this.displayName); } if (folders.length > this.maxResults) { folders = folders.slice(0, this.maxResults); } } else { const items = this.microsoftOutlook.paginate({ fn: this.microsoftOutlook.listSharedFoldersPaged, args: { $, userId: this.userId, params: { ...(this.displayName && { $filter: `displayName eq '${this.displayName.replace(/'/g, "''")}'`, }), includeHiddenFolders: this.includeHiddenFolders, }, }, max: this.maxResults, }); for await (const item of items) { folders.push(item); } } $.export("$summary", `Successfully retrieved ${folders.length} folder${folders.length !== 1 ? "s" : ""}.`); return folders; }, };