@company-semantics/contracts 0.35.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "0.35.0",
3
+ "version": "0.36.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.ts CHANGED
@@ -120,8 +120,35 @@ export type {
120
120
  OrganizationInfo,
121
121
  OwnershipTransferRequest,
122
122
  OwnershipTransferStatus,
123
+ // Workspace visibility DTOs (Phase 2)
124
+ // @see ADR-CONT-030 for design rationale
125
+ WorkspaceRole,
126
+ WorkspaceOverview,
127
+ WorkspaceMember,
128
+ AuthMethodConfig,
129
+ WorkspaceAuthConfig,
130
+ IntegrationStatus,
131
+ WorkspaceIntegration,
132
+ WorkspaceAuditEvent,
133
+ // Workspace expansion DTOs (Phase 3)
134
+ // @see ADR-CONT-031 for design rationale
135
+ OrgInviteStatus,
136
+ OrgInvite,
137
+ CreateInviteRequest,
138
+ AcceptInviteRequest,
139
+ RemoveMemberRequest,
140
+ ChangeMemberRoleRequest,
141
+ OrgAuthPolicy,
142
+ UpdateAuthPolicyRequest,
143
+ PromoteIntegrationRequest,
144
+ DemoteIntegrationRequest,
145
+ Phase3AuditAction,
146
+ // Workspace capability types (Phase 3)
147
+ WorkspaceCapability,
123
148
  } from './org/index'
124
149
 
150
+ export { ROLE_DISPLAY_MAP, WORKSPACE_CAPABILITIES, ROLE_CAPABILITY_MAP } from './org/index'
151
+
125
152
  // MCP tool discovery types
126
153
  // @see company-semantics-backend/src/interfaces/mcp/ for implementation
127
154
  export type {
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Workspace Capability Types
3
+ *
4
+ * Capability constants for Phase 3 workspace expansion features.
5
+ * These define the permission boundaries for workspace actions.
6
+ *
7
+ * INVARIANTS:
8
+ * - Capabilities are checked server-side before any mutation
9
+ * - UI uses capabilities to gate action visibility
10
+ * - Capabilities map to RBAC roles (see RoleCapabilityMap)
11
+ *
12
+ * @see ADR-CONT-031 for design rationale
13
+ */
14
+
15
+ // =============================================================================
16
+ // Workspace Capability Type
17
+ // =============================================================================
18
+
19
+ /**
20
+ * Capabilities for workspace actions.
21
+ * Used for capability-based access control in Phase 3 features.
22
+ *
23
+ * Capability hierarchy (implicit):
24
+ * - owner: all capabilities
25
+ * - admin: invite_member, manage_members (limited)
26
+ * - member: none (read-only)
27
+ */
28
+ export type WorkspaceCapability =
29
+ // Member management
30
+ | 'org.invite_member'
31
+ | 'org.manage_members'
32
+ // Integration management
33
+ | 'org.promote_integration'
34
+ | 'org.demote_integration'
35
+ // Auth policy
36
+ | 'org.manage_auth'
37
+ // Domain claiming (future)
38
+ | 'org.claim_domain';
39
+
40
+ /**
41
+ * All workspace capabilities.
42
+ * Use for iteration and validation.
43
+ */
44
+ export const WORKSPACE_CAPABILITIES: readonly WorkspaceCapability[] = [
45
+ 'org.invite_member',
46
+ 'org.manage_members',
47
+ 'org.promote_integration',
48
+ 'org.demote_integration',
49
+ 'org.manage_auth',
50
+ 'org.claim_domain',
51
+ ] as const;
52
+
53
+ // =============================================================================
54
+ // Role → Capability Mapping
55
+ // =============================================================================
56
+
57
+ /**
58
+ * Capabilities granted to each workspace role.
59
+ *
60
+ * INVARIANTS:
61
+ * - Owner has all capabilities (cannot be restricted)
62
+ * - Admin cannot demote other admins (enforce in service layer)
63
+ * - Member has no mutation capabilities
64
+ *
65
+ * @see Phase 3 Invariant #4: Admin floor
66
+ * @see Phase 3 Invariant #5: Admin ≠ owner
67
+ */
68
+ export const ROLE_CAPABILITY_MAP = {
69
+ owner: [
70
+ 'org.invite_member',
71
+ 'org.manage_members',
72
+ 'org.promote_integration',
73
+ 'org.demote_integration',
74
+ 'org.manage_auth',
75
+ 'org.claim_domain',
76
+ ],
77
+ admin: [
78
+ 'org.invite_member',
79
+ 'org.manage_members', // Note: cannot remove/demote other admins
80
+ 'org.demote_integration', // Can demote own integrations only
81
+ ],
82
+ member: [],
83
+ } as const satisfies Record<string, readonly WorkspaceCapability[]>;
package/src/org/index.ts CHANGED
@@ -11,4 +11,31 @@ export type {
11
11
  OrganizationInfo,
12
12
  OwnershipTransferRequest,
13
13
  OwnershipTransferStatus,
14
+ // Workspace visibility DTOs (Phase 2)
15
+ WorkspaceRole,
16
+ WorkspaceOverview,
17
+ WorkspaceMember,
18
+ AuthMethodConfig,
19
+ WorkspaceAuthConfig,
20
+ IntegrationStatus,
21
+ WorkspaceIntegration,
22
+ WorkspaceAuditEvent,
23
+ // Workspace expansion DTOs (Phase 3)
24
+ OrgInviteStatus,
25
+ OrgInvite,
26
+ CreateInviteRequest,
27
+ AcceptInviteRequest,
28
+ RemoveMemberRequest,
29
+ ChangeMemberRoleRequest,
30
+ OrgAuthPolicy,
31
+ UpdateAuthPolicyRequest,
32
+ PromoteIntegrationRequest,
33
+ DemoteIntegrationRequest,
34
+ Phase3AuditAction,
14
35
  } from './types';
36
+
37
+ export { ROLE_DISPLAY_MAP } from './types';
38
+
39
+ // Workspace capability types (Phase 3)
40
+ export type { WorkspaceCapability } from './capabilities';
41
+ export { WORKSPACE_CAPABILITIES, ROLE_CAPABILITY_MAP } from './capabilities';
package/src/org/types.ts CHANGED
@@ -47,3 +47,247 @@ export interface OwnershipTransferStatus {
47
47
  requestedAt?: string;
48
48
  expiresAt?: string;
49
49
  }
50
+
51
+ // =============================================================================
52
+ // Workspace Visibility DTOs (Phase 2)
53
+ // @see ADR-CONT-030 for design rationale
54
+ // =============================================================================
55
+
56
+ /**
57
+ * Display role for workspace members.
58
+ * Presentation-layer simplification of the internal RBAC roles.
59
+ */
60
+ export type WorkspaceRole = 'owner' | 'admin' | 'member';
61
+
62
+ /**
63
+ * RBAC → UI role mapping (presentation only).
64
+ * Maps internal system roles to user-facing display roles.
65
+ */
66
+ export const ROLE_DISPLAY_MAP = {
67
+ org_owner: 'owner',
68
+ org_admin: 'admin',
69
+ // All other roles → 'member'
70
+ } as const satisfies Partial<Record<string, WorkspaceRole>>;
71
+
72
+ /**
73
+ * Workspace overview for the control plane UI.
74
+ * Read-only projection of organization state.
75
+ */
76
+ export interface WorkspaceOverview {
77
+ id: string;
78
+ name: string;
79
+ type: OrgType;
80
+ owner: {
81
+ id: string;
82
+ name: string;
83
+ email: string;
84
+ };
85
+ createdAt: string;
86
+ memberCount: number;
87
+ claimable: boolean;
88
+ }
89
+
90
+ /**
91
+ * Workspace member for the members list.
92
+ * Human users only (no agent actors).
93
+ */
94
+ export interface WorkspaceMember {
95
+ id: string;
96
+ name: string;
97
+ email: string;
98
+ role: WorkspaceRole;
99
+ joinedAt: string;
100
+ }
101
+
102
+ /**
103
+ * Authentication method configuration.
104
+ */
105
+ export interface AuthMethodConfig {
106
+ enabled: boolean;
107
+ provider?: string;
108
+ }
109
+
110
+ /**
111
+ * Workspace authentication configuration.
112
+ * Enabled auth methods and provider metadata.
113
+ */
114
+ export interface WorkspaceAuthConfig {
115
+ emailOtp: AuthMethodConfig;
116
+ googleSso: AuthMethodConfig;
117
+ microsoftSso: AuthMethodConfig;
118
+ okta: AuthMethodConfig;
119
+ }
120
+
121
+ /**
122
+ * Integration connection status.
123
+ */
124
+ export type IntegrationStatus = 'active' | 'expired' | 'revoked';
125
+
126
+ /**
127
+ * Workspace integration for the integrations list.
128
+ * Shows connections visible to workspace admins.
129
+ *
130
+ * SECURITY: connectedBy.id should be empty string (not exposed for security).
131
+ * lastActivity is aggregated to reduce precision for timing attack mitigation.
132
+ * @see security-safety-reviewer finding: Excessive Information Disclosure
133
+ */
134
+ export interface WorkspaceIntegration {
135
+ id: string;
136
+ provider: string;
137
+ status: IntegrationStatus;
138
+ connectedBy: {
139
+ /** Always empty string for security (user IDs not exposed) */
140
+ id: string;
141
+ /** Name of the user who connected this integration, or 'A team member' if unknown */
142
+ name: string;
143
+ };
144
+ executionScope: ExecutionScope;
145
+ /** Aggregated last activity (e.g., 'within the last day', 'within the last week') */
146
+ lastActivity: string | null;
147
+ }
148
+
149
+ /**
150
+ * Audit event for the workspace audit log.
151
+ * Filtered to spec events only (server-side).
152
+ */
153
+ export interface WorkspaceAuditEvent {
154
+ id: string;
155
+ timestamp: string;
156
+ actor: {
157
+ id: string;
158
+ name: string;
159
+ type: 'user' | 'system';
160
+ };
161
+ action: string;
162
+ summary: string;
163
+ }
164
+
165
+ // =============================================================================
166
+ // Workspace Expansion DTOs (Phase 3)
167
+ // @see ADR-CONT-031 for design rationale
168
+ // =============================================================================
169
+
170
+ /**
171
+ * Status of an organization invite.
172
+ */
173
+ export type OrgInviteStatus = 'pending' | 'accepted' | 'expired' | 'revoked';
174
+
175
+ /**
176
+ * Organization invite for the workspace invites list.
177
+ * Represents a pending or historical invitation.
178
+ */
179
+ export interface OrgInvite {
180
+ id: string;
181
+ orgId: string;
182
+ email: string;
183
+ role: WorkspaceRole;
184
+ invitedBy: {
185
+ id: string;
186
+ name: string;
187
+ };
188
+ status: OrgInviteStatus;
189
+ createdAt: string;
190
+ expiresAt: string;
191
+ acceptedAt?: string;
192
+ }
193
+
194
+ /**
195
+ * Request payload for creating an organization invite.
196
+ */
197
+ export interface CreateInviteRequest {
198
+ email: string;
199
+ role: 'admin' | 'member';
200
+ }
201
+
202
+ /**
203
+ * Request payload for accepting an organization invite.
204
+ */
205
+ export interface AcceptInviteRequest {
206
+ token: string;
207
+ }
208
+
209
+ /**
210
+ * Request payload for removing a member from the workspace.
211
+ */
212
+ export interface RemoveMemberRequest {
213
+ memberId: string;
214
+ }
215
+
216
+ /**
217
+ * Request payload for changing a member's role.
218
+ */
219
+ export interface ChangeMemberRoleRequest {
220
+ memberId: string;
221
+ newRole: 'admin' | 'member';
222
+ }
223
+
224
+ /**
225
+ * Organization authentication policy.
226
+ * Configures authentication requirements for workspace members.
227
+ *
228
+ * INVARIANT: Auth policy changes do not affect existing sessions
229
+ * (unless explicitly revoked via separate action).
230
+ * @see Phase 3 Invariant #11: No retroactive enforcement
231
+ */
232
+ export interface OrgAuthPolicy {
233
+ /** Whether SSO is required for all members */
234
+ requireSSO: boolean;
235
+ /** List of allowed authentication providers (e.g., 'google', 'microsoft', 'okta') */
236
+ allowedProviders: string[];
237
+ }
238
+
239
+ /**
240
+ * Request payload for updating organization auth policy.
241
+ */
242
+ export interface UpdateAuthPolicyRequest {
243
+ requireSSO?: boolean;
244
+ allowedProviders?: string[];
245
+ }
246
+
247
+ /**
248
+ * Request payload for promoting an integration to org scope.
249
+ *
250
+ * INVARIANT: acknowledgedRisk must be true to prove explicit intent.
251
+ * @see Phase 3 Invariant #15: Blast radius acknowledgment
252
+ */
253
+ export interface PromoteIntegrationRequest {
254
+ /** User must acknowledge the blast radius of org-wide access */
255
+ acknowledgedRisk: boolean;
256
+ }
257
+
258
+ /**
259
+ * Request payload for demoting an integration to self scope.
260
+ */
261
+ export interface DemoteIntegrationRequest {
262
+ /** Optional reason for demotion */
263
+ reason?: string;
264
+ }
265
+
266
+ // =============================================================================
267
+ // Phase 3 Audit Action Types
268
+ // @see ADR-CONT-031 for design rationale
269
+ // =============================================================================
270
+
271
+ /**
272
+ * Audit actions for Phase 3 workspace expansion features.
273
+ * These actions are emitted by the backend when workspace state changes.
274
+ *
275
+ * INVARIANT: All mutations must emit corresponding audit events.
276
+ * @see Phase 3 Invariant #13: All mutations are auditable
277
+ */
278
+ export type Phase3AuditAction =
279
+ // Invite lifecycle
280
+ | 'org.member.invited'
281
+ | 'org.member.joined'
282
+ | 'org.invite.revoked'
283
+ | 'org.invite.expired'
284
+ // Member mutations
285
+ | 'org.member.removed'
286
+ | 'org.member.role_changed'
287
+ // Organization transition
288
+ | 'org.type_transition'
289
+ // Integration scope changes
290
+ | 'integration.scope_promoted'
291
+ | 'integration.scope_demoted'
292
+ // Auth policy
293
+ | 'org.auth_policy.updated';