@company-semantics/contracts 1.16.0 → 1.18.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": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -112,17 +112,17 @@
112
112
  "node": "22.x"
113
113
  },
114
114
  "dependencies": {
115
- "zod": "^4.2.1"
115
+ "zod": "^4.4.1"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@types/node": "^25.6.0",
119
119
  "husky": "^9.1.7",
120
120
  "lint-staged": "^16.4.0",
121
- "markdownlint-cli2": "^0.22.0",
121
+ "markdownlint-cli2": "^0.22.1",
122
122
  "openapi-typescript": "^7.13.0",
123
123
  "tsx": "^4.21.0",
124
124
  "typescript": "^5",
125
- "vitest": "^4.1.4",
125
+ "vitest": "^4.1.5",
126
126
  "yaml": "^2.8.3"
127
127
  },
128
128
  "pnpm": {
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Admin What-If Simulator — request/response schemas.
3
+ *
4
+ * Mirrors the Fastify schema for `POST /api/admin/authz/simulate`. The endpoint
5
+ * is read-only and returns the full structured AuthDecision verbatim, so that
6
+ * admins can debug denials by reading evaluator name + reason rather than
7
+ * guessing. See PRD-00544 and feedback_decision_logic_must_be_visible.md.
8
+ */
9
+ import { z } from 'zod';
10
+
11
+ export const SimulateRequest = z.object({
12
+ actor: z.object({
13
+ type: z.enum(['user', 'agent']),
14
+ id: z.string().uuid(),
15
+ }),
16
+ scope: z.string(),
17
+ resource_kind: z.enum(['system', 'org', 'team', 'member', 'doc']),
18
+ resource_id: z.string().uuid().optional(),
19
+ });
20
+
21
+ export type SimulateRequest = z.infer<typeof SimulateRequest>;
22
+
23
+ export const SimulateResponse = z.discriminatedUnion('allow', [
24
+ z.object({
25
+ allow: z.literal(true),
26
+ matched_grant: z.unknown(),
27
+ evaluator_name: z.string().optional(),
28
+ evaluator_reason: z.string().optional(),
29
+ }),
30
+ z.object({
31
+ allow: z.literal(false),
32
+ deny_reasons: z.array(z.unknown()),
33
+ missing: z.object({
34
+ scope: z.string().optional(),
35
+ suggested_role: z.string().optional(),
36
+ }),
37
+ }),
38
+ ]);
39
+
40
+ export type SimulateResponse = z.infer<typeof SimulateResponse>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Admin Direct Grants — request/response schemas.
3
+ *
4
+ * Mirrors the Fastify schemas for `POST /api/admin/grants/direct` and the
5
+ * persisted grant row. `granted_by` is intentionally absent from the create
6
+ * body — it is set by the server from the authenticated actor (see PRD-00544
7
+ * direct-grant-audit-trail and the `direct-grant-audit` CI guard).
8
+ */
9
+ import { z } from 'zod';
10
+
11
+ export const DirectGrantCreate = z.object({
12
+ subject_id: z.string().uuid(),
13
+ scope_pattern: z.string(),
14
+ resource_filter: z.record(z.string(), z.unknown()).optional(),
15
+ expires_at: z.string().datetime().optional(),
16
+ });
17
+
18
+ export type DirectGrantCreate = z.infer<typeof DirectGrantCreate>;
19
+
20
+ export const DirectGrant = z.object({
21
+ id: z.string().uuid(),
22
+ org_id: z.string().uuid(),
23
+ subject_id: z.string().uuid(),
24
+ scope_pattern: z.string(),
25
+ source: z.literal('direct'),
26
+ granted_by: z.string().uuid(),
27
+ granted_at: z.string().datetime(),
28
+ expires_at: z.string().datetime().nullable(),
29
+ });
30
+
31
+ export type DirectGrant = z.infer<typeof DirectGrant>;
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED — do not edit. Run pnpm generate:spec-hash to regenerate.
2
- export const SPEC_HASH = 'e337542ea39d' as const;
3
- export const SPEC_HASH_FULL = 'e337542ea39de6f11b03f87d300e3e4c842825267c6918b1a37f2f86502124f8' as const;
2
+ export const SPEC_HASH = '6edfe6e7117c' as const;
3
+ export const SPEC_HASH_FULL = '6edfe6e7117c49e81cd7cad51ac9cd5c6f4c9e18cf7a37ff82a5630855404a00' as const;
@@ -72,6 +72,26 @@ export interface paths {
72
72
  patch?: never;
73
73
  trace?: never;
74
74
  };
75
+ "/api/auth/consent/grant": {
76
+ parameters: {
77
+ query?: never;
78
+ header?: never;
79
+ path?: never;
80
+ cookie?: never;
81
+ };
82
+ get?: never;
83
+ put?: never;
84
+ /**
85
+ * Grant incremental consent for a write action
86
+ * @description Records per-(user, org, action) consent for a registered write action. Idempotent: regranting an already-active consent re-emits the audit event but does not create a duplicate row.
87
+ */
88
+ post: operations["grantIncrementalConsent"];
89
+ delete?: never;
90
+ options?: never;
91
+ head?: never;
92
+ patch?: never;
93
+ trace?: never;
94
+ };
75
95
  "/api/me": {
76
96
  parameters: {
77
97
  query?: never;
@@ -2036,6 +2056,15 @@ export interface components {
2036
2056
  /** @constant */
2037
2057
  ok: true;
2038
2058
  };
2059
+ ConsentGrantResponse: {
2060
+ /** @constant */
2061
+ ok: true;
2062
+ /** Format: date-time */
2063
+ grantedAt: string;
2064
+ };
2065
+ ConsentGrantRequest: {
2066
+ actionId: string;
2067
+ };
2039
2068
  MeResponse: {
2040
2069
  /** Format: uuid */
2041
2070
  userId: string;
@@ -3552,6 +3581,63 @@ export interface operations {
3552
3581
  };
3553
3582
  };
3554
3583
  };
3584
+ grantIncrementalConsent: {
3585
+ parameters: {
3586
+ query?: never;
3587
+ header?: never;
3588
+ path?: never;
3589
+ cookie?: never;
3590
+ };
3591
+ requestBody: {
3592
+ content: {
3593
+ "application/json": components["schemas"]["ConsentGrantRequest"];
3594
+ };
3595
+ };
3596
+ responses: {
3597
+ /** @description Consent granted */
3598
+ 200: {
3599
+ headers: {
3600
+ [name: string]: unknown;
3601
+ };
3602
+ content: {
3603
+ "application/json": components["schemas"]["ConsentGrantResponse"];
3604
+ };
3605
+ };
3606
+ /** @description Invalid or unregistered actionId */
3607
+ 400: {
3608
+ headers: {
3609
+ [name: string]: unknown;
3610
+ };
3611
+ content: {
3612
+ "application/json": {
3613
+ error: string;
3614
+ message: string;
3615
+ };
3616
+ };
3617
+ };
3618
+ /** @description Not authenticated */
3619
+ 401: {
3620
+ headers: {
3621
+ [name: string]: unknown;
3622
+ };
3623
+ content?: never;
3624
+ };
3625
+ /** @description CSRF token missing or invalid */
3626
+ 403: {
3627
+ headers: {
3628
+ [name: string]: unknown;
3629
+ };
3630
+ content?: never;
3631
+ };
3632
+ /** @description Rate limit exceeded */
3633
+ 429: {
3634
+ headers: {
3635
+ [name: string]: unknown;
3636
+ };
3637
+ content?: never;
3638
+ };
3639
+ };
3640
+ };
3555
3641
  getCurrentUser: {
3556
3642
  parameters: {
3557
3643
  query?: never;
@@ -9,6 +9,7 @@ export const openApiRoutes = {
9
9
  '/api/account/deletion-eligibility': ['GET'],
10
10
  '/api/account/sessions': ['GET'],
11
11
  '/api/account/sessions/{sessionId}': ['DELETE'],
12
+ '/api/auth/consent/grant': ['POST'],
12
13
  '/api/chats': ['GET', 'POST'],
13
14
  '/api/chats/by-interaction/{interactionId}': ['GET'],
14
15
  '/api/chats/events': ['GET'],
@@ -47,7 +48,8 @@ export const openApiRoutes = {
47
48
  '/api/internal-admin/impersonate/start': ['POST'],
48
49
  '/api/me': ['GET'],
49
50
  '/api/org-units': ['POST'],
50
- '/api/org-units/{unitId}': ['GET'],
51
+ '/api/org-units/tree': ['GET'],
52
+ '/api/org-units/{unitId}': ['GET', 'PATCH'],
51
53
  '/api/org-units/{unitId}/ancestors': ['GET'],
52
54
  '/api/org-units/{unitId}/archive': ['POST'],
53
55
  '/api/org-units/{unitId}/children': ['GET'],
@@ -73,7 +75,7 @@ export const openApiRoutes = {
73
75
  '/api/orgs/{orgId}/billing': ['GET'],
74
76
  '/api/orgs/{orgId}/budget-config': ['GET', 'PUT'],
75
77
  '/api/orgs/{orgId}/level-config': ['GET', 'PUT'],
76
- '/api/orgs/{orgId}/tree': ['GET'],
78
+ '/api/rbac/roles': ['GET'],
77
79
  '/api/scope/check': ['GET'],
78
80
  '/api/scope/check-batch': ['POST'],
79
81
  '/api/shared/{token}': ['GET'],
@@ -103,7 +105,7 @@ export const openApiRoutes = {
103
105
  '/api/workspace/invites/validate': ['GET'],
104
106
  '/api/workspace/invites/{id}': ['DELETE'],
105
107
  '/api/workspace/members': ['GET'],
106
- '/api/workspace/members/{id}': ['DELETE'],
108
+ '/api/workspace/members/{id}': ['DELETE', 'GET'],
107
109
  '/api/workspace/members/{id}/role': ['PATCH'],
108
110
  '/api/workspace/name': ['PATCH'],
109
111
  '/api/workspace/resolve-path': ['POST'],
@@ -29,9 +29,14 @@ export {
29
29
  ImpersonationSessionResponseSchema,
30
30
  ImpersonationSessionNullableResponseSchema,
31
31
  EndImpersonationResponseSchema,
32
+ ImpersonationSessionWireDtoSchema,
32
33
  } from './schemas'
33
34
 
34
35
  export type {
35
36
  ImpersonationSessionResponse,
36
37
  EndImpersonationResponse,
38
+ ImpersonationSessionWireDtoParsed,
37
39
  } from './schemas'
40
+
41
+ // Wire DTO for SSE projection (PRD-00557 F5)
42
+ export type { ImpersonationSessionWireDto } from '../impersonation-events'
@@ -36,5 +36,24 @@ export const EndImpersonationResponseSchema = z.object({
36
36
  ok: z.literal(true),
37
37
  })
38
38
 
39
+ /**
40
+ * Wire-only DTO for SSE snapshot/started events (PRD-00557 F5).
41
+ *
42
+ * .strict() rejects extraneous keys so a backend regression that leaks
43
+ * reason / reasonHash / ipAddress / userAgent is caught at the contract
44
+ * boundary, not at the network. This complements the type-level
45
+ * narrowing in src/impersonation-events.ts.
46
+ */
47
+ export const ImpersonationSessionWireDtoSchema = z
48
+ .object({
49
+ id: z.string(),
50
+ targetUserId: z.string(),
51
+ startedAt: z.string().datetime({ offset: true }),
52
+ expiresAt: z.string().datetime({ offset: true }),
53
+ endedAt: z.string().datetime({ offset: true }).nullable(),
54
+ })
55
+ .strict()
56
+
39
57
  export type ImpersonationSessionResponse = z.infer<typeof ImpersonationSessionResponseSchema>
40
58
  export type EndImpersonationResponse = z.infer<typeof EndImpersonationResponseSchema>
59
+ export type ImpersonationSessionWireDtoParsed = z.infer<typeof ImpersonationSessionWireDtoSchema>
@@ -7,7 +7,19 @@
7
7
  */
8
8
 
9
9
  import type { BaseEvent } from './chat/types'
10
- import type { ImpersonationSession } from './impersonation'
10
+
11
+ /**
12
+ * Minimal projection of an impersonation session for over-the-wire delivery.
13
+ * Excludes reason, reasonHash, ipAddress, userAgent — those stay server-side
14
+ * (PRD-00557 F5: type-impossible wire exposure of admin-private fields).
15
+ */
16
+ export interface ImpersonationSessionWireDto {
17
+ readonly id: string
18
+ readonly targetUserId: string
19
+ readonly startedAt: string
20
+ readonly expiresAt: string
21
+ readonly endedAt: string | null
22
+ }
11
23
 
12
24
  /**
13
25
  * Sent as the first frame on SSE connection.
@@ -17,7 +29,7 @@ import type { ImpersonationSession } from './impersonation'
17
29
  export interface ImpersonationSessionSnapshotEvent extends BaseEvent {
18
30
  type: 'impersonation.session.snapshot'
19
31
  data: {
20
- session: ImpersonationSession | null
32
+ session: ImpersonationSessionWireDto | null
21
33
  }
22
34
  }
23
35
 
@@ -25,7 +37,7 @@ export interface ImpersonationSessionSnapshotEvent extends BaseEvent {
25
37
  export interface ImpersonationSessionStartedEvent extends BaseEvent {
26
38
  type: 'impersonation.session.started'
27
39
  data: {
28
- session: ImpersonationSession
40
+ session: ImpersonationSessionWireDto
29
41
  }
30
42
  }
31
43