@punks/backend-entity-manager 0.0.72 → 0.0.74
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/dist/cjs/index.js +201 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/__test__/server/app/auth/auth.dto.d.ts +6 -14
- package/dist/cjs/types/platforms/nest/__test__/server/app/organizations/organization.controller.d.ts +5 -1
- package/dist/cjs/types/platforms/nest/__test__/server/app/organizations/templates/organization-register/index.d.ts +5 -21
- package/dist/cjs/types/platforms/nest/__test__/server/app/organizations/templates/organization-register/models.d.ts +17 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/templates/index.d.ts +3 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/templates/instance-initialize/index.d.ts +11 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/templates/instance-initialize/models.d.ts +4 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/templates/tenant-initialize/index.d.ts +13 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/templates/tenant-initialize/models.d.ts +17 -0
- package/dist/cjs/types/platforms/nest/__test__/server/app/tenants/tenant.controller.d.ts +7 -1
- package/dist/cjs/types/platforms/nest/__test__/server/index.d.ts +1 -0
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/index.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/models/index.d.ts +9 -0
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/providers/index.d.ts +5 -2
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/providers/roles/index.d.ts +14 -0
- package/dist/cjs/types/platforms/nest/__test__/server/{app/auth/services/auth.userRoles.service.d.ts → infrastructure/authentication/providers/userRoles/index.d.ts} +6 -6
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/providers/users/index.d.ts +23 -0
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/roles/index.d.ts +14 -0
- package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/types.d.ts +2 -1
- package/dist/cjs/types/platforms/nest/__test__/tests/ports.d.ts +9 -0
- package/dist/cjs/types/platforms/nest/base/entityActions.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/abstractions/index.d.ts +3 -2
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/handlers.d.ts +3 -1
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/index.d.ts +2 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/user-create/index.d.ts +14 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/user-create/types.d.ts +16 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/user-delete/index.d.ts +7 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/user-delete/types.d.ts +3 -0
- package/dist/cjs/types/platforms/nest/extensions/authentication/services/authentication/index.d.ts +8 -1
- package/dist/cjs/types/platforms/nest/ioc/storage.d.ts +6 -0
- package/dist/cjs/types/platforms/nest/module.d.ts +6 -1
- package/dist/cjs/types/platforms/nest/pipelines/builder/types.d.ts +1 -1
- package/dist/cjs/types/platforms/nest/pipelines/template/errors.d.ts +6 -0
- package/dist/cjs/types/platforms/nest/pipelines/template/index.d.ts +8 -3
- package/dist/cjs/types/platforms/nest/pipelines/template/utils.d.ts +6 -0
- package/dist/cjs/types/platforms/nest/session/storage.d.ts +1 -1
- package/dist/cjs/types/templates/pipelines/converters/index.d.ts +2 -1
- package/dist/cjs/types/types/pipelines.d.ts +16 -2
- package/dist/esm/index.js +202 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/__test__/server/app/auth/auth.dto.d.ts +6 -14
- package/dist/esm/types/platforms/nest/__test__/server/app/organizations/organization.controller.d.ts +5 -1
- package/dist/esm/types/platforms/nest/__test__/server/app/organizations/templates/organization-register/index.d.ts +5 -21
- package/dist/esm/types/platforms/nest/__test__/server/app/organizations/templates/organization-register/models.d.ts +17 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/templates/index.d.ts +3 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/templates/instance-initialize/index.d.ts +11 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/templates/instance-initialize/models.d.ts +4 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/templates/tenant-initialize/index.d.ts +13 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/templates/tenant-initialize/models.d.ts +17 -0
- package/dist/esm/types/platforms/nest/__test__/server/app/tenants/tenant.controller.d.ts +7 -1
- package/dist/esm/types/platforms/nest/__test__/server/index.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/index.d.ts +1 -1
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/models/index.d.ts +9 -0
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/providers/index.d.ts +5 -2
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/providers/roles/index.d.ts +14 -0
- package/dist/esm/types/platforms/nest/__test__/server/{app/auth/services/auth.userRoles.service.d.ts → infrastructure/authentication/providers/userRoles/index.d.ts} +6 -6
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/providers/users/index.d.ts +23 -0
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/roles/index.d.ts +14 -0
- package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/types.d.ts +2 -1
- package/dist/esm/types/platforms/nest/__test__/tests/base/crud-actions.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/base/crud-api.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/base/crud-operations.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/base/seeder.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/base/server-session.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/pipelines/crud_pipeline_api.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/pipelines/crud_pipeline_template.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/pipelines/simple_pipeline.test.d.ts +1 -0
- package/dist/esm/types/platforms/nest/__test__/tests/ports.d.ts +9 -0
- package/dist/esm/types/platforms/nest/base/entityActions.d.ts +1 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/abstractions/index.d.ts +3 -2
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/handlers.d.ts +3 -1
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/index.d.ts +2 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/user-create/index.d.ts +14 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/user-create/types.d.ts +16 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/user-delete/index.d.ts +7 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/handlers/user-delete/types.d.ts +3 -0
- package/dist/esm/types/platforms/nest/extensions/authentication/services/authentication/index.d.ts +8 -1
- package/dist/esm/types/platforms/nest/ioc/storage.d.ts +6 -0
- package/dist/esm/types/platforms/nest/module.d.ts +6 -1
- package/dist/esm/types/platforms/nest/pipelines/builder/types.d.ts +1 -1
- package/dist/esm/types/platforms/nest/pipelines/template/errors.d.ts +6 -0
- package/dist/esm/types/platforms/nest/pipelines/template/index.d.ts +8 -3
- package/dist/esm/types/platforms/nest/pipelines/template/utils.d.ts +6 -0
- package/dist/esm/types/platforms/nest/session/storage.d.ts +1 -1
- package/dist/esm/types/templates/pipelines/converters/index.d.ts +2 -1
- package/dist/esm/types/types/pipelines.d.ts +16 -2
- package/dist/index.d.ts +68 -9
- package/package.json +1 -1
- package/dist/cjs/types/platforms/nest/__test__/server/app/auth/services/auth.roles.service.d.ts +0 -12
- package/dist/cjs/types/platforms/nest/__test__/server/app/auth/services/auth.user.service.d.ts +0 -20
- package/dist/cjs/types/platforms/nest/__test__/server/app/auth/services/index.d.ts +0 -4
- package/dist/esm/types/platforms/nest/__test__/server/app/auth/services/auth.roles.service.d.ts +0 -12
- package/dist/esm/types/platforms/nest/__test__/server/app/auth/services/auth.user.service.d.ts +0 -20
- package/dist/esm/types/platforms/nest/__test__/server/app/auth/services/index.d.ts +0 -4
- /package/dist/cjs/types/__test__/base/{test-actions-plain.test.d.ts → actions-plain.test.d.ts} +0 -0
- /package/dist/cjs/types/__test__/base/{test-actions-with-converters.test.d.ts → actions-with-converters.test.d.ts} +0 -0
- /package/dist/cjs/types/__test__/base/{test-default-entity-manager.test.d.ts → default-entity-manager.test.d.ts} +0 -0
- /package/dist/cjs/types/__test__/providers/typeorm/{test-typeorm-actions.test.d.ts → typeorm-actions.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/{tests/authentication/test_auth_api.test.d.ts → server/app/organizations/templates/organization-register/pipeline.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/{tests/authentication/test_auth_guards.test.d.ts → server/app/tenants/templates/instance-initialize/pipeline.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/{tests/authentication/test_auth_jwt.test.d.ts → server/app/tenants/templates/tenant-initialize/pipeline.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/server/infrastructure/authentication/providers/{auth-context → context}/index.d.ts +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/{base/test_crud_actions.test.d.ts → authentication/auth-api.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/{base/test_crud_api.test.d.ts → authentication/auth-guards.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/{base/test_crud_operations.test.d.ts → authentication/auth-jwt.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/base/{test_seeder.test.d.ts → crud-actions.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/base/{test_server_session.test.d.ts → crud-api.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/{pipelines/test_crud_pipeline.test.d.ts → base/crud-operations.test.d.ts} +0 -0
- /package/dist/cjs/types/platforms/nest/__test__/tests/{pipelines/test_simple_pipeline.test.d.ts → base/seeder.test.d.ts} +0 -0
- /package/dist/{esm/types/__test__/base/test-actions-plain.test.d.ts → cjs/types/platforms/nest/__test__/tests/base/server-session.test.d.ts} +0 -0
- /package/dist/{esm/types/__test__/base/test-actions-with-converters.test.d.ts → cjs/types/platforms/nest/__test__/tests/pipelines/crud_pipeline_api.test.d.ts} +0 -0
- /package/dist/{esm/types/__test__/base/test-default-entity-manager.test.d.ts → cjs/types/platforms/nest/__test__/tests/pipelines/crud_pipeline_template.test.d.ts} +0 -0
- /package/dist/{esm/types/__test__/providers/typeorm/test-typeorm-actions.test.d.ts → cjs/types/platforms/nest/__test__/tests/pipelines/simple_pipeline.test.d.ts} +0 -0
- /package/dist/esm/types/{platforms/nest/__test__/tests/authentication/test_auth_api.test.d.ts → __test__/base/actions-plain.test.d.ts} +0 -0
- /package/dist/esm/types/{platforms/nest/__test__/tests/authentication/test_auth_guards.test.d.ts → __test__/base/actions-with-converters.test.d.ts} +0 -0
- /package/dist/esm/types/{platforms/nest/__test__/tests/authentication/test_auth_jwt.test.d.ts → __test__/base/default-entity-manager.test.d.ts} +0 -0
- /package/dist/esm/types/{platforms/nest/__test__/tests/base/test_crud_actions.test.d.ts → __test__/providers/typeorm/typeorm-actions.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/{tests/base/test_crud_api.test.d.ts → server/app/organizations/templates/organization-register/pipeline.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/{tests/base/test_crud_operations.test.d.ts → server/app/tenants/templates/instance-initialize/pipeline.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/{tests/base/test_seeder.test.d.ts → server/app/tenants/templates/tenant-initialize/pipeline.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/server/infrastructure/authentication/providers/{auth-context → context}/index.d.ts +0 -0
- /package/dist/esm/types/platforms/nest/__test__/tests/{base/test_server_session.test.d.ts → authentication/auth-api.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/tests/{pipelines/test_crud_pipeline.test.d.ts → authentication/auth-guards.test.d.ts} +0 -0
- /package/dist/esm/types/platforms/nest/__test__/tests/{pipelines/test_simple_pipeline.test.d.ts → authentication/auth-jwt.test.d.ts} +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -433,7 +433,12 @@ exports.AuthGuard = __decorate([
|
|
|
433
433
|
__metadata("design:paramtypes", [core.Reflector])
|
|
434
434
|
], exports.AuthGuard);
|
|
435
435
|
|
|
436
|
-
|
|
436
|
+
exports.UserCreationError = void 0;
|
|
437
|
+
(function (UserCreationError) {
|
|
438
|
+
UserCreationError["UserAlreadyExists"] = "userAlreadyExists";
|
|
439
|
+
})(exports.UserCreationError || (exports.UserCreationError = {}));
|
|
440
|
+
|
|
441
|
+
const sessionStorage = new async_hooks.AsyncLocalStorage();
|
|
437
442
|
|
|
438
443
|
exports.AppSessionService = class AppSessionService {
|
|
439
444
|
getValue(key) {
|
|
@@ -449,7 +454,7 @@ exports.AppSessionService = class AppSessionService {
|
|
|
449
454
|
return this.getSession().request;
|
|
450
455
|
}
|
|
451
456
|
getSession() {
|
|
452
|
-
const store =
|
|
457
|
+
const store = sessionStorage.getStore();
|
|
453
458
|
if (!store) {
|
|
454
459
|
throw new Error("No active context found");
|
|
455
460
|
}
|
|
@@ -610,7 +615,10 @@ class EntityCreateCommand {
|
|
|
610
615
|
return;
|
|
611
616
|
}
|
|
612
617
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
613
|
-
const context = await contextService
|
|
618
|
+
const context = await contextService?.getContext();
|
|
619
|
+
if (!context) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
614
622
|
const authorizationResult = await authorization.canCreate(entity, context);
|
|
615
623
|
if (!authorizationResult.isAuthorized)
|
|
616
624
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
@@ -636,7 +644,10 @@ class EntityDeleteCommand {
|
|
|
636
644
|
throw new EntityNotFoundException(id);
|
|
637
645
|
}
|
|
638
646
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
639
|
-
const context = await contextService
|
|
647
|
+
const context = await contextService?.getContext();
|
|
648
|
+
if (!context) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
640
651
|
const authorizationResult = await authorization.canDelete(entity, context);
|
|
641
652
|
if (!authorizationResult.isAuthorized)
|
|
642
653
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Delete, this.services.getEntityName(), entity);
|
|
@@ -670,7 +681,10 @@ class EntitiesDeleteCommand {
|
|
|
670
681
|
return;
|
|
671
682
|
}
|
|
672
683
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
673
|
-
const context = await contextService
|
|
684
|
+
const context = await contextService?.getContext();
|
|
685
|
+
if (!context) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
674
688
|
const authorizationResult = await authorization.canDeleteItems(context);
|
|
675
689
|
if (!authorizationResult.isAuthorized)
|
|
676
690
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Delete, this.services.getEntityName());
|
|
@@ -708,7 +722,10 @@ class EntityUpdateCommand {
|
|
|
708
722
|
throw new EntityNotFoundException();
|
|
709
723
|
}
|
|
710
724
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
711
|
-
const context = await contextService
|
|
725
|
+
const context = await contextService?.getContext();
|
|
726
|
+
if (!context) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
712
729
|
const authorizationResult = await authorization.canUpdate(currentEntity, context);
|
|
713
730
|
if (!authorizationResult.isAuthorized)
|
|
714
731
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Create, this.services.getEntityName(), currentEntity);
|
|
@@ -744,7 +761,10 @@ class EntityUpsertCommand {
|
|
|
744
761
|
}
|
|
745
762
|
const currentEntity = await this.services.resolveRepository().get(id);
|
|
746
763
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
747
|
-
const context = await contextService
|
|
764
|
+
const context = await contextService?.getContext();
|
|
765
|
+
if (!context) {
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
748
768
|
if (currentEntity) {
|
|
749
769
|
const updateResult = await authorization.canUpdate(currentEntity, context);
|
|
750
770
|
if (!updateResult.isAuthorized)
|
|
@@ -1087,7 +1107,9 @@ class EntitiesServiceLocator {
|
|
|
1087
1107
|
this.provider.register(GlobalServices.Pipelines.IPipelineController, instance);
|
|
1088
1108
|
}
|
|
1089
1109
|
resolveAuthenticationContextProvider() {
|
|
1090
|
-
return this.provider.resolve(GlobalServices.Authentication.IAuthenticationContextProvider
|
|
1110
|
+
return this.provider.resolve(GlobalServices.Authentication.IAuthenticationContextProvider, {
|
|
1111
|
+
optional: true,
|
|
1112
|
+
});
|
|
1091
1113
|
}
|
|
1092
1114
|
registerAuthenticationContextProvider(instance) {
|
|
1093
1115
|
this.provider.register(GlobalServices.Authentication.IAuthenticationContextProvider, instance);
|
|
@@ -1399,7 +1421,10 @@ class EntityGetQuery {
|
|
|
1399
1421
|
return;
|
|
1400
1422
|
}
|
|
1401
1423
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1402
|
-
const context = await contextService
|
|
1424
|
+
const context = await contextService?.getContext();
|
|
1425
|
+
if (!context) {
|
|
1426
|
+
return;
|
|
1427
|
+
}
|
|
1403
1428
|
const authorizationResult = await authorization.canRead(entity, context);
|
|
1404
1429
|
if (!authorizationResult.isAuthorized)
|
|
1405
1430
|
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Read, this.services.getEntityName(), entity);
|
|
@@ -1434,7 +1459,7 @@ class EntitiesSearchQuery {
|
|
|
1434
1459
|
return undefined;
|
|
1435
1460
|
}
|
|
1436
1461
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1437
|
-
return await contextService
|
|
1462
|
+
return await contextService?.getContext();
|
|
1438
1463
|
}
|
|
1439
1464
|
async filterAllowedEntities(entities, context) {
|
|
1440
1465
|
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
@@ -19513,7 +19538,7 @@ let UserRegistrationHandler = class UserRegistrationHandler {
|
|
|
19513
19538
|
userId: user.id,
|
|
19514
19539
|
};
|
|
19515
19540
|
}
|
|
19516
|
-
const newUser = await this.createUser(input.email, input.registrationInfo, input.context);
|
|
19541
|
+
const newUser = await this.createUser(input.email, input.userName, input.registrationInfo, input.context);
|
|
19517
19542
|
const passwordHash = await this.createPasswordHash(input.password, newUser.id);
|
|
19518
19543
|
await this.services.getUsersService().update(newUser.id, {
|
|
19519
19544
|
passwordHash,
|
|
@@ -19554,8 +19579,10 @@ let UserRegistrationHandler = class UserRegistrationHandler {
|
|
|
19554
19579
|
timestamp: Date.now(),
|
|
19555
19580
|
});
|
|
19556
19581
|
}
|
|
19557
|
-
async createUser(email, info, context) {
|
|
19558
|
-
return await this.services
|
|
19582
|
+
async createUser(email, userName, info, context) {
|
|
19583
|
+
return await this.services
|
|
19584
|
+
.getUsersService()
|
|
19585
|
+
.create(email, userName, info, context);
|
|
19559
19586
|
}
|
|
19560
19587
|
async resolveUser(userName, context) {
|
|
19561
19588
|
return ((await this.services
|
|
@@ -19889,9 +19916,92 @@ UserVerifyRequestHandler = __decorate([
|
|
|
19889
19916
|
JwtProvider])
|
|
19890
19917
|
], UserVerifyRequestHandler);
|
|
19891
19918
|
|
|
19919
|
+
let UserCreationHandler = class UserCreationHandler {
|
|
19920
|
+
constructor(services, passwordHashingProvider) {
|
|
19921
|
+
this.services = services;
|
|
19922
|
+
this.passwordHashingProvider = passwordHashingProvider;
|
|
19923
|
+
this.logger = backendCore.Log.getLogger("UserCreation");
|
|
19924
|
+
}
|
|
19925
|
+
async execute(input) {
|
|
19926
|
+
const user = (await this.resolveUser(input.email, input.context)) ??
|
|
19927
|
+
(await this.resolveUser(input.userName, input.context));
|
|
19928
|
+
if (user && user.verified) {
|
|
19929
|
+
this.logger.debug(`User already exists: ${input.email} - ${input.userName}`, { user });
|
|
19930
|
+
return {
|
|
19931
|
+
success: false,
|
|
19932
|
+
error: exports.UserCreationError.UserAlreadyExists,
|
|
19933
|
+
};
|
|
19934
|
+
}
|
|
19935
|
+
if (user && !user.verified) {
|
|
19936
|
+
const passwordHash = await this.createPasswordHash(input.password, user.id);
|
|
19937
|
+
await this.services.getUsersService().update(user.id, {
|
|
19938
|
+
passwordHash,
|
|
19939
|
+
passwordUpdateTimestamp: new Date(),
|
|
19940
|
+
verified: true,
|
|
19941
|
+
});
|
|
19942
|
+
this.logger.debug(`User already exists but not verified. Updating password and marking as verified: ${input.email} - ${input.userName}`, { user });
|
|
19943
|
+
return {
|
|
19944
|
+
success: true,
|
|
19945
|
+
userId: user.id,
|
|
19946
|
+
};
|
|
19947
|
+
}
|
|
19948
|
+
const newUser = await this.createUser(input.email, input.userName, input.registrationInfo, input.context);
|
|
19949
|
+
const passwordHash = await this.createPasswordHash(input.password, newUser.id);
|
|
19950
|
+
await this.services.getUsersService().update(newUser.id, {
|
|
19951
|
+
passwordHash,
|
|
19952
|
+
passwordUpdateTimestamp: new Date(),
|
|
19953
|
+
verified: true,
|
|
19954
|
+
});
|
|
19955
|
+
this.logger.debug(`New user created: ${input.email} - ${input.userName}`, {
|
|
19956
|
+
user: newUser,
|
|
19957
|
+
});
|
|
19958
|
+
return {
|
|
19959
|
+
success: true,
|
|
19960
|
+
userId: newUser.id,
|
|
19961
|
+
};
|
|
19962
|
+
}
|
|
19963
|
+
async createPasswordHash(password, userId) {
|
|
19964
|
+
return await this.passwordHashingProvider.hashPassword({
|
|
19965
|
+
password,
|
|
19966
|
+
userId,
|
|
19967
|
+
});
|
|
19968
|
+
}
|
|
19969
|
+
async createUser(email, userName, info, context) {
|
|
19970
|
+
return await this.services
|
|
19971
|
+
.getUsersService()
|
|
19972
|
+
.create(email, userName, info, context);
|
|
19973
|
+
}
|
|
19974
|
+
async resolveUser(userName, context) {
|
|
19975
|
+
return ((await this.services
|
|
19976
|
+
.getUsersService()
|
|
19977
|
+
.getByUserName(userName, context)) ??
|
|
19978
|
+
(await this.services.getUsersService().getByEmail(userName, context)));
|
|
19979
|
+
}
|
|
19980
|
+
};
|
|
19981
|
+
UserCreationHandler = __decorate([
|
|
19982
|
+
common.Injectable(),
|
|
19983
|
+
__metadata("design:paramtypes", [AuthenticationServicesResolver,
|
|
19984
|
+
PasswordHashingProvider])
|
|
19985
|
+
], UserCreationHandler);
|
|
19986
|
+
|
|
19987
|
+
let UserDeleteHandler = class UserDeleteHandler {
|
|
19988
|
+
constructor(services) {
|
|
19989
|
+
this.services = services;
|
|
19990
|
+
}
|
|
19991
|
+
async execute(input) {
|
|
19992
|
+
await this.services.getUsersService().delete(input.userId);
|
|
19993
|
+
}
|
|
19994
|
+
};
|
|
19995
|
+
UserDeleteHandler = __decorate([
|
|
19996
|
+
common.Injectable(),
|
|
19997
|
+
__metadata("design:paramtypes", [AuthenticationServicesResolver])
|
|
19998
|
+
], UserDeleteHandler);
|
|
19999
|
+
|
|
19892
20000
|
exports.AuthenticationService = class AuthenticationService {
|
|
19893
|
-
constructor(userDisableHandler, userEnableHandler, userLoginHandler, userPasswordChangeHandler, userPasswordResetFinalizeHandler, userPasswordResetRequestHandler, userRegistrationHandler, userTokenVerifyHandler, userVerifyRequestHandler, userVerifyCompleteHandler, resolver) {
|
|
20001
|
+
constructor(userCreationHandler, userDisableHandler, userDeleteHandler, userEnableHandler, userLoginHandler, userPasswordChangeHandler, userPasswordResetFinalizeHandler, userPasswordResetRequestHandler, userRegistrationHandler, userTokenVerifyHandler, userVerifyRequestHandler, userVerifyCompleteHandler, resolver) {
|
|
20002
|
+
this.userCreationHandler = userCreationHandler;
|
|
19894
20003
|
this.userDisableHandler = userDisableHandler;
|
|
20004
|
+
this.userDeleteHandler = userDeleteHandler;
|
|
19895
20005
|
this.userEnableHandler = userEnableHandler;
|
|
19896
20006
|
this.userLoginHandler = userLoginHandler;
|
|
19897
20007
|
this.userPasswordChangeHandler = userPasswordChangeHandler;
|
|
@@ -19903,9 +20013,15 @@ exports.AuthenticationService = class AuthenticationService {
|
|
|
19903
20013
|
this.userVerifyCompleteHandler = userVerifyCompleteHandler;
|
|
19904
20014
|
this.resolver = resolver;
|
|
19905
20015
|
}
|
|
20016
|
+
async userCreate(input) {
|
|
20017
|
+
return await this.userCreationHandler.execute(input);
|
|
20018
|
+
}
|
|
19906
20019
|
async userDisable(input) {
|
|
19907
20020
|
await this.userDisableHandler.execute(input);
|
|
19908
20021
|
}
|
|
20022
|
+
async userDelete(input) {
|
|
20023
|
+
await this.userDeleteHandler.execute(input);
|
|
20024
|
+
}
|
|
19909
20025
|
async userEnable(input) {
|
|
19910
20026
|
await this.userEnableHandler.execute(input);
|
|
19911
20027
|
}
|
|
@@ -19945,7 +20061,9 @@ exports.AuthenticationService = class AuthenticationService {
|
|
|
19945
20061
|
};
|
|
19946
20062
|
exports.AuthenticationService = __decorate([
|
|
19947
20063
|
common.Injectable(),
|
|
19948
|
-
__metadata("design:paramtypes", [
|
|
20064
|
+
__metadata("design:paramtypes", [UserCreationHandler,
|
|
20065
|
+
UserDisableHandler,
|
|
20066
|
+
UserDeleteHandler,
|
|
19949
20067
|
UserEnableHandler,
|
|
19950
20068
|
UserLoginHandler,
|
|
19951
20069
|
UserPasswordChangeHandler,
|
|
@@ -20006,6 +20124,21 @@ const orderByPriority = (items, priorityFieldSelector, nameFieldSelector) => {
|
|
|
20006
20124
|
return backendCore.sort(items, backendCore.byField((x) => priorityFieldSelector(x) ?? Number.MAX_VALUE), backendCore.byField((x) => nameFieldSelector(x)));
|
|
20007
20125
|
};
|
|
20008
20126
|
|
|
20127
|
+
exports.PipelineStepErrorType = void 0;
|
|
20128
|
+
(function (PipelineStepErrorType) {
|
|
20129
|
+
PipelineStepErrorType["FailedPrecondition"] = "failedPrecondition";
|
|
20130
|
+
PipelineStepErrorType["OperationError"] = "operationError";
|
|
20131
|
+
PipelineStepErrorType["RollbackError"] = "rollbackError";
|
|
20132
|
+
PipelineStepErrorType["GenericError"] = "genericError";
|
|
20133
|
+
})(exports.PipelineStepErrorType || (exports.PipelineStepErrorType = {}));
|
|
20134
|
+
exports.PipelineErrorType = void 0;
|
|
20135
|
+
(function (PipelineErrorType) {
|
|
20136
|
+
PipelineErrorType["FailedPrecondition"] = "failedPrecondition";
|
|
20137
|
+
PipelineErrorType["OperationError"] = "operationError";
|
|
20138
|
+
PipelineErrorType["RollbackError"] = "rollbackError";
|
|
20139
|
+
PipelineErrorType["Unauthorized"] = "unauthorized";
|
|
20140
|
+
PipelineErrorType["GenericError"] = "genericError";
|
|
20141
|
+
})(exports.PipelineErrorType || (exports.PipelineErrorType = {}));
|
|
20009
20142
|
exports.PipelineStatus = void 0;
|
|
20010
20143
|
(function (PipelineStatus) {
|
|
20011
20144
|
PipelineStatus["Initializing"] = "initializing";
|
|
@@ -20025,6 +20158,18 @@ const getStepOutput = (result) => {
|
|
|
20025
20158
|
const getOperationOutput = (result) => {
|
|
20026
20159
|
return result.type === "success" ? result.output : undefined;
|
|
20027
20160
|
};
|
|
20161
|
+
const mapPipelineErrorType = (stepError) => {
|
|
20162
|
+
switch (stepError) {
|
|
20163
|
+
case exports.PipelineStepErrorType.FailedPrecondition:
|
|
20164
|
+
return exports.PipelineErrorType.FailedPrecondition;
|
|
20165
|
+
case exports.PipelineStepErrorType.OperationError:
|
|
20166
|
+
return exports.PipelineErrorType.OperationError;
|
|
20167
|
+
case exports.PipelineStepErrorType.RollbackError:
|
|
20168
|
+
return exports.PipelineErrorType.RollbackError;
|
|
20169
|
+
case exports.PipelineStepErrorType.GenericError:
|
|
20170
|
+
return exports.PipelineErrorType.GenericError;
|
|
20171
|
+
}
|
|
20172
|
+
};
|
|
20028
20173
|
|
|
20029
20174
|
class PipelineInstance {
|
|
20030
20175
|
constructor(definition, input, context) {
|
|
@@ -20048,6 +20193,7 @@ class PipelineInstance {
|
|
|
20048
20193
|
await this.rollbackSteps(executedSteps, stepResults, state);
|
|
20049
20194
|
return {
|
|
20050
20195
|
type: "error",
|
|
20196
|
+
errorType: mapPipelineErrorType(stepResult.errorType),
|
|
20051
20197
|
input: this.input,
|
|
20052
20198
|
stepResults,
|
|
20053
20199
|
};
|
|
@@ -20127,7 +20273,8 @@ class PipelineInstance {
|
|
|
20127
20273
|
if (!preconditionResult.hasValidPrecondition) {
|
|
20128
20274
|
return {
|
|
20129
20275
|
operationResults: [],
|
|
20130
|
-
type: "
|
|
20276
|
+
type: "error",
|
|
20277
|
+
errorType: exports.PipelineStepErrorType.FailedPrecondition,
|
|
20131
20278
|
input,
|
|
20132
20279
|
};
|
|
20133
20280
|
}
|
|
@@ -20147,6 +20294,7 @@ class PipelineInstance {
|
|
|
20147
20294
|
}
|
|
20148
20295
|
return {
|
|
20149
20296
|
type: "error",
|
|
20297
|
+
errorType: exports.PipelineStepErrorType.OperationError,
|
|
20150
20298
|
operationResults,
|
|
20151
20299
|
input,
|
|
20152
20300
|
};
|
|
@@ -20444,7 +20592,7 @@ class PipelineStepBuilder {
|
|
|
20444
20592
|
},
|
|
20445
20593
|
};
|
|
20446
20594
|
}
|
|
20447
|
-
|
|
20595
|
+
complete() {
|
|
20448
20596
|
return {
|
|
20449
20597
|
steps: this.currentSteps,
|
|
20450
20598
|
};
|
|
@@ -20497,7 +20645,19 @@ exports.PipelinesRunner = __decorate([
|
|
|
20497
20645
|
|
|
20498
20646
|
const PipelineProviders = [exports.PipelinesBuilder, exports.PipelinesRunner];
|
|
20499
20647
|
|
|
20648
|
+
// export const iocStorage = new AsyncLocalStorage<IocContext>()
|
|
20649
|
+
const initializeIoCContext = (context) => {
|
|
20650
|
+
};
|
|
20651
|
+
|
|
20500
20652
|
exports.EntityManagerModule = class EntityManagerModule {
|
|
20653
|
+
constructor(registry) {
|
|
20654
|
+
this.registry = registry;
|
|
20655
|
+
}
|
|
20656
|
+
onModuleInit() {
|
|
20657
|
+
initializeIoCContext({
|
|
20658
|
+
registry: this.registry,
|
|
20659
|
+
});
|
|
20660
|
+
}
|
|
20501
20661
|
};
|
|
20502
20662
|
exports.EntityManagerModule = __decorate([
|
|
20503
20663
|
common.Module({
|
|
@@ -20510,11 +20670,14 @@ exports.EntityManagerModule = __decorate([
|
|
|
20510
20670
|
...PipelineProviders,
|
|
20511
20671
|
],
|
|
20512
20672
|
exports: [exports.EntityManagerRegistry, ...Services$1],
|
|
20513
|
-
})
|
|
20673
|
+
}),
|
|
20674
|
+
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
20514
20675
|
], exports.EntityManagerModule);
|
|
20515
20676
|
|
|
20516
20677
|
const UserHandlers = [
|
|
20678
|
+
UserCreationHandler,
|
|
20517
20679
|
UserDisableHandler,
|
|
20680
|
+
UserDeleteHandler,
|
|
20518
20681
|
UserEnableHandler,
|
|
20519
20682
|
UserLoginHandler,
|
|
20520
20683
|
UserPasswordChangeHandler,
|
|
@@ -20609,7 +20772,7 @@ class AppSession {
|
|
|
20609
20772
|
|
|
20610
20773
|
exports.AppSessionMiddleware = class AppSessionMiddleware {
|
|
20611
20774
|
use(req, res, next) {
|
|
20612
|
-
|
|
20775
|
+
sessionStorage.run(new AppSession(req, res), () => {
|
|
20613
20776
|
next();
|
|
20614
20777
|
});
|
|
20615
20778
|
}
|
|
@@ -20618,7 +20781,7 @@ exports.AppSessionMiddleware = __decorate([
|
|
|
20618
20781
|
common.Injectable()
|
|
20619
20782
|
], exports.AppSessionMiddleware);
|
|
20620
20783
|
function appSessionMiddleware(req, res, next) {
|
|
20621
|
-
|
|
20784
|
+
sessionStorage.run(new AppSession(req, res), () => {
|
|
20622
20785
|
next();
|
|
20623
20786
|
});
|
|
20624
20787
|
}
|
|
@@ -20974,6 +21137,14 @@ class NestTypeOrmEntitySeeder extends TypeOrmEntitySeeder {
|
|
|
20974
21137
|
}
|
|
20975
21138
|
}
|
|
20976
21139
|
|
|
21140
|
+
class PipelineInvocationError extends Error {
|
|
21141
|
+
constructor(errorType, innerError, message) {
|
|
21142
|
+
super(message ?? innerError?.message);
|
|
21143
|
+
this.errorType = errorType;
|
|
21144
|
+
this.innerError = innerError;
|
|
21145
|
+
}
|
|
21146
|
+
}
|
|
21147
|
+
|
|
20977
21148
|
class AppExceptionsFilterBase {
|
|
20978
21149
|
catch(exception, host) {
|
|
20979
21150
|
const ctx = host.switchToHttp();
|
|
@@ -21009,6 +21180,16 @@ class AppExceptionsFilterBase {
|
|
|
21009
21180
|
if (exception instanceof common.HttpException) {
|
|
21010
21181
|
return exception.getStatus();
|
|
21011
21182
|
}
|
|
21183
|
+
if (exception instanceof PipelineInvocationError) {
|
|
21184
|
+
switch (exception.errorType) {
|
|
21185
|
+
case exports.PipelineErrorType.Unauthorized:
|
|
21186
|
+
return common.HttpStatus.UNAUTHORIZED;
|
|
21187
|
+
case exports.PipelineErrorType.FailedPrecondition:
|
|
21188
|
+
return common.HttpStatus.PRECONDITION_FAILED;
|
|
21189
|
+
default:
|
|
21190
|
+
return common.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
21191
|
+
}
|
|
21192
|
+
}
|
|
21012
21193
|
return common.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
21013
21194
|
}
|
|
21014
21195
|
}
|