0.13.8 • Published 15 days ago

@peersyst/kyc-module v0.13.8

Weekly downloads
-
License
-
Repository
-
Last release
15 days 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.8

15 days ago

0.13.6

15 days ago

0.13.7

15 days ago

0.13.5

2 months ago

0.13.4

2 months ago

0.13.3

7 months ago

0.13.1

11 months ago

0.12.76

1 year ago

0.12.75

1 year ago

0.12.74

1 year ago

0.12.73

1 year ago

0.12.71

1 year ago

0.12.70

1 year ago

0.12.68

2 years ago

0.12.67

2 years ago

0.12.66

2 years ago

0.12.65

2 years ago

0.12.64

2 years ago

0.12.63

2 years ago

0.12.62

2 years ago

0.12.61

2 years ago

0.12.60

2 years ago

0.12.54

2 years ago

0.12.53

2 years ago

0.12.52

2 years ago

0.12.50

2 years ago

0.12.49

2 years ago

0.12.46

2 years ago

0.12.45

2 years ago

0.12.44

2 years ago

0.12.43

2 years ago

0.12.42

2 years ago

0.12.41

2 years ago

0.12.40

2 years ago

0.12.37

2 years ago

0.12.36

2 years ago

0.12.35

2 years ago

0.12.34

2 years ago

0.12.33

2 years ago

0.12.32

2 years ago

0.12.15

2 years ago

0.12.0

2 years ago

0.11.20

2 years ago

0.11.19

2 years ago

0.11.13

2 years ago

0.11.12

2 years ago

0.11.11

2 years ago

0.11.10

2 years ago

0.11.9

2 years ago

0.11.8

2 years ago

0.11.7

2 years ago

0.11.6

2 years ago

0.11.5

2 years ago

0.11.4

2 years ago

0.11.3

2 years ago

0.11.2

2 years ago

0.11.1

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago