@krak-stack/registry 0.11.7 → 0.11.9
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/CHANGELOG.md +54 -0
- package/README.md +39 -0
- package/dist/components/app-switcher/html.d.ts +2 -2
- package/dist/components/asset-input/html.d.ts +70 -0
- package/dist/components/asset-input/html.js +1549 -0
- package/dist/components/asset-input/index.d.ts +280 -0
- package/dist/components/asset-input/react.d.ts +32 -0
- package/dist/components/asset-input/react.js +2269 -0
- package/dist/components/asset-input/schema.d.ts +93 -0
- package/dist/components/asset-input/upload.d.ts +15 -0
- package/dist/components/asset-table/html.d.ts +110 -0
- package/dist/components/asset-table/html.js +4934 -0
- package/dist/components/asset-table/index.d.ts +225 -0
- package/dist/components/asset-table/react.d.ts +21 -0
- package/dist/components/asset-table/react.js +8241 -0
- package/dist/components/asset-table/schema.d.ts +73 -0
- package/dist/components/audit-log-table/html.js +47 -13
- package/dist/components/audit-log-table/react.js +36 -12
- package/dist/components/copy-button/html.d.ts +2 -2
- package/dist/components/danger-confirmation/html.d.ts +2 -2
- package/dist/components/data-table/classes.d.ts +2 -0
- package/dist/components/data-table/html.d.ts +58 -0
- package/dist/components/data-table/html.js +47 -13
- package/dist/components/data-table/index.d.ts +51 -1
- package/dist/components/data-table/react.d.ts +1 -0
- package/dist/components/data-table/react.js +36 -12
- package/dist/components/data-table/schema.d.ts +93 -3
- package/dist/components/date-input/html.d.ts +2 -2
- package/dist/components/docs/html.js +22 -4
- package/dist/components/docs/react.js +33 -2
- package/dist/components/editable-text/html.d.ts +2 -2
- package/dist/components/editing-locale-switcher/html.d.ts +2 -2
- package/dist/components/effect-form/react.js +343 -138
- package/dist/components/file-input/classes.d.ts +1 -1
- package/dist/components/file-input/file-type.d.ts +1 -0
- package/dist/components/file-input/html.d.ts +8 -1
- package/dist/components/file-input/html.js +170 -12
- package/dist/components/file-input/index.d.ts +1 -0
- package/dist/components/file-input/react.d.ts +9 -1
- package/dist/components/file-input/react.js +277 -127
- package/dist/components/file-input/schema.d.ts +1 -0
- package/dist/components/form/react.d.ts +5 -5
- package/dist/components/form/react.js +343 -138
- package/dist/components/icon-input/html.js +19 -5
- package/dist/components/icon-input/react.js +70 -13
- package/dist/components/locale-switcher/html.d.ts +2 -2
- package/dist/components/map-menu/html.d.ts +10 -4
- package/dist/components/map-menu/html.js +13 -8
- package/dist/components/map-menu/index.d.ts +5 -4
- package/dist/components/map-menu/react.d.ts +28 -17
- package/dist/components/map-menu/react.js +84 -178
- package/dist/components/map-menu/schema.d.ts +6 -0
- package/dist/components/map-menu/shared.d.ts +4 -0
- package/dist/components/permissions-input/classes.d.ts +8 -0
- package/dist/components/permissions-input/html.d.ts +41 -0
- package/dist/components/permissions-input/html.js +130 -0
- package/dist/components/permissions-input/index.d.ts +80 -0
- package/dist/components/permissions-input/react.d.ts +7 -0
- package/dist/components/permissions-input/react.js +201 -0
- package/dist/components/permissions-input/schema.d.ts +33 -0
- package/dist/components/phone-number-input/html.js +48 -14
- package/dist/components/phone-number-input/react.js +67 -10
- package/dist/components/presence-transition/index.d.ts +2 -2
- package/dist/components/search-menu/html.d.ts +2 -2
- package/dist/components/sidebar-layout/html.d.ts +3 -2
- package/dist/components/sidebar-layout/html.js +20 -2
- package/dist/components/sidebar-layout/index.d.ts +1 -0
- package/dist/components/sidebar-layout/react.js +33 -2
- package/dist/components/time-input/html.d.ts +2 -2
- package/dist/components/timezone-input/html.js +48 -14
- package/dist/components/timezone-input/react.js +67 -10
- package/dist/components/tracking-notice/html.d.ts +4 -4
- package/dist/components/tracking-notice/index.d.ts +2 -2
- package/dist/components/upload-attachment/classes.d.ts +3 -2
- package/dist/components/upload-attachment/html.d.ts +1 -1
- package/dist/components/upload-attachment/html.js +7 -5
- package/dist/components/upload-attachment/react.d.ts +3 -1
- package/dist/components/upload-attachment/react.js +25 -17
- package/dist/components/virtualized-combobox/classes.d.ts +12 -0
- package/dist/components/virtualized-combobox/html.d.ts +45 -3
- package/dist/components/virtualized-combobox/html.js +48 -14
- package/dist/components/virtualized-combobox/index.d.ts +55 -4
- package/dist/components/virtualized-combobox/react.d.ts +6 -2
- package/dist/components/virtualized-combobox/react.js +67 -10
- package/dist/components/virtualized-combobox/schema.d.ts +60 -4
- package/dist/components/webhook-delivery-table/html.js +47 -13
- package/dist/components/webhook-delivery-table/react.js +36 -12
- package/dist/lib/access/index.d.ts +61 -0
- package/dist/lib/access/index.js +92 -0
- package/dist/lib/access/table/classes.d.ts +13 -0
- package/dist/lib/access/table/html.d.ts +39 -0
- package/dist/lib/access/table/html.js +157 -0
- package/dist/lib/access/table/index.d.ts +32 -0
- package/dist/lib/access/table/react.d.ts +3 -0
- package/dist/lib/access/table/react.js +195 -0
- package/dist/lib/access/table/schema.d.ts +43 -0
- package/dist/lib/docs.integrations.server.js +23 -1
- package/dist/lib/docs.js +33 -2
- package/dist/lib/docs.server.js +29 -2
- package/dist/lib/documentation-toolkit.js +23 -1
- package/dist/lib/effect-ui-adapter/use-model.d.ts +1 -1
- package/dist/lib/effect-ui-adapter/use-model.js +19 -11
- package/dist/lib/lucide-effect.d.ts +19 -19
- package/dist/lib/lucide-effect.js +38 -38
- package/dist/services/assets/library.d.ts +221 -0
- package/dist/services/assets/schema.d.ts +3 -0
- package/dist/services/assets/url.d.ts +12 -0
- package/dist/services/assets/use-library.d.ts +20 -0
- package/package.json +13 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
export type UserActor = {
|
|
3
|
+
readonly type: "user";
|
|
4
|
+
readonly userId: string;
|
|
5
|
+
readonly organizationId: string | null;
|
|
6
|
+
readonly roles: ReadonlyArray<string>;
|
|
7
|
+
};
|
|
8
|
+
export type ApiKeyOwner = (Omit<UserActor, "type"> & {
|
|
9
|
+
readonly type: "user";
|
|
10
|
+
}) | {
|
|
11
|
+
readonly type: "organization";
|
|
12
|
+
readonly organizationId: string;
|
|
13
|
+
};
|
|
14
|
+
export type ApiKeyActor = {
|
|
15
|
+
readonly type: "apiKey";
|
|
16
|
+
readonly apiKeyId: string;
|
|
17
|
+
readonly owner: ApiKeyOwner;
|
|
18
|
+
};
|
|
19
|
+
export type Actor = UserActor | ApiKeyActor;
|
|
20
|
+
export type CurrentActor = {
|
|
21
|
+
readonly actor: Actor;
|
|
22
|
+
readonly organizationId: string | null;
|
|
23
|
+
readonly permissions: ReadonlySet<string>;
|
|
24
|
+
};
|
|
25
|
+
export declare const CurrentActor: Context.Service<CurrentActor, CurrentActor>;
|
|
26
|
+
export declare const principalId: (actor: Actor) => string;
|
|
27
|
+
declare const Forbidden_base: Schema.Class<Forbidden, Schema.TaggedStruct<"Forbidden", {}>, import("effect/Cause").YieldableError & {
|
|
28
|
+
readonly brand: unique symbol;
|
|
29
|
+
}>;
|
|
30
|
+
export declare class Forbidden extends Forbidden_base {
|
|
31
|
+
}
|
|
32
|
+
export type Policy<E = never, R = never> = Effect.Effect<void, Forbidden | E, CurrentActor | R>;
|
|
33
|
+
export declare const policy: <E, R>(predicate: (actor: CurrentActor) => Effect.Effect<boolean, E, R>) => Policy<E, R>;
|
|
34
|
+
export declare const permission: (required: string) => Policy;
|
|
35
|
+
export declare const hasPermission: (grants: readonly string[] | ReadonlySet<string>, required: string) => boolean;
|
|
36
|
+
export declare const all: <E, R>(...policies: readonly [Policy<E, R>, ...Array<Policy<E, R>>]) => Policy<E, R>;
|
|
37
|
+
export declare const any: <E, R>(...policies: readonly [Policy<E, R>, ...Array<Policy<E, R>>]) => Policy<E, R>;
|
|
38
|
+
export declare const withPolicy: <E, R>(check: Effect.Effect<void, E, R>) => <A, E2, R2>(effect: Effect.Effect<A, E2, R2>) => Effect.Effect<A, E | E2, R | R2>;
|
|
39
|
+
type RoleGrants<Role extends string, Grant extends string> = {
|
|
40
|
+
readonly roleNames: readonly Role[];
|
|
41
|
+
readonly permissionsForRoles: (verifiedRoles: Iterable<string>) => ReadonlySet<Grant>;
|
|
42
|
+
};
|
|
43
|
+
type RoleMapping<Role extends string, OtherRole extends string> = {
|
|
44
|
+
readonly roles: Readonly<Partial<Record<Role, NoInfer<OtherRole> | null>>>;
|
|
45
|
+
};
|
|
46
|
+
export interface ProjectAccess<Project extends string, Action extends string, Role extends string, Grant extends string> extends RoleGrants<Role, Grant> {
|
|
47
|
+
readonly project: Project;
|
|
48
|
+
readonly actions: readonly Action[];
|
|
49
|
+
/** Local role declarations. Merged grants are available via permissionsForRoles. */
|
|
50
|
+
readonly roles: Readonly<Record<string, readonly Action[] | undefined>>;
|
|
51
|
+
readonly qualify: (action: Action) => `${Project}:${Action}`;
|
|
52
|
+
readonly permission: (action: Action) => Policy;
|
|
53
|
+
readonly merge: <OtherRole extends string, OtherGrant extends string>(other: RoleGrants<OtherRole, OtherGrant>, options?: RoleMapping<Role, OtherRole>) => ProjectAccess<Project, Action, Role, Grant | OtherGrant>;
|
|
54
|
+
}
|
|
55
|
+
/** Define application-owned roles. Role membership must come from the host. */
|
|
56
|
+
export declare const defineProjectAccess: <const Project extends string, const Actions extends readonly string[], const Role extends string>(config: {
|
|
57
|
+
readonly project: Project;
|
|
58
|
+
readonly permissions: Actions;
|
|
59
|
+
readonly roles: Readonly<Record<Role, readonly NoInfer<Actions[number]>[] | undefined>>;
|
|
60
|
+
}) => ProjectAccess<Project, Actions[number], Role, `${Project}:${Actions[number]}`>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// ../../src/lib/access/index.ts
|
|
2
|
+
import { Context, Effect, Schema } from "effect";
|
|
3
|
+
var CurrentActor = Context.Service("@krak-stack/auth/CurrentActor");
|
|
4
|
+
var principalId = (actor) => actor.type === "user" ? actor.userId : actor.apiKeyId;
|
|
5
|
+
|
|
6
|
+
class Forbidden extends Schema.TaggedError()("Forbidden", {}, {
|
|
7
|
+
identifier: "Forbidden",
|
|
8
|
+
title: "Forbidden",
|
|
9
|
+
description: "The authenticated actor lacks a required permission.",
|
|
10
|
+
httpApiStatus: 403
|
|
11
|
+
}) {
|
|
12
|
+
}
|
|
13
|
+
var policy = (predicate) => CurrentActor.pipe(Effect.flatMap(predicate), Effect.flatMap((allowed) => allowed ? Effect.void : Effect.fail(new Forbidden)));
|
|
14
|
+
var permission = (required) => policy(({ permissions }) => Effect.succeed(permissions.has(required)));
|
|
15
|
+
var hasPermission = (grants, required) => {
|
|
16
|
+
for (const grant of grants) {
|
|
17
|
+
if (grant === required)
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
var all = (...policies) => Effect.all(policies, { concurrency: 1, discard: true });
|
|
23
|
+
var any = (...policies) => Effect.firstSuccessOf(policies);
|
|
24
|
+
var withPolicy = (check) => (effect) => Effect.andThen(check, effect);
|
|
25
|
+
var withMerge = (access) => ({
|
|
26
|
+
...access,
|
|
27
|
+
merge: (other, options) => {
|
|
28
|
+
const mappedGrants = new Map;
|
|
29
|
+
const otherRoles = new Set(other.roleNames);
|
|
30
|
+
for (const role of access.roleNames) {
|
|
31
|
+
const mapping = options?.roles;
|
|
32
|
+
const target = mapping && Object.hasOwn(mapping, role) ? mapping[role] : role;
|
|
33
|
+
if (target != null && otherRoles.has(target)) {
|
|
34
|
+
mappedGrants.set(role, other.permissionsForRoles([target]));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return withMerge({
|
|
38
|
+
...access,
|
|
39
|
+
permissionsForRoles: (verifiedRoles) => {
|
|
40
|
+
const roles = [...verifiedRoles];
|
|
41
|
+
const grants = new Set(access.permissionsForRoles(roles));
|
|
42
|
+
for (const role of roles) {
|
|
43
|
+
for (const grant of mappedGrants.get(role) ?? [])
|
|
44
|
+
grants.add(grant);
|
|
45
|
+
}
|
|
46
|
+
return grants;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
var defineProjectAccess = (config) => {
|
|
52
|
+
const actions = [...config.permissions];
|
|
53
|
+
const allowed = new Set(actions);
|
|
54
|
+
const roleNames = [];
|
|
55
|
+
const roles = new Map;
|
|
56
|
+
for (const role in config.roles) {
|
|
57
|
+
if (!Object.hasOwn(config.roles, role))
|
|
58
|
+
continue;
|
|
59
|
+
roleNames.push(role);
|
|
60
|
+
roles.set(role, (config.roles[role] ?? []).filter((action) => allowed.has(action)));
|
|
61
|
+
}
|
|
62
|
+
const qualify = (action) => `${config.project}:${action}`;
|
|
63
|
+
const permissionsForRoles = (verifiedRoles) => {
|
|
64
|
+
const grants = new Set;
|
|
65
|
+
for (const role of verifiedRoles) {
|
|
66
|
+
for (const action of roles.get(role) ?? [])
|
|
67
|
+
grants.add(qualify(action));
|
|
68
|
+
}
|
|
69
|
+
return grants;
|
|
70
|
+
};
|
|
71
|
+
return withMerge({
|
|
72
|
+
project: config.project,
|
|
73
|
+
actions,
|
|
74
|
+
roles: Object.fromEntries(roles),
|
|
75
|
+
roleNames,
|
|
76
|
+
qualify,
|
|
77
|
+
permissionsForRoles,
|
|
78
|
+
permission: (action) => permission(qualify(action))
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
CurrentActor,
|
|
83
|
+
Forbidden,
|
|
84
|
+
all,
|
|
85
|
+
any,
|
|
86
|
+
defineProjectAccess,
|
|
87
|
+
hasPermission,
|
|
88
|
+
permission,
|
|
89
|
+
policy,
|
|
90
|
+
principalId,
|
|
91
|
+
withPolicy
|
|
92
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Html } from "effect/ui/html";
|
|
2
|
+
export type { AccessTableProps } from "./schema.js";
|
|
3
|
+
export declare const AccessTable: import("effect/ui/Component").Component<"AccessTable", {
|
|
4
|
+
readonly access: {
|
|
5
|
+
readonly project: string;
|
|
6
|
+
readonly actions: readonly string[];
|
|
7
|
+
readonly roles: {
|
|
8
|
+
readonly [x: string]: readonly string[] | undefined;
|
|
9
|
+
};
|
|
10
|
+
readonly apiKeys?: {
|
|
11
|
+
readonly user: readonly string[];
|
|
12
|
+
readonly organization: readonly string[];
|
|
13
|
+
} | undefined;
|
|
14
|
+
};
|
|
15
|
+
readonly locale?: string | undefined;
|
|
16
|
+
readonly messages?: {
|
|
17
|
+
readonly action?: string | undefined;
|
|
18
|
+
readonly allowed?: string | undefined;
|
|
19
|
+
readonly apiKeyPermissions?: string | undefined;
|
|
20
|
+
readonly denied?: string | undefined;
|
|
21
|
+
readonly organizationKey?: string | undefined;
|
|
22
|
+
readonly resource?: string | undefined;
|
|
23
|
+
readonly rolePermissions?: string | undefined;
|
|
24
|
+
readonly userKey?: string | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly labels?: {
|
|
27
|
+
readonly roles?: {
|
|
28
|
+
readonly [x: string]: string | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
readonly permissions?: {
|
|
31
|
+
readonly [x: string]: {
|
|
32
|
+
readonly label: string;
|
|
33
|
+
readonly actions: {
|
|
34
|
+
readonly [x: string]: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
} | undefined;
|
|
38
|
+
} | undefined;
|
|
39
|
+
}, null, never, never, never, Html.Elements, {}, never>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// ../../src/lib/access/table/html.ts
|
|
2
|
+
import { Schema as Schema2 } from "effect";
|
|
3
|
+
import { Html } from "effect/ui/html";
|
|
4
|
+
import { Check, Minus } from "@krak-stack/registry/lucide-effect";
|
|
5
|
+
|
|
6
|
+
// ../../src/lib/access/table/classes.ts
|
|
7
|
+
var accessTableClasses = {
|
|
8
|
+
root: "space-y-6",
|
|
9
|
+
scroll: "overflow-x-auto rounded-md border",
|
|
10
|
+
table: "w-full min-w-max border-collapse text-sm",
|
|
11
|
+
caption: "px-4 py-3 text-left font-semibold",
|
|
12
|
+
header: "bg-muted/50",
|
|
13
|
+
cell: "px-4 py-3 text-left font-medium",
|
|
14
|
+
grant: "px-4 py-3 text-center",
|
|
15
|
+
row: "border-t",
|
|
16
|
+
code: "text-muted-foreground ml-2 text-xs",
|
|
17
|
+
allowed: "mx-auto size-4 text-emerald-600 dark:text-emerald-400",
|
|
18
|
+
denied: "text-muted-foreground/60 mx-auto size-4"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ../../src/lib/access/table/index.ts
|
|
22
|
+
var messages = {
|
|
23
|
+
en: {
|
|
24
|
+
resource: "Resource",
|
|
25
|
+
action: "Action",
|
|
26
|
+
allowed: "Allowed",
|
|
27
|
+
denied: "Not allowed",
|
|
28
|
+
rolePermissions: "Role grants",
|
|
29
|
+
apiKeyPermissions: "API-key assignable permissions",
|
|
30
|
+
userKey: "User key",
|
|
31
|
+
organizationKey: "Organization key"
|
|
32
|
+
},
|
|
33
|
+
fr: {
|
|
34
|
+
resource: "Ressource",
|
|
35
|
+
action: "Action",
|
|
36
|
+
allowed: "Autorisé",
|
|
37
|
+
denied: "Non autorisé",
|
|
38
|
+
rolePermissions: "Droits des rôles",
|
|
39
|
+
apiKeyPermissions: "Autorisations attribuables aux clés API",
|
|
40
|
+
userKey: "Clé utilisateur",
|
|
41
|
+
organizationKey: "Clé d’organisation"
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var label = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
45
|
+
var accessTable = ({
|
|
46
|
+
access,
|
|
47
|
+
labels,
|
|
48
|
+
locale,
|
|
49
|
+
messages: overrides
|
|
50
|
+
}) => {
|
|
51
|
+
const defaults = locale?.toLowerCase().split("-")[0] === "fr" ? messages.fr : messages.en;
|
|
52
|
+
const text = {
|
|
53
|
+
action: overrides?.action ?? defaults.action,
|
|
54
|
+
allowed: overrides?.allowed ?? defaults.allowed,
|
|
55
|
+
apiKeyPermissions: overrides?.apiKeyPermissions ?? defaults.apiKeyPermissions,
|
|
56
|
+
denied: overrides?.denied ?? defaults.denied,
|
|
57
|
+
organizationKey: overrides?.organizationKey ?? defaults.organizationKey,
|
|
58
|
+
resource: overrides?.resource ?? defaults.resource,
|
|
59
|
+
rolePermissions: overrides?.rolePermissions ?? defaults.rolePermissions,
|
|
60
|
+
userKey: overrides?.userKey ?? defaults.userKey
|
|
61
|
+
};
|
|
62
|
+
const table = (title, columns) => ({
|
|
63
|
+
title,
|
|
64
|
+
columns,
|
|
65
|
+
rows: access.actions.map((permission) => {
|
|
66
|
+
const separator = permission.indexOf(":");
|
|
67
|
+
const resource = separator < 0 ? permission : permission.slice(0, separator);
|
|
68
|
+
const action = separator < 0 ? permission : permission.slice(separator + 1);
|
|
69
|
+
return {
|
|
70
|
+
permission,
|
|
71
|
+
resource,
|
|
72
|
+
action,
|
|
73
|
+
resourceLabel: labels?.permissions?.[resource]?.label ?? label(resource),
|
|
74
|
+
actionLabel: labels?.permissions?.[resource]?.actions[action] ?? label(action),
|
|
75
|
+
cells: columns.map(({ id, grants }) => ({
|
|
76
|
+
id,
|
|
77
|
+
allowed: grants.includes(permission)
|
|
78
|
+
}))
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const tables = [
|
|
83
|
+
table(text.rolePermissions, Object.entries(access.roles).map(([id, grants]) => ({
|
|
84
|
+
id,
|
|
85
|
+
label: labels?.roles?.[id] ?? label(id),
|
|
86
|
+
grants: grants ?? []
|
|
87
|
+
})))
|
|
88
|
+
];
|
|
89
|
+
if (access.apiKeys) {
|
|
90
|
+
tables.push(table(text.apiKeyPermissions, [
|
|
91
|
+
{ id: "user", label: text.userKey, grants: access.apiKeys.user },
|
|
92
|
+
{
|
|
93
|
+
id: "organization",
|
|
94
|
+
label: text.organizationKey,
|
|
95
|
+
grants: access.apiKeys.organization
|
|
96
|
+
}
|
|
97
|
+
]));
|
|
98
|
+
}
|
|
99
|
+
return { text, tables };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ../../src/lib/access/table/schema.ts
|
|
103
|
+
import { Schema } from "effect";
|
|
104
|
+
var permissions = Schema.Array(Schema.String);
|
|
105
|
+
var labels = Schema.Record(Schema.String, Schema.String);
|
|
106
|
+
var AccessTableMessagesSchema = Schema.Struct({
|
|
107
|
+
action: Schema.optional(Schema.String),
|
|
108
|
+
allowed: Schema.optional(Schema.String),
|
|
109
|
+
apiKeyPermissions: Schema.optional(Schema.String),
|
|
110
|
+
denied: Schema.optional(Schema.String),
|
|
111
|
+
organizationKey: Schema.optional(Schema.String),
|
|
112
|
+
resource: Schema.optional(Schema.String),
|
|
113
|
+
rolePermissions: Schema.optional(Schema.String),
|
|
114
|
+
userKey: Schema.optional(Schema.String)
|
|
115
|
+
}).annotate({ identifier: "AccessTableMessages" });
|
|
116
|
+
var AccessTablePropsSchema = Schema.Struct({
|
|
117
|
+
access: Schema.Struct({
|
|
118
|
+
project: Schema.String,
|
|
119
|
+
actions: permissions,
|
|
120
|
+
roles: Schema.Record(Schema.String, Schema.UndefinedOr(permissions)),
|
|
121
|
+
apiKeys: Schema.optionalKey(Schema.Struct({
|
|
122
|
+
user: permissions,
|
|
123
|
+
organization: permissions
|
|
124
|
+
}))
|
|
125
|
+
}),
|
|
126
|
+
locale: Schema.optional(Schema.String),
|
|
127
|
+
messages: Schema.optional(AccessTableMessagesSchema),
|
|
128
|
+
labels: Schema.optional(Schema.Struct({
|
|
129
|
+
roles: Schema.optionalKey(Schema.Record(Schema.String, Schema.UndefinedOr(Schema.String))),
|
|
130
|
+
permissions: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
|
|
131
|
+
label: Schema.String,
|
|
132
|
+
actions: labels
|
|
133
|
+
})))
|
|
134
|
+
}))
|
|
135
|
+
}).annotate({ identifier: "AccessTableProps" });
|
|
136
|
+
|
|
137
|
+
// ../../src/lib/access/table/html.ts
|
|
138
|
+
var AccessTable = Html.component({
|
|
139
|
+
name: "AccessTable",
|
|
140
|
+
props: AccessTablePropsSchema,
|
|
141
|
+
model: Schema2.Null,
|
|
142
|
+
message: Schema2.Never,
|
|
143
|
+
restore: false
|
|
144
|
+
}).make({
|
|
145
|
+
init: () => null,
|
|
146
|
+
update: () => null,
|
|
147
|
+
view: (h) => {
|
|
148
|
+
const { text, tables } = accessTable(h.props);
|
|
149
|
+
return h.div.class(accessTableClasses.root).children(tables.map(({ title, columns, rows }) => h.div.class(accessTableClasses.scroll).children(h.table.class(accessTableClasses.table).children(h.caption.class(accessTableClasses.caption).children(title), h.thead.class(accessTableClasses.header).children(h.tr.children(h.th.class(accessTableClasses.cell).attr("scope", "col").children(text.resource), h.th.class(accessTableClasses.cell).attr("scope", "col").children(text.action), columns.map(({ label }) => h.th.class(accessTableClasses.grant).attr("scope", "col").children(label)))), h.tbody.children(rows.map(({ resource, action, resourceLabel, actionLabel, cells }) => h.tr.class(accessTableClasses.row).children(h.td.class(accessTableClasses.cell).children(resourceLabel, h.code.class(accessTableClasses.code).children(resource)), h.th.class(accessTableClasses.cell).attr("scope", "row").children(actionLabel, h.code.class(accessTableClasses.code).children(action)), cells.map(({ allowed }) => h.td.class(accessTableClasses.grant).children(h.span.class("sr-only").children(allowed ? text.allowed : text.denied), (allowed ? Check : Minus)(h, {
|
|
150
|
+
size: 16,
|
|
151
|
+
className: allowed ? accessTableClasses.allowed : accessTableClasses.denied
|
|
152
|
+
}))))))))));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
export {
|
|
156
|
+
AccessTable
|
|
157
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AccessTableProps } from "./schema.js";
|
|
2
|
+
export declare const accessTable: ({ access, labels, locale, messages: overrides, }: AccessTableProps) => {
|
|
3
|
+
text: {
|
|
4
|
+
action: string;
|
|
5
|
+
allowed: string;
|
|
6
|
+
apiKeyPermissions: string;
|
|
7
|
+
denied: string;
|
|
8
|
+
organizationKey: string;
|
|
9
|
+
resource: string;
|
|
10
|
+
rolePermissions: string;
|
|
11
|
+
userKey: string;
|
|
12
|
+
};
|
|
13
|
+
tables: {
|
|
14
|
+
title: string;
|
|
15
|
+
columns: readonly {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
grants: readonly string[];
|
|
19
|
+
}[];
|
|
20
|
+
rows: {
|
|
21
|
+
permission: string;
|
|
22
|
+
resource: string;
|
|
23
|
+
action: string;
|
|
24
|
+
resourceLabel: string;
|
|
25
|
+
actionLabel: string;
|
|
26
|
+
cells: {
|
|
27
|
+
id: string;
|
|
28
|
+
allowed: boolean;
|
|
29
|
+
}[];
|
|
30
|
+
}[];
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// ../../src/lib/access/table/react.tsx
|
|
2
|
+
import { Check, Minus } from "lucide-react";
|
|
3
|
+
|
|
4
|
+
// ../../src/lib/access/table/classes.ts
|
|
5
|
+
var accessTableClasses = {
|
|
6
|
+
root: "space-y-6",
|
|
7
|
+
scroll: "overflow-x-auto rounded-md border",
|
|
8
|
+
table: "w-full min-w-max border-collapse text-sm",
|
|
9
|
+
caption: "px-4 py-3 text-left font-semibold",
|
|
10
|
+
header: "bg-muted/50",
|
|
11
|
+
cell: "px-4 py-3 text-left font-medium",
|
|
12
|
+
grant: "px-4 py-3 text-center",
|
|
13
|
+
row: "border-t",
|
|
14
|
+
code: "text-muted-foreground ml-2 text-xs",
|
|
15
|
+
allowed: "mx-auto size-4 text-emerald-600 dark:text-emerald-400",
|
|
16
|
+
denied: "text-muted-foreground/60 mx-auto size-4"
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// ../../src/lib/access/table/index.ts
|
|
20
|
+
var messages = {
|
|
21
|
+
en: {
|
|
22
|
+
resource: "Resource",
|
|
23
|
+
action: "Action",
|
|
24
|
+
allowed: "Allowed",
|
|
25
|
+
denied: "Not allowed",
|
|
26
|
+
rolePermissions: "Role grants",
|
|
27
|
+
apiKeyPermissions: "API-key assignable permissions",
|
|
28
|
+
userKey: "User key",
|
|
29
|
+
organizationKey: "Organization key"
|
|
30
|
+
},
|
|
31
|
+
fr: {
|
|
32
|
+
resource: "Ressource",
|
|
33
|
+
action: "Action",
|
|
34
|
+
allowed: "Autorisé",
|
|
35
|
+
denied: "Non autorisé",
|
|
36
|
+
rolePermissions: "Droits des rôles",
|
|
37
|
+
apiKeyPermissions: "Autorisations attribuables aux clés API",
|
|
38
|
+
userKey: "Clé utilisateur",
|
|
39
|
+
organizationKey: "Clé d’organisation"
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var label = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
43
|
+
var accessTable = ({
|
|
44
|
+
access,
|
|
45
|
+
labels,
|
|
46
|
+
locale,
|
|
47
|
+
messages: overrides
|
|
48
|
+
}) => {
|
|
49
|
+
const defaults = locale?.toLowerCase().split("-")[0] === "fr" ? messages.fr : messages.en;
|
|
50
|
+
const text = {
|
|
51
|
+
action: overrides?.action ?? defaults.action,
|
|
52
|
+
allowed: overrides?.allowed ?? defaults.allowed,
|
|
53
|
+
apiKeyPermissions: overrides?.apiKeyPermissions ?? defaults.apiKeyPermissions,
|
|
54
|
+
denied: overrides?.denied ?? defaults.denied,
|
|
55
|
+
organizationKey: overrides?.organizationKey ?? defaults.organizationKey,
|
|
56
|
+
resource: overrides?.resource ?? defaults.resource,
|
|
57
|
+
rolePermissions: overrides?.rolePermissions ?? defaults.rolePermissions,
|
|
58
|
+
userKey: overrides?.userKey ?? defaults.userKey
|
|
59
|
+
};
|
|
60
|
+
const table = (title, columns) => ({
|
|
61
|
+
title,
|
|
62
|
+
columns,
|
|
63
|
+
rows: access.actions.map((permission) => {
|
|
64
|
+
const separator = permission.indexOf(":");
|
|
65
|
+
const resource = separator < 0 ? permission : permission.slice(0, separator);
|
|
66
|
+
const action = separator < 0 ? permission : permission.slice(separator + 1);
|
|
67
|
+
return {
|
|
68
|
+
permission,
|
|
69
|
+
resource,
|
|
70
|
+
action,
|
|
71
|
+
resourceLabel: labels?.permissions?.[resource]?.label ?? label(resource),
|
|
72
|
+
actionLabel: labels?.permissions?.[resource]?.actions[action] ?? label(action),
|
|
73
|
+
cells: columns.map(({ id, grants }) => ({
|
|
74
|
+
id,
|
|
75
|
+
allowed: grants.includes(permission)
|
|
76
|
+
}))
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
const tables = [
|
|
81
|
+
table(text.rolePermissions, Object.entries(access.roles).map(([id, grants]) => ({
|
|
82
|
+
id,
|
|
83
|
+
label: labels?.roles?.[id] ?? label(id),
|
|
84
|
+
grants: grants ?? []
|
|
85
|
+
})))
|
|
86
|
+
];
|
|
87
|
+
if (access.apiKeys) {
|
|
88
|
+
tables.push(table(text.apiKeyPermissions, [
|
|
89
|
+
{ id: "user", label: text.userKey, grants: access.apiKeys.user },
|
|
90
|
+
{
|
|
91
|
+
id: "organization",
|
|
92
|
+
label: text.organizationKey,
|
|
93
|
+
grants: access.apiKeys.organization
|
|
94
|
+
}
|
|
95
|
+
]));
|
|
96
|
+
}
|
|
97
|
+
return { text, tables };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// ../../src/lib/access/table/react.tsx
|
|
101
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
102
|
+
var AccessTable = (props) => {
|
|
103
|
+
const { text, tables } = accessTable(props);
|
|
104
|
+
return /* @__PURE__ */ jsx("div", {
|
|
105
|
+
className: accessTableClasses.root,
|
|
106
|
+
children: tables.map(({ title, columns, rows }) => /* @__PURE__ */ jsx("div", {
|
|
107
|
+
className: accessTableClasses.scroll,
|
|
108
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
109
|
+
className: accessTableClasses.table,
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ jsx("caption", {
|
|
112
|
+
className: accessTableClasses.caption,
|
|
113
|
+
children: title
|
|
114
|
+
}),
|
|
115
|
+
/* @__PURE__ */ jsx("thead", {
|
|
116
|
+
className: accessTableClasses.header,
|
|
117
|
+
children: /* @__PURE__ */ jsxs("tr", {
|
|
118
|
+
children: [
|
|
119
|
+
/* @__PURE__ */ jsx("th", {
|
|
120
|
+
className: accessTableClasses.cell,
|
|
121
|
+
scope: "col",
|
|
122
|
+
children: text.resource
|
|
123
|
+
}),
|
|
124
|
+
/* @__PURE__ */ jsx("th", {
|
|
125
|
+
className: accessTableClasses.cell,
|
|
126
|
+
scope: "col",
|
|
127
|
+
children: text.action
|
|
128
|
+
}),
|
|
129
|
+
columns.map(({ id, label }) => /* @__PURE__ */ jsx("th", {
|
|
130
|
+
className: accessTableClasses.grant,
|
|
131
|
+
scope: "col",
|
|
132
|
+
children: label
|
|
133
|
+
}, id))
|
|
134
|
+
]
|
|
135
|
+
})
|
|
136
|
+
}),
|
|
137
|
+
/* @__PURE__ */ jsx("tbody", {
|
|
138
|
+
children: rows.map(({
|
|
139
|
+
permission,
|
|
140
|
+
resource,
|
|
141
|
+
action,
|
|
142
|
+
resourceLabel,
|
|
143
|
+
actionLabel,
|
|
144
|
+
cells
|
|
145
|
+
}) => /* @__PURE__ */ jsxs("tr", {
|
|
146
|
+
className: accessTableClasses.row,
|
|
147
|
+
children: [
|
|
148
|
+
/* @__PURE__ */ jsxs("td", {
|
|
149
|
+
className: accessTableClasses.cell,
|
|
150
|
+
children: [
|
|
151
|
+
resourceLabel,
|
|
152
|
+
/* @__PURE__ */ jsx("code", {
|
|
153
|
+
className: accessTableClasses.code,
|
|
154
|
+
children: resource
|
|
155
|
+
})
|
|
156
|
+
]
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsxs("th", {
|
|
159
|
+
className: accessTableClasses.cell,
|
|
160
|
+
scope: "row",
|
|
161
|
+
children: [
|
|
162
|
+
actionLabel,
|
|
163
|
+
/* @__PURE__ */ jsx("code", {
|
|
164
|
+
className: accessTableClasses.code,
|
|
165
|
+
children: action
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
}),
|
|
169
|
+
cells.map(({ id, allowed }) => /* @__PURE__ */ jsxs("td", {
|
|
170
|
+
className: accessTableClasses.grant,
|
|
171
|
+
children: [
|
|
172
|
+
/* @__PURE__ */ jsx("span", {
|
|
173
|
+
className: "sr-only",
|
|
174
|
+
children: allowed ? text.allowed : text.denied
|
|
175
|
+
}),
|
|
176
|
+
allowed ? /* @__PURE__ */ jsx(Check, {
|
|
177
|
+
"aria-hidden": true,
|
|
178
|
+
className: accessTableClasses.allowed
|
|
179
|
+
}) : /* @__PURE__ */ jsx(Minus, {
|
|
180
|
+
"aria-hidden": true,
|
|
181
|
+
className: accessTableClasses.denied
|
|
182
|
+
})
|
|
183
|
+
]
|
|
184
|
+
}, id))
|
|
185
|
+
]
|
|
186
|
+
}, permission))
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
}, title))
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
export {
|
|
194
|
+
AccessTable
|
|
195
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
declare const AccessTableMessagesSchema: Schema.Struct<{
|
|
3
|
+
readonly action: Schema.optional<Schema.String>;
|
|
4
|
+
readonly allowed: Schema.optional<Schema.String>;
|
|
5
|
+
readonly apiKeyPermissions: Schema.optional<Schema.String>;
|
|
6
|
+
readonly denied: Schema.optional<Schema.String>;
|
|
7
|
+
readonly organizationKey: Schema.optional<Schema.String>;
|
|
8
|
+
readonly resource: Schema.optional<Schema.String>;
|
|
9
|
+
readonly rolePermissions: Schema.optional<Schema.String>;
|
|
10
|
+
readonly userKey: Schema.optional<Schema.String>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const AccessTablePropsSchema: Schema.Struct<{
|
|
13
|
+
readonly access: Schema.Struct<{
|
|
14
|
+
readonly project: Schema.String;
|
|
15
|
+
readonly actions: Schema.$Array<Schema.String>;
|
|
16
|
+
readonly roles: Schema.$Record<Schema.String, Schema.UndefinedOr<Schema.$Array<Schema.String>>>;
|
|
17
|
+
readonly apiKeys: Schema.optionalKey<Schema.Struct<{
|
|
18
|
+
readonly user: Schema.$Array<Schema.String>;
|
|
19
|
+
readonly organization: Schema.$Array<Schema.String>;
|
|
20
|
+
}>>;
|
|
21
|
+
}>;
|
|
22
|
+
readonly locale: Schema.optional<Schema.String>;
|
|
23
|
+
readonly messages: Schema.optional<Schema.Struct<{
|
|
24
|
+
readonly action: Schema.optional<Schema.String>;
|
|
25
|
+
readonly allowed: Schema.optional<Schema.String>;
|
|
26
|
+
readonly apiKeyPermissions: Schema.optional<Schema.String>;
|
|
27
|
+
readonly denied: Schema.optional<Schema.String>;
|
|
28
|
+
readonly organizationKey: Schema.optional<Schema.String>;
|
|
29
|
+
readonly resource: Schema.optional<Schema.String>;
|
|
30
|
+
readonly rolePermissions: Schema.optional<Schema.String>;
|
|
31
|
+
readonly userKey: Schema.optional<Schema.String>;
|
|
32
|
+
}>>;
|
|
33
|
+
readonly labels: Schema.optional<Schema.Struct<{
|
|
34
|
+
readonly roles: Schema.optionalKey<Schema.$Record<Schema.String, Schema.UndefinedOr<Schema.String>>>;
|
|
35
|
+
readonly permissions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
36
|
+
readonly label: Schema.String;
|
|
37
|
+
readonly actions: Schema.$Record<Schema.String, Schema.String>;
|
|
38
|
+
}>>>;
|
|
39
|
+
}>>;
|
|
40
|
+
}>;
|
|
41
|
+
export type AccessTableProps = typeof AccessTablePropsSchema.Type;
|
|
42
|
+
export type AccessTableMessages = Required<typeof AccessTableMessagesSchema.Type>;
|
|
43
|
+
export {};
|