@inkeep/agents-core 0.0.0-dev-20260123205017 → 0.0.0-dev-20260123212735
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 +129 -129
- package/dist/auth/auth.d.ts +63 -63
- package/dist/auth/auth.js +16 -12
- 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 +13 -13
- package/dist/client-exports.d.ts +2 -1
- package/dist/client-exports.js +2 -1
- package/dist/data-access/index.d.ts +2 -2
- package/dist/data-access/index.js +2 -2
- package/dist/data-access/manage/agents.d.ts +39 -39
- package/dist/data-access/manage/artifactComponents.d.ts +4 -4
- package/dist/data-access/manage/functionTools.d.ts +6 -6
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +6 -6
- package/dist/data-access/manage/subAgentRelations.d.ts +2 -2
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +6 -6
- package/dist/data-access/manage/subAgents.d.ts +21 -21
- package/dist/data-access/manage/tools.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/conversations.d.ts +4 -4
- package/dist/data-access/runtime/organizations.d.ts +2 -2
- package/dist/data-access/runtime/organizations.js +2 -2
- package/dist/db/manage/manage-schema.d.ts +4 -4
- package/dist/db/runtime/runtime-schema.d.ts +175 -175
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/validation/schemas.d.ts +1532 -1532
- package/package.json +2 -1
- package/spicedb/schema.zed +114 -0
package/dist/auth/auth.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AgentsRunDatabaseClient } from "../db/runtime/runtime-client.js";
|
|
|
2
2
|
import * as _better_auth_sso0 from "@better-auth/sso";
|
|
3
3
|
import * as better_auth0 from "better-auth";
|
|
4
4
|
import { BetterAuthAdvancedOptions } from "better-auth";
|
|
5
|
-
import * as
|
|
5
|
+
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
6
6
|
import * as zod0 from "zod";
|
|
7
7
|
import { GoogleOptions } from "better-auth/social-providers";
|
|
8
8
|
|
|
@@ -219,7 +219,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
219
219
|
handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>;
|
|
220
220
|
}[];
|
|
221
221
|
};
|
|
222
|
-
options:
|
|
222
|
+
options: better_auth_plugins0.BearerOptions | undefined;
|
|
223
223
|
}, {
|
|
224
224
|
id: "sso";
|
|
225
225
|
endpoints: {
|
|
@@ -847,30 +847,30 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
847
847
|
};
|
|
848
848
|
}, {
|
|
849
849
|
id: "organization";
|
|
850
|
-
endpoints:
|
|
850
|
+
endpoints: better_auth_plugins0.OrganizationEndpoints<{
|
|
851
851
|
allowUserToCreateOrganization: true;
|
|
852
|
-
ac:
|
|
852
|
+
ac: better_auth_plugins0.AccessControl;
|
|
853
853
|
roles: {
|
|
854
854
|
member: {
|
|
855
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
856
|
-
actions:
|
|
855
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
856
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
857
857
|
connector: "OR" | "AND";
|
|
858
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
859
|
-
statements:
|
|
858
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
859
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
860
860
|
};
|
|
861
861
|
admin: {
|
|
862
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
863
|
-
actions:
|
|
862
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
863
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
864
864
|
connector: "OR" | "AND";
|
|
865
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
866
|
-
statements:
|
|
865
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
866
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
867
867
|
};
|
|
868
868
|
owner: {
|
|
869
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
870
|
-
actions:
|
|
869
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
870
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
871
871
|
connector: "OR" | "AND";
|
|
872
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
873
|
-
statements:
|
|
872
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
873
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
874
874
|
};
|
|
875
875
|
};
|
|
876
876
|
membershipLimit: number;
|
|
@@ -880,9 +880,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
880
880
|
id: string;
|
|
881
881
|
role: string;
|
|
882
882
|
email: string;
|
|
883
|
-
organization:
|
|
884
|
-
invitation:
|
|
885
|
-
inviter:
|
|
883
|
+
organization: better_auth_plugins0.Organization;
|
|
884
|
+
invitation: better_auth_plugins0.Invitation;
|
|
885
|
+
inviter: better_auth_plugins0.Member & {
|
|
886
886
|
user: better_auth0.User;
|
|
887
887
|
};
|
|
888
888
|
}): Promise<void>;
|
|
@@ -892,28 +892,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
892
892
|
user,
|
|
893
893
|
organization: org
|
|
894
894
|
}: {
|
|
895
|
-
invitation:
|
|
896
|
-
member:
|
|
895
|
+
invitation: better_auth_plugins0.Invitation & Record<string, any>;
|
|
896
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
897
897
|
user: better_auth0.User & Record<string, any>;
|
|
898
|
-
organization:
|
|
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
|
-
member:
|
|
906
|
-
|
|
905
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
906
|
+
newRole: string;
|
|
907
907
|
user: better_auth0.User & Record<string, any>;
|
|
908
|
-
organization:
|
|
908
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
909
909
|
}) => Promise<void>;
|
|
910
910
|
afterRemoveMember: ({
|
|
911
911
|
member,
|
|
912
912
|
organization: org
|
|
913
913
|
}: {
|
|
914
|
-
member:
|
|
914
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
915
915
|
user: better_auth0.User & Record<string, any>;
|
|
916
|
-
organization:
|
|
916
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
917
917
|
}) => Promise<void>;
|
|
918
918
|
};
|
|
919
919
|
}>;
|
|
@@ -1044,8 +1044,8 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1044
1044
|
id: string;
|
|
1045
1045
|
organizationId: string;
|
|
1046
1046
|
email: string;
|
|
1047
|
-
role: "member" | "
|
|
1048
|
-
status:
|
|
1047
|
+
role: "member" | "owner" | "admin";
|
|
1048
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
1049
1049
|
inviterId: string;
|
|
1050
1050
|
expiresAt: Date;
|
|
1051
1051
|
createdAt: Date;
|
|
@@ -1053,7 +1053,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1053
1053
|
Member: {
|
|
1054
1054
|
id: string;
|
|
1055
1055
|
organizationId: string;
|
|
1056
|
-
role: "member" | "
|
|
1056
|
+
role: "member" | "owner" | "admin";
|
|
1057
1057
|
createdAt: Date;
|
|
1058
1058
|
userId: string;
|
|
1059
1059
|
user: {
|
|
@@ -1069,7 +1069,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1069
1069
|
members: {
|
|
1070
1070
|
id: string;
|
|
1071
1071
|
organizationId: string;
|
|
1072
|
-
role: "member" | "
|
|
1072
|
+
role: "member" | "owner" | "admin";
|
|
1073
1073
|
createdAt: Date;
|
|
1074
1074
|
userId: string;
|
|
1075
1075
|
user: {
|
|
@@ -1083,8 +1083,8 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1083
1083
|
id: string;
|
|
1084
1084
|
organizationId: string;
|
|
1085
1085
|
email: string;
|
|
1086
|
-
role: "member" | "
|
|
1087
|
-
status:
|
|
1086
|
+
role: "member" | "owner" | "admin";
|
|
1087
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
1088
1088
|
inviterId: string;
|
|
1089
1089
|
expiresAt: Date;
|
|
1090
1090
|
createdAt: Date;
|
|
@@ -1158,28 +1158,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1158
1158
|
};
|
|
1159
1159
|
options: NoInfer<{
|
|
1160
1160
|
allowUserToCreateOrganization: true;
|
|
1161
|
-
ac:
|
|
1161
|
+
ac: better_auth_plugins0.AccessControl;
|
|
1162
1162
|
roles: {
|
|
1163
1163
|
member: {
|
|
1164
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
1165
|
-
actions:
|
|
1164
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1165
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1166
1166
|
connector: "OR" | "AND";
|
|
1167
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1168
|
-
statements:
|
|
1167
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1168
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1169
1169
|
};
|
|
1170
1170
|
admin: {
|
|
1171
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
1172
|
-
actions:
|
|
1171
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1172
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1173
1173
|
connector: "OR" | "AND";
|
|
1174
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1175
|
-
statements:
|
|
1174
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1175
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1176
1176
|
};
|
|
1177
1177
|
owner: {
|
|
1178
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "
|
|
1179
|
-
actions:
|
|
1178
|
+
authorize<K_1 extends "organization" | "member" | "invitation" | "project" | "ac" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1179
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>[key];
|
|
1180
1180
|
connector: "OR" | "AND";
|
|
1181
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1182
|
-
statements:
|
|
1181
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1182
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "project" | "ac" | "team", better_auth_plugins0.Statements>;
|
|
1183
1183
|
};
|
|
1184
1184
|
};
|
|
1185
1185
|
membershipLimit: number;
|
|
@@ -1189,9 +1189,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1189
1189
|
id: string;
|
|
1190
1190
|
role: string;
|
|
1191
1191
|
email: string;
|
|
1192
|
-
organization:
|
|
1193
|
-
invitation:
|
|
1194
|
-
inviter:
|
|
1192
|
+
organization: better_auth_plugins0.Organization;
|
|
1193
|
+
invitation: better_auth_plugins0.Invitation;
|
|
1194
|
+
inviter: better_auth_plugins0.Member & {
|
|
1195
1195
|
user: better_auth0.User;
|
|
1196
1196
|
};
|
|
1197
1197
|
}): Promise<void>;
|
|
@@ -1201,28 +1201,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1201
1201
|
user,
|
|
1202
1202
|
organization: org
|
|
1203
1203
|
}: {
|
|
1204
|
-
invitation:
|
|
1205
|
-
member:
|
|
1204
|
+
invitation: better_auth_plugins0.Invitation & Record<string, any>;
|
|
1205
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1206
1206
|
user: better_auth0.User & Record<string, any>;
|
|
1207
|
-
organization:
|
|
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
|
-
member:
|
|
1215
|
-
|
|
1214
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1215
|
+
newRole: string;
|
|
1216
1216
|
user: better_auth0.User & Record<string, any>;
|
|
1217
|
-
organization:
|
|
1217
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1218
1218
|
}) => Promise<void>;
|
|
1219
1219
|
afterRemoveMember: ({
|
|
1220
1220
|
member,
|
|
1221
1221
|
organization: org
|
|
1222
1222
|
}: {
|
|
1223
|
-
member:
|
|
1223
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1224
1224
|
user: better_auth0.User & Record<string, any>;
|
|
1225
|
-
organization:
|
|
1225
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1226
1226
|
}) => Promise<void>;
|
|
1227
1227
|
};
|
|
1228
1228
|
}>;
|
|
@@ -1559,8 +1559,8 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1559
1559
|
readonly AUTHENTICATION_REQUIRED: "Authentication required";
|
|
1560
1560
|
};
|
|
1561
1561
|
options: Partial<{
|
|
1562
|
-
expiresIn:
|
|
1563
|
-
interval:
|
|
1562
|
+
expiresIn: better_auth_plugins0.TimeString;
|
|
1563
|
+
interval: better_auth_plugins0.TimeString;
|
|
1564
1564
|
deviceCodeLength: number;
|
|
1565
1565
|
userCodeLength: number;
|
|
1566
1566
|
schema: {
|
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";
|
|
@@ -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 };
|