@contractspec/lib.identity-rbac 3.7.17 → 3.7.18

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 (43) hide show
  1. package/dist/browser/contracts/index.js +1 -1045
  2. package/dist/browser/contracts/organization.js +1 -655
  3. package/dist/browser/contracts/rbac.js +1 -599
  4. package/dist/browser/contracts/user.js +1 -235
  5. package/dist/browser/entities/index.js +1 -464
  6. package/dist/browser/entities/organization.js +1 -150
  7. package/dist/browser/entities/rbac.js +1 -124
  8. package/dist/browser/entities/user.js +1 -168
  9. package/dist/browser/events.js +1 -374
  10. package/dist/browser/identity-rbac.capability.js +1 -31
  11. package/dist/browser/identity-rbac.feature.js +1 -67
  12. package/dist/browser/index.js +1 -2099
  13. package/dist/browser/policies/engine.js +1 -154
  14. package/dist/browser/policies/index.js +1 -154
  15. package/dist/contracts/index.js +1 -1045
  16. package/dist/contracts/organization.js +1 -655
  17. package/dist/contracts/rbac.js +1 -599
  18. package/dist/contracts/user.js +1 -235
  19. package/dist/entities/index.js +1 -464
  20. package/dist/entities/organization.js +1 -150
  21. package/dist/entities/rbac.js +1 -124
  22. package/dist/entities/user.js +1 -168
  23. package/dist/events.js +1 -374
  24. package/dist/identity-rbac.capability.js +1 -31
  25. package/dist/identity-rbac.feature.js +1 -67
  26. package/dist/index.js +1 -2099
  27. package/dist/node/contracts/index.js +1 -1045
  28. package/dist/node/contracts/organization.js +1 -655
  29. package/dist/node/contracts/rbac.js +1 -599
  30. package/dist/node/contracts/user.js +1 -235
  31. package/dist/node/entities/index.js +1 -464
  32. package/dist/node/entities/organization.js +1 -150
  33. package/dist/node/entities/rbac.js +1 -124
  34. package/dist/node/entities/user.js +1 -168
  35. package/dist/node/events.js +1 -374
  36. package/dist/node/identity-rbac.capability.js +1 -31
  37. package/dist/node/identity-rbac.feature.js +1 -67
  38. package/dist/node/index.js +1 -2099
  39. package/dist/node/policies/engine.js +1 -154
  40. package/dist/node/policies/index.js +1 -154
  41. package/dist/policies/engine.js +1 -154
  42. package/dist/policies/index.js +1 -154
  43. package/package.json +5 -5
@@ -1,600 +1,2 @@
1
1
  // @bun
2
- // src/contracts/user.ts
3
- import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
4
- import { ScalarTypeEnum, SchemaModel } from "@contractspec/lib.schema";
5
- var OWNERS = ["platform.identity-rbac"];
6
- var UserProfileModel = new SchemaModel({
7
- name: "UserProfile",
8
- description: "User profile information",
9
- fields: {
10
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
- email: { type: ScalarTypeEnum.EmailAddress(), isOptional: false },
12
- emailVerified: { type: ScalarTypeEnum.Boolean(), isOptional: false },
13
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
14
- firstName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
15
- lastName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
16
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
17
- timezone: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
18
- imageUrl: { type: ScalarTypeEnum.URL(), isOptional: true },
19
- role: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
20
- onboardingCompleted: { type: ScalarTypeEnum.Boolean(), isOptional: false },
21
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
22
- }
23
- });
24
- var CreateUserInputModel = new SchemaModel({
25
- name: "CreateUserInput",
26
- description: "Input for creating a new user",
27
- fields: {
28
- email: { type: ScalarTypeEnum.EmailAddress(), isOptional: false },
29
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
30
- firstName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
31
- lastName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
32
- password: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
33
- }
34
- });
35
- var UpdateUserInputModel = new SchemaModel({
36
- name: "UpdateUserInput",
37
- description: "Input for updating a user profile",
38
- fields: {
39
- name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
40
- firstName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
41
- lastName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
42
- locale: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
- timezone: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
- imageUrl: { type: ScalarTypeEnum.URL(), isOptional: true }
45
- }
46
- });
47
- var DeleteUserInputModel = new SchemaModel({
48
- name: "DeleteUserInput",
49
- description: "Input for deleting a user",
50
- fields: {
51
- confirmEmail: { type: ScalarTypeEnum.EmailAddress(), isOptional: false }
52
- }
53
- });
54
- var SuccessResultModel = new SchemaModel({
55
- name: "SuccessResult",
56
- description: "Simple success result",
57
- fields: {
58
- success: { type: ScalarTypeEnum.Boolean(), isOptional: false }
59
- }
60
- });
61
- var UserDeletedPayloadModel = new SchemaModel({
62
- name: "UserDeletedPayload",
63
- description: "Payload for user deleted event",
64
- fields: {
65
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
66
- }
67
- });
68
- var ListUsersInputModel = new SchemaModel({
69
- name: "ListUsersInput",
70
- description: "Input for listing users",
71
- fields: {
72
- limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
73
- offset: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
74
- search: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
75
- }
76
- });
77
- var ListUsersOutputModel = new SchemaModel({
78
- name: "ListUsersOutput",
79
- description: "Output for listing users",
80
- fields: {
81
- users: { type: UserProfileModel, isOptional: false, isArray: true },
82
- total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false }
83
- }
84
- });
85
- var CreateUserContract = defineCommand({
86
- meta: {
87
- key: "identity.user.create",
88
- version: "1.0.0",
89
- stability: "stable",
90
- owners: [...OWNERS],
91
- tags: ["identity", "user", "create"],
92
- description: "Create a new user account.",
93
- goal: "Register a new user in the system.",
94
- context: "Used during signup flows. May trigger email verification."
95
- },
96
- io: {
97
- input: CreateUserInputModel,
98
- output: UserProfileModel,
99
- errors: {
100
- EMAIL_EXISTS: {
101
- description: "A user with this email already exists",
102
- http: 409,
103
- gqlCode: "EMAIL_EXISTS",
104
- when: "Email is already registered"
105
- }
106
- }
107
- },
108
- policy: {
109
- auth: "anonymous"
110
- },
111
- sideEffects: {
112
- emits: [
113
- {
114
- key: "user.created",
115
- version: "1.0.0",
116
- when: "User is successfully created",
117
- payload: UserProfileModel
118
- }
119
- ],
120
- audit: ["user.created"]
121
- }
122
- });
123
- var GetCurrentUserContract = defineQuery({
124
- meta: {
125
- key: "identity.user.me",
126
- version: "1.0.0",
127
- stability: "stable",
128
- owners: [...OWNERS],
129
- tags: ["identity", "user", "profile"],
130
- description: "Get the current authenticated user profile.",
131
- goal: "Retrieve user profile for the authenticated session.",
132
- context: "Called on app load and after profile updates."
133
- },
134
- io: {
135
- input: null,
136
- output: UserProfileModel
137
- },
138
- policy: {
139
- auth: "user"
140
- }
141
- });
142
- var UpdateUserContract = defineCommand({
143
- meta: {
144
- key: "identity.user.update",
145
- version: "1.0.0",
146
- stability: "stable",
147
- owners: [...OWNERS],
148
- tags: ["identity", "user", "update"],
149
- description: "Update user profile information.",
150
- goal: "Allow users to update their profile.",
151
- context: "Self-service profile updates."
152
- },
153
- io: {
154
- input: UpdateUserInputModel,
155
- output: UserProfileModel
156
- },
157
- policy: {
158
- auth: "user"
159
- },
160
- sideEffects: {
161
- emits: [
162
- {
163
- key: "user.updated",
164
- version: "1.0.0",
165
- when: "User profile is updated",
166
- payload: UserProfileModel
167
- }
168
- ],
169
- audit: ["user.updated"]
170
- }
171
- });
172
- var DeleteUserContract = defineCommand({
173
- meta: {
174
- key: "identity.user.delete",
175
- version: "1.0.0",
176
- stability: "stable",
177
- owners: [...OWNERS],
178
- tags: ["identity", "user", "delete"],
179
- description: "Delete user account and all associated data.",
180
- goal: "Allow users to delete their account (GDPR compliance).",
181
- context: "Self-service account deletion. Cascades to memberships, sessions, etc."
182
- },
183
- io: {
184
- input: DeleteUserInputModel,
185
- output: SuccessResultModel
186
- },
187
- policy: {
188
- auth: "user",
189
- escalate: "human_review"
190
- },
191
- sideEffects: {
192
- emits: [
193
- {
194
- key: "user.deleted",
195
- version: "1.0.0",
196
- when: "User account is deleted",
197
- payload: UserDeletedPayloadModel
198
- }
199
- ],
200
- audit: ["user.deleted"]
201
- }
202
- });
203
- var ListUsersContract = defineQuery({
204
- meta: {
205
- key: "identity.user.list",
206
- version: "1.0.0",
207
- stability: "stable",
208
- owners: [...OWNERS],
209
- tags: ["identity", "user", "admin", "list"],
210
- description: "List all users (admin only).",
211
- goal: "Allow admins to browse and manage users.",
212
- context: "Admin dashboard user management."
213
- },
214
- io: {
215
- input: ListUsersInputModel,
216
- output: ListUsersOutputModel
217
- },
218
- policy: {
219
- auth: "admin"
220
- }
221
- });
222
-
223
- // src/contracts/rbac.ts
224
- import { defineCommand as defineCommand2, defineQuery as defineQuery2 } from "@contractspec/lib.contracts-spec";
225
- import { ScalarTypeEnum as ScalarTypeEnum2, SchemaModel as SchemaModel2 } from "@contractspec/lib.schema";
226
- var RoleModel = new SchemaModel2({
227
- name: "Role",
228
- description: "RBAC role definition",
229
- fields: {
230
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
231
- name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
232
- description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
233
- permissions: {
234
- type: ScalarTypeEnum2.String_unsecure(),
235
- isOptional: false,
236
- isArray: true
237
- },
238
- createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
239
- }
240
- });
241
- var PolicyBindingModel = new SchemaModel2({
242
- name: "PolicyBinding",
243
- description: "Role assignment to a target",
244
- fields: {
245
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
246
- roleId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
247
- targetType: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
248
- targetId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
249
- expiresAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
250
- createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
251
- role: { type: RoleModel, isOptional: false }
252
- }
253
- });
254
- var PermissionCheckResultModel = new SchemaModel2({
255
- name: "PermissionCheckResult",
256
- description: "Result of a permission check",
257
- fields: {
258
- allowed: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
259
- reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
260
- matchedRole: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
261
- }
262
- });
263
- var CreateRoleInputModel = new SchemaModel2({
264
- name: "CreateRoleInput",
265
- description: "Input for creating a role",
266
- fields: {
267
- name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
268
- description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
269
- permissions: {
270
- type: ScalarTypeEnum2.String_unsecure(),
271
- isOptional: false,
272
- isArray: true
273
- }
274
- }
275
- });
276
- var UpdateRoleInputModel = new SchemaModel2({
277
- name: "UpdateRoleInput",
278
- description: "Input for updating a role",
279
- fields: {
280
- roleId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
281
- name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
282
- description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
283
- permissions: {
284
- type: ScalarTypeEnum2.String_unsecure(),
285
- isOptional: true,
286
- isArray: true
287
- }
288
- }
289
- });
290
- var DeleteRoleInputModel = new SchemaModel2({
291
- name: "DeleteRoleInput",
292
- description: "Input for deleting a role",
293
- fields: {
294
- roleId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
295
- }
296
- });
297
- var ListRolesOutputModel = new SchemaModel2({
298
- name: "ListRolesOutput",
299
- description: "Output for listing roles",
300
- fields: {
301
- roles: { type: RoleModel, isOptional: false, isArray: true }
302
- }
303
- });
304
- var AssignRoleInputModel = new SchemaModel2({
305
- name: "AssignRoleInput",
306
- description: "Input for assigning a role",
307
- fields: {
308
- roleId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
309
- targetType: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
310
- targetId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
311
- expiresAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true }
312
- }
313
- });
314
- var RevokeRoleInputModel = new SchemaModel2({
315
- name: "RevokeRoleInput",
316
- description: "Input for revoking a role",
317
- fields: {
318
- bindingId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
319
- }
320
- });
321
- var BindingIdPayloadModel = new SchemaModel2({
322
- name: "BindingIdPayload",
323
- description: "Payload with binding ID",
324
- fields: {
325
- bindingId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
326
- }
327
- });
328
- var CheckPermissionInputModel = new SchemaModel2({
329
- name: "CheckPermissionInput",
330
- description: "Input for checking a permission",
331
- fields: {
332
- userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
333
- orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
334
- permission: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
335
- }
336
- });
337
- var ListUserPermissionsInputModel = new SchemaModel2({
338
- name: "ListUserPermissionsInput",
339
- description: "Input for listing user permissions",
340
- fields: {
341
- userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
342
- orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
343
- }
344
- });
345
- var ListUserPermissionsOutputModel = new SchemaModel2({
346
- name: "ListUserPermissionsOutput",
347
- description: "Output for listing user permissions",
348
- fields: {
349
- permissions: {
350
- type: ScalarTypeEnum2.String_unsecure(),
351
- isOptional: false,
352
- isArray: true
353
- },
354
- roles: { type: RoleModel, isOptional: false, isArray: true }
355
- }
356
- });
357
- var CreateRoleContract = defineCommand2({
358
- meta: {
359
- key: "identity.rbac.role.create",
360
- version: "1.0.0",
361
- stability: "stable",
362
- owners: ["@platform.identity-rbac"],
363
- tags: ["identity", "rbac", "role", "create"],
364
- description: "Create a new role with permissions.",
365
- goal: "Allow admins to define custom roles.",
366
- context: "Role management in admin settings."
367
- },
368
- io: {
369
- input: CreateRoleInputModel,
370
- output: RoleModel,
371
- errors: {
372
- ROLE_EXISTS: {
373
- description: "A role with this name already exists",
374
- http: 409,
375
- gqlCode: "ROLE_EXISTS",
376
- when: "Role name is taken"
377
- }
378
- }
379
- },
380
- policy: {
381
- auth: "admin"
382
- },
383
- sideEffects: {
384
- audit: ["role.created"]
385
- }
386
- });
387
- var UpdateRoleContract = defineCommand2({
388
- meta: {
389
- key: "identity.rbac.role.update",
390
- version: "1.0.0",
391
- stability: "stable",
392
- owners: ["@platform.identity-rbac"],
393
- tags: ["identity", "rbac", "role", "update"],
394
- description: "Update an existing role.",
395
- goal: "Allow admins to modify role permissions.",
396
- context: "Role management in admin settings."
397
- },
398
- io: {
399
- input: UpdateRoleInputModel,
400
- output: RoleModel
401
- },
402
- policy: {
403
- auth: "admin"
404
- },
405
- sideEffects: {
406
- audit: ["role.updated"]
407
- }
408
- });
409
- var DeleteRoleContract = defineCommand2({
410
- meta: {
411
- key: "identity.rbac.role.delete",
412
- version: "1.0.0",
413
- stability: "stable",
414
- owners: ["@platform.identity-rbac"],
415
- tags: ["identity", "rbac", "role", "delete"],
416
- description: "Delete an existing role.",
417
- goal: "Allow admins to remove unused roles.",
418
- context: "Role management. Removes all policy bindings using this role."
419
- },
420
- io: {
421
- input: DeleteRoleInputModel,
422
- output: SuccessResultModel,
423
- errors: {
424
- ROLE_IN_USE: {
425
- description: "Role is still assigned to users or organizations",
426
- http: 409,
427
- gqlCode: "ROLE_IN_USE",
428
- when: "Role has active bindings"
429
- }
430
- }
431
- },
432
- policy: {
433
- auth: "admin"
434
- },
435
- sideEffects: {
436
- audit: ["role.deleted"]
437
- }
438
- });
439
- var ListRolesContract = defineQuery2({
440
- meta: {
441
- key: "identity.rbac.role.list",
442
- version: "1.0.0",
443
- stability: "stable",
444
- owners: ["@platform.identity-rbac"],
445
- tags: ["identity", "rbac", "role", "list"],
446
- description: "List all available roles.",
447
- goal: "Show available roles for assignment.",
448
- context: "Role assignment UI."
449
- },
450
- io: {
451
- input: null,
452
- output: ListRolesOutputModel
453
- },
454
- policy: {
455
- auth: "user"
456
- }
457
- });
458
- var AssignRoleContract = defineCommand2({
459
- meta: {
460
- key: "identity.rbac.assign",
461
- version: "1.0.0",
462
- stability: "stable",
463
- owners: ["@platform.identity-rbac"],
464
- tags: ["identity", "rbac", "assign"],
465
- description: "Assign a role to a user or organization.",
466
- goal: "Grant permissions via role assignment.",
467
- context: "User/org permission management."
468
- },
469
- io: {
470
- input: AssignRoleInputModel,
471
- output: PolicyBindingModel,
472
- errors: {
473
- ROLE_NOT_FOUND: {
474
- description: "The specified role does not exist",
475
- http: 404,
476
- gqlCode: "ROLE_NOT_FOUND",
477
- when: "Role ID is invalid"
478
- },
479
- ALREADY_ASSIGNED: {
480
- description: "This role is already assigned to the target",
481
- http: 409,
482
- gqlCode: "ALREADY_ASSIGNED",
483
- when: "Binding already exists"
484
- }
485
- }
486
- },
487
- policy: {
488
- auth: "admin"
489
- },
490
- sideEffects: {
491
- emits: [
492
- {
493
- key: "role.assigned",
494
- version: "1.0.0",
495
- when: "Role is assigned",
496
- payload: PolicyBindingModel
497
- }
498
- ],
499
- audit: ["role.assigned"]
500
- }
501
- });
502
- var RevokeRoleContract = defineCommand2({
503
- meta: {
504
- key: "identity.rbac.revoke",
505
- version: "1.0.0",
506
- stability: "stable",
507
- owners: ["@platform.identity-rbac"],
508
- tags: ["identity", "rbac", "revoke"],
509
- description: "Revoke a role from a user or organization.",
510
- goal: "Remove permissions via role revocation.",
511
- context: "User/org permission management."
512
- },
513
- io: {
514
- input: RevokeRoleInputModel,
515
- output: SuccessResultModel,
516
- errors: {
517
- BINDING_NOT_FOUND: {
518
- description: "The policy binding does not exist",
519
- http: 404,
520
- gqlCode: "BINDING_NOT_FOUND",
521
- when: "Binding ID is invalid"
522
- }
523
- }
524
- },
525
- policy: {
526
- auth: "admin"
527
- },
528
- sideEffects: {
529
- emits: [
530
- {
531
- key: "role.revoked",
532
- version: "1.0.0",
533
- when: "Role is revoked",
534
- payload: BindingIdPayloadModel
535
- }
536
- ],
537
- audit: ["role.revoked"]
538
- }
539
- });
540
- var CheckPermissionContract = defineQuery2({
541
- meta: {
542
- key: "identity.rbac.check",
543
- version: "1.0.0",
544
- stability: "stable",
545
- owners: ["@platform.identity-rbac"],
546
- tags: ["identity", "rbac", "check", "permission"],
547
- description: "Check if a user has a specific permission.",
548
- goal: "Authorization check before sensitive operations.",
549
- context: "Called by other services to verify permissions."
550
- },
551
- io: {
552
- input: CheckPermissionInputModel,
553
- output: PermissionCheckResultModel
554
- },
555
- policy: {
556
- auth: "user"
557
- }
558
- });
559
- var ListUserPermissionsContract = defineQuery2({
560
- meta: {
561
- key: "identity.rbac.permissions",
562
- version: "1.0.0",
563
- stability: "stable",
564
- owners: ["@platform.identity-rbac"],
565
- tags: ["identity", "rbac", "permissions", "user"],
566
- description: "List all permissions for a user in a context.",
567
- goal: "Show what a user can do in an org.",
568
- context: "UI permission display, debugging."
569
- },
570
- io: {
571
- input: ListUserPermissionsInputModel,
572
- output: ListUserPermissionsOutputModel
573
- },
574
- policy: {
575
- auth: "user"
576
- }
577
- });
578
- export {
579
- UpdateRoleInputModel,
580
- UpdateRoleContract,
581
- RoleModel,
582
- RevokeRoleInputModel,
583
- RevokeRoleContract,
584
- PolicyBindingModel,
585
- PermissionCheckResultModel,
586
- ListUserPermissionsOutputModel,
587
- ListUserPermissionsInputModel,
588
- ListUserPermissionsContract,
589
- ListRolesOutputModel,
590
- ListRolesContract,
591
- DeleteRoleInputModel,
592
- DeleteRoleContract,
593
- CreateRoleInputModel,
594
- CreateRoleContract,
595
- CheckPermissionInputModel,
596
- CheckPermissionContract,
597
- BindingIdPayloadModel,
598
- AssignRoleInputModel,
599
- AssignRoleContract
600
- };
2
+ import{defineCommand as K,defineQuery as X}from"@contractspec/lib.contracts-spec";import{ScalarTypeEnum as q,SchemaModel as x}from"@contractspec/lib.schema";var F=["platform.identity-rbac"],z=new x({name:"UserProfile",description:"User profile information",fields:{id:{type:q.String_unsecure(),isOptional:!1},email:{type:q.EmailAddress(),isOptional:!1},emailVerified:{type:q.Boolean(),isOptional:!1},name:{type:q.String_unsecure(),isOptional:!0},firstName:{type:q.String_unsecure(),isOptional:!0},lastName:{type:q.String_unsecure(),isOptional:!0},locale:{type:q.String_unsecure(),isOptional:!0},timezone:{type:q.String_unsecure(),isOptional:!0},imageUrl:{type:q.URL(),isOptional:!0},role:{type:q.String_unsecure(),isOptional:!0},onboardingCompleted:{type:q.Boolean(),isOptional:!1},createdAt:{type:q.DateTime(),isOptional:!1}}}),Z=new x({name:"CreateUserInput",description:"Input for creating a new user",fields:{email:{type:q.EmailAddress(),isOptional:!1},name:{type:q.String_unsecure(),isOptional:!0},firstName:{type:q.String_unsecure(),isOptional:!0},lastName:{type:q.String_unsecure(),isOptional:!0},password:{type:q.String_unsecure(),isOptional:!0}}}),_=new x({name:"UpdateUserInput",description:"Input for updating a user profile",fields:{name:{type:q.String_unsecure(),isOptional:!0},firstName:{type:q.String_unsecure(),isOptional:!0},lastName:{type:q.String_unsecure(),isOptional:!0},locale:{type:q.String_unsecure(),isOptional:!0},timezone:{type:q.String_unsecure(),isOptional:!0},imageUrl:{type:q.URL(),isOptional:!0}}}),$=new x({name:"DeleteUserInput",description:"Input for deleting a user",fields:{confirmEmail:{type:q.EmailAddress(),isOptional:!1}}}),J=new x({name:"SuccessResult",description:"Simple success result",fields:{success:{type:q.Boolean(),isOptional:!1}}}),v=new x({name:"UserDeletedPayload",description:"Payload for user deleted event",fields:{userId:{type:q.String_unsecure(),isOptional:!1}}}),A=new x({name:"ListUsersInput",description:"Input for listing users",fields:{limit:{type:q.Int_unsecure(),isOptional:!0},offset:{type:q.Int_unsecure(),isOptional:!0},search:{type:q.String_unsecure(),isOptional:!0}}}),k=new x({name:"ListUsersOutput",description:"Output for listing users",fields:{users:{type:z,isOptional:!1,isArray:!0},total:{type:q.Int_unsecure(),isOptional:!1}}}),f=K({meta:{key:"identity.user.create",version:"1.0.0",stability:"stable",owners:[...F],tags:["identity","user","create"],description:"Create a new user account.",goal:"Register a new user in the system.",context:"Used during signup flows. May trigger email verification."},io:{input:Z,output:z,errors:{EMAIL_EXISTS:{description:"A user with this email already exists",http:409,gqlCode:"EMAIL_EXISTS",when:"Email is already registered"}}},policy:{auth:"anonymous"},sideEffects:{emits:[{key:"user.created",version:"1.0.0",when:"User is successfully created",payload:z}],audit:["user.created"]}}),R=X({meta:{key:"identity.user.me",version:"1.0.0",stability:"stable",owners:[...F],tags:["identity","user","profile"],description:"Get the current authenticated user profile.",goal:"Retrieve user profile for the authenticated session.",context:"Called on app load and after profile updates."},io:{input:null,output:z},policy:{auth:"user"}}),h=K({meta:{key:"identity.user.update",version:"1.0.0",stability:"stable",owners:[...F],tags:["identity","user","update"],description:"Update user profile information.",goal:"Allow users to update their profile.",context:"Self-service profile updates."},io:{input:_,output:z},policy:{auth:"user"},sideEffects:{emits:[{key:"user.updated",version:"1.0.0",when:"User profile is updated",payload:z}],audit:["user.updated"]}}),i=K({meta:{key:"identity.user.delete",version:"1.0.0",stability:"stable",owners:[...F],tags:["identity","user","delete"],description:"Delete user account and all associated data.",goal:"Allow users to delete their account (GDPR compliance).",context:"Self-service account deletion. Cascades to memberships, sessions, etc."},io:{input:$,output:J},policy:{auth:"user",escalate:"human_review"},sideEffects:{emits:[{key:"user.deleted",version:"1.0.0",when:"User account is deleted",payload:v}],audit:["user.deleted"]}}),t=X({meta:{key:"identity.user.list",version:"1.0.0",stability:"stable",owners:[...F],tags:["identity","user","admin","list"],description:"List all users (admin only).",goal:"Allow admins to browse and manage users.",context:"Admin dashboard user management."},io:{input:A,output:k},policy:{auth:"admin"}});import{defineCommand as G,defineQuery as V}from"@contractspec/lib.contracts-spec";import{ScalarTypeEnum as j,SchemaModel as w}from"@contractspec/lib.schema";var H=new w({name:"Role",description:"RBAC role definition",fields:{id:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},permissions:{type:j.String_unsecure(),isOptional:!1,isArray:!0},createdAt:{type:j.DateTime(),isOptional:!1}}}),Y=new w({name:"PolicyBinding",description:"Role assignment to a target",fields:{id:{type:j.String_unsecure(),isOptional:!1},roleId:{type:j.String_unsecure(),isOptional:!1},targetType:{type:j.String_unsecure(),isOptional:!1},targetId:{type:j.String_unsecure(),isOptional:!1},expiresAt:{type:j.DateTime(),isOptional:!0},createdAt:{type:j.DateTime(),isOptional:!1},role:{type:H,isOptional:!1}}}),B=new w({name:"PermissionCheckResult",description:"Result of a permission check",fields:{allowed:{type:j.Boolean(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!0},matchedRole:{type:j.String_unsecure(),isOptional:!0}}}),D=new w({name:"CreateRoleInput",description:"Input for creating a role",fields:{name:{type:j.NonEmptyString(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},permissions:{type:j.String_unsecure(),isOptional:!1,isArray:!0}}}),b=new w({name:"UpdateRoleInput",description:"Input for updating a role",fields:{roleId:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!0},description:{type:j.String_unsecure(),isOptional:!0},permissions:{type:j.String_unsecure(),isOptional:!0,isArray:!0}}}),g=new w({name:"DeleteRoleInput",description:"Input for deleting a role",fields:{roleId:{type:j.String_unsecure(),isOptional:!1}}}),L=new w({name:"ListRolesOutput",description:"Output for listing roles",fields:{roles:{type:H,isOptional:!1,isArray:!0}}}),N=new w({name:"AssignRoleInput",description:"Input for assigning a role",fields:{roleId:{type:j.String_unsecure(),isOptional:!1},targetType:{type:j.String_unsecure(),isOptional:!1},targetId:{type:j.String_unsecure(),isOptional:!1},expiresAt:{type:j.DateTime(),isOptional:!0}}}),Q=new w({name:"RevokeRoleInput",description:"Input for revoking a role",fields:{bindingId:{type:j.String_unsecure(),isOptional:!1}}}),W=new w({name:"BindingIdPayload",description:"Payload with binding ID",fields:{bindingId:{type:j.String_unsecure(),isOptional:!1}}}),O=new w({name:"CheckPermissionInput",description:"Input for checking a permission",fields:{userId:{type:j.String_unsecure(),isOptional:!1},orgId:{type:j.String_unsecure(),isOptional:!0},permission:{type:j.String_unsecure(),isOptional:!1}}}),C=new w({name:"ListUserPermissionsInput",description:"Input for listing user permissions",fields:{userId:{type:j.String_unsecure(),isOptional:!1},orgId:{type:j.String_unsecure(),isOptional:!0}}}),I=new w({name:"ListUserPermissionsOutput",description:"Output for listing user permissions",fields:{permissions:{type:j.String_unsecure(),isOptional:!1,isArray:!0},roles:{type:H,isOptional:!1,isArray:!0}}}),y=G({meta:{key:"identity.rbac.role.create",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","role","create"],description:"Create a new role with permissions.",goal:"Allow admins to define custom roles.",context:"Role management in admin settings."},io:{input:D,output:H,errors:{ROLE_EXISTS:{description:"A role with this name already exists",http:409,gqlCode:"ROLE_EXISTS",when:"Role name is taken"}}},policy:{auth:"admin"},sideEffects:{audit:["role.created"]}}),d=G({meta:{key:"identity.rbac.role.update",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","role","update"],description:"Update an existing role.",goal:"Allow admins to modify role permissions.",context:"Role management in admin settings."},io:{input:b,output:H},policy:{auth:"admin"},sideEffects:{audit:["role.updated"]}}),p=G({meta:{key:"identity.rbac.role.delete",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","role","delete"],description:"Delete an existing role.",goal:"Allow admins to remove unused roles.",context:"Role management. Removes all policy bindings using this role."},io:{input:g,output:J,errors:{ROLE_IN_USE:{description:"Role is still assigned to users or organizations",http:409,gqlCode:"ROLE_IN_USE",when:"Role has active bindings"}}},policy:{auth:"admin"},sideEffects:{audit:["role.deleted"]}}),S=V({meta:{key:"identity.rbac.role.list",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","role","list"],description:"List all available roles.",goal:"Show available roles for assignment.",context:"Role assignment UI."},io:{input:null,output:L},policy:{auth:"user"}}),o=G({meta:{key:"identity.rbac.assign",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","assign"],description:"Assign a role to a user or organization.",goal:"Grant permissions via role assignment.",context:"User/org permission management."},io:{input:N,output:Y,errors:{ROLE_NOT_FOUND:{description:"The specified role does not exist",http:404,gqlCode:"ROLE_NOT_FOUND",when:"Role ID is invalid"},ALREADY_ASSIGNED:{description:"This role is already assigned to the target",http:409,gqlCode:"ALREADY_ASSIGNED",when:"Binding already exists"}}},policy:{auth:"admin"},sideEffects:{emits:[{key:"role.assigned",version:"1.0.0",when:"Role is assigned",payload:Y}],audit:["role.assigned"]}}),u=G({meta:{key:"identity.rbac.revoke",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","revoke"],description:"Revoke a role from a user or organization.",goal:"Remove permissions via role revocation.",context:"User/org permission management."},io:{input:Q,output:J,errors:{BINDING_NOT_FOUND:{description:"The policy binding does not exist",http:404,gqlCode:"BINDING_NOT_FOUND",when:"Binding ID is invalid"}}},policy:{auth:"admin"},sideEffects:{emits:[{key:"role.revoked",version:"1.0.0",when:"Role is revoked",payload:W}],audit:["role.revoked"]}}),r=V({meta:{key:"identity.rbac.check",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","check","permission"],description:"Check if a user has a specific permission.",goal:"Authorization check before sensitive operations.",context:"Called by other services to verify permissions."},io:{input:O,output:B},policy:{auth:"user"}}),m=V({meta:{key:"identity.rbac.permissions",version:"1.0.0",stability:"stable",owners:["@platform.identity-rbac"],tags:["identity","rbac","permissions","user"],description:"List all permissions for a user in a context.",goal:"Show what a user can do in an org.",context:"UI permission display, debugging."},io:{input:C,output:I},policy:{auth:"user"}});export{b as UpdateRoleInputModel,d as UpdateRoleContract,H as RoleModel,Q as RevokeRoleInputModel,u as RevokeRoleContract,Y as PolicyBindingModel,B as PermissionCheckResultModel,I as ListUserPermissionsOutputModel,C as ListUserPermissionsInputModel,m as ListUserPermissionsContract,L as ListRolesOutputModel,S as ListRolesContract,g as DeleteRoleInputModel,p as DeleteRoleContract,D as CreateRoleInputModel,y as CreateRoleContract,O as CheckPermissionInputModel,r as CheckPermissionContract,W as BindingIdPayloadModel,N as AssignRoleInputModel,o as AssignRoleContract};