Skip to content

Commit 2130e1b

Browse files
TheBuggedYRNHeshamMegid
authored andcommitted
[MOB-11974] Add Interfaces for Native Modules (#918)
Increase type-safety by adding type definitions for the Native Modules.
1 parent f2a5409 commit 2130e1b

28 files changed

+990
-479
lines changed

src/modules/CrashReporting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Platform } from 'react-native';
22
import type { ExtendedError } from 'react-native/Libraries/Core/Devtools/parseErrorStack';
33

44
import { NativeCrashReporting } from '../native';
5+
import type { CrashData } from '../native/CrashReportingNativeModule';
56
import InstabugUtils from '../utils/InstabugUtils';
67

78
/**
@@ -31,7 +32,7 @@ export const reportJSException = (error: any) => {
3132
export const reportError = (error: ExtendedError) => {
3233
const jsStackTrace = InstabugUtils.getStackTrace(error);
3334

34-
const jsonObject = {
35+
const jsonObject: CrashData = {
3536
message: error.name + ' - ' + error.message,
3637
e_message: error.message,
3738
e_name: error.name,

src/modules/FeatureRequests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ export const setEnabled = (isEnabled: boolean) => {
2323
*/
2424
export const setEmailFieldRequired = (
2525
isEmailFieldRequired: boolean,
26-
types: actionTypes | ActionType,
26+
type: actionTypes | ActionType,
2727
) => {
28-
NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, types);
28+
NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, [
29+
type,
30+
] as ActionType[]);
2931
};
3032

3133
/**

src/modules/Instabug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ export const onNavigationStateChange = (
564564
}
565565
_currentScreen = currentScreen;
566566
setTimeout(() => {
567-
if (_currentScreen === currentScreen) {
567+
if (currentScreen && _currentScreen === currentScreen) {
568568
NativeInstabug.reportScreenChange(currentScreen);
569569
_currentScreen = null;
570570
}

src/modules/Surveys.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Platform } from 'react-native';
22

33
import { NativeSurveys } from '../native';
4+
import type { Survey } from '../native/SurveysNativeModule';
45
import IBGEventEmitter from '../utils/IBGEventEmitter';
56
import InstabugConstants from '../utils/InstabugConstants';
67

7-
export interface Survey {
8-
title: string;
9-
}
8+
export type { Survey };
109

1110
/**
1211
* Sets whether surveys are enabled or not.

src/native.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/native/ApmNativeModule.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { NativeModule } from 'react-native';
2+
3+
import type { logLevel } from '../utils/ArgsRegistry';
4+
5+
export interface ApmNativeModule extends NativeModule {
6+
// Essential APIs //
7+
setEnabled(isEnabled: boolean): void;
8+
9+
// Network APIs //
10+
networkLog(data: string): void;
11+
12+
// App Launches APIs //
13+
setAppLaunchEnabled(isEnabled: boolean): void;
14+
endAppLaunch(): void;
15+
16+
// Execution Traces APIs //
17+
startExecutionTrace(name: string, timestamp: string, callback: (id: string | null) => void): void;
18+
setExecutionTraceAttribute(id: string, key: string, value: string): void;
19+
endExecutionTrace(id: string): void;
20+
21+
// UI Traces APIs //
22+
setAutoUITraceEnabled(isEnabled: boolean): void;
23+
startUITrace(name: string): void;
24+
endUITrace(): void;
25+
ibgSleep(): void;
26+
27+
// Deprecated APIs //
28+
/** @deprecated */
29+
setLogLevel(level: logLevel): void;
30+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { NativeModule } from 'react-native';
2+
3+
import type {
4+
dismissType,
5+
extendedBugReportMode,
6+
floatingButtonEdge,
7+
invocationEvent,
8+
option,
9+
position,
10+
reportType,
11+
} from '../utils/ArgsRegistry';
12+
import type {
13+
DismissType,
14+
ExtendedBugReportMode,
15+
FloatingButtonPosition,
16+
InvocationEvent,
17+
InvocationOption,
18+
RecordingButtonPosition,
19+
ReportType,
20+
} from '../utils/Enums';
21+
22+
export interface BugReportingNativeModule extends NativeModule {
23+
// Essential APIs //
24+
setEnabled(isEnabled: boolean): void;
25+
show(type: reportType | ReportType, options: option[] | InvocationOption[]): void;
26+
27+
// Customization APIs //
28+
setInvocationEvents(events: invocationEvent[] | InvocationEvent[]): void;
29+
setOptions(options: option[] | InvocationOption[]): void;
30+
setExtendedBugReportMode(mode: extendedBugReportMode | ExtendedBugReportMode): void;
31+
setReportTypes(types: reportType[] | ReportType[]): void;
32+
setDisclaimerText(text: string): void;
33+
setCommentMinimumCharacterCount(limit: number, reportTypes: reportType[] | ReportType[]): void;
34+
setFloatingButtonEdge(edge: floatingButtonEdge | FloatingButtonPosition, offset: number): void;
35+
setVideoRecordingFloatingButtonPosition(buttonPosition: position | RecordingButtonPosition): void;
36+
setEnabledAttachmentTypes(
37+
screenshot: boolean,
38+
extraScreenshot: boolean,
39+
galleryImage: boolean,
40+
screenRecording: boolean,
41+
): void;
42+
43+
// Screen Recording APIs //
44+
setAutoScreenRecordingEnabled(isEnabled: boolean): void;
45+
setAutoScreenRecordingDuration(maxDuration: number): void;
46+
setViewHierarchyEnabled(isEnabled: boolean): void;
47+
48+
// Shaking Threshold APIs //
49+
setShakingThresholdForiPhone(threshold: number): void;
50+
setShakingThresholdForiPad(threshold: number): void;
51+
setShakingThresholdForAndroid(threshold: number): void;
52+
53+
// Callbacks //
54+
setOnInvokeHandler(handler: () => void): void;
55+
setDidSelectPromptOptionHandler(handler: (promptOption: string) => void): void;
56+
setOnSDKDismissedHandler(
57+
handler: (dismissType: dismissType | DismissType, reportType: reportType | ReportType) => void,
58+
): void;
59+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { NativeModule, Platform } from 'react-native';
2+
import type { StackFrame } from 'react-native/Libraries/Core/Devtools/parseErrorStack';
3+
4+
export interface CrashData {
5+
message: string;
6+
e_message: string;
7+
e_name: string;
8+
os: typeof Platform['OS'];
9+
platform: 'react_native';
10+
exception: StackFrame[];
11+
}
12+
13+
export interface CrashReportingNativeModule extends NativeModule {
14+
setEnabled(isEnabled: boolean): void;
15+
sendJSCrash(data: CrashData | string): void;
16+
sendHandledJSCrash(data: CrashData | string): void;
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NativeModule } from 'react-native';
2+
3+
import type { actionTypes } from '../utils/ArgsRegistry';
4+
import type { ActionType } from '../utils/Enums';
5+
6+
export interface FeatureRequestsNativeModule extends NativeModule {
7+
setEnabled(isEnabled: boolean): void;
8+
show(): void;
9+
setEmailFieldRequiredForFeatureRequests(
10+
isEmailFieldRequired: boolean,
11+
types: actionTypes[] | ActionType[],
12+
): void;
13+
}

src/native/InstabugNativeModule.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import type { NativeModule, ProcessedColorValue } from 'react-native';
2+
3+
import type Report from '../models/Report';
4+
import type {
5+
colorTheme,
6+
invocationEvent,
7+
locale,
8+
reproStepsMode,
9+
sdkDebugLogsLevel,
10+
strings,
11+
welcomeMessageMode,
12+
} from '../utils/ArgsRegistry';
13+
import type {
14+
ColorTheme,
15+
InvocationEvent,
16+
Locale,
17+
LogLevel,
18+
ReproStepsMode,
19+
StringKey,
20+
WelcomeMessageMode,
21+
} from '../utils/Enums';
22+
import type { NetworkData } from '../utils/XhrNetworkInterceptor';
23+
import type { NativeConstants } from './NativeConstants';
24+
25+
export interface InstabugNativeModule extends NativeModule {
26+
getConstants(): NativeConstants;
27+
28+
// Essential APIs //
29+
setEnabled(isEnabled: boolean): void;
30+
init(
31+
token: string,
32+
invocationEvents: InvocationEvent[] | invocationEvent[],
33+
debugLogsLevel: LogLevel,
34+
): void;
35+
show(): void;
36+
37+
// Misc APIs //
38+
setIBGLogPrintsToConsole(printsToConsole: boolean): void;
39+
setSessionProfilerEnabled(isEnabled: boolean): void;
40+
41+
// Customization APIs //
42+
setLocale(sdkLocale: Locale | locale): void;
43+
setColorTheme(sdkTheme: ColorTheme | colorTheme): void;
44+
setPrimaryColor(color: ProcessedColorValue | null | undefined): void;
45+
setString(string: string, key: StringKey | strings): void;
46+
47+
// Network APIs //
48+
networkLog(network: NetworkData | string): void;
49+
setNetworkLoggingEnabled(isEnabled: boolean): void;
50+
51+
// Repro Steps APIs //
52+
setReproStepsMode(mode: ReproStepsMode | reproStepsMode): void;
53+
setTrackUserSteps(isEnabled: boolean): void;
54+
reportScreenChange(firstScreen: string): void;
55+
addPrivateView(nativeTag: number | null): void;
56+
removePrivateView(nativeTag: number | null): void;
57+
58+
// Logging APIs //
59+
logVerbose(message: string): void;
60+
logInfo(message: string): void;
61+
logDebug(message: string): void;
62+
logError(message: string): void;
63+
logWarn(message: string): void;
64+
clearLogs(): void;
65+
66+
// User APIs //
67+
identifyUser(email: string, name: string): void;
68+
logOut(): void;
69+
logUserEvent(name: string): void;
70+
setUserData(data: string): void;
71+
72+
// User Attributes APIs //
73+
setUserAttribute(key: string, value: string): void;
74+
getUserAttribute(key: string, callback: (attribute: string) => void): void;
75+
removeUserAttribute(key: string): void;
76+
getAllUserAttributes(callback: (attributes: Record<string, string>) => void): void;
77+
clearAllUserAttributes(): void;
78+
79+
// Welcome Message APIs //
80+
showWelcomeMessageWithMode(mode: WelcomeMessageMode | welcomeMessageMode): void;
81+
setWelcomeMessageMode(mode: WelcomeMessageMode | welcomeMessageMode): void;
82+
83+
// Tags APIs //
84+
appendTags(tags: string[]): void;
85+
resetTags(): void;
86+
getTags(callback: (tags: string[]) => void): void;
87+
88+
// Experiments APIs //
89+
addExperiments(experiments: string[]): void;
90+
removeExperiments(experiments: string[]): void;
91+
clearAllExperiments(): void;
92+
93+
// Files APIs //
94+
setFileAttachment(filePath: string, fileName?: string): void;
95+
96+
// Report APIs //
97+
setPreSendingHandler(handler?: (report: Report) => void): void;
98+
appendTagToReport(tag: string): void;
99+
appendConsoleLogToReport(consoleLog: string): void;
100+
setUserAttributeToReport(key: string, value: string): void;
101+
logDebugToReport(log: string): void;
102+
logVerboseToReport(log: string): void;
103+
logWarnToReport(log: string): void;
104+
logErrorToReport(log: string): void;
105+
logInfoToReport(log: string): void;
106+
addFileAttachmentWithURLToReport(url: string, filename?: string): void;
107+
addFileAttachmentWithDataToReport(data: string, filename?: string): void;
108+
109+
// Deprecated APIs //
110+
/** @deprecated */
111+
setSdkDebugLogsLevel(level: sdkDebugLogsLevel): void;
112+
/** @deprecated */
113+
setDebugEnabled(isEnabled: boolean): void;
114+
/** @deprecated */
115+
enable(): void;
116+
/** @deprecated */
117+
disable(): void;
118+
/** @deprecated */
119+
isRunningLive(callback: (isLive: boolean) => void): void;
120+
/** @deprecated */
121+
callPrivateApi(apiName: string, param: any[]): void;
122+
}

0 commit comments

Comments
 (0)