@devmoods/express-extras 0.28.4 → 0.28.6

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Request, type RequestHandler, type Response, Router } from 'express';
2
- import type { RedisClient } from './redis.js';
2
+ import { type RedisClient } from './redis.js';
3
3
  /**
4
4
  * Returns a signed JWT token.
5
5
  */
package/dist/auth.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as crypto from 'node:crypto';
2
- import * as bcrypt from 'bcrypt';
2
+ import bcrypt from 'bcrypt';
3
3
  import { Router, } from 'express';
4
4
  import jwt from 'jsonwebtoken';
5
5
  import { v4 } from 'uuid';
@@ -7,8 +7,9 @@ import { setContext, useContext } from './context.js';
7
7
  import { BadRequest, NotFound, Unauthorized } from './errors.js';
8
8
  import { getLogger } from './logger.js';
9
9
  import { route } from './middleware.js';
10
- import { validateBody, validateParams, } from './validate.js';
10
+ import {} from './redis.js';
11
11
  import { readEnv } from './utils.js';
12
+ import { validateBody, validateParams, } from './validate.js';
12
13
  const logger = getLogger('auth');
13
14
  const TOKEN_EXPIRES_IN = readEnv.number('AUTH_TOKEN_EXPIRES', 3600 * 48);
14
15
  const TEMP_TOKEN_EXIRES_IN = readEnv.number('AUTH_TEMP_TOKEN_EXPIRES', 3600);
@@ -24,6 +25,7 @@ const emailSchema = { type: 'string', minLength: 4 };
24
25
  * Returns a signed JWT token.
25
26
  */
26
27
  export function createAuthToken(payload, secret = AUTH_SECRET) {
28
+ // eslint-disable-next-line import/no-named-as-default-member
27
29
  return jwt.sign(payload, secret, { expiresIn: TOKEN_EXPIRES_IN });
28
30
  }
29
31
  /**
@@ -31,6 +33,7 @@ export function createAuthToken(payload, secret = AUTH_SECRET) {
31
33
  */
32
34
  export function decodeAuthToken(token, secret = AUTH_SECRET) {
33
35
  try {
36
+ // eslint-disable-next-line import/no-named-as-default-member
34
37
  const decoded = jwt.verify(token.trim(), secret);
35
38
  /* c8 ignore next 3 */
36
39
  if (typeof decoded === 'string') {
@@ -327,6 +330,7 @@ export async function checkIfPasswordsMatch(realPassword, attemptedPassword) {
327
330
  if (!realPassword) {
328
331
  throw new Error('User has no defined password');
329
332
  }
333
+ // eslint-disable-next-line import/no-named-as-default-member
330
334
  const validPassword = await bcrypt.compare(attemptedPassword, realPassword);
331
335
  if (!validPassword) {
332
336
  throw new Error(`Passwords do not match`);
@@ -337,5 +341,6 @@ export async function checkIfPasswordsMatch(realPassword, attemptedPassword) {
337
341
  * Returns a hash of a password suitable for storage.
338
342
  */
339
343
  export function hashPassword(password) {
344
+ // eslint-disable-next-line import/no-named-as-default-member
340
345
  return bcrypt.hash(password, 10);
341
346
  }
package/dist/errors.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { STATUS_CODES } from 'node:http';
1
2
  import * as Sentry from '@sentry/node';
2
3
  import { errors } from 'compose-middleware';
3
- import { STATUS_CODES } from 'node:http';
4
+ import {} from 'express';
4
5
  import { DoesNotExistError, IntegrityError } from './postgres.js';
5
6
  export class ApiError extends Error {
6
7
  }
package/dist/listen.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { Application } from 'express';
3
- import type { Server } from 'node:http';
2
+ import { type Server } from 'node:http';
3
+ import { type Application } from 'express';
4
4
  interface StoppableServer extends Server {
5
5
  inspect(): Record<string, any>;
6
6
  stop(): Promise<boolean>;
package/dist/listen.js CHANGED
@@ -1,5 +1,8 @@
1
- import { delay } from '@devmoods/fetch';
2
1
  import * as http from 'node:http';
2
+ import {} from 'node:http';
3
+ import {} from 'node:net';
4
+ import { delay } from '@devmoods/fetch';
5
+ import {} from 'express';
3
6
  import { getLogger } from './logger.js';
4
7
  import { route } from './middleware.js';
5
8
  import { envPort, readEnv } from './utils.js';
package/dist/logger.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { Duplex } from 'node:stream';
3
- import type { CreateSentry } from './sentry.js';
2
+ import { type Duplex } from 'node:stream';
3
+ import { type CreateSentry } from './sentry.js';
4
4
  export type LoggerContext = Record<string, any>;
5
5
  export interface LoggerOptions {
6
6
  /**
package/dist/logger.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as os from 'node:os';
2
+ import {} from 'node:stream';
2
3
  import { useRequestId } from './context.js';
4
+ import {} from './sentry.js';
3
5
  import { readEnv } from './utils.js';
4
6
  const LEVELS = {
5
7
  TRACE: 10,
@@ -0,0 +1,5 @@
1
+ import { program } from 'commander';
2
+ type Command = typeof program.command;
3
+ export declare function registerManagementCommand(register: (command: Command) => void): void;
4
+ export declare function runManagementCommands(): Promise<void>;
5
+ export {};
package/dist/manage.js ADDED
@@ -0,0 +1,7 @@
1
+ import { program } from 'commander';
2
+ export function registerManagementCommand(register) {
3
+ register(program.command.bind(program));
4
+ }
5
+ export async function runManagementCommands() {
6
+ await program.parseAsync(process.argv);
7
+ }
@@ -1,5 +1,5 @@
1
1
  import bodyParser from 'body-parser';
2
- import type { RequestHandler } from 'express';
2
+ import { type RequestHandler } from 'express';
3
3
  type UrlencodedParser = typeof bodyParser.urlencoded;
4
4
  type JsonParser = typeof bodyParser.json;
5
5
  export declare const urlencodedParser: UrlencodedParser;
@@ -2,6 +2,7 @@ import * as Sentry from '@sentry/node';
2
2
  import bodyParser from 'body-parser';
3
3
  import { compose } from 'compose-middleware';
4
4
  import cookieParser from 'cookie-parser';
5
+ import {} from 'express';
5
6
  import helmet from 'helmet';
6
7
  import { withRequestContext } from './context.js';
7
8
  import { NotFound } from './errors.js';
@@ -26,7 +27,12 @@ export function before({ cookies = false, helmet: useHelmet = true, json: useJso
26
27
  directives: {
27
28
  'default-src': ["'self'"],
28
29
  'base-uri': ["'self'"],
29
- 'connect-src': ["'self'", 'ws:', '*.sentry.io'],
30
+ 'connect-src': [
31
+ "'self'",
32
+ 'ws:',
33
+ '*.sentry.io',
34
+ '*.cdn-apple.com',
35
+ ],
30
36
  'font-src': ["'self'", 'https:', 'data:'],
31
37
  'form-action': ["'self'"],
32
38
  'frame-ancestors': ["'self'"],
@@ -1,8 +1,8 @@
1
- import pg, { type PoolClient, type QueryResult, type QueryResultRow } from 'pg';
1
+ import pg, { type PoolClient, type PoolConfig, type QueryResult, type QueryResultRow } from 'pg';
2
2
  import { SQL, type SQLStatement } from 'sql-template-strings';
3
- export interface PostgresOptions extends pg.PoolConfig {
3
+ export interface PostgresOptions extends PoolConfig {
4
4
  onError?: (error: Error, client: any) => void;
5
- url?: pg.PoolConfig['connectionString'];
5
+ url?: PoolConfig['connectionString'];
6
6
  }
7
7
  export declare class DoesNotExistError extends Error {
8
8
  constructor(message: string);
package/dist/postgres.js CHANGED
@@ -70,6 +70,7 @@ export class Transaction extends Connection {
70
70
  * @param config
71
71
  */
72
72
  export function createPostgres({ onError, url = readEnv('POSTGRES_URL'), ...config } = {}) {
73
+ // eslint-disable-next-line import/no-named-as-default-member
73
74
  const pool = new pg.Pool({ connectionString: url, ...config });
74
75
  if (onError) {
75
76
  pool.on('error', onError);
package/dist/routes.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Express, RequestHandler } from 'express';
1
+ import { type Express, type RequestHandler } from 'express';
2
2
  export declare function createDocsRouter(app: Express, extras?: Record<string, any>): RequestHandler;
package/dist/routes.js CHANGED
@@ -1,3 +1,4 @@
1
+ import {} from 'express';
1
2
  import { parseExpressApp } from 'express-route-parser';
2
3
  import { route } from './middleware.js';
3
4
  export function createDocsRouter(app, extras = {}) {
@@ -1,4 +1,9 @@
1
1
  import 'dotenv/config';
2
2
  import * as crypto from 'node:crypto';
3
- // @ts-ignore
4
- globalThis.crypto = crypto;
3
+ try {
4
+ // @ts-ignore
5
+ globalThis.crypto = crypto;
6
+ }
7
+ catch (e) {
8
+ // empty
9
+ }
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { EventEmitter } from 'node:events';
2
+ import { type EventEmitter } from 'node:events';
3
3
  /**
4
4
  * Start a high resolution timer
5
5
  *
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import {} from 'node:events';
1
2
  /**
2
3
  * Start a high resolution timer
3
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devmoods/express-extras",
3
- "version": "0.28.4",
3
+ "version": "0.28.6",
4
4
  "description": "Kubernetes-ready utilities for rapid Node.js application development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,67 +23,65 @@
23
23
  ],
24
24
  "license": "ISC",
25
25
  "devDependencies": {
26
- "@devmoods/eslint-config": "^1.2.0",
27
- "@types/koa-compose": "^3.2.5",
28
- "@types/node": "20.5.9",
29
- "@types/supertest": "^2.0.12",
30
- "@typescript-eslint/eslint-plugin": "^6.6.0",
31
- "@typescript-eslint/parser": "^6.6.0",
32
- "@vitest/coverage-v8": "^0.34.3",
26
+ "@devmoods/eslint-config": "^1.8.0",
27
+ "@types/koa-compose": "^3.2.8",
28
+ "@types/node": "20.9.0",
29
+ "@types/supertest": "^2.0.16",
30
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
31
+ "@typescript-eslint/parser": "^6.10.0",
32
+ "@vitest/coverage-v8": "^0.34.6",
33
33
  "chalk": "^5.3.0",
34
- "eslint": "^8.48.0",
35
- "eslint-plugin-jsx-a11y": "^6.7.1",
36
- "eslint-plugin-prettier": "^5.0.0",
34
+ "eslint": "^8.53.0",
35
+ "eslint-plugin-import": "^2.29.0",
36
+ "eslint-plugin-jsx-a11y": "^6.8.0",
37
+ "eslint-plugin-prettier": "^5.0.1",
37
38
  "eslint-plugin-react": "^7.33.2",
38
39
  "eslint-plugin-react-hooks": "^4.6.0",
39
40
  "faktory-worker": "^4.5.1",
40
- "import-sort-cli": "6.0.0",
41
- "import-sort-style-module": "6.0.0",
42
41
  "prettier": "3.0.3",
43
42
  "supertest": "6.3.3",
44
43
  "ts-node": "10.9.1",
45
44
  "typescript": "5.2.2",
46
- "vitest": "^0.34.3"
45
+ "vitest": "^0.34.6"
47
46
  },
48
47
  "dependencies": {
49
48
  "@devmoods/fetch": "^4.0.1",
50
- "@sentry/node": "^7.67.0",
51
- "@types/bcrypt": "^5.0.0",
52
- "@types/body-parser": "^1.19.2",
53
- "@types/cookie-parser": "^1.4.4",
54
- "@types/express": "^4.17.17",
55
- "@types/jsonwebtoken": "^9.0.2",
56
- "@types/nodemailer": "^6.4.9",
57
- "@types/pg": "^8.10.2",
58
- "@types/superagent": "^4.1.18",
59
- "@types/uuid": "^9.0.3",
49
+ "@sentry/node": "^7.79.0",
50
+ "@types/bcrypt": "^5.0.2",
51
+ "@types/body-parser": "^1.19.5",
52
+ "@types/cookie-parser": "^1.4.6",
53
+ "@types/express": "^4.17.21",
54
+ "@types/jsonwebtoken": "^9.0.5",
55
+ "@types/nodemailer": "^6.4.14",
56
+ "@types/pg": "^8.10.9",
57
+ "@types/superagent": "^4.1.21",
58
+ "@types/uuid": "^9.0.7",
60
59
  "ajv": "^8.12.0",
61
60
  "bcrypt": "^5.1.1",
62
61
  "body-parser": "^1.20.2",
62
+ "commander": "^11.1.0",
63
63
  "compose-middleware": "^5.0.1",
64
64
  "cookie-parser": "^1.4.6",
65
65
  "dotenv": "^16.3.1",
66
66
  "express": "^4.18.2",
67
67
  "express-route-parser": "^1.0.5",
68
- "helmet": "^7.0.0",
68
+ "helmet": "^7.1.0",
69
69
  "jsonwebtoken": "^9.0.2",
70
70
  "meow": "^12.1.1",
71
- "nodemailer": "^6.9.4",
71
+ "nodemailer": "^6.9.7",
72
72
  "pg": "^8.11.3",
73
- "redis": "^4.6.8",
73
+ "redis": "^4.6.10",
74
74
  "sql-template-strings": "^2.2.2",
75
- "uuid": "^9.0.0"
75
+ "uuid": "^9.0.1"
76
76
  },
77
77
  "prettier": {
78
78
  "singleQuote": true
79
79
  },
80
- "importSort": {
81
- ".js, .jsx, .ts, .tsx": {
82
- "style": "module"
83
- }
84
- },
85
80
  "eslintConfig": {
86
81
  "extends": "@devmoods/eslint-config",
82
+ "parserOptions": {
83
+ "project": "./tsconfig.json"
84
+ },
87
85
  "rules": {
88
86
  "@typescript-eslint/consistent-type-imports": "warn",
89
87
  "@typescript-eslint/no-shadow": "off",
@@ -100,8 +98,6 @@
100
98
  "lint": "eslint src",
101
99
  "test": "./test.sh src",
102
100
  "build": "pnpm run clean && tsc --project tsconfig.build.json",
103
- "prettier": "prettier --write '**/*.{js,css,md,ts,tsx}'",
104
- "import-sort": "import-sort --write '**/*.{js,jsx,ts,tsx}'",
105
- "format": "pnpm run import-sort && pnpm run prettier"
101
+ "format": "prettier --write '**/*.{js,css,md,ts,tsx}'"
106
102
  }
107
103
  }