From f6420cd80f54ac44a0717c236de8044c8a0b2c36 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 30 Apr 2025 13:10:35 -0400 Subject: [PATCH 1/3] download-file --- .../actions/create-item/create-item.mjs | 2 +- .../actions/create-list/create-list.mjs | 2 +- .../actions/download-file/download-file.mjs | 61 ++++++++++++ .../actions/update-item/update-item.mjs | 2 +- components/sharepoint/package.json | 4 +- components/sharepoint/sharepoint.app.mjs | 93 +++++++++++++++++++ .../sources/new-list-item/new-list-item.mjs | 2 +- .../updated-list-item/updated-list-item.mjs | 2 +- 8 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 components/sharepoint/actions/download-file/download-file.mjs diff --git a/components/sharepoint/actions/create-item/create-item.mjs b/components/sharepoint/actions/create-item/create-item.mjs index 7121cfff2e3a2..c758c252326a6 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.2", + version: "0.0.3", type: "action", props: { sharepoint, diff --git a/components/sharepoint/actions/create-list/create-list.mjs b/components/sharepoint/actions/create-list/create-list.mjs index 7a378a8e5c9b1..832c80c8f80de 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.2", + version: "0.0.3", type: "action", props: { sharepoint, diff --git a/components/sharepoint/actions/download-file/download-file.mjs b/components/sharepoint/actions/download-file/download-file.mjs new file mode 100644 index 0000000000000..b3c662c38daac --- /dev/null +++ b/components/sharepoint/actions/download-file/download-file.mjs @@ -0,0 +1,61 @@ +import sharepoint from "../../sharepoint.app.mjs"; +import fs from "fs"; + +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.1", + type: "action", + 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, + }), + ], + }, + filename: { + type: "string", + label: "Filename", + description: "The filename to save the downloaded file as in the `/tmp` directory", + }, + }, + async run({ $ }) { + const response = await this.sharepoint.getFile({ + $, + siteId: this.siteId, + fileId: this.fileId, + responseType: "arraybuffer", + }); + + const rawcontent = response.toString("base64"); + const buffer = Buffer.from(rawcontent, "base64"); + const downloadedFilepath = `/tmp/${this.filename}`; + fs.writeFileSync(downloadedFilepath, buffer); + + return { + filename: this.filename, + downloadedFilepath, + }; + }, +}; diff --git a/components/sharepoint/actions/update-item/update-item.mjs b/components/sharepoint/actions/update-item/update-item.mjs index 9a8944bc77207..a05e250492875 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.1", + version: "0.0.2", type: "action", props: { sharepoint, diff --git a/components/sharepoint/package.json b/components/sharepoint/package.json index 1058aad913830..4c9d12b349476 100644 --- a/components/sharepoint/package.json +++ b/components/sharepoint/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sharepoint", - "version": "0.2.0", + "version": "0.3.0", "description": "Pipedream Microsoft Sharepoint Online Components", "main": "sharepoint.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^1.5.1" + "@pipedream/platform": "^3.0.3" } } diff --git a/components/sharepoint/sharepoint.app.mjs b/components/sharepoint/sharepoint.app.mjs index 156cea6a86eb7..451f379bbe56b 100644 --- a/components/sharepoint/sharepoint.app.mjs +++ b/components/sharepoint/sharepoint.app.mjs @@ -117,6 +117,67 @@ export default { }; }, }, + driveId: { + type: "string", + label: "Drive ID", + description: "Identifier of a drive within a site", + async options({ + prevContext, siteId, + }) { + if (!siteId) { + return []; + } + const args = { + siteId, + }; + if (prevContext?.nextLink) { + args.url = prevContext.nextLink; + } + const response = await this.listSiteDrives(args); + const options = response.value?.map(({ + id: value, name: label, + }) => ({ + value, + label, + })) || []; + return { + options, + context: { + nextLink: response["@odata.nextLink"], + }, + }; + }, + }, + fileId: { + type: "string", + label: "File ID", + description: "The file to download. You can either search for the file here, provide a custom *File ID*.", + 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, + })); + }, + }, }, methods: { _baseUrl() { @@ -168,6 +229,38 @@ export default { ...args, }); }, + listSiteDrives({ + siteId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drives`, + ...args, + }); + }, + listDriveItems({ + siteId, driveId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drives/${driveId}/items/root/children`, + ...args, + }); + }, + searchDriveItems({ + siteId, query, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/root/search(q='${query}')`, + ...args, + }); + }, + getFile({ + siteId, fileId, ...args + }) { + return this._makeRequest({ + path: `/sites/${siteId}/drive/items/${fileId}/content`, + ...args, + }); + }, createList({ siteId, ...args }) { 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 6ea88894e9970..4c18625452128 100644 --- a/components/sharepoint/sources/new-list-item/new-list-item.mjs +++ b/components/sharepoint/sources/new-list-item/new-list-item.mjs @@ -5,7 +5,7 @@ export default { 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.2", + version: "0.0.3", 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 b57bf7854cc60..ead8a17b19215 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 is updated in Microsoft Sharepoint.", - version: "0.0.2", + version: "0.0.3", type: "source", dedupe: "unique", props: { From 6fcdc0d24f9bad148c6bba43591e6d265083bf71 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 30 Apr 2025 13:13:54 -0400 Subject: [PATCH 2/3] pnpm-lock.yaml --- pnpm-lock.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 452846d344d86..314c7bd871f12 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11703,8 +11703,8 @@ importers: components/sharepoint: dependencies: '@pipedream/platform': - specifier: ^1.5.1 - version: 1.6.6 + specifier: ^3.0.3 + version: 3.0.3 components/sharpspring: dependencies: From c890c5261139e2f2e25308894e80afef56b829d2 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Wed, 30 Apr 2025 16:14:36 -0400 Subject: [PATCH 3/3] Update components/sharepoint/sharepoint.app.mjs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com> --- components/sharepoint/sharepoint.app.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/sharepoint/sharepoint.app.mjs b/components/sharepoint/sharepoint.app.mjs index 451f379bbe56b..d523e4b640184 100644 --- a/components/sharepoint/sharepoint.app.mjs +++ b/components/sharepoint/sharepoint.app.mjs @@ -151,7 +151,7 @@ export default { fileId: { type: "string", label: "File ID", - description: "The file to download. You can either search for the file here, provide a custom *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,