@eldrajs/theme-nuxt 0.0.0 → 0.2.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 (45) hide show
  1. package/CHANGELOG.md +255 -0
  2. package/LICENSE +21 -0
  3. package/README.md +323 -1
  4. package/dist/module.cjs +5 -0
  5. package/dist/module.d.mts +56 -0
  6. package/dist/module.d.ts +56 -0
  7. package/dist/module.json +12 -0
  8. package/dist/module.mjs +320 -0
  9. package/dist/runtime/catalog.d.ts +119 -0
  10. package/dist/runtime/catalog.js +226 -0
  11. package/dist/runtime/commerce.d.ts +68 -0
  12. package/dist/runtime/commerce.js +40 -0
  13. package/dist/runtime/composables/useEldraPage.d.ts +17 -0
  14. package/dist/runtime/composables/useEldraPage.js +229 -0
  15. package/dist/runtime/designTokens.d.ts +59 -0
  16. package/dist/runtime/designTokens.js +55 -0
  17. package/dist/runtime/drafts.d.ts +3 -0
  18. package/dist/runtime/drafts.js +89 -0
  19. package/dist/runtime/links.d.ts +32 -0
  20. package/dist/runtime/links.js +132 -0
  21. package/dist/runtime/locale.d.ts +21 -0
  22. package/dist/runtime/locale.js +9 -0
  23. package/dist/runtime/localeState.d.ts +52 -0
  24. package/dist/runtime/localeState.js +48 -0
  25. package/dist/runtime/locales.d.ts +186 -0
  26. package/dist/runtime/locales.js +109 -0
  27. package/dist/runtime/messages.d.ts +59 -0
  28. package/dist/runtime/messages.js +66 -0
  29. package/dist/runtime/origins.d.ts +18 -0
  30. package/dist/runtime/origins.js +28 -0
  31. package/dist/runtime/plugin.d.ts +3 -0
  32. package/dist/runtime/plugin.js +83 -0
  33. package/dist/runtime/resolveRoute.d.ts +81 -0
  34. package/dist/runtime/resolveRoute.js +166 -0
  35. package/dist/runtime/routePath.d.ts +31 -0
  36. package/dist/runtime/routePath.js +7 -0
  37. package/dist/runtime/siteIconAssets.d.ts +19 -0
  38. package/dist/runtime/siteIconAssets.js +29 -0
  39. package/dist/runtime/siteIcons.d.ts +74 -0
  40. package/dist/runtime/siteIcons.js +96 -0
  41. package/dist/runtime/staticRoutes.d.ts +14 -0
  42. package/dist/runtime/staticRoutes.js +26 -0
  43. package/dist/types.d.mts +7 -0
  44. package/dist/types.d.ts +7 -0
  45. package/package.json +60 -2
package/CHANGELOG.md ADDED
@@ -0,0 +1,255 @@
1
+ # @eldrajs/theme-nuxt changelog
2
+
3
+ Hand-maintained: every change a consumer can see gets a line under Unreleased in the same change.
4
+ Release-please writes the generated notes from commit messages and does not replace this.
5
+
6
+ ## Unreleased
7
+
8
+ - The runtime registers the theme's own id (`manifest.theme.id`) with `registerBlockFields`, and
9
+ the draft projection validates slots against bare block ids when a published entry's
10
+ `schemaApiId` is `<themeId>:<apiId>`. Route-template targets (a merchant's own schema) and
11
+ `catalog:*` are unchanged. The theme must declare `eldra.themeId` in `package.json` (see the
12
+ `@eldrajs/vite-plugin-theme` changelog).
13
+
14
+ - **Site icons, set in Studio and rendered by the media worker.** A fifth fail-soft read, `GET
15
+ /site/v1/site-icons` (`readSiteIcons`, `./runtime/siteIcons.ts`), answers the site's icon (a
16
+ media-library raster, square, at least 512 px), background colour, theme colour, short name and
17
+ `icons`, the URLs of the variants the media worker renders (`null` when no icon is set). When an
18
+ icon is set, `nuxi generate` writes only `site.webmanifest` into the static output (on both
19
+ nitro `compiled` and `prerender:done`) and adds `<link rel="icon" type="image/png"
20
+ sizes="32x32">`, `<link rel="apple-touch-icon">`, `<link rel="manifest">` and `<meta
21
+ name="theme-color">` to every page; the icon tags point at the media URLs. No image is fetched or
22
+ processed at build time and no `favicon.ico` is generated (the theme's own `public/favicon.ico`
23
+ stays the root fallback). The theme colour defaults to the primary design token and the short name
24
+ to the site name. With no icon set or a failed read, nothing is written or tagged and the theme's
25
+ `public/` files stay. The icons replace the theme's own icon, manifest and `theme-color` tags in
26
+ `app.head`. `sharp` was removed (an earlier draft of this feature generated the files with it):
27
+ native image processing in every theme build was fragile, and the media worker renders the sizes.
28
+ Documented in `docs/themes.md` (Site icons).
29
+
30
+ - **The deployed site now carries Studio's design-token overrides, not only the open preview.** A
31
+ fourth fail-soft read, alongside the store's currency, its locales and the theme-message overrides
32
+ — `GET /site/v1/design-tokens`, same client, same retry policy, absent gateway or any error
33
+ answering `null` with one warning (`readDesignTokens`, `./runtime/designTokens.ts`) — answers the
34
+ organisation's resolved catalog (the theme's own tokens with the site's overrides already
35
+ applied, re-validated through `@eldrajs/theme-core`'s `normalizeThemeDesignTokens`). The result is
36
+ what `virtual:eldra/tokens.css` now generates its CSS from — `@eldrajs/vite-plugin-theme`'s
37
+ `eldraTheme()` gained a `resolveTokens` option for exactly this, set once the module's own
38
+ platform read settles — and what the runtime plugin seeds `context.designTokens` from
39
+ (`runtimeConfig.public.eldra.designTokens`, carried the same way `commerce`/`locales` are), so a
40
+ generated static artifact's CSS and its runtime context both reflect the override through SSR,
41
+ prerender and hydration. The preview bridge path (`applyResolvedDesignTokens`) is unchanged.
42
+
43
+ - **The theme's message catalogue is now merged with the platform's overrides at build time.** A
44
+ third fail-soft read, alongside the store's currency and locales — `GET /site/v1/theme-messages`,
45
+ same client, same retry policy, absent gateway or any error answering `null` with one warning
46
+ (`readThemeMessages`, `./runtime/messages.ts`) — is merged over the manifest's own `messages`
47
+ block and resolved over the organisation's locales (falling back to the theme's own locales/
48
+ default locale when those are unknown) via `@eldrajs/theme-core/i18n`'s
49
+ `mergeMessageCatalogues`/`resolveMessageCatalogue`. The result is what `virtual:eldra/messages`
50
+ now serves — `@eldrajs/vite-plugin-theme`'s `eldraTheme()` gained a `resolveMessages` option for
51
+ exactly this, set once the module's own platform read settles — and what the runtime plugin
52
+ assigns to `context.messages`, so the starter's `vue-i18n` plugin (next) reads one source for
53
+ every organisation locale's full key set, gateway or none.
54
+
55
+ - **Fix: a `link` field's mega-menu/footer column heading no longer vanishes on a locale that never
56
+ got its own `group`.** The runtime plugin now resolves the organisation's content locales before
57
+ building the gateway client, and hands it `defaultLocale` (the store's own `locales.default`,
58
+ falling back to the resolved routing default for a single-locale site) — `@eldrajs/theme-core`'s
59
+ per-field link fallback (see its changelog) then fills an untranslated field of a `link` node from
60
+ the default locale's node instead of leaving it empty.
61
+
62
+ - **`eldra.retry` — how hard a build tries again when the gateway says "not now".**
63
+ `{ attempts, baseDelayMs, maxDelayMs }`, defaulting to five attempts with exponential backoff and
64
+ jitter while honouring `Retry-After`; `{ attempts: 0 }` turns it off. It reaches every gateway read
65
+ a site makes: this module's own `prerender:routes` reads and the platform read behind
66
+ `commerce`/`locales`, and the client the runtime plugin builds for the theme. It is also written to
67
+ the public runtime config (`useRuntimeConfig().public.eldra.retry`), so a storefront that builds
68
+ its own `@eldrajs/sdk` client for commerce reads can hand it the same policy. Nothing has to be set
69
+ for the default behaviour, which is what keeps a `nuxi generate` of a large site alive through the
70
+ gateway's per-minute rate limit — see the README's "When the gateway rate-limits the build".
71
+
72
+ - **Category pages.** A route template whose `schemaApiId` is `catalog:category` is now resolved
73
+ against the store's category tree. Its pattern ends in a catch-all parameter and its `slugField`
74
+ is `path` (`/categories/:path*`), and a category is addressed by its **canonical path** — the
75
+ slugs of its ancestors, root first, then its own (`/categories/billinn/bilstolar`). There is no
76
+ read that takes a path, so the whole category list is read and the path's segments are walked down
77
+ the tree by slug; **only the canonical path resolves**, so a leaf on its own, a wrong parent and a
78
+ trailing extra segment are each the not-found shell rather than a redirect. `useEldraPage()`'s
79
+ `catalog` is `{ kind: 'category', slug, path }` there — the leaf's slug and the whole path — and
80
+ the resolved entry carries the binding paths `slug`, `title`, `path`, `ancestors[]` and
81
+ `children[]`, plus `description` (plain text, like a collection's) and `productCount` only when the catalog read
82
+ carried them (the category model may have neither, and an invented key would bind a template to an
83
+ empty value on every site without one).
84
+ - `prerender:routes` adds one route per **canonical** category path, times the site's locales, the
85
+ same way it fans out collections. A category the list cannot place — no slug, or a parent the list
86
+ does not hold — gets no route, and neither does the subtree under it: a path built over that gap
87
+ addresses a different category.
88
+ - A `link` field pointing at a **category** now resolves to the canonical path. The category targets
89
+ are read as one whole tree rather than in `id:in:` chunks, because a chunked read keyed on the
90
+ wanted ids alone discards the ancestors the path is built from; a target the tree cannot place
91
+ carries no path and renders as plain text rather than as a link the site answers with its
92
+ not-found shell. A reader with no `listCategories` resolves none, exactly as before.
93
+
94
+ - **A route the gateway could not be asked about is no longer rendered as the not-found page.**
95
+ `useEldraPage()`'s resolution failure now travels with the resolution itself rather than in the
96
+ calling composable's own `error` ref: `useAsyncData` keeps one entry per route key and runs only
97
+ the **first** caller's handler, so a theme that calls `useEldraPage()` twice on a page (a plugin
98
+ for the catalog route beside the page component — which the starter does) saw the failure in one
99
+ of them and an ordinary empty resolution in the other. That is indistinguishable from "there is
100
+ no such page", so a transient gateway failure drew the theme's not-found shell, and `nuxi
101
+ generate` wrote it to disk under a path a visitor can reach, with exit code 0. On the server such
102
+ a route is now answered `500` as well, so Nitro writes no file for it and names it in the
103
+ prerender list (pair it with `nitro.prerender.failOnError` to stop the build — its real exposure is
104
+ about twice the route count, because each page's `_payload.json` is prerendered too and resolves
105
+ the route again). A build with no `ELDRA_GATEWAY_URL` / `ELDRA_ORG_ID` is exempt from **both** the
106
+ status and the error: there every read fails by definition, so such a route resolves to the plain
107
+ empty route and the theme renders its static shell, exactly as it did before. The resolved route's
108
+ new optional `error` field is set only for a failure — a genuine not-found (no match, or a 404 from
109
+ the gateway) carries none, exactly as before — and `useEldraPage()`'s `error` is now typed
110
+ `ComputedRef<string | null>`, which is what it has always been at runtime.
111
+
112
+ - **Locale-prefixed routing.** `runtimeConfig.public.eldra` now carries `locales` — the
113
+ organisation's own `{ default, supported }` record, read once during the build, or `null` — and
114
+ the module serves the default locale at `/` with every other supported locale under a path
115
+ prefix (`/is-IS/products/ash-glaze-mug`). The first path segment selects the locale, the rest of
116
+ the path resolves as it does unprefixed, and every gateway read for that page carries that
117
+ `locale`; `/<default-locale>/…` is not generated and resolves as an unknown path. Path segments
118
+ are not translated — a page keeps its default-locale slug under every prefix — so the prerender
119
+ pass lists each content path once and writes it once per locale, seeded `cart`/`wishlist`/`search`
120
+ pages included. The key's type ships as `StoreLocales` (`@eldrajs/theme-nuxt/locales`, a new
121
+ subpath export beside `./commerce`), a new auto-imported `useEldraLocale()` answers which locale
122
+ the page is and prefixes a destination for it, and the module writes `<html lang>` plus an
123
+ `hreflang` alternate per locale (and `x-default`) itself. `useEldraLocale().name(locale)` is that
124
+ locale's own name for a switcher's label, resolved **on the server** and carried in the payload —
125
+ `Intl.DisplayNames` is ICU data and a renderer and a browser need not have the same of it, so a
126
+ page that let each side compute its own labels would hydrate into a mismatch and repaint.
127
+ `eldra.locale` / `ELDRA_LOCALE` keeps its meaning as an override of the **default** locale: naming a supported locale moves it to `/`,
128
+ naming anything else changes no URL and is still forwarded on every read. An organisation with no
129
+ locales, a site built without gateway credentials and a failed read all behave exactly as every
130
+ site did before this: one unprefixed site, no switcher — and only the failed read prints a
131
+ warning, because the other two are not mistakes.
132
+
133
+ - `eldra.templates` accepts static **page** seeds beside the route-template seeds it already took —
134
+ `{ page: { slug }, title, blocks }`, where an entry of `blocks` is either a block
135
+ (`{ apiId, data, required? }`) or a placement of the site's shared header or footer
136
+ (`{ role: 'header' | 'footer' }`). See `@eldrajs/vite-plugin-theme`'s changelog for the grammar;
137
+ this module only widens the option's type and forwards it.
138
+
139
+ - `useEldraPage` no longer replaces the page with an error alert for the first 401 of a preview
140
+ read. A preview token is one hash per organization, so minting one anywhere else revokes the one
141
+ a live preview is using; the editor answers `theme:request-failed` by minting again and
142
+ re-sending `editor:init`, usually within a second, and reporting that first failure blanked the
143
+ page for exactly that second — and, because every keystroke re-reads the drafts, produced one
144
+ alert per keystroke with the page gone. The first failure is held back (what is on screen stays,
145
+ rather than collapsing to the not-found shell) and the error is reported once a 401 arrives on a
146
+ *newer* token — the retry failed too — or after a 10s grace window, so a preview nobody is going
147
+ to recover still says so.
148
+
149
+ - `runtimeConfig.public.eldra` now carries `commerce` — `{ currency, taxInclusivePricing,
150
+ defaultTaxRate }`, or `null` — read once from the organisation during the build, so a prerendered
151
+ page's prices are formatted in the currency the store actually sells in instead of one the theme
152
+ guessed from the content locale. The key's type ships with the package as `StoreCommerce`, so a
153
+ theme reading it does not hand-write the record (`@eldrajs/theme-nuxt/commerce`, a new subpath
154
+ export — the package root's declarations are generated by `nuxt-module-build` and carry the module
155
+ and its options only). A store with no commerce settings, a site built
156
+ without gateway credentials and a read that failed all land on `null` with a single warning
157
+ (`[eldra] the store publishes no currency — prices render as plain numbers`, plus the cause in
158
+ brackets when the read itself failed); the build never fails over it. The module adds no
159
+ environment override: the platform is the source, and a theme-side currency could only relabel
160
+ real amounts. See the README for what a theme should do with `null`.
161
+
162
+ - The batched target reads behind a `link` field now page to the end of a result rather than
163
+ stopping at the first hundred rows, and the category read asks for the ids it actually needs
164
+ (`id:in:`, in chunks, like the product and collection reads) and keeps only those. A target lost
165
+ past a page boundary renders as a link with no destination, which is indistinguishable from a
166
+ deleted one; and a category tree read whole would otherwise put every category a site has into
167
+ the prerendered payload of every page that links to one.
168
+
169
+ - The walk that finds which targets a page names reaches far deeper before it gives up, and says so
170
+ when it does — naming the entry — instead of returning silently. The old bound could be reached
171
+ by a link nested inside a composite inside a list, and the only symptom was a link that quietly
172
+ had no destination.
173
+
174
+ - A `link` field's destinations now resolve to real hrefs on a generated site. Route resolution
175
+ fills the theme context's `links` slice from the page and route-template lists it already reads,
176
+ plus one batched read per target type for the objects the resolved document's blocks name — all
177
+ inside the same `useAsyncData` call, so a `nuxi generate` build bakes every href into the page's
178
+ payload and a prerendered page resolves them with no client request. A read that fails leaves
179
+ those targets unknown: the links pointing at them render unlinked rather than failing the page.
180
+ `useEldraPage()` also returns the slice as `links`.
181
+
182
+ - Fix: on a **generated** site in a browser, `useEldraPage()` now resolves routes from the build
183
+ instead of the gateway. A path Nuxt prerendered (its app manifest ships the list) is read back out
184
+ of the route payload Nuxt has already loaded, so a client navigation between two prerendered
185
+ routes renders in the same tick — `pending` never true, no gateway read — and a path the build
186
+ does not contain is the not-found state immediately, instead of after listing every page and every
187
+ route template to reach the same answer. Studio preview (the route may be a draft), `nuxi dev` and
188
+ an SSR deployment all keep the dynamic resolution they had. New pages need a rebuild to become
189
+ routes, which is what publishing already triggers.
190
+
191
+ - Fix: a page component now resolves the route **it** is being created for. `useRoute()` inside a
192
+ package resolves to Nuxt's app-level route, which `NuxtPage` syncs only after the destination
193
+ page's `<Suspense>` has resolved — and a page's blocks are created inside that pending branch. So
194
+ on every client navigation the destination page ran its `setup` under the route it was replacing:
195
+ it rendered the **departing** page's blocks, ran every read on them a second time, and only then
196
+ swapped to its own content. `useEldraPage()` now reads the router's committed route and pins it
197
+ for the page's lifetime (the identity `eldraRouteKey` already gives `<NuxtPage>`); called outside
198
+ a component — for a plugin's route context — it follows the committed route directly.
199
+
200
+ - Fix: a page served at a URL that differs from the one it was prerendered at only by a trailing
201
+ slash is no longer built twice. A generated site is `<route>/index.html`, and a static host may
202
+ answer `/products/ash-glaze-mug` with a redirect to `/products/ash-glaze-mug/`; Nuxt then
203
+ re-navigates between the two paths while the page hydrates, and the catch-all route's default key
204
+ differs between them — so the page, and every block on it, was destroyed and created again,
205
+ running each block's `setup` (and every storefront read in it) a second time. `useEldraPage()` now
206
+ watches the **canonical** path, the one its async-data key already used, and the module
207
+ auto-imports `eldraRouteKey` for a theme to give `<NuxtPage>` (`:page-key="eldraRouteKey"`) so the
208
+ page survives that move. Themes scaffolded before this should add the `page-key` binding; the
209
+ starter does.
210
+
211
+ - Feat: `useEldraPage()` exposes `reusableComponentProjection` on a **route-template** route. Core
212
+ attaches the projection to whichever document the read returned, and a route resolves exactly one
213
+ of the two — a static route a `page`, a dynamic one a `template` — so the composable now reads the
214
+ page's, else the template's. It is a fallback and never a merge: `@eldrajs/theme-core` refuses a
215
+ projection carrying a binding the rendered document does not place, so a page's projection on a
216
+ template route would fail the layout closed. Preview drafts already reach a placement inside a
217
+ template the same way they reach one inside a page; nothing there needed lifting. The public
218
+ route-template read carries no projection — it is pre-expanded and redacted like a public page
219
+ read — so a prerendered template route renders its header and footer with no component or site
220
+ identity anywhere in the HTML or the payload.
221
+ - Fix: a blank locale is no longer forwarded to the gateway. A site that configures none carries
222
+ `""` — that is what `runtimeConfig.public.eldra.locale` holds, and what an unset `ELDRA_LOCALE`
223
+ becomes — which went out as `?locale=` on every read and came back a 400 from the collection
224
+ lookup. Every boundary that forwards a locale (`useEldraPage()`, route resolution, the catalog
225
+ reads, the module's `prerender:routes` pass and the public runtime config it writes) now treats
226
+ a blank or whitespace-only locale as no locale at all, so the request carries no `locale`
227
+ parameter and the gateway serves the site's default. A blank `locale` from the Studio preview
228
+ bridge falls back to the configured one instead of shadowing it.
229
+
230
+ - Removed the unused `catalogTemplateRoutes` helper from the runtime (never exported from the
231
+ module's public entry, and `prerender:routes` cannot use it: it lists the catalog once per
232
+ **kind** and maps once per template, so a list-and-map-in-one call would refetch the whole
233
+ catalog for every template). Compose `listCatalogDocs` + `catalogDocRoutes` instead.
234
+
235
+ - New `eldra.templates` and `eldra.templateRoles` options, forwarded to
236
+ `@eldrajs/vite-plugin-theme`: the default page templates a site is seeded with on its first
237
+ deploy, and the block data behind the `header`/`footer` roles those seeds place. See that
238
+ package's changelog for the seed shape and its validation.
239
+
240
+ - Feat: catalog-backed route templates render. A route template whose `schemaApiId` is
241
+ `catalog:product` or `catalog:collection` now resolves its object **by slug** through the public
242
+ catalog instead of a CMS entry, and `useEldraPage()` returns a new `catalog`
243
+ (`{ kind: 'product' | 'collection'; slug }`, `null` for every other route) beside `page`,
244
+ `template` and `entry`. The bound `entry` is `{ id, data }` where `data` holds the documented
245
+ binding paths — product: `slug`, `title`, `description`, `status`, `categoryId`, `tags`,
246
+ `variants[]` (`sku`, `price`, `compareAtPrice`, `optionValues[]`), `images[]` (`url`, `alt`);
247
+ collection: `slug`, `title`, `description`, `productCount`, `image` (`url`, `alt`) — every key
248
+ always present, whatever the response omitted. A slug the catalog does not know renders the
249
+ theme's not-found shell, not its error branch.
250
+ - Feat: generation prerenders one route per active catalog object, paging the public list endpoints
251
+ at 100 per page (products filtered to `status:eq:ACTIVE` server-side, and any inactive record the
252
+ gateway still reports dropped client-side). A slug that cannot become a route, or one that
253
+ collides with a route already generated, is skipped with an `[eldra] skipped …` warning naming it
254
+ and the build continues — merchant catalog data must not be able to fail a whole deploy.
255
+ - First release under the `@eldrajs` scope, moved from the private `@eldra/theme-nuxt` package.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eldra Tech
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 CHANGED
@@ -1,3 +1,325 @@
1
1
  # @eldrajs/theme-nuxt
2
2
 
3
- Placeholder that reserved the name for trusted publishing. Install a real version.
3
+ Nuxt module for Eldra themes: wires `@eldrajs/vite-plugin-theme`, the gateway client, draft
4
+ overlays and the Studio preview bridge into a Nuxt 4 site. It prerenders every published page and
5
+ dynamic route from the CMS, writes the generated `.eldra/manifest.json` and the CSP
6
+ `frame-ancestors` header the Studio preview bridge needs, and exposes `useEldraPage` for resolving
7
+ the current route's page/template/entry.
8
+
9
+ ```bash
10
+ pnpm add @eldrajs/theme-nuxt
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ // nuxt.config.ts
17
+ export default defineNuxtConfig({
18
+ modules: ['@eldrajs/theme-nuxt'],
19
+ eldra: {
20
+ gatewayUrl: process.env.ELDRA_GATEWAY_URL,
21
+ orgId: process.env.ELDRA_ORG_ID,
22
+ studioOrigins: ['https://acme.eldracms.com'],
23
+ },
24
+ });
25
+ ```
26
+
27
+ ```vue
28
+ <script setup lang="ts">
29
+ import { EldraLayout } from '@eldrajs/theme-vue';
30
+ const { page, layout, blocks } = useEldraPage();
31
+ </script>
32
+ <template>
33
+ <main>
34
+ <EldraLayout v-if="page && layout" :layout="layout" :blocks="blocks" />
35
+ </main>
36
+ </template>
37
+ ```
38
+
39
+ ## `eldraRouteKey` — required on your `<NuxtPage>`
40
+
41
+ Give your `app.vue` the route key this module auto-imports:
42
+
43
+ ```vue
44
+ <!-- app/app.vue -->
45
+ <template>
46
+ <NuxtPage :page-key="eldraRouteKey" />
47
+ </template>
48
+ ```
49
+
50
+ This is not cosmetic on a **generated** site. `nuxi generate` writes each route as
51
+ `<route>/index.html`, and static hosts disagree about which URL that file lives at — some serve
52
+ `/products/ash-glaze-mug`, others answer it with a redirect to `/products/ash-glaze-mug/`. When the
53
+ URL the visitor lands on differs from the path the page was prerendered at, Nuxt re-navigates
54
+ between the two while the page hydrates; a catch-all page's default route key interpolates the
55
+ splat parameter, so those two spellings key differently and Vue destroys and re-creates the page —
56
+ and every block on it. Each block's `setup` then runs twice, so every read a commerce block makes
57
+ goes out twice. Only one of the two instances ever mounts, so nothing in the DOM gives it away.
58
+
59
+ `eldraRouteKey(route)` keys by the canonical path — the same identity `useEldraPage()` resolves
60
+ content under — so the move is a no-op. Themes scaffolded before this was added should add the
61
+ binding.
62
+
63
+ ## Route resolution on a generated site
64
+
65
+ On a **static build in a browser**, `useEldraPage()` resolves routes from the build, not from the
66
+ gateway. `nuxi generate` ships the list of paths it prerendered (Nuxt's app manifest,
67
+ `/_nuxt/builds/meta/<buildId>.json`), and that list answers both questions the resolver used to ask
68
+ the gateway:
69
+
70
+ - **The path is in the build.** Its page, template and entry are in the `_payload.json` Nuxt's own
71
+ payload plugin loads in `router.beforeResolve`, before the page component exists — so a client
72
+ navigation between two prerendered routes renders the destination in the same tick, with `pending`
73
+ never true and no gateway read at all.
74
+ - **The path is not in the build.** It does not exist: `useEldraPage()` returns the empty route
75
+ (`page === null && template === null`) straight away, so the theme draws its not-found shell
76
+ without the five reads it used to take to conclude the same thing. A route published since the
77
+ build is not in the artifact either — publishing triggers a rebuild, which is what makes the build
78
+ the authority.
79
+
80
+ Three situations keep the old dynamic resolution, and are the reason the manifest is consulted
81
+ rather than assumed:
82
+
83
+ - **Studio preview.** Inside an allowed `studioOrigins` frame the route may be a draft, an
84
+ unpublished page or a path no build has ever contained, so every resolution is live — from the
85
+ first render, before the bridge has even said hello.
86
+ - **`nuxi dev`.** The dev server ships a manifest that prerendered nothing.
87
+ - **An SSR deployment** (`nuxt build` plus a Node server), for the same reason: nothing is in the
88
+ build, so an empty prerendered list means "this build prerendered nothing", never "this route does
89
+ not exist".
90
+
91
+ ### A resolution that **failed** is not a route that is missing
92
+
93
+ The empty route above is an answer: there is no such page. A read the gateway could not answer is
94
+ not, and `useEldraPage()` keeps the two apart — a failed resolution carries `error` on the resolution
95
+ itself (`ResolvedEldraRoute.error`), so `error` is non-null while `page`/`template` are null and a
96
+ theme can draw its error branch instead of its not-found shell. The error lives on the resolution
97
+ rather than inside the composable because `useAsyncData` keeps **one** entry per route key and runs
98
+ only the first caller's handler: a theme that calls `useEldraPage()` twice on a page (a plugin for
99
+ the catalog route beside the page component) would otherwise see the failure in one call and an
100
+ ordinary empty route in the other.
101
+
102
+ **On the server such a route is answered `500`.** Nitro's prerenderer marks a non-200 route failed
103
+ before it writes anything, so a page the gateway could not be asked about is absent from the
104
+ artifact and named in the prerender log, instead of being written as the theme's not-found shell
105
+ under a path a visitor can reach. Pair it with `nitro.prerender.failOnError` if a build must not ship
106
+ without every page — the status alone turns a wrong page into a missing one, and that flag turns a
107
+ missing one into a failed build. Note the real exposure is about twice the route count: with
108
+ `crawlLinks: false` Nitro still prerenders each page's own `_payload.json`, which resolves the route
109
+ again.
110
+
111
+ A build with **no `ELDRA_GATEWAY_URL` / `ELDRA_ORG_ID`** is exempt from both: there every read fails
112
+ by definition, so such a route resolves to the plain empty route with no `error` and the theme
113
+ renders its static shell, which is the whole point of a scaffold build.
114
+
115
+ This is also why `eldraRouteKey` above is required rather than advisory: one page component per
116
+ canonical route is what lets the composable resolve the route its page is being created for. Nuxt
117
+ hands a page its own route through an injection private to Nuxt's app module, which a composable
118
+ shipped in a package cannot reach; `useEldraPage()` therefore reads the router's committed route and
119
+ pins it for the page's lifetime.
120
+
121
+ ## When the gateway rate-limits the build
122
+
123
+ The gateway limits a client to a number of requests per minute. A `generate` of a real site is
124
+ thousands of reads from one address — every page, every route template, every catalog document,
125
+ times the site's locales, and roughly twice over because each page's `_payload.json` resolves its
126
+ route again — so a large build meets that limit routinely. The gateway's answer is `429`; with
127
+ `failOnError` set, one of them used to end the build.
128
+
129
+ **Nothing has to be configured for this.** Every gateway read — this module's own prerender reads,
130
+ the theme's reads at request time, and the platform read behind `commerce`/`locales` — retries an
131
+ idempotent request that answered `429` or `503` (and a dropped connection), honouring `Retry-After`
132
+ and otherwise backing off exponentially with jitter, five attempts including the first. A rate limit
133
+ is waited out rather than fought.
134
+
135
+ The knob exists for a gateway with an unusually narrow limit, or for a build that should fail fast:
136
+
137
+ ```ts
138
+ // nuxt.config.ts
139
+ eldra: {
140
+ // The defaults. `attempts` counts the first request; `{ attempts: 0 }` turns retrying off.
141
+ retry: { attempts: 5, baseDelayMs: 250, maxDelayMs: 5000 },
142
+ }
143
+ ```
144
+
145
+ It is carried in the public runtime config, so a storefront that builds its own `@eldrajs/sdk`
146
+ client for commerce reads can hand it the same policy (`useRuntimeConfig().public.eldra.retry`) —
147
+ the starter does.
148
+
149
+ Two Nitro knobs sit beside it, and neither is this module's to set: `nitro.prerender.concurrency`
150
+ (**1** by default, which is already the gentlest setting — there is nothing to lower unless you have
151
+ raised it) and `nitro.prerender.retry`/`retryDelay` (3 × 500 ms by default), which re-render a route
152
+ whose response was one of ofetch's retryable statuses — 408, 409, 425, 429, 500, 502, 503, 504, and
153
+ so the 500 this module answers a failed resolution with, but not a 404.
154
+
155
+ **The new failure mode is a build that crawls, not one that fails.** A `Retry-After` is honoured up
156
+ to a minute, and `maxDelayMs` caps the _computed_ backoff rather than a wait the gateway asked for,
157
+ so four waits on a limit that keeps asking for a minute is about four minutes on **one** read —
158
+ times Nitro's own re-renders, at `concurrency: 1`, with no output and no error meanwhile. That is
159
+ the intent (a build that waits beats a build that fails), but it is the one thing nobody can
160
+ diagnose from the outside, so `retry: { attempts: 0 }` is the fail-fast lever: one request, and the
161
+ `429` surfaces the way it used to.
162
+
163
+ **The same policy governs reads a shopper triggers**, not only a build: the runtime plugin's client
164
+ serves SSR, a client-side route change and the Studio preview. A visitor who meets the rate limit on
165
+ a client-side navigation therefore waits — up to a minute on one `Retry-After` — where before they
166
+ were shown an error, which for a transient limit is the better of the two. A site that would rather
167
+ fail fast in the browser than wait can set a smaller `attempts`; the prerender reads use the same
168
+ value, so it is one trade-off, not two.
169
+
170
+ ## Catalog-backed route templates
171
+
172
+ A route template whose `schemaApiId` is `catalog:product`, `catalog:collection` or
173
+ `catalog:category` is backed by the store's catalog rather than a CMS schema: the module prerenders
174
+ one route per active product, collection or category, and `useEldraPage()` resolves the object from
175
+ the path.
176
+
177
+ ```vue
178
+ <script setup lang="ts">
179
+ const { template, entry, catalog, layout, blocks } = useEldraPage();
180
+ // catalog is { kind: 'product' | 'collection' | 'category', slug, path? } here, and null on every
181
+ // other route. `path` is set for a category and for nothing else.
182
+ // entry.data carries the binding paths a catalog template addresses —
183
+ // product: slug, title, description, status, categoryId, tags, variants[], images[]
184
+ // collection: slug, title, description, productCount, image
185
+ // category: slug, title, path, ancestors[], children[] (+ description as plain text, and
186
+ // productCount, when the catalog read carries them)
187
+ </script>
188
+ ```
189
+
190
+ A slug the catalog does not know resolves to the empty route, so the theme renders its not-found
191
+ shell. During generation a slug that cannot become a route is skipped with a warning naming it and
192
+ the build continues.
193
+
194
+ ### Categories are nested, and canonical only
195
+
196
+ A category route's pattern ends in a **catch-all** parameter — `/categories/:path*` — and its
197
+ `slugField` is `path`. The parameter matches one or more segments and carries them joined with `/`:
198
+ a category's canonical path is the slugs of its ancestors, root first, then its own
199
+ (`/categories/billinn/bilstolar`).
200
+
201
+ There is no read that takes a path, so the whole category list is read once per request and the
202
+ path's segments are walked down the tree by slug. **Only the canonical path resolves** — a leaf on
203
+ its own, a wrong parent and a trailing extra segment are each the not-found shell rather than a
204
+ redirect — and the prerender pass generates exactly those canonical paths, one per category, times
205
+ the site's locales. A category the list cannot place (no slug, or a parent the list does not hold)
206
+ has no route at all, and neither has the subtree under it.
207
+
208
+ A `link` field pointing at a category resolves through the same path: `collectLinkTargets` reads the
209
+ tree whole for that reason, and a target it cannot place renders as plain text rather than as a link
210
+ to a path the site answers with its not-found shell.
211
+
212
+ `studioOrigins` must be explicit — this module never supplies a broad fallback origin for the
213
+ preview bridge. See [examples/starter-nuxt](../../examples/starter-nuxt) for a full theme and
214
+ [docs/themes.md](../../docs/themes.md) for the integration guide.
215
+
216
+ ## What the store sells in
217
+
218
+ The module reads the organisation's commerce settings once, during the build, and puts them on the
219
+ runtime config beside the gateway URL and the org id. `StoreCommerce` is exported for exactly this,
220
+ so the key's shape is not re-declared per theme:
221
+
222
+ ```ts
223
+ import type { StoreCommerce } from '@eldrajs/theme-nuxt/commerce';
224
+
225
+ const raw = (useRuntimeConfig().public.eldra as { commerce: StoreCommerce | null | '' }).commerce;
226
+ const commerce: StoreCommerce | null = typeof raw === 'object' ? raw : null;
227
+ ```
228
+
229
+ `commerce` is `null` when the store has not configured commerce, when the site is built without
230
+ gateway credentials, or when the read failed — the build prints one warning (naming the cause when
231
+ there was one) and finishes, because a currency nobody can fetch should cost a symbol, not a deploy.
232
+ A theme that formats prices should treat that as "render a plain number", never as a currency to
233
+ guess at; the starter does exactly that in `app/storefront/money.ts`.
234
+
235
+ One detail of Nuxt's own serialisation matters when you read the key: a `null` public runtime-config
236
+ value reaches the page as an **empty string**, so on a store that published nothing `commerce` is
237
+ `''` rather than `null` (the module's `locale` does the same). Treat anything that is not an object
238
+ as "no currency" — not as a malformed record — and only complain about a record that is present but
239
+ incomplete.
240
+
241
+ The module supplies no override of its own, on purpose: the platform publishes the currency the
242
+ catalogue's prices are actually in, so a theme-side setting could only ever relabel real amounts.
243
+ (Nuxt's own public-runtime-config environment overriding — `NUXT_PUBLIC_ELDRA_COMMERCE_CURRENCY` and
244
+ its siblings — still applies wherever Nuxt reads runtime config at request time, as it does to every
245
+ other public key. On a prerendered site there is nothing for it to override: the value is baked into
246
+ each page's payload at build.) It is read at build rather than in the browser because every price on
247
+ a prerendered page is formatted against it.
248
+
249
+ ## Which locales the site serves
250
+
251
+ The module reads the organisation's configured content locales once, during the build, and puts
252
+ them on the runtime config beside `commerce`. `StoreLocales` is exported for exactly this:
253
+
254
+ ```ts
255
+ import type { StoreLocales } from '@eldrajs/theme-nuxt/locales';
256
+
257
+ const raw = (useRuntimeConfig().public.eldra as { locales: StoreLocales | null | '' }).locales;
258
+ const locales: StoreLocales | null = typeof raw === 'object' ? raw : null;
259
+ ```
260
+
261
+ `locales` is `{ default, supported }` with `supported` default-first, or `null` — for an
262
+ organisation that has configured none, for a site built without gateway credentials, and for a read
263
+ that failed (that last one, and only that one, prints a warning naming the cause). `null` means the
264
+ site behaves exactly as it did before locales existed: one unprefixed site, no language switcher.
265
+ The same empty-string serialisation note as `commerce` applies, which is what the `typeof` guard
266
+ above is for.
267
+
268
+ A theme rarely needs to read the key itself: the module turns it into routing (see below) and
269
+ `useEldraLocale()` is the composable that answers "which locale is this page, and what are the
270
+ others".
271
+
272
+ ## Locale-prefixed routing
273
+
274
+ With two or more locales the site serves the default locale at `/` and every other supported
275
+ locale under a path prefix — `/is-IS/products/ash-glaze-mug`. The first path segment selects the
276
+ locale (matched case-insensitively, canonicalised to the spelling the organisation stored) and the
277
+ rest of the path resolves exactly as it does unprefixed; every gateway read made for that page
278
+ carries that `locale`. `/<default-locale>/…` is deliberately **not** generated and resolves as an
279
+ unknown path, because the default locale lives at `/` only.
280
+
281
+ Path segments are not translated: a page is at its default-locale slug under every prefix, so
282
+ `/is-IS/about` is the Icelandic rendering of the same document `/about` serves. The prerender pass
283
+ therefore lists each content path once and writes it once per locale — pages, route templates,
284
+ catalog routes and the seeded `cart`/`wishlist`/`search` pages alike.
285
+
286
+ `eldra.locale` / `ELDRA_LOCALE` keeps the meaning it always had: an override of the **default**
287
+ locale. Naming one of the organisation's supported locales moves that locale to `/` and prefixes
288
+ the others; naming anything else (or deploying against an organisation with no locales) changes no
289
+ URL and still forwards the value on every read.
290
+
291
+ The module gives every page `<html lang>` and a `rel="alternate" hreflang` link per supported
292
+ locale (plus `x-default` for the unprefixed path) on its own — a theme adds nothing for either.
293
+
294
+ ```vue
295
+ <script setup lang="ts">
296
+ // Auto-imported, like `useEldraPage`.
297
+ const { active, defaultLocale, supported, name, path, switchPath, select } = useEldraLocale();
298
+
299
+ // `path()` prefixes one same-site destination for the active locale, and is idempotent.
300
+ const cartHref = computed(() => path('/cart'));
301
+ // `switchPath()` is the same page in another language, query and fragment included;
302
+ // `select()` navigates there.
303
+ </script>
304
+ ```
305
+
306
+ `name(locale)` is that locale's own name ("íslenska (Ísland)") for a switcher's option label. It is
307
+ resolved **once, on the server**, and carried in the payload: `Intl.DisplayNames` is ICU data and a
308
+ renderer and a browser need not have the same of it — Node answers "íslenska (Ísland)" for `is-IS`
309
+ where a reduced-ICU browser build answers "Icelandic (Iceland)" — so a page that let each side
310
+ compute its own labels would hydrate into a mismatch and repaint.
311
+
312
+ Links are already handled where the kit owns them: `useEldraLink()` resolves a `link` field's href
313
+ under the active locale, and a theme's router-link component should put every internal `to`
314
+ through `path()` once (the starter's `app/components/EldraRouterLink.vue` is the reference).
315
+
316
+ ## Development
317
+
318
+ `src/runtime/**` is compiled by Nuxt at build/dev time, not by `tsc` — it imports `nuxt/app` and
319
+ Nuxt's virtual modules (`#imports`, `virtual:eldra/*`), which only exist inside a Nuxt build
320
+ graph. `tsconfig.json`'s `include` is narrowed to `src/index.ts` and `src/module.ts` (the module
321
+ entry, which only imports resolvable packages — and, through it, the framework-free runtime files
322
+ it shares with the composable) so `pnpm typecheck` proves the part `tsc` can
323
+ actually resolve; the runtime files that reach for Nuxt are still type-checked as part of
324
+ `nuxt-module-build build`
325
+ and by consuming Nuxt apps (see `examples/starter-nuxt`'s `nuxi typecheck`).
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)