@terpjs/contract 0.18.0 → 0.19.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/openapi.json CHANGED
@@ -1,6 +1,324 @@
1
1
  {
2
2
  "components": {
3
3
  "schemas": {
4
+ "AccessEndpointRead": {
5
+ "description": "One mounted route and the authority that applies to it.",
6
+ "properties": {
7
+ "by_role": {
8
+ "items": {
9
+ "$ref": "#/components/schemas/AccessRoleOutcomeRead"
10
+ },
11
+ "title": "By Role",
12
+ "type": "array"
13
+ },
14
+ "extra_permissions": {
15
+ "items": {
16
+ "type": "string"
17
+ },
18
+ "title": "Extra Permissions",
19
+ "type": "array"
20
+ },
21
+ "methods": {
22
+ "items": {
23
+ "type": "string"
24
+ },
25
+ "title": "Methods",
26
+ "type": "array"
27
+ },
28
+ "name": {
29
+ "title": "Name",
30
+ "type": "string"
31
+ },
32
+ "operation": {
33
+ "anyOf": [
34
+ {
35
+ "$ref": "#/components/schemas/AccessOperationRead"
36
+ },
37
+ {
38
+ "type": "null"
39
+ }
40
+ ]
41
+ },
42
+ "path": {
43
+ "title": "Path",
44
+ "type": "string"
45
+ },
46
+ "requirement": {
47
+ "title": "Requirement",
48
+ "type": "string"
49
+ }
50
+ },
51
+ "required": [
52
+ "path",
53
+ "methods",
54
+ "requirement",
55
+ "extra_permissions",
56
+ "name",
57
+ "operation",
58
+ "by_role"
59
+ ],
60
+ "title": "AccessEndpointRead",
61
+ "type": "object"
62
+ },
63
+ "AccessModelRead": {
64
+ "description": "The declared authority surface: the ladder, the permissions, and every module.",
65
+ "properties": {
66
+ "modules": {
67
+ "items": {
68
+ "$ref": "#/components/schemas/AccessModuleRead"
69
+ },
70
+ "title": "Modules",
71
+ "type": "array"
72
+ },
73
+ "permissions": {
74
+ "items": {
75
+ "$ref": "#/components/schemas/AccessPermissionRead"
76
+ },
77
+ "title": "Permissions",
78
+ "type": "array"
79
+ },
80
+ "roles": {
81
+ "items": {
82
+ "$ref": "#/components/schemas/AccessRoleRead"
83
+ },
84
+ "title": "Roles",
85
+ "type": "array"
86
+ }
87
+ },
88
+ "required": [
89
+ "roles",
90
+ "permissions",
91
+ "modules"
92
+ ],
93
+ "title": "AccessModelRead",
94
+ "type": "object"
95
+ },
96
+ "AccessModuleRead": {
97
+ "description": "One module's declared authority.",
98
+ "properties": {
99
+ "access": {
100
+ "anyOf": [
101
+ {
102
+ "$ref": "#/components/schemas/ModuleAccessRead"
103
+ },
104
+ {
105
+ "type": "null"
106
+ }
107
+ ]
108
+ },
109
+ "endpoints": {
110
+ "items": {
111
+ "$ref": "#/components/schemas/AccessEndpointRead"
112
+ },
113
+ "title": "Endpoints",
114
+ "type": "array"
115
+ },
116
+ "name": {
117
+ "title": "Name",
118
+ "type": "string"
119
+ },
120
+ "permissions": {
121
+ "items": {
122
+ "type": "string"
123
+ },
124
+ "title": "Permissions",
125
+ "type": "array"
126
+ },
127
+ "policy": {
128
+ "anyOf": [
129
+ {
130
+ "$ref": "#/components/schemas/AccessPolicyRead"
131
+ },
132
+ {
133
+ "type": "null"
134
+ }
135
+ ]
136
+ },
137
+ "prefix": {
138
+ "anyOf": [
139
+ {
140
+ "type": "string"
141
+ },
142
+ {
143
+ "type": "null"
144
+ }
145
+ ],
146
+ "title": "Prefix"
147
+ }
148
+ },
149
+ "required": [
150
+ "name",
151
+ "prefix",
152
+ "policy",
153
+ "permissions",
154
+ "access",
155
+ "endpoints"
156
+ ],
157
+ "title": "AccessModuleRead",
158
+ "type": "object"
159
+ },
160
+ "AccessOperationRead": {
161
+ "description": "What a route does, in the source language (ADR 0102).",
162
+ "properties": {
163
+ "id": {
164
+ "title": "Id",
165
+ "type": "string"
166
+ },
167
+ "label": {
168
+ "title": "Label",
169
+ "type": "string"
170
+ }
171
+ },
172
+ "required": [
173
+ "id",
174
+ "label"
175
+ ],
176
+ "title": "AccessOperationRead",
177
+ "type": "object"
178
+ },
179
+ "AccessPermissionRead": {
180
+ "description": "One declared permission: its name, its rank floor, and what holding it buys.",
181
+ "properties": {
182
+ "label": {
183
+ "anyOf": [
184
+ {
185
+ "type": "string"
186
+ },
187
+ {
188
+ "type": "null"
189
+ }
190
+ ],
191
+ "title": "Label"
192
+ },
193
+ "min_role": {
194
+ "title": "Min Role",
195
+ "type": "string"
196
+ },
197
+ "name": {
198
+ "title": "Name",
199
+ "type": "string"
200
+ }
201
+ },
202
+ "required": [
203
+ "name",
204
+ "min_role",
205
+ "label"
206
+ ],
207
+ "title": "AccessPermissionRead",
208
+ "type": "object"
209
+ },
210
+ "AccessPolicyRead": {
211
+ "description": "A module's declared posture. ``public`` decides which of the other fields apply.",
212
+ "properties": {
213
+ "allows_public_writes": {
214
+ "anyOf": [
215
+ {
216
+ "type": "boolean"
217
+ },
218
+ {
219
+ "type": "null"
220
+ }
221
+ ],
222
+ "title": "Allows Public Writes"
223
+ },
224
+ "authenticated": {
225
+ "anyOf": [
226
+ {
227
+ "type": "boolean"
228
+ },
229
+ {
230
+ "type": "null"
231
+ }
232
+ ],
233
+ "title": "Authenticated"
234
+ },
235
+ "public": {
236
+ "title": "Public",
237
+ "type": "boolean"
238
+ },
239
+ "public_reason": {
240
+ "anyOf": [
241
+ {
242
+ "type": "string"
243
+ },
244
+ {
245
+ "type": "null"
246
+ }
247
+ ],
248
+ "title": "Public Reason"
249
+ },
250
+ "read": {
251
+ "anyOf": [
252
+ {
253
+ "type": "string"
254
+ },
255
+ {
256
+ "type": "null"
257
+ }
258
+ ],
259
+ "title": "Read"
260
+ },
261
+ "write": {
262
+ "anyOf": [
263
+ {
264
+ "type": "string"
265
+ },
266
+ {
267
+ "type": "null"
268
+ }
269
+ ],
270
+ "title": "Write"
271
+ }
272
+ },
273
+ "required": [
274
+ "public"
275
+ ],
276
+ "title": "AccessPolicyRead",
277
+ "type": "object"
278
+ },
279
+ "AccessRoleOutcomeRead": {
280
+ "description": "What one rung gets on one route, replayed through the kernel guard's own decision.",
281
+ "properties": {
282
+ "allowed": {
283
+ "title": "Allowed",
284
+ "type": "boolean"
285
+ },
286
+ "reason": {
287
+ "title": "Reason",
288
+ "type": "string"
289
+ },
290
+ "role": {
291
+ "title": "Role",
292
+ "type": "string"
293
+ }
294
+ },
295
+ "required": [
296
+ "role",
297
+ "allowed",
298
+ "reason"
299
+ ],
300
+ "title": "AccessRoleOutcomeRead",
301
+ "type": "object"
302
+ },
303
+ "AccessRoleRead": {
304
+ "description": "One rung of the app's declared ladder.",
305
+ "properties": {
306
+ "name": {
307
+ "title": "Name",
308
+ "type": "string"
309
+ },
310
+ "rank": {
311
+ "title": "Rank",
312
+ "type": "integer"
313
+ }
314
+ },
315
+ "required": [
316
+ "name",
317
+ "rank"
318
+ ],
319
+ "title": "AccessRoleRead",
320
+ "type": "object"
321
+ },
4
322
  "AccessToken": {
5
323
  "properties": {
6
324
  "access_token": {
@@ -104,6 +422,14 @@
104
422
  "title": "Id",
105
423
  "type": "string"
106
424
  },
425
+ "module_ranks": {
426
+ "additionalProperties": {
427
+ "type": "integer"
428
+ },
429
+ "default": {},
430
+ "title": "Module Ranks",
431
+ "type": "object"
432
+ },
107
433
  "permissions": {
108
434
  "default": [],
109
435
  "items": {
@@ -354,37 +680,219 @@
354
680
  "title": "GroupUpdate",
355
681
  "type": "object"
356
682
  },
357
- "HTTPValidationError": {
683
+ "HTTPValidationError": {
684
+ "properties": {
685
+ "detail": {
686
+ "items": {
687
+ "$ref": "#/components/schemas/ValidationError"
688
+ },
689
+ "title": "Detail",
690
+ "type": "array"
691
+ }
692
+ },
693
+ "title": "HTTPValidationError",
694
+ "type": "object"
695
+ },
696
+ "HeldModuleRoleRead": {
697
+ "description": "One per-module rung a subject holds, and why.",
698
+ "properties": {
699
+ "effective": {
700
+ "title": "Effective",
701
+ "type": "boolean"
702
+ },
703
+ "module": {
704
+ "title": "Module",
705
+ "type": "string"
706
+ },
707
+ "role": {
708
+ "anyOf": [
709
+ {
710
+ "type": "string"
711
+ },
712
+ {
713
+ "type": "null"
714
+ }
715
+ ],
716
+ "title": "Role"
717
+ },
718
+ "role_rank": {
719
+ "title": "Role Rank",
720
+ "type": "integer"
721
+ },
722
+ "stale": {
723
+ "items": {
724
+ "type": "string"
725
+ },
726
+ "title": "Stale",
727
+ "type": "array"
728
+ },
729
+ "via": {
730
+ "$ref": "#/components/schemas/SubjectRefRead"
731
+ }
732
+ },
733
+ "required": [
734
+ "module",
735
+ "role_rank",
736
+ "role",
737
+ "effective",
738
+ "stale",
739
+ "via"
740
+ ],
741
+ "title": "HeldModuleRoleRead",
742
+ "type": "object"
743
+ },
744
+ "HeldPermissionRead": {
745
+ "description": "One permission a subject holds, and why.",
746
+ "properties": {
747
+ "declared": {
748
+ "title": "Declared",
749
+ "type": "boolean"
750
+ },
751
+ "label": {
752
+ "anyOf": [
753
+ {
754
+ "type": "string"
755
+ },
756
+ {
757
+ "type": "null"
758
+ }
759
+ ],
760
+ "title": "Label"
761
+ },
762
+ "name": {
763
+ "title": "Name",
764
+ "type": "string"
765
+ },
766
+ "via": {
767
+ "$ref": "#/components/schemas/SubjectRefRead"
768
+ }
769
+ },
770
+ "required": [
771
+ "name",
772
+ "label",
773
+ "declared",
774
+ "via"
775
+ ],
776
+ "title": "HeldPermissionRead",
777
+ "type": "object"
778
+ },
779
+ "LoginRequest": {
780
+ "properties": {
781
+ "email": {
782
+ "maxLength": 320,
783
+ "title": "Email",
784
+ "type": "string"
785
+ },
786
+ "password": {
787
+ "maxLength": 256,
788
+ "title": "Password",
789
+ "type": "string"
790
+ }
791
+ },
792
+ "required": [
793
+ "email",
794
+ "password"
795
+ ],
796
+ "title": "LoginRequest",
797
+ "type": "object"
798
+ },
799
+ "ModuleAccessRead": {
800
+ "description": "Whether a module takes part in per-module role assignment (ADR 0121).",
801
+ "properties": {
802
+ "assignable": {
803
+ "title": "Assignable",
804
+ "type": "boolean"
805
+ },
806
+ "label": {
807
+ "anyOf": [
808
+ {
809
+ "type": "string"
810
+ },
811
+ {
812
+ "type": "null"
813
+ }
814
+ ],
815
+ "title": "Label"
816
+ },
817
+ "platform_reason": {
818
+ "anyOf": [
819
+ {
820
+ "type": "string"
821
+ },
822
+ {
823
+ "type": "null"
824
+ }
825
+ ],
826
+ "title": "Platform Reason"
827
+ }
828
+ },
829
+ "required": [
830
+ "assignable",
831
+ "label",
832
+ "platform_reason"
833
+ ],
834
+ "title": "ModuleAccessRead",
835
+ "type": "object"
836
+ },
837
+ "ModuleRoleAssign": {
838
+ "description": "The body of an assignment whose subject and module are already in the path.\n\nAddressed by ``(subject_id, module)`` rather than by row id, because that pair *is* the\nfact's identity \u2014 the table's unique constraint says so, and\n:meth:`ModuleRoleService.assign` is already idempotent on it. A surrogate id in the URL\nwould make the caller fetch a row before it could change one, and would let two requests\nthat mean the same thing address it differently.",
358
839
  "properties": {
359
- "detail": {
360
- "items": {
361
- "$ref": "#/components/schemas/ValidationError"
362
- },
363
- "title": "Detail",
364
- "type": "array"
840
+ "role_rank": {
841
+ "title": "Role Rank",
842
+ "type": "integer"
365
843
  }
366
844
  },
367
- "title": "HTTPValidationError",
845
+ "required": [
846
+ "role_rank"
847
+ ],
848
+ "title": "ModuleRoleAssign",
368
849
  "type": "object"
369
850
  },
370
- "LoginRequest": {
851
+ "ModuleRoleRead": {
371
852
  "properties": {
372
- "email": {
373
- "maxLength": 320,
374
- "title": "Email",
853
+ "created_at": {
854
+ "format": "date-time",
855
+ "title": "Created At",
375
856
  "type": "string"
376
857
  },
377
- "password": {
378
- "maxLength": 256,
379
- "title": "Password",
858
+ "id": {
859
+ "format": "uuid",
860
+ "title": "Id",
861
+ "type": "string"
862
+ },
863
+ "module": {
864
+ "title": "Module",
865
+ "type": "string"
866
+ },
867
+ "role_rank": {
868
+ "title": "Role Rank",
869
+ "type": "integer"
870
+ },
871
+ "subject_id": {
872
+ "format": "uuid",
873
+ "title": "Subject Id",
874
+ "type": "string"
875
+ },
876
+ "updated_at": {
877
+ "format": "date-time",
878
+ "title": "Updated At",
380
879
  "type": "string"
880
+ },
881
+ "version": {
882
+ "title": "Version",
883
+ "type": "integer"
381
884
  }
382
885
  },
383
886
  "required": [
384
- "email",
385
- "password"
887
+ "id",
888
+ "subject_id",
889
+ "module",
890
+ "role_rank",
891
+ "version",
892
+ "created_at",
893
+ "updated_at"
386
894
  ],
387
- "title": "LoginRequest",
895
+ "title": "ModuleRoleRead",
388
896
  "type": "object"
389
897
  },
390
898
  "Page_AuditEventRead_": {
@@ -542,6 +1050,77 @@
542
1050
  "title": "Page[UserRead]",
543
1051
  "type": "object"
544
1052
  },
1053
+ "SubjectAccessRead": {
1054
+ "description": "One subject's effective access, with the provenance of every right.\n\nThe answer to \"why can this person do that?\", which is the only defence an administrator\nhas against an over-broad grant. It reports what is *held*; what that lets someone do on a\ngiven route is the declared model's question (``GET /model``), and a pane joins the two.\n\nIt deliberately does **not** carry the subject's global rank. That lives in the users\ntable, which this capability cannot import \u2014 its whole premise is being a leaf the\nidentity modules depend on rather than the reverse \u2014 and a field nothing here could ever\nfill would be structurally null. A pane already fetches the account to show its detail\nscreen, so it has the rank; adding a seam to duplicate it here would be a second source\nof truth for one integer.",
1055
+ "properties": {
1056
+ "module_roles": {
1057
+ "items": {
1058
+ "$ref": "#/components/schemas/HeldModuleRoleRead"
1059
+ },
1060
+ "title": "Module Roles",
1061
+ "type": "array"
1062
+ },
1063
+ "permissions": {
1064
+ "items": {
1065
+ "$ref": "#/components/schemas/HeldPermissionRead"
1066
+ },
1067
+ "title": "Permissions",
1068
+ "type": "array"
1069
+ },
1070
+ "subject_id": {
1071
+ "format": "uuid",
1072
+ "title": "Subject Id",
1073
+ "type": "string"
1074
+ },
1075
+ "via": {
1076
+ "items": {
1077
+ "$ref": "#/components/schemas/SubjectRefRead"
1078
+ },
1079
+ "title": "Via",
1080
+ "type": "array"
1081
+ }
1082
+ },
1083
+ "required": [
1084
+ "subject_id",
1085
+ "via",
1086
+ "permissions",
1087
+ "module_roles"
1088
+ ],
1089
+ "title": "SubjectAccessRead",
1090
+ "type": "object"
1091
+ },
1092
+ "SubjectRefRead": {
1093
+ "description": "Where a right came from: the caller themselves, or a group they belong to.",
1094
+ "properties": {
1095
+ "id": {
1096
+ "format": "uuid",
1097
+ "title": "Id",
1098
+ "type": "string"
1099
+ },
1100
+ "kind": {
1101
+ "title": "Kind",
1102
+ "type": "string"
1103
+ },
1104
+ "name": {
1105
+ "anyOf": [
1106
+ {
1107
+ "type": "string"
1108
+ },
1109
+ {
1110
+ "type": "null"
1111
+ }
1112
+ ],
1113
+ "title": "Name"
1114
+ }
1115
+ },
1116
+ "required": [
1117
+ "id",
1118
+ "kind",
1119
+ "name"
1120
+ ],
1121
+ "title": "SubjectRefRead",
1122
+ "type": "object"
1123
+ },
545
1124
  "UserAdminUpdate": {
546
1125
  "additionalProperties": false,
547
1126
  "description": "Admin edits a user's email / role rank (OCC ``version`` required).\n\nActivation state is changed through the dedicated ``deactivate`` /\n``reactivate`` actions, not this generic patch.",
@@ -863,6 +1442,177 @@
863
1442
  ]
864
1443
  }
865
1444
  },
1445
+ "/api/v1/access/model": {
1446
+ "get": {
1447
+ "description": "The declared authority surface: the ladder, the permissions, and every module.\n\nThe read half of a permission editor, and the reason the projection it is built on moved\ninto the kernel: this capability cannot import ``terp.cli``, where ``terp inspect access``\nlives. One builder, so the pane and the audit view cannot disagree about who may do what.\n\nDerivation over what ``create_app`` recorded on ``app.state`` \u2014 no database read at all,\nwhich is why it says nothing about *who holds* anything. That question needs the grant\nrows and is a different endpoint.\n\nAdmin-only, through this module's own ``Policy``. The permission topology is a map of\nwhere the doors are, so it is not something an under-privileged caller should be able to\nenumerate; a caller asking what *they themselves* may do is answered by ``GET /me``\n(ADR 0096), which needs no privilege because it only ever reports the caller's own.",
1448
+ "operationId": "access.get_model",
1449
+ "responses": {
1450
+ "200": {
1451
+ "content": {
1452
+ "application/json": {
1453
+ "schema": {
1454
+ "$ref": "#/components/schemas/AccessModelRead"
1455
+ }
1456
+ }
1457
+ },
1458
+ "description": "Successful Response"
1459
+ }
1460
+ },
1461
+ "summary": "See which roles exist and what each one may do",
1462
+ "tags": [
1463
+ "access"
1464
+ ]
1465
+ }
1466
+ },
1467
+ "/api/v1/access/subjects/{subject_id}": {
1468
+ "get": {
1469
+ "description": "One subject's effective access, with the provenance of every right.\n\n\"Why can this person do that?\" is the question an administrator has to be able to answer\nbefore any of this is safe, and it is the one a matrix of effective answers cannot answer\non its own. Every row here names the subject it came from \u2014 the person themselves, or a\ngroup they belong to \u2014 because a right whose origin is unknown is a right nobody can\nremove with confidence.\n\nTwo things are reported rather than filtered. A grant naming a permission the app no\nlonger declares comes back with ``declared: false``, and a module role at an undeclared\nrank or in a module that no longer accepts them comes back with its reason in ``stale`` \u2014\non the reasoning ``terp grant list`` gives, that a filtered row is a right nobody can\nexplain. And where several module rows exist for one module, only the highest is marked\n``effective``, which is the thing most often misread: assigning a lower rung alongside a\nhigher one changes nothing at all.",
1470
+ "operationId": "access.get_subject",
1471
+ "parameters": [
1472
+ {
1473
+ "in": "path",
1474
+ "name": "subject_id",
1475
+ "required": true,
1476
+ "schema": {
1477
+ "format": "uuid",
1478
+ "title": "Subject Id",
1479
+ "type": "string"
1480
+ }
1481
+ }
1482
+ ],
1483
+ "responses": {
1484
+ "200": {
1485
+ "content": {
1486
+ "application/json": {
1487
+ "schema": {
1488
+ "$ref": "#/components/schemas/SubjectAccessRead"
1489
+ }
1490
+ }
1491
+ },
1492
+ "description": "Successful Response"
1493
+ },
1494
+ "422": {
1495
+ "content": {
1496
+ "application/json": {
1497
+ "schema": {
1498
+ "$ref": "#/components/schemas/HTTPValidationError"
1499
+ }
1500
+ }
1501
+ },
1502
+ "description": "Validation Error"
1503
+ }
1504
+ },
1505
+ "summary": "See what someone can do, and where each right comes from",
1506
+ "tags": [
1507
+ "access"
1508
+ ]
1509
+ }
1510
+ },
1511
+ "/api/v1/access/subjects/{subject_id}/module-roles/{module}": {
1512
+ "delete": {
1513
+ "operationId": "access.revoke_module_role",
1514
+ "parameters": [
1515
+ {
1516
+ "in": "path",
1517
+ "name": "subject_id",
1518
+ "required": true,
1519
+ "schema": {
1520
+ "format": "uuid",
1521
+ "title": "Subject Id",
1522
+ "type": "string"
1523
+ }
1524
+ },
1525
+ {
1526
+ "in": "path",
1527
+ "name": "module",
1528
+ "required": true,
1529
+ "schema": {
1530
+ "title": "Module",
1531
+ "type": "string"
1532
+ }
1533
+ }
1534
+ ],
1535
+ "responses": {
1536
+ "204": {
1537
+ "description": "Successful Response"
1538
+ },
1539
+ "422": {
1540
+ "content": {
1541
+ "application/json": {
1542
+ "schema": {
1543
+ "$ref": "#/components/schemas/HTTPValidationError"
1544
+ }
1545
+ }
1546
+ },
1547
+ "description": "Validation Error"
1548
+ }
1549
+ },
1550
+ "summary": "Take away someone's role inside one module",
1551
+ "tags": [
1552
+ "access"
1553
+ ]
1554
+ },
1555
+ "put": {
1556
+ "operationId": "access.assign_module_role",
1557
+ "parameters": [
1558
+ {
1559
+ "in": "path",
1560
+ "name": "subject_id",
1561
+ "required": true,
1562
+ "schema": {
1563
+ "format": "uuid",
1564
+ "title": "Subject Id",
1565
+ "type": "string"
1566
+ }
1567
+ },
1568
+ {
1569
+ "in": "path",
1570
+ "name": "module",
1571
+ "required": true,
1572
+ "schema": {
1573
+ "title": "Module",
1574
+ "type": "string"
1575
+ }
1576
+ }
1577
+ ],
1578
+ "requestBody": {
1579
+ "content": {
1580
+ "application/json": {
1581
+ "schema": {
1582
+ "$ref": "#/components/schemas/ModuleRoleAssign"
1583
+ }
1584
+ }
1585
+ },
1586
+ "required": true
1587
+ },
1588
+ "responses": {
1589
+ "200": {
1590
+ "content": {
1591
+ "application/json": {
1592
+ "schema": {
1593
+ "$ref": "#/components/schemas/ModuleRoleRead"
1594
+ }
1595
+ }
1596
+ },
1597
+ "description": "Successful Response"
1598
+ },
1599
+ "422": {
1600
+ "content": {
1601
+ "application/json": {
1602
+ "schema": {
1603
+ "$ref": "#/components/schemas/HTTPValidationError"
1604
+ }
1605
+ }
1606
+ },
1607
+ "description": "Validation Error"
1608
+ }
1609
+ },
1610
+ "summary": "Give someone a role inside one module",
1611
+ "tags": [
1612
+ "access"
1613
+ ]
1614
+ }
1615
+ },
866
1616
  "/api/v1/audit/": {
867
1617
  "get": {
868
1618
  "operationId": "audit.list_events",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/contract",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "description": "Terp frontend contract \u2014 the OpenAPI-generated TypeScript client, design tokens, and the stack-agnostic module/route/nav + auth types.",
6
6
  "exports": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "openapi-typescript": "^7.13.0",
25
- "style-dictionary": "^5.5.0",
25
+ "style-dictionary": "^5.5.2",
26
26
  "vitest": "^4.1.9"
27
27
  },
28
28
  "dependencies": {
package/src/auth.ts CHANGED
@@ -38,6 +38,13 @@ export interface AuthSession {
38
38
  currentUser(): CurrentUser | null;
39
39
  /** True while the provider is resolving an existing session (e.g. boot refresh). */
40
40
  loading(): boolean;
41
- /** UI gate: may the current user perform `action`? (Honours the backend roles.) */
42
- can(action: Action): boolean;
41
+ /**
42
+ * UI gate: may the current user perform `action`? (Honours the backend roles.)
43
+ *
44
+ * `module` names the module the action happens in. Pass it and a per-module rung the caller
45
+ * holds there raises the answer, which is what the server's guard does (ADR 0121) — omit it
46
+ * and the gate is the global rank alone. Omitting it on a module's own screen is the shape
47
+ * that hid a module the caller could actually reach.
48
+ */
49
+ can(action: Action, module?: string): boolean;
43
50
  }
package/src/schema.d.ts CHANGED
@@ -39,6 +39,91 @@ export interface paths {
39
39
  patch?: never;
40
40
  trace?: never;
41
41
  };
42
+ "/api/v1/access/model": {
43
+ parameters: {
44
+ query?: never;
45
+ header?: never;
46
+ path?: never;
47
+ cookie?: never;
48
+ };
49
+ /**
50
+ * See which roles exist and what each one may do
51
+ * @description The declared authority surface: the ladder, the permissions, and every module.
52
+ *
53
+ * The read half of a permission editor, and the reason the projection it is built on moved
54
+ * into the kernel: this capability cannot import ``terp.cli``, where ``terp inspect access``
55
+ * lives. One builder, so the pane and the audit view cannot disagree about who may do what.
56
+ *
57
+ * Derivation over what ``create_app`` recorded on ``app.state`` — no database read at all,
58
+ * which is why it says nothing about *who holds* anything. That question needs the grant
59
+ * rows and is a different endpoint.
60
+ *
61
+ * Admin-only, through this module's own ``Policy``. The permission topology is a map of
62
+ * where the doors are, so it is not something an under-privileged caller should be able to
63
+ * enumerate; a caller asking what *they themselves* may do is answered by ``GET /me``
64
+ * (ADR 0096), which needs no privilege because it only ever reports the caller's own.
65
+ */
66
+ get: operations["access.get_model"];
67
+ put?: never;
68
+ post?: never;
69
+ delete?: never;
70
+ options?: never;
71
+ head?: never;
72
+ patch?: never;
73
+ trace?: never;
74
+ };
75
+ "/api/v1/access/subjects/{subject_id}": {
76
+ parameters: {
77
+ query?: never;
78
+ header?: never;
79
+ path?: never;
80
+ cookie?: never;
81
+ };
82
+ /**
83
+ * See what someone can do, and where each right comes from
84
+ * @description One subject's effective access, with the provenance of every right.
85
+ *
86
+ * "Why can this person do that?" is the question an administrator has to be able to answer
87
+ * before any of this is safe, and it is the one a matrix of effective answers cannot answer
88
+ * on its own. Every row here names the subject it came from — the person themselves, or a
89
+ * group they belong to — because a right whose origin is unknown is a right nobody can
90
+ * remove with confidence.
91
+ *
92
+ * Two things are reported rather than filtered. A grant naming a permission the app no
93
+ * longer declares comes back with ``declared: false``, and a module role at an undeclared
94
+ * rank or in a module that no longer accepts them comes back with its reason in ``stale`` —
95
+ * on the reasoning ``terp grant list`` gives, that a filtered row is a right nobody can
96
+ * explain. And where several module rows exist for one module, only the highest is marked
97
+ * ``effective``, which is the thing most often misread: assigning a lower rung alongside a
98
+ * higher one changes nothing at all.
99
+ */
100
+ get: operations["access.get_subject"];
101
+ put?: never;
102
+ post?: never;
103
+ delete?: never;
104
+ options?: never;
105
+ head?: never;
106
+ patch?: never;
107
+ trace?: never;
108
+ };
109
+ "/api/v1/access/subjects/{subject_id}/module-roles/{module}": {
110
+ parameters: {
111
+ query?: never;
112
+ header?: never;
113
+ path?: never;
114
+ cookie?: never;
115
+ };
116
+ get?: never;
117
+ /** Give someone a role inside one module */
118
+ put: operations["access.assign_module_role"];
119
+ post?: never;
120
+ /** Take away someone's role inside one module */
121
+ delete: operations["access.revoke_module_role"];
122
+ options?: never;
123
+ head?: never;
124
+ patch?: never;
125
+ trace?: never;
126
+ };
42
127
  "/api/v1/audit/": {
43
128
  parameters: {
44
129
  query?: never;
@@ -327,6 +412,115 @@ export interface paths {
327
412
  export type webhooks = Record<string, never>;
328
413
  export interface components {
329
414
  schemas: {
415
+ /**
416
+ * AccessEndpointRead
417
+ * @description One mounted route and the authority that applies to it.
418
+ */
419
+ AccessEndpointRead: {
420
+ /** By Role */
421
+ by_role: components["schemas"]["AccessRoleOutcomeRead"][];
422
+ /** Extra Permissions */
423
+ extra_permissions: string[];
424
+ /** Methods */
425
+ methods: string[];
426
+ /** Name */
427
+ name: string;
428
+ operation: components["schemas"]["AccessOperationRead"] | null;
429
+ /** Path */
430
+ path: string;
431
+ /** Requirement */
432
+ requirement: string;
433
+ };
434
+ /**
435
+ * AccessModelRead
436
+ * @description The declared authority surface: the ladder, the permissions, and every module.
437
+ */
438
+ AccessModelRead: {
439
+ /** Modules */
440
+ modules: components["schemas"]["AccessModuleRead"][];
441
+ /** Permissions */
442
+ permissions: components["schemas"]["AccessPermissionRead"][];
443
+ /** Roles */
444
+ roles: components["schemas"]["AccessRoleRead"][];
445
+ };
446
+ /**
447
+ * AccessModuleRead
448
+ * @description One module's declared authority.
449
+ */
450
+ AccessModuleRead: {
451
+ access: components["schemas"]["ModuleAccessRead"] | null;
452
+ /** Endpoints */
453
+ endpoints: components["schemas"]["AccessEndpointRead"][];
454
+ /** Name */
455
+ name: string;
456
+ /** Permissions */
457
+ permissions: string[];
458
+ policy: components["schemas"]["AccessPolicyRead"] | null;
459
+ /** Prefix */
460
+ prefix: string | null;
461
+ };
462
+ /**
463
+ * AccessOperationRead
464
+ * @description What a route does, in the source language (ADR 0102).
465
+ */
466
+ AccessOperationRead: {
467
+ /** Id */
468
+ id: string;
469
+ /** Label */
470
+ label: string;
471
+ };
472
+ /**
473
+ * AccessPermissionRead
474
+ * @description One declared permission: its name, its rank floor, and what holding it buys.
475
+ */
476
+ AccessPermissionRead: {
477
+ /** Label */
478
+ label: string | null;
479
+ /** Min Role */
480
+ min_role: string;
481
+ /** Name */
482
+ name: string;
483
+ };
484
+ /**
485
+ * AccessPolicyRead
486
+ * @description A module's declared posture. ``public`` decides which of the other fields apply.
487
+ */
488
+ AccessPolicyRead: {
489
+ /** Allows Public Writes */
490
+ allows_public_writes?: boolean | null;
491
+ /** Authenticated */
492
+ authenticated?: boolean | null;
493
+ /** Public */
494
+ public: boolean;
495
+ /** Public Reason */
496
+ public_reason?: string | null;
497
+ /** Read */
498
+ read?: string | null;
499
+ /** Write */
500
+ write?: string | null;
501
+ };
502
+ /**
503
+ * AccessRoleOutcomeRead
504
+ * @description What one rung gets on one route, replayed through the kernel guard's own decision.
505
+ */
506
+ AccessRoleOutcomeRead: {
507
+ /** Allowed */
508
+ allowed: boolean;
509
+ /** Reason */
510
+ reason: string;
511
+ /** Role */
512
+ role: string;
513
+ };
514
+ /**
515
+ * AccessRoleRead
516
+ * @description One rung of the app's declared ladder.
517
+ */
518
+ AccessRoleRead: {
519
+ /** Name */
520
+ name: string;
521
+ /** Rank */
522
+ rank: number;
523
+ };
330
524
  /** AccessToken */
331
525
  AccessToken: {
332
526
  /** Access Token */
@@ -382,6 +576,13 @@ export interface components {
382
576
  * Format: uuid
383
577
  */
384
578
  id: string;
579
+ /**
580
+ * Module Ranks
581
+ * @default {}
582
+ */
583
+ module_ranks: {
584
+ [key: string]: number;
585
+ };
385
586
  /**
386
587
  * Permissions
387
588
  * @default []
@@ -515,6 +716,36 @@ export interface components {
515
716
  /** Detail */
516
717
  detail?: components["schemas"]["ValidationError"][];
517
718
  };
719
+ /**
720
+ * HeldModuleRoleRead
721
+ * @description One per-module rung a subject holds, and why.
722
+ */
723
+ HeldModuleRoleRead: {
724
+ /** Effective */
725
+ effective: boolean;
726
+ /** Module */
727
+ module: string;
728
+ /** Role */
729
+ role: string | null;
730
+ /** Role Rank */
731
+ role_rank: number;
732
+ /** Stale */
733
+ stale: string[];
734
+ via: components["schemas"]["SubjectRefRead"];
735
+ };
736
+ /**
737
+ * HeldPermissionRead
738
+ * @description One permission a subject holds, and why.
739
+ */
740
+ HeldPermissionRead: {
741
+ /** Declared */
742
+ declared: boolean;
743
+ /** Label */
744
+ label: string | null;
745
+ /** Name */
746
+ name: string;
747
+ via: components["schemas"]["SubjectRefRead"];
748
+ };
518
749
  /** LoginRequest */
519
750
  LoginRequest: {
520
751
  /** Email */
@@ -522,6 +753,61 @@ export interface components {
522
753
  /** Password */
523
754
  password: string;
524
755
  };
756
+ /**
757
+ * ModuleAccessRead
758
+ * @description Whether a module takes part in per-module role assignment (ADR 0121).
759
+ */
760
+ ModuleAccessRead: {
761
+ /** Assignable */
762
+ assignable: boolean;
763
+ /** Label */
764
+ label: string | null;
765
+ /** Platform Reason */
766
+ platform_reason: string | null;
767
+ };
768
+ /**
769
+ * ModuleRoleAssign
770
+ * @description The body of an assignment whose subject and module are already in the path.
771
+ *
772
+ * Addressed by ``(subject_id, module)`` rather than by row id, because that pair *is* the
773
+ * fact's identity — the table's unique constraint says so, and
774
+ * :meth:`ModuleRoleService.assign` is already idempotent on it. A surrogate id in the URL
775
+ * would make the caller fetch a row before it could change one, and would let two requests
776
+ * that mean the same thing address it differently.
777
+ */
778
+ ModuleRoleAssign: {
779
+ /** Role Rank */
780
+ role_rank: number;
781
+ };
782
+ /** ModuleRoleRead */
783
+ ModuleRoleRead: {
784
+ /**
785
+ * Created At
786
+ * Format: date-time
787
+ */
788
+ created_at: string;
789
+ /**
790
+ * Id
791
+ * Format: uuid
792
+ */
793
+ id: string;
794
+ /** Module */
795
+ module: string;
796
+ /** Role Rank */
797
+ role_rank: number;
798
+ /**
799
+ * Subject Id
800
+ * Format: uuid
801
+ */
802
+ subject_id: string;
803
+ /**
804
+ * Updated At
805
+ * Format: date-time
806
+ */
807
+ updated_at: string;
808
+ /** Version */
809
+ version: number;
810
+ };
525
811
  /** Page[AuditEventRead] */
526
812
  Page_AuditEventRead_: {
527
813
  /** Items */
@@ -577,6 +863,49 @@ export interface components {
577
863
  /** Total */
578
864
  total: number;
579
865
  };
866
+ /**
867
+ * SubjectAccessRead
868
+ * @description One subject's effective access, with the provenance of every right.
869
+ *
870
+ * The answer to "why can this person do that?", which is the only defence an administrator
871
+ * has against an over-broad grant. It reports what is *held*; what that lets someone do on a
872
+ * given route is the declared model's question (``GET /model``), and a pane joins the two.
873
+ *
874
+ * It deliberately does **not** carry the subject's global rank. That lives in the users
875
+ * table, which this capability cannot import — its whole premise is being a leaf the
876
+ * identity modules depend on rather than the reverse — and a field nothing here could ever
877
+ * fill would be structurally null. A pane already fetches the account to show its detail
878
+ * screen, so it has the rank; adding a seam to duplicate it here would be a second source
879
+ * of truth for one integer.
880
+ */
881
+ SubjectAccessRead: {
882
+ /** Module Roles */
883
+ module_roles: components["schemas"]["HeldModuleRoleRead"][];
884
+ /** Permissions */
885
+ permissions: components["schemas"]["HeldPermissionRead"][];
886
+ /**
887
+ * Subject Id
888
+ * Format: uuid
889
+ */
890
+ subject_id: string;
891
+ /** Via */
892
+ via: components["schemas"]["SubjectRefRead"][];
893
+ };
894
+ /**
895
+ * SubjectRefRead
896
+ * @description Where a right came from: the caller themselves, or a group they belong to.
897
+ */
898
+ SubjectRefRead: {
899
+ /**
900
+ * Id
901
+ * Format: uuid
902
+ */
903
+ id: string;
904
+ /** Kind */
905
+ kind: string;
906
+ /** Name */
907
+ name: string | null;
908
+ };
580
909
  /**
581
910
  * UserAdminUpdate
582
911
  * @description Admin edits a user's email / role rank (OCC ``version`` required).
@@ -768,6 +1097,123 @@ export interface operations {
768
1097
  };
769
1098
  };
770
1099
  };
1100
+ "access.get_model": {
1101
+ parameters: {
1102
+ query?: never;
1103
+ header?: never;
1104
+ path?: never;
1105
+ cookie?: never;
1106
+ };
1107
+ requestBody?: never;
1108
+ responses: {
1109
+ /** @description Successful Response */
1110
+ 200: {
1111
+ headers: {
1112
+ [name: string]: unknown;
1113
+ };
1114
+ content: {
1115
+ "application/json": components["schemas"]["AccessModelRead"];
1116
+ };
1117
+ };
1118
+ };
1119
+ };
1120
+ "access.get_subject": {
1121
+ parameters: {
1122
+ query?: never;
1123
+ header?: never;
1124
+ path: {
1125
+ subject_id: string;
1126
+ };
1127
+ cookie?: never;
1128
+ };
1129
+ requestBody?: never;
1130
+ responses: {
1131
+ /** @description Successful Response */
1132
+ 200: {
1133
+ headers: {
1134
+ [name: string]: unknown;
1135
+ };
1136
+ content: {
1137
+ "application/json": components["schemas"]["SubjectAccessRead"];
1138
+ };
1139
+ };
1140
+ /** @description Validation Error */
1141
+ 422: {
1142
+ headers: {
1143
+ [name: string]: unknown;
1144
+ };
1145
+ content: {
1146
+ "application/json": components["schemas"]["HTTPValidationError"];
1147
+ };
1148
+ };
1149
+ };
1150
+ };
1151
+ "access.assign_module_role": {
1152
+ parameters: {
1153
+ query?: never;
1154
+ header?: never;
1155
+ path: {
1156
+ subject_id: string;
1157
+ module: string;
1158
+ };
1159
+ cookie?: never;
1160
+ };
1161
+ requestBody: {
1162
+ content: {
1163
+ "application/json": components["schemas"]["ModuleRoleAssign"];
1164
+ };
1165
+ };
1166
+ responses: {
1167
+ /** @description Successful Response */
1168
+ 200: {
1169
+ headers: {
1170
+ [name: string]: unknown;
1171
+ };
1172
+ content: {
1173
+ "application/json": components["schemas"]["ModuleRoleRead"];
1174
+ };
1175
+ };
1176
+ /** @description Validation Error */
1177
+ 422: {
1178
+ headers: {
1179
+ [name: string]: unknown;
1180
+ };
1181
+ content: {
1182
+ "application/json": components["schemas"]["HTTPValidationError"];
1183
+ };
1184
+ };
1185
+ };
1186
+ };
1187
+ "access.revoke_module_role": {
1188
+ parameters: {
1189
+ query?: never;
1190
+ header?: never;
1191
+ path: {
1192
+ subject_id: string;
1193
+ module: string;
1194
+ };
1195
+ cookie?: never;
1196
+ };
1197
+ requestBody?: never;
1198
+ responses: {
1199
+ /** @description Successful Response */
1200
+ 204: {
1201
+ headers: {
1202
+ [name: string]: unknown;
1203
+ };
1204
+ content?: never;
1205
+ };
1206
+ /** @description Validation Error */
1207
+ 422: {
1208
+ headers: {
1209
+ [name: string]: unknown;
1210
+ };
1211
+ content: {
1212
+ "application/json": components["schemas"]["HTTPValidationError"];
1213
+ };
1214
+ };
1215
+ };
1216
+ };
771
1217
  "audit.list_events": {
772
1218
  parameters: {
773
1219
  query?: {