@steadphast/connector-nextjs 0.5.4 → 0.7.0

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/README.md CHANGED
@@ -9,6 +9,16 @@ any classification, and never changes the response your visitor receives.
9
9
  The package is one connector with two modes: **Next.js on Vercel** (`kind: "vercel"`) and
10
10
  **Next.js self-hosted** (`kind: "self-hosted"`).
11
11
 
12
+ The optional App Router `DiscoverCollector` component has independent T0 and Family C controls.
13
+ The unreleased Family C addition ships OFF at the API (`BEHAVIORAL_ENABLED` defaults false) and
14
+ does nothing useful until Steadphast announces enablement; do not configure routes yet. Once
15
+ enabled it uses own mode, not visitor permission: exact nonsensitive routes are required, and
16
+ affirmative visitor consent is the default (a no-prompt `notice` basis applies only where Steadphast
17
+ has recorded it for the workspace and `behavioral.consentBasis` is also `"notice"`). Timing
18
+ defaults false and needs both the site and the workspace switch. See
19
+ [Family C own collection](#family-c-own-collection-unreleased); this is not a claim that the
20
+ published 0.6.0 artifact already contains Family C.
21
+
12
22
  ```text
13
23
  Visitor / bot Your Next.js deployment Steadphast
14
24
  ───────────── ─────────────────────── ──────────
@@ -31,10 +41,9 @@ authoritative terms.
31
41
 
32
42
  ## Requirements
33
43
 
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.
44
+ - Next.js 15 or 16 (`^15.0.0 || ^16.0.0`) and React 19 (`^19.0.0`) are peer dependencies.
45
+ The exact-runtime fixtures pin Next.js 15.5.28 (`middleware.ts`) and 16.3.2 (`proxy.ts`);
46
+ other releases on those two lines are expected to work. Next.js 14 and earlier are unsupported.
38
47
  - A Steadphast API key, created in the dashboard under **Settings → API keys** with **Used with**
39
48
  set to the mode you deploy: **Next.js on Vercel** or **Next.js self-hosted**. A key is issued for
40
49
  one deployment mode and is rejected by the other.
@@ -385,6 +394,12 @@ type DiscoverNextConfig = (
385
394
  excludedHeaders?: ReadonlyArray<string>;
386
395
  recordIdPrefix?: string;
387
396
  timeoutMs?: number;
397
+ collector?: boolean;
398
+ behavioral?: {
399
+ mode?: "own" | "off" | "partner";
400
+ timing?: boolean;
401
+ routes?: ReadonlyArray<string>;
402
+ };
388
403
  };
389
404
  ```
390
405
 
@@ -395,9 +410,11 @@ type DiscoverNextConfig = (
395
410
  | `apiUrl` | Yes | The Steadphast API origin, `https://api.steadphast.ai`. See [Destination rules](#destination-rules). |
396
411
  | `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. |
397
412
  | `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. |
398
- | `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookies are captured unless you exclude them. |
413
+ | `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookie values are never sent; list `cookie` or `set-cookie` to also drop the cookie names taken from that header (see [Cookies, query strings, and Referer](#cookies-query-strings-and-referer)). |
399
414
  | `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. |
400
415
  | `timeoutMs` | No | Delivery timeout in milliseconds. Defaults to `5000`. |
416
+ | `collector` | No | T0 remains explicit opt-in with `true`. An explicit `false` also vetoes Family C; leaving it undefined permits independently configured Family C without T0. |
417
+ | `behavioral` | No | Inert until Steadphast enables the API switch (`BEHAVIORAL_ENABLED` defaults false); until then approved routes only add `no-store` and a policy fetch that answers off. Once enabled: own mode, timing/default-false, exact nonsensitive `routes` required. `off` and `partner` install no own collector. Workspace/API OFF and visitor consent remain independent controls. `consentBasis: "notice"` starts the window without a consent callback only when Steadphast has also set the workspace's audited consent basis to `notice`; the default is `affirmative`. `pathCapture: true` adds click target geometry (no label, text or element identity) to click records, and only when the workspace's path capture setting is also on; default off. |
401
418
 
402
419
  `kind`, `publicOrigin`, `apiUrl`, and the `NEXT_PUBLIC_*` rule for `apiKeyEnvVar` are validated
403
420
  when the entry file is evaluated: an invalid value throws a `DiscoverConfigError`, so those
@@ -423,11 +440,17 @@ and redirects are rejected, so your API key is never sent over plaintext or to a
423
440
  ## What is captured
424
441
 
425
442
  Each captured request produces one strict JSON record containing the deployment mode, capture
426
- timestamp, your `recordIdPrefix`, request metadata, and platform metadata:
443
+ timestamp, your `recordIdPrefix`, request metadata and platform metadata. With `collector: true`,
444
+ an eligible forwarded document navigation appends `collector_served: true` and `served_at`
445
+ (Unix milliseconds). These fields report the connector's serving intent, not proof that the
446
+ component rendered or the script executed. Every other envelope, including collector-off
447
+ installations, ends at `platform` as in 0.5.x.
427
448
 
428
449
  - **Request:** method, URL, and headers. The connector reads nothing else. It never reads, clones,
429
450
  buffers, or transmits the request body, so every downstream body consumer in your application
430
- remains callable.
451
+ remains callable. The URL keeps its query keys but not their values, cookie values are never
452
+ sent, and `Referer` is reduced to its origin (see
453
+ [Cookies, query strings, and Referer](#cookies-query-strings-and-referer)).
431
454
  - **Platform (Vercel):** Vercel's protected client IP, request ID (`x-vercel-id`), and the JA4 and
432
455
  JA3 TLS-fingerprint digests when Vercel supplies them.
433
456
  - **Platform (self-hosted):** the client IP and request ID nginx sets in `X-Steadphast-Client-Ip`
@@ -449,34 +472,82 @@ Headers pass through two filters before anything is serialized:
449
472
  built-in exclusions ── a fixed list of recognized credential header names
450
473
  │ and a few name patterns (see below)
451
474
  ▼
452
- your excludedHeaders ── e.g. cookie, and every application-specific credential header
475
+ your excludedHeaders ── every application-specific credential header
453
476
  │
454
477
  ▼
455
- captured header map (everything else, cookies included unless excluded)
478
+ captured header map (everything else; cookie values replaced by cookie names,
479
+ Referer reduced to its origin, URL-bearing headers redacted)
456
480
  ```
457
481
 
458
482
  The built-in filter is a **limited, fixed set**, not a general secret detector. Names are compared
459
483
  case-insensitively with separators removed (`x-api-key`, `X_Api_Key`, and `xapikey` are the same
460
484
  name). The exact set is:
461
485
 
462
- - `authorization`, `x-authorization`, and `proxy-authorization` (but not `x-proxy-authorization`);
486
+ - `authorization`, `x-authorization`, `proxy-authorization`, and `payment-authorization` (but not
487
+ `x-proxy-authorization`);
463
488
  - `api-key`, `api-token`, `auth-key`, `access-key`, `secret-key`, `auth-token`, `access-token`,
464
489
  `bearer-token`, `refresh-token`, `id-token`, `session-token`, and `csrf-token`, each with or
465
490
  without an `x-` prefix;
466
491
  - the bare names `token` and `key` (but not `x-token` or `x-key`);
467
492
  - any name ending in `apikey`, `authtoken`, or `accesstoken`, and any name containing `cryptogram`
468
493
  or `networktoken`;
469
- - `agentic-payment-container` and Vercel's `x-vercel-protection-bypass`.
494
+ - `agentic-payment-container` and Vercel's `x-vercel-protection-bypass`, `x-vercel-oidc-token`, and
495
+ `x-vercel-proxy-signature`;
496
+
497
+ A `Payment-Authorization` header is the payment credential of the Machine Payments Protocol (MPP).
498
+ Its value is never sent. In its place the captured map carries
499
+ `x-steadphast-payment-credential: payment-authorization`, which records only that a credential was
500
+ presented. It is not evidence that a payment succeeded or that a person authorized one. The
501
+ connector removes any `x-steadphast-payment-credential` header the visitor sends, so only the
502
+ connector sets it. List it in `excludedHeaders` to suppress the marker.
503
+
504
+ Vercel's visitor location headers (`x-vercel-ip-country`, `-country-region`, `-city`, `-latitude`,
505
+ `-longitude`, `-postal-code`) are captured; add them to `excludedHeaders` to keep them out.
470
506
 
471
507
  Every other header is captured, including custom credential headers such as `x-token`,
472
508
  `x-github-token`, `x-openai-key`, `x-internal-secret`, or `x-<vendor>-signature`. Audit the
473
509
  headers your application, its upstream proxies, and its third-party integrations attach, and list
474
510
  every credential-bearing name in `excludedHeaders`.
475
511
 
476
- Other headers, including cookies, are captured by default, so exclude them explicitly wherever that
477
- is not acceptable. Excluding a header removes it from the generic header map only; it does not
478
- remove a value that a dedicated field separately carries (for example the user agent). Query
479
- strings can contain sensitive values, so avoid placing secrets or personal data in public URLs.
512
+ Excluding a header removes it from the generic header map only; it does not remove a value that a
513
+ dedicated field separately carries (for example the user agent).
514
+
515
+ ### Cookies, query strings, and Referer
516
+
517
+ These rules apply to every installation, with no configuration, from the first release after
518
+ 0.6.0 (ADR 0017 amendment, 2026-11-17):
519
+
520
+ - **Cookies.** `Cookie` and `Set-Cookie` values are never sent. The captured map instead carries
521
+ `x-steadphast-cookie-names`: the cookie names only, de-duplicated, sorted, and capped at 32 names
522
+ and 1024 bytes. A name must be 1 to 64 RFC 6265 token characters; anything else is dropped. Each
523
+ `Set-Cookie` value contributes only its first name (values are never split on commas). The
524
+ connector removes any `x-steadphast-cookie-names` header the visitor sends. List `cookie` or
525
+ `set-cookie` in `excludedHeaders` to drop the names taken from that header, or
526
+ `x-steadphast-cookie-names` to drop the marker entirely.
527
+ - **Query strings and paths.** `external_url` keeps every query key but empties every value, so
528
+ `/a?utm_source=x&token=abc&flag` is sent as `/a?utm_source=&token=&flag=`. In the path, matrix
529
+ parameter values are emptied (`;jsessionid=abc` becomes `;jsessionid=`) and an encoded query
530
+ starting at `%3F` is treated like a query. The exceptions are requests carrying signature headers
531
+ (a `Signature` header and a `Signature-Input`): one that covers `@query`, `@query-param`,
532
+ `@target-uri`, or `@request-target` keeps its full URL, and one that covers `@path` keeps its raw
533
+ path, because Steadphast needs those exact bytes to verify the RFC 9421 signature. Any visitor
534
+ can send such headers for their own request. The server empties query values before it stores
535
+ the request path either way.
536
+ - **Referer.** `Referer` (and the `Referrer` misspelling) is reduced to its origin,
537
+ `scheme://host[:port]`: path, query, and fragment are removed. A value that is not an absolute
538
+ `http:` or `https:` URL, or that carries credentials (`user@host`), a `%` escape or non-ASCII
539
+ character in the host, a backslash, or whitespace, is dropped entirely rather than repaired.
540
+ - **Other URL-bearing headers.** `Next-Router-State-Tree` and `Next-Url`, which embed the page's
541
+ query values on client navigations, are sent only as the value `present`. The proxy headers
542
+ `X-Forwarded-Uri`, `X-Original-Url`, `X-Original-Uri`, `X-Envoy-Original-Path`, and
543
+ `X-Rewrite-Url`, and any other header whose value starts with `/`, `//`, `http://`, or `https://`
544
+ and contains `?`, are sent with query values emptied, the fragment removed, and any credentials
545
+ dropped from the host.
546
+ - **Signed header values.** A signature covering one of the headers above cannot be verified from
547
+ the minimized value, so that header's raw value is never sent and the signature is reported
548
+ `unattemptable`.
549
+
550
+ Even so, avoid placing secrets or personal data in URL paths or query keys.
480
551
 
481
552
  ### Size limits
482
553
 
@@ -497,6 +568,209 @@ Delivery does not block the visitor response: the connector serializes the recor
497
568
  changes the response status, headers, or body, and never propagates an error into your composed
498
569
  handler.
499
570
 
571
+ ## Family C own collection (unreleased)
572
+
573
+ Family C ships OFF: the API switch `BEHAVIORAL_ENABLED` defaults to false, and this version is not
574
+ published until Steadphast announces enablement. Do not configure routes before then; while OFF an
575
+ approved route only adds `no-store` delivery and a policy fetch that answers off.
576
+
577
+ After enablement, use the existing `DiscoverCollector` server component on supported uncached Node
578
+ App Router documents and add `behavioral: { routes: ["/catalog"], timing: false }` to its shared
579
+ server configuration. Choose routes deliberately; authentication, payment, transaction and health
580
+ routes and sensitive fields remain excluded. An absent route list collects nothing. Explicit
581
+ `collector: false` or `behavioral.mode: "off"` wins over workspace own mode.
582
+
583
+ Workspace owners/admins can independently disable own collection or enable timing in Settings.
584
+ API OFF wins over both. Server rendering fetches current policy without
585
+ caching, with a 250 ms deadline; failure emits no T1 script. This can add bounded page-render
586
+ latency, not a wait for user interaction or a change to classification latency.
587
+
588
+ Connect your actual consent manager through the browser-safe entry:
589
+
590
+ ```ts
591
+ import {
592
+ setBehavioralConsent,
593
+ disableBehavioralCollection,
594
+ closeBehavioralRoute,
595
+ } from "@steadphast/connector-nextjs/client";
596
+
597
+ // Only after affirmative permission; also handle steadphast:behavioral-ready.
598
+ setBehavioralConsent(true);
599
+ // Revoke permission and discard this document's unsent window.
600
+ setBehavioralConsent(false, true);
601
+ // Local OFF: synchronous listener removal and discard.
602
+ disableBehavioralCollection();
603
+ // Before a programmatic SPA transition: close, never continue the window.
604
+ closeBehavioralRoute();
605
+ ```
606
+
607
+ Unknown or denied consent installs no interaction listeners. T0 permission is not Family C consent.
608
+ The one exception is the two-key `notice` basis: when the workspace policy (set only by Steadphast,
609
+ with an audited change record) and `behavioral.consentBasis` both say `notice`, the window starts at
610
+ render, or when a background page first becomes visible, without a callback. Your privacy notice
611
+ must describe the collection. Revocation and `disableBehavioralCollection()` still discard it.
612
+ The library does not retain a consent call made before the collector registers; replay your real
613
+ consent-manager state on `steadphast:behavioral-ready`. Revoked/closed documents cannot restart.
614
+ Remote workspace OFF rejects old-policy submissions and suppresses later renders, but does not
615
+ instantly remove listeners from an already-open disconnected page. There is no polling or retry.
616
+
617
+ One window ends at 30 seconds, 100 actions or first hide, with at most one 4 KiB beacon,
618
+ 30 Hz/1,024 pointer/touch samples and bounded timing intervals. Key records are timing only: the
619
+ collector reads no key identity (`keyCode` only to compare it with 229, for IME composition) and
620
+ sends no character or key class, and drops modifier, shifted, shortcut and IME composition keys.
621
+ The number of key records, which roughly tracks the length of what was typed, leaves the browser;
622
+ dwell and flight values are sent sorted and rounded down to 10 ms. Values, clipboard text,
623
+ passwords, one-time codes, hidden fields, free-text content, payment/transaction/health fields,
624
+ contenteditable content, DOM identifiers and cross-page identifiers are never collected.
625
+ With timing on (site and workspace), the window also sends one connection timing value.
626
+ Collectors from this release add further interaction counts on eligible controls and tagged form
627
+ fields. Counts only: no value, key, text or element identity.
628
+ Use `data-discover-sensitive` for sensitive subtrees, and for any password field with a "show
629
+ password" toggle. Only explicitly reviewed `data-discover-nonsensitive="true"` buttons, selects and
630
+ range/number/checkbox/radio inputs permit key/paste/input observations; tagged
631
+ text/search/email/tel/url inputs and textareas, including fields that ask for the visitor's
632
+ details, give key timing and, from a collector that reports rule version 3 counts, interaction
633
+ counts, and nothing else: never a value, key, text or which field. Never tag a sensitive control
634
+ as nonsensitive.
635
+
636
+ Open-shadow origins and exposed slot/ancestor exclusions are checked transiently; paths, nodes and
637
+ native events are not retained. Unknown or opaque origin hosts abstain even when tagged safe.
638
+ **Closed-root installation prerequisite:** mark a sensitive/opaque component's light-DOM host or
639
+ enclosing visible subtree `data-discover-sensitive`, including its slotted light-DOM controls.
640
+ A tagged nonsensitive child cannot override that boundary. Passive DOM APIs can hide an internal
641
+ sensitive slot ancestor; null `shadowRoot`/`assignedSlot` and missing exposed marks are not proof
642
+ of safety. There is no closed-root probing or prototype instrumentation. If you cannot establish
643
+ and mark the boundary, leave that route unapproved or explicitly OFF. Unmarked opaque installs
644
+ are unsupported; workspace own mode is separate from route approval and visitor consent.
645
+
646
+ The API derives a summary in memory and stores no raw record array. Pending summaries expire at
647
+ 23 hours and attached summaries at 179 days from original receipt; event/subject deletion removes
648
+ linked evidence earlier. Physical purge must remain within the 24-hour/180-day ceilings, including
649
+ outage recovery and lock/pool starvation; the safety margins are one hour and one day, and reader
650
+ expiry alone is not physical deletion. The existing event detail shows
651
+ observations and honest coverage without changing its original verdict. Behavioral predicates and
652
+ partner intake are not released; synthetic engineering controls are not the required human/agent
653
+ evaluation. Customer install/privacy wording and consent review remain required before deployment.
654
+
655
+ ## Optional: the T0 client collector
656
+
657
+ Unreleased version 0.6.0 adds the **T0 client collector**: a small clean-room script, inlined into
658
+ document HTML, that observes browser realms and posts one beacon to `POST /v1/client/t0`.
659
+ The server joins the beacon to its event by the envelope's `record_id_prefix:request_id` identity
660
+ and records `client_environment`; the six client-side flags are derived from that evidence.
661
+
662
+ It is **off by default**, including when the server component is mounted without configuration.
663
+ Every request has inbound `x-steadphast-collector-*` headers removed, even while collection is off.
664
+ Before enabling any tenant, ship the privacy statement line and customer install/notice guidance,
665
+ resolve applicable consent requirements with counsel, and obtain that tenant's explicit opt-in.
666
+ Merging or installing the package does not enable collection.
667
+
668
+ Keep one server-only configuration and pass it to both entry points:
669
+
670
+ ```ts
671
+ // discover-config.ts: never import this module into a Client Component.
672
+ import type { DiscoverNextConfig } from "@steadphast/connector-nextjs";
673
+
674
+ export const discoverConfig = {
675
+ kind: "vercel",
676
+ apiUrl: "https://api.steadphast.ai/v1/connectors/nextjs/events",
677
+ excludedHeaders: ["cookie"],
678
+ recordIdPrefix: "vercel-production",
679
+ collector: false, // Set true only after the tenant's activation prerequisites are complete.
680
+ } satisfies DiscoverNextConfig;
681
+ ```
682
+
683
+ ```ts
684
+ // middleware.ts (15.5) or proxy.ts (16.3)
685
+ import { withDiscover } from "@steadphast/connector-nextjs";
686
+ import { discoverConfig } from "./discover-config";
687
+
688
+ export default withDiscover(discoverConfig);
689
+ ```
690
+
691
+ ```tsx
692
+ // app/layout.tsx
693
+ import { DiscoverCollector } from "@steadphast/connector-nextjs/server";
694
+ import { discoverConfig } from "../discover-config";
695
+
696
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
697
+ return (
698
+ <html lang="en">
699
+ <body>
700
+ {children}
701
+ <DiscoverCollector config={discoverConfig} />
702
+ </body>
703
+ </html>
704
+ );
705
+ }
706
+ ```
707
+
708
+ What the wrapper does with `collector: true`, on a **document navigation** only (a `GET` whose
709
+ `Sec-Fetch-Dest` is `document`, or, when that header is absent, whose `Accept` names `text/html`):
710
+
711
+ - authenticates a render context bound to `record_id_prefix:request_id` and the current
712
+ millisecond with the server's connector API key;
713
+ - forwards only `x-steadphast-collector-context`, after stripping every inbound header in that
714
+ namespace; this domain-separated context is not a browser beacon nonce;
715
+ - appends `collector_served: true` and `served_at` to the envelope. The server holds later
716
+ requests only after a valid beacon has confirmed installation; a late first beacon can confirm it.
717
+
718
+ The wrapper does not read or rewrite the response body. It forwards the authenticated context with
719
+ `NextResponse.next({ request: { headers } })`, including composed next/rewrite responses.
720
+ `DiscoverCollector` separately requires `config.collector === true`, resolves the endpoint only
721
+ from that server configuration, validates the context and mints the browser nonce through the
722
+ server-side HMAC path. Missing configuration, missing context and forged context render nothing.
723
+ Visitor endpoint, nonce and enablement headers are never trusted. The component needs the App
724
+ Router (`next/headers`); the Pages Router is not supported. `react` ^19 is a peer for `./server`.
725
+
726
+ The collector observes the main window, a Blob worker, and a sandboxed `srcdoc` iframe, and reports
727
+ realm cross-checks (a spoofed `navigator` that disagrees across realms), native-function integrity,
728
+ headless and automation markers, a coarse screen/WebGL/feature profile, and interaction *counts*
729
+ (untrusted clicks, whether any trusted input happened). It registers no listener that reads what
730
+ was typed, and it never touches form contents, pointer coordinates, the clipboard, storage,
731
+ cookies, extension URLs, WebRTC, or any persistent identifier. Its one keepalive `text/plain`
732
+ POST explicitly uses `credentials: "omit"`, with a UTF-8 body capped at 2000 bytes. It sends at
733
+ `DOMContentLoaded` plus a short realm grace, on early exit/backgrounding, or at the 1500 ms cap,
734
+ then removes its listeners, worker, Blob URL and iframe. The bundle is gated below 8 KB gzipped.
735
+
736
+ Availability is factual: `available`, `unsupported-api`, `script-failure`, `background-tab`,
737
+ `early-exit` or `insufficient-observation`. Missing realms are not disagreements; discarded fields
738
+ cannot leave stale cross-realm findings. Availability alone changes no classification verdict.
739
+ The full browser version list is sent only when the worker reports client hints to compare it
740
+ with, so an ordinary Chrome beacon fits the budget untrimmed. Trimming optional detail keeps
741
+ `available`; only a trim that removes a field the server's verdict reads, or a cross-realm
742
+ finding, reports `insufficient-observation`.
743
+
744
+ **Content-Security-Policy.** Supply an independently server-generated application CSP nonce as
745
+ `<DiscoverCollector config={discoverConfig} nonce={cspNonce} />`; never read it from an unsanitized
746
+ visitor header. The browser beacon still receives its separate HMAC nonce. The iframe uses that
747
+ script nonce under its own restrictive policy and observes whether a nonce-less probe executes
748
+ there, not whether the customer's page happens to permit inline scripts. Under a strict parent
749
+ policy, allow the intended Blob worker and frame or expect incomplete availability. No policy is
750
+ weakened automatically; unsupported or failed observation is not automation evidence.
751
+
752
+ ## Repository verification
753
+
754
+ From a repository checkout:
755
+
756
+ ```sh
757
+ nix develop -c pnpm -C ts --filter @steadphast/connector-nextjs test
758
+ nix develop -c pnpm -C ts --filter @steadphast/connector-nextjs build
759
+ nix develop -c pnpm -C ts deadcode
760
+ ```
761
+
762
+ The build has three public entries and two repository-only loopback fixture entries. Knip tracks
763
+ the build entrypoints explicitly because the Next.js fixtures import their compiled paths;
764
+ the private entries remain excluded from package exports and published files. The hosted
765
+ `nextjs-connector-checks` gate exercises both supported runtimes through nginx and the live API.
766
+ The durable replay test waits for the first committed value and then for every replay job to
767
+ settle; asynchronous acceptance does not promise FIFO completion.
768
+
769
+ Family C's jsdom controls exercise consent/revocation, first-hide/BFCache/SPA closure, masking,
770
+ sample/action/body bounds and timing abstention deterministically. They do not emulate native
771
+ hardware or satisfy the independent human/agent corpus; real connector → API/Postgres → reader
772
+ verification remains separate.
773
+
500
774
  ## Troubleshooting
501
775
 
502
776
  - **No events appear:** switch the Explore traffic filter to all traffic first, because the default
@@ -521,13 +795,23 @@ handler.
521
795
  the `proxy_set_header Host` lines, and `publicOrigin` agree with each other.
522
796
  - **Self-hosted URLs show the wrong host:** `publicOrigin` does not match the public scheme, host,
523
797
  and port nginx serves; it is never derived from request headers.
524
- - **Cookies still appear:** confirm `excludedHeaders: ["cookie"]` is present in the deployed entry
525
- file.
798
+ - **Cookie values or query values appear:** confirm the deployed connector is newer than 0.6.0;
799
+ 0.6.0 and earlier sent them unless excluded.
526
800
  - **Your site response fails:** inspect your own handler and application route. Steadphast delivery
527
801
  failures are swallowed and never change the response.
528
802
 
529
803
  ## Upgrading
530
804
 
805
+ - **Unreleased (next version after 0.6.0)** never sends cookie values (only the
806
+ `x-steadphast-cookie-names` marker),
807
+ empties query values in `external_url` except for a request carrying signature headers that
808
+ cover the query, and reduces `Referer` to its origin. See
809
+ [Cookies, query strings, and Referer](#cookies-query-strings-and-referer). No configuration
810
+ change is needed; an existing `excludedHeaders: ["cookie"]` now also drops the cookie names.
811
+ - **0.6.0** adds the opt-in T0 client collector. It also stops sending the
812
+ `Payment-Authorization` credential and sends the `x-steadphast-payment-credential` presence
813
+ marker in its place. Upgrade the connector and the Steadphast API together: the API rejects an
814
+ older envelope that still carries `Payment-Authorization`.
531
815
  - **0.5.4** Documentation only: this README now carries the reference nginx configuration and the
532
816
  coding-agent setup prompts; no runtime change.
533
817
  - **0.5.3** Documentation and metadata only; no runtime change.
@@ -0,0 +1,8 @@
1
+ /** Stringified after compilation; every runtime dependency lives inside this function. */
2
+ export declare function behavioralCollector(nonce: string, endpoint: string, timing: boolean, issuedAt: number, route: string, notice?: boolean, pathCapture?: boolean): void;
3
+ /** Call from the customer's consent callback; revocation closes this document permanently. */
4
+ export declare function setBehavioralConsent(granted: boolean, revoked?: boolean): void;
5
+ /** Synchronous browser-local OFF: listeners removed and unsent buffers discarded. */
6
+ export declare function disableBehavioralCollection(): void;
7
+ /** Call before a programmatic SPA transition when the browser has no navigation event. */
8
+ export declare function closeBehavioralRoute(): void;
@@ -0,0 +1 @@
1
+ export { setBehavioralConsent, disableBehavioralCollection, closeBehavioralRoute, } from "./behavioral-collector.js";
package/dist/client.js ADDED
@@ -0,0 +1,19 @@
1
+ // src/behavioral-collector.ts
2
+ function setBehavioralConsent(granted, revoked = false) {
3
+ window.dispatchEvent(
4
+ new CustomEvent("steadphast:behavioral-consent", {
5
+ detail: { granted, revoked }
6
+ })
7
+ );
8
+ }
9
+ function disableBehavioralCollection() {
10
+ window.dispatchEvent(new Event("steadphast:behavioral-disable"));
11
+ }
12
+ function closeBehavioralRoute() {
13
+ window.dispatchEvent(new Event("steadphast:behavioral-route"));
14
+ }
15
+ export {
16
+ closeBehavioralRoute,
17
+ disableBehavioralCollection,
18
+ setBehavioralConsent
19
+ };
package/dist/config.d.ts CHANGED
@@ -21,6 +21,32 @@ export interface DiscoverNextCommonConfig {
21
21
  excludedHeaders?: ReadonlyArray<string>;
22
22
  recordIdPrefix?: string;
23
23
  timeoutMs?: number;
24
+ /**
25
+ * Serve the T0 client collector (ADR 0037). Off by default. Both middleware and the server
26
+ * component must receive this server-owned configuration with collector explicitly enabled.
27
+ * The middleware authenticates a render context for captured document navigations; the server
28
+ * component verifies it and mints the beacon nonce. Neither nonce nor destination is accepted
29
+ * from visitor headers. Disabled requests have no collector output or envelope keys.
30
+ */
31
+ collector?: boolean;
32
+ /**
33
+ * Family C defaults to own, independently of T0. An explicit collector:false or mode:"off"
34
+ * wins. Only exact approved pathnames are eligible; an empty route list collects nothing.
35
+ * Timing remains off unless both this switch and the workspace timing switch are true.
36
+ * Browser consent is supplied separately through the consent event, never by configuration,
37
+ * unless `consentBasis` is "notice" here AND the workspace's Steadphast-set consent basis is
38
+ * "notice" (ADR 0053 amendment, 2026-11-16): then the window starts without a prompt on a site
39
+ * whose privacy notice discloses the collection. Revocation and every OFF control still apply.
40
+ * `pathCapture` likewise needs the workspace's `path_capture_enabled` too: only with both does
41
+ * the page script add each click target's bounding box (geometry only) for pointer-path replay.
42
+ */
43
+ behavioral?: {
44
+ mode?: "own" | "off" | "partner";
45
+ timing?: boolean;
46
+ routes?: ReadonlyArray<string>;
47
+ consentBasis?: "affirmative" | "notice";
48
+ pathCapture?: boolean;
49
+ };
24
50
  }
25
51
  /** The connector configuration: the explicit deployment mode plus the common transport settings. */
26
52
  export type DiscoverNextConfig = DiscoverDeploymentMode & DiscoverNextCommonConfig;
@@ -37,6 +63,13 @@ export declare const SELF_HOSTED_CONNECTOR_ASSERTION: DiscoverConnectorAssertion
37
63
  * `CanonicalEvent`, and it must never be admitted as one.
38
64
  */
39
65
  export declare const ENVELOPE_INGEST_PATHNAME = "/v1/connectors/nextjs/events";
66
+ /** The unauthenticated, CORS-simple T0 beacon route the collector posts to (ADR 0037 decision 5). */
67
+ export declare const BEACON_PATHNAME = "/v1/client/t0";
68
+ /** Reserved namespace: every inbound member is stripped before capture or delegation. */
69
+ export declare const COLLECTOR_HEADER_PREFIX = "x-steadphast-collector-";
70
+ /** Authenticated middleware-to-render context, domain-separated from browser beacon nonces. */
71
+ export declare const COLLECTOR_CONTEXT_HEADER = "x-steadphast-collector-context";
72
+ export declare const BEHAVIORAL_CONTEXT_HEADER = "x-steadphast-collector-behavioral";
40
73
  export declare class DiscoverConfigError extends TypeError {
41
74
  readonly name = "DiscoverConfigError";
42
75
  }
@@ -63,3 +96,5 @@ export declare function parseStrictUrl(value: string, setting: string): URL;
63
96
  export declare function connectorAssertionFor(mode: DiscoverDeploymentMode): DiscoverConnectorAssertion;
64
97
  /** Validates the discriminated mode and returns the resolved `publicOrigin` for self-hosted. */
65
98
  export declare function resolveDeploymentMode(mode: DiscoverDeploymentMode): DiscoverDeploymentMode;
99
+ /** Resolves only server-owned environment settings, never request metadata. */
100
+ export declare function resolveApiKey(customEnvVar: string | undefined): string | undefined;