@duffel/api 1.7.1 → 1.7.5

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,3 +1,4 @@
1
+ import { Client } from 'Client';
1
2
  import { Resource } from '../../Resource';
2
3
  import { CreateOfferRequest, CreateOfferRequestQueryParameters, DuffelResponse, OfferRequest, PaginationMeta } from '../../types';
3
4
  /**
@@ -12,7 +13,7 @@ export declare class OfferRequests extends Resource {
12
13
  * Endpoint path
13
14
  */
14
15
  path: string;
15
- constructor(args: any);
16
+ constructor(client: Client);
16
17
  /**
17
18
  * Retrieves an offer request by its ID
18
19
  * @param {string} id - Duffel's unique identifier for the offer request
@@ -34,9 +35,10 @@ export declare class OfferRequests extends Resource {
34
35
  * To search for flights, you'll need to create an `offer request`.
35
36
  * An offer request describes the passengers and where and when they want to travel (in the form of a list of `slices`).
36
37
  * It may also include additional filters (e.g. a particular cabin to travel in).
37
- * @param {boolean} [return_offers] - When set to `true`, the offer request resource returned will include all the `offers` returned by the airlines.
38
+ * @param {Object} [options] - the parameters for making an offer requests (required: slices, passengers; optional: cabin_class, return_offers)
39
+ * When `return_offers` is set to `true`, the offer request resource returned will include all the `offers` returned by the airlines.
38
40
  * If set to false, the offer request resource won't include any `offers`. To retrieve the associated offers later, use the List Offers endpoint, specifying the `offer_request_id`.
39
41
  * @link https://duffel.com/docs/api/offer-requests/create-offer-request
40
42
  */
41
- create: (options: Partial<CreateOfferRequest & CreateOfferRequestQueryParameters>) => Promise<DuffelResponse<OfferRequest>>;
43
+ create: (options: CreateOfferRequest & CreateOfferRequestQueryParameters) => Promise<DuffelResponse<OfferRequest>>;
42
44
  }
@@ -118,7 +118,7 @@ export interface CreateOfferRequest {
118
118
  /**
119
119
  * The cabin that the passengers want to travel in
120
120
  */
121
- cabin_class: CabinClass;
121
+ cabin_class?: CabinClass;
122
122
  /**
123
123
  * The passengers who want to travel.
124
124
  * If you specify an age for a passenger, the type may differ for the same passenger in different offers due to airline's different rules. e.g. one airline may treat a 14 year old as an adult, and another as a young adult.
@@ -137,5 +137,5 @@ export interface CreateOfferRequestQueryParameters {
137
137
  * To retrieve the associated `offers` later, use the [List Offers](https://duffel.com/docs/api/offers/get-offers) endpoint, specifying the `offer_request_id`.
138
138
  * You should use this option if you want to take advantage of the pagination, sorting and filtering that the [List Offers](https://duffel.com/docs/api/offers/get-offers) endpoint provides.
139
139
  */
140
- return_offers: boolean;
140
+ return_offers?: boolean;
141
141
  }
@@ -1,3 +1,4 @@
1
+ import { Client } from 'Client';
1
2
  import { Resource } from '../../Resource';
2
3
  import { DuffelResponse, ListOffersParams, Offer, LoyaltyProgrammeAccounts, UpdateOffer } from '../../types';
3
4
  interface UpdateOfferBodyParameters {
@@ -5,9 +6,6 @@ interface UpdateOfferBodyParameters {
5
6
  given_name: string;
6
7
  family_name: string;
7
8
  }
8
- interface UpdateOfferBodyParametersWithoutLoyalty {
9
- loyalty_programme_accounts: never;
10
- }
11
9
  /**
12
10
  * Each offer represents flights you can buy from an airline at a particular price that meet your search criteria.
13
11
  * @class
@@ -18,7 +16,7 @@ export declare class Offers extends Resource {
18
16
  * Endpoint path
19
17
  */
20
18
  path: string;
21
- constructor(args: any);
19
+ constructor(client: Client);
22
20
  /**
23
21
  * Retrieves an offer by its ID
24
22
  * @param {string} id - Duffel's unique identifier for the offer
@@ -46,10 +44,10 @@ export declare class Offers extends Resource {
46
44
  * Some offer passenger fields are updateable. Each field that can be updated is detailed in the request object.
47
45
  * @param {string} offerId - Duffel's unique identifier for the offer
48
46
  * @param {string} passengerId - The identifier for the passenger. This ID will be generated by Duffel
49
- * @param {string} params.family_name - The passenger's family name. Only space, -, ', and letters from the ASCII, Latin-1 Supplement and Latin Extended-A (with the exceptions of Æ, æ, IJ, ij, Œ, œ, Þ, and ð) Unicode charts are accepted. All other characters will result in a validation error. The minimum length is 1 character, and the maximum is 20 characters. This is only required if you're also including Loyalty Programme Accounts.
50
- * @param {string} params.given_name - The passenger's given name. Only space, -, ', and letters from the ASCII, Latin-1 Supplement and Latin Extended-A (with the exceptions of Æ, æ, IJ, ij, Œ, œ, Þ, and ð) Unicode charts are accepted. All other characters will result in a validation error. The minimum length is 1 character, and the maximum is 20 characters. This is only required if you're also including Loyalty Programme Accounts.
47
+ * @param {string} params.family_name - The passenger's family name. Only space, -, ', and letters from the ASCII, Latin-1 Supplement and Latin Extended-A (with the exceptions of Æ, æ, IJ, ij, Œ, œ, Þ, and ð) Unicode charts are accepted. All other characters will result in a validation error. The minimum length is 1 character, and the maximum is 20 characters.
48
+ * @param {string} params.given_name - The passenger's given name. Only space, -, ', and letters from the ASCII, Latin-1 Supplement and Latin Extended-A (with the exceptions of Æ, æ, IJ, ij, Œ, œ, Þ, and ð) Unicode charts are accepted. All other characters will result in a validation error. The minimum length is 1 character, and the maximum is 20 characters.
51
49
  * @param {Object.<LoyaltyProgrammeAccounts>} params.loyalty_programme_accounts - The Loyalty Programme Accounts for this passenger
52
50
  */
53
- update: (offerId: string, passengerId: string, params?: UpdateOfferBodyParameters | UpdateOfferBodyParametersWithoutLoyalty | undefined) => Promise<DuffelResponse<UpdateOffer>>;
51
+ update: (offerId: string, passengerId: string, params: UpdateOfferBodyParameters) => Promise<DuffelResponse<UpdateOffer>>;
54
52
  }
55
53
  export {};
@@ -459,7 +459,7 @@ export interface CreateOrder {
459
459
  /**
460
460
  * The payment details to use to pay for the order
461
461
  */
462
- payments: OrderPayment[];
462
+ payments?: OrderPayment[];
463
463
  /**
464
464
  * The payment action you want to take for your order. You can only use pay_later with offers that contain requires_instant_payment: false.
465
465
  */
package/dist/index.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"stream";import e from"http";import r,{URL as o,URLSearchParams as n}from"url";import s from"https";import i from"zlib";function a(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++)e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}return r}function u(t,e,r,o){return new(r||(r=Promise))((function(n,s){function i(t){try{u(o.next(t))}catch(t){s(t)}}function a(t){try{u(o.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}u((o=o.apply(t,e||[])).next())}))}function h(t){return this instanceof h?(this.v=t,this):new h(t)}function c(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=r.apply(t,e||[]),s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(t){n[t]&&(o[t]=function(e){return new Promise((function(r,o){s.push([t,e,r,o])>1||a(t,e)}))})}function a(t,e){try{!function(t){t.value instanceof h?Promise.resolve(t.value.v).then(u,c):l(s[0][2],t)}(n[t](e))}catch(t){l(s[0][3],t)}}function u(t){a("next",t)}function c(t){a("throw",t)}function l(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}!function(){const t={npm_package_version:"1.7.0"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}();class l{constructor(t){this.request=({method:t,path:e,data:r,params:o})=>u(this,void 0,void 0,(function*(){return this.client.request({method:t,path:e,data:r,params:o})})),this.paginatedRequest=({path:t,params:e})=>this.client.paginatedRequest({path:t,params:e}),this.client=t}}class f extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments/payment_intents"}}class p extends l{constructor(t){super(t),this.get=t=>u(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=>u(this,void 0,void 0,(function*(){const{return_offers:e}=t,r=a(t,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class d extends l{constructor(t){super(t),this.get=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:e})})),this.list=t=>{var{offer_request_id:e}=t,r=a(t,["offer_request_id"]);return this.request({method:"GET",path:this.path,params:Object.assign(Object.assign({},r),{offer_request_id:e})})},this.listWithGenerator=t=>{var{offer_request_id:e}=t,r=a(t,["offer_request_id"]);return this.paginatedRequest({path:this.path,params:Object.assign(Object.assign({},r),{offer_request_id:e})})},this.update=(t,e,r)=>u(this,void 0,void 0,(function*(){return this.request(Object.assign({method:"PATCH",path:`${this.path}/${t}/passengers/${e}`},r&&{data:r}))})),this.path="air/offers"}}class m extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class y extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>u(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=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:e}})})),this.path="air/orders"}}class b extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class g extends l{constructor(t){super(t),this.get=t=>u(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 v extends l{constructor(t){super(t),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`,data:e})})),this.path="air/order_changes"}}class w extends l{constructor(t){super(t),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class T extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}var O="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function j(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(r){var o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:function(){return t[r]}})})),e}var S=j(Object.freeze({__proto__:null,default:function(t,e){return e=e||{},new Promise((function(r,o){var n=new XMLHttpRequest,s=[],i=[],a={},u=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:u,headers:{keys:function(){return s},entries:function(){return i},get:function(t){return a[t.toLowerCase()]},has:function(t){return t.toLowerCase()in a}}}};for(var h in n.open(e.method||"get",t,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(t,e,r){s.push(e=e.toLowerCase()),i.push([e,r]),a[e]=a[e]?a[e]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==e.credentials,e.headers)n.setRequestHeader(h,e.headers[h]);n.send(e.body||null)}))}}));const P=t.Readable,$=Symbol("buffer"),E=Symbol("type");class q{constructor(){this[E]="";const t=arguments[0],e=arguments[1],r=[];let o=0;if(t){const e=t,n=Number(e.length);for(let t=0;t<n;t++){const n=e[t];let s;s=n instanceof Buffer?n:ArrayBuffer.isView(n)?Buffer.from(n.buffer,n.byteOffset,n.byteLength):n instanceof ArrayBuffer?Buffer.from(n):n instanceof q?n[$]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[$]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[E]=n)}get size(){return this[$].length}get type(){return this[E]}text(){return Promise.resolve(this[$].toString())}arrayBuffer(){const t=this[$],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new P;return t._read=function(){},t.push(this[$]),t.push(null),t}toString(){return"[object Blob]"}slice(){const t=this.size,e=arguments[0],r=arguments[1];let o,n;o=void 0===e?0:e<0?Math.max(t+e,0):Math.min(e,t),n=void 0===r?t:r<0?Math.max(t+r,0):Math.min(r,t);const s=Math.max(n-o,0),i=this[$].slice(o,o+s),a=new q([],{type:arguments[2]});return a[$]=i,a}}function x(t,e,r){Error.call(this,t),this.message=t,this.type=e,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let _;Object.defineProperties(q.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(q.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),x.prototype=Object.create(Error.prototype),x.prototype.constructor=x,x.prototype.name="FetchError";try{_=require("encoding").convert}catch(t){}const B=Symbol("Body internals"),C=t.PassThrough;function R(e){var r=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=o.size;let s=void 0===n?0:n;var i=o.timeout;let a=void 0===i?0:i;null==e?e=null:k(e)?e=Buffer.from(e.toString()):G(e)||Buffer.isBuffer(e)||("[object ArrayBuffer]"===Object.prototype.toString.call(e)?e=Buffer.from(e):ArrayBuffer.isView(e)?e=Buffer.from(e.buffer,e.byteOffset,e.byteLength):e instanceof t||(e=Buffer.from(String(e)))),this[B]={body:e,disturbed:!1,error:null},this.size=s,this.timeout=a,e instanceof t&&e.on("error",(function(t){const e="AbortError"===t.name?t:new x(`Invalid response body while trying to fetch ${r.url}: ${t.message}`,"system",t);r[B].error=e}))}function A(){var e=this;if(this[B].disturbed)return R.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[B].disturbed=!0,this[B].error)return R.Promise.reject(this[B].error);let r=this.body;if(null===r)return R.Promise.resolve(Buffer.alloc(0));if(G(r)&&(r=r.stream()),Buffer.isBuffer(r))return R.Promise.resolve(r);if(!(r instanceof t))return R.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new R.Promise((function(t,i){let a;e.timeout&&(a=setTimeout((function(){s=!0,i(new x(`Response timeout while trying to fetch ${e.url} (over ${e.timeout}ms)`,"body-timeout"))}),e.timeout)),r.on("error",(function(t){"AbortError"===t.name?(s=!0,i(t)):i(new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t))})),r.on("data",(function(t){if(!s&&null!==t){if(e.size&&n+t.length>e.size)return s=!0,void i(new x(`content size at ${e.url} over limit: ${e.size}`,"max-size"));n+=t.length,o.push(t)}})),r.on("end",(function(){if(!s){clearTimeout(a);try{t(Buffer.concat(o,n))}catch(t){i(new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function k(t){return"object"==typeof t&&"function"==typeof t.append&&"function"==typeof t.delete&&"function"==typeof t.get&&"function"==typeof t.getAll&&"function"==typeof t.has&&"function"==typeof t.set&&("URLSearchParams"===t.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(t)||"function"==typeof t.sort)}function G(t){return"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&"function"==typeof t.constructor&&"string"==typeof t.constructor.name&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag])}function L(e){let r,o,n=e.body;if(e.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof t&&"function"!=typeof n.getBoundary&&(r=new C,o=new C,n.pipe(r),n.pipe(o),e[B].body=r,n=o),n}function z(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":k(e)?"application/x-www-form-urlencoded;charset=UTF-8":G(e)?e.type||null:Buffer.isBuffer(e)||"[object ArrayBuffer]"===Object.prototype.toString.call(e)||ArrayBuffer.isView(e)?null:"function"==typeof e.getBoundary?`multipart/form-data;boundary=${e.getBoundary()}`:e instanceof t?null:"text/plain;charset=UTF-8"}function U(t){const e=t.body;return null===e?0:G(e)?e.size:Buffer.isBuffer(e)?e.length:e&&"function"==typeof e.getLengthSync&&(e._lengthRetrievers&&0==e._lengthRetrievers.length||e.hasKnownLength&&e.hasKnownLength())?e.getLengthSync():null}R.prototype={get body(){return this[B].body},get bodyUsed(){return this[B].disturbed},arrayBuffer(){return A.call(this).then((function(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}))},blob(){let t=this.headers&&this.headers.get("content-type")||"";return A.call(this).then((function(e){return Object.assign(new q([],{type:t.toLowerCase()}),{[$]:e})}))},json(){var t=this;return A.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return R.Promise.reject(new x(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return A.call(this).then((function(t){return t.toString()}))},buffer(){return A.call(this)},textConverted(){var t=this;return A.call(this).then((function(e){return function(t,e){if("function"!=typeof _)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=e.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=t.slice(0,1024).toString(),!o&&n&&(o=/<meta.+?charset=(['"])(.+?)\1/i.exec(n));!o&&n&&(o=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(n),o||(o=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(n),o&&o.pop()),o&&(o=/charset=(.*)/i.exec(o.pop())));!o&&n&&(o=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(n));o&&(s=o.pop(),"gb2312"!==s&&"gbk"!==s||(s="gb18030"));return _(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(R.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),R.mixIn=function(t){for(const e of Object.getOwnPropertyNames(R.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(R.prototype,e);Object.defineProperty(t,e,r)}},R.Promise=global.Promise;const H=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,I=/[^\t\x20-\x7e\x80-\xff]/;function F(t){if(t=`${t}`,H.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function M(t){if(t=`${t}`,I.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function D(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const V=Symbol("map");class N{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[V]=Object.create(null),t instanceof N){const e=t.raw(),r=Object.keys(e);for(const t of r)for(const r of e[t])this.append(t,r)}else if(null==t);else{if("object"!=typeof t)throw new TypeError("Provided initializer must be an object");{const e=t[Symbol.iterator];if(null!=e){if("function"!=typeof e)throw new TypeError("Header pairs must be iterable");const r=[];for(const e of t){if("object"!=typeof e||"function"!=typeof e[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(e))}for(const t of r){if(2!==t.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(t[0],t[1])}}else for(const e of Object.keys(t)){const r=t[e];this.append(e,r)}}}}get(t){F(t=`${t}`);const e=D(this[V],t);return void 0===e?null:this[V][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=W(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];t.call(e,i,s,this),r=W(this),o++}}set(t,e){e=`${e}`,F(t=`${t}`),M(e);const r=D(this[V],t);this[V][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,F(t=`${t}`),M(e);const r=D(this[V],t);void 0!==r?this[V][r].push(e):this[V][t]=[e]}has(t){return F(t=`${t}`),void 0!==D(this[V],t)}delete(t){F(t=`${t}`);const e=D(this[V],t);void 0!==e&&delete this[V][e]}raw(){return this[V]}keys(){return Z(this,"key")}values(){return Z(this,"value")}[Symbol.iterator](){return Z(this,"key+value")}}function W(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[V]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[V][e].join(", ")}:function(e){return[e.toLowerCase(),t[V][e].join(", ")]})}N.prototype.entries=N.prototype[Symbol.iterator],Object.defineProperty(N.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(N.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});const J=Symbol("internal");function Z(t,e){const r=Object.create(K);return r[J]={target:t,kind:e,index:0},r}const K=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==K)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[J];const e=t.target,r=t.kind,o=t.index,n=W(e,r);return o>=n.length?{value:void 0,done:!0}:(this[J].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function Y(t){const e=Object.assign({__proto__:null},t[V]),r=D(t[V],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(K,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const Q=Symbol("Response internals"),X=e.STATUS_CODES;class tt{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R.call(this,t,e);const r=e.status||200,o=new N(e.headers);if(null!=t&&!o.has("Content-Type")){const e=z(t);e&&o.append("Content-Type",e)}this[Q]={url:e.url,status:r,statusText:e.statusText||X[r],headers:o,counter:e.counter}}get url(){return this[Q].url||""}get status(){return this[Q].status}get ok(){return this[Q].status>=200&&this[Q].status<300}get redirected(){return this[Q].counter>0}get statusText(){return this[Q].statusText}get headers(){return this[Q].headers}clone(){return new tt(L(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}R.mixIn(tt.prototype),Object.defineProperties(tt.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(tt.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const et=Symbol("Request internals"),rt=r.parse,ot=r.format,nt="destroy"in t.Readable.prototype;function st(t){return"object"==typeof t&&"object"==typeof t[et]}class it{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};st(t)?e=rt(t.url):(e=t&&t.href?rt(t.href):rt(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||st(t)&&null!==t.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:st(t)&&null!==t.body?L(t):null;R.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new N(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=z(n);t&&s.append("Content-Type",t)}let i=st(t)?t.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(t){const e=t&&"object"==typeof t&&Object.getPrototypeOf(t);return!(!e||"AbortSignal"!==e.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[et]={method:o,redirect:r.redirect||t.redirect||"follow",headers:s,parsedURL:e,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==t.follow?t.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===t.compress||t.compress,this.counter=r.counter||t.counter||0,this.agent=r.agent||t.agent}get method(){return this[et].method}get url(){return ot(this[et].parsedURL)}get headers(){return this[et].headers}get redirect(){return this[et].redirect}get signal(){return this[et].signal}clone(){return new it(this)}}function at(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}R.mixIn(it.prototype),Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(it.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),at.prototype=Object.create(Error.prototype),at.prototype.constructor=at,at.prototype.name="AbortError";const ut=t.PassThrough,ht=r.resolve;function ct(r,o){if(!ct.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return R.Promise=ct.Promise,new ct.Promise((function(n,a){const u=new it(r,o),h=function(e){const r=e[et].parsedURL,o=new N(e[et].headers);if(o.has("Accept")||o.set("Accept","*/*"),!r.protocol||!r.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(r.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(e.signal&&e.body instanceof t.Readable&&!nt)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==e.body&&/^(POST|PUT)$/i.test(e.method)&&(n="0"),null!=e.body){const t=U(e);"number"==typeof t&&(n=String(t))}n&&o.set("Content-Length",n),o.has("User-Agent")||o.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),e.compress&&!o.has("Accept-Encoding")&&o.set("Accept-Encoding","gzip,deflate");let s=e.agent;return"function"==typeof s&&(s=s(r)),o.has("Connection")||s||o.set("Connection","close"),Object.assign({},r,{method:e.method,headers:Y(o),agent:s})}(u),c=("https:"===h.protocol?s:e).request,l=u.signal;let f=null;const p=function(){let e=new at("The user aborted a request.");a(e),u.body&&u.body instanceof t.Readable&&u.body.destroy(e),f&&f.body&&f.body.emit("error",e)};if(l&&l.aborted)return void p();const d=function(){p(),b()},m=c(h);let y;function b(){m.abort(),l&&l.removeEventListener("abort",d),clearTimeout(y)}l&&l.addEventListener("abort",d),u.timeout&&m.once("socket",(function(t){y=setTimeout((function(){a(new x(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(t){a(new x(`request to ${u.url} failed, reason: ${t.message}`,"system",t)),b()})),m.on("response",(function(t){clearTimeout(y);const e=function(t){const e=new N;for(const r of Object.keys(t))if(!H.test(r))if(Array.isArray(t[r]))for(const o of t[r])I.test(o)||(void 0===e[V][r]?e[V][r]=[o]:e[V][r].push(o));else I.test(t[r])||(e[V][r]=[t[r]]);return e}(t.headers);if(ct.isRedirect(t.statusCode)){const r=e.get("Location"),o=null===r?null:ht(u.url,r);switch(u.redirect){case"error":return a(new x(`uri requested responds with a redirect, redirect mode is set to error: ${u.url}`,"no-redirect")),void b();case"manual":if(null!==o)try{e.set("Location",o)}catch(t){a(t)}break;case"follow":if(null===o)break;if(u.counter>=u.follow)return a(new x(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new N(u.headers),follow:u.follow,counter:u.counter+1,agent:u.agent,compress:u.compress,method:u.method,body:u.body,signal:u.signal,timeout:u.timeout,size:u.size};return 303!==t.statusCode&&u.body&&null===U(u)?(a(new x("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==u.method)||(r.method="GET",r.body=void 0,r.headers.delete("content-length")),n(ct(new it(o,r))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=t.pipe(new ut);const o={url:u.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:u.size,timeout:u.timeout,counter:u.counter},s=e.get("Content-Encoding");if(!u.compress||"HEAD"===u.method||null===s||204===t.statusCode||304===t.statusCode)return f=new tt(r,o),void n(f);const h={flush:i.Z_SYNC_FLUSH,finishFlush:i.Z_SYNC_FLUSH};if("gzip"==s||"x-gzip"==s)return r=r.pipe(i.createGunzip(h)),f=new tt(r,o),void n(f);if("deflate"!=s&&"x-deflate"!=s){if("br"==s&&"function"==typeof i.createBrotliDecompress)return r=r.pipe(i.createBrotliDecompress()),f=new tt(r,o),void n(f);f=new tt(r,o),n(f)}else{t.pipe(new ut).once("data",(function(t){r=8==(15&t[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new tt(r,o),n(f)}))}})),function(t,e){const r=e.body;null===r?t.end():G(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,u)}))}ct.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},ct.Promise=global.Promise;var lt=j(Object.freeze({__proto__:null,default:ct,Headers:N,Request:it,Response:tt,FetchError:x}));function ft(t){return t&&t.default||t}var pt=O.fetch=O.fetch||("undefined"==typeof process?ft(S):function(t,e){return ft(lt)(String(t).replace(/^\/\//g,"https://"),e)});class dt extends Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class mt{constructor({token:t,basePath:e,apiVersion:r,debug:s}){this.request=({method:t,path:e,data:r,params:s,compress:i=!0})=>u(this,void 0,void 0,(function*(){var a;let u,h;const c=new o(e,this.basePath),l={"User-Agent":`Duffel/${this.apiVersion} duffel_api_javascript/${process.env.npm_package_version}`,Accept:"application/json","Accept-Encoding":"gzip","Content-Type":"application/json","Duffel-Version":this.apiVersion,Authorization:`Bearer ${this.token}`};if(s){const t=Object.entries(s).sort().filter((t=>null!==t[0]));c.search=new n(t).toString()}r&&(u=JSON.stringify({data:Object.assign({},r)})),(null===(a=this.debug)||void 0===a?void 0:a.verbose)&&(console.info("Endpoint: ",c.href),console.info("Method: ",t),r&&console.info("Body Parameters: ",r),s&&console.info("Query Parameters: ",s));const f=yield pt(c.href,{method:t,headers:l,body:u,compress:i}),p=f.headers.get("content-type");if(h=p&&p.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in h&&h.errors)throw new dt(h);return h})),this.token=t,this.basePath=e||"https://api.duffel.com",this.apiVersion=r||"beta",this.debug=s}paginatedRequest({path:t,params:e}){return c(this,arguments,(function*(){let r=yield h(this.request({method:"GET",path:t,params:e}));for(const t of r.data)yield yield h({data:t});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield h(this.request({method:"GET",path:t,params:{limit:r.meta.limit,after:r.meta.after}}));for(const t of r.data)yield yield h({data:t})}}))}}class yt extends l{constructor(t){super(t),this.get=t=>u(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 bt extends l{constructor(t){super(t),this.get=t=>u(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 gt extends l{constructor(t){super(t),this.get=t=>u(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 vt{constructor(t){this.client=new mt(t),this.aircraft=new yt(this.client),this.airlines=new bt(this.client),this.airports=new gt(this.client),this.offerRequests=new p(this.client),this.offers=new d(this.client),this.orders=new y(this.client),this.orderChangeRequests=new b(this.client),this.orderChangeOffers=new g(this.client),this.orderChanges=new v(this.client),this.orderCancellations=new m(this.client),this.payments=new w(this.client),this.seatMaps=new T(this.client),this.paymentIntents=new f(this.client)}}export{vt as Duffel};
1
+ import t from"stream";import e from"http";import r,{URL as o,URLSearchParams as n}from"url";import s from"https";import i from"zlib";function a(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(t);n<o.length;n++)e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(t,o[n])&&(r[o[n]]=t[o[n]])}return r}function u(t,e,r,o){return new(r||(r=Promise))((function(n,s){function i(t){try{u(o.next(t))}catch(t){s(t)}}function a(t){try{u(o.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(i,a)}u((o=o.apply(t,e||[])).next())}))}function h(t){return this instanceof h?(this.v=t,this):new h(t)}function c(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=r.apply(t,e||[]),s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(t){n[t]&&(o[t]=function(e){return new Promise((function(r,o){s.push([t,e,r,o])>1||a(t,e)}))})}function a(t,e){try{!function(t){t.value instanceof h?Promise.resolve(t.value.v).then(u,c):l(s[0][2],t)}(n[t](e))}catch(t){l(s[0][3],t)}}function u(t){a("next",t)}function c(t){a("throw",t)}function l(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}!function(){const t={npm_package_version:"1.7.4"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}();class l{constructor(t){this.request=({method:t,path:e,data:r,params:o})=>u(this,void 0,void 0,(function*(){return this.client.request({method:t,path:e,data:r,params:o})})),this.paginatedRequest=({path:t,params:e})=>this.client.paginatedRequest({path:t,params:e}),this.client=t}}class f extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="payments/payment_intents"}}class p extends l{constructor(t){super(t),this.get=t=>u(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=>u(this,void 0,void 0,(function*(){const{return_offers:e}=t,r=a(t,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class d extends l{constructor(t){super(t),this.get=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`,params:e})})),this.list=t=>{var{offer_request_id:e}=t,r=a(t,["offer_request_id"]);return this.request({method:"GET",path:this.path,params:Object.assign(Object.assign({},r),{offer_request_id:e})})},this.listWithGenerator=t=>{var{offer_request_id:e}=t,r=a(t,["offer_request_id"]);return this.paginatedRequest({path:this.path,params:Object.assign(Object.assign({},r),{offer_request_id:e})})},this.update=(t,e,r)=>u(this,void 0,void 0,(function*(){return this.request(Object.assign({method:"PATCH",path:`${this.path}/${t}/passengers/${e}`},r&&{data:r}))})),this.path="air/offers"}}class m extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class y extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>u(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=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:e}})})),this.path="air/orders"}}class b extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class g extends l{constructor(t){super(t),this.get=t=>u(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 v extends l{constructor(t){super(t),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,e)=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`,data:e})})),this.path="air/order_changes"}}class w extends l{constructor(t){super(t),this.create=t=>u(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class T extends l{constructor(t){super(t),this.get=t=>u(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}var O="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function j(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(r){var o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:function(){return t[r]}})})),e}var S=j(Object.freeze({__proto__:null,default:function(t,e){return e=e||{},new Promise((function(r,o){var n=new XMLHttpRequest,s=[],i=[],a={},u=function(){return{ok:2==(n.status/100|0),statusText:n.statusText,status:n.status,url:n.responseURL,text:function(){return Promise.resolve(n.responseText)},json:function(){return Promise.resolve(n.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([n.response]))},clone:u,headers:{keys:function(){return s},entries:function(){return i},get:function(t){return a[t.toLowerCase()]},has:function(t){return t.toLowerCase()in a}}}};for(var h in n.open(e.method||"get",t,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(t,e,r){s.push(e=e.toLowerCase()),i.push([e,r]),a[e]=a[e]?a[e]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==e.credentials,e.headers)n.setRequestHeader(h,e.headers[h]);n.send(e.body||null)}))}}));const P=t.Readable,$=Symbol("buffer"),E=Symbol("type");class q{constructor(){this[E]="";const t=arguments[0],e=arguments[1],r=[];let o=0;if(t){const e=t,n=Number(e.length);for(let t=0;t<n;t++){const n=e[t];let s;s=n instanceof Buffer?n:ArrayBuffer.isView(n)?Buffer.from(n.buffer,n.byteOffset,n.byteLength):n instanceof ArrayBuffer?Buffer.from(n):n instanceof q?n[$]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[$]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[E]=n)}get size(){return this[$].length}get type(){return this[E]}text(){return Promise.resolve(this[$].toString())}arrayBuffer(){const t=this[$],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new P;return t._read=function(){},t.push(this[$]),t.push(null),t}toString(){return"[object Blob]"}slice(){const t=this.size,e=arguments[0],r=arguments[1];let o,n;o=void 0===e?0:e<0?Math.max(t+e,0):Math.min(e,t),n=void 0===r?t:r<0?Math.max(t+r,0):Math.min(r,t);const s=Math.max(n-o,0),i=this[$].slice(o,o+s),a=new q([],{type:arguments[2]});return a[$]=i,a}}function x(t,e,r){Error.call(this,t),this.message=t,this.type=e,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let _;Object.defineProperties(q.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(q.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),x.prototype=Object.create(Error.prototype),x.prototype.constructor=x,x.prototype.name="FetchError";try{_=require("encoding").convert}catch(t){}const B=Symbol("Body internals"),C=t.PassThrough;function R(e){var r=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=o.size;let s=void 0===n?0:n;var i=o.timeout;let a=void 0===i?0:i;null==e?e=null:k(e)?e=Buffer.from(e.toString()):G(e)||Buffer.isBuffer(e)||("[object ArrayBuffer]"===Object.prototype.toString.call(e)?e=Buffer.from(e):ArrayBuffer.isView(e)?e=Buffer.from(e.buffer,e.byteOffset,e.byteLength):e instanceof t||(e=Buffer.from(String(e)))),this[B]={body:e,disturbed:!1,error:null},this.size=s,this.timeout=a,e instanceof t&&e.on("error",(function(t){const e="AbortError"===t.name?t:new x(`Invalid response body while trying to fetch ${r.url}: ${t.message}`,"system",t);r[B].error=e}))}function A(){var e=this;if(this[B].disturbed)return R.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[B].disturbed=!0,this[B].error)return R.Promise.reject(this[B].error);let r=this.body;if(null===r)return R.Promise.resolve(Buffer.alloc(0));if(G(r)&&(r=r.stream()),Buffer.isBuffer(r))return R.Promise.resolve(r);if(!(r instanceof t))return R.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new R.Promise((function(t,i){let a;e.timeout&&(a=setTimeout((function(){s=!0,i(new x(`Response timeout while trying to fetch ${e.url} (over ${e.timeout}ms)`,"body-timeout"))}),e.timeout)),r.on("error",(function(t){"AbortError"===t.name?(s=!0,i(t)):i(new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t))})),r.on("data",(function(t){if(!s&&null!==t){if(e.size&&n+t.length>e.size)return s=!0,void i(new x(`content size at ${e.url} over limit: ${e.size}`,"max-size"));n+=t.length,o.push(t)}})),r.on("end",(function(){if(!s){clearTimeout(a);try{t(Buffer.concat(o,n))}catch(t){i(new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function k(t){return"object"==typeof t&&"function"==typeof t.append&&"function"==typeof t.delete&&"function"==typeof t.get&&"function"==typeof t.getAll&&"function"==typeof t.has&&"function"==typeof t.set&&("URLSearchParams"===t.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(t)||"function"==typeof t.sort)}function G(t){return"object"==typeof t&&"function"==typeof t.arrayBuffer&&"string"==typeof t.type&&"function"==typeof t.stream&&"function"==typeof t.constructor&&"string"==typeof t.constructor.name&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag])}function L(e){let r,o,n=e.body;if(e.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof t&&"function"!=typeof n.getBoundary&&(r=new C,o=new C,n.pipe(r),n.pipe(o),e[B].body=r,n=o),n}function z(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":k(e)?"application/x-www-form-urlencoded;charset=UTF-8":G(e)?e.type||null:Buffer.isBuffer(e)||"[object ArrayBuffer]"===Object.prototype.toString.call(e)||ArrayBuffer.isView(e)?null:"function"==typeof e.getBoundary?`multipart/form-data;boundary=${e.getBoundary()}`:e instanceof t?null:"text/plain;charset=UTF-8"}function U(t){const e=t.body;return null===e?0:G(e)?e.size:Buffer.isBuffer(e)?e.length:e&&"function"==typeof e.getLengthSync&&(e._lengthRetrievers&&0==e._lengthRetrievers.length||e.hasKnownLength&&e.hasKnownLength())?e.getLengthSync():null}R.prototype={get body(){return this[B].body},get bodyUsed(){return this[B].disturbed},arrayBuffer(){return A.call(this).then((function(t){return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}))},blob(){let t=this.headers&&this.headers.get("content-type")||"";return A.call(this).then((function(e){return Object.assign(new q([],{type:t.toLowerCase()}),{[$]:e})}))},json(){var t=this;return A.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return R.Promise.reject(new x(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return A.call(this).then((function(t){return t.toString()}))},buffer(){return A.call(this)},textConverted(){var t=this;return A.call(this).then((function(e){return function(t,e){if("function"!=typeof _)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=e.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=t.slice(0,1024).toString(),!o&&n&&(o=/<meta.+?charset=(['"])(.+?)\1/i.exec(n));!o&&n&&(o=/<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(n),o||(o=/<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(n),o&&o.pop()),o&&(o=/charset=(.*)/i.exec(o.pop())));!o&&n&&(o=/<\?xml.+?encoding=(['"])(.+?)\1/i.exec(n));o&&(s=o.pop(),"gb2312"!==s&&"gbk"!==s||(s="gb18030"));return _(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(R.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),R.mixIn=function(t){for(const e of Object.getOwnPropertyNames(R.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(R.prototype,e);Object.defineProperty(t,e,r)}},R.Promise=global.Promise;const H=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,I=/[^\t\x20-\x7e\x80-\xff]/;function F(t){if(t=`${t}`,H.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function M(t){if(t=`${t}`,I.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function D(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const V=Symbol("map");class N{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[V]=Object.create(null),t instanceof N){const e=t.raw(),r=Object.keys(e);for(const t of r)for(const r of e[t])this.append(t,r)}else if(null==t);else{if("object"!=typeof t)throw new TypeError("Provided initializer must be an object");{const e=t[Symbol.iterator];if(null!=e){if("function"!=typeof e)throw new TypeError("Header pairs must be iterable");const r=[];for(const e of t){if("object"!=typeof e||"function"!=typeof e[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(e))}for(const t of r){if(2!==t.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(t[0],t[1])}}else for(const e of Object.keys(t)){const r=t[e];this.append(e,r)}}}}get(t){F(t=`${t}`);const e=D(this[V],t);return void 0===e?null:this[V][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=W(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];t.call(e,i,s,this),r=W(this),o++}}set(t,e){e=`${e}`,F(t=`${t}`),M(e);const r=D(this[V],t);this[V][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,F(t=`${t}`),M(e);const r=D(this[V],t);void 0!==r?this[V][r].push(e):this[V][t]=[e]}has(t){return F(t=`${t}`),void 0!==D(this[V],t)}delete(t){F(t=`${t}`);const e=D(this[V],t);void 0!==e&&delete this[V][e]}raw(){return this[V]}keys(){return Z(this,"key")}values(){return Z(this,"value")}[Symbol.iterator](){return Z(this,"key+value")}}function W(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[V]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[V][e].join(", ")}:function(e){return[e.toLowerCase(),t[V][e].join(", ")]})}N.prototype.entries=N.prototype[Symbol.iterator],Object.defineProperty(N.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(N.prototype,{get:{enumerable:!0},forEach:{enumerable:!0},set:{enumerable:!0},append:{enumerable:!0},has:{enumerable:!0},delete:{enumerable:!0},keys:{enumerable:!0},values:{enumerable:!0},entries:{enumerable:!0}});const J=Symbol("internal");function Z(t,e){const r=Object.create(K);return r[J]={target:t,kind:e,index:0},r}const K=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==K)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[J];const e=t.target,r=t.kind,o=t.index,n=W(e,r);return o>=n.length?{value:void 0,done:!0}:(this[J].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function Y(t){const e=Object.assign({__proto__:null},t[V]),r=D(t[V],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(K,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const Q=Symbol("Response internals"),X=e.STATUS_CODES;class tt{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};R.call(this,t,e);const r=e.status||200,o=new N(e.headers);if(null!=t&&!o.has("Content-Type")){const e=z(t);e&&o.append("Content-Type",e)}this[Q]={url:e.url,status:r,statusText:e.statusText||X[r],headers:o,counter:e.counter}}get url(){return this[Q].url||""}get status(){return this[Q].status}get ok(){return this[Q].status>=200&&this[Q].status<300}get redirected(){return this[Q].counter>0}get statusText(){return this[Q].statusText}get headers(){return this[Q].headers}clone(){return new tt(L(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}R.mixIn(tt.prototype),Object.defineProperties(tt.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(tt.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const et=Symbol("Request internals"),rt=r.parse,ot=r.format,nt="destroy"in t.Readable.prototype;function st(t){return"object"==typeof t&&"object"==typeof t[et]}class it{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};st(t)?e=rt(t.url):(e=t&&t.href?rt(t.href):rt(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||st(t)&&null!==t.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:st(t)&&null!==t.body?L(t):null;R.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new N(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=z(n);t&&s.append("Content-Type",t)}let i=st(t)?t.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(t){const e=t&&"object"==typeof t&&Object.getPrototypeOf(t);return!(!e||"AbortSignal"!==e.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[et]={method:o,redirect:r.redirect||t.redirect||"follow",headers:s,parsedURL:e,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==t.follow?t.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===t.compress||t.compress,this.counter=r.counter||t.counter||0,this.agent=r.agent||t.agent}get method(){return this[et].method}get url(){return ot(this[et].parsedURL)}get headers(){return this[et].headers}get redirect(){return this[et].redirect}get signal(){return this[et].signal}clone(){return new it(this)}}function at(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}R.mixIn(it.prototype),Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(it.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),at.prototype=Object.create(Error.prototype),at.prototype.constructor=at,at.prototype.name="AbortError";const ut=t.PassThrough,ht=r.resolve;function ct(r,o){if(!ct.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return R.Promise=ct.Promise,new ct.Promise((function(n,a){const u=new it(r,o),h=function(e){const r=e[et].parsedURL,o=new N(e[et].headers);if(o.has("Accept")||o.set("Accept","*/*"),!r.protocol||!r.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(r.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(e.signal&&e.body instanceof t.Readable&&!nt)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==e.body&&/^(POST|PUT)$/i.test(e.method)&&(n="0"),null!=e.body){const t=U(e);"number"==typeof t&&(n=String(t))}n&&o.set("Content-Length",n),o.has("User-Agent")||o.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),e.compress&&!o.has("Accept-Encoding")&&o.set("Accept-Encoding","gzip,deflate");let s=e.agent;return"function"==typeof s&&(s=s(r)),o.has("Connection")||s||o.set("Connection","close"),Object.assign({},r,{method:e.method,headers:Y(o),agent:s})}(u),c=("https:"===h.protocol?s:e).request,l=u.signal;let f=null;const p=function(){let e=new at("The user aborted a request.");a(e),u.body&&u.body instanceof t.Readable&&u.body.destroy(e),f&&f.body&&f.body.emit("error",e)};if(l&&l.aborted)return void p();const d=function(){p(),b()},m=c(h);let y;function b(){m.abort(),l&&l.removeEventListener("abort",d),clearTimeout(y)}l&&l.addEventListener("abort",d),u.timeout&&m.once("socket",(function(t){y=setTimeout((function(){a(new x(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(t){a(new x(`request to ${u.url} failed, reason: ${t.message}`,"system",t)),b()})),m.on("response",(function(t){clearTimeout(y);const e=function(t){const e=new N;for(const r of Object.keys(t))if(!H.test(r))if(Array.isArray(t[r]))for(const o of t[r])I.test(o)||(void 0===e[V][r]?e[V][r]=[o]:e[V][r].push(o));else I.test(t[r])||(e[V][r]=[t[r]]);return e}(t.headers);if(ct.isRedirect(t.statusCode)){const r=e.get("Location"),o=null===r?null:ht(u.url,r);switch(u.redirect){case"error":return a(new x(`uri requested responds with a redirect, redirect mode is set to error: ${u.url}`,"no-redirect")),void b();case"manual":if(null!==o)try{e.set("Location",o)}catch(t){a(t)}break;case"follow":if(null===o)break;if(u.counter>=u.follow)return a(new x(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new N(u.headers),follow:u.follow,counter:u.counter+1,agent:u.agent,compress:u.compress,method:u.method,body:u.body,signal:u.signal,timeout:u.timeout,size:u.size};return 303!==t.statusCode&&u.body&&null===U(u)?(a(new x("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==u.method)||(r.method="GET",r.body=void 0,r.headers.delete("content-length")),n(ct(new it(o,r))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=t.pipe(new ut);const o={url:u.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:u.size,timeout:u.timeout,counter:u.counter},s=e.get("Content-Encoding");if(!u.compress||"HEAD"===u.method||null===s||204===t.statusCode||304===t.statusCode)return f=new tt(r,o),void n(f);const h={flush:i.Z_SYNC_FLUSH,finishFlush:i.Z_SYNC_FLUSH};if("gzip"==s||"x-gzip"==s)return r=r.pipe(i.createGunzip(h)),f=new tt(r,o),void n(f);if("deflate"!=s&&"x-deflate"!=s){if("br"==s&&"function"==typeof i.createBrotliDecompress)return r=r.pipe(i.createBrotliDecompress()),f=new tt(r,o),void n(f);f=new tt(r,o),n(f)}else{t.pipe(new ut).once("data",(function(t){r=8==(15&t[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new tt(r,o),n(f)}))}})),function(t,e){const r=e.body;null===r?t.end():G(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,u)}))}ct.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},ct.Promise=global.Promise;var lt=j(Object.freeze({__proto__:null,default:ct,Headers:N,Request:it,Response:tt,FetchError:x}));function ft(t){return t&&t.default||t}var pt=O.fetch=O.fetch||("undefined"==typeof process?ft(S):function(t,e){return ft(lt)(String(t).replace(/^\/\//g,"https://"),e)});class dt extends Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class mt{constructor({token:t,basePath:e,apiVersion:r,debug:s}){this.request=({method:t,path:e,data:r,params:s,compress:i=!0})=>u(this,void 0,void 0,(function*(){var a;let u,h;const c=new o(e,this.basePath),l={"User-Agent":`Duffel/${this.apiVersion} duffel_api_javascript/${process.env.npm_package_version}`,Accept:"application/json","Accept-Encoding":"gzip","Content-Type":"application/json","Duffel-Version":this.apiVersion,Authorization:`Bearer ${this.token}`};if(s){const t=Object.entries(s).sort().filter((t=>null!==t[0]));c.search=new n(t).toString()}r&&(u=JSON.stringify({data:Object.assign({},r)})),(null===(a=this.debug)||void 0===a?void 0:a.verbose)&&(console.info("Endpoint: ",c.href),console.info("Method: ",t),r&&console.info("Body Parameters: ",r),s&&console.info("Query Parameters: ",s));const f=yield pt(c.href,{method:t,headers:l,body:u,compress:i}),p=f.headers.get("content-type");if(h=p&&p.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in h&&h.errors)throw new dt(h);return h})),this.token=t,this.basePath=e||"https://api.duffel.com",this.apiVersion=r||"beta",this.debug=s}paginatedRequest({path:t,params:e}){return c(this,arguments,(function*(){let r=yield h(this.request({method:"GET",path:t,params:e}));for(const t of r.data)yield yield h({data:t});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield h(this.request({method:"GET",path:t,params:{limit:r.meta.limit,after:r.meta.after}}));for(const t of r.data)yield yield h({data:t})}}))}}class yt extends l{constructor(t){super(t),this.get=t=>u(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 bt extends l{constructor(t){super(t),this.get=t=>u(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 gt extends l{constructor(t){super(t),this.get=t=>u(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 vt{constructor(t){this.client=new mt(t),this.aircraft=new yt(this.client),this.airlines=new bt(this.client),this.airports=new gt(this.client),this.offerRequests=new p(this.client),this.offers=new d(this.client),this.orders=new y(this.client),this.orderChangeRequests=new b(this.client),this.orderChangeOffers=new g(this.client),this.orderChanges=new v(this.client),this.orderCancellations=new m(this.client),this.payments=new w(this.client),this.seatMaps=new T(this.client),this.paymentIntents=new f(this.client)}}export{vt as Duffel};
2
2
  //# sourceMappingURL=index.es.js.map