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

fix(deps): update dependency openapi-fetch to ^0.13.0 #5229

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading