Skip to content

Commit

Permalink
Merge pull request #175 from supabase/fix/supabase-node-fetch
Browse files Browse the repository at this point in the history
fix: use @supabase/node-fetch
  • Loading branch information
soedirgo authored Aug 23, 2023
2 parents b2e3486 + 3640e8a commit dc1d067
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 89 deletions.
144 changes: 60 additions & 84 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"docs:json": "typedoc --json docs/v2/spec.json --entryPoints src/index.ts --entryPoints src/packages/* --excludePrivate --excludeExternals --excludeProtected"
},
"dependencies": {
"cross-fetch": "^3.1.5"
"@supabase/node-fetch": "^2.6.13"
},
"devDependencies": {
"@types/jest": "^26.0.13",
Expand Down
8 changes: 5 additions & 3 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => {
if (customFetch) {
_fetch = customFetch
} else if (typeof fetch === 'undefined') {
_fetch = async (...args) => await (await import('cross-fetch')).fetch(...args)
_fetch = (...args) =>
import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
} else {
_fetch = fetch
}
return (...args) => _fetch(...args)
}

export const resolveResponse = async () => {
export const resolveResponse = async (): Promise<typeof Response> => {
if (typeof Response === 'undefined') {
return (await import('cross-fetch')).Response
// @ts-ignore
return (await import('@supabase/node-fetch' as any)).Response
}

return Response
Expand Down
3 changes: 2 additions & 1 deletion test/storageFileApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as fs from 'fs'
import * as path from 'path'
import FormData from 'form-data'
import assert from 'assert'
import fetch from 'cross-fetch'
// @ts-ignore
import fetch from '@supabase/node-fetch'

// TODO: need to setup storage-api server for this test
const URL = 'http://localhost:8000/storage/v1'
Expand Down

0 comments on commit dc1d067

Please sign in to comment.