import {z} from 'zod' export type FormerNameDto = {forenames?: string | undefined, surname?: string | undefined}; export type OfficerFilingDto = {serviceAddress?: ({address_line_1?: string | undefined, address_line_2?: string | undefined, country?: string | undefined, locality?: string | undefined, poBox?: string | undefined, postalCode?: string | undefined, premises?: string | undefined, region?: string | undefined}) | undefined, addressSameAsRegisteredOfficeAddress?: boolean | undefined, appointedOn?: string | undefined, countryOfResidence?: string | undefined, dateOfBirth?: ({day?: number | undefined, month?: number | undefined, year?: number | undefined}) | undefined, formerNames?: Array | undefined, identification?: ({identificationType?: string | undefined, identification_type?: string | undefined, legalAuthority?: string | undefined, legalForm?: string | undefined, legal_authority?: string | undefined, legal_form?: string | undefined, placeRegistered?: string | undefined, place_registered?: string | undefined, registrationNumber?: string | undefined, registration_number?: string | undefined}) | undefined, name?: string | undefined, nationality?: string | undefined, occupation?: string | undefined, referenceAppointmentId: string, referenceEtag: string, referenceOfficerListEtag?: string | undefined, residentialAddress?: ({address_line_1?: string | undefined, address_line_2?: string | undefined, country?: string | undefined, locality?: string | undefined, poBox?: string | undefined, postalCode?: string | undefined, premises?: string | undefined, region?: string | undefined}) | undefined, residentialAddressSameAsServiceAddress?: boolean | undefined, resignedOn: string}; export type CreateApiTransactionsTransIdOfficersArgs = {transId: string, body: OfficerFilingDto}; export type CreateApiTransactionsTransIdOfficersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiTransactionsTransIdOfficersResponse = z.object({}); 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 Filing * * POST /transactions/{transId}/officers */ export const createApiTransactionsTransIdOfficers = async (args: CreateApiTransactionsTransIdOfficersArgs, options?: CreateApiTransactionsTransIdOfficersOptions) => { const {baseUrl = "http://api.companieshouse.gov.uk", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/transactions/${encodeURIComponent(String(args.transId))}/officers${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(createApiTransactionsTransIdOfficersResponse, await res.json()) };