export type AutomationsPostRequest = {name: string, description?: string | undefined, triggerEventId?: string | undefined, nodes: Array<{id: string, label: string, description?: string | undefined, type: 'trigger', config: {actionType?: string | undefined, mode?: ('event' | 'manualAudience') | undefined, triggerEventId?: string | undefined, audienceId?: string | undefined, eventName?: string | undefined}} | {id: string, label: string, description?: string | undefined, type: 'sendEmail', config: {actionType?: string | undefined, emailId: string, emailVersionId: string, domainId: string, subject: string, previewText: string, messageClass?: ('marketing' | 'transactional') | undefined, fromName?: string | undefined, replyTo?: string | undefined, emailTitle?: string | undefined, fromAddress?: string | undefined}} | {id: string, label: string, description?: string | undefined, type: 'wait', config: {actionType?: string | undefined, duration: number, unit: 'ms' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks'}} | {id: string, label: string, description?: string | undefined, type: 'filter', config: {actionType?: string | undefined, logicalOperator: 'AND' | 'OR', conditions: Array<{field: string, type: 'string', operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with', value: string} | {field: string, type: 'number', operator: 'equals' | 'not_equals' | 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: string, type: 'date', operator: 'equals' | 'not_equals' | 'gt' | 'gte' | 'lt' | 'lte', value: string | number} | {field: string, type: 'string', operator: 'in' | 'not_in' | 'contains_any' | 'not_contains_any', value: Array} | {field: string, type: 'number', operator: 'in' | 'not_in', value: Array} | {field: string, type: 'number', operator: 'between', value: Array} | {field: string, type: 'date', operator: 'between', value: Array} | {field: string, type: 'string', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'number', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'date', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'bool', operator: 'is_true' | 'is_false'}>}} | {id: string, label: string, description?: string | undefined, type: 'split', config: {actionType?: string | undefined, mode: 'percentage', leftLabel: string, rightLabel: string, leftPercentage: number, seed?: string | undefined} | {actionType?: string | undefined, mode: 'condition', leftLabel: string, rightLabel: string, logicalOperator: 'AND' | 'OR', conditions: Array<{field: string, type: 'string', operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with', value: string} | {field: string, type: 'number', operator: 'equals' | 'not_equals' | 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: string, type: 'date', operator: 'equals' | 'not_equals' | 'gt' | 'gte' | 'lt' | 'lte', value: string | number} | {field: string, type: 'string', operator: 'in' | 'not_in' | 'contains_any' | 'not_contains_any', value: Array} | {field: string, type: 'number', operator: 'in' | 'not_in', value: Array} | {field: string, type: 'number', operator: 'between', value: Array} | {field: string, type: 'date', operator: 'between', value: Array} | {field: string, type: 'string', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'number', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'date', operator: 'is_empty' | 'is_not_empty'} | {field: string, type: 'bool', operator: 'is_true' | 'is_false'}>}}>, connections?: (Array<{from: string, to: string, branch?: ('left' | 'right') | undefined}>) | undefined, dryRun?: boolean | undefined}; export type CreateApiV1AutomationsArgs = {'Idempotency-Key'?: string | undefined, body: AutomationsPostRequest}; export type CreateApiV1AutomationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an automation * * POST /v1/automations * * Also accepts auth: apiKeyAuth */ export const createApiV1Automations = async (args: CreateApiV1AutomationsArgs, options?: CreateApiV1AutomationsOptions) => { const {baseUrl = "https://brew.new/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/automations${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 };