@company-semantics/contracts 0.118.0 → 0.120.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/src/chat/index.ts CHANGED
@@ -38,6 +38,14 @@ export type {
38
38
  ChatInvalidationEvent,
39
39
  // SSE event unions
40
40
  ChatSseEvent,
41
+ // HTTP response types
42
+ ChatSuccessResponse,
43
+ ChatByInteractionResponse,
44
+ ChatListResponse,
45
+ CreateChatResponse,
46
+ CreateShareResponse,
47
+ ListSharesResponse,
48
+ UpdateShareResponse,
41
49
  } from './types'
42
50
 
43
51
  // =============================================================================
@@ -65,6 +73,14 @@ export {
65
73
  ChatDomainEventSchema,
66
74
  ChatInvalidationEventSchema,
67
75
  ChatSseEventSchema,
76
+ // HTTP response schemas
77
+ ChatSuccessResponseSchema,
78
+ ChatByInteractionResponseSchema,
79
+ ChatListResponseSchema,
80
+ CreateChatResponseSchema,
81
+ CreateShareResponseSchema,
82
+ ListSharesResponseSchema,
83
+ UpdateShareResponseSchema,
68
84
  } from './schemas'
69
85
 
70
86
  // Runtime profile types and constants
@@ -152,3 +152,43 @@ export const ChatSseEventSchema = z.discriminatedUnion('type', [
152
152
  InvalidateChatEventSchema,
153
153
  InvalidateChatListEventSchema,
154
154
  ])
155
+
156
+ // =============================================================================
157
+ // HTTP Response Schemas
158
+ // =============================================================================
159
+
160
+ /** Generic success confirmation for mutations that return no entity data. */
161
+ export const ChatSuccessResponseSchema = z.object({
162
+ success: z.literal(true),
163
+ })
164
+
165
+ /** Response for GET /api/chats/by-interaction/:interactionId */
166
+ export const ChatByInteractionResponseSchema = z.object({
167
+ chatId: z.string(),
168
+ })
169
+
170
+ /** Response for GET /api/chats */
171
+ export const ChatListResponseSchema = z.object({
172
+ chats: z.array(ChatSummaryExtendedSchema),
173
+ })
174
+
175
+ /** Response for POST /api/chats */
176
+ export const CreateChatResponseSchema = z.object({
177
+ chat: ChatSummaryExtendedSchema,
178
+ })
179
+
180
+ /** Response for POST /api/chats/:chatId/shares */
181
+ export const CreateShareResponseSchema = z.object({
182
+ share: ChatShareInfoSchema,
183
+ shareUrl: z.string(),
184
+ })
185
+
186
+ /** Response for GET /api/chats/:chatId/shares */
187
+ export const ListSharesResponseSchema = z.object({
188
+ shares: z.array(ChatShareInfoSchema),
189
+ })
190
+
191
+ /** Response for PATCH /api/shares/:shareId */
192
+ export const UpdateShareResponseSchema = z.object({
193
+ share: ChatShareInfoSchema,
194
+ })
package/src/chat/types.ts CHANGED
@@ -27,6 +27,13 @@ import {
27
27
  ChatDomainEventSchema,
28
28
  ChatInvalidationEventSchema,
29
29
  ChatSseEventSchema,
30
+ ChatSuccessResponseSchema,
31
+ ChatByInteractionResponseSchema,
32
+ ChatListResponseSchema,
33
+ CreateChatResponseSchema,
34
+ CreateShareResponseSchema,
35
+ ListSharesResponseSchema,
36
+ UpdateShareResponseSchema,
30
37
  } from './schemas'
31
38
 
32
39
  // =============================================================================
@@ -227,3 +234,28 @@ export type ChatInvalidationEvent = z.infer<typeof ChatInvalidationEventSchema>
227
234
  * Client receives these via SSE and handles accordingly.
228
235
  */
229
236
  export type ChatSseEvent = z.infer<typeof ChatSseEventSchema>
237
+
238
+ // =============================================================================
239
+ // HTTP Response Types (derived from response schemas)
240
+ // =============================================================================
241
+
242
+ /** Generic mutation success confirmation. */
243
+ export type ChatSuccessResponse = z.infer<typeof ChatSuccessResponseSchema>
244
+
245
+ /** Response for GET /api/chats/by-interaction/:interactionId */
246
+ export type ChatByInteractionResponse = z.infer<typeof ChatByInteractionResponseSchema>
247
+
248
+ /** Response for GET /api/chats */
249
+ export type ChatListResponse = z.infer<typeof ChatListResponseSchema>
250
+
251
+ /** Response for POST /api/chats */
252
+ export type CreateChatResponse = z.infer<typeof CreateChatResponseSchema>
253
+
254
+ /** Response for POST /api/chats/:chatId/shares */
255
+ export type CreateShareResponse = z.infer<typeof CreateShareResponseSchema>
256
+
257
+ /** Response for GET /api/chats/:chatId/shares */
258
+ export type ListSharesResponse = z.infer<typeof ListSharesResponseSchema>
259
+
260
+ /** Response for PATCH /api/shares/:shareId */
261
+ export type UpdateShareResponse = z.infer<typeof UpdateShareResponseSchema>
package/src/org/index.ts CHANGED
@@ -136,3 +136,46 @@ export type {
136
136
  ShareState,
137
137
  PermissionAuditEntry,
138
138
  } from './sharing';
139
+
140
+ // Workspace response schemas (PRD-00445)
141
+ export {
142
+ WorkspaceAccessResponseSchema,
143
+ WorkspaceOverviewSchema,
144
+ WorkspaceMembersResponseSchema,
145
+ WorkspaceAuthConfigSchema,
146
+ WorkspaceAuditEventSchema,
147
+ WorkspaceAuditResponseSchema,
148
+ WorkspaceResolvePathResponseSchema,
149
+ OrgAuthPolicySchema,
150
+ OidcValidationResultSchema,
151
+ WorkspaceResyncSlackLogoResponseSchema,
152
+ TestSsoInitiationSchema,
153
+ TestSsoResultSchema,
154
+ RemoveMemberResponseSchema,
155
+ ChangeMemberRoleResponseSchema,
156
+ UserOrgsResponseSchema,
157
+ SetActiveOrgResponseSchema,
158
+ LeaveOrgResponseSchema,
159
+ ScopeCheckResponseSchema,
160
+ ScopeCheckBatchResponseSchema,
161
+ } from './schemas';
162
+ export type {
163
+ WorkspaceAccessResponse,
164
+ WorkspaceOverview as WorkspaceOverviewDto,
165
+ WorkspaceMembersResponse,
166
+ WorkspaceAuthConfig as WorkspaceAuthConfigDto,
167
+ WorkspaceAuditEvent as WorkspaceAuditEventDto,
168
+ WorkspaceResolvePathResponse,
169
+ OrgAuthPolicy as OrgAuthPolicyDto,
170
+ OidcValidationResult as OidcValidationResultDto,
171
+ WorkspaceResyncSlackLogoResponse,
172
+ TestSsoInitiation as TestSsoInitiationDto,
173
+ TestSsoResult as TestSsoResultDto,
174
+ RemoveMemberResponse,
175
+ ChangeMemberRoleResponse,
176
+ UserOrgsResponse,
177
+ SetActiveOrgResponse,
178
+ LeaveOrgResponse,
179
+ ScopeCheckResponse,
180
+ ScopeCheckBatchResponse,
181
+ } from './schemas';
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Org/Workspace Response Schemas
3
+ *
4
+ * Zod response schemas for workspace core endpoints.
5
+ * Canonical location for runtime validation of workspace API responses.
6
+ *
7
+ * Covers:
8
+ * - workspace.ts (GET /api/workspace, /access, /members, /auth, /audit, etc.)
9
+ * - members.ts (DELETE/PATCH /api/workspace/members)
10
+ * - user-orgs.ts (GET /api/user/orgs, POST /api/user/active-org, /leave)
11
+ * - scope-check.ts (GET /api/scope/check, POST /api/scope/check-batch)
12
+ */
13
+ import { z } from 'zod';
14
+ import { CursorPageSchema } from '../api/primitives';
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Sub-schemas
18
+ // ---------------------------------------------------------------------------
19
+
20
+ const WorkspaceMemberSchema = z.object({
21
+ id: z.string(),
22
+ name: z.string(),
23
+ email: z.string(),
24
+ role: z.enum(['owner', 'admin', 'member', 'auditor']),
25
+ joinedAt: z.string(),
26
+ });
27
+
28
+ const WorkspaceOwnerSchema = z.object({
29
+ id: z.string(),
30
+ name: z.string(),
31
+ email: z.string(),
32
+ });
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // GET /api/workspace/access
36
+ // ---------------------------------------------------------------------------
37
+
38
+ export const WorkspaceAccessResponseSchema = z.object({
39
+ hasAccess: z.boolean(),
40
+ });
41
+
42
+ export type WorkspaceAccessResponse = z.infer<typeof WorkspaceAccessResponseSchema>;
43
+
44
+ // ---------------------------------------------------------------------------
45
+ // GET /api/workspace
46
+ // PATCH /api/workspace/name (returns WorkspaceOverview)
47
+ // ---------------------------------------------------------------------------
48
+
49
+ export const WorkspaceOverviewSchema = z.object({
50
+ id: z.string(),
51
+ name: z.string(),
52
+ type: z.enum(['personal', 'shared']),
53
+ logoUrl: z.string().nullable(),
54
+ owner: WorkspaceOwnerSchema,
55
+ createdAt: z.string(),
56
+ memberCount: z.number(),
57
+ claimable: z.boolean(),
58
+ });
59
+
60
+ export type WorkspaceOverview = z.infer<typeof WorkspaceOverviewSchema>;
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // GET /api/workspace/members
64
+ // ---------------------------------------------------------------------------
65
+
66
+ export const WorkspaceMembersResponseSchema = CursorPageSchema(WorkspaceMemberSchema);
67
+
68
+ export type WorkspaceMembersResponse = z.infer<typeof WorkspaceMembersResponseSchema>;
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // GET /api/workspace/auth
72
+ // ---------------------------------------------------------------------------
73
+
74
+ const OidcValidationResultSchema = z.object({
75
+ valid: z.boolean(),
76
+ issuer: z.string().optional(),
77
+ authorizationEndpoint: z.string().optional(),
78
+ error: z.string().optional(),
79
+ errorCode: z.enum(['UNREACHABLE', 'INVALID_DOCUMENT', 'MISSING_FIELDS', 'SSRF_BLOCKED']).optional(),
80
+ });
81
+
82
+ const SsoDiscoveryConfigSchema = z.object({
83
+ redirectUri: z.string(),
84
+ requiredScopes: z.array(z.string()),
85
+ isOidcConfigured: z.boolean(),
86
+ oidcDiscoveryUrl: z.string().nullable(),
87
+ });
88
+
89
+ const SsoCredentialStatusSchema = z.object({
90
+ hasClientId: z.boolean(),
91
+ hasClientSecret: z.boolean(),
92
+ });
93
+
94
+ const ProviderStatusSchema = z.enum([
95
+ 'NOT_CONFIGURED',
96
+ 'CONFIG_SAVED',
97
+ 'CONFIG_VALID',
98
+ 'TEST_SUCCESS',
99
+ 'ENABLED',
100
+ ]);
101
+
102
+ const SsoStepperStepSchema = z.enum(['configure', 'test', 'enable', 'enforce']);
103
+
104
+ const SsoOperationalStateSchema = z.object({
105
+ providerStatus: ProviderStatusSchema,
106
+ currentStep: SsoStepperStepSchema,
107
+ stepCompleted: z.boolean(),
108
+ activeProvider: z.string().nullable(),
109
+ oidcValidation: OidcValidationResultSchema.optional(),
110
+ credentialsSavedAt: z.string().optional(),
111
+ lastTestSuccessAt: z.string().optional(),
112
+ lastTestSuccessProvider: z.string().optional(),
113
+ });
114
+
115
+ const SsoSetupInfoSchema = SsoDiscoveryConfigSchema.merge(SsoCredentialStatusSchema).merge(
116
+ SsoOperationalStateSchema
117
+ );
118
+
119
+ const SsoReadinessCheckSchema = z.object({
120
+ code: z.string(),
121
+ label: z.string(),
122
+ passed: z.boolean(),
123
+ message: z.string(),
124
+ });
125
+
126
+ const SsoReadinessSchema = z.object({
127
+ ready: z.boolean(),
128
+ checks: z.array(SsoReadinessCheckSchema),
129
+ });
130
+
131
+ const SsoEnforcementStatusSchema = z.object({
132
+ enforced: z.boolean(),
133
+ enforcedDomains: z.array(z.string()),
134
+ enforcedSince: z.string().nullable(),
135
+ });
136
+
137
+ const OwnerIdentityInfoSchema = z.object({
138
+ userId: z.string(),
139
+ name: z.string(),
140
+ email: z.string(),
141
+ hasSsoIdentity: z.boolean(),
142
+ linkedProvider: z.string().nullable(),
143
+ lastSsoLoginAt: z.string().nullable(),
144
+ });
145
+
146
+ const ProviderSuggestionSchema = z.object({
147
+ suggestedProvider: z.enum(['google', 'microsoft']).nullable(),
148
+ confidence: z.enum(['high', 'low']),
149
+ reason: z.string(),
150
+ detectedDomain: z.string().optional(),
151
+ });
152
+
153
+ const AuthMethodConfigSchema = z.object({
154
+ enabled: z.boolean(),
155
+ provider: z.string().optional(),
156
+ });
157
+
158
+ export const WorkspaceAuthConfigSchema = z.object({
159
+ emailOtp: AuthMethodConfigSchema,
160
+ googleSso: AuthMethodConfigSchema,
161
+ microsoftSso: AuthMethodConfigSchema,
162
+ okta: AuthMethodConfigSchema,
163
+ policy: z.object({
164
+ requireSSO: z.boolean(),
165
+ allowedProviders: z.array(z.string()),
166
+ }),
167
+ ssoSetup: SsoSetupInfoSchema.optional(),
168
+ ssoReadiness: SsoReadinessSchema.optional(),
169
+ ssoEnforcement: SsoEnforcementStatusSchema.optional(),
170
+ workspaceSsoState: z.enum(['SSO_DISABLED', 'SSO_ENABLED', 'SSO_ENFORCED']).optional(),
171
+ ownerIdentities: z.array(OwnerIdentityInfoSchema).optional(),
172
+ providerSuggestion: ProviderSuggestionSchema.optional(),
173
+ });
174
+
175
+ export type WorkspaceAuthConfig = z.infer<typeof WorkspaceAuthConfigSchema>;
176
+
177
+ // ---------------------------------------------------------------------------
178
+ // GET /api/workspace/audit
179
+ // ---------------------------------------------------------------------------
180
+
181
+ export const WorkspaceAuditEventSchema = z.object({
182
+ id: z.string(),
183
+ timestamp: z.string(),
184
+ actor: z.object({
185
+ id: z.string(),
186
+ name: z.string(),
187
+ type: z.enum(['user', 'system']),
188
+ }),
189
+ action: z.string(),
190
+ summary: z.string(),
191
+ });
192
+
193
+ export const WorkspaceAuditResponseSchema = z.array(WorkspaceAuditEventSchema);
194
+
195
+ export type WorkspaceAuditEvent = z.infer<typeof WorkspaceAuditEventSchema>;
196
+
197
+ // ---------------------------------------------------------------------------
198
+ // POST /api/workspace/resolve-path
199
+ // ---------------------------------------------------------------------------
200
+
201
+ const ResolvedDeptEntitySchema = z.object({
202
+ id: z.string(),
203
+ name: z.string(),
204
+ slug: z.string(),
205
+ memberCount: z.number(),
206
+ });
207
+
208
+ export const WorkspaceResolvePathResponseSchema = z.object({
209
+ layers: z.array(
210
+ z.discriminatedUnion('type', [
211
+ z.object({ type: z.literal('dept'), entity: ResolvedDeptEntitySchema }),
212
+ z.object({ type: z.literal('team'), entity: ResolvedDeptEntitySchema }),
213
+ z.object({ type: z.literal('members'), scope: z.enum(['org', 'dept', 'team']) }),
214
+ ])
215
+ ),
216
+ });
217
+
218
+ export type WorkspaceResolvePathResponse = z.infer<typeof WorkspaceResolvePathResponseSchema>;
219
+
220
+ // ---------------------------------------------------------------------------
221
+ // PATCH /api/workspace/auth-policy
222
+ // ---------------------------------------------------------------------------
223
+
224
+ export const OrgAuthPolicySchema = z.object({
225
+ requireSSO: z.boolean(),
226
+ allowedProviders: z.array(z.string()),
227
+ selfRevoked: z.boolean().optional(),
228
+ });
229
+
230
+ export type OrgAuthPolicy = z.infer<typeof OrgAuthPolicySchema>;
231
+
232
+ // ---------------------------------------------------------------------------
233
+ // POST /api/workspace/auth-policy/validate-oidc
234
+ // ---------------------------------------------------------------------------
235
+
236
+ export { OidcValidationResultSchema };
237
+ export type OidcValidationResult = z.infer<typeof OidcValidationResultSchema>;
238
+
239
+ // ---------------------------------------------------------------------------
240
+ // POST /api/workspace/resync-slack-logo
241
+ // ---------------------------------------------------------------------------
242
+
243
+ export const WorkspaceResyncSlackLogoResponseSchema = z.object({
244
+ success: z.literal(true),
245
+ logoUrl: z.string().nullable(),
246
+ });
247
+
248
+ export type WorkspaceResyncSlackLogoResponse = z.infer<typeof WorkspaceResyncSlackLogoResponseSchema>;
249
+
250
+ // ---------------------------------------------------------------------------
251
+ // POST /api/workspace/auth-policy/test-sso
252
+ // ---------------------------------------------------------------------------
253
+
254
+ export const TestSsoInitiationSchema = z.object({
255
+ authorizationUrl: z.string(),
256
+ attemptId: z.string(),
257
+ });
258
+
259
+ export type TestSsoInitiation = z.infer<typeof TestSsoInitiationSchema>;
260
+
261
+ // ---------------------------------------------------------------------------
262
+ // GET /api/workspace/auth-policy/test-sso/:attemptId
263
+ // ---------------------------------------------------------------------------
264
+
265
+ export const TestSsoResultSchema = z.object({
266
+ status: z.enum(['pending', 'success', 'failed', 'expired']),
267
+ claims: z
268
+ .object({
269
+ sub: z.string(),
270
+ email: z.string().optional(),
271
+ name: z.string().optional(),
272
+ issuer: z.string(),
273
+ })
274
+ .optional(),
275
+ identityLinked: z.boolean().optional(),
276
+ error: z.string().optional(),
277
+ errorCode: z
278
+ .enum(['IDENTITY_CONFLICT', 'DOMAIN_MISMATCH', 'ISSUER_MISMATCH', 'CALLBACK_ERROR'])
279
+ .optional(),
280
+ });
281
+
282
+ export type TestSsoResult = z.infer<typeof TestSsoResultSchema>;
283
+
284
+ // ---------------------------------------------------------------------------
285
+ // DELETE /api/workspace/members/:id
286
+ // ---------------------------------------------------------------------------
287
+
288
+ export const RemoveMemberResponseSchema = z.object({
289
+ success: z.boolean(),
290
+ memberId: z.string(),
291
+ memberEmail: z.string(),
292
+ message: z.string(),
293
+ });
294
+
295
+ export type RemoveMemberResponse = z.infer<typeof RemoveMemberResponseSchema>;
296
+
297
+ // ---------------------------------------------------------------------------
298
+ // PATCH /api/workspace/members/:id/role
299
+ // ---------------------------------------------------------------------------
300
+
301
+ export const ChangeMemberRoleResponseSchema = z.object({
302
+ success: z.boolean(),
303
+ memberId: z.string(),
304
+ memberEmail: z.string(),
305
+ previousRole: z.string(),
306
+ newRole: z.string(),
307
+ message: z.string(),
308
+ });
309
+
310
+ export type ChangeMemberRoleResponse = z.infer<typeof ChangeMemberRoleResponseSchema>;
311
+
312
+ // ---------------------------------------------------------------------------
313
+ // GET /api/user/orgs
314
+ // ---------------------------------------------------------------------------
315
+
316
+ const UserOrgMembershipSchema = z.object({
317
+ userId: z.string(),
318
+ orgId: z.string(),
319
+ orgName: z.string(),
320
+ orgSlug: z.string(),
321
+ role: z.enum(['owner', 'admin', 'member', 'auditor']),
322
+ joinedAt: z.string(),
323
+ isActive: z.boolean(),
324
+ orgType: z.enum(['personal', 'shared']),
325
+ });
326
+
327
+ export const UserOrgsResponseSchema = z.object({
328
+ orgs: z.array(UserOrgMembershipSchema),
329
+ });
330
+
331
+ export type UserOrgsResponse = z.infer<typeof UserOrgsResponseSchema>;
332
+
333
+ // ---------------------------------------------------------------------------
334
+ // POST /api/user/active-org
335
+ // ---------------------------------------------------------------------------
336
+
337
+ export const SetActiveOrgResponseSchema = z.object({
338
+ success: z.literal(true),
339
+ activeOrgId: z.string(),
340
+ });
341
+
342
+ export type SetActiveOrgResponse = z.infer<typeof SetActiveOrgResponseSchema>;
343
+
344
+ // ---------------------------------------------------------------------------
345
+ // POST /api/user/orgs/:orgId/leave
346
+ // ---------------------------------------------------------------------------
347
+
348
+ export const LeaveOrgResponseSchema = z.object({
349
+ success: z.literal(true),
350
+ nextOrgId: z.string().nullable(),
351
+ });
352
+
353
+ export type LeaveOrgResponse = z.infer<typeof LeaveOrgResponseSchema>;
354
+
355
+ // ---------------------------------------------------------------------------
356
+ // GET /api/scope/check
357
+ // ---------------------------------------------------------------------------
358
+
359
+ export const ScopeCheckResponseSchema = z.object({
360
+ hasAccess: z.boolean(),
361
+ });
362
+
363
+ export type ScopeCheckResponse = z.infer<typeof ScopeCheckResponseSchema>;
364
+
365
+ // ---------------------------------------------------------------------------
366
+ // POST /api/scope/check-batch
367
+ // ---------------------------------------------------------------------------
368
+
369
+ export const ScopeCheckBatchResponseSchema = z.object({
370
+ results: z.record(z.string(), z.object({ hasAccess: z.boolean() })),
371
+ });
372
+
373
+ export type ScopeCheckBatchResponse = z.infer<typeof ScopeCheckBatchResponseSchema>;