Logos DX
    Preparing search index...

    Interface FetchPlugin<H, P, S>

    Plugin contract for extending FetchEngine with hook-based behavior.

    Plugins wrap existing functionality (cache, dedupe, rate-limit) or add new capabilities by registering hooks on the engine. Each plugin returns an unsubscribe function from install() for cleanup.

    function authPlugin(getToken: () => Promise<string>) {
    return {
    name: 'auth',
    install(engine) {
    return engine.hooks.add('beforeRequest', async (url, opts, ctx) => {
    const token = await getToken();
    ctx.args(url, { ...opts, headers: { ...opts.headers, Authorization: `Bearer ${token}` } });
    });
    }
    } satisfies FetchPlugin;
    }
    interface FetchPlugin<H = unknown, P = unknown, S = unknown> {
        hooks?: HookEngine<any, [string]>;
        name: string;
        install(engine: FetchEnginePublic<H, P, S>): () => void;
        reconfigure?(value: unknown): void;
        reconfigureGuard?(pendingValue: unknown): void;
    }

    Type Parameters

    • H = unknown

      Headers type

    • P = unknown

      Params type

    • S = unknown

      State type

    Index

    Properties

    hooks?: HookEngine<any, [string]>
    name: string

    Methods

    • Re-applies the plugin's owned policy config after a runtime engine.config.set() on the matching key (retry, dedupePolicy, cachePolicy, rateLimitPolicy, or cookies).

      Optional — a plugin that doesn't implement it is left untouched by runtime config changes; the engine only invokes it when present.

      Parameters

      • value: unknown

        The full, up-to-date value of the plugin's config key

      Returns void

    • Pre-mutation guard for a runtime config.set() on the plugin's owned policy key, consulted by the engine's ownership validator after the ownership check passes but BEFORE the store mutates.

      Throw to reject the whole set() call — single-key or multi-key merge — leaving the store unchanged and skipping reconfigure entirely. Use this for changes reconfigure can't safely apply in place (e.g. the cache plugin rejects an adapter swap: its store is bound to the original adapter at construction).

      Optional — a plugin that doesn't implement it accepts any value for its key.

      Parameters

      • pendingValue: unknown

        The value the plugin's config key would take on if this set() call were applied

      Returns void