@frontic/nuxt 0.1.12 → 0.1.14

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.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * useFronticSearch Composable
3
+ *
4
+ * Full-featured composable for managing Frontic search listings with filtering,
5
+ * sorting, pagination, and search capabilities.
6
+ *
7
+ * For simple listing access without search features, use useFronticListing instead.
8
+ */
9
+ import { type ComputedRef, type ShallowRef } from 'vue';
10
+ import type { MaybeRef } from 'vue';
11
+ import type { Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Responses } from '@frontic/stack/generated-types';
12
+ import type { UseFronticSearchOptions, SearchState } from '../types/search.js';
13
+ /**
14
+ * Full-featured composable for managing Frontic search listings with filtering, sorting, and pagination
15
+ *
16
+ * @param name - The search listing name (e.g., 'ProductSearch', 'CategoryProducts')
17
+ * @param params - Parameters to pass to the listing endpoint
18
+ * @param options - Optional configuration for filtering, sorting, and caching
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const productSearch = useFronticSearch('ProductSearch', {}, {
23
+ * orFilter: ['properties.color', 'options.size'],
24
+ * searchTermThreshold: 2,
25
+ * filter: {
26
+ * select: ['properties.color', 'properties.size'],
27
+ * label: { 'properties.color': 'Color' }
28
+ * },
29
+ * sorting: {
30
+ * label: { 'name:asc': 'Name A-Z', 'price.amount:asc': 'Price Low-High' }
31
+ * }
32
+ * })
33
+ *
34
+ * // Use the search
35
+ * await productSearch.filterResult('properties.color', ['Red', 'Blue'])
36
+ * await productSearch.sortResult('name:asc')
37
+ * await productSearch.loadNext()
38
+ * ```
39
+ */
40
+ export declare function useFronticSearch<TSearch extends keyof Listings, TFilters extends Record<string, unknown> = TSearch extends keyof ListingQueryFilters ? ListingQueryFilters[TSearch] : Record<string, unknown>, TSorts extends Record<string, unknown> = TSearch extends keyof ListingQuerySorts ? ListingQuerySorts[TSearch] : Record<string, unknown>>(name: TSearch, params: MaybeRef<TSearch extends keyof ListingParameters ? ListingParameters[TSearch] : Record<string, unknown>>, options?: UseFronticSearchOptions<TSearch, TFilters, TSorts>): {
41
+ /**
42
+ * The full listing response containing items, pagination info, and filter metadata.
43
+ */
44
+ data: ShallowRef<Responses[TSearch] | undefined>;
45
+ /**
46
+ * The items array from the listing response.
47
+ */
48
+ result: ComputedRef<Responses[TSearch] | undefined>;
49
+ /**
50
+ * Query status: 'pending' | 'error' | 'success'
51
+ */
52
+ status: ShallowRef<import("@pinia/colada").DataStateStatus>;
53
+ /**
54
+ * Current search state including active filters, sorts, pagination, and available options.
55
+ * Use this to build filter/sort UI components.
56
+ */
57
+ state: import("@vue/reactivity").Ref<SearchState<TFilters, TSorts>, SearchState<TFilters, TSorts>>;
58
+ /**
59
+ * Reactive search term. Bind to an input field for live search.
60
+ * Search triggers automatically when term length exceeds searchTermThreshold.
61
+ */
62
+ searchTerm: import("@vue/reactivity").Ref<string, string>;
63
+ /**
64
+ * Load the next page of results (infinite scroll).
65
+ * Appends new items to existing results.
66
+ */
67
+ loadNext: (vars: void) => Promise<unknown>;
68
+ /**
69
+ * Refresh the listing data (uses cache if valid).
70
+ * Call after external changes that should trigger a refresh.
71
+ */
72
+ refresh: () => Promise<void>;
73
+ /**
74
+ * Force a fresh fetch, bypassing cache.
75
+ * Use when you need guaranteed fresh data.
76
+ */
77
+ refetch: () => Promise<void>;
78
+ /**
79
+ * Navigate to next or previous page.
80
+ * @param direction - 'next' or 'prev'
81
+ * @returns true if navigation was successful, false if no more pages
82
+ */
83
+ paginate: (direction: "next" | "prev") => Promise<boolean>;
84
+ /**
85
+ * Sort results by a specific field. Call without arguments to reset to default.
86
+ * @param sortBy - Sort string in format 'field:asc' or 'field:desc', or omit to reset
87
+ */
88
+ sortResult: (sortBy?: string) => Promise<void>;
89
+ /**
90
+ * Reset sorting to default (backend default order).
91
+ */
92
+ resetSorting: () => Promise<void>;
93
+ /**
94
+ * Set filter values for a specific field (replaces existing values).
95
+ * @param filterField - The field to filter on (e.g., 'properties.color')
96
+ * @param filterOptions - Array of values to filter by
97
+ */
98
+ filterResult: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K]>) => Promise<void>;
99
+ /**
100
+ * Add a single filter option to a field (keeps existing values).
101
+ * @param filterField - The field to filter on
102
+ * @param filterOption - The value to add
103
+ */
104
+ addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K]) => Promise<void>;
105
+ /**
106
+ * Remove a filter option from a field, or remove all values for that field.
107
+ * @param filterField - The field to remove filter from
108
+ * @param filterOption - Optional specific value to remove (removes all if omitted)
109
+ */
110
+ removeFilter: <K extends keyof TFilters & string>(filterField: K, filterOption?: TFilters[K]) => Promise<void>;
111
+ /**
112
+ * Reset filters for a specific field or all fields.
113
+ * @param filterField - Optional field to reset (resets all if omitted)
114
+ */
115
+ resetFilter: (filterField?: keyof TFilters & string) => Promise<void>;
116
+ /**
117
+ * Clear the search term and refresh results.
118
+ */
119
+ resetSearch: () => Promise<void>;
120
+ /**
121
+ * Reset all state (search term, filters, and sorting) to initial values.
122
+ * Equivalent to calling resetSearch(), resetFilter(), and resetSorting() together.
123
+ */
124
+ reset: () => Promise<void>;
125
+ };
@@ -1,4 +1,5 @@
1
- import { useState, computed, watch, ref } from "#imports";
1
+ import { useState } from "nuxt/app";
2
+ import { computed, watch, ref } from "vue";
2
3
  import { useQuery, useMutation, useQueryCache } from "@pinia/colada";
3
4
  import { useDebounceFn } from "@vueuse/core";
4
5
  import { makeLogicalFilter, manageFilter, removeFilter } from "../utils/filter-helpers.js";
@@ -99,8 +100,8 @@ export function useFronticSearch(name, params, options) {
99
100
  }
100
101
  });
101
102
  if (!disableSearch) {
102
- watch(searchTerm, (newTerm) => {
103
- if (newTerm.trim().length > searchTermThreshold || searchState.value.active.search) {
103
+ watch(searchTerm, () => {
104
+ if (searchTerm.value.trim().length > searchTermThreshold || searchState.value.active.search) {
104
105
  triggerSearchFromInput();
105
106
  }
106
107
  });
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Ambient type declarations for @frontic/stack/* virtual modules.
3
+ *
4
+ * At runtime, @frontic/stack/* resolves to the user's .frontic/ or .frontstack/
5
+ * directory via aliases configured by the @frontic/nuxt module.
6
+ * These declarations provide fallback types so that:
7
+ * 1. The module builds with proper .d.ts output (mkdist can resolve imports)
8
+ * 2. vue-tsc can typecheck without the generated client being present
9
+ *
10
+ * When the user generates their client (npx @frontic/cli generate), the actual
11
+ * generated types take precedence via the path alias.
12
+ */
13
+
14
+ declare module '@frontic/stack/generated-client' {
15
+ import type { Blocks, Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Responses } from '@frontic/stack/generated-types'
16
+ import type { Query } from '@frontic/stack/query-types'
17
+
18
+ export interface RequestOptions {
19
+ requestUrl?: string
20
+ contextKey?: string
21
+ contextDomain?: string
22
+ proxyUrl?: string
23
+ }
24
+
25
+ export interface ClientConfig {
26
+ proxyUrl?: string
27
+ }
28
+
29
+ export interface FrontstackClient {
30
+ block: <T extends keyof Blocks>(name: T, key: string, config?: RequestOptions) => Promise<Responses[T]>
31
+ listing: <T extends keyof Listings>(
32
+ name: T,
33
+ parameters: T extends keyof ListingParameters ? ListingParameters[T] : Record<string, unknown>,
34
+ config?: {
35
+ query?: Query<T extends keyof ListingQueryFilters ? ListingQueryFilters[T] : unknown, T extends keyof ListingQuerySorts ? ListingQuerySorts[T] : unknown>
36
+ } & RequestOptions
37
+ ) => Promise<Responses[T]>
38
+ page: (slug: string, config?: RequestOptions) => Promise<Page>
39
+ context: (token: string, config?: RequestOptions) => Promise<Context>
40
+ contextList: (token?: string, config?: RequestOptions) => Promise<[ContextOption[], string]>
41
+ contextUpdate: (context: { region: string; locale: string }, token: string, config?: RequestOptions) => Promise<Context>
42
+ }
43
+
44
+ export function createClient(config?: ClientConfig): FrontstackClient
45
+ export const client: FrontstackClient
46
+ }
47
+
48
+ declare module '@frontic/stack/generated-types' {
49
+ export interface Blocks {}
50
+ export interface BlockData {}
51
+ export interface Pages {}
52
+ export interface PageData {}
53
+ export interface Contexts {}
54
+ export interface ContextData {}
55
+ export interface Listings {}
56
+ export interface ListingParameters {}
57
+ export interface ListingQueryFilters {}
58
+ export interface ListingQuerySorts {}
59
+ export interface Responses {
60
+ [key: string]: unknown
61
+ }
62
+ }
63
+
64
+ declare module '@frontic/stack/query-types' {
65
+ export interface Query<TFilter = unknown, TSort = unknown> {
66
+ filter?: Filter[]
67
+ sort?: Sort | Sort[]
68
+ search?: string
69
+ limit?: number
70
+ page?: number
71
+ }
72
+
73
+ export interface Sort {
74
+ field: string
75
+ order: 'asc' | 'desc'
76
+ }
77
+
78
+ export interface EqualsFilter {
79
+ type: 'equals'
80
+ field: string
81
+ value: unknown | unknown[]
82
+ }
83
+
84
+ export interface LogicalFilter {
85
+ type: 'and' | 'or' | 'not'
86
+ filter: Array<EqualsFilter | LogicalFilter>
87
+ }
88
+
89
+ export type Filter = EqualsFilter | LogicalFilter | RangeFilter | ContainsFilter
90
+
91
+ export interface RangeFilter {
92
+ type: 'range'
93
+ field: string
94
+ from?: unknown
95
+ to?: unknown
96
+ }
97
+
98
+ export interface ContainsFilter {
99
+ type: 'contains'
100
+ field: string
101
+ value: string
102
+ }
103
+ }
104
+
105
+ // Global types used by composables (Page, Context, etc.)
106
+ declare interface Page {
107
+ id?: string
108
+ slug?: string
109
+ title?: string
110
+ type?: string
111
+ block?: string
112
+ meta?: Record<string, unknown>
113
+ data?: Record<string, unknown>
114
+ route?: RouteMeta
115
+ }
116
+
117
+ declare interface PageRoute {
118
+ href: string
119
+ path: string
120
+ slug: string
121
+ url: string
122
+ }
123
+
124
+ declare interface AlternateRoute extends PageRoute {
125
+ locale: string
126
+ region: string
127
+ lang?: string
128
+ }
129
+
130
+ declare interface RouteMeta {
131
+ code: 200 | 301 | 404
132
+ redirect?: PageRoute
133
+ alternates?: AlternateRoute[]
134
+ context?: {
135
+ region: string
136
+ locale: string
137
+ suggested?: AlternateRoute
138
+ }
139
+ }
140
+
141
+ declare interface Context {
142
+ region: string
143
+ locale: string
144
+ scope: string
145
+ token: string
146
+ }
147
+
148
+ declare interface ContextOption {
149
+ region: string
150
+ currency: string
151
+ locales: Array<{
152
+ key: string
153
+ url: string
154
+ }>
155
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -1,5 +1,4 @@
1
1
  import { proxyRequest, getHeader, createError, defineEventHandler } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
2
  export default defineEventHandler(async (event) => {
4
3
  const targetUrl = getHeader(event, "fs-target-url");
5
4
  if (!targetUrl) {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Frontic Type Definitions
3
+ *
4
+ * Export all public types from this file.
5
+ */
6
+ export type { FronticOptions, FronticComposable, FronticComposablesConfig } from '../../module.js';
7
+ export type { InclusionMode, FilterField, SortField, SortString, ListingFieldConfig, FilterOption, UiFilter, UiSort, } from './listing.js';
8
+ export type { SearchState, UseFronticSearchOptions, UseSearchReturn } from './search.js';
9
+ export type { UseFronticClientOptions } from '../composables/useFronticClient.js';
10
+ export type { UseFronticBlockOptions } from '../composables/useFronticBlock.js';
11
+ export type { UseFronticPageOptions } from '../composables/useFronticPage.js';
12
+ export type { UseFronticContextOptions } from '../composables/useFronticContext.js';
13
+ export type { UseFronticListingOptions } from '../composables/useFronticListing.js';
@@ -0,0 +1,354 @@
1
+ /**
2
+ * Frontic Listing Types
3
+ *
4
+ * Type definitions for the useFronticListing composable.
5
+ * These types provide type-safe filtering, sorting, and pagination for Frontic listings.
6
+ */
7
+ import type { MaybeRef, Ref, ShallowRef } from 'vue';
8
+ import type { UseQueryReturn } from '@pinia/colada';
9
+ import type { Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Responses } from '@frontic/stack/generated-types';
10
+ export type { Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Responses };
11
+ export type { Query, Sort, EqualsFilter, LogicalFilter, Filter, RangeFilter, ContainsFilter } from '@frontic/stack/query-types';
12
+ /**
13
+ * Shared request options for all Frontic composables
14
+ * These options match the client's RequestOptions interface
15
+ *
16
+ * TODO(FSC-3044): Replace with imported RequestOptions from @frontic/stack/generated-types
17
+ * once the CLI exports it. See: https://linear.app/frontstack/issue/FSC-3044
18
+ */
19
+ export interface FronticRequestOptions {
20
+ /**
21
+ * Context key (token) for locale/region selection
22
+ */
23
+ contextKey?: MaybeRef<string | undefined>;
24
+ /**
25
+ * Context domain to override the global contextDomain for this request
26
+ * Used to indicate the requested region and locale
27
+ */
28
+ contextDomain?: MaybeRef<string | undefined>;
29
+ /**
30
+ * Request URL for analytics/tracking purposes
31
+ * URL to the current page, used by the Fetch API for tracking
32
+ */
33
+ requestUrl?: MaybeRef<string | undefined>;
34
+ }
35
+ /**
36
+ * Inclusion mode for configuring which fields to show
37
+ * - 'include': Only show specified keys
38
+ * - 'exclude': Show all except specified keys
39
+ */
40
+ export type InclusionMode = 'include' | 'exclude';
41
+ /**
42
+ * Extract filter field keys for a specific listing
43
+ * Provides autocomplete for valid filter fields when the listing is in ListingQueryFilters
44
+ *
45
+ * @template TListing - The listing name (e.g., 'ProductSearch')
46
+ * @example
47
+ * ```ts
48
+ * // If ListingQueryFilters['ProductSearch'] = { 'properties.color': string[], 'properties.size': string[] }
49
+ * type Fields = FilterField<'ProductSearch'>
50
+ * // Fields = 'properties.color' | 'properties.size'
51
+ * ```
52
+ */
53
+ export type FilterField<TListing extends keyof Listings> = TListing extends keyof ListingQueryFilters ? keyof ListingQueryFilters[TListing] & string : string;
54
+ /**
55
+ * Extract sort field keys for a specific listing
56
+ * Provides autocomplete for valid sort fields when the listing is in ListingQuerySorts
57
+ *
58
+ * @template TListing - The listing name (e.g., 'ProductSearch')
59
+ * @example
60
+ * ```ts
61
+ * // If ListingQuerySorts['ProductSearch'] = { 'name': 'asc'|'desc', 'price.amount': 'asc'|'desc' }
62
+ * type Fields = SortField<'ProductSearch'>
63
+ * // Fields = 'name' | 'price.amount'
64
+ * ```
65
+ */
66
+ export type SortField<TListing extends keyof Listings> = TListing extends keyof ListingQuerySorts ? keyof ListingQuerySorts[TListing] & string : string;
67
+ /**
68
+ * Type-safe sort string with format "field:order" or "default"
69
+ * Provides autocomplete for valid sort combinations when the listing is known
70
+ *
71
+ * @template TListing - The listing name (e.g., 'ProductSearch')
72
+ * @example
73
+ * ```ts
74
+ * type Sort = SortString<'ProductSearch'>
75
+ * // Sort = 'default' | 'name:asc' | 'name:desc' | 'price.amount:asc' | 'price.amount:desc'
76
+ * ```
77
+ */
78
+ export type SortString<TListing extends keyof Listings> = TListing extends keyof ListingQuerySorts ? 'default' | `${keyof ListingQuerySorts[TListing] & string}:${'asc' | 'desc'}` : 'default' | `${string}:${'asc' | 'desc'}`;
79
+ /**
80
+ * Generic configuration for listing fields (filters or sorts)
81
+ * Allows flexible control over which fields to show and how to label them
82
+ * @template TFields - The field type (e.g., ListingQueryFilters[TListing] or ListingQuerySorts[TListing])
83
+ */
84
+ export interface ListingFieldConfig<TFields = Record<string, unknown>> {
85
+ /** Field keys to include or exclude. If not provided, all fields are shown. */
86
+ select?: Array<keyof TFields & string>;
87
+ /** Mode: 'include' (show only specified) or 'exclude' (hide specified). Default: 'include' */
88
+ mode?: InclusionMode;
89
+ /** Custom labels for fields (e.g., { "properties.color": "Color" }) */
90
+ label?: Partial<Record<keyof TFields & string, string>>;
91
+ /**
92
+ * Define the display order for fields. Keys listed here appear first in the specified order.
93
+ * Any fields not in this array appear after in their original order.
94
+ * @example
95
+ * // Filters: show "Color" first, then "Size", then any others
96
+ * filter: { sort: ['properties.color', 'properties.size'] }
97
+ *
98
+ * // Sorts: show "Relevance" first, then "Price" options
99
+ * sorting: { sort: ['default', 'price.amount:asc', 'price.amount:desc'] }
100
+ */
101
+ sort?: Array<keyof TFields & string>;
102
+ }
103
+ /**
104
+ * Filter option from API response (matches Frontstack response structure)
105
+ * @internal - Used internally, components should use UiFilter
106
+ */
107
+ export interface FilterOption {
108
+ option: string;
109
+ value: string;
110
+ count: number;
111
+ selected?: boolean;
112
+ disabled?: boolean;
113
+ }
114
+ /**
115
+ * Processed filter ready for UI consumption
116
+ * @template TFilters - Filter fields type for this listing (provides autocomplete for key)
117
+ */
118
+ export interface UiFilter<TFilters = Record<string, unknown>> {
119
+ /** Filter field key (typed based on listing schema) */
120
+ key: keyof TFilters & string;
121
+ /** Human-readable label for the filter */
122
+ label: string;
123
+ /** Available filter options with counts and selection state */
124
+ options: FilterOption[];
125
+ }
126
+ /**
127
+ * Processed sort option ready for UI consumption
128
+ * @template TSorts - Sort fields type for this listing (provides autocomplete for key/value)
129
+ */
130
+ export interface UiSort<TSorts = Record<string, unknown>> {
131
+ /** Sort option key (typed based on listing schema, or 'default') */
132
+ key: (keyof TSorts & string) | 'default';
133
+ /** Human-readable label for the sort option */
134
+ label: string;
135
+ /** Sort value to pass to sortResult (same as key) */
136
+ value: (keyof TSorts & string) | 'default';
137
+ }
138
+ /**
139
+ * Listing state exposed to consumers
140
+ * Contains both the current query state and processed data ready for UI consumption
141
+ */
142
+ export interface ListingState {
143
+ /** Current page number */
144
+ page?: number;
145
+ /** Currently applied sort */
146
+ sort?: {
147
+ field: string;
148
+ order: 'asc' | 'desc';
149
+ };
150
+ /** Current search term (if search is enabled) */
151
+ search?: string;
152
+ /** Currently active filters by field */
153
+ filter?: Record<string, unknown>;
154
+ /** Processed filters ready for UI (includes labels, counts, options) */
155
+ availableFilters?: UiFilter[];
156
+ /** Processed sort options ready for UI (includes labels) */
157
+ availableSorts?: UiSort[];
158
+ /** Number of currently active filters */
159
+ activeFilterCount?: number;
160
+ /** Total number of items matching the current query */
161
+ total?: number;
162
+ }
163
+ /**
164
+ * Configuration for the generic listing composable
165
+ */
166
+ export interface UseListingConfig<TListing extends string = string, TFilters = Record<string, unknown>, _TSorts = Record<string, unknown>> {
167
+ /**
168
+ * The listing name to fetch (e.g., 'ProductSearch', 'CategoryProducts')
169
+ */
170
+ name: TListing;
171
+ /**
172
+ * Parameters to pass to the listing endpoint
173
+ */
174
+ params?: MaybeRef<Record<string, unknown>>;
175
+ /**
176
+ * Cache key for the query (defaults to name)
177
+ */
178
+ cacheKey?: string;
179
+ /**
180
+ * Optional context key for the request
181
+ */
182
+ contextKey?: MaybeRef<string | undefined>;
183
+ /**
184
+ * Minimum length of search term before triggering search (default: 2)
185
+ */
186
+ searchTermThreshold?: number;
187
+ /**
188
+ * Filter fields that should use OR logic (all others use AND)
189
+ * Type-safe: only allows valid filter field names for this listing
190
+ */
191
+ orFilter?: Array<keyof TFilters & string>;
192
+ /**
193
+ * Filter configuration using unified structure
194
+ * Type-safe: select and label must match actual filter fields
195
+ * @example
196
+ * // With select and label
197
+ * filters: {
198
+ * select: ['properties.color', 'properties.size'],
199
+ * mode: 'include',
200
+ * label: { 'properties.color': 'Color', 'properties.size': 'Size' }
201
+ * }
202
+ *
203
+ * // Just label (shows all filters with custom labels)
204
+ * filters: {
205
+ * label: { 'properties.color': 'Color' }
206
+ * }
207
+ *
208
+ * // Just select (shows only these filters)
209
+ * filters: {
210
+ * select: ['properties.color', 'properties.size']
211
+ * }
212
+ */
213
+ filters?: ListingFieldConfig<TFilters>;
214
+ /**
215
+ * Sort configuration using unified structure
216
+ * Type-safe: label must use valid sort field names with :asc/:desc suffix
217
+ *
218
+ * Special handling for 'default' sort:
219
+ * - The 'default' sort represents Frontstack backend's default sorting (no sort applied to query)
220
+ * - It's automatically included if a label is provided in sorts.label
221
+ * - Can be controlled via include/exclude mode like other sorts
222
+ * - Use resetSorting() to return to default sorting
223
+ *
224
+ * @example
225
+ * // Full configuration with default sort
226
+ * sorts: {
227
+ * label: {
228
+ * 'default': 'Relevance',
229
+ * 'name:asc': 'Name A-Z',
230
+ * 'price.amount:asc': 'Price Low-High'
231
+ * }
232
+ * }
233
+ *
234
+ * // Just label (all sorts allowed)
235
+ * sorts: {
236
+ * label: {
237
+ * 'name:asc': 'Name A-Z',
238
+ * 'name:desc': 'Name Z-A'
239
+ * }
240
+ * }
241
+ */
242
+ sorts?: ListingFieldConfig<Record<string, unknown>>;
243
+ /**
244
+ * Enable search functionality (default: true)
245
+ */
246
+ enableSearch?: boolean;
247
+ /**
248
+ * Enable filtering functionality (default: true)
249
+ */
250
+ enableFilter?: boolean;
251
+ /**
252
+ * Enable sorting functionality (default: true)
253
+ */
254
+ enableSorting?: boolean;
255
+ /**
256
+ * Stale time in milliseconds (default: 5 minutes)
257
+ */
258
+ staleTime?: number;
259
+ }
260
+ /**
261
+ * Return type for the generic listing composable
262
+ */
263
+ export interface UseListingReturn<TResponse = unknown, TFilters = Record<string, unknown>> {
264
+ /** The current result set containing items and metadata */
265
+ listing: ShallowRef<TResponse | undefined>;
266
+ /** Current fetch status of the listing */
267
+ status: UseQueryReturn['status'];
268
+ /** Current state of the result including page, sort, search, and filter settings */
269
+ state: Ref<ListingState>;
270
+ /** Current search term */
271
+ searchTerm: Ref<string>;
272
+ /**
273
+ * Loads more items in the current listing (infinite scroll)
274
+ */
275
+ loadMore: () => Promise<TResponse | undefined>;
276
+ /**
277
+ * Fetches the listing with current query parameters
278
+ */
279
+ refresh: () => Promise<void>;
280
+ /**
281
+ * Paginates the results in the specified direction
282
+ * @param direction - Direction to paginate ('next' or 'prev')
283
+ * @returns Promise<boolean> - Returns true if pagination was successful
284
+ */
285
+ paginate: (direction: 'next' | 'prev') => Promise<boolean>;
286
+ /**
287
+ * Sorts the results by the specified field
288
+ * Type-safe: only accepts valid sort strings for this listing
289
+ * @param sortBy - Sort field and direction (e.g., 'name:desc' or 'name:asc' or 'default')
290
+ */
291
+ sortItems: (sortBy: string) => Promise<void>;
292
+ /**
293
+ * Resets sorting to default (Frontstack backend default)
294
+ */
295
+ resetSorting: () => Promise<void>;
296
+ /**
297
+ * Adds a filter option to the specified filter field
298
+ * Type-safe: field and value types are validated
299
+ * @param filterField - The field to filter on (autocomplete available)
300
+ * @param filterOption - The option value to add
301
+ */
302
+ addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K]) => Promise<void>;
303
+ /**
304
+ * Removes a filter option from the specified filter field
305
+ * Type-safe: field and value types are validated
306
+ * @param filterField - The field to remove the filter from (autocomplete available)
307
+ * @param filterOption - The option value to remove (optional - omit to remove entire filter)
308
+ */
309
+ removeFilter: <K extends keyof TFilters & string>(filterField: K, filterOption?: TFilters[K]) => Promise<void>;
310
+ /**
311
+ * Applies filter options to the specified filter field
312
+ * Type-safe: field and value types are validated
313
+ * @param filterField - The field to filter on (autocomplete available)
314
+ * @param filterOptions - Array of filter values to apply
315
+ */
316
+ filterItems: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K]>) => Promise<void>;
317
+ /**
318
+ * Resets filters either for a specific field or all filters if no field specified
319
+ * Type-safe: field names are validated
320
+ * @param filterField - Optional field to reset. If omitted, all filters are reset
321
+ */
322
+ resetFilter: (filterField?: keyof TFilters & string) => Promise<void>;
323
+ /**
324
+ * Clears the search term
325
+ */
326
+ resetSearch: () => Promise<void>;
327
+ }
328
+ /**
329
+ * Configuration for listing queries
330
+ * @template TListing - The listing name, constrained to keyof Listings for type safety
331
+ */
332
+ export interface FetchListingConfig<TListing extends keyof Listings = keyof Listings> extends FronticRequestOptions {
333
+ /**
334
+ * The listing name to fetch (e.g., 'ProductSearch', 'CategoryProducts')
335
+ */
336
+ name: TListing;
337
+ /**
338
+ * Parameters to pass to the listing endpoint
339
+ * Type-safe when TListing is a specific listing name
340
+ */
341
+ params: MaybeRef<TListing extends keyof ListingParameters ? ListingParameters[TListing] : Record<string, unknown>>;
342
+ /**
343
+ * Query configuration (filters, sort, search, pagination)
344
+ */
345
+ query?: MaybeRef<Record<string, unknown>>;
346
+ /**
347
+ * Optional page number for pagination
348
+ */
349
+ page?: MaybeRef<number | undefined>;
350
+ /**
351
+ * Stale time in milliseconds (default: 5 minutes)
352
+ */
353
+ staleTime?: number;
354
+ }