@digilogiclabs/platform-core 1.20.3 → 1.23.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.
Files changed (38) hide show
  1. package/dist/{ConsoleEmail-CO0OM4UT.d.ts → ConsoleEmail-CgSIvRdj.d.mts} +5 -46
  2. package/dist/{ConsoleEmail-DDB28vyS.d.mts → ConsoleEmail-iJO7Cb_v.d.ts} +5 -46
  3. package/dist/{IAI-D8wA_i8N.d.mts → IAI-B7pp322X.d.mts} +1 -170
  4. package/dist/{IAI-D8wA_i8N.d.ts → IAI-B7pp322X.d.ts} +1 -170
  5. package/dist/ICache-BWSuTuhz.d.mts +66 -0
  6. package/dist/ICache-BWSuTuhz.d.ts +66 -0
  7. package/dist/IEmail-CsOcaQcb.d.mts +45 -0
  8. package/dist/IEmail-CsOcaQcb.d.ts +45 -0
  9. package/dist/ILogger-DLDBZaH4.d.mts +105 -0
  10. package/dist/ILogger-DLDBZaH4.d.ts +105 -0
  11. package/dist/{agents-DGciJI27.d.mts → agents-C7FPA8y9.d.mts} +3 -1
  12. package/dist/{agents-Cc65YUoW.d.ts → agents-qyQ3BtXy.d.ts} +3 -1
  13. package/dist/agents.d.mts +4 -2
  14. package/dist/agents.d.ts +4 -2
  15. package/dist/auth.d.mts +386 -1
  16. package/dist/auth.d.ts +386 -1
  17. package/dist/auth.js +451 -0
  18. package/dist/auth.js.map +1 -1
  19. package/dist/auth.mjs +434 -0
  20. package/dist/auth.mjs.map +1 -1
  21. package/dist/circuit-breaker-CP6kw0P5.d.ts +351 -0
  22. package/dist/circuit-breaker-CsQivd57.d.mts +351 -0
  23. package/dist/email-templates.d.mts +106 -1
  24. package/dist/email-templates.d.ts +106 -1
  25. package/dist/email-templates.js +608 -0
  26. package/dist/email-templates.js.map +1 -1
  27. package/dist/email-templates.mjs +596 -0
  28. package/dist/email-templates.mjs.map +1 -1
  29. package/dist/index.d.mts +14 -355
  30. package/dist/index.d.ts +14 -355
  31. package/dist/index.js +10 -7
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +10 -7
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/migrate.js +0 -0
  36. package/dist/testing.d.mts +6 -3
  37. package/dist/testing.d.ts +6 -3
  38. package/package.json +11 -11
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,12 +17,22 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/email-templates/index.ts
21
31
  var email_templates_exports = {};
22
32
  __export(email_templates_exports, {
23
33
  calloutBlock: () => calloutBlock,
34
+ createResilientEmail: () => createResilientEmail,
35
+ createUnsubscribe: () => createUnsubscribe,
24
36
  dataTable: () => dataTable,
25
37
  digestEmail: () => digestEmail,
26
38
  divider: () => divider,
@@ -325,9 +337,605 @@ function securityEmail(branding, data) {
325
337
  cta: data.actionUrl ? { text: data.actionText ?? "Take Action", url: data.actionUrl } : void 0
326
338
  });
327
339
  }
340
+
341
+ // src/auth/tokens.ts
342
+ var import_node_crypto = __toESM(require("crypto"));
343
+ var HMAC_HEX_CHARS = 16;
344
+ function validateSecret(secret) {
345
+ if (typeof secret !== "string" || secret.length < 16) {
346
+ throw new Error(
347
+ "signToken/verifyToken require a secret of at least 16 characters"
348
+ );
349
+ }
350
+ }
351
+ function computeHmac(secret, signedPart) {
352
+ return import_node_crypto.default.createHmac("sha256", secret).update(signedPart).digest("hex").slice(0, HMAC_HEX_CHARS);
353
+ }
354
+ function signToken(opts) {
355
+ validateSecret(opts.secret);
356
+ if (typeof opts.payload !== "string" || opts.payload.length === 0) {
357
+ throw new Error("signToken requires a non-empty payload string");
358
+ }
359
+ const signedPart = opts.ttlSeconds !== void 0 ? `${opts.payload}.${Math.floor(Date.now() / 1e3)}` : opts.payload;
360
+ const encoded = Buffer.from(signedPart, "utf-8").toString("base64url");
361
+ const hmac = computeHmac(opts.secret, signedPart);
362
+ return `${encoded}.${hmac}`;
363
+ }
364
+ function verifyToken(token, opts) {
365
+ validateSecret(opts.secret);
366
+ if (typeof token !== "string" || token.length === 0) {
367
+ return { valid: false, reason: "malformed" };
368
+ }
369
+ const lastDot = token.lastIndexOf(".");
370
+ if (lastDot <= 0 || lastDot === token.length - 1) {
371
+ return { valid: false, reason: "malformed" };
372
+ }
373
+ const encoded = token.slice(0, lastDot);
374
+ const providedHmac = token.slice(lastDot + 1);
375
+ let signedPart;
376
+ try {
377
+ signedPart = Buffer.from(encoded, "base64url").toString("utf-8");
378
+ } catch {
379
+ return { valid: false, reason: "malformed" };
380
+ }
381
+ if (signedPart.length === 0) {
382
+ return { valid: false, reason: "malformed" };
383
+ }
384
+ const expectedHmac = computeHmac(opts.secret, signedPart);
385
+ if (providedHmac.length !== expectedHmac.length || !import_node_crypto.default.timingSafeEqual(
386
+ Buffer.from(providedHmac, "utf-8"),
387
+ Buffer.from(expectedHmac, "utf-8")
388
+ )) {
389
+ return { valid: false, reason: "bad_signature" };
390
+ }
391
+ const tsDot = signedPart.lastIndexOf(".");
392
+ let payload = signedPart;
393
+ let issuedAt;
394
+ if (tsDot > 0) {
395
+ const tsCandidate = signedPart.slice(tsDot + 1);
396
+ const tsNum = Number(tsCandidate);
397
+ if (Number.isFinite(tsNum) && /^\d+$/.test(tsCandidate)) {
398
+ payload = signedPart.slice(0, tsDot);
399
+ issuedAt = tsNum;
400
+ }
401
+ }
402
+ if (opts.maxAgeSeconds !== void 0 && issuedAt !== void 0) {
403
+ const ageSeconds = Math.floor(Date.now() / 1e3) - issuedAt;
404
+ if (ageSeconds > opts.maxAgeSeconds) {
405
+ return { valid: false, reason: "expired" };
406
+ }
407
+ }
408
+ return issuedAt !== void 0 ? { valid: true, payload, issuedAt } : { valid: true, payload };
409
+ }
410
+
411
+ // src/email-templates/unsubscribe.ts
412
+ function normalizeEmail(email) {
413
+ return email.toLowerCase().trim();
414
+ }
415
+ function createUnsubscribe(cfg) {
416
+ if (!cfg.secret || cfg.secret.length < 16) {
417
+ throw new Error(
418
+ "createUnsubscribe requires `secret` of at least 16 characters"
419
+ );
420
+ }
421
+ if (!cfg.baseUrl) {
422
+ throw new Error("createUnsubscribe requires `baseUrl`");
423
+ }
424
+ const baseUrl = cfg.baseUrl.replace(/\/+$/, "");
425
+ const path = (cfg.path ?? "/unsubscribe").replace(/^\/?/, "/");
426
+ return {
427
+ generateToken(email) {
428
+ return signToken({ payload: normalizeEmail(email), secret: cfg.secret });
429
+ },
430
+ verifyToken(token) {
431
+ const result = verifyToken(token, { secret: cfg.secret });
432
+ return result.valid ? result.payload : null;
433
+ },
434
+ generateUrl(email) {
435
+ const token = signToken({
436
+ payload: normalizeEmail(email),
437
+ secret: cfg.secret
438
+ });
439
+ return `${baseUrl}${path}?token=${encodeURIComponent(token)}`;
440
+ },
441
+ generateListUnsubscribeHeader(email) {
442
+ const token = signToken({
443
+ payload: normalizeEmail(email),
444
+ secret: cfg.secret
445
+ });
446
+ const url = `${baseUrl}${path}?token=${encodeURIComponent(token)}`;
447
+ if (cfg.mailtoUnsubscribe) {
448
+ return `<${url}>, <mailto:${cfg.mailtoUnsubscribe}?subject=unsubscribe>`;
449
+ }
450
+ return `<${url}>`;
451
+ },
452
+ generateListUnsubscribePostHeader() {
453
+ return "List-Unsubscribe=One-Click";
454
+ }
455
+ };
456
+ }
457
+
458
+ // src/interfaces/ILogger.ts
459
+ var NoopLogger = class {
460
+ debug() {
461
+ }
462
+ info() {
463
+ }
464
+ warn() {
465
+ }
466
+ error() {
467
+ }
468
+ child() {
469
+ return this;
470
+ }
471
+ };
472
+
473
+ // src/resilience/retry.ts
474
+ var DEFAULT_RETRY_OPTIONS = {
475
+ maxAttempts: 3,
476
+ baseDelay: 100,
477
+ maxDelay: 1e4,
478
+ backoffMultiplier: 2,
479
+ jitter: true,
480
+ maxJitter: 100
481
+ };
482
+ function sleep(ms) {
483
+ return new Promise((resolve) => setTimeout(resolve, ms));
484
+ }
485
+ function calculateDelay(attempt, options) {
486
+ let delay = options.baseDelay * Math.pow(options.backoffMultiplier, attempt - 1);
487
+ delay = Math.min(delay, options.maxDelay);
488
+ if (options.jitter) {
489
+ const jitter = Math.random() * options.maxJitter;
490
+ delay += jitter;
491
+ }
492
+ return Math.floor(delay);
493
+ }
494
+ async function withRetry(fn, options = {}) {
495
+ const opts = { ...DEFAULT_RETRY_OPTIONS, ...options };
496
+ const logger = opts.logger ?? new NoopLogger();
497
+ let lastError;
498
+ let delay = opts.baseDelay;
499
+ for (let attempt = 1; attempt <= opts.maxAttempts; attempt++) {
500
+ try {
501
+ return await fn();
502
+ } catch (error) {
503
+ lastError = error instanceof Error ? error : new Error(String(error));
504
+ if (opts.abortIf?.(lastError)) {
505
+ logger.debug("Retry aborted - non-retryable error", {
506
+ attempt,
507
+ error: lastError
508
+ });
509
+ throw lastError;
510
+ }
511
+ if (opts.retryIf && !opts.retryIf(lastError)) {
512
+ logger.debug("Retry aborted - error not retryable", {
513
+ attempt,
514
+ error: lastError
515
+ });
516
+ throw lastError;
517
+ }
518
+ if (attempt >= opts.maxAttempts) {
519
+ logger.warn("All retry attempts exhausted", {
520
+ attempts: attempt,
521
+ error: lastError
522
+ });
523
+ throw lastError;
524
+ }
525
+ delay = calculateDelay(attempt, opts);
526
+ logger.debug("Retrying operation", {
527
+ attempt,
528
+ maxAttempts: opts.maxAttempts,
529
+ delay,
530
+ error: lastError
531
+ });
532
+ opts.onRetry?.(lastError, attempt, delay);
533
+ await sleep(delay);
534
+ }
535
+ }
536
+ throw lastError ?? new Error("Retry failed with no error");
537
+ }
538
+ var RetryPredicates = {
539
+ /**
540
+ * Retry on network errors
541
+ */
542
+ networkErrors: (error) => {
543
+ const networkErrorCodes = [
544
+ "ECONNRESET",
545
+ "ECONNREFUSED",
546
+ "ETIMEDOUT",
547
+ "ENOTFOUND",
548
+ "EAI_AGAIN",
549
+ "EHOSTUNREACH",
550
+ "ENETUNREACH"
551
+ ];
552
+ const errorCode = error.code;
553
+ if (errorCode && networkErrorCodes.includes(errorCode)) {
554
+ return true;
555
+ }
556
+ const message = error.message.toLowerCase();
557
+ return message.includes("network") || message.includes("timeout") || message.includes("connection") || message.includes("socket");
558
+ },
559
+ /**
560
+ * Retry on HTTP 5xx errors
561
+ */
562
+ serverErrors: (error) => {
563
+ const statusCode = error.statusCode;
564
+ return statusCode !== void 0 && statusCode >= 500 && statusCode < 600;
565
+ },
566
+ /**
567
+ * Retry on HTTP 429 (rate limit) errors
568
+ */
569
+ rateLimitErrors: (error) => {
570
+ const statusCode = error.statusCode;
571
+ return statusCode === 429;
572
+ },
573
+ /**
574
+ * Retry on database deadlock errors
575
+ */
576
+ deadlockErrors: (error) => {
577
+ const message = error.message.toLowerCase();
578
+ return message.includes("deadlock") || message.includes("lock wait timeout");
579
+ },
580
+ /**
581
+ * Never retry on authentication errors
582
+ */
583
+ authenticationErrors: (error) => {
584
+ const statusCode = error.statusCode;
585
+ return statusCode === 401 || statusCode === 403;
586
+ },
587
+ /**
588
+ * Never retry on validation errors
589
+ */
590
+ validationErrors: (error) => {
591
+ const statusCode = error.statusCode;
592
+ return statusCode === 400 || statusCode === 422;
593
+ }
594
+ };
595
+ var RetryConfigs = {
596
+ /**
597
+ * Fast retry for quick failures
598
+ */
599
+ fast: {
600
+ maxAttempts: 3,
601
+ baseDelay: 50,
602
+ maxDelay: 500,
603
+ backoffMultiplier: 2
604
+ },
605
+ /**
606
+ * Standard retry configuration
607
+ */
608
+ standard: {
609
+ maxAttempts: 3,
610
+ baseDelay: 100,
611
+ maxDelay: 5e3,
612
+ backoffMultiplier: 2
613
+ },
614
+ /**
615
+ * Aggressive retry for critical operations
616
+ */
617
+ aggressive: {
618
+ maxAttempts: 5,
619
+ baseDelay: 200,
620
+ maxDelay: 3e4,
621
+ backoffMultiplier: 2
622
+ },
623
+ /**
624
+ * Conservative retry for rate-limited APIs
625
+ */
626
+ rateLimited: {
627
+ maxAttempts: 3,
628
+ baseDelay: 1e3,
629
+ maxDelay: 6e4,
630
+ backoffMultiplier: 3,
631
+ jitter: true,
632
+ maxJitter: 500
633
+ },
634
+ /**
635
+ * Database retry configuration
636
+ */
637
+ database: {
638
+ maxAttempts: 3,
639
+ baseDelay: 100,
640
+ maxDelay: 5e3,
641
+ backoffMultiplier: 2,
642
+ retryIf: (error) => RetryPredicates.networkErrors(error) || RetryPredicates.deadlockErrors(error),
643
+ abortIf: RetryPredicates.validationErrors
644
+ }
645
+ };
646
+
647
+ // src/resilience/circuit-breaker.ts
648
+ var DEFAULT_CIRCUIT_BREAKER_OPTIONS = {
649
+ failureThreshold: 5,
650
+ resetTimeout: 3e4,
651
+ successThreshold: 3,
652
+ failureWindow: 6e4
653
+ };
654
+ var CircuitOpenError = class extends Error {
655
+ name = "CircuitOpenError";
656
+ circuitName;
657
+ state;
658
+ nextAttemptAt;
659
+ constructor(circuitName, state, resetTimeout) {
660
+ super(
661
+ `Circuit "${circuitName}" is ${state}. Retry after ${resetTimeout}ms.`
662
+ );
663
+ this.circuitName = circuitName;
664
+ this.state = state;
665
+ this.nextAttemptAt = new Date(Date.now() + resetTimeout);
666
+ }
667
+ };
668
+ var CircuitBreaker = class {
669
+ state = "closed";
670
+ failures = 0;
671
+ successes = 0;
672
+ failureTimestamps = [];
673
+ lastFailure;
674
+ lastSuccess;
675
+ lastStateChange;
676
+ lastOpenedAt;
677
+ totalRequests = 0;
678
+ rejectedRequests = 0;
679
+ lastError;
680
+ options;
681
+ logger;
682
+ constructor(options) {
683
+ this.options = {
684
+ ...DEFAULT_CIRCUIT_BREAKER_OPTIONS,
685
+ ...options
686
+ };
687
+ this.logger = options.logger ?? new NoopLogger();
688
+ }
689
+ /**
690
+ * Execute a function with circuit breaker protection
691
+ */
692
+ async execute(fn) {
693
+ this.totalRequests++;
694
+ if (!this.canExecute()) {
695
+ this.rejectedRequests++;
696
+ this.options.onReject?.(this.state);
697
+ throw new CircuitOpenError(
698
+ this.options.name,
699
+ this.state,
700
+ this.getRemainingTimeout()
701
+ );
702
+ }
703
+ try {
704
+ const result = await fn();
705
+ this.onSuccess();
706
+ return result;
707
+ } catch (error) {
708
+ this.onFailure(error instanceof Error ? error : new Error(String(error)));
709
+ throw error;
710
+ }
711
+ }
712
+ /**
713
+ * Check if circuit allows execution
714
+ */
715
+ canExecute() {
716
+ switch (this.state) {
717
+ case "closed":
718
+ return true;
719
+ case "open":
720
+ if (this.shouldAttemptReset()) {
721
+ this.transitionTo("half-open");
722
+ return true;
723
+ }
724
+ return false;
725
+ case "half-open":
726
+ return true;
727
+ default:
728
+ return false;
729
+ }
730
+ }
731
+ /**
732
+ * Record a successful execution
733
+ */
734
+ onSuccess() {
735
+ this.lastSuccess = /* @__PURE__ */ new Date();
736
+ this.successes++;
737
+ switch (this.state) {
738
+ case "half-open":
739
+ if (this.successes >= this.options.successThreshold) {
740
+ this.transitionTo("closed");
741
+ }
742
+ break;
743
+ case "closed":
744
+ this.failures = 0;
745
+ this.failureTimestamps = [];
746
+ break;
747
+ }
748
+ }
749
+ /**
750
+ * Record a failed execution
751
+ */
752
+ onFailure(error) {
753
+ if (this.options.shouldTrip && !this.options.shouldTrip(error)) {
754
+ return;
755
+ }
756
+ this.lastError = error;
757
+ this.lastFailure = /* @__PURE__ */ new Date();
758
+ this.failures++;
759
+ const now = Date.now();
760
+ this.failureTimestamps.push(now);
761
+ const windowStart = now - this.options.failureWindow;
762
+ this.failureTimestamps = this.failureTimestamps.filter(
763
+ (ts) => ts > windowStart
764
+ );
765
+ switch (this.state) {
766
+ case "closed":
767
+ if (this.failureTimestamps.length >= this.options.failureThreshold) {
768
+ this.transitionTo("open");
769
+ this.options.onOpen?.(this.failures, error);
770
+ }
771
+ break;
772
+ case "half-open":
773
+ this.transitionTo("open");
774
+ this.options.onOpen?.(this.failures, error);
775
+ break;
776
+ }
777
+ }
778
+ /**
779
+ * Transition to a new state
780
+ */
781
+ transitionTo(newState) {
782
+ const oldState = this.state;
783
+ if (oldState === newState) return;
784
+ this.state = newState;
785
+ this.lastStateChange = /* @__PURE__ */ new Date();
786
+ this.logger.info(`Circuit "${this.options.name}" state change`, {
787
+ from: oldState,
788
+ to: newState,
789
+ failures: this.failures,
790
+ successes: this.successes
791
+ });
792
+ this.options.onStateChange?.(oldState, newState);
793
+ switch (newState) {
794
+ case "open":
795
+ this.lastOpenedAt = /* @__PURE__ */ new Date();
796
+ this.successes = 0;
797
+ break;
798
+ case "half-open":
799
+ this.successes = 0;
800
+ break;
801
+ case "closed":
802
+ this.failures = 0;
803
+ this.failureTimestamps = [];
804
+ this.successes = 0;
805
+ this.options.onClose?.();
806
+ break;
807
+ }
808
+ }
809
+ /**
810
+ * Check if reset timeout has passed
811
+ */
812
+ shouldAttemptReset() {
813
+ if (!this.lastOpenedAt) return true;
814
+ const elapsed = Date.now() - this.lastOpenedAt.getTime();
815
+ return elapsed >= this.options.resetTimeout;
816
+ }
817
+ /**
818
+ * Get remaining time until reset attempt
819
+ */
820
+ getRemainingTimeout() {
821
+ if (!this.lastOpenedAt) return 0;
822
+ const elapsed = Date.now() - this.lastOpenedAt.getTime();
823
+ return Math.max(0, this.options.resetTimeout - elapsed);
824
+ }
825
+ /**
826
+ * Get current circuit state
827
+ */
828
+ getState() {
829
+ return this.state;
830
+ }
831
+ /**
832
+ * Get circuit breaker statistics
833
+ */
834
+ getStats() {
835
+ return {
836
+ state: this.state,
837
+ failures: this.failures,
838
+ successes: this.successes,
839
+ lastFailure: this.lastFailure,
840
+ lastSuccess: this.lastSuccess,
841
+ lastStateChange: this.lastStateChange,
842
+ totalRequests: this.totalRequests,
843
+ rejectedRequests: this.rejectedRequests
844
+ };
845
+ }
846
+ /**
847
+ * Manually reset the circuit to closed state
848
+ */
849
+ reset() {
850
+ this.transitionTo("closed");
851
+ }
852
+ /**
853
+ * Manually trip the circuit to open state
854
+ */
855
+ trip() {
856
+ this.transitionTo("open");
857
+ }
858
+ /**
859
+ * Check if circuit is open
860
+ */
861
+ isOpen() {
862
+ return this.state === "open";
863
+ }
864
+ /**
865
+ * Check if circuit is closed
866
+ */
867
+ isClosed() {
868
+ return this.state === "closed";
869
+ }
870
+ /**
871
+ * Check if circuit is half-open
872
+ */
873
+ isHalfOpen() {
874
+ return this.state === "half-open";
875
+ }
876
+ };
877
+
878
+ // src/email-templates/transport.ts
879
+ var DEFAULT_RETRY = {
880
+ maxAttempts: 3
881
+ };
882
+ function withTimeout(promise, ms) {
883
+ return new Promise((resolve, reject) => {
884
+ const timer = setTimeout(
885
+ () => reject(new Error(`email send timed out after ${ms}ms`)),
886
+ ms
887
+ );
888
+ promise.then(
889
+ (v) => {
890
+ clearTimeout(timer);
891
+ resolve(v);
892
+ },
893
+ (e) => {
894
+ clearTimeout(timer);
895
+ reject(e);
896
+ }
897
+ );
898
+ });
899
+ }
900
+ function createResilientEmail(inner, options = {}) {
901
+ const retryOpts = options.retry === false ? null : { ...DEFAULT_RETRY, ...options.retry ?? {} };
902
+ const breaker = options.circuitBreaker ? new CircuitBreaker(options.circuitBreaker) : null;
903
+ const timeoutMs = options.timeoutMs;
904
+ const wrapAttempt = async (fn) => {
905
+ if (timeoutMs !== void 0) {
906
+ return withTimeout(fn(), timeoutMs);
907
+ }
908
+ return fn();
909
+ };
910
+ const withResilience = async (fn) => {
911
+ const exec = async () => {
912
+ if (retryOpts) {
913
+ return withRetry(() => wrapAttempt(fn), retryOpts);
914
+ }
915
+ return wrapAttempt(fn);
916
+ };
917
+ if (breaker) {
918
+ return breaker.execute(exec);
919
+ }
920
+ return exec();
921
+ };
922
+ return {
923
+ async send(message) {
924
+ return withResilience(() => inner.send(message));
925
+ },
926
+ async sendBatch(messages) {
927
+ return withResilience(() => inner.sendBatch(messages));
928
+ },
929
+ async healthCheck() {
930
+ return inner.healthCheck();
931
+ }
932
+ };
933
+ }
328
934
  // Annotate the CommonJS export names for ESM import in node:
329
935
  0 && (module.exports = {
330
936
  calloutBlock,
937
+ createResilientEmail,
938
+ createUnsubscribe,
331
939
  dataTable,
332
940
  digestEmail,
333
941
  divider,