export type RestConditionGroup = {operator: string, priority?: number | undefined, conditions?: {[key: string]: boolean} | undefined}; export type RestRule = {name?: string | undefined, fireOn?: string | undefined, shortCircuit?: boolean | undefined, priority?: number | undefined, enabled?: boolean | undefined, conditionGroups?: {[key: string]: RestConditionGroup} | undefined, ruleActions?: {[key: string]: boolean} | undefined}; export type CreateApiApiV1SitesSiteIdRuleengineRulesArgs = {siteId: string, body: RestRule}; export type CreateApiApiV1SitesSiteIdRuleengineRulesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /api/v1/sites/{siteId}/ruleengine/rules */ export const createApiApiV1SitesSiteIdRuleengineRules = async (args: CreateApiApiV1SitesSiteIdRuleengineRulesArgs, options: CreateApiApiV1SitesSiteIdRuleengineRulesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/sites/${encodeURIComponent(String(args.siteId))}/ruleengine/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 (await res.json()) as unknown };