@brt-innovation/aether 1.2.0 → 1.3.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/README.dev.md CHANGED
@@ -34,7 +34,11 @@ git checkout main
34
34
  git pull origin main
35
35
  ```
36
36
 
37
- ### 4. Bump Version
37
+ ### 4. Update README.md
38
+
39
+ Update the README.md file to include the latest changes.
40
+
41
+ ### 5. Bump Version
38
42
 
39
43
  Update the package version. This command updates `package.json`, `package-lock.json`, creates a git commit, and adds a git tag.
40
44
 
@@ -48,7 +52,7 @@ Examples:
48
52
  - `npm version minor` (1.0.0 -> 1.1.0)
49
53
  - `npm version major` (1.0.0 -> 2.0.0)
50
54
 
51
- ### 5. Publish
55
+ ### 6. Publish
52
56
 
53
57
  Publish the package to the registry.
54
58
 
@@ -57,11 +61,3 @@ npm run publish
57
61
  ```
58
62
 
59
63
  > **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 , onAppError } from '@brt-innovation/aether';
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('*', authMiddleware({
53
- jwtSecret: process.env.JWT_SECRET,
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)`)
@@ -113,6 +128,50 @@ app.onError(onAppError);
113
128
 
114
129
  ---
115
130
 
131
+ ### Dayjs Utilities
132
+
133
+ Common date/time utilities pre-configured with `dayjs`, `utc`, and `timezone` plugins. `Asia/Bangkok` is used as the default timezone for BKK specific functions.
134
+
135
+ **Import**
136
+
137
+ ```ts
138
+ import {
139
+ startOfDayBkk,
140
+ endOfDayBkk,
141
+ startOfDayBkkToUtc,
142
+ endOfDayBkkToUtc,
143
+ convertUtcToBkk,
144
+ convertBkkToUtc,
145
+ formatDate,
146
+ bkkTimezone,
147
+ } from '@brt-innovation/aether';
148
+ ```
149
+
150
+ **Available Functions**
151
+
152
+ - `bkkTimezone`: Constant `'Asia/Bangkok'`.
153
+ - `startOfDayBkk(date)`: Returns the start of the day (00:00:00) in Bangkok timezone as a `Date` object.
154
+ - `endOfDayBkk(date)`: Returns the end of the day (23:59:59.999) in Bangkok timezone as a `Date` object.
155
+ - `startOfDayBkkToUtc(date)`: Returns the start of the day in Bangkok, converted to UTC as a `Date` object.
156
+ - `endOfDayBkkToUtc(date)`: Returns the end of the day in Bangkok, converted to UTC as a `Date` object.
157
+ - `convertUtcToBkk(date)`: Converts a UTC date to Bangkok time (Date object with BKK wall time).
158
+ - `convertBkkToUtc(date)`: Converts a Bangkok date to UTC.
159
+ - `formatDate(date, options)`: Formats a date string or object.
160
+ - `options.format`: Format string (default: `'YYYY-MM-DD HH:mm:ss'`)
161
+ - `options.timezone`: Target timezone (default: `'UTC'`, options: `'UTC'`, `'Asia/Bangkok'`)
162
+
163
+ **Example**
164
+
165
+ ```ts
166
+ import { formatDate, startOfDayBkk, bkkTimezone } from '@brt-innovation/aether';
167
+
168
+ const now = new Date();
169
+ const bkkStart = startOfDayBkk(now);
170
+ const formatted = formatDate(now, { timezone: bkkTimezone, format: 'DD/MM/YYYY' });
171
+ ```
172
+
173
+ ---
174
+
116
175
  ## License
117
176
 
118
- UNLICENSED - Internal use only for BRT Innovation
177
+ 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.2.0",
3
+ "version": "1.3.1",
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,24 @@
17
17
  },
18
18
  "scripts": {
19
19
  "build": "tsup src/index.ts --dts --tsconfig tsconfig.json",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "format": "prettier --write .",
23
+ "format:check": "prettier --check .",
20
24
  "prepare": "npm run build",
25
+ "prepublishOnly": "npm run test",
21
26
  "publish": "npm publish --access public"
22
27
  },
23
28
  "peerDependencies": {
29
+ "dayjs": "^1.11.19",
24
30
  "hono": "^4.0.0"
25
31
  },
26
32
  "devDependencies": {
33
+ "dayjs": "^1.11.19",
34
+ "prettier": "^3.8.1",
27
35
  "tsup": "^8.5.1",
28
- "typescript": "^5.9.3"
36
+ "typescript": "^5.9.3",
37
+ "vitest": "^4.0.18"
29
38
  },
30
39
  "engines": {
31
40
  "node": ">=20"