@ahmedbaset/adminjs-hono 0.1.1 → 0.1.3

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.
@@ -1,5 +1,5 @@
1
1
  import AdminJS from 'adminjs';
2
- import type { Hono } from 'hono';
2
+ import { Hono } from 'hono';
3
3
  import type { AuthenticationOptions, SessionOptions, UploadOptions } from './types.js';
4
4
  /**
5
5
  * Builds a Hono app with AdminJS routes protected by session-based authentication
@@ -1 +1 @@
1
- {"version":3,"file":"buildAuthenticatedRouter.d.ts","sourceRoot":"","sources":["../src/buildAuthenticatedRouter.ts"],"names":[],"mappings":"AAAA,OAAO,OAAkC,MAAM,SAAS,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAWhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAItF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,qBAAqB,EAC3B,aAAa,CAAC,EAAE,IAAI,EACpB,cAAc,CAAC,EAAE,cAAc,EAC/B,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CA2DN"}
1
+ {"version":3,"file":"buildAuthenticatedRouter.d.ts","sourceRoot":"","sources":["../src/buildAuthenticatedRouter.ts"],"names":[],"mappings":"AAAA,OAAO,OAAkC,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAW3B,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAItF;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,qBAAqB,EAC3B,aAAa,CAAC,EAAE,IAAI,EACpB,cAAc,CAAC,EAAE,cAAc,EAC/B,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CAwDN"}
@@ -1,4 +1,5 @@
1
1
  import { Router as AdminRouter } from 'adminjs';
2
+ import { Hono } from 'hono';
2
3
  import { withLogin } from './authentication/login.handler.js';
3
4
  import { withLogout } from './authentication/logout.handler.js';
4
5
  import { withProtectedRoutesHandler } from './authentication/protected-routes.handler.js';
@@ -27,10 +28,7 @@ export function buildAuthenticatedRouter(admin, auth, predefinedApp, sessionOpti
27
28
  if (auth.authenticate && auth.provider) {
28
29
  throw new WrongArgumentError(INVALID_AUTH_CONFIG_ERROR);
29
30
  }
30
- // Use provided app or create new Hono instance
31
- // eslint-disable-next-line @typescript-eslint/no-var-requires
32
- const { Hono: HonoClass } = require('hono');
33
- const app = predefinedApp ?? new HonoClass();
31
+ const app = predefinedApp ?? new Hono();
34
32
  // Get routes and assets from AdminJS
35
33
  const { routes, assets } = AdminRouter;
36
34
  // If provider is configured, add its UI props to AdminJS env
@@ -1,5 +1,6 @@
1
1
  import AdminJS, { Router as AdminRouter } from 'adminjs';
2
- import type { Hono, Handler } from 'hono';
2
+ import { Hono } from "hono";
3
+ import type { Handler } from 'hono';
3
4
  import type { HonoVariables } from './types.js';
4
5
  /**
5
6
  * Validates and initializes an AdminJS instance
@@ -1 +1 @@
1
- {"version":3,"file":"buildRouter.d.ts","sourceRoot":"","sources":["../src/buildRouter.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAW,MAAM,MAAM,CAAA;AAIlD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAQpD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC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pD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GACvC,OAAO,CAAC;IAAE,SAAS,EAAE,aAAa,CAAA;CAAE,CAAC,CA+CvC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAC7C,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,OAAO,GACb,IAAI,CAUN;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,EACtC,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,OAAO,GACb,IAAI,CAEN;AA0BD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,EACtC,MAAM,EAAE,CAAC,OAAO,WAAW,CAAC,CAAC,QAAQ,CAAC,EACtC,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,OAAO,GACb,IAAI,CAgCN;AAED,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,aAAa,CAAC,EAAE,IAAI,EACpB,aAAa,CAAC,EAAE,aAAa,GAC5B,IAAI,CAkBN"}
@@ -1,4 +1,5 @@
1
1
  import { Router as AdminRouter } from 'adminjs';
2
+ import { Hono } from "hono";
2
3
  import { WrongArgumentError, INVALID_ADMINJS_INSTANCE } from './errors.js';
3
4
  import { log } from './logger.js';
4
5
  import { convertToHonoRoute } from './convertRoutes.js';
@@ -42,23 +43,22 @@ export function routeHandler(admin, route) {
42
43
  ...files,
43
44
  };
44
45
  // Execute the controller action
45
- const html = await controller[route.action]({
46
+ const result = await controller[route.action]({
46
47
  ...c.req,
47
48
  params,
48
49
  query,
49
50
  payload,
50
51
  method,
51
52
  }, c.res);
52
- // Set Content-Type header if specified
53
53
  if (route.contentType) {
54
- c.header('Content-Type', route.contentType);
54
+ c.header("Content-Type", route.contentType);
55
55
  }
56
- // Return response
57
- if (html) {
58
- return c.body(html);
56
+ // Return JSON or HTML based on route
57
+ if (route.contentType === "application/json" ||
58
+ route.path.startsWith("/api")) {
59
+ return c.json(result);
59
60
  }
60
- // If no response body, return empty response
61
- return c.body(null);
61
+ return c.html(result);
62
62
  };
63
63
  }
64
64
  /**
@@ -164,9 +164,7 @@ export function buildRouter(admin, predefinedApp, uploadOptions) {
164
164
  // Initialize AdminJS
165
165
  initializeAdmin(admin);
166
166
  // Use provided app or create new Hono instance
167
- // eslint-disable-next-line @typescript-eslint/no-var-requires
168
- const { Hono: HonoClass } = require('hono');
169
- const app = predefinedApp ?? new HonoClass();
167
+ const app = predefinedApp ?? new Hono();
170
168
  // Get routes and assets from AdminJS
171
169
  const { routes, assets } = AdminRouter;
172
170
  // Register form parsing middleware
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { buildAuthenticatedRouter } from './buildAuthenticatedRouter.js';
2
2
  import { buildRouter } from './buildRouter.js';
3
3
  /**
4
- * @module @adminjs/hono
4
+ * @module @ahmedbaset/adminjs-hono
5
5
  *
6
6
  * AdminJS adapter for Hono web framework
7
7
  *
@@ -13,7 +13,7 @@ import { buildRouter } from './buildRouter.js';
13
13
  * ```typescript
14
14
  * import { Hono } from 'hono'
15
15
  * import AdminJS from 'adminjs'
16
- * import { buildRouter } from '@adminjs/hono'
16
+ * import { buildRouter } from '@ahmedbaset/adminjs-hono'
17
17
  *
18
18
  * const admin = new AdminJS({
19
19
  * databases: [],
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { buildAuthenticatedRouter } from './buildAuthenticatedRouter.js';
2
2
  import { buildRouter } from './buildRouter.js';
3
3
  /**
4
- * @module @adminjs/hono
4
+ * @module @ahmedbaset/adminjs-hono
5
5
  *
6
6
  * AdminJS adapter for Hono web framework
7
7
  *
@@ -13,7 +13,7 @@ import { buildRouter } from './buildRouter.js';
13
13
  * ```typescript
14
14
  * import { Hono } from 'hono'
15
15
  * import AdminJS from 'adminjs'
16
- * import { buildRouter } from '@adminjs/hono'
16
+ * import { buildRouter } from '@ahmedbaset/adminjs-hono'
17
17
  *
18
18
  * const admin = new AdminJS({
19
19
  * databases: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahmedbaset/adminjs-hono",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "AdminJS adapter for Hono web framework",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -36,6 +36,7 @@
36
36
  "scripts": {
37
37
  "dev": "rm -rf lib && tsc --watch",
38
38
  "build": "rm -rf lib && tsc",
39
+ "prepublish": "pnpm run build",
39
40
  "test": "vitest run",
40
41
  "test:watch": "vitest",
41
42
  "lint": "eslint './**/*.ts'",
@@ -55,7 +55,7 @@ export function routeHandler(
55
55
  }
56
56
 
57
57
  // Execute the controller action
58
- const html = await controller[route.action](
58
+ const result = await controller[route.action](
59
59
  {
60
60
  ...c.req,
61
61
  params,
@@ -65,19 +65,19 @@ export function routeHandler(
65
65
  },
66
66
  c.res
67
67
  )
68
-
69
- // Set Content-Type header if specified
68
+
70
69
  if (route.contentType) {
71
- c.header('Content-Type', route.contentType)
70
+ c.header("Content-Type", route.contentType);
72
71
  }
73
-
74
- // Return response
75
- if (html) {
76
- return c.body(html)
72
+
73
+ // Return JSON or HTML based on route
74
+ if (
75
+ route.contentType === "application/json" ||
76
+ route.path.startsWith("/api")
77
+ ) {
78
+ return c.json(result);
77
79
  }
78
-
79
- // If no response body, return empty response
80
- return c.body(null)
80
+ return c.html(result);
81
81
  }
82
82
  }
83
83