@molecule/api-resource-status-page 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +115 -0
  2. package/dist/authorizers/index.d.ts +79 -0
  3. package/dist/authorizers/index.d.ts.map +1 -0
  4. package/dist/authorizers/index.js +158 -0
  5. package/dist/authorizers/index.js.map +1 -0
  6. package/dist/browser-guard.d.ts +2 -0
  7. package/dist/browser-guard.d.ts.map +1 -0
  8. package/dist/browser-guard.js +19 -0
  9. package/dist/browser-guard.js.map +1 -0
  10. package/dist/handlers/createIncident.d.ts +44 -0
  11. package/dist/handlers/createIncident.d.ts.map +1 -0
  12. package/dist/handlers/createIncident.js +73 -0
  13. package/dist/handlers/createIncident.js.map +1 -0
  14. package/dist/handlers/createService.d.ts +44 -0
  15. package/dist/handlers/createService.d.ts.map +1 -0
  16. package/dist/handlers/createService.js +70 -0
  17. package/dist/handlers/createService.js.map +1 -0
  18. package/dist/handlers/deleteService.d.ts +34 -0
  19. package/dist/handlers/deleteService.d.ts.map +1 -0
  20. package/dist/handlers/deleteService.js +64 -0
  21. package/dist/handlers/deleteService.js.map +1 -0
  22. package/dist/handlers/getService.d.ts +52 -0
  23. package/dist/handlers/getService.d.ts.map +1 -0
  24. package/dist/handlers/getService.js +58 -0
  25. package/dist/handlers/getService.js.map +1 -0
  26. package/dist/handlers/getStatus.d.ts +48 -0
  27. package/dist/handlers/getStatus.d.ts.map +1 -0
  28. package/dist/handlers/getStatus.js +76 -0
  29. package/dist/handlers/getStatus.js.map +1 -0
  30. package/dist/handlers/getUptime.d.ts +35 -0
  31. package/dist/handlers/getUptime.d.ts.map +1 -0
  32. package/dist/handlers/getUptime.js +47 -0
  33. package/dist/handlers/getUptime.js.map +1 -0
  34. package/dist/handlers/index.d.ts +11 -0
  35. package/dist/handlers/index.d.ts.map +1 -0
  36. package/dist/handlers/index.js +11 -0
  37. package/dist/handlers/index.js.map +1 -0
  38. package/dist/handlers/listIncidents.d.ts +39 -0
  39. package/dist/handlers/listIncidents.d.ts.map +1 -0
  40. package/dist/handlers/listIncidents.js +51 -0
  41. package/dist/handlers/listIncidents.js.map +1 -0
  42. package/dist/handlers/listServices.d.ts +47 -0
  43. package/dist/handlers/listServices.d.ts.map +1 -0
  44. package/dist/handlers/listServices.js +51 -0
  45. package/dist/handlers/listServices.js.map +1 -0
  46. package/dist/handlers/updateIncident.d.ts +44 -0
  47. package/dist/handlers/updateIncident.d.ts.map +1 -0
  48. package/dist/handlers/updateIncident.js +87 -0
  49. package/dist/handlers/updateIncident.js.map +1 -0
  50. package/dist/handlers/updateService.d.ts +44 -0
  51. package/dist/handlers/updateService.d.ts.map +1 -0
  52. package/dist/handlers/updateService.js +82 -0
  53. package/dist/handlers/updateService.js.map +1 -0
  54. package/dist/i18n.d.ts +14 -0
  55. package/dist/i18n.d.ts.map +1 -0
  56. package/dist/i18n.js +22 -0
  57. package/dist/i18n.js.map +1 -0
  58. package/dist/index.d.ts +95 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +95 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/requestHandlerMap.d.ts +25 -0
  63. package/dist/requestHandlerMap.d.ts.map +1 -0
  64. package/dist/requestHandlerMap.js +37 -0
  65. package/dist/requestHandlerMap.js.map +1 -0
  66. package/dist/resource.d.ts +17 -0
  67. package/dist/resource.d.ts.map +1 -0
  68. package/dist/resource.js +21 -0
  69. package/dist/resource.js.map +1 -0
  70. package/dist/routes.d.ts +39 -0
  71. package/dist/routes.d.ts.map +1 -0
  72. package/dist/routes.js +67 -0
  73. package/dist/routes.js.map +1 -0
  74. package/dist/schema.d.ts +199 -0
  75. package/dist/schema.d.ts.map +1 -0
  76. package/dist/schema.js +140 -0
  77. package/dist/schema.js.map +1 -0
  78. package/dist/types.d.ts +14 -0
  79. package/dist/types.d.ts.map +1 -0
  80. package/dist/types.js +9 -0
  81. package/dist/types.js.map +1 -0
  82. package/package.json +76 -0
  83. package/setup/checks.sql +12 -0
  84. package/setup/incidents.sql +16 -0
  85. package/setup/services.sql +15 -0
  86. package/setup/uptimeWindows.sql +11 -0
@@ -0,0 +1,51 @@
1
+ /**
2
+ * List all monitored services with their latest check status.
3
+ *
4
+ * @module
5
+ */
6
+ import { getLogger } from '@molecule/api-bond';
7
+ import { findMany } from '@molecule/api-database';
8
+ import { t } from '@molecule/api-i18n';
9
+ const logger = getLogger();
10
+ /**
11
+ * Lists all services along with each service's latest check result.
12
+ *
13
+ * @param resource - The service resource configuration.
14
+ * @param resource.tableName - The database table name for services.
15
+ * @returns A request handler that responds with an array of services and their latest check.
16
+ */
17
+ export const listServices = ({ tableName }) => {
18
+ return async (_req) => {
19
+ try {
20
+ const services = await findMany(tableName, {
21
+ orderBy: [{ field: 'name', direction: 'asc' }],
22
+ });
23
+ const serviceList = Array.isArray(services) ? services : [];
24
+ const results = [];
25
+ for (const service of serviceList) {
26
+ const checks = await findMany('checks', {
27
+ where: [{ field: 'serviceId', operator: '=', value: service.id }],
28
+ orderBy: [{ field: 'checkedAt', direction: 'desc' }],
29
+ limit: 1,
30
+ });
31
+ const latestCheck = checks[0] ?? null;
32
+ results.push({
33
+ ...service,
34
+ latestCheck,
35
+ });
36
+ }
37
+ return { statusCode: 200, body: results };
38
+ }
39
+ catch (error) {
40
+ logger.error(error);
41
+ return {
42
+ statusCode: 500,
43
+ body: {
44
+ error: t('status.error.listServicesFailed'),
45
+ errorKey: 'status.error.listServicesFailed',
46
+ },
47
+ };
48
+ }
49
+ };
50
+ };
51
+ //# sourceMappingURL=listServices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listServices.js","sourceRoot":"","sources":["../../src/handlers/listServices.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAE,CAAC,EAAE,MAA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,EAAE,GAAG;gBACf,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,CAAC,iCAAiC,CAAC;oBAC3C,QAAQ,EAAE,iCAAiC;iBAC5C;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Update an existing incident (admin).
3
+ *
4
+ * @module
5
+ */
6
+ import type { MoleculeRequest, MoleculeResponse } from '@molecule/api-resource';
7
+ /**
8
+ * Updates an existing incident by ID. Validates the request body against
9
+ * the update incident schema (all fields optional) before patching.
10
+ *
11
+ * @param _resource - The service resource configuration (unused).
12
+ * @param _resource.tableName - The database table name for services.
13
+ * @returns A request handler that updates an incident and responds with the updated record.
14
+ */
15
+ export declare const updateIncident: ({ tableName: _tableName }: {
16
+ tableName: string;
17
+ }) => (req: MoleculeRequest, res: MoleculeResponse) => Promise<{
18
+ statusCode: number;
19
+ body: {
20
+ error: string;
21
+ errorKey: string;
22
+ props?: undefined;
23
+ };
24
+ } | {
25
+ statusCode: number;
26
+ body: {
27
+ props: {
28
+ id: string;
29
+ createdAt: string;
30
+ updatedAt: string;
31
+ serviceId: string;
32
+ title: string;
33
+ severity: "minor" | "major" | "critical";
34
+ status: "investigating" | "identified" | "monitoring" | "resolved";
35
+ autoDetected: boolean;
36
+ startedAt: string;
37
+ description?: string | undefined;
38
+ resolvedAt?: string | undefined;
39
+ } | null;
40
+ error?: undefined;
41
+ errorKey?: undefined;
42
+ };
43
+ }>;
44
+ //# sourceMappingURL=updateIncident.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateIncident.d.ts","sourceRoot":"","sources":["../../src/handlers/updateIncident.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAS/E;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,2BAA2B;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,MAC/D,KAAK,eAAe,EAAE,KAAK,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;EAqE1D,CAAA"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Update an existing incident (admin).
3
+ *
4
+ * @module
5
+ */
6
+ import { getAnalytics, getLogger } from '@molecule/api-bond';
7
+ import { findById, updateById } from '@molecule/api-database';
8
+ import { t } from '@molecule/api-i18n';
9
+ import { isStatusAdmin } from '../authorizers/index.js';
10
+ import { updateIncidentPropsSchema } from '../schema.js';
11
+ const logger = getLogger();
12
+ const analytics = getAnalytics();
13
+ /**
14
+ * Updates an existing incident by ID. Validates the request body against
15
+ * the update incident schema (all fields optional) before patching.
16
+ *
17
+ * @param _resource - The service resource configuration (unused).
18
+ * @param _resource.tableName - The database table name for services.
19
+ * @returns A request handler that updates an incident and responds with the updated record.
20
+ */
21
+ export const updateIncident = ({ tableName: _tableName }) => {
22
+ return async (req, res) => {
23
+ // Defense-in-depth: deny anyone who isn't a status page admin, even if the
24
+ // `requireAdmin` route middleware was stripped/omitted by the injector.
25
+ if (!(await isStatusAdmin(res))) {
26
+ return {
27
+ statusCode: 403,
28
+ body: {
29
+ error: t('status.error.forbidden', undefined, {
30
+ defaultValue: 'Permission required to manage the status page',
31
+ }),
32
+ errorKey: 'status.error.forbidden',
33
+ },
34
+ };
35
+ }
36
+ const id = String(req.params.id);
37
+ try {
38
+ const existing = await findById('incidents', id);
39
+ if (!existing) {
40
+ return {
41
+ statusCode: 404,
42
+ body: {
43
+ error: t('status.error.incidentNotFound'),
44
+ errorKey: 'status.error.incidentNotFound',
45
+ },
46
+ };
47
+ }
48
+ const parsed = updateIncidentPropsSchema.safeParse(req.body);
49
+ if (!parsed.success) {
50
+ const errors = parsed.error.issues
51
+ .map((e) => `${e.path.join('.')}: ${e.message}`)
52
+ .join(', ');
53
+ return {
54
+ statusCode: 400,
55
+ body: {
56
+ error: t('status.error.validationFailed', { errors }),
57
+ errorKey: 'status.error.validationFailed',
58
+ },
59
+ };
60
+ }
61
+ const data = {
62
+ ...parsed.data,
63
+ updatedAt: new Date().toISOString(),
64
+ };
65
+ const result = await updateById('incidents', id, data);
66
+ logger.debug('Incident updated', { id });
67
+ analytics
68
+ .track({
69
+ name: 'incident.updated',
70
+ properties: { incidentId: id, status: parsed.data.status },
71
+ })
72
+ .catch(() => { });
73
+ return { statusCode: 200, body: { props: result.data } };
74
+ }
75
+ catch (error) {
76
+ logger.error(error);
77
+ return {
78
+ statusCode: 500,
79
+ body: {
80
+ error: t('status.error.updateIncidentFailed'),
81
+ errorKey: 'status.error.updateIncidentFailed',
82
+ },
83
+ };
84
+ }
85
+ };
86
+ };
87
+ //# sourceMappingURL=updateIncident.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateIncident.js","sourceRoot":"","sources":["../../src/handlers/updateIncident.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAGxD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAC1B,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;AAEhC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAE,SAAS,EAAE,UAAU,EAAyB,EAAE,EAAE;IACjF,OAAO,KAAK,EAAE,GAAoB,EAAE,GAAqB,EAAE,EAAE;QAC3D,2EAA2E;QAC3E,wEAAwE;QACxE,IAAI,CAAC,CAAC,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,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AU,CAAsB,WAAW,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;YAE3E,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;YACxC,SAAS;iBACN,KAAK,CAAC;gBACL,IAAI,EAAE,kBAAkB;gBACxB,UAAU,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE;aAC3D,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YAClB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAA;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,CAAC,mCAAmC,CAAC;oBAC7C,QAAQ,EAAE,mCAAmC;iBAC9C;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Update a monitored service (admin).
3
+ *
4
+ * @module
5
+ */
6
+ import type { MoleculeRequest, MoleculeResponse } from '@molecule/api-resource';
7
+ /**
8
+ * Updates an existing monitored service by ID. Validates the request body
9
+ * against the update service schema (all fields optional) before patching.
10
+ *
11
+ * @param resource - The service resource configuration.
12
+ * @param resource.tableName - The database table name for services.
13
+ * @returns A request handler that updates a service and responds with the updated record.
14
+ */
15
+ export declare const updateService: ({ tableName }: {
16
+ tableName: string;
17
+ }) => (req: MoleculeRequest, res: MoleculeResponse) => Promise<{
18
+ statusCode: number;
19
+ body: {
20
+ error: string;
21
+ errorKey: string;
22
+ props?: undefined;
23
+ };
24
+ } | {
25
+ statusCode: number;
26
+ body: {
27
+ props: {
28
+ id: string;
29
+ createdAt: string;
30
+ updatedAt: string;
31
+ name: string;
32
+ url: string;
33
+ method: "GET" | "HEAD" | "POST";
34
+ expectedStatus: number;
35
+ timeoutMs: number;
36
+ intervalMs: number;
37
+ enabled: boolean;
38
+ groupName?: string | undefined;
39
+ } | null;
40
+ error?: undefined;
41
+ errorKey?: undefined;
42
+ };
43
+ }>;
44
+ //# sourceMappingURL=updateService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateService.d.ts","sourceRoot":"","sources":["../../src/handlers/updateService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAS/E;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,eAAe;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,MAClD,KAAK,eAAe,EAAE,KAAK,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;EAgE1D,CAAA"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Update a monitored service (admin).
3
+ *
4
+ * @module
5
+ */
6
+ import { getAnalytics, getLogger } from '@molecule/api-bond';
7
+ import { findById, updateById } from '@molecule/api-database';
8
+ import { t } from '@molecule/api-i18n';
9
+ import { isStatusAdmin } from '../authorizers/index.js';
10
+ import { updateServicePropsSchema } from '../schema.js';
11
+ const logger = getLogger();
12
+ const analytics = getAnalytics();
13
+ /**
14
+ * Updates an existing monitored service by ID. Validates the request body
15
+ * against the update service schema (all fields optional) before patching.
16
+ *
17
+ * @param resource - The service resource configuration.
18
+ * @param resource.tableName - The database table name for services.
19
+ * @returns A request handler that updates a service and responds with the updated record.
20
+ */
21
+ export const updateService = ({ tableName }) => {
22
+ return async (req, res) => {
23
+ // Defense-in-depth: deny anyone who isn't a status page admin, even if the
24
+ // `requireAdmin` route middleware was stripped/omitted by the injector.
25
+ if (!(await isStatusAdmin(res))) {
26
+ return {
27
+ statusCode: 403,
28
+ body: {
29
+ error: t('status.error.forbidden', undefined, {
30
+ defaultValue: 'Permission required to manage the status page',
31
+ }),
32
+ errorKey: 'status.error.forbidden',
33
+ },
34
+ };
35
+ }
36
+ const id = String(req.params.id);
37
+ try {
38
+ const existing = await findById(tableName, id);
39
+ if (!existing) {
40
+ return {
41
+ statusCode: 404,
42
+ body: {
43
+ error: t('status.error.serviceNotFound'),
44
+ errorKey: 'status.error.serviceNotFound',
45
+ },
46
+ };
47
+ }
48
+ const parsed = updateServicePropsSchema.safeParse(req.body);
49
+ if (!parsed.success) {
50
+ const errors = parsed.error.issues
51
+ .map((e) => `${e.path.join('.')}: ${e.message}`)
52
+ .join(', ');
53
+ return {
54
+ statusCode: 400,
55
+ body: {
56
+ error: t('status.error.validationFailed', { errors }),
57
+ errorKey: 'status.error.validationFailed',
58
+ },
59
+ };
60
+ }
61
+ const data = {
62
+ ...parsed.data,
63
+ updatedAt: new Date().toISOString(),
64
+ };
65
+ const result = await updateById(tableName, id, data);
66
+ logger.debug('Service updated', { id });
67
+ analytics.track({ name: 'service.updated', properties: { serviceId: id } }).catch(() => { });
68
+ return { statusCode: 200, body: { props: result.data } };
69
+ }
70
+ catch (error) {
71
+ logger.error(error);
72
+ return {
73
+ statusCode: 500,
74
+ body: {
75
+ error: t('status.error.updateServiceFailed'),
76
+ errorKey: 'status.error.updateServiceFailed',
77
+ },
78
+ };
79
+ }
80
+ };
81
+ };
82
+ //# sourceMappingURL=updateService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateService.js","sourceRoot":"","sources":["../../src/handlers/updateService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAGtC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;A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7
+ * The i18n namespace for the status resource.
8
+ */
9
+ export declare const i18nNamespace = "status";
10
+ /**
11
+ * The i18n registered.
12
+ */
13
+ export declare const i18nRegistered = true;
14
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;GAEG;AACH,eAAO,MAAM,aAAa,WAAW,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,cAAc,OAAO,CAAA"}
package/dist/i18n.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Locale registration for the status resource.
3
+ *
4
+ * @module
5
+ */
6
+ import { registerLocaleModule } from '@molecule/api-i18n';
7
+ try {
8
+ const locales = await import('@molecule/api-locales-status-page');
9
+ registerLocaleModule(locales);
10
+ }
11
+ catch (_error) {
12
+ // Locale package not available (not built or not installed).
13
+ }
14
+ /**
15
+ * The i18n namespace for the status resource.
16
+ */
17
+ export const i18nNamespace = 'status';
18
+ /**
19
+ * The i18n registered.
20
+ */
21
+ export const i18nRegistered = true;
22
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEzD,IAAI,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,mCAAmC,CAAC,CAAA;IACjE,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAAC,OAAO,MAAM,EAAE,CAAC;IAChB,6DAA6D;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAA;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Status page resource for molecule.dev.
3
+ *
4
+ * Public status-page backend: monitored services, incidents with lifecycle
5
+ * updates, health-check history, and uptime windows. The read endpoints power
6
+ * a public status page; the mutation endpoints are for operators.
7
+ *
8
+ * @e2e
9
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
10
+ * each item to this app's actual status-page screens/flows, and check every
11
+ * box off one by one. A box you can't check is an integration bug to fix — not
12
+ * a skip. Verify BEHAVIOR and the public/admin split, not just that CRUD
13
+ * compiles:
14
+ * - [ ] The PUBLIC status page renders every monitored service (component)
15
+ * with its current status and an OVERALL banner that is DERIVED, never
16
+ * hardcoded: GET /status returns `operational` when no enabled service's
17
+ * latest `check` is `down` or `degraded` ("All systems operational"), `down`
18
+ * if ANY latest check is `down`, else `degraded` if any is `degraded` — the
19
+ * banner reflects the WORST service, and a service with no check reads
20
+ * `unknown` (which never turns the banner red). GET /status/services lists
21
+ * each service with its latest check.
22
+ * - [ ] An admin creating an INCIDENT (POST /status/incidents with serviceId,
23
+ * title, severity minor|major|critical, status `investigating`, startedAt)
24
+ * persists it and it shows on the public GET /status/incidents. The affected
25
+ * service reads down/degraded on the page because its latest `check` says so
26
+ * (checks are monitor-written, never typed in), so the overall banner goes
27
+ * non-green while the incident is open.
28
+ * - [ ] Updating the incident (PATCH /status/incidents/:id) advances its
29
+ * timeline through the real lifecycle investigating -> identified ->
30
+ * monitoring -> resolved (bumping updatedAt), and each stage shows on the
31
+ * public page. Marking it `resolved` (with resolvedAt) moves it to history —
32
+ * the public list filtered `?status=resolved` includes it while the active
33
+ * incidents drop it — and once the affected service's latest check returns
34
+ * to `up`, GET /status recovers to "All systems operational" (the banner
35
+ * tracks live check state, so a still-down check keeps it red).
36
+ * - [ ] AUTHORIZATION — reads are PUBLIC: with NO session, every GET (/status,
37
+ * /status/services, /status/services/:id, /status/incidents, /status/uptime)
38
+ * returns 200 — the status page is meant to be seen without signing in.
39
+ * - [ ] AUTHORIZATION — writes are ADMIN-ONLY, deny by default: every mutation
40
+ * (POST/PATCH/DELETE /status/services(/:id), POST/PATCH
41
+ * /status/incidents(/:id)) is refused for an anonymous caller (401) and for
42
+ * a normal signed-in user with no admin claim / `manage status` grant (403),
43
+ * and nothing changes — enforced twice (the `requireAdmin` route middleware
44
+ * AND the in-handler `isStatusAdmin` re-check). A non-admin has NO path to
45
+ * fabricate an outage, delete a service, or post a fake incident, and no
46
+ * endpoint sets a service up/down at all (that is monitor-written).
47
+ *
48
+ * @module
49
+ * @example
50
+ * ```typescript
51
+ * import { createRequestHandler } from '@molecule/api-resource'
52
+ * import { createRequestHandlerMap, routes } from '@molecule/api-resource-status-page'
53
+ *
54
+ * // The handler map is a FACTORY (like api-resource-device) — build it with
55
+ * // the createRequestHandler from @molecule/api-resource (mlcl inject does this):
56
+ * const requestHandlerMap = createRequestHandlerMap(createRequestHandler)
57
+ *
58
+ * // Public reads: GET /status, GET /status/services, GET /status/services/:id,
59
+ * // GET /status/incidents, GET /status/uptime
60
+ * // Admin-only: POST/PATCH/DELETE /status/services(/:id),
61
+ * // POST/PATCH /status/incidents(/:id)
62
+ * ```
63
+ *
64
+ * @remarks
65
+ * The GET routes are PUBLIC by design — a status page is a public surface; do
66
+ * not put them behind auth. The mutating routes are ADMIN-ONLY and DENY by
67
+ * default: they are gated by the `requireAdmin` middleware AND re-checked
68
+ * inside every mutation handler via `isStatusAdmin` — fail-closed
69
+ * defense-in-depth that holds even if a route scanner drops the middleware.
70
+ * "Admin" resolves as: an admin session claim (`isAdmin: true`,
71
+ * `role: 'admin'`, `roles` containing `'admin'`, or a `'status:manage'` /
72
+ * `'admin'` entry in `session.permissions`) OR a bonded
73
+ * `@molecule/api-permissions` grant of `manage` on `status`. Until the app
74
+ * grants one of those, every mutation is denied — grant the claim/permission
75
+ * at startup, do NOT strip the gate: an open mutation surface lets any caller
76
+ * deface the public status page (fabricate outages, delete services).
77
+ *
78
+ * Handler text flows through `t()` with English defaults; the companion
79
+ * locale bond `@molecule/api-locales-status-page` provides translations.
80
+ *
81
+ * Tables: `setup/*.sql` creates `services`, `incidents`, `checks`, and
82
+ * `uptimeWindows`. An mlcl-scaffolded API replays these setup files
83
+ * automatically on migrate; anywhere else run them once — nothing at runtime
84
+ * creates them.
85
+ */
86
+ export * from './authorizers/index.js';
87
+ export * from './browser-guard.js';
88
+ export * as handlers from './handlers/index.js';
89
+ export * from './i18n.js';
90
+ export * from './requestHandlerMap.js';
91
+ export * from './resource.js';
92
+ export * from './routes.js';
93
+ export * from './schema.js';
94
+ export * as types from './types.js';
95
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Status page resource for molecule.dev.
3
+ *
4
+ * Public status-page backend: monitored services, incidents with lifecycle
5
+ * updates, health-check history, and uptime windows. The read endpoints power
6
+ * a public status page; the mutation endpoints are for operators.
7
+ *
8
+ * @e2e
9
+ * Integration checklist — drive the real UI (live preview, no mocks), adapt
10
+ * each item to this app's actual status-page screens/flows, and check every
11
+ * box off one by one. A box you can't check is an integration bug to fix — not
12
+ * a skip. Verify BEHAVIOR and the public/admin split, not just that CRUD
13
+ * compiles:
14
+ * - [ ] The PUBLIC status page renders every monitored service (component)
15
+ * with its current status and an OVERALL banner that is DERIVED, never
16
+ * hardcoded: GET /status returns `operational` when no enabled service's
17
+ * latest `check` is `down` or `degraded` ("All systems operational"), `down`
18
+ * if ANY latest check is `down`, else `degraded` if any is `degraded` — the
19
+ * banner reflects the WORST service, and a service with no check reads
20
+ * `unknown` (which never turns the banner red). GET /status/services lists
21
+ * each service with its latest check.
22
+ * - [ ] An admin creating an INCIDENT (POST /status/incidents with serviceId,
23
+ * title, severity minor|major|critical, status `investigating`, startedAt)
24
+ * persists it and it shows on the public GET /status/incidents. The affected
25
+ * service reads down/degraded on the page because its latest `check` says so
26
+ * (checks are monitor-written, never typed in), so the overall banner goes
27
+ * non-green while the incident is open.
28
+ * - [ ] Updating the incident (PATCH /status/incidents/:id) advances its
29
+ * timeline through the real lifecycle investigating -> identified ->
30
+ * monitoring -> resolved (bumping updatedAt), and each stage shows on the
31
+ * public page. Marking it `resolved` (with resolvedAt) moves it to history —
32
+ * the public list filtered `?status=resolved` includes it while the active
33
+ * incidents drop it — and once the affected service's latest check returns
34
+ * to `up`, GET /status recovers to "All systems operational" (the banner
35
+ * tracks live check state, so a still-down check keeps it red).
36
+ * - [ ] AUTHORIZATION — reads are PUBLIC: with NO session, every GET (/status,
37
+ * /status/services, /status/services/:id, /status/incidents, /status/uptime)
38
+ * returns 200 — the status page is meant to be seen without signing in.
39
+ * - [ ] AUTHORIZATION — writes are ADMIN-ONLY, deny by default: every mutation
40
+ * (POST/PATCH/DELETE /status/services(/:id), POST/PATCH
41
+ * /status/incidents(/:id)) is refused for an anonymous caller (401) and for
42
+ * a normal signed-in user with no admin claim / `manage status` grant (403),
43
+ * and nothing changes — enforced twice (the `requireAdmin` route middleware
44
+ * AND the in-handler `isStatusAdmin` re-check). A non-admin has NO path to
45
+ * fabricate an outage, delete a service, or post a fake incident, and no
46
+ * endpoint sets a service up/down at all (that is monitor-written).
47
+ *
48
+ * @module
49
+ * @example
50
+ * ```typescript
51
+ * import { createRequestHandler } from '@molecule/api-resource'
52
+ * import { createRequestHandlerMap, routes } from '@molecule/api-resource-status-page'
53
+ *
54
+ * // The handler map is a FACTORY (like api-resource-device) — build it with
55
+ * // the createRequestHandler from @molecule/api-resource (mlcl inject does this):
56
+ * const requestHandlerMap = createRequestHandlerMap(createRequestHandler)
57
+ *
58
+ * // Public reads: GET /status, GET /status/services, GET /status/services/:id,
59
+ * // GET /status/incidents, GET /status/uptime
60
+ * // Admin-only: POST/PATCH/DELETE /status/services(/:id),
61
+ * // POST/PATCH /status/incidents(/:id)
62
+ * ```
63
+ *
64
+ * @remarks
65
+ * The GET routes are PUBLIC by design — a status page is a public surface; do
66
+ * not put them behind auth. The mutating routes are ADMIN-ONLY and DENY by
67
+ * default: they are gated by the `requireAdmin` middleware AND re-checked
68
+ * inside every mutation handler via `isStatusAdmin` — fail-closed
69
+ * defense-in-depth that holds even if a route scanner drops the middleware.
70
+ * "Admin" resolves as: an admin session claim (`isAdmin: true`,
71
+ * `role: 'admin'`, `roles` containing `'admin'`, or a `'status:manage'` /
72
+ * `'admin'` entry in `session.permissions`) OR a bonded
73
+ * `@molecule/api-permissions` grant of `manage` on `status`. Until the app
74
+ * grants one of those, every mutation is denied — grant the claim/permission
75
+ * at startup, do NOT strip the gate: an open mutation surface lets any caller
76
+ * deface the public status page (fabricate outages, delete services).
77
+ *
78
+ * Handler text flows through `t()` with English defaults; the companion
79
+ * locale bond `@molecule/api-locales-status-page` provides translations.
80
+ *
81
+ * Tables: `setup/*.sql` creates `services`, `incidents`, `checks`, and
82
+ * `uptimeWindows`. An mlcl-scaffolded API replays these setup files
83
+ * automatically on migrate; anywhere else run them once — nothing at runtime
84
+ * creates them.
85
+ */
86
+ export * from './authorizers/index.js';
87
+ export * from './browser-guard.js';
88
+ export * as handlers from './handlers/index.js';
89
+ export * from './i18n.js';
90
+ export * from './requestHandlerMap.js';
91
+ export * from './resource.js';
92
+ export * from './routes.js';
93
+ export * from './schema.js';
94
+ export * as types from './types.js';
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoFG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Maps route handler names to their implementations.
3
+ *
4
+ * @module
5
+ */
6
+ import type { createRequestHandler as CreateRequestHandler, MoleculeRequestHandler } from '@molecule/api-resource';
7
+ type RequestHandlerCreator = typeof CreateRequestHandler;
8
+ /**
9
+ * Creates the full request handler map for the Status resource. Maps handler names
10
+ * (matching route definitions) to Express middleware via `createRequestHandler`.
11
+ *
12
+ * `requireAdmin` is the status-management authorizer middleware referenced by the
13
+ * mutating routes (`createService`/`updateService`/`deleteService`/`createIncident`/
14
+ * `updateIncident`). It must live here as a real handler-map key so the mlcl
15
+ * injector's route scanner preserves it — a bare middleware string that isn't a
16
+ * handler-map key is silently dropped (which is why the previous `'auth'` gate was
17
+ * inert and the mutating routes shipped public). It is already an Express
18
+ * middleware, so it is NOT wrapped in `createRequestHandler`.
19
+ *
20
+ * @param createRequestHandler - Factory from `@molecule/api-resource` that wraps handler configs into Express middleware.
21
+ * @returns A record mapping handler names to Express middleware functions.
22
+ */
23
+ export declare const createRequestHandlerMap: (createRequestHandler: RequestHandlerCreator) => Record<string, MoleculeRequestHandler>;
24
+ export {};
25
+ //# sourceMappingURL=requestHandlerMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestHandlerMap.d.ts","sourceRoot":"","sources":["../src/requestHandlerMap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,IAAI,oBAAoB,EAC5C,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAM/B,KAAK,qBAAqB,GAAG,OAAO,oBAAoB,CAAA;AAExD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,GAClC,sBAAsB,qBAAqB,KAC1C,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAYtC,CAAA"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Maps route handler names to their implementations.
3
+ *
4
+ * @module
5
+ */
6
+ import { requireAdmin } from './authorizers/index.js';
7
+ import * as handlers from './handlers/index.js';
8
+ import { resource } from './resource.js';
9
+ /**
10
+ * Creates the full request handler map for the Status resource. Maps handler names
11
+ * (matching route definitions) to Express middleware via `createRequestHandler`.
12
+ *
13
+ * `requireAdmin` is the status-management authorizer middleware referenced by the
14
+ * mutating routes (`createService`/`updateService`/`deleteService`/`createIncident`/
15
+ * `updateIncident`). It must live here as a real handler-map key so the mlcl
16
+ * injector's route scanner preserves it — a bare middleware string that isn't a
17
+ * handler-map key is silently dropped (which is why the previous `'auth'` gate was
18
+ * inert and the mutating routes shipped public). It is already an Express
19
+ * middleware, so it is NOT wrapped in `createRequestHandler`.
20
+ *
21
+ * @param createRequestHandler - Factory from `@molecule/api-resource` that wraps handler configs into Express middleware.
22
+ * @returns A record mapping handler names to Express middleware functions.
23
+ */
24
+ export const createRequestHandlerMap = (createRequestHandler) => ({
25
+ requireAdmin: requireAdmin(),
26
+ getStatus: createRequestHandler(handlers.getStatus(resource)),
27
+ listServices: createRequestHandler(handlers.listServices(resource)),
28
+ getService: createRequestHandler(handlers.getService(resource)),
29
+ createService: createRequestHandler(handlers.createService(resource)),
30
+ updateService: createRequestHandler(handlers.updateService(resource)),
31
+ deleteService: createRequestHandler(handlers.deleteService(resource)),
32
+ listIncidents: createRequestHandler(handlers.listIncidents(resource)),
33
+ createIncident: createRequestHandler(handlers.createIncident(resource)),
34
+ updateIncident: createRequestHandler(handlers.updateIncident(resource)),
35
+ getUptime: createRequestHandler(handlers.getUptime(resource)),
36
+ });
37
+ //# sourceMappingURL=requestHandlerMap.js.map