x-utils 1.0.0
Install from the command line:
Learn more about npm packages
$ npm install @polyflix/x-utils@1.0.0
Install via package.json:
"@polyflix/x-utils": "1.0.0"
About this version
Install the package with the following command :
npm i @polyflix/x-utils
This module expose some utilities
Get user roles
get(@IsAdmin(): isAdmin: boolean) {}
get(@MeRoles(): roles: Role[]) {}
get(@MeRoles("Admin"): roles: Role[]) {}
Get user id
get(@MeId(): me: string) {}
Allow only specific roles on a route
@Roles(Role.Admin, Role.Contributor)
Create kafka modules
@Global()
@Module({
imports: [
KafkaModule.register({
useFactory: (configService: ConfigService) => {
return kafkaConfig(configService.get("kafka"));
},
inject: [ConfigService]
})
],
exports: [KafkaModule]
})
Use kafka client
constructor(
@InjectKafkaClient() private readonly kafkaClient: ClientKafka,
) {}
Kafka message
export interface PolyflixKafkaMessage {
key: string;
value: {
trigger: TriggerType;
payload: any;
};
}
export interface PolyflixKafkaValue {
trigger: TriggerType;
payload: any;
}
this.kafkaClient.emit<string, PolyflixKafkaMessage>(topic, {
key: video.slug,
value: {
trigger: TriggerType.PROCESSING,
payload: video
},
});
@EventPattern("polyflix.legacy.video")
video(@Payload("value") message: PolyflixKafkaValue) {
// TODO
}
MinIoMessageValue
match to the payload of an MinIO event in kafka
@EventPattern("minio.upload")
async process(@Payload("value") message: MinIOMessageValue) { }