import {z} from 'zod' export type RegistrationRequestsRegistrationRequestParamState = 'AL' | 'AK' | 'AZ' | 'AR' | 'CA' | 'CO' | 'CT' | 'DE' | 'FL' | 'GA' | 'HI' | 'ID' | 'IL' | 'IN' | 'IA' | 'KS' | 'KY' | 'LA' | 'ME' | 'MD' | 'MA' | 'MI' | 'MN' | 'MS' | 'MO' | 'MT' | 'NE' | 'NV' | 'NH' | 'NJ' | 'NM' | 'NY' | 'NC' | 'ND' | 'OH' | 'OK' | 'OR' | 'PA' | 'RI' | 'SC' | 'SD' | 'TN' | 'TX' | 'UT' | 'VT' | 'VA' | 'WA' | 'WV' | 'WI' | 'WY'; export type RegistrationRequestsRegistrationRequestParamTaxRegistrationTypesItem = 'state_unemployment_insurance' | 'state_tax_withholdings'; export type CreateApiV1PartnerRegistrationRequestsArgs = {body: {state: RegistrationRequestsRegistrationRequestParamState, email: string, company_id?: string | undefined, company_name?: string | undefined, external_id?: string | undefined, tax_registration_types?: Array | undefined, jurisdictions?: Array | undefined, redirect_uri?: string | undefined, redirect_back_uri?: string | undefined}}; export type CreateApiV1PartnerRegistrationRequestsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const registrationRequestState = z.enum(["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]); export const registrationRequest = z.object({object: z.string(), id: z.string(), state: registrationRequestState, status: z.string(), tax_registration_types: z.array(z.string()).nullable(), company_id: z.string(), external_id: z.string().nullable().optional(), submitted_at: z.string().nullable().optional(), created_at: z.string(), agencies: z.array(z.record(z.string(), z.unknown())), items: z.array(z.record(z.string(), z.unknown())), tax_registration: z.record(z.string(), z.unknown()).nullable().optional(), invite_link: 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 registration request * * POST /v1/partner/registration_requests */ export const createApiV1PartnerRegistrationRequests = async (args: CreateApiV1PartnerRegistrationRequestsArgs, options?: CreateApiV1PartnerRegistrationRequestsOptions) => { const {baseUrl = "https://api.middesk.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/partner/registration_requests${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(registrationRequest, await res.json()) };