Skip to content

Commit 0471e62

Browse files
authored
Notion - update to New or Updated Page in Database source (#17762)
* add includeChanges prop * pnpm-lock.yaml * remove console.log * revert updated-page.mjs * updated-page-by-timestamp source
1 parent be3ee1d commit 0471e62

File tree

4 files changed

+149
-3
lines changed

4 files changed

+149
-3
lines changed

components/notion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.7.1",
3+
"version": "0.8.0",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
export default {
2+
"object": "page",
3+
"id": "15e73a03-a25e-811d-8ff0-e99f0561c344",
4+
"created_time": "2024-12-16T22:15:00.000Z",
5+
"last_edited_time": "2025-07-23T17:00:00.000Z",
6+
"created_by": {
7+
"object": "user",
8+
"id": "a697c2ad-539d-4523-a9e8-66f855e6caef"
9+
},
10+
"last_edited_by": {
11+
"object": "user",
12+
"id": "a697c2ad-539d-4523-a9e8-66f855e6caef"
13+
},
14+
"cover": null,
15+
"icon": null,
16+
"parent": {
17+
"type": "database_id",
18+
"database_id": "9813bf8c-a429-4d63-b73b-f476783ff448"
19+
},
20+
"archived": false,
21+
"in_trash": false,
22+
"properties": {
23+
"Created": {
24+
"id": "GsAx",
25+
"type": "created_time",
26+
"created_time": "2024-12-16T22:15:00.000Z"
27+
},
28+
"Tags": {
29+
"id": "h~%7Da",
30+
"type": "multi_select",
31+
"multi_select": []
32+
},
33+
"Name": {
34+
"id": "title",
35+
"type": "title",
36+
"title": [
37+
{
38+
"type": "text",
39+
"text": {
40+
"content": "TestPage",
41+
"link": null
42+
},
43+
"annotations": {
44+
"bold": false,
45+
"italic": false,
46+
"strikethrough": false,
47+
"underline": false,
48+
"code": false,
49+
"color": "default"
50+
},
51+
"plain_text": "TestPage",
52+
"href": null
53+
}
54+
]
55+
}
56+
},
57+
"url": "https://www.notion.so/TestPage-15e73a03a25e811d8ff0e99f0561c344",
58+
"public_url": "https://held-danger-051.notion.site/TestPage-15e73a03a25e811d8ff0e99f0561c344"
59+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import notion from "../../notion.app.mjs";
2+
import base from "../common/base.mjs";
3+
import constants from "../common/constants.mjs";
4+
import sampleEmit from "./test-event.mjs";
5+
6+
export default {
7+
...base,
8+
key: "notion-updated-page-by-timestamp",
9+
name: "New or Updated Page in Database (By Timestamp)",
10+
description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)",
11+
version: "0.0.1",
12+
type: "source",
13+
dedupe: "unique",
14+
props: {
15+
...base.props,
16+
databaseId: {
17+
propDefinition: [
18+
notion,
19+
"databaseId",
20+
],
21+
},
22+
includeNewPages: {
23+
type: "boolean",
24+
label: "Include New Pages",
25+
description: "Set to `false` to emit events only for updates, not for new pages.",
26+
default: true,
27+
},
28+
},
29+
methods: {
30+
...base.methods,
31+
_generateMeta(obj, summary) {
32+
const { id } = obj;
33+
const title = this.notion.extractPageTitle(obj);
34+
const ts = Date.parse(obj.last_edited_time);
35+
return {
36+
id: `${id}-${ts}`,
37+
summary: `${summary}: ${title}`,
38+
ts,
39+
};
40+
},
41+
_emitEvent(page, isNewPage = true) {
42+
const meta = isNewPage
43+
? this._generateMeta(page, constants.summaries.PAGE_ADDED)
44+
: this._generateMeta(page, constants.summaries.PAGE_UPDATED);
45+
this.$emit(page, meta);
46+
},
47+
},
48+
async run() {
49+
const lastUpdatedTimestamp = this.getLastUpdatedTimestamp();
50+
let newLastUpdatedTimestamp = lastUpdatedTimestamp;
51+
52+
const params = {
53+
...this.lastUpdatedSortParam(),
54+
filter: {
55+
timestamp: "last_edited_time",
56+
last_edited_time: {
57+
on_or_after: new Date(lastUpdatedTimestamp).toISOString(),
58+
},
59+
},
60+
};
61+
62+
const pagesStream = this.notion.getPages(this.databaseId, params);
63+
64+
for await (const page of pagesStream) {
65+
if (lastUpdatedTimestamp > Date.parse(page.last_edited_time)) {
66+
break;
67+
}
68+
69+
newLastUpdatedTimestamp = Math.max(
70+
newLastUpdatedTimestamp,
71+
Date.parse(page.last_edited_time),
72+
);
73+
74+
const isNewPage = page.last_edited_time === page.created_time;
75+
76+
if (isNewPage && !this.includeNewPages) {
77+
console.log(`Ignoring new page: ${page.id}`);
78+
continue;
79+
}
80+
81+
this._emitEvent(page, isNewPage);
82+
}
83+
84+
this.setLastUpdatedTimestamp(newLastUpdatedTimestamp);
85+
},
86+
sampleEmit,
87+
};

components/notion/sources/updated-page/updated-page.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import zlib from "zlib";
77
export default {
88
...base,
99
key: "notion-updated-page",
10-
name: "New or Updated Page in Database", /* eslint-disable-line pipedream/source-name */
10+
name: "New or Updated Page in Database (By Property)",
1111
description: "Emit new event when a page is created or updated in the selected database. [See the documentation](https://developers.notion.com/reference/page)",
12-
version: "0.1.7",
12+
version: "0.1.8",
1313
type: "source",
1414
dedupe: "unique",
1515
props: {

0 commit comments

Comments
 (0)