@luisrodrigues/nestjs-scheduler-dashboard 0.0.4 → 0.0.6

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.
@@ -18,6 +18,14 @@ export declare class DashboardController {
18
18
  name: string;
19
19
  }[];
20
20
  };
21
+ getJob(name: string): {
22
+ name: string;
23
+ cronExpression: any;
24
+ running: boolean;
25
+ nextRun: string;
26
+ history: import(".").JobExecution[];
27
+ metrics: import(".").JobMetrics;
28
+ };
21
29
  triggerJob(name: string): {
22
30
  triggered: string;
23
31
  };
@@ -22,6 +22,12 @@ let DashboardController = class DashboardController {
22
22
  getJobs() {
23
23
  return this.jobsService.getJobs();
24
24
  }
25
+ getJob(name) {
26
+ const job = this.jobsService.getJob(name);
27
+ if (!job)
28
+ throw new common_1.HttpException(`Job "${name}" not found`, common_1.HttpStatus.NOT_FOUND);
29
+ return job;
30
+ }
25
31
  triggerJob(name) {
26
32
  const ok = this.jobsService.triggerJob(name);
27
33
  if (!ok)
@@ -42,6 +48,13 @@ __decorate([
42
48
  __metadata("design:paramtypes", []),
43
49
  __metadata("design:returntype", void 0)
44
50
  ], DashboardController.prototype, "getJobs", null);
51
+ __decorate([
52
+ (0, common_1.Get)(':name'),
53
+ __param(0, (0, common_1.Param)('name')),
54
+ __metadata("design:type", Function),
55
+ __metadata("design:paramtypes", [String]),
56
+ __metadata("design:returntype", void 0)
57
+ ], DashboardController.prototype, "getJob", null);
45
58
  __decorate([
46
59
  (0, common_1.Post)(':name/trigger'),
47
60
  __param(0, (0, common_1.Param)('name')),
@@ -20,6 +20,14 @@ export declare class JobsService {
20
20
  name: string;
21
21
  }[];
22
22
  };
23
+ getJob(name: string): {
24
+ name: string;
25
+ cronExpression: any;
26
+ running: boolean;
27
+ nextRun: string;
28
+ history: import(".").JobExecution[];
29
+ metrics: import(".").JobMetrics;
30
+ };
23
31
  triggerJob(name: string): boolean;
24
32
  stopExecution(executionId: string): boolean;
25
33
  }
@@ -20,6 +20,19 @@ class JobsService {
20
20
  const timeouts = this.schedulerRegistry.getTimeouts().map((name) => ({ name }));
21
21
  return { cron, intervals, timeouts };
22
22
  }
23
+ getJob(name) {
24
+ const job = this.schedulerRegistry.getCronJobs().get(name);
25
+ if (!job)
26
+ return null;
27
+ return {
28
+ name,
29
+ cronExpression: job.cronTime.source?.toString() ?? null,
30
+ running: job.running ?? false,
31
+ nextRun: job.nextDate()?.toISO() ?? null,
32
+ history: this.storage.findByJob(name),
33
+ metrics: this.storage.getMetrics(name),
34
+ };
35
+ }
23
36
  triggerJob(name) {
24
37
  const job = this.schedulerRegistry.getCronJobs().get(name);
25
38
  if (!job)
@@ -9,30 +9,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.startStandaloneServer = startStandaloneServer;
10
10
  const core_1 = require("@nestjs/core");
11
11
  const common_1 = require("@nestjs/common");
12
- const serve_static_1 = require("@nestjs/serve-static");
13
12
  const path_1 = require("path");
13
+ const fs_1 = require("fs");
14
14
  const jobs_service_1 = require("./jobs.service");
15
15
  const dashboard_controller_1 = require("./dashboard.controller");
16
16
  const auth_1 = require("./auth");
17
17
  const UI_PATH = (0, path_1.join)(__dirname, '../ui');
18
18
  async function startStandaloneServer(port, jobsService, auth, logger) {
19
+ const indexHtml = (0, fs_1.readFileSync)((0, path_1.join)(UI_PATH, 'index.html'), 'utf-8');
19
20
  let DashboardHttpApp = class DashboardHttpApp {
20
21
  };
21
22
  DashboardHttpApp = __decorate([
22
23
  (0, common_1.Module)({
23
- imports: [
24
- serve_static_1.ServeStaticModule.forRoot({
25
- rootPath: UI_PATH,
26
- exclude: ['/api/(.*)'],
27
- }),
28
- ],
29
24
  controllers: [dashboard_controller_1.DashboardController],
30
25
  providers: [{ provide: jobs_service_1.JobsService, useValue: jobsService }],
31
26
  })
32
27
  ], DashboardHttpApp);
33
- const app = await core_1.NestFactory.create(DashboardHttpApp, { logger: false });
34
- app.use((0, auth_1.createAuthGuard)(auth));
35
- await app.listen(port);
28
+ const nestApp = await core_1.NestFactory.create(DashboardHttpApp, { logger: false });
29
+ const app = nestApp.getHttpAdapter().getInstance();
30
+ const guard = (0, auth_1.createAuthGuard)(auth);
31
+ app.use((req, res, next) => {
32
+ if (req.path.startsWith('/api'))
33
+ return next();
34
+ const filePath = (0, path_1.join)(UI_PATH, req.path);
35
+ if (req.path.includes('.') && (0, fs_1.existsSync)(filePath)) {
36
+ const ext = req.path.split('.').pop()?.toLowerCase();
37
+ const mimeTypes = {
38
+ js: 'application/javascript',
39
+ css: 'text/css',
40
+ html: 'text/html',
41
+ json: 'application/json',
42
+ png: 'image/png',
43
+ svg: 'image/svg+xml',
44
+ ico: 'image/x-icon',
45
+ };
46
+ res.setHeader('Content-Type', mimeTypes[ext ?? ''] ?? 'application/octet-stream');
47
+ (0, fs_1.createReadStream)(filePath).pipe(res);
48
+ return;
49
+ }
50
+ guard(req, res, () => {
51
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
52
+ res.send(indexHtml);
53
+ });
54
+ });
55
+ await nestApp.listen(port);
36
56
  logger.log(`Dashboard running at http://localhost:${port}`);
37
- return app;
57
+ return nestApp;
38
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luisrodrigues/nestjs-scheduler-dashboard",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Dashboard for @nestjs/schedule — embedded UI, job history, metrics, stop/trigger controls",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,6 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@nestjs/platform-express": "^10.0.0",
30
- "@nestjs/serve-static": "^4.0.0",
31
30
  "zod": "^4.3.6"
32
31
  },
33
32
  "keywords": [