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