@amplitude/session-replay-react-native 0.1.0-beta.0 → 0.1.0-beta.1

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 (26) hide show
  1. package/README.md +13 -0
  2. package/android/build.gradle +22 -0
  3. package/android/src/main/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeModule.kt +16 -11
  4. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +40 -0
  5. package/android/src/newarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +7 -0
  6. package/android/src/{main → oldarch}/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativePackage.kt +2 -1
  7. package/android/src/oldarch/java/com/amplitude/sessionreplayreactnative/SessionReplayReactNativeSpec.kt +20 -0
  8. package/ios/AMPNativeSessionReplay.mm +20 -0
  9. package/lib/commonjs/native-module.js +10 -1
  10. package/lib/commonjs/native-module.js.map +1 -1
  11. package/lib/commonjs/specs/NativeAmpSessionReplay.js +22 -0
  12. package/lib/commonjs/specs/NativeAmpSessionReplay.js.map +1 -0
  13. package/lib/commonjs/version.js +1 -1
  14. package/lib/module/native-module.js +10 -2
  15. package/lib/module/native-module.js.map +1 -1
  16. package/lib/module/specs/NativeAmpSessionReplay.js +18 -0
  17. package/lib/module/specs/NativeAmpSessionReplay.js.map +1 -0
  18. package/lib/module/version.js +1 -1
  19. package/lib/typescript/native-module.d.ts.map +1 -1
  20. package/lib/typescript/specs/NativeAmpSessionReplay.d.ts +15 -0
  21. package/lib/typescript/specs/NativeAmpSessionReplay.d.ts.map +1 -0
  22. package/lib/typescript/version.d.ts +1 -1
  23. package/package.json +10 -2
  24. package/src/native-module.ts +16 -10
  25. package/src/specs/NativeAmpSessionReplay.ts +29 -0
  26. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -8,6 +8,19 @@ Amplitude Session Replay for React Native
8
8
  npm install @amplitude/session-replay-react-native
9
9
  ```
10
10
 
11
+ ## React Native New Architecture
12
+
13
+ This SDK supports both the New Architecture (Bridgeless / TurboModules) and the
14
+ legacy architecture. On the New Architecture the native module is exposed as a
15
+ TurboModule; on the legacy architecture it continues to work as a standard bridge
16
+ module. No configuration is required — the correct implementation is selected
17
+ automatically based on how your app is built.
18
+
19
+ `peerDependencies` are intentionally left unconstrained (`react-native: "*"`) so
20
+ the SDK keeps working on older React Native versions on the legacy architecture.
21
+ The TurboModule code path is compiled only when the New Architecture is enabled,
22
+ which itself requires React Native 0.74 or newer.
23
+
11
24
  ## Usage
12
25
 
13
26
  ### Session Replay React Native Standalone SDK
@@ -42,6 +42,18 @@ android {
42
42
  }
43
43
  }
44
44
 
45
+ // New Arch compiles src/newarch (codegen spec + BaseReactPackage); Old Arch
46
+ // compiles src/oldarch (hand-written spec + plain ReactPackage).
47
+ sourceSets {
48
+ main {
49
+ if (isNewArchitectureEnabled()) {
50
+ java.srcDirs += ['src/newarch/java']
51
+ } else {
52
+ java.srcDirs += ['src/oldarch/java']
53
+ }
54
+ }
55
+ }
56
+
45
57
  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
46
58
 
47
59
  defaultConfig {
@@ -83,3 +95,13 @@ dependencies {
83
95
  implementation "com.facebook.react:react-native:+"
84
96
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
85
97
  }
98
+
99
+ // Codegen for the TurboModule spec (New Architecture only). Generates
100
+ // NativeAmpSessionReplaySpec from src/specs/NativeAmpSessionReplay.ts.
101
+ if (isNewArchitectureEnabled()) {
102
+ react {
103
+ jsRootDir = file("../src/specs/")
104
+ libraryName = "AmpSessionReplaySpec"
105
+ codegenJavaPackageName = "com.amplitude.sessionreplayreactnative"
106
+ }
107
+ }
@@ -7,23 +7,24 @@ import com.amplitude.common.Logger
7
7
  import com.amplitude.common.android.LogcatLogger
8
8
  import com.amplitude.core.ServerZone
9
9
  import com.facebook.react.bridge.ReactApplicationContext
10
- import com.facebook.react.bridge.ReactContextBaseJavaModule
11
10
  import com.facebook.react.bridge.ReactMethod
12
11
  import com.facebook.react.bridge.Promise
13
12
  import com.facebook.react.bridge.WritableMap
14
13
  import com.facebook.react.bridge.WritableNativeMap
15
14
  import com.facebook.react.bridge.ReadableMap
16
15
 
16
+ // `@ReactMethod` is required on the legacy architecture and ignored on the new
17
+ // one, so it stays on the overrides below.
17
18
  class SessionReplayReactNativeModule(private val reactContext: ReactApplicationContext) :
18
- ReactContextBaseJavaModule(reactContext) {
19
+ SessionReplayReactNativeSpec(reactContext) {
19
20
  private lateinit var sessionReplay: SessionReplay
20
21
 
21
22
  override fun getName(): String {
22
- return "AMPNativeSessionReplay"
23
+ return NAME
23
24
  }
24
25
 
25
26
  @ReactMethod
26
- fun setup(config: ReadableMap, promise: Promise) {
27
+ override fun setup(config: ReadableMap, promise: Promise) {
27
28
  try {
28
29
  val apiKey = config.getString("apiKey") ?: throw IllegalArgumentException("apiKey is required")
29
30
  val deviceId = config.getString("deviceId")
@@ -88,7 +89,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
88
89
  }
89
90
 
90
91
  @ReactMethod
91
- fun setSessionId(sessionId: Double, promise: Promise) {
92
+ override fun setSessionId(sessionId: Double, promise: Promise) {
92
93
  try {
93
94
  sessionReplay.setSessionId(sessionId.toLong())
94
95
  promise.resolve(null)
@@ -98,7 +99,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
98
99
  }
99
100
 
100
101
  @ReactMethod
101
- fun setDeviceId(deviceId: String?, promise: Promise) {
102
+ override fun setDeviceId(deviceId: String?, promise: Promise) {
102
103
  try {
103
104
  sessionReplay.setDeviceId(deviceId ?: "")
104
105
  promise.resolve(null)
@@ -108,7 +109,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
108
109
  }
109
110
 
110
111
  @ReactMethod
111
- fun getSessionId(promise: Promise) {
112
+ override fun getSessionId(promise: Promise) {
112
113
  try {
113
114
  promise.resolve(sessionReplay.getSessionId().toDouble())
114
115
  } catch (e: Exception) {
@@ -117,7 +118,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
117
118
  }
118
119
 
119
120
  @ReactMethod
120
- fun getSessionReplayProperties(promise: Promise) {
121
+ override fun getSessionReplayProperties(promise: Promise) {
121
122
  try {
122
123
  val properties: Map<String, Any> = sessionReplay.getSessionReplayProperties()
123
124
  val map: WritableMap = WritableNativeMap()
@@ -141,7 +142,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
141
142
  }
142
143
 
143
144
  @ReactMethod
144
- fun start(promise: Promise) {
145
+ override fun start(promise: Promise) {
145
146
  try {
146
147
  sessionReplay.start()
147
148
  promise.resolve(null)
@@ -151,7 +152,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
151
152
  }
152
153
 
153
154
  @ReactMethod
154
- fun stop(promise: Promise) {
155
+ override fun stop(promise: Promise) {
155
156
  try {
156
157
  sessionReplay.stop()
157
158
  promise.resolve(null)
@@ -161,7 +162,7 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
161
162
  }
162
163
 
163
164
  @ReactMethod
164
- fun flush(promise: Promise) {
165
+ override fun flush(promise: Promise) {
165
166
  try {
166
167
  sessionReplay.flush()
167
168
  promise.resolve(null)
@@ -180,4 +181,8 @@ class SessionReplayReactNativeModule(private val reactContext: ReactApplicationC
180
181
  sessionReplay.shutdown()
181
182
  }
182
183
  }
184
+
185
+ companion object {
186
+ const val NAME = "AMPNativeSessionReplay"
187
+ }
183
188
  }
@@ -0,0 +1,40 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import com.facebook.react.uimanager.ViewManager
9
+
10
+ // BaseReactPackage (RN >= 0.74) registers the module as a TurboModule. It lives in
11
+ // the newarch source set so it is compiled only when the New Architecture is
12
+ // enabled; legacy-arch apps on older RN never reference it.
13
+ class SessionReplayReactNativePackage : BaseReactPackage() {
14
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
15
+ return if (name == SessionReplayReactNativeModule.NAME) {
16
+ SessionReplayReactNativeModule(reactContext)
17
+ } else {
18
+ null
19
+ }
20
+ }
21
+
22
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
23
+ return ReactModuleInfoProvider {
24
+ mapOf(
25
+ SessionReplayReactNativeModule.NAME to ReactModuleInfo(
26
+ SessionReplayReactNativeModule.NAME, // name
27
+ SessionReplayReactNativeModule.NAME, // className
28
+ false, // canOverrideExistingModule
29
+ false, // needsEagerInit
30
+ false, // isCxxModule
31
+ true, // isTurboModule
32
+ ),
33
+ )
34
+ }
35
+ }
36
+
37
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
38
+ return listOf(SessionReplayReactNativeViewManager())
39
+ }
40
+ }
@@ -0,0 +1,7 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ // Codegen-generated base (from src/specs/NativeAmpSessionReplay.ts); makes the module a TurboModule.
6
+ abstract class SessionReplayReactNativeSpec(reactContext: ReactApplicationContext) :
7
+ NativeAmpSessionReplaySpec(reactContext)
@@ -5,7 +5,8 @@ import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
7
 
8
-
8
+ // Plain ReactPackage using only APIs present in every supported RN version, so
9
+ // older legacy-arch apps keep building unchanged (no peerDependencies floor).
9
10
  class SessionReplayReactNativePackage : ReactPackage {
10
11
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
12
  return listOf(SessionReplayReactNativeModule(reactContext))
@@ -0,0 +1,20 @@
1
+ package com.amplitude.sessionreplayreactnative
2
+
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReadableMap
7
+
8
+ // Legacy-arch counterpart of the codegen spec: same method signatures so the
9
+ // module's `override`s compile against both bases.
10
+ abstract class SessionReplayReactNativeSpec(reactContext: ReactApplicationContext) :
11
+ ReactContextBaseJavaModule(reactContext) {
12
+ abstract fun setup(config: ReadableMap, promise: Promise)
13
+ abstract fun setSessionId(sessionId: Double, promise: Promise)
14
+ abstract fun setDeviceId(deviceId: String?, promise: Promise)
15
+ abstract fun getSessionId(promise: Promise)
16
+ abstract fun getSessionReplayProperties(promise: Promise)
17
+ abstract fun start(promise: Promise)
18
+ abstract fun stop(promise: Promise)
19
+ abstract fun flush(promise: Promise)
20
+ }
@@ -19,3 +19,23 @@ RCT_EXTERN_METHOD(start:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseReject
19
19
  RCT_EXTERN_METHOD(stop:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
20
20
 
21
21
  @end
22
+
23
+ #ifdef RCT_NEW_ARCH_ENABLED
24
+ // Bind the Swift module to the codegen TurboModule interface. A named category is
25
+ // required because a Swift class cannot gain protocol conformance via an anonymous
26
+ // class extension.
27
+ #import <AmpSessionReplaySpec/AmpSessionReplaySpec.h>
28
+
29
+ @interface AMPNativeSessionReplay (TurboModule) <RCTTurboModule>
30
+ @end
31
+
32
+ @implementation AMPNativeSessionReplay (TurboModule)
33
+
34
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
35
+ (const facebook::react::ObjCTurboModule::InitParams &)params
36
+ {
37
+ return std::make_shared<facebook::react::NativeAmpSessionReplaySpecJSI>(params);
38
+ }
39
+
40
+ @end
41
+ #endif
@@ -5,11 +5,20 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.NativeSessionReplay = void 0;
7
7
  var _reactNative = require("react-native");
8
+ var _NativeAmpSessionReplay = _interopRequireDefault(require("./specs/NativeAmpSessionReplay"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
10
  const LINKING_ERROR = `The package '@amplitude/session-replay-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
9
11
  ios: "- You have run 'pod install'\n",
10
12
  default: ''
11
13
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
12
- const NativeSessionReplay = exports.NativeSessionReplay = _reactNative.NativeModules.AMPNativeSessionReplay ? _reactNative.NativeModules.AMPNativeSessionReplay : new Proxy({}, {
14
+
15
+ // JS callers use the rich, hand-written types below for full type safety; the
16
+ // codegen `Spec` is intentionally loose (`UnsafeObject`) at the native boundary.
17
+ // The spec resolves the native module via `TurboModuleRegistry.get` (both
18
+ // architectures). When the module isn't linked it resolves to null, so we fall
19
+ // back to a proxy that throws a descriptive linking error on first use rather
20
+ // than crashing app startup at import time.
21
+ const NativeSessionReplay = exports.NativeSessionReplay = _NativeAmpSessionReplay.default ?? new Proxy({}, {
13
22
  get() {
14
23
  throw new Error(LINKING_ERROR);
15
24
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","NativeSessionReplay","exports","NativeModules","AMPNativeSessionReplay","Proxy","get","Error"],"sourceRoot":"../../src","sources":["native-module.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,iGAAiG,GACjGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAE1B,MAAMC,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAGE,0BAAa,CAACC,sBAAsB,GAClED,0BAAa,CAACC,sBAAsB,GACpC,IAAIC,KAAK,CACR,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACX,aAAa,CAAC;EAChC;AACF,CACF,CAA6B;;AAEjC;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_NativeAmpSessionReplay","_interopRequireDefault","e","__esModule","default","LINKING_ERROR","Platform","select","ios","NativeSessionReplay","exports","SessionReplaySpec","Proxy","get","Error"],"sourceRoot":"../../src","sources":["native-module.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA+D,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE/D,MAAMG,aAAa,GACjB,iGAAiG,GACjGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEJ,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAIE,+BAAiB,IACnD,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAwC;;AAE1C;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ // The codegen types live in a Flow-typed file that eslint-plugin-import cannot parse.
9
+ // eslint-disable-next-line import/namespace
10
+ // Codegen TurboModule spec for the imperative Session Replay module.
11
+ //
12
+ // The config crosses the bridge as an untyped object: the native side already
13
+ // reads a ReadableMap / NSDictionary, and app-boundary type safety lives in the
14
+ // public `SessionReplayConfig`. See native-module.ts for the typed facade that
15
+ // JS callers actually use.
16
+ // Use non-enforcing `get` (returns null when the native module isn't linked)
17
+ // so importing the package never crashes app startup. The typed facade in
18
+ // native-module.ts throws a friendly linking error lazily on first use instead.
19
+ // Works on both architectures: JSI on the New Architecture, legacy NativeModules
20
+ // fallback on the old one.
21
+ var _default = exports.default = _reactNative.TurboModuleRegistry.get('AMPNativeSessionReplay');
22
+ //# sourceMappingURL=NativeAmpSessionReplay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeAmpSessionReplay.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AAYA;AACA;AACA;AACA;AACA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACeC,gCAAmB,CAACC,GAAG,CAAO,wBAAwB,CAAC","ignoreList":[]}
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- const VERSION = exports.VERSION = '0.1.0-beta.0';
7
+ const VERSION = exports.VERSION = '0.1.0-beta.1';
8
8
  //# sourceMappingURL=version.js.map
@@ -1,9 +1,17 @@
1
- import { NativeModules, Platform } from 'react-native';
1
+ import { Platform } from 'react-native';
2
+ import SessionReplaySpec from './specs/NativeAmpSessionReplay';
2
3
  const LINKING_ERROR = `The package '@amplitude/session-replay-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
3
4
  ios: "- You have run 'pod install'\n",
4
5
  default: ''
5
6
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
6
- export const NativeSessionReplay = NativeModules.AMPNativeSessionReplay ? NativeModules.AMPNativeSessionReplay : new Proxy({}, {
7
+
8
+ // JS callers use the rich, hand-written types below for full type safety; the
9
+ // codegen `Spec` is intentionally loose (`UnsafeObject`) at the native boundary.
10
+ // The spec resolves the native module via `TurboModuleRegistry.get` (both
11
+ // architectures). When the module isn't linked it resolves to null, so we fall
12
+ // back to a proxy that throws a descriptive linking error on first use rather
13
+ // than crashing app startup at import time.
14
+ export const NativeSessionReplay = SessionReplaySpec ?? new Proxy({}, {
7
15
  get() {
8
16
  throw new Error(LINKING_ERROR);
9
17
  }
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","NativeSessionReplay","AMPNativeSessionReplay","Proxy","get","Error"],"sourceRoot":"../../src","sources":["native-module.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,iGAAiG,GACjGD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,OAAO,MAAMC,mBAAmB,GAAGN,aAAa,CAACO,sBAAsB,GAClEP,aAAa,CAACO,sBAAsB,GACpC,IAAIC,KAAK,CACR,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACR,aAAa,CAAC;EAChC;AACF,CACF,CAA6B;;AAEjC;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["Platform","SessionReplaySpec","LINKING_ERROR","select","ios","default","NativeSessionReplay","Proxy","get","Error"],"sourceRoot":"../../src","sources":["native-module.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,iBAAiB,MAAM,gCAAgC;AAE9D,MAAMC,aAAa,GACjB,iGAAiG,GACjGF,QAAQ,CAACG,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,GAAIL,iBAAiB,IACnD,IAAIM,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAwC;;AAE1C;AACA;AACA;AACA;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ // The codegen types live in a Flow-typed file that eslint-plugin-import cannot parse.
3
+ // eslint-disable-next-line import/namespace
4
+
5
+ // Codegen TurboModule spec for the imperative Session Replay module.
6
+ //
7
+ // The config crosses the bridge as an untyped object: the native side already
8
+ // reads a ReadableMap / NSDictionary, and app-boundary type safety lives in the
9
+ // public `SessionReplayConfig`. See native-module.ts for the typed facade that
10
+ // JS callers actually use.
11
+
12
+ // Use non-enforcing `get` (returns null when the native module isn't linked)
13
+ // so importing the package never crashes app startup. The typed facade in
14
+ // native-module.ts throws a friendly linking error lazily on first use instead.
15
+ // Works on both architectures: JSI on the New Architecture, legacy NativeModules
16
+ // fallback on the old one.
17
+ export default TurboModuleRegistry.get('AMPNativeSessionReplay');
18
+ //# sourceMappingURL=NativeAmpSessionReplay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeAmpSessionReplay.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAClD;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,wBAAwB,CAAC","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.0-beta.0';
1
+ export const VERSION = '0.1.0-beta.1';
2
2
  //# sourceMappingURL=version.js.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C;IAEhC;;;;;OAKG;IACH,0BAA0B,IAAI,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAErE;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
@@ -0,0 +1,15 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface Spec extends TurboModule {
4
+ setup(config: UnsafeObject): Promise<void>;
5
+ setSessionId(sessionId: number): Promise<void>;
6
+ setDeviceId(deviceId: string | null): Promise<void>;
7
+ getSessionId(): Promise<number>;
8
+ getSessionReplayProperties(): Promise<UnsafeObject>;
9
+ start(): Promise<void>;
10
+ stop(): Promise<void>;
11
+ flush(): Promise<void>;
12
+ }
13
+ declare const _default: Spec | null;
14
+ export default _default;
15
+ //# sourceMappingURL=NativeAmpSessionReplay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeAmpSessionReplay.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeAmpSessionReplay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAQ9E,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,0BAA0B,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;;AAOD,wBAAuE"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.0-beta.0";
1
+ export declare const VERSION = "0.1.0-beta.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/session-replay-react-native",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "Amplitude Session Replay for React Native",
5
5
  "keywords": [
6
6
  "analytics",
@@ -61,6 +61,14 @@
61
61
  "react": "*",
62
62
  "react-native": "*"
63
63
  },
64
+ "codegenConfig": {
65
+ "name": "AmpSessionReplaySpec",
66
+ "type": "modules",
67
+ "jsSrcsDir": "src/specs",
68
+ "android": {
69
+ "javaPackageName": "com.amplitude.sessionreplayreactnative"
70
+ }
71
+ },
64
72
  "react-native-builder-bob": {
65
73
  "source": "src",
66
74
  "output": "lib",
@@ -85,7 +93,7 @@
85
93
  "lint:eslint": "eslint '{src,test}/**/*.ts'",
86
94
  "lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
87
95
  "test": "jest",
88
- "typecheck": "tsc -p ./tsconfig.json",
96
+ "typecheck": "tsc -p ./tsconfig.json --noEmit",
89
97
  "version": "pnpm version-file && pnpm build",
90
98
  "version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
91
99
  "typescript": "tsc --noEmit",
@@ -1,4 +1,5 @@
1
- import { NativeModules, Platform } from 'react-native';
1
+ import { Platform } from 'react-native';
2
+ import SessionReplaySpec from './specs/NativeAmpSessionReplay';
2
3
 
3
4
  const LINKING_ERROR =
4
5
  `The package '@amplitude/session-replay-react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -6,16 +7,21 @@ const LINKING_ERROR =
6
7
  '- You rebuilt the app after installing the package\n' +
7
8
  '- You are not using Expo Go\n';
8
9
 
9
- export const NativeSessionReplay = NativeModules.AMPNativeSessionReplay
10
- ? (NativeModules.AMPNativeSessionReplay as NativeSessionReplaySpec)
11
- : (new Proxy(
12
- {},
13
- {
14
- get() {
15
- throw new Error(LINKING_ERROR);
16
- },
10
+ // JS callers use the rich, hand-written types below for full type safety; the
11
+ // codegen `Spec` is intentionally loose (`UnsafeObject`) at the native boundary.
12
+ // The spec resolves the native module via `TurboModuleRegistry.get` (both
13
+ // architectures). When the module isn't linked it resolves to null, so we fall
14
+ // back to a proxy that throws a descriptive linking error on first use rather
15
+ // than crashing app startup at import time.
16
+ export const NativeSessionReplay = (SessionReplaySpec ??
17
+ new Proxy(
18
+ {},
19
+ {
20
+ get() {
21
+ throw new Error(LINKING_ERROR);
17
22
  },
18
- ) as NativeSessionReplaySpec);
23
+ },
24
+ )) as unknown as NativeSessionReplaySpec;
19
25
 
20
26
  /**
21
27
  * Configuration interface for setting up the native iOS and Android session replay modules.
@@ -0,0 +1,29 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+ // The codegen types live in a Flow-typed file that eslint-plugin-import cannot parse.
4
+ // eslint-disable-next-line import/namespace
5
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
6
+
7
+ // Codegen TurboModule spec for the imperative Session Replay module.
8
+ //
9
+ // The config crosses the bridge as an untyped object: the native side already
10
+ // reads a ReadableMap / NSDictionary, and app-boundary type safety lives in the
11
+ // public `SessionReplayConfig`. See native-module.ts for the typed facade that
12
+ // JS callers actually use.
13
+ export interface Spec extends TurboModule {
14
+ setup(config: UnsafeObject): Promise<void>;
15
+ setSessionId(sessionId: number): Promise<void>;
16
+ setDeviceId(deviceId: string | null): Promise<void>;
17
+ getSessionId(): Promise<number>;
18
+ getSessionReplayProperties(): Promise<UnsafeObject>;
19
+ start(): Promise<void>;
20
+ stop(): Promise<void>;
21
+ flush(): Promise<void>;
22
+ }
23
+
24
+ // Use non-enforcing `get` (returns null when the native module isn't linked)
25
+ // so importing the package never crashes app startup. The typed facade in
26
+ // native-module.ts throws a friendly linking error lazily on first use instead.
27
+ // Works on both architectures: JSI on the New Architecture, legacy NativeModules
28
+ // fallback on the old one.
29
+ export default TurboModuleRegistry.get<Spec>('AMPNativeSessionReplay');
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.0-beta.0';
1
+ export const VERSION = '0.1.0-beta.1';