@inkeep/agents-core 0.48.7 → 0.50.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-schema.d.ts +83 -83
- package/dist/auth/auth-validation-schemas.d.ts +131 -131
- package/dist/auth/auth.d.ts +53 -53
- package/dist/auth/authz/config.d.ts +20 -1
- package/dist/auth/authz/config.js +27 -1
- package/dist/auth/authz/index.d.ts +2 -2
- package/dist/auth/authz/index.js +2 -2
- package/dist/auth/authz/permissions.d.ts +6 -0
- package/dist/auth/authz/permissions.js +21 -6
- package/dist/auth/authz/sync.js +31 -18
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/client-exports.d.ts +4 -3
- package/dist/data-access/manage/agents.d.ts +43 -43
- package/dist/data-access/manage/artifactComponents.d.ts +14 -14
- package/dist/data-access/manage/contextConfigs.d.ts +20 -20
- package/dist/data-access/manage/dataComponents.d.ts +6 -6
- package/dist/data-access/manage/functionTools.d.ts +16 -16
- package/dist/data-access/manage/skills.d.ts +15 -15
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgentRelations.d.ts +26 -26
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +21 -21
- package/dist/data-access/manage/tools.d.ts +24 -24
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/conversations.d.ts +16 -16
- package/dist/data-access/runtime/messages.d.ts +6 -6
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/tasks.d.ts +3 -3
- package/dist/db/runtime/runtime-schema.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/validation/schemas.d.ts +342 -342
- package/package.json +1 -1
package/dist/auth/auth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as zod0 from "zod";
|
|
|
3
3
|
import * as _better_auth_sso0 from "@better-auth/sso";
|
|
4
4
|
import * as better_auth0 from "better-auth";
|
|
5
5
|
import { BetterAuthAdvancedOptions } from "better-auth";
|
|
6
|
-
import * as
|
|
6
|
+
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
7
7
|
import { GoogleOptions } from "better-auth/social-providers";
|
|
8
8
|
|
|
9
9
|
//#region src/auth/auth.d.ts
|
|
@@ -247,7 +247,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
247
247
|
handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>;
|
|
248
248
|
}[];
|
|
249
249
|
};
|
|
250
|
-
options:
|
|
250
|
+
options: better_auth_plugins0.BearerOptions | undefined;
|
|
251
251
|
}, {
|
|
252
252
|
id: "sso";
|
|
253
253
|
endpoints: {
|
|
@@ -875,30 +875,30 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
875
875
|
};
|
|
876
876
|
}, {
|
|
877
877
|
id: "organization";
|
|
878
|
-
endpoints:
|
|
878
|
+
endpoints: better_auth_plugins0.OrganizationEndpoints<{
|
|
879
879
|
allowUserToCreateOrganization: true;
|
|
880
|
-
ac:
|
|
880
|
+
ac: better_auth_plugins0.AccessControl;
|
|
881
881
|
roles: {
|
|
882
882
|
member: {
|
|
883
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
884
|
-
actions:
|
|
883
|
+
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] | {
|
|
884
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
885
885
|
connector: "OR" | "AND";
|
|
886
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
887
|
-
statements:
|
|
886
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
887
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
888
888
|
};
|
|
889
889
|
admin: {
|
|
890
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
891
|
-
actions:
|
|
890
|
+
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] | {
|
|
891
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
892
892
|
connector: "OR" | "AND";
|
|
893
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
894
|
-
statements:
|
|
893
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
894
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
895
895
|
};
|
|
896
896
|
owner: {
|
|
897
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
898
|
-
actions:
|
|
897
|
+
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] | {
|
|
898
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
899
899
|
connector: "OR" | "AND";
|
|
900
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
901
|
-
statements:
|
|
900
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
901
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
902
902
|
};
|
|
903
903
|
};
|
|
904
904
|
creatorRole: "admin";
|
|
@@ -909,9 +909,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
909
909
|
id: string;
|
|
910
910
|
role: string;
|
|
911
911
|
email: string;
|
|
912
|
-
organization:
|
|
913
|
-
invitation:
|
|
914
|
-
inviter:
|
|
912
|
+
organization: better_auth_plugins0.Organization;
|
|
913
|
+
invitation: better_auth_plugins0.Invitation;
|
|
914
|
+
inviter: better_auth_plugins0.Member & {
|
|
915
915
|
user: better_auth0.User;
|
|
916
916
|
};
|
|
917
917
|
}): Promise<void>;
|
|
@@ -932,28 +932,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
932
932
|
user,
|
|
933
933
|
organization: org
|
|
934
934
|
}: {
|
|
935
|
-
invitation:
|
|
936
|
-
member:
|
|
935
|
+
invitation: better_auth_plugins0.Invitation & Record<string, any>;
|
|
936
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
937
937
|
user: better_auth0.User & Record<string, any>;
|
|
938
|
-
organization:
|
|
938
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
939
939
|
}) => Promise<void>;
|
|
940
940
|
beforeUpdateMemberRole: ({
|
|
941
941
|
member,
|
|
942
942
|
organization: org,
|
|
943
943
|
newRole
|
|
944
944
|
}: {
|
|
945
|
-
member:
|
|
945
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
946
946
|
newRole: string;
|
|
947
947
|
user: better_auth0.User & Record<string, any>;
|
|
948
|
-
organization:
|
|
948
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
949
949
|
}) => Promise<void>;
|
|
950
950
|
afterRemoveMember: ({
|
|
951
951
|
member,
|
|
952
952
|
organization: org
|
|
953
953
|
}: {
|
|
954
|
-
member:
|
|
954
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
955
955
|
user: better_auth0.User & Record<string, any>;
|
|
956
|
-
organization:
|
|
956
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
957
957
|
}) => Promise<void>;
|
|
958
958
|
};
|
|
959
959
|
}>;
|
|
@@ -1085,7 +1085,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1085
1085
|
organizationId: string;
|
|
1086
1086
|
email: string;
|
|
1087
1087
|
role: "member" | "admin" | "owner";
|
|
1088
|
-
status:
|
|
1088
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
1089
1089
|
inviterId: string;
|
|
1090
1090
|
expiresAt: Date;
|
|
1091
1091
|
createdAt: Date;
|
|
@@ -1125,7 +1125,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1125
1125
|
organizationId: string;
|
|
1126
1126
|
email: string;
|
|
1127
1127
|
role: "member" | "admin" | "owner";
|
|
1128
|
-
status:
|
|
1128
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
1129
1129
|
inviterId: string;
|
|
1130
1130
|
expiresAt: Date;
|
|
1131
1131
|
createdAt: Date;
|
|
@@ -1200,28 +1200,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1200
1200
|
};
|
|
1201
1201
|
options: NoInfer<{
|
|
1202
1202
|
allowUserToCreateOrganization: true;
|
|
1203
|
-
ac:
|
|
1203
|
+
ac: better_auth_plugins0.AccessControl;
|
|
1204
1204
|
roles: {
|
|
1205
1205
|
member: {
|
|
1206
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
1207
|
-
actions:
|
|
1206
|
+
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] | {
|
|
1207
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1208
1208
|
connector: "OR" | "AND";
|
|
1209
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1210
|
-
statements:
|
|
1209
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1210
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1211
1211
|
};
|
|
1212
1212
|
admin: {
|
|
1213
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
1214
|
-
actions:
|
|
1213
|
+
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] | {
|
|
1214
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1215
1215
|
connector: "OR" | "AND";
|
|
1216
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1217
|
-
statements:
|
|
1216
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1217
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1218
1218
|
};
|
|
1219
1219
|
owner: {
|
|
1220
|
-
authorize<K_1 extends "organization" | "member" | "invitation" | "
|
|
1221
|
-
actions:
|
|
1220
|
+
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] | {
|
|
1221
|
+
actions: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>[key];
|
|
1222
1222
|
connector: "OR" | "AND";
|
|
1223
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1224
|
-
statements:
|
|
1223
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1224
|
+
statements: better_auth_plugins0.Subset<"organization" | "member" | "invitation" | "ac" | "project" | "team", better_auth_plugins0.Statements>;
|
|
1225
1225
|
};
|
|
1226
1226
|
};
|
|
1227
1227
|
creatorRole: "admin";
|
|
@@ -1232,9 +1232,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1232
1232
|
id: string;
|
|
1233
1233
|
role: string;
|
|
1234
1234
|
email: string;
|
|
1235
|
-
organization:
|
|
1236
|
-
invitation:
|
|
1237
|
-
inviter:
|
|
1235
|
+
organization: better_auth_plugins0.Organization;
|
|
1236
|
+
invitation: better_auth_plugins0.Invitation;
|
|
1237
|
+
inviter: better_auth_plugins0.Member & {
|
|
1238
1238
|
user: better_auth0.User;
|
|
1239
1239
|
};
|
|
1240
1240
|
}): Promise<void>;
|
|
@@ -1255,28 +1255,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1255
1255
|
user,
|
|
1256
1256
|
organization: org
|
|
1257
1257
|
}: {
|
|
1258
|
-
invitation:
|
|
1259
|
-
member:
|
|
1258
|
+
invitation: better_auth_plugins0.Invitation & Record<string, any>;
|
|
1259
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1260
1260
|
user: better_auth0.User & Record<string, any>;
|
|
1261
|
-
organization:
|
|
1261
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1262
1262
|
}) => Promise<void>;
|
|
1263
1263
|
beforeUpdateMemberRole: ({
|
|
1264
1264
|
member,
|
|
1265
1265
|
organization: org,
|
|
1266
1266
|
newRole
|
|
1267
1267
|
}: {
|
|
1268
|
-
member:
|
|
1268
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1269
1269
|
newRole: string;
|
|
1270
1270
|
user: better_auth0.User & Record<string, any>;
|
|
1271
|
-
organization:
|
|
1271
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1272
1272
|
}) => Promise<void>;
|
|
1273
1273
|
afterRemoveMember: ({
|
|
1274
1274
|
member,
|
|
1275
1275
|
organization: org
|
|
1276
1276
|
}: {
|
|
1277
|
-
member:
|
|
1277
|
+
member: better_auth_plugins0.Member & Record<string, any>;
|
|
1278
1278
|
user: better_auth0.User & Record<string, any>;
|
|
1279
|
-
organization:
|
|
1279
|
+
organization: better_auth_plugins0.Organization & Record<string, any>;
|
|
1280
1280
|
}) => Promise<void>;
|
|
1281
1281
|
};
|
|
1282
1282
|
}>;
|
|
@@ -1613,8 +1613,8 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1613
1613
|
readonly AUTHENTICATION_REQUIRED: "Authentication required";
|
|
1614
1614
|
};
|
|
1615
1615
|
options: Partial<{
|
|
1616
|
-
expiresIn:
|
|
1617
|
-
interval:
|
|
1616
|
+
expiresIn: better_auth_plugins0.TimeString;
|
|
1617
|
+
interval: better_auth_plugins0.TimeString;
|
|
1618
1618
|
deviceCodeLength: number;
|
|
1619
1619
|
userCodeLength: number;
|
|
1620
1620
|
schema: {
|
|
@@ -12,5 +12,24 @@ declare function getSpiceDbConfig(): {
|
|
|
12
12
|
token: string;
|
|
13
13
|
tlsEnabled: boolean;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Compose a tenant-scoped SpiceDB project object ID.
|
|
17
|
+
*
|
|
18
|
+
* SpiceDB object IDs are global, so we namespace projects under their tenant
|
|
19
|
+
* to prevent cross-tenant collisions (e.g. two orgs with a project called "default").
|
|
20
|
+
*
|
|
21
|
+
* Format: `{tenantId}/{projectId}`
|
|
22
|
+
*/
|
|
23
|
+
declare function toSpiceDbProjectId(tenantId: string, projectId: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a tenant-scoped SpiceDB project object ID back into its parts.
|
|
26
|
+
*
|
|
27
|
+
* @returns `{ tenantId, projectId }` extracted from the composite ID.
|
|
28
|
+
* @throws if the ID does not contain the separator.
|
|
29
|
+
*/
|
|
30
|
+
declare function fromSpiceDbProjectId(spiceDbProjectId: string): {
|
|
31
|
+
tenantId: string;
|
|
32
|
+
projectId: string;
|
|
33
|
+
};
|
|
15
34
|
//#endregion
|
|
16
|
-
export { getSpiceDbConfig, isLocalhostEndpoint };
|
|
35
|
+
export { fromSpiceDbProjectId, getSpiceDbConfig, isLocalhostEndpoint, toSpiceDbProjectId };
|
|
@@ -19,6 +19,32 @@ function getSpiceDbConfig() {
|
|
|
19
19
|
tlsEnabled: env.SPICEDB_TLS_ENABLED ?? !isLocalhostEndpoint(endpoint)
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
const SPICEDB_PROJECT_ID_SEPARATOR = "/";
|
|
23
|
+
/**
|
|
24
|
+
* Compose a tenant-scoped SpiceDB project object ID.
|
|
25
|
+
*
|
|
26
|
+
* SpiceDB object IDs are global, so we namespace projects under their tenant
|
|
27
|
+
* to prevent cross-tenant collisions (e.g. two orgs with a project called "default").
|
|
28
|
+
*
|
|
29
|
+
* Format: `{tenantId}/{projectId}`
|
|
30
|
+
*/
|
|
31
|
+
function toSpiceDbProjectId(tenantId, projectId) {
|
|
32
|
+
return `${tenantId}${SPICEDB_PROJECT_ID_SEPARATOR}${projectId}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse a tenant-scoped SpiceDB project object ID back into its parts.
|
|
36
|
+
*
|
|
37
|
+
* @returns `{ tenantId, projectId }` extracted from the composite ID.
|
|
38
|
+
* @throws if the ID does not contain the separator.
|
|
39
|
+
*/
|
|
40
|
+
function fromSpiceDbProjectId(spiceDbProjectId) {
|
|
41
|
+
const separatorIndex = spiceDbProjectId.indexOf(SPICEDB_PROJECT_ID_SEPARATOR);
|
|
42
|
+
if (separatorIndex === -1) throw new Error(`Invalid SpiceDB project ID format: ${spiceDbProjectId}`);
|
|
43
|
+
return {
|
|
44
|
+
tenantId: spiceDbProjectId.substring(0, separatorIndex),
|
|
45
|
+
projectId: spiceDbProjectId.substring(separatorIndex + 1)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
22
48
|
|
|
23
49
|
//#endregion
|
|
24
|
-
export { getSpiceDbConfig, isLocalhostEndpoint };
|
|
50
|
+
export { fromSpiceDbProjectId, getSpiceDbConfig, isLocalhostEndpoint, toSpiceDbProjectId };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
|
|
2
|
-
import { getSpiceDbConfig } from "./config.js";
|
|
2
|
+
import { fromSpiceDbProjectId, getSpiceDbConfig, toSpiceDbProjectId } from "./config.js";
|
|
3
3
|
import { OrgRole, OrgRoles, ProjectPermissionLevel, ProjectPermissions, ProjectRole, ProjectRoles, SpiceDbOrgPermission, SpiceDbOrgPermissions, SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes } from "./types.js";
|
|
4
4
|
import { canEditProject, canUseProject, canUseProjectStrict, canViewProject, listAccessibleProjectIds, listUsableProjectIds } from "./permissions.js";
|
|
5
5
|
import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
6
|
-
export { type OrgRole, OrgRoles, type ProjectPermissionLevel, type ProjectPermissions, type ProjectRole, ProjectRoles, type SpiceDbOrgPermission, SpiceDbOrgPermissions, type SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canUseProjectStrict, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUsableProjectIds, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
|
|
6
|
+
export { type OrgRole, OrgRoles, type ProjectPermissionLevel, type ProjectPermissions, type ProjectRole, ProjectRoles, type SpiceDbOrgPermission, SpiceDbOrgPermissions, type SpiceDbProjectPermission, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canUseProjectStrict, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, fromSpiceDbProjectId, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUsableProjectIds, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, toSpiceDbProjectId, writeRelationship };
|
package/dist/auth/authz/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes } from "./types.js";
|
|
2
|
-
import { getSpiceDbConfig } from "./config.js";
|
|
2
|
+
import { fromSpiceDbProjectId, getSpiceDbConfig, toSpiceDbProjectId } from "./config.js";
|
|
3
3
|
import { checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, lookupResources, readRelationships, resetSpiceClient, writeRelationship } from "./client.js";
|
|
4
4
|
import { canEditProject, canUseProject, canUseProjectStrict, canViewProject, listAccessibleProjectIds, listUsableProjectIds } from "./permissions.js";
|
|
5
5
|
import { changeOrgRole, changeProjectRole, grantProjectAccess, listProjectMembers, listUserProjectMembershipsInSpiceDb, removeProjectFromSpiceDb, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb } from "./sync.js";
|
|
6
6
|
|
|
7
|
-
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canUseProjectStrict, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUsableProjectIds, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, writeRelationship };
|
|
7
|
+
export { OrgRoles, ProjectRoles, SpiceDbOrgPermissions, SpiceDbProjectPermissions, SpiceDbRelations, SpiceDbResourceTypes, canEditProject, canUseProject, canUseProjectStrict, canViewProject, changeOrgRole, changeProjectRole, checkBulkPermissions, checkPermission, deleteRelationship, fromSpiceDbProjectId, getSpiceClient, getSpiceDbConfig, grantProjectAccess, listAccessibleProjectIds, listProjectMembers, listUsableProjectIds, listUserProjectMembershipsInSpiceDb, lookupResources, readRelationships, removeProjectFromSpiceDb, resetSpiceClient, revokeAllProjectMemberships, revokeProjectAccess, syncOrgMemberToSpiceDb, syncProjectToSpiceDb, toSpiceDbProjectId, writeRelationship };
|
|
@@ -11,6 +11,7 @@ import { OrgRole } from "./types.js";
|
|
|
11
11
|
*/
|
|
12
12
|
declare function canViewProject(params: {
|
|
13
13
|
userId: string;
|
|
14
|
+
tenantId: string;
|
|
14
15
|
projectId: string;
|
|
15
16
|
orgRole: OrgRole;
|
|
16
17
|
}): Promise<boolean>;
|
|
@@ -23,6 +24,7 @@ declare function canViewProject(params: {
|
|
|
23
24
|
*/
|
|
24
25
|
declare function canUseProject(params: {
|
|
25
26
|
userId: string;
|
|
27
|
+
tenantId: string;
|
|
26
28
|
projectId: string;
|
|
27
29
|
orgRole: OrgRole;
|
|
28
30
|
}): Promise<boolean>;
|
|
@@ -33,6 +35,7 @@ declare function canUseProject(params: {
|
|
|
33
35
|
*/
|
|
34
36
|
declare function canUseProjectStrict(params: {
|
|
35
37
|
userId: string;
|
|
38
|
+
tenantId: string;
|
|
36
39
|
projectId: string;
|
|
37
40
|
}): Promise<boolean>;
|
|
38
41
|
/**
|
|
@@ -44,6 +47,7 @@ declare function canUseProjectStrict(params: {
|
|
|
44
47
|
*/
|
|
45
48
|
declare function canEditProject(params: {
|
|
46
49
|
userId: string;
|
|
50
|
+
tenantId: string;
|
|
47
51
|
projectId: string;
|
|
48
52
|
orgRole: OrgRole;
|
|
49
53
|
}): Promise<boolean>;
|
|
@@ -56,6 +60,7 @@ declare function canEditProject(params: {
|
|
|
56
60
|
*/
|
|
57
61
|
declare function listAccessibleProjectIds(params: {
|
|
58
62
|
userId: string;
|
|
63
|
+
tenantId: string;
|
|
59
64
|
orgRole: OrgRole;
|
|
60
65
|
}): Promise<string[] | 'all'>;
|
|
61
66
|
/**
|
|
@@ -63,6 +68,7 @@ declare function listAccessibleProjectIds(params: {
|
|
|
63
68
|
*/
|
|
64
69
|
declare function listUsableProjectIds(params: {
|
|
65
70
|
userId: string;
|
|
71
|
+
tenantId: string;
|
|
66
72
|
}): Promise<string[]>;
|
|
67
73
|
//#endregion
|
|
68
74
|
export { canEditProject, canUseProject, canUseProjectStrict, canViewProject, listAccessibleProjectIds, listUsableProjectIds };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OrgRoles, SpiceDbProjectPermissions, SpiceDbResourceTypes } from "./types.js";
|
|
2
|
+
import { fromSpiceDbProjectId, toSpiceDbProjectId } from "./config.js";
|
|
2
3
|
import { checkPermission, lookupResources } from "./client.js";
|
|
3
4
|
|
|
4
5
|
//#region src/auth/authz/permissions.ts
|
|
@@ -18,7 +19,7 @@ async function canViewProject(params) {
|
|
|
18
19
|
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
19
20
|
return checkPermission({
|
|
20
21
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
21
|
-
resourceId: params.projectId,
|
|
22
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
22
23
|
permission: SpiceDbProjectPermissions.VIEW,
|
|
23
24
|
subjectType: SpiceDbResourceTypes.USER,
|
|
24
25
|
subjectId: params.userId
|
|
@@ -35,7 +36,7 @@ async function canUseProject(params) {
|
|
|
35
36
|
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
36
37
|
return checkPermission({
|
|
37
38
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
38
|
-
resourceId: params.projectId,
|
|
39
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
39
40
|
permission: SpiceDbProjectPermissions.USE,
|
|
40
41
|
subjectType: SpiceDbResourceTypes.USER,
|
|
41
42
|
subjectId: params.userId
|
|
@@ -50,7 +51,7 @@ async function canUseProjectStrict(params) {
|
|
|
50
51
|
if (params.userId === "system" || params.userId.startsWith("apikey:")) return true;
|
|
51
52
|
return checkPermission({
|
|
52
53
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
53
|
-
resourceId: params.projectId,
|
|
54
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
54
55
|
permission: SpiceDbProjectPermissions.USE,
|
|
55
56
|
subjectType: SpiceDbResourceTypes.USER,
|
|
56
57
|
subjectId: params.userId
|
|
@@ -67,7 +68,7 @@ async function canEditProject(params) {
|
|
|
67
68
|
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return true;
|
|
68
69
|
return checkPermission({
|
|
69
70
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
70
|
-
resourceId: params.projectId,
|
|
71
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
71
72
|
permission: SpiceDbProjectPermissions.EDIT,
|
|
72
73
|
subjectType: SpiceDbResourceTypes.USER,
|
|
73
74
|
subjectId: params.userId
|
|
@@ -82,22 +83,36 @@ async function canEditProject(params) {
|
|
|
82
83
|
*/
|
|
83
84
|
async function listAccessibleProjectIds(params) {
|
|
84
85
|
if (params.orgRole === OrgRoles.OWNER || params.orgRole === OrgRoles.ADMIN) return "all";
|
|
85
|
-
return lookupResources({
|
|
86
|
+
return (await lookupResources({
|
|
86
87
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
87
88
|
permission: SpiceDbProjectPermissions.VIEW,
|
|
88
89
|
subjectType: SpiceDbResourceTypes.USER,
|
|
89
90
|
subjectId: params.userId
|
|
91
|
+
})).flatMap((id) => {
|
|
92
|
+
try {
|
|
93
|
+
const parsed = fromSpiceDbProjectId(id);
|
|
94
|
+
return parsed.tenantId === params.tenantId ? [parsed.projectId] : [];
|
|
95
|
+
} catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
90
98
|
});
|
|
91
99
|
}
|
|
92
100
|
/**
|
|
93
101
|
* Get list of usable project IDs for a user - always checks SpiceDB.
|
|
94
102
|
*/
|
|
95
103
|
async function listUsableProjectIds(params) {
|
|
96
|
-
return lookupResources({
|
|
104
|
+
return (await lookupResources({
|
|
97
105
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
98
106
|
permission: SpiceDbProjectPermissions.USE,
|
|
99
107
|
subjectType: SpiceDbResourceTypes.USER,
|
|
100
108
|
subjectId: params.userId
|
|
109
|
+
})).flatMap((id) => {
|
|
110
|
+
try {
|
|
111
|
+
const parsed = fromSpiceDbProjectId(id);
|
|
112
|
+
return parsed.tenantId === params.tenantId ? [parsed.projectId] : [];
|
|
113
|
+
} catch {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
101
116
|
});
|
|
102
117
|
}
|
|
103
118
|
|
package/dist/auth/authz/sync.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SpiceDbRelations, SpiceDbResourceTypes } from "./types.js";
|
|
2
|
+
import { fromSpiceDbProjectId, toSpiceDbProjectId } from "./config.js";
|
|
2
3
|
import { RelationshipOperation, deleteRelationship, getSpiceClient, readRelationships, writeRelationship } from "./client.js";
|
|
3
4
|
|
|
4
5
|
//#region src/auth/authz/sync.ts
|
|
@@ -87,12 +88,13 @@ async function syncProjectToSpiceDb(params) {
|
|
|
87
88
|
subjectType: SpiceDbResourceTypes.USER,
|
|
88
89
|
subjectId: params.creatorUserId
|
|
89
90
|
})).some((r) => r.relation === SpiceDbRelations.ADMIN || r.relation === SpiceDbRelations.OWNER);
|
|
91
|
+
const spiceProjectId = toSpiceDbProjectId(params.tenantId, params.projectId);
|
|
90
92
|
const updates = [{
|
|
91
|
-
operation: RelationshipOperation.
|
|
93
|
+
operation: RelationshipOperation.TOUCH,
|
|
92
94
|
relationship: {
|
|
93
95
|
resource: {
|
|
94
96
|
objectType: SpiceDbResourceTypes.PROJECT,
|
|
95
|
-
objectId:
|
|
97
|
+
objectId: spiceProjectId
|
|
96
98
|
},
|
|
97
99
|
relation: SpiceDbRelations.ORGANIZATION,
|
|
98
100
|
subject: {
|
|
@@ -106,11 +108,11 @@ async function syncProjectToSpiceDb(params) {
|
|
|
106
108
|
}
|
|
107
109
|
}];
|
|
108
110
|
if (!isOrgAdminOrOwner) updates.push({
|
|
109
|
-
operation: RelationshipOperation.
|
|
111
|
+
operation: RelationshipOperation.TOUCH,
|
|
110
112
|
relationship: {
|
|
111
113
|
resource: {
|
|
112
114
|
objectType: SpiceDbResourceTypes.PROJECT,
|
|
113
|
-
objectId:
|
|
115
|
+
objectId: spiceProjectId
|
|
114
116
|
},
|
|
115
117
|
relation: SpiceDbRelations.PROJECT_ADMIN,
|
|
116
118
|
subject: {
|
|
@@ -135,7 +137,7 @@ async function syncProjectToSpiceDb(params) {
|
|
|
135
137
|
async function grantProjectAccess(params) {
|
|
136
138
|
await writeRelationship({
|
|
137
139
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
138
|
-
resourceId: params.projectId,
|
|
140
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
139
141
|
relation: params.role,
|
|
140
142
|
subjectType: SpiceDbResourceTypes.USER,
|
|
141
143
|
subjectId: params.userId
|
|
@@ -147,7 +149,7 @@ async function grantProjectAccess(params) {
|
|
|
147
149
|
async function revokeProjectAccess(params) {
|
|
148
150
|
await deleteRelationship({
|
|
149
151
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
150
|
-
resourceId: params.projectId,
|
|
152
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
151
153
|
relation: params.role,
|
|
152
154
|
subjectType: SpiceDbResourceTypes.USER,
|
|
153
155
|
subjectId: params.userId
|
|
@@ -159,13 +161,15 @@ async function revokeProjectAccess(params) {
|
|
|
159
161
|
*/
|
|
160
162
|
async function changeProjectRole(params) {
|
|
161
163
|
if (params.oldRole === params.newRole) return;
|
|
162
|
-
|
|
164
|
+
const spice = getSpiceClient();
|
|
165
|
+
const spiceProjectId = toSpiceDbProjectId(params.tenantId, params.projectId);
|
|
166
|
+
await spice.promises.writeRelationships({
|
|
163
167
|
updates: [{
|
|
164
168
|
operation: RelationshipOperation.DELETE,
|
|
165
169
|
relationship: {
|
|
166
170
|
resource: {
|
|
167
171
|
objectType: SpiceDbResourceTypes.PROJECT,
|
|
168
|
-
objectId:
|
|
172
|
+
objectId: spiceProjectId
|
|
169
173
|
},
|
|
170
174
|
relation: params.oldRole,
|
|
171
175
|
subject: {
|
|
@@ -182,7 +186,7 @@ async function changeProjectRole(params) {
|
|
|
182
186
|
relationship: {
|
|
183
187
|
resource: {
|
|
184
188
|
objectType: SpiceDbResourceTypes.PROJECT,
|
|
185
|
-
objectId:
|
|
189
|
+
objectId: spiceProjectId
|
|
186
190
|
},
|
|
187
191
|
relation: params.newRole,
|
|
188
192
|
subject: {
|
|
@@ -207,7 +211,7 @@ async function removeProjectFromSpiceDb(params) {
|
|
|
207
211
|
await getSpiceClient().promises.deleteRelationships({
|
|
208
212
|
relationshipFilter: {
|
|
209
213
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
210
|
-
optionalResourceId: params.projectId,
|
|
214
|
+
optionalResourceId: toSpiceDbProjectId(params.tenantId, params.projectId),
|
|
211
215
|
optionalResourceIdPrefix: "",
|
|
212
216
|
optionalRelation: ""
|
|
213
217
|
},
|
|
@@ -224,7 +228,7 @@ async function removeProjectFromSpiceDb(params) {
|
|
|
224
228
|
async function listProjectMembers(params) {
|
|
225
229
|
return (await readRelationships({
|
|
226
230
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
227
|
-
resourceId: params.projectId
|
|
231
|
+
resourceId: toSpiceDbProjectId(params.tenantId, params.projectId)
|
|
228
232
|
})).filter((rel) => rel.subjectType === SpiceDbResourceTypes.USER && (rel.relation === SpiceDbRelations.PROJECT_ADMIN || rel.relation === SpiceDbRelations.PROJECT_MEMBER || rel.relation === SpiceDbRelations.PROJECT_VIEWER)).map((rel) => ({
|
|
229
233
|
userId: rel.subjectId,
|
|
230
234
|
role: rel.relation
|
|
@@ -239,10 +243,18 @@ async function listUserProjectMembershipsInSpiceDb(params) {
|
|
|
239
243
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
240
244
|
subjectType: SpiceDbResourceTypes.USER,
|
|
241
245
|
subjectId: params.userId
|
|
242
|
-
})).filter((rel) => rel.relation === SpiceDbRelations.PROJECT_ADMIN || rel.relation === SpiceDbRelations.PROJECT_MEMBER || rel.relation === SpiceDbRelations.PROJECT_VIEWER).
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
+
})).filter((rel) => rel.relation === SpiceDbRelations.PROJECT_ADMIN || rel.relation === SpiceDbRelations.PROJECT_MEMBER || rel.relation === SpiceDbRelations.PROJECT_VIEWER).flatMap((rel) => {
|
|
247
|
+
try {
|
|
248
|
+
const parsed = fromSpiceDbProjectId(rel.resourceId);
|
|
249
|
+
if (parsed.tenantId !== params.tenantId) return [];
|
|
250
|
+
return [{
|
|
251
|
+
projectId: parsed.projectId,
|
|
252
|
+
role: rel.relation
|
|
253
|
+
}];
|
|
254
|
+
} catch {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
246
258
|
}
|
|
247
259
|
/**
|
|
248
260
|
* Revoke all project memberships for a user.
|
|
@@ -252,12 +264,13 @@ async function listUserProjectMembershipsInSpiceDb(params) {
|
|
|
252
264
|
*/
|
|
253
265
|
async function revokeAllProjectMemberships(params) {
|
|
254
266
|
const spice = getSpiceClient();
|
|
267
|
+
const tenantPrefix = `${params.tenantId}/`;
|
|
255
268
|
await Promise.all([
|
|
256
269
|
spice.promises.deleteRelationships({
|
|
257
270
|
relationshipFilter: {
|
|
258
271
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
259
272
|
optionalResourceId: "",
|
|
260
|
-
optionalResourceIdPrefix:
|
|
273
|
+
optionalResourceIdPrefix: tenantPrefix,
|
|
261
274
|
optionalRelation: SpiceDbRelations.PROJECT_ADMIN,
|
|
262
275
|
optionalSubjectFilter: {
|
|
263
276
|
subjectType: SpiceDbResourceTypes.USER,
|
|
@@ -274,7 +287,7 @@ async function revokeAllProjectMemberships(params) {
|
|
|
274
287
|
relationshipFilter: {
|
|
275
288
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
276
289
|
optionalResourceId: "",
|
|
277
|
-
optionalResourceIdPrefix:
|
|
290
|
+
optionalResourceIdPrefix: tenantPrefix,
|
|
278
291
|
optionalRelation: SpiceDbRelations.PROJECT_MEMBER,
|
|
279
292
|
optionalSubjectFilter: {
|
|
280
293
|
subjectType: SpiceDbResourceTypes.USER,
|
|
@@ -291,7 +304,7 @@ async function revokeAllProjectMemberships(params) {
|
|
|
291
304
|
relationshipFilter: {
|
|
292
305
|
resourceType: SpiceDbResourceTypes.PROJECT,
|
|
293
306
|
optionalResourceId: "",
|
|
294
|
-
optionalResourceIdPrefix:
|
|
307
|
+
optionalResourceIdPrefix: tenantPrefix,
|
|
295
308
|
optionalRelation: SpiceDbRelations.PROJECT_VIEWER,
|
|
296
309
|
optionalSubjectFilter: {
|
|
297
310
|
subjectType: SpiceDbResourceTypes.USER,
|