Skip to content

Commit bbca900

Browse files
authored
Gmail - Usability Audit (#13724)
* updates * pnpm-lock.yaml * create new topic names * pnpm-lock.yaml * updates to reduce latency * verify-client-id * updates * remove console.log * update alert props * update topicType label * updates * parse attachments
1 parent 5f03279 commit bbca900

File tree

45 files changed

+1560
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1560
-555
lines changed
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
import common from "../../common/verify-client-id.mjs";
1+
import gmail from "../../gmail.app.mjs";
22

33
export default {
4-
...common,
54
key: "gmail-add-label-to-email",
65
name: "Add Label to Email",
7-
description: "Add a label to an email message. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
8-
version: "0.0.3",
6+
description: "Add label(s) to an email message. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
7+
version: "0.0.4",
98
type: "action",
109
props: {
11-
...common.props,
10+
gmail,
1211
message: {
1312
propDefinition: [
14-
common.props.gmail,
13+
gmail,
1514
"message",
1615
],
1716
},
18-
label: {
17+
addLabelIds: {
1918
propDefinition: [
20-
common.props.gmail,
19+
gmail,
2120
"label",
2221
],
23-
withLabel: true,
22+
type: "string[]",
23+
label: "Labels",
2424
},
2525
},
2626
async run({ $ }) {
27-
const response = await this.gmail.addLabelToEmail({
28-
message: this.message,
29-
label: this.label.value,
27+
const {
28+
gmail,
29+
message,
30+
addLabelIds = [],
31+
} = this;
32+
33+
const response = await gmail.updateLabels({
34+
message,
35+
addLabelIds,
3036
});
31-
$.export("$summary", `Successfully added ${this.label.label} label to email`);
37+
38+
$.export("$summary", `Successfully added ${addLabelIds.length} label(s)`);
3239
return response;
3340
},
3441
};

components/gmail/actions/create-draft/create-draft.mjs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,58 @@
1-
import common from "../../common/verify-client-id.mjs";
1+
import gmail from "../../gmail.app.mjs";
22

33
export default {
4-
...common,
54
key: "gmail-create-draft",
65
name: "Create Draft",
76
description: "Create a draft from your Google Workspace email account. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.drafts/create)",
8-
version: "0.0.1",
7+
version: "0.0.2",
98
type: "action",
109
props: {
11-
...common.props,
10+
gmail,
1211
to: {
1312
propDefinition: [
14-
common.props.gmail,
13+
gmail,
1514
"to",
1615
],
1716
},
1817
cc: {
1918
propDefinition: [
20-
common.props.gmail,
19+
gmail,
2120
"cc",
2221
],
2322
},
2423
bcc: {
2524
propDefinition: [
26-
common.props.gmail,
25+
gmail,
2726
"bcc",
2827
],
2928
},
30-
fromName: {
31-
propDefinition: [
32-
common.props.gmail,
33-
"fromName",
34-
],
35-
},
36-
replyTo: {
37-
propDefinition: [
38-
common.props.gmail,
39-
"replyTo",
40-
],
41-
},
4229
subject: {
4330
propDefinition: [
44-
common.props.gmail,
31+
gmail,
4532
"subject",
4633
],
4734
},
4835
body: {
4936
propDefinition: [
50-
common.props.gmail,
37+
gmail,
5138
"body",
5239
],
5340
},
5441
bodyType: {
5542
propDefinition: [
56-
common.props.gmail,
43+
gmail,
5744
"bodyType",
5845
],
5946
},
6047
attachments: {
6148
propDefinition: [
62-
common.props.gmail,
49+
gmail,
6350
"attachments",
6451
],
6552
},
6653
inReplyTo: {
6754
propDefinition: [
68-
common.props.gmail,
55+
gmail,
6956
"message",
7057
],
7158
label: "In Reply To",
@@ -74,7 +61,7 @@ export default {
7461
},
7562
mimeType: {
7663
propDefinition: [
77-
common.props.gmail,
64+
gmail,
7865
"mimeType",
7966
],
8067
},

components/gmail/actions/download-attachment/download-attachment.mjs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
1-
import common from "../../common/verify-client-id.mjs";
1+
import gmail from "../../gmail.app.mjs";
22
import fs from "fs";
33
import path from "path";
4+
import { ConfigurationError } from "@pipedream/platform";
45

56
export default {
6-
...common,
77
key: "gmail-download-attachment",
8-
name: "Download Attachement",
8+
name: "Download Attachment",
99
description: "Download an attachment by attachmentId to the /tmp directory. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments/get)",
10-
version: "0.0.1",
10+
version: "0.0.2",
1111
type: "action",
1212
props: {
13-
...common.props,
13+
gmail,
1414
messageId: {
1515
propDefinition: [
16-
common.props.gmail,
17-
"message",
16+
gmail,
17+
"messageWithAttachments",
1818
],
1919
},
2020
attachmentId: {
2121
propDefinition: [
22-
common.props.gmail,
22+
gmail,
2323
"attachmentId",
2424
({ messageId }) => ({
2525
messageId,
2626
}),
2727
],
28+
withLabel: true,
2829
},
2930
filename: {
3031
type: "string",
3132
label: "Filename",
3233
description: "Name of the new file. Example: `test.jpg`",
34+
optional: true,
3335
},
3436
},
3537
async run({ $ }) {
38+
const attachmentId = this.attachmentId.value || this.attachmentId;
39+
3640
const attachment = await this.gmail.getAttachment({
3741
messageId: this.messageId,
38-
attachmentId: this.attachmentId,
42+
attachmentId,
3943
});
4044

41-
const filePath = path.join("/tmp", this.filename);
45+
const filename = this.filename || this.attachmentId.label;
46+
if (!filename) {
47+
throw new ConfigurationError("Please enter a filename to save the downloaded file as in the `/tmp` directory.");
48+
}
49+
50+
const filePath = path.join("/tmp", filename);
4251
const buffer = Buffer.from(attachment.data, "base64");
4352
fs.writeFileSync(filePath, buffer);
4453

45-
$.export("$summary", `Successfully created file ${this.filename} in \`/tmp\` directory`);
54+
$.export("$summary", `Successfully created file ${filename} in \`/tmp\` directory`);
4655

4756
return {
57+
filename,
4858
filePath,
4959
};
5060
},
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import common from "../../common/verify-client-id.mjs";
1+
import gmail from "../../gmail.app.mjs";
22

33
export default {
4-
...common,
54
key: "gmail-find-email",
65
name: "Find Email",
76
description: "Find an email using Google's Search Engine. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list)",
8-
version: "0.0.4",
7+
version: "0.0.5",
98
type: "action",
109
props: {
11-
...common.props,
10+
gmail,
1211
q: {
1312
propDefinition: [
14-
common.props.gmail,
13+
gmail,
1514
"q",
1615
],
1716
},
1817
labels: {
1918
propDefinition: [
20-
common.props.gmail,
19+
gmail,
2120
"label",
2221
],
2322
type: "string[]",
@@ -32,31 +31,27 @@ export default {
3231
optional: true,
3332
default: false,
3433
},
34+
maxResults: {
35+
type: "integer",
36+
label: "Max Results",
37+
description: "Maximum number of messages to return. This field defaults to 100. The maximum allowed value for this field is 500.",
38+
default: 100,
39+
optional: true,
40+
},
3541
},
3642
async run({ $ }) {
37-
const messageIds = [];
38-
let pageToken;
39-
40-
do {
41-
const {
42-
messages = [],
43-
nextPageToken,
44-
} = await this.gmail.listMessages({
45-
q: this.q,
46-
labelIds: this.labels,
47-
includeSpamTrash: this.includeSpamTrash,
48-
pageToken,
49-
});
50-
messageIds.push(...messages.map(({ id }) => id));
51-
pageToken = nextPageToken;
52-
} while (pageToken);
53-
54-
const messages = await this.gmail.getMessages(messageIds);
55-
56-
const suffix = messages.length === 1
43+
const { messages = [] } = await this.gmail.listMessages({
44+
q: this.q,
45+
labelIds: this.labels,
46+
includeSpamTrash: this.includeSpamTrash,
47+
maxResults: this.maxResults,
48+
});
49+
const messageIds = messages.map(({ id }) => id);
50+
const messagesToEmit = await this.gmail.getMessages(messageIds);
51+
const suffix = messagesToEmit.length === 1
5752
? ""
5853
: "s";
59-
$.export("$summary", `Successfully found ${messages.length} message${suffix}`);
60-
return messages;
54+
$.export("$summary", `Successfully found ${messagesToEmit.length} message${suffix}`);
55+
return messagesToEmit;
6156
},
6257
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import gmail from "../../gmail.app.mjs";
2+
3+
export default {
4+
key: "gmail-remove-label-from-email",
5+
name: "Remove Label from Email",
6+
description: "Remove label(s) from an email message. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
gmail,
11+
message: {
12+
propDefinition: [
13+
gmail,
14+
"message",
15+
],
16+
},
17+
removeLabelIds: {
18+
propDefinition: [
19+
gmail,
20+
"label",
21+
],
22+
type: "string[]",
23+
label: "Labels",
24+
description: "The labels to remove from the email",
25+
},
26+
},
27+
async run({ $ }) {
28+
const {
29+
gmail,
30+
message,
31+
removeLabelIds = [],
32+
} = this;
33+
34+
const response = await gmail.updateLabels({
35+
message,
36+
removeLabelIds,
37+
});
38+
39+
$.export("$summary", `Successfully removed ${removeLabelIds.length} label(s)`);
40+
return response;
41+
},
42+
};

components/gmail/actions/send-email/send-email.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "gmail-send-email",
55
name: "Send Email",
66
description: "Send an email from your Google Workspace email account. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send)",
7-
version: "0.1.3",
7+
version: "0.1.4",
88
type: "action",
99
props: {
1010
gmail,

components/gmail/actions/update-org-signature/update-org-signature.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import googleCloud from "../../../google_cloud/google_cloud.app.mjs";
22
import base from "../update-primary-signature/update-primary-signature.mjs";
3-
import verifyClient from "../../common/verify-client-id.mjs";
3+
import gmail from "../../gmail.app.mjs";
44

55
export default {
66
...base,
77
key: "gmail-update-org-signature",
88
name: "Update Signature for Email in Organization",
99
description: `Update the signature for a specific email address in an organization.
1010
A Google Cloud service account with delegated domain-wide authority is required for this action. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/update)`,
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
14-
...verifyClient.props,
14+
gmail,
1515
googleCloud,
1616
signature: base.props.signature,
1717
email: {

components/gmail/actions/update-primary-signature/update-primary-signature.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import common from "../../common/verify-client-id.mjs";
1+
import gmail from "../../gmail.app.mjs";
22

33
export default {
4-
...common,
54
key: "gmail-update-primary-signature",
65
name: "Update Signature for Primary Email Address",
76
description: "Update the signature for the primary email address. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/update)",
8-
version: "0.0.1",
7+
version: "0.0.2",
98
type: "action",
109
props: {
11-
...common.props,
10+
gmail,
1211
signature: {
1312
type: "string",
1413
label: "Signature",
1514
description: "The new signature.",
1615
},
1716
},
1817
methods: {
19-
...common.methods,
2018
async createOpts() {
2119
const { email } = await this.gmail.userInfo();
2220
return {

0 commit comments

Comments
 (0)