export type ChannelDTO = {uid?: string | undefined, id?: string | undefined, channelTypeUID?: string | undefined, itemType?: string | undefined, kind?: string | undefined, label?: string | undefined, description?: string | undefined, defaultTags?: Array | undefined, properties?: {[key: string]: string} | undefined, configuration?: {[key: string]: Record} | undefined, autoUpdatePolicy?: string | undefined}; export type ThingDTO = {label?: string | undefined, bridgeUID?: string | undefined, configuration?: {[key: string]: Record} | undefined, properties?: {[key: string]: string} | undefined, UID?: string | undefined, thingTypeUID?: string | undefined, location?: string | undefined, channels?: Array | undefined}; export type CreateApiThingsArgs = {'Accept-Language'?: string | undefined, body: ThingDTO}; export type CreateApiThingsOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new thing and adds it to the registry. * * POST /things */ export const createApiThings = async (args: CreateApiThingsArgs, options: CreateApiThingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/things${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 res.blob() };