From 4678daddddc500c559dc2aa0122ae0b870771221 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 23 Oct 2025 13:54:03 -0400 Subject: [PATCH 1/3] new components --- .../actions/create-folder/create-folder.mjs | 72 ++++++++ .../actions/create-item/create-item.mjs | 2 +- .../actions/create-link/create-link.mjs | 74 ++++++++ .../actions/create-list/create-list.mjs | 2 +- .../actions/download-file/download-file.mjs | 2 +- .../find-file-by-name/find-file-by-name.mjs | 52 ++++++ .../get-excel-table/get-excel-table.mjs | 84 +++++++++ .../actions/get-file-by-id/get-file-by-id.mjs | 52 ++++++ .../list-files-in-folder.mjs | 67 +++++++ .../actions/update-item/update-item.mjs | 2 +- .../actions/upload-file/upload-file.mjs | 86 +++++++++ components/sharepoint/common/constants.mjs | 30 ++++ components/sharepoint/common/utils.mjs | 40 +++++ components/sharepoint/package.json | 2 +- components/sharepoint/sharepoint.app.mjs | 163 +++++++++++++++++- .../sharepoint/sources/common/common.mjs | 14 +- .../new-file-created/new-file-created.mjs | 73 ++++++++ .../new-folder-created/new-folder-created.mjs | 73 ++++++++ .../sources/new-list-item/new-list-item.mjs | 4 +- .../updated-list-item/updated-list-item.mjs | 2 +- 20 files changed, 883 insertions(+), 13 deletions(-) create mode 100644 components/sharepoint/actions/create-folder/create-folder.mjs create mode 100644 components/sharepoint/actions/create-link/create-link.mjs create mode 100644 components/sharepoint/actions/find-file-by-name/find-file-by-name.mjs create mode 100644 components/sharepoint/actions/get-excel-table/get-excel-table.mjs create mode 100644 components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs create mode 100644 components/sharepoint/actions/list-files-in-folder/list-files-in-folder.mjs create mode 100644 components/sharepoint/actions/upload-file/upload-file.mjs create mode 100644 components/sharepoint/common/constants.mjs create mode 100644 components/sharepoint/sources/new-file-created/new-file-created.mjs create mode 100644 components/sharepoint/sources/new-folder-created/new-folder-created.mjs diff --git a/components/sharepoint/actions/create-folder/create-folder.mjs b/components/sharepoint/actions/create-folder/create-folder.mjs new file mode 100644 index 0000000000000..29d63a71b4945 --- /dev/null +++ b/components/sharepoint/actions/create-folder/create-folder.mjs @@ -0,0 +1,72 @@ +import sharepoint from "../../sharepoint.app.mjs"; + +export default { + key: "sharepoint-create-folder", + name: "Create Folder", + description: "Create a new folder in SharePoint. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + folderId: { + propDefinition: [ + sharepoint, + "folderId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + label: "Parent Folder ID", + description: "The ID of the folder which the the new folder should be created. You can either search for the folder here or provide a custom *Folder ID*.", + }, + folderName: { + type: "string", + label: "Folder Name", + description: "The name of the new folder to be created. e.g. `New Folder`", + }, + }, + async run({ $ }) { + const data = { + name: this.folderName, + folder: {}, + }; + const response = this.folderId + ? await this.sharepoint.createDriveItemInFolder({ + siteId: this.siteId, + folderId: this.folderId, + data, + }) + : await this.sharepoint.createDriveItem({ + siteId: this.siteId, + driveId: this.driveId, + data, + }); + + if (response?.id) { + $.export("$summary", `Successfully created folder with ID ${response.id}.`); + } + + return response; + }, +}; diff --git a/components/sharepoint/actions/create-item/create-item.mjs b/components/sharepoint/actions/create-item/create-item.mjs index d90d00757a480..caa00d5fb955b 100644 --- a/components/sharepoint/actions/create-item/create-item.mjs +++ b/components/sharepoint/actions/create-item/create-item.mjs @@ -4,7 +4,7 @@ export default { key: "sharepoint-create-item", name: "Create Item", description: "Create a new item in Microsoft Sharepoint. [See the documentation](https://learn.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=http)", - version: "0.0.6", + version: "0.0.7", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/sharepoint/actions/create-link/create-link.mjs b/components/sharepoint/actions/create-link/create-link.mjs new file mode 100644 index 0000000000000..9343e89915a82 --- /dev/null +++ b/components/sharepoint/actions/create-link/create-link.mjs @@ -0,0 +1,74 @@ +import sharepoint from "../../sharepoint.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "sharepoint-create-link", + name: "Create Link", + description: "Create a sharing link for a DriveItem. [See the documentation](https://docs.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + fileId: { + propDefinition: [ + sharepoint, + "fileId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + excludeFolders: false, + }), + ], + }, + type: { + type: "string", + label: "Type", + description: "The type of sharing link to create. Either `view`, `edit`, or `embed`.", + options: constants.SHARING_LINK_TYPE_OPTIONS, + }, + scope: { + type: "string", + label: "Scope", + description: "The scope of link to create. Either `anonymous` or `organization`.", + options: constants.SHARING_LINK_SCOPE_OPTIONS, + optional: true, + }, + }, + async run({ $ }) { + const response = await this.sharepoint.createLink({ + $, + siteId: this.siteId, + fileId: this.fileId, + data: { + type: this.type, + scope: this.scope, + }, + }); + + if (response?.id) { + $.export("$summary", `Successfully created a sharing link with ID \`${response.id}\`.`); + } + + return response; + }, +}; diff --git a/components/sharepoint/actions/create-list/create-list.mjs b/components/sharepoint/actions/create-list/create-list.mjs index af1a9c6aadd9d..47af2ff8c7fc7 100644 --- a/components/sharepoint/actions/create-list/create-list.mjs +++ b/components/sharepoint/actions/create-list/create-list.mjs @@ -4,7 +4,7 @@ export default { key: "sharepoint-create-list", name: "Create List", description: "Create a new list in Microsoft Sharepoint. [See the documentation](https://learn.microsoft.com/en-us/graph/api/list-create?view=graph-rest-1.0&tabs=http)", - version: "0.0.6", + version: "0.0.7", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/sharepoint/actions/download-file/download-file.mjs b/components/sharepoint/actions/download-file/download-file.mjs index 7bb3f09dee4c1..456848d3d9b87 100644 --- a/components/sharepoint/actions/download-file/download-file.mjs +++ b/components/sharepoint/actions/download-file/download-file.mjs @@ -5,7 +5,7 @@ export default { key: "sharepoint-download-file", name: "Download File", description: "Download a Microsoft Sharepoint file to the /tmp directory. [See the documentation](https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http)", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/sharepoint/actions/find-file-by-name/find-file-by-name.mjs b/components/sharepoint/actions/find-file-by-name/find-file-by-name.mjs new file mode 100644 index 0000000000000..ebdcba97a2a33 --- /dev/null +++ b/components/sharepoint/actions/find-file-by-name/find-file-by-name.mjs @@ -0,0 +1,52 @@ +import sharepoint from "../../sharepoint.app.mjs"; + +export default { + key: "sharepoint-find-file-by-name", + name: "Find File by Name", + description: "Search for a file or folder by name. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + name: { + type: "string", + label: "File Name", + description: "The name of the file or folder to search for", + }, + excludeFolders: { + propDefinition: [ + sharepoint, + "excludeFolders", + ], + }, + }, + async run({ $ }) { + const response = await this.sharepoint.searchDriveItems({ + $, + siteId: this.siteId, + query: this.name, + }); + let values = response.value.filter( + ({ name }) => name.toLowerCase().includes(this.name.toLowerCase()), + ); + if (this.excludeFolders) { + values = values.filter(({ folder }) => !folder); + } + + $.export("$summary", `Found ${values.length} matching file${values.length === 1 + ? "" + : "s"}`); + return values; + }, +}; diff --git a/components/sharepoint/actions/get-excel-table/get-excel-table.mjs b/components/sharepoint/actions/get-excel-table/get-excel-table.mjs new file mode 100644 index 0000000000000..028eec5b2c460 --- /dev/null +++ b/components/sharepoint/actions/get-excel-table/get-excel-table.mjs @@ -0,0 +1,84 @@ +import sharepoint from "../../sharepoint.app.mjs"; + +export default { + key: "sharepoint-get-excel-table", + name: "Get Excel Table", + description: "Retrieve a table from an Excel spreadsheet stored in Sharepoint [See the documentation](https://learn.microsoft.com/en-us/graph/api/table-range?view=graph-rest-1.0&tabs=http)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + sharepoint, + alert: { + type: "alert", + alertType: "info", + content: `Note: The table must exist within the Excel spreadsheet. + \nSee Microsoft's documentation on how to [Create and Format a Table](https://support.microsoft.com/en-us/office/create-and-format-tables-e81aa349-b006-4f8a-9806-5af9df0ac664) + `, + }, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + itemId: { + propDefinition: [ + sharepoint, + "excelFileId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + tableName: { + propDefinition: [ + sharepoint, + "tableName", + (c) => ({ + siteId: c.siteId, + itemId: c.itemId, + }), + ], + }, + removeHeaders: { + type: "boolean", + label: "Remove headers?", + optional: true, + description: "By default, The headers are included as the first row.", + default: false, + }, + numberOfRows: { + type: "integer", + optional: true, + default: 0, + min: 0, + label: "Number of rows to return", + description: "Leave blank to return all rows.", + }, + }, + async run({ $ }) { + const range = await this.sharepoint.getExcelTable({ + $, + siteId: this.siteId, + itemId: this.itemId, + tableName: this.tableName, + }); + + const response = this.removeHeaders + ? this.numberOfRows <= 0 + ? range.text.slice(1) + : range.text.slice(1, this.numberOfRows + 1) + : this.numberOfRows <= 0 + ? range.text + : range.text.slice(0, this.numberOfRows + 1); + + $.export("$summary", "Successfully retrieved excel table."); + + return response; + }, +}; diff --git a/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs b/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs new file mode 100644 index 0000000000000..4728ddd000453 --- /dev/null +++ b/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs @@ -0,0 +1,52 @@ +import sharepoint from "../../sharepoint.app.mjs"; + +export default { + key: "sharepoint-get-file-by-id", + name: "Get File by ID", + description: "Retrieves a file by ID. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + fileId: { + propDefinition: [ + sharepoint, + "fileId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + description: "The file to retrieve. You can either search for the file here, provide a custom *File ID*.", + }, + }, + async run({ $ }) { + const response = await this.sharepoint.getDriveItem({ + $, + siteId: this.siteId, + fileId: this.fileId, + }); + $.export("$summary", `Successfully retreived file with ID: ${this.fileId}`); + return response; + }, +}; diff --git a/components/sharepoint/actions/list-files-in-folder/list-files-in-folder.mjs b/components/sharepoint/actions/list-files-in-folder/list-files-in-folder.mjs new file mode 100644 index 0000000000000..1e0dd9bba8154 --- /dev/null +++ b/components/sharepoint/actions/list-files-in-folder/list-files-in-folder.mjs @@ -0,0 +1,67 @@ +import sharepoint from "../../sharepoint.app.mjs"; + +export default { + key: "sharepoint-list-files-in-folder", + name: "List Files in Folder", + description: "Retrieves a list of the files and/or folders directly within a folder. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_children)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + folderId: { + propDefinition: [ + sharepoint, + "folderId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + }, + excludeFolders: { + propDefinition: [ + sharepoint, + "excludeFolders", + ], + }, + }, + async run({ $ }) { + const response = this.folderId + ? await this.sharepoint.listDriveItemsInFolder({ + $, + siteId: this.siteId, + folderId: this.folderId, + }) + : await this.sharepoint.listDriveItems({ + $, + siteId: this.siteId, + driveId: this.driveId, + }); + const values = this.excludeFolders + ? response.value.filter(({ folder }) => !folder) + : response.value; + + $.export("$summary", `Found ${values.length} file(s) and/or folder(s)`); + return values; + }, +}; diff --git a/components/sharepoint/actions/update-item/update-item.mjs b/components/sharepoint/actions/update-item/update-item.mjs index 974c911586bf0..e6dc2fe6c1091 100644 --- a/components/sharepoint/actions/update-item/update-item.mjs +++ b/components/sharepoint/actions/update-item/update-item.mjs @@ -5,7 +5,7 @@ export default { key: "sharepoint-update-item", name: "Update Item", description: "Updates an existing item in Microsoft Sharepoint. [See the documentation](https://learn.microsoft.com/en-us/graph/api/listitem-update?view=graph-rest-1.0&tabs=http)", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: true, openWorldHint: true, diff --git a/components/sharepoint/actions/upload-file/upload-file.mjs b/components/sharepoint/actions/upload-file/upload-file.mjs new file mode 100644 index 0000000000000..bdcf7c425ed9a --- /dev/null +++ b/components/sharepoint/actions/upload-file/upload-file.mjs @@ -0,0 +1,86 @@ +import sharepoint from "../../sharepoint.app.mjs"; +import { getFileStreamAndMetadata } from "@pipedream/platform"; + +export default { + key: "sharepoint-upload-file", + name: "Upload File", + description: "Upload a file to OneDrive. [See the documentation](https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + sharepoint, + siteId: { + propDefinition: [ + sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + uploadFolderId: { + propDefinition: [ + sharepoint, + "folderId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + label: "Upload Folder ID", + description: "The ID of the folder where you want to upload the file. You can either search for the folder here or provide a custom *Folder ID*.", + }, + filePath: { + type: "string", + label: "File Path or URL", + description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)", + }, + filename: { + type: "string", + label: "Name", + description: "Name of the new uploaded file", + }, + syncDir: { + type: "dir", + accessMode: "read", + sync: true, + optional: true, + }, + }, + async run({ $ }) { + const { + siteId, driveId, uploadFolderId, filePath, filename, + } = this; + + const { + stream, metadata, + } = await getFileStreamAndMetadata(filePath); + const name = filename || metadata.name; + + const response = await this.sharepoint.uploadFile({ + siteId, + driveId, + uploadFolderId, + name, + data: stream, + $, + }); + + if (response?.id) { + $.export("$summary", `Successfully uploaded file with ID ${response.id}.`); + } + + return response; + }, +}; diff --git a/components/sharepoint/common/constants.mjs b/components/sharepoint/common/constants.mjs new file mode 100644 index 0000000000000..561612a84127a --- /dev/null +++ b/components/sharepoint/common/constants.mjs @@ -0,0 +1,30 @@ +const SHARING_LINK_TYPE_OPTIONS = [ + { + label: "Create a read-only link to the DriveItem", + value: "view", + }, + { + label: "Create a read-write link to the DriveItem", + value: "edit", + }, + { + label: "Create an embeddable link to the DriveItem. Only available for files in OneDrive personal.", + value: "embed", + }, +]; + +const SHARING_LINK_SCOPE_OPTIONS = [ + { + label: "Anyone with the link has access, without needing to sign in", + value: "anonymous", + }, + { + label: "Anyone signed into your organization can use the link. Only available in OneDrive for Business and SharePoint.", + value: "organization", + }, +]; + +export default { + SHARING_LINK_TYPE_OPTIONS, + SHARING_LINK_SCOPE_OPTIONS, +}; diff --git a/components/sharepoint/common/utils.mjs b/components/sharepoint/common/utils.mjs index 6cb98d98150b1..a440c55e58c53 100644 --- a/components/sharepoint/common/utils.mjs +++ b/components/sharepoint/common/utils.mjs @@ -7,4 +7,44 @@ export default { } return o; }, + adjustPropDefinitions(props, app) { + return Object.fromEntries( + Object.entries(props).map(([ + key, + prop, + ]) => { + if (typeof prop === "string") return [ + key, + prop, + ]; + const { + propDefinition, ...otherValues + } = prop; + if (propDefinition) { + const [ + , ...otherDefs + ] = propDefinition; + return [ + key, + { + propDefinition: [ + app, + ...otherDefs, + ], + ...otherValues, + }, + ]; + } + return [ + key, + otherValues.type === "app" + ? null + : otherValues, + ]; + }) + .filter(([ + , value, + ]) => value), + ); + }, }; diff --git a/components/sharepoint/package.json b/components/sharepoint/package.json index cee3c0e76b0ee..a978e75ab11c3 100644 --- a/components/sharepoint/package.json +++ b/components/sharepoint/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sharepoint", - "version": "0.3.3", + "version": "0.4.0", "description": "Pipedream Microsoft Sharepoint Online Components", "main": "sharepoint.app.mjs", "keywords": [ diff --git a/components/sharepoint/sharepoint.app.mjs b/components/sharepoint/sharepoint.app.mjs index 5c32d3d2963ac..9c94dcb632ab4 100644 --- a/components/sharepoint/sharepoint.app.mjs +++ b/components/sharepoint/sharepoint.app.mjs @@ -148,13 +148,44 @@ export default { }; }, }, + folderId: { + type: "string", + label: "Folder ID", + description: "The folder to list files in. You can either search for the folder here or provide a custom *Folder ID*.", + optional: true, + useQuery: true, + async options({ + query, siteId, driveId, + }) { + const response = query + ? await this.searchDriveItems({ + siteId, + query, + params: { + select: "folder,name,id", + }, + }) + : await this.listDriveItems({ + siteId, + driveId, + }); + const values = response.value.filter(({ folder }) => folder); + return values + .map(({ + name, id, + }) => ({ + label: name, + value: id, + })); + }, + }, fileId: { type: "string", label: "File ID", description: "The file to download. You can either search for the file here or provide a custom *File ID*.", useQuery: true, async options({ - query, siteId, driveId, + query, siteId, driveId, excludeFolders = true, }) { const response = query ? await this.searchDriveItems({ @@ -168,7 +199,9 @@ export default { siteId, driveId, }); - const values = response.value.filter(({ folder }) => !folder); + const values = excludeFolders + ? response.value.filter(({ folder }) => !folder) + : response.value; return values .map(({ name, id, @@ -178,24 +211,73 @@ export default { })); }, }, + excelFileId: { + type: "string", + label: "Spreadsheet", + description: "**Search for the file by name.** Only xlsx files are supported.", + useQuery: true, + async options({ + siteId, query, + }) { + const response = await this.searchDriveItems({ + siteId, + query, + params: { + select: "name,id", + }, + }); + return response.value.filter(({ name }) => name.endsWith(".xlsx")) + .map(({ + name, id, + }) => ({ + label: name, + value: id, + })); + }, + }, + tableName: { + type: "string", + label: "Table Name", + description: "This is set in the **Table Design** tab of the ribbon", + async options({ + siteId, itemId, + }) { + const response = await this.listExcelTables({ + siteId, + itemId, + params: { + select: "name", + }, + }); + return response.value.map(({ name }) => name); + }, + }, + excludeFolders: { + type: "boolean", + label: "Exclude Folders?", + description: "Set to `true` to return only files in the response. Defaults to `false`", + optional: true, + }, }, methods: { _baseUrl() { return "https://graph.microsoft.com/v1.0"; }, - _headers() { + _headers(headers) { return { Authorization: `Bearer ${this.$auth.oauth_access_token}`, + ...headers, }; }, _makeRequest({ $ = this, path, + headers, ...args }) { return axios($, { url: `${this._baseUrl()}${path}`, - headers: this._headers(), + headers: this._headers(headers), ...args, }); }, @@ -251,6 +333,79 @@ export default { ...args, }); }, + listDriveItemsInFolder({ + siteId, folderId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${folderId}/children`, + ...args, + }); + }, + createDriveItem({ + siteId, driveId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drives/${driveId}/items/root/children`, + method: "POST", + ...args, + }); + }, + createDriveItemInFolder({ + siteId, folderId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${folderId}/children`, + method: "POST", + ...args, + }); + }, + createLink({ + siteId, fileId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${fileId}/createLink`, + method: "POST", + ...args, + }); + }, + listExcelTables({ + siteId, itemId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${itemId}/workbook/tables`, + ...args, + }); + }, + getExcelTable({ + siteId, itemId, tableName, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${itemId}/workbook/tables/${tableName}/range`, + ...args, + }); + }, + uploadFile({ + siteId, driveId, uploadFolderId, name, ...args + }) { + return this._makeRequest({ + path: uploadFolderId + ? `/sites/${siteId}/drives/${driveId}/items/${uploadFolderId}:/${encodeURI(name)}:/content` + : `/sites/${siteId}/drives/${driveId}/root:/${encodeURI(name)}:/content`, + method: "PUT", + headers: { + "Content-Type": "application/octet-stream", + }, + ...args, + }); + }, + getDriveItem({ + siteId, fileId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${fileId}`, + ...args, + }); + }, searchDriveItems({ siteId, query, ...args }) { diff --git a/components/sharepoint/sources/common/common.mjs b/components/sharepoint/sources/common/common.mjs index c3eb4fe3dd4ed..29636af11f50b 100644 --- a/components/sharepoint/sources/common/common.mjs +++ b/components/sharepoint/sources/common/common.mjs @@ -23,6 +23,12 @@ export default { const meta = this.generateMeta(item); this.$emit(item, meta); }, + isSortedDesc() { + return false; + }, + isRelevant() { + return true; + }, getResourceFn() { throw new Error("getResourceFn is not implemented"); }, @@ -47,13 +53,19 @@ export default { args, }); + let count = 0; for await (const item of items) { const ts = Date.parse(item[this.getTsField()]); if (ts > lastTs) { - this.emitEvent(item); + if (this.isRelevant(item) && (lastTs || count < 10)) { + this.emitEvent(item); + count++; + } if (ts > maxTs) { maxTs = ts; } + } else if (this.isSortedDesc()) { + break; } } diff --git a/components/sharepoint/sources/new-file-created/new-file-created.mjs b/components/sharepoint/sources/new-file-created/new-file-created.mjs new file mode 100644 index 0000000000000..cdb41ede135b3 --- /dev/null +++ b/components/sharepoint/sources/new-file-created/new-file-created.mjs @@ -0,0 +1,73 @@ +import common from "../common/common.mjs"; + +export default { + ...common, + key: "sharepoint-new-file-created", + name: "New File Created", + description: "Emit new event when a new file is created in Microsoft Sharepoint.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + siteId: { + propDefinition: [ + common.props.sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + common.props.sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + folderId: { + propDefinition: [ + common.props.sharepoint, + "folderId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + }, + }, + methods: { + ...common.methods, + getResourceFn() { + return this.folderId + ? this.sharepoint.listDriveItemsInFolder + : this.sharepoint.listDriveItems; + }, + getArgs() { + return { + siteId: this.siteId, + driveId: this.driveId, + folderId: this.folderId, + params: { + orderby: "lastModifiedDateTime desc", + }, + }; + }, + getTsField() { + return "lastModifiedDateTime"; + }, + isSortedDesc() { + return true; + }, + isRelevant(item) { + return !!item.file; + }, + generateMeta(item) { + return { + id: item.id, + summary: `New File: ${item.name}`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, +}; diff --git a/components/sharepoint/sources/new-folder-created/new-folder-created.mjs b/components/sharepoint/sources/new-folder-created/new-folder-created.mjs new file mode 100644 index 0000000000000..586adcc2777b4 --- /dev/null +++ b/components/sharepoint/sources/new-folder-created/new-folder-created.mjs @@ -0,0 +1,73 @@ +import common from "../common/common.mjs"; + +export default { + ...common, + key: "sharepoint-new-folder-created", + name: "New Folder Created", + description: "Emit new event when a new folder is created in Microsoft Sharepoint.", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + siteId: { + propDefinition: [ + common.props.sharepoint, + "siteId", + ], + }, + driveId: { + propDefinition: [ + common.props.sharepoint, + "driveId", + (c) => ({ + siteId: c.siteId, + }), + ], + }, + folderId: { + propDefinition: [ + common.props.sharepoint, + "folderId", + (c) => ({ + siteId: c.siteId, + driveId: c.driveId, + }), + ], + }, + }, + methods: { + ...common.methods, + getResourceFn() { + return this.folderId + ? this.sharepoint.listDriveItemsInFolder + : this.sharepoint.listDriveItems; + }, + getArgs() { + return { + siteId: this.siteId, + driveId: this.driveId, + folderId: this.folderId, + params: { + orderby: "lastModifiedDateTime desc", + }, + }; + }, + getTsField() { + return "lastModifiedDateTime"; + }, + isSortedDesc() { + return true; + }, + isRelevant(item) { + return !!item.folder; + }, + generateMeta(item) { + return { + id: item.id, + summary: `New Folder: ${item.name}`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, +}; diff --git a/components/sharepoint/sources/new-list-item/new-list-item.mjs b/components/sharepoint/sources/new-list-item/new-list-item.mjs index 08ed675b2f542..7156991e642fc 100644 --- a/components/sharepoint/sources/new-list-item/new-list-item.mjs +++ b/components/sharepoint/sources/new-list-item/new-list-item.mjs @@ -4,8 +4,8 @@ export default { ...common, key: "sharepoint-new-list-item", name: "New List Item", - description: "Emit new event when a new list is created in Microsoft Sharepoint.", - version: "0.0.5", + description: "Emit new event when a new list item is created in Microsoft Sharepoint.", + version: "0.0.6", type: "source", dedupe: "unique", props: { diff --git a/components/sharepoint/sources/updated-list-item/updated-list-item.mjs b/components/sharepoint/sources/updated-list-item/updated-list-item.mjs index fb98c624e5549..263ad6d4498c7 100644 --- a/components/sharepoint/sources/updated-list-item/updated-list-item.mjs +++ b/components/sharepoint/sources/updated-list-item/updated-list-item.mjs @@ -4,7 +4,7 @@ export default { ...common, key: "sharepoint-updated-list-item", name: "Updated List Item", - description: "Emit new event when a list is updated in Microsoft Sharepoint.", + description: "Emit new event when a list item is updated in Microsoft Sharepoint.", version: "0.0.5", type: "source", dedupe: "unique", From 09b338be43bd4abdb8ab6766fb00025e95b08ea0 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 23 Oct 2025 13:58:26 -0400 Subject: [PATCH 2/3] updates --- components/sharepoint/common/utils.mjs | 40 ------------------- .../updated-list-item/updated-list-item.mjs | 2 +- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/components/sharepoint/common/utils.mjs b/components/sharepoint/common/utils.mjs index a440c55e58c53..6cb98d98150b1 100644 --- a/components/sharepoint/common/utils.mjs +++ b/components/sharepoint/common/utils.mjs @@ -7,44 +7,4 @@ export default { } return o; }, - adjustPropDefinitions(props, app) { - return Object.fromEntries( - Object.entries(props).map(([ - key, - prop, - ]) => { - if (typeof prop === "string") return [ - key, - prop, - ]; - const { - propDefinition, ...otherValues - } = prop; - if (propDefinition) { - const [ - , ...otherDefs - ] = propDefinition; - return [ - key, - { - propDefinition: [ - app, - ...otherDefs, - ], - ...otherValues, - }, - ]; - } - return [ - key, - otherValues.type === "app" - ? null - : otherValues, - ]; - }) - .filter(([ - , value, - ]) => value), - ); - }, }; diff --git a/components/sharepoint/sources/updated-list-item/updated-list-item.mjs b/components/sharepoint/sources/updated-list-item/updated-list-item.mjs index 263ad6d4498c7..e633d79288760 100644 --- a/components/sharepoint/sources/updated-list-item/updated-list-item.mjs +++ b/components/sharepoint/sources/updated-list-item/updated-list-item.mjs @@ -5,7 +5,7 @@ export default { key: "sharepoint-updated-list-item", name: "Updated List Item", description: "Emit new event when a list item is updated in Microsoft Sharepoint.", - version: "0.0.5", + version: "0.0.6", type: "source", dedupe: "unique", props: { From 45ff289dee9dab2b843ef70d147dd5b48f019729 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Thu, 23 Oct 2025 14:14:36 -0400 Subject: [PATCH 3/3] updates --- components/sharepoint/actions/create-folder/create-folder.mjs | 4 +++- .../sharepoint/actions/get-file-by-id/get-file-by-id.mjs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/sharepoint/actions/create-folder/create-folder.mjs b/components/sharepoint/actions/create-folder/create-folder.mjs index 29d63a71b4945..b0c57f6e8a0af 100644 --- a/components/sharepoint/actions/create-folder/create-folder.mjs +++ b/components/sharepoint/actions/create-folder/create-folder.mjs @@ -38,7 +38,7 @@ export default { }), ], label: "Parent Folder ID", - description: "The ID of the folder which the the new folder should be created. You can either search for the folder here or provide a custom *Folder ID*.", + description: "The ID of the folder in which the the new folder should be created. You can either search for the folder here or provide a custom *Folder ID*.", }, folderName: { type: "string", @@ -53,11 +53,13 @@ export default { }; const response = this.folderId ? await this.sharepoint.createDriveItemInFolder({ + $, siteId: this.siteId, folderId: this.folderId, data, }) : await this.sharepoint.createDriveItem({ + $, siteId: this.siteId, driveId: this.driveId, data, diff --git a/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs b/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs index 4728ddd000453..ea675e3e3e2e9 100644 --- a/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs +++ b/components/sharepoint/actions/get-file-by-id/get-file-by-id.mjs @@ -37,7 +37,7 @@ export default { driveId: c.driveId, }), ], - description: "The file to retrieve. You can either search for the file here, provide a custom *File ID*.", + description: "The file to retrieve. You can either search for the file here or provide a custom *File ID*.", }, }, async run({ $ }) { @@ -46,7 +46,7 @@ export default { siteId: this.siteId, fileId: this.fileId, }); - $.export("$summary", `Successfully retreived file with ID: ${this.fileId}`); + $.export("$summary", `Successfully retrieved file with ID: ${this.fileId}`); return response; }, };