@dynamic-labs/legacy-react-native-extension 0.0.0 → 5.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 (76) hide show
  1. package/README.md +7 -0
  2. package/android/AndroidManifest.xml +1 -0
  3. package/android/EmbeddedWebViewController.kt +559 -0
  4. package/android/EmbeddedWebViewModule.kt +62 -0
  5. package/android/KeyStoreKeyManager.kt +154 -0
  6. package/android/KeychainModule.kt +71 -0
  7. package/android/build.gradle +38 -0
  8. package/android/dynamic/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  9. package/android/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  10. package/android/dynamic/keychain/KeyStoreKeyManager.kt +154 -0
  11. package/android/dynamic/keychain/KeychainModule.kt +71 -0
  12. package/android/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  13. package/android/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  14. package/android/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  15. package/android/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  16. package/android/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +154 -0
  17. package/android/java/xyz/dynamic/keychain/KeychainModule.kt +71 -0
  18. package/android/keychain/KeyStoreKeyManager.kt +154 -0
  19. package/android/keychain/KeychainModule.kt +71 -0
  20. package/android/main/AndroidManifest.xml +1 -0
  21. package/android/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  22. package/android/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  23. package/android/main/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +154 -0
  24. package/android/main/java/xyz/dynamic/keychain/KeychainModule.kt +71 -0
  25. package/android/src/main/AndroidManifest.xml +1 -0
  26. package/android/src/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  27. package/android/src/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  28. package/android/src/main/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +154 -0
  29. package/android/src/main/java/xyz/dynamic/keychain/KeychainModule.kt +71 -0
  30. package/android/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +559 -0
  31. package/android/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +62 -0
  32. package/android/xyz/dynamic/keychain/KeyStoreKeyManager.kt +154 -0
  33. package/android/xyz/dynamic/keychain/KeychainModule.kt +71 -0
  34. package/expo-module.config.json +12 -0
  35. package/index.cjs +998 -0
  36. package/index.js +973 -0
  37. package/ios/EmbeddedWebViewController.swift +500 -0
  38. package/ios/EmbeddedWebViewModule.swift +69 -0
  39. package/ios/Keychain.podspec +15 -0
  40. package/ios/KeychainModule.swift +39 -0
  41. package/ios/SecureEnclaveKeyManager.swift +187 -0
  42. package/package.json +44 -1
  43. package/src/ReactNativeExtension/ReactNativeExtension.d.ts +64 -0
  44. package/src/ReactNativeExtension/index.d.ts +1 -0
  45. package/src/ReactNativeExtension/logNativeModuleAvailability.d.ts +19 -0
  46. package/src/ReactNativeExtension/setupKeychainHandler/index.d.ts +1 -0
  47. package/src/ReactNativeExtension/setupKeychainHandler/setupKeychainHandler.d.ts +2 -0
  48. package/src/ReactNativeExtension/setupPasskeyHandler/index.d.ts +1 -0
  49. package/src/ReactNativeExtension/setupPasskeyHandler/setupPasskeyHandler.d.ts +2 -0
  50. package/src/ReactNativeExtension/setupPlatformHandler/index.d.ts +1 -0
  51. package/src/ReactNativeExtension/setupPlatformHandler/setupPlatformHandler.d.ts +2 -0
  52. package/src/ReactNativeExtension/setupStorageHandler/index.d.ts +1 -0
  53. package/src/ReactNativeExtension/setupStorageHandler/setupStorageHandler.d.ts +2 -0
  54. package/src/ReactNativeExtension/setupTurnkeyPasskeyHandler/index.d.ts +1 -0
  55. package/src/ReactNativeExtension/setupTurnkeyPasskeyHandler/setupTurnkeyPasskeyHandler.d.ts +2 -0
  56. package/src/components/WebView/EmbeddedWebView/EmbeddedWebView.d.ts +13 -0
  57. package/src/components/WebView/EmbeddedWebView/index.d.ts +1 -0
  58. package/src/components/WebView/WebView.d.ts +37 -0
  59. package/src/components/WebView/WebView.styles.d.ts +26 -0
  60. package/src/components/WebView/index.d.ts +1 -0
  61. package/src/components/WebView/useMessageTransportWebViewBridge/index.d.ts +1 -0
  62. package/src/components/WebView/useMessageTransportWebViewBridge/useMessageTransportWebViewBridge.d.ts +6 -0
  63. package/src/components/WebView/useWebViewVisibility/index.d.ts +1 -0
  64. package/src/components/WebView/useWebViewVisibility/useWebViewVisibility.d.ts +4 -0
  65. package/src/components/WebView/utils/shouldAllowNavigation/index.d.ts +1 -0
  66. package/src/components/WebView/utils/shouldAllowNavigation/shouldAllowNavigation.d.ts +5 -0
  67. package/src/errors/WebViewFailedToLoadError.d.ts +1 -0
  68. package/src/index.d.ts +2 -0
  69. package/src/nativeModules/EmbeddedWebView.d.ts +68 -0
  70. package/src/nativeModules/Keychain.d.ts +23 -0
  71. package/src/nativeModules/index.d.ts +1 -0
  72. package/src/utils/logger.d.ts +2 -0
  73. package/turboModules/NativeDynamicWebView.ts +47 -0
  74. package/turboModules/NativeKeychain.ts +22 -0
  75. package/turboModules/NativeReactNativeManifest.ts +24 -0
  76. package/turboModules/NativeScreenshotProtection.ts +29 -0
package/index.cjs ADDED
@@ -0,0 +1,998 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var assertPackageVersion = require('@dynamic-labs/assert-package-version');
6
+ var reactNative = require('react-native');
7
+ var react = require('react');
8
+ var reactNativeWebview = require('react-native-webview');
9
+ var legacyClient = require('@dynamic-labs/legacy-client');
10
+ var logger$1 = require('@dynamic-labs/logger');
11
+ var messageTransport = require('@dynamic-labs/message-transport');
12
+ var jsxRuntime = require('react/jsx-runtime');
13
+ var expoModulesCore = require('expo-modules-core');
14
+ var reactNativePasskey = require('react-native-passkey');
15
+ var expoLinking = require('expo-linking');
16
+ var expoWebBrowser = require('expo-web-browser');
17
+ var reactNativeKeychain = require('react-native-keychain');
18
+ var reactNativePasskeyStamper = require('@turnkey/react-native-passkey-stamper');
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n["default"] = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var version = "5.1.0";
39
+
40
+ function _extends() {
41
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
42
+ for (var e = 1; e < arguments.length; e++) {
43
+ var t = arguments[e];
44
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
45
+ }
46
+ return n;
47
+ }, _extends.apply(null, arguments);
48
+ }
49
+
50
+ const logger = new logger$1.Logger('react-native-extension');
51
+
52
+ const useMessageTransportWebViewBridge = (core, webViewRef) => {
53
+ /**
54
+ * Receive a message from the webview and forward it to the client
55
+ * message transport
56
+ */
57
+ const onMessageHandler = event => {
58
+ var _a;
59
+ let parsedData = null;
60
+ try {
61
+ parsedData = JSON.parse(event.nativeEvent.data, messageTransport.messageTransportDataJsonReviver);
62
+ } catch (err) {
63
+ logger.debug('error parsing data', err);
64
+ return;
65
+ }
66
+ const message = messageTransport.parseMessageTransportData(parsedData);
67
+ if (!message) {
68
+ logger.debug('invalid message', message);
69
+ return;
70
+ }
71
+ /**
72
+ * Only forward messages from the created by the webview
73
+ */
74
+ if (message.origin === 'webview') {
75
+ if ((_a = core.debug) === null || _a === void 0 ? void 0 : _a.messageTransport) {
76
+ logger.debug('WEBVIEW >>>> HOST', JSON.stringify(message, null, 2));
77
+ }
78
+ core.messageTransport.emit(message);
79
+ }
80
+ };
81
+ /**
82
+ * Send messages created by the client to the webview
83
+ */
84
+ react.useEffect(() => {
85
+ const sendMessageToWebView = message => {
86
+ var _a;
87
+ if (!webViewRef.current) {
88
+ logger.instrument('WebView ref not found — dropping message', {
89
+ environmentId: core.environmentId,
90
+ hostSdkSessionId: core.hostSdkSessionId,
91
+ key: 'webview.message_dropped',
92
+ messageOrigin: message.origin,
93
+ messageType: message.type,
94
+ time: 0
95
+ });
96
+ return;
97
+ }
98
+ /**
99
+ * Only forward messages to the webview
100
+ * that where created by the client/host
101
+ */
102
+ if (message.origin === 'host' && webViewRef.current) {
103
+ if ((_a = core.debug) === null || _a === void 0 ? void 0 : _a.messageTransport) {
104
+ logger.debug('HOST >>>> WEBVIEW', JSON.stringify(message, null, 2));
105
+ }
106
+ webViewRef.current.postMessage(JSON.stringify(message, messageTransport.messageTransportDataJsonReplacer));
107
+ }
108
+ };
109
+ core.messageTransport.on(sendMessageToWebView);
110
+ return () => {
111
+ core.messageTransport.off(sendMessageToWebView);
112
+ };
113
+ }, [core, webViewRef]);
114
+ return {
115
+ onMessageHandler
116
+ };
117
+ };
118
+
119
+ const useWebViewVisibility = core => {
120
+ const webViewVisibilityRequestChannelRef = react.useRef(messageTransport.createRequestChannel(core.messageTransport));
121
+ const [visible, setVisible] = react.useState(false);
122
+ react.useEffect(() => webViewVisibilityRequestChannelRef.current.handle('setVisibility', setVisible), [setVisible]);
123
+ return {
124
+ visible
125
+ };
126
+ };
127
+
128
+ const styles = reactNative.StyleSheet.create({
129
+ container: {
130
+ backgroundColor: 'transparent',
131
+ bottom: 0,
132
+ flex: 1,
133
+ left: 0,
134
+ position: 'absolute',
135
+ right: 0,
136
+ top: 0,
137
+ width: '100%'
138
+ },
139
+ hide: {
140
+ elevation: 0,
141
+ opacity: 0,
142
+ zIndex: -10000
143
+ },
144
+ show: {
145
+ elevation: 10000,
146
+ opacity: 1,
147
+ zIndex: 10000
148
+ },
149
+ webview: {
150
+ backgroundColor: 'transparent',
151
+ flex: 1
152
+ }
153
+ });
154
+
155
+ const waasOrigins = ['https://app.dynamic-preprod.xyz', 'https://app.dynamicauth.com'];
156
+ const turnkeyOrigins = ['https://recovery.turnkey.com', 'https://export.turnkey.com'];
157
+ const isNonProductionBuild = () => process.env['NODE_ENV'] !== 'production';
158
+ const isAllowedWaasOrigin = origin => {
159
+ if (waasOrigins.includes(origin)) {
160
+ return true;
161
+ }
162
+ if (isNonProductionBuild() && /^http:\/\/localhost:\d+$/.test(origin)) {
163
+ return true;
164
+ }
165
+ return false;
166
+ };
167
+ const parseUrl = url => {
168
+ try {
169
+ return new URL(url);
170
+ } catch (error) {
171
+ logger.error('Failed to get origin from url', error);
172
+ return null;
173
+ }
174
+ };
175
+ const shouldAllowNavigation = (request, webViewUrl) => {
176
+ const requestUrl = parseUrl(request.url);
177
+ if (!requestUrl) return false;
178
+ // Sub-frame (iframe) requests are controlled by the trusted web app
179
+ // content — allow them through without restriction.
180
+ if (!request.isTopFrame) return true;
181
+ if (webViewUrl.origin === requestUrl.origin) return true;
182
+ if (requestUrl.pathname.startsWith('/waas-v1') && isAllowedWaasOrigin(requestUrl.origin)) {
183
+ return true;
184
+ }
185
+ if (turnkeyOrigins.includes(requestUrl.origin)) return true;
186
+ return false;
187
+ };
188
+
189
+ const REACT_NATIVE_WEBVIEW_TYPE = 'react_native_webview';
190
+ // react-native-webview's `onError` only carries a `domain` on iOS/macOS.
191
+ // When it is absent (Android) this stable literal stands in so
192
+ // `classifyWebViewLoadError` still receives a domain and classifies the
193
+ // failure by its code alone (unknown domains default to transient).
194
+ const REACT_NATIVE_WEBVIEW_LOAD_ERROR_DOMAIN = 'ReactNativeWebViewLoadError';
195
+ // All load, timeout, retry, telemetry, and terminal-error logic is owned by
196
+ // the webview load controller (`createWebViewLoadController`). This
197
+ // component only owns the platform bindings: the react-native-webview
198
+ // element, its lifecycle-event mapping, the message bridge, visibility
199
+ // handling, and the navigation allowlist.
200
+ const WebView = ({
201
+ webviewUrl,
202
+ core,
203
+ webviewDebuggingEnabled: _webviewDebuggingEnabled = false,
204
+ recoveryTimeout,
205
+ loadingTimeout,
206
+ webviewLoad
207
+ }) => {
208
+ const webViewRef = react.useRef(null);
209
+ const {
210
+ visible
211
+ } = useWebViewVisibility(core);
212
+ // The URL of the load attempt currently in flight. The controller owns
213
+ // URL construction (environmentId, start time, retry counter); loading a
214
+ // new URL remounts the webview via `key`, which is how reloads work on
215
+ // this path. `null` until the controller issues the first load.
216
+ const [currentAttemptUrl, setCurrentAttemptUrl] = react.useState(null);
217
+ const controllerRef = react.useRef(null);
218
+ const {
219
+ onMessageHandler
220
+ } = useMessageTransportWebViewBridge(core, webViewRef);
221
+ /**
222
+ * Owns the load-controller lifecycle: created once per mount, torn down
223
+ * on unmount (keeping the unmount warning + transport block so a stray
224
+ * unmount doesn't leave host messages hitting a dead page).
225
+ */
226
+ react.useEffect(() => {
227
+ const adapter = {
228
+ load: url => setCurrentAttemptUrl(url),
229
+ webviewType: REACT_NATIVE_WEBVIEW_TYPE
230
+ };
231
+ const controller = legacyClient.createWebViewLoadController(Object.assign(Object.assign(Object.assign(Object.assign({
232
+ adapter,
233
+ core
234
+ }, webviewLoad), loadingTimeout !== undefined && {
235
+ pageLoadTimeoutMs: loadingTimeout
236
+ }), recoveryTimeout !== undefined && {
237
+ sdkReadyTimeoutMs: recoveryTimeout
238
+ }), {
239
+ webviewUrl
240
+ }));
241
+ controllerRef.current = controller;
242
+ // Hands the controller to the client core, which wires the
243
+ // customer-facing `client.sdk.loadState` / `client.sdk.retry()`
244
+ // surface to it.
245
+ core.registerWebViewLoadController(controller);
246
+ controller.start();
247
+ return () => {
248
+ logger.warn(unmountWebViewWarningMessage);
249
+ controller.teardown();
250
+ controllerRef.current = null;
251
+ core.messageTransport.block();
252
+ };
253
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the controller lifecycle is strictly mount/unmount
254
+ }, []);
255
+ const dispatch = event => {
256
+ var _a;
257
+ return (_a = controllerRef.current) === null || _a === void 0 ? void 0 : _a.dispatch(event);
258
+ };
259
+ const onError = ({
260
+ nativeEvent
261
+ }) => {
262
+ var _a;
263
+ return dispatch({
264
+ code: nativeEvent.code,
265
+ description: nativeEvent.description,
266
+ domain: (_a = nativeEvent.domain) !== null && _a !== void 0 ? _a : REACT_NATIVE_WEBVIEW_LOAD_ERROR_DOMAIN,
267
+ failedUrl: nativeEvent.url,
268
+ type: 'native_error'
269
+ });
270
+ };
271
+ const onHttpError = ({
272
+ nativeEvent
273
+ }) => dispatch({
274
+ code: nativeEvent.statusCode,
275
+ description: nativeEvent.description,
276
+ domain: legacyClient.EMBEDDED_WEBVIEW_HTTP_ERROR_DOMAIN,
277
+ failedUrl: nativeEvent.url,
278
+ type: 'native_error'
279
+ });
280
+ /**
281
+ * iOS and Android both may kill the webview content process under memory
282
+ * pressure. The controller routes the signal through the bounded
283
+ * backed-off reload cycle, blocking the message transport while the
284
+ * reload is in flight (the machine handles it both mid-load and
285
+ * post-ready).
286
+ */
287
+ const onProcessTerminated = () => dispatch({
288
+ type: 'recovery_requested'
289
+ });
290
+ const containerStyles = [styles['container'], visible ? styles.show : styles.hide];
291
+ if (currentAttemptUrl === null) return null;
292
+ const currentAttemptUrlString = currentAttemptUrl.toString();
293
+ return /*#__PURE__*/jsxRuntime.jsx(reactNativeWebview.WebView, {
294
+ ref: webViewRef,
295
+ source: {
296
+ uri: currentAttemptUrlString
297
+ },
298
+ containerStyle: containerStyles,
299
+ style: styles['webview'],
300
+ onMessage: onMessageHandler,
301
+ onLoadStart: () => dispatch({
302
+ type: 'load_started'
303
+ }),
304
+ onLoad: () => dispatch({
305
+ type: 'response_committed'
306
+ }),
307
+ onLoadEnd: () => dispatch({
308
+ type: 'page_finished'
309
+ }),
310
+ hideKeyboardAccessoryView: true,
311
+ webviewDebuggingEnabled: _webviewDebuggingEnabled,
312
+ onContentProcessDidTerminate: onProcessTerminated,
313
+ onRenderProcessGone: onProcessTerminated,
314
+ onError: onError,
315
+ onHttpError: onHttpError,
316
+ setSupportMultipleWindows: false,
317
+ onShouldStartLoadWithRequest: request => shouldAllowNavigation({
318
+ isTopFrame: request.isTopFrame,
319
+ url: request.url
320
+ }, currentAttemptUrl)
321
+ }, currentAttemptUrlString);
322
+ };
323
+ const createWebView = internalProps => {
324
+ const WebViewWrapper = props => /*#__PURE__*/jsxRuntime.jsx(WebView, _extends({}, internalProps, props));
325
+ return WebViewWrapper;
326
+ };
327
+ const unmountWebViewWarningMessage = `WebView unmounted.
328
+
329
+ The Dynamic WebView may malfunction if it is unmounted.
330
+
331
+ Render the WebView at the top level of your component tree to ensure it is not unmounted.
332
+
333
+ For more information, please refer to the documentation:
334
+ https://docs.dynamic.xyz/react-native/react-native-extension
335
+ `;
336
+
337
+ // eslint-disable-next-line import/no-extraneous-dependencies
338
+ const NATIVE_MODULE_NAME = 'EmbeddedWebView';
339
+ /**
340
+ * Reports whether the EmbeddedWebView native module is linked into the
341
+ * currently running native binary.
342
+ *
343
+ * The embedded webview was introduced mid-version, so an over-the-air JS
344
+ * update can land on an older binary that predates the native module. Callers
345
+ * use this to decide between the native overlay path and the
346
+ * react-native-webview fallback before wiring any side effects.
347
+ *
348
+ * `requireOptionalNativeModule` returns `null` (instead of throwing) when the
349
+ * module is absent. Any unexpected throw is treated as "unavailable" so a
350
+ * runtime quirk can never break the calling flow.
351
+ */
352
+ const isEmbeddedWebViewAvailable = () => {
353
+ try {
354
+ return Boolean(expoModulesCore.requireOptionalNativeModule(NATIVE_MODULE_NAME));
355
+ } catch (_a) {
356
+ return false;
357
+ }
358
+ };
359
+ const getEmbeddedWebView = () => {
360
+ try {
361
+ return expoModulesCore.requireNativeModule(NATIVE_MODULE_NAME);
362
+ } catch (_a) {
363
+ logger.warn('Could not get EmbeddedWebView native module, using unavailable fallback');
364
+ const unavailableError = new Error('EmbeddedWebView is not available');
365
+ const unavailable = {
366
+ addListener: () => ({
367
+ remove: () => undefined
368
+ }),
369
+ destroy: () => Promise.reject(unavailableError),
370
+ postMessage: () => Promise.reject(unavailableError),
371
+ respondToShouldStartLoad: () => Promise.reject(unavailableError),
372
+ setDebuggingEnabled: () => Promise.reject(unavailableError),
373
+ setUrl: () => Promise.reject(unavailableError),
374
+ setVisible: () => Promise.reject(unavailableError)
375
+ };
376
+ return unavailable;
377
+ }
378
+ };
379
+
380
+ // The platform discriminator the load controller attaches to every
381
+ // consolidated `webview.load_*` telemetry event emitted for this path.
382
+ const EMBEDDED_WEBVIEW_TYPE = 'embedded_native';
383
+ // Debug log labels matching the react-native-webview bridge
384
+ // (`useMessageTransportWebViewBridge`) so both paths surface the same
385
+ // HOST/WEBVIEW message trace under `core.debug.messageTransport`.
386
+ const HOST_TO_WEBVIEW_LOG = 'HOST >>>> WEBVIEW';
387
+ const WEBVIEW_TO_HOST_LOG = 'WEBVIEW >>>> HOST';
388
+ // Wires the JS-side bridge to the native WKWebView singleton owned by Swift.
389
+ // This is intentionally not a React component: the embedded webview lives
390
+ // outside the React tree (in a dedicated UIWindow on iOS), so its setup runs
391
+ // once when the SDK is initialised — there's nothing to mount or unmount.
392
+ //
393
+ // All load, timeout, retry, telemetry, and terminal-error logic is owned by
394
+ // the webview load controller (`createWebViewLoadController`). This module
395
+ // only owns the platform bindings: the native-module wiring, the message
396
+ // bridge, visibility handling, and the navigation allowlist.
397
+ //
398
+ // Returns a teardown that removes every JS-side subscription. The native
399
+ // singleton is intentionally NOT destroyed — re-running setup with a fresh
400
+ // `core` (e.g. on client recreation with a new environmentId) just reloads
401
+ // the existing webview via setUrl.
402
+ const setupEmbeddedWebView = ({
403
+ webviewUrl,
404
+ core,
405
+ webviewDebuggingEnabled: _webviewDebuggingEnabled = false,
406
+ webviewLoad
407
+ }) => {
408
+ const native = getEmbeddedWebView();
409
+ // The URL of the load attempt currently in flight. The controller owns
410
+ // URL construction (environmentId, start time, retry counter), so the
411
+ // navigation allowlist below must compare against the URL the native
412
+ // webview was actually pointed at. Until the first `adapter.load` the
413
+ // base URL stands in — only its origin is ever compared.
414
+ let currentAttemptUrl = new URL(webviewUrl);
415
+ const adapter = {
416
+ load: url => {
417
+ var _a;
418
+ currentAttemptUrl = url;
419
+ logger.debug(`[EmbeddedWebView] calling setUrl: ${url.toString()}`);
420
+ (_a = native.setUrl(url.toString())) === null || _a === void 0 ? void 0 : _a.catch(err => {
421
+ logger.warn('EmbeddedWebView.setUrl failed', err);
422
+ });
423
+ },
424
+ webviewType: EMBEDDED_WEBVIEW_TYPE
425
+ };
426
+ const controller = legacyClient.createWebViewLoadController(Object.assign(Object.assign({
427
+ adapter,
428
+ core
429
+ }, webviewLoad), {
430
+ webviewUrl
431
+ }));
432
+ // Hands the controller to the client core, which wires the customer-facing
433
+ // `client.sdk.loadState` / `client.sdk.retry()` surface to it.
434
+ core.registerWebViewLoadController(controller);
435
+ const visibilityChannel = messageTransport.createRequestChannel(core.messageTransport);
436
+ const removeVisibilityHandler = visibilityChannel.handle('setVisibility', visible => {
437
+ native.setVisible(visible).catch(err => {
438
+ logger.warn('EmbeddedWebView.setVisible failed', err);
439
+ });
440
+ });
441
+ const handleHostMessage = message => {
442
+ var _a;
443
+ if (message.origin !== 'host') return;
444
+ if ((_a = core.debug) === null || _a === void 0 ? void 0 : _a.messageTransport) {
445
+ logger.debug(HOST_TO_WEBVIEW_LOG, JSON.stringify(message, null, 2));
446
+ }
447
+ native.postMessage(JSON.stringify(message, messageTransport.messageTransportDataJsonReplacer)).catch(err => {
448
+ logger.warn('EmbeddedWebView.postMessage failed', err);
449
+ });
450
+ };
451
+ core.messageTransport.on(handleHostMessage);
452
+ const onMessageSub = native.addListener('onMessage', event => {
453
+ var _a;
454
+ let parsed = null;
455
+ try {
456
+ parsed = JSON.parse(event.message, messageTransport.messageTransportDataJsonReviver);
457
+ } catch (_b) {
458
+ return;
459
+ }
460
+ const message = messageTransport.parseMessageTransportData(parsed);
461
+ if (!message) return;
462
+ if (message.origin === 'webview') {
463
+ if ((_a = core.debug) === null || _a === void 0 ? void 0 : _a.messageTransport) {
464
+ logger.debug(WEBVIEW_TO_HOST_LOG, JSON.stringify(message, null, 2));
465
+ }
466
+ core.messageTransport.emit(message);
467
+ }
468
+ });
469
+ const onShouldStartLoadSub = native.addListener('onShouldStartLoad', event => {
470
+ const allow = shouldAllowNavigation({
471
+ isTopFrame: event.isTopFrame,
472
+ url: event.url
473
+ }, currentAttemptUrl);
474
+ logger.debug(`[EmbeddedWebView] onShouldStartLoad id=${event.id} url=${event.url} isTopFrame=${event.isTopFrame} allow=${allow}`);
475
+ native.respondToShouldStartLoad(event.id, allow).catch(err => {
476
+ logger.warn('EmbeddedWebView.respondToShouldStartLoad failed', err);
477
+ });
478
+ });
479
+ const onLoadStartSub = native.addListener('onLoadStart', () => {
480
+ logger.debug('[EmbeddedWebView] onLoadStart');
481
+ controller.dispatch({
482
+ type: 'load_started'
483
+ });
484
+ });
485
+ const onLoadSub = native.addListener('onLoad', () => {
486
+ logger.debug('[EmbeddedWebView] onLoad (response committed)');
487
+ controller.dispatch({
488
+ type: 'response_committed'
489
+ });
490
+ });
491
+ const onLoadEndSub = native.addListener('onLoadEnd', () => {
492
+ logger.debug('[EmbeddedWebView] onLoadEnd (page finished)');
493
+ controller.dispatch({
494
+ type: 'page_finished'
495
+ });
496
+ });
497
+ const onLoadErrorSub = native.addListener('onLoadError', event => {
498
+ logger.debug(`[EmbeddedWebView] onLoadError domain=${event.domain} code=${event.code} url=${event.url}`);
499
+ logger.warn('EmbeddedWebView load error', event);
500
+ controller.dispatch({
501
+ code: event.code,
502
+ description: event.description,
503
+ domain: event.domain,
504
+ failedUrl: event.url,
505
+ isProvisional: event.isProvisional,
506
+ type: 'native_error'
507
+ });
508
+ });
509
+ native.setDebuggingEnabled(_webviewDebuggingEnabled).catch(err => {
510
+ logger.warn('EmbeddedWebView.setDebuggingEnabled failed', err);
511
+ });
512
+ // Defer the initial load by one event-loop tick so the JS thread has fully
513
+ // settled after listener registration. On cold boot the main thread is
514
+ // congested with bundle evaluation — yielding here gives pending microtasks
515
+ // and native bridge batches a chance to flush before the native side starts
516
+ // firing navigation events that require a JS round-trip response.
517
+ const warmupTimer = setTimeout(() => {
518
+ controller.start();
519
+ }, 0);
520
+ return () => {
521
+ logger.debug('[EmbeddedWebView] teardown — removing listeners');
522
+ clearTimeout(warmupTimer);
523
+ controller.teardown();
524
+ removeVisibilityHandler();
525
+ core.messageTransport.off(handleHostMessage);
526
+ onMessageSub.remove();
527
+ onShouldStartLoadSub.remove();
528
+ onLoadStartSub.remove();
529
+ onLoadSub.remove();
530
+ onLoadEndSub.remove();
531
+ onLoadErrorSub.remove();
532
+ };
533
+ };
534
+
535
+ // eslint-disable-next-line import/no-extraneous-dependencies
536
+ const KEYCHAIN_MODULE_NAME = 'Keychain';
537
+ /**
538
+ * Reports whether the Keychain native module is linked into the currently
539
+ * running native binary. Mirrors `isEmbeddedWebViewAvailable`: an over-the-air
540
+ * JS update can run on an older binary that predates the module, so any
541
+ * unexpected throw is treated as "unavailable".
542
+ */
543
+ const isKeychainAvailable = () => {
544
+ try {
545
+ return Boolean(expoModulesCore.requireOptionalNativeModule(KEYCHAIN_MODULE_NAME));
546
+ } catch (_a) {
547
+ return false;
548
+ }
549
+ };
550
+ const getKeychain = () => {
551
+ try {
552
+ const keychain = expoModulesCore.requireNativeModule(KEYCHAIN_MODULE_NAME);
553
+ return keychain;
554
+ } catch (error) {
555
+ logger.warn('Could not get dynamic keychain, using unavailable keychain');
556
+ const keychainUnavailableError = new Error('Keychain is not available');
557
+ const unavailableKeychain = {
558
+ deleteKey: () => Promise.reject(keychainUnavailableError),
559
+ generateKeyPair: () => Promise.reject(keychainUnavailableError),
560
+ getPublicKey: () => Promise.reject(keychainUnavailableError),
561
+ hasKey: () => Promise.reject(keychainUnavailableError),
562
+ isAvailable: () => Promise.resolve(false),
563
+ sign: () => Promise.reject(keychainUnavailableError)
564
+ };
565
+ return unavailableKeychain;
566
+ }
567
+ };
568
+
569
+ const NATIVE_MODULES_INSTRUMENT_KEY = 'react_native_extension.native_modules';
570
+ const describeAvailability = available => available ? 'available' : 'unavailable';
571
+ /**
572
+ * Reports the running package version and which native modules are linked into
573
+ * the current binary. The embedded webview / keychain modules were introduced
574
+ * mid-version, so an over-the-air JS update can run ahead of the native binary;
575
+ * pairing the version with the availability matrix surfaces that gap (and lets
576
+ * `embeddedWebViewRequested && !embeddedWebViewAvailable` quantify the
577
+ * react-native-webview fallback rate).
578
+ */
579
+ const logNativeModuleAvailability = ({
580
+ core,
581
+ embeddedWebView,
582
+ embeddedWebViewAvailable,
583
+ keychainAvailable
584
+ }) => {
585
+ const platform = reactNative.Platform.OS;
586
+ logger.instrument('React Native extension native module availability', {
587
+ embeddedWebViewAvailable,
588
+ embeddedWebViewRequested: embeddedWebView,
589
+ environmentId: core.environmentId,
590
+ hostSdkSessionId: core.hostSdkSessionId,
591
+ key: NATIVE_MODULES_INSTRUMENT_KEY,
592
+ keychainAvailable,
593
+ platform,
594
+ time: 0,
595
+ version
596
+ });
597
+ logger.info(`@dynamic-labs/legacy-react-native-extension v${version} (${platform}) — native modules: Keychain=${describeAvailability(keychainAvailable)}, EmbeddedWebView=${describeAvailability(embeddedWebViewAvailable)}`);
598
+ };
599
+
600
+ /******************************************************************************
601
+ Copyright (c) Microsoft Corporation.
602
+
603
+ Permission to use, copy, modify, and/or distribute this software for any
604
+ purpose with or without fee is hereby granted.
605
+
606
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
607
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
608
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
609
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
610
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
611
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
612
+ PERFORMANCE OF THIS SOFTWARE.
613
+ ***************************************************************************** */
614
+
615
+ function __awaiter(thisArg, _arguments, P, generator) {
616
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
617
+ return new (P || (P = Promise))(function (resolve, reject) {
618
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
619
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
620
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
621
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
622
+ });
623
+ }
624
+
625
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
626
+ var e = new Error(message);
627
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
628
+ };
629
+
630
+ const setupPasskeyHandler = core => {
631
+ const passkeyRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
632
+ passkeyRequestChannel.handle('passkey_register', _a => __awaiter(void 0, [_a], void 0, function* ({
633
+ optionsJSON
634
+ }) {
635
+ /**
636
+ * It is safe to cast the request type here because the react-native-passkey
637
+ * package follow the web API spec but typescript does not match both types
638
+ * correctly
639
+ */
640
+ const result = yield reactNativePasskey.Passkey.create(
641
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
642
+ optionsJSON);
643
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
644
+ return result;
645
+ }));
646
+ passkeyRequestChannel.handle('passkey_authenticate', _b => __awaiter(void 0, [_b], void 0, function* ({
647
+ optionsJSON
648
+ }) {
649
+ /**
650
+ * It is safe to cast the request type here because the react-native-passkey
651
+ * package follow the web API spec but typescript does not match both types
652
+ * correctly
653
+ */
654
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
655
+ const result = yield reactNativePasskey.Passkey.get(optionsJSON);
656
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
657
+ return result;
658
+ }));
659
+ };
660
+
661
+ const log = (...args) => logger.logVerboseTroubleshootingMessage('[react-native-extension] setupPlatformHandler', ...args);
662
+ const setupPlatformHandler = core => {
663
+ const platformChannel = messageTransport.createRequestChannel(core.messageTransport);
664
+ const redirectUrl = expoLinking.createURL('');
665
+ log('Setting up platform handler', {
666
+ redirectUrl
667
+ });
668
+ core.manifest.setPlatform('react-native');
669
+ core.manifest.setRedirectUrl(redirectUrl);
670
+ platformChannel.handle('openURL', url => __awaiter(void 0, void 0, void 0, function* () {
671
+ log('openURL called', {
672
+ url
673
+ });
674
+ try {
675
+ yield expoLinking.openURL(url);
676
+ } catch (error) {
677
+ // Re-throw the error so it propagates through the message transport
678
+ // This ensures that if opening the URL fails, the connection promise rejects
679
+ log('openURL failed', {
680
+ error,
681
+ url
682
+ });
683
+ throw error;
684
+ }
685
+ }));
686
+ platformChannel.handle('openAuthenticationWindow', _a => __awaiter(void 0, [_a], void 0, function* ({
687
+ url,
688
+ redirectUrl
689
+ }) {
690
+ log('openAuthenticationWindow called', {
691
+ redirectUrl,
692
+ url
693
+ });
694
+ const result = yield expoWebBrowser.openAuthSessionAsync(url, redirectUrl);
695
+ log('openAuthenticationWindow result', {
696
+ result
697
+ });
698
+ // When not a success, result can only have a type which is a string describing
699
+ // what happened in a single word.
700
+ if (result.type !== 'success') throw new Error(result.type);
701
+ return result.url;
702
+ }));
703
+ platformChannel.handle('downloadFile', _b => __awaiter(void 0, [_b], void 0, function* ({
704
+ base64Content,
705
+ fileName,
706
+ mimeType
707
+ }) {
708
+ /**
709
+ * Sanitize the caller-provided fileName to prevent path traversal
710
+ * (CWE-22). The fileName is used to build a path inside the app cache
711
+ * directory, so a value containing path separators or `..` segments
712
+ * could escape the cache directory and delete/overwrite arbitrary files
713
+ * in the app sandbox. Reject anything that is not a plain basename:
714
+ * empty, `.`/`..`, or containing `/` or `\` (any `..` segment within a
715
+ * path is caught by the separator checks). Reducing to the basename here
716
+ * would silently write attacker-chosen data under a different name, so we
717
+ * reject instead.
718
+ */
719
+ if (!fileName || fileName === '.' || fileName === '..' || fileName.includes('/') || fileName.includes('\\')) {
720
+ throw new Error(`Invalid fileName: ${fileName}`);
721
+ }
722
+ /**
723
+ * Because this is an iOS and Android only package, we need to import
724
+ * dynamically to avoid react-native-web build errors.
725
+ */
726
+ const {
727
+ saveDocuments
728
+ } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@react-native-documents/picker')); });
729
+ const {
730
+ CachesDirectoryPath,
731
+ exists,
732
+ unlink,
733
+ writeFile
734
+ } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('react-native-fs')); });
735
+ /**
736
+ * On native platforms you first need to create a file in the app directory
737
+ * so we can then request the file to be moved by the user to the OS file system.
738
+ */
739
+ const fileUri = `file://${CachesDirectoryPath}/${fileName}`;
740
+ /**
741
+ * Remove the file from the app directory.
742
+ */
743
+ const clearFile = () => __awaiter(void 0, void 0, void 0, function* () {
744
+ const fileExists = yield exists(fileUri);
745
+ if (fileExists) {
746
+ yield unlink(fileUri);
747
+ }
748
+ });
749
+ /**
750
+ * Remove the file from the app directory if it exists.
751
+ */
752
+ yield clearFile();
753
+ try {
754
+ yield writeFile(fileUri, base64Content, {
755
+ encoding: 'base64',
756
+ mimeType
757
+ });
758
+ yield saveDocuments({
759
+ copy: false,
760
+ fileName,
761
+ mimeType,
762
+ sourceUris: [fileUri]
763
+ });
764
+ } finally {
765
+ /**
766
+ * Remove the file after it has been saved
767
+ */
768
+ yield clearFile();
769
+ }
770
+ }));
771
+ // Handle incoming deep links (e.g., wallet redirect flows like Phantom)
772
+ const handleIncomingUrl = url => {
773
+ log('handleIncomingUrl called', {
774
+ hasUrl: Boolean(url),
775
+ url,
776
+ urlParams: url ? new URL(url).searchParams.toString() : null
777
+ });
778
+ if (url) {
779
+ platformChannel.emit('incomingUrl', url);
780
+ }
781
+ };
782
+ expoLinking.getInitialURL().then(url => {
783
+ log('getInitialURL resolved', {
784
+ url
785
+ });
786
+ handleIncomingUrl(url);
787
+ });
788
+ expoLinking.addEventListener('url', ({
789
+ url
790
+ }) => {
791
+ log('addEventListener url event', {
792
+ url
793
+ });
794
+ handleIncomingUrl(url);
795
+ });
796
+ };
797
+
798
+ const assertValidSource = source => {
799
+ if (source !== 'secureStorage') {
800
+ throw new Error(`Invalid storage source "${source}"`);
801
+ }
802
+ };
803
+ const setupStorageHandler = core => {
804
+ const storageRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
805
+ storageRequestChannel.handle('getItem', _a => __awaiter(void 0, [_a], void 0, function* ({
806
+ key,
807
+ source
808
+ }) {
809
+ assertValidSource(source);
810
+ const stored = yield reactNativeKeychain.getGenericPassword({
811
+ service: key
812
+ });
813
+ return stored ? stored.password : null;
814
+ }));
815
+ storageRequestChannel.handle('deleteItem', _b => __awaiter(void 0, [_b], void 0, function* ({
816
+ key,
817
+ source
818
+ }) {
819
+ assertValidSource(source);
820
+ yield reactNativeKeychain.resetGenericPassword({
821
+ service: key
822
+ });
823
+ }));
824
+ storageRequestChannel.handle('setItem', _c => __awaiter(void 0, [_c], void 0, function* ({
825
+ key,
826
+ data,
827
+ source
828
+ }) {
829
+ assertValidSource(source);
830
+ yield reactNativeKeychain.setGenericPassword(key, data, {
831
+ service: key
832
+ });
833
+ }));
834
+ };
835
+
836
+ const setupTurnkeyPasskeyHandler = core => {
837
+ const turnkeyPasskeysRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
838
+ turnkeyPasskeysRequestChannel.handle('createPasskey', _a => __awaiter(void 0, [_a], void 0, function* ({
839
+ publicKey
840
+ }) {
841
+ try {
842
+ const {
843
+ attestation
844
+ } = yield reactNativePasskeyStamper.createPasskey(publicKey);
845
+ return {
846
+ attestation
847
+ };
848
+ } catch (err) {
849
+ logger.error(err);
850
+ throw err;
851
+ }
852
+ }));
853
+ turnkeyPasskeysRequestChannel.handle('passkeyStamp', (rpId, payload) => __awaiter(void 0, void 0, void 0, function* () {
854
+ try {
855
+ const stamper = new reactNativePasskeyStamper.PasskeyStamper({
856
+ rpId
857
+ });
858
+ const stamped = yield stamper.stamp(payload);
859
+ return stamped;
860
+ } catch (err) {
861
+ logger.error(err);
862
+ throw err;
863
+ }
864
+ }));
865
+ };
866
+
867
+ const setupKeychainHandler = core => {
868
+ const keychainRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
869
+ const keychain = getKeychain();
870
+ keychainRequestChannel.handle('keychain_isAvailable', () => __awaiter(void 0, void 0, void 0, function* () {
871
+ return keychain.isAvailable();
872
+ }));
873
+ keychainRequestChannel.handle('keychain_hasKey', _a => __awaiter(void 0, [_a], void 0, function* ({
874
+ key
875
+ }) {
876
+ return keychain.hasKey(key);
877
+ }));
878
+ keychainRequestChannel.handle('keychain_generateKey', _b => __awaiter(void 0, [_b], void 0, function* ({
879
+ key
880
+ }) {
881
+ return keychain.generateKeyPair(key);
882
+ }));
883
+ keychainRequestChannel.handle('keychain_getPublicKey', _c => __awaiter(void 0, [_c], void 0, function* ({
884
+ key
885
+ }) {
886
+ return keychain.getPublicKey(key);
887
+ }));
888
+ keychainRequestChannel.handle('keychain_sign', _d => __awaiter(void 0, [_d], void 0, function* ({
889
+ key,
890
+ payload
891
+ }) {
892
+ return keychain.sign(key, payload);
893
+ }));
894
+ keychainRequestChannel.handle('keychain_removeKey', _e => __awaiter(void 0, [_e], void 0, function* ({
895
+ key
896
+ }) {
897
+ return keychain.deleteKey(key);
898
+ }));
899
+ };
900
+
901
+ const defaultWebviewUrl = `https://webview.dynamicauth.com/${version}`;
902
+ // The native webview singleton outlives the JS bridge, so a re-invocation
903
+ // of the extension factory (e.g. when the consumer recreates the client
904
+ // with a new environmentId) would otherwise stack JS-side listeners on top
905
+ // of the prior ones. We retain the previous teardown at module scope and
906
+ // run it before wiring the next bridge.
907
+ let previousEmbeddedWebViewTeardown = null;
908
+ const ReactNativeExtension = ({
909
+ webviewUrl: _webviewUrl = defaultWebviewUrl,
910
+ webviewDebuggingEnabled,
911
+ appOrigin,
912
+ embeddedWebView: _embeddedWebView = false,
913
+ webviewLoad
914
+ } = {}) => (_, core) => {
915
+ const isPlatformSupportedByWebView = reactNative.Platform.OS === 'android' || reactNative.Platform.OS === 'ios';
916
+ /**
917
+ * If react-native-webview does not supported it will return
918
+ * a dummy webview component so it does not break expo for web
919
+ */
920
+ if (!isPlatformSupportedByWebView) {
921
+ return {
922
+ reactNative: {
923
+ WebView: () => null
924
+ }
925
+ };
926
+ }
927
+ // The embedded webview / keychain modules were introduced mid-version, so
928
+ // an over-the-air JS update can run on an older binary that predates them.
929
+ // Resolve availability once, here, and reuse it for both telemetry and the
930
+ // path-selection gate below. (We are past the web early-return, so the
931
+ // native resolvers only ever run on iOS / Android.)
932
+ const embeddedWebViewAvailable = isEmbeddedWebViewAvailable();
933
+ const keychainAvailable = isKeychainAvailable();
934
+ logNativeModuleAvailability({
935
+ core,
936
+ embeddedWebView: _embeddedWebView,
937
+ embeddedWebViewAvailable,
938
+ keychainAvailable
939
+ });
940
+ if (appOrigin) core.manifest.setAppOrigin(appOrigin);
941
+ setupPasskeyHandler(core);
942
+ setupTurnkeyPasskeyHandler(core);
943
+ setupPlatformHandler(core);
944
+ setupStorageHandler(core);
945
+ setupKeychainHandler(core);
946
+ // Native overlay-webview path (iOS WKWebView / Android android.webkit
947
+ // .WebView). When the native module isn't linked — e.g. an OTA JS update on
948
+ // an older binary that predates it — fall through to the
949
+ // react-native-webview path instead of wiring a bridge to a missing module
950
+ // (which would hang silently).
951
+ const useNativeEmbeddedWebView = _embeddedWebView && embeddedWebViewAvailable;
952
+ if (useNativeEmbeddedWebView) {
953
+ // The native WKWebView lives in its own UIWindow, outside the React
954
+ // tree. Wire the JS bridge once at extension construction and hand the
955
+ // consumer a no-op component so its render never touches the webview.
956
+ if (previousEmbeddedWebViewTeardown) {
957
+ previousEmbeddedWebViewTeardown();
958
+ previousEmbeddedWebViewTeardown = null;
959
+ }
960
+ try {
961
+ previousEmbeddedWebViewTeardown = setupEmbeddedWebView({
962
+ core,
963
+ webviewDebuggingEnabled,
964
+ webviewLoad,
965
+ webviewUrl: _webviewUrl
966
+ });
967
+ } catch (err) {
968
+ // Setup failed — leave the slot empty so the next invocation isn't
969
+ // wedged with a stale teardown reference. The error itself is left
970
+ // to bubble: the consumer needs to see that the bridge isn't wired.
971
+ previousEmbeddedWebViewTeardown = null;
972
+ throw err;
973
+ }
974
+ return {
975
+ reactNative: {
976
+ WebView: () => null
977
+ }
978
+ };
979
+ }
980
+ return {
981
+ reactNative: {
982
+ WebView: createWebView({
983
+ core,
984
+ webviewDebuggingEnabled,
985
+ webviewLoad,
986
+ webviewUrl: _webviewUrl
987
+ })
988
+ }
989
+ };
990
+ };
991
+
992
+ assertPackageVersion.assertPackageVersion('@dynamic-labs/legacy-react-native-extension', version);
993
+
994
+ Object.defineProperty(exports, 'WebViewFailedToLoadError', {
995
+ enumerable: true,
996
+ get: function () { return legacyClient.WebViewFailedToLoadError; }
997
+ });
998
+ exports.ReactNativeExtension = ReactNativeExtension;