@hono-di/auth 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.
package/dist/index.cjs ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
27
+
28
+ // src/index.ts
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
+ AuthGuard: () => AuthGuard,
32
+ CurrentUser: () => CurrentUser,
33
+ IS_PUBLIC_KEY: () => IS_PUBLIC_KEY,
34
+ Public: () => Public,
35
+ ROLES_KEY: () => ROLES_KEY,
36
+ Roles: () => Roles
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/auth.guard.ts
41
+ var import_core2 = require("@hono-di/core");
42
+
43
+ // src/decorators.ts
44
+ var import_core = require("@hono-di/core");
45
+ var IS_PUBLIC_KEY = "isPublic";
46
+ var Public = () => (0, import_core.SetMetadata)(IS_PUBLIC_KEY, true);
47
+ var ROLES_KEY = "roles";
48
+ var Roles = (...roles) => (0, import_core.SetMetadata)(ROLES_KEY, roles);
49
+ var CurrentUser = (0, import_core.createParamDecorator)(
50
+ (data, ctx) => {
51
+ const request = ctx.switchToHttp().getRequest();
52
+ return request.user;
53
+ }
54
+ );
55
+
56
+ // src/auth.guard.ts
57
+ var AuthGuard = class {
58
+ constructor(reflector) {
59
+ this.reflector = reflector;
60
+ }
61
+ async canActivate(context) {
62
+ const isPublic = this.reflector.getAllAndOverride(IS_PUBLIC_KEY, [
63
+ context.getHandler(),
64
+ context.getClass()
65
+ ]);
66
+ if (isPublic) {
67
+ return true;
68
+ }
69
+ return this.validateRequest(context);
70
+ }
71
+ };
72
+ AuthGuard = __decorateClass([
73
+ (0, import_core2.Injectable)()
74
+ ], AuthGuard);
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ AuthGuard,
78
+ CurrentUser,
79
+ IS_PUBLIC_KEY,
80
+ Public,
81
+ ROLES_KEY,
82
+ Roles
83
+ });
@@ -0,0 +1,17 @@
1
+ import * as _hono_di_core from '@hono-di/core';
2
+ import { CanActivate, Reflector, ExecutionContext } from '@hono-di/core';
3
+
4
+ declare abstract class AuthGuard implements CanActivate {
5
+ protected readonly reflector: Reflector;
6
+ constructor(reflector: Reflector);
7
+ canActivate(context: ExecutionContext): Promise<boolean>;
8
+ abstract validateRequest(context: ExecutionContext): boolean | Promise<boolean>;
9
+ }
10
+
11
+ declare const IS_PUBLIC_KEY = "isPublic";
12
+ declare const Public: () => _hono_di_core.CustomDecorator<TKey>;
13
+ declare const ROLES_KEY = "roles";
14
+ declare const Roles: (...roles: string[]) => _hono_di_core.CustomDecorator<TKey>;
15
+ declare const CurrentUser: (data?: unknown) => ParameterDecorator;
16
+
17
+ export { AuthGuard, CurrentUser, IS_PUBLIC_KEY, Public, ROLES_KEY, Roles };
@@ -0,0 +1,17 @@
1
+ import * as _hono_di_core from '@hono-di/core';
2
+ import { CanActivate, Reflector, ExecutionContext } from '@hono-di/core';
3
+
4
+ declare abstract class AuthGuard implements CanActivate {
5
+ protected readonly reflector: Reflector;
6
+ constructor(reflector: Reflector);
7
+ canActivate(context: ExecutionContext): Promise<boolean>;
8
+ abstract validateRequest(context: ExecutionContext): boolean | Promise<boolean>;
9
+ }
10
+
11
+ declare const IS_PUBLIC_KEY = "isPublic";
12
+ declare const Public: () => _hono_di_core.CustomDecorator<TKey>;
13
+ declare const ROLES_KEY = "roles";
14
+ declare const Roles: (...roles: string[]) => _hono_di_core.CustomDecorator<TKey>;
15
+ declare const CurrentUser: (data?: unknown) => ParameterDecorator;
16
+
17
+ export { AuthGuard, CurrentUser, IS_PUBLIC_KEY, Public, ROLES_KEY, Roles };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+
12
+ // src/auth.guard.ts
13
+ import { Injectable } from "@hono-di/core";
14
+
15
+ // src/decorators.ts
16
+ import { SetMetadata, createParamDecorator } from "@hono-di/core";
17
+ var IS_PUBLIC_KEY = "isPublic";
18
+ var Public = () => SetMetadata(IS_PUBLIC_KEY, true);
19
+ var ROLES_KEY = "roles";
20
+ var Roles = (...roles) => SetMetadata(ROLES_KEY, roles);
21
+ var CurrentUser = createParamDecorator(
22
+ (data, ctx) => {
23
+ const request = ctx.switchToHttp().getRequest();
24
+ return request.user;
25
+ }
26
+ );
27
+
28
+ // src/auth.guard.ts
29
+ var AuthGuard = class {
30
+ constructor(reflector) {
31
+ this.reflector = reflector;
32
+ }
33
+ async canActivate(context) {
34
+ const isPublic = this.reflector.getAllAndOverride(IS_PUBLIC_KEY, [
35
+ context.getHandler(),
36
+ context.getClass()
37
+ ]);
38
+ if (isPublic) {
39
+ return true;
40
+ }
41
+ return this.validateRequest(context);
42
+ }
43
+ };
44
+ AuthGuard = __decorateClass([
45
+ Injectable()
46
+ ], AuthGuard);
47
+ export {
48
+ AuthGuard,
49
+ CurrentUser,
50
+ IS_PUBLIC_KEY,
51
+ Public,
52
+ ROLES_KEY,
53
+ Roles
54
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@hono-di/auth",
3
+ "version": "0.0.6",
4
+ "description": "Authentication utilities for HonoDi",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "test": "bun test"
22
+ },
23
+ "dependencies": {},
24
+ "peerDependencies": {
25
+ "@hono-di/core": "0.0.6",
26
+ "hono": "^4"
27
+ },
28
+ "devDependencies": {
29
+ "tsup": "^8.0.2",
30
+ "typescript": "^5.4.2"
31
+ }
32
+ }