Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
clovis-guillemot opened this issue Mar 22, 2024 · 4 comments · Fixed by #2983
Closed

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

clovis-guillemot opened this issue Mar 22, 2024 · 4 comments · Fixed by #2983
Labels
bug Something isn't working Types Changes related to the TypeScript definitions

Comments

@clovis-guillemot
Copy link
Contributor

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

@clovis-guillemot clovis-guillemot added the bug Something isn't working label Mar 22, 2024
@metcoder95
Copy link
Member

I see the problem, the types define that it expects a dispatch as argument, not a curried function that returns a dispatch.

Would you like to send a PR?

compose(...dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher;

@metcoder95 metcoder95 added the Types Changes related to the TypeScript definitions label Mar 22, 2024
@clovis-guillemot
Copy link
Contributor Author

clovis-guillemot commented Mar 22, 2024

I see the problem, the types define that it expects a dispatch as argument, not a curried function that returns a dispatch.

Would you like to send a PR?

compose(...dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher;

Yes I can send a PR for that. Using DispatcherInterceptor type maybe ? Or will be also deprecated ?

@clovis-guillemot
Copy link
Contributor Author

can you approve workflows on my PR @metcoder95 , please ?

@clovis-guillemot
Copy link
Contributor Author

Codecov report seems OK ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Types Changes related to the TypeScript definitions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants