export type DeviceId = string; export type ThingType = string; export type DeviceTag = string; export type FirmwareTypes = 'APP' | 'MODEM' | 'BOOT' | 'SOFTDEVICE' | 'BOOTLOADER' | 'MDM_FULL' | 'SMP' | 'CUSTOM'; export type OnboardSingleDeviceArgs = {certificate: string, subType?: ThingType | undefined, tags?: Array | undefined, supportedFirmwareTypes?: Array | undefined}; export type CreateApiDevicesDeviceIdArgs = {deviceId: DeviceId, body: OnboardSingleDeviceArgs}; export type CreateApiDevicesDeviceIdOptions = {baseUrl?: string | undefined, SimpleToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * OnboardDevice * * POST /devices/{deviceId} */ export const createApiDevicesDeviceId = async (args: CreateApiDevicesDeviceIdArgs, options?: CreateApiDevicesDeviceIdOptions) => { 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 (SimpleToken !== undefined) headers.set('authorization', `Bearer ${SimpleToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/devices/${encodeURIComponent(String(args.deviceId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 };