@jdcpuwiz/zoo-kit 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,230 @@
1
+ export interface paths {
2
+ "/api/v1/notify": {
3
+ parameters: {
4
+ query?: never;
5
+ header?: never;
6
+ path?: never;
7
+ cookie?: never;
8
+ };
9
+ get?: never;
10
+ put?: never;
11
+ /**
12
+ * Queue one push notification.
13
+ * @description Auth: `Authorization: Bearer <source key>` ONLY. Unlike nothing else in
14
+ * the hub, v1 does not read `X-API-Key` or a `?key=` query parameter —
15
+ * a key in a URL leaks into access logs (Bug #177), and two header
16
+ * conventions are two things to keep honouring.
17
+ *
18
+ * Strict: an unknown field, a legacy-only name (`message`, `url`,
19
+ * `link`, `dedupe_key`, `targets`, …) or a wrong type is a 400 naming
20
+ * the field, never silently dropped.
21
+ */
22
+ post: operations["notify"];
23
+ delete?: never;
24
+ options?: never;
25
+ head?: never;
26
+ patch?: never;
27
+ trace?: never;
28
+ };
29
+ "/api/v1/categories": {
30
+ parameters: {
31
+ query?: never;
32
+ header?: never;
33
+ path?: never;
34
+ cookie?: never;
35
+ };
36
+ /**
37
+ * The categories a v1 notify may name.
38
+ * @description Auth: `Authorization: Bearer` with a source key (`zn_…`) OR a paired
39
+ * device key (`znk_…`) — senders validate against it, phone apps render
40
+ * subscription toggles from it.
41
+ */
42
+ get: operations["listCategories"];
43
+ put?: never;
44
+ post?: never;
45
+ delete?: never;
46
+ options?: never;
47
+ head?: never;
48
+ patch?: never;
49
+ trace?: never;
50
+ };
51
+ }
52
+ export type webhooks = Record<string, never>;
53
+ export interface components {
54
+ schemas: {
55
+ Slug: string;
56
+ /**
57
+ * @description Generated from categories.v1.json — the kit's NotifyCategory type. Aliases are accepted on input too.
58
+ * @enum {string}
59
+ */
60
+ CanonicalCategory: "backups" | "bat-signal" | "calendar" | "cameras" | "chores" | "deploys" | "financial" | "general" | "home" | "infra" | "location" | "mail" | "questions" | "security" | "siri" | "summons" | "test" | "todos" | "zoo-news";
61
+ NotifyInput: {
62
+ /** @description Trimmed; blank after trimming is a 400. */
63
+ title: string;
64
+ body?: string;
65
+ /**
66
+ * @description A canonical slug or an alias from categories.v1.json (an alias is
67
+ * stored as sent and reaches devices subscribed to EITHER spelling),
68
+ * or a Category row the hub already holds (created on /categories).
69
+ * Anything else is a 400 — v1 never auto-creates a category from a
70
+ * typo. A Source's categoryOverride still re-stamps the stored
71
+ * category, exactly as on the legacy route (#243).
72
+ */
73
+ category: components["schemas"]["Slug"];
74
+ /**
75
+ * @default active
76
+ * @enum {string}
77
+ */
78
+ priority?: "passive" | "active" | "time-sensitive" | "critical";
79
+ /**
80
+ * Format: uri
81
+ * @description http(s) only (B452). Trimmed.
82
+ */
83
+ deepLink?: string;
84
+ /**
85
+ * Format: uri
86
+ * @description http(s) only; fetched by the hub's image proxy behind IMAGE_PROXY_ALLOWED_HOSTS.
87
+ */
88
+ imageUrl?: string;
89
+ /** @description Same (source, dedupeKey) inside 10 minutes = one notification. */
90
+ dedupeKey?: string;
91
+ /** @description Family member / group slug(s). Absent = routing rules, then category broadcast. */
92
+ target?: string | string[];
93
+ /** @description The iOS action-button set. Required when `actions` is present (not in the study's 3.1 sketch, but the hub ignores actions without it, so v1 carries it rather than silently dropping them). */
94
+ actionCategory?: string;
95
+ actions?: components["schemas"]["NotifyAction"][];
96
+ };
97
+ NotifyAction: {
98
+ id: string;
99
+ callback: {
100
+ /**
101
+ * @default POST
102
+ * @enum {string}
103
+ */
104
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
105
+ url: string;
106
+ headers?: {
107
+ [key: string]: string;
108
+ };
109
+ body?: unknown;
110
+ };
111
+ };
112
+ NotifyAccepted: {
113
+ /** @constant */
114
+ ok: true;
115
+ /** @description true = a NEW notification was stored and fanned out; false = a duplicate, nothing new sent. */
116
+ queued: boolean;
117
+ deduped: boolean;
118
+ id: string;
119
+ };
120
+ Error: {
121
+ /** @constant */
122
+ ok: false;
123
+ error: string;
124
+ };
125
+ Category: {
126
+ slug: components["schemas"]["Slug"];
127
+ name: string;
128
+ aliases: components["schemas"]["Slug"][];
129
+ /** @description true = published in categories.v1.json; false = an ad-hoc Category row (legacy free text or admin-created). */
130
+ canonical: boolean;
131
+ };
132
+ CategoryList: {
133
+ /** @constant */
134
+ version: 1;
135
+ categories: components["schemas"]["Category"][];
136
+ };
137
+ };
138
+ responses: never;
139
+ parameters: never;
140
+ requestBodies: never;
141
+ headers: never;
142
+ pathItems: never;
143
+ }
144
+ export type $defs = Record<string, never>;
145
+ export interface operations {
146
+ notify: {
147
+ parameters: {
148
+ query?: never;
149
+ header?: never;
150
+ path?: never;
151
+ cookie?: never;
152
+ };
153
+ requestBody: {
154
+ content: {
155
+ "application/json": components["schemas"]["NotifyInput"];
156
+ };
157
+ };
158
+ responses: {
159
+ /**
160
+ * @description Duplicate — the same (source, dedupeKey) was accepted inside the
161
+ * last 10 minutes. Nothing new is queued; `id` is the ORIGINAL
162
+ * notification's id. This is the success answer to a retry.
163
+ */
164
+ 200: {
165
+ headers: {
166
+ [name: string]: unknown;
167
+ };
168
+ content: {
169
+ "application/json": components["schemas"]["NotifyAccepted"];
170
+ };
171
+ };
172
+ /** @description Accepted and queued for delivery. */
173
+ 201: {
174
+ headers: {
175
+ [name: string]: unknown;
176
+ };
177
+ content: {
178
+ "application/json": components["schemas"]["NotifyAccepted"];
179
+ };
180
+ };
181
+ /** @description The body is not a valid v1 notify input. */
182
+ 400: {
183
+ headers: {
184
+ [name: string]: unknown;
185
+ };
186
+ content: {
187
+ "application/json": components["schemas"]["Error"];
188
+ };
189
+ };
190
+ /** @description Missing, malformed, unknown or disabled source key. */
191
+ 401: {
192
+ headers: {
193
+ [name: string]: unknown;
194
+ };
195
+ content: {
196
+ "application/json": components["schemas"]["Error"];
197
+ };
198
+ };
199
+ };
200
+ };
201
+ listCategories: {
202
+ parameters: {
203
+ query?: never;
204
+ header?: never;
205
+ path?: never;
206
+ cookie?: never;
207
+ };
208
+ requestBody?: never;
209
+ responses: {
210
+ /** @description Canonical categories (from categories.v1.json) plus any ad-hoc Category rows the hub holds. */
211
+ 200: {
212
+ headers: {
213
+ [name: string]: unknown;
214
+ };
215
+ content: {
216
+ "application/json": components["schemas"]["CategoryList"];
217
+ };
218
+ };
219
+ /** @description Missing or unknown key. */
220
+ 401: {
221
+ headers: {
222
+ [name: string]: unknown;
223
+ };
224
+ content: {
225
+ "application/json": components["schemas"]["Error"];
226
+ };
227
+ };
228
+ };
229
+ };
230
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ // GENERATED by packages/zoo-kit/scripts/generate.mjs from contracts/v1/zoo-notifier.v1.yaml.
4
+ // Do not edit — change the contract and run `npm run gen`.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,261 @@
1
+ export interface paths {
2
+ "/api/v1/people": {
3
+ parameters: {
4
+ query?: never;
5
+ header?: never;
6
+ path?: never;
7
+ cookie?: never;
8
+ };
9
+ /**
10
+ * Every person on the roster, archived ones included (flagged enabled:false).
11
+ * @description Archived people stay in the list: a consumer that silently stopped
12
+ * seeing a row could not tell "archived" from "the sync broke".
13
+ * Order: sortOrder, then name.
14
+ */
15
+ get: operations["listPeople"];
16
+ put?: never;
17
+ post?: never;
18
+ delete?: never;
19
+ options?: never;
20
+ head?: never;
21
+ patch?: never;
22
+ trace?: never;
23
+ };
24
+ "/api/v1/people/{slug}": {
25
+ parameters: {
26
+ query?: never;
27
+ header?: never;
28
+ path?: never;
29
+ cookie?: never;
30
+ };
31
+ get: operations["getPerson"];
32
+ put?: never;
33
+ post?: never;
34
+ delete?: never;
35
+ options?: never;
36
+ head?: never;
37
+ patch?: never;
38
+ trace?: never;
39
+ };
40
+ "/api/v1/whoami-resolve": {
41
+ parameters: {
42
+ query?: never;
43
+ header?: never;
44
+ path?: never;
45
+ cookie?: never;
46
+ };
47
+ /**
48
+ * Map an authentik username to a person.
49
+ * @description GET with a query, not POST with a body, on purpose: it is a pure read,
50
+ * so it is safe to retry against the next base URL, and the kit may
51
+ * cache the answer (<= 15 min, then fail closed) exactly like any other
52
+ * GET. A username is an identifier, not a credential, so it appearing in
53
+ * an access log is acceptable; the person record never does.
54
+ *
55
+ * Matches on the authentik USERNAME (zoo-health's ruling: never email,
56
+ * never display name), compared lowercased — authentik lowercases
57
+ * usernames. A roster row is only matched once its authentik username
58
+ * has been LINKED (the person edit form, or create-on-first-login); an
59
+ * unlinked row is never adopted by slug or name (B519).
60
+ *
61
+ * An archived person is still returned, with enabled:false — whoami in
62
+ * the kit refuses that (fails closed); the directory only reports it.
63
+ */
64
+ get: operations["whoamiResolve"];
65
+ put?: never;
66
+ post?: never;
67
+ delete?: never;
68
+ options?: never;
69
+ head?: never;
70
+ patch?: never;
71
+ trace?: never;
72
+ };
73
+ }
74
+ export type webhooks = Record<string, never>;
75
+ export interface components {
76
+ schemas: {
77
+ Error: {
78
+ error: string;
79
+ denial?: string;
80
+ };
81
+ Person: {
82
+ /** @description Stable forever — the pointer other apps store (zoo-where zooHealthPersonId, home-stack healthId, zoo-meds sourceId). */
83
+ id: string;
84
+ slug: string;
85
+ name: string;
86
+ /** @enum {string} */
87
+ kind: "HUMAN" | "PET";
88
+ /**
89
+ * @description Roster management rights (GUARDIAN = an adult who manages the roster). Not an app's own role — home-stack keeps its own ADULT/KID.
90
+ * @enum {string}
91
+ */
92
+ role: "GUARDIAN" | "MEMBER";
93
+ /** @description false = archived. The legacy /api/internal/roster calls this `active`. */
94
+ enabled: boolean;
95
+ sortOrder: number;
96
+ headingColor: string;
97
+ /** @description A calendar DATE (YYYY-MM-DD), never an instant — a birthday has no time zone. */
98
+ dob: string | null;
99
+ /** @description A pointer (external URL), never bytes. */
100
+ photoUrl: string | null;
101
+ /** @description The linked authentik username, lowercased. null = never linked (pets, people who never sign in). */
102
+ authentikUsername: string | null;
103
+ /** @description Home Assistant device_tracker entity id (zoo-where's HA adapter). */
104
+ haEntityId: string | null;
105
+ /** @description The Traccar Client uniqueId (zoo-where's Traccar adapter), never Traccar's numeric id. */
106
+ traccarDeviceId: string | null;
107
+ };
108
+ PersonEnvelope: {
109
+ /** @constant */
110
+ version: 1;
111
+ person: components["schemas"]["Person"];
112
+ };
113
+ PeopleList: {
114
+ /** @constant */
115
+ version: 1;
116
+ /** Format: date-time */
117
+ generatedAt: string;
118
+ people: components["schemas"]["Person"][];
119
+ };
120
+ };
121
+ responses: {
122
+ /** @description No consumer header, or a missing/wrong token. */
123
+ Unauthorized: {
124
+ headers: {
125
+ [name: string]: unknown;
126
+ };
127
+ content: {
128
+ "application/json": components["schemas"]["Error"];
129
+ };
130
+ };
131
+ /** @description The consumer is not declared in DISPENSER_CONSUMERS. */
132
+ Forbidden: {
133
+ headers: {
134
+ [name: string]: unknown;
135
+ };
136
+ content: {
137
+ "application/json": components["schemas"]["Error"];
138
+ };
139
+ };
140
+ /** @description PEOPLE_API is off or undeclared, or the consumer's token is not configured (a broken install). Never a silent empty list. */
141
+ Unavailable: {
142
+ headers: {
143
+ [name: string]: unknown;
144
+ };
145
+ content: {
146
+ "application/json": components["schemas"]["Error"];
147
+ };
148
+ };
149
+ /** @description No such person (or no person linked to that username). */
150
+ NotFound: {
151
+ headers: {
152
+ [name: string]: unknown;
153
+ };
154
+ content: {
155
+ "application/json": {
156
+ /** @constant */
157
+ error: "not-found";
158
+ };
159
+ };
160
+ };
161
+ };
162
+ parameters: {
163
+ Consumer: string;
164
+ };
165
+ requestBodies: never;
166
+ headers: never;
167
+ pathItems: never;
168
+ }
169
+ export type $defs = Record<string, never>;
170
+ export interface operations {
171
+ listPeople: {
172
+ parameters: {
173
+ query?: never;
174
+ header: {
175
+ "X-Dispenser-Consumer": components["parameters"]["Consumer"];
176
+ };
177
+ path?: never;
178
+ cookie?: never;
179
+ };
180
+ requestBody?: never;
181
+ responses: {
182
+ /** @description The roster. */
183
+ 200: {
184
+ headers: {
185
+ [name: string]: unknown;
186
+ };
187
+ content: {
188
+ "application/json": components["schemas"]["PeopleList"];
189
+ };
190
+ };
191
+ 401: components["responses"]["Unauthorized"];
192
+ 403: components["responses"]["Forbidden"];
193
+ 503: components["responses"]["Unavailable"];
194
+ };
195
+ };
196
+ getPerson: {
197
+ parameters: {
198
+ query?: never;
199
+ header: {
200
+ "X-Dispenser-Consumer": components["parameters"]["Consumer"];
201
+ };
202
+ path: {
203
+ slug: string;
204
+ };
205
+ cookie?: never;
206
+ };
207
+ requestBody?: never;
208
+ responses: {
209
+ /** @description One person (archived ones too). */
210
+ 200: {
211
+ headers: {
212
+ [name: string]: unknown;
213
+ };
214
+ content: {
215
+ "application/json": components["schemas"]["PersonEnvelope"];
216
+ };
217
+ };
218
+ 401: components["responses"]["Unauthorized"];
219
+ 403: components["responses"]["Forbidden"];
220
+ 404: components["responses"]["NotFound"];
221
+ 503: components["responses"]["Unavailable"];
222
+ };
223
+ };
224
+ whoamiResolve: {
225
+ parameters: {
226
+ query: {
227
+ username: string;
228
+ };
229
+ header: {
230
+ "X-Dispenser-Consumer": components["parameters"]["Consumer"];
231
+ };
232
+ path?: never;
233
+ cookie?: never;
234
+ };
235
+ requestBody?: never;
236
+ responses: {
237
+ /** @description The linked person. */
238
+ 200: {
239
+ headers: {
240
+ [name: string]: unknown;
241
+ };
242
+ content: {
243
+ "application/json": components["schemas"]["PersonEnvelope"];
244
+ };
245
+ };
246
+ /** @description username missing or blank. */
247
+ 400: {
248
+ headers: {
249
+ [name: string]: unknown;
250
+ };
251
+ content: {
252
+ "application/json": components["schemas"]["Error"];
253
+ };
254
+ };
255
+ 401: components["responses"]["Unauthorized"];
256
+ 403: components["responses"]["Forbidden"];
257
+ 404: components["responses"]["NotFound"];
258
+ 503: components["responses"]["Unavailable"];
259
+ };
260
+ };
261
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ // GENERATED by packages/zoo-kit/scripts/generate.mjs from contracts/v1/zoo-health.v1.yaml.
4
+ // Do not edit — change the contract and run `npm run gen`.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,46 @@
1
+ export type CheckFn = () => unknown | Promise<unknown>;
2
+ export interface CheckResult {
3
+ ok: boolean;
4
+ ms: number;
5
+ detail?: string;
6
+ error?: string;
7
+ }
8
+ export interface HealthBody {
9
+ ok: boolean;
10
+ app: string;
11
+ version: string | null;
12
+ sha: string | null;
13
+ kit: string;
14
+ uptimeS: number;
15
+ checks: Record<string, CheckResult | {
16
+ ok: boolean;
17
+ missing: string[];
18
+ }>;
19
+ }
20
+ export interface HealthOptions {
21
+ app: string;
22
+ version?: string | null;
23
+ sha?: string | null;
24
+ /**
25
+ * Named checks. A check passes when it resolves to anything other than
26
+ * `false` / `{ ok: false }`; `{ ok, detail }` is reported as is.
27
+ */
28
+ checks?: Record<string, CheckFn>;
29
+ /** Env var NAMES the app needs; reported as `checks.config.missing`. */
30
+ requiredEnv?: string[];
31
+ /** Per-check timeout. Default 3 s. */
32
+ checkTimeoutMs?: number;
33
+ /** HTTP status when ok is false. Default 200 — zoo-vet reads `ok` from the body. */
34
+ failStatus?: number;
35
+ }
36
+ /** Compute the body without a Response — for frameworks that want plain JSON. */
37
+ export declare function healthBody(opts: HealthOptions): Promise<HealthBody>;
38
+ /**
39
+ * A fetch-style handler: `(req?) => Promise<Response>`.
40
+ *
41
+ * Next: export const GET = healthHandler({ app: "zoo-where" }); // in BOTH route files
42
+ * Hono: const h = healthHandler({ app: "x" }); app.get("/api/health", (c) => h(c.req.raw));
43
+ */
44
+ export declare function healthHandler(opts: HealthOptions): (req?: unknown) => Promise<Response>;
45
+ /** Test hook. */
46
+ export declare function _resetHealthCache(): void;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.healthBody = healthBody;
4
+ exports.healthHandler = healthHandler;
5
+ exports._resetHealthCache = _resetHealthCache;
6
+ /**
7
+ * The health/version route (plan §3.4) — one shape for zoo-vet to probe:
8
+ *
9
+ * { ok, app, version, sha, kit, uptimeS, checks }
10
+ *
11
+ * Mount the SAME handler on /api/health AND /api/healthz. It ALWAYS answers:
12
+ * a check that throws, returns false or outlives its timeout marks itself and
13
+ * `ok` false; it never makes the route throw or hang.
14
+ *
15
+ * ERROR TEXT IS GENERIC, ALWAYS. This route is open on the LAN and a raw error
16
+ * (a Prisma one names the database host and port) must not be readable there.
17
+ * A thrown check reports "check failed" and its real message goes to the app's
18
+ * log, one console.warn per failure. A timeout keeps "timed out after N ms",
19
+ * which the kit wrote itself. `detail` is the app's own text and stays as is.
20
+ *
21
+ * version: opts.version, else APP_VERSION, else the `version` in the package.json
22
+ * in the working directory, else null.
23
+ * sha: opts.sha, else GIT_SHA, else null. "unknown" counts as unknown.
24
+ */
25
+ const node_fs_1 = require("node:fs");
26
+ const node_path_1 = require("node:path");
27
+ const env_js_1 = require("./env.js");
28
+ const contract_js_1 = require("./generated/contract.js");
29
+ const UNKNOWN = new Set(["", "unknown", "dev", "none", "null", "undefined"]);
30
+ const clean = (v) => {
31
+ const s = (v ?? "").trim();
32
+ return UNKNOWN.has(s.toLowerCase()) ? null : s;
33
+ };
34
+ let cwdVersion;
35
+ function packageVersion() {
36
+ if (cwdVersion !== undefined)
37
+ return cwdVersion;
38
+ try {
39
+ const pkg = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(process.cwd(), "package.json"), "utf8"));
40
+ cwdVersion = typeof pkg.version === "string" ? clean(pkg.version) : null;
41
+ }
42
+ catch {
43
+ cwdVersion = null;
44
+ }
45
+ return cwdVersion;
46
+ }
47
+ const messageOf = (err) => (err instanceof Error ? err.message : String(err));
48
+ async function runCheck(name, fn, timeoutMs) {
49
+ const started = Date.now();
50
+ let timer;
51
+ // Compared by identity: a check that throws its own "timed out…" text is
52
+ // still app text and may name a host.
53
+ const timedOut = new Error(`timed out after ${timeoutMs} ms`);
54
+ try {
55
+ const value = await Promise.race([
56
+ Promise.resolve().then(fn),
57
+ new Promise((_, reject) => {
58
+ timer = setTimeout(() => reject(timedOut), timeoutMs);
59
+ }),
60
+ ]);
61
+ const ms = Date.now() - started;
62
+ if (value === false)
63
+ return { ok: false, ms };
64
+ if (value && typeof value === "object" && "ok" in value) {
65
+ const v = value;
66
+ return { ok: v.ok !== false, ms, ...(typeof v.detail === "string" ? { detail: v.detail.slice(0, 300) } : {}) };
67
+ }
68
+ return { ok: true, ms };
69
+ }
70
+ catch (err) {
71
+ const ms = Date.now() - started;
72
+ if (err === timedOut)
73
+ return { ok: false, ms, error: timedOut.message };
74
+ console.warn(`[zoo-kit] health check "${name}" failed: ${messageOf(err)}`);
75
+ return { ok: false, ms, error: "check failed" };
76
+ }
77
+ finally {
78
+ clearTimeout(timer);
79
+ }
80
+ }
81
+ /** Compute the body without a Response — for frameworks that want plain JSON. */
82
+ async function healthBody(opts) {
83
+ const timeout = opts.checkTimeoutMs ?? 3_000;
84
+ const names = Object.keys(opts.checks ?? {});
85
+ const results = await Promise.all(names.map((n) => runCheck(n, opts.checks[n], timeout)));
86
+ const checks = Object.fromEntries(names.map((n, i) => [n, results[i]]));
87
+ if (opts.requiredEnv?.length)
88
+ checks.config = (0, env_js_1.checkConfig)(opts.requiredEnv);
89
+ return {
90
+ ok: Object.values(checks).every((c) => c.ok),
91
+ app: opts.app,
92
+ version: clean(opts.version ?? null) ?? clean((0, env_js_1.str)(env_js_1.ENV.APP_VERSION)) ?? packageVersion(),
93
+ sha: clean(opts.sha ?? null) ?? clean((0, env_js_1.str)(env_js_1.ENV.GIT_SHA)),
94
+ kit: contract_js_1.KIT_VERSION,
95
+ uptimeS: Math.floor(process.uptime()),
96
+ checks,
97
+ };
98
+ }
99
+ /**
100
+ * A fetch-style handler: `(req?) => Promise<Response>`.
101
+ *
102
+ * Next: export const GET = healthHandler({ app: "zoo-where" }); // in BOTH route files
103
+ * Hono: const h = healthHandler({ app: "x" }); app.get("/api/health", (c) => h(c.req.raw));
104
+ */
105
+ function healthHandler(opts) {
106
+ return async () => {
107
+ let body;
108
+ try {
109
+ body = await healthBody(opts);
110
+ }
111
+ catch (err) {
112
+ console.warn(`[zoo-kit] health failed: ${messageOf(err)}`);
113
+ body = {
114
+ ok: false,
115
+ app: opts.app,
116
+ version: null,
117
+ sha: null,
118
+ kit: contract_js_1.KIT_VERSION,
119
+ uptimeS: Math.floor(process.uptime()),
120
+ checks: { kit: { ok: false, ms: 0, error: "health failed" } },
121
+ };
122
+ }
123
+ return new Response(JSON.stringify(body), {
124
+ status: body.ok ? 200 : (opts.failStatus ?? 200),
125
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-store" },
126
+ });
127
+ };
128
+ }
129
+ /** Test hook. */
130
+ function _resetHealthCache() {
131
+ cwdVersion = undefined;
132
+ }