import {z} from 'zod' export type UpdateNewsContactRequest = {name?: string | undefined, title?: (string | null) | undefined, company?: (string | null) | undefined, role_context?: (string | null) | undefined, submitted_linkedin_url?: (string | null) | undefined, matched_contact_id?: (number | null) | undefined, match_status?: ('dismissed' | 'needs_review') | undefined}; export type PatchApiApiNewsSubmissionsIdContactsNewsContactIdArgs = {id: number, newsContactId: number, body: UpdateNewsContactRequest}; export type PatchApiApiNewsSubmissionsIdContactsNewsContactIdOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const newsExtractionMatch = z.object({status: z.enum(["pending", "auto_match", "needs_review", "no_match"]).optional(), confidence: z.number().nullable().optional(), resolved_at: z.string().nullable().optional(), person_profile_id: z.number().int().nullable().optional(), contact_id: z.number().int().nullable().optional(), contactable_type: z.enum(["agency", "brand", "property"]).nullable().optional(), contactable_id: z.number().int().nullable().optional(), entity_name: z.string().nullable().optional(), candidates: z.array(z.object({})).optional()}); export const newsExtractionMatchedContact = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), email: z.string().nullable().optional(), position: z.string().nullable().optional(), linkedin: z.string().nullable().optional()}).nullable(); export const newsExtractionAdd = z.object({status: z.enum(["not_added", "processing", "needs_review", "created", "updated", "failed"]).optional(), added_at: z.string().nullable().optional(), contact_id: z.number().int().nullable().optional(), error: z.string().nullable().optional(), linkedin_url: z.string().nullable().optional(), candidates: z.array(z.object({slug: z.string().optional(), linkedin_url: z.string().optional(), title: z.string().optional(), snippet: z.string().optional(), position: z.number().int().optional()})).optional()}); export const newsContactResource = z.object({id: z.number().int().optional(), name: z.string().optional(), title: z.string().nullable().optional(), company: z.string().nullable().optional(), role_context: z.string().nullable().optional(), confidence: z.number().optional(), source: z.enum(["extracted", "submitted"]).optional(), submitted_linkedin_url: z.string().nullable().optional(), match: newsExtractionMatch.optional(), current: newsExtractionMatchedContact.optional(), add: newsExtractionAdd.optional()}); export const patchApiApiNewsSubmissionsIdContactsNewsContactIdResponse = z.object({data: newsContactResource.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 }; /** * Correct what the extractor read, or which contact the row points at * * PATCH /api/news/submissions/{id}/contacts/{newsContactId} */ export const patchApiApiNewsSubmissionsIdContactsNewsContactId = async (args: PatchApiApiNewsSubmissionsIdContactsNewsContactIdArgs, options: PatchApiApiNewsSubmissionsIdContactsNewsContactIdOptions) => { 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/news/submissions/${encodeURIComponent(String(args.id))}/contacts/${encodeURIComponent(String(args.newsContactId))}${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(patchApiApiNewsSubmissionsIdContactsNewsContactIdResponse, await res.json()) };