export type MinionTypes = 'toggle' | 'switch' | 'temperatureSensor' | 'roller' | 'cleaner' | 'airConditioning' | 'light' | 'temperatureLight' | 'colorLight'; export type CommandsRepoDevice = {brand: string, model: string, category: MinionTypes}; export type UpdateApiRfFetchCommandsMinionIdArgs = {minionId: string, body: CommandsRepoDevice}; export type UpdateApiRfFetchCommandsMinionIdOptions = {baseUrl: string, userAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Fetch commands set for certain minion see https://github.com/casanet/rf-commands-repo API. * * PUT /rf/fetch-commands/{minionId} * * Also accepts auth: adminAuth */ export const updateApiRfFetchCommandsMinionId = async (args: UpdateApiRfFetchCommandsMinionIdArgs, options: UpdateApiRfFetchCommandsMinionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, userAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (userAuth !== undefined) headers.set("authentication", userAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rf/fetch-commands/${encodeURIComponent(String(args.minionId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };