@inkeep/agents-core 0.42.0 → 0.43.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.d.ts +24 -24
- package/dist/auth/auth.js +17 -13
- package/dist/auth/authz/client.d.ts +9 -3
- package/dist/auth/authz/client.js +24 -17
- package/dist/auth/authz/config.d.ts +51 -24
- package/dist/auth/authz/config.js +44 -27
- package/dist/auth/authz/index.d.ts +3 -3
- package/dist/auth/authz/index.js +3 -3
- package/dist/auth/authz/permissions.d.ts +0 -4
- package/dist/auth/authz/permissions.js +13 -13
- package/dist/auth/authz/sync.d.ts +23 -2
- package/dist/auth/authz/sync.js +136 -52
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/client-exports.d.ts +3 -2
- package/dist/client-exports.js +3 -2
- package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
- package/dist/constants/execution-limits-shared/defaults.js +1 -1
- package/dist/constants/execution-limits-shared/index.d.ts +1 -1
- package/dist/context/TemplateEngine.d.ts +0 -6
- package/dist/context/TemplateEngine.js +4 -18
- package/dist/credential-stores/keychain-store.d.ts +20 -8
- package/dist/credential-stores/keychain-store.js +107 -43
- package/dist/data-access/index.d.ts +3 -3
- package/dist/data-access/index.js +3 -3
- package/dist/data-access/manage/agentFull.js +28 -24
- package/dist/data-access/manage/agents.d.ts +41 -41
- package/dist/data-access/manage/agents.js +29 -21
- 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 +42 -19
- package/dist/data-access/manage/functionTools.js +34 -22
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentRelations.d.ts +36 -36
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgents.d.ts +15 -15
- package/dist/data-access/manage/tools.d.ts +40 -34
- package/dist/data-access/manage/tools.js +53 -30
- package/dist/data-access/manage/triggers.d.ts +27 -1
- package/dist/data-access/runtime/apiKeys.d.ts +20 -20
- package/dist/data-access/runtime/conversations.d.ts +31 -31
- package/dist/data-access/runtime/messages.d.ts +9 -9
- package/dist/data-access/runtime/organizations.d.ts +2 -2
- package/dist/data-access/runtime/organizations.js +2 -2
- package/dist/data-access/runtime/tasks.d.ts +7 -7
- package/dist/db/manage/manage-schema.d.ts +516 -402
- package/dist/db/manage/manage-schema.js +37 -27
- package/dist/db/runtime/runtime-schema.d.ts +181 -181
- package/dist/db/utils.d.ts +6 -0
- package/dist/db/utils.js +42 -0
- package/dist/dolt/index.d.ts +2 -2
- package/dist/dolt/index.js +2 -2
- package/dist/dolt/migrate-all-branches.js +5 -0
- package/dist/dolt/migrate-dolt.js +4 -1
- package/dist/dolt/schema-sync.d.ts +2 -1
- package/dist/dolt/schema-sync.js +10 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
- package/dist/types/utility.d.ts +1 -1
- package/dist/types/utility.js +2 -1
- package/dist/utils/JsonTransformer.d.ts +1 -3
- package/dist/utils/JsonTransformer.js +14 -23
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/jmespath-utils.d.ts +152 -0
- package/dist/utils/jmespath-utils.js +213 -0
- package/dist/utils/mcp-client.d.ts +1 -1
- package/dist/utils/mcp-client.js +1 -1
- package/dist/utils/signature-validation.d.ts +2 -0
- package/dist/utils/signature-validation.js +3 -0
- package/dist/utils/third-party-mcp-servers/composio-client.d.ts +13 -1
- package/dist/utils/third-party-mcp-servers/composio-client.js +24 -6
- package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
- package/dist/utils/third-party-mcp-servers/index.js +2 -2
- package/dist/utils/trigger-auth.d.ts +31 -8
- package/dist/utils/trigger-auth.js +121 -13
- package/dist/validation/dolt-schemas.d.ts +1 -1
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/index.d.ts +3 -3
- package/dist/validation/index.js +3 -3
- package/dist/validation/render-validation.js +19 -0
- package/dist/validation/schemas.d.ts +2502 -2285
- package/dist/validation/schemas.js +246 -16
- package/dist/validation/stream-event-schemas.d.ts +96 -1
- package/dist/validation/stream-event-schemas.js +67 -2
- package/drizzle/manage/0003_tiny_captain_universe.sql +8 -0
- package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
- package/drizzle/manage/0005_silent_shatterstar.sql +53 -0
- package/drizzle/manage/meta/0003_snapshot.json +3134 -0
- package/drizzle/manage/meta/0004_snapshot.json +3141 -0
- package/drizzle/manage/meta/0005_snapshot.json +3141 -0
- package/drizzle/manage/meta/_journal.json +21 -0
- package/package.json +9 -4
- package/spicedb/schema.zed +114 -0
package/dist/auth/auth.d.ts
CHANGED
|
@@ -852,25 +852,25 @@ 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 "organization" | "
|
|
856
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
855
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
856
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "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<"organization" | "
|
|
859
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
860
860
|
};
|
|
861
861
|
admin: {
|
|
862
|
-
authorize<K_1 extends "organization" | "
|
|
863
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
862
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
863
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "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<"organization" | "
|
|
866
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
867
867
|
};
|
|
868
868
|
owner: {
|
|
869
|
-
authorize<K_1 extends "organization" | "
|
|
870
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
869
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
870
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "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<"organization" | "
|
|
873
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
874
874
|
};
|
|
875
875
|
};
|
|
876
876
|
membershipLimit: number;
|
|
@@ -897,13 +897,13 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
897
897
|
user: better_auth0.User & Record<string, any>;
|
|
898
898
|
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
899
899
|
}) => Promise<void>;
|
|
900
|
-
|
|
900
|
+
beforeUpdateMemberRole: ({
|
|
901
901
|
member,
|
|
902
902
|
organization: org,
|
|
903
|
-
|
|
903
|
+
newRole
|
|
904
904
|
}: {
|
|
905
905
|
member: better_auth_plugins0.Member & Record<string, any>;
|
|
906
|
-
|
|
906
|
+
newRole: string;
|
|
907
907
|
user: better_auth0.User & Record<string, any>;
|
|
908
908
|
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
909
909
|
}) => Promise<void>;
|
|
@@ -1161,25 +1161,25 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1161
1161
|
ac: better_auth_plugins0.AccessControl;
|
|
1162
1162
|
roles: {
|
|
1163
1163
|
member: {
|
|
1164
|
-
authorize<K_1 extends "organization" | "
|
|
1165
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
1164
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1165
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1166
1166
|
connector: "OR" | "AND";
|
|
1167
1167
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1168
|
-
statements: better_auth_plugins0.Subset<"organization" | "
|
|
1168
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1169
1169
|
};
|
|
1170
1170
|
admin: {
|
|
1171
|
-
authorize<K_1 extends "organization" | "
|
|
1172
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
1171
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1172
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1173
1173
|
connector: "OR" | "AND";
|
|
1174
1174
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1175
|
-
statements: better_auth_plugins0.Subset<"organization" | "
|
|
1175
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1176
1176
|
};
|
|
1177
1177
|
owner: {
|
|
1178
|
-
authorize<K_1 extends "organization" | "
|
|
1179
|
-
actions: better_auth_plugins0.Subset<"organization" | "
|
|
1178
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "ac" | "project" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1179
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1180
1180
|
connector: "OR" | "AND";
|
|
1181
1181
|
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1182
|
-
statements: better_auth_plugins0.Subset<"organization" | "
|
|
1182
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1183
1183
|
};
|
|
1184
1184
|
};
|
|
1185
1185
|
membershipLimit: number;
|
|
@@ -1206,13 +1206,13 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1206
1206
|
user: better_auth0.User & Record<string, any>;
|
|
1207
1207
|
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1208
1208
|
}) => Promise<void>;
|
|
1209
|
-
|
|
1209
|
+
beforeUpdateMemberRole: ({
|
|
1210
1210
|
member,
|
|
1211
1211
|
organization: org,
|
|
1212
|
-
|
|
1212
|
+
newRole
|
|
1213
1213
|
}: {
|
|
1214
1214
|
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1215
|
-
|
|
1215
|
+
newRole: string;
|
|
1216
1216
|
user: better_auth0.User & Record<string, any>;
|
|
1217
1217
|
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1218
1218
|
}) => Promise<void>;
|
package/dist/auth/auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { member, ssoProvider } from "./auth-schema.js";
|
|
2
|
+
import { OrgRoles } from "./authz/config.js";
|
|
2
3
|
import { env } from "../env.js";
|
|
3
4
|
import { generateId } from "../utils/conversations.js";
|
|
4
5
|
import "../utils/index.js";
|
|
@@ -22,7 +23,7 @@ async function getInitialOrganization(dbClient, userId) {
|
|
|
22
23
|
/**
|
|
23
24
|
* Extracts the root domain from a URL for cross-subdomain cookie sharing.
|
|
24
25
|
* For example:
|
|
25
|
-
* - https://
|
|
26
|
+
* - https://api.pilot.inkeep.com -> .pilot.inkeep.com
|
|
26
27
|
* - https://pilot.inkeep.com -> .pilot.inkeep.com
|
|
27
28
|
* - http://localhost:3002 -> undefined (no domain for localhost)
|
|
28
29
|
*
|
|
@@ -163,20 +164,23 @@ function createAuth(config) {
|
|
|
163
164
|
console.error("❌ SpiceDB sync failed for new member:", error);
|
|
164
165
|
}
|
|
165
166
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
beforeUpdateMemberRole: async ({ member: member$1, organization: org, newRole }) => {
|
|
168
|
+
const { changeOrgRole, revokeAllProjectMemberships } = await import("./authz/sync.js");
|
|
169
|
+
const oldRole = member$1.role;
|
|
170
|
+
const targetRole = newRole;
|
|
171
|
+
await changeOrgRole({
|
|
172
|
+
tenantId: org.id,
|
|
173
|
+
userId: member$1.userId,
|
|
174
|
+
oldRole,
|
|
175
|
+
newRole: targetRole
|
|
176
|
+
});
|
|
177
|
+
console.log(`🔐 SpiceDB: Updated member ${member$1.userId} role from ${oldRole} to ${targetRole} in org ${org.name}`);
|
|
178
|
+
if (oldRole === OrgRoles.MEMBER && (targetRole === OrgRoles.ADMIN || targetRole === OrgRoles.OWNER)) {
|
|
179
|
+
await revokeAllProjectMemberships({
|
|
172
180
|
tenantId: org.id,
|
|
173
|
-
userId: member$1.userId
|
|
174
|
-
oldRole,
|
|
175
|
-
newRole
|
|
181
|
+
userId: member$1.userId
|
|
176
182
|
});
|
|
177
|
-
console.log(`🔐 SpiceDB:
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.error("❌ SpiceDB sync failed for role update:", error);
|
|
183
|
+
console.log(`🔐 SpiceDB: Revoked all project memberships for ${member$1.userId} (promoted to ${targetRole})`);
|
|
180
184
|
}
|
|
181
185
|
},
|
|
182
186
|
afterRemoveMember: async ({ member: member$1, organization: org }) => {
|
|
@@ -12,9 +12,11 @@ declare function getSpiceClient(): ZedClientInterface;
|
|
|
12
12
|
* Reset the client (useful for testing)
|
|
13
13
|
*/
|
|
14
14
|
declare function resetSpiceClient(): void;
|
|
15
|
+
declare const RelationshipOperation: typeof v1.RelationshipUpdate_Operation;
|
|
16
|
+
declare const Permissionship: typeof v1.CheckPermissionResponse_Permissionship;
|
|
15
17
|
/**
|
|
16
18
|
* Check if a subject has a permission on a resource.
|
|
17
|
-
* Note: Caller must verify isAuthzEnabled(
|
|
19
|
+
* Note: Caller must verify isAuthzEnabled() before calling.
|
|
18
20
|
*/
|
|
19
21
|
declare function checkPermission(params: {
|
|
20
22
|
resourceType: string;
|
|
@@ -67,15 +69,19 @@ declare function deleteRelationship(params: {
|
|
|
67
69
|
}): Promise<void>;
|
|
68
70
|
/**
|
|
69
71
|
* Read relationships for a resource to list subjects with access.
|
|
72
|
+
* Optionally filter by subject type and ID.
|
|
70
73
|
*/
|
|
71
74
|
declare function readRelationships(params: {
|
|
72
75
|
resourceType: string;
|
|
73
|
-
resourceId
|
|
76
|
+
resourceId?: string;
|
|
74
77
|
relation?: string;
|
|
78
|
+
subjectType?: string;
|
|
79
|
+
subjectId?: string;
|
|
75
80
|
}): Promise<Array<{
|
|
81
|
+
resourceId: string;
|
|
76
82
|
subjectType: string;
|
|
77
83
|
subjectId: string;
|
|
78
84
|
relation: string;
|
|
79
85
|
}>>;
|
|
80
86
|
//#endregion
|
|
81
|
-
export { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
|
|
87
|
+
export { Permissionship, RelationshipOperation, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
|
|
@@ -7,6 +7,7 @@ import { v1 } from "@authzed/authzed-node";
|
|
|
7
7
|
*
|
|
8
8
|
* Provides a singleton SpiceDB client and helper functions for common operations.
|
|
9
9
|
*/
|
|
10
|
+
const { RelationshipUpdate_Operation, CheckPermissionResponse_Permissionship } = v1;
|
|
10
11
|
let client = null;
|
|
11
12
|
/**
|
|
12
13
|
* Get the SpiceDB client singleton.
|
|
@@ -25,11 +26,11 @@ function getSpiceClient() {
|
|
|
25
26
|
function resetSpiceClient() {
|
|
26
27
|
client = null;
|
|
27
28
|
}
|
|
28
|
-
const
|
|
29
|
-
const
|
|
29
|
+
const RelationshipOperation = RelationshipUpdate_Operation;
|
|
30
|
+
const Permissionship = CheckPermissionResponse_Permissionship;
|
|
30
31
|
/**
|
|
31
32
|
* Check if a subject has a permission on a resource.
|
|
32
|
-
* Note: Caller must verify isAuthzEnabled(
|
|
33
|
+
* Note: Caller must verify isAuthzEnabled() before calling.
|
|
33
34
|
*/
|
|
34
35
|
async function checkPermission(params) {
|
|
35
36
|
return (await getSpiceClient().promises.checkPermission({
|
|
@@ -46,12 +47,12 @@ async function checkPermission(params) {
|
|
|
46
47
|
optionalRelation: ""
|
|
47
48
|
},
|
|
48
49
|
consistency: { requirement: {
|
|
49
|
-
oneofKind: "
|
|
50
|
-
|
|
50
|
+
oneofKind: "fullyConsistent",
|
|
51
|
+
fullyConsistent: true
|
|
51
52
|
} },
|
|
52
53
|
context: void 0,
|
|
53
54
|
withTracing: false
|
|
54
|
-
})).permissionship ===
|
|
55
|
+
})).permissionship === CheckPermissionResponse_Permissionship.HAS_PERMISSION;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Check multiple permissions on a resource in a single request.
|
|
@@ -75,15 +76,15 @@ async function checkBulkPermissions(params) {
|
|
|
75
76
|
const response = await spice.promises.checkBulkPermissions(v1.CheckBulkPermissionsRequest.create({
|
|
76
77
|
items,
|
|
77
78
|
consistency: { requirement: {
|
|
78
|
-
oneofKind: "
|
|
79
|
-
|
|
79
|
+
oneofKind: "fullyConsistent",
|
|
80
|
+
fullyConsistent: true
|
|
80
81
|
} }
|
|
81
82
|
}));
|
|
82
83
|
const result = {};
|
|
83
84
|
for (let i = 0; i < params.permissions.length; i++) {
|
|
84
85
|
const permission = params.permissions[i];
|
|
85
86
|
const pair = response.pairs[i];
|
|
86
|
-
if (pair.response.oneofKind === "item") result[permission] = pair.response.item.permissionship ===
|
|
87
|
+
if (pair.response.oneofKind === "item") result[permission] = pair.response.item.permissionship === CheckPermissionResponse_Permissionship.HAS_PERMISSION;
|
|
87
88
|
else result[permission] = false;
|
|
88
89
|
}
|
|
89
90
|
return result;
|
|
@@ -103,8 +104,8 @@ async function lookupResources(params) {
|
|
|
103
104
|
optionalRelation: ""
|
|
104
105
|
},
|
|
105
106
|
consistency: { requirement: {
|
|
106
|
-
oneofKind: "
|
|
107
|
-
|
|
107
|
+
oneofKind: "fullyConsistent",
|
|
108
|
+
fullyConsistent: true
|
|
108
109
|
} },
|
|
109
110
|
context: void 0,
|
|
110
111
|
optionalLimit: 0,
|
|
@@ -117,7 +118,7 @@ async function lookupResources(params) {
|
|
|
117
118
|
async function writeRelationship(params) {
|
|
118
119
|
await getSpiceClient().promises.writeRelationships({
|
|
119
120
|
updates: [{
|
|
120
|
-
operation:
|
|
121
|
+
operation: RelationshipUpdate_Operation.TOUCH,
|
|
121
122
|
relationship: {
|
|
122
123
|
resource: {
|
|
123
124
|
objectType: params.resourceType,
|
|
@@ -162,23 +163,29 @@ async function deleteRelationship(params) {
|
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Read relationships for a resource to list subjects with access.
|
|
166
|
+
* Optionally filter by subject type and ID.
|
|
165
167
|
*/
|
|
166
168
|
async function readRelationships(params) {
|
|
167
169
|
return (await getSpiceClient().promises.readRelationships({
|
|
168
170
|
relationshipFilter: {
|
|
169
171
|
resourceType: params.resourceType,
|
|
170
|
-
optionalResourceId: params.resourceId,
|
|
172
|
+
optionalResourceId: params.resourceId || "",
|
|
171
173
|
optionalResourceIdPrefix: "",
|
|
172
174
|
optionalRelation: params.relation || "",
|
|
173
|
-
optionalSubjectFilter:
|
|
175
|
+
optionalSubjectFilter: params.subjectType || params.subjectId ? {
|
|
176
|
+
subjectType: params.subjectType || "",
|
|
177
|
+
optionalSubjectId: params.subjectId || "",
|
|
178
|
+
optionalRelation: void 0
|
|
179
|
+
} : void 0
|
|
174
180
|
},
|
|
175
181
|
consistency: { requirement: {
|
|
176
|
-
oneofKind: "
|
|
177
|
-
|
|
182
|
+
oneofKind: "fullyConsistent",
|
|
183
|
+
fullyConsistent: true
|
|
178
184
|
} },
|
|
179
185
|
optionalLimit: 0,
|
|
180
186
|
optionalCursor: void 0
|
|
181
187
|
})).map((item) => ({
|
|
188
|
+
resourceId: item.relationship?.resource?.objectId || "",
|
|
182
189
|
subjectType: item.relationship?.subject?.object?.objectType || "",
|
|
183
190
|
subjectId: item.relationship?.subject?.object?.objectId || "",
|
|
184
191
|
relation: item.relationship?.relation || ""
|
|
@@ -186,4 +193,4 @@ async function readRelationships(params) {
|
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
//#endregion
|
|
189
|
-
export { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
|
|
196
|
+
export { Permissionship, RelationshipOperation, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, v1, writeRelationship };
|
|
@@ -4,20 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Feature flag and configuration for the SpiceDB authorization system.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
* Check if authorization is enabled.
|
|
9
|
-
*
|
|
10
|
-
* When called without tenantId:
|
|
11
|
-
* - Returns true if ENABLE_AUTHZ=true
|
|
12
|
-
*
|
|
13
|
-
* When called with tenantId:
|
|
14
|
-
* - If ENABLE_AUTHZ=false → returns false
|
|
15
|
-
* - If ENABLE_AUTHZ=true and TENANT_ID is not set → returns true (all tenants)
|
|
16
|
-
* - If ENABLE_AUTHZ=true and TENANT_ID is set → returns true only if tenantId matches
|
|
17
|
-
*/
|
|
18
|
-
declare function isAuthzEnabled(tenantId: string): boolean;
|
|
7
|
+
declare function isAuthzEnabled(): boolean;
|
|
19
8
|
/**
|
|
20
9
|
* Get SpiceDB connection configuration from environment variables.
|
|
10
|
+
* TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
|
|
21
11
|
*/
|
|
22
12
|
declare function getSpiceDbConfig(): {
|
|
23
13
|
endpoint: string;
|
|
@@ -48,29 +38,66 @@ declare const SpiceDbRelations: {
|
|
|
48
38
|
readonly PROJECT_VIEWER: "project_viewer";
|
|
49
39
|
};
|
|
50
40
|
/**
|
|
51
|
-
* SpiceDB permissions
|
|
41
|
+
* SpiceDB permissions for organization resources.
|
|
52
42
|
*
|
|
53
|
-
*
|
|
43
|
+
* From schema.zed definition organization:
|
|
44
|
+
* - view: owner + admin + member
|
|
45
|
+
* - manage: owner + admin (includes managing org settings and all projects)
|
|
54
46
|
*/
|
|
47
|
+
declare const SpiceDbOrgPermissions: {
|
|
48
|
+
readonly VIEW: "view";
|
|
49
|
+
readonly MANAGE: "manage";
|
|
50
|
+
};
|
|
51
|
+
type SpiceDbOrgPermission = (typeof SpiceDbOrgPermissions)[keyof typeof SpiceDbOrgPermissions];
|
|
55
52
|
/**
|
|
56
|
-
* SpiceDB permissions
|
|
53
|
+
* SpiceDB permissions for project resources.
|
|
57
54
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
55
|
+
* From schema.zed definition project:
|
|
56
|
+
* - view: read-only access to project and its resources
|
|
57
|
+
* - use: invoke agents, create API keys, view traces
|
|
58
|
+
* - edit: modify configurations, manage members
|
|
60
59
|
*/
|
|
61
|
-
declare const
|
|
60
|
+
declare const SpiceDbProjectPermissions: {
|
|
62
61
|
readonly VIEW: "view";
|
|
63
62
|
readonly USE: "use";
|
|
64
63
|
readonly EDIT: "edit";
|
|
65
|
-
readonly DELETE: "delete";
|
|
66
64
|
};
|
|
67
|
-
type
|
|
65
|
+
type SpiceDbProjectPermission = (typeof SpiceDbProjectPermissions)[keyof typeof SpiceDbProjectPermissions];
|
|
66
|
+
/**
|
|
67
|
+
* Permission levels for project access checks.
|
|
68
|
+
*/
|
|
69
|
+
type ProjectPermissionLevel = SpiceDbProjectPermission;
|
|
70
|
+
/**
|
|
71
|
+
* Organization roles from SpiceDB schema.
|
|
72
|
+
*/
|
|
73
|
+
declare const OrgRoles: {
|
|
74
|
+
readonly OWNER: "owner";
|
|
75
|
+
readonly ADMIN: "admin";
|
|
76
|
+
readonly MEMBER: "member";
|
|
77
|
+
};
|
|
78
|
+
type OrgRole = (typeof OrgRoles)[keyof typeof OrgRoles];
|
|
68
79
|
/**
|
|
69
|
-
* Project roles
|
|
70
|
-
*
|
|
80
|
+
* Project roles from SpiceDB schema.
|
|
81
|
+
*
|
|
82
|
+
* Hierarchy:
|
|
83
|
+
* - project_admin: Full access (view + use + edit + manage members)
|
|
71
84
|
* - project_member: Operator access (view + use: invoke agents, create API keys)
|
|
72
85
|
* - project_viewer: Read-only access (view only)
|
|
73
86
|
*/
|
|
74
|
-
|
|
87
|
+
declare const ProjectRoles: {
|
|
88
|
+
readonly ADMIN: "project_admin";
|
|
89
|
+
readonly MEMBER: "project_member";
|
|
90
|
+
readonly VIEWER: "project_viewer";
|
|
91
|
+
};
|
|
92
|
+
type ProjectRole = (typeof ProjectRoles)[keyof typeof ProjectRoles];
|
|
93
|
+
/**
|
|
94
|
+
* Project permission capabilities.
|
|
95
|
+
* Maps to the SpiceDB permission checks (view, use, edit).
|
|
96
|
+
*/
|
|
97
|
+
interface ProjectPermissions {
|
|
98
|
+
canView: boolean;
|
|
99
|
+
canUse: boolean;
|
|
100
|
+
canEdit: boolean;
|
|
101
|
+
}
|
|
75
102
|
//#endregion
|
|
76
|
-
export { OrgRole, ProjectRole,
|
|
103
|
+
export { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled };
|
|
@@ -4,31 +4,20 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Feature flag and configuration for the SpiceDB authorization system.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* When called without tenantId:
|
|
11
|
-
* - Returns true if ENABLE_AUTHZ=true
|
|
12
|
-
*
|
|
13
|
-
* When called with tenantId:
|
|
14
|
-
* - If ENABLE_AUTHZ=false → returns false
|
|
15
|
-
* - If ENABLE_AUTHZ=true and TENANT_ID is not set → returns true (all tenants)
|
|
16
|
-
* - If ENABLE_AUTHZ=true and TENANT_ID is set → returns true only if tenantId matches
|
|
17
|
-
*/
|
|
18
|
-
function isAuthzEnabled(tenantId) {
|
|
19
|
-
if (process.env.ENABLE_AUTHZ !== "true") return false;
|
|
20
|
-
const configuredTenantId = process.env.TENANT_ID?.trim();
|
|
21
|
-
if (!configuredTenantId) return true;
|
|
22
|
-
return tenantId === configuredTenantId;
|
|
7
|
+
function isAuthzEnabled() {
|
|
8
|
+
return process.env.ENABLE_AUTHZ === "true";
|
|
23
9
|
}
|
|
24
10
|
/**
|
|
25
11
|
* Get SpiceDB connection configuration from environment variables.
|
|
12
|
+
* TLS is auto-detected: disabled for localhost, enabled for remote endpoints.
|
|
26
13
|
*/
|
|
27
14
|
function getSpiceDbConfig() {
|
|
15
|
+
const endpoint = process.env.SPICEDB_ENDPOINT || "localhost:50051";
|
|
16
|
+
const isLocalhost = endpoint.startsWith("localhost") || endpoint.startsWith("127.0.0.1");
|
|
28
17
|
return {
|
|
29
|
-
endpoint
|
|
18
|
+
endpoint,
|
|
30
19
|
token: process.env.SPICEDB_PRESHARED_KEY || "",
|
|
31
|
-
tlsEnabled:
|
|
20
|
+
tlsEnabled: !isLocalhost
|
|
32
21
|
};
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
@@ -55,22 +44,50 @@ const SpiceDbRelations = {
|
|
|
55
44
|
PROJECT_VIEWER: "project_viewer"
|
|
56
45
|
};
|
|
57
46
|
/**
|
|
58
|
-
* SpiceDB permissions
|
|
47
|
+
* SpiceDB permissions for organization resources.
|
|
59
48
|
*
|
|
60
|
-
*
|
|
49
|
+
* From schema.zed definition organization:
|
|
50
|
+
* - view: owner + admin + member
|
|
51
|
+
* - manage: owner + admin (includes managing org settings and all projects)
|
|
61
52
|
*/
|
|
53
|
+
const SpiceDbOrgPermissions = {
|
|
54
|
+
VIEW: "view",
|
|
55
|
+
MANAGE: "manage"
|
|
56
|
+
};
|
|
62
57
|
/**
|
|
63
|
-
* SpiceDB permissions
|
|
58
|
+
* SpiceDB permissions for project resources.
|
|
64
59
|
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
60
|
+
* From schema.zed definition project:
|
|
61
|
+
* - view: read-only access to project and its resources
|
|
62
|
+
* - use: invoke agents, create API keys, view traces
|
|
63
|
+
* - edit: modify configurations, manage members
|
|
67
64
|
*/
|
|
68
|
-
const
|
|
65
|
+
const SpiceDbProjectPermissions = {
|
|
69
66
|
VIEW: "view",
|
|
70
67
|
USE: "use",
|
|
71
|
-
EDIT: "edit"
|
|
72
|
-
|
|
68
|
+
EDIT: "edit"
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Organization roles from SpiceDB schema.
|
|
72
|
+
*/
|
|
73
|
+
const OrgRoles = {
|
|
74
|
+
OWNER: "owner",
|
|
75
|
+
ADMIN: "admin",
|
|
76
|
+
MEMBER: "member"
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Project roles from SpiceDB schema.
|
|
80
|
+
*
|
|
81
|
+
* Hierarchy:
|
|
82
|
+
* - project_admin: Full access (view + use + edit + manage members)
|
|
83
|
+
* - project_member: Operator access (view + use: invoke agents, create API keys)
|
|
84
|
+
* - project_viewer: Read-only access (view only)
|
|
85
|
+
*/
|
|
86
|
+
const ProjectRoles = {
|
|
87
|
+
ADMIN: "project_admin",
|
|
88
|
+
MEMBER: "project_member",
|
|
89
|
+
VIEWER: "project_viewer"
|
|
73
90
|
};
|
|
74
91
|
|
|
75
92
|
//#endregion
|
|
76
|
-
export {
|
|
93
|
+
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
|
|
2
|
-
import { OrgRole, ProjectRole,
|
|
2
|
+
import { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled } from "./config.js";
|
|
3
3
|
import { canEditProject, canUseProject, canViewProject, listAccessibleProjectIds } from "./permissions.js";
|
|
4
|
-
import { changeProjectRole, grantProjectAccess, listProjectMembers, removeProjectFromSpiceDb, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
5
|
-
export { type OrgRole, type ProjectRole,
|
|
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, isAuthzEnabled, 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 {
|
|
1
|
+
import { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, getSpiceDbConfig, isAuthzEnabled } 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
|
-
import { changeProjectRole, grantProjectAccess, listProjectMembers, removeProjectFromSpiceDb, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
4
|
+
import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, isAuthzEnabled, listAccessibleProjectIds, listProjectMembers, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
|
|
@@ -10,7 +10,6 @@ import { OrgRole } from "./config.js";
|
|
|
10
10
|
* - Otherwise: checks SpiceDB
|
|
11
11
|
*/
|
|
12
12
|
declare function canViewProject(params: {
|
|
13
|
-
tenantId: string;
|
|
14
13
|
userId: string;
|
|
15
14
|
projectId: string;
|
|
16
15
|
orgRole: OrgRole;
|
|
@@ -23,7 +22,6 @@ declare function canViewProject(params: {
|
|
|
23
22
|
* - Otherwise: checks SpiceDB for use permission
|
|
24
23
|
*/
|
|
25
24
|
declare function canUseProject(params: {
|
|
26
|
-
tenantId: string;
|
|
27
25
|
userId: string;
|
|
28
26
|
projectId: string;
|
|
29
27
|
orgRole: OrgRole;
|
|
@@ -36,7 +34,6 @@ declare function canUseProject(params: {
|
|
|
36
34
|
* - Otherwise: checks SpiceDB for edit permission
|
|
37
35
|
*/
|
|
38
36
|
declare function canEditProject(params: {
|
|
39
|
-
tenantId: string;
|
|
40
37
|
userId: string;
|
|
41
38
|
projectId: string;
|
|
42
39
|
orgRole: OrgRole;
|
|
@@ -49,7 +46,6 @@ declare function canEditProject(params: {
|
|
|
49
46
|
* - Otherwise: uses SpiceDB LookupResources
|
|
50
47
|
*/
|
|
51
48
|
declare function listAccessibleProjectIds(params: {
|
|
52
|
-
tenantId: string;
|
|
53
49
|
userId: string;
|
|
54
50
|
orgRole: OrgRole;
|
|
55
51
|
}): Promise<string[] | 'all'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OrgRoles, SpiceDbProjectPermissions, SpiceDbResourceTypes, isAuthzEnabled } from "./config.js";
|
|
2
2
|
import { checkPermission, lookupResources } from "./client.js";
|
|
3
3
|
|
|
4
4
|
//#region src/auth/authz/permissions.ts
|
|
@@ -15,12 +15,12 @@ import { checkPermission, lookupResources } from "./client.js";
|
|
|
15
15
|
* - Otherwise: checks SpiceDB
|
|
16
16
|
*/
|
|
17
17
|
async function canViewProject(params) {
|
|
18
|
-
|
|
19
|
-
if (
|
|
18
|
+
const isAdmin = params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN;
|
|
19
|
+
if (!isAuthzEnabled() || isAdmin) return true;
|
|
20
20
|
return checkPermission({
|
|
21
21
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
22
22
|
resourceId: params.projectId,
|
|
23
|
-
permission:
|
|
23
|
+
permission: SpiceDbProjectPermissions.VIEW,
|
|
24
24
|
subjectType: SpiceDbResourceTypes.USER,
|
|
25
25
|
subjectId: params.userId
|
|
26
26
|
});
|
|
@@ -33,12 +33,12 @@ async function canViewProject(params) {
|
|
|
33
33
|
* - Otherwise: checks SpiceDB for use permission
|
|
34
34
|
*/
|
|
35
35
|
async function canUseProject(params) {
|
|
36
|
-
|
|
37
|
-
if (
|
|
36
|
+
const isAdmin = params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN;
|
|
37
|
+
if (!isAuthzEnabled() || isAdmin) return true;
|
|
38
38
|
return checkPermission({
|
|
39
39
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
40
40
|
resourceId: params.projectId,
|
|
41
|
-
permission:
|
|
41
|
+
permission: SpiceDbProjectPermissions.USE,
|
|
42
42
|
subjectType: SpiceDbResourceTypes.USER,
|
|
43
43
|
subjectId: params.userId
|
|
44
44
|
});
|
|
@@ -51,12 +51,12 @@ async function canUseProject(params) {
|
|
|
51
51
|
* - Otherwise: checks SpiceDB for edit permission
|
|
52
52
|
*/
|
|
53
53
|
async function canEditProject(params) {
|
|
54
|
-
if (
|
|
55
|
-
if (
|
|
54
|
+
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
55
|
+
if (!isAuthzEnabled()) return false;
|
|
56
56
|
return checkPermission({
|
|
57
57
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
58
58
|
resourceId: params.projectId,
|
|
59
|
-
permission:
|
|
59
|
+
permission: SpiceDbProjectPermissions.EDIT,
|
|
60
60
|
subjectType: SpiceDbResourceTypes.USER,
|
|
61
61
|
subjectId: params.userId
|
|
62
62
|
});
|
|
@@ -69,11 +69,11 @@ async function canEditProject(params) {
|
|
|
69
69
|
* - Otherwise: uses SpiceDB LookupResources
|
|
70
70
|
*/
|
|
71
71
|
async function listAccessibleProjectIds(params) {
|
|
72
|
-
|
|
73
|
-
if (
|
|
72
|
+
const isAdmin = params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN;
|
|
73
|
+
if (!isAuthzEnabled() || isAdmin) return "all";
|
|
74
74
|
return lookupResources({
|
|
75
75
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
76
|
-
permission:
|
|
76
|
+
permission: SpiceDbProjectPermissions.VIEW,
|
|
77
77
|
subjectType: SpiceDbResourceTypes.USER,
|
|
78
78
|
subjectId: params.userId
|
|
79
79
|
});
|