@lorikeetai/react-native-sdk 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 ADDED
@@ -0,0 +1,81 @@
1
+ # @lorikeetai/react-native-sdk
2
+
3
+ SDK containing embeddable React Native components that renders the LorikeetCX web widget inside a react-native-webview.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @lorikeetai/react-native-sdk
9
+ ```
10
+
11
+ ## Basic Usage
12
+
13
+ ```tsx
14
+ import { LorikeetWidgetView } from '@lorikeetai/react-native-sdk'
15
+
16
+ export default function Screen() {
17
+ return (
18
+ <LorikeetWidgetView
19
+ publicKey="wk_xxx"
20
+ authToken="your-auth-token"
21
+ onWebViewMessage={(event) => console.log(event.nativeEvent.data)}
22
+ />
23
+ )
24
+ }
25
+ ```
26
+
27
+ **Props:**
28
+
29
+ - `publicKey` (required): The public key for your Lorikeet account
30
+ - `authToken` (required): Authentication token for the user
31
+ - `baseUrl` (optional): Base URL for the Lorikeet API (defaults to `https://chat.lorikeetcx.ai`)
32
+ - `customisations` (optional): Widget customization options from `@lorikeetai/web-sdk`
33
+ - `styles` (optional): Style overrides for the header text
34
+ - `onWebViewMessage` (optional): Handler for messages from the webview
35
+
36
+ ## Headless components
37
+
38
+ You may use these if you want to compose the lorikeet widget itself. It comprises of 2 components - the widget view & header view - which are rolled up together in 'LorikeetWidgetView'.
39
+
40
+ ### LorikeetWidgetHeader
41
+
42
+ Header component for the widget.
43
+
44
+ ```tsx
45
+ <LorikeetWidgetHeader title='Testing' style={{ fontFamily: 'Inter' ... }} />
46
+ ```
47
+
48
+ **Props:**
49
+
50
+ - `title` (required): The title text to display
51
+ - `style` (optional): Style for the header text
52
+
53
+ ### LorikeetWidgetWebView
54
+
55
+ WebView component that handles the widget content.
56
+
57
+ ```tsx
58
+ <LorikeetWidgetWebView
59
+ uri={url}
60
+ webviewProps={{
61
+ scalesPageToFit: true,
62
+ startInLoadingState: true,
63
+ style: ...
64
+ }}
65
+ />
66
+ ```
67
+
68
+ **Props:**
69
+
70
+ - `uri` (required): The URI that the web view will load
71
+ - `baseUrl` (optional): Base URL for the Lorikeet API (defaults to `https://chat.lorikeetcx.ai`)
72
+ - `webviewProps` (optional): Passed through to the webview component
73
+
74
+ ## Development
75
+
76
+ - Build: `pnpm -w turbo build --filter=@lorikeetai/react-native-sdk`
77
+ - Lint: `pnpm --filter=@lorikeetai/react-native-sdk lint`
78
+
79
+ ## License
80
+
81
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var lucideReactNative = require('lucide-react-native');
5
+ var reactNative = require('react-native');
6
+ var reactNativeSafeAreaContext = require('react-native-safe-area-context');
7
+ var reactNativeWebview = require('react-native-webview');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+
14
+ // src/client.ts
15
+ var LorikeetClient = class {
16
+ constructor({ customisations, api_base, public_key }) {
17
+ __publicField(this, "baseUrl", "https://chat.lorikeetcx.ai");
18
+ // Fallback URL
19
+ __publicField(this, "customisations", null);
20
+ __publicField(this, "publicKey");
21
+ __publicField(this, "getWebviewUrl", ({
22
+ customer_email,
23
+ customer_name,
24
+ token,
25
+ ticket_id
26
+ }) => {
27
+ const url = new URL(this.baseUrl);
28
+ url.pathname = ticket_id ? `/tickets/${this.publicKey}/${ticket_id}` : "/widget";
29
+ url.searchParams.append("public_key", this.publicKey);
30
+ if (customer_email) {
31
+ url.searchParams.append("customer_email", customer_email);
32
+ }
33
+ if (customer_name) {
34
+ url.searchParams.append("customer_name", customer_name);
35
+ }
36
+ url.searchParams.append("token", token);
37
+ if (this.customisations) {
38
+ url.searchParams.append(
39
+ "customisations",
40
+ btoa(JSON.stringify(this.customisations))
41
+ );
42
+ }
43
+ return url.toString();
44
+ });
45
+ if (api_base) {
46
+ this.baseUrl = api_base;
47
+ }
48
+ this.publicKey = public_key;
49
+ if (customisations) {
50
+ this.customisations = customisations;
51
+ }
52
+ }
53
+ };
54
+ var stylesheet = reactNative.StyleSheet.create({
55
+ root: { flex: 1, backgroundColor: "#fff" },
56
+ container: {
57
+ flex: 1,
58
+ borderRadius: 8,
59
+ overflow: "hidden",
60
+ shadowColor: "#000",
61
+ shadowOffset: { width: 0, height: 2 },
62
+ shadowOpacity: 0.1,
63
+ shadowRadius: 4,
64
+ elevation: 3
65
+ },
66
+ header: {
67
+ padding: 16,
68
+ justifyContent: "center"
69
+ },
70
+ headerText: {
71
+ textAlign: "center",
72
+ fontSize: 16
73
+ },
74
+ webView: {
75
+ flex: 1
76
+ }
77
+ });
78
+ var LorikeetWidgetWebView = ({
79
+ uri,
80
+ baseUrl = "https://chat.lorikeetcx.ai",
81
+ webviewProps = {}
82
+ }) => {
83
+ return /* @__PURE__ */ jsxRuntime.jsx(
84
+ reactNativeWebview.WebView,
85
+ {
86
+ ...webviewProps,
87
+ onNavigationStateChange: (navState) => {
88
+ if (navState.url.includes(baseUrl)) {
89
+ return false;
90
+ } else {
91
+ void reactNative.Linking.openURL(navState.url);
92
+ return false;
93
+ }
94
+ },
95
+ source: {
96
+ uri
97
+ },
98
+ style: stylesheet.webView
99
+ }
100
+ );
101
+ };
102
+ var LorikeetWidgetHeader = ({
103
+ title,
104
+ style,
105
+ icon = /* @__PURE__ */ jsxRuntime.jsx(lucideReactNative.MessageCirclePlusIcon, {})
106
+ }) => {
107
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: stylesheet.header, children: [
108
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [stylesheet.headerText, style], children: title }),
109
+ icon
110
+ ] });
111
+ };
112
+ function LorikeetWidgetView({
113
+ publicKey,
114
+ baseUrl,
115
+ authToken,
116
+ customisations,
117
+ styles,
118
+ onWebViewMessage
119
+ }) {
120
+ var _a;
121
+ const [lorikeetClient, setLorikeetClient] = react.useState(
122
+ null
123
+ );
124
+ react.useEffect(() => {
125
+ const lorikeetClient2 = new LorikeetClient({
126
+ public_key: publicKey,
127
+ api_base: baseUrl,
128
+ customisations: {
129
+ ...customisations,
130
+ hideHeader: (customisations == null ? void 0 : customisations.hideHeader) === void 0 ? true : customisations.hideHeader
131
+ }
132
+ });
133
+ setLorikeetClient(lorikeetClient2);
134
+ }, [publicKey, baseUrl]);
135
+ if (!lorikeetClient) {
136
+ return null;
137
+ }
138
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNativeSafeAreaContext.SafeAreaView, { edges: ["top", "left", "right"], style: stylesheet.root, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: stylesheet.container, children: [
139
+ /* @__PURE__ */ jsxRuntime.jsx(
140
+ LorikeetWidgetHeader,
141
+ {
142
+ style: styles == null ? void 0 : styles.header,
143
+ title: (_a = customisations == null ? void 0 : customisations.title) != null ? _a : "Lorikeet AI Agent"
144
+ }
145
+ ),
146
+ /* @__PURE__ */ jsxRuntime.jsx(
147
+ LorikeetWidgetWebView,
148
+ {
149
+ baseUrl: lorikeetClient.baseUrl,
150
+ uri: lorikeetClient.getWebviewUrl({
151
+ token: authToken
152
+ }),
153
+ webviewProps: {
154
+ onMessage: onWebViewMessage,
155
+ allowsInlineMediaPlayback: true,
156
+ mediaPlaybackRequiresUserAction: false,
157
+ scalesPageToFit: true,
158
+ startInLoadingState: true,
159
+ style: stylesheet.webView
160
+ }
161
+ }
162
+ )
163
+ ] }) });
164
+ }
165
+
166
+ exports.LorikeetClient = LorikeetClient;
167
+ exports.LorikeetWidgetHeader = LorikeetWidgetHeader;
168
+ exports.LorikeetWidgetView = LorikeetWidgetView;
169
+ exports.LorikeetWidgetWebView = LorikeetWidgetWebView;
170
+ //# sourceMappingURL=index.cjs.map
171
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/widget.tsx"],"names":["StyleSheet","jsx","WebView","Linking","MessageCirclePlusIcon","jsxs","View","Text","useState","useEffect","lorikeetClient","SafeAreaView"],"mappings":";;;;;;;;;;;;;;AAIO,IAAM,iBAAN,MAAqB;AAAA,EAK1B,WAAY,CAAA,EAAE,cAAgB,EAAA,QAAA,EAAU,YAAmC,EAAA;AAJ3E,IAAkB,aAAA,CAAA,IAAA,EAAA,SAAA,EAAA,4BAAA,CAAA,CAAA;AAClB;AAAA,IAAwC,aAAA,CAAA,IAAA,EAAA,gBAAA,EAAA,IAAA,CAAA,CAAA;AACxC,IAAA,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA,CAAA;AAaA,IAAA,aAAA,CAAA,IAAA,EAAA,eAAA,EAAgB,CAAC;AAAA,MACf,cAAA;AAAA,MACA,aAAA;AAAA,MACA,KAAA;AAAA,MACA,SAAA;AAAA,KAMI,KAAA;AACJ,MAAA,MAAM,GAAM,GAAA,IAAI,GAAI,CAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAEhC,MAAA,GAAA,CAAI,WAAW,SACX,GAAA,CAAA,SAAA,EAAY,KAAK,SAAS,CAAA,CAAA,EAAI,SAAS,CACvC,CAAA,GAAA,SAAA,CAAA;AACJ,MAAA,GAAA,CAAI,YAAa,CAAA,MAAA,CAAO,YAAc,EAAA,IAAA,CAAK,SAAS,CAAA,CAAA;AAEpD,MAAA,IAAI,cAAgB,EAAA;AAClB,QAAI,GAAA,CAAA,YAAA,CAAa,MAAO,CAAA,gBAAA,EAAkB,cAAc,CAAA,CAAA;AAAA,OAC1D;AACA,MAAA,IAAI,aAAe,EAAA;AACjB,QAAI,GAAA,CAAA,YAAA,CAAa,MAAO,CAAA,eAAA,EAAiB,aAAa,CAAA,CAAA;AAAA,OACxD;AAEA,MAAI,GAAA,CAAA,YAAA,CAAa,MAAO,CAAA,OAAA,EAAS,KAAK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AA,OAAA;AAAA,QACxB,GAAA,EAAK,eAAe,aAAc,CAAA;AAAA,UAChC,KAAO,EAAA,SAAA;AAAA,SACR,CAAA;AAAA,QACD,YAAc,EAAA;AAAA,UACZ,SAAW,EAAA,gBAAA;AAAA,UACX,yBAA2B,EAAA,IAAA;AAAA,UAC3B,+BAAiC,EAAA,KAAA;AAAA,UACjC,eAAiB,EAAA,IAAA;AAAA,UACjB,mBAAqB,EAAA,IAAA;AAAA,UACrB,OAAO,UAAW,CAAA,OAAA;AAAA,SACpB;AAAA,OAAA;AAAA,KACF;AAAA,GAAA,EACF,CACF,EAAA,CAAA,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import type { Customisations } from '@lorikeetai/web-sdk/types'\n\nimport type { LorikeetInitOptions } from './types'\n\nexport class LorikeetClient {\n baseUrl: string = 'https://chat.lorikeetcx.ai' // Fallback URL\n customisations: Customisations | null = null\n publicKey: string\n\n constructor({ customisations, api_base, public_key }: LorikeetInitOptions) {\n if (api_base) {\n this.baseUrl = api_base\n }\n this.publicKey = public_key\n\n if (customisations) {\n this.customisations = customisations\n }\n }\n\n getWebviewUrl = ({\n customer_email,\n customer_name,\n token,\n ticket_id,\n }: {\n customer_email?: string\n customer_name?: string\n token: string\n ticket_id?: string\n }) => {\n const url = new URL(this.baseUrl)\n\n url.pathname = ticket_id\n ? `/tickets/${this.publicKey}/${ticket_id}`\n : '/widget'\n url.searchParams.append('public_key', this.publicKey)\n\n if (customer_email) {\n url.searchParams.append('customer_email', customer_email)\n }\n if (customer_name) {\n url.searchParams.append('customer_name', customer_name)\n }\n\n url.searchParams.append('token', token)\n\n if (this.customisations) {\n url.searchParams.append(\n 'customisations',\n btoa(JSON.stringify(this.customisations)),\n )\n }\n\n return url.toString()\n }\n}\n","import { useEffect, useState } from 'react'\n\nimport { MessageCirclePlusIcon } from 'lucide-react-native'\nimport { Linking, StyleSheet, Text, View } from 'react-native'\nimport { SafeAreaView } from 'react-native-safe-area-context'\nimport { WebView } from 'react-native-webview'\n\nimport { LorikeetClient } from './client'\nimport type {\n LorikeetWidgetHeaderProps,\n LorikeetWidgetViewProps,\n LorikeetWidgetWebViewProps,\n} from './types'\n\nconst stylesheet = StyleSheet.create({\n root: { flex: 1, backgroundColor: '#fff' },\n container: {\n flex: 1,\n borderRadius: 8,\n overflow: 'hidden',\n shadowColor: '#000',\n shadowOffset: { width: 0, height: 2 },\n shadowOpacity: 0.1,\n shadowRadius: 4,\n elevation: 3,\n },\n header: {\n padding: 16,\n justifyContent: 'center',\n },\n headerText: {\n textAlign: 'center',\n fontSize: 16,\n },\n webView: {\n flex: 1,\n },\n})\n\nexport const LorikeetWidgetWebView = ({\n uri,\n baseUrl = 'https://chat.lorikeetcx.ai',\n webviewProps = {},\n}: LorikeetWidgetWebViewProps) => {\n return (\n <WebView\n {...webviewProps}\n onNavigationStateChange={(navState) => {\n if (navState.url.includes(baseUrl)) {\n return false\n } else {\n void Linking.openURL(navState.url)\n return false\n }\n }}\n source={{\n uri,\n }}\n style={stylesheet.webView}\n />\n )\n}\n\nexport const LorikeetWidgetHeader = ({\n title,\n style,\n icon = <MessageCirclePlusIcon />,\n}: LorikeetWidgetHeaderProps) => {\n return (\n <View style={stylesheet.header}>\n <Text style={[stylesheet.headerText, style]}>{title}</Text>\n {icon}\n </View>\n )\n}\n\nexport function LorikeetWidgetView({\n publicKey,\n baseUrl,\n authToken,\n customisations,\n styles,\n onWebViewMessage,\n}: LorikeetWidgetViewProps) {\n const [lorikeetClient, setLorikeetClient] = useState<LorikeetClient | null>(\n null,\n )\n\n useEffect(() => {\n const lorikeetClient = new LorikeetClient({\n public_key: publicKey,\n api_base: baseUrl,\n customisations: {\n ...customisations,\n hideHeader:\n customisations?.hideHeader === undefined\n ? true\n : customisations.hideHeader,\n },\n })\n setLorikeetClient(lorikeetClient)\n }, [publicKey, baseUrl])\n\n if (!lorikeetClient) {\n return null\n }\n\n return (\n <SafeAreaView edges={['top', 'left', 'right']} style={stylesheet.root}>\n <View style={stylesheet.container}>\n <LorikeetWidgetHeader\n style={styles?.header}\n title={customisations?.title ?? 'Lorikeet AI Agent'}\n />\n <LorikeetWidgetWebView\n baseUrl={lorikeetClient.baseUrl}\n uri={lorikeetClient.getWebviewUrl({\n token: authToken,\n })}\n webviewProps={{\n onMessage: onWebViewMessage,\n allowsInlineMediaPlayback: true,\n mediaPlaybackRequiresUserAction: false,\n scalesPageToFit: true,\n startInLoadingState: true,\n style: stylesheet.webView,\n }}\n />\n </View>\n </SafeAreaView>\n )\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Customisations } from '@lorikeetai/web-sdk/types';
3
+ import { StyleProp, TextStyle } from 'react-native';
4
+ import { WebViewProps, WebViewMessageEvent } from 'react-native-webview';
5
+
6
+ interface LorikeetInitOptions {
7
+ api_base?: string;
8
+ customisations?: Customisations;
9
+ public_key: string;
10
+ }
11
+ type LorikeetWidgetWebViewProps = {
12
+ uri: string;
13
+ baseUrl?: string;
14
+ webviewProps?: WebViewProps;
15
+ };
16
+ type LorikeetWidgetHeaderProps = {
17
+ title: string;
18
+ style?: StyleProp<TextStyle>;
19
+ icon?: React.ReactNode;
20
+ };
21
+ type LorikeetWidgetViewProps = {
22
+ publicKey: string;
23
+ baseUrl?: string;
24
+ authToken: string;
25
+ onWebViewMessage?: (event: WebViewMessageEvent) => void;
26
+ customisations?: Customisations;
27
+ styles?: {
28
+ header?: StyleProp<TextStyle>;
29
+ };
30
+ };
31
+
32
+ declare const LorikeetWidgetWebView: ({ uri, baseUrl, webviewProps, }: LorikeetWidgetWebViewProps) => react_jsx_runtime.JSX.Element;
33
+ declare const LorikeetWidgetHeader: ({ title, style, icon, }: LorikeetWidgetHeaderProps) => react_jsx_runtime.JSX.Element;
34
+ declare function LorikeetWidgetView({ publicKey, baseUrl, authToken, customisations, styles, onWebViewMessage, }: LorikeetWidgetViewProps): react_jsx_runtime.JSX.Element | null;
35
+
36
+ declare class LorikeetClient {
37
+ baseUrl: string;
38
+ customisations: Customisations | null;
39
+ publicKey: string;
40
+ constructor({ customisations, api_base, public_key }: LorikeetInitOptions);
41
+ getWebviewUrl: ({ customer_email, customer_name, token, ticket_id, }: {
42
+ customer_email?: string;
43
+ customer_name?: string;
44
+ token: string;
45
+ ticket_id?: string;
46
+ }) => string;
47
+ }
48
+
49
+ export { LorikeetClient, type LorikeetInitOptions, LorikeetWidgetHeader, type LorikeetWidgetHeaderProps, LorikeetWidgetView, type LorikeetWidgetViewProps, LorikeetWidgetWebView, type LorikeetWidgetWebViewProps };
@@ -0,0 +1,49 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Customisations } from '@lorikeetai/web-sdk/types';
3
+ import { StyleProp, TextStyle } from 'react-native';
4
+ import { WebViewProps, WebViewMessageEvent } from 'react-native-webview';
5
+
6
+ interface LorikeetInitOptions {
7
+ api_base?: string;
8
+ customisations?: Customisations;
9
+ public_key: string;
10
+ }
11
+ type LorikeetWidgetWebViewProps = {
12
+ uri: string;
13
+ baseUrl?: string;
14
+ webviewProps?: WebViewProps;
15
+ };
16
+ type LorikeetWidgetHeaderProps = {
17
+ title: string;
18
+ style?: StyleProp<TextStyle>;
19
+ icon?: React.ReactNode;
20
+ };
21
+ type LorikeetWidgetViewProps = {
22
+ publicKey: string;
23
+ baseUrl?: string;
24
+ authToken: string;
25
+ onWebViewMessage?: (event: WebViewMessageEvent) => void;
26
+ customisations?: Customisations;
27
+ styles?: {
28
+ header?: StyleProp<TextStyle>;
29
+ };
30
+ };
31
+
32
+ declare const LorikeetWidgetWebView: ({ uri, baseUrl, webviewProps, }: LorikeetWidgetWebViewProps) => react_jsx_runtime.JSX.Element;
33
+ declare const LorikeetWidgetHeader: ({ title, style, icon, }: LorikeetWidgetHeaderProps) => react_jsx_runtime.JSX.Element;
34
+ declare function LorikeetWidgetView({ publicKey, baseUrl, authToken, customisations, styles, onWebViewMessage, }: LorikeetWidgetViewProps): react_jsx_runtime.JSX.Element | null;
35
+
36
+ declare class LorikeetClient {
37
+ baseUrl: string;
38
+ customisations: Customisations | null;
39
+ publicKey: string;
40
+ constructor({ customisations, api_base, public_key }: LorikeetInitOptions);
41
+ getWebviewUrl: ({ customer_email, customer_name, token, ticket_id, }: {
42
+ customer_email?: string;
43
+ customer_name?: string;
44
+ token: string;
45
+ ticket_id?: string;
46
+ }) => string;
47
+ }
48
+
49
+ export { LorikeetClient, type LorikeetInitOptions, LorikeetWidgetHeader, type LorikeetWidgetHeaderProps, LorikeetWidgetView, type LorikeetWidgetViewProps, LorikeetWidgetWebView, type LorikeetWidgetWebViewProps };
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { MessageCirclePlusIcon } from 'lucide-react-native';
3
+ import { StyleSheet, Linking, View, Text } from 'react-native';
4
+ import { SafeAreaView } from 'react-native-safe-area-context';
5
+ import { WebView } from 'react-native-webview';
6
+ import { jsx, jsxs } from 'react/jsx-runtime';
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+
12
+ // src/client.ts
13
+ var LorikeetClient = class {
14
+ constructor({ customisations, api_base, public_key }) {
15
+ __publicField(this, "baseUrl", "https://chat.lorikeetcx.ai");
16
+ // Fallback URL
17
+ __publicField(this, "customisations", null);
18
+ __publicField(this, "publicKey");
19
+ __publicField(this, "getWebviewUrl", ({
20
+ customer_email,
21
+ customer_name,
22
+ token,
23
+ ticket_id
24
+ }) => {
25
+ const url = new URL(this.baseUrl);
26
+ url.pathname = ticket_id ? `/tickets/${this.publicKey}/${ticket_id}` : "/widget";
27
+ url.searchParams.append("public_key", this.publicKey);
28
+ if (customer_email) {
29
+ url.searchParams.append("customer_email", customer_email);
30
+ }
31
+ if (customer_name) {
32
+ url.searchParams.append("customer_name", customer_name);
33
+ }
34
+ url.searchParams.append("token", token);
35
+ if (this.customisations) {
36
+ url.searchParams.append(
37
+ "customisations",
38
+ btoa(JSON.stringify(this.customisations))
39
+ );
40
+ }
41
+ return url.toString();
42
+ });
43
+ if (api_base) {
44
+ this.baseUrl = api_base;
45
+ }
46
+ this.publicKey = public_key;
47
+ if (customisations) {
48
+ this.customisations = customisations;
49
+ }
50
+ }
51
+ };
52
+ var stylesheet = StyleSheet.create({
53
+ root: { flex: 1, backgroundColor: "#fff" },
54
+ container: {
55
+ flex: 1,
56
+ borderRadius: 8,
57
+ overflow: "hidden",
58
+ shadowColor: "#000",
59
+ shadowOffset: { width: 0, height: 2 },
60
+ shadowOpacity: 0.1,
61
+ shadowRadius: 4,
62
+ elevation: 3
63
+ },
64
+ header: {
65
+ padding: 16,
66
+ justifyContent: "center"
67
+ },
68
+ headerText: {
69
+ textAlign: "center",
70
+ fontSize: 16
71
+ },
72
+ webView: {
73
+ flex: 1
74
+ }
75
+ });
76
+ var LorikeetWidgetWebView = ({
77
+ uri,
78
+ baseUrl = "https://chat.lorikeetcx.ai",
79
+ webviewProps = {}
80
+ }) => {
81
+ return /* @__PURE__ */ jsx(
82
+ WebView,
83
+ {
84
+ ...webviewProps,
85
+ onNavigationStateChange: (navState) => {
86
+ if (navState.url.includes(baseUrl)) {
87
+ return false;
88
+ } else {
89
+ void Linking.openURL(navState.url);
90
+ return false;
91
+ }
92
+ },
93
+ source: {
94
+ uri
95
+ },
96
+ style: stylesheet.webView
97
+ }
98
+ );
99
+ };
100
+ var LorikeetWidgetHeader = ({
101
+ title,
102
+ style,
103
+ icon = /* @__PURE__ */ jsx(MessageCirclePlusIcon, {})
104
+ }) => {
105
+ return /* @__PURE__ */ jsxs(View, { style: stylesheet.header, children: [
106
+ /* @__PURE__ */ jsx(Text, { style: [stylesheet.headerText, style], children: title }),
107
+ icon
108
+ ] });
109
+ };
110
+ function LorikeetWidgetView({
111
+ publicKey,
112
+ baseUrl,
113
+ authToken,
114
+ customisations,
115
+ styles,
116
+ onWebViewMessage
117
+ }) {
118
+ var _a;
119
+ const [lorikeetClient, setLorikeetClient] = useState(
120
+ null
121
+ );
122
+ useEffect(() => {
123
+ const lorikeetClient2 = new LorikeetClient({
124
+ public_key: publicKey,
125
+ api_base: baseUrl,
126
+ customisations: {
127
+ ...customisations,
128
+ hideHeader: (customisations == null ? void 0 : customisations.hideHeader) === void 0 ? true : customisations.hideHeader
129
+ }
130
+ });
131
+ setLorikeetClient(lorikeetClient2);
132
+ }, [publicKey, baseUrl]);
133
+ if (!lorikeetClient) {
134
+ return null;
135
+ }
136
+ return /* @__PURE__ */ jsx(SafeAreaView, { edges: ["top", "left", "right"], style: stylesheet.root, children: /* @__PURE__ */ jsxs(View, { style: stylesheet.container, children: [
137
+ /* @__PURE__ */ jsx(
138
+ LorikeetWidgetHeader,
139
+ {
140
+ style: styles == null ? void 0 : styles.header,
141
+ title: (_a = customisations == null ? void 0 : customisations.title) != null ? _a : "Lorikeet AI Agent"
142
+ }
143
+ ),
144
+ /* @__PURE__ */ jsx(
145
+ LorikeetWidgetWebView,
146
+ {
147
+ baseUrl: lorikeetClient.baseUrl,
148
+ uri: lorikeetClient.getWebviewUrl({
149
+ token: authToken
150
+ }),
151
+ webviewProps: {
152
+ onMessage: onWebViewMessage,
153
+ allowsInlineMediaPlayback: true,
154
+ mediaPlaybackRequiresUserAction: false,
155
+ scalesPageToFit: true,
156
+ startInLoadingState: true,
157
+ style: stylesheet.webView
158
+ }
159
+ }
160
+ )
161
+ ] }) });
162
+ }
163
+
164
+ export { LorikeetClient, LorikeetWidgetHeader, LorikeetWidgetView, LorikeetWidgetWebView };
165
+ //# sourceMappingURL=index.js.map
166
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts","../src/widget.tsx"],"names":["lorikeetClient"],"mappings":";;;;;;;;;;;;AAIO,IAAM,iBAAN,MAAqB;AAAA,EAK1B,WAAY,CAAA,EAAE,cA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A,IAAA;AAAA,UACrB,OAAO,UAAW,CAAA,OAAA;AAAA,SACpB;AAAA,OAAA;AAAA,KACF;AAAA,GAAA,EACF,CACF,EAAA,CAAA,CAAA;AAEJ","file":"index.js","sourcesContent":["import type { Customisations } from '@lorikeetai/web-sdk/types'\n\nimport type { LorikeetInitOptions } from './types'\n\nexport class LorikeetClient {\n baseUrl: string = 'https://chat.lorikeetcx.ai' // Fallback URL\n customisations: Customisations | null = null\n publicKey: string\n\n constructor({ customisations, api_base, public_key }: LorikeetInitOptions) {\n if (api_base) {\n this.baseUrl = api_base\n }\n this.publicKey = public_key\n\n if (customisations) {\n this.customisations = customisations\n }\n }\n\n getWebviewUrl = ({\n customer_email,\n customer_name,\n token,\n ticket_id,\n }: {\n customer_email?: string\n customer_name?: string\n token: string\n ticket_id?: string\n }) => {\n const url = new URL(this.baseUrl)\n\n url.pathname = ticket_id\n ? `/tickets/${this.publicKey}/${ticket_id}`\n : '/widget'\n url.searchParams.append('public_key', this.publicKey)\n\n if (customer_email) {\n url.searchParams.append('customer_email', customer_email)\n }\n if (customer_name) {\n url.searchParams.append('customer_name', customer_name)\n }\n\n url.searchParams.append('token', token)\n\n if (this.customisations) {\n url.searchParams.append(\n 'customisations',\n btoa(JSON.stringify(this.customisations)),\n )\n }\n\n return url.toString()\n }\n}\n","import { useEffect, useState } from 'react'\n\nimport { MessageCirclePlusIcon } from 'lucide-react-native'\nimport { Linking, StyleSheet, Text, View } from 'react-native'\nimport { SafeAreaView } from 'react-native-safe-area-context'\nimport { WebView } from 'react-native-webview'\n\nimport { LorikeetClient } from './client'\nimport type {\n LorikeetWidgetHeaderProps,\n LorikeetWidgetViewProps,\n LorikeetWidgetWebViewProps,\n} from './types'\n\nconst stylesheet = StyleSheet.create({\n root: { flex: 1, backgroundColor: '#fff' },\n container: {\n flex: 1,\n borderRadius: 8,\n overflow: 'hidden',\n shadowColor: '#000',\n shadowOffset: { width: 0, height: 2 },\n shadowOpacity: 0.1,\n shadowRadius: 4,\n elevation: 3,\n },\n header: {\n padding: 16,\n justifyContent: 'center',\n },\n headerText: {\n textAlign: 'center',\n fontSize: 16,\n },\n webView: {\n flex: 1,\n },\n})\n\nexport const LorikeetWidgetWebView = ({\n uri,\n baseUrl = 'https://chat.lorikeetcx.ai',\n webviewProps = {},\n}: LorikeetWidgetWebViewProps) => {\n return (\n <WebView\n {...webviewProps}\n onNavigationStateChange={(navState) => {\n if (navState.url.includes(baseUrl)) {\n return false\n } else {\n void Linking.openURL(navState.url)\n return false\n }\n }}\n source={{\n uri,\n }}\n style={stylesheet.webView}\n />\n )\n}\n\nexport const LorikeetWidgetHeader = ({\n title,\n style,\n icon = <MessageCirclePlusIcon />,\n}: LorikeetWidgetHeaderProps) => {\n return (\n <View style={stylesheet.header}>\n <Text style={[stylesheet.headerText, style]}>{title}</Text>\n {icon}\n </View>\n )\n}\n\nexport function LorikeetWidgetView({\n publicKey,\n baseUrl,\n authToken,\n customisations,\n styles,\n onWebViewMessage,\n}: LorikeetWidgetViewProps) {\n const [lorikeetClient, setLorikeetClient] = useState<LorikeetClient | null>(\n null,\n )\n\n useEffect(() => {\n const lorikeetClient = new LorikeetClient({\n public_key: publicKey,\n api_base: baseUrl,\n customisations: {\n ...customisations,\n hideHeader:\n customisations?.hideHeader === undefined\n ? true\n : customisations.hideHeader,\n },\n })\n setLorikeetClient(lorikeetClient)\n }, [publicKey, baseUrl])\n\n if (!lorikeetClient) {\n return null\n }\n\n return (\n <SafeAreaView edges={['top', 'left', 'right']} style={stylesheet.root}>\n <View style={stylesheet.container}>\n <LorikeetWidgetHeader\n style={styles?.header}\n title={customisations?.title ?? 'Lorikeet AI Agent'}\n />\n <LorikeetWidgetWebView\n baseUrl={lorikeetClient.baseUrl}\n uri={lorikeetClient.getWebviewUrl({\n token: authToken,\n })}\n webviewProps={{\n onMessage: onWebViewMessage,\n allowsInlineMediaPlayback: true,\n mediaPlaybackRequiresUserAction: false,\n scalesPageToFit: true,\n startInLoadingState: true,\n style: stylesheet.webView,\n }}\n />\n </View>\n </SafeAreaView>\n )\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@lorikeetai/react-native-sdk",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "private": false,
6
+ "description": "LorikeetCX React Native widget for embedding the chat widget via WebView",
7
+ "keywords": [
8
+ "lorikeet",
9
+ "react-native",
10
+ "webview",
11
+ "widget"
12
+ ],
13
+ "author": "LorikeetCX.ai",
14
+ "license": "MIT",
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
18
+ "react-native": "dist/index.js",
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "react-native": "./dist/index.js",
27
+ "import": "./dist/index.mjs",
28
+ "require": "./dist/index.js",
29
+ "types": "./dist/index.d.ts"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "lucide-react-native": "^0.544.0",
34
+ "react-native-webview": "13.15.0",
35
+ "react-native-safe-area-context": "~5.6.0",
36
+ "react-native-svg": "^15.13.0"
37
+ },
38
+ "peerDependencies": {
39
+ "react": ">=18.0.0",
40
+ "react-native": ">=0.70.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/react": "^18.2.75",
44
+ "eslint": "^9.31.0",
45
+ "rimraf": "^6.0.1",
46
+ "tsup": "^8.3.5",
47
+ "typescript": "^5.7.2",
48
+ "@lorikeetai/prettier-config": "1.0.0",
49
+ "@lorikeetai/eslint-config": "1.0.0",
50
+ "@lorikeetai/tsconfig": "1.0.0",
51
+ "@lorikeetai/web-sdk": "1.5.1"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "prettier": "@lorikeetai/prettier-config",
57
+ "lint-staged": {
58
+ "*.{ts,tsx}": [
59
+ "eslint --fix --quiet --config eslint.config.js"
60
+ ],
61
+ "*.{json,md,yml}": [
62
+ "prettier --write"
63
+ ]
64
+ },
65
+ "scripts": {
66
+ "clean": "rimraf dist",
67
+ "build": "tsup",
68
+ "typecheck": "tsc --noEmit",
69
+ "lint": "eslint . --ext .ts,.tsx --config eslint.config.js"
70
+ }
71
+ }