@pipedream/sharepoint 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/create-item/create-item.mjs +73 -0
- package/actions/create-list/create-list.mjs +44 -0
- package/package.json +5 -5
- package/sharepoint.app.mjs +180 -0
- package/sources/common/common.mjs +62 -0
- package/sources/new-list-item/new-list-item.mjs +54 -0
- package/sources/updated-list-item/updated-list-item.mjs +55 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import sharepoint from "../../sharepoint.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "sharepoint-create-item",
|
|
5
|
+
name: "Create Item",
|
|
6
|
+
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.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
sharepoint,
|
|
11
|
+
siteId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
sharepoint,
|
|
14
|
+
"siteId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
listId: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
sharepoint,
|
|
20
|
+
"listId",
|
|
21
|
+
(c) => ({
|
|
22
|
+
siteId: c.siteId,
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
columnNames: {
|
|
27
|
+
propDefinition: [
|
|
28
|
+
sharepoint,
|
|
29
|
+
"columnNames",
|
|
30
|
+
(c) => ({
|
|
31
|
+
siteId: c.siteId,
|
|
32
|
+
listId: c.listId,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
reloadProps: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
async additionalProps() {
|
|
39
|
+
const props = {};
|
|
40
|
+
if (!this.columnNames?.length) {
|
|
41
|
+
return props;
|
|
42
|
+
}
|
|
43
|
+
for (const column of this.columnNames) {
|
|
44
|
+
props[`${column}_value`] = {
|
|
45
|
+
type: "string",
|
|
46
|
+
label: `${column} Value`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return props;
|
|
50
|
+
},
|
|
51
|
+
async run({ $ }) {
|
|
52
|
+
const fields = {};
|
|
53
|
+
if (this.columnNames?.length) {
|
|
54
|
+
for (const column of this.columnNames) {
|
|
55
|
+
fields[column] = this[`${column}_value`];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const response = await this.sharepoint.createItem({
|
|
60
|
+
siteId: this.siteId,
|
|
61
|
+
listId: this.listId,
|
|
62
|
+
data: {
|
|
63
|
+
fields,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (response?.id) {
|
|
68
|
+
$.export("$summary", `Successfully created item with ID ${response.id}.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return response;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import sharepoint from "../../sharepoint.app.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
key: "sharepoint-create-list",
|
|
5
|
+
name: "Create List",
|
|
6
|
+
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.1",
|
|
8
|
+
type: "action",
|
|
9
|
+
props: {
|
|
10
|
+
sharepoint,
|
|
11
|
+
siteId: {
|
|
12
|
+
propDefinition: [
|
|
13
|
+
sharepoint,
|
|
14
|
+
"siteId",
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
name: {
|
|
18
|
+
type: "string",
|
|
19
|
+
label: "Name",
|
|
20
|
+
description: "Name of the list",
|
|
21
|
+
},
|
|
22
|
+
description: {
|
|
23
|
+
type: "string",
|
|
24
|
+
label: "Description",
|
|
25
|
+
description: "Description of the list",
|
|
26
|
+
optional: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
async run({ $ }) {
|
|
30
|
+
const response = await this.sharepoint.createList({
|
|
31
|
+
siteId: this.siteId,
|
|
32
|
+
data: {
|
|
33
|
+
displayName: this.name,
|
|
34
|
+
description: this.description,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (response?.id) {
|
|
39
|
+
$.export("$summary", `Successfully created list with ID ${response.id}.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return response;
|
|
43
|
+
},
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/sharepoint",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Microsoft Sharepoint Online Components",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "sharepoint.app.mjs",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"pipedream",
|
|
8
8
|
"sharepoint"
|
|
9
9
|
],
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
10
|
"homepage": "https://pipedream.com/apps/sharepoint",
|
|
14
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
15
12
|
"publishConfig": {
|
|
16
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^1.5.1"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
type: "app",
|
|
5
|
+
app: "sharepoint",
|
|
6
|
+
propDefinitions: {
|
|
7
|
+
siteId: {
|
|
8
|
+
type: "string",
|
|
9
|
+
label: "Site",
|
|
10
|
+
description: "Identifier of a site",
|
|
11
|
+
async options({ prevContext }) {
|
|
12
|
+
const args = prevContext?.nextLink
|
|
13
|
+
? {
|
|
14
|
+
url: prevContext.nextLink,
|
|
15
|
+
}
|
|
16
|
+
: {};
|
|
17
|
+
const response = await this.listSites(args);
|
|
18
|
+
const options = response.value?.map(({
|
|
19
|
+
id: value, displayName: label,
|
|
20
|
+
}) => ({
|
|
21
|
+
value,
|
|
22
|
+
label,
|
|
23
|
+
})) || [];
|
|
24
|
+
return {
|
|
25
|
+
options,
|
|
26
|
+
context: {
|
|
27
|
+
nextLink: response["@odata.nextLink"],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
listId: {
|
|
33
|
+
type: "string",
|
|
34
|
+
label: "List",
|
|
35
|
+
description: "Identifier of a list",
|
|
36
|
+
async options({
|
|
37
|
+
prevContext, siteId,
|
|
38
|
+
}) {
|
|
39
|
+
if (!siteId) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const args = {
|
|
43
|
+
siteId,
|
|
44
|
+
};
|
|
45
|
+
if (prevContext?.nextLink) {
|
|
46
|
+
args.url = prevContext.nextLink;
|
|
47
|
+
}
|
|
48
|
+
const response = await this.listLists(args);
|
|
49
|
+
const options = response.value?.map(({
|
|
50
|
+
id: value, name: label,
|
|
51
|
+
}) => ({
|
|
52
|
+
value,
|
|
53
|
+
label,
|
|
54
|
+
})) || [];
|
|
55
|
+
return {
|
|
56
|
+
options,
|
|
57
|
+
context: {
|
|
58
|
+
nextLink: response["@odata.nextLink"],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
columnNames: {
|
|
64
|
+
type: "string[]",
|
|
65
|
+
label: "Columns",
|
|
66
|
+
description: "Array of column names",
|
|
67
|
+
async options({
|
|
68
|
+
prevContext, siteId, listId,
|
|
69
|
+
}) {
|
|
70
|
+
if (!siteId || !listId) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const args = {
|
|
74
|
+
siteId,
|
|
75
|
+
listId,
|
|
76
|
+
};
|
|
77
|
+
if (prevContext?.nextLink) {
|
|
78
|
+
args.url = prevContext.nextLink;
|
|
79
|
+
}
|
|
80
|
+
const response = await this.listColumns(args);
|
|
81
|
+
const options = response.value?.map(({ name }) => name ) || [];
|
|
82
|
+
return {
|
|
83
|
+
options,
|
|
84
|
+
context: {
|
|
85
|
+
nextLink: response["@odata.nextLink"],
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
methods: {
|
|
92
|
+
_baseUrl() {
|
|
93
|
+
return "https://graph.microsoft.com/v1.0";
|
|
94
|
+
},
|
|
95
|
+
_headers() {
|
|
96
|
+
return {
|
|
97
|
+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
_makeRequest({
|
|
101
|
+
$ = this,
|
|
102
|
+
path,
|
|
103
|
+
...args
|
|
104
|
+
}) {
|
|
105
|
+
return axios($, {
|
|
106
|
+
url: `${this._baseUrl()}${path}`,
|
|
107
|
+
headers: this._headers(),
|
|
108
|
+
...args,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
listSites(args = {}) {
|
|
112
|
+
return this._makeRequest({
|
|
113
|
+
path: "/me/followedSites",
|
|
114
|
+
...args,
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
listLists({
|
|
118
|
+
siteId, ...args
|
|
119
|
+
}) {
|
|
120
|
+
return this._makeRequest({
|
|
121
|
+
path: `/sites/${siteId}/lists`,
|
|
122
|
+
...args,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
listColumns({
|
|
126
|
+
siteId, listId, ...args
|
|
127
|
+
}) {
|
|
128
|
+
return this._makeRequest({
|
|
129
|
+
path: `/sites/${siteId}/lists/${listId}/columns`,
|
|
130
|
+
...args,
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
listItems({
|
|
134
|
+
siteId, listId, ...args
|
|
135
|
+
}) {
|
|
136
|
+
return this._makeRequest({
|
|
137
|
+
path: `/sites/${siteId}/lists/${listId}/items`,
|
|
138
|
+
...args,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
createList({
|
|
142
|
+
siteId, ...args
|
|
143
|
+
}) {
|
|
144
|
+
return this._makeRequest({
|
|
145
|
+
path: `/sites/${siteId}/lists`,
|
|
146
|
+
method: "POST",
|
|
147
|
+
...args,
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
createItem({
|
|
151
|
+
siteId, listId, ...args
|
|
152
|
+
}) {
|
|
153
|
+
return this._makeRequest({
|
|
154
|
+
path: `/sites/${siteId}/lists/${listId}/items`,
|
|
155
|
+
method: "POST",
|
|
156
|
+
...args,
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
async *paginate({
|
|
160
|
+
fn, args,
|
|
161
|
+
}) {
|
|
162
|
+
let nextLink;
|
|
163
|
+
do {
|
|
164
|
+
if (nextLink) {
|
|
165
|
+
args = {
|
|
166
|
+
...args,
|
|
167
|
+
url: nextLink,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const response = await fn(args);
|
|
171
|
+
|
|
172
|
+
for (const value of response.value) {
|
|
173
|
+
yield value;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
nextLink = response["@odata.nextLink"];
|
|
177
|
+
} while (nextLink);
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import sharepoint from "../../sharepoint.app.mjs";
|
|
2
|
+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
sharepoint,
|
|
7
|
+
db: "$.service.db",
|
|
8
|
+
timer: {
|
|
9
|
+
type: "$.interface.timer",
|
|
10
|
+
default: {
|
|
11
|
+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
methods: {
|
|
16
|
+
_getLastTs() {
|
|
17
|
+
return this.db.get("lastTs") || 0;
|
|
18
|
+
},
|
|
19
|
+
_setLastTs(lastTs) {
|
|
20
|
+
this.db.set("lastTs", lastTs);
|
|
21
|
+
},
|
|
22
|
+
emitEvent(item) {
|
|
23
|
+
const meta = this.generateMeta(item);
|
|
24
|
+
this.$emit(item, meta);
|
|
25
|
+
},
|
|
26
|
+
getResourceFn() {
|
|
27
|
+
throw new Error("getResourceFn is not implemented");
|
|
28
|
+
},
|
|
29
|
+
getArgs() {
|
|
30
|
+
throw new Error("getArgs is not implemented");
|
|
31
|
+
},
|
|
32
|
+
getTsField() {
|
|
33
|
+
throw new Error("getTsField is not implemented");
|
|
34
|
+
},
|
|
35
|
+
generateMeta() {
|
|
36
|
+
throw new Error("generateMeta is not implemented");
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
async run() {
|
|
40
|
+
const lastTs = this._getLastTs();
|
|
41
|
+
let maxTs = lastTs;
|
|
42
|
+
|
|
43
|
+
const fn = this.getResourceFn();
|
|
44
|
+
const args = this.getArgs();
|
|
45
|
+
const items = this.sharepoint.paginate({
|
|
46
|
+
fn,
|
|
47
|
+
args,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
for await (const item of items) {
|
|
51
|
+
const ts = Date.parse(item[this.getTsField()]);
|
|
52
|
+
if (ts > lastTs) {
|
|
53
|
+
this.emitEvent(item);
|
|
54
|
+
if (ts > maxTs) {
|
|
55
|
+
maxTs = ts;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this._setLastTs(maxTs);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import common from "../common/common.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...common,
|
|
5
|
+
key: "sharepoint-new-list-item",
|
|
6
|
+
name: "New List Item",
|
|
7
|
+
description: "Emit new event when a new list is created in Microsoft Sharepoint.",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "source",
|
|
10
|
+
dedupe: "unique",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
siteId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
common.props.sharepoint,
|
|
16
|
+
"siteId",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
listId: {
|
|
20
|
+
propDefinition: [
|
|
21
|
+
common.props.sharepoint,
|
|
22
|
+
"listId",
|
|
23
|
+
(c) => ({
|
|
24
|
+
siteId: c.siteId,
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
...common.methods,
|
|
31
|
+
getResourceFn() {
|
|
32
|
+
return this.sharepoint.listItems;
|
|
33
|
+
},
|
|
34
|
+
getArgs() {
|
|
35
|
+
return {
|
|
36
|
+
siteId: this.siteId,
|
|
37
|
+
listId: this.listId,
|
|
38
|
+
params: {
|
|
39
|
+
expand: "fields",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
getTsField() {
|
|
44
|
+
return "createdDateTime";
|
|
45
|
+
},
|
|
46
|
+
generateMeta(item) {
|
|
47
|
+
return {
|
|
48
|
+
id: item.id.slice(-64),
|
|
49
|
+
summary: `New Item ${item.id}`,
|
|
50
|
+
ts: Date.parse(item.createdDateTime),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import common from "../common/common.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...common,
|
|
5
|
+
key: "sharepoint-updated-list-item",
|
|
6
|
+
name: "Updated List Item",
|
|
7
|
+
description: "Emit new event when a list is updated in Microsoft Sharepoint.",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "source",
|
|
10
|
+
dedupe: "unique",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
siteId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
common.props.sharepoint,
|
|
16
|
+
"siteId",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
listId: {
|
|
20
|
+
propDefinition: [
|
|
21
|
+
common.props.sharepoint,
|
|
22
|
+
"listId",
|
|
23
|
+
(c) => ({
|
|
24
|
+
siteId: c.siteId,
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
...common.methods,
|
|
31
|
+
getResourceFn() {
|
|
32
|
+
return this.sharepoint.listItems;
|
|
33
|
+
},
|
|
34
|
+
getArgs() {
|
|
35
|
+
return {
|
|
36
|
+
siteId: this.siteId,
|
|
37
|
+
listId: this.listId,
|
|
38
|
+
params: {
|
|
39
|
+
expand: "fields",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
getTsField() {
|
|
44
|
+
return "lastModifiedDateTime";
|
|
45
|
+
},
|
|
46
|
+
generateMeta(item) {
|
|
47
|
+
const ts = Date.parse(item.lastModifiedDateTime);
|
|
48
|
+
return {
|
|
49
|
+
id: `${item.id.slice(-51)}${ts}`,
|
|
50
|
+
summary: `Updated Item ${item.id}`,
|
|
51
|
+
ts,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|