@devmoods/express-extras 0.13.9 → 0.15.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/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,9 +8,9 @@ function split(value) {
11
8
  else {
12
9
  const match = value
13
10
  .toString()
14
- .replace('\\/?', '')
15
- .replace('(?=\\/|$)', '$')
16
- .match(/^\/\^((?:\\[.*+?^${}()|[\]\\\/]|[^.*+?^${}()|[\]\\\/])*)\$\//);
11
+ .replace('/?', '')
12
+ .replace('(?=/|$)', '$')
13
+ .match(/^\/\^((?:\\[.*+?^${}()|[\]\\/]|[^.*+?^${}()|[\]\\/])*)\$\//);
17
14
  return match
18
15
  ? match[1].replace(/\\(.)/g, '$1')
19
16
  : '<complex:' + value.toString() + '>';
@@ -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,8 @@ 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
+ instrumenter?: import("@sentry/types").Instrumenter | undefined;
33
+ transportOptions?: Partial<import("@sentry/node/types/transports/http.js").NodeTransportOptions> | undefined;
33
34
  tracesSampleRate: number;
34
35
  initialScope?: import("@sentry/types").CaptureContext | undefined;
35
36
  maxBreadcrumbs?: number | undefined;
@@ -46,8 +47,10 @@ export declare function createSentryOptions(app: Application | null, options?: S
46
47
  } | undefined;
47
48
  tracesSampler?: ((samplingContext: import("@sentry/types").SamplingContext) => number | boolean) | undefined;
48
49
  beforeSend?: ((event: Sentry.Event, hint: Sentry.EventHint) => Sentry.Event | PromiseLike<Sentry.Event | null> | null) | undefined;
50
+ beforeSendTransaction?: ((event: Sentry.Event, hint: Sentry.EventHint) => Sentry.Event | PromiseLike<Sentry.Event | null> | null) | undefined;
49
51
  beforeBreadcrumb?: ((breadcrumb: Sentry.Breadcrumb, hint?: Sentry.BreadcrumbHint | undefined) => Sentry.Breadcrumb | null) | undefined;
50
52
  serverName?: string | undefined;
51
53
  tracePropagationTargets?: import("@sentry/types").TracePropagationTargets | undefined;
54
+ shouldCreateSpanForRequest?(url: string): boolean;
52
55
  onFatalError?(error: Error): void;
53
56
  };
package/dist/sentry.js CHANGED
@@ -1,35 +1,9 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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';
3
+ const logger = getLogger();
6
4
  /**
7
5
  * Send messages to Slack using Incoming Webhooks
8
6
  *
@@ -16,8 +14,8 @@ const logger_1 = require("./logger");
16
14
  *
17
15
  * See https://api.slack.com/messaging/webhooks
18
16
  */
19
- function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = process.env.NODE_ENV !== 'production', } = {}) {
20
- const fetch = (0, fetch_1.createFetch)();
17
+ export function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = process.env.NODE_ENV !== 'production', } = {}) {
18
+ const fetch = createFetch();
21
19
  /**
22
20
  * Post a message to Slack
23
21
  *
@@ -27,6 +25,7 @@ function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = proc
27
25
  */
28
26
  async function postMessage(message, blocks) {
29
27
  if (dryRun) {
28
+ logger.info('slack post message (dry run)', { message });
30
29
  return;
31
30
  }
32
31
  try {
@@ -43,7 +42,7 @@ function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = proc
43
42
  return response.jsonData;
44
43
  }
45
44
  catch (error) {
46
- (0, logger_1.getLogger)('core').error(error);
45
+ logger.error(error);
47
46
  throw error;
48
47
  }
49
48
  }
@@ -51,4 +50,3 @@ function createSlack({ webhookUrl = process.env.SLACK_WEBHOOK_URL, dryRun = proc
51
50
  postMessage,
52
51
  };
53
52
  }
54
- exports.createSlack = createSlack;
@@ -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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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((0, errors_1.BadRequest)({ body: result.errors }));
9
+ return next(BadRequest({ body: result.errors }));
15
10
  }
16
11
  next();
17
12
  };
18
13
  }
19
- exports.validateBody = validateBody;
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((0, errors_1.BadRequest)({ query: result.errors }));
19
+ return next(BadRequest({ query: result.errors }));
26
20
  }
27
21
  next();
28
22
  };
29
23
  }
30
- exports.validateQuery = validateQuery;
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((0, errors_1.BadRequest)({ params: result.errors }));
29
+ return next(BadRequest({ params: result.errors }));
37
30
  }
38
31
  next();
39
32
  };
40
33
  }
41
- exports.validateParams = validateParams;
42
- function compileValidateSchema(schema, options = {}) {
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
- exports.compileValidateSchema = compileValidateSchema;
65
- function validateSchema(data, schema, options = {}) {
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.13.9",
3
+ "version": "0.15.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 --declaration --project tsconfig.build.json",
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,13 +34,20 @@
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.1",
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",
41
- "jest": "29.2.2",
50
+ "jest": "29.3.1",
42
51
  "prettier": "2.7.1",
43
52
  "supertest": "6.3.1",
44
53
  "ts-jest": "29.0.3",
@@ -48,8 +57,8 @@
48
57
  "dependencies": {
49
58
  "@devmoods/fetch": "^3.3.0",
50
59
  "@godaddy/terminus": "^4.11.2",
51
- "@sentry/node": "^7.17.4",
52
- "@sentry/tracing": "^7.17.4",
60
+ "@sentry/node": "^7.18.0",
61
+ "@sentry/tracing": "^7.18.0",
53
62
  "@types/bcrypt": "^5.0.0",
54
63
  "@types/bunyan": "^1.8.8",
55
64
  "@types/cls-hooked": "^4.3.3",
@@ -65,16 +74,16 @@
65
74
  "cls-hooked": "^4.2.2",
66
75
  "compose-middleware": "^5.0.1",
67
76
  "cookie-parser": "^1.4.6",
68
- "dotenv-safe": "^8.2.0",
77
+ "dotenv": "^16.0.3",
69
78
  "express": "^4.18.2",
70
- "helmet": "^5.1.1",
79
+ "helmet": "^6.0.0",
71
80
  "jsonwebtoken": "^8.5.1",
72
- "meow": "^9.0.0",
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": "^8.3.2"
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
  }
package/bin/migrate DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('dotenv').config({
4
- allowEmptyValues: true,
5
- });
6
-
7
- require('ts-node').register({});
8
- const { cli } = require('../dist/migrate.js');
9
- cli();