1 line
3.7 KiB
JavaScript
1 line
3.7 KiB
JavaScript
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("qs"),require("ramda"),require("sprintf-js"),require("axios"),require("loglevel")):"function"==typeof define&&define.amd?define([,,,,],r):"object"==typeof exports?exports.lib=r(require("qs"),require("ramda"),require("sprintf-js"),require("axios"),require("loglevel")):(e.lib=e.lib||{},e.lib.api=r(e[void 0],e[void 0],e[void 0],e[void 0],e[void 0]))}(this,(function(e,r,t,n,o){return function(){"use strict";var i={996:function(e,r,t){var n=t(740);const o=t.n(n)().getLogger("default");o.setLevel("production"===process.env.NODE_ENV?"WARN":"DEBUG"),r.default=o},58:function(e){e.exports=n},740:function(e){e.exports=o},892:function(r){r.exports=e},757:function(e){e.exports=r},780:function(e){e.exports=t}},u={};function a(e){var r=u[e];if(void 0!==r)return r.exports;var t=u[e]={exports:{}};return i[e](t,t.exports,a),t.exports}a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,{a:r}),r},a.d=function(e,r){for(var t in r)a.o(r,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};return function(){var e;a.r(s),a.d(s,{ApiMethodFactory:function(){return y},HttpMethod:function(){return r}}),function(e){e.GET="GET",e.POST="POST",e.PUT="PUT",e.PATCH="PATCH",e.DELETE="DELETE"}(e||(e={}));var r=e,t=a(892),n=a.n(t),o=a(757),i=a(780),u=a(58),d=a.n(u),c=a(996);function l(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}class f extends Error{constructor(e){var r,t,n,o;super(e.message),l(this,"errorCode",void 0),l(this,"errorMessage",void 0),this.errorCode=(null==e||null===(r=e.response)||void 0===r||null===(t=r.data)||void 0===t?void 0:t.errorCode)??-1,this.errorMessage=null==e||null===(n=e.response)||void 0===n||null===(o=n.data)||void 0===o?void 0:o.errorMessage}}const p=async function(e){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{const{data:r}=await d()(e);return r}catch(t){if(null!=t&&t.hasAuthenticated&&!r)return p(e,!0);throw new f(t)}};var v=function(e){let{throwOnError:r=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return c.default.debug(e,`throwOnError: ${r}`),p(e)};function h(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var y=class{constructor(e){var t=this;let{apiPrefix:u}=e;h(this,"apiPrefix",void 0),h(this,"makePath",((e,r)=>t=>{const n=`${this.apiPrefix}${t}`;if(o.isEmpty(r))return n;const u=o.pick(r,e);if(o.isEmpty(u))throw Error("api: empty path data");return(0,i.sprintf)(n,u)})),h(this,"makeEndpoint",((e,r,t,n)=>o.compose(this.addQuery(r,n),this.makePath(r,t))(e))),h(this,"addQuery",((e,r)=>t=>{if(o.isEmpty(r))return t;const i=o.pick(r,e);if(o.isEmpty(i))throw Error("api: empty query data");return`${t}?${n().stringify(i)}`})),h(this,"make",(function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r.GET,{path:i=[],query:u=[],isFormData:a=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return async function(){let r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const d=e=>{if(o.isNil(e)||e instanceof FormData)return e;const r=o.pipe(o.omit(o.concat(i,u)),o.when(o.isEmpty,o.always(null)))(e);if(a){const r=new FormData;return o.forEachObjIndexed(((e,t)=>r.append(t,e)),e),r}return r},c=d(r),l=t.makeEndpoint(e,r,i,u);return await v({method:n,url:l,data:c,headers:s})}})),this.apiPrefix=u}}}(),s}()})); |