@ultimat3/policy 31.45.0 → 31.47.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.
Files changed (2) hide show
  1. package/README.md +17 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -9,8 +9,17 @@ object through the *same* `evaluate()`.
9
9
  `bun add @ultimat3/policy` · guide: [Policies And Authz](https://github.com/developerz-ai/ultimate/wiki/Policies-And-Authz)
10
10
 
11
11
  ```ts
12
+ import { action, t } from '@ultimat3/action';
13
+ import { type Actor } from '@ultimat3/core';
14
+ import { can } from '@ultimat3/policy';
15
+
16
+ declare function ownsPost(actor: Actor | null, postId: string): boolean;
17
+
12
18
  export const publishPost = action({
13
- policy: can('post:publish', ({ input, actor }) => ownsPost(actor, input.postId)),
19
+ input: t.object({ postId: t.uuid }),
20
+ output: t.object({ id: t.uuid, orgId: t.uuid, title: t.string }),
21
+ policy: can<{ postId: string }>('post:publish', ({ input, actor }) => ownsPost(actor, input.postId)),
22
+ handle: ({ input, ctx }) => ctx.posts.publish(input.postId),
14
23
  });
15
24
  ```
16
25
 
@@ -40,6 +49,9 @@ are different problems with different fixes.
40
49
  ## One predicate signature, every surface
41
50
 
42
51
  ```ts
52
+ import { type Actor } from '@ultimat3/policy';
53
+ import { type Ctx } from '@ultimat3/core';
54
+
43
55
  interface PolicyArgs<I = unknown, R = unknown> {
44
56
  input: I;
45
57
  actor: Actor | null;
@@ -53,6 +65,10 @@ live query's per-row gate:
53
65
 
54
66
  ```ts
55
67
  // decides on input alone — `row` is null
68
+ import { can } from '@ultimat3/policy';
69
+
70
+ type Post = { readonly id: string; readonly orgId: string; readonly title: string; readonly authorId: string };
71
+
56
72
  can<{ orgId: string }>('post:create', ({ actor, input }) => actor?.orgId === input.orgId);
57
73
 
58
74
  // decides about a row the surface already loaded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/policy",
3
- "version": "31.45.0",
3
+ "version": "31.47.0",
4
4
  "description": "The one authz rule, evaluated identically in every surface",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -42,6 +42,6 @@
42
42
  "test": "bun test"
43
43
  },
44
44
  "dependencies": {
45
- "@ultimat3/core": "31.45.0"
45
+ "@ultimat3/core": "31.47.0"
46
46
  }
47
47
  }