import {z} from 'zod' export type GetApiCoursesSectionsPublishActionsIdArgs = {id: string}; export type GetApiCoursesSectionsPublishActionsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coursesSectionsPublishActionAttributes = z.object({id: z.number().int().optional(), public_id: z.string().nullable().optional(), course_id: z.number().int().optional(), target_all: z.boolean().nullable().optional(), target_ids: z.array(z.number().int()).nullable().optional(), auto_enroll: z.boolean().nullable().optional(), send_email: z.boolean().nullable().optional(), offer_new_section_via_all_access_products: z.boolean().nullable().optional(), target_count: z.number().int().nullable().optional(), performed_count: z.number().int().nullable().optional(), published_lessons_count: z.number().int().nullable().optional(), status: z.enum(["queued", "scheduled", "processing", "completed"]).optional(), scheduled_for: z.string().nullable().optional(), started_at: z.string().nullable().optional(), completed_at: z.string().nullable().optional(), created_by_id: z.number().int().nullable().optional(), approved_by_id: z.number().int().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().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 }; /** * Fetch Publish Action * * GET /courses/sections/publish_actions/{id} * * Also accepts auth: OAuth2 */ export const getApiCoursesSectionsPublishActionsId = async (args: GetApiCoursesSectionsPublishActionsIdArgs, options?: GetApiCoursesSectionsPublishActionsIdOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/courses/sections/publish_actions/${encodeURIComponent(String(args.id))}${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(coursesSectionsPublishActionAttributes, await res.json()) };