Skip to main content
Home
This release is 1 version behind 0.3.1 — the latest version of @upyo/pool. Jump to latest

@upyo/pool@0.3.0-dev.36+e7618f03
Built and signed on GitHub Actions

Pool transport for Upyo email library—provides load balancing and failover for multiple email providers

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (0.3.0-dev.36+e7618f03)
class PoolTransport
implements Transport, AsyncDisposable

Pool transport that combines multiple transports with various load balancing and failover strategies.

This transport implements the same Transport interface, making it a drop-in replacement for any single transport. It distributes messages across multiple underlying transports based on the configured strategy.

Examples

Round-robin load balancing

import { PoolTransport } from "@upyo/pool";

const transport = new PoolTransport({
  strategy: "round-robin",
  transports: [
    { transport: mailgunTransport },
    { transport: sendgridTransport },
    { transport: sesTransport },
  ],
});

Priority-based failover

const transport = new PoolTransport({
  strategy: "priority",
  transports: [
    { transport: primaryTransport, priority: 100 },
    { transport: backupTransport, priority: 50 },
    { transport: lastResortTransport, priority: 10 },
  ],
});

Custom routing with selectors

const transport = new PoolTransport({
  strategy: "selector-based",
  transports: [
    {
      transport: bulkEmailTransport,
      selector: (msg) => msg.tags?.includes("newsletter"),
    },
    {
      transport: transactionalTransport,
      selector: (msg) => msg.priority === "high",
    },
    { transport: defaultTransport }, // Catches everything else
  ],
});

Constructors

new
PoolTransport(config: PoolConfig)

Creates a new PoolTransport instance.

Properties

The resolved configuration used by this pool transport.

private
readonly
strategy: Strategy

Methods

Disposes of all underlying transports that support disposal.

This method is called automatically when using the await using syntax. It ensures proper cleanup of resources held by the underlying transports.

private
createSendOptions(options?: TransportOptions): TransportOptions | undefined

Creates send options with timeout if configured.

Creates a strategy instance based on the strategy type or returns the provided strategy.

send(
message: Message,
options?: TransportOptions,
): Promise<Receipt>

Sends a single email message using the pool strategy.

The transport is selected based on the configured strategy. If the selected transport fails, the pool will retry with other transports up to the configured retry limit.

sendMany(
messages: Iterable<Message> | AsyncIterable<Message>,
options?: TransportOptions,
): AsyncIterable<Receipt>

Sends multiple email messages using the pool strategy.

Each message is sent individually using the send method, respecting the configured strategy and retry logic.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";
or

Import directly with a jsr specifier

import { PoolTransport } from "jsr:@upyo/pool";

Add Package

pnpm i jsr:@upyo/pool
or (using pnpm 10.8 or older)
pnpm dlx jsr add @upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";

Add Package

yarn add jsr:@upyo/pool
or (using Yarn 4.8 or older)
yarn dlx jsr add @upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";

Add Package

vlt install jsr:@upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";

Add Package

npx jsr add @upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";

Add Package

bunx jsr add @upyo/pool

Import symbol

import { PoolTransport } from "@upyo/pool";