Skip to content

Commit fd5f05f

Browse files
New Component - sharepoint (#16489)
* download-file * pnpm-lock.yaml * Update components/sharepoint/sharepoint.app.mjs Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com> --------- Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com>
1 parent afb07c1 commit fd5f05f

File tree

9 files changed

+163
-9
lines changed

9 files changed

+163
-9
lines changed

components/sharepoint/actions/create-item/create-item.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "sharepoint-create-item",
55
name: "Create Item",
66
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)",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
sharepoint,

components/sharepoint/actions/create-list/create-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "sharepoint-create-list",
55
name: "Create List",
66
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)",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
sharepoint,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sharepoint from "../../sharepoint.app.mjs";
2+
import fs from "fs";
3+
4+
export default {
5+
key: "sharepoint-download-file",
6+
name: "Download File",
7+
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)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
sharepoint,
12+
siteId: {
13+
propDefinition: [
14+
sharepoint,
15+
"siteId",
16+
],
17+
},
18+
driveId: {
19+
propDefinition: [
20+
sharepoint,
21+
"driveId",
22+
(c) => ({
23+
siteId: c.siteId,
24+
}),
25+
],
26+
},
27+
fileId: {
28+
propDefinition: [
29+
sharepoint,
30+
"fileId",
31+
(c) => ({
32+
siteId: c.siteId,
33+
driveId: c.driveId,
34+
}),
35+
],
36+
},
37+
filename: {
38+
type: "string",
39+
label: "Filename",
40+
description: "The filename to save the downloaded file as in the `/tmp` directory",
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = await this.sharepoint.getFile({
45+
$,
46+
siteId: this.siteId,
47+
fileId: this.fileId,
48+
responseType: "arraybuffer",
49+
});
50+
51+
const rawcontent = response.toString("base64");
52+
const buffer = Buffer.from(rawcontent, "base64");
53+
const downloadedFilepath = `/tmp/${this.filename}`;
54+
fs.writeFileSync(downloadedFilepath, buffer);
55+
56+
return {
57+
filename: this.filename,
58+
downloadedFilepath,
59+
};
60+
},
61+
};

components/sharepoint/actions/update-item/update-item.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sharepoint-update-item",
66
name: "Update Item",
77
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)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
sharepoint,

components/sharepoint/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sharepoint",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Pipedream Microsoft Sharepoint Online Components",
55
"main": "sharepoint.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1"
16+
"@pipedream/platform": "^3.0.3"
1717
}
1818
}

components/sharepoint/sharepoint.app.mjs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,67 @@ export default {
117117
};
118118
},
119119
},
120+
driveId: {
121+
type: "string",
122+
label: "Drive ID",
123+
description: "Identifier of a drive within a site",
124+
async options({
125+
prevContext, siteId,
126+
}) {
127+
if (!siteId) {
128+
return [];
129+
}
130+
const args = {
131+
siteId,
132+
};
133+
if (prevContext?.nextLink) {
134+
args.url = prevContext.nextLink;
135+
}
136+
const response = await this.listSiteDrives(args);
137+
const options = response.value?.map(({
138+
id: value, name: label,
139+
}) => ({
140+
value,
141+
label,
142+
})) || [];
143+
return {
144+
options,
145+
context: {
146+
nextLink: response["@odata.nextLink"],
147+
},
148+
};
149+
},
150+
},
151+
fileId: {
152+
type: "string",
153+
label: "File ID",
154+
description: "The file to download. You can either search for the file here or provide a custom *File ID*.",
155+
useQuery: true,
156+
async options({
157+
query, siteId, driveId,
158+
}) {
159+
const response = query
160+
? await this.searchDriveItems({
161+
siteId,
162+
query,
163+
params: {
164+
select: "folder,name,id",
165+
},
166+
})
167+
: await this.listDriveItems({
168+
siteId,
169+
driveId,
170+
});
171+
const values = response.value.filter(({ folder }) => !folder);
172+
return values
173+
.map(({
174+
name, id,
175+
}) => ({
176+
label: name,
177+
value: id,
178+
}));
179+
},
180+
},
120181
},
121182
methods: {
122183
_baseUrl() {
@@ -168,6 +229,38 @@ export default {
168229
...args,
169230
});
170231
},
232+
listSiteDrives({
233+
siteId, ...args
234+
}) {
235+
return this._makeRequest({
236+
path: `/sites/${siteId}/drives`,
237+
...args,
238+
});
239+
},
240+
listDriveItems({
241+
siteId, driveId, ...args
242+
}) {
243+
return this._makeRequest({
244+
path: `/sites/${siteId}/drives/${driveId}/items/root/children`,
245+
...args,
246+
});
247+
},
248+
searchDriveItems({
249+
siteId, query, ...args
250+
}) {
251+
return this._makeRequest({
252+
path: `/sites/${siteId}/drive/root/search(q='${query}')`,
253+
...args,
254+
});
255+
},
256+
getFile({
257+
siteId, fileId, ...args
258+
}) {
259+
return this._makeRequest({
260+
path: `/sites/${siteId}/drive/items/${fileId}/content`,
261+
...args,
262+
});
263+
},
171264
createList({
172265
siteId, ...args
173266
}) {

components/sharepoint/sources/new-list-item/new-list-item.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sharepoint-new-list-item",
66
name: "New List Item",
77
description: "Emit new event when a new list is created in Microsoft Sharepoint.",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
props: {

components/sharepoint/sources/updated-list-item/updated-list-item.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sharepoint-updated-list-item",
66
name: "Updated List Item",
77
description: "Emit new event when a list is updated in Microsoft Sharepoint.",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "source",
1010
dedupe: "unique",
1111
props: {

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)