@company-semantics/contracts 0.102.0 → 0.103.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.102.0",
3
+ "version": "0.103.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,9 +12,15 @@ export type ResourceKey =
12
12
  | { type: 'integrations'; orgId: string }
13
13
  | { type: 'invites'; orgId: string }
14
14
  | { type: 'auditEvents'; orgId: string }
15
+ | { type: 'timeline'; orgId: string }
15
16
  // Identities (singular) — single entities
16
17
  | { type: 'member'; orgId: string; memberId: string }
18
+ | { type: 'team'; orgId: string; teamId: string }
19
+ | { type: 'department'; orgId: string; departmentId: string }
20
+ | { type: 'chat'; orgId: string; chatId: string }
21
+ | { type: 'goalDoc'; orgId: string; slug: string }
17
22
  | { type: 'workspace'; orgId: string }
23
+ | { type: 'workspaceDomains'; orgId: string }
18
24
  | { type: 'authSettings'; orgId: string }
19
25
  | { type: 'billing'; orgId: string }
20
26
  | { type: 'aiUsage'; orgId: string }
@@ -24,7 +30,8 @@ export type ResourceKey =
24
30
  // User-scoped
25
31
  | { type: 'dismissedBanners'; userId: string }
26
32
  | { type: 'userOrgs'; userId: string }
27
- | { type: 'sessions'; userId: string };
33
+ | { type: 'sessions'; userId: string }
34
+ | { type: 'viewer'; userId: string };
28
35
 
29
36
  /**
30
37
  * Action — structured mutation key used across execution system, audit, permissions.
@@ -44,11 +51,11 @@ export function resolveScope(context: {
44
51
  /** All ResourceKey type literals for exhaustive checking. */
45
52
  const ORG_SCOPED_TYPES = [
46
53
  'members', 'departments', 'chats', 'teams', 'integrations', 'invites',
47
- 'auditEvents', 'workspace', 'authSettings', 'billing', 'aiUsage',
48
- 'deletionEligibility', 'transferOwnership', 'goals',
54
+ 'auditEvents', 'timeline', 'workspace', 'workspaceDomains', 'authSettings',
55
+ 'billing', 'aiUsage', 'deletionEligibility', 'transferOwnership', 'goals',
49
56
  ] as const;
50
57
 
51
- const USER_SCOPED_TYPES = ['dismissedBanners', 'userOrgs', 'sessions'] as const;
58
+ const USER_SCOPED_TYPES = ['dismissedBanners', 'userOrgs', 'sessions', 'viewer'] as const;
52
59
 
53
60
  /**
54
61
  * Canonical ResourceKey → query key conversion.
@@ -61,14 +68,23 @@ const USER_SCOPED_TYPES = ['dismissedBanners', 'userOrgs', 'sessions'] as const;
61
68
  */
62
69
  export function toQueryKey(key: ResourceKey): readonly string[] {
63
70
  switch (key.type) {
64
- // Identity with extra field
71
+ // Identities with extra field
65
72
  case 'member':
66
73
  return [key.type, key.orgId, key.memberId] as const;
74
+ case 'team':
75
+ return [key.type, key.orgId, key.teamId] as const;
76
+ case 'department':
77
+ return [key.type, key.orgId, key.departmentId] as const;
78
+ case 'chat':
79
+ return [key.type, key.orgId, key.chatId] as const;
80
+ case 'goalDoc':
81
+ return [key.type, key.orgId, key.slug] as const;
67
82
 
68
83
  // User-scoped
69
84
  case 'dismissedBanners':
70
85
  case 'userOrgs':
71
86
  case 'sessions':
87
+ case 'viewer':
72
88
  return [key.type, key.userId] as const;
73
89
 
74
90
  // Org-scoped collections and identities
@@ -79,7 +95,9 @@ export function toQueryKey(key: ResourceKey): readonly string[] {
79
95
  case 'integrations':
80
96
  case 'invites':
81
97
  case 'auditEvents':
98
+ case 'timeline':
82
99
  case 'workspace':
100
+ case 'workspaceDomains':
83
101
  case 'authSettings':
84
102
  case 'billing':
85
103
  case 'aiUsage':
@@ -106,12 +124,20 @@ export function fromQueryKey(queryKey: readonly string[]): ResourceKey {
106
124
  throw new Error(`Invalid query key: expected at least [type, scope], got ${JSON.stringify(queryKey)}`);
107
125
  }
108
126
 
109
- // Identity with extra field
110
- if (type === 'member') {
127
+ // Identities with extra field
128
+ const identityFields: Record<string, string> = {
129
+ member: 'memberId',
130
+ team: 'teamId',
131
+ department: 'departmentId',
132
+ chat: 'chatId',
133
+ goalDoc: 'slug',
134
+ };
135
+
136
+ if (type in identityFields) {
111
137
  if (rest.length !== 2) {
112
- throw new Error(`Invalid query key for 'member': expected [type, orgId, memberId], got ${JSON.stringify(queryKey)}`);
138
+ throw new Error(`Invalid query key for '${type}': expected [type, orgId, ${identityFields[type]}], got ${JSON.stringify(queryKey)}`);
113
139
  }
114
- return { type: 'member', orgId: rest[0], memberId: rest[1] };
140
+ return { type, orgId: rest[0], [identityFields[type]]: rest[1] } as ResourceKey;
115
141
  }
116
142
 
117
143
  // User-scoped types
@@ -141,6 +167,8 @@ export const resourceRelationships: Record<string, string[]> = {
141
167
  chat: ['chats'],
142
168
  teams: ['team'],
143
169
  team: ['teams'],
170
+ goals: ['goalDoc'],
171
+ goalDoc: ['goals'],
144
172
  };
145
173
 
146
174
  /**
@@ -165,6 +193,10 @@ export function matchesResourceKey(queryKey: readonly unknown[], targetKey: Reso
165
193
  if ('orgId' in parsed && 'orgId' in targetKey && parsed.orgId !== targetKey.orgId) return false;
166
194
  if ('userId' in parsed && 'userId' in targetKey && parsed.userId !== targetKey.userId) return false;
167
195
  if ('memberId' in parsed && 'memberId' in targetKey && parsed.memberId !== targetKey.memberId) return false;
196
+ if ('teamId' in parsed && 'teamId' in targetKey && parsed.teamId !== targetKey.teamId) return false;
197
+ if ('departmentId' in parsed && 'departmentId' in targetKey && parsed.departmentId !== targetKey.departmentId) return false;
198
+ if ('chatId' in parsed && 'chatId' in targetKey && parsed.chatId !== targetKey.chatId) return false;
199
+ if ('slug' in parsed && 'slug' in targetKey && parsed.slug !== targetKey.slug) return false;
168
200
 
169
201
  return true;
170
202
  }