mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat: init sentinel
This commit is contained in:
parent
9bf591555e
commit
f702cc24a3
3 changed files with 64 additions and 0 deletions
|
@ -293,6 +293,8 @@ export const hookConfigGuard = z.object({
|
|||
|
||||
export type HookConfig = z.infer<typeof hookConfigGuard>;
|
||||
|
||||
/* === Custom domains and Cloudflare === */
|
||||
|
||||
export const domainDnsRecordGuard = z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
|
@ -334,3 +336,44 @@ export enum DomainStatus {
|
|||
}
|
||||
|
||||
export const domainStatusGuard = z.nativeEnum(DomainStatus);
|
||||
|
||||
/* === Sentinel activities === */
|
||||
|
||||
/** The subject (actor) type of a sentinel activity. */
|
||||
export enum SentinelActivitySubjectType {
|
||||
User = 'User',
|
||||
App = 'App',
|
||||
Sentinel = 'Sentinel',
|
||||
}
|
||||
export const sentinelActivitySubjectTypeGuard = z.nativeEnum(SentinelActivitySubjectType);
|
||||
|
||||
/** The action target type of a sentinel activity. */
|
||||
export enum SentinelActivityTargetType {
|
||||
User = 'User',
|
||||
App = 'App',
|
||||
}
|
||||
export const sentinelActivityTargetTypeGuard = z.nativeEnum(SentinelActivityTargetType);
|
||||
|
||||
/** The action type of a sentinel activity. */
|
||||
export enum SentinelActivityAction {
|
||||
/**
|
||||
* The subject tries to pass a verification for a target.
|
||||
*
|
||||
* For example, a user (subject) who inputted a verification code or password for themselves
|
||||
* (target).
|
||||
*/
|
||||
Verification = 'Verification',
|
||||
/**
|
||||
* The subject tries to block the target from passing a verification.
|
||||
*
|
||||
* For example, the sentinel (subject) who blocked a user (target) from passing a verification
|
||||
* for 10 minutes.
|
||||
*/
|
||||
BlockVerification = 'BlockVerification',
|
||||
}
|
||||
export const sentinelActivityActionGuard = z.nativeEnum(SentinelActivityAction);
|
||||
|
||||
export type SentinelActivityPayload = Record<string, unknown>;
|
||||
export const sentinelActivityPayloadGuard = z.record(
|
||||
z.unknown()
|
||||
) satisfies z.ZodType<SentinelActivityPayload>;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* init_order = 2 */
|
||||
|
||||
create table logs (
|
||||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
|
|
19
packages/schemas/tables/sentinel_activities.sql
Normal file
19
packages/schemas/tables/sentinel_activities.sql
Normal file
|
@ -0,0 +1,19 @@
|
|||
create type sentinel_activity_result as enum ('Success', 'Failed');
|
||||
|
||||
create table sentinel_activities (
|
||||
tenant_id varchar(21) not null
|
||||
references tenants (id) on update cascade on delete cascade,
|
||||
id varchar(21) not null,
|
||||
subject_type varchar(32) /* @use SentinelActivitySubjectType */ not null,
|
||||
target_type varchar(32) /* @use SentinelActivityTargetType */ not null,
|
||||
target_id varchar(21) not null
|
||||
references users (id) on update cascade on delete cascade,
|
||||
log_id varchar(21)
|
||||
references logs (id) on update cascade on delete cascade,
|
||||
action varchar(64) /* @use SentinelActivityAction */ not null,
|
||||
result sentinel_activity_result not null,
|
||||
payload jsonb /* @use LogContextPayload */ not null,
|
||||
created_at timestamptz not null default(now()),
|
||||
primary key (id)
|
||||
);
|
||||
ex
|
Loading…
Reference in a new issue