@inkeep/agents-core 0.0.0-dev-20260211191741 → 0.0.0-dev-20260211220939
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/dist/auth/auth-schema.d.ts +83 -83
- package/dist/auth/auth-validation-schemas.d.ts +131 -131
- package/dist/auth/auth.d.ts +54 -54
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/client-exports.d.ts +5 -5
- package/dist/client-exports.js +2 -2
- package/dist/data-access/index.d.ts +2 -1
- package/dist/data-access/index.js +2 -1
- package/dist/data-access/manage/agents.d.ts +47 -47
- package/dist/data-access/manage/artifactComponents.d.ts +55 -19
- package/dist/data-access/manage/contextConfigs.d.ts +20 -20
- package/dist/data-access/manage/dataComponents.d.ts +8 -8
- package/dist/data-access/manage/functionTools.d.ts +19 -19
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +21 -21
- package/dist/data-access/manage/tools.d.ts +25 -25
- package/dist/data-access/runtime/apiKeys.d.ts +20 -20
- package/dist/data-access/runtime/conversations.d.ts +16 -16
- package/dist/data-access/runtime/messages.d.ts +6 -6
- package/dist/data-access/runtime/tasks.d.ts +4 -4
- package/dist/data-access/runtime/workAppSlack.d.ts +55 -0
- package/dist/data-access/runtime/workAppSlack.js +146 -0
- package/dist/db/manage/manage-schema.d.ts +416 -387
- package/dist/db/manage/manage-schema.js +7 -10
- package/dist/db/runtime/runtime-schema.d.ts +940 -206
- package/dist/db/runtime/runtime-schema.js +77 -2
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7 -3
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.js +4 -1
- package/dist/utils/slack-link-token.d.ts +57 -0
- package/dist/utils/slack-link-token.js +112 -0
- package/dist/utils/slack-user-token.d.ts +65 -0
- package/dist/utils/slack-user-token.js +129 -0
- package/dist/utils/sse-parser.d.ts +35 -0
- package/dist/utils/sse-parser.js +71 -0
- package/dist/utils/trigger-auth.d.ts +1 -1
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +2 -2
- package/dist/validation/json-schemas.d.ts +28 -0
- package/dist/validation/json-schemas.js +56 -0
- package/dist/validation/schemas.d.ts +4850 -2544
- package/dist/validation/schemas.js +26 -9
- package/drizzle/manage/0007_nice_lilandra.sql +3 -0
- package/drizzle/manage/meta/0007_snapshot.json +3148 -0
- package/drizzle/manage/meta/_journal.json +7 -0
- package/drizzle/runtime/0012_add-slack-work-app-tables.sql +114 -0
- package/drizzle/runtime/meta/0012_snapshot.json +3600 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +1 -1
|
@@ -16,12 +16,12 @@ declare const listConversations: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
16
16
|
}>;
|
|
17
17
|
declare const createConversation: (db: AgentsRunDatabaseClient) => (params: ConversationInsert) => Promise<{
|
|
18
18
|
id: string;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
updatedAt: string;
|
|
21
|
-
agentId: string | null;
|
|
22
|
-
projectId: string;
|
|
23
19
|
tenantId: string;
|
|
20
|
+
projectId: string;
|
|
21
|
+
agentId: string | null;
|
|
24
22
|
title: string | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
25
|
metadata: ConversationMetadata | null;
|
|
26
26
|
ref: {
|
|
27
27
|
type: "tag" | "commit" | "branch";
|
|
@@ -85,12 +85,12 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
85
85
|
conversationId: string;
|
|
86
86
|
}) => Promise<{
|
|
87
87
|
id: string;
|
|
88
|
-
createdAt: string;
|
|
89
|
-
updatedAt: string;
|
|
90
|
-
agentId: string | null;
|
|
91
|
-
projectId: string;
|
|
92
88
|
tenantId: string;
|
|
89
|
+
projectId: string;
|
|
90
|
+
agentId: string | null;
|
|
93
91
|
title: string | null;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
updatedAt: string;
|
|
94
94
|
metadata: ConversationMetadata | null;
|
|
95
95
|
ref: {
|
|
96
96
|
type: "tag" | "commit" | "branch";
|
|
@@ -121,12 +121,12 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
121
121
|
contextConfigId?: string | undefined;
|
|
122
122
|
} | {
|
|
123
123
|
id: string;
|
|
124
|
-
createdAt: string;
|
|
125
|
-
updatedAt: string;
|
|
126
|
-
agentId: string | null;
|
|
127
|
-
projectId: string;
|
|
128
124
|
tenantId: string;
|
|
125
|
+
projectId: string;
|
|
126
|
+
agentId: string | null;
|
|
129
127
|
title: string | null;
|
|
128
|
+
createdAt: string;
|
|
129
|
+
updatedAt: string;
|
|
130
130
|
metadata: ConversationMetadata | null;
|
|
131
131
|
ref: {
|
|
132
132
|
type: "tag" | "commit" | "branch";
|
|
@@ -153,12 +153,12 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
153
153
|
conversationId: string;
|
|
154
154
|
}) => Promise<{
|
|
155
155
|
id: string;
|
|
156
|
-
createdAt: string;
|
|
157
|
-
updatedAt: string;
|
|
158
|
-
agentId: string | null;
|
|
159
|
-
projectId: string;
|
|
160
156
|
tenantId: string;
|
|
157
|
+
projectId: string;
|
|
158
|
+
agentId: string | null;
|
|
161
159
|
title: string | null;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt: string;
|
|
162
162
|
metadata: ConversationMetadata | null;
|
|
163
163
|
ref: {
|
|
164
164
|
type: "tag" | "commit" | "branch";
|
|
@@ -10,10 +10,10 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
10
10
|
messageId: string;
|
|
11
11
|
}) => Promise<{
|
|
12
12
|
id: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
projectId: string;
|
|
13
15
|
createdAt: string;
|
|
14
16
|
updatedAt: string;
|
|
15
|
-
projectId: string;
|
|
16
|
-
tenantId: string;
|
|
17
17
|
metadata: MessageMetadata | null;
|
|
18
18
|
content: MessageContent;
|
|
19
19
|
role: string;
|
|
@@ -141,10 +141,10 @@ declare const getVisibleMessages: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
141
141
|
}[]>;
|
|
142
142
|
declare const createMessage: (db: AgentsRunDatabaseClient) => (params: MessageInsert) => Promise<{
|
|
143
143
|
id: string;
|
|
144
|
+
tenantId: string;
|
|
145
|
+
projectId: string;
|
|
144
146
|
createdAt: string;
|
|
145
147
|
updatedAt: string;
|
|
146
|
-
projectId: string;
|
|
147
|
-
tenantId: string;
|
|
148
148
|
metadata: MessageMetadata | null;
|
|
149
149
|
content: MessageContent;
|
|
150
150
|
role: string;
|
|
@@ -194,10 +194,10 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
194
194
|
messageId: string;
|
|
195
195
|
}) => Promise<{
|
|
196
196
|
id: string;
|
|
197
|
+
tenantId: string;
|
|
198
|
+
projectId: string;
|
|
197
199
|
createdAt: string;
|
|
198
200
|
updatedAt: string;
|
|
199
|
-
projectId: string;
|
|
200
|
-
tenantId: string;
|
|
201
201
|
metadata: MessageMetadata | null;
|
|
202
202
|
content: MessageContent;
|
|
203
203
|
role: string;
|
|
@@ -7,11 +7,11 @@ import { TaskInsert, TaskSelect } from "../../types/entities.js";
|
|
|
7
7
|
//#region src/data-access/runtime/tasks.d.ts
|
|
8
8
|
declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert) => Promise<{
|
|
9
9
|
id: string;
|
|
10
|
+
tenantId: string;
|
|
11
|
+
projectId: string;
|
|
12
|
+
agentId: string;
|
|
10
13
|
createdAt: string;
|
|
11
14
|
updatedAt: string;
|
|
12
|
-
agentId: string;
|
|
13
|
-
projectId: string;
|
|
14
|
-
tenantId: string;
|
|
15
15
|
metadata: TaskMetadataConfig | null;
|
|
16
16
|
ref: {
|
|
17
17
|
type: "tag" | "commit" | "branch";
|
|
@@ -19,8 +19,8 @@ declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert)
|
|
|
19
19
|
hash: string;
|
|
20
20
|
} | null;
|
|
21
21
|
status: string;
|
|
22
|
-
contextId: string;
|
|
23
22
|
subAgentId: string;
|
|
23
|
+
contextId: string;
|
|
24
24
|
}>;
|
|
25
25
|
declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
|
|
26
26
|
id: string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { workAppSlackChannelAgentConfigs, workAppSlackUserMappings, workAppSlackWorkspaces } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
3
|
+
|
|
4
|
+
//#region src/data-access/runtime/workAppSlack.d.ts
|
|
5
|
+
type WorkAppSlackWorkspaceInsert = typeof workAppSlackWorkspaces.$inferInsert;
|
|
6
|
+
type WorkAppSlackWorkspaceSelect = typeof workAppSlackWorkspaces.$inferSelect;
|
|
7
|
+
type WorkAppSlackUserMappingInsert = typeof workAppSlackUserMappings.$inferInsert;
|
|
8
|
+
type WorkAppSlackUserMappingSelect = typeof workAppSlackUserMappings.$inferSelect;
|
|
9
|
+
type WorkAppSlackChannelAgentConfigInsert = typeof workAppSlackChannelAgentConfigs.$inferInsert;
|
|
10
|
+
type WorkAppSlackChannelAgentConfigSelect = typeof workAppSlackChannelAgentConfigs.$inferSelect;
|
|
11
|
+
declare const createWorkAppSlackWorkspace: (db: AgentsRunDatabaseClient) => (data: Omit<WorkAppSlackWorkspaceInsert, "id" | "createdAt" | "updatedAt">) => Promise<WorkAppSlackWorkspaceSelect>;
|
|
12
|
+
declare const findWorkAppSlackWorkspaceByTeamId: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string) => Promise<WorkAppSlackWorkspaceSelect | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Find a workspace by Slack team ID only (without tenant filter).
|
|
15
|
+
* Slack team IDs are globally unique, so this is safe for resolving
|
|
16
|
+
* the tenant from an incoming Slack event where tenant is unknown.
|
|
17
|
+
*/
|
|
18
|
+
declare const findWorkAppSlackWorkspaceBySlackTeamId: (db: AgentsRunDatabaseClient) => (slackTeamId: string) => Promise<WorkAppSlackWorkspaceSelect | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Find a workspace by its Nango connection ID.
|
|
21
|
+
*
|
|
22
|
+
* One Nango connection = one OAuth token = one Slack workspace.
|
|
23
|
+
* The nangoConnectionId should be globally unique (not per-tenant).
|
|
24
|
+
* The schema has a unique constraint on nangoConnectionId ensuring this.
|
|
25
|
+
*/
|
|
26
|
+
declare const findWorkAppSlackWorkspaceByNangoConnectionId: (db: AgentsRunDatabaseClient) => (nangoConnectionId: string) => Promise<WorkAppSlackWorkspaceSelect | null>;
|
|
27
|
+
declare const listWorkAppSlackWorkspacesByTenant: (db: AgentsRunDatabaseClient) => (tenantId: string) => Promise<WorkAppSlackWorkspaceSelect[]>;
|
|
28
|
+
declare const updateWorkAppSlackWorkspace: (db: AgentsRunDatabaseClient) => (id: string, data: Partial<Pick<WorkAppSlackWorkspaceInsert, "status" | "slackTeamName">>) => Promise<WorkAppSlackWorkspaceSelect | null>;
|
|
29
|
+
declare const deleteWorkAppSlackWorkspace: (db: AgentsRunDatabaseClient) => (id: string) => Promise<boolean>;
|
|
30
|
+
declare const deleteWorkAppSlackWorkspaceByNangoConnectionId: (db: AgentsRunDatabaseClient) => (nangoConnectionId: string) => Promise<boolean>;
|
|
31
|
+
declare const findWorkAppSlackUserMapping: (db: AgentsRunDatabaseClient) => (tenantId: string, slackUserId: string, slackTeamId: string, clientId?: string) => Promise<WorkAppSlackUserMappingSelect | null>;
|
|
32
|
+
declare const findWorkAppSlackUserMappingByInkeepUserId: (db: AgentsRunDatabaseClient) => (inkeepUserId: string) => Promise<WorkAppSlackUserMappingSelect[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Find a user mapping by Slack user ID and team ID only (ignores tenant).
|
|
35
|
+
* Use this when you need to find the user's tenant from their mapping.
|
|
36
|
+
*/
|
|
37
|
+
declare const findWorkAppSlackUserMappingBySlackUser: (db: AgentsRunDatabaseClient) => (slackUserId: string, slackTeamId: string, clientId?: string) => Promise<WorkAppSlackUserMappingSelect | null>;
|
|
38
|
+
declare const listWorkAppSlackUserMappingsByTeam: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string) => Promise<WorkAppSlackUserMappingSelect[]>;
|
|
39
|
+
declare const createWorkAppSlackUserMapping: (db: AgentsRunDatabaseClient) => (data: Omit<WorkAppSlackUserMappingInsert, "id" | "clientId" | "createdAt" | "updatedAt"> & {
|
|
40
|
+
clientId?: string;
|
|
41
|
+
}) => Promise<WorkAppSlackUserMappingSelect>;
|
|
42
|
+
declare const deleteWorkAppSlackUserMapping: (db: AgentsRunDatabaseClient) => (tenantId: string, slackUserId: string, slackTeamId: string, clientId?: string) => Promise<boolean>;
|
|
43
|
+
declare const deleteAllWorkAppSlackUserMappingsByTeam: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string, clientId?: string) => Promise<number>;
|
|
44
|
+
declare const createWorkAppSlackChannelAgentConfig: (db: AgentsRunDatabaseClient) => (data: Omit<WorkAppSlackChannelAgentConfigInsert, "id" | "createdAt" | "updatedAt">) => Promise<WorkAppSlackChannelAgentConfigSelect>;
|
|
45
|
+
declare const findWorkAppSlackChannelAgentConfig: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string, slackChannelId: string) => Promise<WorkAppSlackChannelAgentConfigSelect | null>;
|
|
46
|
+
declare const listWorkAppSlackChannelAgentConfigsByTeam: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string) => Promise<WorkAppSlackChannelAgentConfigSelect[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Atomic upsert using onConflictDoUpdate to avoid TOCTOU race conditions.
|
|
49
|
+
* Uses the unique constraint on (tenantId, slackTeamId, slackChannelId).
|
|
50
|
+
*/
|
|
51
|
+
declare const upsertWorkAppSlackChannelAgentConfig: (db: AgentsRunDatabaseClient) => (data: Omit<WorkAppSlackChannelAgentConfigInsert, "id" | "createdAt" | "updatedAt">) => Promise<WorkAppSlackChannelAgentConfigSelect>;
|
|
52
|
+
declare const deleteWorkAppSlackChannelAgentConfig: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string, slackChannelId: string) => Promise<boolean>;
|
|
53
|
+
declare const deleteAllWorkAppSlackChannelAgentConfigsByTeam: (db: AgentsRunDatabaseClient) => (tenantId: string, slackTeamId: string) => Promise<number>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { WorkAppSlackChannelAgentConfigInsert, WorkAppSlackChannelAgentConfigSelect, WorkAppSlackUserMappingInsert, WorkAppSlackUserMappingSelect, WorkAppSlackWorkspaceInsert, WorkAppSlackWorkspaceSelect, createWorkAppSlackChannelAgentConfig, createWorkAppSlackUserMapping, createWorkAppSlackWorkspace, deleteAllWorkAppSlackChannelAgentConfigsByTeam, deleteAllWorkAppSlackUserMappingsByTeam, deleteWorkAppSlackChannelAgentConfig, deleteWorkAppSlackUserMapping, deleteWorkAppSlackWorkspace, deleteWorkAppSlackWorkspaceByNangoConnectionId, findWorkAppSlackChannelAgentConfig, findWorkAppSlackUserMapping, findWorkAppSlackUserMappingByInkeepUserId, findWorkAppSlackUserMappingBySlackUser, findWorkAppSlackWorkspaceByNangoConnectionId, findWorkAppSlackWorkspaceBySlackTeamId, findWorkAppSlackWorkspaceByTeamId, listWorkAppSlackChannelAgentConfigsByTeam, listWorkAppSlackUserMappingsByTeam, listWorkAppSlackWorkspacesByTenant, updateWorkAppSlackWorkspace, upsertWorkAppSlackChannelAgentConfig };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { workAppSlackChannelAgentConfigs, workAppSlackUserMappings, workAppSlackWorkspaces } from "../../db/runtime/runtime-schema.js";
|
|
2
|
+
import { and, eq } from "drizzle-orm";
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
4
|
+
|
|
5
|
+
//#region src/data-access/runtime/workAppSlack.ts
|
|
6
|
+
const DEFAULT_CLIENT_ID = "work-apps-slack";
|
|
7
|
+
const createWorkAppSlackWorkspace = (db) => async (data) => {
|
|
8
|
+
const id = `wsw_${nanoid(21)}`;
|
|
9
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
10
|
+
const [result] = await db.insert(workAppSlackWorkspaces).values({
|
|
11
|
+
id,
|
|
12
|
+
...data,
|
|
13
|
+
createdAt: now,
|
|
14
|
+
updatedAt: now
|
|
15
|
+
}).returning();
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const findWorkAppSlackWorkspaceByTeamId = (db) => async (tenantId, slackTeamId) => {
|
|
19
|
+
return (await db.select().from(workAppSlackWorkspaces).where(and(eq(workAppSlackWorkspaces.tenantId, tenantId), eq(workAppSlackWorkspaces.slackTeamId, slackTeamId))).limit(1))[0] || null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Find a workspace by Slack team ID only (without tenant filter).
|
|
23
|
+
* Slack team IDs are globally unique, so this is safe for resolving
|
|
24
|
+
* the tenant from an incoming Slack event where tenant is unknown.
|
|
25
|
+
*/
|
|
26
|
+
const findWorkAppSlackWorkspaceBySlackTeamId = (db) => async (slackTeamId) => {
|
|
27
|
+
return (await db.select().from(workAppSlackWorkspaces).where(eq(workAppSlackWorkspaces.slackTeamId, slackTeamId)).limit(1))[0] || null;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Find a workspace by its Nango connection ID.
|
|
31
|
+
*
|
|
32
|
+
* One Nango connection = one OAuth token = one Slack workspace.
|
|
33
|
+
* The nangoConnectionId should be globally unique (not per-tenant).
|
|
34
|
+
* The schema has a unique constraint on nangoConnectionId ensuring this.
|
|
35
|
+
*/
|
|
36
|
+
const findWorkAppSlackWorkspaceByNangoConnectionId = (db) => async (nangoConnectionId) => {
|
|
37
|
+
return (await db.select().from(workAppSlackWorkspaces).where(eq(workAppSlackWorkspaces.nangoConnectionId, nangoConnectionId)))[0] || null;
|
|
38
|
+
};
|
|
39
|
+
const listWorkAppSlackWorkspacesByTenant = (db) => async (tenantId) => {
|
|
40
|
+
return db.select().from(workAppSlackWorkspaces).where(eq(workAppSlackWorkspaces.tenantId, tenantId));
|
|
41
|
+
};
|
|
42
|
+
const updateWorkAppSlackWorkspace = (db) => async (id, data) => {
|
|
43
|
+
const [result] = await db.update(workAppSlackWorkspaces).set({
|
|
44
|
+
...data,
|
|
45
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46
|
+
}).where(eq(workAppSlackWorkspaces.id, id)).returning();
|
|
47
|
+
return result || null;
|
|
48
|
+
};
|
|
49
|
+
const deleteWorkAppSlackWorkspace = (db) => async (id) => {
|
|
50
|
+
return (await db.delete(workAppSlackWorkspaces).where(eq(workAppSlackWorkspaces.id, id)).returning()).length > 0;
|
|
51
|
+
};
|
|
52
|
+
const deleteWorkAppSlackWorkspaceByNangoConnectionId = (db) => async (nangoConnectionId) => {
|
|
53
|
+
return (await db.delete(workAppSlackWorkspaces).where(eq(workAppSlackWorkspaces.nangoConnectionId, nangoConnectionId)).returning()).length > 0;
|
|
54
|
+
};
|
|
55
|
+
const findWorkAppSlackUserMapping = (db) => async (tenantId, slackUserId, slackTeamId, clientId = DEFAULT_CLIENT_ID) => {
|
|
56
|
+
return (await db.select().from(workAppSlackUserMappings).where(and(eq(workAppSlackUserMappings.tenantId, tenantId), eq(workAppSlackUserMappings.clientId, clientId), eq(workAppSlackUserMappings.slackUserId, slackUserId), eq(workAppSlackUserMappings.slackTeamId, slackTeamId))).limit(1))[0] || null;
|
|
57
|
+
};
|
|
58
|
+
const findWorkAppSlackUserMappingByInkeepUserId = (db) => async (inkeepUserId) => {
|
|
59
|
+
return db.select().from(workAppSlackUserMappings).where(eq(workAppSlackUserMappings.inkeepUserId, inkeepUserId));
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Find a user mapping by Slack user ID and team ID only (ignores tenant).
|
|
63
|
+
* Use this when you need to find the user's tenant from their mapping.
|
|
64
|
+
*/
|
|
65
|
+
const findWorkAppSlackUserMappingBySlackUser = (db) => async (slackUserId, slackTeamId, clientId = DEFAULT_CLIENT_ID) => {
|
|
66
|
+
return (await db.select().from(workAppSlackUserMappings).where(and(eq(workAppSlackUserMappings.clientId, clientId), eq(workAppSlackUserMappings.slackUserId, slackUserId), eq(workAppSlackUserMappings.slackTeamId, slackTeamId))).limit(1))[0] || null;
|
|
67
|
+
};
|
|
68
|
+
const listWorkAppSlackUserMappingsByTeam = (db) => async (tenantId, slackTeamId) => {
|
|
69
|
+
return db.select().from(workAppSlackUserMappings).where(and(eq(workAppSlackUserMappings.tenantId, tenantId), eq(workAppSlackUserMappings.slackTeamId, slackTeamId)));
|
|
70
|
+
};
|
|
71
|
+
const createWorkAppSlackUserMapping = (db) => async (data) => {
|
|
72
|
+
const id = `wsum_${nanoid(21)}`;
|
|
73
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
74
|
+
const [result] = await db.insert(workAppSlackUserMappings).values({
|
|
75
|
+
id,
|
|
76
|
+
clientId: data.clientId || DEFAULT_CLIENT_ID,
|
|
77
|
+
...data,
|
|
78
|
+
linkedAt: now,
|
|
79
|
+
createdAt: now,
|
|
80
|
+
updatedAt: now
|
|
81
|
+
}).returning();
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
const deleteWorkAppSlackUserMapping = (db) => async (tenantId, slackUserId, slackTeamId, clientId = DEFAULT_CLIENT_ID) => {
|
|
85
|
+
return (await db.delete(workAppSlackUserMappings).where(and(eq(workAppSlackUserMappings.tenantId, tenantId), eq(workAppSlackUserMappings.clientId, clientId), eq(workAppSlackUserMappings.slackUserId, slackUserId), eq(workAppSlackUserMappings.slackTeamId, slackTeamId))).returning()).length > 0;
|
|
86
|
+
};
|
|
87
|
+
const deleteAllWorkAppSlackUserMappingsByTeam = (db) => async (tenantId, slackTeamId, clientId = DEFAULT_CLIENT_ID) => {
|
|
88
|
+
return (await db.delete(workAppSlackUserMappings).where(and(eq(workAppSlackUserMappings.tenantId, tenantId), eq(workAppSlackUserMappings.clientId, clientId), eq(workAppSlackUserMappings.slackTeamId, slackTeamId))).returning()).length;
|
|
89
|
+
};
|
|
90
|
+
const createWorkAppSlackChannelAgentConfig = (db) => async (data) => {
|
|
91
|
+
const id = `wscac_${nanoid(21)}`;
|
|
92
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
93
|
+
const [result] = await db.insert(workAppSlackChannelAgentConfigs).values({
|
|
94
|
+
id,
|
|
95
|
+
...data,
|
|
96
|
+
createdAt: now,
|
|
97
|
+
updatedAt: now
|
|
98
|
+
}).returning();
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
|
+
const findWorkAppSlackChannelAgentConfig = (db) => async (tenantId, slackTeamId, slackChannelId) => {
|
|
102
|
+
return (await db.select().from(workAppSlackChannelAgentConfigs).where(and(eq(workAppSlackChannelAgentConfigs.tenantId, tenantId), eq(workAppSlackChannelAgentConfigs.slackTeamId, slackTeamId), eq(workAppSlackChannelAgentConfigs.slackChannelId, slackChannelId))).limit(1))[0] || null;
|
|
103
|
+
};
|
|
104
|
+
const listWorkAppSlackChannelAgentConfigsByTeam = (db) => async (tenantId, slackTeamId) => {
|
|
105
|
+
return db.select().from(workAppSlackChannelAgentConfigs).where(and(eq(workAppSlackChannelAgentConfigs.tenantId, tenantId), eq(workAppSlackChannelAgentConfigs.slackTeamId, slackTeamId)));
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Atomic upsert using onConflictDoUpdate to avoid TOCTOU race conditions.
|
|
109
|
+
* Uses the unique constraint on (tenantId, slackTeamId, slackChannelId).
|
|
110
|
+
*/
|
|
111
|
+
const upsertWorkAppSlackChannelAgentConfig = (db) => async (data) => {
|
|
112
|
+
const id = `wscac_${nanoid(21)}`;
|
|
113
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
+
const [result] = await db.insert(workAppSlackChannelAgentConfigs).values({
|
|
115
|
+
id,
|
|
116
|
+
...data,
|
|
117
|
+
createdAt: now,
|
|
118
|
+
updatedAt: now
|
|
119
|
+
}).onConflictDoUpdate({
|
|
120
|
+
target: [
|
|
121
|
+
workAppSlackChannelAgentConfigs.tenantId,
|
|
122
|
+
workAppSlackChannelAgentConfigs.slackTeamId,
|
|
123
|
+
workAppSlackChannelAgentConfigs.slackChannelId
|
|
124
|
+
],
|
|
125
|
+
set: {
|
|
126
|
+
projectId: data.projectId,
|
|
127
|
+
agentId: data.agentId,
|
|
128
|
+
agentName: data.agentName,
|
|
129
|
+
slackChannelName: data.slackChannelName,
|
|
130
|
+
slackChannelType: data.slackChannelType,
|
|
131
|
+
enabled: data.enabled,
|
|
132
|
+
configuredByUserId: data.configuredByUserId,
|
|
133
|
+
updatedAt: now
|
|
134
|
+
}
|
|
135
|
+
}).returning();
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
const deleteWorkAppSlackChannelAgentConfig = (db) => async (tenantId, slackTeamId, slackChannelId) => {
|
|
139
|
+
return (await db.delete(workAppSlackChannelAgentConfigs).where(and(eq(workAppSlackChannelAgentConfigs.tenantId, tenantId), eq(workAppSlackChannelAgentConfigs.slackTeamId, slackTeamId), eq(workAppSlackChannelAgentConfigs.slackChannelId, slackChannelId))).returning()).length > 0;
|
|
140
|
+
};
|
|
141
|
+
const deleteAllWorkAppSlackChannelAgentConfigsByTeam = (db) => async (tenantId, slackTeamId) => {
|
|
142
|
+
return (await db.delete(workAppSlackChannelAgentConfigs).where(and(eq(workAppSlackChannelAgentConfigs.tenantId, tenantId), eq(workAppSlackChannelAgentConfigs.slackTeamId, slackTeamId))).returning()).length;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
export { createWorkAppSlackChannelAgentConfig, createWorkAppSlackUserMapping, createWorkAppSlackWorkspace, deleteAllWorkAppSlackChannelAgentConfigsByTeam, deleteAllWorkAppSlackUserMappingsByTeam, deleteWorkAppSlackChannelAgentConfig, deleteWorkAppSlackUserMapping, deleteWorkAppSlackWorkspace, deleteWorkAppSlackWorkspaceByNangoConnectionId, findWorkAppSlackChannelAgentConfig, findWorkAppSlackUserMapping, findWorkAppSlackUserMappingByInkeepUserId, findWorkAppSlackUserMappingBySlackUser, findWorkAppSlackWorkspaceByNangoConnectionId, findWorkAppSlackWorkspaceBySlackTeamId, findWorkAppSlackWorkspaceByTeamId, listWorkAppSlackChannelAgentConfigsByTeam, listWorkAppSlackUserMappingsByTeam, listWorkAppSlackWorkspacesByTenant, updateWorkAppSlackWorkspace, upsertWorkAppSlackChannelAgentConfig };
|