@majkapp/plugin-kit 1.0.8 → 1.0.9
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/dist/plugin-kit.d.ts.map +1 -1
- package/dist/plugin-kit.js +27 -3
- package/package.json +1 -1
package/dist/plugin-kit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-kit.d.ts","sourceRoot":"","sources":["../src/plugin-kit.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EAGb,eAAe,EACf,QAAQ,EACR,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EACX,UAAU,EACV,eAAe,EACf,WAAW,EACX,KAAK,EACL,UAAU,EACV,SAAS,EACT,aAAa,EAIb,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-kit.d.ts","sourceRoot":"","sources":["../src/plugin-kit.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EAGb,eAAe,EACf,QAAQ,EACR,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EACX,UAAU,EACV,eAAe,EACf,WAAW,EACX,KAAK,EACL,UAAU,EACV,SAAS,EACT,aAAa,EAIb,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAwsBjB;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,EAAE,SAAS,MAAM;IAC9C,mDAAmD;IACnD,MAAM,CAAC,KAAK,EAAE,mBAAmB,EAAE,IAAI,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAE7G,0CAA0C;IAC1C,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAE5B,yBAAyB;IACz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EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,aAAa,CAAC,EAAE,CAAC,CAkVnB"}
|
package/dist/plugin-kit.js
CHANGED
|
@@ -448,11 +448,18 @@ class BuiltPlugin {
|
|
|
448
448
|
async startServer() {
|
|
449
449
|
const { port } = this.context.http;
|
|
450
450
|
this.server = http_1.default.createServer(async (req, res) => {
|
|
451
|
+
const startTime = Date.now();
|
|
452
|
+
const method = req.method || 'UNKNOWN';
|
|
453
|
+
const url = req.url || '/';
|
|
451
454
|
try {
|
|
455
|
+
// Log incoming request
|
|
456
|
+
this.context.logger.debug(`→ ${method} ${url}`);
|
|
452
457
|
// CORS preflight
|
|
453
458
|
if (req.method === 'OPTIONS') {
|
|
454
459
|
res.writeHead(204, corsHeaders());
|
|
455
460
|
res.end();
|
|
461
|
+
const duration = Date.now() - startTime;
|
|
462
|
+
this.context.logger.debug(`← ${method} ${url} 204 (${duration}ms)`);
|
|
456
463
|
return;
|
|
457
464
|
}
|
|
458
465
|
// Health check
|
|
@@ -460,6 +467,8 @@ class BuiltPlugin {
|
|
|
460
467
|
const health = await this.isHealthy();
|
|
461
468
|
res.writeHead(200, corsHeaders({ 'Content-Type': 'application/json' }));
|
|
462
469
|
res.end(JSON.stringify({ ...health, plugin: this.name, version: this.version }));
|
|
470
|
+
const duration = Date.now() - startTime;
|
|
471
|
+
this.context.logger.debug(`← ${method} ${url} 200 (${duration}ms)`);
|
|
463
472
|
return;
|
|
464
473
|
}
|
|
465
474
|
// HTML screens virtual route
|
|
@@ -469,6 +478,8 @@ class BuiltPlugin {
|
|
|
469
478
|
if (!screen) {
|
|
470
479
|
res.writeHead(404, corsHeaders({ 'Content-Type': 'text/plain' }));
|
|
471
480
|
res.end('HTML screen not found');
|
|
481
|
+
const duration = Date.now() - startTime;
|
|
482
|
+
this.context.logger.debug(`← ${method} ${url} 404 (${duration}ms)`);
|
|
472
483
|
return;
|
|
473
484
|
}
|
|
474
485
|
res.writeHead(200, corsHeaders({ 'Content-Type': 'text/html; charset=utf-8' }));
|
|
@@ -484,6 +495,8 @@ class BuiltPlugin {
|
|
|
484
495
|
res.writeHead(403, corsHeaders({ 'Content-Type': 'text/plain' }));
|
|
485
496
|
res.end('Forbidden');
|
|
486
497
|
this.context.logger.warn(`Path traversal attempt: ${screen.htmlFile}`);
|
|
498
|
+
const duration = Date.now() - startTime;
|
|
499
|
+
this.context.logger.debug(`← ${method} ${url} 403 (${duration}ms)`);
|
|
487
500
|
return;
|
|
488
501
|
}
|
|
489
502
|
try {
|
|
@@ -493,13 +506,20 @@ class BuiltPlugin {
|
|
|
493
506
|
this.context.logger.error(`Failed to read HTML file: ${error.message}`);
|
|
494
507
|
res.writeHead(500, corsHeaders({ 'Content-Type': 'text/html' }));
|
|
495
508
|
res.end('<!doctype html><html><body><h1>Error loading screen</h1></body></html>');
|
|
509
|
+
const duration = Date.now() - startTime;
|
|
510
|
+
this.context.logger.debug(`← ${method} ${url} 500 (${duration}ms)`);
|
|
511
|
+
return;
|
|
496
512
|
}
|
|
497
513
|
}
|
|
514
|
+
const duration = Date.now() - startTime;
|
|
515
|
+
this.context.logger.debug(`← ${method} ${url} 200 (${duration}ms)`);
|
|
498
516
|
return;
|
|
499
517
|
}
|
|
500
518
|
// React SPA
|
|
501
519
|
if (req.method === 'GET' && this.uiConfig && req.url?.startsWith(this.uiConfig.base)) {
|
|
502
520
|
serveSpa(this.uiConfig, req, res, this.context);
|
|
521
|
+
const duration = Date.now() - startTime;
|
|
522
|
+
this.context.logger.debug(`← ${method} ${url} ${res.statusCode || 200} (${duration}ms)`);
|
|
503
523
|
return;
|
|
504
524
|
}
|
|
505
525
|
// API routes
|
|
@@ -516,6 +536,8 @@ class BuiltPlugin {
|
|
|
516
536
|
method,
|
|
517
537
|
hint: `Available routes: ${this.router.map(r => `${r.method} ${r.name}`).join(', ')}`
|
|
518
538
|
}));
|
|
539
|
+
const duration = Date.now() - startTime;
|
|
540
|
+
this.context.logger.debug(`← ${method} ${pathname} 404 (${duration}ms)`);
|
|
519
541
|
return;
|
|
520
542
|
}
|
|
521
543
|
const body = await readBody(req);
|
|
@@ -541,16 +563,16 @@ class BuiltPlugin {
|
|
|
541
563
|
http: this.context.http
|
|
542
564
|
};
|
|
543
565
|
try {
|
|
544
|
-
this.context.logger.debug(`📥 ${method} ${pathname}`, { params, body });
|
|
545
566
|
const result = await route.handler(request, response, routeContext);
|
|
546
567
|
if (!res.headersSent) {
|
|
547
568
|
res.writeHead(200, corsHeaders({ 'Content-Type': 'application/json' }));
|
|
548
569
|
res.end(JSON.stringify(result ?? { success: true }));
|
|
549
570
|
}
|
|
550
|
-
|
|
571
|
+
const duration = Date.now() - startTime;
|
|
572
|
+
this.context.logger.debug(`← ${method} ${pathname} ${res.statusCode || 200} (${duration}ms)`);
|
|
551
573
|
}
|
|
552
574
|
catch (error) {
|
|
553
|
-
this.context.logger.error(
|
|
575
|
+
this.context.logger.error(`API route error: ${method} ${pathname} - ${error.message}`);
|
|
554
576
|
if (error.stack) {
|
|
555
577
|
this.context.logger.error(error.stack);
|
|
556
578
|
}
|
|
@@ -562,6 +584,8 @@ class BuiltPlugin {
|
|
|
562
584
|
path: pathname
|
|
563
585
|
}));
|
|
564
586
|
}
|
|
587
|
+
const duration = Date.now() - startTime;
|
|
588
|
+
this.context.logger.debug(`← ${method} ${pathname} 500 (${duration}ms)`);
|
|
565
589
|
}
|
|
566
590
|
return;
|
|
567
591
|
}
|