Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update new-email.mjs #15001

Merged
merged 14 commits into from
Jan 14, 2025
Merged

Update new-email.mjs #15001

merged 14 commits into from
Jan 14, 2025

Conversation

mchlbckr
Copy link
Contributor

@mchlbckr mchlbckr commented Dec 16, 2024

Allow for all folders in Outlook to be checked for new emails

WHY

Currently, the node only checks for new emails in the inbox folder. If by certain rules, an email is directly moved into a separate folder, it is ignored by the trigger.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced Microsoft Outlook email integration with ability to monitor specific email folders
    • Added folder selection option for email retrieval
  • Improvements

    • Updated email source to support more flexible message monitoring
    • Improved deduplication of email events
  • Version Updates

    • Microsoft Outlook component updated to version 0.0.10
    • Package version bumped to 1.0.4
  • Technical Updates

    • Added MD5 hashing for event deduplication

Allow for all folders in Outlook to be checked for new emails
Copy link

vercel bot commented Dec 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 14, 2025 5:24pm

Copy link

vercel bot commented Dec 16, 2024

@mchlbckr is attempting to deploy a commit to the Pipedreamers Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request primarily focuses on enhancing the Microsoft Outlook new email source component. The main changes involve adding a folderIds property to allow users to specify specific Outlook folders for monitoring new emails. The implementation includes methods to retrieve and filter email folders, update the event emission logic, and improve deduplication. The package version has been incremented, and an md5 dependency was added to support the new functionality.

Changes

File Change Summary
components/microsoft_outlook/sources/new-email/new-email.mjs - Added folderIds property with folder retrieval options
- Updated activate method resource scope
- Modified getSampleEvents, run, and emitEvent methods
- Added getFolderIdByName and listFolders methods
- Updated version and description
components/microsoft_outlook/package.json - Bumped package version to 1.0.4
- Added md5 dependency
Multiple .app.mjs files - Added newline at end of files (formatting)

Sequence Diagram

sequenceDiagram
    participant User
    participant Trigger
    participant MicrosoftGraph
    participant EmailFolders

    User->>Trigger: Configure folderIds
    Trigger->>MicrosoftGraph: List available folders
    MicrosoftGraph-->>Trigger: Return folder list
    Trigger->>EmailFolders: Retrieve messages from specified folders
    EmailFolders-->>Trigger: Return new email messages
    Trigger->>User: Emit new email events
Loading

Possibly related PRs

Suggested Labels

bug, docs

Poem

🐰 A Rabbit's Ode to Outlook's New Embrace 🐰

Folders dancing, emails in flight,
Pipedream's trigger shines so bright!
From inbox to corners once unseen,
Our code now dances, sleek and clean.
Hop along, new feature dear! 🚀📧


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ce88af and ef5bfc3.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • components/egnyte/egnyte.app.mjs (1 hunks)
  • components/mailboxlayer/mailboxlayer.app.mjs (1 hunks)
  • components/osu/osu.app.mjs (1 hunks)
  • components/uber_direct/uber_direct.app.mjs (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • components/egnyte/egnyte.app.mjs
  • components/mailboxlayer/mailboxlayer.app.mjs
  • components/osu/osu.app.mjs
  • components/uber_direct/uber_direct.app.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dylburger dylburger added the User submitted Submitted by a user label Dec 16, 2024
@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

Line range hint 45-54: Add error handling and implement deduplication strategy

The current implementation needs several improvements to align with Pipedream guidelines:

  1. Add error handling for getMessage API calls
  2. Implement deduplication strategy
  3. Enhance event summary with more details

Consider this implementation:

 async run(event) {
   await this.run({
     event,
     emitFn: async ({ resourceId } = {}) => {
-      const item = await this.microsoftOutlook.getMessage({
-        messageId: resourceId,
-      });
-      this.emitEvent(item);
+      try {
+        const item = await this.microsoftOutlook.getMessage({
+          messageId: resourceId,
+        });
+        
+        // Implement deduplication
+        const dedupKey = `${item.id}-${item.lastModifiedDateTime}`;
+        if (this.db.get(dedupKey)) {
+          return;
+        }
+        this.db.set(dedupKey, true);
+        
+        this.emitEvent(item);
+      } catch (error) {
+        console.error('Error fetching message:', error);
+        throw error;
+      }
     },
   });
 },

Also, enhance the event summary in generateMeta:

 generateMeta(item) {
   return {
     id: item.id,
-    summary: `New email (ID:${item.id})`,
+    summary: `New email from ${item.sender?.emailAddress?.address} - Subject: ${item.subject}`,
     ts: Date.parse(item.createdDateTime),
   };
 },
🧹 Nitpick comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

Line range hint 1-54: Add JSDoc documentation and configuration options

To fully comply with Pipedream guidelines, please add:

  1. JSDoc documentation for methods
  2. Optional configuration props for:
    • Folder filtering
    • Message age threshold
    • Update frequency

Example implementation:

props: {
  folders: {
    type: "string[]",
    label: "Folders to Monitor",
    description: "Leave empty to monitor all folders",
    optional: true,
  },
  maxMessageAge: {
    type: "integer",
    label: "Maximum Message Age (hours)",
    description: "Only process messages newer than this",
    default: 24,
    optional: true,
  },
},
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c2e2e9 and 0df6a1e.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

Line range hint 6-6: Consider bumping the version number.

The change in message fetching behavior is significant enough to warrant a version bump. Since this is a behavioral change that expands functionality without breaking existing behavior, consider incrementing the minor version (e.g., from 0.0.9 to 0.1.0).

-  version: "0.0.9",
+  version: "0.1.0",
🧹 Nitpick comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

Line range hint 4-4: Update component description to reflect the enhanced functionality.

The current description "Emit new event when an email received" should be updated to clarify that it monitors all folders, not just the inbox.

-  description: "Emit new event when an email received",
+  description: "Emit new event when an email is received in any folder",

Also applies to: 7-7

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c2e2e9 and 0df6a1e.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (1 hunks)
🔇 Additional comments (2)
components/microsoft_outlook/sources/new-email/new-email.mjs (2)

16-16: Verify the impact of querying all messages.

The change from /me/mailfolders('inbox')/messages to /me/messages will now fetch emails from all folders instead of just the inbox. While this aligns with the PR objective, please consider:

  1. Performance: Fetching from all folders might increase response time and API usage
  2. Rate Limiting: Verify if this broader scope might hit Microsoft Graph API rate limits sooner
  3. Duplicate Prevention: Ensure the webhook system properly handles messages that might be moved between folders

Let's verify the Microsoft Graph API documentation and rate limits:

✅ Verification successful

The change to query all messages is properly implemented with safeguards

The codebase analysis reveals that the implementation includes important safeguards for querying all messages:

  1. Pagination is implemented using $top parameter to limit the number of messages per request
  2. Messages are ordered by creation date ($orderby: "createdDateTime desc"), ensuring newest messages are processed first
  3. The change aligns with the existing app-level implementation which already supports the /me/messages endpoint

The broader scope of querying all folders should not cause performance or rate limiting issues due to these built-in controls. The webhook system will naturally handle message movements between folders as it operates on message IDs rather than folder locations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for related API endpoint usage and rate limiting information
# in the codebase

# Check for any existing rate limiting handling
rg -A 5 "rateLimitExceeded|429|TooManyRequests" ./components/microsoft_outlook/

# Look for related documentation or comments about message fetching
rg -l "\/me\/messages|\/mailfolders|Microsoft Graph API" ./components/microsoft_outlook/

Length of output: 287


Script:

#!/bin/bash
# Search for rate limiting handling with proper escaping
rg -A 5 "rateLimitExceeded|429|TooManyRequests" ./components/microsoft_outlook/

# Look for API endpoint usage with proper escaping
rg -A 5 "/me/messages|/me/mailfolders" ./components/microsoft_outlook/

# Check component documentation and readme
fd -e md . ./components/microsoft_outlook/ -x cat {}

# Look for error handling in the component
rg -A 5 "catch|error" ./components/microsoft_outlook/sources/new-email/

Length of output: 3529


Script:

#!/bin/bash
# Check for error handling and rate limiting in the app file
rg -A 10 "async _makeRequest|error handling|rate limit" ./components/microsoft_outlook/microsoft_outlook.app.mjs

# Look for pagination or batch processing
rg -A 5 "nextLink|page|batch|\$top|\$skip" ./components/microsoft_outlook/sources/new-email/

# Check if there are any filters applied to message retrieval
rg -A 5 "\$filter|\$select|\$orderby" ./components/microsoft_outlook/sources/new-email/

# Look for webhook subscription configuration
ast-grep --pattern 'createHook|createSubscription'

Length of output: 1373


Line range hint 28-34: Verify message listing parameters for the sample events.

The getSampleEvents method should be consistent with the new behavior. Verify if additional parameters are needed to properly represent messages from all folders.

✅ Verification successful

The getSampleEvents implementation is consistent with the source's behavior

The implementation of getSampleEvents is correctly aligned with the source's functionality:

  • It uses the same message listing endpoint as the webhook subscription (/me/messages)
  • The parameters ($top and $orderby) are appropriate for retrieving recent messages
  • No folder-specific filtering is needed as the source monitors all incoming messages across folders through the webhook subscription
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any folder-specific filtering in message listing

# Search for message listing parameters across the codebase
rg -A 5 "listMessages|\/messages\?" ./components/microsoft_outlook/

Length of output: 174


Script:

#!/bin/bash
# Search for message listing parameters across the codebase
rg -A 5 "listMessages|/messages\?" ./components/microsoft_outlook/

Length of output: 1112


Script:

#!/bin/bash
# Search for getSampleEvents implementations
ast-grep --pattern 'async getSampleEvents() {
  $$$
}'

Length of output: 56


Script:

#!/bin/bash
# Search for message listing related code
rg -A 5 "\$top|\$orderby|listMessages|/messages" ./components/microsoft_outlook/

Length of output: 3481


Script:

#!/bin/bash
# Search for getSampleEvents method with a more flexible pattern
ast-grep --pattern 'getSampleEvents() {
  $$$
}'

Length of output: 50


Script:

#!/bin/bash
# Search for any folder-related message filtering
rg -A 5 "folder|mailFolder" ./components/microsoft_outlook/

Length of output: 2179


Script:

#!/bin/bash
# Search for the entire new-email.mjs file content
cat ./components/microsoft_outlook/sources/new-email/new-email.mjs

Length of output: 1380

@GTFalcao
Copy link
Collaborator

Hi @mchlbckr , thanks for your contribution!

The version number needs to be incremented both in the component being changed, and the package.json of the app.

Also, perhaps this behavior should be controlled by an optional boolean prop - defaulting to false (keeping the existing behavior), thus giving users the option to enable if desired. What do you think?

@mchlbckr
Copy link
Contributor Author

@GTFalcao Thanks for reviewing! Yes, I think either a boolean option would be better or an option to specify all folders that should be screened. Should I make a proposal for this?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0df6a1e and 2b87190.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (3 hunks)
🧰 Additional context used
🪛 eslint
components/microsoft_outlook/sources/new-email/new-email.mjs

[error] 37-37: A linebreak is required after '['.

(array-bracket-newline)


[error] 37-37: A linebreak is required before ']'.

(array-bracket-newline)


[error] 54-54: Expected a line break after this opening brace.

(object-curly-newline)


[error] 54-54: Expected a line break before this closing brace.

(object-curly-newline)


[error] 55-56: Missing trailing comma.

(comma-dangle)


[error] 69-69: A linebreak is required after '['.

(array-bracket-newline)


[error] 69-69: A linebreak is required before ']'.

(array-bracket-newline)

🔇 Additional comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

8-9: Consider version bump for breaking change

Changing from inbox-only to all-folders monitoring is a breaking change that could affect existing implementations. Consider bumping the major version number instead of a minor version bump.

@mchlbckr
Copy link
Contributor Author

Hey @GTFalcao @pipedream-component-development Do you have any update on this issue? Thanks!

@GTFalcao
Copy link
Collaborator

GTFalcao commented Jan 4, 2025

Hey @mchlbckr thanks for updating this, I saw your commit after we talked about the optional prop - looks good to me! I'm moving this forward to the QA stage

@vunguyenhung
Copy link
Collaborator

Hello everyone, I have tested this PR and there're some test cases failed or needed improvement.

Please check the test report below for more information
https://vunguyenhung.notion.site/Update-new-email-mjs-171bf548bb5e812dbe1adb3b652e3c76

@vunguyenhung
Copy link
Collaborator

Hello everyone, I have tested this PR and there're some test cases failed or needed improvement.

Please check the test report below for more information
https://vunguyenhung.notion.site/Update-new-email-mjs-171bf548bb5e812dbe1adb3b652e3c76

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
components/microsoft_outlook/sources/new-email/new-email.mjs (3)

34-36: Remove debugging console.log statement

Remove the console.log statement that was likely used for debugging purposes.

 const events = await this.getSampleEvents({
   pageSize: 25,
-}); console.log(events);
+});

86-93: Optimize folder filtering logic

Consider caching the sentItemFolderId check result and using early returns for better readability:

 isRelevant(item) {
-  if (this.folderIds?.length) {
-    return true;
-  }
-  // if no folderIds are specified, filter out items in Sent Items
-  const sentItemFolderId = this.db.get("sentItemFolderId");
-  return item.parentFolderId !== sentItemFolderId;
+  // If specific folders are selected, all items are relevant
+  if (this.folderIds?.length) return true;
+  
+  // Cache sentItemFolderId for the instance
+  this._sentItemFolderId = this._sentItemFolderId || this.db.get("sentItemFolderId");
+  
+  // Filter out items in Sent Items folder
+  return item.parentFolderId !== this._sentItemFolderId;
 }

11-28: Add monitoring controls to prevent API throttling

Consider adding additional properties to control the monitoring behavior:

  1. Rate limiting controls
  2. Maximum folders to monitor
  3. Message age threshold
  4. Batch size controls

This will help prevent API throttling and manage resource usage, especially important now that the component can monitor multiple folders.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9907c1b and 8d8ef41.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (3 hunks)
🔇 Additional comments (5)
components/microsoft_outlook/sources/new-email/new-email.mjs (5)

8-9: Consider major version bump for breaking change

The change from inbox-only to all-folders monitoring is a breaking change that could affect existing implementations. Consider bumping the major version number instead of a minor version bump.


13-27: Add validation for folder IDs

While the property is well-documented, consider adding input validation to ensure folder IDs match the expected format and exist in the user's Outlook account.


46-48: Add error handling for subscription creation

The activate hook should include error handling for subscription creation failures, especially important now that it's monitoring all messages.


66-85: Improve result handling in getSampleEvents

The current implementation has several potential issues:

  1. Results from different folders aren't sorted by creation time
  2. No deduplication of messages that might appear in multiple folders
  3. Potential memory issues when aggregating results from many folders

113-134: Improve performance and reliability of the run method

The current implementation processes folders sequentially without rate limiting or retry logic for transient failures.

@vunguyenhung
Copy link
Collaborator

Hello everyone, I have tested this PR and there're some test cases failed or needed improvement.

Please check the test report below for more information
https://vunguyenhung.notion.site/Update-new-email-mjs-171bf548bb5e812dbe1adb3b652e3c76

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (3)
components/microsoft_outlook/sources/new-email/new-email.mjs (3)

2-2: ⚠️ Potential issue

Consider a major version bump for breaking changes

The change from inbox-only to all-folders monitoring is a breaking change that could affect existing implementations. Consider bumping the major version number instead of a minor version increment.

Also applies to: 9-10


48-51: 🛠️ Refactor suggestion

Add error handling for subscription creation

The subscription creation in the activate hook should include error handling to prevent silent failures.


69-88: 🛠️ Refactor suggestion

Improve result handling in getSampleEvents

Current implementation has several potential issues:

  1. Results from different folders aren't sorted by creation time
  2. No deduplication of messages that might appear in multiple folders
  3. Potential memory issues when aggregating results from many folders
🧹 Nitpick comments (1)
components/microsoft_outlook/sources/new-email/new-email.mjs (1)

89-97: Add logging for filtered messages

Consider adding debug logging when messages are filtered out. This would help users understand why certain messages aren't being processed.

 isRelevant(item) {
   if (this.folderIds?.length) {
-    return this.folderIds.includes(item.parentFolderId);
+    const isRelevant = this.folderIds.includes(item.parentFolderId);
+    if (!isRelevant) {
+      console.debug(`Skipping message ${item.id} - folder ${item.parentFolderId} not in monitored folders`);
+    }
+    return isRelevant;
   }
   // if no folderIds are specified, filter out items in Sent Items & Drafts
   const sentItemFolderId = this.db.get("sentItemFolderId");
   const draftsFolderId = this.db.get("draftsFolderId");
-  return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
+  const isRelevant = item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
+  if (!isRelevant) {
+    console.debug(`Skipping message ${item.id} - in excluded folder ${item.parentFolderId}`);
+  }
+  return isRelevant;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e90d57e and 930f554.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/microsoft_outlook/package.json (2 hunks)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/microsoft_outlook/package.json
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (2)
components/microsoft_outlook/sources/new-email/new-email.mjs (2)

15-29: Add validation and controls for folder monitoring

The folderIds property implementation could benefit from:

  1. Input validation for folder IDs
  2. Rate limiting controls
  3. Pagination settings for large folder structures

118-139: Enhance performance and reliability of the run method

Consider improving the implementation with:

  1. Concurrent processing with rate limiting
  2. Consistent error handling across all API calls
  3. Retry logic for transient failures

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
components/microsoft_outlook/sources/new-email/new-email.mjs (2)

20-28: Add error handling and caching for folder options

The async options method could fail silently and doesn't implement caching. Consider:

  1. Adding error handling
  2. Implementing caching to prevent repeated API calls
async options() {
+  try {
+    // Cache folder list for 5 minutes
+    const cacheKey = "folderOptions";
+    const cached = this.db.get(cacheKey);
+    if (cached && Date.now() - cached.timestamp < 300000) {
+      return cached.options;
+    }
+
     const { value: folders } = await this.listFolders();
-    return folders?.map(({
+    const options = folders?.map(({
       id: value, displayName: label,
     }) => ({
       value,
       label,
     })) || [];
+    
+    this.db.set(cacheKey, {
+      timestamp: Date.now(),
+      options,
+    });
+    
+    return options;
+  } catch (error) {
+    console.error("Failed to fetch folder options:", error);
+    return [];
+  }
}

89-97: Add error handling for folder ID checks

The isRelevant method should handle cases where folder IDs might be undefined or invalid.

isRelevant(item) {
+  if (!item?.parentFolderId) {
+    console.warn("Received item without parentFolderId:", item);
+    return false;
+  }
+
   if (this.folderIds?.length) {
     return this.folderIds.includes(item.parentFolderId);
   }
   
   // if no folderIds are specified, filter out items in Sent Items & Drafts
   const sentItemFolderId = this.db.get("sentItemFolderId");
   const draftsFolderId = this.db.get("draftsFolderId");
+  
+  if (!sentItemFolderId || !draftsFolderId) {
+    console.warn("Missing system folder IDs, skipping filter");
+    return true;
+  }
   
   return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 930f554 and 8ce88af.

📒 Files selected for processing (1)
  • components/microsoft_outlook/sources/new-email/new-email.mjs (2 hunks)
🔇 Additional comments (4)
components/microsoft_outlook/sources/new-email/new-email.mjs (4)

9-11: Consider major version bump for breaking changes

The change from inbox-only to all-folders monitoring is a breaking change that could affect existing implementations. Consider bumping the major version number instead of a minor version increment.


69-88: Improve result handling in getSampleEvents

The current implementation has several potential issues:

  1. Results from different folders aren't sorted by creation time
  2. No deduplication of messages that might appear in multiple folders
  3. Potential memory issues when aggregating results from many folders

116-139: Improve performance and reliability of the run method

The current implementation processes folders sequentially without rate limiting.


Line range hint 1-142: Add comprehensive testing and documentation

While the implementation is solid, please consider:

  1. Adding unit tests for the new folder selection functionality
  2. Documenting rate limits and performance implications
  3. Adding examples in the component's documentation

Run this script to check for existing tests and documentation:

@vunguyenhung
Copy link
Collaborator

Hi everyone, all test cases are passed! Ready for release!

Test report
https://vunguyenhung.notion.site/Update-new-email-mjs-171bf548bb5e812dbe1adb3b652e3c76

@michelle0927 michelle0927 merged commit 4705140 into PipedreamHQ:master Jan 14, 2025
10 of 11 checks passed
@mchlbckr
Copy link
Contributor Author

I think this still does not work. At least I just tested it and there is an error:

025-01-15T11:39:05
error
TypeError: Cannot destructure property 'id' of 'folders.find(...)' as it is undefined.
at Object.getFolderIdByName (file:///var/task/user/sources/new-email/new-email.mjs:66:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.deploy (file:///var/task/user/sources/new-email/new-email.mjs:34:39)
at async /var/task/index.js:95:13
at async captureObservations (/var/task/node_modules/@lambda-v2/component-runtime/src/captureObservations.js:28:5)
at async exports.main [as handler] (/var/task/index.js:60:20)

image

@michelle0927
Copy link
Collaborator

I think this still does not work. At least I just tested it and there is an error:

025-01-15T11:39:05
error
TypeError: Cannot destructure property 'id' of 'folders.find(...)' as it is undefined.
at Object.getFolderIdByName (file:///var/task/user/sources/new-email/new-email.mjs:66:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.deploy (file:///var/task/user/sources/new-email/new-email.mjs:34:39)
at async /var/task/index.js:95:13
at async captureObservations (/var/task/node_modules/@lambda-v2/component-runtime/src/captureObservations.js:28:5)
at async exports.main [as handler] (/var/task/index.js:60:20)

Hi @mchlbckr , I created a New PR that should fix the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User submitted Submitted by a user
Development

Successfully merging this pull request may close these issues.

6 participants