Skip to content

Commit 08d776b

Browse files
committed
feat(devicepreferences): initial suppport for i18n
- add create and get endpoints for now - unit test DevicePreferencesEndpoint without client proxy - bump axios to resolve vulnerability
1 parent 25dbf42 commit 08d776b

File tree

7 files changed

+152
-187
lines changed

7 files changed

+152
-187
lines changed

package-lock.json

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"dependencies": {
2222
"async-mutex": "^0.2.1",
23-
"axios": "^0.21.1",
23+
"axios": "^0.21.4",
2424
"http-signature": "^1.3.4",
2525
"qs": "^6.9.3",
2626
"sshpk": "^1.16.1",

src/endpoint/devicepreferences.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { Endpoint } from '../endpoint'
22
import { EndpointClient, EndpointClientConfig } from '../endpoint-client'
3+
import { LocaleTag } from '../types'
34
import { PreferenceType } from './devices'
45

56

7+
/**
8+
* The ID of the preference
9+
* @pattern ^[[a-z]*([A-Z][a-z]*)*]{1,36}$
10+
*/
11+
export type PreferenceId = string
12+
613
export interface DevicePreferenceCore {
714
/**
815
* An alphanumeric English language name for this preference. Will be appended to a namespace
@@ -132,9 +139,33 @@ export type DevicePreferenceCreate = DevicePreferenceBase & {
132139
}
133140

134141
export type DevicePreference = DevicePreferenceBase & {
135-
preferenceId: string
142+
preferenceId: PreferenceId
136143
}
137144

145+
export interface PreferenceLocalization {
146+
/** The tag of the locale as defined in [RFC bcp47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt). */
147+
tag: LocaleTag
148+
149+
/**
150+
* A localized label for the Preference
151+
* @example Sensibilité au mouvement
152+
*/
153+
label: string
154+
155+
/**
156+
* A localized description of the Preference
157+
* @example Sensibilité au mouvement
158+
*/
159+
description?: string
160+
161+
/**
162+
* Map of an option name to localizations. Options can only be provided
163+
* to localize Enumeration type Preferences, and are required for Enumerations.
164+
* The number of options in a Preference Localization must match the number
165+
* of options in the Preference.
166+
*/
167+
options?: Record<string, { label: string }>
168+
}
138169

139170
export class DevicePreferencesEndpoint extends Endpoint {
140171
constructor(config: EndpointClientConfig) {
@@ -145,7 +176,7 @@ export class DevicePreferencesEndpoint extends Endpoint {
145176
return this.client.getPagedItems<DevicePreference>('', namespace ? { namespace } : {})
146177
}
147178

148-
public get(id: string): Promise<DevicePreference> {
179+
public get(id: PreferenceId): Promise<DevicePreference> {
149180
return this.client.get(id)
150181
}
151182

@@ -154,7 +185,15 @@ export class DevicePreferencesEndpoint extends Endpoint {
154185
return this.client.post(undefined, devicePreference)
155186
}
156187

157-
public update(id: string, devicePreferences: DevicePreference): Promise<DevicePreference> {
158-
return this.client.put(id, devicePreferences)
188+
public update(id: PreferenceId, devicePreference: DevicePreference): Promise<DevicePreference> {
189+
return this.client.put(id, devicePreference)
190+
}
191+
192+
public createLocalization(preferenceId: PreferenceId, localization: PreferenceLocalization): Promise<PreferenceLocalization> {
193+
return this.client.post(`${preferenceId}/i18n`, localization)
194+
}
195+
196+
public getLocalization(preferenceId: PreferenceId, locale: LocaleTag): Promise<PreferenceLocalization> {
197+
return this.client.get(`${preferenceId}/i18n/${locale}`)
159198
}
160199
}

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,12 @@ export interface IconImage {
4646
}
4747

4848
export interface LocaleReference {
49-
tag: string
49+
/** The tag of the locale as defined in [RFC bcp47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt). */
50+
tag: LocaleTag
5051
}
52+
53+
/**
54+
* The tag of the locale as defined in [RFC bcp47](http://www.rfc-editor.org/rfc/bcp/bcp47.txt).
55+
* @example en
56+
*/
57+
export type LocaleTag = string

test/unit/data/devicepreferences/get.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

test/unit/data/devicepreferences/post.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)