@duffel/react-native-components-assistant 0.2.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/LICENSE +20 -0
- package/README.md +29 -0
- package/lib/module/DuffelAssistantProps.js +2 -0
- package/lib/module/DuffelAssistantProps.js.map +1 -0
- package/lib/module/index.js +65 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/lib/hasJsonWebTokenFormat.js +6 -0
- package/lib/module/lib/hasJsonWebTokenFormat.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/DuffelAssistantProps.d.ts +32 -0
- package/lib/typescript/src/DuffelAssistantProps.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/lib/hasJsonWebTokenFormat.d.ts +2 -0
- package/lib/typescript/src/lib/hasJsonWebTokenFormat.d.ts.map +1 -0
- package/package.json +156 -0
- package/src/DuffelAssistantProps.ts +35 -0
- package/src/index.tsx +68 -0
- package/src/lib/hasJsonWebTokenFormat.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Duffel
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @duffel/react-native-components-assistant
|
|
2
|
+
|
|
3
|
+
UI component for getting travel support in your react native app with the Duffel Assistant.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @duffel/react-native-components-assistant
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { DuffelAssistant } from '@duffel/react-native-components-assistant';
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
const [isDuffelAssistantOpen, setIsDuffelAssistantOpen] = useState(false);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<DuffelAssistant
|
|
21
|
+
isOpen={isDuffelAssistantOpen}
|
|
22
|
+
onClose={() => setIsDuffelAssistantOpen(false)}
|
|
23
|
+
clientKey="<USER_CLIENT_KEY>"
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For documentation and help integrating with this component please visit https://duffel.com/docs/guides/integrating-the-duffel-assistant
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["DuffelAssistantProps.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Modal, Platform, StyleSheet, View } from 'react-native';
|
|
5
|
+
import { WebView } from 'react-native-webview';
|
|
6
|
+
import { hasJsonWebTokenFormat } from "./lib/hasJsonWebTokenFormat.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export const DuffelAssistant = ({
|
|
9
|
+
isOpen,
|
|
10
|
+
onClose,
|
|
11
|
+
...properties
|
|
12
|
+
}) => {
|
|
13
|
+
if (!hasJsonWebTokenFormat(properties.clientKey)) {
|
|
14
|
+
throw new Error('Duffel Assistant client key format must be a valid JWT.');
|
|
15
|
+
}
|
|
16
|
+
return /*#__PURE__*/_jsx(Modal, {
|
|
17
|
+
visible: isOpen,
|
|
18
|
+
onRequestClose: () => onClose(),
|
|
19
|
+
animationType: "slide",
|
|
20
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
21
|
+
style: styles.container,
|
|
22
|
+
children: Platform.OS === 'ios' ? /*#__PURE__*/_jsx(WebView, {
|
|
23
|
+
injectedJavaScriptObject: properties,
|
|
24
|
+
source: {
|
|
25
|
+
uri: 'https://assets.duffel.com/assistant/iframe.html'
|
|
26
|
+
},
|
|
27
|
+
onMessage: event => {
|
|
28
|
+
if (event.nativeEvent.data === 'duffel-assistant-close') {
|
|
29
|
+
onClose();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}) : /*#__PURE__*/_jsx(WebView
|
|
33
|
+
// Required for Android
|
|
34
|
+
, {
|
|
35
|
+
injectedJavaScript: `
|
|
36
|
+
postMessage(
|
|
37
|
+
{
|
|
38
|
+
type: "duffel-assistant-open",
|
|
39
|
+
properties: ${JSON.stringify(properties)},
|
|
40
|
+
},
|
|
41
|
+
"*",
|
|
42
|
+
);
|
|
43
|
+
true;`,
|
|
44
|
+
source: {
|
|
45
|
+
uri: 'https://assets.duffel.com/assistant/iframe.html'
|
|
46
|
+
},
|
|
47
|
+
onMessage: event => {
|
|
48
|
+
if (event.nativeEvent.data === 'duffel-assistant-close') {
|
|
49
|
+
onClose();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const styles = StyleSheet.create({
|
|
57
|
+
container: {
|
|
58
|
+
height: '100%',
|
|
59
|
+
width: '100%',
|
|
60
|
+
paddingHorizontal: 12,
|
|
61
|
+
paddingTop: 50,
|
|
62
|
+
paddingBottom: 30
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Modal","Platform","StyleSheet","View","WebView","hasJsonWebTokenFormat","jsx","_jsx","DuffelAssistant","isOpen","onClose","properties","clientKey","Error","visible","onRequestClose","animationType","children","style","styles","container","OS","injectedJavaScriptObject","source","uri","onMessage","event","nativeEvent","data","injectedJavaScript","JSON","stringify","create","height","width","paddingHorizontal","paddingTop","paddingBottom"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAChE,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAASC,qBAAqB,QAAQ,gCAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAIpE,OAAO,MAAMC,eAA+C,GAAGA,CAAC;EAC9DC,MAAM;EACNC,OAAO;EACP,GAAGC;AACL,CAAC,KAAK;EACJ,IAAI,CAACN,qBAAqB,CAACM,UAAU,CAACC,SAAS,CAAC,EAAE;IAChD,MAAM,IAAIC,KAAK,CAAC,yDAAyD,CAAC;EAC5E;EAEA,oBACEN,IAAA,CAACP,KAAK;IACJc,OAAO,EAAEL,MAAO;IAChBM,cAAc,EAAEA,CAAA,KAAML,OAAO,CAAC,CAAE;IAChCM,aAAa,EAAC,OAAO;IAAAC,QAAA,eAErBV,IAAA,CAACJ,IAAI;MAACe,KAAK,EAAEC,MAAM,CAACC,SAAU;MAAAH,QAAA,EAC3BhB,QAAQ,CAACoB,EAAE,KAAK,KAAK,gBACpBd,IAAA,CAACH,OAAO;QACNkB,wBAAwB,EAAEX,UAAW;QACrCY,MAAM,EAAE;UAAEC,GAAG,EAAE;QAAkD,CAAE;QACnEC,SAAS,EAAGC,KAAK,IAAK;UACpB,IAAIA,KAAK,CAACC,WAAW,CAACC,IAAI,KAAK,wBAAwB,EAAE;YACvDlB,OAAO,CAAC,CAAC;UACX;QACF;MAAE,CACH,CAAC,gBAEFH,IAAA,CAACH;MACC;MAAA;QACAyB,kBAAkB,EAAE;AAChC;AACA;AACA;AACA,4BAA4BC,IAAI,CAACC,SAAS,CAACpB,UAAU,CAAC;AACtD;AACA;AACA;AACA,gBAAiB;QACLY,MAAM,EAAE;UAAEC,GAAG,EAAE;QAAkD,CAAE;QACnEC,SAAS,EAAGC,KAAK,IAAK;UACpB,IAAIA,KAAK,CAACC,WAAW,CAACC,IAAI,KAAK,wBAAwB,EAAE;YACvDlB,OAAO,CAAC,CAAC;UACX;QACF;MAAE,CACH;IACF,CACG;EAAC,CACF,CAAC;AAEZ,CAAC;AAED,MAAMS,MAAM,GAAGjB,UAAU,CAAC8B,MAAM,CAAC;EAC/BZ,SAAS,EAAE;IACTa,MAAM,EAAE,MAAM;IACdC,KAAK,EAAE,MAAM;IACbC,iBAAiB,EAAE,EAAE;IACrBC,UAAU,EAAE,EAAE;IACdC,aAAa,EAAE;EACjB;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hasJsonWebTokenFormat","maybe_jwt","match"],"sourceRoot":"../../../src","sources":["lib/hasJsonWebTokenFormat.ts"],"mappings":";;AAAA,OAAO,SAASA,qBAAqBA,CAACC,SAAiB,EAAE;EACvD,OACE,OAAOA,SAAS,KAAK,QAAQ,IAC7BA,SAAS,CAACC,KAAK,CAAC,kDAAkD,CAAC,KAAK,IAAI;AAEhF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface DuffelAssistantProps {
|
|
2
|
+
isOpen: boolean;
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
/**
|
|
5
|
+
* This is used to authenticate requests to the Duffel API.
|
|
6
|
+
*
|
|
7
|
+
* [Learn about creating a client key on the Duffel API documentation](https://duffel.com/docs/api/v2/component-client-keys/create-component-client-key)
|
|
8
|
+
*
|
|
9
|
+
* This value may be undefined when using fixtures.
|
|
10
|
+
*/
|
|
11
|
+
clientKey: string;
|
|
12
|
+
/**
|
|
13
|
+
* The primary color of the widget.
|
|
14
|
+
* You can customise this to better align with your brand.
|
|
15
|
+
*/
|
|
16
|
+
primaryColor?: string;
|
|
17
|
+
/**
|
|
18
|
+
* For Duffel engineers to work with staging environment for the deployed and built assistant code.
|
|
19
|
+
*
|
|
20
|
+
* @default "production"
|
|
21
|
+
*/
|
|
22
|
+
environment?: 'staging' | 'production' | 'development';
|
|
23
|
+
/**
|
|
24
|
+
* When the clientKey include both the user and resource IDs, the assistant will open directly on the chat window.
|
|
25
|
+
* You may use `issueType` to immediately open a support case with a specific issue type.
|
|
26
|
+
* When no issue type is provided, the user will be able to select the issue type in the chat UI.
|
|
27
|
+
*
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
issueType?: 'cancellation' | 'change' | 'other';
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=DuffelAssistantProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DuffelAssistantProps.d.ts","sourceRoot":"","sources":["../../../src/DuffelAssistantProps.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB;;;;;;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;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,OAAO,CAAC;CACjD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type DuffelAssistantProps as DuffelAssistantPropsImported } from './DuffelAssistantProps';
|
|
3
|
+
export type DuffelAssistantProps = DuffelAssistantPropsImported;
|
|
4
|
+
export declare const DuffelAssistant: React.FC<DuffelAssistantProps>;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAGnG,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAEhE,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAiD1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasJsonWebTokenFormat.d.ts","sourceRoot":"","sources":["../../../../src/lib/hasJsonWebTokenFormat.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,WAKtD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@duffel/react-native-components-assistant",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Duffel Assistant component in React Native",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace duffel-react-native-components-assistant-example",
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"typecheck": "tsc",
|
|
38
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
39
|
+
"clean": "del-cli lib",
|
|
40
|
+
"prepare": "bob build",
|
|
41
|
+
"release": "release-it --only-version"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://duffel.com.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "Duffel <hello@duffel.com> (https://duffel.com)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://duffel.com/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://duffel.com#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
63
|
+
"@eslint/compat": "^1.2.7",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.0",
|
|
65
|
+
"@eslint/js": "^9.22.0",
|
|
66
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
67
|
+
"@react-native/babel-preset": "0.78.2",
|
|
68
|
+
"@react-native/eslint-config": "^0.78.0",
|
|
69
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
70
|
+
"@types/jest": "^29.5.5",
|
|
71
|
+
"@types/react": "^19.0.12",
|
|
72
|
+
"commitlint": "^19.6.1",
|
|
73
|
+
"del-cli": "^5.1.0",
|
|
74
|
+
"eslint": "^9.22.0",
|
|
75
|
+
"eslint-config-prettier": "^10.1.1",
|
|
76
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"prettier": "^3.0.3",
|
|
79
|
+
"react": "19.0.0",
|
|
80
|
+
"react-native": "0.79.5",
|
|
81
|
+
"react-native-builder-bob": "^0.40.12",
|
|
82
|
+
"react-native-webview": "^13.16.0",
|
|
83
|
+
"release-it": "^17.10.0",
|
|
84
|
+
"typescript": "^5.8.3"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": "*",
|
|
88
|
+
"react-native": "*",
|
|
89
|
+
"react-native-webview": "*"
|
|
90
|
+
},
|
|
91
|
+
"workspaces": [
|
|
92
|
+
"example"
|
|
93
|
+
],
|
|
94
|
+
"packageManager": "yarn@3.6.1",
|
|
95
|
+
"jest": {
|
|
96
|
+
"preset": "react-native",
|
|
97
|
+
"modulePathIgnorePatterns": [
|
|
98
|
+
"<rootDir>/example/node_modules",
|
|
99
|
+
"<rootDir>/lib/"
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"commitlint": {
|
|
103
|
+
"extends": [
|
|
104
|
+
"@commitlint/config-conventional"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"release-it": {
|
|
108
|
+
"git": {
|
|
109
|
+
"commitMessage": "chore: release ${version}",
|
|
110
|
+
"tagName": "v${version}"
|
|
111
|
+
},
|
|
112
|
+
"npm": {
|
|
113
|
+
"publish": true
|
|
114
|
+
},
|
|
115
|
+
"github": {
|
|
116
|
+
"release": true
|
|
117
|
+
},
|
|
118
|
+
"plugins": {
|
|
119
|
+
"@release-it/conventional-changelog": {
|
|
120
|
+
"preset": {
|
|
121
|
+
"name": "angular"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"prettier": {
|
|
127
|
+
"quoteProps": "consistent",
|
|
128
|
+
"singleQuote": true,
|
|
129
|
+
"tabWidth": 2,
|
|
130
|
+
"trailingComma": "es5",
|
|
131
|
+
"useTabs": false
|
|
132
|
+
},
|
|
133
|
+
"react-native-builder-bob": {
|
|
134
|
+
"source": "src",
|
|
135
|
+
"output": "lib",
|
|
136
|
+
"targets": [
|
|
137
|
+
[
|
|
138
|
+
"module",
|
|
139
|
+
{
|
|
140
|
+
"esm": true
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
"typescript",
|
|
145
|
+
{
|
|
146
|
+
"project": "tsconfig.build.json"
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
"create-react-native-library": {
|
|
152
|
+
"languages": "js",
|
|
153
|
+
"type": "library",
|
|
154
|
+
"version": "0.51.1"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface DuffelAssistantProps {
|
|
2
|
+
isOpen: boolean;
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is used to authenticate requests to the Duffel API.
|
|
7
|
+
*
|
|
8
|
+
* [Learn about creating a client key on the Duffel API documentation](https://duffel.com/docs/api/v2/component-client-keys/create-component-client-key)
|
|
9
|
+
*
|
|
10
|
+
* This value may be undefined when using fixtures.
|
|
11
|
+
*/
|
|
12
|
+
clientKey: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The primary color of the widget.
|
|
16
|
+
* You can customise this to better align with your brand.
|
|
17
|
+
*/
|
|
18
|
+
primaryColor?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* For Duffel engineers to work with staging environment for the deployed and built assistant code.
|
|
22
|
+
*
|
|
23
|
+
* @default "production"
|
|
24
|
+
*/
|
|
25
|
+
environment?: 'staging' | 'production' | 'development';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* When the clientKey include both the user and resource IDs, the assistant will open directly on the chat window.
|
|
29
|
+
* You may use `issueType` to immediately open a support case with a specific issue type.
|
|
30
|
+
* When no issue type is provided, the user will be able to select the issue type in the chat UI.
|
|
31
|
+
*
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
issueType?: 'cancellation' | 'change' | 'other';
|
|
35
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal, Platform, StyleSheet, View } from 'react-native';
|
|
3
|
+
import { WebView } from 'react-native-webview';
|
|
4
|
+
import { type DuffelAssistantProps as DuffelAssistantPropsImported } from './DuffelAssistantProps';
|
|
5
|
+
import { hasJsonWebTokenFormat } from './lib/hasJsonWebTokenFormat';
|
|
6
|
+
|
|
7
|
+
export type DuffelAssistantProps = DuffelAssistantPropsImported;
|
|
8
|
+
|
|
9
|
+
export const DuffelAssistant: React.FC<DuffelAssistantProps> = ({
|
|
10
|
+
isOpen,
|
|
11
|
+
onClose,
|
|
12
|
+
...properties
|
|
13
|
+
}) => {
|
|
14
|
+
if (!hasJsonWebTokenFormat(properties.clientKey)) {
|
|
15
|
+
throw new Error('Duffel Assistant client key format must be a valid JWT.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Modal
|
|
20
|
+
visible={isOpen}
|
|
21
|
+
onRequestClose={() => onClose()}
|
|
22
|
+
animationType="slide"
|
|
23
|
+
>
|
|
24
|
+
<View style={styles.container}>
|
|
25
|
+
{Platform.OS === 'ios' ? (
|
|
26
|
+
<WebView
|
|
27
|
+
injectedJavaScriptObject={properties}
|
|
28
|
+
source={{ uri: 'https://assets.duffel.com/assistant/iframe.html' }}
|
|
29
|
+
onMessage={(event) => {
|
|
30
|
+
if (event.nativeEvent.data === 'duffel-assistant-close') {
|
|
31
|
+
onClose();
|
|
32
|
+
}
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
) : (
|
|
36
|
+
<WebView
|
|
37
|
+
// Required for Android
|
|
38
|
+
injectedJavaScript={`
|
|
39
|
+
postMessage(
|
|
40
|
+
{
|
|
41
|
+
type: "duffel-assistant-open",
|
|
42
|
+
properties: ${JSON.stringify(properties)},
|
|
43
|
+
},
|
|
44
|
+
"*",
|
|
45
|
+
);
|
|
46
|
+
true;`}
|
|
47
|
+
source={{ uri: 'https://assets.duffel.com/assistant/iframe.html' }}
|
|
48
|
+
onMessage={(event) => {
|
|
49
|
+
if (event.nativeEvent.data === 'duffel-assistant-close') {
|
|
50
|
+
onClose();
|
|
51
|
+
}
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
)}
|
|
55
|
+
</View>
|
|
56
|
+
</Modal>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const styles = StyleSheet.create({
|
|
61
|
+
container: {
|
|
62
|
+
height: '100%',
|
|
63
|
+
width: '100%',
|
|
64
|
+
paddingHorizontal: 12,
|
|
65
|
+
paddingTop: 50,
|
|
66
|
+
paddingBottom: 30,
|
|
67
|
+
},
|
|
68
|
+
});
|