import {z} from 'zod' export type GetApiApiV3AccountsInstitutionIdSignalsArgs = {institution_id: string, offset?: number | undefined, limit?: number | undefined, search?: (string | null) | undefined}; export type GetApiApiV3AccountsInstitutionIdSignalsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const signalSignificance = z.enum(["low", "medium", "high"]); export const institutionEnum = z.enum(["k12_districts", "cities", "counties", "higher_education", "federal_agencies", "federal_departments", "individual_units", "k12_schools", "police_agencies", "usfa_registry", "state_agencies", "states"]); export const cRMType = z.enum(["hubspot", "salesforce", "zapier"]); export const signalInstitution = z.object({name: z.string(), state: z.string(), type: institutionEnum, linked_providers: z.array(cRMType).optional()}); export const signalStatusEnum = z.enum(["active", "dismissed", "pending", "acknowledged"]); export const signalSourceType = z.enum(["purchase_order", "meeting_minutes", "annual_budgets", "procurement_guidelines", "youtube", "rfp", "grants", "press_releases"]); export const enrichedSignal = z.object({id: z.string(), signal_setting_id: z.string(), institution_id: z.string(), significance: signalSignificance, reason: z.string().nullable(), summary: z.string().nullable(), title: z.string().nullable(), metadata_: z.record(z.string(), z.unknown()).nullable(), created_at: z.string(), document_date: z.string().nullable().optional(), query: z.string(), institution: signalInstitution, status: signalStatusEnum, source_type: signalSourceType, keywords: z.array(z.string()).optional(), list_ids: z.array(z.string()).optional()}); export const paginatedResponseEnrichedSignal = z.object({results: z.array(enrichedSignal), total: z.number().int(), offset: z.number().int(), limit: z.number().int()}); 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 }; /** * List Institution Signals * * GET /api/v3/accounts/{institution_id}/signals */ export const getApiApiV3AccountsInstitutionIdSignals = async (args: GetApiApiV3AccountsInstitutionIdSignalsArgs, options: GetApiApiV3AccountsInstitutionIdSignalsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.search != null) query.append("search", String(args.search)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/accounts/${encodeURIComponent(String(args.institution_id))}/signals${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedResponseEnrichedSignal, await res.json()) };