@divyacon/piece-microsoft-outlook 0.7.7 → 0.7.8

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.
Files changed (107) hide show
  1. package/package.json +9 -27
  2. package/src/i18n/de.json +298 -0
  3. package/src/i18n/es.json +298 -0
  4. package/src/i18n/fr.json +298 -0
  5. package/src/i18n/ja.json +298 -0
  6. package/src/i18n/nl.json +298 -0
  7. package/src/i18n/pt.json +298 -0
  8. package/src/i18n/ru.json +41 -0
  9. package/src/i18n/translation.json +298 -0
  10. package/src/i18n/vi.json +41 -0
  11. package/src/i18n/zh.json +298 -0
  12. package/src/index.js +77 -0
  13. package/dist/index.d.ts +0 -2
  14. package/dist/index.d.ts.map +0 -1
  15. package/dist/index.js +0 -65
  16. package/dist/index.js.map +0 -1
  17. package/dist/lib/actions/add-label-to-email.d.ts +0 -5
  18. package/dist/lib/actions/add-label-to-email.d.ts.map +0 -1
  19. package/dist/lib/actions/add-label-to-email.js +0 -44
  20. package/dist/lib/actions/add-label-to-email.js.map +0 -1
  21. package/dist/lib/actions/create-draft-email.d.ts +0 -10
  22. package/dist/lib/actions/create-draft-email.d.ts.map +0 -1
  23. package/dist/lib/actions/create-draft-email.js +0 -108
  24. package/dist/lib/actions/create-draft-email.js.map +0 -1
  25. package/dist/lib/actions/download-email-attachment.d.ts +0 -4
  26. package/dist/lib/actions/download-email-attachment.d.ts.map +0 -1
  27. package/dist/lib/actions/download-email-attachment.js +0 -44
  28. package/dist/lib/actions/download-email-attachment.js.map +0 -1
  29. package/dist/lib/actions/find-email.d.ts +0 -6
  30. package/dist/lib/actions/find-email.d.ts.map +0 -1
  31. package/dist/lib/actions/find-email.js +0 -67
  32. package/dist/lib/actions/find-email.js.map +0 -1
  33. package/dist/lib/actions/forward-email.d.ts +0 -6
  34. package/dist/lib/actions/forward-email.d.ts.map +0 -1
  35. package/dist/lib/actions/forward-email.js +0 -61
  36. package/dist/lib/actions/forward-email.js.map +0 -1
  37. package/dist/lib/actions/move-email-to-folder.d.ts +0 -5
  38. package/dist/lib/actions/move-email-to-folder.d.ts.map +0 -1
  39. package/dist/lib/actions/move-email-to-folder.js +0 -41
  40. package/dist/lib/actions/move-email-to-folder.js.map +0 -1
  41. package/dist/lib/actions/remove-label-from-email.d.ts +0 -5
  42. package/dist/lib/actions/remove-label-from-email.d.ts.map +0 -1
  43. package/dist/lib/actions/remove-label-from-email.js +0 -44
  44. package/dist/lib/actions/remove-label-from-email.js.map +0 -1
  45. package/dist/lib/actions/reply-email.d.ts +0 -10
  46. package/dist/lib/actions/reply-email.d.ts.map +0 -1
  47. package/dist/lib/actions/reply-email.js +0 -161
  48. package/dist/lib/actions/reply-email.js.map +0 -1
  49. package/dist/lib/actions/request-approval-send-email.d.ts +0 -6
  50. package/dist/lib/actions/request-approval-send-email.d.ts.map +0 -1
  51. package/dist/lib/actions/request-approval-send-email.js +0 -99
  52. package/dist/lib/actions/request-approval-send-email.js.map +0 -1
  53. package/dist/lib/actions/send-draft-email.d.ts +0 -4
  54. package/dist/lib/actions/send-draft-email.d.ts.map +0 -1
  55. package/dist/lib/actions/send-draft-email.js +0 -38
  56. package/dist/lib/actions/send-draft-email.js.map +0 -1
  57. package/dist/lib/actions/send-email.d.ts +0 -10
  58. package/dist/lib/actions/send-email.d.ts.map +0 -1
  59. package/dist/lib/actions/send-email.js +0 -111
  60. package/dist/lib/actions/send-email.js.map +0 -1
  61. package/dist/lib/common/auth.d.ts +0 -2
  62. package/dist/lib/common/auth.d.ts.map +0 -1
  63. package/dist/lib/common/auth.js +0 -88
  64. package/dist/lib/common/auth.js.map +0 -1
  65. package/dist/lib/common/client.d.ts +0 -16
  66. package/dist/lib/common/client.d.ts.map +0 -1
  67. package/dist/lib/common/client.js +0 -27
  68. package/dist/lib/common/client.js.map +0 -1
  69. package/dist/lib/common/microsoft-cloud.d.ts +0 -6
  70. package/dist/lib/common/microsoft-cloud.d.ts.map +0 -1
  71. package/dist/lib/common/microsoft-cloud.js +0 -57
  72. package/dist/lib/common/microsoft-cloud.js.map +0 -1
  73. package/dist/lib/common/props.d.ts +0 -10
  74. package/dist/lib/common/props.d.ts.map +0 -1
  75. package/dist/lib/common/props.js +0 -124
  76. package/dist/lib/common/props.js.map +0 -1
  77. package/dist/lib/triggers/new-attachment.d.ts +0 -19
  78. package/dist/lib/triggers/new-attachment.d.ts.map +0 -1
  79. package/dist/lib/triggers/new-attachment.js +0 -129
  80. package/dist/lib/triggers/new-attachment.js.map +0 -1
  81. package/dist/lib/triggers/new-email-in-folder.d.ts +0 -11
  82. package/dist/lib/triggers/new-email-in-folder.d.ts.map +0 -1
  83. package/dist/lib/triggers/new-email-in-folder.js +0 -96
  84. package/dist/lib/triggers/new-email-in-folder.js.map +0 -1
  85. package/dist/lib/triggers/new-email.d.ts +0 -15
  86. package/dist/lib/triggers/new-email.d.ts.map +0 -1
  87. package/dist/lib/triggers/new-email.js +0 -120
  88. package/dist/lib/triggers/new-email.js.map +0 -1
  89. package/src/index.ts +0 -56
  90. package/src/lib/actions/add-label-to-email.ts +0 -41
  91. package/src/lib/actions/create-draft-email.ts +0 -106
  92. package/src/lib/actions/download-email-attachment.ts +0 -47
  93. package/src/lib/actions/find-email.ts +0 -72
  94. package/src/lib/actions/forward-email.ts +0 -64
  95. package/src/lib/actions/move-email-to-folder.ts +0 -36
  96. package/src/lib/actions/remove-label-from-email.ts +0 -43
  97. package/src/lib/actions/reply-email.ts +0 -158
  98. package/src/lib/actions/request-approval-send-email.ts +0 -105
  99. package/src/lib/actions/send-draft-email.ts +0 -33
  100. package/src/lib/actions/send-email.ts +0 -110
  101. package/src/lib/common/auth.ts +0 -85
  102. package/src/lib/common/client.ts +0 -26
  103. package/src/lib/common/microsoft-cloud.ts +0 -56
  104. package/src/lib/common/props.ts +0 -137
  105. package/src/lib/triggers/new-attachment.ts +0 -153
  106. package/src/lib/triggers/new-email-in-folder.ts +0 -95
  107. package/src/lib/triggers/new-email.ts +0 -126
@@ -1,158 +0,0 @@
1
- import { ApFile, createAction, Property, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
- import { microsoftOutlookAuth } from '../common/auth';
3
- import { outlookCommon } from '../common/client';
4
- import { BodyType, Message } from '@microsoft/microsoft-graph-types';
5
- import { PageCollection } from '@microsoft/microsoft-graph-client';
6
-
7
- export const replyEmailAction = createAction({
8
- auth: microsoftOutlookAuth,
9
- name: 'reply-email',
10
- displayName: 'Reply to Email',
11
- description: 'Reply to an outlook email.',
12
- audience: 'both',
13
- aiMetadata: { description: 'Replies to an existing Outlook message (identified by message ID), supporting added CC/BCC recipients and attachments. Set the Create Draft flag to stage the reply without sending; otherwise it is sent immediately. Not idempotent when sending: each call creates and dispatches a new reply.', idempotent: false },
14
- props: {
15
- messageId: Property.Dropdown({
16
- auth: microsoftOutlookAuth,
17
- displayName: 'Email',
18
- description: 'Select the email message to reply to.',
19
- required: true,
20
- refreshers: [],
21
- options: async ({ auth }) => {
22
- if (!auth) {
23
- return {
24
- disabled: true,
25
- options: [],
26
- };
27
- }
28
-
29
- const client = outlookCommon.createClient(auth as OAuth2PropertyValue);
30
-
31
- try {
32
- const response: PageCollection = await client
33
- .api(`${outlookCommon.mailboxPrefix(auth as OAuth2PropertyValue)}/messages?$top=50&$select=id,subject,from,receivedDateTime`)
34
- .orderby('receivedDateTime desc')
35
- .get();
36
-
37
- const messages = response.value as Message[];
38
-
39
- return {
40
- disabled: false,
41
- options: messages.map((message) => ({
42
- label: `${message.subject || 'No Subject'} - ${message.from?.emailAddress?.name || message.from?.emailAddress?.address || 'Unknown Sender'}`,
43
- value: message.id || '',
44
- })),
45
- };
46
- } catch (error) {
47
- return {
48
- disabled: true,
49
- options: [],
50
- };
51
- }
52
- },
53
- }),
54
- bodyFormat: Property.StaticDropdown({
55
- displayName: 'Body Format',
56
- required: true,
57
- defaultValue: 'text',
58
- options: {
59
- disabled: false,
60
- options: [
61
- { label: 'HTML', value: 'html' },
62
- { label: 'Text', value: 'text' },
63
- ],
64
- },
65
- }),
66
- replyBody: Property.LongText({
67
- displayName: 'Reply Body',
68
- required: true,
69
- }),
70
- ccRecipients: Property.Array({
71
- displayName: 'CC Recipients',
72
- required: false,
73
- }),
74
- bccRecipients: Property.Array({
75
- displayName: 'BCC Recipients',
76
- required: false,
77
- }),
78
- attachments: Property.Array({
79
- displayName: 'Attachments',
80
- required: false,
81
- defaultValue: [],
82
- properties: {
83
- file: Property.File({
84
- displayName: 'File',
85
- required: true,
86
- }),
87
- fileName: Property.ShortText({
88
- displayName: 'File Name',
89
- required: false,
90
- }),
91
- },
92
- }),
93
- draft: Property.Checkbox({
94
- displayName: 'Create Draft',
95
- description: 'If enabled, creates draft without sending.',
96
- required: true,
97
- defaultValue: false,
98
- }),
99
- },
100
- async run(context) {
101
- const { replyBody, bodyFormat, messageId, draft } = context.propsValue;
102
- const ccRecipients = context.propsValue.ccRecipients as string[];
103
- const bccRecipients = context.propsValue.bccRecipients as string[];
104
- const attachments = context.propsValue.attachments as Array<{
105
- file: ApFile;
106
- fileName: string;
107
- }>;
108
- const mailPayload: Message = {
109
- body: {
110
- content: replyBody,
111
- contentType: bodyFormat as BodyType,
112
- },
113
- ccRecipients: ccRecipients.map((mail) => ({
114
- emailAddress: {
115
- address: mail,
116
- },
117
- })),
118
- bccRecipients: bccRecipients.map((mail) => ({
119
- emailAddress: {
120
- address: mail,
121
- },
122
- })),
123
- attachments: attachments.map((attachment) => ({
124
- '@odata.type': '#microsoft.graph.fileAttachment',
125
- name: attachment.fileName || attachment.file.filename,
126
- contentBytes: attachment.file.base64,
127
- })),
128
- };
129
- const client = outlookCommon.createClient(context.auth);
130
- try {
131
- const response: Message = await client
132
- .api(`${outlookCommon.mailboxPrefix(context.auth)}/messages/${messageId}/createReply`)
133
- .post({
134
- message: mailPayload,
135
- });
136
- const draftId = response.id;
137
- if (!draft) {
138
- await client.api(`${outlookCommon.mailboxPrefix(context.auth)}/messages/${draftId}/send`).post({});
139
- return {
140
- success: true,
141
- message: 'Reply sent successfully.',
142
- draftId: draftId,
143
- };
144
- }
145
- return {
146
- success: true,
147
- message: 'Draft created successfully.',
148
- draftId: draftId,
149
- draftLink: `https://outlook.office.com/mail/drafts/id/${draftId}`,
150
- };
151
- } catch (error) {
152
- console.error('Reply Email Error:', error);
153
- const errorMessage =
154
- error instanceof Error ? error.message : 'Unknown error';
155
- throw new Error(errorMessage);
156
- }
157
- },
158
- });
@@ -1,105 +0,0 @@
1
- import { createAction, Property } from '@agnocon/pieces-framework';
2
- import { BodyType } from '@microsoft/microsoft-graph-types';
3
- import { assertNotNullOrUndefined } from '@agnocon/pieces-framework';
4
- import { ExecutionType } from '@agnocon/pieces-framework';
5
- import { microsoftOutlookAuth } from '../common/auth';
6
- import { outlookCommon } from '../common/client';
7
-
8
- export const requestApprovalInMail = createAction({
9
- auth: microsoftOutlookAuth,
10
- name: 'request_approval_in_mail',
11
- displayName: 'Request Approval in Email',
12
- description:
13
- 'Send approval request email and then wait until the email is approved or disapproved',
14
- audience: 'both',
15
- aiMetadata: { description: 'Sends an email with a single link to a confirmation page where the recipient chooses Approve or Disapprove, then pauses the flow until they respond, resuming with the decision. Use this as a human-in-the-loop approval gate before proceeding. Not idempotent: each call sends a new email and creates a new pending waitpoint.', idempotent: false },
16
- props: {
17
- recipients: Property.ShortText({
18
- displayName: 'To Email Address',
19
- description:
20
- 'The email address of the recipient who will receive the approval request.',
21
- required: true,
22
- }),
23
- subject: Property.ShortText({
24
- displayName: 'Subject',
25
- description: 'The subject of the approval request email.',
26
- required: true,
27
- }),
28
- body: Property.LongText({
29
- displayName: 'Body',
30
- description:
31
- 'The main content of the email. You can include details about the approval request here in the html format or plain text.',
32
- required: true,
33
- }),
34
- },
35
- async run(context) {
36
- if (context.executionType === ExecutionType.BEGIN) {
37
- try {
38
- const token = context.auth.access_token;
39
-
40
- const recipients = context.propsValue.recipients as string;
41
- const { subject, body } = context.propsValue;
42
-
43
- assertNotNullOrUndefined(token, 'token');
44
- assertNotNullOrUndefined(recipients, 'recipients');
45
- assertNotNullOrUndefined(subject, 'subject');
46
- assertNotNullOrUndefined(body, 'body');
47
-
48
- const waitpoint = await context.run.createWaitpoint({
49
- type: 'WEBHOOK',
50
- });
51
- const confirmationLink = `${waitpoint.resumeUrl}/confirm`;
52
-
53
- const htmlBody = `
54
- <div>
55
- <p>${body}</p>
56
- <br />
57
- <p>
58
- <a href="${confirmationLink}" style="display: inline-block; padding: 10px 20px; background-color: #6e41e2; color: white; text-decoration: none; border-radius: 4px;">Review &amp; Respond</a>
59
- </p>
60
- </div>
61
- `;
62
-
63
- const client = outlookCommon.createClient(context.auth);
64
-
65
- const mailPayload = {
66
- subject,
67
- body: {
68
- content: htmlBody,
69
- contentType: 'html' as BodyType,
70
- },
71
- toRecipients: [
72
- {
73
- emailAddress: {
74
- address: recipients,
75
- },
76
- },
77
- ],
78
- };
79
-
80
- const sendResult = await client.api(`${outlookCommon.mailboxPrefix(context.auth)}/sendMail`).post({
81
- message: mailPayload,
82
- saveToSentItems: true,
83
- });
84
- context.run.waitForWaitpoint(waitpoint.id);
85
-
86
- return {
87
- approved: false, // default approval is false
88
- };
89
- } catch (error) {
90
- console.error(
91
- '[RequestApprovalEmail] Error during BEGIN execution:',
92
- error
93
- );
94
- throw error;
95
- }
96
- } else {
97
- const action = context.resumePayload.queryParams['action'];
98
- const approved = action === 'approve';
99
-
100
- return {
101
- approved,
102
- };
103
- }
104
- },
105
- });
@@ -1,33 +0,0 @@
1
- import { createAction } from '@agnocon/pieces-framework';
2
- import { microsoftOutlookAuth } from '../common/auth';
3
- import { outlookCommon } from '../common/client';
4
- import { draftMessageIdDropdown } from '../common/props';
5
-
6
- export const sendDraftEmailAction = createAction({
7
- auth: microsoftOutlookAuth,
8
- name: 'sendDraftEmail',
9
- displayName: 'Send Draft Email',
10
- description: 'Sends a draft email message.',
11
- audience: 'both',
12
- aiMetadata: { description: 'Sends an existing draft email (identified by draft message ID) from the Outlook mailbox. Use this to dispatch a draft previously staged by Create Draft Email or a draft reply. Not idempotent: once sent the draft no longer exists, so re-running with the same ID will fail.', idempotent: false },
13
- props: {
14
- messageId: draftMessageIdDropdown({
15
- displayName: 'Draft Email',
16
- description: 'Select the draft email message to send.',
17
- required: true,
18
- }),
19
- },
20
- async run(context) {
21
- const { messageId } = context.propsValue;
22
-
23
- const client = outlookCommon.createClient(context.auth);
24
-
25
- await client.api(`${outlookCommon.mailboxPrefix(context.auth)}/messages/${messageId}/send`).post({});
26
-
27
- return {
28
- success: true,
29
- message: 'Draft sent successfully.',
30
- messageId: messageId,
31
- };
32
- },
33
- });
@@ -1,110 +0,0 @@
1
- import { ApFile, createAction, Property } from '@agnocon/pieces-framework';
2
- import { BodyType, Message } from '@microsoft/microsoft-graph-types';
3
-
4
- import { microsoftOutlookAuth } from '../common/auth';
5
- import { outlookCommon } from '../common/client';
6
-
7
- export const sendEmailAction = createAction({
8
- auth: microsoftOutlookAuth,
9
- name: 'send-email',
10
- displayName: 'Send Email',
11
- description: 'Sends an email using Microsoft Outlook.',
12
- audience: 'both',
13
- aiMetadata: { description: 'Composes and sends a new email from the authenticated Outlook mailbox to the given recipients, with optional CC/BCC and file attachments. Use this to send a fresh message (not a reply or forward). Not idempotent: each call dispatches a new email and saves a copy to Sent Items.', idempotent: false },
14
- props: {
15
- recipients: Property.Array({
16
- displayName: 'To Email(s)',
17
- required: true,
18
- }),
19
- ccRecipients: Property.Array({
20
- displayName: 'CC Email(s)',
21
- required: false,
22
- defaultValue: [],
23
- }),
24
- bccRecipients: Property.Array({
25
- displayName: 'BCC Email(s)',
26
- required: false,
27
- defaultValue: [],
28
- }),
29
- subject: Property.ShortText({
30
- displayName: 'Subject',
31
- required: true,
32
- }),
33
- bodyFormat: Property.StaticDropdown({
34
- displayName: 'Body Format',
35
- required: true,
36
- defaultValue: 'text',
37
- options: {
38
- disabled: false,
39
- options: [
40
- { label: 'HTML', value: 'html' },
41
- { label: 'Text', value: 'text' },
42
- ],
43
- },
44
- }),
45
- body: Property.LongText({
46
- displayName: 'Body',
47
- required: true,
48
- }),
49
- attachments: Property.Array({
50
- displayName: 'Attachments',
51
- required: false,
52
- defaultValue: [],
53
- properties: {
54
- file: Property.File({
55
- displayName: 'File',
56
- required: true,
57
- }),
58
- fileName: Property.ShortText({
59
- displayName: 'File Name',
60
- required: false,
61
- }),
62
- },
63
- }),
64
- },
65
- async run(context) {
66
- const recipients = context.propsValue.recipients as string[];
67
- const ccRecipients = context.propsValue.ccRecipients as string[];
68
- const bccRecipients = context.propsValue.bccRecipients as string[];
69
- const attachments = context.propsValue.attachments as Array<{ file: ApFile; fileName: string }>;
70
-
71
- const { subject, body, bodyFormat } = context.propsValue;
72
-
73
- const mailPayload: Message = {
74
- subject,
75
- body: {
76
- content: body,
77
- contentType: bodyFormat as BodyType,
78
- },
79
- toRecipients: recipients.map((mail) => ({
80
- emailAddress: {
81
- address: mail,
82
- },
83
- })),
84
- ccRecipients: ccRecipients.map((mail) => ({
85
- emailAddress: {
86
- address: mail,
87
- },
88
- })),
89
- bccRecipients: bccRecipients.map((mail) => ({
90
- emailAddress: {
91
- address: mail,
92
- },
93
- })),
94
- attachments: attachments.map((attachment) => ({
95
- '@odata.type': '#microsoft.graph.fileAttachment',
96
- name: attachment.fileName || attachment.file.filename,
97
- contentBytes: attachment.file.base64,
98
- })),
99
- };
100
-
101
- const client = outlookCommon.createClient(context.auth);
102
-
103
- const response = await client.api(`${outlookCommon.mailboxPrefix(context.auth)}/sendMail`).post({
104
- message: mailPayload,
105
- saveToSentItems: 'true',
106
- });
107
-
108
- return response;
109
- },
110
- });
@@ -1,85 +0,0 @@
1
- import { OAuth2PropertyValue, PieceAuth, Property } from '@agnocon/pieces-framework';
2
- import { microsoftCloudProperty, microsoftScopeProperty } from './microsoft-cloud';
3
- import { outlookCommon } from './client';
4
-
5
- const authDesc = `
6
- This connection supports two access modes. Pick the matching **Grant Type** and **Access Mode** below.
7
-
8
- **Delegated (Authorization Code)** — acts as the signed-in user. Keep **Access Mode** on the Delegated option, leave **Mailbox** blank, and keep **Tenant ID** as \`common\`. If you use your own Azure app, follow the [Azure app creation guide](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app#register-an-application), set the **Redirect URI** to {{redirectUrl}} and add these **Microsoft Graph (Delegated) permissions**:
9
- - User.Read
10
- - Mail.ReadWrite
11
- - Mail.Send
12
- - Calendars.Read
13
- - offline_access
14
-
15
- **App-only (Client Credentials)** — acts as the application, with no signed-in user. Choose the **Server-to-Server (Client Credentials)** authentication method when creating the connection. Then set **Access Mode** to the App-only option for your cloud, set **Tenant ID** to your Directory (tenant) ID, and set **Mailbox** to the target user's email/UPN or object ID. You must register your own Azure app (the shared app cannot grant app-only access to your tenant). Add these **Microsoft Graph (Application) permissions** and **grant admin consent**:
16
- - Mail.ReadWrite
17
- - Mail.Send
18
-
19
- For app-only, Microsoft grants tenant-wide mailbox access by default — scope it to specific mailboxes with an [ApplicationAccessPolicy](https://learn.microsoft.com/en-us/graph/auth-limit-mailbox-access).
20
- `;
21
-
22
- export const microsoftOutlookAuth = PieceAuth.OAuth2({
23
- description: authDesc,
24
- grantType: 'both_client_credentials_and_authorization_code',
25
- props: {
26
- cloud: microsoftCloudProperty,
27
- accessMode: microsoftScopeProperty,
28
- tenant: Property.ShortText({
29
- displayName: 'Tenant ID',
30
- description:
31
- 'Use "common" for the default delegated multi-tenant flow. For app-only (Client Credentials), set this to your Directory (tenant) ID.',
32
- required: true,
33
- defaultValue: 'common',
34
- }),
35
- mailbox: Property.ShortText({
36
- displayName: 'Mailbox (App-only)',
37
- description:
38
- 'Email/UPN or user object ID of the mailbox to act on. Required for app-only (Client Credentials). Leave blank for delegated access (acts as the signed-in user).',
39
- required: false,
40
- }),
41
- },
42
- authUrl: 'https://{cloud}/{tenant}/oauth2/v2.0/authorize',
43
- tokenUrl: 'https://{cloud}/{tenant}/oauth2/v2.0/token',
44
- required: true,
45
- scope: ['{accessMode}'],
46
- prompt: 'omit',
47
- validate: async ({ auth }) => {
48
- try {
49
- const authValue = auth as OAuth2PropertyValue;
50
- const client = outlookCommon.createClient(authValue);
51
- await client
52
- .api(`${outlookCommon.mailboxPrefix(authValue)}/mailFolders/inbox`)
53
- .get();
54
- return { valid: true };
55
- } catch (error) {
56
- return { valid: false, error: describeGraphError(error) };
57
- }
58
- },
59
- });
60
-
61
- function describeGraphError(error: unknown): string {
62
- if (typeof error === 'object' && error !== null) {
63
- const parts: string[] = [];
64
- if ('statusCode' in error && error.statusCode) {
65
- parts.push(`HTTP ${String(error.statusCode)}`);
66
- }
67
- if ('code' in error && error.code) {
68
- parts.push(String(error.code));
69
- }
70
- if ('message' in error && error.message) {
71
- parts.push(String(error.message));
72
- }
73
- if ('body' in error && error.body) {
74
- const body = error.body;
75
- parts.push(typeof body === 'string' ? body.slice(0, 800) : JSON.stringify(body).slice(0, 800));
76
- }
77
- if (parts.length > 0) {
78
- return parts.join(' | ');
79
- }
80
- }
81
- if (error instanceof Error && error.message) {
82
- return error.message;
83
- }
84
- return 'Unknown error while validating the connection.';
85
- }
@@ -1,26 +0,0 @@
1
- import { OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
- import { Client } from '@microsoft/microsoft-graph-client';
3
- import { getGraphBaseUrl, getMicrosoftCloudFromAuth } from './microsoft-cloud';
4
-
5
- function createClient(auth: OAuth2PropertyValue): Client {
6
- const cloud = getMicrosoftCloudFromAuth(auth);
7
- return Client.initWithMiddleware({
8
- authProvider: {
9
- getAccessToken: () => Promise.resolve(auth.access_token),
10
- },
11
- baseUrl: getGraphBaseUrl(cloud),
12
- });
13
- }
14
-
15
- /**
16
- * Delegated connections act as the signed-in user (`/me`). App-only
17
- * (client-credentials) tokens have no user context, so they must address a
18
- * specific mailbox via `/users/{id}`. Presence of the `mailbox` prop is what
19
- * distinguishes the two, since the piece cannot read the connection's grant type.
20
- */
21
- function mailboxPrefix(auth: OAuth2PropertyValue): string {
22
- const mailbox = (auth.props?.['mailbox'] as string | undefined)?.trim();
23
- return mailbox ? `/users/${encodeURIComponent(mailbox)}` : '/me';
24
- }
25
-
26
- export const outlookCommon = { createClient, mailboxPrefix };
@@ -1,56 +0,0 @@
1
- import { OAuth2PropertyValue, Property } from '@agnocon/pieces-framework';
2
-
3
- const COMMERCIAL_LOGIN_HOST = 'login.microsoftonline.com';
4
- const GOV_LOGIN_HOST = 'login.microsoftonline.us';
5
-
6
- const DELEGATED_SCOPE = 'Mail.ReadWrite Mail.Send Calendars.Read offline_access User.Read openid email profile';
7
- const APP_ONLY_COMMERCIAL_SCOPE = 'https://graph.microsoft.com/.default';
8
- const APP_ONLY_GOV_SCOPE = 'https://graph.microsoft.us/.default';
9
-
10
- const GRAPH_BASE_URLS: Record<string, string> = {
11
- [COMMERCIAL_LOGIN_HOST]: 'https://graph.microsoft.com',
12
- [GOV_LOGIN_HOST]: 'https://graph.microsoft.us',
13
- };
14
-
15
- export const microsoftCloudProperty = Property.StaticDropdown({
16
- displayName: 'Cloud Environment',
17
- description: 'Select your Microsoft cloud environment.',
18
- required: true,
19
- defaultValue: COMMERCIAL_LOGIN_HOST,
20
- options: {
21
- disabled: false,
22
- options: [
23
- { label: 'Commercial (Global)', value: COMMERCIAL_LOGIN_HOST },
24
- { label: 'US Government (GCC High)', value: GOV_LOGIN_HOST },
25
- ],
26
- },
27
- });
28
-
29
- export const microsoftScopeProperty = Property.StaticDropdown({
30
- displayName: 'Access Mode',
31
- description:
32
- 'Pick the option matching your Grant Type. Use a Delegated option with the Authorization Code grant (acts as the signed-in user). Use an App-only option with the Client Credentials grant (acts as the application — also set Tenant ID and Mailbox), choosing the one that matches your Cloud Environment.',
33
- required: true,
34
- defaultValue: DELEGATED_SCOPE,
35
- options: {
36
- disabled: false,
37
- options: [
38
- { label: 'Delegated — Commercial (Global)', value: DELEGATED_SCOPE },
39
- { label: 'App-only — Commercial (Global)', value: APP_ONLY_COMMERCIAL_SCOPE },
40
- { label: 'App-only — US Government (GCC High)', value: APP_ONLY_GOV_SCOPE },
41
- ],
42
- },
43
- });
44
-
45
- function resolveCloudHost(cloudLoginHost: string | undefined | null): string {
46
- return cloudLoginHost ?? COMMERCIAL_LOGIN_HOST;
47
- }
48
-
49
- export function getMicrosoftCloudFromAuth(auth: OAuth2PropertyValue): string {
50
- return resolveCloudHost(auth.props?.['cloud'] as string | undefined);
51
- }
52
-
53
- export function getGraphBaseUrl(cloudLoginHost: string | undefined | null): string {
54
- const host = resolveCloudHost(cloudLoginHost);
55
- return GRAPH_BASE_URLS[host] ?? GRAPH_BASE_URLS[COMMERCIAL_LOGIN_HOST];
56
- }