import {z} from 'zod' export type GetLmsCoursesBulkTaskIdParameterTaskId = string; export type GetApiLmsCoursesBulkTaskIdArgs = {'X-Integration-Id': string, task_id: GetLmsCoursesBulkTaskIdParameterTaskId}; export type GetApiLmsCoursesBulkTaskIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getLmsCoursesBulkTaskIdPositiveResponse = z.object({status: z.literal("success"), data: z.discriminatedUnion("status", [z.object({task_id: z.string(), created_at: z.string(), status: z.literal("PENDING"), completed_at: z.unknown()}), z.object({task_id: z.string(), created_at: z.string(), status: z.literal("COMPLETED"), data: z.array(z.discriminatedUnion("status", [z.object({origin_id: z.string(), status: z.literal("SUCCEEDED"), data: z.object({id: z.string()})}), z.object({origin_id: z.string(), status: z.literal("FAILED"), error: z.object({code: z.enum(["PLATFORM.RATE_LIMIT_EXCEEDED", "PLATFORM.CONCURRENCY_LIMIT_EXCEEDED", "PLATFORM.INTEGRATION_NOT_FOUND", "PLATFORM.INPUT_INVALID", "PLATFORM.UNKNOWN_ERROR", "PLATFORM.IP_NOT_WHITELISTED", "PLATFORM.AUTHENTICATION_INVALID", "PLATFORM.TASK_TIMED_OUT", "INTEGRATION.PERMISSION_MISSING", "INTEGRATION.AUTHENTICATION_INVALID", "INTEGRATION.QA_FAILED", "INTEGRATION.SETUP_SYNC_PENDING", "INTEGRATION.SETUP_INCOMPLETE", "INTEGRATION.INACTIVE", "INTEGRATION.MODEL_NOT_AVAILABLE", "INTEGRATION.MODEL_DISABLED", "INTEGRATION.ACTION_NOT_AVAILABLE", "INTEGRATION.ACTION_DISABLED", "REMOTE.SERVICE_UNAVAILABLE", "REMOTE.RATE_LIMIT_EXCEEDED", "REMOTE.INPUT_INVALID", "REMOTE.UNKNOWN_HTTP_ERROR", "HRIS.STAFFING_ENTITY_CLOSED", "HRIS.EMPLOYEE_ALREADY_EXISTS", "ATS.JOB_CLOSED", "ATS.APPLICATION_ALREADY_EXISTS", "LMS.COURSE_UPDATE_NOT_SUPPORTED", "AI_APPLY.JOB_FEED_IMPORT_ALREADY_RUNNING", "AI_APPLY.JOB_FEED_IMPORT_TIMED_OUT", "AI_APPLY.JOB_POSTING_ALREADY_EXISTS"]).nullable(), title: z.string().nullable(), message: z.string(), log_url: z.string().nullable()})})])), completed_at: z.string()}), z.object({task_id: z.string(), created_at: z.string(), status: z.literal("FAILED"), error: z.object({code: z.enum(["PLATFORM.RATE_LIMIT_EXCEEDED", "PLATFORM.CONCURRENCY_LIMIT_EXCEEDED", "PLATFORM.INTEGRATION_NOT_FOUND", "PLATFORM.INPUT_INVALID", "PLATFORM.UNKNOWN_ERROR", "PLATFORM.IP_NOT_WHITELISTED", "PLATFORM.AUTHENTICATION_INVALID", "PLATFORM.TASK_TIMED_OUT", "INTEGRATION.PERMISSION_MISSING", "INTEGRATION.AUTHENTICATION_INVALID", "INTEGRATION.QA_FAILED", "INTEGRATION.SETUP_SYNC_PENDING", "INTEGRATION.SETUP_INCOMPLETE", "INTEGRATION.INACTIVE", "INTEGRATION.MODEL_NOT_AVAILABLE", "INTEGRATION.MODEL_DISABLED", "INTEGRATION.ACTION_NOT_AVAILABLE", "INTEGRATION.ACTION_DISABLED", "REMOTE.SERVICE_UNAVAILABLE", "REMOTE.RATE_LIMIT_EXCEEDED", "REMOTE.INPUT_INVALID", "REMOTE.UNKNOWN_HTTP_ERROR", "HRIS.STAFFING_ENTITY_CLOSED", "HRIS.EMPLOYEE_ALREADY_EXISTS", "ATS.JOB_CLOSED", "ATS.APPLICATION_ALREADY_EXISTS", "LMS.COURSE_UPDATE_NOT_SUPPORTED", "AI_APPLY.JOB_FEED_IMPORT_ALREADY_RUNNING", "AI_APPLY.JOB_FEED_IMPORT_TIMED_OUT", "AI_APPLY.JOB_POSTING_ALREADY_EXISTS"]).nullable(), title: z.string().nullable(), message: z.string(), log_url: z.string().nullable()}), completed_at: z.string()})])}); 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 }; /** * Get status of “Upsert courses” task * * GET /lms/courses/bulk/{task_id} */ export const getApiLmsCoursesBulkTaskId = async (args: GetApiLmsCoursesBulkTaskIdArgs, options?: GetApiLmsCoursesBulkTaskIdOptions) => { const {baseUrl = "https://api.kombo.dev/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Integration-Id'] != null) headers.set("X-Integration-Id", String(args['X-Integration-Id'])) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/lms/courses/bulk/${encodeURIComponent(String(args.task_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(getLmsCoursesBulkTaskIdPositiveResponse, await res.json()) };