# sml-sb-api

> 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.

Latest version **1.1.8** (published 2023-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install sml-sb-api
pnpm add sml-sb-api
yarn add sml-sb-api
bun add sml-sb-api
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2023-11-14 |
| First published | 2022-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 4 |
| Unpacked size | 661.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | SmartLoyalty |
| Maintainers | duongjerry |

## Links

- npm: https://www.npmjs.com/package/sml-sb-api
- npm.io page: https://npm.io/package/sml-sb-api

## Dependencies (4)

- [he](https://npm.io/package/he.md) ^1.2.0
- [axios](https://npm.io/package/axios.md) ^1.6.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^4.0.9

## Recent versions

- 1.1.8 (latest) — 2023-11-14
- 1.1.7 — 2023-07-12
- 1.1.6 — 2023-07-07
- 1.1.5 — 2023-07-06
- 1.1.4 — 2022-12-09
- 1.1.3 — 2022-11-03
- 1.1.2 — 2022-10-24
- 1.1.1 — 2022-10-19
- 1.1.0 — 2022-10-17
- 1.0.4 — 2022-10-06
- 1.0.2 — 2022-08-19
- 1.0.1 — 2022-08-16
- 1.0.0 — 2022-08-16
- 0.1.0 — 2022-08-16

## README

# 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](https://devhints.io/typescript)

## 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:

```txt
/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;
  };
};
```

---
_Source: https://npm.io/package/sml-sb-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
