feat: initial boilerplate
This commit is contained in:
29
api/libraries/event-store/events/account.ts
Normal file
29
api/libraries/event-store/events/account.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import { email, name, phone } from "relay/schemas";
|
||||
import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
const created = z.discriminatedUnion([
|
||||
z.object({
|
||||
type: z.literal("admin"),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("consultant"),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("organization"),
|
||||
organizationId: z.string(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export default [
|
||||
event.type("account:created").data(created).meta(auditor),
|
||||
event.type("account:avatar:added").data(z.string()).meta(auditor),
|
||||
event.type("account:name:added").data(name).meta(auditor),
|
||||
event.type("account:email:added").data(email).meta(auditor),
|
||||
event.type("account:phone:added").data(phone).meta(auditor),
|
||||
event.type("account:role:added").data(z.string()).meta(auditor),
|
||||
];
|
||||
|
||||
export type AccountCreatedData = z.infer<typeof created>;
|
||||
7
api/libraries/event-store/events/auditor.ts
Normal file
7
api/libraries/event-store/events/auditor.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import z from "zod";
|
||||
|
||||
export const auditor = z.object({
|
||||
accountId: z.string(),
|
||||
});
|
||||
|
||||
export type Auditor = z.infer<typeof auditor>;
|
||||
30
api/libraries/event-store/events/code.ts
Normal file
30
api/libraries/event-store/events/code.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import z from "zod";
|
||||
|
||||
const identity = z.discriminatedUnion([
|
||||
z.object({
|
||||
type: z.literal("admin"),
|
||||
accountId: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("consultant"),
|
||||
accountId: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal("organization"),
|
||||
organizationId: z.string(),
|
||||
accountId: z.string(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export default [
|
||||
event.type("code:created").data(
|
||||
z.object({
|
||||
value: z.string(),
|
||||
identity,
|
||||
}),
|
||||
),
|
||||
event.type("code:claimed"),
|
||||
];
|
||||
|
||||
export type CodeIdentity = z.infer<typeof identity>;
|
||||
11
api/libraries/event-store/events/mod.ts
Normal file
11
api/libraries/event-store/events/mod.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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 type EventStoreFactory = typeof events;
|
||||
11
api/libraries/event-store/events/organization.ts
Normal file
11
api/libraries/event-store/events/organization.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
export default [
|
||||
event
|
||||
.type("organization:created")
|
||||
.data(z.object({ name: z.string() }))
|
||||
.meta(auditor),
|
||||
];
|
||||
37
api/libraries/event-store/events/role.ts
Normal file
37
api/libraries/event-store/events/role.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
const created = z.object({
|
||||
name: z.string(),
|
||||
permissions: z.array(
|
||||
z.object({
|
||||
resource: z.string(),
|
||||
actions: z.array(z.string()),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const operation = z.discriminatedUnion([
|
||||
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(created).meta(auditor),
|
||||
event.type("role:name-set").data(z.string()).meta(auditor),
|
||||
event.type("role:permissions-set").data(z.array(operation)).meta(auditor),
|
||||
];
|
||||
|
||||
export type RoleCreatedData = z.infer<typeof created>;
|
||||
|
||||
export type RolePermissionOperation = z.infer<typeof operation>;
|
||||
13
api/libraries/event-store/events/strategy.ts
Normal file
13
api/libraries/event-store/events/strategy.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { event } from "@valkyr/event-store";
|
||||
import z from "zod";
|
||||
|
||||
import { auditor } from "./auditor.ts";
|
||||
|
||||
export default [
|
||||
event.type("strategy:email:added").data(z.string()).meta(auditor),
|
||||
event.type("strategy:passkey:added").meta(auditor),
|
||||
event
|
||||
.type("strategy:password:added")
|
||||
.data(z.object({ alias: z.string(), password: z.string() }))
|
||||
.meta(auditor),
|
||||
];
|
||||
Reference in New Issue
Block a user