import {z} from 'zod' export type GetApiSurveyWorkflowsSurveyWorkflowIdRunsArgs = {survey_workflow_id: string, after?: string | undefined, per_page?: number | undefined, sort_order?: ('asc' | 'desc') | undefined, sort_property?: ('id' | 'updated_at') | undefined, filter?: ({status?: ('active' | 'paused' | 'completed' | 'canceled') | undefined, contact_id?: string | undefined}) | undefined}; export type GetApiSurveyWorkflowsSurveyWorkflowIdRunsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const surveySelectedOptionAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), label: z.string().nullable().optional()}); export const surveyAnswerAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), field: z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), key: z.string().nullable().optional(), label: z.string().nullable().optional()}).nullable().optional(), entry: z.string().nullable().optional(), selected_options: z.array(surveySelectedOptionAttributes).optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const surveySubmissionAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), form_id: z.number().int().optional(), contact_id: z.number().int().nullable().optional(), answers: z.array(surveyAnswerAttributes).optional()}); export const surveyWorkflowRunAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), survey_workflow_id: z.number().int().optional(), contact_id: z.number().int().nullable().optional(), status: z.enum(["active", "paused", "completed", "canceled"]).optional(), preview: z.boolean().optional(), completed_at: z.string().nullable().optional(), canceled_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), form_submissions: z.array(surveySubmissionAttributes).optional()}); export const getApiSurveyWorkflowsSurveyWorkflowIdRunsResponse = z.array(surveyWorkflowRunAttributes); 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 }; /** * List Full Survey Responses * * GET /survey_workflows/{survey_workflow_id}/runs */ export const getApiSurveyWorkflowsSurveyWorkflowIdRuns = async (args: GetApiSurveyWorkflowsSurveyWorkflowIdRunsArgs, options?: GetApiSurveyWorkflowsSurveyWorkflowIdRunsOptions) => { const {baseUrl = "https://myworkspace.myclickfunnels.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.after != null) query.append("after", String(args.after)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.sort_property != null) query.append("sort_property", String(args.sort_property)) if (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/survey_workflows/${encodeURIComponent(String(args.survey_workflow_id))}/runs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSurveyWorkflowsSurveyWorkflowIdRunsResponse, await res.json()) };