import {z} from 'zod' export type GetApiApiV1SocialMascotJsonOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1SocialMascotJsonResponse = z.object({schema_version: z.string().optional(), mascot_name: z.string().optional(), bible_page: z.string().optional(), handles: z.record(z.string(), z.string()).optional(), handle_status: z.record(z.string(), z.string()).optional(), voice: z.record(z.string(), z.unknown()).optional(), tone: z.record(z.string(), z.unknown()).optional(), pillars: z.array(z.record(z.string(), z.unknown())).optional(), cadence: z.record(z.string(), z.unknown()).optional(), posting_hours_utc: z.record(z.string(), z.unknown()).optional(), hashtag_bank: z.record(z.string(), z.unknown()).optional(), sample_batch: z.record(z.string(), z.unknown()).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 }; /** * Data Nerd mascot bible, voice, pillars, cadence, sample batch * * GET /api/v1/social-mascot.json */ export const getApiApiV1SocialMascotJson = async (options?: GetApiApiV1SocialMascotJsonOptions) => { const {baseUrl = "https://signals.gitdealflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/social-mascot.json${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(getApiApiV1SocialMascotJsonResponse, await res.json()) };