@brt-innovation/aether 1.2.0 → 1.3.0
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.dev.md +0 -8
- package/README.md +20 -5
- package/dist/index.js +4 -5
- package/package.json +10 -2
package/README.dev.md
CHANGED
|
@@ -57,11 +57,3 @@ npm run publish
|
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
> **Note:** This runs custom script `npm publish --access public`. The `prepare` script will automatically run the build process before publishing.
|
|
60
|
-
|
|
61
|
-
### 6. Push Tags
|
|
62
|
-
|
|
63
|
-
Push the new version commit and tags to the repository.
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
git push origin main --tags
|
|
67
|
-
```
|
package/README.md
CHANGED
|
@@ -17,6 +17,16 @@ The library is published as a public npm package and is intended to be shared ac
|
|
|
17
17
|
```bash
|
|
18
18
|
npm install @brt-innovation/aether
|
|
19
19
|
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Peer Dependencies
|
|
24
|
+
|
|
25
|
+
This package requires the following peer dependencies:
|
|
26
|
+
|
|
27
|
+
- dayjs ^1.11.19
|
|
28
|
+
- hono ^4.0.0
|
|
29
|
+
|
|
20
30
|
---
|
|
21
31
|
|
|
22
32
|
## Usage
|
|
@@ -24,7 +34,7 @@ npm install @brt-innovation/aether
|
|
|
24
34
|
### Importing the library
|
|
25
35
|
|
|
26
36
|
```ts
|
|
27
|
-
import { authMiddleware, responseMiddleware
|
|
37
|
+
import { authMiddleware, responseMiddleware, onAppError } from '@brt-innovation/aether';
|
|
28
38
|
```
|
|
29
39
|
|
|
30
40
|
---
|
|
@@ -38,6 +48,7 @@ import { authMiddleware, responseMiddleware , onAppError } from '@brt-innovation
|
|
|
38
48
|
Authentication middleware for Hono using JWT.
|
|
39
49
|
|
|
40
50
|
**Supported token sources**
|
|
51
|
+
|
|
41
52
|
- `Authorization` header (Bearer token)
|
|
42
53
|
- Cookie (fallback if header is missing)
|
|
43
54
|
|
|
@@ -49,9 +60,12 @@ import { authMiddleware } from '@brt-innovation/aether';
|
|
|
49
60
|
|
|
50
61
|
const app = new Hono();
|
|
51
62
|
|
|
52
|
-
app.use(
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
app.use(
|
|
64
|
+
'*',
|
|
65
|
+
authMiddleware({
|
|
66
|
+
jwtSecret: process.env.JWT_SECRET,
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
55
69
|
```
|
|
56
70
|
|
|
57
71
|
**Example (reusable middleware instance)**
|
|
@@ -69,6 +83,7 @@ app.use('*', authMid);
|
|
|
69
83
|
```
|
|
70
84
|
|
|
71
85
|
**Behavior**
|
|
86
|
+
|
|
72
87
|
- Extracts access token from `Authorization` header or cookies
|
|
73
88
|
- Verifies JWT signature and algorithm
|
|
74
89
|
- Stores `userId` in Hono context (`c.set('userId', payload.sub)`)
|
|
@@ -115,4 +130,4 @@ app.onError(onAppError);
|
|
|
115
130
|
|
|
116
131
|
## License
|
|
117
132
|
|
|
118
|
-
UNLICENSED - Internal use only for BRT Innovation
|
|
133
|
+
UNLICENSED - Internal use only for BRT Innovation
|
package/dist/index.js
CHANGED
|
@@ -83,6 +83,9 @@ var responseMiddleware = async (c, next) => {
|
|
|
83
83
|
if (status < 400) {
|
|
84
84
|
wrapped.message = "success";
|
|
85
85
|
wrapped.data = originalBody;
|
|
86
|
+
} else if (status >= 500) {
|
|
87
|
+
wrapped.message = "Internal Server Error";
|
|
88
|
+
console.error("Internal server error: ", originalBody);
|
|
86
89
|
} else {
|
|
87
90
|
wrapped.message = originalBody?.message || "error";
|
|
88
91
|
if (originalBody?.message) delete originalBody.message;
|
|
@@ -131,11 +134,7 @@ var getToken = (c, cookieName) => {
|
|
|
131
134
|
return cookies[cookieName] ?? null;
|
|
132
135
|
};
|
|
133
136
|
var authMiddleware = (options) => {
|
|
134
|
-
const {
|
|
135
|
-
jwtSecret,
|
|
136
|
-
algorithm = "HS256",
|
|
137
|
-
tokenCookieName = "access_token"
|
|
138
|
-
} = options;
|
|
137
|
+
const { jwtSecret, algorithm = "HS256", tokenCookieName = "access_token" } = options;
|
|
139
138
|
return async (c, next) => {
|
|
140
139
|
const token = getToken(c, tokenCookieName);
|
|
141
140
|
if (!token) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brt-innovation/aether",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared utilities and middlewares for Aether microservices",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -17,15 +17,23 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsup src/index.ts --dts --tsconfig tsconfig.json",
|
|
20
|
+
"test": "vitest",
|
|
21
|
+
"format": "prettier --write .",
|
|
22
|
+
"format:check": "prettier --check .",
|
|
20
23
|
"prepare": "npm run build",
|
|
24
|
+
"prepublishOnly": "npm run test",
|
|
21
25
|
"publish": "npm publish --access public"
|
|
22
26
|
},
|
|
23
27
|
"peerDependencies": {
|
|
28
|
+
"dayjs": "^1.11.19",
|
|
24
29
|
"hono": "^4.0.0"
|
|
25
30
|
},
|
|
26
31
|
"devDependencies": {
|
|
32
|
+
"dayjs": "^1.11.19",
|
|
33
|
+
"prettier": "^3.8.1",
|
|
27
34
|
"tsup": "^8.5.1",
|
|
28
|
-
"typescript": "^5.9.3"
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vitest": "^4.0.18"
|
|
29
37
|
},
|
|
30
38
|
"engines": {
|
|
31
39
|
"node": ">=20"
|