@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.
Files changed (52) hide show
  1. package/README.md +30 -2
  2. package/dist/module.d.mts +2 -132
  3. package/dist/module.json +2 -2
  4. package/dist/module.mjs +63 -7
  5. package/dist/runtime/composables/analytics.d.ts +82 -0
  6. package/dist/runtime/composables/analytics.js +38 -0
  7. package/dist/runtime/composables/blocks.d.ts +24 -22
  8. package/dist/runtime/composables/blocks.js +16 -16
  9. package/dist/runtime/composables/index.d.ts +1 -1
  10. package/dist/runtime/composables/listings.d.ts +22 -13
  11. package/dist/runtime/composables/listings.js +24 -25
  12. package/dist/runtime/composables/pages.d.ts +21 -18
  13. package/dist/runtime/composables/pages.js +15 -16
  14. package/dist/runtime/composables/trees.d.ts +24 -22
  15. package/dist/runtime/composables/trees.js +15 -25
  16. package/dist/runtime/composables/useFronticBlock.d.ts +22 -13
  17. package/dist/runtime/composables/useFronticBlock.js +19 -2
  18. package/dist/runtime/composables/useFronticClient.d.ts +6 -3
  19. package/dist/runtime/composables/useFronticContext.d.ts +12 -0
  20. package/dist/runtime/composables/useFronticContext.js +71 -9
  21. package/dist/runtime/composables/useFronticListing.d.ts +23 -19
  22. package/dist/runtime/composables/useFronticListing.js +22 -3
  23. package/dist/runtime/composables/useFronticPage.d.ts +35 -16
  24. package/dist/runtime/composables/useFronticPage.js +36 -7
  25. package/dist/runtime/composables/useFronticSearch.d.ts +4 -96
  26. package/dist/runtime/composables/useFronticSearch.js +179 -51
  27. package/dist/runtime/composables/useFronticTree.d.ts +23 -14
  28. package/dist/runtime/composables/useFronticTree.js +19 -2
  29. package/dist/runtime/server/plugins/fetch-secret.d.ts +2 -0
  30. package/dist/runtime/server/plugins/fetch-secret.js +20 -0
  31. package/dist/runtime/types/client.d.ts +34 -0
  32. package/dist/runtime/types/client.js +0 -0
  33. package/dist/runtime/types/index.d.ts +8 -3
  34. package/dist/runtime/types/listing.d.ts +113 -251
  35. package/dist/runtime/types/options.d.ts +139 -0
  36. package/dist/runtime/types/options.js +0 -0
  37. package/dist/runtime/types/query.d.ts +88 -0
  38. package/dist/runtime/types/query.js +0 -0
  39. package/dist/runtime/types/registry.d.ts +272 -0
  40. package/dist/runtime/types/registry.js +0 -0
  41. package/dist/runtime/types/search.d.ts +56 -36
  42. package/dist/runtime/utils/errors.d.ts +22 -0
  43. package/dist/runtime/utils/errors.js +3 -0
  44. package/dist/runtime/utils/index.d.ts +2 -0
  45. package/dist/runtime/utils/index.js +2 -0
  46. package/dist/runtime/utils/query-keys.d.ts +27 -0
  47. package/dist/runtime/utils/query-keys.js +18 -0
  48. package/dist/runtime/utils/state-helpers.d.ts +3 -6
  49. package/dist/runtime/utils/state-helpers.js +7 -8
  50. package/dist/types.d.mts +2 -2
  51. package/package.json +15 -15
  52. package/dist/runtime/frontic-stack.d.ts +0 -168
@@ -4,8 +4,8 @@
4
4
  * Provides query key management and query factory functions for Frontic listings.
5
5
  * Compatible with both @pinia/colada and useAsyncData patterns.
6
6
  */
7
- import type { FrontstackClient } from '@frontic/stack/generated-client';
8
- import type { Listings, Responses } from '@frontic/stack/generated-types';
7
+ import type { FronticClient } from '../types/client.js';
8
+ import type { ListingName, ResponseOf } from '../types/registry.js';
9
9
  import type { FetchListingConfig } from '../types/listing.js';
10
10
  /**
11
11
  * Query key factory for listing queries
@@ -15,14 +15,17 @@ import type { FetchListingConfig } from '../types/listing.js';
15
15
  * ```ts
16
16
  * LISTING_QUERY_KEYS.root // ['listings']
17
17
  * LISTING_QUERY_KEYS.listing('ProductSearch') // ['listings', 'ProductSearch']
18
- * LISTING_QUERY_KEYS.detail('ProductSearch', { categoryKey: 'shoes' }, { filter: [] })
19
- * // ['listings', 'ProductSearch', { categoryKey: 'shoes' }, { filter: [] }]
18
+ * LISTING_QUERY_KEYS.detail('ProductSearch', { categoryKey: 'shoes' }, { filter: [] }, 'context-token')
19
+ * // ['listings', 'ProductSearch', { categoryKey: 'shoes' }, { filter: [] }, { context: 'context-token', domain: null }]
20
20
  * ```
21
21
  */
22
22
  export declare const LISTING_QUERY_KEYS: {
23
- root: string[];
24
- listing: <TListing extends string>(listingName: TListing) => string[];
25
- detail: <TListing extends string>(listingName: TListing, parameters: Record<string, unknown>, query: Record<string, unknown>) => string[];
23
+ root: readonly ["listings"];
24
+ listing: <TListing extends string>(listingName: TListing) => readonly ["listings", TListing];
25
+ detail: <TListing extends string>(listingName: TListing, parameters: Record<string, unknown>, query: Record<string, unknown>, contextKey?: string, contextDomain?: string) => readonly ["listings", TListing, Record<string, unknown>, Record<string, unknown>, {
26
+ readonly context: string | null;
27
+ readonly domain: string | null;
28
+ }];
26
29
  };
27
30
  /**
28
31
  * Generic query factory for fetching listings
@@ -35,23 +38,29 @@ export declare const LISTING_QUERY_KEYS: {
35
38
  * name: 'ProductSearch',
36
39
  * params: {},
37
40
  * query: { filter: [], sort: { field: 'name', order: 'asc' } },
38
- * contextKey: token.value
41
+ * contextKey: token
39
42
  * })
40
43
  *
41
44
  * const { data, status } = useQuery(productQuery)
42
45
  *
43
46
  * // With useAsyncData
44
47
  * const { data, status } = useAsyncData(
45
- * productQuery.key().join('-'),
48
+ * createCacheKey(productQuery.key()),
46
49
  * productQuery.query
47
50
  * )
48
51
  * ```
49
52
  */
50
- export declare function fetchListingQuery<TListing extends keyof Listings>(config: FetchListingConfig<TListing> & {
51
- _client?: FrontstackClient;
53
+ export declare function fetchListingQuery<TListing extends ListingName>(config: FetchListingConfig<TListing> & {
54
+ _client?: FronticClient;
52
55
  }): {
53
- key: () => string[];
54
- query: () => Promise<Responses[TListing]>;
56
+ placeholderData?: ((previousData: ResponseOf<TListing> | undefined) => ResponseOf<TListing> | undefined) | undefined;
57
+ enabled?: import("vue").MaybeRefOrGetter<boolean> | undefined;
58
+ gcTime?: number | undefined;
59
+ key: () => readonly ["listings", string, Record<string, unknown>, Record<string, unknown>, {
60
+ readonly context: string | null;
61
+ readonly domain: string | null;
62
+ }];
63
+ query: () => Promise<ResponseOf<TListing>>;
55
64
  staleTime: number;
56
65
  };
57
66
  /**
@@ -1,31 +1,27 @@
1
- function unwrapRef(ref) {
2
- return typeof ref === "object" && ref !== null && "value" in ref ? ref.value : ref;
3
- }
1
+ import { toValue } from "vue";
2
+ import { DEFAULT_STALE_TIME, requestContextSlot, toKeyPart } from "../utils/query-keys.js";
4
3
  export const LISTING_QUERY_KEYS = {
5
4
  root: ["listings"],
6
5
  listing: (listingName) => [...LISTING_QUERY_KEYS.root, listingName],
7
- detail: (listingName, parameters, query) => [
8
- ...LISTING_QUERY_KEYS.listing(listingName),
9
- JSON.stringify(parameters),
10
- JSON.stringify(query)
11
- ]
6
+ detail: (listingName, parameters, query, contextKey, contextDomain) => [...LISTING_QUERY_KEYS.listing(listingName), toKeyPart(parameters), toKeyPart(query), requestContextSlot(contextKey, contextDomain)]
12
7
  };
13
8
  export function fetchListingQuery(config) {
14
9
  return {
15
10
  key: () => {
16
- const params = unwrapRef(config.params);
17
- const query = unwrapRef(config.query) ?? {};
18
- const page = unwrapRef(config.page);
11
+ const query = toValue(config.query) ?? {};
12
+ const page = toValue(config.page);
19
13
  const queryWithPage = page ? { ...query, page } : query;
20
- return LISTING_QUERY_KEYS.detail(config.name, params, queryWithPage);
14
+ return LISTING_QUERY_KEYS.detail(
15
+ config.name,
16
+ toValue(config.params),
17
+ queryWithPage,
18
+ toValue(config.contextKey),
19
+ toValue(config.contextDomain)
20
+ );
21
21
  },
22
22
  query: async () => {
23
- const params = unwrapRef(config.params);
24
- const query = unwrapRef(config.query) ?? {};
25
- const contextKey = unwrapRef(config.contextKey);
26
- const contextDomain = unwrapRef(config.contextDomain);
27
- const requestUrl = unwrapRef(config.requestUrl);
28
- const page = unwrapRef(config.page);
23
+ const query = toValue(config.query) ?? {};
24
+ const page = toValue(config.page);
29
25
  const queryWithPage = page ? { ...query, page } : query;
30
26
  try {
31
27
  let client = config._client;
@@ -33,20 +29,23 @@ export function fetchListingQuery(config) {
33
29
  const { useFronticClient } = await import("./useFronticClient.js");
34
30
  client = useFronticClient();
35
31
  }
36
- const result = await client.listing(config.name, params, {
32
+ return await client.listing(config.name, toValue(config.params), {
37
33
  query: queryWithPage,
38
- contextKey,
39
- contextDomain,
40
- requestUrl
34
+ contextKey: toValue(config.contextKey),
35
+ contextDomain: toValue(config.contextDomain),
36
+ requestUrl: toValue(config.requestUrl)
41
37
  });
42
- return result;
43
38
  } catch (error) {
44
39
  console.error(`[@frontic/nuxt] Failed to fetch listing "${String(config.name)}". Make sure the Frontic client is generated.`);
45
40
  throw error;
46
41
  }
47
42
  },
48
- staleTime: config.staleTime ?? 1e3 * 60 * 5
49
- // 5 minutes default
43
+ staleTime: config.staleTime ?? DEFAULT_STALE_TIME,
44
+ ...config.gcTime !== void 0 && { gcTime: config.gcTime },
45
+ ...config.enabled !== void 0 && { enabled: config.enabled },
46
+ // keepPreviousData: show the previous entry's data while a changed key
47
+ // (new page, filter, context) loads; never written to the cache
48
+ ...config.keepPreviousData !== false && { placeholderData: (previousData) => previousData }
50
49
  };
51
50
  }
52
51
  export function createCacheKey(keyArray) {
@@ -1,16 +1,10 @@
1
- /**
2
- * Page Query Factory
3
- *
4
- * Provides query key management and query factory functions for Frontic pages.
5
- * Compatible with both @pinia/colada and useAsyncData patterns.
6
- */
7
- import type { FrontstackClient } from '@frontic/stack/generated-client';
8
1
  import type { MaybeRef } from 'vue';
9
- import type { FronticRequestOptions } from '../types/listing.js';
10
- export interface FetchPageConfig extends FronticRequestOptions {
2
+ import type { FronticClient } from '../types/client.js';
3
+ import type { Page } from '../types/registry.js';
4
+ import type { FronticRequestOptions, FronticQueryOptions } from '../types/listing.js';
5
+ export interface FetchPageConfig extends FronticRequestOptions, FronticQueryOptions {
11
6
  slug: MaybeRef<string>;
12
- staleTime?: number;
13
- _client?: FrontstackClient;
7
+ _client?: FronticClient;
14
8
  }
15
9
  /**
16
10
  * Query key factory for page queries
@@ -21,13 +15,16 @@ export interface FetchPageConfig extends FronticRequestOptions {
21
15
  * PAGE_QUERY_KEYS.root // ['pages']
22
16
  * PAGE_QUERY_KEYS.page('demo-shop.com/uk/products') // ['pages', 'demo-shop.com/uk/products']
23
17
  * PAGE_QUERY_KEYS.detail('demo-shop.com/uk/products', 'context-token')
24
- * // ['pages', 'demo-shop.com/uk/products', 'context-token']
18
+ * // ['pages', 'demo-shop.com/uk/products', { context: 'context-token', domain: null }]
25
19
  * ```
26
20
  */
27
21
  export declare const PAGE_QUERY_KEYS: {
28
- root: string[];
29
- page: (slug: string) => string[];
30
- detail: (slug: string, contextKey?: string) => string[];
22
+ root: readonly ["pages"];
23
+ page: (slug: string) => readonly ["pages", string];
24
+ detail: (slug: string, contextKey?: string, contextDomain?: string) => readonly ["pages", string, {
25
+ readonly context: string | null;
26
+ readonly domain: string | null;
27
+ }];
31
28
  };
32
29
  /**
33
30
  * Generic query factory for fetching pages
@@ -38,20 +35,26 @@ export declare const PAGE_QUERY_KEYS: {
38
35
  * // With @pinia/colada
39
36
  * const pageQuery = fetchPageQuery({
40
37
  * slug: 'demo-shop.com/uk/products/shoes',
41
- * contextKey: token.value
38
+ * contextKey: token
42
39
  * })
43
40
  *
44
41
  * const { data, status } = useQuery(pageQuery)
45
42
  *
46
43
  * // With useAsyncData
47
44
  * const { data, status } = useAsyncData(
48
- * pageQuery.key().join('-'),
45
+ * createPageCacheKey(pageQuery.key()),
49
46
  * pageQuery.query
50
47
  * )
51
48
  * ```
52
49
  */
53
50
  export declare function fetchPageQuery(config: FetchPageConfig): {
54
- key: () => string[];
51
+ placeholderData?: ((previousData: Page | undefined) => import("../types/registry.js").DefaultPage | undefined) | undefined;
52
+ enabled?: import("vue").MaybeRefOrGetter<boolean> | undefined;
53
+ gcTime?: number | undefined;
54
+ key: () => readonly ["pages", string, {
55
+ readonly context: string | null;
56
+ readonly domain: string | null;
57
+ }];
55
58
  query: () => Promise<Page>;
56
59
  staleTime: number;
57
60
  };
@@ -1,32 +1,31 @@
1
- function unwrapRef(ref) {
2
- return typeof ref === "object" && ref !== null && "value" in ref ? ref.value : ref;
3
- }
1
+ import { toValue } from "vue";
2
+ import { DEFAULT_STALE_TIME, requestContextSlot } from "../utils/query-keys.js";
4
3
  export const PAGE_QUERY_KEYS = {
5
4
  root: ["pages"],
6
5
  page: (slug) => [...PAGE_QUERY_KEYS.root, slug],
7
- detail: (slug, contextKey) => [...PAGE_QUERY_KEYS.page(slug), contextKey ?? "default"]
6
+ detail: (slug, contextKey, contextDomain) => [...PAGE_QUERY_KEYS.page(slug), requestContextSlot(contextKey, contextDomain)]
8
7
  };
9
8
  export function fetchPageQuery(config) {
10
9
  return {
11
- key: () => {
12
- const slug = unwrapRef(config.slug);
13
- const contextKey = unwrapRef(config.contextKey);
14
- return PAGE_QUERY_KEYS.detail(slug, contextKey);
15
- },
10
+ key: () => PAGE_QUERY_KEYS.detail(toValue(config.slug), toValue(config.contextKey), toValue(config.contextDomain)),
16
11
  query: async () => {
17
12
  let client = config._client;
18
13
  if (!client) {
19
14
  const { useFronticClient } = await import("./useFronticClient.js");
20
15
  client = useFronticClient();
21
16
  }
22
- const slug = unwrapRef(config.slug);
23
- const contextKey = unwrapRef(config.contextKey);
24
- const contextDomain = unwrapRef(config.contextDomain);
25
- const requestUrl = unwrapRef(config.requestUrl);
26
- return await client.page(slug, { contextKey, contextDomain, requestUrl });
17
+ return await client.page(toValue(config.slug), {
18
+ contextKey: toValue(config.contextKey),
19
+ contextDomain: toValue(config.contextDomain),
20
+ requestUrl: toValue(config.requestUrl)
21
+ });
27
22
  },
28
- staleTime: config.staleTime ?? 1e3 * 60 * 5
29
- // 5 minutes default
23
+ staleTime: config.staleTime ?? DEFAULT_STALE_TIME,
24
+ ...config.gcTime !== void 0 && { gcTime: config.gcTime },
25
+ ...config.enabled !== void 0 && { enabled: config.enabled },
26
+ // keepPreviousData: show the previous entry's data while a changed key
27
+ // (new slug, new context) loads; never written to the cache
28
+ ...config.keepPreviousData !== false && { placeholderData: (previousData) => previousData }
30
29
  };
31
30
  }
32
31
  export function createPageCacheKey(keyArray) {
@@ -1,19 +1,12 @@
1
- /**
2
- * Tree Query Factory
3
- *
4
- * Provides query key management and query factory functions for Frontic trees.
5
- * Compatible with both @pinia/colada and useAsyncData patterns.
6
- */
7
- import type { FrontstackClient } from '@frontic/stack/generated-client';
8
- import type { Trees, Responses } from '@frontic/stack/generated-types';
9
1
  import type { MaybeRef } from 'vue';
10
- import type { FronticRequestOptions } from '../types/listing.js';
11
- export interface FetchTreeConfig<TTree extends string> extends FronticRequestOptions {
2
+ import type { FronticClient } from '../types/client.js';
3
+ import type { TreeName, ResponseOf } from '../types/registry.js';
4
+ import type { FronticRequestOptions, FronticQueryOptions } from '../types/listing.js';
5
+ export interface FetchTreeConfig<TTree extends string> extends FronticRequestOptions, FronticQueryOptions {
12
6
  name: TTree;
13
7
  key?: MaybeRef<string | undefined>;
14
8
  depth?: MaybeRef<number | undefined>;
15
- staleTime?: number;
16
- _client?: FrontstackClient;
9
+ _client?: FronticClient;
17
10
  }
18
11
  /**
19
12
  * Query key factory for tree queries
@@ -29,15 +22,18 @@ export interface FetchTreeConfig<TTree extends string> extends FronticRequestOpt
29
22
  * TREE_QUERY_KEYS.root // ['trees']
30
23
  * TREE_QUERY_KEYS.tree('CategoryNavigation') // ['trees', 'CategoryNavigation']
31
24
  * TREE_QUERY_KEYS.detail('CategoryNavigation', 'shop', 2, 'context-token')
32
- * // ['trees', 'CategoryNavigation', 'shop', '2', 'context-token']
25
+ * // ['trees', 'CategoryNavigation', 'shop', '2', { context: 'context-token', domain: null }]
33
26
  * TREE_QUERY_KEYS.detail('CategoryNavigation')
34
- * // ['trees', 'CategoryNavigation', '', 'all', 'default']
27
+ * // ['trees', 'CategoryNavigation', '', 'all', { context: null, domain: null }]
35
28
  * ```
36
29
  */
37
30
  export declare const TREE_QUERY_KEYS: {
38
- root: string[];
39
- tree: <TTree extends string>(treeName: TTree) => string[];
40
- detail: <TTree extends string>(treeName: TTree, key?: string, depth?: number, contextKey?: string) => string[];
31
+ root: readonly ["trees"];
32
+ tree: <TTree extends string>(treeName: TTree) => readonly ["trees", TTree];
33
+ detail: <TTree extends string>(treeName: TTree, key?: string, depth?: number, contextKey?: string, contextDomain?: string) => readonly ["trees", TTree, string, string, {
34
+ readonly context: string | null;
35
+ readonly domain: string | null;
36
+ }];
41
37
  };
42
38
  /**
43
39
  * Generic query factory for fetching trees
@@ -50,21 +46,27 @@ export declare const TREE_QUERY_KEYS: {
50
46
  * name: 'CategoryNavigation',
51
47
  * key: 'shop',
52
48
  * depth: 2,
53
- * contextKey: token.value
49
+ * contextKey: token
54
50
  * })
55
51
  *
56
52
  * const { data, status } = useQuery(treeQuery)
57
53
  *
58
54
  * // With useAsyncData
59
55
  * const { data, status } = useAsyncData(
60
- * treeQuery.key().join('-'),
56
+ * createTreeCacheKey(treeQuery.key()),
61
57
  * treeQuery.query
62
58
  * )
63
59
  * ```
64
60
  */
65
- export declare function fetchTreeQuery<TTree extends keyof Trees>(config: FetchTreeConfig<TTree>): {
66
- key: () => string[];
67
- query: () => Promise<Responses[TTree]>;
61
+ export declare function fetchTreeQuery<TTree extends TreeName>(config: FetchTreeConfig<TTree>): {
62
+ placeholderData?: ((previousData: ResponseOf<TTree> | undefined) => ResponseOf<TTree> | undefined) | undefined;
63
+ enabled?: import("vue").MaybeRefOrGetter<boolean> | undefined;
64
+ gcTime?: number | undefined;
65
+ key: () => readonly ["trees", TTree, string, string, {
66
+ readonly context: string | null;
67
+ readonly domain: string | null;
68
+ }];
69
+ query: () => Promise<ResponseOf<TTree>>;
68
70
  staleTime: number;
69
71
  };
70
72
  /**
@@ -1,47 +1,37 @@
1
- function unwrapRef(ref) {
2
- return typeof ref === "object" && ref !== null && "value" in ref ? ref.value : ref;
3
- }
1
+ import { toValue } from "vue";
2
+ import { DEFAULT_STALE_TIME, requestContextSlot } from "../utils/query-keys.js";
4
3
  export const TREE_QUERY_KEYS = {
5
4
  root: ["trees"],
6
5
  tree: (treeName) => [...TREE_QUERY_KEYS.root, treeName],
7
- detail: (treeName, key, depth, contextKey) => [
8
- ...TREE_QUERY_KEYS.tree(treeName),
9
- key ?? "",
10
- depth !== void 0 ? String(depth) : "all",
11
- contextKey ?? "default"
12
- ]
6
+ detail: (treeName, key, depth, contextKey, contextDomain) => [...TREE_QUERY_KEYS.tree(treeName), key ?? "", depth !== void 0 ? String(depth) : "all", requestContextSlot(contextKey, contextDomain)]
13
7
  };
14
8
  export function fetchTreeQuery(config) {
15
9
  return {
16
- key: () => {
17
- const key = unwrapRef(config.key);
18
- const depth = unwrapRef(config.depth);
19
- const contextKey = unwrapRef(config.contextKey);
20
- return TREE_QUERY_KEYS.detail(config.name, key, depth, contextKey);
21
- },
10
+ key: () => TREE_QUERY_KEYS.detail(config.name, toValue(config.key), toValue(config.depth), toValue(config.contextKey), toValue(config.contextDomain)),
22
11
  query: async () => {
23
12
  let client = config._client;
24
13
  if (!client) {
25
14
  const { useFronticClient } = await import("./useFronticClient.js");
26
15
  client = useFronticClient();
27
16
  }
28
- const key = unwrapRef(config.key);
29
- const depth = unwrapRef(config.depth);
30
- const contextKey = unwrapRef(config.contextKey);
31
- const contextDomain = unwrapRef(config.contextDomain);
32
- const requestUrl = unwrapRef(config.requestUrl);
17
+ const key = toValue(config.key);
18
+ const depth = toValue(config.depth);
33
19
  const treeQuery = {};
34
20
  if (key !== void 0) treeQuery.key = key;
35
21
  if (depth !== void 0) treeQuery.depth = depth;
36
22
  return await client.tree(config.name, {
37
23
  ...Object.keys(treeQuery).length > 0 && { query: treeQuery },
38
- contextKey,
39
- contextDomain,
40
- requestUrl
24
+ contextKey: toValue(config.contextKey),
25
+ contextDomain: toValue(config.contextDomain),
26
+ requestUrl: toValue(config.requestUrl)
41
27
  });
42
28
  },
43
- staleTime: config.staleTime ?? 1e3 * 60 * 5
44
- // 5 minutes default
29
+ staleTime: config.staleTime ?? DEFAULT_STALE_TIME,
30
+ ...config.gcTime !== void 0 && { gcTime: config.gcTime },
31
+ ...config.enabled !== void 0 && { enabled: config.enabled },
32
+ // keepPreviousData: show the previous entry's data while a changed key
33
+ // (new subtree, new context) loads; never written to the cache
34
+ ...config.keepPreviousData !== false && { placeholderData: (previousData) => previousData }
45
35
  };
46
36
  }
47
37
  export function createTreeCacheKey(keyArray) {
@@ -1,12 +1,7 @@
1
1
  import type { Ref, MaybeRef } from 'vue';
2
- import type { Blocks, Responses } from '@frontic/stack/generated-types';
3
- import type { FronticRequestOptions } from '../types/listing.js';
4
- export interface UseFronticBlockOptions extends FronticRequestOptions {
5
- /**
6
- * Cache stale time in milliseconds
7
- * @default 300000 (5 minutes)
8
- */
9
- staleTime?: number;
2
+ import type { BlockName, ResponseOf } from '../types/registry.js';
3
+ import type { FronticRequestOptions, FronticQueryOptions } from '../types/listing.js';
4
+ export interface UseFronticBlockOptions extends FronticRequestOptions, FronticQueryOptions {
10
5
  }
11
6
  /**
12
7
  * Fetch a Frontic block by name and key
@@ -34,21 +29,35 @@ export interface UseFronticBlockOptions extends FronticRequestOptions {
34
29
  * const { block } = useFronticBlock('ProductCard', productKey)
35
30
  * ```
36
31
  */
37
- export declare function useFronticBlock<T extends keyof Blocks>(name: T, key: MaybeRef<string>, options?: UseFronticBlockOptions): {
32
+ export declare function useFronticBlock<T extends BlockName>(name: T, key: MaybeRef<string>, options?: UseFronticBlockOptions): {
38
33
  /**
39
34
  * The block data, typed based on the block name
40
35
  */
41
- block: Ref<Responses[T] | undefined>;
36
+ block: Ref<ResponseOf<T> | undefined>;
42
37
  /**
43
- * Query status: 'pending' | 'error' | 'success'
38
+ * Data status: 'pending' | 'error' | 'success'
44
39
  */
45
40
  status: import("vue").ShallowRef<import("@pinia/colada").DataStateStatus>;
41
+ /**
42
+ * Network status: 'idle' | 'loading'. Together with `status` this
43
+ * distinguishes a first load (`pending`) from a background refresh
44
+ * (`success` + 'loading').
45
+ */
46
+ asyncStatus: import("vue").ComputedRef<import("@pinia/colada").AsyncStatus>;
47
+ /**
48
+ * Whether a request is in flight (shortcut for `asyncStatus === 'loading'`)
49
+ */
50
+ isLoading: import("vue").ShallowRef<boolean>;
51
+ /**
52
+ * Error of the last fetch, null while pending or after success
53
+ */
54
+ error: import("vue").ShallowRef<Error | null>;
46
55
  /**
47
56
  * Manually refresh the block data (uses cache if valid)
48
57
  */
49
- refresh: (throwOnError?: boolean) => Promise<import("@pinia/colada").DataState<unknown, Error, undefined>>;
58
+ refresh: (throwOnError?: boolean) => Promise<import("@pinia/colada").DataState<ResponseOf<T>, Error, undefined>>;
50
59
  /**
51
60
  * Force a fresh fetch of the block data, bypassing cache
52
61
  */
53
- refetch: (throwOnError?: boolean) => Promise<import("@pinia/colada").DataState<unknown, Error, undefined>>;
62
+ refetch: (throwOnError?: boolean) => Promise<import("@pinia/colada").DataState<ResponseOf<T>, Error, undefined>>;
54
63
  };
@@ -10,18 +10,35 @@ export function useFronticBlock(name, key, options) {
10
10
  contextDomain: options?.contextDomain,
11
11
  requestUrl: options?.requestUrl,
12
12
  staleTime: options?.staleTime,
13
+ gcTime: options?.gcTime,
14
+ enabled: options?.enabled,
15
+ keepPreviousData: options?.keepPreviousData,
13
16
  _client
14
17
  });
15
- const { data, status, refresh, refetch } = useQuery(blockQuery);
18
+ const { data, status, asyncStatus, isLoading, error, refresh, refetch } = useQuery(blockQuery);
16
19
  return {
17
20
  /**
18
21
  * The block data, typed based on the block name
19
22
  */
20
23
  block: data,
21
24
  /**
22
- * Query status: 'pending' | 'error' | 'success'
25
+ * Data status: 'pending' | 'error' | 'success'
23
26
  */
24
27
  status,
28
+ /**
29
+ * Network status: 'idle' | 'loading'. Together with `status` this
30
+ * distinguishes a first load (`pending`) from a background refresh
31
+ * (`success` + 'loading').
32
+ */
33
+ asyncStatus,
34
+ /**
35
+ * Whether a request is in flight (shortcut for `asyncStatus === 'loading'`)
36
+ */
37
+ isLoading,
38
+ /**
39
+ * Error of the last fetch, null while pending or after success
40
+ */
41
+ error,
25
42
  /**
26
43
  * Manually refresh the block data (uses cache if valid)
27
44
  */
@@ -1,4 +1,5 @@
1
- import type { FrontstackClient } from '@frontic/stack/generated-client';
1
+ import type { FronticClient } from '../types/client.js';
2
+ export type { FronticClient } from '../types/client.js';
2
3
  export interface UseFronticClientOptions {
3
4
  /**
4
5
  * Override proxy behavior
@@ -27,7 +28,9 @@ export interface UseFronticClientOptions {
27
28
  * - `string`: Use specific secret
28
29
  * - `undefined`: Use module config fetchApiSecret (on server) or none (on client)
29
30
  *
30
- * Note: On client-side, secrets are injected by the proxy server instead
31
+ * Requests are authenticated server-side without this: the proxy injects the
32
+ * secret for browser traffic, a Nitro plugin for SSR. Generated clients
33
+ * without `fs-secret` support drop this option.
31
34
  */
32
35
  secret?: string;
33
36
  }
@@ -53,4 +56,4 @@ export interface UseFronticClientOptions {
53
56
  * const noContextClient = useFronticClient({ contextDomain: false })
54
57
  * ```
55
58
  */
56
- export declare function useFronticClient(options?: UseFronticClientOptions): FrontstackClient;
59
+ export declare function useFronticClient(options?: UseFronticClientOptions): FronticClient;
@@ -1,4 +1,7 @@
1
1
  import type { Ref } from 'vue';
2
+ import type { Context, ContextOption } from '../types/registry.js';
3
+ /** Payload passed to the `frontic:context:*` hooks */
4
+ export type FronticContext = Context;
2
5
  export interface UseFronticContextOptions {
3
6
  /**
4
7
  * Cookie name for persisting the context token
@@ -49,6 +52,15 @@ export interface UseFronticContextOptions {
49
52
  * </option>
50
53
  * </select>
51
54
  * ```
55
+ *
56
+ * @example React to every context change from anywhere (plugin, middleware, component)
57
+ * ```ts
58
+ * export default defineNuxtPlugin((nuxtApp) => {
59
+ * nuxtApp.hook('frontic:context:updated', (context) => {
60
+ * analytics.setSessionProperties({ region: context.region, locale: context.locale })
61
+ * })
62
+ * })
63
+ * ```
52
64
  */
53
65
  export declare function useFronticContext(options?: UseFronticContextOptions): {
54
66
  /**