@contractspec/lib.identity-rbac 1.56.1 → 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 -7
  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,605 +1,656 @@
1
- import { SuccessResultModel } from "./user.js";
2
- import { ScalarTypeEnum, SchemaModel } from "@contractspec/lib.schema";
1
+ // @bun
2
+ // src/contracts/user.ts
3
+ import { SchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
4
  import { defineCommand, defineQuery } from "@contractspec/lib.contracts";
4
-
5
- //#region src/contracts/organization.ts
6
- const OWNERS = ["platform.identity-rbac"];
7
- const OrganizationModel = new SchemaModel({
8
- name: "Organization",
9
- description: "Organization details",
10
- fields: {
11
- id: {
12
- type: ScalarTypeEnum.String_unsecure(),
13
- isOptional: false
14
- },
15
- name: {
16
- type: ScalarTypeEnum.String_unsecure(),
17
- isOptional: false
18
- },
19
- slug: {
20
- type: ScalarTypeEnum.String_unsecure(),
21
- isOptional: true
22
- },
23
- logo: {
24
- type: ScalarTypeEnum.URL(),
25
- isOptional: true
26
- },
27
- description: {
28
- type: ScalarTypeEnum.String_unsecure(),
29
- isOptional: true
30
- },
31
- type: {
32
- type: ScalarTypeEnum.String_unsecure(),
33
- isOptional: false
34
- },
35
- onboardingCompleted: {
36
- type: ScalarTypeEnum.Boolean(),
37
- isOptional: false
38
- },
39
- createdAt: {
40
- type: ScalarTypeEnum.DateTime(),
41
- isOptional: false
42
- }
43
- }
44
- });
45
- const MemberUserModel = new SchemaModel({
46
- name: "MemberUser",
47
- description: "Basic user info within a member",
48
- fields: {
49
- id: {
50
- type: ScalarTypeEnum.String_unsecure(),
51
- isOptional: false
52
- },
53
- email: {
54
- type: ScalarTypeEnum.EmailAddress(),
55
- isOptional: false
56
- },
57
- name: {
58
- type: ScalarTypeEnum.String_unsecure(),
59
- isOptional: true
60
- }
61
- }
62
- });
63
- const MemberModel = new SchemaModel({
64
- name: "Member",
65
- description: "Organization member",
66
- fields: {
67
- id: {
68
- type: ScalarTypeEnum.String_unsecure(),
69
- isOptional: false
70
- },
71
- userId: {
72
- type: ScalarTypeEnum.String_unsecure(),
73
- isOptional: false
74
- },
75
- organizationId: {
76
- type: ScalarTypeEnum.String_unsecure(),
77
- isOptional: false
78
- },
79
- role: {
80
- type: ScalarTypeEnum.String_unsecure(),
81
- isOptional: false
82
- },
83
- createdAt: {
84
- type: ScalarTypeEnum.DateTime(),
85
- isOptional: false
86
- },
87
- user: {
88
- type: MemberUserModel,
89
- isOptional: false
90
- }
91
- }
92
- });
93
- const InvitationModel = new SchemaModel({
94
- name: "Invitation",
95
- description: "Organization invitation",
96
- fields: {
97
- id: {
98
- type: ScalarTypeEnum.String_unsecure(),
99
- isOptional: false
100
- },
101
- email: {
102
- type: ScalarTypeEnum.EmailAddress(),
103
- isOptional: false
104
- },
105
- role: {
106
- type: ScalarTypeEnum.String_unsecure(),
107
- isOptional: true
108
- },
109
- status: {
110
- type: ScalarTypeEnum.String_unsecure(),
111
- isOptional: false
112
- },
113
- expiresAt: {
114
- type: ScalarTypeEnum.DateTime(),
115
- isOptional: true
116
- },
117
- createdAt: {
118
- type: ScalarTypeEnum.DateTime(),
119
- isOptional: false
120
- }
121
- }
122
- });
123
- const CreateOrgInputModel = new SchemaModel({
124
- name: "CreateOrgInput",
125
- description: "Input for creating an organization",
126
- fields: {
127
- name: {
128
- type: ScalarTypeEnum.NonEmptyString(),
129
- isOptional: false
130
- },
131
- slug: {
132
- type: ScalarTypeEnum.String_unsecure(),
133
- isOptional: true
134
- },
135
- description: {
136
- type: ScalarTypeEnum.String_unsecure(),
137
- isOptional: true
138
- },
139
- type: {
140
- type: ScalarTypeEnum.String_unsecure(),
141
- isOptional: true
142
- }
143
- }
144
- });
145
- const GetOrgInputModel = new SchemaModel({
146
- name: "GetOrgInput",
147
- description: "Input for getting an organization",
148
- fields: { orgId: {
149
- type: ScalarTypeEnum.String_unsecure(),
150
- isOptional: false
151
- } }
152
- });
153
- const UpdateOrgInputModel = new SchemaModel({
154
- name: "UpdateOrgInput",
155
- description: "Input for updating an organization",
156
- fields: {
157
- orgId: {
158
- type: ScalarTypeEnum.String_unsecure(),
159
- isOptional: false
160
- },
161
- name: {
162
- type: ScalarTypeEnum.String_unsecure(),
163
- isOptional: true
164
- },
165
- slug: {
166
- type: ScalarTypeEnum.String_unsecure(),
167
- isOptional: true
168
- },
169
- logo: {
170
- type: ScalarTypeEnum.URL(),
171
- isOptional: true
172
- },
173
- description: {
174
- type: ScalarTypeEnum.String_unsecure(),
175
- isOptional: true
176
- }
177
- }
178
- });
179
- const InviteMemberInputModel = new SchemaModel({
180
- name: "InviteMemberInput",
181
- description: "Input for inviting a member",
182
- fields: {
183
- orgId: {
184
- type: ScalarTypeEnum.String_unsecure(),
185
- isOptional: false
186
- },
187
- email: {
188
- type: ScalarTypeEnum.EmailAddress(),
189
- isOptional: false
190
- },
191
- role: {
192
- type: ScalarTypeEnum.String_unsecure(),
193
- isOptional: false
194
- },
195
- teamId: {
196
- type: ScalarTypeEnum.String_unsecure(),
197
- isOptional: true
198
- }
199
- }
200
- });
201
- const AcceptInviteInputModel = new SchemaModel({
202
- name: "AcceptInviteInput",
203
- description: "Input for accepting an invitation",
204
- fields: { invitationId: {
205
- type: ScalarTypeEnum.String_unsecure(),
206
- isOptional: false
207
- } }
208
- });
209
- const RemoveMemberInputModel = new SchemaModel({
210
- name: "RemoveMemberInput",
211
- description: "Input for removing a member",
212
- fields: {
213
- orgId: {
214
- type: ScalarTypeEnum.String_unsecure(),
215
- isOptional: false
216
- },
217
- userId: {
218
- type: ScalarTypeEnum.String_unsecure(),
219
- isOptional: false
220
- }
221
- }
222
- });
223
- const MemberRemovedPayloadModel = new SchemaModel({
224
- name: "MemberRemovedPayload",
225
- description: "Payload for member removed event",
226
- fields: {
227
- orgId: {
228
- type: ScalarTypeEnum.String_unsecure(),
229
- isOptional: false
230
- },
231
- userId: {
232
- type: ScalarTypeEnum.String_unsecure(),
233
- isOptional: false
234
- }
235
- }
236
- });
237
- const ListMembersInputModel = new SchemaModel({
238
- name: "ListMembersInput",
239
- description: "Input for listing members",
240
- fields: {
241
- orgId: {
242
- type: ScalarTypeEnum.String_unsecure(),
243
- isOptional: false
244
- },
245
- limit: {
246
- type: ScalarTypeEnum.Int_unsecure(),
247
- isOptional: true
248
- },
249
- offset: {
250
- type: ScalarTypeEnum.Int_unsecure(),
251
- isOptional: true
252
- }
253
- }
254
- });
255
- const ListMembersOutputModel = new SchemaModel({
256
- name: "ListMembersOutput",
257
- description: "Output for listing members",
258
- fields: {
259
- members: {
260
- type: MemberModel,
261
- isOptional: false,
262
- isArray: true
263
- },
264
- total: {
265
- type: ScalarTypeEnum.Int_unsecure(),
266
- isOptional: false
267
- }
268
- }
269
- });
270
- const OrganizationWithRoleModel = new SchemaModel({
271
- name: "OrganizationWithRole",
272
- description: "Organization with user role",
273
- fields: {
274
- id: {
275
- type: ScalarTypeEnum.String_unsecure(),
276
- isOptional: false
277
- },
278
- name: {
279
- type: ScalarTypeEnum.String_unsecure(),
280
- isOptional: false
281
- },
282
- slug: {
283
- type: ScalarTypeEnum.String_unsecure(),
284
- isOptional: true
285
- },
286
- logo: {
287
- type: ScalarTypeEnum.URL(),
288
- isOptional: true
289
- },
290
- description: {
291
- type: ScalarTypeEnum.String_unsecure(),
292
- isOptional: true
293
- },
294
- type: {
295
- type: ScalarTypeEnum.String_unsecure(),
296
- isOptional: false
297
- },
298
- onboardingCompleted: {
299
- type: ScalarTypeEnum.Boolean(),
300
- isOptional: false
301
- },
302
- createdAt: {
303
- type: ScalarTypeEnum.DateTime(),
304
- isOptional: false
305
- },
306
- role: {
307
- type: ScalarTypeEnum.String_unsecure(),
308
- isOptional: false
309
- }
310
- }
311
- });
312
- const ListUserOrgsOutputModel = new SchemaModel({
313
- name: "ListUserOrgsOutput",
314
- description: "Output for listing user organizations",
315
- fields: { organizations: {
316
- type: OrganizationWithRoleModel,
317
- isOptional: false,
318
- isArray: true
319
- } }
320
- });
321
- /**
322
- * Create a new organization.
323
- */
324
- const CreateOrgContract = defineCommand({
325
- meta: {
326
- key: "identity.org.create",
327
- version: "1.0.0",
328
- stability: "stable",
329
- owners: [...OWNERS],
330
- tags: [
331
- "identity",
332
- "org",
333
- "create"
334
- ],
335
- description: "Create a new organization.",
336
- goal: "Allow users to create new organizations/workspaces.",
337
- context: "Called during onboarding or when creating additional workspaces."
338
- },
339
- io: {
340
- input: CreateOrgInputModel,
341
- output: OrganizationModel,
342
- errors: { SLUG_EXISTS: {
343
- description: "An organization with this slug already exists",
344
- http: 409,
345
- gqlCode: "SLUG_EXISTS",
346
- when: "Slug is already taken"
347
- } }
348
- },
349
- policy: { auth: "user" },
350
- sideEffects: {
351
- emits: [{
352
- key: "org.created",
353
- version: "1.0.0",
354
- when: "Organization is created",
355
- payload: OrganizationModel
356
- }],
357
- audit: ["org.created"]
358
- }
359
- });
360
- /**
361
- * Get organization details.
362
- */
363
- const GetOrgContract = defineQuery({
364
- meta: {
365
- key: "identity.org.get",
366
- version: "1.0.0",
367
- stability: "stable",
368
- owners: [...OWNERS],
369
- tags: [
370
- "identity",
371
- "org",
372
- "get"
373
- ],
374
- description: "Get organization details.",
375
- goal: "Retrieve organization information.",
376
- context: "Called when viewing organization settings or dashboard."
377
- },
378
- io: {
379
- input: GetOrgInputModel,
380
- output: OrganizationModel
381
- },
382
- policy: { auth: "user" }
383
- });
384
- /**
385
- * Update organization.
386
- */
387
- const UpdateOrgContract = defineCommand({
388
- meta: {
389
- key: "identity.org.update",
390
- version: "1.0.0",
391
- stability: "stable",
392
- owners: [...OWNERS],
393
- tags: [
394
- "identity",
395
- "org",
396
- "update"
397
- ],
398
- description: "Update organization details.",
399
- goal: "Allow org admins to update organization settings.",
400
- context: "Organization settings page."
401
- },
402
- io: {
403
- input: UpdateOrgInputModel,
404
- output: OrganizationModel
405
- },
406
- policy: { auth: "user" },
407
- sideEffects: {
408
- emits: [{
409
- key: "org.updated",
410
- version: "1.0.0",
411
- when: "Organization is updated",
412
- payload: OrganizationModel
413
- }],
414
- audit: ["org.updated"]
415
- }
416
- });
417
- /**
418
- * Invite a member to the organization.
419
- */
420
- const InviteMemberContract = defineCommand({
421
- meta: {
422
- key: "identity.org.invite",
423
- version: "1.0.0",
424
- stability: "stable",
425
- owners: [...OWNERS],
426
- tags: [
427
- "identity",
428
- "org",
429
- "invite",
430
- "member"
431
- ],
432
- description: "Invite a user to join the organization.",
433
- goal: "Allow org admins to invite new members.",
434
- context: "Team management. Sends invitation email."
435
- },
436
- io: {
437
- input: InviteMemberInputModel,
438
- output: InvitationModel,
439
- errors: {
440
- ALREADY_MEMBER: {
441
- description: "User is already a member of this organization",
442
- http: 409,
443
- gqlCode: "ALREADY_MEMBER",
444
- when: "Invitee is already a member"
445
- },
446
- INVITE_PENDING: {
447
- description: "An invitation for this email is already pending",
448
- http: 409,
449
- gqlCode: "INVITE_PENDING",
450
- when: "Active invitation exists"
451
- }
452
- }
453
- },
454
- policy: { auth: "user" },
455
- sideEffects: {
456
- emits: [{
457
- key: "org.invite.sent",
458
- version: "1.0.0",
459
- when: "Invitation is sent",
460
- payload: InvitationModel
461
- }],
462
- audit: ["org.invite.sent"]
463
- }
464
- });
465
- /**
466
- * Accept an invitation.
467
- */
468
- const AcceptInviteContract = defineCommand({
469
- meta: {
470
- key: "identity.org.invite.accept",
471
- version: "1.0.0",
472
- stability: "stable",
473
- owners: [...OWNERS],
474
- tags: [
475
- "identity",
476
- "org",
477
- "invite",
478
- "accept"
479
- ],
480
- description: "Accept an organization invitation.",
481
- goal: "Allow users to join organizations via invitation.",
482
- context: "Called from invitation email link."
483
- },
484
- io: {
485
- input: AcceptInviteInputModel,
486
- output: MemberModel,
487
- errors: {
488
- INVITE_EXPIRED: {
489
- description: "The invitation has expired",
490
- http: 410,
491
- gqlCode: "INVITE_EXPIRED",
492
- when: "Invitation is past expiry date"
493
- },
494
- INVITE_USED: {
495
- description: "The invitation has already been used",
496
- http: 409,
497
- gqlCode: "INVITE_USED",
498
- when: "Invitation was already accepted"
499
- }
500
- }
501
- },
502
- policy: { auth: "user" },
503
- sideEffects: {
504
- emits: [{
505
- key: "org.member.added",
506
- version: "1.0.0",
507
- when: "Member joins org",
508
- payload: MemberModel
509
- }],
510
- audit: ["org.member.added"]
511
- }
512
- });
513
- /**
514
- * Remove a member from the organization.
515
- */
516
- const RemoveMemberContract = defineCommand({
517
- meta: {
518
- key: "identity.org.member.remove",
519
- version: "1.0.0",
520
- stability: "stable",
521
- owners: [...OWNERS],
522
- tags: [
523
- "identity",
524
- "org",
525
- "member",
526
- "remove"
527
- ],
528
- description: "Remove a member from the organization.",
529
- goal: "Allow org admins to remove members.",
530
- context: "Team management."
531
- },
532
- io: {
533
- input: RemoveMemberInputModel,
534
- output: SuccessResultModel,
535
- errors: { CANNOT_REMOVE_OWNER: {
536
- description: "Cannot remove the organization owner",
537
- http: 403,
538
- gqlCode: "CANNOT_REMOVE_OWNER",
539
- when: "Target is the org owner"
540
- } }
541
- },
542
- policy: { auth: "user" },
543
- sideEffects: {
544
- emits: [{
545
- key: "org.member.removed",
546
- version: "1.0.0",
547
- when: "Member is removed",
548
- payload: MemberRemovedPayloadModel
549
- }],
550
- audit: ["org.member.removed"]
551
- }
552
- });
553
- /**
554
- * List organization members.
555
- */
556
- const ListMembersContract = defineQuery({
557
- meta: {
558
- key: "identity.org.members.list",
559
- version: "1.0.0",
560
- stability: "stable",
561
- owners: [...OWNERS],
562
- tags: [
563
- "identity",
564
- "org",
565
- "member",
566
- "list"
567
- ],
568
- description: "List organization members.",
569
- goal: "View all members of an organization.",
570
- context: "Team management page."
571
- },
572
- io: {
573
- input: ListMembersInputModel,
574
- output: ListMembersOutputModel
575
- },
576
- policy: { auth: "user" }
577
- });
578
- /**
579
- * List user's organizations.
580
- */
581
- const ListUserOrgsContract = defineQuery({
582
- meta: {
583
- key: "identity.org.list",
584
- version: "1.0.0",
585
- stability: "stable",
586
- owners: [...OWNERS],
587
- tags: [
588
- "identity",
589
- "org",
590
- "list"
591
- ],
592
- description: "List organizations the current user belongs to.",
593
- goal: "Show user their organizations for workspace switching.",
594
- context: "Workspace switcher, org selection."
595
- },
596
- io: {
597
- input: null,
598
- output: ListUserOrgsOutputModel
599
- },
600
- policy: { auth: "user" }
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
+ }
601
221
  });
602
222
 
603
- //#endregion
604
- export { AcceptInviteContract, AcceptInviteInputModel, CreateOrgContract, CreateOrgInputModel, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, RemoveMemberContract, RemoveMemberInputModel, UpdateOrgContract, UpdateOrgInputModel };
605
- //# sourceMappingURL=organization.js.map
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
+ export {
633
+ UpdateOrgInputModel,
634
+ UpdateOrgContract,
635
+ RemoveMemberInputModel,
636
+ RemoveMemberContract,
637
+ OrganizationWithRoleModel,
638
+ OrganizationModel,
639
+ MemberUserModel,
640
+ MemberRemovedPayloadModel,
641
+ MemberModel,
642
+ ListUserOrgsOutputModel,
643
+ ListUserOrgsContract,
644
+ ListMembersOutputModel,
645
+ ListMembersInputModel,
646
+ ListMembersContract,
647
+ InviteMemberInputModel,
648
+ InviteMemberContract,
649
+ InvitationModel,
650
+ GetOrgInputModel,
651
+ GetOrgContract,
652
+ CreateOrgInputModel,
653
+ CreateOrgContract,
654
+ AcceptInviteInputModel,
655
+ AcceptInviteContract
656
+ };