@axiumine/koa-utils 7.0.0 → 7.1.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.
Files changed (89) hide show
  1. package/LICENSE +0 -5
  2. package/README.md +78 -2
  3. package/dist/dataSources/MariaDB.mjs +8 -6
  4. package/dist/dataSources/MongoDB.mjs +1 -1
  5. package/dist/dataSources/PostgreSQL.mjs +12 -12
  6. package/dist/dataSources/Redis.mjs +16 -7
  7. package/dist/email/SocketLabsLib.d.mts +0 -13
  8. package/dist/email/SocketLabsLib.mjs +48 -208
  9. package/dist/files/moveFileStaticDomain.mjs +1 -1
  10. package/dist/files/storeUploadAsTemp.mjs +5 -1
  11. package/dist/files/uploadTempImage.mjs +2 -1
  12. package/dist/files/uploadTempPdf.mjs +2 -1
  13. package/dist/graphQL/models/MongoDB/UserBase.d.mts +3 -1
  14. package/dist/graphQL/models/MongoDB/log/DevStatsGraphQLCalls.d.mts +3 -1
  15. package/dist/graphQL/models/MongoDB/log/LogGlobalError.d.mts +3 -1
  16. package/dist/graphQL/models/MongoDB/log/LogStatsGraphql.d.mts +3 -1
  17. package/dist/graphQL/models/MongoDB/log/LogThrow.d.mts +3 -1
  18. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +8 -76
  19. package/dist/graphQL/schema/mutations/login4Ever.mjs +1 -0
  20. package/dist/graphQL/schema/mutations/loginAdmin.mjs +1 -0
  21. package/dist/graphQL/schema/mutations/loginRememberme.mjs +1 -0
  22. package/dist/graphQL/schema/mutations/logout.mjs +2 -2
  23. package/dist/graphQL/schema/mutations/refresh.mjs +7 -5
  24. package/dist/graphQL/schema/mutations/resetPwd.d.mts +1 -1
  25. package/dist/graphQL/schema/mutations/signUp.mjs +1 -0
  26. package/dist/graphQL/schema/mutations/updatePassword.mjs +1 -48
  27. package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs +2 -2
  28. package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs +2 -0
  29. package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs +2 -2
  30. package/dist/koa/middleware/authenticatedResourceHandler/index.mjs +2 -2
  31. package/dist/koa/tdwKoaErrorHandler.mjs +1 -1
  32. package/dist/lib/ArrayLib.mjs +4 -3
  33. package/dist/lib/DateLib.mjs +1 -0
  34. package/dist/lib/StringLib.mjs +56 -4
  35. package/dist/lib/db/log/hitStat.mjs +1 -0
  36. package/dist/lib/isIntrospectionBypassAllowed.mjs +1 -1
  37. package/dist/lib/isSessionBlocked.mjs +1 -1
  38. package/dist/lib/tokens.mjs +2 -1
  39. package/dist/lib/tryCatchRethrow.mjs +1 -1
  40. package/dist/private/dataSources/isRedisTlsRequired.d.mts +19 -0
  41. package/dist/private/dataSources/isRedisTlsRequired.mjs +20 -0
  42. package/dist/private/dataSources/redisNodeUrl.d.mts +14 -0
  43. package/dist/private/dataSources/redisNodeUrl.mjs +16 -0
  44. package/dist/private/dataSources/resolveRedisUrl.d.mts +17 -0
  45. package/dist/private/dataSources/resolveRedisUrl.mjs +37 -0
  46. package/dist/private/email/IEmailContent.d.mts +9 -0
  47. package/dist/private/email/IEmailContent.mjs +2 -0
  48. package/dist/private/email/accountMessages.d.mts +11 -0
  49. package/dist/private/email/accountMessages.mjs +55 -0
  50. package/dist/private/email/escapeHtml.d.mts +9 -0
  51. package/dist/private/email/escapeHtml.mjs +17 -0
  52. package/dist/private/email/htmlFrame.d.mts +10 -0
  53. package/dist/private/email/htmlFrame.mjs +25 -0
  54. package/dist/private/email/messageParts.d.mts +12 -0
  55. package/dist/private/email/messageParts.mjs +31 -0
  56. package/dist/private/email/noticeMessages.d.mts +14 -0
  57. package/dist/private/email/noticeMessages.mjs +51 -0
  58. package/dist/private/email/orFalse.d.mts +2 -0
  59. package/dist/private/email/orFalse.mjs +12 -0
  60. package/dist/private/email/resetMessages.d.mts +17 -0
  61. package/dist/private/email/resetMessages.mjs +44 -0
  62. package/dist/private/graphQL/models/MongoDB/private/UserAdminKoaUtils.d.mts +4 -2
  63. package/dist/private/graphQL/schema/mutations/_buildLoginStatsUpdate.mjs +4 -4
  64. package/dist/private/graphQL/schema/mutations/infoUserForLoginSQL.mjs +5 -4
  65. package/dist/private/graphQL/schema/mutations/setRedisLoginSession.mjs +2 -2
  66. package/dist/private/graphQL/schema/mutations/updateLoginStats4ever.mjs +2 -2
  67. package/dist/private/lib/access/applyPasswordReset.d.mts +22 -0
  68. package/dist/private/lib/access/applyPasswordReset.mjs +22 -0
  69. package/dist/private/lib/access/assertResetAllowed.d.mts +14 -0
  70. package/dist/private/lib/access/assertResetAllowed.mjs +51 -0
  71. package/dist/private/lib/access/assertVerifyEmailAllowed.d.mts +6 -1
  72. package/dist/private/lib/access/db/abandonUser.mjs +3 -0
  73. package/dist/private/lib/access/db/confirmNewEmail.mjs +2 -0
  74. package/dist/private/lib/access/db/deleteUserByEmail.mjs +2 -0
  75. package/dist/private/lib/access/db/enableEmailAccess.mjs +2 -0
  76. package/dist/private/lib/access/db/getResetPwd.mjs +2 -0
  77. package/dist/private/lib/access/db/removeResetReq.mjs +2 -0
  78. package/dist/private/lib/access/db/saveResetReq.mjs +2 -0
  79. package/dist/private/lib/access/db/setEmailHash.mjs +2 -0
  80. package/dist/private/lib/access/db/updatePasswordDb.mjs +2 -0
  81. package/dist/private/lib/access/db/userData4VerifyEmail.mjs +2 -0
  82. package/dist/private/lib/access/emailChangeHandlers.d.mts +35 -0
  83. package/dist/private/lib/access/emailChangeHandlers.mjs +87 -0
  84. package/dist/private/lib/access/handleIfHashBad.d.mts +4 -2
  85. package/dist/private/lib/access/handleIfHashBad.mjs +4 -1
  86. package/dist/private/lib/access/safeEqualSecret.d.mts +13 -0
  87. package/dist/private/lib/access/safeEqualSecret.mjs +26 -0
  88. package/dist/private/lib/verifyIntrospectionCode.mjs +1 -1
  89. package/package.json +59 -25
package/LICENSE CHANGED
@@ -1,8 +1,3 @@
1
- koa-utils — Koa utility package
2
- Copyright (C) 2026 Giovanni Manzoni
3
-
4
-
5
-
6
1
  GNU GENERAL PUBLIC LICENSE
7
2
  Version 3, 29 June 2007
8
3
  Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @axiumine/koa-utils
2
2
 
3
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/Axiumine/koa-utils/badge)](https://scorecard.dev/viewer/?uri=github.com/Axiumine/koa-utils)
4
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/16094/badge)](https://www.bestpractices.dev/projects/16094)
5
+
3
6
  TypeScript utility library for Koa + GraphQL backends. Ships authentication middleware, GraphQL error helpers, data-source connectors (MongoDB, MariaDB, PostgreSQL, Redis), file upload pipeline (ClamAV + sharp re-encode), and transactional email via SocketLabs.
4
7
 
5
8
  - **Module format:** ESM only (`.mjs` + `.d.mts`)
@@ -7,6 +10,7 @@ TypeScript utility library for Koa + GraphQL backends. Ships authentication midd
7
10
  - **TypeScript:** `6.0`
8
11
  - **License:** GPL-3.0-or-later
9
12
  - **Maintainer:** [Giovanni Manzoni](https://www.giovannimanzoni.com)
13
+ - **Project:** [Contributing](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) · [Governance](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md) · [Roadmap](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md) · [Security policy](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md) · [Code of Conduct](https://github.com/Axiumine/koa-utils/blob/main/CODE_OF_CONDUCT.md) · [Changelog](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md)
10
14
 
11
15
  ## Install
12
16
 
@@ -43,6 +47,39 @@ The remaining twelve are declared **optional** in `peerDependenciesMeta`. There
43
47
 
44
48
  Optionality is a promise about the load path, not a way to silence the warning: it holds only while the dependency stays behind a subpath the consumer opts into. Adding a root `"."` barrel, or importing one of these from a module that every subpath reaches, breaks it for every consumer at once.
45
49
 
50
+ ## Quick start
51
+
52
+ A Koa app that refuses every request without a valid access token and answers with the caller's id. It needs a MongoDB and a Redis server you can reach.
53
+
54
+ ```bash
55
+ yarn add @axiumine/koa-utils @node-rs/bcrypt @sentry/node dotenv graphql mongoose redis uuid koa
56
+ printf 'MONGODB_URI=mongodb://localhost:27017/app\nREDIS_URL=redis://localhost:6379\nREDIS_KEY=app:\n' > .env
57
+ ```
58
+
59
+ Save this as `server.mts`:
60
+
61
+ ```ts
62
+ import 'dotenv/config'
63
+ import Koa from 'koa'
64
+ import { MongoDBConnect } from '@axiumine/koa-utils/dataSources/MongoDB'
65
+ import { RedisConnect } from '@axiumine/koa-utils/dataSources/Redis'
66
+ import { tdwKoaErrorHandler } from '@axiumine/koa-utils/koa/tdwKoaErrorHandler'
67
+ import { authenticatedResourceHandler } from '@axiumine/koa-utils/koa/middleware/authenticatedResourceHandler'
68
+
69
+ await MongoDBConnect()
70
+ await RedisConnect()
71
+
72
+ const app = new Koa()
73
+ app.use(tdwKoaErrorHandler)
74
+ app.use(authenticatedResourceHandler())
75
+ app.use(async (ctx) => {
76
+ ctx.body = { userId: String(ctx.state.user.id) }
77
+ })
78
+ app.listen(3000)
79
+ ```
80
+
81
+ Run it with `node server.mts` (an ES module project, `"type": "module"`, Node `^24.14.0`, which strips the types itself). `curl -i localhost:3000` answers `412 Precondition Failed` ("No authorization header."): a request needs `Authorization: Bearer access:<uuid>` with a token that exists in Redis. To obtain one, add the `signUp` and `loginRememberme` mutations from [Usage](#usage) to your GraphQL schema and follow the [Auth flow](#auth-flow).
82
+
46
83
  ## Usage
47
84
 
48
85
  No barrel — import each helper from its explicit subpath.
@@ -69,7 +106,10 @@ import { authenticatedResourceHandler } from '@axiumine/koa-utils/koa/middleware
69
106
  import { authenticatedAuthorizationHandler } from '@axiumine/koa-utils/koa/middleware/authenticatedAuthorizationHandler'
70
107
 
71
108
  const app = new Koa()
72
- const keys = new Keygrip([process.env.COOKIE_KEY!])
109
+ // Keygrip signs with HMAC-SHA1 unless told otherwise: pass 'sha256'.
110
+ // Koa signs the refresh cookie with app.keys, so verify with that same instance.
111
+ const keys = new Keygrip([process.env.COOKIE_KEY!], 'sha256')
112
+ app.keys = keys
73
113
 
74
114
  app.use(tdwKoaErrorHandler)
75
115
  app.use(authenticatedResourceHandler()) // resource endpoints
@@ -126,7 +166,7 @@ const verify = createVerifyEmailFlow({
126
166
  router.get('/check/verify-email/:email/:hash', verify.routerVerifyEmail())
127
167
  ```
128
168
 
129
- Every `paths` key is optional and falls back to the `UserBase` layout, so the package-level exports are exactly these factories with no overrides. See [docs/code/lib-access.md](./docs/code/lib-access.md).
169
+ Every `paths` key is optional and falls back to the `UserBase` layout, so the package-level exports are exactly these factories with no overrides. See [docs/code/lib-access.md](https://github.com/Axiumine/koa-utils/blob/main/docs/code/lib-access.md).
130
170
 
131
171
  `onAbandon` decides what the two disposal guards — the fifth wrong hash and a link older than 3 days — do to a pending registration. The default `'delete'` removes the row; use `'soft-delete'` or `'keep'` when other collections depend on it, since mongo has no cascade, or pass `deleteUserByEmail` to replace the writer outright. The link is rejected either way.
132
172
 
@@ -200,6 +240,7 @@ import { StringLib } from '@axiumine/koa-utils/lib/StringLib'
200
240
  | `POSTGRESQL_USER`, `_PWD`, `_HOST`, `_PORT`, `_DBNAME`, `_POOL_MAX`, `_IDLE_TIMEOUT` | PostgreSQL |
201
241
  | `REDIS_URL` or `REDIS_IS_CLUSTER` + `REDIS_DB{1,2,3}_HOST/PORT`, `REDIS_USERNAME`, `REDIS_PASSWORD` | Redis |
202
242
  | `REDIS_KEY` | Prefix for all keys (e.g. `myapp:`) |
243
+ | `REDIS_TLS` | Set to exactly `true` to require TLS: cluster nodes are built as `rediss://` and a non-`rediss://` `REDIS_URL` refuses to boot (see below). Any other value, unset included, keeps the previous plaintext behaviour |
203
244
  | `INTROSPECTION_CODE` | Bypass header `x-introspectioncode` for schema introspection — **only honoured when `NODE_ENV` is `development` or `test`** (see below) |
204
245
  | `SOCKETLABS_SERVER_ID`, `SOCKETLABS_SERVER_APIKEY` | SocketLabs auth |
205
246
  | `PLATFORM_NAME`, `APP_DOMAIN`, `EMAIL_FROM`, `DEV_TEAM_EMAIL` | Email templating |
@@ -224,6 +265,29 @@ if (isIntrospectionBypassAllowed()) {
224
265
  }
225
266
  ```
226
267
 
268
+ ### Redis TLS — the `REDIS_TLS` flag
269
+
270
+ `REDIS_TLS` is opt-in and off by default: with the variable unset, `redisClient` connects exactly as it did before the flag existed, so upgrading changes nothing for an existing deployment.
271
+
272
+ Set it to the **exact** string `true` to require TLS. The match is deliberately exact — `TRUE`, `1`, `yes` and `on` are all read as *off*, because the alternatives (`Boolean(process.env.REDIS_TLS)`, `!== 'false'`) would force TLS on operators who wrote `false` or wrote nothing at all.
273
+
274
+ | | `REDIS_TLS` unset / any other value | `REDIS_TLS=true` |
275
+ | --- | --- | --- |
276
+ | Single client (`REDIS_URL`) | `REDIS_URL` used as-is, whatever its scheme | `REDIS_URL` **must** use the `rediss://` scheme, or the module throws at import time |
277
+ | Cluster (`REDIS_IS_CLUSTER=1`) | root nodes built as `redis://host:port`, `defaults.socket.tls` is `false` | root nodes built as `rediss://host:port`, `defaults.socket.tls` is `true` |
278
+
279
+ The single-client path fails closed rather than rewriting the scheme for you. A silent upgrade from `redis://` to `rediss://` would hide the misconfiguration until the TLS handshake failed, against a host that may not be the one you meant; refusing at startup turns it into one unmissable error instead. The three messages it can throw are:
280
+
281
+ ```
282
+ [Redis] REDIS_TLS is enabled but REDIS_URL is not set — a rediss:// URL is required.
283
+ [Redis] REDIS_TLS is enabled but REDIS_URL is not a valid URL — a rediss:// URL is required.
284
+ [Redis] REDIS_TLS is enabled but REDIS_URL uses scheme "redis:" — rediss:// required.
285
+ ```
286
+
287
+ The scheme is compared through `new URL().protocol`, the same way node-redis compares it, so an upper-case `REDISS://cache:6379` is accepted.
288
+
289
+ For the cluster path the `rediss://` scheme on `rootNodes` is not enough on its own: node-redis uses `rootNodes` only to discover the topology and does not inherit their TLS setting for the connections it then opens to the discovered nodes. `defaults.socket.tls` is what actually carries TLS across the cluster, and it is set from the same flag.
290
+
227
291
  ## TLS / cookies
228
292
 
229
293
  `tokenOptions` sets `secure: false` by design. Flip it at the reverse proxy (Nginx / Caddy / CloudFront), not in source.
@@ -234,7 +298,11 @@ if (isIntrospectionBypassAllowed()) {
234
298
  yarn install
235
299
  yarn build # ESM only — production output
236
300
  yarn build:all # ESM + CJS dual output
301
+ yarn test # build + build:tests + mocha, no coverage gate
302
+ yarn test:coverage # same under c8: fails below 100% on lines, statements, functions or branches of any file
237
303
  yarn lint # eslint --fix + prettier --write
304
+ yarn lint:check # eslint + prettier --check, writes nothing
305
+ yarn check:static # every static gate: caps, lint, typecheck (src, scripts, specs), knip, type-coverage, fta (runs in CI)
238
306
  yarn clean
239
307
  ```
240
308
 
@@ -252,6 +320,14 @@ There is no barrel and no `main` / `module` field.
252
320
 
253
321
  Maintainers who install through a private npm mirror should not commit its host: a git clean/smudge filter rewrites the `resolved` URLs in both directions, keeping the mirror in the working copy and the public registry in history. `yarn install` configures it (via `prepare` → `hooks:install`); point it at your own mirror with `YARN_PROXY_REGISTRY`. A pre-commit check rejects any lockfile that still names a non-public host.
254
322
 
323
+ ## Feedback, contributing and security
324
+
325
+ - **Bugs and feature requests:** open an issue at <https://github.com/Axiumine/koa-utils/issues/new/choose>. Issues are public and searchable.
326
+ - **Contributing code:** fork, branch from `main` and open a pull request; larger changes start with an issue. [CONTRIBUTING.md](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) lists the requirements (tests at 100% coverage, docs in the same change, Conventional Commits, GPL-3.0-or-later). How decisions are made is in [GOVERNANCE.md](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md); the direction is in [ROADMAP.md](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md).
327
+ - **Security vulnerabilities:** never in a public issue. Use GitHub private vulnerability reporting or the email in [SECURITY.md](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md), which also states the supported versions and response times.
328
+ - **Security model and design:** what the library does and does not protect against is in [docs/security.md](https://github.com/Axiumine/koa-utils/blob/main/docs/security.md); the structure is in [docs/architecture.md](https://github.com/Axiumine/koa-utils/blob/main/docs/architecture.md). How to check a release (signed tag, rebuild, attestation) is in [docs/verify-release.md](https://github.com/Axiumine/koa-utils/blob/main/docs/verify-release.md).
329
+ - **Release notes:** [CHANGELOG.md](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md), one entry per release, with a `Security` section whenever a release fixes a vulnerability.
330
+
255
331
  ## Repository
256
332
 
257
333
  <https://github.com/Axiumine/koa-utils>
@@ -2,8 +2,8 @@ import * as Sentry from '@sentry/node';
2
2
  import * as dotenv from 'dotenv';
3
3
  import { Sequelize } from 'sequelize-typescript';
4
4
  dotenv.config();
5
- export const sequelize = new Sequelize(`${process.env.MARIADB_DBNAME}`, `${process.env.MARIADB_USER}`, `${process.env.MARIADB_PWD}`, {
6
- host: `${process.env.MARIADB_IP}`,
5
+ export const sequelize = new Sequelize(`${process.env['MARIADB_DBNAME']}`, `${process.env['MARIADB_USER']}`, `${process.env['MARIADB_PWD']}`, {
6
+ host: `${process.env['MARIADB_IP']}`,
7
7
  dialect: 'mariadb',
8
8
  query: { raw: true },
9
9
  pool: {
@@ -24,17 +24,19 @@ export const sequelize = new Sequelize(`${process.env.MARIADB_DBNAME}`, `${proce
24
24
  backoffExponent: 1.1,
25
25
  timeout: 3000,
26
26
  backoffJitter: 0.1, // Add this required property
27
- max: parseInt(`${process.env.MARIADB_RETRY}`) || 5
27
+ max: parseInt(`${process.env['MARIADB_RETRY']}`) || 5
28
28
  },
29
29
  dialectOptions: {
30
30
  useUTC: true,
31
31
  skipSetTimezone: true,
32
32
  compress: true,
33
- requestTimeout: parseInt(`${process.env.MARIADB_TIMEOUT}`) || 5000
33
+ requestTimeout: parseInt(`${process.env['MARIADB_TIMEOUT']}`) || 5000
34
34
  },
35
- port: parseInt(`${process.env.MARIADB_PORT}`, 10),
35
+ port: parseInt(`${process.env['MARIADB_PORT']}`, 10),
36
+ // Explicit `undefined` is load-bearing: Sequelize reads the key with hasOwnProperty, so omitting it would switch
37
+ // query logging on. The cast only satisfies exactOptionalPropertyTypes (tsconfig.check.json); runtime is unchanged.
36
38
  /* c8 ignore next -- env-dependent boot config; covered only when MARIADB_LOGGING='false' */
37
- logging: process.env.MARIADB_LOGGING === 'false' ? false : undefined // disable print queries in console
39
+ logging: (process.env['MARIADB_LOGGING'] === 'false' ? false : undefined) // disable print queries in console
38
40
  });
39
41
  // Setting up a connection
40
42
  export const MariaDBConnect = async () => {
@@ -24,7 +24,7 @@ export async function MongoDBConnect() {
24
24
  };
25
25
  mongoose.set('sanitizeFilter', true);
26
26
  mongoose.set('strictQuery', false); // will be done in mongose 7
27
- await mongoose.connect(`${process.env.MONGODB_URI}`, options);
27
+ await mongoose.connect(`${process.env['MONGODB_URI']}`, options);
28
28
  /* c8 ignore next 2 -- success log + closing brace; covered only with live MongoDB */
29
29
  console.info('[MongoDB] OK: MongoDB connection has been established successfully. ');
30
30
  }
@@ -4,20 +4,20 @@ import pg from 'pg';
4
4
  const { Client, Pool } = pg;
5
5
  dotenv.config();
6
6
  export const pgClient = new Client({
7
- user: `${process.env.POSTGRESQL_USER}`,
8
- password: `${process.env.POSTGRESQL_PWD}`,
9
- host: `${process.env.POSTGRESQL_HOST}`,
10
- port: parseInt(`${process.env.POSTGRESQL_PORT}`, 10),
11
- database: `${process.env.POSTGRESQL_DBNAME}`
7
+ user: `${process.env['POSTGRESQL_USER']}`,
8
+ password: `${process.env['POSTGRESQL_PWD']}`,
9
+ host: `${process.env['POSTGRESQL_HOST']}`,
10
+ port: parseInt(`${process.env['POSTGRESQL_PORT']}`, 10),
11
+ database: `${process.env['POSTGRESQL_DBNAME']}`
12
12
  });
13
13
  export const pgPool = new Pool({
14
- user: `${process.env.POSTGRESQL_USER}`,
15
- password: `${process.env.POSTGRESQL_PWD}`,
16
- host: `${process.env.POSTGRESQL_HOST}`,
17
- port: parseInt(`${process.env.POSTGRESQL_PORT}`, 10),
18
- database: `${process.env.POSTGRESQL_DBNAME}`,
19
- max: parseInt(`${process.env.POSTGRESQL_POOL_MAX}`, 10),
20
- idleTimeoutMillis: parseInt(`${process.env.POSTGRESQL_IDLE_TIMEOUT}`, 10)
14
+ user: `${process.env['POSTGRESQL_USER']}`,
15
+ password: `${process.env['POSTGRESQL_PWD']}`,
16
+ host: `${process.env['POSTGRESQL_HOST']}`,
17
+ port: parseInt(`${process.env['POSTGRESQL_PORT']}`, 10),
18
+ database: `${process.env['POSTGRESQL_DBNAME']}`,
19
+ max: parseInt(`${process.env['POSTGRESQL_POOL_MAX']}`, 10),
20
+ idleTimeoutMillis: parseInt(`${process.env['POSTGRESQL_IDLE_TIMEOUT']}`, 10)
21
21
  });
22
22
  // the pool will emit an error on behalf of any idle clients
23
23
  // it contains if a backend error or network partition happens
@@ -1,22 +1,31 @@
1
+ import { isRedisTlsRequired } from "../private/dataSources/isRedisTlsRequired.mjs";
2
+ import { redisNodeUrl } from "../private/dataSources/redisNodeUrl.mjs";
3
+ import { resolveRedisUrl } from "../private/dataSources/resolveRedisUrl.mjs";
1
4
  import * as Sentry from '@sentry/node';
2
5
  import * as dotenv from 'dotenv';
3
6
  import { createClient, createCluster } from 'redis';
4
7
  dotenv.config();
5
- export const redisClient = process.env.REDIS_IS_CLUSTER === '1'
8
+ export const redisClient = process.env['REDIS_IS_CLUSTER'] === '1'
6
9
  ? /* c8 ignore start -- cluster branch: requires REDIS_IS_CLUSTER=1 + 3 redis nodes, not in unit env */
7
10
  createCluster({
8
11
  rootNodes: [
9
- { url: `redis://${process.env.REDIS_DB1_HOST}:${process.env.REDIS_DB1_PORT}` },
10
- { url: `redis://${process.env.REDIS_DB2_HOST}:${process.env.REDIS_DB2_PORT}` },
11
- { url: `redis://${process.env.REDIS_DB3_HOST}:${process.env.REDIS_DB3_PORT}` }
12
+ { url: redisNodeUrl(process.env['REDIS_DB1_HOST'], process.env['REDIS_DB1_PORT']) },
13
+ { url: redisNodeUrl(process.env['REDIS_DB2_HOST'], process.env['REDIS_DB2_PORT']) },
14
+ { url: redisNodeUrl(process.env['REDIS_DB3_HOST'], process.env['REDIS_DB3_PORT']) }
12
15
  ],
13
16
  defaults: {
14
- username: process.env.REDIS_USERNAME,
15
- password: process.env.REDIS_PASSWORD
17
+ // casts only satisfy exactOptionalPropertyTypes (tsconfig.check.json); an unset var still reaches node-redis as undefined
18
+ username: process.env['REDIS_USERNAME'],
19
+ password: process.env['REDIS_PASSWORD'],
20
+ // rootNodes only carry the topology-discovery connections; node-redis does not inherit their
21
+ // TLS setting for the connections it then opens to the discovered nodes. Without this the
22
+ // rediss:// scheme above would be a no-op and every real cluster connection would stay
23
+ // plaintext. See the rootNodes JSDoc in @redis/client's cluster/index.d.ts.
24
+ socket: isRedisTlsRequired() ? { tls: true } : { tls: false }
16
25
  }
17
26
  })
18
27
  : /* c8 ignore stop */
19
- createClient({ url: process.env.REDIS_URL });
28
+ createClient({ url: resolveRedisUrl(process.env['REDIS_URL']) }); // cast: see the cluster branch above
20
29
  export const RedisConnect = async () => {
21
30
  console.info('[Redis] Try connect to database... ');
22
31
  redisClient.on('error', (e) => {
@@ -6,7 +6,6 @@ interface IUserInfo {
6
6
  };
7
7
  }
8
8
  export declare class SocketLabsLib {
9
- private StringObj;
10
9
  private readonly platformName;
11
10
  private readonly linkBase;
12
11
  private readonly emailFrom;
@@ -134,17 +133,5 @@ SendResponse {
134
133
  getHtmlHeader(title: string): string;
135
134
  getHtmlFooter(): string;
136
135
  private sendTemplate;
137
- private sendEmail;
138
- /**
139
- * fallback header
140
- * @private
141
- */
142
- private htmlHeader1;
143
- /**
144
- * fallback header
145
- * @private
146
- */
147
- private htmlHeader2;
148
- private fixName;
149
136
  }
150
137
  export {};