mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 23:07:29 +00:00
Add communication account plugin scaffolds
This commit is contained in:
parent
5cfeea6b57
commit
c23ce42948
48 changed files with 1949 additions and 13 deletions
43
packages/account-core/src/audit.ts
Normal file
43
packages/account-core/src/audit.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import type { LogicSrcAccountAuditEvent, LogicSrcAccountKind, LogicSrcPolicyDecision, LogicSrcPrincipal } from "./types.js";
|
||||
|
||||
const REDACTED_KEYS = new Set(["accessToken", "refreshToken", "token", "password", "secret", "clientSecret", "authorization"]);
|
||||
|
||||
export function redactedPreview(input: Record<string, unknown>) {
|
||||
const output: Record<string, unknown> = {};
|
||||
|
||||
for (const [key, value] of Object.entries(input)) {
|
||||
output[key] = REDACTED_KEYS.has(key) ? "[redacted]" : value;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
export function createAccountAuditEvent(input: {
|
||||
id?: string;
|
||||
accountId?: string;
|
||||
provider: string;
|
||||
kind: LogicSrcAccountKind;
|
||||
principal: LogicSrcPrincipal;
|
||||
action: string;
|
||||
decision: LogicSrcPolicyDecision;
|
||||
riskScore?: number;
|
||||
requestPreview?: Record<string, unknown>;
|
||||
resultPreview?: Record<string, unknown>;
|
||||
correlationId?: string;
|
||||
createdAt?: string;
|
||||
}): LogicSrcAccountAuditEvent {
|
||||
return {
|
||||
id: input.id ?? `acct_audit_${Date.now()}`,
|
||||
accountId: input.accountId,
|
||||
provider: input.provider,
|
||||
kind: input.kind,
|
||||
principal: input.principal,
|
||||
action: input.action,
|
||||
decision: input.decision,
|
||||
riskScore: input.riskScore ?? 0,
|
||||
requestPreview: redactedPreview(input.requestPreview ?? {}),
|
||||
resultPreview: redactedPreview(input.resultPreview ?? {}),
|
||||
correlationId: input.correlationId,
|
||||
createdAt: input.createdAt ?? new Date().toISOString()
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue