@ft-engage/react-native 0.0.0-stage → 0.14.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/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @ft-engage/react-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ FT.Engage for React Native. It follows the shared [SDK protocol](../../docs/PROTOCOL.md).
4
+
5
+ ```bash
6
+ npm install @ft-engage/react-native @react-native-async-storage/async-storage
7
+ ```
8
+
9
+ ```tsx
10
+ import { initEngage, trackNavigation } from '@ft-engage/react-native';
11
+
12
+ const { engage } = await initEngage({ publicKey: 'pk_test_...', endpoint: 'https://your-api.example.com', appVersion: '1.0.0' });
13
+
14
+ <NavigationContainer
15
+ ref={navigationRef}
16
+ onReady={() => trackNavigation(engage, navigationRef.getRootState())}
17
+ onStateChange={() => trackNavigation(engage, navigationRef.getRootState())}
18
+ >
19
+ ```
20
+
21
+ `initEngage` keeps the event queue in AsyncStorage, flushes when the app goes to the background, reports crashes and uncaught errors with the trail of what the person did (your existing crash handler still runs), and reads the deep link that opened the app for UTM tags and ad click ids. Report what is on a screen with `engage.content({ title, texts, buttons, fields, errors })` and taps with `engage.tap({ x, y, label })`. Text is masked on the device.
package/dist/bind.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { FtEngage } from '@ft-engage/sdk';
2
+ import type { EngageConfig, KeyValueStorage } from '@ft-engage/sdk';
3
+ export interface NativeDeps {
4
+ os: string;
5
+ appState: {
6
+ addEventListener(type: 'change', fn: (state: string) => void): {
7
+ remove(): void;
8
+ };
9
+ };
10
+ linking: {
11
+ getInitialURL(): Promise<string | null>;
12
+ addEventListener(type: 'url', fn: (e: {
13
+ url: string;
14
+ }) => void): {
15
+ remove(): void;
16
+ };
17
+ };
18
+ errorUtils?: {
19
+ getGlobalHandler(): (error: unknown, isFatal?: boolean) => void;
20
+ setGlobalHandler(fn: (error: unknown, isFatal?: boolean) => void): void;
21
+ };
22
+ asyncStorage: {
23
+ getItem(k: string): Promise<string | null>;
24
+ setItem(k: string, v: string): Promise<void>;
25
+ removeItem(k: string): Promise<void>;
26
+ };
27
+ }
28
+ export type RnConfig = Omit<EngageConfig, 'platform' | 'storage'> & {
29
+ errors?: boolean;
30
+ links?: boolean;
31
+ };
32
+ export declare const asyncStorageAdapter: (s: NativeDeps["asyncStorage"], prefix?: string) => KeyValueStorage;
33
+ export interface BoundEngage {
34
+ engage: FtEngage;
35
+ stop(): void;
36
+ }
37
+ export declare const bind: (config: RnConfig, deps: NativeDeps) => Promise<BoundEngage>;
38
+ type NavState = {
39
+ index?: number;
40
+ routes: Array<{
41
+ name: string;
42
+ state?: NavState;
43
+ }>;
44
+ } | undefined;
45
+ export declare const currentRoute: (state: NavState) => string | null;
46
+ /** Call from React Navigation's `onReady` and `onStateChange`: `onStateChange={() => trackNavigation(engage, ref.getRootState())}`. */
47
+ export declare const trackNavigation: (engage: FtEngage, state: NavState) => void;
48
+ export {};
package/dist/bind.js ADDED
@@ -0,0 +1,51 @@
1
+ import { FtEngage } from '@ft-engage/sdk';
2
+ export const asyncStorageAdapter = (s, prefix = 'ft_engage.') => ({
3
+ get: (k) => s.getItem(prefix + k),
4
+ set: (k, v) => s.setItem(prefix + k, v),
5
+ remove: (k) => s.removeItem(prefix + k),
6
+ });
7
+ export const bind = async (config, deps) => {
8
+ const platform = deps.os === 'ios' ? 'ios' : deps.os === 'android' ? 'android' : 'web';
9
+ const engage = await FtEngage.init({ ...config, platform, storage: asyncStorageAdapter(deps.asyncStorage) });
10
+ const stops = [];
11
+ const sub = deps.appState.addEventListener('change', (state) => {
12
+ if (state === 'background' || state === 'inactive')
13
+ void engage.flush(true);
14
+ });
15
+ stops.push(() => sub.remove());
16
+ if (config.errors !== false && deps.errorUtils) {
17
+ const eu = deps.errorUtils;
18
+ const previous = eu.getGlobalHandler();
19
+ eu.setGlobalHandler((error, isFatal) => {
20
+ engage.error(error, { fatal: isFatal === true, source: 'react-native' });
21
+ if (isFatal)
22
+ void engage.flush(true);
23
+ previous(error, isFatal);
24
+ });
25
+ stops.push(() => eu.setGlobalHandler(previous));
26
+ }
27
+ if (config.links !== false) {
28
+ const first = await deps.linking.getInitialURL().catch(() => null);
29
+ if (first)
30
+ await engage.openedFrom(first);
31
+ const link = deps.linking.addEventListener('url', (e) => void engage.openedFrom(e.url));
32
+ stops.push(() => link.remove());
33
+ }
34
+ return { engage, stop: () => stops.forEach((s) => s()) };
35
+ };
36
+ export const currentRoute = (state) => {
37
+ let s = state;
38
+ let name = null;
39
+ while (s && s.routes.length > 0) {
40
+ const route = s.routes[s.index ?? s.routes.length - 1];
41
+ name = route.name;
42
+ s = route.state;
43
+ }
44
+ return name;
45
+ };
46
+ /** Call from React Navigation's `onReady` and `onStateChange`: `onStateChange={() => trackNavigation(engage, ref.getRootState())}`. */
47
+ export const trackNavigation = (engage, state) => {
48
+ const name = currentRoute(state);
49
+ if (name)
50
+ engage.screen(name);
51
+ };
@@ -0,0 +1,6 @@
1
+ import type { BoundEngage, RnConfig } from './bind.ts';
2
+ export { trackNavigation, currentRoute } from './bind.ts';
3
+ export type { RnConfig } from './bind.ts';
4
+ export * from '@ft-engage/sdk';
5
+ /** Starts FT.Engage in a React Native app: offline queue in AsyncStorage, flush on background, crash and error reporting, and deep links with ad click ids. */
6
+ export declare const initEngage: (config: RnConfig) => Promise<BoundEngage>;
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import { AppState, Linking, Platform } from 'react-native';
3
+ import { bind } from "./bind.js";
4
+ export { trackNavigation, currentRoute } from "./bind.js";
5
+ export * from '@ft-engage/sdk';
6
+ /** Starts FT.Engage in a React Native app: offline queue in AsyncStorage, flush on background, crash and error reporting, and deep links with ad click ids. */
7
+ export const initEngage = (config) => bind(config, {
8
+ os: Platform.OS,
9
+ appState: AppState,
10
+ linking: Linking,
11
+ asyncStorage: AsyncStorage,
12
+ ...(typeof ErrorUtils !== 'undefined' && ErrorUtils ? { errorUtils: ErrorUtils } : {}),
13
+ });
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@ft-engage/react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.14.0",
4
+ "description": "FT.Engage for React Native: screens from React Navigation, errors, deep links and ad click ids, sessions and an offline queue.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": ["dist", "README.md"],
10
+ "scripts": {
11
+ "build": "tsc -p tsconfig.build.json",
12
+ "typecheck": "tsc --noEmit",
13
+ "test": "node --test \"test/**/*.test.ts\""
14
+ },
15
+ "dependencies": {
16
+ "@ft-engage/sdk": "^0.14.0"
17
+ },
18
+ "peerDependencies": {
19
+ "@react-native-async-storage/async-storage": ">=1.19",
20
+ "react-native": ">=0.72"
21
+ },
22
+ "devDependencies": {
23
+ "@ft-engage/sdk": "file:../js",
24
+ "@types/node": "^24.0.0",
25
+ "typescript": "^5.9.3"
26
+ }
27
+ }