Skip to content

Commit

Permalink
fix(deps): update dependency openapi-fetch to ^0.13.0 (#5229)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency openapi-fetch to ^0.13.0

* Fix types

---------

Co-authored-by: Olga Bulat <[email protected]>
  • Loading branch information
openverse-bot and obulat authored Dec 5, 2024
1 parent 81f0edb commit fbda21a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/js/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"vitest": "^2.1.4"
},
"dependencies": {
"openapi-fetch": "^0.11.2"
"openapi-fetch": "^0.13.0"
}
}
17 changes: 14 additions & 3 deletions packages/js/api-client/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Middleware } from "openapi-fetch"
import type { MiddlewareCallbackParams } from "openapi-fetch"
import type { components } from "./generated/openverse"
import type { OpenverseClient, ClientCredentials } from "./types"

Expand All @@ -11,7 +11,15 @@ type OAuth2Token = components["schemas"]["OAuth2Token"]
const currTimestamp = (): number => Math.floor(Date.now() / 1e3)
export const EXPIRY_THRESHOLD = 5 // seconds

export class OpenverseAuthMiddleware implements Middleware {
type MiddlewareOnRequest = (
options: MiddlewareCallbackParams
) => void | Request | undefined | Promise<Request | undefined | void>

interface OpenverseMiddleware {
onRequest: MiddlewareOnRequest
}

export class OpenverseAuthMiddleware implements OpenverseMiddleware {
/**
* An Openverse REST API client.
*
Expand Down Expand Up @@ -57,7 +65,10 @@ export class OpenverseAuthMiddleware implements Middleware {
this.credentials = credentials
}

onRequest: Middleware["onRequest"] = async ({ schemaPath, request }) => {
onRequest: OpenverseMiddleware["onRequest"] = async ({
schemaPath,
request,
}) => {
if (schemaPath == "/v1/auth_tokens/token/") {
// Do not send auth headers for token generation requests
return request
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbda21a

Please sign in to comment.