@duffel/api
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -1,2 +0,2 @@ | ||
import { CabinClass, FlightsConditions, PassengerIdentityDocumentType, Place, PlaceType, Aircraft, Airline, Airport, PaginationMeta } from '../../types'; | ||
import { CabinClass, FlightsConditions, LoyaltyProgrammeAccount, PassengerIdentityDocumentType, Place, PlaceType, Aircraft, Airline, Airport, PaginationMeta } from '../../types'; | ||
/** | ||
@@ -197,2 +197,24 @@ * Each offer represents flights you can buy from an airline at a particular price that meet your search criteria. | ||
/** | ||
* 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**. | ||
*/ | ||
family_name?: string; | ||
/** | ||
* 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**. | ||
*/ | ||
given_name?: string; | ||
/** | ||
* The **Loyalty Programme Accounts** for this passenger. | ||
*/ | ||
loyalty_programme_accounts?: LoyaltyProgrammeAccount[]; | ||
/** | ||
* The identifier for the passenger, unique within this Offer Request and across all Offer Requests. | ||
@@ -199,0 +221,0 @@ * This ID will be generated by Duffel unless you had optionally provided one. |
@@ -1,2 +0,2 @@ | ||
import { Aircraft, Airline, CabinClass, DuffelPassengerGender, DuffelPassengerTitle, DuffelPassengerType, FlightsConditions, OfferAvailableServiceBaggageMetadata, PassengerIdentityDocumentType, PaymentType, Place, PlaceType } from '../../types'; | ||
import { Aircraft, Airline, CabinClass, DuffelPassengerGender, DuffelPassengerTitle, DuffelPassengerType, FlightsConditions, LoyaltyProgrammeAccount, OfferAvailableServiceBaggageMetadata, PassengerIdentityDocumentType, PaymentType, Place, PlaceType } from '../../types'; | ||
/** | ||
@@ -143,2 +143,6 @@ * An object containing metadata about the service, like the designator of the seat. | ||
infant_passenger_id?: string | null; | ||
/** | ||
* The **Loyalty Programme Accounts** for this passenger. | ||
*/ | ||
loyalty_programme_accounts?: LoyaltyProgrammeAccount[]; | ||
} | ||
@@ -145,0 +149,0 @@ export interface OrderPassengerIdentityDocument { |
@@ -1,2 +0,2 @@ | ||
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.5.1"};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 Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class d extends Error{constructor(t){super("Invalid data: "+t),this.name="ValidationError"}}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.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 r.passengers&&r.passengers.forEach((t=>{if(t.loyalty_programme_accounts&&t.loyalty_programme_accounts.length>0&&(!t.given_name||!t.family_name))throw new d("loyalty programme requires family_name and given_name parameters")})),this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class y 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 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.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 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=>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 v 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 w 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 T 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 O 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 j 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 S="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function E(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 P=E(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 $=t.Readable,q=Symbol("buffer"),x=Symbol("type");class _{constructor(){this[x]="";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 _?n[q]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[q]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[x]=n)}get size(){return this[q].length}get type(){return this[x]}text(){return Promise.resolve(this[q].toString())}arrayBuffer(){const t=this[q],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new $;return t._read=function(){},t.push(this[q]),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[q].slice(o,o+s),a=new _([],{type:arguments[2]});return a[q]=i,a}}function B(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 C;Object.defineProperties(_.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(_.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),B.prototype=Object.create(Error.prototype),B.prototype.constructor=B,B.prototype.name="FetchError";try{C=require("encoding").convert}catch(t){}const R=Symbol("Body internals"),A=t.PassThrough;function k(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:L(e)?e=Buffer.from(e.toString()):z(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[R]={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 B(`Invalid response body while trying to fetch ${r.url}: ${t.message}`,"system",t);r[R].error=e}))}function G(){var e=this;if(this[R].disturbed)return k.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[R].disturbed=!0,this[R].error)return k.Promise.reject(this[R].error);let r=this.body;if(null===r)return k.Promise.resolve(Buffer.alloc(0));if(z(r)&&(r=r.stream()),Buffer.isBuffer(r))return k.Promise.resolve(r);if(!(r instanceof t))return k.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new k.Promise((function(t,i){let a;e.timeout&&(a=setTimeout((function(){s=!0,i(new B(`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 B(`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 B(`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 B(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function L(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 z(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 U(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 A,o=new A,n.pipe(r),n.pipe(o),e[R].body=r,n=o),n}function H(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":L(e)?"application/x-www-form-urlencoded;charset=UTF-8":z(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 I(t){const e=t.body;return null===e?0:z(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}k.prototype={get body(){return this[R].body},get bodyUsed(){return this[R].disturbed},arrayBuffer(){return G.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 G.call(this).then((function(e){return Object.assign(new _([],{type:t.toLowerCase()}),{[q]:e})}))},json(){var t=this;return G.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return k.Promise.reject(new B(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return G.call(this).then((function(t){return t.toString()}))},buffer(){return G.call(this)},textConverted(){var t=this;return G.call(this).then((function(e){return function(t,e){if("function"!=typeof C)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 C(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(k.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),k.mixIn=function(t){for(const e of Object.getOwnPropertyNames(k.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(k.prototype,e);Object.defineProperty(t,e,r)}},k.Promise=global.Promise;const F=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,M=/[^\t\x20-\x7e\x80-\xff]/;function D(t){if(t=`${t}`,F.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function V(t){if(t=`${t}`,M.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function N(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const W=Symbol("map");class J{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[W]=Object.create(null),t instanceof J){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){D(t=`${t}`);const e=N(this[W],t);return void 0===e?null:this[W][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=Z(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=Z(this),o++}}set(t,e){e=`${e}`,D(t=`${t}`),V(e);const r=N(this[W],t);this[W][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,D(t=`${t}`),V(e);const r=N(this[W],t);void 0!==r?this[W][r].push(e):this[W][t]=[e]}has(t){return D(t=`${t}`),void 0!==N(this[W],t)}delete(t){D(t=`${t}`);const e=N(this[W],t);void 0!==e&&delete this[W][e]}raw(){return this[W]}keys(){return Y(this,"key")}values(){return Y(this,"value")}[Symbol.iterator](){return Y(this,"key+value")}}function Z(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[W]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[W][e].join(", ")}:function(e){return[e.toLowerCase(),t[W][e].join(", ")]})}J.prototype.entries=J.prototype[Symbol.iterator],Object.defineProperty(J.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(J.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 K=Symbol("internal");function Y(t,e){const r=Object.create(Q);return r[K]={target:t,kind:e,index:0},r}const Q=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==Q)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[K];const e=t.target,r=t.kind,o=t.index,n=Z(e,r);return o>=n.length?{value:void 0,done:!0}:(this[K].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function X(t){const e=Object.assign({__proto__:null},t[W]),r=N(t[W],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(Q,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const tt=Symbol("Response internals"),et=e.STATUS_CODES;class rt{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k.call(this,t,e);const r=e.status||200,o=new J(e.headers);if(null!=t&&!o.has("Content-Type")){const e=H(t);e&&o.append("Content-Type",e)}this[tt]={url:e.url,status:r,statusText:e.statusText||et[r],headers:o,counter:e.counter}}get url(){return this[tt].url||""}get status(){return this[tt].status}get ok(){return this[tt].status>=200&&this[tt].status<300}get redirected(){return this[tt].counter>0}get statusText(){return this[tt].statusText}get headers(){return this[tt].headers}clone(){return new rt(U(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}k.mixIn(rt.prototype),Object.defineProperties(rt.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(rt.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ot=Symbol("Request internals"),nt=r.parse,st=r.format,it="destroy"in t.Readable.prototype;function at(t){return"object"==typeof t&&"object"==typeof t[ot]}class ut{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};at(t)?e=nt(t.url):(e=t&&t.href?nt(t.href):nt(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||at(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:at(t)&&null!==t.body?U(t):null;k.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new J(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=H(n);t&&s.append("Content-Type",t)}let i=at(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[ot]={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[ot].method}get url(){return st(this[ot].parsedURL)}get headers(){return this[ot].headers}get redirect(){return this[ot].redirect}get signal(){return this[ot].signal}clone(){return new ut(this)}}function ht(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}k.mixIn(ut.prototype),Object.defineProperty(ut.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(ut.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),ht.prototype=Object.create(Error.prototype),ht.prototype.constructor=ht,ht.prototype.name="AbortError";const ct=t.PassThrough,lt=r.resolve;function ft(r,o){if(!ft.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return k.Promise=ft.Promise,new ft.Promise((function(n,a){const u=new ut(r,o),h=function(e){const r=e[ot].parsedURL,o=new J(e[ot].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&&!it)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=I(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:X(o),agent:s})}(u),c=("https:"===h.protocol?s:e).request,l=u.signal;let f=null;const p=function(){let e=new ht("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 B(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(t){a(new B(`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 J;for(const r of Object.keys(t))if(!F.test(r))if(Array.isArray(t[r]))for(const o of t[r])M.test(o)||(void 0===e[W][r]?e[W][r]=[o]:e[W][r].push(o));else M.test(t[r])||(e[W][r]=[t[r]]);return e}(t.headers);if(ft.isRedirect(t.statusCode)){const r=e.get("Location"),o=null===r?null:lt(u.url,r);switch(u.redirect){case"error":return a(new B(`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 B(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new J(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===I(u)?(a(new B("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(ft(new ut(o,r))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=t.pipe(new ct);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 rt(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 rt(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 rt(r,o),void n(f);f=new rt(r,o),n(f)}else{t.pipe(new ct).once("data",(function(t){r=8==(15&t[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new rt(r,o),n(f)}))}})),function(t,e){const r=e.body;null===r?t.end():z(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,u)}))}ft.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},ft.Promise=global.Promise;var pt=E(Object.freeze({__proto__:null,default:ft,Headers:J,Request:ut,Response:rt,FetchError:B}));function dt(t){return t&&t.default||t}var mt=S.fetch=S.fetch||("undefined"==typeof process?dt(P):function(t,e){return dt(pt)(String(t).replace(/^\/\//g,"https://"),e)});class yt{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 mt(c.href,{method:t,headers:l,body:u,compress:i}),d=f.headers.get("content-type");if(h=d&&d.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in h&&h.errors)throw new p(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 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/aircraft"}}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/airlines"}}class vt 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 wt{constructor(t){this.client=new yt(t),this.aircraft=new bt(this.client),this.airlines=new gt(this.client),this.airports=new vt(this.client),this.offerRequests=new m(this.client),this.offers=new y(this.client),this.orders=new g(this.client),this.orderChangeRequests=new v(this.client),this.orderChangeOffers=new w(this.client),this.orderChanges=new T(this.client),this.orderCancellations=new b(this.client),this.payments=new O(this.client),this.seatMaps=new j(this.client),this.paymentIntents=new f(this.client)}}export{wt as Duffel}; | ||
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.6.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 Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class d extends Error{constructor(t){super("Invalid data: "+t),this.name="ValidationError"}}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.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 r.passengers&&r.passengers.forEach((t=>{if(t.loyalty_programme_accounts&&t.loyalty_programme_accounts.length>0&&(!t.given_name||!t.family_name))throw new d("loyalty programme requires family_name and given_name parameters")})),this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class y 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 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.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 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=>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 v 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 w 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 T 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 O 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 j 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 S="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function E(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 P=E(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 $=t.Readable,q=Symbol("buffer"),x=Symbol("type");class _{constructor(){this[x]="";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 _?n[q]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[q]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[x]=n)}get size(){return this[q].length}get type(){return this[x]}text(){return Promise.resolve(this[q].toString())}arrayBuffer(){const t=this[q],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new $;return t._read=function(){},t.push(this[q]),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[q].slice(o,o+s),a=new _([],{type:arguments[2]});return a[q]=i,a}}function B(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 C;Object.defineProperties(_.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(_.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),B.prototype=Object.create(Error.prototype),B.prototype.constructor=B,B.prototype.name="FetchError";try{C=require("encoding").convert}catch(t){}const R=Symbol("Body internals"),A=t.PassThrough;function k(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:L(e)?e=Buffer.from(e.toString()):z(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[R]={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 B(`Invalid response body while trying to fetch ${r.url}: ${t.message}`,"system",t);r[R].error=e}))}function G(){var e=this;if(this[R].disturbed)return k.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[R].disturbed=!0,this[R].error)return k.Promise.reject(this[R].error);let r=this.body;if(null===r)return k.Promise.resolve(Buffer.alloc(0));if(z(r)&&(r=r.stream()),Buffer.isBuffer(r))return k.Promise.resolve(r);if(!(r instanceof t))return k.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new k.Promise((function(t,i){let a;e.timeout&&(a=setTimeout((function(){s=!0,i(new B(`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 B(`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 B(`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 B(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function L(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 z(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 U(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 A,o=new A,n.pipe(r),n.pipe(o),e[R].body=r,n=o),n}function H(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":L(e)?"application/x-www-form-urlencoded;charset=UTF-8":z(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 I(t){const e=t.body;return null===e?0:z(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}k.prototype={get body(){return this[R].body},get bodyUsed(){return this[R].disturbed},arrayBuffer(){return G.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 G.call(this).then((function(e){return Object.assign(new _([],{type:t.toLowerCase()}),{[q]:e})}))},json(){var t=this;return G.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return k.Promise.reject(new B(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return G.call(this).then((function(t){return t.toString()}))},buffer(){return G.call(this)},textConverted(){var t=this;return G.call(this).then((function(e){return function(t,e){if("function"!=typeof C)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 C(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(k.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),k.mixIn=function(t){for(const e of Object.getOwnPropertyNames(k.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(k.prototype,e);Object.defineProperty(t,e,r)}},k.Promise=global.Promise;const F=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,M=/[^\t\x20-\x7e\x80-\xff]/;function D(t){if(t=`${t}`,F.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function V(t){if(t=`${t}`,M.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function N(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const W=Symbol("map");class J{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[W]=Object.create(null),t instanceof J){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){D(t=`${t}`);const e=N(this[W],t);return void 0===e?null:this[W][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=Z(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=Z(this),o++}}set(t,e){e=`${e}`,D(t=`${t}`),V(e);const r=N(this[W],t);this[W][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,D(t=`${t}`),V(e);const r=N(this[W],t);void 0!==r?this[W][r].push(e):this[W][t]=[e]}has(t){return D(t=`${t}`),void 0!==N(this[W],t)}delete(t){D(t=`${t}`);const e=N(this[W],t);void 0!==e&&delete this[W][e]}raw(){return this[W]}keys(){return Y(this,"key")}values(){return Y(this,"value")}[Symbol.iterator](){return Y(this,"key+value")}}function Z(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[W]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[W][e].join(", ")}:function(e){return[e.toLowerCase(),t[W][e].join(", ")]})}J.prototype.entries=J.prototype[Symbol.iterator],Object.defineProperty(J.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(J.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 K=Symbol("internal");function Y(t,e){const r=Object.create(Q);return r[K]={target:t,kind:e,index:0},r}const Q=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==Q)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[K];const e=t.target,r=t.kind,o=t.index,n=Z(e,r);return o>=n.length?{value:void 0,done:!0}:(this[K].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function X(t){const e=Object.assign({__proto__:null},t[W]),r=N(t[W],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(Q,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const tt=Symbol("Response internals"),et=e.STATUS_CODES;class rt{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};k.call(this,t,e);const r=e.status||200,o=new J(e.headers);if(null!=t&&!o.has("Content-Type")){const e=H(t);e&&o.append("Content-Type",e)}this[tt]={url:e.url,status:r,statusText:e.statusText||et[r],headers:o,counter:e.counter}}get url(){return this[tt].url||""}get status(){return this[tt].status}get ok(){return this[tt].status>=200&&this[tt].status<300}get redirected(){return this[tt].counter>0}get statusText(){return this[tt].statusText}get headers(){return this[tt].headers}clone(){return new rt(U(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}k.mixIn(rt.prototype),Object.defineProperties(rt.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(rt.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ot=Symbol("Request internals"),nt=r.parse,st=r.format,it="destroy"in t.Readable.prototype;function at(t){return"object"==typeof t&&"object"==typeof t[ot]}class ut{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};at(t)?e=nt(t.url):(e=t&&t.href?nt(t.href):nt(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||at(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:at(t)&&null!==t.body?U(t):null;k.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new J(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=H(n);t&&s.append("Content-Type",t)}let i=at(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[ot]={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[ot].method}get url(){return st(this[ot].parsedURL)}get headers(){return this[ot].headers}get redirect(){return this[ot].redirect}get signal(){return this[ot].signal}clone(){return new ut(this)}}function ht(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}k.mixIn(ut.prototype),Object.defineProperty(ut.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(ut.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),ht.prototype=Object.create(Error.prototype),ht.prototype.constructor=ht,ht.prototype.name="AbortError";const ct=t.PassThrough,lt=r.resolve;function ft(r,o){if(!ft.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return k.Promise=ft.Promise,new ft.Promise((function(n,a){const u=new ut(r,o),h=function(e){const r=e[ot].parsedURL,o=new J(e[ot].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&&!it)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=I(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:X(o),agent:s})}(u),c=("https:"===h.protocol?s:e).request,l=u.signal;let f=null;const p=function(){let e=new ht("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 B(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(t){a(new B(`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 J;for(const r of Object.keys(t))if(!F.test(r))if(Array.isArray(t[r]))for(const o of t[r])M.test(o)||(void 0===e[W][r]?e[W][r]=[o]:e[W][r].push(o));else M.test(t[r])||(e[W][r]=[t[r]]);return e}(t.headers);if(ft.isRedirect(t.statusCode)){const r=e.get("Location"),o=null===r?null:lt(u.url,r);switch(u.redirect){case"error":return a(new B(`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 B(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new J(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===I(u)?(a(new B("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(ft(new ut(o,r))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=t.pipe(new ct);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 rt(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 rt(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 rt(r,o),void n(f);f=new rt(r,o),n(f)}else{t.pipe(new ct).once("data",(function(t){r=8==(15&t[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new rt(r,o),n(f)}))}})),function(t,e){const r=e.body;null===r?t.end():z(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,u)}))}ft.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},ft.Promise=global.Promise;var pt=E(Object.freeze({__proto__:null,default:ft,Headers:J,Request:ut,Response:rt,FetchError:B}));function dt(t){return t&&t.default||t}var mt=S.fetch=S.fetch||("undefined"==typeof process?dt(P):function(t,e){return dt(pt)(String(t).replace(/^\/\//g,"https://"),e)});class yt{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 mt(c.href,{method:t,headers:l,body:u,compress:i}),d=f.headers.get("content-type");if(h=d&&d.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in h&&h.errors)throw new p(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 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/aircraft"}}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/airlines"}}class vt 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 wt{constructor(t){this.client=new yt(t),this.aircraft=new bt(this.client),this.airlines=new gt(this.client),this.airports=new vt(this.client),this.offerRequests=new m(this.client),this.offers=new y(this.client),this.orders=new g(this.client),this.orderChangeRequests=new v(this.client),this.orderChangeOffers=new w(this.client),this.orderChanges=new T(this.client),this.orderCancellations=new b(this.client),this.payments=new O(this.client),this.seatMaps=new j(this.client),this.paymentIntents=new f(this.client)}}export{wt as Duffel}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("stream"),e=require("http"),r=require("url"),o=require("https"),n=require("zlib");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=s(t),a=s(e),u=s(r),h=s(o),c=s(n);function l(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 f(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 d(t){return this instanceof d?(this.v=t,this):new d(t)}function p(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 d?Promise.resolve(t.value.v).then(u,h):c(s[0][2],t)}(n[t](e))}catch(t){c(s[0][3],t)}}function u(t){a("next",t)}function h(t){a("throw",t)}function c(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}!function(){const t={npm_package_version:"1.5.1"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}();class m{constructor(t){this.request=({method:t,path:e,data:r,params:o})=>f(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 y extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments/payment_intents"}}class b extends Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class g extends Error{constructor(t){super("Invalid data: "+t),this.name="ValidationError"}}class v extends m{constructor(t){super(t),this.get=t=>f(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=>f(this,void 0,void 0,(function*(){const{return_offers:e}=t,r=l(t,["return_offers"]);return r.passengers&&r.passengers.forEach((t=>{if(t.loyalty_programme_accounts&&t.loyalty_programme_accounts.length>0&&(!t.given_name||!t.family_name))throw new g("loyalty programme requires family_name and given_name parameters")})),this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class w extends m{constructor(t){super(t),this.get=(t,e)=>f(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=l(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=l(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)=>f(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 T extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class O extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>f(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=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,e)=>f(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:e}})})),this.path="air/orders"}}class j extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class S extends m{constructor(t){super(t),this.get=t=>f(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 P extends m{constructor(t){super(t),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,e)=>f(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 q extends m{constructor(t){super(t),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class E extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}var $="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function x(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 _=x(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 B=i.default.Readable,C=Symbol("buffer"),R=Symbol("type");class L{constructor(){this[R]="";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 L?n[C]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[C]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[R]=n)}get size(){return this[C].length}get type(){return this[R]}text(){return Promise.resolve(this[C].toString())}arrayBuffer(){const t=this[C],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new B;return t._read=function(){},t.push(this[C]),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[C].slice(o,o+s),a=new L([],{type:arguments[2]});return a[C]=i,a}}function A(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 k;Object.defineProperties(L.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(L.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),A.prototype=Object.create(Error.prototype),A.prototype.constructor=A,A.prototype.name="FetchError";try{k=require("encoding").convert}catch(t){}const G=Symbol("Body internals"),z=i.default.PassThrough;function U(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=r.size;let n=void 0===o?0:o;var s=r.timeout;let a=void 0===s?0:s;null==t?t=null:I(t)?t=Buffer.from(t.toString()):M(t)||Buffer.isBuffer(t)||("[object ArrayBuffer]"===Object.prototype.toString.call(t)?t=Buffer.from(t):ArrayBuffer.isView(t)?t=Buffer.from(t.buffer,t.byteOffset,t.byteLength):t instanceof i.default||(t=Buffer.from(String(t)))),this[G]={body:t,disturbed:!1,error:null},this.size=n,this.timeout=a,t instanceof i.default&&t.on("error",(function(t){const r="AbortError"===t.name?t:new A(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t);e[G].error=r}))}function H(){var t=this;if(this[G].disturbed)return U.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[G].disturbed=!0,this[G].error)return U.Promise.reject(this[G].error);let e=this.body;if(null===e)return U.Promise.resolve(Buffer.alloc(0));if(M(e)&&(e=e.stream()),Buffer.isBuffer(e))return U.Promise.resolve(e);if(!(e instanceof i.default))return U.Promise.resolve(Buffer.alloc(0));let r=[],o=0,n=!1;return new U.Promise((function(s,i){let a;t.timeout&&(a=setTimeout((function(){n=!0,i(new A(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),e.on("error",(function(e){"AbortError"===e.name?(n=!0,i(e)):i(new A(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),e.on("data",(function(e){if(!n&&null!==e){if(t.size&&o+e.length>t.size)return n=!0,void i(new A(`content size at ${t.url} over limit: ${t.size}`,"max-size"));o+=e.length,r.push(e)}})),e.on("end",(function(){if(!n){clearTimeout(a);try{s(Buffer.concat(r,o))}catch(e){i(new A(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function I(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 M(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 D(t){let e,r,o=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return o instanceof i.default&&"function"!=typeof o.getBoundary&&(e=new z,r=new z,o.pipe(e),o.pipe(r),t[G].body=e,o=r),o}function F(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":I(t)?"application/x-www-form-urlencoded;charset=UTF-8":M(t)?t.type||null:Buffer.isBuffer(t)||"[object ArrayBuffer]"===Object.prototype.toString.call(t)||ArrayBuffer.isView(t)?null:"function"==typeof t.getBoundary?`multipart/form-data;boundary=${t.getBoundary()}`:t instanceof i.default?null:"text/plain;charset=UTF-8"}function V(t){const e=t.body;return null===e?0:M(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}U.prototype={get body(){return this[G].body},get bodyUsed(){return this[G].disturbed},arrayBuffer(){return H.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 H.call(this).then((function(e){return Object.assign(new L([],{type:t.toLowerCase()}),{[C]:e})}))},json(){var t=this;return H.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return U.Promise.reject(new A(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return H.call(this).then((function(t){return t.toString()}))},buffer(){return H.call(this)},textConverted(){var t=this;return H.call(this).then((function(e){return function(t,e){if("function"!=typeof k)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 k(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(U.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),U.mixIn=function(t){for(const e of Object.getOwnPropertyNames(U.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(U.prototype,e);Object.defineProperty(t,e,r)}},U.Promise=global.Promise;const N=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,W=/[^\t\x20-\x7e\x80-\xff]/;function J(t){if(t=`${t}`,N.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function Z(t){if(t=`${t}`,W.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function K(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const Y=Symbol("map");class Q{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[Y]=Object.create(null),t instanceof Q){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){J(t=`${t}`);const e=K(this[Y],t);return void 0===e?null:this[Y][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=X(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=X(this),o++}}set(t,e){e=`${e}`,J(t=`${t}`),Z(e);const r=K(this[Y],t);this[Y][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,J(t=`${t}`),Z(e);const r=K(this[Y],t);void 0!==r?this[Y][r].push(e):this[Y][t]=[e]}has(t){return J(t=`${t}`),void 0!==K(this[Y],t)}delete(t){J(t=`${t}`);const e=K(this[Y],t);void 0!==e&&delete this[Y][e]}raw(){return this[Y]}keys(){return et(this,"key")}values(){return et(this,"value")}[Symbol.iterator](){return et(this,"key+value")}}function X(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[Y]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[Y][e].join(", ")}:function(e){return[e.toLowerCase(),t[Y][e].join(", ")]})}Q.prototype.entries=Q.prototype[Symbol.iterator],Object.defineProperty(Q.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(Q.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 tt=Symbol("internal");function et(t,e){const r=Object.create(rt);return r[tt]={target:t,kind:e,index:0},r}const rt=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==rt)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[tt];const e=t.target,r=t.kind,o=t.index,n=X(e,r);return o>=n.length?{value:void 0,done:!0}:(this[tt].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function ot(t){const e=Object.assign({__proto__:null},t[Y]),r=K(t[Y],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(rt,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const nt=Symbol("Response internals"),st=a.default.STATUS_CODES;class it{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};U.call(this,t,e);const r=e.status||200,o=new Q(e.headers);if(null!=t&&!o.has("Content-Type")){const e=F(t);e&&o.append("Content-Type",e)}this[nt]={url:e.url,status:r,statusText:e.statusText||st[r],headers:o,counter:e.counter}}get url(){return this[nt].url||""}get status(){return this[nt].status}get ok(){return this[nt].status>=200&&this[nt].status<300}get redirected(){return this[nt].counter>0}get statusText(){return this[nt].statusText}get headers(){return this[nt].headers}clone(){return new it(D(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}U.mixIn(it.prototype),Object.defineProperties(it.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const at=Symbol("Request internals"),ut=u.default.parse,ht=u.default.format,ct="destroy"in i.default.Readable.prototype;function lt(t){return"object"==typeof t&&"object"==typeof t[at]}class ft{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};lt(t)?e=ut(t.url):(e=t&&t.href?ut(t.href):ut(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||lt(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:lt(t)&&null!==t.body?D(t):null;U.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new Q(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=F(n);t&&s.append("Content-Type",t)}let i=lt(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[at]={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[at].method}get url(){return ht(this[at].parsedURL)}get headers(){return this[at].headers}get redirect(){return this[at].redirect}get signal(){return this[at].signal}clone(){return new ft(this)}}function dt(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}U.mixIn(ft.prototype),Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(ft.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),dt.prototype=Object.create(Error.prototype),dt.prototype.constructor=dt,dt.prototype.name="AbortError";const pt=i.default.PassThrough,mt=u.default.resolve;function yt(t,e){if(!yt.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return U.Promise=yt.Promise,new yt.Promise((function(r,o){const n=new ft(t,e),s=function(t){const e=t[at].parsedURL,r=new Q(t[at].headers);if(r.has("Accept")||r.set("Accept","*/*"),!e.protocol||!e.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(e.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(t.signal&&t.body instanceof i.default.Readable&&!ct)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let o=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(o="0"),null!=t.body){const e=V(t);"number"==typeof e&&(o=String(e))}o&&r.set("Content-Length",o),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let n=t.agent;return"function"==typeof n&&(n=n(e)),r.has("Connection")||n||r.set("Connection","close"),Object.assign({},e,{method:t.method,headers:ot(r),agent:n})}(n),u=("https:"===s.protocol?h.default:a.default).request,l=n.signal;let f=null;const d=function(){let t=new dt("The user aborted a request.");o(t),n.body&&n.body instanceof i.default.Readable&&n.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(l&&l.aborted)return void d();const p=function(){d(),b()},m=u(s);let y;function b(){m.abort(),l&&l.removeEventListener("abort",p),clearTimeout(y)}l&&l.addEventListener("abort",p),n.timeout&&m.once("socket",(function(t){y=setTimeout((function(){o(new A(`network timeout at: ${n.url}`,"request-timeout")),b()}),n.timeout)})),m.on("error",(function(t){o(new A(`request to ${n.url} failed, reason: ${t.message}`,"system",t)),b()})),m.on("response",(function(t){clearTimeout(y);const e=function(t){const e=new Q;for(const r of Object.keys(t))if(!N.test(r))if(Array.isArray(t[r]))for(const o of t[r])W.test(o)||(void 0===e[Y][r]?e[Y][r]=[o]:e[Y][r].push(o));else W.test(t[r])||(e[Y][r]=[t[r]]);return e}(t.headers);if(yt.isRedirect(t.statusCode)){const s=e.get("Location"),i=null===s?null:mt(n.url,s);switch(n.redirect){case"error":return o(new A(`uri requested responds with a redirect, redirect mode is set to error: ${n.url}`,"no-redirect")),void b();case"manual":if(null!==i)try{e.set("Location",i)}catch(t){o(t)}break;case"follow":if(null===i)break;if(n.counter>=n.follow)return o(new A(`maximum redirect reached at: ${n.url}`,"max-redirect")),void b();const s={headers:new Q(n.headers),follow:n.follow,counter:n.counter+1,agent:n.agent,compress:n.compress,method:n.method,body:n.body,signal:n.signal,timeout:n.timeout,size:n.size};return 303!==t.statusCode&&n.body&&null===V(n)?(o(new A("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==n.method)||(s.method="GET",s.body=void 0,s.headers.delete("content-length")),r(yt(new ft(i,s))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",p)}));let s=t.pipe(new pt);const i={url:n.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:n.size,timeout:n.timeout,counter:n.counter},a=e.get("Content-Encoding");if(!n.compress||"HEAD"===n.method||null===a||204===t.statusCode||304===t.statusCode)return f=new it(s,i),void r(f);const u={flush:c.default.Z_SYNC_FLUSH,finishFlush:c.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return s=s.pipe(c.default.createGunzip(u)),f=new it(s,i),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof c.default.createBrotliDecompress)return s=s.pipe(c.default.createBrotliDecompress()),f=new it(s,i),void r(f);f=new it(s,i),r(f)}else{t.pipe(new pt).once("data",(function(t){s=8==(15&t[0])?s.pipe(c.default.createInflate()):s.pipe(c.default.createInflateRaw()),f=new it(s,i),r(f)}))}})),function(t,e){const r=e.body;null===r?t.end():M(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,n)}))}yt.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},yt.Promise=global.Promise;var bt=x(Object.freeze({__proto__:null,default:yt,Headers:Q,Request:ft,Response:it,FetchError:A}));function gt(t){return t&&t.default||t}var vt=$.fetch=$.fetch||("undefined"==typeof process?gt(_):function(t,e){return gt(bt)(String(t).replace(/^\/\//g,"https://"),e)});class wt{constructor({token:t,basePath:e,apiVersion:o,debug:n}){this.request=({method:t,path:e,data:o,params:n,compress:s=!0})=>f(this,void 0,void 0,(function*(){var i;let a,u;const h=new r.URL(e,this.basePath),c={"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(n){const t=Object.entries(n).sort().filter((t=>null!==t[0]));h.search=new r.URLSearchParams(t).toString()}o&&(a=JSON.stringify({data:Object.assign({},o)})),(null===(i=this.debug)||void 0===i?void 0:i.verbose)&&(console.info("Endpoint: ",h.href),console.info("Method: ",t),o&&console.info("Body Parameters: ",o),n&&console.info("Query Parameters: ",n));const l=yield vt(h.href,{method:t,headers:c,body:a,compress:s}),f=l.headers.get("content-type");if(u=f&&f.includes("json")?yield l.json():yield l.text(),!l.ok||"errors"in u&&u.errors)throw new b(u);return u})),this.token=t,this.basePath=e||"https://api.duffel.com",this.apiVersion=o||"beta",this.debug=n}paginatedRequest({path:t,params:e}){return p(this,arguments,(function*(){let r=yield d(this.request({method:"GET",path:t,params:e}));for(const t of r.data)yield yield d({data:t});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield d(this.request({method:"GET",path:t,params:{limit:r.meta.limit,after:r.meta.after}}));for(const t of r.data)yield yield d({data:t})}}))}}class Tt extends m{constructor(t){super(t),this.get=t=>f(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 Ot extends m{constructor(t){super(t),this.get=t=>f(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 jt extends m{constructor(t){super(t),this.get=t=>f(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"}}exports.Duffel=class{constructor(t){this.client=new wt(t),this.aircraft=new Tt(this.client),this.airlines=new Ot(this.client),this.airports=new jt(this.client),this.offerRequests=new v(this.client),this.offers=new w(this.client),this.orders=new O(this.client),this.orderChangeRequests=new j(this.client),this.orderChangeOffers=new S(this.client),this.orderChanges=new P(this.client),this.orderCancellations=new T(this.client),this.payments=new q(this.client),this.seatMaps=new E(this.client),this.paymentIntents=new y(this.client)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("stream"),e=require("http"),r=require("url"),o=require("https"),n=require("zlib");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=s(t),a=s(e),u=s(r),h=s(o),c=s(n);function l(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 f(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 d(t){return this instanceof d?(this.v=t,this):new d(t)}function p(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 d?Promise.resolve(t.value.v).then(u,h):c(s[0][2],t)}(n[t](e))}catch(t){c(s[0][3],t)}}function u(t){a("next",t)}function h(t){a("throw",t)}function c(t,e){t(e),s.shift(),s.length&&a(s[0][0],s[0][1])}}!function(){const t={npm_package_version:"1.6.0"};try{if(process)return process.env=Object.assign({},process.env),void Object.assign(process.env,t)}catch(t){}globalThis.process={env:t}}();class m{constructor(t){this.request=({method:t,path:e,data:r,params:o})=>f(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 y extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments/payment_intents"}}class b extends Error{constructor({meta:t,errors:e}){super(),this.meta=t,this.errors=e}}class g extends Error{constructor(t){super("Invalid data: "+t),this.name="ValidationError"}}class v extends m{constructor(t){super(t),this.get=t=>f(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=>f(this,void 0,void 0,(function*(){const{return_offers:e}=t,r=l(t,["return_offers"]);return r.passengers&&r.passengers.forEach((t=>{if(t.loyalty_programme_accounts&&t.loyalty_programme_accounts.length>0&&(!t.given_name||!t.family_name))throw new g("loyalty programme requires family_name and given_name parameters")})),this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=e&&{return_offers:e})})})),this.path="air/offer_requests"}}class w extends m{constructor(t){super(t),this.get=(t,e)=>f(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=l(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=l(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)=>f(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 T extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.confirm=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${t}/actions/confirm`})})),this.path="air/order_cancellations"}}class O extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.list=t=>f(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=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.update=(t,e)=>f(this,void 0,void 0,(function*(){return this.request({method:"PATCH",path:`${this.path}/${t}`,data:{options:e}})})),this.path="air/orders"}}class j extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/order_change_requests"}}class S extends m{constructor(t){super(t),this.get=t=>f(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 P extends m{constructor(t){super(t),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${t}`})})),this.confirm=(t,e)=>f(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 q extends m{constructor(t){super(t),this.create=t=>f(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:t})})),this.path="air/payments"}}class E extends m{constructor(t){super(t),this.get=t=>f(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:t})})),this.path="air/seat_maps"}}var $="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function x(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 _=x(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 B=i.default.Readable,C=Symbol("buffer"),R=Symbol("type");class L{constructor(){this[R]="";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 L?n[C]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[C]=Buffer.concat(r);let n=e&&void 0!==e.type&&String(e.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[R]=n)}get size(){return this[C].length}get type(){return this[R]}text(){return Promise.resolve(this[C].toString())}arrayBuffer(){const t=this[C],e=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);return Promise.resolve(e)}stream(){const t=new B;return t._read=function(){},t.push(this[C]),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[C].slice(o,o+s),a=new L([],{type:arguments[2]});return a[C]=i,a}}function A(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 k;Object.defineProperties(L.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(L.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),A.prototype=Object.create(Error.prototype),A.prototype.constructor=A,A.prototype.name="FetchError";try{k=require("encoding").convert}catch(t){}const G=Symbol("Body internals"),z=i.default.PassThrough;function U(t){var e=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=r.size;let n=void 0===o?0:o;var s=r.timeout;let a=void 0===s?0:s;null==t?t=null:I(t)?t=Buffer.from(t.toString()):M(t)||Buffer.isBuffer(t)||("[object ArrayBuffer]"===Object.prototype.toString.call(t)?t=Buffer.from(t):ArrayBuffer.isView(t)?t=Buffer.from(t.buffer,t.byteOffset,t.byteLength):t instanceof i.default||(t=Buffer.from(String(t)))),this[G]={body:t,disturbed:!1,error:null},this.size=n,this.timeout=a,t instanceof i.default&&t.on("error",(function(t){const r="AbortError"===t.name?t:new A(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t);e[G].error=r}))}function H(){var t=this;if(this[G].disturbed)return U.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[G].disturbed=!0,this[G].error)return U.Promise.reject(this[G].error);let e=this.body;if(null===e)return U.Promise.resolve(Buffer.alloc(0));if(M(e)&&(e=e.stream()),Buffer.isBuffer(e))return U.Promise.resolve(e);if(!(e instanceof i.default))return U.Promise.resolve(Buffer.alloc(0));let r=[],o=0,n=!1;return new U.Promise((function(s,i){let a;t.timeout&&(a=setTimeout((function(){n=!0,i(new A(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),e.on("error",(function(e){"AbortError"===e.name?(n=!0,i(e)):i(new A(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),e.on("data",(function(e){if(!n&&null!==e){if(t.size&&o+e.length>t.size)return n=!0,void i(new A(`content size at ${t.url} over limit: ${t.size}`,"max-size"));o+=e.length,r.push(e)}})),e.on("end",(function(){if(!n){clearTimeout(a);try{s(Buffer.concat(r,o))}catch(e){i(new A(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function I(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 M(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 D(t){let e,r,o=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return o instanceof i.default&&"function"!=typeof o.getBoundary&&(e=new z,r=new z,o.pipe(e),o.pipe(r),t[G].body=e,o=r),o}function F(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":I(t)?"application/x-www-form-urlencoded;charset=UTF-8":M(t)?t.type||null:Buffer.isBuffer(t)||"[object ArrayBuffer]"===Object.prototype.toString.call(t)||ArrayBuffer.isView(t)?null:"function"==typeof t.getBoundary?`multipart/form-data;boundary=${t.getBoundary()}`:t instanceof i.default?null:"text/plain;charset=UTF-8"}function V(t){const e=t.body;return null===e?0:M(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}U.prototype={get body(){return this[G].body},get bodyUsed(){return this[G].disturbed},arrayBuffer(){return H.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 H.call(this).then((function(e){return Object.assign(new L([],{type:t.toLowerCase()}),{[C]:e})}))},json(){var t=this;return H.call(this).then((function(e){try{return JSON.parse(e.toString())}catch(e){return U.Promise.reject(new A(`invalid json response body at ${t.url} reason: ${e.message}`,"invalid-json"))}}))},text(){return H.call(this).then((function(t){return t.toString()}))},buffer(){return H.call(this)},textConverted(){var t=this;return H.call(this).then((function(e){return function(t,e){if("function"!=typeof k)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 k(t,"UTF-8",s).toString()}(e,t.headers)}))}},Object.defineProperties(U.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),U.mixIn=function(t){for(const e of Object.getOwnPropertyNames(U.prototype))if(!(e in t)){const r=Object.getOwnPropertyDescriptor(U.prototype,e);Object.defineProperty(t,e,r)}},U.Promise=global.Promise;const N=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,W=/[^\t\x20-\x7e\x80-\xff]/;function J(t){if(t=`${t}`,N.test(t)||""===t)throw new TypeError(`${t} is not a legal HTTP header name`)}function Z(t){if(t=`${t}`,W.test(t))throw new TypeError(`${t} is not a legal HTTP header value`)}function K(t,e){e=e.toLowerCase();for(const r in t)if(r.toLowerCase()===e)return r}const Y=Symbol("map");class Q{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[Y]=Object.create(null),t instanceof Q){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){J(t=`${t}`);const e=K(this[Y],t);return void 0===e?null:this[Y][e].join(", ")}forEach(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=X(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=X(this),o++}}set(t,e){e=`${e}`,J(t=`${t}`),Z(e);const r=K(this[Y],t);this[Y][void 0!==r?r:t]=[e]}append(t,e){e=`${e}`,J(t=`${t}`),Z(e);const r=K(this[Y],t);void 0!==r?this[Y][r].push(e):this[Y][t]=[e]}has(t){return J(t=`${t}`),void 0!==K(this[Y],t)}delete(t){J(t=`${t}`);const e=K(this[Y],t);void 0!==e&&delete this[Y][e]}raw(){return this[Y]}keys(){return et(this,"key")}values(){return et(this,"value")}[Symbol.iterator](){return et(this,"key+value")}}function X(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(t[Y]).sort();return r.map("key"===e?function(t){return t.toLowerCase()}:"value"===e?function(e){return t[Y][e].join(", ")}:function(e){return[e.toLowerCase(),t[Y][e].join(", ")]})}Q.prototype.entries=Q.prototype[Symbol.iterator],Object.defineProperty(Q.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(Q.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 tt=Symbol("internal");function et(t,e){const r=Object.create(rt);return r[tt]={target:t,kind:e,index:0},r}const rt=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==rt)throw new TypeError("Value of `this` is not a HeadersIterator");var t=this[tt];const e=t.target,r=t.kind,o=t.index,n=X(e,r);return o>=n.length?{value:void 0,done:!0}:(this[tt].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function ot(t){const e=Object.assign({__proto__:null},t[Y]),r=K(t[Y],"Host");return void 0!==r&&(e[r]=e[r][0]),e}Object.defineProperty(rt,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const nt=Symbol("Response internals"),st=a.default.STATUS_CODES;class it{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};U.call(this,t,e);const r=e.status||200,o=new Q(e.headers);if(null!=t&&!o.has("Content-Type")){const e=F(t);e&&o.append("Content-Type",e)}this[nt]={url:e.url,status:r,statusText:e.statusText||st[r],headers:o,counter:e.counter}}get url(){return this[nt].url||""}get status(){return this[nt].status}get ok(){return this[nt].status>=200&&this[nt].status<300}get redirected(){return this[nt].counter>0}get statusText(){return this[nt].statusText}get headers(){return this[nt].headers}clone(){return new it(D(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}U.mixIn(it.prototype),Object.defineProperties(it.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(it.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const at=Symbol("Request internals"),ut=u.default.parse,ht=u.default.format,ct="destroy"in i.default.Readable.prototype;function lt(t){return"object"==typeof t&&"object"==typeof t[at]}class ft{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};lt(t)?e=ut(t.url):(e=t&&t.href?ut(t.href):ut(`${t}`),t={});let o=r.method||t.method||"GET";if(o=o.toUpperCase(),(null!=r.body||lt(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:lt(t)&&null!==t.body?D(t):null;U.call(this,n,{timeout:r.timeout||t.timeout||0,size:r.size||t.size||0});const s=new Q(r.headers||t.headers||{});if(null!=n&&!s.has("Content-Type")){const t=F(n);t&&s.append("Content-Type",t)}let i=lt(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[at]={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[at].method}get url(){return ht(this[at].parsedURL)}get headers(){return this[at].headers}get redirect(){return this[at].redirect}get signal(){return this[at].signal}clone(){return new ft(this)}}function dt(t){Error.call(this,t),this.type="aborted",this.message=t,Error.captureStackTrace(this,this.constructor)}U.mixIn(ft.prototype),Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(ft.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),dt.prototype=Object.create(Error.prototype),dt.prototype.constructor=dt,dt.prototype.name="AbortError";const pt=i.default.PassThrough,mt=u.default.resolve;function yt(t,e){if(!yt.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return U.Promise=yt.Promise,new yt.Promise((function(r,o){const n=new ft(t,e),s=function(t){const e=t[at].parsedURL,r=new Q(t[at].headers);if(r.has("Accept")||r.set("Accept","*/*"),!e.protocol||!e.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(e.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(t.signal&&t.body instanceof i.default.Readable&&!ct)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let o=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(o="0"),null!=t.body){const e=V(t);"number"==typeof e&&(o=String(e))}o&&r.set("Content-Length",o),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let n=t.agent;return"function"==typeof n&&(n=n(e)),r.has("Connection")||n||r.set("Connection","close"),Object.assign({},e,{method:t.method,headers:ot(r),agent:n})}(n),u=("https:"===s.protocol?h.default:a.default).request,l=n.signal;let f=null;const d=function(){let t=new dt("The user aborted a request.");o(t),n.body&&n.body instanceof i.default.Readable&&n.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(l&&l.aborted)return void d();const p=function(){d(),b()},m=u(s);let y;function b(){m.abort(),l&&l.removeEventListener("abort",p),clearTimeout(y)}l&&l.addEventListener("abort",p),n.timeout&&m.once("socket",(function(t){y=setTimeout((function(){o(new A(`network timeout at: ${n.url}`,"request-timeout")),b()}),n.timeout)})),m.on("error",(function(t){o(new A(`request to ${n.url} failed, reason: ${t.message}`,"system",t)),b()})),m.on("response",(function(t){clearTimeout(y);const e=function(t){const e=new Q;for(const r of Object.keys(t))if(!N.test(r))if(Array.isArray(t[r]))for(const o of t[r])W.test(o)||(void 0===e[Y][r]?e[Y][r]=[o]:e[Y][r].push(o));else W.test(t[r])||(e[Y][r]=[t[r]]);return e}(t.headers);if(yt.isRedirect(t.statusCode)){const s=e.get("Location"),i=null===s?null:mt(n.url,s);switch(n.redirect){case"error":return o(new A(`uri requested responds with a redirect, redirect mode is set to error: ${n.url}`,"no-redirect")),void b();case"manual":if(null!==i)try{e.set("Location",i)}catch(t){o(t)}break;case"follow":if(null===i)break;if(n.counter>=n.follow)return o(new A(`maximum redirect reached at: ${n.url}`,"max-redirect")),void b();const s={headers:new Q(n.headers),follow:n.follow,counter:n.counter+1,agent:n.agent,compress:n.compress,method:n.method,body:n.body,signal:n.signal,timeout:n.timeout,size:n.size};return 303!==t.statusCode&&n.body&&null===V(n)?(o(new A("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==t.statusCode&&(301!==t.statusCode&&302!==t.statusCode||"POST"!==n.method)||(s.method="GET",s.body=void 0,s.headers.delete("content-length")),r(yt(new ft(i,s))),void b())}}t.once("end",(function(){l&&l.removeEventListener("abort",p)}));let s=t.pipe(new pt);const i={url:n.url,status:t.statusCode,statusText:t.statusMessage,headers:e,size:n.size,timeout:n.timeout,counter:n.counter},a=e.get("Content-Encoding");if(!n.compress||"HEAD"===n.method||null===a||204===t.statusCode||304===t.statusCode)return f=new it(s,i),void r(f);const u={flush:c.default.Z_SYNC_FLUSH,finishFlush:c.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return s=s.pipe(c.default.createGunzip(u)),f=new it(s,i),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof c.default.createBrotliDecompress)return s=s.pipe(c.default.createBrotliDecompress()),f=new it(s,i),void r(f);f=new it(s,i),r(f)}else{t.pipe(new pt).once("data",(function(t){s=8==(15&t[0])?s.pipe(c.default.createInflate()):s.pipe(c.default.createInflateRaw()),f=new it(s,i),r(f)}))}})),function(t,e){const r=e.body;null===r?t.end():M(r)?r.stream().pipe(t):Buffer.isBuffer(r)?(t.write(r),t.end()):r.pipe(t)}(m,n)}))}yt.isRedirect=function(t){return 301===t||302===t||303===t||307===t||308===t},yt.Promise=global.Promise;var bt=x(Object.freeze({__proto__:null,default:yt,Headers:Q,Request:ft,Response:it,FetchError:A}));function gt(t){return t&&t.default||t}var vt=$.fetch=$.fetch||("undefined"==typeof process?gt(_):function(t,e){return gt(bt)(String(t).replace(/^\/\//g,"https://"),e)});class wt{constructor({token:t,basePath:e,apiVersion:o,debug:n}){this.request=({method:t,path:e,data:o,params:n,compress:s=!0})=>f(this,void 0,void 0,(function*(){var i;let a,u;const h=new r.URL(e,this.basePath),c={"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(n){const t=Object.entries(n).sort().filter((t=>null!==t[0]));h.search=new r.URLSearchParams(t).toString()}o&&(a=JSON.stringify({data:Object.assign({},o)})),(null===(i=this.debug)||void 0===i?void 0:i.verbose)&&(console.info("Endpoint: ",h.href),console.info("Method: ",t),o&&console.info("Body Parameters: ",o),n&&console.info("Query Parameters: ",n));const l=yield vt(h.href,{method:t,headers:c,body:a,compress:s}),f=l.headers.get("content-type");if(u=f&&f.includes("json")?yield l.json():yield l.text(),!l.ok||"errors"in u&&u.errors)throw new b(u);return u})),this.token=t,this.basePath=e||"https://api.duffel.com",this.apiVersion=o||"beta",this.debug=n}paginatedRequest({path:t,params:e}){return p(this,arguments,(function*(){let r=yield d(this.request({method:"GET",path:t,params:e}));for(const t of r.data)yield yield d({data:t});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield d(this.request({method:"GET",path:t,params:{limit:r.meta.limit,after:r.meta.after}}));for(const t of r.data)yield yield d({data:t})}}))}}class Tt extends m{constructor(t){super(t),this.get=t=>f(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 Ot extends m{constructor(t){super(t),this.get=t=>f(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 jt extends m{constructor(t){super(t),this.get=t=>f(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"}}exports.Duffel=class{constructor(t){this.client=new wt(t),this.aircraft=new Tt(this.client),this.airlines=new Ot(this.client),this.airports=new jt(this.client),this.offerRequests=new v(this.client),this.offers=new w(this.client),this.orders=new O(this.client),this.orderChangeRequests=new j(this.client),this.orderChangeOffers=new S(this.client),this.orderChanges=new P(this.client),this.orderCancellations=new T(this.client),this.payments=new q(this.client),this.seatMaps=new E(this.client),this.paymentIntents=new y(this.client)}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@duffel/api", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Javascript client library for the Duffel API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
455577
5404
132
5
7
29
1