//native
type Supabase = {
key: string
}
/**
* Deploy a function
* A new endpoint to deploy functions. It will create if function does not exist.
*/
export async function main(
auth: Supabase,
ref: string,
slug: string | undefined,
bundleOnly: string | undefined,
body: {
file?: string[]
metadata: {
entrypoint_path: string
import_map_path?: string
static_patterns?: string[]
verify_jwt?: false | true
name?: string
}
}
) {
const url = new URL(`https://api.supabase.com/v1/projects/${ref}/functions/deploy`)
for (const [k, v] of [
['slug', slug],
['bundleOnly', bundleOnly]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const formData = new FormData()
for (const [k, v] of Object.entries(body)) {
if (v !== undefined) {
formData.append(k, String(v))
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + auth.key
},
body: formData
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 151 days ago