@descix/platform-api 3.0.0 → 4.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descix/platform-api",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Shared platform infrastructure: Firestore models, auth/session, permissions, entitlements, email",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,9 +68,14 @@ export function isValidEmail(email) {
68
68
  * @param {string} subject - Email subject
69
69
  * @param {string} body - Email body (plain text)
70
70
  * @param {string} [fromEmail] - Optional sender email (defaults to DESCIX_ROUTER_COMMUNITY_MANAGER)
71
+ * @param {Object} [options]
72
+ * @param {string} [options.html] - Optional HTML body (Q15, CEO word Unkamon c7bbc15). When
73
+ * present the message is multipart/alternative: the plain `body` is the text part, `html`
74
+ * the html part (last = preferred). Absent, the message is the same single-part text/plain
75
+ * it has always been — no existing caller changes.
71
76
  * @returns {Promise<void>}
72
77
  */
73
- export async function sendEmail(toEmail, subject, body, fromEmail = null) {
78
+ export async function sendEmail(toEmail, subject, body, fromEmail = null, { html = null } = {}) {
74
79
  const utils = getCloudConfig();
75
80
 
76
81
  // The sender/impersonated user - must be a real user in the domain with Gmail access
@@ -98,16 +103,41 @@ export async function sendEmail(toEmail, subject, body, fromEmail = null) {
98
103
 
99
104
  const gmail = google.gmail({ version: 'v1', auth });
100
105
 
101
- // Build the email message with Reply-To header
102
- const message = [
106
+ // Build the email message with Reply-To header. With `html`, multipart/alternative
107
+ // (text part first, html part last — the alternative order of preference); without it,
108
+ // the single-part text/plain message unchanged.
109
+ const headers = [
103
110
  `From: DeSciX <${impersonatedUser}>`,
104
111
  `To: ${toEmail}`,
105
112
  `Reply-To: ${replyToEmail}`,
106
113
  `Subject: ${subject}`,
107
- 'Content-Type: text/plain; charset="UTF-8"',
108
- '',
109
- body
110
- ].join('\n');
114
+ ];
115
+ let message;
116
+ if (html) {
117
+ const boundary = `descix-alt-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
118
+ message = [
119
+ ...headers,
120
+ 'MIME-Version: 1.0',
121
+ `Content-Type: multipart/alternative; boundary="${boundary}"`,
122
+ '',
123
+ `--${boundary}`,
124
+ 'Content-Type: text/plain; charset="UTF-8"',
125
+ '',
126
+ body,
127
+ `--${boundary}`,
128
+ 'Content-Type: text/html; charset="UTF-8"',
129
+ '',
130
+ html,
131
+ `--${boundary}--`
132
+ ].join('\n');
133
+ } else {
134
+ message = [
135
+ ...headers,
136
+ 'Content-Type: text/plain; charset="UTF-8"',
137
+ '',
138
+ body
139
+ ].join('\n');
140
+ }
111
141
 
112
142
  const raw = base64UrlEncode(message);
113
143