@pipedream/microsoft_outlook 1.4.1 → 1.5.1

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.
@@ -5,7 +5,7 @@ export default {
5
5
  key: "microsoft_outlook-add-label-to-email",
6
6
  name: "Add Label to Email",
7
7
  description: "Adds a label/category to an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-update)",
8
- version: "0.0.5",
8
+ version: "0.0.7",
9
9
  type: "action",
10
10
  props: {
11
11
  microsoftOutlook,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-approve-workflow",
5
5
  name: "Approve Workflow",
6
6
  description: "Suspend the workflow until approved by email. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun#flowsuspend)",
7
- version: "0.0.3",
7
+ version: "0.0.5",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-create-contact",
6
- version: "0.0.12",
6
+ version: "0.0.14",
7
7
  name: "Create Contact",
8
8
  description: "Add a contact to the root Contacts folder, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-create-draft-email",
6
- version: "0.0.12",
6
+ version: "0.0.14",
7
7
  name: "Create Draft Email",
8
8
  description: "Create a draft email, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-post-messages)",
9
9
  props: {
@@ -0,0 +1,55 @@
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
+ import fs from "fs";
3
+ import mime from "mime-types";
4
+
5
+ export default {
6
+ key: "microsoft_outlook-download-attachment",
7
+ name: "Download Attachment",
8
+ description: "Downloads an attachment to the /tmp directory. [See the documentation](https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http)",
9
+ version: "0.0.2",
10
+ type: "action",
11
+ props: {
12
+ microsoftOutlook,
13
+ messageId: {
14
+ propDefinition: [
15
+ microsoftOutlook,
16
+ "messageId",
17
+ ],
18
+ description: "The identifier of the message containing the attachment to download",
19
+ },
20
+ attachmentId: {
21
+ propDefinition: [
22
+ microsoftOutlook,
23
+ "attachmentId",
24
+ (c) => ({
25
+ messageId: c.messageId,
26
+ }),
27
+ ],
28
+ },
29
+ filename: {
30
+ type: "string",
31
+ label: "Filename",
32
+ description: "The filename to save the attachment as in the /tmp directory",
33
+ },
34
+ },
35
+ async run({ $ }) {
36
+ const response = await this.microsoftOutlook.getAttachment({
37
+ $,
38
+ messageId: this.messageId,
39
+ attachmentId: this.attachmentId,
40
+ responseType: "arraybuffer",
41
+ });
42
+
43
+ const rawcontent = response.toString("base64");
44
+ const buffer = Buffer.from(rawcontent, "base64");
45
+ const downloadedFilepath = `/tmp/${this.filename}`;
46
+ fs.writeFileSync(downloadedFilepath, buffer);
47
+ const contentType = mime.lookup(downloadedFilepath);
48
+
49
+ return {
50
+ fileName: this.filename,
51
+ contentType,
52
+ filePath: downloadedFilepath,
53
+ };
54
+ },
55
+ };
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-find-contacts",
6
- version: "0.0.12",
6
+ version: "0.0.14",
7
7
  name: "Find Contacts",
8
8
  description: "Finds contacts with the given search string. [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
9
9
  props: {
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-find-email",
5
5
  name: "Find Email",
6
6
  description: "Search for an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-messages)",
7
- version: "0.0.3",
7
+ version: "0.0.5",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-list-contacts",
6
- version: "0.0.12",
6
+ version: "0.0.14",
7
7
  name: "List Contacts",
8
8
  description: "Get a contact collection from the default contacts folder, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
9
9
  props: {
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-list-folders",
5
5
  name: "List Folders",
6
6
  description: "Retrieves a list of all folders in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders)",
7
- version: "0.0.3",
7
+ version: "0.0.5",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-list-labels",
5
5
  name: "List Labels",
6
6
  description: "Get all the labels/categories that have been defined for a user. [See the documentation](https://learn.microsoft.com/en-us/graph/api/outlookuser-list-mastercategories)",
7
- version: "0.0.5",
7
+ version: "0.0.7",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-move-email-to-folder",
5
5
  name: "Move Email to Folder",
6
6
  description: "Moves an email to the specified folder in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-move)",
7
- version: "0.0.3",
7
+ version: "0.0.5",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-remove-label-from-email",
5
5
  name: "Remove Label from Email",
6
6
  description: "Removes a label/category from an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-update)",
7
- version: "0.0.5",
7
+ version: "0.0.7",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "microsoft_outlook-reply-to-email",
5
5
  name: "Reply to Email",
6
6
  description: "Reply to an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-reply)",
7
- version: "0.0.2",
7
+ version: "0.0.4",
8
8
  type: "action",
9
9
  props: {
10
10
  microsoftOutlook,
@@ -67,7 +67,7 @@ export default {
67
67
  data: {
68
68
  comment: this.comment,
69
69
  message: {
70
- ...this.microsoftOutlook.prepareMessageBody(this),
70
+ ...await this.microsoftOutlook.prepareMessageBody(this),
71
71
  ...this.expand,
72
72
  },
73
73
  },
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-send-email",
6
- version: "0.0.13",
6
+ version: "0.0.15",
7
7
  name: "Send Email",
8
8
  description: "Send an email to one or multiple recipients, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-sendmail)",
9
9
  props: {
@@ -63,7 +63,7 @@ export default {
63
63
  $,
64
64
  data: {
65
65
  message: {
66
- ...this.microsoftOutlook.prepareMessageBody(this),
66
+ ...await this.microsoftOutlook.prepareMessageBody(this),
67
67
  ...this.expand,
68
68
  },
69
69
  },
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-update-contact",
6
- version: "0.0.12",
6
+ version: "0.0.14",
7
7
  name: "Update Contact",
8
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
9
  props: {
@@ -1,7 +1,7 @@
1
- import { axios } from "@pipedream/platform";
2
- import fs from "fs";
1
+ import {
2
+ axios, getFileStream,
3
+ } from "@pipedream/platform";
3
4
  import path from "path";
4
- import { encode } from "js-base64";
5
5
  import mime from "mime-types";
6
6
  const DEFAULT_LIMIT = 50;
7
7
 
@@ -54,9 +54,9 @@ export default {
54
54
  optional: true,
55
55
  },
56
56
  files: {
57
- label: "File paths",
58
- description: "Absolute paths to the files (eg. `/tmp/my_file.pdf`)",
59
57
  type: "string[]",
58
+ label: "File Paths or URLs",
59
+ description: "Provide either an array of file URLs or an array of paths to a files in the /tmp directory (for example, /tmp/myFile.pdf).",
60
60
  optional: true,
61
61
  },
62
62
  contact: {
@@ -170,6 +170,29 @@ export default {
170
170
  })) || [];
171
171
  },
172
172
  },
173
+ attachmentId: {
174
+ type: "string",
175
+ label: "Attachment ID",
176
+ description: "The identifier of the attachment to download",
177
+ async options({
178
+ messageId, page,
179
+ }) {
180
+ const limit = DEFAULT_LIMIT;
181
+ const { value: attachments } = await this.listAttachments({
182
+ messageId,
183
+ params: {
184
+ $top: limit,
185
+ $skip: limit * page,
186
+ },
187
+ });
188
+ return attachments?.map(({
189
+ id: value, name: label,
190
+ }) => ({
191
+ value,
192
+ label,
193
+ })) || [];
194
+ },
195
+ },
173
196
  maxResults: {
174
197
  type: "integer",
175
198
  label: "Max Results",
@@ -230,7 +253,19 @@ export default {
230
253
  ...args,
231
254
  });
232
255
  },
233
- prepareMessageBody(self) {
256
+ async streamToBase64(stream) {
257
+ return new Promise((resolve, reject) => {
258
+ const chunks = [];
259
+
260
+ stream.on("data", (chunk) => chunks.push(chunk));
261
+ stream.on("end", () => {
262
+ const buffer = Buffer.concat(chunks);
263
+ resolve(buffer.toString("base64"));
264
+ });
265
+ stream.on("error", reject);
266
+ });
267
+ },
268
+ async prepareMessageBody(self) {
234
269
  const toRecipients = [];
235
270
  const ccRecipients = [];
236
271
  const bccRecipients = [];
@@ -262,15 +297,13 @@ export default {
262
297
 
263
298
  const attachments = [];
264
299
  for (let i = 0; self.files && i < self.files.length; i++) {
300
+ const stream = await getFileStream(self.files[i]);
301
+ const base64 = await this.streamToBase64(stream);
265
302
  attachments.push({
266
303
  "@odata.type": "#microsoft.graph.fileAttachment",
267
304
  "name": path.basename(self.files[i]),
268
305
  "contentType": mime.lookup(self.files[i]),
269
- "contentBytes": encode([
270
- ...fs.readFileSync(self.files[i], {
271
- flag: "r",
272
- }).values(),
273
- ]),
306
+ "contentBytes": base64,
274
307
  });
275
308
  }
276
309
  const message = {
@@ -403,6 +436,22 @@ export default {
403
436
  ...args,
404
437
  });
405
438
  },
439
+ getAttachment({
440
+ messageId, attachmentId, ...args
441
+ }) {
442
+ return this._makeRequest({
443
+ path: `/me/messages/${messageId}/attachments/${attachmentId}/$value`,
444
+ ...args,
445
+ });
446
+ },
447
+ listAttachments({
448
+ messageId, ...args
449
+ }) {
450
+ return this._makeRequest({
451
+ path: `/me/messages/${messageId}/attachments`,
452
+ ...args,
453
+ });
454
+ },
406
455
  async *paginate({
407
456
  fn, args = {}, max,
408
457
  }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/microsoft_outlook",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Pipedream Microsoft Outlook Components",
5
5
  "main": "microsoft_outlook.app.mjs",
6
6
  "keywords": [
@@ -12,7 +12,7 @@
12
12
  "homepage": "https://pipedream.com/apps/microsoft_outlook",
13
13
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
14
14
  "dependencies": {
15
- "@pipedream/platform": "^3.0.3",
15
+ "@pipedream/platform": "^3.1.0",
16
16
  "axios": "^0.21.1",
17
17
  "js-base64": "^3.7.2",
18
18
  "md5": "^2.3.0",
@@ -0,0 +1,58 @@
1
+ import common from "./common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ props: {
6
+ ...common.props,
7
+ folderIds: {
8
+ propDefinition: [
9
+ common.props.microsoftOutlook,
10
+ "folderIds",
11
+ ],
12
+ optional: true,
13
+ },
14
+ },
15
+ hooks: {
16
+ ...common.hooks,
17
+ async deploy() {
18
+ this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
19
+ this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));
20
+
21
+ const events = await this.getSampleEvents({
22
+ pageSize: 25,
23
+ });
24
+ if (!events || events.length == 0) {
25
+ return;
26
+ }
27
+ for (const item of events) {
28
+ this.emitEvent(item);
29
+ }
30
+ },
31
+ async activate() {
32
+ await this.activate({
33
+ changeType: "created",
34
+ resource: "/me/messages",
35
+ });
36
+ },
37
+ async deactivate() {
38
+ await this.deactivate();
39
+ },
40
+ },
41
+ methods: {
42
+ ...common.methods,
43
+ async getFolderIdByName(name) {
44
+ const { value: folders } = await this.microsoftOutlook.listFolders();
45
+ const folder = folders.find(({ displayName }) => displayName === name);
46
+ return folder?.id;
47
+ },
48
+ isRelevant(item) {
49
+ if (this.folderIds?.length) {
50
+ return this.folderIds.includes(item.parentFolderId);
51
+ }
52
+ // if no folderIds are specified, filter out items in Sent Items & Drafts
53
+ const sentItemFolderId = this.db.get("sentItemFolderId");
54
+ const draftsFolderId = this.db.get("draftsFolderId");
55
+ return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
56
+ },
57
+ },
58
+ };
@@ -1,4 +1,4 @@
1
- import microsoftOutlook from "../microsoft_outlook.app.mjs";
1
+ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
2
2
 
3
3
  const getRenewalInterval = (period) => {
4
4
  let day = 24 * 60 * 60;
@@ -0,0 +1,96 @@
1
+ import common from "../common/common-new-email.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook-new-attachment-received",
6
+ name: "New Attachment Received (Instant)",
7
+ description: "Emit new event when a new email containing one or more attachments arrives in a specified Microsoft Outlook folder.",
8
+ version: "0.0.2",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async getSampleEvents({ pageSize }) {
14
+ const folders = this.folderIds?.length
15
+ ? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
16
+ : [
17
+ "/me/messages",
18
+ ];
19
+
20
+ const messagesWithAttachments = [];
21
+ for (const folder of folders) {
22
+ const { value: messages } = await this.microsoftOutlook.listMessages({
23
+ resource: folder,
24
+ params: {
25
+ $top: pageSize,
26
+ $filter: "hasAttachments eq true",
27
+ },
28
+ });
29
+ messagesWithAttachments.push(...messages);
30
+ }
31
+
32
+ const attachments = [];
33
+ for (const message of messagesWithAttachments) {
34
+ const messageAttachments = await this.getMessageAttachments(message);
35
+ attachments.push(...messageAttachments);
36
+ }
37
+ return attachments;
38
+ },
39
+ async getMessageAttachments(message) {
40
+ const { value: attachments } = await this.microsoftOutlook.listAttachments({
41
+ messageId: message.id,
42
+ });
43
+ if (!attachments?.length) {
44
+ return [];
45
+ }
46
+ return attachments.map((attachment) => ({
47
+ ...attachment,
48
+ messageId: message.id,
49
+ messageSubject: message.subject,
50
+ messageSender: message.sender,
51
+ messageReceivedDateTime: message.receivedDateTime,
52
+ parentFolderId: message.parentFolderId,
53
+ contentBytes: undefined,
54
+ }));
55
+ },
56
+ emitEvent(item) {
57
+ if (this.isRelevant(item)) {
58
+ this.$emit(item, this.generateMeta(item));
59
+ }
60
+ },
61
+ generateMeta(item) {
62
+ return {
63
+ id: item.contentId,
64
+ summary: `New attachment ${item.name}`,
65
+ ts: Date.parse(item.messageReceivedDateTime),
66
+ };
67
+ },
68
+ },
69
+ async run(event) {
70
+ const folders = this.folderIds?.length
71
+ ? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
72
+ : [
73
+ "/me/messages",
74
+ ];
75
+
76
+ for (const folder of folders) {
77
+ await this.run({
78
+ event,
79
+ emitFn: async ({ resourceId } = {}) => {
80
+ try {
81
+ const message = await this.microsoftOutlook.getMessage({
82
+ resource: folder,
83
+ messageId: resourceId,
84
+ });
85
+ if (message.hasAttachments) {
86
+ const attachments = await this.getMessageAttachments(message);
87
+ attachments.forEach((item) => this.emitEvent(item));
88
+ }
89
+ } catch {
90
+ console.log(`Could not fetch message with ID: ${resourceId}`);
91
+ }
92
+ },
93
+ });
94
+ }
95
+ },
96
+ };
@@ -1,11 +1,11 @@
1
- import common from "../common.mjs";
1
+ import common from "../common/common.mjs";
2
2
 
3
3
  export default {
4
4
  ...common,
5
5
  key: "microsoft_outlook-new-contact",
6
6
  name: "New Contact Event (Instant)",
7
7
  description: "Emit new event when a new Contact is created",
8
- version: "0.0.13",
8
+ version: "0.0.15",
9
9
  type: "source",
10
10
  hooks: {
11
11
  ...common.hooks,
@@ -1,4 +1,4 @@
1
- import common from "../common.mjs";
1
+ import common from "../common/common-new-email.mjs";
2
2
  import md5 from "md5";
3
3
  import sampleEmit from "./test-event.mjs";
4
4
 
@@ -7,52 +7,11 @@ export default {
7
7
  key: "microsoft_outlook-new-email",
8
8
  name: "New Email Event (Instant)",
9
9
  description: "Emit new event when an email is received in specified folders.",
10
- version: "0.0.16",
10
+ version: "0.0.18",
11
11
  type: "source",
12
12
  dedupe: "unique",
13
- props: {
14
- ...common.props,
15
- folderIds: {
16
- propDefinition: [
17
- common.props.microsoftOutlook,
18
- "folderIds",
19
- ],
20
- optional: true,
21
- },
22
- },
23
- hooks: {
24
- ...common.hooks,
25
- async deploy() {
26
- this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
27
- this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));
28
-
29
- const events = await this.getSampleEvents({
30
- pageSize: 25,
31
- });
32
- if (!events || events.length == 0) {
33
- return;
34
- }
35
- for (const item of events) {
36
- this.emitEvent(item);
37
- }
38
- },
39
- async activate() {
40
- await this.activate({
41
- changeType: "created",
42
- resource: "/me/messages",
43
- });
44
- },
45
- async deactivate() {
46
- await this.deactivate();
47
- },
48
- },
49
13
  methods: {
50
14
  ...common.methods,
51
- async getFolderIdByName(name) {
52
- const { value: folders } = await this.microsoftOutlook.listFolders();
53
- const folder = folders.find(({ displayName }) => displayName === name);
54
- return folder?.id;
55
- },
56
15
  async getSampleEvents({ pageSize }) {
57
16
  const folders = this.folderIds?.length
58
17
  ? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
@@ -73,15 +32,6 @@ export default {
73
32
  }
74
33
  return results;
75
34
  },
76
- isRelevant(item) {
77
- if (this.folderIds?.length) {
78
- return this.folderIds.includes(item.parentFolderId);
79
- }
80
- // if no folderIds are specified, filter out items in Sent Items & Drafts
81
- const sentItemFolderId = this.db.get("sentItemFolderId");
82
- const draftsFolderId = this.db.get("draftsFolderId");
83
- return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
84
- },
85
35
  emitEvent(item) {
86
36
  if (this.isRelevant(item)) {
87
37
  this.$emit(