-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaudit-plugin.ts
More file actions
57 lines (52 loc) · 2.04 KB
/
audit-plugin.ts
File metadata and controls
57 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import type { Plugin, PluginContext } from '@objectstack/core';
import type { IDataEngine } from '@objectstack/spec/contracts';
import { SysAuditLog, SysActivity, SysComment, SysAttachment, SysNotification } from '@objectstack/platform-objects/audit';
import { installAuditWriters } from './audit-writers.js';
/**
* AuditPlugin
*
* Registers the sys_audit_log / sys_activity / sys_comment system objects
* and installs ObjectQL hook subscribers that automatically write audit
* trail + activity stream rows on every data mutation.
*
* Implements ROADMAP M10.1 (CRM production-readiness).
*/
export class AuditPlugin implements Plugin {
name = 'com.objectstack.audit';
type = 'standard';
version = '1.0.0';
dependencies = ['com.objectstack.engine.objectql'];
async init(ctx: PluginContext): Promise<void> {
// Register audit system objects via the manifest service.
ctx.getService<{ register(m: any): void }>('manifest').register({
id: 'com.objectstack.audit',
name: 'Audit',
version: '1.0.0',
type: 'plugin',
scope: 'system',
defaultDatasource: 'cloud',
namespace: 'sys',
objects: [SysAuditLog, SysActivity, SysComment, SysAttachment, SysNotification],
});
ctx.logger.info('Audit Plugin initialized');
}
async start(ctx: PluginContext): Promise<void> {
// ObjectQL engine is only resolvable after the kernel is ready.
ctx.hook('kernel:ready', async () => {
let engine: IDataEngine | null = null;
try {
engine = ctx.getService<IDataEngine>('objectql');
} catch {
// Fallback alias used in some kernels.
try { engine = ctx.getService<IDataEngine>('data'); } catch { /* ignore */ }
}
if (!engine) {
ctx.logger.warn('AuditPlugin: ObjectQL engine not available — audit writers NOT installed');
return;
}
installAuditWriters(engine as any, this.name);
ctx.logger.info('AuditPlugin: audit + activity writers installed');
});
}
}