@pithy-sh/audit 0.9.2 → 0.9.4

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.
@@ -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,
@@ -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,CAA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BAAkB,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
@@ -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.2";
6
+ export declare const PACKAGE_VERSION = "0.9.4";
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.2";
7
+ const PACKAGE_VERSION = "0.9.4";
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.2",
3
+ "version": "0.9.4",
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.19.0",
42
- "@pithy-sh/secrets": "^0.6.7",
41
+ "@pithy-sh/core": "^0.21.0",
42
+ "@pithy-sh/secrets": "^0.6.9",
43
43
  "hono": "^4.13.2",
44
44
  "kysely": "^0.29.0",
45
45
  "zod": "^4.4.0"
@@ -34,6 +34,13 @@
34
34
  "optional": true
35
35
  }
36
36
  ],
37
+ "testBindings": [
38
+ { "kind": "d1", "name": "DB" },
39
+ { "kind": "r2", "name": "AUDIT_CHECKPOINTS" },
40
+ { "kind": "unbound", "name": "AUDIT_CHECKPOINT" },
41
+ { "kind": "unbound", "name": "AUDIT_SHIP" },
42
+ { "kind": "unbound", "name": "AUDIT_SHIP_DLQ" }
43
+ ],
37
44
  "migrationNamespace": "audit",
38
45
  "whenToEnable": "A queryable, tamper-evident audit trail of security-relevant actions \u2014 logins, token refreshes, entitlement grants, admin config changes. Records who did what, when, and whether it succeeded, attributed to the right actor. Other capabilities emit through the core seam; auth needs it the moment it lands.",
39
46
  "configOptions": [
@@ -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,
@@ -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 },
@@ -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.2";
16
+ export const PACKAGE_VERSION = "0.9.4";