@digitaldefiance/node-express-suite 3.7.3 → 3.7.5

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 (882) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +4 -5
  3. package/src/__tests__/fixtures/{index.d.ts → index.ts} +0 -1
  4. package/src/__tests__/fixtures/model-mocks.mock.ts +164 -0
  5. package/src/__tests__/helpers/application.mock.ts +89 -0
  6. package/src/__tests__/helpers/{index.d.ts → index.ts} +0 -1
  7. package/src/__tests__/helpers/setup-test-env.ts +202 -0
  8. package/src/__tests__/{index.d.ts → index.ts} +0 -1
  9. package/src/application-base.ts +548 -0
  10. package/src/application-concrete.ts +62 -0
  11. package/src/application.ts +330 -0
  12. package/src/backup-code.ts +348 -0
  13. package/src/builders/application-builder.ts +147 -0
  14. package/src/builders/{index.d.ts → index.ts} +0 -1
  15. package/src/constants.ts +89 -0
  16. package/src/container/{index.d.ts → index.ts} +0 -1
  17. package/src/container/service-container.ts +85 -0
  18. package/src/container/service-definitions.ts +23 -0
  19. package/src/controllers/base.ts +512 -0
  20. package/src/controllers/{index.d.ts → index.ts} +0 -1
  21. package/src/controllers/user.ts +1734 -0
  22. package/src/database/database-initializer.ts +13 -0
  23. package/src/database/{index.d.ts → index.ts} +0 -1
  24. package/src/decorators/base-controller.ts +91 -0
  25. package/src/decorators/controller.ts +152 -0
  26. package/src/decorators/{index.d.ts → index.ts} +0 -1
  27. package/src/decorators/zod-validation.ts +64 -0
  28. package/src/defaults.ts +259 -0
  29. package/src/documents/base.ts +17 -0
  30. package/src/documents/email-token.ts +20 -0
  31. package/src/documents/{index.d.ts → index.ts} +0 -1
  32. package/src/documents/mnemonic.ts +20 -0
  33. package/src/documents/role.ts +19 -0
  34. package/src/documents/used-direct-login-token.ts +18 -0
  35. package/src/documents/user-role.ts +20 -0
  36. package/src/documents/user.ts +20 -0
  37. package/src/enumerations/base-model-name.ts +47 -0
  38. package/src/enumerations/{index.d.ts → index.ts} +0 -1
  39. package/src/enumerations/length-encoding-type.ts +16 -0
  40. package/src/enumerations/schema-collection.ts +39 -0
  41. package/src/enumerations/symmetric-error-type.ts +13 -0
  42. package/src/environment.ts +859 -0
  43. package/src/errors/express-validation.ts +38 -0
  44. package/src/errors/{index.d.ts → index.ts} +0 -1
  45. package/src/errors/invalid-backup-code-version.ts +30 -0
  46. package/src/errors/invalid-jwt-token.ts +24 -0
  47. package/src/errors/invalid-model.ts +24 -0
  48. package/src/errors/invalid-new-password.ts +33 -0
  49. package/src/errors/invalid-password.ts +28 -0
  50. package/src/errors/missing-validated-data.ts +55 -0
  51. package/src/errors/mnemonic-or-password-required.ts +26 -0
  52. package/src/errors/model-not-registered.ts +24 -0
  53. package/src/errors/mongoose-validation.ts +56 -0
  54. package/src/errors/symmetric.ts +53 -0
  55. package/src/errors/token-expired.ts +24 -0
  56. package/src/get-language.ts +64 -0
  57. package/src/get-timezone.ts +76 -0
  58. package/src/{index.d.ts → index.ts} +44 -2
  59. package/src/interfaces/api-error-response.ts +15 -0
  60. package/src/interfaces/api-express-validation-error-response.ts +17 -0
  61. package/src/interfaces/api-message-response.ts +12 -0
  62. package/src/interfaces/api-mongo-validation-error-response.ts +17 -0
  63. package/src/interfaces/api-responses/backup-codes-response.ts +15 -0
  64. package/src/interfaces/api-responses/challenge-response.ts +17 -0
  65. package/src/interfaces/api-responses/code-count-response.ts +12 -0
  66. package/src/interfaces/api-responses/{index.d.ts → index.ts} +0 -1
  67. package/src/interfaces/api-responses/login-response.ts +18 -0
  68. package/src/interfaces/api-responses/mnemonic-response.ts +15 -0
  69. package/src/interfaces/api-responses/registration-response.ts +17 -0
  70. package/src/interfaces/api-responses/request-user-response.ts +16 -0
  71. package/src/interfaces/api-responses/user-settings-response.ts +19 -0
  72. package/src/interfaces/application.ts +40 -0
  73. package/src/interfaces/backend-objects/email-token.ts +18 -0
  74. package/src/interfaces/backend-objects/{index.d.ts → index.ts} +0 -1
  75. package/src/interfaces/backend-objects/request-user.ts +19 -0
  76. package/src/interfaces/backend-objects/role.ts +18 -0
  77. package/src/interfaces/backend-objects/user.ts +18 -0
  78. package/src/interfaces/checksum-config.ts +15 -0
  79. package/src/interfaces/checksum-consts.ts +23 -0
  80. package/src/interfaces/constants.ts +114 -0
  81. package/src/interfaces/controller-config.ts +54 -0
  82. package/src/interfaces/create-user-basics.ts +24 -0
  83. package/src/interfaces/csp-config.ts +32 -0
  84. package/src/interfaces/csp-definition.ts +71 -0
  85. package/src/interfaces/db-init-result.ts +17 -0
  86. package/src/interfaces/deep-partial.ts +14 -0
  87. package/src/interfaces/discriminator-collections.ts +21 -0
  88. package/src/interfaces/email-service.ts +26 -0
  89. package/src/interfaces/environment-mongo.ts +86 -0
  90. package/src/interfaces/environment.ts +191 -0
  91. package/src/interfaces/failable-result.ts +20 -0
  92. package/src/interfaces/fec-consts.ts +14 -0
  93. package/src/interfaces/flexible-csp.ts +35 -0
  94. package/src/interfaces/handleable-error-options.ts +19 -0
  95. package/src/interfaces/{index.d.ts → index.ts} +0 -1
  96. package/src/interfaces/jwt-consts.ts +33 -0
  97. package/src/interfaces/jwt-sign-response.ts +31 -0
  98. package/src/interfaces/models/email-token.ts +13 -0
  99. package/src/interfaces/models/{index.d.ts → index.ts} +0 -1
  100. package/src/interfaces/models/mnemonic.ts +14 -0
  101. package/src/interfaces/models/role.ts +13 -0
  102. package/src/interfaces/models/token-role.ts +23 -0
  103. package/src/interfaces/models/used-direct-login-token.ts +21 -0
  104. package/src/interfaces/models/user-role.ts +23 -0
  105. package/src/interfaces/models/user.ts +30 -0
  106. package/src/interfaces/mongo-errors.ts +14 -0
  107. package/src/interfaces/request-user.ts +80 -0
  108. package/src/interfaces/required-string-keys.ts +33 -0
  109. package/src/interfaces/schema.ts +43 -0
  110. package/src/interfaces/server-init-result.ts +48 -0
  111. package/src/interfaces/status-code-response.ts +20 -0
  112. package/src/interfaces/symmetric-encryption-results.d.ts.map +1 -1
  113. package/src/interfaces/symmetric-encryption-results.js.map +1 -1
  114. package/src/interfaces/symmetric-encryption-results.ts +15 -0
  115. package/src/interfaces/test-environment.ts +23 -0
  116. package/src/interfaces/token-response.ts +16 -0
  117. package/src/middleware-utils.ts +138 -0
  118. package/src/middlewares/authenticate-crypto.ts +237 -0
  119. package/src/middlewares/authenticate-token.ts +165 -0
  120. package/src/middlewares/cleanup-crypto.ts +47 -0
  121. package/src/middlewares/{index.d.ts → index.ts} +0 -1
  122. package/src/middlewares/set-global-context-language.ts +38 -0
  123. package/src/model-registry.ts +142 -0
  124. package/src/models/email-token.ts +49 -0
  125. package/src/models/{index.d.ts → index.ts} +0 -1
  126. package/src/models/mnemonic.ts +42 -0
  127. package/src/models/role.ts +38 -0
  128. package/src/models/used-direct-login-token.ts +49 -0
  129. package/src/models/user-role.ts +40 -0
  130. package/src/models/user.ts +42 -0
  131. package/src/pipeline/{index.d.ts → index.ts} +0 -1
  132. package/src/pipeline/pipeline-builder.ts +27 -0
  133. package/src/plugins/{index.d.ts → index.ts} +0 -1
  134. package/src/plugins/plugin-interface.ts +19 -0
  135. package/src/plugins/plugin-manager.ts +53 -0
  136. package/src/registry/email-service-registry.ts +76 -0
  137. package/src/registry/{index.d.ts → index.ts} +0 -1
  138. package/src/responses/{index.d.ts → index.ts} +0 -1
  139. package/src/responses/response-builder.ts +166 -0
  140. package/src/routers/api.ts +233 -0
  141. package/src/routers/app.ts +395 -0
  142. package/src/routers/base.ts +34 -0
  143. package/src/routers/{index.d.ts → index.ts} +0 -1
  144. package/src/routers/router-config.ts +34 -0
  145. package/src/routing/index.ts +1 -0
  146. package/src/routing/route-builder.ts +214 -0
  147. package/src/schemas/email-token.ts +112 -0
  148. package/src/schemas/{index.d.ts → index.ts} +0 -1
  149. package/src/schemas/mnemonic.ts +48 -0
  150. package/src/schemas/role.ts +153 -0
  151. package/src/schemas/schema.ts +185 -0
  152. package/src/schemas/used-direct-login-token.ts +58 -0
  153. package/src/schemas/user-role.ts +93 -0
  154. package/src/schemas/user.ts +244 -0
  155. package/src/services/backup-code.ts +327 -0
  156. package/src/services/base.ts +46 -0
  157. package/src/services/checksum.ts +189 -0
  158. package/src/services/database-initialization.ts +1653 -0
  159. package/src/services/db-init-cache.ts +28 -0
  160. package/src/services/direct-login-token.ts +83 -0
  161. package/src/services/dummy-email-service.ts +43 -0
  162. package/src/services/fec-usage-example.ts +123 -0
  163. package/src/services/fec.ts +399 -0
  164. package/src/services/{index.d.ts → index.ts} +0 -2
  165. package/src/services/jwt.ts +146 -0
  166. package/src/services/key-wrapping.ts +528 -0
  167. package/src/services/mnemonic.ts +174 -0
  168. package/src/services/request-user.ts +127 -0
  169. package/src/services/role.ts +417 -0
  170. package/src/services/symmetric.ts +164 -0
  171. package/src/services/system-user.ts +87 -0
  172. package/src/services/user.ts +2324 -0
  173. package/src/services/xor.ts +39 -0
  174. package/src/testing.ts +9 -0
  175. package/src/transactions/{index.d.ts → index.ts} +0 -1
  176. package/src/transactions/transaction-manager.ts +63 -0
  177. package/src/types/app-config.ts +36 -0
  178. package/src/types/controller-config.ts +28 -0
  179. package/src/types/{environment-variables.d.ts → environment-variables.ts} +32 -5
  180. package/src/types/{index.d.ts → index.ts} +0 -1
  181. package/src/types/{mongoose-helpers.d.ts → mongoose-helpers.ts} +8 -2
  182. package/src/types/mongoose-override.d.ts +1 -0
  183. package/src/types/mongoose.d.ts +1 -0
  184. package/src/types.ts +189 -0
  185. package/src/utils.ts +1116 -0
  186. package/src/validation/{index.d.ts → index.ts} +0 -1
  187. package/src/validation/validation-builder.ts +155 -0
  188. package/src/__tests__/fixtures/index.d.ts.map +0 -1
  189. package/src/__tests__/fixtures/index.js +0 -5
  190. package/src/__tests__/fixtures/index.js.map +0 -1
  191. package/src/__tests__/fixtures/model-mocks.mock.d.ts +0 -12
  192. package/src/__tests__/fixtures/model-mocks.mock.d.ts.map +0 -1
  193. package/src/__tests__/fixtures/model-mocks.mock.js +0 -102
  194. package/src/__tests__/fixtures/model-mocks.mock.js.map +0 -1
  195. package/src/__tests__/helpers/application.mock.d.ts +0 -8
  196. package/src/__tests__/helpers/application.mock.d.ts.map +0 -1
  197. package/src/__tests__/helpers/application.mock.js +0 -77
  198. package/src/__tests__/helpers/application.mock.js.map +0 -1
  199. package/src/__tests__/helpers/index.d.ts.map +0 -1
  200. package/src/__tests__/helpers/index.js +0 -7
  201. package/src/__tests__/helpers/index.js.map +0 -1
  202. package/src/__tests__/helpers/setup-test-env.d.ts +0 -12
  203. package/src/__tests__/helpers/setup-test-env.d.ts.map +0 -1
  204. package/src/__tests__/helpers/setup-test-env.js +0 -121
  205. package/src/__tests__/helpers/setup-test-env.js.map +0 -1
  206. package/src/__tests__/index.d.ts.map +0 -1
  207. package/src/__tests__/index.js +0 -6
  208. package/src/__tests__/index.js.map +0 -1
  209. package/src/application-base.d.ts +0 -123
  210. package/src/application-base.d.ts.map +0 -1
  211. package/src/application-base.js +0 -359
  212. package/src/application-base.js.map +0 -1
  213. package/src/application-concrete.d.ts +0 -13
  214. package/src/application-concrete.d.ts.map +0 -1
  215. package/src/application-concrete.js +0 -21
  216. package/src/application-concrete.js.map +0 -1
  217. package/src/application.d.ts +0 -29
  218. package/src/application.d.ts.map +0 -1
  219. package/src/application.js +0 -167
  220. package/src/application.js.map +0 -1
  221. package/src/backup-code.d.ts +0 -67
  222. package/src/backup-code.d.ts.map +0 -1
  223. package/src/backup-code.js +0 -238
  224. package/src/backup-code.js.map +0 -1
  225. package/src/builders/application-builder.d.ts +0 -35
  226. package/src/builders/application-builder.d.ts.map +0 -1
  227. package/src/builders/application-builder.js +0 -64
  228. package/src/builders/application-builder.js.map +0 -1
  229. package/src/builders/index.d.ts.map +0 -1
  230. package/src/builders/index.js +0 -5
  231. package/src/builders/index.js.map +0 -1
  232. package/src/constants.d.ts +0 -16
  233. package/src/constants.d.ts.map +0 -1
  234. package/src/constants.js +0 -58
  235. package/src/constants.js.map +0 -1
  236. package/src/container/index.d.ts.map +0 -1
  237. package/src/container/index.js +0 -6
  238. package/src/container/index.js.map +0 -1
  239. package/src/container/service-container.d.ts +0 -11
  240. package/src/container/service-container.d.ts.map +0 -1
  241. package/src/container/service-container.js +0 -38
  242. package/src/container/service-container.js.map +0 -1
  243. package/src/container/service-definitions.d.ts +0 -11
  244. package/src/container/service-definitions.d.ts.map +0 -1
  245. package/src/container/service-definitions.js +0 -13
  246. package/src/container/service-definitions.js.map +0 -1
  247. package/src/controllers/base.d.ts +0 -67
  248. package/src/controllers/base.d.ts.map +0 -1
  249. package/src/controllers/base.js +0 -305
  250. package/src/controllers/base.js.map +0 -1
  251. package/src/controllers/index.d.ts.map +0 -1
  252. package/src/controllers/index.js +0 -6
  253. package/src/controllers/index.js.map +0 -1
  254. package/src/controllers/user.d.ts +0 -49
  255. package/src/controllers/user.d.ts.map +0 -1
  256. package/src/controllers/user.js +0 -919
  257. package/src/controllers/user.js.map +0 -1
  258. package/src/database/database-initializer.d.ts +0 -7
  259. package/src/database/database-initializer.d.ts.map +0 -1
  260. package/src/database/database-initializer.js +0 -3
  261. package/src/database/database-initializer.js.map +0 -1
  262. package/src/database/index.d.ts.map +0 -1
  263. package/src/database/index.js +0 -5
  264. package/src/database/index.js.map +0 -1
  265. package/src/decorators/base-controller.d.ts +0 -11
  266. package/src/decorators/base-controller.d.ts.map +0 -1
  267. package/src/decorators/base-controller.js +0 -60
  268. package/src/decorators/base-controller.js.map +0 -1
  269. package/src/decorators/controller.d.ts +0 -38
  270. package/src/decorators/controller.d.ts.map +0 -1
  271. package/src/decorators/controller.js +0 -68
  272. package/src/decorators/controller.js.map +0 -1
  273. package/src/decorators/index.d.ts.map +0 -1
  274. package/src/decorators/index.js +0 -7
  275. package/src/decorators/index.js.map +0 -1
  276. package/src/decorators/zod-validation.d.ts +0 -5
  277. package/src/decorators/zod-validation.d.ts.map +0 -1
  278. package/src/decorators/zod-validation.js +0 -48
  279. package/src/decorators/zod-validation.js.map +0 -1
  280. package/src/defaults.d.ts +0 -7
  281. package/src/defaults.d.ts.map +0 -1
  282. package/src/defaults.js +0 -205
  283. package/src/defaults.js.map +0 -1
  284. package/src/documents/base.d.ts +0 -4
  285. package/src/documents/base.d.ts.map +0 -1
  286. package/src/documents/base.js +0 -3
  287. package/src/documents/base.js.map +0 -1
  288. package/src/documents/email-token.d.ts +0 -8
  289. package/src/documents/email-token.d.ts.map +0 -1
  290. package/src/documents/email-token.js +0 -3
  291. package/src/documents/email-token.js.map +0 -1
  292. package/src/documents/index.d.ts.map +0 -1
  293. package/src/documents/index.js +0 -3
  294. package/src/documents/index.js.map +0 -1
  295. package/src/documents/mnemonic.d.ts +0 -8
  296. package/src/documents/mnemonic.d.ts.map +0 -1
  297. package/src/documents/mnemonic.js +0 -3
  298. package/src/documents/mnemonic.js.map +0 -1
  299. package/src/documents/role.d.ts +0 -8
  300. package/src/documents/role.d.ts.map +0 -1
  301. package/src/documents/role.js +0 -3
  302. package/src/documents/role.js.map +0 -1
  303. package/src/documents/used-direct-login-token.d.ts +0 -5
  304. package/src/documents/used-direct-login-token.d.ts.map +0 -1
  305. package/src/documents/used-direct-login-token.js +0 -3
  306. package/src/documents/used-direct-login-token.js.map +0 -1
  307. package/src/documents/user-role.d.ts +0 -8
  308. package/src/documents/user-role.d.ts.map +0 -1
  309. package/src/documents/user-role.js +0 -3
  310. package/src/documents/user-role.js.map +0 -1
  311. package/src/documents/user.d.ts +0 -8
  312. package/src/documents/user.d.ts.map +0 -1
  313. package/src/documents/user.js +0 -3
  314. package/src/documents/user.js.map +0 -1
  315. package/src/enumerations/base-model-name.d.ts +0 -38
  316. package/src/enumerations/base-model-name.d.ts.map +0 -1
  317. package/src/enumerations/base-model-name.js +0 -34
  318. package/src/enumerations/base-model-name.js.map +0 -1
  319. package/src/enumerations/index.d.ts.map +0 -1
  320. package/src/enumerations/index.js +0 -8
  321. package/src/enumerations/index.js.map +0 -1
  322. package/src/enumerations/length-encoding-type.d.ts +0 -7
  323. package/src/enumerations/length-encoding-type.d.ts.map +0 -1
  324. package/src/enumerations/length-encoding-type.js +0 -11
  325. package/src/enumerations/length-encoding-type.js.map +0 -1
  326. package/src/enumerations/schema-collection.d.ts +0 -34
  327. package/src/enumerations/schema-collection.d.ts.map +0 -1
  328. package/src/enumerations/schema-collection.js +0 -38
  329. package/src/enumerations/schema-collection.js.map +0 -1
  330. package/src/enumerations/symmetric-error-type.d.ts +0 -5
  331. package/src/enumerations/symmetric-error-type.d.ts.map +0 -1
  332. package/src/enumerations/symmetric-error-type.js +0 -9
  333. package/src/enumerations/symmetric-error-type.js.map +0 -1
  334. package/src/environment.d.ts +0 -189
  335. package/src/environment.d.ts.map +0 -1
  336. package/src/environment.js +0 -641
  337. package/src/environment.js.map +0 -1
  338. package/src/errors/express-validation.d.ts +0 -9
  339. package/src/errors/express-validation.d.ts.map +0 -1
  340. package/src/errors/express-validation.js +0 -18
  341. package/src/errors/express-validation.js.map +0 -1
  342. package/src/errors/index.d.ts.map +0 -1
  343. package/src/errors/index.js +0 -16
  344. package/src/errors/index.js.map +0 -1
  345. package/src/errors/invalid-backup-code-version.d.ts +0 -6
  346. package/src/errors/invalid-backup-code-version.d.ts.map +0 -1
  347. package/src/errors/invalid-backup-code-version.js +0 -16
  348. package/src/errors/invalid-backup-code-version.js.map +0 -1
  349. package/src/errors/invalid-jwt-token.d.ts +0 -5
  350. package/src/errors/invalid-jwt-token.d.ts.map +0 -1
  351. package/src/errors/invalid-jwt-token.js +0 -12
  352. package/src/errors/invalid-jwt-token.js.map +0 -1
  353. package/src/errors/invalid-model.d.ts +0 -6
  354. package/src/errors/invalid-model.d.ts.map +0 -1
  355. package/src/errors/invalid-model.js +0 -14
  356. package/src/errors/invalid-model.js.map +0 -1
  357. package/src/errors/invalid-new-password.d.ts +0 -5
  358. package/src/errors/invalid-new-password.d.ts.map +0 -1
  359. package/src/errors/invalid-new-password.js +0 -14
  360. package/src/errors/invalid-new-password.js.map +0 -1
  361. package/src/errors/invalid-password.d.ts +0 -5
  362. package/src/errors/invalid-password.d.ts.map +0 -1
  363. package/src/errors/invalid-password.js +0 -14
  364. package/src/errors/invalid-password.js.map +0 -1
  365. package/src/errors/missing-validated-data.d.ts +0 -7
  366. package/src/errors/missing-validated-data.d.ts.map +0 -1
  367. package/src/errors/missing-validated-data.js +0 -36
  368. package/src/errors/missing-validated-data.js.map +0 -1
  369. package/src/errors/mnemonic-or-password-required.d.ts +0 -5
  370. package/src/errors/mnemonic-or-password-required.d.ts.map +0 -1
  371. package/src/errors/mnemonic-or-password-required.js +0 -14
  372. package/src/errors/mnemonic-or-password-required.js.map +0 -1
  373. package/src/errors/model-not-registered.d.ts +0 -6
  374. package/src/errors/model-not-registered.d.ts.map +0 -1
  375. package/src/errors/model-not-registered.js +0 -14
  376. package/src/errors/model-not-registered.js.map +0 -1
  377. package/src/errors/mongoose-validation.d.ts +0 -12
  378. package/src/errors/mongoose-validation.d.ts.map +0 -1
  379. package/src/errors/mongoose-validation.js +0 -17
  380. package/src/errors/mongoose-validation.js.map +0 -1
  381. package/src/errors/symmetric.d.ts +0 -8
  382. package/src/errors/symmetric.d.ts.map +0 -1
  383. package/src/errors/symmetric.js +0 -22
  384. package/src/errors/symmetric.js.map +0 -1
  385. package/src/errors/token-expired.d.ts +0 -5
  386. package/src/errors/token-expired.d.ts.map +0 -1
  387. package/src/errors/token-expired.js +0 -12
  388. package/src/errors/token-expired.js.map +0 -1
  389. package/src/get-language.d.ts +0 -2
  390. package/src/get-language.d.ts.map +0 -1
  391. package/src/get-language.js +0 -30
  392. package/src/get-language.js.map +0 -1
  393. package/src/get-timezone.d.ts +0 -2
  394. package/src/get-timezone.d.ts.map +0 -1
  395. package/src/get-timezone.js +0 -39
  396. package/src/get-timezone.js.map +0 -1
  397. package/src/index.d.ts.map +0 -1
  398. package/src/index.js +0 -80
  399. package/src/index.js.map +0 -1
  400. package/src/interfaces/api-error-response.d.ts +0 -5
  401. package/src/interfaces/api-error-response.d.ts.map +0 -1
  402. package/src/interfaces/api-error-response.js +0 -3
  403. package/src/interfaces/api-error-response.js.map +0 -1
  404. package/src/interfaces/api-express-validation-error-response.d.ts +0 -7
  405. package/src/interfaces/api-express-validation-error-response.d.ts.map +0 -1
  406. package/src/interfaces/api-express-validation-error-response.js +0 -3
  407. package/src/interfaces/api-express-validation-error-response.js.map +0 -1
  408. package/src/interfaces/api-message-response.d.ts +0 -4
  409. package/src/interfaces/api-message-response.d.ts.map +0 -1
  410. package/src/interfaces/api-message-response.js +0 -3
  411. package/src/interfaces/api-message-response.js.map +0 -1
  412. package/src/interfaces/api-mongo-validation-error-response.d.ts +0 -6
  413. package/src/interfaces/api-mongo-validation-error-response.d.ts.map +0 -1
  414. package/src/interfaces/api-mongo-validation-error-response.js +0 -3
  415. package/src/interfaces/api-mongo-validation-error-response.js.map +0 -1
  416. package/src/interfaces/api-responses/backup-codes-response.d.ts +0 -5
  417. package/src/interfaces/api-responses/backup-codes-response.d.ts.map +0 -1
  418. package/src/interfaces/api-responses/backup-codes-response.js +0 -3
  419. package/src/interfaces/api-responses/backup-codes-response.js.map +0 -1
  420. package/src/interfaces/api-responses/challenge-response.d.ts +0 -6
  421. package/src/interfaces/api-responses/challenge-response.d.ts.map +0 -1
  422. package/src/interfaces/api-responses/challenge-response.js +0 -3
  423. package/src/interfaces/api-responses/challenge-response.js.map +0 -1
  424. package/src/interfaces/api-responses/code-count-response.d.ts +0 -5
  425. package/src/interfaces/api-responses/code-count-response.d.ts.map +0 -1
  426. package/src/interfaces/api-responses/code-count-response.js +0 -3
  427. package/src/interfaces/api-responses/code-count-response.js.map +0 -1
  428. package/src/interfaces/api-responses/index.d.ts.map +0 -1
  429. package/src/interfaces/api-responses/index.js +0 -12
  430. package/src/interfaces/api-responses/index.js.map +0 -1
  431. package/src/interfaces/api-responses/login-response.d.ts +0 -8
  432. package/src/interfaces/api-responses/login-response.d.ts.map +0 -1
  433. package/src/interfaces/api-responses/login-response.js +0 -3
  434. package/src/interfaces/api-responses/login-response.js.map +0 -1
  435. package/src/interfaces/api-responses/mnemonic-response.d.ts +0 -5
  436. package/src/interfaces/api-responses/mnemonic-response.d.ts.map +0 -1
  437. package/src/interfaces/api-responses/mnemonic-response.js +0 -3
  438. package/src/interfaces/api-responses/mnemonic-response.js.map +0 -1
  439. package/src/interfaces/api-responses/registration-response.d.ts +0 -6
  440. package/src/interfaces/api-responses/registration-response.d.ts.map +0 -1
  441. package/src/interfaces/api-responses/registration-response.js +0 -3
  442. package/src/interfaces/api-responses/registration-response.js.map +0 -1
  443. package/src/interfaces/api-responses/request-user-response.d.ts +0 -6
  444. package/src/interfaces/api-responses/request-user-response.d.ts.map +0 -1
  445. package/src/interfaces/api-responses/request-user-response.js +0 -3
  446. package/src/interfaces/api-responses/request-user-response.js.map +0 -1
  447. package/src/interfaces/api-responses/user-settings-response.d.ts +0 -12
  448. package/src/interfaces/api-responses/user-settings-response.d.ts.map +0 -1
  449. package/src/interfaces/api-responses/user-settings-response.js +0 -3
  450. package/src/interfaces/api-responses/user-settings-response.js.map +0 -1
  451. package/src/interfaces/application.d.ts +0 -17
  452. package/src/interfaces/application.d.ts.map +0 -1
  453. package/src/interfaces/application.js +0 -3
  454. package/src/interfaces/application.js.map +0 -1
  455. package/src/interfaces/backend-objects/email-token.d.ts +0 -4
  456. package/src/interfaces/backend-objects/email-token.d.ts.map +0 -1
  457. package/src/interfaces/backend-objects/email-token.js +0 -3
  458. package/src/interfaces/backend-objects/email-token.js.map +0 -1
  459. package/src/interfaces/backend-objects/index.d.ts.map +0 -1
  460. package/src/interfaces/backend-objects/index.js +0 -8
  461. package/src/interfaces/backend-objects/index.js.map +0 -1
  462. package/src/interfaces/backend-objects/request-user.d.ts +0 -5
  463. package/src/interfaces/backend-objects/request-user.d.ts.map +0 -1
  464. package/src/interfaces/backend-objects/request-user.js +0 -3
  465. package/src/interfaces/backend-objects/request-user.js.map +0 -1
  466. package/src/interfaces/backend-objects/role.d.ts +0 -4
  467. package/src/interfaces/backend-objects/role.d.ts.map +0 -1
  468. package/src/interfaces/backend-objects/role.js +0 -3
  469. package/src/interfaces/backend-objects/role.js.map +0 -1
  470. package/src/interfaces/backend-objects/user.d.ts +0 -4
  471. package/src/interfaces/backend-objects/user.d.ts.map +0 -1
  472. package/src/interfaces/backend-objects/user.js +0 -3
  473. package/src/interfaces/backend-objects/user.js.map +0 -1
  474. package/src/interfaces/checksum-config.d.ts +0 -5
  475. package/src/interfaces/checksum-config.d.ts.map +0 -1
  476. package/src/interfaces/checksum-config.js +0 -3
  477. package/src/interfaces/checksum-config.js.map +0 -1
  478. package/src/interfaces/checksum-consts.d.ts +0 -11
  479. package/src/interfaces/checksum-consts.d.ts.map +0 -1
  480. package/src/interfaces/checksum-consts.js +0 -3
  481. package/src/interfaces/checksum-consts.js.map +0 -1
  482. package/src/interfaces/constants.d.ts +0 -102
  483. package/src/interfaces/constants.d.ts.map +0 -1
  484. package/src/interfaces/constants.js +0 -3
  485. package/src/interfaces/constants.js.map +0 -1
  486. package/src/interfaces/controller-config.d.ts +0 -21
  487. package/src/interfaces/controller-config.d.ts.map +0 -1
  488. package/src/interfaces/controller-config.js +0 -3
  489. package/src/interfaces/controller-config.js.map +0 -1
  490. package/src/interfaces/create-user-basics.d.ts +0 -18
  491. package/src/interfaces/create-user-basics.d.ts.map +0 -1
  492. package/src/interfaces/create-user-basics.js +0 -3
  493. package/src/interfaces/create-user-basics.js.map +0 -1
  494. package/src/interfaces/csp-config.d.ts +0 -7
  495. package/src/interfaces/csp-config.d.ts.map +0 -1
  496. package/src/interfaces/csp-config.js +0 -13
  497. package/src/interfaces/csp-config.js.map +0 -1
  498. package/src/interfaces/csp-definition.d.ts +0 -13
  499. package/src/interfaces/csp-definition.d.ts.map +0 -1
  500. package/src/interfaces/csp-definition.js +0 -22
  501. package/src/interfaces/csp-definition.js.map +0 -1
  502. package/src/interfaces/db-init-result.d.ts +0 -5
  503. package/src/interfaces/db-init-result.d.ts.map +0 -1
  504. package/src/interfaces/db-init-result.js +0 -3
  505. package/src/interfaces/db-init-result.js.map +0 -1
  506. package/src/interfaces/deep-partial.d.ts +0 -4
  507. package/src/interfaces/deep-partial.d.ts.map +0 -1
  508. package/src/interfaces/deep-partial.js +0 -3
  509. package/src/interfaces/deep-partial.js.map +0 -1
  510. package/src/interfaces/discriminator-collections.d.ts +0 -7
  511. package/src/interfaces/discriminator-collections.d.ts.map +0 -1
  512. package/src/interfaces/discriminator-collections.js +0 -3
  513. package/src/interfaces/discriminator-collections.js.map +0 -1
  514. package/src/interfaces/email-service.d.ts +0 -4
  515. package/src/interfaces/email-service.d.ts.map +0 -1
  516. package/src/interfaces/email-service.js +0 -3
  517. package/src/interfaces/email-service.js.map +0 -1
  518. package/src/interfaces/environment-mongo.d.ts +0 -76
  519. package/src/interfaces/environment-mongo.d.ts.map +0 -1
  520. package/src/interfaces/environment-mongo.js +0 -3
  521. package/src/interfaces/environment-mongo.js.map +0 -1
  522. package/src/interfaces/environment.d.ts +0 -180
  523. package/src/interfaces/environment.d.ts.map +0 -1
  524. package/src/interfaces/environment.js +0 -3
  525. package/src/interfaces/environment.js.map +0 -1
  526. package/src/interfaces/failable-result.d.ts +0 -7
  527. package/src/interfaces/failable-result.d.ts.map +0 -1
  528. package/src/interfaces/failable-result.js +0 -3
  529. package/src/interfaces/failable-result.js.map +0 -1
  530. package/src/interfaces/fec-consts.d.ts +0 -5
  531. package/src/interfaces/fec-consts.d.ts.map +0 -1
  532. package/src/interfaces/fec-consts.js +0 -3
  533. package/src/interfaces/fec-consts.js.map +0 -1
  534. package/src/interfaces/flexible-csp.d.ts +0 -8
  535. package/src/interfaces/flexible-csp.d.ts.map +0 -1
  536. package/src/interfaces/flexible-csp.js +0 -14
  537. package/src/interfaces/flexible-csp.js.map +0 -1
  538. package/src/interfaces/handleable-error-options.d.ts +0 -7
  539. package/src/interfaces/handleable-error-options.d.ts.map +0 -1
  540. package/src/interfaces/handleable-error-options.js +0 -3
  541. package/src/interfaces/handleable-error-options.js.map +0 -1
  542. package/src/interfaces/index.d.ts.map +0 -1
  543. package/src/interfaces/index.js +0 -38
  544. package/src/interfaces/index.js.map +0 -1
  545. package/src/interfaces/jwt-consts.d.ts +0 -11
  546. package/src/interfaces/jwt-consts.d.ts.map +0 -1
  547. package/src/interfaces/jwt-consts.js +0 -3
  548. package/src/interfaces/jwt-consts.js.map +0 -1
  549. package/src/interfaces/jwt-sign-response.d.ts +0 -11
  550. package/src/interfaces/jwt-sign-response.d.ts.map +0 -1
  551. package/src/interfaces/jwt-sign-response.js +0 -3
  552. package/src/interfaces/jwt-sign-response.js.map +0 -1
  553. package/src/interfaces/models/email-token.d.ts +0 -6
  554. package/src/interfaces/models/email-token.d.ts.map +0 -1
  555. package/src/interfaces/models/email-token.js +0 -3
  556. package/src/interfaces/models/email-token.js.map +0 -1
  557. package/src/interfaces/models/index.d.ts.map +0 -1
  558. package/src/interfaces/models/index.js +0 -11
  559. package/src/interfaces/models/index.js.map +0 -1
  560. package/src/interfaces/models/mnemonic.d.ts +0 -6
  561. package/src/interfaces/models/mnemonic.d.ts.map +0 -1
  562. package/src/interfaces/models/mnemonic.js +0 -3
  563. package/src/interfaces/models/mnemonic.js.map +0 -1
  564. package/src/interfaces/models/role.d.ts +0 -6
  565. package/src/interfaces/models/role.d.ts.map +0 -1
  566. package/src/interfaces/models/role.js +0 -3
  567. package/src/interfaces/models/role.js.map +0 -1
  568. package/src/interfaces/models/token-role.d.ts +0 -11
  569. package/src/interfaces/models/token-role.d.ts.map +0 -1
  570. package/src/interfaces/models/token-role.js +0 -3
  571. package/src/interfaces/models/token-role.js.map +0 -1
  572. package/src/interfaces/models/used-direct-login-token.d.ts +0 -11
  573. package/src/interfaces/models/used-direct-login-token.d.ts.map +0 -1
  574. package/src/interfaces/models/used-direct-login-token.js +0 -3
  575. package/src/interfaces/models/used-direct-login-token.js.map +0 -1
  576. package/src/interfaces/models/user-role.d.ts +0 -11
  577. package/src/interfaces/models/user-role.d.ts.map +0 -1
  578. package/src/interfaces/models/user-role.js +0 -3
  579. package/src/interfaces/models/user-role.js.map +0 -1
  580. package/src/interfaces/models/user.d.ts +0 -11
  581. package/src/interfaces/models/user.d.ts.map +0 -1
  582. package/src/interfaces/models/user.js +0 -3
  583. package/src/interfaces/models/user.js.map +0 -1
  584. package/src/interfaces/mongo-errors.d.ts +0 -5
  585. package/src/interfaces/mongo-errors.d.ts.map +0 -1
  586. package/src/interfaces/mongo-errors.js +0 -3
  587. package/src/interfaces/mongo-errors.js.map +0 -1
  588. package/src/interfaces/request-user.d.ts +0 -58
  589. package/src/interfaces/request-user.d.ts.map +0 -1
  590. package/src/interfaces/request-user.js +0 -3
  591. package/src/interfaces/request-user.js.map +0 -1
  592. package/src/interfaces/required-string-keys.d.ts +0 -22
  593. package/src/interfaces/required-string-keys.d.ts.map +0 -1
  594. package/src/interfaces/required-string-keys.js +0 -3
  595. package/src/interfaces/required-string-keys.js.map +0 -1
  596. package/src/interfaces/schema.d.ts +0 -29
  597. package/src/interfaces/schema.d.ts.map +0 -1
  598. package/src/interfaces/schema.js +0 -3
  599. package/src/interfaces/schema.js.map +0 -1
  600. package/src/interfaces/server-init-result.d.ts +0 -35
  601. package/src/interfaces/server-init-result.d.ts.map +0 -1
  602. package/src/interfaces/server-init-result.js +0 -3
  603. package/src/interfaces/server-init-result.js.map +0 -1
  604. package/src/interfaces/status-code-response.d.ts +0 -7
  605. package/src/interfaces/status-code-response.d.ts.map +0 -1
  606. package/src/interfaces/status-code-response.js +0 -3
  607. package/src/interfaces/status-code-response.js.map +0 -1
  608. package/src/interfaces/symmetric-encryption-results.d.ts +0 -5
  609. package/src/interfaces/test-environment.d.ts +0 -12
  610. package/src/interfaces/test-environment.d.ts.map +0 -1
  611. package/src/interfaces/test-environment.js +0 -3
  612. package/src/interfaces/test-environment.js.map +0 -1
  613. package/src/interfaces/token-response.d.ts +0 -5
  614. package/src/interfaces/token-response.d.ts.map +0 -1
  615. package/src/interfaces/token-response.js +0 -3
  616. package/src/interfaces/token-response.js.map +0 -1
  617. package/src/middleware-utils.d.ts +0 -8
  618. package/src/middleware-utils.d.ts.map +0 -1
  619. package/src/middleware-utils.js +0 -94
  620. package/src/middleware-utils.js.map +0 -1
  621. package/src/middlewares/authenticate-crypto.d.ts +0 -10
  622. package/src/middlewares/authenticate-crypto.d.ts.map +0 -1
  623. package/src/middlewares/authenticate-crypto.js +0 -126
  624. package/src/middlewares/authenticate-crypto.js.map +0 -1
  625. package/src/middlewares/authenticate-token.d.ts +0 -21
  626. package/src/middlewares/authenticate-token.d.ts.map +0 -1
  627. package/src/middlewares/authenticate-token.js +0 -104
  628. package/src/middlewares/authenticate-token.js.map +0 -1
  629. package/src/middlewares/cleanup-crypto.d.ts +0 -7
  630. package/src/middlewares/cleanup-crypto.d.ts.map +0 -1
  631. package/src/middlewares/cleanup-crypto.js +0 -32
  632. package/src/middlewares/cleanup-crypto.js.map +0 -1
  633. package/src/middlewares/index.d.ts.map +0 -1
  634. package/src/middlewares/index.js +0 -8
  635. package/src/middlewares/index.js.map +0 -1
  636. package/src/middlewares/set-global-context-language.d.ts +0 -3
  637. package/src/middlewares/set-global-context-language.d.ts.map +0 -1
  638. package/src/middlewares/set-global-context-language.js +0 -14
  639. package/src/middlewares/set-global-context-language.js.map +0 -1
  640. package/src/model-registry.d.ts +0 -23
  641. package/src/model-registry.d.ts.map +0 -1
  642. package/src/model-registry.js +0 -47
  643. package/src/model-registry.js.map +0 -1
  644. package/src/models/email-token.d.ts +0 -8
  645. package/src/models/email-token.d.ts.map +0 -1
  646. package/src/models/email-token.js +0 -11
  647. package/src/models/email-token.js.map +0 -1
  648. package/src/models/index.d.ts.map +0 -1
  649. package/src/models/index.js +0 -10
  650. package/src/models/index.js.map +0 -1
  651. package/src/models/mnemonic.d.ts +0 -8
  652. package/src/models/mnemonic.d.ts.map +0 -1
  653. package/src/models/mnemonic.js +0 -11
  654. package/src/models/mnemonic.js.map +0 -1
  655. package/src/models/role.d.ts +0 -8
  656. package/src/models/role.d.ts.map +0 -1
  657. package/src/models/role.js +0 -11
  658. package/src/models/role.js.map +0 -1
  659. package/src/models/used-direct-login-token.d.ts +0 -8
  660. package/src/models/used-direct-login-token.d.ts.map +0 -1
  661. package/src/models/used-direct-login-token.js +0 -11
  662. package/src/models/used-direct-login-token.js.map +0 -1
  663. package/src/models/user-role.d.ts +0 -7
  664. package/src/models/user-role.d.ts.map +0 -1
  665. package/src/models/user-role.js +0 -10
  666. package/src/models/user-role.js.map +0 -1
  667. package/src/models/user.d.ts +0 -8
  668. package/src/models/user.d.ts.map +0 -1
  669. package/src/models/user.js +0 -11
  670. package/src/models/user.js.map +0 -1
  671. package/src/pipeline/index.d.ts.map +0 -1
  672. package/src/pipeline/index.js +0 -5
  673. package/src/pipeline/index.js.map +0 -1
  674. package/src/pipeline/pipeline-builder.d.ts +0 -8
  675. package/src/pipeline/pipeline-builder.d.ts.map +0 -1
  676. package/src/pipeline/pipeline-builder.js +0 -18
  677. package/src/pipeline/pipeline-builder.js.map +0 -1
  678. package/src/plugins/index.d.ts.map +0 -1
  679. package/src/plugins/index.js +0 -6
  680. package/src/plugins/index.js.map +0 -1
  681. package/src/plugins/plugin-interface.d.ts +0 -9
  682. package/src/plugins/plugin-interface.d.ts.map +0 -1
  683. package/src/plugins/plugin-interface.js +0 -3
  684. package/src/plugins/plugin-interface.js.map +0 -1
  685. package/src/plugins/plugin-manager.d.ts +0 -13
  686. package/src/plugins/plugin-manager.d.ts.map +0 -1
  687. package/src/plugins/plugin-manager.js +0 -37
  688. package/src/plugins/plugin-manager.js.map +0 -1
  689. package/src/registry/email-service-registry.d.ts +0 -27
  690. package/src/registry/email-service-registry.d.ts.map +0 -1
  691. package/src/registry/email-service-registry.js +0 -42
  692. package/src/registry/email-service-registry.js.map +0 -1
  693. package/src/registry/index.d.ts.map +0 -1
  694. package/src/registry/index.js +0 -6
  695. package/src/registry/index.js.map +0 -1
  696. package/src/responses/index.d.ts.map +0 -1
  697. package/src/responses/index.js +0 -5
  698. package/src/responses/index.js.map +0 -1
  699. package/src/responses/response-builder.d.ts +0 -24
  700. package/src/responses/response-builder.d.ts.map +0 -1
  701. package/src/responses/response-builder.js +0 -63
  702. package/src/responses/response-builder.js.map +0 -1
  703. package/src/routers/api.d.ts +0 -28
  704. package/src/routers/api.d.ts.map +0 -1
  705. package/src/routers/api.js +0 -80
  706. package/src/routers/api.js.map +0 -1
  707. package/src/routers/app.d.ts +0 -33
  708. package/src/routers/app.d.ts.map +0 -1
  709. package/src/routers/app.js +0 -228
  710. package/src/routers/app.js.map +0 -1
  711. package/src/routers/base.d.ts +0 -9
  712. package/src/routers/base.d.ts.map +0 -1
  713. package/src/routers/base.js +0 -14
  714. package/src/routers/base.js.map +0 -1
  715. package/src/routers/index.d.ts.map +0 -1
  716. package/src/routers/index.js +0 -7
  717. package/src/routers/index.js.map +0 -1
  718. package/src/routers/router-config.d.ts +0 -18
  719. package/src/routers/router-config.d.ts.map +0 -1
  720. package/src/routers/router-config.js +0 -8
  721. package/src/routers/router-config.js.map +0 -1
  722. package/src/routing/index.d.ts +0 -2
  723. package/src/routing/index.d.ts.map +0 -1
  724. package/src/routing/index.js +0 -5
  725. package/src/routing/index.js.map +0 -1
  726. package/src/routing/route-builder.d.ts +0 -36
  727. package/src/routing/route-builder.d.ts.map +0 -1
  728. package/src/routing/route-builder.js +0 -86
  729. package/src/routing/route-builder.js.map +0 -1
  730. package/src/schemas/email-token.d.ts +0 -49
  731. package/src/schemas/email-token.d.ts.map +0 -1
  732. package/src/schemas/email-token.js +0 -55
  733. package/src/schemas/email-token.js.map +0 -1
  734. package/src/schemas/index.d.ts.map +0 -1
  735. package/src/schemas/index.js +0 -11
  736. package/src/schemas/index.js.map +0 -1
  737. package/src/schemas/mnemonic.d.ts +0 -27
  738. package/src/schemas/mnemonic.d.ts.map +0 -1
  739. package/src/schemas/mnemonic.js +0 -31
  740. package/src/schemas/mnemonic.js.map +0 -1
  741. package/src/schemas/role.d.ts +0 -42
  742. package/src/schemas/role.d.ts.map +0 -1
  743. package/src/schemas/role.js +0 -89
  744. package/src/schemas/role.js.map +0 -1
  745. package/src/schemas/schema.d.ts +0 -42
  746. package/src/schemas/schema.d.ts.map +0 -1
  747. package/src/schemas/schema.js +0 -70
  748. package/src/schemas/schema.js.map +0 -1
  749. package/src/schemas/used-direct-login-token.d.ts +0 -37
  750. package/src/schemas/used-direct-login-token.d.ts.map +0 -1
  751. package/src/schemas/used-direct-login-token.js +0 -24
  752. package/src/schemas/used-direct-login-token.js.map +0 -1
  753. package/src/schemas/user-role.d.ts +0 -39
  754. package/src/schemas/user-role.d.ts.map +0 -1
  755. package/src/schemas/user-role.js +0 -55
  756. package/src/schemas/user-role.js.map +0 -1
  757. package/src/schemas/user.d.ts +0 -24
  758. package/src/schemas/user.d.ts.map +0 -1
  759. package/src/schemas/user.js +0 -195
  760. package/src/schemas/user.js.map +0 -1
  761. package/src/services/backup-code.d.ts +0 -76
  762. package/src/services/backup-code.d.ts.map +0 -1
  763. package/src/services/backup-code.js +0 -185
  764. package/src/services/backup-code.js.map +0 -1
  765. package/src/services/base.d.ts +0 -11
  766. package/src/services/base.d.ts.map +0 -1
  767. package/src/services/base.js +0 -15
  768. package/src/services/base.js.map +0 -1
  769. package/src/services/checksum.d.ts +0 -69
  770. package/src/services/checksum.d.ts.map +0 -1
  771. package/src/services/checksum.js +0 -145
  772. package/src/services/checksum.js.map +0 -1
  773. package/src/services/crc.d.ts +0 -87
  774. package/src/services/crc.d.ts.map +0 -1
  775. package/src/services/crc.js +0 -198
  776. package/src/services/crc.js.map +0 -1
  777. package/src/services/database-initialization.d.ts +0 -111
  778. package/src/services/database-initialization.d.ts.map +0 -1
  779. package/src/services/database-initialization.js +0 -878
  780. package/src/services/database-initialization.js.map +0 -1
  781. package/src/services/db-init-cache.d.ts +0 -10
  782. package/src/services/db-init-cache.d.ts.map +0 -1
  783. package/src/services/db-init-cache.js +0 -3
  784. package/src/services/db-init-cache.js.map +0 -1
  785. package/src/services/direct-login-token.d.ts +0 -7
  786. package/src/services/direct-login-token.d.ts.map +0 -1
  787. package/src/services/direct-login-token.js +0 -41
  788. package/src/services/direct-login-token.js.map +0 -1
  789. package/src/services/dummy-email-service.d.ts +0 -11
  790. package/src/services/dummy-email-service.d.ts.map +0 -1
  791. package/src/services/dummy-email-service.js +0 -16
  792. package/src/services/dummy-email-service.js.map +0 -1
  793. package/src/services/fec-usage-example.d.ts +0 -38
  794. package/src/services/fec-usage-example.d.ts.map +0 -1
  795. package/src/services/fec-usage-example.js +0 -75
  796. package/src/services/fec-usage-example.js.map +0 -1
  797. package/src/services/fec.d.ts +0 -46
  798. package/src/services/fec.d.ts.map +0 -1
  799. package/src/services/fec.js +0 -214
  800. package/src/services/fec.js.map +0 -1
  801. package/src/services/index.d.ts.map +0 -1
  802. package/src/services/index.js +0 -23
  803. package/src/services/index.js.map +0 -1
  804. package/src/services/jwt.d.ts +0 -30
  805. package/src/services/jwt.d.ts.map +0 -1
  806. package/src/services/jwt.js +0 -90
  807. package/src/services/jwt.js.map +0 -1
  808. package/src/services/key-wrapping.d.ts +0 -61
  809. package/src/services/key-wrapping.d.ts.map +0 -1
  810. package/src/services/key-wrapping.js +0 -307
  811. package/src/services/key-wrapping.js.map +0 -1
  812. package/src/services/mnemonic.d.ts +0 -62
  813. package/src/services/mnemonic.d.ts.map +0 -1
  814. package/src/services/mnemonic.js +0 -114
  815. package/src/services/mnemonic.js.map +0 -1
  816. package/src/services/request-user.d.ts +0 -23
  817. package/src/services/request-user.d.ts.map +0 -1
  818. package/src/services/request-user.js +0 -68
  819. package/src/services/request-user.js.map +0 -1
  820. package/src/services/role.d.ts +0 -87
  821. package/src/services/role.d.ts.map +0 -1
  822. package/src/services/role.js +0 -279
  823. package/src/services/role.js.map +0 -1
  824. package/src/services/symmetric.d.ts +0 -42
  825. package/src/services/symmetric.d.ts.map +0 -1
  826. package/src/services/symmetric.js +0 -101
  827. package/src/services/symmetric.js.map +0 -1
  828. package/src/services/system-user.d.ts +0 -16
  829. package/src/services/system-user.d.ts.map +0 -1
  830. package/src/services/system-user.js +0 -46
  831. package/src/services/system-user.js.map +0 -1
  832. package/src/services/user.d.ts +0 -345
  833. package/src/services/user.d.ts.map +0 -1
  834. package/src/services/user.js +0 -1447
  835. package/src/services/user.js.map +0 -1
  836. package/src/services/xor.d.ts +0 -24
  837. package/src/services/xor.d.ts.map +0 -1
  838. package/src/services/xor.js +0 -37
  839. package/src/services/xor.js.map +0 -1
  840. package/src/testing.d.ts +0 -3
  841. package/src/testing.d.ts.map +0 -1
  842. package/src/testing.js +0 -7
  843. package/src/testing.js.map +0 -1
  844. package/src/transactions/index.d.ts.map +0 -1
  845. package/src/transactions/index.js +0 -5
  846. package/src/transactions/index.js.map +0 -1
  847. package/src/transactions/transaction-manager.d.ts +0 -12
  848. package/src/transactions/transaction-manager.d.ts.map +0 -1
  849. package/src/transactions/transaction-manager.js +0 -30
  850. package/src/transactions/transaction-manager.js.map +0 -1
  851. package/src/types/app-config.d.ts +0 -16
  852. package/src/types/app-config.d.ts.map +0 -1
  853. package/src/types/app-config.js +0 -3
  854. package/src/types/app-config.js.map +0 -1
  855. package/src/types/controller-config.d.ts +0 -14
  856. package/src/types/controller-config.d.ts.map +0 -1
  857. package/src/types/controller-config.js +0 -3
  858. package/src/types/controller-config.js.map +0 -1
  859. package/src/types/environment-variables.d.ts.map +0 -1
  860. package/src/types/environment-variables.js +0 -39
  861. package/src/types/environment-variables.js.map +0 -1
  862. package/src/types/index.d.ts.map +0 -1
  863. package/src/types/index.js +0 -6
  864. package/src/types/index.js.map +0 -1
  865. package/src/types/mongoose-helpers.d.ts.map +0 -1
  866. package/src/types/mongoose-helpers.js +0 -6
  867. package/src/types/mongoose-helpers.js.map +0 -1
  868. package/src/types.d.ts +0 -104
  869. package/src/types.d.ts.map +0 -1
  870. package/src/types.js +0 -14
  871. package/src/types.js.map +0 -1
  872. package/src/utils.d.ts +0 -211
  873. package/src/utils.d.ts.map +0 -1
  874. package/src/utils.js +0 -818
  875. package/src/utils.js.map +0 -1
  876. package/src/validation/index.d.ts.map +0 -1
  877. package/src/validation/index.js +0 -5
  878. package/src/validation/index.js.map +0 -1
  879. package/src/validation/validation-builder.d.ts +0 -32
  880. package/src/validation/validation-builder.d.ts.map +0 -1
  881. package/src/validation/validation-builder.js +0 -81
  882. package/src/validation/validation-builder.js.map +0 -1
package/src/utils.ts ADDED
@@ -0,0 +1,1116 @@
1
+ /**
2
+ * @fileoverview Utility functions for Express application including validation, transactions, error handling, and data encoding.
3
+ * Provides comprehensive helpers for API responses, MongoDB transactions, validation, and cryptographic operations.
4
+ * @module utils
5
+ */
6
+
7
+ import { I18nEngine } from '@digitaldefiance/i18n-lib';
8
+ import {
9
+ ClientSession,
10
+ Connection,
11
+ Types,
12
+ } from '@digitaldefiance/mongoose-types';
13
+ import { NextFunction, Request, Response } from 'express';
14
+ import { Result, ValidationError } from 'express-validator';
15
+ import { existsSync, readdirSync, writeSync } from 'fs';
16
+ import { resolve } from 'path';
17
+ import { z, ZodType } from 'zod';
18
+ import { ExpressValidationError } from './errors/express-validation';
19
+ import { MongooseValidationError } from './errors/mongoose-validation';
20
+ import { IApiErrorResponse, IApplication } from './interfaces';
21
+ import { IApiExpressValidationErrorResponse } from './interfaces/api-express-validation-error-response';
22
+ import { IApiMongoValidationErrorResponse } from './interfaces/api-mongo-validation-error-response';
23
+ import { IMongoErrors } from './interfaces/mongo-errors';
24
+ import { RequiredStringKeys } from './interfaces/required-string-keys';
25
+ import { ApiResponse, SendFunction, TransactionCallback } from './types';
26
+
27
+ /** Debug message type for console output */
28
+ export type DEBUG_TYPE = 'error' | 'warn' | 'log';
29
+
30
+ /**
31
+ * Conditionally prints debug messages to console.
32
+ * @param debug Whether to print debug messages
33
+ * @param type Type of message (error, warn, or log)
34
+ * @param args Arguments to print
35
+ */
36
+ export function debugLog(
37
+ debug: boolean,
38
+ type: DEBUG_TYPE = 'log',
39
+ ...args: unknown[]
40
+ ): void {
41
+ if (debug && type === 'error') {
42
+ console.error(...args);
43
+ } else if (debug && type === 'warn') {
44
+ console.warn(...args);
45
+ } else if (debug && type === 'log') {
46
+ console.log(...args);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Prints debug messages directly to stdout/stderr bypassing Node streams.
52
+ * Uses fs.writeSync to avoid Nx interception.
53
+ * @param debug Whether to print debug messages
54
+ * @param type Type of message (error, warn, or log)
55
+ * @param args Arguments to print
56
+ */
57
+ export function directLog(
58
+ debug: boolean,
59
+ type: DEBUG_TYPE = 'log',
60
+ ...args: any[]
61
+ ): void {
62
+ if (!debug) return;
63
+
64
+ // Format the message
65
+ const message = args
66
+ .map((arg) =>
67
+ typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg),
68
+ )
69
+ .join(' ');
70
+
71
+ // Use fs.writeSync to write directly to the file descriptors
72
+ // This bypasses Node's stream handling and Nx's interception
73
+ const buffer = Buffer.from(message + '\n', 'utf8');
74
+
75
+ if (type === 'error' || type === 'warn') {
76
+ // File descriptor 2 is stderr
77
+ writeSync(2, buffer);
78
+ } else {
79
+ // File descriptor 1 is stdout
80
+ writeSync(1, buffer);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Gets value at a dotted path from an object.
86
+ * @param obj Object to traverse
87
+ * @param path Array of keys representing the path
88
+ * @returns Value at path or undefined
89
+ */
90
+ export function getValueAtPath(
91
+ obj: unknown,
92
+ path: (string | number)[],
93
+ ): unknown {
94
+ return path.reduce<unknown>((acc, key) => {
95
+ if (acc == null) return undefined;
96
+ try {
97
+ if (
98
+ typeof acc === 'object' &&
99
+ acc !== null &&
100
+ (typeof key === 'string' || typeof key === 'number')
101
+ ) {
102
+ return (acc as Record<string | number, unknown>)[key];
103
+ }
104
+ return undefined;
105
+ } catch {
106
+ return undefined;
107
+ }
108
+ }, obj);
109
+ }
110
+
111
+ /**
112
+ * Maps Zod validation issues to express-validator ValidationError format.
113
+ * @param issues Zod validation issues
114
+ * @param source Source object being validated
115
+ * @param location Location of validation (body, query, params, etc.)
116
+ * @returns Array of express-validator ValidationErrors
117
+ */
118
+ export function mapZodIssuesToValidationErrors(
119
+ issues: z.ZodError<unknown>['issues'],
120
+ source: unknown,
121
+ location: 'body' | 'cookies' | 'headers' | 'params' | 'query' = 'body',
122
+ ): ValidationError[] {
123
+ return issues.map((issue) => ({
124
+ type: 'field',
125
+ location,
126
+ path: issue.path
127
+ .filter((p) => typeof p === 'string' || typeof p === 'number')
128
+ .join('.'),
129
+ value: getValueAtPath(source, issue.path as (string | number)[]),
130
+ msg: issue.message,
131
+ }));
132
+ }
133
+
134
+ /**
135
+ * Validates request body against Zod schema and executes callback with validated data.
136
+ * @template T Zod schema type
137
+ * @template TResult Callback return type
138
+ * @param req Express request
139
+ * @param schema Zod schema for validation
140
+ * @param callback Callback to execute with validated data
141
+ * @returns Promise resolving to callback result
142
+ * @throws {MissingValidatedDataError} If validated body is missing
143
+ * @throws {ExpressValidationError} If validation fails
144
+ */
145
+ export async function requireValidatedFieldsAsync<
146
+ T extends ZodType<any, any, any>,
147
+ TResult = void,
148
+ >(
149
+ req: Request,
150
+ schema: T,
151
+ callback: (data: z.output<T>) => Promise<TResult>,
152
+ ): Promise<TResult> {
153
+ if (req.validatedBody === undefined) {
154
+ throw new MissingValidatedDataError();
155
+ }
156
+
157
+ try {
158
+ const validatedData = schema.parse(req.validatedBody) as z.output<T>;
159
+ return await callback(validatedData);
160
+ } catch (error) {
161
+ if (error instanceof z.ZodError) {
162
+ throw new ExpressValidationError(
163
+ mapZodIssuesToValidationErrors(
164
+ error.issues,
165
+ req.validatedBody ?? {},
166
+ 'body',
167
+ ),
168
+ );
169
+ }
170
+ throw error;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Checks if at least one of the required fields is present in validated body.
176
+ * @template T Callback return type
177
+ * @param req Express request
178
+ * @param fields Array of field names to check
179
+ * @param callback Callback to execute if validation passes
180
+ * @returns Promise resolving to callback result
181
+ * @throws {MissingValidatedDataError} If none of the fields are present
182
+ */
183
+ export async function requireOneOfValidatedFieldsAsync<T = void>(
184
+ req: Request,
185
+ fields: string[],
186
+ callback: () => Promise<T>,
187
+ ): Promise<T> {
188
+ if (req.validatedBody === undefined) {
189
+ throw new MissingValidatedDataError();
190
+ }
191
+ const validatedBody = req.validatedBody;
192
+ if (!fields.some((field) => validatedBody?.[field] !== undefined)) {
193
+ throw new MissingValidatedDataError(fields);
194
+ }
195
+ return await callback();
196
+ }
197
+
198
+ /**
199
+ * Validates required fields are present in validated body (synchronous).
200
+ * @template T Callback return type
201
+ * @param req Express request
202
+ * @param fields Array of required field names
203
+ * @param callback Callback to execute if validation passes
204
+ * @returns Callback result
205
+ * @throws {MissingValidatedDataError} If any required field is missing
206
+ */
207
+ export function requireValidatedFieldsOrThrow<T = void>(
208
+ req: Request,
209
+ fields: string[],
210
+ callback: () => T,
211
+ ): T {
212
+ if (req.validatedBody === undefined) {
213
+ throw new MissingValidatedDataError();
214
+ }
215
+ const validatedBody = req.validatedBody;
216
+ fields.forEach((field) => {
217
+ if (validatedBody[field] === undefined) {
218
+ throw new MissingValidatedDataError(field);
219
+ }
220
+ });
221
+ return callback();
222
+ }
223
+
224
+ /**
225
+ * Checks if a value is a valid MongoDB ObjectId string.
226
+ * @param id Value to check
227
+ * @returns True if valid ObjectId string
228
+ */
229
+ export function isValidStringObjectId(id: unknown): boolean {
230
+ return typeof id === 'string' && Types.ObjectId.isValid(id);
231
+ }
232
+
233
+ /**
234
+ * Default number of retry attempts for transactions.
235
+ * Uses fewer retries in test environment for faster feedback.
236
+ */
237
+ export const DEFAULT_RETRY_ATTEMPTS =
238
+ process.env['NODE_ENV'] === 'test' ? 2 : 3;
239
+ /**
240
+ * Default transaction timeout in milliseconds.
241
+ * Uses shorter timeout in test environment for faster failure detection.
242
+ */
243
+ export const DEFAULT_TRANSACTION_TIMEOUT =
244
+ process.env['NODE_ENV'] === 'test' ? 15000 : 60000;
245
+
246
+ /**
247
+ * Default transaction lock request timeout in milliseconds.
248
+ */
249
+ export const DEFAULT_TRANSACTION_LOCK_REQUEST_TIMEOUT =
250
+ process.env['NODE_ENV'] === 'test' ? 10000 : 30000;
251
+
252
+ /** Transaction configuration options */
253
+ export interface TransactionOptions<TID extends PlatformID = Buffer> {
254
+ application?: IApplication<TID>;
255
+ timeoutMs?: number;
256
+ retryAttempts?: number;
257
+ baseDelay?: number;
258
+ debugLogEnabled?: boolean;
259
+ }
260
+
261
+ /**
262
+ * Gets the default base delay for transaction retries from environment variables
263
+ * @returns The base delay in milliseconds
264
+ */
265
+ export function getDefaultBaseDelay(): number {
266
+ const envValue = process.env['MONGO_TRANSACTION_RETRY_BASE_DELAY'];
267
+ if (envValue) {
268
+ const parsed = parseInt(envValue);
269
+ if (!isNaN(parsed) && parsed > 0) {
270
+ return parsed;
271
+ }
272
+ }
273
+ // Fallback to hardcoded values if environment variable is not set or invalid
274
+ return process.env['NODE_ENV'] === 'test' ? 25 : 100;
275
+ }
276
+
277
+ /**
278
+ * Wraps a callback in a transaction if necessary
279
+ * @param connection The mongoose connection
280
+ * @param useTransaction Whether to use a transaction
281
+ * @param session The session to use
282
+ * @param callback The callback to wrap
283
+ * @param options Transaction options including timeout and retry attempts
284
+ * @param args The arguments to pass to the callback
285
+ * @returns The result of the callback
286
+ */
287
+ export async function withTransaction<T, TID extends PlatformID = Buffer>(
288
+ connection: Connection,
289
+ useTransaction: boolean,
290
+ session: ClientSession | undefined,
291
+ callback: TransactionCallback<T>,
292
+ options: TransactionOptions<TID> = {},
293
+ ...args: any
294
+ ): Promise<T> {
295
+ const engine = getSuiteCoreI18nEngine(
296
+ options.application
297
+ ? { constants: options.application.constants }
298
+ : undefined,
299
+ );
300
+ const isTestEnvironment = process.env['NODE_ENV'] === 'test';
301
+ const {
302
+ timeoutMs = DEFAULT_TRANSACTION_TIMEOUT,
303
+ retryAttempts = DEFAULT_RETRY_ATTEMPTS, // Use consistent retry attempts
304
+ baseDelay = getDefaultBaseDelay(),
305
+ debugLogEnabled,
306
+ } = options;
307
+ if (!useTransaction) {
308
+ return await callback(session, undefined, ...args);
309
+ }
310
+ const needSession = useTransaction && session === undefined;
311
+ const client = connection.getClient();
312
+ if (!client) {
313
+ // If no client is available, fall back to non-transactional execution
314
+ debugLog(
315
+ debugLogEnabled === true,
316
+ 'warn',
317
+ engine.translate(
318
+ SuiteCoreComponentId,
319
+ SuiteCoreStringKey.Admin_NoMongoDbClientFoundFallingBack,
320
+ ),
321
+ );
322
+ return await callback(session, undefined, ...args);
323
+ }
324
+
325
+ let attempt = 0;
326
+ while (attempt < retryAttempts) {
327
+ const s = needSession ? await client.startSession() : session;
328
+ try {
329
+ if (needSession && s !== undefined) {
330
+ await s.startTransaction({
331
+ maxCommitTimeMS: timeoutMs,
332
+ });
333
+ }
334
+
335
+ // Race the callback against the timeout
336
+ const timeoutPromise = new Promise<never>((_, reject) => {
337
+ setTimeout(() => {
338
+ reject(
339
+ new Error(
340
+ engine.translate(
341
+ SuiteCoreComponentId,
342
+ SuiteCoreStringKey.Admin_TransactionTimeoutTemplate,
343
+ { timeMs: timeoutMs },
344
+ ),
345
+ ),
346
+ );
347
+ }, timeoutMs);
348
+ });
349
+
350
+ const result = await Promise.race([callback(s, ...args), timeoutPromise]);
351
+
352
+ if (needSession && s !== undefined) await s.commitTransaction();
353
+ return result;
354
+ } catch (error: any) {
355
+ if (needSession && s !== undefined && s.inTransaction())
356
+ await s.abortTransaction();
357
+
358
+ // Check if this is a transient transaction error that can be retried
359
+ const isTransientError =
360
+ error?.errorLabelSet?.has('TransientTransactionError') ||
361
+ error?.errorLabelSet?.has('UnknownTransactionCommitResult') ||
362
+ error?.code === 251 || // NoSuchTransaction
363
+ error?.code === 112 || // WriteConflict
364
+ error?.code === 11000 || // DuplicateKey - very common in concurrent initialization
365
+ error?.code === 16500 || // TransactionAborted
366
+ error?.code === 244 || // TransactionTooOld
367
+ error?.code === 246 || // ExceededTimeLimit
368
+ error?.code === 13436 || // TransactionTooLargeForCache
369
+ error?.code === 50 || // MaxTimeMSExpired
370
+ error?.message?.includes('Transaction') ||
371
+ error?.message?.includes('aborted') ||
372
+ error?.message?.includes('WriteConflict') ||
373
+ error?.message?.includes('NoSuchTransaction') ||
374
+ error?.message?.includes('TransactionTooOld') ||
375
+ error?.message?.includes('ExceededTimeLimit') ||
376
+ error?.message?.includes('duplicate key error') ||
377
+ error?.message?.includes('E11000') ||
378
+ (error?.code === 11000 && error?.message?.includes('duplicate')); // More specific duplicate key handling
379
+
380
+ if (isTransientError && attempt < retryAttempts - 1) {
381
+ attempt++;
382
+ const jitter = Math.random() * 0.3; // Reduced jitter
383
+ const actualBaseDelay = isTestEnvironment
384
+ ? Math.floor(baseDelay * 0.5)
385
+ : baseDelay; // Shorter base delay in tests
386
+ const delay = Math.floor(
387
+ actualBaseDelay * (1 + attempt * 0.5) * (1 + jitter),
388
+ ); // Linear backoff instead of exponential
389
+ debugLog(
390
+ debugLogEnabled === true,
391
+ 'warn',
392
+ engine.translate(
393
+ SuiteCoreComponentId,
394
+ SuiteCoreStringKey.Admin_TransactionFailedTransientTemplate,
395
+ {
396
+ delayMs: delay,
397
+ attempt,
398
+ attempts: retryAttempts,
399
+ },
400
+ undefined,
401
+ ),
402
+ );
403
+ await new Promise((resolve) => setTimeout(resolve, delay));
404
+ continue;
405
+ }
406
+
407
+ throw error;
408
+ } finally {
409
+ if (needSession && s !== undefined) await s.endSession();
410
+ }
411
+ }
412
+
413
+ const jitter = Math.random() * 0.3; // Reduced jitter
414
+ const actualBaseDelay = isTestEnvironment
415
+ ? Math.floor(baseDelay * 0.5)
416
+ : baseDelay; // Shorter base delay in tests
417
+ const delay = Math.floor(
418
+ actualBaseDelay * (1 + attempt * 0.5) * (1 + jitter),
419
+ ); // Linear backoff instead of exponential
420
+
421
+ throw new TranslatableSuiteError(
422
+ SuiteCoreStringKey.Admin_TransactionFailedTransientTemplate,
423
+ {
424
+ delayMs: delay,
425
+ attempt,
426
+ attempts: retryAttempts,
427
+ },
428
+ );
429
+ }
430
+
431
+ /**
432
+ * Sends an API response with the given status and response object.
433
+ * @param status
434
+ * @param response
435
+ * @param res
436
+ */
437
+ export function sendApiMessageResponse<T extends ApiResponse>(
438
+ status: number,
439
+ response: T,
440
+ res: Response<T>,
441
+ ): void {
442
+ res.status(status).json(response);
443
+ }
444
+
445
+ /**
446
+ * Sends an API response with the given status, message, and error.
447
+ * @param status
448
+ * @param message
449
+ * @param error
450
+ * @param res
451
+ */
452
+ export function sendApiErrorResponse(
453
+ status: number,
454
+ message: string,
455
+ error: unknown,
456
+ res: Response,
457
+ ): void {
458
+ sendApiMessageResponse<IApiErrorResponse>(status, { message, error }, res);
459
+ }
460
+
461
+ /**
462
+ * Sends an API response with the given status and validation errors.
463
+ * @param status
464
+ * @param errors
465
+ * @param res
466
+ */
467
+ export function sendApiExpressValidationErrorResponse(
468
+ status: number,
469
+ errors: ValidationError[],
470
+ res: Response,
471
+ application?: IApplication,
472
+ ): void {
473
+ const engine = getSuiteCoreI18nEngine(
474
+ application ? { constants: application.constants } : undefined,
475
+ );
476
+ sendApiMessageResponse<IApiExpressValidationErrorResponse>(
477
+ status,
478
+ {
479
+ message: engine.translate(
480
+ SuiteCoreComponentId,
481
+ SuiteCoreStringKey.ValidationError,
482
+ ),
483
+ errors,
484
+ },
485
+ res,
486
+ );
487
+ }
488
+
489
+ /**
490
+ * Sends an API response with the given status, message, and MongoDB validation errors.
491
+ * @param status
492
+ * @param message
493
+ * @param errors
494
+ * @param res
495
+ */
496
+ export function sendApiMongoValidationErrorResponse(
497
+ status: number,
498
+ message: string,
499
+ errors: IMongoErrors,
500
+ res: Response,
501
+ ): void {
502
+ sendApiMessageResponse<IApiMongoValidationErrorResponse>(
503
+ status,
504
+ { message, errors },
505
+ res,
506
+ );
507
+ }
508
+
509
+ /**
510
+ * Sends a raw JSON response with the given status and response object.
511
+ * @param status The status code
512
+ * @param response The response data
513
+ * @param res The response object
514
+ */
515
+ export function sendRawJsonResponse<T>(
516
+ status: number,
517
+ response: T,
518
+ res: Response<T>,
519
+ ) {
520
+ res.status(status).json(response);
521
+ }
522
+
523
+ function isRecursiveError(error: unknown): boolean {
524
+ return (
525
+ error !== null &&
526
+ typeof error === 'object' &&
527
+ '_handlingInProgress' in error &&
528
+ !!(error as { _handlingInProgress?: boolean })._handlingInProgress
529
+ );
530
+ }
531
+
532
+ function markErrorAsHandling(error: unknown): void {
533
+ if (error && typeof error === 'object') {
534
+ (error as { _handlingInProgress?: boolean })._handlingInProgress = true;
535
+ }
536
+ }
537
+
538
+ function getSafeErrorMessage(
539
+ message?: string,
540
+ application?: IApplication,
541
+ ): string {
542
+ if (message && typeof message === 'string' && message.trim() !== '') {
543
+ return message;
544
+ }
545
+ const engine = getSuiteCoreI18nEngine(
546
+ application ? { constants: application.constants } : undefined,
547
+ );
548
+ try {
549
+ const translated = engine.translate(
550
+ SuiteCoreComponentId,
551
+ SuiteCoreStringKey.Common_UnexpectedError,
552
+ );
553
+ return translated &&
554
+ typeof translated === 'string' &&
555
+ translated.trim() !== ''
556
+ ? translated
557
+ : 'An unexpected error occurred';
558
+ } catch {
559
+ return 'An unexpected error occurred';
560
+ }
561
+ }
562
+
563
+ function convertToHandleableError(error: unknown): {
564
+ handleableError: HandleableError;
565
+ alreadyHandled: boolean;
566
+ errorType: string;
567
+ } {
568
+ if (error instanceof HandleableError) {
569
+ return {
570
+ handleableError: error,
571
+ alreadyHandled: error.handled,
572
+ errorType: error.name,
573
+ };
574
+ }
575
+ if (error instanceof Error) {
576
+ return {
577
+ handleableError: new HandleableError(error),
578
+ alreadyHandled: false,
579
+ errorType: error.name,
580
+ };
581
+ }
582
+ const unknownMessage = getSafeErrorMessage(
583
+ typeof error === 'object' &&
584
+ error !== null &&
585
+ 'message' in (error as object)
586
+ ? ((error as Record<string, unknown>)['message'] as string | undefined)
587
+ : undefined,
588
+ );
589
+ const unknownError = new Error(unknownMessage);
590
+ return {
591
+ handleableError: new HandleableError(unknownError, { sourceData: error }),
592
+ alreadyHandled: false,
593
+ errorType: 'UnexpectedError',
594
+ };
595
+ }
596
+
597
+ function sendErrorResponse<TStringKey extends keyof RequiredStringKeys>(
598
+ error: unknown,
599
+ handleableError: HandleableError,
600
+ errorType: string,
601
+ send: SendFunction<
602
+ | IApiErrorResponse
603
+ | IApiExpressValidationErrorResponse
604
+ | IApiMongoValidationErrorResponse
605
+ >,
606
+ res: Response,
607
+ ): void {
608
+ const engine = I18nEngine.getInstance();
609
+ if (error instanceof ExpressValidationError) {
610
+ // amazonq-ignore-next-line false positive
611
+ send(
612
+ handleableError.statusCode,
613
+ {
614
+ message: engine.translate('core', 'ValidationError' as TStringKey),
615
+ errors:
616
+ error.errors instanceof Result ? error.errors.array() : error.errors,
617
+ errorType: 'ExpressValidationError',
618
+ },
619
+ res,
620
+ );
621
+ } else if (error instanceof MongooseValidationError) {
622
+ // amazonq-ignore-next-line false positive
623
+ send(
624
+ handleableError.statusCode,
625
+ {
626
+ message: engine.translate('core', 'ValidationError' as TStringKey),
627
+ errors: error.errors,
628
+ errorType: 'MongooseValidationError',
629
+ },
630
+ res,
631
+ );
632
+ } else {
633
+ // amazonq-ignore-next-line false positive
634
+ send(
635
+ handleableError.statusCode,
636
+ {
637
+ message: handleableError.message,
638
+ error: {
639
+ message: handleableError.message,
640
+ statusCode: handleableError.statusCode,
641
+ ...(handleableError.stack && { stack: handleableError.stack }),
642
+ },
643
+ errorType: errorType,
644
+ },
645
+ res,
646
+ );
647
+ }
648
+ }
649
+
650
+ export function handleError(
651
+ error: unknown,
652
+ res: Response,
653
+ send: SendFunction<
654
+ | IApiErrorResponse
655
+ | IApiExpressValidationErrorResponse
656
+ | IApiMongoValidationErrorResponse
657
+ >,
658
+ _next: NextFunction,
659
+ ): void {
660
+ if (isRecursiveError(error)) {
661
+ const fallbackError = new HandleableError(
662
+ new Error('Recursive error handling detected'),
663
+ );
664
+ // amazonq-ignore-next-line false positive
665
+ send(
666
+ fallbackError.statusCode,
667
+ {
668
+ message: fallbackError.message,
669
+ error: fallbackError,
670
+ errorType: 'RecursiveError',
671
+ },
672
+ res,
673
+ );
674
+ return;
675
+ }
676
+
677
+ markErrorAsHandling(error);
678
+ const {
679
+ handleableError,
680
+ alreadyHandled: _alreadyHandled,
681
+ errorType,
682
+ } = convertToHandleableError(error);
683
+
684
+ if (!(error instanceof ExpressValidationError)) {
685
+ console.error(
686
+ '[handleError]',
687
+ 'type=' + errorType.replace(/[\r\n]/g, ''),
688
+ 'status=' + String(handleableError.statusCode).replace(/[\r\n]/g, ''),
689
+ 'message=' + (handleableError.message || '').replace(/[\r\n]/g, ''),
690
+ );
691
+ if (error instanceof Error && error.stack) {
692
+ debugLog(true, 'error', '[handleError] stack:', error.stack);
693
+ }
694
+ }
695
+
696
+ if (!res.headersSent) {
697
+ sendErrorResponse(error, handleableError, errorType, send, res);
698
+ handleableError.handled = true;
699
+ }
700
+ }
701
+
702
+ export function locatePEMRoot(devRootDir: string): string | undefined {
703
+ try {
704
+ const normalizedDir = resolve(devRootDir);
705
+ if (
706
+ normalizedDir.includes('..') ||
707
+ !normalizedDir.startsWith(resolve('.'))
708
+ ) {
709
+ return undefined;
710
+ }
711
+ const files = readdirSync(normalizedDir);
712
+ const pemFiles = files.filter(
713
+ (file: string) =>
714
+ // Prevent path traversal by rejecting files with path separators
715
+ !file.includes('/') &&
716
+ !file.includes('\\') &&
717
+ !file.includes('..') &&
718
+ (file.match(/localhost\+\d+-key\.pem$/) ||
719
+ file.match(/localhost\+\d+\.pem$/)),
720
+ );
721
+ if (pemFiles.length < 2) {
722
+ return undefined;
723
+ }
724
+ const roots = pemFiles.map((file: string) => {
725
+ const resolved = resolve(normalizedDir, file);
726
+ if (!resolved.startsWith(normalizedDir)) {
727
+ return undefined;
728
+ }
729
+ const result = /(.*)\/(localhost\+\d+)(.*)\.pem/.exec(resolved);
730
+ return result ? `${result[1]}/${result[2]}` : undefined;
731
+ });
732
+ if (roots.some((root) => root !== roots[0])) {
733
+ return undefined;
734
+ }
735
+ if (!existsSync(roots[0] + '.pem') || !existsSync(roots[0] + '-key.pem')) {
736
+ return undefined;
737
+ }
738
+ return roots[0]!;
739
+ } catch {
740
+ return undefined;
741
+ }
742
+ }
743
+
744
+ /**
745
+ * Encodes the length of the data in the buffer
746
+ * @param buffer The buffer to encode
747
+ * @returns The encoded buffer
748
+ */
749
+ export function lengthEncodeData(buffer: Buffer): Buffer {
750
+ const lengthType: LengthEncodingType = getLengthEncodingTypeForLength(
751
+ buffer.length,
752
+ );
753
+ const lengthTypeSize: number = getLengthForLengthType(lengthType);
754
+ const result: Buffer = Buffer.alloc(1 + lengthTypeSize + buffer.length);
755
+ result.writeUInt8(lengthType, 0);
756
+ switch (lengthType) {
757
+ case LengthEncodingType.UInt8:
758
+ result.writeUInt8(buffer.length, 1);
759
+ break;
760
+ case LengthEncodingType.UInt16:
761
+ result.writeUInt16BE(buffer.length, 1);
762
+ break;
763
+ case LengthEncodingType.UInt32:
764
+ result.writeUInt32BE(buffer.length, 1);
765
+ break;
766
+ case LengthEncodingType.UInt64:
767
+ result.writeBigUInt64BE(BigInt(buffer.length), 1);
768
+ break;
769
+ }
770
+ buffer.copy(result, 1 + lengthTypeSize);
771
+ return result;
772
+ }
773
+
774
+ export function decodeLengthEncodedData(buffer: Buffer): {
775
+ data: Buffer;
776
+ totalLength: number;
777
+ } {
778
+ if (buffer.length < 1) {
779
+ throw new RangeError('Buffer is too short to read length type.');
780
+ }
781
+ const lengthType: LengthEncodingType = getLengthEncodingTypeFromValue(
782
+ buffer.readUint8(0),
783
+ );
784
+ const lengthTypeSize: number = getLengthForLengthType(lengthType);
785
+
786
+ if (buffer.length < 1 + lengthTypeSize) {
787
+ throw new RangeError('Buffer is too short to read the full length value.');
788
+ }
789
+
790
+ let length: number | bigint;
791
+ switch (lengthType) {
792
+ case LengthEncodingType.UInt8:
793
+ length = buffer.readUint8(1);
794
+ break;
795
+ case LengthEncodingType.UInt16:
796
+ length = buffer.readUint16BE(1);
797
+ break;
798
+ case LengthEncodingType.UInt32:
799
+ length = buffer.readUint32BE(1);
800
+ break;
801
+ case LengthEncodingType.UInt64:
802
+ length = buffer.readBigUInt64BE(1);
803
+ if (Number(length) > Number.MAX_SAFE_INTEGER) {
804
+ throw new RangeError('Length exceeds maximum safe integer value');
805
+ }
806
+ break;
807
+ default:
808
+ throw new TranslatableSuiteError(
809
+ SuiteCoreStringKey.Error_LengthIsInvalidType,
810
+ );
811
+ }
812
+
813
+ const totalLength = 1 + lengthTypeSize + Number(length);
814
+ if (totalLength > buffer.length) {
815
+ throw new RangeError('Buffer is too short for declared data length');
816
+ }
817
+ return {
818
+ data: buffer.subarray(1 + lengthTypeSize, totalLength),
819
+ totalLength,
820
+ };
821
+ }
822
+
823
+ import { HandleableError } from '@digitaldefiance/i18n-lib';
824
+ import {
825
+ getSuiteCoreI18nEngine,
826
+ SuiteCoreComponentId,
827
+ SuiteCoreStringKey,
828
+ TranslatableSuiteError,
829
+ } from '@digitaldefiance/suite-core-lib';
830
+ import moment from 'moment-timezone';
831
+ import { BackupCode } from './backup-code';
832
+ import { LengthEncodingType } from './enumerations/length-encoding-type';
833
+ import { MissingValidatedDataError } from './errors';
834
+ import type { PlatformID } from '@digitaldefiance/node-ecies-lib';
835
+
836
+ export function isValidTimezone(timezone: string): boolean {
837
+ return moment.tz.zone(timezone) !== null;
838
+ }
839
+
840
+ /**
841
+ * Omits keys from an object
842
+ */
843
+ export function omit<T extends object, K extends keyof T>(
844
+ obj: T,
845
+ keys: K[],
846
+ ): Omit<T, K> {
847
+ const keysToOmit = new Set(keys);
848
+ return Object.keys(obj).reduce((result, key) => {
849
+ if (!keysToOmit.has(key as K)) {
850
+ result[key as keyof T] = obj[key as keyof T];
851
+ }
852
+ return result;
853
+ }, {} as T) as Omit<T, K>;
854
+ }
855
+
856
+ /**
857
+ * Validates that a collection contains exactly the keys from an enum
858
+ * @param collection The collection to validate
859
+ * @param enumObject The enum object to validate against
860
+ * @param collectionName Optional name for the collection (for better error messages)
861
+ * @param enumName Optional name for the enum (for better error messages)
862
+ * @throws Error if collection has missing, extra, or invalid keys
863
+ */
864
+ export function validateEnumCollection<T extends Record<string, any>>(
865
+ collection: Record<string, unknown>,
866
+ enumObject: T,
867
+ collectionName?: string,
868
+ enumName?: string,
869
+ ): void {
870
+ // For numeric enums, filter out reverse mappings (number -> string)
871
+ const enumKeys = Object.keys(enumObject).filter((key) => isNaN(Number(key)));
872
+ const allEnumValues = enumKeys.map((key) => enumObject[key]);
873
+ const collectionKeys = Object.keys(collection);
874
+
875
+ const collectionLabel = collectionName || 'Collection';
876
+ const enumLabel = enumName || `enum with keys [${enumKeys.join(', ')}]`;
877
+
878
+ if (collectionKeys.length !== allEnumValues.length) {
879
+ throw new Error(
880
+ `${collectionLabel} must contain exactly ${
881
+ allEnumValues.length
882
+ } keys to match ${enumLabel}. Found ${
883
+ collectionKeys.length
884
+ } keys: [${collectionKeys.join(', ')}]`,
885
+ );
886
+ }
887
+
888
+ const invalidKeys = collectionKeys.filter(
889
+ (key) => !allEnumValues.includes(key),
890
+ );
891
+ if (invalidKeys.length > 0) {
892
+ throw new Error(
893
+ `${collectionLabel} contains invalid keys for ${enumLabel}: [${invalidKeys.join(
894
+ ', ',
895
+ )}]. Valid keys are: [${allEnumValues.join(', ')}]`,
896
+ );
897
+ }
898
+
899
+ const missingKeys = allEnumValues.filter((value) => !(value in collection));
900
+ if (missingKeys.length > 0) {
901
+ throw new Error(
902
+ `${collectionLabel} is missing required keys for ${enumLabel}: [${missingKeys.join(
903
+ ', ',
904
+ )}]`,
905
+ );
906
+ }
907
+ }
908
+
909
+ export function uint8ArrayToBase64(uint8Array: Uint8Array): string {
910
+ let binaryString = '';
911
+ for (let i = 0; i < uint8Array.length; i++) {
912
+ binaryString += String.fromCharCode(uint8Array[i]);
913
+ }
914
+ return btoa(binaryString);
915
+ }
916
+
917
+ export function base64ToUint8Array(base64String: string): Uint8Array {
918
+ const binaryString = atob(base64String);
919
+ const len = binaryString.length;
920
+ const bytes = new Uint8Array(len);
921
+ for (let i = 0; i < len; i++) {
922
+ bytes[i] = binaryString.charCodeAt(i);
923
+ }
924
+ return bytes;
925
+ }
926
+
927
+ export function uint8ArrayToHex(uint8Array: Uint8Array): string {
928
+ return Array.from(uint8Array)
929
+ .map((byte) => byte.toString(16).padStart(2, '0'))
930
+ .join('');
931
+ }
932
+
933
+ export function hexToUint8Array(hexString: string): Uint8Array {
934
+ const len = hexString.length;
935
+ const bytes = new Uint8Array(len / 2);
936
+ for (let i = 0; i < len; i += 2) {
937
+ bytes[i / 2] = parseInt(hexString.substring(i, i + 2), 16);
938
+ }
939
+ return bytes;
940
+ }
941
+
942
+ /**
943
+ * Utility functions for browser ECIES implementation
944
+ */
945
+
946
+ /**
947
+ * CRC16-CCITT implementation for data integrity checking
948
+ * Uses the same algorithm as the server-side implementation (CRC16-CCITT-FALSE)
949
+ */
950
+ export function crc16(data: Uint8Array): Uint8Array {
951
+ let crc = 0xffff; // Initial value for CRC16-CCITT-FALSE
952
+ const polynomial = 0x1021; // CRC16-CCITT polynomial
953
+
954
+ for (let i = 0; i < data.length; i++) {
955
+ crc ^= data[i] << 8;
956
+ for (let j = 0; j < 8; j++) {
957
+ if (crc & 0x8000) {
958
+ crc = (crc << 1) ^ polynomial;
959
+ } else {
960
+ crc = crc << 1;
961
+ }
962
+ crc &= 0xffff; // Keep it 16-bit
963
+ }
964
+ }
965
+
966
+ const result = new Uint8Array(2);
967
+ result[0] = (crc >>> 8) & 0xff; // Big-endian
968
+ result[1] = crc & 0xff;
969
+ return result;
970
+ }
971
+
972
+ /**
973
+ * Convert string to Uint8Array (UTF-8 encoding)
974
+ */
975
+ export function stringToUint8Array(str: string): Uint8Array {
976
+ return new TextEncoder().encode(str);
977
+ }
978
+
979
+ /**
980
+ * Convert Uint8Array to string (UTF-8 decoding)
981
+ */
982
+ export function uint8ArrayToString(array: Uint8Array): string {
983
+ return new TextDecoder().decode(array);
984
+ }
985
+
986
+ /**
987
+ * Secure random bytes generation
988
+ */
989
+ export function randomBytes(length: number): Uint8Array {
990
+ return crypto.getRandomValues(new Uint8Array(length));
991
+ }
992
+
993
+ /**
994
+ * Compare two Uint8Arrays for equality
995
+ */
996
+ export function arraysEqual(a: Uint8Array, b: Uint8Array): boolean {
997
+ if (a.length !== b.length) return false;
998
+ for (let i = 0; i < a.length; i++) {
999
+ if (a[i] !== b[i]) return false;
1000
+ }
1001
+ return true;
1002
+ }
1003
+
1004
+ /**
1005
+ * Concatenate multiple Uint8Arrays
1006
+ */
1007
+ export function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array {
1008
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
1009
+ const result = new Uint8Array(totalLength);
1010
+ let offset = 0;
1011
+ for (const array of arrays) {
1012
+ result.set(array, offset);
1013
+ offset += array.length;
1014
+ }
1015
+ return result;
1016
+ }
1017
+
1018
+ /**
1019
+ * Get the length encoding type for a given length
1020
+ * @param length The length to evaluate
1021
+ * @returns The corresponding LengthEncodingType
1022
+ */
1023
+ export function getLengthEncodingTypeForLength(
1024
+ length: number | bigint,
1025
+ ): LengthEncodingType {
1026
+ if (typeof length === 'number') {
1027
+ if (length < 256) {
1028
+ return LengthEncodingType.UInt8;
1029
+ } else if (length < 65536) {
1030
+ return LengthEncodingType.UInt16;
1031
+ } else if (length < 4294967296) {
1032
+ return LengthEncodingType.UInt32;
1033
+ } else if (length < Number.MAX_SAFE_INTEGER) {
1034
+ return LengthEncodingType.UInt64;
1035
+ } else {
1036
+ throw new TranslatableSuiteError(
1037
+ SuiteCoreStringKey.Error_LengthExceedsMaximum,
1038
+ );
1039
+ }
1040
+ } else if (typeof length === 'bigint') {
1041
+ if (length < 256n) {
1042
+ return LengthEncodingType.UInt8;
1043
+ } else if (length < 65536n) {
1044
+ return LengthEncodingType.UInt16;
1045
+ } else if (length < 4294967296n) {
1046
+ return LengthEncodingType.UInt32;
1047
+ } else if (length < 18446744073709551616n) {
1048
+ return LengthEncodingType.UInt64;
1049
+ } else {
1050
+ throw new TranslatableSuiteError(
1051
+ SuiteCoreStringKey.Error_LengthExceedsMaximum,
1052
+ );
1053
+ }
1054
+ } else {
1055
+ throw new TranslatableSuiteError(
1056
+ SuiteCoreStringKey.Error_LengthIsInvalidType,
1057
+ );
1058
+ }
1059
+ }
1060
+
1061
+ /**
1062
+ * Get the length encoding type for a given value
1063
+ * @param value The value to evaluate
1064
+ * @returns The corresponding LengthEncodingType
1065
+ */
1066
+ export function getLengthEncodingTypeFromValue(
1067
+ value: number,
1068
+ ): LengthEncodingType {
1069
+ for (const length of Object.values(LengthEncodingType)) {
1070
+ if (length === value) {
1071
+ return length;
1072
+ }
1073
+ }
1074
+ throw new TranslatableSuiteError(
1075
+ SuiteCoreStringKey.Error_LengthIsInvalidType,
1076
+ );
1077
+ }
1078
+
1079
+ /**
1080
+ * Get the length in bytes for a given LengthEncodingType
1081
+ * @param type The LengthEncodingType to evaluate
1082
+ * @returns The length in bytes
1083
+ */
1084
+ export function getLengthForLengthType(type: LengthEncodingType): number {
1085
+ switch (type) {
1086
+ case LengthEncodingType.UInt8:
1087
+ return 1;
1088
+ case LengthEncodingType.UInt16:
1089
+ return 2;
1090
+ case LengthEncodingType.UInt32:
1091
+ return 4;
1092
+ case LengthEncodingType.UInt64:
1093
+ return 8;
1094
+ default:
1095
+ throw new TranslatableSuiteError(
1096
+ SuiteCoreStringKey.Error_LengthIsInvalidType,
1097
+ );
1098
+ }
1099
+ }
1100
+
1101
+ export function parseBackupCodes(
1102
+ user: 'admin' | 'member' | 'system',
1103
+ environment: Record<string, string | undefined>,
1104
+ ): BackupCode[] {
1105
+ const envVarMap: Record<'admin' | 'member' | 'system', string> = {
1106
+ admin: 'ADMIN_BACKUP_CODES',
1107
+ member: 'MEMBER_BACKUP_CODES',
1108
+ system: 'SYSTEM_BACKUP_CODES',
1109
+ };
1110
+ const envVar = envVarMap[user];
1111
+ const envValue = environment[envVar];
1112
+ const backupCodes =
1113
+ envValue?.split(',').map((code: string) => new BackupCode(code.trim())) ||
1114
+ [];
1115
+ return backupCodes;
1116
+ }