@krak-stack/auth 0.1.57 → 0.1.59
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/access.d.ts +93 -0
- package/dist/access.js +104 -0
- package/dist/api.d.ts +14 -0
- package/dist/components/auth-client-api.d.ts +7 -0
- package/dist/components/auth-provider.d.ts +11 -1
- package/dist/components/auth-provider.js +29 -1
- package/dist/components/index.d.ts +3 -1
- package/dist/components/index.js +2 -1
- package/dist/components/organization-switcher.d.ts +8 -1
- package/dist/components/organization-switcher.js +56 -4
- package/dist/components/user-button.d.ts +1 -1
- package/dist/components/user-button.js +1 -1
- package/dist/extra/api.group.d.ts +112 -104
- package/dist/extra/api.group.js +20 -1
- package/dist/extra/schema.d.ts +6 -0
- package/dist/extra/schema.js +16 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1 -0
- package/dist/service.d.ts +24 -0
- package/package.json +5 -1
package/dist/access.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
export declare const ApiKeyPermissionGrant: Schema.$Record<Schema.String, Schema.$Array<Schema.String>>;
|
|
3
|
+
export type ApiKeyPermissionGrant = typeof ApiKeyPermissionGrant.Type;
|
|
4
|
+
export type UserPrincipal = {
|
|
5
|
+
readonly type: "user";
|
|
6
|
+
readonly userId: string;
|
|
7
|
+
readonly organizationId: string | null;
|
|
8
|
+
readonly roles: ReadonlyArray<string>;
|
|
9
|
+
};
|
|
10
|
+
export type ApiKeyOwner = {
|
|
11
|
+
readonly type: "user";
|
|
12
|
+
readonly userId: string;
|
|
13
|
+
readonly organizationId: string | null;
|
|
14
|
+
readonly roles: ReadonlyArray<string>;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "organization";
|
|
17
|
+
readonly organizationId: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "service";
|
|
20
|
+
readonly serviceId: string;
|
|
21
|
+
};
|
|
22
|
+
export type ApiKeyPrincipal = {
|
|
23
|
+
readonly type: "apiKey";
|
|
24
|
+
readonly apiKeyId: string;
|
|
25
|
+
readonly owner: ApiKeyOwner;
|
|
26
|
+
};
|
|
27
|
+
export type Principal = UserPrincipal | ApiKeyPrincipal;
|
|
28
|
+
export type CurrentPrincipal = {
|
|
29
|
+
readonly principal: Principal;
|
|
30
|
+
readonly organizationId: string | null;
|
|
31
|
+
readonly permissions: ReadonlySet<string>;
|
|
32
|
+
};
|
|
33
|
+
export declare const CurrentPrincipal: Context.Service<CurrentPrincipal, CurrentPrincipal>;
|
|
34
|
+
declare const Forbidden_base: Schema.Class<Forbidden, Schema.Struct<{
|
|
35
|
+
readonly _tag: Schema.tag<"Forbidden">;
|
|
36
|
+
}>, import("effect/Cause").YieldableError>;
|
|
37
|
+
export declare class Forbidden extends Forbidden_base {
|
|
38
|
+
}
|
|
39
|
+
export type Policy<E = never, R = never> = Effect.Effect<void, Forbidden | E, CurrentPrincipal | R>;
|
|
40
|
+
export declare const policy: <E, R>(predicate: (principal: CurrentPrincipal) => Effect.Effect<boolean, E, R>) => Policy<E, R>;
|
|
41
|
+
export declare const permission: (requiredPermission: string) => Policy;
|
|
42
|
+
export declare const all: <E, R>(...policies: readonly [Policy<E, R>, ...Array<Policy<E, R>>]) => Policy<E, R>;
|
|
43
|
+
export declare const any: <E, R>(...policies: readonly [Policy<E, R>, ...Array<Policy<E, R>>]) => Policy<E, R>;
|
|
44
|
+
export declare const withPolicy: <E, R>(accessPolicy: Policy<E, R>) => <A, E2, R2>(self: Effect.Effect<A, E2, R2>) => Effect.Effect<A, E | E2 | Forbidden, R | R2 | CurrentPrincipal>;
|
|
45
|
+
type ProjectPermission<Project extends string, Action extends string> = `${Project}:${Action}`;
|
|
46
|
+
export type ProjectAccessDefinition<Project extends string = string, Action extends string = string> = {
|
|
47
|
+
readonly project: Project;
|
|
48
|
+
readonly actions: ReadonlyArray<Action>;
|
|
49
|
+
readonly roles: Readonly<Record<string, ReadonlyArray<Action> | undefined>>;
|
|
50
|
+
readonly apiKeys: {
|
|
51
|
+
readonly user: ReadonlyArray<Action>;
|
|
52
|
+
readonly organization: ReadonlyArray<Action>;
|
|
53
|
+
};
|
|
54
|
+
readonly qualify: (action: Action) => ProjectPermission<Project, Action>;
|
|
55
|
+
readonly permission: (action: Action) => Policy;
|
|
56
|
+
readonly permissionsForRoles: (roles: unknown) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
57
|
+
readonly permissionsForGrant: (grant: ApiKeyPermissionGrant) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
58
|
+
readonly permissionsForUserKey: (input: {
|
|
59
|
+
readonly grant: ApiKeyPermissionGrant;
|
|
60
|
+
readonly roles: unknown;
|
|
61
|
+
}) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
62
|
+
readonly decodeGrant: (input: unknown) => Effect.Effect<ReadonlySet<ProjectPermission<Project, Action>>, Schema.SchemaError>;
|
|
63
|
+
readonly encodeGrant: (actions: ReadonlyArray<Action>) => ApiKeyPermissionGrant;
|
|
64
|
+
readonly userApiKeyPermissions: ApiKeyPermissionGrant;
|
|
65
|
+
readonly organizationApiKeyPermissions: ApiKeyPermissionGrant;
|
|
66
|
+
readonly principalForUser: (input: {
|
|
67
|
+
readonly userId: string;
|
|
68
|
+
readonly organizationId: string | null;
|
|
69
|
+
readonly roles: unknown;
|
|
70
|
+
}) => CurrentPrincipal;
|
|
71
|
+
readonly principalForApiKey: (input: {
|
|
72
|
+
readonly apiKeyId: string;
|
|
73
|
+
readonly owner: ApiKeyOwner;
|
|
74
|
+
readonly grant: ApiKeyPermissionGrant;
|
|
75
|
+
}) => CurrentPrincipal;
|
|
76
|
+
};
|
|
77
|
+
export type ProjectAccessCatalog = {
|
|
78
|
+
readonly project: string;
|
|
79
|
+
readonly roles: Readonly<Record<string, ReadonlyArray<string> | undefined>>;
|
|
80
|
+
readonly userApiKeyPermissions: ApiKeyPermissionGrant;
|
|
81
|
+
readonly organizationApiKeyPermissions: ApiKeyPermissionGrant;
|
|
82
|
+
};
|
|
83
|
+
export type ProjectAccessConfig<Project extends string, Action extends string> = {
|
|
84
|
+
readonly project: Project;
|
|
85
|
+
readonly permissions: ReadonlyArray<Action>;
|
|
86
|
+
readonly roles: Readonly<Record<string, ReadonlyArray<Action> | undefined>>;
|
|
87
|
+
readonly apiKeys?: {
|
|
88
|
+
readonly user?: ReadonlyArray<Action>;
|
|
89
|
+
readonly organization?: ReadonlyArray<Action>;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export declare const defineProjectAccess: <const Project extends string, const Action extends string>(config: ProjectAccessConfig<Project, Action>) => ProjectAccessDefinition<Project, Action>;
|
|
93
|
+
export {};
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
import { parseRoleList } from "./roles";
|
|
3
|
+
export const ApiKeyPermissionGrant = Schema.Record(Schema.String, Schema.Array(Schema.String)).annotate({
|
|
4
|
+
identifier: "ApiKeyPermissionGrant",
|
|
5
|
+
title: "API key permission grant",
|
|
6
|
+
description: "Better Auth resource and action permissions assigned to a key.",
|
|
7
|
+
});
|
|
8
|
+
export const CurrentPrincipal = Context.Service("@krak-stack/auth/CurrentPrincipal");
|
|
9
|
+
export class Forbidden extends Schema.ErrorClass("Forbidden")({
|
|
10
|
+
_tag: Schema.tag("Forbidden"),
|
|
11
|
+
}, {
|
|
12
|
+
identifier: "Forbidden",
|
|
13
|
+
title: "Forbidden",
|
|
14
|
+
description: "The authenticated principal lacks a required permission.",
|
|
15
|
+
httpApiStatus: 403,
|
|
16
|
+
}) {
|
|
17
|
+
}
|
|
18
|
+
export const policy = (predicate) => Effect.flatMap(CurrentPrincipal, (principal) => Effect.flatMap(predicate(principal), (allowed) => allowed ? Effect.void : Effect.fail(new Forbidden())));
|
|
19
|
+
export const permission = (requiredPermission) => policy((principal) => Effect.succeed(principal.permissions.has(requiredPermission)));
|
|
20
|
+
export const all = (...policies) => Effect.all(policies, { concurrency: 1, discard: true });
|
|
21
|
+
export const any = (...policies) => Effect.firstSuccessOf(policies);
|
|
22
|
+
export const withPolicy = (accessPolicy) => (self) => Effect.andThen(accessPolicy, self);
|
|
23
|
+
const intersection = (left, right) => new Set(Array.from(left).filter((item) => right.has(item)));
|
|
24
|
+
const roleList = (input) => Array.isArray(input)
|
|
25
|
+
? input.flatMap((role) => parseRoleList(role))
|
|
26
|
+
: parseRoleList(input);
|
|
27
|
+
export const defineProjectAccess = (config) => {
|
|
28
|
+
const allowedActions = new Set(config.permissions);
|
|
29
|
+
const qualify = (action) => `${config.project}:${action}`;
|
|
30
|
+
const permissionsForActions = (actions) => new Set(Array.from(actions, (action) => qualify(action)));
|
|
31
|
+
const permissionsForRoles = (input) => {
|
|
32
|
+
const actions = new Set();
|
|
33
|
+
for (const role of roleList(input)) {
|
|
34
|
+
for (const action of config.roles[role] ?? [])
|
|
35
|
+
actions.add(action);
|
|
36
|
+
}
|
|
37
|
+
return permissionsForActions(actions);
|
|
38
|
+
};
|
|
39
|
+
const permissionsForGrant = (grant) => {
|
|
40
|
+
const actions = (grant[config.project] ?? []).filter((action) => allowedActions.has(action));
|
|
41
|
+
return permissionsForActions(actions);
|
|
42
|
+
};
|
|
43
|
+
const encodeGrant = (actions) => ({
|
|
44
|
+
[config.project]: actions.filter((action) => allowedActions.has(action)),
|
|
45
|
+
});
|
|
46
|
+
const userApiKeyActions = config.apiKeys?.user ?? [];
|
|
47
|
+
const organizationApiKeyActions = config.apiKeys?.organization ?? [];
|
|
48
|
+
const principalForUser = (input) => {
|
|
49
|
+
const roles = roleList(input.roles);
|
|
50
|
+
return {
|
|
51
|
+
principal: {
|
|
52
|
+
type: "user",
|
|
53
|
+
userId: input.userId,
|
|
54
|
+
organizationId: input.organizationId,
|
|
55
|
+
roles,
|
|
56
|
+
},
|
|
57
|
+
organizationId: input.organizationId,
|
|
58
|
+
permissions: permissionsForRoles(roles),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const principalForApiKey = (input) => {
|
|
62
|
+
const keyPermissions = permissionsForGrant(input.grant);
|
|
63
|
+
const permissions = (() => {
|
|
64
|
+
switch (input.owner.type) {
|
|
65
|
+
case "user":
|
|
66
|
+
return intersection(intersection(permissionsForRoles(input.owner.roles), permissionsForActions(userApiKeyActions)), keyPermissions);
|
|
67
|
+
case "organization":
|
|
68
|
+
return intersection(permissionsForActions(organizationApiKeyActions), keyPermissions);
|
|
69
|
+
case "service":
|
|
70
|
+
return keyPermissions;
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
const organizationId = input.owner.type === "service" ? null : input.owner.organizationId;
|
|
74
|
+
return {
|
|
75
|
+
principal: {
|
|
76
|
+
type: "apiKey",
|
|
77
|
+
apiKeyId: input.apiKeyId,
|
|
78
|
+
owner: input.owner,
|
|
79
|
+
},
|
|
80
|
+
organizationId,
|
|
81
|
+
permissions,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
project: config.project,
|
|
86
|
+
actions: config.permissions,
|
|
87
|
+
roles: config.roles,
|
|
88
|
+
apiKeys: {
|
|
89
|
+
user: userApiKeyActions,
|
|
90
|
+
organization: organizationApiKeyActions,
|
|
91
|
+
},
|
|
92
|
+
qualify,
|
|
93
|
+
permission: (action) => permission(qualify(action)),
|
|
94
|
+
permissionsForRoles,
|
|
95
|
+
permissionsForGrant,
|
|
96
|
+
permissionsForUserKey: ({ grant, roles }) => intersection(permissionsForRoles(roles), permissionsForGrant(grant)),
|
|
97
|
+
decodeGrant: (input) => Schema.decodeUnknownEffect(ApiKeyPermissionGrant)(input).pipe(Effect.map(permissionsForGrant)),
|
|
98
|
+
encodeGrant,
|
|
99
|
+
userApiKeyPermissions: encodeGrant(userApiKeyActions),
|
|
100
|
+
organizationApiKeyPermissions: encodeGrant(organizationApiKeyActions),
|
|
101
|
+
principalForUser,
|
|
102
|
+
principalForApiKey,
|
|
103
|
+
};
|
|
104
|
+
};
|
package/dist/api.d.ts
CHANGED
|
@@ -141,6 +141,13 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
|
|
|
141
141
|
readonly newPassword: import("effect/Schema").NonEmptyString;
|
|
142
142
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
143
143
|
readonly ok: import("effect/Schema").Boolean;
|
|
144
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateApiKeyPermissions", "PATCH", "/api/auth/api-key/:keyId/permissions", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
145
|
+
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
146
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
147
|
+
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
148
|
+
readonly permissions: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
149
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
150
|
+
readonly ok: import("effect/Schema").Boolean;
|
|
144
151
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"uploadUserImage", "POST", "/api/auth/image/upload", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
|
|
145
152
|
readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
|
|
146
153
|
}>>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
@@ -1037,6 +1044,13 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
1037
1044
|
readonly newPassword: import("effect/Schema").NonEmptyString;
|
|
1038
1045
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1039
1046
|
readonly ok: import("effect/Schema").Boolean;
|
|
1047
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateApiKeyPermissions", "PATCH", "/api/auth/api-key/:keyId/permissions", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
1048
|
+
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
1049
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1050
|
+
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
1051
|
+
readonly permissions: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
1052
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1053
|
+
readonly ok: import("effect/Schema").Boolean;
|
|
1040
1054
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"uploadUserImage", "POST", "/api/auth/image/upload", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
|
|
1041
1055
|
readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
|
|
1042
1056
|
}>>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
@@ -524,6 +524,13 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
524
524
|
readonly newPassword: import("effect/Schema").NonEmptyString;
|
|
525
525
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
526
526
|
readonly ok: import("effect/Schema").Boolean;
|
|
527
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("../extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateApiKeyPermissions", "PATCH", "/api/auth/api-key/:keyId/permissions", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
528
|
+
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
529
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
530
|
+
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
531
|
+
readonly permissions: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
532
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
533
|
+
readonly ok: import("effect/Schema").Boolean;
|
|
527
534
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("../extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"uploadUserImage", "POST", "/api/auth/image/upload", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
|
|
528
535
|
readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
|
|
529
536
|
}>>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import { type AuthUiClient } from "./auth-client";
|
|
3
3
|
import type { ExtraProjectPublicConfig } from "../extra/schema";
|
|
4
|
+
import type { ProjectAccessCatalog } from "../access";
|
|
4
5
|
export type KrakstackAuthLocale = "en" | "fr";
|
|
5
6
|
export type KrakstackAuthProviderProps = {
|
|
6
7
|
children: ReactNode;
|
|
@@ -8,6 +9,7 @@ export type KrakstackAuthProviderProps = {
|
|
|
8
9
|
baseUrl?: string | undefined;
|
|
9
10
|
projectId?: string | null | undefined;
|
|
10
11
|
authClient?: AuthUiClient | undefined;
|
|
12
|
+
access?: ProjectAccessCatalog | undefined;
|
|
11
13
|
};
|
|
12
14
|
export type KrakstackAuthContextValue = {
|
|
13
15
|
locale: KrakstackAuthLocale;
|
|
@@ -15,10 +17,11 @@ export type KrakstackAuthContextValue = {
|
|
|
15
17
|
projectId?: string | null | undefined;
|
|
16
18
|
authClient: AuthUiClient;
|
|
17
19
|
projectConfig: ExtraProjectPublicConfig | null;
|
|
20
|
+
access: ProjectAccessCatalog | null;
|
|
18
21
|
authRefreshVersion: number;
|
|
19
22
|
refreshAuth: () => void;
|
|
20
23
|
};
|
|
21
|
-
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
24
|
+
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
22
25
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
23
26
|
export declare const useAuthClient: () => AuthUiClient;
|
|
24
27
|
export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema").Struct.ReadonlySide<{
|
|
@@ -36,3 +39,10 @@ export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema"
|
|
|
36
39
|
readonly signUpName: import("effect/Schema").Boolean;
|
|
37
40
|
}>;
|
|
38
41
|
}, "Type"> | null;
|
|
42
|
+
export declare const usePermissions: () => {
|
|
43
|
+
loading: boolean;
|
|
44
|
+
permissions: Set<string>;
|
|
45
|
+
can: (action: string) => boolean;
|
|
46
|
+
canAll: (required: ReadonlyArray<string>) => boolean;
|
|
47
|
+
canAny: (required: ReadonlyArray<string>) => boolean;
|
|
48
|
+
};
|
|
@@ -4,6 +4,7 @@ import { useRouterState } from "@tanstack/react-router";
|
|
|
4
4
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from "react";
|
|
5
5
|
import { createAuthUiClient } from "./auth-client";
|
|
6
6
|
import { authClientApi } from "./auth-client-api";
|
|
7
|
+
import { parseRoleList } from "../roles";
|
|
7
8
|
const KrakstackAuthContext = createContext(null);
|
|
8
9
|
const PROJECT_CONTEXT_COOKIE = "krakstack-auth.project_context";
|
|
9
10
|
const setProjectContextCookie = (projectId) => {
|
|
@@ -67,7 +68,7 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
67
68
|
}), { suspendOnWaiting: true });
|
|
68
69
|
return result.value;
|
|
69
70
|
};
|
|
70
|
-
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, }) {
|
|
71
|
+
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, access, }) {
|
|
71
72
|
const searchString = useRouterState({
|
|
72
73
|
select: (state) => state.location.searchStr,
|
|
73
74
|
});
|
|
@@ -87,6 +88,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
87
88
|
locale,
|
|
88
89
|
projectId: resolvedProjectId,
|
|
89
90
|
projectConfig,
|
|
91
|
+
access: access ?? null,
|
|
90
92
|
authRefreshVersion,
|
|
91
93
|
refreshAuth,
|
|
92
94
|
}), [
|
|
@@ -95,6 +97,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
95
97
|
locale,
|
|
96
98
|
resolvedProjectId,
|
|
97
99
|
projectConfig,
|
|
100
|
+
access,
|
|
98
101
|
authRefreshVersion,
|
|
99
102
|
refreshAuth,
|
|
100
103
|
]);
|
|
@@ -109,3 +112,28 @@ export const useAuthClient = () => {
|
|
|
109
112
|
return auth.authClient;
|
|
110
113
|
};
|
|
111
114
|
export const useKrakstackAuthProjectConfig = () => useKrakstackAuth()?.projectConfig ?? null;
|
|
115
|
+
export const usePermissions = () => {
|
|
116
|
+
const auth = useKrakstackAuth();
|
|
117
|
+
if (!auth) {
|
|
118
|
+
throw new Error("KrakstackAuthProvider is required to use permissions.");
|
|
119
|
+
}
|
|
120
|
+
const session = auth.authClient.useSession();
|
|
121
|
+
const activeOrganization = auth.authClient.useActiveOrganization();
|
|
122
|
+
const memberRole = activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role;
|
|
123
|
+
const actions = new Set();
|
|
124
|
+
if (auth.access) {
|
|
125
|
+
for (const role of parseRoleList(memberRole)) {
|
|
126
|
+
for (const action of auth.access.roles[role] ?? [])
|
|
127
|
+
actions.add(action);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
loading: session.isPending || activeOrganization.isPending,
|
|
132
|
+
permissions: auth.access
|
|
133
|
+
? new Set(Array.from(actions, (action) => `${auth.access?.project}:${action}`))
|
|
134
|
+
: new Set(),
|
|
135
|
+
can: (action) => actions.has(action),
|
|
136
|
+
canAll: (required) => required.every((action) => actions.has(action)),
|
|
137
|
+
canAny: (required) => required.some((action) => actions.has(action)),
|
|
138
|
+
};
|
|
139
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
1
|
+
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider";
|
|
2
2
|
export { createAuthUiClient } from "./auth-client";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
4
4
|
export { MemberRequired } from "./member-required";
|
|
@@ -8,6 +8,8 @@ export { AdminOrganizationsTable } from "./admin-organizations";
|
|
|
8
8
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
9
9
|
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
10
10
|
export { assetUrl } from "./utils";
|
|
11
|
+
export { ApiKeyPermissionGrant, CurrentPrincipal, Forbidden, all, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
|
12
|
+
export type { ApiKeyOwner, ApiKeyPrincipal, Policy, Principal, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserPrincipal, } from "../access";
|
|
11
13
|
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
|
|
12
14
|
export type { OrganizationSwitcherDialog, OrganizationSwitcherFeatures, OrganizationSwitcherProps, } from "./organization-switcher";
|
|
13
15
|
export type { UserButtonDialog } from "./user-button";
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
1
|
+
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, usePermissions, } from "./auth-provider";
|
|
2
2
|
export { createAuthUiClient } from "./auth-client";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
4
4
|
export { MemberRequired } from "./member-required";
|
|
@@ -8,3 +8,4 @@ export { AdminOrganizationsTable } from "./admin-organizations";
|
|
|
8
8
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
9
9
|
export { AdminUsersTable, useAdminUsersTotal } from "./admin-users";
|
|
10
10
|
export { assetUrl } from "./utils";
|
|
11
|
+
export { ApiKeyPermissionGrant, CurrentPrincipal, Forbidden, all, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
|
@@ -111,6 +111,9 @@ declare const messages: {
|
|
|
111
111
|
readonly user_api_key_enabled: "Enabled";
|
|
112
112
|
readonly user_api_key_hidden: "Secret hidden";
|
|
113
113
|
readonly user_api_key_name: "Key name";
|
|
114
|
+
readonly user_api_key_no_permissions: "No permissions";
|
|
115
|
+
readonly user_api_key_permissions: "Permissions";
|
|
116
|
+
readonly user_api_key_permissions_description: "Choose the project permissions this API key should receive.";
|
|
114
117
|
readonly user_api_key_rate_limit: "Rate limit";
|
|
115
118
|
readonly user_api_key_referrers: "Allowed referrers (optional)";
|
|
116
119
|
readonly user_api_key_referrers_any: "Any referrer";
|
|
@@ -244,6 +247,9 @@ declare const messages: {
|
|
|
244
247
|
readonly user_api_key_enabled: "Activée";
|
|
245
248
|
readonly user_api_key_hidden: "Secret masqué";
|
|
246
249
|
readonly user_api_key_name: "Nom de la clé";
|
|
250
|
+
readonly user_api_key_no_permissions: "Aucune autorisation";
|
|
251
|
+
readonly user_api_key_permissions: "Autorisations";
|
|
252
|
+
readonly user_api_key_permissions_description: "Choisissez les autorisations de projet à attribuer à cette clé API.";
|
|
247
253
|
readonly user_api_key_rate_limit: "Limite de débit";
|
|
248
254
|
readonly user_api_key_referrers: "Référents autorisés (facultatifs)";
|
|
249
255
|
readonly user_api_key_referrers_any: "Tout référent";
|
|
@@ -292,6 +298,7 @@ export type OrganizationSwitcherProps = {
|
|
|
292
298
|
onChange?: (organization: OrganizationSummary | null) => void;
|
|
293
299
|
onCreate?: (organization: OrganizationSummary) => void;
|
|
294
300
|
onDialogChange?: (dialog: OrganizationSwitcherDialog | null) => void;
|
|
301
|
+
apiKeyPermissions?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
295
302
|
};
|
|
296
303
|
type OrganizationSummary = {
|
|
297
304
|
id: string;
|
|
@@ -302,5 +309,5 @@ type OrganizationSummary = {
|
|
|
302
309
|
parentId?: string | null;
|
|
303
310
|
};
|
|
304
311
|
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
|
|
305
|
-
export declare function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side, className, defaultDialog, features, hideTrigger, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
312
|
+
export declare function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side, className, defaultDialog, features, hideTrigger, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
306
313
|
export {};
|
|
@@ -15,6 +15,7 @@ import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
|
|
|
15
15
|
import { Input } from "@/components/ui/input";
|
|
16
16
|
import { Badge } from "@/components/ui/badge";
|
|
17
17
|
import { Button } from "@/components/ui/button";
|
|
18
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
18
19
|
import { CopyButton } from "@/components/ui/copy-button";
|
|
19
20
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
20
21
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
@@ -142,6 +143,9 @@ const messages = {
|
|
|
142
143
|
user_api_key_enabled: "Enabled",
|
|
143
144
|
user_api_key_hidden: "Secret hidden",
|
|
144
145
|
user_api_key_name: "Key name",
|
|
146
|
+
user_api_key_no_permissions: "No permissions",
|
|
147
|
+
user_api_key_permissions: "Permissions",
|
|
148
|
+
user_api_key_permissions_description: "Choose the project permissions this API key should receive.",
|
|
145
149
|
user_api_key_rate_limit: "Rate limit",
|
|
146
150
|
user_api_key_referrers: "Allowed referrers (optional)",
|
|
147
151
|
user_api_key_referrers_any: "Any referrer",
|
|
@@ -275,6 +279,9 @@ const messages = {
|
|
|
275
279
|
user_api_key_enabled: "Activée",
|
|
276
280
|
user_api_key_hidden: "Secret masqué",
|
|
277
281
|
user_api_key_name: "Nom de la clé",
|
|
282
|
+
user_api_key_no_permissions: "Aucune autorisation",
|
|
283
|
+
user_api_key_permissions: "Autorisations",
|
|
284
|
+
user_api_key_permissions_description: "Choisissez les autorisations de projet à attribuer à cette clé API.",
|
|
278
285
|
user_api_key_rate_limit: "Limite de débit",
|
|
279
286
|
user_api_key_referrers: "Référents autorisés (facultatifs)",
|
|
280
287
|
user_api_key_referrers_any: "Tout référent",
|
|
@@ -809,7 +816,7 @@ const organizationMetadataFromForm = async (value, m, uploadImage, existingMetad
|
|
|
809
816
|
addresses,
|
|
810
817
|
};
|
|
811
818
|
};
|
|
812
|
-
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
819
|
+
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }) {
|
|
813
820
|
const auth = useKrakstackAuth();
|
|
814
821
|
const authClient = providedAuthClient ?? auth?.authClient;
|
|
815
822
|
if (!authClient) {
|
|
@@ -947,7 +954,9 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
947
954
|
onChange?.(null);
|
|
948
955
|
} })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
949
956
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
950
|
-
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys
|
|
957
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys, permissions: apiKeyPermissions ??
|
|
958
|
+
auth?.access?.organizationApiKeyPermissions ??
|
|
959
|
+
{} })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
|
|
951
960
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
952
961
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
953
962
|
? { activeOrganizationId: activeOrganization.data.id }
|
|
@@ -1481,7 +1490,7 @@ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
|
|
|
1481
1490
|
onClick: onCancel,
|
|
1482
1491
|
},
|
|
1483
1492
|
];
|
|
1484
|
-
function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
1493
|
+
function OrganizationApiKeyManager({ authClient, organization, active, permissions, }) {
|
|
1485
1494
|
const m = useOrganizationMessages();
|
|
1486
1495
|
const hasOpened = useOpenedOnce(active);
|
|
1487
1496
|
const keysAtom = hasOpened
|
|
@@ -1493,6 +1502,12 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1493
1502
|
const [creating, setCreating] = useState(false);
|
|
1494
1503
|
const [editingKey, setEditingKey] = useState(null);
|
|
1495
1504
|
const [error, setError] = useState(null);
|
|
1505
|
+
const permissionOptions = organizationApiKeyPermissionOptions(permissions);
|
|
1506
|
+
const [selectedPermissions, setSelectedPermissions] = useState({});
|
|
1507
|
+
const permissionOptionsRef = useRef(permissionOptions);
|
|
1508
|
+
const selectedPermissionsRef = useRef(selectedPermissions);
|
|
1509
|
+
permissionOptionsRef.current = permissionOptions;
|
|
1510
|
+
selectedPermissionsRef.current = selectedPermissions;
|
|
1496
1511
|
const keys = AsyncResult.match(keysResult, {
|
|
1497
1512
|
onInitial: () => [],
|
|
1498
1513
|
onFailure: () => [],
|
|
@@ -1513,9 +1528,11 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1513
1528
|
configId: "organization",
|
|
1514
1529
|
organizationId: organization.id,
|
|
1515
1530
|
name: value.name.trim(),
|
|
1531
|
+
permissions: organizationApiKeySelectedPermissions(permissionOptionsRef.current, selectedPermissionsRef.current),
|
|
1516
1532
|
referrers: parseApiKeyReferrers(value.referrers, m.user_api_key_referrers_error()),
|
|
1517
1533
|
}, m.user_api_key_create_error());
|
|
1518
1534
|
setCreatedKey(created.key);
|
|
1535
|
+
setSelectedPermissions({});
|
|
1519
1536
|
refreshKeys();
|
|
1520
1537
|
return created;
|
|
1521
1538
|
},
|
|
@@ -1527,6 +1544,9 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1527
1544
|
const submitApiKey = useAtomSet(createForm.submit);
|
|
1528
1545
|
const resetApiKey = useAtomSet(createForm.reset);
|
|
1529
1546
|
const createResult = useAtomValue(createForm.submit);
|
|
1547
|
+
const togglePermission = (id, checked) => {
|
|
1548
|
+
setSelectedPermissions((current) => ({ ...current, [id]: checked }));
|
|
1549
|
+
};
|
|
1530
1550
|
useEffect(() => {
|
|
1531
1551
|
if (AsyncResult.isSuccess(createResult))
|
|
1532
1552
|
resetApiKey();
|
|
@@ -1567,7 +1587,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1567
1587
|
event.preventDefault();
|
|
1568
1588
|
event.stopPropagation();
|
|
1569
1589
|
submitApiKey();
|
|
1570
|
-
}, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
|
|
1590
|
+
}, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx("p", { className: "font-medium", children: m.user_api_key_permissions() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_permissions_description() }), _jsx("div", { className: "flex flex-col gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: `organization-${permission.id}`, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsxs(FieldLabel, { htmlFor: `organization-${permission.id}`, children: [permission.resource, ": ", permission.action] })] }, permission.id))) })] })) : null, _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
|
|
1571
1591
|
copied: m.user_api_key_copied(),
|
|
1572
1592
|
copy: m.user_api_key_copy(),
|
|
1573
1593
|
}, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0 overflow-x-hidden", children: _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, features: {
|
|
@@ -1611,6 +1631,15 @@ const apiKeyColumns = ({ m, }) => [
|
|
|
1611
1631
|
? m.user_api_key_enabled()
|
|
1612
1632
|
: m.user_api_key_disabled() })),
|
|
1613
1633
|
},
|
|
1634
|
+
{
|
|
1635
|
+
id: "permissions",
|
|
1636
|
+
accessorFn: (keyData) => keyData.permissions,
|
|
1637
|
+
header: m.user_api_key_permissions(),
|
|
1638
|
+
cell: ({ row }) => {
|
|
1639
|
+
const values = organizationApiKeyFormattedPermissions(row.original.permissions);
|
|
1640
|
+
return values.length > 0 ? (_jsx("div", { className: "flex flex-wrap gap-1", children: values.map((value) => (_jsx(Badge, { variant: "outline", children: value }, value))) })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: m.user_api_key_no_permissions() }));
|
|
1641
|
+
},
|
|
1642
|
+
},
|
|
1614
1643
|
{
|
|
1615
1644
|
id: "referrers",
|
|
1616
1645
|
accessorFn: (keyData) => keyData.metadata,
|
|
@@ -1633,6 +1662,29 @@ const apiKeyColumns = ({ m, }) => [
|
|
|
1633
1662
|
} })),
|
|
1634
1663
|
},
|
|
1635
1664
|
];
|
|
1665
|
+
const organizationApiKeyPermissionOptions = (permissions) => Object.entries(permissions).flatMap(([resource, actions]) => actions.map((action) => ({
|
|
1666
|
+
id: `${resource}:${action}`,
|
|
1667
|
+
resource,
|
|
1668
|
+
action,
|
|
1669
|
+
})));
|
|
1670
|
+
const organizationApiKeySelectedPermissions = (options, selected) => {
|
|
1671
|
+
const permissions = {};
|
|
1672
|
+
for (const option of options) {
|
|
1673
|
+
if (!selected[option.id])
|
|
1674
|
+
continue;
|
|
1675
|
+
permissions[option.resource] = [
|
|
1676
|
+
...(permissions[option.resource] ?? []),
|
|
1677
|
+
option.action,
|
|
1678
|
+
];
|
|
1679
|
+
}
|
|
1680
|
+
return permissions;
|
|
1681
|
+
};
|
|
1682
|
+
const organizationApiKeyFormattedPermissions = (value) => {
|
|
1683
|
+
const decoded = Schema.decodeUnknownOption(Schema.Record(Schema.String, Schema.Array(Schema.String)))(value);
|
|
1684
|
+
return Option.isSome(decoded)
|
|
1685
|
+
? Object.entries(decoded.value).flatMap(([resource, actions]) => actions.map((action) => `${resource}:${action}`))
|
|
1686
|
+
: [];
|
|
1687
|
+
};
|
|
1636
1688
|
const apiKeyRowActions = ({ m, onDelete, onEdit, }) => [
|
|
1637
1689
|
{
|
|
1638
1690
|
name: m.user_api_key_edit_title(),
|
|
@@ -227,7 +227,7 @@ type UserDropdownProps = {
|
|
|
227
227
|
defaultDialog?: UserButtonDialog | null;
|
|
228
228
|
hideTrigger?: boolean;
|
|
229
229
|
renderUnauthenticated?: () => ReactNode;
|
|
230
|
-
apiKeyPermissions?: Record<string, string
|
|
230
|
+
apiKeyPermissions?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
231
231
|
messages?: UserButtonMessages;
|
|
232
232
|
dialog?: UserButtonDialog | null;
|
|
233
233
|
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
@@ -434,7 +434,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
434
434
|
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
435
435
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
436
436
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
437
|
-
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
437
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? auth?.access?.userApiKeyPermissions ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
438
438
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
439
439
|
}, children: _jsxs(DialogContent, { className: "flex h-[85vh] flex-col overflow-y-auto sm:max-w-6xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_button_admin_users() }), _jsx(DialogDescription, { children: m.user_button_admin_users_description() })] }), _jsx(Separator, {}), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(AdminUsersTable, {}) })] }) }), _jsx(Dialog, { open: settingsDialog === "adminOrganizations", onOpenChange: (open) => {
|
|
440
440
|
setSettingsDialog((current) => open
|
|
@@ -1,122 +1,130 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi";
|
|
2
3
|
import { ExtraBadRequest } from "./schema";
|
|
3
4
|
export * from "./schema";
|
|
4
5
|
export type { Organization, OrganizationMetadata } from "../schema";
|
|
5
|
-
export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpApiEndpoint.HttpApiEndpoint<"createApiKey", "POST", "/auth/create-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
6
|
-
readonly configId:
|
|
7
|
-
readonly name:
|
|
8
|
-
readonly organizationId:
|
|
9
|
-
readonly permissions:
|
|
10
|
-
readonly referrers:
|
|
11
|
-
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
12
|
-
readonly id:
|
|
13
|
-
readonly key:
|
|
14
|
-
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<
|
|
15
|
-
readonly organizationId:
|
|
16
|
-
readonly locale:
|
|
17
|
-
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
18
|
-
readonly id:
|
|
19
|
-
readonly name:
|
|
20
|
-
readonly slug:
|
|
21
|
-
readonly displayName:
|
|
22
|
-
readonly contactEmail:
|
|
23
|
-
readonly emails:
|
|
24
|
-
readonly email:
|
|
25
|
-
readonly translations:
|
|
26
|
-
readonly locale:
|
|
27
|
-
readonly label:
|
|
6
|
+
export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpApiEndpoint.HttpApiEndpoint<"createApiKey", "POST", "/auth/create-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
7
|
+
readonly configId: Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>;
|
|
8
|
+
readonly name: Schema.optional<Schema.NonEmptyString>;
|
|
9
|
+
readonly organizationId: Schema.optional<Schema.String>;
|
|
10
|
+
readonly permissions: Schema.optional<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
|
|
11
|
+
readonly referrers: Schema.optional<Schema.$Array<Schema.String>>;
|
|
12
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
13
|
+
readonly id: Schema.String;
|
|
14
|
+
readonly key: Schema.String;
|
|
15
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
16
|
+
readonly organizationId: Schema.String;
|
|
17
|
+
readonly locale: Schema.optional<Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>>;
|
|
18
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
19
|
+
readonly id: Schema.String;
|
|
20
|
+
readonly name: Schema.String;
|
|
21
|
+
readonly slug: Schema.String;
|
|
22
|
+
readonly displayName: Schema.String;
|
|
23
|
+
readonly contactEmail: Schema.NullOr<Schema.String>;
|
|
24
|
+
readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
25
|
+
readonly email: Schema.NonEmptyString;
|
|
26
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
27
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
28
|
+
readonly label: Schema.NonEmptyString;
|
|
28
29
|
}>>;
|
|
29
30
|
}>>>;
|
|
30
|
-
readonly phones:
|
|
31
|
-
readonly number:
|
|
32
|
-
readonly extension:
|
|
33
|
-
readonly translations:
|
|
34
|
-
readonly locale:
|
|
35
|
-
readonly label:
|
|
31
|
+
readonly phones: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
32
|
+
readonly number: Schema.NonEmptyString;
|
|
33
|
+
readonly extension: Schema.optional<Schema.String>;
|
|
34
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
35
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
36
|
+
readonly label: Schema.NonEmptyString;
|
|
36
37
|
}>>;
|
|
37
38
|
}>>>;
|
|
38
|
-
readonly websites:
|
|
39
|
-
readonly url:
|
|
40
|
-
readonly translations:
|
|
41
|
-
readonly locale:
|
|
42
|
-
readonly label:
|
|
39
|
+
readonly websites: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
40
|
+
readonly url: Schema.NonEmptyString;
|
|
41
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
42
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
43
|
+
readonly label: Schema.NonEmptyString;
|
|
43
44
|
}>>;
|
|
44
45
|
}>>>;
|
|
45
|
-
readonly socials:
|
|
46
|
-
readonly platform:
|
|
47
|
-
readonly url:
|
|
48
|
-
readonly translations:
|
|
49
|
-
readonly locale:
|
|
50
|
-
readonly label:
|
|
46
|
+
readonly socials: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
47
|
+
readonly platform: Schema.Literals<readonly ["facebook", "github", "instagram", "linkedin", "tiktok", "x", "youtube"]>;
|
|
48
|
+
readonly url: Schema.NonEmptyString;
|
|
49
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
50
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
51
|
+
readonly label: Schema.NonEmptyString;
|
|
51
52
|
}>>;
|
|
52
53
|
}>>>;
|
|
53
|
-
readonly addresses:
|
|
54
|
-
readonly streetAddress:
|
|
55
|
-
readonly locality:
|
|
56
|
-
readonly region:
|
|
57
|
-
readonly postalCode:
|
|
58
|
-
readonly country:
|
|
59
|
-
readonly translations:
|
|
60
|
-
readonly locale:
|
|
61
|
-
readonly label:
|
|
54
|
+
readonly addresses: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
55
|
+
readonly streetAddress: Schema.optional<Schema.String>;
|
|
56
|
+
readonly locality: Schema.optional<Schema.String>;
|
|
57
|
+
readonly region: Schema.optional<Schema.String>;
|
|
58
|
+
readonly postalCode: Schema.optional<Schema.String>;
|
|
59
|
+
readonly country: Schema.optional<Schema.String>;
|
|
60
|
+
readonly translations: Schema.$Array<Schema.Struct<{
|
|
61
|
+
readonly locale: Schema.Union<readonly [Schema.Literal<"en">, Schema.Literal<"fr">]>;
|
|
62
|
+
readonly label: Schema.NonEmptyString;
|
|
62
63
|
}>>;
|
|
63
|
-
readonly formatted:
|
|
64
|
+
readonly formatted: Schema.String;
|
|
64
65
|
}>>>;
|
|
65
|
-
readonly logo:
|
|
66
|
-
readonly icon:
|
|
67
|
-
}>>, HttpApiEndpoint.Json<typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<
|
|
68
|
-
readonly projectId:
|
|
69
|
-
readonly clientId:
|
|
70
|
-
readonly host:
|
|
71
|
-
readonly rootHost:
|
|
72
|
-
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
73
|
-
readonly projectKey:
|
|
74
|
-
readonly name:
|
|
75
|
-
readonly logoUrl:
|
|
76
|
-
readonly authDomain:
|
|
77
|
-
readonly rootDomain:
|
|
78
|
-
readonly themeCss:
|
|
79
|
-
readonly authOptions:
|
|
80
|
-
readonly emailPassword:
|
|
81
|
-
readonly emailOtp:
|
|
82
|
-
readonly google:
|
|
83
|
-
readonly signUp:
|
|
84
|
-
readonly signUpName:
|
|
66
|
+
readonly logo: Schema.NullOr<Schema.String>;
|
|
67
|
+
readonly icon: Schema.NullOr<Schema.String>;
|
|
68
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
69
|
+
readonly projectId: Schema.optional<Schema.String>;
|
|
70
|
+
readonly clientId: Schema.optional<Schema.String>;
|
|
71
|
+
readonly host: Schema.optional<Schema.String>;
|
|
72
|
+
readonly rootHost: Schema.optional<Schema.String>;
|
|
73
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
74
|
+
readonly projectKey: Schema.String;
|
|
75
|
+
readonly name: Schema.NullOr<Schema.String>;
|
|
76
|
+
readonly logoUrl: Schema.NullOr<Schema.String>;
|
|
77
|
+
readonly authDomain: Schema.NullOr<Schema.String>;
|
|
78
|
+
readonly rootDomain: Schema.NullOr<Schema.String>;
|
|
79
|
+
readonly themeCss: Schema.NullOr<Schema.String>;
|
|
80
|
+
readonly authOptions: Schema.Struct<{
|
|
81
|
+
readonly emailPassword: Schema.Boolean;
|
|
82
|
+
readonly emailOtp: Schema.Boolean;
|
|
83
|
+
readonly google: Schema.Boolean;
|
|
84
|
+
readonly signUp: Schema.Boolean;
|
|
85
|
+
readonly signUpName: Schema.Boolean;
|
|
85
86
|
}>;
|
|
86
|
-
}>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
87
|
-
readonly newPassword:
|
|
88
|
-
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
89
|
-
readonly ok:
|
|
90
|
-
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"
|
|
91
|
-
readonly
|
|
92
|
-
}
|
|
93
|
-
readonly
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
readonly
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
readonly
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
88
|
+
readonly newPassword: Schema.NonEmptyString;
|
|
89
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
90
|
+
readonly ok: Schema.Boolean;
|
|
91
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"updateApiKeyPermissions", "PATCH", "/auth/api-key/:keyId/permissions", HttpApiEndpoint.StringTree<Schema.Struct<{
|
|
92
|
+
readonly keyId: Schema.NonEmptyString;
|
|
93
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
94
|
+
readonly configId: Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>;
|
|
95
|
+
readonly permissions: Schema.$Record<Schema.String, Schema.$Array<Schema.String>>;
|
|
96
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
97
|
+
readonly ok: Schema.Boolean;
|
|
98
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<Schema.Struct<{
|
|
99
|
+
readonly file: Schema.decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, Schema.$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
|
|
100
|
+
}>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
101
|
+
readonly url: Schema.String;
|
|
102
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
103
|
+
readonly key: Schema.NonEmptyString;
|
|
104
|
+
readonly configId: Schema.optional<Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>>;
|
|
105
|
+
readonly permissions: Schema.optional<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
|
|
106
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
107
|
+
readonly valid: Schema.Boolean;
|
|
108
|
+
readonly error: Schema.NullOr<Schema.Struct<{
|
|
109
|
+
readonly message: Schema.String;
|
|
110
|
+
readonly code: Schema.String;
|
|
103
111
|
}>>;
|
|
104
|
-
readonly key:
|
|
105
|
-
readonly id:
|
|
106
|
-
readonly configId:
|
|
107
|
-
readonly name:
|
|
108
|
-
readonly start:
|
|
109
|
-
readonly prefix:
|
|
110
|
-
readonly referenceId:
|
|
111
|
-
readonly enabled:
|
|
112
|
-
readonly expiresAt:
|
|
113
|
-
readonly createdAt:
|
|
114
|
-
readonly updatedAt:
|
|
115
|
-
readonly permissions:
|
|
116
|
-
readonly metadata:
|
|
112
|
+
readonly key: Schema.NullOr<Schema.Struct<{
|
|
113
|
+
readonly id: Schema.String;
|
|
114
|
+
readonly configId: Schema.String;
|
|
115
|
+
readonly name: Schema.NullOr<Schema.String>;
|
|
116
|
+
readonly start: Schema.NullOr<Schema.String>;
|
|
117
|
+
readonly prefix: Schema.NullOr<Schema.String>;
|
|
118
|
+
readonly referenceId: Schema.String;
|
|
119
|
+
readonly enabled: Schema.NullOr<Schema.Boolean>;
|
|
120
|
+
readonly expiresAt: Schema.NullOr<Schema.Date>;
|
|
121
|
+
readonly createdAt: Schema.Date;
|
|
122
|
+
readonly updatedAt: Schema.Date;
|
|
123
|
+
readonly permissions: Schema.NullOr<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
|
|
124
|
+
readonly metadata: Schema.NullOr<Schema.Unknown>;
|
|
117
125
|
}>>;
|
|
118
|
-
}>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyPassword", "POST", "/auth/verify-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
119
|
-
readonly password:
|
|
120
|
-
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<
|
|
121
|
-
readonly ok:
|
|
126
|
+
}>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyPassword", "POST", "/auth/verify-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
127
|
+
readonly password: Schema.NonEmptyString;
|
|
128
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<Schema.Struct<{
|
|
129
|
+
readonly ok: Schema.Boolean;
|
|
122
130
|
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never>, false>;
|
package/dist/extra/api.group.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
1
2
|
import { OpenApi } from "effect/unstable/httpapi";
|
|
2
3
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
|
|
3
|
-
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
|
|
4
|
+
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUpdateApiKeyPermissionsPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
|
|
4
5
|
export * from "./schema";
|
|
5
6
|
export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
6
7
|
.add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
|
|
@@ -11,6 +12,24 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
11
12
|
title: "Get project public config",
|
|
12
13
|
summary: "Get host-aware project white-label config",
|
|
13
14
|
description: "Returns resolved public branding and authentication options through the proxied auth API.",
|
|
15
|
+
})))
|
|
16
|
+
.add(HttpApiEndpoint.patch("updateApiKeyPermissions", "/auth/api-key/:keyId/permissions", {
|
|
17
|
+
params: Schema.Struct({ keyId: Schema.NonEmptyString }),
|
|
18
|
+
payload: Schema.Struct({
|
|
19
|
+
configId: ExtraUpdateApiKeyPermissionsPayload.fields.configId,
|
|
20
|
+
permissions: ExtraUpdateApiKeyPermissionsPayload.fields.permissions,
|
|
21
|
+
}),
|
|
22
|
+
success: ExtraOkResponse,
|
|
23
|
+
error: [
|
|
24
|
+
ExtraBadRequest,
|
|
25
|
+
HttpApiError.Unauthorized,
|
|
26
|
+
HttpApiError.Forbidden,
|
|
27
|
+
HttpApiError.InternalServerError,
|
|
28
|
+
],
|
|
29
|
+
}).annotateMerge(OpenApi.annotations({
|
|
30
|
+
title: "Update API key permissions",
|
|
31
|
+
summary: "Replace an API key's permissions",
|
|
32
|
+
description: "Updates server-only API key permissions after Better Auth verifies user ownership or organization key-management access.",
|
|
14
33
|
})))
|
|
15
34
|
.add(HttpApiEndpoint.get("getOrganizationPublicProfile", "/auth/organization-profile", {
|
|
16
35
|
query: ExtraOrganizationPublicProfileQuery,
|
package/dist/extra/schema.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export declare const ExtraCreateApiKeyResponse: Schema.Struct<{
|
|
|
26
26
|
readonly id: Schema.String;
|
|
27
27
|
readonly key: Schema.String;
|
|
28
28
|
}>;
|
|
29
|
+
export declare const ExtraUpdateApiKeyPermissionsPayload: Schema.Struct<{
|
|
30
|
+
readonly configId: Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>;
|
|
31
|
+
readonly keyId: Schema.NonEmptyString;
|
|
32
|
+
readonly permissions: Schema.$Record<Schema.String, Schema.$Array<Schema.String>>;
|
|
33
|
+
}>;
|
|
29
34
|
export declare const ExtraVerifyApiKeyPayload: Schema.Struct<{
|
|
30
35
|
readonly key: Schema.NonEmptyString;
|
|
31
36
|
readonly configId: Schema.optional<Schema.Union<readonly [Schema.Literal<"user">, Schema.Literal<"organization">, Schema.Literal<"service">]>>;
|
|
@@ -171,6 +176,7 @@ export type ExtraSetPasswordPayload = typeof ExtraSetPasswordPayload.Type;
|
|
|
171
176
|
export type ExtraVerifyPasswordPayload = typeof ExtraVerifyPasswordPayload.Type;
|
|
172
177
|
export type ExtraCreateApiKeyPayload = typeof ExtraCreateApiKeyPayload.Type;
|
|
173
178
|
export type ExtraCreateApiKeyResponse = typeof ExtraCreateApiKeyResponse.Type;
|
|
179
|
+
export type ExtraUpdateApiKeyPermissionsPayload = typeof ExtraUpdateApiKeyPermissionsPayload.Type;
|
|
174
180
|
export type ExtraVerifyApiKeyPayload = typeof ExtraVerifyApiKeyPayload.Type;
|
|
175
181
|
export type ExtraVerifyApiKeyResponse = typeof ExtraVerifyApiKeyResponse.Type;
|
|
176
182
|
export type ExtraProjectPublicConfigQuery = typeof ExtraProjectPublicConfigQuery.Type;
|
package/dist/extra/schema.js
CHANGED
|
@@ -70,6 +70,22 @@ export const ExtraCreateApiKeyResponse = Schema.Struct({
|
|
|
70
70
|
description: "Response returned after creating an API key. The secret key is only returned once.",
|
|
71
71
|
examples: [{ id: "api-key-id", key: "user_1234567890" }],
|
|
72
72
|
});
|
|
73
|
+
export const ExtraUpdateApiKeyPermissionsPayload = Schema.Struct({
|
|
74
|
+
configId: ExtraApiKeyConfigId,
|
|
75
|
+
keyId: Schema.NonEmptyString,
|
|
76
|
+
permissions: ExtraApiKeyPermissions,
|
|
77
|
+
}).annotate({
|
|
78
|
+
identifier: "ExtraUpdateApiKeyPermissionsPayload",
|
|
79
|
+
title: "Extra update API key permissions payload",
|
|
80
|
+
description: "Server-authorized replacement permissions for an existing API key.",
|
|
81
|
+
examples: [
|
|
82
|
+
{
|
|
83
|
+
configId: "organization",
|
|
84
|
+
keyId: "api-key-id",
|
|
85
|
+
permissions: { "211-search": ["search:execute"] },
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
});
|
|
73
89
|
export const ExtraVerifyApiKeyPayload = Schema.Struct({
|
|
74
90
|
key: Schema.NonEmptyString,
|
|
75
91
|
configId: Schema.optional(ExtraApiKeyConfigId),
|
package/dist/server/index.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middl
|
|
|
7
7
|
export type { AuthenticationLiveOptions } from "./middleware";
|
|
8
8
|
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
|
|
9
9
|
export type { Member, Organization, OrganizationMetadata, User, } from "../schema";
|
|
10
|
+
export { ApiKeyPermissionGrant, CurrentPrincipal, Forbidden, all, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
|
11
|
+
export type { ApiKeyOwner, ApiKeyPrincipal, Policy, Principal, ProjectAccessConfig, ProjectAccessCatalog, ProjectAccessDefinition, UserPrincipal, } from "../access";
|
package/dist/server/index.js
CHANGED
|
@@ -4,3 +4,4 @@ export { ServerDomainsApiGroup, ServerOrganizationsApiGroup, ServerUsersApiGroup
|
|
|
4
4
|
export { proxyAuthRequest } from "./proxy";
|
|
5
5
|
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware";
|
|
6
6
|
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema";
|
|
7
|
+
export { ApiKeyPermissionGrant, CurrentPrincipal, Forbidden, all, any, defineProjectAccess, permission, policy, withPolicy, } from "../access";
|
package/dist/service.d.ts
CHANGED
|
@@ -206,6 +206,18 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
206
206
|
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
207
207
|
readonly ok: import("effect/Schema").Boolean;
|
|
208
208
|
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
209
|
+
readonly updateApiKeyPermissions: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
210
|
+
readonly params: import("effect/Schema").Struct.ReadonlySide<{
|
|
211
|
+
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
212
|
+
}, "Type">;
|
|
213
|
+
readonly payload: import("effect/Schema").Struct.ReadonlySide<{
|
|
214
|
+
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
215
|
+
readonly permissions: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
216
|
+
}, "Type">;
|
|
217
|
+
readonly responseMode?: Mode;
|
|
218
|
+
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
219
|
+
readonly ok: import("effect/Schema").Boolean;
|
|
220
|
+
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
209
221
|
readonly uploadUserImage: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
210
222
|
readonly payload: FormData;
|
|
211
223
|
readonly responseMode?: Mode;
|
|
@@ -824,6 +836,18 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
824
836
|
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
825
837
|
readonly ok: import("effect/Schema").Boolean;
|
|
826
838
|
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
839
|
+
readonly updateApiKeyPermissions: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
840
|
+
readonly params: import("effect/Schema").Struct.ReadonlySide<{
|
|
841
|
+
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
842
|
+
}, "Type">;
|
|
843
|
+
readonly payload: import("effect/Schema").Struct.ReadonlySide<{
|
|
844
|
+
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
845
|
+
readonly permissions: import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
846
|
+
}, "Type">;
|
|
847
|
+
readonly responseMode?: Mode;
|
|
848
|
+
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
849
|
+
readonly ok: import("effect/Schema").Boolean;
|
|
850
|
+
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
827
851
|
readonly uploadUserImage: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
828
852
|
readonly payload: FormData;
|
|
829
853
|
readonly responseMode?: Mode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.59",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"types": "./dist/roles.d.ts",
|
|
35
35
|
"default": "./dist/roles.js"
|
|
36
36
|
},
|
|
37
|
+
"./access": {
|
|
38
|
+
"types": "./dist/access.d.ts",
|
|
39
|
+
"default": "./dist/access.js"
|
|
40
|
+
},
|
|
37
41
|
"./components": {
|
|
38
42
|
"types": "./dist/components/index.d.ts",
|
|
39
43
|
"default": "./dist/components/index.js"
|