import { ManagementClientOptions } from './types'; import { HttpClient } from '../common/HttpClient'; import { ManagementTokenProvider } from "./ManagementTokenProvider"; import { DeviceStatus, DeviceList, DeviceDetails } from './types'; export class BrowserFingerprintClient { options: ManagementClientOptions; httpClient: HttpClient; tokenProvider: ManagementTokenProvider; constructor( options: ManagementClientOptions, httpClient: HttpClient, tokenProvider: ManagementTokenProvider, ) { this.options = options; this.tokenProvider = tokenProvider; this.httpClient = httpClient; } /** * 设备管理 - 列表 * @param options * @returns */ async getDeviceList( options: { page?: number; limit?: number; } = { page: 1, limit: 10 } ): Promise { const { page, limit } = options const data = await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/metadata/filter`, data: { "modelId": "device", "showFieldId": false, "previewRelation": true, page, limit } }); return { data: data.list, totalCount: data.totalCount, } } /** * 设备管理 - 详情 * @param id * @returns */ async getDeviceDetails(id: string): Promise { const data = await this.httpClient.request({ method: 'GET', url: `${this.options.host}/api/v3/metadata/get-row?modelId=device&rowId=${id}&showFieldId=false`, }); return data } /** * 设备管理 - 设备状态 * @param id * @returns */ async getDeviceStatus(id: string): Promise { const data = await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/device-status`, data: { id } }); return data; } /** * 设备管理 - 移除设备 * @param id * @returns */ async delDevice(id: string): Promise { try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/delete-device`, data: { id } }); return true; } catch (error) { return false; } } /** * 设备管理 - 禁用设备 * @param id * @returns */ async disableDevice(id: string): Promise { try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/disable-device`, data: { id } }); return true; } catch (error) { return false; } } /** * 设备管理 - 启用设备 * @param id * @returns */ async enableDevice(id: string): Promise { try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/enable-device`, data: { id } }); return true; } catch (error) { return false; } } /** * 设备管理 - 挂起设备 * @param id * @param endTime * @returns */ async suspendDevice(id: string, endTime: number): Promise { try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/suspend-device`, data: { id, endTime } }); return true; } catch (error) { return false; } } /** * 用户中心 - 列表 * @param options * @returns */ async getDeviceUserList( options: { page?: number; limit?: number; userId?: string; } = { page: 1, limit: 10 } ): Promise { const { userId, page, limit } = options const data = await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/get-user-devices?userId=${userId}`, data: { "modelId": "device_rely", "showFieldId": false, "previewRelation": true, // userId, page, limit } }); return { data: data.list, totalCount: data.totalCount, } } /** * 用户中心 - 移除设备 * @param id * @returns */ async delDeviceUser(options: { userId: string; id: string; }): Promise { const { userId, id } = options try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/delete-device-by-user`, data: { id, userId } }); return true; } catch (error) { return false; } } /** * 用户中心 - 禁用设备 * @param id * @returns */ async disableDeviceUser(options: { userId: string; id: string; }): Promise { const { userId, id } = options try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/disable-device-by-user`, data: { id, userId } }); return true; } catch (error) { return false; } } /** * 用户中心 - 启用设备 * @param id * @returns */ async enableDeviceUser(options: { userId: string; id: string; }): Promise { const { userId, id } = options try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/enable-device-by-user`, data: { id, userId } }); return true; } catch (error) { return false; } } /** * 用户中心 - 挂起设备 * @param userId * @param id * @param endTime * @returns */ async suspendDeviceUser(options: { userId: string; id: string; endTime: number; }): Promise { const { userId, id, endTime } = options try { await this.httpClient.request({ method: 'POST', url: `${this.options.host}/api/v3/suspend-device-by-user`, data: { id, endTime, userId } }); return true; } catch (error) { return false; } } }