@krak-stack/auth 0.1.59 → 0.1.61
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 +53 -28
- package/dist/access.js +34 -19
- package/dist/api.d.ts +10 -6
- package/dist/components/api-key-edit-form.d.ts +6 -3
- package/dist/components/api-key-edit-form.js +44 -11
- package/dist/components/api-key-permissions.d.ts +10 -0
- package/dist/components/api-key-permissions.js +45 -0
- package/dist/components/api-key.d.ts +6 -1
- package/dist/components/api-key.js +21 -1
- package/dist/components/auth-client-api.d.ts +5 -3
- package/dist/components/auth-provider.d.ts +4 -2
- package/dist/components/auth-provider.js +3 -1
- package/dist/components/has-permission.d.ts +6 -0
- package/dist/components/has-permission.js +4 -0
- package/dist/components/index.d.ts +5 -2
- package/dist/components/index.js +3 -1
- package/dist/components/organization-switcher.d.ts +2 -2
- package/dist/components/organization-switcher.js +13 -11
- package/dist/components/project-access-matrix.d.ts +28 -0
- package/dist/components/project-access-matrix.js +92 -0
- package/dist/components/user-button.d.ts +2 -2
- package/dist/components/user-button.js +9 -8
- package/dist/extra/api.group.d.ts +5 -3
- package/dist/extra/api.group.js +10 -7
- package/dist/extra/schema.d.ts +6 -4
- package/dist/extra/schema.js +12 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server/actor.d.ts +95 -0
- package/dist/server/actor.js +127 -0
- package/dist/server/index.d.ts +4 -2
- package/dist/server/index.js +2 -1
- package/dist/service.d.ts +21 -17
- package/dist/service.js +5 -2
- package/package.json +5 -1
package/dist/access.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Effect, Schema } from "effect";
|
|
2
2
|
export declare const ApiKeyPermissionGrant: Schema.$Record<Schema.String, Schema.$Array<Schema.String>>;
|
|
3
3
|
export type ApiKeyPermissionGrant = typeof ApiKeyPermissionGrant.Type;
|
|
4
|
-
export type
|
|
4
|
+
export type UserActor = {
|
|
5
5
|
readonly type: "user";
|
|
6
6
|
readonly userId: string;
|
|
7
7
|
readonly organizationId: string | null;
|
|
@@ -19,29 +19,30 @@ export type ApiKeyOwner = {
|
|
|
19
19
|
readonly type: "service";
|
|
20
20
|
readonly serviceId: string;
|
|
21
21
|
};
|
|
22
|
-
export type
|
|
22
|
+
export type ApiKeyActor = {
|
|
23
23
|
readonly type: "apiKey";
|
|
24
24
|
readonly apiKeyId: string;
|
|
25
25
|
readonly owner: ApiKeyOwner;
|
|
26
26
|
};
|
|
27
|
-
export type
|
|
28
|
-
export type
|
|
29
|
-
readonly
|
|
27
|
+
export type Actor = UserActor | ApiKeyActor;
|
|
28
|
+
export type CurrentActor = {
|
|
29
|
+
readonly actor: Actor;
|
|
30
30
|
readonly organizationId: string | null;
|
|
31
31
|
readonly permissions: ReadonlySet<string>;
|
|
32
32
|
};
|
|
33
|
-
export declare const
|
|
33
|
+
export declare const CurrentActor: Context.Service<CurrentActor, CurrentActor>;
|
|
34
34
|
declare const Forbidden_base: Schema.Class<Forbidden, Schema.Struct<{
|
|
35
35
|
readonly _tag: Schema.tag<"Forbidden">;
|
|
36
36
|
}>, import("effect/Cause").YieldableError>;
|
|
37
37
|
export declare class Forbidden extends Forbidden_base {
|
|
38
38
|
}
|
|
39
|
-
export type Policy<E = never, R = never> = Effect.Effect<void, Forbidden | E,
|
|
40
|
-
export declare const policy: <E, R>(predicate: (
|
|
39
|
+
export type Policy<E = never, R = never> = Effect.Effect<void, Forbidden | E, CurrentActor | R>;
|
|
40
|
+
export declare const policy: <E, R>(predicate: (actor: CurrentActor) => Effect.Effect<boolean, E, R>) => Policy<E, R>;
|
|
41
41
|
export declare const permission: (requiredPermission: string) => Policy;
|
|
42
|
+
export declare const actorUserId: Effect.Effect<string, Forbidden, CurrentActor>;
|
|
42
43
|
export declare const all: <E, R>(...policies: readonly [Policy<E, R>, ...Array<Policy<E, R>>]) => Policy<E, R>;
|
|
43
44
|
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:
|
|
45
|
+
export declare const withPolicy: <E, R>(accessPolicy: Effect.Effect<void, E, R>) => <A, E2, R2>(self: Effect.Effect<A, E2, R2>) => Effect.Effect<A, E | E2, R | R2>;
|
|
45
46
|
type ProjectPermission<Project extends string, Action extends string> = `${Project}:${Action}`;
|
|
46
47
|
export type ProjectAccessDefinition<Project extends string = string, Action extends string = string> = {
|
|
47
48
|
readonly project: Project;
|
|
@@ -50,44 +51,68 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
50
51
|
readonly apiKeys: {
|
|
51
52
|
readonly user: ReadonlyArray<Action>;
|
|
52
53
|
readonly organization: ReadonlyArray<Action>;
|
|
54
|
+
readonly service: ReadonlyArray<Action>;
|
|
53
55
|
};
|
|
54
56
|
readonly qualify: (action: Action) => ProjectPermission<Project, Action>;
|
|
55
57
|
readonly permission: (action: Action) => Policy;
|
|
56
58
|
readonly permissionsForRoles: (roles: unknown) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
57
|
-
readonly permissionsForGrant: (grant: ApiKeyPermissionGrant) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
59
|
+
readonly permissionsForGrant: (grant: ApiKeyPermissionGrant | null | undefined) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
58
60
|
readonly permissionsForUserKey: (input: {
|
|
59
|
-
readonly grant: ApiKeyPermissionGrant;
|
|
61
|
+
readonly grant: ApiKeyPermissionGrant | null | undefined;
|
|
60
62
|
readonly roles: unknown;
|
|
61
63
|
}) => ReadonlySet<ProjectPermission<Project, Action>>;
|
|
62
64
|
readonly decodeGrant: (input: unknown) => Effect.Effect<ReadonlySet<ProjectPermission<Project, Action>>, Schema.SchemaError>;
|
|
63
65
|
readonly encodeGrant: (actions: ReadonlyArray<Action>) => ApiKeyPermissionGrant;
|
|
64
|
-
readonly
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
readonly apiKeyPermissions: {
|
|
67
|
+
readonly user: ApiKeyPermissionGrant;
|
|
68
|
+
readonly organization: ApiKeyPermissionGrant;
|
|
69
|
+
readonly service: ApiKeyPermissionGrant;
|
|
70
|
+
};
|
|
71
|
+
readonly actorForUser: (input: {
|
|
67
72
|
readonly userId: string;
|
|
68
73
|
readonly organizationId: string | null;
|
|
69
74
|
readonly roles: unknown;
|
|
70
|
-
}) =>
|
|
71
|
-
readonly
|
|
75
|
+
}) => CurrentActor;
|
|
76
|
+
readonly actorForApiKey: (input: {
|
|
72
77
|
readonly apiKeyId: string;
|
|
73
78
|
readonly owner: ApiKeyOwner;
|
|
74
|
-
readonly grant: ApiKeyPermissionGrant;
|
|
75
|
-
}) =>
|
|
79
|
+
readonly grant: ApiKeyPermissionGrant | null | undefined;
|
|
80
|
+
}) => CurrentActor;
|
|
81
|
+
};
|
|
82
|
+
export type ProjectAccessCatalog = Pick<ProjectAccessDefinition, "project" | "roles" | "apiKeyPermissions">;
|
|
83
|
+
export type ProjectAccessLabelCatalog = {
|
|
84
|
+
readonly project: string;
|
|
85
|
+
readonly roles: Readonly<Record<string, string | undefined>>;
|
|
86
|
+
readonly permissions: Readonly<Record<string, {
|
|
87
|
+
readonly label: string;
|
|
88
|
+
readonly actions: Readonly<Record<string, string>>;
|
|
89
|
+
}>>;
|
|
76
90
|
};
|
|
77
|
-
|
|
91
|
+
type PermissionResource<Action extends string> = Action extends `${infer Resource}:${string}` ? Resource : Action;
|
|
92
|
+
type PermissionAction<Action extends string, Resource extends string> = Action extends `${Resource}:${infer Value}` ? Value : never;
|
|
93
|
+
export type ProjectAccessLabels<Action extends string = string, Role extends string = string> = {
|
|
78
94
|
readonly project: string;
|
|
79
|
-
readonly roles: Readonly<Record<
|
|
80
|
-
readonly
|
|
81
|
-
|
|
95
|
+
readonly roles: Readonly<Partial<Record<Role, string>>>;
|
|
96
|
+
readonly permissions: {
|
|
97
|
+
readonly [Resource in PermissionResource<Action>]: {
|
|
98
|
+
readonly label: string;
|
|
99
|
+
readonly actions: Readonly<Record<PermissionAction<Action, Resource>, string>>;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
82
102
|
};
|
|
83
|
-
export type ProjectAccessConfig<Project extends string,
|
|
103
|
+
export type ProjectAccessConfig<Project extends string, Permissions extends ReadonlyArray<string>> = {
|
|
84
104
|
readonly project: Project;
|
|
85
|
-
readonly permissions:
|
|
86
|
-
readonly roles: Readonly<Record<string, ReadonlyArray<
|
|
105
|
+
readonly permissions: Permissions;
|
|
106
|
+
readonly roles: Readonly<Record<string, ReadonlyArray<Permissions[number]> | undefined>>;
|
|
87
107
|
readonly apiKeys?: {
|
|
88
|
-
readonly user?: ReadonlyArray<
|
|
89
|
-
readonly organization?: ReadonlyArray<
|
|
108
|
+
readonly user?: ReadonlyArray<Permissions[number]>;
|
|
109
|
+
readonly organization?: ReadonlyArray<Permissions[number]>;
|
|
110
|
+
readonly service?: ReadonlyArray<Permissions[number]>;
|
|
90
111
|
};
|
|
91
112
|
};
|
|
92
|
-
export declare const defineProjectAccess: <const Project extends string, const
|
|
113
|
+
export declare const defineProjectAccess: <const Project extends string, const Permissions extends ReadonlyArray<string>>(config: ProjectAccessConfig<Project, Permissions>) => ProjectAccessDefinition<Project, Permissions[number]>;
|
|
114
|
+
export declare const defineProjectAccessLabels: <const Action extends string, const Role extends string>(_access: {
|
|
115
|
+
readonly actions: ReadonlyArray<Action>;
|
|
116
|
+
readonly roles: Readonly<Record<Role, ReadonlyArray<Action> | undefined>>;
|
|
117
|
+
}, labels: ProjectAccessLabels<Action, Role>) => ProjectAccessLabels<Action, Role>;
|
|
93
118
|
export {};
|
package/dist/access.js
CHANGED
|
@@ -5,18 +5,25 @@ export const ApiKeyPermissionGrant = Schema.Record(Schema.String, Schema.Array(S
|
|
|
5
5
|
title: "API key permission grant",
|
|
6
6
|
description: "Better Auth resource and action permissions assigned to a key.",
|
|
7
7
|
});
|
|
8
|
-
export const
|
|
8
|
+
export const CurrentActor = Context.Service("@krak-stack/auth/CurrentActor");
|
|
9
9
|
export class Forbidden extends Schema.ErrorClass("Forbidden")({
|
|
10
10
|
_tag: Schema.tag("Forbidden"),
|
|
11
11
|
}, {
|
|
12
12
|
identifier: "Forbidden",
|
|
13
13
|
title: "Forbidden",
|
|
14
|
-
description: "The authenticated
|
|
14
|
+
description: "The authenticated actor lacks a required permission.",
|
|
15
15
|
httpApiStatus: 403,
|
|
16
16
|
}) {
|
|
17
17
|
}
|
|
18
|
-
export const policy = (predicate) => Effect.flatMap(
|
|
19
|
-
export const permission = (requiredPermission) => policy((
|
|
18
|
+
export const policy = (predicate) => Effect.flatMap(CurrentActor, (actor) => Effect.flatMap(predicate(actor), (allowed) => allowed ? Effect.void : Effect.fail(new Forbidden())));
|
|
19
|
+
export const permission = (requiredPermission) => policy((actor) => Effect.succeed(actor.permissions.has(requiredPermission)));
|
|
20
|
+
export const actorUserId = CurrentActor.pipe(Effect.flatMap(({ actor }) => {
|
|
21
|
+
if (actor.type === "user")
|
|
22
|
+
return Effect.succeed(actor.userId);
|
|
23
|
+
if (actor.owner.type === "user")
|
|
24
|
+
return Effect.succeed(actor.owner.userId);
|
|
25
|
+
return Effect.fail(new Forbidden());
|
|
26
|
+
}));
|
|
20
27
|
export const all = (...policies) => Effect.all(policies, { concurrency: 1, discard: true });
|
|
21
28
|
export const any = (...policies) => Effect.firstSuccessOf(policies);
|
|
22
29
|
export const withPolicy = (accessPolicy) => (self) => Effect.andThen(accessPolicy, self);
|
|
@@ -31,24 +38,27 @@ export const defineProjectAccess = (config) => {
|
|
|
31
38
|
const permissionsForRoles = (input) => {
|
|
32
39
|
const actions = new Set();
|
|
33
40
|
for (const role of roleList(input)) {
|
|
34
|
-
for (const action of config.roles[role] ?? [])
|
|
35
|
-
|
|
41
|
+
for (const action of config.roles[role] ?? []) {
|
|
42
|
+
if (allowedActions.has(action))
|
|
43
|
+
actions.add(action);
|
|
44
|
+
}
|
|
36
45
|
}
|
|
37
46
|
return permissionsForActions(actions);
|
|
38
47
|
};
|
|
39
48
|
const permissionsForGrant = (grant) => {
|
|
40
|
-
const actions = (grant[config.project] ?? []).filter((action) => allowedActions.has(action));
|
|
49
|
+
const actions = (grant?.[config.project] ?? []).filter((action) => allowedActions.has(action));
|
|
41
50
|
return permissionsForActions(actions);
|
|
42
51
|
};
|
|
43
52
|
const encodeGrant = (actions) => ({
|
|
44
53
|
[config.project]: actions.filter((action) => allowedActions.has(action)),
|
|
45
54
|
});
|
|
46
|
-
const userApiKeyActions = config.apiKeys?.user ?? [];
|
|
47
|
-
const organizationApiKeyActions = config.apiKeys?.organization ?? [];
|
|
48
|
-
const
|
|
55
|
+
const userApiKeyActions = (config.apiKeys?.user ?? []).filter((action) => allowedActions.has(action));
|
|
56
|
+
const organizationApiKeyActions = (config.apiKeys?.organization ?? []).filter((action) => allowedActions.has(action));
|
|
57
|
+
const serviceApiKeyActions = (config.apiKeys?.service ?? []).filter((action) => allowedActions.has(action));
|
|
58
|
+
const actorForUser = (input) => {
|
|
49
59
|
const roles = roleList(input.roles);
|
|
50
60
|
return {
|
|
51
|
-
|
|
61
|
+
actor: {
|
|
52
62
|
type: "user",
|
|
53
63
|
userId: input.userId,
|
|
54
64
|
organizationId: input.organizationId,
|
|
@@ -58,7 +68,7 @@ export const defineProjectAccess = (config) => {
|
|
|
58
68
|
permissions: permissionsForRoles(roles),
|
|
59
69
|
};
|
|
60
70
|
};
|
|
61
|
-
const
|
|
71
|
+
const actorForApiKey = (input) => {
|
|
62
72
|
const keyPermissions = permissionsForGrant(input.grant);
|
|
63
73
|
const permissions = (() => {
|
|
64
74
|
switch (input.owner.type) {
|
|
@@ -67,12 +77,12 @@ export const defineProjectAccess = (config) => {
|
|
|
67
77
|
case "organization":
|
|
68
78
|
return intersection(permissionsForActions(organizationApiKeyActions), keyPermissions);
|
|
69
79
|
case "service":
|
|
70
|
-
return keyPermissions;
|
|
80
|
+
return intersection(permissionsForActions(serviceApiKeyActions), keyPermissions);
|
|
71
81
|
}
|
|
72
82
|
})();
|
|
73
83
|
const organizationId = input.owner.type === "service" ? null : input.owner.organizationId;
|
|
74
84
|
return {
|
|
75
|
-
|
|
85
|
+
actor: {
|
|
76
86
|
type: "apiKey",
|
|
77
87
|
apiKeyId: input.apiKeyId,
|
|
78
88
|
owner: input.owner,
|
|
@@ -88,17 +98,22 @@ export const defineProjectAccess = (config) => {
|
|
|
88
98
|
apiKeys: {
|
|
89
99
|
user: userApiKeyActions,
|
|
90
100
|
organization: organizationApiKeyActions,
|
|
101
|
+
service: serviceApiKeyActions,
|
|
91
102
|
},
|
|
92
103
|
qualify,
|
|
93
104
|
permission: (action) => permission(qualify(action)),
|
|
94
105
|
permissionsForRoles,
|
|
95
106
|
permissionsForGrant,
|
|
96
|
-
permissionsForUserKey: ({ grant, roles }) => intersection(permissionsForRoles(roles), permissionsForGrant(grant)),
|
|
107
|
+
permissionsForUserKey: ({ grant, roles }) => intersection(intersection(permissionsForRoles(roles), permissionsForActions(userApiKeyActions)), permissionsForGrant(grant)),
|
|
97
108
|
decodeGrant: (input) => Schema.decodeUnknownEffect(ApiKeyPermissionGrant)(input).pipe(Effect.map(permissionsForGrant)),
|
|
98
109
|
encodeGrant,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
apiKeyPermissions: {
|
|
111
|
+
user: encodeGrant(userApiKeyActions),
|
|
112
|
+
organization: encodeGrant(organizationApiKeyActions),
|
|
113
|
+
service: encodeGrant(serviceApiKeyActions),
|
|
114
|
+
},
|
|
115
|
+
actorForUser,
|
|
116
|
+
actorForApiKey,
|
|
103
117
|
};
|
|
104
118
|
};
|
|
119
|
+
export const defineProjectAccessLabels = (_access, labels) => labels;
|
package/dist/api.d.ts
CHANGED
|
@@ -141,11 +141,14 @@ 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<"
|
|
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<"updateApiKey", "PATCH", "/api/auth/api-key/:keyId", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
145
145
|
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
146
146
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
147
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
|
|
148
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
149
|
+
readonly enabled: import("effect/Schema").Boolean;
|
|
150
|
+
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
151
|
+
readonly referrers: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
149
152
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
150
153
|
readonly ok: import("effect/Schema").Boolean;
|
|
151
154
|
}>>, 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<{
|
|
@@ -155,7 +158,6 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
|
|
|
155
158
|
}>>, 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<"verifyApiKey", "POST", "/api/auth/verify-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
156
159
|
readonly key: import("effect/Schema").NonEmptyString;
|
|
157
160
|
readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
|
|
158
|
-
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
159
161
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
160
162
|
readonly valid: import("effect/Schema").Boolean;
|
|
161
163
|
readonly error: import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
@@ -1044,11 +1046,14 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
1044
1046
|
readonly newPassword: import("effect/Schema").NonEmptyString;
|
|
1045
1047
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1046
1048
|
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<"
|
|
1049
|
+
}>>, 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<"updateApiKey", "PATCH", "/api/auth/api-key/:keyId", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
1048
1050
|
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
1049
1051
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1050
1052
|
readonly configId: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>;
|
|
1051
|
-
readonly
|
|
1053
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
1054
|
+
readonly enabled: import("effect/Schema").Boolean;
|
|
1055
|
+
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
1056
|
+
readonly referrers: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
1052
1057
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1053
1058
|
readonly ok: import("effect/Schema").Boolean;
|
|
1054
1059
|
}>>, 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<{
|
|
@@ -1058,7 +1063,6 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
1058
1063
|
}>>, 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<"verifyApiKey", "POST", "/api/auth/verify-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1059
1064
|
readonly key: import("effect/Schema").NonEmptyString;
|
|
1060
1065
|
readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
|
|
1061
|
-
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
1062
1066
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
1063
1067
|
readonly valid: import("effect/Schema").Boolean;
|
|
1064
1068
|
readonly error: import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ApiKey } from "@better-auth/api-key/client";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProjectAccessLabelCatalog } from "../access";
|
|
3
3
|
type ApiKeySummary = Omit<ApiKey, "key">;
|
|
4
4
|
export type ApiKeyEditMessages = {
|
|
5
5
|
enabled: string;
|
|
@@ -8,13 +8,16 @@ export type ApiKeyEditMessages = {
|
|
|
8
8
|
referrersDescription: string;
|
|
9
9
|
referrersError: string;
|
|
10
10
|
referrersPlaceholder: string;
|
|
11
|
+
permissions: string;
|
|
12
|
+
permissionsDescription: string;
|
|
11
13
|
updateError: string;
|
|
12
14
|
};
|
|
13
|
-
export declare const ApiKeyEditForm: ({
|
|
14
|
-
authClient: AuthUiClient;
|
|
15
|
+
export declare const ApiKeyEditForm: ({ configId, keyData, messages, permissions, permissionLabels, onSaved, }: {
|
|
15
16
|
configId: "organization" | "user";
|
|
16
17
|
keyData: ApiKeySummary;
|
|
17
18
|
messages: ApiKeyEditMessages;
|
|
19
|
+
permissions: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
20
|
+
permissionLabels?: ProjectAccessLabelCatalog | undefined;
|
|
18
21
|
onSaved: () => void;
|
|
19
22
|
}) => import("react").JSX.Element;
|
|
20
23
|
export {};
|
|
@@ -2,15 +2,35 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
4
|
import { Effect, Schema } from "effect";
|
|
5
|
-
import { useState } from "react";
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
6
|
import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@/components/ui/effect-form";
|
|
7
|
-
import { parseApiKeyReferrers } from "./api-key";
|
|
8
|
-
import {
|
|
7
|
+
import { parseApiKeyReferrers, updateApiKey } from "./api-key";
|
|
8
|
+
import { ApiKeyPermissions } from "./api-key-permissions";
|
|
9
|
+
import { apiKeyReferrers } from "./api-key-referrers";
|
|
10
|
+
import { ExtraApiKeyPermissions } from "../extra/schema";
|
|
9
11
|
const editApiKeyFormBuilder = FormBuilder.empty
|
|
10
12
|
.addField("name", Schema.NonEmptyString)
|
|
11
13
|
.addField("enabled", Schema.Boolean)
|
|
12
14
|
.addField("referrers", Schema.String);
|
|
13
|
-
export const ApiKeyEditForm = ({
|
|
15
|
+
export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permissionLabels, onSaved, }) => {
|
|
16
|
+
const permissionOptions = Object.entries(permissions).flatMap(([project, actions]) => actions.map((action) => ({
|
|
17
|
+
id: `${project}:${action}`,
|
|
18
|
+
project,
|
|
19
|
+
action,
|
|
20
|
+
})));
|
|
21
|
+
const currentPermissions = Schema.decodeUnknownOption(ExtraApiKeyPermissions)(keyData.permissions ?? {});
|
|
22
|
+
const currentGrant = currentPermissions._tag === "Some" ? currentPermissions.value : {};
|
|
23
|
+
const initialSelectedPermissions = Object.fromEntries(permissionOptions.map((option) => [
|
|
24
|
+
option.id,
|
|
25
|
+
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
26
|
+
]));
|
|
27
|
+
const [selectedPermissions, setSelectedPermissions] = useState(initialSelectedPermissions);
|
|
28
|
+
const selectedPermissionsRef = useRef(selectedPermissions);
|
|
29
|
+
const permissionOptionsRef = useRef(permissionOptions);
|
|
30
|
+
const permissionsRef = useRef(permissions);
|
|
31
|
+
selectedPermissionsRef.current = selectedPermissions;
|
|
32
|
+
permissionOptionsRef.current = permissionOptions;
|
|
33
|
+
permissionsRef.current = permissions;
|
|
14
34
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
15
35
|
fields: {
|
|
16
36
|
name: TextField,
|
|
@@ -21,16 +41,26 @@ export const ApiKeyEditForm = ({ authClient, configId, keyData, messages, onSave
|
|
|
21
41
|
onSubmit: (_, { decoded }) => Effect.tryPromise({
|
|
22
42
|
try: async () => {
|
|
23
43
|
const referrers = parseApiKeyReferrers(decoded.referrers, messages.referrersError);
|
|
24
|
-
const
|
|
44
|
+
const selectedGrant = {};
|
|
45
|
+
for (const project of Object.keys(permissionsRef.current)) {
|
|
46
|
+
selectedGrant[project] = [];
|
|
47
|
+
}
|
|
48
|
+
for (const option of permissionOptionsRef.current) {
|
|
49
|
+
if (!selectedPermissionsRef.current[option.id])
|
|
50
|
+
continue;
|
|
51
|
+
selectedGrant[option.project] = [
|
|
52
|
+
...(selectedGrant[option.project] ?? []),
|
|
53
|
+
option.action,
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
await updateApiKey({
|
|
25
57
|
configId,
|
|
26
58
|
keyId: keyData.id,
|
|
27
59
|
name: decoded.name.trim(),
|
|
28
60
|
enabled: decoded.enabled,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new Error(result.error.message ?? messages.updateError);
|
|
33
|
-
}
|
|
61
|
+
permissions: selectedGrant,
|
|
62
|
+
referrers,
|
|
63
|
+
}, messages.updateError);
|
|
34
64
|
onSaved();
|
|
35
65
|
},
|
|
36
66
|
catch: (cause) => cause instanceof Error ? cause : new Error(messages.updateError),
|
|
@@ -46,5 +76,8 @@ export const ApiKeyEditForm = ({ authClient, configId, keyData, messages, onSave
|
|
|
46
76
|
event.preventDefault();
|
|
47
77
|
event.stopPropagation();
|
|
48
78
|
submit();
|
|
49
|
-
}, children: [_jsx(form.name, { label: messages.name, required: true }), _jsx(form.enabled, { label: messages.enabled }), _jsx(form.referrers, { label: messages.referrers, description: messages.referrersDescription, placeholder: messages.referrersPlaceholder, rows: 3 }), _jsx(
|
|
79
|
+
}, children: [_jsx(form.name, { label: messages.name, required: true }), _jsx(form.enabled, { label: messages.enabled }), _jsx(form.referrers, { label: messages.referrers, description: messages.referrersDescription, placeholder: messages.referrersPlaceholder, rows: 3 }), _jsx(ApiKeyPermissions, { description: messages.permissionsDescription, idPrefix: "edit", permissions: permissions, labels: permissionLabels, selected: selectedPermissions, title: messages.permissions, onChange: (id, checked) => setSelectedPermissions((current) => ({
|
|
80
|
+
...current,
|
|
81
|
+
[id]: checked,
|
|
82
|
+
})) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
50
83
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProjectAccessLabelCatalog } from "../access";
|
|
2
|
+
export declare const ApiKeyPermissions: ({ description, idPrefix, permissions, labels, selected, title, onChange, }: {
|
|
3
|
+
description: string;
|
|
4
|
+
idPrefix: string;
|
|
5
|
+
permissions: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
6
|
+
labels?: ProjectAccessLabelCatalog | undefined;
|
|
7
|
+
selected: Readonly<Record<string, boolean>>;
|
|
8
|
+
title: string;
|
|
9
|
+
onChange: (id: string, checked: boolean) => void;
|
|
10
|
+
}) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown } from "lucide-react";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
5
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible";
|
|
6
|
+
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, } from "@/components/ui/field";
|
|
7
|
+
export const ApiKeyPermissions = ({ description, idPrefix, permissions, labels, selected, title, onChange, }) => {
|
|
8
|
+
const groups = Object.entries(permissions).reduce((groups, [permissionResource, permissionActions]) => {
|
|
9
|
+
for (const permissionAction of permissionActions) {
|
|
10
|
+
const separator = permissionAction.indexOf(":");
|
|
11
|
+
const resource = separator === -1
|
|
12
|
+
? permissionResource
|
|
13
|
+
: permissionAction.slice(0, separator);
|
|
14
|
+
const label = separator === -1
|
|
15
|
+
? permissionAction
|
|
16
|
+
: permissionAction.slice(separator + 1);
|
|
17
|
+
const group = groups.find((item) => item.resource === resource);
|
|
18
|
+
const permissionLabels = labels?.permissions[resource];
|
|
19
|
+
const action = {
|
|
20
|
+
id: `${permissionResource}:${permissionAction}`,
|
|
21
|
+
label: permissionLabels?.actions[label] ?? label,
|
|
22
|
+
};
|
|
23
|
+
if (group)
|
|
24
|
+
group.actions.push(action);
|
|
25
|
+
else
|
|
26
|
+
groups.push({
|
|
27
|
+
resource,
|
|
28
|
+
label: permissionLabels?.label ?? resource,
|
|
29
|
+
actions: [action],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return groups;
|
|
33
|
+
}, []);
|
|
34
|
+
if (groups.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
return (_jsxs(FieldSet, { className: "gap-3", children: [_jsx(FieldLegend, { className: "mb-0", children: title }), _jsx(FieldDescription, { children: description }), _jsx("div", { className: "overflow-hidden rounded-lg border", children: groups.map(({ resource, label, actions }, index) => (_jsx(PermissionGroup, { actions: actions, className: index > 0 ? "border-t" : "", idPrefix: idPrefix, resourceLabel: label, selected: selected, onChange: onChange }, resource))) })] }));
|
|
37
|
+
};
|
|
38
|
+
const PermissionGroup = ({ actions, className, idPrefix, resourceLabel, selected, onChange, }) => {
|
|
39
|
+
const selectedCount = actions.filter((action) => selected[action.id]).length;
|
|
40
|
+
const [open, setOpen] = useState(selectedCount > 0);
|
|
41
|
+
return (_jsxs(Collapsible, { className: className, open: open, onOpenChange: setOpen, children: [_jsxs(CollapsibleTrigger, { className: "hover:bg-muted/50 focus-visible:ring-ring flex w-full items-center gap-3 px-4 py-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset", children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-sm font-medium", children: resourceLabel }), _jsxs("span", { className: "text-muted-foreground text-xs tabular-nums", children: [selectedCount, "/", actions.length] }), _jsx(ChevronDown, { "aria-hidden": "true", className: `text-muted-foreground size-4 shrink-0 transition-transform ${open ? "rotate-180" : ""}` })] }), _jsx(CollapsibleContent, { className: "border-t px-4 py-3", children: _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "grid gap-3 sm:grid-cols-2", children: actions.map((action) => {
|
|
42
|
+
const inputId = `${idPrefix}-${action.id}`;
|
|
43
|
+
return (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: inputId, checked: selected[action.id] ?? false, onCheckedChange: (checked) => onChange(action.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: inputId, children: action.label }) })] }, action.id));
|
|
44
|
+
}) }) })] }));
|
|
45
|
+
};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraUpdateApiKeyPayload } from "../extra/schema";
|
|
2
3
|
export type CreateApiKeyPayload = typeof ExtraCreateApiKeyPayload.Type;
|
|
3
4
|
export type CreatedApiKey = typeof ExtraCreateApiKeyResponse.Type;
|
|
5
|
+
export type UpdateApiKeyPayload = typeof ExtraUpdateApiKeyPayload.Type;
|
|
4
6
|
export declare const parseApiKeyReferrers: (value: string, errorMessage: string) => string[];
|
|
5
7
|
export declare const createApiKey: (payload: CreateApiKeyPayload, fallbackError: string) => Promise<CreatedApiKey>;
|
|
8
|
+
export declare const updateApiKey: (payload: UpdateApiKeyPayload, fallbackError: string) => Promise<Schema.Struct.ReadonlySide<{
|
|
9
|
+
readonly ok: Schema.Boolean;
|
|
10
|
+
}, "Type">>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option, Schema } from "effect";
|
|
2
|
-
import { ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, } from "../extra/schema";
|
|
2
|
+
import { ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraOkResponse, ExtraUpdateApiKeyPayload, } from "../extra/schema";
|
|
3
3
|
const decodeUrl = Schema.decodeUnknownOption(Schema.URLFromString);
|
|
4
4
|
export const parseApiKeyReferrers = (value, errorMessage) => {
|
|
5
5
|
const referrers = value
|
|
@@ -37,3 +37,23 @@ export const createApiKey = async (payload, fallbackError) => {
|
|
|
37
37
|
}
|
|
38
38
|
return await Schema.decodeUnknownPromise(ExtraCreateApiKeyResponse)(data);
|
|
39
39
|
};
|
|
40
|
+
export const updateApiKey = async (payload, fallbackError) => {
|
|
41
|
+
const decoded = await Schema.decodeUnknownPromise(ExtraUpdateApiKeyPayload)(payload);
|
|
42
|
+
const response = await fetch(`/api/auth/api-key/${encodeURIComponent(decoded.keyId)}`, {
|
|
43
|
+
method: "PATCH",
|
|
44
|
+
credentials: "include",
|
|
45
|
+
headers: { "Content-Type": "application/json" },
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
configId: decoded.configId,
|
|
48
|
+
name: decoded.name,
|
|
49
|
+
enabled: decoded.enabled,
|
|
50
|
+
permissions: decoded.permissions,
|
|
51
|
+
referrers: decoded.referrers,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
const data = await response.json().catch(() => null);
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(await errorMessage(data, fallbackError));
|
|
57
|
+
}
|
|
58
|
+
return await Schema.decodeUnknownPromise(ExtraOkResponse)(data);
|
|
59
|
+
};
|
|
@@ -524,11 +524,14 @@ 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<"
|
|
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<"updateApiKey", "PATCH", "/api/auth/api-key/:keyId", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
528
528
|
readonly keyId: import("effect/Schema").NonEmptyString;
|
|
529
529
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
530
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
|
|
531
|
+
readonly name: import("effect/Schema").NonEmptyString;
|
|
532
|
+
readonly enabled: import("effect/Schema").Boolean;
|
|
533
|
+
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
534
|
+
readonly referrers: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").String>>;
|
|
532
535
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
533
536
|
readonly ok: import("effect/Schema").Boolean;
|
|
534
537
|
}>>, 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<{
|
|
@@ -538,7 +541,6 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
538
541
|
}>>, 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<"verifyApiKey", "POST", "/api/auth/verify-api-key", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
539
542
|
readonly key: import("effect/Schema").NonEmptyString;
|
|
540
543
|
readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
|
|
541
|
-
readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
|
|
542
544
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
543
545
|
readonly valid: import("effect/Schema").Boolean;
|
|
544
546
|
readonly error: import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
@@ -1,7 +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
|
+
import type { ProjectAccessCatalog, ProjectAccessLabelCatalog } from "../access";
|
|
5
5
|
export type KrakstackAuthLocale = "en" | "fr";
|
|
6
6
|
export type KrakstackAuthProviderProps = {
|
|
7
7
|
children: ReactNode;
|
|
@@ -10,6 +10,7 @@ export type KrakstackAuthProviderProps = {
|
|
|
10
10
|
projectId?: string | null | undefined;
|
|
11
11
|
authClient?: AuthUiClient | undefined;
|
|
12
12
|
access?: ProjectAccessCatalog | undefined;
|
|
13
|
+
accessLabels?: ProjectAccessLabelCatalog | undefined;
|
|
13
14
|
};
|
|
14
15
|
export type KrakstackAuthContextValue = {
|
|
15
16
|
locale: KrakstackAuthLocale;
|
|
@@ -18,10 +19,11 @@ export type KrakstackAuthContextValue = {
|
|
|
18
19
|
authClient: AuthUiClient;
|
|
19
20
|
projectConfig: ExtraProjectPublicConfig | null;
|
|
20
21
|
access: ProjectAccessCatalog | null;
|
|
22
|
+
accessLabels: ProjectAccessLabelCatalog | null;
|
|
21
23
|
authRefreshVersion: number;
|
|
22
24
|
refreshAuth: () => void;
|
|
23
25
|
};
|
|
24
|
-
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
26
|
+
export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
25
27
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
26
28
|
export declare const useAuthClient: () => AuthUiClient;
|
|
27
29
|
export declare const useKrakstackAuthProjectConfig: () => import("effect/Schema").Struct.ReadonlySide<{
|
|
@@ -68,7 +68,7 @@ const useProjectConfig = (baseUrl, providedProjectId) => {
|
|
|
68
68
|
}), { suspendOnWaiting: true });
|
|
69
69
|
return result.value;
|
|
70
70
|
};
|
|
71
|
-
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, access, }) {
|
|
71
|
+
export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, access, accessLabels, }) {
|
|
72
72
|
const searchString = useRouterState({
|
|
73
73
|
select: (state) => state.location.searchStr,
|
|
74
74
|
});
|
|
@@ -89,6 +89,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
89
89
|
projectId: resolvedProjectId,
|
|
90
90
|
projectConfig,
|
|
91
91
|
access: access ?? null,
|
|
92
|
+
accessLabels: accessLabels ?? null,
|
|
92
93
|
authRefreshVersion,
|
|
93
94
|
refreshAuth,
|
|
94
95
|
}), [
|
|
@@ -98,6 +99,7 @@ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projec
|
|
|
98
99
|
resolvedProjectId,
|
|
99
100
|
projectConfig,
|
|
100
101
|
access,
|
|
102
|
+
accessLabels,
|
|
101
103
|
authRefreshVersion,
|
|
102
104
|
refreshAuth,
|
|
103
105
|
]);
|