@duffel/react-native-components-assistant 0.5.1 → 0.5.2-canary.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/lib/module/index.js +65 -26
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +85 -26
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { Linking, Modal, Platform, StyleSheet, View } from 'react-native';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { Keyboard, Linking, Modal, Platform, StyleSheet, View } from 'react-native';
|
|
5
5
|
import { WebView } from 'react-native-webview';
|
|
6
6
|
import { hasJsonWebTokenFormat } from "./lib/hasJsonWebTokenFormat.js";
|
|
7
7
|
import { getClientKeyPayload } from "./lib/getClientKeyPayload.js";
|
|
@@ -22,6 +22,26 @@ export const DuffelAssistant = ({
|
|
|
22
22
|
onNewMessage,
|
|
23
23
|
...properties
|
|
24
24
|
}) => {
|
|
25
|
+
const [androidKeyboardHeight, setAndroidKeyboardHeight] = useState(0);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (Platform.OS !== 'android') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!isOpen) {
|
|
31
|
+
setAndroidKeyboardHeight(0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const keyboardDidShowSubscription = Keyboard.addListener('keyboardDidShow', event => {
|
|
35
|
+
setAndroidKeyboardHeight(event.endCoordinates?.height ?? 0);
|
|
36
|
+
});
|
|
37
|
+
const keyboardDidHideSubscription = Keyboard.addListener('keyboardDidHide', () => {
|
|
38
|
+
setAndroidKeyboardHeight(0);
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
keyboardDidShowSubscription.remove();
|
|
42
|
+
keyboardDidHideSubscription.remove();
|
|
43
|
+
};
|
|
44
|
+
}, [isOpen]);
|
|
25
45
|
if (!hasJsonWebTokenFormat(properties.clientKey)) {
|
|
26
46
|
throw new Error('Duffel Assistant client key format must be a valid JWT.');
|
|
27
47
|
}
|
|
@@ -78,13 +98,49 @@ export const DuffelAssistant = ({
|
|
|
78
98
|
Linking.openURL(request.url).catch(() => {});
|
|
79
99
|
return false;
|
|
80
100
|
};
|
|
101
|
+
if (Platform.OS === 'android') {
|
|
102
|
+
return /*#__PURE__*/_jsx(Modal, {
|
|
103
|
+
visible: isOpen,
|
|
104
|
+
onRequestClose: () => onClose(),
|
|
105
|
+
animationType: "slide",
|
|
106
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
107
|
+
style: [styles.androidContainer, {
|
|
108
|
+
paddingBottom: 15 + androidKeyboardHeight
|
|
109
|
+
}],
|
|
110
|
+
children: /*#__PURE__*/_jsx(WebView
|
|
111
|
+
// Required for Android
|
|
112
|
+
, {
|
|
113
|
+
injectedJavaScript: `
|
|
114
|
+
postMessage(
|
|
115
|
+
{
|
|
116
|
+
type: "duffel-assistant-open",
|
|
117
|
+
properties: ${JSON.stringify(properties)},
|
|
118
|
+
},
|
|
119
|
+
"*",
|
|
120
|
+
);
|
|
121
|
+
true;`,
|
|
122
|
+
source: {
|
|
123
|
+
uri: assistantIframeUrl
|
|
124
|
+
},
|
|
125
|
+
onMessage: handleMessage,
|
|
126
|
+
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest
|
|
127
|
+
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
128
|
+
// references `./iframe-app.js` by a stable path, so without this
|
|
129
|
+
// the system WebView can serve a stale bundle for a long time.
|
|
130
|
+
,
|
|
131
|
+
cacheEnabled: false,
|
|
132
|
+
cacheMode: "LOAD_NO_CACHE"
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
81
137
|
return /*#__PURE__*/_jsx(Modal, {
|
|
82
138
|
visible: isOpen,
|
|
83
139
|
onRequestClose: () => onClose(),
|
|
84
140
|
animationType: "slide",
|
|
85
141
|
children: /*#__PURE__*/_jsx(View, {
|
|
86
142
|
style: styles.container,
|
|
87
|
-
children:
|
|
143
|
+
children: /*#__PURE__*/_jsx(WebView, {
|
|
88
144
|
injectedJavaScriptObject: properties
|
|
89
145
|
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
90
146
|
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
@@ -101,29 +157,6 @@ export const DuffelAssistant = ({
|
|
|
101
157
|
// the system WebView can serve a stale bundle for a long time.
|
|
102
158
|
,
|
|
103
159
|
cacheEnabled: false
|
|
104
|
-
}) : /*#__PURE__*/_jsx(WebView
|
|
105
|
-
// Required for Android
|
|
106
|
-
, {
|
|
107
|
-
injectedJavaScript: `
|
|
108
|
-
postMessage(
|
|
109
|
-
{
|
|
110
|
-
type: "duffel-assistant-open",
|
|
111
|
-
properties: ${JSON.stringify(properties)},
|
|
112
|
-
},
|
|
113
|
-
"*",
|
|
114
|
-
);
|
|
115
|
-
true;`,
|
|
116
|
-
source: {
|
|
117
|
-
uri: assistantIframeUrl
|
|
118
|
-
},
|
|
119
|
-
onMessage: handleMessage,
|
|
120
|
-
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest
|
|
121
|
-
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
122
|
-
// references `./iframe-app.js` by a stable path, so without this
|
|
123
|
-
// the system WebView can serve a stale bundle for a long time.
|
|
124
|
-
,
|
|
125
|
-
cacheEnabled: false,
|
|
126
|
-
cacheMode: "LOAD_NO_CACHE"
|
|
127
160
|
})
|
|
128
161
|
})
|
|
129
162
|
});
|
|
@@ -135,6 +168,12 @@ const styles = StyleSheet.create({
|
|
|
135
168
|
paddingHorizontal: 12,
|
|
136
169
|
paddingTop: 50,
|
|
137
170
|
paddingBottom: 30
|
|
171
|
+
},
|
|
172
|
+
androidContainer: {
|
|
173
|
+
flex: 1,
|
|
174
|
+
width: '100%',
|
|
175
|
+
paddingTop: 45,
|
|
176
|
+
paddingBottom: 15
|
|
138
177
|
}
|
|
139
178
|
});
|
|
140
179
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Linking","Modal","Platform","StyleSheet","View","WebView","hasJsonWebTokenFormat","getClientKeyPayload","jsx","_jsx","assistantIframeUrl","isHttpUrl","url","test","isAssistantIframeUrl","parsedUrl","URL","origin","pathname","error","DuffelAssistant","isOpen","onClose","onNewMessage","properties","clientKey","Error","clientKeyPayload","clientKeyIncludesResource","order_id","undefined","booking_id","cars_booking_id","issueType","console","warn","context","supportChannels","chat","showMinimiseButton","onMinimise","handleMessage","
|
|
1
|
+
{"version":3,"names":["React","useEffect","useState","Keyboard","Linking","Modal","Platform","StyleSheet","View","WebView","hasJsonWebTokenFormat","getClientKeyPayload","jsx","_jsx","assistantIframeUrl","isHttpUrl","url","test","isAssistantIframeUrl","parsedUrl","URL","origin","pathname","error","DuffelAssistant","isOpen","onClose","onNewMessage","properties","androidKeyboardHeight","setAndroidKeyboardHeight","OS","keyboardDidShowSubscription","addListener","event","endCoordinates","height","keyboardDidHideSubscription","remove","clientKey","Error","clientKeyPayload","clientKeyIncludesResource","order_id","undefined","booking_id","cars_booking_id","issueType","console","warn","context","supportChannels","chat","showMinimiseButton","onMinimise","handleMessage","nativeEvent","data","parsedData","JSON","parse","type","userId","resourceId","handleShouldStartLoadWithRequest","request","navigationType","openURL","catch","visible","onRequestClose","animationType","children","style","styles","androidContainer","paddingBottom","injectedJavaScript","stringify","source","uri","onMessage","onShouldStartLoadWithRequest","cacheEnabled","cacheMode","container","injectedJavaScriptObject","create","width","paddingHorizontal","paddingTop","flex"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SACEC,QAAQ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,CACrB;IAAC,CACE;EAAC,CACF,CAAC;AAEZ,CAAC;AAED,MAAMT,MAAM,GAAGnE,UAAU,CAACgF,MAAM,CAAC;EAC/BF,SAAS,EAAE;IACTjD,MAAM,EAAE,MAAM;IACdoD,KAAK,EAAE,MAAM;IACbC,iBAAiB,EAAE,EAAE;IACrBC,UAAU,EAAE,EAAE;IACdd,aAAa,EAAE;EACjB,CAAC;EACDD,gBAAgB,EAAE;IAChBgB,IAAI,EAAE,CAAC;IACPH,KAAK,EAAE,MAAM;IACbE,UAAU,EAAE,EAAE;IACdd,aAAa,EAAE;EACjB;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,OAAO,EAAE,KAAK,oBAAoB,IAAI,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAInG,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AA2BhE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAgN1D,CAAC"}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Keyboard,
|
|
4
|
+
Linking,
|
|
5
|
+
Modal,
|
|
6
|
+
Platform,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
3
10
|
import { WebView } from 'react-native-webview';
|
|
4
11
|
import { type DuffelAssistantProps as DuffelAssistantPropsImported } from './DuffelAssistantProps';
|
|
5
12
|
import { hasJsonWebTokenFormat } from './lib/hasJsonWebTokenFormat';
|
|
@@ -38,6 +45,37 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
38
45
|
onNewMessage,
|
|
39
46
|
...properties
|
|
40
47
|
}) => {
|
|
48
|
+
const [androidKeyboardHeight, setAndroidKeyboardHeight] = useState(0);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (Platform.OS !== 'android') {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!isOpen) {
|
|
56
|
+
setAndroidKeyboardHeight(0);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const keyboardDidShowSubscription = Keyboard.addListener(
|
|
61
|
+
'keyboardDidShow',
|
|
62
|
+
(event) => {
|
|
63
|
+
setAndroidKeyboardHeight(event.endCoordinates?.height ?? 0);
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
const keyboardDidHideSubscription = Keyboard.addListener(
|
|
67
|
+
'keyboardDidHide',
|
|
68
|
+
() => {
|
|
69
|
+
setAndroidKeyboardHeight(0);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return () => {
|
|
74
|
+
keyboardDidShowSubscription.remove();
|
|
75
|
+
keyboardDidHideSubscription.remove();
|
|
76
|
+
};
|
|
77
|
+
}, [isOpen]);
|
|
78
|
+
|
|
41
79
|
if (!hasJsonWebTokenFormat(properties.clientKey)) {
|
|
42
80
|
throw new Error('Duffel Assistant client key format must be a valid JWT.');
|
|
43
81
|
}
|
|
@@ -147,29 +185,19 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
147
185
|
return false;
|
|
148
186
|
};
|
|
149
187
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// If that's not possible, you can also upload the assistant built assets to a different folder in assets.duffel and work with that.
|
|
164
|
-
source={{ uri: assistantIframeUrl }}
|
|
165
|
-
onMessage={handleMessage}
|
|
166
|
-
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
167
|
-
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
168
|
-
// references `./iframe-app.js` by a stable path, so without this
|
|
169
|
-
// the system WebView can serve a stale bundle for a long time.
|
|
170
|
-
cacheEnabled={false}
|
|
171
|
-
/>
|
|
172
|
-
) : (
|
|
188
|
+
if (Platform.OS === 'android') {
|
|
189
|
+
return (
|
|
190
|
+
<Modal
|
|
191
|
+
visible={isOpen}
|
|
192
|
+
onRequestClose={() => onClose()}
|
|
193
|
+
animationType="slide"
|
|
194
|
+
>
|
|
195
|
+
<View
|
|
196
|
+
style={[
|
|
197
|
+
styles.androidContainer,
|
|
198
|
+
{ paddingBottom: 15 + androidKeyboardHeight },
|
|
199
|
+
]}
|
|
200
|
+
>
|
|
173
201
|
<WebView
|
|
174
202
|
// Required for Android
|
|
175
203
|
injectedJavaScript={`
|
|
@@ -190,7 +218,32 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
190
218
|
cacheEnabled={false}
|
|
191
219
|
cacheMode="LOAD_NO_CACHE"
|
|
192
220
|
/>
|
|
193
|
-
|
|
221
|
+
</View>
|
|
222
|
+
</Modal>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<Modal
|
|
228
|
+
visible={isOpen}
|
|
229
|
+
onRequestClose={() => onClose()}
|
|
230
|
+
animationType="slide"
|
|
231
|
+
>
|
|
232
|
+
<View style={styles.container}>
|
|
233
|
+
<WebView
|
|
234
|
+
injectedJavaScriptObject={properties}
|
|
235
|
+
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
236
|
+
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
237
|
+
// Easiest solution is to use the production URL with test data.
|
|
238
|
+
// If that's not possible, you can also upload the assistant built assets to a different folder in assets.duffel and work with that.
|
|
239
|
+
source={{ uri: assistantIframeUrl }}
|
|
240
|
+
onMessage={handleMessage}
|
|
241
|
+
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
242
|
+
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
243
|
+
// references `./iframe-app.js` by a stable path, so without this
|
|
244
|
+
// the system WebView can serve a stale bundle for a long time.
|
|
245
|
+
cacheEnabled={false}
|
|
246
|
+
/>
|
|
194
247
|
</View>
|
|
195
248
|
</Modal>
|
|
196
249
|
);
|
|
@@ -204,4 +257,10 @@ const styles = StyleSheet.create({
|
|
|
204
257
|
paddingTop: 50,
|
|
205
258
|
paddingBottom: 30,
|
|
206
259
|
},
|
|
260
|
+
androidContainer: {
|
|
261
|
+
flex: 1,
|
|
262
|
+
width: '100%',
|
|
263
|
+
paddingTop: 45,
|
|
264
|
+
paddingBottom: 15,
|
|
265
|
+
},
|
|
207
266
|
});
|