73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import type { Prisma } from "@prisma/client";
|
|
import { prisma } from "@/lib/db";
|
|
|
|
export const SYSTEM_ACTOR = "ระบบ";
|
|
|
|
export type AuditAction =
|
|
| "META_LOGIN_CONNECTED"
|
|
| "META_LOGIN_REMOVED"
|
|
| "PAGE_CONNECTED"
|
|
| "PAGE_DISCONNECTED"
|
|
| "PAGE_WEBHOOK_SUBSCRIBED"
|
|
| "PAGE_TOKEN_INVALID"
|
|
| "PAGE_MEMBER_SET"
|
|
| "PAGE_MEMBER_REMOVED"
|
|
| "TEAM_CREATED"
|
|
| "TEAM_PAGE_ADDED"
|
|
| "TEAM_INVITE_CREATED"
|
|
| "TEAM_INVITE_REVOKED"
|
|
| "TEAM_INVITE_ACCEPTED"
|
|
| "TEAM_MEMBER_ROLE_SET"
|
|
| "TEAM_MEMBER_REMOVED"
|
|
| "PAGE_ANALYSIS_REQUESTED"
|
|
| "PAGE_PROFILE_SAVED"
|
|
| "POST_CREATED"
|
|
| "POST_EDITED"
|
|
| "POST_PLANNED"
|
|
| "POST_SUBMITTED"
|
|
| "POST_APPROVED"
|
|
| "POST_REJECTED"
|
|
| "POST_SCHEDULED"
|
|
| "POST_PUBLISHED"
|
|
| "POST_FAILED"
|
|
| "POST_CANCELLED"
|
|
| "POST_DELETED"
|
|
| "AI_POST_QUEUED"
|
|
| "AI_POST_STARTED"
|
|
| "AI_POST_COMPLETED"
|
|
| "AI_POST_FAILED"
|
|
| "AI_POST_CANCELLED"
|
|
| "CONTENT_AUTO_ENABLED"
|
|
| "CONTENT_AUTO_DISABLED"
|
|
| "CONTENT_AUTO_PAUSED"
|
|
| "CONTENT_AUTO_SKIPPED"
|
|
| "RULE_SAVED"
|
|
| "RULE_DELETED"
|
|
| "USER_CREATED"
|
|
| "USER_UPDATED"
|
|
| "USER_IDENTITY_LINKED";
|
|
|
|
/** Append-only — AuditLog rows are never updated or deleted. */
|
|
export async function audit(
|
|
entry: {
|
|
action: AuditAction;
|
|
actorId?: string | null;
|
|
actorLabel: string;
|
|
pageId?: string | null;
|
|
postId?: string | null;
|
|
detail?: Prisma.InputJsonValue;
|
|
},
|
|
tx: Prisma.TransactionClient = prisma
|
|
) {
|
|
await tx.auditLog.create({
|
|
data: {
|
|
action: entry.action,
|
|
actorId: entry.actorId ?? null,
|
|
actorLabel: entry.actorLabel,
|
|
pageId: entry.pageId ?? null,
|
|
postId: entry.postId ?? null,
|
|
detail: entry.detail,
|
|
},
|
|
});
|
|
}
|