@duffel/react-native-components-assistant 0.5.1-canary.4 → 0.5.1
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 +32 -51
- 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 +39 -67
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { 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";
|
|
@@ -78,47 +78,13 @@ export const DuffelAssistant = ({
|
|
|
78
78
|
Linking.openURL(request.url).catch(() => {});
|
|
79
79
|
return false;
|
|
80
80
|
};
|
|
81
|
-
if (Platform.OS === 'android') {
|
|
82
|
-
return /*#__PURE__*/_jsx(Modal, {
|
|
83
|
-
visible: isOpen,
|
|
84
|
-
onRequestClose: () => onClose(),
|
|
85
|
-
animationType: "slide",
|
|
86
|
-
children: /*#__PURE__*/_jsx(KeyboardAvoidingView, {
|
|
87
|
-
behavior: 'height',
|
|
88
|
-
enabled: true,
|
|
89
|
-
style: styles.keyboardAvoidingView,
|
|
90
|
-
children: /*#__PURE__*/_jsx(View, {
|
|
91
|
-
style: styles.androidContainer,
|
|
92
|
-
children: /*#__PURE__*/_jsx(WebView
|
|
93
|
-
// Required for Android
|
|
94
|
-
, {
|
|
95
|
-
injectedJavaScript: `
|
|
96
|
-
postMessage(
|
|
97
|
-
{
|
|
98
|
-
type: "duffel-assistant-open",
|
|
99
|
-
properties: ${JSON.stringify(properties)},
|
|
100
|
-
},
|
|
101
|
-
"*",
|
|
102
|
-
);
|
|
103
|
-
true;`,
|
|
104
|
-
source: {
|
|
105
|
-
uri: assistantIframeUrl
|
|
106
|
-
},
|
|
107
|
-
onMessage: handleMessage,
|
|
108
|
-
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest,
|
|
109
|
-
style: styles.webView
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
81
|
return /*#__PURE__*/_jsx(Modal, {
|
|
116
82
|
visible: isOpen,
|
|
117
83
|
onRequestClose: () => onClose(),
|
|
118
84
|
animationType: "slide",
|
|
119
85
|
children: /*#__PURE__*/_jsx(View, {
|
|
120
86
|
style: styles.container,
|
|
121
|
-
children: /*#__PURE__*/_jsx(WebView, {
|
|
87
|
+
children: Platform.OS === 'ios' ? /*#__PURE__*/_jsx(WebView, {
|
|
122
88
|
injectedJavaScriptObject: properties
|
|
123
89
|
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
124
90
|
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
@@ -129,31 +95,46 @@ export const DuffelAssistant = ({
|
|
|
129
95
|
uri: assistantIframeUrl
|
|
130
96
|
},
|
|
131
97
|
onMessage: handleMessage,
|
|
132
|
-
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest
|
|
133
|
-
|
|
98
|
+
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest
|
|
99
|
+
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
100
|
+
// references `./iframe-app.js` by a stable path, so without this
|
|
101
|
+
// the system WebView can serve a stale bundle for a long time.
|
|
102
|
+
,
|
|
103
|
+
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"
|
|
134
127
|
})
|
|
135
128
|
})
|
|
136
129
|
});
|
|
137
130
|
};
|
|
138
131
|
const styles = StyleSheet.create({
|
|
139
|
-
keyboardAvoidingView: {
|
|
140
|
-
flex: 1
|
|
141
|
-
},
|
|
142
132
|
container: {
|
|
143
|
-
|
|
133
|
+
height: '100%',
|
|
144
134
|
width: '100%',
|
|
145
135
|
paddingHorizontal: 12,
|
|
146
136
|
paddingTop: 50,
|
|
147
137
|
paddingBottom: 30
|
|
148
|
-
},
|
|
149
|
-
androidContainer: {
|
|
150
|
-
flex: 1,
|
|
151
|
-
width: '100%',
|
|
152
|
-
paddingTop: 45,
|
|
153
|
-
paddingBottom: 10
|
|
154
|
-
},
|
|
155
|
-
webView: {
|
|
156
|
-
flex: 1
|
|
157
138
|
}
|
|
158
139
|
});
|
|
159
140
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
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","event","nativeEvent","data","parsedData","JSON","parse","type","userId","resourceId","handleShouldStartLoadWithRequest","request","OS","navigationType","openURL","catch","visible","onRequestClose","animationType","children","style","styles","container","injectedJavaScriptObject","source","uri","onMessage","onShouldStartLoadWithRequest","cacheEnabled","injectedJavaScript","stringify","cacheMode","create","height","width","paddingHorizontal","paddingTop","paddingBottom"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,OAAO,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AACzE,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAASC,qBAAqB,QAAQ,gCAA6B;AACnE,SAASC,mBAAmB,QAAQ,8BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAIhE,MAAMC,kBAAkB,GAAG,iDAAiD;AAa5E,MAAMC,SAAS,GAAIC,GAAW,IAAK,cAAc,CAACC,IAAI,CAACD,GAAG,CAAC;AAE3D,MAAME,oBAAoB,GAAIF,GAAW,IAAK;EAC5C,IAAI;IACF,MAAMG,SAAS,GAAG,IAAIC,GAAG,CAACJ,GAAG,CAAC;IAE9B,OAAO,GAAGG,SAAS,CAACE,MAAM,GAAGF,SAAS,CAACG,QAAQ,EAAE,KAAKR,kBAAkB;EAC1E,CAAC,CAAC,OAAOS,KAAK,EAAE;IACd,OAAO,KAAK;EACd;AACF,CAAC;AAED,OAAO,MAAMC,eAA+C,GAAGA,CAAC;EAC9DC,MAAM;EACNC,OAAO;EACPC,YAAY;EACZ,GAAGC;AACL,CAAC,KAAK;EACJ,IAAI,CAAClB,qBAAqB,CAACkB,UAAU,CAACC,SAAS,CAAC,EAAE;IAChD,MAAM,IAAIC,KAAK,CAAC,yDAAyD,CAAC;EAC5E;EAEA,MAAMC,gBAAgB,GAAGpB,mBAAmB,CAACiB,UAAU,C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C;QAC1B;QACA;QACA;QACA;QAAA;QACAyC,MAAM,EAAE;UAAEC,GAAG,EAAExD;QAAmB,CAAE;QACpCyD,SAAS,EAAE1B,aAAc;QACzB2B,4BAA4B,EAAEjB;QAC9B;QACA;QACA;QAAA;QACAkB,YAAY,EAAE;MAAM,CACrB,CAAC,gBAEF5D,IAAA,CAACJ;MACC;MAAA;QACAiE,kBAAkB,EAAE;AAChC;AACA;AACA;AACA,4BAA4BxB,IAAI,CAACyB,SAAS,CAAC/C,UAAU,CAAC;AACtD;AACA;AACA;AACA,gBAAiB;QACLyC,MAAM,EAAE;UAAEC,GAAG,EAAExD;QAAmB,CAAE;QACpCyD,SAAS,EAAE1B,aAAc;QACzB2B,4BAA4B,EAAEjB;QAC9B;QACA;QACA;QAAA;QACAkB,YAAY,EAAE,KAAM;QACpBG,SAAS,EAAC;MAAe,CAC1B;IACF,CACG;EAAC,CACF,CAAC;AAEZ,CAAC;AAED,MAAMV,MAAM,GAAG3D,UAAU,CAACsE,MAAM,CAAC;EAC/BV,SAAS,EAAE;IACTW,MAAM,EAAE,MAAM;IACdC,KAAK,EAAE,MAAM;IACbC,iBAAiB,EAAE,EAAE;IACrBC,UAAU,EAAE,EAAE;IACdC,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,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,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,CAkK1D,CAAC"}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
KeyboardAvoidingView,
|
|
4
|
-
Linking,
|
|
5
|
-
Modal,
|
|
6
|
-
Platform,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
View,
|
|
9
|
-
} from 'react-native';
|
|
2
|
+
import { Linking, Modal, Platform, StyleSheet, View } from 'react-native';
|
|
10
3
|
import { WebView } from 'react-native-webview';
|
|
11
4
|
import { type DuffelAssistantProps as DuffelAssistantPropsImported } from './DuffelAssistantProps';
|
|
12
5
|
import { hasJsonWebTokenFormat } from './lib/hasJsonWebTokenFormat';
|
|
@@ -154,41 +147,6 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
154
147
|
return false;
|
|
155
148
|
};
|
|
156
149
|
|
|
157
|
-
if (Platform.OS === 'android') {
|
|
158
|
-
return (
|
|
159
|
-
<Modal
|
|
160
|
-
visible={isOpen}
|
|
161
|
-
onRequestClose={() => onClose()}
|
|
162
|
-
animationType="slide"
|
|
163
|
-
>
|
|
164
|
-
<KeyboardAvoidingView
|
|
165
|
-
behavior={'height'}
|
|
166
|
-
enabled={true}
|
|
167
|
-
style={styles.keyboardAvoidingView}
|
|
168
|
-
>
|
|
169
|
-
<View style={styles.androidContainer}>
|
|
170
|
-
<WebView
|
|
171
|
-
// Required for Android
|
|
172
|
-
injectedJavaScript={`
|
|
173
|
-
postMessage(
|
|
174
|
-
{
|
|
175
|
-
type: "duffel-assistant-open",
|
|
176
|
-
properties: ${JSON.stringify(properties)},
|
|
177
|
-
},
|
|
178
|
-
"*",
|
|
179
|
-
);
|
|
180
|
-
true;`}
|
|
181
|
-
source={{ uri: assistantIframeUrl }}
|
|
182
|
-
onMessage={handleMessage}
|
|
183
|
-
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
184
|
-
style={styles.webView}
|
|
185
|
-
/>
|
|
186
|
-
</View>
|
|
187
|
-
</KeyboardAvoidingView>
|
|
188
|
-
</Modal>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
150
|
return (
|
|
193
151
|
<Modal
|
|
194
152
|
visible={isOpen}
|
|
@@ -196,40 +154,54 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
196
154
|
animationType="slide"
|
|
197
155
|
>
|
|
198
156
|
<View style={styles.container}>
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
157
|
+
{Platform.OS === 'ios' ? (
|
|
158
|
+
<WebView
|
|
159
|
+
injectedJavaScriptObject={properties}
|
|
160
|
+
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
161
|
+
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
162
|
+
// Easiest solution is to use the production URL with test data.
|
|
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
|
+
) : (
|
|
173
|
+
<WebView
|
|
174
|
+
// Required for Android
|
|
175
|
+
injectedJavaScript={`
|
|
176
|
+
postMessage(
|
|
177
|
+
{
|
|
178
|
+
type: "duffel-assistant-open",
|
|
179
|
+
properties: ${JSON.stringify(properties)},
|
|
180
|
+
},
|
|
181
|
+
"*",
|
|
182
|
+
);
|
|
183
|
+
true;`}
|
|
184
|
+
source={{ uri: assistantIframeUrl }}
|
|
185
|
+
onMessage={handleMessage}
|
|
186
|
+
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
187
|
+
// Always fetch the latest assistant bundle. The iframe.html shell
|
|
188
|
+
// references `./iframe-app.js` by a stable path, so without this
|
|
189
|
+
// the system WebView can serve a stale bundle for a long time.
|
|
190
|
+
cacheEnabled={false}
|
|
191
|
+
cacheMode="LOAD_NO_CACHE"
|
|
192
|
+
/>
|
|
193
|
+
)}
|
|
210
194
|
</View>
|
|
211
195
|
</Modal>
|
|
212
196
|
);
|
|
213
197
|
};
|
|
214
198
|
|
|
215
199
|
const styles = StyleSheet.create({
|
|
216
|
-
keyboardAvoidingView: {
|
|
217
|
-
flex: 1,
|
|
218
|
-
},
|
|
219
200
|
container: {
|
|
220
|
-
|
|
201
|
+
height: '100%',
|
|
221
202
|
width: '100%',
|
|
222
203
|
paddingHorizontal: 12,
|
|
223
204
|
paddingTop: 50,
|
|
224
205
|
paddingBottom: 30,
|
|
225
206
|
},
|
|
226
|
-
androidContainer: {
|
|
227
|
-
flex: 1,
|
|
228
|
-
width: '100%',
|
|
229
|
-
paddingTop: 45,
|
|
230
|
-
paddingBottom: 10,
|
|
231
|
-
},
|
|
232
|
-
webView: {
|
|
233
|
-
flex: 1,
|
|
234
|
-
},
|
|
235
207
|
});
|