Skip to content

Commit ddf1013

Browse files
committed
0.2
1 parent 9daa2fe commit ddf1013

60 files changed

Lines changed: 7289 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
cache: "npm"
18+
- run: npm ci
19+
- run: npm test
20+
21+
browser:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: "npm"
29+
- run: npm ci
30+
- run: npx playwright install --with-deps chromium
31+
- run: npm run test:browser

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Node.js modules
2+
node_modules/
3+
4+
# Coverage
5+
coverage/
6+
7+
# Husky generated scripts
8+
.husky/
9+
10+
# Build output
11+
dist/
12+
13+
# Temporary/utility scripts
14+
scripts/
15+
16+
index.js

.npmignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.github/
2+
3+
docs/
4+
test/
5+
tools/
6+
node_modules/
7+
coverage/
8+
scripts/
9+
10+
.gitignore
11+
.npmignore
12+
.gitattributes
13+
14+
15+
CHANGELOG.md
16+
CONTRIBUTING.md
17+
18+
tsconfig.json
19+
package-lock.json
20+
21+
eslint.config.js
22+
rollup.config.js
23+
eslint.config.js
24+

eslint.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default [
2+
{
3+
ignores: ["dist/", "node_modules/"],
4+
},
5+
{
6+
rules: {
7+
"no-unused-vars": "warn",
8+
"no-undef": "error",
9+
},
10+
},
11+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"use client"
2+
3+
import { useEffect, useState } from "react"
4+
import { analyze, type HumanResult } from "truehuman"
5+
6+
const riskColor: Record<string, string> = {
7+
low: "#166534",
8+
medium: "#b45309",
9+
high: "#991b1b",
10+
}
11+
12+
export function HumanCheck() {
13+
const [result, setResult] = useState<HumanResult | null>(null)
14+
const [error, setError] = useState<string | null>(null)
15+
16+
useEffect(() => {
17+
analyze()
18+
.then(setResult)
19+
.catch((e: unknown) => setError((e as Error).message))
20+
}, [])
21+
22+
if (error) {
23+
return <p style={{ color: "#991b1b" }}>{error}</p>
24+
}
25+
26+
if (!result) {
27+
return <p>Analyzing browser…</p>
28+
}
29+
30+
return (
31+
<div>
32+
<p>
33+
<strong>Human:</strong>{" "}
34+
<span style={{ color: result.human ? "#166534" : "#991b1b" }}>
35+
{result.human ? "✅ Yes" : "❌ No"}
36+
</span>
37+
</p>
38+
<p>
39+
<strong>Score:</strong> {result.score}/100
40+
</p>
41+
<p>
42+
<strong>Risk:</strong>{" "}
43+
<span style={{ color: riskColor[result.risk] }}>{result.risk}</span>
44+
</p>
45+
<p>
46+
<strong>Fingerprint:</strong>{" "}
47+
<code>{result.fingerprint.slice(0, 32)}</code>
48+
</p>
49+
{result.signals.length > 0 && (
50+
<>
51+
<p><strong>Signals detected:</strong></p>
52+
<ul style={{ padding: 0, listStyle: "none" }}>
53+
{result.signals.map((s) => (
54+
<li
55+
key={s}
56+
style={{
57+
display: "inline-block",
58+
background: "#fee2e2",
59+
color: "#991b1b",
60+
padding: "2px 10px",
61+
borderRadius: 6,
62+
fontSize: ".8rem",
63+
margin: "2px 4px",
64+
}}
65+
>
66+
{s}
67+
</li>
68+
))}
69+
</ul>
70+
</>
71+
)}
72+
</div>
73+
)
74+
}

examples/nextjs/app/layout.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { ReactNode } from "react"
2+
3+
export const metadata = {
4+
title: "truehuman — Next.js Example",
5+
description: "Example integrating truehuman with Next.js App Router",
6+
}
7+
8+
export default function RootLayout({ children }: { children: ReactNode }) {
9+
return (
10+
<html lang="en">
11+
<body style={{ margin: 0, fontFamily: "system-ui, sans-serif" }}>
12+
{children}
13+
</body>
14+
</html>
15+
)
16+
}

examples/nextjs/app/page.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { HumanCheck } from "./human-check.js"
2+
3+
export default function Home() {
4+
return (
5+
<main style={{ maxWidth: 520, margin: "0 auto", padding: "2rem" }}>
6+
<h1 style={{ fontSize: "1.5rem", marginBottom: "1rem" }}>
7+
🛡️ truehuman + Next.js
8+
</h1>
9+
<HumanCheck />
10+
</main>
11+
)
12+
}

examples/nextjs/next.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { NextConfig } from "next"
2+
3+
const nextConfig: NextConfig = {}
4+
5+
export default nextConfig

0 commit comments

Comments
 (0)