@pithy-sh/audit 0.5.0 → 0.6.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.
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,0CAA0C,CAAC;AAG7F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAWzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW;;;iBAc8B,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE3D,8EAA8E;AAC9E,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,gFAAgF;IAChF,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,MAAM,GAAE,gBAAqB,GAAG,eAAe,CAgFpE;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,eAAe,CAEvF"}
|
package/dist/capability.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: FSL-1.1-MIT
|
|
3
|
-
import { auditTables } from "./data/tables.js";
|
|
3
|
+
import { auditDatabase, auditTables } from "./data/tables.js";
|
|
4
4
|
import { auditAdminRoutes } from "./http/guards.js";
|
|
5
5
|
import { registerAuditRoutes } from "./http/routes.js";
|
|
6
6
|
import { audit_0001_init } from "./migrations/0001_init.js";
|
|
@@ -9,6 +9,7 @@ import { recordAuditEvent } from "./recorder.js";
|
|
|
9
9
|
import { auditExampleSeed } from "./seeds/example.js";
|
|
10
10
|
import { PACKAGE_NAME, PACKAGE_VERSION } from "./version.generated.js";
|
|
11
11
|
import { defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
12
|
+
import { createWorkerLogger } from "@pithy-sh/core/src/logger/worker";
|
|
12
13
|
import { workerIdentity } from "@pithy-sh/core/src/worker/identity";
|
|
13
14
|
import { z } from "zod";
|
|
14
15
|
//#region src/capability.ts
|
|
@@ -68,6 +69,23 @@ function audit(config = {}) {
|
|
|
68
69
|
}
|
|
69
70
|
} },
|
|
70
71
|
seeds: [auditExampleSeed],
|
|
72
|
+
auditRecorder: (env) => {
|
|
73
|
+
const log = createWorkerLogger({ name: "audit" });
|
|
74
|
+
const binding = env[resolved.database];
|
|
75
|
+
return async (event) => {
|
|
76
|
+
if (typeof binding !== "object" || binding === null) {
|
|
77
|
+
log.error("audit event dropped", {
|
|
78
|
+
reason: `no ${resolved.database} binding`,
|
|
79
|
+
action: event.action
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await recordAuditEvent(auditDatabase(binding), event, {
|
|
84
|
+
origin: workerIdentity(env),
|
|
85
|
+
onError: (error) => log.error("audit event dropped", { error })
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
},
|
|
71
89
|
adminRoutes: auditAdminRoutes(resolved.basePath),
|
|
72
90
|
routes: registerAuditRoutes({
|
|
73
91
|
basePath: resolved.basePath,
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
/** This package's npm name — the join key against a release feed. */
|
|
4
4
|
export declare const PACKAGE_NAME = "@pithy-sh/audit";
|
|
5
5
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
6
|
-
export declare const PACKAGE_VERSION = "0.
|
|
6
|
+
export declare const PACKAGE_VERSION = "0.6.0";
|
|
7
7
|
//# sourceMappingURL=version.generated.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
/** This package's npm name — the join key against a release feed. */
|
|
5
5
|
const PACKAGE_NAME = "@pithy-sh/audit";
|
|
6
6
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
7
|
-
const PACKAGE_VERSION = "0.
|
|
7
|
+
const PACKAGE_VERSION = "0.6.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PACKAGE_NAME, PACKAGE_VERSION };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/audit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "FSL-1.1-MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@hono/zod-validator": "^0.9.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@pithy-sh/core": "^0.
|
|
41
|
+
"@pithy-sh/core": "^0.13.0",
|
|
42
42
|
"hono": "^4.13.2",
|
|
43
43
|
"kysely": "^0.29.0",
|
|
44
44
|
"zod": "^4.4.0"
|
package/src/capability.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: FSL-1.1-MIT
|
|
3
3
|
|
|
4
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
5
|
import type { AuditEventInput } from "@pithy-sh/core/src/audit/auditEvent";
|
|
5
6
|
import { type Capability, defineCapability } from "@pithy-sh/core/src/capability/capability";
|
|
7
|
+
import { createWorkerLogger } from "@pithy-sh/core/src/logger/worker";
|
|
6
8
|
import { workerIdentity } from "@pithy-sh/core/src/worker/identity";
|
|
7
9
|
import { z } from "zod";
|
|
8
10
|
import type { AuditDatabase } from "./data/tables";
|
|
9
|
-
import { auditTables } from "./data/tables";
|
|
11
|
+
import { auditDatabase, auditTables } from "./data/tables";
|
|
10
12
|
import { auditAdminRoutes } from "./http/guards";
|
|
11
13
|
import { registerAuditRoutes } from "./http/routes";
|
|
12
14
|
import { audit_0001_init } from "./migrations/0001_init";
|
|
@@ -93,6 +95,24 @@ export function audit(config: AuditConfigInput = {}): AuditCapability {
|
|
|
93
95
|
},
|
|
94
96
|
},
|
|
95
97
|
seeds: [auditExampleSeed],
|
|
98
|
+
// The same recorder for code with no request — a Workflow step, which has `env` and nothing else (#622).
|
|
99
|
+
// Built over the binding this config names, stamped with the env's own origin, and non-fatal on the same
|
|
100
|
+
// terms as the middleware's: a missing binding or a failed insert drops the event and logs it, and the
|
|
101
|
+
// step it records stands. Found by core's `composedAuditEmit`, so the step imports nothing from here.
|
|
102
|
+
auditRecorder: (env) => {
|
|
103
|
+
const log = createWorkerLogger({ name: "audit" });
|
|
104
|
+
const binding = env[resolved.database];
|
|
105
|
+
return async (event: AuditEventInput) => {
|
|
106
|
+
if (typeof binding !== "object" || binding === null) {
|
|
107
|
+
log.error("audit event dropped", { reason: `no ${resolved.database} binding`, action: event.action });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await recordAuditEvent(auditDatabase(binding as D1Database), event, {
|
|
111
|
+
origin: workerIdentity(env),
|
|
112
|
+
onError: (error) => log.error("audit event dropped", { error }),
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
},
|
|
96
116
|
// Built from the resolved `basePath`, never the default: an adopter who mounts this at `/trail`
|
|
97
117
|
// gets a manifest naming their paths, where a client assuming the default would 404.
|
|
98
118
|
adminRoutes: auditAdminRoutes(resolved.basePath),
|
package/src/version.generated.ts
CHANGED