export type DeviceId = string; export type Url = string; export type RestApiPayload = string; export type UpdateApiDevicesDeviceIdImageArgs = {deviceId: DeviceId, sourceUrl?: Url | undefined, body: RestApiPayload}; export type UpdateApiDevicesDeviceIdImageOptions = {baseUrl?: string | undefined, SimpleToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * UpdateDeviceImage * * PUT /devices/{deviceId}/image */ export const updateApiDevicesDeviceIdImage = async (args: UpdateApiDevicesDeviceIdImageArgs, options?: UpdateApiDevicesDeviceIdImageOptions) => { const {baseUrl = "https://api.nrfcloud.com/v1", fetch: fetchFn = fetch, SimpleToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.sourceUrl != null) query.append("sourceUrl", String(args.sourceUrl)) if (SimpleToken !== undefined) headers.set('authorization', `Bearer ${SimpleToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/devices/${encodeURIComponent(String(args.deviceId))}/image${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 };