@returningai/react-native-widget-sdk 0.1.4 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Supports React Native **0.81–0.86**, React **19.1–19.x**, Expo SDK **54–57**
6
+ (was 0.86 / 19.2 / 57 only). Node engine floor is **20.19.4**, matching React
7
+ Native 0.81. `react-native-webview` stays **^16** — it already supports
8
+ RN ≥ 0.76 with the New Architecture.
9
+ - Fixes three type errors that broke `tsc` in any host that typechecks the
10
+ package against real host types (the package ships TS source):
11
+ `StyleSheet.absoluteFill` spread, the undeclared iOS-only `hasTargetFrame`
12
+ navigation field, and `unref` on a React Native timer handle. Runtime
13
+ behaviour is unchanged.
14
+ - Adds `compat/host-floor` and `compat/host-target` plus `npm run typecheck:hosts`,
15
+ which typechecks `src` against the real `react-native` and
16
+ `react-native-webview` types at both ends of the supported range.
17
+ - `RETURNING_AI_REACT_NATIVE_PACKAGE` gains `minimumExpoSdk`, `minimumReactNative`,
18
+ `react`, and `minimumReact`.
19
+
3
20
  ## 0.1.4
4
21
 
5
22
  - Removes `ReturningAIWidgetEndpoints.adssProduction`. Hosts that need a
@@ -72,7 +89,7 @@
72
89
  cold-start/reload TTI (Task 6). TTI waits for `rai-ready` only, uses a 20s
73
90
  budget, and prints local samples. Parked RN CI is not a green.
74
91
  - Documents the React Native transport name `ReturningAIReactNativeBridge` in
75
- the integration contract. RN CI stays parked (Task 7).
92
+ `docs/architecture.md`. RN CI stays parked (Task 7).
76
93
  - Reads serverless auth response bodies with `Uint8Array` and `TextDecoder`
77
94
  instead of Node `Buffer`, so the exchange works on Hermes.
78
95
  - Drops `onMessage` payloads with a missing document URL. Accepts
package/README.md CHANGED
@@ -15,13 +15,26 @@ npm install @returningai/react-native-widget-sdk react-native-webview
15
15
 
16
16
  Peer dependencies:
17
17
 
18
- - `react` **^19.2**
19
- - `react-native` **^0.86**
18
+ - `react` **>=19.1.0 <20.0.0**
19
+ - `react-native` **>=0.81.0 <0.87.0**
20
20
  - `react-native-webview` **^16**
21
- - Node.js **22.13+**
21
+ - Node.js **20.19.4+** (host build tooling only)
22
22
 
23
- Expo hosts need SDK **57** and a **dev client** (`expo run:ios` /
24
- `expo run:android`). Expo Go is not supported.
23
+ ### Supported host stacks
24
+
25
+ | Stack | React Native | React | Expo SDK | Proof |
26
+ | ---------- | ------------ | ------ | -------- | --------------------------------------------------------------- |
27
+ | **Target** | 0.86.2 | 19.2.3 | 57 | Loyalty samples; device + loopback TTI runs |
28
+ | **Floor** | 0.81.5 | 19.1.0 | 54 | `npm run typecheck:hosts` + the `loyalty_expo54_starter` sample |
29
+
30
+ Anything between those two stacks resolves, and the SDK source typechecks on
31
+ both ends. The floor has not had a device run yet — report issues with the host
32
+ stack and `onError` output.
33
+
34
+ `react-native-webview` 16 requires the **New Architecture** (the legacy
35
+ architecture is unsupported upstream), **iOS 15.1+**, and Android **minSdk 24+**.
36
+ Expo hosts need a **dev client** (`expo run:ios` / `expo run:android`). Expo Go
37
+ is not supported.
25
38
 
26
39
  Install Web Crypto before the widget loads:
27
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@returningai/react-native-widget-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "React Native SDK for embedding ReturningAI custom product widgets.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -23,6 +23,10 @@
23
23
  "scripts": {
24
24
  "test": "jest",
25
25
  "typecheck": "tsc --noEmit",
26
+ "hosts:install": "npm --prefix compat/host-floor install && npm --prefix compat/host-target install",
27
+ "typecheck:hosts": "npm run typecheck:host-floor && npm run typecheck:host-target",
28
+ "typecheck:host-floor": "tsc -p compat/host-floor/tsconfig.json",
29
+ "typecheck:host-target": "tsc -p compat/host-target/tsconfig.json",
26
30
  "playwright:install": "playwright install chromium",
27
31
  "lint": "eslint .",
28
32
  "lint:fix": "eslint . --fix",
@@ -30,11 +34,11 @@
30
34
  "format:check": "prettier --check ."
31
35
  },
32
36
  "engines": {
33
- "node": ">=22.13.0"
37
+ "node": ">=20.19.4"
34
38
  },
35
39
  "peerDependencies": {
36
- "react": "^19.2.0",
37
- "react-native": "^0.86.0",
40
+ "react": ">=19.1.0 <20.0.0",
41
+ "react-native": ">=0.81.0 <0.87.0",
38
42
  "react-native-webview": "^16.0.0"
39
43
  },
40
44
  "devDependencies": {
@@ -88,6 +88,16 @@ import {
88
88
  isReturningAIResourceErrorTerminal,
89
89
  } from "./webview/errorPolicy";
90
90
 
91
+ /**
92
+ * `ShouldStartLoadRequest` plus the iOS-only `hasTargetFrame` flag.
93
+ * The Apple implementation posts `hasTargetFrame` (false when `navigationAction.targetFrame`
94
+ * is nil, i.e. a new-window navigation) but `react-native-webview` does not declare it, so the
95
+ * field is declared optional here instead of asserted at each read.
96
+ */
97
+ type ReturningAIShouldStartLoadRequest = ShouldStartLoadRequest & {
98
+ readonly hasTargetFrame?: boolean;
99
+ };
100
+
91
101
  /**
92
102
  * Host-supplied loading UI factory shown while the widget is not yet ready.
93
103
  * @returns React node for the loading overlay/placeholder
@@ -432,63 +442,66 @@ export function ReturningAIWidget(props: ReturningAIWidgetProps): ReactElement {
432
442
  }, []);
433
443
 
434
444
  /** Applies navigation policy; only `allow` proceeds in the WebView. */
435
- const onShouldStartLoadWithRequest = useCallback((request: ShouldStartLoadRequest): boolean => {
436
- const configuration = propsRef.current.configuration;
437
- if (isReturningAIHtmlShellDocumentUrl(request.url)) {
438
- logReturningAIWebView(
439
- configuration,
440
- "nav-allow-shell",
441
- request.url,
442
- `top=${String(request.isTopFrame)}`,
443
- `frame=${String(request.hasTargetFrame)}`,
444
- request.navigationType,
445
- );
446
- return true;
447
- }
448
- if (
449
- htmlShellLiveRef.current &&
450
- shouldCancelReturningAIContentOriginRootRefetch({
451
- url: request.url,
452
- isTopFrame: request.isTopFrame,
453
- hasTargetFrame: request.hasTargetFrame,
454
- configuration,
455
- })
456
- ) {
445
+ const onShouldStartLoadWithRequest = useCallback(
446
+ (request: ReturningAIShouldStartLoadRequest): boolean => {
447
+ const configuration = propsRef.current.configuration;
448
+ if (isReturningAIHtmlShellDocumentUrl(request.url)) {
449
+ logReturningAIWebView(
450
+ configuration,
451
+ "nav-allow-shell",
452
+ request.url,
453
+ `top=${String(request.isTopFrame)}`,
454
+ `frame=${String(request.hasTargetFrame)}`,
455
+ request.navigationType,
456
+ );
457
+ return true;
458
+ }
459
+ if (
460
+ htmlShellLiveRef.current &&
461
+ shouldCancelReturningAIContentOriginRootRefetch({
462
+ url: request.url,
463
+ isTopFrame: request.isTopFrame,
464
+ hasTargetFrame: request.hasTargetFrame,
465
+ configuration,
466
+ })
467
+ ) {
468
+ logReturningAIWebView(
469
+ configuration,
470
+ "nav-block-base-refetch",
471
+ request.url,
472
+ `top=${String(request.isTopFrame)}`,
473
+ `frame=${String(request.hasTargetFrame)}`,
474
+ request.navigationType,
475
+ );
476
+ return false;
477
+ }
478
+ const coordinator = coordinatorRef.current;
479
+ if (coordinator === null) {
480
+ logReturningAIWebView(configuration, "nav-block-no-session", request.url);
481
+ return false;
482
+ }
483
+ let uri: URL;
484
+ try {
485
+ uri = new URL(request.url);
486
+ } catch {
487
+ logReturningAIWebView(configuration, "nav-allow-unparseable", request.url);
488
+ return true;
489
+ }
490
+ const isMainFrame = request.isTopFrame !== false;
491
+ const action = coordinator.handleNavigation(uri, isMainFrame);
492
+ const allow = action === ReturningAINavigationAction.allow;
457
493
  logReturningAIWebView(
458
494
  configuration,
459
- "nav-block-base-refetch",
495
+ allow ? "nav-allow" : `nav-${action}`,
460
496
  request.url,
461
497
  `top=${String(request.isTopFrame)}`,
462
498
  `frame=${String(request.hasTargetFrame)}`,
463
499
  request.navigationType,
464
500
  );
465
- return false;
466
- }
467
- const coordinator = coordinatorRef.current;
468
- if (coordinator === null) {
469
- logReturningAIWebView(configuration, "nav-block-no-session", request.url);
470
- return false;
471
- }
472
- let uri: URL;
473
- try {
474
- uri = new URL(request.url);
475
- } catch {
476
- logReturningAIWebView(configuration, "nav-allow-unparseable", request.url);
477
- return true;
478
- }
479
- const isMainFrame = request.isTopFrame !== false;
480
- const action = coordinator.handleNavigation(uri, isMainFrame);
481
- const allow = action === ReturningAINavigationAction.allow;
482
- logReturningAIWebView(
483
- configuration,
484
- allow ? "nav-allow" : `nav-${action}`,
485
- request.url,
486
- `top=${String(request.isTopFrame)}`,
487
- `frame=${String(request.hasTargetFrame)}`,
488
- request.navigationType,
489
- );
490
- return allow;
491
- }, []);
501
+ return allow;
502
+ },
503
+ [],
504
+ );
492
505
 
493
506
  const onError = useCallback((event: WebViewErrorEvent) => {
494
507
  const coordinator = coordinatorRef.current;
@@ -699,7 +712,13 @@ const styles = StyleSheet.create({
699
712
  flex: 1,
700
713
  },
701
714
  overlay: {
702
- ...StyleSheet.absoluteFill,
715
+ // Literal instead of StyleSheet.absoluteFill(Object): RN 0.81 types only allow spreading
716
+ // `absoluteFillObject`, RN 0.86 types dropped it and made `absoluteFill` the plain object.
717
+ position: "absolute",
718
+ left: 0,
719
+ right: 0,
720
+ top: 0,
721
+ bottom: 0,
703
722
  },
704
723
  error: {
705
724
  flex: 1,
@@ -88,7 +88,7 @@ export class ReturningAIAuthenticationClient {
88
88
  timedOut = true;
89
89
  controller.abort();
90
90
  }, validated.authenticationTimeoutMilliseconds);
91
- timeout.unref?.();
91
+ unrefTimer(timeout);
92
92
 
93
93
  const result = this.exchange(validated, embedTokenProvider, controller.signal, () => cancelled)
94
94
  .catch((error: unknown) => {
@@ -437,3 +437,13 @@ function raceAbort<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {
437
437
  );
438
438
  });
439
439
  }
440
+
441
+ /**
442
+ * Detaches the timeout from a Node event loop when the host runtime supports it.
443
+ * React Native and browsers return a numeric handle with no `unref`; Node returns a
444
+ * `Timeout`. The call stays optional so neither runtime is special-cased.
445
+ * @param timer - Handle returned by `setTimeout`
446
+ */
447
+ function unrefTimer(timer: ReturnType<typeof setTimeout>): void {
448
+ (timer as unknown as { unref?: () => void }).unref?.();
449
+ }
@@ -10,14 +10,25 @@
10
10
  /**
11
11
  * Published package metadata and documented peer runtime pins.
12
12
  * Values are informational for hosts and docs; they are not enforced at import time.
13
+ * `minimum*` is the lowest host stack typechecked against real host types
14
+ * (`compat/host-floor`); the unprefixed values are the stack the Loyalty samples run
15
+ * (`compat/host-target`). Both are smoke-checked by `npm run typecheck:hosts`.
13
16
  */
14
17
  export const RETURNING_AI_REACT_NATIVE_PACKAGE = {
15
18
  /** Semver of `@returningai/react-native-widget-sdk`. */
16
- version: "0.1.4",
19
+ version: "0.2.0",
17
20
  /** Documented Expo SDK major this package targets. */
18
21
  expoSdk: 57,
22
+ /** Lowest supported Expo SDK major (React Native 0.81 trio). */
23
+ minimumExpoSdk: 54,
19
24
  /** Documented React Native minor this package targets. */
20
25
  reactNative: "0.86",
26
+ /** Lowest supported React Native minor. */
27
+ minimumReactNative: "0.81",
28
+ /** Documented React minor this package targets. */
29
+ react: "19.2",
30
+ /** Lowest supported React minor. */
31
+ minimumReact: "19.1",
21
32
  /** Documented `react-native-webview` version this package targets. */
22
33
  reactNativeWebView: "16.0.0",
23
34
  } as const;