@duffel/components 3.1.6 → 3.1.8--canary.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 +68 -0
- package/components/DuffelCardForm/DuffelCardForm.d.ts +3 -0
- package/components/DuffelCardForm/DuffelCardFormCustomElement.d.ts +13 -0
- package/components/DuffelCardForm/lib/getIFrameEventListener.d.ts +6 -0
- package/components/DuffelCardForm/lib/getTokenFromClientKey.d.ts +1 -0
- package/components/DuffelCardForm/lib/types.d.ts +60 -0
- package/custom-elements.d.ts +1 -0
- package/custom-elements.js +15 -15
- package/custom-elements.js.map +4 -4
- package/index.d.ts +1 -0
- package/index.js +15 -15
- package/index.js.map +4 -4
- package/package.json +2 -2
- package/stories/DuffelCardForm.stories.d.ts +7 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/DuffelAncillariesProps.d.ts +1 -0
- package/types/index.d.ts +2 -0
- /package/{types → tests/lib}/getSegmentDates.d.ts +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @duffel/components
|
|
2
|
+
|
|
3
|
+
This package is a component library to help you build your travel product using the [Duffel API](https://duffel.com/docs).
|
|
4
|
+
|
|
5
|
+
## Get started
|
|
6
|
+
|
|
7
|
+
### Installing
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @duffel/components
|
|
11
|
+
# -- or --
|
|
12
|
+
npm i @duffel/components
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### (alternative) Load from CDN:
|
|
16
|
+
|
|
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
|
+
```
|
|
21
|
+
|
|
22
|
+
## How do I integrate this into my website?
|
|
23
|
+
|
|
24
|
+
1. Please start by reading our integration guide on https://duffel.com/docs/guides/ancillaries-component
|
|
25
|
+
|
|
26
|
+
## Integration examples
|
|
27
|
+
|
|
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.
|
|
29
|
+
|
|
30
|
+
- [Find it on src/examples/client-side](src/examples/client-side)
|
|
31
|
+
|
|
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.
|
|
33
|
+
|
|
34
|
+
- [Find it on src/examples/full-stack](src/examples/full-stack)
|
|
35
|
+
|
|
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.
|
|
37
|
+
|
|
38
|
+
- [Find it on src/examples/just-typescript](src/examples/just-typescript)
|
|
39
|
+
|
|
40
|
+
4. **react-app** | This example imports a local version of `@duffel/components` and renders the a react element with an offer fixture.
|
|
41
|
+
|
|
42
|
+
- [Find it on src/examples/react-app](src/examples/react-app)
|
|
43
|
+
|
|
44
|
+
5. **payments-custom-element** | This example demonstrates the use of the payments component loaded through a script tag
|
|
45
|
+
|
|
46
|
+
- [Find it on src/examples/payments-custom-element](src/examples/payments-custom-element)
|
|
47
|
+
|
|
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.
|
|
49
|
+
|
|
50
|
+
- [Find it on src/examples/payments-just-typescript](src/examples/payments-just-typescript)
|
|
51
|
+
|
|
52
|
+
7. **next** | This example imports and renders `@duffel/components` into a `next.js` project.
|
|
53
|
+
|
|
54
|
+
- [Find it on src/examples/payments-just-typescript](src/examples/next)
|
|
55
|
+
|
|
56
|
+
## What components are available?
|
|
57
|
+
|
|
58
|
+
### Ancillaries component
|
|
59
|
+
|
|
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.
|
|
61
|
+
|
|
62
|
+
- [Find live demo on codesandbox.io ↗](https://codesandbox.io/s/duffel-ancillaries-example-1nxuu7)
|
|
63
|
+
|
|
64
|
+
### Payments component
|
|
65
|
+
|
|
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).
|
|
67
|
+
|
|
68
|
+
#### more coming soon...
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DuffelCardFormProps } from "./DuffelCardForm";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
"duffel-card-form": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
type DuffelCardFormCustomElementRenderArguments = Pick<DuffelCardFormProps, "clientKey" | "styles" | "shouldUseLocalTokenProxy">;
|
|
10
|
+
export declare function renderDuffelCardFormCustomElement(props: DuffelCardFormCustomElementRenderArguments): void;
|
|
11
|
+
export declare function onDuffelCardFormCardIdCreated(onCardIdCreated: DuffelCardFormProps["onStoreForTemporaryUseSuccess"]): void;
|
|
12
|
+
export declare function onDuffelCardFormCardIdCreationError(onCardIdCreationError: DuffelCardFormProps["onStoreForTemporaryUseFailure"]): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DuffelCardFormProps } from "./types";
|
|
2
|
+
type Inputs = {
|
|
3
|
+
setIFrameHeight: (height: string) => void;
|
|
4
|
+
} & Pick<DuffelCardFormProps, "onValidateSuccess" | "onValidateFailure" | "onStoreForTemporaryUseSuccess" | "onStoreForTemporaryUseFailure">;
|
|
5
|
+
export declare function getIFrameEventListener(baseUrl: string, { setIFrameHeight, onStoreForTemporaryUseSuccess, onStoreForTemporaryUseFailure, }: Inputs): (event: MessageEvent) => void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTokenFromClientKey(clientKey: string): string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CustomStyles } from "src/types";
|
|
2
|
+
export interface StoreForTemporaryUseData {
|
|
3
|
+
id: string;
|
|
4
|
+
live_mode: false;
|
|
5
|
+
}
|
|
6
|
+
export interface StoreForTemporaryUseError {
|
|
7
|
+
status: number;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
export type DuffelCardFormStyles = Pick<CustomStyles, "fontFamily"> & {
|
|
11
|
+
stylesheetUrl?: string;
|
|
12
|
+
};
|
|
13
|
+
export type DuffelCardFormActions = "validate" | "store-for-temporary-use";
|
|
14
|
+
export interface DuffelCardFormProps {
|
|
15
|
+
/**
|
|
16
|
+
* The client key present in the Quote object.
|
|
17
|
+
*/
|
|
18
|
+
clientKey: string;
|
|
19
|
+
/**
|
|
20
|
+
* The styles to apply to the iframe input elements.
|
|
21
|
+
*/
|
|
22
|
+
styles?: DuffelCardFormStyles;
|
|
23
|
+
/**
|
|
24
|
+
* If you want to develop with a local deployment of the token proxy on port 8000. Set this flag to true.
|
|
25
|
+
*/
|
|
26
|
+
shouldUseLocalTokenProxy?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The actions you'd like the component to perform.
|
|
29
|
+
*
|
|
30
|
+
* This prop is a dependecy of a useEffect hook in the component
|
|
31
|
+
* and so when it's changed it will perform the action you specify.
|
|
32
|
+
*
|
|
33
|
+
* The action `store-for-temporary-use` will only happen once `validate` has been successful.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
actions: DuffelCardFormActions[];
|
|
37
|
+
/**
|
|
38
|
+
* This function will be called when the card form validation has been successful.
|
|
39
|
+
*/
|
|
40
|
+
onValidateSuccess: () => void;
|
|
41
|
+
/**
|
|
42
|
+
* If the card form validation is successful but data is changed afterwards,
|
|
43
|
+
* making it invalid, this function will be called.
|
|
44
|
+
*/
|
|
45
|
+
onValidateFailure: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* This function will be called when the card has been stored for temporary use.
|
|
48
|
+
*
|
|
49
|
+
* This callback will only be triggered if the `store-for-temporary-use`
|
|
50
|
+
* action is present in the `actions` prop.
|
|
51
|
+
*/
|
|
52
|
+
onStoreForTemporaryUseSuccess: (data: StoreForTemporaryUseData) => void;
|
|
53
|
+
/**
|
|
54
|
+
* This function will be called when the component has failed to store the card for temporary use.
|
|
55
|
+
*
|
|
56
|
+
* This callback will only be triggered if the `store-for-temporary-use`
|
|
57
|
+
* action is present in the `actions` prop.
|
|
58
|
+
*/
|
|
59
|
+
onStoreForTemporaryUseFailure: (error: StoreForTemporaryUseError) => void;
|
|
60
|
+
}
|
package/custom-elements.d.ts
CHANGED
|
@@ -4,3 +4,4 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { onDuffelAncillariesPayloadReady, renderDuffelAncillariesCustomElement, } from "./components/DuffelAncillaries/DuffelAncillariesCustomElement";
|
|
6
6
|
export { onDuffelPaymentsFailedPayment, onDuffelPaymentsSuccessfulPayment, renderDuffelPaymentsCustomElement, } from "./components/DuffelPayments/DuffelPaymentsCustomElement";
|
|
7
|
+
export { renderDuffelCardFormCustomElement, onDuffelCardFormCardIdCreated, onDuffelCardFormCardIdCreationError, } from "./components/DuffelCardForm/DuffelCardFormCustomElement";
|