Edits history of script submission #20852 for ' Bulk update functions (supabase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Supabase = {
    	key: string
    }
    /**
     * Bulk update functions
     * 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.
     */
    export async function main(
    	auth: Supabase,
    	ref: string,
    	body: {
    		id: string
    		slug: string
    		name: string
    		status: 'ACTIVE' | 'REMOVED' | 'THROTTLED'
    		version: number
    		created_at?: number
    		verify_jwt?: false | true
    		import_map?: false | true
    		entrypoint_path?: string
    		import_map_path?: string
    	}[]
    ) {
    	const url = new URL(`https://api.supabase.com/v1/projects/${ref}/functions`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.key
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 207 days ago