@molecule/api-resource-status-page 1.0.1 → 1.0.3

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 CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-08-04T01:49:21.194Z
6
+ Generated: 2026-10-16T15:23:41.923Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-status-page
@@ -18,6 +18,10 @@ Public status-page backend: monitored services, incidents with lifecycle
18
18
  updates, health-check history, and uptime windows. The read endpoints power
19
19
  a public status page; the mutation endpoints are for operators.
20
20
 
21
+ **Tables this package owns: four.** `services` is the parent; `checks`, `incidents` and
22
+ `uptimeWindows` each join to it on their own `serviceId` = `services.id` (a declared FK,
23
+ `ON DELETE CASCADE`) — that `serviceId` is the column every per-service query filters on.
24
+
21
25
  ## Quick Start
22
26
 
23
27
  ```typescript
@@ -48,28 +52,36 @@ npm install @molecule/api-resource-status-page @molecule/api-bond @molecule/api-
48
52
 
49
53
  ### Types
50
54
 
51
- #### `CheckProps`
55
+ #### `ServiceProps`
52
56
 
53
- Health check result properties.
57
+ Full service record properties.
54
58
 
55
59
  ```typescript
56
- type CheckProps = z.infer<typeof checkPropsSchema>
60
+ type ServiceProps = z.infer<typeof servicePropsSchema>
57
61
  ```
58
62
 
59
- #### `CreateIncidentProps`
63
+ #### `CreateServiceProps`
60
64
 
61
- Fields accepted when creating a new incident.
65
+ Fields accepted when creating a new service.
62
66
 
63
67
  ```typescript
64
- type CreateIncidentProps = z.infer<typeof createIncidentPropsSchema>
68
+ type CreateServiceProps = z.infer<typeof createServicePropsSchema>
65
69
  ```
66
70
 
67
- #### `CreateServiceProps`
71
+ #### `UpdateServiceProps`
68
72
 
69
- Fields accepted when creating a new service.
73
+ Updatable service fields.
70
74
 
71
75
  ```typescript
72
- type CreateServiceProps = z.infer<typeof createServicePropsSchema>
76
+ type UpdateServiceProps = z.infer<typeof updateServicePropsSchema>
77
+ ```
78
+
79
+ #### `CheckProps`
80
+
81
+ Health check result properties.
82
+
83
+ ```typescript
84
+ type CheckProps = z.infer<typeof checkPropsSchema>
73
85
  ```
74
86
 
75
87
  #### `IncidentProps`
@@ -80,12 +92,12 @@ Full incident record properties.
80
92
  type IncidentProps = z.infer<typeof incidentPropsSchema>
81
93
  ```
82
94
 
83
- #### `ServiceProps`
95
+ #### `CreateIncidentProps`
84
96
 
85
- Full service record properties.
97
+ Fields accepted when creating a new incident.
86
98
 
87
99
  ```typescript
88
- type ServiceProps = z.infer<typeof servicePropsSchema>
100
+ type CreateIncidentProps = z.infer<typeof createIncidentPropsSchema>
89
101
  ```
90
102
 
91
103
  #### `UpdateIncidentProps`
@@ -96,23 +108,51 @@ Updatable incident fields.
96
108
  type UpdateIncidentProps = z.infer<typeof updateIncidentPropsSchema>
97
109
  ```
98
110
 
99
- #### `UpdateServiceProps`
111
+ #### `UptimeWindowProps`
100
112
 
101
- Updatable service fields.
113
+ Uptime window statistics properties.
102
114
 
103
115
  ```typescript
104
- type UpdateServiceProps = z.infer<typeof updateServicePropsSchema>
116
+ type UptimeWindowProps = z.infer<typeof uptimeWindowPropsSchema>
105
117
  ```
106
118
 
107
- #### `UptimeWindowProps`
119
+ ### Functions
108
120
 
109
- Uptime window statistics properties.
121
+ #### `isStatusAdmin(res)`
122
+
123
+ Resolves whether the current request's session belongs to an actor authorized
124
+ to administer the status page (create/update/delete services + incidents).
125
+ Fail-closed: returns `false` when there is no authenticated session, and
126
+ otherwise only `true` when the session carries an admin claim or a bonded
127
+ permissions provider grants the `manage status` permission.
128
+
129
+ Use this for in-handler defense-in-depth (it does not depend on the route
130
+ middleware being preserved by the injector).
110
131
 
111
132
  ```typescript
112
- type UptimeWindowProps = z.infer<typeof uptimeWindowPropsSchema>
133
+ function isStatusAdmin(res: MoleculeResponse): Promise<boolean>
113
134
  ```
114
135
 
115
- ### Functions
136
+ - `res` — The response whose `locals.session` is inspected.
137
+
138
+ **Returns:** `true` when the session is an authorized status page admin.
139
+
140
+ #### `requireAdmin()`
141
+
142
+ Route middleware that gates the admin-only status page mutation routes. Calls
143
+ `next()` only for an authenticated status page admin; otherwise forwards an
144
+ error to the framework error handler — `Unauthorized` when no session is
145
+ present, `Forbidden` when the session is authenticated but not authorized to
146
+ manage the status page.
147
+
148
+ Exposed as a request-handler-map key so the injector's route scanner keeps it
149
+ (unlike the inert global `'auth'` string, which is dropped).
150
+
151
+ ```typescript
152
+ function requireAdmin(): MoleculeRequestHandler
153
+ ```
154
+
155
+ **Returns:** An Express-compatible middleware function.
116
156
 
117
157
  #### `createRequestHandlerMap(createRequestHandler)`
118
158
 
@@ -149,82 +189,91 @@ function createResource(): types.Resource<unknown>
149
189
 
150
190
  **Returns:** The status resource descriptor with name, tableName, and schema.
151
191
 
152
- #### `isStatusAdmin(res)`
192
+ ### Constants
153
193
 
154
- Resolves whether the current request's session belongs to an actor authorized
155
- to administer the status page (create/update/delete services + incidents).
156
- Fail-closed: returns `false` when there is no authenticated session, and
157
- otherwise only `true` when the session carries an admin claim or a bonded
158
- permissions provider grants the `manage status` permission.
194
+ #### `STATUS_PERMISSION_ACTION`
159
195
 
160
- Use this for in-handler defense-in-depth (it does not depend on the route
161
- middleware being preserved by the injector).
196
+ Permission action checked against `@molecule/api-permissions` for status page
197
+ administration.
162
198
 
163
199
  ```typescript
164
- function isStatusAdmin(res: MoleculeResponse): Promise<boolean>
200
+ const STATUS_PERMISSION_ACTION: 'manage'
165
201
  ```
166
202
 
167
- - `res` — The response whose `locals.session` is inspected.
203
+ #### `STATUS_PERMISSION_RESOURCE`
168
204
 
169
- **Returns:** `true` when the session is an authorized status page admin.
205
+ Permission resource checked against `@molecule/api-permissions` for status page
206
+ administration.
170
207
 
171
- #### `requireAdmin()`
208
+ ```typescript
209
+ const STATUS_PERMISSION_RESOURCE: 'status'
210
+ ```
172
211
 
173
- Route middleware that gates the admin-only status page mutation routes. Calls
174
- `next()` only for an authenticated status page admin; otherwise forwards an
175
- error to the framework error handler — `Unauthorized` when no session is
176
- present, `Forbidden` when the session is authenticated but not authorized to
177
- manage the status page.
212
+ #### `STATUS_ADMIN_PERMISSION`
178
213
 
179
- Exposed as a request-handler-map key so the injector's route scanner keeps it
180
- (unlike the inert global `'auth'` string, which is dropped).
214
+ Session-claim permission string (`'status:manage'`) that, when present in a
215
+ session's `permissions` array, grants status page administration without a
216
+ bonded permissions provider.
181
217
 
182
218
  ```typescript
183
- function requireAdmin(): MoleculeRequestHandler
219
+ const STATUS_ADMIN_PERMISSION: 'status:manage'
184
220
  ```
185
221
 
186
- **Returns:** An Express-compatible middleware function.
222
+ #### `i18nNamespace`
187
223
 
188
- ### Constants
224
+ The i18n namespace for the status resource.
189
225
 
190
- #### `checkPropsSchema`
226
+ ```typescript
227
+ const i18nNamespace: 'status'
228
+ ```
191
229
 
192
- Schema for a single health check result.
230
+ #### `i18nRegistered`
231
+
232
+ The i18n registered.
193
233
 
194
234
  ```typescript
195
- const checkPropsSchema: z.ZodObject<
196
- {
197
- id: z.ZodString
198
- serviceId: z.ZodString
199
- status: z.ZodEnum<{ up: 'up'; down: 'down'; degraded: 'degraded' }>
200
- httpStatus: z.ZodOptional<z.ZodNumber>
201
- latencyMs: z.ZodOptional<z.ZodNumber>
202
- error: z.ZodOptional<z.ZodString>
203
- checkedAt: z.ZodString
204
- },
205
- z.core.$strip
206
- >
235
+ const i18nRegistered: true
207
236
  ```
208
237
 
209
- #### `createIncidentPropsSchema`
238
+ #### `resource`
210
239
 
211
- Schema for creating a new incident.
240
+ The status resource definition.
212
241
 
213
242
  ```typescript
214
- const createIncidentPropsSchema: z.ZodObject<
243
+ const resource: types.Resource<unknown>
244
+ ```
245
+
246
+ #### `routes`
247
+
248
+ Route array for status page endpoints: public read routes and admin-gated mutation routes.
249
+
250
+ ```typescript
251
+ const routes: (
252
+ | { method: 'get'; path: string; middlewares: never[]; handler: string }
253
+ | { method: 'post'; path: string; middlewares: string[]; handler: string }
254
+ | { method: 'patch'; path: string; middlewares: string[]; handler: string }
255
+ | { method: 'delete'; path: string; middlewares: string[]; handler: string }
256
+ )[]
257
+ ```
258
+
259
+ #### `servicePropsSchema`
260
+
261
+ Full schema for a monitored service.
262
+
263
+ ```typescript
264
+ const servicePropsSchema: z.ZodObject<
215
265
  {
216
- status: z.ZodEnum<{
217
- investigating: 'investigating'
218
- identified: 'identified'
219
- monitoring: 'monitoring'
220
- resolved: 'resolved'
221
- }>
222
- serviceId: z.ZodString
223
- title: z.ZodString
224
- description: z.ZodOptional<z.ZodString>
225
- severity: z.ZodEnum<{ minor: 'minor'; major: 'major'; critical: 'critical' }>
226
- autoDetected: z.ZodDefault<z.ZodBoolean>
227
- startedAt: z.ZodString
266
+ id: z.ZodString
267
+ createdAt: z.ZodString
268
+ updatedAt: z.ZodString
269
+ name: z.ZodString
270
+ url: z.ZodString
271
+ method: z.ZodDefault<z.ZodEnum<{ GET: 'GET'; HEAD: 'HEAD'; POST: 'POST' }>>
272
+ expectedStatus: z.ZodDefault<z.ZodNumber>
273
+ timeoutMs: z.ZodDefault<z.ZodNumber>
274
+ intervalMs: z.ZodDefault<z.ZodNumber>
275
+ groupName: z.ZodOptional<z.ZodString>
276
+ enabled: z.ZodDefault<z.ZodBoolean>
228
277
  },
229
278
  z.core.$strip
230
279
  >
@@ -250,20 +299,43 @@ const createServicePropsSchema: z.ZodObject<
250
299
  >
251
300
  ```
252
301
 
253
- #### `i18nNamespace`
302
+ #### `updateServicePropsSchema`
254
303
 
255
- The i18n namespace for the status resource.
304
+ Schema for updating an existing service (all fields optional).
256
305
 
257
306
  ```typescript
258
- const i18nNamespace: 'status'
307
+ const updateServicePropsSchema: z.ZodObject<
308
+ {
309
+ name: z.ZodOptional<z.ZodString>
310
+ url: z.ZodOptional<z.ZodString>
311
+ method: z.ZodOptional<z.ZodDefault<z.ZodEnum<{ GET: 'GET'; HEAD: 'HEAD'; POST: 'POST' }>>>
312
+ expectedStatus: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
313
+ timeoutMs: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
314
+ intervalMs: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
315
+ groupName: z.ZodOptional<z.ZodOptional<z.ZodString>>
316
+ enabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>
317
+ },
318
+ z.core.$strip
319
+ >
259
320
  ```
260
321
 
261
- #### `i18nRegistered`
322
+ #### `checkPropsSchema`
262
323
 
263
- The i18n registered.
324
+ Schema for a single health check result.
264
325
 
265
326
  ```typescript
266
- const i18nRegistered: true
327
+ const checkPropsSchema: z.ZodObject<
328
+ {
329
+ id: z.ZodString
330
+ serviceId: z.ZodString
331
+ status: z.ZodEnum<{ up: 'up'; down: 'down'; degraded: 'degraded' }>
332
+ httpStatus: z.ZodOptional<z.ZodNumber>
333
+ latencyMs: z.ZodOptional<z.ZodNumber>
334
+ error: z.ZodOptional<z.ZodString>
335
+ checkedAt: z.ZodString
336
+ },
337
+ z.core.$strip
338
+ >
267
339
  ```
268
340
 
269
341
  #### `incidentPropsSchema`
@@ -294,457 +366,523 @@ const incidentPropsSchema: z.ZodObject<
294
366
  >
295
367
  ```
296
368
 
297
- #### `resource`
369
+ #### `createIncidentPropsSchema`
298
370
 
299
- The status resource definition.
371
+ Schema for creating a new incident.
300
372
 
301
373
  ```typescript
302
- const resource: types.Resource<unknown>
374
+ const createIncidentPropsSchema: z.ZodObject<
375
+ {
376
+ serviceId: z.ZodString
377
+ title: z.ZodString
378
+ description: z.ZodOptional<z.ZodString>
379
+ severity: z.ZodEnum<{ minor: 'minor'; major: 'major'; critical: 'critical' }>
380
+ status: z.ZodEnum<{
381
+ investigating: 'investigating'
382
+ identified: 'identified'
383
+ monitoring: 'monitoring'
384
+ resolved: 'resolved'
385
+ }>
386
+ autoDetected: z.ZodDefault<z.ZodBoolean>
387
+ startedAt: z.ZodString
388
+ },
389
+ z.core.$strip
390
+ >
303
391
  ```
304
392
 
305
- #### `routes`
393
+ #### `updateIncidentPropsSchema`
306
394
 
307
- Route array for status page endpoints: public read routes and admin-gated mutation routes.
395
+ Schema for updating an existing incident (all fields optional).
308
396
 
309
397
  ```typescript
310
- const routes: (
311
- | { method: 'get'; path: string; middlewares: never[]; handler: string }
312
- | { method: 'post'; path: string; middlewares: string[]; handler: string }
313
- | { method: 'patch'; path: string; middlewares: string[]; handler: string }
314
- | { method: 'delete'; path: string; middlewares: string[]; handler: string }
315
- )[]
398
+ const updateIncidentPropsSchema: z.ZodObject<
399
+ {
400
+ title: z.ZodOptional<z.ZodString>
401
+ description: z.ZodOptional<z.ZodOptional<z.ZodString>>
402
+ severity: z.ZodOptional<z.ZodEnum<{ minor: 'minor'; major: 'major'; critical: 'critical' }>>
403
+ status: z.ZodOptional<
404
+ z.ZodEnum<{
405
+ investigating: 'investigating'
406
+ identified: 'identified'
407
+ monitoring: 'monitoring'
408
+ resolved: 'resolved'
409
+ }>
410
+ >
411
+ resolvedAt: z.ZodOptional<z.ZodOptional<z.ZodString>>
412
+ },
413
+ z.core.$strip
414
+ >
316
415
  ```
317
416
 
318
- #### `servicePropsSchema`
417
+ #### `uptimeWindowPropsSchema`
319
418
 
320
- Full schema for a monitored service.
419
+ Schema for a pre-computed uptime statistics window.
321
420
 
322
421
  ```typescript
323
- const servicePropsSchema: z.ZodObject<
422
+ const uptimeWindowPropsSchema: z.ZodObject<
324
423
  {
325
424
  id: z.ZodString
326
- createdAt: z.ZodString
327
- updatedAt: z.ZodString
328
- name: z.ZodString
329
- url: z.ZodString
330
- method: z.ZodDefault<z.ZodEnum<{ GET: 'GET'; HEAD: 'HEAD'; POST: 'POST' }>>
331
- expectedStatus: z.ZodDefault<z.ZodNumber>
332
- timeoutMs: z.ZodDefault<z.ZodNumber>
333
- intervalMs: z.ZodDefault<z.ZodNumber>
334
- groupName: z.ZodOptional<z.ZodString>
335
- enabled: z.ZodDefault<z.ZodBoolean>
425
+ serviceId: z.ZodString
426
+ window: z.ZodEnum<{ '1h': '1h'; '24h': '24h'; '7d': '7d'; '30d': '30d'; '90d': '90d' }>
427
+ uptimePct: z.ZodNumber
428
+ totalChecks: z.ZodNumber
429
+ upChecks: z.ZodNumber
430
+ avgLatencyMs: z.ZodNumber
336
431
  },
337
432
  z.core.$strip
338
433
  >
339
434
  ```
340
435
 
341
- #### `STATUS_ADMIN_PERMISSION`
436
+ ### Namespaces
342
437
 
343
- Session-claim permission string (`'status:manage'`) that, when present in a
344
- session's `permissions` array, grants status page administration without a
345
- bonded permissions provider.
438
+ #### `z`
439
+
440
+ Re-exports the `zod` module — `z.<name>` is exactly `zod.<name>`, documented by that package (installed at `node_modules/zod`).
441
+
442
+ #### `handlers`
443
+
444
+ Re-exported as a namespace — reach every member below through it (e.g. `handlers.<name>`).
445
+
446
+ ##### `handlers.createIncident(_resource)`
447
+
448
+ Creates a new incident record. Validates the request body against
449
+ the create incident schema before inserting.
346
450
 
347
451
  ```typescript
348
- const STATUS_ADMIN_PERMISSION: 'status:manage'
452
+ function createIncident({ tableName: _tableName }: { tableName: string }): (
453
+ req: MoleculeRequest,
454
+ res: MoleculeResponse,
455
+ ) => Promise<
456
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
457
+ | {
458
+ statusCode: number
459
+ body: {
460
+ props: {
461
+ id: string
462
+ createdAt: string
463
+ updatedAt: string
464
+ serviceId: string
465
+ title: string
466
+ severity: 'minor' | 'major' | 'critical'
467
+ status: 'investigating' | 'identified' | 'monitoring' | 'resolved'
468
+ autoDetected: boolean
469
+ startedAt: string
470
+ description?: string | undefined
471
+ resolvedAt?: string | undefined
472
+ } | null
473
+ error?: undefined
474
+ errorKey?: undefined
475
+ }
476
+ }
477
+ >
349
478
  ```
350
479
 
351
- #### `STATUS_PERMISSION_ACTION`
480
+ - `_resource` — The service resource configuration (unused).
481
+ - `_resource.tableName` — The database table name for services.
352
482
 
353
- Permission action checked against `@molecule/api-permissions` for status page
354
- administration.
483
+ **Returns:** A request handler that creates an incident and responds with the created record.
484
+
485
+ ##### `handlers.createService(resource)`
486
+
487
+ Creates a new monitored service. Validates the request body against
488
+ the create service schema before inserting into the database.
355
489
 
356
490
  ```typescript
357
- const STATUS_PERMISSION_ACTION: 'manage'
491
+ function createService({ tableName }: { tableName: string }): (
492
+ req: MoleculeRequest,
493
+ res: MoleculeResponse,
494
+ ) => Promise<
495
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
496
+ | {
497
+ statusCode: number
498
+ body: {
499
+ props: {
500
+ id: string
501
+ createdAt: string
502
+ updatedAt: string
503
+ name: string
504
+ url: string
505
+ method: 'GET' | 'HEAD' | 'POST'
506
+ expectedStatus: number
507
+ timeoutMs: number
508
+ intervalMs: number
509
+ enabled: boolean
510
+ groupName?: string | undefined
511
+ } | null
512
+ error?: undefined
513
+ errorKey?: undefined
514
+ }
515
+ }
516
+ >
358
517
  ```
359
518
 
360
- #### `STATUS_PERMISSION_RESOURCE`
519
+ - `resource` — The service resource configuration.
520
+ - `resource.tableName` — The database table name for services.
361
521
 
362
- Permission resource checked against `@molecule/api-permissions` for status page
363
- administration.
522
+ **Returns:** A request handler that creates a service and responds with the created record.
523
+
524
+ ##### `handlers.deleteService(resource)`
525
+
526
+ Deletes a monitored service by ID. Returns 404 if the service does not exist.
527
+ Associated checks, incidents, and uptime windows are removed via CASCADE.
364
528
 
365
529
  ```typescript
366
- const STATUS_PERMISSION_RESOURCE: 'status'
530
+ function deleteService({
531
+ tableName,
532
+ }: {
533
+ tableName: string
534
+ }): (
535
+ req: MoleculeRequest,
536
+ res: MoleculeResponse,
537
+ ) => Promise<
538
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
539
+ | { statusCode: number; body: { props: { id: string }; error?: undefined; errorKey?: undefined } }
540
+ >
367
541
  ```
368
542
 
369
- #### `updateIncidentPropsSchema`
543
+ - `resource` — The service resource configuration.
544
+ - `resource.tableName` — The database table name for services.
370
545
 
371
- Schema for updating an existing incident (all fields optional).
546
+ **Returns:** A request handler that deletes a service and responds with 204 on success.
547
+
548
+ ##### `handlers.getService(resource)`
549
+
550
+ Returns a single service by ID along with the last 50 check results.
372
551
 
373
552
  ```typescript
374
- const updateIncidentPropsSchema: z.ZodObject<
375
- {
376
- status: z.ZodOptional<
377
- z.ZodEnum<{
378
- investigating: 'investigating'
379
- identified: 'identified'
380
- monitoring: 'monitoring'
381
- resolved: 'resolved'
382
- }>
383
- >
384
- title: z.ZodOptional<z.ZodString>
385
- description: z.ZodOptional<z.ZodOptional<z.ZodString>>
386
- severity: z.ZodOptional<z.ZodEnum<{ minor: 'minor'; major: 'major'; critical: 'critical' }>>
387
- resolvedAt: z.ZodOptional<z.ZodOptional<z.ZodString>>
388
- },
389
- z.core.$strip
553
+ function getService({ tableName }: { tableName: string }): (req: MoleculeRequest) => Promise<
554
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
555
+ | {
556
+ statusCode: number
557
+ body: {
558
+ props: {
559
+ recentChecks: {
560
+ id: string
561
+ serviceId: string
562
+ status: 'up' | 'down' | 'degraded'
563
+ checkedAt: string
564
+ httpStatus?: number | undefined
565
+ latencyMs?: number | undefined
566
+ error?: string | undefined
567
+ }[]
568
+ id: string
569
+ createdAt: string
570
+ updatedAt: string
571
+ name: string
572
+ url: string
573
+ method: 'GET' | 'HEAD' | 'POST'
574
+ expectedStatus: number
575
+ timeoutMs: number
576
+ intervalMs: number
577
+ enabled: boolean
578
+ groupName?: string | undefined
579
+ }
580
+ error?: undefined
581
+ errorKey?: undefined
582
+ }
583
+ }
390
584
  >
391
585
  ```
392
586
 
393
- #### `updateServicePropsSchema`
587
+ - `resource` — The service resource configuration.
588
+ - `resource.tableName` — The database table name for services.
394
589
 
395
- Schema for updating an existing service (all fields optional).
590
+ **Returns:** A request handler that responds with a service and its recent checks.
591
+
592
+ ##### `handlers.getStatus(resource)`
593
+
594
+ Returns the aggregated system health status.
595
+
596
+ Finds all enabled services, fetches the latest check for each,
597
+ and computes an overall status: `operational`, `degraded`, or `down`.
396
598
 
397
599
  ```typescript
398
- const updateServicePropsSchema: z.ZodObject<
399
- {
400
- name: z.ZodOptional<z.ZodString>
401
- url: z.ZodOptional<z.ZodString>
402
- method: z.ZodOptional<z.ZodDefault<z.ZodEnum<{ GET: 'GET'; HEAD: 'HEAD'; POST: 'POST' }>>>
403
- expectedStatus: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
404
- timeoutMs: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
405
- intervalMs: z.ZodOptional<z.ZodDefault<z.ZodNumber>>
406
- groupName: z.ZodOptional<z.ZodOptional<z.ZodString>>
407
- enabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>
408
- },
409
- z.core.$strip
600
+ function getStatus({ tableName }: { tableName: string }): (_req: MoleculeRequest) => Promise<
601
+ | {
602
+ statusCode: number
603
+ body: {
604
+ status: 'down' | 'degraded' | 'operational'
605
+ services: { id: string; name: string; status: string; latencyMs: number | null }[]
606
+ checkedAt: string
607
+ error?: undefined
608
+ errorKey?: undefined
609
+ }
610
+ }
611
+ | {
612
+ statusCode: number
613
+ body: {
614
+ error: string
615
+ errorKey: string
616
+ status?: undefined
617
+ services?: undefined
618
+ checkedAt?: undefined
619
+ }
620
+ }
410
621
  >
411
622
  ```
412
623
 
413
- #### `uptimeWindowPropsSchema`
624
+ - `resource` — The service resource configuration.
625
+ - `resource.tableName` — The database table name for services.
414
626
 
415
- Schema for a pre-computed uptime statistics window.
627
+ **Returns:** A request handler that responds with overall system status.
628
+
629
+ ##### `handlers.getUptime(_resource)`
630
+
631
+ Returns uptime window statistics for all services, or filtered by
632
+ `?serviceId=` query parameter for a specific service.
416
633
 
417
634
  ```typescript
418
- const uptimeWindowPropsSchema: z.ZodObject<
419
- {
420
- id: z.ZodString
421
- serviceId: z.ZodString
422
- window: z.ZodEnum<{ '1h': '1h'; '24h': '24h'; '7d': '7d'; '30d': '30d'; '90d': '90d' }>
423
- uptimePct: z.ZodNumber
424
- totalChecks: z.ZodNumber
425
- upChecks: z.ZodNumber
426
- avgLatencyMs: z.ZodNumber
427
- },
428
- z.core.$strip
635
+ function getUptime({ tableName: _tableName }: { tableName: string }): (
636
+ req: MoleculeRequest,
637
+ ) => Promise<
638
+ | {
639
+ statusCode: number
640
+ body: {
641
+ id: string
642
+ serviceId: string
643
+ window: '1h' | '24h' | '7d' | '30d' | '90d'
644
+ uptimePct: number
645
+ totalChecks: number
646
+ upChecks: number
647
+ avgLatencyMs: number
648
+ }[]
649
+ }
650
+ | { statusCode: number; body: { error: string; errorKey: string } }
429
651
  >
430
652
  ```
431
653
 
432
- ### Namespaces
654
+ - `_resource` — The service resource configuration (unused).
655
+ - `_resource.tableName` — The database table name for services.
433
656
 
434
- #### `handlers`
657
+ **Returns:** A request handler that responds with uptime window records.
658
+
659
+ ##### `handlers.listIncidents(_resource)`
660
+
661
+ Lists incidents with support for `?status=` filtering and pagination
662
+ via `?limit=` and `?offset=` query parameters.
663
+
664
+ ```typescript
665
+ function listIncidents({ tableName: _tableName }: { tableName: string }): (
666
+ req: MoleculeRequest,
667
+ ) => Promise<
668
+ | {
669
+ statusCode: number
670
+ body: {
671
+ id: string
672
+ createdAt: string
673
+ updatedAt: string
674
+ serviceId: string
675
+ title: string
676
+ severity: 'minor' | 'major' | 'critical'
677
+ status: 'investigating' | 'identified' | 'monitoring' | 'resolved'
678
+ autoDetected: boolean
679
+ startedAt: string
680
+ description?: string | undefined
681
+ resolvedAt?: string | undefined
682
+ }[]
683
+ }
684
+ | { statusCode: number; body: { error: string; errorKey: string } }
685
+ >
686
+ ```
687
+
688
+ - `_resource` — The service resource configuration (unused).
689
+ - `_resource.tableName` — The database table name for services.
435
690
 
436
- Members:
691
+ **Returns:** A request handler that responds with a paginated array of incidents.
437
692
 
438
- - `handlers.createIncident` — function: Creates a new incident record. Validates the request body against
439
- - `handlers.createService` — function: Creates a new monitored service. Validates the request body against
440
- - `handlers.deleteService` — function: Deletes a monitored service by ID. Returns 404 if the service does not exist.
441
- - `handlers.getService` — function: Returns a single service by ID along with the last 50 check results.
442
- - `handlers.getStatus` — function: Returns the aggregated system health status.
443
- - `handlers.getUptime` — function: Returns uptime window statistics for all services, or filtered by
444
- - `handlers.listIncidents` — function: Lists incidents with support for `?status=` filtering and pagination
445
- - `handlers.listServices` — function: Lists all services along with each service's latest check result.
446
- - `handlers.updateIncident` — function: Updates an existing incident by ID. Validates the request body against
447
- - `handlers.updateService` — function: Updates an existing monitored service by ID. Validates the request body
693
+ ##### `handlers.listServices(resource)`
694
+
695
+ Lists all services along with each service's latest check result.
696
+
697
+ ```typescript
698
+ function listServices({ tableName }: { tableName: string }): (_req: MoleculeRequest) => Promise<
699
+ | {
700
+ statusCode: number
701
+ body: {
702
+ latestCheck: {
703
+ id: string
704
+ serviceId: string
705
+ status: 'up' | 'down' | 'degraded'
706
+ checkedAt: string
707
+ httpStatus?: number | undefined
708
+ latencyMs?: number | undefined
709
+ error?: string | undefined
710
+ }
711
+ id: string
712
+ createdAt: string
713
+ updatedAt: string
714
+ name: string
715
+ url: string
716
+ method: 'GET' | 'HEAD' | 'POST'
717
+ expectedStatus: number
718
+ timeoutMs: number
719
+ intervalMs: number
720
+ enabled: boolean
721
+ groupName?: string | undefined
722
+ }[]
723
+ }
724
+ | { statusCode: number; body: { error: string; errorKey: string } }
725
+ >
726
+ ```
727
+
728
+ - `resource` — The service resource configuration.
729
+ - `resource.tableName` — The database table name for services.
730
+
731
+ **Returns:** A request handler that responds with an array of services and their latest check.
732
+
733
+ ##### `handlers.updateIncident(_resource)`
734
+
735
+ Updates an existing incident by ID. Validates the request body against
736
+ the update incident schema (all fields optional) before patching.
737
+
738
+ ```typescript
739
+ function updateIncident({ tableName: _tableName }: { tableName: string }): (
740
+ req: MoleculeRequest,
741
+ res: MoleculeResponse,
742
+ ) => Promise<
743
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
744
+ | {
745
+ statusCode: number
746
+ body: {
747
+ props: {
748
+ id: string
749
+ createdAt: string
750
+ updatedAt: string
751
+ serviceId: string
752
+ title: string
753
+ severity: 'minor' | 'major' | 'critical'
754
+ status: 'investigating' | 'identified' | 'monitoring' | 'resolved'
755
+ autoDetected: boolean
756
+ startedAt: string
757
+ description?: string | undefined
758
+ resolvedAt?: string | undefined
759
+ } | null
760
+ error?: undefined
761
+ errorKey?: undefined
762
+ }
763
+ }
764
+ >
765
+ ```
766
+
767
+ - `_resource` — The service resource configuration (unused).
768
+ - `_resource.tableName` — The database table name for services.
769
+
770
+ **Returns:** A request handler that updates an incident and responds with the updated record.
771
+
772
+ ##### `handlers.updateService(resource)`
773
+
774
+ Updates an existing monitored service by ID. Validates the request body
775
+ against the update service schema (all fields optional) before patching.
776
+
777
+ ```typescript
778
+ function updateService({ tableName }: { tableName: string }): (
779
+ req: MoleculeRequest,
780
+ res: MoleculeResponse,
781
+ ) => Promise<
782
+ | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
783
+ | {
784
+ statusCode: number
785
+ body: {
786
+ props: {
787
+ id: string
788
+ createdAt: string
789
+ updatedAt: string
790
+ name: string
791
+ url: string
792
+ method: 'GET' | 'HEAD' | 'POST'
793
+ expectedStatus: number
794
+ timeoutMs: number
795
+ intervalMs: number
796
+ enabled: boolean
797
+ groupName?: string | undefined
798
+ } | null
799
+ error?: undefined
800
+ errorKey?: undefined
801
+ }
802
+ }
803
+ >
804
+ ```
805
+
806
+ - `resource` — The service resource configuration.
807
+ - `resource.tableName` — The database table name for services.
808
+
809
+ **Returns:** A request handler that updates a service and responds with the updated record.
448
810
 
449
811
  #### `types`
450
812
 
451
- Members:
813
+ Re-exported as a namespace — reach every member below through it (e.g. `types.<name>`).
452
814
 
453
- - `types.CheckProps` — type: Health check result properties.
454
- - `types.CreateIncidentProps` — type: Fields accepted when creating a new incident.
455
- - `types.CreateServiceProps` — type: Fields accepted when creating a new service.
456
- - `types.IncidentProps` — type: Full incident record properties.
457
- - `types.ServiceProps` — type: Full service record properties.
458
- - `types.UpdateIncidentProps` — type: Updatable incident fields.
459
- - `types.UpdateServiceProps` — type: Updatable service fields.
460
- - `types.UptimeWindowProps` — type: Uptime window statistics properties.
461
- - `types.Resource` — type: An object describing the `status` resource.
815
+ ##### `types.ServiceProps`
462
816
 
463
- #### `z`
817
+ Full service record properties.
464
818
 
465
- Members:
466
-
467
- - `z.core` — namespace
468
- - `z.infer` — type
469
- - `z.output` — type
470
- - `z.input` — type
471
- - `z.JSONType` — type
472
- - `z.globalRegistry` — const
473
- - `z.GlobalMeta` — interface
474
- - `z.registry` — function
475
- - `z.config` — function
476
- - `z.$output` — const
477
- - `z.$input` — const
478
- - `z.$brand` — const
479
- - `z.clone` — function
480
- - `z.regexes` — namespace
481
- - `z.treeifyError` — function
482
- - `z.prettifyError` — function
483
- - `z.formatError` — function
484
- - `z.flattenError` — function
485
- - `z.TimePrecision` — const
486
- - `z.util` — namespace
487
- - `z.NEVER` — const: A special constant with type `never`
488
- - `z.toJSONSchema` — function
489
- - `z.fromJSONSchema` — function: Converts a JSON Schema to a Zod schema. This function should be considered semi-experimental. It's behavior is liable to change.
490
- - `z.locales` — namespace
491
- - `z.ZodISODateTime` — interface
492
- - `z.ZodISODate` — interface
493
- - `z.ZodISOTime` — interface
494
- - `z.ZodISODuration` — interface
495
- - `z.iso` — namespace
496
- - `z.ZodCoercedString` — interface
497
- - `z.ZodCoercedNumber` — interface
498
- - `z.ZodCoercedBigInt` — interface
499
- - `z.ZodCoercedBoolean` — interface
500
- - `z.ZodCoercedDate` — interface
501
- - `z.coerce` — namespace
502
- - `z.string` — function
503
- - `z.email` — function
504
- - `z.guid` — function
505
- - `z.uuid` — function
506
- - `z.uuidv4` — function
507
- - `z.uuidv6` — function
508
- - `z.uuidv7` — function
509
- - `z.url` — function
510
- - `z.httpUrl` — function
511
- - `z.emoji` — function
512
- - `z.nanoid` — function
513
- - `z.cuid` — function: Validates a CUID v1 string.
514
- - `z.cuid2` — function
515
- - `z.ulid` — function
516
- - `z.xid` — function
517
- - `z.ksuid` — function
518
- - `z.ipv4` — function
519
- - `z.mac` — function
520
- - `z.ipv6` — function
521
- - `z.cidrv4` — function
522
- - `z.cidrv6` — function
523
- - `z.base64` — function
524
- - `z.base64url` — function
525
- - `z.e164` — function
526
- - `z.jwt` — function
527
- - `z.stringFormat` — function
528
- - `z.hostname` — function
529
- - `z.hex` — function
530
- - `z.hash` — function
531
- - `z.number` — function
532
- - `z.int` — function
533
- - `z.float32` — function
534
- - `z.float64` — function
535
- - `z.int32` — function
536
- - `z.uint32` — function
537
- - `z.boolean` — function
538
- - `z.bigint` — function
539
- - `z.int64` — function
540
- - `z.uint64` — function
541
- - `z.symbol` — function
542
- - `z.any` — function
543
- - `z.unknown` — function
544
- - `z.never` — function
545
- - `z.date` — function
546
- - `z.array` — function
547
- - `z.keyof` — function
548
- - `z.object` — function
549
- - `z.strictObject` — function
550
- - `z.looseObject` — function
551
- - `z.union` — function
552
- - `z.xor` — function: Creates an exclusive union (XOR) where exactly one option must match.
553
- - `z.discriminatedUnion` — function
554
- - `z.intersection` — function
555
- - `z.tuple` — function
556
- - `z.record` — function
557
- - `z.partialRecord` — function
558
- - `z.looseRecord` — function
559
- - `z.map` — function
560
- - `z.set` — function
561
- - `z.nativeEnum` — function
562
- - `z.literal` — function
563
- - `z.file` — function
564
- - `z.transform` — function
565
- - `z.optional` — function
566
- - `z.exactOptional` — function
567
- - `z.nullable` — function
568
- - `z.nullish` — function
569
- - `z._default` — function
570
- - `z.prefault` — function
571
- - `z.nonoptional` — function
572
- - `z.success` — function
573
- - `z.nan` — function
574
- - `z.pipe` — function
575
- - `z.codec` — function
576
- - `z.invertCodec` — function
577
- - `z.readonly` — function
578
- - `z.templateLiteral` — function
579
- - `z.lazy` — function
580
- - `z.promise` — function
581
- - `z._function` — function
582
- - `z.check` — function
583
- - `z.custom` — function
584
- - `z.refine` — function
585
- - `z.superRefine` — function
586
- - `z.json` — function
587
- - `z.preprocess` — function
588
- - `z.ZodStandardSchemaWithJSON` — type
589
- - `z.ZodType` — interface
590
- - `z._ZodType` — interface
591
- - `z._ZodString` — interface
592
- - `z.ZodString` — interface
593
- - `z.ZodStringFormat` — interface
594
- - `z.ZodEmail` — interface
595
- - `z.ZodGUID` — interface
596
- - `z.ZodUUID` — interface
597
- - `z.ZodURL` — interface
598
- - `z.ZodEmoji` — interface
599
- - `z.ZodNanoID` — interface
600
- - `z.ZodCUID` — interface
601
- - `z.ZodCUID2` — interface
602
- - `z.ZodULID` — interface
603
- - `z.ZodXID` — interface
604
- - `z.ZodKSUID` — interface
605
- - `z.ZodIPv4` — interface
606
- - `z.ZodMAC` — interface
607
- - `z.ZodIPv6` — interface
608
- - `z.ZodCIDRv4` — interface
609
- - `z.ZodCIDRv6` — interface
610
- - `z.ZodBase64` — interface
611
- - `z.ZodBase64URL` — interface
612
- - `z.ZodE164` — interface
613
- - `z.ZodJWT` — interface
614
- - `z.ZodCustomStringFormat` — interface
615
- - `z._ZodNumber` — interface
616
- - `z.ZodNumber` — interface
617
- - `z.ZodNumberFormat` — interface
618
- - `z.ZodInt` — interface
619
- - `z.ZodFloat32` — interface
620
- - `z.ZodFloat64` — interface
621
- - `z.ZodInt32` — interface
622
- - `z.ZodUInt32` — interface
623
- - `z._ZodBoolean` — interface
624
- - `z.ZodBoolean` — interface
625
- - `z._ZodBigInt` — interface
626
- - `z.ZodBigInt` — interface
627
- - `z.ZodBigIntFormat` — interface
628
- - `z.ZodSymbol` — interface
629
- - `z.ZodUndefined` — interface
630
- - `z.undefined` — function
631
- - `z.ZodNull` — interface
632
- - `z.null` — function
633
- - `z.ZodAny` — interface
634
- - `z.ZodUnknown` — interface
635
- - `z.ZodNever` — interface
636
- - `z.ZodVoid` — interface
637
- - `z.void` — function
638
- - `z._ZodDate` — interface
639
- - `z.ZodDate` — interface
640
- - `z.ZodArray` — interface
641
- - `z.SafeExtendShape` — type
642
- - `z.ZodObject` — interface
643
- - `z.ZodUnion` — interface
644
- - `z.ZodXor` — interface
645
- - `z.ZodDiscriminatedUnion` — interface
646
- - `z.ZodIntersection` — interface
647
- - `z.ZodTuple` — interface
648
- - `z.ZodRecord` — interface
649
- - `z.ZodMap` — interface
650
- - `z.ZodSet` — interface
651
- - `z.ZodEnum` — interface
652
- - `z.enum` — function
653
- - `z.ZodLiteral` — interface
654
- - `z.ZodFile` — interface
655
- - `z.ZodTransform` — interface
656
- - `z.ZodOptional` — interface
657
- - `z.ZodExactOptional` — interface
658
- - `z.ZodNullable` — interface
659
- - `z.ZodDefault` — interface
660
- - `z.ZodPrefault` — interface
661
- - `z.ZodNonOptional` — interface
662
- - `z.ZodSuccess` — interface
663
- - `z.ZodCatch` — interface
664
- - `z.catch` — function
665
- - `z.ZodNaN` — interface
666
- - `z.ZodPipe` — interface
667
- - `z.ZodCodec` — interface
668
- - `z.ZodPreprocess` — interface
669
- - `z.ZodReadonly` — interface
670
- - `z.ZodTemplateLiteral` — interface
671
- - `z.ZodLazy` — interface
672
- - `z.ZodPromise` — interface
673
- - `z.ZodFunction` — interface
674
- - `z.function` — function
675
- - `z.ZodCustom` — interface
676
- - `z.describe` — const
677
- - `z.meta` — const
678
- - `z.instanceof` — function
679
- - `z.stringbool` — const
680
- - `z.ZodJSONSchemaInternals` — interface
681
- - `z.ZodJSONSchema` — interface
682
- - `z.lt` — function
683
- - `z.lte` — function
684
- - `z.gt` — function
685
- - `z.gte` — function
686
- - `z.positive` — function
687
- - `z.negative` — function
688
- - `z.nonpositive` — function
689
- - `z.nonnegative` — function
690
- - `z.multipleOf` — function
691
- - `z.maxSize` — function
692
- - `z.minSize` — function
693
- - `z.size` — function
694
- - `z.maxLength` — function
695
- - `z.minLength` — function
696
- - `z.length` — function
697
- - `z.regex` — function
698
- - `z.lowercase` — function
699
- - `z.uppercase` — function
700
- - `z.includes` — function
701
- - `z.startsWith` — function
702
- - `z.endsWith` — function
703
- - `z.property` — function
704
- - `z.mime` — function
705
- - `z.overwrite` — function
706
- - `z.normalize` — function
707
- - `z.trim` — function
708
- - `z.toLowerCase` — function
709
- - `z.toUpperCase` — function
710
- - `z.slugify` — function
711
- - `z.RefinementCtx` — interface
712
- - `z.ZodIssue` — type
713
- - `z.ZodError` — interface: An Error-like class used to store Zod validation issues.
714
- - `z.ZodRealError` — const
715
- - `z.ZodFlattenedError` — type
716
- - `z.ZodFormattedError` — type
717
- - `z.ZodErrorMap` — interface
718
- - `z.IssueData` — type
719
- - `z.ZodSafeParseResult` — type
720
- - `z.ZodSafeParseSuccess` — type
721
- - `z.ZodSafeParseError` — type
722
- - `z.parse` — const
723
- - `z.parseAsync` — const
724
- - `z.safeParse` — const
725
- - `z.safeParseAsync` — const
726
- - `z.encode` — const
727
- - `z.decode` — const
728
- - `z.encodeAsync` — const
729
- - `z.decodeAsync` — const
730
- - `z.safeEncode` — const
731
- - `z.safeDecode` — const
732
- - `z.safeEncodeAsync` — const
733
- - `z.safeDecodeAsync` — const
734
- - `z.setErrorMap` — function
735
- - `z.getErrorMap` — function
736
- - `z.TypeOf` — type
737
- - `z.Infer` — type
738
- - `z.ZodFirstPartySchemaTypes` — type
739
- - `z.ZodIssueCode` — const
740
- - `z.inferFlattenedErrors` — type
741
- - `z.inferFormattedError` — type
742
- - `z.BRAND` — type: Use `z.$brand` instead
743
- - `z.ZodTypeAny` — interface
744
- - `z.ZodSchema` — interface
745
- - `z.Schema` — interface
746
- - `z.ZodRawShape` — type: Included for Zod 3 compatibility
747
- - `z.ZodFirstPartyTypeKind` — enum
819
+ ```typescript
820
+ type ServiceProps = z.infer<typeof servicePropsSchema>
821
+ ```
822
+
823
+ ##### `types.CreateServiceProps`
824
+
825
+ Fields accepted when creating a new service.
826
+
827
+ ```typescript
828
+ type CreateServiceProps = z.infer<typeof createServicePropsSchema>
829
+ ```
830
+
831
+ ##### `types.UpdateServiceProps`
832
+
833
+ Updatable service fields.
834
+
835
+ ```typescript
836
+ type UpdateServiceProps = z.infer<typeof updateServicePropsSchema>
837
+ ```
838
+
839
+ ##### `types.CheckProps`
840
+
841
+ Health check result properties.
842
+
843
+ ```typescript
844
+ type CheckProps = z.infer<typeof checkPropsSchema>
845
+ ```
846
+
847
+ ##### `types.IncidentProps`
848
+
849
+ Full incident record properties.
850
+
851
+ ```typescript
852
+ type IncidentProps = z.infer<typeof incidentPropsSchema>
853
+ ```
854
+
855
+ ##### `types.CreateIncidentProps`
856
+
857
+ Fields accepted when creating a new incident.
858
+
859
+ ```typescript
860
+ type CreateIncidentProps = z.infer<typeof createIncidentPropsSchema>
861
+ ```
862
+
863
+ ##### `types.UpdateIncidentProps`
864
+
865
+ Updatable incident fields.
866
+
867
+ ```typescript
868
+ type UpdateIncidentProps = z.infer<typeof updateIncidentPropsSchema>
869
+ ```
870
+
871
+ ##### `types.UptimeWindowProps`
872
+
873
+ Uptime window statistics properties.
874
+
875
+ ```typescript
876
+ type UptimeWindowProps = z.infer<typeof uptimeWindowPropsSchema>
877
+ ```
878
+
879
+ ##### `types.Resource`
880
+
881
+ An object describing the `status` resource.
882
+
883
+ ```typescript
884
+ type Resource<T = unknown> = resourceTypes.Resource<T>
885
+ ```
748
886
 
749
887
  ## Injection Notes
750
888