agendash 4.0.0 → 6.0.1
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/LICENSE.md +25 -0
- package/README.md +109 -200
- package/dist/AgendashController.d.ts +50 -0
- package/dist/AgendashController.js +176 -0
- package/dist/AgendashController.js.map +1 -0
- package/dist/csp.d.ts +1 -0
- package/dist/csp.js +15 -0
- package/dist/csp.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/express.d.ts +22 -0
- package/dist/middlewares/express.js +119 -0
- package/dist/middlewares/express.js.map +1 -0
- package/dist/middlewares/fastify.d.ts +18 -0
- package/dist/middlewares/fastify.js +129 -0
- package/dist/middlewares/fastify.js.map +1 -0
- package/dist/middlewares/hapi.d.ts +28 -0
- package/dist/middlewares/hapi.js +198 -0
- package/dist/middlewares/hapi.js.map +1 -0
- package/dist/middlewares/koa.d.ts +25 -0
- package/dist/middlewares/koa.js +139 -0
- package/dist/middlewares/koa.js.map +1 -0
- package/dist/types.d.ts +154 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +77 -62
- package/public/assets/index-CIdOb8D1.css +5 -0
- package/public/assets/index-Ct6Ovrls.js +17 -0
- package/public/index.html +10 -52
- package/Dockerfile +0 -23
- package/History.md +0 -118
- package/LICENSE +0 -21
- package/all-jobs.png +0 -0
- package/app.js +0 -23
- package/bin/agendash-standalone-fastify.js +0 -61
- package/bin/agendash-standalone-hapi.js +0 -60
- package/bin/agendash-standalone-koa.js +0 -56
- package/bin/agendash-standalone.js +0 -64
- package/create-job.png +0 -0
- package/entrypoint.sh +0 -5
- package/lib/controllers/agendash.js +0 -341
- package/lib/csp.js +0 -28
- package/lib/middlewares/README.md +0 -59
- package/lib/middlewares/express.js +0 -80
- package/lib/middlewares/fastify.js +0 -77
- package/lib/middlewares/hapi.js +0 -101
- package/lib/middlewares/koa.js +0 -77
- package/mobile-ui-sm.png +0 -0
- package/mobile-ui-xs.png +0 -0
- package/public/android-chrome-192x192.png +0 -0
- package/public/android-chrome-512x512.png +0 -0
- package/public/app/assets/ArgensdashV2Logo.svg +0 -18
- package/public/app/css/styles.css +0 -233
- package/public/app/js/confirmDelete.js +0 -40
- package/public/app/js/confirmDeleteMulti.js +0 -45
- package/public/app/js/confirmRequeue.js +0 -40
- package/public/app/js/confirmRequeueMulti.js +0 -45
- package/public/app/js/confirms.js +0 -8
- package/public/app/js/jobdetail.js +0 -48
- package/public/app/js/joblist.js +0 -248
- package/public/app/js/main.js +0 -283
- package/public/app/js/newJob.js +0 -89
- package/public/app/js/sidebar.js +0 -121
- package/public/app/js/topbar.js +0 -95
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/site.webmanifest +0 -1
- package/search.png +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agendash - Dashboard for Agenda job scheduler
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// Core exports
|
|
7
|
+
export { AgendashController } from './AgendashController.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export { cspHeader } from './csp.js';
|
|
10
|
+
// Express middleware (most common)
|
|
11
|
+
export { createExpressMiddleware } from './middlewares/express.js';
|
|
12
|
+
// Other middlewares - exported from subpaths for tree-shaking
|
|
13
|
+
export { createKoaMiddleware, createKoaMiddlewareAsync } from './middlewares/koa.js';
|
|
14
|
+
export { createFastifyPlugin } from './middlewares/fastify.js';
|
|
15
|
+
export { createHapiPlugin } from './middlewares/hapi.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAe;AACf,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,mCAAmC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,8DAA8D;AAC9D,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import type { Agenda } from 'agenda';
|
|
3
|
+
export interface ExpressMiddlewareOptions {
|
|
4
|
+
/** Skip static file serving (useful for dev mode with Vite) */
|
|
5
|
+
skipStaticFiles?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create Express middleware for Agendash
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import express from 'express';
|
|
13
|
+
* import { Agenda } from 'agenda';
|
|
14
|
+
* import { createExpressMiddleware } from 'agendash';
|
|
15
|
+
*
|
|
16
|
+
* const app = express();
|
|
17
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
18
|
+
*
|
|
19
|
+
* app.use('/dash', createExpressMiddleware(agenda));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function createExpressMiddleware(agenda: Agenda, options?: ExpressMiddlewareOptions): Router;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Router, static as serveStatic, json, urlencoded } from 'express';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { AgendashController } from '../AgendashController.js';
|
|
5
|
+
import { cspHeader } from '../csp.js';
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
/**
|
|
8
|
+
* Create Express middleware for Agendash
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import express from 'express';
|
|
13
|
+
* import { Agenda } from 'agenda';
|
|
14
|
+
* import { createExpressMiddleware } from 'agendash';
|
|
15
|
+
*
|
|
16
|
+
* const app = express();
|
|
17
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
18
|
+
*
|
|
19
|
+
* app.use('/dash', createExpressMiddleware(agenda));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function createExpressMiddleware(agenda, options = {}) {
|
|
23
|
+
const controller = new AgendashController(agenda);
|
|
24
|
+
const router = Router();
|
|
25
|
+
// Body parsing
|
|
26
|
+
router.use(json());
|
|
27
|
+
router.use(urlencoded({ extended: false }));
|
|
28
|
+
// CSP header
|
|
29
|
+
router.use((_req, res, next) => {
|
|
30
|
+
res.header('Content-Security-Policy', cspHeader);
|
|
31
|
+
next();
|
|
32
|
+
});
|
|
33
|
+
// Static files (skip in dev mode when using Vite)
|
|
34
|
+
if (!options.skipStaticFiles) {
|
|
35
|
+
router.use('/', serveStatic(join(__dirname, '../../public')));
|
|
36
|
+
}
|
|
37
|
+
// API routes
|
|
38
|
+
router.get('/api', async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const query = req.query;
|
|
41
|
+
const params = {
|
|
42
|
+
name: query.job,
|
|
43
|
+
state: query.state,
|
|
44
|
+
search: query.q,
|
|
45
|
+
property: query.property,
|
|
46
|
+
isObjectId: query.isObjectId,
|
|
47
|
+
skip: query.skip ? parseInt(query.skip, 10) : 0,
|
|
48
|
+
limit: query.limit ? parseInt(query.limit, 10) : 50
|
|
49
|
+
};
|
|
50
|
+
const result = await controller.getJobs(params);
|
|
51
|
+
res.json(result);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
res.status(400).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
router.post('/api/jobs/requeue', async (req, res) => {
|
|
58
|
+
try {
|
|
59
|
+
const { jobIds } = req.body;
|
|
60
|
+
const result = await controller.requeueJobs(jobIds);
|
|
61
|
+
res.json(result);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
res.status(404).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
router.post('/api/jobs/delete', async (req, res) => {
|
|
68
|
+
try {
|
|
69
|
+
const { jobIds } = req.body;
|
|
70
|
+
const result = await controller.deleteJobs(jobIds);
|
|
71
|
+
res.json(result);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
res.status(404).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
router.post('/api/jobs/create', async (req, res) => {
|
|
78
|
+
try {
|
|
79
|
+
const options = req.body;
|
|
80
|
+
const result = await controller.createJob(options);
|
|
81
|
+
res.json(result);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
res.status(400).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
router.post('/api/jobs/pause', async (req, res) => {
|
|
88
|
+
try {
|
|
89
|
+
const { jobIds } = req.body;
|
|
90
|
+
const result = await controller.pauseJobs(jobIds);
|
|
91
|
+
res.json(result);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
res.status(400).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
router.post('/api/jobs/resume', async (req, res) => {
|
|
98
|
+
try {
|
|
99
|
+
const { jobIds } = req.body;
|
|
100
|
+
const result = await controller.resumeJobs(jobIds);
|
|
101
|
+
res.json(result);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
res.status(400).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
router.get('/api/stats', async (req, res) => {
|
|
108
|
+
try {
|
|
109
|
+
const fullDetails = req.query.fullDetails === 'true';
|
|
110
|
+
const result = await controller.getStats(fullDetails);
|
|
111
|
+
res.json(result);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return router;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/middlewares/express.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAO1D;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAc,EAAE,UAAoC,EAAE;IAC7F,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB,eAAe;IACf,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE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|
+
* import Fastify from 'fastify';
|
|
9
|
+
* import { Agenda } from 'agenda';
|
|
10
|
+
* import { createFastifyPlugin } from 'agendash';
|
|
11
|
+
*
|
|
12
|
+
* const fastify = Fastify();
|
|
13
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
14
|
+
*
|
|
15
|
+
* fastify.register(createFastifyPlugin(agenda), { prefix: '/dash' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function createFastifyPlugin(agenda: Agenda): FastifyPluginCallback;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { join, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { AgendashController } from '../AgendashController.js';
|
|
4
|
+
import { cspHeader } from '../csp.js';
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
/**
|
|
7
|
+
* Create Fastify plugin for Agendash
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import Fastify from 'fastify';
|
|
12
|
+
* import { Agenda } from 'agenda';
|
|
13
|
+
* import { createFastifyPlugin } from 'agendash';
|
|
14
|
+
*
|
|
15
|
+
* const fastify = Fastify();
|
|
16
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
17
|
+
*
|
|
18
|
+
* fastify.register(createFastifyPlugin(agenda), { prefix: '/dash' });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createFastifyPlugin(agenda) {
|
|
22
|
+
const controller = new AgendashController(agenda);
|
|
23
|
+
return async (instance) => {
|
|
24
|
+
// Register static file serving
|
|
25
|
+
const fastifyStatic = await import('@fastify/static');
|
|
26
|
+
await instance.register(fastifyStatic.default, {
|
|
27
|
+
root: join(__dirname, '../../public')
|
|
28
|
+
});
|
|
29
|
+
// Index route with CSP header
|
|
30
|
+
instance.get('/', async (_request, reply) => {
|
|
31
|
+
reply.header('Content-Security-Policy', cspHeader);
|
|
32
|
+
return reply.sendFile('index.html');
|
|
33
|
+
});
|
|
34
|
+
// API routes
|
|
35
|
+
instance.get('/api', async (request, reply) => {
|
|
36
|
+
try {
|
|
37
|
+
const { job, state, q, property, isObjectId, skip, limit } = request.query;
|
|
38
|
+
const params = {
|
|
39
|
+
name: job,
|
|
40
|
+
state,
|
|
41
|
+
search: q,
|
|
42
|
+
property,
|
|
43
|
+
isObjectId,
|
|
44
|
+
skip: skip ? parseInt(skip, 10) : 0,
|
|
45
|
+
limit: limit ? parseInt(limit, 10) : 50
|
|
46
|
+
};
|
|
47
|
+
const result = await controller.getJobs(params);
|
|
48
|
+
return reply.send(result);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return reply
|
|
52
|
+
.status(400)
|
|
53
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
instance.post('/api/jobs/requeue', async (request, reply) => {
|
|
57
|
+
try {
|
|
58
|
+
const { jobIds } = request.body;
|
|
59
|
+
const result = await controller.requeueJobs(jobIds);
|
|
60
|
+
return reply.send(result);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return reply
|
|
64
|
+
.status(404)
|
|
65
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
instance.post('/api/jobs/delete', async (request, reply) => {
|
|
69
|
+
try {
|
|
70
|
+
const { jobIds } = request.body;
|
|
71
|
+
const result = await controller.deleteJobs(jobIds);
|
|
72
|
+
return reply.send(result);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return reply
|
|
76
|
+
.status(404)
|
|
77
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
instance.post('/api/jobs/create', async (request, reply) => {
|
|
81
|
+
try {
|
|
82
|
+
const result = await controller.createJob(request.body);
|
|
83
|
+
return reply.send(result);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return reply
|
|
87
|
+
.status(400)
|
|
88
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
instance.post('/api/jobs/pause', async (request, reply) => {
|
|
92
|
+
try {
|
|
93
|
+
const { jobIds } = request.body;
|
|
94
|
+
const result = await controller.pauseJobs(jobIds);
|
|
95
|
+
return reply.send(result);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return reply
|
|
99
|
+
.status(400)
|
|
100
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
instance.post('/api/jobs/resume', async (request, reply) => {
|
|
104
|
+
try {
|
|
105
|
+
const { jobIds } = request.body;
|
|
106
|
+
const result = await controller.resumeJobs(jobIds);
|
|
107
|
+
return reply.send(result);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return reply
|
|
111
|
+
.status(400)
|
|
112
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
instance.get('/api/stats', async (request, reply) => {
|
|
116
|
+
try {
|
|
117
|
+
const fullDetails = request.query.fullDetails === 'true';
|
|
118
|
+
const result = await controller.getStats(fullDetails);
|
|
119
|
+
return reply.send(result);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
return reply
|
|
123
|
+
.status(500)
|
|
124
|
+
.send({ error: error instanceof Error ? error.message : 'Unknown error' });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/middlewares/fastify.ts"],"names":[],"mappings":"AAAA,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AAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,KAAK;qBACV,MAAM,CAAC,GAAG,CAAC;qBACX,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YAC7E,CAAC;QACF,CAAC,CACD,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Agenda } from 'agenda';
|
|
2
|
+
import type { Plugin } from '@hapi/hapi';
|
|
3
|
+
interface AgendashHapiOptions {
|
|
4
|
+
auth?: string | false;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create Hapi plugin for Agendash
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import Hapi from '@hapi/hapi';
|
|
12
|
+
* import Inert from '@hapi/inert';
|
|
13
|
+
* import { Agenda } from 'agenda';
|
|
14
|
+
* import { createHapiPlugin } from 'agendash';
|
|
15
|
+
*
|
|
16
|
+
* const server = Hapi.server({ port: 3000 });
|
|
17
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
18
|
+
*
|
|
19
|
+
* await server.register(Inert);
|
|
20
|
+
* await server.register({
|
|
21
|
+
* plugin: createHapiPlugin(agenda),
|
|
22
|
+
* options: { auth: false },
|
|
23
|
+
* routes: { prefix: '/dash' }
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createHapiPlugin(agenda: Agenda): Plugin<AgendashHapiOptions>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { join, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { AgendashController } from '../AgendashController.js';
|
|
4
|
+
import { cspHeader } from '../csp.js';
|
|
5
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
/**
|
|
7
|
+
* Create Hapi plugin for Agendash
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import Hapi from '@hapi/hapi';
|
|
12
|
+
* import Inert from '@hapi/inert';
|
|
13
|
+
* import { Agenda } from 'agenda';
|
|
14
|
+
* import { createHapiPlugin } from 'agendash';
|
|
15
|
+
*
|
|
16
|
+
* const server = Hapi.server({ port: 3000 });
|
|
17
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
18
|
+
*
|
|
19
|
+
* await server.register(Inert);
|
|
20
|
+
* await server.register({
|
|
21
|
+
* plugin: createHapiPlugin(agenda),
|
|
22
|
+
* options: { auth: false },
|
|
23
|
+
* routes: { prefix: '/dash' }
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function createHapiPlugin(agenda) {
|
|
28
|
+
const controller = new AgendashController(agenda);
|
|
29
|
+
return {
|
|
30
|
+
name: 'agendash',
|
|
31
|
+
version: '6.0.0',
|
|
32
|
+
register: async (server, options) => {
|
|
33
|
+
const authConfig = options.auth ?? false;
|
|
34
|
+
// CSP header on all responses
|
|
35
|
+
server.ext('onPreResponse', (request, h) => {
|
|
36
|
+
const response = request.response;
|
|
37
|
+
if ('header' in response && typeof response.header === 'function') {
|
|
38
|
+
response.header('Content-Security-Policy', cspHeader);
|
|
39
|
+
}
|
|
40
|
+
return h.continue;
|
|
41
|
+
});
|
|
42
|
+
// Static files
|
|
43
|
+
server.route({
|
|
44
|
+
method: 'GET',
|
|
45
|
+
path: '/{param*}',
|
|
46
|
+
handler: {
|
|
47
|
+
directory: {
|
|
48
|
+
path: join(__dirname, '../../public')
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
options: {
|
|
52
|
+
auth: authConfig
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
// API routes
|
|
56
|
+
server.route({
|
|
57
|
+
method: 'GET',
|
|
58
|
+
path: '/api',
|
|
59
|
+
handler: async (request, h) => {
|
|
60
|
+
try {
|
|
61
|
+
const query = request.query;
|
|
62
|
+
const params = {
|
|
63
|
+
name: query.job,
|
|
64
|
+
state: query.state,
|
|
65
|
+
search: query.q,
|
|
66
|
+
property: query.property,
|
|
67
|
+
isObjectId: query.isObjectId,
|
|
68
|
+
skip: query.skip ? parseInt(query.skip, 10) : 0,
|
|
69
|
+
limit: query.limit ? parseInt(query.limit, 10) : 50
|
|
70
|
+
};
|
|
71
|
+
return await controller.getJobs(params);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return h
|
|
75
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
76
|
+
.code(400);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
options: {
|
|
80
|
+
auth: authConfig
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
server.route({
|
|
84
|
+
method: 'POST',
|
|
85
|
+
path: '/api/jobs/requeue',
|
|
86
|
+
handler: async (request, h) => {
|
|
87
|
+
try {
|
|
88
|
+
const { jobIds } = request.payload;
|
|
89
|
+
return await controller.requeueJobs(jobIds);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return h
|
|
93
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
94
|
+
.code(404);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
options: {
|
|
98
|
+
auth: authConfig
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
server.route({
|
|
102
|
+
method: 'POST',
|
|
103
|
+
path: '/api/jobs/delete',
|
|
104
|
+
handler: async (request, h) => {
|
|
105
|
+
try {
|
|
106
|
+
const { jobIds } = request.payload;
|
|
107
|
+
const result = await controller.deleteJobs(jobIds);
|
|
108
|
+
if (result.deleted) {
|
|
109
|
+
return h.response(result);
|
|
110
|
+
}
|
|
111
|
+
return h.response({ message: 'Jobs not deleted' }).code(404);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return h
|
|
115
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
116
|
+
.code(404);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
options: {
|
|
120
|
+
auth: authConfig
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
server.route({
|
|
124
|
+
method: 'POST',
|
|
125
|
+
path: '/api/jobs/create',
|
|
126
|
+
handler: async (request, h) => {
|
|
127
|
+
try {
|
|
128
|
+
const options = request.payload;
|
|
129
|
+
return await controller.createJob(options);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return h
|
|
133
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
134
|
+
.code(400);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
options: {
|
|
138
|
+
auth: authConfig
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
server.route({
|
|
142
|
+
method: 'POST',
|
|
143
|
+
path: '/api/jobs/pause',
|
|
144
|
+
handler: async (request, h) => {
|
|
145
|
+
try {
|
|
146
|
+
const { jobIds } = request.payload;
|
|
147
|
+
return await controller.pauseJobs(jobIds);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return h
|
|
151
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
152
|
+
.code(400);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
options: {
|
|
156
|
+
auth: authConfig
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
server.route({
|
|
160
|
+
method: 'POST',
|
|
161
|
+
path: '/api/jobs/resume',
|
|
162
|
+
handler: async (request, h) => {
|
|
163
|
+
try {
|
|
164
|
+
const { jobIds } = request.payload;
|
|
165
|
+
return await controller.resumeJobs(jobIds);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
return h
|
|
169
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
170
|
+
.code(400);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
options: {
|
|
174
|
+
auth: authConfig
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
server.route({
|
|
178
|
+
method: 'GET',
|
|
179
|
+
path: '/api/stats',
|
|
180
|
+
handler: async (request, h) => {
|
|
181
|
+
try {
|
|
182
|
+
const fullDetails = request.query.fullDetails === 'true';
|
|
183
|
+
return await controller.getStats(fullDetails);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return h
|
|
187
|
+
.response({ error: error instanceof Error ? error.message : 'Unknown error' })
|
|
188
|
+
.code(500);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
options: {
|
|
192
|
+
auth: authConfig
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=hapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hapi.js","sourceRoot":"","sources":["../../src/middlewares/hapi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAGpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAgB1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC9C,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAElD,OAAO;QACN,IAAI,EAAE,UAAU;QA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E,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;6BAC7E,IAAI,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC;gBACF,CAAC;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,UAAU;iBAChB;aACD,CAAC,CAAC;YAEH,MAAM,CAAC,KAAK,CAAC;gBACZ,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,KAAK,EAAE,OAAgB,EAAE,CAAkB,EAAE,EAAE;oBACvD,IAAI,CAAC;wBACJ,MAAM,WAAW,GAAI,OAAO,CAAC,KAAkC,CAAC,WAAW,KAAK,MAAM,CAAC;wBACvF,OAAO,MAAM,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;oBAC/C,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBAChB,OAAO,CAAC;6BACN,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;6BAC7E,IAAI,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC;gBACF,CAAC;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,UAAU;iBAChB;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Agenda } from 'agenda';
|
|
2
|
+
import type { Middleware } from 'koa';
|
|
3
|
+
/**
|
|
4
|
+
* Create Koa middleware array for Agendash (sync version)
|
|
5
|
+
* Note: This returns only the CSP middleware. Use createKoaMiddlewareAsync for full setup.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use createKoaMiddlewareAsync instead for complete middleware setup
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import Koa from 'koa';
|
|
11
|
+
* import { Agenda } from 'agenda';
|
|
12
|
+
* import { createKoaMiddlewareAsync } from 'agendash';
|
|
13
|
+
*
|
|
14
|
+
* const app = new Koa();
|
|
15
|
+
* const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
|
|
16
|
+
*
|
|
17
|
+
* const middlewares = await createKoaMiddlewareAsync(agenda);
|
|
18
|
+
* middlewares.forEach(mw => app.use(mw));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createKoaMiddleware(_agenda: Agenda): Middleware[];
|
|
22
|
+
/**
|
|
23
|
+
* Async version that fully sets up all middlewares
|
|
24
|
+
*/
|
|
25
|
+
export declare function createKoaMiddlewareAsync(agenda: Agenda): Promise<Middleware[]>;
|