diff --git a/package-lock.json b/package-lock.json index 0c05652..ebceef2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0-automated", "license": "MIT", "dependencies": { - "cross-fetch": "^3.1.5" + "@supabase/node-fetch": "^2.6.14" }, "devDependencies": { "@types/jest": "^28.1.0", @@ -1352,6 +1352,17 @@ "@sinonjs/commons": "^1.7.0" } }, + "node_modules/@supabase/node-fetch": { + "version": "2.6.14", + "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.14.tgz", + "integrity": "sha512-w/Tsd22e/5fAeoxqQ4P2MX6EyF+iM6rc9kmlMVFkHuG0rAltt2TLhFbDJfemnHbtvnazWaRfy5KnFU/SYT37dQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + } + }, "node_modules/@testdeck/core": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@testdeck/core/-/core-0.1.2.tgz", @@ -2632,14 +2643,6 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, - "node_modules/cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", - "dependencies": { - "node-fetch": "2.6.7" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -5848,6 +5851,7 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dev": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -12169,6 +12173,14 @@ "@sinonjs/commons": "^1.7.0" } }, + "@supabase/node-fetch": { + "version": "2.6.14", + "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.14.tgz", + "integrity": "sha512-w/Tsd22e/5fAeoxqQ4P2MX6EyF+iM6rc9kmlMVFkHuG0rAltt2TLhFbDJfemnHbtvnazWaRfy5KnFU/SYT37dQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, "@testdeck/core": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@testdeck/core/-/core-0.1.2.tgz", @@ -13198,14 +13210,6 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, - "cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", - "requires": { - "node-fetch": "2.6.7" - } - }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -15594,6 +15598,7 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dev": true, "requires": { "whatwg-url": "^5.0.0" } diff --git a/package.json b/package.json index 05c152d..2aad108 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "homepage": "https://github.com/supabase/functions-js#readme", "dependencies": { - "cross-fetch": "^3.1.5" + "@supabase/node-fetch": "^2.6.14" }, "devDependencies": { "@types/jest": "^28.1.0", diff --git a/src/helper.ts b/src/helper.ts index 9efc01a..cb88f7e 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -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 } diff --git a/src/types.ts b/src/types.ts index 9d9c104..9e0646b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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. */ diff --git a/test/functions/hijack/index.ts b/test/functions/hijack/index.ts index 537e70d..95be677 100644 --- a/test/functions/hijack/index.ts +++ b/test/functions/hijack/index.ts @@ -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 }) diff --git a/test/relay/container.ts b/test/relay/container.ts index a3fec56..acf7450 100644 --- a/test/relay/container.ts +++ b/test/relay/container.ts @@ -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' @@ -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', diff --git a/test/utils/fetch.ts b/test/utils/fetch.ts index 40d7edd..a6491bd 100644 --- a/test/utils/fetch.ts +++ b/test/utils/fetch.ts @@ -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 @@ -11,5 +12,5 @@ export function getCustomFetch( reqInfo: RequestInfo | URL, reqInit?: RequestInit | undefined ): (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise { - return (input, init) => crossFetch(reqInfo, reqInit) + return (input, init) => nodeFetch(reqInfo, reqInit) }