Skip to content

Commit 4abd414

Browse files
committed
Lots of other data source updates
1 parent fe0fcba commit 4abd414

File tree

17 files changed

+90
-200
lines changed

17 files changed

+90
-200
lines changed

components/notion/actions/create-page-from-database/create-page-from-database.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,16 @@ import base from "../common/base-page-builder.mjs";
66
export default {
77
...base,
88
key: "notion-create-page-from-database",
9-
name: "Create Page from Database",
10-
description: "Create a page from a database. [See the documentation](https://developers.notion.com/reference/post-page)",
9+
name: "Create Page from Data Source",
10+
description: "Create a page from a data source. [See the documentation](https://developers.notion.com/reference/post-page)",
1111
version: "1.0.0",
1212
type: "action",
1313
props: {
1414
notion,
15-
parent: {
16-
propDefinition: [
17-
notion,
18-
"databaseId",
19-
],
20-
},
2115
parentDataSource: {
2216
propDefinition: [
2317
notion,
2418
"dataSourceId",
25-
({ parent }) => ({
26-
databaseId: parent,
27-
}),
2819
],
2920
label: "Parent Data Source ID",
3021
description: "Select a parent data source or provide a data source ID",

components/notion/actions/query-database/query-database.mjs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,14 @@ export default {
55
key: "notion-query-database",
66
name: "Query Data Source",
77
description: "Query a data source with a specified filter. [See the documentation](https://developers.notion.com/reference/query-a-data-source)",
8-
version: "1.0.0",
8+
version: "1.0.{{ts}}",
99
type: "action",
1010
props: {
1111
notion,
12-
databaseId: {
13-
propDefinition: [
14-
notion,
15-
"databaseId",
16-
],
17-
},
1812
dataSourceId: {
1913
propDefinition: [
2014
notion,
2115
"dataSourceId",
22-
({ databaseId }) => ({
23-
databaseId,
24-
}),
2516
],
2617
},
2718
filter: {

components/notion/actions/retrieve-database-content/retrieve-database-content.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ export default {
88
type: "action",
99
props: {
1010
notion,
11-
databaseId: {
12-
propDefinition: [
13-
notion,
14-
"databaseId",
15-
],
16-
},
1711
dataSourceId: {
1812
propDefinition: [
1913
notion,
2014
"dataSourceId",
21-
({ databaseId }) => ({
22-
databaseId,
23-
}),
2415
],
2516
},
2617
},

components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ export default {
88
type: "action",
99
props: {
1010
notion,
11-
databaseId: {
12-
propDefinition: [
13-
notion,
14-
"databaseId",
15-
],
16-
},
1711
dataSourceId: {
1812
propDefinition: [
1913
notion,
2014
"dataSourceId",
21-
({ databaseId }) => ({
22-
databaseId,
23-
}),
2415
],
2516
},
2617
},

components/notion/actions/update-database/update-database.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ export default {
1111
type: "action",
1212
props: {
1313
notion,
14-
databaseId: {
15-
propDefinition: [
16-
notion,
17-
"databaseId",
18-
],
19-
},
2014
dataSourceId: {
2115
propDefinition: [
2216
notion,
2317
"dataSourceId",
24-
({ databaseId }) => ({
25-
databaseId,
26-
}),
2718
],
2819
reloadProps: true,
2920
},
@@ -47,7 +38,7 @@ export default {
4738
},
4839
},
4940
async additionalProps(props) {
50-
if (this.databaseId && this.dataSourceId) {
41+
if (this.dataSourceId) {
5142
const dataSource = await this.notion.retrieveDataSource(this.dataSourceId);
5243

5344
props.title.default = dataSource.title.map((text) => text.text.content).join(" ");
@@ -64,7 +55,7 @@ export default {
6455
},
6556
async run({ $ }) {
6657
const response = await this.notion.updateDataSource({
67-
dataSource_id: this.dataSourceId,
58+
data_source_id: this.dataSourceId,
6859
title: [
6960
{
7061
text: {

components/notion/actions/update-page/update-page.mjs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@ export default {
1616
alertType: "info",
1717
content: "Properties that are not set will remain unchanged.",
1818
},
19-
parent: {
20-
propDefinition: [
21-
notion,
22-
"databaseId",
23-
],
24-
},
2519
parentDataSource: {
2620
propDefinition: [
2721
notion,
2822
"dataSourceId",
29-
(c) => ({
30-
databaseId: c.parent,
31-
}),
3223
],
3324
label: "Parent Data Source ID",
3425
description: "Select the data source that contains the page to update. If you instead provide a data source ID in a custom expression, you will also have to provide the page's ID in a custom expression",
@@ -61,7 +52,7 @@ export default {
6152
"propertyTypes",
6253
(c) => ({
6354
parentId: c.parentDataSource,
64-
parentType: "dataSource",
55+
parentType: "data_source",
6556
}),
6657
],
6758
reloadProps: true,

components/notion/notion.app.mjs

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,18 @@ export default {
77
type: "app",
88
app: "notion",
99
propDefinitions: {
10-
databaseId: {
10+
dataSourceId: {
1111
type: "string",
12-
label: "Database ID",
13-
description: "Select a database or provide a database ID",
12+
label: "Data Source ID",
13+
description: "Select a data source or provide a data source ID",
1414
async options({ prevContext }) {
15-
const response = await this.listDatabases({
15+
const response = await this.listDataSources({
1616
start_cursor: prevContext.nextPageParameters ?? undefined,
1717
});
18-
const options = this._extractDatabaseTitleOptions(response.results);
18+
const options = this._extractDataSourceTitleOptions(response.results);
1919
return this._buildPaginatedOptions(options, response.next_cursor);
2020
},
2121
},
22-
dataSourceId: {
23-
type: "string",
24-
label: "Data Source ID",
25-
description: "Select a data source from the database or provide a data source ID",
26-
async options({ databaseId }) {
27-
this._checkOptionsContext(databaseId, "Database ID");
28-
const response = await this.getDataSourcesForDatabase(databaseId);
29-
return this._extractDatabaseTitleOptions(response);
30-
},
31-
},
3222
pageId: {
3323
type: "string",
3424
label: "Page ID",
@@ -113,10 +103,10 @@ export default {
113103
async options({
114104
parentId, parentType,
115105
}) {
116-
this._checkOptionsContext(parentId, "Database ID");
106+
this._checkOptionsContext(parentId, "Data Source ID");
117107
try {
118-
const { properties } = parentType === "database"
119-
? await this.retrieveDatabase(parentId)
108+
const { properties } = parentType === "data_source"
109+
? await this.retrieveDataSource(parentId)
120110
: await this.retrievePage(parentId);
121111
return Object.keys(properties);
122112
} catch (error) {
@@ -232,7 +222,7 @@ export default {
232222
notionVersion: "2025-09-03",
233223
});
234224
},
235-
_extractDatabaseTitleOptions(databases) {
225+
_extractDataSourceTitleOptions(databases) {
236226
return databases.map((database) => {
237227
const title = database.title
238228
.map((title) => title.plain_text)
@@ -266,8 +256,8 @@ export default {
266256
},
267257
};
268258
},
269-
extractDatabaseTitle(database) {
270-
return this._extractDatabaseTitleOptions([
259+
extractDataSourceTitle(database) {
260+
return this._extractDataSourceTitleOptions([
271261
database,
272262
])[0].label;
273263
},
@@ -276,31 +266,25 @@ export default {
276266
page,
277267
])[0].label;
278268
},
279-
async listDatabases(params = {}) {
269+
async listDataSources(params = {}) {
280270
return this._getNotionClient().search({
281271
filter: {
282272
property: "object",
283-
value: "database",
273+
value: "data_source",
284274
},
285275
...params,
286276
});
287277
},
288-
async queryDatabase(databaseId, params = {}) {
289-
return this._getNotionClient().databases.query({
290-
database_id: databaseId,
291-
...params,
292-
});
293-
},
294-
async retrieveDatabase(databaseId) {
295-
return this._getNotionClient().databases.retrieve({
296-
database_id: databaseId,
278+
async retrieveDataSource(dataSourceId) {
279+
return this._getNotionClient().dataSources.retrieve({
280+
data_source_id: dataSourceId,
297281
});
298282
},
299283
async createDatabase(database) {
300284
return this._getNotionClient().databases.create(database);
301285
},
302-
async updateDatabase(database) {
303-
return this._getNotionClient().databases.update(database);
286+
async updateDataSource(database) {
287+
return this._getNotionClient().dataSources.update(database);
304288
},
305289
async queryDataSource(dataSourceId, params = {}) {
306290
return this._getNotionClient().request({
@@ -309,16 +293,6 @@ export default {
309293
body: params,
310294
});
311295
},
312-
async retrieveDataSource(dataSourceId) {
313-
return this._getNotionClient().request({
314-
method: "GET",
315-
path: `data_sources/${dataSourceId}`,
316-
});
317-
},
318-
async getDataSourcesForDatabase(databaseId) {
319-
const database = await this.retrieveDatabase(databaseId);
320-
return database.data_sources || [];
321-
},
322296
async createFileUpload(file) {
323297
return this._getNotionClient().fileUploads.create(file);
324298
},

components/notion/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.10.1",
3+
"version": "1.0.0",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/notion",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@notionhq/client": "4.0.2",
13+
"@notionhq/client": "^5.0.0",
1414
"@pipedream/platform": "^3.1.0",
1515
"@tryfabric/martian": "^1.2.4",
1616
"lodash-es": "^4.17.21",

components/notion/sources/common/base.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default {
3535
const ts = Date.parse(lastTime);
3636

3737
if (type === constants.types.DATABASE || type === constants.types.DATA_SOURCE) {
38-
title = this.notion.extractDatabaseTitle(obj);
38+
title = this.notion.extractDataSourceTitle(obj);
3939
} else {
4040
title = this.notion.extractPageTitle(obj);
4141
// Create composite ID so update events for the same page have unique keys
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import base from "../common/base.mjs";
2+
import constants from "../common/constants.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
...base,
7+
key: "notion-new-data-source",
8+
name: "New Data Source Created",
9+
description: "Emit new event when a data source is created. [See the documentation](https://developers.notion.com/reference/data-source)",
10+
version: "0.0.1",
11+
type: "source",
12+
props: {
13+
...base.props,
14+
infoLabel: {
15+
type: "alert",
16+
alertType: "info",
17+
content: "Ensure Data Sources are shared with your Pipedream integration to receive events.",
18+
},
19+
},
20+
async run() {
21+
const dataSources = [];
22+
const params = this.lastCreatedSortParam();
23+
const lastCreatedTimestamp = this.getLastCreatedTimestamp();
24+
25+
do {
26+
const response = await this.notion.listDataSources(params);
27+
28+
for (const dataSource of response.results) {
29+
if (!this.isResultNew(dataSource.created_time, lastCreatedTimestamp)) {
30+
params.start_cursor = null;
31+
break;
32+
}
33+
dataSources.push(dataSource);
34+
}
35+
36+
params.start_cursor = response.next_cursor;
37+
} while (params.start_cursor);
38+
39+
dataSources.reverse().forEach((dataSource) => {
40+
const meta = this.generateMeta(
41+
dataSource,
42+
constants.types.DATA_SOURCE,
43+
constants.timestamps.CREATED_TIME,
44+
constants.summaries.DATA_SOURCE_ADDED,
45+
);
46+
this.$emit(dataSource, meta);
47+
});
48+
49+
const lastCreatedTime = dataSources[dataSources.length - 1]?.created_time;
50+
if (lastCreatedTime) {
51+
this.setLastCreatedTimestamp(Date.parse(lastCreatedTime));
52+
}
53+
},
54+
sampleEmit,
55+
};

0 commit comments

Comments
 (0)