@objectstack/core 0.9.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{ENHANCED_FEATURES.md → ADVANCED_FEATURES.md} +13 -13
- package/CHANGELOG.md +21 -0
- package/PHASE2_IMPLEMENTATION.md +388 -0
- package/README.md +12 -341
- package/REFACTORING_SUMMARY.md +40 -0
- package/dist/api-registry-plugin.test.js +23 -21
- package/dist/api-registry.test.js +2 -2
- package/dist/dependency-resolver.d.ts +62 -0
- package/dist/dependency-resolver.d.ts.map +1 -0
- package/dist/dependency-resolver.js +317 -0
- package/dist/dependency-resolver.test.d.ts +2 -0
- package/dist/dependency-resolver.test.d.ts.map +1 -0
- package/dist/dependency-resolver.test.js +241 -0
- package/dist/health-monitor.d.ts +65 -0
- package/dist/health-monitor.d.ts.map +1 -0
- package/dist/health-monitor.js +269 -0
- package/dist/health-monitor.test.d.ts +2 -0
- package/dist/health-monitor.test.d.ts.map +1 -0
- package/dist/health-monitor.test.js +68 -0
- package/dist/hot-reload.d.ts +79 -0
- package/dist/hot-reload.d.ts.map +1 -0
- package/dist/hot-reload.js +313 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/kernel-base.d.ts +2 -2
- package/dist/kernel-base.js +2 -2
- package/dist/kernel.d.ts +89 -31
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +430 -73
- package/dist/kernel.test.js +375 -122
- package/dist/lite-kernel.d.ts +55 -0
- package/dist/lite-kernel.d.ts.map +1 -0
- package/dist/lite-kernel.js +112 -0
- package/dist/lite-kernel.test.d.ts +2 -0
- package/dist/lite-kernel.test.d.ts.map +1 -0
- package/dist/lite-kernel.test.js +161 -0
- package/dist/logger.d.ts +2 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +26 -7
- package/dist/plugin-loader.d.ts +15 -0
- package/dist/plugin-loader.d.ts.map +1 -1
- package/dist/plugin-loader.js +40 -10
- package/dist/plugin-loader.test.js +9 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +4 -0
- package/dist/security/permission-manager.d.ts +96 -0
- package/dist/security/permission-manager.d.ts.map +1 -0
- package/dist/security/permission-manager.js +235 -0
- package/dist/security/permission-manager.test.d.ts +2 -0
- package/dist/security/permission-manager.test.d.ts.map +1 -0
- package/dist/security/permission-manager.test.js +220 -0
- package/dist/security/plugin-permission-enforcer.d.ts +1 -1
- package/dist/security/sandbox-runtime.d.ts +115 -0
- package/dist/security/sandbox-runtime.d.ts.map +1 -0
- package/dist/security/sandbox-runtime.js +310 -0
- package/dist/security/security-scanner.d.ts +92 -0
- package/dist/security/security-scanner.d.ts.map +1 -0
- package/dist/security/security-scanner.js +273 -0
- package/examples/{enhanced-kernel-example.ts → kernel-features-example.ts} +6 -6
- package/examples/phase2-integration.ts +355 -0
- package/package.json +3 -2
- package/src/api-registry-plugin.test.ts +23 -21
- package/src/api-registry.test.ts +2 -2
- package/src/dependency-resolver.test.ts +287 -0
- package/src/dependency-resolver.ts +388 -0
- package/src/health-monitor.test.ts +81 -0
- package/src/health-monitor.ts +316 -0
- package/src/hot-reload.ts +388 -0
- package/src/index.ts +6 -1
- package/src/kernel-base.ts +2 -2
- package/src/kernel.test.ts +471 -134
- package/src/kernel.ts +518 -76
- package/src/lite-kernel.test.ts +200 -0
- package/src/lite-kernel.ts +135 -0
- package/src/logger.ts +28 -7
- package/src/plugin-loader.test.ts +10 -1
- package/src/plugin-loader.ts +49 -13
- package/src/security/index.ts +19 -0
- package/src/security/permission-manager.test.ts +256 -0
- package/src/security/permission-manager.ts +336 -0
- package/src/security/plugin-permission-enforcer.test.ts +1 -1
- package/src/security/plugin-permission-enforcer.ts +1 -1
- package/src/security/sandbox-runtime.ts +432 -0
- package/src/security/security-scanner.ts +365 -0
- package/dist/enhanced-kernel.d.ts +0 -103
- package/dist/enhanced-kernel.d.ts.map +0 -1
- package/dist/enhanced-kernel.js +0 -403
- package/dist/enhanced-kernel.test.d.ts +0 -2
- package/dist/enhanced-kernel.test.d.ts.map +0 -1
- package/dist/enhanced-kernel.test.js +0 -412
- package/src/enhanced-kernel.test.ts +0 -535
- package/src/enhanced-kernel.ts +0 -496
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ObjectKernel - Advanced Plugin Features
|
|
2
2
|
|
|
3
|
-
This document describes the
|
|
3
|
+
This document describes the advanced features of ObjectKernel for production-grade plugin management.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The `
|
|
7
|
+
The `ObjectKernel` (formerly `EnhancedObjectKernel`) provides enterprise-grade features for plugin lifecycle management, dependency injection, and operational resilience.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
@@ -13,9 +13,9 @@ The `EnhancedObjectKernel` extends the basic `ObjectKernel` with enterprise-grad
|
|
|
13
13
|
Async plugin loading with comprehensive validation:
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import {
|
|
16
|
+
import { ObjectKernel, PluginMetadata } from '@objectstack/core';
|
|
17
17
|
|
|
18
|
-
const kernel = new
|
|
18
|
+
const kernel = new ObjectKernel({
|
|
19
19
|
logger: { level: 'info' },
|
|
20
20
|
defaultStartupTimeout: 30000, // 30 seconds
|
|
21
21
|
gracefulShutdown: true,
|
|
@@ -242,7 +242,7 @@ for (const [pluginName, startTime] of metrics) {
|
|
|
242
242
|
Properly cleanup resources on shutdown:
|
|
243
243
|
|
|
244
244
|
```typescript
|
|
245
|
-
const kernel = new
|
|
245
|
+
const kernel = new ObjectKernel({
|
|
246
246
|
gracefulShutdown: true,
|
|
247
247
|
shutdownTimeout: 60000 // 60 second timeout
|
|
248
248
|
});
|
|
@@ -309,25 +309,25 @@ const plugin: PluginMetadata = {
|
|
|
309
309
|
};
|
|
310
310
|
```
|
|
311
311
|
|
|
312
|
-
## Migration from
|
|
312
|
+
## Migration from LiteKernel
|
|
313
313
|
|
|
314
|
-
To migrate from `
|
|
314
|
+
To migrate from `LiteKernel` to `ObjectKernel`:
|
|
315
315
|
|
|
316
316
|
```typescript
|
|
317
317
|
// Before
|
|
318
|
-
import {
|
|
319
|
-
const kernel = new
|
|
318
|
+
import { LiteKernel } from '@objectstack/core';
|
|
319
|
+
const kernel = new LiteKernel();
|
|
320
320
|
|
|
321
321
|
// After
|
|
322
|
-
import {
|
|
323
|
-
const kernel = new
|
|
322
|
+
import { ObjectKernel } from '@objectstack/core';
|
|
323
|
+
const kernel = new ObjectKernel({
|
|
324
324
|
logger: { level: 'info' },
|
|
325
325
|
gracefulShutdown: true,
|
|
326
326
|
rollbackOnFailure: true
|
|
327
327
|
});
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
Both kernels
|
|
330
|
+
Both kernels adhere to the same `Plugin` interface, but `ObjectKernel` supports advanced features like Rollback, Sandbox, and Hot Reload.
|
|
331
331
|
|
|
332
332
|
## Best Practices
|
|
333
333
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @objectstack/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Major version release for ObjectStack Protocol v1.0.
|
|
8
|
+
- Stabilized Protocol Definitions
|
|
9
|
+
- Enhanced Runtime Plugin Support
|
|
10
|
+
- Fixed Type Compliance across Monorepo
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @objectstack/spec@1.0.0
|
|
16
|
+
|
|
17
|
+
## 0.9.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @objectstack/spec@0.9.2
|
|
23
|
+
|
|
3
24
|
## 0.9.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# ObjectStack Phase 2 Implementation
|
|
2
|
+
|
|
3
|
+
This document describes the Phase 2 implementation of the ObjectStack Microkernel and Plugin Architecture Improvement Plan.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Phase 2 implements the core runtime features for advanced plugin lifecycle management, dependency resolution, and security sandboxing. These components build upon the protocol definitions from Phase 1 and provide production-ready implementations.
|
|
8
|
+
|
|
9
|
+
## Components
|
|
10
|
+
|
|
11
|
+
### 1. Health Monitor (`health-monitor.ts`)
|
|
12
|
+
|
|
13
|
+
The Health Monitor provides real-time health checking and auto-recovery for plugins.
|
|
14
|
+
|
|
15
|
+
**Features:**
|
|
16
|
+
- Configurable health check intervals
|
|
17
|
+
- Automatic failure detection with thresholds
|
|
18
|
+
- Auto-restart with backoff strategies (fixed, linear, exponential)
|
|
19
|
+
- Health status tracking (healthy, degraded, unhealthy, failed, recovering, unknown)
|
|
20
|
+
- Metrics collection (uptime, memory, CPU, connections, error rate)
|
|
21
|
+
|
|
22
|
+
**Usage:**
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { PluginHealthMonitor } from '@objectstack/core';
|
|
26
|
+
|
|
27
|
+
const monitor = new PluginHealthMonitor(logger);
|
|
28
|
+
|
|
29
|
+
// Register a plugin for monitoring
|
|
30
|
+
monitor.registerPlugin('my-plugin', {
|
|
31
|
+
interval: 30000, // Check every 30 seconds
|
|
32
|
+
timeout: 5000, // 5 second timeout
|
|
33
|
+
failureThreshold: 3, // Mark unhealthy after 3 failures
|
|
34
|
+
successThreshold: 1, // Mark healthy after 1 success
|
|
35
|
+
autoRestart: true, // Auto-restart on failure
|
|
36
|
+
maxRestartAttempts: 3, // Max 3 restart attempts
|
|
37
|
+
restartBackoff: 'exponential',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Start monitoring
|
|
41
|
+
monitor.startMonitoring('my-plugin', pluginInstance);
|
|
42
|
+
|
|
43
|
+
// Get health status
|
|
44
|
+
const status = monitor.getHealthStatus('my-plugin');
|
|
45
|
+
const report = monitor.getHealthReport('my-plugin');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Hot Reload Manager (`hot-reload.ts`)
|
|
49
|
+
|
|
50
|
+
The Hot Reload Manager enables zero-downtime plugin updates with state preservation.
|
|
51
|
+
|
|
52
|
+
**Features:**
|
|
53
|
+
- State preservation strategies (memory, disk, distributed, none)
|
|
54
|
+
- File watching integration points
|
|
55
|
+
- Debounced reload scheduling
|
|
56
|
+
- Graceful shutdown with configurable timeout
|
|
57
|
+
- Before/after reload hooks
|
|
58
|
+
- State checksum verification
|
|
59
|
+
|
|
60
|
+
**Usage:**
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { HotReloadManager } from '@objectstack/core';
|
|
64
|
+
|
|
65
|
+
const hotReload = new HotReloadManager(logger);
|
|
66
|
+
|
|
67
|
+
// Register plugin for hot reload
|
|
68
|
+
hotReload.registerPlugin('my-plugin', {
|
|
69
|
+
enabled: true,
|
|
70
|
+
watchPatterns: ['src/**/*.ts'],
|
|
71
|
+
debounceDelay: 1000,
|
|
72
|
+
preserveState: true,
|
|
73
|
+
stateStrategy: 'memory',
|
|
74
|
+
shutdownTimeout: 30000,
|
|
75
|
+
beforeReload: ['plugin:beforeReload'],
|
|
76
|
+
afterReload: ['plugin:afterReload'],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Trigger reload
|
|
80
|
+
await hotReload.reloadPlugin(
|
|
81
|
+
'my-plugin',
|
|
82
|
+
pluginInstance,
|
|
83
|
+
'1.2.0',
|
|
84
|
+
() => ({ /* current state */ }),
|
|
85
|
+
(state) => { /* restore state */ }
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Dependency Resolver (`dependency-resolver.ts`)
|
|
90
|
+
|
|
91
|
+
The Dependency Resolver provides semantic versioning and dependency management.
|
|
92
|
+
|
|
93
|
+
**Features:**
|
|
94
|
+
- Full SemVer parsing and comparison
|
|
95
|
+
- Version constraint matching (^, ~, >=, <=, <, >, -, *, latest)
|
|
96
|
+
- Topological sorting (Kahn's algorithm)
|
|
97
|
+
- Circular dependency detection
|
|
98
|
+
- Version conflict detection
|
|
99
|
+
- Compatibility level assessment
|
|
100
|
+
- Best version selection
|
|
101
|
+
|
|
102
|
+
**Usage:**
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import {
|
|
106
|
+
SemanticVersionManager,
|
|
107
|
+
DependencyResolver
|
|
108
|
+
} from '@objectstack/core';
|
|
109
|
+
|
|
110
|
+
// Parse and compare versions
|
|
111
|
+
const v1 = SemanticVersionManager.parse('1.2.3');
|
|
112
|
+
const v2 = SemanticVersionManager.parse('1.3.0');
|
|
113
|
+
const cmp = SemanticVersionManager.compare(v1, v2); // -1
|
|
114
|
+
|
|
115
|
+
// Check if version satisfies constraint
|
|
116
|
+
const satisfies = SemanticVersionManager.satisfies(v1, '^1.0.0'); // true
|
|
117
|
+
|
|
118
|
+
// Get compatibility level
|
|
119
|
+
const compat = SemanticVersionManager.getCompatibilityLevel(v1, v2);
|
|
120
|
+
// 'backward-compatible'
|
|
121
|
+
|
|
122
|
+
// Resolve dependencies
|
|
123
|
+
const resolver = new DependencyResolver(logger);
|
|
124
|
+
|
|
125
|
+
const plugins = new Map([
|
|
126
|
+
['core', { dependencies: [] }],
|
|
127
|
+
['plugin-a', { dependencies: ['core'] }],
|
|
128
|
+
['plugin-b', { dependencies: ['core', 'plugin-a'] }],
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
const order = resolver.resolve(plugins);
|
|
132
|
+
// ['core', 'plugin-a', 'plugin-b']
|
|
133
|
+
|
|
134
|
+
// Detect conflicts
|
|
135
|
+
const conflicts = resolver.detectConflicts(pluginsWithVersions);
|
|
136
|
+
|
|
137
|
+
// Find best version
|
|
138
|
+
const best = resolver.findBestVersion(
|
|
139
|
+
['1.0.0', '1.1.0', '1.2.0', '2.0.0'],
|
|
140
|
+
['^1.0.0', '>=1.1.0']
|
|
141
|
+
);
|
|
142
|
+
// '1.2.0'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 4. Permission Manager (`security/permission-manager.ts`)
|
|
146
|
+
|
|
147
|
+
The Permission Manager enforces fine-grained access control for plugins.
|
|
148
|
+
|
|
149
|
+
**Features:**
|
|
150
|
+
- Resource-level permissions (data, UI, system, storage, network, process)
|
|
151
|
+
- Action-based access control (create, read, update, delete, execute, etc.)
|
|
152
|
+
- Permission scopes (global, tenant, user, resource, plugin)
|
|
153
|
+
- Grant/revoke mechanisms
|
|
154
|
+
- Permission expiration
|
|
155
|
+
- Required vs optional permissions
|
|
156
|
+
- Field-level access control
|
|
157
|
+
|
|
158
|
+
**Usage:**
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { PluginPermissionManager } from '@objectstack/core/security';
|
|
162
|
+
|
|
163
|
+
const permManager = new PluginPermissionManager(logger);
|
|
164
|
+
|
|
165
|
+
// Register permissions
|
|
166
|
+
permManager.registerPermissions('my-plugin', {
|
|
167
|
+
permissions: [
|
|
168
|
+
{
|
|
169
|
+
id: 'read-customer-data',
|
|
170
|
+
resource: 'data.object',
|
|
171
|
+
actions: ['read'],
|
|
172
|
+
scope: 'plugin',
|
|
173
|
+
description: 'Read customer data',
|
|
174
|
+
required: true,
|
|
175
|
+
filter: {
|
|
176
|
+
resourceIds: ['customer'],
|
|
177
|
+
fields: ['name', 'email'],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
defaultGrant: 'prompt',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Grant permission
|
|
185
|
+
permManager.grantPermission('my-plugin', 'read-customer-data', 'admin');
|
|
186
|
+
|
|
187
|
+
// Check access
|
|
188
|
+
const result = permManager.checkAccess(
|
|
189
|
+
'my-plugin',
|
|
190
|
+
'data.object',
|
|
191
|
+
'read',
|
|
192
|
+
'customer'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if (result.allowed) {
|
|
196
|
+
// Proceed with operation
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Check all required permissions
|
|
200
|
+
const hasAll = permManager.hasAllRequiredPermissions('my-plugin');
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 5. Sandbox Runtime (`security/sandbox-runtime.ts`)
|
|
204
|
+
|
|
205
|
+
The Sandbox Runtime provides isolated execution environments with resource limits.
|
|
206
|
+
|
|
207
|
+
**Features:**
|
|
208
|
+
- Multiple isolation levels (none, minimal, standard, strict, paranoid)
|
|
209
|
+
- File system access control (allowed/denied paths)
|
|
210
|
+
- Network access control (allowed/blocked hosts)
|
|
211
|
+
- Process spawning control
|
|
212
|
+
- Environment variable access control
|
|
213
|
+
- Resource limit enforcement (memory, CPU, connections)
|
|
214
|
+
- Resource usage monitoring
|
|
215
|
+
|
|
216
|
+
**Usage:**
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { PluginSandboxRuntime } from '@objectstack/core/security';
|
|
220
|
+
|
|
221
|
+
const sandbox = new PluginSandboxRuntime(logger);
|
|
222
|
+
|
|
223
|
+
// Create sandbox
|
|
224
|
+
const context = sandbox.createSandbox('my-plugin', {
|
|
225
|
+
enabled: true,
|
|
226
|
+
level: 'standard',
|
|
227
|
+
filesystem: {
|
|
228
|
+
mode: 'restricted',
|
|
229
|
+
allowedPaths: ['/app/plugins/my-plugin'],
|
|
230
|
+
deniedPaths: ['/etc', '/root'],
|
|
231
|
+
},
|
|
232
|
+
network: {
|
|
233
|
+
mode: 'restricted',
|
|
234
|
+
allowedHosts: ['api.example.com'],
|
|
235
|
+
blockedHosts: ['malicious.com'],
|
|
236
|
+
maxConnections: 10,
|
|
237
|
+
},
|
|
238
|
+
process: {
|
|
239
|
+
allowSpawn: false,
|
|
240
|
+
},
|
|
241
|
+
memory: {
|
|
242
|
+
maxHeap: 100 * 1024 * 1024, // 100 MB
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Check resource access
|
|
247
|
+
const fileAccess = sandbox.checkResourceAccess(
|
|
248
|
+
'my-plugin',
|
|
249
|
+
'file',
|
|
250
|
+
'/app/plugins/my-plugin/data.json'
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const netAccess = sandbox.checkResourceAccess(
|
|
254
|
+
'my-plugin',
|
|
255
|
+
'network',
|
|
256
|
+
'https://api.example.com/data'
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// Check resource limits
|
|
260
|
+
const { withinLimits, violations } = sandbox.checkResourceLimits('my-plugin');
|
|
261
|
+
|
|
262
|
+
// Get resource usage
|
|
263
|
+
const usage = sandbox.getResourceUsage('my-plugin');
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 6. Security Scanner (`security/security-scanner.ts`)
|
|
267
|
+
|
|
268
|
+
The Security Scanner performs comprehensive security analysis of plugins.
|
|
269
|
+
|
|
270
|
+
**Features:**
|
|
271
|
+
- Code vulnerability scanning
|
|
272
|
+
- Dependency vulnerability detection (CVE database integration)
|
|
273
|
+
- Malware pattern detection
|
|
274
|
+
- License compliance checking
|
|
275
|
+
- Configuration security analysis
|
|
276
|
+
- Security scoring (0-100)
|
|
277
|
+
- Issue categorization (critical, high, medium, low, info)
|
|
278
|
+
|
|
279
|
+
**Usage:**
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { PluginSecurityScanner } from '@objectstack/core/security';
|
|
283
|
+
|
|
284
|
+
const scanner = new PluginSecurityScanner(logger);
|
|
285
|
+
|
|
286
|
+
// Perform security scan
|
|
287
|
+
const result = await scanner.scan({
|
|
288
|
+
pluginId: 'my-plugin',
|
|
289
|
+
version: '1.0.0',
|
|
290
|
+
files: ['src/**/*.ts'],
|
|
291
|
+
dependencies: {
|
|
292
|
+
'express': '4.18.0',
|
|
293
|
+
'lodash': '4.17.21',
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
console.log(`Security Score: ${result.score}/100`);
|
|
298
|
+
console.log(`Passed: ${result.passed}`);
|
|
299
|
+
console.log(`Issues:`, result.summary);
|
|
300
|
+
|
|
301
|
+
// Add vulnerability to database
|
|
302
|
+
scanner.addVulnerability('lodash', '4.17.20', {
|
|
303
|
+
cve: 'CVE-2021-23337',
|
|
304
|
+
severity: 'high',
|
|
305
|
+
affectedVersions: ['<=4.17.20'],
|
|
306
|
+
fixedIn: ['4.17.21'],
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Update vulnerability database
|
|
310
|
+
await scanner.updateVulnerabilityDatabase();
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Integration with Kernel
|
|
314
|
+
|
|
315
|
+
These components are designed to integrate with the existing ObjectKernel:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import {
|
|
319
|
+
ObjectKernel,
|
|
320
|
+
PluginHealthMonitor,
|
|
321
|
+
HotReloadManager,
|
|
322
|
+
DependencyResolver,
|
|
323
|
+
PluginPermissionManager,
|
|
324
|
+
PluginSandboxRuntime,
|
|
325
|
+
PluginSecurityScanner
|
|
326
|
+
} from '@objectstack/core';
|
|
327
|
+
|
|
328
|
+
const kernel = new ObjectKernel({ logger: { level: 'info' } });
|
|
329
|
+
|
|
330
|
+
// Initialize Phase 2 components
|
|
331
|
+
const healthMonitor = new PluginHealthMonitor(kernel.logger);
|
|
332
|
+
const hotReload = new HotReloadManager(kernel.logger);
|
|
333
|
+
const depResolver = new DependencyResolver(kernel.logger);
|
|
334
|
+
const permManager = new PluginPermissionManager(kernel.logger);
|
|
335
|
+
const sandbox = new PluginSandboxRuntime(kernel.logger);
|
|
336
|
+
const scanner = new PluginSecurityScanner(kernel.logger);
|
|
337
|
+
|
|
338
|
+
// Register plugins with enhanced features
|
|
339
|
+
// ... plugin registration code ...
|
|
340
|
+
|
|
341
|
+
// Bootstrap kernel
|
|
342
|
+
await kernel.bootstrap();
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Testing
|
|
346
|
+
|
|
347
|
+
Comprehensive unit tests are provided for all components:
|
|
348
|
+
|
|
349
|
+
- `health-monitor.test.ts` - Health monitoring tests
|
|
350
|
+
- `dependency-resolver.test.ts` - SemVer and dependency resolution tests
|
|
351
|
+
- `security/permission-manager.test.ts` - Permission management tests
|
|
352
|
+
|
|
353
|
+
Run tests with:
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
npm test
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Performance Considerations
|
|
360
|
+
|
|
361
|
+
- Health checks run in separate intervals to avoid blocking
|
|
362
|
+
- State preservation uses checksums for integrity verification
|
|
363
|
+
- Dependency resolution uses efficient topological sorting
|
|
364
|
+
- Resource monitoring is throttled (default 5 seconds)
|
|
365
|
+
- Security scanning can be run asynchronously
|
|
366
|
+
|
|
367
|
+
## Security
|
|
368
|
+
|
|
369
|
+
- All permissions must be explicitly granted
|
|
370
|
+
- Sandbox provides multiple isolation levels
|
|
371
|
+
- Security scanner integrates with CVE databases
|
|
372
|
+
- Resource limits prevent DoS attacks
|
|
373
|
+
- State preservation uses checksums to detect tampering
|
|
374
|
+
|
|
375
|
+
## Future Enhancements
|
|
376
|
+
|
|
377
|
+
Phase 3 and beyond will add:
|
|
378
|
+
- Plugin marketplace integration
|
|
379
|
+
- AI-powered plugin development
|
|
380
|
+
- Enhanced monitoring and observability
|
|
381
|
+
- Distributed plugin management
|
|
382
|
+
- Advanced security features
|
|
383
|
+
|
|
384
|
+
## References
|
|
385
|
+
|
|
386
|
+
- [MICROKERNEL_IMPROVEMENT_PLAN.md](../../MICROKERNEL_IMPROVEMENT_PLAN.md)
|
|
387
|
+
- [ARCHITECTURE.md](../../ARCHITECTURE.md)
|
|
388
|
+
- [Protocol Definitions](../spec/src/system/)
|