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

feat: export delimited zip #680

Merged
merged 15 commits into from
Oct 31, 2024
Merged

feat: export delimited zip #680

merged 15 commits into from
Oct 31, 2024

Conversation

carlbrugger
Copy link
Contributor

Please explain how to summarize this PR for the Changelog:

Tell code reviewer how and what to test:

@flatfile-nullify
Copy link

flatfile-nullify bot commented Oct 23, 2024

Nullify Code Vulnerabilities

8 findings found in this pull request

🔴 CRITICAL 🟡 HIGH 🔵 MEDIUM ⚪ LOW
0 0 8 0

You can find a list of all findings here

@carlbrugger carlbrugger marked this pull request as ready for review October 30, 2024 20:09
Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request introduces several new files and configurations for the @flatfile/plugin-export-delimited-zip plugin, which facilitates exporting data from Flatfile sheets into delimited files and compressing them into ZIP format. Key additions include comprehensive documentation, Jest configuration for testing, and a TypeScript plugin that manages the export process. Additionally, modifications to an existing index.ts file streamline the integration of this new functionality into a listener's middleware, simplifying workbook and sheet configurations.

Changes

File Path Change Summary
export/delimited-zip/README.MD New documentation for the @flatfile/plugin-export-delimited-zip plugin, detailing its usage and API calls.
export/delimited-zip/jest.config.js New Jest configuration for testing, specifying TypeScript support and custom setup scripts.
export/delimited-zip/src/export.delimited.zip.plugin.ts New plugin file that defines PluginOptions interface and exportDelimitedZip function for exporting data.
export/delimited-zip/src/index.ts Export statement added to re-export all entities from the export.delimited.zip.plugin module.
export/delimited-zip/tsup.config.mjs New bundler configuration specifying not to include browser-specific code.
export/pivot-table/jest.config.js New Jest configuration for testing in a Node.js environment with TypeScript support.
flatfilers/sandbox/src/index.ts Updated to an asynchronous function, integrating exportDelimitedZip and simplifying workbook configuration.

Possibly related PRs

  • feat: export-workbook refactor #512: The changes in the @flatfile/plugin-export-workbook plugin may relate to the main PR as both involve exporting functionalities, although the main PR focuses on the @flatfile/plugin-export-delimited-zip specifically.
  • importer: rss feed #641: The introduction of the rssImport functionality may have overlapping concerns with the export functionality in the main PR, especially if it involves data handling or processing that could be relevant to the export process.
  • exporter: pivot table report generator #642: The introduction of the @flatfile/plugin-export-pivot-table could relate to the export functionality in the main PR, as both involve exporting data in different formats.
  • fix: async issue #674: This PR addresses async issues in the @flatfile/plugin-delimiter-extractor, which may impact the export process if the delimiter extraction is part of the data preparation for export.
  • fix: async/await bug #685: This PR focuses on fixing async/await bugs across multiple plugins, including those related to data handling, which could affect the export functionality in the main PR.
  • fixes dataRowAndSubHeaderDetection algorithm #687: This PR addresses improvements to the header detection algorithm, which is relevant to the export process as it may influence how data is structured and exported in the main PR.

Suggested reviewers

  • bangarang

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0b85535 and 7c3604e.

📒 Files selected for processing (1)
  • export/delimited-zip/src/export.delimited.zip.plugin.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • export/delimited-zip/src/export.delimited.zip.plugin.ts

🪧 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 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.

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

🧹 Outside diff range and nitpick comments (4)
export/delimited-zip/README.MD (4)

5-6: Add context for the event type trigger.

Consider adding a brief explanation of when the job:ready event is triggered and how it relates to the export process. This would help developers better understand the plugin's lifecycle.

 **Event Type:** 
-`job:ready`
+`job:ready` - Triggered when an export job is initiated through the Flatfile platform

17-27: Enhance parameter documentation with examples and constraints.

Consider adding:

  1. Example values for each parameter
  2. Validation constraints (e.g., allowed delimiters)
  3. Common use cases for different file extensions
 #### `delimiter` - `string`
-The delimiter to use in the exported files. Default: ','
+The delimiter to use in the exported files. Default: ','. Common values: ',', '|', ';', '\t'

 #### `fileExtension` - `string`
-The file extension for the exported files. Default: 'csv'
+The file extension for the exported files. Default: 'csv'. Supported values: 'csv', 'tsv', 'txt'
🧰 Tools
🪛 Markdownlint

17-17: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


31-38: Add context for API endpoint usage.

Consider documenting how each API endpoint is used in the export process to help developers understand the plugin's workflow.

 ## API Calls
 
-api.jobs.ack
-api.jobs.complete
-api.jobs.fail
-api.sheets.list
-api.records.get
-api.files.upload
+- `api.jobs.ack` - Acknowledges the export job has started
+- `api.jobs.complete` - Marks the export job as successfully completed
+- `api.jobs.fail` - Handles export job failures
+- `api.sheets.list` - Retrieves all sheets from the workbook for export
+- `api.records.get` - Fetches records from each sheet
+- `api.files.upload` - Uploads the generated ZIP file

49-61: Expand usage documentation with advanced examples.

Consider adding:

  1. Error handling examples
  2. Advanced configuration scenarios
  3. Event handling examples for monitoring export progress
// Add examples like:
listener.use(exportDelimitedZip({
  job: 'export-delimited-zip',
  delimiter: ',',
  fileExtension: 'csv',
  debug: true,
  // Add error handling
  onError: (error) => {
    console.error('Export failed:', error);
  },
  // Add progress tracking
  onProgress: (progress) => {
    console.log(`Export progress: ${progress}%`);
  }
}))
🧰 Tools
🪛 Markdownlint

49-49: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3c02db1 and 168d43a.

⛔ Files ignored due to path filters (2)
  • export/delimited-zip/package.json is excluded by !**/*.json
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
📒 Files selected for processing (7)
  • export/delimited-zip/README.MD (1 hunks)
  • export/delimited-zip/jest.config.js (1 hunks)
  • export/delimited-zip/src/export.delimited.zip.plugin.ts (1 hunks)
  • export/delimited-zip/src/index.ts (1 hunks)
  • export/delimited-zip/tsup.config.mjs (1 hunks)
  • export/pivot-table/jest.config.js (1 hunks)
  • flatfilers/sandbox/src/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • export/delimited-zip/jest.config.js
  • export/delimited-zip/src/index.ts
  • export/delimited-zip/tsup.config.mjs
  • export/pivot-table/jest.config.js
🧰 Additional context used
🪛 Markdownlint
export/delimited-zip/README.MD

17-17: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


44-44: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


49-49: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (7)
flatfilers/sandbox/src/index.ts (5)

2-3: Import Statements: Verify the Necessity and Order

The import statements include exportDelimitedZip and configureSpace from their respective packages. Ensure that these imports are necessary and properly used in the code below. Additionally, consider organizing the import statements for better readability if the project coding standards require it.


5-5: Async Function Declaration

The default exported function is now declared as async. If there are no await expressions inside this function, the async keyword might be unnecessary. Please verify whether await is used within this function or any of its callbacks.

If await is not used, consider removing the async keyword:

-export default async function (listener: FlatfileListener) {
+export default function (listener: FlatfileListener) {

6-13: Middleware Usage of exportDelimitedZip

The exportDelimitedZip middleware is configured with specific options. Verify that:

  • The job name 'export-delimited-zip' matches the operation defined in the action configuration.
  • The delimiter, fileExtension, and debug options are correctly set according to the desired export format.
  • The middleware is correctly integrated into the listener.

15-112: Sheet and Action Configurations

The sheets Sales and Sales 2 are configured with fields and actions. Consider the following:

  • Field Definitions: Ensure that all required fields are included and that their key, type, and label properties are correctly defined.
  • Action Operations: Confirm that the operations 'generateExampleRecords' and 'export-external-api' are implemented elsewhere in the codebase.
  • Action Modes: Both actions are set to 'foreground'. Verify that this is the intended mode of operation.

You might want to check if the actions' operation values correspond to actual listener implementations. If they are not yet implemented, consider adding placeholders or implementations to prevent runtime errors.


105-109: Association of Workbook Action with Middleware

The workbook action is configured with the operation 'export-delimited-zip'. Ensure that this action correctly triggers the exportDelimitedZip middleware configured earlier.

Confirm that the job name in the middleware configuration matches the operation name in the action:

 listener.use(
   exportDelimitedZip({
-    job: 'export-delimited-zip',
+    job: 'export-delimited-zip', // Should match the action's operation name
     delimiter: '\t',
     fileExtension: 'tsv',
     debug: true,
   })
 )

This alignment is crucial for the middleware to respond to the correct action.

export/delimited-zip/src/export.delimited.zip.plugin.ts (2)

190-192: 🛠️ Refactor suggestion

Include Original Error Message for Improved Debugging

The error thrown provides a generic message, which may hinder debugging efforts. Including the original error message can help identify the root cause more efficiently.

Modify the error handling to incorporate the original error message:

throw new Error(
-   `This job failed probably because it couldn't write to the ${options.fileExtension.toUpperCase()} files, compress them into a ZIP file, or upload it.`
+   `Job failed due to an error: ${error.message}. This may be caused by issues writing to the ${options.fileExtension.toUpperCase()} files, compressing them into a ZIP file, or uploading it.`
)

Likely invalid or redundant comment.


149-162: ⚠️ Potential issue

Use Consistent Sheet References During Cleanup

In the cleanup section, you're iterating over workbook.sheets, but earlier you retrieved sheets using api.sheets.list, stored in the sheets variable. There may be a discrepancy if workbook.sheets is undefined or doesn't match the sheets list.

Update the loop to use the sheets variable for consistency:

- for (const sheet of workbook.sheets) {
+ for (const sheet of sheets) {

Likely invalid or redundant comment.

export/delimited-zip/README.MD Show resolved Hide resolved
export/delimited-zip/src/export.delimited.zip.plugin.ts Outdated Show resolved Hide resolved
export/delimited-zip/src/export.delimited.zip.plugin.ts Outdated Show resolved Hide resolved
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 and nitpick comments (4)
.changeset/lemon-bears-drive.md (1)

9-11: Enhance the changeset description with more details.

The current description could be more comprehensive. Consider adding:

  • Plugin configuration options and parameters
  • API calls for managing the export job lifecycle
  • Integration instructions
  • Any breaking changes or dependencies

Here's a suggested structure:

This release introduces the @flatfile/plugin-export-delimited-zip plugin, which:
- Exports Workbook Sheets as CSV files in a ZIP format
- Provides configuration options for customizing the export process
- Includes API calls for managing the export job lifecycle
- Integrates at the Workbook level via [integration details]

Additional updates include documentation improvements for [specific areas].

Configuration options:
[List key configuration parameters]

Usage:
[Basic usage example]
export/delimited-zip/README.MD (3)

1-12: Enhance the info card section readability.

Consider these minor improvements to make the documentation more consistent and prominent:

 <!-- START_INFOCARD -->

 The `@flatfile/plugin-export-delimited-zip` plugin exports data from Flatfile sheets to delimited files (e.g., CSV) and compresses them into a ZIP file. This plugin provides an efficient way to download and package your data from Flatfile workbooks.

-**Event Type:** 
-`job:ready`
+**Event Type:** `job:ready`

 <!-- END_INFOCARD -->

-
-> ⚠️ **Important:** When embedding Flatfile, this plugin should be deployed in a server-side listener. [Learn more](/docs/orchestration/listeners#listener-types)

31-39: Enhance API calls documentation.

Consider adding brief descriptions for each API call to explain their role in the export process. This would help developers understand the plugin's workflow better.

 ## API Calls

-api.jobs.ack
-api.jobs.complete
-api.jobs.fail
-api.sheets.list
-api.records.get
-api.files.upload
+- `api.jobs.ack` - Acknowledges the export job has started
+- `api.jobs.complete` - Marks the export job as successfully completed
+- `api.jobs.fail` - Handles export job failures
+- `api.sheets.list` - Retrieves the list of sheets to be exported
+- `api.records.get` - Fetches the records from each sheet
+- `api.files.upload` - Uploads the generated ZIP file

50-61: Enhance the code example with comments.

The example would be more helpful with additional comments explaining the configuration options.

 **listener.ts**
 ```typescript
 import type { FlatfileListener } from '@flatfile/listener'
 import { exportDelimitedZip } from '@flatfile/plugin-export-delimited-zip'

 export default function (listener: FlatfileListener) {
   listener.use(exportDelimitedZip({
+    // The job name that triggers this export
     job: 'export-delimited-zip',
+    // Character used to separate values in the output file
     delimiter: ',',
+    // Output file extension (e.g., 'csv', 'tsv')
     fileExtension: 'csv',
   }))
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 168d43a and b4c5b7e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
📒 Files selected for processing (5)
  • .changeset/lemon-bears-drive.md (1 hunks)
  • bundlers/rollup-config/index.mjs (1 hunks)
  • export/delimited-zip/README.MD (1 hunks)
  • plugins/record-hook/rollup.config.mjs (0 hunks)
  • plugins/rollout/README.md (1 hunks)
💤 Files with no reviewable changes (1)
  • plugins/record-hook/rollup.config.mjs
🧰 Additional context used
🪛 Markdownlint
export/delimited-zip/README.MD

17-17: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


44-44: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


49-49: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (5)
.changeset/lemon-bears-drive.md (1)

1-7: Please clarify the version bumps for other packages.

While the bump for @flatfile/plugin-export-delimited-zip is clear, could you explain why the following packages require version bumps?

  • @flatfile/bundler-config-rollup
  • @flatfile/plugin-record-hook
  • @flatfile/plugin-export-pivot-table
  • @flatfile/plugin-rollout
✅ Verification successful

Let me try another verification strategy to check for changes in these packages by looking at the full git diff and package dependencies.


Let me check for any changes in the source files of these packages by looking at the git diff.


Let me try another approach to check for changes by looking at the full git diff and any new files.


Based on the findings, I can now generate a final response:

Version bumps appear to be justified by new package and dependency updates

The version bumps are warranted for the following reasons:

  • @flatfile/plugin-export-delimited-zip: New plugin being introduced with initial implementation
  • @flatfile/plugin-export-pivot-table: Has existing implementation with CHANGELOG indicating updates
  • @flatfile/plugin-record-hook: Core dependency used by multiple packages including the new delimited-zip plugin
  • @flatfile/plugin-rollout: Has existing implementation with CHANGELOG
  • @flatfile/bundler-config-rollup: Build tooling dependency that may require updates to support new plugins
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for related changes in other packages
# Expected: Find changes that justify version bumps

echo "Checking for changes in related packages..."
for pkg in "bundler-config-rollup" "plugin-record-hook" "plugin-export-pivot-table" "plugin-rollout"; do
  echo "Changes in @flatfile/$pkg:"
  git diff --name-only | grep -i "$pkg" || echo "No changes found"
done

Length of output: 1270


Script:

#!/bin/bash
# Get the full git diff to see all changes
git diff

# Also check package dependencies
echo "Checking package.json files..."
fd package.json --exec cat {} \; 

Length of output: 116424


Script:

#!/bin/bash
# Get the git diff for the specific packages mentioned in the changeset
git diff HEAD -- \
  "export/delimited-zip" \
  "plugins/record-hook" \
  "export/pivot-table" \
  "plugins/rollout" \
  "bundlers/rollup"

Length of output: 110


Script:

#!/bin/bash
# Check for any new files in these directories
echo "Checking for new files..."
fd . "export/delimited-zip" "plugins/record-hook" "export/pivot-table" "plugins/rollout" "bundlers/rollup"

# Get the full git status to see changes
echo -e "\nChecking git status..."
git status

Length of output: 1879

plugins/rollout/README.md (1)

17-17: LGTM! Clear and important deployment guidance.

The added note effectively communicates the deployment requirement and enhances the documentation.

export/delimited-zip/README.MD (1)

1-61: Documentation structure and content look good!

The README provides a clear and comprehensive guide for using the export-delimited-zip plugin. The structure is logical, and the content covers all essential aspects of the plugin's functionality.

🧰 Tools
🪛 Markdownlint

17-17: Expected: h3; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


44-44: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


49-49: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

bundlers/rollup-config/index.mjs (2)

44-46: LGTM: Added validation for UMD configuration

Good addition of validation to ensure UMD builds have the required name configuration. The error message is clear and helpful.


38-41: ⚠️ Breaking Change: Default build configuration has been modified

The default values for build types have been significantly changed:

  • includeNode: true → false
  • includeBrowser: true → false
  • includeDefinition: true → false
  • includeUmd: false → true

This change will affect any projects that rely on the default configuration. Ensure this breaking change is properly documented and communicated to users.

plugins/rollout/README.md Show resolved Hide resolved
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: 3

🧹 Outside diff range and nitpick comments (2)
export/delimited-zip/src/export.delimited.zip.plugin.ts (2)

61-61: Reconsider limiting sheet names to 31 characters.

Limiting sheet names to 31 characters might truncate important information. Consider increasing the limit or handling longer names gracefully.


123-124: Consider increasing the pageSize for record processing.

The pageSize is set to 5, which may lead to a high number of API calls for large datasets. Increasing the pageSize can improve performance by reducing the number of calls.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b4c5b7e and 0b85535.

📒 Files selected for processing (5)
  • .changeset/lemon-bears-drive.md (1 hunks)
  • export/delimited-zip/src/export.delimited.zip.plugin.ts (1 hunks)
  • plugins/dedupe/README.md (1 hunks)
  • plugins/delimiter-extractor/README.md (1 hunks)
  • plugins/export-workbook/README.md (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • plugins/dedupe/README.md
  • plugins/delimiter-extractor/README.md
  • plugins/export-workbook/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/lemon-bears-drive.md
🧰 Additional context used
🪛 Biome
export/delimited-zip/src/export.delimited.zip.plugin.ts

[error] 41-41: Unexpected control character in a regular expression.

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)


[error] 41-41: Unexpected control character in a regular expression.

Control characters are unusual and potentially incorrect inputs, so they are disallowed.

(lint/suspicious/noControlCharactersInRegex)

🔇 Additional comments (1)
export/delimited-zip/src/export.delimited.zip.plugin.ts (1)

93-94: Potential issue with accessing undefined record values.

@carlbrugger carlbrugger merged commit c55a4e3 into main Oct 31, 2024
37 checks passed
@carlbrugger carlbrugger deleted the feat/export-delimited-zip branch October 31, 2024 17:02
This was referenced Nov 13, 2024
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.

2 participants