@inkeep/agents-core 0.0.0-dev-20260129102848 ā 0.0.0-dev-20260129163144
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 +104 -104
- package/dist/auth/auth-validation-schemas.d.ts +146 -146
- package/dist/auth/auth.d.ts +26 -24
- package/dist/auth/auth.js +4 -3
- package/dist/auth/authz/client.d.ts +0 -1
- package/dist/auth/authz/client.js +0 -1
- package/dist/auth/authz/config.d.ts +1 -7
- package/dist/auth/authz/config.js +1 -9
- package/dist/auth/authz/index.d.ts +2 -2
- package/dist/auth/authz/index.js +2 -2
- package/dist/auth/authz/permissions.js +4 -8
- package/dist/auth/authz/sync.js +1 -11
- package/dist/auth/init.d.ts +1 -0
- package/dist/auth/init.js +115 -0
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/data-access/manage/agents.d.ts +41 -41
- package/dist/data-access/manage/artifactComponents.d.ts +12 -12
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/dataComponents.d.ts +6 -6
- package/dist/data-access/manage/functionTools.d.ts +18 -18
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentRelations.d.ts +28 -28
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +15 -15
- package/dist/data-access/manage/tools.d.ts +30 -30
- package/dist/data-access/manage/triggers.d.ts +2 -2
- package/dist/data-access/runtime/apiKeys.d.ts +20 -20
- package/dist/data-access/runtime/conversations.d.ts +28 -28
- package/dist/data-access/runtime/messages.d.ts +18 -18
- package/dist/data-access/runtime/organizations.js +2 -2
- package/dist/data-access/runtime/tasks.d.ts +5 -5
- package/dist/db/manage/manage-schema.d.ts +381 -381
- package/dist/db/runtime/runtime-schema.d.ts +175 -175
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/schemas.d.ts +1517 -1517
- package/package.json +3 -2
package/dist/auth/auth.d.ts
CHANGED
|
@@ -179,11 +179,11 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
179
179
|
useSecureCookies?: boolean | undefined;
|
|
180
180
|
disableCSRFCheck?: boolean | undefined;
|
|
181
181
|
disableOriginCheck?: boolean | undefined;
|
|
182
|
-
crossSubDomainCookies
|
|
182
|
+
crossSubDomainCookies?: {
|
|
183
183
|
enabled: boolean;
|
|
184
184
|
additionalCookies?: string[];
|
|
185
185
|
domain?: string;
|
|
186
|
-
};
|
|
186
|
+
} | undefined;
|
|
187
187
|
cookies?: {
|
|
188
188
|
[key: string]: {
|
|
189
189
|
name?: string;
|
|
@@ -852,27 +852,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
852
852
|
ac: better_auth_plugins0.AccessControl;
|
|
853
853
|
roles: {
|
|
854
854
|
member: {
|
|
855
|
-
authorize<K_1 extends "
|
|
856
|
-
actions: better_auth_plugins0.Subset<"
|
|
855
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
856
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
857
857
|
connector: "OR" | "AND";
|
|
858
858
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
859
|
-
statements: better_auth_plugins0.Subset<"
|
|
859
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
860
860
|
};
|
|
861
861
|
admin: {
|
|
862
|
-
authorize<K_1 extends "
|
|
863
|
-
actions: better_auth_plugins0.Subset<"
|
|
862
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
863
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
864
864
|
connector: "OR" | "AND";
|
|
865
865
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
866
|
-
statements: better_auth_plugins0.Subset<"
|
|
866
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
867
867
|
};
|
|
868
868
|
owner: {
|
|
869
|
-
authorize<K_1 extends "
|
|
870
|
-
actions: better_auth_plugins0.Subset<"
|
|
869
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
870
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
871
871
|
connector: "OR" | "AND";
|
|
872
872
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
873
|
-
statements: better_auth_plugins0.Subset<"
|
|
873
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
874
874
|
};
|
|
875
875
|
};
|
|
876
|
+
creatorRole: "admin";
|
|
876
877
|
membershipLimit: number;
|
|
877
878
|
invitationLimit: number;
|
|
878
879
|
invitationExpiresIn: number;
|
|
@@ -1044,7 +1045,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1044
1045
|
id: string;
|
|
1045
1046
|
organizationId: string;
|
|
1046
1047
|
email: string;
|
|
1047
|
-
role: "
|
|
1048
|
+
role: "owner" | "admin" | "member";
|
|
1048
1049
|
status: better_auth_plugins0.InvitationStatus;
|
|
1049
1050
|
inviterId: string;
|
|
1050
1051
|
expiresAt: Date;
|
|
@@ -1053,7 +1054,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1053
1054
|
Member: {
|
|
1054
1055
|
id: string;
|
|
1055
1056
|
organizationId: string;
|
|
1056
|
-
role: "
|
|
1057
|
+
role: "owner" | "admin" | "member";
|
|
1057
1058
|
createdAt: Date;
|
|
1058
1059
|
userId: string;
|
|
1059
1060
|
user: {
|
|
@@ -1069,7 +1070,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1069
1070
|
members: {
|
|
1070
1071
|
id: string;
|
|
1071
1072
|
organizationId: string;
|
|
1072
|
-
role: "
|
|
1073
|
+
role: "owner" | "admin" | "member";
|
|
1073
1074
|
createdAt: Date;
|
|
1074
1075
|
userId: string;
|
|
1075
1076
|
user: {
|
|
@@ -1083,7 +1084,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1083
1084
|
id: string;
|
|
1084
1085
|
organizationId: string;
|
|
1085
1086
|
email: string;
|
|
1086
|
-
role: "
|
|
1087
|
+
role: "owner" | "admin" | "member";
|
|
1087
1088
|
status: better_auth_plugins0.InvitationStatus;
|
|
1088
1089
|
inviterId: string;
|
|
1089
1090
|
expiresAt: Date;
|
|
@@ -1161,27 +1162,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1161
1162
|
ac: better_auth_plugins0.AccessControl;
|
|
1162
1163
|
roles: {
|
|
1163
1164
|
member: {
|
|
1164
|
-
authorize<K_1 extends "
|
|
1165
|
-
actions: better_auth_plugins0.Subset<"
|
|
1165
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1166
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1166
1167
|
connector: "OR" | "AND";
|
|
1167
1168
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1168
|
-
statements: better_auth_plugins0.Subset<"
|
|
1169
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1169
1170
|
};
|
|
1170
1171
|
admin: {
|
|
1171
|
-
authorize<K_1 extends "
|
|
1172
|
-
actions: better_auth_plugins0.Subset<"
|
|
1172
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1173
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1173
1174
|
connector: "OR" | "AND";
|
|
1174
1175
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1175
|
-
statements: better_auth_plugins0.Subset<"
|
|
1176
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1176
1177
|
};
|
|
1177
1178
|
owner: {
|
|
1178
|
-
authorize<K_1 extends "
|
|
1179
|
-
actions: better_auth_plugins0.Subset<"
|
|
1179
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1180
|
+
actions: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1180
1181
|
connector: "OR" | "AND";
|
|
1181
1182
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1182
|
-
statements: better_auth_plugins0.Subset<"
|
|
1183
|
+
statements: better_auth_plugins0.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1183
1184
|
};
|
|
1184
1185
|
};
|
|
1186
|
+
creatorRole: "admin";
|
|
1185
1187
|
membershipLimit: number;
|
|
1186
1188
|
invitationLimit: number;
|
|
1187
1189
|
invitationExpiresIn: number;
|
package/dist/auth/auth.js
CHANGED
|
@@ -106,10 +106,10 @@ function createAuth(config) {
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
advanced: {
|
|
109
|
-
crossSubDomainCookies: {
|
|
109
|
+
...cookieDomain && { crossSubDomainCookies: {
|
|
110
110
|
enabled: true,
|
|
111
|
-
|
|
112
|
-
},
|
|
111
|
+
domain: cookieDomain
|
|
112
|
+
} },
|
|
113
113
|
defaultCookieAttributes: {
|
|
114
114
|
sameSite: "none",
|
|
115
115
|
secure: true,
|
|
@@ -138,6 +138,7 @@ function createAuth(config) {
|
|
|
138
138
|
admin: adminRole,
|
|
139
139
|
owner: ownerRole
|
|
140
140
|
},
|
|
141
|
+
creatorRole: OrgRoles.ADMIN,
|
|
141
142
|
membershipLimit: 300,
|
|
142
143
|
invitationLimit: 300,
|
|
143
144
|
invitationExpiresIn: 10080 * 60,
|
|
@@ -16,7 +16,6 @@ declare const RelationshipOperation: typeof v1.RelationshipUpdate_Operation;
|
|
|
16
16
|
declare const Permissionship: typeof v1.CheckPermissionResponse_Permissionship;
|
|
17
17
|
/**
|
|
18
18
|
* Check if a subject has a permission on a resource.
|
|
19
|
-
* Note: Caller must verify isAuthzEnabled() before calling.
|
|
20
19
|
*/
|
|
21
20
|
declare function checkPermission(params: {
|
|
22
21
|
resourceType: string;
|
|
@@ -30,7 +30,6 @@ const RelationshipOperation = RelationshipUpdate_Operation;
|
|
|
30
30
|
const Permissionship = CheckPermissionResponse_Permissionship;
|
|
31
31
|
/**
|
|
32
32
|
* Check if a subject has a permission on a resource.
|
|
33
|
-
* Note: Caller must verify isAuthzEnabled() before calling.
|
|
34
33
|
*/
|
|
35
34
|
async function checkPermission(params) {
|
|
36
35
|
return (await getSpiceClient().promises.checkPermission({
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
//#region src/auth/authz/config.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* SpiceDB Authorization Configuration
|
|
4
|
-
*
|
|
5
|
-
* Feature flag and configuration for the SpiceDB authorization system.
|
|
6
|
-
*/
|
|
7
|
-
declare function isAuthzEnabled(): boolean;
|
|
8
2
|
/**
|
|
9
3
|
* Get SpiceDB connection configuration from environment variables.
|
|
10
4
|
* TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
|
|
@@ -100,4 +94,4 @@ interface ProjectPermissions {
|
|
|
100
94
|
canEdit: boolean;
|
|
101
95
|
}
|
|
102
96
|
//#endregion
|
|
103
|
-
export { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig
|
|
97
|
+
export { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig };
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
//#region src/auth/authz/config.ts
|
|
2
2
|
/**
|
|
3
|
-
* SpiceDB Authorization Configuration
|
|
4
|
-
*
|
|
5
|
-
* Feature flag and configuration for the SpiceDB authorization system.
|
|
6
|
-
*/
|
|
7
|
-
function isAuthzEnabled() {
|
|
8
|
-
return process.env.ENABLE_AUTHZ === "true";
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
3
|
* Get SpiceDB connection configuration from environment variables.
|
|
12
4
|
* TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
|
|
13
5
|
*/
|
|
@@ -90,4 +82,4 @@ const ProjectRoles = {
|
|
|
90
82
|
};
|
|
91
83
|
|
|
92
84
|
//#endregion
|
|
93
|
-
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig
|
|
85
|
+
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
|
|
2
|
-
import { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig
|
|
2
|
+
import { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig } from "./config.js";
|
|
3
3
|
import { canEditProject, canUseProject, canViewProject, listAccessibleProjectIds } from "./permissions.js";
|
|
4
4
|
import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
5
|
-
export { type OrgRole, OrgRoles, type ProjectPermissionLevel, type ProjectPermissions, type ProjectRole, ProjectRoles, type SpiceDbOrgPermission, SpiceDbOrgPermissions, type SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess,
|
|
5
|
+
export { type OrgRole, OrgRoles, type ProjectPermissionLevel, type ProjectPermissions, type ProjectRole, ProjectRoles, type SpiceDbOrgPermission, SpiceDbOrgPermissions, type SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
|
package/dist/auth/authz/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig
|
|
1
|
+
import { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig } from "./config.js";
|
|
2
2
|
import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
|
|
3
3
|
import { canEditProject, canUseProject, canViewProject, listAccessibleProjectIds } from "./permissions.js";
|
|
4
4
|
import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
5
5
|
|
|
6
|
-
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess,
|
|
6
|
+
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrgRoles, SpiceDbProjectPermissions, SpiceDbResourceTypes
|
|
1
|
+
import { OrgRoles, SpiceDbProjectPermissions, SpiceDbResourceTypes } from "./config.js";
|
|
2
2
|
import { checkPermission, lookupResources } from "./client.js";
|
|
3
3
|
|
|
4
4
|
//#region src/auth/authz/permissions.ts
|
|
@@ -15,8 +15,7 @@ import { checkPermission, lookupResources } from "./client.js";
|
|
|
15
15
|
* - Otherwise: checks SpiceDB
|
|
16
16
|
*/
|
|
17
17
|
async function canViewProject(params) {
|
|
18
|
-
|
|
19
|
-
if (!isAuthzEnabled() || isAdmin) return true;
|
|
18
|
+
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
20
19
|
return checkPermission({
|
|
21
20
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
22
21
|
resourceId: params.projectId,
|
|
@@ -33,8 +32,7 @@ async function canViewProject(params) {
|
|
|
33
32
|
* - Otherwise: checks SpiceDB for use permission
|
|
34
33
|
*/
|
|
35
34
|
async function canUseProject(params) {
|
|
36
|
-
|
|
37
|
-
if (!isAuthzEnabled() || isAdmin) return true;
|
|
35
|
+
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
38
36
|
return checkPermission({
|
|
39
37
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
40
38
|
resourceId: params.projectId,
|
|
@@ -52,7 +50,6 @@ async function canUseProject(params) {
|
|
|
52
50
|
*/
|
|
53
51
|
async function canEditProject(params) {
|
|
54
52
|
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
55
|
-
if (!isAuthzEnabled()) return false;
|
|
56
53
|
return checkPermission({
|
|
57
54
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
58
55
|
resourceId: params.projectId,
|
|
@@ -69,8 +66,7 @@ async function canEditProject(params) {
|
|
|
69
66
|
* - Otherwise: uses SpiceDB LookupResources
|
|
70
67
|
*/
|
|
71
68
|
async function listAccessibleProjectIds(params) {
|
|
72
|
-
|
|
73
|
-
if (!isAuthzEnabled() || isAdmin) return "all";
|
|
69
|
+
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return "all";
|
|
74
70
|
return lookupResources({
|
|
75
71
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
76
72
|
permission: SpiceDbProjectPermissions.VIEW,
|
package/dist/auth/authz/sync.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SpiceDbRelations, SpiceDbResourceTypes
|
|
1
|
+
import { SpiceDbRelations, SpiceDbResourceTypes } from "./config.js";
|
|
2
2
|
import { RelationshipOperation, deleteRelationship, getSpiceClient, readRelationships, writeRelationship } from "./client.js";
|
|
3
3
|
|
|
4
4
|
//#region src/auth/authz/sync.ts
|
|
@@ -12,7 +12,6 @@ import { RelationshipOperation, deleteRelationship, getSpiceClient, readRelation
|
|
|
12
12
|
* Call when: user joins org, role changes, user leaves org.
|
|
13
13
|
*/
|
|
14
14
|
async function syncOrgMemberToSpiceDb(params) {
|
|
15
|
-
if (!isAuthzEnabled()) return;
|
|
16
15
|
if (params.action === "add") await writeRelationship({
|
|
17
16
|
resourceType: SpiceDbResourceTypes.ORGANIZATION,
|
|
18
17
|
resourceId: params.tenantId,
|
|
@@ -34,7 +33,6 @@ async function syncOrgMemberToSpiceDb(params) {
|
|
|
34
33
|
* Call when: user's org role is updated (e.g., member -> admin).
|
|
35
34
|
*/
|
|
36
35
|
async function changeOrgRole(params) {
|
|
37
|
-
if (!isAuthzEnabled()) return;
|
|
38
36
|
if (params.oldRole === params.newRole) return;
|
|
39
37
|
await getSpiceClient().promises.writeRelationships({
|
|
40
38
|
updates: [{
|
|
@@ -82,7 +80,6 @@ async function changeOrgRole(params) {
|
|
|
82
80
|
* Call when: project is created.
|
|
83
81
|
*/
|
|
84
82
|
async function syncProjectToSpiceDb(params) {
|
|
85
|
-
if (!isAuthzEnabled()) return;
|
|
86
83
|
const spice = getSpiceClient();
|
|
87
84
|
const isOrgAdminOrOwner = (await readRelationships({
|
|
88
85
|
resourceType: SpiceDbResourceTypes.ORGANIZATION,
|
|
@@ -136,7 +133,6 @@ async function syncProjectToSpiceDb(params) {
|
|
|
136
133
|
* Grant project access to a user.
|
|
137
134
|
*/
|
|
138
135
|
async function grantProjectAccess(params) {
|
|
139
|
-
if (!isAuthzEnabled()) throw new Error("Authorization is not enabled");
|
|
140
136
|
await writeRelationship({
|
|
141
137
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
142
138
|
resourceId: params.projectId,
|
|
@@ -149,7 +145,6 @@ async function grantProjectAccess(params) {
|
|
|
149
145
|
* Revoke project access from a user.
|
|
150
146
|
*/
|
|
151
147
|
async function revokeProjectAccess(params) {
|
|
152
|
-
if (!isAuthzEnabled()) throw new Error("Authorization is not enabled");
|
|
153
148
|
await deleteRelationship({
|
|
154
149
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
155
150
|
resourceId: params.projectId,
|
|
@@ -163,7 +158,6 @@ async function revokeProjectAccess(params) {
|
|
|
163
158
|
* Removes the old role and adds the new one atomically in a single transaction.
|
|
164
159
|
*/
|
|
165
160
|
async function changeProjectRole(params) {
|
|
166
|
-
if (!isAuthzEnabled()) throw new Error("Authorization is not enabled");
|
|
167
161
|
if (params.oldRole === params.newRole) return;
|
|
168
162
|
await getSpiceClient().promises.writeRelationships({
|
|
169
163
|
updates: [{
|
|
@@ -210,7 +204,6 @@ async function changeProjectRole(params) {
|
|
|
210
204
|
* Call when: project is deleted.
|
|
211
205
|
*/
|
|
212
206
|
async function removeProjectFromSpiceDb(params) {
|
|
213
|
-
if (!isAuthzEnabled()) return;
|
|
214
207
|
await getSpiceClient().promises.deleteRelationships({
|
|
215
208
|
relationshipFilter: {
|
|
216
209
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
@@ -229,7 +222,6 @@ async function removeProjectFromSpiceDb(params) {
|
|
|
229
222
|
* Returns users with project_admin, project_member, or project_viewer roles.
|
|
230
223
|
*/
|
|
231
224
|
async function listProjectMembers(params) {
|
|
232
|
-
if (!isAuthzEnabled()) return [];
|
|
233
225
|
return (await readRelationships({
|
|
234
226
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
235
227
|
resourceId: params.projectId
|
|
@@ -243,7 +235,6 @@ async function listProjectMembers(params) {
|
|
|
243
235
|
* Returns projects where the user has explicit project_admin, project_member, or project_viewer roles.
|
|
244
236
|
*/
|
|
245
237
|
async function listUserProjectMembershipsInSpiceDb(params) {
|
|
246
|
-
if (!isAuthzEnabled()) return [];
|
|
247
238
|
return (await readRelationships({
|
|
248
239
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
249
240
|
subjectType: SpiceDbResourceTypes.USER,
|
|
@@ -260,7 +251,6 @@ async function listUserProjectMembershipsInSpiceDb(params) {
|
|
|
260
251
|
* Uses efficient bulk delete - deletes all project relationships for user without listing first.
|
|
261
252
|
*/
|
|
262
253
|
async function revokeAllProjectMemberships(params) {
|
|
263
|
-
if (!isAuthzEnabled()) return;
|
|
264
254
|
const spice = getSpiceClient();
|
|
265
255
|
await Promise.all([
|
|
266
256
|
spice.promises.deleteRelationships({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { OrgRoles } from "./authz/config.js";
|
|
2
|
+
import { loadEnvironmentFiles } from "../env.js";
|
|
3
|
+
import { syncOrgMemberToSpiceDb } from "./authz/sync.js";
|
|
4
|
+
import "./authz/index.js";
|
|
5
|
+
import { createAgentsRunDatabaseClient } from "../db/runtime/runtime-client.js";
|
|
6
|
+
import { addUserToOrganization, upsertOrganization } from "../data-access/runtime/organizations.js";
|
|
7
|
+
import { getUserByEmail } from "../data-access/runtime/users.js";
|
|
8
|
+
import { createAuth } from "./auth.js";
|
|
9
|
+
|
|
10
|
+
//#region src/auth/init.ts
|
|
11
|
+
/**
|
|
12
|
+
* Standalone initialization script for creating the default organization and admin user.
|
|
13
|
+
* This script is designed to run during setup/migration, NOT at server startup.
|
|
14
|
+
*
|
|
15
|
+
* Uses upsertOrganization to create org with TENANT_ID as the actual organization ID,
|
|
16
|
+
* and Better Auth's API for user creation.
|
|
17
|
+
*
|
|
18
|
+
* Usage: pnpm db:auth:init
|
|
19
|
+
*
|
|
20
|
+
* Required environment variables:
|
|
21
|
+
* - INKEEP_AGENTS_RUN_DATABASE_URL: PostgreSQL connection string
|
|
22
|
+
* - TENANT_ID: Organization/tenant ID (defaults to 'default') - this becomes the org ID
|
|
23
|
+
* - INKEEP_AGENTS_MANAGE_UI_USERNAME: Admin email address
|
|
24
|
+
* - INKEEP_AGENTS_MANAGE_UI_PASSWORD: Admin password (min 8 chars)
|
|
25
|
+
* - BETTER_AUTH_SECRET: Secret for Better Auth
|
|
26
|
+
*
|
|
27
|
+
* Optional environment variables:
|
|
28
|
+
* - INKEEP_AGENTS_API_URL: API URL for Better Auth (defaults to http://localhost:3002)
|
|
29
|
+
*/
|
|
30
|
+
loadEnvironmentFiles();
|
|
31
|
+
const TENANT_ID = process.env.TENANT_ID || "default";
|
|
32
|
+
async function init() {
|
|
33
|
+
console.log("š Initializing database with default organization and user...\n");
|
|
34
|
+
const dbClient = createAgentsRunDatabaseClient();
|
|
35
|
+
const username = process.env.INKEEP_AGENTS_MANAGE_UI_USERNAME;
|
|
36
|
+
const password = process.env.INKEEP_AGENTS_MANAGE_UI_PASSWORD;
|
|
37
|
+
const authSecret = process.env.BETTER_AUTH_SECRET;
|
|
38
|
+
if (!username || !password) {
|
|
39
|
+
console.error("ā INKEEP_AGENTS_MANAGE_UI_USERNAME and INKEEP_AGENTS_MANAGE_UI_PASSWORD are required");
|
|
40
|
+
console.error(" These credentials are used to create the initial admin user.");
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (!authSecret) {
|
|
44
|
+
console.error("ā BETTER_AUTH_SECRET is required");
|
|
45
|
+
console.error(" This secret is used to sign authentication tokens.");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const auth = createAuth({
|
|
49
|
+
baseURL: process.env.INKEEP_AGENTS_API_URL || "http://localhost:3002",
|
|
50
|
+
secret: authSecret,
|
|
51
|
+
dbClient
|
|
52
|
+
});
|
|
53
|
+
console.log(`š¦ Checking/creating organization: ${TENANT_ID}`);
|
|
54
|
+
const { created: orgCreated } = await upsertOrganization(dbClient)({
|
|
55
|
+
organizationId: TENANT_ID,
|
|
56
|
+
name: TENANT_ID,
|
|
57
|
+
slug: TENANT_ID,
|
|
58
|
+
logo: null,
|
|
59
|
+
metadata: null
|
|
60
|
+
});
|
|
61
|
+
if (orgCreated) console.log(` ā
Organization created with ID: ${TENANT_ID}`);
|
|
62
|
+
else console.log(` ā¹ļø Organization already exists: ${TENANT_ID}`);
|
|
63
|
+
console.log(`\nš¤ Creating admin user: ${username}`);
|
|
64
|
+
let user = await getUserByEmail(dbClient)(username);
|
|
65
|
+
if (user) console.log(` ā¹ļø User already exists: ${username}`);
|
|
66
|
+
else {
|
|
67
|
+
console.log(" Creating user with Better Auth...");
|
|
68
|
+
if (!(await auth.api.signUpEmail({ body: {
|
|
69
|
+
email: username,
|
|
70
|
+
password,
|
|
71
|
+
name: username.split("@")[0]
|
|
72
|
+
} })).user) {
|
|
73
|
+
console.error(" ā Failed to create user: signUpEmail returned no user");
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
user = await getUserByEmail(dbClient)(username);
|
|
77
|
+
if (!user) {
|
|
78
|
+
console.error(" ā User was created but could not be retrieved from database");
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
console.log(` ā
User created: ${user.email}`);
|
|
82
|
+
}
|
|
83
|
+
console.log(`\nš Adding user to organization...`);
|
|
84
|
+
await addUserToOrganization(dbClient)({
|
|
85
|
+
userId: user.id,
|
|
86
|
+
organizationId: TENANT_ID,
|
|
87
|
+
role: OrgRoles.ADMIN
|
|
88
|
+
});
|
|
89
|
+
console.log(` ā
User ${user.email} added as ${OrgRoles.ADMIN}`);
|
|
90
|
+
try {
|
|
91
|
+
await syncOrgMemberToSpiceDb({
|
|
92
|
+
tenantId: TENANT_ID,
|
|
93
|
+
userId: user.id,
|
|
94
|
+
role: OrgRoles.ADMIN,
|
|
95
|
+
action: "add"
|
|
96
|
+
});
|
|
97
|
+
console.log(" ā
Synced to SpiceDB");
|
|
98
|
+
} catch {
|
|
99
|
+
console.log(" ā¹ļø SpiceDB sync failed");
|
|
100
|
+
}
|
|
101
|
+
console.log("\n================================================");
|
|
102
|
+
console.log("ā
Initialization complete!");
|
|
103
|
+
console.log("================================================");
|
|
104
|
+
console.log(`\nOrganization: ${TENANT_ID}`);
|
|
105
|
+
console.log(`Admin user: ${username} (owner)`);
|
|
106
|
+
console.log("\nYou can now log in with these credentials.\n");
|
|
107
|
+
process.exit(0);
|
|
108
|
+
}
|
|
109
|
+
init().catch((error) => {
|
|
110
|
+
console.error("\nā Initialization failed:", error);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { };
|
|
@@ -5,25 +5,25 @@ import { organizationClient } from "better-auth/client/plugins";
|
|
|
5
5
|
//#region src/auth/permissions.d.ts
|
|
6
6
|
declare const ac: AccessControl;
|
|
7
7
|
declare const memberRole: {
|
|
8
|
-
authorize<K_1 extends "
|
|
9
|
-
actions: better_auth_plugins69.Subset<"
|
|
8
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key] | {
|
|
9
|
+
actions: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key];
|
|
10
10
|
connector: "OR" | "AND";
|
|
11
11
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins69.AuthorizeResponse;
|
|
12
|
-
statements: better_auth_plugins69.Subset<"
|
|
12
|
+
statements: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>;
|
|
13
13
|
};
|
|
14
14
|
declare const adminRole: {
|
|
15
|
-
authorize<K_1 extends "
|
|
16
|
-
actions: better_auth_plugins69.Subset<"
|
|
15
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key] | {
|
|
16
|
+
actions: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key];
|
|
17
17
|
connector: "OR" | "AND";
|
|
18
18
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins69.AuthorizeResponse;
|
|
19
|
-
statements: better_auth_plugins69.Subset<"
|
|
19
|
+
statements: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>;
|
|
20
20
|
};
|
|
21
21
|
declare const ownerRole: {
|
|
22
|
-
authorize<K_1 extends "
|
|
23
|
-
actions: better_auth_plugins69.Subset<"
|
|
22
|
+
authorize<K_1 extends "project" | "organization" | "member" | "invitation" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key] | {
|
|
23
|
+
actions: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>[key];
|
|
24
24
|
connector: "OR" | "AND";
|
|
25
25
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins69.AuthorizeResponse;
|
|
26
|
-
statements: better_auth_plugins69.Subset<"
|
|
26
|
+
statements: better_auth_plugins69.Subset<"project" | "organization" | "member" | "invitation" | "ac" | "team", better_auth_plugins69.Statements>;
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
29
|
export { ac, adminRole, memberRole, organizationClient, ownerRole };
|