-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.ts
67 lines (61 loc) · 1.48 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type {
Bindings,
Data,
Device,
DeviceData,
DevicePostDataAny,
LoginData,
LoginPostData,
} from '../types.js'
export interface APISettings {
expireAt?: string | null
password?: string | null
token?: string | null
username?: string | null
}
export const isAPISetting = (key: string): key is keyof APISettings =>
(
[
'expireAt',
'password',
'token',
'username',
] satisfies (keyof APISettings)[] as string[]
).includes(key)
export interface SettingManager {
get: <K extends keyof APISettings>(key: K) => APISettings[K]
set: <K extends keyof APISettings>(key: K, value: APISettings[K]) => void
}
export interface Logger {
error: Console['error']
log: Console['log']
}
export interface APIConfig extends Partial<LoginPostData> {
autoSyncInterval?: number | null
language?: string
logger?: Logger
onSync?: () => Promise<void>
settingManager?: SettingManager
shouldVerifySSL?: boolean
timezone?: string
}
export interface IAPI {
authenticate: (data?: LoginPostData) => Promise<boolean>
bindings: () => Promise<{ data: Bindings }>
clearSync: () => void
control: ({
id,
postData,
}: {
id: string
postData: DevicePostDataAny
}) => Promise<{ data: Data }>
deviceData: ({ id }: { id: string }) => Promise<{ data: DeviceData }>
fetch: () => Promise<readonly Device[]>
login: ({
postData,
}: {
postData: LoginPostData
}) => Promise<{ data: LoginData }>
onSync?: () => Promise<void>
}