Edits history of script submission #17814 for ' Delete collection of keys (phrase)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Phrase = {
    	token: string
    	baseUrl: string
    }
    /**
     * Delete collection of keys
     * Delete all keys matching query. Same constraints as list. Please limit the number of affected keys to about 1,000 as you might experience timeouts otherwise.
     */
    export async function main(
    	auth: Phrase,
    	project_id: string,
    	branch: string | undefined,
    	q: string | undefined,
    	locale_id: string | undefined
    ) {
    	const url = new URL(`${auth.baseUrl}/projects/${project_id}/keys`)
    	for (const [k, v] of [
    		['branch', branch],
    		['q', q],
    		['locale_id', locale_id]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'ApiToken ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago