@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,136 @@
1
+ # 07 — llms.txt and humans.txt (build-time, no manual editing)
2
+
3
+ **When to read this:** you want AI agents and curious humans to find an explicit credit, without anyone hand-editing a text file.
4
+
5
+ These are **plain-text identity files**, not ranking factors. They complement (never replace) the JSON-LD and the visible credit. All helpers are pure string transforms plus an optional `Response` wrapper — they never read or write files on disk themselves.
6
+
7
+ ## The idea
8
+
9
+ ```
10
+ client's original text (source) ──► merge ──► static llms.txt / humans.txt
11
+ ▲
12
+ Devalon credit block
13
+ ```
14
+
15
+ The credit is wrapped in markers and merged idempotently. Running the build 100 times produces the same file — no duplicate credits.
16
+
17
+ ## Recommended: Vite plugin
18
+
19
+ ```ts
20
+ // vite.config.ts
21
+ import { defineConfig } from "vite";
22
+ import { devalonVite } from "@devalon.dev/credits/vite";
23
+
24
+ export default defineConfig({
25
+ plugins: [
26
+ devalonVite({
27
+ site_url: "https://example.com",
28
+ site_name: "Example Inc.",
29
+ description: "Custom CRM and booking platform for clinics.",
30
+ services: ["web_development", "ai_agents_automation"],
31
+ agentFilesConfig: {
32
+ // existing client text, if there is any
33
+ source: "# Example\n\n> Official docs and product information.\n",
34
+ },
35
+ }),
36
+ ],
37
+ });
38
+ ```
39
+
40
+ The plugin writes `dist/llms.txt` and `dist/humans.txt`. Set `agentFiles: false` to skip. In the same `closeBundle` pass it also writes the platform header file (`dist/_headers` by default, or `vercel.json` / both via `headersFile`) — see [06 — Server headers](06-server-headers.md). All of these are generated together and all are idempotent. See [02 — CSR / Vite](02-csr-vite.md).
41
+
42
+ ## Build script without Vite
43
+
44
+ `devalonAgentFiles()` returns both files as plain strings, so any build step can write them:
45
+
46
+ ```js
47
+ // scripts/generate-agent-files.mjs
48
+ import { readFile, writeFile } from "node:fs/promises";
49
+ import { devalonAgentFiles } from "@devalon.dev/credits/react";
50
+
51
+ const files = devalonAgentFiles({
52
+ site_url: "https://example.com",
53
+ site_name: "Example Inc.",
54
+ description: "Custom CRM and booking platform for clinics.",
55
+ services: ["web_development"],
56
+ source: await readFile("content/llms.md", "utf8"), // optional
57
+ });
58
+
59
+ for (const [name, content] of Object.entries(files)) {
60
+ await writeFile(new URL(`../public/${name}`, import.meta.url), content, "utf8");
61
+ }
62
+ ```
63
+
64
+ If `source` is omitted or empty, a complete file is generated (H1, description, canonical URL, credit block). The same helper works whether or not a file existed before.
65
+
66
+ ## Server endpoints
67
+
68
+ For a server framework with route handlers, return a ready `Response`:
69
+
70
+ ```ts
71
+ import { devalonLlmsTxtResponse, devalonHumansTxtResponse } from "@devalon.dev/credits/react";
72
+
73
+ export function GET() {
74
+ return devalonLlmsTxtResponse({
75
+ site_url: "https://example.com",
76
+ site_name: "Example Inc.",
77
+ source: existingClientText,
78
+ });
79
+ }
80
+ ```
81
+
82
+ Both helpers set `Content-Type: text/plain; charset=utf-8`. The Vite plugin does not need these — they are for runtime endpoints.
83
+
84
+ ## API
85
+
86
+ | Function | Use |
87
+ | --- | --- |
88
+ | `devalonLlmsBlock(config)` | Markdown fragment only, for pasting into an existing `llms.txt`. |
89
+ | `mergeDevalonLlmsTxt(existing, config)` | Idempotent insert/update of the marked block. |
90
+ | `devalonLlmsTxt(config)` | Whole file string, when there is no source. |
91
+ | `devalonLlmsTxtResponse(config)` | Ready `Response` for a server endpoint. |
92
+ | `devalonHumansBlock(config)` | Text fragment for an existing `humans.txt`. |
93
+ | `mergeDevalonHumansTxt(existing, config)` | Idempotent insert/update, prefers `/* TEAM */`. |
94
+ | `devalonHumansTxt(config)` | Whole file string, when there is no source. |
95
+ | `devalonHumansTxtResponse(config)` | Ready `Response` for a server endpoint. |
96
+ | `devalonAgentFiles(config)` | Both generated files as `{ "llms.txt": string, "humans.txt": string }`. |
97
+
98
+ Config: `site_url` (absolute), `site_name`, optional `description`, `services`, `contributions`, `source`. Unknown service keys throw a `TypeError`.
99
+
100
+ Markers:
101
+
102
+ ```md
103
+ <!-- devalon:start -->
104
+ ## Credits
105
+
106
+ Built and maintained by [Devalon](https://devalon.dev), an AI & software development studio.
107
+ Services: Web Development, AI Agents & Automation.
108
+ <!-- devalon:end -->
109
+ ```
110
+
111
+ For `humans.txt` the markers are `/* devalon:start */` and `/* devalon:end */`, and the block is inserted into an existing `/* TEAM */` section when one exists.
112
+
113
+ ## Who owns the file
114
+
115
+ | Situation | What to do |
116
+ | --- | --- |
117
+ | Has the file and controls it | Pass its text as `source`; the credit is merged automatically. |
118
+ | CMS/hosting provider manages it | Do not touch it. Ask its owner to paste `devalonLlmsBlock(config)`, or rely on JSON-LD + footer + headers. |
119
+ | Has no file | Omit `source` — a full file is generated. |
120
+ | Does not want these files | Set `agentFiles: false` / skip the build step. Everything else still works. |
121
+
122
+ ## What this is — and is not
123
+
124
+ - ✅ Cheap, static, cacheable identity files generated at build, with unambiguous attribution for LLM crawlers and humans.
125
+ - ❌ `llms.txt` is a **convention**, not an official standard. Google has not said it uses it for ranking.
126
+ - ❌ It does not replace JSON-LD (`creator` / `provider`) or the visible credit link.
127
+
128
+ ## Verify
129
+
130
+ ```bash
131
+ yarn build
132
+ grep -i devalon.dev dist/llms.txt dist/humans.txt
133
+ yarn check:credits https://client.com --deployed
134
+ ```
135
+
136
+ The validator reports missing files or a missing mention as **warnings**, not errors: the files belong to the client.
@@ -0,0 +1,56 @@
1
+ # 08 — Credit link validator
2
+
3
+ **When to read this:** before deploying a credit, and after deployment, to confirm the client site is a place where the credit should live.
4
+
5
+ The validator checks the **client site**, not the package build. It is framework-agnostic: the same command works for Next.js, plain React, Vite or a static site.
6
+
7
+ ## Run it
8
+
9
+ ```bash
10
+ # Before deploying — the site should be live and indexable
11
+ yarn check:credits https://client.com
12
+
13
+ # After deployment — also inspects response headers and identity files
14
+ yarn check:credits https://client.com --deployed
15
+ ```
16
+
17
+ ## What it checks
18
+
19
+ | Area | What it looks for |
20
+ | --- | --- |
21
+ | Indexability | HTTP status, `robots` meta, `noindex`, redirect chains |
22
+ | JSON-LD | A Devalon attribution in the structured data |
23
+ | Visible credit | A link back to `devalon.dev` in the HTML |
24
+ | Headers | `X-Devalon-Creator`, `X-Devalon-Project`, `X-Built-By`, `Link: ... rel="author"` |
25
+ | Identity files | `/llms.txt` and `/humans.txt` mention Devalon |
26
+
27
+ Missing identity files or a missing mention are reported as **warnings**, not errors — those files belong to the client. Missing creator header is also a warning, since frameworks and CDNs can strip custom headers (see [06 — Server headers](06-server-headers.md)).
28
+
29
+ For a CSR app built with Vite, verify the generated HTML directly too — the plugin only affects `dist/index.html`, not `vite dev`:
30
+
31
+ ```bash
32
+ yarn build
33
+ grep -o 'application/ld+json' dist/index.html
34
+ grep -o 'https://devalon.dev' dist/index.html
35
+ ```
36
+
37
+ ## Quality gate
38
+
39
+ Only put the credit on sites that are live, indexed and have real traffic. A credit on a staging or `noindex` domain brings no value and can hurt both sides.
40
+
41
+ ## After the credit is live
42
+
43
+ - Keep one canonical `site_url` per client across all integrations (JSON-LD, headers, `llms.txt`, backlink UTM).
44
+ - Re-run the validator after each deployment.
45
+ - With UTM on by default, create a GA4 **Custom channel group** named `Partner credits` with *Session source matches regex* containing your client domains (`client1\.com|client2\.com|...`). If no source was detectable and the link stayed clean, the default referral report is enough.
46
+
47
+ ## Common failures
48
+
49
+ | Symptom | Likely cause |
50
+ | --- | --- |
51
+ | JSON-LD missing | Credit rendered only after hydration; use `devalonHeadHtml()` or the Vite plugin. |
52
+ | Headers missing | CDN/proxy stripping custom `X-` headers, or middleware not applied. |
53
+ | `/llms.txt` missing | File not generated into the deployed output directory. |
54
+ | Duplicate canonical tags | Both a framework head manager and `devalonHeadHtml({ alternates })` are emitting them. |
55
+
56
+ The command never modifies files — it only fetches and reports.
@@ -0,0 +1,76 @@
1
+ # 09 — Performance checklist and final verification
2
+
3
+ **When to read this:** right before shipping a React / Vite integration, to make sure the credit costs nothing at runtime and is actually present in the served HTML.
4
+
5
+ ## Zero client cost
6
+
7
+ - ✅ The components render plain elements. No `"use client"`, no state, no effects, no event handlers.
8
+ - ✅ No hydration work is added — the markup is computed from static props at render/build time.
9
+ - ✅ No remote logo image: a text link adds zero requests.
10
+ - ✅ The JSON-LD is one inline `<script type="application/ld+json">`; the `serialize_json_ld()` step escapes `<`, `>`, `&`, U+2028 and U+2029 so it cannot break the page.
11
+ - ✅ The Vite plugin runs only during `apply: "build"` — nothing is bundled into the browser.
12
+
13
+ ## One credit per URL
14
+
15
+ Render the JSON-LD, canonical link and backlink **once** for each canonical URL:
16
+
17
+ - SSR: in the shared layout / HTML template, not in individual pages.
18
+ - CSR SPA: once in `index.html` via the Vite plugin, not in a component mounted in multiple routes.
19
+ - i18n: once per localized URL, with `page_url` and `alternates.canonical` set to that URL.
20
+
21
+ Duplicate JSON-LD graphs and duplicate canonical tags are worse than no credit at all.
22
+
23
+ ## HTML-first rule
24
+
25
+ The credit must exist in the response body before JavaScript runs. Check with `curl`, not with DevTools after hydration:
26
+
27
+ ```bash
28
+ # SSR server
29
+ curl -s http://localhost:3000/ | grep -o 'application/ld+json'
30
+ curl -s http://localhost:3000/ | grep -o 'rel="canonical"'
31
+ curl -s http://localhost:3000/ | grep -o 'rel="noopener"'
32
+ curl -sI http://localhost:5173/ | grep -i '^x-devalon' # Vite dev/preview middleware
33
+
34
+ # Vite build output
35
+ grep -o 'application/ld+json' dist/index.html
36
+ grep -o 'rel="canonical"' dist/index.html
37
+ grep -o 'https://devalon.dev' dist/index.html
38
+ grep -i 'x-devalon' dist/_headers
39
+ grep -i devalon.dev dist/llms.txt dist/humans.txt
40
+ ```
41
+
42
+ If a check fails:
43
+ 1. In SSR — use `devalonHeadHtml()` in your template instead of relying on head hoisting.
44
+ 2. In CSR — confirm the Vite plugin is in `plugins`, inspect `dist/index.html` (not `vite dev`).
45
+ 3. In i18n — confirm the locale-specific config is the one actually rendered.
46
+
47
+ ## Input hygiene
48
+
49
+ - `site_url` must be an absolute `http(s)` URL. Relative paths throw a `TypeError`.
50
+ - `site_name`, `sentence` and `anchor` must not be empty after trimming.
51
+ - Unknown service keys or locales throw a `TypeError` — fix them instead of casting.
52
+ - Use the same `site_url` in JSON-LD, headers, identity files and UTM. One source of truth.
53
+
54
+ ## Build & types
55
+
56
+ ```bash
57
+ yarn build # tsup bundles + tsc emits declarations for . /next /react /vite
58
+ ```
59
+
60
+ The published entry points are:
61
+
62
+ | Import | Contents |
63
+ | --- | --- |
64
+ | `@devalon.dev/credits` | Schema, catalogs, `build_devalon_json_ld`, `build_devalon_alternates` |
65
+ | `@devalon.dev/credits/next` | Next.js Server Components + Next-specific `Metadata` helper |
66
+ | `@devalon.dev/credits/react` | React components, server HTML helpers, headers, agent files |
67
+ | `@devalon.dev/credits/vite` | `devalonVite()` build-time plugin |
68
+
69
+ ## Final gate
70
+
71
+ ```bash
72
+ yarn check:credits https://client.com
73
+ yarn check:credits https://client.com --deployed
74
+ ```
75
+
76
+ Both must pass before the credit goes live — see [08 — Validator](08-validator.md).
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@devalon.dev/credits",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "Devalon technology-partner attribution for Next.js, React and Vite",
5
+ "license": "MIT",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js"
15
+ },
16
+ "./next": {
17
+ "types": "./dist/next/index.d.ts",
18
+ "import": "./dist/next/index.mjs",
19
+ "require": "./dist/next/index.js"
20
+ },
21
+ "./react": {
22
+ "types": "./dist/react/index.d.ts",
23
+ "import": "./dist/react/index.mjs",
24
+ "require": "./dist/react/index.js"
25
+ },
26
+ "./vite": {
27
+ "types": "./dist/vite/index.d.ts",
28
+ "import": "./dist/vite/index.mjs",
29
+ "require": "./dist/vite/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "README.md",
35
+ "docs/nextjs",
36
+ "docs/react",
37
+ "scripts",
38
+ "!.env",
39
+ "!.env.*"
40
+ ],
41
+ "bin": {
42
+ "devalon-check": "scripts/check-devalon-credits.mjs"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --clean --minify && tsc --emitDeclarationOnly --declarationMap false --outDir dist && rm -rf dist/src",
46
+ "dev": "tsup src/index.ts src/next/index.ts src/react/index.ts src/vite/index.ts --format esm,cjs --watch",
47
+ "check:credits": "node scripts/check-devalon-credits.mjs",
48
+ "test": "yarn build && node --test scripts/*.test.mjs",
49
+ "prepublishOnly": "yarn build"
50
+ },
51
+ "peerDependencies": {
52
+ "react": ">=19.0.0",
53
+ "next": ">=14.0.0",
54
+ "vite": ">=5.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "next": {
58
+ "optional": true
59
+ },
60
+ "vite": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "devDependencies": {
68
+ "@types/react": "^19.3.0",
69
+ "next": "^16.4.6",
70
+ "react": "^19.3.1",
71
+ "tsup": "^9.0.0",
72
+ "typescript": "^7.0.2"
73
+ }
74
+ }
@@ -0,0 +1,178 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import {
5
+ devalonBacklinkHtml,
6
+ devalonInjectHtml,
7
+ detect_site_url,
8
+ resolve_backlink,
9
+ } from "../dist/react/index.mjs";
10
+ import { devalonBacklinkSiteUrlFromHeaders } from "../dist/next/index.mjs";
11
+ import { devalonVite } from "../dist/vite/index.mjs";
12
+
13
+ const CLEAN = "https://devalon.dev";
14
+ const UTM =
15
+ "https://devalon.dev/?utm_source=example.com&utm_medium=credit&utm_campaign=devalon-credits";
16
+
17
+ describe("backlink defaults", () => {
18
+ it("uses the short localized sentences", () => {
19
+ assert.equal(resolve_backlink({ locale: "en" }).text, "Designed and built by");
20
+ assert.equal(resolve_backlink({ locale: "ro" }).text, "Proiectat și realizat de");
21
+ assert.equal(resolve_backlink({ locale: "de" }).text, "Entworfen und entwickelt von");
22
+ });
23
+
24
+ it("emits a clean link when no source is available", () => {
25
+ assert.equal(resolve_backlink({}).href, CLEAN);
26
+ assert.equal(resolve_backlink({ locale: "ro" }).href, CLEAN);
27
+ });
28
+
29
+ it("appends hostname-only UTM by default", () => {
30
+ const result = resolve_backlink({
31
+ site_url: "https://www.Example.com/ro/about?x=1",
32
+ locale: "ro",
33
+ });
34
+ assert.equal(result.href, UTM);
35
+ assert.equal(result.link_text, "Devalon");
36
+ });
37
+
38
+ it("honours utm: false and an explicit sentence/anchor", () => {
39
+ assert.equal(
40
+ resolve_backlink({ site_url: "https://example.com", utm: false }).href,
41
+ CLEAN,
42
+ );
43
+ const result = resolve_backlink({ sentence: "Custom text", anchor: "Studio" });
44
+ assert.equal(result.text, "Custom text");
45
+ assert.equal(result.link_text, "Studio");
46
+ });
47
+
48
+ it("still rejects invalid explicit site_url values", () => {
49
+ assert.throws(() => resolve_backlink({ site_url: "/despre" }), TypeError);
50
+ });
51
+ });
52
+
53
+ describe("source detection", () => {
54
+ it("normalizes bare hosts and strips paths", () => {
55
+ assert.equal(detect_site_url({ SITE_URL: "Example.com/ro" }), "https://example.com");
56
+ assert.equal(
57
+ detect_site_url({ SITE_URL: "http://example.com:8080/x" }),
58
+ "http://example.com",
59
+ );
60
+ });
61
+
62
+ it("respects priority and skips unusable values", () => {
63
+ assert.equal(
64
+ detect_site_url({
65
+ NEXT_PUBLIC_SITE_URL: "ok.com",
66
+ SITE_URL: "ftp://bad.example",
67
+ }),
68
+ "https://ok.com",
69
+ );
70
+ assert.equal(
71
+ detect_site_url({ SITE_URL: "not a url", VERCEL_URL: "app.vercel.app" }),
72
+ "https://app.vercel.app",
73
+ );
74
+ assert.equal(detect_site_url({}), undefined);
75
+ });
76
+
77
+ it("derives an absolute URL from request headers", () => {
78
+ assert.equal(
79
+ devalonBacklinkSiteUrlFromHeaders(
80
+ new Headers({ host: "example.com", "x-forwarded-proto": "http" }),
81
+ ),
82
+ "http://example.com",
83
+ );
84
+ assert.equal(
85
+ devalonBacklinkSiteUrlFromHeaders(
86
+ new Headers({
87
+ "x-forwarded-host": "www.Example.com, proxy",
88
+ host: "internal.local",
89
+ }),
90
+ ),
91
+ "https://example.com",
92
+ );
93
+ assert.equal(devalonBacklinkSiteUrlFromHeaders(undefined), undefined);
94
+ });
95
+
96
+ it("auto-detects from process.env in the HTML helper", () => {
97
+ const original = process.env.SITE_URL;
98
+ process.env.SITE_URL = "env-site.com";
99
+ try {
100
+ const html = devalonBacklinkHtml({ locale: "ro" });
101
+ assert.match(html, /Proiectat și realizat de/);
102
+ assert.match(html, /utm_source=env-site\.com/);
103
+ } finally {
104
+ if (original === undefined) delete process.env.SITE_URL;
105
+ else process.env.SITE_URL = original;
106
+ }
107
+ });
108
+
109
+ it("injects a UTM link into HTML from build-time env", () => {
110
+ const original = process.env.SITE_URL;
111
+ process.env.SITE_URL = "vite-site.com";
112
+ try {
113
+ const plugin = devalonVite({
114
+ site_url: "https://vite-site.com",
115
+ site_name: "Vite Site",
116
+ backlink: { locale: "ro" },
117
+ });
118
+ const html = plugin.transformIndexHtml.handler(
119
+ "<html><head></head><body></body></html>",
120
+ );
121
+ assert.match(html, /utm_source=vite-site\.com/);
122
+ assert.match(html, /Proiectat și realizat de/);
123
+ } finally {
124
+ if (original === undefined) delete process.env.SITE_URL;
125
+ else process.env.SITE_URL = original;
126
+ }
127
+ });
128
+
129
+ it("prefers explicit site_url over detection and still honours utm: false", () => {
130
+ const original = process.env.SITE_URL;
131
+ process.env.SITE_URL = "vite-site.com";
132
+ try {
133
+ const explicit = devalonVite({
134
+ site_url: "https://vite-site.com",
135
+ site_name: "Vite Site",
136
+ backlink: { locale: "ro", site_url: "https://explicit.com/ro" },
137
+ });
138
+ const explicit_html = explicit.transformIndexHtml.handler(
139
+ "<html><head></head><body></body></html>",
140
+ );
141
+ assert.match(explicit_html, /utm_source=explicit\.com/);
142
+ assert.doesNotMatch(explicit_html, /utm_source=vite-site\.com/);
143
+
144
+ const disabled = devalonVite({
145
+ site_url: "https://vite-site.com",
146
+ site_name: "Vite Site",
147
+ backlink: { locale: "ro", utm: false },
148
+ });
149
+ const disabled_html = disabled.transformIndexHtml.handler(
150
+ "<html><head></head><body></body></html>",
151
+ );
152
+ assert.match(disabled_html, /href="https:\/\/devalon\.dev"/);
153
+ assert.doesNotMatch(disabled_html, /utm_source=/);
154
+ } finally {
155
+ if (original === undefined) delete process.env.SITE_URL;
156
+ else process.env.SITE_URL = original;
157
+ }
158
+ });
159
+
160
+ it("keeps devalonInjectHtml clean with no detectable source", () => {
161
+ const original = process.env.SITE_URL;
162
+ delete process.env.SITE_URL;
163
+ try {
164
+ const html = devalonInjectHtml(
165
+ "<html><head></head><body></body></html>",
166
+ {
167
+ site_url: "https://example.com",
168
+ site_name: "Example",
169
+ backlink: { locale: "ro" },
170
+ },
171
+ );
172
+ assert.match(html, /href="https:\/\/devalon\.dev"/);
173
+ assert.doesNotMatch(html, /utm_source=/);
174
+ } finally {
175
+ if (original !== undefined) process.env.SITE_URL = original;
176
+ }
177
+ });
178
+ });