@nexload-sdk/healthcheck-next 2.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 +18 -0
- package/dist/index.cjs +260 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +241 -0
- package/dist/index.mjs.map +7 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @nexload-sdk/healthcheck-next
|
|
2
|
+
|
|
3
|
+
Next.js App Router route factories for `@nexload-sdk/healthcheck`.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createNextHealthRoute } from "@nexload-sdk/healthcheck-next";
|
|
7
|
+
import { health } from "@/lib/health";
|
|
8
|
+
|
|
9
|
+
export const runtime = "nodejs";
|
|
10
|
+
export const dynamic = "force-dynamic";
|
|
11
|
+
export const revalidate = 0;
|
|
12
|
+
export const fetchCache = "force-no-store";
|
|
13
|
+
|
|
14
|
+
export const { GET, HEAD } = createNextHealthRoute(health, {
|
|
15
|
+
scope: "readiness",
|
|
16
|
+
format: "json"
|
|
17
|
+
});
|
|
18
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// @nexload-sdk/healthcheck-next v1.0.0 (build 2026-06-21T16:03:30.148Z)
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
createNextHealthRoute: () => createNextHealthRoute,
|
|
25
|
+
createNextMetricsRoute: () => createNextMetricsRoute
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_healthcheck = require("@nexload-sdk/healthcheck");
|
|
29
|
+
var import_healthcheck_prometheus = require("@nexload-sdk/healthcheck-prometheus");
|
|
30
|
+
function constantTimeEquals(input, expected) {
|
|
31
|
+
const encoder = new TextEncoder();
|
|
32
|
+
const inputBytes = encoder.encode(input);
|
|
33
|
+
const expectedBytes = encoder.encode(expected);
|
|
34
|
+
const length = Math.max(
|
|
35
|
+
inputBytes.length,
|
|
36
|
+
expectedBytes.length
|
|
37
|
+
);
|
|
38
|
+
let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;
|
|
39
|
+
for (let index = 0; index < length; index += 1) {
|
|
40
|
+
mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);
|
|
41
|
+
}
|
|
42
|
+
return mismatch === 0;
|
|
43
|
+
}
|
|
44
|
+
function parseBasicAuth(value) {
|
|
45
|
+
if (!(value == null ? void 0 : value.startsWith("Basic "))) return null;
|
|
46
|
+
try {
|
|
47
|
+
const decoded = atob(value.slice("Basic ".length));
|
|
48
|
+
const separator = decoded.indexOf(":");
|
|
49
|
+
if (separator === -1) return null;
|
|
50
|
+
return {
|
|
51
|
+
username: decoded.slice(
|
|
52
|
+
0,
|
|
53
|
+
separator
|
|
54
|
+
),
|
|
55
|
+
password: decoded.slice(separator + 1)
|
|
56
|
+
};
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function ipToNumber(ip) {
|
|
62
|
+
const parts = ip.split(".").map(Number);
|
|
63
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return ((parts[0] ?? 0) << 24 >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);
|
|
67
|
+
}
|
|
68
|
+
function cidrContains(cidr, ip) {
|
|
69
|
+
const [
|
|
70
|
+
range,
|
|
71
|
+
bitsRaw
|
|
72
|
+
] = cidr.split("/");
|
|
73
|
+
const bits = Number(bitsRaw);
|
|
74
|
+
const rangeNumber = ipToNumber(range ?? "");
|
|
75
|
+
const ipNumber = ipToNumber(ip);
|
|
76
|
+
if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
|
|
80
|
+
return (rangeNumber & mask) === (ipNumber & mask);
|
|
81
|
+
}
|
|
82
|
+
function getRequestIp(request, protection) {
|
|
83
|
+
var _a;
|
|
84
|
+
if (!protection.trustProxy) return null;
|
|
85
|
+
const header = protection.proxyHeader ?? "x-forwarded-for";
|
|
86
|
+
const value = request.headers.get(header);
|
|
87
|
+
if (!value) return null;
|
|
88
|
+
return ((_a = value.split(",")[0]) == null ? void 0 : _a.trim()) ?? null;
|
|
89
|
+
}
|
|
90
|
+
function isAuthorized(request, protection) {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
if (!protection) return true;
|
|
93
|
+
if (protection.bearerToken) {
|
|
94
|
+
const token = ((_a = request.headers.get("authorization")) == null ? void 0 : _a.replace(
|
|
95
|
+
/^Bearer\s+/i,
|
|
96
|
+
""
|
|
97
|
+
)) ?? "";
|
|
98
|
+
if (!constantTimeEquals(
|
|
99
|
+
token,
|
|
100
|
+
protection.bearerToken
|
|
101
|
+
)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (protection.basicAuth) {
|
|
106
|
+
const parsed = parseBasicAuth(request.headers.get("authorization"));
|
|
107
|
+
if (!parsed || !constantTimeEquals(
|
|
108
|
+
parsed.username,
|
|
109
|
+
protection.basicAuth.username
|
|
110
|
+
) || !constantTimeEquals(
|
|
111
|
+
parsed.password,
|
|
112
|
+
protection.basicAuth.password
|
|
113
|
+
)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const ip = getRequestIp(
|
|
118
|
+
request,
|
|
119
|
+
protection
|
|
120
|
+
);
|
|
121
|
+
if (((_b = protection.allowIps) == null ? void 0 : _b.length) && (!ip || !protection.allowIps.includes(ip))) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
if (((_c = protection.allowCidrs) == null ? void 0 : _c.length) && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(
|
|
125
|
+
cidr,
|
|
126
|
+
ip
|
|
127
|
+
)))) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
function unauthorized() {
|
|
133
|
+
return new Response(
|
|
134
|
+
JSON.stringify({
|
|
135
|
+
code: "HEALTHCHECK_ROUTE_UNAUTHORIZED",
|
|
136
|
+
message: "Unauthorized."
|
|
137
|
+
}),
|
|
138
|
+
{
|
|
139
|
+
status: 401,
|
|
140
|
+
headers: {
|
|
141
|
+
"content-type": "application/json; charset=utf-8",
|
|
142
|
+
"cache-control": "no-store, max-age=0"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
function mergeHeaders(...headersList) {
|
|
148
|
+
const headers = new Headers();
|
|
149
|
+
for (const headersInit of headersList) {
|
|
150
|
+
if (!headersInit) continue;
|
|
151
|
+
new Headers(headersInit).forEach((value, key) => headers.set(
|
|
152
|
+
key,
|
|
153
|
+
value
|
|
154
|
+
));
|
|
155
|
+
}
|
|
156
|
+
return headers;
|
|
157
|
+
}
|
|
158
|
+
function baseHeaders(report, contentType) {
|
|
159
|
+
return {
|
|
160
|
+
"cache-control": "no-store, max-age=0",
|
|
161
|
+
"content-type": contentType,
|
|
162
|
+
"x-health-status": report.status,
|
|
163
|
+
"x-health-scope": String(report.scope),
|
|
164
|
+
"x-health-duration-ms": report.durationMs.toFixed(2),
|
|
165
|
+
"x-health-service": report.service.name,
|
|
166
|
+
...report.service.instanceId ? { "x-health-instance": report.service.instanceId } : {}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function summaryBody(report) {
|
|
170
|
+
return JSON.stringify({
|
|
171
|
+
status: report.status,
|
|
172
|
+
scope: report.scope,
|
|
173
|
+
observedAt: report.observedAt,
|
|
174
|
+
durationMs: report.durationMs,
|
|
175
|
+
summary: report.summary
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function createNextHealthRoute(manager, options) {
|
|
179
|
+
async function handle(request, head = false) {
|
|
180
|
+
if (!isAuthorized(
|
|
181
|
+
request,
|
|
182
|
+
options.protect
|
|
183
|
+
)) {
|
|
184
|
+
return unauthorized();
|
|
185
|
+
}
|
|
186
|
+
const report = await manager.run(options.scope);
|
|
187
|
+
const includeDetails = typeof options.includeDetails === "function" ? options.includeDetails(request) : options.includeDetails ?? false;
|
|
188
|
+
const body = options.format === "summary" ? summaryBody(report) : (0, import_healthcheck.stringifyHealthJson)(
|
|
189
|
+
report,
|
|
190
|
+
{ includeDetails }
|
|
191
|
+
);
|
|
192
|
+
const headers = mergeHeaders(
|
|
193
|
+
baseHeaders(
|
|
194
|
+
report,
|
|
195
|
+
"application/json; charset=utf-8"
|
|
196
|
+
),
|
|
197
|
+
typeof options.headers === "function" ? options.headers(report) : options.headers
|
|
198
|
+
);
|
|
199
|
+
return new Response(
|
|
200
|
+
head ? null : body,
|
|
201
|
+
{
|
|
202
|
+
status: (0, import_healthcheck.statusToHttpStatus)(
|
|
203
|
+
report.status,
|
|
204
|
+
options.httpStatus ?? import_healthcheck.DEFAULT_HTTP_STATUS_POLICY
|
|
205
|
+
),
|
|
206
|
+
headers
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
GET: (request) => handle(request),
|
|
212
|
+
HEAD: (request) => handle(
|
|
213
|
+
request,
|
|
214
|
+
true
|
|
215
|
+
)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function createNextMetricsRoute(manager, options) {
|
|
219
|
+
return {
|
|
220
|
+
async GET(request) {
|
|
221
|
+
if (!isAuthorized(
|
|
222
|
+
request,
|
|
223
|
+
options.protect
|
|
224
|
+
)) {
|
|
225
|
+
return unauthorized();
|
|
226
|
+
}
|
|
227
|
+
const report = await manager.run(
|
|
228
|
+
options.scope ?? "all",
|
|
229
|
+
{ profile: "monitoring" }
|
|
230
|
+
);
|
|
231
|
+
const contentType = options.format === "json" ? "application/json; charset=utf-8" : options.format === "openmetrics" ? "application/openmetrics-text; version=1.0.0; charset=utf-8" : "text/plain; version=0.0.4; charset=utf-8";
|
|
232
|
+
const body = options.format === "json" ? JSON.stringify((0, import_healthcheck.toHealthJson)(
|
|
233
|
+
report,
|
|
234
|
+
{ includeDetails: false }
|
|
235
|
+
)) : options.format === "openmetrics" ? (0, import_healthcheck_prometheus.toOpenMetricsText)(
|
|
236
|
+
report,
|
|
237
|
+
{ prefix: options.prefix, defaultLabels: options.defaultLabels }
|
|
238
|
+
) : (0, import_healthcheck_prometheus.toPrometheusText)(
|
|
239
|
+
report,
|
|
240
|
+
{ prefix: options.prefix, defaultLabels: options.defaultLabels }
|
|
241
|
+
);
|
|
242
|
+
return new Response(
|
|
243
|
+
body,
|
|
244
|
+
{
|
|
245
|
+
status: 200,
|
|
246
|
+
headers: baseHeaders(
|
|
247
|
+
report,
|
|
248
|
+
contentType
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
256
|
+
0 && (module.exports = {
|
|
257
|
+
createNextHealthRoute,
|
|
258
|
+
createNextMetricsRoute
|
|
259
|
+
});
|
|
260
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 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 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 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;AAAA,yBAK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5B,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
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HealthHttpStatusPolicy, HealthManager, HealthReport, HealthRunScope, HealthScope } from "@nexload-sdk/healthcheck";
|
|
2
|
+
export interface NextHealthRouteProtection {
|
|
3
|
+
bearerToken?: string;
|
|
4
|
+
basicAuth?: {
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
};
|
|
8
|
+
allowCidrs?: readonly string[];
|
|
9
|
+
allowIps?: readonly string[];
|
|
10
|
+
trustProxy?: boolean;
|
|
11
|
+
proxyHeader?: "x-forwarded-for" | "x-real-ip" | string;
|
|
12
|
+
}
|
|
13
|
+
export interface NextHealthRouteOptions {
|
|
14
|
+
scope: HealthScope;
|
|
15
|
+
format?: "json" | "summary";
|
|
16
|
+
httpStatus?: HealthHttpStatusPolicy;
|
|
17
|
+
includeDetails?: boolean | ((request: Request) => boolean);
|
|
18
|
+
protect?: NextHealthRouteProtection;
|
|
19
|
+
headers?: HeadersInit | ((report: HealthReport) => HeadersInit);
|
|
20
|
+
cache?: "no-store";
|
|
21
|
+
}
|
|
22
|
+
export interface NextMetricsRouteOptions {
|
|
23
|
+
format: "prometheus" | "openmetrics" | "json";
|
|
24
|
+
scope?: HealthRunScope;
|
|
25
|
+
protect?: NextHealthRouteProtection;
|
|
26
|
+
prefix?: string;
|
|
27
|
+
defaultLabels?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createNextHealthRoute(manager: HealthManager, options: NextHealthRouteOptions): {
|
|
30
|
+
GET: (request: Request) => Promise<Response>;
|
|
31
|
+
HEAD: (request: Request) => Promise<Response>;
|
|
32
|
+
};
|
|
33
|
+
export declare function createNextMetricsRoute(manager: HealthManager, options: NextMetricsRouteOptions): {
|
|
34
|
+
GET: (request: Request) => Promise<Response>;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAElC,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,CAAC,EAAE,OAAO,CAAA;IACpB,WAAW,CAAC,EAAE,iBAAiB,GAAG,WAAW,GAAG,MAAM,CAAA;CACvD;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,WAAW,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,cAAc,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,CAAA;IAC1D,OAAO,CAAC,EAAE,yBAAyB,CAAA;IACnC,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,YAAY,KAAK,WAAW,CAAC,CAAA;IAC/D,KAAK,CAAC,EAAE,UAAU,CAAA;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAA;IAC7C,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,OAAO,CAAC,EAAE,yBAAyB,CAAA;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC;AAgLD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,sBAAsB,GACtD;IACD,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC5C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC9C,CAyCA;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,uBAAuB,GACvD;IAAE,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,CAuClD"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @nexload-sdk/healthcheck-next v1.0.0 (build 2026-06-21T16:03:30.021Z)
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_HTTP_STATUS_POLICY,
|
|
6
|
+
statusToHttpStatus,
|
|
7
|
+
stringifyHealthJson,
|
|
8
|
+
toHealthJson
|
|
9
|
+
} from "@nexload-sdk/healthcheck";
|
|
10
|
+
import {
|
|
11
|
+
toOpenMetricsText,
|
|
12
|
+
toPrometheusText
|
|
13
|
+
} from "@nexload-sdk/healthcheck-prometheus";
|
|
14
|
+
function constantTimeEquals(input, expected) {
|
|
15
|
+
const encoder = new TextEncoder();
|
|
16
|
+
const inputBytes = encoder.encode(input);
|
|
17
|
+
const expectedBytes = encoder.encode(expected);
|
|
18
|
+
const length = Math.max(
|
|
19
|
+
inputBytes.length,
|
|
20
|
+
expectedBytes.length
|
|
21
|
+
);
|
|
22
|
+
let mismatch = inputBytes.length === expectedBytes.length ? 0 : 1;
|
|
23
|
+
for (let index = 0; index < length; index += 1) {
|
|
24
|
+
mismatch |= (inputBytes[index] ?? 0) ^ (expectedBytes[index] ?? 0);
|
|
25
|
+
}
|
|
26
|
+
return mismatch === 0;
|
|
27
|
+
}
|
|
28
|
+
function parseBasicAuth(value) {
|
|
29
|
+
if (!value?.startsWith("Basic ")) return null;
|
|
30
|
+
try {
|
|
31
|
+
const decoded = atob(value.slice("Basic ".length));
|
|
32
|
+
const separator = decoded.indexOf(":");
|
|
33
|
+
if (separator === -1) return null;
|
|
34
|
+
return {
|
|
35
|
+
username: decoded.slice(
|
|
36
|
+
0,
|
|
37
|
+
separator
|
|
38
|
+
),
|
|
39
|
+
password: decoded.slice(separator + 1)
|
|
40
|
+
};
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function ipToNumber(ip) {
|
|
46
|
+
const parts = ip.split(".").map(Number);
|
|
47
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return ((parts[0] ?? 0) << 24 >>> 0) + ((parts[1] ?? 0) << 16) + ((parts[2] ?? 0) << 8) + (parts[3] ?? 0);
|
|
51
|
+
}
|
|
52
|
+
function cidrContains(cidr, ip) {
|
|
53
|
+
const [
|
|
54
|
+
range,
|
|
55
|
+
bitsRaw
|
|
56
|
+
] = cidr.split("/");
|
|
57
|
+
const bits = Number(bitsRaw);
|
|
58
|
+
const rangeNumber = ipToNumber(range ?? "");
|
|
59
|
+
const ipNumber = ipToNumber(ip);
|
|
60
|
+
if (rangeNumber === null || ipNumber === null || !Number.isInteger(bits) || bits < 0 || bits > 32) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
|
|
64
|
+
return (rangeNumber & mask) === (ipNumber & mask);
|
|
65
|
+
}
|
|
66
|
+
function getRequestIp(request, protection) {
|
|
67
|
+
if (!protection.trustProxy) return null;
|
|
68
|
+
const header = protection.proxyHeader ?? "x-forwarded-for";
|
|
69
|
+
const value = request.headers.get(header);
|
|
70
|
+
if (!value) return null;
|
|
71
|
+
return value.split(",")[0]?.trim() ?? null;
|
|
72
|
+
}
|
|
73
|
+
function isAuthorized(request, protection) {
|
|
74
|
+
if (!protection) return true;
|
|
75
|
+
if (protection.bearerToken) {
|
|
76
|
+
const token = request.headers.get("authorization")?.replace(
|
|
77
|
+
/^Bearer\s+/i,
|
|
78
|
+
""
|
|
79
|
+
) ?? "";
|
|
80
|
+
if (!constantTimeEquals(
|
|
81
|
+
token,
|
|
82
|
+
protection.bearerToken
|
|
83
|
+
)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (protection.basicAuth) {
|
|
88
|
+
const parsed = parseBasicAuth(request.headers.get("authorization"));
|
|
89
|
+
if (!parsed || !constantTimeEquals(
|
|
90
|
+
parsed.username,
|
|
91
|
+
protection.basicAuth.username
|
|
92
|
+
) || !constantTimeEquals(
|
|
93
|
+
parsed.password,
|
|
94
|
+
protection.basicAuth.password
|
|
95
|
+
)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const ip = getRequestIp(
|
|
100
|
+
request,
|
|
101
|
+
protection
|
|
102
|
+
);
|
|
103
|
+
if (protection.allowIps?.length && (!ip || !protection.allowIps.includes(ip))) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (protection.allowCidrs?.length && (!ip || !protection.allowCidrs.some((cidr) => cidrContains(
|
|
107
|
+
cidr,
|
|
108
|
+
ip
|
|
109
|
+
)))) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
function unauthorized() {
|
|
115
|
+
return new Response(
|
|
116
|
+
JSON.stringify({
|
|
117
|
+
code: "HEALTHCHECK_ROUTE_UNAUTHORIZED",
|
|
118
|
+
message: "Unauthorized."
|
|
119
|
+
}),
|
|
120
|
+
{
|
|
121
|
+
status: 401,
|
|
122
|
+
headers: {
|
|
123
|
+
"content-type": "application/json; charset=utf-8",
|
|
124
|
+
"cache-control": "no-store, max-age=0"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
function mergeHeaders(...headersList) {
|
|
130
|
+
const headers = new Headers();
|
|
131
|
+
for (const headersInit of headersList) {
|
|
132
|
+
if (!headersInit) continue;
|
|
133
|
+
new Headers(headersInit).forEach((value, key) => headers.set(
|
|
134
|
+
key,
|
|
135
|
+
value
|
|
136
|
+
));
|
|
137
|
+
}
|
|
138
|
+
return headers;
|
|
139
|
+
}
|
|
140
|
+
function baseHeaders(report, contentType) {
|
|
141
|
+
return {
|
|
142
|
+
"cache-control": "no-store, max-age=0",
|
|
143
|
+
"content-type": contentType,
|
|
144
|
+
"x-health-status": report.status,
|
|
145
|
+
"x-health-scope": String(report.scope),
|
|
146
|
+
"x-health-duration-ms": report.durationMs.toFixed(2),
|
|
147
|
+
"x-health-service": report.service.name,
|
|
148
|
+
...report.service.instanceId ? { "x-health-instance": report.service.instanceId } : {}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function summaryBody(report) {
|
|
152
|
+
return JSON.stringify({
|
|
153
|
+
status: report.status,
|
|
154
|
+
scope: report.scope,
|
|
155
|
+
observedAt: report.observedAt,
|
|
156
|
+
durationMs: report.durationMs,
|
|
157
|
+
summary: report.summary
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function createNextHealthRoute(manager, options) {
|
|
161
|
+
async function handle(request, head = false) {
|
|
162
|
+
if (!isAuthorized(
|
|
163
|
+
request,
|
|
164
|
+
options.protect
|
|
165
|
+
)) {
|
|
166
|
+
return unauthorized();
|
|
167
|
+
}
|
|
168
|
+
const report = await manager.run(options.scope);
|
|
169
|
+
const includeDetails = typeof options.includeDetails === "function" ? options.includeDetails(request) : options.includeDetails ?? false;
|
|
170
|
+
const body = options.format === "summary" ? summaryBody(report) : stringifyHealthJson(
|
|
171
|
+
report,
|
|
172
|
+
{ includeDetails }
|
|
173
|
+
);
|
|
174
|
+
const headers = mergeHeaders(
|
|
175
|
+
baseHeaders(
|
|
176
|
+
report,
|
|
177
|
+
"application/json; charset=utf-8"
|
|
178
|
+
),
|
|
179
|
+
typeof options.headers === "function" ? options.headers(report) : options.headers
|
|
180
|
+
);
|
|
181
|
+
return new Response(
|
|
182
|
+
head ? null : body,
|
|
183
|
+
{
|
|
184
|
+
status: statusToHttpStatus(
|
|
185
|
+
report.status,
|
|
186
|
+
options.httpStatus ?? DEFAULT_HTTP_STATUS_POLICY
|
|
187
|
+
),
|
|
188
|
+
headers
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
GET: (request) => handle(request),
|
|
194
|
+
HEAD: (request) => handle(
|
|
195
|
+
request,
|
|
196
|
+
true
|
|
197
|
+
)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function createNextMetricsRoute(manager, options) {
|
|
201
|
+
return {
|
|
202
|
+
async GET(request) {
|
|
203
|
+
if (!isAuthorized(
|
|
204
|
+
request,
|
|
205
|
+
options.protect
|
|
206
|
+
)) {
|
|
207
|
+
return unauthorized();
|
|
208
|
+
}
|
|
209
|
+
const report = await manager.run(
|
|
210
|
+
options.scope ?? "all",
|
|
211
|
+
{ profile: "monitoring" }
|
|
212
|
+
);
|
|
213
|
+
const contentType = options.format === "json" ? "application/json; charset=utf-8" : options.format === "openmetrics" ? "application/openmetrics-text; version=1.0.0; charset=utf-8" : "text/plain; version=0.0.4; charset=utf-8";
|
|
214
|
+
const body = options.format === "json" ? JSON.stringify(toHealthJson(
|
|
215
|
+
report,
|
|
216
|
+
{ includeDetails: false }
|
|
217
|
+
)) : options.format === "openmetrics" ? toOpenMetricsText(
|
|
218
|
+
report,
|
|
219
|
+
{ prefix: options.prefix, defaultLabels: options.defaultLabels }
|
|
220
|
+
) : toPrometheusText(
|
|
221
|
+
report,
|
|
222
|
+
{ prefix: options.prefix, defaultLabels: options.defaultLabels }
|
|
223
|
+
);
|
|
224
|
+
return new Response(
|
|
225
|
+
body,
|
|
226
|
+
{
|
|
227
|
+
status: 200,
|
|
228
|
+
headers: baseHeaders(
|
|
229
|
+
report,
|
|
230
|
+
contentType
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
createNextHealthRoute,
|
|
239
|
+
createNextMetricsRoute
|
|
240
|
+
};
|
|
241
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 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 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 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,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAwCP,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;AACrC,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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ACF;AAEO,SAAS,uBACd,SAAwB,SAC0B;AAClD,SAAO;AAAA,IACL,MAAM,IAAK,SAAS;AAClB,UAAI,CAAC;AAAA,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
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexload-sdk/healthcheck-next",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Next.js App Router route factories for @nexload-sdk/healthcheck.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nextjs",
|
|
7
|
+
"healthcheck",
|
|
8
|
+
"app-router",
|
|
9
|
+
"monitoring"
|
|
10
|
+
],
|
|
11
|
+
"author": "GecutWeb",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"package.json"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nexload-sdk/healthcheck-prometheus": "2.0.0",
|
|
36
|
+
"@nexload-sdk/healthcheck": "4.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^25.0.3",
|
|
40
|
+
"eslint": "^9.39.2",
|
|
41
|
+
"typescript": "5.9.3",
|
|
42
|
+
"@nexload-sdk/bundler": "4.0.1",
|
|
43
|
+
"@nexload-sdk/eslint-config": "4.0.1",
|
|
44
|
+
"@nexload-sdk/typescript-config": "4.0.1"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "node esbuild.config.mjs",
|
|
48
|
+
"lint": "eslint src",
|
|
49
|
+
"test": "node --test test/*.test.mjs"
|
|
50
|
+
}
|
|
51
|
+
}
|