import { M as Middleware, S as SendContext } from "../packem_shared/types.d-CRs03TYV.js"; export { type a as SendFunction, c as composeMiddleware } from "../packem_shared/types.d-CRs03TYV.js"; import { C as ChannelType, B as BaseNotificationPayload } from "../packem_shared/types.d-C7l7qdMG.js"; import { A as Attributes, C as Context, T as Tracer } from "../packem_shared/tracer.d-BPznIQx9.js"; interface CircuitBreakerMiddlewareOptions { /** Time in ms the circuit stays open before a trial request (default 30000). */ resetTimeout?: number; /** Consecutive failures before the circuit opens (default 5). */ threshold?: number; } /** * Trips a circuit after consecutive failures, short-circuiting further sends until a * cool-off elapses (then allows a single trial request). * @param options Failure `threshold` and open-circuit `resetTimeout` (ms). * @returns A middleware. */ declare const circuitBreakerMiddleware: (options?: CircuitBreakerMiddlewareOptions) => Middleware; interface DedupeMiddlewareOptions { /** Derive the dedupe key (default: `payload.idempotencyKey`). */ keyFn?: (context: SendContext) => string | undefined; /** How long a key is remembered, in ms (default 60000). */ ttl?: number; } /** * Suppresses duplicate sends within a TTL window, keyed by idempotency key. A suppressed * send resolves successfully with `sent: false` and a `deduped:` message id. * @param options Custom `keyFn` and `ttl` (ms) controlling how keys are derived and expire. * @returns A middleware. */ declare const dedupeMiddleware: (options?: DedupeMiddlewareOptions) => Middleware; interface LoggingMiddlewareOptions { /** Console-like logger (default `console`). */ logger?: Console; } /** * Logs each send attempt and its outcome. * @param options Provide a custom console-like `logger` (defaults to the global console). * @returns A middleware. */ declare const loggingMiddleware: (options?: LoggingMiddlewareOptions) => Middleware; interface RateLimitMiddlewareOptions { /** Time window in ms over which `rate` tokens are available (default 1000). */ interval?: number; /** Number of sends allowed per `interval` (token bucket capacity). */ rate: number; } /** * Throttles sends with a token-bucket rate limiter. * @param options Bucket `rate` (capacity) and refill `interval` (ms). * @returns A middleware. */ declare const rateLimitMiddleware: (options: RateLimitMiddlewareOptions) => Middleware; interface RetryMiddlewareOptions { /** Base backoff delay in ms (default 250). */ baseDelay?: number; /** Maximum retry attempts after the first try (default 3). */ retries?: number; /** Decide whether a failed result is retryable (default: always retry). */ shouldRetry?: (error: unknown) => boolean; } /** * Retries failed sends with exponential backoff + jitter. * @param options Attempt count (`retries`), `baseDelay` (ms) and a `shouldRetry` predicate. * @returns A middleware. */ declare const retryMiddleware: (options?: RetryMiddlewareOptions) => Middleware; /** * Options for {@link suppressionMiddleware}. */ interface SuppressionMiddlewareOptions { /** Returns whether a recipient is suppressed on a channel (unsubscribed, hard-bounced); may be async. */ isSuppressed: (recipient: string, channel: ChannelType) => boolean | Promise; /** Resolves the recipient identifier from a payload. Defaults to a stringified `payload.to`. */ resolveRecipient?: (payload: BaseNotificationPayload) => string | undefined; } /** * Short-circuits sends to suppressed recipients (unsubscribed, hard-bounced, ...). When the resolved * recipient is suppressed the send resolves successfully with `sent: false` and a `suppressed:` message * id, mirroring how {@link import("./dedupe").dedupeMiddleware} returns a synthetic success. * * Edge-safe: pure logic with no Node built-ins, so it runs on Cloudflare Workers and other edge runtimes. * @param options Suppression check and optional recipient resolver. See {@link SuppressionMiddlewareOptions}. * @returns A middleware. */ declare const suppressionMiddleware: (options: SuppressionMiddlewareOptions) => Middleware; /** * Advisory options influencing aggregation configuration parameters. * * @since 1.7.0 * @experimental */ interface MetricAdvice { /** * Hint the explicit bucket boundaries for SDK if the metric is been * aggregated with a HistogramAggregator. */ explicitBucketBoundaries?: number[]; } /** * Options needed for metric creation * * @since 1.3.0 */ interface MetricOptions { /** * The description of the Metric. * @default '' */ description?: string; /** * The unit of the Metric values. * @default '' */ unit?: string; /** * Indicates the type of the recorded value. * @default {@link ValueType.DOUBLE} */ valueType?: ValueType; /** * The advice influencing aggregation configuration parameters. * @experimental * @since 1.7.0 */ advice?: MetricAdvice; } /** * The Type of value. It describes how the data is reported. * * @since 1.3.0 */ declare enum ValueType { INT = 0, DOUBLE = 1 } /** * Counter is the most common synchronous instrument. This instrument supports * an `Add(increment)` function for reporting a sum, and is restricted to * non-negative increments. The default aggregation is Sum, as for any additive * instrument. * * Example uses for Counter: *
    *
  1. count the number of bytes received.
  2. *
  3. count the number of requests completed.
  4. *
  5. count the number of accounts created.
  6. *
  7. count the number of checkpoints run.
  8. *
  9. count the number of 5xx errors.
  10. *
      * * @since 1.3.0 */ interface Counter { /** * Increment value of counter by the input. Inputs must not be negative. */ add(value: number, attributes?: AttributesTypes, context?: Context): void; } /** * @since 1.3.0 */ interface UpDownCounter { /** * Increment value of counter by the input. Inputs may be negative. */ add(value: number, attributes?: AttributesTypes, context?: Context): void; } /** * @since 1.9.0 */ interface Gauge { /** * Records a measurement. */ record(value: number, attributes?: AttributesTypes, context?: Context): void; } /** * @since 1.3.0 */ interface Histogram { /** * Records a measurement. Value of the measurement must not be negative. */ record(value: number, attributes?: AttributesTypes, context?: Context): void; } /** * @deprecated please use {@link Attributes} * @since 1.3.0 */ type MetricAttributes = Attributes; /** * Interface that is being used in callback function for Observable Metric. * * @since 1.3.0 */ interface ObservableResult { /** * Observe a measurement of the value associated with the given attributes. * * @param value The value to be observed. * @param attributes The attributes associated with the value. If more than * one value is associated with the same attributes values, SDK may pick the * last one or simply drop the entire observable result. */ observe(this: ObservableResult, value: number, attributes?: AttributesTypes): void; } /** * Interface that is being used in batch observable callback function. */ interface BatchObservableResult { /** * Observe a measurement of the value associated with the given attributes. * * @param metric The observable metric to be observed. * @param value The value to be observed. * @param attributes The attributes associated with the value. If more than * one value is associated with the same attributes values, SDK may pick the * last one or simply drop the entire observable result. */ observe(this: BatchObservableResult, metric: Observable, value: number, attributes?: AttributesTypes): void; } /** * The observable callback for Observable instruments. * * @since 1.3.0 */ type ObservableCallback = (observableResult: ObservableResult) => void | Promise; /** * The observable callback for a batch of Observable instruments. * * @since 1.3.0 */ type BatchObservableCallback = (observableResult: BatchObservableResult) => void | Promise; /** * @since 1.3.0 */ interface Observable { /** * Sets up a function that will be called whenever a metric collection is initiated. * * If the function is already in the list of callbacks for this Observable, the function is not added a second time. */ addCallback(callback: ObservableCallback): void; /** * Removes a callback previously registered with {@link Observable.addCallback}. */ removeCallback(callback: ObservableCallback): void; } /** * @since 1.3.0 */ type ObservableCounter = Observable; /** * @since 1.3.0 */ type ObservableUpDownCounter = Observable; /** * @since 1.3.0 */ type ObservableGauge = Observable; /** * An interface to allow the recording metrics. * * {@link Metric}s are used for recording pre-defined aggregation (`Counter`), * or raw values (`Histogram`) in which the aggregation and attributes * for the exported metric are deferred. * * @since 1.3.0 */ interface Meter { /** * Creates and returns a new `Gauge`. * @param name the name of the metric. * @param [options] the metric options. */ createGauge(name: string, options?: MetricOptions): Gauge; /** * Creates and returns a new `Histogram`. * @param name the name of the metric. * @param [options] the metric options. */ createHistogram(name: string, options?: MetricOptions): Histogram; /** * Creates a new `Counter` metric. Generally, this kind of metric when the * value is a quantity, the sum is of primary interest, and the event count * and value distribution are not of primary interest. * @param name the name of the metric. * @param [options] the metric options. */ createCounter(name: string, options?: MetricOptions): Counter; /** * Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous * instrument and very similar to Counter except that Add(increment) * supports negative increments. It is generally useful for capturing changes * in an amount of resources used, or any quantity that rises and falls * during a request. * Example uses for UpDownCounter: *
        *
      1. count the number of active requests.
      2. *
      3. count memory in use by instrumenting new and delete.
      4. *
      5. count queue size by instrumenting enqueue and dequeue.
      6. *
      7. count semaphore up and down operations.
      8. *
      * * @param name the name of the metric. * @param [options] the metric options. */ createUpDownCounter(name: string, options?: MetricOptions): UpDownCounter; /** * Creates a new `ObservableGauge` metric. * * The callback SHOULD be safe to be invoked concurrently. * * @param name the name of the metric. * @param [options] the metric options. */ createObservableGauge(name: string, options?: MetricOptions): ObservableGauge; /** * Creates a new `ObservableCounter` metric. * * The callback SHOULD be safe to be invoked concurrently. * * @param name the name of the metric. * @param [options] the metric options. */ createObservableCounter(name: string, options?: MetricOptions): ObservableCounter; /** * Creates a new `ObservableUpDownCounter` metric. * * The callback SHOULD be safe to be invoked concurrently. * * @param name the name of the metric. * @param [options] the metric options. */ createObservableUpDownCounter(name: string, options?: MetricOptions): ObservableUpDownCounter; /** * Sets up a function that will be called whenever a metric collection is * initiated. * * If the function is already in the list of callbacks for this Observable, * the function is not added a second time. * * Only the associated observables can be observed in the callback. * Measurements of observables that are not associated observed in the * callback are dropped. * * @param callback the batch observable callback * @param observables the observables associated with this batch observable callback */ addBatchObservableCallback(callback: BatchObservableCallback, observables: Observable[]): void; /** * Removes a callback previously registered with {@link Meter.addBatchObservableCallback}. * * The callback to be removed is identified using a combination of the callback itself, * and the set of the observables associated with it. * * @param callback the batch observable callback * @param observables the observables associated with this batch observable callback */ removeBatchObservableCallback(callback: BatchObservableCallback, observables: Observable[]): void; } interface TelemetryMiddlewareOptions { /** * The OpenTelemetry {@link Meter} used to record a send counter and duration histogram. * When omitted, no metrics are recorded. */ meter?: Meter; /** * The OpenTelemetry {@link Tracer} used to create a span per send. When omitted, no span * is recorded (keeping `@opentelemetry/api` an optional peer dependency). */ tracer?: Tracer; } /** * Records an OpenTelemetry span plus a send counter and duration histogram for each send. * Edge-safe: `@opentelemetry/api` is runtime-agnostic and both the tracer and meter are * injected, so nothing is emitted until the host application supplies them. * @param options Provide a `tracer` and/or `meter` to enable tracing and metrics. * @returns A middleware. */ declare const telemetryMiddleware: (options?: TelemetryMiddlewareOptions) => Middleware; export { type CircuitBreakerMiddlewareOptions, type DedupeMiddlewareOptions, type LoggingMiddlewareOptions, type Middleware, type RateLimitMiddlewareOptions, type RetryMiddlewareOptions, type SendContext, type SuppressionMiddlewareOptions, type TelemetryMiddlewareOptions, circuitBreakerMiddleware, dedupeMiddleware, loggingMiddleware, rateLimitMiddleware, retryMiddleware, suppressionMiddleware, telemetryMiddleware };