@bradsearch/search-sdk
Version:
TypeScript SDK for BradSearch API with JWT authentication, field mapping, and faceted search capabilities
102 lines • 2.82 kB
TypeScript
export type FieldType = "text" | "keyword" | "text_keyword" | "hierarchy" | "variants" | "object" | "url" | "image_url" | "integer";
/**
* Visibility setting for facets by viewport. Undefined defaults to 'both'.
*/
export type FacetsVisibility = "mobile" | "desktop" | "both";
export interface FieldConfig {
type: FieldType;
filterable?: boolean;
fields?: Record<string, FieldConfig>;
label?: string;
count?: number;
/** Number of hierarchy depth levels to display as tree (hierarchy type only). Prunes top levels when tree is deeper than depth. */
depth?: number;
/** Control facets visibility by device type */
facetsVisibility?: FacetsVisibility;
}
export interface ItemMapping {
title?: string;
reference?: string;
link?: string;
imageUrl?: string;
brand?: string;
price?: string;
priceTaxExcluded?: string;
basePrice?: string;
basePriceTaxExcluded?: string;
[key: string]: string | undefined;
}
export interface ApiSdkConfig {
token: string;
baseUrl: string;
fields: Record<string, FieldConfig>;
mapping?: ItemMapping;
}
export interface Item {
id: string;
title: string;
link: string;
imageUrl: {
small: string;
medium: string;
};
reference: string;
brand?: string;
_highlights?: Record<string, string>;
price?: string;
priceTaxExcluded?: string;
basePrice?: string;
basePriceTaxExcluded?: string;
}
export interface FacetValue {
value: string;
count: number;
}
export interface Context {
price: PriceContext;
}
export interface PriceContext {
withTaxes: boolean;
}
export interface DidYouMean {
categories?: string[];
queries?: string[];
}
export interface SearchResponse<T = Item> {
limit: number;
total: number;
offset: number;
facets: Record<string, FacetValue[]>;
documents: T[];
'did-you-mean'?: DidYouMean;
}
export interface QueryOptions {
signal?: AbortSignal;
limit?: number;
offset?: number;
sortBy?: string;
locale?: string;
order?: "asc" | "desc";
searchAll?: boolean;
autocomplete?: boolean;
context?: Context;
correlationId?: string;
}
export interface Filters {
[fieldName: string]: string | string[];
}
export declare class ApiError extends Error {
statusCode?: number | undefined;
constructor(message: string, statusCode?: number | undefined);
}
export declare class AuthenticationError extends ApiError {
constructor(message?: string);
}
export declare class ValidationError extends ApiError {
constructor(message?: string);
}
export declare class NetworkError extends ApiError {
constructor(message?: string);
}
export declare function filterable(target: any, propertyKey: string): void;
//# sourceMappingURL=index.d.ts.map