@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,226 @@
1
+ # 06 — 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 `DevalonJsonLd`: the JSON-LD script tells crawlers who built the project, this link confirms it for people and brings referral traffic.
6
+
7
+ ## Minimal example (App Router)
8
+
9
+ ```tsx
10
+ // app/layout.tsx (or app/[locale]/layout.tsx)
11
+ import { DevalonBacklink } from "@devalon.dev/credits/next";
12
+
13
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
14
+ return (
15
+ <html lang="en">
16
+ <body>
17
+ {children}
18
+
19
+ <footer>
20
+ <DevalonBacklink />
21
+ </footer>
22
+ </body>
23
+ </html>
24
+ );
25
+ }
26
+ ```
27
+
28
+ Rendered HTML:
29
+
30
+ ```html
31
+ <span>Designed and built by
32
+ <a href="https://devalon.dev" target="_blank" rel="noopener" referrerpolicy="origin">Devalon</a>
33
+ </span>
34
+ ```
35
+
36
+ No JavaScript, no image, no hydration. The link is in the static HTML, so crawlers see it without executing anything. When a source is detected the `href` gains UTM parameters (see below); with no source it stays clean.
37
+
38
+ ## Props
39
+
40
+ | Prop | Required | Notes |
41
+ | --- | --- | --- |
42
+ | `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`. |
43
+ | `locale` | no | One of `en`, `ro`, `ru`, `de`, `da`, `fr`, `es`. Selects the built-in sentence. Defaults to `en`. |
44
+ | `sentence` | no | Overrides the built-in sentence. Must not be empty. |
45
+ | `anchor` | no | Visible link text. Defaults to the brand name `Devalon`. Must not be empty. |
46
+ | `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. |
47
+ | `className` | no | Your own class for the wrapper `<span>`. The component ships no CSS. |
48
+
49
+ Built-in sentences:
50
+
51
+ | locale | sentence |
52
+ | --- | --- |
53
+ | `en` | Designed and built by |
54
+ | `ro` | Proiectat și realizat de |
55
+ | `ru` | Дизайн и разработка от |
56
+ | `de` | Entworfen und entwickelt von |
57
+ | `da` | Designet og udviklet af |
58
+ | `fr` | Conçu et développé par |
59
+ | `es` | Diseñado y desarrollado por |
60
+
61
+ Prefer the longer wording? Pass it explicitly, e.g. `sentence="Acest site a fost proiectat și construit de"`.
62
+
63
+ ## Any subset of the 7 languages
64
+
65
+ Your site can expose 3 of the 7 languages and pass the validated value straight through:
66
+
67
+ ```tsx
68
+ // app/[locale]/layout.tsx
69
+ import { DevalonBacklink } from "@devalon.dev/credits/next";
70
+ import { notFound } from "next/navigation";
71
+ import { isLocale } from "@/lib/i18n"; // your subset: ["ro", "ru", "en"]
72
+
73
+ export default async function LocaleLayout({
74
+ params,
75
+ children,
76
+ }: {
77
+ params: Promise<{ locale: string }>;
78
+ children: React.ReactNode;
79
+ }) {
80
+ const { locale } = await params;
81
+ if (!isLocale(locale)) notFound();
82
+
83
+ return (
84
+ <html lang={locale}>
85
+ <body>
86
+ {children}
87
+ <footer>
88
+ <DevalonBacklink locale={locale} />
89
+ </footer>
90
+ </body>
91
+ </html>
92
+ );
93
+ }
94
+ ```
95
+
96
+ `Locale` from your type guard is a subset of `devalon_locale`, so no cast is needed. The auto-detected source is site-wide, so it is identical in all languages.
97
+
98
+ ## UTM attribution (on by default)
99
+
100
+ `utm` defaults to `true`. The component reads the build-time environment and uses the **hostname only** as `utm_source`:
101
+
102
+ ```bash
103
+ # .env.local / deployment env
104
+ NEXT_PUBLIC_SITE_URL=https://example.com
105
+ # -> https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits
106
+ ```
107
+
108
+ `NEXT_PUBLIC_SITE_URL` is recommended because Next.js inlines it into both the server and client bundles, so auto-detection never causes a hydration mismatch. The generic `SITE_URL` and platform variables (`VERCEL_PROJECT_PRODUCTION_URL`, `CF_PAGES_URL`, `VERCEL_URL`) are used by the Vite plugin and by HTML-string helpers. Bare hostnames are accepted; paths are ignored. Invalid values are skipped.
109
+
110
+ With **no** detectable source the link stays clean — `https://devalon.dev` — and nothing throws. Pass `utm={false}` to force a clean link even when a source exists. An explicit `site_url` always wins over detection. The parameters do not change the destination page and do not affect the value of the backlink.
111
+
112
+ ### Live host detection (opt-in, makes the route dynamic)
113
+
114
+ If you need the request host rather than a build-time value, read it yourself and pass it in. This opts the layout into dynamic rendering, so only do it where that trade-off is acceptable:
115
+
116
+ ```tsx
117
+ import { headers } from "next/headers";
118
+ import {
119
+ DevalonBacklink,
120
+ devalonBacklinkSiteUrlFromHeaders,
121
+ } from "@devalon.dev/credits/next";
122
+
123
+ export default async function Footer() {
124
+ const site_url = devalonBacklinkSiteUrlFromHeaders(await headers());
125
+ return <DevalonBacklink site_url={site_url} />;
126
+ }
127
+ ```
128
+
129
+ The helper returns `undefined` when no usable host is present, which again yields a clean link.
130
+
131
+ ## Combine it with the JSON-LD component
132
+
133
+ Use one source of truth for `site_url` in the JSON-LD; the visible credit detects its own source from the environment and stays in agreement:
134
+
135
+ ```tsx
136
+ import { DevalonBacklink, DevalonJsonLd } from "@devalon.dev/credits/next";
137
+
138
+ const SITE_URL = "https://example.com";
139
+ const SITE_NAME = "Example Inc.";
140
+
141
+ <DevalonJsonLd
142
+ site_url={SITE_URL}
143
+ site_name={SITE_NAME}
144
+ in_language="en"
145
+ page_url={`${SITE_URL}/`}
146
+ services={["web_development"]}
147
+ contributions={["developing", "maintaining"]}
148
+ />
149
+
150
+ <footer>
151
+ <DevalonBacklink />
152
+ </footer>
153
+ ```
154
+
155
+ The JSON-LD renders a `<script>`; the backlink renders an `<a>`. They are independent and can live in different files. Set `NEXT_PUBLIC_SITE_URL` to the same value so the detected backlink source agrees with `SITE_URL` (or pass `site_url={SITE_URL}` to the backlink explicitly).
156
+
157
+ ## Pages Router
158
+
159
+ ```tsx
160
+ // pages/_app.tsx
161
+ import type { AppProps } from "next/app";
162
+ import { DevalonBacklink } from "@devalon.dev/credits/next";
163
+
164
+ export default function App({ Component, pageProps }: AppProps) {
165
+ return (
166
+ <>
167
+ <Component {...pageProps} />
168
+ <footer>
169
+ <DevalonBacklink locale="ro" />
170
+ </footer>
171
+ </>
172
+ );
173
+ }
174
+ ```
175
+
176
+ There is no effect, state or extra JS emitted by the component itself.
177
+
178
+ ## What this link does and does not do
179
+
180
+ - It is a **credit / relationship link**: discovery, brand awareness, entity consistency and referral traffic.
181
+ - It does **not** replace topical backlinks from sites in your niche, and it is not a ranking lever for commercial keywords.
182
+ - Keep it a normal `follow` link: `rel="noopener"`, never `noreferrer`, never `nofollow` or `sponsored` for a genuine credit.
183
+ - Keep it visibly readable. Hidden or tiny links carry no value and can be treated as spam.
184
+
185
+ ## Quality gate before deploying
186
+
187
+ Only put the credit on sites that are live, indexed and have real traffic. Run the validator before each deployment:
188
+
189
+ ```bash
190
+ yarn check:credits https://client.com
191
+ yarn check:credits https://client.com --deployed # after deployment
192
+ ```
193
+
194
+ See [07 — Credit link validator](07-validator.md).
195
+
196
+ If no source is detectable and the link stays clean, create a GA4 **Custom channel group** named `Partner credits` with the rule *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). Clean links, clean reporting.
197
+
198
+ ## Performance rules
199
+
200
+ - Render once in the layout footer, not repeated in every page component.
201
+ - Do not add `"use client"` to the rendering file to style it — use `className`.
202
+ - Do not inject the link with `useEffect` / `document.createElement`; it must exist in the initial HTML.
203
+ - Do not load a remote logo image — that would add a request and a `remotePatterns` config. Text-only is intentional.
204
+ - The output is computed at render time from static props plus build-time env, so static generation bakes it into the HTML. Avoid `cookies()` / `headers()` in that layout; the opt-in live-host helper above is the one exception and makes that route dynamic.
205
+
206
+ ## Common mistakes
207
+
208
+ | Don't | Do |
209
+ | --- | --- |
210
+ | `rel="noopener noreferrer"` | `rel="noopener"` only — `noreferrer` kills referral data. |
211
+ | `rel="nofollow"` / `rel="sponsored"` for a genuine credit | Leave it a follow link. |
212
+ | `display:none`, `font-size:1px`, white-on-white | Keep the text visibly readable. |
213
+ | Expect UTM with no environment source set | Set `NEXT_PUBLIC_SITE_URL`, or accept the clean link. |
214
+ | Pass a relative URL like `/despre` as `site_url` | Pass an absolute `https://...` URL, or let detection supply it. |
215
+ | Put the credit on a staging or `noindex` site | Run the validator first. |
216
+
217
+ ## Verify
218
+
219
+ ```bash
220
+ yarn build
221
+ curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
222
+ curl -s http://localhost:3000/ro | grep -o 'Proiectat și realizat de'
223
+ curl -s http://localhost:3000/ru | grep -o 'Дизайн и разработка от'
224
+ # With NEXT_PUBLIC_SITE_URL set, expect an attributed link:
225
+ curl -s http://localhost:3000/ | grep -o 'utm_source=example.com'
226
+ ```
@@ -0,0 +1,55 @@
1
+ # 07 — Credit link validator
2
+
3
+ **When to read this:** before adding a Devalon credit link to a client site, and again after deployment.
4
+
5
+ A credit link on a dead, blocked or unindexed site sends no traffic and adds no signal. This script catches that before you ship.
6
+
7
+ ## Run it
8
+
9
+ ```bash
10
+ yarn check:credits https://client.com
11
+ ```
12
+
13
+ After deployment, also verify that the link and the JSON-LD are actually in the served HTML:
14
+
15
+ ```bash
16
+ yarn check:credits https://client.com --deployed
17
+ ```
18
+
19
+ From an installed package, the same tool is available as:
20
+
21
+ ```bash
22
+ npx devalon-check https://client.com --deployed
23
+ ```
24
+
25
+ ## What it checks
26
+
27
+ | Check | Result |
28
+ | --- | --- |
29
+ | URL is absolute http(s) | error → stop |
30
+ | Site responds with HTTP 2xx/3xx | error if not |
31
+ | No `<meta name="robots" content="noindex">` (also `googlebot`) | error if present |
32
+ | `robots.txt` does not `Disallow: /` for `User-agent: *` | error if blocked |
33
+ | `/sitemap.xml` exists and is a urlset/sitemapindex | warning if missing |
34
+ | With `--deployed`: `devalon.dev` link present in raw HTML | error if missing |
35
+ | With `--deployed`: `application/ld+json` present in raw HTML | error if missing |
36
+ | With `--deployed`: `X-Devalon-Creator` / `X-Devalon-Project` headers | warning if missing (headers are optional) |
37
+ | With `--deployed`: `X-Built-By` and `Link: rel="author"` | warning if missing |
38
+ | With `--deployed`: `/llms.txt` exists and mentions Devalon | warning if missing |
39
+
40
+ Exit code is `1` if any error was found, `0` otherwise. Warnings do not fail the check.
41
+
42
+ ## Interpreting failures
43
+
44
+ - **HTTP error** — the site is down, behind auth, or blocks automated clients. Confirm manually in a browser.
45
+ - **noindex** — remove it or choose another page; search engines will not index the credit link.
46
+ - **robots.txt disallows /** — a credit link there will never be crawled.
47
+ - **No sitemap** — add one; the credit page is still crawlable via links, but discovery is slower.
48
+ - **No devalon.dev link with `--deployed`** — the component was not rendered on this URL, or the HTML is generated only on the client (never inject the credit with `useEffect`).
49
+ - **No JSON-LD with `--deployed`** — `DevalonJsonLd` is missing from the layout, or the page was rendered dynamically in a way that strips the script.
50
+
51
+ ## Good-to-know
52
+
53
+ - The script is dependency-free and uses Node's built-in `fetch` (Node 18+).
54
+ - Requests time out after 10 seconds.
55
+ - It does not modify any files and does not send data anywhere.
@@ -0,0 +1,122 @@
1
+ # 08 — 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 and in what language, without adding any React code.
4
+
5
+ This is a **server utility**, not a component. It writes HTTP response headers to a `Response` / `NextResponse`. There is no JSX, no `"use client"`, no hydration.
6
+
7
+ ## Middleware (recommended for multi-language sites)
8
+
9
+ ```ts
10
+ // middleware.ts
11
+ import { NextResponse, type NextRequest } from "next/server";
12
+ import { withDevalonHeaders } from "@devalon.dev/credits/next";
13
+
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
+ export function middleware(request: NextRequest) {
21
+ const response = NextResponse.next();
22
+ const segment = request.nextUrl.pathname.split("/")[1]; // ro | ru | en
23
+ const locale = ["ro", "ru", "en"].includes(segment)
24
+ ? (segment as "ro" | "ru" | "en")
25
+ : "en";
26
+
27
+ return withDevalonHeaders(response, { ...devalonConfig, locale });
28
+ }
29
+
30
+ // Next.js requires this exact export name for middleware configuration.
31
+ export const config = {
32
+ matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
33
+ };
34
+ ```
35
+
36
+ The `matcher` keeps middleware away from static assets, so the extra work happens only on page requests.
37
+
38
+ ## Static alternative (`next.config.ts`)
39
+
40
+ If you do not need the locale per request, skip middleware entirely:
41
+
42
+ ```ts
43
+ import { devalonHeadersConfig } from "@devalon.dev/credits/next";
44
+
45
+ export default {
46
+ async headers() {
47
+ return [
48
+ {
49
+ source: "/:path*",
50
+ headers: devalonHeadersConfig({
51
+ site_url: "https://example.com",
52
+ services: ["web_development"],
53
+ contributions: ["developing", "maintaining"],
54
+ }),
55
+ },
56
+ ];
57
+ },
58
+ };
59
+ ```
60
+
61
+ Zero runtime cost — the headers are baked into the framework config at build time. The tradeoff: no `X-Devalon-Locale` per page.
62
+
63
+ ## Headers emitted
64
+
65
+ ```
66
+ X-Devalon-Creator: Devalon
67
+ X-Devalon-Creator-Url: https://devalon.dev
68
+ X-Devalon-Creator-Id: https://devalon.dev/#organization
69
+ X-Devalon-Project: https://example.com
70
+ X-Devalon-Services: web_development, ai_agents_automation
71
+ X-Devalon-Contributions: developing, maintaining
72
+ X-Devalon-Relationships: creator, provider
73
+ X-Devalon-Locale: ro
74
+ X-Built-By: Devalon (https://devalon.dev)
75
+ Link: <https://devalon.dev>; rel="author"
76
+ ```
77
+
78
+ - `Services` are canonicalized: legacy aliases resolve to the current key, duplicates are removed.
79
+ - `Relationships` come from the same contribution mapping used by the JSON-LD graph (`creator` / `maintainer` / `provider`).
80
+ - `X-Devalon-Locale` is emitted only when `locale` is provided; it accepts all 7 supported languages (`en`, `ro`, `ru`, `de`, `da`, `fr`, `es`).
81
+ - Empty `services`, `contributions` or resolved relationships omit their respective header. `contributions` defaults to `["development", "engineering"]`.
82
+ - All values are ASCII (URLs, keys, locales) so `Headers` never rejects diacritics. The client name lives in the JSON-LD, not in headers.
83
+ - `X-Built-By` is a plain custom header: brand plus URL, no framework/runtime versions, so it does not add stack fingerprinting.
84
+ - `Link: <https://devalon.dev>; rel="author"` uses a registered link relation (Web Linking). In middleware, `withDevalonHeaders` **appends** it to any existing `Link` header instead of overwriting it. With the static `next.config.ts` variant, keep this in mind if you already set `Link` headers.
85
+ - Neither header is a Google ranking signal. They are operational metadata — see [09 — llms.txt and humans.txt](09-llms-and-humans-txt.md) for the identity files agents read.
86
+
87
+ ### CDN / platform caveat
88
+
89
+ Vercel, Cloudflare, Coolify or a reverse proxy can rewrite or strip custom headers. After deployment, verify on the real URL:
90
+
91
+ ```bash
92
+ curl -sI https://client.com/ro | grep -iE 'x-devalon|x-built-by|^link'
93
+ ```
94
+
95
+ If a header is missing, the platform is filtering it — not the code. The JSON-LD and the visible credit are not affected.
96
+
97
+ ## Verify
98
+
99
+ ```bash
100
+ curl -sI http://localhost:3000/ro | grep -i '^x-devalon'
101
+ ```
102
+
103
+ Expect the block above. The validator also checks the creator header after deployment:
104
+
105
+ ```bash
106
+ yarn check:credits https://client.com --deployed
107
+ ```
108
+
109
+ ## What this is — and is not
110
+
111
+ - ✅ Operational metadata: instant provenance via `curl -I`, inventory of deployed projects, audit and CDN/debugging checks.
112
+ - ❌ **Not an SEO ranking factor.** Google ignores custom `X-` headers. They do not replace `DevalonJsonLd` or the visible credit link.
113
+
114
+ ## Common mistakes
115
+
116
+ | Don't | Do |
117
+ | --- | --- |
118
+ | Expect headers to affect rankings. | Use the JSON-LD component for entity signals. |
119
+ | Export the middleware config as `configMatcher`. | Next.js requires `export const config = { matcher: [...] }`. |
120
+ | Run middleware on `_next/static` assets. | Add the `matcher` exclusion. |
121
+ | Pass a relative `site_url`. | Pass an absolute `https://...` URL. |
122
+ | Put a client name with diacritics in a header. | Keep it in JSON-LD; headers carry ASCII identifiers only. |
@@ -0,0 +1,163 @@
1
+ # 09 — llms.txt and humans.txt generated at build
2
+
3
+ **When to read this:** you want AI agents and curious humans to find an explicit credit, without anyone manually editing a text file.
4
+
5
+ These are **plain-text identity files**, not ranking factors. They complement (never replace) `DevalonJsonLd` and the visible footer credit.
6
+
7
+ ## The idea
8
+
9
+ A route handler at `app/llms.txt/route.ts` becomes a real endpoint at `/llms.txt`. With `export const dynamic = "force-static"`, Next.js calls `GET()` **once, at `next build`**, takes the returned body and writes it as a static file. At runtime nothing executes — the result is indistinguishable from a file in `public/`, but it was generated from code.
10
+
11
+ ```
12
+ client's original text (source) ──► mergeDevalonLlmsTxt ──► static /llms.txt
13
+ ▲
14
+ Devalon credit block
15
+ ```
16
+
17
+ No copy-paste after setup. The client owns the source text; the library owns the transformation.
18
+
19
+ ## Recommended: App Router route handler
20
+
21
+ ```ts
22
+ // app/llms.txt/route.ts
23
+ import { devalonLlmsTxtResponse } from "@devalon.dev/credits/next";
24
+
25
+ export const dynamic = "force-static";
26
+
27
+ export function GET() {
28
+ return devalonLlmsTxtResponse({
29
+ site_url: "https://example.com",
30
+ site_name: "Example Inc.",
31
+ description: "Custom CRM and booking platform for clinics.",
32
+ services: ["web_development", "ai_agents_automation"] as const,
33
+ // source: existing client text, if there is any
34
+ });
35
+ }
36
+ ```
37
+
38
+ For `humans.txt`, use `devalonHumansTxtResponse` in `app/humans.txt/route.ts`:
39
+
40
+ ```ts
41
+ import { devalonHumansTxtResponse } from "@devalon.dev/credits/next";
42
+
43
+ export const dynamic = "force-static";
44
+
45
+ export function GET() {
46
+ return devalonHumansTxtResponse({
47
+ site_url: "https://example.com",
48
+ site_name: "Example Inc.",
49
+ });
50
+ }
51
+ ```
52
+
53
+ Both helpers return a `Response` with `Content-Type: text/plain; charset=utf-8`. No manual text editing, no `useEffect`, no middleware body rewriting.
54
+
55
+ ## Where the client's text comes from
56
+
57
+ `source` is just a string. Pick one place and keep it there:
58
+
59
+ | Source | How | When to use |
60
+ | --- | --- | --- |
61
+ | Constant in the route file | `source: "# Client\n\n> ..."` | Short, rarely changing text |
62
+ | File in the repo | `readFile("content/llms.md", "utf8")` with `runtime = "nodejs"` | Versioned, editor-friendly |
63
+ | CMS / API | `fetch(...)` at build with `force-static` | Editors outside the codebase |
64
+
65
+ Example with a file source:
66
+
67
+ ```ts
68
+ // app/llms.txt/route.ts
69
+ import { readFile } from "node:fs/promises";
70
+ import path from "node:path";
71
+ import { devalonLlmsTxtResponse } from "@devalon.dev/credits/next";
72
+
73
+ export const runtime = "nodejs";
74
+ export const dynamic = "force-static";
75
+
76
+ export async function GET() {
77
+ const source = await readFile(
78
+ path.join(process.cwd(), "content/llms.md"),
79
+ "utf8",
80
+ );
81
+
82
+ return devalonLlmsTxtResponse({
83
+ site_url: "https://example.com",
84
+ site_name: "Example Inc.",
85
+ source,
86
+ });
87
+ }
88
+ ```
89
+
90
+ If `source` is omitted or empty, the helper generates a complete file (H1, description, canonical URL, credit block). So the same route works whether or not a file existed before.
91
+
92
+ ## The merge is idempotent
93
+
94
+ The credit is wrapped in markers:
95
+
96
+ ```md
97
+ <!-- devalon:start -->
98
+ ## Credits
99
+
100
+ Built and maintained by [Devalon](https://devalon.dev), an AI & software development studio.
101
+ Services: Web Development, AI Agents & Automation.
102
+ <!-- devalon:end -->
103
+ ```
104
+
105
+ `mergeDevalonLlmsTxt` replaces only what is between the markers, or appends the block if the markers are absent. Running the build 100 times produces the same file — no duplicate credits. For `humans.txt` the markers are `/* devalon:start */` and `/* devalon:end */`, and the block is inserted into an existing `/* TEAM */` section when one exists.
106
+
107
+ ## If the site already has `public/llms.txt`
108
+
109
+ A route handler and a public file at the same path collide: Next.js warns about the conflict and the route wins, leaving the public file dead. Do this **once**:
110
+
111
+ 1. Move the client's text from `public/llms.txt` to `content/llms.md` (or into a constant);
112
+ 2. Let the route handler serve `/llms.txt` using that text as `source`;
113
+ 3. Remove `public/llms.txt`.
114
+
115
+ The URL does not change, so any existing links to `/llms.txt` keep working.
116
+
117
+ ## Who owns the file
118
+
119
+ | Situation | What to do |
120
+ | --- | --- |
121
+ | Has the file and controls it | Use a route handler with its text as `source`. No manual credit editing. |
122
+ | Has the file but a CMS/hosting provider manages it | Do not touch it. Ask its owner to paste `devalonLlmsBlock(config)`, or rely on JSON-LD + footer + headers instead. |
123
+ | Has no file | Use `devalonLlmsTxtResponse` / `devalonHumansTxtResponse` with no `source` — a full file is generated. |
124
+ | Does not want these files | Nothing happens. They are optional conventions; everything else still works. |
125
+
126
+ These helpers are **pure string transforms plus a `Response` wrapper** — they never read or write files on disk. Your route decides where the source comes from.
127
+
128
+ ## Pages Router
129
+
130
+ There is no route handler here. Keep static files in `public/`, or run a build script that reads the existing file, calls `mergeDevalonLlmsTxt` / `mergeDevalonHumansTxt`, and writes the result. The generated output is still served as a plain static file.
131
+
132
+ ## API
133
+
134
+ | Function | Use |
135
+ | --- | --- |
136
+ | `devalonLlmsBlock(config)` | Markdown fragment only, for pasting into an existing `llms.txt`. |
137
+ | `mergeDevalonLlmsTxt(existing, config)` | Idempotent insert/update of the marked block. |
138
+ | `devalonLlmsTxt(config)` | Whole file string, when there is no source. |
139
+ | `devalonLlmsTxtResponse(config)` | Ready `Response` for `app/llms.txt/route.ts`. |
140
+ | `devalonHumansBlock(config)` | Text fragment for an existing `humans.txt`. |
141
+ | `mergeDevalonHumansTxt(existing, config)` | Idempotent insert/update, prefers `/* TEAM */`. |
142
+ | `devalonHumansTxt(config)` | Whole file string, when there is no source. |
143
+ | `devalonHumansTxtResponse(config)` | Ready `Response` for `app/humans.txt/route.ts`. |
144
+
145
+ Config: `site_url` (absolute), `site_name`, optional `description`, `services`, `contributions`, `source`. Unknown service keys throw a `TypeError`.
146
+
147
+ ## What this is — and is not
148
+
149
+ - ✅ Cheap, static, cacheable identity files generated at build, with attribution kept unambiguous for LLM crawlers and humans.
150
+ - ❌ Middleware cannot append to a pass-through response body. The route handler generates a new response instead — see [08 — Server headers](08-server-headers.md) for the header-only case.
151
+ - ❌ `llms.txt` is a **convention**, not an official standard. Google has not said it uses it for ranking.
152
+ - ❌ It does not replace JSON-LD (`creator` / `provider`) or the visible credit link.
153
+
154
+ ## Verify
155
+
156
+ ```bash
157
+ yarn build
158
+ curl -s https://client.com/llms.txt | grep -i devalon.dev
159
+ curl -s https://client.com/humans.txt | grep -i devalon.dev
160
+ yarn check:credits https://client.com --deployed
161
+ ```
162
+
163
+ The validator reports missing files or a missing mention as **warnings**, not errors: the files belong to the client.
@@ -0,0 +1,112 @@
1
+ # 01 — SSR setup (React without Next.js)
2
+
3
+ **When to read this:** you render React on the server — React DOM Server, Remix, Astro, TanStack Start, or a custom Express renderer — and need the Devalon credit in the served HTML.
4
+
5
+ `@devalon.dev/credits/react` has **no Next.js dependency**. Every capability is available in three forms, so you choose how much control you need:
6
+
7
+ | Level | API | Output |
8
+ | --- | --- | --- |
9
+ | Declarative | `DevalonJsonLd`, `DevalonAlternates`, `DevalonBacklink` | React elements, emitted wherever you render them |
10
+ | Explicit server | `devalonHeadHtml()`, `devalonBacklinkHtml()` | HTML strings you place in your own template |
11
+ | Build-time | `devalonInjectHtml()` or the Vite plugin | Injected into an existing HTML document, idempotently |
12
+
13
+ For SEO, only one thing matters: **the JSON-LD and the canonical/backlink must exist in the HTML the server sends**, before hydration. Prefer level 2 if your setup has no head manager.
14
+
15
+ ## Recommended: explicit server injection
16
+
17
+ ```tsx
18
+ // server/render.tsx
19
+ import { renderToString } from "react-dom/server";
20
+ import {
21
+ devalonHeadHtml,
22
+ type devalon_head_html_config,
23
+ } from "@devalon.dev/credits/react";
24
+ import { App } from "../src/App";
25
+
26
+ export const devalonConfig: devalon_head_html_config = {
27
+ site_url: "https://example.com",
28
+ site_name: "Example Inc.",
29
+ in_language: "en",
30
+ page_url: "https://example.com/",
31
+ services: ["web_development"],
32
+ contributions: ["developing", "maintaining"],
33
+ alternates: {
34
+ canonical: "https://example.com/",
35
+ pages: { en: "https://example.com/", ro: "https://example.com/ro" },
36
+ },
37
+ };
38
+
39
+ export function render() {
40
+ const app = renderToString(<App />);
41
+
42
+ return `<!doctype html>
43
+ <html lang="en">
44
+ <head><meta charset="utf-8" /><title>Example Inc.</title>${devalonHeadHtml(devalonConfig)}</head>
45
+ <body><div id="root">${app}</div></body>
46
+ </html>`;
47
+ }
48
+ ```
49
+
50
+ `devalonHeadHtml()` returns the JSON-LD `<script>` plus, when `alternates` is set, the canonical and `hreflang` `<link>` tags. It escapes values, so a client name with diacritics is safe.
51
+
52
+ Render the visible credit inside the app tree; it is a normal server-rendered element:
53
+
54
+ ```tsx
55
+ // src/App.tsx
56
+ import { DevalonBacklink } from "@devalon.dev/credits/react";
57
+
58
+ export function App() {
59
+ return (
60
+ <>
61
+ <main>…</main>
62
+ <footer><DevalonBacklink locale="en" /></footer>
63
+ </>
64
+ );
65
+ }
66
+ ```
67
+
68
+ ## Alternative: inject into a finished HTML string
69
+
70
+ If you already have an HTML template (static site, custom renderer, CDN worker), use `devalonInjectHtml`:
71
+
72
+ ```ts
73
+ import { devalonInjectHtml } from "@devalon.dev/credits/react";
74
+
75
+ const html = readTemplate(); // ...<head></head>...<body>...</body>...
76
+ const served = devalonInjectHtml(html, {
77
+ ...devalonConfig,
78
+ backlink: { locale: "en" },
79
+ });
80
+ ```
81
+
82
+ - Head tags are inserted after the opening `<head>` (or at the top when there is no `<head>`).
83
+ - The backlink is inserted before `</body>` (or at the end when there is no `<body>`).
84
+ - Both blocks are wrapped in `<!-- devalon:head:start/end -->` and `<!-- devalon:backlink:start/end -->` markers. Running it again **replaces** the marked blocks instead of duplicating them.
85
+
86
+ ## When the declarative components are enough
87
+
88
+ Frameworks with a head manager (Remix `meta`, Astro `<head>`, TanStack Start head, React 19 hoisting in supported setups) can use the components directly:
89
+
90
+ ```tsx
91
+ import { DevalonAlternates, DevalonJsonLd } from "@devalon.dev/credits/react";
92
+
93
+ <DevalonJsonLd {...credit} />
94
+ <DevalonAlternates canonical="https://example.com/" pages={{ en: "https://example.com/" }} />
95
+ ```
96
+
97
+ If the tags do not appear in the server HTML (`curl` check below), switch to `devalonHeadHtml()` — it never depends on hoisting.
98
+
99
+ ## Rules
100
+
101
+ 1. Render the credit **once per URL**, not once in the layout and again in the page.
102
+ 2. `site_url` is the canonical site root and never changes with language; `page_url` is the localized page.
103
+ 3. No `"use client"`, no `useEffect`, no `document.createElement` — the markup must exist at render time.
104
+ 4. If you use a CSP nonce, pass `nonce` to `devalonHeadHtml()` / `DevalonJsonLd` — see [04 — Metadata and CSP](04-metadata-and-csp.md).
105
+
106
+ ## Verify
107
+
108
+ ```bash
109
+ curl -s http://localhost:3000/ | grep -o 'application/ld+json'
110
+ curl -s http://localhost:3000/ | grep -o 'rel="canonical"'
111
+ curl -s http://localhost:3000/ | grep -o 'https://devalon.dev'
112
+ ```