@digitaldefiance/node-express-suite 3.6.20 → 3.6.21

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