@punks/backend-entity-manager 0.0.72 → 0.0.73
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/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/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/esm/index.js
CHANGED
|
@@ -425,7 +425,12 @@ AuthGuard = __decorate([
|
|
|
425
425
|
__metadata("design:paramtypes", [Reflector])
|
|
426
426
|
], AuthGuard);
|
|
427
427
|
|
|
428
|
-
|
|
428
|
+
var UserCreationError;
|
|
429
|
+
(function (UserCreationError) {
|
|
430
|
+
UserCreationError["UserAlreadyExists"] = "userAlreadyExists";
|
|
431
|
+
})(UserCreationError || (UserCreationError = {}));
|
|
432
|
+
|
|
433
|
+
const sessionStorage = new AsyncLocalStorage();
|
|
429
434
|
|
|
430
435
|
let AppSessionService = class AppSessionService {
|
|
431
436
|
getValue(key) {
|
|
@@ -441,7 +446,7 @@ let AppSessionService = class AppSessionService {
|
|
|
441
446
|
return this.getSession().request;
|
|
442
447
|
}
|
|
443
448
|
getSession() {
|
|
444
|
-
const store =
|
|
449
|
+
const store = sessionStorage.getStore();
|
|
445
450
|
if (!store) {
|
|
446
451
|
throw new Error("No active context found");
|
|
447
452
|
}
|
|
@@ -602,7 +607,10 @@ class EntityCreateCommand {
|
|
|
602
607
|
return;
|
|
603
608
|
}
|
|
604
609
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
605
|
-
const context = await contextService
|
|
610
|
+
const context = await contextService?.getContext();
|
|
611
|
+
if (!context) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
606
614
|
const authorizationResult = await authorization.canCreate(entity, context);
|
|
607
615
|
if (!authorizationResult.isAuthorized)
|
|
608
616
|
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), entity);
|
|
@@ -628,7 +636,10 @@ class EntityDeleteCommand {
|
|
|
628
636
|
throw new EntityNotFoundException(id);
|
|
629
637
|
}
|
|
630
638
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
631
|
-
const context = await contextService
|
|
639
|
+
const context = await contextService?.getContext();
|
|
640
|
+
if (!context) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
632
643
|
const authorizationResult = await authorization.canDelete(entity, context);
|
|
633
644
|
if (!authorizationResult.isAuthorized)
|
|
634
645
|
throw new EntityOperationUnauthorizedException(EntityOperationType.Delete, this.services.getEntityName(), entity);
|
|
@@ -662,7 +673,10 @@ class EntitiesDeleteCommand {
|
|
|
662
673
|
return;
|
|
663
674
|
}
|
|
664
675
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
665
|
-
const context = await contextService
|
|
676
|
+
const context = await contextService?.getContext();
|
|
677
|
+
if (!context) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
666
680
|
const authorizationResult = await authorization.canDeleteItems(context);
|
|
667
681
|
if (!authorizationResult.isAuthorized)
|
|
668
682
|
throw new EntityOperationUnauthorizedException(EntityOperationType.Delete, this.services.getEntityName());
|
|
@@ -700,7 +714,10 @@ class EntityUpdateCommand {
|
|
|
700
714
|
throw new EntityNotFoundException();
|
|
701
715
|
}
|
|
702
716
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
703
|
-
const context = await contextService
|
|
717
|
+
const context = await contextService?.getContext();
|
|
718
|
+
if (!context) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
704
721
|
const authorizationResult = await authorization.canUpdate(currentEntity, context);
|
|
705
722
|
if (!authorizationResult.isAuthorized)
|
|
706
723
|
throw new EntityOperationUnauthorizedException(EntityOperationType.Create, this.services.getEntityName(), currentEntity);
|
|
@@ -736,7 +753,10 @@ class EntityUpsertCommand {
|
|
|
736
753
|
}
|
|
737
754
|
const currentEntity = await this.services.resolveRepository().get(id);
|
|
738
755
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
739
|
-
const context = await contextService
|
|
756
|
+
const context = await contextService?.getContext();
|
|
757
|
+
if (!context) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
740
760
|
if (currentEntity) {
|
|
741
761
|
const updateResult = await authorization.canUpdate(currentEntity, context);
|
|
742
762
|
if (!updateResult.isAuthorized)
|
|
@@ -1079,7 +1099,9 @@ class EntitiesServiceLocator {
|
|
|
1079
1099
|
this.provider.register(GlobalServices.Pipelines.IPipelineController, instance);
|
|
1080
1100
|
}
|
|
1081
1101
|
resolveAuthenticationContextProvider() {
|
|
1082
|
-
return this.provider.resolve(GlobalServices.Authentication.IAuthenticationContextProvider
|
|
1102
|
+
return this.provider.resolve(GlobalServices.Authentication.IAuthenticationContextProvider, {
|
|
1103
|
+
optional: true,
|
|
1104
|
+
});
|
|
1083
1105
|
}
|
|
1084
1106
|
registerAuthenticationContextProvider(instance) {
|
|
1085
1107
|
this.provider.register(GlobalServices.Authentication.IAuthenticationContextProvider, instance);
|
|
@@ -1391,7 +1413,10 @@ class EntityGetQuery {
|
|
|
1391
1413
|
return;
|
|
1392
1414
|
}
|
|
1393
1415
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1394
|
-
const context = await contextService
|
|
1416
|
+
const context = await contextService?.getContext();
|
|
1417
|
+
if (!context) {
|
|
1418
|
+
return;
|
|
1419
|
+
}
|
|
1395
1420
|
const authorizationResult = await authorization.canRead(entity, context);
|
|
1396
1421
|
if (!authorizationResult.isAuthorized)
|
|
1397
1422
|
throw new EntityOperationUnauthorizedException(EntityOperationType.Read, this.services.getEntityName(), entity);
|
|
@@ -1426,7 +1451,7 @@ class EntitiesSearchQuery {
|
|
|
1426
1451
|
return undefined;
|
|
1427
1452
|
}
|
|
1428
1453
|
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1429
|
-
return await contextService
|
|
1454
|
+
return await contextService?.getContext();
|
|
1430
1455
|
}
|
|
1431
1456
|
async filterAllowedEntities(entities, context) {
|
|
1432
1457
|
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
@@ -19505,7 +19530,7 @@ let UserRegistrationHandler = class UserRegistrationHandler {
|
|
|
19505
19530
|
userId: user.id,
|
|
19506
19531
|
};
|
|
19507
19532
|
}
|
|
19508
|
-
const newUser = await this.createUser(input.email, input.registrationInfo, input.context);
|
|
19533
|
+
const newUser = await this.createUser(input.email, input.userName, input.registrationInfo, input.context);
|
|
19509
19534
|
const passwordHash = await this.createPasswordHash(input.password, newUser.id);
|
|
19510
19535
|
await this.services.getUsersService().update(newUser.id, {
|
|
19511
19536
|
passwordHash,
|
|
@@ -19546,8 +19571,10 @@ let UserRegistrationHandler = class UserRegistrationHandler {
|
|
|
19546
19571
|
timestamp: Date.now(),
|
|
19547
19572
|
});
|
|
19548
19573
|
}
|
|
19549
|
-
async createUser(email, info, context) {
|
|
19550
|
-
return await this.services
|
|
19574
|
+
async createUser(email, userName, info, context) {
|
|
19575
|
+
return await this.services
|
|
19576
|
+
.getUsersService()
|
|
19577
|
+
.create(email, userName, info, context);
|
|
19551
19578
|
}
|
|
19552
19579
|
async resolveUser(userName, context) {
|
|
19553
19580
|
return ((await this.services
|
|
@@ -19881,9 +19908,92 @@ UserVerifyRequestHandler = __decorate([
|
|
|
19881
19908
|
JwtProvider])
|
|
19882
19909
|
], UserVerifyRequestHandler);
|
|
19883
19910
|
|
|
19911
|
+
let UserCreationHandler = class UserCreationHandler {
|
|
19912
|
+
constructor(services, passwordHashingProvider) {
|
|
19913
|
+
this.services = services;
|
|
19914
|
+
this.passwordHashingProvider = passwordHashingProvider;
|
|
19915
|
+
this.logger = Log.getLogger("UserCreation");
|
|
19916
|
+
}
|
|
19917
|
+
async execute(input) {
|
|
19918
|
+
const user = (await this.resolveUser(input.email, input.context)) ??
|
|
19919
|
+
(await this.resolveUser(input.userName, input.context));
|
|
19920
|
+
if (user && user.verified) {
|
|
19921
|
+
this.logger.debug(`User already exists: ${input.email} - ${input.userName}`, { user });
|
|
19922
|
+
return {
|
|
19923
|
+
success: false,
|
|
19924
|
+
error: UserCreationError.UserAlreadyExists,
|
|
19925
|
+
};
|
|
19926
|
+
}
|
|
19927
|
+
if (user && !user.verified) {
|
|
19928
|
+
const passwordHash = await this.createPasswordHash(input.password, user.id);
|
|
19929
|
+
await this.services.getUsersService().update(user.id, {
|
|
19930
|
+
passwordHash,
|
|
19931
|
+
passwordUpdateTimestamp: new Date(),
|
|
19932
|
+
verified: true,
|
|
19933
|
+
});
|
|
19934
|
+
this.logger.debug(`User already exists but not verified. Updating password and marking as verified: ${input.email} - ${input.userName}`, { user });
|
|
19935
|
+
return {
|
|
19936
|
+
success: true,
|
|
19937
|
+
userId: user.id,
|
|
19938
|
+
};
|
|
19939
|
+
}
|
|
19940
|
+
const newUser = await this.createUser(input.email, input.userName, input.registrationInfo, input.context);
|
|
19941
|
+
const passwordHash = await this.createPasswordHash(input.password, newUser.id);
|
|
19942
|
+
await this.services.getUsersService().update(newUser.id, {
|
|
19943
|
+
passwordHash,
|
|
19944
|
+
passwordUpdateTimestamp: new Date(),
|
|
19945
|
+
verified: true,
|
|
19946
|
+
});
|
|
19947
|
+
this.logger.debug(`New user created: ${input.email} - ${input.userName}`, {
|
|
19948
|
+
user: newUser,
|
|
19949
|
+
});
|
|
19950
|
+
return {
|
|
19951
|
+
success: true,
|
|
19952
|
+
userId: newUser.id,
|
|
19953
|
+
};
|
|
19954
|
+
}
|
|
19955
|
+
async createPasswordHash(password, userId) {
|
|
19956
|
+
return await this.passwordHashingProvider.hashPassword({
|
|
19957
|
+
password,
|
|
19958
|
+
userId,
|
|
19959
|
+
});
|
|
19960
|
+
}
|
|
19961
|
+
async createUser(email, userName, info, context) {
|
|
19962
|
+
return await this.services
|
|
19963
|
+
.getUsersService()
|
|
19964
|
+
.create(email, userName, info, context);
|
|
19965
|
+
}
|
|
19966
|
+
async resolveUser(userName, context) {
|
|
19967
|
+
return ((await this.services
|
|
19968
|
+
.getUsersService()
|
|
19969
|
+
.getByUserName(userName, context)) ??
|
|
19970
|
+
(await this.services.getUsersService().getByEmail(userName, context)));
|
|
19971
|
+
}
|
|
19972
|
+
};
|
|
19973
|
+
UserCreationHandler = __decorate([
|
|
19974
|
+
Injectable(),
|
|
19975
|
+
__metadata("design:paramtypes", [AuthenticationServicesResolver,
|
|
19976
|
+
PasswordHashingProvider])
|
|
19977
|
+
], UserCreationHandler);
|
|
19978
|
+
|
|
19979
|
+
let UserDeleteHandler = class UserDeleteHandler {
|
|
19980
|
+
constructor(services) {
|
|
19981
|
+
this.services = services;
|
|
19982
|
+
}
|
|
19983
|
+
async execute(input) {
|
|
19984
|
+
await this.services.getUsersService().delete(input.userId);
|
|
19985
|
+
}
|
|
19986
|
+
};
|
|
19987
|
+
UserDeleteHandler = __decorate([
|
|
19988
|
+
Injectable(),
|
|
19989
|
+
__metadata("design:paramtypes", [AuthenticationServicesResolver])
|
|
19990
|
+
], UserDeleteHandler);
|
|
19991
|
+
|
|
19884
19992
|
let AuthenticationService = class AuthenticationService {
|
|
19885
|
-
constructor(userDisableHandler, userEnableHandler, userLoginHandler, userPasswordChangeHandler, userPasswordResetFinalizeHandler, userPasswordResetRequestHandler, userRegistrationHandler, userTokenVerifyHandler, userVerifyRequestHandler, userVerifyCompleteHandler, resolver) {
|
|
19993
|
+
constructor(userCreationHandler, userDisableHandler, userDeleteHandler, userEnableHandler, userLoginHandler, userPasswordChangeHandler, userPasswordResetFinalizeHandler, userPasswordResetRequestHandler, userRegistrationHandler, userTokenVerifyHandler, userVerifyRequestHandler, userVerifyCompleteHandler, resolver) {
|
|
19994
|
+
this.userCreationHandler = userCreationHandler;
|
|
19886
19995
|
this.userDisableHandler = userDisableHandler;
|
|
19996
|
+
this.userDeleteHandler = userDeleteHandler;
|
|
19887
19997
|
this.userEnableHandler = userEnableHandler;
|
|
19888
19998
|
this.userLoginHandler = userLoginHandler;
|
|
19889
19999
|
this.userPasswordChangeHandler = userPasswordChangeHandler;
|
|
@@ -19895,9 +20005,15 @@ let AuthenticationService = class AuthenticationService {
|
|
|
19895
20005
|
this.userVerifyCompleteHandler = userVerifyCompleteHandler;
|
|
19896
20006
|
this.resolver = resolver;
|
|
19897
20007
|
}
|
|
20008
|
+
async userCreate(input) {
|
|
20009
|
+
return await this.userCreationHandler.execute(input);
|
|
20010
|
+
}
|
|
19898
20011
|
async userDisable(input) {
|
|
19899
20012
|
await this.userDisableHandler.execute(input);
|
|
19900
20013
|
}
|
|
20014
|
+
async userDelete(input) {
|
|
20015
|
+
await this.userDeleteHandler.execute(input);
|
|
20016
|
+
}
|
|
19901
20017
|
async userEnable(input) {
|
|
19902
20018
|
await this.userEnableHandler.execute(input);
|
|
19903
20019
|
}
|
|
@@ -19937,7 +20053,9 @@ let AuthenticationService = class AuthenticationService {
|
|
|
19937
20053
|
};
|
|
19938
20054
|
AuthenticationService = __decorate([
|
|
19939
20055
|
Injectable(),
|
|
19940
|
-
__metadata("design:paramtypes", [
|
|
20056
|
+
__metadata("design:paramtypes", [UserCreationHandler,
|
|
20057
|
+
UserDisableHandler,
|
|
20058
|
+
UserDeleteHandler,
|
|
19941
20059
|
UserEnableHandler,
|
|
19942
20060
|
UserLoginHandler,
|
|
19943
20061
|
UserPasswordChangeHandler,
|
|
@@ -19998,6 +20116,21 @@ const orderByPriority = (items, priorityFieldSelector, nameFieldSelector) => {
|
|
|
19998
20116
|
return sort(items, byField((x) => priorityFieldSelector(x) ?? Number.MAX_VALUE), byField((x) => nameFieldSelector(x)));
|
|
19999
20117
|
};
|
|
20000
20118
|
|
|
20119
|
+
var PipelineStepErrorType;
|
|
20120
|
+
(function (PipelineStepErrorType) {
|
|
20121
|
+
PipelineStepErrorType["FailedPrecondition"] = "failedPrecondition";
|
|
20122
|
+
PipelineStepErrorType["OperationError"] = "operationError";
|
|
20123
|
+
PipelineStepErrorType["RollbackError"] = "rollbackError";
|
|
20124
|
+
PipelineStepErrorType["GenericError"] = "genericError";
|
|
20125
|
+
})(PipelineStepErrorType || (PipelineStepErrorType = {}));
|
|
20126
|
+
var PipelineErrorType;
|
|
20127
|
+
(function (PipelineErrorType) {
|
|
20128
|
+
PipelineErrorType["FailedPrecondition"] = "failedPrecondition";
|
|
20129
|
+
PipelineErrorType["OperationError"] = "operationError";
|
|
20130
|
+
PipelineErrorType["RollbackError"] = "rollbackError";
|
|
20131
|
+
PipelineErrorType["Unauthorized"] = "unauthorized";
|
|
20132
|
+
PipelineErrorType["GenericError"] = "genericError";
|
|
20133
|
+
})(PipelineErrorType || (PipelineErrorType = {}));
|
|
20001
20134
|
var PipelineStatus;
|
|
20002
20135
|
(function (PipelineStatus) {
|
|
20003
20136
|
PipelineStatus["Initializing"] = "initializing";
|
|
@@ -20017,6 +20150,18 @@ const getStepOutput = (result) => {
|
|
|
20017
20150
|
const getOperationOutput = (result) => {
|
|
20018
20151
|
return result.type === "success" ? result.output : undefined;
|
|
20019
20152
|
};
|
|
20153
|
+
const mapPipelineErrorType = (stepError) => {
|
|
20154
|
+
switch (stepError) {
|
|
20155
|
+
case PipelineStepErrorType.FailedPrecondition:
|
|
20156
|
+
return PipelineErrorType.FailedPrecondition;
|
|
20157
|
+
case PipelineStepErrorType.OperationError:
|
|
20158
|
+
return PipelineErrorType.OperationError;
|
|
20159
|
+
case PipelineStepErrorType.RollbackError:
|
|
20160
|
+
return PipelineErrorType.RollbackError;
|
|
20161
|
+
case PipelineStepErrorType.GenericError:
|
|
20162
|
+
return PipelineErrorType.GenericError;
|
|
20163
|
+
}
|
|
20164
|
+
};
|
|
20020
20165
|
|
|
20021
20166
|
class PipelineInstance {
|
|
20022
20167
|
constructor(definition, input, context) {
|
|
@@ -20040,6 +20185,7 @@ class PipelineInstance {
|
|
|
20040
20185
|
await this.rollbackSteps(executedSteps, stepResults, state);
|
|
20041
20186
|
return {
|
|
20042
20187
|
type: "error",
|
|
20188
|
+
errorType: mapPipelineErrorType(stepResult.errorType),
|
|
20043
20189
|
input: this.input,
|
|
20044
20190
|
stepResults,
|
|
20045
20191
|
};
|
|
@@ -20119,7 +20265,8 @@ class PipelineInstance {
|
|
|
20119
20265
|
if (!preconditionResult.hasValidPrecondition) {
|
|
20120
20266
|
return {
|
|
20121
20267
|
operationResults: [],
|
|
20122
|
-
type: "
|
|
20268
|
+
type: "error",
|
|
20269
|
+
errorType: PipelineStepErrorType.FailedPrecondition,
|
|
20123
20270
|
input,
|
|
20124
20271
|
};
|
|
20125
20272
|
}
|
|
@@ -20139,6 +20286,7 @@ class PipelineInstance {
|
|
|
20139
20286
|
}
|
|
20140
20287
|
return {
|
|
20141
20288
|
type: "error",
|
|
20289
|
+
errorType: PipelineStepErrorType.OperationError,
|
|
20142
20290
|
operationResults,
|
|
20143
20291
|
input,
|
|
20144
20292
|
};
|
|
@@ -20436,7 +20584,7 @@ class PipelineStepBuilder {
|
|
|
20436
20584
|
},
|
|
20437
20585
|
};
|
|
20438
20586
|
}
|
|
20439
|
-
|
|
20587
|
+
complete() {
|
|
20440
20588
|
return {
|
|
20441
20589
|
steps: this.currentSteps,
|
|
20442
20590
|
};
|
|
@@ -20489,7 +20637,19 @@ PipelinesRunner = __decorate([
|
|
|
20489
20637
|
|
|
20490
20638
|
const PipelineProviders = [PipelinesBuilder, PipelinesRunner];
|
|
20491
20639
|
|
|
20640
|
+
// export const iocStorage = new AsyncLocalStorage<IocContext>()
|
|
20641
|
+
const initializeIoCContext = (context) => {
|
|
20642
|
+
};
|
|
20643
|
+
|
|
20492
20644
|
let EntityManagerModule = class EntityManagerModule {
|
|
20645
|
+
constructor(registry) {
|
|
20646
|
+
this.registry = registry;
|
|
20647
|
+
}
|
|
20648
|
+
onModuleInit() {
|
|
20649
|
+
initializeIoCContext({
|
|
20650
|
+
registry: this.registry,
|
|
20651
|
+
});
|
|
20652
|
+
}
|
|
20493
20653
|
};
|
|
20494
20654
|
EntityManagerModule = __decorate([
|
|
20495
20655
|
Module({
|
|
@@ -20502,11 +20662,14 @@ EntityManagerModule = __decorate([
|
|
|
20502
20662
|
...PipelineProviders,
|
|
20503
20663
|
],
|
|
20504
20664
|
exports: [EntityManagerRegistry, ...Services$1],
|
|
20505
|
-
})
|
|
20665
|
+
}),
|
|
20666
|
+
__metadata("design:paramtypes", [EntityManagerRegistry])
|
|
20506
20667
|
], EntityManagerModule);
|
|
20507
20668
|
|
|
20508
20669
|
const UserHandlers = [
|
|
20670
|
+
UserCreationHandler,
|
|
20509
20671
|
UserDisableHandler,
|
|
20672
|
+
UserDeleteHandler,
|
|
20510
20673
|
UserEnableHandler,
|
|
20511
20674
|
UserLoginHandler,
|
|
20512
20675
|
UserPasswordChangeHandler,
|
|
@@ -20601,7 +20764,7 @@ class AppSession {
|
|
|
20601
20764
|
|
|
20602
20765
|
let AppSessionMiddleware = class AppSessionMiddleware {
|
|
20603
20766
|
use(req, res, next) {
|
|
20604
|
-
|
|
20767
|
+
sessionStorage.run(new AppSession(req, res), () => {
|
|
20605
20768
|
next();
|
|
20606
20769
|
});
|
|
20607
20770
|
}
|
|
@@ -20610,7 +20773,7 @@ AppSessionMiddleware = __decorate([
|
|
|
20610
20773
|
Injectable()
|
|
20611
20774
|
], AppSessionMiddleware);
|
|
20612
20775
|
function appSessionMiddleware(req, res, next) {
|
|
20613
|
-
|
|
20776
|
+
sessionStorage.run(new AppSession(req, res), () => {
|
|
20614
20777
|
next();
|
|
20615
20778
|
});
|
|
20616
20779
|
}
|
|
@@ -20966,6 +21129,14 @@ class NestTypeOrmEntitySeeder extends TypeOrmEntitySeeder {
|
|
|
20966
21129
|
}
|
|
20967
21130
|
}
|
|
20968
21131
|
|
|
21132
|
+
class PipelineInvocationError extends Error {
|
|
21133
|
+
constructor(errorType, innerError, message) {
|
|
21134
|
+
super(message ?? innerError?.message);
|
|
21135
|
+
this.errorType = errorType;
|
|
21136
|
+
this.innerError = innerError;
|
|
21137
|
+
}
|
|
21138
|
+
}
|
|
21139
|
+
|
|
20969
21140
|
class AppExceptionsFilterBase {
|
|
20970
21141
|
catch(exception, host) {
|
|
20971
21142
|
const ctx = host.switchToHttp();
|
|
@@ -21001,6 +21172,16 @@ class AppExceptionsFilterBase {
|
|
|
21001
21172
|
if (exception instanceof HttpException) {
|
|
21002
21173
|
return exception.getStatus();
|
|
21003
21174
|
}
|
|
21175
|
+
if (exception instanceof PipelineInvocationError) {
|
|
21176
|
+
switch (exception.errorType) {
|
|
21177
|
+
case PipelineErrorType.Unauthorized:
|
|
21178
|
+
return HttpStatus.UNAUTHORIZED;
|
|
21179
|
+
case PipelineErrorType.FailedPrecondition:
|
|
21180
|
+
return HttpStatus.PRECONDITION_FAILED;
|
|
21181
|
+
default:
|
|
21182
|
+
return HttpStatus.INTERNAL_SERVER_ERROR;
|
|
21183
|
+
}
|
|
21184
|
+
}
|
|
21004
21185
|
return HttpStatus.INTERNAL_SERVER_ERROR;
|
|
21005
21186
|
}
|
|
21006
21187
|
}
|
|
@@ -26219,5 +26400,5 @@ SendgridEmailModule = SendgridEmailModule_1 = __decorate([
|
|
|
26219
26400
|
})
|
|
26220
26401
|
], SendgridEmailModule);
|
|
26221
26402
|
|
|
26222
|
-
export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsEmailModule, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EventsService, InvalidCredentialsError, MemberOf, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, NumericFacet, NumericFacetItem, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, PipelineController, PipelineStatus, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, ReplicationMode, Roles, SendgridEmailModule, SendgridEmailTemplate, SortDirection, StringFacet, StringFacetItem, TrackingService, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, getLocalizedText, newUuid, renderHandlebarsTemplate };
|
|
26403
|
+
export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsEmailModule, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EventsService, InvalidCredentialsError, MemberOf, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, NumericFacet, NumericFacetItem, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, PipelineController, PipelineErrorType, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, ReplicationMode, Roles, SendgridEmailModule, SendgridEmailTemplate, SortDirection, StringFacet, StringFacetItem, TrackingService, UserCreationError, UserRegistrationError, WpAppInitializer, WpAwsSesEmailTemplate, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, getLocalizedText, newUuid, renderHandlebarsTemplate };
|
|
26223
26404
|
//# sourceMappingURL=index.js.map
|