diff --git a/components/notion/actions/create-comment/create-comment.mjs b/components/notion/actions/create-comment/create-comment.mjs new file mode 100644 index 0000000000000..8471473e20d62 --- /dev/null +++ b/components/notion/actions/create-comment/create-comment.mjs @@ -0,0 +1,53 @@ +import notion from "../../notion.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + key: "notion-create-comment", + name: "Create Comment", + description: "Creates a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)", + version: "0.0.1", + type: "action", + props: { + notion, + pageId: { + propDefinition: [ + notion, + "pageId", + ], + description: "Unique identifier of a page. Either this or a Discussion ID is required (not both)", + optional: true, + }, + discussionId: { + type: "string", + label: "Discussion ID", + description: "A UUID identifier for a discussion thread. Either this or a Page ID is required (not both)", + optional: true, + }, + comment: { + type: "string", + label: "Comment", + description: "The comment text", + }, + }, + async run({ $ }) { + if ((this.pageId && this.discussionId) || (!this.pageId && !this.discussionId)) { + throw new ConfigurationError("Either a Page ID or a Discussion ID is required (not both)"); + } + + const response = await this.notion._getNotionClient().comments.create({ + parent: this.pageId && { + page_id: this.pageId, + }, + discussion_id: this.discussionId, + rich_text: [ + { + text: { + content: this.comment, + }, + }, + ], + }); + $.export("$summary", `Successfully added comment with ID: ${response.id}`); + return response; + }, +}; diff --git a/components/notion/package.json b/components/notion/package.json index 8d9c22a9dd694..c06202a516975 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.2.7", + "version": "0.3.0", "description": "Pipedream Notion Components", "main": "notion.app.mjs", "keywords": [ @@ -11,6 +11,7 @@ "author": "Pipedream (https://pipedream.com/)", "dependencies": { "@notionhq/client": "^2.2.3", + "@pipedream/platform": "^3.0.3", "@tryfabric/martian": "^1.2.4", "asynckit": "^0.4.0", "combined-stream": "^1.0.8", diff --git a/components/notion/sources/new-comment-created/new-comment-created.mjs b/components/notion/sources/new-comment-created/new-comment-created.mjs new file mode 100644 index 0000000000000..b8b04ae1ebb5a --- /dev/null +++ b/components/notion/sources/new-comment-created/new-comment-created.mjs @@ -0,0 +1,59 @@ +import base from "../common/base.mjs"; + +export default { + ...base, + key: "notion-new-comment-created", + name: "New Comment Created", + description: "Emit new event when a new comment is created in a page or block. [See the documentation](https://developers.notion.com/reference/retrieve-a-comment)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...base.props, + pageId: { + propDefinition: [ + base.props.notion, + "pageId", + ], + description: "Unique identifier of a page or block", + }, + }, + methods: { + ...base.methods, + generateMeta(comment) { + return { + id: comment.id, + summary: `New Comment ID: ${comment.id}`, + ts: comment.created_time, + }; + }, + }, + async run() { + const lastTs = this.getLastCreatedTimestamp(); + let maxTs = lastTs; + let cursor; + + do { + const { + results, next_cursor: next, + } = await this.notion._getNotionClient().comments.list({ + block_id: this.pageId, + start_cursor: cursor, + page_size: 100, + }); + if (!results?.length) { + break; + } + for (const comment of results) { + const ts = Date.parse(comment.created_time); + if (ts >= lastTs) { + maxTs = Math.max(ts, maxTs); + this.$emit(comment, this.generateMeta(comment)); + } + } + cursor = next; + } while (cursor); + + this.setLastCreatedTimestamp(maxTs); + }, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79157dbac0937..62dd1d0144765 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1005,8 +1005,7 @@ importers: specifier: ^9.0.1 version: 9.0.1 - components/azure_storage: - specifiers: {} + components/azure_storage: {} components/backblaze: {} @@ -3104,8 +3103,7 @@ importers: components/easypost: {} - components/easypromos: - specifiers: {} + components/easypromos: {} components/easysendy: dependencies: @@ -3159,8 +3157,7 @@ importers: specifier: ^4.0.0 version: 4.0.1 - components/elevio: - specifiers: {} + components/elevio: {} components/elmah_io: dependencies: @@ -4823,8 +4820,7 @@ importers: specifier: ^1.6.0 version: 1.6.6 - components/homerun: - specifiers: {} + components/homerun: {} components/hookdeck: dependencies: @@ -6943,6 +6939,9 @@ importers: '@notionhq/client': specifier: ^2.2.3 version: 2.2.15 + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 '@tryfabric/martian': specifier: ^1.2.4 version: 1.2.4 @@ -8319,8 +8318,7 @@ importers: specifier: ^1.1.1 version: 1.6.6 - components/ragie: - specifiers: {} + components/ragie: {} components/railsr: {} @@ -8513,8 +8511,7 @@ importers: specifier: ^1.3.0 version: 1.6.6 - components/refiner: - specifiers: {} + components/refiner: {} components/reflect: dependencies: @@ -11049,8 +11046,7 @@ importers: specifier: ^6.2.13 version: 6.2.13 - components/typefully: - specifiers: {} + components/typefully: {} components/typless: {} @@ -11575,8 +11571,7 @@ importers: components/weworkbook: {} - components/what_are_those: - specifiers: {} + components/what_are_those: {} components/whatconverts: {} @@ -24688,22 +24683,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - 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 + 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 . superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - 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 + 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 . superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - 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 + 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 . superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - 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 + 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) supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}