@limetry/preflight 0.0.0-stage → 1.2.49
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 +125 -2
- package/dist/checks.d.ts +46 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +61 -0
- package/dist/checks.js.map +1 -0
- package/dist/dotenv-files.d.ts +23 -0
- package/dist/dotenv-files.d.ts.map +1 -0
- package/dist/dotenv-files.js +57 -0
- package/dist/dotenv-files.js.map +1 -0
- package/dist/env-runtime.d.ts +43 -0
- package/dist/env-runtime.d.ts.map +1 -0
- package/dist/env-runtime.js +60 -0
- package/dist/env-runtime.js.map +1 -0
- package/dist/format.d.ts +40 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +94 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/listen-urls.d.ts +37 -0
- package/dist/listen-urls.d.ts.map +1 -0
- package/dist/listen-urls.js +91 -0
- package/dist/listen-urls.js.map +1 -0
- package/dist/logger.d.ts +14 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +64 -0
- package/dist/logger.js.map +1 -0
- package/dist/mask.d.ts +26 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +55 -0
- package/dist/mask.js.map +1 -0
- package/dist/ports.d.ts +58 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +134 -0
- package/dist/ports.js.map +1 -0
- package/dist/probes/http.d.ts +61 -0
- package/dist/probes/http.d.ts.map +1 -0
- package/dist/probes/http.js +106 -0
- package/dist/probes/http.js.map +1 -0
- package/dist/probes/postgres.d.ts +27 -0
- package/dist/probes/postgres.d.ts.map +1 -0
- package/dist/probes/postgres.js +64 -0
- package/dist/probes/postgres.js.map +1 -0
- package/dist/probes/posthog.d.ts +37 -0
- package/dist/probes/posthog.d.ts.map +1 -0
- package/dist/probes/posthog.js +79 -0
- package/dist/probes/posthog.js.map +1 -0
- package/dist/probes/redis.d.ts +25 -0
- package/dist/probes/redis.d.ts.map +1 -0
- package/dist/probes/redis.js +65 -0
- package/dist/probes/redis.js.map +1 -0
- package/dist/probes/sentry.d.ts +56 -0
- package/dist/probes/sentry.d.ts.map +1 -0
- package/dist/probes/sentry.js +130 -0
- package/dist/probes/sentry.js.map +1 -0
- package/dist/probes/telemetry.d.ts +30 -0
- package/dist/probes/telemetry.d.ts.map +1 -0
- package/dist/probes/telemetry.js +77 -0
- package/dist/probes/telemetry.js.map +1 -0
- package/dist/run.d.ts +70 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +82 -0
- package/dist/run.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Startup preflight checks for Limetry apps (`@limetry/preflight`).
|
|
3
|
+
*
|
|
4
|
+
* ## Env injection model
|
|
5
|
+
*
|
|
6
|
+
* This package is product-agnostic. It never assumes a Zod schema. Callers pass
|
|
7
|
+
* an injected `source: NodeJS.ProcessEnv` (often defaulting to `process.env` at
|
|
8
|
+
* the **call site only**). Helpers that already receive `source` must not read
|
|
9
|
+
* ambient `process.env` again — that breaks tests and hides missing keys.
|
|
10
|
+
*
|
|
11
|
+
* Product adapters (web, servers) should:
|
|
12
|
+
* 1. Parse a typed env object (Zod) for owned secrets/settings.
|
|
13
|
+
* 2. Pass the same `source` bag into `runPreflight` / probes for deployment
|
|
14
|
+
* flags (`NODE_ENV`, `VERCEL_*`, `NEXT_PHASE`) and shared origin resolvers.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export { connectivityIcon, envCheck } from "./checks.js";
|
|
19
|
+
export { annotated, listEffectiveDotenvFiles } from "./dotenv-files.js";
|
|
20
|
+
export { isNextBuildPhase, isProductionRuntime, isTestEnv, shouldFailHard, shouldProbeConnectivity, } from "./env-runtime.js";
|
|
21
|
+
export { formatPreflightReport, PREFLIGHT_SEPARATOR } from "./format.js";
|
|
22
|
+
export { expandListenUrls, isLoopbackHostname, lanIPv4Addresses, resolvePublicListenUrl, } from "./listen-urls.js";
|
|
23
|
+
export { createPreflightLogger } from "./logger.js";
|
|
24
|
+
export { maskSecret, redactDatabaseUrl } from "./mask.js";
|
|
25
|
+
export { getAvailablePort, isPortInUse, resolveAvailablePort, resolveDevListenPort, } from "./ports.js";
|
|
26
|
+
export { createHttpProbe, probeHttp, probeReachableOrigin, } from "./probes/http.js";
|
|
27
|
+
export { createPostgresProbe, probePostgres } from "./probes/postgres.js";
|
|
28
|
+
export { createPosthogProbe, probePosthogDecide, resolvePosthogHost } from "./probes/posthog.js";
|
|
29
|
+
export { createRedisProbe, probeRedis } from "./probes/redis.js";
|
|
30
|
+
export { createSentryProbe, isSentryIngestReachableStatus, parseSentryDsn, probeSentryIngest, sentryEnvelopeUrl, } from "./probes/sentry.js";
|
|
31
|
+
export { collectConfiguredTelemetry } from "./probes/telemetry.js";
|
|
32
|
+
export { runPreflight } from "./run.js";
|
|
33
|
+
export { checkBlocksStartup, } from "./types.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,uBAAuB,GACxB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,qBAAqB,EAAe,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACzD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,GAErB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,eAAe,EAEf,SAAS,EACT,oBAAoB,GACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAChG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,cAAc,EACd,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,0BAA0B,EAAwB,MAAM,uBAAuB,CAAA;AACxF,OAAO,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAA;AACjE,OAAO,EACL,kBAAkB,GAKnB,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen URL normalization for local and Vercel-hosted preflight banners.
|
|
3
|
+
*/
|
|
4
|
+
import type { NetworkInterfaceInfo } from "node:os";
|
|
5
|
+
/**
|
|
6
|
+
* True for loopback hostnames commonly used in local listen URLs.
|
|
7
|
+
*
|
|
8
|
+
* @param hostname - Hostname portion of a listen URL.
|
|
9
|
+
* @returns Whether the host should be treated as loopback.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Non-internal IPv4 addresses from the given (or OS) network interfaces.
|
|
14
|
+
* Reserved for tooling; banner listen URLs no longer enumerate LAN.
|
|
15
|
+
*
|
|
16
|
+
* @param interfaces - Interface map; defaults to `os.networkInterfaces()`.
|
|
17
|
+
* @returns List of non-internal IPv4 address strings.
|
|
18
|
+
*/
|
|
19
|
+
export declare function lanIPv4Addresses(interfaces?: NodeJS.Dict<NetworkInterfaceInfo[]>): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Returns the single canonical listen URL.
|
|
22
|
+
* Loopback hosts are normalized to `localhost` so 127.0.0.1 / ::1 / 0.0.0.0
|
|
23
|
+
* do not print as separate synonyms, and LAN interfaces are not enumerated.
|
|
24
|
+
*
|
|
25
|
+
* @param url - Raw listen URL from the server or adapter.
|
|
26
|
+
* @returns One-element array with the canonical URL, or `[url]` when unparsable.
|
|
27
|
+
*/
|
|
28
|
+
export declare function expandListenUrls(url: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Prefer Vercel production/preview host from `source`, else `fallback`.
|
|
31
|
+
*
|
|
32
|
+
* @param fallback - URL used when no Vercel host env vars are present.
|
|
33
|
+
* @param source - Injected env bag; read `VERCEL_*` from it only (not ambient process.env).
|
|
34
|
+
* @returns Absolute public HTTPS (or existing scheme) listen URL.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolvePublicListenUrl(fallback: string, source?: NodeJS.ProcessEnv): string;
|
|
37
|
+
//# sourceMappingURL=listen-urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen-urls.d.ts","sourceRoot":"","sources":["../src/listen-urls.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAGnD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO5D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,GAAE,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAuB,GACpE,MAAM,EAAE,CAYV;AAgBD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAWtD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAM,CAAC,UAAwB,GACtC,MAAM,CAUR"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen URL normalization for local and Vercel-hosted preflight banners.
|
|
3
|
+
*/
|
|
4
|
+
import { networkInterfaces } from "node:os";
|
|
5
|
+
/**
|
|
6
|
+
* True for loopback hostnames commonly used in local listen URLs.
|
|
7
|
+
*
|
|
8
|
+
* @param hostname - Hostname portion of a listen URL.
|
|
9
|
+
* @returns Whether the host should be treated as loopback.
|
|
10
|
+
*/
|
|
11
|
+
export function isLoopbackHostname(hostname) {
|
|
12
|
+
return hostname === "localhost"
|
|
13
|
+
|| hostname === "127.0.0.1"
|
|
14
|
+
|| hostname === "0.0.0.0"
|
|
15
|
+
|| hostname === "::"
|
|
16
|
+
|| hostname === "::1"
|
|
17
|
+
|| hostname === "[::1]";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Non-internal IPv4 addresses from the given (or OS) network interfaces.
|
|
21
|
+
* Reserved for tooling; banner listen URLs no longer enumerate LAN.
|
|
22
|
+
*
|
|
23
|
+
* @param interfaces - Interface map; defaults to `os.networkInterfaces()`.
|
|
24
|
+
* @returns List of non-internal IPv4 address strings.
|
|
25
|
+
*/
|
|
26
|
+
export function lanIPv4Addresses(interfaces = networkInterfaces()) {
|
|
27
|
+
const ips = [];
|
|
28
|
+
for (const addrs of Object.values(interfaces)) {
|
|
29
|
+
for (const addr of addrs ?? []) {
|
|
30
|
+
const family = String(addr.family);
|
|
31
|
+
const isV4 = family === "IPv4" || family === "4";
|
|
32
|
+
if (isV4 && !addr.internal) {
|
|
33
|
+
ips.push(addr.address);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return ips;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Builds a URL string from protocol, host, optional port, and path.
|
|
41
|
+
*
|
|
42
|
+
* @param protocol - URL protocol including trailing colon slash form from `URL`.
|
|
43
|
+
* @param host - Hostname to embed.
|
|
44
|
+
* @param port - Port string; omitted from the host part when empty.
|
|
45
|
+
* @param path - Path without a trailing slash (may be empty).
|
|
46
|
+
* @returns Assembled absolute URL string.
|
|
47
|
+
*/
|
|
48
|
+
function withPort(protocol, host, port, path) {
|
|
49
|
+
const hostPart = port ? `${host}:${port}` : host;
|
|
50
|
+
return `${protocol}//${hostPart}${path}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns the single canonical listen URL.
|
|
54
|
+
* Loopback hosts are normalized to `localhost` so 127.0.0.1 / ::1 / 0.0.0.0
|
|
55
|
+
* do not print as separate synonyms, and LAN interfaces are not enumerated.
|
|
56
|
+
*
|
|
57
|
+
* @param url - Raw listen URL from the server or adapter.
|
|
58
|
+
* @returns One-element array with the canonical URL, or `[url]` when unparsable.
|
|
59
|
+
*/
|
|
60
|
+
export function expandListenUrls(url) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = new URL(url);
|
|
63
|
+
const path = parsed.pathname === "/" ? "" : parsed.pathname.replace(/\/$/, "");
|
|
64
|
+
if (isLoopbackHostname(parsed.hostname)) {
|
|
65
|
+
return [withPort(parsed.protocol, "localhost", parsed.port, path)];
|
|
66
|
+
}
|
|
67
|
+
return [`${parsed.origin}${path}`];
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return [url];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Prefer Vercel production/preview host from `source`, else `fallback`.
|
|
75
|
+
*
|
|
76
|
+
* @param fallback - URL used when no Vercel host env vars are present.
|
|
77
|
+
* @param source - Injected env bag; read `VERCEL_*` from it only (not ambient process.env).
|
|
78
|
+
* @returns Absolute public HTTPS (or existing scheme) listen URL.
|
|
79
|
+
*/
|
|
80
|
+
export function resolvePublicListenUrl(fallback, source = process.env) {
|
|
81
|
+
if (source.VERCEL_ENV === "production" && source.VERCEL_PROJECT_PRODUCTION_URL) {
|
|
82
|
+
const host = source.VERCEL_PROJECT_PRODUCTION_URL.replace(/\/$/, "");
|
|
83
|
+
return host.startsWith("http") ? host : `https://${host}`;
|
|
84
|
+
}
|
|
85
|
+
if (source.VERCEL_URL) {
|
|
86
|
+
const host = source.VERCEL_URL.replace(/\/$/, "");
|
|
87
|
+
return host.startsWith("http") ? host : `https://${host}`;
|
|
88
|
+
}
|
|
89
|
+
return fallback;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=listen-urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen-urls.js","sourceRoot":"","sources":["../src/listen-urls.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,QAAQ,KAAK,WAAW;WAC1B,QAAQ,KAAK,WAAW;WACxB,QAAQ,KAAK,SAAS;WACtB,QAAQ,KAAK,IAAI;WACjB,QAAQ,KAAK,KAAK;WAClB,QAAQ,KAAK,OAAO,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,aAAkD,iBAAiB,EAAE;IAErE,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,EAAE,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,MAAM,CAAC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AMG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAgB,EAChB,SAA4B,OAAO,CAAC,GAAG;IAEvC,IAAI,MAAM,CAAC,UAAU,KAAK,YAAY,IAAI,MAAM,CAAC,6BAA6B,EAAE,CAAC;QAC/E,MAAM,IAAI,GAAG,MAAM,CAAC,6BAA6B,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACpE,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAA;IAC3D,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QACjD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAAA;IAC3D,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pino logger factory for preflight banners with pretty or JSON stdout writers.
|
|
3
|
+
*/
|
|
4
|
+
import { type Logger } from "pino";
|
|
5
|
+
/**
|
|
6
|
+
* Pino logger for preflight banners. Disabled in test; JSON when production + non-TTY.
|
|
7
|
+
*
|
|
8
|
+
* @param product - Product display name used in logger `name` and `base.product`.
|
|
9
|
+
* @param source - Injected env bag for `NODE_ENV` / `LOG_LEVEL` (not ambient re-reads).
|
|
10
|
+
* @returns Configured Pino {@link Logger}, or a disabled logger in test env.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPreflightLogger(product: string, source?: NodeJS.ProcessEnv): Logger;
|
|
13
|
+
export type { Logger };
|
|
14
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAa,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAA;AA0CxC;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAM,CAAC,UAAwB,GACtC,MAAM,CAqBR;AAED,YAAY,EAAE,MAAM,EAAE,CAAA"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pino logger factory for preflight banners with pretty or JSON stdout writers.
|
|
3
|
+
*/
|
|
4
|
+
import pino from "pino";
|
|
5
|
+
import { isTestEnv } from "./env-runtime.js";
|
|
6
|
+
/**
|
|
7
|
+
* Writes banner text as plain stdout; other records as JSON or message-only.
|
|
8
|
+
*
|
|
9
|
+
* @param chunk - Serialized Pino log line (usually JSON).
|
|
10
|
+
* @param jsonMode - When true, emit raw JSON for non-banner records.
|
|
11
|
+
* @returns Nothing; writes to `process.stdout`.
|
|
12
|
+
*/
|
|
13
|
+
function writePretty(chunk, jsonMode) {
|
|
14
|
+
try {
|
|
15
|
+
const record = JSON.parse(chunk);
|
|
16
|
+
if (record.preflightBanner && typeof record.msg === "string") {
|
|
17
|
+
process.stdout.write(`${record.msg}\n`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (jsonMode) {
|
|
21
|
+
process.stdout.write(chunk.endsWith("\n") ? chunk : `${chunk}\n`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (typeof record.msg === "string") {
|
|
25
|
+
process.stdout.write(`${record.msg}\n`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
process.stdout.write(chunk.endsWith("\n") ? chunk : `${chunk}\n`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
process.stdout.write(chunk.endsWith("\n") ? chunk : `${chunk}\n`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pino logger for preflight banners. Disabled in test; JSON when production + non-TTY.
|
|
37
|
+
*
|
|
38
|
+
* @param product - Product display name used in logger `name` and `base.product`.
|
|
39
|
+
* @param source - Injected env bag for `NODE_ENV` / `LOG_LEVEL` (not ambient re-reads).
|
|
40
|
+
* @returns Configured Pino {@link Logger}, or a disabled logger in test env.
|
|
41
|
+
*/
|
|
42
|
+
export function createPreflightLogger(product, source = process.env) {
|
|
43
|
+
if (isTestEnv(source)) {
|
|
44
|
+
return pino({ enabled: false });
|
|
45
|
+
}
|
|
46
|
+
const jsonMode = source.NODE_ENV === "production" && !process.stdout.isTTY;
|
|
47
|
+
const name = `${product.toLowerCase().replace(/\s+/g, "-")}.preflight`;
|
|
48
|
+
return pino({
|
|
49
|
+
name,
|
|
50
|
+
level: source.LOG_LEVEL ?? "info",
|
|
51
|
+
base: { product },
|
|
52
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
53
|
+
formatters: {
|
|
54
|
+
level(label) {
|
|
55
|
+
return { level: label };
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
write(chunk) {
|
|
60
|
+
writePretty(chunk, jsonMode);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAqB,MAAM,MAAM,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAW5C;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,QAAiB;IACnD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAuB,CAAA;QACtD,IAAI,MAAM,CAAC,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,IAAI,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAA;IACtE,OAAO,IAAI,CAAC;QACV,IAAI;QACJ,KAAK,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM;QACjC,IAAI,EAAE,EAAE,OAAO,EAAE;QACjB,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO;QACxC,UAAU,EAAE;YACV,KAAK,CAAC,KAAK;gBACT,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;YACzB,CAAC;SACF;KACF,EAAE;QACD,KAAK,CAAC,KAAa;YACjB,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC9B,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/mask.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret and database URL redaction helpers for preflight banner display.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Masks API keys / webhook secrets for banner display.
|
|
6
|
+
*
|
|
7
|
+
* Recognizes Stripe-style prefixes and generic `sk-` keys; otherwise returns a
|
|
8
|
+
* full mask. Unset values render as `"(unset)"`.
|
|
9
|
+
*
|
|
10
|
+
* @param value - Raw secret string, or undefined when unset.
|
|
11
|
+
* @returns Masked display string safe for logs and banners.
|
|
12
|
+
*/
|
|
13
|
+
export declare function maskSecret(value: string | undefined): string;
|
|
14
|
+
/**
|
|
15
|
+
* Splits a Postgres URL into display, host endpoint, and database name (no password).
|
|
16
|
+
*
|
|
17
|
+
* @param value - Connection string to parse.
|
|
18
|
+
* @returns Display path without credentials, host endpoint, and database name.
|
|
19
|
+
* Invalid URLs return `"(invalid)"` / `"(none)"` placeholders.
|
|
20
|
+
*/
|
|
21
|
+
export declare function redactDatabaseUrl(value: string): {
|
|
22
|
+
display: string;
|
|
23
|
+
endpoint: string;
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=mask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAa5D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG;IAChD,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb,CAiBA"}
|
package/dist/mask.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret and database URL redaction helpers for preflight banner display.
|
|
3
|
+
*/
|
|
4
|
+
const SECRET_PREFIXES = ["sk_live_", "sk_test_", "pk_live_", "pk_test_", "whsec_"];
|
|
5
|
+
const MASK = "•".repeat(10);
|
|
6
|
+
/**
|
|
7
|
+
* Masks API keys / webhook secrets for banner display.
|
|
8
|
+
*
|
|
9
|
+
* Recognizes Stripe-style prefixes and generic `sk-` keys; otherwise returns a
|
|
10
|
+
* full mask. Unset values render as `"(unset)"`.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Raw secret string, or undefined when unset.
|
|
13
|
+
* @returns Masked display string safe for logs and banners.
|
|
14
|
+
*/
|
|
15
|
+
export function maskSecret(value) {
|
|
16
|
+
if (!value) {
|
|
17
|
+
return "(unset)";
|
|
18
|
+
}
|
|
19
|
+
for (const prefix of SECRET_PREFIXES) {
|
|
20
|
+
if (value.startsWith(prefix)) {
|
|
21
|
+
return `${prefix}${MASK}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (value.startsWith("sk-")) {
|
|
25
|
+
return `sk-${MASK}`;
|
|
26
|
+
}
|
|
27
|
+
return MASK;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Splits a Postgres URL into display, host endpoint, and database name (no password).
|
|
31
|
+
*
|
|
32
|
+
* @param value - Connection string to parse.
|
|
33
|
+
* @returns Display path without credentials, host endpoint, and database name.
|
|
34
|
+
* Invalid URLs return `"(invalid)"` / `"(none)"` placeholders.
|
|
35
|
+
*/
|
|
36
|
+
export function redactDatabaseUrl(value) {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = new URL(value);
|
|
39
|
+
const endpoint = `${parsed.protocol}//${parsed.host}`;
|
|
40
|
+
const name = parsed.pathname.replace(/^\//, "");
|
|
41
|
+
return {
|
|
42
|
+
display: name ? `${endpoint}/${name}` : endpoint,
|
|
43
|
+
endpoint,
|
|
44
|
+
name: name || "(none)",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return {
|
|
49
|
+
display: "(invalid)",
|
|
50
|
+
endpoint: "(invalid)",
|
|
51
|
+
name: "(none)",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=mask.js.map
|
package/dist/mask.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAA;AAE3F,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAE3B;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAyB;IAClD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,OAAO,GAAG,MAAM,GAAG,IAAI,EAAE,CAAA;QAC3B,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,IAAI,EAAE,CAAA;IACrB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAK7C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC7B,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,IAAI,EAAE,CAAA;QACrD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC/C,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ;YAChD,QAAQ;YACR,IAAI,EAAE,IAAI,IAAI,QAAQ;SACvB,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,OAAO,EAAE,WAAW;YACpB,QAAQ,EAAE,WAAW;YACrB,IAAI,EAAE,QAAQ;SACf,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/ports.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local TCP port availability checks and preferred-port hopping for dev servers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Returns true when something is already bound to or accepting connections on the port.
|
|
6
|
+
*
|
|
7
|
+
* @param port - TCP port to inspect on loopback and default interfaces.
|
|
8
|
+
* @returns Whether the port appears occupied.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPortInUse(port: number): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Finds the first available port starting from a preferred value.
|
|
13
|
+
*
|
|
14
|
+
* @param preferredPort - First port to try.
|
|
15
|
+
* @param maxTries - Maximum consecutive ports to probe (default 50).
|
|
16
|
+
* @returns The first free port in `[preferredPort, preferredPort + maxTries)`.
|
|
17
|
+
* @throws Error When no free port is found within `maxTries`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAvailablePort(preferredPort: number, maxTries?: number): Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Result of resolving a listen port against occupancy.
|
|
22
|
+
*/
|
|
23
|
+
export type ResolvedPort = {
|
|
24
|
+
/**
|
|
25
|
+
* Port originally requested by the caller.
|
|
26
|
+
*/
|
|
27
|
+
preferred: number;
|
|
28
|
+
/**
|
|
29
|
+
* Port that should be used for listening.
|
|
30
|
+
*/
|
|
31
|
+
port: number;
|
|
32
|
+
/**
|
|
33
|
+
* `true` when `port` differs from `preferred`.
|
|
34
|
+
*/
|
|
35
|
+
changed: boolean;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a listen port, hopping forward when the preferred port is occupied.
|
|
39
|
+
*
|
|
40
|
+
* @param preferredPort - First port to try.
|
|
41
|
+
* @param maxTries - Maximum consecutive ports to probe (default 50).
|
|
42
|
+
* @returns Preferred port, chosen port, and whether they differ.
|
|
43
|
+
* @throws Error When {@link getAvailablePort} cannot find a free port.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveAvailablePort(preferredPort: number, maxTries?: number): Promise<ResolvedPort>;
|
|
46
|
+
/**
|
|
47
|
+
* In development, hop off an occupied preferred port. Otherwise return preferred unchanged.
|
|
48
|
+
*
|
|
49
|
+
* @param preferredPort - Configured listen port.
|
|
50
|
+
* @param options - Hop behavior controls.
|
|
51
|
+
* @returns Resolved listen port metadata.
|
|
52
|
+
* @throws Error When hopping is enabled and no free port is found.
|
|
53
|
+
*/
|
|
54
|
+
export declare function resolveDevListenPort(preferredPort: number, options?: {
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
maxTries?: number;
|
|
57
|
+
}): Promise<ResolvedPort>;
|
|
58
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA;;GAEG;AAsEH;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBhE;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,aAAa,EAAE,MAAM,EACrB,QAAQ,GAAE,MAA0B,GACnC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,EACrB,QAAQ,GAAE,MAA0B,GACnC,OAAO,CAAC,YAAY,CAAC,CAOvB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACb,GACL,OAAO,CAAC,YAAY,CAAC,CAWvB"}
|
package/dist/ports.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local TCP port availability checks and preferred-port hopping for dev servers.
|
|
3
|
+
*/
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
const CONNECT_HOSTS = ["127.0.0.1", "::1", "localhost"];
|
|
6
|
+
const CONNECT_TIMEOUT_MS = 150;
|
|
7
|
+
const DEFAULT_MAX_TRIES = 50;
|
|
8
|
+
/**
|
|
9
|
+
* Attempts a short TCP connect to detect an accepting listener.
|
|
10
|
+
*
|
|
11
|
+
* @param port - Port to probe.
|
|
12
|
+
* @param host - Host to connect to.
|
|
13
|
+
* @returns `true` when a connection succeeds within the timeout.
|
|
14
|
+
*/
|
|
15
|
+
function checkPortConnect(port, host) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
const socket = new net.Socket();
|
|
18
|
+
const finish = (inUse) => {
|
|
19
|
+
socket.removeAllListeners();
|
|
20
|
+
socket.destroy();
|
|
21
|
+
resolve(inUse);
|
|
22
|
+
};
|
|
23
|
+
socket.setTimeout(CONNECT_TIMEOUT_MS);
|
|
24
|
+
socket.once("connect", () => {
|
|
25
|
+
finish(true);
|
|
26
|
+
});
|
|
27
|
+
socket.once("timeout", () => {
|
|
28
|
+
finish(false);
|
|
29
|
+
});
|
|
30
|
+
socket.once("error", () => {
|
|
31
|
+
finish(false);
|
|
32
|
+
});
|
|
33
|
+
socket.connect(port, host);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Attempts to bind a temporary server to detect `EADDRINUSE`.
|
|
38
|
+
*
|
|
39
|
+
* @param port - Port to listen on.
|
|
40
|
+
* @param host - Optional bind host; when omitted, binds the default interface.
|
|
41
|
+
* @returns `true` when the port is already in use.
|
|
42
|
+
*/
|
|
43
|
+
function checkPortListen(port, host) {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const server = net.createServer();
|
|
46
|
+
server.unref();
|
|
47
|
+
server.once("error", (err) => {
|
|
48
|
+
resolve(err.code === "EADDRINUSE");
|
|
49
|
+
});
|
|
50
|
+
server.once("listening", () => {
|
|
51
|
+
server.close(() => {
|
|
52
|
+
resolve(false);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
if (host) {
|
|
56
|
+
server.listen(port, host);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
server.listen(port);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns true when something is already bound to or accepting connections on the port.
|
|
64
|
+
*
|
|
65
|
+
* @param port - TCP port to inspect on loopback and default interfaces.
|
|
66
|
+
* @returns Whether the port appears occupied.
|
|
67
|
+
*/
|
|
68
|
+
export async function isPortInUse(port) {
|
|
69
|
+
for (const host of CONNECT_HOSTS) {
|
|
70
|
+
if (await checkPortConnect(port, host)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (await checkPortListen(port, "127.0.0.1")) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (await checkPortListen(port)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Finds the first available port starting from a preferred value.
|
|
84
|
+
*
|
|
85
|
+
* @param preferredPort - First port to try.
|
|
86
|
+
* @param maxTries - Maximum consecutive ports to probe (default 50).
|
|
87
|
+
* @returns The first free port in `[preferredPort, preferredPort + maxTries)`.
|
|
88
|
+
* @throws Error When no free port is found within `maxTries`.
|
|
89
|
+
*/
|
|
90
|
+
export async function getAvailablePort(preferredPort, maxTries = DEFAULT_MAX_TRIES) {
|
|
91
|
+
for (let offset = 0; offset < maxTries; offset += 1) {
|
|
92
|
+
const candidate = preferredPort + offset;
|
|
93
|
+
if (!(await isPortInUse(candidate))) {
|
|
94
|
+
return candidate;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`Could not find an available port after ${maxTries} tries starting from ${preferredPort}`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolves a listen port, hopping forward when the preferred port is occupied.
|
|
101
|
+
*
|
|
102
|
+
* @param preferredPort - First port to try.
|
|
103
|
+
* @param maxTries - Maximum consecutive ports to probe (default 50).
|
|
104
|
+
* @returns Preferred port, chosen port, and whether they differ.
|
|
105
|
+
* @throws Error When {@link getAvailablePort} cannot find a free port.
|
|
106
|
+
*/
|
|
107
|
+
export async function resolveAvailablePort(preferredPort, maxTries = DEFAULT_MAX_TRIES) {
|
|
108
|
+
const port = await getAvailablePort(preferredPort, maxTries);
|
|
109
|
+
return {
|
|
110
|
+
preferred: preferredPort,
|
|
111
|
+
port,
|
|
112
|
+
changed: port !== preferredPort,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* In development, hop off an occupied preferred port. Otherwise return preferred unchanged.
|
|
117
|
+
*
|
|
118
|
+
* @param preferredPort - Configured listen port.
|
|
119
|
+
* @param options - Hop behavior controls.
|
|
120
|
+
* @returns Resolved listen port metadata.
|
|
121
|
+
* @throws Error When hopping is enabled and no free port is found.
|
|
122
|
+
*/
|
|
123
|
+
export async function resolveDevListenPort(preferredPort, options = {}) {
|
|
124
|
+
const enabled = options.enabled ?? true;
|
|
125
|
+
if (!enabled) {
|
|
126
|
+
return {
|
|
127
|
+
preferred: preferredPort,
|
|
128
|
+
port: preferredPort,
|
|
129
|
+
changed: false,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return resolveAvailablePort(preferredPort, options.maxTries ?? DEFAULT_MAX_TRIES);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.js","sourceRoot":"","sources":["../src/ports.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,GAAG,MAAM,UAAU,CAAA;AAE1B,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,WAAW,CAAU,CAAA;AAChE,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAC9B,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAE5B;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,IAAY,EAAE,IAAY;IAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,CAAA;QAE/B,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE;YACtC,MAAM,CAAC,kBA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K,aAAa;KAChC,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,aAAqB,EACrB,UAGI,EAAE;IAEN,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAA;IACvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;YACL,SAAS,EAAE,aAAa;YACxB,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,KAAK;SACf,CAAA;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,aAAa,EAAE,OAAO,CAAC,QAAQ,IAAI,iBAAiB,CAAC,CAAA;AACnF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP reachability probes used by connectivity checks and vendor wrappers.
|
|
3
|
+
*/
|
|
4
|
+
import type { ConnectivityProbe, ProbeResult } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Default timeout for HTTP and store probes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_PROBE_TIMEOUT_MS = 5000;
|
|
9
|
+
/**
|
|
10
|
+
* Optional request headers for HTTP probes.
|
|
11
|
+
*/
|
|
12
|
+
export type HttpHeaders = Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* GET/HEAD-style probe that treats only 2xx as success.
|
|
15
|
+
*
|
|
16
|
+
* @param input - Target URL and success/failure detail templates.
|
|
17
|
+
* @returns Probe result with elapsed timing in `detail`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function probeHttp(input: {
|
|
20
|
+
failure: string;
|
|
21
|
+
headers?: HttpHeaders;
|
|
22
|
+
method?: string;
|
|
23
|
+
success: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
url: string;
|
|
26
|
+
}): Promise<ProbeResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Treats any HTTP response (including 4xx/5xx) as reachability. Network errors fail.
|
|
29
|
+
*
|
|
30
|
+
* @param input - Target URL and success/failure detail templates.
|
|
31
|
+
* @returns Probe result with status code when reachable.
|
|
32
|
+
*/
|
|
33
|
+
export declare function probeReachableOrigin(input: {
|
|
34
|
+
failure: string;
|
|
35
|
+
headers?: HttpHeaders;
|
|
36
|
+
method?: string;
|
|
37
|
+
success: string;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
url: string;
|
|
40
|
+
}): Promise<ProbeResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Wraps {@link probeHttp} as a {@link ConnectivityProbe}, optionally retrying
|
|
43
|
+
* transient failures (useful when a sibling process is still booting).
|
|
44
|
+
*
|
|
45
|
+
* @param input - Probe identity plus {@link probeHttp} options.
|
|
46
|
+
* @returns Connectivity probe suitable for `runPreflight`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createHttpProbe(input: {
|
|
49
|
+
critical?: boolean;
|
|
50
|
+
failure: string;
|
|
51
|
+
headers?: HttpHeaders;
|
|
52
|
+
method?: string;
|
|
53
|
+
name: string;
|
|
54
|
+
required: boolean;
|
|
55
|
+
retries?: number;
|
|
56
|
+
retryDelayMs?: number;
|
|
57
|
+
success: string;
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
url: string;
|
|
60
|
+
}): ConnectivityProbe;
|
|
61
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/probes/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEjE;;GAEG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAA;AAE5C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAYhD;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,WA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