@frontic/nuxt 1.3.0 → 1.3.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.
- package/dist/module.json +1 -1
- package/dist/module.mjs +26 -3
- package/dist/runtime/composables/useFronticClient.js +2 -2
- package/dist/runtime/composables/useFronticSearch.js +21 -4
- package/dist/runtime/server/client.js +2 -2
- package/dist/runtime/types/errors.d.ts +1 -1
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/types/listing.d.ts +3 -3
- package/dist/runtime/utils/describe-error.d.ts +3 -3
- package/dist/runtime/utils/describe-error.js +1 -1
- package/package.json +3 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -168,6 +168,13 @@ frontic: { composables: false }
|
|
|
168
168
|
nitroConfig.alias ||= {};
|
|
169
169
|
nitroConfig.alias["@frontic/stack"] = clientDirPath;
|
|
170
170
|
});
|
|
171
|
+
nuxt.hook("nitro:prepare:types", ({ references }) => {
|
|
172
|
+
if (!hasFronticClient) return;
|
|
173
|
+
for (const file of ["generated-types.d.ts", "fetch-api.d.ts"]) {
|
|
174
|
+
const path = join(clientDirPath, file);
|
|
175
|
+
if (existsSync(path)) references.push({ path });
|
|
176
|
+
}
|
|
177
|
+
});
|
|
171
178
|
nuxt.hook("prepare:types", ({ tsConfig }) => {
|
|
172
179
|
tsConfig.compilerOptions ||= {};
|
|
173
180
|
tsConfig.compilerOptions.paths ||= {};
|
|
@@ -296,23 +303,39 @@ export {}
|
|
|
296
303
|
const errorsModule = resolveModule("./runtime/types/errors");
|
|
297
304
|
addTypeTemplate({
|
|
298
305
|
filename: "types/frontic-fetch-error.d.ts",
|
|
299
|
-
getContents: () => `import type {
|
|
306
|
+
getContents: () => `import type { FronticFetchErrorPayload } from '${errorsModule}'
|
|
300
307
|
|
|
301
308
|
declare module '#app' {
|
|
302
309
|
interface RuntimeNuxtHooks {
|
|
303
|
-
'frontic:fetch:error': (payload:
|
|
310
|
+
'frontic:fetch:error': (payload: FronticFetchErrorPayload) => void | Promise<void>
|
|
304
311
|
}
|
|
305
312
|
}
|
|
306
313
|
|
|
307
314
|
declare module 'nitropack/types' {
|
|
308
315
|
interface NitroRuntimeHooks {
|
|
309
|
-
'frontic:fetch:error': (payload:
|
|
316
|
+
'frontic:fetch:error': (payload: FronticFetchErrorPayload) => void | Promise<void>
|
|
310
317
|
}
|
|
311
318
|
}
|
|
312
319
|
|
|
313
320
|
export {}
|
|
314
321
|
`
|
|
315
322
|
});
|
|
323
|
+
addTypeTemplate(
|
|
324
|
+
{
|
|
325
|
+
filename: "types/frontic-fetch-error.nitro.d.ts",
|
|
326
|
+
getContents: () => `import type { FronticFetchErrorPayload } from '${errorsModule}'
|
|
327
|
+
|
|
328
|
+
declare module 'nitropack/types' {
|
|
329
|
+
interface NitroRuntimeHooks {
|
|
330
|
+
'frontic:fetch:error': (payload: FronticFetchErrorPayload) => void | Promise<void>
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {}
|
|
335
|
+
`
|
|
336
|
+
},
|
|
337
|
+
{ nitro: true }
|
|
338
|
+
);
|
|
316
339
|
}
|
|
317
340
|
nuxt.options.runtimeConfig.public.frontic = {
|
|
318
341
|
hasFronticClient,
|
|
@@ -3,7 +3,7 @@ import { createClient } from "@frontic/stack/generated-client";
|
|
|
3
3
|
import { resolveContextDomain } from "../utils/resolve-context-domain.js";
|
|
4
4
|
import { resolveContextKey } from "../utils/resolve-context-key.js";
|
|
5
5
|
import { withDefaults } from "../utils/request-defaults.js";
|
|
6
|
-
import {
|
|
6
|
+
import { toFronticFetchErrorPayload } from "../utils/describe-error.js";
|
|
7
7
|
export function useFronticClient(options) {
|
|
8
8
|
const config = useRuntimeConfig();
|
|
9
9
|
const fronticConfig = config.public.frontic;
|
|
@@ -37,7 +37,7 @@ export function useFronticClient(options) {
|
|
|
37
37
|
const baseClient = createClient({ proxyUrl });
|
|
38
38
|
function reporting(operation, identity, reqOptions, run) {
|
|
39
39
|
return run().catch((error) => {
|
|
40
|
-
const payload =
|
|
40
|
+
const payload = toFronticFetchErrorPayload(
|
|
41
41
|
operation,
|
|
42
42
|
identity,
|
|
43
43
|
{
|
|
@@ -143,6 +143,7 @@ export function useFronticSearch(name, ...args) {
|
|
|
143
143
|
initialDataUpdatedAt: options?.initialDataUpdatedAt,
|
|
144
144
|
_client
|
|
145
145
|
};
|
|
146
|
+
const isEnabled = () => toValue(options?.enabled) !== false;
|
|
146
147
|
let data;
|
|
147
148
|
let status;
|
|
148
149
|
let asyncStatus;
|
|
@@ -214,17 +215,32 @@ export function useFronticSearch(name, ...args) {
|
|
|
214
215
|
error = infiniteResult.error;
|
|
215
216
|
refresh = infiniteResult.refresh;
|
|
216
217
|
refetch = infiniteResult.refetch;
|
|
218
|
+
const edgePageParam = (edge) => {
|
|
219
|
+
const pageParams = infiniteResult.data.value?.pageParams;
|
|
220
|
+
return edge === "first" ? pageParams?.at(0) : pageParams?.at(-1);
|
|
221
|
+
};
|
|
222
|
+
const emitLoadedPage = (edge, pageParamBefore) => {
|
|
223
|
+
if (edgePageParam(edge) === pageParamBefore) return;
|
|
224
|
+
const pages = infiniteResult.data.value?.pages;
|
|
225
|
+
const loaded = edge === "first" ? pages?.at(0) : pages?.at(-1);
|
|
226
|
+
if (loaded) emitListingResolved(loaded, "loadMore");
|
|
227
|
+
};
|
|
217
228
|
loadNextFn = async () => {
|
|
229
|
+
if (!isEnabled()) return flattenedData.value;
|
|
230
|
+
const pageParamBefore = edgePageParam("last");
|
|
218
231
|
await infiniteResult.loadNextPage();
|
|
219
|
-
|
|
232
|
+
emitLoadedPage("last", pageParamBefore);
|
|
220
233
|
return flattenedData.value;
|
|
221
234
|
};
|
|
222
235
|
loadPrevFn = async () => {
|
|
236
|
+
if (!isEnabled()) return flattenedData.value;
|
|
237
|
+
const pageParamBefore = edgePageParam("first");
|
|
223
238
|
await infiniteResult.loadPreviousPage();
|
|
224
|
-
|
|
239
|
+
emitLoadedPage("first", pageParamBefore);
|
|
225
240
|
return flattenedData.value;
|
|
226
241
|
};
|
|
227
242
|
loadPageFn = async (page) => {
|
|
243
|
+
if (!isEnabled()) return flattenedData.value;
|
|
228
244
|
const pagedQueryFactory = fetchListingQuery({
|
|
229
245
|
...queryConfig,
|
|
230
246
|
page: ref(page)
|
|
@@ -370,8 +386,9 @@ export function useFronticSearch(name, ...args) {
|
|
|
370
386
|
function resetPage() {
|
|
371
387
|
_page.value = void 0;
|
|
372
388
|
}
|
|
373
|
-
function withIntent(trigger, changedFilter) {
|
|
374
|
-
|
|
389
|
+
async function withIntent(trigger, changedFilter) {
|
|
390
|
+
if (!isEnabled()) return;
|
|
391
|
+
await runRefresh({ trigger, changedFilter });
|
|
375
392
|
}
|
|
376
393
|
const triggerSearchFromInput = useDebounceFn(() => {
|
|
377
394
|
const committed = searchTerm.value.trim().length > searchTermThreshold ? searchTerm.value : void 0;
|
|
@@ -2,7 +2,7 @@ import { getCookie, getRequestURL } from "h3";
|
|
|
2
2
|
import { useRuntimeConfig, useNitroApp } from "nitropack/runtime";
|
|
3
3
|
import { createClient } from "@frontic/stack/generated-client";
|
|
4
4
|
import { withDefaults } from "../utils/request-defaults.js";
|
|
5
|
-
import {
|
|
5
|
+
import { toFronticFetchErrorPayload } from "../utils/describe-error.js";
|
|
6
6
|
function resolveOverride(override, fallback) {
|
|
7
7
|
return override === false ? void 0 : override ?? fallback();
|
|
8
8
|
}
|
|
@@ -26,7 +26,7 @@ export function createFronticServerClient(event, options) {
|
|
|
26
26
|
function reporting(operation, identity, reqOptions, run) {
|
|
27
27
|
return run().catch((error) => {
|
|
28
28
|
const reported = reqOptions?.contextKey === false ? void 0 : reqOptions?.contextKey ?? contextKey;
|
|
29
|
-
const payload =
|
|
29
|
+
const payload = toFronticFetchErrorPayload(operation, identity, { contextDomain, contextKey: reported, requestUrl }, error);
|
|
30
30
|
const hooks = useNitroApp().hooks;
|
|
31
31
|
void Promise.resolve(hooks.callHook("frontic:fetch:error", payload)).catch(() => {
|
|
32
32
|
});
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/** Which client call failed. `contextList` and `contextUpdate` both report as `context`. */
|
|
12
12
|
export type FronticFetchOperation = 'block' | 'listing' | 'tree' | 'page' | 'context' | 'proxy' | 'sitemap';
|
|
13
|
-
export interface
|
|
13
|
+
export interface FronticFetchErrorPayload {
|
|
14
14
|
operation: FronticFetchOperation;
|
|
15
15
|
/** Block, listing or tree name. Absent for `page`, `context`, `proxy` and `sitemap`. */
|
|
16
16
|
name?: string;
|
|
@@ -10,7 +10,7 @@ export type { FronticClient } from './client.js';
|
|
|
10
10
|
export type { FronticRequestOptions, FronticQueryOptions, InclusionMode, FilterField, SortField, SortString, SortStringOf, ListingQuery, ListingEnvelope, ListingFieldConfig, FilterOption, UiFilter, UiSort, AggregationStats, Pagination, FilterData, AggregationData, FilterGroup, AggregationGroup, } from './listing.js';
|
|
11
11
|
export type { RangeFilterValue } from '../utils/filter-helpers.js';
|
|
12
12
|
export type { FronticAnalyticsItem, FronticListingTrigger, FronticListingResolved, FronticSearchCommitted, FronticPageResolved } from '../composables/analytics.js';
|
|
13
|
-
export type {
|
|
13
|
+
export type { FronticFetchErrorPayload, FronticFetchOperation } from './errors.js';
|
|
14
14
|
export type { SearchState, UseFronticSearchOptions, UseSearchReturn, SearchUrlSlice, SearchUrlQuerySyncOptions } from './search.js';
|
|
15
15
|
export type { UseFronticClientOptions } from '../composables/useFronticClient.js';
|
|
16
16
|
export type { UseFronticBlockOptions } from '../composables/useFronticBlock.js';
|
|
@@ -36,9 +36,9 @@ export interface FronticQueryOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
gcTime?: number;
|
|
38
38
|
/**
|
|
39
|
-
* Whether the query fetches. While `false`, no request is made
|
|
40
|
-
*
|
|
41
|
-
* not known yet.
|
|
39
|
+
* Whether the query fetches. While `false`, no request is made except by an
|
|
40
|
+
* explicit `refresh()` or `refetch()` call; flipping it back to `true`
|
|
41
|
+
* refreshes. Useful when an input (e.g. a reactive key) is not known yet.
|
|
42
42
|
* @default true
|
|
43
43
|
*/
|
|
44
44
|
enabled?: MaybeRefOrGetter<boolean>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* `cause` is non-enumerable, so it is absent from `console.error(err)` and from
|
|
7
7
|
* anything that serialises the error, and has to be walked explicitly.
|
|
8
8
|
*/
|
|
9
|
-
import { type
|
|
9
|
+
import { type FronticFetchErrorPayload, type FronticFetchOperation } from '../types/errors.js';
|
|
10
10
|
/**
|
|
11
11
|
* Flatten an error and its `cause` chain, outermost first.
|
|
12
12
|
*
|
|
@@ -44,7 +44,7 @@ export declare function toFetchErrorDetail(error: unknown): FronticFetchErrorDet
|
|
|
44
44
|
* runtime failed — the app composable announces it on the Nuxt app, the server
|
|
45
45
|
* client on the Nitro app, and neither should invent its own fields.
|
|
46
46
|
*/
|
|
47
|
-
export declare function
|
|
47
|
+
export declare function toFronticFetchErrorPayload(operation: FronticFetchOperation, identity: {
|
|
48
48
|
name?: string;
|
|
49
49
|
slug?: string;
|
|
50
50
|
domain?: string;
|
|
@@ -54,4 +54,4 @@ export declare function toFronticFetchError(operation: FronticFetchOperation, id
|
|
|
54
54
|
requestUrl?: string;
|
|
55
55
|
proxyUrl?: string;
|
|
56
56
|
targetUrl?: string;
|
|
57
|
-
}, error: unknown):
|
|
57
|
+
}, error: unknown): FronticFetchErrorPayload;
|
|
@@ -37,7 +37,7 @@ export function toFetchErrorDetail(error) {
|
|
|
37
37
|
...statusOf(error) !== void 0 && { status: statusOf(error) }
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
export function
|
|
40
|
+
export function toFronticFetchErrorPayload(operation, identity, request, error) {
|
|
41
41
|
return {
|
|
42
42
|
operation,
|
|
43
43
|
...identity.name !== void 0 && { name: identity.name },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontic/nuxt",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Nuxt module for Frontic - data fetching composables with smart caching, page routing, and context management",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Frontic",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"test": "vitest run",
|
|
57
57
|
"test:watch": "vitest watch",
|
|
58
58
|
"test:coverage": "vitest run --coverage",
|
|
59
|
-
"clean": "rm -rf dist .nuxt"
|
|
59
|
+
"clean": "rm -rf dist .nuxt",
|
|
60
|
+
"emit:docs-manifest": "node scripts/emit-docs-manifest.js"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"@nuxt/kit": "^4.5.2",
|