@arkstack/driver-express 0.4.1 → 0.4.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.
|
@@ -13,8 +13,10 @@ const auth = async (req, res, next) => {
|
|
|
13
13
|
req,
|
|
14
14
|
status: 401
|
|
15
15
|
});
|
|
16
|
+
const auth = Auth.make().setRequest(req);
|
|
16
17
|
const user = await Auth.make().setRequest(req).authorizeToken(token);
|
|
17
18
|
req.user = user;
|
|
19
|
+
req.auth = auth;
|
|
18
20
|
req.authUser = user;
|
|
19
21
|
req.authToken = token;
|
|
20
22
|
if (Hook.has("middleware:auth", "after")) Hook.get("middleware:auth", "after")?.({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/request-logger.ts"],"sourcesContent":["import { Auth, AuthenticationException } from '@arkstack/auth'\n\nimport type { Handler } from 'express'\nimport { Hook } from '@arkstack/common'\n\nexport const auth: Handler = async (req, res, next) => {\n try {\n if (Hook.has('middleware:auth', 'before'))\n Hook.get('middleware:auth', 'before')?.({ req, res })\n\n const token = readBearerToken(req.headers.authorization)\n\n if (!token) {\n throw new AuthenticationException('Unauthenticated', { req, status: 401 })\n }\n\n const user = await Auth.make().setRequest(req).authorizeToken(token)\n\n req.user = user\n req.authUser = user\n req.authToken = token\n\n if (Hook.has('middleware:auth', 'after'))\n Hook.get('middleware:auth', 'after')?.({ req, res })\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n Hook.get('middleware:auth', 'error')?.(error, { req, res })\n\n next(error)\n }\n}\n\nconst readBearerToken = (authorization: string | string[] | undefined) => {\n const value = Array.isArray(authorization) ? authorization[0] : authorization\n\n if (!value?.startsWith('Bearer ')) {\n return null\n }\n\n return value.substring(7)\n}\n","import { Logger, nodeEnv } from '@arkstack/common'\nimport { NextFunction, Request, Response } from 'express'\n\nconst colors: Record<string, 'green' | 'blue' | 'yellow' | 'red' | 'cyan'> = {\n GET: 'green',\n POST: 'blue',\n PUT: 'yellow',\n DELETE: 'red',\n PATCH: 'cyan',\n}\n\n/**\n * Middleware to log incoming requests and their response times.\n * \n * @param config Configuration options for the request logger middleware.\n * @param config.allowInProduction If true, the logger will also log requests in production environment. Default is false. \n * @returns \n */\nexport const requestLogger = ({\n allowInProduction = false,\n}: {\n allowInProduction?: boolean\n} = {}) => async (req: Request, res: Response, next: NextFunction) => {\n if (nodeEnv() === 'prod' && !allowInProduction) return next()\n\n const start = Date.now()\n\n const status = res.statusCode || 200\n const duration = Date.now() - start\n Logger.log([\n [`[${req.method}]`, colors[req.method] || 'white'],\n [req.url, 'cyan'],\n [status.toString(), status >= 500 ? 'red' : status >= 400 ? 'yellow' : 'green'],\n [`- ${duration}ms`, 'dim']\n ], ' ')\n\n next()\n}"],"mappings":";;;;AAKA,MAAa,OAAgB,OAAO,KAAK,KAAK,SAAS;AACnD,KAAI;AACA,MAAI,KAAK,IAAI,mBAAmB,SAAS,CACrC,MAAK,IAAI,mBAAmB,SAAS,GAAG;GAAE;GAAK;GAAK,CAAC;EAEzD,MAAM,QAAQ,gBAAgB,IAAI,QAAQ,cAAc;AAExD,MAAI,CAAC,MACD,OAAM,IAAI,wBAAwB,mBAAmB;GAAE;GAAK,QAAQ;GAAK,CAAC;EAG9E,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC,WAAW,IAAI,CAAC,eAAe,MAAM;AAEpE,MAAI,OAAO;AACX,MAAI,WAAW;AACf,MAAI,YAAY;AAEhB,MAAI,KAAK,IAAI,mBAAmB,QAAQ,CACpC,MAAK,IAAI,mBAAmB,QAAQ,GAAG;GAAE;GAAK;GAAK,CAAC;AAExD,QAAM;UACD,OAAO;AACZ,MAAI,KAAK,IAAI,mBAAmB,QAAQ,CACpC,MAAK,IAAI,mBAAmB,QAAQ,GAAG,OAAO;GAAE;GAAK;GAAK,CAAC;AAE/D,OAAK,MAAM;;;AAInB,MAAM,mBAAmB,kBAAiD;CACtE,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK;AAEhE,KAAI,CAAC,OAAO,WAAW,UAAU,CAC7B,QAAO;AAGX,QAAO,MAAM,UAAU,EAAE;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/request-logger.ts"],"sourcesContent":["import { Auth, AuthenticationException } from '@arkstack/auth'\n\nimport type { Handler } from 'express'\nimport { Hook } from '@arkstack/common'\n\nexport const auth: Handler = async (req, res, next) => {\n try {\n if (Hook.has('middleware:auth', 'before'))\n Hook.get('middleware:auth', 'before')?.({ req, res })\n\n const token = readBearerToken(req.headers.authorization)\n\n if (!token) {\n throw new AuthenticationException('Unauthenticated', { req, status: 401 })\n }\n\n const auth = Auth.make().setRequest(req)\n const user = await Auth.make().setRequest(req).authorizeToken(token)\n\n req.user = user\n req.auth = auth\n req.authUser = user\n req.authToken = token\n\n if (Hook.has('middleware:auth', 'after'))\n Hook.get('middleware:auth', 'after')?.({ req, res })\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n Hook.get('middleware:auth', 'error')?.(error, { req, res })\n\n next(error)\n }\n}\n\nconst readBearerToken = (authorization: string | string[] | undefined) => {\n const value = Array.isArray(authorization) ? authorization[0] : authorization\n\n if (!value?.startsWith('Bearer ')) {\n return null\n }\n\n return value.substring(7)\n}\n","import { Logger, nodeEnv } from '@arkstack/common'\nimport { NextFunction, Request, Response } from 'express'\n\nconst colors: Record<string, 'green' | 'blue' | 'yellow' | 'red' | 'cyan'> = {\n GET: 'green',\n POST: 'blue',\n PUT: 'yellow',\n DELETE: 'red',\n PATCH: 'cyan',\n}\n\n/**\n * Middleware to log incoming requests and their response times.\n * \n * @param config Configuration options for the request logger middleware.\n * @param config.allowInProduction If true, the logger will also log requests in production environment. Default is false. \n * @returns \n */\nexport const requestLogger = ({\n allowInProduction = false,\n}: {\n allowInProduction?: boolean\n} = {}) => async (req: Request, res: Response, next: NextFunction) => {\n if (nodeEnv() === 'prod' && !allowInProduction) return next()\n\n const start = Date.now()\n\n const status = res.statusCode || 200\n const duration = Date.now() - start\n Logger.log([\n [`[${req.method}]`, colors[req.method] || 'white'],\n [req.url, 'cyan'],\n [status.toString(), status >= 500 ? 'red' : status >= 400 ? 'yellow' : 'green'],\n [`- ${duration}ms`, 'dim']\n ], ' ')\n\n next()\n}"],"mappings":";;;;AAKA,MAAa,OAAgB,OAAO,KAAK,KAAK,SAAS;AACnD,KAAI;AACA,MAAI,KAAK,IAAI,mBAAmB,SAAS,CACrC,MAAK,IAAI,mBAAmB,SAAS,GAAG;GAAE;GAAK;GAAK,CAAC;EAEzD,MAAM,QAAQ,gBAAgB,IAAI,QAAQ,cAAc;AAExD,MAAI,CAAC,MACD,OAAM,IAAI,wBAAwB,mBAAmB;GAAE;GAAK,QAAQ;GAAK,CAAC;EAG9E,MAAM,OAAO,KAAK,MAAM,CAAC,WAAW,IAAI;EACxC,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC,WAAW,IAAI,CAAC,eAAe,MAAM;AAEpE,MAAI,OAAO;AACX,MAAI,OAAO;AACX,MAAI,WAAW;AACf,MAAI,YAAY;AAEhB,MAAI,KAAK,IAAI,mBAAmB,QAAQ,CACpC,MAAK,IAAI,mBAAmB,QAAQ,GAAG;GAAE;GAAK;GAAK,CAAC;AAExD,QAAM;UACD,OAAO;AACZ,MAAI,KAAK,IAAI,mBAAmB,QAAQ,CACpC,MAAK,IAAI,mBAAmB,QAAQ,GAAG,OAAO;GAAE;GAAK;GAAK,CAAC;AAE/D,OAAK,MAAM;;;AAInB,MAAM,mBAAmB,kBAAiD;CACtE,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK;AAEhE,KAAI,CAAC,OAAO,WAAW,UAAU,CAC7B,QAAO;AAGX,QAAO,MAAM,UAAU,EAAE;;;;;ACxC7B,MAAM,SAAuE;CACzE,KAAK;CACL,MAAM;CACN,KAAK;CACL,QAAQ;CACR,OAAO;CACV;;;;;;;;AASD,MAAa,iBAAiB,EAC1B,oBAAoB,UAGpB,EAAE,KAAK,OAAO,KAAc,KAAe,SAAuB;AAClE,KAAI,SAAS,KAAK,UAAU,CAAC,kBAAmB,QAAO,MAAM;CAE7D,MAAM,QAAQ,KAAK,KAAK;CAExB,MAAM,SAAS,IAAI,cAAc;CACjC,MAAM,WAAW,KAAK,KAAK,GAAG;AAC9B,QAAO,IAAI;EACP,CAAC,IAAI,IAAI,OAAO,IAAI,OAAO,IAAI,WAAW,QAAQ;EAClD,CAAC,IAAI,KAAK,OAAO;EACjB,CAAC,OAAO,UAAU,EAAE,UAAU,MAAM,QAAQ,UAAU,MAAM,WAAW,QAAQ;EAC/E,CAAC,KAAK,SAAS,KAAK,MAAM;EAC7B,EAAE,IAAI;AAEP,OAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express driver package for Arkstack providing Express-specific implementations of core Arkstack features such as routing, middleware, and database integration.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"express-rate-limit": "^8.4.1",
|
|
41
41
|
"@resora/plugin-clear-router": "^1.0.3",
|
|
42
42
|
"resora": "^1.2.0",
|
|
43
|
-
"@arkstack/contract": "^0.4.
|
|
43
|
+
"@arkstack/contract": "^0.4.3"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"express": "^5.2.1",
|
|
47
|
-
"@arkstack/auth": "^0.4.
|
|
48
|
-
"@arkstack/common": "^0.4.
|
|
47
|
+
"@arkstack/auth": "^0.4.3",
|
|
48
|
+
"@arkstack/common": "^0.4.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@arkstack/auth": {
|