Edits history of script submission #15195 for ' Set CORS settings (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Set CORS settings
     * The *Set CORS settings* endpoint allows you to register allowed origins (i.e. your domains) for use in cross-origin resource sharing ([CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)).
     
    Enabling CORS with Codat is required by our embeddable UIs (such as [Connections SDK](https://docs.codat.io/auth-flow/optimize/connection-management) and [Link SDK](https://docs.codat.io/auth-flow/authorize-embedded-link)) to access Codat's API endpoints.
     */
    export async function main(auth: Codat, body: { allowedOrigins?: string[] }) {
    	const url = new URL(`https://api.codat.io/corsSettings`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: `Basic ${auth.encodedKey}`
    		},
    		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 235 days ago