feat: add cerbos access control
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { RoleSchema } from "@spec/schemas/account/role.ts";
|
||||
import { EmailSchema } from "@spec/schemas/email.ts";
|
||||
import { NameSchema } from "@spec/schemas/name.ts";
|
||||
import { event } from "@valkyr/event-store";
|
||||
@@ -10,5 +11,5 @@ export default [
|
||||
event.type("account:avatar:added").data(z.string()).meta(AuditorSchema),
|
||||
event.type("account:name:added").data(NameSchema).meta(AuditorSchema),
|
||||
event.type("account:email:added").data(EmailSchema).meta(AuditorSchema),
|
||||
event.type("account:role:added").data(z.string()).meta(AuditorSchema),
|
||||
event.type("account:role:added").data(RoleSchema).meta(AuditorSchema),
|
||||
];
|
||||
|
||||
@@ -3,9 +3,8 @@ import { EventFactory } from "@valkyr/event-store";
|
||||
import account from "./account.ts";
|
||||
import code from "./code.ts";
|
||||
import organization from "./organization.ts";
|
||||
import role from "./role.ts";
|
||||
import strategy from "./strategy.ts";
|
||||
|
||||
export const events = new EventFactory([...account, ...code, ...organization, ...role, ...strategy]);
|
||||
export const events = new EventFactory([...account, ...code, ...organization, ...strategy]);
|
||||
|
||||
export type EventStoreFactory = typeof events;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import z from "zod";
|
||||
|
||||
import { AuditorSchema } from "./auditor.ts";
|
||||
|
||||
const CreatedSchema = z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(
|
||||
z.object({
|
||||
resource: z.string(),
|
||||
actions: z.array(z.string()),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const OperationSchema = z.discriminatedUnion("type", [
|
||||
z.object({
|
||||
type: z.literal("grant"),
|
||||
resource: z.string(),
|
||||
action: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("deny"),
|
||||
resource: z.string(),
|
||||
action: z.string().optional(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export default [
|
||||
event.type("role:created").data(CreatedSchema).meta(AuditorSchema),
|
||||
event.type("role:name-set").data(z.string()).meta(AuditorSchema),
|
||||
event.type("role:permissions-set").data(z.array(OperationSchema)).meta(AuditorSchema),
|
||||
];
|
||||
|
||||
export type RoleCreatedData = z.infer<typeof CreatedSchema>;
|
||||
|
||||
export type RolePermissionOperation = z.infer<typeof OperationSchema>;
|
||||
Reference in New Issue
Block a user