@steadphast/connector-nextjs 0.5.2 → 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.
Files changed (2) hide show
  1. package/README.md +39 -65
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,10 +2,13 @@
2
2
 
3
3
  The Next.js connector for [Steadphast](https://steadphast.ai). It runs in your Next.js Middleware
4
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.
5
+ application, and sends a bounded, sanitized record of each request to Steadphast in the background.
6
6
  Steadphast classifies the traffic server-side: the connector never reads a request body, never runs
7
7
  any classification, and never changes the response your visitor receives.
8
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
+
9
12
  ```text
10
13
  Visitor / bot Your Next.js deployment Steadphast
11
14
  ───────────── ─────────────────────── ──────────
@@ -15,8 +18,8 @@ any classification, and never changes the response your visitor receives.
15
18
  │ │ 2. read method, URL, headers only │
16
19
  │ │ 3. drop recognized credential headers │
17
20
  │ │ + your excludedHeaders │
18
- │ │ 4. build one bounded envelope │
19
- │ │ 5. waitUntil(POST envelope) ─────────►│ classify
21
+ │ │ 4. build one bounded record │
22
+ │ │ 5. waitUntil(POST record) ───────────►│ classify
20
23
  │ │ 6. run your handler, then the app │ + store
21
24
  │◄───────────────────────────────┤ response (unchanged by the connector) │
22
25
  │ │ │
@@ -28,16 +31,13 @@ authoritative terms.
28
31
 
29
32
  ## Requirements
30
33
 
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.
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.
35
38
  - 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).
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.
41
41
 
42
42
  ## Install
43
43
 
@@ -55,7 +55,7 @@ The package has no runtime dependencies; install no other Steadphast package. On
55
55
  earlier, `npm install` stops with `ERESOLVE` and `pnpm add` warns about an unmet peer: upgrade
56
56
  Next.js rather than forcing the install.
57
57
 
58
- ## Quick start on Vercel
58
+ ## Quick start: Next.js on Vercel
59
59
 
60
60
  ### Next.js 15: `middleware.ts`
61
61
 
@@ -130,13 +130,15 @@ Keep the wrapper as the file's default export so Next.js calls it with both the
130
130
  `NextFetchEvent`; delivery is scheduled through `event.waitUntil`. Do not call the wrapper from a
131
131
  route handler, and do not drop the event argument.
132
132
 
133
- ## Self-hosted Next.js
133
+ ## Next.js self-hosted
134
134
 
135
135
  Self-hosted mode is for a Next.js application started with `next start` on a server, virtual
136
136
  machine, or container you operate, with nginx terminating client TLS directly in front of it. It
137
137
  is the same package configured with `kind: "self-hosted"`. Use it in either entry file; for
138
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).
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>.
140
142
 
141
143
  ```ts
142
144
  import { withDiscover } from "@steadphast/connector-nextjs";
@@ -160,7 +162,7 @@ export const config = {
160
162
  of the captured request URL's origin. It must be one HTTPS origin with no credentials, path, query,
161
163
  or fragment, and it must match the public authority nginx serves exactly. It is separate from
162
164
  `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**.
165
+ process, issued with **Used with** set to **Next.js self-hosted**.
164
166
 
165
167
  ### The nginx trust boundary
166
168
 
@@ -172,10 +174,10 @@ is reachable without nginx, or a proxy that passes client headers through, lets
172
174
  the IP recorded for its requests.
173
175
 
174
176
  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:
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:
179
181
 
180
182
  - terminates client TLS directly on TLS 1.2 or 1.3 and refuses a handshake without the configured
181
183
  server name;
@@ -212,12 +214,12 @@ type DiscoverNextConfig = (
212
214
  | Option | Required | Description |
213
215
  |---|---|---|
214
216
  | `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. |
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. |
218
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. |
219
221
  | `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. |
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. |
221
223
  | `timeoutMs` | No | Delivery timeout in milliseconds. Defaults to `5000`. |
222
224
 
223
225
  `kind`, `publicOrigin`, `apiUrl`, and the `NEXT_PUBLIC_*` rule for `apiKeyEnvVar` are validated
@@ -243,7 +245,7 @@ and redirects are rejected, so your API key is never sent over plaintext or to a
243
245
 
244
246
  ## What is captured
245
247
 
246
- Each captured request produces one strict JSON envelope containing the deployment mode, capture
248
+ Each captured request produces one strict JSON record containing the deployment mode, capture
247
249
  timestamp, your `recordIdPrefix`, request metadata, and platform metadata:
248
250
 
249
251
  - **Request:** method, URL, and headers. The connector reads nothing else. It never reads, clones,
@@ -296,13 +298,12 @@ every credential-bearing name in `excludedHeaders`.
296
298
 
297
299
  Other headers, including cookies, are captured by default, so exclude them explicitly wherever that
298
300
  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.
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.
302
303
 
303
304
  ### Size limits
304
305
 
305
- Every per-field, per-header, header-count, and whole-envelope limit is enforced before anything is
306
+ Every per-field, per-header, header-count, and whole-record limit is enforced before anything is
306
307
  sent. A value that cannot be represented exactly is either omitted, when omission preserves
307
308
  meaning, or the whole observation is dropped. Nothing is ever truncated and presented as observed
308
309
  data.
@@ -314,17 +315,17 @@ timeout. There is no batching, no retry, and no client-side queue. A delivery th
314
315
  or is rejected drops that single event, and nothing about the request, response, or credential is
315
316
  logged.
316
317
 
317
- Delivery does not block the visitor response: the connector serializes the envelope, schedules the
318
+ Delivery does not block the visitor response: the connector serializes the record, schedules the
318
319
  `POST` through `waitUntil`, and then calls your handler. A drop, timeout, or rejection never
319
320
  changes the response status, headers, or body, and never propagates an error into your composed
320
321
  handler.
321
322
 
322
323
  ## Troubleshooting
323
324
 
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.
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.
328
329
  - **The deployment fails at startup:** `apiUrl` is not HTTPS or its path is neither `/` nor
329
330
  `/v1/connectors/nextjs/events`, `publicOrigin` is not a bare HTTPS origin, or `apiKeyEnvVar`
330
331
  names a `NEXT_PUBLIC_*` variable. The thrown `DiscoverConfigError` names the setting.
@@ -332,8 +333,8 @@ handler.
332
333
  are captured, so a plain `http://localhost` server never ships. Front the server with an HTTPS
333
334
  proxy or send `X-Forwarded-Proto: https`, which Next.js honors when building the request URL.
334
335
  - **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.
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.
337
338
  - **Self-hosted requests answer `421`:** nginx received a `Host` or absolute-form request target
338
339
  that does not match its configured public authority. Make the `server_name`, the `Host` checks,
339
340
  the `proxy_set_header Host` lines, and `publicOrigin` agree with each other.
@@ -346,37 +347,10 @@ handler.
346
347
 
347
348
  ## Upgrading
348
349
 
350
+ - **0.5.3** Documentation and metadata only; no runtime change.
349
351
  - **0.5.2** changes documentation and package metadata only; the shipped code is identical to
350
352
  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
- ```
376
-
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.
353
+ - **0.5.1** is the first published version of this package.
380
354
 
381
355
  ## License
382
356
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@steadphast/connector-nextjs",
3
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",
4
+ "version": "0.5.3",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Steadphast",
7
7
  "homepage": "https://steadphast.ai",