diff --git a/components/notion/actions/append-block/append-block.mjs b/components/notion/actions/append-block/append-block.mjs index 6a937b893f265..f37c28ef07e99 100644 --- a/components/notion/actions/append-block/append-block.mjs +++ b/components/notion/actions/append-block/append-block.mjs @@ -7,7 +7,7 @@ export default { name: "Append Block to Parent", description: "Append new and/or existing blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)", - version: "0.3.5", + version: "0.3.6", type: "action", props: { notion, diff --git a/components/notion/actions/common/base-page-builder.mjs b/components/notion/actions/common/base-page-builder.mjs index 145c6099b086f..418d9ebd08c93 100644 --- a/components/notion/actions/common/base-page-builder.mjs +++ b/components/notion/actions/common/base-page-builder.mjs @@ -84,7 +84,7 @@ export default { .map((property) => ({ type: properties[property]?.type ?? property, label: property, - value: this[property] || this.properties[property], + value: this[property] || this.properties?.[property], })); }, /** diff --git a/components/notion/actions/complete-file-upload/complete-file-upload.mjs b/components/notion/actions/complete-file-upload/complete-file-upload.mjs new file mode 100644 index 0000000000000..db4b112acb6a9 --- /dev/null +++ b/components/notion/actions/complete-file-upload/complete-file-upload.mjs @@ -0,0 +1,31 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-complete-file-upload", + name: "Complete File Upload", + description: "Use this action to finalize a `mode=multi_part` file upload after all of the parts have been sent successfully. [See the documentation](https://developers.notion.com/reference/complete-a-file-upload)", + version: "0.0.1", + type: "action", + props: { + notion, + fileUploadId: { + propDefinition: [ + notion, + "fileUploadId", + () => ({ + status: "pending", + }), + ], + }, + }, + async run({ $ }) { + const response = await this.notion.completeFileUpload({ + file_upload_id: this.fileUploadId, + }); + + $.export("$summary", `Successfully completed file upload with ID ${this.fileUploadId}`); + return response; + }, +}; diff --git a/components/notion/actions/create-comment/create-comment.mjs b/components/notion/actions/create-comment/create-comment.mjs index 19db69a0a2a2b..7a9bbafd3bcaf 100644 --- a/components/notion/actions/create-comment/create-comment.mjs +++ b/components/notion/actions/create-comment/create-comment.mjs @@ -1,11 +1,11 @@ -import notion from "../../notion.app.mjs"; import { ConfigurationError } from "@pipedream/platform"; +import notion from "../../notion.app.mjs"; export default { key: "notion-create-comment", name: "Create Comment", description: "Create a comment in a page or existing discussion thread. [See the documentation](https://developers.notion.com/reference/create-a-comment)", - version: "0.0.5", + version: "0.0.6", type: "action", props: { notion, diff --git a/components/notion/actions/create-database/create-database.mjs b/components/notion/actions/create-database/create-database.mjs new file mode 100644 index 0000000000000..cec0be4d25774 --- /dev/null +++ b/components/notion/actions/create-database/create-database.mjs @@ -0,0 +1,54 @@ +import utils from "../../common/utils.mjs"; +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-create-database", + name: "Create Database", + description: "Create a database. [See the documentation](https://developers.notion.com/reference/create-a-database)", + version: "0.0.1", + type: "action", + props: { + notion, + parent: { + propDefinition: [ + notion, + "pageId", + ], + label: "Parent Page ID", + description: "Select a parent page or provide a page ID", + }, + title: { + type: "string", + label: "Title", + description: "Title of database as it appears in Notion. An array of [rich text objects](https://developers.notion.com/reference/rich-text).", + optional: true, + }, + properties: { + type: "object", + label: "Properties", + description: "Property schema of database. The keys are the names of properties as they appear in Notion and the values are [property schema objects](https://developers.notion.com/reference/property-schema-object).", + }, + }, + async run({ $ }) { + const response = await this.notion.createDatabase({ + parent: { + type: "page_id", + page_id: this.parent, + }, + title: [ + { + type: "text", + text: { + content: this.title, + }, + }, + ], + properties: utils.parseObject(this.properties), + }); + + $.export("$summary", `Successfully created database with ID ${response.id}`); + return response; + }, +}; diff --git a/components/notion/actions/create-file-upload/create-file-upload.mjs b/components/notion/actions/create-file-upload/create-file-upload.mjs new file mode 100644 index 0000000000000..907e8d73f6345 --- /dev/null +++ b/components/notion/actions/create-file-upload/create-file-upload.mjs @@ -0,0 +1,70 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-create-file-upload", + name: "Create File Upload", + description: "Create a file upload. [See the documentation](https://developers.notion.com/reference/create-a-file-upload)", + version: "0.0.1", + type: "action", + props: { + notion, + mode: { + type: "string", + label: "Mode", + description: "How the file is being sent. Use `Multi Part` for files larger than 20MB. Use `External URL` for files that are temporarily hosted publicly elsewhere.", + options: [ + { + label: "Single Part", + value: "single_part", + }, + { + label: "Multi Part", + value: "multi_part", + }, + { + label: "External URL", + value: "external_url", + }, + ], + optional: true, + }, + filename: { + type: "string", + label: "Filename", + description: "Name of the file to be created. Required when mode is multi_part or external_url. Otherwise optional, and used to override the filename. Must include an extension.", + optional: true, + }, + contentType: { + type: "string", + label: "Content Type", + description: "MIME type of the file to be created. Recommended when sending the file in multiple parts. Must match the content type of the file that's sent, and the extension of the `filename` parameter if any.", + optional: true, + }, + numberOfParts: { + type: "integer", + label: "Number of Parts", + description: "When mode is `Multi Part`, the number of parts you are uploading. Must be between 1 and 1,000. This must match the number of parts as well as the final part_number you send.", + optional: true, + }, + externalUrl: { + type: "string", + label: "External URL", + description: "When mode is `External URL`, provide the HTTPS URL of a publicly accessible file to import into your workspace.", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.notion.createFileUpload({ + mode: this.mode, + filename: this.filename, + content_type: this.contentType, + number_of_parts: this.numberOfParts, + external_url: this.externalUrl, + }); + + $.export("$summary", `Successfully created file upload with ID ${response.id}`); + return response; + }, +}; diff --git a/components/notion/actions/create-page-from-database/create-page-from-database.mjs b/components/notion/actions/create-page-from-database/create-page-from-database.mjs index 28dc11521e098..b08e5c32bfe3f 100644 --- a/components/notion/actions/create-page-from-database/create-page-from-database.mjs +++ b/components/notion/actions/create-page-from-database/create-page-from-database.mjs @@ -1,14 +1,14 @@ -import notion from "../../notion.app.mjs"; -import base from "../common/base-page-builder.mjs"; import NOTION_ICONS from "../../common/notion-icons.mjs"; import utils from "../../common/utils.mjs"; +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; export default { ...base, key: "notion-create-page-from-database", name: "Create Page from Database", description: "Create a page from a database. [See the documentation](https://developers.notion.com/reference/post-page)", - version: "0.2.2", + version: "0.2.3", type: "action", props: { notion, diff --git a/components/notion/actions/create-page/create-page.mjs b/components/notion/actions/create-page/create-page.mjs index 66ad3794f99cf..45bdeb80a61e1 100644 --- a/components/notion/actions/create-page/create-page.mjs +++ b/components/notion/actions/create-page/create-page.mjs @@ -7,7 +7,7 @@ export default { key: "notion-create-page", name: "Create Page", description: "Create a page from a parent page. [See the documentation](https://developers.notion.com/reference/post-page)", - version: "0.2.18", + version: "0.2.19", type: "action", props: { notion, diff --git a/components/notion/actions/delete-block/delete-block.mjs b/components/notion/actions/delete-block/delete-block.mjs new file mode 100644 index 0000000000000..43145174ff9a0 --- /dev/null +++ b/components/notion/actions/delete-block/delete-block.mjs @@ -0,0 +1,29 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-delete-block", + name: "Delete Block", + description: "Sets a Block object, including page blocks, to archived: true using the ID specified. [See the documentation](https://developers.notion.com/reference/delete-a-block)", + version: "0.0.1", + type: "action", + props: { + notion, + infoLabel: { + type: "alert", + alertType: "info", + content: "**Note:** In the Notion UI application, this moves the block to the \"Trash\" where it can still be accessed and restored.", + }, + blockId: { + type: "string", + label: "Block ID", + description: "Block ID retrieved from the **Retrieve Page Content** action", + }, + }, + async run({ $ }) { + const response = await this.notion.deleteBlock(this.blockId); + $.export("$summary", `Successfully deleted block with ID ${this.blockId}`); + return response; + }, +}; diff --git a/components/notion/actions/duplicate-page/duplicate-page.mjs b/components/notion/actions/duplicate-page/duplicate-page.mjs index 8fa34cd09ef12..008fbe604e949 100644 --- a/components/notion/actions/duplicate-page/duplicate-page.mjs +++ b/components/notion/actions/duplicate-page/duplicate-page.mjs @@ -1,13 +1,13 @@ +import utils from "../../common/utils.mjs"; import notion from "../../notion.app.mjs"; import base from "../common/base-page-builder.mjs"; -import utils from "../../common/utils.mjs"; export default { ...base, key: "notion-duplicate-page", name: "Duplicate Page", description: "Create a new page copied from an existing page block. [See the documentation](https://developers.notion.com/reference/post-page)", - version: "0.0.15", + version: "0.0.16", type: "action", props: { notion, diff --git a/components/notion/actions/list-all-users/list-all-users.mjs b/components/notion/actions/list-all-users/list-all-users.mjs new file mode 100644 index 0000000000000..058409303dfe1 --- /dev/null +++ b/components/notion/actions/list-all-users/list-all-users.mjs @@ -0,0 +1,23 @@ +import notion from "../../notion.app.mjs"; + +export default { + key: "notion-list-all-users", + name: "List All Users", + description: "Returns all users in the workspace. [See the documentation](https://developers.notion.com/reference/get-users)", + version: "0.0.1", + type: "action", + props: { + notion, + }, + async run({ $ }) { + const response = this.notion.paginate({ + fn: this.notion.getUsers, + }); + const users = []; + for await (const user of response) { + users.push(user); + } + $.export("$summary", `Successfully retrieved ${users.length} users`); + return users; + }, +}; diff --git a/components/notion/actions/list-file-uploads/list-file-uploads.mjs b/components/notion/actions/list-file-uploads/list-file-uploads.mjs new file mode 100644 index 0000000000000..133d77acd041c --- /dev/null +++ b/components/notion/actions/list-file-uploads/list-file-uploads.mjs @@ -0,0 +1,28 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-list-file-uploads", + name: "List File Uploads", + description: "Use this action to list file uploads. [See the documentation](https://developers.notion.com/reference/list-file-uploads)", + version: "0.0.1", + type: "action", + props: { + notion, + }, + async run({ $ }) { + const response = this.notion.paginate({ + fn: this.notion.listFileUploads, + }); + + const responseArray = []; + + for await (const item of response) { + responseArray.push(item); + } + + $.export("$summary", `Successfully retrieved ${responseArray.length} file uploads`); + return responseArray; + }, +}; diff --git a/components/notion/actions/query-database/query-database.mjs b/components/notion/actions/query-database/query-database.mjs index 3a46cc773de3d..a5b977b740f1b 100644 --- a/components/notion/actions/query-database/query-database.mjs +++ b/components/notion/actions/query-database/query-database.mjs @@ -1,11 +1,11 @@ -import notion from "../../notion.app.mjs"; import utils from "../../common/utils.mjs"; +import notion from "../../notion.app.mjs"; export default { key: "notion-query-database", name: "Query Database", description: "Query a database with a specified filter. [See the documentation](https://developers.notion.com/reference/post-database-query)", - version: "0.0.13", + version: "0.1.0", type: "action", props: { notion, @@ -20,12 +20,20 @@ export default { description: "The filter to apply, as a JSON-stringified object. [See the documentation for available filters](https://developers.notion.com/reference/post-database-query-filter). Example: `{ \"property\": \"Name\", \"title\": { \"contains\": \"title to search for\" } }`", type: "string", }, + sorts: { + label: "Sorts", + description: "The sort order for the query. [See the documentation for available sorts](https://developers.notion.com/reference/post-database-query-sort). Example: `[ { \"property\": \"Name\", \"direction\": \"ascending\" } ]`", + type: "string[]", + }, }, async run({ $ }) { - const { filter } = this; + const { + filter, sorts, + } = this; const response = await this.notion.queryDatabase(this.databaseId, { filter: utils.parseStringToJSON(filter), + sorts: utils.parseObject(sorts), }); const length = response?.results?.length; diff --git a/components/notion/actions/retrieve-block/retrieve-block.mjs b/components/notion/actions/retrieve-block/retrieve-block.mjs index 0f89513434bf2..8b05ad5146082 100644 --- a/components/notion/actions/retrieve-block/retrieve-block.mjs +++ b/components/notion/actions/retrieve-block/retrieve-block.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-block", name: "Retrieve Page Content", description: "Get page content as block objects or markdown. Blocks can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)", - version: "0.2.3", + version: "0.2.4", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-database-content/retrieve-database-content.mjs b/components/notion/actions/retrieve-database-content/retrieve-database-content.mjs index c9f91b581d0ab..967e82788f05a 100644 --- a/components/notion/actions/retrieve-database-content/retrieve-database-content.mjs +++ b/components/notion/actions/retrieve-database-content/retrieve-database-content.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-database-content", name: "Retrieve Database Content", description: "Get all content of a database. [See the documentation](https://developers.notion.com/reference/post-database-query)", - version: "0.0.7", + version: "0.0.8", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs b/components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs index a4460a0ceb449..b188548f5e3e5 100644 --- a/components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs +++ b/components/notion/actions/retrieve-database-schema/retrieve-database-schema.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-database-schema", name: "Retrieve Database Schema", description: "Get the property schema of a database in Notion. [See the documentation](https://developers.notion.com/reference/retrieve-a-database)", - version: "0.0.9", + version: "0.0.10", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-file-upload/retrieve-file-upload.mjs b/components/notion/actions/retrieve-file-upload/retrieve-file-upload.mjs new file mode 100644 index 0000000000000..90614ba8b120a --- /dev/null +++ b/components/notion/actions/retrieve-file-upload/retrieve-file-upload.mjs @@ -0,0 +1,28 @@ +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-retrieve-file-upload", + name: "Retrieve File Upload", + description: "Use this action to retrieve a file upload. [See the documentation](https://developers.notion.com/reference/retrieve-a-file-upload)", + version: "0.0.1", + type: "action", + props: { + notion, + fileUploadId: { + propDefinition: [ + notion, + "fileUploadId", + ], + }, + }, + async run({ $ }) { + const response = await this.notion.retrieveFileUpload({ + file_upload_id: this.fileUploadId, + }); + + $.export("$summary", `Successfully retrieved file upload with ID ${this.fileUploadId}`); + return response; + }, +}; diff --git a/components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs b/components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs index e65eac38b0acb..ee2ce6da66b97 100644 --- a/components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs +++ b/components/notion/actions/retrieve-page-property-item/retrieve-page-property-item.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-page-property-item", name: "Retrieve Page Property Item", description: "Get a Property Item object for a selected page and property. [See the documentation](https://developers.notion.com/reference/retrieve-a-page-property)", - version: "0.0.8", + version: "0.0.9", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-page/retrieve-page.mjs b/components/notion/actions/retrieve-page/retrieve-page.mjs index 3e770e95db091..9b51d32e1e64e 100644 --- a/components/notion/actions/retrieve-page/retrieve-page.mjs +++ b/components/notion/actions/retrieve-page/retrieve-page.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-page", name: "Retrieve Page Metadata", description: "Get details of a page. [See the documentation](https://developers.notion.com/reference/retrieve-a-page)", - version: "0.0.9", + version: "0.0.10", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-user/retrieve-user.mjs b/components/notion/actions/retrieve-user/retrieve-user.mjs new file mode 100644 index 0000000000000..af6836035361f --- /dev/null +++ b/components/notion/actions/retrieve-user/retrieve-user.mjs @@ -0,0 +1,23 @@ +import notion from "../../notion.app.mjs"; + +export default { + key: "notion-retrieve-user", + name: "Retrieve User", + description: "Returns a user using the ID specified. [See the documentation](https://developers.notion.com/reference/get-user)", + version: "0.0.1", + type: "action", + props: { + notion, + userId: { + propDefinition: [ + notion, + "userId", + ], + }, + }, + async run({ $ }) { + const response = await this.notion.getUser(this.userId); + $.export("$summary", `Successfully retrieved user with ID ${this.userId}`); + return response; + }, +}; diff --git a/components/notion/actions/search/search.mjs b/components/notion/actions/search/search.mjs index d6456cda589cb..f1a02f940c942 100644 --- a/components/notion/actions/search/search.mjs +++ b/components/notion/actions/search/search.mjs @@ -5,7 +5,7 @@ export default { key: "notion-search", name: "Find Pages or Databases", description: "Searches for a page or database. [See the documentation](https://developers.notion.com/reference/post-search)", - version: "0.0.8", + version: "0.0.9", type: "action", props: { ...common.props, diff --git a/components/notion/actions/send-file-upload/send-file-upload.mjs b/components/notion/actions/send-file-upload/send-file-upload.mjs new file mode 100644 index 0000000000000..c5a892fc8fd21 --- /dev/null +++ b/components/notion/actions/send-file-upload/send-file-upload.mjs @@ -0,0 +1,62 @@ +import { getFileStreamAndMetadata } from "@pipedream/platform"; +import { Blob } from "buffer"; +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-send-file-upload", + name: "Send File Upload", + description: "Send a file upload. [See the documentation](https://developers.notion.com/reference/send-a-file-upload)", + version: "0.0.1", + type: "action", + props: { + notion, + fileUploadId: { + propDefinition: [ + notion, + "fileUploadId", + () => ({ + status: "pending", + }), + ], + }, + file: { + type: "string", + label: "Image File Path or URL", + description: "The image to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myImage.jpg`).", + }, + syncDir: { + type: "dir", + accessMode: "read", + sync: true, + }, + }, + async run({ $ }) { + const { + stream, metadata, + } = await getFileStreamAndMetadata(this.file); + + const fileBinary = await new Promise((resolve, reject) => { + const chunks = []; + stream.on("data", (chunk) => chunks.push(chunk)); + stream.on("end", () => resolve(Buffer.concat(chunks))); + stream.on("error", reject); + }); + + const response = await this.notion.sendFileUpload({ + file_upload_id: this.fileUploadId, + file: { + data: new Blob([ + fileBinary, + ], { + type: metadata.contentType, + }), + filename: metadata.name, + }, + }); + + $.export("$summary", `Successfully created file upload with ID ${response.id}`); + return response; + }, +}; diff --git a/components/notion/actions/update-block/update-block.mjs b/components/notion/actions/update-block/update-block.mjs new file mode 100644 index 0000000000000..da88064e6e841 --- /dev/null +++ b/components/notion/actions/update-block/update-block.mjs @@ -0,0 +1,38 @@ +import utils from "../../common/utils.mjs"; +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-update-block", + name: "Update Child Block", + description: "Updates a child block object. [See the documentation](https://developers.notion.com/reference/update-a-block)", + version: "0.0.1", + type: "action", + props: { + notion, + blockId: { + type: "string", + label: "Block ID", + description: "Block ID retrieved from the **Retrieve Page Content** action", + }, + infoLabel: { + type: "alert", + alertType: "info", + content: "**Note:** The update replaces the entire value for a given field. If a field is omitted (ex: omitting checked when updating a to_do block), the value will not be changed.", + }, + content: { + type: "string", + label: "Content", + description: "The content of the block. **E.g. {\"code\": {\"rich_text\":[{\"type\":\"text\",\"text\":{\"content\":\"Updated content\"}}]}}** [See the documentation](https://developers.notion.com/reference/update-a-block)", + }, + }, + async run({ $ }) { + const response = await this.notion.updateBlock({ + block_id: this.blockId, + ...utils.parseObject(this.content), + }); + $.export("$summary", `Successfully updated block with ID ${this.blockId}`); + return response; + }, +}; diff --git a/components/notion/actions/update-database/update-database.mjs b/components/notion/actions/update-database/update-database.mjs new file mode 100644 index 0000000000000..17d16abcad626 --- /dev/null +++ b/components/notion/actions/update-database/update-database.mjs @@ -0,0 +1,79 @@ +import utils from "../../common/utils.mjs"; +import notion from "../../notion.app.mjs"; +import base from "../common/base-page-builder.mjs"; + +export default { + ...base, + key: "notion-update-database", + name: "Update Database", + description: "Update a database. [See the documentation](https://developers.notion.com/reference/update-a-database)", + version: "0.0.1", + type: "action", + props: { + notion, + databaseId: { + propDefinition: [ + notion, + "databaseId", + ], + reloadProps: true, + }, + title: { + type: "string", + label: "Title", + description: "Title of database as it appears in Notion. An array of [rich text objects](https://developers.notion.com/reference/rich-text).", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "An array of [rich text objects](https://developers.notion.com/reference/rich-text) that represents the description of the database that is displayed in the Notion UI. If omitted, then the database description remains unchanged.", + optional: true, + }, + properties: { + type: "object", + label: "Properties", + description: "The properties of a database to be changed in the request, in the form of a JSON object. If updating an existing property, then the keys are the names or IDs of the properties as they appear in Notion, and the values are [property schema objects](https://developers.notion.com/reference/rich-text). If adding a new property, then the key is the name of the new database property and the value is a [property schema object](https://developers.notion.com/reference/property-schema-object).", + optional: true, + }, + }, + async additionalProps(props) { + if (this.databaseId) { + const database = await this.notion.retrieveDatabase(this.databaseId); + + props.title.default = database.title.map((text) => text.text.content).join(" "); + props.description.default = database.description.map((text) => text.plain_text).join(" "); + props.properties.default = Object.entries(database.properties).reduce((acc, [ + key, + value, + ]) => { + acc[key] = JSON.stringify(value); + return acc; + }, {}); + return {}; + } + }, + async run({ $ }) { + const response = await this.notion.updateDatabase({ + database_id: this.databaseId, + title: [ + { + text: { + content: this.title, + }, + }, + ], + description: [ + { + text: { + content: this.description, + }, + }, + ], + properties: utils.parseObject(this.properties), + }); + + $.export("$summary", `Successfully updated database with ID ${response.id}`); + return response; + }, +}; diff --git a/components/notion/actions/update-page/update-page.mjs b/components/notion/actions/update-page/update-page.mjs index a9df852c362d1..652a393a0b7eb 100644 --- a/components/notion/actions/update-page/update-page.mjs +++ b/components/notion/actions/update-page/update-page.mjs @@ -1,13 +1,13 @@ +import pick from "lodash-es/pick.js"; import notion from "../../notion.app.mjs"; import base from "../common/base-page-builder.mjs"; -import pick from "lodash-es/pick.js"; export default { ...base, key: "notion-update-page", name: "Update Page", description: "Update a page's property values. To append page content, use the *Append Block* action instead. [See the documentation](https://developers.notion.com/reference/patch-page)", - version: "1.1.8", + version: "1.1.9", type: "action", props: { notion, diff --git a/components/notion/common/utils.mjs b/components/notion/common/utils.mjs index 3f726e81dc095..358052ec01f3f 100644 --- a/components/notion/common/utils.mjs +++ b/components/notion/common/utils.mjs @@ -32,7 +32,7 @@ function parseArray(value) { function parseObject(obj) { if (!obj) { - return {}; + return null; } if (typeof obj === "string") { try { diff --git a/components/notion/notion.app.mjs b/components/notion/notion.app.mjs index 121016abe2c13..b831c907d8299 100644 --- a/components/notion/notion.app.mjs +++ b/components/notion/notion.app.mjs @@ -1,7 +1,7 @@ import notion from "@notionhq/client"; -import NOTION_META from "./common/notion-meta-selection.mjs"; import { ConfigurationError } from "@pipedream/platform"; import { NotionToMarkdown } from "notion-to-md"; +import NOTION_META from "./common/notion-meta-selection.mjs"; export default { type: "app", @@ -127,12 +127,12 @@ export default { description: "The page title (defaults to `Untitled`)", optional: true, }, - userIds: { - type: "string[]", - label: "Users", - description: "Select one or more users, or provide user IDs", + userId: { + type: "string", + label: "User ID", + description: "Select a user, or provide a user ID", async options() { - const users = await this.getUsers(); + const { results: users } = await this.getUsers(); return users.map((user) => ({ label: user.name, @@ -140,6 +140,34 @@ export default { })); }, }, + fileUploadId: { + type: "string", + label: "File Upload ID", + description: "The ID of the file upload to send.", + async options({ + prevContext, status, + }) { + const { + results, next_cursor: nextCursor, + } = await this.listFileUploads({ + status, + page_size: 100, + start_cursor: prevContext.nextPageParameters ?? undefined, + }); + + return { + options: results.map(({ + id: value, filename: label, + }) => ({ + label, + value, + })), + context: { + nextPageParameters: nextCursor, + }, + }; + }, + }, sortDirection: { type: "string", label: "Sort Direction", @@ -258,6 +286,35 @@ export default { database_id: databaseId, }); }, + async createDatabase(database) { + return this._getNotionClient().databases.create(database); + }, + async updateDatabase(database) { + return this._getNotionClient().databases.update(database); + }, + async createFileUpload(file) { + return this._getNotionClient().fileUploads.create(file); + }, + async listFileUploads(params = {}) { + return this._getNotionClient().fileUploads.list(params); + }, + async sendFileUpload(file) { + return this._getNotionClient().fileUploads.send(file); + }, + async completeFileUpload(file) { + return this._getNotionClient().fileUploads.complete(file); + }, + async retrieveFileUpload(params) { + return this._getNotionClient().fileUploads.retrieve(params); + }, + async updateBlock(block) { + return this._getNotionClient().blocks.update(block); + }, + async deleteBlock(blockId) { + return this._getNotionClient().blocks.delete({ + block_id: blockId, + }); + }, async createPage(page) { return this._getNotionClient().pages.create(page); }, @@ -352,10 +409,13 @@ export default { block_id: blockId, }); }, - async getUsers() { - const response = await this._getNotionClient().users.list(); - - return response.results; + async getUsers(opts = {}) { + return this._getNotionClient().users.list(opts); + }, + async getUser(userId) { + return this._getNotionClient().users.retrieve({ + user_id: userId, + }); }, async getPageAsMarkdown(pageId, shouldRetrieveChildren) { const notion = this._getNotionClient(); @@ -373,5 +433,36 @@ export default { ? output : output.parent; }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let cursor = null; + + do { + params.start_cursor = cursor; + const { + results, + next_cursor: nextCursor, + has_more: hasMoreResults, + } = await fn({ + params, + ...opts, + }); + + for (const d of results) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = hasMoreResults; + cursor = nextCursor; + + } while (hasMore); + }, }, }; diff --git a/components/notion/package.json b/components/notion/package.json index e7deef34156de..b8f598c6f6d60 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.8.1", + "version": "0.9.0", "description": "Pipedream Notion Components", "main": "notion.app.mjs", "keywords": [ @@ -10,8 +10,8 @@ "homepage": "https://pipedream.com/apps/notion", "author": "Pipedream (https://pipedream.com/)", "dependencies": { - "@notionhq/client": "^2.2.3", - "@pipedream/platform": "^3.0.3", + "@notionhq/client": "^4.0.1", + "@pipedream/platform": "^3.1.0", "@tryfabric/martian": "^1.2.4", "lodash-es": "^4.17.21", "notion-to-md": "3.1.8" diff --git a/components/notion/sources/new-comment-created/new-comment-created.mjs b/components/notion/sources/new-comment-created/new-comment-created.mjs index 4f0ca91c92079..a3eeb5bbd206a 100644 --- a/components/notion/sources/new-comment-created/new-comment-created.mjs +++ b/components/notion/sources/new-comment-created/new-comment-created.mjs @@ -5,7 +5,7 @@ export default { key: "notion-new-comment-created", name: "New Comment Created", description: "Emit new event when a new comment is created in a page or block. [See the documentation](https://developers.notion.com/reference/retrieve-a-comment)", - version: "0.0.5", + version: "0.0.6", type: "source", dedupe: "unique", props: { diff --git a/components/notion/sources/new-database/new-database.mjs b/components/notion/sources/new-database/new-database.mjs index c3c057c7cca0f..0fefa0b6f2eac 100644 --- a/components/notion/sources/new-database/new-database.mjs +++ b/components/notion/sources/new-database/new-database.mjs @@ -1,13 +1,13 @@ import base from "../common/base.mjs"; -import sampleEmit from "./test-event.mjs"; import constants from "../common/constants.mjs"; +import sampleEmit from "./test-event.mjs"; export default { ...base, key: "notion-new-database", name: "New Database Created", description: "Emit new event when a database is created. [See the documentation](https://developers.notion.com/reference/database)", - version: "0.0.12", + version: "0.0.13", type: "source", props: { ...base.props, diff --git a/components/notion/sources/new-page/new-page.mjs b/components/notion/sources/new-page/new-page.mjs index 043bd61a501cf..25e590ddc8ffb 100644 --- a/components/notion/sources/new-page/new-page.mjs +++ b/components/notion/sources/new-page/new-page.mjs @@ -1,14 +1,14 @@ import notion from "../../notion.app.mjs"; -import sampleEmit from "./test-event.mjs"; import base from "../common/base.mjs"; import constants from "../common/constants.mjs"; +import sampleEmit from "./test-event.mjs"; export default { ...base, key: "notion-new-page", name: "New Page in Database", description: "Emit new event when a page is created in the selected database. [See the documentation](https://developers.notion.com/reference/page)", - version: "0.0.14", + version: "0.0.15", type: "source", props: { ...base.props, diff --git a/components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs b/components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs index 70164a2dfc0ed..3ecf3158baeec 100644 --- a/components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs +++ b/components/notion/sources/page-or-subpage-updated/page-or-subpage-updated.mjs @@ -1,13 +1,13 @@ import base from "../common/base.mjs"; -import sampleEmit from "./test-event.mjs"; import constants from "../common/constants.mjs"; +import sampleEmit from "./test-event.mjs"; export default { ...base, key: "notion-page-or-subpage-updated", name: "Page or Subpage Updated", /* eslint-disable-line pipedream/source-name */ description: "Emit new event when the selected page or one of its sub-pages is updated. [See the documentation](https://developers.notion.com/reference/page)", - version: "0.0.10", + version: "0.0.11", type: "source", dedupe: "unique", props: { diff --git a/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs b/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs index 3f7b45ee37253..88c4a551a6e66 100644 --- a/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs +++ b/components/notion/sources/updated-page-by-timestamp/updated-page-by-timestamp.mjs @@ -8,7 +8,7 @@ export default { key: "notion-updated-page-by-timestamp", name: "New or Updated Page in Database (By Timestamp)", 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.0.2", + version: "0.0.3", type: "source", dedupe: "unique", props: { diff --git a/components/notion/sources/updated-page-id/updated-page-id.mjs b/components/notion/sources/updated-page-id/updated-page-id.mjs index 1bb281219e314..a620aa922576d 100644 --- a/components/notion/sources/updated-page-id/updated-page-id.mjs +++ b/components/notion/sources/updated-page-id/updated-page-id.mjs @@ -7,7 +7,7 @@ export default { key: "notion-updated-page-id", name: "Page Updated", /* eslint-disable-line pipedream/source-name */ description: "Emit new event when a selected page is updated. [See the documentation](https://developers.notion.com/reference/page)", - version: "0.0.9", + version: "0.0.10", type: "source", dedupe: "unique", props: { diff --git a/components/notion/sources/updated-page/updated-page.mjs b/components/notion/sources/updated-page/updated-page.mjs index 52dbca1eeef87..e7d8b9e2ebb2d 100644 --- a/components/notion/sources/updated-page/updated-page.mjs +++ b/components/notion/sources/updated-page/updated-page.mjs @@ -1,15 +1,15 @@ +import zlib from "zlib"; import notion from "../../notion.app.mjs"; -import sampleEmit from "./test-event.mjs"; import base from "../common/base.mjs"; import constants from "../common/constants.mjs"; -import zlib from "zlib"; +import sampleEmit from "./test-event.mjs"; export default { ...base, key: "notion-updated-page", name: "New or Updated Page in Database (By Property)", 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.9", + version: "0.1.10", type: "source", dedupe: "unique", props: { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d5eeeca611d6..0398b861526b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8617,8 +8617,7 @@ importers: specifier: ^3.1.0 version: 3.1.0 - components/mexc: - specifiers: {} + components/mexc: {} components/mezmo: {} @@ -9447,11 +9446,11 @@ importers: components/notion: dependencies: '@notionhq/client': - specifier: ^2.2.3 - version: 2.2.15 + specifier: ^4.0.1 + version: 4.0.1 '@pipedream/platform': - specifier: ^3.0.3 - version: 3.0.3 + specifier: ^3.1.0 + version: 3.1.0 '@tryfabric/martian': specifier: ^1.2.4 version: 1.2.4 @@ -13017,8 +13016,7 @@ importers: specifier: ^1.4.0 version: 1.6.6 - components/siteglide: - specifiers: {} + components/siteglide: {} components/siteleaf: dependencies: @@ -20061,14 +20059,14 @@ packages: resolution: {integrity: sha512-m7zZ5l3RUktayf1lRBV1XMb8HSKsmWTv/LZPqP7UGC1NMzOlc+bbTOPNQ4CP/c1P4cP61VWLb/zBq7a3c0nMaw==} engines: {node: '>=12'} - '@notionhq/client@2.2.15': - resolution: {integrity: sha512-XhdSY/4B1D34tSco/GION+23GMjaS9S2zszcqYkMHo8RcWInymF6L1x+Gk7EmHdrSxNFva2WM8orhC4BwQCwgw==} - engines: {node: '>=12'} - '@notionhq/client@2.3.0': resolution: {integrity: sha512-l7WqTCpQqC+HibkB9chghONQTYcxNQT0/rOJemBfmuKQRTu2vuV8B3yA395iKaUdDo7HI+0KvQaz9687Xskzkw==} engines: {node: '>=12'} + '@notionhq/client@4.0.1': + resolution: {integrity: sha512-SdILqiiThECLR2KDUOvl4JqRaJWBwDYaEw/f0qu+G6rKN/QUCkaJ84vN5MgBw1yKsMAsKxBlDazs3Jw6vv2ikA==} + engines: {node: '>=18'} + '@octokit/auth-token@2.5.0': resolution: {integrity: sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==} @@ -39327,13 +39325,6 @@ snapshots: transitivePeerDependencies: - encoding - '@notionhq/client@2.2.15': - dependencies: - '@types/node-fetch': 2.6.12 - node-fetch: 2.7.0 - transitivePeerDependencies: - - encoding - '@notionhq/client@2.3.0': dependencies: '@types/node-fetch': 2.6.12 @@ -39341,6 +39332,8 @@ snapshots: transitivePeerDependencies: - encoding + '@notionhq/client@4.0.1': {} + '@octokit/auth-token@2.5.0': dependencies: '@octokit/types': 6.41.0