//native
type Codat = {
encodedKey: string
}
/**
* Update preferences for text fields on sync flow
* To enable update of preferences set for the text fields on sync flow.
*/
export async function main(auth: Codat, locale: 'en-us' | 'fr-fr' | undefined, body: {}) {
const url = new URL(`https://api.codat.io/sync/commerce/config/ui/text`)
for (const [k, v] of [['locale', locale]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'PATCH',
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