@devalon.dev/credits 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -2
  3. package/dist/chunk-NG7NWZWD.mjs +16 -0
  4. package/dist/chunk-SHIXBOQB.mjs +1 -0
  5. package/dist/chunk-YBXS4SND.mjs +11 -0
  6. package/dist/core/agent-files.d.ts +46 -0
  7. package/dist/core/alternates.d.ts +4 -0
  8. package/dist/core/backlink.d.ts +43 -0
  9. package/dist/core/escape.d.ts +2 -0
  10. package/dist/core/headers.d.ts +34 -0
  11. package/dist/core/html.d.ts +27 -0
  12. package/dist/core/index.d.ts +13 -0
  13. package/dist/core/json-ld.d.ts +11 -0
  14. package/dist/core/url.d.ts +2 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +1 -0
  17. package/dist/index.mjs +1 -0
  18. package/dist/next/agent-files.d.ts +2 -0
  19. package/dist/next/alternates.d.ts +4 -0
  20. package/dist/next/backlink.d.ts +5 -0
  21. package/dist/next/headers.d.ts +2 -0
  22. package/dist/next/index.d.ts +14 -0
  23. package/dist/next/index.js +16 -0
  24. package/dist/next/index.mjs +1 -0
  25. package/dist/next/json-ld.d.ts +5 -0
  26. package/dist/next/schema.d.ts +1 -0
  27. package/dist/next/source.d.ts +12 -0
  28. package/dist/next/types.d.ts +1 -0
  29. package/dist/react/agent-files.d.ts +2 -0
  30. package/dist/react/alternates.d.ts +5 -0
  31. package/dist/react/backlink.d.ts +5 -0
  32. package/dist/react/headers.d.ts +2 -0
  33. package/dist/react/html.d.ts +2 -0
  34. package/dist/react/index.d.ts +15 -0
  35. package/dist/react/index.js +26 -0
  36. package/dist/react/index.mjs +1 -0
  37. package/dist/react/json-ld.d.ts +5 -0
  38. package/dist/react/schema.d.ts +1 -0
  39. package/dist/react/types.d.ts +1 -0
  40. package/dist/schema.d.ts +1183 -0
  41. package/dist/types.d.ts +75 -0
  42. package/dist/vite/index.d.ts +2 -0
  43. package/dist/vite/index.js +32 -0
  44. package/dist/vite/index.mjs +7 -0
  45. package/dist/vite/plugin.d.ts +51 -0
  46. package/docs/nextjs/01-app-router.md +101 -0
  47. package/docs/nextjs/02-app-router-i18n.md +166 -0
  48. package/docs/nextjs/03-pages-router.md +127 -0
  49. package/docs/nextjs/04-metadata-and-csp.md +113 -0
  50. package/docs/nextjs/05-performance-checklist.md +67 -0
  51. package/docs/nextjs/06-backlink-component.md +226 -0
  52. package/docs/nextjs/07-validator.md +55 -0
  53. package/docs/nextjs/08-server-headers.md +122 -0
  54. package/docs/nextjs/09-llms-and-humans-txt.md +163 -0
  55. package/docs/react/01-ssr-setup.md +112 -0
  56. package/docs/react/02-csr-vite.md +122 -0
  57. package/docs/react/03-i18n.md +104 -0
  58. package/docs/react/04-metadata-and-csp.md +105 -0
  59. package/docs/react/05-backlink-component.md +94 -0
  60. package/docs/react/06-server-headers.md +150 -0
  61. package/docs/react/07-agent-files.md +136 -0
  62. package/docs/react/08-validator.md +56 -0
  63. package/docs/react/09-performance-checklist.md +76 -0
  64. package/package.json +72 -4
  65. package/scripts/backlink.test.mjs +178 -0
  66. package/scripts/check-devalon-credits.mjs +175 -0
@@ -0,0 +1,122 @@
1
+ # 02 — CSR / Vite (build-time injection)
2
+
3
+ **When to read this:** your app is a client-side React SPA built with Vite, and you still want the credit in the **initial HTML** — not inserted after hydration.
4
+
5
+ A pure CSR app has no server at request time, so the only place to put metadata is the build output. `@devalon.dev/credits/vite` does exactly that: it transforms `index.html` during `vite build` and writes the identity and header files into the output directory. It also installs response-header middleware in `vite dev` / `vite preview`. Nothing ships to the browser — all plugin hooks run in Node.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @devalon.dev/credits
11
+ # vite is an optional peer; you already have it in a Vite project
12
+ ```
13
+
14
+ ## Setup
15
+
16
+ ```ts
17
+ // vite.config.ts
18
+ import { defineConfig } from "vite";
19
+ import react from "@vitejs/plugin-react";
20
+ import { devalonVite } from "@devalon.dev/credits/vite";
21
+
22
+ export default defineConfig({
23
+ plugins: [
24
+ react(),
25
+ devalonVite({
26
+ site_url: "https://example.com",
27
+ site_name: "Example Inc.",
28
+ in_language: "en",
29
+ page_url: "https://example.com/",
30
+ services: ["web_development", "ai_agents_automation"],
31
+ contributions: ["developing", "maintaining"],
32
+
33
+ alternates: {
34
+ canonical: "https://example.com/",
35
+ pages: {
36
+ en: "https://example.com/",
37
+ ro: "https://example.com/ro",
38
+ },
39
+ },
40
+
41
+ backlink: { locale: "ro" },
42
+ agentFilesConfig: {
43
+ description: "Custom CRM and booking platform for clinics.",
44
+ },
45
+ }),
46
+ ],
47
+ });
48
+ ```
49
+
50
+ After `vite build`:
51
+
52
+ ```
53
+ dist/index.html ← JSON-LD + canonical/hreflang in <head>, backlink before </body>
54
+ dist/llms.txt ← generated identity file
55
+ dist/humans.txt ← generated identity file
56
+ dist/_headers ← Devalon response headers for Netlify / Cloudflare Pages
57
+ ```
58
+
59
+ ## Plugin options
60
+
61
+ | Option | Required | Notes |
62
+ | --- | --- | --- |
63
+ | `site_url`, `site_name` | yes | Absolute canonical URL and client brand. Same config shape as `DevalonJsonLd`. |
64
+ | `in_language`, `page_url`, `services`, `contributions`, `custom_services` | no | Forwarded to the JSON-LD graph. |
65
+ | `alternates` | no | `devalon_alternates_config`: `canonical` + `pages`. Emits canonical/hreflang tags. |
66
+ | `nonce` | no | Added as the `nonce` attribute of the JSON-LD script. Useful for a strict CSP. |
67
+ | `backlink` | no | `devalon_backlink_props`. Omit it for a metadata-only integration. |
68
+ | `agentFiles` | no | Defaults to `true`. Set to `false` to skip writing `llms.txt` / `humans.txt`. |
69
+ | `agentFilesConfig` | no | Extra config for the identity files (`description`, `source`, …). Merged over the values above. |
70
+ | `humansSource` | no | Existing `humans.txt` text to merge into, when the client already has one. |
71
+ | `headers` | no | `true` by default: applies `devalonHeadersConfig()` as middleware in `vite dev` and `vite preview`. Pass `{ locale, localeFromPath }` to control the locale, or `false` to disable all header handling. |
72
+ | `headersFile` | no | `"_headers"` by default. `"vercel.json"`, `"all"` or `false` are also accepted. Written into `dist` at build. |
73
+
74
+ The plugin is **idempotent**: marked blocks are replaced on every build, so repeated builds never duplicate credits. `source` in `agentFilesConfig` is the client's own `llms.txt` text; the Devalon block is merged into it. Existing `_headers` / `vercel.json` content is preserved — see [06 — Server headers](06-server-headers.md).
75
+
76
+ ### Backlink source detection
77
+
78
+ UTM attribution is on by default for the injected backlink. The plugin reads the build environment and uses the **hostname only** as `utm_source`. Keys are checked in this order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths and ports are ignored, and invalid values are skipped. With no usable value the link stays clean — no build failure.
79
+
80
+ An explicit `backlink.site_url` always wins over detection, and `backlink: { utm: false }` still forces a clean link. Detection happens at build time, so the output stays a single static HTML document.
81
+
82
+ ## Without the plugin
83
+
84
+ `@devalon.dev/credits/react` exposes the pure transform if you prefer to wire your own build step:
85
+
86
+ ```ts
87
+ import { readFile, writeFile } from "node:fs/promises";
88
+ import { devalonAgentFiles, devalonInjectHtml } from "@devalon.dev/credits/react";
89
+
90
+ const html = await readFile("dist/index.html", "utf8");
91
+ await writeFile(
92
+ "dist/index.html",
93
+ devalonInjectHtml(html, {
94
+ site_url: "https://example.com",
95
+ site_name: "Example Inc.",
96
+ backlink: { locale: "en" },
97
+ }),
98
+ );
99
+
100
+ const files = devalonAgentFiles({
101
+ site_url: "https://example.com",
102
+ site_name: "Example Inc.",
103
+ });
104
+ // write files["llms.txt"] and files["humans.txt"] wherever you like
105
+ ```
106
+
107
+ ## Caveats
108
+
109
+ - `vite dev` applies the HTML transform and the header middleware, but it does **not** write files to `dist`. Inspect `dist/index.html` and `dist/_headers` after `yarn build` when verifying the production output.
110
+ - A static SPA has one HTML document for all routes. Use the site-level canonical URL, or generate one HTML per locale if you need per-language `hreflang`.
111
+ - The identity files are conventions, not ranking factors. They complement the JSON-LD and the visible credit — see [07 — Agent files](07-agent-files.md).
112
+
113
+ ## Verify
114
+
115
+ ```bash
116
+ yarn build
117
+ grep -o 'application/ld+json' dist/index.html
118
+ grep -o 'rel="canonical"' dist/index.html
119
+ grep -o 'https://devalon.dev' dist/index.html
120
+ grep -i devalon.dev dist/llms.txt dist/humans.txt
121
+ grep -i 'x-devalon' dist/_headers
122
+ ```
@@ -0,0 +1,104 @@
1
+ # 03 — Multi-language sites (ro / ru / en)
2
+
3
+ **When to read this:** the client site serves several languages and the credit must follow the active locale.
4
+
5
+ The package supports 7 locales: `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. You can use any subset — expose only the languages your app actually serves.
6
+
7
+ ## Two URLs, always distinct
8
+
9
+ - `site_url` — the canonical **site root**. It stays the same in every language.
10
+ - `page_url` — the canonical URL of the **localized page**. It changes with the language.
11
+
12
+ ```ts
13
+ const SITE_URL = "https://example.com";
14
+
15
+ const configFor = (locale: "ro" | "ru" | "en") => ({
16
+ site_url: SITE_URL,
17
+ site_name: "Example Inc.",
18
+ in_language: locale,
19
+ page_url: `${SITE_URL}/${locale}`,
20
+ services: ["web_development"] as const,
21
+ contributions: ["developing", "maintaining"] as const,
22
+ alternates: {
23
+ canonical: `${SITE_URL}/${locale}`,
24
+ pages: {
25
+ ro: `${SITE_URL}/ro`,
26
+ ru: `${SITE_URL}/ru`,
27
+ en: `${SITE_URL}/en`,
28
+ },
29
+ },
30
+ });
31
+ ```
32
+
33
+ `build_devalon_alternates()` (used by `DevalonAlternates` and `devalonAlternatesHtml`) only emits `hreflang` entries for languages present in `pages`, in the canonical locale order. Passing a subset is correct.
34
+
35
+ ## SSR with a per-locale route
36
+
37
+ ```tsx
38
+ // server/render.tsx — your router gives you the locale
39
+ import { devalonHeadHtml } from "@devalon.dev/credits/react";
40
+
41
+ export function render(locale: "ro" | "ru" | "en", appHtml: string) {
42
+ const config = configFor(locale);
43
+
44
+ return `<!doctype html>
45
+ <html lang="${locale}">
46
+ <head>${devalonHeadHtml(config)}<title>Example Inc.</title></head>
47
+ <body><div id="root">${appHtml}</div></body>
48
+ </html>`;
49
+ }
50
+ ```
51
+
52
+ Render the visible backlink with the same locale:
53
+
54
+ ```tsx
55
+ import { DevalonBacklink } from "@devalon.dev/credits/react";
56
+
57
+ <DevalonBacklink locale={locale} />
58
+ ```
59
+
60
+ The detected source is site-wide and identical in every language — only the hostname becomes `utm_source`, so a different root would split your referral data. If you pass `site_url` explicitly, keep it identical across locales.
61
+
62
+ ## Per-request headers
63
+
64
+ For SSR frameworks, attach the locale to the response:
65
+
66
+ ```ts
67
+ import { withDevalonHeaders } from "@devalon.dev/credits/react";
68
+
69
+ const response = new Response(html, {
70
+ headers: { "Content-Type": "text/html; charset=utf-8" },
71
+ });
72
+
73
+ withDevalonHeaders(response, {
74
+ site_url: SITE_URL,
75
+ locale,
76
+ services: ["web_development"],
77
+ contributions: ["developing", "maintaining"],
78
+ });
79
+ ```
80
+
81
+ See [06 — Server headers](06-server-headers.md) for Express / CDN variants.
82
+
83
+ ## Built-in backlink sentences
84
+
85
+ | locale | sentence |
86
+ | --- | --- |
87
+ | `en` | Designed and built by |
88
+ | `ro` | Proiectat și realizat de |
89
+ | `ru` | Дизайн и разработка от |
90
+ | `de` | Entworfen und entwickelt von |
91
+ | `da` | Designet og udviklet af |
92
+ | `fr` | Conçu et développé par |
93
+ | `es` | Diseñado y desarrollado por |
94
+
95
+ Override any of them with `sentence`, or pass `anchor` to change the link text.
96
+
97
+ ## Common mistakes
98
+
99
+ | Don't | Do |
100
+ | --- | --- |
101
+ | Change `site_url` per language. | Keep it constant; change `page_url` and `alternates.canonical`. |
102
+ | Emit hreflang for languages the site does not serve. | Pass only the real pages in `alternates.pages`. |
103
+ | Render the credit in every page component. | Render once per URL, in the shared layout/header. |
104
+ | Pass an arbitrary string as `locale`. | Use one of the 7 supported codes; invalid values throw `TypeError`. |
@@ -0,0 +1,105 @@
1
+ # 04 — Metadata (canonical / hreflang) and CSP nonce
2
+
3
+ **When to read this:** you want canonical and `hreflang` links next to the attribution, or your site has a strict Content Security Policy that only allows inline scripts with a nonce.
4
+
5
+ ## The data helper
6
+
7
+ `build_devalon_alternates()` is shared with the Next.js entry. It validates and normalizes URLs (trailing slashes, query strings and hashes are removed):
8
+
9
+ ```ts
10
+ import { build_devalon_alternates } from "@devalon.dev/credits/react";
11
+
12
+ const { canonical, languages } = build_devalon_alternates({
13
+ canonical: "https://example.com/ro",
14
+ pages: {
15
+ ro: "https://example.com/ro",
16
+ ru: "https://example.com/ru",
17
+ en: "https://example.com/en",
18
+ },
19
+ });
20
+ // canonical: "https://example.com/ro"
21
+ // languages: { en: "https://example.com/en", ro: "https://example.com/ro", ru: "https://example.com/ru" }
22
+ ```
23
+
24
+ ## Declarative: `DevalonAlternates`
25
+
26
+ ```tsx
27
+ import { DevalonAlternates } from "@devalon.dev/credits/react";
28
+
29
+ <DevalonAlternates
30
+ canonical="https://example.com/ro"
31
+ pages={{
32
+ ro: "https://example.com/ro",
33
+ ru: "https://example.com/ru",
34
+ en: "https://example.com/en",
35
+ }}
36
+ />
37
+ ```
38
+
39
+ It renders `<link rel="canonical">` and one `<link rel="alternate" hreflang="…">` per provided language. With a head manager (or React 19 hoisting in a supported SSR setup), place it anywhere in the tree. If `curl` does not show the tags in the server HTML, use the explicit form below.
40
+
41
+ ## Explicit: `devalonAlternatesHtml` / `devalonHeadHtml`
42
+
43
+ ```ts
44
+ import { devalonHeadHtml, devalonAlternatesHtml } from "@devalon.dev/credits/react";
45
+
46
+ // Only the links, as a string:
47
+ const links = devalonAlternatesHtml({
48
+ canonical: "https://example.com/ro",
49
+ pages: { ro: "https://example.com/ro", en: "https://example.com/en" },
50
+ });
51
+
52
+ // JSON-LD + links together (recommended for a custom <head>):
53
+ const head = devalonHeadHtml({
54
+ site_url: "https://example.com",
55
+ site_name: "Example Inc.",
56
+ in_language: "ro",
57
+ page_url: "https://example.com/ro",
58
+ services: ["web_development"],
59
+ alternates: {
60
+ canonical: "https://example.com/ro",
61
+ pages: { ro: "https://example.com/ro", en: "https://example.com/en" },
62
+ },
63
+ });
64
+ ```
65
+
66
+ `devalonHeadHtml()` escapes all attributes and JSON-LD content. The JSON-LD serializer additionally converts `<`, `>`, `&`, U+2028 and U+2029 to Unicode escapes, so the script cannot break out of its element.
67
+
68
+ ## CSP nonce
69
+
70
+ If your CSP uses `script-src 'self' 'nonce-…'`, pass the **per-request** nonce:
71
+
72
+ ```tsx
73
+ // Declarative
74
+ <DevalonJsonLd nonce={nonce} site_url="https://example.com" site_name="Example Inc." />
75
+ ```
76
+
77
+ ```ts
78
+ // Explicit server head
79
+ devalonHeadHtml({
80
+ site_url: "https://example.com",
81
+ site_name: "Example Inc.",
82
+ nonce,
83
+ });
84
+ // -> <script type="application/ld+json" nonce="…">…</script>
85
+ ```
86
+
87
+ A hardcoded build-time nonce defeats the purpose of a CSP. Note that reading request headers to obtain the nonce makes that route dynamically rendered — use a nonce only when the CSP requires it.
88
+
89
+ ## Do not duplicate tags
90
+
91
+ If a framework head manager already emits canonical/hreflang, pick **one** source:
92
+
93
+ - Framework-managed → use `DevalonAlternates` (or your own `<link>` tags) and omit `alternates` from `devalonHeadHtml()`.
94
+ - Custom server template → `devalonHeadHtml({ ..., alternates })` and no declarative component.
95
+
96
+ Duplicate `<link rel="canonical">` is ambiguous to crawlers; duplicate JSON-LD graphs waste parse time.
97
+
98
+ ## Verify
99
+
100
+ ```bash
101
+ curl -s http://localhost:3000/ro | grep -o 'rel="canonical"[^>]*'
102
+ curl -s http://localhost:3000/ro | grep -o 'hreflang="[a-z]*"'
103
+ curl -sI http://localhost:3000/ro | grep -i content-security-policy
104
+ curl -s http://localhost:3000/ro | grep -o '<script[^>]*application/ld+json[^>]*>'
105
+ ```
@@ -0,0 +1,94 @@
1
+ # 05 — Backlink component (visible credit link)
2
+
3
+ **When to read this:** you want a visible credit on the client site that sends a clean `follow` link back to `devalon.dev`.
4
+
5
+ `DevalonBacklink` is the visible counterpart of the JSON-LD: crawlers read the graph, people read the link. It renders plain HTML — no JavaScript, no image, no hydration.
6
+
7
+ ## Declarative usage
8
+
9
+ ```tsx
10
+ import { DevalonBacklink } from "@devalon.dev/credits/react";
11
+
12
+ export function Footer() {
13
+ return (
14
+ <footer>
15
+ <DevalonBacklink locale="ro" />
16
+ </footer>
17
+ );
18
+ }
19
+ ```
20
+
21
+ Rendered HTML:
22
+
23
+ ```html
24
+ <span>Proiectat și realizat de
25
+ <a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
26
+ </span>
27
+ ```
28
+
29
+ It also works as a plain server-rendered element in any React setup. It does not need a `"use client"` boundary.
30
+
31
+ ## Explicit HTML string
32
+
33
+ When the body of your document is assembled as a string (custom SSR template, static site, CDN worker):
34
+
35
+ ```ts
36
+ import { devalonBacklinkHtml } from "@devalon.dev/credits/react";
37
+
38
+ const credit = devalonBacklinkHtml({ locale: "ro", className: "credit" });
39
+ // <span class="credit">Proiectat și realizat de <a href="https://devalon.dev" ...>Devalon</a></span>
40
+ ```
41
+
42
+ Or inject it automatically with `devalonInjectHtml(html, { ..., backlink: { locale: "ro" } })` — see [01 — SSR setup](01-ssr-setup.md) and [02 — CSR / Vite](02-csr-vite.md).
43
+
44
+ ## Props
45
+
46
+ | Prop | Required | Notes |
47
+ | --- | --- | --- |
48
+ | `site_url` | no | Absolute http(s) URL of the client site. Only its hostname is used, for `utm_source`; `www.` is stripped. Auto-detected when omitted. Invalid explicit URLs throw a `TypeError`. |
49
+ | `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
50
+ | `sentence` | no | Overrides the built-in sentence. Must not be empty. |
51
+ | `anchor` | no | Visible link text. Defaults to `Devalon`. Must not be empty. |
52
+ | `utm` | no | Appends `utm_source` / `utm_medium` / `utm_campaign`. Defaults to **true**. With no detectable source the link stays clean instead of throwing. Pass `false` to force a clean link. |
53
+ | `className` | no | Your class for the wrapper `<span>`. The component ships no CSS. |
54
+
55
+ ## UTM attribution (on by default)
56
+
57
+ `utm` defaults to `true`. In Node SSR and HTML-string helpers the source is detected from `process.env`; in the browser there is no server environment, so the Vite plugin bakes the source into the HTML at build time. Only the hostname is used:
58
+
59
+ ```tsx
60
+ <DevalonBacklink />
61
+ // with SITE_URL=https://example.com/ro in the build environment:
62
+ // https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
63
+ ```
64
+
65
+ Env keys, in priority order: `NEXT_PUBLIC_SITE_URL`, `SITE_URL`, `VITE_SITE_URL`, `VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`. Bare hostnames are accepted, paths are ignored, invalid values are skipped. An explicit `site_url` wins over detection. With no detectable source the link stays clean. UTM does not change the destination page or the value of the backlink.
66
+
67
+ Use `detect_site_url(env)` from either entrypoint to inspect what would be detected for a given env object.
68
+
69
+ ## Quality rules
70
+
71
+ - It is a **credit / relationship link**: discovery, brand consistency, referral traffic. Not a commercial keyword ranking lever.
72
+ - Keep it a normal `follow` link: `rel="noopener"`, never `noreferrer`, `nofollow` or `sponsored` for a genuine credit.
73
+ - Keep it visibly readable. Hidden or 1px text can be treated as spam.
74
+ - Render it once, in the shared footer/layout, not in every page component.
75
+ - Do not create the link with `useEffect` / `document.createElement`; it must be in the initial HTML.
76
+
77
+ ## Common mistakes
78
+
79
+ | Don't | Do |
80
+ | --- | --- |
81
+ | `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
82
+ | `rel="nofollow"` for a genuine credit | Leave it a follow link. |
83
+ | `display:none`, white-on-white | Keep the text visibly readable. |
84
+ | Expect UTM with no environment source set | Set a build-time env var, or accept the clean link. |
85
+ | Pass a relative `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
86
+ | Put the credit on a `noindex` staging site | Run the validator first — [08 — Validator](08-validator.md). |
87
+
88
+ ## Verify
89
+
90
+ ```bash
91
+ curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
92
+ curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
93
+ curl -s http://localhost:3000/ | grep -o 'https://devalon.dev' | wc -l # expect 1 in the body credit
94
+ ```
@@ -0,0 +1,150 @@
1
+ # 06 — Server utility: Devalon response headers
2
+
3
+ **When to read this:** you want `curl -I` (or your CDN, audit tooling, validator) to state who built the site, without adding React code.
4
+
5
+ This is a **server utility**, not a component. There is no JSX, no `"use client"`, no hydration. `devalonHeadersConfig()` returns plain `{ key, value }` pairs; `withDevalonHeaders()` writes them onto any object exposing a mutable `Headers` instance.
6
+
7
+ ## Express / Node
8
+
9
+ ```ts
10
+ import express from "express";
11
+ import { devalonHeadersMiddleware } from "@devalon.dev/credits/react";
12
+
13
+ const app = express();
14
+ const devalonConfig = {
15
+ site_url: "https://example.com",
16
+ services: ["web_development", "ai_agents_automation"] as const,
17
+ contributions: ["developing", "maintaining"] as const,
18
+ };
19
+
20
+ app.use(devalonHeadersMiddleware(devalonConfig));
21
+ ```
22
+
23
+ `devalonHeadersMiddleware()` is framework-agnostic: it only needs `req.url`, `res.getHeader()` and `res.setHeader()`. It detects the locale from the first path segment when you pass `localeFromPath: ["ro", "ru", "en"]`, and it **appends** to an existing `Link` header instead of overwriting it.
24
+
25
+ Or mutate a `Response` directly:
26
+
27
+ ```ts
28
+ import { withDevalonHeaders } from "@devalon.dev/credits/react";
29
+
30
+ const response = new Response(html, {
31
+ headers: { "Content-Type": "text/html; charset=utf-8" },
32
+ });
33
+
34
+ withDevalonHeaders(response, { ...devalonConfig, locale: "ro" });
35
+ ```
36
+
37
+ ## Automatic with the Vite plugin
38
+
39
+ `devalonVite()` handles all three environments from one config:
40
+
41
+ ```ts
42
+ // vite.config.ts
43
+ import { defineConfig } from "vite";
44
+ import { devalonVite } from "@devalon.dev/credits/vite";
45
+
46
+ export default defineConfig({
47
+ plugins: [
48
+ devalonVite({
49
+ site_url: "https://example.com",
50
+ site_name: "Example Inc.",
51
+ services: ["web_development"],
52
+ in_language: "en",
53
+
54
+ // dev + preview responses
55
+ headers: { localeFromPath: ["ro", "ru", "en"] },
56
+ // static production output
57
+ headersFile: "_headers", // or "vercel.json", "all", false
58
+ }),
59
+ ],
60
+ });
61
+ ```
62
+
63
+ | Setting | Effect |
64
+ | --- | --- |
65
+ | `headers` | `true` (default) installs middleware in `vite dev` and `vite preview`. `false` disables all header handling. An object sets a fixed `locale` and/or `localeFromPath`. |
66
+ | `headersFile` | `"_headers"` (default) writes a Netlify / Cloudflare Pages file; `"vercel.json"` writes Vercel config; `"all"` writes both; `false` skips it. |
67
+ | `in_language` | Used as the fixed `X-Devalon-Locale` when `localeFromPath` is not set. |
68
+
69
+ `localeFromPath` reads the first path segment (`/ro/page` → `ro`) per request. For a static SPA with no per-locale paths, use `headers: { locale: "ro" }` or rely on `in_language`.
70
+
71
+ The plugin **merges, never clobbers**: an existing `_headers` keeps its own rules (only the `# devalon:start/end` block is replaced), and an existing `vercel.json` keeps its rewrites/other header entries while the previous Devalon entry is removed. Repeated builds are identical.
72
+
73
+ ### Manual Vite config (without the plugin)
74
+
75
+ ```ts
76
+ import { defineConfig } from "vite";
77
+ import { devalonHeadersConfig } from "@devalon.dev/credits/react";
78
+
79
+ export default defineConfig({
80
+ server: {
81
+ headers: Object.fromEntries(
82
+ devalonHeadersConfig({ site_url: "https://example.com" }).map(
83
+ ({ key, value }) => [key, value],
84
+ ),
85
+ ),
86
+ },
87
+ });
88
+ ```
89
+
90
+ ## Headers emitted
91
+
92
+ ```
93
+ X-Devalon-Creator: Devalon
94
+ X-Devalon-Creator-Url: https://devalon.dev
95
+ X-Devalon-Creator-Id: https://devalon.dev/#organization
96
+ X-Devalon-Project: https://example.com
97
+ X-Devalon-Services: web_development, ai_agents_automation
98
+ X-Devalon-Contributions: developing, maintaining
99
+ X-Devalon-Relationships: creator, provider
100
+ X-Devalon-Locale: ro
101
+ X-Built-By: Devalon (https://devalon.dev)
102
+ Link: <https://devalon.dev>; rel="author"
103
+ ```
104
+
105
+ - `Services` are canonicalized: legacy aliases resolve to the current key, duplicates are removed.
106
+ - `Relationships` come from the same contribution mapping as the JSON-LD graph (`creator` / `maintainer` / `provider`).
107
+ - `X-Devalon-Locale` is emitted only when `locale` is provided; all 7 supported languages are accepted.
108
+ - Empty `services`, `contributions` or resolved relationships omit their respective header. `contributions` defaults to `["development", "engineering"]`.
109
+ - All values are ASCII, so `Headers` never rejects diacritics. The client name lives in the JSON-LD, not in headers.
110
+ - `withDevalonHeaders()` **appends** the `Link` header to any existing `Link` value instead of overwriting it.
111
+ - `X-Built-By` contains no framework/runtime versions — no stack fingerprinting.
112
+
113
+ ## What this is — and is not
114
+
115
+ - ✅ Operational metadata: instant provenance via `curl -I`, project inventory, audit and CDN debugging.
116
+ - ❌ **Not an SEO ranking factor.** Google ignores custom `X-` headers. They do not replace the JSON-LD or the visible credit.
117
+
118
+ ## CDN caveat
119
+
120
+ Vercel, Cloudflare, Coolify or a reverse proxy can rewrite or strip custom headers. After deployment, verify on the real URL:
121
+
122
+ ```bash
123
+ curl -sI https://client.com/ | grep -iE 'x-devalon|x-built-by|^link'
124
+ ```
125
+
126
+ If a header is missing, the platform is filtering it — not the code. The JSON-LD and the visible credit are not affected.
127
+
128
+ ## Common mistakes
129
+
130
+ | Don't | Do |
131
+ | --- | --- |
132
+ | Expect headers to affect rankings. | Use `DevalonJsonLd` / `devalonHeadHtml` for entity signals. |
133
+ | Pass a relative `site_url`. | Pass an absolute `https://...` URL. |
134
+ | Put a client name with diacritics in a header. | Keep it in JSON-LD; headers carry ASCII identifiers only. |
135
+ | Overwrite an existing `Link` header. | Use `withDevalonHeaders()` / `devalonHeadersMiddleware()`, which append. |
136
+ | Expect `vite dev` to read `_headers`. | The file is for production hosts; dev/preview use the middleware. |
137
+
138
+ ## Verify
139
+
140
+ ```bash
141
+ # SSR server / vite dev / vite preview
142
+ curl -sI http://localhost:3000/ | grep -i '^x-devalon'
143
+ curl -sI http://localhost:5173/ro | grep -i 'x-devalon-locale'
144
+
145
+ # static output before deploying
146
+ grep -i 'x-devalon' dist/_headers
147
+ grep -i 'X-Devalon' dist/vercel.json
148
+
149
+ yarn check:credits https://client.com --deployed
150
+ ```