rn-erxes-sdk 0.4.0 → 0.4.3

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.
Files changed (52) hide show
  1. package/lib/commonjs/App.js +3 -2
  2. package/lib/commonjs/App.js.map +1 -1
  3. package/lib/commonjs/Widget.js +6 -5
  4. package/lib/commonjs/Widget.js.map +1 -1
  5. package/lib/commonjs/components/InputTools.js +2 -1
  6. package/lib/commonjs/components/InputTools.js.map +1 -1
  7. package/lib/commonjs/graphql/ApolloContainer.js +3 -2
  8. package/lib/commonjs/graphql/ApolloContainer.js.map +1 -1
  9. package/lib/commonjs/index.js +13 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/screen/conversation/ConversationDetail.js +4 -2
  12. package/lib/commonjs/screen/conversation/ConversationDetail.js.map +1 -1
  13. package/lib/commonjs/screen/home/Home.js +4 -2
  14. package/lib/commonjs/screen/home/Home.js.map +1 -1
  15. package/lib/commonjs/utils/logger.js +55 -0
  16. package/lib/commonjs/utils/logger.js.map +1 -0
  17. package/lib/module/App.js +3 -2
  18. package/lib/module/App.js.map +1 -1
  19. package/lib/module/Widget.js +6 -5
  20. package/lib/module/Widget.js.map +1 -1
  21. package/lib/module/components/InputTools.js +2 -1
  22. package/lib/module/components/InputTools.js.map +1 -1
  23. package/lib/module/graphql/ApolloContainer.js +3 -2
  24. package/lib/module/graphql/ApolloContainer.js.map +1 -1
  25. package/lib/module/index.js +1 -0
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/screen/conversation/ConversationDetail.js +4 -2
  28. package/lib/module/screen/conversation/ConversationDetail.js.map +1 -1
  29. package/lib/module/screen/home/Home.js +4 -2
  30. package/lib/module/screen/home/Home.js.map +1 -1
  31. package/lib/module/utils/logger.js +46 -0
  32. package/lib/module/utils/logger.js.map +1 -0
  33. package/lib/typescript/App.d.ts.map +1 -1
  34. package/lib/typescript/Widget.d.ts.map +1 -1
  35. package/lib/typescript/components/InputTools.d.ts.map +1 -1
  36. package/lib/typescript/graphql/ApolloContainer.d.ts.map +1 -1
  37. package/lib/typescript/index.d.ts +1 -0
  38. package/lib/typescript/index.d.ts.map +1 -1
  39. package/lib/typescript/screen/conversation/ConversationDetail.d.ts.map +1 -1
  40. package/lib/typescript/screen/home/Home.d.ts.map +1 -1
  41. package/lib/typescript/utils/logger.d.ts +18 -0
  42. package/lib/typescript/utils/logger.d.ts.map +1 -0
  43. package/package.json +1 -1
  44. package/rn-erxes-sdk.podspec +2 -2
  45. package/src/App.tsx +3 -2
  46. package/src/Widget.tsx +6 -5
  47. package/src/components/InputTools.tsx +2 -1
  48. package/src/graphql/ApolloContainer.tsx +3 -2
  49. package/src/index.tsx +2 -0
  50. package/src/screen/conversation/ConversationDetail.tsx +4 -2
  51. package/src/screen/home/Home.tsx +4 -2
  52. package/src/utils/logger.ts +40 -0
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Debug-gated logger for the SDK.
3
+ *
4
+ * A published SDK should not write to the host app's console in production. All
5
+ * internal logging goes through here so it can be silenced. By default logging
6
+ * follows React Native's `__DEV__` flag (on in development, off in release
7
+ * builds); hosts can override either way via {@link setDebugLogging}.
8
+ */
9
+
10
+ let enabled = typeof __DEV__ !== 'undefined' ? __DEV__ : false;
11
+
12
+ /** Enable or disable SDK debug logging at runtime. */
13
+ export const setDebugLogging = value => {
14
+ enabled = value;
15
+ };
16
+
17
+ /** Whether SDK debug logging is currently active. */
18
+ export const isDebugLogging = () => enabled;
19
+ const PREFIX = '[erxes]';
20
+ export const logger = {
21
+ info: function () {
22
+ if (enabled) {
23
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
24
+ args[_key] = arguments[_key];
25
+ }
26
+ console.log(PREFIX, ...args);
27
+ }
28
+ },
29
+ warn: function () {
30
+ if (enabled) {
31
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
32
+ args[_key2] = arguments[_key2];
33
+ }
34
+ console.warn(PREFIX, ...args);
35
+ }
36
+ },
37
+ error: function () {
38
+ if (enabled) {
39
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
40
+ args[_key3] = arguments[_key3];
41
+ }
42
+ console.error(PREFIX, ...args);
43
+ }
44
+ }
45
+ };
46
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["enabled","__DEV__","setDebugLogging","value","isDebugLogging","PREFIX","logger","info","_len","arguments","length","args","Array","_key","console","log","warn","_len2","_key2","error","_len3","_key3"],"sourceRoot":"../../../src","sources":["utils/logger.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,IAAIA,OAAO,GAAG,OAAOC,OAAO,KAAK,WAAW,GAAGA,OAAO,GAAG,KAAK;;AAE9D;AACA,OAAO,MAAMC,eAAe,GAAIC,KAAc,IAAK;EACjDH,OAAO,GAAGG,KAAK;AACjB,CAAC;;AAED;AACA,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAMJ,OAAO;AAE3C,MAAMK,MAAM,GAAG,SAAS;AAExB,OAAO,MAAMC,MAAM,GAAG;EACpBC,IAAI,EAAE,SAAAA,CAAA,EAAwB;IAC5B,IAAIP,OAAO,EAAE;MAAA,SAAAQ,IAAA,GAAAC,SAAA,CAAAC,MAAA,EADLC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;QAAJF,IAAI,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;MAAA;MAEVC,OAAO,CAACC,GAAG,CAACV,MAAM,EAAE,GAAGM,IAAI,CAAC;IAC9B;EACF,CAAC;EACDK,IAAI,EAAE,SAAAA,CAAA,EAAwB;IAC5B,IAAIhB,OAAO,EAAE;MAAA,SAAAiB,KAAA,GAAAR,SAAA,CAAAC,MAAA,EADLC,IAAI,OAAAC,KAAA,CAAAK,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;QAAJP,IAAI,CAAAO,KAAA,IAAAT,SAAA,CAAAS,KAAA;MAAA;MAEVJ,OAAO,CAACE,IAAI,CAACX,MAAM,EAAE,GAAGM,IAAI,CAAC;IAC/B;EACF,CAAC;EACDQ,KAAK,EAAE,SAAAA,CAAA,EAAwB;IAC7B,IAAInB,OAAO,EAAE;MAAA,SAAAoB,KAAA,GAAAX,SAAA,CAAAC,MAAA,EADJC,IAAI,OAAAC,KAAA,CAAAQ,KAAA,GAAAC,KAAA,MAAAA,KAAA,GAAAD,KAAA,EAAAC,KAAA;QAAJV,IAAI,CAAAU,KAAA,IAAAZ,SAAA,CAAAY,KAAA;MAAA;MAEXP,OAAO,CAACK,KAAK,CAACd,MAAM,EAAE,GAAGM,IAAI,CAAC;IAChC;EACF;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.tsx"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,KAAoB,MAAM,OAAO,CAAC;AAMzC,MAAM,MAAM,SAAS,GAAG;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAmGjC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.tsx"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,KAAoB,MAAM,OAAO,CAAC;AAOzC,MAAM,MAAM,SAAS,GAAG;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAmGjC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Widget.d.ts","sourceRoot":"","sources":["../../src/Widget.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAyCzC,QAAA,MAAM,MAAM,UAAW,GAAG,6BA+TzB,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Widget.d.ts","sourceRoot":"","sources":["../../src/Widget.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAoB,MAAM,OAAO,CAAC;AA0CzC,QAAA,MAAM,MAAM,UAAW,GAAG,6BA+TzB,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"InputTools.d.ts","sourceRoot":"","sources":["../../../src/components/InputTools.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAoCpE,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAwO7B,CAAC;AA0IF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"InputTools.d.ts","sourceRoot":"","sources":["../../../src/components/InputTools.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAqCpE,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAwO7B,CAAC;AA0IF,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloContainer.d.ts","sourceRoot":"","sources":["../../../src/graphql/ApolloContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAc1B,QAAA,MAAM,eAAe,4BAA6B,GAAG,sBAmDpD,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"ApolloContainer.d.ts","sourceRoot":"","sources":["../../../src/graphql/ApolloContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAe1B,QAAA,MAAM,eAAe,4BAA6B,GAAG,sBAmDpD,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { ErxesNativeIOS } from './nativeIos';
2
2
  export type { NativeIOSAction, NativeIOSConfig, NativeIOSUser, } from './nativeIos';
3
+ export { setDebugLogging, isDebugLogging } from './utils/logger';
3
4
  export { ErxesMessenger } from './ErxesMessenger';
4
5
  export type { ErxesUser, ErxesAction, ErxesMessengerHelpers, ErxesMessengerProps, } from './ErxesMessenger';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EACV,eAAe,EACf,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EACV,eAAe,EACf,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationDetail.d.ts","sourceRoot":"","sources":["../../../../src/screen/conversation/ConversationDetail.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAgFxE,QAAA,MAAM,kBAAkB,yBA8TvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"ConversationDetail.d.ts","sourceRoot":"","sources":["../../../../src/screen/conversation/ConversationDetail.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAiFxE,QAAA,MAAM,kBAAkB,yBA+TvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../../../src/screen/home/Home.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAkB1C,QAAA,MAAM,IAAI,yBA8MT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../../../src/screen/home/Home.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAmB1C,QAAA,MAAM,IAAI,yBA+MT,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Debug-gated logger for the SDK.
3
+ *
4
+ * A published SDK should not write to the host app's console in production. All
5
+ * internal logging goes through here so it can be silenced. By default logging
6
+ * follows React Native's `__DEV__` flag (on in development, off in release
7
+ * builds); hosts can override either way via {@link setDebugLogging}.
8
+ */
9
+ /** Enable or disable SDK debug logging at runtime. */
10
+ export declare const setDebugLogging: (value: boolean) => void;
11
+ /** Whether SDK debug logging is currently active. */
12
+ export declare const isDebugLogging: () => boolean;
13
+ export declare const logger: {
14
+ info: (...args: unknown[]) => void;
15
+ warn: (...args: unknown[]) => void;
16
+ error: (...args: unknown[]) => void;
17
+ };
18
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,sDAAsD;AACtD,eAAO,MAAM,eAAe,UAAW,OAAO,SAE7C,CAAC;AAEF,qDAAqD;AACrD,eAAO,MAAM,cAAc,eAAgB,CAAC;AAI5C,eAAO,MAAM,MAAM;oBACD,OAAO,EAAE;oBAKT,OAAO,EAAE;qBAKR,OAAO,EAAE;CAK3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-erxes-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.3",
4
4
  "description": "react-native erxes sdk",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -36,10 +36,10 @@ Pod::Spec.new do |s|
36
36
  spm_dependency(
37
37
  s,
38
38
  url: 'https://github.com/erxes/erxes-ios-sdk.git',
39
- requirement: { :kind => 'exactVersion', :version => '0.30.7' },
39
+ requirement: { :kind => 'exactVersion', :version => '0.30.10' },
40
40
  products: ['MessengerSDK']
41
41
  )
42
42
  else
43
- raise 'rn-erxes-sdk requires React Native 0.81+ CocoaPods SPM support to install MessengerSDK 0.30.7'
43
+ raise 'rn-erxes-sdk requires React Native 0.81+ CocoaPods SPM support to install MessengerSDK 0.30.10'
44
44
  end
45
45
  end
package/src/App.tsx CHANGED
@@ -3,6 +3,7 @@ import React, { useEffect } from 'react';
3
3
  import Widget from './Widget';
4
4
  import AsyncStorage from '@react-native-async-storage/async-storage';
5
5
  import { createObjectIdLikeString } from './utils/objectId';
6
+ import { logger } from './utils/logger';
6
7
  import ApolloContainer from './graphql/ApolloContainer';
7
8
 
8
9
  export type PropTypes = {
@@ -69,7 +70,7 @@ const ErxesSDK: React.FC<PropTypes> = ({
69
70
  })
70
71
  .catch((e) => {
71
72
  setLoading(false);
72
- console.log('Failed on cachedConversationId', e.message);
73
+ logger.error('Failed on cachedConversationId', e.message);
73
74
  });
74
75
  })
75
76
  .catch((e) => {
@@ -78,7 +79,7 @@ const ErxesSDK: React.FC<PropTypes> = ({
78
79
  visitorId: createObjectIdLikeString(),
79
80
  });
80
81
  setLoading(false);
81
- console.log('Failed on cachedCustomerId', e.message);
82
+ logger.error('Failed on cachedCustomerId', e.message);
82
83
  });
83
84
  }, []);
84
85
 
package/src/Widget.tsx CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  widgetsSaveBrowserInfo,
10
10
  } from './graphql/mutation';
11
11
  import AppContext from './context/Context';
12
+ import { logger } from './utils/logger';
12
13
  import ConversationDetail from './screen/conversation/ConversationDetail';
13
14
  import MessengerShell from './components/MessengerShell';
14
15
  import { TouchableOpacity } from 'react-native';
@@ -119,7 +120,7 @@ const Widget = (props: any) => {
119
120
  return res;
120
121
  })
121
122
  .catch((err) => {
122
- console.log(err);
123
+ logger.error('readConversationMessages failed', err);
123
124
  return null;
124
125
  });
125
126
  },
@@ -210,7 +211,7 @@ const Widget = (props: any) => {
210
211
  refetchUnreadConversations();
211
212
  },
212
213
  error(err) {
213
- console.log(err);
214
+ logger.error('unread conversations subscription error', err);
214
215
  },
215
216
  });
216
217
 
@@ -248,7 +249,7 @@ const Widget = (props: any) => {
248
249
  }
249
250
  })
250
251
  .catch((err) => {
251
- console.log(err);
252
+ logger.error('connect failed', err);
252
253
  });
253
254
  }, []);
254
255
 
@@ -261,10 +262,10 @@ const Widget = (props: any) => {
261
262
  },
262
263
  })
263
264
  .then(() => {
264
- console.log('browser info saved');
265
+ logger.info('browser info saved');
265
266
  })
266
267
  .catch((err) => {
267
- console.log(err);
268
+ logger.error('saveBrowserInfo failed', err);
268
269
  });
269
270
  }
270
271
  }, [connection]);
@@ -11,6 +11,7 @@ import {
11
11
  Platform,
12
12
  } from 'react-native';
13
13
  import { messengerTheme } from '../theme';
14
+ import { logger } from '../utils/logger';
14
15
  import {
15
16
  SendIcon,
16
17
  AttachmentIcon,
@@ -107,7 +108,7 @@ const InputTools: React.FC<any> = (props: any) => {
107
108
  const uploaded = await uploadFile(file, subDomain);
108
109
  setAttachments((prev) => [...prev, uploaded]);
109
110
  } catch (err) {
110
- console.log('attachment upload failed', err);
111
+ logger.error('attachment upload failed', err);
111
112
  const message = err instanceof Error ? err.message : '';
112
113
  showUploadError(
113
114
  message.includes('Invalid configured file type')
@@ -10,6 +10,7 @@ import {
10
10
  import { getMainDefinition } from '@apollo/client/utilities';
11
11
  import { onError } from '@apollo/client/link/error';
12
12
  import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
13
+ import { logger } from '../utils/logger';
13
14
  import { createClient } from 'graphql-ws';
14
15
 
15
16
  const ApolloContainer = ({ children, subDomain }: any) => {
@@ -28,8 +29,8 @@ const ApolloContainer = ({ children, subDomain }: any) => {
28
29
  );
29
30
 
30
31
  const logoutLink = onError(({ networkError, graphQLErrors }) => {
31
- console.log('--netError', networkError);
32
- console.log('--gqlError', graphQLErrors);
32
+ logger.error('network error', networkError);
33
+ logger.error('graphQL errors', graphQLErrors);
33
34
  });
34
35
 
35
36
  const httpLink = createHttpLink({
package/src/index.tsx CHANGED
@@ -5,6 +5,8 @@ export type {
5
5
  NativeIOSUser,
6
6
  } from './nativeIos';
7
7
 
8
+ export { setDebugLogging, isDebugLogging } from './utils/logger';
9
+
8
10
  export { ErxesMessenger } from './ErxesMessenger';
9
11
  export type {
10
12
  ErxesUser,
@@ -32,6 +32,7 @@ import { BackIcon } from '../../components/Icons';
32
32
  import DateSeparator from '../../components/conversation/DateSeparator';
33
33
  import WelcomeMessage from '../../components/conversation/WelcomeMessage';
34
34
  import TypingStatus from '../../components/conversation/TypingStatus';
35
+ import { logger } from '../../utils/logger';
35
36
 
36
37
  const hasUserDetails = (user: any): boolean =>
37
38
  Boolean(user?.details?.fullName || user?.details?.avatar);
@@ -301,7 +302,8 @@ const ConversationDetail = () => {
301
302
  })
302
303
  .then((res: any) => {
303
304
  if (res.errors) {
304
- return console.log(res.errors);
305
+ logger.error('insertMessage errors', res.errors);
306
+ return;
305
307
  }
306
308
 
307
309
  const insertedMessage = res.data.widgetsInsertMessage;
@@ -326,7 +328,7 @@ const ConversationDetail = () => {
326
328
  }
327
329
  })
328
330
  .catch((err: any) => {
329
- console.log(err);
331
+ logger.error('insertMessage failed', err);
330
332
  })
331
333
  .finally(() => {
332
334
  sendingRef.current = false;
@@ -14,6 +14,7 @@ import React, { useContext } from 'react';
14
14
  import AsyncStorage from '@react-native-async-storage/async-storage';
15
15
  import { useMutation } from '@apollo/client';
16
16
  import AppContext from '../../context/Context';
17
+ import { logger } from '../../utils/logger';
17
18
  import Supporters from '../greetings/Supporters';
18
19
  import Social from '../greetings/Social';
19
20
  import { messengerTheme } from '../../theme';
@@ -92,7 +93,8 @@ const Home = () => {
92
93
  })
93
94
  .then((res: any) => {
94
95
  if (res.errors) {
95
- return console.log(res.errors);
96
+ logger.error('insertMessage errors', res.errors);
97
+ return;
96
98
  }
97
99
 
98
100
  const insertedMessage = res.data.widgetsInsertMessage;
@@ -104,7 +106,7 @@ const Home = () => {
104
106
  }
105
107
  })
106
108
  .catch((err: any) => {
107
- console.log(err);
109
+ logger.error('insertMessage failed', err);
108
110
  })
109
111
  .finally(() => {
110
112
  sendingRef.current = false;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Debug-gated logger for the SDK.
3
+ *
4
+ * A published SDK should not write to the host app's console in production. All
5
+ * internal logging goes through here so it can be silenced. By default logging
6
+ * follows React Native's `__DEV__` flag (on in development, off in release
7
+ * builds); hosts can override either way via {@link setDebugLogging}.
8
+ */
9
+
10
+ declare const __DEV__: boolean;
11
+
12
+ let enabled = typeof __DEV__ !== 'undefined' ? __DEV__ : false;
13
+
14
+ /** Enable or disable SDK debug logging at runtime. */
15
+ export const setDebugLogging = (value: boolean) => {
16
+ enabled = value;
17
+ };
18
+
19
+ /** Whether SDK debug logging is currently active. */
20
+ export const isDebugLogging = () => enabled;
21
+
22
+ const PREFIX = '[erxes]';
23
+
24
+ export const logger = {
25
+ info: (...args: unknown[]) => {
26
+ if (enabled) {
27
+ console.log(PREFIX, ...args);
28
+ }
29
+ },
30
+ warn: (...args: unknown[]) => {
31
+ if (enabled) {
32
+ console.warn(PREFIX, ...args);
33
+ }
34
+ },
35
+ error: (...args: unknown[]) => {
36
+ if (enabled) {
37
+ console.error(PREFIX, ...args);
38
+ }
39
+ },
40
+ };