Edits history of script submission #12673 for ' Get a list of operations (neondb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Neondb = {
    	apiKey: string
    }
    /**
     * Get a list of operations
     * Retrieves a list of operations for the specified Neon project.
    You can obtain a `project_id` by listing the projects for your Neon account.
    The number of operations returned can be large.
    To paginate the response, issue an initial request with a `limit` value.
    Then, add the `cursor` value that was returned in the response to the next request.
    
     */
    export async function main(
    	auth: Neondb,
    	project_id: string,
    	cursor: string | undefined,
    	limit: string | undefined
    ) {
    	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}/operations`)
    	for (const [k, v] of [
    		['cursor', cursor],
    		['limit', limit]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago