Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/notion",
"version": "0.1.22",
"version": "0.1.23",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand Down
32 changes: 25 additions & 7 deletions components/notion/sources/updated-page/updated-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
key: "notion-updated-page",
name: "Updated Page in Database", /* eslint-disable-line pipedream/source-name */
description: "Emit new event when a page in a database is updated. To select a specific page, use `Updated Page ID` instead",
version: "0.0.17",
version: "0.0.18",
type: "source",
dedupe: "unique",
props: {
Expand Down Expand Up @@ -49,8 +49,9 @@ export default {
let lastUpdatedTimestamp = 0;
for await (const page of pagesStream) {
propertyValues[page.id] = {};
for (const property of properties) {
propertyValues[page.id][property] = md5(JSON.stringify(page.properties[property]));
for (const propertyName of properties) {
const hash = this.calculateHash(page.properties[propertyName]);
propertyValues[page.id][propertyName] = hash;
}
lastUpdatedTimestamp = Math.max(
lastUpdatedTimestamp,
Expand Down Expand Up @@ -80,6 +81,22 @@ export default {
const { properties } = await this.notion.retrieveDatabase(this.databaseId);
return Object.keys(properties);
},
calculateHash(property) {
const clone = structuredClone(property);
this.maybeRemoveFileSubItems(clone);
return md5(JSON.stringify(clone));
},
maybeRemoveFileSubItems(property) {
// Files & Media type:
// `url` and `expiry_time` are constantly updated by Notion, so ignore these fields
if (property.type === "files") {
for (const file of property.files) {
if (file.type === "file") {
delete file.file;
}
}
}
},
generateMeta(obj, summary) {
const { id } = obj;
const title = this.notion.extractPageTitle(obj);
Expand Down Expand Up @@ -119,13 +136,14 @@ export default {
);

let propertyChangeFound = false;
for (const property of properties) {
const currentProperty = md5(JSON.stringify(page.properties[property]));
if (!propertyValues[page.id] || currentProperty !== propertyValues[page.id][property]) {
for (const propertyName of properties) {
const hash = this.calculateHash(page.properties[propertyName]);
const dbValue = propertyValues[page.id][propertyName];
if (!propertyValues[page.id] || hash !== dbValue) {
propertyChangeFound = true;
propertyValues[page.id] = {
...propertyValues[page.id],
[property]: currentProperty,
[propertyName]: hash,
};
}
}
Expand Down
Loading