@contractspec/lib.identity-rbac 0.0.0-canary-20260113162409

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/dist/contracts/index.d.ts +4 -0
  4. package/dist/contracts/index.js +5 -0
  5. package/dist/contracts/organization.d.ts +896 -0
  6. package/dist/contracts/organization.d.ts.map +1 -0
  7. package/dist/contracts/organization.js +605 -0
  8. package/dist/contracts/organization.js.map +1 -0
  9. package/dist/contracts/rbac.d.ts +612 -0
  10. package/dist/contracts/rbac.d.ts.map +1 -0
  11. package/dist/contracts/rbac.js +484 -0
  12. package/dist/contracts/rbac.js.map +1 -0
  13. package/dist/contracts/user.d.ts +611 -0
  14. package/dist/contracts/user.d.ts.map +1 -0
  15. package/dist/contracts/user.js +333 -0
  16. package/dist/contracts/user.js.map +1 -0
  17. package/dist/entities/index.d.ts +177 -0
  18. package/dist/entities/index.d.ts.map +1 -0
  19. package/dist/entities/index.js +36 -0
  20. package/dist/entities/index.js.map +1 -0
  21. package/dist/entities/organization.d.ts +87 -0
  22. package/dist/entities/organization.d.ts.map +1 -0
  23. package/dist/entities/organization.js +151 -0
  24. package/dist/entities/organization.js.map +1 -0
  25. package/dist/entities/rbac.d.ts +88 -0
  26. package/dist/entities/rbac.d.ts.map +1 -0
  27. package/dist/entities/rbac.js +138 -0
  28. package/dist/entities/rbac.js.map +1 -0
  29. package/dist/entities/user.d.ts +88 -0
  30. package/dist/entities/user.d.ts.map +1 -0
  31. package/dist/entities/user.js +194 -0
  32. package/dist/entities/user.js.map +1 -0
  33. package/dist/events.d.ts +690 -0
  34. package/dist/events.d.ts.map +1 -0
  35. package/dist/events.js +683 -0
  36. package/dist/events.js.map +1 -0
  37. package/dist/identity-rbac.capability.d.ts +8 -0
  38. package/dist/identity-rbac.capability.d.ts.map +1 -0
  39. package/dist/identity-rbac.capability.js +29 -0
  40. package/dist/identity-rbac.capability.js.map +1 -0
  41. package/dist/identity-rbac.feature.d.ts +12 -0
  42. package/dist/identity-rbac.feature.d.ts.map +1 -0
  43. package/dist/identity-rbac.feature.js +195 -0
  44. package/dist/identity-rbac.feature.js.map +1 -0
  45. package/dist/index.d.ts +12 -0
  46. package/dist/index.js +14 -0
  47. package/dist/policies/engine.d.ts +133 -0
  48. package/dist/policies/engine.d.ts.map +1 -0
  49. package/dist/policies/engine.js +168 -0
  50. package/dist/policies/engine.js.map +1 -0
  51. package/dist/policies/index.d.ts +2 -0
  52. package/dist/policies/index.js +3 -0
  53. package/package.json +85 -0
@@ -0,0 +1,484 @@
1
+ import { SuccessResultModel } from "./user.js";
2
+ import { ScalarTypeEnum, SchemaModel } from "@contractspec/lib.schema";
3
+ import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
4
+
5
+ //#region src/contracts/rbac.ts
6
+ const RoleModel = new SchemaModel({
7
+ name: "Role",
8
+ description: "RBAC role definition",
9
+ fields: {
10
+ id: {
11
+ type: ScalarTypeEnum.String_unsecure(),
12
+ isOptional: false
13
+ },
14
+ name: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false
17
+ },
18
+ description: {
19
+ type: ScalarTypeEnum.String_unsecure(),
20
+ isOptional: true
21
+ },
22
+ permissions: {
23
+ type: ScalarTypeEnum.String_unsecure(),
24
+ isOptional: false,
25
+ isArray: true
26
+ },
27
+ createdAt: {
28
+ type: ScalarTypeEnum.DateTime(),
29
+ isOptional: false
30
+ }
31
+ }
32
+ });
33
+ const PolicyBindingModel = new SchemaModel({
34
+ name: "PolicyBinding",
35
+ description: "Role assignment to a target",
36
+ fields: {
37
+ id: {
38
+ type: ScalarTypeEnum.String_unsecure(),
39
+ isOptional: false
40
+ },
41
+ roleId: {
42
+ type: ScalarTypeEnum.String_unsecure(),
43
+ isOptional: false
44
+ },
45
+ targetType: {
46
+ type: ScalarTypeEnum.String_unsecure(),
47
+ isOptional: false
48
+ },
49
+ targetId: {
50
+ type: ScalarTypeEnum.String_unsecure(),
51
+ isOptional: false
52
+ },
53
+ expiresAt: {
54
+ type: ScalarTypeEnum.DateTime(),
55
+ isOptional: true
56
+ },
57
+ createdAt: {
58
+ type: ScalarTypeEnum.DateTime(),
59
+ isOptional: false
60
+ },
61
+ role: {
62
+ type: RoleModel,
63
+ isOptional: false
64
+ }
65
+ }
66
+ });
67
+ const PermissionCheckResultModel = new SchemaModel({
68
+ name: "PermissionCheckResult",
69
+ description: "Result of a permission check",
70
+ fields: {
71
+ allowed: {
72
+ type: ScalarTypeEnum.Boolean(),
73
+ isOptional: false
74
+ },
75
+ reason: {
76
+ type: ScalarTypeEnum.String_unsecure(),
77
+ isOptional: true
78
+ },
79
+ matchedRole: {
80
+ type: ScalarTypeEnum.String_unsecure(),
81
+ isOptional: true
82
+ }
83
+ }
84
+ });
85
+ const CreateRoleInputModel = new SchemaModel({
86
+ name: "CreateRoleInput",
87
+ description: "Input for creating a role",
88
+ fields: {
89
+ name: {
90
+ type: ScalarTypeEnum.NonEmptyString(),
91
+ isOptional: false
92
+ },
93
+ description: {
94
+ type: ScalarTypeEnum.String_unsecure(),
95
+ isOptional: true
96
+ },
97
+ permissions: {
98
+ type: ScalarTypeEnum.String_unsecure(),
99
+ isOptional: false,
100
+ isArray: true
101
+ }
102
+ }
103
+ });
104
+ const UpdateRoleInputModel = new SchemaModel({
105
+ name: "UpdateRoleInput",
106
+ description: "Input for updating a role",
107
+ fields: {
108
+ roleId: {
109
+ type: ScalarTypeEnum.String_unsecure(),
110
+ isOptional: false
111
+ },
112
+ name: {
113
+ type: ScalarTypeEnum.String_unsecure(),
114
+ isOptional: true
115
+ },
116
+ description: {
117
+ type: ScalarTypeEnum.String_unsecure(),
118
+ isOptional: true
119
+ },
120
+ permissions: {
121
+ type: ScalarTypeEnum.String_unsecure(),
122
+ isOptional: true,
123
+ isArray: true
124
+ }
125
+ }
126
+ });
127
+ const DeleteRoleInputModel = new SchemaModel({
128
+ name: "DeleteRoleInput",
129
+ description: "Input for deleting a role",
130
+ fields: { roleId: {
131
+ type: ScalarTypeEnum.String_unsecure(),
132
+ isOptional: false
133
+ } }
134
+ });
135
+ const ListRolesOutputModel = new SchemaModel({
136
+ name: "ListRolesOutput",
137
+ description: "Output for listing roles",
138
+ fields: { roles: {
139
+ type: RoleModel,
140
+ isOptional: false,
141
+ isArray: true
142
+ } }
143
+ });
144
+ const AssignRoleInputModel = new SchemaModel({
145
+ name: "AssignRoleInput",
146
+ description: "Input for assigning a role",
147
+ fields: {
148
+ roleId: {
149
+ type: ScalarTypeEnum.String_unsecure(),
150
+ isOptional: false
151
+ },
152
+ targetType: {
153
+ type: ScalarTypeEnum.String_unsecure(),
154
+ isOptional: false
155
+ },
156
+ targetId: {
157
+ type: ScalarTypeEnum.String_unsecure(),
158
+ isOptional: false
159
+ },
160
+ expiresAt: {
161
+ type: ScalarTypeEnum.DateTime(),
162
+ isOptional: true
163
+ }
164
+ }
165
+ });
166
+ const RevokeRoleInputModel = new SchemaModel({
167
+ name: "RevokeRoleInput",
168
+ description: "Input for revoking a role",
169
+ fields: { bindingId: {
170
+ type: ScalarTypeEnum.String_unsecure(),
171
+ isOptional: false
172
+ } }
173
+ });
174
+ const BindingIdPayloadModel = new SchemaModel({
175
+ name: "BindingIdPayload",
176
+ description: "Payload with binding ID",
177
+ fields: { bindingId: {
178
+ type: ScalarTypeEnum.String_unsecure(),
179
+ isOptional: false
180
+ } }
181
+ });
182
+ const CheckPermissionInputModel = new SchemaModel({
183
+ name: "CheckPermissionInput",
184
+ description: "Input for checking a permission",
185
+ fields: {
186
+ userId: {
187
+ type: ScalarTypeEnum.String_unsecure(),
188
+ isOptional: false
189
+ },
190
+ orgId: {
191
+ type: ScalarTypeEnum.String_unsecure(),
192
+ isOptional: true
193
+ },
194
+ permission: {
195
+ type: ScalarTypeEnum.String_unsecure(),
196
+ isOptional: false
197
+ }
198
+ }
199
+ });
200
+ const ListUserPermissionsInputModel = new SchemaModel({
201
+ name: "ListUserPermissionsInput",
202
+ description: "Input for listing user permissions",
203
+ fields: {
204
+ userId: {
205
+ type: ScalarTypeEnum.String_unsecure(),
206
+ isOptional: false
207
+ },
208
+ orgId: {
209
+ type: ScalarTypeEnum.String_unsecure(),
210
+ isOptional: true
211
+ }
212
+ }
213
+ });
214
+ const ListUserPermissionsOutputModel = new SchemaModel({
215
+ name: "ListUserPermissionsOutput",
216
+ description: "Output for listing user permissions",
217
+ fields: {
218
+ permissions: {
219
+ type: ScalarTypeEnum.String_unsecure(),
220
+ isOptional: false,
221
+ isArray: true
222
+ },
223
+ roles: {
224
+ type: RoleModel,
225
+ isOptional: false,
226
+ isArray: true
227
+ }
228
+ }
229
+ });
230
+ /**
231
+ * Create a new role.
232
+ */
233
+ const CreateRoleContract = defineCommand({
234
+ meta: {
235
+ key: "identity.rbac.role.create",
236
+ version: "1.0.0",
237
+ stability: "stable",
238
+ owners: ["@platform.identity-rbac"],
239
+ tags: [
240
+ "identity",
241
+ "rbac",
242
+ "role",
243
+ "create"
244
+ ],
245
+ description: "Create a new role with permissions.",
246
+ goal: "Allow admins to define custom roles.",
247
+ context: "Role management in admin settings."
248
+ },
249
+ io: {
250
+ input: CreateRoleInputModel,
251
+ output: RoleModel,
252
+ errors: { ROLE_EXISTS: {
253
+ description: "A role with this name already exists",
254
+ http: 409,
255
+ gqlCode: "ROLE_EXISTS",
256
+ when: "Role name is taken"
257
+ } }
258
+ },
259
+ policy: { auth: "admin" },
260
+ sideEffects: { audit: ["role.created"] }
261
+ });
262
+ /**
263
+ * Update a role.
264
+ */
265
+ const UpdateRoleContract = defineCommand({
266
+ meta: {
267
+ key: "identity.rbac.role.update",
268
+ version: "1.0.0",
269
+ stability: "stable",
270
+ owners: ["@platform.identity-rbac"],
271
+ tags: [
272
+ "identity",
273
+ "rbac",
274
+ "role",
275
+ "update"
276
+ ],
277
+ description: "Update an existing role.",
278
+ goal: "Allow admins to modify role permissions.",
279
+ context: "Role management in admin settings."
280
+ },
281
+ io: {
282
+ input: UpdateRoleInputModel,
283
+ output: RoleModel
284
+ },
285
+ policy: { auth: "admin" },
286
+ sideEffects: { audit: ["role.updated"] }
287
+ });
288
+ /**
289
+ * Delete a role.
290
+ */
291
+ const DeleteRoleContract = defineCommand({
292
+ meta: {
293
+ key: "identity.rbac.role.delete",
294
+ version: "1.0.0",
295
+ stability: "stable",
296
+ owners: ["@platform.identity-rbac"],
297
+ tags: [
298
+ "identity",
299
+ "rbac",
300
+ "role",
301
+ "delete"
302
+ ],
303
+ description: "Delete an existing role.",
304
+ goal: "Allow admins to remove unused roles.",
305
+ context: "Role management. Removes all policy bindings using this role."
306
+ },
307
+ io: {
308
+ input: DeleteRoleInputModel,
309
+ output: SuccessResultModel,
310
+ errors: { ROLE_IN_USE: {
311
+ description: "Role is still assigned to users or organizations",
312
+ http: 409,
313
+ gqlCode: "ROLE_IN_USE",
314
+ when: "Role has active bindings"
315
+ } }
316
+ },
317
+ policy: { auth: "admin" },
318
+ sideEffects: { audit: ["role.deleted"] }
319
+ });
320
+ /**
321
+ * List all roles.
322
+ */
323
+ const ListRolesContract = defineQuery({
324
+ meta: {
325
+ key: "identity.rbac.role.list",
326
+ version: "1.0.0",
327
+ stability: "stable",
328
+ owners: ["@platform.identity-rbac"],
329
+ tags: [
330
+ "identity",
331
+ "rbac",
332
+ "role",
333
+ "list"
334
+ ],
335
+ description: "List all available roles.",
336
+ goal: "Show available roles for assignment.",
337
+ context: "Role assignment UI."
338
+ },
339
+ io: {
340
+ input: null,
341
+ output: ListRolesOutputModel
342
+ },
343
+ policy: { auth: "user" }
344
+ });
345
+ /**
346
+ * Assign a role to a user or organization.
347
+ */
348
+ const AssignRoleContract = defineCommand({
349
+ meta: {
350
+ key: "identity.rbac.assign",
351
+ version: "1.0.0",
352
+ stability: "stable",
353
+ owners: ["@platform.identity-rbac"],
354
+ tags: [
355
+ "identity",
356
+ "rbac",
357
+ "assign"
358
+ ],
359
+ description: "Assign a role to a user or organization.",
360
+ goal: "Grant permissions via role assignment.",
361
+ context: "User/org permission management."
362
+ },
363
+ io: {
364
+ input: AssignRoleInputModel,
365
+ output: PolicyBindingModel,
366
+ errors: {
367
+ ROLE_NOT_FOUND: {
368
+ description: "The specified role does not exist",
369
+ http: 404,
370
+ gqlCode: "ROLE_NOT_FOUND",
371
+ when: "Role ID is invalid"
372
+ },
373
+ ALREADY_ASSIGNED: {
374
+ description: "This role is already assigned to the target",
375
+ http: 409,
376
+ gqlCode: "ALREADY_ASSIGNED",
377
+ when: "Binding already exists"
378
+ }
379
+ }
380
+ },
381
+ policy: { auth: "admin" },
382
+ sideEffects: {
383
+ emits: [{
384
+ key: "role.assigned",
385
+ version: "1.0.0",
386
+ when: "Role is assigned",
387
+ payload: PolicyBindingModel
388
+ }],
389
+ audit: ["role.assigned"]
390
+ }
391
+ });
392
+ /**
393
+ * Revoke a role from a user or organization.
394
+ */
395
+ const RevokeRoleContract = defineCommand({
396
+ meta: {
397
+ key: "identity.rbac.revoke",
398
+ version: "1.0.0",
399
+ stability: "stable",
400
+ owners: ["@platform.identity-rbac"],
401
+ tags: [
402
+ "identity",
403
+ "rbac",
404
+ "revoke"
405
+ ],
406
+ description: "Revoke a role from a user or organization.",
407
+ goal: "Remove permissions via role revocation.",
408
+ context: "User/org permission management."
409
+ },
410
+ io: {
411
+ input: RevokeRoleInputModel,
412
+ output: SuccessResultModel,
413
+ errors: { BINDING_NOT_FOUND: {
414
+ description: "The policy binding does not exist",
415
+ http: 404,
416
+ gqlCode: "BINDING_NOT_FOUND",
417
+ when: "Binding ID is invalid"
418
+ } }
419
+ },
420
+ policy: { auth: "admin" },
421
+ sideEffects: {
422
+ emits: [{
423
+ key: "role.revoked",
424
+ version: "1.0.0",
425
+ when: "Role is revoked",
426
+ payload: BindingIdPayloadModel
427
+ }],
428
+ audit: ["role.revoked"]
429
+ }
430
+ });
431
+ /**
432
+ * Check if a user has a specific permission.
433
+ */
434
+ const CheckPermissionContract = defineQuery({
435
+ meta: {
436
+ key: "identity.rbac.check",
437
+ version: "1.0.0",
438
+ stability: "stable",
439
+ owners: ["@platform.identity-rbac"],
440
+ tags: [
441
+ "identity",
442
+ "rbac",
443
+ "check",
444
+ "permission"
445
+ ],
446
+ description: "Check if a user has a specific permission.",
447
+ goal: "Authorization check before sensitive operations.",
448
+ context: "Called by other services to verify permissions."
449
+ },
450
+ io: {
451
+ input: CheckPermissionInputModel,
452
+ output: PermissionCheckResultModel
453
+ },
454
+ policy: { auth: "user" }
455
+ });
456
+ /**
457
+ * List permissions for a user.
458
+ */
459
+ const ListUserPermissionsContract = defineQuery({
460
+ meta: {
461
+ key: "identity.rbac.permissions",
462
+ version: "1.0.0",
463
+ stability: "stable",
464
+ owners: ["@platform.identity-rbac"],
465
+ tags: [
466
+ "identity",
467
+ "rbac",
468
+ "permissions",
469
+ "user"
470
+ ],
471
+ description: "List all permissions for a user in a context.",
472
+ goal: "Show what a user can do in an org.",
473
+ context: "UI permission display, debugging."
474
+ },
475
+ io: {
476
+ input: ListUserPermissionsInputModel,
477
+ output: ListUserPermissionsOutputModel
478
+ },
479
+ policy: { auth: "user" }
480
+ });
481
+
482
+ //#endregion
483
+ export { AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateRoleContract, CreateRoleInputModel, DeleteRoleContract, DeleteRoleInputModel, ListRolesContract, ListRolesOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, PermissionCheckResultModel, PolicyBindingModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, UpdateRoleContract, UpdateRoleInputModel };
484
+ //# sourceMappingURL=rbac.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rbac.js","names":[],"sources":["../../src/contracts/rbac.ts"],"sourcesContent":["import { SchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';\nimport { defineCommand, defineQuery } from '@contractspec/lib.contracts';\nimport { SuccessResultModel } from './user';\n\n// ============ SchemaModels ============\n\nexport const RoleModel = new SchemaModel({\n name: 'Role',\n description: 'RBAC role definition',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n permissions: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n isArray: true,\n },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\nexport const PolicyBindingModel = new SchemaModel({\n name: 'PolicyBinding',\n description: 'Role assignment to a target',\n fields: {\n id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n roleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n targetType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // user | organization\n targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n expiresAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n role: { type: RoleModel, isOptional: false },\n },\n});\n\nexport const PermissionCheckResultModel = new SchemaModel({\n name: 'PermissionCheckResult',\n description: 'Result of a permission check',\n fields: {\n allowed: { type: ScalarTypeEnum.Boolean(), isOptional: false },\n reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n matchedRole: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\nexport const CreateRoleInputModel = new SchemaModel({\n name: 'CreateRoleInput',\n description: 'Input for creating a role',\n fields: {\n name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n permissions: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n isArray: true,\n },\n },\n});\n\nexport const UpdateRoleInputModel = new SchemaModel({\n name: 'UpdateRoleInput',\n description: 'Input for updating a role',\n fields: {\n roleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n permissions: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: true,\n isArray: true,\n },\n },\n});\n\nexport const DeleteRoleInputModel = new SchemaModel({\n name: 'DeleteRoleInput',\n description: 'Input for deleting a role',\n fields: {\n roleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const ListRolesOutputModel = new SchemaModel({\n name: 'ListRolesOutput',\n description: 'Output for listing roles',\n fields: {\n roles: { type: RoleModel, isOptional: false, isArray: true },\n },\n});\n\nexport const AssignRoleInputModel = new SchemaModel({\n name: 'AssignRoleInput',\n description: 'Input for assigning a role',\n fields: {\n roleId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n targetType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // user | organization\n targetId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n expiresAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },\n },\n});\n\nexport const RevokeRoleInputModel = new SchemaModel({\n name: 'RevokeRoleInput',\n description: 'Input for revoking a role',\n fields: {\n bindingId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const BindingIdPayloadModel = new SchemaModel({\n name: 'BindingIdPayload',\n description: 'Payload with binding ID',\n fields: {\n bindingId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const CheckPermissionInputModel = new SchemaModel({\n name: 'CheckPermissionInput',\n description: 'Input for checking a permission',\n fields: {\n userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n permission: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n },\n});\n\nexport const ListUserPermissionsInputModel = new SchemaModel({\n name: 'ListUserPermissionsInput',\n description: 'Input for listing user permissions',\n fields: {\n userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n orgId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },\n },\n});\n\nexport const ListUserPermissionsOutputModel = new SchemaModel({\n name: 'ListUserPermissionsOutput',\n description: 'Output for listing user permissions',\n fields: {\n permissions: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n isArray: true,\n },\n roles: { type: RoleModel, isOptional: false, isArray: true },\n },\n});\n\n// ============ Contracts ============\n\n/**\n * Create a new role.\n */\nexport const CreateRoleContract = defineCommand({\n meta: {\n key: 'identity.rbac.role.create',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'role', 'create'],\n description: 'Create a new role with permissions.',\n goal: 'Allow admins to define custom roles.',\n context: 'Role management in admin settings.',\n },\n io: {\n input: CreateRoleInputModel,\n output: RoleModel,\n errors: {\n ROLE_EXISTS: {\n description: 'A role with this name already exists',\n http: 409,\n gqlCode: 'ROLE_EXISTS',\n when: 'Role name is taken',\n },\n },\n },\n policy: {\n auth: 'admin',\n },\n sideEffects: {\n audit: ['role.created'],\n },\n});\n\n/**\n * Update a role.\n */\nexport const UpdateRoleContract = defineCommand({\n meta: {\n key: 'identity.rbac.role.update',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'role', 'update'],\n description: 'Update an existing role.',\n goal: 'Allow admins to modify role permissions.',\n context: 'Role management in admin settings.',\n },\n io: {\n input: UpdateRoleInputModel,\n output: RoleModel,\n },\n policy: {\n auth: 'admin',\n },\n sideEffects: {\n audit: ['role.updated'],\n },\n});\n\n/**\n * Delete a role.\n */\nexport const DeleteRoleContract = defineCommand({\n meta: {\n key: 'identity.rbac.role.delete',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'role', 'delete'],\n description: 'Delete an existing role.',\n goal: 'Allow admins to remove unused roles.',\n context: 'Role management. Removes all policy bindings using this role.',\n },\n io: {\n input: DeleteRoleInputModel,\n output: SuccessResultModel,\n errors: {\n ROLE_IN_USE: {\n description: 'Role is still assigned to users or organizations',\n http: 409,\n gqlCode: 'ROLE_IN_USE',\n when: 'Role has active bindings',\n },\n },\n },\n policy: {\n auth: 'admin',\n },\n sideEffects: {\n audit: ['role.deleted'],\n },\n});\n\n/**\n * List all roles.\n */\nexport const ListRolesContract = defineQuery({\n meta: {\n key: 'identity.rbac.role.list',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'role', 'list'],\n description: 'List all available roles.',\n goal: 'Show available roles for assignment.',\n context: 'Role assignment UI.',\n },\n io: {\n input: null,\n output: ListRolesOutputModel,\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * Assign a role to a user or organization.\n */\nexport const AssignRoleContract = defineCommand({\n meta: {\n key: 'identity.rbac.assign',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'assign'],\n description: 'Assign a role to a user or organization.',\n goal: 'Grant permissions via role assignment.',\n context: 'User/org permission management.',\n },\n io: {\n input: AssignRoleInputModel,\n output: PolicyBindingModel,\n errors: {\n ROLE_NOT_FOUND: {\n description: 'The specified role does not exist',\n http: 404,\n gqlCode: 'ROLE_NOT_FOUND',\n when: 'Role ID is invalid',\n },\n ALREADY_ASSIGNED: {\n description: 'This role is already assigned to the target',\n http: 409,\n gqlCode: 'ALREADY_ASSIGNED',\n when: 'Binding already exists',\n },\n },\n },\n policy: {\n auth: 'admin',\n },\n sideEffects: {\n emits: [\n {\n key: 'role.assigned',\n version: '1.0.0',\n when: 'Role is assigned',\n payload: PolicyBindingModel,\n },\n ],\n audit: ['role.assigned'],\n },\n});\n\n/**\n * Revoke a role from a user or organization.\n */\nexport const RevokeRoleContract = defineCommand({\n meta: {\n key: 'identity.rbac.revoke',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'revoke'],\n description: 'Revoke a role from a user or organization.',\n goal: 'Remove permissions via role revocation.',\n context: 'User/org permission management.',\n },\n io: {\n input: RevokeRoleInputModel,\n output: SuccessResultModel,\n errors: {\n BINDING_NOT_FOUND: {\n description: 'The policy binding does not exist',\n http: 404,\n gqlCode: 'BINDING_NOT_FOUND',\n when: 'Binding ID is invalid',\n },\n },\n },\n policy: {\n auth: 'admin',\n },\n sideEffects: {\n emits: [\n {\n key: 'role.revoked',\n version: '1.0.0',\n when: 'Role is revoked',\n payload: BindingIdPayloadModel,\n },\n ],\n audit: ['role.revoked'],\n },\n});\n\n/**\n * Check if a user has a specific permission.\n */\nexport const CheckPermissionContract = defineQuery({\n meta: {\n key: 'identity.rbac.check',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'check', 'permission'],\n description: 'Check if a user has a specific permission.',\n goal: 'Authorization check before sensitive operations.',\n context: 'Called by other services to verify permissions.',\n },\n io: {\n input: CheckPermissionInputModel,\n output: PermissionCheckResultModel,\n },\n policy: {\n auth: 'user',\n },\n});\n\n/**\n * List permissions for a user.\n */\nexport const ListUserPermissionsContract = defineQuery({\n meta: {\n key: 'identity.rbac.permissions',\n version: '1.0.0',\n stability: 'stable',\n owners: ['@platform.identity-rbac'],\n tags: ['identity', 'rbac', 'permissions', 'user'],\n description: 'List all permissions for a user in a context.',\n goal: 'Show what a user can do in an org.',\n context: 'UI permission display, debugging.',\n },\n io: {\n input: ListUserPermissionsInputModel,\n output: ListUserPermissionsOutputModel,\n },\n policy: {\n auth: 'user',\n },\n});\n"],"mappings":";;;;;AAMA,MAAa,YAAY,IAAI,YAAY;CACvC,MAAM;CACN,aAAa;CACb,QAAQ;EACN,IAAI;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACjE,MAAM;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAO;EACnE,aAAa;GAAE,MAAM,eAAe,iBAAiB;GAAE,YAAY;GAAM;EACzE,aAAa;GACX,MAAM,eAAe,iBAAiB;GACtC,YAAY;GACZ,SAAS;GACV;EACD,WAAW;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