@eldrajs/theme-nuxt 0.3.0 → 0.3.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 CHANGED
@@ -5,6 +5,17 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **A build sends a read-only build token for its own rate-limit bucket (WS-403, WS-409).**
9
+ `ELDRA_BUILD_TOKEN` (`eldra_bld_…`, created in Studio → Settings → Developers → Build tokens) is
10
+ sent as `X-Eldra-Build-Token` by the module's build-time reads and by the clients of a
11
+ `nuxi generate` prerender; never in the browser, `nuxi dev` or a deployed server answering a
12
+ visitor. The site deploy token is never read or sent by the build: keep `ELDRA_DEPLOY_TOKEN` on the
13
+ `eldra-theme deploy` job only. The starter's GitHub, GitLab and Bitbucket pipelines are split
14
+ into a build job (with the build token, uploading `.output/public`) and a deploy job (the pinned
15
+ CLI against that artifact, no project install) so build-time code never sees the deploy token. The token is stored in no runtime config (public or private) and appears in no build output,
16
+ server bundle included: it is read from the environment at call time. New auto-import
17
+ `useEldraBuildToken()` returns it (prerender only) for a theme's own `@eldrajs/sdk` client.
18
+
8
19
  - **Baked form definitions keep `consentText` (WS-386).** `toFormDefinition` carries a subscribing
9
20
  form's consent sentence per locale and refuses a malformed one, like the other localized texts.
10
21
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.13.0"
6
6
  },
7
- "version": "0.3.0",
7
+ "version": "0.3.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -123,9 +123,14 @@ const eldraModule = defineNuxtModule({
123
123
  siteName: seoSiteName(nuxt.options.app.head.title),
124
124
  isPreview: nuxt.options.dev || buildTarget !== "production"
125
125
  };
126
+ const buildToken = (process.env.ELDRA_BUILD_TOKEN ?? "").trim();
126
127
  addPlugin(resolver.resolve("./runtime/plugin"));
127
128
  addPlugin(resolver.resolve("./runtime/analyticsPlugin"));
128
129
  addImports([
130
+ {
131
+ name: "useEldraBuildToken",
132
+ from: resolver.resolve("./runtime/composables/useEldraBuildToken")
133
+ },
129
134
  { name: "useEldraPage", from: resolver.resolve("./runtime/composables/useEldraPage") },
130
135
  { name: "useEldraSeo", from: resolver.resolve("./runtime/composables/useEldraSeo") },
131
136
  {
@@ -164,7 +169,8 @@ const eldraModule = defineNuxtModule({
164
169
  const client = createEldraClient({
165
170
  gatewayUrl: options.gatewayUrl,
166
171
  orgId: options.orgId,
167
- retry: options.retry
172
+ retry: options.retry,
173
+ buildToken: buildToken || void 0
168
174
  });
169
175
  const locale = normalizeLocale(options.locale);
170
176
  const [pages, templates] = await Promise.all([
@@ -332,7 +338,9 @@ const eldraModule = defineNuxtModule({
332
338
  const platformClient = options.gatewayUrl === "" || options.orgId === "" ? null : createEldraClient$1({
333
339
  apiBaseUrl: options.gatewayUrl,
334
340
  orgId: options.orgId,
335
- retry: options.retry
341
+ retry: options.retry,
342
+ // Not for `nuxi dev`: only a build claims the build bucket.
343
+ buildToken: nuxt.options.dev ? void 0 : buildToken || void 0
336
344
  });
337
345
  const [
338
346
  commerce,
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The organisation's read-only **build token** (`eldra_bld_…`), as a theme build sends it to the gateway in `X-Eldra-Build-Token` so
3
+ * the build's reads land in their own rate-limit bucket rather than the machine's IP bucket.
4
+ *
5
+ * It is a secret, so it is stored nowhere: not in `runtimeConfig.public` (serialised into every
6
+ * page's payload) and not in private runtime config either, because Nitro inlines private
7
+ * defaults in plaintext into the server build, so an SSR `nuxi build` would ship the token inside
8
+ * `.output/server`. The composable reads `ELDRA_BUILD_TOKEN` from the process environment at call
9
+ * time instead, and only during a prerender, which runs in the same process as `nuxi generate`.
10
+ *
11
+ * It never falls back to `ELDRA_DEPLOY_TOKEN`: the deploy token can publish a site, and handing it
12
+ * to `nuxi generate` would expose it to every npm dependency the build runs.
13
+ */
14
+ /** Pure core of {@link useEldraBuildToken}: the token in `env`, or `undefined` for none/blank. */
15
+ export declare function pickBuildToken(env: Record<string, string | undefined> | null | undefined): string | undefined;
@@ -0,0 +1,6 @@
1
+ export function pickBuildToken(env) {
2
+ const value = env?.ELDRA_BUILD_TOKEN;
3
+ if (typeof value !== "string") return void 0;
4
+ const token = value.trim();
5
+ return token === "" ? void 0 : token;
6
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The build token (`ELDRA_BUILD_TOKEN`, read-only) to pass as `buildToken` to a gateway client, or `undefined`.
3
+ *
4
+ * Answers only while Nitro is **prerendering** (`nuxi generate`): not in the browser, not in
5
+ * `nuxi dev`, not when a deployed SSR server answers a visitor — a visitor's request must never
6
+ * claim the build's rate-limit budget. The value is read from `process.env` at call time and is
7
+ * never stored in runtime config; see `../buildToken.ts`.
8
+ */
9
+ export declare function useEldraBuildToken(): string | undefined;
@@ -0,0 +1,6 @@
1
+ import { pickBuildToken } from "../buildToken.js";
2
+ export function useEldraBuildToken() {
3
+ if (!import.meta.server || !import.meta.prerender) return void 0;
4
+ const env = globalThis.process?.env;
5
+ return pickBuildToken(env);
6
+ }
@@ -15,6 +15,7 @@ import blockFields from "virtual:eldra/block-fields";
15
15
  import manifest from "virtual:eldra/manifest";
16
16
  import messages from "virtual:eldra/messages";
17
17
  import "virtual:eldra/tokens.css";
18
+ import { useEldraBuildToken } from "./composables/useEldraBuildToken.js";
18
19
  import { resolveSiteDesignTokens } from "./designTokens.js";
19
20
  import { createNuxtEldraLocaleState, localeAlternates } from "./localeState.js";
20
21
  import { localeDisplayName, resolveLocaleRouting, resolveStoreLocales } from "./locales.js";
@@ -33,6 +34,8 @@ export default defineNuxtPlugin({
33
34
  orgId: cfg.orgId,
34
35
  stega: true,
35
36
  retry: cfg.retry ?? void 0,
37
+ // Server prerender only; `undefined` in the browser. See `./buildToken.ts`.
38
+ buildToken: useEldraBuildToken(),
36
39
  defaultLocale: storeLocales?.default ?? routing.default ?? null
37
40
  });
38
41
  const preview = createEldraPreviewState();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-nuxt",
3
- "version": "0.3.0",
3
+ "version": "0.3.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",
@@ -46,10 +46,10 @@
46
46
  "dependencies": {
47
47
  "@nuxt/kit": "^4.0.0",
48
48
  "defu": "^6.1.4",
49
- "@eldrajs/sdk": "^0.3.0",
50
- "@eldrajs/vite-plugin-theme": "^0.3.0",
51
- "@eldrajs/theme-core": "^0.3.0",
52
- "@eldrajs/theme-vue": "^0.2.1"
49
+ "@eldrajs/sdk": "^0.3.2",
50
+ "@eldrajs/theme-vue": "^0.2.2",
51
+ "@eldrajs/theme-core": "^0.3.1",
52
+ "@eldrajs/vite-plugin-theme": "^0.3.1"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@nuxt/module-builder": "^0.8.4",