@rownd/react-native 0.2.5 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +34 -52
- package/android/build.gradle +127 -37
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/reactnativerowndplugin/RowndPluginModule.kt +98 -0
- package/android/src/main/java/com/reactnativerowndplugin/RowndPluginPackage.kt +16 -0
- package/ios/{ReactNative.xcodeproj → Rownd.xcodeproj}/project.pbxproj +13 -12
- package/ios/RowndPlugin-Bridging-Header.h +3 -0
- package/ios/RowndPlugin.m +26 -0
- package/ios/RowndPlugin.swift +83 -0
- package/ios/RowndPluginEventEmitter.m +12 -0
- package/ios/RowndPluginEventEmitter.swift +19 -0
- package/lib/commonjs/components/GlobalContext.js +32 -298
- package/lib/commonjs/components/GlobalContext.js.map +1 -1
- package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
- package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
- package/lib/commonjs/constants/action.js +13 -0
- package/lib/commonjs/constants/action.js.map +1 -0
- package/lib/commonjs/hooks/rownd.js +15 -146
- package/lib/commonjs/hooks/rownd.js.map +1 -1
- package/lib/commonjs/index.js +2 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/reducer/rowndReducer.js +89 -0
- package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
- package/lib/commonjs/utils/config.js +0 -26
- package/lib/commonjs/utils/config.js.map +1 -1
- package/lib/commonjs/utils/nativeModule.js +72 -0
- package/lib/commonjs/utils/nativeModule.js.map +1 -0
- package/lib/module/components/GlobalContext.js +30 -293
- package/lib/module/components/GlobalContext.js.map +1 -1
- package/lib/module/components/GlobalContext.types.js +2 -0
- package/lib/module/components/GlobalContext.types.js.map +1 -0
- package/lib/module/constants/action.js +6 -0
- package/lib/module/constants/action.js.map +1 -0
- package/lib/module/hooks/rownd.js +12 -137
- package/lib/module/hooks/rownd.js.map +1 -1
- package/lib/module/index.js +2 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/reducer/rowndReducer.js +78 -0
- package/lib/module/reducer/rowndReducer.js.map +1 -0
- package/lib/module/utils/config.js +1 -16
- package/lib/module/utils/config.js.map +1 -1
- package/lib/module/utils/nativeModule.js +48 -0
- package/lib/module/utils/nativeModule.js.map +1 -0
- package/lib/typescript/components/GlobalContext.d.ts +13 -0
- package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
- package/lib/typescript/constants/action.d.ts +7 -0
- package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
- package/lib/typescript/utils/config.d.ts +10 -0
- package/lib/typescript/utils/nativeModule.d.ts +10 -0
- package/package.json +36 -56
- package/rownd-react-native.podspec +36 -0
- package/src/components/GlobalContext.tsx +47 -457
- package/src/components/GlobalContext.types.ts +105 -0
- package/src/constants/action.ts +8 -0
- package/src/hooks/rownd.ts +29 -147
- package/src/index.tsx +2 -4
- package/src/reducer/rowndReducer.ts +78 -0
- package/src/utils/config.ts +0 -27
- package/src/utils/nativeModule.ts +69 -0
- package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
- package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
- package/ios/ReactNativeViewManager.m +0 -34
- package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
- package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
- package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
- package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
- package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
- package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
- package/lib/commonjs/components/AutoSigninDialog.js +0 -132
- package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
- package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
- package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
- package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
- package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
- package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
- package/lib/commonjs/components/DarkText.js +0 -35
- package/lib/commonjs/components/DarkText.js.map +0 -1
- package/lib/commonjs/components/DefaultContext.js +0 -266
- package/lib/commonjs/components/DefaultContext.js.map +0 -1
- package/lib/commonjs/components/RowndComponents.js +0 -25
- package/lib/commonjs/components/RowndComponents.js.map +0 -1
- package/lib/commonjs/components/RowndProvider.js +0 -55
- package/lib/commonjs/components/RowndProvider.js.map +0 -1
- package/lib/commonjs/components/SignIn.js +0 -644
- package/lib/commonjs/components/SignIn.js.map +0 -1
- package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
- package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
- package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
- package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
- package/lib/commonjs/components/images/ErrorIcon.js +0 -31
- package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
- package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
- package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
- package/lib/commonjs/data/actions.js +0 -26
- package/lib/commonjs/data/actions.js.map +0 -1
- package/lib/commonjs/hooks/api.js +0 -155
- package/lib/commonjs/hooks/api.js.map +0 -1
- package/lib/commonjs/hooks/debounce.js +0 -38
- package/lib/commonjs/hooks/debounce.js.map +0 -1
- package/lib/commonjs/hooks/fingerprint.js +0 -176
- package/lib/commonjs/hooks/fingerprint.js.map +0 -1
- package/lib/commonjs/hooks/index.js +0 -48
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/interval.js +0 -31
- package/lib/commonjs/hooks/interval.js.map +0 -1
- package/lib/commonjs/hooks/nav.js +0 -39
- package/lib/commonjs/hooks/nav.js.map +0 -1
- package/lib/commonjs/index.tsx.bak +0 -26
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/utils/events.js +0 -57
- package/lib/commonjs/utils/events.js.map +0 -1
- package/lib/commonjs/utils/form.js +0 -46
- package/lib/commonjs/utils/form.js.map +0 -1
- package/lib/commonjs/utils/queue.js +0 -117
- package/lib/commonjs/utils/queue.js.map +0 -1
- package/lib/commonjs/utils/storage.js +0 -15
- package/lib/commonjs/utils/storage.js.map +0 -1
- package/lib/commonjs/utils/tokens.js +0 -35
- package/lib/commonjs/utils/tokens.js.map +0 -1
- package/lib/commonjs/utils/user-data.js +0 -21
- package/lib/commonjs/utils/user-data.js.map +0 -1
- package/lib/module/assets/images/checkmark--filled.svg +0 -12
- package/lib/module/assets/images/email-verify-waiting.svg +0 -36
- package/lib/module/assets/images/error-icon-material.svg +0 -1
- package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
- package/lib/module/components/AuthenticatedComponent.js +0 -24
- package/lib/module/components/AuthenticatedComponent.js.map +0 -1
- package/lib/module/components/AutoSigninDialog.js +0 -110
- package/lib/module/components/AutoSigninDialog.js.map +0 -1
- package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
- package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
- package/lib/module/components/BottomSheetTextInput/index.js +0 -5
- package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
- package/lib/module/components/BottomSheetTextInput/types.js +0 -2
- package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
- package/lib/module/components/DarkText.js +0 -24
- package/lib/module/components/DarkText.js.map +0 -1
- package/lib/module/components/DefaultContext.js +0 -244
- package/lib/module/components/DefaultContext.js.map +0 -1
- package/lib/module/components/RowndComponents.js +0 -12
- package/lib/module/components/RowndComponents.js.map +0 -1
- package/lib/module/components/RowndProvider.js +0 -39
- package/lib/module/components/RowndProvider.js.map +0 -1
- package/lib/module/components/SignIn.js +0 -616
- package/lib/module/components/SignIn.js.map +0 -1
- package/lib/module/components/images/CheckmarkFilled.js +0 -27
- package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
- package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
- package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
- package/lib/module/components/images/ErrorIcon.js +0 -18
- package/lib/module/components/images/ErrorIcon.js.map +0 -1
- package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
- package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
- package/lib/module/data/actions.js +0 -19
- package/lib/module/data/actions.js.map +0 -1
- package/lib/module/hooks/api.js +0 -135
- package/lib/module/hooks/api.js.map +0 -1
- package/lib/module/hooks/debounce.js +0 -29
- package/lib/module/hooks/debounce.js.map +0 -1
- package/lib/module/hooks/fingerprint.js +0 -157
- package/lib/module/hooks/fingerprint.js.map +0 -1
- package/lib/module/hooks/index.js +0 -7
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/hooks/interval.js +0 -23
- package/lib/module/hooks/interval.js.map +0 -1
- package/lib/module/hooks/nav.js +0 -30
- package/lib/module/hooks/nav.js.map +0 -1
- package/lib/module/index.tsx.bak +0 -26
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/events.js +0 -45
- package/lib/module/utils/events.js.map +0 -1
- package/lib/module/utils/form.js +0 -34
- package/lib/module/utils/form.js.map +0 -1
- package/lib/module/utils/queue.js +0 -109
- package/lib/module/utils/queue.js.map +0 -1
- package/lib/module/utils/storage.js +0 -6
- package/lib/module/utils/storage.js.map +0 -1
- package/lib/module/utils/tokens.js +0 -24
- package/lib/module/utils/tokens.js.map +0 -1
- package/lib/module/utils/user-data.js +0 -14
- package/lib/module/utils/user-data.js.map +0 -1
- package/lib/package.json +0 -173
- package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
- package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
- package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
- package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
- package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
- package/lib/typescript/src/components/DarkText.d.ts +0 -3
- package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
- package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
- package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
- package/lib/typescript/src/components/SignIn.d.ts +0 -2
- package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
- package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
- package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
- package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
- package/lib/typescript/src/data/actions.d.ts +0 -20
- package/lib/typescript/src/hooks/api.d.ts +0 -12
- package/lib/typescript/src/hooks/debounce.d.ts +0 -5
- package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
- package/lib/typescript/src/hooks/index.d.ts +0 -6
- package/lib/typescript/src/hooks/interval.d.ts +0 -2
- package/lib/typescript/src/hooks/nav.d.ts +0 -6
- package/lib/typescript/src/index.d.ts +0 -4
- package/lib/typescript/src/types.d.ts +0 -26
- package/lib/typescript/src/utils/config.d.ts +0 -18
- package/lib/typescript/src/utils/events.d.ts +0 -22
- package/lib/typescript/src/utils/form.d.ts +0 -18
- package/lib/typescript/src/utils/queue.d.ts +0 -21
- package/lib/typescript/src/utils/storage.d.ts +0 -3
- package/lib/typescript/src/utils/tokens.d.ts +0 -4
- package/lib/typescript/src/utils/user-data.d.ts +0 -3
- package/react-native.podspec +0 -19
- package/src/assets/images/checkmark--filled.svg +0 -12
- package/src/assets/images/email-verify-waiting.svg +0 -36
- package/src/assets/images/error-icon-material.svg +0 -1
- package/src/assets/images/phone-verify-waiting.svg +0 -26
- package/src/components/AuthenticatedComponent.tsx +0 -30
- package/src/components/AutoSigninDialog.tsx +0 -131
- package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
- package/src/components/BottomSheetTextInput/index.ts +0 -5
- package/src/components/BottomSheetTextInput/types.ts +0 -3
- package/src/components/DarkText.tsx +0 -16
- package/src/components/DefaultContext.tsx +0 -278
- package/src/components/RowndComponents.tsx +0 -18
- package/src/components/RowndProvider.tsx +0 -56
- package/src/components/SignIn.tsx +0 -797
- package/src/components/images/CheckmarkFilled.tsx +0 -30
- package/src/components/images/EmailVerifyWaiting.tsx +0 -95
- package/src/components/images/ErrorIcon.tsx +0 -11
- package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
- package/src/data/actions.ts +0 -21
- package/src/hooks/api.ts +0 -162
- package/src/hooks/debounce.ts +0 -36
- package/src/hooks/fingerprint.ts +0 -217
- package/src/hooks/index.ts +0 -7
- package/src/hooks/interval.ts +0 -25
- package/src/hooks/nav.tsx +0 -29
- package/src/index.tsx.bak +0 -26
- package/src/types.ts +0 -27
- package/src/utils/events.ts +0 -54
- package/src/utils/form.tsx +0 -64
- package/src/utils/queue.ts +0 -75
- package/src/utils/storage.ts +0 -7
- package/src/utils/tokens.ts +0 -26
- package/src/utils/user-data.ts +0 -15
|
@@ -1,476 +1,66 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
event_id: string;
|
|
22
|
-
section: string;
|
|
23
|
-
options?: any;
|
|
24
|
-
};
|
|
25
|
-
user: {
|
|
26
|
-
data: {
|
|
27
|
-
id?: string;
|
|
28
|
-
email: string | null;
|
|
29
|
-
[key: string]: any;
|
|
30
|
-
};
|
|
31
|
-
needs_refresh?: boolean;
|
|
32
|
-
redacted: string[];
|
|
33
|
-
};
|
|
34
|
-
auth: {
|
|
35
|
-
access_token: string | null;
|
|
36
|
-
refresh_token: string | null;
|
|
37
|
-
app_id: string | null;
|
|
38
|
-
init_data?: Record<string, any>;
|
|
39
|
-
is_verified_user?: boolean;
|
|
40
|
-
};
|
|
41
|
-
app: {
|
|
42
|
-
id?: string;
|
|
43
|
-
icon?: string;
|
|
44
|
-
icon_content_type?: string;
|
|
45
|
-
config: AppConfig | null;
|
|
46
|
-
schema: AppSchema | null;
|
|
47
|
-
user_verification_field?: string;
|
|
48
|
-
user_verification_fields?: string[];
|
|
49
|
-
};
|
|
50
|
-
local_acls: Record<string, { shared: boolean }> | null;
|
|
51
|
-
is_saving_user_data: boolean;
|
|
52
|
-
config?: IConfig;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
type AppSchema = Record<string, SchemaField>;
|
|
56
|
-
|
|
57
|
-
export interface SchemaField {
|
|
58
|
-
display_name: string;
|
|
59
|
-
type: string;
|
|
60
|
-
data_category: string;
|
|
61
|
-
required: boolean;
|
|
62
|
-
owned_by: string;
|
|
63
|
-
user_visible: boolean;
|
|
64
|
-
revoke_after: string;
|
|
65
|
-
required_retention: string;
|
|
66
|
-
collection_justification: string;
|
|
67
|
-
opt_out_warning: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface AppConfig {
|
|
71
|
-
customizations: {
|
|
72
|
-
primary_color: string;
|
|
73
|
-
};
|
|
74
|
-
default_user_id_format?: string;
|
|
75
|
-
hub: {
|
|
76
|
-
auth: {
|
|
77
|
-
allow_unverified_users?: boolean;
|
|
78
|
-
additional_fields: [
|
|
79
|
-
{
|
|
80
|
-
name: string;
|
|
81
|
-
type: string;
|
|
82
|
-
label: string;
|
|
83
|
-
placeholder?: string;
|
|
84
|
-
options: [
|
|
85
|
-
{
|
|
86
|
-
value: string;
|
|
87
|
-
label: string;
|
|
88
|
-
}
|
|
89
|
-
];
|
|
90
|
-
}
|
|
91
|
-
];
|
|
92
|
-
email: {
|
|
93
|
-
from_address: string;
|
|
94
|
-
image: string;
|
|
95
|
-
};
|
|
96
|
-
show_app_icon: boolean;
|
|
97
|
-
};
|
|
98
|
-
customizations: HubCustomizations;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface HubCustomizations {
|
|
103
|
-
rounded_corners: boolean;
|
|
104
|
-
primary_color: string;
|
|
105
|
-
placement: 'bottom-left' | 'hidden';
|
|
106
|
-
offset_x: number;
|
|
107
|
-
offset_y: number;
|
|
108
|
-
property_overrides: Record<string, string>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type ContextProps = {
|
|
112
|
-
config: IConfig;
|
|
113
|
-
};
|
|
1
|
+
import React, {
|
|
2
|
+
useReducer,
|
|
3
|
+
createContext,
|
|
4
|
+
FunctionComponent,
|
|
5
|
+
useEffect,
|
|
6
|
+
useContext,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import { NativeEventEmitter, YellowBox, Platform } from 'react-native';
|
|
9
|
+
import { initialRowndState, rowndReducer } from '../reducer/rowndReducer';
|
|
10
|
+
|
|
11
|
+
import * as NativeRowndModules from '../utils/nativeModule';
|
|
12
|
+
import { Rownd, IOSRowndEventEmitter } from '../utils/nativeModule';
|
|
13
|
+
import type { ContextProps, GlobalState } from './GlobalContext.types';
|
|
14
|
+
import type { TAction } from '../constants/action';
|
|
15
|
+
import { ActionType } from '../constants/action';
|
|
16
|
+
|
|
17
|
+
YellowBox.ignoreWarnings([
|
|
18
|
+
'Sending `update_state` with no listeners registered.',
|
|
19
|
+
]);
|
|
20
|
+
YellowBox.ignoreWarnings(['YellowBox has been replaced with LogBox.']);
|
|
114
21
|
|
|
115
22
|
export const GlobalContext = createContext<
|
|
116
|
-
{ state: GlobalState; dispatch: Dispatch } | undefined
|
|
23
|
+
{ state: GlobalState; dispatch: React.Dispatch<TAction> } | undefined
|
|
117
24
|
>(undefined);
|
|
118
25
|
|
|
119
|
-
|
|
120
|
-
if (storage.contains('state')) {
|
|
121
|
-
const state = JSON.parse(storage.getString('state') || '{}');
|
|
26
|
+
const eventEmitter = new NativeEventEmitter(IOSRowndEventEmitter || Rownd);
|
|
122
27
|
|
|
123
|
-
|
|
124
|
-
...initialState,
|
|
125
|
-
...state,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return initialState;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// async function updateStorage(newState: any) {
|
|
133
|
-
// const oldState = JSON.parse(await storage.getItem('state') || '{}');
|
|
134
|
-
|
|
135
|
-
// if (!isEqual(oldState, newState)) {
|
|
136
|
-
// console.log('writing new state', newState);
|
|
137
|
-
// await storage.setItem('state', JSON.stringify(newState));
|
|
138
|
-
// }
|
|
139
|
-
// }
|
|
140
|
-
|
|
141
|
-
const GlobalContextProvider: FunctionComponent<ContextProps> = ({
|
|
28
|
+
const RowndProvider: FunctionComponent<ContextProps> = ({
|
|
142
29
|
children,
|
|
143
30
|
config,
|
|
144
31
|
}) => {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
is_container_visible: false,
|
|
148
|
-
use_modal: false,
|
|
149
|
-
nav: {
|
|
150
|
-
current_route: '/',
|
|
151
|
-
route_trigger: '',
|
|
152
|
-
event_id: '',
|
|
153
|
-
section: '',
|
|
154
|
-
options: {},
|
|
155
|
-
},
|
|
156
|
-
user: {
|
|
157
|
-
data: {
|
|
158
|
-
email: null,
|
|
159
|
-
},
|
|
160
|
-
needs_refresh: false,
|
|
161
|
-
redacted: [],
|
|
162
|
-
},
|
|
163
|
-
auth: {
|
|
164
|
-
access_token: null,
|
|
165
|
-
refresh_token: null,
|
|
166
|
-
app_id: null,
|
|
167
|
-
},
|
|
168
|
-
app: {
|
|
169
|
-
schema: null,
|
|
170
|
-
config: null,
|
|
171
|
-
},
|
|
172
|
-
local_acls: null,
|
|
173
|
-
is_saving_user_data: false,
|
|
174
|
-
config,
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// TODO: There's a better way to do this where we have a set of rules that watch/apply to the state as it changes
|
|
178
|
-
// function dispatchExternalEvents(prevState: GlobalState, nextState: GlobalState) {
|
|
179
|
-
|
|
180
|
-
// // Log in, get new token, load previous auth state, etc
|
|
181
|
-
// if (prevState.auth.access_token !== nextState.auth.access_token) {
|
|
182
|
-
// events.dispatch(EventType.AUTH, {
|
|
183
|
-
// access_token: nextState.auth.access_token,
|
|
184
|
-
// user_id: nextState.user.data.id,
|
|
185
|
-
// app_id: nextState.auth.app_id,
|
|
186
|
-
// });
|
|
187
|
-
// }
|
|
188
|
-
|
|
189
|
-
// // User data changes. Also, fire the event when ACLs change since this affects the data
|
|
190
|
-
// // that the application can see.
|
|
191
|
-
// if (!isEqual(prevState.local_acls, nextState.local_acls) ||
|
|
192
|
-
// !isEqual(prevState.user.data, nextState.user.data)) {
|
|
193
|
-
// events.dispatch(EventType.USER_DATA, {
|
|
194
|
-
// // The data is filtered on the local_acls
|
|
195
|
-
// data: redactUserDataWithAcls(nextState.user.data, nextState.local_acls),
|
|
196
|
-
// });
|
|
197
|
-
// }
|
|
198
|
-
|
|
199
|
-
// // Log out
|
|
200
|
-
// if (nextState.auth.access_token === null) {
|
|
201
|
-
// events.dispatch(EventType.SIGN_OUT, {});
|
|
202
|
-
// }
|
|
203
|
-
// }
|
|
204
|
-
|
|
205
|
-
function mainReducer(state: GlobalState, action: TAction): GlobalState {
|
|
206
|
-
let decodedToken: any;
|
|
207
|
-
|
|
208
|
-
let newState;
|
|
209
|
-
// let cachedAuth;
|
|
210
|
-
switch (action.type) {
|
|
211
|
-
case ActionType.SET_CONTAINER_VISIBLE:
|
|
212
|
-
newState = {
|
|
213
|
-
...state,
|
|
214
|
-
is_container_visible: action.payload.isVisible,
|
|
215
|
-
use_modal:
|
|
216
|
-
action.payload.isVisible === false ? false : state.use_modal,
|
|
217
|
-
nav: {
|
|
218
|
-
...state.nav,
|
|
219
|
-
current_route: '/',
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
break;
|
|
223
|
-
|
|
224
|
-
case ActionType.CHANGE_ROUTE:
|
|
225
|
-
newState = {
|
|
226
|
-
...state,
|
|
227
|
-
nav: {
|
|
228
|
-
...state.nav,
|
|
229
|
-
current_route: action.payload.route,
|
|
230
|
-
route_trigger: action.payload.trigger || '',
|
|
231
|
-
event_id: action.payload.event_id,
|
|
232
|
-
options: action.payload.opts,
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
break;
|
|
237
|
-
|
|
238
|
-
case ActionType.SET_SECTION:
|
|
239
|
-
newState = {
|
|
240
|
-
...state,
|
|
241
|
-
nav: {
|
|
242
|
-
...state.nav,
|
|
243
|
-
section: action.payload.section,
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
break;
|
|
247
|
-
|
|
248
|
-
case ActionType.LOGIN_SUCCESS:
|
|
249
|
-
// storage.setItem('auth', JSON.stringify(action.payload));
|
|
250
|
-
decodedToken = jwt_decode(action.payload.access_token);
|
|
251
|
-
|
|
252
|
-
// Ensure this token is for this app
|
|
253
|
-
if (action.payload.app_id !== state.app.id) {
|
|
254
|
-
return {
|
|
255
|
-
...state,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
newState = {
|
|
260
|
-
...state,
|
|
261
|
-
auth: {
|
|
262
|
-
...state.auth,
|
|
263
|
-
access_token: action.payload.access_token,
|
|
264
|
-
refresh_token: action.payload.refresh_token,
|
|
265
|
-
app_id: action.payload.app_id,
|
|
266
|
-
is_verified_user:
|
|
267
|
-
decodedToken?.['https://auth.rownd.io/is_verified_user'] !==
|
|
268
|
-
false, // default is `true` if the attribute doesn't exist
|
|
269
|
-
},
|
|
270
|
-
user: {
|
|
271
|
-
...state.user,
|
|
272
|
-
data: {
|
|
273
|
-
...state.user.data,
|
|
274
|
-
id: action.payload.app_user_id,
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
break;
|
|
279
|
-
|
|
280
|
-
case ActionType.SIGN_OUT:
|
|
281
|
-
// storage.removeItem('auth');
|
|
282
|
-
newState = {
|
|
283
|
-
...state,
|
|
284
|
-
user: {
|
|
285
|
-
data: {
|
|
286
|
-
email: null,
|
|
287
|
-
},
|
|
288
|
-
redacted: [],
|
|
289
|
-
},
|
|
290
|
-
auth: {
|
|
291
|
-
access_token: null,
|
|
292
|
-
refresh_token: null,
|
|
293
|
-
app_id: null,
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
break;
|
|
297
|
-
|
|
298
|
-
case ActionType.REFRESH_TOKEN:
|
|
299
|
-
newState = {
|
|
300
|
-
...state,
|
|
301
|
-
auth: {
|
|
302
|
-
...state.auth,
|
|
303
|
-
access_token: action.payload.access_token,
|
|
304
|
-
refresh_token: action.payload.refresh_token,
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
// cachedAuth = storage.getItem('auth');
|
|
309
|
-
// if (cachedAuth) {
|
|
310
|
-
// const cachedAuthObj = JSON.parse(cachedAuth);
|
|
311
|
-
// cachedAuth = {
|
|
312
|
-
// ...cachedAuthObj,
|
|
313
|
-
// ...newState.auth,
|
|
314
|
-
// };
|
|
315
|
-
// storage.setItem('auth', JSON.stringify(newState.auth));
|
|
316
|
-
// }
|
|
317
|
-
|
|
318
|
-
break;
|
|
319
|
-
|
|
320
|
-
case ActionType.LOAD_USER:
|
|
321
|
-
newState = {
|
|
322
|
-
...state,
|
|
323
|
-
user: {
|
|
324
|
-
...state.user,
|
|
325
|
-
data: {
|
|
326
|
-
...action.payload.data,
|
|
327
|
-
},
|
|
328
|
-
redacted: action.payload.redacted,
|
|
329
|
-
},
|
|
330
|
-
};
|
|
331
|
-
break;
|
|
332
|
-
|
|
333
|
-
case ActionType.UPDATE_LOCAL_ACLS:
|
|
334
|
-
newState = {
|
|
335
|
-
...state,
|
|
336
|
-
local_acls: {
|
|
337
|
-
...state.local_acls,
|
|
338
|
-
...action.payload,
|
|
339
|
-
},
|
|
340
|
-
};
|
|
341
|
-
break;
|
|
342
|
-
|
|
343
|
-
case ActionType.SET_USER_DATA_FIELD:
|
|
344
|
-
// Dispatch a USER_DATA_SAVED event to satisfy event listeners when the data
|
|
345
|
-
// was not changed and no request to Rownd was ever made.
|
|
346
|
-
if (state.user.data[action.payload.field] === action.payload.value) {
|
|
347
|
-
events.dispatch(EventType.USER_DATA_SAVED, state.user.data);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
newState = {
|
|
351
|
-
...state,
|
|
352
|
-
user: {
|
|
353
|
-
...state.user,
|
|
354
|
-
data: {
|
|
355
|
-
...state.user.data,
|
|
356
|
-
[action.payload.field]: action.payload.value,
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
|
-
break;
|
|
361
|
-
|
|
362
|
-
case ActionType.SET_USER_DATA:
|
|
363
|
-
// Dispatch a USER_DATA_SAVED event to satisfy event listeners when the data
|
|
364
|
-
// was not changed and no request to Rownd was ever made.
|
|
365
|
-
if (
|
|
366
|
-
isEqual(
|
|
367
|
-
pick(state.user.data, Object.keys(action.payload.data)),
|
|
368
|
-
action.payload.data
|
|
369
|
-
)
|
|
370
|
-
) {
|
|
371
|
-
events.dispatch(EventType.USER_DATA_SAVED, state.user.data);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
newState = {
|
|
375
|
-
...state,
|
|
376
|
-
user: {
|
|
377
|
-
...state.user,
|
|
378
|
-
data: {
|
|
379
|
-
...state.user.data,
|
|
380
|
-
...action.payload.data,
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
};
|
|
384
|
-
break;
|
|
385
|
-
|
|
386
|
-
case ActionType.SET_REFRESH_USER_DATA:
|
|
387
|
-
newState = {
|
|
388
|
-
...state,
|
|
389
|
-
user: {
|
|
390
|
-
...state.user,
|
|
391
|
-
needs_refresh: action.payload.needs_refresh,
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
break;
|
|
395
|
-
|
|
396
|
-
case ActionType.LOAD_STATE:
|
|
397
|
-
newState = {
|
|
398
|
-
...action.payload,
|
|
399
|
-
};
|
|
400
|
-
break;
|
|
401
|
-
|
|
402
|
-
case ActionType.SET_IS_SAVING_USER_DATA: {
|
|
403
|
-
newState = {
|
|
404
|
-
...state,
|
|
405
|
-
is_saving_user_data: action.payload.saving,
|
|
406
|
-
};
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
case ActionType.SET_APP_CONFIG:
|
|
411
|
-
newState = {
|
|
412
|
-
...state,
|
|
413
|
-
app: {
|
|
414
|
-
...state.app,
|
|
415
|
-
...action.payload,
|
|
416
|
-
},
|
|
417
|
-
};
|
|
418
|
-
break;
|
|
419
|
-
|
|
420
|
-
default:
|
|
421
|
-
newState = state;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Write state to local storage, minus a few fields
|
|
425
|
-
const persistedState: any = { ...newState };
|
|
426
|
-
delete persistedState.config;
|
|
427
|
-
delete persistedState.nav;
|
|
428
|
-
delete persistedState.is_container_visible;
|
|
429
|
-
delete persistedState.use_modal;
|
|
430
|
-
delete persistedState.is_initializing;
|
|
431
|
-
delete persistedState.is_saving_user_data;
|
|
432
|
-
|
|
433
|
-
// updateStorage(persistedState);
|
|
434
|
-
storage.set('state', JSON.stringify(persistedState));
|
|
435
|
-
|
|
436
|
-
// Fire any events that depend on state updates
|
|
437
|
-
// dispatchExternalEvents(state, newState);
|
|
438
|
-
|
|
439
|
-
return newState;
|
|
440
|
-
}
|
|
32
|
+
const [state, dispatch] = useReducer(rowndReducer, initialRowndState);
|
|
33
|
+
const value = { state, dispatch };
|
|
441
34
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
handleStateInit
|
|
446
|
-
);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
NativeRowndModules.configure(config.appKey);
|
|
37
|
+
}, [config.appKey]);
|
|
447
38
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const onSessionConnect = (event: any) => {
|
|
41
|
+
dispatch({
|
|
42
|
+
type: ActionType.UPDATE_STATE,
|
|
43
|
+
payload: Platform.OS === 'android' ? JSON.parse(event.state) : event,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const subscription = eventEmitter.addListener(
|
|
47
|
+
'update_state',
|
|
48
|
+
onSessionConnect
|
|
49
|
+
);
|
|
452
50
|
|
|
453
|
-
|
|
454
|
-
// return;
|
|
455
|
-
// }
|
|
51
|
+
if (!subscription) return;
|
|
456
52
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
// });
|
|
462
|
-
// }, []);
|
|
53
|
+
return () => {
|
|
54
|
+
subscription.remove();
|
|
55
|
+
};
|
|
56
|
+
}, []);
|
|
463
57
|
|
|
464
|
-
const value = { state, dispatch };
|
|
465
58
|
return (
|
|
466
|
-
<GlobalContext.Provider value={value}>
|
|
467
|
-
{children}
|
|
468
|
-
{/* <ExternalApi config={config} dispatchEvents={(state: GlobalState) => dispatchExternalEvents(initialState, state)} /> */}
|
|
469
|
-
</GlobalContext.Provider>
|
|
59
|
+
<GlobalContext.Provider value={value}>{children}</GlobalContext.Provider>
|
|
470
60
|
);
|
|
471
61
|
};
|
|
472
62
|
|
|
473
|
-
function
|
|
63
|
+
function useRowndContext() {
|
|
474
64
|
const context = useContext(GlobalContext);
|
|
475
65
|
|
|
476
66
|
if (context === undefined) {
|
|
@@ -482,4 +72,4 @@ function useGlobalContext() {
|
|
|
482
72
|
return context;
|
|
483
73
|
}
|
|
484
74
|
|
|
485
|
-
export {
|
|
75
|
+
export { RowndProvider, useRowndContext };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { TAction } from '../constants/action';
|
|
2
|
+
import type { IConfig } from '../utils/config';
|
|
3
|
+
|
|
4
|
+
export type ContextProps = {
|
|
5
|
+
config: IConfig;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type Dispatch = (action: TAction) => void;
|
|
9
|
+
|
|
10
|
+
export type GlobalState = {
|
|
11
|
+
// is_initializing: boolean;
|
|
12
|
+
// is_container_visible: boolean;
|
|
13
|
+
// use_modal: boolean;
|
|
14
|
+
// nav: {
|
|
15
|
+
// current_route: string;
|
|
16
|
+
// route_trigger: string;
|
|
17
|
+
// event_id: string;
|
|
18
|
+
// section: string;
|
|
19
|
+
// options?: any;
|
|
20
|
+
// };
|
|
21
|
+
user: {
|
|
22
|
+
data: {
|
|
23
|
+
id?: string;
|
|
24
|
+
email?: string | null;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
27
|
+
// needs_refresh?: boolean;
|
|
28
|
+
// redacted: string[];
|
|
29
|
+
};
|
|
30
|
+
auth: {
|
|
31
|
+
access_token: string | null;
|
|
32
|
+
refresh_token: string | null;
|
|
33
|
+
app_id: string | null;
|
|
34
|
+
init_data?: Record<string, any>;
|
|
35
|
+
is_verified_user?: boolean;
|
|
36
|
+
};
|
|
37
|
+
app: {
|
|
38
|
+
id?: string;
|
|
39
|
+
icon?: string;
|
|
40
|
+
icon_content_type?: string;
|
|
41
|
+
config: AppConfig | null;
|
|
42
|
+
schema: AppSchema | null;
|
|
43
|
+
user_verification_field?: string;
|
|
44
|
+
user_verification_fields?: string[];
|
|
45
|
+
};
|
|
46
|
+
// local_acls: Record<string, { shared: boolean }> | null;
|
|
47
|
+
// is_saving_user_data: boolean;
|
|
48
|
+
config?: IConfig;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type AppSchema = Record<string, SchemaField>;
|
|
52
|
+
|
|
53
|
+
export interface SchemaField {
|
|
54
|
+
display_name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
data_category: string;
|
|
57
|
+
required: boolean;
|
|
58
|
+
owned_by: string;
|
|
59
|
+
user_visible: boolean;
|
|
60
|
+
revoke_after: string;
|
|
61
|
+
required_retention: string;
|
|
62
|
+
collection_justification: string;
|
|
63
|
+
opt_out_warning: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AppConfig {
|
|
67
|
+
customizations: {
|
|
68
|
+
primary_color: string;
|
|
69
|
+
};
|
|
70
|
+
default_user_id_format?: string;
|
|
71
|
+
hub: {
|
|
72
|
+
auth: {
|
|
73
|
+
allow_unverified_users?: boolean;
|
|
74
|
+
additional_fields: [
|
|
75
|
+
{
|
|
76
|
+
name: string;
|
|
77
|
+
type: string;
|
|
78
|
+
label: string;
|
|
79
|
+
placeholder?: string;
|
|
80
|
+
options: [
|
|
81
|
+
{
|
|
82
|
+
value: string;
|
|
83
|
+
label: string;
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
email: {
|
|
89
|
+
from_address: string;
|
|
90
|
+
image: string;
|
|
91
|
+
};
|
|
92
|
+
show_app_icon: boolean;
|
|
93
|
+
};
|
|
94
|
+
customizations: HubCustomizations;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface HubCustomizations {
|
|
99
|
+
rounded_corners: boolean;
|
|
100
|
+
primary_color: string;
|
|
101
|
+
placement: 'bottom-left' | 'hidden';
|
|
102
|
+
offset_x: number;
|
|
103
|
+
offset_y: number;
|
|
104
|
+
property_overrides: Record<string, string>;
|
|
105
|
+
}
|