//native
type Codat = {
encodedKey: string
}
/**
* Retrieve preferences for text fields on sync flow
* To enable retrieval of preferences set for the text fields on Sync Flow.
*/
export async function main(auth: Codat, locale: 'en-us' | 'fr-fr' | undefined) {
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: 'GET',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
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