import {z} from 'zod' export type PatchGeoPersonaRequest = {enabled?: boolean | undefined, name?: string | undefined, role?: string | undefined, company?: string | undefined, summary?: string | undefined, searchStyle?: string | undefined, profile?: ({goals?: Array | undefined, painPoints?: Array | undefined, currentStack?: Array | undefined, buyingTriggers?: Array | undefined, objections?: Array | undefined}) | undefined}; export type PatchApiV1ProjectsProjectIdGeoPersonasPersonaIdArgs = {projectId: string, personaId: string, body: PatchGeoPersonaRequest}; export type PatchApiV1ProjectsProjectIdGeoPersonasPersonaIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const geoPersona = z.object({id: z.string(), name: z.string(), role: z.string(), company: z.string(), summary: z.string(), searchStyle: z.string(), profile: z.object({goals: z.array(z.string()), painPoints: z.array(z.string()), currentStack: z.array(z.string()), buyingTriggers: z.array(z.string()), objections: z.array(z.string())}), conversationPrompts: z.array(z.string()), enabled: z.boolean(), archivedAt: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), memories: z.array(z.object({id: z.string(), kind: z.enum(["background", "experience", "preference", "constraint"]), content: z.string()}))}); export const geoPersonaResponse = z.object({persona: geoPersona, organization: z.object({id: z.string(), slug: z.string(), name: z.string(), logo: 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 GEO persona * * PATCH /v1/projects/{projectId}/geo/personas/{personaId} */ export const patchApiV1ProjectsProjectIdGeoPersonasPersonaId = async (args: PatchApiV1ProjectsProjectIdGeoPersonasPersonaIdArgs, options?: PatchApiV1ProjectsProjectIdGeoPersonasPersonaIdOptions) => { const {baseUrl = "https://api.usenotra.com", 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(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/geo/personas/${encodeURIComponent(String(args.personaId))}${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(geoPersonaResponse, await res.json()) };