# @polyflix/x-utils

> NestJS utilities for Polyflix from Polytech

Latest version **1.8.2** (published 2022-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @polyflix/x-utils
pnpm add @polyflix/x-utils
yarn add @polyflix/x-utils
bun add @polyflix/x-utils
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.8.2 |
| Published | 2022-11-26 |
| First published | 2022-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | sylvain-reynaud |

## Links

- npm: https://www.npmjs.com/package/@polyflix/x-utils
- npm.io page: https://npm.io/package/@polyflix/x-utils

## Dependencies (5)

- [express](https://npm.io/package/express.md) ^4.18.1
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^8.4.4
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.4.4
- [@nestjs/config](https://npm.io/package/@nestjs/config.md) ^2.0.0
- [@nestjs/microservices](https://npm.io/package/@nestjs/microservices.md) ^8.4.4

## Recent versions

- 1.8.2 (latest) — 2022-11-26

## README

# X Utils

## Install

Install the package with the following command :

```
npm i @polyflix/x-utils
```

## How to use

This module expose some utilities

### Decorators

Get user roles

```ts
 get(@IsAdmin(): isAdmin: boolean) {}

 get(@MeRoles(): roles: Role[]) {}

 get(@MeRoles("Admin"): roles: Role[]) {}
```

Get user id

```ts
 get(@MeId(): me: string) {}
```

### Guards

Allow only specific roles on a route

```ts
@Roles(Role.Admin, Role.Contributor)
```

### Kafka

Create kafka modules

```ts
@Global()
@Module({
    imports: [
        KafkaModule.register({
            useFactory: (configService: ConfigService) => {
                return kafkaConfig(configService.get("kafka"));
            },
            inject: [ConfigService]
        })
    ],
    exports: [KafkaModule]
})
```

Use kafka client

```ts
constructor(
    @InjectKafkaClient() private readonly kafkaClient: ClientKafka,
) {}
```

Kafka message

```ts
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
}
```

### MinIO

`MinIoMessageValue` match to the payload of an MinIO event in kafka

```ts
@EventPattern("minio.upload")
async process(@Payload("value") message: MinIOMessageValue) { }
```

---
_Source: https://npm.io/package/@polyflix/x-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
