terse-types 0.0.33 → 0.0.34

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,314 @@
1
+ import { ConfigType } from "./Configs.js";
2
+ import { IntegrationType } from "./Integrations.js";
3
+ function assertNever(value) {
4
+ throw new Error(`Unhandled config type: ${JSON.stringify(value)}`);
5
+ }
6
+ // Slack
7
+ function getSlackOutputConfigACLRules(config) {
8
+ const rules = [];
9
+ if (config.channelId) {
10
+ rules.push({
11
+ integrationType: IntegrationType.SLACK,
12
+ integrationId: config.integrationId,
13
+ resourceType: "channel",
14
+ resourceId: config.channelId
15
+ });
16
+ }
17
+ for (const userId of config.userIds ?? []) {
18
+ rules.push({
19
+ integrationType: IntegrationType.SLACK,
20
+ integrationId: config.integrationId,
21
+ resourceType: "dm_user",
22
+ resourceId: userId
23
+ });
24
+ }
25
+ return rules;
26
+ }
27
+ function getSlackInputConfigACLRules(config) {
28
+ const rules = [];
29
+ if (config.channelId) {
30
+ rules.push({
31
+ integrationType: IntegrationType.SLACK,
32
+ integrationId: config.integrationId,
33
+ resourceType: "channel",
34
+ resourceId: config.channelId
35
+ });
36
+ }
37
+ for (const userId of config.userIds ?? []) {
38
+ rules.push({
39
+ integrationType: IntegrationType.SLACK,
40
+ integrationId: config.integrationId,
41
+ resourceType: "dm_user",
42
+ resourceId: userId
43
+ });
44
+ }
45
+ return rules;
46
+ }
47
+ // Notion
48
+ function getNotionConfigACLRules(config) {
49
+ return [
50
+ ...(config.pageIds ?? []).map((pageId) => ({
51
+ integrationType: IntegrationType.NOTION,
52
+ integrationId: config.integrationId,
53
+ resourceType: "page",
54
+ resourceId: pageId
55
+ })),
56
+ ...(config.databaseIds ?? []).map((databaseId) => ({
57
+ integrationType: IntegrationType.NOTION,
58
+ integrationId: config.integrationId,
59
+ resourceType: "database",
60
+ resourceId: databaseId
61
+ }))
62
+ ];
63
+ }
64
+ // Gmail
65
+ function getGmailOutputConfigACLRules(config) {
66
+ return [
67
+ {
68
+ integrationType: IntegrationType.GMAIL,
69
+ integrationId: config.integrationId,
70
+ resourceType: "send",
71
+ resourceId: "send"
72
+ }
73
+ ];
74
+ }
75
+ function getGmailDraftOutputConfigACLRules(config) {
76
+ return [
77
+ {
78
+ integrationType: IntegrationType.GMAIL,
79
+ integrationId: config.integrationId,
80
+ resourceType: "draft",
81
+ resourceId: "draft"
82
+ }
83
+ ];
84
+ }
85
+ // Terse built-in capabilities
86
+ function getWebConfigACLRules(config) {
87
+ return [
88
+ {
89
+ integrationType: IntegrationType.TERSE,
90
+ integrationId: config.integrationId,
91
+ resourceType: "web_capability",
92
+ resourceId: "system"
93
+ }
94
+ ];
95
+ }
96
+ function getImageEditConfigACLRules(config) {
97
+ return [
98
+ {
99
+ integrationType: IntegrationType.TERSE,
100
+ integrationId: config.integrationId,
101
+ resourceType: "image_edit_capability",
102
+ resourceId: "system"
103
+ }
104
+ ];
105
+ }
106
+ // Linear
107
+ function getLinearInputConfigACLRules(config) {
108
+ const rules = [
109
+ {
110
+ integrationType: IntegrationType.LINEAR,
111
+ integrationId: config.integrationId,
112
+ resourceType: "integration",
113
+ resourceId: config.integrationId
114
+ }
115
+ ];
116
+ if (config.teamId) {
117
+ rules.push({
118
+ integrationType: IntegrationType.LINEAR,
119
+ integrationId: config.integrationId,
120
+ resourceType: "team",
121
+ resourceId: config.teamId
122
+ });
123
+ }
124
+ if (config.projectId) {
125
+ rules.push({
126
+ integrationType: IntegrationType.LINEAR,
127
+ integrationId: config.integrationId,
128
+ resourceType: "project",
129
+ resourceId: config.projectId
130
+ });
131
+ }
132
+ return rules;
133
+ }
134
+ function getLinearOutputConfigACLRules(config) {
135
+ const rules = [
136
+ {
137
+ integrationType: IntegrationType.LINEAR,
138
+ integrationId: config.integrationId,
139
+ resourceType: "integration",
140
+ resourceId: config.integrationId
141
+ }
142
+ ];
143
+ if (config.teamId) {
144
+ rules.push({
145
+ integrationType: IntegrationType.LINEAR,
146
+ integrationId: config.integrationId,
147
+ resourceType: "team",
148
+ resourceId: config.teamId
149
+ });
150
+ }
151
+ if (config.projectId) {
152
+ rules.push({
153
+ integrationType: IntegrationType.LINEAR,
154
+ integrationId: config.integrationId,
155
+ resourceType: "project",
156
+ resourceId: config.projectId
157
+ });
158
+ }
159
+ return rules;
160
+ }
161
+ // PostHog
162
+ function getPosthogConfigACLRules(config) {
163
+ return [
164
+ {
165
+ integrationType: IntegrationType.POSTHOG,
166
+ integrationId: config.integrationId,
167
+ resourceType: "project",
168
+ resourceId: config.projectId
169
+ }
170
+ ];
171
+ }
172
+ // Datadog
173
+ function getDatadogConfigACLRules(config) {
174
+ const rules = [
175
+ {
176
+ integrationType: IntegrationType.DATADOG,
177
+ integrationId: config.integrationId,
178
+ resourceType: "integration",
179
+ resourceId: config.integrationId
180
+ }
181
+ ];
182
+ for (const indexName of config.defaultIndexes ?? []) {
183
+ rules.push({
184
+ integrationType: IntegrationType.DATADOG,
185
+ integrationId: config.integrationId,
186
+ resourceType: "index",
187
+ resourceId: indexName
188
+ });
189
+ }
190
+ return rules;
191
+ }
192
+ // LaunchDarkly
193
+ function getLaunchDarklyConfigACLRules(config) {
194
+ const rules = [
195
+ {
196
+ integrationType: IntegrationType.LAUNCHDARKLY,
197
+ integrationId: config.integrationId,
198
+ resourceType: "project",
199
+ resourceId: config.projectKey
200
+ }
201
+ ];
202
+ for (const envKey of config.environmentKeys) {
203
+ rules.push({
204
+ integrationType: IntegrationType.LAUNCHDARKLY,
205
+ integrationId: config.integrationId,
206
+ resourceType: "environment",
207
+ resourceId: `${config.projectKey}:${envKey}`
208
+ });
209
+ }
210
+ return rules;
211
+ }
212
+ // WorkOS
213
+ function getWorkOSInputConfigACLRules(config) {
214
+ return [
215
+ {
216
+ integrationType: IntegrationType.WORKOS,
217
+ integrationId: config.integrationId,
218
+ resourceType: "integration",
219
+ resourceId: config.integrationId
220
+ }
221
+ ];
222
+ }
223
+ function getWorkOSOutputConfigACLRules(config) {
224
+ return [
225
+ {
226
+ integrationType: IntegrationType.WORKOS,
227
+ integrationId: config.integrationId,
228
+ resourceType: "integration",
229
+ resourceId: config.integrationId
230
+ }
231
+ ];
232
+ }
233
+ // Attio
234
+ function getAttioOutputConfigACLRules(config) {
235
+ const rules = [
236
+ {
237
+ integrationType: IntegrationType.ATTIO,
238
+ integrationId: config.integrationId,
239
+ resourceType: "integration",
240
+ resourceId: config.integrationId
241
+ }
242
+ ];
243
+ if (config.objectSlug) {
244
+ rules.push({
245
+ integrationType: IntegrationType.ATTIO,
246
+ integrationId: config.integrationId,
247
+ resourceType: "object",
248
+ resourceId: config.objectSlug
249
+ });
250
+ }
251
+ return rules;
252
+ }
253
+ // Snowflake
254
+ function getSnowflakeOutputConfigACLRules(config) {
255
+ return [
256
+ {
257
+ integrationType: IntegrationType.SNOWFLAKE,
258
+ integrationId: config.integrationId,
259
+ resourceType: "integration",
260
+ resourceId: config.integrationId
261
+ }
262
+ ];
263
+ }
264
+ export function getConfigACLRules(config) {
265
+ switch (config.configType) {
266
+ // Input/trigger-only configs do not grant model-selected output tool ACL.
267
+ case ConfigType.GMAIL:
268
+ case ConfigType.TIME_TRIGGER:
269
+ case ConfigType.WEBHOOK_INPUT:
270
+ case ConfigType.WEBMONITOR:
271
+ case ConfigType.HEY_REACH_INPUT:
272
+ return [];
273
+ case ConfigType.SLACK:
274
+ return getSlackInputConfigACLRules(config);
275
+ case ConfigType.SLACK_OUTPUT:
276
+ return getSlackOutputConfigACLRules(config);
277
+ case ConfigType.NOTION:
278
+ return getNotionConfigACLRules(config);
279
+ case ConfigType.LINEAR_INPUT:
280
+ return getLinearInputConfigACLRules(config);
281
+ case ConfigType.LINEAR_OUTPUT:
282
+ return getLinearOutputConfigACLRules(config);
283
+ case ConfigType.GITHUB:
284
+ // GitHub repository IDs require backend hydration to owner/repo names.
285
+ return [];
286
+ case ConfigType.GMAIL_OUTPUT:
287
+ return getGmailOutputConfigACLRules(config);
288
+ case ConfigType.GMAIL_DRAFT_OUTPUT:
289
+ return getGmailDraftOutputConfigACLRules(config);
290
+ case ConfigType.POSTHOG:
291
+ return getPosthogConfigACLRules(config);
292
+ case ConfigType.DATADOG:
293
+ return getDatadogConfigACLRules(config);
294
+ case ConfigType.LAUNCHDARKLY:
295
+ return getLaunchDarklyConfigACLRules(config);
296
+ case ConfigType.WEB:
297
+ return getWebConfigACLRules(config);
298
+ case ConfigType.IMAGE_EDIT:
299
+ return getImageEditConfigACLRules(config);
300
+ case ConfigType.WORKOS_INPUT:
301
+ return getWorkOSInputConfigACLRules(config);
302
+ case ConfigType.WORKOS_OUTPUT:
303
+ return getWorkOSOutputConfigACLRules(config);
304
+ case ConfigType.ATTIO_OUTPUT:
305
+ return getAttioOutputConfigACLRules(config);
306
+ case ConfigType.SNOWFLAKE_OUTPUT:
307
+ return getSnowflakeOutputConfigACLRules(config);
308
+ default:
309
+ return assertNever(config);
310
+ }
311
+ }
312
+ export function getMergedACLRules(configs) {
313
+ return configs.flatMap(getConfigACLRules);
314
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terse-types",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "type": "module",
5
5
  "description": "Shared Terse TypeScript types, enums, constants, and helpers.",
6
6
  "main": "./dist/index.js",