@company-semantics/contracts 0.36.0 → 0.37.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.ts CHANGED
@@ -130,9 +130,24 @@ export type {
130
130
  IntegrationStatus,
131
131
  WorkspaceIntegration,
132
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,
133
148
  } from './org/index'
134
149
 
135
- export { ROLE_DISPLAY_MAP } from './org/index'
150
+ export { ROLE_DISPLAY_MAP, WORKSPACE_CAPABILITIES, ROLE_CAPABILITY_MAP } from './org/index'
136
151
 
137
152
  // MCP tool discovery types
138
153
  // @see company-semantics-backend/src/interfaces/mcp/ for implementation
@@ -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
@@ -20,6 +20,22 @@ export type {
20
20
  IntegrationStatus,
21
21
  WorkspaceIntegration,
22
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,
23
35
  } from './types';
24
36
 
25
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
@@ -110,12 +110,25 @@ export interface AuthMethodConfig {
110
110
  /**
111
111
  * Workspace authentication configuration.
112
112
  * Enabled auth methods and provider metadata.
113
+ *
114
+ * The `policy` field contains the org-level auth policy (owner-configurable).
115
+ * If no explicit policy exists, default values are returned.
113
116
  */
114
117
  export interface WorkspaceAuthConfig {
115
118
  emailOtp: AuthMethodConfig;
116
119
  googleSso: AuthMethodConfig;
117
120
  microsoftSso: AuthMethodConfig;
118
121
  okta: AuthMethodConfig;
122
+ /**
123
+ * Org-level authentication policy.
124
+ * Owner-only configuration for SSO requirements.
125
+ */
126
+ policy: {
127
+ /** Whether SSO is required for all members */
128
+ requireSSO: boolean;
129
+ /** List of allowed authentication providers */
130
+ allowedProviders: string[];
131
+ };
119
132
  }
120
133
 
121
134
  /**
@@ -126,16 +139,23 @@ export type IntegrationStatus = 'active' | 'expired' | 'revoked';
126
139
  /**
127
140
  * Workspace integration for the integrations list.
128
141
  * Shows connections visible to workspace admins.
142
+ *
143
+ * SECURITY: connectedBy.id should be empty string (not exposed for security).
144
+ * lastActivity is aggregated to reduce precision for timing attack mitigation.
145
+ * @see security-safety-reviewer finding: Excessive Information Disclosure
129
146
  */
130
147
  export interface WorkspaceIntegration {
131
148
  id: string;
132
149
  provider: string;
133
150
  status: IntegrationStatus;
134
151
  connectedBy: {
152
+ /** Always empty string for security (user IDs not exposed) */
135
153
  id: string;
154
+ /** Name of the user who connected this integration, or 'A team member' if unknown */
136
155
  name: string;
137
156
  };
138
157
  executionScope: ExecutionScope;
158
+ /** Aggregated last activity (e.g., 'within the last day', 'within the last week') */
139
159
  lastActivity: string | null;
140
160
  }
141
161
 
@@ -154,3 +174,133 @@ export interface WorkspaceAuditEvent {
154
174
  action: string;
155
175
  summary: string;
156
176
  }
177
+
178
+ // =============================================================================
179
+ // Workspace Expansion DTOs (Phase 3)
180
+ // @see ADR-CONT-031 for design rationale
181
+ // =============================================================================
182
+
183
+ /**
184
+ * Status of an organization invite.
185
+ */
186
+ export type OrgInviteStatus = 'pending' | 'accepted' | 'expired' | 'revoked';
187
+
188
+ /**
189
+ * Organization invite for the workspace invites list.
190
+ * Represents a pending or historical invitation.
191
+ */
192
+ export interface OrgInvite {
193
+ id: string;
194
+ orgId: string;
195
+ email: string;
196
+ role: WorkspaceRole;
197
+ invitedBy: {
198
+ id: string;
199
+ name: string;
200
+ };
201
+ status: OrgInviteStatus;
202
+ createdAt: string;
203
+ expiresAt: string;
204
+ acceptedAt?: string;
205
+ }
206
+
207
+ /**
208
+ * Request payload for creating an organization invite.
209
+ */
210
+ export interface CreateInviteRequest {
211
+ email: string;
212
+ role: 'admin' | 'member';
213
+ }
214
+
215
+ /**
216
+ * Request payload for accepting an organization invite.
217
+ */
218
+ export interface AcceptInviteRequest {
219
+ token: string;
220
+ }
221
+
222
+ /**
223
+ * Request payload for removing a member from the workspace.
224
+ */
225
+ export interface RemoveMemberRequest {
226
+ memberId: string;
227
+ }
228
+
229
+ /**
230
+ * Request payload for changing a member's role.
231
+ */
232
+ export interface ChangeMemberRoleRequest {
233
+ memberId: string;
234
+ newRole: 'admin' | 'member';
235
+ }
236
+
237
+ /**
238
+ * Organization authentication policy.
239
+ * Configures authentication requirements for workspace members.
240
+ *
241
+ * INVARIANT: Auth policy changes do not affect existing sessions
242
+ * (unless explicitly revoked via separate action).
243
+ * @see Phase 3 Invariant #11: No retroactive enforcement
244
+ */
245
+ export interface OrgAuthPolicy {
246
+ /** Whether SSO is required for all members */
247
+ requireSSO: boolean;
248
+ /** List of allowed authentication providers (e.g., 'google', 'microsoft', 'okta') */
249
+ allowedProviders: string[];
250
+ }
251
+
252
+ /**
253
+ * Request payload for updating organization auth policy.
254
+ */
255
+ export interface UpdateAuthPolicyRequest {
256
+ requireSSO?: boolean;
257
+ allowedProviders?: string[];
258
+ }
259
+
260
+ /**
261
+ * Request payload for promoting an integration to org scope.
262
+ *
263
+ * INVARIANT: acknowledgedRisk must be true to prove explicit intent.
264
+ * @see Phase 3 Invariant #15: Blast radius acknowledgment
265
+ */
266
+ export interface PromoteIntegrationRequest {
267
+ /** User must acknowledge the blast radius of org-wide access */
268
+ acknowledgedRisk: boolean;
269
+ }
270
+
271
+ /**
272
+ * Request payload for demoting an integration to self scope.
273
+ */
274
+ export interface DemoteIntegrationRequest {
275
+ /** Optional reason for demotion */
276
+ reason?: string;
277
+ }
278
+
279
+ // =============================================================================
280
+ // Phase 3 Audit Action Types
281
+ // @see ADR-CONT-031 for design rationale
282
+ // =============================================================================
283
+
284
+ /**
285
+ * Audit actions for Phase 3 workspace expansion features.
286
+ * These actions are emitted by the backend when workspace state changes.
287
+ *
288
+ * INVARIANT: All mutations must emit corresponding audit events.
289
+ * @see Phase 3 Invariant #13: All mutations are auditable
290
+ */
291
+ export type Phase3AuditAction =
292
+ // Invite lifecycle
293
+ | 'org.member.invited'
294
+ | 'org.member.joined'
295
+ | 'org.invite.revoked'
296
+ | 'org.invite.expired'
297
+ // Member mutations
298
+ | 'org.member.removed'
299
+ | 'org.member.role_changed'
300
+ // Organization transition
301
+ | 'org.type_transition'
302
+ // Integration scope changes
303
+ | 'integration.scope_promoted'
304
+ | 'integration.scope_demoted'
305
+ // Auth policy
306
+ | 'org.auth_policy.updated';