@dads-framework/audit 0.0.0-stage → 0.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.
Files changed (189) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +198 -2
  3. package/dist/audit.tsbuildinfo +1 -0
  4. package/dist/index.d.ts +26 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +25 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/actor/compose-subject-to-audit-actor.d.ts +32 -0
  9. package/dist/lib/actor/compose-subject-to-audit-actor.d.ts.map +1 -0
  10. package/dist/lib/actor/compose-subject-to-audit-actor.js +66 -0
  11. package/dist/lib/actor/compose-subject-to-audit-actor.js.map +1 -0
  12. package/dist/lib/audit-plugin.d.ts +21 -0
  13. package/dist/lib/audit-plugin.d.ts.map +1 -0
  14. package/dist/lib/audit-plugin.js +61 -0
  15. package/dist/lib/audit-plugin.js.map +1 -0
  16. package/dist/lib/client-diagnostics/client-diagnostic-event.ids.d.ts +5 -0
  17. package/dist/lib/client-diagnostics/client-diagnostic-event.ids.d.ts.map +1 -0
  18. package/dist/lib/client-diagnostics/client-diagnostic-event.ids.js +4 -0
  19. package/dist/lib/client-diagnostics/client-diagnostic-event.ids.js.map +1 -0
  20. package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.d.ts +23 -0
  21. package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.d.ts.map +1 -0
  22. package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.js +27 -0
  23. package/dist/lib/client-diagnostics/client-diagnostics.route-handlers.js.map +1 -0
  24. package/dist/lib/client-diagnostics/client-diagnostics.routes.d.ts +18 -0
  25. package/dist/lib/client-diagnostics/client-diagnostics.routes.d.ts.map +1 -0
  26. package/dist/lib/client-diagnostics/client-diagnostics.routes.js +41 -0
  27. package/dist/lib/client-diagnostics/client-diagnostics.routes.js.map +1 -0
  28. package/dist/lib/client-diagnostics/logic/client-diagnostic-row.d.ts +30 -0
  29. package/dist/lib/client-diagnostics/logic/client-diagnostic-row.d.ts.map +1 -0
  30. package/dist/lib/client-diagnostics/logic/client-diagnostic-row.js +39 -0
  31. package/dist/lib/client-diagnostics/logic/client-diagnostic-row.js.map +1 -0
  32. package/dist/lib/client-diagnostics/record-client-diagnostics.d.ts +29 -0
  33. package/dist/lib/client-diagnostics/record-client-diagnostics.d.ts.map +1 -0
  34. package/dist/lib/client-diagnostics/record-client-diagnostics.js +40 -0
  35. package/dist/lib/client-diagnostics/record-client-diagnostics.js.map +1 -0
  36. package/dist/lib/compose-audit.d.ts +27 -0
  37. package/dist/lib/compose-audit.d.ts.map +1 -0
  38. package/dist/lib/compose-audit.js +38 -0
  39. package/dist/lib/compose-audit.js.map +1 -0
  40. package/dist/lib/database/attach-audit-trigger.d.ts +34 -0
  41. package/dist/lib/database/attach-audit-trigger.d.ts.map +1 -0
  42. package/dist/lib/database/attach-audit-trigger.js +40 -0
  43. package/dist/lib/database/attach-audit-trigger.js.map +1 -0
  44. package/dist/lib/database/audit-log-position.ids.d.ts +13 -0
  45. package/dist/lib/database/audit-log-position.ids.d.ts.map +1 -0
  46. package/dist/lib/database/audit-log-position.ids.js +11 -0
  47. package/dist/lib/database/audit-log-position.ids.js.map +1 -0
  48. package/dist/lib/database/audit-row-json.d.ts +10 -0
  49. package/dist/lib/database/audit-row-json.d.ts.map +1 -0
  50. package/dist/lib/database/audit-row-json.js +2 -0
  51. package/dist/lib/database/audit-row-json.js.map +1 -0
  52. package/dist/lib/database/audit-trigger-allowlist.d.ts +4 -0
  53. package/dist/lib/database/audit-trigger-allowlist.d.ts.map +1 -0
  54. package/dist/lib/database/audit-trigger-allowlist.js +8 -0
  55. package/dist/lib/database/audit-trigger-allowlist.js.map +1 -0
  56. package/dist/lib/database/configure-audit-triggers.d.ts +8 -0
  57. package/dist/lib/database/configure-audit-triggers.d.ts.map +1 -0
  58. package/dist/lib/database/configure-audit-triggers.js +27 -0
  59. package/dist/lib/database/configure-audit-triggers.js.map +1 -0
  60. package/dist/lib/database/configure-plugin-audit-triggers.d.ts +11 -0
  61. package/dist/lib/database/configure-plugin-audit-triggers.d.ts.map +1 -0
  62. package/dist/lib/database/configure-plugin-audit-triggers.js +23 -0
  63. package/dist/lib/database/configure-plugin-audit-triggers.js.map +1 -0
  64. package/dist/lib/database/generated-tables/audit-log.tables.d.ts +363 -0
  65. package/dist/lib/database/generated-tables/audit-log.tables.d.ts.map +1 -0
  66. package/dist/lib/database/generated-tables/audit-log.tables.js +53 -0
  67. package/dist/lib/database/generated-tables/audit-log.tables.js.map +1 -0
  68. package/dist/lib/database/generated-tables/client-diagnostic-events.tables.d.ts +376 -0
  69. package/dist/lib/database/generated-tables/client-diagnostic-events.tables.d.ts.map +1 -0
  70. package/dist/lib/database/generated-tables/client-diagnostic-events.tables.js +45 -0
  71. package/dist/lib/database/generated-tables/client-diagnostic-events.tables.js.map +1 -0
  72. package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.d.ts +76 -0
  73. package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.d.ts.map +1 -0
  74. package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.js +32 -0
  75. package/dist/lib/database/generated-tables/known-fault-fingerprints.tables.js.map +1 -0
  76. package/dist/lib/database/generated-tables/request-log.tables.d.ts +678 -0
  77. package/dist/lib/database/generated-tables/request-log.tables.d.ts.map +1 -0
  78. package/dist/lib/database/generated-tables/request-log.tables.js +59 -0
  79. package/dist/lib/database/generated-tables/request-log.tables.js.map +1 -0
  80. package/dist/lib/database/migrations/20260910233455_audit.migration.d.ts +5 -0
  81. package/dist/lib/database/migrations/20260910233455_audit.migration.d.ts.map +1 -0
  82. package/dist/lib/database/migrations/20260910233455_audit.migration.js +304 -0
  83. package/dist/lib/database/migrations/20260910233455_audit.migration.js.map +1 -0
  84. package/dist/lib/database/readers/audit-log-reader.interface.d.ts +82 -0
  85. package/dist/lib/database/readers/audit-log-reader.interface.d.ts.map +1 -0
  86. package/dist/lib/database/readers/audit-log-reader.interface.js +10 -0
  87. package/dist/lib/database/readers/audit-log-reader.interface.js.map +1 -0
  88. package/dist/lib/database/readers/drizzle-audit-log-reader.d.ts +16 -0
  89. package/dist/lib/database/readers/drizzle-audit-log-reader.d.ts.map +1 -0
  90. package/dist/lib/database/readers/drizzle-audit-log-reader.js +197 -0
  91. package/dist/lib/database/readers/drizzle-audit-log-reader.js.map +1 -0
  92. package/dist/lib/database/readers/drizzle-fault-alert-reader.d.ts +36 -0
  93. package/dist/lib/database/readers/drizzle-fault-alert-reader.d.ts.map +1 -0
  94. package/dist/lib/database/readers/drizzle-fault-alert-reader.js +113 -0
  95. package/dist/lib/database/readers/drizzle-fault-alert-reader.js.map +1 -0
  96. package/dist/lib/database/readers/drizzle-request-log-reader.d.ts +16 -0
  97. package/dist/lib/database/readers/drizzle-request-log-reader.d.ts.map +1 -0
  98. package/dist/lib/database/readers/drizzle-request-log-reader.js +88 -0
  99. package/dist/lib/database/readers/drizzle-request-log-reader.js.map +1 -0
  100. package/dist/lib/database/readers/fault-alert-reader.interface.d.ts +73 -0
  101. package/dist/lib/database/readers/fault-alert-reader.interface.d.ts.map +1 -0
  102. package/dist/lib/database/readers/fault-alert-reader.interface.js +13 -0
  103. package/dist/lib/database/readers/fault-alert-reader.interface.js.map +1 -0
  104. package/dist/lib/database/readers/request-log-reader.interface.d.ts +64 -0
  105. package/dist/lib/database/readers/request-log-reader.interface.d.ts.map +1 -0
  106. package/dist/lib/database/readers/request-log-reader.interface.js +9 -0
  107. package/dist/lib/database/readers/request-log-reader.interface.js.map +1 -0
  108. package/dist/lib/database/testing/audited-fixture-tables.d.ts +14 -0
  109. package/dist/lib/database/testing/audited-fixture-tables.d.ts.map +1 -0
  110. package/dist/lib/database/testing/audited-fixture-tables.js +46 -0
  111. package/dist/lib/database/testing/audited-fixture-tables.js.map +1 -0
  112. package/dist/lib/database/writers/client-diagnostic-writer.interface.d.ts +20 -0
  113. package/dist/lib/database/writers/client-diagnostic-writer.interface.d.ts.map +1 -0
  114. package/dist/lib/database/writers/client-diagnostic-writer.interface.js +3 -0
  115. package/dist/lib/database/writers/client-diagnostic-writer.interface.js.map +1 -0
  116. package/dist/lib/database/writers/drizzle-client-diagnostic-writer.d.ts +11 -0
  117. package/dist/lib/database/writers/drizzle-client-diagnostic-writer.d.ts.map +1 -0
  118. package/dist/lib/database/writers/drizzle-client-diagnostic-writer.js +46 -0
  119. package/dist/lib/database/writers/drizzle-client-diagnostic-writer.js.map +1 -0
  120. package/dist/lib/database/writers/drizzle-request-log-writer.d.ts +9 -0
  121. package/dist/lib/database/writers/drizzle-request-log-writer.d.ts.map +1 -0
  122. package/dist/lib/database/writers/drizzle-request-log-writer.js +17 -0
  123. package/dist/lib/database/writers/drizzle-request-log-writer.js.map +1 -0
  124. package/dist/lib/database/writers/request-log-writer.interface.d.ts +17 -0
  125. package/dist/lib/database/writers/request-log-writer.interface.d.ts.map +1 -0
  126. package/dist/lib/database/writers/request-log-writer.interface.js +10 -0
  127. package/dist/lib/database/writers/request-log-writer.interface.js.map +1 -0
  128. package/dist/lib/export/create-audit-log-exporter.d.ts +19 -0
  129. package/dist/lib/export/create-audit-log-exporter.d.ts.map +1 -0
  130. package/dist/lib/export/create-audit-log-exporter.js +59 -0
  131. package/dist/lib/export/create-audit-log-exporter.js.map +1 -0
  132. package/dist/lib/fault-alerts/alert-new-faults.job.d.ts +48 -0
  133. package/dist/lib/fault-alerts/alert-new-faults.job.d.ts.map +1 -0
  134. package/dist/lib/fault-alerts/alert-new-faults.job.js +105 -0
  135. package/dist/lib/fault-alerts/alert-new-faults.job.js.map +1 -0
  136. package/dist/lib/fault-alerts/logic/describe-fault-line.d.ts +16 -0
  137. package/dist/lib/fault-alerts/logic/describe-fault-line.d.ts.map +1 -0
  138. package/dist/lib/fault-alerts/logic/describe-fault-line.js +21 -0
  139. package/dist/lib/fault-alerts/logic/describe-fault-line.js.map +1 -0
  140. package/dist/lib/fault-alerts/logic/summarize-new-faults.d.ts +51 -0
  141. package/dist/lib/fault-alerts/logic/summarize-new-faults.d.ts.map +1 -0
  142. package/dist/lib/fault-alerts/logic/summarize-new-faults.js +56 -0
  143. package/dist/lib/fault-alerts/logic/summarize-new-faults.js.map +1 -0
  144. package/dist/lib/fault-alerts/new-faults.email-template.d.ts +8 -0
  145. package/dist/lib/fault-alerts/new-faults.email-template.d.ts.map +1 -0
  146. package/dist/lib/fault-alerts/new-faults.email-template.js +66 -0
  147. package/dist/lib/fault-alerts/new-faults.email-template.js.map +1 -0
  148. package/dist/lib/jobs/prune-client-diagnostics.job.d.ts +25 -0
  149. package/dist/lib/jobs/prune-client-diagnostics.job.d.ts.map +1 -0
  150. package/dist/lib/jobs/prune-client-diagnostics.job.js +38 -0
  151. package/dist/lib/jobs/prune-client-diagnostics.job.js.map +1 -0
  152. package/dist/lib/jobs/prune-request-log.job.d.ts +23 -0
  153. package/dist/lib/jobs/prune-request-log.job.d.ts.map +1 -0
  154. package/dist/lib/jobs/prune-request-log.job.js +36 -0
  155. package/dist/lib/jobs/prune-request-log.job.js.map +1 -0
  156. package/dist/lib/jobs/retention-window.d.ts +3 -0
  157. package/dist/lib/jobs/retention-window.d.ts.map +1 -0
  158. package/dist/lib/jobs/retention-window.js +10 -0
  159. package/dist/lib/jobs/retention-window.js.map +1 -0
  160. package/dist/lib/request-log/insert-foreign-rows.d.ts +21 -0
  161. package/dist/lib/request-log/insert-foreign-rows.d.ts.map +1 -0
  162. package/dist/lib/request-log/insert-foreign-rows.js +86 -0
  163. package/dist/lib/request-log/insert-foreign-rows.js.map +1 -0
  164. package/dist/lib/request-log/postgres-request-log-sink.d.ts +64 -0
  165. package/dist/lib/request-log/postgres-request-log-sink.d.ts.map +1 -0
  166. package/dist/lib/request-log/postgres-request-log-sink.js +168 -0
  167. package/dist/lib/request-log/postgres-request-log-sink.js.map +1 -0
  168. package/dist/schema.d.ts +6 -0
  169. package/dist/schema.d.ts.map +1 -0
  170. package/dist/schema.js +5 -0
  171. package/dist/schema.js.map +1 -0
  172. package/dist/testing/audit-log-record.factory.d.ts +13 -0
  173. package/dist/testing/audit-log-record.factory.d.ts.map +1 -0
  174. package/dist/testing/audit-log-record.factory.js +46 -0
  175. package/dist/testing/audit-log-record.factory.js.map +1 -0
  176. package/dist/testing/audit-log.factory.d.ts +14 -0
  177. package/dist/testing/audit-log.factory.d.ts.map +1 -0
  178. package/dist/testing/audit-log.factory.js +30 -0
  179. package/dist/testing/audit-log.factory.js.map +1 -0
  180. package/dist/testing/index.d.ts +4 -0
  181. package/dist/testing/index.d.ts.map +1 -0
  182. package/dist/testing/index.js +5 -0
  183. package/dist/testing/index.js.map +1 -0
  184. package/dist/testing/request-log.factory.d.ts +13 -0
  185. package/dist/testing/request-log.factory.d.ts.map +1 -0
  186. package/dist/testing/request-log.factory.js +40 -0
  187. package/dist/testing/request-log.factory.js.map +1 -0
  188. package/package.json +67 -4
  189. package/src/lib/database/migrations/20260910233455_audit.migration.ts +345 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-log-reader.interface.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/readers/request-log-reader.interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,wDAAwD;IACxD,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAA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+1,9 @@
1
+ /**
2
+ * No behavior lives in this file — it is not a wrapper or a pass-through.
3
+ * This abstract class is the port for reading `request_log`: the type a
4
+ * caller holds AND the injection token composition binds.
5
+ * `DrizzleRequestLogReader` (database/readers/) implements it.
6
+ */
7
+ export class RequestLogReader {
8
+ }
9
+ //# sourceMappingURL=request-log-reader.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-log-reader.interface.js","sourceRoot":"","sources":["../../../../src/lib/database/readers/request-log-reader.interface.ts"],"names":[],"mappings":"AAmDA;;;;;GAKG;AACH,MAAM,OAAgB,gBAAgB;CAcrC"}
@@ -0,0 +1,14 @@
1
+ import type { PostgresConnection } from "@dads-framework/postgres";
2
+ /**
3
+ * Kit-owned tables for the audit suites, created in a test's private database
4
+ * and put under audit the same way a real table's migration does it
5
+ * (`attachAuditTrigger`). These fixtures are independent of any application schema.
6
+ *
7
+ * - `audit_fixture_parties` has a primary key, a unique slug, and an optional
8
+ * column, like a typical entity table.
9
+ * - `audit_fixture_reports` has no primary key: it is named by a unique pair
10
+ * and partitioned by a uuid owner column, like the tables with a composite unique key.
11
+ */
12
+ export declare const AUDITED_FIXTURE_TABLES: readonly ["audit_fixture_parties", "audit_fixture_reports"];
13
+ export declare function createAuditedFixtureTables(pool: PostgresConnection["pool"]): Promise<void>;
14
+ //# sourceMappingURL=audited-fixture-tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audited-fixture-tables.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/testing/audited-fixture-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YACjC,uBAAuB,EACvB,uBAAuB,CACf,CAAC;AAEX,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
@@ -0,0 +1,46 @@
1
+ import { attachAuditTrigger } from "../attach-audit-trigger.js";
2
+ /**
3
+ * Kit-owned tables for the audit suites, created in a test's private database
4
+ * and put under audit the same way a real table's migration does it
5
+ * (`attachAuditTrigger`). These fixtures are independent of any application schema.
6
+ *
7
+ * - `audit_fixture_parties` has a primary key, a unique slug, and an optional
8
+ * column, like a typical entity table.
9
+ * - `audit_fixture_reports` has no primary key: it is named by a unique pair
10
+ * and partitioned by a uuid owner column, like the tables with a composite unique key.
11
+ */
12
+ export const AUDITED_FIXTURE_TABLES = [
13
+ "audit_fixture_parties",
14
+ "audit_fixture_reports",
15
+ ];
16
+ export async function createAuditedFixtureTables(pool) {
17
+ const statements = [
18
+ `CREATE TABLE IF NOT EXISTS audit_fixture_parties (
19
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
20
+ name text NOT NULL,
21
+ slug text NOT NULL UNIQUE,
22
+ locale text
23
+ )`,
24
+ `CREATE TABLE IF NOT EXISTS audit_fixture_reports (
25
+ device_id uuid NOT NULL,
26
+ application text NOT NULL,
27
+ partition_id uuid NOT NULL,
28
+ note text,
29
+ UNIQUE (device_id, application)
30
+ )`,
31
+ ];
32
+ const builder = {
33
+ sql: (statement) => {
34
+ statements.push(statement);
35
+ },
36
+ };
37
+ attachAuditTrigger(builder, "audit_fixture_parties", { keyColumns: ["id"] });
38
+ attachAuditTrigger(builder, "audit_fixture_reports", {
39
+ keyColumns: ["device_id", "application"],
40
+ ownerColumn: "partition_id",
41
+ });
42
+ for (const statement of statements) {
43
+ await pool.query(statement);
44
+ }
45
+ }
46
+ //# sourceMappingURL=audited-fixture-tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audited-fixture-tables.js","sourceRoot":"","sources":["../../../../src/lib/database/testing/audited-fixture-tables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,uBAAuB;IACvB,uBAAuB;CACf,CAAC;AAEX,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,IAAgC;IAEhC,MAAM,UAAU,GAAa;QAC3B;;;;;OAKG;QACH;;;;;;OAMG;KACJ,CAAC;IACF,MAAM,OAAO,GAAG;QACd,GAAG,EAAE,CAAC,SAAiB,EAAE,EAAE;YACzB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;IACF,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7E,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,EAAE;QACnD,UAAU,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC;QACxC,WAAW,EAAE,cAAc;KAC5B,CAAC,CAAC;IACH,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { clientDiagnosticEvents } from "../generated-tables/client-diagnostic-events.tables.js";
2
+ /**
3
+ * No behavior lives in this file. This abstract class is the port for storing
4
+ * and pruning `client_diagnostic_events` — the type the recorder and the
5
+ * retention sweep hold, and the injection token composition binds.
6
+ * `DrizzleClientDiagnosticWriter` implements it; a fake stands in for unit
7
+ * tests, which is what lets the recorder's rules be proved without a database.
8
+ */
9
+ export type ClientDiagnosticRow = Readonly<Pick<typeof clientDiagnosticEvents.$inferSelect, "id" | "occurredAt" | "fingerprint" | "kind" | "severity" | "name" | "message" | "frames" | "breadcrumbs" | "release" | "client" | "requestId" | "actorKind" | "actorId" | "context">>;
10
+ export declare abstract class ClientDiagnosticWriter {
11
+ /** Store a batch as one statement. Returns how many rows were written. */
12
+ abstract record(rows: readonly ClientDiagnosticRow[]): Promise<number>;
13
+ /**
14
+ * Delete every row recorded strictly before `cutoff`, returning the count.
15
+ * The table is allowlisted out of the `audit_record` trigger, so this
16
+ * produces no `audit_log` row.
17
+ */
18
+ abstract deleteRecordedBefore(cutoff: Date): Promise<number>;
19
+ }
20
+ //# sourceMappingURL=client-diagnostic-writer.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-diagnostic-writer.interface.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/writers/client-diagnostic-writer.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wDAAwD,CAAC;AAErG;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACxC,IAAI,CACF,OAAO,sBAAsB,CAAC,YAAY,EACxC,IAAI,GACJ,YAAY,GACZ,aAAa,GACb,MAAM,GACN,UAAU,GACV,MAAM,GACN,SAAS,GACT,QAAQ,GACR,aAAa,GACb,SAAS,GACT,QAAQ,GACR,WAAW,GACX,WAAW,GACX,SAAS,GACT,SAAS,CACZ,CACF,CAAC;AAEF,8BAAsB,sBAAsB;IAC1C,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvE;;;;OAIG;IACH,QAAQ,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9D"}
@@ -0,0 +1,3 @@
1
+ export class ClientDiagnosticWriter {
2
+ }
3
+ //# sourceMappingURL=client-diagnostic-writer.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-diagnostic-writer.interface.js","sourceRoot":"","sources":["../../../../src/lib/database/writers/client-diagnostic-writer.interface.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAgB,sBAAsB;CAU3C"}
@@ -0,0 +1,11 @@
1
+ import type { DrizzleHandle } from "@dads-framework/postgres";
2
+ import type { ClientDiagnosticWriter } from "./client-diagnostic-writer.interface.js";
3
+ import { type ClientDiagnosticRow } from "./client-diagnostic-writer.interface.js";
4
+ /** Drizzle adapter for client diagnostic storage and its retention sweep. */
5
+ export declare class DrizzleClientDiagnosticWriter implements ClientDiagnosticWriter {
6
+ private readonly db;
7
+ constructor(db: DrizzleHandle);
8
+ record(rows: readonly ClientDiagnosticRow[]): Promise<number>;
9
+ deleteRecordedBefore(cutoff: Date): Promise<number>;
10
+ }
11
+ //# sourceMappingURL=drizzle-client-diagnostic-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-client-diagnostic-writer.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/writers/drizzle-client-diagnostic-writer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAEnF,6EAA6E;AAC7E,qBAAa,6BAA8B,YAAW,sBAAsB;IAC9D,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAAI;IAE5C,MAAM,CAAC,IAAI,EAAE,SAAS,mBAAmB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlE;IAEK,oBAAoB,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAMxD;CACF"}
@@ -0,0 +1,46 @@
1
+ import { lt } from "drizzle-orm";
2
+ import { clientDiagnosticEvents } from "../generated-tables/client-diagnostic-events.tables.js";
3
+ import {} from "./client-diagnostic-writer.interface.js";
4
+ /** Drizzle adapter for client diagnostic storage and its retention sweep. */
5
+ export class DrizzleClientDiagnosticWriter {
6
+ db;
7
+ constructor(db) {
8
+ this.db = db;
9
+ }
10
+ async record(rows) {
11
+ if (rows.length === 0)
12
+ return 0;
13
+ // One statement for the batch: a page that failed several ways at once
14
+ // reports once, and storing it costs one round trip rather than twenty.
15
+ const written = await this.db
16
+ .insert(clientDiagnosticEvents)
17
+ .values(rows.map((row) => ({
18
+ id: row.id,
19
+ occurredAt: row.occurredAt,
20
+ fingerprint: row.fingerprint,
21
+ kind: row.kind,
22
+ severity: row.severity,
23
+ name: row.name,
24
+ message: row.message,
25
+ frames: row.frames,
26
+ breadcrumbs: row.breadcrumbs,
27
+ release: row.release,
28
+ client: row.client,
29
+ requestId: row.requestId,
30
+ actorKind: row.actorKind,
31
+ actorId: row.actorId,
32
+ context: row.context,
33
+ })))
34
+ .onConflictDoNothing({ target: clientDiagnosticEvents.id })
35
+ .returning({ id: clientDiagnosticEvents.id });
36
+ return written.length;
37
+ }
38
+ async deleteRecordedBefore(cutoff) {
39
+ const deleted = await this.db
40
+ .delete(clientDiagnosticEvents)
41
+ .where(lt(clientDiagnosticEvents.recordedAt, cutoff))
42
+ .returning({ id: clientDiagnosticEvents.id });
43
+ return deleted.length;
44
+ }
45
+ }
46
+ //# sourceMappingURL=drizzle-client-diagnostic-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-client-diagnostic-writer.js","sourceRoot":"","sources":["../../../../src/lib/database/writers/drizzle-client-diagnostic-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAIjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wDAAwD,CAAC;AAEhG,OAAO,EAA4B,MAAM,yCAAyC,CAAC;AAEnF,6EAA6E;AAC7E,MAAM,OAAO,6BAA6B;IACX,EAAE;IAA/B,YAA6B,EAAiB;kBAAjB,EAAE;IAAkB,CAAC;IAElD,KAAK,CAAC,MAAM,CAAC,IAAoC;QAC/C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,CAAC,CAAC;QAChC,uEAAuE;QACvE,wEAAwE;QACxE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE;aAC1B,MAAM,CAAC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res";
2
+ import type { RequestLogWriter } from "./request-log-writer.interface.js";
3
+ /** Drizzle adapter for the `request_log` retention sweep. */
4
+ export declare class DrizzleRequestLogWriter implements RequestLogWriter {
5
+ private readonly db;
6
+ constructor(db: DrizzleHandle);
7
+ deleteRecordedBefore(cutoff: Date): Promise<number>;
8
+ }
9
+ //# sourceMappingURL=drizzle-request-log-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-request-log-writer.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/writers/drizzle-request-log-writer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,6DAA6D;AAC7D,qBAAa,uBAAwB,YAAW,gBAAgB;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE;IAA/B,YAA6B,EAAE,EAAE,aAAa,EAAI;IAE5C,oBAAoB,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAMxD;CACF"}
@@ -0,0 +1,17 @@
1
+ import { lt } from "drizzle-orm";
2
+ import { requestLog } from "../generated-tables/request-log.tables.js";
3
+ /** Drizzle adapter for the `request_log` retention sweep. */
4
+ export class DrizzleRequestLogWriter {
5
+ db;
6
+ constructor(db) {
7
+ this.db = db;
8
+ }
9
+ async deleteRecordedBefore(cutoff) {
10
+ const deleted = await this.db
11
+ .delete(requestLog)
12
+ .where(lt(requestLog.recordedAt, cutoff))
13
+ .returning({ requestId: requestLog.requestId });
14
+ return deleted.length;
15
+ }
16
+ }
17
+ //# sourceMappingURL=drizzle-request-log-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-request-log-writer.js","sourceRoot":"","sources":["../../../../src/lib/database/writers/drizzle-request-log-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AAGvE,6DAA6D;AAC7D,MAAM,OAAO,uBAAuB;IACL,EAAE;IAA/B,YAA6B,EAAiB;kBAAjB,EAAE;IAAkB,CAAC;IAElD,KAAK,CAAC,oBAAoB,CAAC,MAAY;QACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE;aAC1B,MAAM,CAAC,UAAU,CAAC;aAClB,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;aACxC,SAAS,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC,MAAM,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * No behavior lives in this file — it is not a wrapper or a pass-through.
3
+ * This abstract class is the port for the `request_log` retention sweep:
4
+ * the type the prune job holds AND the injection token
5
+ * composition binds. `DrizzleRequestLogWriter` (database/writers/)
6
+ * implements it; a fake stands in for the job's unit tests.
7
+ */
8
+ export declare abstract class RequestLogWriter {
9
+ /**
10
+ * Delete every `request_log` row recorded strictly before `cutoff` and
11
+ * return how many rows were removed. `request_log` carries no
12
+ * `audit_record` trigger (it is allowlisted — see
13
+ * `AUDIT_TRIGGER_ALLOWLIST`), so this delete produces no `audit_log` row.
14
+ */
15
+ abstract deleteRecordedBefore(cutoff: Date): Promise<number>;
16
+ }
17
+ //# sourceMappingURL=request-log-writer.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-log-writer.interface.d.ts","sourceRoot":"","sources":["../../../../src/lib/database/writers/request-log-writer.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,8BAAsB,gBAAgB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9D"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * No behavior lives in this file — it is not a wrapper or a pass-through.
3
+ * This abstract class is the port for the `request_log` retention sweep:
4
+ * the type the prune job holds AND the injection token
5
+ * composition binds. `DrizzleRequestLogWriter` (database/writers/)
6
+ * implements it; a fake stands in for the job's unit tests.
7
+ */
8
+ export class RequestLogWriter {
9
+ }
10
+ //# sourceMappingURL=request-log-writer.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-log-writer.interface.js","sourceRoot":"","sources":["../../../../src/lib/database/writers/request-log-writer.interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAgB,gBAAgB;CAQrC"}
@@ -0,0 +1,19 @@
1
+ import type { AuditLogCursor, AuditLogReader } from "../database/readers/audit-log-reader.interface.js";
2
+ export type AuditLogExportOptions = {
3
+ readonly reader: Pick<AuditLogReader, "listRows">;
4
+ /** The tenant dimension configured on the audited tables. */
5
+ readonly tenantDimension: string;
6
+ /** Check the authenticated caller's permission to export this tenant. */
7
+ readonly authorize: (tenantId: string) => boolean | Promise<boolean>;
8
+ };
9
+ export type AuditLogExportPage = {
10
+ readonly kind: "denied";
11
+ } | {
12
+ readonly kind: "page";
13
+ readonly contentType: "application/x-ndjson";
14
+ readonly body: string;
15
+ readonly nextCursor: AuditLogCursor | null;
16
+ };
17
+ /** Read one authorized tenant page and serialize audit metadata as NDJSON. */
18
+ export declare function createAuditLogExporter({ reader, tenantDimension, authorize, }: AuditLogExportOptions): (input: unknown) => Promise<AuditLogExportPage>;
19
+ //# sourceMappingURL=create-audit-log-exporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-audit-log-exporter.d.ts","sourceRoot":"","sources":["../../../src/lib/export/create-audit-log-exporter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEf,MAAM,mDAAmD,CAAC;AAwB3D,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAClD,6DAA6D;IAC7D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEN,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,eAAe,EACf,SAAS,GACV,EAAE,qBAAqB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAyBzE"}
@@ -0,0 +1,59 @@
1
+ import { z } from "zod";
2
+ import { parseAuditLogPosition } from "../database/audit-log-position.ids.js";
3
+ const exportRequest = z.strictObject({
4
+ tenantId: z.string().min(1).max(255),
5
+ pageSize: z.int().min(1).max(500).default(100),
6
+ olderThan: z
7
+ .strictObject({
8
+ recordedAt: z.iso.datetime({ precision: 6 }),
9
+ position: z
10
+ .int()
11
+ .positive()
12
+ .transform((value, context) => {
13
+ const position = parseAuditLogPosition(value);
14
+ if (position !== null)
15
+ return position;
16
+ context.addIssue({
17
+ code: "custom",
18
+ message: "Invalid audit log position",
19
+ });
20
+ return z.NEVER;
21
+ }),
22
+ })
23
+ .optional(),
24
+ });
25
+ /** Read one authorized tenant page and serialize audit metadata as NDJSON. */
26
+ export function createAuditLogExporter({ reader, tenantDimension, authorize, }) {
27
+ const dimension = z
28
+ .string()
29
+ .regex(/^[a-z_][a-z0-9_]{0,62}$/u)
30
+ .parse(tenantDimension);
31
+ return async (input) => {
32
+ const { tenantId, pageSize, olderThan } = exportRequest.parse(input);
33
+ const grant = await authorize(tenantId);
34
+ if (grant !== true)
35
+ return { kind: "denied" };
36
+ const rows = await reader.listRows({ kind: "application", values: { [dimension]: tenantId } }, {}, olderThan ?? null, pageSize + 1);
37
+ const page = rows.slice(0, pageSize);
38
+ return {
39
+ kind: "page",
40
+ contentType: "application/x-ndjson",
41
+ body: page.map(serializeAuditMetadata).join(""),
42
+ nextCursor: rows.length > pageSize ? (page.at(-1)?.cursor ?? null) : null,
43
+ };
44
+ };
45
+ }
46
+ function serializeAuditMetadata(row) {
47
+ return `${JSON.stringify({
48
+ position: row.position,
49
+ recordedAt: row.cursor.recordedAt,
50
+ actorKind: row.actorKind,
51
+ actorId: row.actorId,
52
+ userId: row.userId,
53
+ requestId: row.requestId,
54
+ tableName: row.tableName,
55
+ operation: row.operation,
56
+ changedColumns: row.changedColumns,
57
+ })}\n`;
58
+ }
59
+ //# sourceMappingURL=create-audit-log-exporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-audit-log-exporter.js","sourceRoot":"","sources":["../../../src/lib/export/create-audit-log-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAO9E,MAAM,aAAa,GAAG,CAAC,CAAC,YAAY,CAAC;IACnC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACpC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9C,SAAS,EAAE,CAAC;SACT,YAAY,CAAC;QACZ,UAAU,EAAE,CAAC,CAAC,GAA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AAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sBAAsB;YACnC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/C,UAAU,EAAE,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;SAC1E,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAmB;IACjD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;QACvB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,UAAU;QACjC,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,cAAc,EAAE,GAAG,CAAC,cAAc;KACnC,CAAC,IAAI,CAAC;AACT,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Clock } from "@dads-framework/clock";
2
+ import type { EmailDelivery } from "@dads-framework/email-delivery";
3
+ import { type JobDefinition, type JobLog } from "@dads-framework/job-queue";
4
+ import type { FaultAlertReader } from "../database/readers/fault-alert-reader.interface.js";
5
+ export declare const ALERT_NEW_FAULTS_JOB = "audit.alert-new-faults";
6
+ export type CreateAlertNewFaultsJobDeps = {
7
+ readonly reader: FaultAlertReader;
8
+ readonly clock: Pick<Clock, "now">;
9
+ readonly email: Pick<EmailDelivery, "enqueue" | "dispatch">;
10
+ /** Who hears about it. Empty means nobody, and the job says so once. */
11
+ readonly recipients: readonly string[];
12
+ /**
13
+ * How far back a sweep looks for faults that are happening.
14
+ *
15
+ * It bounds the scan, not the definition of new — `known_fault_fingerprints`
16
+ * does that — so it can be raised to cover a missed run without reporting
17
+ * anything twice. What it does decide is how long a fault has to stop
18
+ * happening before a sweep stops noticing it.
19
+ */
20
+ readonly windowHours: number;
21
+ readonly log: JobLog;
22
+ };
23
+ /**
24
+ * Tells somebody when a fault type nobody has seen before starts happening.
25
+ *
26
+ * This is the job that makes all the recording matter. Everything else in the
27
+ * telemetry work answers a question someone already thought to ask; this one
28
+ * is the only part that speaks first.
29
+ *
30
+ * **New types, not volume.** A fingerprint nobody has been told about, that is
31
+ * happening now, is the single highest-signal thing this data can say. A route
32
+ * that fails a thousand times an hour and always has is a known problem, and
33
+ * paging on it is how a channel becomes one people filter.
34
+ *
35
+ * **New means never reported, not recently absent.** The memory lives in
36
+ * `known_fault_fingerprints`, which is never pruned, so a fault that goes
37
+ * quiet for a month and returns is not news — and the sweep window can be any
38
+ * length without a fingerprint being reported twice.
39
+ *
40
+ * **Silence when nothing is new.** No heartbeat email, deliberately: an hourly
41
+ * "nothing broke" is indistinguishable from no alerting at all after about a
42
+ * week, because nobody reads it.
43
+ *
44
+ * **Enqueued, not sent in-band.** The outbox owns delivery and retry, so a
45
+ * mail vendor having a bad day cannot fail this job or lose the alert.
46
+ */
47
+ export declare function createAlertNewFaultsJob(deps: CreateAlertNewFaultsJobDeps): JobDefinition;
48
+ //# sourceMappingURL=alert-new-faults.job.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alert-new-faults.job.d.ts","sourceRoot":"","sources":["../../../src/lib/fault-alerts/alert-new-faults.job.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,MAAM,EACZ,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAQ5F,eAAO,MAAM,oBAAoB,2BAA2B,CAAC;AAI7D,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC;IAC5D,wEAAwE;IACxE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,2BAA2B,GAChC,aAAa,CAkEf"}
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { cronSchedule, defineJob, } from "@dads-framework/job-queue";
3
+ import { describeFaultLine } from "./logic/describe-fault-line.js";
4
+ import { isWorthSending, summarizeNewFaults, } from "./logic/summarize-new-faults.js";
5
+ import { newFaultsEmailTemplate } from "./new-faults.email-template.js";
6
+ export const ALERT_NEW_FAULTS_JOB = "audit.alert-new-faults";
7
+ const MS_PER_HOUR = 60 * 60 * 1000;
8
+ /**
9
+ * Tells somebody when a fault type nobody has seen before starts happening.
10
+ *
11
+ * This is the job that makes all the recording matter. Everything else in the
12
+ * telemetry work answers a question someone already thought to ask; this one
13
+ * is the only part that speaks first.
14
+ *
15
+ * **New types, not volume.** A fingerprint nobody has been told about, that is
16
+ * happening now, is the single highest-signal thing this data can say. A route
17
+ * that fails a thousand times an hour and always has is a known problem, and
18
+ * paging on it is how a channel becomes one people filter.
19
+ *
20
+ * **New means never reported, not recently absent.** The memory lives in
21
+ * `known_fault_fingerprints`, which is never pruned, so a fault that goes
22
+ * quiet for a month and returns is not news — and the sweep window can be any
23
+ * length without a fingerprint being reported twice.
24
+ *
25
+ * **Silence when nothing is new.** No heartbeat email, deliberately: an hourly
26
+ * "nothing broke" is indistinguishable from no alerting at all after about a
27
+ * week, because nobody reads it.
28
+ *
29
+ * **Enqueued, not sent in-band.** The outbox owns delivery and retry, so a
30
+ * mail vendor having a bad day cannot fail this job or lose the alert.
31
+ */
32
+ export function createAlertNewFaultsJob(deps) {
33
+ requirePositiveIntegerWindow(deps.windowHours);
34
+ return defineJob({
35
+ name: ALERT_NEW_FAULTS_JOB,
36
+ payload: z.strictObject({}),
37
+ retry: { attempts: 3, backoffMs: 5_000 },
38
+ schedules: [
39
+ cronSchedule({
40
+ id: "audit.alert-new-faults.hourly",
41
+ pattern: "0 5 * * * *",
42
+ timeZone: "UTC",
43
+ payload: {},
44
+ }),
45
+ ],
46
+ run: async () => {
47
+ if (deps.recipients.length === 0) {
48
+ deps.log.info({ event: "fault-alerts.no-recipients" }, "fault alerting has nobody to tell");
49
+ return;
50
+ }
51
+ const since = new Date(deps.clock.now().getTime() - deps.windowHours * MS_PER_HOUR);
52
+ await learnWhatIsAlreadyBroken(deps, since);
53
+ const [server, client] = await Promise.all([
54
+ deps.reader.unalertedServerFaultsSince(since),
55
+ deps.reader.unalertedClientFaultsSince(since),
56
+ ]);
57
+ const summary = summarizeNewFaults({ server, client });
58
+ if (!isWorthSending(summary))
59
+ return;
60
+ const enqueued = await deps.email.enqueue(newFaultsEmailTemplate, {
61
+ faults: summary.faults.map(describeFaultLine),
62
+ totalOccurrences: summary.totalOccurrences,
63
+ truncated: summary.truncated,
64
+ windowHours: deps.windowHours,
65
+ }, { to: deps.recipients.map((address) => ({ address })) });
66
+ await deps.email.dispatch([enqueued.id]);
67
+ // After the mail is durably queued, and only for the faults the mail
68
+ // actually listed: a truncated tail stays unremembered so the next
69
+ // sweep carries it rather than losing it.
70
+ await deps.reader.rememberAlertedFaults(summary.faults.map((fault) => ({
71
+ origin: fault.origin,
72
+ fingerprint: fault.fingerprint,
73
+ })));
74
+ deps.log.info({
75
+ event: "fault-alerts.sent",
76
+ faults: summary.faults.length,
77
+ occurrences: summary.totalOccurrences,
78
+ truncated: summary.truncated,
79
+ }, "new faults alerted");
80
+ },
81
+ });
82
+ }
83
+ /**
84
+ * While the memory is empty, everything already on record is taken as known.
85
+ *
86
+ * Switching alerting on would otherwise report months of familiar problems in
87
+ * one email, which is how a channel becomes one people filter on day one.
88
+ * Only faults that predate the window are swallowed, so on a system where
89
+ * nothing has broken yet this records nothing and the first fault to ever
90
+ * happen still gets its alert.
91
+ */
92
+ async function learnWhatIsAlreadyBroken(deps, since) {
93
+ if (await deps.reader.hasRememberedAnyFault())
94
+ return;
95
+ const learned = await deps.reader.rememberFaultsSeenBefore(since);
96
+ if (learned === 0)
97
+ return;
98
+ deps.log.info({ event: "fault-alerts.learned", faults: learned }, "fault alerting took what was already broken as known");
99
+ }
100
+ function requirePositiveIntegerWindow(windowHours) {
101
+ if (!Number.isInteger(windowHours) || windowHours <= 0) {
102
+ throw new Error(`fault alert windowHours must be a positive integer, got ${windowHours}`);
103
+ }
104
+ }
105
+ //# sourceMappingURL=alert-new-faults.job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alert-new-faults.job.js","sourceRoot":"","sources":["../../../src/lib/fault-alerts/alert-new-faults.job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EACL,YAAY,EACZ,SAAS,GAGV,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EACL,cAAc,EACd,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,MAAM,CAAC,MAAM,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I,MAAM,IAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE;QAAE,OAAO;IACtD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAClE,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO;IAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,OAAO,EAAE,EAClD,sDAAsD,CACvD,CAAC;AACJ,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAmB;IACvD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,2DAA2D,WAAW,EAAE,CACzE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * One fault, as a line somebody reads on a phone.
3
+ *
4
+ * Formatting lives here rather than in the email because it is a decision with
5
+ * a right answer worth testing — what a reader needs first, and what is
6
+ * noise — and because a template that branches on counts and nulls is a
7
+ * template nobody can review at a glance.
8
+ *
9
+ * Order is deliberate: the type and origin say whether this is your problem,
10
+ * the count says how bad, the location says where to look, and the
11
+ * fingerprint is the handle for looking properly. Someone who stops reading
12
+ * after the first two words has still learned the most important thing.
13
+ */
14
+ import type { AlertableFault } from "./summarize-new-faults.js";
15
+ export declare function describeFaultLine(fault: AlertableFault): string;
16
+ //# sourceMappingURL=describe-fault-line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-fault-line.d.ts","sourceRoot":"","sources":["../../../../src/lib/fault-alerts/logic/describe-fault-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAO/D"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * One fault, as a line somebody reads on a phone.
3
+ *
4
+ * Formatting lives here rather than in the email because it is a decision with
5
+ * a right answer worth testing — what a reader needs first, and what is
6
+ * noise — and because a template that branches on counts and nulls is a
7
+ * template nobody can review at a glance.
8
+ *
9
+ * Order is deliberate: the type and origin say whether this is your problem,
10
+ * the count says how bad, the location says where to look, and the
11
+ * fingerprint is the handle for looking properly. Someone who stops reading
12
+ * after the first two words has still learned the most important thing.
13
+ */
14
+ export function describeFaultLine(fault) {
15
+ const occurrences = fault.occurrences === 1
16
+ ? "1 occurrence"
17
+ : `${fault.occurrences} occurrences`;
18
+ const location = fault.where === null ? "" : ` at ${fault.where}`;
19
+ return `${fault.type} (${fault.origin}) — ${occurrences}${location} · ${fault.fingerprint}`;
20
+ }
21
+ //# sourceMappingURL=describe-fault-line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-fault-line.js","sourceRoot":"","sources":["../../../../src/lib/fault-alerts/logic/describe-fault-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,UAAU,iBAAiB,CAAC,KAAqB;IACrD,MAAM,WAAW,GACf,KAAK,CAAC,WAAW,KAAK,CAAC;QACrB,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,GAAG,KAAK,CAAC,WAAW,cAAc,CAAC;IACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IAClE,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,MAAM,OAAO,WAAW,GAAG,QAAQ,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * What is worth waking someone for.
3
+ *
4
+ * The judgement that decides whether all the recording is worth anything, and
5
+ * a pure function with its own tests because getting it wrong is silent in
6
+ * both directions: too eager and people stop reading; too quiet and nobody
7
+ * finds out, which is the pain this exists to end.
8
+ *
9
+ * The rule is **new fault types, not fault volume.** A fingerprint nobody has
10
+ * been told about, that is happening now, is the single highest-signal thing
11
+ * this data can say. Volume is deliberately not an alert: a route that fails a
12
+ * thousand times an hour and always has is a known problem, and paging on it
13
+ * teaches people to ignore the channel.
14
+ *
15
+ * Deciding which fingerprints qualify is the reader's job, not this one's —
16
+ * it is a fact in `known_fault_fingerprints`. What is decided here is how many
17
+ * of them one email is allowed to carry, and in what order.
18
+ */
19
+ import type { FaultGroup, FaultOrigin } from "../../database/readers/fault-alert-reader.interface.js";
20
+ /** One fault as the email renders it. */
21
+ export type AlertableFault = {
22
+ readonly fingerprint: string;
23
+ readonly type: string;
24
+ readonly occurrences: number;
25
+ readonly where: string | null;
26
+ readonly origin: FaultOrigin;
27
+ };
28
+ export type NewFaultSummary = {
29
+ readonly faults: readonly AlertableFault[];
30
+ /** Total across every fault below, so the subject can lead with a number. */
31
+ readonly totalOccurrences: number;
32
+ /** Trimmed because more were found than one email should carry. */
33
+ readonly truncated: boolean;
34
+ };
35
+ /**
36
+ * The most a digest carries. Past this, the list stops being a thing anyone
37
+ * reads and the right response is to look at the data directly — so the email
38
+ * says so rather than growing without bound.
39
+ *
40
+ * The tail is not dropped, only deferred: the caller remembers what the email
41
+ * listed, so anything trimmed here is still unreported and leads the next
42
+ * sweep.
43
+ */
44
+ export declare const MAX_FAULTS_PER_ALERT = 25;
45
+ export declare function summarizeNewFaults(input: {
46
+ readonly server: readonly FaultGroup[];
47
+ readonly client: readonly FaultGroup[];
48
+ }): NewFaultSummary;
49
+ /** Nothing new happened, and an email saying so is how a channel dies. */
50
+ export declare function isWorthSending(summary: NewFaultSummary): boolean;
51
+ //# sourceMappingURL=summarize-new-faults.d.ts.map