Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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.7.1",
"version": "0.7.2",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand Down
45 changes: 39 additions & 6 deletions components/notion/sources/updated-page/updated-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
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: {
Expand Down Expand Up @@ -38,16 +39,32 @@
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: {

Check warning on line 49 in components/notion/sources/updated-page/updated-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 49 in components/notion/sources/updated-page/updated-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
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();
Expand Down Expand Up @@ -124,14 +141,15 @@
: 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
Expand All @@ -149,9 +167,24 @@
},
};
let newLastUpdatedTimestamp = lastCheckedTimestamp;
const propertiesToCheck = await this._getPropertiesToCheck();
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();

for await (const page of pagesStream) {
const changes = [];
let isNewPage = false;
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading