import {z} from 'zod' export type PropertyItem = {property: string, value: string}; export type CreateCompanyDto = {properties: Array}; export type CreateApiApiV1CompaniesCompanyArgs = {body: CreateCompanyDto}; export type CreateApiApiV1CompaniesCompanyOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const objectId = z.object({}); export const contactLinkedin = z.object({id: z.string(), type: z.enum(["common", "sales"])}); export const companyModel = z.object({_id: objectId, owner: objectId, properties: z.object({}), source: z.enum(["crm", "insights", "linkedin-plugin", "linkedin-plugin-fastmode", "integration", "api", "import"]), workspaceId: z.number(), search: objectId, insightId: objectId, linkedin: z.array(contactLinkedin), deleted: z.boolean(), createdAt: z.string(), updatedAt: z.string(), keywords: z.array(z.string()), foundedAt: z.number(), companyType: z.enum(["education", "government", "nonprofit", "private", "public"])}); export const companyResponse = z.object({data: companyModel}); 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 company * * POST /api/v1/companies/company */ export const createApiApiV1CompaniesCompany = async (args: CreateApiApiV1CompaniesCompanyArgs, options?: CreateApiApiV1CompaniesCompanyOptions) => { const {baseUrl = "https://api.getprospect.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("apiKey", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/companies/company${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(companyResponse, await res.json()) };