Skip to content

fix: use @supabase/node-fetch #62

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

Merged
merged 1 commit into from
Aug 23, 2023
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
39 changes: 22 additions & 17 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 @@
},
"homepage": "https://github.com/supabase/functions-js#readme",
"dependencies": {
"cross-fetch": "^3.1.5"
"@supabase/node-fetch": "^2.6.13"
},
"devDependencies": {
"@types/jest": "^28.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ 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
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type FunctionInvokeOptions = {
/**
* The HTTP verb of the request
*/
method?: "POST"| "GET"| "PUT" | "PATCH" | "DELETE"
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
/**
* The body of the request.
*/
Expand Down
30 changes: 14 additions & 16 deletions test/functions/hijack/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { serve } from 'https://deno.land/std@0.130.0/http/server.ts'

serve((req) => {
const p = Deno.upgradeHttp(req);

(
// Run this async IIFE concurrently, first packet won't arrive
// until we return HTTP101 response.
async () => {
const [conn, firstPacket] = await p
const decoder = new TextDecoder()
const text = decoder.decode(firstPacket)
console.log(text)
// Hello
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
conn.write(uint8Array)
conn.close()
}
)()
const p = Deno.upgradeHttp(req)

// Run this async IIFE concurrently, first packet won't arrive
// until we return HTTP101 response.
;(async () => {
const [conn, firstPacket] = await p
const decoder = new TextDecoder()
const text = decoder.decode(firstPacket)
console.log(text)
// Hello
const uint8Array = new Uint8Array([72, 101, 108, 108, 111])
conn.write(uint8Array)
conn.close()
})()

// HTTP101 - Switching Protocols
return new Response(null, { status: 101 })
Expand Down
5 changes: 3 additions & 2 deletions test/relay/container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs'
import { nanoid } from 'nanoid'
import crossFetch from 'cross-fetch'
// @ts-ignore
import nodeFetch from '@supabase/node-fetch'
import { sign } from 'jsonwebtoken'
import { GenericContainer, Network, StartedTestContainer, Wait } from 'testcontainers'
import { ExecResult } from 'testcontainers/dist/docker/types'
Expand Down Expand Up @@ -87,7 +88,7 @@ export async function runRelay(
log(`check function is healthy: ${slug + '-' + id}`)
for (let ctr = 0; ctr < 30; ctr++) {
try {
const healthCheck = await crossFetch(
const healthCheck = await nodeFetch(
`http://localhost:${startedRelay.getMappedPort(8081)}/${slug}`,
{
method: 'POST',
Expand Down
5 changes: 3 additions & 2 deletions test/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import crossFetch from 'cross-fetch'
// @ts-ignore
import nodeFetch from '@supabase/node-fetch'

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