1 | |
2 | type Supabase = { |
3 | key: string |
4 | } |
5 | |
6 | * Create a function |
7 | * This endpoint is deprecated - use the deploy endpoint. Creates a function and adds it to the specified project. |
8 | */ |
9 | export async function main( |
10 | auth: Supabase, |
11 | ref: string, |
12 | slug: string | undefined, |
13 | name: string | undefined, |
14 | verify_jwt: string | undefined, |
15 | import_map: string | undefined, |
16 | entrypoint_path: string | undefined, |
17 | import_map_path: string | undefined |
18 | ) { |
19 | const url = new URL(`https://api.supabase.com/v1/projects/${ref}/functions`) |
20 | for (const [k, v] of [ |
21 | ['slug', slug], |
22 | ['name', name], |
23 | ['verify_jwt', verify_jwt], |
24 | ['import_map', import_map], |
25 | ['entrypoint_path', entrypoint_path], |
26 | ['import_map_path', import_map_path] |
27 | ]) { |
28 | if (v !== undefined && v !== '' && k !== undefined) { |
29 | url.searchParams.append(k, v) |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: 'POST', |
34 | headers: { |
35 | Authorization: 'Bearer ' + auth.key |
36 | }, |
37 | body: undefined |
38 | }) |
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 | return await response.json() |
44 | } |
45 |
|