目录

Template Files

The template files include two files required for the custom plugin: CustomVerify.ts and tsconfig.json.

Plugin Template CustomVerify.ts

The plugin template file can be customized. You can rename the CustomVerify class.

The class name of CustomVerify must match the name attribute of verify_plugin in the config.yaml file.

import {VerifyPlugin} from '../libs/plugins/verify/VerifyPlugin';  // The CustomVerify.ts plugin file is stored in the default location (the plugins folder under the root directory where ohpm-repo is decompressed). This is the default import path for the VerifyPlugin interface class.

interface VerifyUser {
  id: string;
  name: string;
  phone: string;
  email: string;
}

interface VerifyPluginConf {
  type: string;
  name: string;
  path: string;
  length: number;
  liveTime: number;
  receiver: string;
  [key: string]: any;
}

export class CustomVerify implements VerifyPlugin {

  /**
   * Sends a verification code and returns the sending result.
   * @param user
   * @param code
   * @param config
   * @returns Response information. A successCode of 0 indicates success.
   */
  sendMsg(user: VerifyUser, code: string, config: VerifyPluginConf): Promise<{
    successCode:string
  }> {
    let successCode: string;
    return {
      successCode
    };
  };

  /**
   * Generates a verification code.
   * @param user
   * @param config
   * @returns Response information. A successCode of 0 indicates success.
   */
  generateCode(user: VerifyUser, config: VerifyPluginConf): Promise<{
    successCode:string
  }> {
    let successCode: string;
    return {
      successCode
    };
  };

  /**
   * Validates the verification code entered by the user.
   * @param user
   * @param code
   * @param config
   * @returns Response information. A successCode of 0 indicates success.
   */
  verifyCode(user: VerifyUser, code: string, config: VerifyPluginConf): Promise<{
    successCode:string
  }> {
    let successCode: string;
    return {
      successCode
    };
  };
}

Configuration File tsconfig.json for TS Compilation

// The tsconfig.json file specifies the compilation options and the files required for the compilation in the root directory. The custom plugin file (.ts) is compiled into a .js file.
{
  "include": [
    "plugins/*" // Location of the plugin file
  ],
  "compilerOptions": {
    "target": "es2016",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "commonjs",
    "rootDir": "./plugins",
    "typeRoots": [
      "./node_modules/@types"
    ],
    "types": [
      "node",
    ],
    "resolveJsonModule": true,
    "outDir": "./plugins/outDir",   // Output location of the file after the compilation
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "alwaysStrict": true,
    "strict": false,
    "noImplicitReturns": true,
    "skipLibCheck": true
  }
}