@upyo/maileroo 0.6.0-dev.227 → 0.6.0-dev.237
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 +32 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -280,8 +280,10 @@ async function convertMessage(message, config, signal) {
|
|
|
280
280
|
const emailData = {
|
|
281
281
|
from: convertAddress(message.sender),
|
|
282
282
|
to: convertAddressList(message.recipients),
|
|
283
|
-
subject: message.subject
|
|
283
|
+
subject: message.subject,
|
|
284
|
+
reference_id: createMailerooReference(message.idempotencyKey)
|
|
284
285
|
};
|
|
286
|
+
signal?.throwIfAborted();
|
|
285
287
|
const cc = convertOptionalAddressList(message.ccRecipients);
|
|
286
288
|
if (cc !== void 0) emailData.cc = cc;
|
|
287
289
|
const bcc = convertOptionalAddressList(message.bccRecipients);
|
|
@@ -301,6 +303,33 @@ async function convertMessage(message, config, signal) {
|
|
|
301
303
|
signal?.throwIfAborted();
|
|
302
304
|
return emailData;
|
|
303
305
|
}
|
|
306
|
+
function createMailerooReference(idempotencyKey) {
|
|
307
|
+
if (idempotencyKey == null || idempotencyKey === "") {
|
|
308
|
+
const bytes = new Uint8Array(12);
|
|
309
|
+
crypto.getRandomValues(bytes);
|
|
310
|
+
return bytesToHex(bytes);
|
|
311
|
+
}
|
|
312
|
+
return hashReference(idempotencyKey);
|
|
313
|
+
}
|
|
314
|
+
function bytesToHex(bytes) {
|
|
315
|
+
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
316
|
+
}
|
|
317
|
+
function hashReference(value) {
|
|
318
|
+
const bytes = new TextEncoder().encode(value);
|
|
319
|
+
const seeds = [
|
|
320
|
+
2166136261,
|
|
321
|
+
2654435769,
|
|
322
|
+
2246822507
|
|
323
|
+
];
|
|
324
|
+
return seeds.map((seed) => {
|
|
325
|
+
let hash = seed;
|
|
326
|
+
for (const byte of bytes) {
|
|
327
|
+
hash ^= byte;
|
|
328
|
+
hash = Math.imul(hash, 16777619);
|
|
329
|
+
}
|
|
330
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
331
|
+
}).join("");
|
|
332
|
+
}
|
|
304
333
|
function convertAddress(address) {
|
|
305
334
|
return address.name == null || address.name === "" ? { address: address.address } : {
|
|
306
335
|
address: address.address,
|
|
@@ -344,7 +373,8 @@ async function convertAttachment(attachment, signal) {
|
|
|
344
373
|
};
|
|
345
374
|
}
|
|
346
375
|
function waitForAttachmentContent(content, signal) {
|
|
347
|
-
if (
|
|
376
|
+
if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
|
|
377
|
+
if (signal == null) return content;
|
|
348
378
|
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
349
379
|
return new Promise((resolve, reject) => {
|
|
350
380
|
const onAbort = () => {
|
package/dist/index.d.cts
CHANGED
|
@@ -176,6 +176,7 @@ interface MailerooEmail {
|
|
|
176
176
|
readonly tags?: Record<string, string>;
|
|
177
177
|
readonly headers?: Record<string, string>;
|
|
178
178
|
readonly attachments?: readonly MailerooAttachment[];
|
|
179
|
+
readonly reference_id?: string;
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* Converts an Upyo message to Maileroo API JSON format.
|
package/dist/index.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ interface MailerooEmail {
|
|
|
176
176
|
readonly tags?: Record<string, string>;
|
|
177
177
|
readonly headers?: Record<string, string>;
|
|
178
178
|
readonly attachments?: readonly MailerooAttachment[];
|
|
179
|
+
readonly reference_id?: string;
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* Converts an Upyo message to Maileroo API JSON format.
|
package/dist/index.js
CHANGED
|
@@ -257,8 +257,10 @@ async function convertMessage(message, config, signal) {
|
|
|
257
257
|
const emailData = {
|
|
258
258
|
from: convertAddress(message.sender),
|
|
259
259
|
to: convertAddressList(message.recipients),
|
|
260
|
-
subject: message.subject
|
|
260
|
+
subject: message.subject,
|
|
261
|
+
reference_id: createMailerooReference(message.idempotencyKey)
|
|
261
262
|
};
|
|
263
|
+
signal?.throwIfAborted();
|
|
262
264
|
const cc = convertOptionalAddressList(message.ccRecipients);
|
|
263
265
|
if (cc !== void 0) emailData.cc = cc;
|
|
264
266
|
const bcc = convertOptionalAddressList(message.bccRecipients);
|
|
@@ -278,6 +280,33 @@ async function convertMessage(message, config, signal) {
|
|
|
278
280
|
signal?.throwIfAborted();
|
|
279
281
|
return emailData;
|
|
280
282
|
}
|
|
283
|
+
function createMailerooReference(idempotencyKey) {
|
|
284
|
+
if (idempotencyKey == null || idempotencyKey === "") {
|
|
285
|
+
const bytes = new Uint8Array(12);
|
|
286
|
+
crypto.getRandomValues(bytes);
|
|
287
|
+
return bytesToHex(bytes);
|
|
288
|
+
}
|
|
289
|
+
return hashReference(idempotencyKey);
|
|
290
|
+
}
|
|
291
|
+
function bytesToHex(bytes) {
|
|
292
|
+
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
293
|
+
}
|
|
294
|
+
function hashReference(value) {
|
|
295
|
+
const bytes = new TextEncoder().encode(value);
|
|
296
|
+
const seeds = [
|
|
297
|
+
2166136261,
|
|
298
|
+
2654435769,
|
|
299
|
+
2246822507
|
|
300
|
+
];
|
|
301
|
+
return seeds.map((seed) => {
|
|
302
|
+
let hash = seed;
|
|
303
|
+
for (const byte of bytes) {
|
|
304
|
+
hash ^= byte;
|
|
305
|
+
hash = Math.imul(hash, 16777619);
|
|
306
|
+
}
|
|
307
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
308
|
+
}).join("");
|
|
309
|
+
}
|
|
281
310
|
function convertAddress(address) {
|
|
282
311
|
return address.name == null || address.name === "" ? { address: address.address } : {
|
|
283
312
|
address: address.address,
|
|
@@ -321,7 +350,8 @@ async function convertAttachment(attachment, signal) {
|
|
|
321
350
|
};
|
|
322
351
|
}
|
|
323
352
|
function waitForAttachmentContent(content, signal) {
|
|
324
|
-
if (
|
|
353
|
+
if (content instanceof Uint8Array) return signal?.aborted ? Promise.reject(abortReason(signal)) : Promise.resolve(content);
|
|
354
|
+
if (signal == null) return content;
|
|
325
355
|
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
326
356
|
return new Promise((resolve, reject) => {
|
|
327
357
|
const onAbort = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/maileroo",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.237",
|
|
4
4
|
"description": "Maileroo transport for Upyo email library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@upyo/core": "0.6.0-dev.
|
|
56
|
+
"@upyo/core": "0.6.0-dev.237+c3b73b1a"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"tsdown": "^0.12.7",
|