@company-semantics/contracts 0.117.0 → 0.119.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>
@@ -28,3 +28,7 @@ export type { AvatarSource, ResolvedAvatar } from './avatar';
28
28
 
29
29
  // Functions - Avatar
30
30
  export { generateInitials, resolveAvatar } from './avatar';
31
+
32
+ // Response Schemas (Zod) - canonical location per ADR-CONT-044
33
+ export { MeResponseSchema, AuthStartResponseSchema, AuthVerifyResponseSchema, SsoConfigResponseSchema, ProfileResponseSchema } from './schemas';
34
+ export type { MeResponse, AuthStartResponse, AuthVerifyResponse, SsoConfigResponse, ProfileResponse } from './schemas';
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Identity Response Schemas
3
+ *
4
+ * Zod response schemas for auth and identity endpoints.
5
+ * Canonical location for runtime validation of identity API responses.
6
+ *
7
+ * Deviation note (AuthStartResponseSchema): The PRD reference suggested
8
+ * z.object({ sent: boolean }), but the actual POST /auth/start route returns
9
+ * a discriminated union on `mode` (otp | sso | hybrid). Schema matches reality.
10
+ */
11
+ import { z } from 'zod';
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Shared sub-schemas
15
+ // ---------------------------------------------------------------------------
16
+
17
+ const ResolvedAvatarSchema = z.object({
18
+ source: z.enum(['slack', 'initials']),
19
+ url: z.string().optional(),
20
+ initials: z.string(),
21
+ });
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // GET /api/me
25
+ // ---------------------------------------------------------------------------
26
+
27
+ /**
28
+ * Full identity context returned by GET /api/me.
29
+ * Canonical location: moved from backend contract-surfaces.ts per ADR-CONT-044.
30
+ */
31
+ export const MeResponseSchema = z.object({
32
+ userId: z.string().uuid(),
33
+ email: z.string(),
34
+ fullName: z.string(),
35
+ preferredName: z.string().nullable(),
36
+ displayName: z.string(),
37
+ nameSource: z.enum(['self', 'sso']),
38
+ nameEditable: z.boolean(),
39
+ primaryDepartmentId: z.string().nullable(),
40
+ slackUserId: z.string().nullable(),
41
+ avatar: ResolvedAvatarSchema,
42
+ orgId: z.string().uuid(),
43
+ orgName: z.string().nullable(),
44
+ orgSlug: z.string(),
45
+ plan: z.string(),
46
+ hasMultipleOrgs: z.boolean(),
47
+ isInternalAdmin: z.boolean(),
48
+ });
49
+
50
+ export type MeResponse = z.infer<typeof MeResponseSchema>;
51
+
52
+ // ---------------------------------------------------------------------------
53
+ // POST /auth/start
54
+ // Discriminated union on mode: otp | sso | hybrid
55
+ // ---------------------------------------------------------------------------
56
+
57
+ export const AuthStartResponseSchema = z.discriminatedUnion('mode', [
58
+ z.object({
59
+ mode: z.literal('otp'),
60
+ devOtp: z.string().optional(),
61
+ }),
62
+ z.object({
63
+ mode: z.literal('sso'),
64
+ providers: z.array(z.string()),
65
+ redirectUrl: z.string(),
66
+ }),
67
+ z.object({
68
+ mode: z.literal('hybrid'),
69
+ providers: z.array(z.string()),
70
+ redirectUrl: z.string(),
71
+ otpAllowed: z.literal(true),
72
+ devOtp: z.string().optional(),
73
+ }),
74
+ ]);
75
+
76
+ export type AuthStartResponse = z.infer<typeof AuthStartResponseSchema>;
77
+
78
+ // ---------------------------------------------------------------------------
79
+ // POST /auth/verify
80
+ // Sets session cookie on success; body is minimal.
81
+ // ---------------------------------------------------------------------------
82
+
83
+ export const AuthVerifyResponseSchema = z.union([
84
+ z.object({
85
+ success: z.literal(true),
86
+ ok: z.literal(true),
87
+ }),
88
+ z.object({
89
+ success: z.literal(true),
90
+ ok: z.literal(true),
91
+ acceptedInvite: z.literal(true),
92
+ orgId: z.string(),
93
+ role: z.string(),
94
+ }),
95
+ ]);
96
+
97
+ export type AuthVerifyResponse = z.infer<typeof AuthVerifyResponseSchema>;
98
+
99
+ // ---------------------------------------------------------------------------
100
+ // GET /api/workspace/auth (SSO configuration)
101
+ // Matches WorkspaceAuthConfig from org/types.ts
102
+ // ---------------------------------------------------------------------------
103
+
104
+ const AuthMethodConfigSchema = z.object({
105
+ enabled: z.boolean(),
106
+ provider: z.string().optional(),
107
+ });
108
+
109
+ export const SsoConfigResponseSchema = z.object({
110
+ emailOtp: AuthMethodConfigSchema,
111
+ googleSso: AuthMethodConfigSchema,
112
+ microsoftSso: AuthMethodConfigSchema,
113
+ okta: AuthMethodConfigSchema,
114
+ policy: z.object({
115
+ requireSSO: z.boolean(),
116
+ allowedProviders: z.array(z.string()),
117
+ }),
118
+ });
119
+
120
+ export type SsoConfigResponse = z.infer<typeof SsoConfigResponseSchema>;
121
+
122
+ // ---------------------------------------------------------------------------
123
+ // PATCH /api/user/profile
124
+ // Profile shape returned after a successful profile update.
125
+ // ---------------------------------------------------------------------------
126
+
127
+ export const ProfileResponseSchema = z.object({
128
+ success: z.literal(true),
129
+ user: z.object({
130
+ id: z.string(),
131
+ fullName: z.string(),
132
+ preferredName: z.string().nullable(),
133
+ displayName: z.string(),
134
+ nameSource: z.enum(['self', 'sso']),
135
+ primaryDepartmentId: z.string().nullable(),
136
+ }),
137
+ });
138
+
139
+ export type ProfileResponse = z.infer<typeof ProfileResponseSchema>;
package/src/index.ts CHANGED
@@ -120,6 +120,21 @@ export { extractFirstWord, resolveDisplayName, deriveFullName } from './identity
120
120
  export type { AvatarSource, ResolvedAvatar } from './identity/index'
121
121
  export { generateInitials, resolveAvatar } from './identity/index'
122
122
 
123
+ // Identity response schemas (Zod) - canonical location per ADR-CONT-044
124
+ export {
125
+ MeResponseSchema,
126
+ AuthStartResponseSchema,
127
+ AuthVerifyResponseSchema,
128
+ SsoConfigResponseSchema,
129
+ ProfileResponseSchema,
130
+ } from './identity/index'
131
+ export type {
132
+ MeResponse,
133
+ AuthVerifyResponse,
134
+ SsoConfigResponse,
135
+ ProfileResponse,
136
+ } from './identity/index'
137
+
123
138
  // Auth domain types
124
139
  export type { AuthStartMode, AuthStartResponse } from './auth/index'
125
140
  export { OTPErrorCode } from './auth/index'