From 490c66a1d82c08d9d970a3e57d8076cdc6298ad6 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 27 Jun 2025 13:40:15 -0300 Subject: [PATCH 1/3] Update Reddit component to version 1.2.0, add new private message source, and increment action versions to 0.1.2 and 0.1.3 for various actions. Refactor imports for consistency. --- .../list-comments-in-a-post.mjs | 4 +- .../list-subreddits-by-query.mjs | 4 +- .../actions/search-post/search-post.mjs | 2 +- .../submit-a-comment/submit-a-comment.mjs | 2 +- .../actions/submit-a-post/submit-a-post.mjs | 4 +- components/reddit/package.json | 4 +- components/reddit/reddit.app.mjs | 11 +++- .../new-comments-by-user.mjs | 2 +- .../new-comments-on-a-post.mjs | 4 +- .../new-hot-posts-on-a-subreddit.mjs | 6 +- .../new-links-by-user/new-links-by-user.mjs | 2 +- .../new-links-on-a-subreddit.mjs | 4 +- .../new-private-message.mjs | 65 +++++++++++++++++++ .../new-saved-post-by-user.mjs | 2 +- 14 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 components/reddit/sources/new-private-message/new-private-message.mjs diff --git a/components/reddit/actions/list-comments-in-a-post/list-comments-in-a-post.mjs b/components/reddit/actions/list-comments-in-a-post/list-comments-in-a-post.mjs index 82a112387a7e1..7443cd2f61eb0 100644 --- a/components/reddit/actions/list-comments-in-a-post/list-comments-in-a-post.mjs +++ b/components/reddit/actions/list-comments-in-a-post/list-comments-in-a-post.mjs @@ -1,10 +1,10 @@ -import reddit from "../../reddit.app.mjs"; import { axios } from "@pipedream/platform"; +import reddit from "../../reddit.app.mjs"; export default { type: "action", key: "reddit-list-comments-in-a-post", - version: "0.1.1", + version: "0.1.2", name: "List Comments in a Post", description: "List comments for a specific post. [See the docs here](https://www.reddit.com/dev/api/#GET_comments_{article})", props: { diff --git a/components/reddit/actions/list-subreddits-by-query/list-subreddits-by-query.mjs b/components/reddit/actions/list-subreddits-by-query/list-subreddits-by-query.mjs index 8a741749a595b..3321da3d814d2 100644 --- a/components/reddit/actions/list-subreddits-by-query/list-subreddits-by-query.mjs +++ b/components/reddit/actions/list-subreddits-by-query/list-subreddits-by-query.mjs @@ -1,10 +1,10 @@ -import reddit from "../../reddit.app.mjs"; import { axios } from "@pipedream/platform"; +import reddit from "../../reddit.app.mjs"; export default { type: "action", key: "reddit-list-subreddits-by-query", - version: "0.1.1", + version: "0.1.2", name: "List Subreddits by Query", description: "List subreddits based on a search criteria. [See the docs here](https://www.reddit.com/dev/api/#GET_subreddits_search)", props: { diff --git a/components/reddit/actions/search-post/search-post.mjs b/components/reddit/actions/search-post/search-post.mjs index 188f6cf11bef4..d533e322b1eed 100644 --- a/components/reddit/actions/search-post/search-post.mjs +++ b/components/reddit/actions/search-post/search-post.mjs @@ -3,7 +3,7 @@ import reddit from "../../reddit.app.mjs"; export default { type: "action", key: "reddit-search-post", - version: "0.1.1", + version: "0.1.2", name: "Search Post", description: "Search posts by title. [See the docs here](https://www.reddit.com/dev/api/#GET_search)", props: { diff --git a/components/reddit/actions/submit-a-comment/submit-a-comment.mjs b/components/reddit/actions/submit-a-comment/submit-a-comment.mjs index f225b582f7c32..bd5f391600a73 100644 --- a/components/reddit/actions/submit-a-comment/submit-a-comment.mjs +++ b/components/reddit/actions/submit-a-comment/submit-a-comment.mjs @@ -4,7 +4,7 @@ import reddit from "../../reddit.app.mjs"; export default { type: "action", key: "reddit-submit-a-comment", - version: "0.1.1", + version: "0.1.2", name: "Submit a Comment", description: "Submit a new comment or reply to a message. [See the docs here](https://www.reddit.com/dev/api/#POST_api_comment)", props: { diff --git a/components/reddit/actions/submit-a-post/submit-a-post.mjs b/components/reddit/actions/submit-a-post/submit-a-post.mjs index 71ff0f1eccf38..a697f0e1f3aea 100644 --- a/components/reddit/actions/submit-a-post/submit-a-post.mjs +++ b/components/reddit/actions/submit-a-post/submit-a-post.mjs @@ -1,11 +1,11 @@ import { axios } from "@pipedream/platform"; -import reddit from "../../reddit.app.mjs"; import tzs from "../../pytz-timezones.mjs"; +import reddit from "../../reddit.app.mjs"; export default { type: "action", key: "reddit-submit-a-post", - version: "0.1.1", + version: "0.1.2", name: "Submit a Post", description: "Create a post to a subreddit. [See the docs here](https://www.reddit.com/dev/api/#POST_api_submit)", props: { diff --git a/components/reddit/package.json b/components/reddit/package.json index 47c6810321ad0..b56a06d0fee08 100644 --- a/components/reddit/package.json +++ b/components/reddit/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/reddit", - "version": "1.1.3", + "version": "1.2.0", "description": "Pipedream Reddit Components", "main": "reddit.app.mjs", "keywords": [ @@ -13,7 +13,7 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.4.0", + "@pipedream/platform": "^3.1.0", "async-retry": "^1.3.3", "axios": "^0.27.2", "lodash": "^4.17.21", diff --git a/components/reddit/reddit.app.mjs b/components/reddit/reddit.app.mjs index fa40b50630fd1..f13e56ec4ff2d 100644 --- a/components/reddit/reddit.app.mjs +++ b/components/reddit/reddit.app.mjs @@ -1,8 +1,8 @@ import { axios } from "@pipedream/platform"; -import qs from "qs"; -import isNil from "lodash/isNil.js"; import retry from "async-retry"; import get from "lodash/get.js"; +import isNil from "lodash/isNil.js"; +import qs from "qs"; export default { type: "app", @@ -490,5 +490,12 @@ export default { }, })); }, + getPrivateMessages(opts = { }) { + return this._withRetries(() => + this._makeRequest({ + path: `/message/inbox`, + ...opts + })); + }, }, }; diff --git a/components/reddit/sources/new-comments-by-user/new-comments-by-user.mjs b/components/reddit/sources/new-comments-by-user/new-comments-by-user.mjs index f4c0fb4012f38..41c69feb3b77b 100644 --- a/components/reddit/sources/new-comments-by-user/new-comments-by-user.mjs +++ b/components/reddit/sources/new-comments-by-user/new-comments-by-user.mjs @@ -7,7 +7,7 @@ export default { key: "reddit-new-comments-by-user", name: "New Comments by User", description: "Emit new event each time a user posts a new comment.", - version: "0.1.1", + version: "0.1.2", dedupe: "unique", props: { ...common.props, diff --git a/components/reddit/sources/new-comments-on-a-post/new-comments-on-a-post.mjs b/components/reddit/sources/new-comments-on-a-post/new-comments-on-a-post.mjs index 0eae1a98c9f97..141d4441b1b82 100644 --- a/components/reddit/sources/new-comments-on-a-post/new-comments-on-a-post.mjs +++ b/components/reddit/sources/new-comments-on-a-post/new-comments-on-a-post.mjs @@ -1,5 +1,5 @@ -import common from "../common.mjs"; import get from "lodash/get.js"; +import common from "../common.mjs"; const { reddit } = common.props; export default { @@ -9,7 +9,7 @@ export default { name: "New comments on a post", description: "Emit new event each time a new comment is added to a subreddit.", - version: "0.1.1", + version: "0.1.2", dedupe: "unique", props: { ...common.props, diff --git a/components/reddit/sources/new-hot-posts-on-a-subreddit/new-hot-posts-on-a-subreddit.mjs b/components/reddit/sources/new-hot-posts-on-a-subreddit/new-hot-posts-on-a-subreddit.mjs index 3ef6d77c221d3..eb621670cd050 100644 --- a/components/reddit/sources/new-hot-posts-on-a-subreddit/new-hot-posts-on-a-subreddit.mjs +++ b/components/reddit/sources/new-hot-posts-on-a-subreddit/new-hot-posts-on-a-subreddit.mjs @@ -1,7 +1,7 @@ +import get from "lodash/get.js"; import common from "../common.mjs"; -import sampleEmit from "./test-event.mjs"; import regionData from "./region-data.mjs"; -import get from "lodash/get.js"; +import sampleEmit from "./test-event.mjs"; const { reddit } = common.props; export default { @@ -11,7 +11,7 @@ export default { name: "New hot posts on a subreddit", description: "Emit new event each time a new hot post is added to the top 10 items in a subreddit.", - version: "0.2.2", + version: "0.2.3", dedupe: "unique", props: { ...common.props, diff --git a/components/reddit/sources/new-links-by-user/new-links-by-user.mjs b/components/reddit/sources/new-links-by-user/new-links-by-user.mjs index 6c6a8423c0d3a..80dc985f30587 100644 --- a/components/reddit/sources/new-links-by-user/new-links-by-user.mjs +++ b/components/reddit/sources/new-links-by-user/new-links-by-user.mjs @@ -7,7 +7,7 @@ export default { key: "reddit-new-links-by-user", name: "New Links by User", description: "Emit new event each time a user posts a new link.", - version: "0.1.1", + version: "0.1.2", dedupe: "unique", props: { ...common.props, diff --git a/components/reddit/sources/new-links-on-a-subreddit/new-links-on-a-subreddit.mjs b/components/reddit/sources/new-links-on-a-subreddit/new-links-on-a-subreddit.mjs index 8f426fed06631..eb2027e1b53d6 100644 --- a/components/reddit/sources/new-links-on-a-subreddit/new-links-on-a-subreddit.mjs +++ b/components/reddit/sources/new-links-on-a-subreddit/new-links-on-a-subreddit.mjs @@ -1,5 +1,5 @@ -import common from "../common.mjs"; import get from "lodash/get.js"; +import common from "../common.mjs"; const { reddit } = common.props; export default { @@ -8,7 +8,7 @@ export default { key: "reddit-new-links-on-a-subreddit", name: "New Links on a Subreddit", description: "Emit new event each time a new link is added to a subreddit", - version: "0.1.1", + version: "0.1.2", dedupe: "unique", props: { ...common.props, diff --git a/components/reddit/sources/new-private-message/new-private-message.mjs b/components/reddit/sources/new-private-message/new-private-message.mjs new file mode 100644 index 0000000000000..e52f5d0e2d652 --- /dev/null +++ b/components/reddit/sources/new-private-message/new-private-message.mjs @@ -0,0 +1,65 @@ +import common from "../common.mjs"; +const { reddit } = common.props; + +export default { + ...common, + type: "source", + key: "reddit-new-private-message", + name: "New Private Message", + description: "Emit new event each time you receive a new private message.", + version: "0.0.1", + dedupe: "unique", + hooks: { + async deploy() { + // Emits sample events on the first run during deploy. + var privateMessages = await this.reddit.getPrivateMessages({ + params: { + limit: 20, + } + }); + + let { children: messages = [] } = privateMessages.data; + if (messages.length === 0) { + console.log("No data available, skipping iteration"); + return; + } + + const { id = this._getBefore() } = messages[0].data; + this._setBefore(id); + messages.reverse().forEach(this.emitRedditEvent); + }, + }, + methods: { + ...common.methods, + generateEventMetadata(redditEvent) { + return { + id: redditEvent.data.id, + summary: redditEvent.data.body, + ts: redditEvent.data.created, + }; + }, + }, + async run() { + let privateMessages; + do { + privateMessages = await this.reddit.getPrivateMessages({ + params: { + before: `t4_${this._getBefore()}`, + limit: 2, + } + }); + + const { children: messages = [] } = privateMessages.data; + if (messages.length === 0) { + console.log("No data available, skipping iteration"); + break; + } + const { id } = messages[0].data; + this._setBefore(id); + + messages.reverse().forEach((message) => { + this.emitRedditEvent(message); + }); + } while (privateMessages); + }, +}; diff --git a/components/reddit/sources/new-saved-post-by-user/new-saved-post-by-user.mjs b/components/reddit/sources/new-saved-post-by-user/new-saved-post-by-user.mjs index dc8111d88afa7..1cb5eb18020c1 100644 --- a/components/reddit/sources/new-saved-post-by-user/new-saved-post-by-user.mjs +++ b/components/reddit/sources/new-saved-post-by-user/new-saved-post-by-user.mjs @@ -7,7 +7,7 @@ export default { key: "reddit-new-saved-post-by-user", name: "New Saved Post by User", description: "Emit new event each time a user saves a post.", - version: "0.1.2", + version: "0.1.3", dedupe: "unique", props: { ...common.props, From 26c5acd0fbf3af2ee5407db1b78b8170ab4ed44c Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 27 Jun 2025 13:55:56 -0300 Subject: [PATCH 2/3] pnpm update --- pnpm-lock.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fc97dde92332f..b9df63de43d68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1575,8 +1575,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/bitget: - specifiers: {} + components/bitget: {} components/bitly: dependencies: @@ -6905,8 +6904,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/joggai: - specifiers: {} + components/joggai: {} components/join: {} @@ -11037,8 +11035,8 @@ importers: components/reddit: dependencies: '@pipedream/platform': - specifier: ^1.4.0 - version: 1.6.6 + specifier: ^3.1.0 + version: 3.1.0 async-retry: specifier: ^1.3.3 version: 1.3.3 From 11276340a1acfb4d341f7f18b187a6f1c4190b4f Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 27 Jun 2025 14:30:25 -0300 Subject: [PATCH 3/3] fix lint --- components/reddit/reddit.app.mjs | 4 ++-- .../sources/new-private-message/new-private-message.mjs | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/reddit/reddit.app.mjs b/components/reddit/reddit.app.mjs index f13e56ec4ff2d..f830f1f1f34a5 100644 --- a/components/reddit/reddit.app.mjs +++ b/components/reddit/reddit.app.mjs @@ -493,8 +493,8 @@ export default { getPrivateMessages(opts = { }) { return this._withRetries(() => this._makeRequest({ - path: `/message/inbox`, - ...opts + path: "/message/inbox", + ...opts, })); }, }, diff --git a/components/reddit/sources/new-private-message/new-private-message.mjs b/components/reddit/sources/new-private-message/new-private-message.mjs index e52f5d0e2d652..2de054f424eea 100644 --- a/components/reddit/sources/new-private-message/new-private-message.mjs +++ b/components/reddit/sources/new-private-message/new-private-message.mjs @@ -1,5 +1,4 @@ import common from "../common.mjs"; -const { reddit } = common.props; export default { ...common, @@ -15,15 +14,15 @@ export default { var privateMessages = await this.reddit.getPrivateMessages({ params: { limit: 20, - } + }, }); - + let { children: messages = [] } = privateMessages.data; if (messages.length === 0) { console.log("No data available, skipping iteration"); return; } - + const { id = this._getBefore() } = messages[0].data; this._setBefore(id); messages.reverse().forEach(this.emitRedditEvent); @@ -46,7 +45,7 @@ export default { params: { before: `t4_${this._getBefore()}`, limit: 2, - } + }, }); const { children: messages = [] } = privateMessages.data;