@duffel/components 3.4.3 → 3.5.0--canary-2
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/components/DuffelCardForm/lib/getIFrameEventListener.d.ts +2 -2
- package/components/DuffelCardForm/lib/getIFrameOriginForEnvironment.d.ts +2 -0
- package/components/DuffelCardForm/lib/getIframeURL.d.ts +2 -0
- package/components/DuffelCardForm/lib/getPathnameForIntent.d.ts +2 -0
- package/components/DuffelCardForm/lib/postMessageToCreateCardForTemporaryUse.d.ts +1 -0
- package/components/DuffelCardForm/lib/postMessageToSaveCard.d.ts +1 -0
- package/components/DuffelCardForm/lib/postMessageWithStyles.d.ts +2 -0
- package/components/DuffelCardForm/lib/types.d.ts +68 -10
- package/components/DuffelCardForm/lib/useDuffelCardFormActions.d.ts +23 -0
- package/custom-elements.js +2 -2
- package/custom-elements.js.map +2 -2
- package/index.d.ts +3 -1
- package/index.js +15 -15
- package/index.js.map +4 -4
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -2,6 +2,6 @@ import { DuffelCardFormProps } from "./types";
|
|
|
2
2
|
type Inputs = {
|
|
3
3
|
setIFrameHeight: (height: string) => void;
|
|
4
4
|
postMessageWithStyles: () => void;
|
|
5
|
-
} & Pick<DuffelCardFormProps, "onValidateSuccess" | "onValidateFailure" | "onCreateCardForTemporaryUseSuccess" | "onCreateCardForTemporaryUseFailure">;
|
|
6
|
-
export declare function getIFrameEventListener(
|
|
5
|
+
} & Pick<DuffelCardFormProps, "onValidateSuccess" | "onValidateFailure" | "onCreateCardForTemporaryUseSuccess" | "onCreateCardForTemporaryUseFailure" | "onSaveCardSuccess" | "onSaveCardFailure">;
|
|
6
|
+
export declare function getIFrameEventListener(iFrameURL: URL, { postMessageWithStyles, setIFrameHeight, onValidateSuccess, onValidateFailure, onCreateCardForTemporaryUseSuccess, onCreateCardForTemporaryUseFailure, onSaveCardSuccess, onSaveCardFailure, }: Inputs): (event: MessageEvent) => void;
|
|
7
7
|
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { DuffelCardFormProps } from "./types";
|
|
2
|
+
export declare function getIframeURL(tokenProxyEnvironment: DuffelCardFormProps["tokenProxyEnvironment"], intent: DuffelCardFormProps["intent"], clientKey: DuffelCardFormProps["clientKey"], cardId: DuffelCardFormProps["cardId"]): URL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function postMessageToCreateCardForTemporaryUse(iFrameReference: React.RefObject<HTMLIFrameElement>, baseUrl: URL): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function postMessageToSaveCard(iFrameReference: React.RefObject<HTMLIFrameElement>, baseUrl: URL): void;
|
|
@@ -2,9 +2,27 @@ export interface CreateCardForTemporaryUseData {
|
|
|
2
2
|
id: string;
|
|
3
3
|
live_mode: false;
|
|
4
4
|
}
|
|
5
|
-
export
|
|
5
|
+
export type CreateCardForTemporaryUseError = {
|
|
6
6
|
status: number;
|
|
7
7
|
message: string;
|
|
8
|
+
};
|
|
9
|
+
export type SaveCardError = {
|
|
10
|
+
status: number;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export interface SaveCardData {
|
|
14
|
+
id: string;
|
|
15
|
+
live_mode: boolean;
|
|
16
|
+
last_4_digits: string;
|
|
17
|
+
bin: string;
|
|
18
|
+
expiry_month: number;
|
|
19
|
+
expiry_year: number;
|
|
20
|
+
brand: string;
|
|
21
|
+
cardholder_name: string;
|
|
22
|
+
/**
|
|
23
|
+
* The card will no longer be available for use after this time.
|
|
24
|
+
*/
|
|
25
|
+
unavailable_at: string;
|
|
8
26
|
}
|
|
9
27
|
/**
|
|
10
28
|
* An object where each key value pair is a style to be applied.
|
|
@@ -28,10 +46,11 @@ export interface DuffelCardFormStyles {
|
|
|
28
46
|
sectionTitle?: StylesMap;
|
|
29
47
|
layoutGrid?: StylesMap;
|
|
30
48
|
}
|
|
31
|
-
export type DuffelCardFormActions = "validate" | "create-card-for-temporary-use";
|
|
49
|
+
export type DuffelCardFormActions = "validate" | "save-card" | "create-card-for-temporary-use";
|
|
50
|
+
export type DuffelCardFormIntent = "to-create-card-for-temporary-use" | "to-use-saved-card" | "to-save-card";
|
|
32
51
|
export interface DuffelCardFormProps {
|
|
33
52
|
/**
|
|
34
|
-
* The client key
|
|
53
|
+
* The client key retrieved from the Duffel API.
|
|
35
54
|
*/
|
|
36
55
|
clientKey: string;
|
|
37
56
|
/**
|
|
@@ -44,38 +63,77 @@ export interface DuffelCardFormProps {
|
|
|
44
63
|
* @default: `production`
|
|
45
64
|
*/
|
|
46
65
|
tokenProxyEnvironment?: "development" | "staging" | "production";
|
|
66
|
+
/**
|
|
67
|
+
* The card intent defines what the form is meant to look like.
|
|
68
|
+
* It can be one of:
|
|
69
|
+
*
|
|
70
|
+
* - `to-create-card-for-temporary-use`: The full form will be shown. You may also use this intent for the use case of using and saving the card.
|
|
71
|
+
* - `to-use-saved-card`: When using this intent also provide the saved card ID. Only a cvv field will be rendered.
|
|
72
|
+
* - `to-save-card`: The form will be shown without the cvv field. This only allows you to save a card for future use,
|
|
73
|
+
* but not create an id for immediate, temporary use. For the use case of saving during checkout or save + use, use the `to-create-card-for-temporary-use` intent.
|
|
74
|
+
*/
|
|
75
|
+
intent: DuffelCardFormIntent;
|
|
47
76
|
/**
|
|
48
77
|
* The actions you'd like the component to perform.
|
|
49
78
|
*
|
|
50
79
|
* This prop is a dependecy of a useEffect hook in the component
|
|
51
80
|
* and so when it's changed it will perform the action you specify.
|
|
52
81
|
*
|
|
53
|
-
* The
|
|
82
|
+
* The `create-card-for-temporary-use` and `save-card` actions will only happen once `validate` has been successful.
|
|
83
|
+
*
|
|
84
|
+
* We recommend using the `useDuffelCardFormActions` hook for a simpler, more readable interface to manage the actions array.
|
|
54
85
|
*
|
|
55
86
|
*/
|
|
56
87
|
actions: DuffelCardFormActions[];
|
|
88
|
+
/**
|
|
89
|
+
* Once a card is saved, in order to use it, travellers need to enter its cvv.
|
|
90
|
+
* When using the `use-saved-card` intent, you must provide the card ID.
|
|
91
|
+
*/
|
|
92
|
+
cardId?: string;
|
|
57
93
|
/**
|
|
58
94
|
* This function will be called when the card form validation has been successful.
|
|
59
95
|
*/
|
|
60
|
-
onValidateSuccess
|
|
96
|
+
onValidateSuccess?: () => void;
|
|
61
97
|
/**
|
|
62
98
|
* If the card form validation is successful but data is changed afterwards,
|
|
63
99
|
* making it invalid, this function will be called.
|
|
64
100
|
*/
|
|
65
|
-
onValidateFailure
|
|
101
|
+
onValidateFailure?: () => void;
|
|
66
102
|
/**
|
|
67
103
|
* This function will be called when the card has been created for temporary use.
|
|
68
104
|
*
|
|
69
105
|
* This callback will only be triggered if the `create-card-for-temporary-use`
|
|
70
|
-
* action is present in the `actions` prop.
|
|
106
|
+
* action is present in the `actions` prop. Alternatively,
|
|
107
|
+
* you may use the `triggerCreateCardForTemporaryUse` function from the
|
|
108
|
+
* `useDuffelCardFormActions` hook.
|
|
71
109
|
*/
|
|
72
|
-
onCreateCardForTemporaryUseSuccess
|
|
110
|
+
onCreateCardForTemporaryUseSuccess?: (data: CreateCardForTemporaryUseData) => void;
|
|
73
111
|
/**
|
|
74
112
|
* This function will be called when the component has failed to create the card for temporary use.
|
|
75
113
|
*
|
|
76
114
|
* This callback will only be triggered if the `create-card-for-temporary-use`
|
|
77
|
-
* action is present in the `actions` prop.
|
|
115
|
+
* action is present in the `actions` prop. Alternatively,
|
|
116
|
+
* you may use the `triggerCreateCardForTemporaryUse` function from the
|
|
117
|
+
* `useDuffelCardFormActions` hook.
|
|
118
|
+
*/
|
|
119
|
+
onCreateCardForTemporaryUseFailure?: (error: CreateCardForTemporaryUseError) => void;
|
|
120
|
+
/**
|
|
121
|
+
* This function will be called when the card has been saved.
|
|
122
|
+
*
|
|
123
|
+
* This callback will only be triggered if the `save-card`
|
|
124
|
+
* action is present in the `actions` prop. Alternatively,
|
|
125
|
+
* you may use the `triggerSaveCard` function from the
|
|
126
|
+
* `useDuffelCardFormActions` hook.
|
|
127
|
+
*/
|
|
128
|
+
onSaveCardSuccess?: (data: SaveCardData) => void;
|
|
129
|
+
/**
|
|
130
|
+
* This function will be called when saving the card has failed.
|
|
131
|
+
*
|
|
132
|
+
* This callback will only be triggered if the `save-card`
|
|
133
|
+
* action is present in the `actions` prop. Alternatively,
|
|
134
|
+
* you may use the `triggerSaveCard` function from the
|
|
135
|
+
* `useDuffelCardFormActions` hook.
|
|
78
136
|
*/
|
|
79
|
-
|
|
137
|
+
onSaveCardFailure?: (error: SaveCardError) => void;
|
|
80
138
|
}
|
|
81
139
|
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DuffelCardFormProps } from "./types";
|
|
2
|
+
export interface UseDuffelCardFormActionsHook {
|
|
3
|
+
/**
|
|
4
|
+
* The actions array that should be passed to the `actions` prop of the `DuffelCardForm` component.
|
|
5
|
+
* You do not have have to modify this array directly, instead rely on `triggerSaveCard` and `triggerCreateCardForTemporaryUse` to update the array.
|
|
6
|
+
*/
|
|
7
|
+
actions: DuffelCardFormProps["actions"];
|
|
8
|
+
/**
|
|
9
|
+
* Call this function to tell the component to save the card.
|
|
10
|
+
*/
|
|
11
|
+
triggerSaveCard: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Call this function to tell the component to create a card for temporary use.
|
|
14
|
+
*/
|
|
15
|
+
triggerCreateCardForTemporaryUse: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This hook gives you convinient helpers to read and reason through the DuffelCardForm integration.
|
|
19
|
+
* Add `actions` to the `DuffelCardForm` actions prop and call the functions to trigger the actions you'd like.
|
|
20
|
+
*
|
|
21
|
+
* In the background, this hook is setting the state on actions prop and the component's useEffect hook will trigger the action.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useDuffelCardFormActions(): UseDuffelCardFormActionsHook;
|