From 5514bee3715de143131d6f6c68d859b6f7f4075c Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Wed, 23 Jul 2025 13:04:24 -0400 Subject: [PATCH 1/5] add includeChanges prop --- components/notion/package.json | 2 +- .../sources/updated-page/updated-page.mjs | 47 ++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/components/notion/package.json b/components/notion/package.json index b4335b5880bb0..026acc763ee8d 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.7.1", + "version": "0.7.2", "description": "Pipedream Notion Components", "main": "notion.app.mjs", "keywords": [ diff --git a/components/notion/sources/updated-page/updated-page.mjs b/components/notion/sources/updated-page/updated-page.mjs index 668fdbc4ff220..7726ee5bcde76 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -3,13 +3,14 @@ import sampleEmit from "./test-event.mjs"; import base from "../common/base.mjs"; import constants from "../common/constants.mjs"; import zlib from "zlib"; +import { ConfigurationError } from "@pipedream/platform"; export default { ...base, key: "notion-updated-page", name: "New or Updated Page in Database", /* eslint-disable-line pipedream/source-name */ 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: { @@ -38,16 +39,32 @@ export default { description: "Only emit events when one or more of the selected properties have changed", optional: true, }, + includeChanges: { + type: "boolean", + label: "Include Changes", + description: "If `false`, the emitted event will not include information about the specific property changes. Must be `true` if `property types` is set. Default: `true`", + default: true, + optional: true, + }, alert: { type: "alert", alertType: "warning", - content: "Source not saving? Your database might be too large. If deployment takes longer than one minute, an error will occur.", + content: "Source not saving? Your database might be too large. If deployment takes longer than one minute, an error will occur. Try removing `property types` and setting `includeChanges` to `false`.", }, }, hooks: { async activate() { - console.log("Activating: fetching pages and properties"); + if (!this.includeChanges && this.properties?.length) { + throw new ConfigurationError("`includeChanges` must be `true` if `properties` are set"); + } + this._setLastUpdatedTimestamp(Date.now()); + + if (!this.includeChanges) { + return; + } + + console.log("Activating: fetching pages and properties"); const propertyValues = {}; const propertiesToCheck = await this._getPropertiesToCheck(); const params = this.lastUpdatedSortParam(); @@ -124,14 +141,15 @@ export default { : this._generateMeta(page, constants.summaries.PAGE_UPDATED); const event = { page, - changes, }; + if (this.includeChanges) { + event.changes = changes; + } this.$emit(event, meta); }, }, async run() { const lastCheckedTimestamp = this._getLastUpdatedTimestamp(); - const propertyValues = this._getPropertyValues(); if (!lastCheckedTimestamp) { // recently updated (deactivated / activated), skip execution @@ -149,10 +167,25 @@ export default { }, }; let newLastUpdatedTimestamp = lastCheckedTimestamp; - const propertiesToCheck = await this._getPropertiesToCheck(); const pagesStream = this.notion.getPages(this.databaseId, params); - for await (const page of pagesStream) { + if (!this.includeChanges) { + for await (const page of pagesStream) { + newLastUpdatedTimestamp = Math.max( + newLastUpdatedTimestamp, + Date.parse(page.last_edited_time), + ); + const isNewPage = page.last_edited_time === page.created_time; + this._emitEvent(page, [], isNewPage); + } + this._setLastUpdatedTimestamp(newLastUpdatedTimestamp); + return; + } + + const propertiesToCheck = await this._getPropertiesToCheck(); + const propertyValues = this._getPropertyValues(); + + for await (const page of pagesStream) { console.log(page); const changes = []; let isNewPage = false; let propertyHasChanged = false; From 27c634410874a663bdb2c2da2ec01863038bb8f5 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Wed, 23 Jul 2025 13:05:16 -0400 Subject: [PATCH 2/5] pnpm-lock.yaml --- pnpm-lock.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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==} From d1651f80b35d504516388ed9784a3e40e88ee0f4 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Wed, 23 Jul 2025 13:07:50 -0400 Subject: [PATCH 3/5] remove console.log --- components/notion/sources/updated-page/updated-page.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/notion/sources/updated-page/updated-page.mjs b/components/notion/sources/updated-page/updated-page.mjs index 7726ee5bcde76..ab49b6d0545ba 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -185,7 +185,7 @@ export default { const propertiesToCheck = await this._getPropertiesToCheck(); const propertyValues = this._getPropertyValues(); - for await (const page of pagesStream) { console.log(page); + for await (const page of pagesStream) { const changes = []; let isNewPage = false; let propertyHasChanged = false; From f0513c3ed49eab21bb808856dc6d39fe16d7bb9c Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 24 Jul 2025 11:20:48 -0400 Subject: [PATCH 4/5] revert updated-page.mjs --- .../sources/updated-page/updated-page.mjs | 43 +++---------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/components/notion/sources/updated-page/updated-page.mjs b/components/notion/sources/updated-page/updated-page.mjs index ab49b6d0545ba..c46210f7f0152 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -3,7 +3,6 @@ import sampleEmit from "./test-event.mjs"; import base from "../common/base.mjs"; import constants from "../common/constants.mjs"; import zlib from "zlib"; -import { ConfigurationError } from "@pipedream/platform"; export default { ...base, @@ -39,32 +38,16 @@ export default { description: "Only emit events when one or more of the selected properties have changed", optional: true, }, - includeChanges: { - type: "boolean", - label: "Include Changes", - description: "If `false`, the emitted event will not include information about the specific property changes. Must be `true` if `property types` is set. Default: `true`", - default: true, - optional: true, - }, alert: { type: "alert", alertType: "warning", - content: "Source not saving? Your database might be too large. If deployment takes longer than one minute, an error will occur. Try removing `property types` and setting `includeChanges` to `false`.", + content: "Source not saving? Your database might be too large. If deployment takes longer than one minute, an error will occur.", }, }, hooks: { async activate() { - if (!this.includeChanges && this.properties?.length) { - throw new ConfigurationError("`includeChanges` must be `true` if `properties` are set"); - } - - this._setLastUpdatedTimestamp(Date.now()); - - if (!this.includeChanges) { - return; - } - console.log("Activating: fetching pages and properties"); + this._setLastUpdatedTimestamp(Date.now()); const propertyValues = {}; const propertiesToCheck = await this._getPropertiesToCheck(); const params = this.lastUpdatedSortParam(); @@ -141,15 +124,14 @@ export default { : this._generateMeta(page, constants.summaries.PAGE_UPDATED); const event = { page, + changes, }; - if (this.includeChanges) { - event.changes = changes; - } this.$emit(event, meta); }, }, async run() { const lastCheckedTimestamp = this._getLastUpdatedTimestamp(); + const propertyValues = this._getPropertyValues(); if (!lastCheckedTimestamp) { // recently updated (deactivated / activated), skip execution @@ -167,23 +149,8 @@ export default { }, }; let newLastUpdatedTimestamp = lastCheckedTimestamp; - const pagesStream = this.notion.getPages(this.databaseId, params); - - if (!this.includeChanges) { - for await (const page of pagesStream) { - newLastUpdatedTimestamp = Math.max( - newLastUpdatedTimestamp, - Date.parse(page.last_edited_time), - ); - const isNewPage = page.last_edited_time === page.created_time; - this._emitEvent(page, [], isNewPage); - } - this._setLastUpdatedTimestamp(newLastUpdatedTimestamp); - return; - } - const propertiesToCheck = await this._getPropertiesToCheck(); - const propertyValues = this._getPropertyValues(); + const pagesStream = this.notion.getPages(this.databaseId, params); for await (const page of pagesStream) { const changes = []; From a614172dc1be320f671ffe5ed34341abd180e80b Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 24 Jul 2025 11:55:12 -0400 Subject: [PATCH 5/5] updated-page-by-timestamp source --- components/notion/package.json | 2 +- .../updated-page-by-timestamp/test-event.mjs | 59 +++++++++++++ .../updated-page-by-timestamp.mjs | 87 +++++++++++++++++++ .../sources/updated-page/updated-page.mjs | 2 +- 4 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 components/notion/sources/updated-page-by-timestamp/test-event.mjs create mode 100644 components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs diff --git a/components/notion/package.json b/components/notion/package.json index 026acc763ee8d..6d5b5a5dc3928 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.7.2", + "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 c46210f7f0152..af299d9464419 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -7,7 +7,7 @@ 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.8", type: "source",