@tokenoftrust/storefront-runner 7.9.12 → 7.10.1

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.
@@ -3,7 +3,7 @@
3
3
  * <Seo> — per-page title/meta, Open Graph, Twitter card, canonical, JSON-LD.
4
4
  * (brief §8). Tenant-aware: OG image + site name come from the resolved tenant.
5
5
  */
6
- import { articleSeoMetaTags, resolveOgImage, type ArticleMeta } from "@/lib/content/seo/meta.js";
6
+ import { articleSeoMetaTags, resolveOgImage, siteVerificationMetaTags, type ArticleMeta } from "@/lib/content/seo/meta.js";
7
7
  import { withXDefault, type Alternate } from "@/lib/content/seo/alternates.js";
8
8
  import { safeJsonScriptContent } from "@/lib/content/shared/jsonScript";
9
9
  import { documentTitle } from "@/lib/content/seo/documentTitle";
@@ -90,6 +90,7 @@ const articleMeta = articleSeoMetaTags({
90
90
  twitterCreator,
91
91
  });
92
92
 
93
+ const siteVerification = siteVerificationMetaTags(tenant.seo?.siteVerification);
93
94
  const graphs = jsonLd ? (Array.isArray(jsonLd) ? jsonLd : [jsonLd]) : [];
94
95
  const alternateLinks = withXDefault(alternates);
95
96
  const paginationLinks = [
@@ -102,6 +103,7 @@ const paginationLinks = [
102
103
  {description && <meta name="description" content={description} />}
103
104
  <link rel="canonical" href={canonical} />
104
105
  {noindex && <meta name="robots" content="noindex,nofollow" />}
106
+ {siteVerification.map((t) => <meta name={t.name} content={t.content} />)}
105
107
 
106
108
  {
107
109
  paginationLinks.map((l) => <link rel={l.rel} href={l.href} />)
@@ -34,6 +34,34 @@ export interface ArticleSeoInput {
34
34
  twitterCreator?: string;
35
35
  }
36
36
 
37
+ /** The tenant's declared `seo.siteVerification` (tenant.ts `SeoDeclaration`). */
38
+ export interface SiteVerificationDeclaration {
39
+ google?: string | string[];
40
+ bing?: string | string[];
41
+ }
42
+
43
+ const SITE_VERIFICATION_META_NAMES = [
44
+ ["google", "google-site-verification"],
45
+ ["bing", "msvalidate.01"],
46
+ ] as const;
47
+
48
+ /** A verification token is a bare token; anything else (markup, quotes) is dropped, never escaped into a page. */
49
+ const SITE_VERIFICATION_TOKEN = /^[A-Za-z0-9._-]{1,200}$/;
50
+
51
+ /** One `<meta name content>` per declared, well-formed token, Google first then Bing. */
52
+ export function siteVerificationMetaTags(declared: SiteVerificationDeclaration | undefined): MetaTag[] {
53
+ if (!declared || typeof declared !== "object") return [];
54
+ const tags: MetaTag[] = [];
55
+ for (const [key, name] of SITE_VERIFICATION_META_NAMES) {
56
+ const value = declared[key];
57
+ const tokens = Array.isArray(value) ? value : value === undefined ? [] : [value];
58
+ for (const token of new Set(tokens)) {
59
+ if (typeof token === "string" && SITE_VERIFICATION_TOKEN.test(token)) tags.push({ name, content: token });
60
+ }
61
+ }
62
+ return tags;
63
+ }
64
+
37
65
  /**
38
66
  * The og:image/twitter:image URL, or `null` when neither the page nor the
39
67
  * tenant's theme declares one. Never falls back to a platform placeholder --
@@ -25,6 +25,7 @@ import {
25
25
  type ConsentSnapshot,
26
26
  } from "@tot/public-runtime";
27
27
  import { reportTrackingChainHealth } from "../../measurement/tracking/interactionHealth.js";
28
+ import { siteVerificationMetaTags, type SiteVerificationDeclaration } from "../seo/meta.js";
28
29
  import { ASYNC_CSS_SWAP_JS } from "./asyncCss.js";
29
30
  import { ROOT_SERVED_HREF_NAMESPACES, withBase } from "../../publication/shared/basePath.js";
30
31
 
@@ -425,6 +426,11 @@ export function rawHtmlResponse(
425
426
  * popup off serves none on this path either. Omitted keeps the document's own.
426
427
  */
427
428
  arrivalPopup?: boolean;
429
+ /**
430
+ * The tenant's declared `seo.siteVerification`: its meta tags are added to the head, matching
431
+ * <Seo>. A tag the document already carries is not repeated.
432
+ */
433
+ siteVerification?: SiteVerificationDeclaration;
428
434
  },
429
435
  ): Response {
430
436
  let composed =
@@ -470,6 +476,10 @@ export function rawHtmlResponse(
470
476
  composed = nonceInlineTags(composed, opts.nonce);
471
477
  const phases = renderIntegrationPhases(opts.plan, opts.nonce, opts.consentSnapshot);
472
478
  composed = injectHeadStart(composed, phases.head);
479
+ const verification = siteVerificationMetaTags(opts.siteVerification)
480
+ .map((t) => `<meta name="${t.name}" content="${t.content}">`)
481
+ .join("");
482
+ if (verification) composed = injectHeadStart(composed, verification);
473
483
  composed = injectBodyStart(composed, phases.bodyStart);
474
484
  if (opts.complianceTop) composed = injectBodyStart(composed, opts.complianceTop);
475
485
  composed = injectBodyEnd(composed, phases.bodyDeferred);
@@ -114,10 +114,11 @@ if (!blogPostProps) {
114
114
  complianceTop: complianceChrome.top || undefined,
115
115
  complianceBottom: complianceChrome.bottom || undefined,
116
116
  arrivalPopup: arrivalPopupEnabled(tenant),
117
+ siteVerification: tenant.seo?.siteVerification,
117
118
  });
118
119
  }
119
120
 
120
- page = await content.getPage(slug);
121
+ page =await content.getPage(slug);
121
122
  if (!page) return new Response(null, { status: 404 });
122
123
  }
123
124
 
@@ -100,6 +100,7 @@ if (rawHtml && rawPolicy.allowed) {
100
100
  complianceTop: complianceChrome.top || undefined,
101
101
  complianceBottom: complianceChrome.bottom || undefined,
102
102
  arrivalPopup: arrivalPopupEnabled(tenant),
103
+ siteVerification: tenant.seo?.siteVerification,
103
104
  });
104
105
  }
105
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.9.12",
3
+ "version": "7.10.1",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -142,7 +142,7 @@ export function resolveStoreTimeZone(declared) {
142
142
 
143
143
 
144
144
  /** Every `seo` key (mirrors packages/public-runtime/src/declared-tenant-config.mjs). */
145
- export const SEO_KEYS = Object.freeze(["trailingSlash", "verbatimSeoTitles", "structuredData"]);
145
+ export const SEO_KEYS = Object.freeze(["trailingSlash", "verbatimSeoTitles", "structuredData", "siteVerification"]);
146
146
 
147
147
  /** Every `seo.structuredData` key. */
148
148
  export const STRUCTURED_DATA_KEYS = Object.freeze(["graphs", "names", "reviews", "onlyOn"]);
@@ -179,6 +179,31 @@ export const STRUCTURED_DATA_NAME_SOURCES = Object.freeze(["documentTitle", "tit
179
179
  const isPlainObject = (value) =>
180
180
  value !== null && typeof value === "object" && !Array.isArray(value);
181
181
 
182
+ /** Search-engine site-verification tokens: `seo.siteVerification` keys. */
183
+ export const SITE_VERIFICATION_KEYS = Object.freeze(["google", "bing"]);
184
+ /** A verification token is a bare token, never markup: letters, digits, `_`, `-`, `.`. */
185
+ export const SITE_VERIFICATION_TOKEN = /^[A-Za-z0-9._-]{1,200}$/;
186
+
187
+ /**
188
+ * @param {unknown} value
189
+ * @returns {string[]}
190
+ */
191
+ function siteVerificationProblems(value) {
192
+ if (!isPlainObject(value)) return ["`seo.siteVerification` must be an object"];
193
+ const problems = [];
194
+ for (const [key, tokens] of Object.entries(/** @type {Record<string, unknown>} */ (value))) {
195
+ if (!SITE_VERIFICATION_KEYS.includes(key)) {
196
+ problems.push(`\`seo.siteVerification.${key}\` is not a search engine (${SITE_VERIFICATION_KEYS.join(", ")})`);
197
+ continue;
198
+ }
199
+ const list = Array.isArray(tokens) ? tokens : [tokens];
200
+ if (list.length === 0 || !list.every((t) => typeof t === "string" && SITE_VERIFICATION_TOKEN.test(t))) {
201
+ problems.push(`\`seo.siteVerification.${key}\` must be a verification token (or a list of them): letters, digits, "_", "-", "."; paste the content value, not the whole tag`);
202
+ }
203
+ }
204
+ return problems;
205
+ }
206
+
182
207
  /**
183
208
  * What is wrong with a declared `seo` value, one sentence per problem; `[]` when it is valid.
184
209
  * A profile that names a node or page type the renderer does not build is refused whole: a
@@ -200,6 +225,7 @@ export function seoDeclarationProblems(seo) {
200
225
  if (source.verbatimSeoTitles !== undefined && typeof source.verbatimSeoTitles !== "boolean") {
201
226
  problems.push("`seo.verbatimSeoTitles` must be true or false");
202
227
  }
228
+ if (source.siteVerification !== undefined) problems.push(...siteVerificationProblems(source.siteVerification));
203
229
  const sd = source.structuredData;
204
230
  if (sd === undefined) return problems;
205
231
  if (!isPlainObject(sd)) return [...problems, "`seo.structuredData` must be an object"];
@@ -579,30 +579,39 @@ export function createCaptureArtifactRewriter(rewrites: readonly CaptureRewrite[
579
579
  // once, at each `/`, to find the only rewrites with a needle that can occur in it: wherever a needle
580
580
  // occurs, a `/` is followed by its anchor. A rewrite with a needle lacking an anchor (no slash, or
581
581
  // fewer characters after it) is always tried.
582
+ // A file name shorter than the anchor length is its own anchor (its whole text), so short names
583
+ // such as `2-4.avif` are indexed rather than always tried. `anchorLengths` records the distinct
584
+ // anchor lengths in use, and an artifact is probed once per length at each `/`.
582
585
  const anchored = new Map<string, number[]>();
586
+ const anchorLengths = new Set<number>();
583
587
  const always: number[] = [];
584
588
  prepared.forEach(({ needles }, index) => {
585
589
  const anchors = new Set<string>();
586
590
  for (const needle of needles) {
587
591
  const slash = needle.lastIndexOf("/");
588
- if (slash < 0 || needle.length - slash - 1 < REWRITE_ANCHOR_LENGTH) {
592
+ if (slash < 0 || slash === needle.length - 1) {
589
593
  always.push(index);
590
594
  return;
591
595
  }
592
- anchors.add(needle.substr(slash + 1, REWRITE_ANCHOR_LENGTH));
596
+ const anchor = needle.substr(slash + 1, REWRITE_ANCHOR_LENGTH);
597
+ anchors.add(anchor);
593
598
  }
594
599
  for (const anchor of anchors) {
600
+ anchorLengths.add(anchor.length);
595
601
  const list = anchored.get(anchor);
596
602
  if (list) list.push(index);
597
603
  else anchored.set(anchor, [index]);
598
604
  }
599
605
  });
606
+ const lengths = [...anchorLengths].sort((a, b) => a - b);
600
607
  const candidatesIn = (content: string): number[] => {
601
608
  if (anchored.size === 0) return always;
602
609
  const found = new Set<number>(always);
603
610
  for (let at = content.indexOf("/"); at !== -1; at = content.indexOf("/", at + 1)) {
604
- const list = anchored.get(content.substr(at + 1, REWRITE_ANCHOR_LENGTH));
605
- if (list) for (const index of list) found.add(index);
611
+ for (const length of lengths) {
612
+ const list = anchored.get(content.substr(at + 1, length));
613
+ if (list) for (const index of list) found.add(index);
614
+ }
606
615
  }
607
616
  return [...found].sort((a, b) => a - b);
608
617
  };
@@ -142,6 +142,8 @@ export interface CheckoutOrderListFilters {
142
142
  status?: string;
143
143
  /** Optional redeemed coupon code filter (case-insensitive). */
144
144
  coupon?: string;
145
+ /** Free-text search over the whole book before paging (case-insensitive): order id, SKU, product name, coupon, status. */
146
+ q?: string;
145
147
  /** ISO datetime lower bound. */
146
148
  from?: string;
147
149
  /** ISO datetime upper bound. */
@@ -83,7 +83,7 @@ export const FEATURE_KEYS = Object.freeze([
83
83
  export const SITE_TYPES_LIST = Object.freeze(["commerce", "marketing"]);
84
84
 
85
85
  /** Every `seo` key (SeoDeclaration, tenant.ts). */
86
- export const SEO_KEYS = Object.freeze(["trailingSlash", "verbatimSeoTitles", "structuredData"]);
86
+ export const SEO_KEYS = Object.freeze(["trailingSlash", "verbatimSeoTitles", "structuredData", "siteVerification"]);
87
87
 
88
88
  /** Every `seo.structuredData` key. */
89
89
  export const STRUCTURED_DATA_KEYS = Object.freeze(["graphs", "names", "reviews", "onlyOn"]);
@@ -195,6 +195,31 @@ const SITE_TYPES = new Set(SITE_TYPES_LIST);
195
195
  const isPlainObject = (value) =>
196
196
  value !== null && typeof value === "object" && !Array.isArray(value);
197
197
 
198
+ /** Search-engine site-verification tokens: `seo.siteVerification` keys. */
199
+ export const SITE_VERIFICATION_KEYS = Object.freeze(["google", "bing"]);
200
+ /** A verification token is a bare token, never markup: letters, digits, `_`, `-`, `.`. */
201
+ export const SITE_VERIFICATION_TOKEN = /^[A-Za-z0-9._-]{1,200}$/;
202
+
203
+ /**
204
+ * @param {unknown} value
205
+ * @returns {string[]}
206
+ */
207
+ function siteVerificationProblems(value) {
208
+ if (!isPlainObject(value)) return ["`seo.siteVerification` must be an object"];
209
+ const problems = [];
210
+ for (const [key, tokens] of Object.entries(/** @type {Record<string, unknown>} */ (value))) {
211
+ if (!SITE_VERIFICATION_KEYS.includes(key)) {
212
+ problems.push(`\`seo.siteVerification.${key}\` is not a search engine (${SITE_VERIFICATION_KEYS.join(", ")})`);
213
+ continue;
214
+ }
215
+ const list = Array.isArray(tokens) ? tokens : [tokens];
216
+ if (list.length === 0 || !list.every((t) => typeof t === "string" && SITE_VERIFICATION_TOKEN.test(t))) {
217
+ problems.push(`\`seo.siteVerification.${key}\` must be a verification token (or a list of them): letters, digits, "_", "-", "."; paste the content value, not the whole tag`);
218
+ }
219
+ }
220
+ return problems;
221
+ }
222
+
198
223
  /**
199
224
  * What is wrong with a declared `seo` value, one sentence per problem; `[]` when it is valid.
200
225
  * A profile that names a node or page type the renderer does not build is refused whole: a
@@ -216,6 +241,7 @@ export function seoDeclarationProblems(seo) {
216
241
  if (source.verbatimSeoTitles !== undefined && typeof source.verbatimSeoTitles !== "boolean") {
217
242
  problems.push("`seo.verbatimSeoTitles` must be true or false");
218
243
  }
244
+ if (source.siteVerification !== undefined) problems.push(...siteVerificationProblems(source.siteVerification));
219
245
  const sd = source.structuredData;
220
246
  if (sd === undefined) return problems;
221
247
  if (!isPlainObject(sd)) return [...problems, "`seo.structuredData` must be an object"];
@@ -879,6 +879,16 @@ export interface SeoDeclaration {
879
879
  * suffixed with the store name unless it already names the store.
880
880
  */
881
881
  verbatimSeoTitles?: boolean;
882
+ /**
883
+ * Search-engine site-verification tokens (the `content` value of the engine's meta tag, never the
884
+ * whole tag). Rendered on every page as `<meta name="google-site-verification">` and
885
+ * `<meta name="msvalidate.01">`. A list verifies several properties. A root verification file
886
+ * (`public/google<token>.html`, `public/BingSiteAuth.xml`) is served at `/<filename>` as-is.
887
+ */
888
+ siteVerification?: {
889
+ google?: string | string[];
890
+ bing?: string | string[];
891
+ };
882
892
  /**
883
893
  * The structured-data profile. When present it is the ONLY JSON-LD a declared page type
884
894
  * emits: one `@graph` holding exactly the listed nodes, in order. A node whose data the