@steadphast/connector-nextjs 0.5.1 → 0.5.3
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.
- package/NOTICE +9 -4
- package/README.md +272 -264
- package/package.json +14 -13
package/NOTICE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Steadphast
|
|
1
|
+
Steadphast Next.js Connector
|
|
2
2
|
Copyright 2026 Steadphast
|
|
3
3
|
|
|
4
4
|
This product is licensed under the Apache License, Version 2.0 (the
|
|
@@ -7,6 +7,11 @@ distributed with this package, or at:
|
|
|
7
7
|
|
|
8
8
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
9
|
|
|
10
|
-
This package bundles source from the Steadphast Discover
|
|
11
|
-
(ts/packages/connector-core in the Steadphast
|
|
12
|
-
|
|
10
|
+
This package bundles source from the Steadphast Discover Connector Core
|
|
11
|
+
(ts/packages/connector-core in the Steadphast repository), whose NOTICE
|
|
12
|
+
reads:
|
|
13
|
+
|
|
14
|
+
Steadphast Discover Connector Core
|
|
15
|
+
Copyright 2026 Steadphast
|
|
16
|
+
|
|
17
|
+
The bundled source is licensed under the same terms.
|
package/README.md
CHANGED
|
@@ -1,106 +1,43 @@
|
|
|
1
1
|
# @steadphast/connector-nextjs
|
|
2
2
|
|
|
3
|
-
The Next.js connector for Steadphast
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
The server accepts `"2"` only: version 1 acceptance was removed at the cutoff recorded in the
|
|
29
|
-
ADR 0034 amendments. Rollback is by package version, and rolling back to 0.4.0 first requires
|
|
30
|
-
restoring v1 acceptance across the API fleet (design D6), otherwise every 0.4.0 envelope is
|
|
31
|
-
rejected as an unknown version with the fixed `malformed_request` response.
|
|
32
|
-
|
|
33
|
-
## Breaking 0.4.0 cutover
|
|
34
|
-
|
|
35
|
-
Version 0.4.0 replaces 0.3.0. This is a clean cutover, not a compatibility release — there is no
|
|
36
|
-
shim, no dual-write, no fallback, and no alias:
|
|
37
|
-
|
|
38
|
-
- the wire body is a sanitized `envelope_version: "2"` object (`"1"` before 0.5.0), **never** a `CanonicalEvent` and
|
|
39
|
-
never a `{ "records": [...] }` batch;
|
|
40
|
-
- the only accepted destination path is `/v1/connectors/nextjs/events`. An `apiUrl` whose pathname
|
|
41
|
-
is exactly the canonical `/v1/events` route is rejected at construction, so a sanitized envelope
|
|
42
|
-
can never be posted as a canonical event. An origin form is normalized to the dedicated path;
|
|
43
|
-
- the canonical mapper surface is gone from the package root. `CANONICAL_EVENT_KEYS`,
|
|
44
|
-
`mapVercelRequestToCanonicalEvent`, and `mapSelfHostedRequestToCanonicalEvent` are no longer
|
|
45
|
-
exported, and there is no public canonical-mapping API in this package;
|
|
46
|
-
- the package root exports only the configuration surface plus `withDiscover`. Raw shipping
|
|
47
|
-
primitives (`ship`, the dropped-event counters, `DEFAULT_SHIP_TIMEOUT_MS`) are **not** re-exported
|
|
48
|
-
from this package root;
|
|
49
|
-
- `withDiscover` still takes exactly one explicit deployment mode and an explicit `apiUrl`; there is
|
|
50
|
-
no default export, env-only handler, or inferred mode.
|
|
51
|
-
|
|
52
|
-
The required modes are unchanged (ADR 0033 remains in force for mode, authority, boundary,
|
|
53
|
-
destination, and lifecycle rules):
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
{ kind: "vercel" }
|
|
57
|
-
{ kind: "self-hosted", publicOrigin: "https://canonical.example" }
|
|
3
|
+
The Next.js connector for [Steadphast](https://steadphast.ai). It runs in your Next.js Middleware
|
|
4
|
+
(Next.js 15) or Proxy (Next.js 16), captures request metadata before the request reaches your
|
|
5
|
+
application, and sends a bounded, sanitized record of each request to Steadphast in the background.
|
|
6
|
+
Steadphast classifies the traffic server-side: the connector never reads a request body, never runs
|
|
7
|
+
any classification, and never changes the response your visitor receives.
|
|
8
|
+
|
|
9
|
+
The package is one connector with two modes: **Next.js on Vercel** (`kind: "vercel"`) and
|
|
10
|
+
**Next.js self-hosted** (`kind: "self-hosted"`).
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
Visitor / bot Your Next.js deployment Steadphast
|
|
14
|
+
───────────── ─────────────────────── ──────────
|
|
15
|
+
│ request │ │
|
|
16
|
+
├───────────────────────────────►│ middleware.ts / proxy.ts │
|
|
17
|
+
│ │ 1. skip static assets │
|
|
18
|
+
│ │ 2. read method, URL, headers only │
|
|
19
|
+
│ │ 3. drop recognized credential headers │
|
|
20
|
+
│ │ + your excludedHeaders │
|
|
21
|
+
│ │ 4. build one bounded record │
|
|
22
|
+
│ │ 5. waitUntil(POST record) ───────────►│ classify
|
|
23
|
+
│ │ 6. run your handler, then the app │ + store
|
|
24
|
+
│◄───────────────────────────────┤ response (unchanged by the connector) │
|
|
25
|
+
│ │ │
|
|
26
|
+
Event appears in Explore ◄┘
|
|
58
27
|
```
|
|
59
28
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sends the exact `X-Steadphast-Connector: nextjs-self-hosted` assertion. The authenticated API key's
|
|
63
|
-
stored connector label must match; the assertion is reject-only and never assigns provenance.
|
|
64
|
-
|
|
65
|
-
## What is still gated
|
|
66
|
-
|
|
67
|
-
Acceptance of ADR 0034 does not complete its rollout gates, and this README is not activation
|
|
68
|
-
documentation:
|
|
69
|
-
|
|
70
|
-
- **Internal-deployment migration** — moving every internal deployment onto the dedicated endpoint
|
|
71
|
-
is a separate gate; this package version does not assert that inventory is complete.
|
|
72
|
-
- **Legacy cutoff** — fleet-wide rejection of both Next.js key labels on `/v1/events` is a later,
|
|
73
|
-
separately verified gate.
|
|
74
|
-
- **Release provenance** — a published version is produced only from a tagged `main` commit by
|
|
75
|
-
the release workflow described under "Publishing" below. An untagged local `dist/` build is
|
|
76
|
-
not a release and is not evidence that any version was published, audited, or adopted.
|
|
77
|
-
- **Activation** — self-hosted connector-key self-service issuance, dashboard controls, the ADR 0017
|
|
78
|
-
expendable/non-expendable decision, and the issue #349 decision remain deferred. Nothing in this
|
|
79
|
-
package claims that any customer or pilot deployment is active.
|
|
80
|
-
- **Customer activation and external support** — inviting a customer to a workspace, issuing
|
|
81
|
-
their key, and any support commitment remain separate human-authorized gates. Publication to
|
|
82
|
-
npm makes the package installable; it does not activate anyone. GA is later still.
|
|
83
|
-
|
|
84
|
-
## Build inside this monorepo
|
|
85
|
-
|
|
86
|
-
Repository callers consume the workspace package rather than the published one:
|
|
87
|
-
|
|
88
|
-
```jsonc
|
|
89
|
-
{
|
|
90
|
-
"dependencies": {
|
|
91
|
-
"@steadphast/connector-nextjs": "workspace:*"
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
```
|
|
29
|
+
Licensed under Apache-2.0. The `LICENSE` and `NOTICE` files shipped with the package are the
|
|
30
|
+
authoritative terms.
|
|
95
31
|
|
|
96
|
-
|
|
32
|
+
## Requirements
|
|
97
33
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
34
|
+
- Next.js 15 and 16. Next.js is the only peer dependency (`^15.0.0 || ^16.0.0`), so the package
|
|
35
|
+
installs against the Next.js version your application already pins. Tested with Next.js 15.5.23
|
|
36
|
+
(`middleware.ts`) and 16.3.2 (`proxy.ts`); other releases on those two lines are expected to
|
|
37
|
+
work. Next.js 14 and earlier are not supported.
|
|
38
|
+
- A Steadphast API key, created in the dashboard under **Settings → API keys** with **Used with**
|
|
39
|
+
set to the mode you deploy: **Next.js on Vercel** or **Next.js self-hosted**. A key is issued for
|
|
40
|
+
one deployment mode and is rejected by the other.
|
|
104
41
|
|
|
105
42
|
## Install
|
|
106
43
|
|
|
@@ -108,48 +45,29 @@ external and bundles the connector's runtime dependencies.
|
|
|
108
45
|
npm install @steadphast/connector-nextjs
|
|
109
46
|
```
|
|
110
47
|
|
|
111
|
-
|
|
112
|
-
application already pins. The manifest declares no runtime dependencies: the build bundles
|
|
113
|
-
`@discover/connector-core` into `dist/index.js`, so the package installs standalone.
|
|
114
|
-
`artifact.test.ts` pins that manifest shape.
|
|
115
|
-
|
|
116
|
-
## Publishing
|
|
117
|
-
|
|
118
|
-
Releases are published by the `publish-connector-nextjs` GitHub Actions workflow, which is
|
|
119
|
-
dispatched manually against a tag on `main` and is the only sanctioned publisher. It rebuilds the
|
|
120
|
-
package from that tag, verifies the manifest version matches the tag, packs, and publishes with
|
|
121
|
-
`--access public`. Never run `npm publish` or `pnpm publish` from a working copy: the manifest's
|
|
122
|
-
`prepublishOnly` script exits before npm is contacted unless `STEADPHAST_CONNECTOR_RELEASE=1` is
|
|
123
|
-
set, and only the workflow's publish step sets it, after every gate has passed.
|
|
124
|
-
|
|
125
|
-
To inspect what a release would contain without publishing anything:
|
|
48
|
+
Or, with pnpm:
|
|
126
49
|
|
|
127
50
|
```sh
|
|
128
|
-
pnpm
|
|
129
|
-
pnpm --filter @steadphast/connector-nextjs pack --dry-run
|
|
51
|
+
pnpm add @steadphast/connector-nextjs
|
|
130
52
|
```
|
|
131
53
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
such as `mapRequestToCanonicalEvent` or `CANONICAL_EVENT_KEYS`.
|
|
54
|
+
The package has no runtime dependencies; install no other Steadphast package. On Next.js 14 or
|
|
55
|
+
earlier, `npm install` stops with `ERESOLVE` and `pnpm add` warns about an unmet peer: upgrade
|
|
56
|
+
Next.js rather than forcing the install.
|
|
136
57
|
|
|
137
|
-
## Next.js
|
|
58
|
+
## Quick start: Next.js on Vercel
|
|
59
|
+
|
|
60
|
+
### Next.js 15: `middleware.ts`
|
|
138
61
|
|
|
139
62
|
Place `middleware.ts` beside the root `app` or `pages` directory, or at `src/middleware.ts` when the
|
|
140
|
-
application lives under `src/`.
|
|
63
|
+
application lives under `src/`. Vercel mode runs on the Edge or Node.js runtime.
|
|
141
64
|
|
|
142
65
|
```ts
|
|
143
66
|
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
144
67
|
|
|
145
|
-
const apiUrl = process.env.STEADPHAST_API_URL;
|
|
146
|
-
if (!apiUrl) {
|
|
147
|
-
throw new Error("STEADPHAST_API_URL is required");
|
|
148
|
-
}
|
|
149
|
-
|
|
150
68
|
export default withDiscover({
|
|
151
69
|
kind: "vercel",
|
|
152
|
-
apiUrl,
|
|
70
|
+
apiUrl: "https://api.steadphast.ai",
|
|
153
71
|
excludedHeaders: ["cookie"],
|
|
154
72
|
recordIdPrefix: "vercel-production",
|
|
155
73
|
});
|
|
@@ -159,26 +77,17 @@ export const config = {
|
|
|
159
77
|
};
|
|
160
78
|
```
|
|
161
79
|
|
|
162
|
-
Next.js
|
|
163
|
-
topology is Node-only; add `runtime: "nodejs"` to the exported `config` and use the self-hosted
|
|
164
|
-
configuration below.
|
|
165
|
-
|
|
166
|
-
## Next.js 16.3: `proxy.ts`
|
|
80
|
+
### Next.js 16: `proxy.ts`
|
|
167
81
|
|
|
168
82
|
Place `proxy.ts` beside the root `app` or `pages` directory, or at `src/proxy.ts` when the
|
|
169
|
-
application lives under `src/`.
|
|
83
|
+
application lives under `src/`. Proxy runs on Node.js.
|
|
170
84
|
|
|
171
85
|
```ts
|
|
172
86
|
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
173
87
|
|
|
174
|
-
const apiUrl = process.env.STEADPHAST_API_URL;
|
|
175
|
-
if (!apiUrl) {
|
|
176
|
-
throw new Error("STEADPHAST_API_URL is required");
|
|
177
|
-
}
|
|
178
|
-
|
|
179
88
|
export default withDiscover({
|
|
180
89
|
kind: "vercel",
|
|
181
|
-
apiUrl,
|
|
90
|
+
apiUrl: "https://api.steadphast.ai",
|
|
182
91
|
excludedHeaders: ["cookie"],
|
|
183
92
|
recordIdPrefix: "vercel-production",
|
|
184
93
|
});
|
|
@@ -188,162 +97,261 @@ export const config = {
|
|
|
188
97
|
};
|
|
189
98
|
```
|
|
190
99
|
|
|
191
|
-
|
|
192
|
-
wrapper schedules capture and delivery, then invokes that handler once and preserves its response,
|
|
193
|
-
rewrite, redirect, `undefined` result, or thrown error.
|
|
100
|
+
### Set the API key
|
|
194
101
|
|
|
195
|
-
|
|
102
|
+
Add `STEADPHAST_API_KEY` to every Vercel environment where capture should be enabled. It is a
|
|
103
|
+
server-only secret: never give it a `NEXT_PUBLIC_*` name. When no key is set, the connector logs a
|
|
104
|
+
warning once and ships nothing; the visitor response is unaffected.
|
|
196
105
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
106
|
+
Deploy, make a request to a matched path, and open **Explore** in the Steadphast dashboard. The
|
|
107
|
+
event normally appears within about 60 seconds.
|
|
108
|
+
|
|
109
|
+
### Keep your own Middleware or Proxy logic
|
|
110
|
+
|
|
111
|
+
`withDiscover(config, handler?)` composes one application handler. The wrapper schedules capture and
|
|
112
|
+
delivery, then calls your handler once and preserves its response, rewrite, redirect, `undefined`
|
|
113
|
+
result, or thrown error:
|
|
201
114
|
|
|
202
115
|
```ts
|
|
116
|
+
import { NextResponse } from "next/server";
|
|
203
117
|
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
204
118
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
119
|
+
export default withDiscover(
|
|
120
|
+
{ kind: "vercel", apiUrl: "https://api.steadphast.ai", excludedHeaders: ["cookie"] },
|
|
121
|
+
(request) => {
|
|
122
|
+
if (request.nextUrl.pathname === "/old") {
|
|
123
|
+
return NextResponse.redirect(new URL("/new", request.url));
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Keep the wrapper as the file's default export so Next.js calls it with both the request and the
|
|
130
|
+
`NextFetchEvent`; delivery is scheduled through `event.waitUntil`. Do not call the wrapper from a
|
|
131
|
+
route handler, and do not drop the event argument.
|
|
132
|
+
|
|
133
|
+
## Next.js self-hosted
|
|
134
|
+
|
|
135
|
+
Self-hosted mode is for a Next.js application started with `next start` on a server, virtual
|
|
136
|
+
machine, or container you operate, with nginx terminating client TLS directly in front of it. It
|
|
137
|
+
is the same package configured with `kind: "self-hosted"`. Use it in either entry file; for
|
|
138
|
+
Next.js 15 `middleware.ts` also add `runtime: "nodejs"` to the exported `config` (Next.js 16
|
|
139
|
+
`proxy.ts` is already Node-only and does not accept the `runtime` option). The full setup guide,
|
|
140
|
+
including the reference nginx configuration, is in the dashboard at
|
|
141
|
+
<https://app.steadphast.ai/docs/integrations/nextjs-self-hosted>.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
209
145
|
|
|
210
146
|
export default withDiscover({
|
|
211
147
|
kind: "self-hosted",
|
|
212
148
|
publicOrigin: "https://www.example.com",
|
|
213
|
-
apiUrl,
|
|
149
|
+
apiUrl: "https://api.steadphast.ai",
|
|
214
150
|
excludedHeaders: ["cookie"],
|
|
215
151
|
recordIdPrefix: "nextjs-self-hosted-production",
|
|
216
152
|
});
|
|
217
153
|
|
|
218
154
|
export const config = {
|
|
155
|
+
// Next.js 15 middleware.ts only; remove this line in Next.js 16 proxy.ts.
|
|
156
|
+
runtime: "nodejs",
|
|
219
157
|
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
220
158
|
};
|
|
221
159
|
```
|
|
222
160
|
|
|
223
|
-
`publicOrigin` is the
|
|
224
|
-
|
|
225
|
-
and it must match
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
161
|
+
`publicOrigin` is the public scheme, host, and port your visitors use, and it is the only source
|
|
162
|
+
of the captured request URL's origin. It must be one HTTPS origin with no credentials, path, query,
|
|
163
|
+
or fragment, and it must match the public authority nginx serves exactly. It is separate from
|
|
164
|
+
`apiUrl`. The API key comes from the `STEADPHAST_API_KEY` environment variable of the `next start`
|
|
165
|
+
process, issued with **Used with** set to **Next.js self-hosted**.
|
|
166
|
+
|
|
167
|
+
### The nginx trust boundary
|
|
168
|
+
|
|
169
|
+
In this mode the connector trusts exactly two request headers, `X-Steadphast-Client-Ip` and
|
|
170
|
+
`X-Steadphast-Request-Id`, and only because nginx overwrites both on every proxied request from
|
|
171
|
+
facts nginx itself established. The connector never falls back to `X-Forwarded-For`, `X-Real-IP`,
|
|
172
|
+
the public `x-request-id`, any `x-vercel-*` header, or the socket address. A Next.js listener that
|
|
173
|
+
is reachable without nginx, or a proxy that passes client headers through, lets any client forge
|
|
174
|
+
the IP recorded for its requests.
|
|
175
|
+
|
|
176
|
+
The supported topology is exactly one nginx directly in front of the application, and the
|
|
177
|
+
supported configuration is the reference nginx configuration in the
|
|
178
|
+
[dashboard guide](https://app.steadphast.ai/docs/integrations/nextjs-self-hosted). Start from that
|
|
179
|
+
file and change only the values it lists (public host and port, certificate paths, and the loopback
|
|
180
|
+
`proxy_pass` address). It:
|
|
181
|
+
|
|
182
|
+
- terminates client TLS directly on TLS 1.2 or 1.3 and refuses a handshake without the configured
|
|
183
|
+
server name;
|
|
184
|
+
- accepts exactly one public host and port and answers `421` to every other `Host` or absolute-form
|
|
185
|
+
request target;
|
|
186
|
+
- overwrites `Host`, `X-Forwarded-Host`, and `X-Forwarded-Proto` from validated routing and
|
|
187
|
+
transport facts;
|
|
188
|
+
- overwrites `X-Steadphast-Client-Ip` with the direct TCP peer (`$remote_addr`) and
|
|
189
|
+
`X-Steadphast-Request-Id` with nginx's own `$request_id`, replacing every client-supplied copy;
|
|
190
|
+
- appends its peer to `X-Forwarded-For`, which the connector keeps only as untrusted evidence.
|
|
191
|
+
|
|
192
|
+
Bind the application to loopback (for example `next start -H 127.0.0.1 -p 3000`) and confirm from
|
|
193
|
+
outside the host that the Next.js port is not reachable. A CDN, load balancer, or second proxy in
|
|
194
|
+
front of nginx, a public direct Next.js port, and pass-through internal headers are unsupported:
|
|
195
|
+
the connector cannot detect them, and a CDN in front makes the recorded client IP that CDN's
|
|
196
|
+
address. No TLS fingerprint is available in this mode.
|
|
197
|
+
|
|
198
|
+
## Configuration reference
|
|
229
199
|
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
200
|
+
```ts
|
|
201
|
+
type DiscoverNextConfig = (
|
|
202
|
+
| { kind: "vercel" }
|
|
203
|
+
| { kind: "self-hosted"; publicOrigin: string }
|
|
204
|
+
) & {
|
|
205
|
+
apiUrl: string;
|
|
206
|
+
apiKeyEnvVar?: string;
|
|
207
|
+
captureAllPaths?: boolean;
|
|
208
|
+
excludedHeaders?: ReadonlyArray<string>;
|
|
209
|
+
recordIdPrefix?: string;
|
|
210
|
+
timeoutMs?: number;
|
|
211
|
+
};
|
|
237
212
|
```
|
|
238
213
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
and
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
into the envelope's generic header map.
|
|
250
|
-
|
|
251
|
-
## Destination policy
|
|
252
|
-
|
|
253
|
-
`apiUrl` is required in both modes and controls the outbound Discover destination. Configuration
|
|
254
|
-
accepts only:
|
|
255
|
-
|
|
256
|
-
- an absolute HTTPS origin whose pathname is exactly `/`; or
|
|
257
|
-
- an absolute HTTPS URL whose pathname is exactly `/v1/connectors/nextjs/events`.
|
|
258
|
-
|
|
259
|
-
It must have a non-empty host and no userinfo, query, or fragment. An origin is normalized to
|
|
260
|
-
`/v1/connectors/nextjs/events`. HTTP, an exact `/v1/events`, any other path, and redirects
|
|
261
|
-
(`redirect: "error"`) are rejected, so the bearer key is never sent over plaintext or to a
|
|
262
|
-
redirect-selected destination.
|
|
263
|
-
|
|
264
|
-
The non-exported loopback HTTP constructor is an in-repository fixture seam only. It targets the
|
|
265
|
-
same dedicated path, accepts a tightly bounded loopback ingest URL for tests, and is not reachable
|
|
266
|
-
from package exports, deployment configuration, environment flags, or production code.
|
|
267
|
-
|
|
268
|
-
## API key and lifecycle
|
|
269
|
-
|
|
270
|
-
By default the connector reads `STEADPHAST_API_KEY`, with `DISCOVER_API_KEY` retained only as the
|
|
271
|
-
legacy key-name fallback. An explicit `apiKeyEnvVar` reads only that variable. Keys must remain
|
|
272
|
-
server-only and must never use a `NEXT_PUBLIC_*` name.
|
|
273
|
-
|
|
274
|
-
The exported function must remain Next's Middleware or Proxy entry so Next calls it with both
|
|
275
|
-
`NextRequest` and `NextFetchEvent`. The connector always registers the delivery promise with
|
|
276
|
-
`event.waitUntil`. It does not use `after()`, a global request context, or an `@vercel/functions`
|
|
277
|
-
fallback. Do not call the wrapper from a route handler or discard the event argument.
|
|
278
|
-
|
|
279
|
-
Route exclusion runs before any header inspection. Static assets are skipped by default, except
|
|
280
|
-
`robots.txt` and `sitemap.xml`; set `captureAllPaths: true` to capture every matched path. The Next
|
|
281
|
-
matcher still controls whether the connector runs at all — exclude sensitive routes there when none
|
|
282
|
-
of their path, query, or header metadata should be captured.
|
|
283
|
-
|
|
284
|
-
## What the envelope contains
|
|
285
|
-
|
|
286
|
-
The body is one strict, closed JSON object with `envelope_version: "2"`, `deployment_mode`,
|
|
287
|
-
`captured_at`, `record_id_prefix`, `request`, and `platform`. `platform.kind` always equals
|
|
288
|
-
`deployment_mode`.
|
|
289
|
-
|
|
290
|
-
The connector still owns the safety controls that must run before a network boundary, and nothing
|
|
291
|
-
else:
|
|
292
|
-
|
|
293
|
-
- **No request body.** The connector reads only `method`, `url`, and `headers`. It never reads,
|
|
294
|
-
clones, buffers, parses, or transmits body bytes, so `bodyUsed` stays `false` and every downstream
|
|
295
|
-
body consumer remains callable.
|
|
296
|
-
- **No client-side classification.** No category, verification state, entity, confidence, evidence,
|
|
297
|
-
or flag is computed in Middleware or Proxy.
|
|
298
|
-
- **No client-side `source_ip`.** Vercel's protected forwarding item and the self-hosted ingress
|
|
299
|
-
value are copied as `platform.client_ip` evidence; promoting either to canonical `source_ip` is a
|
|
300
|
-
server decision.
|
|
301
|
-
- **No client-side `record_id`.** The connector emits only the bounded `record_id_prefix` and the
|
|
302
|
-
`x-vercel-id` candidate; the adapter derives `record_id`.
|
|
303
|
-
- **No TLS-fingerprint preference.** Vercel `ja4` and `ja3` are copied separately and independently;
|
|
304
|
-
the connector never picks one over the other.
|
|
305
|
-
- **No forwarded-chain identity.** Ordinary `x-forwarded-for` travels as bounded, untrusted
|
|
306
|
-
`request.forwarded_for` evidence only. It is never parsed into identity or authority.
|
|
307
|
-
- **No `signed_components`.** `signature` and `signature-input` are copied verbatim as bounded
|
|
308
|
-
evidence; RFC 9421 reconstruction is server-side.
|
|
214
|
+
| Option | Required | Description |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `kind` | Yes | `"vercel"` or `"self-hosted"`. The mode is never inferred from headers, environment variables, host names, or runtime globals. |
|
|
217
|
+
| `publicOrigin` | Self-hosted only | The public HTTPS origin nginx serves. See [Next.js self-hosted](#nextjs-self-hosted). |
|
|
218
|
+
| `apiUrl` | Yes | The Steadphast API origin, `https://api.steadphast.ai`. See [Destination rules](#destination-rules). |
|
|
219
|
+
| `apiKeyEnvVar` | No | Name of the server-only environment variable holding the API key. Defaults to `STEADPHAST_API_KEY` (`DISCOVER_API_KEY` is still read as a deprecated fallback; migrate to `STEADPHAST_API_KEY`). When set, only the named variable is read. A `NEXT_PUBLIC_*` name is rejected. |
|
|
220
|
+
| `captureAllPaths` | No | Static assets (scripts, styles, images, fonts, and similar) are skipped by default, except `robots.txt` and `sitemap.xml`. Set `true` to capture every path the matcher allows. |
|
|
221
|
+
| `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookies are captured unless you exclude them. |
|
|
222
|
+
| `recordIdPrefix` | No | A short label that prefixes the record IDs Steadphast assigns, useful for telling deployments apart. Defaults to `vercel-routing-middleware` or `nextjs-self-hosted`. Limit: 128 UTF-8 bytes. A longer value is not rejected at startup but makes every capture drop silently. |
|
|
223
|
+
| `timeoutMs` | No | Delivery timeout in milliseconds. Defaults to `5000`. |
|
|
309
224
|
|
|
310
|
-
|
|
225
|
+
`kind`, `publicOrigin`, `apiUrl`, and the `NEXT_PUBLIC_*` rule for `apiKeyEnvVar` are validated
|
|
226
|
+
when the entry file is evaluated: an invalid value throws a `DiscoverConfigError`, so those
|
|
227
|
+
misconfigurations fail at startup rather than silently shipping nothing. The other options are not
|
|
228
|
+
checked at startup.
|
|
229
|
+
|
|
230
|
+
Route exclusion runs before any header is inspected. The Next.js `matcher` decides whether the
|
|
231
|
+
connector runs at all: exclude routes there when none of their path, query, or header metadata
|
|
232
|
+
should be captured (form submissions, authentication callbacks, and similar action endpoints are
|
|
233
|
+
common candidates).
|
|
234
|
+
|
|
235
|
+
### Destination rules
|
|
236
|
+
|
|
237
|
+
`apiUrl` accepts only:
|
|
311
238
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
policy is unchanged: other headers, including cookies, are still captured by default, so exclude
|
|
316
|
-
them explicitly for any traffic where that is not acceptable. Excluding a header removes it from the
|
|
317
|
-
generic map only; it does not remove a value that a dedicated envelope field separately carries.
|
|
239
|
+
- an absolute HTTPS origin whose pathname is exactly `/` (`https://api.steadphast.ai`), which
|
|
240
|
+
resolves to the connector endpoint `/v1/connectors/nextjs/events`; or
|
|
241
|
+
- that exact endpoint URL, `https://api.steadphast.ai/v1/connectors/nextjs/events`.
|
|
318
242
|
|
|
319
|
-
|
|
243
|
+
It must have a non-empty host and no credentials, query, or fragment. Plain HTTP, any other path,
|
|
244
|
+
and redirects are rejected, so your API key is never sent over plaintext or to a redirected host.
|
|
320
245
|
|
|
321
|
-
|
|
322
|
-
before Fetch, and every limit is published envelope protocol semantics rather than an implementation
|
|
323
|
-
ratchet. A value that cannot be represented byte-exactly is either omitted — only when omission
|
|
324
|
-
preserves meaning — or the whole observation is dropped. Nothing is ever truncated and then
|
|
325
|
-
presented as observed bytes, and no partial capture is substituted for a value that would change
|
|
326
|
-
identity, URL, signature, or header semantics.
|
|
246
|
+
## What is captured
|
|
327
247
|
|
|
328
|
-
|
|
248
|
+
Each captured request produces one strict JSON record containing the deployment mode, capture
|
|
249
|
+
timestamp, your `recordIdPrefix`, request metadata, and platform metadata:
|
|
329
250
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
251
|
+
- **Request:** method, URL, and headers. The connector reads nothing else. It never reads, clones,
|
|
252
|
+
buffers, or transmits the request body, so every downstream body consumer in your application
|
|
253
|
+
remains callable.
|
|
254
|
+
- **Platform (Vercel):** Vercel's protected client IP, request ID (`x-vercel-id`), and the JA4 and
|
|
255
|
+
JA3 TLS-fingerprint digests when Vercel supplies them.
|
|
256
|
+
- **Platform (self-hosted):** the client IP and request ID nginx sets in `X-Steadphast-Client-Ip`
|
|
257
|
+
and `X-Steadphast-Request-Id`. Those two headers are never copied into the captured header map.
|
|
258
|
+
- **Signature evidence:** `signature` and `signature-input` headers are copied verbatim so
|
|
259
|
+
Steadphast can verify RFC 9421 Web Bot Auth signatures server-side.
|
|
333
260
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
261
|
+
Ordinary `x-forwarded-for` travels as untrusted evidence only; the connector never parses it into a
|
|
262
|
+
client identity.
|
|
263
|
+
|
|
264
|
+
### Privacy exclusions
|
|
265
|
+
|
|
266
|
+
Headers pass through two filters before anything is serialized:
|
|
267
|
+
|
|
268
|
+
```text
|
|
269
|
+
incoming headers
|
|
270
|
+
│
|
|
271
|
+
▼
|
|
272
|
+
built-in exclusions ── a fixed list of recognized credential header names
|
|
273
|
+
│ and a few name patterns (see below)
|
|
274
|
+
▼
|
|
275
|
+
your excludedHeaders ── e.g. cookie, and every application-specific credential header
|
|
276
|
+
│
|
|
277
|
+
▼
|
|
278
|
+
captured header map (everything else, cookies included unless excluded)
|
|
279
|
+
```
|
|
339
280
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
281
|
+
The built-in filter is a **limited, fixed set**, not a general secret detector. Names are compared
|
|
282
|
+
case-insensitively with separators removed (`x-api-key`, `X_Api_Key`, and `xapikey` are the same
|
|
283
|
+
name). The exact set is:
|
|
284
|
+
|
|
285
|
+
- `authorization`, `x-authorization`, and `proxy-authorization` (but not `x-proxy-authorization`);
|
|
286
|
+
- `api-key`, `api-token`, `auth-key`, `access-key`, `secret-key`, `auth-token`, `access-token`,
|
|
287
|
+
`bearer-token`, `refresh-token`, `id-token`, `session-token`, and `csrf-token`, each with or
|
|
288
|
+
without an `x-` prefix;
|
|
289
|
+
- the bare names `token` and `key` (but not `x-token` or `x-key`);
|
|
290
|
+
- any name ending in `apikey`, `authtoken`, or `accesstoken`, and any name containing `cryptogram`
|
|
291
|
+
or `networktoken`;
|
|
292
|
+
- `agentic-payment-container` and Vercel's `x-vercel-protection-bypass`.
|
|
293
|
+
|
|
294
|
+
Every other header is captured, including custom credential headers such as `x-token`,
|
|
295
|
+
`x-github-token`, `x-openai-key`, `x-internal-secret`, or `x-<vendor>-signature`. Audit the
|
|
296
|
+
headers your application, its upstream proxies, and its third-party integrations attach, and list
|
|
297
|
+
every credential-bearing name in `excludedHeaders`.
|
|
298
|
+
|
|
299
|
+
Other headers, including cookies, are captured by default, so exclude them explicitly wherever that
|
|
300
|
+
is not acceptable. Excluding a header removes it from the generic header map only; it does not
|
|
301
|
+
remove a value that a dedicated field separately carries (for example the user agent). Query
|
|
302
|
+
strings can contain sensitive values, so avoid placing secrets or personal data in public URLs.
|
|
303
|
+
|
|
304
|
+
### Size limits
|
|
305
|
+
|
|
306
|
+
Every per-field, per-header, header-count, and whole-record limit is enforced before anything is
|
|
307
|
+
sent. A value that cannot be represented exactly is either omitted, when omission preserves
|
|
308
|
+
meaning, or the whole observation is dropped. Nothing is ever truncated and presented as observed
|
|
309
|
+
data.
|
|
310
|
+
|
|
311
|
+
## Delivery behavior
|
|
312
|
+
|
|
313
|
+
Each captured request schedules exactly one `POST` to Steadphast through `waitUntil`, with a bounded
|
|
314
|
+
timeout. There is no batching, no retry, and no client-side queue. A delivery that fails, times out,
|
|
315
|
+
or is rejected drops that single event, and nothing about the request, response, or credential is
|
|
316
|
+
logged.
|
|
317
|
+
|
|
318
|
+
Delivery does not block the visitor response: the connector serializes the record, schedules the
|
|
319
|
+
`POST` through `waitUntil`, and then calls your handler. A drop, timeout, or rejection never
|
|
320
|
+
changes the response status, headers, or body, and never propagates an error into your composed
|
|
321
|
+
handler.
|
|
322
|
+
|
|
323
|
+
## Troubleshooting
|
|
324
|
+
|
|
325
|
+
- **No events appear:** confirm the API key was issued for the mode you set in `kind` (**Next.js on
|
|
326
|
+
Vercel** or **Next.js self-hosted**), that `STEADPHAST_API_KEY` is set in the deployed
|
|
327
|
+
environment, that the entry file default-exports the wrapper, that `recordIdPrefix` is within its
|
|
328
|
+
128-byte limit, and that the matcher or static-asset filter did not skip the path.
|
|
329
|
+
- **The deployment fails at startup:** `apiUrl` is not HTTPS or its path is neither `/` nor
|
|
330
|
+
`/v1/connectors/nextjs/events`, `publicOrigin` is not a bare HTTPS origin, or `apiKeyEnvVar`
|
|
331
|
+
names a `NEXT_PUBLIC_*` variable. The thrown `DiscoverConfigError` names the setting.
|
|
332
|
+
- **Nothing ships from a local `next dev` or `next start`:** in Vercel mode only HTTPS request URLs
|
|
333
|
+
are captured, so a plain `http://localhost` server never ships. Front the server with an HTTPS
|
|
334
|
+
proxy or send `X-Forwarded-Proto: https`, which Next.js honors when building the request URL.
|
|
335
|
+
- **Self-hosted events have no client IP:** nginx is not overwriting `X-Steadphast-Client-Ip`, or
|
|
336
|
+
the request bypassed nginx. Compare your configuration with the reference nginx configuration in
|
|
337
|
+
the dashboard guide and confirm the Next.js port is not reachable from outside.
|
|
338
|
+
- **Self-hosted requests answer `421`:** nginx received a `Host` or absolute-form request target
|
|
339
|
+
that does not match its configured public authority. Make the `server_name`, the `Host` checks,
|
|
340
|
+
the `proxy_set_header Host` lines, and `publicOrigin` agree with each other.
|
|
341
|
+
- **Self-hosted URLs show the wrong host:** `publicOrigin` does not match the public scheme, host,
|
|
342
|
+
and port nginx serves; it is never derived from request headers.
|
|
343
|
+
- **Cookies still appear:** confirm `excludedHeaders: ["cookie"]` is present in the deployed entry
|
|
344
|
+
file.
|
|
345
|
+
- **Your site response fails:** inspect your own handler and application route. Steadphast delivery
|
|
346
|
+
failures are swallowed and never change the response.
|
|
347
|
+
|
|
348
|
+
## Upgrading
|
|
349
|
+
|
|
350
|
+
- **0.5.3** Documentation and metadata only; no runtime change.
|
|
351
|
+
- **0.5.2** changes documentation and package metadata only; the shipped code is identical to
|
|
352
|
+
0.5.1, and no upgrade action is needed.
|
|
353
|
+
- **0.5.1** is the first published version of this package.
|
|
344
354
|
|
|
345
355
|
## License
|
|
346
356
|
|
|
347
|
-
Apache-2.0. See the `LICENSE` and `NOTICE` files shipped with the package.
|
|
348
|
-
package and the Steadphast Discover connector-core source bundled into `dist/index.js`; it does not
|
|
349
|
-
extend to any other part of the Steadphast Discover repository or product.
|
|
357
|
+
Apache-2.0. See the `LICENSE` and `NOTICE` files shipped with the package.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steadphast/connector-nextjs",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.5.
|
|
3
|
+
"description": "Next.js Middleware and Proxy connector for Steadphast: captures request metadata before it reaches your app and sends it to Steadphast for AI and bot traffic classification, without touching the response.",
|
|
4
|
+
"version": "0.5.3",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Steadphast",
|
|
7
7
|
"homepage": "https://steadphast.ai",
|
|
@@ -29,6 +29,15 @@
|
|
|
29
29
|
"NOTICE",
|
|
30
30
|
"README.md"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && esbuild src/index.ts src/internal-loopback.ts --bundle --format=esm --platform=neutral --target=es2022 --outdir=dist --external:next/server",
|
|
34
|
+
"prepublishOnly": "node -e \"if(process.env.STEADPHAST_CONNECTOR_RELEASE!=='1'){console.error('refusing to publish: only the publish-connector-nextjs workflow releases this package (it sets STEADPHAST_CONNECTOR_RELEASE=1 after every gate passes).');process.exit(1)}\"",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"lint": "biome check src package.json tsconfig.json tsconfig.build.json vitest.config.ts",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:coverage": "vitest run --coverage",
|
|
39
|
+
"test:perf": "vitest run --reporter=verbose --slowTestThreshold=300"
|
|
40
|
+
},
|
|
32
41
|
"main": "./dist/index.js",
|
|
33
42
|
"types": "./dist/index.d.ts",
|
|
34
43
|
"exports": {
|
|
@@ -42,21 +51,13 @@
|
|
|
42
51
|
"next": "^15.0.0 || ^16.0.0"
|
|
43
52
|
},
|
|
44
53
|
"devDependencies": {
|
|
54
|
+
"@discover/connector-core": "workspace:*",
|
|
45
55
|
"@edge-runtime/vm": "5.0.0",
|
|
46
56
|
"@vitest/coverage-v8": "4.1.10",
|
|
47
57
|
"esbuild": "0.28.1",
|
|
48
58
|
"next": "15.5.23",
|
|
49
59
|
"react": "19.2.8",
|
|
50
60
|
"react-dom": "19.2.8",
|
|
51
|
-
"vitest": "4.1.10"
|
|
52
|
-
"@discover/connector-core": "0.2.1"
|
|
53
|
-
},
|
|
54
|
-
"scripts": {
|
|
55
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json && esbuild src/index.ts src/internal-loopback.ts --bundle --format=esm --platform=neutral --target=es2022 --outdir=dist --external:next/server",
|
|
56
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
57
|
-
"lint": "biome check src package.json tsconfig.json tsconfig.build.json vitest.config.ts",
|
|
58
|
-
"test": "vitest run",
|
|
59
|
-
"test:coverage": "vitest run --coverage",
|
|
60
|
-
"test:perf": "vitest run --reporter=verbose --slowTestThreshold=300"
|
|
61
|
+
"vitest": "4.1.10"
|
|
61
62
|
}
|
|
62
|
-
}
|
|
63
|
+
}
|