@duffel/api
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -15,3 +15,3 @@ import e from"stream";import t from"http";import r,{URL as o,URLSearchParams as n}from"url";import s from"https";import i from"zlib"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function a(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((o=o.apply(e,t||[])).next())}))}function u(e){return this instanceof u?(this.v=e,this):new u(e)}function c(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=r.apply(e,t||[]),s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(e){n[e]&&(o[e]=function(t){return new Promise((function(r,o){s.push([e,t,r,o])>1||a(e,t)}))})}function a(e,t){try{!function(e){e.value instanceof u?Promise.resolve(e.value.v).then(c,h):l(s[0][2],e)}(n[e](t))}catch(e){l(s[0][3],e)}}function c(e){a("next",e)}function h(e){a("throw",e)}function l(e,t){e(t),s.shift(),s.length&&a(s[0][0],s[0][1])}}class h{constructor(e){this.request=({method:e,path:t,data:r,params:o})=>a(this,void 0,void 0,(function*(){return this.client.request({method:e,path:t,data:r,params:o})})),this.paginatedRequest=({path:e,params:t})=>this.client.paginatedRequest({path:e,params:t}),this.client=e}}class l extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.create=e=>a(this,void 0,void 0,(function*(){const{return_offers:t}=e,r=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}(e,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:{return_offers:t}})})),this.path="air/offer_requests"}}class f extends h{constructor(e){super(e),this.get=(e,t)=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`,params:t})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/offers"}}class p extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.confirm=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${e}/actions/confirm`})})),this.path="air/order_cancellations"}}class d extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:e})})),this.listWithGenerator=e=>this.paginatedRequest({path:"air/orders",params:e}),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/orders"}}class m extends h{constructor(e){super(e),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/payments"}}class y extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:e})})),this.path="air/seat_maps"}}var b="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function g(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})})),t}var v=g(Object.freeze({__proto__:null,default:function(e,t){return t=t||{},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(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in n.open(t.method||"get",e,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==t.credentials,t.headers)n.setRequestHeader(c,t.headers[c]);n.send(t.body||null)}))}}));const w=e.Readable,T=Symbol("buffer"),O=Symbol("type");class S{constructor(){this[O]="";const e=arguments[0],t=arguments[1],r=[];let o=0;if(e){const t=e,n=Number(t.length);for(let e=0;e<n;e++){const n=t[e];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 S?n[T]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[T]=Buffer.concat(r);let n=t&&void 0!==t.type&&String(t.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[O]=n)}get size(){return this[T].length}get type(){return this[O]}text(){return Promise.resolve(this[T].toString())}arrayBuffer(){const e=this[T],t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return Promise.resolve(t)}stream(){const e=new w;return e._read=function(){},e.push(this[T]),e.push(null),e}toString(){return"[object Blob]"}slice(){const e=this.size,t=arguments[0],r=arguments[1];let o,n;o=void 0===t?0:t<0?Math.max(e+t,0):Math.min(t,e),n=void 0===r?e:r<0?Math.max(e+r,0):Math.min(r,e);const s=Math.max(n-o,0),i=this[T].slice(o,o+s),a=new S([],{type:arguments[2]});return a[T]=i,a}}function j(e,t,r){Error.call(this,e),this.message=e,this.type=t,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let P;Object.defineProperties(S.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(S.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),j.prototype=Object.create(Error.prototype),j.prototype.constructor=j,j.prototype.name="FetchError";try{P=require("encoding").convert}catch(e){}const E=Symbol("Body internals"),x=e.PassThrough;function $(t){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==t?t=null:B(t)?t=Buffer.from(t.toString()):C(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 e||(t=Buffer.from(String(t)))),this[E]={body:t,disturbed:!1,error:null},this.size=s,this.timeout=a,t instanceof e&&t.on("error",(function(e){const t="AbortError"===e.name?e:new j(`Invalid response body while trying to fetch ${r.url}: ${e.message}`,"system",e);r[E].error=t}))}function q(){var t=this;if(this[E].disturbed)return $.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[E].disturbed=!0,this[E].error)return $.Promise.reject(this[E].error);let r=this.body;if(null===r)return $.Promise.resolve(Buffer.alloc(0));if(C(r)&&(r=r.stream()),Buffer.isBuffer(r))return $.Promise.resolve(r);if(!(r instanceof e))return $.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new $.Promise((function(e,i){let a;t.timeout&&(a=setTimeout((function(){s=!0,i(new j(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),r.on("error",(function(e){"AbortError"===e.name?(s=!0,i(e)):i(new j(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),r.on("data",(function(e){if(!s&&null!==e){if(t.size&&n+e.length>t.size)return s=!0,void i(new j(`content size at ${t.url} over limit: ${t.size}`,"max-size"));n+=e.length,o.push(e)}})),r.on("end",(function(){if(!s){clearTimeout(a);try{e(Buffer.concat(o,n))}catch(e){i(new j(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function B(e){return"object"==typeof e&&"function"==typeof e.append&&"function"==typeof e.delete&&"function"==typeof e.get&&"function"==typeof e.getAll&&"function"==typeof e.has&&"function"==typeof e.set&&("URLSearchParams"===e.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(e)||"function"==typeof e.sort)}function C(e){return"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&"function"==typeof e.constructor&&"string"==typeof e.constructor.name&&/^(Blob|File)$/.test(e.constructor.name)&&/^(Blob|File)$/.test(e[Symbol.toStringTag])}function R(t){let r,o,n=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof e&&"function"!=typeof n.getBoundary&&(r=new x,o=new x,n.pipe(r),n.pipe(o),t[E].body=r,n=o),n}function _(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":B(t)?"application/x-www-form-urlencoded;charset=UTF-8":C(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 e?null:"text/plain;charset=UTF-8"}function L(e){const t=e.body;return null===t?0:C(t)?t.size:Buffer.isBuffer(t)?t.length:t&&"function"==typeof t.getLengthSync&&(t._lengthRetrievers&&0==t._lengthRetrievers.length||t.hasKnownLength&&t.hasKnownLength())?t.getLengthSync():null}$.prototype={get body(){return this[E].body},get bodyUsed(){return this[E].disturbed},arrayBuffer(){return q.call(this).then((function(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}))},blob(){let e=this.headers&&this.headers.get("content-type")||"";return q.call(this).then((function(t){return Object.assign(new S([],{type:e.toLowerCase()}),{[T]:t})}))},json(){var e=this;return q.call(this).then((function(t){try{return JSON.parse(t.toString())}catch(t){return $.Promise.reject(new j(`invalid json response body at ${e.url} reason: ${t.message}`,"invalid-json"))}}))},text(){return q.call(this).then((function(e){return e.toString()}))},buffer(){return q.call(this)},textConverted(){var e=this;return q.call(this).then((function(t){return function(e,t){if("function"!=typeof P)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=t.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=e.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 P(e,"UTF-8",s).toString()}(t,e.headers)}))}},Object.defineProperties($.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),$.mixIn=function(e){for(const t of Object.getOwnPropertyNames($.prototype))if(!(t in e)){const r=Object.getOwnPropertyDescriptor($.prototype,t);Object.defineProperty(e,t,r)}},$.Promise=global.Promise;const k=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,A=/[^\t\x20-\x7e\x80-\xff]/;function z(e){if(e=`${e}`,k.test(e)||""===e)throw new TypeError(`${e} is not a legal HTTP header name`)}function G(e){if(e=`${e}`,A.test(e))throw new TypeError(`${e} is not a legal HTTP header value`)}function U(e,t){t=t.toLowerCase();for(const r in e)if(r.toLowerCase()===t)return r}const H=Symbol("map");class I{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[H]=Object.create(null),e instanceof I){const t=e.raw(),r=Object.keys(t);for(const e of r)for(const r of t[e])this.append(e,r)}else if(null==e);else{if("object"!=typeof e)throw new TypeError("Provided initializer must be an object");{const t=e[Symbol.iterator];if(null!=t){if("function"!=typeof t)throw new TypeError("Header pairs must be iterable");const r=[];for(const t of e){if("object"!=typeof t||"function"!=typeof t[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(t))}for(const e of r){if(2!==e.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(e[0],e[1])}}else for(const t of Object.keys(e)){const r=e[t];this.append(t,r)}}}}get(e){z(e=`${e}`);const t=U(this[H],e);return void 0===t?null:this[H][t].join(", ")}forEach(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=F(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];e.call(t,i,s,this),r=F(this),o++}}set(e,t){t=`${t}`,z(e=`${e}`),G(t);const r=U(this[H],e);this[H][void 0!==r?r:e]=[t]}append(e,t){t=`${t}`,z(e=`${e}`),G(t);const r=U(this[H],e);void 0!==r?this[H][r].push(t):this[H][e]=[t]}has(e){return z(e=`${e}`),void 0!==U(this[H],e)}delete(e){z(e=`${e}`);const t=U(this[H],e);void 0!==t&&delete this[H][t]}raw(){return this[H]}keys(){return D(this,"key")}values(){return D(this,"value")}[Symbol.iterator](){return D(this,"key+value")}}function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(e[H]).sort();return r.map("key"===t?function(e){return e.toLowerCase()}:"value"===t?function(t){return e[H][t].join(", ")}:function(t){return[t.toLowerCase(),e[H][t].join(", ")]})}I.prototype.entries=I.prototype[Symbol.iterator],Object.defineProperty(I.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(I.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 M=Symbol("internal");function D(e,t){const r=Object.create(V);return r[M]={target:e,kind:t,index:0},r}const V=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==V)throw new TypeError("Value of `this` is not a HeadersIterator");var e=this[M];const t=e.target,r=e.kind,o=e.index,n=F(t,r);return o>=n.length?{value:void 0,done:!0}:(this[M].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function N(e){const t=Object.assign({__proto__:null},e[H]),r=U(e[H],"Host");return void 0!==r&&(t[r]=t[r][0]),t}Object.defineProperty(V,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const W=Symbol("Response internals"),J=t.STATUS_CODES;class Z{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};$.call(this,e,t);const r=t.status||200,o=new I(t.headers);if(null!=e&&!o.has("Content-Type")){const t=_(e);t&&o.append("Content-Type",t)}this[W]={url:t.url,status:r,statusText:t.statusText||J[r],headers:o,counter:t.counter}}get url(){return this[W].url||""}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}clone(){return new Z(R(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}$.mixIn(Z.prototype),Object.defineProperties(Z.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(Z.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const K=Symbol("Request internals"),Y=r.parse,Q=r.format,X="destroy"in e.Readable.prototype;function ee(e){return"object"==typeof e&&"object"==typeof e[K]}class te{constructor(e){let t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ee(e)?t=Y(e.url):(t=e&&e.href?Y(e.href):Y(`${e}`),e={});let o=r.method||e.method||"GET";if(o=o.toUpperCase(),(null!=r.body||ee(e)&&null!==e.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:ee(e)&&null!==e.body?R(e):null;$.call(this,n,{timeout:r.timeout||e.timeout||0,size:r.size||e.size||0});const s=new I(r.headers||e.headers||{});if(null!=n&&!s.has("Content-Type")){const e=_(n);e&&s.append("Content-Type",e)}let i=ee(e)?e.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(e){const t=e&&"object"==typeof e&&Object.getPrototypeOf(e);return!(!t||"AbortSignal"!==t.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[K]={method:o,redirect:r.redirect||e.redirect||"follow",headers:s,parsedURL:t,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==e.follow?e.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===e.compress||e.compress,this.counter=r.counter||e.counter||0,this.agent=r.agent||e.agent}get method(){return this[K].method}get url(){return Q(this[K].parsedURL)}get headers(){return this[K].headers}get redirect(){return this[K].redirect}get signal(){return this[K].signal}clone(){return new te(this)}}function re(e){Error.call(this,e),this.type="aborted",this.message=e,Error.captureStackTrace(this,this.constructor)}$.mixIn(te.prototype),Object.defineProperty(te.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(te.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),re.prototype=Object.create(Error.prototype),re.prototype.constructor=re,re.prototype.name="AbortError";const oe=e.PassThrough,ne=r.resolve;function se(r,o){if(!se.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return $.Promise=se.Promise,new se.Promise((function(n,a){const u=new te(r,o),c=function(t){const r=t[K].parsedURL,o=new I(t[K].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(t.signal&&t.body instanceof e.Readable&&!X)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(n="0"),null!=t.body){const e=L(t);"number"==typeof e&&(n=String(e))}n&&o.set("Content-Length",n),o.has("User-Agent")||o.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!o.has("Accept-Encoding")&&o.set("Accept-Encoding","gzip,deflate");let s=t.agent;return"function"==typeof s&&(s=s(r)),o.has("Connection")||s||o.set("Connection","close"),Object.assign({},r,{method:t.method,headers:N(o),agent:s})}(u),h=("https:"===c.protocol?s:t).request,l=u.signal;let f=null;const p=function(){let t=new re("The user aborted a request.");a(t),u.body&&u.body instanceof e.Readable&&u.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(l&&l.aborted)return void p();const d=function(){p(),b()},m=h(c);let y;function b(){m.abort(),l&&l.removeEventListener("abort",d),clearTimeout(y)}l&&l.addEventListener("abort",d),u.timeout&&m.once("socket",(function(e){y=setTimeout((function(){a(new j(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(e){a(new j(`request to ${u.url} failed, reason: ${e.message}`,"system",e)),b()})),m.on("response",(function(e){clearTimeout(y);const t=function(e){const t=new I;for(const r of Object.keys(e))if(!k.test(r))if(Array.isArray(e[r]))for(const o of e[r])A.test(o)||(void 0===t[H][r]?t[H][r]=[o]:t[H][r].push(o));else A.test(e[r])||(t[H][r]=[e[r]]);return t}(e.headers);if(se.isRedirect(e.statusCode)){const r=t.get("Location"),o=null===r?null:ne(u.url,r);switch(u.redirect){case"error":return a(new j(`uri requested responds with a redirect, redirect mode is set to error: ${u.url}`,"no-redirect")),void b();case"manual":if(null!==o)try{t.set("Location",o)}catch(e){a(e)}break;case"follow":if(null===o)break;if(u.counter>=u.follow)return a(new j(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new I(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!==e.statusCode&&u.body&&null===L(u)?(a(new j("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==e.statusCode&&(301!==e.statusCode&&302!==e.statusCode||"POST"!==u.method)||(r.method="GET",r.body=void 0,r.headers.delete("content-length")),n(se(new te(o,r))),void b())}}e.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=e.pipe(new oe);const o={url:u.url,status:e.statusCode,statusText:e.statusMessage,headers:t,size:u.size,timeout:u.timeout,counter:u.counter},s=t.get("Content-Encoding");if(!u.compress||"HEAD"===u.method||null===s||204===e.statusCode||304===e.statusCode)return f=new Z(r,o),void n(f);const c={flush:i.Z_SYNC_FLUSH,finishFlush:i.Z_SYNC_FLUSH};if("gzip"==s||"x-gzip"==s)return r=r.pipe(i.createGunzip(c)),f=new Z(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 Z(r,o),void n(f);f=new Z(r,o),n(f)}else{e.pipe(new oe).once("data",(function(e){r=8==(15&e[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new Z(r,o),n(f)}))}})),function(e,t){const r=t.body;null===r?e.end():C(r)?r.stream().pipe(e):Buffer.isBuffer(r)?(e.write(r),e.end()):r.pipe(e)}(m,u)}))}se.isRedirect=function(e){return 301===e||302===e||303===e||307===e||308===e},se.Promise=global.Promise;var ie=g(Object.freeze({__proto__:null,default:se,Headers:I,Request:te,Response:Z,FetchError:j}));function ae(e){return e&&e.default||e}var ue=b.fetch=b.fetch||("undefined"==typeof process?ae(v):function(e,t){return ae(ie)(String(e).replace(/^\/\//g,"https://"),t)});class ce extends Error{constructor({meta:e,errors:t}){super(),this.meta=e,this.errors=t}}class he{constructor({token:e,basePath:t,apiVersion:r,debug:s}){this.request=({method:e,path:t,data:r,params:s,compress:i=!0})=>a(this,void 0,void 0,(function*(){var a;let u,c;const h=new o(t,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 e=Object.entries(s).sort().filter((e=>null!==e[0]));h.search=new n(e).toString()}r&&(u=JSON.stringify({data:Object.assign({},r)})),(null===(a=this.debug)||void 0===a?void 0:a.verbose)&&(console.info("Endpoint: ",h.href),console.info("Method: ",e),r&&console.info("Body Parameters: ",r),s&&console.info("Query Parameters: ",s));const f=yield ue(h.href,{method:e,headers:l,body:u,compress:i}),p=f.headers.get("content-type");if(c=p&&p.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in c&&c.errors)throw new ce(c);return c})),this.token=e,this.basePath=t||"https://api.duffel.com",this.apiVersion=r||"beta",this.debug=s}paginatedRequest({path:e,params:t}){return c(this,arguments,(function*(){let r=yield u(this.request({method:"GET",path:e,params:t}));for(const e of r.data)yield yield u({data:e});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield u(this.request({method:"GET",path:e,params:{limit:r.meta.limit,after:r.meta.after}}));for(const e of r.data)yield yield u({data:e})}}))}}class le extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class fe extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class pe extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}class de{constructor(e){this.client=new he(e),this.aircraft=new le(this.client),this.airlines=new fe(this.client),this.airports=new pe(this.client),this.offerRequests=new l(this.client),this.offers=new f(this.client),this.orders=new d(this.client),this.orderCancellations=new p(this.client),this.payments=new m(this.client),this.seatMaps=new y(this.client)}}export{de as Duffel}; | ||
***************************************************************************** */function a(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((o=o.apply(e,t||[])).next())}))}function u(e){return this instanceof u?(this.v=e,this):new u(e)}function c(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=r.apply(e,t||[]),s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(e){n[e]&&(o[e]=function(t){return new Promise((function(r,o){s.push([e,t,r,o])>1||a(e,t)}))})}function a(e,t){try{!function(e){e.value instanceof u?Promise.resolve(e.value.v).then(c,h):l(s[0][2],e)}(n[e](t))}catch(e){l(s[0][3],e)}}function c(e){a("next",e)}function h(e){a("throw",e)}function l(e,t){e(t),s.shift(),s.length&&a(s[0][0],s[0][1])}}class h{constructor(e){this.request=({method:e,path:t,data:r,params:o})=>a(this,void 0,void 0,(function*(){return this.client.request({method:e,path:t,data:r,params:o})})),this.paginatedRequest=({path:e,params:t})=>this.client.paginatedRequest({path:e,params:t}),this.client=e}}class l extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.create=e=>a(this,void 0,void 0,(function*(){const{return_offers:t}=e,r=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}(e,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=t&&{return_offers:t})})})),this.path="air/offer_requests"}}class f extends h{constructor(e){super(e),this.get=(e,t)=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`,params:t})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/offers"}}class p extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.confirm=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${e}/actions/confirm`})})),this.path="air/order_cancellations"}}class d extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:e})})),this.listWithGenerator=e=>this.paginatedRequest({path:"air/orders",params:e}),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/orders"}}class m extends h{constructor(e){super(e),this.create=e=>a(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/payments"}}class y extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:e})})),this.path="air/seat_maps"}}var b="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function g(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})})),t}var v=g(Object.freeze({__proto__:null,default:function(e,t){return t=t||{},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(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in n.open(t.method||"get",e,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==t.credentials,t.headers)n.setRequestHeader(c,t.headers[c]);n.send(t.body||null)}))}}));const w=e.Readable,T=Symbol("buffer"),O=Symbol("type");class S{constructor(){this[O]="";const e=arguments[0],t=arguments[1],r=[];let o=0;if(e){const t=e,n=Number(t.length);for(let e=0;e<n;e++){const n=t[e];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 S?n[T]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[T]=Buffer.concat(r);let n=t&&void 0!==t.type&&String(t.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[O]=n)}get size(){return this[T].length}get type(){return this[O]}text(){return Promise.resolve(this[T].toString())}arrayBuffer(){const e=this[T],t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return Promise.resolve(t)}stream(){const e=new w;return e._read=function(){},e.push(this[T]),e.push(null),e}toString(){return"[object Blob]"}slice(){const e=this.size,t=arguments[0],r=arguments[1];let o,n;o=void 0===t?0:t<0?Math.max(e+t,0):Math.min(t,e),n=void 0===r?e:r<0?Math.max(e+r,0):Math.min(r,e);const s=Math.max(n-o,0),i=this[T].slice(o,o+s),a=new S([],{type:arguments[2]});return a[T]=i,a}}function j(e,t,r){Error.call(this,e),this.message=e,this.type=t,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let P;Object.defineProperties(S.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(S.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),j.prototype=Object.create(Error.prototype),j.prototype.constructor=j,j.prototype.name="FetchError";try{P=require("encoding").convert}catch(e){}const E=Symbol("Body internals"),x=e.PassThrough;function $(t){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==t?t=null:B(t)?t=Buffer.from(t.toString()):C(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 e||(t=Buffer.from(String(t)))),this[E]={body:t,disturbed:!1,error:null},this.size=s,this.timeout=a,t instanceof e&&t.on("error",(function(e){const t="AbortError"===e.name?e:new j(`Invalid response body while trying to fetch ${r.url}: ${e.message}`,"system",e);r[E].error=t}))}function q(){var t=this;if(this[E].disturbed)return $.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[E].disturbed=!0,this[E].error)return $.Promise.reject(this[E].error);let r=this.body;if(null===r)return $.Promise.resolve(Buffer.alloc(0));if(C(r)&&(r=r.stream()),Buffer.isBuffer(r))return $.Promise.resolve(r);if(!(r instanceof e))return $.Promise.resolve(Buffer.alloc(0));let o=[],n=0,s=!1;return new $.Promise((function(e,i){let a;t.timeout&&(a=setTimeout((function(){s=!0,i(new j(`Response timeout while trying to fetch ${t.url} (over ${t.timeout}ms)`,"body-timeout"))}),t.timeout)),r.on("error",(function(e){"AbortError"===e.name?(s=!0,i(e)):i(new j(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e))})),r.on("data",(function(e){if(!s&&null!==e){if(t.size&&n+e.length>t.size)return s=!0,void i(new j(`content size at ${t.url} over limit: ${t.size}`,"max-size"));n+=e.length,o.push(e)}})),r.on("end",(function(){if(!s){clearTimeout(a);try{e(Buffer.concat(o,n))}catch(e){i(new j(`Could not create Buffer from response body for ${t.url}: ${e.message}`,"system",e))}}}))}))}function B(e){return"object"==typeof e&&"function"==typeof e.append&&"function"==typeof e.delete&&"function"==typeof e.get&&"function"==typeof e.getAll&&"function"==typeof e.has&&"function"==typeof e.set&&("URLSearchParams"===e.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(e)||"function"==typeof e.sort)}function C(e){return"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&"function"==typeof e.constructor&&"string"==typeof e.constructor.name&&/^(Blob|File)$/.test(e.constructor.name)&&/^(Blob|File)$/.test(e[Symbol.toStringTag])}function R(t){let r,o,n=t.body;if(t.bodyUsed)throw new Error("cannot clone body after it is used");return n instanceof e&&"function"!=typeof n.getBoundary&&(r=new x,o=new x,n.pipe(r),n.pipe(o),t[E].body=r,n=o),n}function _(t){return null===t?null:"string"==typeof t?"text/plain;charset=UTF-8":B(t)?"application/x-www-form-urlencoded;charset=UTF-8":C(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 e?null:"text/plain;charset=UTF-8"}function L(e){const t=e.body;return null===t?0:C(t)?t.size:Buffer.isBuffer(t)?t.length:t&&"function"==typeof t.getLengthSync&&(t._lengthRetrievers&&0==t._lengthRetrievers.length||t.hasKnownLength&&t.hasKnownLength())?t.getLengthSync():null}$.prototype={get body(){return this[E].body},get bodyUsed(){return this[E].disturbed},arrayBuffer(){return q.call(this).then((function(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}))},blob(){let e=this.headers&&this.headers.get("content-type")||"";return q.call(this).then((function(t){return Object.assign(new S([],{type:e.toLowerCase()}),{[T]:t})}))},json(){var e=this;return q.call(this).then((function(t){try{return JSON.parse(t.toString())}catch(t){return $.Promise.reject(new j(`invalid json response body at ${e.url} reason: ${t.message}`,"invalid-json"))}}))},text(){return q.call(this).then((function(e){return e.toString()}))},buffer(){return q.call(this)},textConverted(){var e=this;return q.call(this).then((function(t){return function(e,t){if("function"!=typeof P)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=t.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=e.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 P(e,"UTF-8",s).toString()}(t,e.headers)}))}},Object.defineProperties($.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),$.mixIn=function(e){for(const t of Object.getOwnPropertyNames($.prototype))if(!(t in e)){const r=Object.getOwnPropertyDescriptor($.prototype,t);Object.defineProperty(e,t,r)}},$.Promise=global.Promise;const k=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,A=/[^\t\x20-\x7e\x80-\xff]/;function z(e){if(e=`${e}`,k.test(e)||""===e)throw new TypeError(`${e} is not a legal HTTP header name`)}function G(e){if(e=`${e}`,A.test(e))throw new TypeError(`${e} is not a legal HTTP header value`)}function U(e,t){t=t.toLowerCase();for(const r in e)if(r.toLowerCase()===t)return r}const H=Symbol("map");class I{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[H]=Object.create(null),e instanceof I){const t=e.raw(),r=Object.keys(t);for(const e of r)for(const r of t[e])this.append(e,r)}else if(null==e);else{if("object"!=typeof e)throw new TypeError("Provided initializer must be an object");{const t=e[Symbol.iterator];if(null!=t){if("function"!=typeof t)throw new TypeError("Header pairs must be iterable");const r=[];for(const t of e){if("object"!=typeof t||"function"!=typeof t[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(t))}for(const e of r){if(2!==e.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(e[0],e[1])}}else for(const t of Object.keys(e)){const r=e[t];this.append(t,r)}}}}get(e){z(e=`${e}`);const t=U(this[H],e);return void 0===t?null:this[H][t].join(", ")}forEach(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=F(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];e.call(t,i,s,this),r=F(this),o++}}set(e,t){t=`${t}`,z(e=`${e}`),G(t);const r=U(this[H],e);this[H][void 0!==r?r:e]=[t]}append(e,t){t=`${t}`,z(e=`${e}`),G(t);const r=U(this[H],e);void 0!==r?this[H][r].push(t):this[H][e]=[t]}has(e){return z(e=`${e}`),void 0!==U(this[H],e)}delete(e){z(e=`${e}`);const t=U(this[H],e);void 0!==t&&delete this[H][t]}raw(){return this[H]}keys(){return D(this,"key")}values(){return D(this,"value")}[Symbol.iterator](){return D(this,"key+value")}}function F(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(e[H]).sort();return r.map("key"===t?function(e){return e.toLowerCase()}:"value"===t?function(t){return e[H][t].join(", ")}:function(t){return[t.toLowerCase(),e[H][t].join(", ")]})}I.prototype.entries=I.prototype[Symbol.iterator],Object.defineProperty(I.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(I.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 M=Symbol("internal");function D(e,t){const r=Object.create(V);return r[M]={target:e,kind:t,index:0},r}const V=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==V)throw new TypeError("Value of `this` is not a HeadersIterator");var e=this[M];const t=e.target,r=e.kind,o=e.index,n=F(t,r);return o>=n.length?{value:void 0,done:!0}:(this[M].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function N(e){const t=Object.assign({__proto__:null},e[H]),r=U(e[H],"Host");return void 0!==r&&(t[r]=t[r][0]),t}Object.defineProperty(V,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const W=Symbol("Response internals"),J=t.STATUS_CODES;class Z{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};$.call(this,e,t);const r=t.status||200,o=new I(t.headers);if(null!=e&&!o.has("Content-Type")){const t=_(e);t&&o.append("Content-Type",t)}this[W]={url:t.url,status:r,statusText:t.statusText||J[r],headers:o,counter:t.counter}}get url(){return this[W].url||""}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}clone(){return new Z(R(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}$.mixIn(Z.prototype),Object.defineProperties(Z.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(Z.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const K=Symbol("Request internals"),Y=r.parse,Q=r.format,X="destroy"in e.Readable.prototype;function ee(e){return"object"==typeof e&&"object"==typeof e[K]}class te{constructor(e){let t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ee(e)?t=Y(e.url):(t=e&&e.href?Y(e.href):Y(`${e}`),e={});let o=r.method||e.method||"GET";if(o=o.toUpperCase(),(null!=r.body||ee(e)&&null!==e.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:ee(e)&&null!==e.body?R(e):null;$.call(this,n,{timeout:r.timeout||e.timeout||0,size:r.size||e.size||0});const s=new I(r.headers||e.headers||{});if(null!=n&&!s.has("Content-Type")){const e=_(n);e&&s.append("Content-Type",e)}let i=ee(e)?e.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(e){const t=e&&"object"==typeof e&&Object.getPrototypeOf(e);return!(!t||"AbortSignal"!==t.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[K]={method:o,redirect:r.redirect||e.redirect||"follow",headers:s,parsedURL:t,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==e.follow?e.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===e.compress||e.compress,this.counter=r.counter||e.counter||0,this.agent=r.agent||e.agent}get method(){return this[K].method}get url(){return Q(this[K].parsedURL)}get headers(){return this[K].headers}get redirect(){return this[K].redirect}get signal(){return this[K].signal}clone(){return new te(this)}}function re(e){Error.call(this,e),this.type="aborted",this.message=e,Error.captureStackTrace(this,this.constructor)}$.mixIn(te.prototype),Object.defineProperty(te.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(te.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),re.prototype=Object.create(Error.prototype),re.prototype.constructor=re,re.prototype.name="AbortError";const oe=e.PassThrough,ne=r.resolve;function se(r,o){if(!se.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return $.Promise=se.Promise,new se.Promise((function(n,a){const u=new te(r,o),c=function(t){const r=t[K].parsedURL,o=new I(t[K].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(t.signal&&t.body instanceof e.Readable&&!X)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let n=null;if(null==t.body&&/^(POST|PUT)$/i.test(t.method)&&(n="0"),null!=t.body){const e=L(t);"number"==typeof e&&(n=String(e))}n&&o.set("Content-Length",n),o.has("User-Agent")||o.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),t.compress&&!o.has("Accept-Encoding")&&o.set("Accept-Encoding","gzip,deflate");let s=t.agent;return"function"==typeof s&&(s=s(r)),o.has("Connection")||s||o.set("Connection","close"),Object.assign({},r,{method:t.method,headers:N(o),agent:s})}(u),h=("https:"===c.protocol?s:t).request,l=u.signal;let f=null;const p=function(){let t=new re("The user aborted a request.");a(t),u.body&&u.body instanceof e.Readable&&u.body.destroy(t),f&&f.body&&f.body.emit("error",t)};if(l&&l.aborted)return void p();const d=function(){p(),b()},m=h(c);let y;function b(){m.abort(),l&&l.removeEventListener("abort",d),clearTimeout(y)}l&&l.addEventListener("abort",d),u.timeout&&m.once("socket",(function(e){y=setTimeout((function(){a(new j(`network timeout at: ${u.url}`,"request-timeout")),b()}),u.timeout)})),m.on("error",(function(e){a(new j(`request to ${u.url} failed, reason: ${e.message}`,"system",e)),b()})),m.on("response",(function(e){clearTimeout(y);const t=function(e){const t=new I;for(const r of Object.keys(e))if(!k.test(r))if(Array.isArray(e[r]))for(const o of e[r])A.test(o)||(void 0===t[H][r]?t[H][r]=[o]:t[H][r].push(o));else A.test(e[r])||(t[H][r]=[e[r]]);return t}(e.headers);if(se.isRedirect(e.statusCode)){const r=t.get("Location"),o=null===r?null:ne(u.url,r);switch(u.redirect){case"error":return a(new j(`uri requested responds with a redirect, redirect mode is set to error: ${u.url}`,"no-redirect")),void b();case"manual":if(null!==o)try{t.set("Location",o)}catch(e){a(e)}break;case"follow":if(null===o)break;if(u.counter>=u.follow)return a(new j(`maximum redirect reached at: ${u.url}`,"max-redirect")),void b();const r={headers:new I(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!==e.statusCode&&u.body&&null===L(u)?(a(new j("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==e.statusCode&&(301!==e.statusCode&&302!==e.statusCode||"POST"!==u.method)||(r.method="GET",r.body=void 0,r.headers.delete("content-length")),n(se(new te(o,r))),void b())}}e.once("end",(function(){l&&l.removeEventListener("abort",d)}));let r=e.pipe(new oe);const o={url:u.url,status:e.statusCode,statusText:e.statusMessage,headers:t,size:u.size,timeout:u.timeout,counter:u.counter},s=t.get("Content-Encoding");if(!u.compress||"HEAD"===u.method||null===s||204===e.statusCode||304===e.statusCode)return f=new Z(r,o),void n(f);const c={flush:i.Z_SYNC_FLUSH,finishFlush:i.Z_SYNC_FLUSH};if("gzip"==s||"x-gzip"==s)return r=r.pipe(i.createGunzip(c)),f=new Z(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 Z(r,o),void n(f);f=new Z(r,o),n(f)}else{e.pipe(new oe).once("data",(function(e){r=8==(15&e[0])?r.pipe(i.createInflate()):r.pipe(i.createInflateRaw()),f=new Z(r,o),n(f)}))}})),function(e,t){const r=t.body;null===r?e.end():C(r)?r.stream().pipe(e):Buffer.isBuffer(r)?(e.write(r),e.end()):r.pipe(e)}(m,u)}))}se.isRedirect=function(e){return 301===e||302===e||303===e||307===e||308===e},se.Promise=global.Promise;var ie=g(Object.freeze({__proto__:null,default:se,Headers:I,Request:te,Response:Z,FetchError:j}));function ae(e){return e&&e.default||e}var ue=b.fetch=b.fetch||("undefined"==typeof process?ae(v):function(e,t){return ae(ie)(String(e).replace(/^\/\//g,"https://"),t)});class ce extends Error{constructor({meta:e,errors:t}){super(),this.meta=e,this.errors=t}}class he{constructor({token:e,basePath:t,apiVersion:r,debug:s}){this.request=({method:e,path:t,data:r,params:s,compress:i=!0})=>a(this,void 0,void 0,(function*(){var a;let u,c;const h=new o(t,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 e=Object.entries(s).sort().filter((e=>null!==e[0]));h.search=new n(e).toString()}r&&(u=JSON.stringify({data:Object.assign({},r)})),(null===(a=this.debug)||void 0===a?void 0:a.verbose)&&(console.info("Endpoint: ",h.href),console.info("Method: ",e),r&&console.info("Body Parameters: ",r),s&&console.info("Query Parameters: ",s));const f=yield ue(h.href,{method:e,headers:l,body:u,compress:i}),p=f.headers.get("content-type");if(c=p&&p.includes("json")?yield f.json():yield f.text(),!f.ok||"errors"in c&&c.errors)throw new ce(c);return c})),this.token=e,this.basePath=t||"https://api.duffel.com",this.apiVersion=r||"beta",this.debug=s}paginatedRequest({path:e,params:t}){return c(this,arguments,(function*(){let r=yield u(this.request({method:"GET",path:e,params:t}));for(const e of r.data)yield yield u({data:e});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield u(this.request({method:"GET",path:e,params:{limit:r.meta.limit,after:r.meta.after}}));for(const e of r.data)yield yield u({data:e})}}))}}class le extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class fe extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class pe extends h{constructor(e){super(e),this.get=e=>a(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}class de{constructor(e){this.client=new he(e),this.aircraft=new le(this.client),this.airlines=new fe(this.client),this.airports=new pe(this.client),this.offerRequests=new l(this.client),this.offers=new f(this.client),this.orders=new d(this.client),this.orderCancellations=new p(this.client),this.payments=new m(this.client),this.seatMaps=new y(this.client)}}export{de as Duffel}; | ||
//# sourceMappingURL=index.es.js.map |
@@ -16,3 +16,3 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("stream"),t=require("http"),r=require("url"),o=require("https"),n=require("zlib");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=s(e),a=s(t),u=s(r),c=s(o),l=s(n);function h(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((o=o.apply(e,t||[])).next())}))}function f(e){return this instanceof f?(this.v=e,this):new f(e)}function d(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var o,n=r.apply(e,t||[]),s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(e){n[e]&&(o[e]=function(t){return new Promise((function(r,o){s.push([e,t,r,o])>1||a(e,t)}))})}function a(e,t){try{!function(e){e.value instanceof f?Promise.resolve(e.value.v).then(u,c):l(s[0][2],e)}(n[e](t))}catch(e){l(s[0][3],e)}}function u(e){a("next",e)}function c(e){a("throw",e)}function l(e,t){e(t),s.shift(),s.length&&a(s[0][0],s[0][1])}}class p{constructor(e){this.request=({method:e,path:t,data:r,params:o})=>h(this,void 0,void 0,(function*(){return this.client.request({method:e,path:t,data:r,params:o})})),this.paginatedRequest=({path:e,params:t})=>this.client.paginatedRequest({path:e,params:t}),this.client=e}}class m extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.create=e=>h(this,void 0,void 0,(function*(){const{return_offers:t}=e,r= | ||
***************************************************************************** */ | ||
function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}(e,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:{return_offers:t}})})),this.path="air/offer_requests"}}class y extends p{constructor(e){super(e),this.get=(e,t)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`,params:t})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/offers"}}class b extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.confirm=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${e}/actions/confirm`})})),this.path="air/order_cancellations"}}class g extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:e})})),this.listWithGenerator=e=>this.paginatedRequest({path:"air/orders",params:e}),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/orders"}}class v extends p{constructor(e){super(e),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/payments"}}class w extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:e})})),this.path="air/seat_maps"}}var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function O(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})})),t}var S=O(Object.freeze({__proto__:null,default:function(e,t){return t=t||{},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(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in n.open(t.method||"get",e,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==t.credentials,t.headers)n.setRequestHeader(c,t.headers[c]);n.send(t.body||null)}))}}));const j=i.default.Readable,P=Symbol("buffer"),E=Symbol("type");class x{constructor(){this[E]="";const e=arguments[0],t=arguments[1],r=[];let o=0;if(e){const t=e,n=Number(t.length);for(let e=0;e<n;e++){const n=t[e];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 x?n[P]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[P]=Buffer.concat(r);let n=t&&void 0!==t.type&&String(t.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[E]=n)}get size(){return this[P].length}get type(){return this[E]}text(){return Promise.resolve(this[P].toString())}arrayBuffer(){const e=this[P],t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return Promise.resolve(t)}stream(){const e=new j;return e._read=function(){},e.push(this[P]),e.push(null),e}toString(){return"[object Blob]"}slice(){const e=this.size,t=arguments[0],r=arguments[1];let o,n;o=void 0===t?0:t<0?Math.max(e+t,0):Math.min(t,e),n=void 0===r?e:r<0?Math.max(e+r,0):Math.min(r,e);const s=Math.max(n-o,0),i=this[P].slice(o,o+s),a=new x([],{type:arguments[2]});return a[P]=i,a}}function $(e,t,r){Error.call(this,e),this.message=e,this.type=t,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let q;Object.defineProperties(x.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(x.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),$.prototype=Object.create(Error.prototype),$.prototype.constructor=$,$.prototype.name="FetchError";try{q=require("encoding").convert}catch(e){}const B=Symbol("Body internals"),R=i.default.PassThrough;function C(e){var t=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==e?e=null:L(e)?e=Buffer.from(e.toString()):k(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 i.default||(e=Buffer.from(String(e)))),this[B]={body:e,disturbed:!1,error:null},this.size=n,this.timeout=a,e instanceof i.default&&e.on("error",(function(e){const r="AbortError"===e.name?e:new $(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e);t[B].error=r}))}function _(){var e=this;if(this[B].disturbed)return C.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[B].disturbed=!0,this[B].error)return C.Promise.reject(this[B].error);let t=this.body;if(null===t)return C.Promise.resolve(Buffer.alloc(0));if(k(t)&&(t=t.stream()),Buffer.isBuffer(t))return C.Promise.resolve(t);if(!(t instanceof i.default))return C.Promise.resolve(Buffer.alloc(0));let r=[],o=0,n=!1;return new C.Promise((function(s,i){let a;e.timeout&&(a=setTimeout((function(){n=!0,i(new $(`Response timeout while trying to fetch ${e.url} (over ${e.timeout}ms)`,"body-timeout"))}),e.timeout)),t.on("error",(function(t){"AbortError"===t.name?(n=!0,i(t)):i(new $(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t))})),t.on("data",(function(t){if(!n&&null!==t){if(e.size&&o+t.length>e.size)return n=!0,void i(new $(`content size at ${e.url} over limit: ${e.size}`,"max-size"));o+=t.length,r.push(t)}})),t.on("end",(function(){if(!n){clearTimeout(a);try{s(Buffer.concat(r,o))}catch(t){i(new $(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function L(e){return"object"==typeof e&&"function"==typeof e.append&&"function"==typeof e.delete&&"function"==typeof e.get&&"function"==typeof e.getAll&&"function"==typeof e.has&&"function"==typeof e.set&&("URLSearchParams"===e.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(e)||"function"==typeof e.sort)}function k(e){return"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&"function"==typeof e.constructor&&"string"==typeof e.constructor.name&&/^(Blob|File)$/.test(e.constructor.name)&&/^(Blob|File)$/.test(e[Symbol.toStringTag])}function A(e){let t,r,o=e.body;if(e.bodyUsed)throw new Error("cannot clone body after it is used");return o instanceof i.default&&"function"!=typeof o.getBoundary&&(t=new R,r=new R,o.pipe(t),o.pipe(r),e[B].body=t,o=r),o}function z(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":L(e)?"application/x-www-form-urlencoded;charset=UTF-8":k(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 i.default?null:"text/plain;charset=UTF-8"}function G(e){const t=e.body;return null===t?0:k(t)?t.size:Buffer.isBuffer(t)?t.length:t&&"function"==typeof t.getLengthSync&&(t._lengthRetrievers&&0==t._lengthRetrievers.length||t.hasKnownLength&&t.hasKnownLength())?t.getLengthSync():null}C.prototype={get body(){return this[B].body},get bodyUsed(){return this[B].disturbed},arrayBuffer(){return _.call(this).then((function(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}))},blob(){let e=this.headers&&this.headers.get("content-type")||"";return _.call(this).then((function(t){return Object.assign(new x([],{type:e.toLowerCase()}),{[P]:t})}))},json(){var e=this;return _.call(this).then((function(t){try{return JSON.parse(t.toString())}catch(t){return C.Promise.reject(new $(`invalid json response body at ${e.url} reason: ${t.message}`,"invalid-json"))}}))},text(){return _.call(this).then((function(e){return e.toString()}))},buffer(){return _.call(this)},textConverted(){var e=this;return _.call(this).then((function(t){return function(e,t){if("function"!=typeof q)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=t.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=e.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 q(e,"UTF-8",s).toString()}(t,e.headers)}))}},Object.defineProperties(C.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),C.mixIn=function(e){for(const t of Object.getOwnPropertyNames(C.prototype))if(!(t in e)){const r=Object.getOwnPropertyDescriptor(C.prototype,t);Object.defineProperty(e,t,r)}},C.Promise=global.Promise;const U=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,H=/[^\t\x20-\x7e\x80-\xff]/;function I(e){if(e=`${e}`,U.test(e)||""===e)throw new TypeError(`${e} is not a legal HTTP header name`)}function M(e){if(e=`${e}`,H.test(e))throw new TypeError(`${e} is not a legal HTTP header value`)}function D(e,t){t=t.toLowerCase();for(const r in e)if(r.toLowerCase()===t)return r}const F=Symbol("map");class V{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[F]=Object.create(null),e instanceof V){const t=e.raw(),r=Object.keys(t);for(const e of r)for(const r of t[e])this.append(e,r)}else if(null==e);else{if("object"!=typeof e)throw new TypeError("Provided initializer must be an object");{const t=e[Symbol.iterator];if(null!=t){if("function"!=typeof t)throw new TypeError("Header pairs must be iterable");const r=[];for(const t of e){if("object"!=typeof t||"function"!=typeof t[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(t))}for(const e of r){if(2!==e.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(e[0],e[1])}}else for(const t of Object.keys(e)){const r=e[t];this.append(t,r)}}}}get(e){I(e=`${e}`);const t=D(this[F],e);return void 0===t?null:this[F][t].join(", ")}forEach(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=N(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];e.call(t,i,s,this),r=N(this),o++}}set(e,t){t=`${t}`,I(e=`${e}`),M(t);const r=D(this[F],e);this[F][void 0!==r?r:e]=[t]}append(e,t){t=`${t}`,I(e=`${e}`),M(t);const r=D(this[F],e);void 0!==r?this[F][r].push(t):this[F][e]=[t]}has(e){return I(e=`${e}`),void 0!==D(this[F],e)}delete(e){I(e=`${e}`);const t=D(this[F],e);void 0!==t&&delete this[F][t]}raw(){return this[F]}keys(){return J(this,"key")}values(){return J(this,"value")}[Symbol.iterator](){return J(this,"key+value")}}function N(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(e[F]).sort();return r.map("key"===t?function(e){return e.toLowerCase()}:"value"===t?function(t){return e[F][t].join(", ")}:function(t){return[t.toLowerCase(),e[F][t].join(", ")]})}V.prototype.entries=V.prototype[Symbol.iterator],Object.defineProperty(V.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(V.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 W=Symbol("internal");function J(e,t){const r=Object.create(Z);return r[W]={target:e,kind:t,index:0},r}const Z=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==Z)throw new TypeError("Value of `this` is not a HeadersIterator");var e=this[W];const t=e.target,r=e.kind,o=e.index,n=N(t,r);return o>=n.length?{value:void 0,done:!0}:(this[W].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function K(e){const t=Object.assign({__proto__:null},e[F]),r=D(e[F],"Host");return void 0!==r&&(t[r]=t[r][0]),t}Object.defineProperty(Z,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const Y=Symbol("Response internals"),Q=a.default.STATUS_CODES;class X{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};C.call(this,e,t);const r=t.status||200,o=new V(t.headers);if(null!=e&&!o.has("Content-Type")){const t=z(e);t&&o.append("Content-Type",t)}this[Y]={url:t.url,status:r,statusText:t.statusText||Q[r],headers:o,counter:t.counter}}get url(){return this[Y].url||""}get status(){return this[Y].status}get ok(){return this[Y].status>=200&&this[Y].status<300}get redirected(){return this[Y].counter>0}get statusText(){return this[Y].statusText}get headers(){return this[Y].headers}clone(){return new X(A(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}C.mixIn(X.prototype),Object.defineProperties(X.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(X.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ee=Symbol("Request internals"),te=u.default.parse,re=u.default.format,oe="destroy"in i.default.Readable.prototype;function ne(e){return"object"==typeof e&&"object"==typeof e[ee]}class se{constructor(e){let t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ne(e)?t=te(e.url):(t=e&&e.href?te(e.href):te(`${e}`),e={});let o=r.method||e.method||"GET";if(o=o.toUpperCase(),(null!=r.body||ne(e)&&null!==e.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:ne(e)&&null!==e.body?A(e):null;C.call(this,n,{timeout:r.timeout||e.timeout||0,size:r.size||e.size||0});const s=new V(r.headers||e.headers||{});if(null!=n&&!s.has("Content-Type")){const e=z(n);e&&s.append("Content-Type",e)}let i=ne(e)?e.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(e){const t=e&&"object"==typeof e&&Object.getPrototypeOf(e);return!(!t||"AbortSignal"!==t.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[ee]={method:o,redirect:r.redirect||e.redirect||"follow",headers:s,parsedURL:t,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==e.follow?e.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===e.compress||e.compress,this.counter=r.counter||e.counter||0,this.agent=r.agent||e.agent}get method(){return this[ee].method}get url(){return re(this[ee].parsedURL)}get headers(){return this[ee].headers}get redirect(){return this[ee].redirect}get signal(){return this[ee].signal}clone(){return new se(this)}}function ie(e){Error.call(this,e),this.type="aborted",this.message=e,Error.captureStackTrace(this,this.constructor)}C.mixIn(se.prototype),Object.defineProperty(se.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(se.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),ie.prototype=Object.create(Error.prototype),ie.prototype.constructor=ie,ie.prototype.name="AbortError";const ae=i.default.PassThrough,ue=u.default.resolve;function ce(e,t){if(!ce.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return C.Promise=ce.Promise,new ce.Promise((function(r,o){const n=new se(e,t),s=function(e){const t=e[ee].parsedURL,r=new V(e[ee].headers);if(r.has("Accept")||r.set("Accept","*/*"),!t.protocol||!t.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(t.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(e.signal&&e.body instanceof i.default.Readable&&!oe)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let o=null;if(null==e.body&&/^(POST|PUT)$/i.test(e.method)&&(o="0"),null!=e.body){const t=G(e);"number"==typeof t&&(o=String(t))}o&&r.set("Content-Length",o),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),e.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let n=e.agent;return"function"==typeof n&&(n=n(t)),r.has("Connection")||n||r.set("Connection","close"),Object.assign({},t,{method:e.method,headers:K(r),agent:n})}(n),u=("https:"===s.protocol?c.default:a.default).request,h=n.signal;let f=null;const d=function(){let e=new ie("The user aborted a request.");o(e),n.body&&n.body instanceof i.default.Readable&&n.body.destroy(e),f&&f.body&&f.body.emit("error",e)};if(h&&h.aborted)return void d();const p=function(){d(),b()},m=u(s);let y;function b(){m.abort(),h&&h.removeEventListener("abort",p),clearTimeout(y)}h&&h.addEventListener("abort",p),n.timeout&&m.once("socket",(function(e){y=setTimeout((function(){o(new $(`network timeout at: ${n.url}`,"request-timeout")),b()}),n.timeout)})),m.on("error",(function(e){o(new $(`request to ${n.url} failed, reason: ${e.message}`,"system",e)),b()})),m.on("response",(function(e){clearTimeout(y);const t=function(e){const t=new V;for(const r of Object.keys(e))if(!U.test(r))if(Array.isArray(e[r]))for(const o of e[r])H.test(o)||(void 0===t[F][r]?t[F][r]=[o]:t[F][r].push(o));else H.test(e[r])||(t[F][r]=[e[r]]);return t}(e.headers);if(ce.isRedirect(e.statusCode)){const s=t.get("Location"),i=null===s?null:ue(n.url,s);switch(n.redirect){case"error":return o(new $(`uri requested responds with a redirect, redirect mode is set to error: ${n.url}`,"no-redirect")),void b();case"manual":if(null!==i)try{t.set("Location",i)}catch(e){o(e)}break;case"follow":if(null===i)break;if(n.counter>=n.follow)return o(new $(`maximum redirect reached at: ${n.url}`,"max-redirect")),void b();const s={headers:new V(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!==e.statusCode&&n.body&&null===G(n)?(o(new $("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==e.statusCode&&(301!==e.statusCode&&302!==e.statusCode||"POST"!==n.method)||(s.method="GET",s.body=void 0,s.headers.delete("content-length")),r(ce(new se(i,s))),void b())}}e.once("end",(function(){h&&h.removeEventListener("abort",p)}));let s=e.pipe(new ae);const i={url:n.url,status:e.statusCode,statusText:e.statusMessage,headers:t,size:n.size,timeout:n.timeout,counter:n.counter},a=t.get("Content-Encoding");if(!n.compress||"HEAD"===n.method||null===a||204===e.statusCode||304===e.statusCode)return f=new X(s,i),void r(f);const u={flush:l.default.Z_SYNC_FLUSH,finishFlush:l.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return s=s.pipe(l.default.createGunzip(u)),f=new X(s,i),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof l.default.createBrotliDecompress)return s=s.pipe(l.default.createBrotliDecompress()),f=new X(s,i),void r(f);f=new X(s,i),r(f)}else{e.pipe(new ae).once("data",(function(e){s=8==(15&e[0])?s.pipe(l.default.createInflate()):s.pipe(l.default.createInflateRaw()),f=new X(s,i),r(f)}))}})),function(e,t){const r=t.body;null===r?e.end():k(r)?r.stream().pipe(e):Buffer.isBuffer(r)?(e.write(r),e.end()):r.pipe(e)}(m,n)}))}ce.isRedirect=function(e){return 301===e||302===e||303===e||307===e||308===e},ce.Promise=global.Promise;var le=O(Object.freeze({__proto__:null,default:ce,Headers:V,Request:se,Response:X,FetchError:$}));function he(e){return e&&e.default||e}var fe=T.fetch=T.fetch||("undefined"==typeof process?he(S):function(e,t){return he(le)(String(e).replace(/^\/\//g,"https://"),t)});class de extends Error{constructor({meta:e,errors:t}){super(),this.meta=e,this.errors=t}}class pe{constructor({token:e,basePath:t,apiVersion:o,debug:n}){this.request=({method:e,path:t,data:o,params:n,compress:s=!0})=>h(this,void 0,void 0,(function*(){var i;let a,u;const c=new r.URL(t,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(n){const e=Object.entries(n).sort().filter((e=>null!==e[0]));c.search=new r.URLSearchParams(e).toString()}o&&(a=JSON.stringify({data:Object.assign({},o)})),(null===(i=this.debug)||void 0===i?void 0:i.verbose)&&(console.info("Endpoint: ",c.href),console.info("Method: ",e),o&&console.info("Body Parameters: ",o),n&&console.info("Query Parameters: ",n));const h=yield fe(c.href,{method:e,headers:l,body:a,compress:s}),f=h.headers.get("content-type");if(u=f&&f.includes("json")?yield h.json():yield h.text(),!h.ok||"errors"in u&&u.errors)throw new de(u);return u})),this.token=e,this.basePath=t||"https://api.duffel.com",this.apiVersion=o||"beta",this.debug=n}paginatedRequest({path:e,params:t}){return d(this,arguments,(function*(){let r=yield f(this.request({method:"GET",path:e,params:t}));for(const e of r.data)yield yield f({data:e});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield f(this.request({method:"GET",path:e,params:{limit:r.meta.limit,after:r.meta.after}}));for(const e of r.data)yield yield f({data:e})}}))}}class me extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class ye extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class be extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}exports.Duffel=class{constructor(e){this.client=new pe(e),this.aircraft=new me(this.client),this.airlines=new ye(this.client),this.airports=new be(this.client),this.offerRequests=new m(this.client),this.offers=new y(this.client),this.orders=new g(this.client),this.orderCancellations=new b(this.client),this.payments=new v(this.client),this.seatMaps=new w(this.client)}}; | ||
function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}(e,["return_offers"]);return this.request({method:"POST",path:`${this.path}/`,data:r,params:Object.assign({},null!=t&&{return_offers:t})})})),this.path="air/offer_requests"}}class y extends p{constructor(e){super(e),this.get=(e,t)=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`,params:t})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/offers"}}class b extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.confirm=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:`${this.path}/${e}/actions/confirm`})})),this.path="air/order_cancellations"}}class g extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:this.path,params:e})})),this.listWithGenerator=e=>this.paginatedRequest({path:"air/orders",params:e}),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/orders"}}class v extends p{constructor(e){super(e),this.create=e=>h(this,void 0,void 0,(function*(){return this.request({method:"POST",path:this.path,data:e})})),this.path="air/payments"}}class w extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}`,params:e})})),this.path="air/seat_maps"}}var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function O(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})})),t}var j=O(Object.freeze({__proto__:null,default:function(e,t){return t=t||{},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(e){return a[e.toLowerCase()]},has:function(e){return e.toLowerCase()in a}}}};for(var c in n.open(t.method||"get",e,!0),n.onload=function(){n.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,(function(e,t,r){s.push(t=t.toLowerCase()),i.push([t,r]),a[t]=a[t]?a[t]+","+r:r})),r(u())},n.onerror=o,n.withCredentials="include"==t.credentials,t.headers)n.setRequestHeader(c,t.headers[c]);n.send(t.body||null)}))}}));const S=i.default.Readable,P=Symbol("buffer"),E=Symbol("type");class x{constructor(){this[E]="";const e=arguments[0],t=arguments[1],r=[];let o=0;if(e){const t=e,n=Number(t.length);for(let e=0;e<n;e++){const n=t[e];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 x?n[P]:Buffer.from("string"==typeof n?n:String(n)),o+=s.length,r.push(s)}}this[P]=Buffer.concat(r);let n=t&&void 0!==t.type&&String(t.type).toLowerCase();n&&!/[^\u0020-\u007E]/.test(n)&&(this[E]=n)}get size(){return this[P].length}get type(){return this[E]}text(){return Promise.resolve(this[P].toString())}arrayBuffer(){const e=this[P],t=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return Promise.resolve(t)}stream(){const e=new S;return e._read=function(){},e.push(this[P]),e.push(null),e}toString(){return"[object Blob]"}slice(){const e=this.size,t=arguments[0],r=arguments[1];let o,n;o=void 0===t?0:t<0?Math.max(e+t,0):Math.min(t,e),n=void 0===r?e:r<0?Math.max(e+r,0):Math.min(r,e);const s=Math.max(n-o,0),i=this[P].slice(o,o+s),a=new x([],{type:arguments[2]});return a[P]=i,a}}function $(e,t,r){Error.call(this,e),this.message=e,this.type=t,r&&(this.code=this.errno=r.code),Error.captureStackTrace(this,this.constructor)}let q;Object.defineProperties(x.prototype,{size:{enumerable:!0},type:{enumerable:!0},slice:{enumerable:!0}}),Object.defineProperty(x.prototype,Symbol.toStringTag,{value:"Blob",writable:!1,enumerable:!1,configurable:!0}),$.prototype=Object.create(Error.prototype),$.prototype.constructor=$,$.prototype.name="FetchError";try{q=require("encoding").convert}catch(e){}const B=Symbol("Body internals"),R=i.default.PassThrough;function C(e){var t=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==e?e=null:L(e)?e=Buffer.from(e.toString()):k(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 i.default||(e=Buffer.from(String(e)))),this[B]={body:e,disturbed:!1,error:null},this.size=n,this.timeout=a,e instanceof i.default&&e.on("error",(function(e){const r="AbortError"===e.name?e:new $(`Invalid response body while trying to fetch ${t.url}: ${e.message}`,"system",e);t[B].error=r}))}function _(){var e=this;if(this[B].disturbed)return C.Promise.reject(new TypeError(`body used already for: ${this.url}`));if(this[B].disturbed=!0,this[B].error)return C.Promise.reject(this[B].error);let t=this.body;if(null===t)return C.Promise.resolve(Buffer.alloc(0));if(k(t)&&(t=t.stream()),Buffer.isBuffer(t))return C.Promise.resolve(t);if(!(t instanceof i.default))return C.Promise.resolve(Buffer.alloc(0));let r=[],o=0,n=!1;return new C.Promise((function(s,i){let a;e.timeout&&(a=setTimeout((function(){n=!0,i(new $(`Response timeout while trying to fetch ${e.url} (over ${e.timeout}ms)`,"body-timeout"))}),e.timeout)),t.on("error",(function(t){"AbortError"===t.name?(n=!0,i(t)):i(new $(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,"system",t))})),t.on("data",(function(t){if(!n&&null!==t){if(e.size&&o+t.length>e.size)return n=!0,void i(new $(`content size at ${e.url} over limit: ${e.size}`,"max-size"));o+=t.length,r.push(t)}})),t.on("end",(function(){if(!n){clearTimeout(a);try{s(Buffer.concat(r,o))}catch(t){i(new $(`Could not create Buffer from response body for ${e.url}: ${t.message}`,"system",t))}}}))}))}function L(e){return"object"==typeof e&&"function"==typeof e.append&&"function"==typeof e.delete&&"function"==typeof e.get&&"function"==typeof e.getAll&&"function"==typeof e.has&&"function"==typeof e.set&&("URLSearchParams"===e.constructor.name||"[object URLSearchParams]"===Object.prototype.toString.call(e)||"function"==typeof e.sort)}function k(e){return"object"==typeof e&&"function"==typeof e.arrayBuffer&&"string"==typeof e.type&&"function"==typeof e.stream&&"function"==typeof e.constructor&&"string"==typeof e.constructor.name&&/^(Blob|File)$/.test(e.constructor.name)&&/^(Blob|File)$/.test(e[Symbol.toStringTag])}function A(e){let t,r,o=e.body;if(e.bodyUsed)throw new Error("cannot clone body after it is used");return o instanceof i.default&&"function"!=typeof o.getBoundary&&(t=new R,r=new R,o.pipe(t),o.pipe(r),e[B].body=t,o=r),o}function z(e){return null===e?null:"string"==typeof e?"text/plain;charset=UTF-8":L(e)?"application/x-www-form-urlencoded;charset=UTF-8":k(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 i.default?null:"text/plain;charset=UTF-8"}function G(e){const t=e.body;return null===t?0:k(t)?t.size:Buffer.isBuffer(t)?t.length:t&&"function"==typeof t.getLengthSync&&(t._lengthRetrievers&&0==t._lengthRetrievers.length||t.hasKnownLength&&t.hasKnownLength())?t.getLengthSync():null}C.prototype={get body(){return this[B].body},get bodyUsed(){return this[B].disturbed},arrayBuffer(){return _.call(this).then((function(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}))},blob(){let e=this.headers&&this.headers.get("content-type")||"";return _.call(this).then((function(t){return Object.assign(new x([],{type:e.toLowerCase()}),{[P]:t})}))},json(){var e=this;return _.call(this).then((function(t){try{return JSON.parse(t.toString())}catch(t){return C.Promise.reject(new $(`invalid json response body at ${e.url} reason: ${t.message}`,"invalid-json"))}}))},text(){return _.call(this).then((function(e){return e.toString()}))},buffer(){return _.call(this)},textConverted(){var e=this;return _.call(this).then((function(t){return function(e,t){if("function"!=typeof q)throw new Error("The package `encoding` must be installed to use the textConverted() function");const r=t.get("content-type");let o,n,s="utf-8";r&&(o=/charset=([^;]*)/i.exec(r));n=e.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 q(e,"UTF-8",s).toString()}(t,e.headers)}))}},Object.defineProperties(C.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0}}),C.mixIn=function(e){for(const t of Object.getOwnPropertyNames(C.prototype))if(!(t in e)){const r=Object.getOwnPropertyDescriptor(C.prototype,t);Object.defineProperty(e,t,r)}},C.Promise=global.Promise;const U=/[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/,H=/[^\t\x20-\x7e\x80-\xff]/;function I(e){if(e=`${e}`,U.test(e)||""===e)throw new TypeError(`${e} is not a legal HTTP header name`)}function M(e){if(e=`${e}`,H.test(e))throw new TypeError(`${e} is not a legal HTTP header value`)}function D(e,t){t=t.toLowerCase();for(const r in e)if(r.toLowerCase()===t)return r}const F=Symbol("map");class V{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;if(this[F]=Object.create(null),e instanceof V){const t=e.raw(),r=Object.keys(t);for(const e of r)for(const r of t[e])this.append(e,r)}else if(null==e);else{if("object"!=typeof e)throw new TypeError("Provided initializer must be an object");{const t=e[Symbol.iterator];if(null!=t){if("function"!=typeof t)throw new TypeError("Header pairs must be iterable");const r=[];for(const t of e){if("object"!=typeof t||"function"!=typeof t[Symbol.iterator])throw new TypeError("Each header pair must be iterable");r.push(Array.from(t))}for(const e of r){if(2!==e.length)throw new TypeError("Each header pair must be a name/value tuple");this.append(e[0],e[1])}}else for(const t of Object.keys(e)){const r=e[t];this.append(t,r)}}}}get(e){I(e=`${e}`);const t=D(this[F],e);return void 0===t?null:this[F][t].join(", ")}forEach(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=N(this),o=0;for(;o<r.length;){var n=r[o];const s=n[0],i=n[1];e.call(t,i,s,this),r=N(this),o++}}set(e,t){t=`${t}`,I(e=`${e}`),M(t);const r=D(this[F],e);this[F][void 0!==r?r:e]=[t]}append(e,t){t=`${t}`,I(e=`${e}`),M(t);const r=D(this[F],e);void 0!==r?this[F][r].push(t):this[F][e]=[t]}has(e){return I(e=`${e}`),void 0!==D(this[F],e)}delete(e){I(e=`${e}`);const t=D(this[F],e);void 0!==t&&delete this[F][t]}raw(){return this[F]}keys(){return J(this,"key")}values(){return J(this,"value")}[Symbol.iterator](){return J(this,"key+value")}}function N(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"key+value";const r=Object.keys(e[F]).sort();return r.map("key"===t?function(e){return e.toLowerCase()}:"value"===t?function(t){return e[F][t].join(", ")}:function(t){return[t.toLowerCase(),e[F][t].join(", ")]})}V.prototype.entries=V.prototype[Symbol.iterator],Object.defineProperty(V.prototype,Symbol.toStringTag,{value:"Headers",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(V.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 W=Symbol("internal");function J(e,t){const r=Object.create(Z);return r[W]={target:e,kind:t,index:0},r}const Z=Object.setPrototypeOf({next(){if(!this||Object.getPrototypeOf(this)!==Z)throw new TypeError("Value of `this` is not a HeadersIterator");var e=this[W];const t=e.target,r=e.kind,o=e.index,n=N(t,r);return o>=n.length?{value:void 0,done:!0}:(this[W].index=o+1,{value:n[o],done:!1})}},Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));function K(e){const t=Object.assign({__proto__:null},e[F]),r=D(e[F],"Host");return void 0!==r&&(t[r]=t[r][0]),t}Object.defineProperty(Z,Symbol.toStringTag,{value:"HeadersIterator",writable:!1,enumerable:!1,configurable:!0});const Y=Symbol("Response internals"),Q=a.default.STATUS_CODES;class X{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};C.call(this,e,t);const r=t.status||200,o=new V(t.headers);if(null!=e&&!o.has("Content-Type")){const t=z(e);t&&o.append("Content-Type",t)}this[Y]={url:t.url,status:r,statusText:t.statusText||Q[r],headers:o,counter:t.counter}}get url(){return this[Y].url||""}get status(){return this[Y].status}get ok(){return this[Y].status>=200&&this[Y].status<300}get redirected(){return this[Y].counter>0}get statusText(){return this[Y].statusText}get headers(){return this[Y].headers}clone(){return new X(A(this),{url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected})}}C.mixIn(X.prototype),Object.defineProperties(X.prototype,{url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}}),Object.defineProperty(X.prototype,Symbol.toStringTag,{value:"Response",writable:!1,enumerable:!1,configurable:!0});const ee=Symbol("Request internals"),te=u.default.parse,re=u.default.format,oe="destroy"in i.default.Readable.prototype;function ne(e){return"object"==typeof e&&"object"==typeof e[ee]}class se{constructor(e){let t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};ne(e)?t=te(e.url):(t=e&&e.href?te(e.href):te(`${e}`),e={});let o=r.method||e.method||"GET";if(o=o.toUpperCase(),(null!=r.body||ne(e)&&null!==e.body)&&("GET"===o||"HEAD"===o))throw new TypeError("Request with GET/HEAD method cannot have body");let n=null!=r.body?r.body:ne(e)&&null!==e.body?A(e):null;C.call(this,n,{timeout:r.timeout||e.timeout||0,size:r.size||e.size||0});const s=new V(r.headers||e.headers||{});if(null!=n&&!s.has("Content-Type")){const e=z(n);e&&s.append("Content-Type",e)}let i=ne(e)?e.signal:null;if("signal"in r&&(i=r.signal),null!=i&&!function(e){const t=e&&"object"==typeof e&&Object.getPrototypeOf(e);return!(!t||"AbortSignal"!==t.constructor.name)}(i))throw new TypeError("Expected signal to be an instanceof AbortSignal");this[ee]={method:o,redirect:r.redirect||e.redirect||"follow",headers:s,parsedURL:t,signal:i},this.follow=void 0!==r.follow?r.follow:void 0!==e.follow?e.follow:20,this.compress=void 0!==r.compress?r.compress:void 0===e.compress||e.compress,this.counter=r.counter||e.counter||0,this.agent=r.agent||e.agent}get method(){return this[ee].method}get url(){return re(this[ee].parsedURL)}get headers(){return this[ee].headers}get redirect(){return this[ee].redirect}get signal(){return this[ee].signal}clone(){return new se(this)}}function ie(e){Error.call(this,e),this.type="aborted",this.message=e,Error.captureStackTrace(this,this.constructor)}C.mixIn(se.prototype),Object.defineProperty(se.prototype,Symbol.toStringTag,{value:"Request",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperties(se.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0}}),ie.prototype=Object.create(Error.prototype),ie.prototype.constructor=ie,ie.prototype.name="AbortError";const ae=i.default.PassThrough,ue=u.default.resolve;function ce(e,t){if(!ce.Promise)throw new Error("native promise missing, set fetch.Promise to your favorite alternative");return C.Promise=ce.Promise,new ce.Promise((function(r,o){const n=new se(e,t),s=function(e){const t=e[ee].parsedURL,r=new V(e[ee].headers);if(r.has("Accept")||r.set("Accept","*/*"),!t.protocol||!t.hostname)throw new TypeError("Only absolute URLs are supported");if(!/^https?:$/.test(t.protocol))throw new TypeError("Only HTTP(S) protocols are supported");if(e.signal&&e.body instanceof i.default.Readable&&!oe)throw new Error("Cancellation of streamed requests with AbortSignal is not supported in node < 8");let o=null;if(null==e.body&&/^(POST|PUT)$/i.test(e.method)&&(o="0"),null!=e.body){const t=G(e);"number"==typeof t&&(o=String(t))}o&&r.set("Content-Length",o),r.has("User-Agent")||r.set("User-Agent","node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"),e.compress&&!r.has("Accept-Encoding")&&r.set("Accept-Encoding","gzip,deflate");let n=e.agent;return"function"==typeof n&&(n=n(t)),r.has("Connection")||n||r.set("Connection","close"),Object.assign({},t,{method:e.method,headers:K(r),agent:n})}(n),u=("https:"===s.protocol?c.default:a.default).request,h=n.signal;let f=null;const d=function(){let e=new ie("The user aborted a request.");o(e),n.body&&n.body instanceof i.default.Readable&&n.body.destroy(e),f&&f.body&&f.body.emit("error",e)};if(h&&h.aborted)return void d();const p=function(){d(),b()},m=u(s);let y;function b(){m.abort(),h&&h.removeEventListener("abort",p),clearTimeout(y)}h&&h.addEventListener("abort",p),n.timeout&&m.once("socket",(function(e){y=setTimeout((function(){o(new $(`network timeout at: ${n.url}`,"request-timeout")),b()}),n.timeout)})),m.on("error",(function(e){o(new $(`request to ${n.url} failed, reason: ${e.message}`,"system",e)),b()})),m.on("response",(function(e){clearTimeout(y);const t=function(e){const t=new V;for(const r of Object.keys(e))if(!U.test(r))if(Array.isArray(e[r]))for(const o of e[r])H.test(o)||(void 0===t[F][r]?t[F][r]=[o]:t[F][r].push(o));else H.test(e[r])||(t[F][r]=[e[r]]);return t}(e.headers);if(ce.isRedirect(e.statusCode)){const s=t.get("Location"),i=null===s?null:ue(n.url,s);switch(n.redirect){case"error":return o(new $(`uri requested responds with a redirect, redirect mode is set to error: ${n.url}`,"no-redirect")),void b();case"manual":if(null!==i)try{t.set("Location",i)}catch(e){o(e)}break;case"follow":if(null===i)break;if(n.counter>=n.follow)return o(new $(`maximum redirect reached at: ${n.url}`,"max-redirect")),void b();const s={headers:new V(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!==e.statusCode&&n.body&&null===G(n)?(o(new $("Cannot follow redirect with body being a readable stream","unsupported-redirect")),void b()):(303!==e.statusCode&&(301!==e.statusCode&&302!==e.statusCode||"POST"!==n.method)||(s.method="GET",s.body=void 0,s.headers.delete("content-length")),r(ce(new se(i,s))),void b())}}e.once("end",(function(){h&&h.removeEventListener("abort",p)}));let s=e.pipe(new ae);const i={url:n.url,status:e.statusCode,statusText:e.statusMessage,headers:t,size:n.size,timeout:n.timeout,counter:n.counter},a=t.get("Content-Encoding");if(!n.compress||"HEAD"===n.method||null===a||204===e.statusCode||304===e.statusCode)return f=new X(s,i),void r(f);const u={flush:l.default.Z_SYNC_FLUSH,finishFlush:l.default.Z_SYNC_FLUSH};if("gzip"==a||"x-gzip"==a)return s=s.pipe(l.default.createGunzip(u)),f=new X(s,i),void r(f);if("deflate"!=a&&"x-deflate"!=a){if("br"==a&&"function"==typeof l.default.createBrotliDecompress)return s=s.pipe(l.default.createBrotliDecompress()),f=new X(s,i),void r(f);f=new X(s,i),r(f)}else{e.pipe(new ae).once("data",(function(e){s=8==(15&e[0])?s.pipe(l.default.createInflate()):s.pipe(l.default.createInflateRaw()),f=new X(s,i),r(f)}))}})),function(e,t){const r=t.body;null===r?e.end():k(r)?r.stream().pipe(e):Buffer.isBuffer(r)?(e.write(r),e.end()):r.pipe(e)}(m,n)}))}ce.isRedirect=function(e){return 301===e||302===e||303===e||307===e||308===e},ce.Promise=global.Promise;var le=O(Object.freeze({__proto__:null,default:ce,Headers:V,Request:se,Response:X,FetchError:$}));function he(e){return e&&e.default||e}var fe=T.fetch=T.fetch||("undefined"==typeof process?he(j):function(e,t){return he(le)(String(e).replace(/^\/\//g,"https://"),t)});class de extends Error{constructor({meta:e,errors:t}){super(),this.meta=e,this.errors=t}}class pe{constructor({token:e,basePath:t,apiVersion:o,debug:n}){this.request=({method:e,path:t,data:o,params:n,compress:s=!0})=>h(this,void 0,void 0,(function*(){var i;let a,u;const c=new r.URL(t,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(n){const e=Object.entries(n).sort().filter((e=>null!==e[0]));c.search=new r.URLSearchParams(e).toString()}o&&(a=JSON.stringify({data:Object.assign({},o)})),(null===(i=this.debug)||void 0===i?void 0:i.verbose)&&(console.info("Endpoint: ",c.href),console.info("Method: ",e),o&&console.info("Body Parameters: ",o),n&&console.info("Query Parameters: ",n));const h=yield fe(c.href,{method:e,headers:l,body:a,compress:s}),f=h.headers.get("content-type");if(u=f&&f.includes("json")?yield h.json():yield h.text(),!h.ok||"errors"in u&&u.errors)throw new de(u);return u})),this.token=e,this.basePath=t||"https://api.duffel.com",this.apiVersion=o||"beta",this.debug=n}paginatedRequest({path:e,params:t}){return d(this,arguments,(function*(){let r=yield f(this.request({method:"GET",path:e,params:t}));for(const e of r.data)yield yield f({data:e});for(;r.meta&&"after"in r.meta&&r.meta.after;){r=yield f(this.request({method:"GET",path:e,params:{limit:r.meta.limit,after:r.meta.after}}));for(const e of r.data)yield yield f({data:e})}}))}}class me extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/aircraft"}}class ye extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airlines"}}class be extends p{constructor(e){super(e),this.get=e=>h(this,void 0,void 0,(function*(){return this.request({method:"GET",path:`${this.path}/${e}`})})),this.list=e=>this.request({method:"GET",path:this.path,params:e}),this.listWithGenerator=()=>this.paginatedRequest({path:this.path}),this.path="air/airports"}}exports.Duffel=class{constructor(e){this.client=new pe(e),this.aircraft=new me(this.client),this.airlines=new ye(this.client),this.airports=new be(this.client),this.offerRequests=new m(this.client),this.offers=new y(this.client),this.orders=new g(this.client),this.orderCancellations=new b(this.client),this.payments=new v(this.client),this.seatMaps=new w(this.client)}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@duffel/api", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Javascript client library for the Duffel API", | ||
@@ -45,3 +45,3 @@ "main": "dist/index.js", | ||
"colors": "^1.4.0", | ||
"dotenv": "^9.0.1", | ||
"dotenv": "^10.0.0", | ||
"eslint": "^7.26.0", | ||
@@ -48,0 +48,0 @@ "eslint-plugin-spellcheck": "^0.0.17", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
416323
4