@bugfender/rn-bugfender 1.1.3 → 2.0.0-alpha.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.
Files changed (166) hide show
  1. package/README.md +110 -86
  2. package/RnBugfender.podspec +21 -0
  3. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  4. package/android/.gradle/{5.6.4 → 7.1/dependencies-accessors}/gc.properties +0 -0
  5. package/android/.gradle/7.1/executionHistory/executionHistory.bin +0 -0
  6. package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
  7. package/android/.gradle/{5.6.4 → 7.1}/fileChanges/last-build.bin +0 -0
  8. package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
  9. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  10. package/android/.gradle/7.1/gc.properties +0 -0
  11. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  12. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  13. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  14. package/android/.gradle/checksums/checksums.lock +0 -0
  15. package/android/.gradle/{5.6.4/fileHashes/fileHashes.bin → checksums/md5-checksums.bin} +0 -0
  16. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  17. package/android/.idea/compiler.xml +6 -0
  18. package/android/.idea/gradle.xml +1 -2
  19. package/android/.idea/jarRepositories.xml +40 -0
  20. package/android/.idea/misc.xml +4 -110
  21. package/android/.idea/runConfigurations.xml +1 -3
  22. package/android/.idea/uiDesigner.xml +124 -0
  23. package/android/build.gradle +47 -24
  24. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  25. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  26. package/android/gradlew +34 -21
  27. package/android/gradlew.bat +24 -19
  28. package/android/src/main/AndroidManifest.xml +4 -3
  29. package/android/src/main/java/com/bugfender/react/{RNBugfenderModule.java → RnBugfenderModule.java} +88 -13
  30. package/android/src/main/java/com/bugfender/react/RnBugfenderPackage.java +28 -0
  31. package/ios/RnBugfender.h +5 -0
  32. package/ios/{RNBugfender.m → RnBugfender.m} +67 -8
  33. package/ios/{RNBugfender.xcodeproj → RnBugfender.xcodeproj}/project.pbxproj +42 -37
  34. package/ios/{RNBugfender.xcodeproj → RnBugfender.xcodeproj}/project.xcworkspace/contents.xcworkspacedata +0 -3
  35. package/ios/{RNBugfender.xcodeproj → RnBugfender.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  36. package/ios/RnBugfender.xcodeproj/project.xcworkspace/xcuserdata/fj.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  37. package/ios/{RNBugfender.xcodeproj/xcuserdata/rubenvot.xcuserdatad → RnBugfender.xcodeproj/xcuserdata/fj.xcuserdatad}/xcschemes/xcschememanagement.plist +1 -6
  38. package/lib/commonjs/bugfender.js +338 -0
  39. package/lib/commonjs/bugfender.js.map +1 -0
  40. package/lib/commonjs/index.js +28 -0
  41. package/lib/commonjs/index.js.map +1 -0
  42. package/lib/commonjs/index.web.js +30 -0
  43. package/lib/commonjs/index.web.js.map +1 -0
  44. package/lib/commonjs/override-console-methods.js +91 -0
  45. package/lib/commonjs/override-console-methods.js.map +1 -0
  46. package/lib/commonjs/print-to-console.js +78 -0
  47. package/lib/commonjs/print-to-console.js.map +1 -0
  48. package/lib/commonjs/sdk-options.js +81 -0
  49. package/lib/commonjs/sdk-options.js.map +1 -0
  50. package/lib/commonjs/string-formatter.js +55 -0
  51. package/lib/commonjs/string-formatter.js.map +1 -0
  52. package/lib/commonjs/types/device.js +2 -0
  53. package/lib/commonjs/types/device.js.map +1 -0
  54. package/lib/commonjs/types/log.js +35 -0
  55. package/lib/commonjs/types/log.js.map +1 -0
  56. package/lib/commonjs/types/sdk-options.js +55 -0
  57. package/lib/commonjs/types/sdk-options.js.map +1 -0
  58. package/lib/commonjs/user-feedback.js +31 -0
  59. package/lib/commonjs/user-feedback.js.map +1 -0
  60. package/lib/module/bugfender.js +323 -0
  61. package/lib/module/bugfender.js.map +1 -0
  62. package/lib/module/index.js +6 -0
  63. package/lib/module/index.js.map +1 -0
  64. package/lib/module/index.web.js +5 -0
  65. package/lib/module/index.web.js.map +1 -0
  66. package/lib/module/override-console-methods.js +75 -0
  67. package/lib/module/override-console-methods.js.map +1 -0
  68. package/lib/module/print-to-console.js +67 -0
  69. package/lib/module/print-to-console.js.map +1 -0
  70. package/lib/module/sdk-options.js +72 -0
  71. package/lib/module/sdk-options.js.map +1 -0
  72. package/lib/module/string-formatter.js +45 -0
  73. package/lib/module/string-formatter.js.map +1 -0
  74. package/lib/module/types/device.js +2 -0
  75. package/lib/module/types/device.js.map +1 -0
  76. package/lib/module/types/log.js +24 -0
  77. package/lib/module/types/log.js.map +1 -0
  78. package/lib/module/types/sdk-options.js +46 -0
  79. package/lib/module/types/sdk-options.js.map +1 -0
  80. package/lib/module/user-feedback.js +22 -0
  81. package/lib/module/user-feedback.js.map +1 -0
  82. package/lib/typescript/bugfender.d.ts +163 -0
  83. package/lib/typescript/index.d.ts +5 -0
  84. package/lib/typescript/index.web.d.ts +4 -0
  85. package/lib/typescript/override-console-methods.d.ts +10 -0
  86. package/lib/typescript/print-to-console.d.ts +14 -0
  87. package/lib/typescript/sdk-options.d.ts +16 -0
  88. package/lib/typescript/string-formatter.d.ts +4 -0
  89. package/lib/typescript/types/device.d.ts +4 -0
  90. package/lib/typescript/types/log.d.ts +59 -0
  91. package/lib/typescript/types/sdk-options.d.ts +40 -0
  92. package/lib/typescript/user-feedback.d.ts +31 -0
  93. package/package.json +146 -12
  94. package/src/bugfender.ts +360 -0
  95. package/src/index.tsx +7 -0
  96. package/src/index.web.tsx +5 -0
  97. package/src/override-console-methods.ts +53 -0
  98. package/src/print-to-console.ts +67 -0
  99. package/src/sdk-options.ts +68 -0
  100. package/src/string-formatter.ts +44 -0
  101. package/src/types/device.ts +4 -0
  102. package/src/types/log.ts +75 -0
  103. package/src/types/sdk-options.ts +81 -0
  104. package/src/user-feedback.ts +33 -0
  105. package/.idea/codeStyles/Project.xml +0 -116
  106. package/.idea/modules.xml +0 -8
  107. package/.idea/rn-bugfender.iml +0 -9
  108. package/.idea/vcs.xml +0 -6
  109. package/RNBugfender.podspec +0 -26
  110. package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
  111. package/android/.idea/caches/build_file_checksums.ser +0 -0
  112. package/android/.idea/codeStyles/Project.xml +0 -116
  113. package/android/.idea/libraries/Gradle__com_android_support_appcompat_v7_23_0_1_aar.xml +0 -15
  114. package/android/.idea/libraries/Gradle__com_android_support_recyclerview_v7_23_0_1_aar.xml +0 -12
  115. package/android/.idea/libraries/Gradle__com_android_support_support_annotations_23_0_1_jar.xml +0 -11
  116. package/android/.idea/libraries/Gradle__com_android_support_support_v4_23_0_1_aar.xml +0 -16
  117. package/android/.idea/libraries/Gradle__com_bugfender_sdk_android_3_0_5_aar.xml +0 -12
  118. package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_0_8_1_aar.xml +0 -12
  119. package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_0_8_1_aar.xml +0 -12
  120. package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_0_8_1_aar.xml +0 -12
  121. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_0_8_1_aar.xml +0 -12
  122. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp_0_8_1_aar.xml +0 -12
  123. package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_20_1_aar.xml +0 -16
  124. package/android/.idea/libraries/Gradle__com_facebook_stetho_stetho_1_2_0_jar.xml +0 -11
  125. package/android/.idea/libraries/Gradle__com_facebook_stetho_stetho_okhttp_1_2_0_jar.xml +0 -11
  126. package/android/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_2_3_jar.xml +0 -11
  127. package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_0_jar.xml +0 -11
  128. package/android/.idea/libraries/Gradle__com_nineoldandroids_library_2_4_0_jar.xml +0 -11
  129. package/android/.idea/libraries/Gradle__com_parse_bolts_bolts_android_1_1_4_jar.xml +0 -11
  130. package/android/.idea/libraries/Gradle__com_squareup_okhttp_okhttp_2_5_0_jar.xml +0 -11
  131. package/android/.idea/libraries/Gradle__com_squareup_okhttp_okhttp_ws_2_5_0_jar.xml +0 -11
  132. package/android/.idea/libraries/Gradle__com_squareup_okio_okio_1_6_0_jar.xml +0 -11
  133. package/android/.idea/libraries/Gradle__commons_cli_commons_cli_1_2_jar.xml +0 -13
  134. package/android/.idea/libraries/Gradle__org_webkit_android_jsc_r174650_aar.xml +0 -10
  135. package/android/.idea/modules.xml +0 -8
  136. package/android/android.iml +0 -116
  137. package/android/build/generated/source/buildConfig/debug/com/bugfender/react/BuildConfig.java +0 -13
  138. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -11
  139. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output.json +0 -1
  140. package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
  141. package/android/build/intermediates/compile_library_classes/debug/classes.jar +0 -0
  142. package/android/build/intermediates/compile_only_not_namespaced_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  143. package/android/build/intermediates/incremental/debug-mergeJniLibs/merge-state +0 -0
  144. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
  145. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
  146. package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
  147. package/android/build/intermediates/incremental/packageDebugResources/compile-file-map.properties +0 -1
  148. package/android/build/intermediates/incremental/packageDebugResources/merger.xml +0 -2
  149. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/bugfender/react/BuildConfig.class +0 -0
  150. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/bugfender/react/RNBugfenderModule.class +0 -0
  151. package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/bugfender/react/RNBugfenderPackage.class +0 -0
  152. package/android/build/intermediates/library_java_res/debug/res.jar +0 -0
  153. package/android/build/intermediates/library_manifest/debug/AndroidManifest.xml +0 -11
  154. package/android/build/intermediates/merged_manifests/debug/output.json +0 -1
  155. package/android/build/intermediates/res/symbol-table-with-package/debug/package-aware-r.txt +0 -1309
  156. package/android/build/intermediates/runtime_library_classes/debug/classes.jar +0 -0
  157. package/android/build/intermediates/symbols/debug/R.txt +0 -1783
  158. package/android/build/intermediates/transforms/mergeJniLibs/debug/__content__.json +0 -1
  159. package/android/build/outputs/logs/manifest-merger-debug-report.txt +0 -37
  160. package/android/local.properties +0 -8
  161. package/android/src/main/java/com/bugfender/react/RNBugfenderPackage.java +0 -29
  162. package/bugfender.js +0 -188
  163. package/example/.babelrc +0 -3
  164. package/example/.watchmanconfig +0 -1
  165. package/example/App.js +0 -121
  166. package/ios/RNBugfender.h +0 -7
@@ -0,0 +1,360 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import type { ISDKOptions } from './types/sdk-options';
3
+ import type { UserFeedbackOptions, UserFeedbackResult } from './user-feedback';
4
+ import { DefaultUserFeedbackOptions } from './user-feedback';
5
+ import type { DeviceKeyValue } from './types/device';
6
+ import type { ILogEntry } from './types/log';
7
+ import { StringFormatter } from './string-formatter';
8
+ import { LogLevel } from "./types/log";
9
+ import { OverrideConsoleMethods } from "./override-console-methods";
10
+ import { PrintToConsole } from "./print-to-console";
11
+ import { SDKOptions } from "./sdk-options";
12
+
13
+ const LINKING_ERROR =
14
+ `The package '@bugfender/rn-bugfender' doesn't seem to be linked. Make sure: \n\n` +
15
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
16
+ '- You rebuilt the app after installing the package\n' +
17
+ '- You are not using Expo managed workflow\n';
18
+
19
+ const RnBugfender = NativeModules.RnBugfender
20
+ ? NativeModules.RnBugfender
21
+ : new Proxy(
22
+ {},
23
+ {
24
+ get() {
25
+ throw new Error(LINKING_ERROR);
26
+ },
27
+ }
28
+ );
29
+
30
+ class BugfenderClass {
31
+ private stringFormatter = new StringFormatter();
32
+ private overrideConsoleMethods = new OverrideConsoleMethods(window);
33
+ private printToConsole = new PrintToConsole(global.console);
34
+ private sdkOptions: SDKOptions = new SDKOptions();
35
+ private initialized = false;
36
+
37
+ public async init(options: ISDKOptions): Promise<void> {
38
+ if (!this.initialized) {
39
+ const validatedOptions = this.sdkOptions.init(options);
40
+
41
+ // Needs to be executed prior initialization
42
+ if (typeof options.deviceName !== 'undefined') {
43
+ RnBugfender.overrideDeviceName(options.deviceName);
44
+ }
45
+
46
+ // Library initialization
47
+ Platform.OS === 'ios'
48
+ ? RnBugfender.activateLogger(validatedOptions.appKey)
49
+ : RnBugfender.init(validatedOptions.appKey, false);
50
+
51
+ if (typeof validatedOptions.apiURL !== 'undefined') {
52
+ RnBugfender.setApiUrl(validatedOptions.apiURL);
53
+ }
54
+
55
+ if (typeof validatedOptions.baseURL !== 'undefined') {
56
+ RnBugfender.setBaseUrl(validatedOptions.baseURL);
57
+ }
58
+
59
+ if (validatedOptions.enableLogcatLogging) {
60
+ RnBugfender.enableLogcatLogging();
61
+ }
62
+
63
+ if (validatedOptions.logUIEvents) {
64
+ RnBugfender.enableUIEventLogging();
65
+ }
66
+
67
+ if (validatedOptions.registerErrorHandler) {
68
+ RnBugfender.enableCrashReporting();
69
+ }
70
+
71
+ if (validatedOptions.overrideConsoleMethods) {
72
+ this.overrideConsoleMethods.init(this.stringFormatter);
73
+ }
74
+
75
+ this.printToConsole.init(validatedOptions.printToConsole ?? true);
76
+
77
+ this.initialized = true;
78
+ }
79
+ }
80
+
81
+ /**
82
+ * @returns Bugfender dashboard URL for the device
83
+ */
84
+ public getDeviceURL(): Promise<string> {
85
+ return RnBugfender.getDeviceUrl();
86
+ }
87
+
88
+ /**
89
+ * @returns Bugfender dashboard URL for the current session
90
+ */
91
+ public getSessionURL(): Promise<string> {
92
+ return RnBugfender.getSessionUrl();
93
+ }
94
+
95
+ /**
96
+ * Show a modal which asks for feedback. Once the user closes the modal or sends the feedback
97
+ * the returned promise resolves with the result.
98
+ *
99
+ * ```typescript
100
+ * Bugfender.getUserFeedback().then((result) => {
101
+ * if (result.isSent) {
102
+ * // User sent the feedback
103
+ * // `result.feedbackURL` contains the Bugfender feedback URL
104
+ * } else {
105
+ * // User closed the modal without sending the feedback
106
+ * }
107
+ * });
108
+ * ```
109
+ *
110
+ * @param options Options object to configure modal strings
111
+ * @returns Promise which resolves once the user closes the modal or sends the feedback
112
+ */
113
+ public async getUserFeedback(
114
+ options?: UserFeedbackOptions
115
+ ): Promise<UserFeedbackResult> {
116
+ return new Promise<UserFeedbackResult>((resolve) => {
117
+ options = {
118
+ ...new DefaultUserFeedbackOptions(),
119
+ ...(options ?? {}),
120
+ };
121
+
122
+ return RnBugfender.showUserFeedback(
123
+ options.title,
124
+ options.hint,
125
+ options.subjectPlaceholder,
126
+ options.feedbackPlaceholder,
127
+ options.submitLabel,
128
+ options.closeLabel
129
+ ).then(
130
+ (value: string) => {
131
+ resolve({
132
+ isSent: true,
133
+ feedbackURL: value,
134
+ });
135
+ },
136
+ (_: any) => {
137
+ resolve({
138
+ isSent: false,
139
+ });
140
+ }
141
+ );
142
+ });
143
+ }
144
+
145
+ /**
146
+ * @param obj A JavaScript value to output
147
+ * @param objs List of optional JavaScript values to output
148
+ */
149
+ public log(obj: unknown, ...objs: unknown[]): void;
150
+ /**
151
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
152
+ *
153
+ * @param msg Message with optional `%` placeholders
154
+ * @param subst Optional substitutions list
155
+ */
156
+ public log(msg: string, ...subst: unknown[]): void;
157
+ public log(...parameters: unknown[]): void {
158
+ this.printToConsole.log(...parameters);
159
+
160
+ let message = this.stringFormatter.format([...parameters]);
161
+ RnBugfender.debug('', message);
162
+ }
163
+
164
+ /**
165
+ * @param obj A JavaScript value to output
166
+ * @param objs List of optional JavaScript values to output
167
+ */
168
+ public warn(obj: unknown, ...objs: unknown[]): void;
169
+ /**
170
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
171
+ *
172
+ * @param msg Message with optional `%` placeholders
173
+ * @param subst Optional substitutions list
174
+ */
175
+ public warn(msg: string, ...subst: unknown[]): void;
176
+ public warn(...parameters: unknown[]): void {
177
+ this.printToConsole.warn(...parameters);
178
+
179
+ let message = this.stringFormatter.format([...parameters]);
180
+ RnBugfender.warning('', message);
181
+ }
182
+
183
+ /**
184
+ * @param obj A JavaScript value to output
185
+ * @param objs List of optional JavaScript values to output
186
+ */
187
+ public error(obj: unknown, ...objs: unknown[]): void;
188
+ /**
189
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
190
+ *
191
+ * @param msg Message with optional `%` placeholders
192
+ * @param subst Optional substitutions list
193
+ */
194
+ public error(msg: string, ...subst: unknown[]): void;
195
+ public error(...parameters: unknown[]): void {
196
+ this.printToConsole.error(...parameters);
197
+
198
+ let message = this.stringFormatter.format([...parameters]);
199
+ RnBugfender.error('', message);
200
+ }
201
+
202
+ /**
203
+ * @param obj A JavaScript value to output
204
+ * @param objs List of optional JavaScript values to output
205
+ */
206
+ public trace(obj: unknown, ...objs: unknown[]): void;
207
+ /**
208
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
209
+ *
210
+ * @param msg Message with optional `%` placeholders
211
+ * @param subst Optional substitutions list
212
+ */
213
+ public trace(msg: string, ...subst: unknown[]): void;
214
+ public trace(...parameters: unknown[]): void {
215
+ this.printToConsole.trace(...parameters);
216
+
217
+ let message = this.stringFormatter.format([...parameters]);
218
+ RnBugfender.trace('', message);
219
+ }
220
+
221
+ /**
222
+ * @param obj A JavaScript value to output
223
+ * @param objs List of optional JavaScript values to output
224
+ */
225
+ public info(obj: unknown, ...objs: unknown[]): void;
226
+ /**
227
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
228
+ *
229
+ * @param msg Message with optional `%` placeholders
230
+ * @param subst Optional substitutions list
231
+ */
232
+ public info(msg: string, ...subst: unknown[]): void;
233
+ public info(...parameters: unknown[]): void {
234
+ this.printToConsole.info(...parameters);
235
+
236
+ let message = this.stringFormatter.format([...parameters]);
237
+ RnBugfender.info('', message);
238
+ }
239
+
240
+ /**
241
+ * @param obj A JavaScript value to output
242
+ * @param objs List of optional JavaScript values to output
243
+ */
244
+ public fatal(obj: unknown, ...objs: unknown[]): void;
245
+ /**
246
+ * String message with optional substitutions. This mimicks que the `window.console` template messages. [Learn more in MDN](https://developer.mozilla.org/en-US/docs/Web/API/console#Using_string_substitutions).
247
+ *
248
+ * @param msg Message with optional `%` placeholders
249
+ * @param subst Optional substitutions list
250
+ */
251
+ public fatal(msg: string, ...subst: unknown[]): void;
252
+ public fatal(...parameters: unknown[]): void {
253
+ this.printToConsole.error(...parameters);
254
+
255
+ let message = this.stringFormatter.format([...parameters]);
256
+ RnBugfender.fatal('', message);
257
+ }
258
+
259
+ /**
260
+ * Remove a device associated key-value pair. [Learn more](https://bugfender.com/blog/associated-device-information/).
261
+ *
262
+ * @param key Key identifier
263
+ */
264
+ public removeDeviceKey(key: string): void {
265
+ RnBugfender.removeDeviceKey(key);
266
+ this.printToConsole.info(`Device key "${key}" removed`);
267
+ }
268
+
269
+ /**
270
+ * Use this method if you need more control over the data sent while logging. See `ILogEntry` interface reference to see all the accepted properties.
271
+ *
272
+ * @param log Log object that complies with `ILogEntry` interface.
273
+ */
274
+ public sendLog(log: ILogEntry): void {
275
+ this.printToConsole.printLog(log);
276
+
277
+ RnBugfender.log(
278
+ log.line ?? 0,
279
+ log.method ?? '',
280
+ log.file ?? '',
281
+ log.level ?? LogLevel.Debug,
282
+ log.tag ?? '',
283
+ log.text ?? ''
284
+ );
285
+ }
286
+
287
+ /**
288
+ * Send an issue.
289
+ *
290
+ * @param title - Title
291
+ * @param text - Text content
292
+ * @returns Bugfender dashboard URL for the issue.
293
+ */
294
+ public sendIssue(title: string, text: string): Promise<string> {
295
+ this.printToConsole.warn(`Issue: ${title}.\n${text}`);
296
+ return RnBugfender.sendIssue(title, text);
297
+ }
298
+
299
+ /**
300
+ * Send a crash report.
301
+ *
302
+ * @param title - Title
303
+ * @param text - Text content
304
+ * @returns Bugfender dashboard URL for the crash.
305
+ */
306
+ public sendCrash(title: string, text: string): Promise<string> {
307
+ this.printToConsole.error(`Crash: ${title}.\n${text}`);
308
+ return RnBugfender.sendCrash(title, text);
309
+ }
310
+
311
+ /**
312
+ * Send an user feedback.
313
+ *
314
+ * @param title - Title/Subject
315
+ * @param text - Feedback text
316
+ * @returns Bugfender dashboard URL for the feedback.
317
+ */
318
+ public sendUserFeedback(title: string, text: string): Promise<string> {
319
+ this.printToConsole.info(`User Feedback: ${title}.\n${text}`);
320
+ return RnBugfender.sendUserFeedback(title, text);
321
+ }
322
+
323
+ /**
324
+ * Set a device associated key-value pair. [Learn more](https://bugfender.com/blog/associated-device-information/).
325
+ *
326
+ * @param key Key identifier.
327
+ * @param value Value.
328
+ */
329
+ public setDeviceKey(key: string, value: DeviceKeyValue): void {
330
+ this.printToConsole.info(`Device key "${key}" set to "${value}"`);
331
+
332
+ if (typeof value === 'boolean') {
333
+ RnBugfender.setDeviceBoolean(key, value);
334
+ } else if (typeof value === 'string') {
335
+ RnBugfender.setDeviceString(key, value);
336
+ } else {
337
+ // typeof value === 'number'
338
+ if (Number.isInteger(value)) {
339
+ RnBugfender.setDeviceInteger(key, value);
340
+ } else {
341
+ RnBugfender.setDeviceFloat(key, value);
342
+ }
343
+ }
344
+ }
345
+
346
+ /**
347
+ * Synchronizes all logs and issues with the server once, regardless if this device is enabled or not.
348
+ *
349
+ * Logs and issues are synchronized only once. After that, the logs are again sent according to the enabled flag
350
+ * in the Bugfender Console.
351
+ */
352
+ public forceSendOnce(): void {
353
+ this.printToConsole.info(`Force send once`);
354
+ RnBugfender.forceSendOnce();
355
+ }
356
+ }
357
+
358
+ export {
359
+ BugfenderClass, RnBugfender
360
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,7 @@
1
+ import { LogLevel } from './types/log';
2
+ import { SDKOptionsBuilder } from './types/sdk-options';
3
+ import { BugfenderClass } from './bugfender';
4
+
5
+ const Bugfender = new BugfenderClass();
6
+
7
+ export { Bugfender, LogLevel, SDKOptionsBuilder };
@@ -0,0 +1,5 @@
1
+ import { LogLevel } from './types/log';
2
+ import { SDKOptionsBuilder } from './types/sdk-options';
3
+ import { Bugfender } from '@bugfender/sdk';
4
+
5
+ export { Bugfender, LogLevel, SDKOptionsBuilder };
@@ -0,0 +1,53 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import {RnBugfender} from "./bugfender";
3
+ import type {StringFormatter} from "./string-formatter";
4
+
5
+ /**
6
+ * Overrides the `window.console` methods in order to execute the Bugfender equivalent logging
7
+ * methods while keeping the original browser functionality.
8
+ */
9
+ export class OverrideConsoleMethods {
10
+ constructor(
11
+ protected window: Window,
12
+ ) {
13
+ }
14
+
15
+ public init(stringFormatter: StringFormatter): void {
16
+
17
+ (this.window as any).console = function (console: Console) {
18
+ return {
19
+ ...console,
20
+ log: function (...parameters: unknown[]) {
21
+ console.log(...parameters);
22
+ let message = stringFormatter.format([...parameters]);
23
+ RnBugfender.debug('', message);
24
+ },
25
+ debug: function (...parameters: unknown[]) {
26
+ console.debug(...parameters);
27
+ let message = stringFormatter.format([...parameters]);
28
+ RnBugfender.debug('', message);
29
+ },
30
+ trace: function (...parameters: unknown[]) {
31
+ console.trace(...parameters);
32
+ let message = stringFormatter.format([...parameters]);
33
+ RnBugfender.trace('', message);
34
+ },
35
+ info: function (...parameters: unknown[]) {
36
+ console.info(...parameters);
37
+ let message = stringFormatter.format([...parameters]);
38
+ RnBugfender.info('', message);
39
+ },
40
+ warn: function (...parameters: unknown[]) {
41
+ console.warn(...parameters);
42
+ let message = stringFormatter.format([...parameters]);
43
+ RnBugfender.warning('', message);
44
+ },
45
+ error: function (...parameters: unknown[]) {
46
+ console.error(...parameters);
47
+ let message = stringFormatter.format([...parameters]);
48
+ RnBugfender.error('', message);
49
+ },
50
+ };
51
+ }((this.window as any).console);
52
+ }
53
+ }
@@ -0,0 +1,67 @@
1
+ import {format} from 'util';
2
+ import type {ILogEntry} from "./types/log";
3
+ import {LogLevel} from "./types/log";
4
+
5
+ export class PrintToConsole {
6
+ protected printToConsole: boolean = false;
7
+
8
+ constructor(
9
+ protected readonly console: Console,
10
+ ) {
11
+ }
12
+
13
+ public init(printToConsole: boolean): void {
14
+ this.printToConsole = printToConsole;
15
+ }
16
+
17
+ public error(...parameters: unknown[]): void {
18
+ if (this.printToConsole) {
19
+ this.console.error(...parameters);
20
+ }
21
+ }
22
+
23
+ public info(...parameters: unknown[]): void {
24
+ if (this.printToConsole) {
25
+ this.console.info(...parameters);
26
+ }
27
+ }
28
+
29
+ public log(...parameters: unknown[]): void {
30
+ if (this.printToConsole) {
31
+ this.console.log(...parameters);
32
+ }
33
+ }
34
+
35
+ public debug(...parameters: unknown[]): void {
36
+ if (this.printToConsole) {
37
+ this.console.debug(...parameters);
38
+ }
39
+ }
40
+
41
+ public trace(...parameters: unknown[]): void {
42
+ if (this.printToConsole) {
43
+ this.console.trace(...parameters);
44
+ }
45
+ }
46
+
47
+ public warn(...parameters: unknown[]): void {
48
+ if (this.printToConsole) {
49
+ this.console.warn(...parameters);
50
+ }
51
+ }
52
+
53
+ public printLog(log: ILogEntry): void {
54
+ if (this.printToConsole) {
55
+ // Log to browser console
56
+ // debug, warning, error, trace, info, fatal
57
+ const levelToMethod = ['log', 'warn', 'error', 'trace', 'info', 'error'];
58
+ const method = levelToMethod[log.level || LogLevel.Debug];
59
+ const tag = log.tag ? `[${log.tag}] ` : '';
60
+ const location = [log.file || '', log.method || '', log.line || ''].filter(p => p !== '').join(':');
61
+ const message = `${tag}${format(log.text)} ${location}`;
62
+
63
+ // @ts-ignore
64
+ this.console[method](message);
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,68 @@
1
+ import type {ISDKOptions} from "./types/sdk-options";
2
+
3
+ export class SDKOptions {
4
+ protected rules = {
5
+ appKey: ['required', 'string'],
6
+ apiURL: ['string', 'url'],
7
+ baseURL: ['string', 'url'],
8
+ overrideConsoleMethods: ['boolean'],
9
+ printToConsole: ['boolean'],
10
+ logBrowserEvents: ['boolean'],
11
+ logUIEvents: ['boolean'],
12
+ registerErrorHandler: ['boolean'],
13
+ version: ['string'],
14
+ };
15
+
16
+ public init(options: ISDKOptions): ISDKOptions {
17
+ // Validate user provided options
18
+ this.validate(options);
19
+
20
+ // Removing undefined attributes
21
+ options = { ...options };
22
+ Object.entries(options).forEach(([key, value]) => {
23
+ if (value === undefined) {
24
+ // @ts-ignore
25
+ delete options[key];
26
+ }
27
+ });
28
+
29
+ // Set default values if needed
30
+ return {
31
+ overrideConsoleMethods: true,
32
+ printToConsole: true,
33
+ logUIEvents: true,
34
+ registerErrorHandler: true,
35
+ enableLogcatLogging: false,
36
+ ...options,
37
+ };
38
+ }
39
+
40
+ protected validate(options: ISDKOptions): void {
41
+ const urlValidator = new RegExp(/^http(s)?:\/\//i);
42
+
43
+ Object.entries(this.rules).forEach(([key, rules]) => {
44
+ // @ts-ignore
45
+ const value = options[key];
46
+
47
+ rules.forEach(rule => {
48
+ if (rule === 'required') {
49
+ if (typeof value === 'undefined') {
50
+ throw new Error(`Bugfender requires '${key}' option to initialize.`)
51
+ }
52
+ } else if (rule === 'string') {
53
+ if (!['string', 'undefined'].includes(typeof value)) {
54
+ throw new Error(`'${key}' option must be a string.`);
55
+ }
56
+ } else if (rule === 'url') {
57
+ if (typeof value !== 'undefined' && !urlValidator.test(value)) {
58
+ throw new Error(`'${key}' option must be a valid URL.`);
59
+ }
60
+ } else if (rule === 'boolean') {
61
+ if (!['boolean', 'undefined'].includes(typeof value)) {
62
+ throw new Error(`'${key}' option must be a boolean.`);
63
+ }
64
+ }
65
+ })
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,44 @@
1
+ import {format} from "util";
2
+
3
+ export class StringFormatter {
4
+ public format(parameters: unknown[]): string {
5
+ const [, ...textParams] = parameters;
6
+ let [textFormat] = parameters as string[];
7
+ let text: string;
8
+
9
+ try {
10
+ // Our sanitizer gives better results, try with it first
11
+ textFormat = this.toString(textFormat);
12
+ } catch {
13
+ // Fallback to `format`
14
+ textFormat = format(textFormat);
15
+ }
16
+
17
+ if (textParams.length > 0) {
18
+ text = format(textFormat, ...textParams);
19
+ } else {
20
+ text = textFormat;
21
+ }
22
+
23
+ return text;
24
+ }
25
+
26
+ private toString(value: unknown): string {
27
+ // Depending on the type we prefer to do `String` or `stringify`
28
+ const isToString = ['string', 'symbol', 'bigint', 'function'].includes(typeof value) || value instanceof Error;
29
+
30
+ if (isToString) {
31
+ try {
32
+ return String(value);
33
+ } catch {
34
+ return JSON.stringify(value);
35
+ }
36
+ } else {
37
+ try {
38
+ return JSON.stringify(value);
39
+ } catch {
40
+ return String(value);
41
+ }
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Device Key Value
3
+ */
4
+ export type DeviceKeyValue = string | number | boolean;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Log Levels
3
+ *
4
+ * Check the main README to see how to access the `LogLevel` enum.
5
+ */
6
+ export enum LogLevel {
7
+ Debug = 0,
8
+ Warning = 1,
9
+ Error = 2,
10
+ Trace = 3,
11
+ Info = 4,
12
+ Fatal = 5,
13
+ }
14
+
15
+ /**
16
+ * @hidden
17
+ */
18
+ export const LOG_LEVELS: LogLevel[] = [
19
+ LogLevel.Debug,
20
+ LogLevel.Warning,
21
+ LogLevel.Error,
22
+ LogLevel.Trace,
23
+ LogLevel.Info,
24
+ LogLevel.Fatal,
25
+ ];
26
+
27
+ /**
28
+ * @hidden
29
+ */
30
+ export interface ILogEntryShort {
31
+ /** Date ISO */
32
+ x: string;
33
+ /** Text */
34
+ t: string;
35
+ /** Method */
36
+ m: string;
37
+ /** Absolute Time */
38
+ at: number;
39
+ /** Tag */
40
+ tg: string;
41
+ /** File */
42
+ f: string;
43
+ /** Line */
44
+ l: number;
45
+ /** Level */
46
+ ll: number;
47
+ /** URL */
48
+ u: string;
49
+ }
50
+
51
+ /**
52
+ * Log Entry object interface
53
+ */
54
+ export interface ILogEntry {
55
+ /** The line number where the log was triggered from */
56
+ line?: number;
57
+
58
+ /** The log's level based on LogLevel constant */
59
+ level?: LogLevel;
60
+
61
+ /** The log's tag */
62
+ tag?: string;
63
+
64
+ /** The method name where the log was triggered from */
65
+ method?: string;
66
+
67
+ /** The file name where the log was triggered from */
68
+ file?: string;
69
+
70
+ /** The log's text content */
71
+ text?: string;
72
+
73
+ /** The log's origin URL. This attribute is ignored on Android & iOS */
74
+ url?: string;
75
+ }