@peersyst/kyc-module
v0.13.9
Published
Know Your Customer module
Downloads
108
Readme
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.