0.13.9 • Published 11 months ago

@peersyst/kyc-module v0.13.9

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Description

Nest framework TypeScript base kyc module using sumsub.

Installation

$ npm install --save @peersyst/kyc-module

How to use it

Base kyc module

  • Import and register KycModule in AppModule and apply Signature middleware for SumsubController
import { Module, NestModule, MiddlewareConsumer } from "@nestjs/common";
import { KycModule, SignatureMiddleware, SumsubController, OrmType } from "@peersyst/kyc-module";

@Module({
    imports: [
        ConfigModule.forRoot(...),
        TypeOrmModule.forRootAsync(...),
        UserModule,
        KycModule.register(UserModule, ConfigModule, {
          ormType: OrmType.TYPEORM,
          addTestEndpoints: false,
        }),
    ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(SignatureMiddleware).forRoutes(SumsubController);
  }
}
  • Implement KycUserServiceI for your UserService
import { KycUserServiceI } from "@peersyst/kyc-module";

@Injectable()
export class MyUserService implements KycUserServiceI {...}
  • UserModule should export a provider named UserService
@Module({
    imports: [
        TypeOrmModule.forFeature([User]),
    ],
    providers: [MyUserService, { provide: "UserService", useClass: MyUserService }],
    controllers: [UserController],
    exports: [MyUserService, { provide: "UserService", useClass: MyUserService }, TypeOrmModule],
})
export class UserModule {}
  • Enable rawBody on main.ts
...
import * as bodyParser from "body-parser";
import { ServerResponse } from "http";

async function bootstrap() {
    const app = await NestFactory.create(AppModule, { bodyParser: false });

    const rawBodyBuffer = (req: any, res: ServerResponse, buffer: Buffer, encoding: BufferEncoding) => {
        if (buffer && buffer.length) {
            req.rawBody = buffer.toString(encoding || "utf8");
        }
    };

    app.use(bodyParser.urlencoded({ verify: rawBodyBuffer, extended: true }));
    app.use(bodyParser.json({ verify: rawBodyBuffer }));
    ...
}
  • Add configService configuration variables
export default (): any => ({
    sumsub: {
        secretKey: process.env.SUMSUB_SECRET_KEY,
        baseUrl: process.env.SUMSUB_BASE_URL,
        appToken: process.env.APP_TOKEN,
    },
});
  • Add KycErrorCode and KycErrorBody to app ErrorCodes
import { HttpStatus } from "@nestjs/common";
import { KycErrorCode, KycErrorBody } from "@peersyst/kyc-module";

// Define app error codes
enum AppErrorCode {}

export const ErrorCode = { ...AppErrorCode, ...KycErrorCode };
export type ErrorCodeType = AppErrorCode | KycErrorCode;

export const ErrorBody: { [code in ErrorCodeType]: { statusCode: HttpStatus; message: string } } = {
    // Define app error code bodies
    ...KycErrorBody,
};
  • If ormType is sequelize: create model in your models folder with name KycModel
export { KycModel } from "@peersyst/kyc-module";
  • If ormType is typeorm: create entity in your entities folder with name KycEntity
export { KycEntity } from "@peersyst/kyc-module";

Add Notifications

  • Set notifications to true in register module and add NotificationModule
KycModule.register(UserModule, ConfigModule, {
    ...
    notifications: true,
    NotificationModule: MyNotificationModule,
}),

NotificationModule should export a provider named NotificationService (v8 onwards):

@Module({
    providers: [MyNotificationService, { provide: "NotificationService", useClass: MyNotificationService }],
    exports: [MyNotificationService, { provide: "NotificationService", useClass: MyNotificationService }],
})
export class NotificationModule {}
  • Implement KycNotificationInterface for your NotificationService
import { KycNotificationInterface } from "@peersyst/kyc-module";

@Injectable()
export class MyNotificationService implements KycNotificationInterface {...}

License

Nest is MIT licensed.

0.13.9

11 months ago

0.13.8

1 year ago

0.13.6

1 year ago

0.13.7

1 year ago

0.13.5

1 year ago

0.13.4

1 year ago

0.13.3

2 years ago

0.13.1

2 years ago

0.12.76

2 years ago

0.12.75

2 years ago

0.12.74

2 years ago

0.12.73

2 years ago

0.12.71

2 years ago

0.12.70

2 years ago

0.12.68

3 years ago

0.12.67

3 years ago

0.12.66

3 years ago

0.12.65

3 years ago

0.12.64

3 years ago

0.12.63

3 years ago

0.12.62

3 years ago

0.12.61

3 years ago

0.12.60

3 years ago

0.12.54

3 years ago

0.12.53

3 years ago

0.12.52

3 years ago

0.12.50

3 years ago

0.12.49

3 years ago

0.12.46

3 years ago

0.12.45

3 years ago

0.12.44

3 years ago

0.12.43

3 years ago

0.12.42

3 years ago

0.12.41

3 years ago

0.12.40

3 years ago

0.12.37

3 years ago

0.12.36

3 years ago

0.12.35

3 years ago

0.12.34

3 years ago

0.12.33

3 years ago

0.12.32

3 years ago

0.12.15

3 years ago

0.12.0

3 years ago

0.11.20

3 years ago

0.11.19

3 years ago

0.11.13

3 years ago

0.11.12

3 years ago

0.11.11

3 years ago

0.11.10

3 years ago

0.11.9

3 years ago

0.11.8

3 years ago

0.11.7

3 years ago

0.11.6

3 years ago

0.11.5

3 years ago

0.11.4

3 years ago

0.11.3

3 years ago

0.11.2

3 years ago

0.11.1

3 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago