@devmoods/express-extras 0.18.0 → 0.19.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/dist/auth.d.ts +1 -2
- package/dist/middleware.js +30 -1
- package/dist/redis.d.ts +1 -1
- package/dist/sentry.d.ts +4 -4
- package/dist/sentry.js +1 -2
- package/package.json +16 -15
package/dist/auth.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface AuthOptions<UserModel extends Record<string, any>> {
|
|
|
13
13
|
onResetRequested?(user: UserModel, temporaryToken: string): void | Promise<void>;
|
|
14
14
|
onPasswordChanged?(user: UserModel, newPassword: string): Promise<void>;
|
|
15
15
|
}
|
|
16
|
-
interface CreateAuth<UserModel extends Record<string, any>> {
|
|
16
|
+
export interface CreateAuth<UserModel extends Record<string, any>> {
|
|
17
17
|
createRouter: () => Router;
|
|
18
18
|
useCurrentUser: () => UserModel | undefined;
|
|
19
19
|
middleware: (authorize?: boolean) => RequestHandler;
|
|
@@ -27,4 +27,3 @@ export declare function parseAuthorizationHeader(req: Request): string | null;
|
|
|
27
27
|
export declare function setAccessTokenCookie(res: Response, token: string | null): void;
|
|
28
28
|
export declare function checkIfPasswordsMatch(realPassword: string, attemptedPassword: string): Promise<boolean>;
|
|
29
29
|
export declare function hashPassword(password: string): Promise<string>;
|
|
30
|
-
export {};
|
package/dist/middleware.js
CHANGED
|
@@ -5,14 +5,18 @@ import cookieParser from 'cookie-parser';
|
|
|
5
5
|
import helmet from 'helmet';
|
|
6
6
|
import { withRequestContext } from './context.js';
|
|
7
7
|
import { NotFound } from './errors.js';
|
|
8
|
+
import { getLogger } from './logger.js';
|
|
8
9
|
export const urlencodedParser = bodyParser.urlencoded;
|
|
9
10
|
export const jsonParser = bodyParser.json;
|
|
11
|
+
const logger = getLogger('core');
|
|
10
12
|
export { asyncMiddleware as route };
|
|
11
13
|
/**
|
|
12
14
|
* Register middleware that must come before the app routes.
|
|
13
15
|
*/
|
|
14
16
|
export function before({ cookies = false, helmet: useHelmet = true, json: useJson = true, allowUnsafeInlineScripts = false, } = {}) {
|
|
15
17
|
return compose([
|
|
18
|
+
withRequestContext(),
|
|
19
|
+
logRequestDuration(),
|
|
16
20
|
Sentry.Handlers.requestHandler(),
|
|
17
21
|
Sentry.Handlers.tracingHandler(),
|
|
18
22
|
useHelmet &&
|
|
@@ -39,9 +43,34 @@ export function before({ cookies = false, helmet: useHelmet = true, json: useJso
|
|
|
39
43
|
}),
|
|
40
44
|
useJson && jsonParser(),
|
|
41
45
|
cookies && cookieParser(),
|
|
42
|
-
withRequestContext(),
|
|
43
46
|
].filter(Boolean));
|
|
44
47
|
}
|
|
48
|
+
function logRequestDuration() {
|
|
49
|
+
const getDurationInMilliseconds = (start) => {
|
|
50
|
+
const NS_PER_SEC = 1e9;
|
|
51
|
+
const NS_TO_MS = 1e6;
|
|
52
|
+
const diff = process.hrtime(start);
|
|
53
|
+
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
|
|
54
|
+
};
|
|
55
|
+
return (req, res, next) => {
|
|
56
|
+
const start = process.hrtime();
|
|
57
|
+
logger.info('http request', {
|
|
58
|
+
method: req.method,
|
|
59
|
+
url: req.originalUrl,
|
|
60
|
+
path: req.path,
|
|
61
|
+
});
|
|
62
|
+
res.on('finish', () => {
|
|
63
|
+
const duration = getDurationInMilliseconds(start);
|
|
64
|
+
logger.info('http response', {
|
|
65
|
+
method: req.method,
|
|
66
|
+
url: req.originalUrl,
|
|
67
|
+
path: req.path,
|
|
68
|
+
duration,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
next();
|
|
72
|
+
};
|
|
73
|
+
}
|
|
45
74
|
/**
|
|
46
75
|
* Middleware that sends a 404
|
|
47
76
|
*
|
package/dist/redis.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
|
-
export type RedisClient = ReturnType<typeof createClient>;
|
|
3
2
|
export interface RedisOptions {
|
|
4
3
|
url?: string;
|
|
5
4
|
onError: (error: Error) => void;
|
|
6
5
|
}
|
|
6
|
+
export type RedisClient = ReturnType<typeof createClient>;
|
|
7
7
|
export declare function createRedis({ url, onError, }: RedisOptions): RedisClient;
|
package/dist/sentry.d.ts
CHANGED
|
@@ -20,21 +20,21 @@ export declare function createSentryOptions(app: Application | null, options?: S
|
|
|
20
20
|
transport?: ((transportOptions: import("@sentry/node/types/transports/http.js").NodeTransportOptions) => import("@sentry/types").Transport) | undefined;
|
|
21
21
|
stackParser?: import("@sentry/types").StackParser | import("@sentry/types").StackLineParser[] | undefined;
|
|
22
22
|
release?: string | undefined;
|
|
23
|
-
environment?: string | undefined;
|
|
24
23
|
debug?: boolean | undefined;
|
|
25
|
-
instrumenter?: import("@sentry/types").Instrumenter | undefined;
|
|
26
|
-
sampleRate?: number | undefined;
|
|
27
|
-
dsn: string | undefined;
|
|
28
24
|
enabled?: boolean | undefined;
|
|
29
25
|
attachStacktrace?: boolean | undefined;
|
|
30
26
|
autoSessionTracking?: boolean | undefined;
|
|
31
27
|
sendClientReports?: boolean | undefined;
|
|
28
|
+
dsn: string | undefined;
|
|
29
|
+
environment?: string | undefined;
|
|
32
30
|
dist?: string | undefined;
|
|
31
|
+
instrumenter?: import("@sentry/types").Instrumenter | undefined;
|
|
33
32
|
transportOptions?: Partial<import("@sentry/node/types/transports/http.js").NodeTransportOptions> | undefined;
|
|
34
33
|
tracesSampleRate: number;
|
|
35
34
|
enableTracing?: boolean | undefined;
|
|
36
35
|
initialScope?: import("@sentry/types").CaptureContext | undefined;
|
|
37
36
|
maxBreadcrumbs?: number | undefined;
|
|
37
|
+
sampleRate?: number | undefined;
|
|
38
38
|
maxValueLength?: number | undefined;
|
|
39
39
|
normalizeDepth?: number | undefined;
|
|
40
40
|
normalizeMaxBreadth?: number | undefined;
|
package/dist/sentry.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
|
-
import * as Tracing from '@sentry/tracing';
|
|
3
2
|
/**
|
|
4
3
|
* Create a pre-configured Sentry client
|
|
5
4
|
*/
|
|
@@ -19,7 +18,7 @@ export function createSentryOptions(app, options = {}) {
|
|
|
19
18
|
dsn: process.env.SENTRY_DSN,
|
|
20
19
|
integrations: [
|
|
21
20
|
new Sentry.Integrations.Http({ tracing: true }),
|
|
22
|
-
app && new
|
|
21
|
+
app && new Sentry.Integrations.Express({ app }),
|
|
23
22
|
].filter(Boolean),
|
|
24
23
|
tracesSampleRate: 1.0,
|
|
25
24
|
...options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devmoods/express-extras",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Kubernetes-ready utilities for rapid Node.js application development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,31 +23,32 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@devmoods/eslint-config": "^1.
|
|
27
|
-
"@types
|
|
26
|
+
"@devmoods/eslint-config": "^1.2.0",
|
|
27
|
+
"@sentry/types": "^7.60.1",
|
|
28
|
+
"@types/express-serve-static-core": "^4.17.35",
|
|
29
|
+
"@types/node": "20.4.5",
|
|
28
30
|
"@types/supertest": "2.0.12",
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
30
|
-
"@typescript-eslint/parser": "^
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
32
|
+
"@typescript-eslint/parser": "^6.2.0",
|
|
31
33
|
"chalk": "^5.3.0",
|
|
32
|
-
"eslint": "^8.
|
|
34
|
+
"eslint": "^8.46.0",
|
|
33
35
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
34
|
-
"eslint-plugin-prettier": "^
|
|
35
|
-
"eslint-plugin-react": "^7.
|
|
36
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
37
|
+
"eslint-plugin-react": "^7.33.1",
|
|
36
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
37
39
|
"import-sort-cli": "6.0.0",
|
|
38
40
|
"import-sort-style-module": "6.0.0",
|
|
39
41
|
"isomorphic-fetch": "3.0.0",
|
|
40
|
-
"prettier": "
|
|
42
|
+
"prettier": "3.0.0",
|
|
41
43
|
"supertest": "6.3.3",
|
|
42
44
|
"ts-node": "10.9.1",
|
|
43
45
|
"typescript": "5.1.6",
|
|
44
|
-
"vitest": "^0.
|
|
46
|
+
"vitest": "^0.33.0"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
49
|
"@devmoods/fetch": "^3.3.0",
|
|
48
50
|
"@godaddy/terminus": "^4.12.1",
|
|
49
|
-
"@sentry/node": "^7.
|
|
50
|
-
"@sentry/tracing": "^7.57.0",
|
|
51
|
+
"@sentry/node": "^7.60.1",
|
|
51
52
|
"@types/bcrypt": "^5.0.0",
|
|
52
53
|
"@types/body-parser": "^1.19.2",
|
|
53
54
|
"@types/bunyan": "^1.8.8",
|
|
@@ -55,7 +56,7 @@
|
|
|
55
56
|
"@types/cookie-parser": "^1.4.3",
|
|
56
57
|
"@types/express": "^4.17.17",
|
|
57
58
|
"@types/jsonwebtoken": "^9.0.2",
|
|
58
|
-
"@types/nodemailer": "^6.4.
|
|
59
|
+
"@types/nodemailer": "^6.4.9",
|
|
59
60
|
"@types/pg": "^8.10.2",
|
|
60
61
|
"@types/uuid": "^9.0.2",
|
|
61
62
|
"ajv": "^8.12.0",
|
|
@@ -68,9 +69,9 @@
|
|
|
68
69
|
"dotenv": "^16.3.1",
|
|
69
70
|
"express": "^4.18.2",
|
|
70
71
|
"helmet": "^7.0.0",
|
|
71
|
-
"jsonwebtoken": "^9.0.
|
|
72
|
+
"jsonwebtoken": "^9.0.1",
|
|
72
73
|
"meow": "^12.0.1",
|
|
73
|
-
"nodemailer": "^6.9.
|
|
74
|
+
"nodemailer": "^6.9.4",
|
|
74
75
|
"pg": "^8.11.1",
|
|
75
76
|
"redis": "^4.6.7",
|
|
76
77
|
"sql-template-strings": "^2.2.2",
|