siteshield 0.1.0 → 0.1.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 (2) hide show
  1. package/README.md +34 -15
  2. package/package.json +27 -8
package/README.md CHANGED
@@ -1,27 +1,33 @@
1
- # SiteShield Next.js adapter
1
+ # SiteShield
2
2
 
3
- SiteShield's Node.js security engine and Next.js request adapter. This is an early MVP for team demonstrations, not a complete edge firewall. It makes local decisions and can report restricted events asynchronously to a separately deployed SiteShield API.
3
+ SiteShield is a reusable Node.js bot-protection library for Next.js. This repository is **only the npm package**: it has no Next.js application, dashboard, API server, or WordPress plugin. Create a separate Next.js project to integrate and test it.
4
4
 
5
- ## Install
5
+ The current public release is [`siteshield@0.1.0`](https://www.npmjs.com/package/siteshield). Install it in your Next.js project with `npm install siteshield`.
6
6
 
7
- ```sh
8
- npm install siteshield
7
+ ## Structure
8
+
9
+ ```text
10
+ src/core/ Security decisions, policies and counters
11
+ src/integrations/next.ts Next.js request adapter and optional event reporter
12
+ tsconfig.json Package build configuration
13
+ tsconfig.test.json Test compilation configuration
14
+ package.json npm exports and scripts
9
15
  ```
10
16
 
11
- Create `proxy.ts` in a Next.js 16 app (Node.js runtime):
17
+ `dist/` is generated by the build and contains the code published to npm. `node_modules/` and `dist-test/` are generated local files.
18
+
19
+ ## Integrate in a separate Next.js project
20
+
21
+ For Next.js 16 on Node.js, create `proxy.ts` in that other project:
12
22
 
13
23
  ```ts
14
24
  import { NextResponse, type NextRequest, type NextFetchEvent } from 'next/server';
15
- import { createNextShield, createApiEventReporter } from 'siteshield/next';
25
+ import { createNextShield } from 'siteshield/next';
16
26
 
17
27
  const shield = createNextShield({
18
- siteId: process.env.SITESHIELD_SITE_ID!,
19
- policy: { mode: 'monitor' },
28
+ siteId: 'my-project',
29
+ policy: { mode: 'enforce', maxRequests: 30, windowMs: 60_000 },
20
30
  getClientIp: (request) => request.headers.get('x-company-client-ip') ?? undefined,
21
- eventReporter: createApiEventReporter(
22
- process.env.SITESHIELD_API_URL!,
23
- process.env.SITESHIELD_SITE_KEY!,
24
- ),
25
31
  });
26
32
 
27
33
  export async function proxy(request: NextRequest, event: NextFetchEvent) {
@@ -31,6 +37,19 @@ export async function proxy(request: NextRequest, event: NextFetchEvent) {
31
37
  export const config = { matcher: ['/api/:path*', '/login'] };
32
38
  ```
33
39
 
34
- The example IP header is **not** automatically trustworthy. Only use it if your ingress overwrites client-supplied headers and prevents direct origin access. A missing/invalid IP or counter-store failure produces HTTP 503, never a silent allow. `mode: 'monitor'` records would-be restrictions without enforcing them; test and set `mode: 'enforce'` when ready. The local in-memory counter default is only appropriate for a single instance. For multiple instances, pass a shared `RedisCounterStore` via `counterStore` (exported from `siteshield/counters`).
40
+ The IP header is only illustrative. Use it **only** if a trusted reverse proxy overwrites it and direct origin access is prevented. A loopback-only resolver returning `127.0.0.1` is useful for local testing but must never be used in production. Missing trusted IPs and counter failures return 503.
41
+
42
+ Default counters are in memory, suitable for one process and local demonstrations. For multiple instances, pass a shared `RedisCounterStore` from `siteshield/counters`. `mode: 'monitor'` records would-be restrictions without enforcing them; `mode: 'enforce'` returns 429 for rate limits and 403 for blocks. This is not an edge firewall or a substitute for DDoS protection.
43
+
44
+ `createApiEventReporter` sends restricted events to a separately hosted SiteShield API. This repository does not provide or deploy that API. Keep site credentials server-side and never use `NEXT_PUBLIC_` for secrets.
45
+
46
+ ## Develop and release
47
+
48
+ ```powershell
49
+ npm install
50
+ npm test
51
+ npm run build
52
+ npm run pack:package
53
+ ```
35
54
 
36
- The API URL, site ID, and site key must be server-only environment variables (never `NEXT_PUBLIC_`). The central SiteShield API must be deployed and configured separately. Do not expose this package as a substitute for network/edge DDoS protection. The WordPress plugin is distributed separately from this npm package.
55
+ The package created by `npm run pack:package` can be installed into your separate Next.js project for testing. Published versions are immutable: bump the root `package.json` version before `npm run publish:package`. Publishing needs ownership of the `siteshield` npm package and npm account verification.
package/package.json CHANGED
@@ -1,23 +1,42 @@
1
1
  {
2
2
  "name": "siteshield",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Reusable bot-protection engine and Next.js adapter",
5
5
  "type": "module",
6
- "engines": { "node": ">=20" },
7
- "publishConfig": { "access": "public" },
8
- "files": ["dist"],
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
9
12
  "exports": {
10
13
  "./next": {
11
14
  "types": "./dist/integrations/next.d.ts",
12
15
  "import": "./dist/integrations/next.js"
13
16
  },
14
- "./core": {
15
- "types": "./dist/core/engine.d.ts",
16
- "import": "./dist/core/engine.js"
17
- },
18
17
  "./counters": {
19
18
  "types": "./dist/core/counters.d.ts",
20
19
  "import": "./dist/core/counters.js"
20
+ },
21
+ "./core": {
22
+ "types": "./dist/core/engine.d.ts",
23
+ "import": "./dist/core/engine.js"
21
24
  }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "clean": "node -e \"for (const p of ['dist','dist-test']) require('node:fs').rmSync(p,{recursive:true,force:true})\"",
31
+ "build": "npm run clean && tsc -p tsconfig.json",
32
+ "build:package": "npm run build",
33
+ "pack:package": "npm run build && npm pack",
34
+ "publish:package": "npm run build && npm publish --access public",
35
+ "test": "tsc -p tsconfig.test.json && node --test dist-test/core/*.test.js dist-test/integrations/*.test.js",
36
+ "prepack": "npm run build"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.20.5",
40
+ "typescript": "^5.7.2"
22
41
  }
23
42
  }