@contractspec/lib.identity-rbac 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/browser/contracts/index.js +1045 -0
  2. package/dist/browser/contracts/organization.js +655 -0
  3. package/dist/browser/contracts/rbac.js +599 -0
  4. package/dist/browser/contracts/user.js +235 -0
  5. package/dist/browser/entities/index.js +464 -0
  6. package/dist/browser/entities/organization.js +150 -0
  7. package/dist/browser/entities/rbac.js +124 -0
  8. package/dist/browser/entities/user.js +168 -0
  9. package/dist/browser/events.js +374 -0
  10. package/dist/browser/identity-rbac.capability.js +28 -0
  11. package/dist/browser/identity-rbac.feature.js +67 -0
  12. package/dist/browser/index.js +2099 -0
  13. package/dist/browser/policies/engine.js +154 -0
  14. package/dist/browser/policies/index.js +154 -0
  15. package/dist/contracts/index.d.ts +4 -4
  16. package/dist/contracts/index.d.ts.map +1 -0
  17. package/dist/contracts/index.js +1045 -4
  18. package/dist/contracts/organization.d.ts +758 -764
  19. package/dist/contracts/organization.d.ts.map +1 -1
  20. package/dist/contracts/organization.js +653 -602
  21. package/dist/contracts/rbac.d.ts +517 -523
  22. package/dist/contracts/rbac.d.ts.map +1 -1
  23. package/dist/contracts/rbac.js +597 -481
  24. package/dist/contracts/user.d.ts +513 -519
  25. package/dist/contracts/user.d.ts.map +1 -1
  26. package/dist/contracts/user.js +222 -319
  27. package/dist/entities/index.d.ts +164 -169
  28. package/dist/entities/index.d.ts.map +1 -1
  29. package/dist/entities/index.js +462 -33
  30. package/dist/entities/organization.d.ts +58 -63
  31. package/dist/entities/organization.d.ts.map +1 -1
  32. package/dist/entities/organization.js +145 -145
  33. package/dist/entities/rbac.d.ts +62 -67
  34. package/dist/entities/rbac.d.ts.map +1 -1
  35. package/dist/entities/rbac.js +119 -132
  36. package/dist/entities/user.d.ts +66 -71
  37. package/dist/entities/user.d.ts.map +1 -1
  38. package/dist/entities/user.js +164 -189
  39. package/dist/events.d.ts +537 -543
  40. package/dist/events.d.ts.map +1 -1
  41. package/dist/events.js +343 -651
  42. package/dist/identity-rbac.capability.d.ts +2 -7
  43. package/dist/identity-rbac.capability.d.ts.map +1 -1
  44. package/dist/identity-rbac.capability.js +29 -29
  45. package/dist/identity-rbac.feature.d.ts +1 -6
  46. package/dist/identity-rbac.feature.d.ts.map +1 -1
  47. package/dist/identity-rbac.feature.js +66 -193
  48. package/dist/index.d.ts +6 -12
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +2100 -14
  51. package/dist/node/contracts/index.js +1045 -0
  52. package/dist/node/contracts/organization.js +655 -0
  53. package/dist/node/contracts/rbac.js +599 -0
  54. package/dist/node/contracts/user.js +235 -0
  55. package/dist/node/entities/index.js +464 -0
  56. package/dist/node/entities/organization.js +150 -0
  57. package/dist/node/entities/rbac.js +124 -0
  58. package/dist/node/entities/user.js +168 -0
  59. package/dist/node/events.js +374 -0
  60. package/dist/node/identity-rbac.capability.js +28 -0
  61. package/dist/node/identity-rbac.feature.js +67 -0
  62. package/dist/node/index.js +2099 -0
  63. package/dist/node/policies/engine.js +154 -0
  64. package/dist/node/policies/index.js +154 -0
  65. package/dist/policies/engine.d.ts +98 -101
  66. package/dist/policies/engine.d.ts.map +1 -1
  67. package/dist/policies/engine.js +151 -164
  68. package/dist/policies/index.d.ts +2 -2
  69. package/dist/policies/index.d.ts.map +1 -0
  70. package/dist/policies/index.js +154 -2
  71. package/package.json +149 -40
  72. package/dist/contracts/organization.js.map +0 -1
  73. package/dist/contracts/rbac.js.map +0 -1
  74. package/dist/contracts/user.js.map +0 -1
  75. package/dist/entities/index.js.map +0 -1
  76. package/dist/entities/organization.js.map +0 -1
  77. package/dist/entities/rbac.js.map +0 -1
  78. package/dist/entities/user.js.map +0 -1
  79. package/dist/events.js.map +0 -1
  80. package/dist/identity-rbac.capability.js.map +0 -1
  81. package/dist/identity-rbac.feature.js.map +0 -1
  82. package/dist/policies/engine.js.map +0 -1
@@ -1,5 +1,1046 @@
1
- import { CreateUserContract, CreateUserInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, SuccessResultModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel } from "./user.js";
2
- import { AcceptInviteContract, AcceptInviteInputModel, CreateOrgContract, CreateOrgInputModel, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, RemoveMemberContract, RemoveMemberInputModel, UpdateOrgContract, UpdateOrgInputModel } from "./organization.js";
3
- import { AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateRoleContract, CreateRoleInputModel, DeleteRoleContract, DeleteRoleInputModel, ListRolesContract, ListRolesOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, PermissionCheckResultModel, PolicyBindingModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, UpdateRoleContract, UpdateRoleInputModel } from "./rbac.js";
1
+ // @bun
2
+ // src/contracts/user.ts
3
+ import { SchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
+ import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
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
+ });
4
222
 
5
- export { AcceptInviteContract, AcceptInviteInputModel, AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateOrgContract, CreateOrgInputModel, CreateRoleContract, CreateRoleInputModel, CreateUserContract, CreateUserInputModel, DeleteRoleContract, DeleteRoleInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListRolesContract, ListRolesOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, PermissionCheckResultModel, PolicyBindingModel, RemoveMemberContract, RemoveMemberInputModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, SuccessResultModel, UpdateOrgContract, UpdateOrgInputModel, UpdateRoleContract, UpdateRoleInputModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel };
223
+ // src/contracts/organization.ts
224
+ import { ScalarTypeEnum as ScalarTypeEnum2, SchemaModel as SchemaModel2 } from "@contractspec/lib.schema";
225
+ import { defineCommand as defineCommand2, defineQuery as defineQuery2 } from "@contractspec/lib.contracts";
226
+ var OWNERS2 = ["platform.identity-rbac"];
227
+ var OrganizationModel = new SchemaModel2({
228
+ name: "Organization",
229
+ description: "Organization details",
230
+ fields: {
231
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
232
+ name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
233
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
234
+ logo: { type: ScalarTypeEnum2.URL(), isOptional: true },
235
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
236
+ type: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
237
+ onboardingCompleted: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
238
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
239
+ }
240
+ });
241
+ var MemberUserModel = new SchemaModel2({
242
+ name: "MemberUser",
243
+ description: "Basic user info within a member",
244
+ fields: {
245
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
246
+ email: { type: ScalarTypeEnum2.EmailAddress(), isOptional: false },
247
+ name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
248
+ }
249
+ });
250
+ var MemberModel = new SchemaModel2({
251
+ name: "Member",
252
+ description: "Organization member",
253
+ fields: {
254
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
255
+ userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
256
+ organizationId: {
257
+ type: ScalarTypeEnum2.String_unsecure(),
258
+ isOptional: false
259
+ },
260
+ role: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
261
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
262
+ user: { type: MemberUserModel, isOptional: false }
263
+ }
264
+ });
265
+ var InvitationModel = new SchemaModel2({
266
+ name: "Invitation",
267
+ description: "Organization invitation",
268
+ fields: {
269
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
270
+ email: { type: ScalarTypeEnum2.EmailAddress(), isOptional: false },
271
+ role: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
272
+ status: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
273
+ expiresAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
274
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
275
+ }
276
+ });
277
+ var CreateOrgInputModel = new SchemaModel2({
278
+ name: "CreateOrgInput",
279
+ description: "Input for creating an organization",
280
+ fields: {
281
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
282
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
283
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
284
+ type: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
285
+ }
286
+ });
287
+ var GetOrgInputModel = new SchemaModel2({
288
+ name: "GetOrgInput",
289
+ description: "Input for getting an organization",
290
+ fields: {
291
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
292
+ }
293
+ });
294
+ var UpdateOrgInputModel = new SchemaModel2({
295
+ name: "UpdateOrgInput",
296
+ description: "Input for updating an organization",
297
+ fields: {
298
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
299
+ name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
300
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
301
+ logo: { type: ScalarTypeEnum2.URL(), isOptional: true },
302
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
303
+ }
304
+ });
305
+ var InviteMemberInputModel = new SchemaModel2({
306
+ name: "InviteMemberInput",
307
+ description: "Input for inviting a member",
308
+ fields: {
309
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
310
+ email: { type: ScalarTypeEnum2.EmailAddress(), isOptional: false },
311
+ role: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
312
+ teamId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
313
+ }
314
+ });
315
+ var AcceptInviteInputModel = new SchemaModel2({
316
+ name: "AcceptInviteInput",
317
+ description: "Input for accepting an invitation",
318
+ fields: {
319
+ invitationId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
320
+ }
321
+ });
322
+ var RemoveMemberInputModel = new SchemaModel2({
323
+ name: "RemoveMemberInput",
324
+ description: "Input for removing a member",
325
+ fields: {
326
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
327
+ userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
328
+ }
329
+ });
330
+ var MemberRemovedPayloadModel = new SchemaModel2({
331
+ name: "MemberRemovedPayload",
332
+ description: "Payload for member removed event",
333
+ fields: {
334
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
335
+ userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
336
+ }
337
+ });
338
+ var ListMembersInputModel = new SchemaModel2({
339
+ name: "ListMembersInput",
340
+ description: "Input for listing members",
341
+ fields: {
342
+ orgId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
343
+ limit: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
344
+ offset: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true }
345
+ }
346
+ });
347
+ var ListMembersOutputModel = new SchemaModel2({
348
+ name: "ListMembersOutput",
349
+ description: "Output for listing members",
350
+ fields: {
351
+ members: { type: MemberModel, isOptional: false, isArray: true },
352
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false }
353
+ }
354
+ });
355
+ var OrganizationWithRoleModel = new SchemaModel2({
356
+ name: "OrganizationWithRole",
357
+ description: "Organization with user role",
358
+ fields: {
359
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
360
+ name: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
361
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
362
+ logo: { type: ScalarTypeEnum2.URL(), isOptional: true },
363
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
364
+ type: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
365
+ onboardingCompleted: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
366
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
367
+ role: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
368
+ }
369
+ });
370
+ var ListUserOrgsOutputModel = new SchemaModel2({
371
+ name: "ListUserOrgsOutput",
372
+ description: "Output for listing user organizations",
373
+ fields: {
374
+ organizations: {
375
+ type: OrganizationWithRoleModel,
376
+ isOptional: false,
377
+ isArray: true
378
+ }
379
+ }
380
+ });
381
+ var CreateOrgContract = defineCommand2({
382
+ meta: {
383
+ key: "identity.org.create",
384
+ version: "1.0.0",
385
+ stability: "stable",
386
+ owners: [...OWNERS2],
387
+ tags: ["identity", "org", "create"],
388
+ description: "Create a new organization.",
389
+ goal: "Allow users to create new organizations/workspaces.",
390
+ context: "Called during onboarding or when creating additional workspaces."
391
+ },
392
+ io: {
393
+ input: CreateOrgInputModel,
394
+ output: OrganizationModel,
395
+ errors: {
396
+ SLUG_EXISTS: {
397
+ description: "An organization with this slug already exists",
398
+ http: 409,
399
+ gqlCode: "SLUG_EXISTS",
400
+ when: "Slug is already taken"
401
+ }
402
+ }
403
+ },
404
+ policy: {
405
+ auth: "user"
406
+ },
407
+ sideEffects: {
408
+ emits: [
409
+ {
410
+ key: "org.created",
411
+ version: "1.0.0",
412
+ when: "Organization is created",
413
+ payload: OrganizationModel
414
+ }
415
+ ],
416
+ audit: ["org.created"]
417
+ }
418
+ });
419
+ var GetOrgContract = defineQuery2({
420
+ meta: {
421
+ key: "identity.org.get",
422
+ version: "1.0.0",
423
+ stability: "stable",
424
+ owners: [...OWNERS2],
425
+ tags: ["identity", "org", "get"],
426
+ description: "Get organization details.",
427
+ goal: "Retrieve organization information.",
428
+ context: "Called when viewing organization settings or dashboard."
429
+ },
430
+ io: {
431
+ input: GetOrgInputModel,
432
+ output: OrganizationModel
433
+ },
434
+ policy: {
435
+ auth: "user"
436
+ }
437
+ });
438
+ var UpdateOrgContract = defineCommand2({
439
+ meta: {
440
+ key: "identity.org.update",
441
+ version: "1.0.0",
442
+ stability: "stable",
443
+ owners: [...OWNERS2],
444
+ tags: ["identity", "org", "update"],
445
+ description: "Update organization details.",
446
+ goal: "Allow org admins to update organization settings.",
447
+ context: "Organization settings page."
448
+ },
449
+ io: {
450
+ input: UpdateOrgInputModel,
451
+ output: OrganizationModel
452
+ },
453
+ policy: {
454
+ auth: "user"
455
+ },
456
+ sideEffects: {
457
+ emits: [
458
+ {
459
+ key: "org.updated",
460
+ version: "1.0.0",
461
+ when: "Organization is updated",
462
+ payload: OrganizationModel
463
+ }
464
+ ],
465
+ audit: ["org.updated"]
466
+ }
467
+ });
468
+ var InviteMemberContract = defineCommand2({
469
+ meta: {
470
+ key: "identity.org.invite",
471
+ version: "1.0.0",
472
+ stability: "stable",
473
+ owners: [...OWNERS2],
474
+ tags: ["identity", "org", "invite", "member"],
475
+ description: "Invite a user to join the organization.",
476
+ goal: "Allow org admins to invite new members.",
477
+ context: "Team management. Sends invitation email."
478
+ },
479
+ io: {
480
+ input: InviteMemberInputModel,
481
+ output: InvitationModel,
482
+ errors: {
483
+ ALREADY_MEMBER: {
484
+ description: "User is already a member of this organization",
485
+ http: 409,
486
+ gqlCode: "ALREADY_MEMBER",
487
+ when: "Invitee is already a member"
488
+ },
489
+ INVITE_PENDING: {
490
+ description: "An invitation for this email is already pending",
491
+ http: 409,
492
+ gqlCode: "INVITE_PENDING",
493
+ when: "Active invitation exists"
494
+ }
495
+ }
496
+ },
497
+ policy: {
498
+ auth: "user"
499
+ },
500
+ sideEffects: {
501
+ emits: [
502
+ {
503
+ key: "org.invite.sent",
504
+ version: "1.0.0",
505
+ when: "Invitation is sent",
506
+ payload: InvitationModel
507
+ }
508
+ ],
509
+ audit: ["org.invite.sent"]
510
+ }
511
+ });
512
+ var AcceptInviteContract = defineCommand2({
513
+ meta: {
514
+ key: "identity.org.invite.accept",
515
+ version: "1.0.0",
516
+ stability: "stable",
517
+ owners: [...OWNERS2],
518
+ tags: ["identity", "org", "invite", "accept"],
519
+ description: "Accept an organization invitation.",
520
+ goal: "Allow users to join organizations via invitation.",
521
+ context: "Called from invitation email link."
522
+ },
523
+ io: {
524
+ input: AcceptInviteInputModel,
525
+ output: MemberModel,
526
+ errors: {
527
+ INVITE_EXPIRED: {
528
+ description: "The invitation has expired",
529
+ http: 410,
530
+ gqlCode: "INVITE_EXPIRED",
531
+ when: "Invitation is past expiry date"
532
+ },
533
+ INVITE_USED: {
534
+ description: "The invitation has already been used",
535
+ http: 409,
536
+ gqlCode: "INVITE_USED",
537
+ when: "Invitation was already accepted"
538
+ }
539
+ }
540
+ },
541
+ policy: {
542
+ auth: "user"
543
+ },
544
+ sideEffects: {
545
+ emits: [
546
+ {
547
+ key: "org.member.added",
548
+ version: "1.0.0",
549
+ when: "Member joins org",
550
+ payload: MemberModel
551
+ }
552
+ ],
553
+ audit: ["org.member.added"]
554
+ }
555
+ });
556
+ var RemoveMemberContract = defineCommand2({
557
+ meta: {
558
+ key: "identity.org.member.remove",
559
+ version: "1.0.0",
560
+ stability: "stable",
561
+ owners: [...OWNERS2],
562
+ tags: ["identity", "org", "member", "remove"],
563
+ description: "Remove a member from the organization.",
564
+ goal: "Allow org admins to remove members.",
565
+ context: "Team management."
566
+ },
567
+ io: {
568
+ input: RemoveMemberInputModel,
569
+ output: SuccessResultModel,
570
+ errors: {
571
+ CANNOT_REMOVE_OWNER: {
572
+ description: "Cannot remove the organization owner",
573
+ http: 403,
574
+ gqlCode: "CANNOT_REMOVE_OWNER",
575
+ when: "Target is the org owner"
576
+ }
577
+ }
578
+ },
579
+ policy: {
580
+ auth: "user"
581
+ },
582
+ sideEffects: {
583
+ emits: [
584
+ {
585
+ key: "org.member.removed",
586
+ version: "1.0.0",
587
+ when: "Member is removed",
588
+ payload: MemberRemovedPayloadModel
589
+ }
590
+ ],
591
+ audit: ["org.member.removed"]
592
+ }
593
+ });
594
+ var ListMembersContract = defineQuery2({
595
+ meta: {
596
+ key: "identity.org.members.list",
597
+ version: "1.0.0",
598
+ stability: "stable",
599
+ owners: [...OWNERS2],
600
+ tags: ["identity", "org", "member", "list"],
601
+ description: "List organization members.",
602
+ goal: "View all members of an organization.",
603
+ context: "Team management page."
604
+ },
605
+ io: {
606
+ input: ListMembersInputModel,
607
+ output: ListMembersOutputModel
608
+ },
609
+ policy: {
610
+ auth: "user"
611
+ }
612
+ });
613
+ var ListUserOrgsContract = defineQuery2({
614
+ meta: {
615
+ key: "identity.org.list",
616
+ version: "1.0.0",
617
+ stability: "stable",
618
+ owners: [...OWNERS2],
619
+ tags: ["identity", "org", "list"],
620
+ description: "List organizations the current user belongs to.",
621
+ goal: "Show user their organizations for workspace switching.",
622
+ context: "Workspace switcher, org selection."
623
+ },
624
+ io: {
625
+ input: null,
626
+ output: ListUserOrgsOutputModel
627
+ },
628
+ policy: {
629
+ auth: "user"
630
+ }
631
+ });
632
+
633
+ // src/contracts/rbac.ts
634
+ import { SchemaModel as SchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
635
+ import { defineCommand as defineCommand3, defineQuery as defineQuery3 } from "@contractspec/lib.contracts";
636
+ var RoleModel = new SchemaModel3({
637
+ name: "Role",
638
+ description: "RBAC role definition",
639
+ fields: {
640
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
641
+ name: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
642
+ description: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
643
+ permissions: {
644
+ type: ScalarTypeEnum3.String_unsecure(),
645
+ isOptional: false,
646
+ isArray: true
647
+ },
648
+ createdAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
649
+ }
650
+ });
651
+ var PolicyBindingModel = new SchemaModel3({
652
+ name: "PolicyBinding",
653
+ description: "Role assignment to a target",
654
+ fields: {
655
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
656
+ roleId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
657
+ targetType: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
658
+ targetId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
659
+ expiresAt: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
660
+ createdAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false },
661
+ role: { type: RoleModel, isOptional: false }
662
+ }
663
+ });
664
+ var PermissionCheckResultModel = new SchemaModel3({
665
+ name: "PermissionCheckResult",
666
+ description: "Result of a permission check",
667
+ fields: {
668
+ allowed: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
669
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
670
+ matchedRole: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
671
+ }
672
+ });
673
+ var CreateRoleInputModel = new SchemaModel3({
674
+ name: "CreateRoleInput",
675
+ description: "Input for creating a role",
676
+ fields: {
677
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
678
+ description: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
679
+ permissions: {
680
+ type: ScalarTypeEnum3.String_unsecure(),
681
+ isOptional: false,
682
+ isArray: true
683
+ }
684
+ }
685
+ });
686
+ var UpdateRoleInputModel = new SchemaModel3({
687
+ name: "UpdateRoleInput",
688
+ description: "Input for updating a role",
689
+ fields: {
690
+ roleId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
691
+ name: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
692
+ description: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
693
+ permissions: {
694
+ type: ScalarTypeEnum3.String_unsecure(),
695
+ isOptional: true,
696
+ isArray: true
697
+ }
698
+ }
699
+ });
700
+ var DeleteRoleInputModel = new SchemaModel3({
701
+ name: "DeleteRoleInput",
702
+ description: "Input for deleting a role",
703
+ fields: {
704
+ roleId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
705
+ }
706
+ });
707
+ var ListRolesOutputModel = new SchemaModel3({
708
+ name: "ListRolesOutput",
709
+ description: "Output for listing roles",
710
+ fields: {
711
+ roles: { type: RoleModel, isOptional: false, isArray: true }
712
+ }
713
+ });
714
+ var AssignRoleInputModel = new SchemaModel3({
715
+ name: "AssignRoleInput",
716
+ description: "Input for assigning a role",
717
+ fields: {
718
+ roleId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
719
+ targetType: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
720
+ targetId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
721
+ expiresAt: { type: ScalarTypeEnum3.DateTime(), isOptional: true }
722
+ }
723
+ });
724
+ var RevokeRoleInputModel = new SchemaModel3({
725
+ name: "RevokeRoleInput",
726
+ description: "Input for revoking a role",
727
+ fields: {
728
+ bindingId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
729
+ }
730
+ });
731
+ var BindingIdPayloadModel = new SchemaModel3({
732
+ name: "BindingIdPayload",
733
+ description: "Payload with binding ID",
734
+ fields: {
735
+ bindingId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
736
+ }
737
+ });
738
+ var CheckPermissionInputModel = new SchemaModel3({
739
+ name: "CheckPermissionInput",
740
+ description: "Input for checking a permission",
741
+ fields: {
742
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
743
+ orgId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
744
+ permission: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
745
+ }
746
+ });
747
+ var ListUserPermissionsInputModel = new SchemaModel3({
748
+ name: "ListUserPermissionsInput",
749
+ description: "Input for listing user permissions",
750
+ fields: {
751
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
752
+ orgId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
753
+ }
754
+ });
755
+ var ListUserPermissionsOutputModel = new SchemaModel3({
756
+ name: "ListUserPermissionsOutput",
757
+ description: "Output for listing user permissions",
758
+ fields: {
759
+ permissions: {
760
+ type: ScalarTypeEnum3.String_unsecure(),
761
+ isOptional: false,
762
+ isArray: true
763
+ },
764
+ roles: { type: RoleModel, isOptional: false, isArray: true }
765
+ }
766
+ });
767
+ var CreateRoleContract = defineCommand3({
768
+ meta: {
769
+ key: "identity.rbac.role.create",
770
+ version: "1.0.0",
771
+ stability: "stable",
772
+ owners: ["@platform.identity-rbac"],
773
+ tags: ["identity", "rbac", "role", "create"],
774
+ description: "Create a new role with permissions.",
775
+ goal: "Allow admins to define custom roles.",
776
+ context: "Role management in admin settings."
777
+ },
778
+ io: {
779
+ input: CreateRoleInputModel,
780
+ output: RoleModel,
781
+ errors: {
782
+ ROLE_EXISTS: {
783
+ description: "A role with this name already exists",
784
+ http: 409,
785
+ gqlCode: "ROLE_EXISTS",
786
+ when: "Role name is taken"
787
+ }
788
+ }
789
+ },
790
+ policy: {
791
+ auth: "admin"
792
+ },
793
+ sideEffects: {
794
+ audit: ["role.created"]
795
+ }
796
+ });
797
+ var UpdateRoleContract = defineCommand3({
798
+ meta: {
799
+ key: "identity.rbac.role.update",
800
+ version: "1.0.0",
801
+ stability: "stable",
802
+ owners: ["@platform.identity-rbac"],
803
+ tags: ["identity", "rbac", "role", "update"],
804
+ description: "Update an existing role.",
805
+ goal: "Allow admins to modify role permissions.",
806
+ context: "Role management in admin settings."
807
+ },
808
+ io: {
809
+ input: UpdateRoleInputModel,
810
+ output: RoleModel
811
+ },
812
+ policy: {
813
+ auth: "admin"
814
+ },
815
+ sideEffects: {
816
+ audit: ["role.updated"]
817
+ }
818
+ });
819
+ var DeleteRoleContract = defineCommand3({
820
+ meta: {
821
+ key: "identity.rbac.role.delete",
822
+ version: "1.0.0",
823
+ stability: "stable",
824
+ owners: ["@platform.identity-rbac"],
825
+ tags: ["identity", "rbac", "role", "delete"],
826
+ description: "Delete an existing role.",
827
+ goal: "Allow admins to remove unused roles.",
828
+ context: "Role management. Removes all policy bindings using this role."
829
+ },
830
+ io: {
831
+ input: DeleteRoleInputModel,
832
+ output: SuccessResultModel,
833
+ errors: {
834
+ ROLE_IN_USE: {
835
+ description: "Role is still assigned to users or organizations",
836
+ http: 409,
837
+ gqlCode: "ROLE_IN_USE",
838
+ when: "Role has active bindings"
839
+ }
840
+ }
841
+ },
842
+ policy: {
843
+ auth: "admin"
844
+ },
845
+ sideEffects: {
846
+ audit: ["role.deleted"]
847
+ }
848
+ });
849
+ var ListRolesContract = defineQuery3({
850
+ meta: {
851
+ key: "identity.rbac.role.list",
852
+ version: "1.0.0",
853
+ stability: "stable",
854
+ owners: ["@platform.identity-rbac"],
855
+ tags: ["identity", "rbac", "role", "list"],
856
+ description: "List all available roles.",
857
+ goal: "Show available roles for assignment.",
858
+ context: "Role assignment UI."
859
+ },
860
+ io: {
861
+ input: null,
862
+ output: ListRolesOutputModel
863
+ },
864
+ policy: {
865
+ auth: "user"
866
+ }
867
+ });
868
+ var AssignRoleContract = defineCommand3({
869
+ meta: {
870
+ key: "identity.rbac.assign",
871
+ version: "1.0.0",
872
+ stability: "stable",
873
+ owners: ["@platform.identity-rbac"],
874
+ tags: ["identity", "rbac", "assign"],
875
+ description: "Assign a role to a user or organization.",
876
+ goal: "Grant permissions via role assignment.",
877
+ context: "User/org permission management."
878
+ },
879
+ io: {
880
+ input: AssignRoleInputModel,
881
+ output: PolicyBindingModel,
882
+ errors: {
883
+ ROLE_NOT_FOUND: {
884
+ description: "The specified role does not exist",
885
+ http: 404,
886
+ gqlCode: "ROLE_NOT_FOUND",
887
+ when: "Role ID is invalid"
888
+ },
889
+ ALREADY_ASSIGNED: {
890
+ description: "This role is already assigned to the target",
891
+ http: 409,
892
+ gqlCode: "ALREADY_ASSIGNED",
893
+ when: "Binding already exists"
894
+ }
895
+ }
896
+ },
897
+ policy: {
898
+ auth: "admin"
899
+ },
900
+ sideEffects: {
901
+ emits: [
902
+ {
903
+ key: "role.assigned",
904
+ version: "1.0.0",
905
+ when: "Role is assigned",
906
+ payload: PolicyBindingModel
907
+ }
908
+ ],
909
+ audit: ["role.assigned"]
910
+ }
911
+ });
912
+ var RevokeRoleContract = defineCommand3({
913
+ meta: {
914
+ key: "identity.rbac.revoke",
915
+ version: "1.0.0",
916
+ stability: "stable",
917
+ owners: ["@platform.identity-rbac"],
918
+ tags: ["identity", "rbac", "revoke"],
919
+ description: "Revoke a role from a user or organization.",
920
+ goal: "Remove permissions via role revocation.",
921
+ context: "User/org permission management."
922
+ },
923
+ io: {
924
+ input: RevokeRoleInputModel,
925
+ output: SuccessResultModel,
926
+ errors: {
927
+ BINDING_NOT_FOUND: {
928
+ description: "The policy binding does not exist",
929
+ http: 404,
930
+ gqlCode: "BINDING_NOT_FOUND",
931
+ when: "Binding ID is invalid"
932
+ }
933
+ }
934
+ },
935
+ policy: {
936
+ auth: "admin"
937
+ },
938
+ sideEffects: {
939
+ emits: [
940
+ {
941
+ key: "role.revoked",
942
+ version: "1.0.0",
943
+ when: "Role is revoked",
944
+ payload: BindingIdPayloadModel
945
+ }
946
+ ],
947
+ audit: ["role.revoked"]
948
+ }
949
+ });
950
+ var CheckPermissionContract = defineQuery3({
951
+ meta: {
952
+ key: "identity.rbac.check",
953
+ version: "1.0.0",
954
+ stability: "stable",
955
+ owners: ["@platform.identity-rbac"],
956
+ tags: ["identity", "rbac", "check", "permission"],
957
+ description: "Check if a user has a specific permission.",
958
+ goal: "Authorization check before sensitive operations.",
959
+ context: "Called by other services to verify permissions."
960
+ },
961
+ io: {
962
+ input: CheckPermissionInputModel,
963
+ output: PermissionCheckResultModel
964
+ },
965
+ policy: {
966
+ auth: "user"
967
+ }
968
+ });
969
+ var ListUserPermissionsContract = defineQuery3({
970
+ meta: {
971
+ key: "identity.rbac.permissions",
972
+ version: "1.0.0",
973
+ stability: "stable",
974
+ owners: ["@platform.identity-rbac"],
975
+ tags: ["identity", "rbac", "permissions", "user"],
976
+ description: "List all permissions for a user in a context.",
977
+ goal: "Show what a user can do in an org.",
978
+ context: "UI permission display, debugging."
979
+ },
980
+ io: {
981
+ input: ListUserPermissionsInputModel,
982
+ output: ListUserPermissionsOutputModel
983
+ },
984
+ policy: {
985
+ auth: "user"
986
+ }
987
+ });
988
+ export {
989
+ UserProfileModel,
990
+ UserDeletedPayloadModel,
991
+ UpdateUserInputModel,
992
+ UpdateUserContract,
993
+ UpdateRoleInputModel,
994
+ UpdateRoleContract,
995
+ UpdateOrgInputModel,
996
+ UpdateOrgContract,
997
+ SuccessResultModel,
998
+ RoleModel,
999
+ RevokeRoleInputModel,
1000
+ RevokeRoleContract,
1001
+ RemoveMemberInputModel,
1002
+ RemoveMemberContract,
1003
+ PolicyBindingModel,
1004
+ PermissionCheckResultModel,
1005
+ OrganizationWithRoleModel,
1006
+ OrganizationModel,
1007
+ MemberUserModel,
1008
+ MemberRemovedPayloadModel,
1009
+ MemberModel,
1010
+ ListUsersOutputModel,
1011
+ ListUsersInputModel,
1012
+ ListUsersContract,
1013
+ ListUserPermissionsOutputModel,
1014
+ ListUserPermissionsInputModel,
1015
+ ListUserPermissionsContract,
1016
+ ListUserOrgsOutputModel,
1017
+ ListUserOrgsContract,
1018
+ ListRolesOutputModel,
1019
+ ListRolesContract,
1020
+ ListMembersOutputModel,
1021
+ ListMembersInputModel,
1022
+ ListMembersContract,
1023
+ InviteMemberInputModel,
1024
+ InviteMemberContract,
1025
+ InvitationModel,
1026
+ GetOrgInputModel,
1027
+ GetOrgContract,
1028
+ GetCurrentUserContract,
1029
+ DeleteUserInputModel,
1030
+ DeleteUserContract,
1031
+ DeleteRoleInputModel,
1032
+ DeleteRoleContract,
1033
+ CreateUserInputModel,
1034
+ CreateUserContract,
1035
+ CreateRoleInputModel,
1036
+ CreateRoleContract,
1037
+ CreateOrgInputModel,
1038
+ CreateOrgContract,
1039
+ CheckPermissionInputModel,
1040
+ CheckPermissionContract,
1041
+ BindingIdPayloadModel,
1042
+ AssignRoleInputModel,
1043
+ AssignRoleContract,
1044
+ AcceptInviteInputModel,
1045
+ AcceptInviteContract
1046
+ };