@punks/backend-entity-manager 0.0.109 → 0.0.111

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.
@@ -0,0 +1,6 @@
1
+ import { IAuthRole, IAuthUser } from "../abstractions";
2
+ export type CurrentUserData = {
3
+ user: IAuthUser;
4
+ roles: IAuthRole[];
5
+ };
6
+ export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -1,3 +1,4 @@
1
+ export { CurrentUser, CurrentUserData } from "./currentUser";
1
2
  export { Authenticated, MemberOf, Public, Roles, buildRolesGuard, } from "./guards";
2
3
  export { AuthenticationExtensionSymbols } from "./symbols";
3
4
  export { WpRolesService } from "./rolesService";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Log, csvParse, excelParse, excelBuild, csvBuild, isNullOrUndefined, sort, byField, toDict, newUuid as newUuid$1, ensureTailingSlash, removeUndefinedProps } from '@punks/backend-core';
2
- import { applyDecorators, Injectable, SetMetadata, Global, Module, Scope, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
2
+ import { applyDecorators, Injectable, SetMetadata, createParamDecorator, Global, Module, Scope, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
3
3
  import { ApiProperty } from '@nestjs/swagger';
4
4
  import { Reflector } from '@nestjs/core';
5
5
  import { AsyncLocalStorage } from 'async_hooks';
@@ -2334,6 +2334,19 @@ __decorate([
2334
2334
  __metadata("design:type", Array)
2335
2335
  ], StringFacet.prototype, "items", void 0);
2336
2336
 
2337
+ const CurrentUser = createParamDecorator((data, context) => {
2338
+ const request = context.switchToHttp().getRequest();
2339
+ if (!request.auth) {
2340
+ return undefined;
2341
+ }
2342
+ const user = request.auth.user;
2343
+ const roles = request.auth.roles;
2344
+ return {
2345
+ user,
2346
+ roles,
2347
+ };
2348
+ });
2349
+
2337
2350
  const AuthenticationExtensionSymbols = {
2338
2351
  UserService: Symbol.for("WP.EXT:AUTHENTICATION.USER_SERVICE"),
2339
2352
  RolesService: Symbol.for("WP.EXT:AUTHENTICATION.ROLES_SERVICE"),
@@ -2434,14 +2447,15 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
2434
2447
  });
2435
2448
  return isAuthenticated;
2436
2449
  }
2437
- this.logger.debug(`Authorized:false -> auth guard`, {
2450
+ const isAuthenticated = !!auth?.user;
2451
+ this.logger.debug(`Authorized:${isAuthenticated} -> auth guard`, {
2438
2452
  ...this.getContextInfo({
2439
2453
  context,
2440
2454
  roles: auth?.roles,
2441
2455
  user: auth?.user,
2442
2456
  }),
2443
2457
  });
2444
- return false;
2458
+ return isAuthenticated;
2445
2459
  }
2446
2460
  isRoleMatching(allowedRoles, userRoles) {
2447
2461
  return userRoles.some((role) => allowedRoles.includes(role.uid));
@@ -2478,14 +2492,16 @@ let AuthGuard = AuthGuard_1 = class AuthGuard {
2478
2492
  },
2479
2493
  ...(user
2480
2494
  ? {
2481
- id: user.id,
2482
- userName: user.userName,
2483
- email: user.email,
2484
- roles: roles?.map((role) => ({
2485
- id: role.id,
2486
- name: role.name,
2487
- uid: role.uid,
2488
- })),
2495
+ user: {
2496
+ id: user.id,
2497
+ userName: user.userName,
2498
+ email: user.email,
2499
+ roles: roles?.map((role) => ({
2500
+ id: role.id,
2501
+ name: role.name,
2502
+ uid: role.uid,
2503
+ })),
2504
+ },
2489
2505
  }
2490
2506
  : {}),
2491
2507
  };
@@ -27683,5 +27699,5 @@ InMemoryEmailProvider = __decorate([
27683
27699
  WpEmailProvider("in-memory")
27684
27700
  ], InMemoryEmailProvider);
27685
27701
 
27686
- export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsEmailModule, AwsS2BucketError, AwsS3BucketProvider, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, BucketItemType, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntityVersionOperation, EventsService, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InvalidCredentialsError, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestPipelineTemplate, 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, WpBucketProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntityVersioningProvider, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, buildRolesGuard, createContainer, createExpressFileResponse, getLocalizedText, newUuid, renderHandlebarsTemplate, toEntitiesImportInput };
27702
+ export { AUTHENTICATION_EVENTS_NAMESPACE, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsEmailModule, AwsS2BucketError, AwsS3BucketProvider, AwsSesEmailTemplate, BooleanFacet, BooleanFacetItem, BucketItemType, CurrentUser, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntityVersionOperation, EventsService, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InvalidCredentialsError, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestPipelineTemplate, 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, WpBucketProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntityVersioningProvider, WpEventsTracker, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, buildRolesGuard, createContainer, createExpressFileResponse, getLocalizedText, newUuid, renderHandlebarsTemplate, toEntitiesImportInput };
27687
27703
  //# sourceMappingURL=index.js.map