@pipedream/microsoft_outlook 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Pipedream, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-create-calendar-event",
6
+ version: "0.0.1",
7
+ name: "Create Calendar Event",
8
+ description: "Create an event in the user's default calendar, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-events)",
9
+ props: {
10
+ microsoftOutlook,
11
+ subject: {
12
+ label: "Subject",
13
+ description: "Subject of the event",
14
+ type: "string",
15
+ },
16
+ contentType: {
17
+ propDefinition: [
18
+ microsoftOutlook,
19
+ "contentType",
20
+ ],
21
+ },
22
+ content: {
23
+ propDefinition: [
24
+ microsoftOutlook,
25
+ "content",
26
+ ],
27
+ description: "Content",
28
+ },
29
+ timeZone: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "timeZone",
33
+ ],
34
+ },
35
+ start: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "start",
39
+ ],
40
+ },
41
+ end: {
42
+ propDefinition: [
43
+ microsoftOutlook,
44
+ "end",
45
+ ],
46
+ },
47
+ attendees: {
48
+ propDefinition: [
49
+ microsoftOutlook,
50
+ "attendees",
51
+ ],
52
+ },
53
+ location: {
54
+ propDefinition: [
55
+ microsoftOutlook,
56
+ "location",
57
+ ],
58
+ },
59
+ isOnlineMeeting: {
60
+ propDefinition: [
61
+ microsoftOutlook,
62
+ "isOnlineMeeting",
63
+ ],
64
+ },
65
+ expand: {
66
+ propDefinition: [
67
+ microsoftOutlook,
68
+ "expand",
69
+ ],
70
+ description: "Additional event details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/event)",
71
+ },
72
+ },
73
+ async run({ $ }) {
74
+ //RegExp to check time strings(yyyy-MM-ddThh:mm:ss)
75
+ const re = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/;
76
+ if (!re.test(this.start) || !re.test(this.start)) {
77
+ throw new Error("Please provide both start and end props in 'yyyy-MM-ddThh:mm:ss'");
78
+ }
79
+ const data = {
80
+ subject: this.subject,
81
+ body: {
82
+ contentType: this.contentType ?? "HTML",
83
+ content: this.content,
84
+ },
85
+ start: {
86
+ dateTime: this.start,
87
+ timeZone: this.timeZone,
88
+ },
89
+ end: {
90
+ dateTime: this.end,
91
+ timeZone: this.timeZone,
92
+ },
93
+ location: {
94
+ displayName: this.location,
95
+ },
96
+ attendees: this.attendees.map((at) => ({
97
+ emailAddress: {
98
+ address: at,
99
+ },
100
+ })),
101
+ isOnlineMeeting: this.isOnlineMeeting,
102
+ ...this.expand,
103
+ };
104
+ const response = await this.microsoftOutlook.createCalendarEvent({
105
+ $,
106
+ data,
107
+ });
108
+ $.export("$summary", "Calendar event has been created.");
109
+ return response;
110
+ },
111
+ };
@@ -0,0 +1,60 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-create-contact",
6
+ version: "0.0.1",
7
+ name: "Create Contact",
8
+ description: "Add a contact to the root Contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
9
+ props: {
10
+ microsoftOutlook,
11
+ givenName: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "givenName",
15
+ ],
16
+ },
17
+ surname: {
18
+ propDefinition: [
19
+ microsoftOutlook,
20
+ "surname",
21
+ ],
22
+ },
23
+ emailAddresses: {
24
+ propDefinition: [
25
+ microsoftOutlook,
26
+ "emailAddresses",
27
+ ],
28
+ },
29
+ businessPhones: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "businessPhones",
33
+ ],
34
+ },
35
+ expand: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "expand",
39
+ ],
40
+ description: "Additional contact details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/contact)",
41
+ },
42
+ },
43
+ async run({ $ }) {
44
+ const response = await this.microsoftOutlook.createContact({
45
+ $,
46
+ data: {
47
+ givenName: this.givenName,
48
+ surname: this.surname,
49
+ emailAddresses: this.emailAddresses.map((a, i) => ({
50
+ address: a,
51
+ name: `Email #${i + 1}`,
52
+ })),
53
+ businessPhones: this.businessPhones,
54
+ ...this.expand,
55
+ },
56
+ });
57
+ $.export("$summary", "Contact has been created.");
58
+ return response;
59
+ },
60
+ };
@@ -0,0 +1,54 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-create-draft-email",
6
+ version: "0.0.1",
7
+ name: "Create Draft Email",
8
+ description: "Create a draft email, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-messages)",
9
+ props: {
10
+ microsoftOutlook,
11
+ recipients: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "recipients",
15
+ ],
16
+ },
17
+ subject: {
18
+ propDefinition: [
19
+ microsoftOutlook,
20
+ "subject",
21
+ ],
22
+ },
23
+ content: {
24
+ propDefinition: [
25
+ microsoftOutlook,
26
+ "content",
27
+ ],
28
+ },
29
+ files: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "files",
33
+ ],
34
+ },
35
+ expand: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "expand",
39
+ ],
40
+ description: "Additional email details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/message)",
41
+ },
42
+ },
43
+ async run({ $ }) {
44
+ const response = await this.microsoftOutlook.createDraft({
45
+ $,
46
+ data: {
47
+ ...this.microsoftOutlook.prepareMessageBody(this),
48
+ ...this.expand,
49
+ },
50
+ });
51
+ $.export("$summary", "Email draft has been created.");
52
+ return response;
53
+ },
54
+ };
@@ -0,0 +1,33 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-find-contacts",
6
+ version: "0.0.1",
7
+ name: "Find Contacts",
8
+ description: "Finds contacts with given search string",
9
+ props: {
10
+ microsoftOutlook,
11
+ searchString: {
12
+ label: "Search string",
13
+ description: "Provide email address, given name, surname or display name (case sensitive)",
14
+ type: "string",
15
+ },
16
+ },
17
+ async run({ $ }) {
18
+ const contactList = await this.microsoftOutlook.listContacts({
19
+ $,
20
+ });
21
+ const relatedContacts = contactList.value.filter((c) => {
22
+ return c.displayName.includes(this.searchString) ||
23
+ c.givenName.includes(this.searchString) ||
24
+ c.surname.includes(this.searchString) ||
25
+ c.emailAddresses.find((e) =>
26
+ e.address == this.searchString ||
27
+ e.name.includes(this.searchString));
28
+ });
29
+ // eslint-disable-next-line multiline-ternary
30
+ $.export("$summary", `${relatedContacts.length} contact${relatedContacts.length != 1 ? "s" : ""} has been filtered.`);
31
+ return relatedContacts;
32
+ },
33
+ };
@@ -0,0 +1,27 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-list-contacts",
6
+ version: "0.0.1",
7
+ name: "List Contacts",
8
+ description: "Get a contact collection from the default contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
9
+ props: {
10
+ microsoftOutlook,
11
+ filterAddress: {
12
+ label: "Email adress",
13
+ description: "If this is given, only contacts with the given address will be retrieved.",
14
+ type: "string",
15
+ optional: true,
16
+ },
17
+ },
18
+ async run({ $ }) {
19
+ const response = await this.microsoftOutlook.listContacts({
20
+ $,
21
+ filterAddress: this.filterAddress,
22
+ });
23
+ // eslint-disable-next-line multiline-ternary
24
+ $.export("$summary", `${response.value.length} contact${response.value.length != 1 ? "s" : ""} has been retrieved.`);
25
+ return response.value;
26
+ },
27
+ };
@@ -0,0 +1,61 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-send-email",
6
+ version: "0.0.2",
7
+ name: "Send Email",
8
+ description: "Send an email to one or multiple recipients, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-sendmail)",
9
+ props: {
10
+ microsoftOutlook,
11
+ recipients: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "recipients",
15
+ ],
16
+ },
17
+ subject: {
18
+ propDefinition: [
19
+ microsoftOutlook,
20
+ "subject",
21
+ ],
22
+ },
23
+ contentType: {
24
+ propDefinition: [
25
+ microsoftOutlook,
26
+ "contentType",
27
+ ],
28
+ },
29
+ content: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "content",
33
+ ],
34
+ },
35
+ files: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "files",
39
+ ],
40
+ },
41
+ expand: {
42
+ propDefinition: [
43
+ microsoftOutlook,
44
+ "expand",
45
+ ],
46
+ description: "Additional email details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/message)",
47
+ },
48
+ },
49
+ async run({ $ }) {
50
+ await this.microsoftOutlook.sendEmail({
51
+ $,
52
+ data: {
53
+ message: {
54
+ ...this.microsoftOutlook.prepareMessageBody(this),
55
+ ...this.expand,
56
+ },
57
+ },
58
+ });
59
+ $.export("$summary", "Email has been sent.");
60
+ },
61
+ };
@@ -0,0 +1,70 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook-update-contact",
6
+ version: "0.0.1",
7
+ name: "Update Contact",
8
+ description: "Add a contact to the root Contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
9
+ props: {
10
+ microsoftOutlook,
11
+ contact: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "contact",
15
+ ],
16
+ },
17
+ givenName: {
18
+ propDefinition: [
19
+ microsoftOutlook,
20
+ "givenName",
21
+ ],
22
+ },
23
+ surname: {
24
+ propDefinition: [
25
+ microsoftOutlook,
26
+ "surname",
27
+ ],
28
+ },
29
+ emailAddresses: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "emailAddresses",
33
+ ],
34
+ },
35
+ businessPhones: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "businessPhones",
39
+ ],
40
+ },
41
+ expand: {
42
+ propDefinition: [
43
+ microsoftOutlook,
44
+ "expand",
45
+ ],
46
+ description: "Additional contact details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/contact)",
47
+ },
48
+ },
49
+ async run({ $ }) {
50
+ const emailAddresses = this.emailAddresses && this.emailAddresses.length ?
51
+ this.emailAddresses.map((a, i) => ({
52
+ address: a,
53
+ name: `Email #${i + 1}`,
54
+ })) :
55
+ undefined;
56
+ const response = await this.microsoftOutlook.updateContact({
57
+ $,
58
+ contactId: this.contact,
59
+ data: {
60
+ givenName: this.givenName,
61
+ surname: this.surname,
62
+ emailAddresses,
63
+ businessPhones: this.businessPhones,
64
+ ...this.expand,
65
+ },
66
+ });
67
+ $.export("$summary", "Contact has been updated.");
68
+ return response;
69
+ },
70
+ };
@@ -0,0 +1,298 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { encode } from "js-base64";
5
+ import mime from "mime-types";
6
+
7
+ export default {
8
+ type: "app",
9
+ app: "microsoft_outlook",
10
+ propDefinitions: {
11
+ recipients: {
12
+ label: "Recipients",
13
+ description: "Array of email addresses",
14
+ type: "string[]",
15
+ },
16
+ subject: {
17
+ label: "Subject",
18
+ description: "Subject of the email",
19
+ type: "string",
20
+ },
21
+ contentType: {
22
+ label: "Content Type",
23
+ description: "Content type (default `HTML`)",
24
+ type: "string",
25
+ optional: true,
26
+ },
27
+ content: {
28
+ label: "Content",
29
+ description: "Content of the email in text format",
30
+ type: "string",
31
+ optional: true,
32
+ },
33
+ files: {
34
+ label: "File paths",
35
+ description: "Absolute paths to the files (eg. `/tmp/my_file.pdf`)",
36
+ type: "string[]",
37
+ optional: true,
38
+ },
39
+ timeZone: {
40
+ label: "Time Zone",
41
+ description: "Time zone of the event in supported time zones, [See the docs](https://docs.microsoft.com/en-us/graph/api/outlookuser-supportedtimezones)",
42
+ type: "string",
43
+ async options() {
44
+ const timeZonesResponse = await this.getSupportedTimeZones();
45
+ return timeZonesResponse.value.map((tz) => ({
46
+ label: tz.displayName,
47
+ value: tz.alias,
48
+ }));
49
+ },
50
+ },
51
+ contact: {
52
+ label: "Contact",
53
+ description: "The contact to be updated",
54
+ type: "string",
55
+ async options() {
56
+ const contactResponse = await this.listContacts();
57
+ return contactResponse.value.map((co) => ({
58
+ label: co.displayName,
59
+ value: co.id,
60
+ }));
61
+ },
62
+ },
63
+ start: {
64
+ label: "Start",
65
+ description: "Start date-time (yyyy-MM-ddThh:mm:ss) e.g. '2022-04-15T11:20:00'",
66
+ type: "string",
67
+ },
68
+ end: {
69
+ label: "End",
70
+ description: "Start date-time (yyyy-MM-ddThh:mm:ss) e.g. '2022-04-15T13:30:00'",
71
+ type: "string",
72
+ },
73
+ givenName: {
74
+ label: "Given name",
75
+ description: "Given name of the contact",
76
+ type: "string",
77
+ optional: true,
78
+ },
79
+ surname: {
80
+ label: "Surname",
81
+ description: "Surname of the contact",
82
+ type: "string",
83
+ optional: true,
84
+ },
85
+ emailAddresses: {
86
+ label: "Email adresses",
87
+ description: "Email addresses",
88
+ type: "string[]",
89
+ optional: true,
90
+ },
91
+ businessPhones: {
92
+ label: "Recipients",
93
+ description: "Array of phone numbers",
94
+ type: "string[]",
95
+ optional: true,
96
+ },
97
+ attendees: {
98
+ label: "Attendees",
99
+ description: "Array of email addresses",
100
+ type: "string[]",
101
+ },
102
+ location: {
103
+ label: "Location",
104
+ description: "Location of the event",
105
+ type: "string",
106
+ optional: true,
107
+ },
108
+ isOnlineMeeting: {
109
+ label: "Is Online Meeting",
110
+ description: "If it is online meeting or not",
111
+ type: "boolean",
112
+ optional: true,
113
+ },
114
+ expand: {
115
+ label: "Expand",
116
+ description: "Additional properties",
117
+ type: "object",
118
+ optional: true,
119
+ },
120
+ },
121
+ methods: {
122
+ _getUrl(path) {
123
+ return `https://graph.microsoft.com/v1.0${path}`;
124
+ },
125
+ _getHeaders() {
126
+ return {
127
+ "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
128
+ "accept": "application/json",
129
+ "Content-Type": "application/json",
130
+ };
131
+ },
132
+ async _makeRequest({
133
+ $,
134
+ path,
135
+ headers,
136
+ ...otherConfig
137
+ } = {}) {
138
+ const config = {
139
+ url: this._getUrl(path),
140
+ headers: this._getHeaders(headers),
141
+ ...otherConfig,
142
+ };
143
+ return axios($ ?? this, config);
144
+ },
145
+ async createHook({ ...args } = {}) {
146
+ const response = await this._makeRequest({
147
+ method: "POST",
148
+ path: "/subscriptions",
149
+ ...args,
150
+ });
151
+ return response;
152
+ },
153
+ async renewHook({
154
+ hookId,
155
+ ...args
156
+ } = {}) {
157
+ return await this._makeRequest({
158
+ method: "PATCH",
159
+ path: `/subscriptions/${hookId}`,
160
+ ...args,
161
+ });
162
+ },
163
+ async deleteHook({
164
+ hookId,
165
+ ...args
166
+ } = {}) {
167
+ return await this._makeRequest({
168
+ method: "DELETE",
169
+ path: `/subscriptions/${hookId}`,
170
+ ...args,
171
+ });
172
+ },
173
+ prepareMessageBody(self) {
174
+ const toRecipients = [];
175
+ for (const address of self.recipients) {
176
+ toRecipients.push({
177
+ emailAddress: {
178
+ address,
179
+ },
180
+ });
181
+ }
182
+ const attachments = [];
183
+ for (let i = 0; self.files && i < self.files.length; i++) {
184
+ attachments.push({
185
+ "@odata.type": "#microsoft.graph.fileAttachment",
186
+ "name": path.basename(self.files[i]),
187
+ "contentType": mime.lookup(self.files[i]),
188
+ "contentBytes": encode([
189
+ ...fs.readFileSync(self.files[i], {
190
+ flag: "r",
191
+ }).values(),
192
+ ]),
193
+ });
194
+ }
195
+ const message = {
196
+ subject: self.subject,
197
+ body: {
198
+ content: self.content,
199
+ contentType: self.contentType ?? "HTML",
200
+ },
201
+ toRecipients,
202
+ attachments,
203
+ };
204
+ return message;
205
+ },
206
+ async getSupportedTimeZones() {
207
+ return await this._makeRequest({
208
+ method: "GET",
209
+ path: "/me/outlook/supportedTimeZones",
210
+ });
211
+ },
212
+ async createCalendarEvent({ ...args } = {}) {
213
+ return await this._makeRequest({
214
+ method: "POST",
215
+ path: "/me/events",
216
+ ...args,
217
+ });
218
+ },
219
+ async sendEmail({ ...args } = {}) {
220
+ return await this._makeRequest({
221
+ method: "POST",
222
+ path: "/me/sendMail",
223
+ ...args,
224
+ });
225
+ },
226
+ async createDraft({ ...args } = {}) {
227
+ return await this._makeRequest({
228
+ method: "POST",
229
+ path: "/me/messages",
230
+ ...args,
231
+ });
232
+ },
233
+ async createContact({ ...args } = {}) {
234
+ return await this._makeRequest({
235
+ method: "POST",
236
+ path: "/me/contacts",
237
+ ...args,
238
+ });
239
+ },
240
+ async listContacts({
241
+ filterAddress,
242
+ ...args
243
+ } = {}) {
244
+ const paramsContainer = {};
245
+ if (filterAddress) {
246
+ paramsContainer.params = {
247
+ "$filter": `emailAddresses/any(a:a/address eq '${filterAddress}')`,
248
+ };
249
+ }
250
+ return await this._makeRequest({
251
+ method: "GET",
252
+ path: "/me/contacts",
253
+ ...paramsContainer,
254
+ ...args,
255
+ });
256
+ },
257
+ async updateContact({
258
+ contactId,
259
+ ...args
260
+ } = {}) {
261
+ return await this._makeRequest({
262
+ method: "PATCH",
263
+ path: `/me/contacts/${contactId}`,
264
+ ...args,
265
+ });
266
+ },
267
+ async getMessage({
268
+ messageId,
269
+ ...args
270
+ } = {}) {
271
+ return await this._makeRequest({
272
+ method: "GET",
273
+ path: `/me/messages/${messageId}`,
274
+ ...args,
275
+ });
276
+ },
277
+ async getCalendarEvent({
278
+ eventId,
279
+ ...args
280
+ } = {}) {
281
+ return await this._makeRequest({
282
+ method: "GET",
283
+ path: `/me/events/${eventId}`,
284
+ ...args,
285
+ });
286
+ },
287
+ async getContact({
288
+ contactId,
289
+ ...args
290
+ } = {}) {
291
+ return await this._makeRequest({
292
+ method: "GET",
293
+ path: `/me/contacts/${contactId}`,
294
+ ...args,
295
+ });
296
+ },
297
+ },
298
+ };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@pipedream/microsoft_outlook",
3
+ "version": "0.0.2",
4
+ "description": "Pipedream Microsoft Outlook Components",
5
+ "main": "microsoft_outlook.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "microsoft_outlook",
9
+ "microsoft",
10
+ "outlook"
11
+ ],
12
+ "homepage": "https://pipedream.com/apps/microsoft_outlook",
13
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "axios": "^0.21.1",
17
+ "js-base64": "^3.7.2",
18
+ "mime-types": "^2.1.35"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ }
23
+ }
@@ -0,0 +1,99 @@
1
+ import microsoftOutlook from "../microsoft_outlook.app.mjs";
2
+
3
+ const getRenewalInterval = (period) => {
4
+ let day = 24 * 60 * 60;
5
+ return period ?
6
+ day * 2.5 * 1000 :// Subscription expiration can only be 4230 minutes in the future.
7
+ day * 2;
8
+ };
9
+
10
+ export default {
11
+ props: {
12
+ microsoftOutlook,
13
+ http: {
14
+ type: "$.interface.http",
15
+ customResponse: true,
16
+ },
17
+ db: "$.service.db",
18
+ timer: {
19
+ type: "$.interface.timer",
20
+ label: "Webhook renewal timer",
21
+ description: "Graph API expires Outlook notifications in 3 days, we auto-renew them in 2 days, [see](https://docs.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0#maximum-length-of-subscription-per-resource-type)",
22
+ default: {
23
+ intervalSeconds: getRenewalInterval(),
24
+ },
25
+ },
26
+ },
27
+ methods: {
28
+ getIntervalEnd() {
29
+ return new Date(Date.now() + getRenewalInterval(true));
30
+ },
31
+ randomString() {
32
+ return `${Math.random().toString(36)
33
+ .substring(2, 15)}${Math.random().toString(36)
34
+ .substring(2, 15)}`;
35
+ },
36
+ async activate({
37
+ resource,
38
+ changeType,
39
+ } = {}) {
40
+ const clientState = this.randomString();
41
+ const response = await this.microsoftOutlook.createHook({
42
+ data: {
43
+ notificationUrl: this.http.endpoint,
44
+ changeType,
45
+ resource,
46
+ expirationDateTime: this.getIntervalEnd(),
47
+ clientState: clientState,
48
+ },
49
+ });
50
+ if (clientState == response.clientState) {
51
+ this.db.set("hookId", response.id);
52
+ this.db.set("clientState", clientState);
53
+ }
54
+ },
55
+ async deactivate() {
56
+ const hookId = this.db.get("hookId");
57
+ await this.microsoftOutlook.deleteHook({
58
+ hookId,
59
+ });
60
+ },
61
+ async run({
62
+ event,
63
+ emitFn,
64
+ } = {}) {
65
+ if (event.interval_seconds || event.cron) {
66
+ await this.microsoftOutlook.renewHook({
67
+ hookId: this.db.get("hookId"),
68
+ data: {
69
+ expirationDateTime: this.getIntervalEnd(),
70
+ },
71
+ });
72
+ return;
73
+ }
74
+ if (event.query && event.query.validationToken) {
75
+ this.http.respond({
76
+ status: 200,
77
+ headers: {
78
+ "Content-Type": "text/plain",
79
+ },
80
+ body: event.query.validationToken,
81
+ });
82
+ } else {
83
+ this.http.respond({
84
+ status: 202,
85
+ });
86
+ const eventBody = JSON.parse(event.bodyRaw);
87
+ for (let i = 0; i < eventBody.value.length; i++) {
88
+ const notification = eventBody.value[i];
89
+ if (!notification.clientState || notification.clientState == this.db.get("clientState")) {
90
+ const resourceId = notification.resourceData.id;
91
+ await emitFn({
92
+ resourceId,
93
+ });
94
+ }
95
+ }
96
+ }
97
+ },
98
+ },
99
+ };
@@ -0,0 +1,41 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook-new-calendar-event",
6
+ name: "New Calendar Event",
7
+ description: "Emit new event when a new Calendar event is created",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ hooks: {
11
+ async activate() {
12
+ await this.activate({
13
+ changeType: "created",
14
+ resource: "/me/events",
15
+ });
16
+ },
17
+ async deactivate() {
18
+ await this.deactivate();
19
+ },
20
+ },
21
+ async run(event) {
22
+ await this.run({
23
+ event,
24
+ emitFn: async ({ resourceId } = {}) => {
25
+ const item = await this.microsoftOutlook.getCalendarEvent({
26
+ eventId: resourceId,
27
+ });
28
+ this.$emit(
29
+ {
30
+ message: item,
31
+ },
32
+ {
33
+ id: item.id,
34
+ ts: Date.parse(item.createdDateTime),
35
+ summary: `New calendar event (ID:${item.id})`,
36
+ },
37
+ );
38
+ },
39
+ });
40
+ },
41
+ };
@@ -0,0 +1,41 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook-new-contact",
6
+ name: "New Contact Event",
7
+ description: "Emit new event when a new Contact is created",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ hooks: {
11
+ async activate() {
12
+ await this.activate({
13
+ changeType: "created",
14
+ resource: "/me/contacts",
15
+ });
16
+ },
17
+ async deactivate() {
18
+ await this.deactivate();
19
+ },
20
+ },
21
+ async run(event) {
22
+ await this.run({
23
+ event,
24
+ emitFn: async ({ resourceId } = {}) => {
25
+ const item = await this.microsoftOutlook.getContact({
26
+ contactId: resourceId,
27
+ });
28
+ this.$emit(
29
+ {
30
+ contact: item,
31
+ },
32
+ {
33
+ id: item.id,
34
+ ts: Date.parse(item.createdDateTime),
35
+ summary: `New contact (ID:${item.id})`,
36
+ },
37
+ );
38
+ },
39
+ });
40
+ },
41
+ };
@@ -0,0 +1,41 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook-new-email",
6
+ name: "New Email Event",
7
+ description: "Emit new event when an email received",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ hooks: {
11
+ async activate() {
12
+ await this.activate({
13
+ changeType: "created",
14
+ resource: "/me/mailfolders('inbox')/messages",
15
+ });
16
+ },
17
+ async deactivate() {
18
+ await this.deactivate();
19
+ },
20
+ },
21
+ async run(event) {
22
+ await this.run({
23
+ event,
24
+ emitFn: async ({ resourceId } = {}) => {
25
+ const item = await this.microsoftOutlook.getMessage({
26
+ messageId: resourceId,
27
+ });
28
+ this.$emit(
29
+ {
30
+ email: item,
31
+ },
32
+ {
33
+ id: item.id,
34
+ ts: Date.parse(item.createdDateTime),
35
+ summary: `New email (ID:${item.id})`,
36
+ },
37
+ );
38
+ },
39
+ });
40
+ },
41
+ };
@@ -0,0 +1,42 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook-updated-calendar-event",
6
+ name: "New Calendar Event Update",
7
+ description: "Emit new event when a Calendar event is updated",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ hooks: {
12
+ async activate() {
13
+ await this.activate({
14
+ changeType: "updated",
15
+ resource: "/me/events",
16
+ });
17
+ },
18
+ async deactivate() {
19
+ await this.deactivate();
20
+ },
21
+ },
22
+ async run(event) {
23
+ await this.run({
24
+ event,
25
+ emitFn: async ({ resourceId } = {}) => {
26
+ const item = await this.microsoftOutlook.getCalendarEvent({
27
+ eventId: resourceId,
28
+ });
29
+ this.$emit(
30
+ {
31
+ message: item,
32
+ },
33
+ {
34
+ id: item.id,
35
+ ts: Date.parse(item.createdDateTime),
36
+ summary: `Calendar event updated (ID:${item.id})`,
37
+ },
38
+ );
39
+ },
40
+ });
41
+ },
42
+ };