Skip to content

Conversation

@AaronDDM
Copy link
Collaborator

What did you do?

replaced: form-data with form-data-node package for proper ESM support and edge worker support
fix: sending attachments >3MB via Buffer or Readable streams
added: new examples showing how to send attachments

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@codecov
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

❌ Patch coverage is 65.90909% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.87%. Comparing base (fd72d9d) to head (257e4ae).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/resources/messages.ts 53.33% 5 Missing and 2 partials ⚠️
src/utils.ts 75.00% 4 Missing and 2 partials ⚠️
src/apiClient.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main     #653       +/-   ##
=========================================
+ Coverage      0   94.87%   +94.87%     
=========================================
  Files         0       35       +35     
  Lines         0      781      +781     
  Branches      0       66       +66     
=========================================
+ Hits          0      741      +741     
- Misses        0       33       +33     
- Partials      0        7        +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…t and edge worker support

fix: sending attachments >3MB via Buffer or Readable streams
added: new examples showing how to send attachments
@playerzero-ai
Copy link

playerzero-ai bot commented Jul 18, 2025

Pull Request Summary

The pull request introduces several significant changes across various components of the project, focusing on enhancing functionality, compatibility, and user experience. Key changes include:

  • Testing Enhancements:

    • Updated Jest configuration to improve compatibility with TypeScript and ESM modules.
    • Improved mocking paths for apiClient in multiple test files to ensure accurate testing.
    • Introduced jest-fetch-mock for better control over fetch requests in tests.
    • Enhanced test utilities for handling form data and file-like objects.
  • New Examples and Functionalities:

    • Added examples for sending attachments using different methods (buffer, stream, file path, string) in the Nylas SDK.
    • Introduced a CLI interface for testing attachment methods, providing a more interactive experience.
    • Developed a Cloudflare Worker for sending email attachments, complete with a user-friendly HTML interface.
  • Code and Library Updates:

    • Replaced form-data with formdata-node for improved form data handling.
    • Updated TypeScript configurations for modern language features and better compatibility.
    • Refactored attachment handling functions to support various content types and improve efficiency.
  • Setup and Configuration:

    • Added a setup script for Nylas Cloudflare Worker, streamlining the development environment setup.
    • Configured Cloudflare Workers with environment variables for Nylas API integration.
  • Internal Testing and Quality Assurance:

    • Introduced functions for generating large test content to ensure system capability in handling large files.
    • Simplified and improved test reliability by ensuring correct module mocking and path resolutions.

Overall, these changes aim to enhance the project's testing capabilities, improve attachment handling, and provide a more robust and user-friendly experience for developers and end-users.

Functional Tests

  • Verify that attachments can be encoded to base64 correctly for Buffer, ReadableStream, and string content types.
  • Test the Cloudflare Worker interface for uploading and sending email attachments, ensuring file size and processing time limits are respected.
  • Ensure that the application can handle and send attachments using streams, buffers, file paths, and base64 strings.
  • Check that the TypeScript configuration updates do not break existing functionality and support modern features.
  • Validate that the CLI interfaces for testing attachment methods function correctly and provide expected outputs.
  • Test the handling of large files (over 3MB) to ensure they are processed and sent correctly.
  • Ensure that the new setup script for Cloudflare Workers correctly sets up the environment and dependencies.
  • Verify that the new file and attachment management system handles different formats and sizes as expected.
  • Check that the new CLI script for sending attachments via the Nylas SDK works as intended for all supported formats.
  • Test the new function for sending email attachments as base64 encoded strings for both large and small files.
  • Ensure that the removal of detailed Nylas API demonstration in folder listing does not impact folder listing functionality.

Files Changed

File Name Summary
jest.config.js Simplified module mapping to use TypeScript files directly; added support for .js imports in TS files; enabled ESM handling for .ts files; excluded certain modules from transform; configured jest-fetch-mock setup.
tests/resources/webhooks.spec.ts Fixed apiClient mock path to correct module location.
examples/edge-environment/wrangler.toml Added Cloudflare Workers project config with environment variables and resource limits for Nylas API integration.
examples/messages/examples/buffer-attachments.ts Added buffer-based attachment sending for small files with environment variable loading and timeout handling.
tests/resources/configurations.spec.ts Corrected apiClient mock path for reliable configuration tests.
tests/resources/credentials.spec.ts Fixed apiClient mock path; no functional changes.
tests/setupTests.ts Added jest-fetch-mock setup and enabled fetch mocking with TypeScript export.
examples/messages/examples/stream-attachments.ts Added stream-based attachment sending supporting large/small files with dynamic email content and timeout.
tests/resources/events.spec.ts Corrected apiClient mock path for accurate event tests.
tests/resources/drafts.spec.ts Fixed apiClient mock path; switched from form-data to formdata-node; improved mocks for FormData, Blob, File; enhanced draft attachment tests for file-like objects.
examples/edge-environment/tsconfig.json Updated TS config for ES2022 target, ESNext modules, Cloudflare types, strict mode, and bundler resolution.
examples/edge-environment/src/worker.ts Added Cloudflare Worker for uploading files and sending email attachments via Nylas SDK with UI, validation, and CORS handling.
examples/messages/examples/index.ts Created index exporting various attachment sending functions and types for easier reference.
src/utils.ts Switched to Node.js built-ins; added formdata-node support; added functions to convert streams to files and encode attachment content to base64; deprecated old encoding function.
tests/testUtils.ts Removed node-fetch import; simplified stream EOF handling; added MockFormData class for form data testing.
examples/messages/examples/flexible-attachments.ts Added flexible attachment sending function supporting different sizes and formats with dynamic email content and timeout.
src/resources/auth.ts Updated import of createHash to use node:crypto for compatibility.
src/resources/messages.ts Switched to formdata-node for FormData; replaced old encoding function; improved attachment handling for various content types.
tests/resources/bookings.spec.ts Fixed apiClient mock path for booking tests.
tests/resources/smartCompose.spec.ts Corrected apiClient mock path for smart compose tests.
tests/apiClient.spec.ts Removed node-fetch dependency; switched to jest-fetch-mock; standardized fetch mocking; improved timeout tests with ms conversion and backward compatibility.
examples/edge-environment/setup.sh Added setup script checking Node.js, npm, wrangler, dependencies, and environment variables for Cloudflare Worker development.
tests/resources/attachments.spec.ts Fixed apiClient mock path; no functional changes.
tests/resources/sessions.spec.ts Corrected apiClient mock path for session tests.
tests/resources/messages.spec.ts Fixed apiClient mock path; switched to formdata-node; enhanced Blob and File mocks; improved attachment tests for size-based handling.
tests/resources/redirectUris.spec.ts Fixed apiClient mock path for redirect URI tests.
examples/messages/utils/attachment-file-manager.ts Added file management system supporting multiple formats; classes for file handling and collections; methods for file status and attachment requests; backward-compatible helper function.
src/apiClient.ts Replaced node-fetch/externals.js with node:stream; switched to formdata-node and form-data-encoder; removed automatic form data headers; added error on missing response body in streams.
examples/messages/cli-interface.ts Added CLI for attachment examples with interactive prompts, file checks, commands for sending attachments, and error handling.
tests/utils.spec.ts Updated fs mocking to node:fs; added tests for new encoding functions supporting buffers, streams, and strings; verified backward compatibility.
src/resources/drafts.ts Replaced old attachment encoding function with new one in draft handling.
tests/resources/applications.spec.ts Fixed apiClient mock path for application tests.
examples/messages/send-attachments-cli.ts Added CLI script for sending attachments via various methods; includes file manager and environment variable loading.
examples/messages/examples/file-path-attachments.ts Added file path-based attachment sending supporting large and small files with dynamic email content and timeout.
test-file-size.js Added function to generate large text and JSON content (>3MB) for testing file size handling with detailed logging.
tests/resources/calendars.spec.ts Fixed apiClient mock path for calendar tests.
examples/messages/examples/string-attachments.ts Added base64 string attachment sending supporting large/small files with error handling and dynamic email content.
tests/resources/contacts.spec.ts Fixed apiClient mock path for contact tests.
examples/folders/folders.ts Removed detailed Nylas API folder listing demo; simplified to basic folder listing with Microsoft account support; removed SDK initialization and environment checks.

View more in PlayerZero
updated: Jul 19 @ 12:01 AM UTC

Copy link

@samuelpx samuelpx left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, big PR. Great!

@AaronDDM AaronDDM merged commit b3a9d87 into main Jul 31, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants