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..d523e4b640184 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 or 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: { 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: