Skip to content

Commit d98e363

Browse files
authored
Merge pull request #952 from duffelhq/introduces-v2
Introduces API v2
2 parents 886f2c4 + 24d73b2 commit d98e363

File tree

12 files changed

+83
-84
lines changed

12 files changed

+83
-84
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@duffel/api",
3-
"version": "2.14.4",
3+
"version": "3.0.0",
44
"description": "Javascript client library for the Duffel API",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

src/Client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export class DuffelError extends Error {
3636
}
3737
}
3838

39+
const CURRENT_API_VERSION = 'v2'
40+
3941
export class Client {
4042
private token: string
4143
private basePath: string
@@ -46,7 +48,7 @@ export class Client {
4648
constructor({ token, basePath, apiVersion, debug, source }: Config) {
4749
this.token = token
4850
this.basePath = basePath || 'https://api.duffel.com'
49-
this.apiVersion = apiVersion || 'v1'
51+
this.apiVersion = apiVersion || CURRENT_API_VERSION
5052
this.debug = debug
5153
this.source = source
5254
}

src/Stays/Stays.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Stays', () => {
2121
},
2222
check_in_date: '2023-10-20',
2323
check_out_date: '2023-10-24',
24-
adults: 2,
24+
guests: [{ type: 'adult' }, { type: 'adult' }, { type: 'child', age: 5 }],
2525
rooms: 1,
2626
}
2727

@@ -44,7 +44,7 @@ describe('Stays', () => {
4444
},
4545
check_in_date: '2023-10-20',
4646
check_out_date: '2023-10-24',
47-
adults: 2,
47+
guests: [{ type: 'adult' }, { type: 'adult' }, { type: 'child', age: 5 }],
4848
rooms: 1,
4949
}
5050

src/Stays/StaysTypes.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ export interface StaysRate {
159159
*/
160160
total_currency: string
161161

162-
/**
163-
Deprecated. Refer to available_payment_methods instead.
164-
*/
165-
payment_method: StaysPaymentType
166-
167162
/**
168163
* The methods available for payment of this rate.
169164
@@ -335,20 +330,10 @@ export interface StaysAccommodation {
335330
} | null
336331

337332
/**
338-
* Deprecated: Instructions to access the accommodation in the booking
333+
* The key collection details for the accommodation.
339334
*/
340335
key_collection: StaysBookingKeyCollection | null
341336

342-
/**
343-
* The total currency for the cheapest rate for this accommodation, as an ISO 4217 currency code. If rooms data is available, this is equivalent to the cheapest rate for the cheapest room.
344-
*/
345-
cheapest_rate_currency: string
346-
347-
/**
348-
* The total amount for the cheapest rate for this accommodation. If rooms data is available, this is equivalent to the cheapest rate for the cheapest room.
349-
*/
350-
cheapest_rate_total_amount: string
351-
352337
/**
353338
* The accommodation’s description
354339
*/
@@ -418,7 +403,7 @@ export interface StaysQuote {
418403
/**
419404
* The id of the stay quote.
420405
*
421-
* Example: "quo_0000AS0NZdKjjnnHZmSUbI"
406+
* @example: "quo_0000AS0NZdKjjnnHZmSUbI"
422407
*/
423408
id: string
424409

@@ -526,17 +511,6 @@ export interface StaysQuote {
526511
*/
527512
supported_loyalty_programme: StaysLoyaltyProgrammeReference | null
528513

529-
/**
530-
* A client key to authenticate with Duffel's Card Component when creating a tokenised card.
531-
* This value will be `null` if your organisation does not have this feature enabled,
532-
*/
533-
card_component_key: string | null
534-
535-
/*
536-
* The number of adult guests this quote is for.
537-
*/
538-
adults: number
539-
540514
/*
541515
* The number of rooms this quote is for
542516
*/
@@ -644,14 +618,12 @@ type Child = { type: 'child'; age: number }
644618

645619
export type Guest = Adult | Child
646620

647-
type OccupancyCriteria = {
648-
rooms: number
649-
} & ({ adults: number } | { guests: Array<Guest> })
650-
651-
type CommonStaysSearchParams = {
621+
interface CommonStaysSearchParams {
652622
check_in_date: string
653623
check_out_date: string
654-
} & OccupancyCriteria
624+
rooms: number
625+
guests: Array<Guest>
626+
}
655627

656628
export type LocationParams = {
657629
radius: number
@@ -679,9 +651,10 @@ export interface StaysSearchResult {
679651
check_in_date: string
680652
check_out_date: string
681653
accommodation: StaysAccommodation
682-
adults: number
683654
rooms: number
684655
guests: Array<Guest>
656+
cheapest_rate_total_amount: string
657+
cheapest_rate_currency: string
685658
}
686659

687660
export interface StaysLoyaltyProgramme {

src/Stays/mocks.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
5151
fee_amount: '40.00',
5252
cancellation_timeline: [],
5353
board_type: 'room_only',
54-
payment_method: 'balance', // Deprecated. Refer to available_payment_methods instead.
5554
available_payment_methods: ['balance'],
5655
quantity_available: 1,
5756
supported_loyalty_programme: null,
@@ -83,7 +82,6 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
8382
fee_amount: '40.00',
8483
cancellation_timeline: [],
8584
board_type: 'room_only',
86-
payment_method: 'card', // Deprecated. Refer to available_payment_methods instead.
8785
available_payment_methods: ['card'],
8886
quantity_available: 1,
8987
supported_loyalty_programme: 'duffel_hotel_group_rewards',
@@ -145,8 +143,6 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
145143
key_collection: {
146144
instructions: 'Key is at the property. Collect from the lock box.',
147145
},
148-
cheapest_rate_total_amount: '799.00',
149-
cheapest_rate_currency: 'GBP',
150146
chain: {
151147
name: 'The Ritz-Carlton',
152148
},
@@ -158,9 +154,10 @@ export const MOCK_SEARCH_RESULT: StaysSearchResult = {
158154
id: 'sta_something',
159155
check_in_date: '2023-03-24',
160156
check_out_date: '2023-03-28',
161-
adults: 2,
162157
rooms: 1,
163158
guests: [{ type: 'adult' }, { type: 'adult' }],
159+
cheapest_rate_total_amount: '799.00',
160+
cheapest_rate_currency: 'GBP',
164161
}
165162

166163
export const MOCK_BOOKING: StaysBooking = {
@@ -221,8 +218,6 @@ export const MOCK_QUOTE: StaysQuote = {
221218
due_at_accommodation_amount: null,
222219
due_at_accommodation_currency: 'USD',
223220
supported_loyalty_programme: 'duffel_hotel_group_rewards',
224-
card_component_key: null,
225-
adults: 2,
226221
rooms: 1,
227222
guests: [{ type: 'adult' }, { type: 'adult' }],
228223
}

src/booking/AirlineInitiatedChanges/mockAirlineInitiatedChanges.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export const mockAirlineInitiatedChange: AirlineInitiatedChange = {
123123
city_name: 'Barcelona',
124124
city: null,
125125
},
126-
changeable: null,
127126
},
128127
],
129128
order_id: 'ord_00009hthhsUZ8W4LxQgkjo',
@@ -250,7 +249,6 @@ export const mockAirlineInitiatedChange: AirlineInitiatedChange = {
250249
city_name: 'Barcelona',
251250
city: null,
252251
},
253-
changeable: false,
254252
},
255253
],
256254
action_taken_at: null,

src/booking/Offers/OfferTypes.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
import {
2-
CabinClass,
3-
FlightsConditions,
4-
LoyaltyProgrammeAccount,
5-
PassengerIdentityDocumentType,
6-
Place,
7-
PlaceType,
82
Aircraft,
93
Airline,
104
Airport,
11-
PaginationMeta,
5+
CabinClass,
6+
CreateOfferRequestPassengerFareType,
127
DuffelPassengerType,
8+
FlightsConditions,
9+
LoyaltyProgrammeAccount,
1310
OfferSliceConditions,
11+
PaginationMeta,
12+
Place,
13+
PlaceType,
1414
} from '../../types'
1515

1616
/**
1717
* Each offer represents flights you can buy from an airline at a particular price that meet your search criteria.
1818
* @link https://duffel.com/docs/api/offers/schema
1919
*/
2020
export interface Offer {
21-
/**
22-
* The types of identity documents that may be provided for the passengers when creating an order based on this offer.
23-
* If this is `[]`, then you must not provide identity documents.
24-
*/
25-
allowed_passenger_identity_document_types: PassengerIdentityDocumentType[]
26-
2721
/**
2822
* The services that can be booked along with the offer but are not included by default, for example an additional checked bag.
2923
* This field is only returned in the Get single offer endpoint.
@@ -141,8 +135,29 @@ export interface Offer {
141135
* Partial offers are only ever returned through the multi-step search flow.
142136
*/
143137
partial: boolean
138+
139+
/**
140+
* A list of airline IATA codes whose loyalty programmes are supported when booking the offer.
141+
* Loyalty programmes present within the offer passengers that are not present in this field shall be ignored at booking.
142+
* If this is an empty list ([]), no loyalty programmes are supported for the offer and shall be ignored if provided.
143+
* @example: ["AF","KL","DL"]
144+
*/
145+
supported_loyalty_programmes: string[]
146+
147+
/**
148+
* The types of identity documents supported by the airline and may be provided for the
149+
* passengers when creating an order based on this offer. Currently, possible types are `passport`,
150+
* `tax_id`, `known_traveler_number`, and `passenger_redress_number`.
151+
*/
152+
supported_passenger_identity_document_types: OfferSupportedPassengerIdentityDocumentTypes[]
144153
}
145154

155+
export type OfferSupportedPassengerIdentityDocumentTypes =
156+
| 'passport'
157+
| 'tax_id'
158+
| 'known_traveler_number'
159+
| 'passenger_redress_number'
160+
146161
export interface OfferAvailableServiceBaggageMetadata {
147162
/**
148163
* The maximum weight that the baggage can have in kilograms.
@@ -354,6 +369,12 @@ export interface OfferPassenger {
354369
* Optionally providing one has been deprecated.
355370
*/
356371
id: string
372+
373+
/**
374+
* The fare type of the passenger
375+
* Example: "contract_bulk"
376+
*/
377+
fare_type: CreateOfferRequestPassengerFareType | null
357378
}
358379

359380
export interface OfferSlice {

src/booking/Offers/mockOffer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export const mockOffer: Offer = {
180180
airline_iata_code: 'BA',
181181
},
182182
],
183+
fare_type: null,
183184
},
184185
],
185186
passenger_identity_documents_required: false,
@@ -244,7 +245,8 @@ export const mockOffer: Offer = {
244245
type: 'cancel_for_any_reason',
245246
},
246247
],
247-
allowed_passenger_identity_document_types: ['passport'],
248+
supported_passenger_identity_document_types: ['passport'],
249+
supported_loyalty_programmes: [],
248250
}
249251

250252
export const mockUpdatedOffer = {

src/booking/Offers/mockPartialOffer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export const mockPartialOffer: Offer = {
180180
airline_iata_code: 'BA',
181181
},
182182
],
183+
fare_type: null,
183184
},
184185
],
185186
passenger_identity_documents_required: false,
@@ -244,7 +245,8 @@ export const mockPartialOffer: Offer = {
244245
type: 'cancel_for_any_reason',
245246
},
246247
],
247-
allowed_passenger_identity_document_types: ['passport'],
248+
supported_passenger_identity_document_types: ['passport'],
249+
supported_loyalty_programmes: [],
248250
}
249251

250252
export const mockUpdatedOffer = {

src/booking/OrderCancellations/OrderCancellationsTypes.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ export interface OrderCancellation {
4040
*/
4141
order_id: string
4242
/**
43-
* The amount that will be returned to the original payment method if the order is cancelled, determined according to the fare conditions. This may be `0.00` if the fare is non-refundable. It will include the refund amount of the flights and the services booked.
43+
* The amount that will be returned to the original payment method if the order is cancelled, determined according
44+
* to the fare conditions. This may be 0.00 if the fare is non-refundable. It will include the refund amount
45+
* of the flights and the services booked. This may be null in cases where the refund amount is unknown.
46+
* This only applies in cases where we are unable to get a refund quote from the carrier.
4447
*/
45-
refund_amount: string
48+
refund_amount: string | null
4649
/**
47-
* The currency of the `refund_amount`, as an [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code.
48-
* It will match your organisation's billing currency unless you're using Duffel as an accredited IATA agent, in which case it will be in the currency provided by the airline (which will usually be based on the country where your IATA agency is registered).
49-
* For pay later orders that are awaiting payment, the refund amount will always be 0.00.
50+
* The currency of the refund_amount, as an ISO 4217 currency code.
51+
* It will match your organisation's billing currency unless you’re using Duffel as an accredited IATA agent,
52+
* in which case it will be in the currency provided by the airline (which will usually be based on the
53+
* country where your IATA agency is registered). For hold orders that are awaiting payment, the refund amount will always be 0.00.
5054
*/
51-
refund_currency: string
55+
refund_currency: string | null
5256
/**
5357
* Where the refund, once confirmed, will be sent. `card` is currently a restricted feature. `awaiting_payment` is for pay later orders where no payment has been made yet.
5458
*/

0 commit comments

Comments
 (0)