Edits history of script submission #12652 for ' Create a compute endpoint (neondb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Neondb = {
    	apiKey: string
    }
    /**
     * Create a compute endpoint
     * Creates a compute endpoint for the specified branch.
     */
    export async function main(
    	auth: Neondb,
    	project_id: string,
    	body: {
    		endpoint: {
    			branch_id: string
    			region_id?: string
    			type: 'read_only' | 'read_write'
    			settings?: { pg_settings?: {}; pgbouncer_settings?: {} }
    			autoscaling_limit_min_cu?: number
    			autoscaling_limit_max_cu?: number
    			provisioner?: string
    			pooler_enabled?: false | true
    			pooler_mode?: 'transaction'
    			disabled?: false | true
    			passwordless_access?: false | true
    			suspend_timeout_seconds?: number
    		}
    	}
    ) {
    	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/endpoints`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		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 428 days ago