import {z} from 'zod' export type UpskillingPlanEntitySchema = {entityType: string | null, progress?: (string | null) | undefined, courseId?: (string | null) | undefined, skills?: Array | undefined, description?: (string | null) | undefined, title?: (string | null) | undefined}; export type UpskillingPlanSectionSchema = {sectionName: string | null, entities: Array}; export type UpskillingPlanTemplateCreateSchema = {status?: (string | null) | undefined, externalId?: (string | null) | undefined, planSubtype?: (string | null) | undefined, sections?: Array | undefined, name: string | null, planDurationDays?: (number | null) | undefined, creatorProfileId?: (string | null) | undefined, skills?: Array | undefined, description?: (string | null) | undefined, associatedRoleIds?: Array | undefined}; export type CreateApiApiV2CareerhubUpskillPlanTemplatesArgs = {Authorization: string, body: UpskillingPlanTemplateCreateSchema}; export type CreateApiApiV2CareerhubUpskillPlanTemplatesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const upskillingPlanEntitySchema = z.object({entityType: z.string().nullable(), progress: z.string().nullable().optional(), courseId: z.string().nullable().optional(), skills: z.array(z.string()).optional(), description: z.string().nullable().optional(), title: z.string().nullable().optional()}); export const upskillingPlanSectionSchema = z.object({sectionName: z.string().nullable(), entities: z.array(upskillingPlanEntitySchema)}); export const upskillingPlanTemplateSchema = z.object({status: z.string().nullable().optional(), id: z.number().int().nullable().optional(), createdAt: z.number().int().nullable().optional(), planSubtype: z.string().nullable().optional(), sections: z.array(upskillingPlanSectionSchema).nullable().optional(), name: z.string().nullable().optional(), externalId: z.string().nullable().optional(), userId: z.string().nullable().optional(), planDurationDays: z.number().int().nullable().optional(), publishedAt: z.number().int().nullable().optional(), skills: z.array(z.string()).nullable().optional(), groupId: z.string().nullable().optional(), updatedAt: z.number().int().nullable().optional(), description: z.string().nullable().optional(), associatedRoleIds: z.array(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 }; /** * Create Upskill Plan Template * * POST /api/v2/careerhub/upskill-plan-templates */ export const createApiApiV2CareerhubUpskillPlanTemplates = async (args: CreateApiApiV2CareerhubUpskillPlanTemplatesArgs, options?: CreateApiApiV2CareerhubUpskillPlanTemplatesOptions) => { const {baseUrl = "https://apiv2.eightfold.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/careerhub/upskill-plan-templates${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 validateResponse(upskillingPlanTemplateSchema, await res.json()) };