@eldrajs/theme-nuxt 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -8
- package/README.md +17 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +55 -8
- package/dist/runtime/composables/useEldraRegion.d.ts +11 -0
- package/dist/runtime/composables/useEldraRegion.js +6 -0
- package/dist/runtime/previewSession.d.ts +13 -0
- package/dist/runtime/previewSession.js +32 -7
- package/dist/runtime/region.d.ts +67 -0
- package/dist/runtime/region.js +43 -0
- package/dist/runtime/storeAmounts.d.ts +20 -0
- package/dist/runtime/storeAmounts.js +35 -0
- package/package.json +13 -5
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- **Store amounts for price tokens (WS-1473).** The build reads the free-shipping threshold per currency once, beside the other reads (`features.getStoreAmounts()`, fail-soft, `STORE_AMOUNTS_READ_FAILED_WARNING`), into `runtimeConfig.public.eldra.storeAmounts`: `{ freeShippingThreshold: { ISK: 1500000 } }` in minor units, or `null`. New subpath `@eldrajs/theme-nuxt/store-amounts` (`toStoreAmounts`, `readStoreAmounts`).
|
|
9
|
+
- **The organisation's regional format (WS-1277).** The build reads it once beside the commerce settings and locales (`features.getRegion()`, fail-soft with its own warning, `REGION_READ_FAILED_WARNING`) and bakes it into `runtimeConfig.public.eldra.region`: `{ countryCode, formatLocale, timeZone }` or `null`. New subpath `@eldrajs/theme-nuxt/region` (`StoreRegion`, `resolveStoreRegion`, `readStoreRegion`) and auto-import `useEldraRegion()`. Format money, numbers and dates with `formatLocale` and keep strings on the content locale.
|
|
10
|
+
- **A theme can keep a draft preview session's veil up for its own reads (WS-1277).** New
|
|
11
|
+
auto-import `holdPreviewSession(work)`: work started while a session is covered (a read outside
|
|
12
|
+
Nuxt's async data that the draft's own render started, such as a block whose draft names a
|
|
13
|
+
collection the pinned build never read) keeps the veil up until it settles, and the session
|
|
14
|
+
renders once more before the draft is shown, within the same 15 s bound. A no-op outside a
|
|
15
|
+
covered session. A focus the session replays now lands on the settled page.
|
|
8
16
|
- **Link targets carry a card's picture and price (WS-1326).** `collectLinkTargets` fills
|
|
9
17
|
`LinkTargetInfo.image` from a product's `thumbnail` or a collection's `image` and
|
|
10
18
|
`LinkTargetInfo.price` from a product's `minPrice`, out of the reads it already makes.
|
|
@@ -106,7 +114,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
106
114
|
|
|
107
115
|
- **The site profile carries the registered company.** `readSiteProfile`, `resolveSiteProfile` and
|
|
108
116
|
`useSiteProfile()` gain `legal` (`{name, kennitala, streetAddress, postalCode, city,
|
|
109
|
-
|
|
117
|
+
countryCode}` or `null`), from `GET /site/v1/site-profile` since public contract 5.1.0; a
|
|
110
118
|
platform before that reads as `null`. The starter writes it on the home `Organization` as
|
|
111
119
|
`legalName`, `taxID` and `address`.
|
|
112
120
|
|
|
@@ -178,7 +186,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
178
186
|
`!seo.noindex`). New module option `structuredData: { disable }` (`true`, or the node kinds
|
|
179
187
|
`product`, `breadcrumb`, `itemList`, `organization`, `website`) on `runtimeConfig.public.eldra`;
|
|
180
188
|
editing a node at runtime is `provideStructuredData((type, node, { path, locale }) => node |
|
|
181
|
-
|
|
189
|
+
null)`. The build reads the shop's profile from `GET /site/v1/site-profile` (`readSiteProfile`,
|
|
182
190
|
`./runtime/siteProfile.ts`; fail-soft like the other platform reads, build-only) and carries it,
|
|
183
191
|
with the site name and the site icon's 512 px rendering filling its gaps, on
|
|
184
192
|
`runtimeConfig.public.eldra.siteProfile`; `useSiteProfile()` returns it with the site origin.
|
|
@@ -194,7 +202,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
194
202
|
production URL from a seventh fail-soft read, `GET /site/v1/crawl` (`readCrawlSettings`,
|
|
195
203
|
`./runtime/crawl.ts`, production builds only); with neither, nothing is written and one line says
|
|
196
204
|
why. A theme's own `public/robots.txt` or `public/sitemap.xml` is never replaced (one line, `[eldra]
|
|
197
|
-
|
|
205
|
+
<file> generation skipped: theme ships its own`). New module option `sitemap` (`false`, or
|
|
198
206
|
`{ maxUrls, maxBytes }`). The head's hreflang `<link>`s are absolute when the origin is known. The
|
|
199
207
|
runtime `eldraSeo.siteUrl` now follows the same origin. Documented in `docs/theme-seo.md`.
|
|
200
208
|
|
|
@@ -216,13 +224,13 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
216
224
|
`@eldrajs/vite-plugin-theme` changelog).
|
|
217
225
|
|
|
218
226
|
- **Site icons, set in Studio and rendered by the media worker.** A fifth fail-soft read, `GET
|
|
219
|
-
|
|
227
|
+
/site/v1/site-icons` (`readSiteIcons`, `./runtime/siteIcons.ts`), answers the site's icon (a
|
|
220
228
|
media-library raster, square, at least 512 px), background colour, theme colour, short name and
|
|
221
229
|
`icons`, the URLs of the variants the media worker renders (`null` when no icon is set). When an
|
|
222
230
|
icon is set, `nuxi generate` writes only `site.webmanifest` into the static output (on both
|
|
223
231
|
nitro `compiled` and `prerender:done`) and adds `<link rel="icon" type="image/png"
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
sizes="32x32">`, `<link rel="apple-touch-icon">`, `<link rel="manifest">` and `<meta
|
|
233
|
+
name="theme-color">` to every page; the icon tags point at the media URLs. No image is fetched or
|
|
226
234
|
processed at build time and no `favicon.ico` is generated (the theme's own `public/favicon.ico`
|
|
227
235
|
stays the root fallback). The theme colour defaults to the primary design token and the short name
|
|
228
236
|
to the site name. With no icon set or a failed read, nothing is written or tagged and the theme's
|
|
@@ -302,7 +310,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
302
310
|
for the catalog route beside the page component — which the starter does) saw the failure in one
|
|
303
311
|
of them and an ordinary empty resolution in the other. That is indistinguishable from "there is
|
|
304
312
|
no such page", so a transient gateway failure drew the theme's not-found shell, and `nuxi
|
|
305
|
-
|
|
313
|
+
generate` wrote it to disk under a path a visitor can reach, with exit code 0. On the server such
|
|
306
314
|
a route is now answered `500` as well, so Nitro writes no file for it and names it in the
|
|
307
315
|
prerender list (pair it with `nitro.prerender.failOnError` to stop the build — its real exposure is
|
|
308
316
|
about twice the route count, because each page's `_payload.json` is prerendered too and resolves
|
|
@@ -347,7 +355,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
347
355
|
page for exactly that second — and, because every keystroke re-reads the drafts, produced one
|
|
348
356
|
alert per keystroke with the page gone. The first failure is held back (what is on screen stays,
|
|
349
357
|
rather than collapsing to the not-found shell) and the error is reported once a 401 arrives on a
|
|
350
|
-
|
|
358
|
+
_newer_ token — the retry failed too — or after a 10s grace window, so a preview nobody is going
|
|
351
359
|
to recover still says so.
|
|
352
360
|
|
|
353
361
|
- `runtimeConfig.public.eldra` now carries `commerce` — `{ currency, taxInclusivePricing,
|
package/README.md
CHANGED
|
@@ -282,6 +282,23 @@ A theme rarely needs to read the key itself: the module turns it into routing (s
|
|
|
282
282
|
`useEldraLocale()` is the composable that answers "which locale is this page, and what are the
|
|
283
283
|
others".
|
|
284
284
|
|
|
285
|
+
## Which regional format the site writes in
|
|
286
|
+
|
|
287
|
+
The module also reads the organisation's **regional format** once, during the build:
|
|
288
|
+
`runtimeConfig.public.eldra.region` is `{ countryCode, formatLocale, timeZone }` or `null`. It is
|
|
289
|
+
not the content locale: format money, numbers and dates with `formatLocale` and show a timestamp's
|
|
290
|
+
day in `timeZone`, and keep the page's words on the content locale. An English-language Icelandic
|
|
291
|
+
store then prints "4.790 kr." on its English pages.
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
const region = useEldraRegion(); // StoreRegion | null, from '@eldrajs/theme-nuxt/region'
|
|
295
|
+
const formatLocale = region?.formatLocale ?? useEldraLocale().active ?? 'en-US';
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
`null` for an organisation that publishes none, for a site built without gateway credentials, for a
|
|
299
|
+
record whose tag or zone `Intl` would refuse, and for a read that failed (only that last one prints a
|
|
300
|
+
warning). With `null`, format in the content locale, as before.
|
|
301
|
+
|
|
285
302
|
## Locale-prefixed routing
|
|
286
303
|
|
|
287
304
|
With two or more locales the site serves the default locale at `/` and every other supported
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -10,6 +10,8 @@ import { readCrawlSettings } from '../dist/runtime/crawl.js';
|
|
|
10
10
|
import { buildCrawlFiles } from '../dist/runtime/crawlOutput.js';
|
|
11
11
|
import { readRedirects, buildRedirectsFile, readThemeRedirects } from '../dist/runtime/redirects.js';
|
|
12
12
|
import { readStoreCommerce } from '../dist/runtime/commerce.js';
|
|
13
|
+
import { readStoreRegion } from '../dist/runtime/region.js';
|
|
14
|
+
import { readStoreAmounts } from '../dist/runtime/storeAmounts.js';
|
|
13
15
|
import { readDesignTokens } from '../dist/runtime/designTokens.js';
|
|
14
16
|
import { readFormDefinitions } from '../dist/runtime/forms.js';
|
|
15
17
|
import { buildSiteIconOutput } from '../dist/runtime/siteIconAssets.js';
|
|
@@ -92,6 +94,13 @@ const eldraModule = defineNuxtModule({
|
|
|
92
94
|
// first for the same reason: the key has to exist before another module's `setup` can look
|
|
93
95
|
// for it. See `./runtime/locales.ts`.
|
|
94
96
|
locales: null,
|
|
97
|
+
// The organisation's regional format (the locale money, numbers and dates are written in,
|
|
98
|
+
// and the time zone they are shown in — not the content locale), filled in below from the
|
|
99
|
+
// same platform read. Written here first for the same reason. See `./runtime/region.ts`.
|
|
100
|
+
region: null,
|
|
101
|
+
// The store's amounts for `⟦store …⟧` price tokens (the free-shipping threshold per
|
|
102
|
+
// currency), filled in below from the same platform read. See `./runtime/storeAmounts.ts`.
|
|
103
|
+
storeAmounts: null,
|
|
95
104
|
// The organisation's resolved design-token catalog (the theme's own tokens with the site's
|
|
96
105
|
// overrides already applied), filled in below from the same platform read settling. Written
|
|
97
106
|
// here first for the same reason `commerce`/`locales` are: the key has to exist before
|
|
@@ -127,7 +136,10 @@ const eldraModule = defineNuxtModule({
|
|
|
127
136
|
isPreview: nuxt.options.dev || buildTarget !== "production"
|
|
128
137
|
};
|
|
129
138
|
const buildToken = (process.env.ELDRA_BUILD_TOKEN ?? "").trim();
|
|
130
|
-
addPlugin({
|
|
139
|
+
addPlugin({
|
|
140
|
+
src: resolver.resolve("./runtime/previewSessionRoute"),
|
|
141
|
+
mode: "client"
|
|
142
|
+
});
|
|
131
143
|
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
132
144
|
addServerHandler({
|
|
133
145
|
route: VISITOR_COUNTRY_PATH,
|
|
@@ -136,15 +148,24 @@ const eldraModule = defineNuxtModule({
|
|
|
136
148
|
});
|
|
137
149
|
addPlugin(resolver.resolve("./runtime/analyticsPlugin"));
|
|
138
150
|
if (options.campaignAttribution !== false) {
|
|
139
|
-
addPlugin({
|
|
151
|
+
addPlugin({
|
|
152
|
+
src: resolver.resolve("./runtime/attributionPlugin"),
|
|
153
|
+
mode: "client"
|
|
154
|
+
});
|
|
140
155
|
}
|
|
141
156
|
addImports([
|
|
142
157
|
{
|
|
143
158
|
name: "useEldraBuildToken",
|
|
144
159
|
from: resolver.resolve("./runtime/composables/useEldraBuildToken")
|
|
145
160
|
},
|
|
146
|
-
{
|
|
147
|
-
|
|
161
|
+
{
|
|
162
|
+
name: "useEldraPage",
|
|
163
|
+
from: resolver.resolve("./runtime/composables/useEldraPage")
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "useEldraSeo",
|
|
167
|
+
from: resolver.resolve("./runtime/composables/useEldraSeo")
|
|
168
|
+
},
|
|
148
169
|
{
|
|
149
170
|
name: "useEldraAnalytics",
|
|
150
171
|
from: resolver.resolve("./runtime/composables/useEldraAnalytics")
|
|
@@ -157,7 +178,15 @@ const eldraModule = defineNuxtModule({
|
|
|
157
178
|
})),
|
|
158
179
|
// The route key a theme's catch-all page gives `<NuxtPage>`; see `./runtime/routePath`.
|
|
159
180
|
{ name: "eldraRouteKey", from: resolver.resolve("./runtime/routePath") },
|
|
160
|
-
{
|
|
181
|
+
{
|
|
182
|
+
name: "useEldraForms",
|
|
183
|
+
from: resolver.resolve("./runtime/composables/useEldraForms")
|
|
184
|
+
},
|
|
185
|
+
// The regional format money, numbers and dates are written in (`./runtime/region.ts`).
|
|
186
|
+
{
|
|
187
|
+
name: "useEldraRegion",
|
|
188
|
+
from: resolver.resolve("./runtime/composables/useEldraRegion")
|
|
189
|
+
},
|
|
161
190
|
{ name: "useEldra", from: "@eldrajs/theme-vue" },
|
|
162
191
|
// The active content locale and the path helpers around it. Re-exported from theme-vue
|
|
163
192
|
// rather than defined here: the state lives on the theme context so a **block** can read it
|
|
@@ -165,7 +194,13 @@ const eldraModule = defineNuxtModule({
|
|
|
165
194
|
// module is what fills it from the route.
|
|
166
195
|
{ name: "useEldraLocale", from: "@eldrajs/theme-vue" },
|
|
167
196
|
{ name: "useEldraEntry", from: "@eldrajs/theme-vue" },
|
|
168
|
-
{ name: "useEldraPreview", from: "@eldrajs/theme-vue" }
|
|
197
|
+
{ name: "useEldraPreview", from: "@eldrajs/theme-vue" },
|
|
198
|
+
// A read a theme makes outside Nuxt's async data, started while a draft preview session is
|
|
199
|
+
// covered, keeps the veil up until it has answered (`./runtime/previewSession.ts`).
|
|
200
|
+
{
|
|
201
|
+
name: "holdPreviewSession",
|
|
202
|
+
from: resolver.resolve("./runtime/previewSession")
|
|
203
|
+
}
|
|
169
204
|
]);
|
|
170
205
|
let localeRouting = resolveLocaleRouting(null, options.locale);
|
|
171
206
|
const crawlRoutes = [];
|
|
@@ -353,8 +388,14 @@ const eldraModule = defineNuxtModule({
|
|
|
353
388
|
);
|
|
354
389
|
nuxt.options.app.head.meta = [
|
|
355
390
|
...nuxt.options.app.head.meta ?? [],
|
|
356
|
-
{
|
|
357
|
-
|
|
391
|
+
{
|
|
392
|
+
name: "eldra-theme-version",
|
|
393
|
+
content: themeVersion(nuxt.options.rootDir)
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: "eldra-sdk-version",
|
|
397
|
+
content: packageVersion(resolver.resolve("../package.json"))
|
|
398
|
+
}
|
|
358
399
|
];
|
|
359
400
|
const platformClient = options.gatewayUrl === "" || options.orgId === "" ? null : createEldraClient$1({
|
|
360
401
|
apiBaseUrl: options.gatewayUrl,
|
|
@@ -366,6 +407,8 @@ const eldraModule = defineNuxtModule({
|
|
|
366
407
|
const [
|
|
367
408
|
commerce,
|
|
368
409
|
locales,
|
|
410
|
+
region,
|
|
411
|
+
storeAmounts,
|
|
369
412
|
platformMessages,
|
|
370
413
|
platformDesignTokens,
|
|
371
414
|
platformSiteIcons,
|
|
@@ -377,6 +420,8 @@ const eldraModule = defineNuxtModule({
|
|
|
377
420
|
] = await Promise.all([
|
|
378
421
|
readStoreCommerce(platformClient),
|
|
379
422
|
readStoreLocales(platformClient),
|
|
423
|
+
readStoreRegion(platformClient),
|
|
424
|
+
readStoreAmounts(platformClient),
|
|
380
425
|
readThemeMessages(platformClient),
|
|
381
426
|
readDesignTokens(platformClient),
|
|
382
427
|
nuxt.options.dev ? Promise.resolve(null) : readSiteIcons(platformClient),
|
|
@@ -403,6 +448,8 @@ const eldraModule = defineNuxtModule({
|
|
|
403
448
|
const runtimeEldra = nuxt.options.runtimeConfig.public.eldra;
|
|
404
449
|
runtimeEldra.commerce = commerce;
|
|
405
450
|
runtimeEldra.locales = locales;
|
|
451
|
+
runtimeEldra.region = region;
|
|
452
|
+
runtimeEldra.storeAmounts = storeAmounts;
|
|
406
453
|
runtimeEldra.designTokens = platformDesignTokens;
|
|
407
454
|
runtimeEldra.forms = platformForms;
|
|
408
455
|
nuxt.options.runtimeConfig.public.eldraSeo.setting = platformSeo;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type StoreRegion } from '../region.js';
|
|
2
|
+
/**
|
|
3
|
+
* The organisation's regional format — `{ countryCode, formatLocale, timeZone }` — or `null` when
|
|
4
|
+
* the build could not learn one (`../region.ts`). Format money, numbers and dates with
|
|
5
|
+
* `formatLocale` and show times in `timeZone`; keep strings on the content locale
|
|
6
|
+
* (`useEldraLocale().active`). With `null`, format in the content locale, as before.
|
|
7
|
+
*
|
|
8
|
+
* Read off `runtimeConfig.public.eldra.region`, which the module bakes in once at build, so the
|
|
9
|
+
* server render and the browser agree on every formatted value.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useEldraRegion(): StoreRegion | null;
|
|
@@ -117,6 +117,19 @@ export declare const PREVIEW_SESSION_DRAFT_TIMEOUT_MS = 15000;
|
|
|
117
117
|
* settled within `timeoutMs`, end in the unavailable notice. Never the published page either way.
|
|
118
118
|
*/
|
|
119
119
|
export declare function settlePreviewSessionDrafts(reads: () => Promise<unknown>, afterRender: () => Promise<unknown>, timeoutMs?: number): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Keep the veil up until `work` has settled, when it was started while the session is covered —
|
|
122
|
+
* a no-op otherwise (outside a session, or once the draft is shown).
|
|
123
|
+
*
|
|
124
|
+
* For the reads a theme makes outside Nuxt's async data, which the session cannot see: a block
|
|
125
|
+
* whose draft names a collection the pinned build never read starts that read in the draft's own
|
|
126
|
+
* render, and without this the veil drops on its skeleton and the page changes under the merchant
|
|
127
|
+
* a moment later — and a focus the session replays (`replayCoveredFocus`) scrolls against a layout
|
|
128
|
+
* that is about to change, landing where the live page, which never had the skeleton, does not.
|
|
129
|
+
* Resolve `work` once its answer has been written where the page renders it from; the session
|
|
130
|
+
* renders once more after it.
|
|
131
|
+
*/
|
|
132
|
+
export declare function holdPreviewSession(work: PromiseLike<unknown>): void;
|
|
120
133
|
/** How long a session waits for the site's saved settings before it keeps the build's. */
|
|
121
134
|
export declare const PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS = 10000;
|
|
122
135
|
/**
|
|
@@ -211,20 +211,45 @@ export async function settlePreviewSessionDrafts(reads, afterRender, timeoutMs =
|
|
|
211
211
|
() => "settled"
|
|
212
212
|
);
|
|
213
213
|
const outcome = await Promise.race([settled, timedOut]);
|
|
214
|
-
clearTimeout(timer);
|
|
215
214
|
if (outcome === "timeout") {
|
|
215
|
+
clearTimeout(timer);
|
|
216
216
|
refuse({ status: "unavailable", errorId: null });
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
for (let round = 0; ; round += 1) {
|
|
220
|
+
try {
|
|
221
|
+
await afterRender();
|
|
222
|
+
} catch (cause) {
|
|
223
|
+
clearTimeout(timer);
|
|
224
|
+
console.warn("[eldra] the draft preview could not be rendered", cause);
|
|
225
|
+
refuse({ status: "unavailable", errorId: null });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (held.size === 0 || round >= PREVIEW_SESSION_HELD_ROUNDS) break;
|
|
229
|
+
const quiet = await Promise.race([
|
|
230
|
+
Promise.all([...held]).then(() => "quiet"),
|
|
231
|
+
timedOut
|
|
232
|
+
]);
|
|
233
|
+
if (quiet === "timeout") {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
refuse({ status: "unavailable", errorId: null });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
225
238
|
}
|
|
239
|
+
clearTimeout(timer);
|
|
226
240
|
markPreviewSessionDraftShown();
|
|
227
241
|
}
|
|
242
|
+
const PREVIEW_SESSION_HELD_ROUNDS = 5;
|
|
243
|
+
const held = /* @__PURE__ */ new Set();
|
|
244
|
+
export function holdPreviewSession(work) {
|
|
245
|
+
if (state.status !== "pending") return;
|
|
246
|
+
const settled = Promise.resolve(work).then(
|
|
247
|
+
() => void 0,
|
|
248
|
+
() => void 0
|
|
249
|
+
);
|
|
250
|
+
held.add(settled);
|
|
251
|
+
void settled.then(() => held.delete(settled));
|
|
252
|
+
}
|
|
228
253
|
export const PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS = 1e4;
|
|
229
254
|
export async function settlePreviewSessionSiteSettings(read, timeoutMs = PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS) {
|
|
230
255
|
let open = true;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EldraFeatureClient, EldraOrganizationRegion } from '@eldrajs/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The organisation's **regional format**, as it reaches a theme on
|
|
4
|
+
* `runtimeConfig.public.eldra.region`: `{ countryCode, formatLocale, timeZone }`, or `null`.
|
|
5
|
+
*
|
|
6
|
+
* Published as `@eldrajs/theme-nuxt/region` beside `./commerce` and `./locales`, so a theme reading
|
|
7
|
+
* that key types it from here. The shape is the SDK's own (`features.getRegion()`), aliased under
|
|
8
|
+
* the name the runtime config uses.
|
|
9
|
+
*
|
|
10
|
+
* It is **not** the content locale. A merchant picks the language a page is written in and, in
|
|
11
|
+
* Studio, the regional format money, numbers and dates are written in — an English-language
|
|
12
|
+
* Icelandic store prints "4.790 kr." and "26. nóvember 2026" under English copy. A theme formats
|
|
13
|
+
* with `formatLocale` and shows times in `timeZone`; its strings stay on the content locale.
|
|
14
|
+
*
|
|
15
|
+
* Read **once, at build**, because every price and date a prerendered page carries is formatted
|
|
16
|
+
* with it: a value fetched in the browser would reformat every amount a tick after the page drew.
|
|
17
|
+
*
|
|
18
|
+
* `null` is a real answer: a gateway older than the field publishes none, and a theme then formats
|
|
19
|
+
* in the content locale, exactly as it did before regional formats existed.
|
|
20
|
+
*/
|
|
21
|
+
export type StoreRegion = EldraOrganizationRegion;
|
|
22
|
+
/**
|
|
23
|
+
* The slice of an `@eldrajs/sdk` client this read needs — a whole `EldraClient` satisfies it.
|
|
24
|
+
* Narrow so the module's tests can hand it a client that answers, omits or throws.
|
|
25
|
+
*/
|
|
26
|
+
export interface StoreRegionReader {
|
|
27
|
+
features: Pick<EldraFeatureClient, 'getRegion'>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The one line a build prints when it could not learn the regional format. It names the outcome —
|
|
31
|
+
* the content locale formats everything — because that is indistinguishable on the page from a
|
|
32
|
+
* store whose regional format happens to match its language, and only this case is fixable.
|
|
33
|
+
*
|
|
34
|
+
* No warning when the organisation publishes none: the outcome is the behaviour every site had
|
|
35
|
+
* before the field existed, and a line every such build printed would teach its reader to ignore
|
|
36
|
+
* build warnings.
|
|
37
|
+
*/
|
|
38
|
+
export declare const REGION_READ_FAILED_WARNING = "[eldra] could not read the organisation\u2019s regional format \u2014 prices and dates follow the content locale";
|
|
39
|
+
/**
|
|
40
|
+
* How long the build waits for the answer. A bound, because the read is optional: a regional
|
|
41
|
+
* format nobody can fetch must not be the reason a deploy never finishes.
|
|
42
|
+
*
|
|
43
|
+
* Exported so the test that proves the bound can assert the value rather than restate it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const READ_TIMEOUT_MS = 10000;
|
|
46
|
+
/**
|
|
47
|
+
* The regional format for `runtimeConfig.public.eldra.region`, or `null`.
|
|
48
|
+
*
|
|
49
|
+
* Fail-soft: a gateway that cannot be reached, a read that times out, a record the SDK refuses and
|
|
50
|
+
* an organisation that publishes none all end with `null` and a build that finishes; only a read
|
|
51
|
+
* that threw prints the one line above, with its cause.
|
|
52
|
+
*
|
|
53
|
+
* `reader` is `null` for a site built without gateway credentials: no request, no warning.
|
|
54
|
+
*/
|
|
55
|
+
export declare function readStoreRegion(reader: StoreRegionReader | null, warn?: (message: string) => void): Promise<StoreRegion | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Accepts only a whole, usable record — re-checking what the SDK checked, because this is also
|
|
58
|
+
* what reads the value back **out** of the runtime config (`resolveStoreRegion`), where Nitro
|
|
59
|
+
* serialises an absent one as `''` and a hand-written key could hold anything. Every field ends up
|
|
60
|
+
* in an `Intl` constructor on every price and date, and `Intl` throws on a bad tag or zone.
|
|
61
|
+
*/
|
|
62
|
+
export declare function toStoreRegion(value: unknown): StoreRegion | null;
|
|
63
|
+
/**
|
|
64
|
+
* The regional format the **running** site formats with, read off
|
|
65
|
+
* `runtimeConfig.public.eldra.region` (`''` when the build wrote `null`).
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveStoreRegion(value: unknown): StoreRegion | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const REGION_READ_FAILED_WARNING = "[eldra] could not read the organisation\u2019s regional format \u2014 prices and dates follow the content locale";
|
|
2
|
+
export const READ_TIMEOUT_MS = 1e4;
|
|
3
|
+
export async function readStoreRegion(reader, warn = console.warn) {
|
|
4
|
+
if (reader === null) return null;
|
|
5
|
+
const controller = new AbortController();
|
|
6
|
+
const timer = setTimeout(
|
|
7
|
+
() => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
|
|
8
|
+
READ_TIMEOUT_MS
|
|
9
|
+
);
|
|
10
|
+
try {
|
|
11
|
+
return toStoreRegion(await reader.features.getRegion(void 0, { signal: controller.signal }));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
warn(`${REGION_READ_FAILED_WARNING} (${describe(error)})`);
|
|
14
|
+
return null;
|
|
15
|
+
} finally {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function toStoreRegion(value) {
|
|
20
|
+
if (value === null || typeof value !== "object") return null;
|
|
21
|
+
const record = value;
|
|
22
|
+
const { countryCode, formatLocale, timeZone } = record;
|
|
23
|
+
if (typeof countryCode !== "string" || !/^(?:[A-Z]{2})?$/.test(countryCode)) return null;
|
|
24
|
+
if (typeof formatLocale !== "string" || formatLocale === "") return null;
|
|
25
|
+
if (!isUsable(() => Intl.getCanonicalLocales(formatLocale))) return null;
|
|
26
|
+
if (typeof timeZone !== "string" || timeZone === "") return null;
|
|
27
|
+
if (!isUsable(() => new Intl.DateTimeFormat("en", { timeZone }))) return null;
|
|
28
|
+
return { countryCode, formatLocale, timeZone };
|
|
29
|
+
}
|
|
30
|
+
export function resolveStoreRegion(value) {
|
|
31
|
+
return toStoreRegion(value);
|
|
32
|
+
}
|
|
33
|
+
function isUsable(probe) {
|
|
34
|
+
try {
|
|
35
|
+
probe();
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function describe(error) {
|
|
42
|
+
return error instanceof Error ? error.message : String(error);
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EldraFeatureClient, StoreAmounts } from '@eldrajs/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The store's amounts for `⟦store …⟧` price tokens (WS-1473): today the free-shipping threshold
|
|
4
|
+
* per currency, the lowest among the organisation's active delivery methods
|
|
5
|
+
* (`features.getStoreAmounts()`), in minor units.
|
|
6
|
+
*
|
|
7
|
+
* Read once at build time, like the currency and the regional format, and baked into
|
|
8
|
+
* `runtimeConfig.public.eldra.storeAmounts`: every currency's amount is there, so a shopper who
|
|
9
|
+
* switches currency after the page loads needs no request. **Fail-soft**: a gateway that cannot be
|
|
10
|
+
* reached, or a credential-less build, answers `null` with one warning, and a token naming a store
|
|
11
|
+
* setting then hides its sentence; the build never fails over it.
|
|
12
|
+
*/
|
|
13
|
+
export interface StoreAmountsReader {
|
|
14
|
+
features: Pick<EldraFeatureClient, 'getStoreAmounts'>;
|
|
15
|
+
}
|
|
16
|
+
export declare const STORE_AMOUNTS_READ_FAILED_WARNING = "[eldra] could not read the store\u2019s delivery thresholds \u2014 sentences naming one are left out";
|
|
17
|
+
export declare const READ_TIMEOUT_MS = 10000;
|
|
18
|
+
export declare function readStoreAmounts(reader: StoreAmountsReader | null, warn?: (message: string) => void): Promise<StoreAmounts | null>;
|
|
19
|
+
/** The amounts, kept only where every value is a currency code and a non-negative integer. */
|
|
20
|
+
export declare function toStoreAmounts(value: unknown): StoreAmounts | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const STORE_AMOUNTS_READ_FAILED_WARNING = "[eldra] could not read the store\u2019s delivery thresholds \u2014 sentences naming one are left out";
|
|
2
|
+
export const READ_TIMEOUT_MS = 1e4;
|
|
3
|
+
export async function readStoreAmounts(reader, warn = console.warn) {
|
|
4
|
+
if (reader === null) return null;
|
|
5
|
+
const controller = new AbortController();
|
|
6
|
+
const timer = setTimeout(
|
|
7
|
+
() => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
|
|
8
|
+
READ_TIMEOUT_MS
|
|
9
|
+
);
|
|
10
|
+
try {
|
|
11
|
+
return toStoreAmounts(await reader.features.getStoreAmounts({ signal: controller.signal }));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
warn(
|
|
14
|
+
`${STORE_AMOUNTS_READ_FAILED_WARNING} (${error instanceof Error ? error.message : String(error)})`
|
|
15
|
+
);
|
|
16
|
+
return null;
|
|
17
|
+
} finally {
|
|
18
|
+
clearTimeout(timer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function toStoreAmounts(value) {
|
|
22
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [name, amounts] of Object.entries(value)) {
|
|
25
|
+
if (amounts === null || typeof amounts !== "object" || Array.isArray(amounts)) continue;
|
|
26
|
+
const clean = {};
|
|
27
|
+
for (const [code, amount] of Object.entries(amounts)) {
|
|
28
|
+
if (/^[A-Z]{3}$/.test(code) && Number.isSafeInteger(amount) && amount >= 0) {
|
|
29
|
+
clean[code] = amount;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (Object.keys(clean).length > 0) out[name] = clean;
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-nuxt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Nuxt module for Eldra themes: wires @eldrajs/vite-plugin-theme, the gateway client, draft overlays and the Studio preview bridge into a Nuxt 4 site.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -41,6 +41,14 @@
|
|
|
41
41
|
"types": "./dist/runtime/locales.d.ts",
|
|
42
42
|
"import": "./dist/runtime/locales.js"
|
|
43
43
|
},
|
|
44
|
+
"./region": {
|
|
45
|
+
"types": "./dist/runtime/region.d.ts",
|
|
46
|
+
"import": "./dist/runtime/region.js"
|
|
47
|
+
},
|
|
48
|
+
"./store-amounts": {
|
|
49
|
+
"types": "./dist/runtime/storeAmounts.d.ts",
|
|
50
|
+
"import": "./dist/runtime/storeAmounts.js"
|
|
51
|
+
},
|
|
44
52
|
"./package.json": "./package.json"
|
|
45
53
|
},
|
|
46
54
|
"publishConfig": {
|
|
@@ -51,10 +59,10 @@
|
|
|
51
59
|
"@nuxt/kit": "^4.7.0",
|
|
52
60
|
"defu": "^6.1.4",
|
|
53
61
|
"h3": "^1.15.0",
|
|
54
|
-
"@eldrajs/
|
|
55
|
-
"@eldrajs/
|
|
56
|
-
"@eldrajs/theme
|
|
57
|
-
"@eldrajs/theme-
|
|
62
|
+
"@eldrajs/theme-vue": "^0.2.9",
|
|
63
|
+
"@eldrajs/sdk": "^0.5.5",
|
|
64
|
+
"@eldrajs/vite-plugin-theme": "^0.4.1",
|
|
65
|
+
"@eldrajs/theme-core": "^0.4.1"
|
|
58
66
|
},
|
|
59
67
|
"devDependencies": {
|
|
60
68
|
"@nuxt/module-builder": "^0.8.4",
|