import {z} from 'zod' export type UpdatableUserStatus = 'ACTIVE' | 'INACTIVE'; export type CreateUser = {request_timestamp: number, name: string, middlename?: string | undefined, surname: string, job_title?: string | undefined, email?: string | undefined, mobile: string, mobile_prefix: string, mobile_access: boolean, web_access: boolean, custom_reference_id?: string | undefined, reports_to?: string | undefined, status?: UpdatableUserStatus | undefined}; export type CreateApiBusinessV2EmployeesCreateArgs = {'X-Soldo-Fingerprint': string, 'X-Soldo-Fingerprint-Signature': string, body: CreateUser}; export type CreateApiBusinessV2EmployeesCreateOptions = {baseUrl?: string | undefined, standardAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const userStatus = z.enum(["ACTIVE", "INACTIVE", "BLOCKED", "SUSPENDED", "PENDING", "ARCHIVED"]); export const addressCategory = z.enum(["USER", "COMPANY"]); export const address = z.object({id: z.string().optional(), recipient: z.string().optional(), name: z.string().optional(), line1: z.string().optional(), line2: z.string().optional(), country: z.string().optional(), county: z.string().optional(), city: z.string().optional(), post_code: z.string().optional(), delivery_phone_number: z.string().optional(), default_shipping: z.boolean().optional(), type: z.string().optional(), category: addressCategory.optional(), user_id: z.string().optional(), creation_time: z.string().optional(), last_update: z.string().optional()}); export const userRole = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), scope: z.string().optional()}); export const workStatus = z.enum(["AVAILABLE", "OUT_OF_OFFICE"]); export const user = z.object({id: z.string().optional(), name: z.string().optional(), surname: z.string().optional(), middlename: z.string().optional(), dob: z.string().optional(), job_title: z.string().optional(), department: z.string().optional(), email: z.string().optional(), mobile: z.string().optional(), mobile_prefix: z.string().optional(), custom_reference_id: z.string().optional(), status: userStatus.optional(), visible: z.boolean().optional(), mobile_access: z.boolean().optional(), web_access: z.boolean().optional(), groups: z.array(z.string()).optional(), shipping_address: address.optional(), reports_to: z.string().optional(), roles: z.array(userRole).optional(), contact_id: z.string().optional(), creation_time: z.string().optional(), last_update: z.string().optional(), work_status: workStatus.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 User * * POST /business/v2/employees/create */ export const createApiBusinessV2EmployeesCreate = async (args: CreateApiBusinessV2EmployeesCreateArgs, options?: CreateApiBusinessV2EmployeesCreateOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Soldo-Fingerprint'] != null) headers.set("X-Soldo-Fingerprint", String(args['X-Soldo-Fingerprint'])) if (args['X-Soldo-Fingerprint-Signature'] != null) headers.set("X-Soldo-Fingerprint-Signature", String(args['X-Soldo-Fingerprint-Signature'])) if (standardAuth !== undefined) headers.set('authorization', `Bearer ${standardAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/business/v2/employees/create${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(user, await res.json()) };