@inkeep/agents-core 0.58.20 → 0.59.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/dist/auth/auth-config-utils.d.ts +49 -0
- package/dist/auth/auth-config-utils.js +133 -0
- package/dist/auth/auth-schema.d.ts +102 -85
- package/dist/auth/auth-schema.js +1 -0
- package/dist/auth/auth-types.d.ts +170 -0
- package/dist/auth/auth-types.js +53 -0
- package/dist/auth/auth-validation-schemas.d.ts +186 -152
- package/dist/auth/auth.d.ts +43 -1286
- package/dist/auth/auth.js +61 -70
- package/dist/auth/cookie-names.d.ts +7 -0
- package/dist/auth/cookie-names.js +13 -0
- package/dist/auth/email-send-status-store.js +15 -3
- package/dist/auth/init.js +2 -1
- package/dist/auth/password-reset-link-store.js +8 -1
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/data-access/index.d.ts +4 -3
- package/dist/data-access/index.js +3 -3
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/triggers.d.ts +2 -2
- package/dist/data-access/runtime/apiKeys.d.ts +4 -4
- package/dist/data-access/runtime/apps.d.ts +4 -4
- package/dist/data-access/runtime/auth.d.ts +9 -9
- package/dist/data-access/runtime/auth.js +19 -21
- package/dist/data-access/runtime/conversations.d.ts +4 -4
- package/dist/data-access/runtime/messages.d.ts +9 -9
- package/dist/data-access/runtime/organizations.d.ts +28 -4
- package/dist/data-access/runtime/organizations.js +131 -9
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/tasks.d.ts +2 -2
- package/dist/db/manage/manage-schema.d.ts +361 -361
- package/dist/db/runtime/runtime-schema.d.ts +302 -302
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -3
- package/dist/middleware/no-auth.d.ts +2 -2
- package/dist/utils/error.d.ts +51 -48
- package/dist/utils/error.js +3 -0
- package/dist/validation/schemas.d.ts +1641 -1641
- package/drizzle/runtime/0023_lazy_energizer.sql +1 -0
- package/drizzle/runtime/0024_moaning_kingpin.sql +1 -0
- package/drizzle/runtime/meta/0024_snapshot.json +4270 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +16 -3
|
@@ -16,10 +16,10 @@ declare const getApiKeyById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
16
16
|
createdAt: string;
|
|
17
17
|
updatedAt: string;
|
|
18
18
|
expiresAt: string | null;
|
|
19
|
-
lastUsedAt: string | null;
|
|
20
19
|
publicId: string;
|
|
21
20
|
keyHash: string;
|
|
22
21
|
keyPrefix: string;
|
|
22
|
+
lastUsedAt: string | null;
|
|
23
23
|
} | undefined>;
|
|
24
24
|
declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: string) => Promise<{
|
|
25
25
|
id: string;
|
|
@@ -30,10 +30,10 @@ declare const getApiKeyByPublicId: (db: AgentsRunDatabaseClient) => (publicId: s
|
|
|
30
30
|
createdAt: string;
|
|
31
31
|
updatedAt: string;
|
|
32
32
|
expiresAt: string | null;
|
|
33
|
-
lastUsedAt: string | null;
|
|
34
33
|
publicId: string;
|
|
35
34
|
keyHash: string;
|
|
36
35
|
keyPrefix: string;
|
|
36
|
+
lastUsedAt: string | null;
|
|
37
37
|
} | undefined>;
|
|
38
38
|
declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
39
39
|
scopes: ProjectScopeConfig;
|
|
@@ -47,10 +47,10 @@ declare const listApiKeys: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
47
47
|
createdAt: string;
|
|
48
48
|
updatedAt: string;
|
|
49
49
|
expiresAt: string | null;
|
|
50
|
-
lastUsedAt: string | null;
|
|
51
50
|
publicId: string;
|
|
52
51
|
keyHash: string;
|
|
53
52
|
keyPrefix: string;
|
|
53
|
+
lastUsedAt: string | null;
|
|
54
54
|
}[]>;
|
|
55
55
|
declare const listApiKeysPaginated: (db: AgentsRunDatabaseClient) => (params: {
|
|
56
56
|
scopes: ProjectScopeConfig;
|
|
@@ -74,10 +74,10 @@ declare const createApiKey: (db: AgentsRunDatabaseClient) => (params: ApiKeyInse
|
|
|
74
74
|
createdAt: string;
|
|
75
75
|
updatedAt: string;
|
|
76
76
|
expiresAt: string | null;
|
|
77
|
-
lastUsedAt: string | null;
|
|
78
77
|
publicId: string;
|
|
79
78
|
keyHash: string;
|
|
80
79
|
keyPrefix: string;
|
|
80
|
+
lastUsedAt: string | null;
|
|
81
81
|
}>;
|
|
82
82
|
declare const updateApiKey: (db: AgentsRunDatabaseClient) => (params: {
|
|
83
83
|
scopes: ProjectScopeConfig;
|
|
@@ -23,9 +23,9 @@ declare const getAppById: (db: AgentsRunDatabaseClient) => (id: string) => Promi
|
|
|
23
23
|
type: "api";
|
|
24
24
|
api: Record<string, never>;
|
|
25
25
|
};
|
|
26
|
-
defaultAgentId: string | null;
|
|
27
|
-
defaultProjectId: string | null;
|
|
28
26
|
lastUsedAt: string | null;
|
|
27
|
+
defaultProjectId: string | null;
|
|
28
|
+
defaultAgentId: string | null;
|
|
29
29
|
} | undefined>;
|
|
30
30
|
declare const updateAppLastUsed: (db: AgentsRunDatabaseClient) => (id: string) => Promise<void>;
|
|
31
31
|
declare const getAppByIdForTenant: (db: AgentsRunDatabaseClient) => (params: {
|
|
@@ -70,9 +70,9 @@ declare const createApp: (db: AgentsRunDatabaseClient) => (params: AppInsert) =>
|
|
|
70
70
|
type: "api";
|
|
71
71
|
api: Record<string, never>;
|
|
72
72
|
};
|
|
73
|
-
defaultAgentId: string | null;
|
|
74
|
-
defaultProjectId: string | null;
|
|
75
73
|
lastUsedAt: string | null;
|
|
74
|
+
defaultProjectId: string | null;
|
|
75
|
+
defaultAgentId: string | null;
|
|
76
76
|
}>;
|
|
77
77
|
declare const updateAppForTenant: (db: AgentsRunDatabaseClient) => (params: {
|
|
78
78
|
scopes: TenantScopeConfig;
|
|
@@ -5,14 +5,14 @@ declare const getInitialOrganization: (db: AgentsRunDatabaseClient) => (userId:
|
|
|
5
5
|
id: string;
|
|
6
6
|
} | null>;
|
|
7
7
|
declare const queryHasCredentialAccount: (db: AgentsRunDatabaseClient) => (userId: string) => Promise<boolean>;
|
|
8
|
-
|
|
9
|
-
providerId: string;
|
|
8
|
+
declare const querySsoProviderIssuers: (db: AgentsRunDatabaseClient) => () => Promise<{
|
|
10
9
|
issuer: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
declare const
|
|
10
|
+
}[]>;
|
|
11
|
+
declare const querySsoProviderIds: (db: AgentsRunDatabaseClient) => () => Promise<string[]>;
|
|
12
|
+
declare const queryOrgAllowedAuthMethods: (db: AgentsRunDatabaseClient) => (orgId: string) => Promise<{
|
|
13
|
+
allowedAuthMethods: string | null;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
declare const queryMemberExists: (db: AgentsRunDatabaseClient) => (userId: string, organizationId: string) => Promise<boolean>;
|
|
16
|
+
declare const queryPendingInvitationExists: (db: AgentsRunDatabaseClient) => (email: string, organizationId: string) => Promise<boolean>;
|
|
17
17
|
//#endregion
|
|
18
|
-
export {
|
|
18
|
+
export { getInitialOrganization, queryHasCredentialAccount, queryMemberExists, queryOrgAllowedAuthMethods, queryPendingInvitationExists, querySsoProviderIds, querySsoProviderIssuers };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { account, member, ssoProvider } from "../../auth/auth-schema.js";
|
|
2
|
-
import { generateId } from "../../utils/conversations.js";
|
|
3
|
-
import "../../utils/index.js";
|
|
1
|
+
import { account, invitation, member, organization, ssoProvider } from "../../auth/auth-schema.js";
|
|
4
2
|
import { and, eq } from "drizzle-orm";
|
|
5
3
|
|
|
6
4
|
//#region src/data-access/runtime/auth.ts
|
|
@@ -12,24 +10,24 @@ const queryHasCredentialAccount = (db) => async (userId) => {
|
|
|
12
10
|
const [row] = await db.select({ id: account.id }).from(account).where(and(eq(account.userId, userId), eq(account.providerId, "credential"))).limit(1);
|
|
13
11
|
return !!row;
|
|
14
12
|
};
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const querySsoProviderIssuers = (db) => async () => {
|
|
14
|
+
return db.select({ issuer: ssoProvider.issuer }).from(ssoProvider);
|
|
15
|
+
};
|
|
16
|
+
const querySsoProviderIds = (db) => async () => {
|
|
17
|
+
return (await db.select({ providerId: ssoProvider.providerId }).from(ssoProvider)).map((r) => r.providerId);
|
|
18
|
+
};
|
|
19
|
+
const queryOrgAllowedAuthMethods = (db) => async (orgId) => {
|
|
20
|
+
const [org] = await db.select({ allowedAuthMethods: organization.allowedAuthMethods }).from(organization).where(eq(organization.id, orgId)).limit(1);
|
|
21
|
+
return org;
|
|
22
|
+
};
|
|
23
|
+
const queryMemberExists = (db) => async (userId, organizationId) => {
|
|
24
|
+
const [row] = await db.select({ id: member.id }).from(member).where(and(eq(member.userId, userId), eq(member.organizationId, organizationId))).limit(1);
|
|
25
|
+
return !!row;
|
|
26
|
+
};
|
|
27
|
+
const queryPendingInvitationExists = (db) => async (email, organizationId) => {
|
|
28
|
+
const [row] = await db.select({ id: invitation.id }).from(invitation).where(and(eq(invitation.email, email), eq(invitation.organizationId, organizationId), eq(invitation.status, "pending"))).limit(1);
|
|
29
|
+
return !!row;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
//#endregion
|
|
35
|
-
export { getInitialOrganization, queryHasCredentialAccount,
|
|
33
|
+
export { getInitialOrganization, queryHasCredentialAccount, queryMemberExists, queryOrgAllowedAuthMethods, queryPendingInvitationExists, querySsoProviderIds, querySsoProviderIssuers };
|
|
@@ -24,12 +24,12 @@ declare const createConversation: (db: AgentsRunDatabaseClient) => (params: Conv
|
|
|
24
24
|
createdAt: string;
|
|
25
25
|
updatedAt: string;
|
|
26
26
|
metadata: ConversationMetadata | null;
|
|
27
|
+
userId: string | null;
|
|
27
28
|
ref: {
|
|
28
29
|
type: "commit" | "tag" | "branch";
|
|
29
30
|
name: string;
|
|
30
31
|
hash: string;
|
|
31
32
|
} | null;
|
|
32
|
-
userId: string | null;
|
|
33
33
|
activeSubAgentId: string;
|
|
34
34
|
lastContextResolution: string | null;
|
|
35
35
|
}>;
|
|
@@ -93,12 +93,12 @@ declare const getConversation: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
93
93
|
createdAt: string;
|
|
94
94
|
updatedAt: string;
|
|
95
95
|
metadata: ConversationMetadata | null;
|
|
96
|
+
userId: string | null;
|
|
96
97
|
ref: {
|
|
97
98
|
type: "commit" | "tag" | "branch";
|
|
98
99
|
name: string;
|
|
99
100
|
hash: string;
|
|
100
101
|
} | null;
|
|
101
|
-
userId: string | null;
|
|
102
102
|
activeSubAgentId: string;
|
|
103
103
|
lastContextResolution: string | null;
|
|
104
104
|
} | undefined>;
|
|
@@ -129,12 +129,12 @@ declare const createOrGetConversation: (db: AgentsRunDatabaseClient) => (input:
|
|
|
129
129
|
createdAt: string;
|
|
130
130
|
updatedAt: string;
|
|
131
131
|
metadata: ConversationMetadata | null;
|
|
132
|
+
userId: string | null;
|
|
132
133
|
ref: {
|
|
133
134
|
type: "commit" | "tag" | "branch";
|
|
134
135
|
name: string;
|
|
135
136
|
hash: string;
|
|
136
137
|
} | null;
|
|
137
|
-
userId: string | null;
|
|
138
138
|
activeSubAgentId: string;
|
|
139
139
|
lastContextResolution: string | null;
|
|
140
140
|
}>;
|
|
@@ -161,12 +161,12 @@ declare const getActiveAgentForConversation: (db: AgentsRunDatabaseClient) => (p
|
|
|
161
161
|
createdAt: string;
|
|
162
162
|
updatedAt: string;
|
|
163
163
|
metadata: ConversationMetadata | null;
|
|
164
|
+
userId: string | null;
|
|
164
165
|
ref: {
|
|
165
166
|
type: "commit" | "tag" | "branch";
|
|
166
167
|
name: string;
|
|
167
168
|
hash: string;
|
|
168
169
|
} | null;
|
|
169
|
-
userId: string | null;
|
|
170
170
|
activeSubAgentId: string;
|
|
171
171
|
lastContextResolution: string | null;
|
|
172
172
|
} | undefined>;
|
|
@@ -17,17 +17,17 @@ declare const getMessageById: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
17
17
|
updatedAt: string;
|
|
18
18
|
metadata: MessageMetadata | null;
|
|
19
19
|
content: MessageContent;
|
|
20
|
-
|
|
20
|
+
role: string;
|
|
21
21
|
fromSubAgentId: string | null;
|
|
22
22
|
toSubAgentId: string | null;
|
|
23
23
|
fromExternalAgentId: string | null;
|
|
24
24
|
toExternalAgentId: string | null;
|
|
25
25
|
taskId: string | null;
|
|
26
26
|
a2aTaskId: string | null;
|
|
27
|
-
|
|
28
|
-
visibility: string;
|
|
27
|
+
conversationId: string;
|
|
29
28
|
fromTeamAgentId: string | null;
|
|
30
29
|
toTeamAgentId: string | null;
|
|
30
|
+
visibility: string;
|
|
31
31
|
messageType: string;
|
|
32
32
|
parentMessageId: string | null;
|
|
33
33
|
a2aSessionId: string | null;
|
|
@@ -151,17 +151,17 @@ declare const createMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
151
151
|
updatedAt: string;
|
|
152
152
|
metadata: MessageMetadata | null;
|
|
153
153
|
content: MessageContent;
|
|
154
|
-
|
|
154
|
+
role: string;
|
|
155
155
|
fromSubAgentId: string | null;
|
|
156
156
|
toSubAgentId: string | null;
|
|
157
157
|
fromExternalAgentId: string | null;
|
|
158
158
|
toExternalAgentId: string | null;
|
|
159
159
|
taskId: string | null;
|
|
160
160
|
a2aTaskId: string | null;
|
|
161
|
-
|
|
162
|
-
visibility: string;
|
|
161
|
+
conversationId: string;
|
|
163
162
|
fromTeamAgentId: string | null;
|
|
164
163
|
toTeamAgentId: string | null;
|
|
164
|
+
visibility: string;
|
|
165
165
|
messageType: string;
|
|
166
166
|
parentMessageId: string | null;
|
|
167
167
|
a2aSessionId: string | null;
|
|
@@ -204,17 +204,17 @@ declare const deleteMessage: (db: AgentsRunDatabaseClient) => (params: {
|
|
|
204
204
|
updatedAt: string;
|
|
205
205
|
metadata: MessageMetadata | null;
|
|
206
206
|
content: MessageContent;
|
|
207
|
-
|
|
207
|
+
role: string;
|
|
208
208
|
fromSubAgentId: string | null;
|
|
209
209
|
toSubAgentId: string | null;
|
|
210
210
|
fromExternalAgentId: string | null;
|
|
211
211
|
toExternalAgentId: string | null;
|
|
212
212
|
taskId: string | null;
|
|
213
213
|
a2aTaskId: string | null;
|
|
214
|
-
|
|
215
|
-
visibility: string;
|
|
214
|
+
conversationId: string;
|
|
216
215
|
fromTeamAgentId: string | null;
|
|
217
216
|
toTeamAgentId: string | null;
|
|
217
|
+
visibility: string;
|
|
218
218
|
messageType: string;
|
|
219
219
|
parentMessageId: string | null;
|
|
220
220
|
a2aSessionId: string | null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AgentsRunDatabaseClient } from "../../db/runtime/runtime-client.js";
|
|
2
|
+
import { AllowedAuthMethod, MethodOption, OrgAuthInfo } from "../../auth/auth-types.js";
|
|
2
3
|
import { UserOrganization } from "../../auth/auth-validation-schemas.js";
|
|
3
4
|
|
|
4
5
|
//#region src/data-access/runtime/organizations.d.ts
|
|
@@ -39,6 +40,7 @@ declare const addUserToOrganization: (db: AgentsRunDatabaseClient) => (data: {
|
|
|
39
40
|
userId: string;
|
|
40
41
|
organizationId: string;
|
|
41
42
|
role: string;
|
|
43
|
+
isServiceAccount?: boolean;
|
|
42
44
|
}) => Promise<void>;
|
|
43
45
|
declare const upsertOrganization: (db: AgentsRunDatabaseClient) => (data: {
|
|
44
46
|
organizationId: string;
|
|
@@ -55,19 +57,41 @@ interface UserProviderInfo {
|
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
59
|
* Get authentication providers for a list of users.
|
|
58
|
-
* Returns which providers each user has linked (e.g., 'credential', 'google'
|
|
60
|
+
* Returns which providers each user has linked (e.g., 'credential', 'google').
|
|
59
61
|
*/
|
|
60
62
|
declare const getUserProvidersFromDb: (db: AgentsRunDatabaseClient) => (userIds: string[]) => Promise<UserProviderInfo[]>;
|
|
63
|
+
declare const getAllowedAuthMethods: (db: AgentsRunDatabaseClient) => (organizationId: string) => Promise<AllowedAuthMethod[]>;
|
|
61
64
|
/**
|
|
62
|
-
* Create an invitation directly in db
|
|
63
|
-
*
|
|
65
|
+
* Create an invitation directly in db.
|
|
66
|
+
* Accepts an optional explicit authMethod; defaults to email-password.
|
|
64
67
|
*/
|
|
65
68
|
declare const createInvitationInDb: (db: AgentsRunDatabaseClient) => (data: {
|
|
66
69
|
organizationId: string;
|
|
67
70
|
email: string;
|
|
71
|
+
authMethod?: string;
|
|
68
72
|
}) => Promise<{
|
|
69
73
|
id: string;
|
|
70
74
|
authMethod: string;
|
|
71
75
|
}>;
|
|
76
|
+
interface SSOProviderLookupResult {
|
|
77
|
+
providerId: string;
|
|
78
|
+
issuer: string;
|
|
79
|
+
domain: string;
|
|
80
|
+
organizationId: string | null;
|
|
81
|
+
providerType: 'oidc' | 'saml';
|
|
82
|
+
}
|
|
83
|
+
declare const getSSOProvidersByDomain: (db: AgentsRunDatabaseClient) => (domain: string) => Promise<SSOProviderLookupResult[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Filters org-allowed auth methods by email domain.
|
|
86
|
+
* SSO providers are only included if their domain matches the user's email domain.
|
|
87
|
+
* Non-SSO methods (email-password, google) pass through unfiltered.
|
|
88
|
+
*/
|
|
89
|
+
declare const getFilteredAuthMethodsForEmail: (db: AgentsRunDatabaseClient) => (organizationId: string, email: string) => Promise<MethodOption[]>;
|
|
90
|
+
declare function allowedMethodsToMethodOptions(methods: AllowedAuthMethod[], ssoProviders: SSOProviderLookupResult[]): MethodOption[];
|
|
91
|
+
/**
|
|
92
|
+
* Main auth-lookup query for the login flow.
|
|
93
|
+
* Returns org-grouped methods based on SSO domain match and/or user org membership.
|
|
94
|
+
*/
|
|
95
|
+
declare const getAuthLookupForEmail: (db: AgentsRunDatabaseClient) => (email: string) => Promise<OrgAuthInfo[]>;
|
|
72
96
|
//#endregion
|
|
73
|
-
export { UserProviderInfo, addUserToOrganization, createInvitationInDb, getPendingInvitationsByEmail, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
|
|
97
|
+
export { type MethodOption, type OrgAuthInfo, SSOProviderLookupResult, UserProviderInfo, addUserToOrganization, allowedMethodsToMethodOptions, createInvitationInDb, getAllowedAuthMethods, getAuthLookupForEmail, getFilteredAuthMethodsForEmail, getPendingInvitationsByEmail, getSSOProvidersByDomain, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { account, invitation, member, organization } from "../../auth/auth-schema.js";
|
|
1
|
+
import { account, invitation, member, organization, ssoProvider, user } from "../../auth/auth-schema.js";
|
|
2
|
+
import { parseAllowedAuthMethods } from "../../auth/auth-types.js";
|
|
2
3
|
import { and, desc, eq, inArray, or } from "drizzle-orm";
|
|
3
4
|
import { generateId } from "better-auth";
|
|
4
5
|
|
|
@@ -51,7 +52,10 @@ const getPendingInvitationsByEmail = (db) => async (email) => {
|
|
|
51
52
|
*/
|
|
52
53
|
const addUserToOrganization = (db) => async (data) => {
|
|
53
54
|
if ((await db.select().from(organization).where(eq(organization.id, data.organizationId)).limit(1)).length === 0) throw new Error(`Organization ${data.organizationId} does not exist`);
|
|
54
|
-
if ((await db.select().from(member).where(and(eq(member.userId, data.userId), eq(member.organizationId, data.organizationId))).limit(1)).length > 0)
|
|
55
|
+
if ((await db.select().from(member).where(and(eq(member.userId, data.userId), eq(member.organizationId, data.organizationId))).limit(1)).length > 0) {
|
|
56
|
+
if (data.isServiceAccount) await db.update(organization).set({ serviceAccountUserId: data.userId }).where(eq(organization.id, data.organizationId));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
55
59
|
await db.insert(member).values({
|
|
56
60
|
id: `${data.userId}_${data.organizationId}`,
|
|
57
61
|
userId: data.userId,
|
|
@@ -59,6 +63,7 @@ const addUserToOrganization = (db) => async (data) => {
|
|
|
59
63
|
role: data.role,
|
|
60
64
|
createdAt: /* @__PURE__ */ new Date()
|
|
61
65
|
});
|
|
66
|
+
if (data.isServiceAccount) await db.update(organization).set({ serviceAccountUserId: data.userId }).where(eq(organization.id, data.organizationId));
|
|
62
67
|
};
|
|
63
68
|
const upsertOrganization = (db) => async (data) => {
|
|
64
69
|
if ((await db.select().from(organization).where(or(eq(organization.id, data.organizationId), eq(organization.slug, data.slug))).limit(1)).length > 0) return { created: false };
|
|
@@ -74,7 +79,7 @@ const upsertOrganization = (db) => async (data) => {
|
|
|
74
79
|
};
|
|
75
80
|
/**
|
|
76
81
|
* Get authentication providers for a list of users.
|
|
77
|
-
* Returns which providers each user has linked (e.g., 'credential', 'google'
|
|
82
|
+
* Returns which providers each user has linked (e.g., 'credential', 'google').
|
|
78
83
|
*/
|
|
79
84
|
const getUserProvidersFromDb = (db) => async (userIds) => {
|
|
80
85
|
if (userIds.length === 0) return [];
|
|
@@ -93,17 +98,23 @@ const getUserProvidersFromDb = (db) => async (userIds) => {
|
|
|
93
98
|
providers: providerMap.get(userId) || []
|
|
94
99
|
}));
|
|
95
100
|
};
|
|
101
|
+
const getAllowedAuthMethods = (db) => async (organizationId) => {
|
|
102
|
+
const org = (await db.select({ allowedAuthMethods: organization.allowedAuthMethods }).from(organization).where(eq(organization.id, organizationId)).limit(1))[0];
|
|
103
|
+
if (!org) return [{ method: "email-password" }];
|
|
104
|
+
return parseAllowedAuthMethods(org.allowedAuthMethods);
|
|
105
|
+
};
|
|
96
106
|
/**
|
|
97
|
-
* Create an invitation directly in db
|
|
98
|
-
*
|
|
107
|
+
* Create an invitation directly in db.
|
|
108
|
+
* Accepts an optional explicit authMethod; defaults to email-password.
|
|
99
109
|
*/
|
|
100
110
|
const createInvitationInDb = (db) => async (data) => {
|
|
101
111
|
const orgSettings = (await db.select({
|
|
102
112
|
serviceAccountUserId: organization.serviceAccountUserId,
|
|
113
|
+
allowedAuthMethods: organization.allowedAuthMethods,
|
|
103
114
|
preferredAuthMethod: organization.preferredAuthMethod
|
|
104
115
|
}).from(organization).where(eq(organization.id, data.organizationId)).limit(1))[0];
|
|
105
116
|
if (!orgSettings?.serviceAccountUserId) throw new Error(`Organization ${data.organizationId} does not have a serviceAccountUserId configured`);
|
|
106
|
-
|
|
117
|
+
const resolvedMethod = data.authMethod || orgSettings.preferredAuthMethod || "email-password";
|
|
107
118
|
const inviteId = generateId();
|
|
108
119
|
const expiresAt = new Date(Date.now() + 3600 * 1e3);
|
|
109
120
|
await db.insert(invitation).values({
|
|
@@ -114,13 +125,124 @@ const createInvitationInDb = (db) => async (data) => {
|
|
|
114
125
|
status: "pending",
|
|
115
126
|
expiresAt,
|
|
116
127
|
inviterId: orgSettings.serviceAccountUserId,
|
|
117
|
-
authMethod:
|
|
128
|
+
authMethod: resolvedMethod
|
|
118
129
|
});
|
|
119
130
|
return {
|
|
120
131
|
id: inviteId,
|
|
121
|
-
authMethod:
|
|
132
|
+
authMethod: resolvedMethod
|
|
122
133
|
};
|
|
123
134
|
};
|
|
135
|
+
const getSSOProvidersByDomain = (db) => async (domain) => {
|
|
136
|
+
return (await db.select({
|
|
137
|
+
providerId: ssoProvider.providerId,
|
|
138
|
+
issuer: ssoProvider.issuer,
|
|
139
|
+
domain: ssoProvider.domain,
|
|
140
|
+
organizationId: ssoProvider.organizationId,
|
|
141
|
+
oidcConfig: ssoProvider.oidcConfig,
|
|
142
|
+
samlConfig: ssoProvider.samlConfig
|
|
143
|
+
}).from(ssoProvider).where(eq(ssoProvider.domain, domain))).map((provider) => ({
|
|
144
|
+
providerId: provider.providerId,
|
|
145
|
+
issuer: provider.issuer,
|
|
146
|
+
domain: provider.domain,
|
|
147
|
+
organizationId: provider.organizationId,
|
|
148
|
+
providerType: provider.samlConfig ? "saml" : "oidc"
|
|
149
|
+
}));
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Filters org-allowed auth methods by email domain.
|
|
153
|
+
* SSO providers are only included if their domain matches the user's email domain.
|
|
154
|
+
* Non-SSO methods (email-password, google) pass through unfiltered.
|
|
155
|
+
*/
|
|
156
|
+
const getFilteredAuthMethodsForEmail = (db) => async (organizationId, email) => {
|
|
157
|
+
const emailDomain = email.split("@")[1]?.toLowerCase();
|
|
158
|
+
if (!emailDomain) return [];
|
|
159
|
+
const [allowed, domainProviders] = await Promise.all([getAllowedAuthMethods(db)(organizationId), getSSOProvidersByDomain(db)(emailDomain)]);
|
|
160
|
+
return allowedMethodsToMethodOptions(allowed, domainProviders.filter((p) => p.organizationId === organizationId));
|
|
161
|
+
};
|
|
162
|
+
function allowedMethodsToMethodOptions(methods, ssoProviders) {
|
|
163
|
+
const options = [];
|
|
164
|
+
for (const m of methods) if (m.method === "email-password") options.push({ method: "email-password" });
|
|
165
|
+
else if (m.method === "google") options.push({ method: "google" });
|
|
166
|
+
else if (m.method === "sso") {
|
|
167
|
+
if (!m.enabled) continue;
|
|
168
|
+
const provider = ssoProviders.find((p) => p.providerId === m.providerId);
|
|
169
|
+
if (!provider) continue;
|
|
170
|
+
options.push({
|
|
171
|
+
method: "sso",
|
|
172
|
+
providerId: m.providerId,
|
|
173
|
+
providerType: provider.providerType,
|
|
174
|
+
displayName: m.displayName
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return options;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Main auth-lookup query for the login flow.
|
|
181
|
+
* Returns org-grouped methods based on SSO domain match and/or user org membership.
|
|
182
|
+
*/
|
|
183
|
+
const getAuthLookupForEmail = (db) => async (email) => {
|
|
184
|
+
const emailDomain = email.split("@")[1]?.toLowerCase();
|
|
185
|
+
if (!emailDomain) return [];
|
|
186
|
+
const orgMap = /* @__PURE__ */ new Map();
|
|
187
|
+
const domainProviders = await getSSOProvidersByDomain(db)(emailDomain);
|
|
188
|
+
const orgIdsFromSSO = [...new Set(domainProviders.map((p) => p.organizationId).filter(Boolean))];
|
|
189
|
+
for (const orgId of orgIdsFromSSO) {
|
|
190
|
+
const org = (await db.select({
|
|
191
|
+
id: organization.id,
|
|
192
|
+
name: organization.name,
|
|
193
|
+
slug: organization.slug,
|
|
194
|
+
allowedAuthMethods: organization.allowedAuthMethods,
|
|
195
|
+
preferredAuthMethod: organization.preferredAuthMethod
|
|
196
|
+
}).from(organization).where(eq(organization.id, orgId)).limit(1))[0];
|
|
197
|
+
if (!org) continue;
|
|
198
|
+
const allowed = parseAllowedAuthMethods(org.allowedAuthMethods);
|
|
199
|
+
const orgSSO = domainProviders.filter((p) => p.organizationId === orgId);
|
|
200
|
+
orgMap.set(orgId, {
|
|
201
|
+
organizationId: org.id,
|
|
202
|
+
organizationName: org.name,
|
|
203
|
+
organizationSlug: org.slug,
|
|
204
|
+
methods: allowedMethodsToMethodOptions(allowed, orgSSO)
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const userRow = await db.select({ id: user.id }).from(user).where(eq(user.email, email.toLowerCase())).limit(1);
|
|
208
|
+
if (userRow[0]) {
|
|
209
|
+
const memberships = await db.select({
|
|
210
|
+
organizationId: member.organizationId,
|
|
211
|
+
orgName: organization.name,
|
|
212
|
+
orgSlug: organization.slug,
|
|
213
|
+
allowedAuthMethods: organization.allowedAuthMethods,
|
|
214
|
+
preferredAuthMethod: organization.preferredAuthMethod
|
|
215
|
+
}).from(member).innerJoin(organization, eq(member.organizationId, organization.id)).where(eq(member.userId, userRow[0].id));
|
|
216
|
+
for (const m of memberships) {
|
|
217
|
+
if (orgMap.has(m.organizationId)) continue;
|
|
218
|
+
const allowed = parseAllowedAuthMethods(m.allowedAuthMethods);
|
|
219
|
+
const orgSSO = domainProviders.filter((p) => p.organizationId === m.organizationId);
|
|
220
|
+
orgMap.set(m.organizationId, {
|
|
221
|
+
organizationId: m.organizationId,
|
|
222
|
+
organizationName: m.orgName,
|
|
223
|
+
organizationSlug: m.orgSlug,
|
|
224
|
+
methods: allowedMethodsToMethodOptions(allowed, orgSSO)
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const serviceAccountOrgs = await db.select({
|
|
228
|
+
id: organization.id,
|
|
229
|
+
name: organization.name,
|
|
230
|
+
slug: organization.slug
|
|
231
|
+
}).from(organization).where(eq(organization.serviceAccountUserId, userRow[0].id));
|
|
232
|
+
for (const org of serviceAccountOrgs) {
|
|
233
|
+
const existing = orgMap.get(org.id);
|
|
234
|
+
if (existing) {
|
|
235
|
+
if (!existing.methods.some((m) => m.method === "email-password")) existing.methods.unshift({ method: "email-password" });
|
|
236
|
+
} else orgMap.set(org.id, {
|
|
237
|
+
organizationId: org.id,
|
|
238
|
+
organizationName: org.name,
|
|
239
|
+
organizationSlug: org.slug,
|
|
240
|
+
methods: [{ method: "email-password" }]
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return [...orgMap.values()];
|
|
245
|
+
};
|
|
124
246
|
|
|
125
247
|
//#endregion
|
|
126
|
-
export { addUserToOrganization, createInvitationInDb, getPendingInvitationsByEmail, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
|
|
248
|
+
export { addUserToOrganization, allowedMethodsToMethodOptions, createInvitationInDb, getAllowedAuthMethods, getAuthLookupForEmail, getFilteredAuthMethodsForEmail, getPendingInvitationsByEmail, getSSOProvidersByDomain, getUserOrganizationsFromDb, getUserProvidersFromDb, upsertOrganization };
|
|
@@ -39,7 +39,7 @@ declare const listScheduledTriggerInvocationsPaginated: (db: AgentsRunDatabaseCl
|
|
|
39
39
|
name: string;
|
|
40
40
|
hash: string;
|
|
41
41
|
} | null;
|
|
42
|
-
status: "pending" | "
|
|
42
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
43
43
|
scheduledFor: string;
|
|
44
44
|
startedAt: string | null;
|
|
45
45
|
completedAt: string | null;
|
|
@@ -184,7 +184,7 @@ declare const listUpcomingInvocationsForAgentPaginated: (db: AgentsRunDatabaseCl
|
|
|
184
184
|
name: string;
|
|
185
185
|
hash: string;
|
|
186
186
|
} | null;
|
|
187
|
-
status: "pending" | "
|
|
187
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
188
188
|
scheduledFor: string;
|
|
189
189
|
startedAt: string | null;
|
|
190
190
|
completedAt: string | null;
|
|
@@ -223,7 +223,7 @@ declare const listProjectScheduledTriggerInvocationsPaginated: (db: AgentsRunDat
|
|
|
223
223
|
name: string;
|
|
224
224
|
hash: string;
|
|
225
225
|
} | null;
|
|
226
|
-
status: "pending" | "
|
|
226
|
+
status: "pending" | "failed" | "running" | "completed" | "cancelled";
|
|
227
227
|
scheduledFor: string;
|
|
228
228
|
startedAt: string | null;
|
|
229
229
|
completedAt: string | null;
|
|
@@ -14,13 +14,13 @@ declare const createTask: (db: AgentsRunDatabaseClient) => (params: TaskInsert)
|
|
|
14
14
|
createdAt: string;
|
|
15
15
|
updatedAt: string;
|
|
16
16
|
metadata: TaskMetadataConfig | null;
|
|
17
|
+
status: string;
|
|
18
|
+
subAgentId: string;
|
|
17
19
|
ref: {
|
|
18
20
|
type: "commit" | "tag" | "branch";
|
|
19
21
|
name: string;
|
|
20
22
|
hash: string;
|
|
21
23
|
} | null;
|
|
22
|
-
status: string;
|
|
23
|
-
subAgentId: string;
|
|
24
24
|
contextId: string;
|
|
25
25
|
}>;
|
|
26
26
|
declare const getTask: (db: AgentsRunDatabaseClient) => (params: {
|