Skip to content

Commit 08a976d

Browse files
committed
fix: use @supabase/node-fetch
1 parent ae31b44 commit 08a976d

File tree

7 files changed

+46
-40
lines changed

7 files changed

+46
-40
lines changed

package-lock.json

Lines changed: 22 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"homepage": "https://github.com/supabase/functions-js#readme",
3838
"dependencies": {
39-
"cross-fetch": "^3.1.5"
39+
"@supabase/node-fetch": "^2.6.14"
4040
},
4141
"devDependencies": {
4242
"@types/jest": "^28.1.0",

src/helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => {
55
if (customFetch) {
66
_fetch = customFetch
77
} else if (typeof fetch === 'undefined') {
8-
_fetch = async (...args) => await (await import('cross-fetch')).fetch(...args)
8+
_fetch = (...args) =>
9+
import('@supabase/node-fetch' as any).then(({ default: fetch }) => fetch(...args))
910
} else {
1011
_fetch = fetch
1112
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type FunctionInvokeOptions = {
4949
/**
5050
* The HTTP verb of the request
5151
*/
52-
method?: "POST"| "GET"| "PUT" | "PATCH" | "DELETE"
52+
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
5353
/**
5454
* The body of the request.
5555
*/

test/functions/hijack/index.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { serve } from 'https://deno.land/std@0.130.0/http/server.ts'
22

33
serve((req) => {
4-
const p = Deno.upgradeHttp(req);
5-
6-
(
7-
// Run this async IIFE concurrently, first packet won't arrive
8-
// until we return HTTP101 response.
9-
async () => {
10-
const [conn, firstPacket] = await p
11-
const decoder = new TextDecoder()
12-
const text = decoder.decode(firstPacket)
13-
console.log(text)
14-
// Hello
15-
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
16-
conn.write(uint8Array)
17-
conn.close()
18-
}
19-
)()
4+
const p = Deno.upgradeHttp(req)
5+
6+
// Run this async IIFE concurrently, first packet won't arrive
7+
// until we return HTTP101 response.
8+
;(async () => {
9+
const [conn, firstPacket] = await p
10+
const decoder = new TextDecoder()
11+
const text = decoder.decode(firstPacket)
12+
console.log(text)
13+
// Hello
14+
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
15+
conn.write(uint8Array)
16+
conn.close()
17+
})()
2018

2119
// HTTP101 - Switching Protocols
2220
return new Response(null, { status: 101 })

test/relay/container.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs'
22
import { nanoid } from 'nanoid'
3-
import crossFetch from 'cross-fetch'
3+
// @ts-ignore
4+
import nodeFetch from '@supabase/node-fetch'
45
import { sign } from 'jsonwebtoken'
56
import { GenericContainer, Network, StartedTestContainer, Wait } from 'testcontainers'
67
import { ExecResult } from 'testcontainers/dist/docker/types'
@@ -87,7 +88,7 @@ export async function runRelay(
8788
log(`check function is healthy: ${slug + '-' + id}`)
8889
for (let ctr = 0; ctr < 30; ctr++) {
8990
try {
90-
const healthCheck = await crossFetch(
91+
const healthCheck = await nodeFetch(
9192
`http://localhost:${startedRelay.getMappedPort(8081)}/${slug}`,
9293
{
9394
method: 'POST',

test/utils/fetch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import crossFetch from 'cross-fetch'
1+
// @ts-ignore
2+
import nodeFetch from '@supabase/node-fetch'
23

34
/**
45
* It returns a crossFetch function that uses overridden input: RequestInfo and init?: RequestInit for
@@ -11,5 +12,5 @@ export function getCustomFetch(
1112
reqInfo: RequestInfo | URL,
1213
reqInit?: RequestInit | undefined
1314
): (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response> {
14-
return (input, init) => crossFetch(reqInfo, reqInit)
15+
return (input, init) => nodeFetch(reqInfo, reqInit)
1516
}

0 commit comments

Comments
 (0)