import { BiasStrength, BrowserBridge, Request } from 'groupby-api'; import { QueryTimeAutocompleteConfig, QueryTimeProductSearchConfig, Sayt } from 'sayt'; import RecommendationsAdapter from './adapters/recommendations'; interface Configuration { /** * GroupBy customer ID */ customerId: string; /** * ID unique to the viewer of the rendered page */ visitorId?: string; /** * ID unique to the session of the viewer of the rendered page */ sessionId?: string; /** * area of search data */ area?: string; /** * input language for the search engine */ language?: string; /** * collection of search data or collection options */ collection?: Configuration.ValueOptions; /** * state initial configuration for SAYT */ autocomplete?: Configuration.Autocomplete; /** * state initial configuration for Searchandiser */ search?: Configuration.Search; /** * state initial configuration for the collections Searchandiser request */ collections?: Configuration.Collections; /** * state initial configuration for Recommendations */ recommendations?: Configuration.Recommendations; /** * state initial configuration for details Searchandiser request */ details?: Configuration.Details; /** * state initial configuration for the more refinements Searchandiser request */ refinements?: Configuration.Refinements; /** * state configuration for navigation related data modifications */ navigations?: Configuration.Navigations; /** * network request configuration */ network?: Configuration.Bridge; /** * personalization configuration */ personalization?: Configuration.Personalization; /** * History length can be either 1 or 0. Setting history length to 0 prevents * products from being saved into browser history, reducing the chance that * the browser size limit will be reached, but forces a re-fetch on history change. */ history?: { length?: number; }; } declare namespace Configuration { interface Bridge { /** * map of headers to send with search requests */ headers?: { [key: string]: string; }; /** * send requests over HTTPS */ https?: boolean; /** * connection timeout for search requests */ timeout?: number; /** * global request error handler */ errorHandler?: (error: Error) => void; /** * add SkipCache header to search requests */ skipCache?: boolean; /** * add SkipSemantish header to search requests */ skipSemantish?: boolean; /** * URL to be used in place of the standard GroupBy search URL. */ proxyUrl?: string; } interface Clients { bridge: BrowserBridge; sayt: Sayt; } interface Sort { /** * field path to sort on */ field: string; descending?: boolean; } interface Search { /** * product fields to request * auto-generated from structure if not provided */ fields?: string[]; /** * number of products to request or sort options and default */ pageSize?: Configuration.ValueOptions; /** * sorting of products or sort options and default */ sort?: Configuration.LabeledValueOptions; /** * redirect to the details page of product if there is only 1 product result for a search */ redirectSingleResult: boolean; /** * maximum number of refinements to show in a single section */ maxRefinements?: number; /** * reset the collection to the default collection on a search */ useDefaultCollection?: boolean; /** * override any computed request value */ overrides?: Configuration.SearchOverrides; } type SearchOverrides = Partial | ((currReq: Request, prevReq: Request) => Request); interface Autocomplete { /** * area override */ area?: string; /** * collection override */ collection?: string; /** * language override */ language?: string; /** * category field used to render sayt results */ category?: string; /** * number of characters before activating typeahead */ searchCharMinLimit?: number; /** * whether to use the first term as a category search */ showCategoryValuesForFirstMatch?: boolean; /** * number of suggestions to request */ suggestionCount?: number; /** * number of navigations to request */ navigationCount?: number; /** * map of field to label, also restricts displayed navigations if provided */ navigations?: { [field: string]: string; }; /** * whether to sort the returned suggestions alphabetically */ alphabetical?: boolean; /** * whether to use fuzzy matching for suggestion results */ fuzzy?: boolean; /** * enable updating query when hovering over sayt elements */ hoverAutoFill?: boolean; /** * specify optional debounce value in milliseconds */ debounceThreshold?: number; /** * autocomplete products settings */ products?: Configuration.Autocomplete.Products; /** * recommendations API settings */ recommendations?: Configuration.Autocomplete.Recommendations; /** * override any computed request value */ overrides?: { suggestions?: Configuration.AutocompleteSuggestionsOverrides; products?: Configuration.AutocompleteProductsOverrides; }; } type AutocompleteSuggestionsOverrides = Partial | ((currConfig: QueryTimeAutocompleteConfig, prevConfig: QueryTimeAutocompleteConfig) => QueryTimeAutocompleteConfig); type AutocompleteProductsOverrides = Partial | ((currConfig: QueryTimeProductSearchConfig, prevConfig: QueryTimeProductSearchConfig) => QueryTimeProductSearchConfig); namespace Autocomplete { interface Recommendations { /** * number of suggestions to request */ suggestionCount: number; /** * type of product siuggestions to request */ suggestionMode: RecommendationMode; } interface Products { /** * area override */ area?: string; /** * collection override */ collection?: string; /** * language override */ language?: string; /** * number of products to request */ count: number; } } interface Recommendations { /** * set object to enable location-specific autocomplete recommendations */ location?: Configuration.Recommendations.Location | false; /** * Product ID field as used in recommendations. */ idField: string; productSuggestions: Configuration.Recommendations.ProductSuggestions; iNav: Configuration.Recommendations.INav; pastPurchases: Configuration.Recommendations.PastPurchases; /** * override any computed request value */ overrides?: { navigations?: Configuration.RecommendationsNavigationsOverrides; ids?: Configuration.RecommendationsIdsOverrides; products?: Configuration.SearchOverrides; autocompleteSuggestions?: Configuration.RecommendationsSuggestionsOverrides; }; } type RecommendationsNavigationsOverrides = Partial | ((currReq: RecommendationsAdapter.RecommendationsBody, prevReq: RecommendationsAdapter.RecommendationsBody) => RecommendationsAdapter.RecommendationsBody); type RecommendationsIdsOverrides = Partial | ((currReq: RecommendationsAdapter.RecommendationsRequest, prevReq: RecommendationsAdapter.RecommendationsRequest) => RecommendationsAdapter.RecommendationsRequest); type RecommendationsSuggestionsOverrides = Partial | ((currReq: RecommendationsAdapter.Request & { query: string; }, prevReq: RecommendationsAdapter.Request & { query: string; }) => RecommendationsAdapter.Request & { query: string; }); interface Personalization { realTimeBiasing?: Personalization.RealTimeBiasing; } namespace Recommendations { interface Location { minSize: number; distance: string; } interface ProductSuggestions { /** * Number of products to request. */ productCount: number; /** * Type of product recommendations to request. */ mode: Configuration.RecommendationMode; } interface PastPurchases { /** * Number of products to request. */ productCount: number; /** * Number of past purchase products to bias by. */ biasCount: number; /** * Overall strength of applied biases. */ biasInfluence: number; /** * Strength of applied biases. */ biasStrength: BiasStrength; /** * A security token or a function to retrieve a token */ securedPayload: Recommendations.SecuredPayload | (() => Recommendations.SecuredPayload); /** * sorting of products or sort options and default */ sort?: Configuration.LabeledValueOptions; /** * Enable past purchases or not */ enabled: boolean; /** * maximum number of refinements to show in a single section */ maxRefinements?: number; /** * override any computed request value */ overrides?: { autocomplete?: Configuration.SearchOverrides; products?: Configuration.SearchOverrides; }; } interface SecuredPayload { cipherText?: string; initialValue?: string; messageAuthenticationCode?: string; } interface INav { /** * Navigation settings. */ navigations: Navigations; /** * Refinement settings. */ refinements: Refinements; /** * Minimum number of navigations required in response. */ minSize?: number; /** * Maximum number of navigations to return. */ size: number; /** * Time period of recorded recommendations. */ window: 'day' | 'week' | 'month'; } interface Navigations { /** * Whether to sort navigations. */ sort: boolean; /** * Navigations to pin to the top regardless of recommendations. */ pinned?: string[]; } interface Refinements { /** * Whether to sort refinements, or array of what refinements to sort. */ sort: boolean | string[]; /** * Refinements to pin to the top regardless of recommendations. */ pinned?: Configuration.Recommendations.Pinned; } interface Pinned { [id: string]: string[]; } } interface Navigations { /** * Remap navigation data type. */ type?: Configuration.Navigations.NavigationType; } namespace Navigations { interface NavigationType { /** * Map of navigation name to data type. */ [key: string]: 'toggle'; } } interface Collections { overrides?: Configuration.SearchOverrides; } interface Details { overrides?: Configuration.SearchOverrides; } interface Refinements { overrides?: Configuration.SearchOverrides; } namespace Personalization { interface RealTimeBiasing { attributes?: { [attribute: string]: RealTimeBiasingAttribute; }; strength: BiasStrength; maxBiases: number; attributeMaxBiases: number; expiry: number; autocomplete: boolean; } interface RealTimeBiasingAttribute { strength: BiasStrength; maxBiases: number; } } type ValueOptions = T | { options: T[]; default: T; }; type LabeledValueOptions = ValueOptions & { labels?: string[]; }; type RecommendationMode = keyof typeof RECOMMENDATION_MODES; const RECOMMENDATION_MODES: { popular: string; trending: string; recent: string; }; } export default Configuration;