@pithy-sh/audit 0.5.0 → 0.7.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 (183) hide show
  1. package/README.md +93 -0
  2. package/dist/accessHistory.d.ts +315 -0
  3. package/dist/accessHistory.d.ts.map +1 -0
  4. package/dist/accessHistory.js +299 -0
  5. package/dist/actions.d.ts +15 -1
  6. package/dist/actions.d.ts.map +1 -1
  7. package/dist/actions.js +16 -2
  8. package/dist/capability.d.ts +14 -0
  9. package/dist/capability.d.ts.map +1 -1
  10. package/dist/capability.js +124 -12
  11. package/dist/chain/append.d.ts +43 -0
  12. package/dist/chain/append.d.ts.map +1 -0
  13. package/dist/chain/append.js +110 -0
  14. package/dist/chain/checkpoint.d.ts +70 -0
  15. package/dist/chain/checkpoint.d.ts.map +1 -0
  16. package/dist/chain/checkpoint.js +133 -0
  17. package/dist/chain/lockCheck.d.ts +15 -0
  18. package/dist/chain/lockCheck.d.ts.map +1 -0
  19. package/dist/chain/lockCheck.js +75 -0
  20. package/dist/chain/prune.d.ts +84 -0
  21. package/dist/chain/prune.d.ts.map +1 -0
  22. package/dist/chain/prune.js +231 -0
  23. package/dist/chain/rows.d.ts +74 -0
  24. package/dist/chain/rows.d.ts.map +1 -0
  25. package/dist/chain/rows.js +133 -0
  26. package/dist/chain/tombstone.d.ts +21 -0
  27. package/dist/chain/tombstone.d.ts.map +1 -0
  28. package/dist/chain/tombstone.js +98 -0
  29. package/dist/chain/verify.d.ts +63 -0
  30. package/dist/chain/verify.d.ts.map +1 -0
  31. package/dist/chain/verify.js +220 -0
  32. package/dist/citations.d.ts +17 -0
  33. package/dist/citations.d.ts.map +1 -0
  34. package/dist/citations.js +48 -0
  35. package/dist/cli/emitFromCLI.d.ts +5 -0
  36. package/dist/cli/emitFromCLI.d.ts.map +1 -1
  37. package/dist/cli/emitFromCLI.js +5 -0
  38. package/dist/data/auditEvent.d.ts +4 -0
  39. package/dist/data/auditEvent.d.ts.map +1 -1
  40. package/dist/data/auditEvent.js +7 -3
  41. package/dist/data/sinkState.d.ts +23 -0
  42. package/dist/data/sinkState.d.ts.map +1 -0
  43. package/dist/data/sinkState.js +25 -0
  44. package/dist/data/tables.d.ts +14 -1
  45. package/dist/data/tables.d.ts.map +1 -1
  46. package/dist/data/tables.js +5 -1
  47. package/dist/http/guards.d.ts +39 -6
  48. package/dist/http/guards.d.ts.map +1 -1
  49. package/dist/http/guards.js +101 -17
  50. package/dist/http/responses.d.ts +503 -0
  51. package/dist/http/responses.d.ts.map +1 -1
  52. package/dist/http/responses.js +157 -5
  53. package/dist/http/routes.d.ts +25 -3
  54. package/dist/http/routes.d.ts.map +1 -1
  55. package/dist/http/routes.js +321 -15
  56. package/dist/http/schemas.d.ts +67 -0
  57. package/dist/http/schemas.d.ts.map +1 -1
  58. package/dist/http/schemas.js +88 -4
  59. package/dist/http/views.d.ts +25 -1
  60. package/dist/http/views.d.ts.map +1 -1
  61. package/dist/http/views.js +107 -2
  62. package/dist/migrations/0003_call_index.d.ts +21 -0
  63. package/dist/migrations/0003_call_index.d.ts.map +1 -0
  64. package/dist/migrations/0003_call_index.js +33 -0
  65. package/dist/migrations/0004_request_index.d.ts +16 -0
  66. package/dist/migrations/0004_request_index.d.ts.map +1 -0
  67. package/dist/migrations/0004_request_index.js +24 -0
  68. package/dist/migrations/0005_chain.d.ts +24 -0
  69. package/dist/migrations/0005_chain.d.ts.map +1 -0
  70. package/dist/migrations/0005_chain.js +43 -0
  71. package/dist/migrations/0006_sinks.d.ts +11 -0
  72. package/dist/migrations/0006_sinks.d.ts.map +1 -0
  73. package/dist/migrations/0006_sinks.js +20 -0
  74. package/dist/provision/resolveAuditConfig.d.ts +31 -0
  75. package/dist/provision/resolveAuditConfig.d.ts.map +1 -0
  76. package/dist/provision/resolveAuditConfig.js +43 -0
  77. package/dist/purge/contribution.d.ts +21 -0
  78. package/dist/purge/contribution.d.ts.map +1 -0
  79. package/dist/purge/contribution.js +41 -0
  80. package/dist/reach.d.ts +250 -0
  81. package/dist/reach.d.ts.map +1 -0
  82. package/dist/reach.js +244 -0
  83. package/dist/recorder.d.ts +11 -0
  84. package/dist/recorder.d.ts.map +1 -1
  85. package/dist/recorder.js +23 -5
  86. package/dist/routePattern.d.ts +60 -0
  87. package/dist/routePattern.d.ts.map +1 -0
  88. package/dist/routePattern.js +130 -0
  89. package/dist/seeds/example.d.ts.map +1 -1
  90. package/dist/seeds/example.js +23 -6
  91. package/dist/ship/consumer.d.ts +45 -0
  92. package/dist/ship/consumer.d.ts.map +1 -0
  93. package/dist/ship/consumer.js +141 -0
  94. package/dist/ship/event.d.ts +59 -0
  95. package/dist/ship/event.d.ts.map +1 -0
  96. package/dist/ship/event.js +77 -0
  97. package/dist/ship/health.d.ts +33 -0
  98. package/dist/ship/health.d.ts.map +1 -0
  99. package/dist/ship/health.js +80 -0
  100. package/dist/ship/profiles.d.ts +34 -0
  101. package/dist/ship/profiles.d.ts.map +1 -0
  102. package/dist/ship/profiles.js +62 -0
  103. package/dist/ship/queue.d.ts +57 -0
  104. package/dist/ship/queue.d.ts.map +1 -0
  105. package/dist/ship/queue.js +70 -0
  106. package/dist/ship/secrets.d.ts +7 -0
  107. package/dist/ship/secrets.d.ts.map +1 -0
  108. package/dist/ship/secrets.js +40 -0
  109. package/dist/ship/shipper.d.ts +15 -0
  110. package/dist/ship/shipper.d.ts.map +1 -0
  111. package/dist/ship/shipper.js +27 -0
  112. package/dist/ship/sinks.d.ts +54 -0
  113. package/dist/ship/sinks.d.ts.map +1 -0
  114. package/dist/ship/sinks.js +45 -0
  115. package/dist/ship/state.d.ts +27 -0
  116. package/dist/ship/state.d.ts.map +1 -0
  117. package/dist/ship/state.js +29 -0
  118. package/dist/usage.d.ts +159 -0
  119. package/dist/usage.d.ts.map +1 -0
  120. package/dist/usage.js +87 -0
  121. package/dist/version.generated.d.ts +1 -1
  122. package/dist/version.generated.js +1 -1
  123. package/dist/workflows/prune.d.ts +73 -0
  124. package/dist/workflows/prune.d.ts.map +1 -0
  125. package/dist/workflows/prune.js +128 -0
  126. package/dist/workflows/retryPolicy.d.ts +10 -0
  127. package/dist/workflows/retryPolicy.d.ts.map +1 -0
  128. package/dist/workflows/retryPolicy.js +14 -0
  129. package/dist/workflows/specs.d.ts +70 -0
  130. package/dist/workflows/specs.d.ts.map +1 -0
  131. package/dist/workflows/specs.js +70 -0
  132. package/dist/workflows/worker.d.ts +32 -0
  133. package/dist/workflows/worker.d.ts.map +1 -0
  134. package/dist/workflows/worker.js +41 -0
  135. package/package.json +5 -2
  136. package/pithy.manifest.json +36 -4
  137. package/src/accessHistory.ts +360 -0
  138. package/src/actions.ts +15 -1
  139. package/src/capability.ts +154 -12
  140. package/src/chain/append.ts +161 -0
  141. package/src/chain/checkpoint.ts +172 -0
  142. package/src/chain/lockCheck.ts +72 -0
  143. package/src/chain/prune.ts +340 -0
  144. package/src/chain/rows.ts +211 -0
  145. package/src/chain/tombstone.ts +104 -0
  146. package/src/chain/verify.ts +366 -0
  147. package/src/citations.ts +62 -0
  148. package/src/cli/emitFromCLI.ts +5 -0
  149. package/src/cloudflare-test.d.ts +1 -0
  150. package/src/data/auditEvent.ts +31 -1
  151. package/src/data/sinkState.ts +41 -0
  152. package/src/data/tables.ts +7 -1
  153. package/src/http/guards.ts +90 -6
  154. package/src/http/responses.ts +318 -3
  155. package/src/http/routes.ts +379 -7
  156. package/src/http/schemas.ts +158 -2
  157. package/src/http/views.ts +123 -1
  158. package/src/migrations/0003_call_index.ts +35 -0
  159. package/src/migrations/0004_request_index.ts +26 -0
  160. package/src/migrations/0005_chain.ts +56 -0
  161. package/src/migrations/0006_sinks.ts +28 -0
  162. package/src/provision/resolveAuditConfig.ts +60 -0
  163. package/src/purge/contribution.ts +39 -0
  164. package/src/reach.ts +454 -0
  165. package/src/recorder.ts +64 -42
  166. package/src/routePattern.ts +141 -0
  167. package/src/seeds/example.ts +13 -0
  168. package/src/ship/consumer.ts +169 -0
  169. package/src/ship/event.ts +86 -0
  170. package/src/ship/health.ts +92 -0
  171. package/src/ship/profiles.ts +99 -0
  172. package/src/ship/queue.ts +108 -0
  173. package/src/ship/secrets.ts +42 -0
  174. package/src/ship/shipper.ts +32 -0
  175. package/src/ship/sinks.ts +82 -0
  176. package/src/ship/state.ts +61 -0
  177. package/src/usage.ts +176 -0
  178. package/src/version.generated.ts +1 -1
  179. package/src/workflows/prune.ts +196 -0
  180. package/src/workflows/retryPolicy.ts +14 -0
  181. package/src/workflows/specs.ts +92 -0
  182. package/src/workflows/worker.ts +65 -0
  183. package/src/workflows/wrangler.jsonc +40 -0
@@ -49,4 +49,71 @@ export declare const ListAuditEventsQuery: z.ZodObject<{
49
49
  limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
50
50
  }, z.core.$strip>;
51
51
  export type ListAuditEventsQuery = z.infer<typeof ListAuditEventsQuery>;
52
+ /**
53
+ * The access-history query: over what window, and where to resume.
54
+ *
55
+ * `since` is required, so an unbounded replay of the whole trail is a 400 before any query runs; `until` defaults to
56
+ * now in the handler, the one value a schema cannot compute for a request. A window that ends before it starts is
57
+ * refused rather than answered with nothing, because nothing would read as nobody's access having changed.
58
+ */
59
+ export declare const AccessHistoryQuery: z.ZodObject<{
60
+ since: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
61
+ until: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
62
+ cursor: z.ZodOptional<z.ZodString>;
63
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
64
+ }, z.core.$strip>;
65
+ export type AccessHistoryQuery = z.infer<typeof AccessHistoryQuery>;
66
+ /**
67
+ * The reach query: whose calls to read, over what window, and whether to expand one route into its subjects.
68
+ *
69
+ * `connectionId` and `since` are required, so a missing one is a 400 before any query runs: an unbounded read over
70
+ * every credential is not a question this route answers. `until` defaults to now in the handler, which is the one
71
+ * value a schema cannot compute for a request. A window that ends before it starts is refused rather than answered
72
+ * with nothing, because nothing would read as a credential that reached nothing. `subjects=true` needs a `route`:
73
+ * the expansion is one route's subject list, never every route's.
74
+ */
75
+ export declare const ControlPlaneReachQuery: z.ZodObject<{
76
+ connectionId: z.ZodString;
77
+ keyId: z.ZodOptional<z.ZodString>;
78
+ since: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
79
+ until: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
80
+ route: z.ZodOptional<z.ZodString>;
81
+ subjects: z.ZodOptional<z.ZodEnum<{
82
+ false: "false";
83
+ true: "true";
84
+ }>>;
85
+ }, z.core.$strip>;
86
+ export type ControlPlaneReachQuery = z.infer<typeof ControlPlaneReachQuery>;
87
+ /**
88
+ * The usage query: whose calls to count, and over what window.
89
+ *
90
+ * `connectionId` and `since` are required, so a missing one is a 400 before any query runs — an unbounded window over
91
+ * every connection is not a question this route answers. `until` defaults to now in the handler, which is the one
92
+ * value a schema cannot compute for a request. A window that ends before it starts is refused rather than answered
93
+ * with nothing, because nothing would read as an idle connection.
94
+ */
95
+ export declare const ControlPlaneUsageQuery: z.ZodObject<{
96
+ connectionId: z.ZodString;
97
+ since: z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>;
98
+ until: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
99
+ }, z.core.$strip>;
100
+ export type ControlPlaneUsageQuery = z.infer<typeof ControlPlaneUsageQuery>;
101
+ /** The chain verify query: whose chain, and over what window. */
102
+ export declare const ChainVerifyQuery: z.ZodObject<{
103
+ tenant: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodLiteral<"">, z.ZodTransform<null, "">>]>;
104
+ since: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
105
+ until: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
106
+ }, z.core.$strip>;
107
+ export type ChainVerifyQuery = z.infer<typeof ChainVerifyQuery>;
108
+ /** The most events one export page carries. */
109
+ export declare const MAX_EXPORT_PAGE = 1000;
110
+ /** The chain export query: whose chain, over what window, and where to resume. */
111
+ export declare const ChainExportQuery: z.ZodObject<{
112
+ tenant: z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodLiteral<"">, z.ZodTransform<null, "">>]>;
113
+ since: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
114
+ until: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<Date, string>>>;
115
+ cursor: z.ZodOptional<z.ZodString>;
116
+ limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
117
+ }, z.core.$strip>;
118
+ export type ChainExportQuery = z.infer<typeof ChainExportQuery>;
52
119
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/http/schemas.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+CxB,kCAAkC;AAClC,eAAO,MAAM,iBAAiB;;iBAS+B,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCiE,CAAC;AACnG,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/http/schemas.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+CxB,kCAAkC;AAClC,eAAO,MAAM,iBAAiB;;iBAS+B,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyCiE,CAAC;AACnG,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;iBAqBiE,CAAC;AACjG,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAKpE;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;iBA4B2E,CAAC;AAC/G,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB;;;;iBAYyC,CAAC;AAC7E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAU5E,iEAAiE;AACjE,eAAO,MAAM,gBAAgB;;;;iBAc4C,CAAC;AAC1E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,+CAA+C;AAC/C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,kFAAkF;AAClF,eAAO,MAAM,gBAAgB;;;;;;iBA0B8D,CAAC;AAC5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
@@ -1,12 +1,12 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: FSL-1.1-MIT
3
3
  import { AuditAction, AuditActorType, AuditOutcome, AuditSeverity } from "@pithy-sh/core/src/audit/auditEvent";
4
- import { z } from "zod";
5
4
  import { ControlPlaneActorKind } from "@pithy-sh/core/src/controlPlane/data/connection";
6
5
  import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
6
+ import { z } from "zod";
7
7
  //#region src/http/schemas.ts
8
8
  /**
9
- * The request contracts audit's two routes declare (CLAUDE.md §HTTP).
9
+ * The request contracts audit's routes declare (CLAUDE.md §HTTP).
10
10
  *
11
11
  * Every one of these is a **bound on something a caller chose**, which is the whole job here: a
12
12
  * control-plane credential is verified, but verified is not trusted, and a management client with a
@@ -53,7 +53,7 @@ const AuditEventIdParam = z.object({ eventId: z.string().uuid().describe("The ev
53
53
  const ListAuditEventsQuery = z.object({
54
54
  actorType: AuditActorType.optional().describe("Filter to one kind of principal. `control-plane` is the one that separates a management client's own actions from the adopter's users'."),
55
55
  actorId: FilterValue.optional().describe("Filter to one principal — a user id, a service name, a token subject."),
56
- actorKind: ControlPlaneActorKind.optional().describe("Filter to one kind of management client: `agent`, `dashboard` or `script`. What `actorType=control-plane` cannot say on its own."),
56
+ actorKind: ControlPlaneActorKind.optional().describe("Filter to one kind of client: `agent`, `dashboard` or `script`. `agent` finds a management agent's rows and every row a user's MCP client wrote, on both paths."),
57
57
  action: AuditAction.max(MAX_FILTER_LENGTH).optional().describe("Filter to one exact `domain/reason` action code. Exact, never a prefix — the taxonomy is federated."),
58
58
  outcome: AuditOutcome.optional().describe("Filter to one outcome. `denied` is the one worth watching: a run of denials is what a credential being probed looks like."),
59
59
  severity: AuditSeverity.optional().describe("Filter to one severity."),
@@ -68,5 +68,89 @@ const ListAuditEventsQuery = z.object({
68
68
  cursor: z.string().max(512).optional().describe("Where to resume, from the previous page's `nextCursor`. Opaque; a malformed one is a first page."),
69
69
  limit: z.coerce.number().int().min(1).max(MAX_PAGE_SIZE).optional().describe("How many events to return. Bounded, because a verified client can still have a bug.")
70
70
  }).describe("The audit trail query: what to filter the trail by, and where to resume reading it.");
71
+ /**
72
+ * The access-history query: over what window, and where to resume.
73
+ *
74
+ * `since` is required, so an unbounded replay of the whole trail is a 400 before any query runs; `until` defaults to
75
+ * now in the handler, the one value a schema cannot compute for a request. A window that ends before it starts is
76
+ * refused rather than answered with nothing, because nothing would read as nobody's access having changed.
77
+ */
78
+ const AccessHistoryQuery = z.object({
79
+ since: TimeBound.describe("Inclusive lower bound on when a change happened, ISO-8601. Required."),
80
+ until: TimeBound.optional().describe("Inclusive upper bound on when a change happened, ISO-8601. Defaults to now."),
81
+ cursor: z.string().max(512).optional().describe("Where to resume, from the previous page's `nextCursor`. Opaque; a malformed one is a first page."),
82
+ limit: z.coerce.number().int().min(1).max(MAX_PAGE_SIZE).optional().describe("How many changes to return. Bounded, because a verified client can still have a bug.")
83
+ }).refine((query) => query.until === void 0 || query.until.getTime() >= query.since.getTime(), {
84
+ message: "`until` must not be before `since`.",
85
+ path: ["until"]
86
+ }).describe("The access-history query: a window, oldest first, and where to resume reading it.");
87
+ /** A declared route pattern or a called path, as the reach answer names it. */
88
+ const RouteValue = z.string().min(1).max(512).startsWith("/");
89
+ /**
90
+ * The reach query: whose calls to read, over what window, and whether to expand one route into its subjects.
91
+ *
92
+ * `connectionId` and `since` are required, so a missing one is a 400 before any query runs: an unbounded read over
93
+ * every credential is not a question this route answers. `until` defaults to now in the handler, which is the one
94
+ * value a schema cannot compute for a request. A window that ends before it starts is refused rather than answered
95
+ * with nothing, because nothing would read as a credential that reached nothing. `subjects=true` needs a `route`:
96
+ * the expansion is one route's subject list, never every route's.
97
+ */
98
+ const ControlPlaneReachQuery = z.object({
99
+ connectionId: FilterValue.describe("The control-plane connection whose reach to read — the `resourceId` its call rows carry. Required."),
100
+ keyId: FilterValue.optional().describe("Narrow to the calls one registered key signed. The leaked-key question: omit it for the whole connection."),
101
+ since: TimeBound.describe("Inclusive lower bound on when a call landed, ISO-8601. Required."),
102
+ until: TimeBound.optional().describe("Inclusive upper bound on when a call landed, ISO-8601. Defaults to now."),
103
+ route: RouteValue.optional().describe("Narrow to one route: a declared pattern such as `/admin/users/:userId`, or the called path of an unmatched row."),
104
+ subjects: z.enum(["true", "false"]).optional().describe("`true` expands `route` into the paths it was called with and the subject ids they name. Needs `route`.")
105
+ }).refine((query) => query.until === void 0 || query.until.getTime() >= query.since.getTime(), {
106
+ message: "`until` must not be before `since`.",
107
+ path: ["until"]
108
+ }).refine((query) => query.subjects !== "true" || query.route !== void 0, {
109
+ message: "`subjects=true` needs a `route` to expand.",
110
+ path: ["route"]
111
+ }).describe("The control-plane reach query: one connection, over a window, optionally one key and one route.");
112
+ /**
113
+ * The usage query: whose calls to count, and over what window.
114
+ *
115
+ * `connectionId` and `since` are required, so a missing one is a 400 before any query runs — an unbounded window over
116
+ * every connection is not a question this route answers. `until` defaults to now in the handler, which is the one
117
+ * value a schema cannot compute for a request. A window that ends before it starts is refused rather than answered
118
+ * with nothing, because nothing would read as an idle connection.
119
+ */
120
+ const ControlPlaneUsageQuery = z.object({
121
+ connectionId: FilterValue.describe("The control-plane connection whose calls to count — the `resourceId` its call rows carry. Required."),
122
+ since: TimeBound.describe("Inclusive lower bound on when a call landed, ISO-8601. Required."),
123
+ until: TimeBound.optional().describe("Inclusive upper bound on when a call landed, ISO-8601. Defaults to now.")
124
+ }).refine((query) => query.until === void 0 || query.until.getTime() >= query.since.getTime(), {
125
+ message: "`until` must not be before `since`.",
126
+ path: ["until"]
127
+ }).describe("The control-plane usage query: one connection, over a window.");
128
+ /**
129
+ * The tenant whose chain to read. **Required**, because there is no "every chain": a chain is one tenant's.
130
+ * Send it empty (`?tenant=`) for the untenanted chain — the same encoding the listing's filter uses.
131
+ */
132
+ const ChainTenant = TenantFilter.describe("The tenant whose chain to read. Send it empty (`?tenant=`) for the chain of events that belong to no tenant. Required: a chain is one tenant's.");
133
+ /** The chain verify query: whose chain, and over what window. */
134
+ const ChainVerifyQuery = z.object({
135
+ tenant: ChainTenant,
136
+ since: TimeBound.optional().describe("Inclusive start of the window, ISO-8601. Omitted, the walk starts at the chain's first event."),
137
+ until: TimeBound.optional().describe("Inclusive end of the window, ISO-8601. Omitted, the walk runs to the chain's head, and a checkpoint past it is a truncation.")
138
+ }).refine((query) => query.until === void 0 || query.since === void 0 || query.until >= query.since, {
139
+ message: "`until` must not be before `since`.",
140
+ path: ["until"]
141
+ }).describe("The chain verify query: one tenant's chain, over a window.");
142
+ /** The most events one export page carries. */
143
+ const MAX_EXPORT_PAGE = 1e3;
144
+ /** The chain export query: whose chain, over what window, and where to resume. */
145
+ const ChainExportQuery = z.object({
146
+ tenant: ChainTenant,
147
+ since: TimeBound.optional().describe("Inclusive start of the window, ISO-8601. Omitted, the export starts at the chain's first event."),
148
+ until: TimeBound.optional().describe("Inclusive end of the window, ISO-8601. Omitted, the export runs to the chain's head."),
149
+ cursor: z.string().max(32).optional().describe("Where to resume, from the previous page's `nextCursor`. A malformed one is a first page."),
150
+ limit: z.coerce.number().int().min(1).max(MAX_EXPORT_PAGE).optional().describe(`How many events one page carries. At most ${MAX_EXPORT_PAGE}; defaults to 500.`)
151
+ }).refine((query) => query.until === void 0 || query.since === void 0 || query.until >= query.since, {
152
+ message: "`until` must not be before `since`.",
153
+ path: ["until"]
154
+ }).describe("The chain export query: one tenant's chain, over a window, a page at a time.");
71
155
  //#endregion
72
- export { AuditEventIdParam, ListAuditEventsQuery };
156
+ export { AccessHistoryQuery, AuditEventIdParam, ChainExportQuery, ChainVerifyQuery, ControlPlaneReachQuery, ControlPlaneUsageQuery, ListAuditEventsQuery, MAX_EXPORT_PAGE };
@@ -1,7 +1,10 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { AccessHistoryRow } from "../accessHistory";
3
4
  import type { AuditEventRow } from "../data/auditEvent";
4
- import type { AuditEventDetailView, AuditEventView } from "./responses";
5
+ import type { ControlPlaneReachRow, ControlPlaneReachSubjectRow } from "../reach";
6
+ import type { ControlPlaneUsageRow } from "../usage";
7
+ import type { AccessChangeView, AuditEventDetailView, AuditEventView, ControlPlaneReachSubjectView, ControlPlaneReachView, ControlPlaneUsageView } from "./responses";
5
8
  /**
6
9
  * What a management client is shown of an audit event — decided here, once, rather than by whichever
7
10
  * columns a query happened to select.
@@ -52,4 +55,25 @@ import type { AuditEventDetailView, AuditEventView } from "./responses";
52
55
  export declare function auditEventView(row: AuditEventRow): AuditEventView;
53
56
  /** Project one row for the single-event read, network identifiers and metadata included. */
54
57
  export declare function auditEventDetailView(row: AuditEventRow): AuditEventDetailView;
58
+ /**
59
+ * Project one access change (#831) into the wire union, by what changed.
60
+ *
61
+ * The statement already read nothing but the named metadata keys, so this drops nothing personal; what it does is
62
+ * keep each subject's fields to that subject, so a member change never carries a null `scopesBefore` a client could
63
+ * read as a connection that held nothing.
64
+ */
65
+ export declare function accessChangeView(row: AccessHistoryRow): AccessChangeView;
66
+ /**
67
+ * Project one reach row (#828). Field for field, with the instants as ISO-8601: the statement already read nothing
68
+ * but the scope, the key, the method and the path out of `metadata`, and the tenant out of the handler's events, so
69
+ * there is nothing here to drop.
70
+ */
71
+ export declare function controlPlaneReachView(row: ControlPlaneReachRow): ControlPlaneReachView;
72
+ /** Project one subject row (#828), field for field, the same way — never a spread a new field would ride out on. */
73
+ export declare function controlPlaneReachSubjectView(row: ControlPlaneReachSubjectRow): ControlPlaneReachSubjectView;
74
+ /**
75
+ * Project one usage row (#812). Field for field, with the instants as ISO-8601: the aggregate already read nothing but
76
+ * the scope, the key, and the last allowed call's method and path out of `metadata`, so there is nothing here to drop.
77
+ */
78
+ export declare function controlPlaneUsageView(row: ControlPlaneUsageRow): ControlPlaneUsageView;
55
79
  //# sourceMappingURL=views.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../src/http/views.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CA2BjE;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,aAAa,GAAG,oBAAoB,CAE7E"}
1
+ {"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../src/http/views.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,4BAA4B,EAC5B,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CA6BjE;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,aAAa,GAAG,oBAAoB,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,GAAG,gBAAgB,CA2CxE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,oBAAoB,GAAG,qBAAqB,CActF;AAED,oHAAoH;AACpH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,2BAA2B,GAAG,4BAA4B,CAgB3G;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,oBAAoB,GAAG,qBAAqB,CAWtF"}
@@ -1,5 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import { InternalError } from "@pithy-sh/core/src/error/pithyError";
3
4
  //#region src/http/views.ts
4
5
  /**
5
6
  * What a management client is shown of an audit event — decided here, once, rather than by whichever
@@ -66,7 +67,8 @@ function auditEventView(row) {
66
67
  environment: row.environment,
67
68
  worker: row.worker,
68
69
  version: row.version,
69
- tenant: row.tenant
70
+ tenant: row.tenant,
71
+ chainSeq: row.chainSeq
70
72
  };
71
73
  }
72
74
  /** Project one row for the single-event read, network identifiers and metadata included. */
@@ -78,5 +80,108 @@ function auditEventDetailView(row) {
78
80
  metadata: row.metadata
79
81
  };
80
82
  }
83
+ /**
84
+ * Project one access change (#831) into the wire union, by what changed.
85
+ *
86
+ * The statement already read nothing but the named metadata keys, so this drops nothing personal; what it does is
87
+ * keep each subject's fields to that subject, so a member change never carries a null `scopesBefore` a client could
88
+ * read as a connection that held nothing.
89
+ */
90
+ function accessChangeView(row) {
91
+ const base = {
92
+ eventId: row.eventId,
93
+ occurredAt: row.occurredAt.toISOString(),
94
+ action: row.action,
95
+ actorType: row.actorType,
96
+ actorId: row.actorId,
97
+ actorKind: row.actorKind,
98
+ detail: row.recorded ? "recorded" : "not_recorded"
99
+ };
100
+ if (row.subject === "member") return {
101
+ ...base,
102
+ subject: "member",
103
+ organizationId: row.organizationId,
104
+ membershipId: row.membershipId,
105
+ userId: row.userId,
106
+ roleBefore: row.roleBefore,
107
+ roleAfter: row.roleAfter
108
+ };
109
+ if (row.subject === "connection") return {
110
+ ...base,
111
+ subject: "connection",
112
+ connectionId: row.connectionId,
113
+ connectionKind: row.connectionKind,
114
+ purpose: row.purpose,
115
+ principal: row.principal,
116
+ scopesBefore: row.scopesBefore,
117
+ scopesAfter: row.scopesAfter,
118
+ replacedConnectionId: row.replacedConnectionId
119
+ };
120
+ if (row.keyChange === null) throw new InternalError({
121
+ message: "Audit could not read a key change.",
122
+ detail: `access-history row for event ${row.eventId} is a key change with no change recorded`
123
+ });
124
+ return {
125
+ ...base,
126
+ subject: "key",
127
+ connectionId: row.connectionId,
128
+ keyId: row.keyId,
129
+ change: row.keyChange
130
+ };
131
+ }
132
+ /**
133
+ * Project one reach row (#828). Field for field, with the instants as ISO-8601: the statement already read nothing
134
+ * but the scope, the key, the method and the path out of `metadata`, and the tenant out of the handler's events, so
135
+ * there is nothing here to drop.
136
+ */
137
+ function controlPlaneReachView(row) {
138
+ return {
139
+ tenant: row.tenant,
140
+ action: row.action,
141
+ method: row.method,
142
+ route: row.route,
143
+ matched: row.matched,
144
+ outcome: row.outcome,
145
+ scope: row.scope,
146
+ count: row.count,
147
+ subjects: row.subjects,
148
+ firstAt: row.firstAt.toISOString(),
149
+ lastAt: row.lastAt.toISOString()
150
+ };
151
+ }
152
+ /** Project one subject row (#828), field for field, the same way — never a spread a new field would ride out on. */
153
+ function controlPlaneReachSubjectView(row) {
154
+ return {
155
+ tenant: row.tenant,
156
+ action: row.action,
157
+ method: row.method,
158
+ route: row.route,
159
+ matched: row.matched,
160
+ path: row.path,
161
+ outcome: row.outcome,
162
+ scope: row.scope,
163
+ subjectId: row.subjectId,
164
+ params: { ...row.params },
165
+ count: row.count,
166
+ firstAt: row.firstAt.toISOString(),
167
+ lastAt: row.lastAt.toISOString()
168
+ };
169
+ }
170
+ /**
171
+ * Project one usage row (#812). Field for field, with the instants as ISO-8601: the aggregate already read nothing but
172
+ * the scope, the key, and the last allowed call's method and path out of `metadata`, so there is nothing here to drop.
173
+ */
174
+ function controlPlaneUsageView(row) {
175
+ return {
176
+ scope: row.scope,
177
+ keyId: row.keyId,
178
+ allowed: row.allowed,
179
+ denied: row.denied,
180
+ lastAllowedAt: row.lastAllowedAt?.toISOString() ?? null,
181
+ lastAllowedMethod: row.lastAllowedMethod,
182
+ lastAllowedPath: row.lastAllowedPath,
183
+ lastDeniedAt: row.lastDeniedAt?.toISOString() ?? null
184
+ };
185
+ }
81
186
  //#endregion
82
- export { auditEventDetailView, auditEventView };
187
+ export { accessChangeView, auditEventDetailView, auditEventView, controlPlaneReachSubjectView, controlPlaneReachView, controlPlaneUsageView };
@@ -0,0 +1,21 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { Migration } from "kysely/migration";
4
+ /**
5
+ * One connection's calls over a window — `#812`.
6
+ *
7
+ * `GET {audit}/control-plane/usage` reads the `controlplane/call_allowed` and `controlplane/call_denied` rows of one
8
+ * connection between two instants, and groups them by scope and key. None of 0001's indexes serves that:
9
+ * `pithyAuditEventsResourceIdx` finds the connection's rows but not by action or time, and `pithyAuditEventsActionIdx`
10
+ * finds every call of every connection. On the table a dashboard connection appends thousands of rows to a day, the
11
+ * difference is a range read against a scan.
12
+ *
13
+ * **In this column order, and it is the query's.** `action` first, because the read names two actions with `IN` and
14
+ * SQLite walks one range per value. `resourceId` second, an equality inside each. `occurredAt` last, so the window
15
+ * is a bounded range rather than a filter over every row the connection ever wrote. `resourceType` is left out: a
16
+ * connection id is a UUID, so `resourceId` is already selective, and the type is checked against the row it finds.
17
+ *
18
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
19
+ */
20
+ export declare const audit_0003_call_index: Migration;
21
+ //# sourceMappingURL=0003_call_index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0003_call_index.d.ts","sourceRoot":"","sources":["../../src/migrations/0003_call_index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAYnC,CAAC"}
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ //#region src/migrations/0003_call_index.ts
4
+ /**
5
+ * One connection's calls over a window — `#812`.
6
+ *
7
+ * `GET {audit}/control-plane/usage` reads the `controlplane/call_allowed` and `controlplane/call_denied` rows of one
8
+ * connection between two instants, and groups them by scope and key. None of 0001's indexes serves that:
9
+ * `pithyAuditEventsResourceIdx` finds the connection's rows but not by action or time, and `pithyAuditEventsActionIdx`
10
+ * finds every call of every connection. On the table a dashboard connection appends thousands of rows to a day, the
11
+ * difference is a range read against a scan.
12
+ *
13
+ * **In this column order, and it is the query's.** `action` first, because the read names two actions with `IN` and
14
+ * SQLite walks one range per value. `resourceId` second, an equality inside each. `occurredAt` last, so the window
15
+ * is a bounded range rather than a filter over every row the connection ever wrote. `resourceType` is left out: a
16
+ * connection id is a UUID, so `resourceId` is already selective, and the type is checked against the row it finds.
17
+ *
18
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
19
+ */
20
+ const audit_0003_call_index = {
21
+ up: async (db) => {
22
+ await db.schema.createIndex("pithyAuditEventsCallIdx").on("pithyAuditEvents").columns([
23
+ "action",
24
+ "resourceId",
25
+ "occurredAt"
26
+ ]).execute();
27
+ },
28
+ down: async (db) => {
29
+ await db.schema.dropIndex("pithyAuditEventsCallIdx").execute();
30
+ }
31
+ };
32
+ //#endregion
33
+ export { audit_0003_call_index };
@@ -0,0 +1,16 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { Migration } from "kysely/migration";
4
+ /**
5
+ * The events one request wrote — `#828`.
6
+ *
7
+ * `GET {audit}/control-plane/reach` answers whose data a credential reached, and the gate's own
8
+ * `controlplane/call_allowed` row cannot say: it is written before the handler runs, so before any tenant is
9
+ * resolved. The handler's events carry the tenant, and the request id (`cf-ray`) is what ties them to the call. The
10
+ * reach statement finds them by it, once per call in the window, so without this index every call is a scan of the
11
+ * trail.
12
+ *
13
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
14
+ */
15
+ export declare const audit_0004_request_index: Migration;
16
+ //# sourceMappingURL=0004_request_index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0004_request_index.d.ts","sourceRoot":"","sources":["../../src/migrations/0004_request_index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAQtC,CAAC"}
@@ -0,0 +1,24 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ //#region src/migrations/0004_request_index.ts
4
+ /**
5
+ * The events one request wrote — `#828`.
6
+ *
7
+ * `GET {audit}/control-plane/reach` answers whose data a credential reached, and the gate's own
8
+ * `controlplane/call_allowed` row cannot say: it is written before the handler runs, so before any tenant is
9
+ * resolved. The handler's events carry the tenant, and the request id (`cf-ray`) is what ties them to the call. The
10
+ * reach statement finds them by it, once per call in the window, so without this index every call is a scan of the
11
+ * trail.
12
+ *
13
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
14
+ */
15
+ const audit_0004_request_index = {
16
+ up: async (db) => {
17
+ await db.schema.createIndex("pithyAuditEventsRequestIdx").on("pithyAuditEvents").column("requestId").execute();
18
+ },
19
+ down: async (db) => {
20
+ await db.schema.dropIndex("pithyAuditEventsRequestIdx").execute();
21
+ }
22
+ };
23
+ //#endregion
24
+ export { audit_0004_request_index };
@@ -0,0 +1,24 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { Migration } from "kysely/migration";
4
+ /**
5
+ * The hash chain — `#822`.
6
+ *
7
+ * Four columns, every one nullable and none back-filled. `chainSeq` is an event's 1-based position in its tenant's
8
+ * chain, `chainPrev` the hash of the event before it, `chainHash` its own hash over the canonical serialization
9
+ * (`@pithy-sh/core/src/audit/chain`), and `chainSalt` the per-event salt its IP, user-agent and metadata are
10
+ * committed under.
11
+ *
12
+ * **A row written before this migration keeps all four null, and that is its mark: before the chain.** Asserting a
13
+ * chain over rows nobody checked when they were written would be a claim, not evidence, so nothing here computes
14
+ * one.
15
+ *
16
+ * **Two partial unique indexes, one per kind of chain.** The tenant column is nullable and SQLite treats nulls as
17
+ * distinct in a unique index, so one index on `(tenant, chainSeq)` would let the untenanted chain hold two events
18
+ * at one position. Splitting by `tenant is null` closes that, and gives the verify walk an index in chain order for
19
+ * either kind. The recorder's append is already one compare-and-set statement; these are the backstop under it.
20
+ *
21
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
22
+ */
23
+ export declare const audit_0005_chain: Migration;
24
+ //# sourceMappingURL=0005_chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0005_chain.d.ts","sourceRoot":"","sources":["../../src/migrations/0005_chain.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,EAAE,SA8B9B,CAAC"}
@@ -0,0 +1,43 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import { sql } from "kysely";
4
+ //#region src/migrations/0005_chain.ts
5
+ /**
6
+ * The hash chain — `#822`.
7
+ *
8
+ * Four columns, every one nullable and none back-filled. `chainSeq` is an event's 1-based position in its tenant's
9
+ * chain, `chainPrev` the hash of the event before it, `chainHash` its own hash over the canonical serialization
10
+ * (`@pithy-sh/core/src/audit/chain`), and `chainSalt` the per-event salt its IP, user-agent and metadata are
11
+ * committed under.
12
+ *
13
+ * **A row written before this migration keeps all four null, and that is its mark: before the chain.** Asserting a
14
+ * chain over rows nobody checked when they were written would be a claim, not evidence, so nothing here computes
15
+ * one.
16
+ *
17
+ * **Two partial unique indexes, one per kind of chain.** The tenant column is nullable and SQLite treats nulls as
18
+ * distinct in a unique index, so one index on `(tenant, chainSeq)` would let the untenanted chain hold two events
19
+ * at one position. Splitting by `tenant is null` closes that, and gives the verify walk an index in chain order for
20
+ * either kind. The recorder's append is already one compare-and-set statement; these are the backstop under it.
21
+ *
22
+ * **Appended, never folded into `0001`.** The audit capability has shipped, so its table is history.
23
+ */
24
+ const audit_0005_chain = {
25
+ up: async (db) => {
26
+ await db.schema.alterTable("pithyAuditEvents").addColumn("chainSeq", "integer").execute();
27
+ await db.schema.alterTable("pithyAuditEvents").addColumn("chainPrev", "text").execute();
28
+ await db.schema.alterTable("pithyAuditEvents").addColumn("chainHash", "text").execute();
29
+ await db.schema.alterTable("pithyAuditEvents").addColumn("chainSalt", "text").execute();
30
+ await db.schema.createIndex("pithyAuditEventsTenantChainIdx").on("pithyAuditEvents").columns(["tenant", "chainSeq"]).unique().where(sql.ref("tenant"), "is not", null).execute();
31
+ await db.schema.createIndex("pithyAuditEventsUntenantedChainIdx").on("pithyAuditEvents").column("chainSeq").unique().where(sql.ref("tenant"), "is", null).execute();
32
+ },
33
+ down: async (db) => {
34
+ await db.schema.dropIndex("pithyAuditEventsUntenantedChainIdx").execute();
35
+ await db.schema.dropIndex("pithyAuditEventsTenantChainIdx").execute();
36
+ await db.schema.alterTable("pithyAuditEvents").dropColumn("chainSalt").execute();
37
+ await db.schema.alterTable("pithyAuditEvents").dropColumn("chainHash").execute();
38
+ await db.schema.alterTable("pithyAuditEvents").dropColumn("chainPrev").execute();
39
+ await db.schema.alterTable("pithyAuditEvents").dropColumn("chainSeq").execute();
40
+ }
41
+ };
42
+ //#endregion
43
+ export { audit_0005_chain };
@@ -0,0 +1,11 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { Migration } from "kysely/migration";
4
+ /**
5
+ * Shipping's delivery state — `#824`.
6
+ *
7
+ * One table, `pithy_audit_sinks`, one row per declared sink: what the manifest's health keys report. Nothing in it
8
+ * is the trail, and nothing in the trail changes. **Appended, never folded into `0001`**: audit has shipped.
9
+ */
10
+ export declare const audit_0006_sinks: Migration;
11
+ //# sourceMappingURL=0006_sinks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"0006_sinks.d.ts","sourceRoot":"","sources":["../../src/migrations/0006_sinks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAe9B,CAAC"}
@@ -0,0 +1,20 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import { sql } from "kysely";
4
+ //#region src/migrations/0006_sinks.ts
5
+ /**
6
+ * Shipping's delivery state — `#824`.
7
+ *
8
+ * One table, `pithy_audit_sinks`, one row per declared sink: what the manifest's health keys report. Nothing in it
9
+ * is the trail, and nothing in the trail changes. **Appended, never folded into `0001`**: audit has shipped.
10
+ */
11
+ const audit_0006_sinks = {
12
+ up: async (db) => {
13
+ await db.schema.createTable("pithyAuditSinks").addColumn("sink", "text", (col) => col.primaryKey()).addColumn("lastDeliveredAt", "integer").addColumn("lastFailedAt", "integer").addColumn("retrying", "integer", (col) => col.notNull().defaultTo(sql`0`)).addColumn("deadLettered", "integer", (col) => col.notNull().defaultTo(sql`0`)).execute();
14
+ },
15
+ down: async (db) => {
16
+ await db.schema.dropTable("pithyAuditSinks").execute();
17
+ }
18
+ };
19
+ //#endregion
20
+ export { audit_0006_sinks };
@@ -0,0 +1,31 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: FSL-1.1-MIT
3
+ import type { FeatureIdentity } from "@pithy-sh/core/src/naming/feature";
4
+ import { type WorkflowHostTemplate } from "@pithy-sh/core/src/workflow/host";
5
+ /**
6
+ * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config
7
+ * (#822). Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
8
+ * bucket it writes, and the Workflow names derived from audit's own specs.
9
+ */
10
+ /**
11
+ * The checkpoint bucket's name in a declared environment — **the name `pithy provision` gives the
12
+ * `AUDIT_CHECKPOINTS` binding**, read through the very function it composes it with, so the host and the app
13
+ * Worker cannot bind two different buckets.
14
+ */
15
+ export declare function auditCheckpointBucketName(project: string, env: string): string;
16
+ /** The resolved resource ids and names for one environment's checkpoint host. */
17
+ export interface AuditConfigParams {
18
+ /** The project name, from `requireProjectName` and never guessed. */
19
+ project: string;
20
+ /** The target environment. */
21
+ env: string;
22
+ /** The feature this host serves, when it serves one (#643). */
23
+ feature?: FeatureIdentity;
24
+ /** The audit database's id — the D1 behind the binding `audit({ database })` names. */
25
+ auditDatabaseId: string;
26
+ /** The checkpoint bucket's name. */
27
+ bucketName: string;
28
+ }
29
+ /** Fill the template for one environment. */
30
+ export declare function resolveAuditConfig(template: WorkflowHostTemplate, params: AuditConfigParams): WorkflowHostTemplate;
31
+ //# sourceMappingURL=resolveAuditConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveAuditConfig.d.ts","sourceRoot":"","sources":["../../src/provision/resolveAuditConfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAyC,KAAK,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAIpH;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,uFAAuF;IACvF,eAAe,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,CAoBlH"}