@repzo/widget-react-native 1.0.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 +482 -0
- package/lib/commonjs/agent-ui-blocks.js +159 -0
- package/lib/commonjs/agent-ui-blocks.js.map +1 -0
- package/lib/commonjs/api/client.js +267 -0
- package/lib/commonjs/api/client.js.map +1 -0
- package/lib/commonjs/api/realtime.js +193 -0
- package/lib/commonjs/api/realtime.js.map +1 -0
- package/lib/commonjs/api/sse-parser.js +58 -0
- package/lib/commonjs/api/sse-parser.js.map +1 -0
- package/lib/commonjs/controller.js +23 -0
- package/lib/commonjs/controller.js.map +1 -0
- package/lib/commonjs/device-id.js +75 -0
- package/lib/commonjs/device-id.js.map +1 -0
- package/lib/commonjs/events.js +49 -0
- package/lib/commonjs/events.js.map +1 -0
- package/lib/commonjs/i18n.js +106 -0
- package/lib/commonjs/i18n.js.map +1 -0
- package/lib/commonjs/index.js +98 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/locales.js +85 -0
- package/lib/commonjs/locales.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/push/push-notifications.js +208 -0
- package/lib/commonjs/push/push-notifications.js.map +1 -0
- package/lib/commonjs/state/use-widget-state.js +23 -0
- package/lib/commonjs/state/use-widget-state.js.map +1 -0
- package/lib/commonjs/state/widget-store.js +1682 -0
- package/lib/commonjs/state/widget-store.js.map +1 -0
- package/lib/commonjs/storage.js +147 -0
- package/lib/commonjs/storage.js.map +1 -0
- package/lib/commonjs/types.js +44 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/ui/WidgetProvider.js +404 -0
- package/lib/commonjs/ui/WidgetProvider.js.map +1 -0
- package/lib/commonjs/ui/components/AgentUiBlocks.js +864 -0
- package/lib/commonjs/ui/components/AgentUiBlocks.js.map +1 -0
- package/lib/commonjs/ui/components/Avatar.js +76 -0
- package/lib/commonjs/ui/components/Avatar.js.map +1 -0
- package/lib/commonjs/ui/components/ConversationRow.js +155 -0
- package/lib/commonjs/ui/components/ConversationRow.js.map +1 -0
- package/lib/commonjs/ui/components/ErrorBoundary.js +44 -0
- package/lib/commonjs/ui/components/ErrorBoundary.js.map +1 -0
- package/lib/commonjs/ui/components/Gradient.js +168 -0
- package/lib/commonjs/ui/components/Gradient.js.map +1 -0
- package/lib/commonjs/ui/components/Launcher.js +125 -0
- package/lib/commonjs/ui/components/Launcher.js.map +1 -0
- package/lib/commonjs/ui/components/Markdown.js +257 -0
- package/lib/commonjs/ui/components/Markdown.js.map +1 -0
- package/lib/commonjs/ui/components/OutboundMessageCard.js +157 -0
- package/lib/commonjs/ui/components/OutboundMessageCard.js.map +1 -0
- package/lib/commonjs/ui/components/WidgetPanel.js +131 -0
- package/lib/commonjs/ui/components/WidgetPanel.js.map +1 -0
- package/lib/commonjs/ui/components/icons.js +383 -0
- package/lib/commonjs/ui/components/icons.js.map +1 -0
- package/lib/commonjs/ui/hooks/use-keyboard-overlap.js +113 -0
- package/lib/commonjs/ui/hooks/use-keyboard-overlap.js.map +1 -0
- package/lib/commonjs/ui/hooks/use-reduce-motion.js +38 -0
- package/lib/commonjs/ui/hooks/use-reduce-motion.js.map +1 -0
- package/lib/commonjs/ui/hooks/use-widget-insets.js +41 -0
- package/lib/commonjs/ui/hooks/use-widget-insets.js.map +1 -0
- package/lib/commonjs/ui/screens/chat/ChatView.js +590 -0
- package/lib/commonjs/ui/screens/chat/ChatView.js.map +1 -0
- package/lib/commonjs/ui/screens/chat/ChatView.styles.js +362 -0
- package/lib/commonjs/ui/screens/chat/ChatView.styles.js.map +1 -0
- package/lib/commonjs/ui/screens/chat/ChatView.types.js +6 -0
- package/lib/commonjs/ui/screens/chat/ChatView.types.js.map +1 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.js +150 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.js.map +1 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.styles.js +118 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.styles.js.map +1 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.types.js +6 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.types.js.map +1 -0
- package/lib/commonjs/ui/screens/home/HomeView.js +336 -0
- package/lib/commonjs/ui/screens/home/HomeView.js.map +1 -0
- package/lib/commonjs/ui/screens/home/HomeView.styles.js +245 -0
- package/lib/commonjs/ui/screens/home/HomeView.styles.js.map +1 -0
- package/lib/commonjs/ui/screens/home/HomeView.types.js +6 -0
- package/lib/commonjs/ui/screens/home/HomeView.types.js.map +1 -0
- package/lib/commonjs/ui/screens/home/greeting.js +49 -0
- package/lib/commonjs/ui/screens/home/greeting.js.map +1 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.js +229 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.js.map +1 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.styles.js +125 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.styles.js.map +1 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.types.js +6 -0
- package/lib/commonjs/ui/screens/pre-chat/PreChatForm.types.js.map +1 -0
- package/lib/commonjs/ui/styles/global.js +55 -0
- package/lib/commonjs/ui/styles/global.js.map +1 -0
- package/lib/commonjs/ui/styles/theme.js +148 -0
- package/lib/commonjs/ui/styles/theme.js.map +1 -0
- package/lib/commonjs/ui/utils/conversations.js +125 -0
- package/lib/commonjs/ui/utils/conversations.js.map +1 -0
- package/lib/commonjs/ui/utils/html.js +44 -0
- package/lib/commonjs/ui/utils/html.js.map +1 -0
- package/lib/commonjs/ui/utils/native-gradient.js +65 -0
- package/lib/commonjs/ui/utils/native-gradient.js.map +1 -0
- package/lib/commonjs/ui/utils/rtl.js +56 -0
- package/lib/commonjs/ui/utils/rtl.js.map +1 -0
- package/lib/commonjs/ui/utils/safe-url.js +67 -0
- package/lib/commonjs/ui/utils/safe-url.js.map +1 -0
- package/lib/module/agent-ui-blocks.js +152 -0
- package/lib/module/agent-ui-blocks.js.map +1 -0
- package/lib/module/api/client.js +261 -0
- package/lib/module/api/client.js.map +1 -0
- package/lib/module/api/realtime.js +189 -0
- package/lib/module/api/realtime.js.map +1 -0
- package/lib/module/api/sse-parser.js +53 -0
- package/lib/module/api/sse-parser.js.map +1 -0
- package/lib/module/controller.js +19 -0
- package/lib/module/controller.js.map +1 -0
- package/lib/module/device-id.js +69 -0
- package/lib/module/device-id.js.map +1 -0
- package/lib/module/events.js +44 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/i18n.js +99 -0
- package/lib/module/i18n.js.map +1 -0
- package/lib/module/index.js +55 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/locales.js +80 -0
- package/lib/module/locales.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/push/push-notifications.js +204 -0
- package/lib/module/push/push-notifications.js.map +1 -0
- package/lib/module/state/use-widget-state.js +18 -0
- package/lib/module/state/use-widget-state.js.map +1 -0
- package/lib/module/state/widget-store.js +1677 -0
- package/lib/module/state/widget-store.js.map +1 -0
- package/lib/module/storage.js +141 -0
- package/lib/module/storage.js.map +1 -0
- package/lib/module/types.js +40 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/ui/WidgetProvider.js +400 -0
- package/lib/module/ui/WidgetProvider.js.map +1 -0
- package/lib/module/ui/components/AgentUiBlocks.js +857 -0
- package/lib/module/ui/components/AgentUiBlocks.js.map +1 -0
- package/lib/module/ui/components/Avatar.js +71 -0
- package/lib/module/ui/components/Avatar.js.map +1 -0
- package/lib/module/ui/components/ConversationRow.js +150 -0
- package/lib/module/ui/components/ConversationRow.js.map +1 -0
- package/lib/module/ui/components/ErrorBoundary.js +39 -0
- package/lib/module/ui/components/ErrorBoundary.js.map +1 -0
- package/lib/module/ui/components/Gradient.js +165 -0
- package/lib/module/ui/components/Gradient.js.map +1 -0
- package/lib/module/ui/components/Launcher.js +121 -0
- package/lib/module/ui/components/Launcher.js.map +1 -0
- package/lib/module/ui/components/Markdown.js +253 -0
- package/lib/module/ui/components/Markdown.js.map +1 -0
- package/lib/module/ui/components/OutboundMessageCard.js +153 -0
- package/lib/module/ui/components/OutboundMessageCard.js.map +1 -0
- package/lib/module/ui/components/WidgetPanel.js +127 -0
- package/lib/module/ui/components/WidgetPanel.js.map +1 -0
- package/lib/module/ui/components/icons.js +370 -0
- package/lib/module/ui/components/icons.js.map +1 -0
- package/lib/module/ui/hooks/use-keyboard-overlap.js +109 -0
- package/lib/module/ui/hooks/use-keyboard-overlap.js.map +1 -0
- package/lib/module/ui/hooks/use-reduce-motion.js +34 -0
- package/lib/module/ui/hooks/use-reduce-motion.js.map +1 -0
- package/lib/module/ui/hooks/use-widget-insets.js +37 -0
- package/lib/module/ui/hooks/use-widget-insets.js.map +1 -0
- package/lib/module/ui/screens/chat/ChatView.js +586 -0
- package/lib/module/ui/screens/chat/ChatView.js.map +1 -0
- package/lib/module/ui/screens/chat/ChatView.styles.js +358 -0
- package/lib/module/ui/screens/chat/ChatView.styles.js.map +1 -0
- package/lib/module/ui/screens/chat/ChatView.types.js +4 -0
- package/lib/module/ui/screens/chat/ChatView.types.js.map +1 -0
- package/lib/module/ui/screens/conversations/ConversationsList.js +146 -0
- package/lib/module/ui/screens/conversations/ConversationsList.js.map +1 -0
- package/lib/module/ui/screens/conversations/ConversationsList.styles.js +114 -0
- package/lib/module/ui/screens/conversations/ConversationsList.styles.js.map +1 -0
- package/lib/module/ui/screens/conversations/ConversationsList.types.js +4 -0
- package/lib/module/ui/screens/conversations/ConversationsList.types.js.map +1 -0
- package/lib/module/ui/screens/home/HomeView.js +332 -0
- package/lib/module/ui/screens/home/HomeView.js.map +1 -0
- package/lib/module/ui/screens/home/HomeView.styles.js +242 -0
- package/lib/module/ui/screens/home/HomeView.styles.js.map +1 -0
- package/lib/module/ui/screens/home/HomeView.types.js +4 -0
- package/lib/module/ui/screens/home/HomeView.types.js.map +1 -0
- package/lib/module/ui/screens/home/greeting.js +44 -0
- package/lib/module/ui/screens/home/greeting.js.map +1 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.js +225 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.js.map +1 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.styles.js +121 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.styles.js.map +1 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.types.js +4 -0
- package/lib/module/ui/screens/pre-chat/PreChatForm.types.js.map +1 -0
- package/lib/module/ui/styles/global.js +51 -0
- package/lib/module/ui/styles/global.js.map +1 -0
- package/lib/module/ui/styles/theme.js +137 -0
- package/lib/module/ui/styles/theme.js.map +1 -0
- package/lib/module/ui/utils/conversations.js +115 -0
- package/lib/module/ui/utils/conversations.js.map +1 -0
- package/lib/module/ui/utils/html.js +39 -0
- package/lib/module/ui/utils/html.js.map +1 -0
- package/lib/module/ui/utils/native-gradient.js +60 -0
- package/lib/module/ui/utils/native-gradient.js.map +1 -0
- package/lib/module/ui/utils/rtl.js +49 -0
- package/lib/module/ui/utils/rtl.js.map +1 -0
- package/lib/module/ui/utils/safe-url.js +59 -0
- package/lib/module/ui/utils/safe-url.js.map +1 -0
- package/lib/typescript/commonjs/agent-ui-blocks.d.ts +20 -0
- package/lib/typescript/commonjs/agent-ui-blocks.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/client.d.ts +115 -0
- package/lib/typescript/commonjs/api/client.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/realtime.d.ts +39 -0
- package/lib/typescript/commonjs/api/realtime.d.ts.map +1 -0
- package/lib/typescript/commonjs/api/sse-parser.d.ts +13 -0
- package/lib/typescript/commonjs/api/sse-parser.d.ts.map +1 -0
- package/lib/typescript/commonjs/controller.d.ts +15 -0
- package/lib/typescript/commonjs/controller.d.ts.map +1 -0
- package/lib/typescript/commonjs/device-id.d.ts +15 -0
- package/lib/typescript/commonjs/device-id.d.ts.map +1 -0
- package/lib/typescript/commonjs/events.d.ts +41 -0
- package/lib/typescript/commonjs/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n.d.ts +78 -0
- package/lib/typescript/commonjs/i18n.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +103 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/locales.d.ts +18 -0
- package/lib/typescript/commonjs/locales.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/push/push-notifications.d.ts +71 -0
- package/lib/typescript/commonjs/push/push-notifications.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/use-widget-state.d.ts +10 -0
- package/lib/typescript/commonjs/state/use-widget-state.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/widget-store.d.ts +227 -0
- package/lib/typescript/commonjs/state/widget-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/storage.d.ts +42 -0
- package/lib/typescript/commonjs/storage.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +391 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/WidgetProvider.d.ts +15 -0
- package/lib/typescript/commonjs/ui/WidgetProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/AgentUiBlocks.d.ts +27 -0
- package/lib/typescript/commonjs/ui/components/AgentUiBlocks.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/Avatar.d.ts +19 -0
- package/lib/typescript/commonjs/ui/components/Avatar.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/ConversationRow.d.ts +26 -0
- package/lib/typescript/commonjs/ui/components/ConversationRow.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/ErrorBoundary.d.ts +27 -0
- package/lib/typescript/commonjs/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/Gradient.d.ts +33 -0
- package/lib/typescript/commonjs/ui/components/Gradient.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/Launcher.d.ts +18 -0
- package/lib/typescript/commonjs/ui/components/Launcher.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/Markdown.d.ts +19 -0
- package/lib/typescript/commonjs/ui/components/Markdown.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/OutboundMessageCard.d.ts +20 -0
- package/lib/typescript/commonjs/ui/components/OutboundMessageCard.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/WidgetPanel.d.ts +26 -0
- package/lib/typescript/commonjs/ui/components/WidgetPanel.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/components/icons.d.ts +38 -0
- package/lib/typescript/commonjs/ui/components/icons.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/use-keyboard-overlap.d.ts +33 -0
- package/lib/typescript/commonjs/ui/hooks/use-keyboard-overlap.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/use-reduce-motion.d.ts +11 -0
- package/lib/typescript/commonjs/ui/hooks/use-reduce-motion.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/use-widget-insets.d.ts +16 -0
- package/lib/typescript/commonjs/ui/hooks/use-widget-insets.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.d.ts +11 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.styles.d.ts +349 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.styles.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.types.d.ts +48 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.d.ts +10 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.styles.d.ts +113 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.styles.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.types.d.ts +31 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.d.ts +17 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.styles.d.ts +227 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.styles.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.types.d.ts +40 -0
- package/lib/typescript/commonjs/ui/screens/home/HomeView.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/home/greeting.d.ts +19 -0
- package/lib/typescript/commonjs/ui/screens/home/greeting.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.d.ts +7 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.styles.d.ts +115 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.styles.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.types.d.ts +20 -0
- package/lib/typescript/commonjs/ui/screens/pre-chat/PreChatForm.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/styles/global.d.ts +46 -0
- package/lib/typescript/commonjs/ui/styles/global.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/styles/theme.d.ts +103 -0
- package/lib/typescript/commonjs/ui/styles/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/conversations.d.ts +41 -0
- package/lib/typescript/commonjs/ui/utils/conversations.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/html.d.ts +10 -0
- package/lib/typescript/commonjs/ui/utils/html.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/native-gradient.d.ts +61 -0
- package/lib/typescript/commonjs/ui/utils/native-gradient.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/rtl.d.ts +33 -0
- package/lib/typescript/commonjs/ui/utils/rtl.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/safe-url.d.ts +21 -0
- package/lib/typescript/commonjs/ui/utils/safe-url.d.ts.map +1 -0
- package/lib/typescript/module/agent-ui-blocks.d.ts +20 -0
- package/lib/typescript/module/agent-ui-blocks.d.ts.map +1 -0
- package/lib/typescript/module/api/client.d.ts +115 -0
- package/lib/typescript/module/api/client.d.ts.map +1 -0
- package/lib/typescript/module/api/realtime.d.ts +39 -0
- package/lib/typescript/module/api/realtime.d.ts.map +1 -0
- package/lib/typescript/module/api/sse-parser.d.ts +13 -0
- package/lib/typescript/module/api/sse-parser.d.ts.map +1 -0
- package/lib/typescript/module/controller.d.ts +15 -0
- package/lib/typescript/module/controller.d.ts.map +1 -0
- package/lib/typescript/module/device-id.d.ts +15 -0
- package/lib/typescript/module/device-id.d.ts.map +1 -0
- package/lib/typescript/module/events.d.ts +41 -0
- package/lib/typescript/module/events.d.ts.map +1 -0
- package/lib/typescript/module/i18n.d.ts +78 -0
- package/lib/typescript/module/i18n.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +103 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/locales.d.ts +18 -0
- package/lib/typescript/module/locales.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/push/push-notifications.d.ts +71 -0
- package/lib/typescript/module/push/push-notifications.d.ts.map +1 -0
- package/lib/typescript/module/state/use-widget-state.d.ts +10 -0
- package/lib/typescript/module/state/use-widget-state.d.ts.map +1 -0
- package/lib/typescript/module/state/widget-store.d.ts +227 -0
- package/lib/typescript/module/state/widget-store.d.ts.map +1 -0
- package/lib/typescript/module/storage.d.ts +42 -0
- package/lib/typescript/module/storage.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +391 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/lib/typescript/module/ui/WidgetProvider.d.ts +15 -0
- package/lib/typescript/module/ui/WidgetProvider.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/AgentUiBlocks.d.ts +27 -0
- package/lib/typescript/module/ui/components/AgentUiBlocks.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/Avatar.d.ts +19 -0
- package/lib/typescript/module/ui/components/Avatar.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/ConversationRow.d.ts +26 -0
- package/lib/typescript/module/ui/components/ConversationRow.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/ErrorBoundary.d.ts +27 -0
- package/lib/typescript/module/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/Gradient.d.ts +33 -0
- package/lib/typescript/module/ui/components/Gradient.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/Launcher.d.ts +18 -0
- package/lib/typescript/module/ui/components/Launcher.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/Markdown.d.ts +19 -0
- package/lib/typescript/module/ui/components/Markdown.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/OutboundMessageCard.d.ts +20 -0
- package/lib/typescript/module/ui/components/OutboundMessageCard.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/WidgetPanel.d.ts +26 -0
- package/lib/typescript/module/ui/components/WidgetPanel.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/icons.d.ts +38 -0
- package/lib/typescript/module/ui/components/icons.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/use-keyboard-overlap.d.ts +33 -0
- package/lib/typescript/module/ui/hooks/use-keyboard-overlap.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/use-reduce-motion.d.ts +11 -0
- package/lib/typescript/module/ui/hooks/use-reduce-motion.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/use-widget-insets.d.ts +16 -0
- package/lib/typescript/module/ui/hooks/use-widget-insets.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.d.ts +11 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.styles.d.ts +349 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.styles.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.types.d.ts +48 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.types.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.d.ts +10 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.styles.d.ts +113 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.styles.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.types.d.ts +31 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.types.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/home/HomeView.d.ts +17 -0
- package/lib/typescript/module/ui/screens/home/HomeView.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/home/HomeView.styles.d.ts +227 -0
- package/lib/typescript/module/ui/screens/home/HomeView.styles.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/home/HomeView.types.d.ts +40 -0
- package/lib/typescript/module/ui/screens/home/HomeView.types.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/home/greeting.d.ts +19 -0
- package/lib/typescript/module/ui/screens/home/greeting.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.d.ts +7 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.styles.d.ts +115 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.styles.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.types.d.ts +20 -0
- package/lib/typescript/module/ui/screens/pre-chat/PreChatForm.types.d.ts.map +1 -0
- package/lib/typescript/module/ui/styles/global.d.ts +46 -0
- package/lib/typescript/module/ui/styles/global.d.ts.map +1 -0
- package/lib/typescript/module/ui/styles/theme.d.ts +103 -0
- package/lib/typescript/module/ui/styles/theme.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/conversations.d.ts +41 -0
- package/lib/typescript/module/ui/utils/conversations.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/html.d.ts +10 -0
- package/lib/typescript/module/ui/utils/html.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/native-gradient.d.ts +61 -0
- package/lib/typescript/module/ui/utils/native-gradient.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/rtl.d.ts +33 -0
- package/lib/typescript/module/ui/utils/rtl.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/safe-url.d.ts +21 -0
- package/lib/typescript/module/ui/utils/safe-url.d.ts.map +1 -0
- package/metro.js +40 -0
- package/package.json +116 -0
- package/src/agent-ui-blocks.ts +302 -0
- package/src/api/client.ts +332 -0
- package/src/api/realtime.ts +225 -0
- package/src/api/sse-parser.ts +51 -0
- package/src/controller.ts +20 -0
- package/src/device-id.ts +71 -0
- package/src/events.ts +74 -0
- package/src/i18n.ts +114 -0
- package/src/index.tsx +199 -0
- package/src/locales.ts +80 -0
- package/src/push/push-notifications.ts +254 -0
- package/src/state/use-widget-state.ts +20 -0
- package/src/state/widget-store.ts +1815 -0
- package/src/storage.ts +153 -0
- package/src/types.ts +445 -0
- package/src/ui/WidgetProvider.tsx +434 -0
- package/src/ui/components/AgentUiBlocks.tsx +912 -0
- package/src/ui/components/Avatar.tsx +86 -0
- package/src/ui/components/ConversationRow.tsx +163 -0
- package/src/ui/components/ErrorBoundary.tsx +49 -0
- package/src/ui/components/Gradient.tsx +165 -0
- package/src/ui/components/Launcher.tsx +128 -0
- package/src/ui/components/Markdown.tsx +291 -0
- package/src/ui/components/OutboundMessageCard.tsx +154 -0
- package/src/ui/components/WidgetPanel.tsx +133 -0
- package/src/ui/components/icons.tsx +315 -0
- package/src/ui/hooks/use-keyboard-overlap.ts +134 -0
- package/src/ui/hooks/use-reduce-motion.ts +39 -0
- package/src/ui/hooks/use-widget-insets.ts +44 -0
- package/src/ui/screens/chat/ChatView.styles.ts +357 -0
- package/src/ui/screens/chat/ChatView.tsx +690 -0
- package/src/ui/screens/chat/ChatView.types.ts +46 -0
- package/src/ui/screens/conversations/ConversationsList.styles.ts +111 -0
- package/src/ui/screens/conversations/ConversationsList.tsx +144 -0
- package/src/ui/screens/conversations/ConversationsList.types.ts +33 -0
- package/src/ui/screens/home/HomeView.styles.ts +246 -0
- package/src/ui/screens/home/HomeView.tsx +336 -0
- package/src/ui/screens/home/HomeView.types.ts +42 -0
- package/src/ui/screens/home/greeting.ts +50 -0
- package/src/ui/screens/pre-chat/PreChatForm.styles.ts +120 -0
- package/src/ui/screens/pre-chat/PreChatForm.tsx +221 -0
- package/src/ui/screens/pre-chat/PreChatForm.types.ts +22 -0
- package/src/ui/styles/global.ts +50 -0
- package/src/ui/styles/theme.ts +155 -0
- package/src/ui/utils/conversations.ts +122 -0
- package/src/ui/utils/html.ts +58 -0
- package/src/ui/utils/native-gradient.ts +60 -0
- package/src/ui/utils/rtl.ts +43 -0
- package/src/ui/utils/safe-url.ts +63 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural parsing for agent-authored UI blocks.
|
|
3
|
+
*
|
|
4
|
+
* The CRM validates these with zod (`shared/agent-ui-blocks.ts`) before
|
|
5
|
+
* broadcasting, so this side only needs to reject malformed payloads rather
|
|
6
|
+
* than re-implement the schema — which keeps the SDK dependency-free. Action
|
|
7
|
+
* message formatting is copied verbatim so the transcript reads the same on
|
|
8
|
+
* web and mobile.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { AgentUiAction, AgentUiBlock, AgentProcedureForm } from './types';
|
|
12
|
+
|
|
13
|
+
const KNOWN_BLOCK_TYPES = new Set([
|
|
14
|
+
'product_service_card',
|
|
15
|
+
'product_choices',
|
|
16
|
+
'commerce_actions',
|
|
17
|
+
'cart_order_summary',
|
|
18
|
+
'contact_lead_form',
|
|
19
|
+
'consent',
|
|
20
|
+
'appointment_slot_picker',
|
|
21
|
+
'quote_preview',
|
|
22
|
+
'success_receipt',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const KNOWN_ACTION_TYPES = new Set([
|
|
26
|
+
'add_to_cart',
|
|
27
|
+
'buy_now',
|
|
28
|
+
'submit_contact',
|
|
29
|
+
'record_consent',
|
|
30
|
+
'select_appointment_provider',
|
|
31
|
+
'select_appointment_slot',
|
|
32
|
+
'open_record',
|
|
33
|
+
'accept_quote',
|
|
34
|
+
'next_action',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
38
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The renderer dereferences nested fields and hands strings to <Text>, so a
|
|
42
|
+
// block is only accepted when every field it touches has the right shape —
|
|
43
|
+
// one wrong type (`providers` missing, a numeric slot time, a string
|
|
44
|
+
// `amount`) must skip that block, not throw inside the host app's tree.
|
|
45
|
+
|
|
46
|
+
const isString = (value: unknown): value is string => typeof value === 'string';
|
|
47
|
+
|
|
48
|
+
const isNumber = (value: unknown): value is number =>
|
|
49
|
+
typeof value === 'number' && Number.isFinite(value);
|
|
50
|
+
|
|
51
|
+
const isOptional = (value: unknown, check: (value: unknown) => boolean) =>
|
|
52
|
+
value === undefined || value === null || check(value);
|
|
53
|
+
|
|
54
|
+
const isArrayOf = (value: unknown, check: (item: unknown) => boolean) =>
|
|
55
|
+
Array.isArray(value) && value.every(check);
|
|
56
|
+
|
|
57
|
+
function isAction(value: unknown): value is AgentUiAction {
|
|
58
|
+
if (!isRecord(value)) return false;
|
|
59
|
+
return (
|
|
60
|
+
isString(value.id) &&
|
|
61
|
+
isString(value.label) &&
|
|
62
|
+
isString(value.type) &&
|
|
63
|
+
KNOWN_ACTION_TYPES.has(value.type) &&
|
|
64
|
+
isRecord(value.payload)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isCommerceItem(value: unknown): boolean {
|
|
69
|
+
return (
|
|
70
|
+
isRecord(value) &&
|
|
71
|
+
isString(value.name) &&
|
|
72
|
+
isNumber(value.quantity) &&
|
|
73
|
+
isNumber(value.unitPrice) &&
|
|
74
|
+
isNumber(value.lineTotal)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isVariant(value: unknown): boolean {
|
|
79
|
+
return (
|
|
80
|
+
isRecord(value) &&
|
|
81
|
+
isString(value.id) &&
|
|
82
|
+
isString(value.title) &&
|
|
83
|
+
isNumber(value.price) &&
|
|
84
|
+
isString(value.currency)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function isFormField(value: unknown): boolean {
|
|
89
|
+
return (
|
|
90
|
+
isRecord(value) &&
|
|
91
|
+
isString(value.name) &&
|
|
92
|
+
isString(value.label) &&
|
|
93
|
+
isOptional(value.placeholder, isString) &&
|
|
94
|
+
isOptional(value.value, isString)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isProvider(value: unknown): boolean {
|
|
99
|
+
return isRecord(value) && isString(value.id) && isString(value.name);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isSlot(value: unknown): boolean {
|
|
103
|
+
return (
|
|
104
|
+
isRecord(value) &&
|
|
105
|
+
isString(value.startTime) &&
|
|
106
|
+
isString(value.endTime) &&
|
|
107
|
+
isString(value.slotToken) &&
|
|
108
|
+
isOptional(value.staffUserId, isString)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isDay(value: unknown): boolean {
|
|
113
|
+
return isRecord(value) && isString(value.date) && isArrayOf(value.slots, isSlot);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isValidBlock(block: Record<string, unknown>): boolean {
|
|
117
|
+
switch (block.type) {
|
|
118
|
+
case 'product_service_card': {
|
|
119
|
+
const product = block.product;
|
|
120
|
+
return (
|
|
121
|
+
isRecord(product) &&
|
|
122
|
+
isString(product.name) &&
|
|
123
|
+
isNumber(product.price) &&
|
|
124
|
+
isString(product.currency) &&
|
|
125
|
+
isOptional(product.imageUrl, isString) &&
|
|
126
|
+
isOptional(product.shortDescription, isString) &&
|
|
127
|
+
isOptional(product.description, isString) &&
|
|
128
|
+
isOptional(product.unit, isString) &&
|
|
129
|
+
isOptional(product.durationMinutes, isNumber)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
case 'product_choices':
|
|
133
|
+
return (
|
|
134
|
+
isString(block.productId) &&
|
|
135
|
+
isString(block.title) &&
|
|
136
|
+
Array.isArray(block.variants) &&
|
|
137
|
+
block.variants.length > 0 &&
|
|
138
|
+
block.variants.every(isVariant)
|
|
139
|
+
);
|
|
140
|
+
case 'commerce_actions':
|
|
141
|
+
return isArrayOf(block.actions, isAction);
|
|
142
|
+
case 'cart_order_summary':
|
|
143
|
+
return (
|
|
144
|
+
isString(block.title) &&
|
|
145
|
+
isString(block.currency) &&
|
|
146
|
+
isArrayOf(block.items, isCommerceItem) &&
|
|
147
|
+
isNumber(block.subtotal) &&
|
|
148
|
+
isNumber(block.total) &&
|
|
149
|
+
isOptional(block.discount, isNumber) &&
|
|
150
|
+
isOptional(block.tax, isNumber) &&
|
|
151
|
+
isOptional(block.shipping, isNumber) &&
|
|
152
|
+
isOptional(block.status, isString) &&
|
|
153
|
+
isOptional(block.action, isAction)
|
|
154
|
+
);
|
|
155
|
+
case 'contact_lead_form':
|
|
156
|
+
return (
|
|
157
|
+
isString(block.title) &&
|
|
158
|
+
isString(block.submitLabel) &&
|
|
159
|
+
isOptional(block.description, isString) &&
|
|
160
|
+
Array.isArray(block.fields) &&
|
|
161
|
+
block.fields.length > 0 &&
|
|
162
|
+
block.fields.every(isFormField)
|
|
163
|
+
);
|
|
164
|
+
case 'consent':
|
|
165
|
+
return isString(block.statement) && isArrayOf(block.channels, isString);
|
|
166
|
+
case 'appointment_slot_picker':
|
|
167
|
+
return (
|
|
168
|
+
isString(block.serviceId) &&
|
|
169
|
+
isString(block.serviceName) &&
|
|
170
|
+
isNumber(block.durationMinutes) &&
|
|
171
|
+
isOptional(block.timezone, isString) &&
|
|
172
|
+
isOptional(block.selectedProviderId, isString) &&
|
|
173
|
+
isOptional(block.providers, (value) => isArrayOf(value, isProvider)) &&
|
|
174
|
+
Array.isArray(block.days) &&
|
|
175
|
+
block.days.length > 0 &&
|
|
176
|
+
block.days.every(isDay)
|
|
177
|
+
);
|
|
178
|
+
case 'quote_preview':
|
|
179
|
+
return (
|
|
180
|
+
isString(block.name) &&
|
|
181
|
+
isString(block.currency) &&
|
|
182
|
+
isString(block.status) &&
|
|
183
|
+
isNumber(block.amount) &&
|
|
184
|
+
isOptional(block.serialNumber, isString) &&
|
|
185
|
+
isOptional(block.contactName, isString) &&
|
|
186
|
+
isOptional(block.validUntil, isString) &&
|
|
187
|
+
isOptional(block.actions, (value) => isArrayOf(value, isAction))
|
|
188
|
+
);
|
|
189
|
+
case 'success_receipt':
|
|
190
|
+
return (
|
|
191
|
+
isString(block.title) &&
|
|
192
|
+
isOptional(block.description, isString) &&
|
|
193
|
+
isOptional(block.reference, isString) &&
|
|
194
|
+
isOptional(block.amount, isNumber) &&
|
|
195
|
+
isOptional(block.currency, isString) &&
|
|
196
|
+
isOptional(block.nextActions, (value) => isArrayOf(value, isAction))
|
|
197
|
+
);
|
|
198
|
+
default:
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Drops blocks this SDK version does not know how to render, or whose fields
|
|
205
|
+
* don't match what the renderer reads. Optional lists the server may omit
|
|
206
|
+
* come back as empty arrays.
|
|
207
|
+
*/
|
|
208
|
+
export function parseAgentUiBlocks(value: unknown): AgentUiBlock[] {
|
|
209
|
+
if (!Array.isArray(value)) return [];
|
|
210
|
+
const blocks: AgentUiBlock[] = [];
|
|
211
|
+
for (const block of value) {
|
|
212
|
+
if (!isRecord(block)) continue;
|
|
213
|
+
if (!isString(block.id) || !isString(block.type)) continue;
|
|
214
|
+
if (!KNOWN_BLOCK_TYPES.has(block.type) || !isValidBlock(block)) continue;
|
|
215
|
+
|
|
216
|
+
const normalized =
|
|
217
|
+
block.type === 'appointment_slot_picker'
|
|
218
|
+
? { ...block, providers: block.providers ?? [] }
|
|
219
|
+
: block.type === 'quote_preview'
|
|
220
|
+
? { ...block, actions: block.actions ?? [] }
|
|
221
|
+
: block.type === 'success_receipt'
|
|
222
|
+
? { ...block, nextActions: block.nextActions ?? [] }
|
|
223
|
+
: block;
|
|
224
|
+
blocks.push(normalized as unknown as AgentUiBlock);
|
|
225
|
+
}
|
|
226
|
+
return blocks;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function getAgentUiBlocks(metadata: Record<string, unknown> | null | undefined) {
|
|
230
|
+
if (!isRecord(metadata)) return [];
|
|
231
|
+
return parseAgentUiBlocks(metadata.agentUiBlocks);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function getProcedureForm(
|
|
235
|
+
metadata: Record<string, unknown> | null | undefined
|
|
236
|
+
): AgentProcedureForm | null {
|
|
237
|
+
if (!isRecord(metadata)) return null;
|
|
238
|
+
const form = metadata.agentProcedureForm;
|
|
239
|
+
if (!isRecord(form) || !Array.isArray(form.fields) || form.fields.length === 0) return null;
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
procedureId: typeof form.procedureId === 'string' ? form.procedureId : '',
|
|
243
|
+
procedureName: typeof form.procedureName === 'string' ? form.procedureName : 'Details',
|
|
244
|
+
fields: form.fields
|
|
245
|
+
.filter((field: any) => field && typeof field.name === 'string')
|
|
246
|
+
.map((field: any) => ({
|
|
247
|
+
name: field.name,
|
|
248
|
+
label: typeof field.label === 'string' ? field.label : field.name,
|
|
249
|
+
type: ['email', 'phone', 'date', 'time', 'text'].includes(field.type) ? field.type : 'text',
|
|
250
|
+
required: field.required !== false,
|
|
251
|
+
})),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function formatAgentUiActionMessage(action: AgentUiAction): string {
|
|
256
|
+
const payload = action.payload;
|
|
257
|
+
switch (action.type) {
|
|
258
|
+
case 'add_to_cart':
|
|
259
|
+
return `Add ${String(payload.productName || 'this item')} to my cart${
|
|
260
|
+
payload.variantTitle ? ` (${String(payload.variantTitle)})` : ''
|
|
261
|
+
}.`;
|
|
262
|
+
case 'buy_now':
|
|
263
|
+
if (payload.cartId) return `Create an order from cart ${String(payload.cartId)}.`;
|
|
264
|
+
if (action.module === 'appointments' || payload.productType === 'service') {
|
|
265
|
+
return `Book ${String(payload.productName || 'this service')}${
|
|
266
|
+
payload.variantTitle ? ` (${String(payload.variantTitle)})` : ''
|
|
267
|
+
}.`;
|
|
268
|
+
}
|
|
269
|
+
return `Buy ${String(payload.productName || 'this item')} now${
|
|
270
|
+
payload.variantTitle ? ` (${String(payload.variantTitle)})` : ''
|
|
271
|
+
}.`;
|
|
272
|
+
case 'select_appointment_provider':
|
|
273
|
+
return `Show appointment times for ${String(
|
|
274
|
+
payload.serviceName || 'this service'
|
|
275
|
+
)} with ${String(payload.providerName || 'any available professional')}.`;
|
|
276
|
+
case 'select_appointment_slot':
|
|
277
|
+
return `Book ${String(payload.serviceName || 'this service')} on ${String(
|
|
278
|
+
payload.date || 'the selected date'
|
|
279
|
+
)} at ${String(payload.startTime || 'the selected time')}${
|
|
280
|
+
payload.providerName ? ` with ${String(payload.providerName)}` : ''
|
|
281
|
+
}.`;
|
|
282
|
+
case 'accept_quote':
|
|
283
|
+
return `I accept quote ${String(payload.reference || payload.quoteId || '')}.`.trim();
|
|
284
|
+
case 'record_consent':
|
|
285
|
+
return `I consent to being contacted by ${
|
|
286
|
+
Array.isArray(payload.channels) ? payload.channels.join(', ') : 'the selected channel'
|
|
287
|
+
}.`;
|
|
288
|
+
case 'open_record':
|
|
289
|
+
return action.label;
|
|
290
|
+
case 'submit_contact':
|
|
291
|
+
return (
|
|
292
|
+
Object.entries(payload)
|
|
293
|
+
.filter(([, value]) => typeof value === 'string' && value.trim())
|
|
294
|
+
.map(([key, value]) => `${key}: ${String(value).trim()}`)
|
|
295
|
+
.join('\n') || 'I have submitted my contact details.'
|
|
296
|
+
);
|
|
297
|
+
case 'next_action':
|
|
298
|
+
return action.label;
|
|
299
|
+
default:
|
|
300
|
+
return action.label;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch client for `/api/widget/*`.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the web widget's `client/src/widget/lib/api.ts`, with
|
|
5
|
+
* localStorage swapped for the storage adapter and EventSource moved to
|
|
6
|
+
* `api/realtime.ts`. Visitor tokens live up to 14 days with no refresh, so a
|
|
7
|
+
* 401 triggers one silent re-init + retry (single-flight, owned by the store).
|
|
8
|
+
* The token itself lives in `SecureStorage`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { SecureStorage, TOKEN_KEY } from '../storage';
|
|
12
|
+
import type {
|
|
13
|
+
AgentUiAction,
|
|
14
|
+
Conversation,
|
|
15
|
+
InitResponse,
|
|
16
|
+
Message,
|
|
17
|
+
OutboundMessage,
|
|
18
|
+
RepzoWidgetErrorCode,
|
|
19
|
+
WidgetAttachment,
|
|
20
|
+
WidgetConfig,
|
|
21
|
+
WidgetUser,
|
|
22
|
+
} from '../types';
|
|
23
|
+
import { isHttpUrl, urlScheme } from '../ui/utils/safe-url';
|
|
24
|
+
|
|
25
|
+
/** Server `code`s that no retry or re-init can fix. */
|
|
26
|
+
const TERMINAL_CODES = new Set<RepzoWidgetErrorCode>([
|
|
27
|
+
'messenger_api_disabled',
|
|
28
|
+
'identity_verification_failed',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export function isTerminalErrorCode(code: string | null | undefined): boolean {
|
|
32
|
+
return !!code && TERMINAL_CODES.has(code as RepzoWidgetErrorCode);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class RepzoWidgetError extends Error {
|
|
36
|
+
readonly status: number;
|
|
37
|
+
|
|
38
|
+
readonly code: RepzoWidgetErrorCode;
|
|
39
|
+
|
|
40
|
+
constructor(message: string, status: number, code: RepzoWidgetErrorCode = 'http') {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'RepzoWidgetError';
|
|
43
|
+
this.status = status;
|
|
44
|
+
this.code = code;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Builds the error for a non-2xx `{ message, code }` body. */
|
|
48
|
+
static fromResponse(status: number, body: unknown): RepzoWidgetError {
|
|
49
|
+
const payload = (body && typeof body === 'object' ? body : {}) as {
|
|
50
|
+
message?: unknown;
|
|
51
|
+
code?: unknown;
|
|
52
|
+
};
|
|
53
|
+
const message = typeof payload.message === 'string' && payload.message ? payload.message : null;
|
|
54
|
+
const code =
|
|
55
|
+
status === 403 && typeof payload.code === 'string' && isTerminalErrorCode(payload.code)
|
|
56
|
+
? (payload.code as RepzoWidgetErrorCode)
|
|
57
|
+
: 'http';
|
|
58
|
+
return new RepzoWidgetError(message || `HTTP ${status}`, status, code);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface RequestOptions {
|
|
63
|
+
method?: 'GET' | 'POST' | 'DELETE';
|
|
64
|
+
body?: unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Never re-init on 401: set for init itself (so a 401 never recurses) and
|
|
67
|
+
* for logout-time calls, which must not mint a session for a signed-out user.
|
|
68
|
+
*/
|
|
69
|
+
skipReauth?: boolean;
|
|
70
|
+
/** Authenticate with this token instead of the stored one (logout). */
|
|
71
|
+
authToken?: string | null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class WidgetApiClient {
|
|
75
|
+
private baseUrl = '';
|
|
76
|
+
|
|
77
|
+
private channelAccountId = '';
|
|
78
|
+
|
|
79
|
+
private token: string | null = null;
|
|
80
|
+
|
|
81
|
+
private tokenLoaded = false;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Set by the store: given the token that just got a 401, returns a valid
|
|
85
|
+
* token (fresh, or one another caller already minted), or null.
|
|
86
|
+
*/
|
|
87
|
+
reauthorize: ((failedToken: string | null) => Promise<string | null>) | null = null;
|
|
88
|
+
|
|
89
|
+
/** Set by the store: a 403 with a terminal `code` came back from any endpoint. */
|
|
90
|
+
onTerminalError: ((error: RepzoWidgetError) => void) | null = null;
|
|
91
|
+
|
|
92
|
+
configure(baseUrl: string, channelAccountId: string) {
|
|
93
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
94
|
+
this.channelAccountId = channelAccountId;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getBaseUrl(): string {
|
|
98
|
+
return this.baseUrl;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getChannelAccountId(): string {
|
|
102
|
+
return this.channelAccountId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async getToken(): Promise<string | null> {
|
|
106
|
+
if (this.token) return this.token;
|
|
107
|
+
if (!this.tokenLoaded) {
|
|
108
|
+
this.tokenLoaded = true;
|
|
109
|
+
this.token = await SecureStorage.getItem(TOKEN_KEY);
|
|
110
|
+
}
|
|
111
|
+
return this.token;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async setToken(token: string): Promise<void> {
|
|
115
|
+
this.token = token;
|
|
116
|
+
this.tokenLoaded = true;
|
|
117
|
+
await SecureStorage.setItem(TOKEN_KEY, token);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async clearToken(): Promise<void> {
|
|
121
|
+
this.token = null;
|
|
122
|
+
this.tokenLoaded = true;
|
|
123
|
+
await SecureStorage.removeItem(TOKEN_KEY);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Absolute URL for a server media path (avatars, attachments). Only ever
|
|
128
|
+
* returns `http(s)` — relative paths resolve against `baseUrl`; any other
|
|
129
|
+
* scheme (`file:`, `data:`, `intent:`, host deep links…) yields null.
|
|
130
|
+
*/
|
|
131
|
+
resolveUrl(url: string | null | undefined): string | null {
|
|
132
|
+
const trimmed = url?.trim();
|
|
133
|
+
if (!trimmed) return null;
|
|
134
|
+
if (isHttpUrl(trimmed)) return trimmed;
|
|
135
|
+
if (urlScheme(trimmed)) return null;
|
|
136
|
+
const resolved = `${this.baseUrl}${trimmed.startsWith('/') ? '' : '/'}${trimmed}`;
|
|
137
|
+
return isHttpUrl(resolved) ? resolved : null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
|
|
141
|
+
let sentToken: string | null = null;
|
|
142
|
+
|
|
143
|
+
const send = async (): Promise<Response> => {
|
|
144
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
145
|
+
const token = options.authToken !== undefined ? options.authToken : await this.getToken();
|
|
146
|
+
sentToken = token;
|
|
147
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
return await fetch(`${this.baseUrl}${path}`, {
|
|
151
|
+
method: options.method ?? 'GET',
|
|
152
|
+
headers,
|
|
153
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
154
|
+
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new RepzoWidgetError(
|
|
157
|
+
error instanceof Error ? error.message : 'Network request failed',
|
|
158
|
+
0,
|
|
159
|
+
'network'
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let response = await send();
|
|
165
|
+
|
|
166
|
+
// The token expired or was revoked: mint a new session once.
|
|
167
|
+
if (response.status === 401 && !options.skipReauth && this.reauthorize) {
|
|
168
|
+
const refreshed = await this.reauthorize(sentToken);
|
|
169
|
+
if (refreshed) response = await send();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
const body = await response.json().catch(() => null);
|
|
174
|
+
const error = RepzoWidgetError.fromResponse(response.status, body);
|
|
175
|
+
// skipReauth calls (init, logout-time) are handled by their caller,
|
|
176
|
+
// which knows whether the result is still current.
|
|
177
|
+
if (isTerminalErrorCode(error.code) && !options.skipReauth) this.onTerminalError?.(error);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (response.status === 204) return undefined as T;
|
|
182
|
+
return (await response.json()) as T;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ─── Endpoints ────────────────────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
/** Public config. `platform` makes the server apply the Mobile SDKs overrides. */
|
|
188
|
+
getConfig(platform?: 'ios' | 'android' | 'web'): Promise<WidgetConfig> {
|
|
189
|
+
const query = platform ? `?platform=${encodeURIComponent(platform)}` : '';
|
|
190
|
+
return this.request(`/api/widget/config/${encodeURIComponent(this.channelAccountId)}${query}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getOutboundMessage(): Promise<{ message: OutboundMessage | null }> {
|
|
194
|
+
return this.request(`/api/widget/outbound/${encodeURIComponent(this.channelAccountId)}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Does NOT store the returned token — the store persists it only once it
|
|
199
|
+
* knows the identity op that asked for it is still current.
|
|
200
|
+
*/
|
|
201
|
+
async init(params: {
|
|
202
|
+
user?: WidgetUser;
|
|
203
|
+
trackingVisitorId?: string;
|
|
204
|
+
platform?: string;
|
|
205
|
+
sdkVersion?: string;
|
|
206
|
+
/** False for fresh sessions — never resume another identity's token. */
|
|
207
|
+
resumeToken?: boolean;
|
|
208
|
+
}): Promise<InitResponse> {
|
|
209
|
+
const visitorToken = params.resumeToken === false ? null : await this.getToken();
|
|
210
|
+
const user = params.user
|
|
211
|
+
? {
|
|
212
|
+
...(params.user.email ? { email: params.user.email } : {}),
|
|
213
|
+
...(params.user.name ? { name: params.user.name } : {}),
|
|
214
|
+
...(params.user.phone ? { phone: params.user.phone } : {}),
|
|
215
|
+
...(params.user.userId ? { user_id: params.user.userId } : {}),
|
|
216
|
+
...(params.user.userHash ? { user_hash: params.user.userHash } : {}),
|
|
217
|
+
}
|
|
218
|
+
: undefined;
|
|
219
|
+
|
|
220
|
+
return this.request<InitResponse>('/api/widget/init', {
|
|
221
|
+
method: 'POST',
|
|
222
|
+
skipReauth: true,
|
|
223
|
+
body: {
|
|
224
|
+
channelAccountId: this.channelAccountId,
|
|
225
|
+
visitorToken,
|
|
226
|
+
trackingVisitorId: params.trackingVisitorId,
|
|
227
|
+
platform: params.platform,
|
|
228
|
+
sdkVersion: params.sdkVersion,
|
|
229
|
+
...(user ? { user } : {}),
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Revokes `token` server-side. A 401 means it was already dead — fine. */
|
|
235
|
+
async logout(token: string): Promise<void> {
|
|
236
|
+
try {
|
|
237
|
+
await this.request('/api/widget/logout', {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
skipReauth: true,
|
|
240
|
+
authToken: token,
|
|
241
|
+
});
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error instanceof RepzoWidgetError && error.status === 401) return;
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
sendMessage(data: {
|
|
249
|
+
conversationId?: string;
|
|
250
|
+
forceNewConversation?: boolean;
|
|
251
|
+
body: string;
|
|
252
|
+
attachments?: WidgetAttachment[];
|
|
253
|
+
visitorName?: string;
|
|
254
|
+
visitorEmail?: string;
|
|
255
|
+
agentUiAction?: AgentUiAction;
|
|
256
|
+
}): Promise<{ messageId: string; conversationId: string; isNewConversation: boolean }> {
|
|
257
|
+
return this.request('/api/widget/messages', { method: 'POST', body: data });
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
listConversations(): Promise<{ data: Conversation[] }> {
|
|
261
|
+
return this.request('/api/widget/conversations');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
listMessages(
|
|
265
|
+
conversationId: string,
|
|
266
|
+
cursor?: string | null
|
|
267
|
+
): Promise<{ data: Message[]; meta: { hasMore: boolean; nextCursor: string | null } }> {
|
|
268
|
+
const query = cursor ? `?cursor=${encodeURIComponent(cursor)}` : '';
|
|
269
|
+
return this.request(
|
|
270
|
+
`/api/widget/conversations/${encodeURIComponent(conversationId)}/messages${query}`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Advances the visitor's read cursor for a thread they're watching live.
|
|
276
|
+
* Best effort and `skipReauth`: a burst of live replies must never turn an
|
|
277
|
+
* expired token into a burst of re-inits.
|
|
278
|
+
*/
|
|
279
|
+
markConversationRead(conversationId: string): Promise<void> {
|
|
280
|
+
return this.request(
|
|
281
|
+
`/api/widget/conversations/${encodeURIComponent(conversationId)}/read`,
|
|
282
|
+
{ method: 'POST', skipReauth: true }
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
identify(data: {
|
|
287
|
+
email?: string;
|
|
288
|
+
name?: string;
|
|
289
|
+
phone?: string;
|
|
290
|
+
customAttributes?: Record<string, string | number | boolean>;
|
|
291
|
+
}): Promise<void> {
|
|
292
|
+
return this.request('/api/widget/identify', { method: 'POST', body: data });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
sendTyping(conversationId: string, isTyping: boolean): Promise<void> {
|
|
296
|
+
return this.request('/api/widget/typing', {
|
|
297
|
+
method: 'POST',
|
|
298
|
+
body: { conversationId, isTyping },
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
trackEvent(data: {
|
|
303
|
+
event: string;
|
|
304
|
+
visitorId?: string | null;
|
|
305
|
+
metadata?: Record<string, unknown>;
|
|
306
|
+
}): Promise<void> {
|
|
307
|
+
return this.request('/api/widget/events', {
|
|
308
|
+
method: 'POST',
|
|
309
|
+
body: { ...data, channelAccountId: this.channelAccountId },
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
registerPushToken(data: {
|
|
314
|
+
token: string;
|
|
315
|
+
platform: string;
|
|
316
|
+
bundleId?: string;
|
|
317
|
+
}): Promise<void> {
|
|
318
|
+
return this.request('/api/widget/push-token', { method: 'POST', body: data });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Logout passes the session's token explicitly and `skipReauth`. */
|
|
322
|
+
removePushToken(
|
|
323
|
+
token: string,
|
|
324
|
+
auth: { authToken?: string | null; skipReauth?: boolean } = {}
|
|
325
|
+
): Promise<void> {
|
|
326
|
+
return this.request('/api/widget/push-token', {
|
|
327
|
+
method: 'DELETE',
|
|
328
|
+
body: { token },
|
|
329
|
+
...auth,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|