sml-sb-api v1.1.8
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
, plaints-node
, or simpletsc
.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 smsmail
(string): API url for mailauthen
(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;
};
};