import {z} from 'zod' export type CompanyUpdate = {canonicalName?: string | undefined, alternativeNames?: Array | undefined, website?: string | undefined, description?: string | undefined, shortDescription?: string | undefined, sector?: string | undefined, industry?: string | undefined, companyType?: ('operating' | 'investor' | 'lender' | 'investment_bank' | 'advisor' | 'sponsor' | 'service_provider') | undefined, externalId?: string | undefined, custom?: {[key: string]: unknown} | undefined}; export type UpdateApiV1CompaniesIdArgs = {body: CompanyUpdate}; export type UpdateApiV1CompaniesIdOptions = {baseUrl?: string | undefined, MetalClientId?: string | undefined, MetalApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const location = z.object({city: z.string().optional(), state: z.string().optional(), country: z.string().optional()}); export const externalReference = z.object({source: z.string().optional(), id: z.string().optional()}); export const reference = z.object({id: z.string().optional(), type: z.string().optional()}); export const discoveredValue = z.object({value: z.unknown(), source: z.string().optional(), confidence: z.number().optional(), pinned: z.boolean().optional(), discoveredAt: z.string().optional()}); export const enrichmentProvenance = z.record(z.string(), z.array(discoveredValue)); export const company = z.object({id: z.string().optional(), canonicalName: z.string().optional(), alternativeNames: z.array(z.string()).optional(), website: z.string().optional(), description: z.string().optional(), shortDescription: z.string().optional(), sector: z.string().optional(), subsector: z.string().optional(), industry: z.string().optional(), location: location.optional(), companyType: z.enum(["operating", "investor", "lender", "investment_bank", "advisor", "sponsor", "service_provider"]).optional(), origin: z.enum(["user", "crm", "agent", "screening"]).optional(), externalId: z.string().optional(), externalReference: externalReference.optional(), tags: z.array(z.string()).optional(), assignees: z.array(reference).optional(), custom: z.record(z.string(), z.unknown()).optional(), employeeCount: z.number().int().optional(), ownershipStatus: z.string().optional(), lastValuation: z.number().optional(), lastRoundDate: z.string().optional(), lastAmountRaised: z.number().optional(), totalMoneyRaised: z.number().optional(), lastFinancials: z.record(z.string(), z.unknown()).optional(), enrichment: enrichmentProvenance.optional(), lastEnrichedAt: z.string().optional(), lastEnrichmentStartedAt: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const updateApiV1CompaniesIdResponse = z.object({data: company.optional()}); 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 * * PUT /v1/companies/{id} */ export const updateApiV1CompaniesId = async (args: UpdateApiV1CompaniesIdArgs, options?: UpdateApiV1CompaniesIdOptions) => { const {baseUrl = "https://api.metal.ai", fetch: fetchFn = fetch, MetalClientId, MetalApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (MetalClientId !== undefined) headers.set("x-metal-client-id", MetalClientId) if (MetalApiKey !== undefined) headers.set("x-metal-api-key", MetalApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV1CompaniesIdResponse, await res.json()) };