@duffel/components 3.3.2 → 3.4.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/README.md CHANGED
@@ -2,67 +2,148 @@
2
2
 
3
3
  This package is a component library to help you build your travel product using the [Duffel API](https://duffel.com/docs).
4
4
 
5
- ## Get started
5
+ ## Getting started
6
6
 
7
- ### Installing
7
+ There are 3 different ways to integrate the components into your website. This will depend on which technology you are using. We'll use the ancillaries component as an example, but the same steps will apply for other components.
8
8
 
9
- ```sh
10
- yarn add @duffel/components
11
- # -- or --
12
- npm i @duffel/components
13
- ```
9
+ ### Integrating React component
14
10
 
15
- ### (alternative) Load from CDN:
11
+ 1. Install the package:
16
12
 
17
- ```html
18
- <script src="https://assets.duffel.com/components/VERSION/duffel-ancillaries.js"></script>
19
- <script src="https://assets.duffel.com/components/VERSION/duffel-payments.js"></script>
20
- ```
13
+ ```sh
14
+ yarn add @duffel/components
15
+ # -- or --
16
+ npm i @duffel/components
17
+ ```
21
18
 
22
- ## How do I integrate this into my website?
19
+ 2. Import the component from `@duffel/components`
23
20
 
24
- 1. Please start by reading our integration guide on https://duffel.com/docs/guides/ancillaries-component
21
+ ```javascript
22
+ import { DuffelAncillaries } from "@duffel/components";
23
+ ```
25
24
 
26
- ## Integration examples
25
+ 3. Render the component with the desired props
27
26
 
28
- 1. **client-side** | This example loads a local version of the components using a `script` tag. It uses a fixture for the offer and seat maps.
27
+ ```jsx
28
+ <DuffelAncillaries
29
+ offer_id="fixture_off_1"
30
+ services={["bags", "seats"]}
31
+ passengers={[...]}
32
+ onPayloadReady={console.log}
33
+ />
34
+ ```
29
35
 
30
- - [Find it on src/examples/client-side](src/examples/client-side)
36
+ ### Integrating HTML custom element
31
37
 
32
- 2. **full-stack** | This example loads a local version of the components using a `script` tag. It will search and retrieve an offer from the Duffel API and render the ancillaries component custom element with its `offer_id` and `client_key`. As soon as a service modal is closed it will create a test order with the given payload.
38
+ If you are not using React but still in a node environment, you can:
33
39
 
34
- - [Find it on src/examples/full-stack](src/examples/full-stack)
40
+ 1. Install the package:
35
41
 
36
- 3. **just-typescript** | This example imports a local version of `@duffel/components` and renders the custom element with an offer fixture once the page loads.
42
+ ```sh
43
+ yarn add @duffel/components
44
+ # -- or --
45
+ npm i @duffel/components
46
+ ```
37
47
 
38
- - [Find it on src/examples/just-typescript](src/examples/just-typescript)
48
+ 2. Import the component render function and event listeners from `@duffel/components/custom-elements`
39
49
 
40
- 4. **react-app** | This example imports a local version of `@duffel/components` and renders the a react element with an offer fixture.
50
+ ```javascript
51
+ import {
52
+ renderDuffelAncillariesCustomElement,
53
+ onDuffelAncillariesPayloadReady,
54
+ } from "@duffel/components/custom-elements";
55
+ ```
41
56
 
42
- - [Find it on src/examples/react-app](src/examples/react-app)
57
+ 3. Include the custom element in your HTML
43
58
 
44
- 5. **payments-custom-element** | This example demonstrates the use of the payments component loaded through a script tag
59
+ ```html
60
+ <duffel-ancillaries></duffel-ancillaries>
61
+ ```
45
62
 
46
- - [Find it on src/examples/payments-custom-element](src/examples/payments-custom-element)
63
+ 4. Call the render function with the right properties to render the custom element:
47
64
 
48
- 6. **payments-just-typescript** | This example imports a local version of `@duffel/components` and renders the payments custom element with a fixture of the payment intent.
65
+ ```javascript
66
+ renderDuffelAncillariesCustomElement({
67
+ offer_id: "fixture_off_1",
68
+ services: ["bags", "seats"],
69
+ passengers: [...],
70
+ });
71
+ ```
49
72
 
50
- - [Find it on src/examples/payments-just-typescript](src/examples/payments-just-typescript)
73
+ 5. Set up listeners for events triggered by the component:
51
74
 
52
- 7. **next** | This example imports and renders `@duffel/components` into a `next.js` project.
75
+ ```javascript
76
+ onDuffelAncillariesPayloadReady((data, metadata) => {
77
+ console.table(data);
78
+ console.table(metadata);
79
+ });
80
+ ```
53
81
 
54
- - [Find it on src/examples/payments-just-typescript](src/examples/next)
82
+ ### Integrating custom element without node
55
83
 
56
- ## What components are available?
84
+ If you are not in a node environment and can't rely on npm to install the package, we make it available through our CDN. Here's how to integrate it:
57
85
 
58
- ### Ancillaries component
86
+ 1. Include a script tag
59
87
 
60
- The ancillaries component allows your customers to add ancillaries to their order. It's simple to add to your website and can be customised to fit your brand. This component is avaiable through npm and our cdn.
88
+ ```html
89
+ <!--
90
+ Replace VERSION with the desired version.
91
+ You can find them all on https://www.npmjs.com/package/@duffel/components?activeTab=versions
92
+
93
+ Replace COMPONENT with the desired component you'd like to use.
94
+ You can find the components available in the `./cdn-dist` directory after running `yarn build-and-publish --dry-run`
95
+
96
+ For example, for the duffel ancillaries component on version 3.3.1, use:
97
+ https://assets.duffel.com/components/3.3.1/duffel-ancillaries.js
98
+ -->
61
99
 
62
- - [Find live demo on codesandbox.io&nbsp;&nbsp;↗](https://codesandbox.io/s/duffel-ancillaries-example-1nxuu7)
100
+ <script src="https://assets.duffel.com/components/VERSION/COMPONENT.js"></script>
101
+ ```
63
102
 
64
- ### Payments component
103
+ 2. Include the custom element tag in your HTML:
65
104
 
66
- The payments component provides a [PCI-compliant](https://help.duffel.com/hc/en-gb/articles/4409049543058) way for you to collect card payments for online bookings from your customers. To learn more about how to work with Duffel payments please visit the [Collecting customer card payments guide](https://duffel.com/docs/guides/collecting-customer-card-payments).
105
+ ```html
106
+ <duffel-ancillaries></duffel-ancillaries>
107
+ ```
67
108
 
68
- #### more coming soon...
109
+ 3. Render the component with the required data. You can safely call this function as many times as you want, e.g., when your passenger data changes.
110
+
111
+ ```javascript
112
+ const duffelAncillariesElement = document.querySelector("duffel-ancillaries");
113
+
114
+ duffelAncillariesElement.render({
115
+ offer_id: "fixture_off_1",
116
+ services: ["bags", "seats"],
117
+ passengers: [...],
118
+ });
119
+ ```
120
+
121
+ 4. Listen to the 'onPayloadReady' event on the component. `event.detail.data` contains the payload you need to send to Duffel's API to create an order.
122
+
123
+ ```javascript
124
+ const duffelAncillariesElement =
125
+ document.querySelector("duffel-ancillaries");
126
+
127
+ duffelAncillariesElement.addEventListener("onPayloadReady", (event) =>
128
+ console.log("onPayloadReady\n", event.detail)
129
+ );
130
+ ```
131
+
132
+ ## FAQ
133
+
134
+ ### Are there integration guides?
135
+
136
+ - [Integrating the ancillaries component into your booking flow](https://duffel.com/docs/guides/ancillaries-component).
137
+ - [Collecting payments with Duffel Payments](https://duffel.com/docs/guides/collecting-customer-card-payments)
138
+
139
+ More guides are coming soon.
140
+
141
+ The `examples` folder is a great way to get started quickly and see fully functioning examples for every component.
142
+
143
+ ### What components are available through npm?
144
+
145
+ The list of React components can be found in `src/index.ts`. If you are using custom elements, you can find all render functions and event listeners in `src/custom-elements.ts`.
146
+
147
+ ### What components are available through the CDN?
148
+
149
+ Please check `entryPoints` in `config/esbuild.base.config.js`. It lists all the components we'll build and upload to the CDN.
@@ -39,9 +39,11 @@ export interface DuffelCardFormProps {
39
39
  */
40
40
  styles?: DuffelCardFormStyles;
41
41
  /**
42
- * If you want to develop with a local deployment of the token proxy on port 8000. Set this flag to true.
42
+ * If you want to develop with in a different environment of the token proxy, you can choose it here.
43
+ *
44
+ * @default: `production`
43
45
  */
44
- shouldUseLocalTokenProxy?: boolean;
46
+ tokenProxyEnvironment?: "development" | "staging" | "production";
45
47
  /**
46
48
  * The actions you'd like the component to perform.
47
49
  *