@activepieces/piece-gmail 0.10.1 → 0.11.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.
Files changed (35) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +20 -1
  3. package/src/index.js.map +1 -1
  4. package/src/lib/actions/create-draft-reply-action.d.ts +10 -0
  5. package/src/lib/actions/create-draft-reply-action.js +262 -0
  6. package/src/lib/actions/create-draft-reply-action.js.map +1 -0
  7. package/src/lib/actions/get-mail-action.d.ts +1 -3
  8. package/src/lib/actions/get-mail-action.js +20 -27
  9. package/src/lib/actions/get-mail-action.js.map +1 -1
  10. package/src/lib/actions/reply-to-email-action.d.ts +9 -0
  11. package/src/lib/actions/reply-to-email-action.js +195 -0
  12. package/src/lib/actions/reply-to-email-action.js.map +1 -0
  13. package/src/lib/actions/request-approval-in-email.d.ts +11 -0
  14. package/src/lib/actions/request-approval-in-email.js +176 -0
  15. package/src/lib/actions/request-approval-in-email.js.map +1 -0
  16. package/src/lib/actions/search-email-action.d.ts +9 -2
  17. package/src/lib/actions/search-email-action.js +162 -14
  18. package/src/lib/actions/search-email-action.js.map +1 -1
  19. package/src/lib/common/data.d.ts +8 -0
  20. package/src/lib/common/data.js +37 -0
  21. package/src/lib/common/data.js.map +1 -1
  22. package/src/lib/common/props.d.ts +2 -0
  23. package/src/lib/common/props.js +153 -0
  24. package/src/lib/common/props.js.map +1 -1
  25. package/src/lib/triggers/new-attachment.d.ts +171 -0
  26. package/src/lib/triggers/new-attachment.js +128 -0
  27. package/src/lib/triggers/new-attachment.js.map +1 -0
  28. package/src/lib/triggers/new-conversation.d.ts +46 -0
  29. package/src/lib/triggers/new-conversation.js +310 -0
  30. package/src/lib/triggers/new-conversation.js.map +1 -0
  31. package/src/lib/triggers/new-email.js +1 -9
  32. package/src/lib/triggers/new-email.js.map +1 -1
  33. package/src/lib/triggers/new-label.d.ts +2 -0
  34. package/src/lib/triggers/new-label.js +79 -0
  35. package/src/lib/triggers/new-label.js.map +1 -0
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gmailReplyToEmailAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
7
+ const mail_composer_1 = tslib_1.__importDefault(require("nodemailer/lib/mail-composer"));
8
+ const __1 = require("../../");
9
+ const googleapis_1 = require("googleapis");
10
+ const googleapis_common_1 = require("googleapis-common");
11
+ const props_1 = require("../common/props");
12
+ exports.gmailReplyToEmailAction = (0, pieces_framework_1.createAction)({
13
+ auth: __1.gmailAuth,
14
+ name: 'reply_to_email',
15
+ displayName: 'Reply to Email',
16
+ description: 'Reply to an existing email.',
17
+ props: {
18
+ message_id: props_1.GmailProps.message,
19
+ reply_type: pieces_framework_1.Property.StaticDropdown({
20
+ displayName: 'Reply Type',
21
+ description: 'Choose whether to reply to sender only or to all recipients',
22
+ required: true,
23
+ defaultValue: 'reply',
24
+ options: {
25
+ disabled: false,
26
+ options: [
27
+ {
28
+ label: 'Reply (to sender only)',
29
+ value: 'reply',
30
+ },
31
+ {
32
+ label: 'Reply All (to all recipients)',
33
+ value: 'reply_all',
34
+ },
35
+ ],
36
+ },
37
+ }),
38
+ body_type: pieces_framework_1.Property.StaticDropdown({
39
+ displayName: 'Body Type',
40
+ required: true,
41
+ defaultValue: 'plain_text',
42
+ options: {
43
+ disabled: false,
44
+ options: [
45
+ {
46
+ label: 'Plain text',
47
+ value: 'plain_text',
48
+ },
49
+ {
50
+ label: 'HTML',
51
+ value: 'html',
52
+ },
53
+ ],
54
+ },
55
+ }),
56
+ body: pieces_framework_1.Property.LongText({
57
+ displayName: 'Reply Body',
58
+ description: 'Your reply message content',
59
+ required: true,
60
+ }),
61
+ sender_name: pieces_framework_1.Property.ShortText({
62
+ displayName: 'Sender Name',
63
+ description: 'Optional sender name to display',
64
+ required: false,
65
+ }),
66
+ attachment: pieces_framework_1.Property.File({
67
+ displayName: 'Attachment',
68
+ description: 'Optional file to attach to your reply',
69
+ required: false,
70
+ }),
71
+ attachment_name: pieces_framework_1.Property.ShortText({
72
+ displayName: 'Attachment Name',
73
+ description: 'Custom name for the attachment',
74
+ required: false,
75
+ }),
76
+ },
77
+ run(context) {
78
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
79
+ var _a;
80
+ const authClient = new googleapis_common_1.OAuth2Client();
81
+ authClient.setCredentials(context.auth);
82
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
83
+ const originalMessage = yield gmail.users.messages.get({
84
+ userId: 'me',
85
+ id: context.propsValue.message_id,
86
+ format: 'full',
87
+ });
88
+ if (!originalMessage.data || !originalMessage.data.payload) {
89
+ throw new Error('Could not fetch original message details');
90
+ }
91
+ const headers = originalMessage.data.payload.headers || [];
92
+ const headerMap = headers.reduce((acc, header) => {
93
+ if (header.name && header.value) {
94
+ acc[header.name.toLowerCase()] = header.value;
95
+ }
96
+ return acc;
97
+ }, {});
98
+ const originalSubject = headerMap['subject'] || '';
99
+ const originalFrom = headerMap['from'] || '';
100
+ const originalTo = headerMap['to'] || '';
101
+ const originalCc = headerMap['cc'] || '';
102
+ const originalReplyTo = headerMap['reply-to'] || '';
103
+ const originalMessageId = headerMap['message-id'] || '';
104
+ const originalReferences = headerMap['references'] || '';
105
+ const toRecipients = [];
106
+ const ccRecipients = [];
107
+ if (context.propsValue.reply_type === 'reply_all') {
108
+ const senderEmail = originalReplyTo || originalFrom;
109
+ if (senderEmail) {
110
+ toRecipients.push(senderEmail);
111
+ }
112
+ const currentUserEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
113
+ if (originalTo) {
114
+ const toEmails = originalTo.split(',').map((email) => email.trim());
115
+ toRecipients.push(...toEmails.filter((email) => !email.includes(currentUserEmail || '')));
116
+ }
117
+ if (originalCc) {
118
+ const ccEmails = originalCc.split(',').map((email) => email.trim());
119
+ ccRecipients.push(...ccEmails.filter((email) => !email.includes(currentUserEmail || '')));
120
+ }
121
+ }
122
+ else {
123
+ const senderEmail = originalReplyTo || originalFrom;
124
+ if (senderEmail) {
125
+ toRecipients.push(senderEmail);
126
+ }
127
+ }
128
+ let replySubject = originalSubject;
129
+ if (!replySubject.toLowerCase().startsWith('re:')) {
130
+ replySubject = `Re: ${replySubject}`;
131
+ }
132
+ let referencesHeader = originalMessageId;
133
+ if (originalReferences) {
134
+ referencesHeader = `${originalReferences} ${originalMessageId}`;
135
+ }
136
+ const senderEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
137
+ const subjectBase64 = Buffer.from(replySubject).toString('base64');
138
+ const mailOptions = {
139
+ to: toRecipients.join(', '),
140
+ cc: ccRecipients.length > 0 ? ccRecipients.join(', ') : undefined,
141
+ subject: `=?UTF-8?B?${subjectBase64}?=`,
142
+ text: context.propsValue.body_type === 'plain_text'
143
+ ? context.propsValue.body
144
+ : undefined,
145
+ html: context.propsValue.body_type === 'html'
146
+ ? context.propsValue.body
147
+ : undefined,
148
+ attachments: [],
149
+ headers: [
150
+ {
151
+ key: 'In-Reply-To',
152
+ value: originalMessageId,
153
+ },
154
+ {
155
+ key: 'References',
156
+ value: referencesHeader,
157
+ },
158
+ ],
159
+ };
160
+ if (senderEmail) {
161
+ mailOptions.from = context.propsValue.sender_name
162
+ ? `${context.propsValue.sender_name} <${senderEmail}>`
163
+ : senderEmail;
164
+ }
165
+ if (context.propsValue.attachment) {
166
+ const lookupResult = mime_types_1.default.lookup(context.propsValue.attachment.extension || '');
167
+ const attachmentOption = [
168
+ {
169
+ filename: (_a = context.propsValue.attachment_name) !== null && _a !== void 0 ? _a : context.propsValue.attachment.filename,
170
+ content: context.propsValue.attachment.base64,
171
+ contentType: lookupResult || undefined,
172
+ encoding: 'base64',
173
+ },
174
+ ];
175
+ mailOptions.attachments = attachmentOption;
176
+ }
177
+ const mail = new mail_composer_1.default(mailOptions).compile();
178
+ mail.keepBcc = true;
179
+ const mailBody = yield mail.build();
180
+ const encodedPayload = Buffer.from(mailBody)
181
+ .toString('base64')
182
+ .replace(/\+/g, '-')
183
+ .replace(/\//g, '_');
184
+ const response = yield gmail.users.messages.send({
185
+ userId: 'me',
186
+ requestBody: {
187
+ threadId: originalMessage.data.threadId || undefined,
188
+ raw: encodedPayload,
189
+ },
190
+ });
191
+ return response.data;
192
+ });
193
+ },
194
+ });
195
+ //# sourceMappingURL=reply-to-email-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reply-to-email-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/reply-to-email-action.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,oEAA8B;AAC9B,yFAAwD;AAExD,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AACjD,2CAA6C;AAEhC,QAAA,uBAAuB,GAAG,IAAA,+BAAY,EAAC;IAClD,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,6BAA6B;IAC1C,KAAK,EAAE;QACL,UAAU,EAAE,kBAAU,CAAC,OAAO;QAC9B,UAAU,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAClC,WAAW,EAAE,YAAY;YACzB,WAAW,EACT,6DAA6D;YAC/D,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,OAAO;YACrB,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,wBAAwB;wBAC/B,KAAK,EAAE,OAAO;qBACf;oBACD;wBACE,KAAK,EAAE,+BAA+B;wBACtC,KAAK,EAAE,WAAW;qBACnB;iBACF;aACF;SACF,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACjC,WAAW,EAAE,WAAW;YACxB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,YAAY;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C,QAAQ,IAAI,SAAS;oBACpD,GAAG,EAAE,cAAc;iBACpB;aACF,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const requestApprovalInEmail: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
2
+ receiver: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ cc: import("@activepieces/pieces-framework").ArrayProperty<false>;
4
+ bcc: import("@activepieces/pieces-framework").ArrayProperty<false>;
5
+ subject: import("@activepieces/pieces-framework").ShortTextProperty<true>;
6
+ body: import("@activepieces/pieces-framework").ShortTextProperty<true>;
7
+ reply_to: import("@activepieces/pieces-framework").ArrayProperty<false>;
8
+ sender_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
9
+ from: import("@activepieces/pieces-framework").ShortTextProperty<false>;
10
+ in_reply_to: import("@activepieces/pieces-framework").ShortTextProperty<false>;
11
+ }>;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestApprovalInEmail = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const __1 = require("../..");
7
+ const googleapis_1 = require("googleapis");
8
+ const googleapis_common_1 = require("googleapis-common");
9
+ const mail_composer_1 = tslib_1.__importDefault(require("nodemailer/lib/mail-composer"));
10
+ const shared_1 = require("@activepieces/shared");
11
+ exports.requestApprovalInEmail = (0, pieces_framework_1.createAction)({
12
+ auth: __1.gmailAuth,
13
+ name: 'request_approval_in_mail',
14
+ displayName: 'Request Approval in Email',
15
+ description: 'Send approval request email and then wait until the email is approved or disapproved',
16
+ props: {
17
+ receiver: pieces_framework_1.Property.ShortText({
18
+ displayName: 'Receiver Email (To)',
19
+ description: 'The email address of the recipient who will receive the approval request.',
20
+ required: true,
21
+ }),
22
+ cc: pieces_framework_1.Property.Array({
23
+ displayName: 'CC Email',
24
+ description: 'The email addresses of the recipients who will receive a carbon copy of the approval request.',
25
+ required: false,
26
+ }),
27
+ bcc: pieces_framework_1.Property.Array({
28
+ displayName: 'BCC Email',
29
+ description: 'The email addresses of the recipients who will receive a blind carbon copy of the approval request.',
30
+ required: false,
31
+ }),
32
+ subject: pieces_framework_1.Property.ShortText({
33
+ displayName: 'Subject',
34
+ description: 'The subject of the approval request email.',
35
+ required: true,
36
+ }),
37
+ body: pieces_framework_1.Property.ShortText({
38
+ displayName: 'Body',
39
+ description: 'Body for the email you want to send',
40
+ required: true,
41
+ }),
42
+ reply_to: pieces_framework_1.Property.Array({
43
+ displayName: 'Reply-To Email',
44
+ description: 'Email address to set as the "Reply-To" header',
45
+ required: false,
46
+ }),
47
+ sender_name: pieces_framework_1.Property.ShortText({
48
+ displayName: 'Sender Name',
49
+ required: false,
50
+ }),
51
+ from: pieces_framework_1.Property.ShortText({
52
+ displayName: 'Sender Email',
53
+ description: "The address must be listed in your GMail account's settings",
54
+ required: false,
55
+ }),
56
+ in_reply_to: pieces_framework_1.Property.ShortText({
57
+ displayName: 'In reply to',
58
+ description: 'Reply to this Message-ID',
59
+ required: false,
60
+ }),
61
+ },
62
+ run(context) {
63
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
64
+ var _a, _b, _c, _d;
65
+ if (context.executionType === shared_1.ExecutionType.BEGIN) {
66
+ try {
67
+ const token = context.auth.access_token;
68
+ const { subject, body } = context.propsValue;
69
+ (0, shared_1.assertNotNullOrUndefined)(token, 'token');
70
+ (0, shared_1.assertNotNullOrUndefined)(context.propsValue.receiver, 'receiver');
71
+ (0, shared_1.assertNotNullOrUndefined)(subject, 'subject');
72
+ (0, shared_1.assertNotNullOrUndefined)(body, 'body');
73
+ const approvalLink = context.generateResumeUrl({
74
+ queryParams: { action: 'approve' },
75
+ });
76
+ const disapprovalLink = context.generateResumeUrl({
77
+ queryParams: { action: 'disapprove' },
78
+ });
79
+ const htmlBody = `
80
+ <div>
81
+ <p>${body}</p>
82
+ <br />
83
+ <p>
84
+ <a href="${approvalLink}" style="display: inline-block; padding: 10px 20px; margin-right: 10px; background-color: #2acc50; color: white; text-decoration: none; border-radius: 4px;">Approve</a>
85
+ <a href="${disapprovalLink}" style="display: inline-block; padding: 10px 20px; background-color: #e4172b; color: white; text-decoration: none; border-radius: 4px;">Disapprove</a>
86
+ </p>
87
+ </div>
88
+ `;
89
+ const authClient = new googleapis_common_1.OAuth2Client();
90
+ authClient.setCredentials(context.auth);
91
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
92
+ const subjectBase64 = Buffer.from(context.propsValue['subject']).toString('base64');
93
+ const replyTo = (_a = context.propsValue['reply_to']) === null || _a === void 0 ? void 0 : _a.filter((email) => email !== '');
94
+ const receiverEmail = context.propsValue.receiver;
95
+ const cc = (_b = context.propsValue['cc']) === null || _b === void 0 ? void 0 : _b.filter((email) => email !== '');
96
+ const bcc = (_c = context.propsValue['bcc']) === null || _c === void 0 ? void 0 : _c.filter((email) => email !== '');
97
+ const mailOptions = {
98
+ to: receiverEmail,
99
+ cc: cc ? cc.join(', ') : undefined,
100
+ bcc: bcc ? bcc.join(', ') : undefined,
101
+ subject: `=?UTF-8?B?${subjectBase64}?=`,
102
+ replyTo: replyTo ? replyTo.join(', ') : '',
103
+ // text:
104
+ // context.propsValue.body_type === 'plain_text'
105
+ // ? context.propsValue['body']
106
+ // : undefined,
107
+ html: htmlBody,
108
+ attachments: [],
109
+ };
110
+ const senderEmail = context.propsValue.from ||
111
+ (yield googleapis_1.google
112
+ .oauth2({ version: 'v2', auth: authClient })
113
+ .userinfo.get()).data.email;
114
+ if (senderEmail) {
115
+ mailOptions.from = context.propsValue.sender_name
116
+ ? `${context.propsValue['sender_name']} <${senderEmail}>`
117
+ : senderEmail;
118
+ }
119
+ let threadId = undefined;
120
+ if (context.propsValue.in_reply_to) {
121
+ mailOptions.headers = [
122
+ {
123
+ key: 'References',
124
+ value: context.propsValue.in_reply_to,
125
+ },
126
+ {
127
+ key: 'In-Reply-To',
128
+ value: context.propsValue.in_reply_to,
129
+ },
130
+ ];
131
+ const messages = yield gmail.users.messages.list({
132
+ userId: 'me',
133
+ q: `Rfc822msgid:${context.propsValue.in_reply_to}`,
134
+ });
135
+ threadId = (_d = messages.data.messages) === null || _d === void 0 ? void 0 : _d[0].threadId;
136
+ }
137
+ const mail = new mail_composer_1.default(mailOptions).compile();
138
+ mail.keepBcc = true;
139
+ const mailBody = yield mail.build();
140
+ const encodedPayload = Buffer.from(mailBody)
141
+ .toString('base64')
142
+ .replace(/\+/g, '-')
143
+ .replace(/\//g, '_');
144
+ yield gmail.users.messages.send({
145
+ userId: 'me',
146
+ requestBody: {
147
+ threadId,
148
+ raw: encodedPayload,
149
+ },
150
+ });
151
+ context.run.pause({
152
+ pauseMetadata: {
153
+ type: shared_1.PauseType.WEBHOOK,
154
+ response: {},
155
+ },
156
+ });
157
+ return {
158
+ approved: false, // default approval is false
159
+ };
160
+ }
161
+ catch (error) {
162
+ console.error('[RequestApprovalEmail] Error during BEGIN execution:', error);
163
+ throw error;
164
+ }
165
+ }
166
+ else {
167
+ const action = context.resumePayload.queryParams['action'];
168
+ const approved = action === 'approve';
169
+ return {
170
+ approved,
171
+ };
172
+ }
173
+ });
174
+ },
175
+ });
176
+ //# sourceMappingURL=request-approval-in-email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-approval-in-email.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/request-approval-in-email.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,6BAAkC;AAClC,2CAAoC;AACpC,yDAAiD;AACjD,yFAAwD;AAExD,iDAI8B;AAEjB,QAAA,sBAAsB,GAAG,IAAA,+BAAY,EAAC;IACjD,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,0BAA0B;IAChC,WAAW,EAAE,2BAA2B;IACxC,WAAW,EACT,sF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ACZ,WAAW,EAAE;4BACX,QAAQ;4BACR,GAAG,EAAE,cAAc;yBACpB;qBACF,CAAC,CAAC;oBACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;wBAChB,aAAa,EAAE;4BACb,IAAI,EAAE,kBAAS,CAAC,OAAO;4BACvB,QAAQ,EAAE,EAAE;yBACb;qBACF,CAAC,CAAC;oBAEH,OAAO;wBACL,QAAQ,EAAE,KAAK,EAAE,4BAA4B;qBAC9C,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CACX,sDAAsD,EACtD,KAAK,CACN,CAAC;oBACF,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAC3D,MAAM,QAAQ,GAAG,MAAM,KAAK,SAAS,CAAC;gBAEtC,OAAO;oBACL,QAAQ;iBACT,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,8 +1,15 @@
1
1
  import { GmailLabel } from '../common/models';
2
- export declare const gmailSearchMail: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
3
- subject: import("@activepieces/pieces-framework").ShortTextProperty<false>;
2
+ export declare const gmailSearchMailAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
4
3
  from: import("@activepieces/pieces-framework").ShortTextProperty<false>;
5
4
  to: import("@activepieces/pieces-framework").ShortTextProperty<false>;
5
+ subject: import("@activepieces/pieces-framework").ShortTextProperty<false>;
6
+ content: import("@activepieces/pieces-framework").ShortTextProperty<false>;
7
+ has_attachment: import("@activepieces/pieces-framework").CheckboxProperty<false>;
8
+ attachment_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
6
9
  label: import("@activepieces/pieces-framework").DropdownProperty<GmailLabel, false, import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>>;
7
10
  category: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
11
+ after_date: import("@activepieces/pieces-framework").DateTimeProperty<false>;
12
+ before_date: import("@activepieces/pieces-framework").DateTimeProperty<false>;
13
+ include_spam_trash: import("@activepieces/pieces-framework").CheckboxProperty<false>;
14
+ max_results: import("@activepieces/pieces-framework").NumberProperty<false>;
8
15
  }>;
@@ -1,32 +1,180 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gmailSearchMail = void 0;
3
+ exports.gmailSearchMailAction = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const __1 = require("../../");
7
+ const googleapis_1 = require("googleapis");
8
+ const googleapis_common_1 = require("googleapis-common");
6
9
  const data_1 = require("../common/data");
7
10
  const props_1 = require("../common/props");
8
- const __1 = require("../../");
9
- exports.gmailSearchMail = (0, pieces_framework_1.createAction)({
11
+ exports.gmailSearchMailAction = (0, pieces_framework_1.createAction)({
10
12
  auth: __1.gmailAuth,
11
13
  name: 'gmail_search_mail',
12
- description: 'Find for an email in your Gmail account',
13
14
  displayName: 'Find Email',
15
+ description: 'Find emails using advanced search criteria.',
14
16
  props: {
15
- subject: props_1.GmailProps.subject,
16
17
  from: props_1.GmailProps.from,
17
18
  to: props_1.GmailProps.to,
19
+ subject: props_1.GmailProps.subject,
20
+ content: pieces_framework_1.Property.ShortText({
21
+ displayName: 'Email Content',
22
+ description: 'Search for specific text within email body',
23
+ required: false,
24
+ }),
25
+ has_attachment: pieces_framework_1.Property.Checkbox({
26
+ displayName: 'Has Attachment',
27
+ description: 'Only find emails with attachments',
28
+ required: false,
29
+ defaultValue: false,
30
+ }),
31
+ attachment_name: pieces_framework_1.Property.ShortText({
32
+ displayName: 'Attachment Name',
33
+ description: 'Search for emails with specific attachment filename',
34
+ required: false,
35
+ }),
18
36
  label: props_1.GmailProps.label,
19
37
  category: props_1.GmailProps.category,
38
+ after_date: pieces_framework_1.Property.DateTime({
39
+ displayName: 'After Date',
40
+ description: 'Find emails sent after this date',
41
+ required: false,
42
+ }),
43
+ before_date: pieces_framework_1.Property.DateTime({
44
+ displayName: 'Before Date',
45
+ description: 'Find emails sent before this date',
46
+ required: false,
47
+ }),
48
+ include_spam_trash: pieces_framework_1.Property.Checkbox({
49
+ displayName: 'Include Spam & Trash',
50
+ description: 'Include emails from Spam and Trash folders in search results',
51
+ required: false,
52
+ defaultValue: false,
53
+ }),
54
+ max_results: pieces_framework_1.Property.Number({
55
+ displayName: 'Max Results',
56
+ description: 'Maximum number of emails to return (1-500)',
57
+ required: false,
58
+ defaultValue: 10,
59
+ }),
20
60
  },
21
- run: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue: { from, to, subject, label, category } }) {
22
- return yield data_1.GmailRequests.searchMail({
23
- access_token: auth.access_token,
24
- from: from,
25
- to: to,
26
- subject: subject,
27
- label: label,
28
- category: category,
61
+ run(context) {
62
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
+ var _a, _b, _c, _d, _e, _f, _g;
64
+ const authClient = new googleapis_common_1.OAuth2Client();
65
+ authClient.setCredentials(context.auth);
66
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
67
+ const queryParts = [];
68
+ if ((_a = context.propsValue.from) === null || _a === void 0 ? void 0 : _a.trim()) {
69
+ queryParts.push(`from:(${context.propsValue.from.trim()})`);
70
+ }
71
+ if ((_b = context.propsValue.to) === null || _b === void 0 ? void 0 : _b.trim()) {
72
+ queryParts.push(`to:(${context.propsValue.to.trim()})`);
73
+ }
74
+ if ((_c = context.propsValue.subject) === null || _c === void 0 ? void 0 : _c.trim()) {
75
+ queryParts.push(`subject:(${context.propsValue.subject.trim()})`);
76
+ }
77
+ if ((_d = context.propsValue.content) === null || _d === void 0 ? void 0 : _d.trim()) {
78
+ queryParts.push(`"${context.propsValue.content.trim()}"`);
79
+ }
80
+ if (context.propsValue.has_attachment) {
81
+ queryParts.push('has:attachment');
82
+ }
83
+ if ((_e = context.propsValue.attachment_name) === null || _e === void 0 ? void 0 : _e.trim()) {
84
+ queryParts.push(`filename:(${context.propsValue.attachment_name.trim()})`);
85
+ }
86
+ if (context.propsValue.label) {
87
+ const label = context.propsValue.label;
88
+ queryParts.push(`label:${label.name}`);
89
+ }
90
+ if ((_f = context.propsValue.category) === null || _f === void 0 ? void 0 : _f.trim()) {
91
+ queryParts.push(`category:${context.propsValue.category.trim()}`);
92
+ }
93
+ if (context.propsValue.after_date) {
94
+ const afterDate = new Date(context.propsValue.after_date);
95
+ const afterDateStr = afterDate
96
+ .toISOString()
97
+ .split('T')[0]
98
+ .replace(/-/g, '/');
99
+ queryParts.push(`after:${afterDateStr}`);
100
+ }
101
+ if (context.propsValue.before_date) {
102
+ const beforeDate = new Date(context.propsValue.before_date);
103
+ const beforeDateStr = beforeDate
104
+ .toISOString()
105
+ .split('T')[0]
106
+ .replace(/-/g, '/');
107
+ queryParts.push(`before:${beforeDateStr}`);
108
+ }
109
+ const searchQuery = queryParts.join(' ');
110
+ if (!searchQuery.trim()) {
111
+ throw new Error('Please provide at least one search criterion');
112
+ }
113
+ const maxResults = Math.min(Math.max(context.propsValue.max_results || 10, 1), 500);
114
+ try {
115
+ const searchResponse = yield gmail.users.messages.list({
116
+ userId: 'me',
117
+ q: searchQuery,
118
+ maxResults: maxResults,
119
+ includeSpamTrash: context.propsValue.include_spam_trash,
120
+ });
121
+ const messages = searchResponse.data.messages || [];
122
+ if (messages.length === 0) {
123
+ return {
124
+ found: false,
125
+ results: {
126
+ messages: [],
127
+ count: 0,
128
+ },
129
+ };
130
+ }
131
+ const detailedMessages = yield Promise.all(messages.map((message) => tslib_1.__awaiter(this, void 0, void 0, function* () {
132
+ try {
133
+ const rawMailResponse = yield gmail.users.messages.get({
134
+ userId: 'me',
135
+ id: message.id,
136
+ format: 'raw',
137
+ });
138
+ const parsedMailResponse = yield (0, data_1.parseStream)(Buffer.from(rawMailResponse.data.raw, 'base64').toString('utf-8'));
139
+ return Object.assign(Object.assign({ id: message.id }, parsedMailResponse), { attachments: yield (0, data_1.convertAttachment)(parsedMailResponse.attachments, context.files) });
140
+ }
141
+ catch (error) {
142
+ console.error(`Failed to get details for message ${message.id}:`, error);
143
+ return {
144
+ id: message.id,
145
+ threadId: message.threadId,
146
+ error: 'Failed to retrieve message details',
147
+ };
148
+ }
149
+ })));
150
+ return {
151
+ found: true,
152
+ results: {
153
+ messages: detailedMessages,
154
+ count: detailedMessages.length,
155
+ },
156
+ };
157
+ }
158
+ catch (error) {
159
+ // Enhanced error handling
160
+ if (error.code === 400) {
161
+ if ((_g = error.message) === null || _g === void 0 ? void 0 : _g.includes('Invalid query')) {
162
+ throw new Error(`Invalid search query: "${searchQuery}". Please check your search syntax.`);
163
+ }
164
+ throw new Error(`Invalid search request: ${error.message}`);
165
+ }
166
+ else if (error.code === 403) {
167
+ throw new Error('Insufficient permissions to search emails. Ensure the gmail.readonly scope is granted.');
168
+ }
169
+ else if (error.code === 429) {
170
+ throw new Error('Gmail API rate limit exceeded. Please try again later.');
171
+ }
172
+ else if (error.code === 500) {
173
+ throw new Error('Gmail API server error. Please try again later.');
174
+ }
175
+ throw new Error(`Failed to search emails: ${error.message}`);
176
+ }
29
177
  });
30
- }),
178
+ },
31
179
  });
32
180
  //# sourceMappingURL=search-email-action.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"search-email-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/search-email-action.ts"],"names":[],"mappings":";;;;AAAA,qEAA8D;AAC9D,yCAA+C;AAE/C,2CAA6C;AAC7C,8BAAmC;AAEtB,QAAA,eAAe,GAAG,IAAA,+BAAY,EAAC;IAC1C,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,mBAAmB;IACzB,WAAW,EAAE,yCAAyC;IACtD,WAAW,EAAE,YAAY;IACzB,KAAK,EAAE;QACL,OAAO,EAAE,kBAAU,CAAC,OAAO;QAC3B,IAAI,EAAE,kBAAU,CAAC,IAAI;QACrB,EAAE,EAAE,kBAAU,CAAC,EAAE;QACjB,KAAK,EAAE,kBAAU,CAAC,KAAK;QACvB,QAAQ,EAAE,kBAAU,CAAC,QAAQ;KAC9B;IACD,GAAG,EAAE,KAAqE,EAAE,oDAAhE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACtE,OAAA,MAAM,oBAAa,CAAC,UAAU,CAAC;YAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,IAAI,EAAE,IAAc;YACpB,EAAE,EAAE,EAAY;YAChB,OAAO,EAAE,OAAiB;YAC1B,KAAK,EAAE,KAAmB;YAC1B,QAAQ,EAAE,QAAkB;SAC7B,CAAC,CAAA;MAAA;CACL,CAAC,CAAC"}
1
+ {"version":3,"file":"search-email-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/search-email-action.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AACjD,yCAAgE;AAChE,2CAA6C;AAGhC,QAAA,qBAAqB,GAAG,IAAA,+BAAY,EAAC;IAChD,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,mBAAmB;IACzB,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,6CAA6C;IAC1D,KAAK,EAAE;QACL,IAAI,EAAE,kBAAU,CAAC,IAAI;QACrB,EAAE,EAAE,kBAAU,CAAC,EAAE;QACjB,OAAO,EAAE,kBAAU,CAAC,OAAO;QAC3B,OAAO,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC1B,WAAW,EAAE,eAAe;YAC5B,WAAW,EAAE,4CAA4C;YACzD,QAAQ,EAAE,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