import {z} from 'zod' export type UpdateCompanyPayload = {name?: string | undefined, relationship?: ('client' | 'target' | 'none') | undefined, type?: ('educational' | 'government' | 'nonprofit' | 'private' | 'public' | 'null' | null) | undefined, size?: ('1-10' | '11-50' | '51-200' | '201-500' | '501-1000' | '1001-5000' | '5001-10000' | '10001+' | 'null' | null) | undefined, summary?: (string | null) | undefined, overview?: (string | null) | undefined, industry?: (Array | null) | undefined, employeeCount?: (number | null) | undefined, ticker?: (string | null) | undefined, location?: ({name?: (string | null) | undefined, locality?: (string | null) | undefined, region?: (string | null) | undefined, metro?: (string | null) | undefined, country?: (string | null) | undefined, streetAddress?: (string | null) | undefined, addressLine2?: (string | null) | undefined, postalCode?: (string | null) | undefined, raw?: (string | null) | undefined, latitude?: (number | null) | undefined, longitude?: (number | null) | undefined} | null) | undefined, identities?: (Array<{type: 'linkedin' | 'phone' | 'website' | 'aboutme' | 'angellist' | 'behance' | 'crunchbase' | 'dribbble' | 'ello' | 'facebook' | 'flickr' | 'foursquare' | 'github' | 'gitlab' | 'google' | 'gravatar' | 'indeed' | 'instagram' | 'klout' | 'meetup' | 'myspace' | 'pinterest' | 'quora' | 'reddit' | 'soundcloud' | 'stackoverflow' | 'twitter' | 'vimeo' | 'wordpress' | 'xing' | 'youtube' | 'medium' | 'scholar' | 'other', value: string, primary?: boolean | undefined}>) | undefined, customAttributes?: (Array<{customAttributeId: string, optionId?: (string | null) | undefined, value?: (string | number | null) | undefined}>) | undefined, ownerEmail?: string | undefined}; export type PatchApiApiV1CompaniesIdArgs = {id: string, body: UpdateCompanyPayload}; export type PatchApiApiV1CompaniesIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV1CompaniesIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), name: z.string(), websiteUrl: z.string().nullable(), linkedinUrl: z.string().nullable(), relationship: z.enum(["client", "target", "none"]), type: z.enum(["educational", "government", "nonprofit", "private", "public", "null"]).nullable(), size: z.enum(["1-10", "11-50", "51-200", "201-500", "501-1000", "1001-5000", "5001-10000", "10001+", "null"]).nullable(), industry: z.array(z.string()).nullable(), summary: z.string().nullable(), overview: z.string().nullable(), logo: z.string().nullable(), employeeCount: z.number().int().nullable(), ticker: z.string().nullable(), location: z.object({formattedAddress: z.string().nullable(), city: z.string().nullable(), region: z.string().nullable(), country: z.string().nullable(), metro: z.string().nullable(), streetAddress: z.string().nullable(), addressLine2: z.string().nullable(), postalCode: z.string().nullable(), raw: z.string().nullable(), latitude: z.number().nullable(), longitude: z.number().nullable()}).nullable(), identities: z.array(z.object({type: z.string(), value: z.string(), primary: z.boolean()})), customAttributes: z.array(z.object({attributeId: z.string(), attributeName: z.string().nullable(), attributeType: z.enum(["options", "text_block", "text_line", "number_input", "integer", "date", "null"]).nullable(), values: z.array(z.union([z.string(), z.number(), z.object({optionId: z.string(), optionValue: z.string().nullable()})]))})), owners: z.array(z.object({id: z.string(), name: z.string(), email: z.string()})), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string().nullable()})}); 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 }; /** * Update a company * * PATCH /api/v1/companies/{id} */ export const patchApiApiV1CompaniesId = async (args: PatchApiApiV1CompaniesIdArgs, options: PatchApiApiV1CompaniesIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/companies/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiApiV1CompaniesIdResponse, await res.json()) };