@frontic/nuxt 0.8.4 → 1.0.0
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.
- package/README.md +30 -2
- package/dist/module.d.mts +2 -132
- package/dist/module.json +2 -2
- package/dist/module.mjs +63 -7
- package/dist/runtime/composables/analytics.d.ts +82 -0
- package/dist/runtime/composables/analytics.js +38 -0
- package/dist/runtime/composables/blocks.d.ts +24 -22
- package/dist/runtime/composables/blocks.js +16 -16
- package/dist/runtime/composables/index.d.ts +1 -1
- package/dist/runtime/composables/listings.d.ts +22 -13
- package/dist/runtime/composables/listings.js +24 -25
- package/dist/runtime/composables/pages.d.ts +21 -18
- package/dist/runtime/composables/pages.js +15 -16
- package/dist/runtime/composables/trees.d.ts +24 -22
- package/dist/runtime/composables/trees.js +15 -25
- package/dist/runtime/composables/useFronticBlock.d.ts +22 -13
- package/dist/runtime/composables/useFronticBlock.js +19 -2
- package/dist/runtime/composables/useFronticClient.d.ts +6 -3
- package/dist/runtime/composables/useFronticContext.d.ts +12 -0
- package/dist/runtime/composables/useFronticContext.js +71 -9
- package/dist/runtime/composables/useFronticListing.d.ts +23 -19
- package/dist/runtime/composables/useFronticListing.js +22 -3
- package/dist/runtime/composables/useFronticPage.d.ts +35 -16
- package/dist/runtime/composables/useFronticPage.js +36 -7
- package/dist/runtime/composables/useFronticSearch.d.ts +4 -96
- package/dist/runtime/composables/useFronticSearch.js +179 -51
- package/dist/runtime/composables/useFronticTree.d.ts +23 -14
- package/dist/runtime/composables/useFronticTree.js +19 -2
- package/dist/runtime/server/plugins/fetch-secret.d.ts +2 -0
- package/dist/runtime/server/plugins/fetch-secret.js +20 -0
- package/dist/runtime/types/client.d.ts +34 -0
- package/dist/runtime/types/client.js +0 -0
- package/dist/runtime/types/index.d.ts +8 -3
- package/dist/runtime/types/listing.d.ts +113 -251
- package/dist/runtime/types/options.d.ts +139 -0
- package/dist/runtime/types/options.js +0 -0
- package/dist/runtime/types/query.d.ts +88 -0
- package/dist/runtime/types/query.js +0 -0
- package/dist/runtime/types/registry.d.ts +272 -0
- package/dist/runtime/types/registry.js +0 -0
- package/dist/runtime/types/search.d.ts +56 -36
- package/dist/runtime/utils/errors.d.ts +22 -0
- package/dist/runtime/utils/errors.js +3 -0
- package/dist/runtime/utils/index.d.ts +2 -0
- package/dist/runtime/utils/index.js +2 -0
- package/dist/runtime/utils/query-keys.d.ts +27 -0
- package/dist/runtime/utils/query-keys.js +18 -0
- package/dist/runtime/utils/state-helpers.d.ts +3 -6
- package/dist/runtime/utils/state-helpers.js +7 -8
- package/dist/types.d.mts +2 -2
- package/package.json +15 -15
- package/dist/runtime/frontic-stack.d.ts +0 -168
|
@@ -1,25 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Frontic Listing Types
|
|
3
3
|
*
|
|
4
|
-
* Type definitions for the useFronticListing composable
|
|
5
|
-
*
|
|
4
|
+
* Type definitions for the useFronticListing composable and the listing query
|
|
5
|
+
* factory. All schema-derived typing flows from the registry (./registry).
|
|
6
6
|
*/
|
|
7
|
-
import type { MaybeRef,
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
export type { Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Responses };
|
|
11
|
-
export type { Query, Sort, EqualsFilter, LogicalFilter, Filter, RangeFilter, ContainsFilter } from '
|
|
7
|
+
import type { MaybeRef, MaybeRefOrGetter } from 'vue';
|
|
8
|
+
import type { ListingName, ListingParamsOf, ListingFiltersOf, ListingSortsOf, RequestOptions, FilterGroup, AggregationGroup, DefaultFilterOption, DefaultAggregationStats, FilterData, AggregationData, Pagination } from './registry.js';
|
|
9
|
+
import type { Query } from './query.js';
|
|
10
|
+
export type { Blocks, Listings, ListingParameters, ListingQueryFilters, ListingQuerySorts, Trees, Responses, ResponseOf, ListingParamsOf, ListingFiltersOf, ListingSortsOf, RequestOptions, TreeQuery, Pagination, FilterData, AggregationData, FilterGroup, AggregationGroup, } from './registry.js';
|
|
11
|
+
export type { Query, Sort, SortField as QuerySortField, EqualsFilter, LogicalFilter, Filter, RangeFilter, ContainsFilter } from './query.js';
|
|
12
12
|
/**
|
|
13
13
|
* Shared request options for all Frontic composables.
|
|
14
14
|
*
|
|
15
|
-
* Derived from the client's `RequestOptions
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* Derived from the client's `RequestOptions`; each field is wrapped in
|
|
16
|
+
* `MaybeRef` so callers can pass reactive values. Narrowed to the options that
|
|
17
|
+
* make sense per call site (proxyUrl is configured at module level, secret is
|
|
18
|
+
* injected server-side).
|
|
19
19
|
*/
|
|
20
20
|
export type FronticRequestOptions = {
|
|
21
21
|
[K in 'contextKey' | 'contextDomain' | 'requestUrl']?: MaybeRef<RequestOptions[K] | undefined>;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Cache behaviour options shared by all Frontic query composables and
|
|
25
|
+
* factories. Each maps onto the Pinia Colada query option of the same concern.
|
|
26
|
+
*/
|
|
27
|
+
export interface FronticQueryOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Cache stale time in milliseconds
|
|
30
|
+
* @default 300000 (5 minutes)
|
|
31
|
+
*/
|
|
32
|
+
staleTime?: number;
|
|
33
|
+
/**
|
|
34
|
+
* How long an unused cache entry is kept before garbage collection, in
|
|
35
|
+
* milliseconds. Forwarded to Pinia Colada (its default: 5 minutes).
|
|
36
|
+
*/
|
|
37
|
+
gcTime?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the query fetches. While `false`, no request is made; flipping it
|
|
40
|
+
* back to `true` refreshes. Useful when an input (e.g. a reactive key) is
|
|
41
|
+
* not known yet.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Keep the previous data on screen while a changed query (new page, filter,
|
|
47
|
+
* context) loads, instead of dropping back to `pending`. First loads still
|
|
48
|
+
* report `pending`; track background loads via `asyncStatus`/`isLoading`.
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
keepPreviousData?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves to the typed `Query<filter, sort>` shape for a given listing name.
|
|
55
|
+
* Falls back to an untyped query when the listing isn't in the generated maps.
|
|
56
|
+
*/
|
|
57
|
+
export type ListingQuery<TListing extends ListingName = ListingName> = Query<ListingFiltersOf<TListing>, ListingSortsOf<TListing>>;
|
|
23
58
|
/**
|
|
24
59
|
* Inclusion mode for configuring which fields to show
|
|
25
60
|
* - 'include': Only show specified keys
|
|
@@ -28,33 +63,43 @@ export type FronticRequestOptions = {
|
|
|
28
63
|
export type InclusionMode = 'include' | 'exclude';
|
|
29
64
|
/**
|
|
30
65
|
* Extract filter field keys for a specific listing
|
|
31
|
-
* Provides autocomplete for valid filter fields when the listing is in
|
|
66
|
+
* Provides autocomplete for valid filter fields when the listing is in the registry
|
|
32
67
|
*
|
|
33
68
|
* @template TListing - The listing name (e.g., 'ProductSearch')
|
|
34
69
|
* @example
|
|
35
70
|
* ```ts
|
|
36
|
-
* // If
|
|
71
|
+
* // If the filters map for 'ProductSearch' is { 'properties.color': string, 'properties.size': string }
|
|
37
72
|
* type Fields = FilterField<'ProductSearch'>
|
|
38
73
|
* // Fields = 'properties.color' | 'properties.size'
|
|
39
74
|
* ```
|
|
40
75
|
*/
|
|
41
|
-
export type FilterField<TListing extends
|
|
76
|
+
export type FilterField<TListing extends ListingName> = keyof ListingFiltersOf<TListing> & string;
|
|
42
77
|
/**
|
|
43
78
|
* Extract sort field keys for a specific listing
|
|
44
|
-
* Provides autocomplete for valid sort fields when the listing is in
|
|
79
|
+
* Provides autocomplete for valid sort fields when the listing is in the registry
|
|
45
80
|
*
|
|
46
81
|
* @template TListing - The listing name (e.g., 'ProductSearch')
|
|
47
82
|
* @example
|
|
48
83
|
* ```ts
|
|
49
|
-
* // If
|
|
84
|
+
* // If the sorts map for 'ProductSearch' is { 'name': string, 'price.amount': number }
|
|
50
85
|
* type Fields = SortField<'ProductSearch'>
|
|
51
86
|
* // Fields = 'name' | 'price.amount'
|
|
52
87
|
* ```
|
|
53
88
|
*/
|
|
54
|
-
export type SortField<TListing extends
|
|
89
|
+
export type SortField<TListing extends ListingName> = keyof ListingSortsOf<TListing> & string;
|
|
55
90
|
/**
|
|
56
91
|
* Type-safe sort string with format "field:order" or "default"
|
|
57
|
-
*
|
|
92
|
+
*
|
|
93
|
+
* @template TSorts - The sortable fields map (field -> value type)
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* type S = SortStringOf<{ name: string; 'price.amount': number }>
|
|
97
|
+
* // S = 'default' | 'name:asc' | 'name:desc' | 'price.amount:asc' | 'price.amount:desc'
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export type SortStringOf<TSorts> = string extends keyof TSorts & string ? 'default' | `${string}:${'asc' | 'desc'}` : 'default' | `${keyof TSorts & string}:${'asc' | 'desc'}`;
|
|
101
|
+
/**
|
|
102
|
+
* Type-safe sort string for a specific listing name
|
|
58
103
|
*
|
|
59
104
|
* @template TListing - The listing name (e.g., 'ProductSearch')
|
|
60
105
|
* @example
|
|
@@ -63,19 +108,19 @@ export type SortField<TListing extends keyof Listings> = TListing extends keyof
|
|
|
63
108
|
* // Sort = 'default' | 'name:asc' | 'name:desc' | 'price.amount:asc' | 'price.amount:desc'
|
|
64
109
|
* ```
|
|
65
110
|
*/
|
|
66
|
-
export type SortString<TListing extends
|
|
111
|
+
export type SortString<TListing extends ListingName> = SortStringOf<ListingSortsOf<TListing>>;
|
|
67
112
|
/**
|
|
68
113
|
* Generic configuration for listing fields (filters or sorts)
|
|
69
114
|
* Allows flexible control over which fields to show and how to label them
|
|
70
|
-
* @template
|
|
115
|
+
* @template TKeys - The allowed key union (filter field names, or sort strings)
|
|
71
116
|
*/
|
|
72
|
-
export interface ListingFieldConfig<
|
|
117
|
+
export interface ListingFieldConfig<TKeys extends string = string> {
|
|
73
118
|
/** Field keys to include or exclude. If not provided, all fields are shown. */
|
|
74
|
-
select?:
|
|
119
|
+
select?: TKeys[];
|
|
75
120
|
/** Mode: 'include' (show only specified) or 'exclude' (hide specified). Default: 'include' */
|
|
76
121
|
mode?: InclusionMode;
|
|
77
122
|
/** Custom labels for fields (e.g., { "properties.color": "Color" }) */
|
|
78
|
-
label?: Partial<Record<
|
|
123
|
+
label?: Partial<Record<TKeys, string>>;
|
|
79
124
|
/**
|
|
80
125
|
* Define the display order for fields. Keys listed here appear first in the specified order.
|
|
81
126
|
* Any fields not in this array appear after in their original order.
|
|
@@ -86,7 +131,7 @@ export interface ListingFieldConfig<TFields = Record<string, unknown>> {
|
|
|
86
131
|
* // Sorts: show "Relevance" first, then "Price" options
|
|
87
132
|
* sorting: { sort: ['default', 'price.amount:asc', 'price.amount:desc'] }
|
|
88
133
|
*/
|
|
89
|
-
sort?:
|
|
134
|
+
sort?: TKeys[];
|
|
90
135
|
/**
|
|
91
136
|
* Display type per field. Value is passed through as-is to UiFilter.type.
|
|
92
137
|
* Use any string that fits your UI rendering logic (e.g., 'range', 'boolean', 'color').
|
|
@@ -94,19 +139,13 @@ export interface ListingFieldConfig<TFields = Record<string, unknown>> {
|
|
|
94
139
|
* @example
|
|
95
140
|
* type: { 'price.amount': 'range', 'properties.isNew': 'boolean' }
|
|
96
141
|
*/
|
|
97
|
-
type?: Partial<Record<NoInfer<
|
|
142
|
+
type?: Partial<Record<NoInfer<TKeys>, string>>;
|
|
98
143
|
}
|
|
99
144
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
145
|
+
* One facet option of a filter field, as returned by the Fetch API.
|
|
146
|
+
* Resolves to the generated shape when the client provides the envelope.
|
|
102
147
|
*/
|
|
103
|
-
export
|
|
104
|
-
option: string;
|
|
105
|
-
value: string;
|
|
106
|
-
count: number;
|
|
107
|
-
selected?: boolean;
|
|
108
|
-
disabled?: boolean;
|
|
109
|
-
}
|
|
148
|
+
export type FilterOption = FilterGroup extends Array<infer TOption> ? TOption : DefaultFilterOption;
|
|
110
149
|
/**
|
|
111
150
|
* Processed filter ready for UI consumption
|
|
112
151
|
* @template TFilters - Filter fields type for this listing (provides autocomplete for key)
|
|
@@ -120,234 +159,59 @@ export interface UiFilter<TFilters = Record<string, unknown>> {
|
|
|
120
159
|
options: FilterOption[];
|
|
121
160
|
/** Display type for this filter. 'default' unless configured via type config. */
|
|
122
161
|
type: string;
|
|
123
|
-
/**
|
|
124
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Aggregation for this field when the response carries one: `total` covers
|
|
164
|
+
* the whole set, `result` the current filtered result. Useful for range UI
|
|
165
|
+
* such as price sliders.
|
|
166
|
+
*/
|
|
167
|
+
data?: AggregationGroup;
|
|
125
168
|
}
|
|
126
169
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
170
|
+
* Statistics for one aggregated field — min/max/avg/sum plus the number of
|
|
171
|
+
* possible values. Resolves to the generated shape when the client provides
|
|
172
|
+
* the envelope.
|
|
129
173
|
*/
|
|
130
|
-
export
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/** Minimum value for this field */
|
|
134
|
-
min?: number;
|
|
135
|
-
/** Average value for this field */
|
|
136
|
-
avg?: number;
|
|
137
|
-
/** Sum of all values for this field */
|
|
138
|
-
sum?: number;
|
|
139
|
-
/** Number of items with this field */
|
|
140
|
-
count?: number;
|
|
141
|
-
/** Total number of possible values for this field */
|
|
142
|
-
total: number;
|
|
143
|
-
}
|
|
174
|
+
export type AggregationStats = AggregationGroup extends {
|
|
175
|
+
total: infer TStats;
|
|
176
|
+
} ? TStats : DefaultAggregationStats;
|
|
144
177
|
/**
|
|
145
178
|
* Processed sort option ready for UI consumption
|
|
146
|
-
* @template TSorts - Sort fields
|
|
179
|
+
* @template TSorts - Sort fields map for this listing (provides autocomplete for key/value)
|
|
147
180
|
*/
|
|
148
181
|
export interface UiSort<TSorts = Record<string, unknown>> {
|
|
149
|
-
/** Sort option key
|
|
150
|
-
key:
|
|
182
|
+
/** Sort option key: 'field:asc', 'field:desc' or 'default' */
|
|
183
|
+
key: SortStringOf<TSorts>;
|
|
151
184
|
/** Human-readable label for the sort option */
|
|
152
185
|
label: string;
|
|
153
186
|
/** Sort value to pass to sortResult (same as key) */
|
|
154
|
-
value:
|
|
187
|
+
value: SortStringOf<TSorts>;
|
|
155
188
|
}
|
|
156
189
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
190
|
+
* Composable arguments for a listing, mirroring the generated client:
|
|
191
|
+
* `parameters` is optional exactly when every field of it is, so a listing
|
|
192
|
+
* that takes none can be called without the empty object.
|
|
159
193
|
*/
|
|
160
|
-
export
|
|
161
|
-
/** Current page number */
|
|
162
|
-
page?: number;
|
|
163
|
-
/** Currently applied sort */
|
|
164
|
-
sort?: {
|
|
165
|
-
field: string;
|
|
166
|
-
order: 'asc' | 'desc';
|
|
167
|
-
};
|
|
168
|
-
/** Current search term (if search is enabled) */
|
|
169
|
-
search?: string;
|
|
170
|
-
/** Currently active filters by field */
|
|
171
|
-
filter?: Record<string, unknown>;
|
|
172
|
-
/** Processed filters ready for UI (includes labels, counts, options) */
|
|
173
|
-
availableFilters?: UiFilter[];
|
|
174
|
-
/** Processed sort options ready for UI (includes labels) */
|
|
175
|
-
availableSorts?: UiSort[];
|
|
176
|
-
/** Number of currently active filters */
|
|
177
|
-
activeFilterCount?: number;
|
|
178
|
-
/** Total number of items matching the current query */
|
|
179
|
-
total?: number;
|
|
180
|
-
}
|
|
194
|
+
export type ListingArgs<TListing extends ListingName, TOptions> = {} extends ListingParamsOf<TListing> ? [params?: MaybeRef<ListingParamsOf<TListing>>, options?: TOptions] : [params: MaybeRef<ListingParamsOf<TListing>>, options?: TOptions];
|
|
181
195
|
/**
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*/
|
|
188
|
-
name: TListing;
|
|
189
|
-
/**
|
|
190
|
-
* Parameters to pass to the listing endpoint
|
|
191
|
-
*/
|
|
192
|
-
params?: MaybeRef<Record<string, unknown>>;
|
|
193
|
-
/**
|
|
194
|
-
* Cache key for the query (defaults to name)
|
|
195
|
-
*/
|
|
196
|
-
cacheKey?: string;
|
|
197
|
-
/**
|
|
198
|
-
* Optional context key for the request
|
|
199
|
-
*/
|
|
200
|
-
contextKey?: MaybeRef<string | undefined>;
|
|
201
|
-
/**
|
|
202
|
-
* Minimum length of search term before triggering search (default: 2)
|
|
203
|
-
*/
|
|
204
|
-
searchTermThreshold?: number;
|
|
205
|
-
/**
|
|
206
|
-
* Filter fields that should use OR logic (all others use AND)
|
|
207
|
-
* Type-safe: only allows valid filter field names for this listing
|
|
208
|
-
*/
|
|
209
|
-
orFilter?: Array<keyof TFilters & string>;
|
|
210
|
-
/**
|
|
211
|
-
* Filter configuration using unified structure
|
|
212
|
-
* Type-safe: select and label must match actual filter fields
|
|
213
|
-
* @example
|
|
214
|
-
* // With select and label
|
|
215
|
-
* filters: {
|
|
216
|
-
* select: ['properties.color', 'properties.size'],
|
|
217
|
-
* mode: 'include',
|
|
218
|
-
* label: { 'properties.color': 'Color', 'properties.size': 'Size' }
|
|
219
|
-
* }
|
|
220
|
-
*
|
|
221
|
-
* // Just label (shows all filters with custom labels)
|
|
222
|
-
* filters: {
|
|
223
|
-
* label: { 'properties.color': 'Color' }
|
|
224
|
-
* }
|
|
225
|
-
*
|
|
226
|
-
* // Just select (shows only these filters)
|
|
227
|
-
* filters: {
|
|
228
|
-
* select: ['properties.color', 'properties.size']
|
|
229
|
-
* }
|
|
230
|
-
*/
|
|
231
|
-
filters?: ListingFieldConfig<TFilters>;
|
|
232
|
-
/**
|
|
233
|
-
* Sort configuration using unified structure
|
|
234
|
-
* Type-safe: label must use valid sort field names with :asc/:desc suffix
|
|
235
|
-
*
|
|
236
|
-
* Special handling for 'default' sort:
|
|
237
|
-
* - The 'default' sort represents Frontic backend's default sorting (no sort applied to query)
|
|
238
|
-
* - It's automatically included if a label is provided in sorts.label
|
|
239
|
-
* - Can be controlled via include/exclude mode like other sorts
|
|
240
|
-
* - Use resetSorting() to return to default sorting
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* // Full configuration with default sort
|
|
244
|
-
* sorts: {
|
|
245
|
-
* label: {
|
|
246
|
-
* 'default': 'Relevance',
|
|
247
|
-
* 'name:asc': 'Name A-Z',
|
|
248
|
-
* 'price.amount:asc': 'Price Low-High'
|
|
249
|
-
* }
|
|
250
|
-
* }
|
|
251
|
-
*
|
|
252
|
-
* // Just label (all sorts allowed)
|
|
253
|
-
* sorts: {
|
|
254
|
-
* label: {
|
|
255
|
-
* 'name:asc': 'Name A-Z',
|
|
256
|
-
* 'name:desc': 'Name Z-A'
|
|
257
|
-
* }
|
|
258
|
-
* }
|
|
259
|
-
*/
|
|
260
|
-
sorts?: ListingFieldConfig<Record<string, unknown>>;
|
|
261
|
-
/**
|
|
262
|
-
* Enable search functionality (default: true)
|
|
263
|
-
*/
|
|
264
|
-
enableSearch?: boolean;
|
|
265
|
-
/**
|
|
266
|
-
* Enable filtering functionality (default: true)
|
|
267
|
-
*/
|
|
268
|
-
enableFilter?: boolean;
|
|
269
|
-
/**
|
|
270
|
-
* Enable sorting functionality (default: true)
|
|
271
|
-
*/
|
|
272
|
-
enableSorting?: boolean;
|
|
273
|
-
/**
|
|
274
|
-
* Stale time in milliseconds (default: 5 minutes)
|
|
275
|
-
*/
|
|
276
|
-
staleTime?: number;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Return type for the generic listing composable
|
|
196
|
+
* The envelope fields a listing response carries, as the module reads them.
|
|
197
|
+
*
|
|
198
|
+
* Generated response types declare all of these (`_filter`, `_aggregation`,
|
|
199
|
+
* `_sort`, `_page`, `_total`); this is the structural view the composable
|
|
200
|
+
* works through, so the fields resolve without a cast per access.
|
|
280
201
|
*/
|
|
281
|
-
export interface
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
/** Current search term */
|
|
289
|
-
searchTerm: Ref<string>;
|
|
290
|
-
/**
|
|
291
|
-
* Loads more items in the current listing (infinite scroll)
|
|
292
|
-
*/
|
|
293
|
-
loadMore: () => Promise<TResponse | undefined>;
|
|
294
|
-
/**
|
|
295
|
-
* Fetches the listing with current query parameters
|
|
296
|
-
*/
|
|
297
|
-
refresh: () => Promise<void>;
|
|
298
|
-
/**
|
|
299
|
-
* Paginates the results in the specified direction
|
|
300
|
-
* @param direction - Direction to paginate ('next' or 'prev')
|
|
301
|
-
* @returns Promise<boolean> - Returns true if pagination was successful
|
|
302
|
-
*/
|
|
303
|
-
paginate: (direction: 'next' | 'prev') => Promise<boolean>;
|
|
304
|
-
/**
|
|
305
|
-
* Sorts the results by the specified field
|
|
306
|
-
* Type-safe: only accepts valid sort strings for this listing
|
|
307
|
-
* @param sortBy - Sort field and direction (e.g., 'name:desc' or 'name:asc' or 'default')
|
|
308
|
-
*/
|
|
309
|
-
sortItems: (sortBy: string) => Promise<void>;
|
|
310
|
-
/**
|
|
311
|
-
* Resets sorting to default (Frontic backend default)
|
|
312
|
-
*/
|
|
313
|
-
resetSorting: () => Promise<void>;
|
|
314
|
-
/**
|
|
315
|
-
* Adds a filter option to the specified filter field
|
|
316
|
-
* Type-safe: field and value types are validated
|
|
317
|
-
* @param filterField - The field to filter on (autocomplete available)
|
|
318
|
-
* @param filterOption - The option value to add
|
|
319
|
-
*/
|
|
320
|
-
addFilter: <K extends keyof TFilters & string>(filterField: K, filterOption: TFilters[K]) => Promise<void>;
|
|
321
|
-
/**
|
|
322
|
-
* Removes a filter option from the specified filter field
|
|
323
|
-
* Type-safe: field and value types are validated
|
|
324
|
-
* @param filterField - The field to remove the filter from (autocomplete available)
|
|
325
|
-
* @param filterOption - The option value to remove (optional - omit to remove entire filter)
|
|
326
|
-
*/
|
|
327
|
-
removeFilter: <K extends keyof TFilters & string>(filterField: K, filterOption?: TFilters[K]) => Promise<void>;
|
|
328
|
-
/**
|
|
329
|
-
* Applies filter options to the specified filter field
|
|
330
|
-
* Type-safe: field and value types are validated
|
|
331
|
-
* @param filterField - The field to filter on (autocomplete available)
|
|
332
|
-
* @param filterOptions - Array of filter values to apply
|
|
333
|
-
*/
|
|
334
|
-
filterItems: <K extends keyof TFilters & string>(filterField: K, filterOptions: Array<TFilters[K]>) => Promise<void>;
|
|
335
|
-
/**
|
|
336
|
-
* Resets filters either for a specific field or all filters if no field specified
|
|
337
|
-
* Type-safe: field names are validated
|
|
338
|
-
* @param filterField - Optional field to reset. If omitted, all filters are reset
|
|
339
|
-
*/
|
|
340
|
-
resetFilter: (filterField?: keyof TFilters & string) => Promise<void>;
|
|
341
|
-
/**
|
|
342
|
-
* Clears the search term
|
|
343
|
-
*/
|
|
344
|
-
resetSearch: () => Promise<void>;
|
|
202
|
+
export interface ListingEnvelope {
|
|
203
|
+
items?: unknown[];
|
|
204
|
+
filter?: FilterData;
|
|
205
|
+
aggregation?: AggregationData;
|
|
206
|
+
sort?: unknown;
|
|
207
|
+
page?: Pagination;
|
|
208
|
+
total?: number;
|
|
345
209
|
}
|
|
346
210
|
/**
|
|
347
211
|
* Configuration for listing queries
|
|
348
|
-
* @template TListing - The listing name, constrained to
|
|
212
|
+
* @template TListing - The listing name, constrained to the registry's listing names
|
|
349
213
|
*/
|
|
350
|
-
export interface FetchListingConfig<TListing extends
|
|
214
|
+
export interface FetchListingConfig<TListing extends ListingName = ListingName> extends FronticRequestOptions, FronticQueryOptions {
|
|
351
215
|
/**
|
|
352
216
|
* The listing name to fetch (e.g., 'ProductSearch', 'CategoryProducts')
|
|
353
217
|
*/
|
|
@@ -356,19 +220,17 @@ export interface FetchListingConfig<TListing extends keyof Listings = keyof List
|
|
|
356
220
|
* Parameters to pass to the listing endpoint
|
|
357
221
|
* Type-safe when TListing is a specific listing name
|
|
358
222
|
*/
|
|
359
|
-
params: MaybeRef<TListing
|
|
223
|
+
params: MaybeRef<ListingParamsOf<TListing>>;
|
|
360
224
|
/**
|
|
361
225
|
* Query configuration (filters, sort, search, pagination).
|
|
362
|
-
*
|
|
363
|
-
*
|
|
226
|
+
* Typed against the listing's filter/sort schema — same shape as
|
|
227
|
+
* `client.listing(name, params, { query })`. The factory normalises
|
|
228
|
+
* `undefined` to `{}` internally, so a `MaybeRef` wrapping `undefined`
|
|
229
|
+
* is accepted — useful for reactive query options.
|
|
364
230
|
*/
|
|
365
|
-
query?: MaybeRef<
|
|
231
|
+
query?: MaybeRef<ListingQuery<TListing> | undefined>;
|
|
366
232
|
/**
|
|
367
233
|
* Optional page number for pagination
|
|
368
234
|
*/
|
|
369
235
|
page?: MaybeRef<number | undefined>;
|
|
370
|
-
/**
|
|
371
|
-
* Stale time in milliseconds (default: 5 minutes)
|
|
372
|
-
*/
|
|
373
|
-
staleTime?: number;
|
|
374
236
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frontic Module Options
|
|
3
|
+
*
|
|
4
|
+
* Lives in the runtime tree (mkdist-built) so both package entries resolve it:
|
|
5
|
+
* `@frontic/nuxt` re-exports it from the module entry, `@frontic/nuxt/types`
|
|
6
|
+
* from the runtime types barrel.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Available Frontic composables that can be enabled/disabled
|
|
10
|
+
*
|
|
11
|
+
* - 'block': useFronticBlock - Fetch single blocks (products, categories)
|
|
12
|
+
* - 'listing': useFronticListing - Fetch listings with caching
|
|
13
|
+
* - 'search': useFronticSearch - Full-featured search with filters/sorting
|
|
14
|
+
* - 'tree': useFronticTree - Fetch hierarchical menu trees
|
|
15
|
+
* - 'page': useFronticPage - Dynamic page routing
|
|
16
|
+
* - 'context': useFronticContext - Locale/region management
|
|
17
|
+
* - 'client': useFronticClient - Low-level API client
|
|
18
|
+
*/
|
|
19
|
+
export type FronticComposable = 'block' | 'listing' | 'search' | 'tree' | 'page' | 'context' | 'client';
|
|
20
|
+
/**
|
|
21
|
+
* Frontic composables configuration
|
|
22
|
+
* - true: Enable all composables (default)
|
|
23
|
+
* - false or []: Disable all composables
|
|
24
|
+
* - string[]: Enable only specified composables
|
|
25
|
+
*/
|
|
26
|
+
export type FronticComposablesConfig = boolean | FronticComposable[];
|
|
27
|
+
/**
|
|
28
|
+
* Frontic module configuration options
|
|
29
|
+
*/
|
|
30
|
+
export interface FronticOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Prefix for all auto-imported Frontic UI components.
|
|
33
|
+
* Set to 'Ui' to get `<UiButton>`, or leave empty for `<Button>`.
|
|
34
|
+
* @default ''
|
|
35
|
+
*/
|
|
36
|
+
componentsPrefix: string;
|
|
37
|
+
/**
|
|
38
|
+
* Directory that the components live in.
|
|
39
|
+
* @default "@/components/ui"
|
|
40
|
+
*/
|
|
41
|
+
componentDir: string;
|
|
42
|
+
/**
|
|
43
|
+
* Configure which Frontic composables to auto-import
|
|
44
|
+
*
|
|
45
|
+
* When a composable is disabled, it will not be auto-imported during the Nuxt build.
|
|
46
|
+
* This means you won't get type errors or warnings—the composable simply won't exist.
|
|
47
|
+
* Use this to reduce bundle size by excluding composables you don't need.
|
|
48
|
+
*
|
|
49
|
+
* Available composables:
|
|
50
|
+
* - 'block': useFronticBlock - Fetch single blocks
|
|
51
|
+
* - 'listing': useFronticListing - Fetch listings
|
|
52
|
+
* - 'search': useFronticSearch - Search with filters/sorting
|
|
53
|
+
* - 'tree': useFronticTree - Fetch hierarchical menu trees
|
|
54
|
+
* - 'page': useFronticPage - Dynamic page routing
|
|
55
|
+
* - 'context': useFronticContext - Locale/region management
|
|
56
|
+
* - 'client': useFronticClient - Low-level API client
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* composables: true // Enable all (default)
|
|
60
|
+
* composables: false // Disable all
|
|
61
|
+
* composables: ['listing', 'page', 'client'] // Enable specific ones
|
|
62
|
+
*
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
composables?: FronticComposablesConfig;
|
|
66
|
+
/**
|
|
67
|
+
* Enable/configure the API proxy for CORS prevention
|
|
68
|
+
* - true: Enable proxy at default path '/api/frontic'
|
|
69
|
+
* - false: Disable proxy
|
|
70
|
+
* - string: Enable proxy at custom path
|
|
71
|
+
*
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
proxy?: boolean | string;
|
|
75
|
+
/**
|
|
76
|
+
* Context domain for scope/region/locale resolution and page slug construction.
|
|
77
|
+
*
|
|
78
|
+
* Controls which Frontic domain is used across all composables:
|
|
79
|
+
* - useFronticPage: prepended to the pathname to construct the page slug
|
|
80
|
+
* - useFronticBlock/Listing/Context: injected as contextDomain request option
|
|
81
|
+
*
|
|
82
|
+
* - string: Static domain (e.g. 'shop.com')
|
|
83
|
+
* - true: Read `contextDomain` property from current @nuxtjs/i18n locale object
|
|
84
|
+
*
|
|
85
|
+
* When not set, useFronticPage derives the domain from the request URL host.
|
|
86
|
+
*
|
|
87
|
+
* @example 'demo-shop.com'
|
|
88
|
+
* @example true
|
|
89
|
+
*/
|
|
90
|
+
contextDomain?: string | boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Cookie name for persisting the context token
|
|
93
|
+
* @default 'fs-context'
|
|
94
|
+
*/
|
|
95
|
+
contextCookieName?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Cookie max age in seconds for context token
|
|
98
|
+
* @default 31536000 (1 year)
|
|
99
|
+
*/
|
|
100
|
+
contextCookieMaxAge?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Disable automatic context fetching and cookie management in useFronticContext
|
|
103
|
+
*
|
|
104
|
+
* When true:
|
|
105
|
+
* - The context endpoint will NOT be called automatically on mount
|
|
106
|
+
* - No context cookie will be set automatically
|
|
107
|
+
* - You must manually call `refresh()` to fetch contexts
|
|
108
|
+
* - You are responsible for storing and managing the context token
|
|
109
|
+
*
|
|
110
|
+
* Use this when you want full control over context management,
|
|
111
|
+
* or when integrating with an existing locale/region system.
|
|
112
|
+
*
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
115
|
+
disableContext?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Automatically redirect on 301 responses
|
|
118
|
+
* Can be overridden per-request in useFronticPage
|
|
119
|
+
* @default true
|
|
120
|
+
*/
|
|
121
|
+
redirectOn301?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Throw a 404 error when page is not found
|
|
124
|
+
* Can be overridden per-request in useFronticPage
|
|
125
|
+
* @default true
|
|
126
|
+
*/
|
|
127
|
+
throwOn404?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* API secret for authenticating Fetch API requests
|
|
130
|
+
* Required for protected environments (e.g., development/staging)
|
|
131
|
+
* Stored in private runtime config (server-only, never exposed to browser)
|
|
132
|
+
*
|
|
133
|
+
* Injected server-side on both paths: by the proxy for browser requests,
|
|
134
|
+
* by a Nitro plugin for SSR requests
|
|
135
|
+
*
|
|
136
|
+
* @example process.env.FRONTIC_FETCH_SECRET
|
|
137
|
+
*/
|
|
138
|
+
fetchApiSecret?: string;
|
|
139
|
+
}
|
|
File without changes
|