@eldrajs/theme-nuxt 0.4.6 → 0.4.8

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,8 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **A store's own currency can be off (WS-1399).** `commerce` on `runtimeConfig.public.eldra` carries `defaultCurrency` when it is not the store's own `currency`, and `currencies` is cleaned with the default first. A store selling in its own currency gets the same config as before.
9
+ - **Selling in more than one currency (WS-1391).** `commerce` on `runtimeConfig.public.eldra` carries `currencies`, the currencies the store offers with its own first, when it offers more than one (a one-currency store's config is unchanged). New server route `GET /_eldra/visitor` answers `{ country }` from Cloudflare's `CF-IPCountry` header, `private, no-store`, so a prerendered page can start a first-time visitor in their country's currency; it answers `null` off Cloudflare.
8
10
  - **Campaign landings are captured (WS-546).** A client plugin calls `@eldrajs/sdk`'s
9
11
  `captureCampaignAttribution` on the first page and after every navigation, so a theme's cart adds
10
12
  carry the campaign a visitor came from (`utm_*` tags only, one `localStorage` key, 30 days). New
package/README.md CHANGED
@@ -228,7 +228,9 @@ preview bridge. See [examples/starter-nuxt](../../examples/starter-nuxt) for a f
228
228
 
229
229
  The module reads the organisation's commerce settings once, during the build, and puts them on the
230
230
  runtime config beside the gateway URL and the org id. `StoreCommerce` is exported for exactly this,
231
- so the key's shape is not re-declared per theme:
231
+ so the key's shape is not re-declared per theme. Beside `currency` (the store's own) it may carry
232
+ `currencies` (what the storefront offers, the default first, when more than one) and
233
+ `defaultCurrency` (what pages are built in, when it is not `currency`: the store turned its own off):
232
234
 
233
235
  ```ts
234
236
  import type { StoreCommerce } from '@eldrajs/theme-nuxt/commerce';
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.13.0"
6
6
  },
7
- "version": "0.4.6",
7
+ "version": "0.4.8",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { mkdirSync, existsSync, readFileSync, writeFileSync, copyFileSync, cpSync } from 'node:fs';
2
2
  import { join, resolve } from 'node:path';
3
- import { defineNuxtModule, createResolver, addVitePlugin, addPlugin, addImports } from '@nuxt/kit';
4
- import { createEldraClient, resolvePagePath, parseDynamicRoutePattern, catalogRouteTarget, buildDynamicRoutePath, normalizeThemeDesignTokens, EldraClientError, stripStega } from '@eldrajs/theme-core';
3
+ import { defineNuxtModule, createResolver, addVitePlugin, addPlugin, addServerHandler, addImports } from '@nuxt/kit';
4
+ import { VISITOR_COUNTRY_PATH, createEldraClient, resolvePagePath, parseDynamicRoutePattern, catalogRouteTarget, buildDynamicRoutePath, normalizeThemeDesignTokens, EldraClientError, stripStega } from '@eldrajs/theme-core';
5
5
  import { createEldraClient as createEldraClient$1 } from '@eldrajs/sdk';
6
6
  import eldraTheme from '@eldrajs/vite-plugin-theme';
7
7
  import { listCatalogDocs, catalogDocRouteRefs } from '../dist/runtime/catalog.js';
@@ -127,6 +127,11 @@ const eldraModule = defineNuxtModule({
127
127
  };
128
128
  const buildToken = (process.env.ELDRA_BUILD_TOKEN ?? "").trim();
129
129
  addPlugin(resolver.resolve("./runtime/plugin"));
130
+ addServerHandler({
131
+ route: VISITOR_COUNTRY_PATH,
132
+ method: "get",
133
+ handler: resolver.resolve("./runtime/server/visitor")
134
+ });
130
135
  addPlugin(resolver.resolve("./runtime/analyticsPlugin"));
131
136
  if (options.campaignAttribution !== false) {
132
137
  addPlugin({ src: resolver.resolve("./runtime/attributionPlugin"), mode: "client" });
@@ -1,7 +1,7 @@
1
1
  import type { EldraFeatureClient, EldraOrganizationCommerce } from '@eldrajs/sdk';
2
2
  /**
3
3
  * What the store sells in, as it reaches a theme on `runtimeConfig.public.eldra.commerce`:
4
- * `{ currency, taxInclusivePricing, defaultTaxRate }`, or `null`.
4
+ * `{ currency, taxInclusivePricing, defaultTaxRate, currencies?, defaultCurrency? }`, or `null`.
5
5
  *
6
6
  * Published as `@eldrajs/theme-nuxt/commerce`, so a theme reading that key types it from here
7
7
  * instead of hand-writing the record — it is the public contract of a public runtime-config key,
@@ -1,3 +1,4 @@
1
+ import { defaultCurrencyOf, offeredCurrencies } from "@eldrajs/theme-core";
1
2
  export const NO_CURRENCY_WARNING = "[eldra] the store publishes no currency \u2014 prices render as plain numbers";
2
3
  export const READ_TIMEOUT_MS = 1e4;
3
4
  export async function readStoreCommerce(reader, warn = console.warn) {
@@ -33,7 +34,15 @@ function toStoreCommerce(value) {
33
34
  const { currency, taxInclusivePricing, defaultTaxRate } = value;
34
35
  if (typeof currency !== "string" || currency === "") return null;
35
36
  if (typeof taxInclusivePricing !== "boolean" || typeof defaultTaxRate !== "number") return null;
36
- return { currency, taxInclusivePricing, defaultTaxRate };
37
+ const defaultCurrency = defaultCurrencyOf({ ...value, currency });
38
+ const currencies = offeredCurrencies(defaultCurrency, value.currencies);
39
+ return {
40
+ currency,
41
+ taxInclusivePricing,
42
+ defaultTaxRate,
43
+ ...currencies.length > 1 ? { currencies } : {},
44
+ ...defaultCurrency === currency ? {} : { defaultCurrency }
45
+ };
37
46
  }
38
47
  function describe(error) {
39
48
  return error instanceof Error ? error.message : String(error);
@@ -0,0 +1,4 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, {
2
+ country: string | null;
3
+ }>;
4
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { defineEventHandler, getRequestHeader, setResponseHeader } from "h3";
2
+ import { countryFromHeader } from "@eldrajs/theme-core";
3
+ export default defineEventHandler((event) => {
4
+ setResponseHeader(event, "cache-control", "private, no-store");
5
+ return { country: countryFromHeader(getRequestHeader(event, "cf-ipcountry")) };
6
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-nuxt",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
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",
@@ -50,10 +50,11 @@
50
50
  "dependencies": {
51
51
  "@nuxt/kit": "^4.0.0",
52
52
  "defu": "^6.1.4",
53
- "@eldrajs/sdk": "^0.5.2",
54
- "@eldrajs/theme-vue": "^0.2.5",
55
- "@eldrajs/vite-plugin-theme": "^0.3.4",
56
- "@eldrajs/theme-core": "^0.3.4"
53
+ "h3": "^1.15.0",
54
+ "@eldrajs/theme-core": "^0.3.6",
55
+ "@eldrajs/theme-vue": "^0.2.7",
56
+ "@eldrajs/vite-plugin-theme": "^0.3.6",
57
+ "@eldrajs/sdk": "^0.5.4"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@nuxt/module-builder": "^0.8.4",