@frontic/nuxt 1.3.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "frontic",
3
3
  "configKey": "frontic",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -296,17 +296,17 @@ export {}
296
296
  const errorsModule = resolveModule("./runtime/types/errors");
297
297
  addTypeTemplate({
298
298
  filename: "types/frontic-fetch-error.d.ts",
299
- getContents: () => `import type { FronticFetchError } from '${errorsModule}'
299
+ getContents: () => `import type { FronticFetchErrorPayload } from '${errorsModule}'
300
300
 
301
301
  declare module '#app' {
302
302
  interface RuntimeNuxtHooks {
303
- 'frontic:fetch:error': (payload: FronticFetchError) => void | Promise<void>
303
+ 'frontic:fetch:error': (payload: FronticFetchErrorPayload) => void | Promise<void>
304
304
  }
305
305
  }
306
306
 
307
307
  declare module 'nitropack/types' {
308
308
  interface NitroRuntimeHooks {
309
- 'frontic:fetch:error': (payload: FronticFetchError) => void | Promise<void>
309
+ 'frontic:fetch:error': (payload: FronticFetchErrorPayload) => void | Promise<void>
310
310
  }
311
311
  }
312
312
 
@@ -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 { toFronticFetchError } from "../utils/describe-error.js";
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 = toFronticFetchError(
40
+ const payload = toFronticFetchErrorPayload(
41
41
  operation,
42
42
  identity,
43
43
  {
@@ -214,14 +214,26 @@ export function useFronticSearch(name, ...args) {
214
214
  error = infiniteResult.error;
215
215
  refresh = infiniteResult.refresh;
216
216
  refetch = infiniteResult.refetch;
217
+ const edgePageParam = (edge) => {
218
+ const pageParams = infiniteResult.data.value?.pageParams;
219
+ return edge === "first" ? pageParams?.at(0) : pageParams?.at(-1);
220
+ };
221
+ const emitLoadedPage = (edge, pageParamBefore) => {
222
+ if (edgePageParam(edge) === pageParamBefore) return;
223
+ const pages = infiniteResult.data.value?.pages;
224
+ const loaded = edge === "first" ? pages?.at(0) : pages?.at(-1);
225
+ if (loaded) emitListingResolved(loaded, "loadMore");
226
+ };
217
227
  loadNextFn = async () => {
228
+ const pageParamBefore = edgePageParam("last");
218
229
  await infiniteResult.loadNextPage();
219
- if (flattenedData.value) emitListingResolved(flattenedData.value, "loadMore");
230
+ emitLoadedPage("last", pageParamBefore);
220
231
  return flattenedData.value;
221
232
  };
222
233
  loadPrevFn = async () => {
234
+ const pageParamBefore = edgePageParam("first");
223
235
  await infiniteResult.loadPreviousPage();
224
- if (flattenedData.value) emitListingResolved(flattenedData.value, "loadMore");
236
+ emitLoadedPage("first", pageParamBefore);
225
237
  return flattenedData.value;
226
238
  };
227
239
  loadPageFn = async (page) => {
@@ -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 { toFronticFetchError } from "../utils/describe-error.js";
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 = toFronticFetchError(operation, identity, { contextDomain, contextKey: reported, requestUrl }, error);
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 FronticFetchError {
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 { FronticFetchError, FronticFetchOperation } from './errors.js';
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';
@@ -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 FronticFetchError, type FronticFetchOperation } from '../types/errors.js';
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 toFronticFetchError(operation: FronticFetchOperation, identity: {
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): FronticFetchError;
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 toFronticFetchError(operation, identity, request, error) {
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.0",
3
+ "version": "1.3.1",
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",