Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request introduces several modifications across the project. The distribution services and their tests now use an updated parameter structure, replacing simple IDs with full submission objects. A configuration file handling environment variables has been removed in favor of a centralized configuration service. A new Notion integration has been added along with its documentation and related configuration updates. Additional improvements include enhanced Twitter client validations, changes to submission handling, and frontend moderation actions using button clicks with environment-specific logic. Finally, unused dependencies have been removed from the package manifest. Changes
Sequence Diagram(s)sequenceDiagram
participant DS as DistributionService
participant NP as NotionPlugin
participant NAPI as NotionAPI
DS->>NP: distribute(feedId, submission)
NP->>NP: Validate configuration (token, databaseId)
NP->>NAPI: Create database row with submission data
NAPI-->>NP: Success/Error response
NP-->>DS: Return result
sequenceDiagram
participant User
participant FI as FeedItem
participant TL as TwitterLib
participant API as MockAPI/TwitterIntent
User->>FI: Click "Approve" button
FI->>TL: handleApprove(submission, botId)
alt Development Mode
TL->>API: POST tweet approval details
API-->>TL: Response
else Production Mode
TL->>Browser: Open Twitter intent URL for approval
end
Possibly related PRs
Poem
Tip 🌐 Web search-backed reviews and chat
✨ Finishing Touches
🪧 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 (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (7)
backend/src/external/notion/index.ts (2)
5-34: Enhance error reporting in the initialize process.
Capturing and logging the entire error is helpful, but consider adding more context, such as which feedId triggered the error. Also evaluate whether the raw error object might contain sensitive information that should be sanitized.
36-50: Consider implementing retry logic for Notion API calls.
Network or rate-limit errors on Notion’s side can cause transient failures. A retry mechanism would help improve resilience.backend/src/__tests__/mocks/distribution-service.mock.ts (1)
7-11: Replace ‘any’ with a more specific type to ensure robust tests.
Ifsubmissionis always aTwitterSubmission, strongly typing it will help catch future changes and potential usage errors (e.g., a missingtweetId).frontend/src/lib/twitter.ts (1)
9-12: Consider using a more robust ID generation method.The current ID generation might lead to collisions in high-concurrency scenarios.
Consider using a UUID library:
-const generateTweetId = () => - `${Date.now()}${Math.floor(Math.random() * 1000)}`; +import { v4 as uuidv4 } from 'uuid'; +const generateTweetId = () => uuidv4();backend/src/services/distribution/distribution.service.ts (1)
168-185: Remove commented-out code.The commented-out code block should be removed since it's no longer needed and the TODO comment above explains the future requirements.
Apply this diff:
- // const content = ""; - - // // Transform content (required for recap) - // const processedContent = await this.transformContent( - // transform.plugin, - // content, - // transform.config, - // ); - - // // Distribute to all configured outputs - // for (const dist of distribute) { - // await this.distributeContent( - // feedId, - // dist.plugin, - // processedContent, - // dist.config, - // ); - // }backend/src/services/twitter/client.ts (1)
207-207: Consider safer type handling for tweet IDs.The non-null assertions (!.) could be replaced with safer type handling.
Apply this diff:
- const tweetId = BigInt(tweet.id!); + const tweetId = tweet.id ? BigInt(tweet.id) : null; + if (!tweetId) { + logger.warn('Tweet found without ID:', tweet); + continue; + } // Sort chronologically (oldest to newest) allNewTweets.sort((a, b) => { - const aId = BigInt(a.id!); - const bId = BigInt(b.id!); + const aId = a.id ? BigInt(a.id) : null; + const bId = b.id ? BigInt(b.id) : null; + if (!aId || !bId) return 0; return aId > bId ? 1 : aId < bId ? -1 : 0; }); // Use the first tweet from the batch since it's the newest const highestId = batch[0].id; - await this.setLastCheckedTweetId(highestId!); + if (highestId) { + await this.setLastCheckedTweetId(highestId); + } else { + logger.warn('Highest tweet found without ID:', batch[0]); + }Also applies to: 215-216, 224-224
docs/docs/plugins/distributors/notion.md (1)
1-101: Documentation is comprehensive but could be enhanced.The Notion plugin documentation is well-structured with clear setup instructions, security considerations, and configuration examples. Consider these enhancements:
- Add a hyphen in "full-page" when used as a compound adjective.
- Add a comma in the tip section: "If your stream had been disabled, and you have existing, approved submissions..."
- Consider adding troubleshooting section for common issues.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~36-~36: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...tegration: - Open your database as a full page - Click the "..." menu in the top ri...(EN_COMPOUND_ADJECTIVE_INTERNAL)
[uncategorized] ~85-~85: This verb may not be in the correct tense. Consider changing the tense to fit the context better.
Context: ... new rows. :::tip If your stream had been disabled and you have existing, ap...(AI_EN_LECTOR_REPLACEMENT_VERB_TENSE)
[uncategorized] ~85-~85: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...:tip If your stream had been disabled and you have existing, approved submissions...(COMMA_COMPOUND_SENTENCE)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockbis excluded by!**/bun.lockb
📒 Files selected for processing (13)
backend/src/__tests__/mocks/distribution-service.mock.ts(1 hunks)backend/src/config/config.ts(0 hunks)backend/src/external/notion/index.ts(1 hunks)backend/src/index.ts(3 hunks)backend/src/services/distribution/distribution.service.ts(4 hunks)backend/src/services/submissions/submission.service.ts(4 hunks)backend/src/services/twitter/client.ts(2 hunks)backend/src/types/plugin.ts(1 hunks)curate.config.test.json(2 hunks)docs/docs/plugins/distributors/notion.md(1 hunks)frontend/src/components/FeedItem.tsx(2 hunks)frontend/src/lib/twitter.ts(1 hunks)package.json(0 hunks)
💤 Files with no reviewable changes (2)
- package.json
- backend/src/config/config.ts
🧰 Additional context used
🪛 LanguageTool
docs/docs/plugins/distributors/notion.md
[uncategorized] ~36-~36: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...tegration: - Open your database as a full page - Click the "..." menu in the top ri...
(EN_COMPOUND_ADJECTIVE_INTERNAL)
[uncategorized] ~85-~85: This verb may not be in the correct tense. Consider changing the tense to fit the context better.
Context: ... new rows. :::tip If your stream had been disabled and you have existing, ap...
(AI_EN_LECTOR_REPLACEMENT_VERB_TENSE)
[uncategorized] ~85-~85: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...:tip If your stream had been disabled and you have existing, approved submissions...
(COMMA_COMPOUND_SENTENCE)
🔇 Additional comments (14)
backend/src/external/notion/index.ts (2)
1-4: Check for consistent type imports and references.
Your imports look good and match the interfaces fromtypes/pluginandtypes/twitter. No issues identified.
52-101: Verify database schema requirements for Notion pages.
Many Notion databases require a title property to be set for new pages. The plugin currently omits a “title” property, which may lead to unexpected behavior.Do you want me to generate a shell script to search for any references or usage instructions for a required Notion title property across the codebase?
backend/src/types/plugin.ts (1)
4-4: Well-aligned interface update.
Updating thedistributemethod signature to accept aTwitterSubmissionobject centralizes handling of submission data and ensures consistency across the application.backend/src/services/distribution/distribution.service.ts (1)
65-69: LGTM! Parameter type change aligns with plugin interface.The change from content string to TwitterSubmission object provides more context to plugins.
backend/src/services/twitter/client.ts (1)
114-122: LGTM! Early validation of required credentials.Good practice to validate environment variables early in the initialization process.
backend/src/index.ts (3)
4-4: LGTM!The import changes look good. Using
dotenv/configis a cleaner way to load environment variables, and theConfigServiceimport aligns with the centralized configuration management approach.Also applies to: 10-10
40-45: LGTM!The configuration loading logic is well-structured and follows a clear sequence:
- Start spinner with loading message
- Get ConfigService instance
- Load configuration
- Get loaded config
- Update spinner with success message
322-322: LGTM!The error handling update correctly includes "config" in the list of spinner keys to fail during initialization errors.
backend/src/services/submissions/submission.service.ts (3)
296-296: LGTM!The changes correctly prioritize using the existing submission over creating a new one when processing stream outputs.
Also applies to: 334-334
353-353: LGTM!The non-null assertion for tweet ID is safe here as it's already checked in the calling context.
365-365: LGTM!The error message has been improved to be more descriptive by including both tweet ID and user ID validation.
curate.config.test.json (3)
3-3: LGTM!The bot ID update to "test_bot" is consistent with the test environment naming convention.
11-18: LGTM!The plugin configurations for Telegram and Notion are well-structured and correctly specify their types and URLs.
35-46: Verify the environment variable placeholders.The configuration uses environment variable placeholders for sensitive values:
{CRYPTOGRANTWIRE_NOTION_TOKEN}{TELEGRAM_BOT_TOKEN}Run this script to check if these environment variables are properly documented:
| export const handleApprove = async ( | ||
| submission: TwitterSubmissionWithFeedData, | ||
| botId: string, | ||
| ) => { | ||
| if (isDev()) { | ||
| const newTweetId = generateTweetId(); | ||
| const response = await fetch("/api/test/tweets", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| id: newTweetId, | ||
| text: `!approve @${botId}`, | ||
| username: "test_admin", | ||
| userId: "mock-user-id-test_admin", | ||
| timeParsed: new Date(), | ||
| inReplyToStatusId: submission.curatorTweetId, | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| console.error("Failed to submit approval tweet"); | ||
| return; | ||
| } | ||
|
|
||
| console.log("Development mode: Submitted approval tweet", { newTweetId }); | ||
| return; | ||
| } | ||
|
|
||
| // In production, open Twitter intent | ||
| window.open( | ||
| getTwitterIntentUrl({ | ||
| action: "approve", | ||
| submission, | ||
| botId, | ||
| }), | ||
| "_blank", | ||
| ); | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance error handling in development mode.
The error handling could be improved to provide better feedback to users.
Apply this diff to enhance error handling:
if (!response.ok) {
- console.error("Failed to submit approval tweet");
+ const errorData = await response.json().catch(() => ({}));
+ console.error("Failed to submit approval tweet:", {
+ status: response.status,
+ statusText: response.statusText,
+ error: errorData
+ });
return;
}📝 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.
| export const handleApprove = async ( | |
| submission: TwitterSubmissionWithFeedData, | |
| botId: string, | |
| ) => { | |
| if (isDev()) { | |
| const newTweetId = generateTweetId(); | |
| const response = await fetch("/api/test/tweets", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| id: newTweetId, | |
| text: `!approve @${botId}`, | |
| username: "test_admin", | |
| userId: "mock-user-id-test_admin", | |
| timeParsed: new Date(), | |
| inReplyToStatusId: submission.curatorTweetId, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| console.error("Failed to submit approval tweet"); | |
| return; | |
| } | |
| console.log("Development mode: Submitted approval tweet", { newTweetId }); | |
| return; | |
| } | |
| // In production, open Twitter intent | |
| window.open( | |
| getTwitterIntentUrl({ | |
| action: "approve", | |
| submission, | |
| botId, | |
| }), | |
| "_blank", | |
| ); | |
| }; | |
| export const handleApprove = async ( | |
| submission: TwitterSubmissionWithFeedData, | |
| botId: string, | |
| ) => { | |
| if (isDev()) { | |
| const newTweetId = generateTweetId(); | |
| const response = await fetch("/api/test/tweets", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| id: newTweetId, | |
| text: `!approve @${botId}`, | |
| username: "test_admin", | |
| userId: "mock-user-id-test_admin", | |
| timeParsed: new Date(), | |
| inReplyToStatusId: submission.curatorTweetId, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| const errorData = await response.json().catch(() => ({})); | |
| console.error("Failed to submit approval tweet:", { | |
| status: response.status, | |
| statusText: response.statusText, | |
| error: errorData | |
| }); | |
| return; | |
| } | |
| console.log("Development mode: Submitted approval tweet", { newTweetId }); | |
| return; | |
| } | |
| // In production, open Twitter intent | |
| window.open( | |
| getTwitterIntentUrl({ | |
| action: "approve", | |
| submission, | |
| botId, | |
| }), | |
| "_blank", | |
| ); | |
| }; |
| export const handleReject = async ( | ||
| submission: TwitterSubmissionWithFeedData, | ||
| botId: string, | ||
| ) => { | ||
| if (isDev()) { | ||
| const newTweetId = generateTweetId(); | ||
| const response = await fetch("/api/test/tweets", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| id: newTweetId, | ||
| text: `!reject @${botId} spam`, | ||
| username: "test_admin", | ||
| userId: "test_admin_id", | ||
| timeParsed: new Date(), | ||
| inReplyToStatusId: submission.curatorTweetId, | ||
| }), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| console.error("Failed to submit rejection tweet"); | ||
| return; | ||
| } | ||
|
|
||
| console.log("Development mode: Submitted rejection tweet", { newTweetId }); | ||
| return; | ||
| } | ||
|
|
||
| // In production, open Twitter intent | ||
| window.open( | ||
| getTwitterIntentUrl({ | ||
| action: "reject", | ||
| submission, | ||
| botId, | ||
| }), | ||
| "_blank", | ||
| ); | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Code duplication in handleReject function.
The handleReject function largely duplicates the handleApprove logic.
Extract the common logic into a shared function:
+const handleModerationAction = async (
+ action: 'approve' | 'reject',
+ submission: TwitterSubmissionWithFeedData,
+ botId: string,
+) => {
+ if (isDev()) {
+ const newTweetId = generateTweetId();
+ const response = await fetch("/api/test/tweets", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ id: newTweetId,
+ text: `!${action} @${botId}${action === 'reject' ? ' spam' : ''}`,
+ username: "test_admin",
+ userId: "mock-user-id-test_admin",
+ timeParsed: new Date(),
+ inReplyToStatusId: submission.curatorTweetId,
+ }),
+ });
+
+ if (!response.ok) {
+ console.error(`Failed to submit ${action} tweet`);
+ return;
+ }
+
+ console.log(`Development mode: Submitted ${action} tweet`, { newTweetId });
+ return;
+ }
+
+ window.open(
+ getTwitterIntentUrl({
+ action,
+ submission,
+ botId,
+ }),
+ "_blank",
+ );
+};
+
+export const handleApprove = (submission: TwitterSubmissionWithFeedData, botId: string) =>
+ handleModerationAction('approve', submission, botId);
+
+export const handleReject = (submission: TwitterSubmissionWithFeedData, botId: string) =>
+ handleModerationAction('reject', submission, botId);📝 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.
| export const handleReject = async ( | |
| submission: TwitterSubmissionWithFeedData, | |
| botId: string, | |
| ) => { | |
| if (isDev()) { | |
| const newTweetId = generateTweetId(); | |
| const response = await fetch("/api/test/tweets", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| id: newTweetId, | |
| text: `!reject @${botId} spam`, | |
| username: "test_admin", | |
| userId: "test_admin_id", | |
| timeParsed: new Date(), | |
| inReplyToStatusId: submission.curatorTweetId, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| console.error("Failed to submit rejection tweet"); | |
| return; | |
| } | |
| console.log("Development mode: Submitted rejection tweet", { newTweetId }); | |
| return; | |
| } | |
| // In production, open Twitter intent | |
| window.open( | |
| getTwitterIntentUrl({ | |
| action: "reject", | |
| submission, | |
| botId, | |
| }), | |
| "_blank", | |
| ); | |
| }; | |
| const handleModerationAction = async ( | |
| action: 'approve' | 'reject', | |
| submission: TwitterSubmissionWithFeedData, | |
| botId: string, | |
| ) => { | |
| if (isDev()) { | |
| const newTweetId = generateTweetId(); | |
| const response = await fetch("/api/test/tweets", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ | |
| id: newTweetId, | |
| text: `!${action} @${botId}${action === 'reject' ? ' spam' : ''}`, | |
| username: "test_admin", | |
| userId: "mock-user-id-test_admin", | |
| timeParsed: new Date(), | |
| inReplyToStatusId: submission.curatorTweetId, | |
| }), | |
| }); | |
| if (!response.ok) { | |
| console.error(`Failed to submit ${action} tweet`); | |
| return; | |
| } | |
| console.log(`Development mode: Submitted ${action} tweet`, { newTweetId }); | |
| return; | |
| } | |
| window.open( | |
| getTwitterIntentUrl({ | |
| action, | |
| submission, | |
| botId, | |
| }), | |
| "_blank", | |
| ); | |
| }; | |
| export const handleApprove = (submission: TwitterSubmissionWithFeedData, botId: string) => | |
| handleModerationAction('approve', submission, botId); | |
| export const handleReject = (submission: TwitterSubmissionWithFeedData, botId: string) => | |
| handleModerationAction('reject', submission, botId); |
| <button | ||
| onClick={() => handleApprove(submission, botId)} | ||
| className="px-3 py-1.5 bg-green-200 hover:bg-green-300 text-black rounded-md border-2 border-black shadow-sharp hover:shadow-sharp-hover transition-all duration-200 translate-x-0 translate-y-0 hover:-translate-x-0.5 hover:-translate-y-0.5 text-sm font-medium" | ||
| > | ||
| approve | ||
| </a> | ||
| <a | ||
| href={getTwitterIntentUrl({ action: "reject", submission, botId })} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| </button> |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add loading states to moderation buttons.
The buttons should indicate when an action is in progress to prevent double-clicks.
Add loading states:
+import { useState } from 'react';
const ModerationActions = ({
submission,
}: {
submission: TwitterSubmissionWithFeedData;
}) => {
const botId = useBotId();
+ const [isLoading, setIsLoading] = useState<'approve' | 'reject' | null>(null);
+
+ const handleAction = async (action: 'approve' | 'reject') => {
+ setIsLoading(action);
+ try {
+ await (action === 'approve'
+ ? handleApprove(submission, botId)
+ : handleReject(submission, botId));
+ } finally {
+ setIsLoading(null);
+ }
+ };
return (
<div className="flex flex-col gap-2 mt-4">
<button
- onClick={() => handleApprove(submission, botId)}
+ onClick={() => handleAction('approve')}
+ disabled={isLoading !== null}
className="px-3 py-1.5 bg-green-200 hover:bg-green-300 text-black rounded-md border-2 border-black shadow-sharp hover:shadow-sharp-hover transition-all duration-200 translate-x-0 translate-y-0 hover:-translate-x-0.5 hover:-translate-y-0.5 text-sm font-medium"
>
- approve
+ {isLoading === 'approve' ? 'approving...' : 'approve'}
</button>
<button
- onClick={() => handleReject(submission, botId)}
+ onClick={() => handleAction('reject')}
+ disabled={isLoading !== null}
className="px-3 py-1.5 bg-red-200 hover:bg-red-300 text-black rounded-md border-2 border-black shadow-sharp hover:shadow-sharp-hover transition-all duration-200 translate-x-0 translate-y-0 hover:-translate-x-0.5 hover:-translate-y-0.5 text-sm font-medium"
>
- reject
+ {isLoading === 'reject' ? 'rejecting...' : 'reject'}
</button>
</div>
);
};Also applies to: 106-111
Summary by CodeRabbit
New Features
Documentation