@checkstack/common 0.11.0 → 0.12.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/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @checkstack/common
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6d52276: feat(automation): expose `trigger.actor` so automations can filter on who/what caused an event
8
+
9
+ Every platform event now carries an **actor** - the user, application (API
10
+ client), service (backend-to-backend), or `system` (background /
11
+ unauthenticated) that caused it - and the automation engine surfaces it to
12
+ automations as `trigger.actor`. This lets a trigger filter gate on the
13
+ origin of the event it reacts to:
14
+
15
+ ```text
16
+ {{ trigger.actor.type == "system" }} # auto-created by the platform
17
+ {{ trigger.actor.type == "user" }} # a human
18
+ {{ trigger.actor.id == "app-deploybot" }} # a specific application
19
+ ```
20
+
21
+ `trigger.actor` is available on **every** trigger - it is injected by the
22
+ platform, not declared per trigger - and editor autocomplete + Run Script
23
+ context types include `trigger.actor.{type,id,name}`.
24
+
25
+ How it works:
26
+
27
+ - **`@checkstack/common`** adds the canonical `Actor` type / `ActorSchema`
28
+ and `SYSTEM_ACTOR`.
29
+ - **`@checkstack/backend-api`** adds `resolveActor(user)` and a
30
+ `HookEventMeta` envelope. The hook listener / `onHook` signature gains an
31
+ optional second `meta` argument (additive, backward compatible).
32
+ - **`@checkstack/backend`** wraps emitted hooks in an envelope so the actor
33
+ travels with the payload through the distributed queue, unwrapping it
34
+ before delivery. The RPC emit path captures the authenticated caller;
35
+ background emits default to the system actor. Raw/legacy queue data is
36
+ treated as a system-actor payload, so delivery stays backward compatible.
37
+ - **`@checkstack/automation-backend`** threads the actor into the dispatch
38
+ scope (`trigger.actor`), available to trigger filters, top-level
39
+ conditions, and all run templates, and persisted in the run's scope
40
+ snapshot. Manual runs are attributed to the invoking user.
41
+ - **`@checkstack/automation-common`** / **`@checkstack/automation-frontend`**
42
+ expose `trigger.actor` in the editor variable scope and the generated
43
+ Run Script `context.trigger.actor` types.
44
+
45
+ No database migration and no per-trigger schema changes: the actor rides as
46
+ event-envelope metadata and in the run scope snapshot.
47
+
3
48
  ## 0.11.0
4
49
 
5
50
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/common",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  "devDependencies": {
21
21
  "typescript": "^5.7.2",
22
22
  "@checkstack/tsconfig": "0.0.7",
23
- "@checkstack/scripts": "0.3.2"
23
+ "@checkstack/scripts": "0.3.3"
24
24
  },
25
25
  "scripts": {
26
26
  "typecheck": "tsgo -b",
package/src/actor.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+
3
+ /**
4
+ * Who (or what) caused a platform event. Travels as event-envelope metadata
5
+ * on every emitted hook and is surfaced to automations as `trigger.actor`, so
6
+ * an automation can filter on the origin of the event it reacts to - e.g.
7
+ * "only incidents auto-created by the system" or "systems created by a
8
+ * specific application/API client".
9
+ *
10
+ * - `system` - no authenticated caller (platform-internal / background /
11
+ * automatic events such as healthcheck or SLO triggers).
12
+ * - `user` - a human user (session/token authenticated).
13
+ * - `application` - an external application authenticated via API key.
14
+ * - `service` - a trusted backend-to-backend (plugin) call; `id` is the
15
+ * originating plugin id.
16
+ */
17
+ export const ACTOR_TYPES = ["system", "user", "application", "service"] as const;
18
+
19
+ export type ActorType = (typeof ACTOR_TYPES)[number];
20
+
21
+ export const ActorSchema = z.object({
22
+ type: z.enum(ACTOR_TYPES),
23
+ /**
24
+ * Stable identifier for the actor: the user id, application id, originating
25
+ * plugin id for services, or the literal `"system"`.
26
+ */
27
+ id: z.string(),
28
+ /** Human-readable display name when known (absent for system/service). */
29
+ name: z.string().optional(),
30
+ });
31
+
32
+ export type Actor = z.infer<typeof ActorSchema>;
33
+
34
+ /** Canonical actor for platform-internal / unauthenticated events. */
35
+ export const SYSTEM_ACTOR: Actor = {
36
+ type: "system",
37
+ id: "system",
38
+ name: "System",
39
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./types";
2
+ export * from "./actor";
2
3
  export * from "./pagination";
3
4
  export * from "./routes";
4
5
  export * from "./plugin-metadata";