@digitaldefiance/node-express-suite 3.6.7 → 3.6.9

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