@alethialabs/platform 0.4.0 → 0.5.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.
@@ -0,0 +1,22 @@
1
+ import type { NewPlatformAudit } from "./schema";
2
+ import type { PlatformAuditInput } from "./types";
3
+ /** Inserts one `platform_audit` row on the caller's service connection. */
4
+ export type PlatformAuditWrite = (row: NewPlatformAudit) => Promise<unknown>;
5
+ /** What a platform-operator act is recorded as. */
6
+ export interface PlatformAuditEntry {
7
+ /** The operator's email, from a verified identity — never from the request body. */
8
+ actor: string;
9
+ /** A stable slug, e.g. "grant_enterprise" | "set_test_org" | "switch_test_org". */
10
+ action: string;
11
+ /** The target org, or null for a create (the id is the result). */
12
+ orgId: string | null;
13
+ /** REQUIRED free-text justification. Blank throws before anything is written. */
14
+ reason: string;
15
+ /** What the operator asked for, verbatim. */
16
+ input: PlatformAuditInput;
17
+ }
18
+ /**
19
+ * Runs `run` between an `attempt` row and a `result` row in `platform_audit`. Throws when the reason
20
+ * is blank (nothing is written), rethrows `run`'s error after recording it as `outcome: "error"`.
21
+ */
22
+ export declare function withPlatformAudit<T>(write: PlatformAuditWrite, entry: PlatformAuditEntry, run: () => Promise<T>): Promise<T>;
package/dist/audit.js ADDED
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: 2026 Alethia Labs <legal@alethialabs.io>
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+ /**
4
+ * Runs `run` between an `attempt` row and a `result` row in `platform_audit`. Throws when the reason
5
+ * is blank (nothing is written), rethrows `run`'s error after recording it as `outcome: "error"`.
6
+ */
7
+ export async function withPlatformAudit(write, entry, run) {
8
+ const reason = entry.reason?.trim();
9
+ if (!reason)
10
+ throw new Error("A reason is required for operator actions.");
11
+ const base = {
12
+ actorEmail: entry.actor,
13
+ action: entry.action,
14
+ targetOrgId: entry.orgId,
15
+ input: entry.input,
16
+ reason,
17
+ };
18
+ await write({ ...base, phase: "attempt" });
19
+ try {
20
+ const out = await run();
21
+ await write({ ...base, phase: "result", outcome: "ok" });
22
+ return out;
23
+ }
24
+ catch (err) {
25
+ await write({
26
+ ...base,
27
+ phase: "result",
28
+ outcome: "error",
29
+ detail: err instanceof Error ? err.message : String(err),
30
+ });
31
+ throw err;
32
+ }
33
+ }
package/dist/types.d.ts CHANGED
@@ -18,4 +18,10 @@ export interface PlatformAuditInput {
18
18
  paddleCustomerId?: string | null;
19
19
  /** The value it replaced, when the operator confirmed replacing one. */
20
20
  replacedPaddleCustomerId?: string | null;
21
+ /** The test-organization flag an operator set or cleared (set_test_org / clear_test_org). */
22
+ isTestOrg?: boolean;
23
+ /** The AI tier a test-organization switch set (switch_test_org). */
24
+ aiTier?: string;
25
+ /** The usage preset a test-organization switch applied: fresh | near | over. */
26
+ usagePreset?: string;
21
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alethialabs/platform",
3
- "version": "0.4.0",
4
- "description": "Alethia platform records: enterprise contracts and the platform audit log, as Drizzle schema, enums and types.",
3
+ "version": "0.5.0",
4
+ "description": "Alethia platform records: enterprise contracts and the platform audit log, as Drizzle schema, enums and types, and the audit discipline both apps write it with.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Alethia Labs <legal@alethialabs.io>",
7
7
  "homepage": "https://alethialabs.io",
@@ -41,6 +41,10 @@
41
41
  "./access-jwt": {
42
42
  "types": "./dist/access-jwt.d.ts",
43
43
  "default": "./dist/access-jwt.js"
44
+ },
45
+ "./audit": {
46
+ "types": "./dist/audit.d.ts",
47
+ "default": "./dist/audit.js"
44
48
  }
45
49
  },
46
50
  "files": [