@duffel/api 3.1.0 → 3.1.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.
@@ -1,6 +1,15 @@
1
1
  import { OrderSlice } from '../../types';
2
2
  export type AirlineInitiatedChangeActionTaken = 'accepted' | 'cancelled' | 'changed';
3
3
  export type AirlineInitiatedChangeAvailableAction = 'accept' | 'cancel' | 'change' | 'update';
4
+ /**
5
+ * The associated Travel Agent Ticket, if any, for this Airline-Initiated Change.
6
+ * This value will be present for Airline-Initiated changes that take some time to be processed.
7
+ */
8
+ export interface TravelAgentTicket {
9
+ id: string;
10
+ external_ticket_id: string;
11
+ }
12
+ type EmptyObject = Record<string, unknown>;
4
13
  export interface AirlineInitiatedChange {
5
14
  /**
6
15
  * The action taken in response to this airline-initiated change. Accepted,
@@ -48,10 +57,11 @@ export interface AirlineInitiatedChange {
48
57
  * Change. This value will be present for Airline-Initiated changes that take
49
58
  * some time to be processed.
50
59
  */
51
- travel_agent_ticket: any | null;
60
+ travel_agent_ticket: TravelAgentTicket | EmptyObject | null;
52
61
  /**
53
62
  * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime at which
54
63
  * the airline-initiated change was last updated.
55
64
  */
56
65
  updated_at: string;
57
66
  }
67
+ export {};
@@ -1,4 +1,4 @@
1
- import { Airline, CabinClass, DuffelPassengerType, Place, PlaceType } from '../../types';
1
+ import { Airline, CabinClass, PassengerType, Place, PlaceType } from '../../types';
2
2
  import { Offer } from '../Offers/OfferTypes';
3
3
  export interface OfferRequestSlice {
4
4
  /**
@@ -59,7 +59,7 @@ export interface CreateOfferRequestAdultPassenger extends CreateOfferRequestPass
59
59
  * specify their `age` instead of a `type`. A passenger can have only a type
60
60
  * or an age, but not both.
61
61
  */
62
- type: Extract<DuffelPassengerType, 'adult'>;
62
+ type: Extract<PassengerType, 'adult'>;
63
63
  }
64
64
  export interface CreateOfferRequestNonAdultPassenger extends CreateOfferRequestPassengerCommon {
65
65
  /**
@@ -110,7 +110,7 @@ export interface OfferRequestPassenger {
110
110
  /**
111
111
  * The type of the passenger.
112
112
  */
113
- type?: DuffelPassengerType;
113
+ type?: PassengerType;
114
114
  /**
115
115
  * The passenger's family name. Only `space`, `-`, `'`, and letters from the `ASCII`, `Latin-1 Supplement` and `Latin
116
116
  * Extended-A` (with the exceptions of `Æ`, `æ`, `IJ`, `ij`, `Œ`, `œ`, `Þ`, , and `ð`) Unicode charts are accepted. All
@@ -228,6 +228,10 @@ export interface CreateOfferRequest {
228
228
  */
229
229
  slices: CreateOfferRequestSlice[];
230
230
  }
231
+ export type TimeRangeFilter = {
232
+ from: string;
233
+ to: string;
234
+ };
231
235
  export interface CreateOfferRequestSlice {
232
236
  /**
233
237
  * The 3-letter IATA code for the city or airport where this slice ends
@@ -247,11 +251,11 @@ export interface CreateOfferRequestSlice {
247
251
  /**
248
252
  * The inclusive time range for the arrival of the slice
249
253
  */
250
- arrival_time?: string | null;
254
+ arrival_time: TimeRangeFilter | null;
251
255
  /**
252
256
  * The inclusive time range for the departure of the slice
253
257
  */
254
- departure_time?: string | null;
258
+ departure_time: TimeRangeFilter | null;
255
259
  }
256
260
  export interface CreateOfferRequestQueryParameters {
257
261
  /**
@@ -1,4 +1,4 @@
1
- import { Aircraft, Airline, Airport, CabinClass, CreateOfferRequestPassengerFareType, DuffelPassengerType, FlightsConditions, LoyaltyProgrammeAccount, OfferSliceConditions, PaginationMeta, Place, PlaceType } from '../../types';
1
+ import { Aircraft, Airline, Airport, CabinClass, CreateOfferRequestPassengerFareType, PassengerType, FlightsConditions, LoyaltyProgrammeAccount, OfferSliceConditions, PaginationMeta, Place, PlaceType, Stop } from '../../types';
2
2
  /**
3
3
  * Each offer represents flights you can buy from an airline at a particular price that meet your search criteria.
4
4
  * @link https://duffel.com/docs/api/offers/schema
@@ -260,11 +260,11 @@ export interface OfferPassenger {
260
260
  /**
261
261
  * The age of the passenger on the departure_date of the final slice.
262
262
  */
263
- age?: number;
263
+ age: number | null;
264
264
  /**
265
265
  * The type of the passenger.
266
266
  */
267
- type?: DuffelPassengerType;
267
+ type: PassengerType | null;
268
268
  /**
269
269
  * The passenger's family name. Only `space`, `-`, `'`, and letters from the `ASCII`, `Latin-1 Supplement` and `Latin
270
270
  * Extended-A` (with the exceptions of `Æ`, `æ`, `IJ`, `ij`, `Œ`, `œ`, `Þ`, , and `ð`) Unicode charts are accepted. All
@@ -363,7 +363,7 @@ export interface OfferSlice {
363
363
  * - `"4"`: premium seating, additional legroom and recline. Situated in business class or higher.
364
364
  * - `"5"`: deluxe seating, additional legroom and reclines to lie flat position. Situated in business class or higher.
365
365
  */
366
- ngs_shelf: number;
366
+ ngs_shelf: number | null;
367
367
  }
368
368
  export interface OfferSliceSegment {
369
369
  /**
@@ -431,29 +431,7 @@ export interface OfferSliceSegment {
431
431
  /**
432
432
  * Additional segment-specific information about the stops, if any, included in the segment
433
433
  */
434
- stops?: OfferSliceSegmentStop[];
435
- }
436
- export interface OfferSliceSegmentStop {
437
- /**
438
- * Duffel's unique identifier for the Stop
439
- */
440
- id: string;
441
- /**
442
- * The airport at which the Stop happens
443
- */
444
- airport: Airport;
445
- /**
446
- * The ISO 8601 datetime at which the Stop is scheduled to arrive, in the airport's timezone (see destination.timezone)
447
- */
448
- arriving_at: string;
449
- /**
450
- * The ISO 8601 datetime at which the Stop is scheduled to depart, in the airport's timezone (see origin.timezone)
451
- */
452
- departing_at: string;
453
- /**
454
- * The duration of the Stop, represented as a ISO 8601 duration
455
- */
456
- duration: string;
434
+ stops: Array<Stop>;
457
435
  }
458
436
  export type WiFiAmenityCost = 'free' | 'paid' | 'free or paid' | 'n/a';
459
437
  export type SeatPitch = 'less' | 'more' | 'standard' | 'n/a';
@@ -485,64 +463,65 @@ export interface OfferSliceSegmentPassenger {
485
463
  /**
486
464
  * Data about the cabin that the passenger will be flying in for this segment
487
465
  */
488
- cabin: {
489
- /**
490
- * The name of the cabin class
491
- */
492
- name: CabinClass;
466
+ cabin: OfferSliceSegmentPassengerCabin | null;
467
+ }
468
+ export interface OfferSliceSegmentPassengerCabin {
469
+ /**
470
+ * The name of the cabin class
471
+ */
472
+ name: CabinClass;
473
+ /**
474
+ * TThe name that the marketing carrier uses to market this cabin class
475
+ */
476
+ marketing_name: string;
477
+ /**
478
+ * The amenities specific to this cabin class on this plane
479
+ */
480
+ amenities: {
493
481
  /**
494
- * TThe name that the marketing carrier uses to market this cabin class
482
+ * If Wi-Fi is available, information on its cost, availability, etc
495
483
  */
496
- marketing_name: string;
484
+ wifi: {
485
+ /**
486
+ * Whether Wi-Fi is available in this cabin
487
+ */
488
+ available: boolean;
489
+ /**
490
+ * The cost, if any, to use the Wi-Fi
491
+ */
492
+ cost: WiFiAmenityCost;
493
+ } | null;
497
494
  /**
498
- * The amenities specific to this cabin class on this plane
495
+ * Information on the standard seat in this cabin class. Exceptions may apply, such as on exit rows.
499
496
  */
500
- amenities: {
497
+ seat: {
501
498
  /**
502
- * If Wi-Fi is available, information on its cost, availability, etc
499
+ * The distance from a point on a seat to the seat front/behind it, in inches, or "n/a" if not available
503
500
  */
504
- wifi: {
505
- /**
506
- * Whether Wi-Fi is available in this cabin
507
- */
508
- available: boolean;
509
- /**
510
- * The cost, if any, to use the Wi-Fi
511
- */
512
- cost: WiFiAmenityCost;
513
- } | null;
501
+ pitch: SeatPitch;
514
502
  /**
515
- * Information on the standard seat in this cabin class. Exceptions may apply, such as on exit rows.
503
+ * A summary of the seat characteristics for the cabin.
504
+ * Includes the following:
505
+ * - `"standard"` - typical seating with regular legroom / recline
506
+ * - `"extra_legroom"` - typical seating with additional legroom
507
+ * - `"skycouch"` - a row of seats converted into a couch layout
508
+ * - `"recliner"` - seating with additional legroom and recline
509
+ * - `"angle_flat"` - seating with additional legroom and near flat recline
510
+ * - `"full_flat_pod"` - seating with full flat recline and enclosing privacy screens
511
+ * - `"private_suite"` - a full suite, typically including a bed and recliner seat
516
512
  */
517
- seat: {
518
- /**
519
- * The distance from a point on a seat to the seat front/behind it, in inches, or "n/a" if not available
520
- */
521
- pitch: SeatPitch;
522
- /**
523
- * A summary of the seat characteristics for the cabin.
524
- * Includes the following:
525
- * - `"standard"` - typical seating with regular legroom / recline
526
- * - `"extra_legroom"` - typical seating with additional legroom
527
- * - `"skycouch"` - a row of seats converted into a couch layout
528
- * - `"recliner"` - seating with additional legroom and recline
529
- * - `"angle_flat"` - seating with additional legroom and near flat recline
530
- * - `"full_flat_pod"` - seating with full flat recline and enclosing privacy screens
531
- * - `"private_suite"` - a full suite, typically including a bed and recliner seat
532
- */
533
- type: SeatType;
534
- } | null;
513
+ type: SeatType;
514
+ } | null;
515
+ /**
516
+ * If power (AC and/or USB) is available, information on what is available
517
+ */
518
+ power: {
535
519
  /**
536
- * If power (AC and/or USB) is available, information on what is available
520
+ * Whether there is power available or not in this cabin
537
521
  */
538
- power: {
539
- /**
540
- * Whether there is power available or not in this cabin
541
- */
542
- available: boolean;
543
- } | null;
544
- };
545
- } | null;
522
+ available: boolean;
523
+ } | null;
524
+ };
546
525
  }
547
526
  export type BaggageType = 'carry_on' | 'checked';
548
527
  export interface OfferSliceSegmentPassengerBaggage {
@@ -11,6 +11,36 @@ export interface ListOrderCancellationsParams extends PaginationMeta {
11
11
  */
12
12
  order_id?: string;
13
13
  }
14
+ export interface OrderCancellationAirlineCredit {
15
+ /**
16
+ * Duffel's unique identifier for the airline credit
17
+ */
18
+ id: string;
19
+ /**
20
+ * The human-readable name used by the airline to categorize the type of credit being offered. This name should help when trying to understand the airline's conditions of use which apply to this credit.
21
+ */
22
+ credit_name: string;
23
+ /**
24
+ * The code which identifies the airline credit to the airline and will be used to redeem the airline credit
25
+ */
26
+ credit_code: string;
27
+ /**
28
+ * The monetary value associated with this airline credit
29
+ */
30
+ credit_amount: string;
31
+ /**
32
+ * The currency in which this airline credit is issued, as an ISO 4217 currency code
33
+ */
34
+ credit_currency: string;
35
+ /**
36
+ * The date the credit was issued. It is important to note that this date might not be the same as the date of cancellation. Often airlines associate credits with tickets, in which case the date of issue is considered to be the date the ticket was originally issued. Airline credits may have expiration dates which are based on the date of issue. Airlines don't always reliably disclose the expiration date in their APIs at the time of cancellation, so we are unable to return this information on airline credits. To get the latest info on expiration dates for airline credits we recommend checking directly with the airlines to determine the specific conditions of use for the credit.
37
+ */
38
+ issued_on: string;
39
+ /**
40
+ * Duffel's unique identifier for the passenger on the order that the credit is associated with
41
+ */
42
+ passenger_id: string;
43
+ }
14
44
  export interface OrderCancellation {
15
45
  /**
16
46
  * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime that indicates when the order cancellation was confirmed
@@ -53,5 +83,9 @@ export interface OrderCancellation {
53
83
  /**
54
84
  * 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.
55
85
  */
56
- refund_to: 'arc_bsp_cash' | 'balance' | 'card' | 'voucher' | 'awaiting_payment';
86
+ refund_to: 'arc_bsp_cash' | 'balance' | 'card' | 'voucher' | 'awaiting_payment' | 'airline_credits';
87
+ /**
88
+ * The airline credits for this OrderCancellation
89
+ */
90
+ airline_credits: OrderCancellationAirlineCredit[];
57
91
  }
@@ -3,7 +3,7 @@ export interface OrderChange {
3
3
  /**
4
4
  * The price of this offer as a change to your existing order, excluding taxes
5
5
  */
6
- change_total_amount: string | null;
6
+ change_total_amount: string;
7
7
  /**
8
8
  * The currency of the change_total_amount, as an ISO 4217 currency code.
9
9
  * It will match your organisation's billing currency unless you're using Duffel
@@ -11,7 +11,7 @@ export interface OrderChange {
11
11
  * by the airline (which will usually be based on the country where your
12
12
  * IATA agency is registered).
13
13
  */
14
- change_total_currency: string | null;
14
+ change_total_currency: string;
15
15
  /**
16
16
  * Whether the order was created in live mode. This field will be set to `true`
17
17
  * if the order was created in live mode, or `false` if it was created in test mode.
@@ -24,7 +24,7 @@ export interface OrderChange {
24
24
  /**
25
25
  * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime that indicates when the order change was confirmed
26
26
  */
27
- confirmed_at: string;
27
+ confirmed_at: string | null;
28
28
  /**
29
29
  * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime at which the offer will expire
30
30
  * and no longer be usable to create an order
@@ -37,7 +37,7 @@ export interface OrderChange {
37
37
  /**
38
38
  * The price of this offer if it was newly purchased, excluding taxes
39
39
  */
40
- new_total_amount: string | null;
40
+ new_total_amount: string;
41
41
  /**
42
42
  * The currency of the new_total_amount, as an ISO 4217 currency code.
43
43
  * It will match your organisation's billing currency unless you're using
@@ -53,7 +53,7 @@ export interface OrderChange {
53
53
  /**
54
54
  * The penalty price imposed by the airline for making this change
55
55
  */
56
- penalty_amount: string | null;
56
+ penalty_total_amount: string | null;
57
57
  /**
58
58
  * The currency of the penalty_amount, as an ISO 4217 currency code.
59
59
  * It will match your organisation's billing currency unless you're using
@@ -61,12 +61,14 @@ export interface OrderChange {
61
61
  * currency provided by the airline (which will usually be based on
62
62
  * the country where your IATA agency is registered).
63
63
  */
64
- penalty_currency: string | null;
64
+ penalty_total_currency: string | null;
65
65
  /**
66
- * Where the refund, once confirmed, will be sent. card is currently a restricted feature.
67
- * `awaiting_payment` is for pay later orders where no payment has been made yet.
66
+ * Where the refund, once confirmed, will be sent.
67
+ * Refunds are indicated by a negative change_total_amount.
68
+ * If the change does not require a refund, this field will be null.
69
+ * original_form_of_payment refers to the form of payment used to create the order.
68
70
  */
69
- refund_to: 'arc_bsp_cash' | 'balance' | 'card' | 'voucher' | 'awaiting_payment' | 'original_form_of_payment';
71
+ refund_to: 'voucher' | 'original_form_of_payment';
70
72
  /**
71
73
  * The slices to be added and/or removed
72
74
  */
@@ -1,4 +1,4 @@
1
- import { Aircraft, Airline, AirlineInitiatedChange, Airport, CabinClass, DuffelPassengerGender, DuffelPassengerTitle, DuffelPassengerType, FlightsConditions, LoyaltyProgrammeAccount, OfferAvailableServiceBaggage, OfferAvailableServiceBaggageMetadata, PassengerIdentityDocumentType, PaymentType, Place, PlaceType } from '../../types';
1
+ import { Aircraft, Airline, AirlineInitiatedChange, Airport, CabinClass, DuffelPassengerGender, DuffelPassengerTitle, PassengerType, FlightsConditions, LoyaltyProgrammeAccount, OfferAvailableServiceBaggage, OfferAvailableServiceBaggageMetadata, PassengerIdentityDocumentType, PaymentType, Place, PlaceType } from '../../types';
2
2
  /**
3
3
  * An object containing metadata about the service, like the designator of the seat.
4
4
  */
@@ -17,7 +17,7 @@ export interface Seat {
17
17
  * A name which describes the type of seat, which you can display in your user interface to help customers to understand its features
18
18
  * @example "Exit row seat"
19
19
  */
20
- name: string;
20
+ name: string | null;
21
21
  }
22
22
  /**
23
23
  * An object containing metadata about the service, like the maximum weight and dimensions of the baggage.
@@ -134,7 +134,7 @@ export interface OrderPassenger {
134
134
  * The type of the passenger
135
135
  * @return "adult", "child", or "infant_without_seat"
136
136
  */
137
- type: DuffelPassengerType;
137
+ type: PassengerType;
138
138
  /**
139
139
  * The id of the infant associated with this passenger
140
140
  * @return "adult", "child", or "infant_without_seat"
@@ -144,6 +144,18 @@ export interface OrderPassenger {
144
144
  * The **Loyalty Programme Accounts** for this passenger.
145
145
  */
146
146
  loyalty_programme_accounts?: LoyaltyProgrammeAccount[];
147
+ /**
148
+ * The passenger's email address.
149
+ * Note that this data may differ from the airline's records if it was updated directly with the airline since the order was created.
150
+ * @xample "amelia@duffel.com"
151
+ */
152
+ email: string;
153
+ /**
154
+ * The passenger's phone number in E.164 (international) format.
155
+ * Note that this data may differ from the airline's records if it was updated directly with the airline since the order was created.
156
+ * @xample "442080160509"
157
+ */
158
+ phone_number: string;
147
159
  }
148
160
  export interface OrderPassengerIdentityDocument {
149
161
  /**
@@ -183,7 +195,7 @@ export interface OrderSliceSegment {
183
195
  /**
184
196
  * The aircraft that the operating carrier will use to operate this segment
185
197
  */
186
- aircraft?: Aircraft;
198
+ aircraft: Aircraft;
187
199
  /**
188
200
  * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) datetime at which the segment is scheduled to arrive, in the destination airport timezone (see destination.timezone)
189
201
  */
@@ -200,11 +212,11 @@ export interface OrderSliceSegment {
200
212
  * The terminal at the destination airport where the segment is scheduled to arrive
201
213
  * @example "5"
202
214
  */
203
- destination_terminal?: string | null;
215
+ destination_terminal: string;
204
216
  /**
205
217
  * The duration of the segment, represented as a [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) duration
206
218
  */
207
- duration?: string;
219
+ duration: string;
208
220
  /**
209
221
  * Duffel's unique identifier for the segment.
210
222
  * It identifies the segment of an order (i.e. the same segment across orders will have different ids.
@@ -236,7 +248,7 @@ export interface OrderSliceSegment {
236
248
  * The terminal at the origin airport from which the segment is scheduled to depart
237
249
  * @example "B"
238
250
  */
239
- origin_terminal?: string | null;
251
+ origin_terminal: string;
240
252
  /**
241
253
  * Additional segment-specific information about the passengers included in the offer (e.g. their baggage allowance and the cabin class they will be travelling in)
242
254
  */
@@ -245,7 +257,41 @@ export interface OrderSliceSegment {
245
257
  * The distance of the segment in kilometres
246
258
  * @example "424.2"
247
259
  */
248
- distance?: string | null;
260
+ distance: string;
261
+ /**
262
+ * Additional segment-specific information about the stops, if any, included in the segment
263
+ */
264
+ stops: Array<Stop>;
265
+ }
266
+ export interface Stop {
267
+ /**
268
+ * The airport at which the stop happens
269
+ */
270
+ airport: Airport;
271
+ /**
272
+ * The ISO 8601 datetime at which the stop is scheduled to arrive, in the airport's timezone (see destination.timezone)
273
+ *
274
+ * @example "2020-06-13T16:38:02"
275
+ */
276
+ arriving_at: string;
277
+ /**
278
+ * The ISO 8601 datetime at which the stop is scheduled to depart, in the airport's timezone (see origin.timezone)
279
+ *
280
+ * @example "2020-06-13T16:38:02"
281
+ */
282
+ departing_at: string;
283
+ /**
284
+ * The duration of the stop, represented as a ISO 8601 duration
285
+ *
286
+ * @example "PT02H26M"
287
+ */
288
+ duration: string;
289
+ /**
290
+ * Duffel's unique identifier for the resource
291
+ *
292
+ * @example "sto_00009htYpSCXrwaB9Dn456"
293
+ */
294
+ id: string;
249
295
  }
250
296
  export interface OrderSlice {
251
297
  /**
@@ -303,6 +349,10 @@ export interface OrderPaymentStatus {
303
349
  * Price Guarantee means it will hold price
304
350
  */
305
351
  price_guarantee_expires_at?: string;
352
+ /**
353
+ * The ISO 8601 datetime at which the Order was paid for, if at all
354
+ */
355
+ paid_at: string | null;
306
356
  }
307
357
  /**
308
358
  * The type of document
@@ -320,6 +370,11 @@ export interface OrderDocument {
320
370
  * The type of document
321
371
  */
322
372
  type: OrderDocumentsType;
373
+ /**
374
+ * The list of passenger ids the document applies to
375
+ * @example ["pas_00009hj8USM7Ncg31cBCLL"]
376
+ */
377
+ passenger_ids: string[];
323
378
  }
324
379
  export interface OrderPayment {
325
380
  /**
@@ -441,7 +496,7 @@ export interface Order {
441
496
  /**
442
497
  * The airline-initiated changes for this order.
443
498
  */
444
- airline_initiated_changes?: AirlineInitiatedChange[];
499
+ airline_initiated_changes: AirlineInitiatedChange[];
445
500
  /**
446
501
  * The available actions you can take on this order through our API.
447
502
  * It's a list of zero or more of the following values:
@@ -453,6 +508,14 @@ export interface Order {
453
508
  * @example: ["cancel","update"]
454
509
  */
455
510
  available_actions: OrderAvailableAction[];
511
+ /**
512
+ * Airlines are always the source of truth for orders. The orders returned in the Duffel API
513
+ * are a view of those orders. This field is the ISO 8601 datetime at which the order was
514
+ * last synced with the airline. If this datetime is in the last minute you can consider the order up to date.
515
+ *
516
+ * @example "2020-04-11T15:48:11Z"
517
+ */
518
+ synced_at: string;
456
519
  }
457
520
  export type OrderAvailableAction = 'cancel' | 'change' | 'update';
458
521
  export interface CreateOrder {
package/dist/index.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"node-fetch";import{URL as s,URLSearchParams as e}from"url";function i(t,s){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&s.indexOf(i)<0&&(e[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var h=0;for(i=Object.getOwnPropertySymbols(t);h<i.length;h++)s.indexOf(i[h])<0&&Object.prototype.propertyIsEnumerable.call(t,i[h])&&(e[i[h]]=t[i[h]])}return e}function h(t,s,e,i){return new(e||(e=Promise))((function(h,r){function a(t){try{o(i.next(t))}catch(t){r(t)}}function n(t){try{o(i.throw(t))}catch(t){r(t)}}function o(t){var s;t.done?h(t.value):(s=t.value,s instanceof e?s:new e((function(t){t(s)}))).then(a,n)}o((i=i.apply(t,s||[])).next())}))}function r(t){return this instanceof r?(this.v=t,this):new r(t)}function a(t,s,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i,h=e.apply(t,s||[]),a=[];return i={},n("next"),n("throw"),n("return"),i[Symbol.asyncIterator]=function(){return this},i;function n(t){h[t]&&(i[t]=function(s){return new Promise((function(e,i){a.push([t,s,e,i])>1||o(t,s)}))})}function o(t,s){try{(e=h[t](s)).value instanceof r?Promise.resolve(e.value.v).then(u,c):d(a[0][2],e)}catch(t){d(a[0][3],t)}var e}function u(t){o("next",t)}function c(t){o("throw",t)}function d(t,s){t(s),a.shift(),a.length&&o(a[0][0],a[0][1])}}!function(){const t={npm_package_version:"3.0.0"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}(),"function"==typeof SuppressedError&&SuppressedError;class n{constructor(t){this.request=({method:t,path:s,data:e,params:i})=>h(this,void 0,void 0,(function*(){return this.client.request({method:t,path:s,data:e,params:i})})),this.paginatedRequest=({path:t,params:s})=>this.client.paginatedRequest({path:t,params:s}),this.client=t}}class o extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="payments/payment_intents"}}class u extends n{constructor(t){super(t),this.update=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{action_taken:s}})})),this.accept=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/accept`})})),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:{order_id:t}})})),this.path="air/airline_initiated_changes"}}class c extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.create=t=>h(this,void 0,void 0,(function*(){const{return_offers:s,supplier_timeout:e}=t,h=i(t,["return_offers","supplier_timeout"]);return this.request({method:"POST",path:`${this.path}/`,data:h,params:Object.assign(Object.assign({},null!=s&&{return_offers:s}),null!=e&&{supplier_timeout:e})})})),this.path="air/offer_requests"}}class d extends n{constructor(t){super(t),this.get=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:s})})),this.list=t=>{var{offer_request_id:s}=t,e=i(t,["offer_request_id"]);return this.request({method:"GET",path:this.path,params:Object.assign(Object.assign({},e),{offer_request_id:s})})},this.listWithGenerator=t=>{var{offer_request_id:s}=t,e=i(t,["offer_request_id"]);return this.paginatedRequest({path:this.path,params:Object.assign(Object.assign({},e),{offer_request_id:s})})},this.update=(t,s,e)=>h(this,void 0,void 0,(function*(){return this.request(Object.assign({method:"PATCH",path:`${this.path}/${t}/passengers/${s}`},e&&{data:e}))})),this.path="air/offers"}}class p extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=t=>this.paginatedRequest({path:this.path,params:t}),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class l extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:t})})),this.listWithGenerator=t=>this.paginatedRequest({path:"air/orders",params:t}),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:s}})})),this.getAvailableServices=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}/available_services`})})),this.addServices=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/services`,data:s})})),this.path="air/orders"}}class f extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class v extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/order_change_offers"}}class m extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`,data:s})})),this.path="air/order_changes"}}class q extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class g extends n{constructor(t){super(t),this.get=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:s})})),this.create=t=>h(this,void 0,void 0,(function*(){const{supplier_timeout:s}=t,e=i(t,["supplier_timeout"]);return this.request({method:"POST",path:`${this.path}/`,data:e,params:Object.assign({},null!=s&&{supplier_timeout:s})})})),this.getFaresById=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}/fares`,params:s})})),this.path="air/partial_offer_requests"}}class $ extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}let T=class extends Error{constructor({meta:t,errors:s,headers:e}){super(),this.meta=t,this.errors=s,this.headers=e}};class y{constructor({token:i,basePath:r,apiVersion:a,debug:n,source:o}){this.request=({method:i,path:r,data:a,params:n,compress:o=!0})=>h(this,void 0,void 0,(function*(){var h,u;let c,d;const p=new s(r,this.basePath),l={"User-Agent":[`Duffel/${this.apiVersion}`,`duffel_api_javascript/${process.env.npm_package_version}`,this.source?`source/${this.source}`:""].join(" ").trim(),Accept:"application/json","Accept-Encoding":"gzip","Content-Type":"application/json","Duffel-Version":this.apiVersion,Authorization:`Bearer ${this.token}`};if(n){const t=new e;Object.entries(n).sort().filter((t=>null!==t[0])).forEach((([s,e])=>{Array.isArray(e)?e.forEach((e=>t.append(s,e.toString()))):t.append(s,e.toString())})),p.search=t.toString()}a&&(c=JSON.stringify({data:Object.assign({},a)})),(null===(h=this.debug)||void 0===h?void 0:h.verbose)&&(console.info("Endpoint: ",p.href),console.info("Method: ",i),a&&console.info("Body Parameters: ",a),n&&console.info("Query Parameters: ",n));const f=yield t(p.href,{method:i,headers:l,body:c,compress:o});(null===(u=this.debug)||void 0===u?void 0:u.verbose)&&f.headers.get("x-request-id")&&console.info("Request ID: ",f.headers.get("x-request-id"));const v=f.headers.get("content-type");if(d=v&&v.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in d&&d.errors)throw new T(Object.assign(Object.assign({},d),{headers:f.headers}));return Object.assign(Object.assign({},d),{headers:f.headers})})),this.token=i,this.basePath=r||"https://api.duffel.com",this.apiVersion=a||"v2",this.debug=n,this.source=o}paginatedRequest({path:t,params:s}){return a(this,arguments,(function*(){let e=yield r(this.request({method:"GET",path:t,params:s}));for(const t of e.data)yield yield r({data:t});for(;e.meta&&"after"in e.meta&&e.meta.after;){e=yield r(this.request({method:"GET",path:t,params:{limit:e.meta.limit,after:e.meta.after}}));for(const t of e.data)yield yield r({data:t})}}))}}class O extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class b extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class _ extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}class E extends n{constructor(t){super(t),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="places/suggestions"}}class w extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="payments/refunds"}}class G extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="links/sessions"}}class P extends n{constructor(t){super(t),this.redeliver=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/events/${t}/actions/redeliver`})})),this.ping=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/ping`})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/events/${t}`})})),this.listDeliveries=t=>h(this,void 0,void 0,(function*(){var s=i(t,[]);return this.request({method:"GET",path:`${this.path}/deliveries`,params:Object.assign({},s)})})),this.delete=t=>h(this,void 0,void 0,(function*(){return this.request({method:"DELETE",path:`${this.path}/${t}`})})),this.update=(t,{active:s,events:e,url:i})=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{active:s,events:e,url:i}})})),this.list=t=>h(this,void 0,void 0,(function*(){var s=i(t,[]);return this.request({method:"GET",path:this.path,params:Object.assign({},s)})})),this.create=({events:t,url:s})=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:{events:t,url:s}})})),this.path="air/webhooks"}}class S extends n{constructor(t){super(t),this.suggestions=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/suggestions`,data:{query:t,location:s}})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.path="stays/accommodation"}}class x extends n{constructor(t){super(t),this.list=()=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path})})),this.path="stays/loyalty_programmes"}}class j extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=()=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path})})),this.cancel=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/cancel`})})),this.path="stays/bookings"}}class R extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:{rate_id:t}})})),this.path="stays/quotes"}}class k extends n{constructor(t){super(t),this.fetchAllRates=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/fetch_all_rates`})})),this.path="stays/search_results"}}class A extends n{constructor(t){super(t),this.search=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/search`,data:t})})),this.path="stays",this.accommodation=new S(t),this.loyaltyProgrammes=new x(t),this.searchResults=new k(t),this.quotes=new R(t),this.bookings=new j(t)}}class C extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="vault/cards"}}class I{constructor(t){this.client=new y(t),this.aircraft=new O(this.client),this.airlines=new b(this.client),this.airports=new _(this.client),this.airlineInitiatedChanges=new u(this.client),this.links=new G(this.client),this.offerRequests=new c(this.client),this.offers=new d(this.client),this.orders=new l(this.client),this.orderChangeRequests=new f(this.client),this.orderChangeOffers=new v(this.client),this.orderChanges=new m(this.client),this.orderCancellations=new p(this.client),this.payments=new q(this.client),this.seatMaps=new $(this.client),this.paymentIntents=new o(this.client),this.partialOfferRequests=new g(this.client),this.suggestions=new E(this.client),this.refunds=new w(this.client),this.webhooks=new P(this.client),this.stays=new A(this.client),this.cardsClient=new y(Object.assign(Object.assign({},t),{basePath:"https://api.duffel.cards"})),this.cards=new C(this.cardsClient)}}const W=T;export{I as Duffel,W as DuffelError};
1
+ import t from"node-fetch";import{URL as s,URLSearchParams as e}from"url";function i(t,s){var e={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&s.indexOf(i)<0&&(e[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var h=0;for(i=Object.getOwnPropertySymbols(t);h<i.length;h++)s.indexOf(i[h])<0&&Object.prototype.propertyIsEnumerable.call(t,i[h])&&(e[i[h]]=t[i[h]])}return e}function h(t,s,e,i){return new(e||(e=Promise))((function(h,r){function a(t){try{o(i.next(t))}catch(t){r(t)}}function n(t){try{o(i.throw(t))}catch(t){r(t)}}function o(t){var s;t.done?h(t.value):(s=t.value,s instanceof e?s:new e((function(t){t(s)}))).then(a,n)}o((i=i.apply(t,s||[])).next())}))}function r(t){return this instanceof r?(this.v=t,this):new r(t)}function a(t,s,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i,h=e.apply(t,s||[]),a=[];return i={},n("next"),n("throw"),n("return"),i[Symbol.asyncIterator]=function(){return this},i;function n(t){h[t]&&(i[t]=function(s){return new Promise((function(e,i){a.push([t,s,e,i])>1||o(t,s)}))})}function o(t,s){try{(e=h[t](s)).value instanceof r?Promise.resolve(e.value.v).then(u,c):d(a[0][2],e)}catch(t){d(a[0][3],t)}var e}function u(t){o("next",t)}function c(t){o("throw",t)}function d(t,s){t(s),a.shift(),a.length&&o(a[0][0],a[0][1])}}!function(){const t={npm_package_version:"3.1.2"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}(),"function"==typeof SuppressedError&&SuppressedError;class n{constructor(t){this.request=({method:t,path:s,data:e,params:i})=>h(this,void 0,void 0,(function*(){return this.client.request({method:t,path:s,data:e,params:i})})),this.paginatedRequest=({path:t,params:s})=>this.client.paginatedRequest({path:t,params:s}),this.client=t}}class o extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="payments/payment_intents"}}class u extends n{constructor(t){super(t),this.update=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{action_taken:s}})})),this.accept=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/accept`})})),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:{order_id:t}})})),this.path="air/airline_initiated_changes"}}class c extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.create=t=>h(this,void 0,void 0,(function*(){const{return_offers:s,supplier_timeout:e}=t,h=i(t,["return_offers","supplier_timeout"]);return this.request({method:"POST",path:`${this.path}/`,data:h,params:Object.assign(Object.assign({},null!=s&&{return_offers:s}),null!=e&&{supplier_timeout:e})})})),this.path="air/offer_requests"}}class d extends n{constructor(t){super(t),this.get=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:s})})),this.list=t=>{var{offer_request_id:s}=t,e=i(t,["offer_request_id"]);return this.request({method:"GET",path:this.path,params:Object.assign(Object.assign({},e),{offer_request_id:s})})},this.listWithGenerator=t=>{var{offer_request_id:s}=t,e=i(t,["offer_request_id"]);return this.paginatedRequest({path:this.path,params:Object.assign(Object.assign({},e),{offer_request_id:s})})},this.update=(t,s,e)=>h(this,void 0,void 0,(function*(){return this.request(Object.assign({method:"PATCH",path:`${this.path}/${t}/passengers/${s}`},e&&{data:e}))})),this.path="air/offers"}}class p extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=t=>this.paginatedRequest({path:this.path,params:t}),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class l extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:t})})),this.listWithGenerator=t=>this.paginatedRequest({path:"air/orders",params:t}),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:s}})})),this.getAvailableServices=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}/available_services`})})),this.addServices=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/services`,data:s})})),this.path="air/orders"}}class f extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class v extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/order_change_offers"}}class m extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`,data:s})})),this.path="air/order_changes"}}class q extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class g extends n{constructor(t){super(t),this.get=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:s})})),this.create=t=>h(this,void 0,void 0,(function*(){const{supplier_timeout:s}=t,e=i(t,["supplier_timeout"]);return this.request({method:"POST",path:`${this.path}/`,data:e,params:Object.assign({},null!=s&&{supplier_timeout:s})})})),this.getFaresById=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}/fares`,params:s})})),this.path="air/partial_offer_requests"}}class $ extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}let T=class extends Error{constructor({meta:t,errors:s,headers:e}){super(),this.meta=t,this.errors=s,this.headers=e}};class y{constructor({token:i,basePath:r,apiVersion:a,debug:n,source:o}){this.request=({method:i,path:r,data:a,params:n,compress:o=!0})=>h(this,void 0,void 0,(function*(){var h,u;let c,d;const p=new s(r,this.basePath),l={"User-Agent":[`Duffel/${this.apiVersion}`,`duffel_api_javascript/${process.env.npm_package_version}`,this.source?`source/${this.source}`:""].join(" ").trim(),Accept:"application/json","Accept-Encoding":"gzip","Content-Type":"application/json","Duffel-Version":this.apiVersion,Authorization:`Bearer ${this.token}`};if(n){const t=new e;Object.entries(n).sort().filter((t=>null!==t[0])).forEach((([s,e])=>{Array.isArray(e)?e.forEach((e=>t.append(s,e.toString()))):t.append(s,e.toString())})),p.search=t.toString()}a&&(c=JSON.stringify({data:Object.assign({},a)})),(null===(h=this.debug)||void 0===h?void 0:h.verbose)&&(console.info("Endpoint: ",p.href),console.info("Method: ",i),a&&console.info("Body Parameters: ",a),n&&console.info("Query Parameters: ",n));const f=yield t(p.href,{method:i,headers:l,body:c,compress:o});(null===(u=this.debug)||void 0===u?void 0:u.verbose)&&f.headers.get("x-request-id")&&console.info("Request ID: ",f.headers.get("x-request-id"));const v=f.headers.get("content-type");if(d=v&&v.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in d&&d.errors)throw new T(Object.assign(Object.assign({},d),{headers:f.headers}));return Object.assign(Object.assign({},d),{headers:f.headers})})),this.token=i,this.basePath=r||"https://api.duffel.com",this.apiVersion=a||"v2",this.debug=n,this.source=o}paginatedRequest({path:t,params:s}){return a(this,arguments,(function*(){let e=yield r(this.request({method:"GET",path:t,params:s}));for(const t of e.data)yield yield r({data:t});for(;e.meta&&"after"in e.meta&&e.meta.after;){e=yield r(this.request({method:"GET",path:t,params:{limit:e.meta.limit,after:e.meta.after}}));for(const t of e.data)yield yield r({data:t})}}))}}class O extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class b extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class _ extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>this.request({method:"GET",path:this.path,params:t}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}class E extends n{constructor(t){super(t),this.list=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="places/suggestions"}}class w extends n{constructor(t){super(t),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="payments/refunds"}}class G extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="links/sessions"}}class P extends n{constructor(t){super(t),this.redeliver=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/events/${t}/actions/redeliver`})})),this.ping=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/ping`})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/events/${t}`})})),this.listDeliveries=t=>h(this,void 0,void 0,(function*(){var s=i(t,[]);return this.request({method:"GET",path:`${this.path}/deliveries`,params:Object.assign({},s)})})),this.delete=t=>h(this,void 0,void 0,(function*(){return this.request({method:"DELETE",path:`${this.path}/${t}`})})),this.update=(t,{active:s,events:e,url:i})=>h(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{active:s,events:e,url:i}})})),this.list=t=>h(this,void 0,void 0,(function*(){var s=i(t,[]);return this.request({method:"GET",path:this.path,params:Object.assign({},s)})})),this.create=({events:t,url:s})=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:{events:t,url:s}})})),this.path="air/webhooks"}}class S extends n{constructor(t){super(t),this.suggestions=(t,s)=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/suggestions`,data:{query:t,location:s}})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.path="stays/accommodation"}}class x extends n{constructor(t){super(t),this.list=()=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path})})),this.path="stays/loyalty_programmes"}}class j extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=()=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path})})),this.cancel=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/cancel`})})),this.path="stays/bookings"}}class R extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:{rate_id:t}})})),this.path="stays/quotes"}}class k extends n{constructor(t){super(t),this.fetchAllRates=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/fetch_all_rates`})})),this.path="stays/search_results"}}class A extends n{constructor(t){super(t),this.search=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/search`,data:t})})),this.path="stays",this.accommodation=new S(t),this.loyaltyProgrammes=new x(t),this.searchResults=new k(t),this.quotes=new R(t),this.bookings=new j(t)}}class C extends n{constructor(t){super(t),this.create=t=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="vault/cards"}}class I{constructor(t){this.client=new y(t),this.aircraft=new O(this.client),this.airlines=new b(this.client),this.airports=new _(this.client),this.airlineInitiatedChanges=new u(this.client),this.links=new G(this.client),this.offerRequests=new c(this.client),this.offers=new d(this.client),this.orders=new l(this.client),this.orderChangeRequests=new f(this.client),this.orderChangeOffers=new v(this.client),this.orderChanges=new m(this.client),this.orderCancellations=new p(this.client),this.payments=new q(this.client),this.seatMaps=new $(this.client),this.paymentIntents=new o(this.client),this.partialOfferRequests=new g(this.client),this.suggestions=new E(this.client),this.refunds=new w(this.client),this.webhooks=new P(this.client),this.stays=new A(this.client),this.cardsClient=new y(Object.assign(Object.assign({},t),{basePath:"https://api.duffel.cards"})),this.cards=new C(this.cardsClient)}}const W=T;export{I as Duffel,W as DuffelError};
2
2
  //# sourceMappingURL=index.es.js.map