-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 - typefully #15217
base: master
Are you sure you want to change the base?
New Components - typefully #15217
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
WalkthroughThis pull request introduces comprehensive support for the Typefully application in Pipedream, adding multiple components for draft management. The changes include new sources for tracking draft publications and scheduling, as well as actions for creating and scheduling drafts. The implementation provides a robust integration with the Typefully API, enabling users to interact with drafts through various methods like creating, scheduling, and monitoring draft statuses. Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
Sources - New Draft Published - New Draft Scheduled Actions - Create Draft - Schedule Draft Next Slot - Schedule Draft
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: 3
🧹 Nitpick comments (6)
components/typefully/sources/common/base.mjs (1)
44-44
: Simplify timestamp assignment usingDate.now()
The use of
Date.parse(new Date())
can be simplified for better readability and efficiency.Apply this diff to streamline the timestamp assignment:
- ts: Date.parse(new Date()), + ts: Date.now(),components/typefully/typefully.app.mjs (2)
90-96
: Add input validation for createDraft methodThe method should validate the required fields in the request data before making the API call.
createDraft(opts = {}) { + const { data } = opts; + if (!data?.content) { + throw new Error("Draft content is required"); + } return this._makeRequest({ method: "POST", path: "/drafts/", ...opts, }); }
66-70
: Add date format validation for scheduleDate propThe scheduleDate prop should include a pattern to validate the ISO format.
scheduleDate: { type: "string", label: "Schedule Date", description: "Date to schedule the draft (ISO format - YYYY-MM-DDTHH:MM:SSZ)", + pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", + examples: ["2025-01-15T14:30:00Z"], },components/typefully/actions/schedule-draft/schedule-draft.mjs (1)
3-68
: Consider extracting common code to a shared utilityThere's significant code duplication between create-draft.mjs and schedule-draft.mjs. Consider creating a shared utility for common functionality.
Create a new file
components/typefully/common/draft-utils.mjs
:export const transformDraftData = (data) => { return { content: data.content, threadify: data.threadify, share: data.share, auto_retweet_enabled: data.autoRetweetEnabled, auto_plug_enabled: data.autoPlugEnabled, ...(data.scheduleDate && { schedule_date: data.scheduleDate }), }; }; export const validateScheduleDate = (date) => { const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/; if (!dateRegex.test(date)) { throw new Error("Invalid schedule date format. Expected: YYYY-MM-DDTHH:MM:SSZ"); } };components/typefully/actions/schedule-draft-next-slot/schedule-draft-next-slot.mjs (2)
46-57
: Extract "next-free-slot" to a constant and improve error handlingThe hardcoded value should be defined as a constant, and error handling should be improved.
+const NEXT_FREE_SLOT = "next-free-slot"; + async run({ $ }) { + const transformedData = { + content: this.content, + threadify: this.threadify, + share: this.share, + schedule_date: NEXT_FREE_SLOT, + auto_retweet_enabled: this.autoRetweetEnabled, + auto_plug_enabled: this.autoPlugEnabled, + }; + const response = await this.typefully.createDraft({ $, - data: { - "content": this.content, - "threadify": this.threadify, - "share": this.share, - "schedule-date": "next-free-slot", - "auto_retweet_enabled": this.autoRetweetEnabled, - "auto_plug_enabled": this.autoPlugEnabled, - }, + data: transformedData, }); + + if (!response?.id) { + throw new Error("Failed to schedule draft: Invalid response from API"); + }
3-62
: Add rate limiting considerationsSince this component uses the "next-free-slot" feature, it's important to consider rate limiting to prevent overwhelming the scheduling system.
Consider implementing a delay between consecutive calls to this endpoint. You can add this to the app's
_makeRequest
method or implement it specifically for this action.Example implementation in
typefully.app.mjs
:const RATE_LIMIT_DELAY = 1000; // 1 second async _makeRequest({ $ = this, path, ...opts }) { if (path.includes('/drafts/') && opts.method === 'POST') { await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_DELAY)); } // ... rest of the implementation }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
components/typefully/actions/create-draft/create-draft.mjs
(1 hunks)components/typefully/actions/schedule-draft-next-slot/schedule-draft-next-slot.mjs
(1 hunks)components/typefully/actions/schedule-draft/schedule-draft.mjs
(1 hunks)components/typefully/package.json
(2 hunks)components/typefully/sources/common/base.mjs
(1 hunks)components/typefully/sources/new-draft-published/new-draft-published.mjs
(1 hunks)components/typefully/sources/new-draft-published/test-event.mjs
(1 hunks)components/typefully/sources/new-draft-scheduled/new-draft-scheduled.mjs
(1 hunks)components/typefully/sources/new-draft-scheduled/test-event.mjs
(1 hunks)components/typefully/typefully.app.mjs
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- components/typefully/sources/new-draft-scheduled/test-event.mjs
- components/typefully/sources/new-draft-published/test-event.mjs
🔇 Additional comments (4)
components/typefully/sources/new-draft-scheduled/new-draft-scheduled.mjs (1)
14-20
: Methods are correctly implementedThe
getFunction
andgetSummary
methods are properly defined and extend the base module as expected.components/typefully/sources/new-draft-published/new-draft-published.mjs (1)
14-20
: Methods are correctly implementedThe
getFunction
andgetSummary
methods are properly defined and extend the base module as expected.components/typefully/package.json (2)
3-3
: LGTM! Version bump follows semantic versioning.The minor version increment from 0.0.1 to 0.1.0 correctly reflects the addition of new features (Typefully components) while maintaining backward compatibility.
15-17
: Verify the @pipedream/platform version.Let's ensure we're using the latest stable version of the platform package.
✅ Verification successful
The package is already using the latest version (3.0.3)
The current version specification
^3.0.3
in package.json is correct and up-to-date.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check latest version of @pipedream/platform npm view @pipedream/platform versions --json | jq -r '.[-1]' # Check for any breaking changes or deprecation notices in recent versions npm view @pipedream/platform@">3.0.3" version --jsonLength of output: 754
_baseUrl() { | ||
return "https://api.typefully.com/v1"; | ||
}, | ||
_headers() { | ||
return { | ||
"x-api-key": `${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, |
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.
🛠️ Refactor suggestion
Add error handling to _makeRequest method
The base request method should include error handling to provide meaningful error messages when API calls fail.
_makeRequest({
$ = this, path, ...opts
}) {
+ const baseURL = this._baseUrl();
+ const headers = this._headers();
return axios($, {
- url: this._baseUrl() + path,
- headers: this._headers(),
+ url: `${baseURL}${path}`,
+ headers,
...opts,
+ }).catch((error) => {
+ const statusCode = error.response?.status;
+ const message = error.response?.data?.message || error.message;
+ throw new Error(`Typefully API request failed: ${statusCode} - ${message}`);
});
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
_baseUrl() { | |
return "https://api.typefully.com/v1"; | |
}, | |
_headers() { | |
return { | |
"x-api-key": `${this.$auth.api_key}`, | |
}; | |
}, | |
_makeRequest({ | |
$ = this, path, ...opts | |
}) { | |
return axios($, { | |
url: this._baseUrl() + path, | |
headers: this._headers(), | |
...opts, | |
}); | |
}, | |
_baseUrl() { | |
return "https://api.typefully.com/v1"; | |
}, | |
_headers() { | |
return { | |
"x-api-key": `${this.$auth.api_key}`, | |
}; | |
}, | |
_makeRequest({ | |
$ = this, path, ...opts | |
}) { | |
const baseURL = this._baseUrl(); | |
const headers = this._headers(); | |
return axios($, { | |
url: `${baseURL}${path}`, | |
headers, | |
...opts, | |
}).catch((error) => { | |
const statusCode = error.response?.status; | |
const message = error.response?.data?.message || error.message; | |
throw new Error(`Typefully API request failed: ${statusCode} - ${message}`); | |
}); | |
}, |
async run({ $ }) { | ||
const response = await this.typefully.createDraft({ | ||
$, | ||
data: { | ||
content: this.content, | ||
threadify: this.threadify, | ||
share: this.share, | ||
auto_retweet_enabled: this.autoRetweetEnabled, | ||
auto_plug_enabled: this.autoPlugEnabled, | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Created draft with ID: ${response.id}.`); | ||
return response; | ||
}, |
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.
🛠️ Refactor suggestion
Improve response handling and add parameter transformation
The run method should:
- Transform camelCase parameters to snake_case for API consistency
- Add proper error handling for the API response
async run({ $ }) {
+ // Transform parameters to snake_case format
+ const transformedData = {
+ content: this.content,
+ threadify: this.threadify,
+ share: this.share,
+ auto_retweet_enabled: this.autoRetweetEnabled,
+ auto_plug_enabled: this.autoPlugEnabled,
+ };
+
const response = await this.typefully.createDraft({
$,
- data: {
- content: this.content,
- threadify: this.threadify,
- share: this.share,
- auto_retweet_enabled: this.autoRetweetEnabled,
- auto_plug_enabled: this.autoPlugEnabled,
- },
+ data: transformedData,
});
+
+ if (!response?.id) {
+ throw new Error("Failed to create draft: Invalid response from API");
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async run({ $ }) { | |
const response = await this.typefully.createDraft({ | |
$, | |
data: { | |
content: this.content, | |
threadify: this.threadify, | |
share: this.share, | |
auto_retweet_enabled: this.autoRetweetEnabled, | |
auto_plug_enabled: this.autoPlugEnabled, | |
}, | |
}); | |
$.export("$summary", `Created draft with ID: ${response.id}.`); | |
return response; | |
}, | |
async run({ $ }) { | |
// Transform parameters to snake_case format | |
const transformedData = { | |
content: this.content, | |
threadify: this.threadify, | |
share: this.share, | |
auto_retweet_enabled: this.autoRetweetEnabled, | |
auto_plug_enabled: this.autoPlugEnabled, | |
}; | |
const response = await this.typefully.createDraft({ | |
$, | |
data: transformedData, | |
}); | |
if (!response?.id) { | |
throw new Error("Failed to create draft: Invalid response from API"); | |
} | |
$.export("$summary", `Created draft with ID: ${response.id}.`); | |
return response; | |
} |
async run({ $ }) { | ||
const response = await this.typefully.createDraft({ | ||
$, | ||
data: { | ||
"content": this.content, | ||
"threadify": this.threadify, | ||
"share": this.share, | ||
"schedule-date": this.scheduleDate, | ||
"auto_retweet_enabled": this.autoRetweetEnabled, | ||
"auto_plug_enabled": this.autoPlugEnabled, | ||
}, | ||
}); |
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.
Fix parameter naming inconsistency and add date validation
Issues found:
- Inconsistent parameter naming (
schedule-date
vs snake_case) - Missing date validation before API call
async run({ $ }) {
+ // Validate schedule date format
+ const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
+ if (!dateRegex.test(this.scheduleDate)) {
+ throw new Error("Invalid schedule date format. Expected: YYYY-MM-DDTHH:MM:SSZ");
+ }
+
+ const transformedData = {
+ content: this.content,
+ threadify: this.threadify,
+ share: this.share,
+ schedule_date: this.scheduleDate,
+ auto_retweet_enabled: this.autoRetweetEnabled,
+ auto_plug_enabled: this.autoPlugEnabled,
+ };
+
const response = await this.typefully.createDraft({
$,
- data: {
- "content": this.content,
- "threadify": this.threadify,
- "share": this.share,
- "schedule-date": this.scheduleDate,
- "auto_retweet_enabled": this.autoRetweetEnabled,
- "auto_plug_enabled": this.autoPlugEnabled,
- },
+ data: transformedData,
});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async run({ $ }) { | |
const response = await this.typefully.createDraft({ | |
$, | |
data: { | |
"content": this.content, | |
"threadify": this.threadify, | |
"share": this.share, | |
"schedule-date": this.scheduleDate, | |
"auto_retweet_enabled": this.autoRetweetEnabled, | |
"auto_plug_enabled": this.autoPlugEnabled, | |
}, | |
}); | |
async run({ $ }) { | |
// Validate schedule date format | |
const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/; | |
if (!dateRegex.test(this.scheduleDate)) { | |
throw new Error("Invalid schedule date format. Expected: YYYY-MM-DDTHH:MM:SSZ"); | |
} | |
const transformedData = { | |
content: this.content, | |
threadify: this.threadify, | |
share: this.share, | |
schedule_date: this.scheduleDate, | |
auto_retweet_enabled: this.autoRetweetEnabled, | |
auto_plug_enabled: this.autoPlugEnabled, | |
}; | |
const response = await this.typefully.createDraft({ | |
$, | |
data: transformedData, | |
}); |
Resolves #15184.
Summary by CodeRabbit
Release Notes for Typefully Integration
New Features
Improvements
Version Update