import {z} from 'zod' export type DtosAddress = {addr1?: string | undefined, addr2?: string | undefined, city?: string | undefined, state?: string | undefined, zip?: string | undefined, county?: string | undefined, country?: ('Afghanistan' | 'Albania' | 'Algeria' | 'Argentina' | 'Armenia' | 'Australia' | 'Austria' | 'Azerbaijan' | 'Bahrain' | 'Bangladesh' | 'Belarus' | 'Belgium' | 'Belize' | 'Benin' | 'Bhutan' | 'Bolivarian Republic of Venezuela' | 'Bolivia' | 'Bosnia and Herzegovina' | 'Botswana' | 'Brazil' | 'Brunei Darussalam' | 'Bulgaria' | 'Burundi' | 'Cambodia' | 'Cameroon' | 'Canada' | 'Caribbean' | 'Chile' | 'Colombia' | 'Congo (DRC)' | 'Costa Rica' | 'Côte d'Ivoire' | 'Croatia' | 'Cuba' | 'Cyprus' | 'Czech Republic' | 'Denmark' | 'Djibouti' | 'Dominican Republic' | 'Ecuador' | 'Egypt' | 'El Salvador' | 'Eritrea' | 'Estonia' | 'Ethiopia' | 'Faroe Islands' | 'Fiji' | 'Finland' | 'France' | 'Gambia' | 'Georgia' | 'Germany' | 'Ghana' | 'Greece' | 'Greenland' | 'Guatemala' | 'Haiti' | 'Honduras' | 'Hong Kong S.A.R.' | 'Hungary' | 'Iceland' | 'India' | 'Indonesia' | 'Iran' | 'Iraq' | 'Ireland' | 'Islamic Republic of Pakistan' | 'Israel' | 'Italy' | 'Jamaica' | 'Japan' | 'Jordan' | 'Kazakhstan' | 'Kenya' | 'Korea' | 'Kuwait' | 'Kyrgyzstan' | 'Lao P.D.R.' | 'Latin America' | 'Latvia' | 'Lebanon' | 'Liberia' | 'Libya' | 'Liechtenstein' | 'Lithuania' | 'Luxembourg' | 'Macao S.A.R.' | 'Malaysia' | 'Maldives' | 'Mali' | 'Malta' | 'Mexico' | 'Moldova' | 'Mongolia' | 'Montenegro' | 'Morocco' | 'Myanmar' | 'Namibia' | 'Nepal' | 'Netherlands' | 'New Zealand' | 'Nicaragua' | 'Nigeria' | 'North Macedonia' | 'Norway' | 'Oman' | 'Palestine' | 'Panama' | 'Paraguay' | 'People's Republic of China' | 'Peru' | 'Philippines' | 'Poland' | 'Portugal' | 'Principality of Monaco' | 'Puerto Rico' | 'Qatar' | 'Réunion' | 'Romania' | 'Russia' | 'Rwanda' | 'Saudi Arabia' | 'Senegal' | 'Serbia' | 'Sierra Leone' | 'Singapore' | 'Slovakia' | 'Slovenia' | 'Somalia' | 'South Africa' | 'Spain' | 'Sri Lanka' | 'Sudan' | 'Sweden' | 'Switzerland' | 'Syria' | 'Taiwan' | 'Tajikistan' | 'Tanzania' | 'Thailand' | 'Trinidad and Tobago' | 'Tunisia' | 'Turkey' | 'Turkmenistan' | 'U.A.E.' | 'Uganda' | 'Ukraine' | 'United Kingdom' | 'United States' | 'Uruguay' | 'Uzbekistan' | 'Vietnam' | 'Yemen' | 'Zambia' | 'Zimbabwe') | undefined, region?: string | undefined}; export type DtosPlanLocation = {location_id: string, name: string, address: DtosAddress, phone?: string | undefined, fax?: string | undefined, headquarters?: boolean | undefined}; export type DtosPlanCompanyCarrierSettings = {carrier?: string | undefined, field?: string | undefined, value: unknown}; export type DtosPlanCompany = {name: string, agent_email?: string | undefined, assign_agent_teams?: boolean | undefined, create_team_for_agent?: boolean | undefined, ein?: string | undefined, sic?: string | undefined, default_pay_cycle_periods?: number | undefined, locations?: Array | undefined, carrier_settings?: Array | undefined}; export type CreateApiVVersionCompaniesArgs = {new_companies_only?: boolean | undefined, version: string, body: DtosPlanCompany}; export type CreateApiVVersionCompaniesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const controllersCompanyControllerModel = 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 }; /** * company * * POST /v{version}/companies */ export const createApiVVersionCompanies = async (args: CreateApiVVersionCompaniesArgs, options: CreateApiVVersionCompaniesOptions) => { const {baseUrl, 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.new_companies_only != null) query.append("new_companies_only", String(args.new_companies_only)) const url = `${baseUrl.replace(/\/+$/, '')}/v${encodeURIComponent(String(args.version))}/companies${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(controllersCompanyControllerModel, await res.json()) };