@pithy-sh/audit 0.9.1 → 0.9.3

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/actions.d.ts CHANGED
@@ -2,18 +2,18 @@
2
2
  // SPDX-License-Identifier: FSL-1.1-MIT
3
3
  /**
4
4
  * Author a capability's action constants. The taxonomy is **federated**: each capability owns and
5
- * exports its own `domain/reason` action codes (`auth/login`, `entitlement/granted`) and adds them
5
+ * exports its own `domain/reason` action codes (`auth/signin`, `entitlement/granted`) and adds them
6
6
  * without touching core — the way migrations and table prefixes already federate per-capability.
7
7
  *
8
8
  * This validates every code against the shared {@link AuditAction} shape at author time, so a typo
9
9
  * (a missing slash, an uppercase letter) fails loudly where the constant is declared rather than
10
10
  * silently when an event is emitted. Returns the same object, typed, so call sites read
11
- * `AuthAuditActions.login`:
11
+ * `AuthAuditActions.signin`:
12
12
  *
13
13
  * ```ts
14
14
  * export const AuthAuditActions = defineAuditActions({
15
- * login: "auth/login",
16
- * tokenRefreshed: "auth/token_refreshed",
15
+ * signin: "auth/signin",
16
+ * tokenRefresh: "auth/token_refresh",
17
17
  * });
18
18
  * ```
19
19
  */
package/dist/actions.js CHANGED
@@ -5,18 +5,18 @@ import { AuditAction } from "@pithy-sh/core/src/audit/auditEvent";
5
5
  //#region src/actions.ts
6
6
  /**
7
7
  * Author a capability's action constants. The taxonomy is **federated**: each capability owns and
8
- * exports its own `domain/reason` action codes (`auth/login`, `entitlement/granted`) and adds them
8
+ * exports its own `domain/reason` action codes (`auth/signin`, `entitlement/granted`) and adds them
9
9
  * without touching core — the way migrations and table prefixes already federate per-capability.
10
10
  *
11
11
  * This validates every code against the shared {@link AuditAction} shape at author time, so a typo
12
12
  * (a missing slash, an uppercase letter) fails loudly where the constant is declared rather than
13
13
  * silently when an event is emitted. Returns the same object, typed, so call sites read
14
- * `AuthAuditActions.login`:
14
+ * `AuthAuditActions.signin`:
15
15
  *
16
16
  * ```ts
17
17
  * export const AuthAuditActions = defineAuditActions({
18
- * login: "auth/login",
19
- * tokenRefreshed: "auth/token_refreshed",
18
+ * signin: "auth/signin",
19
+ * tokenRefresh: "auth/token_refresh",
20
20
  * });
21
21
  * ```
22
22
  */
@@ -25,7 +25,7 @@ function defineAuditActions(actions) {
25
25
  const parsed = AuditAction.safeParse(code);
26
26
  if (!parsed.success) throw new AuditInvalidEventError({
27
27
  message: `Invalid audit action code for "${name}": ${code}`,
28
- action: "Use a lowercase namespaced `domain/reason` code, e.g. `auth/login`.",
28
+ action: "Use a lowercase namespaced `domain/reason` code, e.g. `auth/signin`.",
29
29
  detail: parsed.error.message
30
30
  });
31
31
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: FSL-1.1-MIT
3
3
  import { type CapabilitySettings } from "@pithy-sh/core/src/capability/settings";
4
4
  /**
5
- * **`pithy doctor`'s line on the checkpoint bucket's object lock (#822).**
5
+ * **`pithy doctor`'s line on the checkpoint bucket's object lock.**
6
6
  *
7
7
  * A checkpoint is evidence only while nothing can replace it. The Worker cannot tell through its binding whether
8
8
  * the bucket is locked, so doctor asks the account, per deployed environment: a bucket with no indefinite lock over
@@ -10,6 +10,9 @@ import { type CapabilitySettings } from "@pithy-sh/core/src/capability/settings"
10
10
  * database to be held to. A bucket that is locked says nothing, which is doctor's way of saying it is in force.
11
11
  *
12
12
  * `dev` is never asked: a developer's checkpoints are a local Miniflare bucket, and no lock means anything there.
13
+ *
14
+ * A Worker that owns `AUDIT_CHECKPOINTS` checkpoints into a bucket of its own, so that bucket is the one asked, and
15
+ * the lock it names is `--worker`'s.
13
16
  */
14
17
  export declare function checkpointLockCheck(): CapabilitySettings;
15
18
  //# sourceMappingURL=lockCheck.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lockCheck.d.ts","sourceRoot":"","sources":["../../src/chain/lockCheck.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,wCAAwC,CAAC;AAOhD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,kBAAkB,CA8CxD"}
1
+ {"version":3,"file":"lockCheck.d.ts","sourceRoot":"","sources":["../../src/chain/lockCheck.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,wCAAwC,CAAC;AAOhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,IAAI,kBAAkB,CAiDxD"}
@@ -8,7 +8,7 @@ import { remedy } from "@pithy-sh/core/src/cli/command";
8
8
  import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
9
9
  //#region src/chain/lockCheck.ts
10
10
  /**
11
- * **`pithy doctor`'s line on the checkpoint bucket's object lock (#822).**
11
+ * **`pithy doctor`'s line on the checkpoint bucket's object lock.**
12
12
  *
13
13
  * A checkpoint is evidence only while nothing can replace it. The Worker cannot tell through its binding whether
14
14
  * the bucket is locked, so doctor asks the account, per deployed environment: a bucket with no indefinite lock over
@@ -16,6 +16,9 @@ import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
16
16
  * database to be held to. A bucket that is locked says nothing, which is doctor's way of saying it is in force.
17
17
  *
18
18
  * `dev` is never asked: a developer's checkpoints are a local Miniflare bucket, and no lock means anything there.
19
+ *
20
+ * A Worker that owns `AUDIT_CHECKPOINTS` checkpoints into a bucket of its own, so that bucket is the one asked, and
21
+ * the lock it names is `--worker`'s.
19
22
  */
20
23
  function checkpointLockCheck() {
21
24
  return {
@@ -23,9 +26,10 @@ function checkpointLockCheck() {
23
26
  async account(context) {
24
27
  const findings = [];
25
28
  const unanswered = [];
29
+ const owner = context.ownBindings?.includes("AUDIT_CHECKPOINTS") ? context.workerDirectory : void 0;
26
30
  for (const { name: environment } of context.environments) {
27
31
  if (environment === LOCAL_ENVIRONMENT) continue;
28
- const bucket = auditCheckpointBucketName(context.project, environment);
32
+ const bucket = auditCheckpointBucketName(context.project, environment, owner);
29
33
  try {
30
34
  const ask = context.account.r2BucketLock;
31
35
  if (!ask) throw new InternalError({
@@ -51,7 +55,10 @@ function checkpointLockCheck() {
51
55
  });
52
56
  continue;
53
57
  }
54
- const lock = remedy("audit lock", { flags: { "--env": environment } });
58
+ const lock = remedy("audit lock", { flags: {
59
+ "--env": environment,
60
+ ...owner === void 0 ? {} : { "--worker": owner }
61
+ } });
55
62
  findings.push({
56
63
  setting: `${AUDIT_CHECKPOINT_BINDING} object lock`,
57
64
  environment,
@@ -55,7 +55,7 @@ const ListAuditEventsQuery = z.object({
55
55
  actorId: FilterValue.optional().describe("Filter to one principal — a user id, a service name, a token subject."),
56
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; `actionPrefix` is the domain-wide filter."),
58
- actionPrefix: z.string().regex(/^[a-z][a-z0-9]*\/?$/, "An action prefix is one domain, lowercase, with or without its trailing `/` (e.g. `auth` or `auth/`).").max(MAX_FILTER_LENGTH).transform((value) => value.replace(/\/$/, "")).optional().describe("Filter to every action under one domain — `auth` or `auth/` matches `auth/login` and `auth/logout`, never `authority/granted`. The domain is the only prefix: a reason is never matched by its start."),
58
+ actionPrefix: z.string().regex(/^[a-z][a-z0-9]*\/?$/, "An action prefix is one domain, lowercase, with or without its trailing `/` (e.g. `auth` or `auth/`).").max(MAX_FILTER_LENGTH).transform((value) => value.replace(/\/$/, "")).optional().describe("Filter to every action under one domain — `auth` or `auth/` matches `auth/signin` and `auth/signout`, never `authority/granted`. The domain is the only prefix: a reason is never matched by its start."),
59
59
  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."),
60
60
  severity: AuditSeverity.optional().describe("Filter to one severity."),
61
61
  resourceType: FilterValue.optional().describe("Filter to the kind of thing acted on (`user`, `secret`)."),
@@ -3,8 +3,8 @@
3
3
  import type { FeatureIdentity } from "@pithy-sh/core/src/naming/feature";
4
4
  import { type WorkflowHostTemplate } from "@pithy-sh/core/src/workflow/host";
5
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
6
+ * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config.
7
+ * Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
8
8
  * bucket it writes, and the Workflow names derived from audit's own specs.
9
9
  */
10
10
  /**
@@ -12,15 +12,20 @@ import { type WorkflowHostTemplate } from "@pithy-sh/core/src/workflow/host";
12
12
  * `AUDIT_CHECKPOINTS` binding**, read through the very function it composes it with, so the host and the app
13
13
  * Worker cannot bind two different buckets.
14
14
  */
15
- export declare function auditCheckpointBucketName(project: string, env: string): string;
15
+ export declare function auditCheckpointBucketName(project: string, env: string, owner?: string): string;
16
16
  /** The resolved resource ids and names for one environment's checkpoint host. */
17
17
  export interface AuditConfigParams {
18
18
  /** The project name, from `requireProjectName` and never guessed. */
19
19
  project: string;
20
20
  /** The target environment. */
21
21
  env: string;
22
- /** The feature this host serves, when it serves one (#643). */
22
+ /** The feature this host serves, when it serves one. */
23
23
  feature?: FeatureIdentity;
24
+ /**
25
+ * The `apps/<owner>` Worker whose own host this is, when it owns a binding the host binds. The Worker and its
26
+ * Workflows then carry `<owner>---<capability>`, so it never takes the shared host's names.
27
+ */
28
+ owner?: string;
24
29
  /** The audit database's id — the D1 behind the binding `audit({ database })` names. */
25
30
  auditDatabaseId: string;
26
31
  /** The checkpoint bucket's name. */
@@ -1 +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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AAkB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,CAsBlH"}
@@ -6,8 +6,8 @@ import { environmentScope } from "@pithy-sh/core/src/naming/provisionScope";
6
6
  import { hostWorkflowsFor, resolveWorkflowHost } from "@pithy-sh/core/src/workflow/host";
7
7
  //#region src/provision/resolveAuditConfig.ts
8
8
  /**
9
- * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config
10
- * (#822). Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
9
+ * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config.
10
+ * Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
11
11
  * bucket it writes, and the Workflow names derived from audit's own specs.
12
12
  */
13
13
  /**
@@ -15,23 +15,25 @@ import { hostWorkflowsFor, resolveWorkflowHost } from "@pithy-sh/core/src/workfl
15
15
  * `AUDIT_CHECKPOINTS` binding**, read through the very function it composes it with, so the host and the app
16
16
  * Worker cannot bind two different buckets.
17
17
  */
18
- function auditCheckpointBucketName(project, env) {
19
- return environmentScope(project, env).resource(AUDIT_CHECKPOINT_BINDING, "r2", {});
18
+ function auditCheckpointBucketName(project, env, owner) {
19
+ return environmentScope(project, env).resource(AUDIT_CHECKPOINT_BINDING, "r2", {}, owner);
20
20
  }
21
21
  /** Fill the template for one environment. */
22
22
  function resolveAuditConfig(template, params) {
23
- const { project, env, feature } = params;
23
+ const { project, env, feature, owner } = params;
24
24
  const derived = hostWorkflowsFor(auditWorkflowRegistry, {
25
25
  project,
26
26
  capability: AUDIT_CAPABILITY,
27
27
  env,
28
- ...feature ? { feature } : {}
28
+ ...feature ? { feature } : {},
29
+ ...owner !== void 0 ? { owner } : {}
29
30
  });
30
31
  const resolved = resolveWorkflowHost(template, {
31
32
  project,
32
33
  capability: AUDIT_CAPABILITY,
33
34
  env,
34
35
  ...feature ? { feature } : {},
36
+ ...owner !== void 0 ? { owner } : {},
35
37
  databaseIds: { DB: params.auditDatabaseId },
36
38
  r2BucketNames: { [AUDIT_CHECKPOINT_BINDING]: params.bucketName },
37
39
  workflows: derived.workflows
package/dist/query.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface AuditQuery {
26
26
  actorKind?: ControlPlaneActorKind;
27
27
  /** Match an exact `domain/reason` action code. */
28
28
  action?: string;
29
- /** Match every action under one domain — `auth` matches `auth/login`, never `authority/granted`. */
29
+ /** Match every action under one domain — `auth` matches `auth/signin`, never `authority/granted`. */
30
30
  actionPrefix?: string;
31
31
  /** Match the outcome (`success` | `failure` | `denied`). */
32
32
  outcome?: AuditOutcome;
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACvG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAG7F,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,yCAAyC;IACzC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oGAAoG;IACpG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB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,OAAO,CAAC,aAAa,EAAE,CAAC,CAK3G;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,MAAM,GAAE,UAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAuBzG;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAGtG"}
@@ -78,7 +78,7 @@ const auditExampleSeed = defineSeed({
78
78
  id: 1,
79
79
  eventId: "example-audit-0001",
80
80
  occurredAt: minutesAgo(90),
81
- action: "auth/login",
81
+ action: "auth/signin",
82
82
  outcome: "success",
83
83
  severity: "info",
84
84
  actorType: "user",
@@ -99,7 +99,7 @@ const auditExampleSeed = defineSeed({
99
99
  id: 2,
100
100
  eventId: "example-audit-0002",
101
101
  occurredAt: minutesAgo(75),
102
- action: "auth/login",
102
+ action: "auth/signin",
103
103
  outcome: "denied",
104
104
  severity: "warning",
105
105
  actorType: "user",
@@ -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.9.1";
6
+ export declare const PACKAGE_VERSION = "0.9.3";
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.9.1";
7
+ const PACKAGE_VERSION = "0.9.3";
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.9.1",
3
+ "version": "0.9.3",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -38,8 +38,8 @@
38
38
  "@hono/zod-validator": "^0.9.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@pithy-sh/core": "^0.18.0",
42
- "@pithy-sh/secrets": "^0.6.6",
41
+ "@pithy-sh/core": "^0.20.0",
42
+ "@pithy-sh/secrets": "^0.6.8",
43
43
  "hono": "^4.13.2",
44
44
  "kysely": "^0.29.0",
45
45
  "zod": "^4.4.0"
package/src/actions.ts CHANGED
@@ -6,18 +6,18 @@ import { AuditInvalidEventError } from "./error/errors";
6
6
 
7
7
  /**
8
8
  * Author a capability's action constants. The taxonomy is **federated**: each capability owns and
9
- * exports its own `domain/reason` action codes (`auth/login`, `entitlement/granted`) and adds them
9
+ * exports its own `domain/reason` action codes (`auth/signin`, `entitlement/granted`) and adds them
10
10
  * without touching core — the way migrations and table prefixes already federate per-capability.
11
11
  *
12
12
  * This validates every code against the shared {@link AuditAction} shape at author time, so a typo
13
13
  * (a missing slash, an uppercase letter) fails loudly where the constant is declared rather than
14
14
  * silently when an event is emitted. Returns the same object, typed, so call sites read
15
- * `AuthAuditActions.login`:
15
+ * `AuthAuditActions.signin`:
16
16
  *
17
17
  * ```ts
18
18
  * export const AuthAuditActions = defineAuditActions({
19
- * login: "auth/login",
20
- * tokenRefreshed: "auth/token_refreshed",
19
+ * signin: "auth/signin",
20
+ * tokenRefresh: "auth/token_refresh",
21
21
  * });
22
22
  * ```
23
23
  */
@@ -27,7 +27,7 @@ export function defineAuditActions<const T extends Record<string, string>>(actio
27
27
  if (!parsed.success) {
28
28
  throw new AuditInvalidEventError({
29
29
  message: `Invalid audit action code for "${name}": ${code}`,
30
- action: "Use a lowercase namespaced `domain/reason` code, e.g. `auth/login`.",
30
+ action: "Use a lowercase namespaced `domain/reason` code, e.g. `auth/signin`.",
31
31
  detail: parsed.error.message,
32
32
  });
33
33
  }
@@ -14,7 +14,7 @@ import { auditCheckpointBucketName } from "../provision/resolveAuditConfig";
14
14
  import { AUDIT_CHECKPOINT_BINDING, AUDIT_CHECKPOINT_LOCK_PREFIX } from "./checkpoint";
15
15
 
16
16
  /**
17
- * **`pithy doctor`'s line on the checkpoint bucket's object lock (#822).**
17
+ * **`pithy doctor`'s line on the checkpoint bucket's object lock.**
18
18
  *
19
19
  * A checkpoint is evidence only while nothing can replace it. The Worker cannot tell through its binding whether
20
20
  * the bucket is locked, so doctor asks the account, per deployed environment: a bucket with no indefinite lock over
@@ -22,6 +22,9 @@ import { AUDIT_CHECKPOINT_BINDING, AUDIT_CHECKPOINT_LOCK_PREFIX } from "./checkp
22
22
  * database to be held to. A bucket that is locked says nothing, which is doctor's way of saying it is in force.
23
23
  *
24
24
  * `dev` is never asked: a developer's checkpoints are a local Miniflare bucket, and no lock means anything there.
25
+ *
26
+ * A Worker that owns `AUDIT_CHECKPOINTS` checkpoints into a bucket of its own, so that bucket is the one asked, and
27
+ * the lock it names is `--worker`'s.
25
28
  */
26
29
  export function checkpointLockCheck(): CapabilitySettings {
27
30
  return {
@@ -29,9 +32,10 @@ export function checkpointLockCheck(): CapabilitySettings {
29
32
  async account(context) {
30
33
  const findings: SettingsFinding[] = [];
31
34
  const unanswered: UnansweredEnvironment[] = [];
35
+ const owner = context.ownBindings?.includes(AUDIT_CHECKPOINT_BINDING) ? context.workerDirectory : undefined;
32
36
  for (const { name: environment } of context.environments) {
33
37
  if (environment === LOCAL_ENVIRONMENT) continue;
34
- const bucket = auditCheckpointBucketName(context.project, environment);
38
+ const bucket = auditCheckpointBucketName(context.project, environment, owner);
35
39
  try {
36
40
  const ask = context.account.r2BucketLock;
37
41
  if (!ask) {
@@ -53,7 +57,9 @@ export function checkpointLockCheck(): CapabilitySettings {
53
57
  });
54
58
  continue;
55
59
  }
56
- const lock = remedy("audit lock", { flags: { "--env": environment } });
60
+ const lock = remedy("audit lock", {
61
+ flags: { "--env": environment, ...(owner === undefined ? {} : { "--worker": owner }) },
62
+ });
57
63
  findings.push({
58
64
  setting: `${AUDIT_CHECKPOINT_BINDING} object lock`,
59
65
  environment,
@@ -92,7 +92,7 @@ export const ListAuditEventsQuery = z
92
92
  .transform((value) => value.replace(/\/$/, ""))
93
93
  .optional()
94
94
  .describe(
95
- "Filter to every action under one domain — `auth` or `auth/` matches `auth/login` and `auth/logout`, never `authority/granted`. The domain is the only prefix: a reason is never matched by its start.",
95
+ "Filter to every action under one domain — `auth` or `auth/` matches `auth/signin` and `auth/signout`, never `authority/granted`. The domain is the only prefix: a reason is never matched by its start.",
96
96
  ),
97
97
  outcome: AuditOutcome.optional().describe(
98
98
  "Filter to one outcome. `denied` is the one worth watching: a run of denials is what a credential being probed looks like.",
@@ -8,8 +8,8 @@ import { AUDIT_CHECKPOINT_BINDING } from "../chain/checkpoint";
8
8
  import { AUDIT_CAPABILITY, auditWorkflowRegistry } from "../workflows/specs";
9
9
 
10
10
  /**
11
- * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config
12
- * (#822). Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
11
+ * Resolve the checkpoint host's committed `wrangler.jsonc` template into one environment's standalone config.
12
+ * Thin over core's {@link resolveWorkflowHost}: this file owns only which database the host reads, which
13
13
  * bucket it writes, and the Workflow names derived from audit's own specs.
14
14
  */
15
15
 
@@ -18,8 +18,8 @@ import { AUDIT_CAPABILITY, auditWorkflowRegistry } from "../workflows/specs";
18
18
  * `AUDIT_CHECKPOINTS` binding**, read through the very function it composes it with, so the host and the app
19
19
  * Worker cannot bind two different buckets.
20
20
  */
21
- export function auditCheckpointBucketName(project: string, env: string): string {
22
- return environmentScope(project, env).resource(AUDIT_CHECKPOINT_BINDING, "r2", {});
21
+ export function auditCheckpointBucketName(project: string, env: string, owner?: string): string {
22
+ return environmentScope(project, env).resource(AUDIT_CHECKPOINT_BINDING, "r2", {}, owner);
23
23
  }
24
24
 
25
25
  /** The resolved resource ids and names for one environment's checkpoint host. */
@@ -28,8 +28,13 @@ export interface AuditConfigParams {
28
28
  project: string;
29
29
  /** The target environment. */
30
30
  env: string;
31
- /** The feature this host serves, when it serves one (#643). */
31
+ /** The feature this host serves, when it serves one. */
32
32
  feature?: FeatureIdentity;
33
+ /**
34
+ * The `apps/<owner>` Worker whose own host this is, when it owns a binding the host binds. The Worker and its
35
+ * Workflows then carry `<owner>---<capability>`, so it never takes the shared host's names.
36
+ */
37
+ owner?: string;
33
38
  /** The audit database's id — the D1 behind the binding `audit({ database })` names. */
34
39
  auditDatabaseId: string;
35
40
  /** The checkpoint bucket's name. */
@@ -38,18 +43,20 @@ export interface AuditConfigParams {
38
43
 
39
44
  /** Fill the template for one environment. */
40
45
  export function resolveAuditConfig(template: WorkflowHostTemplate, params: AuditConfigParams): WorkflowHostTemplate {
41
- const { project, env, feature } = params;
46
+ const { project, env, feature, owner } = params;
42
47
  const derived = hostWorkflowsFor(auditWorkflowRegistry, {
43
48
  project,
44
49
  capability: AUDIT_CAPABILITY,
45
50
  env,
46
51
  ...(feature ? { feature } : {}),
52
+ ...(owner !== undefined ? { owner } : {}),
47
53
  });
48
54
  const resolved = resolveWorkflowHost(template, {
49
55
  project,
50
56
  capability: AUDIT_CAPABILITY,
51
57
  env,
52
58
  ...(feature ? { feature } : {}),
59
+ ...(owner !== undefined ? { owner } : {}),
53
60
  // The host always reads it as `DB`; which database that is follows the adopter's `audit({ database })`.
54
61
  databaseIds: { DB: params.auditDatabaseId },
55
62
  r2BucketNames: { [AUDIT_CHECKPOINT_BINDING]: params.bucketName },
package/src/query.ts CHANGED
@@ -30,7 +30,7 @@ export interface AuditQuery {
30
30
  actorKind?: ControlPlaneActorKind;
31
31
  /** Match an exact `domain/reason` action code. */
32
32
  action?: string;
33
- /** Match every action under one domain — `auth` matches `auth/login`, never `authority/granted`. */
33
+ /** Match every action under one domain — `auth` matches `auth/signin`, never `authority/granted`. */
34
34
  actionPrefix?: string;
35
35
  /** Match the outcome (`success` | `failure` | `denied`). */
36
36
  outcome?: AuditOutcome;
@@ -75,7 +75,7 @@ export const auditExampleSeed: SeedSet = defineSeed({
75
75
  id: 1,
76
76
  eventId: "example-audit-0001",
77
77
  occurredAt: minutesAgo(90),
78
- action: "auth/login",
78
+ action: "auth/signin",
79
79
  outcome: "success",
80
80
  severity: "info",
81
81
  actorType: "user",
@@ -96,7 +96,7 @@ export const auditExampleSeed: SeedSet = defineSeed({
96
96
  id: 2,
97
97
  eventId: "example-audit-0002",
98
98
  occurredAt: minutesAgo(75),
99
- action: "auth/login",
99
+ action: "auth/signin",
100
100
  outcome: "denied",
101
101
  severity: "warning",
102
102
  actorType: "user",
@@ -13,4 +13,4 @@
13
13
  export const PACKAGE_NAME = "@pithy-sh/audit";
14
14
 
15
15
  /** This package's version, stamped from its own package.json at generation time. */
16
- export const PACKAGE_VERSION = "0.9.1";
16
+ export const PACKAGE_VERSION = "0.9.3";