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