Skip to content

[TS] Signature method of Interceptor using Dispatcher#compose #2982

@clovis-guillemot

Description

@clovis-guillemot

Bug Description

Cannot define a custom Interceptor for Dispatcher#compose using TS

Reproducible By

N/A

Expected Behavior

No change when migrate from interceptors to compose :
From

const client = new Client(url, {
        interceptors: {
            Client: [hawkInterceptor],
        },
})

To :

const client = new Client(url).compose(hawkInterceptor)

Logs & Screenshots

const client = new Client(url).compose(hawkInterceptor)
import * as Hawk from 'hawk'
import {type Dispatcher} from 'undici'

import {getConfig} from '#/utils'
import {getCurrentUniverseUrl} from '#/utils/urls'

export const hawkInterceptor = (dispatch: Dispatcher['dispatch']) => {
    return function HawhAuthorizationHeader(
        opts: Dispatcher.DispatchOptions,
        handler: Dispatcher.DispatchHandlers
    ) {
        const authConfig = getConfig('auth')
        const {header: authorization} = Hawk.client.header(
            `${getCurrentUniverseUrl()}${opts.path}`,
            opts.method,
            {
                credentials: {
                    algorithm: 'sha256',
                    ...authConfig.hawk,
                },
            }
        )
        if (!opts.headers) opts.headers = {}
        if (authorization) {
            opts.headers = {...opts.headers, authorization}
        }
        return dispatch(opts, handler)
    }
}
Capture d’écran 2024-03-22 à 10 08 34

Environment

Node 20
Undici : ^6.10.0 (6.10.1)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypesChanges related to the TypeScript definitionsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions