@duffel/react-native-components-assistant 0.4.6 → 0.5.1-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/README.md +4 -0
- package/lib/module/index.js +41 -25
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/DuffelAssistantProps.d.ts +23 -0
- package/lib/typescript/src/DuffelAssistantProps.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DuffelAssistantProps.ts +26 -0
- package/src/index.tsx +54 -24
package/README.md
CHANGED
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { Linking, Modal, Platform, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { KeyboardAvoidingView, 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";
|
|
@@ -43,6 +43,9 @@ export const DuffelAssistant = ({
|
|
|
43
43
|
if (!clientKeyIncludesResource && properties.context) {
|
|
44
44
|
throw new Error('The context prop is only supported when the client key includes a resource id.');
|
|
45
45
|
}
|
|
46
|
+
if (typeof properties.supportChannels !== 'undefined' && properties.supportChannels.chat !== true) {
|
|
47
|
+
throw new Error('The supportChannels prop must keep chat enabled. Phone-only support isn’t offered.');
|
|
48
|
+
}
|
|
46
49
|
if (properties.showMinimiseButton && typeof properties.onMinimise !== 'function') {
|
|
47
50
|
console.warn('The showMinimiseButton prop is set to true, but the onMinimise callback is not provided. Make sure to listen to the onMinimise callback to handle the minimisation of the Assistant.');
|
|
48
51
|
}
|
|
@@ -79,24 +82,29 @@ export const DuffelAssistant = ({
|
|
|
79
82
|
visible: isOpen,
|
|
80
83
|
onRequestClose: () => onClose(),
|
|
81
84
|
animationType: "slide",
|
|
82
|
-
children: /*#__PURE__*/_jsx(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
children: /*#__PURE__*/_jsx(KeyboardAvoidingView, {
|
|
86
|
+
behavior: Platform.OS === 'android' ? 'padding' : undefined,
|
|
87
|
+
enabled: Platform.OS === 'android',
|
|
88
|
+
style: styles.keyboardAvoidingView,
|
|
89
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
90
|
+
style: styles.container,
|
|
91
|
+
children: Platform.OS === 'ios' ? /*#__PURE__*/_jsx(WebView, {
|
|
92
|
+
injectedJavaScriptObject: properties
|
|
93
|
+
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
94
|
+
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
95
|
+
// Easiest solution is to use the production URL with test data.
|
|
96
|
+
// If that's not possible, you can also upload the assistant built assets to a different folder in assets.duffel and work with that.
|
|
97
|
+
,
|
|
98
|
+
source: {
|
|
99
|
+
uri: assistantIframeUrl
|
|
100
|
+
},
|
|
101
|
+
onMessage: handleMessage,
|
|
102
|
+
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest,
|
|
103
|
+
style: styles.webView
|
|
104
|
+
}) : /*#__PURE__*/_jsx(WebView
|
|
105
|
+
// Required for Android
|
|
106
|
+
, {
|
|
107
|
+
injectedJavaScript: `
|
|
100
108
|
postMessage(
|
|
101
109
|
{
|
|
102
110
|
type: "duffel-assistant-open",
|
|
@@ -105,22 +113,30 @@ export const DuffelAssistant = ({
|
|
|
105
113
|
"*",
|
|
106
114
|
);
|
|
107
115
|
true;`,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
source: {
|
|
117
|
+
uri: assistantIframeUrl
|
|
118
|
+
},
|
|
119
|
+
onMessage: handleMessage,
|
|
120
|
+
onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest,
|
|
121
|
+
style: styles.webView
|
|
122
|
+
})
|
|
113
123
|
})
|
|
114
124
|
})
|
|
115
125
|
});
|
|
116
126
|
};
|
|
117
127
|
const styles = StyleSheet.create({
|
|
128
|
+
keyboardAvoidingView: {
|
|
129
|
+
flex: 1
|
|
130
|
+
},
|
|
118
131
|
container: {
|
|
119
|
-
|
|
132
|
+
flex: 1,
|
|
120
133
|
width: '100%',
|
|
121
134
|
paddingHorizontal: 12,
|
|
122
135
|
paddingTop: 50,
|
|
123
136
|
paddingBottom: 30
|
|
137
|
+
},
|
|
138
|
+
webView: {
|
|
139
|
+
flex: 1
|
|
124
140
|
}
|
|
125
141
|
});
|
|
126
142
|
//# 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","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","injectedJavaScript","stringify","create","
|
|
1
|
+
{"version":3,"names":["React","KeyboardAvoidingView","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","behavior","enabled","style","styles","keyboardAvoidingView","container","injectedJavaScriptObject","source","uri","onMessage","onShouldStartLoadWithRequest","webView","injectedJavaScript","stringify","create","flex","width","paddingHorizontal","paddingTop","paddingBottom"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,oBAAoB,EACpBC,OAAO,EACPC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,IAAI,QACC,cAAc;AACrB,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,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R,OAAO,EAAE;IACPI,IAAI,EAAE;EACR;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -15,6 +15,20 @@ export type DuffelAssistantContext = {
|
|
|
15
15
|
*/
|
|
16
16
|
issueType?: SupportIssueType;
|
|
17
17
|
};
|
|
18
|
+
export type DuffelAssistantSupportChannels = {
|
|
19
|
+
/**
|
|
20
|
+
* Chat support must stay enabled whenever supportChannels is provided.
|
|
21
|
+
* Phone-only support is not supported.
|
|
22
|
+
*/
|
|
23
|
+
chat: true;
|
|
24
|
+
/**
|
|
25
|
+
* Enable phone as an additional support channel when it has been configured
|
|
26
|
+
* for your organisation by Duffel.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
phone: boolean;
|
|
31
|
+
};
|
|
18
32
|
export interface DuffelAssistantProps {
|
|
19
33
|
/**
|
|
20
34
|
* This prop is used to control whether the Assistant is open/visible or closed.
|
|
@@ -74,5 +88,14 @@ export interface DuffelAssistantProps {
|
|
|
74
88
|
* @default undefined
|
|
75
89
|
*/
|
|
76
90
|
context?: DuffelAssistantContext;
|
|
91
|
+
/**
|
|
92
|
+
* Configure which support channels the Assistant should offer.
|
|
93
|
+
* When omitted, the Assistant will continue to offer chat only.
|
|
94
|
+
*
|
|
95
|
+
* Chat must remain enabled whenever this prop is provided.
|
|
96
|
+
*
|
|
97
|
+
* @default undefined
|
|
98
|
+
*/
|
|
99
|
+
supportChannels?: DuffelAssistantSupportChannels;
|
|
77
100
|
}
|
|
78
101
|
//# sourceMappingURL=DuffelAssistantProps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DuffelAssistantProps.d.ts","sourceRoot":"","sources":["../../../src/DuffelAssistantProps.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEnE,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;OAKG;IACH,OAAO,CAAC,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IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IAExB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;IAEvD;;OAEG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAE7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE9E;;;;OAIG;IACH,OAAO,CAAC,EAAE,sBAAsB,CAAC;IAEjC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,8BAA8B,CAAC;CAClD"}
|
|
@@ -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;AAU1B,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,CAiK1D,CAAC"}
|
package/package.json
CHANGED
|
@@ -18,6 +18,22 @@ export type DuffelAssistantContext = {
|
|
|
18
18
|
issueType?: SupportIssueType;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
export type DuffelAssistantSupportChannels = {
|
|
22
|
+
/**
|
|
23
|
+
* Chat support must stay enabled whenever supportChannels is provided.
|
|
24
|
+
* Phone-only support is not supported.
|
|
25
|
+
*/
|
|
26
|
+
chat: true;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Enable phone as an additional support channel when it has been configured
|
|
30
|
+
* for your organisation by Duffel.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
phone: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
21
37
|
export interface DuffelAssistantProps {
|
|
22
38
|
/**
|
|
23
39
|
* This prop is used to control whether the Assistant is open/visible or closed.
|
|
@@ -83,4 +99,14 @@ export interface DuffelAssistantProps {
|
|
|
83
99
|
* @default undefined
|
|
84
100
|
*/
|
|
85
101
|
context?: DuffelAssistantContext;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Configure which support channels the Assistant should offer.
|
|
105
|
+
* When omitted, the Assistant will continue to offer chat only.
|
|
106
|
+
*
|
|
107
|
+
* Chat must remain enabled whenever this prop is provided.
|
|
108
|
+
*
|
|
109
|
+
* @default undefined
|
|
110
|
+
*/
|
|
111
|
+
supportChannels?: DuffelAssistantSupportChannels;
|
|
86
112
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
KeyboardAvoidingView,
|
|
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';
|
|
@@ -82,6 +89,15 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
82
89
|
);
|
|
83
90
|
}
|
|
84
91
|
|
|
92
|
+
if (
|
|
93
|
+
typeof properties.supportChannels !== 'undefined' &&
|
|
94
|
+
properties.supportChannels.chat !== true
|
|
95
|
+
) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
'The supportChannels prop must keep chat enabled. Phone-only support isn’t offered.'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
85
101
|
if (
|
|
86
102
|
properties.showMinimiseButton &&
|
|
87
103
|
typeof properties.onMinimise !== 'function'
|
|
@@ -144,22 +160,28 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
144
160
|
onRequestClose={() => onClose()}
|
|
145
161
|
animationType="slide"
|
|
146
162
|
>
|
|
147
|
-
<
|
|
148
|
-
{Platform.OS === '
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
<KeyboardAvoidingView
|
|
164
|
+
behavior={Platform.OS === 'android' ? 'padding' : undefined}
|
|
165
|
+
enabled={Platform.OS === 'android'}
|
|
166
|
+
style={styles.keyboardAvoidingView}
|
|
167
|
+
>
|
|
168
|
+
<View style={styles.container}>
|
|
169
|
+
{Platform.OS === 'ios' ? (
|
|
170
|
+
<WebView
|
|
171
|
+
injectedJavaScriptObject={properties}
|
|
172
|
+
// When you are running this in development iOS doesn't allow request from hosts with invalid https certificates.
|
|
173
|
+
// If you try ngrok with the local esbuild server it will fail because ngrok requests in https and the dev server rejects http requests.
|
|
174
|
+
// Easiest solution is to use the production URL with test data.
|
|
175
|
+
// If that's not possible, you can also upload the assistant built assets to a different folder in assets.duffel and work with that.
|
|
176
|
+
source={{ uri: assistantIframeUrl }}
|
|
177
|
+
onMessage={handleMessage}
|
|
178
|
+
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
179
|
+
style={styles.webView}
|
|
180
|
+
/>
|
|
181
|
+
) : (
|
|
182
|
+
<WebView
|
|
183
|
+
// Required for Android
|
|
184
|
+
injectedJavaScript={`
|
|
163
185
|
postMessage(
|
|
164
186
|
{
|
|
165
187
|
type: "duffel-assistant-open",
|
|
@@ -168,22 +190,30 @@ export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
|
168
190
|
"*",
|
|
169
191
|
);
|
|
170
192
|
true;`}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
193
|
+
source={{ uri: assistantIframeUrl }}
|
|
194
|
+
onMessage={handleMessage}
|
|
195
|
+
onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest}
|
|
196
|
+
style={styles.webView}
|
|
197
|
+
/>
|
|
198
|
+
)}
|
|
199
|
+
</View>
|
|
200
|
+
</KeyboardAvoidingView>
|
|
177
201
|
</Modal>
|
|
178
202
|
);
|
|
179
203
|
};
|
|
180
204
|
|
|
181
205
|
const styles = StyleSheet.create({
|
|
206
|
+
keyboardAvoidingView: {
|
|
207
|
+
flex: 1,
|
|
208
|
+
},
|
|
182
209
|
container: {
|
|
183
|
-
|
|
210
|
+
flex: 1,
|
|
184
211
|
width: '100%',
|
|
185
212
|
paddingHorizontal: 12,
|
|
186
213
|
paddingTop: 50,
|
|
187
214
|
paddingBottom: 30,
|
|
188
215
|
},
|
|
216
|
+
webView: {
|
|
217
|
+
flex: 1,
|
|
218
|
+
},
|
|
189
219
|
});
|