import {z} from 'zod' export type GetApiApiV11BoostburyGuidArgs = {guid: string, 'X-HawkSearch-ApiKey': string}; export type GetApiApiV11BoostburyGuidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const boostBury = z.object({RuleId: z.number().int().optional(), SyncGuid: z.string().optional(), Name: z.string(), IsTrigger: z.boolean(), IsLast: z.boolean(), Boost: z.number().int().optional(), ConditionXml: z.string(), SortOrder: z.number().int().optional(), StartDate: z.string().optional(), EndDate: z.string().optional(), LandingPageIds: z.string().optional(), TriggerXml: z.string().optional(), VisibilityXml: z.string().optional(), Tags: z.string().optional(), CreateDate: z.string().optional(), ModifyDate: z.string().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 }; /** * Get boost bury rule by guid * * GET /api/v11/boostbury/{guid} */ export const getApiApiV11BoostburyGuid = async (args: GetApiApiV11BoostburyGuidArgs, options?: GetApiApiV11BoostburyGuidOptions) => { const {baseUrl = "https://indexing-dev.hawksearch.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-HawkSearch-ApiKey'] != null) headers.set("X-HawkSearch-ApiKey", String(args['X-HawkSearch-ApiKey'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v11/boostbury/${encodeURIComponent(String(args.guid))}${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(boostBury, await res.json()) };