-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.ts
More file actions
72 lines (64 loc) · 1.78 KB
/
Copy pathinterfaces.ts
File metadata and controls
72 lines (64 loc) · 1.78 KB
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
68
69
70
71
72
import type {
Bindings,
Data,
Device,
DeviceData,
DevicePostDataAny,
LoginData,
LoginPostData,
} from '../types.ts'
const apiSettingKeys: Set<string> = new Set([
'expireAt',
'password',
'token',
'username',
]) satisfies Set<keyof APISettings>
export interface APIConfig extends Partial<LoginPostData> {
readonly autoSyncInterval?: number | null
readonly language?: string
readonly logger?: Logger
readonly onSync?: OnSyncFunction
readonly settingManager?: SettingManager
readonly shouldVerifySSL?: boolean
readonly timezone?: string
}
export interface APISettings {
readonly expireAt?: string | null
readonly password?: string | null
readonly token?: string | null
readonly username?: string | null
}
export interface IAPI {
readonly onSync?: OnSyncFunction
readonly authenticate: (data?: LoginPostData) => Promise<boolean>
readonly bindings: () => Promise<{ data: Bindings }>
readonly clearSync: () => void
readonly control: ({
id,
postData,
}: {
id: string
postData: DevicePostDataAny
}) => Promise<{ data: Data }>
readonly deviceData: ({ id }: { id: string }) => Promise<{ data: DeviceData }>
readonly fetch: () => Promise<readonly Device[]>
readonly login: ({
postData,
}: {
postData: LoginPostData
}) => Promise<{ data: LoginData }>
}
export interface Logger {
readonly error: Console['error']
readonly log: Console['log']
}
export interface SettingManager {
readonly get: <K extends keyof APISettings>(key: K) => APISettings[K]
readonly set: <K extends keyof APISettings>(
key: K,
value: APISettings[K],
) => void
}
export type OnSyncFunction = (params?: { ids?: string[] }) => Promise<void>
export const isAPISetting = (value: string): value is keyof APISettings =>
apiSettingKeys.has(value)