@eldrajs/theme-nuxt 0.1.1 → 0.3.0

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 (42) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/dist/module.d.mts +48 -2
  3. package/dist/module.d.ts +48 -2
  4. package/dist/module.json +1 -1
  5. package/dist/module.mjs +231 -11
  6. package/dist/runtime/analytics.d.ts +83 -0
  7. package/dist/runtime/analytics.js +83 -0
  8. package/dist/runtime/analyticsPlugin.d.ts +15 -0
  9. package/dist/runtime/analyticsPlugin.js +21 -0
  10. package/dist/runtime/catalog.d.ts +5 -0
  11. package/dist/runtime/catalog.js +6 -3
  12. package/dist/runtime/composables/useEldraAnalytics.d.ts +10 -0
  13. package/dist/runtime/composables/useEldraAnalytics.js +6 -0
  14. package/dist/runtime/composables/useEldraForms.d.ts +8 -0
  15. package/dist/runtime/composables/useEldraForms.js +5 -0
  16. package/dist/runtime/composables/useEldraSeo.d.ts +27 -0
  17. package/dist/runtime/composables/useEldraSeo.js +41 -0
  18. package/dist/runtime/composables/useStructuredData.d.ts +35 -0
  19. package/dist/runtime/composables/useStructuredData.js +55 -0
  20. package/dist/runtime/crawl.d.ts +29 -0
  21. package/dist/runtime/crawl.js +50 -0
  22. package/dist/runtime/crawlOutput.d.ts +54 -0
  23. package/dist/runtime/crawlOutput.js +96 -0
  24. package/dist/runtime/drafts.js +7 -1
  25. package/dist/runtime/forms.d.ts +29 -0
  26. package/dist/runtime/forms.js +154 -0
  27. package/dist/runtime/localeState.d.ts +6 -4
  28. package/dist/runtime/localeState.js +7 -15
  29. package/dist/runtime/plugin.js +7 -2
  30. package/dist/runtime/redirects.d.ts +74 -0
  31. package/dist/runtime/redirects.js +190 -0
  32. package/dist/runtime/seo.d.ts +23 -0
  33. package/dist/runtime/seo.js +95 -0
  34. package/dist/runtime/seoHead.d.ts +27 -0
  35. package/dist/runtime/seoHead.js +28 -0
  36. package/dist/runtime/siteIconAssets.d.ts +19 -0
  37. package/dist/runtime/siteIconAssets.js +29 -0
  38. package/dist/runtime/siteIcons.d.ts +74 -0
  39. package/dist/runtime/siteIcons.js +96 -0
  40. package/dist/runtime/siteProfile.d.ts +56 -0
  41. package/dist/runtime/siteProfile.js +69 -0
  42. package/package.json +6 -5
@@ -0,0 +1,95 @@
1
+ import { SEO_SYNTAX } from "@eldrajs/theme-core";
2
+ export const SEO_WARNING = "[eldra] could not read the platform\u2019s SEO settings \u2014 page titles use the default pattern";
3
+ export const READ_TIMEOUT_MS = 1e4;
4
+ export async function readSeo(reader, warn = console.warn) {
5
+ const read = reader === null ? { setting: null, cause: null } : await readOrNull(reader);
6
+ if (read.setting === null) {
7
+ warn(read.cause === null ? SEO_WARNING : `${SEO_WARNING} (${read.cause})`);
8
+ return null;
9
+ }
10
+ return read.setting;
11
+ }
12
+ async function readOrNull(reader) {
13
+ const controller = new AbortController();
14
+ const timer = setTimeout(
15
+ () => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
16
+ READ_TIMEOUT_MS
17
+ );
18
+ try {
19
+ const response = await reader.request({
20
+ path: "/site/v1/seo",
21
+ signal: controller.signal
22
+ });
23
+ const setting = toSeoSetting(response);
24
+ return {
25
+ setting,
26
+ cause: setting === null ? "the platform published an unusable response" : null
27
+ };
28
+ } catch (error) {
29
+ return { setting: null, cause: error instanceof Error ? error.message : String(error) };
30
+ } finally {
31
+ clearTimeout(timer);
32
+ }
33
+ }
34
+ function toSeoSetting(value) {
35
+ const record = asRecord(value);
36
+ if (record === null) return null;
37
+ if (typeof record.revision !== "number" || !Number.isFinite(record.revision)) return null;
38
+ if (record.syntax !== SEO_SYNTAX) return null;
39
+ const site = asRecord(record.site);
40
+ const templates = asRecord(record.templates);
41
+ if (site === null || templates === null) return null;
42
+ const titlePattern = toLocaleMap(site.titlePattern);
43
+ const description = toLocaleMap(site.description);
44
+ if (titlePattern === null || description === null) return null;
45
+ const name = optionalText(site.name);
46
+ const imageAssetId = optionalText(site.imageAssetId);
47
+ const imageUrl = optionalText(site.imageUrl);
48
+ const twitterHandle = optionalText(site.twitterHandle);
49
+ if (name === void 0 || imageAssetId === void 0 || imageUrl === void 0 || twitterHandle === void 0) {
50
+ return null;
51
+ }
52
+ const byContext = /* @__PURE__ */ Object.create(null);
53
+ for (const [context, raw] of Object.entries(templates)) {
54
+ const entry = asRecord(raw);
55
+ if (entry === null) return null;
56
+ const patterns = {};
57
+ if (entry.titlePattern !== void 0) {
58
+ const map = toLocaleMap(entry.titlePattern);
59
+ if (map === null) return null;
60
+ patterns.titlePattern = map;
61
+ }
62
+ if (entry.descriptionPattern !== void 0) {
63
+ const map = toLocaleMap(entry.descriptionPattern);
64
+ if (map === null) return null;
65
+ patterns.descriptionPattern = map;
66
+ }
67
+ byContext[context] = patterns;
68
+ }
69
+ return {
70
+ revision: record.revision,
71
+ syntax: SEO_SYNTAX,
72
+ site: { name, titlePattern, description, imageAssetId, imageUrl, twitterHandle },
73
+ templates: byContext
74
+ };
75
+ }
76
+ function asRecord(value) {
77
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
78
+ }
79
+ function optionalText(value) {
80
+ if (value === null || value === void 0) return null;
81
+ if (typeof value !== "string") return void 0;
82
+ const text = value.trim();
83
+ return text === "" ? null : text;
84
+ }
85
+ function toLocaleMap(value) {
86
+ if (value === null || value === void 0) return {};
87
+ const record = asRecord(value);
88
+ if (record === null) return null;
89
+ const map = /* @__PURE__ */ Object.create(null);
90
+ for (const [locale, text] of Object.entries(record)) {
91
+ if (typeof text !== "string") return null;
92
+ map[locale] = text;
93
+ }
94
+ return map;
95
+ }
@@ -0,0 +1,27 @@
1
+ import type { ResolvedSeo } from '@eldrajs/theme-core';
2
+ /** A `<meta>` tag as `useHead` takes it. */
3
+ export interface SeoMetaTag {
4
+ name?: string;
5
+ property?: string;
6
+ content: string;
7
+ }
8
+ export interface SeoHead {
9
+ title: string;
10
+ meta: SeoMetaTag[];
11
+ link: {
12
+ rel: 'canonical';
13
+ href: string;
14
+ }[];
15
+ }
16
+ /**
17
+ * The head one resolved route writes: `<title>`, description, canonical, Open Graph, Twitter card
18
+ * and robots. Pure, so a test can read every tag without a Nuxt app.
19
+ *
20
+ * `og:url`, `og:image` and the canonical link are written only when absolute (the resolver
21
+ * returns `null` otherwise); a share card with a relative URL is worse than none. `robots` is
22
+ * written only for `noindex` — an indexable page says nothing, which is the default.
23
+ */
24
+ export declare function buildSeoHead(seo: ResolvedSeo, context: {
25
+ locale: string | null;
26
+ siteName: string;
27
+ }): SeoHead;
@@ -0,0 +1,28 @@
1
+ export function buildSeoHead(seo, context) {
2
+ const meta = [];
3
+ const name = (key, content) => {
4
+ if (content !== null && content !== "") meta.push({ name: key, content });
5
+ };
6
+ const property = (key, content) => {
7
+ if (content !== null && content !== "") meta.push({ property: key, content });
8
+ };
9
+ name("description", seo.description);
10
+ property("og:title", seo.ogTitle);
11
+ property("og:description", seo.ogDescription);
12
+ property("og:type", seo.ogType);
13
+ property("og:site_name", context.siteName);
14
+ property("og:locale", context.locale === null ? null : context.locale.replace("-", "_"));
15
+ property("og:url", seo.canonical);
16
+ property("og:image", seo.image);
17
+ name("twitter:card", seo.image === null ? "summary" : "summary_large_image");
18
+ name("twitter:title", seo.ogTitle);
19
+ name("twitter:description", seo.ogDescription);
20
+ name("twitter:image", seo.image);
21
+ name("twitter:site", seo.twitterSite);
22
+ if (seo.noindex) name("robots", "noindex");
23
+ return {
24
+ title: seo.title,
25
+ meta,
26
+ link: seo.canonical === null ? [] : [{ rel: "canonical", href: seo.canonical }]
27
+ };
28
+ }
@@ -0,0 +1,19 @@
1
+ import type { ResolvedSiteIcons } from './siteIcons.js';
2
+ /** One file the build writes into the static output. */
3
+ export interface GeneratedIconFile {
4
+ /** Path relative to the site root. */
5
+ name: string;
6
+ data: Buffer;
7
+ }
8
+ export interface SiteIconOutput {
9
+ /** Only `site.webmanifest`: every image is linked straight from the media CDN. */
10
+ files: GeneratedIconFile[];
11
+ link: Record<string, string>[];
12
+ meta: Record<string, string>[];
13
+ }
14
+ /**
15
+ * The web manifest and head tags for a resolved site icon setting. Pure and in-memory — no image
16
+ * is fetched or processed here: the media worker renders every size (always PNG), Core builds the
17
+ * URLs, and this only points at them. The manifest is same-origin JSON (a browser requires it).
18
+ */
19
+ export declare function buildSiteIconOutput(setting: Pick<ResolvedSiteIcons, 'icons' | 'backgroundColor' | 'themeColor' | 'shortName' | 'name'>, baseURL?: string): SiteIconOutput;
@@ -0,0 +1,29 @@
1
+ export function buildSiteIconOutput(setting, baseURL = "/") {
2
+ const base = baseURL.endsWith("/") ? baseURL : `${baseURL}/`;
3
+ const { icons } = setting;
4
+ const name = setting.name ?? setting.shortName;
5
+ const manifest = {
6
+ ...name === null ? {} : { name },
7
+ ...setting.shortName === null ? {} : { short_name: setting.shortName },
8
+ icons: [
9
+ { src: icons.icon192, sizes: "192x192", type: "image/png" },
10
+ { src: icons.icon512, sizes: "512x512", type: "image/png" },
11
+ { src: icons.maskable512, sizes: "512x512", type: "image/png", purpose: "maskable" }
12
+ ],
13
+ ...setting.themeColor === null ? {} : { theme_color: setting.themeColor },
14
+ background_color: setting.backgroundColor,
15
+ display: "standalone",
16
+ start_url: base
17
+ };
18
+ return {
19
+ files: [
20
+ { name: "site.webmanifest", data: Buffer.from(JSON.stringify(manifest, null, 2) + "\n") }
21
+ ],
22
+ link: [
23
+ { rel: "icon", type: "image/png", sizes: "32x32", href: icons.favicon32 },
24
+ { rel: "apple-touch-icon", href: icons.appleTouch180 },
25
+ { rel: "manifest", href: `${base}site.webmanifest` }
26
+ ],
27
+ meta: setting.themeColor === null ? [] : [{ name: "theme-color", content: setting.themeColor }]
28
+ };
29
+ }
@@ -0,0 +1,74 @@
1
+ import type { EldraClient } from '@eldrajs/sdk';
2
+ /**
3
+ * The site's icon setting exactly as `GET /site/v1/site-icons` answers it (and Studio's
4
+ * `PUT /sites/{siteId}/site-icons` stores it). `iconUrl: null` means "no icons set": the theme's
5
+ * own `public/` files and head tags stay. The colour and short-name defaults (the theme's primary
6
+ * token, the site name) are resolved by the **build** — `resolveSiteIcons` below — never by Core.
7
+ */
8
+ export interface SiteIconsSetting {
9
+ revision: number;
10
+ /** The media-library asset URL (`{media}/public/{orgId}/assets/{assetId}`), or `null` when no icon is set. */
11
+ iconUrl: string | null;
12
+ /** `#rrggbb`. Paints the iOS icon and the maskable Android icon, which cannot be transparent. */
13
+ backgroundColor: string;
14
+ /** `#rrggbb`, or `null` for the theme's primary design token. */
15
+ themeColor: string | null;
16
+ /** 1–12 characters, or `null` for the site name. */
17
+ shortName: string | null;
18
+ /**
19
+ * The rendered variants, built by Core (the only place that knows the media worker's icon
20
+ * suffixes) — `null` exactly when `iconUrl` is `null`. The build links to these, never renders.
21
+ */
22
+ icons: SiteIconUrls | null;
23
+ }
24
+ /** Absolute media URLs of the icon variants the media worker renders (always `image/png`). */
25
+ export interface SiteIconUrls {
26
+ favicon32: string;
27
+ appleTouch180: string;
28
+ icon192: string;
29
+ icon512: string;
30
+ maskable512: string;
31
+ }
32
+ /**
33
+ * The slice of an `@eldrajs/sdk` client this read needs — a whole `EldraClient` satisfies it. The
34
+ * same narrow shape, for the same reasons, as `DesignTokensReader`: `GET /site/v1/site-icons` is a
35
+ * site-module read with no typed `features.*` method, so the client's generic `request` carries it.
36
+ */
37
+ export interface SiteIconsReader {
38
+ request: EldraClient['request'];
39
+ }
40
+ /** The one line a build prints when it could not read the platform's site icons. */
41
+ export declare const SITE_ICONS_WARNING = "[eldra] could not read the platform\u2019s site icons \u2014 keeping the theme\u2019s own icon files";
42
+ /** How long the build waits for the answer; see `READ_TIMEOUT_MS` in `./designTokens.ts`. */
43
+ export declare const READ_TIMEOUT_MS = 10000;
44
+ /** Android's launcher shows at most about this many characters of `short_name`. */
45
+ export declare const SHORT_NAME_MAX = 12;
46
+ /**
47
+ * The platform's site-icon setting, or `null`.
48
+ *
49
+ * Fail-soft exactly like `readDesignTokens`: no client, an unreachable gateway, a timeout and a
50
+ * response that is not the documented shape all end in `null` and **one** warning, so a theme keeps
51
+ * deploying with the icon files it ships. A well-formed answer with `iconUrl: null` is **not** a
52
+ * failure — it is the normal "nothing set" state — and warns nothing.
53
+ */
54
+ export declare function readSiteIcons(reader: SiteIconsReader | null, warn?: (message: string) => void): Promise<SiteIconsSetting | null>;
55
+ /** The values the generated files and tags are made from, defaults filled in. */
56
+ export interface ResolvedSiteIcons {
57
+ iconUrl: string;
58
+ icons: SiteIconUrls;
59
+ backgroundColor: string;
60
+ /** `null` when neither the setting nor the theme gives one — the meta tag is then omitted. */
61
+ themeColor: string | null;
62
+ /** `null` when neither the setting nor a site name gives one. */
63
+ shortName: string | null;
64
+ name: string | null;
65
+ }
66
+ /**
67
+ * Fills in the defaults Core deliberately does not store: the theme colour falls back to the
68
+ * theme's primary design token, the short name to the site name (cut to Android's limit). `null`
69
+ * when no icon is set, which is the signal to leave the theme's own files alone.
70
+ */
71
+ export declare function resolveSiteIcons(setting: SiteIconsSetting | null, defaults: {
72
+ siteName?: string | null;
73
+ primaryToken?: string | null;
74
+ }): ResolvedSiteIcons | null;
@@ -0,0 +1,96 @@
1
+ const ICON_URL_KEYS = ["favicon32", "appleTouch180", "icon192", "icon512", "maskable512"];
2
+ export const SITE_ICONS_WARNING = "[eldra] could not read the platform\u2019s site icons \u2014 keeping the theme\u2019s own icon files";
3
+ export const READ_TIMEOUT_MS = 1e4;
4
+ export const SHORT_NAME_MAX = 12;
5
+ const HEX_COLOR = /^#[0-9a-f]{6}$/i;
6
+ export async function readSiteIcons(reader, warn = console.warn) {
7
+ const read = reader === null ? { setting: null, cause: null } : await readOrNull(reader);
8
+ if (read.setting === null) {
9
+ warn(read.cause === null ? SITE_ICONS_WARNING : `${SITE_ICONS_WARNING} (${read.cause})`);
10
+ return null;
11
+ }
12
+ return read.setting;
13
+ }
14
+ async function readOrNull(reader) {
15
+ const controller = new AbortController();
16
+ const timer = setTimeout(
17
+ () => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
18
+ READ_TIMEOUT_MS
19
+ );
20
+ try {
21
+ const response = await reader.request({
22
+ path: "/site/v1/site-icons",
23
+ signal: controller.signal
24
+ });
25
+ const setting = toSiteIconsSetting(response);
26
+ return {
27
+ setting,
28
+ cause: setting === null ? "the platform published an unusable response" : null
29
+ };
30
+ } catch (error) {
31
+ return { setting: null, cause: error instanceof Error ? error.message : String(error) };
32
+ } finally {
33
+ clearTimeout(timer);
34
+ }
35
+ }
36
+ function toSiteIconsSetting(value) {
37
+ if (typeof value !== "object" || value === null) return null;
38
+ const record = value;
39
+ if (typeof record.revision !== "number" || !Number.isFinite(record.revision)) return null;
40
+ const { iconUrl, backgroundColor, themeColor, shortName } = record;
41
+ if (iconUrl !== null && typeof iconUrl !== "string") return null;
42
+ if (typeof backgroundColor !== "string" || !HEX_COLOR.test(backgroundColor)) return null;
43
+ if (themeColor !== null && (typeof themeColor !== "string" || !HEX_COLOR.test(themeColor))) {
44
+ return null;
45
+ }
46
+ if (shortName !== null && typeof shortName !== "string") return null;
47
+ const icons = toSiteIconUrls(record.icons);
48
+ if (icons === void 0) return null;
49
+ if ((iconUrl === null || iconUrl === "") !== (icons === null)) return null;
50
+ return {
51
+ revision: record.revision,
52
+ iconUrl: iconUrl === "" ? null : iconUrl,
53
+ backgroundColor: backgroundColor.toLowerCase(),
54
+ themeColor: themeColor === null ? null : themeColor.toLowerCase(),
55
+ shortName: shortName === null ? null : truncateRunes(shortName.trim(), SHORT_NAME_MAX) || null,
56
+ icons
57
+ };
58
+ }
59
+ function toSiteIconUrls(value) {
60
+ if (value === null) return null;
61
+ if (typeof value !== "object") return void 0;
62
+ const record = value;
63
+ const urls = {};
64
+ for (const key of ICON_URL_KEYS) {
65
+ const url = record[key];
66
+ if (typeof url !== "string" || !isAbsoluteHttpUrl(url)) return void 0;
67
+ urls[key] = url;
68
+ }
69
+ return urls;
70
+ }
71
+ function isAbsoluteHttpUrl(value) {
72
+ try {
73
+ const { protocol, hostname } = new URL(value);
74
+ if (protocol === "https:") return true;
75
+ return protocol === "http:" && (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]");
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
80
+ export function resolveSiteIcons(setting, defaults) {
81
+ if (setting === null || setting.iconUrl === null || setting.icons === null) return null;
82
+ const siteName = defaults.siteName?.trim() || null;
83
+ const primary = defaults.primaryToken ?? null;
84
+ const name = siteName ?? setting.shortName;
85
+ return {
86
+ iconUrl: setting.iconUrl,
87
+ icons: setting.icons,
88
+ backgroundColor: setting.backgroundColor,
89
+ themeColor: setting.themeColor ?? (primary !== null && HEX_COLOR.test(primary) ? primary : null),
90
+ shortName: setting.shortName ?? (siteName === null ? null : truncateRunes(siteName, 12)),
91
+ name
92
+ };
93
+ }
94
+ function truncateRunes(value, max) {
95
+ return Array.from(value).slice(0, max).join("").trim();
96
+ }
@@ -0,0 +1,56 @@
1
+ import type { EldraClient } from '@eldrajs/sdk';
2
+ /**
3
+ * The site's public profile exactly as `GET /site/v1/site-profile` answers it (and Studio's
4
+ * `PUT /sites/{siteId}/site-profile` stores it): what the structured data's `Organization` says
5
+ * about the shop. Every field may be unset; the build fills the gaps (`resolveSiteProfile`).
6
+ */
7
+ export interface SiteProfileSetting {
8
+ revision: number;
9
+ /** The organisation's display name, or `null` for the site name. */
10
+ name: string | null;
11
+ /** A logo override (absolute), or `null` for the site icon's 512 px rendering. */
12
+ logoUrl: string | null;
13
+ /** Social profile URLs (https). */
14
+ sameAs: string[];
15
+ contact: {
16
+ email: string | null;
17
+ telephone: string | null;
18
+ };
19
+ }
20
+ /** What a page's `Organization` is written from: gaps already filled, `name` never empty. */
21
+ export interface ResolvedSiteProfile {
22
+ name: string;
23
+ logoUrl: string | null;
24
+ sameAs: string[];
25
+ contact: {
26
+ email: string | null;
27
+ telephone: string | null;
28
+ };
29
+ }
30
+ /**
31
+ * The slice of an `@eldrajs/sdk` client this read needs — a whole `EldraClient` satisfies it. The
32
+ * same narrow shape as `SiteIconsReader`: `GET /site/v1/site-profile` is a site-module read with no
33
+ * typed `features.*` method, so the client's generic `request` carries it.
34
+ */
35
+ export interface SiteProfileReader {
36
+ request: EldraClient['request'];
37
+ }
38
+ /** The one line a build prints when it could not read the platform's site profile. */
39
+ export declare const SITE_PROFILE_WARNING = "[eldra] could not read the platform\u2019s site profile \u2014 the Organization structured data uses the site name and icon only";
40
+ /** How long the build waits for the answer; see `READ_TIMEOUT_MS` in `./designTokens.ts`. */
41
+ export declare const READ_TIMEOUT_MS = 10000;
42
+ /**
43
+ * The platform's site profile, or `null`. Fail-soft exactly like `readSiteIcons`: no client, an
44
+ * unreachable gateway, a timeout and an answer that is not the documented shape all end in `null`
45
+ * and **one** warning; the build still writes valid markup, from the site name and icon.
46
+ */
47
+ export declare function readSiteProfile(reader: SiteProfileReader | null, warn?: (message: string) => void): Promise<SiteProfileSetting | null>;
48
+ /**
49
+ * Fills in what the profile leaves unset: the name falls back to the site name, the logo to the
50
+ * site icon's 512 px rendering (`icon512`, not the maskable one: Google wants a logo, not a
51
+ * padded launcher icon). Always answers, so a build whose read failed still has an Organization.
52
+ */
53
+ export declare function resolveSiteProfile(setting: SiteProfileSetting | null, defaults: {
54
+ siteName: string;
55
+ iconLogoUrl: string | null;
56
+ }): ResolvedSiteProfile;
@@ -0,0 +1,69 @@
1
+ export const SITE_PROFILE_WARNING = "[eldra] could not read the platform\u2019s site profile \u2014 the Organization structured data uses the site name and icon only";
2
+ export const READ_TIMEOUT_MS = 1e4;
3
+ export async function readSiteProfile(reader, warn = console.warn) {
4
+ const read = reader === null ? { setting: null, cause: null } : await readOrNull(reader);
5
+ if (read.setting === null) {
6
+ warn(read.cause === null ? SITE_PROFILE_WARNING : `${SITE_PROFILE_WARNING} (${read.cause})`);
7
+ return null;
8
+ }
9
+ return read.setting;
10
+ }
11
+ async function readOrNull(reader) {
12
+ const controller = new AbortController();
13
+ const timer = setTimeout(
14
+ () => controller.abort(new Error(`timed out after ${READ_TIMEOUT_MS}ms`)),
15
+ READ_TIMEOUT_MS
16
+ );
17
+ try {
18
+ const response = await reader.request({
19
+ path: "/site/v1/site-profile",
20
+ signal: controller.signal
21
+ });
22
+ const setting = toSiteProfile(response);
23
+ return {
24
+ setting,
25
+ cause: setting === null ? "the platform published an unusable response" : null
26
+ };
27
+ } catch (error) {
28
+ return { setting: null, cause: error instanceof Error ? error.message : String(error) };
29
+ } finally {
30
+ clearTimeout(timer);
31
+ }
32
+ }
33
+ function toSiteProfile(value) {
34
+ if (typeof value !== "object" || value === null) return null;
35
+ const record = value;
36
+ if (typeof record.revision !== "number" || !Number.isFinite(record.revision)) return null;
37
+ const { name, logoUrl, sameAs, contact } = record;
38
+ if (name !== null && typeof name !== "string") return null;
39
+ if (logoUrl !== null && typeof logoUrl !== "string") return null;
40
+ if (!Array.isArray(sameAs) || sameAs.some((url) => typeof url !== "string")) return null;
41
+ if (typeof contact !== "object" || contact === null) return null;
42
+ const { email, telephone } = contact;
43
+ if (email !== null && typeof email !== "string") return null;
44
+ if (telephone !== null && typeof telephone !== "string") return null;
45
+ return {
46
+ revision: record.revision,
47
+ name: name === null ? null : name.trim() || null,
48
+ logoUrl: logoUrl !== null && isHttpsUrl(logoUrl) ? logoUrl : null,
49
+ // A profile link that is not https is dropped, not repaired: a wrong `sameAs` claims an
50
+ // identity the shop may not hold.
51
+ sameAs: sameAs.map((url) => url.trim()).filter(isHttpsUrl),
52
+ contact: { email: email?.trim() || null, telephone: telephone?.trim() || null }
53
+ };
54
+ }
55
+ function isHttpsUrl(value) {
56
+ try {
57
+ return new URL(value).protocol === "https:";
58
+ } catch {
59
+ return false;
60
+ }
61
+ }
62
+ export function resolveSiteProfile(setting, defaults) {
63
+ return {
64
+ name: setting?.name ?? defaults.siteName,
65
+ logoUrl: setting?.logoUrl ?? defaults.iconLogoUrl,
66
+ sameAs: setting?.sameAs ?? [],
67
+ contact: setting?.contact ?? { email: null, telephone: null }
68
+ };
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-nuxt",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
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,16 +46,17 @@
46
46
  "dependencies": {
47
47
  "@nuxt/kit": "^4.0.0",
48
48
  "defu": "^6.1.4",
49
- "@eldrajs/sdk": "^0.2.9",
50
- "@eldrajs/theme-core": "^0.1.0",
51
- "@eldrajs/theme-vue": "^0.1.0",
52
- "@eldrajs/vite-plugin-theme": "^0.1.0"
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"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@nuxt/module-builder": "^0.8.4",
56
56
  "@nuxt/schema": "^4.0.0",
57
57
  "@playwright/test": "1.62.1",
58
58
  "execa": "^9.5.2",
59
+ "jsdom": "30.1.0",
59
60
  "nuxt": "^4.0.0"
60
61
  },
61
62
  "engines": {