Skip to content

Commit

Permalink
Export msw handler factory function to support usage within consumers…
Browse files Browse the repository at this point in the history
…' own msw server
  • Loading branch information
mlev committed Jun 29, 2024
1 parent 7600fa7 commit 15f31f3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JwtPayload } from 'jsonwebtoken'
import { createJWKS, createKeyPair, signJwt } from './tools.js'
import { setupServer } from 'msw/node'
import { HttpResponse, http } from 'msw'
import { HttpResponse, http, RequestHandlerOptions } from 'msw'

const createJWKSMock = (

Check failure on line 6 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

The inferred type of 'createJWKSMock' cannot be named without a reference to '../.yarn/unplugged/msw-virtual-92e8948317/node_modules/msw/lib/core/handlers/HttpHandler.js'. This is likely not portable. A type annotation is necessary.
jwksBase: string,
Expand All @@ -12,11 +12,13 @@ const createJWKSMock = (
...keypair,
jwksOrigin: jwksBase,
})
const server = setupServer(
http.get(new URL(jwksPath, jwksBase).href, () =>
HttpResponse.json(JWKS),
const jwksHandler = (options?: RequestHandlerOptions) =>
http.get(
new URL(jwksPath, jwksBase).href,
() => HttpResponse.json(JWKS),
options
)
)
const server = setupServer(jwksHandler())

const kid = () => JWKS.keys[0].kid

Expand All @@ -35,6 +37,7 @@ const createJWKSMock = (
stop,
kid,
token,
jwksHandler,
}
}

Expand Down

0 comments on commit 15f31f3

Please sign in to comment.