@sagepilot-ai/react-native-sdk 0.4.1 → 0.4.3
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 +3 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +22 -5
- package/dist/index.mjs +22 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ For full integration docs, see [React Native SDK docs](https://docs.sagepilot.ai
|
|
|
16
16
|
|
|
17
17
|
## Install
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Base SDK **0.4.3** adds the optional native URL handler. Camera and push add-ons remain at **0.4.2** and retain their existing peer compatibility; chat-only apps do not need either add-on.
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
npm install @sagepilot-ai/react-native-sdk@latest react-native-webview
|
|
@@ -91,6 +91,8 @@ export function SagepilotProvider({ children }: { children: ReactNode }) {
|
|
|
91
91
|
}
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
For native product navigation, pass `onOpenURL` to `SagepilotChatProvider`. It receives external top-level destinations; return `true` (or a promise resolving to `true`) when your native router handles the URL. Returning `false`, omitting the callback, or throwing preserves the existing `Linking.openURL` fallback. Same-origin widget pages, including `/cta` click tracking, load normally before their final destination is offered to the callback. A handled destination resets the hosted WebView so reopening chat does not leave it on a tracking page.
|
|
95
|
+
|
|
94
96
|
```tsx
|
|
95
97
|
export function App() {
|
|
96
98
|
return (
|
package/dist/index.d.mts
CHANGED
|
@@ -487,6 +487,8 @@ type SagepilotChatProviderProps = {
|
|
|
487
487
|
children?: ReactNode;
|
|
488
488
|
closeLabel?: string;
|
|
489
489
|
loadingLabel?: string;
|
|
490
|
+
/** Handle an external destination natively. Return true when handled; false or an error uses Linking.openURL. Same-origin widget and tracking pages remain in the WebView. */
|
|
491
|
+
onOpenURL?: (url: string) => boolean | Promise<boolean>;
|
|
490
492
|
};
|
|
491
493
|
|
|
492
494
|
type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
|
|
@@ -542,6 +544,7 @@ type SagepilotPushAdapter = {
|
|
|
542
544
|
workspaceId: string;
|
|
543
545
|
channelId: string;
|
|
544
546
|
sdkVersion: string;
|
|
547
|
+
storage?: SagepilotCacheStorage;
|
|
545
548
|
owner: SagepilotPushOwner | null;
|
|
546
549
|
customerId: () => string | null;
|
|
547
550
|
upload: (event: SagepilotPushEvent) => Promise<unknown>;
|
|
@@ -724,7 +727,7 @@ type SagepilotAsyncStorageLike = {
|
|
|
724
727
|
};
|
|
725
728
|
declare function createAsyncStorageCacheStorage(asyncStorage: SagepilotAsyncStorageLike): SagepilotCacheStorage;
|
|
726
729
|
|
|
727
|
-
declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: SagepilotChatProviderProps): ReactNode;
|
|
730
|
+
declare function SagepilotChatProvider({ children, closeLabel, loadingLabel, onOpenURL }: SagepilotChatProviderProps): ReactNode;
|
|
728
731
|
|
|
729
732
|
declare function useSagepilotChat(): SagepilotChatHookState;
|
|
730
733
|
|
package/dist/index.d.ts
CHANGED
|
@@ -487,6 +487,8 @@ type SagepilotChatProviderProps = {
|
|
|
487
487
|
children?: ReactNode;
|
|
488
488
|
closeLabel?: string;
|
|
489
489
|
loadingLabel?: string;
|
|
490
|
+
/** Handle an external destination natively. Return true when handled; false or an error uses Linking.openURL. Same-origin widget and tracking pages remain in the WebView. */
|
|
491
|
+
onOpenURL?: (url: string) => boolean | Promise<boolean>;
|
|
490
492
|
};
|
|
491
493
|
|
|
492
494
|
type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
|
|
@@ -542,6 +544,7 @@ type SagepilotPushAdapter = {
|
|
|
542
544
|
workspaceId: string;
|
|
543
545
|
channelId: string;
|
|
544
546
|
sdkVersion: string;
|
|
547
|
+
storage?: SagepilotCacheStorage;
|
|
545
548
|
owner: SagepilotPushOwner | null;
|
|
546
549
|
customerId: () => string | null;
|
|
547
550
|
upload: (event: SagepilotPushEvent) => Promise<unknown>;
|
|
@@ -724,7 +727,7 @@ type SagepilotAsyncStorageLike = {
|
|
|
724
727
|
};
|
|
725
728
|
declare function createAsyncStorageCacheStorage(asyncStorage: SagepilotAsyncStorageLike): SagepilotCacheStorage;
|
|
726
729
|
|
|
727
|
-
declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: SagepilotChatProviderProps): ReactNode;
|
|
730
|
+
declare function SagepilotChatProvider({ children, closeLabel, loadingLabel, onOpenURL }: SagepilotChatProviderProps): ReactNode;
|
|
728
731
|
|
|
729
732
|
declare function useSagepilotChat(): SagepilotChatHookState;
|
|
730
733
|
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var import_react_native2 = require("react-native");
|
|
|
54
54
|
|
|
55
55
|
// package.json
|
|
56
56
|
var name = "@sagepilot-ai/react-native-sdk";
|
|
57
|
-
var version = "0.4.
|
|
57
|
+
var version = "0.4.3";
|
|
58
58
|
|
|
59
59
|
// src/core/config/constants.ts
|
|
60
60
|
var SDK_NAME = name;
|
|
@@ -173,6 +173,7 @@ var SagepilotPush = class {
|
|
|
173
173
|
workspaceId: this.context.workspaceId,
|
|
174
174
|
channelId: this.context.channelId,
|
|
175
175
|
sdkVersion: SDK_VERSION,
|
|
176
|
+
storage: this.config.storage,
|
|
176
177
|
owner: binding?.endpointId && binding.customerId === this.context.customerId() ? { customerId: binding.customerId, endpointId: binding.endpointId } : null,
|
|
177
178
|
customerId: this.context.customerId,
|
|
178
179
|
upload: (event) => this.context.request("/push/events", "POST", event),
|
|
@@ -2237,6 +2238,19 @@ var import_react = require("react");
|
|
|
2237
2238
|
var import_react_native4 = require("react-native");
|
|
2238
2239
|
var import_react_native_webview = require("react-native-webview");
|
|
2239
2240
|
|
|
2241
|
+
// src/core/webview/openUrl.ts
|
|
2242
|
+
async function openHostedChatURL(url, openSystemURL, onOpenURL) {
|
|
2243
|
+
try {
|
|
2244
|
+
if (await onOpenURL?.(url) === true) return true;
|
|
2245
|
+
} catch {
|
|
2246
|
+
}
|
|
2247
|
+
try {
|
|
2248
|
+
await openSystemURL(url);
|
|
2249
|
+
} catch {
|
|
2250
|
+
}
|
|
2251
|
+
return false;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2240
2254
|
// src/core/webview/mobileBridge.ts
|
|
2241
2255
|
var FILE_PICKER_PROTOCOL_VERSION = 2;
|
|
2242
2256
|
function buildBridgeCapabilitiesPayload(capabilities) {
|
|
@@ -2548,7 +2562,8 @@ var emptyAndroidInsets = { top: 0, bottom: 0 };
|
|
|
2548
2562
|
function SagepilotChatProvider({
|
|
2549
2563
|
children,
|
|
2550
2564
|
closeLabel = "Close",
|
|
2551
|
-
loadingLabel = "Loading chat"
|
|
2565
|
+
loadingLabel = "Loading chat",
|
|
2566
|
+
onOpenURL
|
|
2552
2567
|
}) {
|
|
2553
2568
|
const [state, setState] = (0, import_react.useState)(readPresentationState);
|
|
2554
2569
|
const [androidModalInsets, setAndroidModalInsets] = (0, import_react.useState)(emptyAndroidInsets);
|
|
@@ -3031,16 +3046,18 @@ function SagepilotChatProvider({
|
|
|
3031
3046
|
};
|
|
3032
3047
|
const handleShouldStartLoadWithRequest = (0, import_react.useCallback)((request) => {
|
|
3033
3048
|
const url = request?.url ?? "";
|
|
3034
|
-
if (!url || request?.isTopFrame === false || isInternalWebViewScheme(url)) {
|
|
3049
|
+
if (!url || request?.isTopFrame === false && request?.hasTargetFrame !== false || isInternalWebViewScheme(url)) {
|
|
3035
3050
|
return true;
|
|
3036
3051
|
}
|
|
3037
3052
|
const widgetOrigin = readUrlOrigin(state.conversationUrl ?? state.preloadUrl);
|
|
3038
3053
|
if (widgetOrigin && readUrlOrigin(url) === widgetOrigin) {
|
|
3039
3054
|
return true;
|
|
3040
3055
|
}
|
|
3041
|
-
import_react_native4.Linking.openURL
|
|
3056
|
+
void openHostedChatURL(url, import_react_native4.Linking.openURL, onOpenURL).then((handled) => {
|
|
3057
|
+
if (handled) setNativeWebViewKey((key) => key + 1);
|
|
3058
|
+
});
|
|
3042
3059
|
return false;
|
|
3043
|
-
}, [state.conversationUrl, state.preloadUrl]);
|
|
3060
|
+
}, [state.conversationUrl, state.preloadUrl, onOpenURL]);
|
|
3044
3061
|
(0, import_react.useEffect)(() => {
|
|
3045
3062
|
if (import_react_native4.Platform.OS !== "web" || typeof window === "undefined") return;
|
|
3046
3063
|
const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { AppState as AppState2, Platform } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
// package.json
|
|
5
5
|
var name = "@sagepilot-ai/react-native-sdk";
|
|
6
|
-
var version = "0.4.
|
|
6
|
+
var version = "0.4.3";
|
|
7
7
|
|
|
8
8
|
// src/core/config/constants.ts
|
|
9
9
|
var SDK_NAME = name;
|
|
@@ -122,6 +122,7 @@ var SagepilotPush = class {
|
|
|
122
122
|
workspaceId: this.context.workspaceId,
|
|
123
123
|
channelId: this.context.channelId,
|
|
124
124
|
sdkVersion: SDK_VERSION,
|
|
125
|
+
storage: this.config.storage,
|
|
125
126
|
owner: binding?.endpointId && binding.customerId === this.context.customerId() ? { customerId: binding.customerId, endpointId: binding.endpointId } : null,
|
|
126
127
|
customerId: this.context.customerId,
|
|
127
128
|
upload: (event) => this.context.request("/push/events", "POST", event),
|
|
@@ -2198,6 +2199,19 @@ import {
|
|
|
2198
2199
|
} from "react-native";
|
|
2199
2200
|
import { WebView } from "react-native-webview";
|
|
2200
2201
|
|
|
2202
|
+
// src/core/webview/openUrl.ts
|
|
2203
|
+
async function openHostedChatURL(url, openSystemURL, onOpenURL) {
|
|
2204
|
+
try {
|
|
2205
|
+
if (await onOpenURL?.(url) === true) return true;
|
|
2206
|
+
} catch {
|
|
2207
|
+
}
|
|
2208
|
+
try {
|
|
2209
|
+
await openSystemURL(url);
|
|
2210
|
+
} catch {
|
|
2211
|
+
}
|
|
2212
|
+
return false;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2201
2215
|
// src/core/webview/mobileBridge.ts
|
|
2202
2216
|
var FILE_PICKER_PROTOCOL_VERSION = 2;
|
|
2203
2217
|
function buildBridgeCapabilitiesPayload(capabilities) {
|
|
@@ -2509,7 +2523,8 @@ var emptyAndroidInsets = { top: 0, bottom: 0 };
|
|
|
2509
2523
|
function SagepilotChatProvider({
|
|
2510
2524
|
children,
|
|
2511
2525
|
closeLabel = "Close",
|
|
2512
|
-
loadingLabel = "Loading chat"
|
|
2526
|
+
loadingLabel = "Loading chat",
|
|
2527
|
+
onOpenURL
|
|
2513
2528
|
}) {
|
|
2514
2529
|
const [state, setState] = useState(readPresentationState);
|
|
2515
2530
|
const [androidModalInsets, setAndroidModalInsets] = useState(emptyAndroidInsets);
|
|
@@ -2992,16 +3007,18 @@ function SagepilotChatProvider({
|
|
|
2992
3007
|
};
|
|
2993
3008
|
const handleShouldStartLoadWithRequest = useCallback((request) => {
|
|
2994
3009
|
const url = request?.url ?? "";
|
|
2995
|
-
if (!url || request?.isTopFrame === false || isInternalWebViewScheme(url)) {
|
|
3010
|
+
if (!url || request?.isTopFrame === false && request?.hasTargetFrame !== false || isInternalWebViewScheme(url)) {
|
|
2996
3011
|
return true;
|
|
2997
3012
|
}
|
|
2998
3013
|
const widgetOrigin = readUrlOrigin(state.conversationUrl ?? state.preloadUrl);
|
|
2999
3014
|
if (widgetOrigin && readUrlOrigin(url) === widgetOrigin) {
|
|
3000
3015
|
return true;
|
|
3001
3016
|
}
|
|
3002
|
-
Linking2.openURL
|
|
3017
|
+
void openHostedChatURL(url, Linking2.openURL, onOpenURL).then((handled) => {
|
|
3018
|
+
if (handled) setNativeWebViewKey((key) => key + 1);
|
|
3019
|
+
});
|
|
3003
3020
|
return false;
|
|
3004
|
-
}, [state.conversationUrl, state.preloadUrl]);
|
|
3021
|
+
}, [state.conversationUrl, state.preloadUrl, onOpenURL]);
|
|
3005
3022
|
useEffect(() => {
|
|
3006
3023
|
if (Platform3.OS !== "web" || typeof window === "undefined") return;
|
|
3007
3024
|
const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
|