@pipedream/microsoft_outlook 1.7.10 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.15",
8
+ version: "0.0.16",
9
9
  annotations: {
10
10
  destructiveHint: true,
11
11
  openWorldHint: true,
@@ -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.13",
7
+ version: "0.0.14",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -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.22",
6
+ version: "0.0.23",
7
7
  annotations: {
8
8
  destructiveHint: false,
9
9
  openWorldHint: true,
@@ -4,7 +4,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
4
4
  export default {
5
5
  type: "action",
6
6
  key: "microsoft_outlook-create-draft-email",
7
- version: "0.0.22",
7
+ version: "0.0.23",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -13,7 +13,7 @@ export default {
13
13
  key: "microsoft_outlook-download-attachment",
14
14
  name: "Download Attachment",
15
15
  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)",
16
- version: "0.0.11",
16
+ version: "0.0.12",
17
17
  annotations: {
18
18
  destructiveHint: false,
19
19
  openWorldHint: true,
@@ -56,14 +56,6 @@ export default {
56
56
  },
57
57
  },
58
58
  methods: {
59
- getAttachmentInfo({
60
- messageId, attachmentId, ...args
61
- }) {
62
- return this.microsoftOutlook._makeRequest({
63
- path: `/me/messages/${messageId}/attachments/${attachmentId}`,
64
- ...args,
65
- });
66
- },
67
59
  async imageToPdf(imageBuffer) {
68
60
  return new Promise((resolve, reject) => {
69
61
  const doc = new PDFDocument({
@@ -113,7 +105,6 @@ export default {
113
105
  $,
114
106
  messageId: this.messageId,
115
107
  attachmentId: this.attachmentId,
116
- responseType: "arraybuffer",
117
108
  });
118
109
 
119
110
  let filename = this.filename;
@@ -122,11 +113,10 @@ export default {
122
113
  filename = `${name}.pdf`;
123
114
  }
124
115
 
125
- const rawcontent = response.toString("base64");
126
- let buffer = Buffer.from(rawcontent, "base64");
116
+ let buffer = await this.microsoftOutlook.streamToBuffer(response);
127
117
 
128
118
  if (this.convertToPdf) {
129
- const { contentType: mimeType } = await this.getAttachmentInfo({
119
+ const { contentType: mimeType } = await this.microsoftOutlook.getAttachmentInfo({
130
120
  $,
131
121
  messageId: this.messageId,
132
122
  attachmentId: this.attachmentId,
@@ -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.22",
6
+ version: "0.0.23",
7
7
  annotations: {
8
8
  destructiveHint: false,
9
9
  openWorldHint: true,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "microsoft_outlook-find-email",
6
6
  name: "Find Email",
7
7
  description: "Search for an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-messages)",
8
- version: "0.0.16",
8
+ version: "0.0.17",
9
9
  annotations: {
10
10
  destructiveHint: false,
11
11
  openWorldHint: true,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "microsoft_outlook-find-shared-folder-email",
6
6
  name: "Find Shared Folder Email",
7
7
  description: "Search for an email in a shared folder in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-messages)",
8
- version: "0.0.7",
8
+ version: "0.0.8",
9
9
  annotations: {
10
10
  destructiveHint: false,
11
11
  openWorldHint: true,
@@ -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.22",
6
+ version: "0.0.23",
7
7
  annotations: {
8
8
  destructiveHint: false,
9
9
  openWorldHint: true,
@@ -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.13",
7
+ version: "0.0.14",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -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.15",
7
+ version: "0.0.16",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -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.13",
7
+ version: "0.0.14",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -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.15",
7
+ version: "0.0.16",
8
8
  annotations: {
9
9
  destructiveHint: true,
10
10
  openWorldHint: true,
@@ -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.12",
7
+ version: "0.0.13",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -4,7 +4,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
4
4
  export default {
5
5
  type: "action",
6
6
  key: "microsoft_outlook-send-email",
7
- version: "0.0.23",
7
+ version: "0.0.24",
8
8
  annotations: {
9
9
  destructiveHint: false,
10
10
  openWorldHint: true,
@@ -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.22",
6
+ version: "0.0.23",
7
7
  annotations: {
8
8
  destructiveHint: true,
9
9
  openWorldHint: true,
@@ -1,6 +1,6 @@
1
- import {
2
- axios, getFileStreamAndMetadata, ConfigurationError,
3
- } from "@pipedream/platform";
1
+ import { getFileStreamAndMetadata } from "@pipedream/platform";
2
+ import { Client } from "@microsoft/microsoft-graph-client";
3
+ import "isomorphic-fetch";
4
4
  const DEFAULT_LIMIT = 50;
5
5
 
6
6
  export default {
@@ -266,64 +266,26 @@ export default {
266
266
  },
267
267
  },
268
268
  methods: {
269
- _getUrl(path) {
270
- return `https://graph.microsoft.com/v1.0${path}`;
271
- },
272
- _getHeaders(headers) {
273
- return {
274
- "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
275
- "accept": "application/json",
276
- "Content-Type": "application/json",
277
- ...headers,
278
- };
279
- },
280
- async _makeRequest({
281
- $,
282
- path,
283
- headers,
284
- ...otherConfig
285
- } = {}) {
286
- const config = {
287
- url: this._getUrl(path),
288
- headers: this._getHeaders(headers),
289
- ...otherConfig,
290
- };
291
- try {
292
- return await axios($ ?? this, config);
293
- } catch (error) {
294
- if (error?.response?.status === 403) {
295
- throw new Error("Insufficient permissions. Please verify that your Microsoft account has the necessary permissions to perform this operation.");
296
- }
297
- throw new ConfigurationError(error.message);
298
- }
299
- },
300
- async createHook({ ...args } = {}) {
301
- const response = await this._makeRequest({
302
- method: "POST",
303
- path: "/subscriptions",
304
- ...args,
269
+ client() {
270
+ return Client.init({
271
+ authProvider: (done) => {
272
+ done(null, this.$auth.oauth_access_token);
273
+ },
305
274
  });
306
- return response;
275
+ },
276
+ async createHook({ data = {} } = {}) {
277
+ return await this.client().api("/subscriptions")
278
+ .post(data);
307
279
  },
308
280
  async renewHook({
309
- hookId,
310
- ...args
281
+ hookId, data = {},
311
282
  } = {}) {
312
- return await this._makeRequest({
313
- method: "PATCH",
314
- path: `/subscriptions/${hookId}`,
315
- ...args,
316
- });
283
+ return await this.client().api(`/subscriptions/${hookId}`)
284
+ .patch(data);
317
285
  },
318
- async deleteHook({
319
- hookId,
320
- ...args
321
- } = {}) {
322
- return await this._makeRequest({
323
- method: "DELETE",
324
- path: `/subscriptions/${hookId}`,
325
- ...args,
326
- });
286
+ async deleteHook({ hookId } = {}) {
287
+ return await this.client().api(`/subscriptions/${hookId}`)
288
+ .delete();
327
289
  },
328
290
  async streamToBase64(stream) {
329
291
  return new Promise((resolve, reject) => {
@@ -337,6 +299,35 @@ export default {
337
299
  stream.on("error", reject);
338
300
  });
339
301
  },
302
+ async streamToBuffer(stream) {
303
+ // Node.js Readable stream
304
+ if (typeof stream.on === "function") {
305
+ return new Promise((resolve, reject) => {
306
+ const chunks = [];
307
+ stream.on("data", (chunk) => chunks.push(chunk));
308
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
309
+ stream.on("error", reject);
310
+ });
311
+ }
312
+
313
+ // Web ReadableStream (WHATWG)
314
+ if (typeof stream.getReader === "function") {
315
+ const reader = stream.getReader();
316
+ const chunks = [];
317
+
318
+ while (true) {
319
+ const {
320
+ done, value,
321
+ } = await reader.read();
322
+ if (done) break;
323
+ chunks.push(Buffer.from(value));
324
+ }
325
+
326
+ return Buffer.concat(chunks);
327
+ }
328
+
329
+ throw new Error("Unknown stream type returned by Microsoft Graph client");
330
+ },
340
331
  async prepareMessageBody(self) {
341
332
  const toRecipients = [];
342
333
  const ccRecipients = [];
@@ -397,159 +388,111 @@ export default {
397
388
 
398
389
  return message;
399
390
  },
400
- async sendEmail({ ...args } = {}) {
401
- return await this._makeRequest({
402
- method: "POST",
403
- path: "/me/sendMail",
404
- ...args,
405
- });
391
+ async sendEmail({ data = {} } = {}) {
392
+ return await this.client().api("/me/sendMail")
393
+ .post(data);
406
394
  },
407
395
  async replyToEmail({
408
- messageId, ...args
409
- }) {
410
- return await this._makeRequest({
411
- method: "POST",
412
- path: `/me/messages/${messageId}/reply`,
413
- ...args,
414
- });
396
+ messageId, data = {},
397
+ } = {}) {
398
+ return await this.client().api(`/me/messages/${messageId}/reply`)
399
+ .post(data);
415
400
  },
416
- async createDraft({ ...args } = {}) {
417
- return await this._makeRequest({
418
- method: "POST",
419
- path: "/me/messages",
420
- ...args,
421
- });
401
+ async createDraft({ data = {} } = {}) {
402
+ return await this.client().api("/me/messages")
403
+ .post(data);
422
404
  },
423
- async createContact({ ...args } = {}) {
424
- return await this._makeRequest({
425
- method: "POST",
426
- path: "/me/contacts",
427
- ...args,
428
- });
405
+ async createContact({ data = {} } = {}) {
406
+ return await this.client().api("/me/contacts")
407
+ .post(data);
429
408
  },
430
409
  async listContacts({
431
- filterAddress,
432
- ...args
410
+ filterAddress, params = {},
433
411
  } = {}) {
434
- args.params = {
435
- ...args?.params,
436
- };
437
412
  if (filterAddress) {
438
- args.params["$filter"] = `emailAddresses/any(a:a/address eq '${filterAddress}')`;
413
+ params["$filter"] = `emailAddresses/any(a:a/address eq '${filterAddress}')`;
439
414
  }
440
- return await this._makeRequest({
441
- method: "GET",
442
- path: "/me/contacts",
443
- ...args,
444
- });
415
+ return await this.client().api("/me/contacts")
416
+ .get(params);
445
417
  },
446
418
  async updateContact({
447
- contactId,
448
- ...args
419
+ contactId, data = {},
449
420
  } = {}) {
450
- return await this._makeRequest({
451
- method: "PATCH",
452
- path: `/me/contacts/${contactId}`,
453
- ...args,
454
- });
421
+ return await this.client().api(`/me/contacts/${contactId}`)
422
+ .patch(data);
455
423
  },
456
424
  async getMessage({
457
- messageId,
458
- ...args
425
+ messageId, params = {},
459
426
  } = {}) {
460
- return await this._makeRequest({
461
- method: "GET",
462
- path: `/me/messages/${messageId}`,
463
- ...args,
464
- });
427
+ return await this.client().api(`/me/messages/${messageId}`)
428
+ .get(params);
465
429
  },
466
- async listMessages({ ...args } = {}) {
467
- return await this._makeRequest({
468
- method: "GET",
469
- path: "/me/messages",
470
- ...args,
471
- });
430
+ async listMessages({ params = {} } = {}) {
431
+ return await this.client().api("/me/messages")
432
+ .get(params);
472
433
  },
473
434
  async listSharedFolderMessages({
474
- userId, sharedFolderId, ...args
435
+ userId, sharedFolderId, params = {},
475
436
  } = {}) {
476
- return await this._makeRequest({
477
- method: "GET",
478
- path: `/users/${userId}/mailFolders/${sharedFolderId}/messages`,
479
- ...args,
480
- });
437
+ return await this.client().api(`/users/${userId}/mailFolders/${sharedFolderId}/messages`)
438
+ .get(params);
481
439
  },
482
440
  async getContact({
483
- contactId,
484
- ...args
441
+ contactId, params = {},
485
442
  } = {}) {
486
- return await this._makeRequest({
487
- method: "GET",
488
- path: `/me/contacts/${contactId}`,
489
- ...args,
490
- });
443
+ return await this.client().api(`/me/contacts/${contactId}`)
444
+ .get(params);
491
445
  },
492
- listLabels(args = {}) {
493
- return this._makeRequest({
494
- path: "/me/outlook/masterCategories",
495
- ...args,
496
- });
446
+ async listLabels({ params = {} } = {}) {
447
+ return await this.client().api("/me/outlook/masterCategories")
448
+ .get(params);
497
449
  },
498
- listFolders(args = {}) {
499
- return this._makeRequest({
500
- path: "/me/mailFolders",
501
- ...args,
502
- });
450
+ async listFolders({ params = {} } = {}) {
451
+ return await this.client().api("/me/mailFolders")
452
+ .get(params);
503
453
  },
504
- moveMessage({
505
- messageId, ...args
506
- }) {
507
- return this._makeRequest({
508
- method: "POST",
509
- path: `/me/messages/${messageId}/move`,
510
- ...args,
511
- });
454
+ async moveMessage({
455
+ messageId, data = {},
456
+ } = {}) {
457
+ return await this.client().api(`/me/messages/${messageId}/move`)
458
+ .post(data);
512
459
  },
513
- updateMessage({
514
- messageId, ...args
515
- }) {
516
- return this._makeRequest({
517
- method: "PATCH",
518
- path: `/me/messages/${messageId}`,
519
- ...args,
520
- });
460
+ async updateMessage({
461
+ messageId, data = {},
462
+ } = {}) {
463
+ return await this.client().api(`/me/messages/${messageId}`)
464
+ .patch(data);
521
465
  },
522
- getAttachment({
523
- messageId, attachmentId, ...args
524
- }) {
525
- return this._makeRequest({
526
- path: `/me/messages/${messageId}/attachments/${attachmentId}/$value`,
527
- ...args,
528
- });
466
+ async getAttachment({
467
+ messageId, attachmentId, params = {},
468
+ } = {}) {
469
+ return await this.client().api(`/me/messages/${messageId}/attachments/${attachmentId}/$value`)
470
+ .responseType("stream")
471
+ .get(params);
529
472
  },
530
- listAttachments({
531
- messageId, ...args
532
- }) {
533
- return this._makeRequest({
534
- path: `/me/messages/${messageId}/attachments`,
535
- ...args,
536
- });
473
+ async getAttachmentInfo({
474
+ messageId, attachmentId, params = {},
475
+ } = {}) {
476
+ return await this.client().api(`/me/messages/${messageId}/attachments/${attachmentId}`)
477
+ .get(params);
537
478
  },
538
- listUsers(args = {}) {
539
- return this._makeRequest({
540
- path: "/users",
541
- ...args,
542
- });
479
+ async listAttachments({
480
+ messageId, params = {},
481
+ } = {}) {
482
+ return await this.client().api(`/me/messages/${messageId}/attachments`)
483
+ .get(params);
484
+ },
485
+ async listUsers({ params = {} } = {}) {
486
+ return await this.client().api("/users")
487
+ .get(params);
543
488
  },
544
489
  async listSharedFolders({
545
- userId, parentFolderId, ...args
490
+ userId, parentFolderId, params = {},
546
491
  } = {}) {
547
- const { value } = await this._makeRequest({
548
- path: `/users/${userId}/mailFolders${parentFolderId
549
- ? `/${parentFolderId}/childFolders`
550
- : ""}`,
551
- ...args,
552
- });
492
+ const { value } = await this.client().api(`/users/${userId}/mailFolders${parentFolderId
493
+ ? `/${parentFolderId}/childFolders`
494
+ : ""}`)
495
+ .get(params);
553
496
 
554
497
  const foldersArray = [];
555
498
  for (const folder of value) {
@@ -557,7 +500,6 @@ export default {
557
500
  foldersArray.push(...await this.listSharedFolders({
558
501
  userId,
559
502
  parentFolderId: folder.id,
560
- ...args,
561
503
  }));
562
504
  }
563
505
 
@@ -575,18 +517,19 @@ export default {
575
517
  $skip: 0,
576
518
  },
577
519
  };
578
- let total, count = 0;
520
+ let hasMore, count = 0;
579
521
  do {
580
- const { value } = await fn(args);
522
+ const response = await fn(args);
523
+ const { value } = response;
581
524
  for (const item of value) {
582
525
  yield item;
583
526
  if (max && ++count >= max) {
584
527
  return;
585
528
  }
586
529
  }
587
- total = value?.length;
530
+ hasMore = response?.["@odata.nextLink"];
588
531
  args.params["$skip"] += limit;
589
- } while (total);
532
+ } while (hasMore);
590
533
  },
591
534
  },
592
535
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/microsoft_outlook",
3
- "version": "1.7.10",
3
+ "version": "1.8.0",
4
4
  "description": "Pipedream Microsoft Outlook Components",
5
5
  "main": "microsoft_outlook.app.mjs",
6
6
  "keywords": [
@@ -12,6 +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
+ "@microsoft/microsoft-graph-client": "^3.0.7",
15
16
  "@pipedream/platform": "^3.1.1",
16
17
  "@sparticuz/chromium": "^143.0.4",
17
18
  "axios": "^0.30.2",
@@ -6,7 +6,7 @@ export default {
6
6
  key: "microsoft_outlook-new-attachment-received",
7
7
  name: "New Attachment Received (Instant)",
8
8
  description: "Emit new event when a new email containing one or more attachments arrives in a specified Microsoft Outlook folder.",
9
- version: "0.1.6",
9
+ version: "0.1.7",
10
10
  type: "source",
11
11
  dedupe: "unique",
12
12
  props: {
@@ -56,10 +56,8 @@ export default {
56
56
  const messageAttachment = await this.microsoftOutlook.getAttachment({
57
57
  messageId: item.messageId,
58
58
  attachmentId: item.id,
59
- responseType: "arraybuffer",
60
59
  });
61
- const rawcontent = messageAttachment.toString("base64");
62
- const buffer = Buffer.from(rawcontent, "base64");
60
+ const buffer = await this.microsoftOutlook.streamToBuffer(messageAttachment);
63
61
  const filepath = `${item.id}/${item.name}`;
64
62
  // Upload the attachment to the configured directory (File Stash) so it
65
63
  // can be accessed later.
@@ -5,7 +5,7 @@ export default {
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.22",
8
+ version: "0.0.23",
9
9
  type: "source",
10
10
  hooks: {
11
11
  ...common.hooks,
@@ -7,7 +7,7 @@ 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.1.8",
10
+ version: "0.1.9",
11
11
  type: "source",
12
12
  dedupe: "unique",
13
13
  methods: {
@@ -7,7 +7,7 @@ export default {
7
7
  key: "microsoft_outlook-new-email-in-shared-folder",
8
8
  name: "New Email in Shared Folder Event",
9
9
  description: "Emit new event when an email is received in specified shared folders.",
10
- version: "0.0.8",
10
+ version: "0.0.9",
11
11
  type: "source",
12
12
  dedupe: "unique",
13
13
  props: {