(
38 | Component: ComponentType
39 | ): ComponentType
{
40 | return function ManagedConfigComponent(props: P) {
41 | return (
42 |
43 | {(managedConfig: T) => (
44 |
45 | )}
46 |
47 | );
48 | };
49 | }
50 |
51 | export default Context;
52 |
--------------------------------------------------------------------------------
/src/emm-native.ts:
--------------------------------------------------------------------------------
1 | export default require("./NativeEmm").default;
--------------------------------------------------------------------------------
/src/emm.ts:
--------------------------------------------------------------------------------
1 | import {
2 | NativeEventEmitter,
3 | Platform,
4 | } from 'react-native';
5 |
6 | import type {
7 | AuthenticateConfig,
8 | AuthenticationMethods,
9 | } from './types/authenticate';
10 | import type {
11 | EnterpriseMobilityManager,
12 | ManagedConfigCallBack,
13 | } from './types/managed';
14 |
15 | import RNEmm from './emm-native';
16 |
17 | const emitter = new NativeEventEmitter(RNEmm);
18 |
19 | const Emm: EnterpriseMobilityManager = {
20 | addListener: (callback: ManagedConfigCallBack) => {
21 | return emitter.addListener('managedConfigChanged', (config: T) => {
22 | callback(config);
23 | });
24 | },
25 | authenticate: async (opts: AuthenticateConfig) => {
26 | try {
27 | const options: AuthenticateConfig = {
28 | reason: opts.reason || '',
29 | description: opts.description || '',
30 | fallback: opts.fallback || true,
31 | supressEnterPassword: opts.supressEnterPassword || false,
32 | blurOnAuthenticate: opts.blurOnAuthenticate || false,
33 | };
34 |
35 | await RNEmm.authenticate(options);
36 |
37 | return true;
38 | } catch {
39 | return false;
40 | }
41 | },
42 | getManagedConfig: () => RNEmm.getManagedConfig() as T,
43 | isDeviceSecured: async () => {
44 | try {
45 | const result: AuthenticationMethods = await RNEmm.deviceSecureWith();
46 | return result.face || result.fingerprint || result.passcode;
47 | } catch {
48 | return false;
49 | }
50 | },
51 | openSecuritySettings: () => {
52 | if (Platform.OS === 'android') {
53 | RNEmm.openSecuritySettings();
54 | }
55 | },
56 | setAppGroupId: (identifier: string) => {
57 | if (Platform.OS === 'ios') {
58 | RNEmm.setAppGroupId(identifier);
59 | }
60 | },
61 | deviceSecureWith: function (): Promise {
62 | return RNEmm.deviceSecureWith();
63 | },
64 | enableBlurScreen: function (enabled: boolean): void {
65 | return RNEmm.setBlurScreen(enabled);
66 | },
67 | applyBlurEffect: (radius = 8) => RNEmm.applyBlurEffect(radius),
68 | removeBlurEffect: () => RNEmm.removeBlurEffect(),
69 | exitApp: function (): void {
70 | RNEmm.exitApp();
71 | }
72 | };
73 |
74 | export default Emm;
75 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './context';
2 | import Emm from './emm';
3 | export * from './types/authenticate';
4 | export * from './types/managed';
5 |
6 | export default Emm;
7 |
--------------------------------------------------------------------------------
/src/types/authenticate.ts:
--------------------------------------------------------------------------------
1 | export type AuthenticateConfig = {
2 | reason?: string;
3 | description?: string;
4 | fallback?: boolean;
5 | supressEnterPassword?: boolean;
6 | blurOnAuthenticate?: boolean;
7 | };
8 |
9 | export type AuthenticationMethods = {
10 | readonly face: boolean;
11 | readonly fingerprint: boolean;
12 | readonly passcode: boolean;
13 | };
14 |
--------------------------------------------------------------------------------
/src/types/managed.ts:
--------------------------------------------------------------------------------
1 | import type { EmitterSubscription } from 'react-native';
2 | import type { AuthenticateConfig, AuthenticationMethods } from './authenticate';
3 |
4 | export type ManagedConfigCallBack = {
5 | (config: T): void;
6 | };
7 |
8 | export interface EnterpriseMobilityManager {
9 | addListener(callback: ManagedConfigCallBack): EmitterSubscription;
10 |
11 | authenticate(opts: AuthenticateConfig): Promise;
12 |
13 | deviceSecureWith(): Promise;
14 |
15 | enableBlurScreen(enabled: boolean): void;
16 |
17 | applyBlurEffect: (radius: number) => void;
18 |
19 | removeBlurEffect: () => void;
20 |
21 | exitApp(): void;
22 |
23 | getManagedConfig(): T;
24 |
25 | isDeviceSecured(): Promise;
26 |
27 | openSecuritySettings(): void;
28 |
29 | setAppGroupId(identifier: string): void;
30 | }
31 |
--------------------------------------------------------------------------------
/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": ["example"]
4 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "paths": {
5 | "@mattermost/react-native-emm": ["./src/index.ts"]
6 | },
7 | "allowSyntheticDefaultImports": true,
8 | "allowUnreachableCode": false,
9 | "allowUnusedLabels": false,
10 | "esModuleInterop": true,
11 | "verbatimModuleSyntax": true,
12 | "forceConsistentCasingInFileNames": true,
13 | "jsx": "react-native",
14 | "lib": ["esnext"],
15 | "types": ["react-native", "jest"],
16 | "isolatedModules": true,
17 | "module": "esnext",
18 | "moduleResolution": "node",
19 | "noFallthroughCasesInSwitch": true,
20 | "noImplicitReturns": true,
21 | "noImplicitUseStrict": false,
22 | "noStrictGenericChecks": false,
23 | "noUnusedLocals": true,
24 | "noUnusedParameters": true,
25 | "resolveJsonModule": true,
26 | "skipLibCheck": true,
27 | "strict": true,
28 | "target": "esnext",
29 | },
30 | }
31 |
--------------------------------------------------------------------------------