@eldrajs/theme-cli 0.2.1 → 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 (67) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/previews.json +35 -35
  3. package/template/.github/workflows/eldra-deploy.yml +29 -2
  4. package/template/.gitlab-ci.yml +37 -10
  5. package/template/README.md +4 -4
  6. package/template/app/composables/useFormSpam.ts +1 -0
  7. package/template/app/plugins/chunk-reload.client.ts +29 -0
  8. package/template/app/plugins/eldra-storefront.ts +8 -0
  9. package/template/app/storefront/gateway.ts +34 -11
  10. package/template/app/storefront/sharedRead.ts +34 -0
  11. package/template/app/storefront/structuredData.ts +17 -0
  12. package/template/app/utils/chunkReload.ts +11 -0
  13. package/template/bitbucket-pipelines.yml +26 -6
  14. package/template/blocks/announcement-bar/preview.png +0 -0
  15. package/template/blocks/article/preview.png +0 -0
  16. package/template/blocks/article-list/preview.png +0 -0
  17. package/template/blocks/breadcrumbs/preview.png +0 -0
  18. package/template/blocks/cart/preview.png +0 -0
  19. package/template/blocks/collection-grid/Block.vue +146 -94
  20. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  21. package/template/blocks/collection-grid/preview.png +0 -0
  22. package/template/blocks/collection-header/preview.png +0 -0
  23. package/template/blocks/contact/preview.png +0 -0
  24. package/template/blocks/cta/preview.png +0 -0
  25. package/template/blocks/faq/preview.png +0 -0
  26. package/template/blocks/feature-grid/preview.png +0 -0
  27. package/template/blocks/footer/Block.vue +11 -4
  28. package/template/blocks/footer/__tests__/Block.spec.ts +68 -3
  29. package/template/blocks/footer/preview.png +0 -0
  30. package/template/blocks/form/preview.png +0 -0
  31. package/template/blocks/gallery/preview.png +0 -0
  32. package/template/blocks/hero/preview.png +0 -0
  33. package/template/blocks/image/preview.png +0 -0
  34. package/template/blocks/logo-cloud/preview.png +0 -0
  35. package/template/blocks/navigation/Block.vue +125 -541
  36. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  37. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  38. package/template/blocks/navigation/preview.png +0 -0
  39. package/template/blocks/newsletter/preview.png +0 -0
  40. package/template/blocks/order-status/preview.png +0 -0
  41. package/template/blocks/pricing-table/preview.png +0 -0
  42. package/template/blocks/product-carousel/preview.png +0 -0
  43. package/template/blocks/product-detail/preview.png +0 -0
  44. package/template/blocks/quote/preview.png +0 -0
  45. package/template/blocks/rich-text/preview.png +0 -0
  46. package/template/blocks/search/preview.png +0 -0
  47. package/template/blocks/split-content/preview.png +0 -0
  48. package/template/blocks/stats/preview.png +0 -0
  49. package/template/blocks/tabs/preview.png +0 -0
  50. package/template/blocks/team/preview.png +0 -0
  51. package/template/blocks/testimonials/preview.png +0 -0
  52. package/template/blocks/timeline/preview.png +0 -0
  53. package/template/blocks/trust-strip/preview.png +0 -0
  54. package/template/blocks/video-embed/preview.png +0 -0
  55. package/template/blocks/wishlist/preview.png +0 -0
  56. package/template/test/chunkReload.spec.ts +20 -0
  57. package/template/test/imageFraming.browser.spec.ts +125 -0
  58. package/template/test/pages/article.spec.ts +1 -1
  59. package/template/test/pages/collection.spec.ts +1 -1
  60. package/template/test/pages/home.spec.ts +1 -1
  61. package/template/test/pages/product.spec.ts +1 -1
  62. package/template/test/prerenderRefresh.browser.spec.ts +8 -13
  63. package/template/test/storefront/gateway.spec.ts +6 -0
  64. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  65. package/template/test/storefront/sharedRead.spec.ts +43 -0
  66. package/template/test/storefront/structuredData.spec.ts +31 -0
  67. 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.1",
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.0",
46
- "@eldrajs/vite-plugin-theme": "^0.3.0"
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": "18b3e8d7c29a044b2bac93ca16a72c78dbf7d9f744a036b6fbec3af3de70229e",
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
  }
@@ -5,7 +5,9 @@ on:
5
5
  repository_dispatch:
6
6
  types: [eldra.rebuild]
7
7
  jobs:
8
- deploy:
8
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it never gets
9
+ # the deploy token. Only the build token, which is read-only.
10
+ build:
9
11
  runs-on: ubuntu-latest
10
12
  steps:
11
13
  - uses: actions/checkout@v4
@@ -17,10 +19,35 @@ jobs:
17
19
  env:
18
20
  ELDRA_GATEWAY_URL: ${{ vars.ELDRA_GATEWAY_URL }}
19
21
  ELDRA_ORG_ID: ${{ vars.ELDRA_ORG_ID }}
22
+ # Read-only build token (Studio → Settings → Developers → Build tokens): gives the build's
23
+ # gateway reads their own rate-limit bucket.
24
+ ELDRA_BUILD_TOKEN: ${{ secrets.ELDRA_BUILD_TOKEN }}
20
25
  # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
21
26
  ELDRA_SITE_URL: ${{ vars.ELDRA_SITE_URL }}
22
- - run: pnpm exec eldra-theme deploy
27
+ - uses: actions/upload-artifact@v4
28
+ with:
29
+ name: eldra-build
30
+ path: .output/public
31
+ # The manifest lives in .output/public/.eldra, a hidden directory.
32
+ include-hidden-files: true
33
+ if-no-files-found: error
34
+ retention-days: 1
35
+ # The deploy job has the deploy token (it can publish the site) and runs none of the project's
36
+ # code: no checkout, no `pnpm install`, only the pinned CLI, installed with scripts disabled.
37
+ deploy:
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ steps:
41
+ - uses: actions/setup-node@v4
42
+ with: { node-version: 20 }
43
+ - uses: actions/download-artifact@v4
44
+ with:
45
+ name: eldra-build
46
+ path: .output/public
47
+ # Keep this version in step with @eldrajs/theme-cli in package.json.
48
+ - run: npx --yes @eldrajs/theme-cli@0.2.1 deploy
23
49
  env:
50
+ npm_config_ignore_scripts: 'true'
24
51
  ELDRA_API_URL: ${{ vars.ELDRA_API_URL }}
25
52
  ELDRA_DEPLOY_TOKEN: ${{ secrets.ELDRA_DEPLOY_TOKEN }}
26
53
  ELDRA_TRIGGER_DEPLOYMENT_ID: ${{ github.event.client_payload.deploymentId }}
@@ -1,18 +1,45 @@
1
- stages: [deploy]
1
+ stages: [build, deploy]
2
2
 
3
- eldra-deploy:
4
- stage: deploy
3
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it must never
4
+ # receive the deploy token. Create these in Settings → CI/CD → Variables:
5
+ # ELDRA_BUILD_TOKEN masked. A read-only build token (Studio → Settings → Developers → Build
6
+ # tokens): gives the build's gateway reads their own rate-limit bucket.
7
+ # ELDRA_DEPLOY_TOKEN masked, protected, with the environment scope `production`. It can publish
8
+ # the site; scoped like this only the deploy job (environment: production, on
9
+ # a protected branch) receives it, never the build job.
10
+ # ELDRA_GATEWAY_URL, ELDRA_ORG_ID, ELDRA_SITE_URL (the public origin) and ELDRA_API_URL: plain
11
+ # variables.
12
+ # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
13
+ # The platform's trigger passes ELDRA_TRIGGER_DEPLOYMENT_ID as a pipeline variable.
14
+
15
+ .rules: &rules
16
+ - if: '$CI_PIPELINE_SOURCE == "trigger"'
17
+ - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
18
+
19
+ eldra-build:
20
+ stage: build
5
21
  image: node:20
6
- rules:
7
- - if: '$CI_PIPELINE_SOURCE == "trigger"'
8
- - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
22
+ rules: *rules
9
23
  before_script:
10
24
  - corepack enable && corepack prepare pnpm@9.15.0 --activate
11
25
  script:
12
26
  - pnpm install --frozen-lockfile
13
27
  - pnpm exec nuxi generate
14
- - pnpm exec eldra-theme deploy
28
+ artifacts:
29
+ # .output/public/.eldra/manifest.json is a hidden path; artifacts keep it.
30
+ paths:
31
+ - .output/public
32
+ expire_in: 1 hour
33
+
34
+ # Runs none of the project's code: no `pnpm install`, only the pinned CLI, installed with scripts
35
+ # disabled. Keep the version in step with @eldrajs/theme-cli in package.json.
36
+ eldra-deploy:
37
+ stage: deploy
38
+ image: node:20
39
+ needs: [eldra-build]
40
+ rules: *rules
41
+ environment: production
15
42
  variables:
16
- # A build is production unless ELDRA_BUILD_TARGET=preview, so none is set here.
17
- # ELDRA_SITE_URL (the public origin) is a CI/CD variable set on the project.
18
- ELDRA_TRIGGER_DEPLOYMENT_ID: $ELDRA_TRIGGER_DEPLOYMENT_ID
43
+ npm_config_ignore_scripts: 'true'
44
+ script:
45
+ - npx --yes @eldrajs/theme-cli@0.2.1 deploy
@@ -296,10 +296,10 @@ The deploy command uploads the generated static site and exact `.eldra/manifest.
296
296
 
297
297
  ## Wiring rebuilds
298
298
 
299
- The starter includes GitHub Actions, GitLab CI, and Bitbucket Pipelines examples. All build locally with Node 20 and pnpm, run `nuxi generate`, then push the static output with `eldra-theme deploy`.
299
+ The starter includes GitHub Actions, GitLab CI, and Bitbucket Pipelines examples. Each is split into a **build job** and a **deploy job**. The build job checks out the theme, installs with Node 20 and pnpm, runs `nuxi generate` (with `ELDRA_BUILD_TOKEN`, a read-only build token, so the build's gateway reads get their own rate-limit budget; it is sent only from the build in `X-Eldra-Build-Token`) and uploads `.output/public` as an artifact. The deploy job downloads the artifact and pushes it with `eldra-theme deploy` and `ELDRA_DEPLOY_TOKEN`, which can publish the site. The build job never receives the deploy token, because it runs every npm dependency's code. The deploy job installs none of the project's dependencies: it runs the pinned `@eldrajs/theme-cli` with install scripts disabled (keep its version in step with `package.json`).
300
300
 
301
- - GitHub: set repository variables `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` (the public origin, for canonical and `og:url`), plus secret `ELDRA_DEPLOY_TOKEN`. In Studio choose the GitHub trigger and configure `https://api.github.com/repos/<owner>/<repo>/dispatches` with a token allowed to dispatch workflows.
302
- - GitLab: configure those four names as project CI/CD variables, masking `ELDRA_DEPLOY_TOKEN`. In Studio use the project pipeline-trigger URL, trigger token, and branch/tag ref.
303
- - Bitbucket: configure repository variables, securing `ELDRA_DEPLOY_TOKEN`. In Studio use the pipelines endpoint, `username:app-password` token, and ref; the backend selects the `eldra-rebuild` custom pipeline.
301
+ - GitHub: set repository variables `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` (the public origin, for canonical and `og:url`), plus repository secrets `ELDRA_BUILD_TOKEN` (used by the `build` job only) and `ELDRA_DEPLOY_TOKEN` (used by the `deploy` job only). Create the build token in Studio under Settings → Developers → Build tokens. In Studio choose the GitHub trigger and configure `https://api.github.com/repos/<owner>/<repo>/dispatches` with a token allowed to dispatch workflows.
302
+ - GitLab: configure `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID`, `ELDRA_API_URL` and `ELDRA_SITE_URL` as project CI/CD variables and `ELDRA_BUILD_TOKEN` as a masked variable. Create `ELDRA_DEPLOY_TOKEN` as a **masked, protected variable scoped to the `production` environment**; the deploy job declares `environment: production`, so the build job never receives it. In Studio use the project pipeline-trigger URL, trigger token, and branch/tag ref.
303
+ - Bitbucket: configure `ELDRA_GATEWAY_URL`, `ELDRA_ORG_ID` and `ELDRA_SITE_URL` as repository variables, securing `ELDRA_BUILD_TOKEN`. Define `ELDRA_DEPLOY_TOKEN` (secured) and `ELDRA_API_URL` as **deployment variables** of the Production environment, not repository variables; the deploy step declares `deployment: production`, so the build step never receives them. In Studio use the pipelines endpoint, `username:app-password` token, and ref; the backend selects the `eldra-rebuild` custom pipeline.
304
304
 
305
305
  Trigger tokens and app passwords are write-only in Studio. Rebuild requests supply `ELDRA_TRIGGER_DEPLOYMENT_ID`; the deploy command returns it as multipart `triggerDeploymentId`, completing the existing MANUAL or CONTENT_PUBLISH deployment rather than creating a duplicate.
@@ -43,6 +43,7 @@ export function useFormSpam(formKey: Ref<string>) {
43
43
  }
44
44
 
45
45
  return {
46
+ definition: definition.data,
46
47
  honeypot,
47
48
  honeypotField,
48
49
  siteKey,
@@ -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,
@@ -187,6 +190,9 @@ export default defineNuxtPlugin({
187
190
  // @eldrajs/theme-nuxt's, and a rate limit that only one of them waits
188
191
  // out still fails the build.
189
192
  retry: publicConfig.eldra?.retry ?? undefined,
193
+ // The read-only build token (`ELDRA_BUILD_TOKEN`), from the build environment and only during a prerender (`undefined` in
194
+ // the browser): it gives the build its own rate-limit budget at the gateway.
195
+ buildToken: useEldraBuildToken(),
190
196
  });
191
197
 
192
198
  let source: StorefrontSource | null = null;
@@ -262,6 +268,8 @@ export default defineNuxtPlugin({
262
268
 
263
269
  source = createGatewayStorefront(client, {
264
270
  route,
271
+ // Build-wide reads (the category tree) are made once per prerender, not once per route.
272
+ shared,
265
273
  // What the store sells in, as the platform published it — the module read it once during the
266
274
  // build (`@eldrajs/theme-nuxt`), so a prerendered page already has it. `app/plugins/
267
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
+ }
@@ -2,20 +2,40 @@ image: node:20
2
2
 
3
3
  definitions:
4
4
  steps:
5
- - step: &eldra-deploy
6
- name: Build and deploy to Eldra
5
+ # The build runs every npm dependency's code (install scripts, the Nuxt build), so it must never
6
+ # receive the deploy token. Define these variables:
7
+ # ELDRA_BUILD_TOKEN, ELDRA_GATEWAY_URL, ELDRA_ORG_ID, ELDRA_SITE_URL (the public origin):
8
+ # repository variables. ELDRA_BUILD_TOKEN is secured (a read-only build token: Studio →
9
+ # Settings → Developers → Build tokens).
10
+ # ELDRA_DEPLOY_TOKEN and ELDRA_API_URL: deployment variables of the Production environment
11
+ # (Repository settings → Deployments), NOT repository variables. The deploy token can
12
+ # publish the site; as a deployment variable only the deploy step receives it.
13
+ # A build is production unless ELDRA_BUILD_TARGET=preview (noindex, `Disallow: /`).
14
+ - step: &eldra-build
15
+ name: Build the theme
7
16
  script:
8
17
  - corepack enable && corepack prepare pnpm@9.15.0 --activate
9
18
  - pnpm install --frozen-lockfile
10
- # A build is production unless ELDRA_BUILD_TARGET=preview (noindex, `Disallow: /`).
11
- # Set ELDRA_SITE_URL as a repository variable.
12
- - ELDRA_SITE_URL="$ELDRA_SITE_URL" pnpm exec nuxi generate
13
- - pnpm exec eldra-theme deploy
19
+ - pnpm exec nuxi generate
20
+ artifacts:
21
+ # The manifest is in .output/public/.eldra, a hidden directory: listed explicitly.
22
+ - .output/public/**
23
+ - .output/public/.eldra/**
24
+ # Runs none of the project's code: no `pnpm install`, only the pinned CLI, installed with
25
+ # scripts disabled. Keep the version in step with @eldrajs/theme-cli in package.json.
26
+ - step: &eldra-deploy
27
+ name: Deploy to Eldra
28
+ deployment: production
29
+ script:
30
+ - export npm_config_ignore_scripts=true
31
+ - npx --yes @eldrajs/theme-cli@0.2.1 deploy
14
32
 
15
33
  pipelines:
16
34
  branches:
17
35
  main:
36
+ - step: *eldra-build
18
37
  - step: *eldra-deploy
19
38
  custom:
20
39
  eldra-rebuild:
40
+ - step: *eldra-build
21
41
  - step: *eldra-deploy
Binary file
Binary file