import {z} from 'zod' export type SignalStatusEnum = 'active' | 'dismissed' | 'pending' | 'acknowledged'; export type SignalSourceType = 'purchase_order' | 'meeting_minutes' | 'annual_budgets' | 'procurement_guidelines' | 'youtube' | 'rfp' | 'grants' | 'press_releases'; export type InstitutionEnum = 'k12_districts' | 'cities' | 'counties' | 'higher_education' | 'federal_agencies' | 'federal_departments' | 'individual_units' | 'k12_schools' | 'police_agencies' | 'usfa_registry' | 'state_agencies' | 'states'; export type SignalSortEnum = 'created_at_desc' | 'created_at_asc'; export type InstitutionSortEnum = 'most_signals' | 'most_recent' | 'oldest' | 'most_contacts' | 'account_type'; export type SignalFilters = {created_after?: (string | null) | undefined, created_before?: (string | null) | undefined, offset?: number | undefined, limit?: (number | null) | undefined, statuses?: (Array | null) | undefined, signal_ids?: (Array | null) | undefined, signal_setting_ids?: (Array | null) | undefined, list_ids?: (Array | null) | undefined, data_sources?: (Array | null) | undefined, institution_types?: (Array | null) | undefined, keywords?: (Array | null) | undefined, states?: (Array | null) | undefined, saved?: (boolean | null) | undefined, exclude_territory_ids?: (Array | null) | undefined, exclude_institution_ids?: (Array | null) | undefined, sort_by?: SignalSortEnum | undefined, institution_sort?: (InstitutionSortEnum | null) | undefined, user_id?: (string | null) | undefined, query?: (string | null) | undefined}; export type CreateApiApiV3SignalsSearchArgs = {body: SignalFilters}; export type CreateApiApiV3SignalsSearchOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV3SignalsSearchResponse = z.unknown(); 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 }; /** * Search Signals * * POST /api/v3/signals/search */ export const createApiApiV3SignalsSearch = async (args: CreateApiApiV3SignalsSearchArgs, options: CreateApiApiV3SignalsSearchOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/signals/search${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(createApiApiV3SignalsSearchResponse, await res.json()) };