@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
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bryton Cooper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,199 @@
1
- # Temporary Holding Version
1
+ # @dads-framework/audit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Find who changed an audited row, what changed, and which request caused it.
4
+ The kit also records requests and client diagnostics. `composeAudit` wires
5
+ their retention jobs and diagnostic route to the application's services.
6
+
7
+ ## Try it
8
+
9
+ In the generated starter, [`migrations/20261120080000_starter.migration.ts`](../../../apps/kit-workbench/migrations/20261120080000_starter.migration.ts)
10
+ installs the audit schema and attaches row triggers. That migration knows the
11
+ application's table keys and which columns define tenant scope.
12
+
13
+ Use Node.js 22 or later and a disposable Postgres database. Set
14
+ `DATABASE_URL` to the migrated database. Apply the audit schema through
15
+ `installAuditSchemaV1(pgm)` in your migration runner, create the example
16
+ table, and attach the trigger as shown under [Use it](#use-it). The
17
+ application must authorize access before invoking the audit reader.
18
+
19
+ ```sh
20
+ npm install @dads-framework/audit @dads-framework/audit-actor @dads-framework/postgres
21
+ npm install -D tsx
22
+ ```
23
+
24
+ Save as `record-audit.mts` and run `npx tsx record-audit.mts`.
25
+
26
+ <!-- dads:check-example -->
27
+
28
+ ```ts
29
+ import { randomUUID } from "node:crypto";
30
+ import { DrizzleAuditLogReader } from "@dads-framework/audit";
31
+ import {
32
+ currentAuditActor,
33
+ withSystemActor,
34
+ } from "@dads-framework/audit-actor";
35
+ import { createPostgresConnection } from "@dads-framework/postgres";
36
+
37
+ const connectionString = process.env.DATABASE_URL;
38
+ if (!connectionString) throw new Error("Set DATABASE_URL.");
39
+
40
+ const connection = createPostgresConnection(
41
+ {
42
+ connectionString,
43
+ schema: {},
44
+ auditActorSource: currentAuditActor,
45
+ },
46
+ console,
47
+ );
48
+ try {
49
+ const id = randomUUID();
50
+ const workspace = "audit-example";
51
+ await withSystemActor("example-import", () =>
52
+ connection.pool.query(
53
+ "INSERT INTO documents (id, workspace_key, project_key) VALUES ($1, $2, $3)",
54
+ [id, workspace, "example-project"],
55
+ ),
56
+ );
57
+
58
+ const reader = new DrizzleAuditLogReader(connection.drizzle);
59
+ const filter = { record: { tableName: "documents", rowKey: { id } } };
60
+ const rows = await reader.listRows(
61
+ { kind: "application", values: { workspace } },
62
+ filter,
63
+ null,
64
+ 10,
65
+ );
66
+ console.log(rows.map(({ operation, actorId }) => [operation, actorId]));
67
+ const outside = await reader.listRows(
68
+ { kind: "application", values: { workspace: "unrelated" } },
69
+ filter,
70
+ null,
71
+ 10,
72
+ );
73
+ console.log(outside.length);
74
+ } finally {
75
+ await connection.close();
76
+ }
77
+ ```
78
+
79
+ The result is one row with operation `insert` and actor ID `example-import`,
80
+ then `0` for the unrelated workspace.
81
+
82
+ ## Use it
83
+
84
+ Register a migration after the audit schema migration. For the example, add
85
+ the table before attaching the trigger.
86
+
87
+ ```ts
88
+ import { configureAuditTriggers } from "@dads-framework/audit/schema";
89
+ import type { MigrationBuilder } from "node-pg-migrate";
90
+
91
+ export function up(pgm: MigrationBuilder) {
92
+ pgm.sql(`
93
+ CREATE TABLE public.documents (
94
+ id uuid PRIMARY KEY,
95
+ workspace_key text NOT NULL,
96
+ project_key text NOT NULL
97
+ )
98
+ `);
99
+ configureAuditTriggers(pgm, {
100
+ tables: {
101
+ documents: {
102
+ keyColumns: ["id"],
103
+ scopeColumns: { workspace: "workspace_key", project: "project_key" },
104
+ },
105
+ },
106
+ });
107
+ }
108
+ ```
109
+
110
+ In an application migration, declare each audited table's identity columns and
111
+ map any scope dimensions. Use `excludeTables` to explicitly remove triggers
112
+ from existing tables such as temporary credential storage.
113
+
114
+ The migration reconciles each named table's trigger in the public schema.
115
+ Name new tables in their own application migration. Audit-owned tables are
116
+ always excluded from this configuration. Configuration changes affect future
117
+ writes. The kit keeps previously recorded audit entries intact.
118
+
119
+ ### Read the audit trail
120
+
121
+ Capture dimensions from the affected row at write time. Read them with
122
+ `{ kind: "application", values: { workspace: "example" } }`. All supplied
123
+ dimensions must match, and an empty scope matches nothing. An update that
124
+ changes a dimension is excluded from reads constrained by that dimension, so
125
+ a scope never exposes the other scope's row image. A platform read includes those updates.
126
+
127
+ Wrap writes in an audit actor context or use the attributed Postgres pool
128
+ from an application request or job. Applications can supply their own actor
129
+ kinds and request attribution. An audited write without an actor stamp
130
+ fails before it commits.
131
+
132
+ ## Export audit metadata for a tenant
133
+
134
+ Build the exporter with the audit reader, the tenant dimension configured on
135
+ your audited tables, and an application permission check. This handler fragment
136
+ assumes `auditReader` is your `AuditLogReader` and `canExportAuditLog` checks
137
+ the authenticated caller's export permission for the supplied tenant.
138
+
139
+ ```ts
140
+ import { createAuditLogExporter } from "@dads-framework/audit";
141
+
142
+ const exportPage = createAuditLogExporter({
143
+ reader: auditReader,
144
+ tenantDimension: "workspace",
145
+ authorize: (tenantId) => canExportAuditLog(caller, tenantId),
146
+ });
147
+
148
+ const first = await exportPage({ tenantId: "example", pageSize: 100 });
149
+ if (first.kind === "page") {
150
+ // Write first.body as first.contentType and return first.nextCursor.
151
+ }
152
+ ```
153
+
154
+ The exporter checks the permission on every page before reading the audit log.
155
+ A denied request returns `{ kind: "denied" }`. Malformed input throws a Zod
156
+ validation error. The permission check must cover all audit metadata in the
157
+ requested tenant. Serve the page through an authenticated handler and prevent
158
+ shared caching of its contents.
159
+
160
+ Each successful page contains zero or more newline-terminated JSON objects as
161
+ `application/x-ndjson`. Each object includes the position, exact UTC timestamp,
162
+ actor kind and ID, user ID, request ID, table, operation, and changed column
163
+ names. Row keys, row images, actor reasons, and client fields stay in storage.
164
+
165
+ `pageSize` defaults to 100 and accepts integers from 1 to 500. Pages run newest
166
+ first by timestamp and position. Resume with the same tenant and pass
167
+ `nextCursor` as `olderThan`. The next page starts strictly before that cursor.
168
+ A `null` cursor means the query found no further rows, and an empty page has an
169
+ empty body. Pages are independent reads of the live log. Writes or deletes
170
+ between requests can change the remaining results.
171
+
172
+ ## What it refuses to do
173
+
174
+ Audit records describe supplied mutations and actors. Application policies decide which records each caller may see.
175
+
176
+ ## Contract
177
+
178
+ The trigger records identity columns and before and after row images as JSON
179
+ objects. Request and diagnostic context follows the client context contract.
180
+ Captured client hint headers are stored as string values. The reader returns
181
+ the newest rows first. Pass the last row's cursor to continue paging.
182
+
183
+ ### Install in an API
184
+
185
+ `createAuditPlugin` declares the audit migrations, exclusions, and scope columns.
186
+ Provide a database, clock, and logger through `auditDepsService`. Include
187
+ `audit.audit` in the API services to read `auditService`. List `audit.routes`
188
+ under routes to accept client diagnostics, and list `audit.jobs` under jobs
189
+ on the host that runs retention. All three selections share one set of
190
+ services per API.
191
+
192
+ Pass `api.migrationSources(root)` to the migration workspace. The package
193
+ ships its TypeScript baseline migration with a stable journal name and checksum.
194
+ Use those sources once per migration workspace. For applications calling
195
+ `installAuditSchemaV1` in their own bootstrap migration, that bootstrap owns
196
+ the audit schema and the same workspace does not list the audit plugin source.
197
+ An application migration can use `configurePluginAuditTriggers` from
198
+ `@dads-framework/audit/schema` with the composed audit policy and table keys.
199
+ Keep the policy referenced by an applied migration stable.