Skip to content

Commit

Permalink
Add IdentityProvider #181
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Jan 18, 2025
1 parent 80221f4 commit ac7f374
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/shared/_dependencyInjection/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import MongoConnection, { MONGO_CLIENT } from '@src/shared/infrastructure/persis
import MikroOrmTransactionalDecorator from '../infrastructure/persistence/mikroOrm/decorators/mikroOrmTransactionalDecorator';
import NestJwtTokenGenerator from '@src/shared/infrastructure/auth/jwt/nestJwtTokenGenerator';
import NestJwtM2mTokenGenerator from '@src/shared/infrastructure/auth/jwt/nestJwtM2mTokenGenerator';
import { UuidIdentityProvider } from '@src/shared/infrastructure/services/UuidIdentityProvider';
import { IDENTITY_PROVIDER } from '@src/shared/domain/services/IdentityProvider';

export const services = [
MikroOrmTransactionalDecorator,
Expand Down Expand Up @@ -52,6 +54,10 @@ export const services = [
provide: QUERY_BUS,
useClass: NestQueryBusBus,
},
{
provide: IDENTITY_PROVIDER,
useClass: UuidIdentityProvider,
},
MongoEventStoreRepository,
PersistDomainEventsSubscriber,
NestJwtTokenGenerator,
Expand Down
7 changes: 7 additions & 0 deletions src/shared/domain/services/IdentityProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface IdentityProvider {
generate(): string;

generateFromValue(value: string): string;
}

export const IDENTITY_PROVIDER = Symbol('IdentityProvider');
12 changes: 12 additions & 0 deletions src/shared/infrastructure/services/UuidIdentityProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IdentityProvider } from '@src/shared/domain/services/IdentityProvider';
import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';

export class UuidIdentityProvider implements IdentityProvider {
generate(): string {
return uuidv4();
}

generateFromValue(value: string): string {
return uuidv5(value, uuidv5.DNS);
}
}
2 changes: 2 additions & 0 deletions src/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ConfigModule } from '@nestjs/config';
import { Inject } from '@src/shared/domain/injector/inject.decorator';
import NestJwtTokenGenerator from '@src/shared/infrastructure/auth/jwt/nestJwtTokenGenerator';
import NestJwtM2mTokenGenerator from '@src/shared/infrastructure/auth/jwt/nestJwtM2mTokenGenerator';
import { IDENTITY_PROVIDER } from '@src/shared/domain/services/IdentityProvider';

@Global()
@Module({
Expand Down Expand Up @@ -47,6 +48,7 @@ import NestJwtM2mTokenGenerator from '@src/shared/infrastructure/auth/jwt/nestJw
NestJwtM2mTokenGenerator,
MONGO_CLIENT,
LOGGER,
IDENTITY_PROVIDER,
QUERY_BUS,
COMMAND_BUS,
EVENT_BUS,
Expand Down

0 comments on commit ac7f374

Please sign in to comment.