# miniapp-sdk
<a href="https://www.npmjs.org/package/acheckin-sdk">
<img src="https://badge.fury.io/js/acheckin-sdk.svg" alt="Current npm package version." />
</a>

## 📋 Yêu cầu

- Ứng dụng ACheckin: https://acheckin.vn/
- NodeJS & NPM (khuyên dùng) hoặc dự án Web có thể chạy độc lập không cần cài đặt lên server

## 🛠 Cài đặt
### 🚀 Tạo mới một dự án
Bạn có thể khởi tạo một ứng dụng mới hoàn toàn bằng công cụ ACheckin CLI do chúng tôi cung cấp.

Chú ý: ứng dụng được viết trên nền ReactJS.

1. #### Cài đặt CLI

   `npm install acheckin -global`

2. #### Tạo dự án mới

   ```acheckin init MyMiniApp [options]```<br>
   ##### options
   - `--template [js|ts|html]` (Mặc định là **js**)
   - `--id [your_bundle_id]` (Mặc định **acheckin.miniapp.myminiapp**)
    <br>
3. #### Chúc mừng, bạn đã khởi tạo thành công!
   Nhập lệnh `cd MyMiniApp && acheckin run` và dùng ACheckin trên điện thoại quét mã QR được tạo trên Terminal.

### 📚 Thêm ACheckin SDK vào một dự án có sẵn

## 📖 API Reference

| API | Mô tả | Quyền truy cập |
<<<<<<< HEAD
| ----------- | ------ | -----------
| [setHeaderTitle](#setheadertitle) | Đặt tiêu đề của ứng dụng | ```none``` |
| [getAccessToken](#getaccesstoken) | Lấy token | ```none``` |
| [getUserInfo](#getuserinfo) | Lấy thông tin người dùng | ```user_personal_email``` ```basic_info``` |
done| [getDeviceInfo](#getdeviceinfo) | Lấy thông tin thiết bị | ```basic_device``` ```device_battery``` ```network_info``` ```device_ip```| 
done | [readQrBarCode](#readqrbarcode) | Đọc mã Qr hoặc Bar  | ```device_camera``` |
done| [handleShakeDevice](#handleshakedevice) | Xử lý lắc thiết  | ```device_shake``` |
| [showBottomBar](#showbottombar) | Hiển thị thanh công cụ dưới màn hình | ```none``` |
| [hideBottomBar](#hidebottombar) | Ẩn thanh công ưới màn hình | ```none``` |
| [setLocalNotification](#setlocalnotification) | Cài đặt gửi thông báo tại local | ```device_notification``` |
done | [vibrateDevice](#vibratedevice) | Sự kiện rung thiết bị | ```device_hardware``` |
on process | [setItem](#setitem) | Lưu giá trị vào bộ nhớ thiết bị | ```device_storage``` |
on process | [getItem](#getitem) | Lấy giá trị từ bộ nhớ thiết bị | ```device_storage``` |
done| [shareScreen](#sharescreen) | Chia sẻ màn hình tới các ứng dụng khác | ```basic_device``` |
| [isBioAvailable](#isbioavailable) | Kiểm tra thiết bị có hỗ trợ sinh trắc học không | Đang cập nhật |
| [bioAuthenticate](#bioauthenticate) | Xác thực bằng sinh trắc học | Đang cập nhật |
done| [getCurrentLocation](#getcurrentlocation) | Lấy vị trí hiện tại | ```device_location``` |

## ```setHeaderTitle```
> - Đặt tiêu đề của ứng dụng.
>```typescript
>setHeadererTitle(string): Promise<any>;
>```

## ```getAccessToken```
> - Lấy token.
>```typescript
>getAccessToken(): Promise<string>;
>```

## ```getUserInfo```
> - Lấy thông tin người dùng.
>```typescript
>getUserPersonalInfo(Array<keyof UserPersonalInfo>): Promise<UserInfo>;
>```
>```typescript
>interface UserInfo {
>	id: string;
>	name: string;
>	picture: string;
>}
>```
=======
| ----------- | ------ | -----------|
| [getDeviceInfo](#getdeviceinfo) | Lấy thông tin thiết bị | ```basic_device``` ```device_battery``` ```network_info``` ```device_ip```| 
| [readQrBarCode](#readqrbarcode) | Đọc mã Qr hoặc Bar  | ```device_camera``` |
| [handleShakeDevice](#handleshakedevice) | Xử lý lắc thiết  | ```device_shake``` |
| [setLocalNotification](#setlocalnotification) | Cài đặt gửi thông báo tại local | ```device_notification``` |
| [vibrateDevice](#vibratedevice) | Sự kiện rung thiết bị | ```device_hardware``` |
| [setItem](#setitem) | Lưu giá trị vào bộ nhớ thiết bị | ```device_storage``` |
| [getItem](#getitem) | Lấy giá trị từ bộ nhớ thiết bị | ```device_storage``` |
| [removeItem](#removeitem) | Xoá giá trị từ bộ nhớ theo key | ```device_storage``` |
| [clear](#clear) | Xoá toàn bộ giá trị từ bộ nhớ | ```device_storage``` |
| [shareScreen](#sharescreen) | Chia sẻ màn hình tới các ứng dụng khác | ```basic_device``` |
| [isBioAvailable](#isbioavailable) | Kiểm tra thiết bị có hỗ trợ sinh trắc học không | Đang cập nhật |
| [bioAuthenticate](#bioauthenticate) | Xác thực bằng sinh trắc học | Đang cập nhật |
| [getCurrentLocation](#getcurrentlocation) | Lấy vị trí hiện tại | ```device_location``` |
| [playAudio](#playaudio) | Play nhạc mp3 | ```none``` |
| [stopAudio](#stopaudio) | Stop nhạc mp3 | ```none``` |
| [selectDatetime](#selectdatetime) | Chọn thời gian | ```none``` |
>>>>>>> 62886241e77944e7f2396cc650b6d11f09f7c7d3

## ```getDeviceInfo```
> - Lấy thông tin thiết bị.
>```typescript
>getDeviceInfo(Array<keyof DeviceInfo>):Promise<DeviceInfo>;
>```
>```typescript
>interface DeviceInfo {
>	device_id: string;
>	device_name: string;
>	device_platform: string;
>	bundle_id: string;
>	device_os_version: string;
>	is_tablet: boolean;
>	ip_address: string;
>	battery_level: number;
>	battery_changing: boolean;
>	device_mac_address: string;
>	device_manufacturer: string;
>	device_brand: string;
>	wifi_name: string;
>	is_wifi: boolean;
>	has_network: string;
>	is_mobile_data: boolean;
>}
>```

## ```readQrBarCode```
> - Đọc QR hoặc bar code.
>```typescript
>readBarCode():Promise<string>;
>```

## ```handleShakeDevice```
> - Xử lý sự kiện lắc thiết bị.
>```typescript
>addShakeEventListener(callback: () => void);
>```

## ```setLocalNotification```
> - Cài đặt gửi thông báo tại local.
>```typescript
>setLocalNotification(param: schedule): Promise<any>;
>```
>```typescript
>interface schedule {
>	title: string;
>	body: string;
>	schedule?: number;
>}
>```
## ```vibrateDevice```
> - Sự kiện rung thiết bị.
>```typescript
>vibrate(data:vibrate): Promise;
>```
>```typescript
>interface vibrate {
>	type: 'nomal' | 'auto' | 'cancel'; 
>  time:number ('milli seconds');
>  delay:numer
>}
>```
## ```setItem```
> - Lưu giá trị vào bộ nhớ thiết bị.
>```typescript
>setItem(key: string, value: string): Promise<boolean>;
>```

## ```getItem```
> - Lấy giá trị từ bộ nhớ thiết bị.
>```typescript
>getItem(key: string): Promise<string>;
>```

## ```removeItem```
> - Xoá giá trị từ bộ nhớ thiết bị theo key.
>```typescript
>removeItem(key: string): Promise<string>;
>```

## ```clear```
> - Xoá toàn bộ giá trị từ bộ nhớ thiết bị.
>```typescript
>clear(): Promise<string>;
>```

## ```shareScreen```
> - Chia sẻ màn hình tới các ứng dụng khác.
>```typescript
>shareScreen(message: string): Promise<any>;
>```

## ```isBioAvailable```
> - Kiểm tra thiết bị có hỗ trợ sinh trắc học không.
>```typescript
>isSensorAvailable(): Promise<biometryType>;
>```
>``` typescript
>- IOS: 
> enum biometryType: 'Touch ID' | 'Face ID'
>- ANDROID:
> enum biometryType: 'Biometrics'
>```

## ```bioAuthenticate```
> - Xác thực bằng sinh trắc học.
>```typescript
>bioAuthenticate(param: params): Promise;
>```
>```typescript
>interface params {
>	title: string; (android)
>	subTitle: string; (android)
>	description: string; (android & ios)
>	cancelButton=string; (android)
>}
>```

## ```getCurrentLocation```
> - Lấy vị trí hiện tại
>```typescript
>getCurrentLocation(): Promise<Location>;
>```
>```typescript
>interface Location {
>   latitude: number;
>   longitude: number;
>}
>```


## ```playAudio```
> - Play nhạc mp3
>```typescript
>playAudio(audio: Audio): Promise<boolean>
>```
>```typescript
>interface Audio {
>    url: string;
>    background?: boolean;
>    title?: string;
>    artwork?: string;
>}
>```

## ```stopAudio```
> - Stop nhạc mp3
>```typescript
>stopAudio(): Promise<boolean>
>```

## ```selectDatetime```
> - Chọn thời gian
>```typescript
>selectDatetime(date: Date): Promise<boolean>
>```
>```typescript
>interface Date {
>    type: 'datetime' | 'time' | 'date';
>    is_24_hour?: boolean;
>}
>```
