import {z} from 'zod' export type GetApiApiV11BannerIdArgs = {id: number, 'X-HawkSearch-ApiKey': string}; export type GetApiApiV11BannerIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const banner = z.object({Id: z.number().int().optional(), SyncGuid: z.string().optional(), Name: z.string(), BannerType: z.string().optional(), Width: z.number().int().gte(0).lte(2147483647).optional(), Height: z.number().int().gte(0).lte(2147483647).optional(), Link: z.string().optional(), Filename: z.string().optional(), AltText: z.string().optional(), HTML: z.string().optional(), Target: z.string().optional(), IsTrackingEnabled: z.boolean().optional(), RuleXML: z.string().optional(), RuleStyle: z.string().optional(), RuleSortFieldId: z.number().int().optional(), RuleNofItems: z.number().int().optional(), RuleSortDirection: z.string().optional(), RuleTitle: z.string().optional(), RuleIsDynamic: z.boolean().optional(), WidgetId: z.number().int().optional(), WidgetArgs: z.string().optional(), Tags: z.string().optional(), IsMobile: z.boolean().optional(), DisableHtmlEditor: z.boolean().optional(), MobileBannerType: z.string().optional(), MobileIsTrackingEnabled: z.boolean().optional(), MobileHTML: z.string().optional(), MobileWidth: z.number().int().optional(), MobileHeight: z.number().int().optional(), MobileLink: z.string().optional(), MobileAltText: z.string().optional(), MobileTarget: z.string().optional(), MobileFileName: z.string().optional(), MobileWidgetId: z.number().int().optional(), MobileWidgetArgs: z.string().optional(), MobileCustomWidgetArgs: z.string().optional(), MobileDisableHtmlEditor: z.boolean().optional(), CustomWidgetArgs: z.string().optional(), CreateDate: z.string().optional(), ModifyDate: z.string().optional(), IsTablet: z.boolean().optional(), TabletBannerType: z.string().optional(), TabletIsTrackingEnabled: z.boolean().optional(), TabletHTML: z.string().optional(), TabletWidth: z.number().int().optional(), TabletHeight: z.number().int().optional(), TabletLink: z.string().optional(), TabletAltText: z.string().optional(), TabletTarget: z.string().optional(), TabletFileName: z.string().optional(), TabletWidgetId: z.number().int().optional(), TabletWidgetArgs: z.string().optional(), TabletCustomWidgetArgs: z.string().optional(), TabletDisableHtmlEditor: z.boolean().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 banner by id * * GET /api/v11/banner/{id} */ export const getApiApiV11BannerId = async (args: GetApiApiV11BannerIdArgs, options?: GetApiApiV11BannerIdOptions) => { 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/banner/${encodeURIComponent(String(args.id))}${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(banner, await res.json()) };