Edits history of script submission #10684 for ' Patch project-level claims (circleci)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Circleci = {
    	token: string
    }
    /**
     * Patch project-level claims
     * Creates/Updates project-level custom claims of OIDC identity tokens
     */
    export async function main(
    	auth: Circleci,
    	orgID: string,
    	projectID: string,
    	body: { audience?: string[]; ttl?: string }
    ) {
    	const url = new URL(
    		`https://circleci.com/api/v2/org/${orgID}/project/${projectID}/oidc-custom-claims`
    	)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			'Circle-Token': auth.token
    		},
    		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 536 days ago