@eldrajs/theme-cli 0.2.2 → 0.2.3

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 (60) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/previews.json +35 -35
  3. package/template/app/plugins/chunk-reload.client.ts +29 -0
  4. package/template/app/plugins/eldra-storefront.ts +5 -0
  5. package/template/app/storefront/gateway.ts +34 -11
  6. package/template/app/storefront/sharedRead.ts +34 -0
  7. package/template/app/storefront/structuredData.ts +17 -0
  8. package/template/app/utils/chunkReload.ts +11 -0
  9. package/template/blocks/announcement-bar/preview.png +0 -0
  10. package/template/blocks/article/preview.png +0 -0
  11. package/template/blocks/article-list/preview.png +0 -0
  12. package/template/blocks/breadcrumbs/preview.png +0 -0
  13. package/template/blocks/cart/preview.png +0 -0
  14. package/template/blocks/collection-grid/Block.vue +146 -94
  15. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  16. package/template/blocks/collection-grid/preview.png +0 -0
  17. package/template/blocks/collection-header/preview.png +0 -0
  18. package/template/blocks/contact/preview.png +0 -0
  19. package/template/blocks/cta/preview.png +0 -0
  20. package/template/blocks/faq/preview.png +0 -0
  21. package/template/blocks/feature-grid/preview.png +0 -0
  22. package/template/blocks/footer/preview.png +0 -0
  23. package/template/blocks/form/preview.png +0 -0
  24. package/template/blocks/gallery/preview.png +0 -0
  25. package/template/blocks/hero/preview.png +0 -0
  26. package/template/blocks/image/preview.png +0 -0
  27. package/template/blocks/logo-cloud/preview.png +0 -0
  28. package/template/blocks/navigation/Block.vue +125 -541
  29. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  30. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  31. package/template/blocks/navigation/preview.png +0 -0
  32. package/template/blocks/newsletter/preview.png +0 -0
  33. package/template/blocks/order-status/preview.png +0 -0
  34. package/template/blocks/pricing-table/preview.png +0 -0
  35. package/template/blocks/product-carousel/preview.png +0 -0
  36. package/template/blocks/product-detail/preview.png +0 -0
  37. package/template/blocks/quote/preview.png +0 -0
  38. package/template/blocks/rich-text/preview.png +0 -0
  39. package/template/blocks/search/preview.png +0 -0
  40. package/template/blocks/split-content/preview.png +0 -0
  41. package/template/blocks/stats/preview.png +0 -0
  42. package/template/blocks/tabs/preview.png +0 -0
  43. package/template/blocks/team/preview.png +0 -0
  44. package/template/blocks/testimonials/preview.png +0 -0
  45. package/template/blocks/timeline/preview.png +0 -0
  46. package/template/blocks/trust-strip/preview.png +0 -0
  47. package/template/blocks/video-embed/preview.png +0 -0
  48. package/template/blocks/wishlist/preview.png +0 -0
  49. package/template/test/chunkReload.spec.ts +20 -0
  50. package/template/test/imageFraming.browser.spec.ts +125 -0
  51. package/template/test/pages/article.spec.ts +1 -1
  52. package/template/test/pages/collection.spec.ts +1 -1
  53. package/template/test/pages/home.spec.ts +1 -1
  54. package/template/test/pages/product.spec.ts +1 -1
  55. package/template/test/prerenderRefresh.browser.spec.ts +8 -13
  56. package/template/test/storefront/gateway.spec.ts +6 -0
  57. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  58. package/template/test/storefront/sharedRead.spec.ts +43 -0
  59. package/template/test/storefront/structuredData.spec.ts +31 -0
  60. package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
5
5
  "keywords": [
6
6
  "cli",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {
43
43
  "citty": "^0.1.6",
44
44
  "tar": "^7.4.3",
45
- "@eldrajs/theme-core": "^0.3.1",
46
- "@eldrajs/vite-plugin-theme": "^0.3.1"
45
+ "@eldrajs/theme-core": "^0.3.2",
46
+ "@eldrajs/vite-plugin-theme": "^0.3.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "execa": "^9.5.2"
@@ -1,37 +1,37 @@
1
1
  {
2
- "announcement-bar": "68ba9861a4fcecb582e18aa7f44a51ff3f6465c9fbb47e88cddd8890420337be",
3
- "article": "5a5254d7ee0f76eec3ac8c1a66b34eefe9356e087bd36d825e4574bbe968e4a6",
4
- "article-list": "1d661f6f33521324f89524b53095a09d5ded680618bfcb96fc909e9ed67c6b49",
5
- "breadcrumbs": "80f7223888fe94df391ef9eb14e7d21db29783865e96e501efb545681633d35f",
6
- "cart": "cd4c0b36d1096fb01371ee10e3ca96ea6c79c5c3adfc708861a2a66dbc295070",
7
- "collection-grid": "54346552f7c6485b93fff6b97f19896c25f4995c1a6a20548a0303751733c757",
8
- "collection-header": "20b09301eb4f776e7d8af810bcb3c68c163a9d0f57640464542ab475837bf26d",
9
- "contact": "fe8f7c5ac315c08303b4f60a428037389205498689f86bf9d298c4ae2743a0d5",
10
- "cta": "c77c1ad7ee168c9b9a21ba3829fbf7d49ce553eb44e55e24048054440ff1b9b9",
11
- "faq": "4f6545197383c27ffa047f127f66689a579f471a813abb8077ee02acdc5042c3",
12
- "feature-grid": "42a3e8c3ed8ba59c47808072e7bd75134f0dd5cd6601890aaefe4d9d680a758d",
13
- "footer": "b8abd478dea9527a12eb16df8bbc77c0138f72c3b9ccd187a42e35519aca8d2e",
14
- "form": "215c423696dc865cc11b65680dd4bea7d015fe934605843338aa6a90a49fc491",
15
- "gallery": "66757de8c7f8450ac115826353352010a31883260dae2f963cb17d186f64843b",
16
- "hero": "cd9f9ae50828278eedd8e8a71c5b2955ad4d1fc5d6d0373ab3ba6f30df1bc293",
17
- "image": "1a384a1981e8fbdf3e6815d339158eff339e547c53487be26f247ed88dc3ac82",
18
- "logo-cloud": "406912fe0300486b7cd485411bd34bdcf4d93c82340f27d63e6713543949b6de",
19
- "navigation": "93b181878989575035cf454218148aea9cb049f17eb3b25e9da2db15fc7d7c4a",
20
- "newsletter": "f676177b2fca8a09cf59f4ecc4e84fc60aa525f2539252577e0e9b26c8e331ed",
21
- "order-status": "d8b65673592446379e561d3d48597668a3106c07840f744332c8fca3ae52369d",
22
- "pricing-table": "68d1a9d389f4042268ae0fd79b84c587ec01eb8893f7ada06c54245b5956b94a",
23
- "product-carousel": "024c67324ffd1d6247698472432b4e834ca81af55eab2234c4328503216aaaa3",
24
- "product-detail": "299507d04f82e14a40e6e3ce918eca8b2a859b979f5ec05a887a1e40d266858c",
25
- "quote": "ffdc3c965ee0a91a7182cec18ce97d9f62f55d46546b4b0be043cf6b88910e04",
26
- "rich-text": "a0cd489b4d00771c8da71fe3a4bc93b92e50bf34278d5c517b10cc6b6c35b039",
27
- "search": "c5c2b96738215219dcdc097a35579b0d38780e47b944d1d70edc8d8616c20ce4",
28
- "split-content": "99f9e1259086fef5e9edc03afa6c28eebc92d05b2ec9ef8c4651130da798db60",
29
- "stats": "708d400b93646a28b80a60893d0a8faa74a718258626998f0060126cde0b69ea",
30
- "tabs": "f689ffce96742598f115e4275fecd27759a97bb137d55e3acbd8e2fb118e10ce",
31
- "team": "e36e1af3528e799000c4ba8464c3785ac07a47aac4eac2a98dfc82ae0f409924",
32
- "testimonials": "25a01fd4e5399eac5d01c25a5010ef07ffacbba47c8daa3e36d3737d11e1fb40",
33
- "timeline": "2f8944c3df228ab1c7e268abbae8e8ca935ac0a070c1a088504a7566f74a109f",
34
- "trust-strip": "ed8c3652aa09ff76983d7dc217490a1c8ecf9e87ff4539eeb4ab7b18619648ea",
35
- "video-embed": "22e334618a755bceecef473bb8e027efd829f457756482088043232143237659",
36
- "wishlist": "273cbad2f658ccb87354266890a078f5951294bd8066fd4a236e0a2b5456796c"
2
+ "announcement-bar": "8a689cf55c908f2049731c24d89007f12b303b686c331d11e3fef18263f43fee",
3
+ "article": "e3de7c95a5aa30507e551e37ccbec0c28067c500c7623dc8b77902b59893d828",
4
+ "article-list": "673c37d8c8019aa15facba9459a523aa9c89dc183ef27fa7b512a0a3574db377",
5
+ "breadcrumbs": "3b4f9c9144592a1d83b07f7bcecc7efdf875e789643412625335903e4f06c0c2",
6
+ "cart": "4dee720ac08788d623e814bbc02fe4e8f63e9471770ce445d189c7621421a639",
7
+ "collection-grid": "b1e016552881b4325eff64ec69a1232b3349fadfa136f7f8f1113a487c07848a",
8
+ "collection-header": "1eabde9b00ef3566cedab4566d021ff5c0bad20e69aafbed5b57a7788c0eb34f",
9
+ "contact": "061036ca4bd571a058230c54fff612686dfdc6465b59e28991b4c313c001fd3c",
10
+ "cta": "ace9143e94d3a8136ab06daf4875c493c5dff738a6a91d4e0486440aa2d65a21",
11
+ "faq": "b67c46e039e67ba5c3ee1a6050ff0c15d647b80d8e801516a89532f3e461f6b7",
12
+ "feature-grid": "44fb41a30935185fe2e00b0028b7b9fa46c98e71d20c9bd92d0a440513e44163",
13
+ "footer": "70c6b557b65a9e50db7d7345a40d516b82a1762251d1bd572b12dd3eebdf29e1",
14
+ "form": "0afb1e35077d8e9e43350f9e6e78192326c98d4b29ffe0c9caf916a9cdd36569",
15
+ "gallery": "a2c652a4ca579c581196fac0a698916b76cca52232df6e873f7bf80941353446",
16
+ "hero": "b9c98af851deb55a2747880d0da555b91e354081adad68dce84672d28178f774",
17
+ "image": "3fe172e731e1ff31f998155ba9cce82fb159b496a850f372af80941bd6dc660b",
18
+ "logo-cloud": "f5818878f713c885148161e90fa7d006aae35578fd893b9da511652dc29b88f9",
19
+ "navigation": "67b29fcfb822d5572ecd74c203070f92ec387e96607c137e662b953fcda73580",
20
+ "newsletter": "77d5c21da977426e037f38627c87b3a7ebbe4afec94936480d342642ac6d1d02",
21
+ "order-status": "0f7f858848ab13a4437c4c5e709ef4e232fe64dd2e868ebb8c5d79dc0a8728e8",
22
+ "pricing-table": "9c1a947af841e97cc87ff600edf3c53c7a54a9065a4bd72a42121e7b8bc2f715",
23
+ "product-carousel": "67379d314525e362d91c97e765cd2f6c60a58ab71ef993279a35a2d413f053ff",
24
+ "product-detail": "11b47a73b8ea60c2b73577b276da10a8fab5ca148070be7f4fe23ab390fca106",
25
+ "quote": "0a3aebe57b2b5d4128b3a8479b7fdb28951b182e576fae3d063e7b544d40dc5d",
26
+ "rich-text": "fe0eac23870282628672872bd8b57050415e2925b317390bf1a378670a628ea1",
27
+ "search": "418b02e1f70bd654670206a14bb8bbdc6da3f4b5e9871a637cd995fb9273cff3",
28
+ "split-content": "76a2ae7167ba86c15d1853bf391fa02f510822d348ac3d0a0b5ccfbc1f1b4f6c",
29
+ "stats": "42e663f6e51a95489797620f03423c739f6a6a602b79449b7a7bb992cf3cc1b1",
30
+ "tabs": "e8149e00646111ee090acf2fcc35cc4f55f3ccc3bfdbca0c692b9dd9dca0af52",
31
+ "team": "4351405de230c1b44ae354b24adc8effd403b97a3d65156a7f3cff0e28644e06",
32
+ "testimonials": "e4732b33affc438566c4c06bc06a35ab92d008c42e07390936bf42b830d3636c",
33
+ "timeline": "3e311d49e2d167e64899af12ca5677203ceb56159ef1a92bf390f8442057b65f",
34
+ "trust-strip": "4635537d093f5da1fc7f9bab83d4a43861280fc49d1546014102affc2355b675",
35
+ "video-embed": "e8065f78c5a1b51c2703b5cf70108f7d41100aa46dc78fc64f9232e138d7d832",
36
+ "wishlist": "b2b67468462794e4e28d6c72c31ad29ddb0730c7531f61f8773c9cbab0d8676c"
37
37
  }
@@ -0,0 +1,29 @@
1
+ import { defineNuxtPlugin } from 'nuxt/app';
2
+ import { isChunkError, shouldReload } from '../utils/chunkReload';
3
+
4
+ const KEY = 'eldra:chunk-reload-at';
5
+
6
+ // A deploy renames every `_nuxt` chunk, so a tab or cached page from the old build asks for files that are gone and its lazy blocks never render.
7
+ export default defineNuxtPlugin((nuxtApp) => {
8
+ function reloadOnce(): void {
9
+ let last: number | null = null;
10
+ try {
11
+ const stored = window.sessionStorage.getItem(KEY);
12
+ last = stored === null ? null : Number(stored);
13
+ if (!shouldReload(Date.now(), last)) return;
14
+ window.sessionStorage.setItem(KEY, String(Date.now()));
15
+ } catch {
16
+ return;
17
+ }
18
+ window.location.reload();
19
+ }
20
+
21
+ window.addEventListener('vite:preloadError', (event) => {
22
+ event.preventDefault();
23
+ reloadOnce();
24
+ });
25
+ nuxtApp.hook('app:chunkError', reloadOnce);
26
+ nuxtApp.hook('vue:error', (error) => {
27
+ if (isChunkError(error)) reloadOnce();
28
+ });
29
+ });
@@ -13,6 +13,7 @@ import {
13
13
  type StorefrontPrerenderHandle,
14
14
  type StorefrontRuntime,
15
15
  } from '../storefront/gateway';
16
+ import { createSharedRead } from '../storefront/sharedRead';
16
17
  import { withAnalytics } from '../storefront/analytics';
17
18
  import { createVolatileRefresher } from '../storefront/refresh';
18
19
  import {
@@ -178,6 +179,8 @@ export default defineNuxtPlugin({
178
179
  formsEndpoint?: string;
179
180
  };
180
181
 
182
+ // Build-wide reads (the category tree) are shared across the routes of a prerender (WS-406).
183
+ const shared = createSharedRead(publicConfig.eldra);
181
184
  const client = createEldraClient({
182
185
  apiBaseUrl: publicConfig.eldra?.gatewayUrl || undefined,
183
186
  orgId: publicConfig.eldra?.orgId || undefined,
@@ -265,6 +268,8 @@ export default defineNuxtPlugin({
265
268
 
266
269
  source = createGatewayStorefront(client, {
267
270
  route,
271
+ // Build-wide reads (the category tree) are made once per prerender, not once per route.
272
+ shared,
268
273
  // What the store sells in, as the platform published it — the module read it once during the
269
274
  // build (`@eldrajs/theme-nuxt`), so a prerendered page already has it. `app/plugins/
270
275
  // eldra-ui-messages.ts` provides the currency half to `@eldrajs/ui`; this puts the whole
@@ -17,6 +17,8 @@ import {
17
17
  import { fromMinorUnits, roundMoney, toMinorUnits } from './money';
18
18
  import { chunkIds, collectVolatileTargets } from './volatile';
19
19
  import { canonicalAvailabilityValues, OPTION_SOURCE_PREFIX } from './facets';
20
+
21
+ const TOGGLE_SOURCE_PREFIX = 'toggle:';
20
22
  import { optionDisplayType, storefrontOptionKind } from './options';
21
23
  import {
22
24
  buildCategoryIndex,
@@ -1297,7 +1299,7 @@ const GATEWAY_UNSORTABLE: readonly string[] = ['best-selling'];
1297
1299
  * - **`category` is a slug in the URL and a uuid in the request.** The block's values are the facet
1298
1300
  * terms' slugs (a filtered view has to stay linkable and readable), while `categoryId` takes
1299
1301
  * catalog ids, so the slugs are resolved through the store's own category list — see
1300
- * `readCategories`.
1302
+ * `readCategoryRows`.
1301
1303
  * - **`availability` is one value, not a set.** Both boxes ticked is every product, which is no
1302
1304
  * filter at all, so nothing is sent; one box is sent as the platform's own
1303
1305
  * `in_stock`/`out_of_stock` spelling, which `canonicalAvailabilityValues` also folds the retired
@@ -1319,6 +1321,8 @@ interface CatalogFilterQuery {
1319
1321
  collectionId?: string[];
1320
1322
  availability?: string;
1321
1323
  option?: string[];
1324
+ /** `onSale=true`, the one boolean parameter the platform has today (`facets.toggles[]`'s `on_sale`). */
1325
+ onSale?: true;
1322
1326
  }
1323
1327
 
1324
1328
  /**
@@ -1396,9 +1400,8 @@ function priceParam(raw: string | undefined, currency: string | undefined): numb
1396
1400
  * URL and the active-filter row all say is applied is a lie, so that one fails the collection read,
1397
1401
  * which the block already draws as an error over the last good page.
1398
1402
  */
1399
- async function readCategories(client: EldraClient): Promise<CategoryIndex> {
1400
- const rows = (await client.catalog.listCategories({})) as unknown as RawCategory[] | null;
1401
- return buildCategoryIndex(rows);
1403
+ async function readCategoryRows(client: EldraClient): Promise<RawCategory[] | null> {
1404
+ return (await client.catalog.listCategories({})) as unknown as RawCategory[] | null;
1402
1405
  }
1403
1406
 
1404
1407
  /**
@@ -1466,6 +1469,11 @@ async function catalogFilterQuery(
1466
1469
  if (known.length === 1) query.availability = known[0];
1467
1470
  continue;
1468
1471
  }
1472
+ if (source.startsWith(TOGGLE_SOURCE_PREFIX)) {
1473
+ // A toggle is a yes/no switch; only the one the platform has a parameter for (onSale) is sent.
1474
+ if (source.slice(TOGGLE_SOURCE_PREFIX.length) === 'on_sale') query.onSale = true;
1475
+ continue;
1476
+ }
1469
1477
  if (source === 'category') {
1470
1478
  const { idBySlug } = await categoriesOnce();
1471
1479
  const matched = selected
@@ -1895,6 +1903,14 @@ async function detailSnapshots(
1895
1903
 
1896
1904
  export interface GatewayStorefrontOptions {
1897
1905
  route: StorefrontRoute;
1906
+ /**
1907
+ * Shares a build-wide read between the storefronts of a prerender (WS-406): `nuxi generate`
1908
+ * creates one storefront per route, so a read that never changes during a build (the category
1909
+ * tree) would otherwise go out once per route. The app layer binds it to the site and passes
1910
+ * `@eldrajs/theme-nuxt/prerender`'s `memoizeForPrerender`, which runs `load` every time outside a
1911
+ * prerender. Omitted — Storybook, a spec — every storefront reads for itself.
1912
+ */
1913
+ shared?: <T>(name: string, load: () => Promise<T>, locale: string | undefined) => Promise<T>;
1898
1914
  /**
1899
1915
  * Overrides where form submissions go (`forms.submit`); see `postToFormsEndpoint`. Form
1900
1916
  * definitions still come from the platform. Also the endpoint `catalog.notifyBackInStock` posts to.
@@ -1992,11 +2008,11 @@ export function createGatewayStorefront(
1992
2008
  /**
1993
2009
  * The store's category tree, read at most once for the life of this storefront and only when
1994
2010
  * something actually needs it: a category filter to resolve, a product page's breadcrumb trail, or
1995
- * a category facet the platform could not place its own terms in (`readCategories`).
2011
+ * a category facet the platform could not place its own terms in (`readCategoryRows`).
1996
2012
  *
1997
2013
  * The in-flight read is what is cached, so a product page and a grid asking at once share one
1998
2014
  * request; a failure drops the cache so the next read tries again rather than inheriting the first
1999
- * one's error. Which callers swallow that failure and which let it through is on `readCategories`.
2015
+ * one's error. Which callers swallow that failure and which let it through is on `readCategoryRows`.
2000
2016
  *
2001
2017
  * It is read on the **server** during a prerender, inside the same `useAsyncData` the product or
2002
2018
  * collection read runs under, so a generated product page carries its trail in the page payload
@@ -2004,10 +2020,17 @@ export function createGatewayStorefront(
2004
2020
  */
2005
2021
  let categories: Promise<CategoryIndex> | null = null;
2006
2022
  const categoriesOnce = (): Promise<CategoryIndex> => {
2007
- categories ??= readCategories(client).catch((caught: unknown) => {
2008
- categories = null;
2009
- throw caught;
2010
- });
2023
+ // The rows, not the index, are what a build shares: the same list `@eldrajs/theme-nuxt` reads
2024
+ // for link targets, under the same memo name and key, so a build reads it once per locale.
2025
+ const read = (): Promise<RawCategory[] | null> => readCategoryRows(client);
2026
+ categories ??= (
2027
+ options.shared === undefined ? read() : options.shared('categories', read, locale?.())
2028
+ )
2029
+ .then((rows) => buildCategoryIndex(rows))
2030
+ .catch((caught: unknown) => {
2031
+ categories = null;
2032
+ throw caught;
2033
+ });
2011
2034
  return categories;
2012
2035
  };
2013
2036
 
@@ -2139,7 +2162,7 @@ export function createGatewayStorefront(
2139
2162
  // add a serial round trip to every product page. The tree's failure is swallowed here — a
2140
2163
  // product page without a category crumb is a product page, while a product page that 500s
2141
2164
  // because the category list was unreachable is not — which is the opposite of what the
2142
- // `category` *filter* does with the same read (`readCategories`).
2165
+ // `category` *filter* does with the same read (`readCategoryRows`).
2143
2166
  const [stock, tree] = await Promise.all([
2144
2167
  readStock(client, raw, signal),
2145
2168
  categoriesOnce().catch(() => null),
@@ -0,0 +1,34 @@
1
+ import {
2
+ CATEGORIES_MEMO_NAME,
3
+ memoizeForPrerender,
4
+ prerenderMemoScope,
5
+ } from '@eldrajs/theme-nuxt/prerender';
6
+
7
+ /**
8
+ * How the storefront shares build-wide reads (WS-406). No Nuxt global is touched: the plugin passes
9
+ * the public runtime config.
10
+ *
11
+ * Reads are keyed gateway + organisation + locale, the same key `@eldrajs/theme-nuxt` uses for its
12
+ * own reads, so a list both ask for (the categories) is read once per build.
13
+ */
14
+ export interface StorefrontSharedConfig {
15
+ gatewayUrl?: string;
16
+ orgId?: string;
17
+ }
18
+
19
+ export type SharedRead = <T>(
20
+ name: string,
21
+ load: () => Promise<T>,
22
+ locale: string | undefined
23
+ ) => Promise<T>;
24
+
25
+ export { CATEGORIES_MEMO_NAME };
26
+
27
+ export function createSharedRead(
28
+ config: StorefrontSharedConfig | undefined,
29
+ memoize: typeof memoizeForPrerender = memoizeForPrerender
30
+ ): SharedRead {
31
+ const gatewayUrl = config?.gatewayUrl ?? '';
32
+ return (name, load, locale) =>
33
+ memoize(prerenderMemoScope(gatewayUrl, config?.orgId, locale), name, load);
34
+ }
@@ -58,6 +58,15 @@ export interface PageLdParts {
58
58
  logoUrl: string | null;
59
59
  sameAs: readonly string[];
60
60
  contact: { email: string | null; telephone: string | null };
61
+ /** The registered company (`useSiteProfile().legal`), or `null`. */
62
+ legal: {
63
+ name: string | null;
64
+ kennitala: string;
65
+ streetAddress: string | null;
66
+ postalCode: string | null;
67
+ city: string | null;
68
+ countryCode: string | null;
69
+ } | null;
61
70
  };
62
71
  /** The site's search page path (`/search`, unprefixed: it follows the home URL), or `null` when
63
72
  * the site has none. */
@@ -109,6 +118,14 @@ export function pageStructuredData(parts: PageLdParts): StructuredDataEntry[] {
109
118
  logo: parts.profile.logoUrl,
110
119
  sameAs: parts.profile.sameAs,
111
120
  contact: parts.profile.contact,
121
+ legalName: parts.profile.legal?.name,
122
+ taxID: parts.profile.legal?.kennitala,
123
+ address: parts.profile.legal && {
124
+ streetAddress: parts.profile.legal.streetAddress,
125
+ postalCode: parts.profile.legal.postalCode,
126
+ addressLocality: parts.profile.legal.city,
127
+ addressCountry: parts.profile.legal.countryCode,
128
+ },
112
129
  }),
113
130
  },
114
131
  {
@@ -0,0 +1,11 @@
1
+ const CHUNK_ERROR =
2
+ /dynamically imported module|importing a module script failed|error loading dynamically imported module/i;
3
+
4
+ export function isChunkError(error: unknown): boolean {
5
+ return CHUNK_ERROR.test(error instanceof Error ? error.message : String(error));
6
+ }
7
+
8
+ /** One reload per window of `windowMs`, so a chunk that stays missing cannot reload the page forever. */
9
+ export function shouldReload(now: number, lastReloadAt: number | null, windowMs = 30_000): boolean {
10
+ return lastReloadAt === null || now - lastReloadAt > windowMs;
11
+ }
Binary file
Binary file