@steadphast/connector-nextjs 0.5.1 → 0.5.2
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 +298 -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
|
-
fallback. One consequence: a Vercel request with no `x-vercel-id` whose `x-forwarded-for` is
|
|
25
|
-
unrepresentable now drops entirely, because the fallback hashes that value (0.4.0 kept it when a
|
|
26
|
-
public ID was present). Self-hosted envelopes are unchanged.
|
|
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 one sanitized evidence envelope per 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
|
+
```text
|
|
10
|
+
Visitor / bot Your Next.js deployment Steadphast
|
|
11
|
+
───────────── ─────────────────────── ──────────
|
|
12
|
+
│ request │ │
|
|
13
|
+
├───────────────────────────────►│ middleware.ts / proxy.ts │
|
|
14
|
+
│ │ 1. skip static assets │
|
|
15
|
+
│ │ 2. read method, URL, headers only │
|
|
16
|
+
│ │ 3. drop recognized credential headers │
|
|
17
|
+
│ │ + your excludedHeaders │
|
|
18
|
+
│ │ 4. build one bounded envelope │
|
|
19
|
+
│ │ 5. waitUntil(POST envelope) ─────────►│ classify
|
|
20
|
+
│ │ 6. run your handler, then the app │ + store
|
|
21
|
+
│◄───────────────────────────────┤ response (unchanged by the connector) │
|
|
22
|
+
│ │ │
|
|
23
|
+
Event appears in Explore ◄┘
|
|
58
24
|
```
|
|
59
25
|
|
|
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
|
-
```
|
|
26
|
+
Licensed under Apache-2.0. The `LICENSE` and `NOTICE` files shipped with the package are the
|
|
27
|
+
authoritative terms.
|
|
95
28
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
```sh
|
|
99
|
-
pnpm --filter @steadphast/connector-nextjs build
|
|
100
|
-
```
|
|
29
|
+
## Requirements
|
|
101
30
|
|
|
102
|
-
|
|
103
|
-
|
|
31
|
+
- Next.js 15 or 16. Next.js is the only peer dependency (`^15.0.0 || ^16.0.0`), so the package
|
|
32
|
+
installs against the Next.js version your application already pins. The tested and supported
|
|
33
|
+
versions are Next.js **15.5.23** (`middleware.ts`) and **16.3.2** (`proxy.ts`); other releases on
|
|
34
|
+
those two lines are expected to work. Next.js 14 and earlier are not supported.
|
|
35
|
+
- A Steadphast API key, created in the dashboard under **Settings → API keys** with **Used with**
|
|
36
|
+
set to the mode you deploy: **Vercel Routing Middleware** or **Self-hosted Next.js**. A key issued
|
|
37
|
+
for one mode is rejected by the other.
|
|
38
|
+
- Version **0.5.1 or later** of this package, the first version published under this name. The
|
|
39
|
+
earlier `@discover/connector-nextjs` package (0.5.0 and older) is retired; see
|
|
40
|
+
[Upgrading](#upgrading).
|
|
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
|
-
|
|
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.
|
|
57
|
+
|
|
58
|
+
## Quick start on Vercel
|
|
136
59
|
|
|
137
|
-
|
|
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,287 @@ export const config = {
|
|
|
188
97
|
};
|
|
189
98
|
```
|
|
190
99
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
100
|
+
### Set the API key
|
|
101
|
+
|
|
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.
|
|
105
|
+
|
|
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.
|
|
194
108
|
|
|
195
|
-
|
|
109
|
+
### Keep your own Middleware or Proxy logic
|
|
196
110
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
`proxy.ts` is already Node-only and does not accept the `runtime` option.
|
|
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
|
+
## Self-hosted Next.js
|
|
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).
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
209
143
|
|
|
210
144
|
export default withDiscover({
|
|
211
145
|
kind: "self-hosted",
|
|
212
146
|
publicOrigin: "https://www.example.com",
|
|
213
|
-
apiUrl,
|
|
147
|
+
apiUrl: "https://api.steadphast.ai",
|
|
214
148
|
excludedHeaders: ["cookie"],
|
|
215
149
|
recordIdPrefix: "nextjs-self-hosted-production",
|
|
216
150
|
});
|
|
217
151
|
|
|
218
152
|
export const config = {
|
|
153
|
+
// Next.js 15 middleware.ts only; remove this line in Next.js 16 proxy.ts.
|
|
154
|
+
runtime: "nodejs",
|
|
219
155
|
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
220
156
|
};
|
|
221
157
|
```
|
|
222
158
|
|
|
223
|
-
`publicOrigin` is the
|
|
224
|
-
|
|
225
|
-
and it must match
|
|
159
|
+
`publicOrigin` is the public scheme, host, and port your visitors use, and it is the only source
|
|
160
|
+
of the captured request URL's origin. It must be one HTTPS origin with no credentials, path, query,
|
|
161
|
+
or fragment, and it must match the public authority nginx serves exactly. It is separate from
|
|
162
|
+
`apiUrl`. The API key comes from the `STEADPHAST_API_KEY` environment variable of the `next start`
|
|
163
|
+
process, issued with **Used with** set to **Self-hosted Next.js**.
|
|
164
|
+
|
|
165
|
+
### The nginx trust boundary
|
|
166
|
+
|
|
167
|
+
In this mode the connector trusts exactly two request headers, `X-Steadphast-Client-Ip` and
|
|
168
|
+
`X-Steadphast-Request-Id`, and only because nginx overwrites both on every proxied request from
|
|
169
|
+
facts nginx itself established. The connector never falls back to `X-Forwarded-For`, `X-Real-IP`,
|
|
170
|
+
the public `x-request-id`, any `x-vercel-*` header, or the socket address. A Next.js listener that
|
|
171
|
+
is reachable without nginx, or a proxy that passes client headers through, lets any client forge
|
|
172
|
+
the IP recorded for its requests.
|
|
173
|
+
|
|
174
|
+
The supported topology is exactly one nginx directly in front of the application, and the
|
|
175
|
+
supported configuration is the complete reference `nginx.conf` published in the Steadphast
|
|
176
|
+
dashboard under **Docs → Integrations → Self-hosted Next.js**, which Steadphast tests on every
|
|
177
|
+
change. Start from that file and change only the values it lists (public host and port,
|
|
178
|
+
certificate paths, and the loopback `proxy_pass` address). It:
|
|
179
|
+
|
|
180
|
+
- terminates client TLS directly on TLS 1.2 or 1.3 and refuses a handshake without the configured
|
|
181
|
+
server name;
|
|
182
|
+
- accepts exactly one public host and port and answers `421` to every other `Host` or absolute-form
|
|
183
|
+
request target;
|
|
184
|
+
- overwrites `Host`, `X-Forwarded-Host`, and `X-Forwarded-Proto` from validated routing and
|
|
185
|
+
transport facts;
|
|
186
|
+
- overwrites `X-Steadphast-Client-Ip` with the direct TCP peer (`$remote_addr`) and
|
|
187
|
+
`X-Steadphast-Request-Id` with nginx's own `$request_id`, replacing every client-supplied copy;
|
|
188
|
+
- appends its peer to `X-Forwarded-For`, which the connector keeps only as untrusted evidence.
|
|
189
|
+
|
|
190
|
+
Bind the application to loopback (for example `next start -H 127.0.0.1 -p 3000`) and confirm from
|
|
191
|
+
outside the host that the Next.js port is not reachable. A CDN, load balancer, or second proxy in
|
|
192
|
+
front of nginx, a public direct Next.js port, and pass-through internal headers are unsupported:
|
|
193
|
+
the connector cannot detect them, and a CDN in front makes the recorded client IP that CDN's
|
|
194
|
+
address. No TLS fingerprint is available in this mode.
|
|
195
|
+
|
|
196
|
+
## Configuration reference
|
|
226
197
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
198
|
+
```ts
|
|
199
|
+
type DiscoverNextConfig = (
|
|
200
|
+
| { kind: "vercel" }
|
|
201
|
+
| { kind: "self-hosted"; publicOrigin: string }
|
|
202
|
+
) & {
|
|
203
|
+
apiUrl: string;
|
|
204
|
+
apiKeyEnvVar?: string;
|
|
205
|
+
captureAllPaths?: boolean;
|
|
206
|
+
excludedHeaders?: ReadonlyArray<string>;
|
|
207
|
+
recordIdPrefix?: string;
|
|
208
|
+
timeoutMs?: number;
|
|
209
|
+
};
|
|
237
210
|
```
|
|
238
211
|
|
|
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.
|
|
212
|
+
| Option | Required | Description |
|
|
213
|
+
|---|---|---|
|
|
214
|
+
| `kind` | Yes | `"vercel"` or `"self-hosted"`. The mode is never inferred from headers, environment variables, host names, or runtime globals. |
|
|
215
|
+
| `publicOrigin` | Self-hosted only | The public HTTPS origin nginx serves. See [Self-hosted Next.js](#self-hosted-nextjs). |
|
|
216
|
+
| `apiUrl` | Yes | The Steadphast API origin, normally `https://api.steadphast.ai`. See [Destination rules](#destination-rules). |
|
|
217
|
+
| `apiKeyEnvVar` | No | Name of the server-only environment variable holding the API key. Defaults to `STEADPHAST_API_KEY`, with `DISCOVER_API_KEY` accepted as a deprecated fallback. When set, only the named variable is read. A `NEXT_PUBLIC_*` name is rejected. |
|
|
218
|
+
| `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. |
|
|
219
|
+
| `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookies are captured unless you exclude them. |
|
|
220
|
+
| `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`. Must be at most 128 UTF-8 bytes; a longer value is not rejected at startup but makes every capture drop silently. |
|
|
221
|
+
| `timeoutMs` | No | Delivery timeout in milliseconds. Defaults to `5000`. |
|
|
309
222
|
|
|
310
|
-
|
|
223
|
+
`kind`, `publicOrigin`, `apiUrl`, and the `NEXT_PUBLIC_*` rule for `apiKeyEnvVar` are validated
|
|
224
|
+
when the entry file is evaluated: an invalid value throws a `DiscoverConfigError`, so those
|
|
225
|
+
misconfigurations fail at startup rather than silently shipping nothing. The other options are not
|
|
226
|
+
checked at startup.
|
|
227
|
+
|
|
228
|
+
Route exclusion runs before any header is inspected. The Next.js `matcher` decides whether the
|
|
229
|
+
connector runs at all: exclude routes there when none of their path, query, or header metadata
|
|
230
|
+
should be captured (form submissions, authentication callbacks, and similar action endpoints are
|
|
231
|
+
common candidates).
|
|
232
|
+
|
|
233
|
+
### Destination rules
|
|
311
234
|
|
|
312
|
-
|
|
313
|
-
credential/auth, card-network executory, and deployment-bypass classes; the case-insensitive
|
|
314
|
-
operator `excludedHeaders`; and — in self-hosted mode — the internal ingress headers. ADR 0017
|
|
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.
|
|
235
|
+
`apiUrl` accepts only:
|
|
318
236
|
|
|
319
|
-
|
|
237
|
+
- an absolute HTTPS origin whose pathname is exactly `/` (`https://api.steadphast.ai`), which
|
|
238
|
+
resolves to the connector endpoint `/v1/connectors/nextjs/events`; or
|
|
239
|
+
- that exact endpoint URL, `https://api.steadphast.ai/v1/connectors/nextjs/events`.
|
|
320
240
|
|
|
321
|
-
|
|
322
|
-
|
|
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.
|
|
241
|
+
It must have a non-empty host and no credentials, query, or fragment. Plain HTTP, any other path,
|
|
242
|
+
and redirects are rejected, so your API key is never sent over plaintext or to a redirected host.
|
|
327
243
|
|
|
328
|
-
##
|
|
244
|
+
## What is captured
|
|
329
245
|
|
|
330
|
-
Each captured request produces
|
|
331
|
-
|
|
332
|
-
particular, never a fallback to `/v1/events`.
|
|
246
|
+
Each captured request produces one strict JSON envelope containing the deployment mode, capture
|
|
247
|
+
timestamp, your `recordIdPrefix`, request metadata, and platform metadata:
|
|
333
248
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
249
|
+
- **Request:** method, URL, and headers. The connector reads nothing else. It never reads, clones,
|
|
250
|
+
buffers, or transmits the request body, so every downstream body consumer in your application
|
|
251
|
+
remains callable.
|
|
252
|
+
- **Platform (Vercel):** Vercel's protected client IP, request ID (`x-vercel-id`), and the JA4 and
|
|
253
|
+
JA3 TLS-fingerprint digests when Vercel supplies them.
|
|
254
|
+
- **Platform (self-hosted):** the client IP and request ID nginx sets in `X-Steadphast-Client-Ip`
|
|
255
|
+
and `X-Steadphast-Request-Id`. Those two headers are never copied into the captured header map.
|
|
256
|
+
- **Signature evidence:** `signature` and `signature-input` headers are copied verbatim so
|
|
257
|
+
Steadphast can verify RFC 9421 Web Bot Auth signatures server-side.
|
|
258
|
+
|
|
259
|
+
Ordinary `x-forwarded-for` travels as untrusted evidence only; the connector never parses it into a
|
|
260
|
+
client identity.
|
|
261
|
+
|
|
262
|
+
### Privacy exclusions
|
|
263
|
+
|
|
264
|
+
Headers pass through two filters before anything is serialized:
|
|
265
|
+
|
|
266
|
+
```text
|
|
267
|
+
incoming headers
|
|
268
|
+
│
|
|
269
|
+
▼
|
|
270
|
+
built-in exclusions ── a fixed list of recognized credential header names
|
|
271
|
+
│ and a few name patterns (see below)
|
|
272
|
+
▼
|
|
273
|
+
your excludedHeaders ── e.g. cookie, and every application-specific credential header
|
|
274
|
+
│
|
|
275
|
+
▼
|
|
276
|
+
captured header map (everything else, cookies included unless excluded)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The built-in filter is a **limited, fixed set**, not a general secret detector. Names are compared
|
|
280
|
+
case-insensitively with separators removed (`x-api-key`, `X_Api_Key`, and `xapikey` are the same
|
|
281
|
+
name). The exact set is:
|
|
282
|
+
|
|
283
|
+
- `authorization`, `x-authorization`, and `proxy-authorization` (but not `x-proxy-authorization`);
|
|
284
|
+
- `api-key`, `api-token`, `auth-key`, `access-key`, `secret-key`, `auth-token`, `access-token`,
|
|
285
|
+
`bearer-token`, `refresh-token`, `id-token`, `session-token`, and `csrf-token`, each with or
|
|
286
|
+
without an `x-` prefix;
|
|
287
|
+
- the bare names `token` and `key` (but not `x-token` or `x-key`);
|
|
288
|
+
- any name ending in `apikey`, `authtoken`, or `accesstoken`, and any name containing `cryptogram`
|
|
289
|
+
or `networktoken`;
|
|
290
|
+
- `agentic-payment-container` and Vercel's `x-vercel-protection-bypass`.
|
|
291
|
+
|
|
292
|
+
Every other header is captured, including custom credential headers such as `x-token`,
|
|
293
|
+
`x-github-token`, `x-openai-key`, `x-internal-secret`, or `x-<vendor>-signature`. Audit the
|
|
294
|
+
headers your application, its upstream proxies, and its third-party integrations attach, and list
|
|
295
|
+
every credential-bearing name in `excludedHeaders`.
|
|
296
|
+
|
|
297
|
+
Other headers, including cookies, are captured by default, so exclude them explicitly wherever that
|
|
298
|
+
is not acceptable. Excluding a header removes it from the generic header map only; it does not
|
|
299
|
+
remove a value that a dedicated envelope field separately carries (for example the user agent).
|
|
300
|
+
Query strings can contain sensitive values, so avoid placing secrets or personal data in public
|
|
301
|
+
URLs.
|
|
302
|
+
|
|
303
|
+
### Size limits
|
|
304
|
+
|
|
305
|
+
Every per-field, per-header, header-count, and whole-envelope limit is enforced before anything is
|
|
306
|
+
sent. A value that cannot be represented exactly is either omitted, when omission preserves
|
|
307
|
+
meaning, or the whole observation is dropped. Nothing is ever truncated and presented as observed
|
|
308
|
+
data.
|
|
309
|
+
|
|
310
|
+
## Delivery behavior
|
|
311
|
+
|
|
312
|
+
Each captured request schedules exactly one `POST` to Steadphast through `waitUntil`, with a bounded
|
|
313
|
+
timeout. There is no batching, no retry, and no client-side queue. A delivery that fails, times out,
|
|
314
|
+
or is rejected drops that single event, and nothing about the request, response, or credential is
|
|
315
|
+
logged.
|
|
316
|
+
|
|
317
|
+
Delivery does not block the visitor response: the connector serializes the envelope, schedules the
|
|
318
|
+
`POST` through `waitUntil`, and then calls your handler. A drop, timeout, or rejection never
|
|
319
|
+
changes the response status, headers, or body, and never propagates an error into your composed
|
|
320
|
+
handler.
|
|
321
|
+
|
|
322
|
+
## Troubleshooting
|
|
323
|
+
|
|
324
|
+
- **No events appear:** confirm the API key's **Used with** label matches the configured `kind`,
|
|
325
|
+
that `STEADPHAST_API_KEY` is set in the deployed environment, that the entry file default-exports
|
|
326
|
+
the wrapper, that `recordIdPrefix` is within 128 bytes, and that the matcher or static-asset
|
|
327
|
+
filter did not skip the path.
|
|
328
|
+
- **The deployment fails at startup:** `apiUrl` is not HTTPS or its path is neither `/` nor
|
|
329
|
+
`/v1/connectors/nextjs/events`, `publicOrigin` is not a bare HTTPS origin, or `apiKeyEnvVar`
|
|
330
|
+
names a `NEXT_PUBLIC_*` variable. The thrown `DiscoverConfigError` names the setting.
|
|
331
|
+
- **Nothing ships from a local `next dev` or `next start`:** in Vercel mode only HTTPS request URLs
|
|
332
|
+
are captured, so a plain `http://localhost` server never ships. Front the server with an HTTPS
|
|
333
|
+
proxy or send `X-Forwarded-Proto: https`, which Next.js honors when building the request URL.
|
|
334
|
+
- **Self-hosted events have no client IP:** nginx is not overwriting `X-Steadphast-Client-Ip`, or
|
|
335
|
+
the request bypassed nginx. Compare your configuration with the reference in the dashboard guide
|
|
336
|
+
and confirm the Next.js port is not reachable from outside.
|
|
337
|
+
- **Self-hosted requests answer `421`:** nginx received a `Host` or absolute-form request target
|
|
338
|
+
that does not match its configured public authority. Make the `server_name`, the `Host` checks,
|
|
339
|
+
the `proxy_set_header Host` lines, and `publicOrigin` agree with each other.
|
|
340
|
+
- **Self-hosted URLs show the wrong host:** `publicOrigin` does not match the public scheme, host,
|
|
341
|
+
and port nginx serves; it is never derived from request headers.
|
|
342
|
+
- **Cookies still appear:** confirm `excludedHeaders: ["cookie"]` is present in the deployed entry
|
|
343
|
+
file.
|
|
344
|
+
- **Your site response fails:** inspect your own handler and application route. Steadphast delivery
|
|
345
|
+
failures are swallowed and never change the response.
|
|
346
|
+
|
|
347
|
+
## Upgrading
|
|
348
|
+
|
|
349
|
+
- **0.5.2** changes documentation and package metadata only; the shipped code is identical to
|
|
350
|
+
0.5.1, and no upgrade action is needed.
|
|
351
|
+
- **0.5.1** is the first version published as `@steadphast/connector-nextjs`. Deployments on the
|
|
352
|
+
retired `@discover/connector-nextjs` package (0.5.0 and older) must replace the dependency and
|
|
353
|
+
the import specifier; the `withDiscover` API and configuration are otherwise unchanged from
|
|
354
|
+
0.5.0.
|
|
355
|
+
- **0.5.0** sends envelope version 2, the only version the Steadphast API accepts. Deployments on
|
|
356
|
+
0.4.x or earlier must upgrade; their envelopes are rejected.
|
|
357
|
+
- **0.4.0** changed the public API: `withDiscover` requires an explicit `kind` and `apiUrl`; the
|
|
358
|
+
package root exports `withDiscover`, its configuration types, `DiscoverConfigError`, the two
|
|
359
|
+
connector-assertion constants, and the two self-hosted header-name constants, and nothing else;
|
|
360
|
+
and `apiUrl` must target the connector endpoint described under
|
|
361
|
+
[Destination rules](#destination-rules).
|
|
362
|
+
|
|
363
|
+
## Developing this package
|
|
364
|
+
|
|
365
|
+
The source lives in the Steadphast repository at `ts/packages/connector-nextjs`, next to the
|
|
366
|
+
`@discover/connector-core` package it bundles. The package's whole job is to emit the sanitized
|
|
367
|
+
envelope described above; turning that envelope into a Steadphast event, and every enrichment and
|
|
368
|
+
classification step, happens only on the Steadphast server, so nothing here depends on or
|
|
369
|
+
duplicates the server's event model. Inside the repository, which runs every command through its
|
|
370
|
+
Nix development shell:
|
|
371
|
+
|
|
372
|
+
```sh
|
|
373
|
+
nix develop -c pnpm -C ts --filter @steadphast/connector-nextjs test
|
|
374
|
+
nix develop -c pnpm -C ts --filter @steadphast/connector-nextjs build
|
|
375
|
+
```
|
|
339
376
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
lifecycle description, not a sustained-load guarantee.
|
|
377
|
+
The `DEVELOPMENT.md` beside the source (not shipped in the npm tarball) covers the design
|
|
378
|
+
references, the canonical-contract seam, the monorepo build, the release process, and the rollout
|
|
379
|
+
history.
|
|
344
380
|
|
|
345
381
|
## License
|
|
346
382
|
|
|
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.
|
|
383
|
+
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.2",
|
|
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
|
+
}
|