diff --git a/components/notion/package.json b/components/notion/package.json index b4335b5880bb0..6d5b5a5dc3928 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.7.1", + "version": "0.8.0", "description": "Pipedream Notion Components", "main": "notion.app.mjs", "keywords": [ diff --git a/components/notion/sources/updated-page-by-timestamp/test-event.mjs b/components/notion/sources/updated-page-by-timestamp/test-event.mjs new file mode 100644 index 0000000000000..a88c4999c8314 --- /dev/null +++ b/components/notion/sources/updated-page-by-timestamp/test-event.mjs @@ -0,0 +1,59 @@ +export default { + "object": "page", + "id": "15e73a03-a25e-811d-8ff0-e99f0561c344", + "created_time": "2024-12-16T22:15:00.000Z", + "last_edited_time": "2025-07-23T17:00:00.000Z", + "created_by": { + "object": "user", + "id": "a697c2ad-539d-4523-a9e8-66f855e6caef" + }, + "last_edited_by": { + "object": "user", + "id": "a697c2ad-539d-4523-a9e8-66f855e6caef" + }, + "cover": null, + "icon": null, + "parent": { + "type": "database_id", + "database_id": "9813bf8c-a429-4d63-b73b-f476783ff448" + }, + "archived": false, + "in_trash": false, + "properties": { + "Created": { + "id": "GsAx", + "type": "created_time", + "created_time": "2024-12-16T22:15:00.000Z" + }, + "Tags": { + "id": "h~%7Da", + "type": "multi_select", + "multi_select": [] + }, + "Name": { + "id": "title", + "type": "title", + "title": [ + { + "type": "text", + "text": { + "content": "TestPage", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "TestPage", + "href": null + } + ] + } + }, + "url": "https://www.notion.so/TestPage-15e73a03a25e811d8ff0e99f0561c344", + "public_url": "https://held-danger-051.notion.site/TestPage-15e73a03a25e811d8ff0e99f0561c344" +} \ No newline at end of file diff --git a/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs b/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs new file mode 100644 index 0000000000000..23e4ca15dedeb --- /dev/null +++ b/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs @@ -0,0 +1,87 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base.mjs"; +import constants from "../common/constants.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...base, + key: "notion-updated-page-by-timestamp", + name: "New or Updated Page in Database (By Timestamp)", + description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...base.props, + databaseId: { + propDefinition: [ + notion, + "databaseId", + ], + }, + includeNewPages: { + type: "boolean", + label: "Include New Pages", + description: "Set to `false` to emit events only for updates, not for new pages.", + default: true, + }, + }, + methods: { + ...base.methods, + _generateMeta(obj, summary) { + const { id } = obj; + const title = this.notion.extractPageTitle(obj); + const ts = Date.parse(obj.last_edited_time); + return { + id: `${id}-${ts}`, + summary: `${summary}: ${title}`, + ts, + }; + }, + _emitEvent(page, isNewPage = true) { + const meta = isNewPage + ? this._generateMeta(page, constants.summaries.PAGE_ADDED) + : this._generateMeta(page, constants.summaries.PAGE_UPDATED); + this.$emit(page, meta); + }, + }, + async run() { + const lastUpdatedTimestamp = this.getLastUpdatedTimestamp(); + let newLastUpdatedTimestamp = lastUpdatedTimestamp; + + const params = { + ...this.lastUpdatedSortParam(), + filter: { + timestamp: "last_edited_time", + last_edited_time: { + on_or_after: new Date(lastUpdatedTimestamp).toISOString(), + }, + }, + }; + + const pagesStream = this.notion.getPages(this.databaseId, params); + + for await (const page of pagesStream) { + if (lastUpdatedTimestamp > Date.parse(page.last_edited_time)) { + break; + } + + newLastUpdatedTimestamp = Math.max( + newLastUpdatedTimestamp, + Date.parse(page.last_edited_time), + ); + + const isNewPage = page.last_edited_time === page.created_time; + + if (isNewPage && !this.includeNewPages) { + console.log(`Ignoring new page: ${page.id}`); + continue; + } + + this._emitEvent(page, isNewPage); + } + + this.setLastUpdatedTimestamp(newLastUpdatedTimestamp); + }, + sampleEmit, +}; diff --git a/components/notion/sources/updated-page/updated-page.mjs b/components/notion/sources/updated-page/updated-page.mjs index 668fdbc4ff220..af299d9464419 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -7,9 +7,9 @@ import zlib from "zlib"; export default { ...base, key: "notion-updated-page", - name: "New or Updated Page in Database", /* eslint-disable-line pipedream/source-name */ + name: "New or Updated Page in Database (By Property)", description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)", - version: "0.1.7", + version: "0.1.8", type: "source", dedupe: "unique", props: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 914682d319f4c..31e3b1306da74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29979,22 +29979,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + 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 superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + 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 superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + 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 upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + 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==}