import {z} from 'zod' export type UpdateApiWorkflowsIdArgs = {id: number, body: {name: string, filter?: ({ids?: Array | undefined}) | undefined, individual_record_filter?: ({condition: 'AND' | 'OR', rules: Array<{id: string, query_builder_id?: string | undefined, customfield_id: string, label?: string | undefined, type?: ('integer' | 'double' | 'boolean' | 'tri_state_boolean' | 'string' | 'long_string' | 'select' | 'date' | 'datetime' | 'file') | undefined, input?: string | undefined, operator: 'equal' | 'not_equal' | 'in' | 'not_in' | 'less' | 'less_or_equal' | 'greater' | 'greater_or_equal' | 'between' | 'not_between' | 'begins_with' | 'not_begins_with' | 'contains' | 'not_contains' | 'ends_with' | 'not_ends_with' | 'is_empty' | 'is_not_empty' | 'is_null' | 'is_not_null' | 'true' | 'false' | 'past_less' | 'past_exactly' | 'past_more_than' | 'future_less' | 'future_exactly' | 'future_more_than' | 'after' | 'on' | 'before' | 'is' | 'is_not', value?: Array | undefined, entity?: ('account' | 'person' | 'opportunity' | 'campaign' | 'tag' | 'task' | 'workflow' | 'workflow_record' | 'workflow_step_record' | 'lead') | undefined, display_entity?: ('Account' | 'Contact' | 'Opportunity' | 'Campaign' | 'Tag' | 'Task' | 'Workflow' | 'Lead') | undefined, pipeline?: number | undefined, enabled: string, internal?: boolean | undefined}>, order_by?: string | undefined, not?: boolean | undefined, valid?: boolean | undefined, search?: string | undefined}) | undefined, status?: ('live' | 'paused' | 'scheduled' | 'draft') | undefined, status_message?: string | undefined, record_type?: 'contact' | undefined, goal?: ('opened' | 'clicked' | 'replied') | undefined, continuous?: boolean | undefined, exit_after_days?: number | undefined, schedule_date?: string | undefined, schedule_time_start?: string | undefined, schedule_time_end?: string | undefined, schedule_days?: Array | undefined, steps?: (Array<{id?: number | undefined, name?: string | undefined, order: number, filter?: ({condition: 'AND' | 'OR', rules: Array<{id: string, query_builder_id?: string | undefined, customfield_id: string, label?: string | undefined, type?: ('integer' | 'double' | 'boolean' | 'tri_state_boolean' | 'string' | 'long_string' | 'select' | 'date' | 'datetime' | 'file') | undefined, input?: string | undefined, operator: 'equal' | 'not_equal' | 'in' | 'not_in' | 'less' | 'less_or_equal' | 'greater' | 'greater_or_equal' | 'between' | 'not_between' | 'begins_with' | 'not_begins_with' | 'contains' | 'not_contains' | 'ends_with' | 'not_ends_with' | 'is_empty' | 'is_not_empty' | 'is_null' | 'is_not_null' | 'true' | 'false' | 'past_less' | 'past_exactly' | 'past_more_than' | 'future_less' | 'future_exactly' | 'future_more_than' | 'after' | 'on' | 'before' | 'is' | 'is_not', value?: Array | undefined, entity?: ('account' | 'person' | 'opportunity' | 'campaign' | 'tag' | 'task' | 'workflow' | 'workflow_record' | 'workflow_step_record' | 'lead') | undefined, display_entity?: ('Account' | 'Contact' | 'Opportunity' | 'Campaign' | 'Tag' | 'Task' | 'Workflow' | 'Lead') | undefined, pipeline?: number | undefined, enabled: string, internal?: boolean | undefined}>, order_by?: string | undefined, not?: boolean | undefined, valid?: boolean | undefined, search?: string | undefined}) | undefined, trigger_step?: number | undefined, trigger_step_index?: number | undefined, trigger_after_days?: number | undefined, trigger?: ('sent' | 'opened' | 'clicked' | 'replied' | 'not_opened' | 'not_replied' | 'not_clicked') | undefined, action_type?: 'send_email' | undefined, action_config?: Record | undefined, action_status?: string | undefined, action_source?: number | undefined, action_source_email?: string | undefined, analytics?: ({total?: ({name?: string | undefined, value?: number | undefined, type?: ('absolute' | 'percentage') | undefined}) | undefined, sent?: ({name?: string | undefined, value?: number | undefined, type?: ('absolute' | 'percentage') | undefined}) | undefined, interacted?: ({name?: string | undefined, value?: number | undefined, type?: ('absolute' | 'percentage') | undefined}) | undefined, replied?: ({name?: string | undefined, value?: number | undefined, type?: ('absolute' | 'percentage') | undefined}) | undefined, failed?: ({name?: string | undefined, value?: number | undefined, type?: ('absolute' | 'percentage') | undefined}) | undefined}) | undefined, metrics_data?: Record | undefined}>) | undefined}}; export type UpdateApiWorkflowsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiWorkflowsIdResponse = z.object({success: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update a workflow * * PUT /workflows/{id} */ export const updateApiWorkflowsId = async (args: UpdateApiWorkflowsIdArgs, options?: UpdateApiWorkflowsIdOptions) => { const {baseUrl = "https://api.salesflare.com", 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(/\/+$/, '')}/workflows/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 validateResponse(updateApiWorkflowsIdResponse, await res.json()) };