@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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP reachability probes used by connectivity checks and vendor wrappers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default timeout for HTTP and store probes.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_PROBE_TIMEOUT_MS = 5000;
|
|
8
|
+
/**
|
|
9
|
+
* Formats elapsed milliseconds since `started` for probe detail suffixes.
|
|
10
|
+
*
|
|
11
|
+
* @param started - `Date.now()` captured at probe start.
|
|
12
|
+
* @returns Elapsed duration string such as `"42ms"`.
|
|
13
|
+
*/
|
|
14
|
+
function elapsedSuffix(started) {
|
|
15
|
+
return `${Date.now() - started}ms`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* GET/HEAD-style probe that treats only 2xx as success.
|
|
19
|
+
*
|
|
20
|
+
* @param input - Target URL and success/failure detail templates.
|
|
21
|
+
* @returns Probe result with elapsed timing in `detail`.
|
|
22
|
+
*/
|
|
23
|
+
export async function probeHttp(input) {
|
|
24
|
+
const started = Date.now();
|
|
25
|
+
const timeoutMs = input.timeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(input.url, {
|
|
28
|
+
method: input.method ?? "GET",
|
|
29
|
+
headers: input.headers,
|
|
30
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
31
|
+
});
|
|
32
|
+
const elapsed = elapsedSuffix(started);
|
|
33
|
+
if (response.ok) {
|
|
34
|
+
return {
|
|
35
|
+
ok: true,
|
|
36
|
+
detail: `${input.success} (${elapsed}).`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
detail: `${input.failure} (${elapsed}): HTTP ${response.status}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const reason = error instanceof Error ? error.message : "request failed";
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
detail: `${input.failure} (${elapsedSuffix(started)}): ${reason}`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Treats any HTTP response (including 4xx/5xx) as reachability. Network errors fail.
|
|
54
|
+
*
|
|
55
|
+
* @param input - Target URL and success/failure detail templates.
|
|
56
|
+
* @returns Probe result with status code when reachable.
|
|
57
|
+
*/
|
|
58
|
+
export async function probeReachableOrigin(input) {
|
|
59
|
+
const started = Date.now();
|
|
60
|
+
const timeoutMs = input.timeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(input.url, {
|
|
63
|
+
method: input.method ?? "GET",
|
|
64
|
+
headers: input.headers,
|
|
65
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
ok: true,
|
|
69
|
+
detail: `${input.success} (${elapsedSuffix(started)}, HTTP ${response.status}).`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
const reason = error instanceof Error ? error.message : "request failed";
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
detail: `${input.failure} (${elapsedSuffix(started)}): ${reason}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Wraps {@link probeHttp} as a {@link ConnectivityProbe}, optionally retrying
|
|
82
|
+
* transient failures (useful when a sibling process is still booting).
|
|
83
|
+
*
|
|
84
|
+
* @param input - Probe identity plus {@link probeHttp} options.
|
|
85
|
+
* @returns Connectivity probe suitable for `runPreflight`.
|
|
86
|
+
*/
|
|
87
|
+
export function createHttpProbe(input) {
|
|
88
|
+
const retries = Math.max(0, input.retries ?? 0);
|
|
89
|
+
const retryDelayMs = input.retryDelayMs ?? 400;
|
|
90
|
+
return {
|
|
91
|
+
name: input.name,
|
|
92
|
+
required: input.required,
|
|
93
|
+
critical: input.critical,
|
|
94
|
+
run: async () => {
|
|
95
|
+
let last = await probeHttp(input);
|
|
96
|
+
for (let attempt = 0; attempt < retries && !last.ok; attempt += 1) {
|
|
97
|
+
await new Promise((resolve) => {
|
|
98
|
+
setTimeout(resolve, retryDelayMs);
|
|
99
|
+
});
|
|
100
|
+
last = await probeHttp(input);
|
|
101
|
+
}
|
|
102
|
+
return last;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/probes/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAA;AAO5C;;;;;GAKG;AACH,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,IAAI,CAAA;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK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AI,CAAC,EAAE,CAAC;gBAClE,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;oBAC5B,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;gBACnC,CAAC,CAAC,CAAA;gBACF,IAAI,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres connectivity probe (`SELECT 1`) via optional peer dependency `pg`.
|
|
3
|
+
*/
|
|
4
|
+
import type { ConnectivityProbe, ProbeResult } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Runs `SELECT 1` against Postgres. Requires optional peer `pg`.
|
|
7
|
+
*
|
|
8
|
+
* @param url - Postgres connection string.
|
|
9
|
+
* @param timeoutMs - Connection timeout in milliseconds (default {@link DEFAULT_PROBE_TIMEOUT_MS}).
|
|
10
|
+
* @returns Probe result; fails when `pg` is missing or the query errors.
|
|
11
|
+
*/
|
|
12
|
+
export declare function probePostgres(url: string, timeoutMs?: number): Promise<ProbeResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Wraps {@link probePostgres} as a {@link ConnectivityProbe}.
|
|
15
|
+
*
|
|
16
|
+
* @param input - Connection options: `url` (Postgres connection string), `required` (whether
|
|
17
|
+
* failure can block startup), optional `critical` (hard-fail override when required), and
|
|
18
|
+
* optional `timeoutMs` (connection timeout forwarded to {@link probePostgres}).
|
|
19
|
+
* @returns Named `"postgres"` connectivity probe.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPostgresProbe(input: {
|
|
22
|
+
critical?: boolean;
|
|
23
|
+
required: boolean;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
url: string;
|
|
26
|
+
}): ConnectivityProbe;
|
|
27
|
+
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/probes/postgres.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGjE;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,SAAS,SAA2B,GACnC,OAAO,CAAC,WAAW,CAAC,CAgCtB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,iBAAiB,CAOpB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres connectivity probe (`SELECT 1`) via optional peer dependency `pg`.
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_PROBE_TIMEOUT_MS } from "./http.js";
|
|
5
|
+
/**
|
|
6
|
+
* Runs `SELECT 1` against Postgres. Requires optional peer `pg`.
|
|
7
|
+
*
|
|
8
|
+
* @param url - Postgres connection string.
|
|
9
|
+
* @param timeoutMs - Connection timeout in milliseconds (default {@link DEFAULT_PROBE_TIMEOUT_MS}).
|
|
10
|
+
* @returns Probe result; fails when `pg` is missing or the query errors.
|
|
11
|
+
*/
|
|
12
|
+
export async function probePostgres(url, timeoutMs = DEFAULT_PROBE_TIMEOUT_MS) {
|
|
13
|
+
const started = Date.now();
|
|
14
|
+
let PoolCtor;
|
|
15
|
+
try {
|
|
16
|
+
const pg = await import("pg");
|
|
17
|
+
PoolCtor = pg.Pool;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
detail: "Database connection failed: pg is not installed in this process.",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const pool = new PoolCtor({
|
|
26
|
+
connectionString: url,
|
|
27
|
+
connectionTimeoutMillis: timeoutMs,
|
|
28
|
+
max: 1,
|
|
29
|
+
});
|
|
30
|
+
try {
|
|
31
|
+
await pool.query("SELECT 1");
|
|
32
|
+
return {
|
|
33
|
+
ok: true,
|
|
34
|
+
detail: `Database connected successfully (${Date.now() - started}ms).`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const reason = error instanceof Error ? error.message : "query failed";
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
detail: `Database connection failed (${Date.now() - started}ms): ${reason}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
await pool.end();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Wraps {@link probePostgres} as a {@link ConnectivityProbe}.
|
|
50
|
+
*
|
|
51
|
+
* @param input - Connection options: `url` (Postgres connection string), `required` (whether
|
|
52
|
+
* failure can block startup), optional `critical` (hard-fail override when required), and
|
|
53
|
+
* optional `timeoutMs` (connection timeout forwarded to {@link probePostgres}).
|
|
54
|
+
* @returns Named `"postgres"` connectivity probe.
|
|
55
|
+
*/
|
|
56
|
+
export function createPostgresProbe(input) {
|
|
57
|
+
return {
|
|
58
|
+
name: "postgres",
|
|
59
|
+
required: input.required,
|
|
60
|
+
critical: input.critical,
|
|
61
|
+
run: () => probePostgres(input.url, input.timeoutMs),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/probes/postgres.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,SAAS,GAAG,wB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AC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC;KACrD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostHog host normalization and `/decide` reachability probe.
|
|
3
|
+
*
|
|
4
|
+
* Matches setup-monitoring: POST `/decide/?v=3` with the project API key.
|
|
5
|
+
* HTTP 404 (and any non-2xx) is a failure — `/_health` must not be used.
|
|
6
|
+
*/
|
|
7
|
+
import type { ConnectivityProbe, ProbeResult } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes a PostHog host URL (default US cloud).
|
|
10
|
+
*
|
|
11
|
+
* @param host - Optional host override; blank/undefined uses the US cloud default.
|
|
12
|
+
* @returns Absolute host origin without a trailing slash.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolvePosthogHost(host: string | undefined): string;
|
|
15
|
+
/**
|
|
16
|
+
* POSTs to PostHog `/decide/?v=3` to verify the project key and host.
|
|
17
|
+
*
|
|
18
|
+
* @param input - API key, optional host, timeout.
|
|
19
|
+
* @returns Probe result; non-2xx fails (including 404).
|
|
20
|
+
*/
|
|
21
|
+
export declare function probePosthogDecide(input: {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
host?: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}): Promise<ProbeResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Optional PostHog `/decide` reachability probe.
|
|
28
|
+
*
|
|
29
|
+
* @param input - API key, host override, and severity flags.
|
|
30
|
+
* @returns Named `"posthog"` connectivity probe.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createPosthogProbe(input: {
|
|
33
|
+
apiKey: string;
|
|
34
|
+
host?: string;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
}): ConnectivityProbe;
|
|
37
|
+
//# sourceMappingURL=posthog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog.d.ts","sourceRoot":"","sources":["../../src/probes/posthog.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAKjE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMnE;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,WAAW,CAAC,CAgCvB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,iBAAiB,CAUpB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostHog host normalization and `/decide` reachability probe.
|
|
3
|
+
*
|
|
4
|
+
* Matches setup-monitoring: POST `/decide/?v=3` with the project API key.
|
|
5
|
+
* HTTP 404 (and any non-2xx) is a failure — `/_health` must not be used.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_PROBE_TIMEOUT_MS } from "./http.js";
|
|
8
|
+
const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes a PostHog host URL (default US cloud).
|
|
11
|
+
*
|
|
12
|
+
* @param host - Optional host override; blank/undefined uses the US cloud default.
|
|
13
|
+
* @returns Absolute host origin without a trailing slash.
|
|
14
|
+
*/
|
|
15
|
+
export function resolvePosthogHost(host) {
|
|
16
|
+
const raw = (host ?? DEFAULT_POSTHOG_HOST).trim();
|
|
17
|
+
if (!raw) {
|
|
18
|
+
return DEFAULT_POSTHOG_HOST;
|
|
19
|
+
}
|
|
20
|
+
return raw.replace(/\/$/, "");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* POSTs to PostHog `/decide/?v=3` to verify the project key and host.
|
|
24
|
+
*
|
|
25
|
+
* @param input - API key, optional host, timeout.
|
|
26
|
+
* @returns Probe result; non-2xx fails (including 404).
|
|
27
|
+
*/
|
|
28
|
+
export async function probePosthogDecide(input) {
|
|
29
|
+
const started = Date.now();
|
|
30
|
+
const origin = resolvePosthogHost(input.host);
|
|
31
|
+
const timeoutMs = input.timeoutMs ?? DEFAULT_PROBE_TIMEOUT_MS;
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(`${origin}/decide/?v=3`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: { "Content-Type": "application/json" },
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
token: input.apiKey,
|
|
38
|
+
distinct_id: "limetry-preflight",
|
|
39
|
+
}),
|
|
40
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
41
|
+
});
|
|
42
|
+
const elapsed = `${Date.now() - started}ms`;
|
|
43
|
+
if (response.ok) {
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
detail: `PostHog reachable (${elapsed}, HTTP ${response.status}).`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
detail: `PostHog unreachable (${elapsed}): HTTP ${response.status}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const reason = error instanceof Error ? error.message : "request failed";
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
detail: `PostHog unreachable (${Date.now() - started}ms): ${reason}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Optional PostHog `/decide` reachability probe.
|
|
64
|
+
*
|
|
65
|
+
* @param input - API key, host override, and severity flags.
|
|
66
|
+
* @returns Named `"posthog"` connectivity probe.
|
|
67
|
+
*/
|
|
68
|
+
export function createPosthogProbe(input) {
|
|
69
|
+
return {
|
|
70
|
+
name: "posthog",
|
|
71
|
+
required: input.required ?? false,
|
|
72
|
+
critical: false,
|
|
73
|
+
run: () => probePosthogDecide({
|
|
74
|
+
apiKey: input.apiKey,
|
|
75
|
+
host: input.host,
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=posthog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"posthog.js","sourceRoot":"","sources":["../../src/probes/posthog.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEpD,MAAM,oBAAoB,GAAG,0BAA0B,CAAA;AAEvD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IACzD,MAAM,GAAG,GAAG,CAAC,IAAI,IAAI,oBAAoB,CAAC,CAAC,IAAI,EAAE,CAAA;IACjD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,oBAAoB,CAAA;IAC7B,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAIxC;IACC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC1B,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,wBAAwB,CAAA;IAC7D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,cAAc,EAAE;YACpD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;g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|
4
|
+
import type { ConnectivityProbe, ProbeResult } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Connects and `PING`s Redis. Requires optional peer `ioredis`.
|
|
7
|
+
*
|
|
8
|
+
* @param url - Redis connection URL.
|
|
9
|
+
* @param timeoutMs - Connect timeout in milliseconds (default {@link DEFAULT_PROBE_TIMEOUT_MS}).
|
|
10
|
+
* @returns Probe result; fails when `ioredis` is missing or ping errors.
|
|
11
|
+
*/
|
|
12
|
+
export declare function probeRedis(url: string, timeoutMs?: number): Promise<ProbeResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Wraps {@link probeRedis} as a {@link ConnectivityProbe}.
|
|
15
|
+
*
|
|
16
|
+
* @param input - Connection URL and severity flags.
|
|
17
|
+
* @returns Named `"redis"` connectivity probe.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createRedisProbe(input: {
|
|
20
|
+
critical?: boolean;
|
|
21
|
+
required: boolean;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
url: string;
|
|
24
|
+
}): ConnectivityProbe;
|
|
25
|
+
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/probes/redis.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGjE;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,SAAS,SAA2B,GACnC,OAAO,CAAC,WAAW,CAAC,CAmCtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,iBAAiB,CAOpB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis connectivity probe (`PING`) via optional peer dependency `ioredis`.
|
|
3
|
+
*/
|
|
4
|
+
import { DEFAULT_PROBE_TIMEOUT_MS } from "./http.js";
|
|
5
|
+
/**
|
|
6
|
+
* Connects and `PING`s Redis. Requires optional peer `ioredis`.
|
|
7
|
+
*
|
|
8
|
+
* @param url - Redis connection URL.
|
|
9
|
+
* @param timeoutMs - Connect timeout in milliseconds (default {@link DEFAULT_PROBE_TIMEOUT_MS}).
|
|
10
|
+
* @returns Probe result; fails when `ioredis` is missing or ping errors.
|
|
11
|
+
*/
|
|
12
|
+
export async function probeRedis(url, timeoutMs = DEFAULT_PROBE_TIMEOUT_MS) {
|
|
13
|
+
const started = Date.now();
|
|
14
|
+
let RedisCtor;
|
|
15
|
+
try {
|
|
16
|
+
const mod = await import("ioredis");
|
|
17
|
+
RedisCtor = mod.Redis;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
detail: "Redis connection failed: ioredis is not installed in this process.",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const redis = new RedisCtor(url, {
|
|
26
|
+
connectTimeout: timeoutMs,
|
|
27
|
+
maxRetriesPerRequest: 1,
|
|
28
|
+
enableOfflineQueue: false,
|
|
29
|
+
lazyConnect: true,
|
|
30
|
+
});
|
|
31
|
+
redis.on("error", () => undefined);
|
|
32
|
+
try {
|
|
33
|
+
await redis.connect();
|
|
34
|
+
await redis.ping();
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
detail: `Redis connected successfully (${Date.now() - started}ms).`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const reason = error instanceof Error ? error.message : "ping failed";
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
detail: `Redis connection failed (${Date.now() - started}ms): ${reason}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
redis.disconnect();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Wraps {@link probeRedis} as a {@link ConnectivityProbe}.
|
|
53
|
+
*
|
|
54
|
+
* @param input - Connection URL and severity flags.
|
|
55
|
+
* @returns Named `"redis"` connectivity probe.
|
|
56
|
+
*/
|
|
57
|
+
export function createRedisProbe(input) {
|
|
58
|
+
return {
|
|
59
|
+
name: "redis",
|
|
60
|
+
required: input.required,
|
|
61
|
+
critical: input.critical,
|
|
62
|
+
run: () => probeRedis(input.url, input.timeoutMs),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=redis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/probes/redis.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,SAAS,GAAG,wBAAwB;IAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC1B,IAAI,SAAyC,CAAA;IAC7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAA;QACnC,SAAS,GAAG,GAAG,CAAC,KAAK,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,oEAAoE;SAC7E,CAAA;IACH,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE;QAC/B,cAAc,EAAE,SAAS;QACzB,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,KAAK;QACzB,WAAW,EAAE,IAAI;KAClB,CAAC,CAAA;IACF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAClC,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,OAAO,EAAE,CAAA;QACrB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAClB,OAAO;YACL,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,iCAAiC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,MAAM;SACpE,CAAA;IACH,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAA;QACrE,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,4BAA4B,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,QAAQ,MAAM,EAAE;SACzE,CAAA;IACH,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,UAAU,EAAE,CAAA;IACpB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAKhC;IACC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC;KAClD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry DSN parsing and ingest-envelope reachability probe.
|
|
3
|
+
*
|
|
4
|
+
* Probes the project envelope endpoint using only the DSN public key
|
|
5
|
+
* (no org auth token). Matches setup-monitoring / web-disruptdev: POST the
|
|
6
|
+
* envelope URL. A minimal body (`{}\\n`) returns HTTP 200; empty bodies often
|
|
7
|
+
* return 400/401. HTTP 404 is always a failure.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConnectivityProbe, ProbeResult } from "../types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Extracts ingest origin + project id from a Sentry DSN, or `null` if invalid.
|
|
12
|
+
*
|
|
13
|
+
* @param dsn - Sentry DSN URL string.
|
|
14
|
+
* @returns Origin and project id when the DSN has a username and project path segment.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseSentryDsn(dsn: string): {
|
|
17
|
+
origin: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
publicKey: string;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* Builds the Sentry ingest envelope URL for a DSN.
|
|
23
|
+
*
|
|
24
|
+
* @param dsn - Sentry DSN URL string.
|
|
25
|
+
* @returns Envelope URL, or `null` when the DSN is invalid.
|
|
26
|
+
*/
|
|
27
|
+
export declare function sentryEnvelopeUrl(dsn: string): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Returns true when an envelope response proves ingest is reachable.
|
|
30
|
+
*
|
|
31
|
+
* Accepts 2xx–4xx except 404 (wrong project / missing route). Rejects 5xx and
|
|
32
|
+
* network errors. Prefer HTTP 200 via {@link MINIMAL_ENVELOPE_BODY}.
|
|
33
|
+
*
|
|
34
|
+
* @param status - HTTP status from the envelope POST.
|
|
35
|
+
* @returns Whether the status counts as reachable.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isSentryIngestReachableStatus(status: number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* POSTs a minimal envelope to verify ingest is reachable (DSN public key only).
|
|
40
|
+
*
|
|
41
|
+
* @param dsn - Sentry DSN used to derive the envelope URL and auth header.
|
|
42
|
+
* @param timeoutMs - Abort timeout.
|
|
43
|
+
* @returns Probe result; 404 and 5xx fail.
|
|
44
|
+
*/
|
|
45
|
+
export declare function probeSentryIngest(dsn: string, timeoutMs?: number): Promise<ProbeResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Optional Sentry reachability probe from a DSN. Returns `null` when DSN is invalid.
|
|
48
|
+
*
|
|
49
|
+
* @param input - DSN and optional required flag.
|
|
50
|
+
* @returns Named `"sentry"` probe, or `null` when the DSN cannot be parsed.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createSentryProbe(input: {
|
|
53
|
+
dsn: string;
|
|
54
|
+
required?: boolean;
|
|
55
|
+
}): ConnectivityProbe | null;
|
|
56
|
+
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../src/probes/sentry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAWjE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAe3G;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,MAAM,EACX,SAAS,SAA2B,GACnC,OAAO,CAAC,WAAW,CAAC,CAsCtB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,iBAAiB,GAAG,IAAI,CAW3B"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentry DSN parsing and ingest-envelope reachability probe.
|
|
3
|
+
*
|
|
4
|
+
* Probes the project envelope endpoint using only the DSN public key
|
|
5
|
+
* (no org auth token). Matches setup-monitoring / web-disruptdev: POST the
|
|
6
|
+
* envelope URL. A minimal body (`{}\\n`) returns HTTP 200; empty bodies often
|
|
7
|
+
* return 400/401. HTTP 404 is always a failure.
|
|
8
|
+
*/
|
|
9
|
+
import { DEFAULT_PROBE_TIMEOUT_MS } from "./http.js";
|
|
10
|
+
/**
|
|
11
|
+
* Minimal envelope body that Sentry ingest accepts with HTTP 200.
|
|
12
|
+
*
|
|
13
|
+
* Empty bodies return 400/401; this avoids looking like a failed check without
|
|
14
|
+
* requiring an org API token or sending a full event payload.
|
|
15
|
+
*/
|
|
16
|
+
const MINIMAL_ENVELOPE_BODY = "{}\n";
|
|
17
|
+
/**
|
|
18
|
+
* Extracts ingest origin + project id from a Sentry DSN, or `null` if invalid.
|
|
19
|
+
*
|
|
20
|
+
* @param dsn - Sentry DSN URL string.
|
|
21
|
+
* @returns Origin and project id when the DSN has a username and project path segment.
|
|
22
|
+
*/
|
|
23
|
+
export function parseSentryDsn(dsn) {
|
|
24
|
+
try {
|
|
25
|
+
const parsed = new URL(dsn);
|
|
26
|
+
const projectId = parsed.pathname.split("/").filter(Boolean).at(-1);
|
|
27
|
+
if (!parsed.username || !projectId) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
origin: parsed.origin,
|
|
32
|
+
projectId,
|
|
33
|
+
publicKey: parsed.username,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Builds the Sentry ingest envelope URL for a DSN.
|
|
42
|
+
*
|
|
43
|
+
* @param dsn - Sentry DSN URL string.
|
|
44
|
+
* @returns Envelope URL, or `null` when the DSN is invalid.
|
|
45
|
+
*/
|
|
46
|
+
export function sentryEnvelopeUrl(dsn) {
|
|
47
|
+
const parsed = parseSentryDsn(dsn);
|
|
48
|
+
if (!parsed) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return `${parsed.origin}/api/${parsed.projectId}/envelope/`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns true when an envelope response proves ingest is reachable.
|
|
55
|
+
*
|
|
56
|
+
* Accepts 2xx–4xx except 404 (wrong project / missing route). Rejects 5xx and
|
|
57
|
+
* network errors. Prefer HTTP 200 via {@link MINIMAL_ENVELOPE_BODY}.
|
|
58
|
+
*
|
|
59
|
+
* @param status - HTTP status from the envelope POST.
|
|
60
|
+
* @returns Whether the status counts as reachable.
|
|
61
|
+
*/
|
|
62
|
+
export function isSentryIngestReachableStatus(status) {
|
|
63
|
+
return status >= 200 && status < 500 && status !== 404;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* POSTs a minimal envelope to verify ingest is reachable (DSN public key only).
|
|
67
|
+
*
|
|
68
|
+
* @param dsn - Sentry DSN used to derive the envelope URL and auth header.
|
|
69
|
+
* @param timeoutMs - Abort timeout.
|
|
70
|
+
* @returns Probe result; 404 and 5xx fail.
|
|
71
|
+
*/
|
|
72
|
+
export async function probeSentryIngest(dsn, timeoutMs = DEFAULT_PROBE_TIMEOUT_MS) {
|
|
73
|
+
const started = Date.now();
|
|
74
|
+
const parsed = parseSentryDsn(dsn);
|
|
75
|
+
const url = parsed ? `${parsed.origin}/api/${parsed.projectId}/envelope/` : null;
|
|
76
|
+
if (!parsed || !url) {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
detail: "Sentry unreachable: invalid DSN",
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(url, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/x-sentry-envelope",
|
|
87
|
+
"X-Sentry-Auth": `Sentry sentry_version=7,sentry_client=limetry-preflight/1.0,sentry_key=${parsed.publicKey}`,
|
|
88
|
+
},
|
|
89
|
+
body: MINIMAL_ENVELOPE_BODY,
|
|
90
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
91
|
+
});
|
|
92
|
+
const elapsed = `${Date.now() - started}ms`;
|
|
93
|
+
if (isSentryIngestReachableStatus(response.status)) {
|
|
94
|
+
return {
|
|
95
|
+
ok: true,
|
|
96
|
+
detail: `Sentry reachable (${elapsed}, HTTP ${response.status}).`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
detail: `Sentry unreachable (${elapsed}): HTTP ${response.status}`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const reason = error instanceof Error ? error.message : "request failed";
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
detail: `Sentry unreachable (${Date.now() - started}ms): ${reason}`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Optional Sentry reachability probe from a DSN. Returns `null` when DSN is invalid.
|
|
114
|
+
*
|
|
115
|
+
* @param input - DSN and optional required flag.
|
|
116
|
+
* @returns Named `"sentry"` probe, or `null` when the DSN cannot be parsed.
|
|
117
|
+
*/
|
|
118
|
+
export function createSentryProbe(input) {
|
|
119
|
+
const parsed = parseSentryDsn(input.dsn);
|
|
120
|
+
if (!parsed) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
name: "sentry",
|
|
125
|
+
required: input.required ?? false,
|
|
126
|
+
critical: false,
|
|
127
|
+
run: () => probeSentryIngest(input.dsn),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=sentry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/probes/sentry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,MAAM,CAAA;AAEpC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