@company-semantics/contracts 0.121.0 → 0.123.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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Content Domain Barrel
3
+ *
4
+ * Re-exports content response schemas for company-md, teams, departments, and drive.
5
+ * Import from '@company-semantics/contracts/content'.
6
+ */
7
+
8
+ // Company.md response schemas (PRD-00448)
9
+ export {
10
+ CompanyMdListResponseSchema,
11
+ CompanyMdDocResponseSchema,
12
+ CompanyMdShareResponseSchema,
13
+ CompanyMdContextBankResponseSchema,
14
+ CompanyMdSettingsResponseSchema,
15
+ } from './schemas';
16
+ export type {
17
+ CompanyMdListResponse,
18
+ CompanyMdDocResponse,
19
+ CompanyMdShareResponse,
20
+ CompanyMdContextBankResponse,
21
+ CompanyMdSettingsResponse,
22
+ } from './schemas';
23
+
24
+ // Team response schemas (PRD-00448)
25
+ export { TeamListResponseSchema, TeamResponseSchema } from './schemas';
26
+ export type { TeamListResponse, TeamResponse } from './schemas';
27
+
28
+ // Department response schemas (PRD-00448)
29
+ export { DepartmentListResponseSchema, DepartmentResponseSchema } from './schemas';
30
+ export type { DepartmentListResponse, DepartmentResponse } from './schemas';
31
+
32
+ // Drive response schemas (PRD-00448)
33
+ export { DriveFileListResponseSchema, DriveFileContentResponseSchema } from './schemas';
34
+ export type { DriveFileListResponse, DriveFileContentResponse } from './schemas';
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Content Domain Response Schemas
3
+ *
4
+ * Zod response schemas for content and org structure endpoints.
5
+ * Canonical location for runtime validation of company-md, team,
6
+ * department, and drive API responses.
7
+ *
8
+ * Covers:
9
+ * - company-md.ts (GET /api/company-md/tree, GET /api/company-md/docs/:slug, etc.)
10
+ * - company-md-sharing.ts (GET /api/company-md/docs/:slug/sharing)
11
+ * - teams.ts (GET /api/teams, GET /api/teams/:teamId, etc.)
12
+ * - departments.ts (GET /api/departments, GET /api/departments/:id, etc.)
13
+ * - drive.ts (GET /api/drive/files, GET /api/drive/files/recent, etc.)
14
+ */
15
+ import { z } from 'zod';
16
+ import { CursorPageSchema } from '../api/primitives';
17
+
18
+ // ---------------------------------------------------------------------------
19
+ // Company.md Sub-schemas
20
+ // ---------------------------------------------------------------------------
21
+
22
+ const CompanyMdOwningTeamSchema = z.object({
23
+ id: z.string(),
24
+ name: z.string(),
25
+ });
26
+
27
+ const CompanyMdPersonSchema = z.object({
28
+ id: z.string(),
29
+ name: z.string(),
30
+ });
31
+
32
+ const CompanyMdSourceSchema = z.object({
33
+ label: z.string(),
34
+ sourceType: z.enum(['meeting', 'document', 'conversation', 'manual']),
35
+ referencedAt: z.string(),
36
+ });
37
+
38
+ const CompanyMdDependencySchema = z.object({
39
+ targetSlug: z.string(),
40
+ description: z.string(),
41
+ });
42
+
43
+ const CompanyMdTreeNodeSchema = z.object({
44
+ id: z.string(),
45
+ slug: z.string(),
46
+ title: z.string(),
47
+ level: z.enum(['root', 'department', 'team', 'context']),
48
+ parentId: z.string().nullable(),
49
+ department: z.string().nullable(),
50
+ departmentId: z.string().nullable(),
51
+ visibility: z.enum(['public', 'private']),
52
+ owningTeam: CompanyMdOwningTeamSchema.nullable(),
53
+ type: z.enum(['company', 'department', 'team', 'cross_team', 'doc', 'goal', 'source', 'map', 'context_bank']),
54
+ canEdit: z.boolean(),
55
+ memberCount: z.number().int(),
56
+ description: z.string().optional(),
57
+ departmentIds: z.array(z.string()).optional(),
58
+ });
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // Company.md HTTP Response Schemas
62
+ // ---------------------------------------------------------------------------
63
+
64
+ /** Response for GET /api/company-md/tree */
65
+ export const CompanyMdListResponseSchema = CursorPageSchema(CompanyMdTreeNodeSchema);
66
+
67
+ /** Response for GET /api/company-md/docs/:slug */
68
+ export const CompanyMdDocResponseSchema = z.object({
69
+ id: z.string(),
70
+ slug: z.string(),
71
+ title: z.string(),
72
+ level: z.enum(['root', 'department', 'team', 'context']),
73
+ department: z.string().nullable(),
74
+ departmentId: z.string().nullable(),
75
+ content: z.string(),
76
+ visibility: z.enum(['public', 'private']),
77
+ parentId: z.string().nullable(),
78
+ owningTeam: CompanyMdOwningTeamSchema.nullable(),
79
+ owner: CompanyMdPersonSchema.nullable(),
80
+ coOwners: z.array(CompanyMdPersonSchema),
81
+ canEdit: z.boolean(),
82
+ inheritsFrom: z.string().nullable(),
83
+ sources: z.array(CompanyMdSourceSchema),
84
+ dependencies: z.array(CompanyMdDependencySchema),
85
+ members: z.array(CompanyMdPersonSchema),
86
+ extractionStatus: z.enum(['pending', 'extracting', 'complete', 'failed']),
87
+ createdAt: z.string(),
88
+ updatedAt: z.string(),
89
+ });
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Company.md Sharing Sub-schemas
93
+ // ---------------------------------------------------------------------------
94
+
95
+ const AclEntrySchema = z.object({
96
+ principalType: z.enum(['user', 'team']),
97
+ principalId: z.string(),
98
+ principalName: z.string(),
99
+ accessLevel: z.enum(['viewer', 'commenter', 'editor']),
100
+ grantedBy: z.object({ id: z.string(), name: z.string() }).nullable(),
101
+ grantedAt: z.string(),
102
+ });
103
+
104
+ const AccessReasonSchema = z.object({
105
+ source: z.enum(['org_rbac', 'sharing_policy', 'team_baseline', 'acl_grant', 'doc_ownership']),
106
+ detail: z.string(),
107
+ });
108
+
109
+ const EffectiveAccessSchema = z.object({
110
+ level: z.enum(['none', 'viewer', 'commenter', 'editor']),
111
+ reasons: z.array(AccessReasonSchema),
112
+ canShare: z.boolean(),
113
+ });
114
+
115
+ /** Response for GET /api/company-md/docs/:slug/sharing */
116
+ export const CompanyMdShareResponseSchema = z.object({
117
+ sharingPolicy: z.enum(['restricted', 'org_read', 'org_comment', 'org_edit']),
118
+ acl: z.array(AclEntrySchema),
119
+ effectiveAccess: EffectiveAccessSchema,
120
+ });
121
+
122
+ // ---------------------------------------------------------------------------
123
+ // Company.md Context Bank + Settings Response Schemas
124
+ // ---------------------------------------------------------------------------
125
+
126
+ const CompanyMdContextBankItemSchema = z.object({
127
+ id: z.string(),
128
+ slug: z.string(),
129
+ title: z.string(),
130
+ visibility: z.enum(['public', 'private']),
131
+ updatedAt: z.string(),
132
+ });
133
+
134
+ /** Response for GET /api/company-md/docs/:slug/context-bank */
135
+ export const CompanyMdContextBankResponseSchema = z.object({
136
+ items: z.array(CompanyMdContextBankItemSchema),
137
+ });
138
+
139
+ const CompanyMdLevelLabelsSchema = z.object({
140
+ root: z.string(),
141
+ department: z.string(),
142
+ team: z.string(),
143
+ });
144
+
145
+ /** Response for GET /api/company-md/settings */
146
+ export const CompanyMdSettingsResponseSchema = z.object({
147
+ levelLabels: CompanyMdLevelLabelsSchema,
148
+ });
149
+
150
+ // ---------------------------------------------------------------------------
151
+ // Team Sub-schemas
152
+ // ---------------------------------------------------------------------------
153
+
154
+ const TeamMemberSchema = z.object({
155
+ userId: z.string(),
156
+ name: z.string(),
157
+ email: z.string(),
158
+ role: z.enum(['member', 'manager', 'owner']),
159
+ joinedAt: z.string(),
160
+ });
161
+
162
+ const TeamSummarySchema = z.object({
163
+ id: z.string(),
164
+ name: z.string(),
165
+ slug: z.string(),
166
+ description: z.string().nullable(),
167
+ memberCount: z.number().int(),
168
+ scope: z.enum(['department', 'cross_department', 'org']),
169
+ department: z.object({ id: z.string(), name: z.string(), slug: z.string() }).nullable(),
170
+ homeDepartment: z.object({ id: z.string(), name: z.string(), slug: z.string() }).nullable(),
171
+ });
172
+
173
+ // ---------------------------------------------------------------------------
174
+ // Team HTTP Response Schemas
175
+ // ---------------------------------------------------------------------------
176
+
177
+ /** Response for GET /api/teams */
178
+ export const TeamListResponseSchema = z.object({
179
+ teams: z.array(TeamSummarySchema),
180
+ });
181
+
182
+ /** Response for GET /api/teams/:teamId */
183
+ export const TeamResponseSchema = z.object({
184
+ id: z.string(),
185
+ name: z.string(),
186
+ slug: z.string(),
187
+ description: z.string().nullable(),
188
+ syncMode: z.enum(['manual_only', 'synced_readonly', 'synced_with_overrides']),
189
+ members: z.array(TeamMemberSchema),
190
+ });
191
+
192
+ // ---------------------------------------------------------------------------
193
+ // Department Sub-schemas
194
+ // ---------------------------------------------------------------------------
195
+
196
+ const DepartmentMemberSchema = z.object({
197
+ userId: z.string(),
198
+ name: z.string(),
199
+ email: z.string(),
200
+ role: z.enum(['member', 'manager', 'owner']),
201
+ joinedAt: z.string(),
202
+ });
203
+
204
+ const DepartmentSummarySchema = z.object({
205
+ id: z.string(),
206
+ name: z.string(),
207
+ slug: z.string(),
208
+ description: z.string().nullable(),
209
+ memberCount: z.number().int(),
210
+ position: z.number().int(),
211
+ });
212
+
213
+ // ---------------------------------------------------------------------------
214
+ // Department HTTP Response Schemas
215
+ // ---------------------------------------------------------------------------
216
+
217
+ /** Response for GET /api/departments */
218
+ export const DepartmentListResponseSchema = z.object({
219
+ departments: z.array(DepartmentSummarySchema),
220
+ });
221
+
222
+ /** Response for GET /api/departments/:id */
223
+ export const DepartmentResponseSchema = z.object({
224
+ id: z.string(),
225
+ name: z.string(),
226
+ slug: z.string(),
227
+ description: z.string().nullable(),
228
+ position: z.number().int(),
229
+ syncMode: z.enum(['manual_only', 'scim', 'hris']),
230
+ memberCount: z.number().int(),
231
+ members: z.array(DepartmentMemberSchema),
232
+ });
233
+
234
+ // ---------------------------------------------------------------------------
235
+ // Drive Sub-schemas
236
+ // ---------------------------------------------------------------------------
237
+
238
+ const DriveFileOwnerSchema = z.object({
239
+ displayName: z.string().optional(),
240
+ emailAddress: z.string().optional(),
241
+ });
242
+
243
+ const DriveFileSchema = z.object({
244
+ id: z.string(),
245
+ name: z.string(),
246
+ mimeType: z.string(),
247
+ createdTime: z.string().optional(),
248
+ modifiedTime: z.string().optional(),
249
+ owners: z.array(DriveFileOwnerSchema).optional(),
250
+ webViewLink: z.string().optional(),
251
+ iconLink: z.string().optional(),
252
+ size: z.string().optional(),
253
+ });
254
+
255
+ // ---------------------------------------------------------------------------
256
+ // Drive HTTP Response Schemas
257
+ // ---------------------------------------------------------------------------
258
+
259
+ /** Response for GET /api/drive/files and GET /api/drive/files/recent */
260
+ export const DriveFileListResponseSchema = z.object({
261
+ files: z.array(DriveFileSchema),
262
+ nextPageToken: z.string().optional(),
263
+ });
264
+
265
+ /** Response for GET /api/drive/files/:fileId/content */
266
+ export const DriveFileContentResponseSchema = z.object({
267
+ content: z.string(),
268
+ exportedAs: z.string(),
269
+ truncated: z.boolean(),
270
+ });
271
+
272
+ // ---------------------------------------------------------------------------
273
+ // Inferred Types
274
+ // ---------------------------------------------------------------------------
275
+
276
+ export type CompanyMdListResponse = z.infer<typeof CompanyMdListResponseSchema>;
277
+ export type CompanyMdDocResponse = z.infer<typeof CompanyMdDocResponseSchema>;
278
+ export type CompanyMdShareResponse = z.infer<typeof CompanyMdShareResponseSchema>;
279
+ export type CompanyMdContextBankResponse = z.infer<typeof CompanyMdContextBankResponseSchema>;
280
+ export type CompanyMdSettingsResponse = z.infer<typeof CompanyMdSettingsResponseSchema>;
281
+ export type TeamListResponse = z.infer<typeof TeamListResponseSchema>;
282
+ export type TeamResponse = z.infer<typeof TeamResponseSchema>;
283
+ export type DepartmentListResponse = z.infer<typeof DepartmentListResponseSchema>;
284
+ export type DepartmentResponse = z.infer<typeof DepartmentResponseSchema>;
285
+ export type DriveFileListResponse = z.infer<typeof DriveFileListResponseSchema>;
286
+ export type DriveFileContentResponse = z.infer<typeof DriveFileContentResponseSchema>;
@@ -145,3 +145,25 @@ export type {
145
145
  TimelineIcon,
146
146
  TimelineUIEvent,
147
147
  } from './timeline-ui'
148
+
149
+ // =============================================================================
150
+ // HTTP Response Schemas (Zod)
151
+ // =============================================================================
152
+
153
+ export {
154
+ ExecutionSummarySchema,
155
+ ExecutionListResponseSchema,
156
+ TimelineEventSchema,
157
+ ExecutionTimelineResponseSchema,
158
+ ConfirmExecutionResponseSchema,
159
+ RejectExecutionResponseSchema,
160
+ } from './schemas'
161
+
162
+ export type {
163
+ ExecutionSummaryResponse,
164
+ ExecutionListResponse,
165
+ TimelineEvent,
166
+ ExecutionTimelineResponse,
167
+ ConfirmExecutionResponse,
168
+ RejectExecutionResponse,
169
+ } from './schemas'
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Execution Response Schemas
3
+ *
4
+ * Zod schemas for execution HTTP endpoint responses.
5
+ * These schemas are used for runtime validation at API contract surfaces.
6
+ *
7
+ * @see ADR-CONT-029 for design rationale
8
+ */
9
+
10
+ import { z } from 'zod'
11
+
12
+ // =============================================================================
13
+ // Execution Summary
14
+ // =============================================================================
15
+
16
+ export const ExecutionSummarySchema = z.object({
17
+ executionId: z.string().uuid(),
18
+ kind: z.string(),
19
+ status: z.enum(['pending', 'succeeded', 'failed']),
20
+ decidedAt: z.string().datetime({ offset: true }),
21
+ completedAt: z.string().datetime({ offset: true }).optional(),
22
+ target: z.object({ type: z.string() }),
23
+ })
24
+
25
+ export type ExecutionSummaryResponse = z.infer<typeof ExecutionSummarySchema>
26
+
27
+ // =============================================================================
28
+ // Execution List Response
29
+ // =============================================================================
30
+
31
+ export const ExecutionListResponseSchema = z.object({
32
+ executions: z.array(ExecutionSummarySchema),
33
+ nextCursor: z.string().nullable().optional(),
34
+ hasMore: z.boolean().optional(),
35
+ })
36
+
37
+ export type ExecutionListResponse = z.infer<typeof ExecutionListResponseSchema>
38
+
39
+ // =============================================================================
40
+ // Timeline Event
41
+ // =============================================================================
42
+
43
+ const TimelineRelatedIdsSchema = z.object({
44
+ decisionId: z.string().optional(),
45
+ artifactId: z.string().optional(),
46
+ rollbackId: z.string().optional(),
47
+ provenanceIds: z.array(z.string()).optional(),
48
+ })
49
+
50
+ export const TimelineEventSchema = z.object({
51
+ eventId: z.string(),
52
+ executionId: z.string().uuid(),
53
+ timestamp: z.string(),
54
+ createdAt: z.string(),
55
+ kind: z.string(),
56
+ summary: z.string(),
57
+ details: z.record(z.string(), z.unknown()).optional(),
58
+ relatedIds: TimelineRelatedIdsSchema.optional(),
59
+ visibilityLevel: z.enum(['system', 'oversight', 'org_admin', 'user']),
60
+ })
61
+
62
+ export type TimelineEvent = z.infer<typeof TimelineEventSchema>
63
+
64
+ // =============================================================================
65
+ // Execution Timeline Response
66
+ // =============================================================================
67
+
68
+ export const ExecutionTimelineResponseSchema = z.object({
69
+ events: z.array(TimelineEventSchema),
70
+ })
71
+
72
+ export type ExecutionTimelineResponse = z.infer<typeof ExecutionTimelineResponseSchema>
73
+
74
+ // =============================================================================
75
+ // Execution Lifecycle Responses
76
+ // =============================================================================
77
+
78
+ export const ConfirmExecutionResponseSchema = z.object({
79
+ status: z.enum([
80
+ 'executing',
81
+ 'blocked_pending_approval',
82
+ 'already_confirmed',
83
+ 'awaiting_approval',
84
+ ]),
85
+ code: z.string().optional(),
86
+ executionId: z.string().optional(),
87
+ })
88
+
89
+ export type ConfirmExecutionResponse = z.infer<typeof ConfirmExecutionResponseSchema>
90
+
91
+ export const RejectExecutionResponseSchema = z.object({
92
+ status: z.literal('cancelled'),
93
+ })
94
+
95
+ export type RejectExecutionResponse = z.infer<typeof RejectExecutionResponseSchema>