@openfn/language-gmail 1.3.0 → 1.3.2

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.
package/dist/index.cjs CHANGED
@@ -147,8 +147,9 @@ async function getMessageContent(message, desiredContent) {
147
147
  return `Unsupported content type: ${desiredContent.type}`;
148
148
  }
149
149
  }
150
- async function sendMessageWithAttachments(message) {
150
+ async function buildAndSendMessage(message) {
151
151
  const attachments = await parseAttachments(message.attachments);
152
+ const hasAttachments = attachments && attachments.length > 0;
152
153
  const lines = [
153
154
  `To: ${message.to}`,
154
155
  `Subject: ${message.subject}`,
@@ -161,18 +162,20 @@ async function sendMessageWithAttachments(message) {
161
162
  "",
162
163
  message.body
163
164
  ];
164
- for (const attachment of attachments) {
165
- const file = attachment.filename;
166
- lines.push(
167
- `--${SEND_MESSAGE_BOUNDARY}`,
168
- `Content-Type: application/octet-stream; name="${file}"`,
169
- "Content-Transfer-Encoding: base64",
170
- `Content-Disposition: attachment; filename="${file}"`,
171
- "",
172
- attachment.content
173
- );
165
+ if (hasAttachments) {
166
+ for (const attachment of attachments) {
167
+ const file = attachment.filename;
168
+ lines.push(
169
+ `--${SEND_MESSAGE_BOUNDARY}`,
170
+ `Content-Type: application/octet-stream; name="${file}"`,
171
+ "Content-Transfer-Encoding: base64",
172
+ `Content-Disposition: attachment; filename="${file}"`,
173
+ "",
174
+ attachment.content
175
+ );
176
+ }
177
+ lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
174
178
  }
175
- lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
176
179
  const rawMessage = lines.join("\r\n");
177
180
  const encodedMessage = Buffer.from(rawMessage).toString("base64");
178
181
  try {
@@ -182,7 +185,7 @@ async function sendMessageWithAttachments(message) {
182
185
  });
183
186
  return result.data;
184
187
  } catch (error) {
185
- throw new Error("Error fetching messages: " + error.message);
188
+ throw new Error("Error sending message: " + error.message);
186
189
  }
187
190
  }
188
191
  async function parseAttachments(attachments) {
@@ -418,7 +421,7 @@ function sendMessage(message) {
418
421
  const messages = Array.isArray(resolvedMessage) ? resolvedMessage : [resolvedMessage];
419
422
  const results = [];
420
423
  for (const msg of messages) {
421
- const result = await sendMessageWithAttachments(msg);
424
+ const result = await buildAndSendMessage(msg);
422
425
  results.push(result);
423
426
  }
424
427
  return {
package/dist/index.js CHANGED
@@ -111,8 +111,9 @@ async function getMessageContent(message, desiredContent) {
111
111
  return `Unsupported content type: ${desiredContent.type}`;
112
112
  }
113
113
  }
114
- async function sendMessageWithAttachments(message) {
114
+ async function buildAndSendMessage(message) {
115
115
  const attachments = await parseAttachments(message.attachments);
116
+ const hasAttachments = attachments && attachments.length > 0;
116
117
  const lines = [
117
118
  `To: ${message.to}`,
118
119
  `Subject: ${message.subject}`,
@@ -125,18 +126,20 @@ async function sendMessageWithAttachments(message) {
125
126
  "",
126
127
  message.body
127
128
  ];
128
- for (const attachment of attachments) {
129
- const file = attachment.filename;
130
- lines.push(
131
- `--${SEND_MESSAGE_BOUNDARY}`,
132
- `Content-Type: application/octet-stream; name="${file}"`,
133
- "Content-Transfer-Encoding: base64",
134
- `Content-Disposition: attachment; filename="${file}"`,
135
- "",
136
- attachment.content
137
- );
129
+ if (hasAttachments) {
130
+ for (const attachment of attachments) {
131
+ const file = attachment.filename;
132
+ lines.push(
133
+ `--${SEND_MESSAGE_BOUNDARY}`,
134
+ `Content-Type: application/octet-stream; name="${file}"`,
135
+ "Content-Transfer-Encoding: base64",
136
+ `Content-Disposition: attachment; filename="${file}"`,
137
+ "",
138
+ attachment.content
139
+ );
140
+ }
141
+ lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
138
142
  }
139
- lines.push(`--${SEND_MESSAGE_BOUNDARY}--`, "");
140
143
  const rawMessage = lines.join("\r\n");
141
144
  const encodedMessage = Buffer.from(rawMessage).toString("base64");
142
145
  try {
@@ -146,7 +149,7 @@ async function sendMessageWithAttachments(message) {
146
149
  });
147
150
  return result.data;
148
151
  } catch (error) {
149
- throw new Error("Error fetching messages: " + error.message);
152
+ throw new Error("Error sending message: " + error.message);
150
153
  }
151
154
  }
152
155
  async function parseAttachments(attachments) {
@@ -397,7 +400,7 @@ function sendMessage(message) {
397
400
  const messages = Array.isArray(resolvedMessage) ? resolvedMessage : [resolvedMessage];
398
401
  const results = [];
399
402
  for (const msg of messages) {
400
- const result = await sendMessageWithAttachments(msg);
403
+ const result = await buildAndSendMessage(msg);
401
404
  results.push(result);
402
405
  }
403
406
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfn/language-gmail",
3
3
  "label": "Gmail",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "description": "OpenFn gmail adaptor",
6
6
  "type": "module",
7
7
  "exports": {
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "googleapis": "100.0.0",
25
25
  "jszip": "^3.10.1",
26
- "@openfn/language-common": "2.4.0"
26
+ "@openfn/language-common": "2.5.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "assertion-error": "2.0.0",
package/types/Utils.d.ts CHANGED
@@ -10,6 +10,6 @@ export function getMessageResult(userId: any, messageId: any): Promise<{
10
10
  }>;
11
11
  export function getContentIndicators(defaultContentRequests?: any[], contentRequests?: any[]): any[];
12
12
  export function getMessageContent(message: any, desiredContent: any): Promise<any>;
13
- export function sendMessageWithAttachments(message: any): Promise<any>;
13
+ export function buildAndSendMessage(message: any): Promise<any>;
14
14
  export function createConnection(state: any): any;
15
15
  export function removeConnection(state: any): any;