From 2d334963d6a8967e4006a1d4cf2132e5e65cf613 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 5 Jun 2025 11:04:29 -0400 Subject: [PATCH 1/4] new components --- .../get-latest-post/get-latest-post.mjs | 19 ++++ .../get-pinned-post/get-pinned-post.mjs | 27 ++++++ .../actions/get-post/get-post.mjs | 26 ++++++ .../actions/list-posts/list-posts.mjs | 26 ++++++ components/changes_page/changes_page.app.mjs | 91 ++++++++++++++++++- components/changes_page/package.json | 5 +- .../new-post-created/new-post-created.mjs | 67 ++++++++++++++ 7 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 components/changes_page/actions/get-latest-post/get-latest-post.mjs create mode 100644 components/changes_page/actions/get-pinned-post/get-pinned-post.mjs create mode 100644 components/changes_page/actions/get-post/get-post.mjs create mode 100644 components/changes_page/actions/list-posts/list-posts.mjs create mode 100644 components/changes_page/sources/new-post-created/new-post-created.mjs diff --git a/components/changes_page/actions/get-latest-post/get-latest-post.mjs b/components/changes_page/actions/get-latest-post/get-latest-post.mjs new file mode 100644 index 0000000000000..1837939a2660b --- /dev/null +++ b/components/changes_page/actions/get-latest-post/get-latest-post.mjs @@ -0,0 +1,19 @@ +import changesPage from "../../changes_page.app.mjs"; + +export default { + key: "changes_page-get-latest-post", + name: "Get Latest Post", + description: "Get the latest post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-latest-post)", + version: "0.0.1", + type: "action", + props: { + changesPage, + }, + async run({ $ }) { + const post = await this.changesPage.getLatestPost({ + $, + }); + $.export("$summary", "Successfully retrieved latest post"); + return post; + }, +}; diff --git a/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs b/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs new file mode 100644 index 0000000000000..659defef3e127 --- /dev/null +++ b/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs @@ -0,0 +1,27 @@ +import changesPage from "../../changes_page.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + key: "changes_page-get-pinned-post", + name: "Get Pinned Post", + description: "Get the pinned post from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-pinned-post)", + version: "0.0.1", + type: "action", + props: { + changesPage, + }, + async run({ $ }) { + try { + const post = await this.changesPage.getPinnedPost({ + $, + }); + $.export("$summary", "Successfully retrieved pinned post"); + return post; + } catch (error) { + if (error.response.status === 404) { + throw new ConfigurationError("No pinned post found"); + } + throw error; + } + }, +}; diff --git a/components/changes_page/actions/get-post/get-post.mjs b/components/changes_page/actions/get-post/get-post.mjs new file mode 100644 index 0000000000000..f28172d284319 --- /dev/null +++ b/components/changes_page/actions/get-post/get-post.mjs @@ -0,0 +1,26 @@ +import changesPage from "../../changes_page.app.mjs"; + +export default { + key: "changes_page-get-post", + name: "Get Post", + description: "Get a post by ID from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-a-post-by-id)", + version: "0.0.1", + type: "action", + props: { + changesPage, + postId: { + propDefinition: [ + changesPage, + "postId", + ], + }, + }, + async run({ $ }) { + const post = await this.changesPage.getPost({ + $, + postId: this.postId, + }); + $.export("$summary", `Successfully retrieved post ${this.postId}`); + return post; + }, +}; diff --git a/components/changes_page/actions/list-posts/list-posts.mjs b/components/changes_page/actions/list-posts/list-posts.mjs new file mode 100644 index 0000000000000..6d9e4ff738d76 --- /dev/null +++ b/components/changes_page/actions/list-posts/list-posts.mjs @@ -0,0 +1,26 @@ +import changesPage from "../../changes_page.app.mjs"; + +export default { + key: "changes_page-list-posts", + name: "List Posts", + description: "Retrieve a list of posts from Changes Page. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)", + version: "0.0.1", + type: "action", + props: { + changesPage, + maxResults: { + type: "integer", + label: "Max Results", + description: "The maximum number of posts to retrieve", + default: 100, + }, + }, + async run({ $ }) { + const posts = await this.changesPage.getPaginatedResources({ + fn: this.changesPage.listPosts, + max: this.maxResults, + }); + $.export("$summary", `Successfully retrieved ${posts.length} posts`); + return posts; + }, +}; diff --git a/components/changes_page/changes_page.app.mjs b/components/changes_page/changes_page.app.mjs index 94072dd5b5b5c..af4786c03d5d3 100644 --- a/components/changes_page/changes_page.app.mjs +++ b/components/changes_page/changes_page.app.mjs @@ -1,11 +1,94 @@ +import { axios } from "@pipedream/platform"; +const DEFAULT_LIMIT = 50; + export default { type: "app", app: "changes_page", - propDefinitions: {}, + propDefinitions: { + postId: { + type: "string", + label: "Post ID", + description: "The ID of the post to retrieve", + async options({ page }) { + const posts = await this.listPosts({ + params: { + offset: page * DEFAULT_LIMIT, + }, + }); + return posts.map((post) => ({ + label: post.title, + value: post.id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.subdomain}.changes.page`; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + ...opts, + }); + }, + getPost({ + postId, ...opts + }) { + return this._makeRequest({ + path: `/changes.json/${postId}`, + ...opts, + }); + }, + getLatestPost(opts = {}) { + return this._makeRequest({ + path: "/latest.json", + ...opts, + }); + }, + getPinnedPost(opts = {}) { + return this._makeRequest({ + path: "/pinned.json", + ...opts, + }); + }, + listPosts(opts = {}) { + return this._makeRequest({ + path: "/changes.json", + ...opts, + }); + }, + async *paginate({ + fn, params = {}, max, + }) { + params = { + ...params, + offset: 0, + }; + let total, count = 0; + do { + const response = await fn({ + params, + }); + for (const item of response) { + yield item; + if (max && ++count >= max) { + return; + } + } + total = response.length; + params.offset += DEFAULT_LIMIT; + } while (total === DEFAULT_LIMIT); + }, + async getPaginatedResources(opts = {}) { + const resources = this.paginate(opts); + const items = []; + for await (const item of resources) { + items.push(item); + } + return items; }, }, }; diff --git a/components/changes_page/package.json b/components/changes_page/package.json index a493503df10c3..153bfa1e7e180 100644 --- a/components/changes_page/package.json +++ b/components/changes_page/package.json @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/changes_page/sources/new-post-created/new-post-created.mjs b/components/changes_page/sources/new-post-created/new-post-created.mjs new file mode 100644 index 0000000000000..62748ef50955f --- /dev/null +++ b/components/changes_page/sources/new-post-created/new-post-created.mjs @@ -0,0 +1,67 @@ +import changesPage from "../../changes_page.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; + +export default { + key: "changes_page-new-post-created", + name: "New Post Created", + description: "Emit new event when a new post is created. [See the documentation](https://docs.changes.page/docs/api/page#get-all-posts)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + changesPage, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs") || 0; + }, + _setLastTs(ts) { + this.db.set("lastTs", ts); + }, + generateMeta(post) { + return { + id: post.id, + summary: post.title, + ts: Date.parse(post.created_at), + }; + }, + async processEvent(max) { + const lastTs = this._getLastTs(); + const results = this.changesPage.paginate({ + fn: this.changesPage.listPosts, + max, + }); + const posts = []; + for await (const post of results) { + if (Date.parse(post.created_at) > lastTs) { + posts.push(post); + } else { + break; + } + } + if (!posts.length) { + return; + } + this._setLastTs(Date.parse(posts[0].created_at)); + posts.reverse().forEach((post) => { + const meta = this.generateMeta(post); + this.$emit(post, meta); + }); + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + }, + }, + async run() { + await this.processEvent(); + }, +}; From 062a1026ee5622c52b64634c42a4de4258575183 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 5 Jun 2025 11:05:07 -0400 Subject: [PATCH 2/4] pnpm-lock.yaml --- pnpm-lock.yaml | 52 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75fc57c631269..174fcb845b005 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2205,7 +2205,11 @@ importers: components/changenow: {} - components/changes_page: {} + components/changes_page: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/channeladvisor: dependencies: @@ -15600,14 +15604,6 @@ importers: specifier: ^6.0.0 version: 6.2.0 - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/cjs: {} - - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/esm: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/cjs: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/esm: {} - packages/ai: dependencies: '@pipedream/sdk': @@ -18726,6 +18722,9 @@ packages: '@pipedream/platform@3.0.3': resolution: {integrity: sha512-7elalas41lnT8i6EAFkqB7fT/+hkLGEQ1njS6A7CVguTrEswaIYk/seKmkfkRY7+O6qncgnXswYIKCBML9Co7w==} + '@pipedream/platform@3.1.0': + resolution: {integrity: sha512-ELmV3fpd9PIUm74/RPaqmA7hJaY4ryIn6PCNT1NP/gnqMrkRNOAr+DTV4xPaJgPiRm74WC5HvrkC8YdRveXzZA==} + '@pipedream/postgresql@2.2.3': resolution: {integrity: sha512-Co9r4UKvvimEPo9T4v+EfVn/Sqqw8+X7PtvsAF7tydq7CHpkmOT9eYAiD0Kuybg5WbuWuqDaXHHmhVtsAxgpBw==} @@ -29151,22 +29150,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==} @@ -35396,7 +35395,7 @@ snapshots: '@pipedream/docusign@0.2.1': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 transitivePeerDependencies: - debug @@ -35446,7 +35445,7 @@ snapshots: '@pipedream/linear_app@0.7.1': dependencies: '@linear/sdk': 13.0.0 - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 transitivePeerDependencies: - debug - encoding @@ -35461,7 +35460,7 @@ snapshots: '@pipedream/monday@0.7.0': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 form-data: 4.0.2 lodash.flatmap: 4.5.0 lodash.map: 4.6.0 @@ -35474,7 +35473,7 @@ snapshots: '@pipedream/notion@0.6.2': dependencies: '@notionhq/client': 2.3.0 - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 '@tryfabric/martian': 1.2.4 lodash-es: 4.17.21 notion-to-md: 3.1.8 @@ -35580,6 +35579,17 @@ snapshots: transitivePeerDependencies: - debug + '@pipedream/platform@3.1.0': + dependencies: + axios: 1.9.0 + fp-ts: 2.16.10 + io-ts: 2.2.22(fp-ts@2.16.10) + mime-types: 3.0.1 + querystring: 0.2.1 + uuid: 11.1.0 + transitivePeerDependencies: + - debug + '@pipedream/postgresql@2.2.3': dependencies: '@pipedream/platform': 2.0.0 @@ -35591,13 +35601,13 @@ snapshots: '@pipedream/quickbooks@0.5.1': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 transitivePeerDependencies: - debug '@pipedream/ramp@0.1.2': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 uuid: 10.0.0 transitivePeerDependencies: - debug @@ -35634,14 +35644,14 @@ snapshots: '@pipedream/sftp@0.4.1': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 ssh2-sftp-client: 11.0.0 transitivePeerDependencies: - debug '@pipedream/shopify@0.7.0': dependencies: - '@pipedream/platform': 3.0.3 + '@pipedream/platform': 3.1.0 async-retry: 1.3.3 bottleneck: 2.19.5 form-data: 4.0.2 From 0e2c18a3de4ea302754367aacabe0ef92d680803 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 5 Jun 2025 11:09:44 -0400 Subject: [PATCH 3/4] packages.json version --- components/changes_page/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/changes_page/package.json b/components/changes_page/package.json index 153bfa1e7e180..dcaec62ca4e32 100644 --- a/components/changes_page/package.json +++ b/components/changes_page/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/changes_page", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream changes.page Components", "main": "changes_page.app.mjs", "keywords": [ From a04af0d4bc607b10ab8c96305f2e2bd379ff46af Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 5 Jun 2025 11:26:26 -0400 Subject: [PATCH 4/4] updates --- .../changes_page/actions/get-pinned-post/get-pinned-post.mjs | 2 +- components/changes_page/changes_page.app.mjs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs b/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs index 659defef3e127..a5eaef776c24b 100644 --- a/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs +++ b/components/changes_page/actions/get-pinned-post/get-pinned-post.mjs @@ -18,7 +18,7 @@ export default { $.export("$summary", "Successfully retrieved pinned post"); return post; } catch (error) { - if (error.response.status === 404) { + if (error.response?.status === 404) { throw new ConfigurationError("No pinned post found"); } throw error; diff --git a/components/changes_page/changes_page.app.mjs b/components/changes_page/changes_page.app.mjs index af4786c03d5d3..862dce4d6a137 100644 --- a/components/changes_page/changes_page.app.mjs +++ b/components/changes_page/changes_page.app.mjs @@ -72,6 +72,9 @@ export default { const response = await fn({ params, }); + if (!response || response.length === 0) { + break; + } for (const item of response) { yield item; if (max && ++count >= max) {