open-index/open-npm huggingface dataset:
npm package: @kagari/auth
Description: @kagari/auth ===== A facility for authentication based on passport & typeorm, supports session and jwt
Latest version: 0.7.0

@kagari/auth
=====
A facility for authentication based on passport & typeorm, supports session and jwt

### Usage
prepare business logic
```typescript
// validation function
import { ComposeAccessTokenPayload, ComposeRefreshTokenPayload, ValidateFunction } from '@kagari/auth';
import { UserEntity } from './User.entity';

// validate credential
export const validate: ValidateFunction = (credential) => {
  // any logic validate if input is valid
  return credential // return validated values
}

// verify crendetial
export const verify: ValidateFunction = async (repo, credential) => {
  // your logic verify the user(if password matches)
  return { id: 1, username: 'foobar' }
}

// token genderators
export const getAccessTokenPayload: ComposeAccessTokenPayload = (userInfo) => (userInfo)
export const getRefreshTokenPayload: ComposeRefreshTokenPayload = (userInfo) => (userInfo)
```

register modules
```typescript
// local session
import { JwtAuthModule, LocalAuthModule } from '@kagari/auth';
import { UserEntity } from './User.entity';
import { composeAccessTokenPayload, composeRefreshTokenPayload } from './helpers';


// or use forRoot directly
LocalAuthModule.forRootAsync({
  useFactory: () => ({
    entity: UserEntity,
    validate: validate,
    verfiy: verify,
    session: {
      // options for express-session
    },
    include: [
      // options for MiddlewareConsumer.forRoutes()
      // for all by default
    ],
    exclude: [
      // options for MiddlewareConsumer.forRoutes().exclude()
      // exclude `/api/**` by default
    ],
  })
})

// or use forRoot directly
JwtAuthModule.forRootAsync({
  useFactory: () => ({
    entity: UserEntity,
    validate: validate,
    verify: verify,
    jwt: {
      // options for @nestjs/jwt module
    },
    payload: {
      access: composeAccessTokenPayload,
      refresh: composeRefreshTokenPayload,
    }
  })
})
```
npm package: @kagari/database
Description: typeorm wrapper for kagari framework
Latest version: 0.7.0

### @kagari/database

typeorm wrapper for kagari framework

usage

```typescript
import { DatabaseModule, NestLogger } from '@kagari/database';

DatabaseModule.forRoot({
  type: 'postgres',
  // same with TypeOrmModuleOptions
  logger: new NestLogger({ context: 'database' })
})

// also available using forRootAsync
```

reexport

```typescript
import { getRepositoryToken } from '@kagari/database';
// same as
import { getRepositoryToken } from '@nestjs/typeorm';

import { Not } from '@kagari/database'
// same as
import { Not } from 'typeorm'
```
npm package: @kagari/rbac
Description: rbac implement for kagari framework, needs work with `@kagari/auth` together.
Latest version: 0.7.0

### @kagari/rbac

rbac implement for kagari framework, needs work with `@kagari/auth` together.

usage

```typescript
// prepare business logic
import { CanActivateFunction, RoleBasedAccessControlModule } from '@kagari/rbac';
import { ExecutionContext, UseGuards } from '@nestjs/common';
import { UserEntity } from './User.entity';
import { RoleEntity } from './Role.entity';
import { PermissionEntity } from './Permission.entity';
import { LocalAuthenticatedGuard } from './local-authenticated.guard';

const canActivate: CanActivateFunction = function(context: ExecutionContext) {
  // your logic check if this user can pass
  
  // this referes to RoleBasedAccessControlModule
  // which injects Reflector, you can get any injectable by it
}

RoleBasedAccessControlModule.forRoot({
  entities: {
    user: UserEntity,
    role: RoleEntity,
    permission: PermissionEntity
  },
  canActivate: canActivate
})

@UseGuards(LocalAuthenticatedGuard, RoleBasedAccessControlModule)
class SomeController {
  // all handlers under this controller will be protected by rbac strategy
}
```
npm package: @kagari/restful
Description: provides a protocol for list query > this package is in develop, may not support every query operator
Latest version: 0.7.0

### @kagari/restful

provides a protocol for list query
> this package is in develop, may not support every query operator

```typescript
import { Controller, Get } from '@nestjs/common';
import { ParsedQueryString, QueryProtocol } from '@kagari/restful';

@Controller()
class SomeClass {
  @Get()
  findAll(@QueryProtocol(/* supprts give validate pipe in */) query: ParsedQueryString) {
    // apply the query
  }
}
```

### use in browser
import the entire package will import also `@nestjs/*` packages.
to avoid it, use like below

```typescript
import { deserialize } from '@kagari/restful/dist/deserialize';
import { getOperatedValue } from '@kagari/restful/dist/helpers';
import { Operations } from '@kagari/restful/dist/types';

const querystring = deserialize({
  $page: 1,
  $pageSize: 20,
  $withDeleted: true,
  createdAt: getOperatedValue(Operations.bw, ['2022-10-01', '2022-10-31'])
})
// $page=1&$pageSize=20&$withDeleted=true&created=$bw(2022-10-01,2022-10-31)
```