@activepieces/piece-microsoft-sharepoint 0.1.1 → 0.1.3
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/package.json +7 -13
- package/src/lib/triggers/new-list-item.js +64 -77
- package/src/lib/triggers/new-list-item.js.map +1 -1
- package/src/lib/triggers/new-list.js +59 -71
- package/src/lib/triggers/new-list.js.map +1 -1
- package/src/lib/triggers/new-or-updated-file.js +82 -81
- package/src/lib/triggers/new-or-updated-file.js.map +1 -1
- package/src/lib/triggers/new-or-updated-folder.js +82 -81
- package/src/lib/triggers/new-or-updated-folder.js.map +1 -1
- package/src/lib/triggers/new-or-updated-list.js +71 -69
- package/src/lib/triggers/new-or-updated-list.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/piece-microsoft-sharepoint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@microsoft/microsoft-graph-client": "3.0.7",
|
|
6
6
|
"@microsoft/microsoft-graph-types": "2.40.0",
|
|
7
7
|
"@sinclair/typebox": "0.34.11",
|
|
8
8
|
"axios": "1.8.3",
|
|
9
9
|
"axios-retry": "4.4.1",
|
|
10
|
+
"dayjs": "1.11.9",
|
|
10
11
|
"deepmerge-ts": "7.1.0",
|
|
11
12
|
"mime-types": "2.1.35",
|
|
12
13
|
"nanoid": "3.3.8",
|
|
13
14
|
"semver": "7.6.0",
|
|
15
|
+
"socket.io-client": "4.8.1",
|
|
14
16
|
"zod": "3.25.76",
|
|
15
|
-
"@activepieces/pieces-common": "0.
|
|
16
|
-
"@activepieces/pieces-framework": "0.20.
|
|
17
|
-
"@activepieces/shared": "0.
|
|
18
|
-
"tslib": "2.
|
|
19
|
-
},
|
|
20
|
-
"overrides": {
|
|
21
|
-
"@tryfabric/martian": {
|
|
22
|
-
"@notionhq/client": "$@notionhq/client"
|
|
23
|
-
},
|
|
24
|
-
"vite": {
|
|
25
|
-
"rollup": "npm:@rollup/wasm-node"
|
|
26
|
-
}
|
|
17
|
+
"@activepieces/pieces-common": "0.8.1",
|
|
18
|
+
"@activepieces/pieces-framework": "0.20.2",
|
|
19
|
+
"@activepieces/shared": "0.25.2",
|
|
20
|
+
"tslib": "2.6.2"
|
|
27
21
|
},
|
|
28
22
|
"resolutions": {
|
|
29
23
|
"rollup": "npm:@rollup/wasm-node"
|
|
@@ -6,102 +6,89 @@ const __1 = require("../../");
|
|
|
6
6
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
-
const
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
11
|
+
const polling = {
|
|
12
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
13
|
+
items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
14
|
+
const { siteId, listId } = propsValue;
|
|
15
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
16
|
+
authProvider: {
|
|
17
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const items = [];
|
|
21
|
+
const filter = lastFetchEpochMS === 0 ? `$filter=createdDateTime gt ${(0, dayjs_1.default)().toISOString()}` : '$top=10';
|
|
22
|
+
let response = yield client
|
|
23
|
+
.api(`/sites/${siteId}/lists/${listId}/items?${filter}`)
|
|
24
|
+
.expand('fields')
|
|
25
|
+
.get();
|
|
26
|
+
if (lastFetchEpochMS === 0) {
|
|
27
|
+
for (const message of response.value) {
|
|
28
|
+
items.push(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
while (response.value.length > 0) {
|
|
33
|
+
for (const message of response.value) {
|
|
34
|
+
items.push(message);
|
|
35
|
+
}
|
|
36
|
+
if (response['@odata.nextLink']) {
|
|
37
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
items.sort((a, b) => {
|
|
45
|
+
const aDate = (0, dayjs_1.default)(a.createdDateTime);
|
|
46
|
+
const bDate = (0, dayjs_1.default)(b.createdDateTime);
|
|
47
|
+
return bDate.diff(aDate);
|
|
48
|
+
});
|
|
49
|
+
return items.map((item) => ({
|
|
50
|
+
epochMilliSeconds: (0, dayjs_1.default)(item.createdDateTime).valueOf(),
|
|
51
|
+
data: item,
|
|
52
|
+
}));
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
10
55
|
exports.newListItemTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
56
|
auth: __1.microsoftSharePointAuth,
|
|
12
57
|
name: 'new_list_item',
|
|
13
58
|
displayName: 'New List Item',
|
|
14
|
-
description: '
|
|
59
|
+
description: 'Triggers when a new item is created in a SharePoint list.',
|
|
15
60
|
props: {
|
|
16
61
|
siteId: common_1.microsoftSharePointCommon.siteId,
|
|
17
62
|
listId: common_1.microsoftSharePointCommon.listId,
|
|
18
63
|
},
|
|
19
|
-
type: pieces_framework_1.TriggerStrategy.
|
|
20
|
-
sampleData:
|
|
21
|
-
"id": "3",
|
|
22
|
-
"createdDateTime": "2025-09-26T14:41:00Z",
|
|
23
|
-
"lastModifiedDateTime": "2025-09-26T14:41:00Z",
|
|
24
|
-
"webUrl": "https://contoso.sharepoint.com/sites/MySite/Lists/MyTasks/3_.000",
|
|
25
|
-
"fields": {
|
|
26
|
-
"@odata.etag": "\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,1\"",
|
|
27
|
-
"id": "3",
|
|
28
|
-
"Title": "Draft Q4 Marketing Plan",
|
|
29
|
-
"Status": "Not Started",
|
|
30
|
-
"Priority": "Normal",
|
|
31
|
-
"DueDate": "2025-11-15T00:00:00Z"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
64
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
65
|
+
sampleData: undefined,
|
|
34
66
|
onEnable(context) {
|
|
35
67
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
68
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
69
|
+
auth: context.auth,
|
|
70
|
+
store: context.store,
|
|
71
|
+
propsValue: context.propsValue,
|
|
41
72
|
});
|
|
42
|
-
try {
|
|
43
|
-
const expirationDateTime = new Date();
|
|
44
|
-
expirationDateTime.setDate(expirationDateTime.getDate() + 2);
|
|
45
|
-
const subscription = yield client.api('/subscriptions').post({
|
|
46
|
-
changeType: 'created',
|
|
47
|
-
notificationUrl: context.webhookUrl,
|
|
48
|
-
resource: `/sites/${siteId}/lists/${listId}/items`,
|
|
49
|
-
expirationDateTime: expirationDateTime.toISOString(),
|
|
50
|
-
clientState: clientState,
|
|
51
|
-
});
|
|
52
|
-
yield context.store.put('subscriptionId', subscription.id);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw new Error(`Failed to create subscription: ${error.message || 'Unknown error'}`);
|
|
56
|
-
}
|
|
57
73
|
});
|
|
58
74
|
},
|
|
59
75
|
onDisable(context) {
|
|
60
76
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.warn(`Error deleting subscription ${subscriptionId}:`, error);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
yield context.store.delete('subscriptionId');
|
|
77
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
78
|
+
auth: context.auth,
|
|
79
|
+
store: context.store,
|
|
80
|
+
propsValue: context.propsValue,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
test(context) {
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
76
87
|
});
|
|
77
88
|
},
|
|
78
89
|
run(context) {
|
|
79
90
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
|
|
81
|
-
const notifications = (_a = context.payload.body) === null || _a === void 0 ? void 0 : _a.value;
|
|
82
|
-
if (!notifications || !Array.isArray(notifications)) {
|
|
83
|
-
return [];
|
|
84
|
-
}
|
|
85
|
-
const validNotifications = notifications.filter((notif) => notif.clientState === clientState);
|
|
86
|
-
if (validNotifications.length === 0) {
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
90
|
-
authProvider: {
|
|
91
|
-
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
const newItemPayloads = [];
|
|
95
|
-
for (const notification of validNotifications) {
|
|
96
|
-
try {
|
|
97
|
-
const newItem = yield client.api(notification.resource).expand('fields').get();
|
|
98
|
-
newItemPayloads.push(newItem);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
console.error('Error fetching list item from notification:', error);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return newItemPayloads;
|
|
91
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
105
92
|
});
|
|
106
93
|
},
|
|
107
94
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-list-item.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-list-item.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC;AACxC,sCAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"new-list-item.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-list-item.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC;AACxC,sCAAsD;AACtD,8EAA2E;AAC3E,+DAAqF;AACrF,0DAA0B;AAQ1B,MAAM,OAAO,GAAyE;IACrF,QAAQ,EAAE,8BAAc,CAAC,SAAS;IAClC,KAAK,EAAE,KAA+C,EAAE,oDAA1C,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE;QACnD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;QAEtC,MAAM,MAAM,GAAG,+BAAM,CAAC,kBAAkB,CAAC;YACxC,YAAY,EAAE;gBACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;aACxD;SACD,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,MAAM,MAAM,GACX,gBAAgB,KAAK,CAAC,CAAC,CAAC,CAAC,8BAA8B,IAAA,eAAK,GAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAG5F,IAAI,QAAQ,GAAmB,MAAM,MAAM;aACzC,GAAG,CAAC,UAAU,MAAM,UAAU,MAAM,UAAU,MAAM,EAAE,CAAC;aACvD,MAAM,CAAC,QAAQ,CAAC;aAChB,GAAG,EAAE,CAAC;QAER,IAAI,gBAAgB,KAAK,CAAC,EAAE,CAAC;YAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,KAAmB,EAAE,CAAC;gBACpD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,CAAC;QACF,CAAC;aAAM,CAAC;YACP,OAAO,QAAQ,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AS;IACf,QAAQ,CAAC,OAAO;;YACrB,MAAM,6BAAa,CAAC,QAAQ,CAAC,OAAO,EAAE;gBACrC,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC9B,CAAC,CAAC;QACJ,CAAC;KAAA;IACK,SAAS,CAAC,OAAO;;YACtB,MAAM,6BAAa,CAAC,SAAS,CAAC,OAAO,EAAE;gBACtC,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC9B,CAAC,CAAC;QACJ,CAAC;KAAA;IACK,IAAI,CAAC,OAAO;;YACjB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;IACK,GAAG,CAAC,OAAO;;YAChB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -6,95 +6,83 @@ const __1 = require("../../");
|
|
|
6
6
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
-
const
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
11
|
+
const polling = {
|
|
12
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
13
|
+
items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
14
|
+
const { siteId } = propsValue;
|
|
15
|
+
const isTestMode = lastFetchEpochMS === 0;
|
|
16
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
17
|
+
authProvider: {
|
|
18
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const lists = [];
|
|
22
|
+
let response = yield client.api(`/sites/${siteId}/lists`).get();
|
|
23
|
+
let stop = false;
|
|
24
|
+
while (!stop && response.value.length > 0) {
|
|
25
|
+
for (const item of response.value) {
|
|
26
|
+
if (isTestMode) {
|
|
27
|
+
lists.push(item);
|
|
28
|
+
if (lists.length >= 10) {
|
|
29
|
+
stop = true;
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
lists.push(item);
|
|
34
|
+
}
|
|
35
|
+
if (stop || !response['@odata.nextLink'])
|
|
36
|
+
break;
|
|
37
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
38
|
+
}
|
|
39
|
+
lists.sort((a, b) => {
|
|
40
|
+
const aDate = (0, dayjs_1.default)(a.createdDateTime);
|
|
41
|
+
const bDate = (0, dayjs_1.default)(b.createdDateTime);
|
|
42
|
+
return bDate.diff(aDate);
|
|
43
|
+
});
|
|
44
|
+
return lists.map((list) => ({
|
|
45
|
+
epochMilliSeconds: (0, dayjs_1.default)(list.createdDateTime).valueOf(),
|
|
46
|
+
data: list,
|
|
47
|
+
}));
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
10
50
|
exports.newListTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
51
|
auth: __1.microsoftSharePointAuth,
|
|
12
52
|
name: 'new_list',
|
|
13
53
|
displayName: 'New List',
|
|
14
|
-
description: '
|
|
54
|
+
description: 'Triggers when a new list is created in a site.',
|
|
15
55
|
props: {
|
|
16
56
|
siteId: common_1.microsoftSharePointCommon.siteId,
|
|
17
57
|
},
|
|
18
|
-
type: pieces_framework_1.TriggerStrategy.
|
|
19
|
-
sampleData:
|
|
20
|
-
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
21
|
-
"displayName": "Asset Management",
|
|
22
|
-
"description": "A new list to track company assets.",
|
|
23
|
-
"createdDateTime": "2025-09-26T14:45:00Z",
|
|
24
|
-
"lastModifiedDateTime": "2025-09-26T14:45:00Z",
|
|
25
|
-
"webUrl": "https://contoso.sharepoint.com/sites/MySite/Lists/Asset%20Management"
|
|
26
|
-
},
|
|
58
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
59
|
+
sampleData: undefined,
|
|
27
60
|
onEnable(context) {
|
|
28
61
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
62
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
63
|
+
auth: context.auth,
|
|
64
|
+
store: context.store,
|
|
65
|
+
propsValue: context.propsValue,
|
|
34
66
|
});
|
|
35
|
-
try {
|
|
36
|
-
const expirationDateTime = new Date();
|
|
37
|
-
expirationDateTime.setDate(expirationDateTime.getDate() + 2);
|
|
38
|
-
const subscription = yield client.api('/subscriptions').post({
|
|
39
|
-
changeType: 'created',
|
|
40
|
-
notificationUrl: context.webhookUrl,
|
|
41
|
-
resource: `/sites/${siteId}/lists`,
|
|
42
|
-
expirationDateTime: expirationDateTime.toISOString(),
|
|
43
|
-
clientState: clientState,
|
|
44
|
-
});
|
|
45
|
-
yield context.store.put('subscriptionId', subscription.id);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new Error(`Failed to create subscription: ${error.message || 'Unknown error'}`);
|
|
49
|
-
}
|
|
50
67
|
});
|
|
51
68
|
},
|
|
52
69
|
onDisable(context) {
|
|
53
70
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
catch (error) {
|
|
65
|
-
console.warn(`Error deleting subscription ${subscriptionId}:`, error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
yield context.store.delete('subscriptionId');
|
|
71
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
72
|
+
auth: context.auth,
|
|
73
|
+
store: context.store,
|
|
74
|
+
propsValue: context.propsValue,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
test(context) {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
69
81
|
});
|
|
70
82
|
},
|
|
71
83
|
run(context) {
|
|
72
84
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
const notifications = (_a = context.payload.body) === null || _a === void 0 ? void 0 : _a.value;
|
|
75
|
-
if (!notifications || !Array.isArray(notifications)) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const validNotifications = notifications.filter((notif) => notif.clientState === clientState);
|
|
79
|
-
if (validNotifications.length === 0) {
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
83
|
-
authProvider: {
|
|
84
|
-
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
const newListPayloads = [];
|
|
88
|
-
for (const notification of validNotifications) {
|
|
89
|
-
try {
|
|
90
|
-
const newList = yield client.api(notification.resource).get();
|
|
91
|
-
newListPayloads.push(newList);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error('Error fetching list from notification:', error);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return newListPayloads;
|
|
85
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
98
86
|
});
|
|
99
87
|
},
|
|
100
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-list.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-list.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC;AACxC,sCAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"new-list.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-list.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC;AACxC,sCAAsD;AACtD,8EAA2E;AAC3E,+DAAqF;AACrF,0DAA0B;AAM1B,MAAM,OAAO,GAAyE;IACrF,QAAQ,EAAE,8BAAc,CAAC,SAAS;IAClC,KAAK,EAAE,KAA+C,EAAE,oDAA1C,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE;QACnD,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC;QAC9B,MAAM,UAAU,GAAG,gBAAgB,KAAK,CAAC,CAAC;QAE1C,MAAM,MAAM,GAAG,+BAAM,CAAC,kBAAkB,CAAC;YACxC,YAAY,EAAE;gBACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;aACxD;SACD,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,IAAI,QAAQ,GAAmB,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,MAAM,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC;QAEhF,IAAI,IAAI,GAAG,KAAK,CAAC;QAEjB,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAe,EAAE,CAAC;gBAC7C,IAAI,UAAU,EAAE,CAAC;oBAChB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACjB,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;wBACxB,IAAI,GA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,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC9B,CAAC,CAAC;QACJ,CAAC;KAAA;IACK,SAAS,CAAC,OAAO;;YACtB,MAAM,6BAAa,CAAC,SAAS,CAAC,OAAO,EAAE;gBACtC,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC9B,CAAC,CAAC;QACJ,CAAC;KAAA;IACK,IAAI,CAAC,OAAO;;YACjB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;IACK,GAAG,CAAC,OAAO;;YAChB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -6,12 +6,65 @@ const __1 = require("../../");
|
|
|
6
6
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
-
const
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
11
|
+
const polling = {
|
|
12
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
13
|
+
items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
14
|
+
const { siteId, driveId, folderId } = propsValue;
|
|
15
|
+
const isTestMode = lastFetchEpochMS === 0;
|
|
16
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
17
|
+
authProvider: {
|
|
18
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const files = [];
|
|
22
|
+
const endpoint = folderId !== 'root'
|
|
23
|
+
? `/sites/${siteId}/drive/items/${folderId}/children`
|
|
24
|
+
: `/sites/${siteId}/drives/${driveId}/items/root/children`;
|
|
25
|
+
let response = yield client
|
|
26
|
+
.api(endpoint)
|
|
27
|
+
.orderby('lastModifiedDateTime desc')
|
|
28
|
+
.get();
|
|
29
|
+
let stop = false;
|
|
30
|
+
while (!stop && response.value.length > 0) {
|
|
31
|
+
for (const item of response.value) {
|
|
32
|
+
if (!item.file)
|
|
33
|
+
continue;
|
|
34
|
+
const modifiedMs = (0, dayjs_1.default)(item.lastModifiedDateTime).valueOf();
|
|
35
|
+
if (isTestMode) {
|
|
36
|
+
files.push(item);
|
|
37
|
+
if (files.length >= 10) {
|
|
38
|
+
stop = true;
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (modifiedMs < lastFetchEpochMS) {
|
|
43
|
+
stop = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
files.push(item);
|
|
47
|
+
}
|
|
48
|
+
if (stop || !response['@odata.nextLink'])
|
|
49
|
+
break;
|
|
50
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
51
|
+
}
|
|
52
|
+
files.sort((a, b) => {
|
|
53
|
+
const aDate = (0, dayjs_1.default)(a.lastModifiedDateTime);
|
|
54
|
+
const bDate = (0, dayjs_1.default)(b.lastModifiedDateTime);
|
|
55
|
+
return bDate.diff(aDate);
|
|
56
|
+
});
|
|
57
|
+
return files.map((file) => ({
|
|
58
|
+
epochMilliSeconds: (0, dayjs_1.default)(file.lastModifiedDateTime).valueOf(),
|
|
59
|
+
data: file,
|
|
60
|
+
}));
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
10
63
|
exports.newOrUpdatedFileTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
64
|
auth: __1.microsoftSharePointAuth,
|
|
12
65
|
name: 'new_or_updated_file',
|
|
13
66
|
displayName: 'New or Updated File',
|
|
14
|
-
description: '
|
|
67
|
+
description: 'Triggers when a file is created or updated in a given folder.',
|
|
15
68
|
props: {
|
|
16
69
|
siteId: common_1.microsoftSharePointCommon.siteId,
|
|
17
70
|
driveId: common_1.microsoftSharePointCommon.driveId,
|
|
@@ -34,11 +87,9 @@ exports.newOrUpdatedFileTrigger = (0, pieces_framework_1.createTrigger)({
|
|
|
34
87
|
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
35
88
|
},
|
|
36
89
|
});
|
|
37
|
-
const options = [
|
|
38
|
-
{ label: 'Root Folder', value: 'root' },
|
|
39
|
-
];
|
|
90
|
+
const options = [{ label: 'Root Folder', value: 'root' }];
|
|
40
91
|
let response = yield client
|
|
41
|
-
.api(`/drives/${driveId}/root/children?$filter=folder ne null&$select=id,name`)
|
|
92
|
+
.api(`/sites/${siteId}/drives/${driveId}/items/root/children?$filter=folder ne null&$select=id,name`)
|
|
42
93
|
.get();
|
|
43
94
|
while (response.value.length > 0) {
|
|
44
95
|
for (const item of response.value) {
|
|
@@ -55,95 +106,45 @@ exports.newOrUpdatedFileTrigger = (0, pieces_framework_1.createTrigger)({
|
|
|
55
106
|
}),
|
|
56
107
|
}),
|
|
57
108
|
},
|
|
58
|
-
type: pieces_framework_1.TriggerStrategy.
|
|
109
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
59
110
|
sampleData: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
111
|
+
id: '01DRYVE_ID_GOES_HERE',
|
|
112
|
+
name: 'Updated-Financials.xlsx',
|
|
113
|
+
webUrl: 'https://contoso.sharepoint.com/Shared%20Documents/Updated-Financials.xlsx',
|
|
114
|
+
size: 65432,
|
|
115
|
+
createdDateTime: '2025-09-26T10:00:00Z',
|
|
116
|
+
lastModifiedDateTime: '2025-09-26T14:34:00Z',
|
|
117
|
+
file: {
|
|
118
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
68
119
|
},
|
|
69
|
-
|
|
120
|
+
parentReference: { id: 'PARENT_FOLDER_ID_HERE' },
|
|
70
121
|
},
|
|
71
122
|
onEnable(context) {
|
|
72
123
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
124
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
125
|
+
auth: context.auth,
|
|
126
|
+
store: context.store,
|
|
127
|
+
propsValue: context.propsValue,
|
|
78
128
|
});
|
|
79
|
-
try {
|
|
80
|
-
const effectiveFolderId = folderId === 'root'
|
|
81
|
-
? (yield client.api(`/drives/${driveId}/root`).get()).id
|
|
82
|
-
: folderId;
|
|
83
|
-
const expirationDateTime = new Date();
|
|
84
|
-
expirationDateTime.setDate(expirationDateTime.getDate() + 2);
|
|
85
|
-
const subscription = yield client.api('/subscriptions').post({
|
|
86
|
-
changeType: 'created,updated',
|
|
87
|
-
notificationUrl: context.webhookUrl,
|
|
88
|
-
resource: `/sites/${siteId}/drive/items/${effectiveFolderId}/children`,
|
|
89
|
-
expirationDateTime: expirationDateTime.toISOString(),
|
|
90
|
-
clientState: clientState,
|
|
91
|
-
});
|
|
92
|
-
yield context.store.put('subscriptionId', subscription.id);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
throw new Error(`Failed to create subscription: ${error.message || 'Unknown error'}`);
|
|
96
|
-
}
|
|
97
129
|
});
|
|
98
130
|
},
|
|
99
131
|
onDisable(context) {
|
|
100
132
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.warn(`Error deleting subscription ${subscriptionId}:`, error);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
yield context.store.delete('subscriptionId');
|
|
133
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
134
|
+
auth: context.auth,
|
|
135
|
+
store: context.store,
|
|
136
|
+
propsValue: context.propsValue,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
test(context) {
|
|
141
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
116
143
|
});
|
|
117
144
|
},
|
|
118
145
|
run(context) {
|
|
119
146
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
|
|
121
|
-
const notifications = (_a = context.payload.body) === null || _a === void 0 ? void 0 : _a.value;
|
|
122
|
-
if (!notifications || !Array.isArray(notifications)) {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
const validNotifications = notifications.filter((notif) => notif.clientState === clientState);
|
|
126
|
-
if (validNotifications.length === 0) {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
130
|
-
authProvider: {
|
|
131
|
-
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
const changedFilePayloads = [];
|
|
135
|
-
for (const notification of validNotifications) {
|
|
136
|
-
try {
|
|
137
|
-
const changedFile = yield client.api(notification.resource).get();
|
|
138
|
-
if (changedFile.file) {
|
|
139
|
-
changedFilePayloads.push(changedFile);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
console.error('Error fetching file from notification:', error);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return changedFilePayloads;
|
|
147
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
147
148
|
});
|
|
148
149
|
},
|
|
149
150
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-or-updated-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-or-updated-file.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAMwC;AACxC,sCAAsD;AACtD,8EAA2E;
|
|
1
|
+
{"version":3,"file":"new-or-updated-file.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-or-updated-file.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAMwC;AACxC,sCAAsD;AACtD,8EAA2E;AAE3E,+DAAqF;AACrF,0DAA0B;AAQ1B,MAAM,OAAO,GAAyE;IACrF,QAAQ,EAAE,8BAAc,CAAC,SAAS;IAClC,KAAK,EAAE,KAA+C,EAAE,oDAA1C,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE;QACnD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC;QACjD,MAAM,UAAU,GAAG,gBAAgB,KAAK,CAAC,CAAC;QAE1C,MAAM,MAAM,GAAG,+BAAM,CAAC,kBAAkB,CAAC;YACxC,YAAY,EAAE;gBACb,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC;aACxD;SACD,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,MAAM,QAAQ,GACb,QAAQ,KAAK,MAAM;YAClB,CAAC,CAAC,UAAU,MAAM,gBAAgB,QAAQ,WAAW;YACrD,CAAC,CAAC,UAAU,MAAM,WAAW,OAAO,sBAAsB,CAAC;QAE7D,IAAI,QAAQ,GAAmB,MAAM,MAAM;aACzC,GAAG,CAAC,QAAQ,CAAC;aACb,OAAO,CAAC,2BAA2B,CAAC;aACpC,GAAG,EAAE,CAAC;QAER,IAAI,IAAI,GAAG,KAAK,CAAC;QAEjB,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG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,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;aAC9B,CAAC,CAAC;QACJ,CAAC;KAAA;IACK,IAAI,CAAC,OAAO;;YACjB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;IACK,GAAG,CAAC,OAAO;;YAChB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -6,12 +6,65 @@ const __1 = require("../../");
|
|
|
6
6
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
-
const
|
|
9
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
10
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
11
|
+
const polling = {
|
|
12
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
13
|
+
items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
14
|
+
const { siteId, driveId, parentFolderId } = propsValue;
|
|
15
|
+
const isTestMode = lastFetchEpochMS === 0;
|
|
16
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
17
|
+
authProvider: {
|
|
18
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const folders = [];
|
|
22
|
+
const endpoint = parentFolderId !== 'root'
|
|
23
|
+
? `/sites/${siteId}/drive/items/${parentFolderId}/children`
|
|
24
|
+
: `/sites/${siteId}/drives/${driveId}/items/root/children`;
|
|
25
|
+
let response = yield client
|
|
26
|
+
.api(endpoint)
|
|
27
|
+
.orderby('lastModifiedDateTime desc')
|
|
28
|
+
.get();
|
|
29
|
+
let stop = false;
|
|
30
|
+
while (!stop && response.value.length > 0) {
|
|
31
|
+
for (const item of response.value) {
|
|
32
|
+
if (!item.folder)
|
|
33
|
+
continue;
|
|
34
|
+
const modifiedMs = (0, dayjs_1.default)(item.lastModifiedDateTime).valueOf();
|
|
35
|
+
if (isTestMode) {
|
|
36
|
+
folders.push(item);
|
|
37
|
+
if (folders.length >= 10) {
|
|
38
|
+
stop = true;
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (modifiedMs < lastFetchEpochMS) {
|
|
43
|
+
stop = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
folders.push(item);
|
|
47
|
+
}
|
|
48
|
+
if (stop || !response['@odata.nextLink'])
|
|
49
|
+
break;
|
|
50
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
51
|
+
}
|
|
52
|
+
folders.sort((a, b) => {
|
|
53
|
+
const aDate = (0, dayjs_1.default)(a.lastModifiedDateTime);
|
|
54
|
+
const bDate = (0, dayjs_1.default)(b.lastModifiedDateTime);
|
|
55
|
+
return bDate.diff(aDate);
|
|
56
|
+
});
|
|
57
|
+
return folders.map((folder) => ({
|
|
58
|
+
epochMilliSeconds: (0, dayjs_1.default)(folder.lastModifiedDateTime).valueOf(),
|
|
59
|
+
data: folder,
|
|
60
|
+
}));
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
10
63
|
exports.newOrUpdatedFolderTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
64
|
auth: __1.microsoftSharePointAuth,
|
|
12
65
|
name: 'new_or_updated_folder',
|
|
13
66
|
displayName: 'New or Updated Folder',
|
|
14
|
-
description: '
|
|
67
|
+
description: 'Triggers when a folder is created or updated (e.g., name change).',
|
|
15
68
|
props: {
|
|
16
69
|
siteId: common_1.microsoftSharePointCommon.siteId,
|
|
17
70
|
driveId: common_1.microsoftSharePointCommon.driveId,
|
|
@@ -34,11 +87,9 @@ exports.newOrUpdatedFolderTrigger = (0, pieces_framework_1.createTrigger)({
|
|
|
34
87
|
getAccessToken: () => Promise.resolve(authValue.access_token),
|
|
35
88
|
},
|
|
36
89
|
});
|
|
37
|
-
const options = [
|
|
38
|
-
{ label: 'Root Folder', value: 'root' },
|
|
39
|
-
];
|
|
90
|
+
const options = [{ label: 'Root Folder', value: 'root' }];
|
|
40
91
|
let response = yield client
|
|
41
|
-
.api(`/drives/${driveId}/root/children?$filter=folder ne null&$select=id,name`)
|
|
92
|
+
.api(`/sites/${siteId}/drives/${driveId}/items/root/children?$filter=folder ne null&$select=id,name`)
|
|
42
93
|
.get();
|
|
43
94
|
while (response.value.length > 0) {
|
|
44
95
|
for (const item of response.value) {
|
|
@@ -55,95 +106,45 @@ exports.newOrUpdatedFolderTrigger = (0, pieces_framework_1.createTrigger)({
|
|
|
55
106
|
}),
|
|
56
107
|
}),
|
|
57
108
|
},
|
|
58
|
-
type: pieces_framework_1.TriggerStrategy.
|
|
109
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
59
110
|
sampleData: {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
111
|
+
id: '01DRYVE_FOLDER_ID_GOES_HERE',
|
|
112
|
+
name: 'Project Alpha',
|
|
113
|
+
webUrl: 'https://contoso.sharepoint.com/Shared%20Documents/Project%20Alpha',
|
|
114
|
+
size: 0,
|
|
115
|
+
createdDateTime: '2025-09-26T14:50:00Z',
|
|
116
|
+
lastModifiedDateTime: '2025-09-26T14:50:00Z',
|
|
117
|
+
folder: {
|
|
118
|
+
childCount: 0,
|
|
68
119
|
},
|
|
69
|
-
|
|
120
|
+
parentReference: { id: 'PARENT_FOLDER_ID_HERE' },
|
|
70
121
|
},
|
|
71
122
|
onEnable(context) {
|
|
72
123
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
124
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
125
|
+
auth: context.auth,
|
|
126
|
+
store: context.store,
|
|
127
|
+
propsValue: context.propsValue,
|
|
78
128
|
});
|
|
79
|
-
try {
|
|
80
|
-
const effectiveParentId = parentFolderId === 'root'
|
|
81
|
-
? (yield client.api(`/drives/${driveId}/root`).get()).id
|
|
82
|
-
: parentFolderId;
|
|
83
|
-
const expirationDateTime = new Date();
|
|
84
|
-
expirationDateTime.setDate(expirationDateTime.getDate() + 2);
|
|
85
|
-
const subscription = yield client.api('/subscriptions').post({
|
|
86
|
-
changeType: 'created,updated',
|
|
87
|
-
notificationUrl: context.webhookUrl,
|
|
88
|
-
resource: `/sites/${siteId}/drive/items/${effectiveParentId}/children`,
|
|
89
|
-
expirationDateTime: expirationDateTime.toISOString(),
|
|
90
|
-
clientState: clientState,
|
|
91
|
-
});
|
|
92
|
-
yield context.store.put('subscriptionId', subscription.id);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
throw new Error(`Failed to create subscription: ${error.message || 'Unknown error'}`);
|
|
96
|
-
}
|
|
97
129
|
});
|
|
98
130
|
},
|
|
99
131
|
onDisable(context) {
|
|
100
132
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.warn(`Error deleting subscription ${subscriptionId}:`, error);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
yield context.store.delete('subscriptionId');
|
|
133
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
134
|
+
auth: context.auth,
|
|
135
|
+
store: context.store,
|
|
136
|
+
propsValue: context.propsValue,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
test(context) {
|
|
141
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
116
143
|
});
|
|
117
144
|
},
|
|
118
145
|
run(context) {
|
|
119
146
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
|
|
121
|
-
const notifications = (_a = context.payload.body) === null || _a === void 0 ? void 0 : _a.value;
|
|
122
|
-
if (!notifications || !Array.isArray(notifications)) {
|
|
123
|
-
return [];
|
|
124
|
-
}
|
|
125
|
-
const validNotifications = notifications.filter((notif) => notif.clientState === clientState);
|
|
126
|
-
if (validNotifications.length === 0) {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
130
|
-
authProvider: {
|
|
131
|
-
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
const folderPayloads = [];
|
|
135
|
-
for (const notification of validNotifications) {
|
|
136
|
-
try {
|
|
137
|
-
const changedItem = yield client.api(notification.resource).get();
|
|
138
|
-
if (changedItem.folder) {
|
|
139
|
-
folderPayloads.push(changedItem);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
console.error('Error fetching folder from notification:', error);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return folderPayloads;
|
|
147
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
147
148
|
});
|
|
148
149
|
},
|
|
149
150
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-or-updated-folder.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-or-updated-folder.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAMwC;AACxC,sCAAsD;AACtD,8EAA2E;
|
|
1
|
+
{"version":3,"file":"new-or-updated-folder.js","sourceRoot":"","sources":["../../../../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KAAA;IACK,GAAG,CAAC,OAAO;;YAChB,OAAO,MAAM,6BAAa,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -6,95 +6,97 @@ const __1 = require("../../");
|
|
|
6
6
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
7
|
const common_1 = require("../common");
|
|
8
8
|
const microsoft_graph_client_1 = require("@microsoft/microsoft-graph-client");
|
|
9
|
-
const
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
11
|
+
const polling = {
|
|
12
|
+
strategy: pieces_common_1.DedupeStrategy.TIMEBASED,
|
|
13
|
+
items: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue, lastFetchEpochMS }) {
|
|
14
|
+
const { siteId } = propsValue;
|
|
15
|
+
const isTestMode = lastFetchEpochMS === 0;
|
|
16
|
+
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
17
|
+
authProvider: {
|
|
18
|
+
getAccessToken: () => Promise.resolve(auth.access_token),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const lists = [];
|
|
22
|
+
let response = yield client
|
|
23
|
+
.api(`/sites/${siteId}/lists`)
|
|
24
|
+
.get();
|
|
25
|
+
let stop = false;
|
|
26
|
+
while (!stop && response.value.length > 0) {
|
|
27
|
+
for (const item of response.value) {
|
|
28
|
+
const modifiedMs = (0, dayjs_1.default)(item.lastModifiedDateTime).valueOf();
|
|
29
|
+
if (isTestMode) {
|
|
30
|
+
lists.push(item);
|
|
31
|
+
if (lists.length >= 10) {
|
|
32
|
+
stop = true;
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (modifiedMs < lastFetchEpochMS) {
|
|
37
|
+
stop = true;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
lists.push(item);
|
|
41
|
+
}
|
|
42
|
+
if (stop || !response['@odata.nextLink'])
|
|
43
|
+
break;
|
|
44
|
+
response = yield client.api(response['@odata.nextLink']).get();
|
|
45
|
+
}
|
|
46
|
+
lists.sort((a, b) => {
|
|
47
|
+
const aDate = (0, dayjs_1.default)(a.lastModifiedDateTime);
|
|
48
|
+
const bDate = (0, dayjs_1.default)(b.lastModifiedDateTime);
|
|
49
|
+
return bDate.diff(aDate);
|
|
50
|
+
});
|
|
51
|
+
return lists.map((list) => ({
|
|
52
|
+
epochMilliSeconds: (0, dayjs_1.default)(list.lastModifiedDateTime).valueOf(),
|
|
53
|
+
data: list,
|
|
54
|
+
}));
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
10
57
|
exports.newOrUpdatedListTrigger = (0, pieces_framework_1.createTrigger)({
|
|
11
58
|
auth: __1.microsoftSharePointAuth,
|
|
12
59
|
name: 'new_or_updated_list',
|
|
13
60
|
displayName: 'New or Updated List',
|
|
14
|
-
description: '
|
|
61
|
+
description: 'Triggers when a list is created or updated in a site.',
|
|
15
62
|
props: {
|
|
16
63
|
siteId: common_1.microsoftSharePointCommon.siteId,
|
|
17
64
|
},
|
|
18
|
-
type: pieces_framework_1.TriggerStrategy.
|
|
65
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
19
66
|
sampleData: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
67
|
+
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
|
68
|
+
displayName: 'Projects Tracker',
|
|
69
|
+
description: 'Updated list for tracking all ongoing projects.',
|
|
70
|
+
createdDateTime: '2025-09-26T11:00:00Z',
|
|
71
|
+
lastModifiedDateTime: '2025-09-26T14:55:00Z',
|
|
72
|
+
webUrl: 'https://contoso.sharepoint.com/sites/MySite/Lists/Projects%20Tracker',
|
|
26
73
|
},
|
|
27
74
|
onEnable(context) {
|
|
28
75
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
76
|
+
yield pieces_common_1.pollingHelper.onEnable(polling, {
|
|
77
|
+
auth: context.auth,
|
|
78
|
+
store: context.store,
|
|
79
|
+
propsValue: context.propsValue,
|
|
34
80
|
});
|
|
35
|
-
try {
|
|
36
|
-
const expirationDateTime = new Date();
|
|
37
|
-
expirationDateTime.setDate(expirationDateTime.getDate() + 2);
|
|
38
|
-
const subscription = yield client.api('/subscriptions').post({
|
|
39
|
-
changeType: 'created,updated',
|
|
40
|
-
notificationUrl: context.webhookUrl,
|
|
41
|
-
resource: `/sites/${siteId}/lists`,
|
|
42
|
-
expirationDateTime: expirationDateTime.toISOString(),
|
|
43
|
-
clientState: clientState,
|
|
44
|
-
});
|
|
45
|
-
yield context.store.put('subscriptionId', subscription.id);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new Error(`Failed to create subscription: ${error.message || 'Unknown error'}`);
|
|
49
|
-
}
|
|
50
81
|
});
|
|
51
82
|
},
|
|
52
83
|
onDisable(context) {
|
|
53
84
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
catch (error) {
|
|
65
|
-
console.warn(`Error deleting subscription ${subscriptionId}:`, error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
yield context.store.delete('subscriptionId');
|
|
85
|
+
yield pieces_common_1.pollingHelper.onDisable(polling, {
|
|
86
|
+
auth: context.auth,
|
|
87
|
+
store: context.store,
|
|
88
|
+
propsValue: context.propsValue,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
test(context) {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
return yield pieces_common_1.pollingHelper.test(polling, context);
|
|
69
95
|
});
|
|
70
96
|
},
|
|
71
97
|
run(context) {
|
|
72
98
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
const notifications = (_a = context.payload.body) === null || _a === void 0 ? void 0 : _a.value;
|
|
75
|
-
if (!notifications || !Array.isArray(notifications)) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const validNotifications = notifications.filter((notif) => notif.clientState === clientState);
|
|
79
|
-
if (validNotifications.length === 0) {
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
const client = microsoft_graph_client_1.Client.initWithMiddleware({
|
|
83
|
-
authProvider: {
|
|
84
|
-
getAccessToken: () => Promise.resolve(context.auth.access_token),
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
const listPayloads = [];
|
|
88
|
-
for (const notification of validNotifications) {
|
|
89
|
-
try {
|
|
90
|
-
const changedList = yield client.api(notification.resource).get();
|
|
91
|
-
listPayloads.push(changedList);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error('Error fetching list from notification:', error);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return listPayloads;
|
|
99
|
+
return yield pieces_common_1.pollingHelper.poll(polling, context);
|
|
98
100
|
});
|
|
99
101
|
},
|
|
100
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new-or-updated-list.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-or-updated-list.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC;AACxC,sCAAsD;AACtD,
|
|
1
|
+
{"version":3,"file":"new-or-updated-list.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/microsoft-sharepoint/src/lib/triggers/new-or-updated-list.ts"],"names":[],"mappings":";;;;AAAA,8BAAiD;AACjD,qEAIwC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