@steadphast/connector-nextjs 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +12 -0
- package/README.md +349 -0
- package/dist/config.d.ts +65 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +670 -0
- package/dist/middleware.d.ts +18 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Steadphast
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Steadphast Discover Next.js Connector
|
|
2
|
+
Copyright 2026 Steadphast
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (the
|
|
5
|
+
"License"). You may obtain a copy of the License in the LICENSE file
|
|
6
|
+
distributed with this package, or at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
This package bundles source from the Steadphast Discover connector core
|
|
11
|
+
(ts/packages/connector-core in the Steadphast Discover repository), which
|
|
12
|
+
is licensed under the same terms.
|
package/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# @steadphast/connector-nextjs
|
|
2
|
+
|
|
3
|
+
The Next.js connector for Steadphast Discover, published on the public npm registry as
|
|
4
|
+
`@steadphast/connector-nextjs`. The package is licensed under Apache-2.0; the `LICENSE` and
|
|
5
|
+
`NOTICE` it ships with are the authoritative terms.
|
|
6
|
+
|
|
7
|
+
Current version: **0.5.1**. The package installs on any Next.js 15 or 16 release (peer range
|
|
8
|
+
`^15.0.0 || ^16.0.0`). The tested and supported versions are Next.js **15.5.23** (`middleware.ts`)
|
|
9
|
+
and **16.3.2** (`proxy.ts`), which the hosted gate proves on every change; other releases on those
|
|
10
|
+
two lines are expected to work but are not gate-proven. The package makes no non-Next or Next 14
|
|
11
|
+
or earlier support claim.
|
|
12
|
+
|
|
13
|
+
The connector is a thin request-time safety and capture layer (ADR 0034). It serializes one strict,
|
|
14
|
+
bounded, sanitized **version 2 evidence envelope** per captured request and schedules exactly one
|
|
15
|
+
best-effort `POST /v1/connectors/nextjs/events` with the `NextFetchEvent.waitUntil` supplied by
|
|
16
|
+
Next.js. Normalization to a `CanonicalEvent`, enrichment, and classification all remain server-side
|
|
17
|
+
in Discover; none of them ever run in Middleware or Proxy.
|
|
18
|
+
|
|
19
|
+
## 0.5.0: envelope version 2
|
|
20
|
+
|
|
21
|
+
0.5.0 emits `envelope_version: "2"` only, with no runtime switch (ADR 0034 amendment, issue
|
|
22
|
+
#349). Version 2 is version 1 minus `platform.public_request_id`: the public `x-request-id` header
|
|
23
|
+
stays in `request.headers` as evidence, and Vercel identity is `x-vercel-id`, else the stable
|
|
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" }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Mode is never inferred from headers, environment variables, host names, or runtime globals. Vercel
|
|
61
|
+
mode sends the exact `X-Steadphast-Connector: vercel-routing-middleware` assertion; self-hosted mode
|
|
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
|
+
```
|
|
95
|
+
|
|
96
|
+
Before an exact Next.js fixture or in-repo application consumes it, build it from source:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
pnpm --filter @steadphast/connector-nextjs build
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This produces the ignored `dist/index.js` workspace artifact. The build leaves only `next/server`
|
|
103
|
+
external and bundles the connector's runtime dependencies.
|
|
104
|
+
|
|
105
|
+
## Install
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
npm install @steadphast/connector-nextjs
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Next.js is the only peer dependency, so the package installs against the Next.js version your
|
|
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:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
pnpm --filter @steadphast/connector-nextjs build
|
|
129
|
+
pnpm --filter @steadphast/connector-nextjs pack --dry-run
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Confirm the pack contains only `package.json`, `LICENSE` and `NOTICE` (the Apache-2.0 text and
|
|
133
|
+
notice, checked by the same test), `README.md`, `dist/index.js`, and the three `.d.ts` files, that
|
|
134
|
+
`dist/index.js` imports nothing but `next/server`, and that it carries no canonical-mapper symbols
|
|
135
|
+
such as `mapRequestToCanonicalEvent` or `CANONICAL_EVENT_KEYS`.
|
|
136
|
+
|
|
137
|
+
## Next.js 15.5: `middleware.ts`
|
|
138
|
+
|
|
139
|
+
Place `middleware.ts` beside the root `app` or `pages` directory, or at `src/middleware.ts` when the
|
|
140
|
+
application lives under `src/`.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
144
|
+
|
|
145
|
+
const apiUrl = process.env.STEADPHAST_API_URL;
|
|
146
|
+
if (!apiUrl) {
|
|
147
|
+
throw new Error("STEADPHAST_API_URL is required");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default withDiscover({
|
|
151
|
+
kind: "vercel",
|
|
152
|
+
apiUrl,
|
|
153
|
+
excludedHeaders: ["cookie"],
|
|
154
|
+
recordIdPrefix: "vercel-production",
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export const config = {
|
|
158
|
+
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
159
|
+
};
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Next.js 15.5 supports this Vercel mode on its Edge or Node runtime. The supported self-hosted
|
|
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`
|
|
167
|
+
|
|
168
|
+
Place `proxy.ts` beside the root `app` or `pages` directory, or at `src/proxy.ts` when the
|
|
169
|
+
application lives under `src/`. Next.js 16.3 Proxy uses Node.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
173
|
+
|
|
174
|
+
const apiUrl = process.env.STEADPHAST_API_URL;
|
|
175
|
+
if (!apiUrl) {
|
|
176
|
+
throw new Error("STEADPHAST_API_URL is required");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export default withDiscover({
|
|
180
|
+
kind: "vercel",
|
|
181
|
+
apiUrl,
|
|
182
|
+
excludedHeaders: ["cookie"],
|
|
183
|
+
recordIdPrefix: "vercel-production",
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export const config = {
|
|
187
|
+
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
188
|
+
};
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`withDiscover(config, handler?)` may also compose one application Middleware or Proxy handler. The
|
|
192
|
+
wrapper schedules capture and delivery, then invokes that handler once and preserves its response,
|
|
193
|
+
rewrite, redirect, `undefined` result, or thrown error.
|
|
194
|
+
|
|
195
|
+
## Self-hosted configuration
|
|
196
|
+
|
|
197
|
+
Self-hosted mode is supported only when Node-hosted Next.js is private behind the repository's
|
|
198
|
+
normative nginx boundary. Use the configuration below in either supported file: add
|
|
199
|
+
`runtime: "nodejs"` to the exported `config` only for Next.js 15.5 `middleware.ts`; Next.js 16.3
|
|
200
|
+
`proxy.ts` is already Node-only and does not accept the `runtime` option.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { withDiscover } from "@steadphast/connector-nextjs";
|
|
204
|
+
|
|
205
|
+
const apiUrl = process.env.STEADPHAST_API_URL;
|
|
206
|
+
if (!apiUrl) {
|
|
207
|
+
throw new Error("STEADPHAST_API_URL is required");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default withDiscover({
|
|
211
|
+
kind: "self-hosted",
|
|
212
|
+
publicOrigin: "https://www.example.com",
|
|
213
|
+
apiUrl,
|
|
214
|
+
excludedHeaders: ["cookie"],
|
|
215
|
+
recordIdPrefix: "nextjs-self-hosted-production",
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
export const config = {
|
|
219
|
+
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
|
220
|
+
};
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`publicOrigin` is the sole scheme and authority source for the self-hosted envelope's
|
|
224
|
+
`request.external_url`. It must be one HTTPS origin with no credentials, path, query, or fragment,
|
|
225
|
+
and it must match nginx's validated public scheme, host, and port. It is separate from `apiUrl`.
|
|
226
|
+
|
|
227
|
+
The application listener must be bound to loopback or another private transport. nginx terminates
|
|
228
|
+
client TLS directly, rejects unknown hosts, and always overwrites these internal headers:
|
|
229
|
+
|
|
230
|
+
```nginx
|
|
231
|
+
proxy_set_header Host $server_name:$server_port;
|
|
232
|
+
proxy_set_header X-Forwarded-Host $server_name:$server_port;
|
|
233
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
234
|
+
proxy_set_header X-Steadphast-Client-Ip $remote_addr;
|
|
235
|
+
proxy_set_header X-Steadphast-Request-Id $request_id;
|
|
236
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Use the exact committed
|
|
240
|
+
[`deploy/nginx/steadphast-nextjs.conf`](../../../deploy/nginx/steadphast-nextjs.conf) as the
|
|
241
|
+
reference boundary. A CDN or load balancer before nginx, a public direct Next.js port, pass-through
|
|
242
|
+
internal headers, and configurable multi-hop trust are unsupported.
|
|
243
|
+
|
|
244
|
+
Only a singular valid `x-steadphast-client-ip` can populate the self-hosted `platform.client_ip`,
|
|
245
|
+
and only a singular valid `x-steadphast-request-id` can populate `platform.request_id`. Missing,
|
|
246
|
+
duplicate/comma-joined, malformed, ambiguous, control-bearing, or overlong trusted values omit the
|
|
247
|
+
corresponding optional field; the connector never falls back to `X-Forwarded-For`, `X-Real-IP`,
|
|
248
|
+
public `x-request-id`, `x-vercel-*`, or socket guessing. The two internal headers are never copied
|
|
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.
|
|
309
|
+
|
|
310
|
+
### Privacy exclusions
|
|
311
|
+
|
|
312
|
+
Before serialization the connector removes, from the generic header map, the built-in
|
|
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.
|
|
318
|
+
|
|
319
|
+
### All-or-nothing limits
|
|
320
|
+
|
|
321
|
+
Every per-field, per-header, header-count, aggregate-header, and whole-envelope limit is enforced
|
|
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.
|
|
327
|
+
|
|
328
|
+
## Delivery and visitor isolation
|
|
329
|
+
|
|
330
|
+
Each captured request produces exactly one envelope and exactly one bounded `POST` scheduled through
|
|
331
|
+
`waitUntil`. There is no batching, no retry, no durable client queue, and no fallback route — in
|
|
332
|
+
particular, never a fallback to `/v1/events`.
|
|
333
|
+
|
|
334
|
+
The only success is HTTP `202` with the exact strict JSON body `{"accepted":1}`, which the server
|
|
335
|
+
writes only after a normalized durable admission. Any non-`202` status, unparseable JSON, missing or
|
|
336
|
+
non-unit `accepted`, or extra response field is treated as a failed or malformed acknowledgement:
|
|
337
|
+
the single event is dropped and counted on the process-local counter, and nothing about the request,
|
|
338
|
+
the response, the body, or the credential is logged.
|
|
339
|
+
|
|
340
|
+
Delivery is fully isolated from the visitor: a drop, timeout, rejection, or malformed
|
|
341
|
+
acknowledgement never changes the visitor's response, status, headers, or timing, and never
|
|
342
|
+
propagates an error into the composed handler. Lifecycle handles stay process-local. This is a
|
|
343
|
+
lifecycle description, not a sustained-load guarantee.
|
|
344
|
+
|
|
345
|
+
## License
|
|
346
|
+
|
|
347
|
+
Apache-2.0. See the `LICENSE` and `NOTICE` files shipped with the package. The license covers this
|
|
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.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment mode is a required discriminated configuration (ADR 0033 §1). It is never inferred
|
|
3
|
+
* from request headers, environment shape, host names, or runtime globals.
|
|
4
|
+
*/
|
|
5
|
+
export type DiscoverDeploymentMode = {
|
|
6
|
+
kind: "vercel";
|
|
7
|
+
} | {
|
|
8
|
+
kind: "self-hosted";
|
|
9
|
+
publicOrigin: string;
|
|
10
|
+
};
|
|
11
|
+
export type DiscoverConnectorAssertion = "vercel-routing-middleware" | "nextjs-self-hosted";
|
|
12
|
+
export interface DiscoverNextCommonConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Discover API origin (`https://host/`) or the exact envelope ingest URL
|
|
15
|
+
* (`https://host/v1/connectors/nextjs/events`). The origin form is normalized to that dedicated
|
|
16
|
+
* path; the legacy canonical-event route `/v1/events` is rejected (ADR 0034 §1).
|
|
17
|
+
*/
|
|
18
|
+
apiUrl: string;
|
|
19
|
+
apiKeyEnvVar?: string;
|
|
20
|
+
captureAllPaths?: boolean;
|
|
21
|
+
excludedHeaders?: ReadonlyArray<string>;
|
|
22
|
+
recordIdPrefix?: string;
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
}
|
|
25
|
+
/** The connector configuration: the explicit deployment mode plus the common transport settings. */
|
|
26
|
+
export type DiscoverNextConfig = DiscoverDeploymentMode & DiscoverNextCommonConfig;
|
|
27
|
+
/** Fixed internal ingress headers owned by the reference nginx boundary (ADR 0033 §2, §6). */
|
|
28
|
+
export declare const SELF_HOSTED_CLIENT_IP_HEADER = "x-steadphast-client-ip";
|
|
29
|
+
export declare const SELF_HOSTED_REQUEST_ID_HEADER = "x-steadphast-request-id";
|
|
30
|
+
/** Maximum textual length of an IPv4 or IPv6 literal, including IPv4-embedded IPv6. */
|
|
31
|
+
export declare const MAX_SELF_HOSTED_CLIENT_IP_LENGTH = 45;
|
|
32
|
+
export declare const VERCEL_CONNECTOR_ASSERTION: DiscoverConnectorAssertion;
|
|
33
|
+
export declare const SELF_HOSTED_CONNECTOR_ASSERTION: DiscoverConnectorAssertion;
|
|
34
|
+
/**
|
|
35
|
+
* The dedicated sanitized-envelope endpoint (ADR 0034 §1). It is deliberately NOT the canonical
|
|
36
|
+
* `/v1/events` route: the body this package ships is a source-specific evidence envelope, not a
|
|
37
|
+
* `CanonicalEvent`, and it must never be admitted as one.
|
|
38
|
+
*/
|
|
39
|
+
export declare const ENVELOPE_INGEST_PATHNAME = "/v1/connectors/nextjs/events";
|
|
40
|
+
export declare class DiscoverConfigError extends TypeError {
|
|
41
|
+
readonly name = "DiscoverConfigError";
|
|
42
|
+
}
|
|
43
|
+
export declare function validateApiKeyEnvVar(apiKeyEnvVar: string | undefined): void;
|
|
44
|
+
/**
|
|
45
|
+
* Production outbound destination policy (ADR 0033 §1 as amended by ADR 0034 §1): absolute HTTPS,
|
|
46
|
+
* non-empty host, no userinfo/query/fragment, and a pathname of exactly `/` or the dedicated
|
|
47
|
+
* envelope path. The origin form is normalized to the dedicated envelope ingest URL, so every
|
|
48
|
+
* accepted configuration resolves to exactly one destination path. An exact `/v1/events`
|
|
49
|
+
* destination is rejected outright so a sanitized envelope can never be posted as a canonical
|
|
50
|
+
* event. Errors never echo the configured value.
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveProductionIngestUrl(apiUrl: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Self-hosted `publicOrigin` policy (ADR 0033 §7): one HTTPS origin with no credentials, path,
|
|
55
|
+
* query, or fragment. Returns the serialized origin.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolvePublicOrigin(publicOrigin: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Shared strict parse: absolute URL, non-empty host, and no username, password, query, or
|
|
60
|
+
* fragment — checked on the raw string so `?`/`#` with empty components are also rejected.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseStrictUrl(value: string, setting: string): URL;
|
|
63
|
+
export declare function connectorAssertionFor(mode: DiscoverDeploymentMode): DiscoverConnectorAssertion;
|
|
64
|
+
/** Validates the discriminated mode and returns the resolved `publicOrigin` for self-hosted. */
|
|
65
|
+
export declare function resolveDeploymentMode(mode: DiscoverDeploymentMode): DiscoverDeploymentMode;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { type DiscoverConnectorAssertion, type DiscoverDeploymentMode, type DiscoverNextCommonConfig, type DiscoverNextConfig, DiscoverConfigError, SELF_HOSTED_CLIENT_IP_HEADER, SELF_HOSTED_CONNECTOR_ASSERTION, SELF_HOSTED_REQUEST_ID_HEADER, VERCEL_CONNECTOR_ASSERTION, } from "./config.js";
|
|
2
|
+
export { type DiscoverNextHandler, type DiscoverNextMiddleware, withDiscover, } from "./middleware.js";
|