Skip to content

[MOB-11974] Add Interfaces for Native Modules #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/modules/CrashReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Platform } from 'react-native';
import type { ExtendedError } from 'react-native/Libraries/Core/Devtools/parseErrorStack';

import { NativeCrashReporting } from '../native';
import type { CrashData } from '../native/CrashReportingNativeModule';
import InstabugUtils from '../utils/InstabugUtils';

/**
Expand Down Expand Up @@ -31,7 +32,7 @@ export const reportJSException = (error: any) => {
export const reportError = (error: ExtendedError) => {
const jsStackTrace = InstabugUtils.getStackTrace(error);

const jsonObject = {
const jsonObject: CrashData = {
message: error.name + ' - ' + error.message,
e_message: error.message,
e_name: error.name,
Expand Down
6 changes: 4 additions & 2 deletions src/modules/FeatureRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export const setEnabled = (isEnabled: boolean) => {
*/
export const setEmailFieldRequired = (
isEmailFieldRequired: boolean,
types: actionTypes | ActionType,
type: actionTypes | ActionType,
) => {
NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, types);
NativeFeatureRequests.setEmailFieldRequiredForFeatureRequests(isEmailFieldRequired, [
type,
] as ActionType[]);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Instabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export const onNavigationStateChange = (
}
_currentScreen = currentScreen;
setTimeout(() => {
if (_currentScreen === currentScreen) {
if (currentScreen && _currentScreen === currentScreen) {
NativeInstabug.reportScreenChange(currentScreen);
_currentScreen = null;
}
Expand Down
5 changes: 2 additions & 3 deletions src/modules/Surveys.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Platform } from 'react-native';

import { NativeSurveys } from '../native';
import type { Survey } from '../native/SurveysNativeModule';
import IBGEventEmitter from '../utils/IBGEventEmitter';
import InstabugConstants from '../utils/InstabugConstants';

export interface Survey {
title: string;
}
export type { Survey };

/**
* Sets whether surveys are enabled or not.
Expand Down
28 changes: 0 additions & 28 deletions src/native.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/native/ApmNativeModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { NativeModule } from 'react-native';

import type { logLevel } from '../utils/ArgsRegistry';

export interface ApmNativeModule extends NativeModule {
// Essential APIs //
setEnabled(isEnabled: boolean): void;

// Network APIs //
networkLog(data: string): void;

// App Launches APIs //
setAppLaunchEnabled(isEnabled: boolean): void;
endAppLaunch(): void;

// Execution Traces APIs //
startExecutionTrace(name: string, timestamp: string, callback: (id: string | null) => void): void;
setExecutionTraceAttribute(id: string, key: string, value: string): void;
endExecutionTrace(id: string): void;

// UI Traces APIs //
setAutoUITraceEnabled(isEnabled: boolean): void;
startUITrace(name: string): void;
endUITrace(): void;
ibgSleep(): void;

// Deprecated APIs //
/** @deprecated */
setLogLevel(level: logLevel): void;
}
59 changes: 59 additions & 0 deletions src/native/BugReportingNativeModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { NativeModule } from 'react-native';

import type {
dismissType,
extendedBugReportMode,
floatingButtonEdge,
invocationEvent,
option,
position,
reportType,
} from '../utils/ArgsRegistry';
import type {
DismissType,
ExtendedBugReportMode,
FloatingButtonPosition,
InvocationEvent,
InvocationOption,
RecordingButtonPosition,
ReportType,
} from '../utils/Enums';

export interface BugReportingNativeModule extends NativeModule {
// Essential APIs //
setEnabled(isEnabled: boolean): void;
show(type: reportType | ReportType, options: option[] | InvocationOption[]): void;

// Customization APIs //
setInvocationEvents(events: invocationEvent[] | InvocationEvent[]): void;
setOptions(options: option[] | InvocationOption[]): void;
setExtendedBugReportMode(mode: extendedBugReportMode | ExtendedBugReportMode): void;
setReportTypes(types: reportType[] | ReportType[]): void;
setDisclaimerText(text: string): void;
setCommentMinimumCharacterCount(limit: number, reportTypes: reportType[] | ReportType[]): void;
setFloatingButtonEdge(edge: floatingButtonEdge | FloatingButtonPosition, offset: number): void;
setVideoRecordingFloatingButtonPosition(buttonPosition: position | RecordingButtonPosition): void;
setEnabledAttachmentTypes(
screenshot: boolean,
extraScreenshot: boolean,
galleryImage: boolean,
screenRecording: boolean,
): void;

// Screen Recording APIs //
setAutoScreenRecordingEnabled(isEnabled: boolean): void;
setAutoScreenRecordingDuration(maxDuration: number): void;
setViewHierarchyEnabled(isEnabled: boolean): void;

// Shaking Threshold APIs //
setShakingThresholdForiPhone(threshold: number): void;
setShakingThresholdForiPad(threshold: number): void;
setShakingThresholdForAndroid(threshold: number): void;

// Callbacks //
setOnInvokeHandler(handler: () => void): void;
setDidSelectPromptOptionHandler(handler: (promptOption: string) => void): void;
setOnSDKDismissedHandler(
handler: (dismissType: dismissType | DismissType, reportType: reportType | ReportType) => void,
): void;
}
17 changes: 17 additions & 0 deletions src/native/CrashReportingNativeModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { NativeModule, Platform } from 'react-native';
import type { StackFrame } from 'react-native/Libraries/Core/Devtools/parseErrorStack';

export interface CrashData {
message: string;
e_message: string;
e_name: string;
os: typeof Platform['OS'];
platform: 'react_native';
exception: StackFrame[];
}

export interface CrashReportingNativeModule extends NativeModule {
setEnabled(isEnabled: boolean): void;
sendJSCrash(data: CrashData | string): void;
sendHandledJSCrash(data: CrashData | string): void;
}
13 changes: 13 additions & 0 deletions src/native/FeatureRequestsNativeModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { NativeModule } from 'react-native';

import type { actionTypes } from '../utils/ArgsRegistry';
import type { ActionType } from '../utils/Enums';

export interface FeatureRequestsNativeModule extends NativeModule {
setEnabled(isEnabled: boolean): void;
show(): void;
setEmailFieldRequiredForFeatureRequests(
isEmailFieldRequired: boolean,
types: actionTypes[] | ActionType[],
): void;
}
122 changes: 122 additions & 0 deletions src/native/InstabugNativeModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import type { NativeModule, ProcessedColorValue } from 'react-native';

import type Report from '../models/Report';
import type {
colorTheme,
invocationEvent,
locale,
reproStepsMode,
sdkDebugLogsLevel,
strings,
welcomeMessageMode,
} from '../utils/ArgsRegistry';
import type {
ColorTheme,
InvocationEvent,
Locale,
LogLevel,
ReproStepsMode,
StringKey,
WelcomeMessageMode,
} from '../utils/Enums';
import type { NetworkData } from '../utils/XhrNetworkInterceptor';
import type { NativeConstants } from './NativeConstants';

export interface InstabugNativeModule extends NativeModule {
getConstants(): NativeConstants;

// Essential APIs //
setEnabled(isEnabled: boolean): void;
init(
token: string,
invocationEvents: InvocationEvent[] | invocationEvent[],
debugLogsLevel: LogLevel,
): void;
show(): void;

// Misc APIs //
setIBGLogPrintsToConsole(printsToConsole: boolean): void;
setSessionProfilerEnabled(isEnabled: boolean): void;

// Customization APIs //
setLocale(sdkLocale: Locale | locale): void;
setColorTheme(sdkTheme: ColorTheme | colorTheme): void;
setPrimaryColor(color: ProcessedColorValue | null | undefined): void;
setString(string: string, key: StringKey | strings): void;

// Network APIs //
networkLog(network: NetworkData | string): void;
setNetworkLoggingEnabled(isEnabled: boolean): void;

// Repro Steps APIs //
setReproStepsMode(mode: ReproStepsMode | reproStepsMode): void;
setTrackUserSteps(isEnabled: boolean): void;
reportScreenChange(firstScreen: string): void;
addPrivateView(nativeTag: number | null): void;
removePrivateView(nativeTag: number | null): void;

// Logging APIs //
logVerbose(message: string): void;
logInfo(message: string): void;
logDebug(message: string): void;
logError(message: string): void;
logWarn(message: string): void;
clearLogs(): void;

// User APIs //
identifyUser(email: string, name: string): void;
logOut(): void;
logUserEvent(name: string): void;
setUserData(data: string): void;

// User Attributes APIs //
setUserAttribute(key: string, value: string): void;
getUserAttribute(key: string, callback: (attribute: string) => void): void;
removeUserAttribute(key: string): void;
getAllUserAttributes(callback: (attributes: Record<string, string>) => void): void;
clearAllUserAttributes(): void;

// Welcome Message APIs //
showWelcomeMessageWithMode(mode: WelcomeMessageMode | welcomeMessageMode): void;
setWelcomeMessageMode(mode: WelcomeMessageMode | welcomeMessageMode): void;

// Tags APIs //
appendTags(tags: string[]): void;
resetTags(): void;
getTags(callback: (tags: string[]) => void): void;

// Experiments APIs //
addExperiments(experiments: string[]): void;
removeExperiments(experiments: string[]): void;
clearAllExperiments(): void;

// Files APIs //
setFileAttachment(filePath: string, fileName?: string): void;

// Report APIs //
setPreSendingHandler(handler?: (report: Report) => void): void;
appendTagToReport(tag: string): void;
appendConsoleLogToReport(consoleLog: string): void;
setUserAttributeToReport(key: string, value: string): void;
logDebugToReport(log: string): void;
logVerboseToReport(log: string): void;
logWarnToReport(log: string): void;
logErrorToReport(log: string): void;
logInfoToReport(log: string): void;
addFileAttachmentWithURLToReport(url: string, filename?: string): void;
addFileAttachmentWithDataToReport(data: string, filename?: string): void;

// Deprecated APIs //
/** @deprecated */
setSdkDebugLogsLevel(level: sdkDebugLogsLevel): void;
/** @deprecated */
setDebugEnabled(isEnabled: boolean): void;
/** @deprecated */
enable(): void;
/** @deprecated */
disable(): void;
/** @deprecated */
isRunningLive(callback: (isLive: boolean) => void): void;
/** @deprecated */
callPrivateApi(apiName: string, param: any[]): void;
}
Loading