-
Notifications
You must be signed in to change notification settings - Fork 54
/
deviceprofiles.ts
183 lines (160 loc) · 4.85 KB
/
deviceprofiles.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { Endpoint } from '../endpoint'
import { EndpointClient, EndpointClientConfig } from '../endpoint-client'
import { LocaleReference, Status, SuccessStatusValue } from '../types'
import { CapabilityReference, PreferenceType } from './devices'
export interface DeviceComponentRequest {
id?: string
capabilities?: CapabilityReference[]
categories?: string[]
}
export interface DeviceComponent extends DeviceComponentRequest {
/**
* UTF-8 label for the component. This value is generated and dependent on the locale of the request
*/
label?: string
}
export enum DeviceProfileStatus {
DEVELOPMENT = 'DEVELOPMENT',
PUBLISHED = 'PUBLISHED'
}
export interface DeviceProfilePreferenceDefinition {
minimum?: number
maximum?: number
minLength?: number
maxLength?: number
// eslint-disable-next-line @typescript-eslint/no-explicit-any
default: any
stringType?: 'text' | 'password' | 'paragraph'
options?: { [key: string]: string }
}
export interface DeviceProfilePreferenceCore {
title: string
description?: string
required?: boolean
preferenceType: PreferenceType
}
export interface DeviceProfilePreferenceRequest extends DeviceProfilePreferenceCore {
explicit?: boolean
definition: DeviceProfilePreferenceDefinition
preferenceId?: string
}
export interface DeviceProfileUpdateRequest {
/**
* must have between 1 and 20 components
*/
components?: DeviceComponentRequest[]
metadata?: { [key: string]: string }
preferences?: DeviceProfilePreferenceRequest[]
}
export interface DeviceProfileCreateRequest extends DeviceProfileUpdateRequest {
name?: string
}
export type DeviceProfileRequest = DeviceProfileCreateRequest
export interface DeviceProfilePreference extends DeviceProfilePreferenceCore {
id?: string
}
export interface DeviceProfile extends DeviceProfileCreateRequest {
id: string
name: string
components: DeviceComponent[]
metadata?: { [key: string]: string }
status: DeviceProfileStatus
}
export interface ComponentTranslations {
/**
* Short UTF-8 text used when displaying the component.
*/
label: string
/**
* UTF-8 text describing the component.
*/
description?: string
}
export interface DeviceProfileTranslations {
tag: string
/**
* A map of component ID to it's translations.
*/
components?: { [key: string]: ComponentTranslations }
}
export class DeviceProfilesEndpoint extends Endpoint {
constructor(config: EndpointClientConfig) {
super(new EndpointClient('deviceprofiles', config))
}
/**
* List all the device profiles belonging to the principal (i.e. user)
*/
public list(): Promise<DeviceProfile[]> {
return this.client.getPagedItems<DeviceProfile>()
}
/**
* Get the definition of a specific device profile
* @param id UUID of the device profile
*/
public get(id: string): Promise<DeviceProfile> {
return this.client.get(id)
}
/**
* Delete a device profile
* @param id UUID of the device profile
*/
public async delete(id: string): Promise<Status> {
await this.client.delete(id)
return SuccessStatusValue
}
/**
* Create a device profile
* @param data device profile definition
*/
public create(data: DeviceProfileCreateRequest): Promise<DeviceProfile> {
return this.client.post(undefined, data)
}
/**
* Update a device profile
* @param id UUID of the device profile
* @param data the new device profile definition
*/
public update(id: string, data: DeviceProfileUpdateRequest): Promise<DeviceProfile> {
return this.client.put(id, data)
}
/**
* Update the status of a device profile
* @param id UUID of the device profile
* @param deviceProfileStatus new device profile status
*/
public updateStatus(id: string, deviceProfileStatus: DeviceProfileStatus): Promise<DeviceProfile> {
return this.client.post(`${id}/status`, {deviceProfileStatus})
}
/**
* Returns a list of the locales supported by the device profile
* @param id UUID of the device profile
*/
public listLocales(id: string): Promise<LocaleReference[]> {
return this.client.getPagedItems(`${id}/i18n`)
}
/**
* Retrieve the translations for the specified locale
* @param id UUID of the device profile
* @param tag locale tag, e.g. 'en', 'es', or 'ko'
*/
public getTranslations(id: string, tag: string): Promise<DeviceProfileTranslations> {
return this.client.get(`${id}/i18n/${tag}`)
}
/**
* Create or update the translations for a device profile
* @param id UUID of the device profile
* @param data translations
*/
public upsertTranslations(id: string, data: DeviceProfileTranslations): Promise<DeviceProfileTranslations> {
return this.client.put(`${id}/i18n/${data.tag}`, data)
}
/**
* Retrieve the translations for the specified locale
* @param id UUID of the device profile
* @param tag locale tag, e.g. 'en', 'es', or 'ko'
*/
public async deleteTranslations(id: string, tag: string): Promise<Status> {
await this.client.delete(`${id}/i18n/${tag}`)
return SuccessStatusValue
}
}