Bulk update functions
One script reply has been approved by the moderators Verified

Bulk update functions. It will create a new function or replace existing. The operation is idempotent. NOTE: You will need to manually bump the version.

Created by hugo697 154 days ago
Submitted by hugo697 Bun
Verified 154 days ago
1
//native
2
type Supabase = {
3
	key: string
4
}
5
/**
6
 * Bulk update functions
7
 * Bulk update functions. It will create a new function or replace existing. The operation is idempotent. NOTE: You will need to manually bump the version.
8
 */
9
export async function main(
10
	auth: Supabase,
11
	ref: string,
12
	body: {
13
		id: string
14
		slug: string
15
		name: string
16
		status: 'ACTIVE' | 'REMOVED' | 'THROTTLED'
17
		version: number
18
		created_at?: number
19
		verify_jwt?: false | true
20
		import_map?: false | true
21
		entrypoint_path?: string
22
		import_map_path?: string
23
	}[]
24
) {
25
	const url = new URL(`https://api.supabase.com/v1/projects/${ref}/functions`)
26

27
	const response = await fetch(url, {
28
		method: 'PUT',
29
		headers: {
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.key
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41