import {z} from 'zod' export type PropertyHrisTaxonomyAlternativeNames = Array; export type PropertyHrisTaxonomyRoleIds = Array; export type HrisMetadata = {id?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, slug?: string | undefined}; export type PropertyHrisTaxonomyMetadata = Array; export type HrisTaxonomy = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, type?: ('SKILL' | 'KNOWLEDGE' | 'COMPETENCE' | 'ABILITY' | 'CERTIFICATION' | 'ROLE' | 'HOLIDAY' | 'LEAVE') | undefined, name?: string | undefined, description?: string | undefined, domain?: string | undefined, category?: string | undefined, subcategory?: string | undefined, parent_id?: string | undefined, alternative_names?: PropertyHrisTaxonomyAlternativeNames | undefined, url?: string | undefined, role_ids?: PropertyHrisTaxonomyRoleIds | undefined, is_active?: boolean | undefined, metadata?: PropertyHrisTaxonomyMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type CreateApiHrisConnectionIdTaxonomyArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'type' | 'name' | 'description' | 'domain' | 'category' | 'subcategory' | 'parent_id' | 'alternative_names' | 'url' | 'role_ids' | 'is_active' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, body: HrisTaxonomy}; export type CreateApiHrisConnectionIdTaxonomyOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const propertyHrisTaxonomyAlternativeNames = z.array(z.string()); export const propertyHrisTaxonomyRoleIds = z.array(z.string()); export const hrisMetadata = z.object({id: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), slug: z.string().optional()}); export const propertyHrisTaxonomyMetadata = z.array(hrisMetadata); export const hrisTaxonomy = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), type: z.enum(["SKILL", "KNOWLEDGE", "COMPETENCE", "ABILITY", "CERTIFICATION", "ROLE", "HOLIDAY", "LEAVE"]).optional(), name: z.string().optional(), description: z.string().optional(), domain: z.string().optional(), category: z.string().optional(), subcategory: z.string().optional(), parent_id: z.string().optional(), alternative_names: propertyHrisTaxonomyAlternativeNames.optional(), url: z.string().optional(), role_ids: propertyHrisTaxonomyRoleIds.optional(), is_active: z.boolean().optional(), metadata: propertyHrisTaxonomyMetadata.optional(), raw: z.record(z.string(), z.unknown()).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 a taxonomy * * POST /hris/{connection_id}/taxonomy */ export const createApiHrisConnectionIdTaxonomy = async (args: CreateApiHrisConnectionIdTaxonomyArgs, options?: CreateApiHrisConnectionIdTaxonomyOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/hris/${encodeURIComponent(String(args.connection_id))}/taxonomy${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(hrisTaxonomy, await res.json()) };