diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1f7304b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + +jobs: + quality-gate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - uses: actions/setup-node@v4 + with: + node-version: 22 + + - run: bun install --frozen-lockfile + + - run: bun run lint + + - run: bun run typecheck + + - run: bun run test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..520ccb1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,35 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: read + id-token: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org/ + + - run: bun install --frozen-lockfile + + - run: bun run build + + - run: bun run test + + - run: npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d9f18a --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +node_modules/ +dist/ +coverage/ +*.log +.DS_Store +.env +.env.* +playwright-report/ +test-results/ +.blob-storage/ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..ba12a20 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +dist/ +coverage/ +node_modules/ +bun.lock* +package-lock.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..1563a4a --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "printWidth": 100, + "singleQuote": true, + "trailingComma": "all", + "semi": true +} diff --git a/AGENTS.md b/AGENTS.md index 15947cf..c7d01f4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,3 +13,11 @@ Defaults: the five canonical role names are used as-is. See `docs/agents/triage- ### Domain docs Single-context: one `GLOSSARY.md` + `docs/adr/` at the repo root. See `docs/agents/domain.md`. + +## House rules + +- No code comments anywhere; express intent through self-documenting code. Compiler/linter directives are the only exception. +- Never commit to `main` directly; work on feature branches or worktrees. +- Claim tickets by self-assignment before starting work. +- Keep commits small and focused, one concern per commit. +- Use conventional-commit messages (`feat:`, `fix:`, `docs:`, `chore:`, `test:`, `refactor:`, `build:`, `ci:`). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b64367b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Expert Vision Software + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 71a6824..579a51d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,265 @@ Framework-agnostic programmatic SEO engine for SPAs and component frameworks. - **Meta / canonical / Open Graph / Twitter Card rendering** into the document head - **Zero framework dependencies** — the only runtime dependency is `schema-dts` +## Install + +```bash +bun add @expert-vision-software/programmatic-seo +``` + +ESM-only, TypeScript declarations included, Node 22+. + +## Quickstart + +```ts +import {SeoService} from "@expert-vision-software/programmatic-seo"; + +const seo = new SeoService(); + +seo.initialize({ + rootUrl: "https://example.com", + siteTitle: "Example", + logger: console, +}); + +seo.siteWide + .setBreadcrumb([{name: "Home", url: "/"}]) + .setLogo({url: "https://example.com/logo.png", width: 300, height: 68}) + .setOrganization({name: "Example Inc.", url: "https://example.com"}) + .setWebApplication({name: "Example App", description: "What the app does."}); + +seo.prepareToNavigate(); + +seo.page() + .setTitle("My Article") + .setDescription("What the article is about.") + .setUrl("/articles/my-article") + .contentPage() + .setDates({published: "2026-01-15", modified: "2026-02-01"}) + .setKeywords("example", "seo") + .emit(); + +seo.setUrl("https://example.com/articles/my-article"); +``` + +The lifecycle: `initialize()` once at startup → configure site-wide nodes on the `siteWide` +builder → per navigation call `prepareToNavigate()`, then commit the page's spec via +`emit(spec)` or a `page()` / `contentPage()` builder chain → on navigation end, sync the URL +with `setUrl(window.location.href)`. + +The full public surface — `emit()` merge semantics, spec field tables, builder chains, +URL hygiene guard, date normalization, config parsing — is documented in +[docs/API.md](docs/API.md). + +## Framework integration + +`ISeoPage` is pure data with zero framework types, so the service drops into any host. The +package ships no adapters; wiring stays consumer-side. + +### Aurelia + +The proven pattern (as consumed by +[BillGrokker](https://github.com/Expert-Vision-Software/billgrokker)): a DI token, +a logger bridge, an initialization AppTask, and a navigation-event handler. + +```ts +import {DI} from "aurelia"; +import {SeoService} from "@expert-vision-software/programmatic-seo"; + +export const ISeoService = DI.createInterface( + "ISeoService", + x => x.singleton(SeoService), +); +export type ISeoService = SeoService; +``` + +Register and initialize in an `AppTask`, bridging Aurelia's `ILogger` over the package's +`SeoLogger` interface: + +```ts +import {AppTask, ILogger} from "aurelia"; +import {ISeoService} from "./seo-service.di"; +import type {SeoLogger} from "@expert-vision-software/programmatic-seo"; +import {HomeBreadcrumbItem} from "./constants/breadcrumbs"; + +export const initializeSeo: IRegistry = { + register(container: IContainer): IContainer { + const seoLogger: SeoLogger = container.get(ILogger).scopeTo("SeoService"); + return container.register(AppTask.activated(ISeoService, seoSvc => { + seoSvc.initialize({rootUrl: ROOT_URL, logger: seoLogger}); + seoSvc.siteWide.setBreadcrumb([HomeBreadcrumbItem]); + seoSvc.siteWide.setLogo({url: `${ROOT_URL}/logo.png`, width: 300, height: 68}); + seoSvc.siteWide.setOrganization({name: "Example", url: ROOT_URL}); + })); + }, +}; +``` + +Sync navigation: `au:router:navigation-start` → `prepareToNavigate()`; +`au:router:navigation-end` → `setUrl(window.location.href)`: + +```ts +import {resolve} from "aurelia"; +import {IRouterEvents} from "@aurelia/router"; +import {ISeoService} from "./seo-service.di"; + +events.subscribe("au:router:navigation-start", () => seo.prepareToNavigate()); +events.subscribe("au:router:navigation-end", () => { + seo.setUrl(window.location.href); +}); +``` + +Page components then emit in `attached()`: + +```ts +public attached(): void { + this._seo.page().setTitle(title).setDescription(desc).setUrl(path).emit(); +} +``` + +### React + +```tsx +import {useEffect, useMemo} from "react"; +import type {ISeoPage} from "@expert-vision-software/programmatic-seo"; + +function useSeo(spec: ISeoPage) { + useEffect(() => { + seo.emit(spec); + }, [spec]); +} + +function Article({post}: {post: Post}) { + const spec = useMemo(() => ({ + title: post.title, + description: post.excerpt, + url: `/posts/${post.slug}`, + ogType: "article", + article: { + canonicalPath: `/posts/${post.slug}`, + description: post.excerpt, + datePublished: post.publishedAt, + dateModified: post.modifiedAt, + }, + }), [post]); + useSeo(spec); + return
…
; +} +``` + +### Vue + +```ts +import {watch} from "vue"; +import type {ISeoPage} from "@expert-vision-software/programmatic-seo"; + +export function useSeo(spec: Ref) { + watch(spec, v => seo.emit(v), {deep: true}); +} +``` + +### Next.js + +The spec is plain serializable data, so a client `` component calls `emit()` +on mount, or a server-side renderer can pass the same `ISeoPage` shape down: + +```tsx +"use client"; +import {useEffect} from "react"; +import type {ISeoPage} from "@expert-vision-software/programmatic-seo"; + +export function SeoHead({spec}: {spec: ISeoPage}) { + useEffect(() => { + seo.emit(spec); + }, [spec]); + return null; +} +``` + +## Logger bridging + +The package never logs through a framework; it calls the `SeoLogger` seam supplied via the +config `logger` field. Bridge your framework logger over it: + +```ts +import type {SeoLogger} from "@expert-vision-software/programmatic-seo"; + +const seoLogger: SeoLogger = { + debug: (msg, ...args) => frameworkLogger.debug(msg, args), + info: (msg, ...args) => frameworkLogger.info(msg, args), + warn: (msg, ...args) => frameworkLogger.warn(msg, args), + error: (msg, ...args) => frameworkLogger.error(msg, args), +}; + +seo.initialize({rootUrl: "https://example.com", logger: seoLogger}); +``` + +Without a `logger`, the service stays silent (no-op defaults). Aurelia users: see the +`ILogger.scopeTo("SeoService")` bridge above. + +## Production baseline + +The implementation iterates against production truth: committed fixtures of the +SPA-rendered `` per route, captured once from `https://billgrokker.com` +([#3](https://github.com/Expert-Vision-Software/programmatic-seo/issues/3)), with +synthesis tests proving the public API reproduces them +([#6](https://github.com/Expert-Vision-Software/programmatic-seo/issues/6)). + +- **Capture once:** fixtures are committed artifacts; the git history is the baseline's + history. Volatile runtime values (dates that default to "now") are normalized to the + `{{NOW}}` token; every rule is documented in `fixtures/baseline/NORMALIZATION.md`. +- **Re-capture is manual and deliberate:** a PR titled `baseline: recapture` with a + justification in the body (production head change, new route, fixture drift). CI never + auto-recaptures. The procedure: + + ```sh + bun install && bunx playwright install chromium + npm run capture-baseline + ``` + + This rewrites `fixtures/baseline/*.json` for all nine routes from + `https://billgrokker.com`. Verify idempotence: run the command a second time and confirm + `git status` shows no further diff outside `{{NOW}}` fields (see + `fixtures/baseline/NORMALIZATION.md`). Commit the changed fixtures in a single + `baseline: recapture` PR describing what changed in production and why. +- **Interpreting synthesis failures:** a fixture mismatch means either the package output + drifted from upstream behavior (a regression — fix the implementation) or production + changed legitimately (a real-world change — re-capture via a reviewed PR). A failure is + never silenced by editing the fixture inline with the change that broke it. + +### Baseline synthesis tests + +`test/baseline-synthesis.spec.ts` reconstructs each of the nine fixture routes +through the public API only — `initialize` → `siteWide.set*(...)` → +`emit()` / `page()` chains → `setUrl(href)` — inside a fresh jsdom document +seeded with the SPA's served static head, then compares the serialized head +against the fixture after the shared normalization (`scripts/normalize.ts`, +the single source of truth, shared with the capture harness). + +Content inputs come from the fixtures' stored data blocks, never the network: +bill-detail routes synthesize from the fixture's `bill` metadata block +(title, dates, policyArea, breadcrumbs) plus the captured description meta, +and the FAQ routes reuse the fixture's stored `Question` content. The doubled +`` values on router-titled routes (home, FAQ, not-found, account) and +the `/faq` → `/faq/index` canonical are reproduced as-is: they are upstream +behaviors (the SPA router's `buildTitle` composition and the router's +`/faq/index` URL) — not bugs to fix here. + +Granular failure interpretation: + +- **Diff only inside `{{NOW}}` fields** → a normalization bug. Fix the + normalization module or the test harness; never the fixture. +- **Diff in JSON-LD shape, `@id` values, key order, meta set, canonical, or + title** → a package regression. Fix the package; the fixture is production + truth. +- **Diff caused by an intentional behavior change** → land a `baseline: + recapture` PR first, then update the synthesis expectation. Do not weaken + the comparison in the test. + +Rendered output is **byte-identical** to the upstream implementation; this is the hard +constraint inherited from the source project (stable `@id` ordering, key insertion order, +`@context`/`@graph` shape). + ## Status Pre-release: the engine is being extracted behavior-identically from @@ -15,23 +274,8 @@ Pre-release: the engine is being extracted behavior-identically from (BillGrokker's SPA SEO service, hardened and extraction-prepared upstream). - Normative spec: [#1](https://github.com/Expert-Vision-Software/programmatic-seo/issues/1) -- First publish: [#9](https://github.com/Expert-Vision-Software/programmatic-seo/issues/9) → npm **`@expert-vision-software/programmatic-seo`** (v0.1.0) - -## How it is used - -```text -initialize(config) site defaults from the host document (meta, title, JSON-LD graph) -siteWide.set*(...) site-wide nodes: organization, logo, webApplication, base breadcrumb -emit(pageSpec) per navigation: atomic commit of the page's SEO spec -page().set*(...).emit() the same, via the chainable builder -prepareToNavigate() page-state reset between navigations (site-wide state persists) -setUrl(href) first-class navigation sync -``` - -Full API reference lands with the docs ticket -([#7](https://github.com/Expert-Vision-Software/programmatic-seo/issues/7)), -adapted from the upstream -[SEO service reference](https://github.com/Expert-Vision-Software/billgrokker/blob/3169c7a10003/docs/reference/seo-service-api.md). +- First publish: [#9](https://github.com/Expert-Vision-Software/programmatic-seo/issues/9) — + npm **`@expert-vision-software/programmatic-seo`** (v0.1.0) ## Extraction plan @@ -46,21 +290,12 @@ adapted from the upstream | [#8](https://github.com/Expert-Vision-Software/programmatic-seo/issues/8) | CI: PR gate + tag-driven npm publish with provenance | | [#9](https://github.com/Expert-Vision-Software/programmatic-seo/issues/9) | Publish v0.1.0 | -## Production baseline - -The implementation iterates against production truth: committed fixtures of the -SPA-rendered `<head>` per route, captured once from `https://billgrokker.com` -([#3](https://github.com/Expert-Vision-Software/programmatic-seo/issues/3)), with -synthesis tests proving the public API reproduces them -([#6](https://github.com/Expert-Vision-Software/programmatic-seo/issues/6)). -Re-capture is always a deliberate, reviewed PR — never automated. - -Rendered output is **byte-identical** to the upstream implementation; this is the -hard constraint inherited from the source project (stable `@id` ordering, key -insertion order, `@context`/`@graph` shape). - ## Downstream adoption BillGrokker switches to this package under its own spec: [Expert-Vision-Software/billgrokker#36](https://github.com/Expert-Vision-Software/billgrokker/issues/36) -(baseline parity gate → integration → import swap → parity verification → docs). \ No newline at end of file +(baseline parity gate → integration → import swap → parity verification → docs). + +## License + +[MIT](LICENSE) diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..fcee66e --- /dev/null +++ b/bun.lock @@ -0,0 +1,544 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "@expert-vision-software/programmatic-seo", + "dependencies": { + "schema-dts": "^2.0.0", + }, + "devDependencies": { + "@eslint/js": "^9.39.0", + "@types/jsdom": "^27.0.0", + "@types/node": "^22.0.0", + "eslint": "^9.39.0", + "eslint-config-prettier": "^10.1.8", + "jsdom": "^27.0.0", + "playwright": "^1.65.1", + "prettier": "^3.6.2", + "typescript": "^5.9.3", + "typescript-eslint": "^8.46.0", + "vitest": "^3.2.4", + }, + }, + }, + "packages": { + "@acemir/cssom": ["@acemir/cssom@0.9.33", "", {}, "sha512-52IMmrBsIsDZLp/KFM+KmaMLJ8GTj113K+iFGFCoOjstZSZbsAxMJE8KYtwao7bz1LsEG810ts1m5wvkVEqPlg=="], + + "@asamuzakjp/css-color": ["@asamuzakjp/css-color@4.1.2", "", { "dependencies": { "@csstools/css-calc": "^3.0.0", "@csstools/css-color-parser": "^4.0.1", "@csstools/css-parser-algorithms": "^4.0.0", "@csstools/css-tokenizer": "^4.0.0", "lru-cache": "^11.2.5" } }, "sha512-NfBUvBaYgKIuq6E/RBLY1m0IohzNHAYyaJGuTK79Z23uNwmz2jl1mPsC5ZxCCxylinKhT1Amn5oNTlx1wN8cQg=="], + + "@asamuzakjp/dom-selector": ["@asamuzakjp/dom-selector@6.8.1", "", { "dependencies": { "@asamuzakjp/nwsapi": "^2.3.9", "bidi-js": "^1.0.3", "css-tree": "^3.1.0", "is-potential-custom-element-name": "^1.0.1", "lru-cache": "^11.2.6" } }, "sha512-MvRz1nCqW0fsy8Qz4dnLIvhOlMzqDVBabZx6lH+YywFDdjXhMY37SmpV1XFX3JzG5GWHn63j6HX6QPr3lZXHvQ=="], + + "@asamuzakjp/nwsapi": ["@asamuzakjp/nwsapi@2.3.9", "", {}, "sha512-n8GuYSrI9bF7FFZ/SjhwevlHc8xaVlb/7HmHelnc/PZXBD2ZR49NnN9sMMuDdEGPeeRQ5d0hqlSlEpgCX3Wl0Q=="], + + "@csstools/color-helpers": ["@csstools/color-helpers@6.1.3", "", {}, "sha512-c6CpX5G1pvuOKTXiRFJ54Lzc8zQrZ3qUjp44QC5DJNt1OmA1vmfUxOMCcKdDqsvffVDG0/MHnY63J+Mn0nmdUg=="], + + "@csstools/css-calc": ["@csstools/css-calc@3.4.4", "", { "peerDependencies": { "@csstools/css-parser-algorithms": "^4.0.3", "@csstools/css-tokenizer": "^4.0.3" } }, "sha512-Jwo1Z8DUsZ8xVOLBdLMfhjJFvWD6pqaUTlBNQZ+qIB2i9g7yG8kd/UBJj2c9J9Twr+u87cjy9BjkmfvMbyOk3Q=="], + + "@csstools/css-color-parser": ["@csstools/css-color-parser@4.2.8", "", { "dependencies": { "@csstools/color-helpers": "^6.1.3", "@csstools/css-calc": "^3.4.4" }, "peerDependencies": { "@csstools/css-parser-algorithms": "^4.0.3", "@csstools/css-tokenizer": "^4.0.3" } }, "sha512-JLsKBee9dmnA3L+H+vYK4lQ6n5CoY3yEnh33zdlMutRfrTxtqt+hFeoZ1maHRt5vLw67huDLpOkDb3rl9A51MQ=="], + + "@csstools/css-parser-algorithms": ["@csstools/css-parser-algorithms@4.0.3", "", { "peerDependencies": { "@csstools/css-tokenizer": "^4.0.3" } }, "sha512-EpCfUDaJtwohPHC7egoXxPGT/R1/WyyAhw87MKB/7BPPZvZU+IcEqo4er5FpLnby2Gvwt9Lpxy+WNEDyFjoXtA=="], + + "@csstools/css-syntax-patches-for-csstree": ["@csstools/css-syntax-patches-for-csstree@1.1.17", "", { "peerDependencies": { "css-tree": "^3.2.1" }, "optionalPeers": ["css-tree"] }, "sha512-IPx9W33+t0Yt5TVb+Y7oICrThOIry0TY6GuXfSHOatxA0uiHqbzi98Gai905lpBAX1m/LH7iI96e9jcI7Dkvxw=="], + + "@csstools/css-tokenizer": ["@csstools/css-tokenizer@4.0.3", "", {}, "sha512-gdkFe/Z4KU1q8Y5S3GYScXGcOnO56dgWwIs5+97Ij1VIKISItOIUlCXUq4VLbdnRclF+SSQ49sLsn3KeV111AA=="], + + "@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.28.2", "", { "os": "aix", "cpu": "ppc64" }, "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ=="], + + "@esbuild/android-arm": ["@esbuild/android-arm@0.28.2", "", { "os": "android", "cpu": "arm" }, "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg=="], + + "@esbuild/android-arm64": ["@esbuild/android-arm64@0.28.2", "", { "os": "android", "cpu": "arm64" }, "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A=="], + + "@esbuild/android-x64": ["@esbuild/android-x64@0.28.2", "", { "os": "android", "cpu": "x64" }, "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q=="], + + "@esbuild/darwin-arm64": ["@esbuild/darwin-arm64@0.28.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw=="], + + "@esbuild/darwin-x64": ["@esbuild/darwin-x64@0.28.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw=="], + + "@esbuild/freebsd-arm64": ["@esbuild/freebsd-arm64@0.28.2", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw=="], + + "@esbuild/freebsd-x64": ["@esbuild/freebsd-x64@0.28.2", "", { "os": "freebsd", "cpu": "x64" }, "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg=="], + + "@esbuild/linux-arm": ["@esbuild/linux-arm@0.28.2", "", { "os": "linux", "cpu": "arm" }, "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w=="], + + "@esbuild/linux-arm64": ["@esbuild/linux-arm64@0.28.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug=="], + + "@esbuild/linux-ia32": ["@esbuild/linux-ia32@0.28.2", "", { "os": "linux", "cpu": "ia32" }, "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ=="], + + "@esbuild/linux-loong64": ["@esbuild/linux-loong64@0.28.2", "", { "os": "linux", "cpu": "none" }, "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ=="], + + "@esbuild/linux-mips64el": ["@esbuild/linux-mips64el@0.28.2", "", { "os": "linux", "cpu": "none" }, "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA=="], + + "@esbuild/linux-ppc64": ["@esbuild/linux-ppc64@0.28.2", "", { "os": "linux", "cpu": "ppc64" }, "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ=="], + + "@esbuild/linux-riscv64": ["@esbuild/linux-riscv64@0.28.2", "", { "os": "linux", "cpu": "none" }, "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA=="], + + "@esbuild/linux-s390x": ["@esbuild/linux-s390x@0.28.2", "", { "os": "linux", "cpu": "s390x" }, "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg=="], + + "@esbuild/linux-x64": ["@esbuild/linux-x64@0.28.2", "", { "os": "linux", "cpu": "x64" }, "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ=="], + + "@esbuild/netbsd-arm64": ["@esbuild/netbsd-arm64@0.28.2", "", { "os": "none", "cpu": "arm64" }, "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw=="], + + "@esbuild/netbsd-x64": ["@esbuild/netbsd-x64@0.28.2", "", { "os": "none", "cpu": "x64" }, "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw=="], + + "@esbuild/openbsd-arm64": ["@esbuild/openbsd-arm64@0.28.2", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ=="], + + "@esbuild/openbsd-x64": ["@esbuild/openbsd-x64@0.28.2", "", { "os": "openbsd", "cpu": "x64" }, "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw=="], + + "@esbuild/openharmony-arm64": ["@esbuild/openharmony-arm64@0.28.2", "", { "os": "none", "cpu": "arm64" }, "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q=="], + + "@esbuild/sunos-x64": ["@esbuild/sunos-x64@0.28.2", "", { "os": "sunos", "cpu": "x64" }, "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g=="], + + "@esbuild/win32-arm64": ["@esbuild/win32-arm64@0.28.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ=="], + + "@esbuild/win32-ia32": ["@esbuild/win32-ia32@0.28.2", "", { "os": "win32", "cpu": "ia32" }, "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA=="], + + "@esbuild/win32-x64": ["@esbuild/win32-x64@0.28.2", "", { "os": "win32", "cpu": "x64" }, "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g=="], + + "@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.10.1", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-cuadcxVFE8sDK6iWJbs8Sn0av2Nrh2QSGQhVlBW9AaAHqHwjWsZHT8LJ4hFGPh7ASBV2deFdM7H/DPjulmh8rg=="], + + "@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.3", "", {}, "sha512-R76UKbvsqI68DJJVTVyqFKqU98CN4+B+acxNfEA2IFarSzP0SjtKf/3+fFiXzTyv5Fj3PxLkGHe2wnVWWMxobQ=="], + + "@eslint/config-array": ["@eslint/config-array@0.21.2", "", { "dependencies": { "@eslint/object-schema": "^2.1.7", "debug": "^4.3.1", "minimatch": "^3.1.5" } }, "sha512-nJl2KGTlrf9GjLimgIru+V/mzgSK0ABCDQRvxw5BjURL7WfH5uoWmizbH7QB6MmnMBd8cIC9uceWnezL1VZWWw=="], + + "@eslint/config-helpers": ["@eslint/config-helpers@0.4.2", "", { "dependencies": { "@eslint/core": "^0.17.0" } }, "sha512-gBrxN88gOIf3R7ja5K9slwNayVcZgK6SOUORm2uBzTeIEfeVaIhOpCtTox3P6R7o2jLFwLFTLnC7kU/RGcYEgw=="], + + "@eslint/core": ["@eslint/core@0.17.0", "", { "dependencies": { "@types/json-schema": "^7.0.15" } }, "sha512-yL/sLrpmtDaFEiUj1osRP4TI2MDz1AddJL+jZ7KSqvBuliN4xqYY54IfdN8qD8Toa6g1iloph1fxQNkjOxrrpQ=="], + + "@eslint/eslintrc": ["@eslint/eslintrc@3.3.7", "", { "dependencies": { "ajv": "^6.14.0", "debug": "^4.3.2", "espree": "^10.0.1", "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.3.2", "minimatch": "^3.1.5", "strip-json-comments": "^3.1.1" } }, "sha512-F42g89Qd5oAWtp0k0nnSrjziAKza7w8SVT4mStc18LZMaRb4J1HQAHLCalEtDCxrTuksx7NU9qsmeLwpOfPqWw=="], + + "@eslint/js": ["@eslint/js@9.39.5", "", {}, "sha512-QywQuszQh77pIXCsq998c8hbhSTI/azTty1Z6N53dmAudKHhy573j3yvRLsX2BSp8YpLtoCEG8E9DJe+8zUh4A=="], + + "@eslint/object-schema": ["@eslint/object-schema@2.1.7", "", {}, "sha512-VtAOaymWVfZcmZbp6E2mympDIHvyjXs/12LqWYjVw6qjrfF+VK+fyG33kChz3nnK+SU5/NeHOqrTEHS8sXO3OA=="], + + "@eslint/plugin-kit": ["@eslint/plugin-kit@0.4.1", "", { "dependencies": { "@eslint/core": "^0.17.0", "levn": "^0.4.1" } }, "sha512-43/qtrDUokr7LJqoF2c3+RInu/t4zfrpYdoSDfYyhg52rwLV6TnOvdG4fXm7IkSB3wErkcmJS9iEhjVtOSEjjA=="], + + "@exodus/bytes": ["@exodus/bytes@1.16.0", "", { "peerDependencies": { "@noble/hashes": "^1.8.0 || ^2.0.0" }, "optionalPeers": ["@noble/hashes"] }, "sha512-IcpW84uEn3N7ETtNZMlxKhfl6Pec8rUNGOTBtWbK1FKhJxIFAptZyVrvVRVBimAJxJCgc3PxepxkdWWG4DVzfA=="], + + "@humanfs/core": ["@humanfs/core@0.19.2", "", { "dependencies": { "@humanfs/types": "^0.15.0" } }, "sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA=="], + + "@humanfs/node": ["@humanfs/node@0.16.8", "", { "dependencies": { "@humanfs/core": "^0.19.2", "@humanfs/types": "^0.15.0", "@humanwhocodes/retry": "^0.4.0" } }, "sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ=="], + + "@humanfs/types": ["@humanfs/types@0.15.0", "", {}, "sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q=="], + + "@humanwhocodes/module-importer": ["@humanwhocodes/module-importer@1.0.1", "", {}, "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA=="], + + "@humanwhocodes/retry": ["@humanwhocodes/retry@0.4.3", "", {}, "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ=="], + + "@isaacs/nonrecursive-glob-match": ["@isaacs/nonrecursive-glob-match@1.1.0", "", {}, "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw=="], + + "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], + + "@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.68.8", "", { "os": "android", "cpu": "arm" }, "sha512-7l9FdeCGjhmMTVePgndK4t9u5tLR+VuTTMoyc0PscqZDdYjS07ZsQ0vQYsWsODu/ZZYPG7WVJwbUZ77n1hVT+w=="], + + "@rollup/rollup-android-arm64": ["@rollup/rollup-android-arm64@4.68.8", "", { "os": "android", "cpu": "arm64" }, "sha512-kXkkIiJujBjArHwEToz99BQqIqibn4xdV6SjsoaxuZzvLUCVEzoHQ1Lp62m7xOhpLRpWpCtxL2ZUy/ADKuz9/g=="], + + "@rollup/rollup-android-x64": ["@rollup/rollup-android-x64@4.68.8", "", { "os": "android", "cpu": "x64" }, "sha512-KYoBygnHs3zUOLR0z7SaqhMnUrSF9pbuTOJT/uHK3PrgCXdv/xaMubZD8jCpg6NTo46deasLgZRq38xFTyu8uw=="], + + "@rollup/rollup-darwin-arm64": ["@rollup/rollup-darwin-arm64@4.68.8", "", { "os": "darwin", "cpu": "arm64" }, "sha512-YmBUNjgm5bsjOByO+H1TFbuGZe+ZnHcYtPXYj9+L1cwTu/BG8zjuUzO2PH9KwS85P0UH+WJDSb+mQ2hqjp5uBQ=="], + + "@rollup/rollup-darwin-x64": ["@rollup/rollup-darwin-x64@4.68.8", "", { "os": "darwin", "cpu": "x64" }, "sha512-XMX5ybuOmkwiM13KJtsBxakZ69pyaR9thRYU2fMejhaB0VuzLMIkIc+9TBsu2rv34eEf6XaSMOaLOyEgHGWHTQ=="], + + "@rollup/rollup-freebsd-arm64": ["@rollup/rollup-freebsd-arm64@4.68.8", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-WuBXScWJDaqPJKwVrotUe1sM9DHWMN937C23RClt0MVHVt7A1rBy285ZfZTLccPEVMxmGJMt2jvdHMOI33lrKA=="], + + "@rollup/rollup-freebsd-x64": ["@rollup/rollup-freebsd-x64@4.68.8", "", { "os": "freebsd", "cpu": "x64" }, "sha512-kegwGqP3rMenEMaKo8OzMBb5WvLW2h2jrQ3iKuYptTTF8C/yuxz+hinjBPrtYuIPLJDwxHc/hv2e4u5pmrqo9A=="], + + "@rollup/rollup-linux-arm-gnueabihf": ["@rollup/rollup-linux-arm-gnueabihf@4.68.8", "", { "os": "linux", "cpu": "arm" }, "sha512-Qct0oLM1zGNbvqs1udQnuchg+Q9uHbkMcQqCfs3M7foNn7HvEkUypfFn9o5fklimUI5OF3A2nMknd4/vrEyeVg=="], + + "@rollup/rollup-linux-arm-musleabihf": ["@rollup/rollup-linux-arm-musleabihf@4.68.8", "", { "os": "linux", "cpu": "arm" }, "sha512-xTH5vD+lW/5MU3kL/Op8RSSG/O9fxUQZuJcSBmmBeYem9uXYvCq6PDHx/oDSNeyLD/p4pGujG2PVI0R8MjAhSw=="], + + "@rollup/rollup-linux-arm64-gnu": ["@rollup/rollup-linux-arm64-gnu@4.68.8", "", { "os": "linux", "cpu": "arm64" }, "sha512-lPPStmynSHvwWpSrAsuemPFB+EWFObXjwz44EK4Hph47U6SBAk1Kehq5MkI7i8EYVjrXddaAV7YkJH8mX8QSZQ=="], + + "@rollup/rollup-linux-arm64-musl": ["@rollup/rollup-linux-arm64-musl@4.68.8", "", { "os": "linux", "cpu": "arm64" }, "sha512-kZkvIYAihM6l6M+giSUHayDDf/JL+TYR5bYWiAX7/jUFWvMkMmysA4GV2F0HOsXQNEyctW3x1xLjww1GqW7Q1w=="], + + "@rollup/rollup-linux-loong64-gnu": ["@rollup/rollup-linux-loong64-gnu@4.68.8", "", { "os": "linux", "cpu": "none" }, "sha512-XZKLEIY977OJr6zUtK6nlQcLXme34c8HqVp3+WmKQxKVN6Nj+b9qE3ZHWIDHXznHJsGl2AsaMOgB0GL0fkZGUg=="], + + "@rollup/rollup-linux-loong64-musl": ["@rollup/rollup-linux-loong64-musl@4.68.8", "", { "os": "linux", "cpu": "none" }, "sha512-+sN+Fj6F9suk8SkL6boIfXDmj9iJwSKPCTeCy8/pfTOHuzNX+duhTb9uyj6154oVK8Odl5zgL4DXRZzXjsRKcw=="], + + "@rollup/rollup-linux-ppc64-gnu": ["@rollup/rollup-linux-ppc64-gnu@4.68.8", "", { "os": "linux", "cpu": "ppc64" }, "sha512-EBCu3uDFaGwSodUl+XR8yubvVFUkSo6QK9YAIOV1vljqntzTF2/mXLM6utgLaSGf/8oM+qEe8Ai0Jd4+tyMoIQ=="], + + "@rollup/rollup-linux-ppc64-musl": ["@rollup/rollup-linux-ppc64-musl@4.68.8", "", { "os": "linux", "cpu": "ppc64" }, "sha512-hRC0jWdsLBckCijx2wiUfk7zW1SqEW47yMsCNoDGmQfoqq0AjW+9UYZqxg3LTmG76PyHNdNGBSuspB3CqrhGIA=="], + + "@rollup/rollup-linux-riscv64-gnu": ["@rollup/rollup-linux-riscv64-gnu@4.68.8", "", { "os": "linux", "cpu": "none" }, "sha512-OZKrTRWyGnLITUTipbeXDdtb2dxQPyFk/Fbw9qER8pIvd2Ja9hHELkY0Fv5p9yYYkimqtzVhApKKXGv0cWGQGw=="], + + "@rollup/rollup-linux-riscv64-musl": ["@rollup/rollup-linux-riscv64-musl@4.68.8", "", { "os": "linux", "cpu": "none" }, "sha512-HmhSRSQ+dOeOntPfmYux4rCpOQLtsGbcGLQu4nm8ig3tuVqe/bKfDHorg36LKAqYq4X/nwFr79ImtaFHHsn4ug=="], + + "@rollup/rollup-linux-s390x-gnu": ["@rollup/rollup-linux-s390x-gnu@4.68.8", "", { "os": "linux", "cpu": "s390x" }, "sha512-wk1Ci1hsMREaBELoKPSnzRAh1oUULI+8kfb2F5vVmTD2IcfR9AKMskCusizZhIAvojOtPZihPj4OdKy6ifZwhQ=="], + + "@rollup/rollup-linux-x64-gnu": ["@rollup/rollup-linux-x64-gnu@4.68.8", "", { "os": "linux", "cpu": "x64" }, "sha512-mDufoUJ6fnKZnCyjV3sGEDvXQQkM6j1UmINHheGX4Emau3TZWJzX3sCVmbzkNB+W2G84BiFQdDCcF09lv0i0VA=="], + + "@rollup/rollup-linux-x64-musl": ["@rollup/rollup-linux-x64-musl@4.68.8", "", { "os": "linux", "cpu": "x64" }, "sha512-7EGVL9rYRYQZe3UC8JQzfBN9rxk484Rfs4u/yGWumTYKUdJt6tmdP+0Y3qHvAvzJCQ+JQM5rSqZbVyrJARlGpA=="], + + "@rollup/rollup-openbsd-x64": ["@rollup/rollup-openbsd-x64@4.68.8", "", { "os": "openbsd", "cpu": "x64" }, "sha512-Umklz+QSGwKWQVlVrsMJrwFx1oNRYHgrxSGiZM8pJCMpzWnMDMinDhPILf0BvRXfA1QOArsDcs+AE7Jd6dQxvA=="], + + "@rollup/rollup-openharmony-arm64": ["@rollup/rollup-openharmony-arm64@4.68.8", "", { "os": "none", "cpu": "arm64" }, "sha512-BlRp6uzQDK5rczAdaXQ8dlSIRFRlkDRBqpb8GGtv8iwZxQdOjoigdFU5t5dcxpnpU0caMoT9mH27MyAl4dWwKw=="], + + "@rollup/rollup-win32-arm64-msvc": ["@rollup/rollup-win32-arm64-msvc@4.68.8", "", { "os": "win32", "cpu": "arm64" }, "sha512-Sc8Mkf/fVfcV0hBJNDRIM82BjS4kJn2Of0jP8dgQ+TodquxtCZ/5D6FgSsY3uN5IBmNi8Zrb/OHd60IEYKaw+Q=="], + + "@rollup/rollup-win32-ia32-msvc": ["@rollup/rollup-win32-ia32-msvc@4.68.8", "", { "os": "win32", "cpu": "ia32" }, "sha512-XPTFXclN+I+Cfu3ONWDsw+uvgSZjTJa1B2u2EvtdKlSdgNU6mrOZdgeaMkvN+2T2KPTEXn6fnRY8IODlRg3/Tg=="], + + "@rollup/rollup-win32-x64-gnu": ["@rollup/rollup-win32-x64-gnu@4.68.8", "", { "os": "win32", "cpu": "x64" }, "sha512-63dWiHgvpWcienfdr465lT3SIn4u3535vbDfaLKhSn0F2KJ06bbcUsewDGJZUPZCbJ67qESrPDhb85UnWdb5ew=="], + + "@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.68.8", "", { "os": "win32", "cpu": "x64" }, "sha512-/W1LBsMeQAdiCuH3Z2gkRspl3mlxL+butknhq4vXjmxO45vuT08BqhehxDoE4YS+m6s9lhpq6M9/PjTEAg8PYw=="], + + "@types/chai": ["@types/chai@5.2.3", "", { "dependencies": { "@types/deep-eql": "*", "assertion-error": "^2.0.1" } }, "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA=="], + + "@types/deep-eql": ["@types/deep-eql@4.0.2", "", {}, "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw=="], + + "@types/estree": ["@types/estree@1.0.10", "", {}, "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g=="], + + "@types/jsdom": ["@types/jsdom@27.0.0", "", { "dependencies": { "@types/node": "*", "@types/tough-cookie": "*", "parse5": "^7.0.0" } }, "sha512-NZyFl/PViwKzdEkQg96gtnB8wm+1ljhdDay9ahn4hgb+SfVtPCbm3TlmDUFXTA+MGN3CijicnMhG18SI5H3rFw=="], + + "@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="], + + "@types/node": ["@types/node@22.20.5", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA=="], + + "@types/tough-cookie": ["@types/tough-cookie@4.0.5", "", {}, "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA=="], + + "@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.73.0", "", { "dependencies": { "@eslint-community/regexpp": "^4.12.2", "@typescript-eslint/scope-manager": "8.73.0", "@typescript-eslint/type-utils": "8.73.0", "@typescript-eslint/utils": "8.73.0", "@typescript-eslint/visitor-keys": "8.73.0", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" }, "peerDependencies": { "@typescript-eslint/parser": "^8.73.0", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "sha512-UkygMFer53Yzn29MCYFTHf34hGXf5KJhiDWfIm1tXtXRrym1CS6l5H9Y3yCtPWChpC0/f93H88gdj8tN0dd4kw=="], + + "@typescript-eslint/parser": ["@typescript-eslint/parser@8.73.0", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.73.0", "@typescript-eslint/types": "8.73.0", "@typescript-eslint/typescript-estree": "8.73.0", "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "sha512-AuL45bVcmssHfZ3Di3cs9Q0l4gBm4ZFVrJOQEE7VpqW+PVgQaEwSwazz4TVIiFabXkk6U51EprYDwqw+HR8ePw=="], + + "@typescript-eslint/project-service": ["@typescript-eslint/project-service@8.73.0", "", { "dependencies": { "@typescript-eslint/tsconfig-utils": "^8.73.0", "@typescript-eslint/types": "^8.73.0", "debug": "^4.4.3" }, "peerDependencies": { "typescript": ">=4.8.4 <6.1.0" } }, "sha512-/pEf8Rc4Mjk+qJnY0uO1+Gadeal8uv50xpuic+srG2vIVatA0XxvWMUeMtFvs6OCHqftiQ7/+qH4aehG5stzIA=="], + + "@typescript-eslint/scope-manager": ["@typescript-eslint/scope-manager@8.73.0", "", { "dependencies": { "@typescript-eslint/types": "8.73.0", "@typescript-eslint/visitor-keys": "8.73.0" } }, "sha512-/TjD738Iq2rzj5z0ixVOi+TsvgjAzZPLPaH1yWdDBytR/HTR5gMpyYWZeCe5WTQZLwk3ho8AV7U3muoQCRtXBQ=="], + + "@typescript-eslint/tsconfig-utils": ["@typescript-eslint/tsconfig-utils@8.73.0", "", { "peerDependencies": { "typescript": ">=4.8.4 <6.1.0" } }, "sha512-lmtCFOfYaJfpqZywGuXi4FpNtE+NQ+YLe3T0K9rtEDcW8ZuGWvfI++pj8r05sYMI8vWT2CYK4rWyedmD6Rp4og=="], + + "@typescript-eslint/type-utils": ["@typescript-eslint/type-utils@8.73.0", "", { "dependencies": { "@typescript-eslint/types": "8.73.0", "@typescript-eslint/typescript-estree": "8.73.0", "@typescript-eslint/utils": "8.73.0", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "sha512-MOC9i4xy1F7KcDde7Ip8jf1SrRiALb2Km4UWxGNjUE2YlhjIEo1ayE27GHIwIQyfWuHTmEonQT14uyurlyC6aA=="], + + "@typescript-eslint/types": ["@typescript-eslint/types@8.73.0", "", {}, "sha512-O/1ytYzflF16QDKXx4/qOXg1IuZp+n7hr9t+S0nv7N/2Tl8rJiNCshztV1gcSUvHbPtoX3+zmNbtSAyVbzxVfw=="], + + "@typescript-eslint/typescript-estree": ["@typescript-eslint/typescript-estree@8.73.0", "", { "dependencies": { "@typescript-eslint/project-service": "8.73.0", "@typescript-eslint/tsconfig-utils": "8.73.0", "@typescript-eslint/types": "8.73.0", "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3", "minimatch": "^11.0.1", "semver": "^7.7.3", "tinyglobby": "^0.2.15", "ts-api-utils": "^2.5.0" }, "peerDependencies": { "@typescript/native": "npm:typescript@>=7.1.0-dev.20261009.1 || >=7.1.0-beta <7.1.0-dev", "typescript": ">=4.8.4 <6.1.0" }, "optionalPeers": ["@typescript/native"] }, "sha512-InjlBkSdWceIwIBWSwS3ENUp+i0O02PGX3Zv2wnihWJC1WDVGvG7mTHuf8b57uAaITj94d6tRPDH+sUEtXdRQQ=="], + + "@typescript-eslint/utils": ["@typescript-eslint/utils@8.73.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", "@typescript-eslint/scope-manager": "8.73.0", "@typescript-eslint/types": "8.73.0", "@typescript-eslint/typescript-estree": "8.73.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "sha512-j2SVJJvVkXdUL0WcEzo4vEH1mO1vIi8KlVukcYA2MgMZvYN2LlZR4PmsW+GTSxSW24j6Q/EP7+MOifLtg5hmsA=="], + + "@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.73.0", "", { "dependencies": { "@typescript-eslint/types": "8.73.0", "eslint-visitor-keys": "^5.0.0" } }, "sha512-k4lsFVpRZICbltkIEEH4hZRkwXkqDF1GHBpClKQOHQY+RkoZAAuyc1ci3I6p+CB6v3U4jaHIUshc4RzzQXZWLg=="], + + "@vitest/expect": ["@vitest/expect@3.2.7", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/spy": "3.2.7", "@vitest/utils": "3.2.7", "chai": "^5.2.0", "tinyrainbow": "^2.0.0" } }, "sha512-E8eBXaKibuvH2pSZErOjdVb5vF4PbKYcrnluBTYxEk1l/VhhwZg1kZQsdtjq+CsF5CFydf2Rdkz7jDHKSisi3w=="], + + "@vitest/mocker": ["@vitest/mocker@3.2.7", "", { "dependencies": { "@vitest/spy": "3.2.7", "estree-walker": "^3.0.3", "magic-string": "^0.30.17" }, "peerDependencies": { "msw": "^2.4.9", "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0" }, "optionalPeers": ["msw", "vite"] }, "sha512-Trr0hYO9CM3Wj6ksWHRhK9IZpIY6wTMO5u/MqXurMxT57sWBaOPEtP3Oq60ihZuh5JsiagKfz95OcxdEP6dBrA=="], + + "@vitest/pretty-format": ["@vitest/pretty-format@3.2.7", "", { "dependencies": { "tinyrainbow": "^2.0.0" } }, "sha512-KUHlwqVu0sRlhCdyPdQ/wBoTfRahjUky1MubOmYw9fWfIZy1gNoHpuaaQBPAaMaVYdQYHJLurzj8ECCj5OwTqA=="], + + "@vitest/runner": ["@vitest/runner@3.2.7", "", { "dependencies": { "@vitest/utils": "3.2.7", "pathe": "^2.0.3", "strip-literal": "^3.0.0" } }, "sha512-sB9y4ovltoQP+WaUPwmSxO9WIg9Ig694Di5PalVPsYHklAdE027mehpWF2SQSVq+k6sFgaivbTjTJwZLSHbedA=="], + + "@vitest/snapshot": ["@vitest/snapshot@3.2.7", "", { "dependencies": { "@vitest/pretty-format": "3.2.7", "magic-string": "^0.30.17", "pathe": "^2.0.3" } }, "sha512-7C+MwShwtBSI5Buwoyg3s/iY1eHL9PKAf+O1wVh/TdnjXUtkoL/9YQtre90i4MtNXM6edP1wJ2zOBpfCyhIS7g=="], + + "@vitest/spy": ["@vitest/spy@3.2.7", "", { "dependencies": { "tinyspy": "^4.0.3" } }, "sha512-Q2eQGI6d2L/hBtZ0qNuKcAGid68XK6cv1xsoaIma6PaJhHPoqcEJhYpXZ/5myCMqkNgtP6UKuBhbc0nHKnrkuQ=="], + + "@vitest/utils": ["@vitest/utils@3.2.7", "", { "dependencies": { "@vitest/pretty-format": "3.2.7", "loupe": "^3.1.4", "tinyrainbow": "^2.0.0" } }, "sha512-x6BDOd7dyo3PFLY3I9/HJ25X/6OurhGXk2/B9gOZNPF7XDVjeBK4k01lQE5uvDpbuheErh91qYuE1E2OEjK3Rw=="], + + "acorn": ["acorn@8.19.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw=="], + + "acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="], + + "agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="], + + "ajv": ["ajv@6.15.0", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw=="], + + "ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="], + + "argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="], + + "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], + + "balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="], + + "bidi-js": ["bidi-js@1.1.0", "", { "dependencies": { "require-from-string": "^2.0.2" } }, "sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg=="], + + "brace-expansion": ["brace-expansion@1.1.22", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-CKLDTuSsN0+r1ThM0WkzzBI7dnPI6xEGfa/JnVYIK9JNBA1N1NyPwXVHor//NKD/y3sDxp764sZdLhFK7pH8XQ=="], + + "cac": ["cac@6.7.14", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="], + + "callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="], + + "chai": ["chai@5.3.3", "", { "dependencies": { "assertion-error": "^2.0.1", "check-error": "^2.1.1", "deep-eql": "^5.0.1", "loupe": "^3.1.0", "pathval": "^2.0.0" } }, "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw=="], + + "chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="], + + "check-error": ["check-error@2.1.3", "", {}, "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA=="], + + "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="], + + "color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="], + + "concat-map": ["concat-map@0.0.1", "", {}, "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="], + + "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="], + + "css-tree": ["css-tree@3.2.1", "", { "dependencies": { "mdn-data": "2.27.1", "source-map-js": "^1.2.1" } }, "sha512-X7sjQzceUhu1u7Y/ylrRZFU2FS6LRiFVp6rKLPg23y3x3c3DOKAwuXGDp+PAGjh6CSnCjYeAul8pcT8bAl+lSA=="], + + "cssstyle": ["cssstyle@5.3.7", "", { "dependencies": { "@asamuzakjp/css-color": "^4.1.1", "@csstools/css-syntax-patches-for-csstree": "^1.0.21", "css-tree": "^3.1.0", "lru-cache": "^11.2.4" } }, "sha512-7D2EPVltRrsTkhpQmksIu+LxeWAIEk6wRDMJ1qljlv+CKHJM+cJLlfhWIzNA44eAsHXSNe3+vO6DW1yCYx8SuQ=="], + + "data-urls": ["data-urls@6.0.1", "", { "dependencies": { "whatwg-mimetype": "^5.0.0", "whatwg-url": "^15.1.0" } }, "sha512-euIQENZg6x8mj3fO6o9+fOW8MimUI4PpD/fZBhJfeioZVy9TUpM4UY7KjQNVZFlqwJ0UdzRDzkycB997HEq1BQ=="], + + "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" }, "peerDependencies": { "supports-color": "*" }, "optionalPeers": ["supports-color"] }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="], + + "decimal.js": ["decimal.js@10.6.0", "", {}, "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg=="], + + "deep-eql": ["deep-eql@5.0.2", "", {}, "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q=="], + + "deep-is": ["deep-is@0.1.4", "", {}, "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="], + + "entities": ["entities@6.0.1", "", {}, "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g=="], + + "es-module-lexer": ["es-module-lexer@1.7.0", "", {}, "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA=="], + + "esbuild": ["esbuild@0.28.2", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.28.2", "@esbuild/android-arm": "0.28.2", "@esbuild/android-arm64": "0.28.2", "@esbuild/android-x64": "0.28.2", "@esbuild/darwin-arm64": "0.28.2", "@esbuild/darwin-x64": "0.28.2", "@esbuild/freebsd-arm64": "0.28.2", "@esbuild/freebsd-x64": "0.28.2", "@esbuild/linux-arm": "0.28.2", "@esbuild/linux-arm64": "0.28.2", "@esbuild/linux-ia32": "0.28.2", "@esbuild/linux-loong64": "0.28.2", "@esbuild/linux-mips64el": "0.28.2", "@esbuild/linux-ppc64": "0.28.2", "@esbuild/linux-riscv64": "0.28.2", "@esbuild/linux-s390x": "0.28.2", "@esbuild/linux-x64": "0.28.2", "@esbuild/netbsd-arm64": "0.28.2", "@esbuild/netbsd-x64": "0.28.2", "@esbuild/openbsd-arm64": "0.28.2", "@esbuild/openbsd-x64": "0.28.2", "@esbuild/openharmony-arm64": "0.28.2", "@esbuild/sunos-x64": "0.28.2", "@esbuild/win32-arm64": "0.28.2", "@esbuild/win32-ia32": "0.28.2", "@esbuild/win32-x64": "0.28.2" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA=="], + + "escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="], + + "eslint": ["eslint@9.39.5", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.21.2", "@eslint/config-helpers": "^0.4.2", "@eslint/core": "^0.17.0", "@eslint/eslintrc": "^3.3.6", "@eslint/js": "9.39.5", "@eslint/plugin-kit": "^0.4.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.4.0", "eslint-visitor-keys": "^4.2.1", "espree": "^10.4.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.5", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-DgZS62aPLXKlnxILS/AYCoRvHaZeXceIzlXPkkGGzJWSow1aEk0lbTlxUSlyjC8jcaKxAdOnTDz+o1JFSBsyjw=="], + + "eslint-config-prettier": ["eslint-config-prettier@10.1.8", "", { "peerDependencies": { "eslint": ">=7.0.0" }, "bin": { "eslint-config-prettier": "bin/cli.js" } }, "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w=="], + + "eslint-scope": ["eslint-scope@8.4.0", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg=="], + + "eslint-visitor-keys": ["eslint-visitor-keys@4.2.1", "", {}, "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ=="], + + "espree": ["espree@10.4.0", "", { "dependencies": { "acorn": "^8.15.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^4.2.1" } }, "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ=="], + + "esquery": ["esquery@1.7.0", "", { "dependencies": { "estraverse": "^5.1.0" } }, "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g=="], + + "esrecurse": ["esrecurse@4.3.0", "", { "dependencies": { "estraverse": "^5.2.0" } }, "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag=="], + + "estraverse": ["estraverse@5.3.0", "", {}, "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA=="], + + "estree-walker": ["estree-walker@3.0.3", "", { "dependencies": { "@types/estree": "^1.0.0" } }, "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g=="], + + "esutils": ["esutils@2.0.3", "", {}, "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="], + + "expect-type": ["expect-type@1.4.0", "", {}, "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA=="], + + "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], + + "fast-json-stable-stringify": ["fast-json-stable-stringify@2.1.0", "", {}, "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="], + + "fast-levenshtein": ["fast-levenshtein@2.0.6", "", {}, "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="], + + "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], + + "file-entry-cache": ["file-entry-cache@8.0.0", "", { "dependencies": { "flat-cache": "^4.0.0" } }, "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ=="], + + "find-up": ["find-up@5.0.0", "", { "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng=="], + + "flat-cache": ["flat-cache@4.0.1", "", { "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.4" } }, "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw=="], + + "flatted": ["flatted@3.4.4", "", {}, "sha512-5+ybhBZANEJxaH3X5evAFatUxLfEHSr7n6kYJ+1Qd0mUqr4eu9gIf6GDbWHf8RJijHrjjO8G+la14SlL2SeS1Q=="], + + "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], + + "glob-parent": ["glob-parent@6.0.2", "", { "dependencies": { "is-glob": "^4.0.3" } }, "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A=="], + + "globals": ["globals@14.0.0", "", {}, "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ=="], + + "has-flag": ["has-flag@4.0.0", "", {}, "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="], + + "html-encoding-sniffer": ["html-encoding-sniffer@6.0.0", "", { "dependencies": { "@exodus/bytes": "^1.6.0" } }, "sha512-CV9TW3Y3f8/wT0BRFc1/KAVQ3TUHiXmaAb6VW9vtiMFf7SLoMd1PdAc4W3KFOFETBJUb90KatHqlsZMWV+R9Gg=="], + + "http-proxy-agent": ["http-proxy-agent@7.0.2", "", { "dependencies": { "agent-base": "^7.1.0", "debug": "^4.3.4" } }, "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig=="], + + "https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="], + + "ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], + + "import-fresh": ["import-fresh@3.3.1", "", { "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ=="], + + "imurmurhash": ["imurmurhash@0.1.4", "", {}, "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA=="], + + "is-extglob": ["is-extglob@2.1.1", "", {}, "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ=="], + + "is-glob": ["is-glob@4.0.3", "", { "dependencies": { "is-extglob": "^2.1.1" } }, "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg=="], + + "is-potential-custom-element-name": ["is-potential-custom-element-name@1.0.1", "", {}, "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ=="], + + "isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="], + + "js-tokens": ["js-tokens@9.0.1", "", {}, "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ=="], + + "js-yaml": ["js-yaml@4.3.2", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA=="], + + "jsdom": ["jsdom@27.4.0", "", { "dependencies": { "@acemir/cssom": "^0.9.28", "@asamuzakjp/dom-selector": "^6.7.6", "@exodus/bytes": "^1.6.0", "cssstyle": "^5.3.4", "data-urls": "^6.0.0", "decimal.js": "^10.6.0", "html-encoding-sniffer": "^6.0.0", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.6", "is-potential-custom-element-name": "^1.0.1", "parse5": "^8.0.0", "saxes": "^6.0.0", "symbol-tree": "^3.2.4", "tough-cookie": "^6.0.0", "w3c-xmlserializer": "^5.0.0", "webidl-conversions": "^8.0.0", "whatwg-mimetype": "^4.0.0", "whatwg-url": "^15.1.0", "ws": "^8.18.3", "xml-name-validator": "^5.0.0" }, "peerDependencies": { "canvas": "^3.0.0" }, "optionalPeers": ["canvas"] }, "sha512-mjzqwWRD9Y1J1KUi7W97Gja1bwOOM5Ug0EZ6UDK3xS7j7mndrkwozHtSblfomlzyB4NepioNt+B2sOSzczVgtQ=="], + + "json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="], + + "json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="], + + "json-stable-stringify-without-jsonify": ["json-stable-stringify-without-jsonify@1.0.1", "", {}, "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw=="], + + "keyv": ["keyv@4.5.4", "", { "dependencies": { "json-buffer": "3.0.1" } }, "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw=="], + + "levn": ["levn@0.4.1", "", { "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" } }, "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ=="], + + "locate-path": ["locate-path@6.0.0", "", { "dependencies": { "p-locate": "^5.0.0" } }, "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw=="], + + "lodash.merge": ["lodash.merge@4.6.2", "", {}, "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="], + + "loupe": ["loupe@3.2.1", "", {}, "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ=="], + + "lru-cache": ["lru-cache@11.5.3", "", {}, "sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg=="], + + "magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="], + + "mdn-data": ["mdn-data@2.27.1", "", {}, "sha512-9Yubnt3e8A0OKwxYSXyhLymGW4sCufcLG6VdiDdUGVkPhpqLxlvP5vl1983gQjJl3tqbrM731mjaZaP68AgosQ=="], + + "minimatch": ["minimatch@3.1.5", "", { "dependencies": { "brace-expansion": "^1.1.7" } }, "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w=="], + + "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], + + "nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="], + + "natural-compare": ["natural-compare@1.4.0", "", {}, "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="], + + "optionator": ["optionator@0.9.4", "", { "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g=="], + + "p-limit": ["p-limit@3.1.0", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="], + + "p-locate": ["p-locate@5.0.0", "", { "dependencies": { "p-limit": "^3.0.2" } }, "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw=="], + + "parent-module": ["parent-module@1.0.1", "", { "dependencies": { "callsites": "^3.0.0" } }, "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g=="], + + "parse5": ["parse5@7.3.0", "", { "dependencies": { "entities": "^6.0.0" } }, "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw=="], + + "path-exists": ["path-exists@4.0.0", "", {}, "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="], + + "path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="], + + "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], + + "pathval": ["pathval@2.0.1", "", {}, "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ=="], + + "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], + + "picomatch": ["picomatch@4.0.7", "", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], + + "playwright": ["playwright@1.65.1", "", { "dependencies": { "playwright-core": "1.65.1" }, "bin": { "playwright": "cli.js" } }, "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw=="], + + "playwright-core": ["playwright-core@1.65.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw=="], + + "postcss": ["postcss@8.5.33", "", { "dependencies": { "nanoid": "^3.3.20", "picocolors": "^1.1.1", "source-map-js": "^1.2.2" } }, "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ=="], + + "prelude-ls": ["prelude-ls@1.2.1", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="], + + "prettier": ["prettier@3.10.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-70vp3ZUYoPlFbF9uiTdXHUUCGEIp7d4+6p+8DYbkm2jP7x/3i/paXVF6dopSI3zd/CEitrZN1rc4i85xWmmXlg=="], + + "punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="], + + "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="], + + "resolve-from": ["resolve-from@4.0.0", "", {}, "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g=="], + + "rollup": ["rollup@4.68.8", "", { "dependencies": { "@types/estree": "^1.0.10" }, "optionalDependencies": { "@rollup/rollup-android-arm-eabi": "4.68.8", "@rollup/rollup-android-arm64": "4.68.8", "@rollup/rollup-android-x64": "4.68.8", "@rollup/rollup-darwin-arm64": "4.68.8", "@rollup/rollup-darwin-x64": "4.68.8", "@rollup/rollup-freebsd-arm64": "4.68.8", "@rollup/rollup-freebsd-x64": "4.68.8", "@rollup/rollup-linux-arm-gnueabihf": "4.68.8", "@rollup/rollup-linux-arm-musleabihf": "4.68.8", "@rollup/rollup-linux-arm64-gnu": "4.68.8", "@rollup/rollup-linux-arm64-musl": "4.68.8", "@rollup/rollup-linux-loong64-gnu": "4.68.8", "@rollup/rollup-linux-loong64-musl": "4.68.8", "@rollup/rollup-linux-ppc64-gnu": "4.68.8", "@rollup/rollup-linux-ppc64-musl": "4.68.8", "@rollup/rollup-linux-riscv64-gnu": "4.68.8", "@rollup/rollup-linux-riscv64-musl": "4.68.8", "@rollup/rollup-linux-s390x-gnu": "4.68.8", "@rollup/rollup-linux-x64-gnu": "4.68.8", "@rollup/rollup-linux-x64-musl": "4.68.8", "@rollup/rollup-openbsd-x64": "4.68.8", "@rollup/rollup-openharmony-arm64": "4.68.8", "@rollup/rollup-win32-arm64-msvc": "4.68.8", "@rollup/rollup-win32-ia32-msvc": "4.68.8", "@rollup/rollup-win32-x64-gnu": "4.68.8", "@rollup/rollup-win32-x64-msvc": "4.68.8", "fsevents": "~2.3.2" }, "bin": { "rollup": "dist/bin/rollup" } }, "sha512-IHx4DeeTGhoAPke6p1Wlg0JEQFyQoZQQjEe1iD+nhEERk7eoeHK9zyOpVJiGc54Z1MCgI96rN1tD7Ttub8XyPA=="], + + "saxes": ["saxes@6.0.0", "", { "dependencies": { "xmlchars": "^2.2.0" } }, "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA=="], + + "schema-dts": ["schema-dts@2.1.0", "", { "dependencies": { "schema-dts-lib": "^1.1.0" } }, "sha512-Y/NvOvuJUZwrm+EmNqJF3M+bRufERJs1h5GJPLilUuK5D5b53ttU+XZgIjEFaAVRToh+ib+cQawFmxKC5Jt9ow=="], + + "schema-dts-lib": ["schema-dts-lib@1.1.0", "", {}, "sha512-Nx00FDPHDimSENMznVpADeYUJDsqlMiO9wcs2S+giggNTm5+ruNkM4m9z9qCk6xUJT+ThDM3NxxpwfHfFk1G+Q=="], + + "semver": ["semver@7.8.6", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw=="], + + "shebang-command": ["shebang-command@2.0.0", "", { "dependencies": { "shebang-regex": "^3.0.0" } }, "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA=="], + + "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="], + + "siginfo": ["siginfo@2.0.0", "", {}, "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g=="], + + "source-map-js": ["source-map-js@1.2.4", "", {}, "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA=="], + + "stackback": ["stackback@0.0.2", "", {}, "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw=="], + + "std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="], + + "strip-json-comments": ["strip-json-comments@3.1.1", "", {}, "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig=="], + + "strip-literal": ["strip-literal@3.1.0", "", { "dependencies": { "js-tokens": "^9.0.1" } }, "sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg=="], + + "supports-color": ["supports-color@7.2.0", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="], + + "symbol-tree": ["symbol-tree@3.2.4", "", {}, "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw=="], + + "tinybench": ["tinybench@2.9.0", "", {}, "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg=="], + + "tinyexec": ["tinyexec@0.3.2", "", {}, "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA=="], + + "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], + + "tinypool": ["tinypool@1.1.1", "", {}, "sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg=="], + + "tinyrainbow": ["tinyrainbow@2.0.0", "", {}, "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw=="], + + "tinyspy": ["tinyspy@4.0.6", "", {}, "sha512-u8KszXvGfU68hVcZpRHKG28T0krMuv2G5nDhiHaMLen/gIuFEgIJhaJuO69qjnXg5paSrbPMFfx3brNuN8eVSg=="], + + "tldts": ["tldts@7.5.5", "", { "dependencies": { "tldts-core": "^7.5.5" }, "bin": { "tldts": "bin/cli.js" } }, "sha512-Hy6IImaWALzJOgCIss4gIFi4G0M9lqk95pFKCUVxQPZw+biZ1Pv6f28JpYgahpJB+BufA0HYsIU/aP/WIx3KRg=="], + + "tldts-core": ["tldts-core@7.5.5", "", {}, "sha512-rEJz/8cJFY/bdF354gl14yxavbrIbvM+FcbkYVQ6CSCMQTJdUFUIm39TTWSiGPvcpQh7/F6qHrD3SkwwdgtDCw=="], + + "tough-cookie": ["tough-cookie@6.1.0", "", { "dependencies": { "tldts": "^7.0.5" } }, "sha512-FTxc8u8Kl2tz0Lat1u8ksvcy8bwHRyEMawwTWybo51JqaC6O7SvfuhAKg+Ld6VqyIe2QRJBzY9HA7y2WyFRT2w=="], + + "tr46": ["tr46@6.0.0", "", { "dependencies": { "punycode": "^2.3.1" } }, "sha512-bLVMLPtstlZ4iMQHpFHTR7GAGj2jxi8Dg0s2h2MafAE4uSWF98FC/3MomU51iQAMf8/qDUbKWf5GxuvvVcXEhw=="], + + "ts-api-utils": ["ts-api-utils@2.5.0", "", { "peerDependencies": { "typescript": ">=4.8.4" } }, "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA=="], + + "type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="], + + "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + + "typescript-eslint": ["typescript-eslint@8.73.0", "", { "dependencies": { "@typescript-eslint/eslint-plugin": "8.73.0", "@typescript-eslint/parser": "8.73.0", "@typescript-eslint/typescript-estree": "8.73.0", "@typescript-eslint/utils": "8.73.0" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "sha512-+EnKy9rkYPun4l+kG2bDuYWQ6y1tGVgdR/tY1U9AC6h21CjEwOoc7gsjwe0FXB8uWFzk4QiCFbuRWgX758PiAg=="], + + "undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], + + "uri-js": ["uri-js@4.4.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg=="], + + "vite": ["vite@7.3.8", "", { "dependencies": { "esbuild": "^0.27.0 || ^0.28.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-3tTi78MAKhVk9h+YZVXMQ8POmneJuE97QUPAWtJghHzhH7BAyiqQOC2KZh1DWOsu/USB2cRXhznPByaabvYXfw=="], + + "vite-node": ["vite-node@3.2.4", "", { "dependencies": { "cac": "^6.7.14", "debug": "^4.4.1", "es-module-lexer": "^1.7.0", "pathe": "^2.0.3", "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0" }, "bin": { "vite-node": "vite-node.mjs" } }, "sha512-EbKSKh+bh1E1IFxeO0pg1n4dvoOTt0UDiXMd/qn++r98+jPO1xtJilvXldeuQ8giIB5IkpjCgMleHMNEsGH6pg=="], + + "vitest": ["vitest@3.2.7", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/expect": "3.2.7", "@vitest/mocker": "3.2.7", "@vitest/pretty-format": "^3.2.7", "@vitest/runner": "3.2.7", "@vitest/snapshot": "3.2.7", "@vitest/spy": "3.2.7", "@vitest/utils": "3.2.7", "chai": "^5.2.0", "debug": "^4.4.1", "expect-type": "^1.2.1", "magic-string": "^0.30.17", "pathe": "^2.0.3", "picomatch": "^4.0.2", "std-env": "^3.9.0", "tinybench": "^2.9.0", "tinyexec": "^0.3.2", "tinyglobby": "^0.2.14", "tinypool": "^1.1.1", "tinyrainbow": "^2.0.0", "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0", "vite-node": "3.2.4", "why-is-node-running": "^2.3.0" }, "peerDependencies": { "@edge-runtime/vm": "*", "@types/debug": "^4.1.12", "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", "@vitest/browser": "3.2.7", "@vitest/ui": "3.2.7", "happy-dom": "*", "jsdom": "*" }, "optionalPeers": ["@edge-runtime/vm", "@types/debug", "@types/node", "@vitest/browser", "@vitest/ui", "happy-dom", "jsdom"], "bin": { "vitest": "./vitest.mjs" } }, "sha512-KrxIJ62Fd89gfysR4WotlgZABiz2dqFPgqGzX7s+CwsqLFomRH7777ZcrOD6+WVAh7khPQP41A+BKbpcJFrdEg=="], + + "w3c-xmlserializer": ["w3c-xmlserializer@5.0.0", "", { "dependencies": { "xml-name-validator": "^5.0.0" } }, "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA=="], + + "webidl-conversions": ["webidl-conversions@8.0.1", "", {}, "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ=="], + + "whatwg-mimetype": ["whatwg-mimetype@4.0.0", "", {}, "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg=="], + + "whatwg-url": ["whatwg-url@15.1.0", "", { "dependencies": { "tr46": "^6.0.0", "webidl-conversions": "^8.0.0" } }, "sha512-2ytDk0kiEj/yu90JOAp44PVPUkO9+jVhyf+SybKlRHSDlvOOZhdPIrr7xTH64l4WixO2cP+wQIcgujkGBPPz6g=="], + + "which": ["which@2.0.2", "", { "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "./bin/node-which" } }, "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="], + + "why-is-node-running": ["why-is-node-running@2.3.0", "", { "dependencies": { "siginfo": "^2.0.0", "stackback": "0.0.2" }, "bin": { "why-is-node-running": "cli.js" } }, "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w=="], + + "word-wrap": ["word-wrap@1.2.5", "", {}, "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA=="], + + "ws": ["ws@8.23.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-wCkmX8QMOrKjgO8HW2WyDbTSGeqkocxgDzS9iR79rEAexty6/2qzilx3Ag8Tqf9ykop3irLKle0MtVn5qjVnoQ=="], + + "xml-name-validator": ["xml-name-validator@5.0.0", "", {}, "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg=="], + + "xmlchars": ["xmlchars@2.2.0", "", {}, "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw=="], + + "yocto-queue": ["yocto-queue@0.1.0", "", {}, "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="], + + "@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="], + + "@types/jsdom/@types/node": ["@types/node@26.6.6", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog=="], + + "@typescript-eslint/eslint-plugin/ignore": ["ignore@7.0.16", "", {}, "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A=="], + + "@typescript-eslint/typescript-estree/minimatch": ["minimatch@11.0.9", "", { "dependencies": { "@isaacs/nonrecursive-glob-match": "^1.1.0", "brace-expansion": "^5.0.12" } }, "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q=="], + + "@typescript-eslint/visitor-keys/eslint-visitor-keys": ["eslint-visitor-keys@5.0.1", "", {}, "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA=="], + + "data-urls/whatwg-mimetype": ["whatwg-mimetype@5.0.0", "", {}, "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw=="], + + "jsdom/parse5": ["parse5@8.1.1", "", { "dependencies": { "entities": "^9.0.0" } }, "sha512-EcR/6WDcU7b2N3vQSxKALCk9lXGtUMQxXio008OEMBE0kavu/7JLfBEeFPzi43nMqVDSbEn3QCK+BMCc9zO//w=="], + + "@types/jsdom/@types/node/undici-types": ["undici-types@8.9.0", "", {}, "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg=="], + + "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@5.0.13", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-Vh3dmFbc4wZeox7M9I/0L9GfFd83Su4+yCck/OF9Gi/P/dAHn0RT7X4K9R7gMNMhDck3DvhR6QXsnQdjjgwNvQ=="], + + "jsdom/parse5/entities": ["entities@9.0.0", "", {}, "sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg=="], + + "@typescript-eslint/typescript-estree/minimatch/brace-expansion/balanced-match": ["balanced-match@4.0.4", "", {}, "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="], + } +} diff --git a/docs/API.md b/docs/API.md new file mode 100644 index 0000000..d8f1bf7 --- /dev/null +++ b/docs/API.md @@ -0,0 +1,408 @@ +# API reference + +Full public surface of `@expert-vision-software/programmatic-seo` (exported from +`src/index.ts`). + +Adapted from the upstream reference document +[seo-service-api.md](https://github.com/Expert-Vision-Software/billgrokker/blob/3169c7a10003/docs/reference/seo-service-api.md) +(BillGrokker, master @ `3169c7a10003`), verified against this package's source. + +--- + +## `SeoService` + +The entry point. One instance per app (register as a singleton). + +```ts +class SeoService { + readonly siteWide: ISitewideBuilder; + get rootUrl(): string; + initialize(config: SeoServiceConfig | string): void; + emit(seoPage: ISeoPage): void; + page(): IPageBuilder; + prepareToNavigate(): void; + setUrl(pathOrUrl: string): this; + resolveUrl(path: string): string; + setSiteName(name: string): this; + getDefaults(): SeoConfig; +} +``` + +### `initialize(config: SeoServiceConfig | string): void` + +Initializes the service, reads static defaults from the host document, applies page +defaults, and renders any site-wide nodes configured before `initialize()`. A string is +accepted as shorthand for `{rootUrl: str}`. Idempotent: a second call is a no-op. + +### `emit(seoPage: ISeoPage): void` + +The single atomic commit point. Accepts a plain `ISeoPage` object. See +[merge semantics](#emit-merge-semantics). + +### `page(): IPageBuilder` + +Factory returning a chainable [`SeoPageBuilder`](#seoPageBuilder) (L1). The canonical entry +point for all page-level SEO. See [builder chains](#builder-chains-l1--l2). + +### `prepareToNavigate(): void` + +Page-state reset between navigations: removes meta/canonical tags the service created, +removes `script[data-seo="true"]` scripts, clears page-level title/keywords/breadcrumbs, and +re-renders the graph from site-wide state only. Call on navigation start. + +### `setUrl(pathOrUrl: string): this` + +First-class navigation-sync method (not a builder passthrough). Called with +`window.location.href` on navigation end. Accepts an absolute URL or a root-relative path; +invalid values throw `` `Invalid URL: ${pathOrUrl}` ``. Sets `og:url`, `twitter:url`, the +canonical link, and syncs the active `WebPage`/`Article` node's `url`. + +### `resolveUrl(path: string): string` + +Resolves a path against the configured `rootUrl` (absolute URLs pass through). + +### `setSiteName(name: string): this` + +Sets `og:site_name` and `apple-mobile-web-app-title`. + +### `getDefaults(): SeoConfig` + +Returns the `SeoConfig` parsed from the host document at `initialize()` time. + +--- + +## `SeoServiceConfig` + +```ts +type SeoServiceConfig = { + rootUrl: string; + siteTitle?: string; + pageTitleSuffix?: string; + language?: string; + description?: string; + defaultKeywords?: readonly string[]; + graphScriptDomId?: string; + webApplicationId?: string; + logoId?: string; + organizationId?: string; + logger?: SeoLogger; +}; +``` + +`pageTitleSuffix` defaults to `" | ${siteTitle}"` when a `siteTitle` (or a document-parsed +site name) is present. The `@id` fields default to `${rootUrl}/#webapplication`, `#logo`, +`#organization`. `graphScriptDomId` defaults to `${rootUrl}/#graph` and identifies the +`<script type="application/ld+json" data-id="...">` the service hydrates from and renders +into. `logger` is the [SeoLogger](#seologger) bridge. + +--- + +## `ISitewideBuilder` + +Available as `service.siteWide`. Configure before or after `initialize()`; nodes persist +across `prepareToNavigate()` resets. All setters return the builder. + +| Method | Renders | +|---|---| +| `setBreadcrumb(items)` | Site-wide breadcrumb prefix merged into every page's `BreadcrumbList` | +| `setKeywords(...keywords)` | Site-wide keyword baseline for pages that don't set their own | +| `setBaseGraphNode(node)` | Arbitrary JSON-LD node by explicit `@id` | +| `setLogo({url, width, height, caption?})` | `ImageObject` node at the configured logo `@id`; back-fills `logo` refs on existing organization/application nodes | +| `setOrganization({name, url?, logo?, sameAs?, contactPoint?})` | `Organization` node; back-fills `publisher` on the application node | +| `setWebApplication({name, url?, description?, softwareVersion?, applicationCategory?, operatingSystem?})` | `WebApplication`/`SoftwareApplication` node with a free `Offer` | + +--- + +## `SeoLogger` + +The logging seam. Supply an implementation via `SeoServiceConfig.logger`; without one the +service is silent. + +```ts +interface SeoLogger { + debug(msg: string, ...args: unknown[]): void; + info(msg: string, ...args: unknown[]): void; + warn(msg: string, ...args: unknown[]): void; + error(msg: string, ...args: unknown[]): void; +} +``` + +--- + +## Builder chains (L1 / L2) + +### `SeoPageBuilder` — L1 + +Created by `service.page()`. Also constructible standalone via +`createBuilder(target)` with `{rootUrl, emit}` — useful in tests. All setters return `this`; +`emit()` commits the built spec; `build()` returns the `ISeoPage` without committing. + +```ts +interface IPageBuilder { + setTitle(title: string): this; + setDescription(description: string): this; + setUrl(url: string): this; + setCanonicalPath(path: string): this; + setOgType(type: "article" | "website"): this; + setImage(image: string): this; + setKeywords(...keywords: (string | string[])[]): this; + appendKeywords(...keywords: (string | string[])[]): this; + setBreadcrumbs(items: readonly BreadcrumbItem[]): this; + appendBreadcrumbs(items: readonly BreadcrumbItem[]): this; + setNoIndex(): this; + setStatusCode(code: number): this; + setResponseHttpStatus(code: number): this; + setTwitter(options: TwitterSpec): this; + setWebPage(spec: WebPageBuilderSpec): this; + setArticle(spec: ArticleBuilderSpec): this; + setFaqPage(spec: FaqPageSpec): this; + contentPage(): ContentPageBuilder; + emit(): void; + build(): ISeoPage; +} +``` + +`setKeywords` and `appendKeywords` are de-duplicating and cumulative within one chain; +`appendBreadcrumbs` extends the chain's breadcrumb list, `setBreadcrumbs` replaces it. +`setWebPage`/`setArticle` merge field-by-field into the chain's node state; dates accept +`SeoDateInput` and are normalized (see [DateOnly normalization](#dateonly-normalization)). + +#### URL hygiene guard + +`setUrl`, `setCanonicalPath`, `setWebPage({canonicalPath})`, `setArticle({canonicalPath})`, +and `setFaqPage({canonicalPath})` **throw** when passed an absolute `http(s)` URL whose +origin matches the configured `rootUrl`: + +``` +Use relative url when referring to same website. If you mean to set to another site's root url, it cannot match the value of '${rootUrl}'. +``` + +Exception: `setImage` is NOT guarded (`og:image` accepts absolute off-site URLs). + +### `ContentPageBuilder` — L2 + +Created by `page().contentPage()`. Entering L2 seeds the `webPage` + `article` node pair +(`webPage` gets `breadcrumb: true` by default), sets `ogType: "article"`, and exposes +article-focused helpers. `end()` returns to the parent `SeoPageBuilder` (e.g. to reach +`setFaqPage`). All L1 setters are delegated; `emit()`/`build()` delegate too. + +```ts +class ContentPageBuilder { + setDates(dates: {published?: SeoDateInput; modified?: SeoDateInput}): this; + setAbout(about: string | Thing): this; + setSection(section: string): this; + setQuestion(question: {name: string; answerText: string; answerUrl?: string}): this; + setFaqPage(spec: FaqPageSpec): this; + end(): SeoPageBuilder; +} +``` + +- `setDates` fans the published/modified dates to both the `webPage` and `article` nodes. +- `setAbout("Policy Area")` wraps the string as a `Thing` and sets `articleSection` to the + same value; passing a `Thing` object sets `about` only. `setSection` sets + `articleSection` only. +- `setQuestion` sets `webPage.mainEntity` to a `Question` with an `acceptedAnswer` + (`answerUrl` adds an `url` on the answer). + +#### Root-value inheritance + +At `build()` time: + +- `title` → `webPage.name`, `article.name`, `article.headline` (when not explicitly set) +- `description` → `webPage.description`, `article.description` (when not explicitly set) +- `url` (relative) → `webPage.canonicalPath`, `article.canonicalPath` (when not explicitly + set; explicit `setCanonicalPath` wins, and sets canonical-only without syncing `url` / + `og:url`) +- chain `keywords` → `article.keywords` (comma-joined) when `setArticle` didn't set its own + +Builder chains and atomic `emit()` are provably interchangeable: `page().set*(...).emit()` +builds exactly the `ISeoPage` that an equivalent `emit(spec)` consumes. + +--- + +## The `ISeoPage` spec + +Pure data, zero framework types. Every field is optional; omitted fields leave current +page-state untouched. + +```ts +interface ISeoPage { + title?: string; + description?: string; + url?: string; + canonicalPath?: string; + ogType?: "article" | "website"; + image?: string; + keywords?: AppendableList<string>; + breadcrumbs?: AppendableList<BreadcrumbItem>; + noIndex?: boolean; + statusCode?: number; + responseHttpStatus?: number; + webPage?: WebPageSpec; + article?: ArticleSpec; + faqPage?: FaqPageSpec; + twitter?: TwitterSpec; +} +``` + +| Field | Renders | +|---|---| +| `title` | `document.title` (with configured suffix), `og:title`, `twitter:title` | +| `description` | `<meta name="description">`, `og:description`, `twitter:description` | +| `url` | `og:url`, `twitter:url`, `<link rel="canonical">`, active node `url` sync | +| `canonicalPath` | `<link rel="canonical">` only — no `og:url` sync | +| `ogType` | `og:type` | +| `image` | `og:image`, `twitter:image` | +| `keywords` | `<meta name="keywords">`, `og:keywords`, active `Article` node `keywords` | +| `breadcrumbs` | `BreadcrumbList` JSON-LD node, merged after site-wide items | +| `noIndex` | `<meta name="robots" content="noindex, nofollow">` when `true` | +| `statusCode` | `<meta name="prerender-status-code">` | +| `responseHttpStatus` | `<meta name="response-http-status">` (hosting-layer status hint) | +| `twitter` | `twitter:card`, `twitter:site` (handle normalized to `@…`) | + +### `WebPageSpec` + +| Field | Type | Notes | +|---|---|---| +| `canonicalPath` | `string` (required) | Computes the node's `@id` (`${rootUrl}${path}#webpage`) and `url` | +| `name` | `string?` | Falls back to the page `title` | +| `description` | `string` (required) | Copied verbatim into the node | +| `datePublished` | `string?` | ISO-8601 | +| `dateModified` | `string?` | ISO-8601 | +| `breadcrumb` | `boolean?` | `true` adds the `breadcrumb` `@id` ref and renders the breadcrumb list even with no page-level items | +| `mainEntity` | `Thing \| Thing[]?` | E.g. a `Question` for Q&A pages | + +### `ArticleSpec` + +| Field | Type | Notes | +|---|---|---| +| `canonicalPath` | `string` (required) | `@id` is `${rootUrl}${path}#article` | +| `name` | `string?` | Falls back to page `title` | +| `headline` | `string?` | Falls back to page `title` | +| `description` | `string` (required) | | +| `datePublished` | `string` (required) | | +| `dateModified` | `string` (required) | | +| `about` | `Thing?` | | +| `articleSection` | `string?` | | +| `keywords` | `string?` | Comma-separated | + +### `FaqPageSpec` + +| Field | Type | Notes | +|---|---|---| +| `canonicalPath` | `string` (required) | `@id` is `${rootUrl}${path}#faqpage` | +| `mainEntity` | `Question[]` (required) | Each needs an `acceptedAnswer` for rich results | + +### `TwitterSpec` + +| Field | Type | +|---|---| +| `card` | `"summary" \| "summary_large_image" \| "app" \| "player"` | +| `handle` | `string?` (rendered with a leading `@`) | + +### `BreadcrumbItem` + +The input shape (DX); mapped to schema.org `ListItem` at render time, URLs resolved against +`rootUrl`. + +```ts +interface BreadcrumbItem { + name: string; + url: string; +} +``` + +### `AppendableList<T>` + +```ts +type AppendableList<T> = T[] | {append: T[]}; +``` + +Used for `keywords` and `breadcrumbs`: a bare array **replaces** the current page-state +list; `{append: [...]}` **appends** (de-duplicated). + +--- + +## `emit()` merge semantics + +The service holds per-navigation **page state** (reset by `prepareToNavigate()`; site-wide +state from `siteWide` is independent). `emit(spec)` applies the spec with: + +| Field kind in spec | Absent | Present | +|---|---|---| +| Scalar (`title`, `description`, `url`, `ogType`, `image`, `noIndex`, `statusCode`, `responseHttpStatus`, `canonicalPath`, `twitter.card`, `twitter.handle`) | unchanged | **replace** page-state value | +| List (`breadcrumbs`, `keywords`) as bare array | unchanged | **replace** page-state list | +| List as `{append: [...]}` | unchanged | **append** to current page-state list | +| Graph node (`webPage`, `article`, `faqPage`) | unchanged (keep current node) | **render/update** JSON-LD node (idempotent by `canonicalPath`; sets the active node id) | + +Consequences: + +- **Partial emit:** emit only what you want to set/override; omit the rest. +- **Layered contribution:** a wrapper emits `keywords: {append: [...]}`; the page emits + `keywords: [...]` (replace). Neither reads the other. +- **Idempotent graph:** re-emitting a node with the same `canonicalPath` updates it in + place (`@id` stable). +- **Reset:** `prepareToNavigate()` clears page state; `siteWide` nodes persist. + +--- + +## DateOnly normalization + +```ts +type DateOnly = `${number}${number}${number}${number}-${number}${number}-${number}${number}`; +type SeoDateInput = DateOnly | (string & {}); +function normalizeSeoDate(input: SeoDateInput): string; +``` + +`normalizeSeoDate("2025-08-01")` → `"2025-08-01T00:00:00+00:00"`. Any other string passes +through unchanged, so pre-formatted ISO strings are accepted everywhere dates go +(`setWebPage`, `setArticle`, `setDates`). + +--- + +## `HtmlSeoConfigParser` + +```ts +type SeoConfig = { + title: string; + description: string; + keywords: string[]; + siteName: string; + locale: string; + robots: string; + pageUrl: string; + logoUrl: string; + og: {type: string; imageUrl: string; imageWidth: number; imageHeight: number}; + twitter: {cardType: "summary" | "summary_large_image" | "app" | "player"; handleId: string; domain: string}; + jsonLd?: JsonLdScript[] | JsonLdScript | undefined; +}; + +type JsonLdScript = {id: string; data: JsonLdObject}; + +type GraphDocument = { + "@context": string | string[] | Record<string, unknown>; + "@graph": JsonLdObject[]; +}; + +function HtmlSeoConfigParser(rootDomain: string, graphScriptDomId?: string): SeoConfig; +``` + +Reads static SEO defaults from the host document (usually the served `index.html`): title, +meta description/keywords/robots, `og:*` and `twitter:*` metas, and the JSON-LD graph script +identified by `data-id` (default `https://${rootDomain}/#graph`). The service calls this +inside `initialize()`; the result is available via `getDefaults()`. It operates on the +host-provided `document`, staying host-agnostic (works under jsdom in tests). + +## `createBuilder` + +```ts +function createBuilder(target: ISeoBuilderTarget): IPageBuilder; + +interface ISeoBuilderTarget { + readonly rootUrl: string; + emit(seoPage: ISeoPage): void; +} +``` + +Constructs an L1 `SeoPageBuilder` against an explicit emit target — how `SeoService.page()` +wires the builder, and useful standalone in tests or custom hosts. diff --git a/docs/CI.md b/docs/CI.md new file mode 100644 index 0000000..22e38b5 --- /dev/null +++ b/docs/CI.md @@ -0,0 +1,13 @@ +# CI / Release + +Two GitHub Actions workflows: + +- **ci.yml** — runs on every PR and on pushes to `main`. Bun install, then lint, typecheck, and tests. All gates must pass. +- **release.yml** — runs when a `v*` tag is pushed. Bun install, build, test, then `npm publish --provenance` (npm, not bun, so provenance attestation works). Any failure turns the tag run red; there are no silent successes. + +## Human prerequisites (before the first publish, ticket #9) + +1. The npm org **`expert-vision-software`** must exist on npmjs.com (the unscoped `programmatic-seo` name is already taken on the registry, hence the scope). +2. An org member must add the npm automation token as the repository secret **`NPM_TOKEN`**. + +Until both are done, release runs will fail at the publish step — the workflows themselves are valid regardless. diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..0672432 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,15 @@ +import eslint from '@eslint/js'; +import eslintConfigPrettier from 'eslint-config-prettier'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config( + { ignores: ['dist/', 'coverage/'] }, + eslint.configs.recommended, + ...tseslint.configs.recommended, + eslintConfigPrettier, + { + rules: { + '@typescript-eslint/no-explicit-any': 'error', + }, + }, +); diff --git a/fixtures/baseline/NORMALIZATION.md b/fixtures/baseline/NORMALIZATION.md new file mode 100644 index 0000000..e54be8f --- /dev/null +++ b/fixtures/baseline/NORMALIZATION.md @@ -0,0 +1,57 @@ +# Baseline normalization rules + +The baseline capture (`npm run capture-baseline`) must be idempotent: two +consecutive runs against the same production state produce byte-identical +fixture files. Volatile values produced from `new Date()` at runtime are +replaced with the token `{{NOW}}`. This module (`scripts/normalize.ts`) is +the single source of truth for the rules; the synthesis tests (#6) reuse it. + +## Rules + +### Rule 1: runtime-now ISO datetimes + +Any substring matching `YYYY-MM-DDT{HH}:{MM}(:{SS})?(.fff)?(Z|±HH:MM)?` +whose date part equals the capture date is replaced with `{{NOW}}`. + +Why: pages that default a date to "now" when no real date exists (the search +page's `dateModified`, bill details with missing dates) render the wall-clock +instant of the capturing browser, e.g. `2026-11-23T14:03:22.481Z`. + +### Rule 2: runtime-now bare dates + +Any bare `YYYY-MM-DD` string equal to the capture date is replaced with +`{{NOW}}`. + +Why: some fields are rendered as date-only defaults of "now". + +### Rule 3: attribute-less metas + +Meta tags without attributes, e.g. `<meta charset="utf-8">`, are captured +with `name`, `property`, and `content` keys set to `null`. Extraction always +records `name`, `property`, and `content` for every meta, using `null` when +the attribute is absent. + +## Known non-volatile dates + +Dates that happen to equal the capture date but come from real data (e.g. a +sitemap `lastmod` of today, or a bill genuinely modified today) are +indistinguishable from runtime-now values and are also tokenized. This is the +accepted trade-off of content-based detection; the fixture's `sitemap.lastmod` +metadata keeps the original value. + +## What is NOT normalized + +- Everything else must be byte-stable across runs: titles, descriptions, + canonicals, robots directives, OG/Twitter metas, all other JSON-LD fields. +- The search page keyword list ends in `", "` with no active query; if a + future capture embeds a query term, that is a production change and goes + through a `baseline: recapture` PR, not a normalization rule. +- Capture metadata (`capturedAt` uses date-only resolution, `sourceSha`, + `sitemap`) is stable within a capture day and never tokenized. + +## Settle-wait + +Instability from timing (not content) is handled by the capture harness, not +normalization: after `networkidle`, the head is polled every 250 ms until its +fingerprint is unchanged for 5 consecutive polls (20 s cap); a route that +never settles fails the run instead of writing a fixture. diff --git a/fixtures/baseline/account-login.json b/fixtures/baseline/account-login.json new file mode 100644 index 0000000..1415dd0 --- /dev/null +++ b/fixtures/baseline/account-login.json @@ -0,0 +1,190 @@ +{ + "route": "/account/login", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": null, + "httpStatus": 200, + "head": { + "title": "Login | Login | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "robots", + "property": null, + "content": "noindex, nofollow" + }, + { + "name": null, + "property": "og:title", + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": "twitter:description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/account/login" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/account/login" + } + ], + "canonical": "https://billgrokker.com/account/login", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/account-signup.json b/fixtures/baseline/account-signup.json new file mode 100644 index 0000000..94e8137 --- /dev/null +++ b/fixtures/baseline/account-signup.json @@ -0,0 +1,190 @@ +{ + "route": "/account/signup", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": null, + "httpStatus": 200, + "head": { + "title": "Register for an Account | Register for an Account | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "robots", + "property": null, + "content": "noindex, nofollow" + }, + { + "name": null, + "property": "og:title", + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": "twitter:description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/account/signup" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/account/signup" + } + ], + "canonical": "https://billgrokker.com/account/signup", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/bill-119-hr-1.json b/fixtures/baseline/bill-119-hr-1.json new file mode 100644 index 0000000..c5ae27c --- /dev/null +++ b/fixtures/baseline/bill-119-hr-1.json @@ -0,0 +1,301 @@ +{ + "route": "/bills/119/hr/1", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2025-07-04", + "changefreq": "never", + "priority": "0.8" + }, + "httpStatus": 200, + "head": { + "title": "HR. 1 (119th) - An act to provide for reconc... | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Analysis and summary of HR. 1 (119th): An act to provide for reconciliation pursuant .... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": "keywords", + "property": null, + "content": "bills, legislation, congress, government, politics, hr1" + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "HR. 1 (119th) - An act to provide for reconc..." + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "article" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Analysis and summary of HR. 1 (119th): An act to provide for reconciliation pursuant .... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "bills, legislation, congress, government, politics, hr1" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "HR. 1 (119th) - An act to provide for reconc..." + }, + { + "name": "twitter:description", + "property": null, + "content": "Analysis and summary of HR. 1 (119th): An act to provide for reconciliation pursuant .... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/bills/119/hr/1" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/bills/119/hr/1" + } + ], + "canonical": "https://billgrokker.com/bills/119/hr/1", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + }, + { + "@id": "https://billgrokker.com/bills/119/hr/1#webpage", + "@type": "WebPage", + "url": "https://billgrokker.com/bills/119/hr/1", + "inLanguage": "en-US", + "name": "HR. 1 (119th) - An act to provide for reconc...", + "description": "Analysis and summary of HR. 1 (119th): An act to provide for reconciliation pursuant .... AI-powered plain-English breakdown and analysis on Bill Grokker.", + "isPartOf": { + "@id": "https://billgrokker.com/#webapplication" + }, + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "primaryImageOfPage": { + "@id": "https://billgrokker.com/#logo" + }, + "datePublished": "2025-05-20T00:00:00+00:00", + "dateModified": "2025-07-04T00:00:00+00:00", + "breadcrumb": { + "@id": "https://billgrokker.com/bills/119/hr/1#breadcrumb" + } + }, + { + "@id": "https://billgrokker.com/bills/119/hr/1#breadcrumb", + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": [ + { + "@type": "ListItem", + "position": 1, + "item": { + "@id": "https://billgrokker.com/", + "@type": "Thing", + "name": "Home" + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "https://billgrokker.com/bills/search", + "@type": "Thing", + "name": "Search Bills" + } + }, + { + "@type": "ListItem", + "position": 3, + "item": { + "@id": "https://billgrokker.com/bills/119/search", + "@type": "Thing", + "name": "119th Congress" + } + }, + { + "@type": "ListItem", + "position": 4, + "item": { + "@id": "https://billgrokker.com/bills/119/hr/1", + "@type": "Thing", + "name": "HR. 1 (119th)" + } + } + ] + }, + { + "@id": "https://billgrokker.com/bills/119/hr/1#article", + "@type": "Article", + "name": "HR. 1 (119th) - An act to provide for reconc...", + "headline": "HR. 1 (119th) - An act to provide for reconc...", + "description": "Analysis and summary of HR. 1 (119th): An act to provide for reconciliation pursuant .... AI-powered plain-English breakdown and analysis on Bill Grokker.", + "url": "https://billgrokker.com/bills/119/hr/1", + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "author": { + "@id": "https://billgrokker.com/#organization" + }, + "publisher": { + "@id": "https://billgrokker.com/#organization" + }, + "about": { + "@type": "Thing", + "name": "Economics and Public Finance" + }, + "articleSection": "Economics and Public Finance", + "mainEntityOfPage": { + "@type": "WebPage", + "@id": "https://billgrokker.com/bills/119/hr/1#webpage" + }, + "datePublished": "2025-05-20T00:00:00+00:00", + "dateModified": "2025-07-04T00:00:00+00:00", + "keywords": "bills, legislation, congress, government, politics, hr1" + } + ] + } + ] + }, + "bill": { + "title": "HR. 1 (119th) - An act to provide for reconc...", + "dates": { + "datePublished": "2025-05-20T00:00:00+00:00", + "dateModified": "2025-07-04T00:00:00+00:00" + }, + "policyArea": "Economics and Public Finance", + "breadcrumbs": [ + "Home", + "Search Bills", + "119th Congress", + "HR. 1 (119th)" + ] + } +} diff --git a/fixtures/baseline/bill-119-s-5653.json b/fixtures/baseline/bill-119-s-5653.json new file mode 100644 index 0000000..e6803b8 --- /dev/null +++ b/fixtures/baseline/bill-119-s-5653.json @@ -0,0 +1,301 @@ +{ + "route": "/bills/119/s/5653", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2026-11-23", + "changefreq": "daily", + "priority": "0.8" + }, + "httpStatus": 200, + "head": { + "title": "S. 5653 (119th) - Bipartisan American Afford... | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Analysis and summary of S. 5653 (119th): Bipartisan American Affordability and Jobs A.... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": "keywords", + "property": null, + "content": "bills, legislation, congress, government, politics, s5653" + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "S. 5653 (119th) - Bipartisan American Afford..." + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "article" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Analysis and summary of S. 5653 (119th): Bipartisan American Affordability and Jobs A.... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "bills, legislation, congress, government, politics, s5653" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "S. 5653 (119th) - Bipartisan American Afford..." + }, + { + "name": "twitter:description", + "property": null, + "content": "Analysis and summary of S. 5653 (119th): Bipartisan American Affordability and Jobs A.... AI-powered plain-English breakdown and analysis on Bill Grokker." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/bills/119/s/5653" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/bills/119/s/5653" + } + ], + "canonical": "https://billgrokker.com/bills/119/s/5653", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + }, + { + "@id": "https://billgrokker.com/bills/119/s/5653#webpage", + "@type": "WebPage", + "url": "https://billgrokker.com/bills/119/s/5653", + "inLanguage": "en-US", + "name": "S. 5653 (119th) - Bipartisan American Afford...", + "description": "Analysis and summary of S. 5653 (119th): Bipartisan American Affordability and Jobs A.... AI-powered plain-English breakdown and analysis on Bill Grokker.", + "isPartOf": { + "@id": "https://billgrokker.com/#webapplication" + }, + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "primaryImageOfPage": { + "@id": "https://billgrokker.com/#logo" + }, + "datePublished": "2026-09-30T00:00:00+00:00", + "dateModified": "2026-09-30T00:00:00+00:00", + "breadcrumb": { + "@id": "https://billgrokker.com/bills/119/s/5653#breadcrumb" + } + }, + { + "@id": "https://billgrokker.com/bills/119/s/5653#breadcrumb", + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": [ + { + "@type": "ListItem", + "position": 1, + "item": { + "@id": "https://billgrokker.com/", + "@type": "Thing", + "name": "Home" + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "https://billgrokker.com/bills/search", + "@type": "Thing", + "name": "Search Bills" + } + }, + { + "@type": "ListItem", + "position": 3, + "item": { + "@id": "https://billgrokker.com/bills/119/search", + "@type": "Thing", + "name": "119th Congress" + } + }, + { + "@type": "ListItem", + "position": 4, + "item": { + "@id": "https://billgrokker.com/bills/119/s/5653", + "@type": "Thing", + "name": "S. 5653 (119th)" + } + } + ] + }, + { + "@id": "https://billgrokker.com/bills/119/s/5653#article", + "@type": "Article", + "name": "S. 5653 (119th) - Bipartisan American Afford...", + "headline": "S. 5653 (119th) - Bipartisan American Afford...", + "description": "Analysis and summary of S. 5653 (119th): Bipartisan American Affordability and Jobs A.... AI-powered plain-English breakdown and analysis on Bill Grokker.", + "url": "https://billgrokker.com/bills/119/s/5653", + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "author": { + "@id": "https://billgrokker.com/#organization" + }, + "publisher": { + "@id": "https://billgrokker.com/#organization" + }, + "about": { + "@type": "Thing", + "name": "Environmental Protection" + }, + "articleSection": "Environmental Protection", + "mainEntityOfPage": { + "@type": "WebPage", + "@id": "https://billgrokker.com/bills/119/s/5653#webpage" + }, + "datePublished": "2026-09-30T00:00:00+00:00", + "dateModified": "2026-09-30T00:00:00+00:00", + "keywords": "bills, legislation, congress, government, politics, s5653" + } + ] + } + ] + }, + "bill": { + "title": "S. 5653 (119th) - Bipartisan American Afford...", + "dates": { + "datePublished": "2026-09-30T00:00:00+00:00", + "dateModified": "2026-09-30T00:00:00+00:00" + }, + "policyArea": "Environmental Protection", + "breadcrumbs": [ + "Home", + "Search Bills", + "119th Congress", + "S. 5653 (119th)" + ] + } +} diff --git a/fixtures/baseline/bills-search.json b/fixtures/baseline/bills-search.json new file mode 100644 index 0000000..ca4050d --- /dev/null +++ b/fixtures/baseline/bills-search.json @@ -0,0 +1,241 @@ +{ + "route": "/bills/search", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2026-04-09", + "changefreq": "daily", + "priority": "0.9" + }, + "httpStatus": 200, + "head": { + "title": "Search Bills | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Legislation bills related to a search term." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bills, congress, bill grokker, search legislation, " + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "Search Bills" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Legislation bills related to a search term." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bills, congress, bill grokker, search legislation, " + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "Search Bills" + }, + { + "name": "twitter:description", + "property": null, + "content": "Legislation bills related to a search term." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/bills/search" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/bills/search" + } + ], + "canonical": "https://billgrokker.com/bills/search", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + }, + { + "@id": "https://billgrokker.com/bills/search#webpage", + "@type": "WebPage", + "url": "https://billgrokker.com/bills/search", + "inLanguage": "en-US", + "name": "Search Bills", + "description": "Legislation bills related to a search term.", + "isPartOf": { + "@id": "https://billgrokker.com/#webapplication" + }, + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "primaryImageOfPage": { + "@id": "https://billgrokker.com/#logo" + }, + "datePublished": "2025-08-01T00:00:00+00:00", + "dateModified": "{{NOW}}", + "breadcrumb": { + "@id": "https://billgrokker.com/bills/search#breadcrumb" + } + }, + { + "@id": "https://billgrokker.com/bills/search#breadcrumb", + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": [ + { + "@type": "ListItem", + "position": 1, + "item": { + "@id": "https://billgrokker.com/", + "@type": "Thing", + "name": "Home" + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "https://billgrokker.com/bills/search", + "@type": "Thing", + "name": "Search Bills" + } + } + ] + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/faq-companion-bills.json b/fixtures/baseline/faq-companion-bills.json new file mode 100644 index 0000000..67dc573 --- /dev/null +++ b/fixtures/baseline/faq-companion-bills.json @@ -0,0 +1,259 @@ +{ + "route": "/faq/companion-bills", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2026-08-15", + "changefreq": "monthly", + "priority": "0.7" + }, + "httpStatus": 200, + "head": { + "title": "Companion Bills Explained | Frequently Asked Questions | Companion Bills Explained | Frequently Asked Questions | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Companion bills are identical or nearly identical bills introduced in both the House and Senate simultaneously to accelerate the legislative process." + }, + { + "name": "keywords", + "property": null, + "content": "companion bills, legislation, congress, house, senate, bicameral, bill duplication" + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "Companion Bills Explained" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "article" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Companion bills are identical or nearly identical bills introduced in both the House and Senate simultaneously to accelerate the legislative process." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "companion bills, legislation, congress, house, senate, bicameral, bill duplication" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "Companion Bills Explained" + }, + { + "name": "twitter:description", + "property": null, + "content": "Companion bills are identical or nearly identical bills introduced in both the House and Senate simultaneously to accelerate the legislative process." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/faq/companion-bills" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/faq/companion-bills" + } + ], + "canonical": "https://billgrokker.com/faq/companion-bills", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + }, + { + "@id": "https://billgrokker.com/faq/companion-bills#webpage", + "@type": "WebPage", + "url": "https://billgrokker.com/faq/companion-bills", + "inLanguage": "en-US", + "name": "Companion Bills Explained", + "description": "Companion bills are identical or nearly identical bills introduced in both the House and Senate simultaneously to accelerate the legislative process.", + "isPartOf": { + "@id": "https://billgrokker.com/#webapplication" + }, + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "primaryImageOfPage": { + "@id": "https://billgrokker.com/#logo" + }, + "datePublished": "2025-07-25T00:00:00+00:00", + "dateModified": "2025-07-25T00:00:00+00:00", + "breadcrumb": { + "@id": "https://billgrokker.com/faq/companion-bills#breadcrumb" + }, + "mainEntity": { + "@type": "Question", + "name": "Why are bills duplicated sometimes?", + "acceptedAnswer": { + "@type": "Answer", + "text": "Bills often appear in duplicate because of a deliberate legislative tactic called companion bills — identical or nearly identical legislation introduced simultaneously in both the House and the Senate. This strategy allows both chambers to work on the same policy in parallel, dramatically shortening the time it takes to reach a floor vote.", + "url": "https://billgrokker.com/faq#why-are-bills-duplicated" + } + } + }, + { + "@id": "https://billgrokker.com/faq/companion-bills#breadcrumb", + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": [ + { + "@type": "ListItem", + "position": 1, + "item": { + "@id": "https://billgrokker.com/", + "@type": "Thing", + "name": "Home" + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "https://billgrokker.com/faq/", + "@type": "Thing", + "name": "FAQ" + } + }, + { + "@type": "ListItem", + "position": 3, + "item": { + "@id": "https://billgrokker.com/faq/companion-bills", + "@type": "Thing", + "name": "Companion Bills" + } + } + ] + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/faq.json b/fixtures/baseline/faq.json new file mode 100644 index 0000000..7c764a6 --- /dev/null +++ b/fixtures/baseline/faq.json @@ -0,0 +1,368 @@ +{ + "route": "/faq", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2026-08-15", + "changefreq": "monthly", + "priority": "0.7" + }, + "httpStatus": 200, + "head": { + "title": "FAQ | Frequently Asked Questions | FAQ | Frequently Asked Questions | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Frequently asked questions about Bill Grokker and how it works." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bills, congress, bill grokker, frequent questions, common questions, explanation" + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "Frequently Asked Questions" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Frequently asked questions about Bill Grokker and how it works." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bills, congress, bill grokker, frequent questions, common questions, explanation" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "Frequently Asked Questions" + }, + { + "name": "twitter:description", + "property": null, + "content": "Frequently asked questions about Bill Grokker and how it works." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/faq/index" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/faq/index" + } + ], + "canonical": "https://billgrokker.com/faq/index", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + }, + { + "@id": "https://billgrokker.com/faq#webpage", + "@type": "WebPage", + "url": "https://billgrokker.com/faq/index", + "inLanguage": "en-US", + "name": "Frequently Asked Questions", + "description": "Frequently asked questions about Bill Grokker and how it works.", + "isPartOf": { + "@id": "https://billgrokker.com/#webapplication" + }, + "image": { + "@id": "https://billgrokker.com/#logo" + }, + "primaryImageOfPage": { + "@id": "https://billgrokker.com/#logo" + }, + "datePublished": "2025-08-01T00:00:00+00:00", + "dateModified": "2025-08-05T00:00:00+00:00", + "breadcrumb": { + "@id": "https://billgrokker.com/faq#breadcrumb" + } + }, + { + "@id": "https://billgrokker.com/faq#breadcrumb", + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": [ + { + "@type": "ListItem", + "position": 1, + "item": { + "@id": "https://billgrokker.com/", + "@type": "Thing", + "name": "Home" + } + }, + { + "@type": "ListItem", + "position": 2, + "item": { + "@id": "https://billgrokker.com/faq/", + "@type": "Thing", + "name": "FAQ" + } + } + ] + }, + { + "@id": "https://billgrokker.com/faq#faqpage", + "@type": "FAQPage", + "mainEntity": [ + { + "@type": "Question", + "name": "What is Bill Grokker and how does it help in understanding legislation?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bill Grokker is a smart technology platform designed to simplify complex legislative bills and acts. It provides plain-language summaries, AI-driven analysis, and real-time updates to help users easily understand the nuances of US legislation.", + "url": "https://billgrokker.com/faq#what-is-bill-grokker", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "What does 'grokking' a bill mean on the Bill Grokker platform?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "'Grokking' a bill refers to deeply understanding the content and implications of legislative texts through Bill Grokker's tools. The term 'grok' originates from Robert Heinlein's science fiction, meaning to fully comprehend something intuitively and thoroughly.", + "url": "https://billgrokker.com/faq#what-does-grokking-a", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "What key features does Bill Grokker offer for exploring bills?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bill Grokker offers concise, neutral plain-language summaries, legislative search and navigation by keyword or bill number, current bill status updates, multi-perspective AI analysis, bias scoring, partisan benefit projections, category tagging, a bill chat agent for Q&A, and email alerts for specific bill updates.", + "url": "https://billgrokker.com/faq#what-key-features-does", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "How does Bill Grokker use AI to analyze legislation?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bill Grokker employs AI to generate diverse viewpoint breakdowns of bills, assess bias based on language and intent, predict which political party benefits from the bill, and provide an unbiased chat agent that explains bill text and answers user questions.", + "url": "https://billgrokker.com/faq#how-does-bill-grokker", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "Can I receive updates about specific bills on Bill Grokker?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Yes! Users can subscribe to email alerts for updates on specific bills they are interested in. This ensures you stay informed about any changes or developments related to those legislative acts.", + "url": "https://billgrokker.com/faq#can-i-receive-updates", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "How can I search and navigate through bills using Bill Grokker?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bill Grokker allows users to search bills by keyword, bill number, or topic. Additionally, bills are tagged with categories for easy browsing by interest area, making it straightforward to find relevant legislation quickly.", + "url": "https://billgrokker.com/faq#how-can-i-search", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "Why are legislative bills so long and difficult to read?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Most federal bills are characterized by an unprecedented volume of complex data, often spanning hundreds or even thousands of pages filled with dense legal jargon. This jargon serves as a primary barrier to civic participation, making it nearly impossible for the average citizen to identify hidden clauses or understand the real-world implications of a proposed law. BillGrokker addresses this by providing plain-language summaries that strip away legal complexities to deliver the \"ground truth\" of the legislation. Our platform acts as a high-intelligence hub, using AI to transform sparse government metadata into a comprehensive domain model that highlights the core objectives and sections of a bill in a way that is approachable for non-experts.", + "url": "https://billgrokker.com/faq#why-are-legislative-bills", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "What is the chance that a bill I'm tracking will actually become law?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "The velocity of bill introductions often outpaces the public's capacity to follow them, yet statistically, only about 1.7% of bills typically become law. Because the legislative process is so restrictive, it is critical for users to see the \"Bill Status\" (e.g., introduced, passed House, or signed into law) alongside any summary to assess its current relevance. While our ecosystem focuses on the ideological \"why\" and \"who benefits\" through Partisan Benefit Projections, we integrate real-time data from the Congress.gov API to ensure you are viewing the most current status of any active legislation.", + "url": "https://billgrokker.com/faq#what-is-the-chance", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "How can I tell if my representative's vote actually aligns with my interests?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Traditional data sources like Congress.gov provide raw voting records, but they lack a participatory layer for public sentiment. Through our integrated opencongress.us platform, you can record your own \"Yay\" or \"Nay\" opinion on a bill and use a Comparison Dashboard to see a visual alignment between your representative's official actions and the crowdsourced opinions of the public. Our AI further assists this by predicting whether a bill's impact aligns with specific partisan priorities—such as public sector support versus private-sector efficiency—allowing you to hold elected officials accountable based on data-centric sentiment analysis.", + "url": "https://billgrokker.com/faq#how-can-i-tell", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "Why are bills duplicated sometimes?", + "url": "https://billgrokker.com/faq/companion-bills", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bills often appear in duplicate because of a deliberate legislative tactic called companion bills—identical or nearly identical legislation introduced simultaneously in both the House and the Senate. This strategy allows both chambers to work on the same policy in parallel, dramatically shortening the time it takes to reach a floor vote. Each chamber has its own procedural rules and committee jurisdictions, so sponsors enlist allies across the aisle to shepherd the bill through both bodies concurrently. When the versions differ after committee markup, a conference committee reconciles them into a single enrolled bill. Read more…", + "url": "https://billgrokker.com/faq#why-are-bills-duplicated", + "upvoteCount": 1 + } + } + ] + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/home.json b/fixtures/baseline/home.json new file mode 100644 index 0000000..1933f8f --- /dev/null +++ b/fixtures/baseline/home.json @@ -0,0 +1,194 @@ +{ + "route": "/", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": { + "lastmod": "2026-04-09", + "changefreq": "weekly", + "priority": "1.0" + }, + "httpStatus": 200, + "head": { + "title": "AI-Powered Legislative Summaries | AI-Powered Legislative Summaries | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "robots", + "property": null, + "content": "index, follow" + }, + { + "name": null, + "property": "og:title", + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": "twitter:description", + "property": null, + "content": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/" + } + ], + "canonical": "https://billgrokker.com/", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + } + ] + } + ] + }, + "bill": null +} diff --git a/fixtures/baseline/not-found.json b/fixtures/baseline/not-found.json new file mode 100644 index 0000000..0884898 --- /dev/null +++ b/fixtures/baseline/not-found.json @@ -0,0 +1,200 @@ +{ + "route": "/not-found", + "capturedAt": "2026-11-23", + "sourceSha": "3328df5c202c2a97213d025d2b61bbde60f09755", + "sitemap": null, + "httpStatus": 200, + "head": { + "title": "Not Found | Not Found | Bill Grokker", + "metas": [ + { + "name": null, + "property": null, + "content": null + }, + { + "name": "viewport", + "property": null, + "content": "width=device-width, initial-scale=1" + }, + { + "name": "description", + "property": null, + "content": "The page you requested could not be found." + }, + { + "name": "keywords", + "property": null, + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "robots", + "property": null, + "content": "noindex, nofollow" + }, + { + "name": null, + "property": "og:title", + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": null, + "property": "og:site_name", + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:type", + "content": "website" + }, + { + "name": null, + "property": "og:locale", + "content": "en" + }, + { + "name": null, + "property": "og:description", + "content": "The page you requested could not be found." + }, + { + "name": null, + "property": "og:image", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:logo", + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": null, + "property": "og:image:width", + "content": "300" + }, + { + "name": null, + "property": "og:image:height", + "content": "68" + }, + { + "name": null, + "property": "og:keywords", + "content": "legislation, bill summaries, executive orders, AI analysis, bias scoring, government, policy, law" + }, + { + "name": "twitter:card", + "property": null, + "content": "summary" + }, + { + "name": "twitter:site", + "property": null, + "content": "@BillGrokker" + }, + { + "name": null, + "property": "twitter:domain", + "content": "billgrokker.com" + }, + { + "name": "twitter:title", + "property": null, + "content": "AI-Powered Legislative Summaries | Bill Grokker" + }, + { + "name": "twitter:description", + "property": null, + "content": "The page you requested could not be found." + }, + { + "name": "twitter:image", + "property": null, + "content": "https://billgrokker.com/images/logo-color.png" + }, + { + "name": "mobile-web-app-capable", + "property": null, + "content": "yes" + }, + { + "name": "apple-mobile-web-app-title", + "property": null, + "content": "Bill Grokker" + }, + { + "name": null, + "property": "og:url", + "content": "https://billgrokker.com/not-found" + }, + { + "name": null, + "property": "twitter:url", + "content": "https://billgrokker.com/not-found" + }, + { + "name": "prerender-status-code", + "property": null, + "content": "404" + }, + { + "name": "response-http-status", + "property": null, + "content": "404" + } + ], + "canonical": "https://billgrokker.com/not-found", + "jsonLd": [ + { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "ImageObject", + "@id": "https://billgrokker.com/#logo", + "url": "https://billgrokker.com/images/logo-color.png", + "width": 300, + "height": 68, + "caption": "Bill Grokker" + }, + { + "@type": "Organization", + "@id": "https://billgrokker.com/#organization", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "sameAs": [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker" + ], + "contactPoint": { + "@type": "ContactPoint", + "contactType": "customer service", + "url": "mailto:support@expertvision.software" + } + }, + { + "@type": [ + "WebApplication", + "SoftwareApplication" + ], + "@id": "https://billgrokker.com/#webapplication", + "name": "Bill Grokker", + "url": "https://billgrokker.com", + "operatingSystem": "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD" + }, + "description": "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring.", + "softwareVersion": "1.0.0", + "applicationCategory": "Government" + } + ] + } + ] + }, + "bill": null +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a1d135a --- /dev/null +++ b/package.json @@ -0,0 +1,63 @@ +{ + "name": "@expert-vision-software/programmatic-seo", + "version": "0.1.0", + "description": "Framework-agnostic programmatic SEO engine: declarative page specs, chainable builders, managed JSON-LD @graph, and head rendering.", + "type": "module", + "license": "MIT", + "author": "Expert Vision Software", + "repository": { + "type": "git", + "url": "git+https://github.com/Expert-Vision-Software/programmatic-seo.git" + }, + "bugs": { + "url": "https://github.com/Expert-Vision-Software/programmatic-seo/issues" + }, + "homepage": "https://github.com/Expert-Vision-Software/programmatic-seo#readme", + "keywords": [ + "seo", + "meta-tags", + "json-ld", + "schema.org", + "structured-data", + "open-graph", + "twitter-card", + "typescript", + "framework-agnostic" + ], + "engines": { + "node": ">=22" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, + "files": [ + "dist" + ], + "sideEffects": false, + "scripts": { + "build": "tsc -p tsconfig.build.json", + "test": "vitest run", + "lint": "eslint .", + "typecheck": "tsc --noEmit", + "capture-baseline": "bun scripts/capture-baseline.ts" + }, + "dependencies": { + "schema-dts": "^2.0.0" + }, + "devDependencies": { + "@eslint/js": "^9.39.0", + "@types/jsdom": "^27.0.0", + "@types/node": "^22.0.0", + "eslint": "^9.39.0", + "eslint-config-prettier": "^10.1.8", + "jsdom": "^27.0.0", + "playwright": "^1.65.1", + "prettier": "^3.6.2", + "typescript": "^5.9.3", + "typescript-eslint": "^8.46.0", + "vitest": "^3.2.4" + } +} diff --git a/scripts/capture-baseline.ts b/scripts/capture-baseline.ts new file mode 100644 index 0000000..94704fe --- /dev/null +++ b/scripts/capture-baseline.ts @@ -0,0 +1,179 @@ +import { execFileSync } from "node:child_process"; +import { mkdirSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { chromium, type Page } from "playwright"; +import { fingerprint, normalizeHead, type RawHead } from "./normalize"; + +const ORIGIN = "https://billgrokker.com"; + +interface RouteSpec { + route: string; + slug: string; + bill?: boolean; +} + +const ROUTES: RouteSpec[] = [ + { route: "/", slug: "home" }, + { route: "/bills/search", slug: "bills-search" }, + { route: "/faq", slug: "faq" }, + { route: "/faq/companion-bills", slug: "faq-companion-bills" }, + { route: "/bills/119/hr/1", slug: "bill-119-hr-1", bill: true }, + { route: "/bills/119/s/5653", slug: "bill-119-s-5653", bill: true }, + { route: "/not-found", slug: "not-found" }, + { route: "/account/login", slug: "account-login" }, + { route: "/account/signup", slug: "account-signup" }, +]; + +const SETTLE_POLLS = 5; +const SETTLE_INTERVAL_MS = 250; +const SETTLE_TIMEOUT_MS = 20000; + +async function readHead(page: Page): Promise<RawHead> { + return page.evaluate(() => { + const metaNodes = Array.from(document.head.querySelectorAll("meta")); + return { + title: document.title, + metas: metaNodes.map((m) => ({ + name: m.getAttribute("name"), + property: m.getAttribute("property"), + content: m.getAttribute("content"), + })), + canonical: document.head.querySelector('link[rel="canonical"]')?.getAttribute("href") ?? null, + jsonLd: Array.from(document.head.querySelectorAll('script[type="application/ld+json"]')).map((s) => JSON.parse(s.textContent ?? "null")), + }; + }); +} + +async function captureRoute(browser: Awaited<ReturnType<typeof chromium.launch>>, spec: RouteSpec, today: string) { + const context = await browser.newContext(); + const page = await context.newPage(); + const response = await page.goto(ORIGIN + spec.route, { waitUntil: "networkidle", timeout: 60000 }); + if (!response) throw new Error(`${spec.route}: navigation failed (no response)`); + + const start = Date.now(); + let stableCount = 0; + let head = await readHead(page); + let mark = fingerprint(head); + while (stableCount < SETTLE_POLLS) { + await page.waitForTimeout(SETTLE_INTERVAL_MS); + const next = await readHead(page); + const nextMark = fingerprint(next); + if (nextMark === mark) { + stableCount += 1; + } else { + stableCount = 0; + head = next; + mark = nextMark; + } + if (Date.now() - start > SETTLE_TIMEOUT_MS) { + throw new Error(`${spec.route}: head did not settle within ${SETTLE_TIMEOUT_MS}ms`); + } + } + + const normalized = normalizeHead(head, today); + return { + route: spec.route, + capturedAt: today, + sourceSha: sourceSha(), + sitemap: sitemapIndex[spec.route] ?? null, + httpStatus: response.status(), + head: normalized, + bill: spec.bill ? extractBill(normalized.jsonLd, spec.route) : null, + }; +} + +interface BillContent { + title: string; + dates: { datePublished: string; dateModified: string }; + policyArea: string; + breadcrumbs: string[]; +} + +function extractBill(jsonLd: Array<unknown>, route: string): BillContent { + const nodes = extractPageNodes(jsonLd); + const article = nodes.find((n) => Array.isArray(n["@type"]) ? n["@type"].includes("Article") : n["@type"] === "Article"); + const breadcrumb = nodes.find((n) => n["@type"] === "BreadcrumbList"); + if (!article || !breadcrumb) throw new Error(`${route}: article or breadcrumb JSON-LD node missing`); + const items = (breadcrumb["itemListElement"] as Array<{ item: { name?: string } }>).map((i) => i.item?.name ?? ""); + return { + title: String(article["name"]), + dates: { + datePublished: String(article["datePublished"]), + dateModified: String(article["dateModified"]), + }, + policyArea: String(article["articleSection"] ?? (article["about"] as { name?: string } | undefined)?.name ?? ""), + breadcrumbs: items, + }; +} + +const SITE_WIDE_ID_SUFFIXES = ["#logo", "#organization", "#webapplication"]; + +interface GraphNode { + "@id"?: string; + "@type"?: string | string[]; + [key: string]: unknown; +} + +function extractPageNodes(jsonLd: Array<unknown>): Array<GraphNode> { + const out: Array<GraphNode> = []; + for (const block of jsonLd) { + const graph = (block as { "@graph"?: Array<GraphNode> })["@graph"]; + if (!graph) continue; + for (const node of graph) { + const id = node["@id"]; + if (id && SITE_WIDE_ID_SUFFIXES.some((s) => String(id).endsWith(s))) continue; + out.push(node); + } + } + return out; +} + +function sourceSha(): string { + return execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim(); +} + +interface SitemapEntry { + lastmod: string; + changefreq: string; + priority: string; +} + +const sitemapIndex: Record<string, SitemapEntry> = {}; + +async function loadSitemap(): Promise<void> { + const res = await fetch(ORIGIN + "/sitemap.xml"); + if (!res.ok) throw new Error(`sitemap fetch failed: ${res.status}`); + const xml = await res.text(); + const urlRe = /<url>([\s\S]*?)<\/url>/g; + const tag = (name: string, block: string): string => + block.match(new RegExp(`<${name}>\\s*([\\s\\S]*?)\\s*</${name}>`))?.[1]?.trim() ?? ""; + for (const match of xml.matchAll(urlRe)) { + const loc = tag("loc", match[1]); + const path = new URL(loc).pathname; + sitemapIndex[path] = { + lastmod: tag("lastmod", match[1]), + changefreq: tag("changefreq", match[1]), + priority: tag("priority", match[1]), + }; + } +} + +async function main(): Promise<void> { + const today = new Date().toISOString().slice(0, 10); + await loadSitemap(); + const browser = await chromium.launch(); + const outDir = join(process.cwd(), "fixtures", "baseline"); + mkdirSync(outDir, { recursive: true }); + for (const spec of ROUTES) { + const record = await captureRoute(browser, spec, today); + const file = join(outDir, `${spec.slug}.json`); + writeFileSync(file, JSON.stringify(record, null, 2) + "\n", "utf8"); + console.log(`captured ${spec.route} -> fixtures/baseline/${spec.slug}.json`); + } + await browser.close(); +} + +main().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/scripts/normalize.ts b/scripts/normalize.ts new file mode 100644 index 0000000..283c578 --- /dev/null +++ b/scripts/normalize.ts @@ -0,0 +1,48 @@ +export const NOW_TOKEN = "{{NOW}}"; + +export interface RawHead { + title: string; + metas: Array<{ name: string | null; property: string | null; content: string | null }>; + canonical: string | null; + jsonLd: Array<unknown>; +} + +const isoDateTimeRe = (day: string): RegExp => + new RegExp(`${day}T\\d{2}:\\d{2}(:\\d{2})?(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?`, "g"); + +const isoDateRe = (day: string): RegExp => + new RegExp(`(?<![\\d-])${day}(?![\\d-])`, "g"); + +export function normalizeString(value: string, today: string): string { + return value.replace(isoDateTimeRe(today), NOW_TOKEN).replace(isoDateRe(today), NOW_TOKEN); +} + +export function normalizeDeep(value: unknown, today: string): unknown { + if (typeof value === "string") return normalizeString(value, today); + if (Array.isArray(value)) return value.map((item) => normalizeDeep(item, today)); + if (value !== null && typeof value === "object") { + const out: Record<string, unknown> = {}; + for (const [key, entry] of Object.entries(value as Record<string, unknown>)) { + out[key] = normalizeDeep(entry, today); + } + return out; + } + return value; +} + +export function normalizeHead(head: RawHead, today: string): RawHead { + return { + title: normalizeString(head.title, today), + metas: head.metas.map((meta) => ({ + name: meta.name, + property: meta.property, + content: meta.content === null ? null : normalizeString(meta.content, today), + })), + canonical: head.canonical === null ? null : normalizeString(head.canonical, today), + jsonLd: head.jsonLd.map((block) => normalizeDeep(block, today)), + }; +} + +export function fingerprint(value: unknown): string { + return JSON.stringify(value); +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..05c43e4 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,17 @@ +export type { + AppendableList, + ArticleSpec, + BreadcrumbItem, + FaqPageSpec, + ISeoPage, + TwitterSpec, + WebPageSpec, +} from "./seo-page.js"; +export type {DateOnly, SeoDateInput} from "./seo-specs.js"; +export {normalizeSeoDate} from "./seo-specs.js"; +export type {GraphDocument, JsonLdScript, SeoConfig} from "./models/seo-config.js"; +export {HtmlSeoConfigParser} from "./models/seo-config.js"; +export type {ISeoBuilderTarget, IPageBuilder} from "./seo-page-builder.js"; +export {ContentPageBuilder, SeoPageBuilder, createBuilder} from "./seo-page-builder.js"; +export type {ISitewideBuilder, SeoLogger, SeoServiceConfig} from "./seo-service.js"; +export {SeoService} from "./seo-service.js"; diff --git a/src/models/seo-config.ts b/src/models/seo-config.ts new file mode 100644 index 0000000..864c7eb --- /dev/null +++ b/src/models/seo-config.ts @@ -0,0 +1,125 @@ +import type {JsonLdObject} from "schema-dts"; + +function getMetaContent(name: string): string { + let element = document.querySelector(`meta[name="${name}"]`) as HTMLMetaElement | null; + + if (!element) { + element = document.querySelector(`meta[property="${name}"]`) as HTMLMetaElement | null; + } + + return element?.content || ''; +} + +function getKeywords(): string[] { + const keywordsMeta = document.querySelector('meta[name="keywords"]') as HTMLMetaElement | null; + if (!keywordsMeta?.content) return []; + + return keywordsMeta.content + .split(',') + .map(k => k.trim()) + .filter(Boolean); +} + +export type GraphDocument = { + "@context": string | string[] | Record<string, unknown>; + "@graph": JsonLdObject[]; +}; + +function getGraphNodes(selectorParam: string | HTMLScriptElement): JsonLdObject[] | null { + const script = typeof selectorParam === 'string' + ? document.querySelector(`script[data-id="${selectorParam}"]`) as HTMLScriptElement | null + : selectorParam; + + if (!script?.textContent) return null; + + try { + const doc = JSON.parse(script.textContent) as GraphDocument; + return Array.isArray(doc["@graph"]) ? doc["@graph"] : null; + } catch (e) { + console.error('Failed to parse JSON-LD graph', e); + return null; + } +} + +export type JsonLdScript = { + id: string; + data: JsonLdObject; +} + +export type SeoConfig = { + title: string; + description: string; + keywords: string[]; + siteName: string; + locale: string; + robots: string; + pageUrl: string; + logoUrl: string; + og: { type: string; imageUrl: string; imageWidth: number; imageHeight: number }; + twitter: { cardType: "summary" | "summary_large_image" | "app" | "player"; handleId: string; domain: string }; + jsonLd?: JsonLdScript[] | JsonLdScript | undefined; +}; + +export function HtmlSeoConfigParser(rootDomain: string, graphScriptDomId?: string): SeoConfig { + + const pageTitle = document.title || ''; + + const description = getMetaContent('description'); + const keywords = getKeywords(); + const robots = getMetaContent('robots') || 'index, follow'; + + const ogSiteName = getMetaContent('og:site_name'); + const ogType = getMetaContent('og:type'); + const ogUrl = getMetaContent('og:url'); + const ogLocale = document.documentElement.lang || "en"; + const ogLogo = getMetaContent('og:logo'); + const ogImageWidth = parseInt(getMetaContent('og:image:width')); + const ogImageHeight = parseInt(getMetaContent('og:image:height')); + + const twitterCardType = getMetaContent('twitter:card') as 'summary' | 'summary_large_image' | 'app' | 'player'; + const twitterHandleId = getMetaContent('twitter:site'); + const twitterDomain = rootDomain; + + let jsonLd: JsonLdScript[] | JsonLdScript | null = null; + const graphScriptId = graphScriptDomId ?? `https://${rootDomain}/#graph`; + const graphScript = document.querySelector(`script[data-id="${graphScriptId}"][type="application/ld+json"]`) as HTMLScriptElement | null; + if (graphScript) { + const nodes = getGraphNodes(graphScript); + if (nodes && nodes.length > 0) { + const items: JsonLdScript[] = nodes + .filter(node => typeof node?.["@id"] === 'string') + .map(node => ({id: node["@id"] as string, data: node})); + if (items.length === 1) { + jsonLd = items[0] ?? null; + } else if (items.length > 1) { + jsonLd = items; + } + } + } + + return { + title: pageTitle, + description: description, + keywords: keywords, + siteName: ogSiteName, + locale: ogLocale, + robots: robots, + pageUrl: ogUrl, + logoUrl: ogLogo, + + og: { + type: ogType, + imageUrl: ogLogo, + imageWidth: ogImageWidth, + imageHeight: ogImageHeight + }, + + twitter: { + cardType: twitterCardType, + handleId: twitterHandleId, + domain: twitterDomain + }, + + jsonLd: jsonLd ?? undefined + }; +} diff --git a/src/seo-page-builder.ts b/src/seo-page-builder.ts new file mode 100644 index 0000000..8dfecfa --- /dev/null +++ b/src/seo-page-builder.ts @@ -0,0 +1,512 @@ +import type {Thing} from "schema-dts"; +import type {BreadcrumbItem, FaqPageSpec, ISeoPage, TwitterSpec, WebPageSpec, ArticleSpec} from "./seo-page.js"; +import {normalizeSeoDate} from "./seo-specs.js"; +import type {SeoDateInput} from "./seo-specs.js"; + +export interface ISeoBuilderTarget { + readonly rootUrl: string; + emit(seoPage: ISeoPage): void; +} + +export interface IPageBuilder { + setTitle(title: string): IPageBuilder; + setDescription(description: string): IPageBuilder; + setUrl(url: string): IPageBuilder; + setCanonicalPath(path: string): IPageBuilder; + setOgType(type: "article" | "website"): IPageBuilder; + setImage(image: string): IPageBuilder; + setKeywords(...keywords: (string | string[])[]): IPageBuilder; + appendKeywords(...keywords: (string | string[])[]): IPageBuilder; + setBreadcrumbs(items: readonly BreadcrumbItem[]): IPageBuilder; + appendBreadcrumbs(items: readonly BreadcrumbItem[]): IPageBuilder; + setNoIndex(): IPageBuilder; + setStatusCode(code: number): IPageBuilder; + setResponseHttpStatus(code: number): IPageBuilder; + setTwitter(options: TwitterSpec): IPageBuilder; + setWebPage(spec: { + canonicalPath?: string; + name?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + breadcrumb?: boolean; + mainEntity?: Thing | Thing[]; + }): IPageBuilder; + setArticle(spec: { + canonicalPath?: string; + name?: string; + headline?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + about?: Thing; + articleSection?: string; + keywords?: string; + }): IPageBuilder; + setFaqPage(spec: FaqPageSpec): IPageBuilder; + contentPage(): ContentPageBuilder; + emit(): void; + build(): ISeoPage; +} + +interface WebPageInputState { + canonicalPath?: string; + name?: string; + description?: string; + datePublished?: string; + dateModified?: string; + breadcrumb?: boolean; + mainEntity?: Thing | Thing[]; +} + +interface ArticleInputState { + canonicalPath?: string; + name?: string; + headline?: string; + description?: string; + datePublished?: string; + dateModified?: string; + about?: Thing; + articleSection?: string; + keywords?: string; +} + +interface BuilderState { + title?: string; + description?: string; + url?: string; + canonicalPath?: string; + ogType?: "article" | "website"; + image?: string; + keywords?: string[]; + breadcrumbs?: BreadcrumbItem[]; + noIndex?: boolean; + statusCode?: number; + responseHttpStatus?: number; + twitter?: TwitterSpec; + webPage?: WebPageInputState; + article?: ArticleInputState; + faqPage?: FaqPageSpec; +} + +export class ContentPageBuilder { + private readonly _parent: SeoPageBuilder; + private readonly _state: BuilderState; + + constructor(parent: SeoPageBuilder, state: BuilderState) { + this._parent = parent; + this._state = state; + } + + public setDates(dates: {published?: SeoDateInput; modified?: SeoDateInput}): ContentPageBuilder { + if (dates.published !== undefined) { + this._ensureWebPage().datePublished = normalizeSeoDate(dates.published); + this._ensureArticle().datePublished = normalizeSeoDate(dates.published); + } + if (dates.modified !== undefined) { + this._ensureWebPage().dateModified = normalizeSeoDate(dates.modified); + this._ensureArticle().dateModified = normalizeSeoDate(dates.modified); + } + return this; + } + + public setAbout(about: string | Thing): ContentPageBuilder { + const article = this._ensureArticle(); + if (typeof about === "string") { + article.about = {"@type": "Thing", "name": about} as Thing; + article.articleSection = about; + } else { + article.about = about; + } + return this; + } + + public setSection(section: string): ContentPageBuilder { + this._ensureArticle().articleSection = section; + return this; + } + + public setQuestion(question: { + name: string; + answerText: string; + answerUrl?: string; + }): ContentPageBuilder { + const resolvedUrl = question.answerUrl; + const answer: Record<string, unknown> = { + "@type": "Answer", + "text": question.answerText, + }; + if (resolvedUrl) { + answer["url"] = resolvedUrl; + } + this._ensureWebPage().mainEntity = { + "@type": "Question", + "name": question.name, + "acceptedAnswer": answer, + } as unknown as Thing; + return this; + } + + public setTitle(title: string): ContentPageBuilder { + this._parent.setTitle(title); + return this; + } + + public setDescription(description: string): ContentPageBuilder { + this._parent.setDescription(description); + return this; + } + + public setUrl(url: string): ContentPageBuilder { + this._parent.setUrl(url); + return this; + } + + public setCanonicalPath(path: string): ContentPageBuilder { + this._parent.setCanonicalPath(path); + return this; + } + + public setOgType(type: "article" | "website"): ContentPageBuilder { + this._parent.setOgType(type); + return this; + } + + public setImage(image: string): ContentPageBuilder { + this._parent.setImage(image); + return this; + } + + public setKeywords(...keywords: (string | string[])[]): ContentPageBuilder { + this._parent.setKeywords(...keywords); + return this; + } + + public appendKeywords(...keywords: (string | string[])[]): ContentPageBuilder { + this._parent.appendKeywords(...keywords); + return this; + } + + public setBreadcrumbs(items: readonly BreadcrumbItem[]): ContentPageBuilder { + this._parent.setBreadcrumbs(items); + return this; + } + + public appendBreadcrumbs(items: readonly BreadcrumbItem[]): ContentPageBuilder { + this._parent.appendBreadcrumbs(items); + return this; + } + + public setNoIndex(): ContentPageBuilder { + this._parent.setNoIndex(); + return this; + } + + public setStatusCode(code: number): ContentPageBuilder { + this._parent.setStatusCode(code); + return this; + } + + public setResponseHttpStatus(code: number): ContentPageBuilder { + this._parent.setResponseHttpStatus(code); + return this; + } + + public setTwitter(options: TwitterSpec): ContentPageBuilder { + this._parent.setTwitter(options); + return this; + } + + public setWebPage(spec: { + canonicalPath?: string; + name?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + breadcrumb?: boolean; + mainEntity?: Thing | Thing[]; + }): ContentPageBuilder { + this._parent.setWebPage(spec); + return this; + } + + public setArticle(spec: { + canonicalPath?: string; + name?: string; + headline?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + about?: Thing; + articleSection?: string; + keywords?: string; + }): ContentPageBuilder { + this._parent.setArticle(spec); + return this; + } + + public setFaqPage(spec: FaqPageSpec): ContentPageBuilder { + this._parent.setFaqPage(spec); + return this; + } + + public emit(): void { + this._parent.emit(); + } + + public build(): ISeoPage { + return this._parent.build(); + } + + public end(): SeoPageBuilder { + return this._parent; + } + + private _ensureWebPage(): WebPageInputState { + if (!this._state.webPage) { + this._state.webPage = {}; + } + return this._state.webPage; + } + + private _ensureArticle(): ArticleInputState { + if (!this._state.article) { + this._state.article = {}; + } + return this._state.article; + } +} + +export class SeoPageBuilder implements IPageBuilder { + private readonly _state: BuilderState = {}; + private readonly _target: ISeoBuilderTarget; + + constructor(target: ISeoBuilderTarget) { + this._target = target; + } + + public setTitle(title: string): this { + this._state.title = title; + return this; + } + + public setDescription(description: string): this { + this._state.description = description; + return this; + } + + public setUrl(url: string): this { + this._guardUrl(url); + this._state.url = url; + return this; + } + + public setCanonicalPath(path: string): this { + this._guardUrl(path); + this._state.canonicalPath = path; + return this; + } + + public setOgType(type: "article" | "website"): this { + this._state.ogType = type; + return this; + } + + public setImage(image: string): this { + this._state.image = image; + return this; + } + + public setKeywords(...keywords: (string | string[])[]): this { + this._state.keywords = [...new Set([...(this._state.keywords ?? []), ...keywords.flat()])]; + return this; + } + + public appendKeywords(...keywords: (string | string[])[]): this { + return this.setKeywords(...keywords); + } + + public setBreadcrumbs(items: readonly BreadcrumbItem[]): this { + this._state.breadcrumbs = [...items]; + return this; + } + + public appendBreadcrumbs(items: readonly BreadcrumbItem[]): this { + this._state.breadcrumbs = [...(this._state.breadcrumbs ?? []), ...items]; + return this; + } + + public setNoIndex(): this { + this._state.noIndex = true; + return this; + } + + public setStatusCode(code: number): this { + this._state.statusCode = code; + return this; + } + + public setResponseHttpStatus(code: number): this { + this._state.responseHttpStatus = code; + return this; + } + + public setTwitter(options: TwitterSpec): this { + this._state.twitter = options; + return this; + } + + public setWebPage(spec: { + canonicalPath?: string; + name?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + breadcrumb?: boolean; + mainEntity?: Thing | Thing[]; + }): this { + if (spec.canonicalPath) this._guardUrl(spec.canonicalPath); + if (!this._state.webPage) { + this._state.webPage = {}; + } + if (spec.canonicalPath !== undefined) this._state.webPage.canonicalPath = spec.canonicalPath; + if (spec.name !== undefined) this._state.webPage.name = spec.name; + if (spec.description !== undefined) this._state.webPage.description = spec.description; + if (spec.datePublished !== undefined) this._state.webPage.datePublished = normalizeSeoDate(spec.datePublished); + if (spec.dateModified !== undefined) this._state.webPage.dateModified = normalizeSeoDate(spec.dateModified); + if (spec.breadcrumb !== undefined) this._state.webPage.breadcrumb = spec.breadcrumb; + if (spec.mainEntity !== undefined) this._state.webPage.mainEntity = spec.mainEntity; + return this; + } + + public setArticle(spec: { + canonicalPath?: string; + name?: string; + headline?: string; + description?: string; + datePublished?: SeoDateInput; + dateModified?: SeoDateInput; + about?: Thing; + articleSection?: string; + keywords?: string; + }): this { + if (spec.canonicalPath) this._guardUrl(spec.canonicalPath); + if (!this._state.article) { + this._state.article = {}; + } + if (spec.canonicalPath !== undefined) this._state.article.canonicalPath = spec.canonicalPath; + if (spec.name !== undefined) this._state.article.name = spec.name; + if (spec.headline !== undefined) this._state.article.headline = spec.headline; + if (spec.description !== undefined) this._state.article.description = spec.description; + if (spec.datePublished !== undefined) this._state.article.datePublished = normalizeSeoDate(spec.datePublished); + if (spec.dateModified !== undefined) this._state.article.dateModified = normalizeSeoDate(spec.dateModified); + if (spec.about !== undefined) this._state.article.about = spec.about; + if (spec.articleSection !== undefined) this._state.article.articleSection = spec.articleSection; + if (spec.keywords !== undefined) this._state.article.keywords = spec.keywords; + return this; + } + + public setFaqPage(spec: FaqPageSpec): this { + if (spec.canonicalPath) this._guardUrl(spec.canonicalPath); + this._state.faqPage = spec; + return this; + } + + public contentPage(): ContentPageBuilder { + if (!this._state.webPage) { + this._state.webPage = {breadcrumb: true}; + } + if (!this._state.article) { + this._state.article = {}; + } + this._state.ogType = "article"; + return new ContentPageBuilder(this, this._state); + } + + public emit(): void { + this._target.emit(this.build()); + } + + public build(): ISeoPage { + const s = this._state; + const effectiveUrl = s.url; + const effectiveCanonicalPath = s.canonicalPath + ?? (effectiveUrl && !/^https?:\/\//i.test(effectiveUrl) ? effectiveUrl : undefined) + ?? (s.webPage?.canonicalPath) + ?? (s.article?.canonicalPath); + + let webPageSpec: WebPageSpec | undefined; + const webPageCp = effectiveCanonicalPath ?? effectiveUrl; + if (webPageCp || (s.webPage && (s.webPage.breadcrumb !== undefined || s.webPage.mainEntity !== undefined || s.webPage.datePublished !== undefined || s.webPage.dateModified !== undefined))) { + const s2 = s.webPage ?? {}; + webPageSpec = { + canonicalPath: s2.canonicalPath ?? webPageCp ?? "", + name: s2.name ?? s.title, + description: s2.description ?? s.description ?? "", + datePublished: s2.datePublished ?? "", + dateModified: s2.dateModified ?? "", + breadcrumb: s2.breadcrumb, + mainEntity: s2.mainEntity, + }; + } + + let articleSpec: ArticleSpec | undefined; + if (s.article !== undefined) { + const articleCp = effectiveCanonicalPath ?? effectiveUrl; + const s2 = s.article; + const articleKeywords = s2.keywords ?? (s.keywords ? s.keywords.join(", ") : undefined); + articleSpec = { + canonicalPath: s2.canonicalPath ?? articleCp ?? "", + name: s2.name ?? s.title, + headline: s2.headline ?? s.title, + description: s2.description ?? s.description ?? "", + datePublished: s2.datePublished ?? "", + dateModified: s2.dateModified ?? "", + about: s2.about, + articleSection: s2.articleSection, + keywords: articleKeywords, + }; + } + + const spec: ISeoPage = {}; + if (s.title !== undefined) spec.title = s.title; + if (s.description !== undefined) spec.description = s.description; + if (effectiveUrl !== undefined) spec.url = effectiveUrl; + if (s.canonicalPath !== undefined) { + spec.canonicalPath = s.canonicalPath; + } + if (s.ogType !== undefined) spec.ogType = s.ogType; + if (s.image !== undefined) spec.image = s.image; + if (s.keywords !== undefined) spec.keywords = s.keywords; + if (s.breadcrumbs !== undefined) spec.breadcrumbs = s.breadcrumbs; + if (s.noIndex !== undefined) spec.noIndex = s.noIndex; + if (s.statusCode !== undefined) spec.statusCode = s.statusCode; + if (s.responseHttpStatus !== undefined) spec.responseHttpStatus = s.responseHttpStatus; + if (s.twitter !== undefined) spec.twitter = s.twitter; + if (webPageSpec !== undefined) spec.webPage = webPageSpec as WebPageSpec; + if (articleSpec !== undefined) spec.article = articleSpec as ArticleSpec; + if (s.faqPage !== undefined) spec.faqPage = s.faqPage; + return spec; + } + + private _guardUrl(pathOrUrl: string): void { + if (/^https?:\/\//i.test(pathOrUrl)) { + try { + const origin = new URL(pathOrUrl).origin; + const rootOrigin = new URL(this._target.rootUrl).origin; + if (origin === rootOrigin) { + throw new Error( + `Use relative url when referring to same website. If you mean to set to another site's root url, it cannot match the value of '${this._target.rootUrl}'.` + ); + } + } catch (e) { + if (e instanceof TypeError) return; + throw e; + } + } + } +} + +export function createBuilder(target: ISeoBuilderTarget): IPageBuilder { + return new SeoPageBuilder(target); +} diff --git a/src/seo-page.ts b/src/seo-page.ts new file mode 100644 index 0000000..60e3935 --- /dev/null +++ b/src/seo-page.ts @@ -0,0 +1,153 @@ +import type {Thing, Question} from "schema-dts"; + +/** + * A single entry in a `BreadcrumbItem[]` breadcrumb list. The service renders these as + * schema.org `ListItem` entries inside a `BreadcrumbList` JSON-LD node, and the URL is + * resolved against the configured root. + */ +export interface BreadcrumbItem { + /** Human-readable label for the breadcrumb step. Used as the `name` on the rendered `ListItem`. */ + name: string; + /** Absolute or root-relative path the step points to. Resolved against the site's `rootUrl`. */ + url: string; +} + +/** + * A list field that can either replace the current page-state list (bare array) or append to it + * (object form with `append`). Used for `breadcrumbs` and `keywords` on `ISeoPage`. Lets layered + * contributors (a layout wrapper + a page) compose without reading each other. + */ +export type AppendableList<T> = T[] | {append: T[]}; + +/** + * Spec for emitting a schema.org `WebPage` JSON-LD node. Drives the page-level structured data + * Google uses to understand the page's identity, publication dates, and relationship to the site. + */ +export interface WebPageSpec { + /** Path used to compute the node's `@id` and `url`. Combined with `rootUrl` at render. */ + canonicalPath: string; + /** Display name for the page node. Falls back to the page `title` if omitted. */ + name?: string | undefined; + /** Required description; copied verbatim into the node's `description` field. SEO-critical. */ + description: string; + /** ISO-8601 publish date. Appears in the node as `datePublished`. Helps Google News / rich results. */ + datePublished?: string | undefined; + /** ISO-8601 last-modified date. Appears in the node as `dateModified`. Signals freshness to crawlers. */ + dateModified?: string | undefined; + /** + * Spec control flag. When `true`, the rendered WebPage node includes + * `"breadcrumb": {"@id": "<canonicalPath>#breadcrumb"}`, linking it to the page's `BreadcrumbList`. + * Also causes the breadcrumb list to render even when no page-level `breadcrumbs` are emitted + * (so site-wide breadcrumbs alone still appear). + */ + breadcrumb?: boolean | undefined; + /** Optional `mainEntity` for the page — e.g. a `Question` for a Q&A page or a `Thing` summary. */ + mainEntity?: Thing | Thing[] | undefined; +} + +/** + * Spec for emitting a schema.org `Article` JSON-LD node. Required for Google News / article rich + * results. Co-exists with a `WebPage` node on the same page (the article's `mainEntityOfPage` + * points back to the WebPage). + */ +export interface ArticleSpec { + /** Path used to compute the node's `@id` and `url`. Combined with `rootUrl` at render. */ + canonicalPath: string; + /** Display name. Falls back to page `title`. */ + name?: string | undefined; + /** Headline — can differ from `name` for editorial titles. Falls back to page `title`. */ + headline?: string | undefined; + /** Required description; copied into the node. SEO-critical for article rich results. */ + description: string; + /** Required ISO-8601 publish date. Drives `datePublished` — required for article rich results. */ + datePublished: string; + /** Required ISO-8601 last-modified date. Drives `dateModified`. */ + dateModified: string; + /** Optional `about` entity — typically a `Thing` describing the article's topic. */ + about?: Thing | undefined; + /** Optional section label (e.g. "Politics"). Maps to `articleSection` — helps Google News categorization. */ + articleSection?: string | undefined; + /** Optional comma-separated keywords string. Maps to `keywords` on the article node. */ + keywords?: string | undefined; +} + +/** + * Spec for emitting a schema.org `FAQPage` JSON-LD node. Required for FAQ rich results in Google + * Search (the expandable Q&A SERP feature). Each entry in `mainEntity` must be a `Question`. + */ +export interface FaqPageSpec { + /** Path used to compute the node's `@id`. Combined with `rootUrl` at render. */ + canonicalPath: string; + /** Required `Question[]`. Each must include an `acceptedAnswer` to qualify for FAQ rich results. */ + mainEntity: Question[]; +} + +/** + * Twitter / X card configuration. Drives `<meta name="twitter:*">` tags. Defaults are applied at + * init via `initialize()` — override per-page by emitting a `twitter` field on `ISeoPage`. + */ +export interface TwitterSpec { + /** Twitter card type. `summary_large_image` is required for image-forward cards. */ + card?: "summary" | "summary_large_image" | "app" | "player"; + /** Site handle (with or without leading `@`). Rendered as `twitter:site` after normalization. */ + handle?: string; +} + +/** + * Pure-data page SEO spec. Emitted to `SeoService.emit()` as a single atomic commit. + * Every field is optional; omitted fields leave the current page-state value untouched, which + * lets layered contributors (a wrapper + a page) compose without coupling. + * + * All fields are framework-agnostic — this type travels cleanly into the split-out package + * and can be consumed from React, Vue, Next.js, or any other host. + */ +export interface ISeoPage { + /** Page title. Drives `document.title` (with configured suffix) plus `og:title` and `twitter:title`. */ + title?: string; + /** Page description. Drives the `<meta name="description">`, `og:description`, `twitter:description`. SEO-critical. */ + description?: string; + /** + * Canonical path or absolute URL for the page. Drives `og:url`, `twitter:url`, `<link rel="canonical">`, + * and synchronizes the active `WebPage`/`Article` node's `url` field. Use a path (`/foo`) for the + * site's own pages; use an absolute URL when canonicalizing to an off-site location. + */ + url?: string; + /** + * Sets `<link rel="canonical">` only, without touching `og:url` / `twitter:url` / graph nodes. + * Distinct from `url` — use when the canonical target differs from the social-share URL. + */ + canonicalPath?: string; + /** Open Graph type. `article` is required for article rich results. */ + ogType?: "article" | "website"; + /** Social-share image. Drives `og:image` and `twitter:image`. Recommended ≥1200×630 for OG. */ + image?: string; + /** + * Page-level keywords. Bare array = replace; `{append: [...]}` = append to current page-state. + * Renders into `<meta name="keywords">`, `og:keywords`, and synchronizes the active `Article` node. + */ + keywords?: AppendableList<string>; + /** + * Page-level breadcrumb items. Bare array = replace; `{append: [...]}` = append. + * Renders a `BreadcrumbList` JSON-LD node, merged with site-wide items (e.g. `Home`) at render time. + */ + breadcrumbs?: AppendableList<BreadcrumbItem>; + /** When `true`, emits `<meta name="robots" content="noindex, nofollow">`. Use for auth pages, 404s, internal routes. */ + noIndex?: boolean; + /** HTTP status hint for prerenderers (e.g. `404` for not-found, `410` for gone). Drives `<meta name="prerender-status-code">`. */ + statusCode?: number; + /** + * HTTP status hint consumed downstream by the hosting layer (Stage 2 nginx parser). + * Drives `<meta name="response-http-status" content="...">`. Independent of `statusCode`: + * `statusCode` targets `prerender-status-code` (PageReplica), `responseHttpStatus` targets the + * nginx parser that turns the SPA shell into a real HTTP 404 for non-bill routes. + */ + responseHttpStatus?: number; + /** Optional `WebPage` graph node. See {@link WebPageSpec}. */ + webPage?: WebPageSpec; + /** Optional `Article` graph node. See {@link ArticleSpec}. Usually paired with a `webPage`. */ + article?: ArticleSpec; + /** Optional `FAQPage` graph node. See {@link FaqPageSpec}. Required for FAQ rich results. */ + faqPage?: FaqPageSpec; + /** Optional Twitter / X card overrides. See {@link TwitterSpec}. */ + twitter?: TwitterSpec; +} \ No newline at end of file diff --git a/src/seo-service.ts b/src/seo-service.ts new file mode 100644 index 0000000..fc9d23a --- /dev/null +++ b/src/seo-service.ts @@ -0,0 +1,786 @@ +import type {SeoConfig} from './models/seo-config.js'; +import {HtmlSeoConfigParser} from './models/seo-config.js'; +import type {JsonLdObject} from "schema-dts"; +import type {ISeoPage, AppendableList, WebPageSpec, ArticleSpec, FaqPageSpec, BreadcrumbItem} from "./seo-page.js"; +import {createBuilder} from "./seo-page-builder.js"; +import type {IPageBuilder} from "./seo-page-builder.js"; + +export type {ISeoPage, WebPageSpec, ArticleSpec, FaqPageSpec, TwitterSpec, AppendableList} from "./seo-page.js"; + +type GraphScriptDocument = { + "@context": string; + "@graph": JsonLdObject[]; +}; + +export interface SeoLogger { + debug(msg: string, ...args: unknown[]): void; + + info(msg: string, ...args: unknown[]): void; + + warn(msg: string, ...args: unknown[]): void; + + error(msg: string, ...args: unknown[]): void; +} + +export type SeoServiceConfig = { + rootUrl: string; + siteTitle?: string; + pageTitleSuffix?: string; + language?: string; + description?: string; + defaultKeywords?: readonly string[]; + graphScriptDomId?: string; + webApplicationId?: string; + logoId?: string; + organizationId?: string; + logger?: SeoLogger; +}; + +export interface ISitewideBuilder { + setBreadcrumb(items: readonly BreadcrumbItem[]): ISitewideBuilder; + + setKeywords(...keywords: (string | string[])[]): ISitewideBuilder; + + setBaseGraphNode(node: JsonLdObject): ISitewideBuilder; + + setLogo(options: { url: string; width: number; height: number; caption?: string }): ISitewideBuilder; + + setOrganization(options: { + name: string; + url?: string; + logo?: { "@id": string }; + sameAs?: string[]; + contactPoint?: object + }): ISitewideBuilder; + + setWebApplication(options: { + name: string; + url?: string; + description?: string; + softwareVersion?: string; + applicationCategory?: string; + operatingSystem?: string + }): ISitewideBuilder; +} + +export class SeoService { + private static readonly GRAPH_CONTEXT = "https://schema.org"; + + private _rootUrl: string = ""; + private _graphScriptId: string = ""; + private _pageTitleSuffix: string = ""; + private _language: string = "en-US"; + private _webApplicationId: string = ""; + private _logoId: string = ""; + private _organizationId: string = ""; + private _baseConfig!: SeoConfig; + private _currentTags: Set<HTMLElement> = new Set(); + private _isInitialized = false; + private _baseNodeIds: Set<string> = new Set(); + private _activePageNodeId: string | null = null; + private _activeArticleNodeId: string | null = null; + + private _pageTitle: string | null = null; + private _pageBreadcrumbItems: BreadcrumbItem[] = []; + private _pageKeywords: string[] = []; + private _lastBreadcrumbPath: string = ""; + private _breadcrumbConfigured: boolean = false; + + private _siteBreadcrumbItems: readonly BreadcrumbItem[] = []; + private _siteKeywords: string[] = []; + private _manualBaseNodes: Map<string, JsonLdObject> = new Map(); + private _graphNodes: JsonLdObject[] = []; + private _seedNodes: JsonLdObject[] = []; + private _graphDirty: boolean = false; + private _graphHydrated: boolean = false; + + private _logger: SeoLogger = { + debug() { + }, + info() { + }, + warn() { + }, + error() { + }, + }; + + public readonly siteWide: ISitewideBuilder; + + constructor() { + this.siteWide = this._createSitewideBuilder(); + } + + public get rootUrl(): string { + return this._rootUrl; + } + + public page(): IPageBuilder { + return createBuilder({ + rootUrl: this._rootUrl, + emit: (spec: ISeoPage) => this.emit(spec), + }); + } + + private _createSitewideBuilder(): ISitewideBuilder { + // eslint-disable-next-line @typescript-eslint/no-this-alias + const _this = this; + return { + setBreadcrumb(items) { + _this._siteBreadcrumbItems = items; + return this; + }, + setKeywords(...keywords) { + _this._siteKeywords = [...new Set(keywords.flat())]; + return this; + }, + setBaseGraphNode(node: JsonLdObject): ISitewideBuilder { + const id = node["@id"] as string; + _this._manualBaseNodes.set(id, node); + _this._baseNodeIds.add(id); + _this._renderGraphNode(id, node); + return this; + }, + setLogo(options): ISitewideBuilder { + const logoNode: JsonLdObject = { + "@type": "ImageObject", + "@id": _this._logoId, + "url": options.url, + "width": options.width, + "height": options.height, + } as unknown as JsonLdObject; + if (options.caption) { + (logoNode as unknown as Record<string, unknown>)["caption"] = options.caption; + } + _this._manualBaseNodes.set(_this._logoId, logoNode); + _this._baseNodeIds.add(_this._logoId); + _this._renderGraphNode(_this._logoId, logoNode); + + _this._ensureLoaded(); + const orgIdx = _this._findNodeIndex(_this._graphNodes, _this._organizationId); + if (orgIdx !== -1) { + const orgNode = _this._graphNodes[orgIdx] as unknown as Record<string, unknown>; + if (!orgNode["logo"]) { + _this._updateRenderedJsonLdBlock(_this._organizationId, {"logo": {"@id": _this._logoId}}); + } + } + const appIdx = _this._findNodeIndex(_this._graphNodes, _this._webApplicationId); + if (appIdx !== -1) { + const appNode = _this._graphNodes[appIdx] as unknown as Record<string, unknown>; + if (!appNode["logo"]) { + _this._updateRenderedJsonLdBlock(_this._webApplicationId, {"logo": {"@id": _this._logoId}}); + } + } + return this; + }, + setOrganization(options): ISitewideBuilder { + const orgNode: Record<string, unknown> = { + "@type": "Organization", + "@id": _this._organizationId, + "name": options.name, + "url": options.url ?? _this._rootUrl, + }; + if (options.logo) orgNode["logo"] = options.logo; + if (options.sameAs) orgNode["sameAs"] = options.sameAs; + if (options.contactPoint) orgNode["contactPoint"] = options.contactPoint; + _this._manualBaseNodes.set(_this._organizationId, orgNode as unknown as JsonLdObject); + _this._baseNodeIds.add(_this._organizationId); + _this._renderGraphNode(_this._organizationId, orgNode); + + _this._ensureLoaded(); + const appIdx = _this._findNodeIndex(_this._graphNodes, _this._webApplicationId); + if (appIdx !== -1) { + const appNode = _this._graphNodes[appIdx] as unknown as Record<string, unknown>; + if (!appNode["publisher"]) { + _this._updateRenderedJsonLdBlock(_this._webApplicationId, {"publisher": {"@id": _this._organizationId}}); + } + } + return this; + }, + setWebApplication(options): ISitewideBuilder { + const appNode: Record<string, unknown> = { + "@type": ["WebApplication", "SoftwareApplication"], + "@id": _this._webApplicationId, + "name": options.name, + "url": options.url ?? _this._rootUrl, + "operatingSystem": options.operatingSystem ?? "All", + "offers": { + "@type": "Offer", + "price": "0", + "priceCurrency": "USD", + }, + }; + if (options.description) appNode["description"] = options.description; + if (options.softwareVersion) appNode["softwareVersion"] = options.softwareVersion; + if (options.applicationCategory) appNode["applicationCategory"] = options.applicationCategory; + _this._manualBaseNodes.set(_this._webApplicationId, appNode as unknown as JsonLdObject); + _this._baseNodeIds.add(_this._webApplicationId); + _this._renderGraphNode(_this._webApplicationId, appNode); + return this; + }, + }; + } + + private _applyTitle(title: string): void { + this._pageTitle = title; + const suffix = this._pageTitleSuffix || ""; + document.title = `${title}${suffix}`; + this._setMeta('og:title', title, true); + this._setMeta('twitter:title', title); + } + + private _applyDescription(description: string): void { + this._setMeta('description', description); + this._setMeta('og:description', description, true); + this._setMeta('twitter:description', description); + } + + private _applyUrl(pathOrUrl: string): void { + const isAbsolute = /^https?:\/\//i.test(pathOrUrl); + if (isAbsolute) { + if (!this._isValidUrl(pathOrUrl)) { + throw new Error(`Invalid URL: ${pathOrUrl}`); + } + } else if (!pathOrUrl.startsWith("/")) { + throw new Error(`Invalid URL: ${pathOrUrl}`); + } + + let fullUrl: string; + if (isAbsolute) { + const url = new URL(pathOrUrl.toLowerCase()); + const pathAndQuery = `${url.pathname}${url.search}`; + fullUrl = `${this._rootUrl}${pathAndQuery}`; + } else { + fullUrl = this._resolveUrl(pathOrUrl.toLowerCase()); + } + this._setMeta('og:url', fullUrl, true); + this._setMeta('twitter:url', fullUrl, true); + this._setCanonicalOnly(fullUrl); + + try { + if (this._activePageNodeId) { + this._updateRenderedJsonLdBlock(this._activePageNodeId, {url: fullUrl}); + } + if (this._activeArticleNodeId) { + this._updateRenderedJsonLdBlock(this._activeArticleNodeId, {url: fullUrl}); + } + } catch { + void 0; + } + } + + private _applyOgType(typeParam: "article" | "website"): void { + this._setMeta('og:type', typeParam, true); + } + + private _applyImage(imageUrl: string): void { + this._setMeta('og:image', imageUrl, true); + this._setMeta('twitter:image', imageUrl); + } + + private _applyKeywords(spec: AppendableList<string>): void { + if (Array.isArray(spec)) { + this._pageKeywords = [...spec]; + } else { + const existing = new Set(this._pageKeywords); + for (const kw of spec.append) existing.add(kw); + this._pageKeywords = [...existing]; + } + this._renderKeywords(); + } + + private _applyWebPage(options: WebPageSpec): void { + const name = options.name ?? this._pageTitle ?? ""; + const fullUrl = this._resolveUrl(options.canonicalPath); + const webpageId = `${fullUrl}#webpage`; + this._renderGraphNode(webpageId, { + "@id": webpageId, + "@type": "WebPage", + "url": fullUrl, + "inLanguage": this._language, + "name": name, + "description": options.description, + "isPartOf": {"@id": this._webApplicationId}, + "image": {"@id": this._logoId}, + "primaryImageOfPage": {"@id": this._logoId}, + ...(options.datePublished ? {"datePublished": options.datePublished} : {}), + ...(options.dateModified ? {"dateModified": options.dateModified} : {}), + ...(options.breadcrumb ? {"breadcrumb": {"@id": `${fullUrl}#breadcrumb`}} : {}), + ...(options.mainEntity ? {"mainEntity": options.mainEntity} : {}), + }); + if (options.breadcrumb) { + this._lastBreadcrumbPath = options.canonicalPath; + if (!this._breadcrumbConfigured) { + this._applyBreadcrumbAt(options.canonicalPath, []); + } + } + } + + private _applyBreadcrumbAt(canonicalPath: string, itemsOrSpec: AppendableList<BreadcrumbItem>): void { + if ("append" in itemsOrSpec) { + const existing = new Set(this._pageBreadcrumbItems); + for (const it of itemsOrSpec.append) existing.add(it); + this._pageBreadcrumbItems = [...existing]; + this._breadcrumbConfigured = true; + this._renderBreadcrumbFromState(this._lastBreadcrumbPath || canonicalPath); + } else { + this._lastBreadcrumbPath = canonicalPath; + this._pageBreadcrumbItems = [...itemsOrSpec]; + this._breadcrumbConfigured = true; + this._renderBreadcrumbFromState(canonicalPath); + } + } + + private _applyArticle(options: ArticleSpec): void { + const name = options.name ?? this._pageTitle ?? ""; + const headline = options.headline ?? this._pageTitle ?? name; + const fullUrl = this._resolveUrl(options.canonicalPath); + const articleId = `${fullUrl}#article`; + this._renderGraphNode(articleId, { + "@id": articleId, + "@type": "Article", + "name": name, + "headline": headline, + "description": options.description, + "url": fullUrl, + "image": {"@id": this._logoId}, + "author": {"@id": this._organizationId}, + "publisher": {"@id": this._organizationId}, + ...(options.about ? {"about": options.about} : {}), + ...(options.articleSection ? {"articleSection": options.articleSection} : {}), + "mainEntityOfPage": {"@type": "WebPage", "@id": `${fullUrl}#webpage`}, + "datePublished": options.datePublished, + "dateModified": options.dateModified, + ...(options.keywords ? {"keywords": options.keywords} : {}), + }); + } + + private _applyFaqPage(options: FaqPageSpec): void { + const fullUrl = this._resolveUrl(options.canonicalPath); + const faqPageId = `${fullUrl}#faqpage`; + this._renderGraphNode(faqPageId, { + "@id": faqPageId, + "@type": "FAQPage", + "mainEntity": options.mainEntity, + }); + } + + private _applyTwitterCard(cardType?: "summary" | "summary_large_image" | "app" | "player"): void { + if (cardType) { + this._setMeta('twitter:card', cardType); + } + } + + private _applyTwitterHandle(username: string): void { + this._setMeta('twitter:site', username.startsWith('@') ? username : `@${username}`); + } + + private _applyStatusCode(statusCodeParam: number): void { + this._setMeta("prerender-status-code", statusCodeParam.toString()); + } + + private _applyResponseStatusCode(statusCodeParam: number): void { + this._setMeta("response-http-status", statusCodeParam.toString()); + } + + private _applyNoIndex(): void { + this._setMeta("robots", "noindex, nofollow"); + } + + private _applyCanonicalUrl(path: string): void { + const fullUrl = this._resolveUrl(path); + this._setCanonicalOnly(fullUrl); + } + + public getDefaults(): SeoConfig { + return this._baseConfig; + } + + public prepareToNavigate(): void { + this._currentTags.forEach(tag => tag.remove()); + this._currentTags.clear(); + const scripts = document.querySelectorAll('script[data-seo="true"]') as NodeListOf<HTMLScriptElement>; + scripts.forEach(script => script.remove()); + + if (this._activePageNodeId && !this._baseNodeIds.has(this._activePageNodeId)) { + this._activePageNodeId = null; + } + if (this._activeArticleNodeId && !this._baseNodeIds.has(this._activeArticleNodeId)) { + this._activeArticleNodeId = null; + } + + this._pageTitle = null; + this._pageBreadcrumbItems = []; + this._pageKeywords = []; + this._lastBreadcrumbPath = ""; + this._breadcrumbConfigured = false; + + const mergedNodes: JsonLdObject[] = []; + for (const seedNode of this._seedNodes) { + const id = seedNode["@id"] as string; + const manual = this._manualBaseNodes.get(id); + mergedNodes.push(manual ?? seedNode); + } + for (const [id, node] of this._manualBaseNodes.entries()) { + if (!this._seedNodes.some(n => n["@id"] === id)) { + mergedNodes.push(node); + } + } + this._graphNodes = mergedNodes; + this._graphDirty = true; + this._commitGraph(); + + this._applyPageDefaults(); + this._logger.debug("SEO configurations have been reset."); + } + + public initialize(config: SeoServiceConfig | string): void { + if (this._isInitialized) return; + + const resolved = typeof config === "string" ? {rootUrl: config} : config; + if (resolved.logger) { + this._logger = resolved.logger; + } + this._rootUrl = resolved.rootUrl.replace(/\/+$/, ""); + this._graphScriptId = resolved.graphScriptDomId ?? `${this._rootUrl}/#graph`; + this._language = resolved.language ?? "en-US"; + this._webApplicationId = resolved.webApplicationId ?? `${this._rootUrl}/#webapplication`; + this._logoId = resolved.logoId ?? `${this._rootUrl}/#logo`; + this._organizationId = resolved.organizationId ?? `${this._rootUrl}/#organization`; + + const hostname = new URL(this._rootUrl).hostname; + this._baseConfig = HtmlSeoConfigParser(hostname, this._graphScriptId); + + this._ensureLoaded(); + + const siteName = resolved.siteTitle ?? this._baseConfig.siteName ?? ""; + this._pageTitleSuffix = resolved.pageTitleSuffix ?? (siteName ? ` | ${siteName}` : ""); + + if (resolved.defaultKeywords) { + this._siteKeywords = [...new Set(resolved.defaultKeywords)]; + } else if (this._baseConfig.keywords?.length) { + this._siteKeywords = [...this._baseConfig.keywords]; + } + + this._applyPageDefaults(); + this._isInitialized = true; + this._logger.debug("SEO configurations have been initialized."); + } + + public resolveUrl(path: string): string { + return this._resolveUrl(path); + } + + public setSiteName(nameParam: string): this { + this._setMeta('og:site_name', nameParam, true); + this._setMeta("apple-mobile-web-app-title", nameParam); + + return this; + } + + public setUrl(pathOrUrl: string): this { + this._applyUrl(pathOrUrl); + return this; + } + + public emit(seoPage: ISeoPage): void { + const webPageSpec = seoPage.webPage; + const articleSpec = seoPage.article; + const faqPageSpec = seoPage.faqPage; + + if (seoPage.title !== undefined) { + this._applyTitle(seoPage.title); + } + if (seoPage.description !== undefined) { + this._applyDescription(seoPage.description); + } + if (webPageSpec) { + this._applyWebPage(webPageSpec); + } + if (articleSpec) { + this._applyArticle(articleSpec); + } + if (faqPageSpec) { + this._applyFaqPage(faqPageSpec); + } + if (seoPage.breadcrumbs !== undefined) { + this._applyBreadcrumbAt(this._lastBreadcrumbPath, seoPage.breadcrumbs); + } + if (seoPage.url !== undefined) { + this._applyUrl(seoPage.url); + } + if (seoPage.ogType !== undefined) { + this._applyOgType(seoPage.ogType); + } + if (seoPage.image !== undefined) { + this._applyImage(seoPage.image); + } + if (seoPage.keywords !== undefined) { + this._applyKeywords(seoPage.keywords); + } + if (seoPage.twitter?.card !== undefined) { + this._applyTwitterCard(seoPage.twitter.card); + } + if (seoPage.twitter?.handle !== undefined) { + this._applyTwitterHandle(seoPage.twitter.handle); + } + if (seoPage.statusCode !== undefined) { + this._applyStatusCode(seoPage.statusCode); + } + if (seoPage.responseHttpStatus !== undefined) { + this._applyResponseStatusCode(seoPage.responseHttpStatus); + } + if (seoPage.noIndex === true) { + this._applyNoIndex(); + } + if (seoPage.canonicalPath !== undefined) { + this._applyCanonicalUrl(seoPage.canonicalPath); + } + } + + private _resolveUrl(pathOrUrl: string): string { + if (/^https?:\/\//i.test(pathOrUrl)) { + return pathOrUrl; + } + const normalizedPath = pathOrUrl.startsWith("/") ? pathOrUrl : `/${pathOrUrl}`; + return `${this._rootUrl}${normalizedPath}`; + } + + private _renderKeywords(): void { + const keywordListString = this._pageKeywords.join(', '); + this._setMeta('keywords', keywordListString); + this._setMeta('og:keywords', keywordListString, true); + + try { + if (this._activeArticleNodeId) { + this._updateRenderedJsonLdBlock(this._activeArticleNodeId, {keywords: keywordListString}); + } + } catch { + void 0; + } + } + + private _renderBreadcrumbFromState(canonicalPath: string): void { + const combined = [...this._siteBreadcrumbItems, ...this._pageBreadcrumbItems]; + if (combined.length === 0) return; + const resolvedPath = canonicalPath || (typeof window !== "undefined" ? window.location.pathname : ""); + const fullUrl = this._resolveUrl(resolvedPath); + const breadcrumbId = `${fullUrl}#breadcrumb`; + this._renderGraphNode(breadcrumbId, { + "@id": breadcrumbId, + "name": "Breadcrumbs", + "@type": "BreadcrumbList", + "itemListElement": combined.map((item, index) => ({ + "@type": "ListItem", + "position": index + 1, + "item": { + "@id": this._resolveUrl(item.url), + "@type": "Thing", + "name": item.name, + }, + })), + }); + } + + private _renderGraphNode(ldId: string, data: object, updateIfExistsParam: boolean = true): void { + this._ensureLoaded(); + const idx = this._findNodeIndex(this._graphNodes, ldId); + const node = this._stripContext(data) as unknown as JsonLdObject; + + if (idx !== -1) { + if (!updateIfExistsParam) { + throw new Error(`JSON-LD with id ${ldId} already exists`); + } + this._graphNodes[idx] = this._withId(node, ldId); + } else { + this._graphNodes.push(this._withId(node, ldId)); + } + + const type = node["@type"]; + if (type === "WebPage") { + this._activePageNodeId = ldId; + } else if (type === "Article") { + this._activeArticleNodeId = ldId; + } + + this._graphDirty = true; + this._commitGraph(); + } + + private _ensureLoaded(): void { + if (this._graphHydrated) return; + const fromConfig = this._baseConfig?.jsonLd; + let nodes: JsonLdObject[]; + if (fromConfig) { + const items = Array.isArray(fromConfig) ? fromConfig : [fromConfig]; + nodes = items.map(item => this._stripContext(item.data) as unknown as JsonLdObject) + .map(node => this._withId(node, node["@id"] as string)); + } else { + const doc = this._readGraphDocument(); + nodes = doc ? [...doc["@graph"]] : []; + } + this._seedNodes = [...nodes]; + this._graphNodes = nodes; + this._graphHydrated = true; + this._graphDirty = false; + } + + private _commitGraph(): void { + if (!this._graphDirty) return; + this._serializeGraph(); + this._graphDirty = false; + } + + private _readGraphDocument(): GraphScriptDocument | null { + if (this._graphHydrated) { + return {"@context": SeoService.GRAPH_CONTEXT, "@graph": [...this._graphNodes]}; + } + const script = document.querySelector(`script[data-id="${this._graphScriptId}"]`) as HTMLScriptElement | null; + if (!script?.textContent) { + return {"@context": SeoService.GRAPH_CONTEXT, "@graph": []}; + } + try { + const parsed = JSON.parse(script.textContent); + if (parsed && typeof parsed === 'object' && Array.isArray(parsed["@graph"])) { + return { + "@context": parsed["@context"] ?? SeoService.GRAPH_CONTEXT, + "@graph": parsed["@graph"] as JsonLdObject[], + }; + } + return {"@context": SeoService.GRAPH_CONTEXT, "@graph": []}; + } catch (e) { + this._logger.error('Failed to parse JSON-LD graph', e); + return null; + } + } + + private _serializeGraph(): void { + let script = document.querySelector(`script[data-id="${this._graphScriptId}"]`) as HTMLScriptElement | null; + if (!script) { + script = document.createElement('script'); + script.type = 'application/ld+json'; + script.setAttribute('data-id', this._graphScriptId); + document.head.appendChild(script); + } + script.text = JSON.stringify({"@context": SeoService.GRAPH_CONTEXT, "@graph": this._graphNodes}); + } + + private _findNodeIndex(nodes: JsonLdObject[], id: string): number { + for (let i = 0; i < nodes.length; i++) { + if (nodes[i]?.["@id"] === id) return i; + } + return -1; + } + + private _stripContext(value: unknown): Record<string, unknown> { + if (value && typeof value === 'object' && !Array.isArray(value)) { + const copy = {...(value as Record<string, unknown>)}; + delete copy["@context"]; + return copy; + } + return {}; + } + + private _withId(node: JsonLdObject, id: string): JsonLdObject { + (node as unknown as Record<string, unknown>)["@id"] = id; + return node; + } + + private _setMeta(nameOrProperty: string, content: string, isProperty = false): void { + if (!content) return; + + const selector = isProperty || nameOrProperty.startsWith('og:') + ? `meta[property="${nameOrProperty}"]` + : `meta[name="${nameOrProperty}"]`; + + let meta = document.querySelector(selector) as HTMLMetaElement; + + if (!meta) { + meta = document.createElement('meta'); + if (isProperty) { + meta.setAttribute('property', nameOrProperty); + } else { + meta.setAttribute('name', nameOrProperty); + } + + document.head.appendChild(meta); + this._currentTags.add(meta); + } + + meta.setAttribute('data-seo', 'true'); + meta.content = content; + } + + private _setCanonicalOnly(url: string): void { + let link = document.querySelector('link[rel="canonical"]') as HTMLLinkElement; + + if (!link) { + link = document.createElement('link'); + link.rel = 'canonical'; + document.head.appendChild(link); + this._currentTags.add(link); + } + + link.setAttribute('data-seo', 'true'); + const parsed = new URL(url); + link.href = parsed.origin + parsed.pathname; + } + + private _applyPageDefaults(): void { + const {title, description, og, twitter} = this._baseConfig; + + if (title) this._applyTitle(title); + if (description) this._applyDescription(description); + + this._setMeta('og:site_name', this._baseConfig.siteName, true); + this._setMeta("apple-mobile-web-app-title", this._baseConfig.siteName); + this._setMeta("robots", this._baseConfig.robots); + this._applyUrl(window.location.href); + this._applyImage(this._baseConfig.logoUrl); + + if (this._siteKeywords.length > 0) { + this._pageKeywords = [...this._siteKeywords]; + this._renderKeywords(); + } + + if (og) { + this._setMeta('og:type', og.type, true); + if (og.imageWidth) this._setMeta('og:image:width', og.imageWidth.toString(), true); + if (og.imageHeight) this._setMeta('og:image:height', og.imageHeight.toString(), true); + this._setMeta("og:logo", og.imageUrl ?? this._baseConfig.logoUrl, true); + } + + if (twitter) { + this._setMeta('twitter:card', twitter.cardType); + this._setMeta('twitter:site', twitter.handleId); + this._setMeta('twitter:domain', twitter.domain, true); + } + + this._manualBaseNodes.forEach((node, id) => { + this._renderGraphNode(id, node); + }); + } + + private _updateRenderedJsonLdBlock(ldId: string, partial: Record<string, unknown>): void { + this._ensureLoaded(); + + const idx = this._findNodeIndex(this._graphNodes, ldId); + if (idx === -1) { + throw new Error(`JSON-LD with id ${ldId} does not exist`); + } + + const existing = this._graphNodes[idx] as unknown as Record<string, unknown>; + this._graphNodes[idx] = {...existing, ...partial} as unknown as JsonLdObject; + this._graphDirty = true; + this._commitGraph(); + } + + private _isValidUrl(url: string): boolean { + try { + new URL(url); + return true; + } catch { + return false; + } + } +} diff --git a/src/seo-specs.ts b/src/seo-specs.ts new file mode 100644 index 0000000..3e36cbd --- /dev/null +++ b/src/seo-specs.ts @@ -0,0 +1,11 @@ +export type DateOnly = `${number}${number}${number}${number}-${number}${number}-${number}${number}`; +export type SeoDateInput = DateOnly | (string & {}); + +const dateOnlyRegex = /^\d{4}-\d{2}-\d{2}$/; + +export function normalizeSeoDate(input: SeoDateInput): string { + if (typeof input === "string" && dateOnlyRegex.test(input)) { + return `${input}T00:00:00+00:00`; + } + return input; +} diff --git a/test/baseline-synthesis.spec.ts b/test/baseline-synthesis.spec.ts new file mode 100644 index 0000000..2c4b0f8 --- /dev/null +++ b/test/baseline-synthesis.spec.ts @@ -0,0 +1,424 @@ +import {describe, expect, it} from "vitest"; +import {readFileSync} from "node:fs"; +import {join} from "node:path"; +import {JSDOM} from "jsdom"; +import type {Thing} from "schema-dts"; +import {SeoService} from "../src/index.js"; +import type {BreadcrumbItem} from "../src/seo-page.js"; +import {normalizeHead, type RawHead} from "../scripts/normalize.js"; + +const ROOT_URL = "https://billgrokker.com"; +const FIXTURES_DIR = join(process.cwd(), "fixtures", "baseline"); + +interface Fixture { + route: string; + capturedAt: string; + head: RawHead; + bill: { + title: string; + dates: {datePublished: string; dateModified: string}; + policyArea: string; + breadcrumbs: string[]; + } | null; +} + +interface GraphNode { + "@id"?: string; + "@type"?: string | string[]; + mainEntity?: unknown; + [key: string]: unknown; +} + +function loadFixture(slug: string): Fixture { + return JSON.parse(readFileSync(join(FIXTURES_DIR, `${slug}.json`), "utf8")) as Fixture; +} + +const STATIC_HEAD = `<head> + <title>AI-Powered Legislative Summaries | Bill Grokker + + + + + + + + + + + + + + + + + + + + + + + + +`; + +const HOME_BREADCRUMB: BreadcrumbItem = {name: "Home", url: "/"}; +const FAQ_BREADCRUMB: BreadcrumbItem = {name: "FAQ", url: "/faq/"}; +const SEARCH_DEFAULT_BREADCRUMB: BreadcrumbItem = {name: "Search Bills", url: "/bills/search"}; + +const SITE_DEFAULT_DESCRIPTION = + "Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring."; + +interface RoutePlan { + slug: string; + browserLocation: string; + routerTitleChain?: string[]; + synthesize: (service: SeoService, fixture: Fixture) => void; +} + +function siteWideSetup(service: SeoService): void { + service.siteWide.setBreadcrumb([HOME_BREADCRUMB]); + service.siteWide.setLogo({ + url: `${ROOT_URL}/images/logo-color.png`, + width: 300, + height: 68, + caption: "Bill Grokker", + }); + service.siteWide.setOrganization({ + name: "Bill Grokker", + url: ROOT_URL, + sameAs: [ + "https://x.com/billgrokker", + "https://www.facebook.com/billgrokker", + "https://www.instagram.com/billgrokker", + "https://www.linkedin.com/company/billgrokker", + "https://github.com/billgrokker", + ], + contactPoint: { + "@type": "ContactPoint", + contactType: "customer service", + url: "mailto:support@expertvision.software", + }, + }); + service.siteWide.setWebApplication({ + name: "Bill Grokker", + description: SITE_DEFAULT_DESCRIPTION, + softwareVersion: "1.0.0", + applicationCategory: "Government", + }); +} + +function fixtureGraphNode(fixture: Fixture, idSuffix: string): GraphNode { + const block = fixture.head.jsonLd[0] as {"@graph": GraphNode[]}; + const node = block["@graph"].find((n) => typeof n["@id"] === "string" && String(n["@id"]).endsWith(idSuffix)); + if (!node) throw new Error(`${fixture.route}: no JSON-LD node ending in ${idSuffix}`); + return node; +} + +function fixtureDescription(fixture: Fixture): string { + const meta = fixture.head.metas.find((m) => m.name === "description"); + if (!meta?.content) throw new Error(`${fixture.route}: no description meta in fixture`); + return meta.content; +} + +function parseBillRoute(route: string): {congress: string; type: string; number: string} { + const match = route.match(/^\/bills\/(\d+)\/([a-z]+)\/(\d+)$/); + if (!match) throw new Error(`unparseable bill route: ${route}`); + const [, congress, type, number] = match; + return {congress: congress as string, type: type as string, number: number as string}; +} + +const ROUTE_PLANS: RoutePlan[] = [ + { + slug: "home", + browserLocation: `${ROOT_URL}/`, + routerTitleChain: ["AI-Powered Legislative Summaries"], + synthesize: () => undefined, + }, + { + slug: "bills-search", + browserLocation: `${ROOT_URL}/bills/search`, + synthesize: (service) => { + const pageDesc = "Legislation bills related to a search term."; + service.page() + .setTitle("Search Bills") + .setDescription(pageDesc) + .setUrl("/bills/search") + .setWebPage({ + description: pageDesc, + datePublished: "2025-08-01", + dateModified: new Date().toISOString(), + breadcrumb: true, + }) + .setBreadcrumbs([SEARCH_DEFAULT_BREADCRUMB]) + .setKeywords("legislation", "bills", "congress", "bill grokker", "search legislation", "") + .setOgType("website") + .emit(); + }, + }, + { + slug: "faq", + browserLocation: `${ROOT_URL}/faq/index`, + routerTitleChain: ["FAQ", "Frequently Asked Questions"], + synthesize: (service, fixture) => { + const pageDesc = "Frequently asked questions about Bill Grokker and how it works."; + const mainEntity = fixtureGraphNode(fixture, "#faqpage")["mainEntity"] as Thing[]; + service.page() + .setTitle("Frequently Asked Questions") + .setDescription(pageDesc) + .setUrl("/faq") + .setWebPage({ + description: pageDesc, + datePublished: "2025-08-01", + dateModified: "2025-08-05", + breadcrumb: true, + }) + .setFaqPage({canonicalPath: "/faq", mainEntity}) + .setBreadcrumbs([FAQ_BREADCRUMB]) + .setKeywords("legislation", "bills", "congress", "bill grokker", "frequent questions", "common questions", "explanation") + .emit(); + }, + }, + { + slug: "faq-companion-bills", + browserLocation: `${ROOT_URL}/faq/companion-bills`, + routerTitleChain: ["Companion Bills Explained", "Frequently Asked Questions"], + synthesize: (service, fixture) => { + const pageDesc = + "Companion bills are identical or nearly identical bills introduced in both the House and Senate simultaneously to accelerate the legislative process."; + const mainEntity = fixtureGraphNode(fixture, "#webpage")["mainEntity"] as Thing; + service.page() + .setTitle("Companion Bills Explained") + .setDescription(pageDesc) + .setUrl("/faq/companion-bills") + .setWebPage({ + description: pageDesc, + datePublished: "2025-07-25", + dateModified: "2025-07-25", + breadcrumb: true, + mainEntity, + }) + .setKeywords("companion bills", "legislation", "congress", "house", "senate", "bicameral", "bill duplication") + .setBreadcrumbs([ + FAQ_BREADCRUMB, + {name: "Companion Bills", url: "/faq/companion-bills"}, + ]) + .setOgType("article") + .emit(); + }, + }, + { + slug: "bill-119-hr-1", + browserLocation: `${ROOT_URL}/bills/119/hr/1`, + synthesize: (service, fixture) => { + synthesizeBillDetail(service, fixture); + }, + }, + { + slug: "bill-119-s-5653", + browserLocation: `${ROOT_URL}/bills/119/s/5653`, + synthesize: (service, fixture) => { + synthesizeBillDetail(service, fixture); + }, + }, + { + slug: "not-found", + browserLocation: `${ROOT_URL}/not-found`, + routerTitleChain: ["Not Found"], + synthesize: (service) => { + service.emit({ + description: "The page you requested could not be found.", + noIndex: true, + statusCode: 404, + responseHttpStatus: 404, + }); + }, + }, + { + slug: "account-login", + browserLocation: `${ROOT_URL}/account/login`, + routerTitleChain: ["Login"], + synthesize: (service) => { + service.emit({noIndex: true}); + }, + }, + { + slug: "account-signup", + browserLocation: `${ROOT_URL}/account/signup`, + routerTitleChain: ["Register for an Account"], + synthesize: (service) => { + service.emit({noIndex: true}); + }, + }, +]; + +function synthesizeBillDetail(service: SeoService, fixture: Fixture): void { + const bill = fixture.bill; + if (!bill) throw new Error(`${fixture.route}: fixture has no bill metadata block`); + const {congress, type, number} = parseBillRoute(fixture.route); + const billIdentifier = `${type}${number}`; + const formattedBillId = `${type.toUpperCase()}. ${number} (${congress}th)`; + const canonicalPath = `/bills/${congress}/${type.toLowerCase()}/${number}`; + + const cp = service.page() + .setTitle(bill.title) + .setDescription(fixtureDescription(fixture)) + .setUrl(canonicalPath) + .contentPage() + .setDates({ + published: bill.dates.datePublished, + modified: bill.dates.dateModified, + }) + .setKeywords(`bills, legislation, congress, government, politics, ${billIdentifier}`) + .setBreadcrumbs([ + SEARCH_DEFAULT_BREADCRUMB, + {name: `${congress}th Congress`, url: `/bills/${congress}/search`}, + {name: formattedBillId, url: canonicalPath}, + ]); + if (bill.policyArea) { + cp.setAbout(bill.policyArea).setSection(bill.policyArea); + } + cp.emit(); +} + +function createDom(location: string): {dom: JSDOM; service: SeoService} { + const dom = new JSDOM(`${STATIC_HEAD}`, { + url: location, + }); + Object.defineProperty(globalThis, "document", { + value: dom.window.document, + configurable: true, + writable: true, + }); + Object.defineProperty(globalThis, "window", { + value: dom.window, + configurable: true, + writable: true, + }); + const service = new SeoService(); + service.initialize({rootUrl: ROOT_URL}); + return {dom, service}; +} + +function readHead(dom: JSDOM): RawHead { + const doc = dom.window.document; + const metaNodes = Array.from(doc.head.querySelectorAll("meta")); + return { + title: doc.title, + metas: metaNodes.map((m) => ({ + name: m.getAttribute("name"), + property: m.getAttribute("property"), + content: m.getAttribute("content"), + })), + canonical: doc.head.querySelector('link[rel="canonical"]')?.getAttribute("href") ?? null, + jsonLd: Array.from(doc.head.querySelectorAll('script[type="application/ld+json"]')).map((s) => + JSON.parse(s.textContent ?? "null") + ), + }; +} + +function applyRouterTitle(dom: JSDOM, chain: string[]): void { + const titlePart = chain.join(" | "); + const baseTitle = [...chain, "Bill Grokker"].join(" | "); + dom.window.document.title = `${titlePart} | ${baseTitle}`; +} + +describe("baseline synthesis (fixtures vs public API)", () => { + for (const plan of ROUTE_PLANS) { + it(`reproduces ${plan.slug} (${loadFixture(plan.slug).route})`, () => { + const fixture = loadFixture(plan.slug); + const {dom, service} = createDom(plan.browserLocation); + try { + siteWideSetup(service); + plan.synthesize(service, fixture); + service.setUrl(plan.browserLocation); + if (plan.routerTitleChain) { + applyRouterTitle(dom, plan.routerTitleChain); + } + const today = new Date().toISOString().slice(0, 10); + const synthesized = normalizeHead(readHead(dom), today); + expect(synthesized).toEqual(fixture.head); + } finally { + dom.window.close(); + } + }); + } +}); diff --git a/test/seo-config.spec.ts b/test/seo-config.spec.ts new file mode 100644 index 0000000..d956da8 --- /dev/null +++ b/test/seo-config.spec.ts @@ -0,0 +1,171 @@ +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {HtmlSeoConfigParser} from "../src/index.js"; +import type {JsonLdScript} from "../src/index.js"; + +function addMeta(attrs: Record): void { + const meta = document.createElement("meta"); + for (const [key, value] of Object.entries(attrs)) { + meta.setAttribute(key, value); + } + document.head.appendChild(meta); +} + +function addGraphScript(dataId: string, content: string): void { + const script = document.createElement("script"); + script.setAttribute("type", "application/ld+json"); + script.setAttribute("data-id", dataId); + script.textContent = content; + document.head.appendChild(script); +} + +describe("HtmlSeoConfigParser", () => { + beforeEach(() => { + document.head.innerHTML = ""; + document.body.innerHTML = ""; + document.title = ""; + document.documentElement.removeAttribute("lang"); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("parses meta, og and twitter tags from the document", () => { + document.title = "H.R. 1 | Bill Grokker"; + document.documentElement.setAttribute("lang", "fr"); + addMeta({name: "description", content: "Test bill description"}); + addMeta({name: "keywords", content: "bills, legislation , , law"}); + addMeta({name: "robots", content: "noindex"}); + addMeta({property: "og:site_name", content: "Bill Grokker"}); + addMeta({name: "og:type", content: "article"}); + addMeta({name: "og:url", content: "https://billgrokker.com/bills/1"}); + addMeta({name: "og:logo", content: "https://billgrokker.com/logo.png"}); + addMeta({name: "og:image:width", content: "1200"}); + addMeta({name: "og:image:height", content: "630"}); + addMeta({name: "twitter:card", content: "summary_large_image"}); + addMeta({name: "twitter:site", content: "@billgrokker"}); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.title).toBe("H.R. 1 | Bill Grokker"); + expect(config.description).toBe("Test bill description"); + expect(config.keywords).toEqual(["bills", "legislation", "law"]); + expect(config.robots).toBe("noindex"); + expect(config.siteName).toBe("Bill Grokker"); + expect(config.locale).toBe("fr"); + expect(config.pageUrl).toBe("https://billgrokker.com/bills/1"); + expect(config.logoUrl).toBe("https://billgrokker.com/logo.png"); + expect(config.og).toEqual({type: "article", imageUrl: "https://billgrokker.com/logo.png", imageWidth: 1200, imageHeight: 630}); + expect(config.twitter).toEqual({cardType: "summary_large_image", handleId: "@billgrokker", domain: "billgrokker.com"}); + }); + + it("falls back to defaults when meta tags are absent", () => { + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.title).toBe(""); + expect(config.description).toBe(""); + expect(config.keywords).toEqual([]); + expect(config.robots).toBe("index, follow"); + expect(config.locale).toBe("en"); + expect(config.og.type).toBe(""); + expect(Number.isNaN(config.og.imageWidth)).toBe(true); + expect(Number.isNaN(config.og.imageHeight)).toBe(true); + expect(config.twitter.cardType).toBe(""); + expect(config.jsonLd).toBeUndefined(); + }); + + it("collects jsonLd as a single object for one graph node", () => { + addGraphScript("https://billgrokker.com/#graph", JSON.stringify({ + "@context": "https://schema.org", + "@graph": [{"@type": "WebPage", "@id": "https://billgrokker.com/#webpage"}] + })); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(Array.isArray(config.jsonLd)).toBe(false); + expect(config.jsonLd).toEqual({ + id: "https://billgrokker.com/#webpage", + data: {"@type": "WebPage", "@id": "https://billgrokker.com/#webpage"} + }); + }); + + it("collects jsonLd as an array for multiple graph nodes using the explicit dom id", () => { + addGraphScript("custom-graph", JSON.stringify({ + "@context": "https://schema.org", + "@graph": [ + {"@type": "WebPage", "@id": "https://billgrokker.com/#webpage"}, + {"@type": "Organization", "@id": "https://billgrokker.com/#organization"} + ] + })); + + const config = HtmlSeoConfigParser("billgrokker.com", "custom-graph"); + + expect(Array.isArray(config.jsonLd)).toBe(true); + const scripts = config.jsonLd as JsonLdScript[]; + expect(scripts.map(script => script.id)).toEqual([ + "https://billgrokker.com/#webpage", + "https://billgrokker.com/#organization" + ]); + }); + + it("filters graph nodes without a string @id", () => { + addGraphScript("https://billgrokker.com/#graph", JSON.stringify({ + "@graph": [ + {"@type": "WebPage"}, + {"@type": "Organization", "@id": "https://billgrokker.com/#organization"} + ] + })); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.jsonLd).toEqual({ + id: "https://billgrokker.com/#organization", + data: {"@type": "Organization", "@id": "https://billgrokker.com/#organization"} + }); + }); + + it("returns undefined jsonLd when the graph has no nodes", () => { + addGraphScript("https://billgrokker.com/#graph", JSON.stringify({"@graph": []})); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.jsonLd).toBeUndefined(); + }); + + it("returns undefined jsonLd when @graph is not an array", () => { + addGraphScript("https://billgrokker.com/#graph", JSON.stringify({"@context": "https://schema.org"})); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.jsonLd).toBeUndefined(); + }); + + it("returns undefined jsonLd when the graph script has no content", () => { + addGraphScript("https://billgrokker.com/#graph", ""); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.jsonLd).toBeUndefined(); + }); + + it("logs and returns undefined jsonLd when the graph script is invalid JSON", () => { + const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); + addGraphScript("https://billgrokker.com/#graph", "{invalid"); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(consoleError).toHaveBeenCalledWith("Failed to parse JSON-LD graph", expect.any(Error)); + expect(config.jsonLd).toBeUndefined(); + }); + + it("ignores graph scripts without the ld+json type", () => { + const script = document.createElement("script"); + script.setAttribute("data-id", "https://billgrokker.com/#graph"); + script.textContent = ""; + document.head.appendChild(script); + + const config = HtmlSeoConfigParser("billgrokker.com"); + + expect(config.jsonLd).toBeUndefined(); + }); +}); diff --git a/test/seo-equiv.spec.ts b/test/seo-equiv.spec.ts new file mode 100644 index 0000000..9bd5f54 --- /dev/null +++ b/test/seo-equiv.spec.ts @@ -0,0 +1,389 @@ +import {describe, expect, it, afterEach, vi} from "vitest"; +import {SeoService} from "../src/index.js"; +import type {JsonLdObject} from "schema-dts"; + +import {JSDOM} from "jsdom"; + +function createDocument() { + const dom = new JSDOM(` + + + AI-Powered Legislative Summaries | Bill Grokker + + + + + + + + + + + + + + + +`, { + url: "https://billgrokker.com/", + runScripts: "dangerously", + pretendToBeVisual: true, + }); + return dom.window.document; +} + +type GraphDocument = {"@context": string, "@graph": JsonLdObject[]}; + +function getGraph(doc: Document): GraphDocument | null { + const script = doc.querySelector('script[data-id="https://billgrokker.com/#graph"]'); + if (!script?.textContent) return null; + try { + return JSON.parse(script.textContent) as GraphDocument; + } catch { + return null; + } +} + +describe("SeoService L0 emit API", () => { + afterEach(() => { + vi.resetAllMocks(); + }); + + function createSeoService(doc: Document): SeoService { + Object.defineProperty(globalThis, "document", {value: doc, configurable: true, writable: true}); + Object.defineProperty(globalThis, "window", {value: doc.defaultView as unknown as Window & typeof globalThis, configurable: true, writable: true}); + return new SeoService(); + } + + function extractGraph(doc: Document): GraphDocument { + const graph = getGraph(doc); + if (!graph) { + return {"@context": "https://schema.org", "@graph": []}; + } + return graph; + } + + describe("Scenario 1: Detail page with article", () => { + it("L0 plain object emit produces correct JSON-LD graph", () => { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + seo.emit({ + title: "H.R. 1", + description: "Test bill", + url: "/bills/119/hr-1", + ogType: "article", + webPage: { canonicalPath: "/bills/119/hr-1", name: "H.R. 1", description: "Test bill", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + article: { canonicalPath: "/bills/119/hr-1", name: "H.R. 1", headline: "H.R. 1", description: "Test bill", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", about: { "@type": "Thing", name: "Policy Area" }, articleSection: "Policy Area", keywords: "bills,legislation" }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "119th Congress", url: "/bills/119/search" }], + keywords: ["bills", "legislation"] + }); + + const graph = extractGraph(doc); + + const webpageNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/bills/119/hr-1#webpage"); + const articleNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/bills/119/hr-1#article"); + const breadcrumbNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/bills/119/hr-1#breadcrumb"); + + expect(webpageNode).toBeDefined(); + expect(webpageNode?.["@type"]).toBe("WebPage"); + expect((webpageNode as Record).name).toBe("H.R. 1"); + expect((webpageNode as Record).description).toBe("Test bill"); + expect((webpageNode as Record).datePublished).toBe("2025-08-01T00:00:00+00:00"); + expect((webpageNode as Record).dateModified).toBe("2025-08-05T00:00:00+00:00"); + + expect(articleNode).toBeDefined(); + expect(articleNode?.["@type"]).toBe("Article"); + expect((articleNode as Record).name).toBe("H.R. 1"); + expect((articleNode as Record).headline).toBe("H.R. 1"); + expect((articleNode as Record).description).toBe("Test bill"); + expect((articleNode as Record).datePublished).toBe("2025-08-01T00:00:00+00:00"); + expect((articleNode as Record).dateModified).toBe("2025-08-05T00:00:00+00:00"); + expect((articleNode as Record).articleSection).toBe("Policy Area"); + expect((articleNode as Record).keywords).toBe("bills, legislation"); + + expect(breadcrumbNode).toBeDefined(); + expect(breadcrumbNode?.["@type"]).toBe("BreadcrumbList"); + }); + }); + + describe("Scenario 2: Search page (website, no article)", () => { + it("L0 plain object emit produces correct JSON-LD graph", () => { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + seo.emit({ + title: "Search", + description: "Search legislation", + url: "/search", + ogType: "website", + webPage: { canonicalPath: "/search", name: "Search", description: "Search legislation", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + breadcrumbs: [{ name: "Home", url: "/" }], + keywords: ["legislation", "bills"] + }); + + const graph = extractGraph(doc); + + const webpageNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/search#webpage"); + const breadcrumbNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/search#breadcrumb"); + + expect(webpageNode).toBeDefined(); + expect(webpageNode?.["@type"]).toBe("WebPage"); + expect((webpageNode as Record).name).toBe("Search"); + expect((webpageNode as Record).description).toBe("Search legislation"); + expect((webpageNode as Record).datePublished).toBe("2025-08-01T00:00:00+00:00"); + expect((webpageNode as Record).dateModified).toBe("2025-08-05T00:00:00+00:00"); + + expect(breadcrumbNode).toBeDefined(); + expect(breadcrumbNode?.["@type"]).toBe("BreadcrumbList"); + + const articleNode = graph["@graph"].find(n => (n as Record)?.["@type"] === "Article"); + expect(articleNode).toBeUndefined(); + }); + }); + + describe("Scenario 3: FAQ index (webPage + faqPage)", () => { + it("L0 plain object emit produces correct JSON-LD graph", () => { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + seo.emit({ + title: "FAQ", + description: "Frequently asked questions", + url: "/faq", + ogType: "website", + webPage: { canonicalPath: "/faq", name: "FAQ", description: "Frequently asked questions", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + faqPage: { canonicalPath: "/faq", mainEntity: [{ "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text." } }] }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }], + keywords: ["faq", "questions"] + }); + + const graph = extractGraph(doc); + + const webpageNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq#webpage"); + const faqNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq#faqpage"); + const breadcrumbNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq#breadcrumb"); + + expect(webpageNode).toBeDefined(); + expect(webpageNode?.["@type"]).toBe("WebPage"); + expect((webpageNode as Record).name).toBe("FAQ"); + + expect(faqNode).toBeDefined(); + expect(faqNode?.["@type"]).toBe("FAQPage"); + expect((faqNode as Record).mainEntity).toHaveLength(1); + expect(((faqNode as Record).mainEntity as Record[])[0]?.name).toBe("Why are bills duplicated?"); + + expect(breadcrumbNode).toBeDefined(); + + const articleNode = graph["@graph"].find(n => (n as Record)?.["@type"] === "Article"); + expect(articleNode).toBeUndefined(); + }); + }); + + describe("Scenario 4: Companion bills (WebPage with Question mainEntity, no Article)", () => { + it("L0 plain object emit produces correct JSON-LD graph", () => { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + seo.emit({ + title: "Companion Bills", + description: "FAQ about companion bills", + url: "/faq/companion-bills", + ogType: "article", + webPage: { canonicalPath: "/faq/companion-bills", name: "Companion Bills", description: "FAQ about companion bills", datePublished: "2025-07-25T00:00:00+00:00", dateModified: "2025-07-25T00:00:00+00:00", breadcrumb: true, mainEntity: { "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text.", "url": "https://billgrokker.com/faq#why-are-bills-duplicated" } } }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }, { name: "Companion Bills", url: "/faq/companion-bills" }], + keywords: ["companion bills", "legislation"] + }); + + const graph = extractGraph(doc); + + const webpageNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq/companion-bills#webpage"); + const articleNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq/companion-bills#article"); + const breadcrumbNode = graph["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/faq/companion-bills#breadcrumb"); + + expect(webpageNode).toBeDefined(); + expect(webpageNode?.["@type"]).toBe("WebPage"); + expect((webpageNode as Record).name).toBe("Companion Bills"); + expect((webpageNode as Record).mainEntity).toBeDefined(); + + expect(articleNode).toBeUndefined(); + + expect(breadcrumbNode).toBeDefined(); + }); + }); + + describe("Builder API vs L0 emit equivalence", () => { + function normalizeGraph(graph: GraphDocument): GraphDocument { + const sorted = [...graph["@graph"]].sort((a, b) => { + const aId = (a as Record)["@id"] as string ?? ""; + const bId = (b as Record)["@id"] as string ?? ""; + return aId.localeCompare(bId); + }); + return {"@context": graph["@context"], "@graph": sorted}; + } + + function emitL0(scenario: "details" | "search" | "faq" | "companion"): GraphDocument { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + if (scenario === "details") { + seo.emit({ + title: "H.R. 1", + description: "Test bill", + url: "/bills/119/hr-1", + ogType: "article", + webPage: { canonicalPath: "/bills/119/hr-1", name: "H.R. 1", description: "Test bill", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + article: { canonicalPath: "/bills/119/hr-1", name: "H.R. 1", headline: "H.R. 1", description: "Test bill", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", about: { "@type": "Thing", name: "Policy Area" }, articleSection: "Policy Area", keywords: "bills, legislation" }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "119th Congress", url: "/bills/119/search" }], + keywords: ["bills", "legislation"], + }); + } else if (scenario === "search") { + seo.emit({ + title: "Search", + description: "Search legislation", + url: "/search", + ogType: "website", + webPage: { canonicalPath: "/search", name: "Search", description: "Search legislation", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + breadcrumbs: [{ name: "Home", url: "/" }], + keywords: ["legislation", "bills"], + }); + } else if (scenario === "faq") { + seo.emit({ + title: "FAQ", + description: "Frequently asked questions", + url: "/faq", + ogType: "website", + webPage: { canonicalPath: "/faq", name: "FAQ", description: "Frequently asked questions", datePublished: "2025-08-01T00:00:00+00:00", dateModified: "2025-08-05T00:00:00+00:00", breadcrumb: true }, + faqPage: { canonicalPath: "/faq", mainEntity: [{ "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text." } }] }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }], + keywords: ["faq", "questions"], + }); + } else { + seo.emit({ + title: "Companion Bills", + description: "FAQ about companion bills", + url: "/faq/companion-bills", + ogType: "article", + webPage: { canonicalPath: "/faq/companion-bills", name: "Companion Bills", description: "FAQ about companion bills", datePublished: "2025-07-25T00:00:00+00:00", dateModified: "2025-07-25T00:00:00+00:00", breadcrumb: true, mainEntity: { "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text.", "url": "https://billgrokker.com/faq#why-are-bills-duplicated" } } }, + breadcrumbs: [{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }, { name: "Companion Bills", url: "/faq/companion-bills" }], + keywords: ["companion bills", "legislation"], + }); + } + + return normalizeGraph(extractGraph(doc)); + } + + function emitBuilder(scenario: "details" | "search" | "faq" | "companion"): GraphDocument { + const doc = createDocument(); + const seo = createSeoService(doc); + seo.initialize({rootUrl: "https://billgrokker.com"}); + + if (scenario === "details") { + const cp = seo.page() + .setTitle("H.R. 1") + .setDescription("Test bill") + .setUrl("/bills/119/hr-1") + .contentPage() + .setDates({published: "2025-08-01", modified: "2025-08-05"}) + .setKeywords("bills", "legislation") + .setBreadcrumbs([{ name: "Home", url: "/" }, { name: "119th Congress", url: "/bills/119/search" }]); + cp.setAbout("Policy Area").setSection("Policy Area"); + cp.emit(); + } else if (scenario === "search") { + seo.page() + .setTitle("Search") + .setDescription("Search legislation") + .setUrl("/search") + .setWebPage({ description: "Search legislation", datePublished: "2025-08-01", dateModified: "2025-08-05", breadcrumb: true }) + .setBreadcrumbs([{ name: "Home", url: "/" }]) + .setKeywords("legislation", "bills") + .setOgType("website") + .emit(); + } else if (scenario === "faq") { + seo.page() + .setTitle("FAQ") + .setDescription("Frequently asked questions") + .setUrl("/faq") + .setWebPage({ description: "Frequently asked questions", datePublished: "2025-08-01", dateModified: "2025-08-05", breadcrumb: true }) + .setFaqPage({ canonicalPath: "/faq", mainEntity: [{ "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text." } }] }) + .setBreadcrumbs([{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }]) + .setKeywords("faq", "questions") + .setOgType("website") + .emit(); + } else { + seo.page() + .setTitle("Companion Bills") + .setDescription("FAQ about companion bills") + .setUrl("/faq/companion-bills") + .setWebPage({ description: "FAQ about companion bills", datePublished: "2025-07-25", dateModified: "2025-07-25", breadcrumb: true, mainEntity: { "@type": "Question", "name": "Why are bills duplicated?", "acceptedAnswer": { "@type": "Answer", "text": "Because both chambers must pass identical text.", "url": "https://billgrokker.com/faq#why-are-bills-duplicated" } } }) + .setBreadcrumbs([{ name: "Home", url: "/" }, { name: "FAQ", url: "/faq" }, { name: "Companion Bills", url: "/faq/companion-bills" }]) + .setKeywords("companion bills", "legislation") + .setOgType("article") + .emit(); + } + + return normalizeGraph(extractGraph(doc)); + } + + for (const scenario of ["details", "search", "faq", "companion"] as const) { + it(`${scenario} page: builder API produces identical JSON-LD to L0 emit`, () => { + const l0Graph = emitL0(scenario); + const builderGraph = emitBuilder(scenario); + expect(builderGraph).toEqual(l0Graph); + }); + } + }); +}); diff --git a/test/seo-page-builder.spec.ts b/test/seo-page-builder.spec.ts new file mode 100644 index 0000000..0883a42 --- /dev/null +++ b/test/seo-page-builder.spec.ts @@ -0,0 +1,651 @@ +import {describe, expect, it, beforeEach} from "vitest"; +import {SeoPageBuilder, ContentPageBuilder, createBuilder} from "../src/index.js"; +import type {ISeoBuilderTarget, IPageBuilder} from "../src/index.js"; +import type {ISeoPage} from "../src/index.js"; +import type {WebPageSpec, ArticleSpec} from "../src/index.js"; + +describe("SeoPageBuilder", () => { + let emittedSpecs: ISeoPage[] = []; + + const target: ISeoBuilderTarget = { + rootUrl: "https://billgrokker.com", + emit: (spec: ISeoPage) => { emittedSpecs.push(spec); }, + }; + + beforeEach(() => { + emittedSpecs = []; + }); + + describe("URL guard", () => { + it("throws when same-site absolute URL is passed to setUrl", () => { + const builder = createBuilder(target); + expect(() => builder.setUrl("https://billgrokker.com/bills/hr-1")).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setCanonicalPath", () => { + const builder = createBuilder(target); + expect(() => builder.setCanonicalPath("https://billgrokker.com/bills/hr-1")).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setWebPage", () => { + const builder = createBuilder(target); + expect(() => builder.setWebPage({canonicalPath: "https://billgrokker.com/bills/hr-1"})).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setArticle", () => { + const builder = createBuilder(target); + expect(() => builder.setArticle({canonicalPath: "https://billgrokker.com/bills/hr-1"})).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("allows off-site absolute URL in setUrl", () => { + const builder = createBuilder(target); + expect(() => builder.setUrl("https://other-site.com/page")).not.toThrow(); + }); + + it("allows relative URL in setUrl", () => { + const builder = createBuilder(target); + expect(() => builder.setUrl("/bills/hr-1")).not.toThrow(); + }); + + it("allows relative URL in setCanonicalPath", () => { + const builder = createBuilder(target); + expect(() => builder.setCanonicalPath("/bills/hr-1")).not.toThrow(); + }); + + it("does not guard setImage (og:image accepts absolute URLs)", () => { + const builder = createBuilder(target); + expect(() => builder.setImage("https://other-site.com/image.png")).not.toThrow(); + }); + }); + + describe("ContentPageBuilder URL guard", () => { + it("throws when same-site absolute URL is passed to setUrl", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setUrl("https://billgrokker.com/bills/hr-1")).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setCanonicalPath", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setCanonicalPath("https://billgrokker.com/bills/hr-1")).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setWebPage", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setWebPage({canonicalPath: "https://billgrokker.com/bills/hr-1"})).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setArticle", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setArticle({canonicalPath: "https://billgrokker.com/bills/hr-1"})).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("throws when same-site absolute URL is passed to setFaqPage", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setFaqPage({canonicalPath: "https://billgrokker.com/bills/hr-1"})).toThrow( + /Use relative url when referring to same website/ + ); + }); + + it("does not guard setImage (og:image accepts absolute URLs)", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(() => cp.setImage("https://other-site.com/image.png")).not.toThrow(); + }); + }); + + describe("chainability", () => { + it("setTitle returns same builder instance", () => { + const builder = createBuilder(target); + const result = builder.setTitle("Test"); + expect(result).toBe(builder); + }); + + it("setDescription returns same builder instance", () => { + const builder = createBuilder(target); + const result = builder.setDescription("Description"); + expect(result).toBe(builder); + }); + + it("setUrl returns same builder instance", () => { + const builder = createBuilder(target); + const result = builder.setUrl("/page"); + expect(result).toBe(builder); + }); + + it("setKeywords returns same builder instance", () => { + const builder = createBuilder(target); + const result = builder.setKeywords("a", "b"); + expect(result).toBe(builder); + }); + + it("appendKeywords returns same builder instance", () => { + const builder = createBuilder(target); + const result = builder.appendKeywords("a", "b"); + expect(result).toBe(builder); + }); + }); + + describe("build() output shape", () => { + it("returns empty ISeoPage when nothing set", () => { + const builder = createBuilder(target); + const spec = builder.build(); + expect(spec).toEqual({}); + }); + + it("includes title when set", () => { + const builder = createBuilder(target); + builder.setTitle("Test Title"); + expect(builder.build().title).toBe("Test Title"); + }); + + it("includes description when set", () => { + const builder = createBuilder(target); + builder.setDescription("Test description"); + expect(builder.build().description).toBe("Test description"); + }); + + it("includes url when set with relative path", () => { + const builder = createBuilder(target); + builder.setUrl("/bills/hr-1"); + expect(builder.build().url).toBe("/bills/hr-1"); + }); + + it("includes canonicalPath when set", () => { + const builder = createBuilder(target); + builder.setCanonicalPath("/bills/hr-1"); + expect(builder.build().canonicalPath).toBe("/bills/hr-1"); + }); + + it("does not include url when canonicalPath is set without url", () => { + const builder = createBuilder(target); + builder.setCanonicalPath("/bills/hr-1"); + const spec = builder.build(); + expect(spec.url).toBeUndefined(); + expect(spec.canonicalPath).toBe("/bills/hr-1"); + }); + + it("includes ogType when set", () => { + const builder = createBuilder(target); + builder.setOgType("article"); + expect(builder.build().ogType).toBe("article"); + }); + + it("includes image when set", () => { + const builder = createBuilder(target); + builder.setImage("https://other.com/img.png"); + expect(builder.build().image).toBe("https://other.com/img.png"); + }); + + it("includes keywords when set", () => { + const builder = createBuilder(target); + builder.setKeywords("a", "b"); + expect(builder.build().keywords).toEqual(["a", "b"]); + }); + + it("deduplicates keywords", () => { + const builder = createBuilder(target); + builder.setKeywords("a", "a", "b"); + expect(builder.build().keywords).toEqual(["a", "b"]); + }); + + it("includes noIndex when set", () => { + const builder = createBuilder(target); + builder.setNoIndex(); + expect(builder.build().noIndex).toBe(true); + }); + + it("includes statusCode when set", () => { + const builder = createBuilder(target); + builder.setStatusCode(404); + expect(builder.build().statusCode).toBe(404); + }); + + it("includes breadcrumbs when set", () => { + const builder = createBuilder(target); + builder.setBreadcrumbs([{name: "Home", url: "/"}]); + expect(builder.build().breadcrumbs).toEqual([{name: "Home", url: "/"}]); + }); + + it("setBreadcrumbs replaces breadcrumbs", () => { + const builder = createBuilder(target); + builder.setBreadcrumbs([{name: "A", url: "/a"}]); + builder.setBreadcrumbs([{name: "B", url: "/b"}]); + expect(builder.build().breadcrumbs).toEqual([{name: "B", url: "/b"}]); + }); + + it("appendBreadcrumbs adds to existing breadcrumbs", () => { + const builder = createBuilder(target); + builder.setBreadcrumbs([{name: "A", url: "/a"}]); + builder.appendBreadcrumbs([{name: "B", url: "/b"}]); + expect(builder.build().breadcrumbs).toEqual([{name: "A", url: "/a"}, {name: "B", url: "/b"}]); + }); + }); + + describe("root-value inheritance", () => { + it("title falls through to webPage.name", () => { + const builder = createBuilder(target); + builder.setTitle("Page Title").setUrl("/page").setDescription("desc"); + const spec = builder.build(); + expect(spec.webPage).toMatchObject({name: "Page Title"}); + }); + + it("title falls through to article.name and article.headline", () => { + const builder = createBuilder(target); + builder.setTitle("Page Title").setUrl("/page").setDescription("desc").setArticle({}); + const spec = builder.build(); + expect(spec.article).toMatchObject({name: "Page Title", headline: "Page Title"}); + }); + + it("description falls through to webPage.description", () => { + const builder = createBuilder(target); + builder.setUrl("/page").setDescription("SEO Description").setWebPage({}); + const spec = builder.build(); + expect(spec.webPage).toMatchObject({description: "SEO Description"}); + }); + + it("url falls through to webPage.canonicalPath", () => { + const builder = createBuilder(target); + builder.setUrl("/bills/hr-1").setDescription("desc"); + const spec = builder.build(); + expect(spec.webPage).toMatchObject({canonicalPath: "/bills/hr-1"}); + }); + + it("url falls through to article.canonicalPath", () => { + const builder = createBuilder(target); + builder.setUrl("/bills/hr-1").setDescription("desc").setArticle({}); + const spec = builder.build(); + expect(spec.article).toMatchObject({canonicalPath: "/bills/hr-1"}); + }); + + it("setCanonicalPath sets canonicalPath without affecting url", () => { + const builder = createBuilder(target); + builder.setUrl("/page").setCanonicalPath("/canonical-page").setDescription("desc"); + const spec = builder.build(); + expect(spec.url).toBe("/page"); + expect(spec.canonicalPath).toBe("/canonical-page"); + }); + + it("webPage.name overrides inherited title", () => { + const builder = createBuilder(target); + builder.setTitle("Page Title").setUrl("/page").setDescription("desc") + .setWebPage({name: "Custom WebPage Name"}); + const spec = builder.build(); + expect(spec.webPage).toMatchObject({name: "Custom WebPage Name"}); + expect(spec.article).toBeUndefined(); + }); + + it("explicit webPage.canonicalPath overrides inherited url", () => { + const builder = createBuilder(target); + builder.setUrl("/page").setDescription("desc") + .setWebPage({canonicalPath: "/explicit-page"}); + const spec = builder.build(); + expect(spec.webPage).toMatchObject({canonicalPath: "/explicit-page"}); + }); + }); + + describe("webPage spec", () => { + it("setWebPage sets breadcrumb flag", () => { + const builder = createBuilder(target); + builder.setWebPage({breadcrumb: true}); + expect(builder.build().webPage).toMatchObject({breadcrumb: true}); + }); + + it("setWebPage sets datePublished normalized from DateOnly", () => { + const builder = createBuilder(target); + builder.setWebPage({datePublished: "2025-08-01"}); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec}; + expect(spec.webPage.datePublished).toBe("2025-08-01T00:00:00+00:00"); + }); + + it("setWebPage passes dateModified", () => { + const builder = createBuilder(target); + builder.setWebPage({dateModified: "2025-08-05"}); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec}; + expect(spec.webPage.dateModified).toBe("2025-08-05T00:00:00+00:00"); + }); + }); + + describe("article spec", () => { + it("setArticle sets article properties", () => { + const builder = createBuilder(target); + builder.setArticle({ + headline: "Article Headline", + description: "Article desc", + datePublished: "2025-08-01", + dateModified: "2025-08-05", + }); + const spec = builder.build() as ISeoPage & {article: ArticleSpec}; + expect(spec.article.headline).toBe("Article Headline"); + expect(spec.article.description).toBe("Article desc"); + expect(spec.article.datePublished).toBe("2025-08-01T00:00:00+00:00"); + expect(spec.article.dateModified).toBe("2025-08-05T00:00:00+00:00"); + }); + + it("article requires content (headline/about) to be included", () => { + const builder = createBuilder(target); + builder.setArticle({headline: "Headline"}); + const spec = builder.build(); + expect(spec.article).toBeDefined(); + expect((spec.article as ArticleSpec).headline).toBe("Headline"); + }); + + it("article is included when url is set", () => { + const builder = createBuilder(target); + builder.setUrl("/article").setArticle({headline: "Headline"}); + const spec = builder.build(); + expect(spec.article).toBeDefined(); + }); + }); + + describe("faqPage spec", () => { + it("setFaqPage sets faqPage", () => { + const builder = createBuilder(target); + builder.setFaqPage({mainEntity: []}); + expect(builder.build().faqPage).toEqual({mainEntity: []}); + }); + }); + + describe("twitter", () => { + it("setTwitter sets twitter options", () => { + const builder = createBuilder(target); + builder.setTwitter({card: "summary", handle: "@test"}); + const spec = builder.build(); + expect(spec.twitter).toEqual({card: "summary", handle: "@test"}); + }); + }); + + describe("emit()", () => { + it("calls target.emit with built spec", () => { + const builder = createBuilder(target); + builder.setTitle("Emit Test").emit(); + expect(emittedSpecs).toHaveLength(1); + expect(emittedSpecs[0].title).toBe("Emit Test"); + }); + + it("emit is idempotent — build does not emit", () => { + const builder = createBuilder(target); + builder.setTitle("No Emit"); + builder.build(); + expect(emittedSpecs).toHaveLength(0); + }); + + it("calling emit twice emits twice", () => { + const builder = createBuilder(target); + builder.setTitle("First").emit(); + builder.setTitle("Second").emit(); + expect(emittedSpecs).toHaveLength(2); + expect(emittedSpecs[0].title).toBe("First"); + expect(emittedSpecs[1].title).toBe("Second"); + }); + }); + + describe("contentPage()", () => { + it("returns ContentPageBuilder instance", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp).toBeInstanceOf(ContentPageBuilder); + }); + + it("sets ogType to article on the builder", () => { + const builder = createBuilder(target); + builder.contentPage(); + expect(builder.build().ogType).toBe("article"); + }); + + it("seeds webPage with breadcrumb: true", () => { + const builder = createBuilder(target); + builder.contentPage(); + expect(builder.build().webPage).toMatchObject({breadcrumb: true}); + }); + + it("seeds article when url is set", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage(); + expect(builder.build().article).toBeDefined(); + }); + + it("end() returns SeoPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.end()).toBeInstanceOf(SeoPageBuilder); + }); + }); + + describe("ContentPageBuilder.setDates", () => { + it("fans published date to both webPage and article", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage().setDates({published: "2025-08-01"}); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec; article: ArticleSpec}; + expect(spec.webPage.datePublished).toBe("2025-08-01T00:00:00+00:00"); + expect(spec.article.datePublished).toBe("2025-08-01T00:00:00+00:00"); + }); + + it("fans modified date to both webPage and article", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage().setDates({modified: "2025-08-05"}); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec; article: ArticleSpec}; + expect(spec.webPage.dateModified).toBe("2025-08-05T00:00:00+00:00"); + expect(spec.article.dateModified).toBe("2025-08-05T00:00:00+00:00"); + }); + + it("normalizes DateOnly to ISO format", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage().setDates({published: "2025-08-01"}); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec; article: ArticleSpec}; + expect(spec.webPage.datePublished).toBe("2025-08-01T00:00:00+00:00"); + }); + }); + + describe("ContentPageBuilder.setAbout", () => { + it("wraps string in Thing for article.about", () => { + const builder = createBuilder(target); + builder.setUrl("/page").setDescription("desc").contentPage().setAbout("Politics"); + const spec = builder.build() as ISeoPage & {article: ArticleSpec}; + expect(spec.article.about).toEqual({"@type": "Thing", "name": "Politics"}); + }); + + it("passes object through directly", () => { + const builder = createBuilder(target); + const aboutObj = {"@type": "Thing", "name": "Test"}; + builder.setUrl("/page").setDescription("desc").contentPage().setAbout(aboutObj); + const spec = builder.build() as ISeoPage & {article: ArticleSpec}; + expect(spec.article.about).toEqual(aboutObj); + }); + + it("sets articleSection from string", () => { + const builder = createBuilder(target); + builder.setUrl("/page").setDescription("desc").contentPage().setAbout("Politics"); + const spec = builder.build() as ISeoPage & {article: ArticleSpec}; + expect(spec.article.articleSection).toBe("Politics"); + }); + }); + + describe("ContentPageBuilder.setQuestion", () => { + it("sets webPage.mainEntity to Question", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage().setQuestion({ + name: "What is HR-1?", + answerText: "It is a bill.", + }); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec}; + expect(spec.webPage.mainEntity!["@type"]).toBe("Question"); + expect(spec.webPage.mainEntity.name).toBe("What is HR-1?"); + expect(spec.webPage.mainEntity.acceptedAnswer["@type"]).toBe("Answer"); + expect(spec.webPage.mainEntity.acceptedAnswer.text).toBe("It is a bill."); + }); + + it("includes answerUrl when provided", () => { + const builder = createBuilder(target); + builder.setUrl("/page").contentPage().setQuestion({ + name: "What is HR-1?", + answerText: "It is a bill.", + answerUrl: "https://example.com/answer", + }); + const spec = builder.build() as ISeoPage & {webPage: WebPageSpec}; + const mainEntity = spec.webPage.mainEntity as {acceptedAnswer: {url: string}}; + expect(mainEntity.acceptedAnswer.url).toBe("https://example.com/answer"); + }); + }); + + describe("ContentPageBuilder chain returns", () => { + it("setDates returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setDates({})).toBe(cp); + }); + + it("setAbout returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setAbout("Politics")).toBe(cp); + }); + + it("setSection returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setSection("Politics")).toBe(cp); + }); + + it("setQuestion returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setQuestion({name: "Q", answerText: "A"})).toBe(cp); + }); + + it("setWebPage on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setWebPage({name: "Test"})).toBe(cp); + }); + + it("setArticle on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setArticle({headline: "Headline"})).toBe(cp); + }); + + it("setBreadcrumbs on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setBreadcrumbs([{name: "Home", url: "/"}])).toBe(cp); + }); + + it("appendBreadcrumbs on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.appendBreadcrumbs([{name: "Home", url: "/"}])).toBe(cp); + }); + + it("setTitle on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setTitle("Title")).toBe(cp); + }); + + it("setDescription on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setDescription("Desc")).toBe(cp); + }); + + it("setUrl on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setUrl("/page")).toBe(cp); + }); + + it("setCanonicalPath on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setCanonicalPath("/canonical")).toBe(cp); + }); + + it("setOgType on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setOgType("article")).toBe(cp); + }); + + it("setImage on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setImage("https://img.png")).toBe(cp); + }); + + it("setKeywords on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setKeywords("a")).toBe(cp); + }); + + it("setNoIndex on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setNoIndex()).toBe(cp); + }); + + it("setStatusCode on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setStatusCode(404)).toBe(cp); + }); + + it("setResponseHttpStatus on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setResponseHttpStatus(404)).toBe(cp); + }); + + it("setTwitter on ContentPageBuilder returns ContentPageBuilder", () => { + const builder = createBuilder(target); + const cp = builder.contentPage(); + expect(cp.setTwitter({card: "summary"})).toBe(cp); + }); + }); + + describe("SeoPageBuilder implements IPageBuilder", () => { + it("SeoPageBuilder is IPageBuilder", () => { + const builder: IPageBuilder = createBuilder(target); + expect(builder.setTitle("t")).toBe(builder); + expect(builder.setDescription("d")).toBe(builder); + expect(builder.setUrl("/p")).toBe(builder); + expect(builder.setCanonicalPath("/p")).toBe(builder); + expect(builder.setOgType("article")).toBe(builder); + expect(builder.setImage("https://img.png")).toBe(builder); + expect(builder.setKeywords("k")).toBe(builder); + expect(builder.appendKeywords("k")).toBe(builder); + expect(builder.setBreadcrumbs([{name: "H", url: "/"}])).toBe(builder); + expect(builder.appendBreadcrumbs([{name: "H", url: "/"}])).toBe(builder); + expect(builder.setNoIndex()).toBe(builder); + expect(builder.setStatusCode(404)).toBe(builder); + expect(builder.setResponseHttpStatus(404)).toBe(builder); + expect(builder.setTwitter({card: "summary"})).toBe(builder); + expect(builder.setWebPage({})).toBe(builder); + expect(builder.setArticle({})).toBe(builder); + expect(builder.setFaqPage({mainEntity: []})).toBe(builder); + expect(builder.contentPage()).toBeInstanceOf(ContentPageBuilder); + expect(builder.emit()).toBeUndefined(); + }); + }); +}); diff --git a/test/seo-service.spec.ts b/test/seo-service.spec.ts new file mode 100644 index 0000000..c02ba4a --- /dev/null +++ b/test/seo-service.spec.ts @@ -0,0 +1,1538 @@ +import {describe, expect, it, vi, beforeEach, afterEach} from "vitest"; +import {SeoService} from "../src/index.js"; +import type {JsonLdObject} from "schema-dts"; + +import {JSDOM} from "jsdom"; + +function createDocumentNoGraph() { + const dom = new JSDOM(` + + + No Graph Loader + + + + + + + + + + + + +`, { + url: "https://billgrokker.com/", + runScripts: "dangerously", + pretendToBeVisual: true, + }); + return dom.window.document; +} + +type GraphDocument = {"@context": string, "@graph": JsonLdObject[]}; + +function getGraph(doc: Document): GraphDocument | null { + const script = doc.querySelector('script[data-id="https://billgrokker.com/#graph"]'); + if (!script?.textContent) return null; + try { + return JSON.parse(script.textContent) as GraphDocument; + } catch { + return null; + } +} + +function findNodeById(graph: GraphDocument, id: string): JsonLdObject | undefined { + return graph["@graph"].find(n => n?.["@id"] === id); +} + +function createDocument() { + + const dom = new JSDOM(` + + + AI-Powered Legislative Summaries | Bill Grokker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`, { + url: "https://billgrokker.com/", + runScripts: "dangerously", + pretendToBeVisual: true, + }); + return dom.window.document; +} + +describe("SeoService", () => { + let seoService: SeoService; + + beforeEach(() => { + const document = createDocument(); + Object.defineProperty(globalThis, "document", {value: document, configurable: true, writable: true}); + Object.defineProperty(globalThis, "window", {value: document.defaultView as unknown as Window & typeof globalThis, configurable: true, writable: true}); + + seoService = new SeoService(); + }); + + afterEach(() => { + vi.resetAllMocks(); + }); + + describe("initialize", () => { + it("reads from index.html defaults and sets up base configuration", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + const defaults = seoService.getDefaults(); + expect(defaults.title).toBe("AI-Powered Legislative Summaries | Bill Grokker"); + expect(defaults.description).toBe("Bill Grokker offers AI-powered legislative summaries for bills and executive orders. Understand bills or laws with analysis and bias scoring."); + expect(defaults.keywords).toEqual(["legislation", "bill summaries", "executive orders", "AI analysis", "bias scoring", "government", "policy", "law"]); + expect(defaults.siteName).toBe("Bill Grokker"); + expect(defaults.robots).toBe("index, follow"); + expect(defaults.og?.type).toBe("website"); + }); + + it("returns early if already initialized", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + const defaults1 = seoService.getDefaults(); + + seoService.initialize({rootUrl: "https://different.com"}); + const defaults2 = seoService.getDefaults(); + + expect(defaults1.title).toBe("AI-Powered Legislative Summaries | Bill Grokker"); + expect(defaults2.title).toBe("AI-Powered Legislative Summaries | Bill Grokker"); + }); + }); + + describe("getDefaults", () => { + it("returns the base configuration", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + const defaults = seoService.getDefaults(); + expect(defaults).toBeDefined(); + expect(defaults.siteName).toBe("Bill Grokker"); + }); + }); + +describe("setTitle", () => { + it("updates document.title with | Bill Grokker suffix", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({title: "Test Page Title"}); + expect(document.title).toBe("Test Page Title | Bill Grokker"); + }); + + it("sets og:title and twitter:title meta tags", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({title: "Test Page Title"}); + + const ogTitle = document.querySelector('meta[property="og:title"]') as HTMLMetaElement; + const twitterTitle = document.querySelector('meta[name="twitter:title"]') as HTMLMetaElement; + + expect(ogTitle?.content).toBe("Test Page Title"); + expect(twitterTitle?.content).toBe("Test Page Title"); + }); + }); + + describe("setDescription", () => { + it("sets meta description", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({description: "New description for the page"}); + + const description = document.querySelector('meta[name="description"]') as HTMLMetaElement; + expect(description?.content).toBe("New description for the page"); + }); + + it("sets og:description and twitter:description meta tags", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({description: "New description for the page"}); + + const ogDescription = document.querySelector('meta[property="og:description"]') as HTMLMetaElement; + const twitterDescription = document.querySelector('meta[name="twitter:description"]') as HTMLMetaElement; + + expect(ogDescription?.content).toBe("New description for the page"); + expect(twitterDescription?.content).toBe("New description for the page"); + }); + }); + + describe("setSiteName", () => { + it("sets og:site_name and apple-mobile-web-app-title meta tags", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.setSiteName("My Custom Site"); + + const ogSiteName = document.querySelector('meta[property="og:site_name"]') as HTMLMetaElement; + const appleTitle = document.querySelector('meta[name="apple-mobile-web-app-title"]') as HTMLMetaElement; + + expect(ogSiteName?.content).toBe("My Custom Site"); + expect(appleTitle?.content).toBe("My Custom Site"); + }); + }); + + describe("setImage", () => { + it("sets og:image and twitter:image meta tags", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({image: "https://example.com/image.png"}); + + const ogImage = document.querySelector('meta[property="og:image"]') as HTMLMetaElement; + const twitterImage = document.querySelector('meta[name="twitter:image"]') as HTMLMetaElement; + + expect(ogImage?.content).toBe("https://example.com/image.png"); + expect(twitterImage?.content).toBe("https://example.com/image.png"); + }); + }); + + describe("setOgType", () => { + it("sets og:type meta tag", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ogType: "article"}); + + const ogType = document.querySelector('meta[property="og:type"]') as HTMLMetaElement; + expect(ogType?.content).toBe("article"); + }); + }); + + describe("setUrl", () => { + it("sets og:url and twitter:url meta tags", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.setUrl("https://billgrokker.com/bills/hr-1234"); + + const ogUrl = document.querySelector('meta[property="og:url"]') as HTMLMetaElement; + const twitterUrl = document.querySelector('meta[property="twitter:url"]') as HTMLMetaElement; + + expect(ogUrl?.content).toBe("https://billgrokker.com/bills/hr-1234"); + expect(twitterUrl?.content).toBe("https://billgrokker.com/bills/hr-1234"); + }); + + it("sets canonical link", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.setUrl("https://billgrokker.com/bills/hr-1234"); + + const canonical = document.querySelector('link[rel="canonical"]') as HTMLLinkElement; + expect(canonical?.href).toBe("https://billgrokker.com/bills/hr-1234"); + }); + + it("throws on invalid URL", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + expect(() => seoService.setUrl("not-a-valid-url")).toThrow("Invalid URL: not-a-valid-url"); + }); + }); + + describe("setKeywords", () => { + it("sets meta keywords and og:keywords", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({keywords: ["legislation", "bills", "AI analysis"]}); + + const keywords = document.querySelector('meta[name="keywords"]') as HTMLMetaElement; + const ogKeywords = document.querySelector('meta[property="og:keywords"]') as HTMLMetaElement; + + expect(keywords?.content).toBe("legislation, bills, AI analysis"); + expect(ogKeywords?.content).toBe("legislation, bills, AI analysis"); + }); + + it("flattens nested arrays", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({keywords: ["legislation", "bills", "AI analysis", "nested"]}); + + const keywords = document.querySelector('meta[name="keywords"]') as HTMLMetaElement; + expect(keywords?.content).toBe("legislation, bills, AI analysis, nested"); + }); + }); + + describe("setWebPage", () => { + it("creates a WebPage node with canonical URL-based @id", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/bills/118/hr/1", name: "Test Page", description: "Test description"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/bills/118/hr/1#webpage"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("WebPage"); + }); + + it("includes boilerplate isPartOf, image, primaryImageOfPage, and inLanguage", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#webpage") as Record; + expect(node.inLanguage).toBe("en-US"); + expect((node.isPartOf as Record)["@id"]).toBe("https://billgrokker.com/#webapplication"); + expect((node.image as Record)["@id"]).toBe("https://billgrokker.com/#logo"); + expect((node.primaryImageOfPage as Record)["@id"]).toBe("https://billgrokker.com/#logo"); + }); + + it("includes datePublished and dateModified when provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-07-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#webpage") as Record; + expect(node.datePublished).toBe("2025-01-01T00:00:00.000Z"); + expect(node.dateModified).toBe("2025-07-01T00:00:00.000Z"); + }); + + it("omits datePublished and dateModified when not provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#webpage") as Record; + expect(node).not.toHaveProperty("datePublished"); + expect(node).not.toHaveProperty("dateModified"); + }); + + it("includes breadcrumb reference when breadcrumb option is true", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc", breadcrumb: true}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#webpage") as Record; + expect((node.breadcrumb as Record)["@id"]).toBe("https://billgrokker.com/page#breadcrumb"); + }); + + it("omits breadcrumb reference when breadcrumb option is not set", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#webpage") as Record; + expect(node).not.toHaveProperty("breadcrumb"); + }); + + it("sets _activePageNodeId for setUrl updates", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Test", description: "Desc"}}); + + expect((seoService as unknown as {_activePageNodeId: string | null})._activePageNodeId).toBe("https://billgrokker.com/page#webpage"); + }); + + it("updates existing WebPage when called with same canonicalUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "Old", description: "Old desc"}}); + + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/page", name: "New", description: "New desc"}}); + + const graph = getGraph(document); + const nodes = graph!["@graph"].filter(n => n?.["@id"] === "https://billgrokker.com/page#webpage"); + expect(nodes).toHaveLength(1); + expect((nodes[0] as Record).name).toBe("New"); + }); + }); + + describe("setBreadcrumb", () => { + it("creates a BreadcrumbList node with canonical URL-based @id", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "https://billgrokker.com/bills/118/hr/1", description: "d", breadcrumb: true}, + breadcrumbs: [ + { name: "Home", url: "/" }, + {name: "Search Bills", url: "https://billgrokker.com/bills/search"}, + {name: "HR. 1 (118th)", url: "https://billgrokker.com/bills/118/hr/1"}, + ], + }); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/bills/118/hr/1#breadcrumb"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("BreadcrumbList"); + }); + + it("maps items to ListItem with sequential 1-based positions", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "https://billgrokker.com/page", description: "d", breadcrumb: true}, + breadcrumbs: [ + { name: "Home", url: "/" }, + {name: "Section", url: "https://billgrokker.com/section"}, + {name: "Current", url: "https://billgrokker.com/page"}, + ], + }); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#breadcrumb"); + const items = (node as Record)?.itemListElement as Array>; + expect(items).toHaveLength(3); + expect(items[0]).toEqual({"@type": "ListItem", "position": 1, "item": {"@id": "https://billgrokker.com/", "@type": "Thing", "name": "Home"}}); + expect(items[1]).toEqual({"@type": "ListItem", "position": 2, "item": {"@id": "https://billgrokker.com/section", "@type": "Thing", "name": "Section"}}); + expect(items[2]).toEqual({"@type": "ListItem", "position": 3, "item": {"@id": "https://billgrokker.com/page", "@type": "Thing", "name": "Current"}}); + }); + + it("handles single-item breadcrumb", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "https://billgrokker.com/page", description: "d", breadcrumb: true}, + breadcrumbs: [ + { name: "Home", url: "/" }, + ], + }); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#breadcrumb"); + const items = (node as Record)?.itemListElement as Array>; + expect(items).toHaveLength(1); + expect(items[0]?.position).toBe(1); + }); + + it("updates existing breadcrumb when called with same canonicalUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "https://billgrokker.com/page", description: "d", breadcrumb: true}, + breadcrumbs: [ + { name: "Home", url: "/" }, + {name: "Old", url: "https://billgrokker.com/old"}, + ], + }); + + seoService.emit({ + breadcrumbs: [ + { name: "Home", url: "/" }, + {name: "New", url: "https://billgrokker.com/new"}, + ], + }); + + const graph = getGraph(document); + const nodes = graph!["@graph"].filter(n => n?.["@id"] === "https://billgrokker.com/page#breadcrumb"); + expect(nodes).toHaveLength(1); + const items = (nodes[0] as Record)?.itemListElement as Array>; + expect((items[1] as Record)?.item).toEqual({"@id": "https://billgrokker.com/new", "@type": "Thing", "name": "New"}); + }); + + it("breadcrumb node is removed by prepareToNavigate", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "https://billgrokker.com/page", description: "d", breadcrumb: true}, + breadcrumbs: [ + { name: "Home", url: "/" }, + ], + }); + + expect(findNodeById(getGraph(document)!, "https://billgrokker.com/page#breadcrumb")).toBeDefined(); + + seoService.prepareToNavigate(); + + expect(findNodeById(getGraph(document)!, "https://billgrokker.com/page#breadcrumb")).toBeUndefined(); + }); + }); + + describe("robotShouldIgnorePage", () => { + it("sets robots meta to noindex, nofollow", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({noIndex: true}); + + const robots = document.querySelector('meta[name="robots"]') as HTMLMetaElement; + expect(robots?.content).toBe("noindex, nofollow"); + }); + + it("does NOT persist into the next prepareToNavigate — singleton must reset robots", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({noIndex: true}); + + const robotsBefore = document.querySelector('meta[name="robots"]') as HTMLMetaElement; + expect(robotsBefore?.content).toBe("noindex, nofollow"); + + seoService.prepareToNavigate(); + + const robotsAfter = document.querySelector('meta[name="robots"]') as HTMLMetaElement; + expect(robotsAfter?.content).toBe("index, follow"); + expect(robotsAfter?.content).not.toContain("noindex"); + }); + + it("reset works even after multiple noIndex emits", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({noIndex: true}); + seoService.emit({noIndex: true}); + seoService.emit({noIndex: true}); + + seoService.prepareToNavigate(); + + const robots = document.querySelector('meta[name="robots"]') as HTMLMetaElement; + expect(robots?.content).toBe("index, follow"); + }); + }); + + describe("setTwitterCard", () => { + it("sets twitter:card meta tag when cardType is provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({twitter: {card: "summary_large_image"}}); + + const twitterCard = document.querySelector('meta[name="twitter:card"]') as HTMLMetaElement; + expect(twitterCard?.content).toBe("summary_large_image"); + }); + }); + + describe("setTwitterHandle", () => { + it("sets twitter:site meta tag with @ prefix if not present", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({twitter: {handle: "TestUser"}}); + + const twitterSite = document.querySelector('meta[name="twitter:site"]') as HTMLMetaElement; + expect(twitterSite?.content).toBe("@TestUser"); + }); + + it("keeps existing @ prefix", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({twitter: {handle: "@ExistingUser"}}); + + const twitterSite = document.querySelector('meta[name="twitter:site"]') as HTMLMetaElement; + expect(twitterSite?.content).toBe("@ExistingUser"); + }); + }); + + describe("setStatusCode", () => { + it("sets prerender-status-code meta tag", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({statusCode: 404}); + + const statusCode = document.querySelector('meta[name="prerender-status-code"]') as HTMLMetaElement; + expect(statusCode?.content).toBe("404"); + }); + }); + + describe("setResponseHttpStatus", () => { + it("sets response-http-status meta tag with provided status code", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({responseHttpStatus: 404}); + + const meta = document.querySelector('meta[name="response-http-status"]') as HTMLMetaElement; + expect(meta?.content).toBe("404"); + }); + + it("does not collide with prerender-status-code when both are emitted", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({statusCode: 404, responseHttpStatus: 404}); + + const prerender = document.querySelector('meta[name="prerender-status-code"]') as HTMLMetaElement; + const response = document.querySelector('meta[name="response-http-status"]') as HTMLMetaElement; + expect(prerender?.content).toBe("404"); + expect(response?.content).toBe("404"); + }); + + it("emits response-http-status independently of statusCode", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({responseHttpStatus: 410}); + + const response = document.querySelector('meta[name="response-http-status"]') as HTMLMetaElement; + const prerender = document.querySelector('meta[name="prerender-status-code"]'); + expect(response?.content).toBe("410"); + expect(prerender).toBeNull(); + }); + + it("marks the meta tag as seo-managed via data-seo attribute", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({responseHttpStatus: 404}); + + const meta = document.querySelector('meta[name="response-http-status"]') as HTMLMetaElement; + expect(meta?.getAttribute("data-seo")).toBe("true"); + }); + + it("does not write a meta tag when responseHttpStatus is omitted", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({title: "Page"}); + + const meta = document.querySelector('meta[name="response-http-status"]'); + expect(meta).toBeNull(); + }); + }); + + describe("setArticle", () => { + it("creates an Article node with canonical URL-based @id", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/bills/118/hr/1", name: "Test Article", headline: "Test Headline", description: "Test description", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/bills/118/hr/1#article"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("Article"); + expect(node?.name).toBe("Test Article"); + expect(node?.headline).toBe("Test Headline"); + expect(node?.description).toBe("Test description"); + expect(node?.url).toBe("https://billgrokker.com/bills/118/hr/1"); + }); + + it("includes author and publisher refs", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#article") as Record; + expect((node.author as Record)["@id"]).toBe("https://billgrokker.com/#organization"); + expect((node.publisher as Record)["@id"]).toBe("https://billgrokker.com/#organization"); + expect((node.image as Record)["@id"]).toBe("https://billgrokker.com/#logo"); + }); + + it("includes mainEntityOfPage pointing to WebPage node", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#article") as Record; + const mainEntity = node.mainEntityOfPage as Record; + expect(mainEntity["@type"]).toBe("WebPage"); + expect(mainEntity["@id"]).toBe("https://billgrokker.com/page#webpage"); + }); + + it("includes optional about, articleSection, and keywords", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z", about: {"@type": "Thing", "name": "Policy"} as never, articleSection: "Government", keywords: "bills, legislation"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#article") as Record; + expect((node.about as Record).name).toBe("Policy"); + expect(node.articleSection).toBe("Government"); + expect(node.keywords).toBe("bills, legislation"); + }); + + it("omits optional fields when not provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/page#article") as Record; + expect(node).not.toHaveProperty("about"); + expect(node).not.toHaveProperty("articleSection"); + expect(node).not.toHaveProperty("keywords"); + }); + + it("sets _activeArticleNodeId for setUrl and setKeywords updates", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + expect((seoService as unknown as {_activeArticleNodeId: string | null})._activeArticleNodeId).toBe("https://billgrokker.com/page#article"); + }); + + it("updates existing Article when called with same canonicalUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "Old", headline: "Old", description: "Old desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + seoService.emit({article: {canonicalPath: "https://billgrokker.com/page", name: "New", headline: "New", description: "New desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const nodes = graph!["@graph"].filter(n => n?.["@id"] === "https://billgrokker.com/page#article"); + expect(nodes).toHaveLength(1); + expect((nodes[0] as Record).name).toBe("New"); + }); + }); + + describe("setFaqPage", () => { + it("creates a FAQPage node with canonical URL-based @id", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "What is Bill Grokker?", + "answerCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "A platform for understanding legislation.", + } + } + ]}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("FAQPage"); + expect((node as Record).mainEntity).toHaveLength(1); + }); + + it("updates existing FAQPage when called with same canonicalUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Original question?", + "answerCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Original answer.", + } + } + ]}}); + + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Updated question?", + "answerCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "A platform for understanding legislation.", + } + } + ]}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("FAQPage"); + expect((node as Record).mainEntity).toHaveLength(1); + }); + + it("updates existing FAQPage when called with same canonicalUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Original question?", + "answerCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Original answer.", + } + } + ]}}); + + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Updated question?", + "answerCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Updated answer.", + } + } + ]}}); + + const graph = getGraph(document); + const faqNode = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + expect(faqNode).toBeDefined(); + expect(faqNode).toHaveProperty("@type", "FAQPage"); + expect((faqNode as Record).mainEntity).toHaveLength(1); + + const mainEntity = (faqNode as Record).mainEntity as Record[]; + expect(mainEntity[0]).toHaveProperty("name", "Updated question?"); + }); + }); + + describe("prepareToNavigate", () => { + it("clears page-specific SEO data but preserves base JSON-LD nodes from index.html", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Test Org"}); + seoService.siteWide.setWebApplication({name: "Test App"}); + seoService.siteWide.setLogo({url: "https://example.com/logo.png", width: 300, height: 68}); + seoService.emit({title: "Page Title", description: "Page description"}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Test", description: "Desc"}}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + expect(graph).not.toBeNull(); + expect(findNodeById(graph!, "https://example.com/page#webpage")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + }); + + it("clears page-specific SEO meta/link tags and rebuilds base nodes into the graph", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Test Org"}); + seoService.siteWide.setWebApplication({name: "Test App"}); + seoService.emit({title: "Test Page"}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Test", description: "Desc"}}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + expect(findNodeById(graph!, "https://example.com/page#webpage")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + + const graphScript = document.querySelector('script[data-id="https://billgrokker.com/#graph"]'); + expect(graphScript).not.toBeNull(); + + const seoScripts = document.querySelectorAll('script[data-seo="true"]'); + expect(seoScripts.length).toBe(0); + }); + + it("reapplies base configuration after clearing", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({title: "Custom Title"}); + + seoService.prepareToNavigate(); + + expect(document.title).toContain("| Bill Grokker"); + const ogTitle = document.querySelector('meta[property="og:title"]') as HTMLMetaElement; + expect(ogTitle).not.toBeNull(); + }); + }); + + describe("edge cases", () => { + it("handles empty content in _setMeta gracefully", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + expect(() => (seoService as unknown as { + _setMeta: (name: string, content: string, isProperty?: boolean) => void + })._setMeta.call(seoService, "test", "", false)).not.toThrow(); + }); + + it("handles URL with query parameters in setUrl", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.setUrl("https://billgrokker.com/bills/search?q=HR1234&exec=1"); + + const ogUrl = document.querySelector('meta[property="og:url"]') as HTMLMetaElement; + expect(ogUrl?.content).toBe("https://billgrokker.com/bills/search?q=hr1234&exec=1"); + }); + }); + + describe("graph model", () => { + it("renders nodes into the @graph array of the single graph script", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const separateScript = document.querySelector('script[data-id="https://example.com/page#article"]'); + expect(separateScript).toBeNull(); + + const graph = getGraph(document); + expect(graph).not.toBeNull(); + const node = findNodeById(graph!, "https://example.com/page#article"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("Article"); + }); + + it("strips @context from page-emitted data", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://example.com/page#article"); + expect(node).toBeDefined(); + expect(node).not.toHaveProperty("@context"); + expect(node).toHaveProperty("@type", "Article"); + expect(node).toHaveProperty("name", "Test"); + }); + + it("graph script has @context at document level only", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const jsonLdScripts = document.querySelectorAll('script[type="application/ld+json"]'); + expect(jsonLdScripts.length).toBe(1); + + const graph = getGraph(document); + expect(graph?.["@context"]).toBe("https://schema.org"); + expect(Array.isArray(graph?.["@graph"])).toBe(true); + expect((graph?.["@graph"] ?? []).length).toBeGreaterThan(0); + + const nodes = graph?.["@graph"] ?? []; + nodes.forEach(node => { + expect(node).not.toHaveProperty("@context"); + }); + }); + + it("multiple page nodes coexist in the graph", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Page", description: "Desc"}}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Article", headline: "Article", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + const graph = getGraph(document); + expect(findNodeById(graph!, "https://example.com/page#webpage")).toBeDefined(); + expect(findNodeById(graph!, "https://example.com/page#article")).toBeDefined(); + }); + + it("merges partial update into existing node by @id via private _updateRenderedJsonLdBlock", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z", keywords: "original"}}); + + (seoService as unknown as { + _updateRenderedJsonLdBlock: (id: string, partial: Record) => void + })._updateRenderedJsonLdBlock("https://example.com/page#article", {updated: "data"}); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://example.com/page#article"); + expect(node?.updated).toBe("data"); + }); + + it("setUrl updates active page node url without touching base nodes", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Test", description: "Desc"}}); + + const webAppBefore = getGraph(document)?.["@graph"].find(n => n?.["@id"] === "https://billgrokker.com/#webapplication"); + + seoService.setUrl("https://billgrokker.com/bills/hr-1234"); + + const graph = getGraph(document); + const pageNode = findNodeById(graph!, "https://example.com/page#webpage"); + expect(pageNode?.url).toBe("https://billgrokker.com/bills/hr-1234"); + + const webAppAfter = findNodeById(graph!, "https://billgrokker.com/#webapplication"); + expect(webAppAfter).toEqual(webAppBefore); + expect((webAppAfter as unknown as {url: string}).url).toBe("https://billgrokker.com"); + }); + + it("emit keywords updates active article node keywords", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Test", headline: "Test", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z", keywords: "old"}}); + + seoService.emit({keywords: ["new", "keywords"]}); + + const graph = getGraph(document); + const articleNode = findNodeById(graph!, "https://example.com/page#article"); + expect(articleNode?.keywords).toBe("new, keywords"); + }); + + it("prepareToNavigate removes page-specific nodes from graph but preserves base nodes", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Test Org"}); + seoService.siteWide.setWebApplication({name: "Test App"}); + seoService.siteWide.setLogo({url: "https://example.com/logo.png", width: 300, height: 68}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Page", description: "Desc"}}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Article", headline: "Article", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + expect(findNodeById(graph!, "https://example.com/page#webpage")).toBeUndefined(); + expect(findNodeById(graph!, "https://example.com/page#article")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#logo")).toBeDefined(); + }); + + it("tracks _activePageNodeId and _activeArticleNodeId via setWebPage and setArticle", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://example.com/page", name: "Page", description: "Desc"}}); + seoService.emit({article: {canonicalPath: "https://example.com/page", name: "Article", headline: "Article", description: "Desc", datePublished: "2025-01-01T00:00:00.000Z", dateModified: "2025-01-01T00:00:00.000Z"}}); + + expect((seoService as unknown as {_activePageNodeId: string | null})._activePageNodeId).toBe("https://example.com/page#webpage"); + expect((seoService as unknown as {_activeArticleNodeId: string | null})._activeArticleNodeId).toBe("https://example.com/page#article"); + }); + }); + + describe("FAQPage JSON-LD", () => { + it("renders FAQPage with mainEntity containing Question and Answer nodes", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "What is Bill Grokker?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Bill Grokker is a platform for understanding legislation.", + "url": "https://billgrokker.com/faq#what-is-bill-grokker", + "upvoteCount": 1 + } + }, + { + "@type": "Question", + "name": "How does it work?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "It uses AI to analyze bills and provide summaries.", + "url": "https://billgrokker.com/faq#how-does-it-work", + "upvoteCount": 1 + } + } + ]}}); + + const graph = getGraph(document); + const faqNode = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + + expect(faqNode).toBeDefined(); + expect(faqNode).toHaveProperty("@type", "FAQPage"); + expect(faqNode).toHaveProperty("mainEntity"); + expect((faqNode as Record).mainEntity).toHaveLength(2); + + const mainEntity = (faqNode as Record).mainEntity as Record[]; + expect(mainEntity[0]).toHaveProperty("@type", "Question"); + expect(mainEntity[0]).toHaveProperty("name", "What is Bill Grokker?"); + expect(mainEntity[0]).toHaveProperty("answerCount", 1); + expect(mainEntity[0]).toHaveProperty("upvoteCount", 1); + expect(mainEntity[0]).toHaveProperty("acceptedAnswer"); + expect((mainEntity[0] as Record).acceptedAnswer).toHaveProperty("@type", "Answer"); + expect((mainEntity[0] as Record).acceptedAnswer).toHaveProperty("text", "Bill Grokker is a platform for understanding legislation."); + expect((mainEntity[0] as Record).acceptedAnswer).toHaveProperty("url", "https://billgrokker.com/faq#what-is-bill-grokker"); + expect((mainEntity[0] as Record).acceptedAnswer).toHaveProperty("upvoteCount", 1); + + expect(mainEntity[1]).toHaveProperty("@type", "Question"); + expect(mainEntity[1]).toHaveProperty("name", "How does it work?"); + expect(mainEntity[1]).toHaveProperty("answerCount", 1); + expect(mainEntity[1]).toHaveProperty("upvoteCount", 1); + expect(mainEntity[1]).toHaveProperty("acceptedAnswer"); + expect((mainEntity[1] as Record).acceptedAnswer).toHaveProperty("@type", "Answer"); + expect((mainEntity[1] as Record).acceptedAnswer).toHaveProperty("url", "https://billgrokker.com/faq#how-does-it-work"); + }); + + it("allows FAQPage and WebPage to coexist in the same graph", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "https://billgrokker.com/faq", name: "FAQ Page", description: "Desc"}}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Test question?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Test answer.", + "url": "https://billgrokker.com/faq#test-question", + "upvoteCount": 1 + } + } + ]}}); + + const graph = getGraph(document); + const webPageNode = findNodeById(graph!, "https://billgrokker.com/faq#webpage"); + const faqNode = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + + expect(webPageNode).toBeDefined(); + expect(webPageNode).toHaveProperty("@type", "WebPage"); + + expect(faqNode).toBeDefined(); + expect(faqNode).toHaveProperty("@type", "FAQPage"); + expect((faqNode as Record).mainEntity).toHaveLength(1); + }); + + it("updates existing FAQPage node when re-rendered", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Original question?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Original answer.", + "url": "https://billgrokker.com/faq#original-question", + "upvoteCount": 1 + } + } + ]}}); + + seoService.emit({faqPage: {canonicalPath: "https://billgrokker.com/faq", mainEntity: [ + { + "@type": "Question", + "name": "Updated question?", + "answerCount": 1, + "upvoteCount": 1, + "acceptedAnswer": { + "@type": "Answer", + "text": "Updated answer.", + "url": "https://billgrokker.com/faq#updated-question", + "upvoteCount": 1 + } + } + ]}}); + + const graph = getGraph(document); + const faqNode = findNodeById(graph!, "https://billgrokker.com/faq#faqpage"); + + expect(faqNode).toBeDefined(); + expect(faqNode).toHaveProperty("@type", "FAQPage"); + expect((faqNode as Record).mainEntity).toHaveLength(1); + + const mainEntity = (faqNode as Record).mainEntity as Record[]; + expect(mainEntity[0]).toHaveProperty("name", "Updated question?"); + }); + }); + + describe("siteWide builder", () => { + describe("setBaseGraphNode", () => { + it("adds a node to the graph", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setBaseGraphNode({ + "@id": "https://billgrokker.com/#custom", + "@type": "Thing", + "name": "Custom Node", + } as unknown as JsonLdObject); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/#custom"); + expect(node).toBeDefined(); + expect(node?.["@type"]).toBe("Thing"); + expect(node?.name).toBe("Custom Node"); + }); + + it("persists across prepareToNavigate", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setBaseGraphNode({ + "@id": "https://billgrokker.com/#custom", + "@type": "Thing", + "name": "Custom Node", + } as unknown as JsonLdObject); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/#custom"); + expect(node).toBeDefined(); + expect(node?.name).toBe("Custom Node"); + }); + + it("updates existing node when called with same @id", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setBaseGraphNode({ + "@id": "https://billgrokker.com/#custom", + "@type": "Thing", + "name": "Original", + } as unknown as JsonLdObject); + seoService.siteWide.setBaseGraphNode({ + "@id": "https://billgrokker.com/#custom", + "@type": "Thing", + "name": "Updated", + } as unknown as JsonLdObject); + + const graph = getGraph(document); + const node = findNodeById(graph!, "https://billgrokker.com/#custom"); + expect(node?.name).toBe("Updated"); + }); + }); + + describe("setLogo", () => { + it("creates or updates the ImageObject base node", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setLogo({url: "https://billgrokker.com/logo.png", width: 200, height: 60, caption: "Test"}); + + const graph = getGraph(document); + const logoNode = findNodeById(graph!, "https://billgrokker.com/#logo") as Record; + expect(logoNode).toBeDefined(); + expect(logoNode["@type"]).toBe("ImageObject"); + expect(logoNode.url).toBe("https://billgrokker.com/logo.png"); + expect(logoNode.width).toBe(200); + expect(logoNode.height).toBe(60); + expect(logoNode.caption).toBe("Test"); + }); + + it("sets organization.logo ref when org exists and logo is unset", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setLogo({url: "https://billgrokker.com/logo.png", width: 200, height: 60}); + + const graph = getGraph(document); + const orgNode = findNodeById(graph!, "https://billgrokker.com/#organization") as Record; + expect((orgNode.logo as Record)["@id"]).toBe("https://billgrokker.com/#logo"); + }); + + it("persists across prepareToNavigate", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setLogo({url: "https://billgrokker.com/logo.png", width: 200, height: 60}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + const logoNode = findNodeById(graph!, "https://billgrokker.com/#logo") as Record; + expect(logoNode).toBeDefined(); + expect(logoNode.url).toBe("https://billgrokker.com/logo.png"); + expect(logoNode.width).toBe(200); + }); + }); + + describe("setOrganization", () => { + it("creates or updates the Organization base node", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({ + name: "Test Org", + url: "https://example.com", + sameAs: ["https://x.com/test"], + }); + + const graph = getGraph(document); + const orgNode = findNodeById(graph!, "https://billgrokker.com/#organization") as Record; + expect(orgNode).toBeDefined(); + expect(orgNode["@type"]).toBe("Organization"); + expect(orgNode.name).toBe("Test Org"); + expect(orgNode.url).toBe("https://example.com"); + expect(orgNode.sameAs).toEqual(["https://x.com/test"]); + }); + + it("defaults url to rootUrl when not provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "NoUrl Org"}); + + const graph = getGraph(document); + const orgNode = findNodeById(graph!, "https://billgrokker.com/#organization") as Record; + expect(orgNode.url).toBe("https://billgrokker.com"); + }); + + it("sets webApplication.publisher ref when app exists and publisher is unset", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Pub Org"}); + + const graph = getGraph(document); + const appNode = findNodeById(graph!, "https://billgrokker.com/#webapplication") as Record; + expect((appNode.publisher as Record)["@id"]).toBe("https://billgrokker.com/#organization"); + }); + + it("persists across prepareToNavigate", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Persistent Org"}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + const orgNode = findNodeById(graph!, "https://billgrokker.com/#organization") as Record; + expect(orgNode).toBeDefined(); + expect(orgNode.name).toBe("Persistent Org"); + }); + }); + + describe("setWebApplication", () => { + it("creates or updates the WebApplication base node", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setWebApplication({ + name: "Test App", + description: "Test description", + softwareVersion: "2.0.0", + applicationCategory: "Education", + }); + + const graph = getGraph(document); + const appNode = findNodeById(graph!, "https://billgrokker.com/#webapplication") as Record; + expect(appNode).toBeDefined(); + expect(appNode["@type"]).toEqual(["WebApplication", "SoftwareApplication"]); + expect(appNode.name).toBe("Test App"); + expect(appNode.description).toBe("Test description"); + expect(appNode.softwareVersion).toBe("2.0.0"); + expect(appNode.applicationCategory).toBe("Education"); + expect(appNode.operatingSystem).toBe("All"); + expect((appNode.offers as Record)?.price).toBe("0"); + expect((appNode.offers as Record)?.priceCurrency).toBe("USD"); + }); + + it("defaults url to rootUrl when not provided", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setWebApplication({name: "NoUrl App"}); + + const graph = getGraph(document); + const appNode = findNodeById(graph!, "https://billgrokker.com/#webapplication") as Record; + expect(appNode.url).toBe("https://billgrokker.com"); + }); + + it("persists across prepareToNavigate", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setWebApplication({name: "Persistent App", softwareVersion: "3.0.0"}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + const appNode = findNodeById(graph!, "https://billgrokker.com/#webapplication") as Record; + expect(appNode).toBeDefined(); + expect(appNode.name).toBe("Persistent App"); + expect(appNode.softwareVersion).toBe("3.0.0"); + }); + }); + }); + + describe("in-memory graph store", () => { + it("seeds _graphNodes from loader output on initialize", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + const graph = getGraph(document); + expect(graph).not.toBeNull(); + expect(findNodeById(graph!, "https://billgrokker.com/#logo")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + }); + + it("does not call _readGraphDocument on subsequent graph mutations", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + const readSpy = vi.spyOn(seoService as unknown as {_readGraphDocument: () => unknown}, "_readGraphDocument"); + + seoService.emit({webPage: {canonicalPath: "/test", description: "Test page"}}); + seoService.emit({article: {canonicalPath: "/test", description: "Test article", datePublished: "2024-01-01", dateModified: "2024-01-01"}}); + seoService.siteWide.setBaseGraphNode({ + "@id": "https://billgrokker.com/#extra", + "@type": "Thing", + "name": "Extra", + } as unknown as JsonLdObject); + + expect(readSpy).not.toHaveBeenCalled(); + + readSpy.mockRestore(); + }); + + it("flushes the graph after each mutation", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + const serializeSpy = vi.spyOn(seoService as unknown as {_serializeGraph: () => void}, "_serializeGraph"); + const baseline = serializeSpy.mock.calls.length; + + seoService.emit({webPage: {canonicalPath: "/a", description: "A"}}); + const afterWebPage = serializeSpy.mock.calls.length; + expect(afterWebPage).toBeGreaterThan(baseline); + + seoService.emit({article: {canonicalPath: "/a", description: "A", datePublished: "2024-01-01", dateModified: "2024-01-01"}}); + const afterArticle = serializeSpy.mock.calls.length; + expect(afterArticle).toBeGreaterThan(afterWebPage); + + seoService.emit({keywords: ["foo", "bar"]}); + const afterKeywords = serializeSpy.mock.calls.length; + expect(afterKeywords).toBeGreaterThan(afterArticle); + + serializeSpy.mockRestore(); + }); + + it("does not serialize when graph is not dirty", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + const serializeSpy = vi.spyOn(seoService as unknown as {_serializeGraph: () => void}, "_serializeGraph"); + const baseline = serializeSpy.mock.calls.length; + + seoService.emit({title: "New Title"}); + seoService.emit({description: "New Desc"}); + seoService.emit({image: "https://billgrokker.com/img.png"}); + + expect(serializeSpy.mock.calls.length).toBe(baseline); + + serializeSpy.mockRestore(); + }); + + it("falls back to _readGraphDocument when loader produced no jsonLd", () => { + const originalDoc = globalThis.document; + Object.defineProperty(globalThis, "document", {value: createDocumentNoGraph() as unknown as Document, configurable: true, writable: true}); + + try { + const freshService = new SeoService(); + const readSpy = vi.spyOn(freshService as unknown as {_readGraphDocument: () => unknown}, "_readGraphDocument"); + + freshService.initialize({rootUrl: "https://billgrokker.com"}); + + expect(readSpy).toHaveBeenCalled(); + + readSpy.mockRestore(); + } finally { + Object.defineProperty(globalThis, "document", {value: originalDoc, configurable: true, writable: true}); + } + }); + + it("preserves loader-seeded nodes across prepareToNavigate when no manual override", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + seoService.emit({webPage: {canonicalPath: "/page1", description: "Page 1"}}); + + seoService.prepareToNavigate(); + + const graph = getGraph(document); + expect(findNodeById(graph!, "https://billgrokker.com/page1#webpage")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#logo")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + }); + + it("prepareToNavigate flushes the cleared state before next observation", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.siteWide.setOrganization({name: "Test Org"}); + seoService.siteWide.setWebApplication({name: "Test App"}); + seoService.siteWide.setLogo({url: "https://billgrokker.com/logo.png", width: 300, height: 68}); + + seoService.emit({webPage: {canonicalPath: "/page1", description: "Page 1"}}); + seoService.emit({article: {canonicalPath: "/page1", description: "Article 1", datePublished: "2024-01-01", dateModified: "2024-01-01"}}); + + let graph = getGraph(document); + expect(findNodeById(graph!, "https://billgrokker.com/page1#webpage")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/page1#article")).toBeDefined(); + + seoService.prepareToNavigate(); + + graph = getGraph(document); + expect(findNodeById(graph!, "https://billgrokker.com/page1#webpage")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/page1#article")).toBeUndefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#logo")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#organization")).toBeDefined(); + expect(findNodeById(graph!, "https://billgrokker.com/#webapplication")).toBeDefined(); + }); + }); + + describe("emit()", () => { + it("renders a complete page in one atomic commit", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + + seoService.emit({ + title: "Emit Title", + description: "Emit description", + url: "/emit-page", + ogType: "article", + image: "https://example.com/img.png", + keywords: ["emit", "seo"], + breadcrumbs: [{name: "Home", url: "/"}, {name: "Emit", url: "/emit-page"}], + noIndex: true, + statusCode: 404, + twitter: {card: "summary_large_image", handle: "@emit"}, + webPage: {canonicalPath: "/emit-page", description: "Emit description", breadcrumb: true}, + }); + + expect(document.title).toBe("Emit Title | Bill Grokker"); + const meta = (name: string) => document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") + ?? document.querySelector(`meta[property="${name}"]`)?.getAttribute("content"); + expect(meta("description")).toBe("Emit description"); + expect(meta("og:title")).toBe("Emit Title"); + expect(meta("og:url")).toBe("https://billgrokker.com/emit-page"); + expect(meta("og:type")).toBe("article"); + expect(meta("og:image")).toBe("https://example.com/img.png"); + expect(meta("keywords")).toBe("emit, seo"); + expect(meta("robots")).toBe("noindex, nofollow"); + expect(meta("prerender-status-code")).toBe("404"); + expect(meta("twitter:card")).toBe("summary_large_image"); + expect(meta("twitter:site")).toBe("@emit"); + + const graph = getGraph(document)!; + const webPage = findNodeById(graph, "https://billgrokker.com/emit-page#webpage"); + expect(webPage).toBeDefined(); + expect(webPage?.["@type"]).toBe("WebPage"); + const breadcrumb = findNodeById(graph, "https://billgrokker.com/emit-page#breadcrumb"); + expect(breadcrumb).toBeDefined(); + expect(breadcrumb?.["@type"]).toBe("BreadcrumbList"); + }); + + it("replaces page-state list when keywords is a bare array", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({keywords: ["a", "b", "c"]}); + expect((document.querySelector('meta[name="keywords"]') as HTMLMetaElement).content).toBe("a, b, c"); + + seoService.emit({keywords: ["x"]}); + expect((document.querySelector('meta[name="keywords"]') as HTMLMetaElement).content).toBe("x"); + }); + + it("appends page-state list when keywords uses {append: [...}]", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({keywords: ["a", "b"]}); + seoService.emit({keywords: {append: ["c", "d"]}}); + expect((document.querySelector('meta[name="keywords"]') as HTMLMetaElement).content).toBe("a, b, c, d"); + }); + + it("appends to breadcrumbs via {append: [...}] without resetting", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({ + webPage: {canonicalPath: "/p", description: "d", breadcrumb: true}, + breadcrumbs: [{name: "Home", url: "/"}], + }); + + seoService.emit({ + breadcrumbs: {append: [{name: "Sub", url: "/p/sub"}]}, + }); + + const graph = getGraph(document)!; + const bc = findNodeById(graph, "https://billgrokker.com/p#breadcrumb"); + const items = (bc?.itemListElement as Array<{item: {name: string}}>) ?? []; + expect(items.map(i => i.item.name)).toEqual(["Home", "Sub"]); + }); + + it("partial emit: omitted fields leave page-state untouched", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({title: "First", description: "First desc"}); + expect(document.title).toBe("First | Bill Grokker"); + expect((document.querySelector('meta[name="description"]') as HTMLMetaElement).content).toBe("First desc"); + + seoService.emit({title: "Second"}); + expect(document.title).toBe("Second | Bill Grokker"); + expect((document.querySelector('meta[name="description"]') as HTMLMetaElement).content).toBe("First desc"); + }); + + it("layered emit: wrapper appends keywords, page omits — wrapper persists alongside site defaults", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + const before = (document.querySelector('meta[name="keywords"]') as HTMLMetaElement).content; + expect(before).not.toContain("wrapper-tag"); + + seoService.emit({keywords: {append: ["wrapper-tag"]}}); + + seoService.emit({ + title: "Layered", + webPage: {canonicalPath: "/layered", description: "L"}, + }); + + const kw = (document.querySelector('meta[name="keywords"]') as HTMLMetaElement).content; + expect(kw.split(", ")).toContain("wrapper-tag"); + expect(kw.split(", ")).toContain("policy"); + const graph = getGraph(document)!; + expect(findNodeById(graph, "https://billgrokker.com/layered#webpage")).toBeDefined(); + }); + + it("emitting the same webPage twice with the same canonicalPath updates in place", () => { + seoService.initialize({rootUrl: "https://billgrokker.com"}); + seoService.emit({webPage: {canonicalPath: "/same", description: "v1"}}); + const graph1 = getGraph(document)!; + const node1 = findNodeById(graph1, "https://billgrokker.com/same#webpage") as {description: string} | undefined; + expect(node1?.description).toBe("v1"); + + seoService.emit({webPage: {canonicalPath: "/same", description: "v2"}}); + const graph2 = getGraph(document)!; + const node2 = findNodeById(graph2, "https://billgrokker.com/same#webpage") as {description: string} | undefined; + expect(node2?.description).toBe("v2"); + const sameIdNodes = graph2["@graph"].filter(n => n?.["@id"] === "https://billgrokker.com/same#webpage"); + expect(sameIdNodes).toHaveLength(1); + }); + }); +}); diff --git a/test/seo-specs.spec.ts b/test/seo-specs.spec.ts new file mode 100644 index 0000000..f753755 --- /dev/null +++ b/test/seo-specs.spec.ts @@ -0,0 +1,24 @@ +import {describe, expect, it} from "vitest"; +import {normalizeSeoDate} from "../src/index.js"; + +describe("normalizeSeoDate", () => { + it("appends UTC midnight to a date-only string", () => { + expect(normalizeSeoDate("2025-08-01")).toBe("2025-08-01T00:00:00+00:00"); + }); + + it("leaves a full timestamp unchanged", () => { + expect(normalizeSeoDate("2025-08-01T10:30:00+00:00")).toBe("2025-08-01T10:30:00+00:00"); + }); + + it("leaves a non-date string unchanged", () => { + expect(normalizeSeoDate("not-a-date")).toBe("not-a-date"); + }); + + it("matches the pattern without calendar validation", () => { + expect(normalizeSeoDate("2025-13-99")).toBe("2025-13-99T00:00:00+00:00"); + }); + + it("rejects single-digit month or day parts", () => { + expect(normalizeSeoDate("2025-8-01")).toBe("2025-8-01"); + }); +}); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..e4c016c --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "rootDir": "src" + }, + "include": ["src"], + "exclude": ["src/**/*.test.ts", "src/**/*.test-d.ts", "dist"] +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..617e529 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "outDir": "dist", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "exactOptionalPropertyTypes": true, + "verbatimModuleSyntax": true, + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "skipLibCheck": true + }, + "include": ["src", "vitest.config.ts"] +} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..647a9e5 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + environment: 'jsdom', + }, +});