@xovris/next 0.0.0-stage → 0.1.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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,10 @@
1
+ // Imported by instrumentation-client.ts: Next.js inlines the NEXT_PUBLIC_ variables the wizard wrote at build time.
2
+ import { init } from '@xovris/browser';
3
+ init({
4
+ url: process.env.NEXT_PUBLIC_XOVRIS_INGEST_URL,
5
+ key: process.env.NEXT_PUBLIC_XOVRIS_INGEST_KEY,
6
+ release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
7
+ environment: process.env.NEXT_PUBLIC_VERCEL_ENV ?? process.env.NODE_ENV,
8
+ // The wizard adds the tunnel route and this variable together (D01.02.02); absent, events go straight to Xovris.
9
+ tunnel: process.env.NEXT_PUBLIC_XOVRIS_TUNNEL,
10
+ });
@@ -0,0 +1,15 @@
1
+ interface NextRequestInfo {
2
+ path: string;
3
+ method: string;
4
+ headers: Record<string, string | string[] | undefined>;
5
+ }
6
+ interface NextErrorContext {
7
+ routerKind: 'Pages Router' | 'App Router';
8
+ routePath: string;
9
+ routeType: 'render' | 'route' | 'action' | 'middleware';
10
+ renderSource?: string;
11
+ revalidateReason?: string;
12
+ }
13
+ /** Next.js 15+ instrumentation hook: exported from instrumentation.ts by the wizard's codemod. */
14
+ export declare function onRequestError(err: unknown, request: NextRequestInfo, context: NextErrorContext): Promise<void>;
15
+ export { captureException, flush } from '@xovris/node';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ // @xovris/next (ADR 0011): Next.js's own hooks wired to Xovris - register() loads the server client, onRequestError
2
+ // reports every server, route-handler and middleware error with its route, and @xovris/next/client covers the browser.
3
+ import { init } from '@xovris/node';
4
+ /** Next.js 15+ instrumentation hook: exported from instrumentation.ts by the wizard's codemod. */
5
+ export async function onRequestError(err, request, context) {
6
+ const c = init();
7
+ c.captureException(err, {
8
+ handled: false, mechanism: 'next.onRequestError',
9
+ tags: { 'next.router': context.routerKind, 'next.route': context.routePath, 'next.route_type': context.routeType, ...(context.renderSource ? { 'next.render_source': context.renderSource } : {}) },
10
+ request: { url: request.path, method: request.method },
11
+ });
12
+ await c.flush(2000);
13
+ }
14
+ export { captureException, flush } from '@xovris/node';
package/dist/otel.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { batchFor, xovrisSpanProcessor, XovrisSpanProcessor } from '@xovris/node/otel';
package/dist/otel.js ADDED
@@ -0,0 +1,2 @@
1
+ // The processor the wizard adds to an existing registerOTel({...}) or NodeSDK in instrumentation.ts (D01.02.01).
2
+ export { batchFor, xovrisSpanProcessor, XovrisSpanProcessor } from '@xovris/node/otel';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ // Imported from register() in instrumentation.ts: the Node.js server runtime starts the client with its process
2
+ // handlers and joins (or, when none runs, starts) the app's tracer; the edge runtime has no process events, so it
3
+ // relies on onRequestError alone.
4
+ import { init, startTracing } from '@xovris/node';
5
+ if (process.env.NEXT_RUNTIME !== 'edge') {
6
+ init();
7
+ void startTracing();
8
+ }
@@ -0,0 +1,10 @@
1
+ export interface TunnelOptions {
2
+ ingestUrl?: string | undefined;
3
+ fetch?: typeof fetch;
4
+ maxBytes?: number;
5
+ }
6
+ export declare function createTunnelHandler(o?: TunnelOptions): {
7
+ POST(req: Request): Promise<Response>;
8
+ };
9
+ /** The default handler: export { POST } from '@xovris/next/tunnel' in app/xovris/route.ts. */
10
+ export declare const POST: (req: Request) => Promise<Response>;
package/dist/tunnel.js ADDED
@@ -0,0 +1,55 @@
1
+ // The first-party tunnel (D01.02.02): a Next.js route handler on the customer's own domain that forwards browser envelopes
2
+ // to the project's Xovris ingest address, so an ad blocker that refuses the ingest host does not silence browser errors.
3
+ // It forwards ONLY to the address the wizard configured - an envelope naming any other host or project is refused - so the
4
+ // route can never become an open relay; it adds nothing but the tunnel marker the server turns into the diagnosis.
5
+ // app/xovris/route.ts: export { POST } from '@xovris/next/tunnel';
6
+ import { envelopeUrl, projectIdFrom } from '@xovris/core';
7
+ export function createTunnelHandler(o = {}) {
8
+ const max = o.maxBytes ?? 1_000_000;
9
+ return {
10
+ async POST(req) {
11
+ const ingest = o.ingestUrl ?? process.env.XOVRIS_INGEST_URL ?? process.env.NEXT_PUBLIC_XOVRIS_INGEST_URL;
12
+ const target = ingest ? envelopeUrl(ingest) : null;
13
+ if (!ingest || !target)
14
+ return new Response('Xovris: no ingest address is set for the tunnel. Run npx xovris@latest init.', { status: 503 });
15
+ const auth = req.headers.get('x-sentry-auth');
16
+ if (!auth || !/sentry_key=[^,\s]+/.test(auth))
17
+ return new Response(null, { status: 400 });
18
+ if (Number(req.headers.get('content-length') ?? 0) > max)
19
+ return new Response(null, { status: 413 });
20
+ const body = await req.text();
21
+ if (new TextEncoder().encode(body).length > max)
22
+ return new Response(null, { status: 413 });
23
+ let head;
24
+ try {
25
+ head = JSON.parse(body.split('\n', 1)[0] ?? '');
26
+ }
27
+ catch {
28
+ return new Response(null, { status: 400 });
29
+ }
30
+ if (typeof head.dsn === 'string') {
31
+ // A DSN in the header must be this project on this ingest host, or the envelope is not ours to carry.
32
+ let d;
33
+ try {
34
+ d = new URL(head.dsn);
35
+ }
36
+ catch {
37
+ return new Response(null, { status: 400 });
38
+ }
39
+ const project = projectIdFrom(ingest);
40
+ if (d.host !== new URL(target).host || (project && d.pathname.replace(/^\/|\/$/g, '') !== project))
41
+ return new Response(null, { status: 403 });
42
+ }
43
+ const f = o.fetch ?? fetch;
44
+ try {
45
+ const res = await f(target, { method: 'POST', headers: { 'content-type': 'application/x-sentry-envelope', 'x-sentry-auth': auth, 'x-xovris-tunnel': req.headers.get('x-xovris-tunnel') === 'blocked' ? 'blocked' : 'on' }, body });
46
+ return new Response(null, { status: res.status, ...(res.headers.get('retry-after') ? { headers: { 'retry-after': res.headers.get('retry-after') } } : {}) });
47
+ }
48
+ catch {
49
+ return new Response(null, { status: 502 });
50
+ }
51
+ },
52
+ };
53
+ }
54
+ /** The default handler: export { POST } from '@xovris/next/tunnel' in app/xovris/route.ts. */
55
+ export const { POST } = createTunnelHandler();
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@xovris/next",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Xovris for Next.js: register(), onRequestError and the client instrumentation the wizard wires in (ADR 0011).",
4
+ "version": "0.1.0",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./register": {
16
+ "types": "./dist/register.d.ts",
17
+ "import": "./dist/register.js"
18
+ },
19
+ "./client": {
20
+ "types": "./dist/client.d.ts",
21
+ "import": "./dist/client.js"
22
+ },
23
+ "./otel": {
24
+ "types": "./dist/otel.d.ts",
25
+ "import": "./dist/otel.js"
26
+ },
27
+ "./tunnel": {
28
+ "types": "./dist/tunnel.d.ts",
29
+ "import": "./dist/tunnel.js"
30
+ }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "@xovris/node": "0.1.0",
37
+ "@xovris/browser": "0.1.0",
38
+ "@xovris/core": "0.1.0"
39
+ },
40
+ "homepage": "https://xovris.ai/developers/",
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.build.json",
46
+ "typecheck": "tsc --noEmit -p .",
47
+ "test": "vitest run"
48
+ }
6
49
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.