@norcy/react-native-toolkit 0.1.5 → 0.1.7
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/lib/commonjs/AppleLoginUtil.js +137 -0
- package/lib/commonjs/AppleLoginUtil.js.map +1 -0
- package/lib/commonjs/PrefData.js +122 -0
- package/lib/commonjs/PrefData.js.map +1 -0
- package/lib/commonjs/ReportUtil.js +115 -0
- package/lib/commonjs/ReportUtil.js.map +1 -0
- package/lib/commonjs/SentryManager.js +54 -0
- package/lib/commonjs/SentryManager.js.map +1 -0
- package/lib/commonjs/constant.js +18 -0
- package/lib/commonjs/constant.js.map +1 -0
- package/lib/commonjs/index.js +60 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/AppleLoginUtil.js +131 -0
- package/lib/module/AppleLoginUtil.js.map +1 -0
- package/lib/module/PrefData.js +115 -0
- package/lib/module/PrefData.js.map +1 -0
- package/lib/module/ReportUtil.js +109 -0
- package/lib/module/ReportUtil.js.map +1 -0
- package/lib/module/SentryManager.js +46 -0
- package/lib/module/SentryManager.js.map +1 -0
- package/lib/module/constant.js +12 -0
- package/lib/module/constant.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/AppleLoginUtil.d.ts +26 -0
- package/lib/typescript/PrefData.d.ts +15 -0
- package/lib/typescript/ReportUtil.d.ts +11 -0
- package/lib/typescript/SentryManager.d.ts +4 -0
- package/lib/typescript/constant.d.ts +17 -0
- package/lib/typescript/index.d.ts +5 -0
- package/package.json +13 -3
- package/src/AppleLoginUtil.ts +105 -0
- package/src/PrefData.ts +134 -0
- package/src/ReportUtil.ts +136 -0
- package/src/SentryManager.ts +47 -0
- package/src/constant.ts +20 -0
- package/src/index.tsx +5 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { appleAuth } from '@invertase/react-native-apple-authentication';
|
|
2
|
+
import { getBundleId } from 'react-native-device-info';
|
|
3
|
+
import { LoginState } from './constant';
|
|
4
|
+
const AV = require('leancloud-storage');
|
|
5
|
+
export const AppleLoginUtil = {
|
|
6
|
+
// 这是监听苹果取消授权的回调,目前不需要
|
|
7
|
+
// appleAuth.onCredentialRevoked(async () => {
|
|
8
|
+
// fetchAndUpdateCredentialState(loginUser).catch(error => {
|
|
9
|
+
// updateCredentialStateForUser(`Error: ${error.code}`)
|
|
10
|
+
// });
|
|
11
|
+
// });
|
|
12
|
+
|
|
13
|
+
fetchAndUpdateCredentialState: async (user, callback) => {
|
|
14
|
+
console.log('User 正在登录鉴权:', user);
|
|
15
|
+
if (user === null) {
|
|
16
|
+
callback({
|
|
17
|
+
result: LoginState.NOTLOGIN
|
|
18
|
+
}, {
|
|
19
|
+
error: 'USER EMPTY'
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
const credentialState = await appleAuth.getCredentialStateForUser(user);
|
|
23
|
+
if (credentialState === appleAuth.State.AUTHORIZED) {
|
|
24
|
+
console.log('登录鉴权成功');
|
|
25
|
+
callback({
|
|
26
|
+
result: LoginState.AUTHORIZED
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
console.warn('登录鉴权失败');
|
|
30
|
+
callback({
|
|
31
|
+
result: LoginState.NOTLOGIN
|
|
32
|
+
}, {
|
|
33
|
+
error: 'Authorized Failed'
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
requestAppleUserForLogin: async () => {
|
|
39
|
+
if (!appleAuth.isSupported) {
|
|
40
|
+
return {
|
|
41
|
+
error: 'Apple Auth Not Supported'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// start a login request
|
|
46
|
+
try {
|
|
47
|
+
const appleAuthRequestResponse = await appleAuth.performRequest({
|
|
48
|
+
requestedOperation: appleAuth.Operation.LOGIN,
|
|
49
|
+
requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME]
|
|
50
|
+
});
|
|
51
|
+
console.log('appleAuthRequestResponse login', appleAuthRequestResponse);
|
|
52
|
+
const {
|
|
53
|
+
user: newUser,
|
|
54
|
+
email,
|
|
55
|
+
identityToken
|
|
56
|
+
} = appleAuthRequestResponse;
|
|
57
|
+
console.log(`Apple Authentication Completed, ${newUser}, ${email}`);
|
|
58
|
+
return {
|
|
59
|
+
user: newUser,
|
|
60
|
+
email: email,
|
|
61
|
+
identityToken: identityToken
|
|
62
|
+
};
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error.code === appleAuth.Error.CANCELED) {
|
|
65
|
+
// console.warn('User canceled Apple Sign in.');
|
|
66
|
+
return {
|
|
67
|
+
error: 'User Cancel Login',
|
|
68
|
+
code: error.code
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
// console.warn('登录鉴权出错: ', error);
|
|
72
|
+
return {
|
|
73
|
+
error: 'Login Request Fail',
|
|
74
|
+
code: error.code
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
requestAppleUserForLogout: async () => {
|
|
80
|
+
if (!appleAuth.isSupported) {
|
|
81
|
+
throw {
|
|
82
|
+
error: 'Apple Auth Not Supported',
|
|
83
|
+
code: -1
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// start a login request
|
|
88
|
+
try {
|
|
89
|
+
const appleAuthRequestResponse = await appleAuth.performRequest({
|
|
90
|
+
requestedOperation: appleAuth.Operation.LOGOUT
|
|
91
|
+
});
|
|
92
|
+
console.log('appleAuthRequestResponse logout', appleAuthRequestResponse);
|
|
93
|
+
return {
|
|
94
|
+
authorizationCode: appleAuthRequestResponse.authorizationCode
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error.code === appleAuth.Error.CANCELED) {
|
|
98
|
+
throw {
|
|
99
|
+
error: 'User Cancel Logout',
|
|
100
|
+
code: error.code
|
|
101
|
+
};
|
|
102
|
+
} else {
|
|
103
|
+
throw {
|
|
104
|
+
error: 'Logout Request Fail',
|
|
105
|
+
code: error.code
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
requestDeleteAccount: async () => {
|
|
111
|
+
if (appleAuth.isSupported) {
|
|
112
|
+
const {
|
|
113
|
+
authorizationCode
|
|
114
|
+
} = await AppleLoginUtil.requestAppleUserForLogout();
|
|
115
|
+
console.log('get authorizationCode success', authorizationCode);
|
|
116
|
+
const {
|
|
117
|
+
token
|
|
118
|
+
} = await AV.Cloud.run('getToken', {
|
|
119
|
+
authorizationCode,
|
|
120
|
+
bundleId: getBundleId()
|
|
121
|
+
});
|
|
122
|
+
console.log('get token success', token);
|
|
123
|
+
await AV.Cloud.run('revokeAppleAccount', {
|
|
124
|
+
token,
|
|
125
|
+
bundleId: getBundleId()
|
|
126
|
+
});
|
|
127
|
+
console.log('revoke account success');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=AppleLoginUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["appleAuth","getBundleId","LoginState","AV","require","AppleLoginUtil","fetchAndUpdateCredentialState","user","callback","console","log","result","NOTLOGIN","error","credentialState","getCredentialStateForUser","State","AUTHORIZED","warn","requestAppleUserForLogin","isSupported","appleAuthRequestResponse","performRequest","requestedOperation","Operation","LOGIN","requestedScopes","Scope","EMAIL","FULL_NAME","newUser","email","identityToken","code","Error","CANCELED","requestAppleUserForLogout","LOGOUT","authorizationCode","requestDeleteAccount","token","Cloud","run","bundleId"],"sources":["AppleLoginUtil.ts"],"sourcesContent":["import { appleAuth } from '@invertase/react-native-apple-authentication';\nimport { getBundleId } from 'react-native-device-info';\nimport { LoginState } from './constant';\n\nconst AV = require('leancloud-storage');\n\nexport const AppleLoginUtil = {\n // 这是监听苹果取消授权的回调,目前不需要\n // appleAuth.onCredentialRevoked(async () => {\n // fetchAndUpdateCredentialState(loginUser).catch(error => {\n // updateCredentialStateForUser(`Error: ${error.code}`)\n // });\n // });\n\n fetchAndUpdateCredentialState: async (user: string, callback: Function) => {\n console.log('User 正在登录鉴权:', user);\n\n if (user === null) {\n callback({ result: LoginState.NOTLOGIN }, { error: 'USER EMPTY' });\n } else {\n const credentialState = await appleAuth.getCredentialStateForUser(user);\n if (credentialState === appleAuth.State.AUTHORIZED) {\n console.log('登录鉴权成功');\n callback({ result: LoginState.AUTHORIZED });\n } else {\n console.warn('登录鉴权失败');\n callback(\n { result: LoginState.NOTLOGIN },\n { error: 'Authorized Failed' }\n );\n }\n }\n },\n\n requestAppleUserForLogin: async () => {\n if (!appleAuth.isSupported) {\n return { error: 'Apple Auth Not Supported' };\n }\n\n // start a login request\n try {\n const appleAuthRequestResponse = await appleAuth.performRequest({\n requestedOperation: appleAuth.Operation.LOGIN,\n requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],\n });\n\n console.log('appleAuthRequestResponse login', appleAuthRequestResponse);\n\n const { user: newUser, email, identityToken } = appleAuthRequestResponse;\n\n console.log(`Apple Authentication Completed, ${newUser}, ${email}`);\n\n return { user: newUser, email: email, identityToken: identityToken };\n } catch (error: any) {\n if (error.code === appleAuth.Error.CANCELED) {\n // console.warn('User canceled Apple Sign in.');\n return { error: 'User Cancel Login', code: error.code };\n } else {\n // console.warn('登录鉴权出错: ', error);\n return { error: 'Login Request Fail', code: error.code };\n }\n }\n },\n\n requestAppleUserForLogout: async () => {\n if (!appleAuth.isSupported) {\n throw { error: 'Apple Auth Not Supported', code: -1 };\n }\n\n // start a login request\n try {\n const appleAuthRequestResponse = await appleAuth.performRequest({\n requestedOperation: appleAuth.Operation.LOGOUT,\n });\n\n console.log('appleAuthRequestResponse logout', appleAuthRequestResponse);\n\n return { authorizationCode: appleAuthRequestResponse.authorizationCode };\n } catch (error: any) {\n if (error.code === appleAuth.Error.CANCELED) {\n throw { error: 'User Cancel Logout', code: error.code };\n } else {\n throw { error: 'Logout Request Fail', code: error.code };\n }\n }\n },\n\n requestDeleteAccount: async () => {\n if (appleAuth.isSupported) {\n const { authorizationCode } =\n await AppleLoginUtil.requestAppleUserForLogout();\n console.log('get authorizationCode success', authorizationCode);\n const { token } = await AV.Cloud.run('getToken', {\n authorizationCode,\n bundleId: getBundleId(),\n });\n console.log('get token success', token);\n await AV.Cloud.run('revokeAppleAccount', {\n token,\n bundleId: getBundleId(),\n });\n console.log('revoke account success');\n }\n },\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,8CAA8C;AACxE,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,UAAU,QAAQ,YAAY;AAEvC,MAAMC,EAAE,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAEvC,OAAO,MAAMC,cAAc,GAAG;EAC5B;EACA;EACA;EACA;EACA;EACA;;EAEAC,6BAA6B,EAAE,MAAAA,CAAOC,IAAY,EAAEC,QAAkB,KAAK;IACzEC,OAAO,CAACC,GAAG,CAAC,cAAc,EAAEH,IAAI,CAAC;IAEjC,IAAIA,IAAI,KAAK,IAAI,EAAE;MACjBC,QAAQ,CAAC;QAAEG,MAAM,EAAET,UAAU,CAACU;MAAS,CAAC,EAAE;QAAEC,KAAK,EAAE;MAAa,CAAC,CAAC;IACpE,CAAC,MAAM;MACL,MAAMC,eAAe,GAAG,MAAMd,SAAS,CAACe,yBAAyB,CAACR,IAAI,CAAC;MACvE,IAAIO,eAAe,KAAKd,SAAS,CAACgB,KAAK,CAACC,UAAU,EAAE;QAClDR,OAAO,CAACC,GAAG,CAAC,QAAQ,CAAC;QACrBF,QAAQ,CAAC;UAAEG,MAAM,EAAET,UAAU,CAACe;QAAW,CAAC,CAAC;MAC7C,CAAC,MAAM;QACLR,OAAO,CAACS,IAAI,CAAC,QAAQ,CAAC;QACtBV,QAAQ,CACN;UAAEG,MAAM,EAAET,UAAU,CAACU;QAAS,CAAC,EAC/B;UAAEC,KAAK,EAAE;QAAoB,CAC/B,CAAC;MACH;IACF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O,CAACC,GAAG,CAAC,wBAAwB,CAAC;IACvC;EACF;AACF,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-community/async-storage';
|
|
2
|
+
const EventEmitter = require('events').EventEmitter;
|
|
3
|
+
const eventEmitter = new EventEmitter();
|
|
4
|
+
let isDataLoaded = false;
|
|
5
|
+
const _PrefDatas = {};
|
|
6
|
+
export const BuildInPrefs = {
|
|
7
|
+
LastLoginType: {
|
|
8
|
+
key: 'LastLoginType_Key',
|
|
9
|
+
type: 'int',
|
|
10
|
+
default: -1
|
|
11
|
+
},
|
|
12
|
+
isFirstLaunch: {
|
|
13
|
+
key: 'isFirstLaunch_Key2',
|
|
14
|
+
type: 'bool',
|
|
15
|
+
default: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getPrefByKey = (Prefs, key) => {
|
|
19
|
+
for (const keyOfPref in Prefs) {
|
|
20
|
+
if (Prefs[keyOfPref].key === key) {
|
|
21
|
+
return Prefs[keyOfPref];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
export const PrefData = {
|
|
27
|
+
load: async initPrefs => {
|
|
28
|
+
console.log('读取配置');
|
|
29
|
+
let keys = [];
|
|
30
|
+
const Prefs = {
|
|
31
|
+
...BuildInPrefs,
|
|
32
|
+
...initPrefs
|
|
33
|
+
};
|
|
34
|
+
for (const pref in Prefs) {
|
|
35
|
+
keys.push(Prefs[pref].key);
|
|
36
|
+
}
|
|
37
|
+
const values = await getMultiDatas(keys);
|
|
38
|
+
for (let i = 0; i < values.length; i++) {
|
|
39
|
+
const key = values[i][0];
|
|
40
|
+
const value = values[i][1];
|
|
41
|
+
const pref = getPrefByKey(Prefs, key);
|
|
42
|
+
if (!pref) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// console.log(key, value, pref);
|
|
46
|
+
if (!value) {
|
|
47
|
+
_PrefDatas[key] = pref.default;
|
|
48
|
+
} else if (pref.type === 'object' || pref.type === 'array') {
|
|
49
|
+
_PrefDatas[key] = JSON.parse(value);
|
|
50
|
+
} else if (pref.type === 'int') {
|
|
51
|
+
_PrefDatas[key] = parseInt(value, 10);
|
|
52
|
+
} else if (pref.type === 'bool') {
|
|
53
|
+
_PrefDatas[key] = JSON.parse(value);
|
|
54
|
+
} else {
|
|
55
|
+
_PrefDatas[key] = value;
|
|
56
|
+
}
|
|
57
|
+
// console.log(
|
|
58
|
+
// '配置读取结果:',
|
|
59
|
+
// key,
|
|
60
|
+
// _PrefDatas[key],
|
|
61
|
+
// typeof _PrefDatas[key],
|
|
62
|
+
// );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
eventEmitter.emit('load');
|
|
66
|
+
isDataLoaded = true;
|
|
67
|
+
},
|
|
68
|
+
getValue: pref => {
|
|
69
|
+
return _PrefDatas[pref.key];
|
|
70
|
+
},
|
|
71
|
+
setValue: async (pref, value) => {
|
|
72
|
+
const key = pref.key;
|
|
73
|
+
let finalValue;
|
|
74
|
+
_PrefDatas[key] = value;
|
|
75
|
+
if (pref.type === 'object' || pref.type === 'array') {
|
|
76
|
+
finalValue = JSON.stringify(value);
|
|
77
|
+
} else if (pref.type === 'int') {
|
|
78
|
+
finalValue = value.toString();
|
|
79
|
+
} else if (pref.type === 'bool') {
|
|
80
|
+
finalValue = value.toString();
|
|
81
|
+
} else {
|
|
82
|
+
finalValue = value;
|
|
83
|
+
}
|
|
84
|
+
await storeData(key, finalValue);
|
|
85
|
+
},
|
|
86
|
+
addListener: callback => {
|
|
87
|
+
if (isDataLoaded) {
|
|
88
|
+
callback && callback();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
eventEmitter.on('load', callback);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const storeData = async (key, value) => {
|
|
95
|
+
try {
|
|
96
|
+
if (typeof value !== 'string') {
|
|
97
|
+
console.error('只接受 String');
|
|
98
|
+
}
|
|
99
|
+
// console.log('save to storage ' + value);
|
|
100
|
+
await AsyncStorage.setItem(key, value);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(e);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const getMultiDatas = async keys => {
|
|
106
|
+
try {
|
|
107
|
+
const values = await AsyncStorage.multiGet(keys);
|
|
108
|
+
// console.log('read from storage ' + values);
|
|
109
|
+
return values;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error(e);
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=PrefData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AsyncStorage","EventEmitter","require","eventEmitter","isDataLoaded","_PrefDatas","BuildInPrefs","LastLoginType","key","type","default","isFirstLaunch","getPrefByKey","Prefs","keyOfPref","PrefData","load","initPrefs","console","log","keys","pref","push","values","getMultiDatas","i","length","value","JSON","parse","parseInt","emit","getValue","setValue","finalValue","stringify","toString","storeData","addListener","callback","on","error","setItem","e","multiGet"],"sources":["PrefData.ts"],"sourcesContent":["import AsyncStorage from '@react-native-community/async-storage';\n\nconst EventEmitter = require('events').EventEmitter;\nconst eventEmitter = new EventEmitter();\n\nlet isDataLoaded = false;\n\nexport interface PrefType {\n key: string;\n type: string;\n default: any;\n}\n\nexport interface PrefsType {\n [key: string]: PrefType;\n}\n\nconst _PrefDatas: { [key: string]: any } = {};\n\nexport const BuildInPrefs: PrefsType = {\n LastLoginType: {\n key: 'LastLoginType_Key',\n type: 'int',\n default: -1,\n },\n isFirstLaunch: {\n key: 'isFirstLaunch_Key2',\n type: 'bool',\n default: true,\n },\n};\n\nconst getPrefByKey = (Prefs: PrefsType, key: string) => {\n for (const keyOfPref in Prefs) {\n if (Prefs[keyOfPref].key === key) {\n return Prefs[keyOfPref];\n }\n }\n return null;\n};\n\nexport const PrefData = {\n load: async (initPrefs: PrefsType) => {\n console.log('读取配置');\n let keys = [];\n const Prefs = { ...BuildInPrefs, ...initPrefs };\n for (const pref in Prefs) {\n keys.push(Prefs[pref].key);\n }\n const values = await getMultiDatas(keys);\n\n for (let i = 0; i < values.length; i++) {\n const key = values[i][0];\n const value = values[i][1];\n const pref = getPrefByKey(Prefs, key);\n if (!pref) {\n continue;\n }\n // console.log(key, value, pref);\n if (!value) {\n _PrefDatas[key] = pref.default;\n } else if (pref.type === 'object' || pref.type === 'array') {\n _PrefDatas[key] = JSON.parse(value);\n } else if (pref.type === 'int') {\n _PrefDatas[key] = parseInt(value, 10);\n } else if (pref.type === 'bool') {\n _PrefDatas[key] = JSON.parse(value);\n } else {\n _PrefDatas[key] = value;\n }\n // console.log(\n // '配置读取结果:',\n // key,\n // _PrefDatas[key],\n // typeof _PrefDatas[key],\n // );\n }\n\n eventEmitter.emit('load');\n isDataLoaded = true;\n },\n\n getValue: (pref: PrefType) => {\n return _PrefDatas[pref.key];\n },\n\n setValue: async (pref: PrefType, value: any) => {\n const key = pref.key;\n let finalValue: string;\n _PrefDatas[key] = value;\n if (pref.type === 'object' || pref.type === 'array') {\n finalValue = JSON.stringify(value);\n } else if (pref.type === 'int') {\n finalValue = value.toString();\n } else if (pref.type === 'bool') {\n finalValue = value.toString();\n } else {\n finalValue = value;\n }\n\n await storeData(key, finalValue);\n },\n\n addListener: (callback: Function) => {\n if (isDataLoaded) {\n callback && callback();\n return;\n }\n eventEmitter.on('load', callback);\n },\n};\n\nconst storeData = async (key: string, value: string) => {\n try {\n if (typeof value !== 'string') {\n console.error('只接受 String');\n }\n // console.log('save to storage ' + value);\n await AsyncStorage.setItem(key, value);\n } catch (e) {\n console.error(e);\n }\n};\n\nconst getMultiDatas = async (keys: string[]) => {\n try {\n const values = await AsyncStorage.multiGet(keys);\n // console.log('read from storage ' + values);\n return values;\n } catch (e) {\n console.error(e);\n return [];\n }\n};\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,uCAAuC;AAEhE,MAAMC,YAAY,GAAGC,OAAO,CAAC,QAAQ,CAAC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|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
import { getBrand, getDeviceId, getModel, getReadableVersion } from 'react-native-device-info';
|
|
3
|
+
import { Notification } from './Notification';
|
|
4
|
+
const CommonInfo = {
|
|
5
|
+
appVer: getReadableVersion(),
|
|
6
|
+
platform: Platform.OS,
|
|
7
|
+
sysVer: Platform.Version,
|
|
8
|
+
model: getModel(),
|
|
9
|
+
brand: getBrand(),
|
|
10
|
+
device: getDeviceId()
|
|
11
|
+
};
|
|
12
|
+
const enable = () => {
|
|
13
|
+
if (__DEV__) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (!NativeModules.NCYReport) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
const isValidReport = (eventId, params) => {
|
|
22
|
+
if (typeof eventId !== 'string' || (eventId === null || eventId === void 0 ? void 0 : eventId.length) === 0) {
|
|
23
|
+
console.error('Report 数据非法 1');
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (params == null) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (typeof params !== 'object' || Array.isArray(params)) {
|
|
30
|
+
console.error('Report 数据非法 2');
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
for (const key in params) {
|
|
34
|
+
if (typeof key !== 'string') {
|
|
35
|
+
console.error('Report 数据非法 3');
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
const convertToValidParams = params => {
|
|
42
|
+
const ret = {};
|
|
43
|
+
for (const key in params) {
|
|
44
|
+
const value = JSON.stringify(params[key]);
|
|
45
|
+
ret[key] = value;
|
|
46
|
+
}
|
|
47
|
+
return ret;
|
|
48
|
+
};
|
|
49
|
+
export const ReportUtil = {
|
|
50
|
+
init: () => {
|
|
51
|
+
if (!enable()) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
Notification.addListener('onLogin', _ref => {
|
|
55
|
+
let {
|
|
56
|
+
error,
|
|
57
|
+
user
|
|
58
|
+
} = _ref;
|
|
59
|
+
if (!error && user) {
|
|
60
|
+
NativeModules.NCYReport.signIn(user.AVUser.get('objectId'));
|
|
61
|
+
ReportUtil.setCommonInfo('user', user.AVUser.get('objectId'));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
Notification.addListener('onLogout', () => {
|
|
65
|
+
NativeModules.NCYReport.signOut();
|
|
66
|
+
ReportUtil.setCommonInfo('user', '');
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
report: (eventId, params) => {
|
|
70
|
+
if (!enable()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!isValidReport(eventId, params)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const validParams = convertToValidParams(params);
|
|
77
|
+
const realParams = {
|
|
78
|
+
...validParams,
|
|
79
|
+
...ReportUtil.getCommonInfo()
|
|
80
|
+
};
|
|
81
|
+
console.log(realParams);
|
|
82
|
+
NativeModules.NCYReport.report(eventId, realParams);
|
|
83
|
+
},
|
|
84
|
+
setCommonInfo: (key, value) => {
|
|
85
|
+
CommonInfo[key] = value;
|
|
86
|
+
},
|
|
87
|
+
getCommonInfo: () => {
|
|
88
|
+
return CommonInfo;
|
|
89
|
+
},
|
|
90
|
+
viewAppear: page => {
|
|
91
|
+
if (!__DEV__) {
|
|
92
|
+
console.log(page, 'viewWillAppear');
|
|
93
|
+
}
|
|
94
|
+
if (!enable()) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
NativeModules.NCYReport.enterPage(page);
|
|
98
|
+
},
|
|
99
|
+
viewDisappear: page => {
|
|
100
|
+
if (!__DEV__) {
|
|
101
|
+
console.log(page, 'viewWillDisappear');
|
|
102
|
+
}
|
|
103
|
+
if (!enable()) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
NativeModules.NCYReport.leavePage(page);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=ReportUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","getBrand","getDeviceId","getModel","getReadableVersion","Notification","CommonInfo","appVer","platform","OS","sysVer","Version","model","brand","device","enable","__DEV__","NCYReport","isValidReport","eventId","params","length","console","error","Array","isArray","key","convertToValidParams","ret","value","JSON","stringify","ReportUtil","init","addListener","_ref","user","signIn","AVUser","get","setCommonInfo","signOut","report","validParams","realParams","getCommonInfo","log","viewAppear","page","enterPage","viewDisappear","leavePage"],"sources":["ReportUtil.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport {\n getBrand,\n getDeviceId,\n getModel,\n getReadableVersion,\n} from 'react-native-device-info';\nimport { Notification } from './Notification';\nimport { UserType } from './constant';\n\nexport interface ReportItemType {\n [key: string]: number | string;\n}\n\nconst CommonInfo: ReportItemType = {\n appVer: getReadableVersion(),\n platform: Platform.OS,\n sysVer: Platform.Version,\n model: getModel(),\n brand: getBrand(),\n device: getDeviceId(),\n};\n\nconst enable = () => {\n if (__DEV__) {\n return false;\n }\n if (!NativeModules.NCYReport) {\n return false;\n }\n return true;\n};\n\nconst isValidReport = (eventId: string, params?: ReportItemType) => {\n if (typeof eventId !== 'string' || eventId?.length === 0) {\n console.error('Report 数据非法 1');\n return false;\n }\n\n if (params == null) {\n return true;\n }\n\n if (typeof params !== 'object' || Array.isArray(params)) {\n console.error('Report 数据非法 2');\n return false;\n }\n\n for (const key in params) {\n if (typeof key !== 'string') {\n console.error('Report 数据非法 3');\n return false;\n }\n }\n\n return true;\n};\n\nconst convertToValidParams = (params?: ReportItemType) => {\n const ret: ReportItemType = {};\n for (const key in params) {\n const value = JSON.stringify(params[key]);\n ret[key] = value;\n }\n return ret;\n};\n\nexport const ReportUtil = {\n init: () => {\n if (!enable()) {\n return;\n }\n\n Notification.addListener(\n 'onLogin',\n ({ error, user }: { error: any; user: UserType }) => {\n if (!error && user) {\n NativeModules.NCYReport.signIn(user.AVUser.get('objectId'));\n ReportUtil.setCommonInfo('user', user.AVUser.get('objectId'));\n }\n }\n );\n\n Notification.addListener('onLogout', () => {\n NativeModules.NCYReport.signOut();\n ReportUtil.setCommonInfo('user', '');\n });\n },\n\n report: (eventId: string, params?: ReportItemType) => {\n if (!enable()) {\n return;\n }\n\n if (!isValidReport(eventId, params)) {\n return;\n }\n\n const validParams = convertToValidParams(params);\n const realParams = { ...validParams, ...ReportUtil.getCommonInfo() };\n console.log(realParams);\n NativeModules.NCYReport.report(eventId, realParams);\n },\n\n setCommonInfo: (key: string, value: string) => {\n CommonInfo[key] = value;\n },\n\n getCommonInfo: () => {\n return CommonInfo;\n },\n\n viewAppear: (page: string) => {\n if (!__DEV__) {\n console.log(page, 'viewWillAppear');\n }\n\n if (!enable()) {\n return;\n }\n\n NativeModules.NCYReport.enterPage(page);\n },\n\n viewDisappear: (page: string) => {\n if (!__DEV__) {\n console.log(page, 'viewWillDisappear');\n }\n\n if (!enable()) {\n return;\n }\n\n NativeModules.NCYReport.leavePage(page);\n },\n};\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SACEC,QAAQ,EACRC,WAAW,EACXC,QAAQ,EACRC,kBAAkB,QACb,0BAA0B;AACjC,SAASC,YAAY,QAAQ,gBAAgB;AAO7C,MAAMC,UAA0B,GAAG;EACjCC,MAAM,EAAEH,kBAAkB,CAAC,CAAC;EAC5BI,QAAQ,EAAER,QAAQ,CAACS,EAAE;EACrBC,MAAM,EAAEV,QAAQ,CAACW,OAAO;EACxBC,KAAK,EAAET,QAAQ,CAAC,CAAC;EACjBU,KAAK,EAAEZ,QAAQ,CAAC,CAAC;EACjBa,MAAM,EAAEZ,WAAW,CAAC;AACtB,CAAC;AAED,MAAMa,MAAM,GAAGA,CAAA,KAAM;EACnB,IAAIC,OAAO,EAAE;IAC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O,CAACwB,GAAG,CAACE,IAAI,EAAE,gBAAgB,CAAC;IACrC;IAEA,IAAI,CAACjC,MAAM,CAAC,CAAC,EAAE;MACb;IACF;IAEAhB,aAAa,CAACkB,SAAS,CAACgC,SAAS,CAACD,IAAI,CAAC;EACzC,CAAC;EAEDE,aAAa,EAAGF,IAAY,IAAK;IAC/B,IAAI,CAAChC,OAAO,EAAE;MACZM,OAAO,CAACwB,GAAG,CAACE,IAAI,EAAE,mBAAmB,CAAC;IACxC;IAEA,IAAI,CAACjC,MAAM,CAAC,CAAC,EAAE;MACb;IACF;IAEAhB,aAAa,CAACkB,SAAS,CAACkC,SAAS,CAACH,IAAI,CAAC;EACzC;AACF,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Notification } from '@norcy/react-native-toolkit';
|
|
2
|
+
import * as Sentry from '@sentry/react-native';
|
|
3
|
+
export const SentryManager = {
|
|
4
|
+
init: () => {
|
|
5
|
+
if (__DEV__) {
|
|
6
|
+
console.log('__DEV__ 下不使用 Sentry');
|
|
7
|
+
} else {
|
|
8
|
+
// DEV 下不打开 Sentry
|
|
9
|
+
console.log('__RELEASE__ 下使用 Sentry');
|
|
10
|
+
Sentry.init({
|
|
11
|
+
dsn: 'https://a67f2741a16c45c4a66527b8f8b046a2@o473216.ingest.sentry.io/6509175',
|
|
12
|
+
tracesSampleRate: 1.0
|
|
13
|
+
});
|
|
14
|
+
Notification.addListener('onLogin', _ref => {
|
|
15
|
+
let {
|
|
16
|
+
error,
|
|
17
|
+
user
|
|
18
|
+
} = _ref;
|
|
19
|
+
if (!error && user) {
|
|
20
|
+
const sentryUser = {
|
|
21
|
+
id: user.AVUser.get('objectId'),
|
|
22
|
+
email: user.email,
|
|
23
|
+
username: user.nickname
|
|
24
|
+
};
|
|
25
|
+
Sentry.setUser(sentryUser);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Notification.addListener('onLogout', () => {
|
|
29
|
+
Sentry.setUser(null);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Sentry.nativeCrash();
|
|
33
|
+
// Sentry.captureException(new Error('测试77!'));
|
|
34
|
+
// throw new Error('My first Sentry error!');
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
setTag: (key, value) => {
|
|
39
|
+
if (!__DEV__) {
|
|
40
|
+
if (key.length) {
|
|
41
|
+
Sentry.setTag(key, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=SentryManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Notification","Sentry","SentryManager","init","__DEV__","console","log","dsn","tracesSampleRate","addListener","_ref","error","user","sentryUser","id","AVUser","get","email","username","nickname","setUser","setTag","key","value","length"],"sources":["SentryManager.ts"],"sourcesContent":["import { Notification, UserType } from '@norcy/react-native-toolkit';\nimport * as Sentry from '@sentry/react-native';\n\nexport const SentryManager = {\n init: () => {\n if (__DEV__) {\n console.log('__DEV__ 下不使用 Sentry');\n } else {\n // DEV 下不打开 Sentry\n console.log('__RELEASE__ 下使用 Sentry');\n Sentry.init({\n dsn: 'https://a67f2741a16c45c4a66527b8f8b046a2@o473216.ingest.sentry.io/6509175',\n tracesSampleRate: 1.0,\n });\n\n Notification.addListener(\n 'onLogin',\n ({ error, user }: { error: any; user: UserType }) => {\n if (!error && user) {\n const sentryUser: Sentry.User = {\n id: user.AVUser.get('objectId'),\n email: user.email,\n username: user.nickname,\n };\n Sentry.setUser(sentryUser);\n }\n }\n );\n\n Notification.addListener('onLogout', () => {\n Sentry.setUser(null);\n });\n\n // Sentry.nativeCrash();\n // Sentry.captureException(new Error('测试77!'));\n // throw new Error('My first Sentry error!');\n }\n },\n\n setTag: (key: string, value: any) => {\n if (!__DEV__) {\n if (key.length) {\n Sentry.setTag(key, value);\n }\n }\n },\n};\n"],"mappings":"AAAA,SAASA,YAAY,QAAkB,6BAA6B;AACpE,OAA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oginState[LoginState["AUTHORIZED"] = 1] = "AUTHORIZED";
|
|
4
|
+
return LoginState;
|
|
5
|
+
}({});
|
|
6
|
+
export let LoginType = /*#__PURE__*/function (LoginType) {
|
|
7
|
+
LoginType[LoginType["LoginTypeApple"] = 0] = "LoginTypeApple";
|
|
8
|
+
LoginType[LoginType["LoginTypeWeChat"] = 1] = "LoginTypeWeChat";
|
|
9
|
+
LoginType[LoginType["LoginTypeVisitor"] = 2] = "LoginTypeVisitor";
|
|
10
|
+
return LoginType;
|
|
11
|
+
}({});
|
|
12
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LoginState","LoginType"],"sources":["constant.ts"],"sourcesContent":["import { User } from 'leancloud-storage';\n\nexport interface UserType {\n nickname: string;\n email: string;\n headimgurl: string;\n type: number;\n AVUser: User;\n}\n\nexport enum LoginState {\n NOTLOGIN,\n AUTHORIZED,\n}\n\nexport enum LoginType {\n LoginTypeApple,\n LoginTypeWeChat,\n LoginTypeVisitor,\n}\n"],"mappings":"AAUA,WAAYA,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAKtB,WAAYC,SAAS,0BAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAATA,SAAS,CAATA,SAAS;EAAA,OAATA,SAAS;AAAA"}
|
package/lib/module/index.js
CHANGED
|
@@ -5,4 +5,9 @@ const {
|
|
|
5
5
|
export default ReactNativeToolkit;
|
|
6
6
|
export * from './SyncPrefData';
|
|
7
7
|
export * from './Notification';
|
|
8
|
+
export * from './ReportUtil';
|
|
9
|
+
export * from './SentryManager';
|
|
10
|
+
export * from './AppleLoginUtil';
|
|
11
|
+
export * from './constant';
|
|
12
|
+
export * from './PrefData';
|
|
8
13
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","ReactNativeToolkit"],"sources":["index.tsx"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ntype ReactNativeToolkitType = {\n multiply(a: number, b: number): Promise<number>;\n};\n\nconst { ReactNativeToolkit } = NativeModules;\n\nexport default ReactNativeToolkit as ReactNativeToolkitType;\nexport * from './SyncPrefData';\nexport * from './Notification';\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,MAAM;EAAEC;AAAmB,CAAC,GAAGD,aAAa;AAE5C,eAAeC,kBAAkB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB"}
|
|
1
|
+
{"version":3,"names":["NativeModules","ReactNativeToolkit"],"sources":["index.tsx"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ntype ReactNativeToolkitType = {\n multiply(a: number, b: number): Promise<number>;\n};\n\nconst { ReactNativeToolkit } = NativeModules;\n\nexport default ReactNativeToolkit as ReactNativeToolkitType;\nexport * from './SyncPrefData';\nexport * from './Notification';\nexport * from './ReportUtil';\nexport * from './SentryManager';\nexport * from './AppleLoginUtil';\nexport * from './constant';\nexport * from './PrefData';\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,MAAM;EAAEC;AAAmB,CAAC,GAAGD,aAAa;AAE5C,eAAeC,kBAAkB;AACjC,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,cAAc;AAC5B,cAAc,iBAAiB;AAC/B,cAAc,kBAAkB;AAChC,cAAc,YAAY;AAC1B,cAAc,YAAY"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const AppleLoginUtil: {
|
|
2
|
+
fetchAndUpdateCredentialState: (user: string, callback: Function) => Promise<void>;
|
|
3
|
+
requestAppleUserForLogin: () => Promise<{
|
|
4
|
+
error: string;
|
|
5
|
+
user?: undefined;
|
|
6
|
+
email?: undefined;
|
|
7
|
+
identityToken?: undefined;
|
|
8
|
+
code?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
user: string;
|
|
11
|
+
email: string | null;
|
|
12
|
+
identityToken: string | null;
|
|
13
|
+
error?: undefined;
|
|
14
|
+
code?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
error: string;
|
|
17
|
+
code: any;
|
|
18
|
+
user?: undefined;
|
|
19
|
+
email?: undefined;
|
|
20
|
+
identityToken?: undefined;
|
|
21
|
+
}>;
|
|
22
|
+
requestAppleUserForLogout: () => Promise<{
|
|
23
|
+
authorizationCode: string | null;
|
|
24
|
+
}>;
|
|
25
|
+
requestDeleteAccount: () => Promise<void>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PrefType {
|
|
2
|
+
key: string;
|
|
3
|
+
type: string;
|
|
4
|
+
default: any;
|
|
5
|
+
}
|
|
6
|
+
export interface PrefsType {
|
|
7
|
+
[key: string]: PrefType;
|
|
8
|
+
}
|
|
9
|
+
export declare const BuildInPrefs: PrefsType;
|
|
10
|
+
export declare const PrefData: {
|
|
11
|
+
load: (initPrefs: PrefsType) => Promise<void>;
|
|
12
|
+
getValue: (pref: PrefType) => any;
|
|
13
|
+
setValue: (pref: PrefType, value: any) => Promise<void>;
|
|
14
|
+
addListener: (callback: Function) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ReportItemType {
|
|
2
|
+
[key: string]: number | string;
|
|
3
|
+
}
|
|
4
|
+
export declare const ReportUtil: {
|
|
5
|
+
init: () => void;
|
|
6
|
+
report: (eventId: string, params?: ReportItemType) => void;
|
|
7
|
+
setCommonInfo: (key: string, value: string) => void;
|
|
8
|
+
getCommonInfo: () => ReportItemType;
|
|
9
|
+
viewAppear: (page: string) => void;
|
|
10
|
+
viewDisappear: (page: string) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { User } from 'leancloud-storage';
|
|
2
|
+
export interface UserType {
|
|
3
|
+
nickname: string;
|
|
4
|
+
email: string;
|
|
5
|
+
headimgurl: string;
|
|
6
|
+
type: number;
|
|
7
|
+
AVUser: User;
|
|
8
|
+
}
|
|
9
|
+
export declare enum LoginState {
|
|
10
|
+
NOTLOGIN = 0,
|
|
11
|
+
AUTHORIZED = 1
|
|
12
|
+
}
|
|
13
|
+
export declare enum LoginType {
|
|
14
|
+
LoginTypeApple = 0,
|
|
15
|
+
LoginTypeWeChat = 1,
|
|
16
|
+
LoginTypeVisitor = 2
|
|
17
|
+
}
|
|
@@ -5,3 +5,8 @@ declare const _default: ReactNativeToolkitType;
|
|
|
5
5
|
export default _default;
|
|
6
6
|
export * from './SyncPrefData';
|
|
7
7
|
export * from './Notification';
|
|
8
|
+
export * from './ReportUtil';
|
|
9
|
+
export * from './SentryManager';
|
|
10
|
+
export * from './AppleLoginUtil';
|
|
11
|
+
export * from './constant';
|
|
12
|
+
export * from './PrefData';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@norcy/react-native-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "My Toolkit",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -60,11 +60,21 @@
|
|
|
60
60
|
"react": "16.11.0",
|
|
61
61
|
"react-native": "0.62.2",
|
|
62
62
|
"release-it": "^13.5.8",
|
|
63
|
-
"typescript": "^5.0.2"
|
|
63
|
+
"typescript": "^5.0.2",
|
|
64
|
+
"@invertase/react-native-apple-authentication": "^2.1.2",
|
|
65
|
+
"react-native-device-info": "^10.0.2",
|
|
66
|
+
"@sentry/react-native": "^3.4.3",
|
|
67
|
+
"leancloud-storage": "^4.10.1",
|
|
68
|
+
"@react-native-community/async-storage": "^1.12.0"
|
|
64
69
|
},
|
|
65
70
|
"peerDependencies": {
|
|
66
71
|
"react": "*",
|
|
67
|
-
"react-native": "*"
|
|
72
|
+
"react-native": "*",
|
|
73
|
+
"@invertase/react-native-apple-authentication": "*",
|
|
74
|
+
"react-native-device-info": "*",
|
|
75
|
+
"@sentry/react-native": "*",
|
|
76
|
+
"@react-native-community/async-storage": "*",
|
|
77
|
+
"leancloud-storage": "*"
|
|
68
78
|
},
|
|
69
79
|
"jest": {
|
|
70
80
|
"preset": "react-native",
|