import {z} from 'zod' export type V1GpEmploymentsPersonalInput = {firstName: string, middleName?: (string | null) | undefined, lastName: string, fullLegalName: string, nameInNativeLanguage?: string | undefined, dateOfBirth: string, gender: 'FEMALE' | 'MALE' | 'UNSPECIFIED', maritalStatus?: ('DIVORCED' | 'MARRIED' | 'SINGLE' | 'UNSPECIFIED') | undefined, religion?: (string | null) | undefined, nationality?: string | undefined}; export type V1GpEmploymentsContactInput = {personalEmail: string, personalPhoneNumber?: string | undefined, emergencyContact?: ({name: string, phoneNumber: string, relationship: 'SPOUSE' | 'DAUGHTER' | 'SON' | 'FATHER' | 'MOTHER'} | null) | undefined}; export type V1GpEmploymentsEmploymentInput = {employeeCode: string, entity: string, workEmail?: string | undefined, startDate: string, term: 'FIXED' | 'PERMANENT', endDate?: (string | null) | undefined, designation: string, department: string, reportsTo?: string | undefined}; export type V2CompensationComponent = {name: string, billingRate: number, billingRateType: 'VALUE' | 'PERC_BASE_PAY' | 'BASE_PAY_DAYS' | 'CTC_DAYS' | 'CTC_PERCENTAGE' | 'EARNINGS_PERCENTAGE' | 'BASIC_SALARY_PERCENTAGE' | 'QUALIFYING_EARNINGS_PERCENTAGE', currency: string, frequency: 'WEEKLY' | 'SEMIMONTHLY' | 'BIWEEKLY' | 'MONTHLY' | 'ANNUALLY' | 'SEMIANNUALLY' | 'QUARTERLY' | 'DAILY' | 'ONETIME' | 'HOURLY', payScheduleName: string, startDate: string, endDate?: (string | null) | undefined, isInstallment?: (boolean | null) | undefined, numberOfInstallments?: (number | null) | undefined, notes?: (string | null) | undefined}; export type V1GpEmploymentsCompensationInput = {baseSalary: V2CompensationComponent, additionalPays?: Array | undefined}; export type V1GpEmploymentsAddressInput = {addressLine1?: string | undefined, addressLine2?: (string | null) | undefined, streetName?: (string | null) | undefined, city?: string | undefined, subdivision?: (string | null) | undefined, country?: string | undefined, postalCode?: string | undefined}; export type V1GpEmploymentsPostRequest = {personal: V1GpEmploymentsPersonalInput, contact: V1GpEmploymentsContactInput, employment: V1GpEmploymentsEmploymentInput, compensation: V1GpEmploymentsCompensationInput, address?: V1GpEmploymentsAddressInput | undefined}; export type CreateApiV1EmployeesGpEmploymentsArgs = {body: V1GpEmploymentsPostRequest}; export type CreateApiV1EmployeesGpEmploymentsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v1GpEmploymentsPostResponse = z.object({id: 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 }; /** * Create a GP (Global Payroll) employee * * POST /v1/employees/gp-employments */ export const createApiV1EmployeesGpEmployments = async (args: CreateApiV1EmployeesGpEmploymentsArgs, options?: CreateApiV1EmployeesGpEmploymentsOptions) => { const {baseUrl = "https://api.usemultiplier.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/employees/gp-employments${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(v1GpEmploymentsPostResponse, await res.json()) };