@nexload-sdk/healthcheck-next 2.1.0 → 3.0.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 +149 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,8 +1,66 @@
|
|
|
1
1
|
# @nexload-sdk/healthcheck-next
|
|
2
2
|
|
|
3
|
-
Next.js App Router route factories for `@nexload-sdk/healthcheck
|
|
3
|
+
**Next.js App Router `GET`/`HEAD` health and metrics route factories for `@nexload-sdk/healthcheck`.**
|
|
4
|
+
|
|
5
|
+
[Documentation](https://gecut.github.io/nexload-sdk/packages/healthcheck/next/) · [API reference](https://gecut.github.io/nexload-sdk/packages/healthcheck/next/api/)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@nexload-sdk/healthcheck-next)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
> [!IMPORTANT]
|
|
13
|
+
> A new major release is pending across the healthcheck family in `.changeset/healthcheck-major.md` (import ordering updates, no runtime behavior changes).
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
|
|
17
|
+
- [Overview](#overview)
|
|
18
|
+
- [Philosophy](#philosophy)
|
|
19
|
+
- [Install](#install)
|
|
20
|
+
- [Quick start](#quick-start)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [API](#api)
|
|
23
|
+
- [Configuration](#configuration)
|
|
24
|
+
- [Runtime and compatibility](#runtime-and-compatibility)
|
|
25
|
+
- [Caveats](#caveats)
|
|
26
|
+
- [Related packages](#related-packages)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
`@nexload-sdk/healthcheck-next` creates Web Standard `Request` -> `Response` handlers (`createNextHealthRoute`, `createNextMetricsRoute`) for Next.js App Router route files. It solves repetitive `Cache-Control: no-store` headers, HTTP status mapping (`200` vs `503`), Prometheus/OpenMetrics formatting, and fail-closed route protection for diagnostics and metrics endpoints. It is for Next.js App Router services.
|
|
32
|
+
|
|
33
|
+
What it is not:
|
|
34
|
+
|
|
35
|
+
- Not a Pages Router (`pages/api/*`) adapter.
|
|
36
|
+
- Not a Next.js middleware or authentication framework.
|
|
37
|
+
|
|
38
|
+
## Philosophy
|
|
39
|
+
|
|
40
|
+
- **Fail-closed protection:** Supplying `protect` requires at least one valid policy (bearer token, Basic auth, or IPv4/CIDR allowlist) and throws `HEALTHCHECK_INVALID_CONFIG` at startup if misconfigured.
|
|
41
|
+
- **Uncached by default:** Every response sets `cache-control: no-store, max-age=0`; report responses also set `x-health-status`, `x-health-scope`, `x-health-duration-ms`, `x-health-service`, and `x-health-instance` when `instanceId` is set.
|
|
42
|
+
- **Constant-time credential checks:** Bearer and Basic auth comparisons use a constant-time byte loop.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-next
|
|
48
|
+
# or
|
|
49
|
+
npm install @nexload-sdk/healthcheck @nexload-sdk/healthcheck-next
|
|
50
|
+
# or
|
|
51
|
+
yarn add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-next
|
|
52
|
+
# or
|
|
53
|
+
bun add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-next
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| Package | Range | Required / Optional |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| *(none)* | — | No peer dependencies (`@nexload-sdk/healthcheck` and `@nexload-sdk/healthcheck-prometheus` are direct dependencies) |
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
4
61
|
|
|
5
62
|
```ts
|
|
63
|
+
// app/api/health/ready/route.ts
|
|
6
64
|
import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
|
|
7
65
|
import { health } from "@/lib/health";
|
|
8
66
|
|
|
@@ -13,8 +71,96 @@ export const fetchCache = "force-no-store";
|
|
|
13
71
|
|
|
14
72
|
export const { GET, HEAD } = createNextHealthRoute(health, {
|
|
15
73
|
scope: "readiness",
|
|
16
|
-
format: "json"
|
|
74
|
+
format: "json",
|
|
17
75
|
});
|
|
18
76
|
```
|
|
19
77
|
|
|
20
|
-
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Protected diagnostics route
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// app/api/health/diagnostics/route.ts
|
|
84
|
+
import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
|
|
85
|
+
import { health } from "@/lib/health";
|
|
86
|
+
|
|
87
|
+
export const runtime = "nodejs";
|
|
88
|
+
export const dynamic = "force-dynamic";
|
|
89
|
+
|
|
90
|
+
export const { GET, HEAD } = createNextHealthRoute(health, {
|
|
91
|
+
scope: "diagnostics",
|
|
92
|
+
format: "json",
|
|
93
|
+
includeDetails: true,
|
|
94
|
+
protect: {
|
|
95
|
+
bearerToken: process.env.HEALTHCHECK_DIAGNOSTICS_TOKEN,
|
|
96
|
+
trustProxy: true,
|
|
97
|
+
allowCidrs: ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Prometheus / OpenMetrics route
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// app/api/metrics/route.ts
|
|
106
|
+
import { createNextMetricsRoute } from "@nexload-sdk/healthcheck-next";
|
|
107
|
+
import { health } from "@/lib/health";
|
|
108
|
+
|
|
109
|
+
export const runtime = "nodejs";
|
|
110
|
+
export const dynamic = "force-dynamic";
|
|
111
|
+
|
|
112
|
+
export const { GET } = createNextMetricsRoute(health, {
|
|
113
|
+
format: "prometheus",
|
|
114
|
+
scope: "all",
|
|
115
|
+
prefix: "nexload",
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## API
|
|
120
|
+
|
|
121
|
+
### Root entry (`@nexload-sdk/healthcheck-next`)
|
|
122
|
+
|
|
123
|
+
| Export | Kind | Summary |
|
|
124
|
+
| --- | --- | --- |
|
|
125
|
+
| `createNextHealthRoute` | `function` | Returns `{ GET, HEAD }` route handlers for a `HealthScope` |
|
|
126
|
+
| `createNextMetricsRoute` | `function` | Returns `{ GET }` handler emitting `prometheus`, `openmetrics`, or `json` |
|
|
127
|
+
| `NextHealthRouteOptions` | `interface` | Options for `createNextHealthRoute` |
|
|
128
|
+
| `NextMetricsRouteOptions` | `interface` | Options for `createNextMetricsRoute` |
|
|
129
|
+
| `NextHealthRouteProtection` | `interface` | Bearer, Basic, IPv4, and CIDR protection policy |
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | Description |
|
|
134
|
+
| --- | --- | --- | --- |
|
|
135
|
+
| `scope` | `HealthScope` (health) / `HealthRunScope` (metrics) | Required (health) / `"all"` (metrics) | Scope passed to `manager.run()` |
|
|
136
|
+
| `format` | `"json" \| "summary"` (health) / `"prometheus" \| "openmetrics" \| "json"` (metrics) | `"json"` (health) / Required (metrics) | Response serialization format |
|
|
137
|
+
| `httpStatus` (health only) | `HealthHttpStatusPolicy` | `DEFAULT_HTTP_STATUS_POLICY` | Status code mapping for `ok`, `degraded`, `unhealthy` |
|
|
138
|
+
| `includeDetails` (health only) | `boolean \| ((req: Request) => boolean)` | `false` | Controls detail inclusion in JSON responses |
|
|
139
|
+
| `protect` | `NextHealthRouteProtection` | `undefined` | Optional fail-closed auth and IPv4 allowlist policy |
|
|
140
|
+
| `headers` (health only) | `HeadersInit \| ((report) => HeadersInit)` | `undefined` | Extra response headers merged onto `baseHeaders` |
|
|
141
|
+
| `cache` (health only) | `"no-store"` | `"no-store"` | Only `"no-store"` is supported |
|
|
142
|
+
|
|
143
|
+
Metrics route options also include `prefix` (string, default `"nexload"`) and `defaultLabels` (`Record<string, string>`). The metrics route uses the `"monitoring"` profile and responds with status 200 for reports.
|
|
144
|
+
|
|
145
|
+
## Runtime and compatibility
|
|
146
|
+
|
|
147
|
+
- **Module format:** Dual ESM (`import`) and CJS (`require`).
|
|
148
|
+
- **Runtime:** Uses Web Standard `Request`, `Response`, `Headers`, `TextEncoder`, and `atob`—compatible with Next.js Node.js and Edge runtimes (use `runtime = "nodejs"` if your `HealthManager` uses `@nexload-sdk/healthcheck-node`).
|
|
149
|
+
|
|
150
|
+
## Caveats
|
|
151
|
+
|
|
152
|
+
> [!CAUTION]
|
|
153
|
+
> IP (`allowIps`) and CIDR (`allowCidrs`) protection require `trustProxy: true` and currently accept IPv4 addresses only. Only enable `trustProxy: true` when `proxyHeader` (default `"x-forwarded-for"`) is set and stripped by your reverse proxy.
|
|
154
|
+
|
|
155
|
+
> [!WARNING]
|
|
156
|
+
> `bearerToken` and `basicAuth` cannot be configured together on the same route because they share the `Authorization` header. Supplying an empty `protect: {}` object throws `HEALTHCHECK_INVALID_CONFIG`.
|
|
157
|
+
|
|
158
|
+
## Related packages
|
|
159
|
+
|
|
160
|
+
- [healthcheck](../core/README.md) — Core `HealthManager` and status policies
|
|
161
|
+
- [healthcheck-node](../node/README.md) — Node.js runtime adapter for Next.js `runtime = "nodejs"`
|
|
162
|
+
- [healthcheck-prometheus](../prometheus/README.md) — Prometheus and OpenMetrics serializers used by `createNextMetricsRoute`
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|
package/dist/index.cjs
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DEFAULT_HTTP_STATUS_POLICY,\n statusToHttpStatus,\n stringifyHealthJson,\n toHealthJson\n} from \"@nexload-sdk/healthcheck\";\nimport {\n toOpenMetricsText,\n toPrometheusText\n} from \"@nexload-sdk/healthcheck-prometheus\";\n\nimport type {\n HealthHttpStatusPolicy,\n HealthManager,\n HealthReport,\n HealthRunScope,\n HealthScope\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface NextHealthRouteProtection {\n bearerToken?: string\n basicAuth?: {\n username: string\n password: string\n }\n allowCidrs?: readonly string[]\n allowIps?: readonly string[]\n trustProxy?: boolean\n proxyHeader?: \"x-forwarded-for\" | \"x-real-ip\" | string\n}\n\nexport interface NextHealthRouteOptions {\n scope: HealthScope\n format?: \"json\" | \"summary\"\n httpStatus?: HealthHttpStatusPolicy\n includeDetails?: boolean | ((request: Request) => boolean)\n protect?: NextHealthRouteProtection\n headers?: HeadersInit | ((report: HealthReport) => HeadersInit)\n cache?: \"no-store\"\n}\n\nexport interface NextMetricsRouteOptions {\n format: \"prometheus\" | \"openmetrics\" | \"json\"\n scope?: HealthRunScope\n protect?: NextHealthRouteProtection\n prefix?: string\n defaultLabels?: Record<string, string>\n}\n\nfunction constantTimeEquals (\n input: string, expected: string\n): boolean {\n const encoder = new TextEncoder();\n const inputBytes = encoder.encode(input);\n const expectedBytes = encoder.encode(expected);\n const length = Math.max(\n inputBytes.length, expectedBytes.length\n );\n let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;\n\n for (let index = 0; index < length; index += 1) {\n mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);\n }\n\n return mismatch === 0;\n}\n\nfunction parseBasicAuth (value: string | null): { username: string, password: string } | null {\n if (!value?.startsWith(\"Basic \")) return null;\n\n try {\n const decoded = atob(value.slice(\"Basic \".length));\n const separator = decoded.indexOf(\":\");\n if (separator === -1) return null;\n\n return {\n username: decoded.slice(\n 0, separator\n ),\n password: decoded.slice(separator + 1),\n };\n } catch {\n return null;\n }\n}\n\nfunction ipToNumber (ip: string): number | null {\n const parts = ip.split(\".\").map(Number);\n if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {\n return null;\n }\n\n return (((parts[0] ?? 0) << 24) >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);\n}\n\nfunction cidrContains (\n cidr: string, ip: string\n): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n const rangeNumber = ipToNumber(range ?? \"\");\n const ipNumber = ipToNumber(ip);\n\n if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {\n return false;\n }\n\n const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;\n return (rangeNumber & mask) === (ipNumber & mask);\n}\n\nfunction isValidCidr (cidr: string): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n\n return ipToNumber(range ?? \"\") !== null\n && Number.isInteger(bits)\n && bits >= 0\n && bits <= 32;\n}\n\nfunction invalidConfig (message: string): Error {\n const error = new Error(message);\n error.name = \"HEALTHCHECK_INVALID_CONFIG\";\n return error;\n}\n\nfunction validateProtection (protection?: NextHealthRouteProtection): void {\n if (!protection) return;\n\n const hasBearer = \"bearerToken\" in protection;\n const hasBasic = protection.basicAuth !== undefined;\n const hasIps = (protection.allowIps?.length ?? 0) > 0;\n const hasCidrs = (protection.allowCidrs?.length ?? 0) > 0;\n\n if (!hasBearer && !hasBasic && !hasIps && !hasCidrs) {\n throw invalidConfig(\"Route protection must configure at least one access policy.\");\n }\n\n if (hasBearer && !protection.bearerToken?.trim()) {\n throw invalidConfig(\"Bearer token protection requires a non-empty token.\");\n }\n\n if (hasBasic && (!protection.basicAuth?.username.trim() || !protection.basicAuth.password)) {\n throw invalidConfig(\"Basic authentication requires a non-empty username and password.\");\n }\n\n if (hasBearer && hasBasic) {\n throw invalidConfig(\"Bearer and Basic authentication cannot share one Authorization header.\");\n }\n\n if ((hasIps || hasCidrs) && protection.trustProxy !== true) {\n throw invalidConfig(\"IP and CIDR protection require trustProxy: true.\");\n }\n\n if (protection.allowIps?.some((ip) => ipToNumber(ip) === null)) {\n throw invalidConfig(\"IP protection currently accepts valid IPv4 addresses only.\");\n }\n\n if (protection.allowCidrs?.some((cidr) => !isValidCidr(cidr))) {\n throw invalidConfig(\"CIDR protection currently accepts valid IPv4 CIDRs only.\");\n }\n}\n\nfunction getRequestIp (\n request: Request, protection: NextHealthRouteProtection\n): string | null {\n if (!protection.trustProxy) return null;\n\n const header = protection.proxyHeader ?? \"x-forwarded-for\";\n const value = request.headers.get(header);\n if (!value) return null;\n\n return value.split(\",\")[0]?.trim() ?? null;\n}\n\nfunction isAuthorized (\n request: Request, protection?: NextHealthRouteProtection\n): boolean {\n if (!protection) return true;\n\n if (protection.bearerToken) {\n const token = request.headers.get(\"authorization\")?.replace(\n /^Bearer\\s+/i, \"\"\n ) ?? \"\";\n if (!constantTimeEquals(\n token, protection.bearerToken\n )) {\n return false;\n }\n }\n\n if (protection.basicAuth) {\n const parsed = parseBasicAuth(request.headers.get(\"authorization\"));\n if (!parsed || !constantTimeEquals(\n parsed.username, protection.basicAuth.username\n ) || !constantTimeEquals(\n parsed.password, protection.basicAuth.password\n )) {\n return false;\n }\n }\n\n const ip = getRequestIp(\n request, protection\n );\n if (protection.allowIps?.length && (!ip || !protection.allowIps.includes(ip))) {\n return false;\n }\n\n if (protection.allowCidrs?.length && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(\n cidr, ip\n )))) {\n return false;\n }\n\n return true;\n}\n\nfunction unauthorized (): Response {\n return new Response(\n JSON.stringify({\n code: \"HEALTHCHECK_ROUTE_UNAUTHORIZED\",\n message: \"Unauthorized.\",\n }), {\n status: 401,\n headers: {\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store, max-age=0\",\n },\n }\n );\n}\n\nfunction mergeHeaders (...headersList: Array<HeadersInit | undefined>): Headers {\n const headers = new Headers();\n\n for (const headersInit of headersList) {\n if (!headersInit) continue;\n new Headers(headersInit).forEach((\n value, key\n ) => headers.set(\n key, value\n ));\n }\n\n return headers;\n}\n\nfunction baseHeaders (\n report: HealthReport, contentType: string\n): HeadersInit {\n return {\n \"cache-control\": \"no-store, max-age=0\",\n \"content-type\": contentType,\n \"x-health-status\": report.status,\n \"x-health-scope\": String(report.scope),\n \"x-health-duration-ms\": report.durationMs.toFixed(2),\n \"x-health-service\": report.service.name,\n ...(report.service.instanceId ? { \"x-health-instance\": report.service.instanceId, } : {}),\n };\n}\n\nfunction summaryBody (report: HealthReport): string {\n return JSON.stringify({\n status: report.status,\n scope: report.scope,\n observedAt: report.observedAt,\n durationMs: report.durationMs,\n summary: report.summary,\n });\n}\n\nexport function createNextHealthRoute (\n manager: HealthManager, options: NextHealthRouteOptions\n): {\n GET: (request: Request) => Promise<Response>\n HEAD: (request: Request) => Promise<Response>\n} {\n validateProtection(options.protect);\n\n if (options.cache !== undefined && options.cache !== \"no-store\") {\n throw invalidConfig(\"Health routes only support cache: no-store.\");\n }\n\n async function handle (\n request: Request, head = false\n ): Promise<Response> {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(options.scope);\n const includeDetails = typeof options.includeDetails === \"function\"\n ? options.includeDetails(request)\n : options.includeDetails ?? false;\n const body = options.format === \"summary\"\n ? summaryBody(report)\n : stringifyHealthJson(\n report, { includeDetails, }\n );\n const headers = mergeHeaders(\n baseHeaders(\n report, \"application/json; charset=utf-8\"\n ), typeof options.headers === \"function\" ? options.headers(report) : options.headers\n );\n\n return new Response(\n head ? null : body, {\n status: statusToHttpStatus(\n report.status, options.httpStatus ?? DEFAULT_HTTP_STATUS_POLICY\n ),\n headers,\n }\n );\n }\n\n return {\n GET: (request) => handle(request),\n HEAD: (request) => handle(\n request, true\n ),\n };\n}\n\nexport function createNextMetricsRoute (\n manager: HealthManager, options: NextMetricsRouteOptions\n): { GET: (request: Request) => Promise<Response> } {\n validateProtection(options.protect);\n\n return {\n async GET (request) {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(\n options.scope ?? \"all\", { profile: \"monitoring\", }\n );\n const contentType = options.format === \"json\"\n ? \"application/json; charset=utf-8\"\n : options.format === \"openmetrics\"\n ? \"application/openmetrics-text; version=1.0.0; charset=utf-8\"\n : \"text/plain; version=0.0.4; charset=utf-8\";\n const body = options.format === \"json\"\n ? JSON.stringify(toHealthJson(\n report, { includeDetails: false, }\n ))\n : options.format === \"openmetrics\"\n ? toOpenMetricsText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n )\n : toPrometheusText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n );\n\n return new Response(\n body, {\n status: 200,\n headers: baseHeaders(\n report, contentType\n ),\n }\n );\n },\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type {\n HealthHttpStatusPolicy,\n HealthManager,\n HealthReport,\n HealthRunScope,\n HealthScope\n} from \"@nexload-sdk/healthcheck\";\n\nimport {\n DEFAULT_HTTP_STATUS_POLICY,\n statusToHttpStatus,\n stringifyHealthJson,\n toHealthJson\n} from \"@nexload-sdk/healthcheck\";\nimport {\n toOpenMetricsText,\n toPrometheusText\n} from \"@nexload-sdk/healthcheck-prometheus\";\n\nexport interface NextHealthRouteProtection {\n bearerToken?: string\n basicAuth?: {\n username: string\n password: string\n }\n allowCidrs?: readonly string[]\n allowIps?: readonly string[]\n trustProxy?: boolean\n proxyHeader?: \"x-forwarded-for\" | \"x-real-ip\" | string\n}\n\nexport interface NextHealthRouteOptions {\n scope: HealthScope\n format?: \"json\" | \"summary\"\n httpStatus?: HealthHttpStatusPolicy\n includeDetails?: boolean | ((request: Request) => boolean)\n protect?: NextHealthRouteProtection\n headers?: HeadersInit | ((report: HealthReport) => HeadersInit)\n cache?: \"no-store\"\n}\n\nexport interface NextMetricsRouteOptions {\n format: \"prometheus\" | \"openmetrics\" | \"json\"\n scope?: HealthRunScope\n protect?: NextHealthRouteProtection\n prefix?: string\n defaultLabels?: Record<string, string>\n}\n\nfunction constantTimeEquals (\n input: string, expected: string\n): boolean {\n const encoder = new TextEncoder();\n const inputBytes = encoder.encode(input);\n const expectedBytes = encoder.encode(expected);\n const length = Math.max(\n inputBytes.length, expectedBytes.length\n );\n let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;\n\n for (let index = 0; index < length; index += 1) {\n mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);\n }\n\n return mismatch === 0;\n}\n\nfunction parseBasicAuth (value: string | null): { username: string, password: string } | null {\n if (!value?.startsWith(\"Basic \")) return null;\n\n try {\n const decoded = atob(value.slice(\"Basic \".length));\n const separator = decoded.indexOf(\":\");\n\n if (separator === -1) return null;\n\n return {\n username: decoded.slice(\n 0, separator\n ),\n password: decoded.slice(separator + 1),\n };\n } catch {\n return null;\n }\n}\n\nfunction ipToNumber (ip: string): number | null {\n const parts = ip.split(\".\").map(Number);\n\n if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {\n return null;\n }\n\n return (((parts[0] ?? 0) << 24) >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);\n}\n\nfunction cidrContains (\n cidr: string, ip: string\n): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n const rangeNumber = ipToNumber(range ?? \"\");\n const ipNumber = ipToNumber(ip);\n\n if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {\n return false;\n }\n\n const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;\n\n return (rangeNumber & mask) === (ipNumber & mask);\n}\n\nfunction isValidCidr (cidr: string): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n\n return ipToNumber(range ?? \"\") !== null\n && Number.isInteger(bits)\n && bits >= 0\n && bits <= 32;\n}\n\nfunction invalidConfig (message: string): Error {\n const error = new Error(message);\n error.name = \"HEALTHCHECK_INVALID_CONFIG\";\n\n return error;\n}\n\nfunction validateProtection (protection?: NextHealthRouteProtection): void {\n if (!protection) return;\n\n const hasBearer = \"bearerToken\" in protection;\n const hasBasic = protection.basicAuth !== undefined;\n const hasIps = (protection.allowIps?.length ?? 0) > 0;\n const hasCidrs = (protection.allowCidrs?.length ?? 0) > 0;\n\n if (!hasBearer && !hasBasic && !hasIps && !hasCidrs) {\n throw invalidConfig(\"Route protection must configure at least one access policy.\");\n }\n\n if (hasBearer && !protection.bearerToken?.trim()) {\n throw invalidConfig(\"Bearer token protection requires a non-empty token.\");\n }\n\n if (hasBasic && (!protection.basicAuth?.username.trim() || !protection.basicAuth.password)) {\n throw invalidConfig(\"Basic authentication requires a non-empty username and password.\");\n }\n\n if (hasBearer && hasBasic) {\n throw invalidConfig(\"Bearer and Basic authentication cannot share one Authorization header.\");\n }\n\n if ((hasIps || hasCidrs) && protection.trustProxy !== true) {\n throw invalidConfig(\"IP and CIDR protection require trustProxy: true.\");\n }\n\n if (protection.allowIps?.some((ip) => ipToNumber(ip) === null)) {\n throw invalidConfig(\"IP protection currently accepts valid IPv4 addresses only.\");\n }\n\n if (protection.allowCidrs?.some((cidr) => !isValidCidr(cidr))) {\n throw invalidConfig(\"CIDR protection currently accepts valid IPv4 CIDRs only.\");\n }\n}\n\nfunction getRequestIp (\n request: Request, protection: NextHealthRouteProtection\n): string | null {\n if (!protection.trustProxy) return null;\n\n const header = protection.proxyHeader ?? \"x-forwarded-for\";\n const value = request.headers.get(header);\n\n if (!value) return null;\n\n return value.split(\",\")[0]?.trim() ?? null;\n}\n\nfunction isAuthorized (\n request: Request, protection?: NextHealthRouteProtection\n): boolean {\n if (!protection) return true;\n\n if (protection.bearerToken) {\n const token = request.headers.get(\"authorization\")?.replace(\n /^Bearer\\s+/i, \"\"\n ) ?? \"\";\n\n if (!constantTimeEquals(\n token, protection.bearerToken\n )) {\n return false;\n }\n }\n\n if (protection.basicAuth) {\n const parsed = parseBasicAuth(request.headers.get(\"authorization\"));\n\n if (!parsed || !constantTimeEquals(\n parsed.username, protection.basicAuth.username\n ) || !constantTimeEquals(\n parsed.password, protection.basicAuth.password\n )) {\n return false;\n }\n }\n\n const ip = getRequestIp(\n request, protection\n );\n\n if (protection.allowIps?.length && (!ip || !protection.allowIps.includes(ip))) {\n return false;\n }\n\n if (protection.allowCidrs?.length && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(\n cidr, ip\n )))) {\n return false;\n }\n\n return true;\n}\n\nfunction unauthorized (): Response {\n return new Response(\n JSON.stringify({\n code: \"HEALTHCHECK_ROUTE_UNAUTHORIZED\",\n message: \"Unauthorized.\",\n }), {\n status: 401,\n headers: {\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store, max-age=0\",\n },\n }\n );\n}\n\nfunction mergeHeaders (...headersList: Array<HeadersInit | undefined>): Headers {\n const headers = new Headers();\n\n for (const headersInit of headersList) {\n if (!headersInit) continue;\n new Headers(headersInit).forEach((\n value, key\n ) => headers.set(\n key, value\n ));\n }\n\n return headers;\n}\n\nfunction baseHeaders (\n report: HealthReport, contentType: string\n): HeadersInit {\n return {\n \"cache-control\": \"no-store, max-age=0\",\n \"content-type\": contentType,\n \"x-health-status\": report.status,\n \"x-health-scope\": String(report.scope),\n \"x-health-duration-ms\": report.durationMs.toFixed(2),\n \"x-health-service\": report.service.name,\n ...(report.service.instanceId ? { \"x-health-instance\": report.service.instanceId, } : {}),\n };\n}\n\nfunction summaryBody (report: HealthReport): string {\n return JSON.stringify({\n status: report.status,\n scope: report.scope,\n observedAt: report.observedAt,\n durationMs: report.durationMs,\n summary: report.summary,\n });\n}\n\nexport function createNextHealthRoute (\n manager: HealthManager, options: NextHealthRouteOptions\n): {\n GET: (request: Request) => Promise<Response>\n HEAD: (request: Request) => Promise<Response>\n} {\n validateProtection(options.protect);\n\n if (options.cache !== undefined && options.cache !== \"no-store\") {\n throw invalidConfig(\"Health routes only support cache: no-store.\");\n }\n\n async function handle (\n request: Request, head = false\n ): Promise<Response> {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(options.scope);\n const includeDetails = typeof options.includeDetails === \"function\"\n ? options.includeDetails(request)\n : options.includeDetails ?? false;\n const body = options.format === \"summary\"\n ? summaryBody(report)\n : stringifyHealthJson(\n report, { includeDetails, }\n );\n const headers = mergeHeaders(\n baseHeaders(\n report, \"application/json; charset=utf-8\"\n ), typeof options.headers === \"function\" ? options.headers(report) : options.headers\n );\n\n return new Response(\n head ? null : body, {\n status: statusToHttpStatus(\n report.status, options.httpStatus ?? DEFAULT_HTTP_STATUS_POLICY\n ),\n headers,\n }\n );\n }\n\n return {\n GET: (request) => handle(request),\n HEAD: (request) => handle(\n request, true\n ),\n };\n}\n\nexport function createNextMetricsRoute (\n manager: HealthManager, options: NextMetricsRouteOptions\n): { GET: (request: Request) => Promise<Response> } {\n validateProtection(options.protect);\n\n return {\n async GET (request) {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(\n options.scope ?? \"all\", { profile: \"monitoring\", }\n );\n const contentType = options.format === \"json\"\n ? \"application/json; charset=utf-8\"\n : options.format === \"openmetrics\"\n ? \"application/openmetrics-text; version=1.0.0; charset=utf-8\"\n : \"text/plain; version=0.0.4; charset=utf-8\";\n const body = options.format === \"json\"\n ? JSON.stringify(toHealthJson(\n report, { includeDetails: false, }\n ))\n : options.format === \"openmetrics\"\n ? toOpenMetricsText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n )\n : toPrometheusText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n );\n\n return new Response(\n body, {\n status: 200,\n headers: baseHeaders(\n report, contentType\n ),\n }\n );\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AA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AAM,SAAS,MAAM,QAAQ;AAAA,QAC3B,QAAQ,SAAS;AAAA,QAAO,EAAE,SAAS,aAAc;AAAA,MACnD;AACA,YAAM,cAAc,QAAQ,WAAW,SACnC,oCACA,QAAQ,WAAW,gBACjB,+DACA;AACN,YAAM,OAAO,QAAQ,WAAW,SAC5B,KAAK,cAAU;AAAA,QACf;AAAA,QAAQ,EAAE,gBAAgB,MAAO;AAAA,MACnC,CAAC,IACC,QAAQ,WAAW,oBACjB;AAAA,QACA;AAAA,QAAQ,EAAE,QAAQ,QAAQ,QAAQ,eAAe,QAAQ,cAAe;AAAA,MAC1E,QACE;AAAA,QACA;AAAA,QAAQ,EAAE,QAAQ,QAAQ,QAAQ,eAAe,QAAQ,cAAe;AAAA,MAC1E;AAEJ,aAAO,IAAI;AAAA,QACT;AAAA,QAAM;AAAA,UACJ,QAAQ;AAAA,UACR,SAAS;AAAA,YACP;AAAA,YAAQ;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAalC,MAAM,WAAW,yBAAyB;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE;QACV,QAAQ,EAAE,MAAM,CAAA;QAChB,QAAQ,EAAE,MAAM,CAAA;KACjB,CAAA;IACD,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC9B,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5B,UAAU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GED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n DEFAULT_HTTP_STATUS_POLICY,\n statusToHttpStatus,\n stringifyHealthJson,\n toHealthJson\n} from \"@nexload-sdk/healthcheck\";\nimport {\n toOpenMetricsText,\n toPrometheusText\n} from \"@nexload-sdk/healthcheck-prometheus\";\n\nimport type {\n HealthHttpStatusPolicy,\n HealthManager,\n HealthReport,\n HealthRunScope,\n HealthScope\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface NextHealthRouteProtection {\n bearerToken?: string\n basicAuth?: {\n username: string\n password: string\n }\n allowCidrs?: readonly string[]\n allowIps?: readonly string[]\n trustProxy?: boolean\n proxyHeader?: \"x-forwarded-for\" | \"x-real-ip\" | string\n}\n\nexport interface NextHealthRouteOptions {\n scope: HealthScope\n format?: \"json\" | \"summary\"\n httpStatus?: HealthHttpStatusPolicy\n includeDetails?: boolean | ((request: Request) => boolean)\n protect?: NextHealthRouteProtection\n headers?: HeadersInit | ((report: HealthReport) => HeadersInit)\n cache?: \"no-store\"\n}\n\nexport interface NextMetricsRouteOptions {\n format: \"prometheus\" | \"openmetrics\" | \"json\"\n scope?: HealthRunScope\n protect?: NextHealthRouteProtection\n prefix?: string\n defaultLabels?: Record<string, string>\n}\n\nfunction constantTimeEquals (\n input: string, expected: string\n): boolean {\n const encoder = new TextEncoder();\n const inputBytes = encoder.encode(input);\n const expectedBytes = encoder.encode(expected);\n const length = Math.max(\n inputBytes.length, expectedBytes.length\n );\n let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;\n\n for (let index = 0; index < length; index += 1) {\n mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);\n }\n\n return mismatch === 0;\n}\n\nfunction parseBasicAuth (value: string | null): { username: string, password: string } | null {\n if (!value?.startsWith(\"Basic \")) return null;\n\n try {\n const decoded = atob(value.slice(\"Basic \".length));\n const separator = decoded.indexOf(\":\");\n if (separator === -1) return null;\n\n return {\n username: decoded.slice(\n 0, separator\n ),\n password: decoded.slice(separator + 1),\n };\n } catch {\n return null;\n }\n}\n\nfunction ipToNumber (ip: string): number | null {\n const parts = ip.split(\".\").map(Number);\n if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {\n return null;\n }\n\n return (((parts[0] ?? 0) << 24) >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);\n}\n\nfunction cidrContains (\n cidr: string, ip: string\n): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n const rangeNumber = ipToNumber(range ?? \"\");\n const ipNumber = ipToNumber(ip);\n\n if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {\n return false;\n }\n\n const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;\n return (rangeNumber & mask) === (ipNumber & mask);\n}\n\nfunction isValidCidr (cidr: string): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n\n return ipToNumber(range ?? \"\") !== null\n && Number.isInteger(bits)\n && bits >= 0\n && bits <= 32;\n}\n\nfunction invalidConfig (message: string): Error {\n const error = new Error(message);\n error.name = \"HEALTHCHECK_INVALID_CONFIG\";\n return error;\n}\n\nfunction validateProtection (protection?: NextHealthRouteProtection): void {\n if (!protection) return;\n\n const hasBearer = \"bearerToken\" in protection;\n const hasBasic = protection.basicAuth !== undefined;\n const hasIps = (protection.allowIps?.length ?? 0) > 0;\n const hasCidrs = (protection.allowCidrs?.length ?? 0) > 0;\n\n if (!hasBearer && !hasBasic && !hasIps && !hasCidrs) {\n throw invalidConfig(\"Route protection must configure at least one access policy.\");\n }\n\n if (hasBearer && !protection.bearerToken?.trim()) {\n throw invalidConfig(\"Bearer token protection requires a non-empty token.\");\n }\n\n if (hasBasic && (!protection.basicAuth?.username.trim() || !protection.basicAuth.password)) {\n throw invalidConfig(\"Basic authentication requires a non-empty username and password.\");\n }\n\n if (hasBearer && hasBasic) {\n throw invalidConfig(\"Bearer and Basic authentication cannot share one Authorization header.\");\n }\n\n if ((hasIps || hasCidrs) && protection.trustProxy !== true) {\n throw invalidConfig(\"IP and CIDR protection require trustProxy: true.\");\n }\n\n if (protection.allowIps?.some((ip) => ipToNumber(ip) === null)) {\n throw invalidConfig(\"IP protection currently accepts valid IPv4 addresses only.\");\n }\n\n if (protection.allowCidrs?.some((cidr) => !isValidCidr(cidr))) {\n throw invalidConfig(\"CIDR protection currently accepts valid IPv4 CIDRs only.\");\n }\n}\n\nfunction getRequestIp (\n request: Request, protection: NextHealthRouteProtection\n): string | null {\n if (!protection.trustProxy) return null;\n\n const header = protection.proxyHeader ?? \"x-forwarded-for\";\n const value = request.headers.get(header);\n if (!value) return null;\n\n return value.split(\",\")[0]?.trim() ?? null;\n}\n\nfunction isAuthorized (\n request: Request, protection?: NextHealthRouteProtection\n): boolean {\n if (!protection) return true;\n\n if (protection.bearerToken) {\n const token = request.headers.get(\"authorization\")?.replace(\n /^Bearer\\s+/i, \"\"\n ) ?? \"\";\n if (!constantTimeEquals(\n token, protection.bearerToken\n )) {\n return false;\n }\n }\n\n if (protection.basicAuth) {\n const parsed = parseBasicAuth(request.headers.get(\"authorization\"));\n if (!parsed || !constantTimeEquals(\n parsed.username, protection.basicAuth.username\n ) || !constantTimeEquals(\n parsed.password, protection.basicAuth.password\n )) {\n return false;\n }\n }\n\n const ip = getRequestIp(\n request, protection\n );\n if (protection.allowIps?.length && (!ip || !protection.allowIps.includes(ip))) {\n return false;\n }\n\n if (protection.allowCidrs?.length && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(\n cidr, ip\n )))) {\n return false;\n }\n\n return true;\n}\n\nfunction unauthorized (): Response {\n return new Response(\n JSON.stringify({\n code: \"HEALTHCHECK_ROUTE_UNAUTHORIZED\",\n message: \"Unauthorized.\",\n }), {\n status: 401,\n headers: {\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store, max-age=0\",\n },\n }\n );\n}\n\nfunction mergeHeaders (...headersList: Array<HeadersInit | undefined>): Headers {\n const headers = new Headers();\n\n for (const headersInit of headersList) {\n if (!headersInit) continue;\n new Headers(headersInit).forEach((\n value, key\n ) => headers.set(\n key, value\n ));\n }\n\n return headers;\n}\n\nfunction baseHeaders (\n report: HealthReport, contentType: string\n): HeadersInit {\n return {\n \"cache-control\": \"no-store, max-age=0\",\n \"content-type\": contentType,\n \"x-health-status\": report.status,\n \"x-health-scope\": String(report.scope),\n \"x-health-duration-ms\": report.durationMs.toFixed(2),\n \"x-health-service\": report.service.name,\n ...(report.service.instanceId ? { \"x-health-instance\": report.service.instanceId, } : {}),\n };\n}\n\nfunction summaryBody (report: HealthReport): string {\n return JSON.stringify({\n status: report.status,\n scope: report.scope,\n observedAt: report.observedAt,\n durationMs: report.durationMs,\n summary: report.summary,\n });\n}\n\nexport function createNextHealthRoute (\n manager: HealthManager, options: NextHealthRouteOptions\n): {\n GET: (request: Request) => Promise<Response>\n HEAD: (request: Request) => Promise<Response>\n} {\n validateProtection(options.protect);\n\n if (options.cache !== undefined && options.cache !== \"no-store\") {\n throw invalidConfig(\"Health routes only support cache: no-store.\");\n }\n\n async function handle (\n request: Request, head = false\n ): Promise<Response> {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(options.scope);\n const includeDetails = typeof options.includeDetails === \"function\"\n ? options.includeDetails(request)\n : options.includeDetails ?? false;\n const body = options.format === \"summary\"\n ? summaryBody(report)\n : stringifyHealthJson(\n report, { includeDetails, }\n );\n const headers = mergeHeaders(\n baseHeaders(\n report, \"application/json; charset=utf-8\"\n ), typeof options.headers === \"function\" ? options.headers(report) : options.headers\n );\n\n return new Response(\n head ? null : body, {\n status: statusToHttpStatus(\n report.status, options.httpStatus ?? DEFAULT_HTTP_STATUS_POLICY\n ),\n headers,\n }\n );\n }\n\n return {\n GET: (request) => handle(request),\n HEAD: (request) => handle(\n request, true\n ),\n };\n}\n\nexport function createNextMetricsRoute (\n manager: HealthManager, options: NextMetricsRouteOptions\n): { GET: (request: Request) => Promise<Response> } {\n validateProtection(options.protect);\n\n return {\n async GET (request) {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(\n options.scope ?? \"all\", { profile: \"monitoring\", }\n );\n const contentType = options.format === \"json\"\n ? \"application/json; charset=utf-8\"\n : options.format === \"openmetrics\"\n ? \"application/openmetrics-text; version=1.0.0; charset=utf-8\"\n : \"text/plain; version=0.0.4; charset=utf-8\";\n const body = options.format === \"json\"\n ? JSON.stringify(toHealthJson(\n report, { includeDetails: false, }\n ))\n : options.format === \"openmetrics\"\n ? toOpenMetricsText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n )\n : toPrometheusText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n );\n\n return new Response(\n body, {\n status: 200,\n headers: baseHeaders(\n report, contentType\n ),\n }\n );\n },\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;
|
|
4
|
+
"sourcesContent": ["import type {\n HealthHttpStatusPolicy,\n HealthManager,\n HealthReport,\n HealthRunScope,\n HealthScope\n} from \"@nexload-sdk/healthcheck\";\n\nimport {\n DEFAULT_HTTP_STATUS_POLICY,\n statusToHttpStatus,\n stringifyHealthJson,\n toHealthJson\n} from \"@nexload-sdk/healthcheck\";\nimport {\n toOpenMetricsText,\n toPrometheusText\n} from \"@nexload-sdk/healthcheck-prometheus\";\n\nexport interface NextHealthRouteProtection {\n bearerToken?: string\n basicAuth?: {\n username: string\n password: string\n }\n allowCidrs?: readonly string[]\n allowIps?: readonly string[]\n trustProxy?: boolean\n proxyHeader?: \"x-forwarded-for\" | \"x-real-ip\" | string\n}\n\nexport interface NextHealthRouteOptions {\n scope: HealthScope\n format?: \"json\" | \"summary\"\n httpStatus?: HealthHttpStatusPolicy\n includeDetails?: boolean | ((request: Request) => boolean)\n protect?: NextHealthRouteProtection\n headers?: HeadersInit | ((report: HealthReport) => HeadersInit)\n cache?: \"no-store\"\n}\n\nexport interface NextMetricsRouteOptions {\n format: \"prometheus\" | \"openmetrics\" | \"json\"\n scope?: HealthRunScope\n protect?: NextHealthRouteProtection\n prefix?: string\n defaultLabels?: Record<string, string>\n}\n\nfunction constantTimeEquals (\n input: string, expected: string\n): boolean {\n const encoder = new TextEncoder();\n const inputBytes = encoder.encode(input);\n const expectedBytes = encoder.encode(expected);\n const length = Math.max(\n inputBytes.length, expectedBytes.length\n );\n let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;\n\n for (let index = 0; index < length; index += 1) {\n mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);\n }\n\n return mismatch === 0;\n}\n\nfunction parseBasicAuth (value: string | null): { username: string, password: string } | null {\n if (!value?.startsWith(\"Basic \")) return null;\n\n try {\n const decoded = atob(value.slice(\"Basic \".length));\n const separator = decoded.indexOf(\":\");\n\n if (separator === -1) return null;\n\n return {\n username: decoded.slice(\n 0, separator\n ),\n password: decoded.slice(separator + 1),\n };\n } catch {\n return null;\n }\n}\n\nfunction ipToNumber (ip: string): number | null {\n const parts = ip.split(\".\").map(Number);\n\n if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {\n return null;\n }\n\n return (((parts[0] ?? 0) << 24) >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);\n}\n\nfunction cidrContains (\n cidr: string, ip: string\n): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n const rangeNumber = ipToNumber(range ?? \"\");\n const ipNumber = ipToNumber(ip);\n\n if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {\n return false;\n }\n\n const mask = bits === 0 ? 0 : (0xffffffff << (32 - bits)) >>> 0;\n\n return (rangeNumber & mask) === (ipNumber & mask);\n}\n\nfunction isValidCidr (cidr: string): boolean {\n const [\n range,\n bitsRaw\n ] = cidr.split(\"/\");\n const bits = Number(bitsRaw);\n\n return ipToNumber(range ?? \"\") !== null\n && Number.isInteger(bits)\n && bits >= 0\n && bits <= 32;\n}\n\nfunction invalidConfig (message: string): Error {\n const error = new Error(message);\n error.name = \"HEALTHCHECK_INVALID_CONFIG\";\n\n return error;\n}\n\nfunction validateProtection (protection?: NextHealthRouteProtection): void {\n if (!protection) return;\n\n const hasBearer = \"bearerToken\" in protection;\n const hasBasic = protection.basicAuth !== undefined;\n const hasIps = (protection.allowIps?.length ?? 0) > 0;\n const hasCidrs = (protection.allowCidrs?.length ?? 0) > 0;\n\n if (!hasBearer && !hasBasic && !hasIps && !hasCidrs) {\n throw invalidConfig(\"Route protection must configure at least one access policy.\");\n }\n\n if (hasBearer && !protection.bearerToken?.trim()) {\n throw invalidConfig(\"Bearer token protection requires a non-empty token.\");\n }\n\n if (hasBasic && (!protection.basicAuth?.username.trim() || !protection.basicAuth.password)) {\n throw invalidConfig(\"Basic authentication requires a non-empty username and password.\");\n }\n\n if (hasBearer && hasBasic) {\n throw invalidConfig(\"Bearer and Basic authentication cannot share one Authorization header.\");\n }\n\n if ((hasIps || hasCidrs) && protection.trustProxy !== true) {\n throw invalidConfig(\"IP and CIDR protection require trustProxy: true.\");\n }\n\n if (protection.allowIps?.some((ip) => ipToNumber(ip) === null)) {\n throw invalidConfig(\"IP protection currently accepts valid IPv4 addresses only.\");\n }\n\n if (protection.allowCidrs?.some((cidr) => !isValidCidr(cidr))) {\n throw invalidConfig(\"CIDR protection currently accepts valid IPv4 CIDRs only.\");\n }\n}\n\nfunction getRequestIp (\n request: Request, protection: NextHealthRouteProtection\n): string | null {\n if (!protection.trustProxy) return null;\n\n const header = protection.proxyHeader ?? \"x-forwarded-for\";\n const value = request.headers.get(header);\n\n if (!value) return null;\n\n return value.split(\",\")[0]?.trim() ?? null;\n}\n\nfunction isAuthorized (\n request: Request, protection?: NextHealthRouteProtection\n): boolean {\n if (!protection) return true;\n\n if (protection.bearerToken) {\n const token = request.headers.get(\"authorization\")?.replace(\n /^Bearer\\s+/i, \"\"\n ) ?? \"\";\n\n if (!constantTimeEquals(\n token, protection.bearerToken\n )) {\n return false;\n }\n }\n\n if (protection.basicAuth) {\n const parsed = parseBasicAuth(request.headers.get(\"authorization\"));\n\n if (!parsed || !constantTimeEquals(\n parsed.username, protection.basicAuth.username\n ) || !constantTimeEquals(\n parsed.password, protection.basicAuth.password\n )) {\n return false;\n }\n }\n\n const ip = getRequestIp(\n request, protection\n );\n\n if (protection.allowIps?.length && (!ip || !protection.allowIps.includes(ip))) {\n return false;\n }\n\n if (protection.allowCidrs?.length && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(\n cidr, ip\n )))) {\n return false;\n }\n\n return true;\n}\n\nfunction unauthorized (): Response {\n return new Response(\n JSON.stringify({\n code: \"HEALTHCHECK_ROUTE_UNAUTHORIZED\",\n message: \"Unauthorized.\",\n }), {\n status: 401,\n headers: {\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store, max-age=0\",\n },\n }\n );\n}\n\nfunction mergeHeaders (...headersList: Array<HeadersInit | undefined>): Headers {\n const headers = new Headers();\n\n for (const headersInit of headersList) {\n if (!headersInit) continue;\n new Headers(headersInit).forEach((\n value, key\n ) => headers.set(\n key, value\n ));\n }\n\n return headers;\n}\n\nfunction baseHeaders (\n report: HealthReport, contentType: string\n): HeadersInit {\n return {\n \"cache-control\": \"no-store, max-age=0\",\n \"content-type\": contentType,\n \"x-health-status\": report.status,\n \"x-health-scope\": String(report.scope),\n \"x-health-duration-ms\": report.durationMs.toFixed(2),\n \"x-health-service\": report.service.name,\n ...(report.service.instanceId ? { \"x-health-instance\": report.service.instanceId, } : {}),\n };\n}\n\nfunction summaryBody (report: HealthReport): string {\n return JSON.stringify({\n status: report.status,\n scope: report.scope,\n observedAt: report.observedAt,\n durationMs: report.durationMs,\n summary: report.summary,\n });\n}\n\nexport function createNextHealthRoute (\n manager: HealthManager, options: NextHealthRouteOptions\n): {\n GET: (request: Request) => Promise<Response>\n HEAD: (request: Request) => Promise<Response>\n} {\n validateProtection(options.protect);\n\n if (options.cache !== undefined && options.cache !== \"no-store\") {\n throw invalidConfig(\"Health routes only support cache: no-store.\");\n }\n\n async function handle (\n request: Request, head = false\n ): Promise<Response> {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(options.scope);\n const includeDetails = typeof options.includeDetails === \"function\"\n ? options.includeDetails(request)\n : options.includeDetails ?? false;\n const body = options.format === \"summary\"\n ? summaryBody(report)\n : stringifyHealthJson(\n report, { includeDetails, }\n );\n const headers = mergeHeaders(\n baseHeaders(\n report, \"application/json; charset=utf-8\"\n ), typeof options.headers === \"function\" ? options.headers(report) : options.headers\n );\n\n return new Response(\n head ? null : body, {\n status: statusToHttpStatus(\n report.status, options.httpStatus ?? DEFAULT_HTTP_STATUS_POLICY\n ),\n headers,\n }\n );\n }\n\n return {\n GET: (request) => handle(request),\n HEAD: (request) => handle(\n request, true\n ),\n };\n}\n\nexport function createNextMetricsRoute (\n manager: HealthManager, options: NextMetricsRouteOptions\n): { GET: (request: Request) => Promise<Response> } {\n validateProtection(options.protect);\n\n return {\n async GET (request) {\n if (!isAuthorized(\n request, options.protect\n )) {\n return unauthorized();\n }\n\n const report = await manager.run(\n options.scope ?? \"all\", { profile: \"monitoring\", }\n );\n const contentType = options.format === \"json\"\n ? \"application/json; charset=utf-8\"\n : options.format === \"openmetrics\"\n ? \"application/openmetrics-text; version=1.0.0; charset=utf-8\"\n : \"text/plain; version=0.0.4; charset=utf-8\";\n const body = options.format === \"json\"\n ? JSON.stringify(toHealthJson(\n report, { includeDetails: false, }\n ))\n : options.format === \"openmetrics\"\n ? toOpenMetricsText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n )\n : toPrometheusText(\n report, { prefix: options.prefix, defaultLabels: options.defaultLabels, }\n );\n\n return new Response(\n body, {\n status: 200,\n headers: baseHeaders(\n report, contentType\n ),\n }\n );\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAgCP,SAAS,mBACP,OAAe,UACN;AACT,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,aAAa,QAAQ,OAAO,KAAK;AACvC,QAAM,gBAAgB,QAAQ,OAAO,QAAQ;AAC7C,QAAM,SAAS,KAAK;AAAA,IAClB,WAAW;AAAA,IAAQ,cAAc;AAAA,EACnC;AACA,MAAI,WAAW,WAAW,WAAW,cAAc,SAAS,IAAI;AAEhE,WAAS,QAAQ,GAAG,QAAQ,QAAQ,SAAS,GAAG;AAC9C,iBAAa,WAAW,KAAK,KAAK,MAAM,cAAc,KAAK,KAAK;AAAA,EAClE;AAEA,SAAO,aAAa;AACtB;AAEA,SAAS,eAAgB,OAAqE;AAC5F,MAAI,CAAC,OAAO,WAAW,QAAQ,EAAG,QAAO;AAEzC,MAAI;AACF,UAAM,UAAU,KAAK,MAAM,MAAM,SAAS,MAAM,CAAC;AACjD,UAAM,YAAY,QAAQ,QAAQ,GAAG;AAErC,QAAI,cAAc,GAAI,QAAO;AAE7B,WAAO;AAAA,MACL,UAAU,QAAQ;AAAA,QAChB;AAAA,QAAG;AAAA,MACL;AAAA,MACA,UAAU,QAAQ,MAAM,YAAY,CAAC;AAAA,IACvC;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,WAAY,IAA2B;AAC9C,QAAM,QAAQ,GAAG,MAAM,GAAG,EAAE,IAAI,MAAM;AAEtC,MAAI,MAAM,WAAW,KAAK,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,GAAG,GAAG;AACjG,WAAO;AAAA,EACT;AAEA,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,QACH;AAAA,QAAS,QAAQ;AAAA,MACnB,GAAG;AACD,eAAO,aAAa;AAAA,MACtB;AAEA,YAAM,SAAS,MAAM,QAAQ;AAAA,QAC3B,QAAQ,SAAS;AAAA,QAAO,EAAE,SAAS,aAAc;AAAA,MACnD;AACA,YAAM,cAAc,QAAQ,WAAW,SACnC,oCACA,QAAQ,WAAW,gBACjB,+DACA;AACN,YAAM,OAAO,QAAQ,WAAW,SAC5B,KAAK,UAAU;AAAA,QACf;AAAA,QAAQ,EAAE,gBAAgB,MAAO;AAAA,MACnC,CAAC,IACC,QAAQ,WAAW,gBACjB;AAAA,QACA;AAAA,QAAQ,EAAE,QAAQ,QAAQ,QAAQ,eAAe,QAAQ,cAAe;AAAA,MAC1E,IACE;AAAA,QACA;AAAA,QAAQ,EAAE,QAAQ,QAAQ,QAAQ,eAAe,QAAQ,cAAe;AAAA,MAC1E;AAEJ,aAAO,IAAI;AAAA,QACT;AAAA,QAAM;AAAA,UACJ,QAAQ;AAAA,UACR,SAAS;AAAA,YACP;AAAA,YAAQ;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexload-sdk/healthcheck-next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Next.js App Router route factories for @nexload-sdk/healthcheck.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nextjs",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nexload-sdk/healthcheck": "
|
|
36
|
-
"@nexload-sdk/healthcheck-prometheus": "
|
|
35
|
+
"@nexload-sdk/healthcheck": "5.0.0",
|
|
36
|
+
"@nexload-sdk/healthcheck-prometheus": "3.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^25.0.3",
|
|
40
40
|
"eslint": "^9.39.2",
|
|
41
41
|
"typescript": "5.9.3",
|
|
42
42
|
"@nexload-sdk/bundler": "4.0.1",
|
|
43
|
-
"@nexload-sdk/eslint-config": "
|
|
44
|
-
"@nexload-sdk/typescript-config": "
|
|
43
|
+
"@nexload-sdk/eslint-config": "9.39.2",
|
|
44
|
+
"@nexload-sdk/typescript-config": "5.9.3"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "node esbuild.config.mjs",
|