@checkstack/common 0.10.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 +99 -0
- package/package.json +2 -2
- package/src/actor.ts +39 -0
- package/src/index.ts +1 -0
- package/src/pagination.test.ts +110 -43
- package/src/pagination.ts +34 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,104 @@
|
|
|
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
|
+
|
|
48
|
+
## 0.11.0
|
|
49
|
+
|
|
50
|
+
### Minor Changes
|
|
51
|
+
|
|
52
|
+
- f23f3c9: Add the canonical `PaginationInput` zod schema and `PaginatedResult`
|
|
53
|
+
output factory in `@checkstack/common`. `PaginationInput` is an
|
|
54
|
+
integer-clamped `{ limit: 1-100 (default 20), offset: >= 0 (default 0) }`
|
|
55
|
+
shape that composes with `.extend({...})` for domain-specific filters
|
|
56
|
+
(e.g. `unreadOnly` on notifications). `PaginatedResult(itemSchema)`
|
|
57
|
+
returns the standard `{ items, total, limit, offset }` envelope. The
|
|
58
|
+
existing `PaginationInputSchema` / `paginatedOutput` / `PaginatedResponse`
|
|
59
|
+
exports are now marked `@deprecated` and will be removed once the
|
|
60
|
+
follow-up sweep migrates every `*-common` consumer to the canonical
|
|
61
|
+
contract.
|
|
62
|
+
- f23f3c9: Sweep every paginated `*-common` contract onto the canonical
|
|
63
|
+
`PaginationInput` / `PaginatedResult` from `@checkstack/common` and
|
|
64
|
+
remove the now-unused legacy exports.
|
|
65
|
+
|
|
66
|
+
**BREAKING CHANGE** - `@checkstack/common` drops the deprecated
|
|
67
|
+
`PaginationInputSchema`, `paginatedOutput`, and `PaginatedResponse`
|
|
68
|
+
symbols. Callers must consume `PaginationInput` (input) and
|
|
69
|
+
`PaginatedResult(itemSchema)` (output) instead. The canonical input is
|
|
70
|
+
`{ limit (1-100, default 20), offset (>= 0, default 0) }`; the
|
|
71
|
+
canonical output envelope is
|
|
72
|
+
`{ items, total, limit, offset }`.
|
|
73
|
+
|
|
74
|
+
**BREAKING CHANGE** - `@checkstack/notification-common` migrates
|
|
75
|
+
`getNotifications` off the legacy `PaginationInputSchema`
|
|
76
|
+
(`{ limit, offset, unreadOnly }` with output `{ notifications, total }`)
|
|
77
|
+
onto `ListNotificationsInputSchema =
|
|
78
|
+
PaginationInput.extend({ unreadOnly })` and
|
|
79
|
+
`PaginatedResult(NotificationSchema)`. The output key changes from
|
|
80
|
+
`notifications` to `items`, and `limit` / `offset` are now echoed on
|
|
81
|
+
the response. The `PaginationInput` type alias previously exported
|
|
82
|
+
from `notification-common` is removed - use `ListNotificationsInput`
|
|
83
|
+
or the canonical `PaginationInput` from `@checkstack/common`.
|
|
84
|
+
|
|
85
|
+
**BREAKING CHANGE** - `@checkstack/integration-common` migrates
|
|
86
|
+
`listSubscriptions` (inline `{ page, pageSize, ... }` -> output
|
|
87
|
+
`{ subscriptions, total }`) and `getDeliveryLogs` (via
|
|
88
|
+
`DeliveryLogQueryInputSchema` `{ subscriptionId?, eventType?, status?,
|
|
89
|
+
page, pageSize }` -> output `{ logs, total }`) onto the canonical
|
|
90
|
+
`PaginationInput.extend({...})` input and
|
|
91
|
+
`PaginatedResult(itemSchema)` output. External callers must switch
|
|
92
|
+
from `{ page, pageSize }` to `{ limit, offset }` and read response
|
|
93
|
+
items from `data.items` (no more `data.subscriptions` / `data.logs`).
|
|
94
|
+
|
|
95
|
+
The matching `*-backend` handlers were updated to consume the new
|
|
96
|
+
input shape (`offset` arithmetic in lieu of `(page - 1) * pageSize`)
|
|
97
|
+
and to echo `limit` / `offset` on the response. The `*-frontend` call
|
|
98
|
+
sites in `NotificationsPage`, `NotificationBell`, `IntegrationsPage`,
|
|
99
|
+
and `DeliveryLogsPage` were updated to send the new input shape and
|
|
100
|
+
read `data.items`.
|
|
101
|
+
|
|
3
102
|
## 0.10.0
|
|
4
103
|
|
|
5
104
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/common",
|
|
3
|
-
"version": "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.
|
|
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
package/src/pagination.test.ts
CHANGED
|
@@ -1,89 +1,156 @@
|
|
|
1
1
|
import { describe, it, expect } from "bun:test";
|
|
2
|
-
import { PaginationInputSchema, paginatedOutput } from "./pagination";
|
|
3
2
|
import { z } from "zod";
|
|
3
|
+
import { PaginationInput, PaginatedResult } from "./pagination";
|
|
4
4
|
|
|
5
|
-
describe("
|
|
6
|
-
it("
|
|
7
|
-
const result =
|
|
8
|
-
limit: 20,
|
|
9
|
-
offset: 40,
|
|
10
|
-
});
|
|
11
|
-
|
|
5
|
+
describe("PaginationInput (canonical)", () => {
|
|
6
|
+
it("applies default limit and offset when omitted", () => {
|
|
7
|
+
const result = PaginationInput.parse({});
|
|
12
8
|
expect(result.limit).toBe(20);
|
|
13
|
-
expect(result.offset).toBe(
|
|
9
|
+
expect(result.offset).toBe(0);
|
|
14
10
|
});
|
|
15
11
|
|
|
16
|
-
it("
|
|
17
|
-
const result =
|
|
12
|
+
it("accepts valid limit and offset values", () => {
|
|
13
|
+
const result = PaginationInput.parse({ limit: 50, offset: 100 });
|
|
14
|
+
expect(result.limit).toBe(50);
|
|
15
|
+
expect(result.offset).toBe(100);
|
|
16
|
+
});
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
expect(
|
|
18
|
+
it("rejects limit below 1", () => {
|
|
19
|
+
expect(() => PaginationInput.parse({ limit: 0 })).toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("rejects limit above 100", () => {
|
|
23
|
+
expect(() => PaginationInput.parse({ limit: 101 })).toThrow();
|
|
21
24
|
});
|
|
22
25
|
|
|
23
|
-
it("
|
|
24
|
-
expect(() =>
|
|
26
|
+
it("rejects negative offset", () => {
|
|
27
|
+
expect(() => PaginationInput.parse({ offset: -1 })).toThrow();
|
|
25
28
|
});
|
|
26
29
|
|
|
27
|
-
it("
|
|
28
|
-
expect(() =>
|
|
30
|
+
it("rejects non-integer limit values", () => {
|
|
31
|
+
expect(() => PaginationInput.parse({ limit: 10.5 })).toThrow();
|
|
29
32
|
});
|
|
30
33
|
|
|
31
|
-
it("
|
|
32
|
-
expect(() =>
|
|
34
|
+
it("rejects non-integer offset values", () => {
|
|
35
|
+
expect(() => PaginationInput.parse({ offset: 1.5 })).toThrow();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("supports `.extend({...})` for domain extras", () => {
|
|
39
|
+
const ListNotificationsInput = PaginationInput.extend({
|
|
40
|
+
unreadOnly: z.boolean().default(false),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const parsed = ListNotificationsInput.parse({});
|
|
44
|
+
expect(parsed.limit).toBe(20);
|
|
45
|
+
expect(parsed.offset).toBe(0);
|
|
46
|
+
expect(parsed.unreadOnly).toBe(false);
|
|
47
|
+
|
|
48
|
+
const parsedWithExtras = ListNotificationsInput.parse({
|
|
49
|
+
limit: 5,
|
|
50
|
+
unreadOnly: true,
|
|
51
|
+
});
|
|
52
|
+
expect(parsedWithExtras.limit).toBe(5);
|
|
53
|
+
expect(parsedWithExtras.unreadOnly).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("infers a typed PaginationInput", () => {
|
|
57
|
+
const sample: PaginationInput = { limit: 10, offset: 0 };
|
|
58
|
+
expect(sample.limit).toBe(10);
|
|
59
|
+
expect(sample.offset).toBe(0);
|
|
33
60
|
});
|
|
34
61
|
});
|
|
35
62
|
|
|
36
|
-
describe("
|
|
63
|
+
describe("PaginatedResult (canonical)", () => {
|
|
37
64
|
const ItemSchema = z.object({
|
|
38
65
|
id: z.string(),
|
|
39
66
|
name: z.string(),
|
|
40
67
|
});
|
|
41
68
|
|
|
42
|
-
it("
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const result = outputSchema.parse({
|
|
69
|
+
it("produces an { items, total, limit, offset } shape", () => {
|
|
70
|
+
const schema = PaginatedResult(ItemSchema);
|
|
71
|
+
const result = schema.parse({
|
|
46
72
|
items: [
|
|
47
|
-
{ id: "1", name: "
|
|
48
|
-
{ id: "2", name: "
|
|
73
|
+
{ id: "1", name: "First" },
|
|
74
|
+
{ id: "2", name: "Second" },
|
|
49
75
|
],
|
|
50
|
-
total:
|
|
76
|
+
total: 42,
|
|
77
|
+
limit: 20,
|
|
78
|
+
offset: 0,
|
|
51
79
|
});
|
|
52
80
|
|
|
53
81
|
expect(result.items).toHaveLength(2);
|
|
54
|
-
expect(result.total).toBe(
|
|
82
|
+
expect(result.total).toBe(42);
|
|
83
|
+
expect(result.limit).toBe(20);
|
|
84
|
+
expect(result.offset).toBe(0);
|
|
55
85
|
});
|
|
56
86
|
|
|
57
|
-
it("
|
|
58
|
-
const
|
|
59
|
-
|
|
87
|
+
it("rejects items that do not match the inner schema", () => {
|
|
88
|
+
const schema = PaginatedResult(ItemSchema);
|
|
60
89
|
expect(() =>
|
|
61
|
-
|
|
62
|
-
items: [{ id: "1" }],
|
|
90
|
+
schema.parse({
|
|
91
|
+
items: [{ id: "1" }],
|
|
63
92
|
total: 1,
|
|
64
|
-
|
|
93
|
+
limit: 20,
|
|
94
|
+
offset: 0,
|
|
95
|
+
}),
|
|
65
96
|
).toThrow();
|
|
66
97
|
});
|
|
67
98
|
|
|
68
|
-
it("
|
|
69
|
-
const
|
|
99
|
+
it("rejects a missing total", () => {
|
|
100
|
+
const schema = PaginatedResult(ItemSchema);
|
|
101
|
+
expect(() =>
|
|
102
|
+
schema.parse({
|
|
103
|
+
items: [],
|
|
104
|
+
limit: 20,
|
|
105
|
+
offset: 0,
|
|
106
|
+
}),
|
|
107
|
+
).toThrow();
|
|
108
|
+
});
|
|
70
109
|
|
|
110
|
+
it("rejects a missing limit/offset", () => {
|
|
111
|
+
const schema = PaginatedResult(ItemSchema);
|
|
71
112
|
expect(() =>
|
|
72
|
-
|
|
73
|
-
items: [
|
|
74
|
-
|
|
113
|
+
schema.parse({
|
|
114
|
+
items: [],
|
|
115
|
+
total: 0,
|
|
116
|
+
}),
|
|
75
117
|
).toThrow();
|
|
76
118
|
});
|
|
77
119
|
|
|
78
|
-
it("
|
|
79
|
-
const
|
|
120
|
+
it("rejects a negative total", () => {
|
|
121
|
+
const schema = PaginatedResult(ItemSchema);
|
|
122
|
+
expect(() =>
|
|
123
|
+
schema.parse({
|
|
124
|
+
items: [],
|
|
125
|
+
total: -1,
|
|
126
|
+
limit: 20,
|
|
127
|
+
offset: 0,
|
|
128
|
+
}),
|
|
129
|
+
).toThrow();
|
|
130
|
+
});
|
|
80
131
|
|
|
81
|
-
|
|
132
|
+
it("accepts an empty items array", () => {
|
|
133
|
+
const schema = PaginatedResult(ItemSchema);
|
|
134
|
+
const result = schema.parse({
|
|
82
135
|
items: [],
|
|
83
136
|
total: 0,
|
|
137
|
+
limit: 20,
|
|
138
|
+
offset: 0,
|
|
84
139
|
});
|
|
85
|
-
|
|
86
140
|
expect(result.items).toEqual([]);
|
|
87
141
|
expect(result.total).toBe(0);
|
|
88
142
|
});
|
|
143
|
+
|
|
144
|
+
it("infers a typed result via z.infer", () => {
|
|
145
|
+
const schema = PaginatedResult(ItemSchema);
|
|
146
|
+
type Result = z.infer<typeof schema>;
|
|
147
|
+
const value: Result = {
|
|
148
|
+
items: [{ id: "x", name: "X" }],
|
|
149
|
+
total: 1,
|
|
150
|
+
limit: 20,
|
|
151
|
+
offset: 0,
|
|
152
|
+
};
|
|
153
|
+
expect(value.items[0]?.id).toBe("x");
|
|
154
|
+
});
|
|
89
155
|
});
|
|
156
|
+
|
package/src/pagination.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Canonical pagination input schema for RPC procedures.
|
|
5
|
+
*
|
|
6
|
+
* This is the single source of truth for paginated list inputs across
|
|
7
|
+
* the platform. Domain-specific extras (e.g. `unreadOnly` on
|
|
8
|
+
* notifications) must compose with `.extend({...})` — do NOT redefine
|
|
9
|
+
* the base fields.
|
|
6
10
|
*
|
|
7
11
|
* @example
|
|
8
12
|
* ```typescript
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
* import { PaginationInput, PaginatedResult } from "@checkstack/common";
|
|
14
|
+
*
|
|
15
|
+
* const ListNotificationsInput = PaginationInput.extend({
|
|
16
|
+
* unreadOnly: z.boolean().default(false),
|
|
17
|
+
* });
|
|
11
18
|
*
|
|
12
|
-
* const
|
|
13
|
-
* getItems: _base
|
|
14
|
-
* .input(PaginationInputSchema.extend({ search: z.string().optional() }))
|
|
15
|
-
* .output(paginatedOutput(ItemSchema)),
|
|
16
|
-
* };
|
|
19
|
+
* const ListNotificationsOutput = PaginatedResult(NotificationSchema);
|
|
17
20
|
* ```
|
|
18
21
|
*/
|
|
19
|
-
export const
|
|
20
|
-
/** Number of items per page (1-100) */
|
|
21
|
-
limit: z.number().min(1).max(100).default(
|
|
22
|
-
/** Number of items to skip */
|
|
23
|
-
offset: z.number().min(0).default(0),
|
|
22
|
+
export const PaginationInput = z.object({
|
|
23
|
+
/** Number of items per page (1-100). */
|
|
24
|
+
limit: z.number().int().min(1).max(100).default(20),
|
|
25
|
+
/** Number of items to skip from the start of the result set. */
|
|
26
|
+
offset: z.number().int().min(0).default(0),
|
|
24
27
|
});
|
|
25
28
|
|
|
26
|
-
export type PaginationInput = z.infer<typeof
|
|
29
|
+
export type PaginationInput = z.infer<typeof PaginationInput>;
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
32
|
+
* Canonical paginated response factory.
|
|
33
|
+
*
|
|
34
|
+
* Wraps an item schema in the standard `{ items, total, limit, offset }`
|
|
35
|
+
* shape. The echoed `limit` / `offset` mirror what the server actually
|
|
36
|
+
* applied so clients can render correct pagination controls even when
|
|
37
|
+
* defaults were used.
|
|
31
38
|
*
|
|
32
39
|
* @example
|
|
33
40
|
* ```typescript
|
|
34
|
-
* //
|
|
35
|
-
*
|
|
36
|
-
* .input(
|
|
37
|
-
* .output(
|
|
41
|
+
* // In a contract:
|
|
42
|
+
* getNotifications: _base
|
|
43
|
+
* .input(PaginationInput)
|
|
44
|
+
* .output(PaginatedResult(NotificationSchema)),
|
|
38
45
|
*
|
|
39
|
-
* // Returns: { items:
|
|
46
|
+
* // Returns: { items: Notification[], total: number, limit: number, offset: number }
|
|
40
47
|
* ```
|
|
41
48
|
*/
|
|
42
|
-
export
|
|
43
|
-
|
|
49
|
+
export const PaginatedResult = <T extends z.ZodTypeAny>(itemSchema: T) =>
|
|
50
|
+
z.object({
|
|
44
51
|
items: z.array(itemSchema),
|
|
45
|
-
total: z.number(),
|
|
52
|
+
total: z.number().int().min(0),
|
|
53
|
+
limit: z.number().int(),
|
|
54
|
+
offset: z.number().int(),
|
|
46
55
|
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Type helper for paginated responses
|
|
51
|
-
*/
|
|
52
|
-
export type PaginatedResponse<T> = {
|
|
53
|
-
items: T[];
|
|
54
|
-
total: number;
|
|
55
|
-
};
|