-
Notifications
You must be signed in to change notification settings - Fork 4
Add Notion plugin #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clarkd
wants to merge
5
commits into
main
Choose a base branch
from
plugin/add-notion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "displayName": "Authenticate", | ||
| "dataStream": { "name": "currentUser" }, | ||
| "required": true, | ||
| "error": "Could not connect to Notion. Make sure you have signed in and authorised access to your workspace.", | ||
| "success": "Connected to Notion successfully." | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "name": "Notion User", | ||
| "sourceType": "Notion User", | ||
| "icon": "user", | ||
| "singular": "User", | ||
| "plural": "Users" | ||
| }, | ||
| { | ||
| "name": "Notion Data Source", | ||
| "sourceType": "Notion Data Source", | ||
| "icon": "table", | ||
| "singular": "Data Source", | ||
| "plural": "Data Sources" | ||
| }, | ||
| { | ||
| "name": "Notion Page", | ||
| "sourceType": "Notion Page", | ||
| "icon": "file-lines", | ||
| "singular": "Page", | ||
| "plural": "Pages" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "currentUser", | ||
| "displayName": "Current User", | ||
| "description": "The authenticated Notion bot user and its workspace", | ||
| "tags": ["Account"], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "users/me", | ||
| "postRequestScript": "currentUser.js" | ||
| }, | ||
| "matches": "none", | ||
| "visibility": { "type": "hidden" }, | ||
| "metadata": [ | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "workspaceName", "displayName": "Workspace", "shape": "string" }, | ||
| { "name": "type", "displayName": "Type", "shape": "string" }, | ||
| { "name": "id", "displayName": "ID", "shape": "string", "role": "id", "visible": false } | ||
| ], | ||
| "timeframes": false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "name": "dataSourceRows", | ||
| "displayName": "Data Source Contents", | ||
| "description": "Pages within a data source with their property values", | ||
| "tags": ["Data Sources", "Pages"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "config": { | ||
| "httpMethod": "post", | ||
| "endpointPath": "data_sources/{{object.rawId}}/query", | ||
| "postBody": {}, | ||
| "postRequestScript": "dataSourceRows.js", | ||
| "paging": { | ||
| "mode": "token", | ||
| "pageSize": { "realm": "body", "path": "page_size", "value": 100 }, | ||
| "in": { "realm": "payload", "path": "next_cursor" }, | ||
| "out": { "realm": "body", "path": "start_cursor" } | ||
| } | ||
| }, | ||
| "matches": { | ||
| "sourceType": { "type": "oneOf", "values": ["Notion Data Source"] } | ||
| }, | ||
| "metadata": [ | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "lastEditedTime", "displayName": "Last Edited", "shape": "date" }, | ||
| { "name": "createdTime", "displayName": "Created", "shape": "date", "visible": false }, | ||
| { "name": "url", "displayName": "URL", "shape": ["url", { "label": "Open in Notion" }], "visible": false }, | ||
| { "name": "id", "displayName": "ID", "shape": "string", "role": "id", "visible": false }, | ||
| { "pattern": ".*" } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "dataSourceSchema", | ||
| "displayName": "Data Source Schema", | ||
| "description": "Property names and types (schema) for a single data source", | ||
| "tags": ["Data Sources"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "data_sources/{{object.rawId}}", | ||
| "paging": { "mode": "none" }, | ||
| "postRequestScript": "dataSourceSchema.js" | ||
| }, | ||
| "matches": { | ||
| "sourceType": { "type": "oneOf", "values": ["Notion Data Source"] } | ||
| }, | ||
| "metadata": [ | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "type", "displayName": "Type", "shape": "string" }, | ||
| { "name": "details", "displayName": "Details", "shape": "string" } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "dataSourcesSearch", | ||
| "displayName": "Data Sources", | ||
| "description": "Data sources (database tables) shared with the integration", | ||
| "tags": ["Data Sources"], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "post", | ||
| "endpointPath": "search", | ||
| "postBody": { "filter": { "property": "object", "value": "data_source" } }, | ||
| "postRequestScript": "dataSourcesSearch.js", | ||
| "paging": { | ||
| "mode": "token", | ||
| "pageSize": { "realm": "body", "path": "page_size", "value": 100 }, | ||
| "in": { "realm": "payload", "path": "next_cursor" }, | ||
| "out": { "realm": "body", "path": "start_cursor" } | ||
| } | ||
| }, | ||
| "matches": "none", | ||
| "metadata": [ | ||
| { "name": "id", "displayName": "ID", "shape": "string", "role": "id", "visible": false }, | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "createdTime", "displayName": "Created", "shape": "date" }, | ||
| { "name": "lastEditedTime", "displayName": "Last Edited", "shape": "date" }, | ||
| { "name": "url", "displayName": "URL", "shape": ["url", { "label": "Open in Notion" }] }, | ||
| { "name": "parentDatabaseId", "displayName": "Parent Database ID", "shape": "string", "visible": false } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "name": "pageComments", | ||
| "displayName": "Page Comments", | ||
| "description": "Comments and discussion threads on a single Notion page", | ||
| "tags": ["Comments"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "comments", | ||
| "getArgs": [ | ||
| { "key": "block_id", "value": "{{object.rawId}}" } | ||
| ], | ||
| "postRequestScript": "pageComments.js", | ||
| "paging": { | ||
| "mode": "token", | ||
| "pageSize": { "realm": "queryArg", "path": "page_size", "value": "100" }, | ||
| "in": { "realm": "payload", "path": "next_cursor" }, | ||
| "out": { "realm": "queryArg", "path": "start_cursor" } | ||
| }, | ||
| "errorHandling": { | ||
| "type": "script", | ||
| "script": "result = response.status === 403 ? 'Notion did not grant the Read comments capability. Enable \"Read comments\" on your Notion integration, then reconnect the plugin in SquaredUp.' : ((data && data.message) || ('Notion comments API returned status ' + response.status));" | ||
| } | ||
| }, | ||
| "matches": { | ||
| "sourceType": { "type": "oneOf", "values": ["Notion Page"] } | ||
| }, | ||
| "metadata": [ | ||
| { "name": "id", "displayName": "ID", "shape": "string", "visible": false }, | ||
| { "name": "createdTime", "displayName": "Created", "shape": "date" }, | ||
| { "name": "text", "displayName": "Comment", "shape": "string", "role": "label" }, | ||
| { "name": "createdById", "displayName": "Created By ID", "shape": "string", "visible": false }, | ||
| { | ||
| "name": "author", | ||
| "displayName": "Author", | ||
| "sourceId": "createdById", | ||
| "sourceType": "Notion User", | ||
| "objectPropertyPath": "name" | ||
| } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "pageContent", | ||
| "displayName": "Page Content", | ||
| "description": "Block-level content of a Notion page β paragraphs, headings, to-do items, lists, quotes, callouts and code blocks", | ||
| "tags": ["Pages"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "blocks/{{object.rawId}}/children", | ||
| "paging": { | ||
| "mode": "token", | ||
| "pageSize": { "realm": "queryArg", "path": "page_size", "value": "100" }, | ||
| "in": { "realm": "payload", "path": "next_cursor" }, | ||
| "out": { "realm": "queryArg", "path": "start_cursor" } | ||
| }, | ||
| "postRequestScript": "pageContent.js" | ||
| }, | ||
| "matches": { "sourceType": { "type": "oneOf", "values": ["Notion Page"] } }, | ||
| "metadata": [ | ||
| { "name": "type", "displayName": "Type", "shape": "string" }, | ||
| { "name": "text", "displayName": "Text", "shape": "string", "role": "label" }, | ||
| { "name": "checked", "displayName": "Checked", "shape": "boolean" }, | ||
| { "name": "hasChildren", "displayName": "Has Children", "shape": "boolean", "visible": false }, | ||
| { "pattern": ".*" } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "name": "pageProperties", | ||
| "displayName": "Page Properties", | ||
| "description": "Property values for a single Notion page", | ||
| "tags": ["Pages"], | ||
| "baseDataSourceName": "httpRequestScopedSingle", | ||
| "config": { | ||
| "httpMethod": "get", | ||
| "endpointPath": "pages/{{object.rawId}}", | ||
| "postRequestScript": "pageProperties.js", | ||
| "paging": { "mode": "none" } | ||
| }, | ||
| "matches": { | ||
| "sourceType": { "type": "oneOf", "values": ["Notion Page"] } | ||
| }, | ||
| "metadata": [ | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "lastEditedTime", "displayName": "Last Edited", "shape": "date" }, | ||
| { "name": "createdTime", "displayName": "Created", "shape": "date", "visible": false }, | ||
| { "name": "url", "displayName": "URL", "shape": ["url", { "label": "Open in Notion" }], "visible": false }, | ||
| { "name": "id", "displayName": "ID", "shape": "string", "role": "id", "visible": false }, | ||
| { "pattern": ".*" } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "name": "pagesSearch", | ||
| "displayName": "Pages", | ||
| "description": "Pages shared with the integration, including database rows", | ||
| "tags": ["Pages"], | ||
| "baseDataSourceName": "httpRequestUnscoped", | ||
| "config": { | ||
| "httpMethod": "post", | ||
| "endpointPath": "search", | ||
| "postBody": { "filter": { "property": "object", "value": "page" } }, | ||
| "postRequestScript": "pagesSearch.js", | ||
| "paging": { | ||
| "mode": "token", | ||
| "pageSize": { "realm": "body", "path": "page_size", "value": 100 }, | ||
| "in": { "realm": "payload", "path": "next_cursor" }, | ||
| "out": { "realm": "body", "path": "start_cursor" } | ||
| } | ||
| }, | ||
| "matches": "none", | ||
| "ui": [ | ||
| { | ||
| "type": "objects", | ||
| "name": "scope", | ||
| "label": "Page or data source (optional)", | ||
| "matches": { | ||
| "sourceType": { "type": "oneOf", "values": ["Notion Page", "Notion Data Source"] } | ||
| } | ||
| } | ||
| ], | ||
| "metadata": [ | ||
| { "name": "id", "displayName": "ID", "shape": "string", "role": "id", "visible": false }, | ||
| { "name": "name", "displayName": "Name", "shape": "string", "role": "label" }, | ||
| { "name": "createdTime", "displayName": "Created", "shape": "date" }, | ||
| { "name": "lastEditedTime", "displayName": "Last Edited", "shape": "date" }, | ||
| { "name": "url", "displayName": "URL", "shape": ["url", { "label": "Open in Notion" }] }, | ||
| { "name": "parentType", "displayName": "Parent Type", "shape": "string", "visible": false }, | ||
| { "name": "parentDataSourceId", "displayName": "Parent Data Source ID", "shape": "string", "visible": false } | ||
| ], | ||
| "timeframes": false | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // /v1/users/me returns a single user object (the integration's bot user), | ||
| // not an array β wrap it as one row and surface the workspace name. | ||
| result = [ | ||
| { | ||
| id: data.id, | ||
| name: data.name || (data.bot && data.bot.workspace_name) || "Notion bot", | ||
| type: data.type, | ||
| workspaceName: data.bot && data.bot.workspace_name | ||
| } | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // POST /v1/data_sources/{id}/query returns the pages (rows) of a data source, | ||
| // accumulated across pages under data.results. Each page's `properties` is a bag | ||
| // of typed Notion property values keyed by the property name; flatten each to a | ||
| // scalar so the custom fields become plain columns. | ||
| const plain = (rich) => (rich || []).map((t) => t.plain_text).join(""); | ||
|
|
||
| const valueOf = (prop) => { | ||
| if (!prop) return null; | ||
| switch (prop.type) { | ||
| case "title": | ||
| return plain(prop.title); | ||
| case "rich_text": | ||
| return plain(prop.rich_text); | ||
| case "number": | ||
| return prop.number; | ||
| case "select": | ||
| return prop.select ? prop.select.name : null; | ||
| case "status": | ||
| return prop.status ? prop.status.name : null; | ||
| case "multi_select": | ||
| return (prop.multi_select || []).map((s) => s.name).join(", "); | ||
| case "date": | ||
| return prop.date ? prop.date.start : null; | ||
| case "checkbox": | ||
| return prop.checkbox; | ||
| case "url": | ||
| return prop.url; | ||
| case "email": | ||
| return prop.email; | ||
| case "phone_number": | ||
| return prop.phone_number; | ||
| case "people": | ||
| return (prop.people || []).map((p) => p.name || p.id).join(", "); | ||
| case "files": | ||
| return (prop.files || []).map((f) => f.name).join(", "); | ||
| case "created_time": | ||
| return prop.created_time; | ||
| case "last_edited_time": | ||
| return prop.last_edited_time; | ||
| case "created_by": | ||
| return prop.created_by ? prop.created_by.name || prop.created_by.id : null; | ||
| case "last_edited_by": | ||
| return prop.last_edited_by ? prop.last_edited_by.name || prop.last_edited_by.id : null; | ||
| case "unique_id": | ||
| return prop.unique_id | ||
| ? (prop.unique_id.prefix ? prop.unique_id.prefix + "-" : "") + prop.unique_id.number | ||
| : null; | ||
| case "formula": | ||
| return prop.formula | ||
| ? prop.formula.string ?? | ||
| prop.formula.number ?? | ||
| prop.formula.boolean ?? | ||
| (prop.formula.date ? prop.formula.date.start : null) | ||
| : null; | ||
| case "rollup": | ||
| if (!prop.rollup) return null; | ||
| if (prop.rollup.type === "array") { | ||
| return (prop.rollup.array || []).map((item) => valueOf(item)).filter((v) => v != null).join(", "); | ||
| } | ||
| return prop.rollup.number ?? (prop.rollup.date ? prop.rollup.date.start : null); | ||
| case "relation": | ||
| return (prop.relation || []).map((r) => r.id).join(", "); | ||
| default: | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| result = (data.results || []).map((page) => { | ||
| const props = page.properties || {}; | ||
| const row = { | ||
| id: page.id, | ||
| url: page.url || null, | ||
| createdTime: page.created_time || null, | ||
| lastEditedTime: page.last_edited_time || null | ||
| }; | ||
| let title = ""; | ||
| for (const key of Object.keys(props)) { | ||
| const prop = props[key]; | ||
| const value = valueOf(prop); | ||
| // The title property is surfaced as `name` β don't also emit it as a duplicate column. | ||
| if (prop && prop.type === "title") { | ||
| title = value || title; | ||
| continue; | ||
| } | ||
| row[key] = value; | ||
| } | ||
| row.name = title || "Untitled"; | ||
| return row; | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.