Skip to content

Commit af306a3

Browse files
authored
Implement request permission methods for Family Locator SDK (#250)
https://jira.tid.es/browse/WEB-2406 closes #249
1 parent 585d231 commit af306a3

7 files changed

Lines changed: 278 additions & 4 deletions

File tree

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,103 @@ Get current SDK config. Wrapper for `getConfig`.
18721872
getLocatorSdkConfig: () => Promise<{config: LocatorSdkConfig | null}>;
18731873
```
18741874
1875+
### requestPermissionLocation
1876+
1877+
<kbd>App version >= TBD</kbd>
1878+
1879+
Request location permission from the user.
1880+
1881+
```ts
1882+
requestPermissionLocation: () => Promise<{status: 'granted' | 'denied'}>;
1883+
```
1884+
1885+
#### Error cases
1886+
1887+
- 500: Internal Error
1888+
1889+
### requestPermissionBackgroundLocation
1890+
1891+
<kbd>App version >= TBD</kbd>
1892+
1893+
Request background location permission from the user.
1894+
1895+
```ts
1896+
requestPermissionBackgroundLocation: () => Promise<{
1897+
status: 'granted' | 'denied' | 'settings_change_required';
1898+
}>;
1899+
```
1900+
1901+
#### Notes
1902+
1903+
- Android: show a custom alert and navigate to OS settings on accept.
1904+
- iOS: upgrade to Always happens via OS escalation after background usage.
1905+
1906+
#### Error cases
1907+
1908+
- 500: Internal Error
1909+
1910+
### requestPermissionMicrophone
1911+
1912+
<kbd>App version >= TBD</kbd>
1913+
1914+
Request microphone permission from the user.
1915+
1916+
```ts
1917+
requestPermissionMicrophone: () => Promise<{status: 'granted' | 'denied'}>;
1918+
```
1919+
1920+
#### Error cases
1921+
1922+
- 500: Internal Error
1923+
1924+
### requestPermissionNotifications
1925+
1926+
<kbd>App version >= TBD</kbd>
1927+
1928+
Request standard notifications permission from the user.
1929+
1930+
```ts
1931+
requestPermissionNotifications: () => Promise<{status: 'granted' | 'denied'}>;
1932+
```
1933+
1934+
#### Error cases
1935+
1936+
- 500: Internal Error
1937+
1938+
### requestPermissionCriticalAlerts
1939+
1940+
<kbd>App version >= TBD</kbd>
1941+
1942+
Request critical alerts permission from the user (iOS only).
1943+
1944+
```ts
1945+
requestPermissionCriticalAlerts: () => Promise<{status: 'granted' | 'denied'}>;
1946+
```
1947+
1948+
#### Error cases
1949+
1950+
- 500: Internal Error
1951+
1952+
### requestPermissionBatteryOptimization
1953+
1954+
<kbd>App version >= TBD</kbd>
1955+
1956+
Request permission to disable battery optimization (Android only).
1957+
1958+
```ts
1959+
requestPermissionBatteryOptimization: () => Promise<{
1960+
status: 'denied' | 'settings_change_required';
1961+
}>;
1962+
```
1963+
1964+
#### Notes
1965+
1966+
- Android: show a custom alert and navigate to OS settings on accept.
1967+
1968+
#### Error cases
1969+
1970+
- 500: Internal Error
1971+
18751972
### openOcrScanner
18761973
18771974
<kbd>App version >=26.1</kbd>

index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,10 @@ export {
156156
getLocatorSdkSession,
157157
getLocatorSdkMode,
158158
getLocatorSdkConfig,
159+
requestPermissionLocation,
160+
requestPermissionBackgroundLocation,
161+
requestPermissionMicrophone,
162+
requestPermissionNotifications,
163+
requestPermissionCriticalAlerts,
164+
requestPermissionBatteryOptimization,
159165
} from './src/family-locator';

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
"ts-jest": "^27.1.1",
4545
"typescript": "^4.5.3",
4646
"uglify-es": "^3.3.9"
47-
}
47+
},
48+
"dependencies": {}
4849
}

src/__tests__/family-locator-test.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
getLocatorSdkSession,
99
getLocatorSdkMode,
1010
getLocatorSdkConfig,
11+
requestPermissionLocation,
12+
requestPermissionBackgroundLocation,
13+
requestPermissionMicrophone,
14+
requestPermissionNotifications,
15+
requestPermissionCriticalAlerts,
16+
requestPermissionBatteryOptimization,
1117
} from '../family-locator';
1218
import {
1319
createFakeAndroidPostMessage,
@@ -225,3 +231,99 @@ test('getLocatorSdkConfig', async () => {
225231
const res = await getLocatorSdkConfig();
226232
expect(res).toEqual({config});
227233
});
234+
235+
test('requestPermissionLocation', async () => {
236+
createFakeAndroidPostMessage({
237+
checkMessage: (msg) => {
238+
expect(msg.type).toBe('REQUEST_PERMISSION_LOCATION');
239+
},
240+
getResponse: (msg) => ({
241+
type: 'REQUEST_PERMISSION_LOCATION',
242+
id: msg.id,
243+
payload: {status: 'granted'},
244+
}),
245+
});
246+
247+
const res = await requestPermissionLocation();
248+
expect(res).toEqual({status: 'granted'});
249+
});
250+
251+
test('requestPermissionBackgroundLocation', async () => {
252+
createFakeAndroidPostMessage({
253+
checkMessage: (msg) => {
254+
expect(msg.type).toBe('REQUEST_PERMISSION_BACKGROUND_LOCATION');
255+
},
256+
getResponse: (msg) => ({
257+
type: 'REQUEST_PERMISSION_BACKGROUND_LOCATION',
258+
id: msg.id,
259+
payload: {status: 'settings_change_required'},
260+
}),
261+
});
262+
263+
const res = await requestPermissionBackgroundLocation();
264+
expect(res).toEqual({status: 'settings_change_required'});
265+
});
266+
267+
test('requestPermissionMicrophone', async () => {
268+
createFakeAndroidPostMessage({
269+
checkMessage: (msg) => {
270+
expect(msg.type).toBe('REQUEST_PERMISSION_MICROPHONE');
271+
},
272+
getResponse: (msg) => ({
273+
type: 'REQUEST_PERMISSION_MICROPHONE',
274+
id: msg.id,
275+
payload: {status: 'denied'},
276+
}),
277+
});
278+
279+
const res = await requestPermissionMicrophone();
280+
expect(res).toEqual({status: 'denied'});
281+
});
282+
283+
test('requestPermissionNotifications', async () => {
284+
createFakeAndroidPostMessage({
285+
checkMessage: (msg) => {
286+
expect(msg.type).toBe('REQUEST_PERMISSION_NOTIFICATIONS');
287+
},
288+
getResponse: (msg) => ({
289+
type: 'REQUEST_PERMISSION_NOTIFICATIONS',
290+
id: msg.id,
291+
payload: {status: 'granted'},
292+
}),
293+
});
294+
295+
const res = await requestPermissionNotifications();
296+
expect(res).toEqual({status: 'granted'});
297+
});
298+
299+
test('requestPermissionCriticalAlerts', async () => {
300+
createFakeAndroidPostMessage({
301+
checkMessage: (msg) => {
302+
expect(msg.type).toBe('REQUEST_PERMISSION_CRITICAL_ALERTS');
303+
},
304+
getResponse: (msg) => ({
305+
type: 'REQUEST_PERMISSION_CRITICAL_ALERTS',
306+
id: msg.id,
307+
payload: {status: 'denied'},
308+
}),
309+
});
310+
311+
const res = await requestPermissionCriticalAlerts();
312+
expect(res).toEqual({status: 'denied'});
313+
});
314+
315+
test('requestPermissionBatteryOptimization', async () => {
316+
createFakeAndroidPostMessage({
317+
checkMessage: (msg) => {
318+
expect(msg.type).toBe('REQUEST_PERMISSION_BATTERY_OPTIMIZATION');
319+
},
320+
getResponse: (msg) => ({
321+
type: 'REQUEST_PERMISSION_BATTERY_OPTIMIZATION',
322+
id: msg.id,
323+
payload: {status: 'settings_change_required'},
324+
}),
325+
});
326+
327+
const res = await requestPermissionBatteryOptimization();
328+
expect(res).toEqual({status: 'settings_change_required'});
329+
});

src/family-locator.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,29 @@ export const getLocatorSdkConfig = (): Promise<{
121121
postMessageToNativeApp({
122122
type: 'GET_LOCATOR_SDK_CONFIG',
123123
});
124+
125+
type PermissionStatus = 'granted' | 'denied';
126+
127+
export const requestPermissionLocation = (): Promise<{
128+
status: PermissionStatus;
129+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_LOCATION'});
130+
131+
export const requestPermissionBackgroundLocation = (): Promise<{
132+
status: PermissionStatus | 'settings_change_required';
133+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_BACKGROUND_LOCATION'});
134+
135+
export const requestPermissionMicrophone = (): Promise<{
136+
status: PermissionStatus;
137+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_MICROPHONE'});
138+
139+
export const requestPermissionNotifications = (): Promise<{
140+
status: PermissionStatus;
141+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_NOTIFICATIONS'});
142+
143+
export const requestPermissionCriticalAlerts = (): Promise<{
144+
status: PermissionStatus;
145+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_CRITICAL_ALERTS'});
146+
147+
export const requestPermissionBatteryOptimization = (): Promise<{
148+
status: 'denied' | 'settings_change_required';
149+
}> => postMessageToNativeApp({type: 'REQUEST_PERMISSION_BATTERY_OPTIMIZATION'});

src/post-message.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,48 @@ export type ResponsesFromNativeApp = {
169169
granted: boolean;
170170
};
171171
};
172+
REQUEST_PERMISSION_LOCATION: {
173+
id: string;
174+
type: 'REQUEST_PERMISSION_LOCATION';
175+
payload: {
176+
status: 'granted' | 'denied';
177+
};
178+
};
179+
REQUEST_PERMISSION_BACKGROUND_LOCATION: {
180+
id: string;
181+
type: 'REQUEST_PERMISSION_BACKGROUND_LOCATION';
182+
payload: {
183+
status: 'granted' | 'denied' | 'settings_change_required';
184+
};
185+
};
186+
REQUEST_PERMISSION_MICROPHONE: {
187+
id: string;
188+
type: 'REQUEST_PERMISSION_MICROPHONE';
189+
payload: {
190+
status: 'granted' | 'denied';
191+
};
192+
};
193+
REQUEST_PERMISSION_NOTIFICATIONS: {
194+
id: string;
195+
type: 'REQUEST_PERMISSION_NOTIFICATIONS';
196+
payload: {
197+
status: 'granted' | 'denied';
198+
};
199+
};
200+
REQUEST_PERMISSION_CRITICAL_ALERTS: {
201+
id: string;
202+
type: 'REQUEST_PERMISSION_CRITICAL_ALERTS';
203+
payload: {
204+
status: 'granted' | 'denied';
205+
};
206+
};
207+
REQUEST_PERMISSION_BATTERY_OPTIMIZATION: {
208+
id: string;
209+
type: 'REQUEST_PERMISSION_BATTERY_OPTIMIZATION';
210+
payload: {
211+
status: 'denied' | 'settings_change_required';
212+
};
213+
};
172214
INTERNAL_NAVIGATION: {
173215
type: 'INTERNAL_NAVIGATION';
174216
id: string;

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,9 +1032,9 @@ camelcase@^6.2.0:
10321032
integrity sha512-tVI4q5jjFV5CavAU8DXfza/TJcZutVKo/5Foskmsqcm0MsL91moHvwiGNnqaa2o6PF/7yT5ikDRcVcl8Rj6LCA==
10331033

10341034
caniuse-lite@^1.0.30001286:
1035-
version "1.0.30001641"
1036-
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001641.tgz"
1037-
integrity sha512-Phv5thgl67bHYo1TtMY/MurjkHhV4EDaCosezRXgZ8jzA/Ub+wjxAvbGvjoFENStinwi5kCyOYV3mi5tOGykwA==
1035+
version "1.0.30001774"
1036+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001774.tgz"
1037+
integrity sha512-DDdwPGz99nmIEv216hKSgLD+D4ikHQHjBC/seF98N9CPqRX4M5mSxT9eTV6oyisnJcuzxtZy4n17yKKQYmYQOA==
10381038

10391039
chalk@^2.0.0:
10401040
version "2.4.2"

0 commit comments

Comments
 (0)