@arkstack/driver-express 0.6.4 → 0.7.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.
|
@@ -18,6 +18,7 @@ const auth = async (req, res, next) => {
|
|
|
18
18
|
req.user = user;
|
|
19
19
|
req.auth = auth;
|
|
20
20
|
req.authUser = user;
|
|
21
|
+
req.session = auth.session();
|
|
21
22
|
req.authToken = token;
|
|
22
23
|
if (Hook.has("middleware:auth", "after")) await Promise.resolve(Hook.get("middleware:auth", "after")?.({
|
|
23
24
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/formdata.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 await Promise.resolve(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 await Promise.resolve(Hook.get('middleware:auth', 'after')?.({ req, res }))\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n await Promise.resolve(Hook.get('middleware:auth', 'error')?.(error, {\n req,\n res\n }))\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 multer from 'multer'\n\nexport const formdata = multer({ storage: multer.memoryStorage() })","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;CACnD,IAAI;EACA,IAAI,KAAK,IAAI,mBAAmB,SAAS,EACrC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,SAAS,GAAG;GAAE;GAAK;GAAK,CAAC,CAAC;EAEhF,MAAM,QAAQ,gBAAgB,IAAI,QAAQ,cAAc;EAExD,IAAI,CAAC,OACD,MAAM,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;EAEpE,IAAI,OAAO;EACX,IAAI,OAAO;EACX,IAAI,WAAW;EACf,IAAI,YAAY;EAEhB,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,QAAQ,GAAG;GAAE;GAAK;GAAK,CAAC,CAAC;EAE/E,MAAM;UACD,OAAO;EACZ,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,QAAQ,GAAG,OAAO;GAChE;GACA;GACH,CAAC,CAAC;EAEP,KAAK,MAAM;;;AAInB,MAAM,mBAAmB,kBAAiD;CACtE,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK;CAEhE,IAAI,CAAC,OAAO,WAAW,UAAU,EAC7B,OAAO;CAGX,OAAO,MAAM,UAAU,EAAE;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/middlewares/auth.ts","../../src/middlewares/formdata.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 await Promise.resolve(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.session = auth.session()\n req.authToken = token\n\n if (Hook.has('middleware:auth', 'after'))\n await Promise.resolve(Hook.get('middleware:auth', 'after')?.({ req, res }))\n\n next()\n } catch (error) {\n if (Hook.has('middleware:auth', 'error'))\n await Promise.resolve(Hook.get('middleware:auth', 'error')?.(error, {\n req,\n res\n }))\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 multer from 'multer'\n\nexport const formdata = multer({ storage: multer.memoryStorage() })","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;CACnD,IAAI;EACA,IAAI,KAAK,IAAI,mBAAmB,SAAS,EACrC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,SAAS,GAAG;GAAE;GAAK;GAAK,CAAC,CAAC;EAEhF,MAAM,QAAQ,gBAAgB,IAAI,QAAQ,cAAc;EAExD,IAAI,CAAC,OACD,MAAM,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;EAEpE,IAAI,OAAO;EACX,IAAI,OAAO;EACX,IAAI,WAAW;EACf,IAAI,UAAU,KAAK,SAAS;EAC5B,IAAI,YAAY;EAEhB,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,QAAQ,GAAG;GAAE;GAAK;GAAK,CAAC,CAAC;EAE/E,MAAM;UACD,OAAO;EACZ,IAAI,KAAK,IAAI,mBAAmB,QAAQ,EACpC,MAAM,QAAQ,QAAQ,KAAK,IAAI,mBAAmB,QAAQ,GAAG,OAAO;GAChE;GACA;GACH,CAAC,CAAC;EAEP,KAAK,MAAM;;;AAInB,MAAM,mBAAmB,kBAAiD;CACtE,MAAM,QAAQ,MAAM,QAAQ,cAAc,GAAG,cAAc,KAAK;CAEhE,IAAI,CAAC,OAAO,WAAW,UAAU,EAC7B,OAAO;CAGX,OAAO,MAAM,UAAU,EAAE;;;;AC7C7B,MAAa,WAAW,OAAO,EAAE,SAAS,OAAO,eAAe,EAAE,CAAA;;;ACClE,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;CAClE,IAAI,SAAS,KAAK,UAAU,CAAC,mBAAmB,OAAO,MAAM;CAE7D,MAAM,QAAQ,KAAK,KAAK;CAExB,MAAM,SAAS,IAAI,cAAc;CACjC,MAAM,WAAW,KAAK,KAAK,GAAG;CAC9B,OAAO,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;CAEP,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-express",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express driver for Arkstack, providing Express-based runtime integration for the framework.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"multer": "^2.1.1",
|
|
40
40
|
"clear-router": "^2.6.4",
|
|
41
41
|
"express-rate-limit": "^8.4.1",
|
|
42
|
-
"@resora/plugin-clear-router": "^1.0.
|
|
43
|
-
"resora": "^1.2.
|
|
44
|
-
"@arkstack/contract": "^0.
|
|
42
|
+
"@resora/plugin-clear-router": "^1.0.15",
|
|
43
|
+
"resora": "^1.2.5",
|
|
44
|
+
"@arkstack/contract": "^0.7.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"express": "^5.2.1",
|
|
48
|
-
"@arkstack/auth": "^0.
|
|
49
|
-
"@arkstack/common": "^0.
|
|
48
|
+
"@arkstack/auth": "^0.7.1",
|
|
49
|
+
"@arkstack/common": "^0.7.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"@arkstack/auth": {
|