@msgly/gmail 0.2.3 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -20,9 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- createGmailAdapter: () => createGmailAdapter
23
+ createGmailAdapter: () => createGmailAdapter,
24
+ fmt: () => fmt
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
27
+ var fmt = {
28
+ bold: (t) => `<b>${t}</b>`,
29
+ italic: (t) => `<i>${t}</i>`,
30
+ underline: (t) => `<u>${t}</u>`,
31
+ strikethrough: (t) => `<s>${t}</s>`,
32
+ code: (t) => `<code>${t}</code>`,
33
+ pre: (t) => `<pre>${t}</pre>`,
34
+ link: (t, url) => `<a href="${url}">${t}</a>`,
35
+ color: (t, hex) => `<span style="color:${hex}">${t}</span>`,
36
+ br: () => "<br>"
37
+ };
26
38
  var DEFAULT_TOKEN_URL = "https://oauth2.googleapis.com/token";
27
39
  var DEFAULT_API_BASE = "https://gmail.googleapis.com";
28
40
  var DEFAULT_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
@@ -226,12 +238,13 @@ function sanitizeHeaderValue(value) {
226
238
  return value.replace(/[\r\n]/g, "");
227
239
  }
228
240
  function buildReplyEmail(opts) {
241
+ const contentType = opts.format === "html" ? "text/html; charset=utf-8" : "text/plain; charset=utf-8";
229
242
  const headers = [
230
243
  `From: ${sanitizeHeaderValue(opts.from)}`,
231
244
  `To: ${sanitizeHeaderValue(opts.to)}`,
232
245
  `Subject: ${sanitizeHeaderValue(opts.subject)}`,
233
246
  "MIME-Version: 1.0",
234
- "Content-Type: text/plain; charset=utf-8",
247
+ `Content-Type: ${contentType}`,
235
248
  "Content-Transfer-Encoding: 8bit",
236
249
  `Date: ${(/* @__PURE__ */ new Date()).toUTCString()}`
237
250
  ];
@@ -435,6 +448,7 @@ function createGmailAdapter(config) {
435
448
  to: message.contact.channelUserId,
436
449
  subject,
437
450
  body: message.content.text,
451
+ format: message.content.format,
438
452
  inReplyTo,
439
453
  references
440
454
  });
@@ -540,5 +554,6 @@ function createGmailAdapter(config) {
540
554
  }
541
555
  // Annotate the CommonJS export names for ESM import in node:
542
556
  0 && (module.exports = {
543
- createGmailAdapter
557
+ createGmailAdapter,
558
+ fmt
544
559
  });
package/dist/index.d.cts CHANGED
@@ -67,6 +67,25 @@ interface GmailAdapter extends Adapter {
67
67
  /** Stop the existing watch. Mailbox stops emitting notifications. */
68
68
  stopWatch(): Promise<void>;
69
69
  }
70
+ /**
71
+ * HTML formatting helpers for Gmail. Pass `format: 'html'` on TextContent to
72
+ * send as an HTML email part (Content-Type: text/html).
73
+ *
74
+ * @example
75
+ * content: { type: 'text', format: 'html',
76
+ * text: `${fmt.bold('Hello')} ${fmt.link('click here', 'https://example.com')}` }
77
+ */
78
+ declare const fmt: {
79
+ bold: (t: string) => string;
80
+ italic: (t: string) => string;
81
+ underline: (t: string) => string;
82
+ strikethrough: (t: string) => string;
83
+ code: (t: string) => string;
84
+ pre: (t: string) => string;
85
+ link: (t: string, url: string) => string;
86
+ color: (t: string, hex: string) => string;
87
+ br: () => string;
88
+ };
70
89
  /**
71
90
  * Gmail adapter for Msgly — receives via Pub/Sub push notifications,
72
91
  * sends via the Gmail REST API.
@@ -95,4 +114,4 @@ interface GmailAdapter extends Adapter {
95
114
  */
96
115
  declare function createGmailAdapter(config: GmailConfig): GmailAdapter;
97
116
 
98
- export { type GmailAdapter, type GmailConfig, createGmailAdapter };
117
+ export { type GmailAdapter, type GmailConfig, createGmailAdapter, fmt };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,25 @@ interface GmailAdapter extends Adapter {
67
67
  /** Stop the existing watch. Mailbox stops emitting notifications. */
68
68
  stopWatch(): Promise<void>;
69
69
  }
70
+ /**
71
+ * HTML formatting helpers for Gmail. Pass `format: 'html'` on TextContent to
72
+ * send as an HTML email part (Content-Type: text/html).
73
+ *
74
+ * @example
75
+ * content: { type: 'text', format: 'html',
76
+ * text: `${fmt.bold('Hello')} ${fmt.link('click here', 'https://example.com')}` }
77
+ */
78
+ declare const fmt: {
79
+ bold: (t: string) => string;
80
+ italic: (t: string) => string;
81
+ underline: (t: string) => string;
82
+ strikethrough: (t: string) => string;
83
+ code: (t: string) => string;
84
+ pre: (t: string) => string;
85
+ link: (t: string, url: string) => string;
86
+ color: (t: string, hex: string) => string;
87
+ br: () => string;
88
+ };
70
89
  /**
71
90
  * Gmail adapter for Msgly — receives via Pub/Sub push notifications,
72
91
  * sends via the Gmail REST API.
@@ -95,4 +114,4 @@ interface GmailAdapter extends Adapter {
95
114
  */
96
115
  declare function createGmailAdapter(config: GmailConfig): GmailAdapter;
97
116
 
98
- export { type GmailAdapter, type GmailConfig, createGmailAdapter };
117
+ export { type GmailAdapter, type GmailConfig, createGmailAdapter, fmt };
package/dist/index.js CHANGED
@@ -1,4 +1,15 @@
1
1
  // src/index.ts
2
+ var fmt = {
3
+ bold: (t) => `<b>${t}</b>`,
4
+ italic: (t) => `<i>${t}</i>`,
5
+ underline: (t) => `<u>${t}</u>`,
6
+ strikethrough: (t) => `<s>${t}</s>`,
7
+ code: (t) => `<code>${t}</code>`,
8
+ pre: (t) => `<pre>${t}</pre>`,
9
+ link: (t, url) => `<a href="${url}">${t}</a>`,
10
+ color: (t, hex) => `<span style="color:${hex}">${t}</span>`,
11
+ br: () => "<br>"
12
+ };
2
13
  var DEFAULT_TOKEN_URL = "https://oauth2.googleapis.com/token";
3
14
  var DEFAULT_API_BASE = "https://gmail.googleapis.com";
4
15
  var DEFAULT_JWKS_URL = "https://www.googleapis.com/oauth2/v3/certs";
@@ -202,12 +213,13 @@ function sanitizeHeaderValue(value) {
202
213
  return value.replace(/[\r\n]/g, "");
203
214
  }
204
215
  function buildReplyEmail(opts) {
216
+ const contentType = opts.format === "html" ? "text/html; charset=utf-8" : "text/plain; charset=utf-8";
205
217
  const headers = [
206
218
  `From: ${sanitizeHeaderValue(opts.from)}`,
207
219
  `To: ${sanitizeHeaderValue(opts.to)}`,
208
220
  `Subject: ${sanitizeHeaderValue(opts.subject)}`,
209
221
  "MIME-Version: 1.0",
210
- "Content-Type: text/plain; charset=utf-8",
222
+ `Content-Type: ${contentType}`,
211
223
  "Content-Transfer-Encoding: 8bit",
212
224
  `Date: ${(/* @__PURE__ */ new Date()).toUTCString()}`
213
225
  ];
@@ -411,6 +423,7 @@ function createGmailAdapter(config) {
411
423
  to: message.contact.channelUserId,
412
424
  subject,
413
425
  body: message.content.text,
426
+ format: message.content.format,
414
427
  inReplyTo,
415
428
  references
416
429
  });
@@ -515,5 +528,6 @@ function createGmailAdapter(config) {
515
528
  };
516
529
  }
517
530
  export {
518
- createGmailAdapter
531
+ createGmailAdapter,
532
+ fmt
519
533
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msgly/gmail",
3
- "version": "0.2.3",
3
+ "version": "0.4.0",
4
4
  "description": "Gmail adapter for Msgly — receive and reply to emails via Gmail API + Pub/Sub push",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "README.md"
20
20
  ],
21
21
  "dependencies": {
22
- "@msgly/core": "0.2.3"
22
+ "@msgly/core": "0.4.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.11.0",