@nosto/search-js 3.21.1 → 3.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,5 +8,22 @@ export type SearchHitWithSku = SearchHit & {
8
8
  * @param type - The type of search that the hit belongs to.
9
9
  * @param hit - The search hit to add to the cart.
10
10
  * @param quantity - The quantity of the hit to add to the cart.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { addToCart } from '@nosto/search-js'
15
+ *
16
+ * // Add a single product to cart
17
+ * await addToCart('serp', {
18
+ * productId: '123',
19
+ * skuId: 'sku-123'
20
+ * })
21
+ *
22
+ * // Add multiple quantities
23
+ * await addToCart('serp', {
24
+ * productId: '456',
25
+ * skuId: 'sku-456'
26
+ * }, 3)
27
+ * ```
11
28
  */
12
29
  export declare function addToCart(type: SearchTrackOptions, hit: SearchHitWithSku, quantity?: number): Promise<void>;
@@ -6,5 +6,33 @@ import { DecoratedResult, HitDecorator, SearchOptions } from './types';
6
6
  * @param query - The search query to be executed.
7
7
  * @param options - An object containing optional parameters for the search.
8
8
  * @returns A promise that resolves to the search result.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { search } from '@nosto/search-js'
13
+ * import { priceDecorator } from '@nosto/search-js/currencies'
14
+ *
15
+ * // Basic search
16
+ * const results = await search({ query: 'shoes' })
17
+ *
18
+ * // Search with decorators
19
+ * const decoratedResults = await search(
20
+ * { query: 'shoes' },
21
+ * { hitDecorators: [priceDecorator()] }
22
+ * )
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { search } from '@nosto/search-js'
28
+ *
29
+ * // Search with filters
30
+ * const results = await search({
31
+ * query: 'shoes',
32
+ * filters: {
33
+ * color: ['red', 'blue']
34
+ * }
35
+ * })
36
+ * ```
9
37
  */
10
38
  export declare function search<HD extends readonly HitDecorator[]>(query: SearchQuery, options?: SearchOptions<HD>): Promise<DecoratedResult<HD>>;
@@ -5,6 +5,43 @@ export interface CurrencyConfig {
5
5
  defaultLocale: string;
6
6
  currencySettings: CurrencyFormats;
7
7
  }
8
+ /**
9
+ * Creates a currency formatting function with customizable settings.
10
+ *
11
+ * @param overrides - Optional configuration to override default currency settings.
12
+ * @returns An object containing the formatCurrency function.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { getCurrencyFormatting } from '@nosto/search-js/currencies'
17
+ *
18
+ * // Use default settings from Nosto
19
+ * const { formatCurrency } = getCurrencyFormatting()
20
+ * console.log(formatCurrency(1234.56)) // Uses default currency
21
+ * console.log(formatCurrency(1234.56, 'USD')) // "$1,234.56"
22
+ * ```
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { getCurrencyFormatting } from '@nosto/search-js/currencies'
27
+ *
28
+ * // Override with custom settings
29
+ * const { formatCurrency } = getCurrencyFormatting({
30
+ * defaultCurrency: 'EUR',
31
+ * defaultLocale: 'de-DE',
32
+ * currencySettings: {
33
+ * EUR: {
34
+ * currencyBeforeAmount: false,
35
+ * currencyToken: '€',
36
+ * decimalCharacter: ',',
37
+ * groupingSeparator: '.',
38
+ * decimalPlaces: 2
39
+ * }
40
+ * }
41
+ * })
42
+ * console.log(formatCurrency(1234.56)) // "1.234,56€"
43
+ * ```
44
+ */
8
45
  export declare function getCurrencyFormatting(overrides?: Partial<CurrencyConfig>): {
9
46
  formatCurrency: (value: number, currency?: string) => string;
10
47
  };
@@ -8,8 +8,49 @@ export type Result = SearchProduct & FormattedPrices & {
8
8
  skus?: (SearchProductSku & FormattedPrices)[];
9
9
  };
10
10
  /**
11
- * Exposes currency formatting logic as a SearchProduct decorator
12
- * Sets priceText and listPriceText fields on product and SKU level
13
- * Requires price, listPrice and priceCurrencyCode fields to be present
11
+ * Exposes currency formatting logic as a SearchProduct decorator.
12
+ * Sets priceText and listPriceText fields on product and SKU level.
13
+ * Requires price, listPrice and priceCurrencyCode fields to be present.
14
+ *
15
+ * @param config - Optional configuration to customize currency formatting.
16
+ * @returns A decorator function that adds formatted price text to search products.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { search } from '@nosto/search-js'
21
+ * import { priceDecorator } from '@nosto/search-js/currencies'
22
+ *
23
+ * // Use with default settings
24
+ * const results = await search(
25
+ * { query: 'shoes' },
26
+ * { hitDecorators: [priceDecorator()] }
27
+ * )
28
+ * console.log(results.products.hits[0].priceText) // "$99.99"
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { search } from '@nosto/search-js'
34
+ * import { priceDecorator } from '@nosto/search-js/currencies'
35
+ *
36
+ * // Use with custom currency settings
37
+ * const customDecorator = priceDecorator({
38
+ * defaultCurrency: 'EUR',
39
+ * currencySettings: {
40
+ * EUR: {
41
+ * currencyBeforeAmount: true,
42
+ * currencyToken: '€',
43
+ * decimalCharacter: ',',
44
+ * groupingSeparator: '.',
45
+ * decimalPlaces: 2
46
+ * }
47
+ * }
48
+ * })
49
+ * const results = await search(
50
+ * { query: 'shoes' },
51
+ * { hitDecorators: [customDecorator] }
52
+ * )
53
+ * console.log(results.products.hits[0].priceText) // "€99,99"
54
+ * ```
14
55
  */
15
56
  export declare function priceDecorator(config?: Partial<CurrencyConfig>): (hit: SearchProduct) => Result;
@@ -31,13 +31,6 @@ type RangeProps = [number | undefined, number | undefined];
31
31
  * ```
32
32
  */
33
33
  export declare function useRange(id: string): {
34
- readonly min: 0;
35
- readonly max: 0;
36
- readonly range: readonly [0, 0];
37
- readonly active: false;
38
- readonly toggleActive: () => void;
39
- readonly updateRange: () => void;
40
- } | {
41
34
  /** Min value */
42
35
  min: number;
43
36
  /** Max value */
@@ -80,9 +80,9 @@ export declare function useRangeSelector(id: string, rangeSize: number): {
80
80
  /** Maximum value */
81
81
  max: number;
82
82
  /** Range value */
83
- range: number[] | readonly [0, 0];
83
+ range: number[];
84
84
  /** Update range function */
85
- updateRange: (([from, to]: [number | undefined, number | undefined]) => void) | (() => void);
85
+ updateRange: ([from, to]: [number | undefined, number | undefined]) => void;
86
86
  /** Ranges */
87
87
  ranges: {
88
88
  min: number;
@@ -5,5 +5,29 @@ export type Config = {
5
5
  /**
6
6
  * Replaces full size images with thumbnail sized versions.
7
7
  * Uses `shopifyThumbnailDecorator` and `nostoThumbnailDecorator` based on the platform.
8
+ *
9
+ * @param config - Configuration object specifying the desired thumbnail size.
10
+ * @returns A decorator function that transforms image URLs to thumbnail versions.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { search } from '@nosto/search-js'
15
+ * import { thumbnailDecorator } from '@nosto/search-js/thumbnails'
16
+ *
17
+ * // Use thumbnail decorator with search
18
+ * const results = await search(
19
+ * { query: 'shoes' },
20
+ * {
21
+ * hitDecorators: [
22
+ * thumbnailDecorator({ size: '200x200' })
23
+ * ]
24
+ * }
25
+ * )
26
+ * console.log(results.products.hits[0].thumb_url)
27
+ *
28
+ * // Available sizes: '100x100', '200x200', '400x400', '600x600', '800x800'
29
+ * const smallThumbs = thumbnailDecorator({ size: '100x100' })
30
+ * const largeThumbs = thumbnailDecorator({ size: '800x800' })
31
+ * ```
8
32
  */
9
33
  export declare function thumbnailDecorator({ size }: Config): (hit: import('@nosto/nosto-js/client').SearchProduct) => import('@nosto/nosto-js/client').SearchProduct;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosto/search-js",
3
- "version": "3.21.1",
3
+ "version": "3.21.2",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "files": [