1.1.8 • Published 6 months ago

sml-sb-api v1.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

User Guide

Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.

This TSDX setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use ts-node-dev, plain ts-node, or simple tsc.

If you’re new to TypeScript, checkout this handy cheatsheet

Commands

TSDX scaffolds your new library inside /src.

This builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.

To do a one-off build, use npm run build or yarn build.

To run tests, use npm test or yarn test.

Configuration

Code quality is set up for you with prettier, husky, and lint-staged. Adjust the respective fields in package.json accordingly.

Jest

Jest tests are set up to run with npm test or yarn test.

Setup Files

This is the folder structure we set up for you:

/src
  index.ts
  sb-api.ts
  defines.ts
  utils.ts
/test
  sb-api.test.ts
  utils.test.ts
.gitignore
package.json
README.md
tsconfig.json

TypeScript

tsconfig.json is set up to interpret dom and esnext types, as well as react for jsx. Adjust according to your needs.

Using SBApi

See example code in test files

Definitions

SBApiHeader

reqType: REQUEST | RESPONSE \ api (string): Mã API \ priority: '1' | '2' | '3' | '4' | '5' \ apiKey (string): API Key \ channel (string): \ subChannel (string): \ location (string): \ context (string): \ trusted (string): true | false; \ requestAPI (string): Tên Client gửi request \ requestNode (string): Địa chỉ Client gửi request \ userID (string): ID người dùng; \ duration (string): timestamp value \ zip (string): true | false \

SBApiConn

apiKey (string): API Key \ xIBMClientId (string): X-IBM-Client-Id \ xIBMClientSecret (string): X-IBM-Client-Secret \ urls:

  • sms (string): API url for sms
  • mail (string): API url for mail
  • authen (string): API url for authen & otp

Methods

Send Mail: SBApi.sendMail(options: SendMailRequest): Promise<SendMailResponse>

export type SendMailRequestBodyParams = {
  from: string;
  to: string;
  subject: string;
  isHtmlBody: 'true' | 'false';
  priority: 'low' | 'normal' | 'high';
  fileAttachment?: {
    file: { fileName: string; fileByte64: string }[];
  };
  bodyMsg: string;
};

export type SendMailRequest = {
  header: Pick<
    SBApiHeader,
    'channel' | 'subChannel' | 'requestAPI' | 'requestNode' | 'userID'
  >;
  params: SendMailRequestBodyParams;
};

export type SendMailResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      reqID: string;
      utility?: {
        mydata?: {
          result?: 'OK';
        };
      };
    };
    error?: SBApiError;
    security: SBApiSecurity;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.sendSms(options: SendSmsRequest): Promise<SendSmsResponse>

export type SendSmsRequestBodyParams = {
  phone: string;
  servicesId: string;
  infor: string;
};

export type SendSmsRequest = {
  header: Pick<
    SBApiHeader,
    'channel' | 'subChannel' | 'requestAPI' | 'requestNode' | 'userID'
  >;
  params: SendSmsRequestBodyParams;
};

export type SendSmsResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      reqID: string;
    };
    error?: SBApiError;
    security: SBApiSecurity;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.sendSmsByTemplate(options: SendSmsByTemplateRequest): Promise<SendSmsByTemplateResponse>

export type SendSmsByTemplateRequestBodyParams = {
  phone: string;
  servicesId: string;
  templateId: string;
  bodyParam: {
    param: { paramName: string; paramValue: string }[];
  };
};

export type SendSmsByTemplateRequest = {
  header: Pick<
    SBApiHeader,
    'channel' | 'subChannel' | 'requestAPI' | 'requestNode' | 'userID'
  >;
  params: SendSmsByTemplateRequestBodyParams;
};

export type SendSmsByTemplateResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      reqID: string;
    };
    error?: SBApiError;
    security: SBApiSecurity;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.getLogin(options:GetLoginRequest): Promise<GetLoginResponse>

export type GetLoginRequestBodyParams = {
  username: string;
  password: string;
  /** Ma giao dich */
  transId: string;
};

export type GetLoginRequest = {
  header: Pick<
    SBApiHeader,
    | 'channel'
    | 'subChannel'
    | 'requestAPI'
    | 'requestNode'
    | 'userID'
    | 'trusted'
  > &
    Partial<Pick<SBApiHeader, 'location' | 'context'>>;
  params: GetLoginRequestBodyParams;
};

export type GetLoginResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      enquiry: {
        transId: string;
        responseCode: string;
        sessionId: string;
        packageUser: string;
        phone: string;
        customerID: string;
        customerName: string;
        companyCode: string;
        username: string;
        aliasName: string;
      };
    };
    error?: SBApiError;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.getOtp(options: GetOtpRequest): Promise<GetOtpResponse>

export type GetOtpRequestBodyParams = {
  /** Ma session */
  sessionId: string;
  transType: 'ACCOUNT' | 'CARD' | 'USER' | string;
  /** Ten dang nhap. Bat buoc neu transType = 'ACCOUNT' */
  accountNo?: string;
  /** Bat buoc neu transType = 'CARD' */
  cardNo?: string;
  /** Bat buoc neu transType = 'USER' */
  username?: string;
  /** Bat buoc neu transType khac 'ACCOUNT', 'CARD', 'USER' */
  customerId?: string;
  transId: string;
  transInfo: string;
  smsParams: {
    tempId: string;
    content: string;
  };
};

export type GetOtpRequest = {
  header: Pick<
    SBApiHeader,
    | 'channel'
    | 'subChannel'
    | 'requestAPI'
    | 'requestNode'
    | 'userID'
    | 'trusted'
  > &
    Partial<Pick<SBApiHeader, 'location' | 'context'>>;
  params: GetOtpRequestBodyParams;
};

export type GetOtpResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      enquiry: {
        transId: string;
        responseCode: string;
      };
    };
    error?: SBApiError;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.confirmOtp(options: ConfirmOtpRequest): Promise<ConfirmOtpResponse>

export type ConfirmOtpRequestBodyParams = {
  /** Ma session */
  sessionId: string;
  /** Loai giao dich */
  transType?: 'ACCOUNT' | 'CARD' | 'USER';
  softOtp?: boolean;
  /** Ten dang nhap. Bat buoc neu transType = 'ACCOUNT' */
  accountNo?: string;
  /** Bat buoc neu transType = 'CARD' */
  cardNo?: string;
  /** Bat buoc neu transType = 'USER' hoac softOtp = true */
  username?: string;
  /** Bat buoc neu transType khac 'ACCOUNT', 'CARD', 'USER' */
  customerId?: string;
  transId: string;
  transInfo: string;
  /** Ma xac thuc OTP */
  validateCode: string;
};

export type ConfirmOtpRequest = {
  header: Pick<
    SBApiHeader,
    | 'channel'
    | 'subChannel'
    | 'requestAPI'
    | 'requestNode'
    | 'userID'
    | 'trusted'
  > &
    Partial<Pick<SBApiHeader, 'location' | 'context'>>;
  params: ConfirmOtpRequestBodyParams;
};

export type ConfirmOtpResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      enquiry: {
        responseCode: string;
      };
    };
    error?: SBApiError;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};

Send Mail: SBApi.getRegname(options: GetRegnameRequest): Promise<GetRegnameResponse>

export type GetRegnameRequestBodyParams = {
  /** Ma session */
  sessionId: string;
  /** username can doi */
  signOnName: string;
  username: string;
  softOtp?: boolean;
  /** Required if softOtp is true */
  transactionId?: string;
  /** Ma xac thuc OTP */
  validateCode: string;
};

export type GetRegnameRequest = {
  header: Pick<
    SBApiHeader,
    | 'channel'
    | 'subChannel'
    | 'requestAPI'
    | 'requestNode'
    | 'userID'
    | 'trusted'
  > &
    Partial<Pick<SBApiHeader, 'location' | 'context'>>;
  params: GetRegnameRequestBodyParams;
};

export type GetRegnameResponse = {
  success: boolean;
  data: {
    header: SBApiHeader;
    body?: {
      status: 'OK';
      enquiry: {
        responseCode: string;
      };
    };
    error?: SBApiError;
  } | null;
  error?: {
    code: string;
    msg: string;
  };
};
1.1.8

6 months ago

1.1.7

10 months ago

1.1.6

10 months ago

1.1.5

10 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.4

1 year ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago