@bull-board/hapi 3.5.5

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # <img alt="@bull-board" src="https://raw.githubusercontent.com/felixmosh/bull-board/master/packages/ui/src/static/images/logo.svg" width="35px" /> @bull-board/hapi
2
+
3
+ [Hapi.js](https://hapi.dev/) server adapter for `bull-board`.
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@bull-board/hapi">
7
+ <img alt="npm version" src="https://img.shields.io/npm/v/@bull-board/hapi">
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/bull-board">
10
+ <img alt="npm downloads" src="https://img.shields.io/npm/dw/bull-board">
11
+ </a>
12
+ <a href="https://github.com/vcapretz/bull-board/blob/master/LICENSE">
13
+ <img alt="licence" src="https://img.shields.io/github/license/vcapretz/bull-board">
14
+ </a>
15
+ <p>
16
+
17
+ ![UI](https://raw.githubusercontent.com/felixmosh/bull-board/master/screenshots/shot.png)
18
+ ![Fails](https://raw.githubusercontent.com/felixmosh/bull-board/master/screenshots/fails.png)
19
+
20
+ # Usage examples
21
+ 1. [Simple hapi setup](https://github.com/felixmosh/bull-board/tree/master/examples/with-hapi)
22
+
23
+ For more info visit the main [README](https://github.com/felixmosh/bull-board#readme)
@@ -0,0 +1,19 @@
1
+ import { AppControllerRoute, AppViewRoute, BullBoardQueues, ControllerHandlerReturnType, IServerAdapter } from '@bull-board/api/dist/typings/app';
2
+ import { PluginBase, PluginPackage } from '@hapi/hapi';
3
+ export declare class HapiAdapter implements IServerAdapter {
4
+ private basePath;
5
+ private bullBoardQueues;
6
+ private errorHandler;
7
+ private statics;
8
+ private viewPath;
9
+ private entryRoute;
10
+ private apiRoutes;
11
+ setBasePath(path: string): HapiAdapter;
12
+ setStaticPath(staticsRoute: string, staticsPath: string): HapiAdapter;
13
+ setViewsPath(viewPath: string): HapiAdapter;
14
+ setErrorHandler(handler: (error: Error) => ControllerHandlerReturnType): this;
15
+ setApiRoutes(routes: AppControllerRoute[]): HapiAdapter;
16
+ setEntryRoute(routeDef: AppViewRoute): HapiAdapter;
17
+ setQueues(bullBoardQueues: BullBoardQueues): HapiAdapter;
18
+ registerPlugin(): PluginBase<any> & PluginPackage;
19
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HapiAdapter = void 0;
7
+ const vision_1 = __importDefault(require("@hapi/vision"));
8
+ const inert_1 = __importDefault(require("@hapi/inert"));
9
+ const toHapiPath_1 = require("./utils/toHapiPath");
10
+ class HapiAdapter {
11
+ constructor() {
12
+ this.basePath = '';
13
+ }
14
+ setBasePath(path) {
15
+ this.basePath = path;
16
+ return this;
17
+ }
18
+ setStaticPath(staticsRoute, staticsPath) {
19
+ this.statics = { route: staticsRoute, path: staticsPath };
20
+ return this;
21
+ }
22
+ setViewsPath(viewPath) {
23
+ this.viewPath = viewPath;
24
+ return this;
25
+ }
26
+ setErrorHandler(handler) {
27
+ this.errorHandler = handler;
28
+ return this;
29
+ }
30
+ setApiRoutes(routes) {
31
+ this.apiRoutes = routes.reduce((result, routeRaw) => {
32
+ const routes = Array.isArray(routeRaw.route) ? routeRaw.route : [routeRaw.route];
33
+ const methods = Array.isArray(routeRaw.method) ? routeRaw.method : [routeRaw.method];
34
+ routes.forEach((path) => {
35
+ result.push({
36
+ method: methods.map((method) => method.toUpperCase()),
37
+ path: toHapiPath_1.toHapiPath(path),
38
+ handler: routeRaw.handler,
39
+ });
40
+ });
41
+ return result;
42
+ }, []);
43
+ return this;
44
+ }
45
+ setEntryRoute(routeDef) {
46
+ this.entryRoute = routeDef;
47
+ return this;
48
+ }
49
+ setQueues(bullBoardQueues) {
50
+ this.bullBoardQueues = bullBoardQueues;
51
+ return this;
52
+ }
53
+ registerPlugin() {
54
+ return {
55
+ pkg: require('../package.json'),
56
+ register: async (server) => {
57
+ if (!this.statics) {
58
+ throw new Error(`Please call 'setStaticPath' before using 'registerPlugin'`);
59
+ }
60
+ else if (!this.entryRoute) {
61
+ throw new Error(`Please call 'setEntryRoute' before using 'registerPlugin'`);
62
+ }
63
+ else if (!this.viewPath) {
64
+ throw new Error(`Please call 'setViewsPath' before using 'registerPlugin'`);
65
+ }
66
+ else if (!this.apiRoutes) {
67
+ throw new Error(`Please call 'setApiRoutes' before using 'registerPlugin'`);
68
+ }
69
+ else if (!this.bullBoardQueues) {
70
+ throw new Error(`Please call 'setQueues' before using 'registerPlugin'`);
71
+ }
72
+ else if (!this.errorHandler) {
73
+ throw new Error(`Please call 'setErrorHandler' before using 'registerPlugin'`);
74
+ }
75
+ await server.register(vision_1.default);
76
+ server.views({
77
+ engines: {
78
+ ejs: require('ejs'),
79
+ },
80
+ path: this.viewPath,
81
+ });
82
+ await server.register(inert_1.default);
83
+ server.route({
84
+ method: 'GET',
85
+ path: `${this.statics.route}/{param*}`,
86
+ handler: {
87
+ directory: {
88
+ path: this.statics.path,
89
+ },
90
+ },
91
+ });
92
+ const { method, route, handler } = this.entryRoute;
93
+ const routes = Array.isArray(route) ? route : [route];
94
+ routes.forEach((path) => server.route({
95
+ method: method.toUpperCase(),
96
+ path: toHapiPath_1.toHapiPath(path),
97
+ handler: (_request, h) => {
98
+ const { name } = handler();
99
+ return h.view(name, { basePath: this.basePath });
100
+ },
101
+ }));
102
+ const errorHandler = this.errorHandler;
103
+ this.apiRoutes.forEach((route) => {
104
+ server.route({
105
+ method: route.method,
106
+ path: route.path,
107
+ handler: async (request, h) => {
108
+ try {
109
+ const response = await route.handler({
110
+ queues: this.bullBoardQueues,
111
+ params: request.params,
112
+ query: request.query,
113
+ });
114
+ return h.response(response.body).code(response.status || 200);
115
+ }
116
+ catch (e) {
117
+ const response = errorHandler(e);
118
+ return h.response(response.body).code(response.status);
119
+ }
120
+ },
121
+ });
122
+ });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,CAAC,CAAC;oBACnD,CAAC;iBACF,CAAC,CACH,CAAC;gBAEF,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;gBAEvC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC/B,MAAM,CAAC,KAAK,CAAC;wBACX,MAAM,EAAE,KAAK,CAAC,MAAM;wBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;4BAC5B,IAAI;gCACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;oCACnC,MAAM,EAAE,IAAI,CAAC,eAAsB;oCACnC,MAAM,EAAE,OAAO,CAAC,MAAa;oCAC7B,KAAK,EAAE,OAAO,CAAC,KAAY;iCAC5B,CAAC,CAAC;gCAEH,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;6BAC/D;4BAAC,OAAO,CAAC,EAAE;gCACV,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gCACjC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAa,CAAC,CAAC;6BAC/D;wBACH,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AA1ID,kCA0IC"}
@@ -0,0 +1 @@
1
+ export { HapiAdapter } from './HapiAdapter';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HapiAdapter = void 0;
4
+ var HapiAdapter_1 = require("./HapiAdapter");
5
+ Object.defineProperty(exports, "HapiAdapter", { enumerable: true, get: function () { return HapiAdapter_1.HapiAdapter; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
@@ -0,0 +1 @@
1
+ export declare function toHapiPath(path: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toHapiPath = void 0;
4
+ function toHapiPath(path) {
5
+ return path
6
+ .split('/')
7
+ .map((path) => (path.startsWith(':') ? `{${path.substring(1)}}` : path))
8
+ .join('/');
9
+ }
10
+ exports.toHapiPath = toHapiPath;
11
+ //# sourceMappingURL=toHapiPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toHapiPath.js","sourceRoot":"","sources":["../../src/utils/toHapiPath.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACvE,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AALD,gCAKC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@bull-board/hapi",
3
+ "version": "3.5.5",
4
+ "description": "Hapi.js server adapter for Bull-Board package",
5
+ "keywords": [
6
+ "bull",
7
+ "bullmq",
8
+ "redis",
9
+ "hapi",
10
+ "adapter",
11
+ "queue",
12
+ "monitoring",
13
+ "dashboard"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/felixmosh/bull-board.git",
18
+ "directory": "packages/hapi"
19
+ },
20
+ "license": "MIT",
21
+ "author": "felixmosh",
22
+ "main": "dist/index.js",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "clean": "rm -rf dist"
29
+ },
30
+ "dependencies": {
31
+ "@bull-board/api": "3.5.5",
32
+ "@bull-board/ui": "3.5.5",
33
+ "@hapi/inert": "^6.0.3",
34
+ "@hapi/vision": "^6.1.0",
35
+ "ejs": "^3.1.6"
36
+ },
37
+ "devDependencies": {
38
+ "@hapi/hapi": "^20.1.3",
39
+ "@types/hapi__hapi": "^20.0.8",
40
+ "@types/hapi__inert": "^5.2.2",
41
+ "@types/hapi__vision": "^5.5.2"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }