//native
type Supabase = {
key: string
}
/**
* Create a function
* This endpoint is deprecated - use the deploy endpoint. Creates a function and adds it to the specified project.
*/
export async function main(
auth: Supabase,
ref: string,
slug: string | undefined,
name: string | undefined,
verify_jwt: string | undefined,
import_map: string | undefined,
entrypoint_path: string | undefined,
import_map_path: string | undefined
) {
const url = new URL(`https://api.supabase.com/v1/projects/${ref}/functions`)
for (const [k, v] of [
['slug', slug],
['name', name],
['verify_jwt', verify_jwt],
['import_map', import_map],
['entrypoint_path', entrypoint_path],
['import_map_path', import_map_path]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + auth.key
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 151 days ago