@lovable.dev/email-js 0.8.0 → 0.9.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/README.md CHANGED
@@ -102,6 +102,11 @@ fails or times out, or the body is over the size limit, the SDK logs one
102
102
  `[email-js] upload skipped: …` warning and sends the body inline, so sends keep
103
103
  working without any change on your side. There is no option to turn it off.
104
104
 
105
+ The slot request names the send (`run_id` or `idempotency_key`) and its
106
+ recipient. When Lovable already accepted that send, a retry gets it back
107
+ (`send_id`, `status`) with no new upload or send request. A send with `cc` or
108
+ `bcc` is not named and takes every step again.
109
+
105
110
  ### Cc and bcc
106
111
 
107
112
  `cc` and `bcc` take arrays of addresses (`"a@b.com"` or `"Name <a@b.com>"`).
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _lovable_dev_webhooks_js = require("@lovable.dev/webhooks-js");
3
- const SDK_VERSION = "0.8.0";
3
+ const SDK_VERSION = "0.9.0";
4
4
  const SDK_HEADER = "X-Lovable-SDK";
5
5
  const SDK_HEADER_VALUE = `email-js/${SDK_VERSION}`;
6
6
  function resolveApiBaseUrl(apiBaseUrl) {
@@ -70,6 +70,7 @@ async function emailApiRequest(options, path, init = { method: "GET" }) {
70
70
  //#region src/email.ts
71
71
  const DEFAULT_SEND_PATH = "/v1/messaging/email/send";
72
72
  const PREPARE_UPLOADS_PATH = "/v1/messaging/email/prepare-uploads";
73
+ const HEADER_EXACT = /^[\x21-\x7e](?:[\x20-\x7e]*[\x21-\x7e])?$/;
73
74
  const DEFAULT_UPLOAD_BUDGET = {
74
75
  prepareTimeoutMs: 1e4,
75
76
  putTimeoutMs: 1e4
@@ -114,8 +115,12 @@ async function sendLovableEmailWithUploadBudget(payload, options, budget) {
114
115
  ...payload,
115
116
  from: formatEmailFrom(payload.from)
116
117
  };
117
- const bodyPayloadId = await uploadBody(options, apiHeaders, bodyPayloadDocument(request), budget);
118
- if (bodyPayloadId) request.body_payload_id = bodyPayloadId;
118
+ const upload = await uploadBody(options, {
119
+ ...apiHeaders,
120
+ ...sendIdentityHeaders(payload)
121
+ }, bodyPayloadDocument(request), budget);
122
+ if (typeof upload === "object") return upload;
123
+ if (upload) request.body_payload_id = upload;
119
124
  const response = await fetch(url, {
120
125
  method: "POST",
121
126
  headers,
@@ -141,6 +146,21 @@ function bodyPayloadDocument(request) {
141
146
  if (request.message_id) document.message_id = request.message_id;
142
147
  return document;
143
148
  }
149
+ function sendIdentityHeaders(payload) {
150
+ if (payload.cc?.length || payload.bcc?.length || !headerExact(payload.to)) return {};
151
+ const recipient = { "X-Lovable-Recipient": payload.to };
152
+ if (typeof payload.run_id === "string" && payload.run_id.trim()) return headerExact(payload.run_id) ? {
153
+ ...recipient,
154
+ "X-Lovable-Run-Id": payload.run_id
155
+ } : {};
156
+ return headerExact(payload.idempotency_key) ? {
157
+ ...recipient,
158
+ "Idempotency-Key": payload.idempotency_key
159
+ } : {};
160
+ }
161
+ function headerExact(value) {
162
+ return typeof value === "string" && HEADER_EXACT.test(value);
163
+ }
144
164
  async function uploadBody(options, apiHeaders, document, budget) {
145
165
  const bytes = new TextEncoder().encode(JSON.stringify(document));
146
166
  let file;
@@ -157,7 +177,9 @@ async function uploadBody(options, apiHeaders, document, budget) {
157
177
  discardBody(response);
158
178
  return uploadSkipped(`prepare ${response.status}`);
159
179
  }
160
- file = preparedFile(await response.json());
180
+ const prepared = await response.json();
181
+ if (prepared?.send?.success === true) return prepared.send;
182
+ file = preparedFile(prepared);
161
183
  } catch (error) {
162
184
  return uploadSkipped(`prepare ${errorClass(error)}`);
163
185
  }
package/dist/index.d.cts CHANGED
@@ -32,6 +32,8 @@ interface EmailSendResponse {
32
32
  success: boolean;
33
33
  message_id?: string;
34
34
  workflow_id?: string;
35
+ /** Set when the send was accepted into the email queue; a retry of the same send returns the same ID. */
36
+ send_id?: string;
35
37
  status?: string;
36
38
  }
37
39
  interface SendEmailOptions {
package/dist/index.d.ts CHANGED
@@ -32,6 +32,8 @@ interface EmailSendResponse {
32
32
  success: boolean;
33
33
  message_id?: string;
34
34
  workflow_id?: string;
35
+ /** Set when the send was accepted into the email queue; a retry of the same send returns the same ID. */
36
+ send_id?: string;
35
37
  status?: string;
36
38
  }
37
39
  interface SendEmailOptions {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebhookError, verifyWebhookRequest } from "@lovable.dev/webhooks-js";
2
- const SDK_VERSION = "0.8.0";
2
+ const SDK_VERSION = "0.9.0";
3
3
  const SDK_HEADER = "X-Lovable-SDK";
4
4
  const SDK_HEADER_VALUE = `email-js/${SDK_VERSION}`;
5
5
  function resolveApiBaseUrl(apiBaseUrl) {
@@ -69,6 +69,7 @@ async function emailApiRequest(options, path, init = { method: "GET" }) {
69
69
  //#region src/email.ts
70
70
  const DEFAULT_SEND_PATH = "/v1/messaging/email/send";
71
71
  const PREPARE_UPLOADS_PATH = "/v1/messaging/email/prepare-uploads";
72
+ const HEADER_EXACT = /^[\x21-\x7e](?:[\x20-\x7e]*[\x21-\x7e])?$/;
72
73
  const DEFAULT_UPLOAD_BUDGET = {
73
74
  prepareTimeoutMs: 1e4,
74
75
  putTimeoutMs: 1e4
@@ -113,8 +114,12 @@ async function sendLovableEmailWithUploadBudget(payload, options, budget) {
113
114
  ...payload,
114
115
  from: formatEmailFrom(payload.from)
115
116
  };
116
- const bodyPayloadId = await uploadBody(options, apiHeaders, bodyPayloadDocument(request), budget);
117
- if (bodyPayloadId) request.body_payload_id = bodyPayloadId;
117
+ const upload = await uploadBody(options, {
118
+ ...apiHeaders,
119
+ ...sendIdentityHeaders(payload)
120
+ }, bodyPayloadDocument(request), budget);
121
+ if (typeof upload === "object") return upload;
122
+ if (upload) request.body_payload_id = upload;
118
123
  const response = await fetch(url, {
119
124
  method: "POST",
120
125
  headers,
@@ -140,6 +145,21 @@ function bodyPayloadDocument(request) {
140
145
  if (request.message_id) document.message_id = request.message_id;
141
146
  return document;
142
147
  }
148
+ function sendIdentityHeaders(payload) {
149
+ if (payload.cc?.length || payload.bcc?.length || !headerExact(payload.to)) return {};
150
+ const recipient = { "X-Lovable-Recipient": payload.to };
151
+ if (typeof payload.run_id === "string" && payload.run_id.trim()) return headerExact(payload.run_id) ? {
152
+ ...recipient,
153
+ "X-Lovable-Run-Id": payload.run_id
154
+ } : {};
155
+ return headerExact(payload.idempotency_key) ? {
156
+ ...recipient,
157
+ "Idempotency-Key": payload.idempotency_key
158
+ } : {};
159
+ }
160
+ function headerExact(value) {
161
+ return typeof value === "string" && HEADER_EXACT.test(value);
162
+ }
143
163
  async function uploadBody(options, apiHeaders, document, budget) {
144
164
  const bytes = new TextEncoder().encode(JSON.stringify(document));
145
165
  let file;
@@ -156,7 +176,9 @@ async function uploadBody(options, apiHeaders, document, budget) {
156
176
  discardBody(response);
157
177
  return uploadSkipped(`prepare ${response.status}`);
158
178
  }
159
- file = preparedFile(await response.json());
179
+ const prepared = await response.json();
180
+ if (prepared?.send?.success === true) return prepared.send;
181
+ file = preparedFile(prepared);
160
182
  } catch (error) {
161
183
  return uploadSkipped(`prepare ${errorClass(error)}`);
162
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/email-js",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Lovable Email JS",
5
5
  "repository": {
6
6
  "type": "git",