@devmoods/express-extras 0.13.9 → 0.14.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/bin/migrate.js +10 -0
- package/dist/__tests__/auth.spec.jsx +3 -5
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +33 -45
- package/dist/context.d.ts +1 -1
- package/dist/context.js +10 -17
- package/dist/email.js +4 -31
- package/dist/errors.js +16 -51
- package/dist/index.d.ts +13 -13
- package/dist/index.js +14 -32
- package/dist/listen.d.ts +4 -4
- package/dist/listen.js +5 -11
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +12 -22
- package/dist/middleware.d.ts +5 -3
- package/dist/middleware.js +20 -54
- package/dist/migrate.d.ts +1 -1
- package/dist/migrate.js +25 -31
- package/dist/postgres.d.ts +109 -109
- package/dist/postgres.js +7 -16
- package/dist/redis.d.ts +262 -262
- package/dist/redis.js +3 -7
- package/dist/routes.d.ts +1 -1
- package/dist/routes.js +3 -7
- package/dist/sentry.d.ts +3 -3
- package/dist/sentry.js +4 -32
- package/dist/slack.js +5 -9
- package/dist/validate.d.ts +2 -2
- package/dist/validate.js +13 -23
- package/package.json +24 -7
- package/bin/migrate +0 -9
package/dist/routes.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listRoutes = void 0;
|
|
4
1
|
function split(value) {
|
|
5
2
|
if (typeof value === 'string') {
|
|
6
3
|
return value;
|
|
@@ -11,8 +8,8 @@ function split(value) {
|
|
|
11
8
|
else {
|
|
12
9
|
const match = value
|
|
13
10
|
.toString()
|
|
14
|
-
.replace('
|
|
15
|
-
.replace('(
|
|
11
|
+
.replace('/?', '')
|
|
12
|
+
.replace('(?=/|$)', '$')
|
|
16
13
|
.match(/^\/\^((?:\\[.*+?^${}()|[\]\\\/]|[^.*+?^${}()|[\]\\\/])*)\$\//);
|
|
17
14
|
return match
|
|
18
15
|
? match[1].replace(/\\(.)/g, '$1')
|
|
@@ -35,11 +32,10 @@ function getRoutesOfLayer(path, layer) {
|
|
|
35
32
|
}
|
|
36
33
|
return [];
|
|
37
34
|
}
|
|
38
|
-
function listRoutes(app) {
|
|
35
|
+
export function listRoutes(app) {
|
|
39
36
|
const routes = [];
|
|
40
37
|
for (const layer of app._router.stack) {
|
|
41
38
|
routes.push(...getRoutesOfLayer('', layer));
|
|
42
39
|
}
|
|
43
40
|
return routes;
|
|
44
41
|
}
|
|
45
|
-
exports.listRoutes = listRoutes;
|
package/dist/sentry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
|
-
import { Application } from 'express';
|
|
2
|
+
import { type Application } from 'express';
|
|
3
3
|
export type { Sentry };
|
|
4
4
|
export interface SentryOptions extends Sentry.NodeOptions {
|
|
5
5
|
}
|
|
@@ -17,7 +17,7 @@ export declare function createSentry(options?: SentryOptions): {
|
|
|
17
17
|
export declare function createSentryOptions(app: Application | null, options?: SentryOptions): {
|
|
18
18
|
defaultIntegrations?: false | import("@sentry/types").Integration[] | undefined;
|
|
19
19
|
integrations: import("@sentry/types").Integration[] | ((integrations: import("@sentry/types").Integration[]) => import("@sentry/types").Integration[]) | undefined;
|
|
20
|
-
transport?: ((transportOptions: import("@sentry/node/types/transports").NodeTransportOptions) => import("@sentry/types").Transport) | undefined;
|
|
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
23
|
environment?: string | undefined;
|
|
@@ -29,7 +29,7 @@ export declare function createSentryOptions(app: Application | null, options?: S
|
|
|
29
29
|
autoSessionTracking?: boolean | undefined;
|
|
30
30
|
sendClientReports?: boolean | undefined;
|
|
31
31
|
dist?: string | undefined;
|
|
32
|
-
transportOptions?: Partial<import("@sentry/node/types/transports").NodeTransportOptions> | undefined;
|
|
32
|
+
transportOptions?: Partial<import("@sentry/node/types/transports/http.js").NodeTransportOptions> | undefined;
|
|
33
33
|
tracesSampleRate: number;
|
|
34
34
|
initialScope?: import("@sentry/types").CaptureContext | undefined;
|
|
35
35
|
maxBreadcrumbs?: number | undefined;
|
package/dist/sentry.js
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.createSentryOptions = exports.createSentry = void 0;
|
|
27
|
-
const Sentry = __importStar(require("@sentry/node"));
|
|
28
|
-
const Tracing = __importStar(require("@sentry/tracing"));
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
2
|
+
import * as Tracing from '@sentry/tracing';
|
|
29
3
|
/**
|
|
30
4
|
* Create a pre-configured Sentry client
|
|
31
5
|
*/
|
|
32
|
-
function createSentry(options = {}) {
|
|
6
|
+
export function createSentry(options = {}) {
|
|
33
7
|
return {
|
|
34
8
|
client: Sentry,
|
|
35
9
|
init(app, getOptions = (defaultOptions) => defaultOptions) {
|
|
@@ -37,11 +11,10 @@ function createSentry(options = {}) {
|
|
|
37
11
|
},
|
|
38
12
|
};
|
|
39
13
|
}
|
|
40
|
-
exports.createSentry = createSentry;
|
|
41
14
|
/**
|
|
42
15
|
* Construct sensible Sentry default options for an Express-based app.
|
|
43
16
|
*/
|
|
44
|
-
function createSentryOptions(app, options = {}) {
|
|
17
|
+
export function createSentryOptions(app, options = {}) {
|
|
45
18
|
return {
|
|
46
19
|
dsn: process.env.SENTRY_DSN,
|
|
47
20
|
integrations: [
|
|
@@ -52,4 +25,3 @@ function createSentryOptions(app, options = {}) {
|
|
|
52
25
|
...options,
|
|
53
26
|
};
|
|
54
27
|
}
|
|
55
|
-
exports.createSentryOptions = createSentryOptions;
|
package/dist/slack.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.createSlack = void 0;
|
|
4
|
-
const fetch_1 = require("@devmoods/fetch");
|
|
5
|
-
const logger_1 = require("./logger");
|
|
1
|
+
import { createFetch } from '@devmoods/fetch';
|
|
2
|
+
import { getLogger } from './logger.js';
|
|
6
3
|
/**
|
|
7
4
|
* Send messages to Slack using Incoming Webhooks
|
|
8
5
|
*
|
|
@@ -16,8 +13,8 @@ const logger_1 = require("./logger");
|
|
|
16
13
|
*
|
|
17
14
|
* See https://api.slack.com/messaging/webhooks
|
|
18
15
|
*/
|
|
19
|
-
function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = process.env.NODE_ENV !== 'production', } = {}) {
|
|
20
|
-
const fetch =
|
|
16
|
+
export function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = process.env.NODE_ENV !== 'production', } = {}) {
|
|
17
|
+
const fetch = createFetch();
|
|
21
18
|
/**
|
|
22
19
|
* Post a message to Slack
|
|
23
20
|
*
|
|
@@ -43,7 +40,7 @@ function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = proc
|
|
|
43
40
|
return response.jsonData;
|
|
44
41
|
}
|
|
45
42
|
catch (error) {
|
|
46
|
-
|
|
43
|
+
getLogger('core').error(error);
|
|
47
44
|
throw error;
|
|
48
45
|
}
|
|
49
46
|
}
|
|
@@ -51,4 +48,3 @@ function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = proc
|
|
|
51
48
|
postMessage,
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
|
-
exports.createSlack = createSlack;
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Options } from 'ajv';
|
|
2
|
-
import { RequestHandler } from 'express';
|
|
1
|
+
import { type Options } from 'ajv';
|
|
2
|
+
import { type RequestHandler } from 'express';
|
|
3
3
|
export declare type ValidationSchema = {
|
|
4
4
|
type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
|
|
5
5
|
format?: string;
|
package/dist/validate.js
CHANGED
|
@@ -1,46 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.validateSchema = exports.compileValidateSchema = exports.validateParams = exports.validateQuery = exports.validateBody = void 0;
|
|
7
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
const errors_1 = require("./errors");
|
|
9
|
-
function validateBody(schema) {
|
|
1
|
+
import _Ajv from 'ajv';
|
|
2
|
+
import { BadRequest } from './errors.js';
|
|
3
|
+
const Ajv = _Ajv;
|
|
4
|
+
export function validateBody(schema) {
|
|
10
5
|
const validate = compileValidateSchema(schema);
|
|
11
6
|
return (req, res, next) => {
|
|
12
7
|
const result = validate(req.body);
|
|
13
8
|
if (!result.isValid) {
|
|
14
|
-
return next(
|
|
9
|
+
return next(BadRequest({ body: result.errors }));
|
|
15
10
|
}
|
|
16
11
|
next();
|
|
17
12
|
};
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
function validateQuery(schema) {
|
|
14
|
+
export function validateQuery(schema) {
|
|
21
15
|
const validate = compileValidateSchema(schema, { coerceTypes: true });
|
|
22
16
|
return (req, res, next) => {
|
|
23
17
|
const result = validate(req.query);
|
|
24
18
|
if (!result.isValid) {
|
|
25
|
-
return next(
|
|
19
|
+
return next(BadRequest({ query: result.errors }));
|
|
26
20
|
}
|
|
27
21
|
next();
|
|
28
22
|
};
|
|
29
23
|
}
|
|
30
|
-
|
|
31
|
-
function validateParams(schema) {
|
|
24
|
+
export function validateParams(schema) {
|
|
32
25
|
const validate = compileValidateSchema(schema, { coerceTypes: true });
|
|
33
26
|
return (req, res, next) => {
|
|
34
27
|
const result = validate(req.params);
|
|
35
28
|
if (!result.isValid) {
|
|
36
|
-
return next(
|
|
29
|
+
return next(BadRequest({ params: result.errors }));
|
|
37
30
|
}
|
|
38
31
|
next();
|
|
39
32
|
};
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const ajv = new ajv_1.default({
|
|
34
|
+
export function compileValidateSchema(schema, options = {}) {
|
|
35
|
+
const ajv = new Ajv({
|
|
44
36
|
allErrors: true,
|
|
45
37
|
...options,
|
|
46
38
|
});
|
|
@@ -61,9 +53,8 @@ function compileValidateSchema(schema, options = {}) {
|
|
|
61
53
|
};
|
|
62
54
|
};
|
|
63
55
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const ajv = new ajv_1.default({
|
|
56
|
+
export function validateSchema(data, schema, options = {}) {
|
|
57
|
+
const ajv = new Ajv({
|
|
67
58
|
allErrors: true,
|
|
68
59
|
...options,
|
|
69
60
|
});
|
|
@@ -81,7 +72,6 @@ function validateSchema(data, schema, options = {}) {
|
|
|
81
72
|
errors,
|
|
82
73
|
};
|
|
83
74
|
}
|
|
84
|
-
exports.validateSchema = validateSchema;
|
|
85
75
|
function transformAjvErrors(errors) {
|
|
86
76
|
if (errors == null) {
|
|
87
77
|
return [];
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devmoods/express-extras",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Kubernetes-ready utilities for rapid Node.js application development",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
8
|
"bin": {
|
|
8
|
-
"migrate": "bin/migrate"
|
|
9
|
+
"migrate": "bin/migrate.js"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"start": "ts-node example",
|
|
12
|
+
"start": "ts-node --esm example/index.ts",
|
|
12
13
|
"clean": "rm -rf dist",
|
|
14
|
+
"lint": "eslint src",
|
|
13
15
|
"test": "NODE_ENV=test jest",
|
|
14
|
-
"build": "npm run clean && tsc --
|
|
16
|
+
"build": "npm run clean && tsc --project tsconfig.build.json",
|
|
15
17
|
"prepublishOnly": "npm run clean && npm run build",
|
|
16
18
|
"prettier": "prettier --write '**/*.{js,css,md,ts,tsx}'",
|
|
17
19
|
"import-sort": "import-sort --write '**/*.{js,jsx,ts,tsx}'",
|
|
@@ -32,9 +34,16 @@
|
|
|
32
34
|
],
|
|
33
35
|
"license": "ISC",
|
|
34
36
|
"devDependencies": {
|
|
37
|
+
"@devmoods/eslint-config": "^1.0.0",
|
|
35
38
|
"@types/jest": "29.2.2",
|
|
36
39
|
"@types/node": "18.11.9",
|
|
37
40
|
"@types/supertest": "2.0.12",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
42
|
+
"eslint": "^8.27.0",
|
|
43
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
44
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
45
|
+
"eslint-plugin-react": "^7.31.10",
|
|
46
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
38
47
|
"import-sort-cli": "6.0.0",
|
|
39
48
|
"import-sort-style-module": "6.0.0",
|
|
40
49
|
"isomorphic-fetch": "3.0.0",
|
|
@@ -67,14 +76,14 @@
|
|
|
67
76
|
"cookie-parser": "^1.4.6",
|
|
68
77
|
"dotenv-safe": "^8.2.0",
|
|
69
78
|
"express": "^4.18.2",
|
|
70
|
-
"helmet": "^
|
|
79
|
+
"helmet": "^6.0.0",
|
|
71
80
|
"jsonwebtoken": "^8.5.1",
|
|
72
|
-
"meow": "^
|
|
81
|
+
"meow": "^11.0.0",
|
|
73
82
|
"nodemailer": "^6.8.0",
|
|
74
83
|
"pg": "^8.8.0",
|
|
75
84
|
"redis": "^4.4.0",
|
|
76
85
|
"sql-template-strings": "^2.2.2",
|
|
77
|
-
"uuid": "^
|
|
86
|
+
"uuid": "^9.0.0"
|
|
78
87
|
},
|
|
79
88
|
"prettier": {
|
|
80
89
|
"singleQuote": true
|
|
@@ -83,5 +92,13 @@
|
|
|
83
92
|
".js, .jsx, .ts, .tsx": {
|
|
84
93
|
"style": "module"
|
|
85
94
|
}
|
|
95
|
+
},
|
|
96
|
+
"eslintConfig": {
|
|
97
|
+
"extends": "@devmoods/eslint-config",
|
|
98
|
+
"rules": {
|
|
99
|
+
"@typescript-eslint/consistent-type-imports": "warn",
|
|
100
|
+
"@typescript-eslint/no-shadow": "off",
|
|
101
|
+
"react-hooks/rules-of-hooks": "off"
|
|
102
|
+
}
|
|
86
103
|
}
|
|
87
104
|
}
|