@slates-integrations/sharepoint 0.2.0-rc.6
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/README.md +65 -0
- package/docs/SPEC.md +98 -0
- package/logo.svg +1 -0
- package/package.json +20 -0
- package/slate.json +19 -0
- package/src/auth.ts +69 -0
- package/src/config.ts +4 -0
- package/src/index.ts +36 -0
- package/src/lib/client.ts +562 -0
- package/src/spec.ts +13 -0
- package/src/tools/errors.ts +16 -0
- package/src/tools/get-content-types.ts +109 -0
- package/src/tools/get-drive.ts +96 -0
- package/src/tools/get-file-versions.ts +53 -0
- package/src/tools/get-site.ts +79 -0
- package/src/tools/index.ts +12 -0
- package/src/tools/list-sites.ts +76 -0
- package/src/tools/manage-columns.ts +159 -0
- package/src/tools/manage-file.ts +262 -0
- package/src/tools/manage-list-items.ts +203 -0
- package/src/tools/manage-list.ts +133 -0
- package/src/tools/manage-permissions.ts +195 -0
- package/src/tools/search-drive.ts +61 -0
- package/src/tools/search.ts +132 -0
- package/src/triggers/drive-item-changes.ts +202 -0
- package/src/triggers/inbound-webhook.ts +67 -0
- package/src/triggers/index.ts +3 -0
- package/src/triggers/list-item-changes.ts +176 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { SlateTrigger, SlateDefaultPollingIntervalSeconds } from 'slates';
|
|
2
|
+
import { SharePointClient } from '../lib/client';
|
|
3
|
+
import { spec } from '../spec';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
export let listItemChanges = SlateTrigger.create(spec, {
|
|
7
|
+
name: 'List Item Changes',
|
|
8
|
+
key: 'list_item_changes',
|
|
9
|
+
description:
|
|
10
|
+
'Triggers when list items are created, updated, or deleted in a SharePoint list. Polls the list items delta API to detect changes.'
|
|
11
|
+
})
|
|
12
|
+
.input(
|
|
13
|
+
z.object({
|
|
14
|
+
siteId: z.string().describe('SharePoint site ID to monitor'),
|
|
15
|
+
listId: z.string().describe('SharePoint list ID to monitor'),
|
|
16
|
+
changeType: z
|
|
17
|
+
.enum(['created', 'updated', 'deleted'])
|
|
18
|
+
.describe('Type of change detected'),
|
|
19
|
+
itemId: z.string().describe('ID of the changed list item'),
|
|
20
|
+
fields: z
|
|
21
|
+
.record(z.string(), z.any())
|
|
22
|
+
.optional()
|
|
23
|
+
.describe('Current field values of the item (not present for deletions)'),
|
|
24
|
+
lastModifiedDateTime: z.string().optional().describe('When the item was last modified'),
|
|
25
|
+
lastModifiedBy: z.string().optional().describe('User who last modified the item')
|
|
26
|
+
})
|
|
27
|
+
)
|
|
28
|
+
.output(
|
|
29
|
+
z.object({
|
|
30
|
+
siteId: z.string().describe('SharePoint site ID'),
|
|
31
|
+
listId: z.string().describe('SharePoint list ID'),
|
|
32
|
+
itemId: z.string().describe('ID of the changed list item'),
|
|
33
|
+
changeType: z.enum(['created', 'updated', 'deleted']).describe('Type of change'),
|
|
34
|
+
fields: z
|
|
35
|
+
.record(z.string(), z.any())
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('Current field values (not present for deletions)'),
|
|
38
|
+
lastModifiedDateTime: z.string().optional().describe('When the item was last modified'),
|
|
39
|
+
lastModifiedBy: z.string().optional().describe('User who last modified the item'),
|
|
40
|
+
webUrl: z.string().optional().describe('URL of the list item')
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
.polling({
|
|
44
|
+
options: {
|
|
45
|
+
intervalInSeconds: SlateDefaultPollingIntervalSeconds
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
pollEvents: async ctx => {
|
|
49
|
+
let client = new SharePointClient(ctx.auth.token);
|
|
50
|
+
let state = ctx.state as {
|
|
51
|
+
deltaToken?: string;
|
|
52
|
+
knownItems?: Record<string, string>;
|
|
53
|
+
siteId?: string;
|
|
54
|
+
listId?: string;
|
|
55
|
+
initialized?: boolean;
|
|
56
|
+
} | null;
|
|
57
|
+
|
|
58
|
+
let siteId = state?.siteId;
|
|
59
|
+
let listId = state?.listId;
|
|
60
|
+
|
|
61
|
+
if (!siteId || !listId) {
|
|
62
|
+
return {
|
|
63
|
+
inputs: [],
|
|
64
|
+
updatedState: {
|
|
65
|
+
...state,
|
|
66
|
+
initialized: false
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let deltaToken = state?.deltaToken;
|
|
72
|
+
let knownItems = state?.knownItems || {};
|
|
73
|
+
|
|
74
|
+
let data = await client.getListItemsDelta(siteId, listId, deltaToken);
|
|
75
|
+
let items = data.value || [];
|
|
76
|
+
let newDeltaToken = data['@odata.deltaLink'];
|
|
77
|
+
|
|
78
|
+
if (!state?.initialized) {
|
|
79
|
+
let updatedKnown: Record<string, string> = {};
|
|
80
|
+
for (let item of items) {
|
|
81
|
+
let isDeleted = item.deleted !== undefined || item['@removed'] !== undefined;
|
|
82
|
+
if (!isDeleted) {
|
|
83
|
+
updatedKnown[item.id] = item.lastModifiedDateTime || '';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
inputs: [],
|
|
88
|
+
updatedState: {
|
|
89
|
+
siteId,
|
|
90
|
+
listId,
|
|
91
|
+
deltaToken: newDeltaToken,
|
|
92
|
+
knownItems: updatedKnown,
|
|
93
|
+
initialized: true
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let inputs: Array<{
|
|
99
|
+
siteId: string;
|
|
100
|
+
listId: string;
|
|
101
|
+
changeType: 'created' | 'updated' | 'deleted';
|
|
102
|
+
itemId: string;
|
|
103
|
+
fields?: Record<string, any>;
|
|
104
|
+
lastModifiedDateTime?: string;
|
|
105
|
+
lastModifiedBy?: string;
|
|
106
|
+
}> = [];
|
|
107
|
+
|
|
108
|
+
let updatedKnown = { ...knownItems };
|
|
109
|
+
|
|
110
|
+
for (let item of items) {
|
|
111
|
+
let isDeleted = item.deleted !== undefined || item['@removed'] !== undefined;
|
|
112
|
+
|
|
113
|
+
if (isDeleted) {
|
|
114
|
+
if (knownItems[item.id]) {
|
|
115
|
+
inputs.push({
|
|
116
|
+
siteId,
|
|
117
|
+
listId,
|
|
118
|
+
changeType: 'deleted',
|
|
119
|
+
itemId: item.id
|
|
120
|
+
});
|
|
121
|
+
delete updatedKnown[item.id];
|
|
122
|
+
}
|
|
123
|
+
} else if (!knownItems[item.id]) {
|
|
124
|
+
inputs.push({
|
|
125
|
+
siteId,
|
|
126
|
+
listId,
|
|
127
|
+
changeType: 'created',
|
|
128
|
+
itemId: item.id,
|
|
129
|
+
fields: item.fields,
|
|
130
|
+
lastModifiedDateTime: item.lastModifiedDateTime,
|
|
131
|
+
lastModifiedBy: item.lastModifiedBy?.user?.displayName
|
|
132
|
+
});
|
|
133
|
+
updatedKnown[item.id] = item.lastModifiedDateTime || '';
|
|
134
|
+
} else {
|
|
135
|
+
inputs.push({
|
|
136
|
+
siteId,
|
|
137
|
+
listId,
|
|
138
|
+
changeType: 'updated',
|
|
139
|
+
itemId: item.id,
|
|
140
|
+
fields: item.fields,
|
|
141
|
+
lastModifiedDateTime: item.lastModifiedDateTime,
|
|
142
|
+
lastModifiedBy: item.lastModifiedBy?.user?.displayName
|
|
143
|
+
});
|
|
144
|
+
updatedKnown[item.id] = item.lastModifiedDateTime || '';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
inputs,
|
|
150
|
+
updatedState: {
|
|
151
|
+
siteId,
|
|
152
|
+
listId,
|
|
153
|
+
deltaToken: newDeltaToken,
|
|
154
|
+
knownItems: updatedKnown,
|
|
155
|
+
initialized: true
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
handleEvent: async ctx => {
|
|
161
|
+
return {
|
|
162
|
+
type: `list_item.${ctx.input.changeType}`,
|
|
163
|
+
id: `${ctx.input.listId}_${ctx.input.itemId}_${ctx.input.lastModifiedDateTime || Date.now()}`,
|
|
164
|
+
output: {
|
|
165
|
+
siteId: ctx.input.siteId,
|
|
166
|
+
listId: ctx.input.listId,
|
|
167
|
+
itemId: ctx.input.itemId,
|
|
168
|
+
changeType: ctx.input.changeType,
|
|
169
|
+
fields: ctx.input.fields,
|
|
170
|
+
lastModifiedDateTime: ctx.input.lastModifiedDateTime,
|
|
171
|
+
lastModifiedBy: ctx.input.lastModifiedBy
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
.build();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"types": ["node"],
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noUncheckedIndexedAccess": true,
|
|
17
|
+
"noImplicitOverride": true,
|
|
18
|
+
"noUnusedLocals": false,
|
|
19
|
+
"noUnusedParameters": false,
|
|
20
|
+
"noPropertyAccessFromIndexSignature": false
|
|
21
|
+
},
|
|
22
|
+
"include": ["src"]
|
|
23
|
+
}
|