Skip to content

Commit

Permalink
[Notion] updated page trigger fix (#14116)
Browse files Browse the repository at this point in the history
* remove url and expiry_time for file properties

* bump versions

* refactor a bit

* use structuredClone
  • Loading branch information
andrewjschuang authored Sep 26, 2024
1 parent 7d93e79 commit ab316a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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

0 comments on commit ab316a1

Please sign in to comment.