@frontic/nuxt 0.0.3 → 0.1.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.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +126 -0
  3. package/dist/module.d.mts +87 -10
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +117 -56
  6. package/dist/runtime/composables/blocks.d.ts +0 -0
  7. package/dist/runtime/composables/blocks.js +31 -0
  8. package/dist/runtime/composables/index.js +7 -0
  9. package/dist/runtime/composables/listings.js +15 -9
  10. package/dist/runtime/composables/pages.d.ts +0 -0
  11. package/dist/runtime/composables/pages.js +31 -0
  12. package/dist/runtime/composables/useFronticBlock.d.ts +0 -0
  13. package/dist/runtime/composables/useFronticBlock.js +31 -0
  14. package/dist/runtime/composables/useFronticClient.d.ts +0 -0
  15. package/dist/runtime/composables/useFronticClient.js +67 -0
  16. package/dist/runtime/composables/useFronticContext.d.ts +0 -0
  17. package/dist/runtime/composables/useFronticContext.js +77 -0
  18. package/dist/runtime/composables/useFronticListing.js +26 -201
  19. package/dist/runtime/composables/useFronticPage.d.ts +0 -0
  20. package/dist/runtime/composables/useFronticPage.js +74 -0
  21. package/dist/runtime/composables/useFronticSearch.d.ts +0 -0
  22. package/dist/runtime/composables/useFronticSearch.js +321 -0
  23. package/dist/runtime/server/api/frontic/[...path].d.ts +0 -0
  24. package/dist/runtime/server/api/frontic/[...path].js +21 -0
  25. package/dist/runtime/types/search.d.ts +0 -0
  26. package/dist/runtime/types/search.js +0 -0
  27. package/dist/runtime/utils/state-helpers.js +19 -19
  28. package/dist/types.d.mts +4 -2
  29. package/package.json +29 -23
  30. package/dist/module.cjs +0 -5
  31. package/dist/module.d.ts +0 -48
  32. package/dist/types.d.ts +0 -7
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Frontic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # @frontic/nuxt
2
+
3
+ Nuxt module for integrating with [Frontstack](https://frontstack.dev) headless commerce. Provides auto-imported composables for data fetching with smart caching, page routing, and context management.
4
+
5
+ ## Features
6
+
7
+ - **Smart caching** via [Pinia Colada](https://pinia-colada.esm.dev/) - stale-while-revalidate, request deduplication, SSR hydration
8
+ - **Type-safe composables** - Full TypeScript support with generated types from your Frontstack schema
9
+ - **Search & filtering** - Ready-to-use search state management with filters, sorting, and pagination
10
+ - **Page routing** - Dynamic page resolution with automatic redirects and 404 handling
11
+ - **Context management** - Locale and region switching with cookie persistence
12
+ - **Built-in proxy** - CORS-free API requests through your Nuxt server
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npx nuxi@latest module add @frontic/nuxt
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ```typescript
23
+ // nuxt.config.ts
24
+ export default defineNuxtConfig({
25
+ modules: ['@frontic/nuxt'],
26
+ frontic: {
27
+ contextDomain: 'your-shop.com',
28
+ },
29
+ })
30
+ ```
31
+
32
+ Generate the Frontstack client:
33
+
34
+ ```bash
35
+ npx @frontic/cli generate
36
+ ```
37
+
38
+ ## Composables
39
+
40
+ ### useFronticPage
41
+
42
+ Dynamic page routing with automatic redirects and 404 handling:
43
+
44
+ ```typescript
45
+ const { page, data, type, block, alternates } = useFronticPage()
46
+ ```
47
+
48
+ ### useFronticSearch
49
+
50
+ Full-featured search with filtering, sorting, and pagination:
51
+
52
+ ```typescript
53
+ const { result, state, searchTerm, filterResult, sortResult, loadNext } = useFronticSearch(
54
+ 'ProductSearch',
55
+ {},
56
+ {
57
+ filter: {
58
+ select: ['properties.color', 'properties.size'],
59
+ label: { 'properties.color': 'Color' },
60
+ },
61
+ sorting: {
62
+ label: { 'name:asc': 'Name A-Z', 'price.amount:asc': 'Price: Low to High' },
63
+ },
64
+ }
65
+ )
66
+ ```
67
+
68
+ ### useFronticListing
69
+
70
+ Simple listing access:
71
+
72
+ ```typescript
73
+ const { listing, status, refresh } = useFronticListing('FeaturedProducts', { limit: 10 })
74
+ ```
75
+
76
+ ### useFronticBlock
77
+
78
+ Fetch single blocks (products, categories):
79
+
80
+ ```typescript
81
+ const { block, status } = useFronticBlock('Product', 'product-handle')
82
+ ```
83
+
84
+ ### useFronticContext
85
+
86
+ Manage locale and region:
87
+
88
+ ```typescript
89
+ const { contexts, current, update } = useFronticContext()
90
+ ```
91
+
92
+ ## Configuration
93
+
94
+ ```typescript
95
+ export default defineNuxtConfig({
96
+ frontic: {
97
+ // Page routing
98
+ contextDomain: 'your-shop.com',
99
+ redirectOn301: true,
100
+ throwOn404: true,
101
+
102
+ // API proxy
103
+ proxy: true, // or '/api/custom-path'
104
+ fetchApiSecret: process.env.FRONTSTACK_FETCH_SECRET,
105
+
106
+ // Context cookies
107
+ contextCookieName: 'fs-context',
108
+ contextCookieMaxAge: 31536000,
109
+
110
+ // Composables
111
+ composables: true, // or ['page', 'search', 'listing', 'block', 'context', 'client']
112
+
113
+ // UI components (optional)
114
+ prefix: 'Ui',
115
+ componentDir: '@/components/ui',
116
+ },
117
+ })
118
+ ```
119
+
120
+ ## Documentation
121
+
122
+ Full documentation at [docs.frontstack.dev/reference/nuxt-module](https://docs.frontstack.dev/reference/nuxt-module)
123
+
124
+ ## License
125
+
126
+ MIT
package/dist/module.d.mts CHANGED
@@ -2,8 +2,15 @@ import { NuxtModule } from '@nuxt/schema';
2
2
 
3
3
  /**
4
4
  * Available Frontic composables that can be enabled/disabled
5
+ *
6
+ * - 'block': useFronticBlock - Fetch single blocks (products, categories)
7
+ * - 'listing': useFronticListing - Fetch listings with caching
8
+ * - 'search': useFronticSearch - Full-featured search with filters/sorting
9
+ * - 'page': useFronticPage - Dynamic page routing
10
+ * - 'context': useFronticContext - Locale/region management
11
+ * - 'client': useFronticClient - Low-level API client
5
12
  */
6
- type FronticComposable = 'listing' | 'page' | 'block' | 'context';
13
+ type FronticComposable = 'block' | 'listing' | 'search' | 'page' | 'context' | 'client';
7
14
  /**
8
15
  * Frontic composables configuration
9
16
  * - true: Enable all composables (default)
@@ -26,23 +33,93 @@ interface FronticOptions {
26
33
  */
27
34
  componentDir: string;
28
35
  /**
29
- * Configure which Frontic composables to enable
30
- * - true: Enable all composables (default)
31
- * - false or []: Disable all composables
32
- * - string[]: Enable only specified composables
36
+ * Configure which Frontic composables to auto-import
33
37
  *
34
- * Available: 'listing', 'page', 'block', 'context'
38
+ * When a composable is disabled, it will not be auto-imported during the Nuxt build.
39
+ * This means you won't get type errors or warnings—the composable simply won't exist.
40
+ * Use this to reduce bundle size by excluding composables you don't need.
41
+ *
42
+ * Available composables:
43
+ * - 'block': useFronticBlock - Fetch single blocks
44
+ * - 'listing': useFronticListing - Fetch listings
45
+ * - 'search': useFronticSearch - Search with filters/sorting
46
+ * - 'page': useFronticPage - Dynamic page routing
47
+ * - 'context': useFronticContext - Locale/region management
48
+ * - 'client': useFronticClient - Low-level API client
35
49
  *
36
50
  * @example
37
- * composables: true // Enable all
51
+ * composables: true // Enable all (default)
38
52
  * composables: false // Disable all
39
- * composables: ['listing', 'page'] // Enable specific ones
53
+ * composables: ['listing', 'page', 'client'] // Enable specific ones
40
54
  *
41
55
  * @default true
42
56
  */
43
57
  composables?: FronticComposablesConfig;
58
+ /**
59
+ * Enable/configure the API proxy for CORS prevention
60
+ * - true: Enable proxy at default path '/api/stack'
61
+ * - false: Disable proxy
62
+ * - string: Enable proxy at custom path
63
+ *
64
+ * @default true
65
+ */
66
+ proxy?: boolean | string;
67
+ /**
68
+ * Context domain for page slug construction
69
+ * Used by useFronticPage when auto-detecting slug from current route
70
+ *
71
+ * @example 'demo-shop.com'
72
+ */
73
+ contextDomain?: string;
74
+ /**
75
+ * Cookie name for persisting the context token
76
+ * @default 'fs-context'
77
+ */
78
+ contextCookieName?: string;
79
+ /**
80
+ * Cookie max age in seconds for context token
81
+ * @default 31536000 (1 year)
82
+ */
83
+ contextCookieMaxAge?: number;
84
+ /**
85
+ * Disable automatic context fetching and cookie management in useFronticContext
86
+ *
87
+ * When true:
88
+ * - The context endpoint will NOT be called automatically on mount
89
+ * - No context cookie will be set automatically
90
+ * - You must manually call `refresh()` to fetch contexts
91
+ * - You are responsible for storing and managing the context token
92
+ *
93
+ * Use this when you want full control over context management,
94
+ * or when integrating with an existing locale/region system.
95
+ *
96
+ * @default false
97
+ */
98
+ disableContext?: boolean;
99
+ /**
100
+ * Automatically redirect on 301 responses
101
+ * Can be overridden per-request in useFronticPage
102
+ * @default true
103
+ */
104
+ redirectOn301?: boolean;
105
+ /**
106
+ * Throw a 404 error when page is not found
107
+ * Can be overridden per-request in useFronticPage
108
+ * @default true
109
+ */
110
+ throwOn404?: boolean;
111
+ /**
112
+ * API secret for authenticating Fetch API requests
113
+ * Required for protected environments (e.g., development/staging)
114
+ * Stored in private runtime config (server-only, never exposed to browser)
115
+ *
116
+ * For client-side requests, the secret is automatically injected by the proxy
117
+ *
118
+ * @example process.env.FRONTSTACK_FETCH_SECRET
119
+ */
120
+ fetchApiSecret?: string;
44
121
  }
45
- declare const module: NuxtModule<FronticOptions>;
122
+ declare const module$1: NuxtModule<FronticOptions>;
46
123
 
47
- export { module as default };
124
+ export { module$1 as default };
48
125
  export type { FronticComposable, FronticComposablesConfig, FronticOptions };
package/dist/module.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "nuxt": ">=3.17.0"
7
7
  },
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.4",
9
+ "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -1,33 +1,28 @@
1
1
  import { existsSync, readdirSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
- import { defineNuxtModule, createResolver, addImports, addComponentsDir, addComponentExports } from '@nuxt/kit';
4
+ import { defineNuxtModule, createResolver, addServerHandler, addImports, addComponentsDir, addComponentExports } from '@nuxt/kit';
5
5
 
6
-
7
-
8
- // -- Unbuild CommonJS Shims --
9
- import __cjs_url__ from 'url';
10
- import __cjs_path__ from 'path';
11
- import __cjs_mod__ from 'module';
12
- const __filename = __cjs_url__.fileURLToPath(import.meta.url);
13
- const __dirname = __cjs_path__.dirname(__filename);
14
- const require = __cjs_mod__.createRequire(import.meta.url);
15
6
  const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
16
- const IMPLEMENTED_COMPOSABLES = ["listing"];
7
+ const ALL_COMPOSABLES = ["block", "listing", "search", "page", "context", "client"];
17
8
  function isComposableEnabled(config, name) {
18
- if (config === true)
19
- return true;
20
- if (config === false)
21
- return false;
22
- if (Array.isArray(config))
23
- return config.includes(name);
9
+ if (config === true) return true;
10
+ if (config === false) return false;
11
+ if (Array.isArray(config)) return config.includes(name);
24
12
  return true;
25
13
  }
26
- const module = defineNuxtModule({
14
+ const module$1 = defineNuxtModule({
27
15
  defaults: {
28
16
  prefix: "",
29
17
  componentDir: "@/components/ui",
30
- composables: true
18
+ composables: true,
19
+ proxy: true,
20
+ contextCookieName: "fs-context",
21
+ contextCookieMaxAge: 60 * 60 * 24 * 365,
22
+ // 1 year
23
+ disableContext: false,
24
+ redirectOn301: true,
25
+ throwOn404: true
31
26
  },
32
27
  meta: {
33
28
  name: "frontic",
@@ -38,22 +33,46 @@ const module = defineNuxtModule({
38
33
  }
39
34
  },
40
35
  async setup(options, nuxt) {
41
- const { componentDir, prefix, composables: composablesConfig = true } = options;
36
+ const {
37
+ componentDir,
38
+ prefix,
39
+ composables: composablesConfig = true,
40
+ proxy: proxyConfig = true,
41
+ contextDomain,
42
+ contextCookieName = "fs-context",
43
+ contextCookieMaxAge = 60 * 60 * 24 * 365,
44
+ disableContext = false,
45
+ redirectOn301 = true,
46
+ throwOn404 = true,
47
+ fetchApiSecret
48
+ } = options;
42
49
  const COMPONENT_DIR_PATH = componentDir;
43
50
  const ROOT_DIR_PATH = nuxt.options.rootDir;
44
51
  const { resolve, resolvePath } = createResolver(ROOT_DIR_PATH);
45
52
  const { resolve: resolveModule } = createResolver(_dirname);
46
53
  const runtimeDir = resolveModule("./runtime");
54
+ const proxyPath = typeof proxyConfig === "string" ? proxyConfig : proxyConfig !== false ? "/api/stack" : void 0;
55
+ if (proxyPath) {
56
+ addServerHandler({
57
+ route: `${proxyPath}/**`,
58
+ handler: resolveModule("./runtime/server/api/stack/[...path]")
59
+ });
60
+ }
47
61
  const fronticClientDir = join(ROOT_DIR_PATH, ".frontstack");
48
62
  const fronticClientPath = join(fronticClientDir, "generated-client.ts");
49
63
  const hasFronticClient = existsSync(fronticClientPath);
64
+ const blockEnabled = isComposableEnabled(composablesConfig, "block");
50
65
  const listingEnabled = isComposableEnabled(composablesConfig, "listing");
66
+ const searchEnabled = isComposableEnabled(composablesConfig, "search");
51
67
  const pageEnabled = isComposableEnabled(composablesConfig, "page");
52
- const blockEnabled = isComposableEnabled(composablesConfig, "block");
53
68
  const contextEnabled = isComposableEnabled(composablesConfig, "context");
54
- const anyImplementedEnabled = IMPLEMENTED_COMPOSABLES.some((c) => isComposableEnabled(composablesConfig, c));
55
- if (anyImplementedEnabled && !hasFronticClient) {
56
- const enabledList = IMPLEMENTED_COMPOSABLES.filter((c) => isComposableEnabled(composablesConfig, c)).map((c) => `useFrontic${c.charAt(0).toUpperCase() + c.slice(1)}`);
69
+ const clientEnabled = isComposableEnabled(composablesConfig, "client");
70
+ const anyComposableEnabled = ALL_COMPOSABLES.some((c) => isComposableEnabled(composablesConfig, c));
71
+ if (anyComposableEnabled && !hasFronticClient) {
72
+ const enabledList = ALL_COMPOSABLES.filter((c) => isComposableEnabled(composablesConfig, c)).map((c) => {
73
+ if (c === "client") return "useFronticClient";
74
+ return `useFrontic${c.charAt(0).toUpperCase() + c.slice(1)}`;
75
+ });
57
76
  console.warn(
58
77
  `
59
78
  [@frontic/nuxt] Frontic client not found at .frontstack/generated-client.ts
@@ -66,44 +85,88 @@ frontic: { composables: false }
66
85
  nuxt.hook("prepare:types", ({ tsConfig }) => {
67
86
  tsConfig.compilerOptions ||= {};
68
87
  tsConfig.compilerOptions.paths ||= {};
69
- tsConfig.compilerOptions.paths["@frontstack/*"] = ["./.frontstack/*"];
88
+ tsConfig.compilerOptions.paths["@frontic/stack/*"] = ["../.frontstack/*"];
70
89
  });
71
- if (anyImplementedEnabled) {
90
+ if (anyComposableEnabled) {
72
91
  const composablesDir = resolve(runtimeDir, "composables");
73
92
  const utilsDir = resolve(runtimeDir, "utils");
74
- addImports([
75
- { name: "LISTING_QUERY_KEYS", from: join(composablesDir, "listings") },
76
- { name: "fetchListingQuery", from: join(composablesDir, "listings") },
77
- { name: "createCacheKey", from: join(composablesDir, "listings") }
78
- ]);
79
- addImports([{ name: "useFronticListing", from: join(composablesDir, "useFronticListing") }]);
80
- addImports([
81
- { name: "makeEqualsFilter", from: join(utilsDir, "filter-helpers") },
82
- { name: "makeLogicalFilter", from: join(utilsDir, "filter-helpers") },
83
- { name: "manageFilter", from: join(utilsDir, "filter-helpers") },
84
- { name: "removeFilter", from: join(utilsDir, "filter-helpers") },
85
- { name: "hasFilter", from: join(utilsDir, "filter-helpers") },
86
- { name: "getFilterValues", from: join(utilsDir, "filter-helpers") }
87
- ]);
88
- addImports([
89
- { name: "makeFilterState", from: join(utilsDir, "state-helpers") },
90
- { name: "processAvailableFilters", from: join(utilsDir, "state-helpers") },
91
- { name: "processAvailableSorts", from: join(utilsDir, "state-helpers") },
92
- { name: "applyFilterConfig", from: join(utilsDir, "state-helpers") },
93
- { name: "countActiveFilters", from: join(utilsDir, "state-helpers") },
94
- { name: "parseSortString", from: join(utilsDir, "state-helpers") },
95
- { name: "isSortAllowed", from: join(utilsDir, "state-helpers") }
96
- ]);
93
+ if (clientEnabled) {
94
+ addImports([{ name: "useFronticClient", from: join(composablesDir, "useFronticClient") }]);
95
+ }
96
+ if (blockEnabled) {
97
+ addImports([
98
+ { name: "useFronticBlock", from: join(composablesDir, "useFronticBlock") },
99
+ { name: "BLOCK_QUERY_KEYS", from: join(composablesDir, "blocks") },
100
+ { name: "fetchBlockQuery", from: join(composablesDir, "blocks") },
101
+ { name: "createBlockCacheKey", from: join(composablesDir, "blocks") }
102
+ ]);
103
+ }
104
+ if (listingEnabled) {
105
+ addImports([
106
+ { name: "useFronticListing", from: join(composablesDir, "useFronticListing") },
107
+ { name: "LISTING_QUERY_KEYS", from: join(composablesDir, "listings") },
108
+ { name: "fetchListingQuery", from: join(composablesDir, "listings") },
109
+ { name: "createCacheKey", from: join(composablesDir, "listings") }
110
+ ]);
111
+ }
112
+ if (searchEnabled) {
113
+ addImports([{ name: "useFronticSearch", from: join(composablesDir, "useFronticSearch") }]);
114
+ if (!listingEnabled) {
115
+ addImports([
116
+ { name: "LISTING_QUERY_KEYS", from: join(composablesDir, "listings") },
117
+ { name: "fetchListingQuery", from: join(composablesDir, "listings") },
118
+ { name: "createCacheKey", from: join(composablesDir, "listings") }
119
+ ]);
120
+ }
121
+ addImports([
122
+ { name: "makeEqualsFilter", from: join(utilsDir, "filter-helpers") },
123
+ { name: "makeLogicalFilter", from: join(utilsDir, "filter-helpers") },
124
+ { name: "manageFilter", from: join(utilsDir, "filter-helpers") },
125
+ { name: "removeFilter", from: join(utilsDir, "filter-helpers") },
126
+ { name: "hasFilter", from: join(utilsDir, "filter-helpers") },
127
+ { name: "getFilterValues", from: join(utilsDir, "filter-helpers") },
128
+ { name: "makeFilterState", from: join(utilsDir, "state-helpers") },
129
+ { name: "processAvailableFilters", from: join(utilsDir, "state-helpers") },
130
+ { name: "processAvailableSorts", from: join(utilsDir, "state-helpers") },
131
+ { name: "applyFilterConfig", from: join(utilsDir, "state-helpers") },
132
+ { name: "countActiveFilters", from: join(utilsDir, "state-helpers") },
133
+ { name: "parseSortString", from: join(utilsDir, "state-helpers") },
134
+ { name: "isSortAllowed", from: join(utilsDir, "state-helpers") }
135
+ ]);
136
+ }
137
+ if (pageEnabled) {
138
+ addImports([
139
+ { name: "useFronticPage", from: join(composablesDir, "useFronticPage") },
140
+ { name: "PAGE_QUERY_KEYS", from: join(composablesDir, "pages") },
141
+ { name: "fetchPageQuery", from: join(composablesDir, "pages") },
142
+ { name: "createPageCacheKey", from: join(composablesDir, "pages") }
143
+ ]);
144
+ }
145
+ if (contextEnabled) {
146
+ addImports([{ name: "useFronticContext", from: join(composablesDir, "useFronticContext") }]);
147
+ }
97
148
  }
98
149
  nuxt.options.runtimeConfig.public.frontic = {
99
150
  hasFronticClient,
151
+ proxyPath,
152
+ contextDomain,
153
+ contextCookieName,
154
+ contextCookieMaxAge,
155
+ disableContext,
156
+ redirectOn301,
157
+ throwOn404,
100
158
  composables: {
159
+ block: blockEnabled,
101
160
  listing: listingEnabled,
161
+ search: searchEnabled,
102
162
  page: pageEnabled,
103
- block: blockEnabled,
104
- context: contextEnabled
163
+ context: contextEnabled,
164
+ client: clientEnabled
105
165
  }
106
166
  };
167
+ nuxt.options.runtimeConfig.frontic = {
168
+ fetchApiSecret
169
+ };
107
170
  const componentsPath = await resolvePath(COMPONENT_DIR_PATH);
108
171
  addComponentsDir(
109
172
  {
@@ -128,16 +191,14 @@ frontic: { composables: false }
128
191
  priority: 1
129
192
  });
130
193
  } catch (err) {
131
- if (err instanceof Error)
132
- console.warn("Module error: ", err.message);
194
+ if (err instanceof Error) console.warn("Module error: ", err.message);
133
195
  }
134
196
  })
135
197
  );
136
198
  } catch (err) {
137
- if (err instanceof Error)
138
- console.warn(err.message);
199
+ if (err instanceof Error) console.warn(err.message);
139
200
  }
140
201
  }
141
202
  });
142
203
 
143
- export { module as default };
204
+ export { module$1 as default };
File without changes
@@ -0,0 +1,31 @@
1
+ function unwrapRef(ref) {
2
+ return typeof ref === "object" && ref !== null && "value" in ref ? ref.value : ref;
3
+ }
4
+ export const BLOCK_QUERY_KEYS = {
5
+ root: ["blocks"],
6
+ block: (blockName) => [...BLOCK_QUERY_KEYS.root, blockName],
7
+ detail: (blockName, key, contextKey) => [...BLOCK_QUERY_KEYS.block(blockName), key, contextKey ?? "default"]
8
+ };
9
+ export function fetchBlockQuery(config) {
10
+ return {
11
+ key: () => {
12
+ const key = unwrapRef(config.key);
13
+ const contextKey = unwrapRef(config.contextKey);
14
+ return BLOCK_QUERY_KEYS.detail(config.name, key, contextKey);
15
+ },
16
+ query: async () => {
17
+ const { useFronticClient } = await import("./useFronticClient.js");
18
+ const client = useFronticClient();
19
+ const key = unwrapRef(config.key);
20
+ const contextKey = unwrapRef(config.contextKey);
21
+ const contextDomain = unwrapRef(config.contextDomain);
22
+ const requestUrl = unwrapRef(config.requestUrl);
23
+ return await client.block(config.name, key, { contextKey, contextDomain, requestUrl });
24
+ },
25
+ staleTime: config.staleTime ?? 1e3 * 60 * 5
26
+ // 5 minutes default
27
+ };
28
+ }
29
+ export function createBlockCacheKey(keyArray) {
30
+ return keyArray.map((part) => typeof part === "object" ? JSON.stringify(part) : String(part)).join("-");
31
+ }
@@ -1,2 +1,9 @@
1
+ export { useFronticClient } from "./useFronticClient.js";
2
+ export { useFronticSearch } from "./useFronticSearch.js";
1
3
  export { useFronticListing } from "./useFronticListing.js";
2
4
  export { fetchListingQuery, LISTING_QUERY_KEYS, createCacheKey } from "./listings.js";
5
+ export { useFronticBlock } from "./useFronticBlock.js";
6
+ export { fetchBlockQuery, BLOCK_QUERY_KEYS, createBlockCacheKey } from "./blocks.js";
7
+ export { useFronticPage } from "./useFronticPage.js";
8
+ export { fetchPageQuery, PAGE_QUERY_KEYS, createPageCacheKey } from "./pages.js";
9
+ export { useFronticContext } from "./useFronticContext.js";
@@ -13,26 +13,32 @@ export const LISTING_QUERY_KEYS = {
13
13
  export function fetchListingQuery(config) {
14
14
  return {
15
15
  key: () => {
16
- const params = unwrapRef(config.parameters);
17
- const query = unwrapRef(config.query);
16
+ const params = unwrapRef(config.params);
17
+ const query = unwrapRef(config.query) ?? {};
18
18
  const page = unwrapRef(config.page);
19
19
  const queryWithPage = page ? { ...query, page } : query;
20
- return LISTING_QUERY_KEYS.detail(config.listingName, params, queryWithPage);
20
+ return LISTING_QUERY_KEYS.detail(config.name, params, queryWithPage);
21
21
  },
22
22
  query: async () => {
23
- const params = unwrapRef(config.parameters);
24
- const query = unwrapRef(config.query);
23
+ const params = unwrapRef(config.params);
24
+ const query = unwrapRef(config.query) ?? {};
25
25
  const contextKey = unwrapRef(config.contextKey);
26
+ const contextDomain = unwrapRef(config.contextDomain);
27
+ const requestUrl = unwrapRef(config.requestUrl);
26
28
  const page = unwrapRef(config.page);
27
29
  const queryWithPage = page ? { ...query, page } : query;
28
30
  try {
29
- const { default: client } = await import("@frontstack/generated-client");
30
- return await client.listing(config.listingName, params, {
31
+ const { useFronticClient } = await import("./useFronticClient.js");
32
+ const client = useFronticClient();
33
+ const result = await client.listing(config.name, params, {
31
34
  query: queryWithPage,
32
- contextKey
35
+ contextKey,
36
+ contextDomain,
37
+ requestUrl
33
38
  });
39
+ return result;
34
40
  } catch (error) {
35
- console.error(`[@frontic/nuxt] Failed to fetch listing "${config.listingName}". Make sure the Frontic client is generated.`);
41
+ console.error(`[@frontic/nuxt] Failed to fetch listing "${String(config.name)}". Make sure the Frontic client is generated.`);
36
42
  throw error;
37
43
  }
38
44
  },
File without changes
@@ -0,0 +1,31 @@
1
+ function unwrapRef(ref) {
2
+ return typeof ref === "object" && ref !== null && "value" in ref ? ref.value : ref;
3
+ }
4
+ export const PAGE_QUERY_KEYS = {
5
+ root: ["pages"],
6
+ page: (slug) => [...PAGE_QUERY_KEYS.root, slug],
7
+ detail: (slug, contextKey) => [...PAGE_QUERY_KEYS.page(slug), contextKey ?? "default"]
8
+ };
9
+ export function fetchPageQuery(config) {
10
+ return {
11
+ key: () => {
12
+ const slug = unwrapRef(config.slug);
13
+ const contextKey = unwrapRef(config.contextKey);
14
+ return PAGE_QUERY_KEYS.detail(slug, contextKey);
15
+ },
16
+ query: async () => {
17
+ const { useFronticClient } = await import("./useFronticClient.js");
18
+ const client = useFronticClient();
19
+ const slug = unwrapRef(config.slug);
20
+ const contextKey = unwrapRef(config.contextKey);
21
+ const contextDomain = unwrapRef(config.contextDomain);
22
+ const requestUrl = unwrapRef(config.requestUrl);
23
+ return await client.page(slug, { contextKey, contextDomain, requestUrl });
24
+ },
25
+ staleTime: config.staleTime ?? 1e3 * 60 * 5
26
+ // 5 minutes default
27
+ };
28
+ }
29
+ export function createPageCacheKey(keyArray) {
30
+ return keyArray.map((part) => typeof part === "object" ? JSON.stringify(part) : String(part)).join("-");
31
+ }
File without changes
@@ -0,0 +1,31 @@
1
+ import { useQuery } from "@pinia/colada";
2
+ import { fetchBlockQuery } from "./blocks.js";
3
+ export function useFronticBlock(name, key, options) {
4
+ const blockQuery = fetchBlockQuery({
5
+ name,
6
+ key,
7
+ contextKey: options?.contextKey,
8
+ contextDomain: options?.contextDomain,
9
+ requestUrl: options?.requestUrl,
10
+ staleTime: options?.staleTime
11
+ });
12
+ const { data, status, refresh, refetch } = useQuery(blockQuery);
13
+ return {
14
+ /**
15
+ * The block data, typed based on the block name
16
+ */
17
+ block: data,
18
+ /**
19
+ * Query status: 'pending' | 'error' | 'success'
20
+ */
21
+ status,
22
+ /**
23
+ * Manually refresh the block data (uses cache if valid)
24
+ */
25
+ refresh,
26
+ /**
27
+ * Force a fresh fetch of the block data, bypassing cache
28
+ */
29
+ refetch
30
+ };
31
+ }