-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - pdforge #16722
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
New Components - pdforge #16722
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis update introduces a new integration for pdforge, providing two actions: generating PDFs from HTML or from templates. It includes a reusable action base, utility functions, and a fully implemented app definition with authentication, S3, webhook support, and both synchronous and asynchronous API flows. Package dependencies and metadata are also updated. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Action (generate-pdf)
participant pdforge.app
participant pdforge API
participant S3 (optional)
participant Webhook (optional)
User->>Action (generate-pdf): Provide input (HTML/template, options)
Action (generate-pdf)->>pdforge.app: Call generatePDFfromHTML or generateDocumentFromTemplate
pdforge.app->>pdforge API: POST request (sync/async based on webhook)
alt Async (webhook provided)
pdforge API-->>Webhook: Notify completion
Action (generate-pdf)-->>User: Return async summary
else Sync
pdforge API-->>pdforge.app: Return file URL or S3 info
alt Save to S3
pdforge API-->>S3: Store file
Action (generate-pdf)-->>User: Return S3 details
else Download file
pdforge.app->>Action (generate-pdf): Provide file URL
Action (generate-pdf)->>User: Return file path and summary
end
end
Assessment against linked issues
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
components/pdforge/actions/common/base.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/pdforge/actions/generate-pdf-from-html/generate-pdf-from-html.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/pdforge/actions/generate-pdf-from-template/generate-pdf-from-template.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Actions - Generate PDF From HTML - Generate PDF From TEMPLATE
There was a problem hiding this 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 (7)
components/pdforge/common/utils.mjs (1)
33-48: Optimize clearObj function to avoid O(n²) complexityThe spread syntax in the accumulator of
reduce()can lead to O(n²) time complexity for large objects, as flagged by static analysis.Consider refactoring to avoid the spread operator on the accumulator:
export const clearObj = (obj) => { return Object.entries(obj) .filter(([, v]) => (v != null && v != "" && JSON.stringify(v) != "{}")) .reduce((acc, [k, v]) => { - return { - ...acc, - [k]: (!Array.isArray(v) && v === Object(v)) - ? clearObj(v) - : v, - }; + acc[k] = (!Array.isArray(v) && v === Object(v)) + ? clearObj(v) + : v; + return acc; }, {}); };🧰 Tools
🪛 Biome (1.9.4)
[error] 43-43: Avoid the use of spread (
...) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce) because it causes a time complexity ofO(n^2).
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
components/pdforge/actions/common/base.mjs (1)
79-92: Remove redundant webhook assignmentThe webhook property is being set twice (once in the initial data object and again in the asyncMode condition).
const data = { ...this.getAdditionalData(), convertToImage: this.convertToImage, webhook: this.webhook, }; if (this.saveS3) { data.s3Bucked = this.s3Bucked; data.s3Key = this.s3Key; } if (this.asyncMode) { - data.webhook = this.webhook; }components/pdforge/actions/generate-pdf-from-html/generate-pdf-from-html.mjs (2)
8-8: Consider adding more details to documentation linkThe documentation link is helpful, but it would be more user-friendly to specify what information can be found there (e.g., "See the documentation for API details and examples").
35-39: Improve success message with file detailsThe success message is clear but could be enhanced by including more details about the generated file, such as file name or size if available from the response.
getSummary({ convertToImage }) { return `${convertToImage ? "PNG" : "PDF"} successfully generated from provided HTML content.`; },components/pdforge/pdforge.app.mjs (3)
21-21: Fix typo in descriptionThere's a typo in the fileName description: "direcrtory" should be "directory".
- description: "The filename without extension for saving the file in the `/tmp` direcrtory", + description: "The filename without extension for saving the file in the `/tmp` directory",
6-27: Add validation for URL and file propertiesConsider adding validation for the webhook URL format and potentially for S3 bucket naming patterns to prevent runtime errors.
For the webhook property, you could add:
webhook: { type: "string", label: "Webhook URL", description: "The URL of your webhook endpoint", + pattern: "^https?://.*", + validatePattern: true, },
40-48: Add error handling to request methodThe
_makeRequestmethod could benefit from error handling to provide more descriptive error messages specific to pdforge API errors._makeRequest({ $ = this, baseUrl, removeHeader, path = "", ...opts }) { - return axios($, { - url: this._baseUrl(baseUrl) + path, - headers: this._headers(removeHeader), - ...opts, - }); + return axios($, { + url: this._baseUrl(baseUrl) + path, + headers: this._headers(removeHeader), + ...opts, + }).catch(err => { + const status = err.response?.status; + const message = err.response?.data?.message || err.message; + throw new Error(`pdforge API error (${status}): ${message}`); + }); },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
components/pdforge/actions/common/base.mjs(1 hunks)components/pdforge/actions/generate-pdf-from-html/generate-pdf-from-html.mjs(1 hunks)components/pdforge/actions/generate-pdf-from-template/generate-pdf-from-template.mjs(1 hunks)components/pdforge/common/utils.mjs(1 hunks)components/pdforge/package.json(2 hunks)components/pdforge/pdforge.app.mjs(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
components/pdforge/common/utils.mjs
[error] 43-43: Avoid the use of spread (...) syntax on accumulators.
Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.
(lint/performance/noAccumulatingSpread)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Verify TypeScript components
- GitHub Check: pnpm publish
- GitHub Check: Publish TypeScript components
🔇 Additional comments (8)
components/pdforge/actions/generate-pdf-from-template/generate-pdf-from-template.mjs (1)
1-40: Implementation looks good!The action is well-structured and properly extends the common base component. Good job on clearly defined props with descriptive labels and using the parseObject utility for data formatting.
components/pdforge/common/utils.mjs (1)
1-31: Well-implemented utility functionsThe checkTmp and parseObject functions are well-designed with proper error handling and edge case coverage.
components/pdforge/actions/common/base.mjs (2)
10-75: Props and dynamic visibility management look goodThe component's props are well-defined with clear labels and descriptions. The additionalProps method effectively controls property visibility based on the selected mode.
76-133: Implement file handling correctlyThe file handling logic for non-async, non-S3 modes is well implemented using proper stream handling and file system operations.
components/pdforge/actions/generate-pdf-from-html/generate-pdf-from-html.mjs (1)
1-41: Well-structured PDF generation action componentThis action component for generating PDFs from HTML content is well-designed. It properly extends the common base, defines appropriate properties, and implements the necessary methods to integrate with the pdforge API.
The component:
- Clearly separates input concerns (HTML content and PDF parameters)
- Properly parses object parameters
- Provides descriptive documentation links
- Returns appropriate success messages based on the output type
components/pdforge/pdforge.app.mjs (3)
1-48: Well-implemented API client setupThe API client setup is well-structured with appropriate helper methods for:
- Base URL handling with default value
- Authentication headers
- Request abstraction using axios
This follows good practices for code organization and reuse.
16-16: Reconsider if s3key should be marked as secretThe
s3keyproperty is marked as secret, but since it's typically just a path and filename, it may not need to be treated as sensitive information unless it contains confidential naming patterns.
49-70: Well-implemented API method handlersThe API methods for generating documents from templates and HTML content are well-implemented. They:
- Handle both synchronous and asynchronous modes
- Properly pass through options to the request method
- Use clear endpoint paths
Resolves #16687.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation