appambit 0.1.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 (52) hide show
  1. package/Appambit.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +191 -0
  4. package/android/build.gradle +78 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/appambit/AppambitAnalyticsModule.kt +56 -0
  8. package/android/src/main/java/com/appambit/AppambitCrashesModule.kt +90 -0
  9. package/android/src/main/java/com/appambit/AppambitModule.kt +22 -0
  10. package/android/src/main/java/com/appambit/AppambitPackage.kt +42 -0
  11. package/ios/AppAmbitAnalytics.h +5 -0
  12. package/ios/AppAmbitAnalytics.mm +45 -0
  13. package/ios/AppAmbitCrashes.h +5 -0
  14. package/ios/AppAmbitCrashes.mm +80 -0
  15. package/ios/AppAmbitSDKWrapper.swift +79 -0
  16. package/ios/Appambit.h +13 -0
  17. package/ios/Appambit.mm +17 -0
  18. package/lib/module/NativeAppambitAnalytics.js +5 -0
  19. package/lib/module/NativeAppambitAnalytics.js.map +1 -0
  20. package/lib/module/NativeAppambitCore.js +5 -0
  21. package/lib/module/NativeAppambitCore.js.map +1 -0
  22. package/lib/module/NativeAppambitCrashes.js +5 -0
  23. package/lib/module/NativeAppambitCrashes.js.map +1 -0
  24. package/lib/module/index.js +99 -0
  25. package/lib/module/index.js.map +1 -0
  26. package/lib/module/package.json +1 -0
  27. package/lib/typescript/appambit_test_app/src/App.d.ts +2 -0
  28. package/lib/typescript/appambit_test_app/src/App.d.ts.map +1 -0
  29. package/lib/typescript/appambit_test_app/src/components/CustomButton.d.ts +8 -0
  30. package/lib/typescript/appambit_test_app/src/components/CustomButton.d.ts.map +1 -0
  31. package/lib/typescript/appambit_test_app/src/components/CustomInput.d.ts +10 -0
  32. package/lib/typescript/appambit_test_app/src/components/CustomInput.d.ts.map +1 -0
  33. package/lib/typescript/appambit_test_app/src/screens/AnalyticsScreen.d.ts +2 -0
  34. package/lib/typescript/appambit_test_app/src/screens/AnalyticsScreen.d.ts.map +1 -0
  35. package/lib/typescript/appambit_test_app/src/screens/CrashesScreen.d.ts +2 -0
  36. package/lib/typescript/appambit_test_app/src/screens/CrashesScreen.d.ts.map +1 -0
  37. package/lib/typescript/appambit_test_app/src/utils/uuid.d.ts +2 -0
  38. package/lib/typescript/appambit_test_app/src/utils/uuid.d.ts.map +1 -0
  39. package/lib/typescript/package.json +1 -0
  40. package/lib/typescript/src/NativeAppambitAnalytics.d.ts +14 -0
  41. package/lib/typescript/src/NativeAppambitAnalytics.d.ts.map +1 -0
  42. package/lib/typescript/src/NativeAppambitCore.d.ts +7 -0
  43. package/lib/typescript/src/NativeAppambitCore.d.ts.map +1 -0
  44. package/lib/typescript/src/NativeAppambitCrashes.d.ts +23 -0
  45. package/lib/typescript/src/NativeAppambitCrashes.d.ts.map +1 -0
  46. package/lib/typescript/src/index.d.ts +24 -0
  47. package/lib/typescript/src/index.d.ts.map +1 -0
  48. package/package.json +164 -0
  49. package/src/NativeAppambitAnalytics.ts +14 -0
  50. package/src/NativeAppambitCore.ts +7 -0
  51. package/src/NativeAppambitCrashes.ts +23 -0
  52. package/src/index.tsx +138 -0
package/src/index.tsx ADDED
@@ -0,0 +1,138 @@
1
+ import Appambit from './NativeAppambitCore';
2
+ import AppambitAnalytics from './NativeAppambitAnalytics';
3
+ import AppambitCrashes from './NativeAppambitCrashes';
4
+
5
+ type LogErrorParams = {
6
+ exception?: any;
7
+ message?: string;
8
+ stack?: string;
9
+ classFqn?: string;
10
+ fileName?: string;
11
+ lineNumber?: number;
12
+ properties?: Record<string, string>;
13
+ };
14
+
15
+ // Start the Appambit SDK with the provided app key
16
+
17
+ export function start(appkey: string): void {
18
+ Appambit.start(appkey);
19
+ }
20
+
21
+ // Analytics methods
22
+
23
+ export function setUserId(userId: string): void {
24
+ AppambitAnalytics.setUserId(userId);
25
+ }
26
+
27
+ export function setUserEmail(userEmail: string): void {
28
+ AppambitAnalytics.setUserEmail(userEmail);
29
+ }
30
+
31
+ export function clearToken(): void {
32
+ AppambitAnalytics.clearToken();
33
+ }
34
+
35
+ export function startSession(): void {
36
+ AppambitAnalytics.startSession();
37
+ }
38
+
39
+ export function endSession(): void {
40
+ AppambitAnalytics.endSession();
41
+ }
42
+
43
+ export function enableManualSession(): void {
44
+ AppambitAnalytics.enableManualSession();
45
+ }
46
+
47
+ export function trackEvent(eventTitle: string, properties?: Record<string, string>): void {
48
+ AppambitAnalytics.trackEvent(eventTitle, properties);
49
+ }
50
+
51
+ export function generateTestEvent(): void {
52
+ AppambitAnalytics.generateTestEvent();
53
+ }
54
+
55
+ // Crashes methods
56
+
57
+ export function didCrashInLastSession(): Promise<boolean> {
58
+ return AppambitCrashes.didCrashInLastSession();
59
+ }
60
+
61
+ export function generateTestCrash(): void {
62
+ AppambitCrashes.generateTestCrash();
63
+ }
64
+
65
+ export function logErrorMessage(message: string, properties?: Record<string, string>): void {
66
+ AppambitCrashes.logErrorMessage(message, properties);
67
+ }
68
+
69
+ export async function logError({
70
+ message,
71
+ exception,
72
+ stack,
73
+ classFqn,
74
+ fileName,
75
+ lineNumber,
76
+ properties,
77
+ }: LogErrorParams): Promise<void> {
78
+ if (!AppambitCrashes) {
79
+ console.warn('AppambitCrashes not registered');
80
+ return;
81
+ }
82
+
83
+ const messageStr =
84
+ message && message.length > 0
85
+ ? message
86
+ : exception
87
+ ? exception.message || JSON.stringify(exception)
88
+ : "UnknownError";
89
+
90
+ const stackStr =
91
+ stack && stack.length > 0
92
+ ? stack
93
+ : exception?.stack
94
+ ? exception.stack.toString()
95
+ : new Error().stack?.toString();
96
+
97
+ const payload: Record<string, any> = {};
98
+
99
+ if (messageStr) payload.message = messageStr;
100
+ if (stackStr) payload.stack = stackStr;
101
+ if (properties && Object.keys(properties).length > 0)
102
+ payload.properties = properties;
103
+ if (classFqn) payload.classFqn = classFqn;
104
+ if (fileName) payload.fileName = fileName;
105
+
106
+ if (typeof lineNumber === 'number' && !isNaN(lineNumber) && isFinite(lineNumber)) {
107
+ payload.lineNumber = lineNumber;
108
+ }
109
+
110
+ if (Object.keys(payload).length === 0) return;
111
+
112
+ const userProvidedMessage = !!message && message.length > 0;
113
+
114
+ if (userProvidedMessage) {
115
+ AppambitCrashes.logErrorMessage(message, properties);
116
+ } else if (exception || (stackStr && stackStr.length > 0)) {
117
+ AppambitCrashes.logError(payload);
118
+ }
119
+ }
120
+
121
+ ErrorUtils.setGlobalHandler((error) => {
122
+ const hasMessage = typeof error?.message === "string" && error.message.trim().length > 0;
123
+
124
+ if (hasMessage) {
125
+ logError({
126
+ exception: error,
127
+ message: error.message,
128
+ stack: error.stack,
129
+ classFqn: error.constructor?.name,
130
+ });
131
+ } else {
132
+ logError({
133
+ exception: error,
134
+ stack: error.stack,
135
+ classFqn: error.constructor?.name,
136
+ });
137
+ }
138
+ });