@dynamic-labs/react-native-extension 4.83.0 → 4.83.2-alpha.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 (33) hide show
  1. package/android/EmbeddedWebViewController.kt +26 -0
  2. package/android/EmbeddedWebViewModule.kt +8 -1
  3. package/android/KeyStoreKeyManager.kt +7 -1
  4. package/android/dynamic/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  5. package/android/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  6. package/android/dynamic/keychain/KeyStoreKeyManager.kt +7 -1
  7. package/android/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  8. package/android/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  9. package/android/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  10. package/android/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  11. package/android/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +7 -1
  12. package/android/keychain/KeyStoreKeyManager.kt +7 -1
  13. package/android/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  14. package/android/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  15. package/android/main/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +7 -1
  16. package/android/src/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  17. package/android/src/main/java/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  18. package/android/src/main/java/xyz/dynamic/keychain/KeyStoreKeyManager.kt +7 -1
  19. package/android/xyz/dynamic/embeddedwebview/EmbeddedWebViewController.kt +26 -0
  20. package/android/xyz/dynamic/embeddedwebview/EmbeddedWebViewModule.kt +8 -1
  21. package/android/xyz/dynamic/keychain/KeyStoreKeyManager.kt +7 -1
  22. package/index.cjs +352 -23
  23. package/index.js +353 -24
  24. package/ios/EmbeddedWebViewController.swift +22 -0
  25. package/ios/EmbeddedWebViewModule.swift +8 -1
  26. package/package.json +6 -6
  27. package/src/components/WebView/EmbeddedWebView/EmbeddedWebView.d.ts +20 -1
  28. package/src/components/WebView/EmbeddedWebView/embeddedWebViewPhaseTimers/embeddedWebViewPhaseTimers.d.ts +52 -0
  29. package/src/components/WebView/EmbeddedWebView/embeddedWebViewPhaseTimers/index.d.ts +1 -0
  30. package/src/components/WebView/useWebViewPhaseTimers/index.d.ts +1 -0
  31. package/src/components/WebView/useWebViewPhaseTimers/useWebViewPhaseTimers.d.ts +45 -0
  32. package/src/errors/WebViewFailedToLoadError.d.ts +84 -1
  33. package/src/nativeModules/EmbeddedWebView.d.ts +27 -2
@@ -0,0 +1,45 @@
1
+ import { Core } from '@dynamic-labs/client';
2
+ import { WebViewFailedToLoadErrorMeta, WebViewFailedToLoadErrorPhase } from '../../../errors/WebViewFailedToLoadError';
3
+ /**
4
+ * Wire-format `type` of a webview-side `manifest` request.
5
+ *
6
+ * `requestChannel.request('manifest')` sends a `MessageTransportData` whose
7
+ * `type` is the literal request name. The host replies with `manifest__ack`,
8
+ * which we ignore: receiving the request is sufficient evidence that the
9
+ * webview JS bundle is alive and the message bridge works.
10
+ */
11
+ type WebViewPhaseEvent = 'load_start' | 'load' | 'load_end' | 'native_error' | 'os_kill';
12
+ type UseWebViewPhaseTimersProps = {
13
+ core: Core;
14
+ webViewUrl: URL;
15
+ loadingTimeout: number;
16
+ recoveryTimeout: number;
17
+ };
18
+ export type WebViewPhaseTimers = {
19
+ /**
20
+ * Record a per-attempt lifecycle event. `load_start` resets the
21
+ * per-attempt state (so the timings reflect the current reload), while
22
+ * `native_error` and `os_kill` increment cumulative counters that
23
+ * persist across reloads.
24
+ */
25
+ recordEvent: (event: WebViewPhaseEvent) => void;
26
+ /**
27
+ * Build the structured meta to attach to {@link WebViewFailedToLoadError}.
28
+ * Pass `phase` explicitly from the callsite (the phase reflects the
29
+ * source of the failure, not just the current timing state).
30
+ */
31
+ getMeta: (args: {
32
+ phase: WebViewFailedToLoadErrorPhase;
33
+ }) => WebViewFailedToLoadErrorMeta;
34
+ };
35
+ /**
36
+ * Tracks how long each step of the WebView load took, so when we raise
37
+ * `WebViewFailedToLoadError` we can attach the timings to the error log.
38
+ *
39
+ * The timings cover the host-side phases of the load — the webview-side
40
+ * timings (`webview.time_to_load_manifest`, `webview.time_to_sdk_ready`)
41
+ * still come from the webview itself once it boots, but those don't help
42
+ * when the webview never boots in the first place.
43
+ */
44
+ export declare const useWebViewPhaseTimers: ({ core, webViewUrl, loadingTimeout, recoveryTimeout, }: UseWebViewPhaseTimersProps) => WebViewPhaseTimers;
45
+ export {};
@@ -1,3 +1,86 @@
1
+ /**
2
+ * Categorical phase the WebView was in when the failure was raised.
3
+ *
4
+ * Use this for high-level grouping; the duration fields on
5
+ * {@link WebViewFailedToLoadErrorMeta} give the granular timing data.
6
+ */
7
+ export type WebViewFailedToLoadErrorPhase = 'html_load' | 'sdk_bootstrap' | 'after_clear_state' | 'native_error' | 'embedded_native_error' | 'unknown';
8
+ /**
9
+ * Structured context attached to {@link WebViewFailedToLoadError} so the
10
+ * resulting error log carries enough information to tell *which* step the
11
+ * WebView was stuck in when the failure was raised, and how long each step
12
+ * took.
13
+ *
14
+ * The setter on `InitializationModule.error` forwards this object directly
15
+ * to `logger.error`, so every field below ends up as a structured field on
16
+ * the same Datadog log as the error message.
17
+ */
18
+ export type WebViewFailedToLoadErrorMeta = {
19
+ phase: WebViewFailedToLoadErrorPhase;
20
+ /**
21
+ * Milliseconds between RN's `onLoadStart` and `onLoad` callbacks (the
22
+ * HTML + asset fetch). `null` if `onLoad` never fired.
23
+ */
24
+ htmlLoadMs: number | null;
25
+ /**
26
+ * Milliseconds between RN's `onLoad` and `onLoadEnd` callbacks. Usually
27
+ * small; mostly there to flag pathological cases. `null` if `onLoadEnd`
28
+ * never fired.
29
+ */
30
+ onLoadToOnLoadEndMs: number | null;
31
+ /**
32
+ * Milliseconds between `onLoadEnd` and the first `manifest` request
33
+ * received from the webview-side SDK. Proxy for "the JS bundle is alive
34
+ * and the message bridge works". `null` if the manifest request never
35
+ * arrived.
36
+ */
37
+ manifestReceivedMs: number | null;
38
+ /**
39
+ * Milliseconds between `onLoadEnd` and the webview-side SDK signalling
40
+ * it has finished initialising (via the `sdkHasLoadedEventName` store
41
+ * change). `null` if the SDK never signalled it was ready.
42
+ */
43
+ sdkReadyMs: number | null;
44
+ /**
45
+ * Number of `retry` increments in the WebView URL at the time of failure
46
+ * (covers OS-kill reloads, load_error reloads, and recovery reloads).
47
+ */
48
+ retryCount: number;
49
+ /**
50
+ * Whether the `clear-state` query parameter was present in the URL when
51
+ * the failure was raised. `true` indicates we already retried with a
52
+ * clean state and still couldn't finish loading.
53
+ */
54
+ hadClearState: boolean;
55
+ /**
56
+ * Number of times RN's `onError` fired across the lifetime of the
57
+ * WebView component instance.
58
+ */
59
+ nativeErrorCount: number;
60
+ /**
61
+ * Number of times the OS killed the WebView process (via
62
+ * `onContentProcessDidTerminate` on iOS or `onRenderProcessGone` on
63
+ * Android) across the lifetime of the WebView component instance.
64
+ */
65
+ osKillCount: number;
66
+ /** The configured value for `loadingTimeout` (ms). */
67
+ loadingTimeoutMs: number;
68
+ /** The configured value for `recoveryTimeout` (ms). */
69
+ recoveryTimeoutMs: number;
70
+ /** The URL the WebView was attempting to load when the failure occurred. */
71
+ webviewUrl?: string;
72
+ /**
73
+ * Native error info, only populated when the failure originated from the
74
+ * embedded native WebView path (iOS WKWebView / Android WebView), where
75
+ * we get a single `onLoadError` event with these fields.
76
+ */
77
+ nativeErrorCode?: number;
78
+ nativeErrorDescription?: string;
79
+ nativeErrorDomain?: string;
80
+ nativeErrorIsProvisional?: boolean;
81
+ nativeErrorFailedUrl?: string;
82
+ };
1
83
  export declare class WebViewFailedToLoadError extends Error {
2
- constructor();
84
+ readonly meta?: WebViewFailedToLoadErrorMeta;
85
+ constructor(meta?: WebViewFailedToLoadErrorMeta);
3
86
  }
@@ -16,7 +16,32 @@ export type EmbeddedWebViewOnLoadErrorEvent = {
16
16
  description: string;
17
17
  isProvisional: boolean;
18
18
  };
19
- export type EmbeddedWebViewEventName = 'onMessage' | 'onShouldStartLoad' | 'onLoadError';
19
+ /**
20
+ * Fired when the native webview starts a provisional navigation — the
21
+ * request has been issued but no response bytes have arrived yet.
22
+ * Maps to `WKNavigationDelegate.didStartProvisionalNavigation` on iOS and
23
+ * `WebViewClient.onPageStarted` on Android.
24
+ */
25
+ export type EmbeddedWebViewOnLoadStartEvent = {
26
+ url: string;
27
+ };
28
+ /**
29
+ * Fired when the response has committed and the native webview has begun
30
+ * rendering. Maps to `WKNavigationDelegate.didCommit` on iOS and
31
+ * `WebViewClient.onPageCommitVisible` on Android.
32
+ */
33
+ export type EmbeddedWebViewOnLoadEvent = {
34
+ url: string;
35
+ };
36
+ /**
37
+ * Fired when the native webview finishes loading the page. Maps to
38
+ * `WKNavigationDelegate.didFinish` on iOS and `WebViewClient.onPageFinished`
39
+ * on Android.
40
+ */
41
+ export type EmbeddedWebViewOnLoadEndEvent = {
42
+ url: string;
43
+ };
44
+ export type EmbeddedWebViewEventName = 'onMessage' | 'onShouldStartLoad' | 'onLoadError' | 'onLoadStart' | 'onLoad' | 'onLoadEnd';
20
45
  export type EmbeddedWebViewNativeModule = {
21
46
  setUrl: (url: string) => Promise<void>;
22
47
  setVisible: (visible: boolean) => Promise<void>;
@@ -24,6 +49,6 @@ export type EmbeddedWebViewNativeModule = {
24
49
  destroy: () => Promise<void>;
25
50
  postMessage: (message: string) => Promise<void>;
26
51
  respondToShouldStartLoad: (id: string, allow: boolean) => Promise<void>;
27
- addListener: <T extends EmbeddedWebViewOnMessageEvent | EmbeddedWebViewOnShouldStartLoadEvent | EmbeddedWebViewOnLoadErrorEvent>(eventName: EmbeddedWebViewEventName, listener: (event: T) => void) => EmbeddedWebViewSubscription;
52
+ addListener: <T extends EmbeddedWebViewOnMessageEvent | EmbeddedWebViewOnShouldStartLoadEvent | EmbeddedWebViewOnLoadErrorEvent | EmbeddedWebViewOnLoadStartEvent | EmbeddedWebViewOnLoadEvent | EmbeddedWebViewOnLoadEndEvent>(eventName: EmbeddedWebViewEventName, listener: (event: T) => void) => EmbeddedWebViewSubscription;
28
53
  };
29
54
  export declare const getEmbeddedWebView: () => EmbeddedWebViewNativeModule;