export type TriggerDTO = {id?: string | undefined, label?: string | undefined, description?: string | undefined, configuration?: {[key: string]: Record} | undefined, type?: string | undefined}; export type ConditionDTO = {id?: string | undefined, label?: string | undefined, description?: string | undefined, configuration?: {[key: string]: Record} | undefined, type?: string | undefined, inputs?: {[key: string]: string} | undefined}; export type ActionDTO = {id?: string | undefined, label?: string | undefined, description?: string | undefined, configuration?: {[key: string]: Record} | undefined, type?: string | undefined, inputs?: {[key: string]: string} | undefined}; export type ParameterOptionDTO = {label?: string | undefined, value?: string | undefined}; export type FilterCriteriaDTO = {value?: string | undefined, name?: string | undefined}; export type ConfigDescriptionParameterDTO = {context?: string | undefined, defaultValue?: string | undefined, description?: string | undefined, label?: string | undefined, name?: string | undefined, required?: boolean | undefined, type?: ('TEXT' | 'INTEGER' | 'DECIMAL' | 'BOOLEAN') | undefined, min?: number | undefined, max?: number | undefined, stepsize?: number | undefined, pattern?: string | undefined, readOnly?: boolean | undefined, multiple?: boolean | undefined, multipleLimit?: number | undefined, groupName?: string | undefined, advanced?: boolean | undefined, verify?: boolean | undefined, limitToOptions?: boolean | undefined, unit?: string | undefined, unitLabel?: string | undefined, options?: Array | undefined, filterCriteria?: Array | undefined}; export type RuleDTO = {triggers?: Array | undefined, conditions?: Array | undefined, actions?: Array | undefined, configuration?: {[key: string]: Record} | undefined, configDescriptions?: Array | undefined, templateUID?: string | undefined, uid?: string | undefined, name?: string | undefined, tags?: Array | undefined, visibility?: ('VISIBLE' | 'HIDDEN' | 'EXPERT') | undefined, description?: string | undefined}; export type CreateApiRulesArgs = {body: RuleDTO}; export type CreateApiRulesOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a rule. * * POST /rules */ export const createApiRules = async (args: CreateApiRulesArgs, options: CreateApiRulesOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/rules${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 };