import {z} from 'zod' export type ApiFacetRangeModel = {RangeId?: number | undefined, Name: string, LBound?: string | undefined, UBound?: string | undefined, SortOrder: number, AssetName?: string | undefined, AssetUrl?: string | undefined}; export type FacetValueOrderInfo = {Value?: string | undefined, SortOrder?: number | undefined}; export type FacetBoostBury = {BoostValues?: Array | undefined, BuryValues?: Array | undefined}; export type FacetModel = {SyncGuid?: string | undefined, FacetId?: number | undefined, Name: string, FacetType: string, FieldType: string, MaxCount: number, MinHitCount: number, Field: string, Param?: string | undefined, DisplayType: string, ScrollHeight: number, ScrollThreshold: number, TruncateThreshold: number, SearchThreshold: number, SortOrder: number, ExpandSelection: boolean, IsCurrency: boolean, IsNumeric: boolean, IsSearch: boolean, IsVisible: boolean, UBound?: string | undefined, LBound?: string | undefined, Increment?: string | undefined, NofVisible?: number | undefined, Height?: number | undefined, DisplayRuleXML?: string | undefined, SortBy?: string | undefined, ParentId?: number | undefined, IsCollapsible: boolean, IsCollapsedDefault: boolean, SwatchData?: string | undefined, FacetRangeDisplayType?: number | undefined, PreloadChildren?: boolean | undefined, Tooltip?: string | undefined, ShowSliderInputs: boolean, ShowFacetImageCount?: boolean | undefined, FacetRanges?: Array | undefined, Tags?: string | undefined, CreateDate?: string | undefined, ModifyDate?: string | undefined, BoostBury?: FacetBoostBury | undefined, ListName?: string | undefined, NumericPrecision?: number | undefined, CurrencySymbol?: string | undefined, DefaultItemType?: string | undefined}; export type UpdateApiApiV11FacetGuidArgs = {guid: string, 'X-HawkSearch-ApiKey': string, body: FacetModel}; export type UpdateApiApiV11FacetGuidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV11FacetGuidResponse = z.object({}); 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 }; /** * Update facet by guid * * PUT /api/v11/Facet/{guid} */ export const updateApiApiV11FacetGuid = async (args: UpdateApiApiV11FacetGuidArgs, options?: UpdateApiApiV11FacetGuidOptions) => { const {baseUrl = "https://indexing-dev.hawksearch.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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/Facet/${encodeURIComponent(String(args.guid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV11FacetGuidResponse, await res.json()) };