@eldrajs/theme-nuxt 0.5.1 → 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 +10 -8
- package/README.md +17 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +52 -8
- package/dist/runtime/composables/useEldraRegion.d.ts +11 -0
- package/dist/runtime/composables/useEldraRegion.js +6 -0
- 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,8 @@ 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.
|
|
8
10
|
- **A theme can keep a draft preview session's veil up for its own reads (WS-1277).** New
|
|
9
11
|
auto-import `holdPreviewSession(work)`: work started while a session is covered (a read outside
|
|
10
12
|
Nuxt's async data that the draft's own render started, such as a block whose draft names a
|
|
@@ -112,7 +114,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
112
114
|
|
|
113
115
|
- **The site profile carries the registered company.** `readSiteProfile`, `resolveSiteProfile` and
|
|
114
116
|
`useSiteProfile()` gain `legal` (`{name, kennitala, streetAddress, postalCode, city,
|
|
115
|
-
|
|
117
|
+
countryCode}` or `null`), from `GET /site/v1/site-profile` since public contract 5.1.0; a
|
|
116
118
|
platform before that reads as `null`. The starter writes it on the home `Organization` as
|
|
117
119
|
`legalName`, `taxID` and `address`.
|
|
118
120
|
|
|
@@ -184,7 +186,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
184
186
|
`!seo.noindex`). New module option `structuredData: { disable }` (`true`, or the node kinds
|
|
185
187
|
`product`, `breadcrumb`, `itemList`, `organization`, `website`) on `runtimeConfig.public.eldra`;
|
|
186
188
|
editing a node at runtime is `provideStructuredData((type, node, { path, locale }) => node |
|
|
187
|
-
|
|
189
|
+
null)`. The build reads the shop's profile from `GET /site/v1/site-profile` (`readSiteProfile`,
|
|
188
190
|
`./runtime/siteProfile.ts`; fail-soft like the other platform reads, build-only) and carries it,
|
|
189
191
|
with the site name and the site icon's 512 px rendering filling its gaps, on
|
|
190
192
|
`runtimeConfig.public.eldra.siteProfile`; `useSiteProfile()` returns it with the site origin.
|
|
@@ -200,7 +202,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
200
202
|
production URL from a seventh fail-soft read, `GET /site/v1/crawl` (`readCrawlSettings`,
|
|
201
203
|
`./runtime/crawl.ts`, production builds only); with neither, nothing is written and one line says
|
|
202
204
|
why. A theme's own `public/robots.txt` or `public/sitemap.xml` is never replaced (one line, `[eldra]
|
|
203
|
-
|
|
205
|
+
<file> generation skipped: theme ships its own`). New module option `sitemap` (`false`, or
|
|
204
206
|
`{ maxUrls, maxBytes }`). The head's hreflang `<link>`s are absolute when the origin is known. The
|
|
205
207
|
runtime `eldraSeo.siteUrl` now follows the same origin. Documented in `docs/theme-seo.md`.
|
|
206
208
|
|
|
@@ -222,13 +224,13 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
222
224
|
`@eldrajs/vite-plugin-theme` changelog).
|
|
223
225
|
|
|
224
226
|
- **Site icons, set in Studio and rendered by the media worker.** A fifth fail-soft read, `GET
|
|
225
|
-
|
|
227
|
+
/site/v1/site-icons` (`readSiteIcons`, `./runtime/siteIcons.ts`), answers the site's icon (a
|
|
226
228
|
media-library raster, square, at least 512 px), background colour, theme colour, short name and
|
|
227
229
|
`icons`, the URLs of the variants the media worker renders (`null` when no icon is set). When an
|
|
228
230
|
icon is set, `nuxi generate` writes only `site.webmanifest` into the static output (on both
|
|
229
231
|
nitro `compiled` and `prerender:done`) and adds `<link rel="icon" type="image/png"
|
|
230
|
-
|
|
231
|
-
|
|
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
|
|
232
234
|
processed at build time and no `favicon.ico` is generated (the theme's own `public/favicon.ico`
|
|
233
235
|
stays the root fallback). The theme colour defaults to the primary design token and the short name
|
|
234
236
|
to the site name. With no icon set or a failed read, nothing is written or tagged and the theme's
|
|
@@ -308,7 +310,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
308
310
|
for the catalog route beside the page component — which the starter does) saw the failure in one
|
|
309
311
|
of them and an ordinary empty resolution in the other. That is indistinguishable from "there is
|
|
310
312
|
no such page", so a transient gateway failure drew the theme's not-found shell, and `nuxi
|
|
311
|
-
|
|
313
|
+
generate` wrote it to disk under a path a visitor can reach, with exit code 0. On the server such
|
|
312
314
|
a route is now answered `500` as well, so Nitro writes no file for it and names it in the
|
|
313
315
|
prerender list (pair it with `nitro.prerender.failOnError` to stop the build — its real exposure is
|
|
314
316
|
about twice the route count, because each page's `_payload.json` is prerendered too and resolves
|
|
@@ -353,7 +355,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
353
355
|
page for exactly that second — and, because every keystroke re-reads the drafts, produced one
|
|
354
356
|
alert per keystroke with the page gone. The first failure is held back (what is on screen stays,
|
|
355
357
|
rather than collapsing to the not-found shell) and the error is reported once a 401 arrives on a
|
|
356
|
-
|
|
358
|
+
_newer_ token — the retry failed too — or after a 10s grace window, so a preview nobody is going
|
|
357
359
|
to recover still says so.
|
|
358
360
|
|
|
359
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
|
|
@@ -168,7 +197,10 @@ const eldraModule = defineNuxtModule({
|
|
|
168
197
|
{ name: "useEldraPreview", from: "@eldrajs/theme-vue" },
|
|
169
198
|
// A read a theme makes outside Nuxt's async data, started while a draft preview session is
|
|
170
199
|
// covered, keeps the veil up until it has answered (`./runtime/previewSession.ts`).
|
|
171
|
-
{
|
|
200
|
+
{
|
|
201
|
+
name: "holdPreviewSession",
|
|
202
|
+
from: resolver.resolve("./runtime/previewSession")
|
|
203
|
+
}
|
|
172
204
|
]);
|
|
173
205
|
let localeRouting = resolveLocaleRouting(null, options.locale);
|
|
174
206
|
const crawlRoutes = [];
|
|
@@ -356,8 +388,14 @@ const eldraModule = defineNuxtModule({
|
|
|
356
388
|
);
|
|
357
389
|
nuxt.options.app.head.meta = [
|
|
358
390
|
...nuxt.options.app.head.meta ?? [],
|
|
359
|
-
{
|
|
360
|
-
|
|
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
|
+
}
|
|
361
399
|
];
|
|
362
400
|
const platformClient = options.gatewayUrl === "" || options.orgId === "" ? null : createEldraClient$1({
|
|
363
401
|
apiBaseUrl: options.gatewayUrl,
|
|
@@ -369,6 +407,8 @@ const eldraModule = defineNuxtModule({
|
|
|
369
407
|
const [
|
|
370
408
|
commerce,
|
|
371
409
|
locales,
|
|
410
|
+
region,
|
|
411
|
+
storeAmounts,
|
|
372
412
|
platformMessages,
|
|
373
413
|
platformDesignTokens,
|
|
374
414
|
platformSiteIcons,
|
|
@@ -380,6 +420,8 @@ const eldraModule = defineNuxtModule({
|
|
|
380
420
|
] = await Promise.all([
|
|
381
421
|
readStoreCommerce(platformClient),
|
|
382
422
|
readStoreLocales(platformClient),
|
|
423
|
+
readStoreRegion(platformClient),
|
|
424
|
+
readStoreAmounts(platformClient),
|
|
383
425
|
readThemeMessages(platformClient),
|
|
384
426
|
readDesignTokens(platformClient),
|
|
385
427
|
nuxt.options.dev ? Promise.resolve(null) : readSiteIcons(platformClient),
|
|
@@ -406,6 +448,8 @@ const eldraModule = defineNuxtModule({
|
|
|
406
448
|
const runtimeEldra = nuxt.options.runtimeConfig.public.eldra;
|
|
407
449
|
runtimeEldra.commerce = commerce;
|
|
408
450
|
runtimeEldra.locales = locales;
|
|
451
|
+
runtimeEldra.region = region;
|
|
452
|
+
runtimeEldra.storeAmounts = storeAmounts;
|
|
409
453
|
runtimeEldra.designTokens = platformDesignTokens;
|
|
410
454
|
runtimeEldra.forms = platformForms;
|
|
411
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;
|
|
@@ -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/vite-plugin-theme": "^0.4.
|
|
57
|
-
"@eldrajs/theme-core": "^0.4.
|
|
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",
|