import type { NavigationContainerRefWithCurrent } from '@react-navigation/native'; import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; // TODO: DXM-1898: Limit user control of logs // The user should not have that much control over logs. This should be only for our use. export const LOG_TAGS = { LIFECYCLE: 'LIFECYCLE', GESTURE: 'GESTURE', SIGNAL: 'SIGNAL', PLAYBACK: 'PLAYBACK', NETWORK: 'NETWORK', NAVIGATION: 'NAVIGATION', } as const; /** * Defines the log category that you wish to receive in native Loggers. */ export type LogTag = (typeof LOG_TAGS)[keyof typeof LOG_TAGS]; /** * Configuration options for the DXA React Native SDK. * * @property {NavigationContainerRefWithCurrent} navigationRef - Reference to the React Navigation container * for automatic screen tracking. * @property {string[]} customViewTypesToMask - Adds additional/custom View Types that will be masked. * This property only supports iOS UIKit view types. */ export type DxaConfiguration = { navigationRef?: NavigationContainerRefWithCurrent; customViewTypesToMask?: string[]; }; /** * Configuration options for the DXA recording session that are passed to native code. * We use two separate configuration types because: * 1. DxaConfiguration is used by JS layer functions and can include React-specific properties * 2. NativeDxaConfiguration is used for communication with native modules (via TurboModules) * * React-specific properties like navigationRef are excluded because they cannot be * serialized for the TurboModule interface. * * TurboModules cannot use complex type utilities like Omit<>, so we define this type explicitly * rather than deriving it from DxaConfiguration. * https://github.com/facebook/react-native/issues/38769 * * @property {string[]} customViewTypesToMask - Adds additional/custom View Types that will be masked. * This property only supports iOS UIKit view types. */ export type NativeDxaConfiguration = { customViewTypesToMask?: string[]; }; /** * Result of an initialization operation. * @property {string} result - The result status. */ export type InitializationResult = { result: string; }; /** * Result of attempting to start a session. * @property {string} result - The result status. * @property {string} [message] - Message describing the session start result. * @property {string} [sessionId] - The identifier for the started session. * @property {string} [sessionStartTimeMillis] - Unix timestamp of session start in milliseconds. * @property {string} [error] - Error message if the start was unsuccessful. */ export type SessionStartResult = { result: string; message?: string; sessionId?: string; sessionStartTimeMillis?: string; error?: string; }; /** * Result of attempting to close a session. * @property {string} result - The result status. * @property {string} [error] - Error message if the stop was unsuccessful. */ export type SessionCloseResult = { result: string; error?: string; }; /** * Result of attempting to pause a session. * @property {string} result - The result status. */ export type SessionPauseResult = { result: string; }; /** * Result of attempting to resume a session. * @property {string} result - The result status. */ export type SessionResumeResult = { result: string; }; /** * Result of attempting to LogError. * * @property {string} result - The result status. */ export type LogErrorResult = { result: string; }; export type IScreenChangePayload = { screenHierarchy: { screenName: string; screenType: string; }[]; changeType: 'appear' | 'disappear'; detectionType: 'auto' | 'manual'; }; export interface Spec extends TurboModule { initializeProject( brandId: string, projectId: string, sdkVersion: string, reactNativeVersion: string ): InitializationResult; setLoggingTags(tags: LogTag[]): LogTag[]; startRecording( dxaConfiguration?: NativeDxaConfiguration ): Promise; stopRecording(): Promise; pauseRecording(): Promise; resumeRecording(): Promise; logError(message?: string): LogErrorResult; reportScreenChangeOnNative(screenChangePayload: IScreenChangePayload): void; } export default TurboModuleRegistry.getEnforcing('DxaReactNative');