@maestro-js/mail 1.0.0-alpha.2 → 1.0.0-alpha.20

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.d.ts CHANGED
@@ -218,11 +218,12 @@ interface SesClientAdapter {
218
218
  }): Promise<{
219
219
  MessageId?: string;
220
220
  }>;
221
+ configurationSetName: string;
221
222
  }
222
223
  interface SesMailDriver extends MailDriver {
223
224
  toMailEvent(event: SesWebhookEvent): MailEvent | null;
224
225
  }
225
- declare function sesMailDriver(ses: SesClientAdapter, configurationSetName: string): SesMailDriver;
226
+ declare function sesMailDriver(ses: SesClientAdapter): SesMailDriver;
226
227
 
227
228
  interface IcsAttachmentOptions {
228
229
  filename?: string;
@@ -393,7 +394,7 @@ declare namespace Mail {
393
394
  /** Logger for recording sent envelopes and webhook events */
394
395
  logger: Log.Logger<[MailLogMessage]>;
395
396
  /** Queue service for {@link queue} and {@link later} delivery */
396
- queueService: Queue.QueueService;
397
+ queue?: Queue.QueueService;
397
398
  /** Optional callback invoked when a send fails, before the error is rethrown */
398
399
  onMessageSendFailure?(envelope: Envelope, error: unknown): unknown;
399
400
  }
package/dist/index.js CHANGED
@@ -145,7 +145,7 @@ var sesToMaestroEventMapping = {
145
145
  Click: "click",
146
146
  Subscription: "unsubscribe"
147
147
  };
148
- function sesMailDriver(ses, configurationSetName) {
148
+ function sesMailDriver(ses) {
149
149
  async function send(envelope) {
150
150
  assert3.ok(envelope.from, "missing from address");
151
151
  function getsComposerAddr(addresses) {
@@ -200,7 +200,7 @@ function sesMailDriver(ses, configurationSetName) {
200
200
  input: {
201
201
  RawMessage: { Data: rawBuffer },
202
202
  Destinations: [recipient],
203
- ConfigurationSetName: configurationSetName,
203
+ ConfigurationSetName: ses.configurationSetName,
204
204
  Tags: messageTags.length ? messageTags : void 0
205
205
  }
206
206
  };
@@ -320,12 +320,10 @@ function parseIsoToDurationObject(iso) {
320
320
 
321
321
  // src/index.ts
322
322
  import assert5 from "assert";
323
- import { Log as Log2 } from "@maestro-js/log";
324
323
 
325
324
  // src/stub-mail-driver.ts
326
325
  import assert4 from "assert";
327
326
  import { randomUUID } from "crypto";
328
- import "@maestro-js/log";
329
327
  function stubMailDriver({ logger } = {}) {
330
328
  async function send(envelope) {
331
329
  assert4.ok(envelope.from, "missing from address");
@@ -350,16 +348,16 @@ function stubMailDriver({ logger } = {}) {
350
348
  import { ServiceRegistry } from "@maestro-js/service-registry";
351
349
  var EMPTY_ENVELOPE = /* @__PURE__ */ Symbol("EMPTY_ENVELOPE");
352
350
  function create(config) {
353
- const queueService = config.queueService;
354
- const mailQueue = queueService.create({
351
+ const queueService = config.queue;
352
+ const mailQueue = queueService?.create({
355
353
  name: ["Maestro.Mail", config.name].filter(Boolean).join("."),
356
- async workFn(envelope) {
354
+ async handle(envelope) {
357
355
  return send(envelope);
358
356
  }
359
357
  });
360
- const mailableQueue = queueService.create({
358
+ const mailableQueue = queueService?.create({
361
359
  name: ["Maestro.Mailable", config.name].filter(Boolean).join("."),
362
- async workFn(props) {
360
+ async handle(props) {
363
361
  const mailable2 = mailableRegistry.get(props.mailableName);
364
362
  if (!mailable2) {
365
363
  throw new Error(`No mailable found with name ${props.mailableName}`);
@@ -418,10 +416,16 @@ function create(config) {
418
416
  }
419
417
  }
420
418
  function queue(envelope) {
421
- mailQueue.addMessage(envelope, { scheduledDate: null });
419
+ if (!mailQueue) {
420
+ throw new Error("Queueing not configured for Mail");
421
+ }
422
+ mailQueue.dispatch(envelope);
422
423
  }
423
424
  function later(envelope, scheduledDate) {
424
- mailQueue.addMessage(envelope, { scheduledDate });
425
+ if (!mailQueue) {
426
+ throw new Error("Queueing not configured for Mail");
427
+ }
428
+ mailQueue.dispatchWithDelay(envelope, scheduledDate);
425
429
  }
426
430
  async function sendMailable(props) {
427
431
  const mailable2 = mailableRegistry.get(props.mailableName);
@@ -446,7 +450,14 @@ function create(config) {
446
450
  }
447
451
  }
448
452
  async function queueMailable(props, options) {
449
- await mailableQueue.addMessage(props, options);
453
+ if (!mailableQueue) {
454
+ throw new Error("Queueing not configured for Mail");
455
+ }
456
+ if (options.scheduledDate) {
457
+ await mailableQueue.dispatchWithDelay(props, options.scheduledDate);
458
+ } else {
459
+ await mailableQueue.dispatch(props);
460
+ }
450
461
  }
451
462
  function formatEnvelope(envelope) {
452
463
  function formatAddress(mailAddress) {
@@ -458,13 +469,6 @@ function create(config) {
458
469
  const formattedToUniq = [...new Set(formattedTo.map((f) => typeof f === "string" ? f : f.email))].map(
459
470
  (email) => formattedTo.find((t) => typeof t === "string" ? t === email : t.email === email)
460
471
  );
461
- if (formattedToUniq.length !== formattedTo.length) {
462
- Log2.warn({
463
- message: "Addresses were not unique in the request. Duplicate email addresses have been removed",
464
- original: formattedTo,
465
- modified: formattedToUniq
466
- });
467
- }
468
472
  return {
469
473
  ...envelope,
470
474
  to: formattedToUniq,
package/package.json CHANGED
@@ -12,18 +12,21 @@
12
12
  "ics": "^3.8.1",
13
13
  "iso-fns2": "npm:iso-fns@2.0.0-alpha.26",
14
14
  "nodemailer": "^7.0.5",
15
- "@maestro-js/helpers": "1.0.0-alpha.2",
16
- "@maestro-js/log": "1.0.0-alpha.2",
17
- "@maestro-js/service-registry": "1.0.0-alpha.2"
15
+ "@maestro-js/helpers": "1.0.0-alpha.20",
16
+ "@maestro-js/service-registry": "1.0.0-alpha.20"
17
+ },
18
+ "peerDependencies": {
19
+ "@maestro-js/log": "1.0.0-alpha.20"
18
20
  },
19
21
  "devDependencies": {
20
22
  "@react-email/render": "0.0.7",
21
23
  "@types/node": "^22.19.11",
22
24
  "@types/nodemailer": "^6.4.17",
23
25
  "@types/react": "^19.0.0",
24
- "@maestro-js/queue": "1.0.0-alpha.2"
26
+ "@maestro-js/log": "1.0.0-alpha.20",
27
+ "@maestro-js/queue": "1.0.0-alpha.20"
25
28
  },
26
- "version": "1.0.0-alpha.2",
29
+ "version": "1.0.0-alpha.20",
27
30
  "publishConfig": {
28
31
  "access": "restricted"
29
32
  },