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(browser): avoid global-conflicting variable name fetch #199

Merged
merged 2 commits into from
May 14, 2021
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"lint": "eslint --config ./src/.eslintrc.json ./src",
"runtime-browser": "run-s runtime:clear runtime:browser:* runtime:refs",
"runtime-node": "run-s runtime:clear runtime:node:* runtime:refs",
"runtime-node-webcrypto": "run-s runtime:clear runtime:browser:* && cp ./src/runtime/node/webcrypto.ts ./src/runtime/ && cp ./src/runtime/node/fetch.ts ./src/runtime/ && cp ./src/runtime/node/base64url.ts ./src/runtime/ && cp ./src/runtime/node/zlib.ts ./src/runtime/ && run-s runtime:refs",
"runtime-node-webcrypto": "run-s runtime:clear runtime:browser:* && cp ./src/runtime/node/webcrypto.ts ./src/runtime/ && cp ./src/runtime/node/fetch_jwks.ts ./src/runtime/ && cp ./src/runtime/node/base64url.ts ./src/runtime/ && cp ./src/runtime/node/zlib.ts ./src/runtime/ && run-s runtime:refs",
"runtime:browser:copy": "cp ./src/runtime/browser/*.ts ./src/runtime",
"runtime:clear": "run-s -s runtime:find | xargs -0 rm -f",
"runtime:find": "find src/runtime -not -name '*.d.ts' -maxdepth 1 -type f -print0",
Expand Down
4 changes: 2 additions & 2 deletions src/jwks/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
JWKSNoMatchingKey,
JWKSMultipleMatchingKeys,
} from '../util/errors.js'
import fetchJson from '../runtime/fetch.js'
import fetchJwks from '../runtime/fetch_jwks.js'
import isObject from '../lib/is_object.js'

function getKtyFromAlg(alg: string) {
Expand Down Expand Up @@ -187,7 +187,7 @@ class RemoteJWKSet {

async reload() {
if (!this._pendingFetch) {
this._pendingFetch = fetchJson(this._url, this._timeoutDuration, this._options)
this._pendingFetch = fetchJwks(this._url, this._timeoutDuration, this._options)
.then((json) => {
if (
typeof json !== 'object' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FetchFunction } from '../interfaces.d'
import { JOSEError } from '../../util/errors.js'
import globalThis from './global.js'

const fetch: FetchFunction = async (url: URL, timeout: number) => {
const fetchJwks: FetchFunction = async (url: URL, timeout: number) => {
let controller!: AbortController
if (typeof AbortController === 'function') {
controller = new AbortController()
Expand All @@ -28,4 +28,4 @@ const fetch: FetchFunction = async (url: URL, timeout: number) => {
throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON')
}
}
export default fetch
export default fetchJwks
8 changes: 6 additions & 2 deletions src/runtime/node/fetch.ts → src/runtime/node/fetch_jwks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const protocols: { [protocol: string]: (...args: Parameters<typeof https>) => Cl

type AcceptedRequestOptions = Pick<RequestOptions, 'agent'>

const fetch: FetchFunction = async (url: URL, timeout: number, options: AcceptedRequestOptions) => {
const fetchJwks: FetchFunction = async (
url: URL,
timeout: number,
options: AcceptedRequestOptions,
) => {
if (protocols[url.protocol] === undefined) {
throw new TypeError('Unsupported URL protocol.')
}
Expand Down Expand Up @@ -46,4 +50,4 @@ const fetch: FetchFunction = async (url: URL, timeout: number, options: Accepted
}
}

export default fetch
export default fetchJwks