@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.
- package/package.json +3 -3
- package/template/.eldra/previews.json +35 -35
- package/template/.github/workflows/eldra-deploy.yml +29 -2
- package/template/.gitlab-ci.yml +37 -10
- package/template/README.md +4 -4
- package/template/app/composables/useFormSpam.ts +1 -0
- package/template/app/plugins/chunk-reload.client.ts +29 -0
- package/template/app/plugins/eldra-storefront.ts +8 -0
- package/template/app/storefront/gateway.ts +34 -11
- package/template/app/storefront/sharedRead.ts +34 -0
- package/template/app/storefront/structuredData.ts +17 -0
- package/template/app/utils/chunkReload.ts +11 -0
- package/template/bitbucket-pipelines.yml +26 -6
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +146 -94
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +11 -4
- package/template/blocks/footer/__tests__/Block.spec.ts +68 -3
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/preview.png +0 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +125 -541
- package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
- package/template/blocks/navigation/parts/MenuLink.vue +15 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/test/chunkReload.spec.ts +20 -0
- package/template/test/imageFraming.browser.spec.ts +125 -0
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/collection.spec.ts +1 -1
- package/template/test/pages/home.spec.ts +1 -1
- package/template/test/pages/product.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +8 -13
- package/template/test/storefront/gateway.spec.ts +6 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
- package/template/test/storefront/sharedRead.spec.ts +43 -0
- package/template/test/storefront/structuredData.spec.ts +31 -0
- 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.
|
|
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.
|
|
46
|
-
"@eldrajs/vite-plugin-theme": "^0.3.
|
|
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": "
|
|
3
|
-
"article": "
|
|
4
|
-
"article-list": "
|
|
5
|
-
"breadcrumbs": "
|
|
6
|
-
"cart": "
|
|
7
|
-
"collection-grid": "
|
|
8
|
-
"collection-header": "
|
|
9
|
-
"contact": "
|
|
10
|
-
"cta": "
|
|
11
|
-
"faq": "
|
|
12
|
-
"feature-grid": "
|
|
13
|
-
"footer": "
|
|
14
|
-
"form": "
|
|
15
|
-
"gallery": "
|
|
16
|
-
"hero": "
|
|
17
|
-
"image": "
|
|
18
|
-
"logo-cloud": "
|
|
19
|
-
"navigation": "
|
|
20
|
-
"newsletter": "
|
|
21
|
-
"order-status": "
|
|
22
|
-
"pricing-table": "
|
|
23
|
-
"product-carousel": "
|
|
24
|
-
"product-detail": "
|
|
25
|
-
"quote": "
|
|
26
|
-
"rich-text": "
|
|
27
|
-
"search": "
|
|
28
|
-
"split-content": "
|
|
29
|
-
"stats": "
|
|
30
|
-
"tabs": "
|
|
31
|
-
"team": "
|
|
32
|
-
"testimonials": "
|
|
33
|
-
"timeline": "
|
|
34
|
-
"trust-strip": "
|
|
35
|
-
"video-embed": "
|
|
36
|
-
"wishlist": "
|
|
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
|
-
|
|
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
|
-
-
|
|
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 }}
|
package/template/.gitlab-ci.yml
CHANGED
|
@@ -1,18 +1,45 @@
|
|
|
1
|
-
stages: [deploy]
|
|
1
|
+
stages: [build, deploy]
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
43
|
+
npm_config_ignore_scripts: 'true'
|
|
44
|
+
script:
|
|
45
|
+
- npx --yes @eldrajs/theme-cli@0.2.1 deploy
|
package/template/README.md
CHANGED
|
@@ -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.
|
|
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
|
|
302
|
-
- GitLab: configure
|
|
303
|
-
- Bitbucket: configure repository variables, securing `
|
|
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.
|
|
@@ -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
|
-
* `
|
|
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
|
|
1400
|
-
|
|
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 (`
|
|
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 `
|
|
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
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
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 (`
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|