@aurigma/ui-framework
Version:
A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.
1 lines • 9.82 kB
JavaScript
(window.multistep_editor_jsonpFunction=window.multistep_editor_jsonpFunction||[]).push([[14],{896:function(e,t,r){"use strict";r.r(t),r.d(t,"AuWidgetAjax",(function(){return i})),r.d(t,"widget",(function(){return i}));var n=r(0),s=r(2),o=(r(201),r(37)),c=r(1),i=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._isRestoring=!1,t._isLoaded=!1,t.enabled=!0,t.headers={},t.method="POST",t.responses=[],t.error=null,t.statusCode=null,t.responseHeaders=null,t.responseType="json",t.requestPromise=Promise.resolve(),t._requestPending=!1,t._lockList=[],t._fetchTimer=null,t._fetchDelay=50,t._currentAbortController=null,t}return Object(n.d)(t,e),t.prototype.requestPendingObserver=function(e){this.showPreloader(e)},t.prototype._doFetch=function(e){return Object(n.b)(this,void 0,void 0,(function(){var t,r,s=this;return Object(n.e)(this,(function(o){return c.a.isNotNullOrUndefined(this.requests)&&c.a.isNotEmptyArray(this.requests)?(t=this.requests.map((function(e){var t={enabled:void 0===e.enabled||e.enabled,_onSuccess:e.onSuccess?c.a.functionWrapperConstructor(e.onSuccess):s._onSuccess,_onError:e.onSuccess?c.a.functionWrapperConstructor(e.onError):s._onError,headers:e.headers?e.headers:s.headers,request:e.request?e.request:s.request,responseType:e.responseType?e.responseType:s.responseType,method:e.method?e.method:s.method,url:e.url?e.url:s.url};return s._createFetch(t)})),Promise.all(t).then((function(t){return Object(n.b)(s,void 0,void 0,(function(){return Object(n.e)(this,(function(r){return this._fetchTimer=null,c.a.isNullableArray(t)||(this.responses=t,this.emitChange({responses:this.responses},!1)),e(t),[2]}))}))}))):(r={enabled:this.enabled,_onSuccess:this._onSuccess,_onError:this._onError,headers:this.headers,request:this.request,responseType:this.responseType,method:this.method,url:this.url},this._createFetch(r).then((function(t){return Object(n.b)(s,void 0,void 0,(function(){return Object(n.e)(this,(function(r){return this._fetchTimer=null,t&&(this.response=t,this.emitChange({response:this.response},!1)),e(t),[2]}))}))}))),[2]}))}))},t.prototype._createFetch=function(e){return Object(n.b)(this,void 0,void 0,(function(){var t,r,s,o,i,u=this;return Object(n.e)(this,(function(a){if(c.a.isNotUndefined(e.url)){if(!1===e.enabled)return[2,Promise.resolve(null)];this._requestPending=!0,t={method:e.method,redirect:"follow"},c.a.isObjectNotEmpty(e.request)&&(t.body=JSON.stringify(e.request)),-1!==["get","head"].indexOf(t.method.toLowerCase())&&delete t.body,(c.a.isObjectNotEmpty(e.headers)||t.body)&&(t.headers=new Headers(Object.assign(t.body?{"Content-type":"application/json"}:{},e.headers||{}))),r=new Request(e.url,t),this._currentAbortController=new AbortController,s=function(e){return u.statusCode=e.status,u.emitChange({statusCode:u.statusCode},!1),e},o=function(t){return Object(n.b)(u,void 0,void 0,(function(){var r,s,o;return Object(n.e)(this,(function(n){switch(n.label){case 0:return t.ok?[2,t]:[4,t.text()];case 1:r=n.sent();try{s=JSON.parse(r),o={body:s,headers:t.headers,statusCode:t.status},e._onError(o)}catch(c){e._onError()}throw Error("[".concat(t.status,",").concat(t.statusText,"] : ").concat(r))}}))}))},i=function(e){return Object(n.b)(u,void 0,void 0,(function(){return Object(n.e)(this,(function(n){switch(n.label){case 0:return e.redirected?(r=new Request(e.url,t),[4,fetch(r,{signal:this._currentAbortController.signal})]):[3,2];case 1:e=n.sent(),n.label=2;case 2:return[2,e]}}))}))},e._currentFetch=fetch(r,{signal:this._currentAbortController.signal}).then(i).then(s).then(o).then((function(t){return Object(n.b)(u,void 0,void 0,(function(){var r,s,o,c,i,u;return Object(n.e)(this,(function(n){switch(n.label){case 0:switch(this.statusCode=t.status,this.responseHeaders=t.headers,this.emitChange({responseHeaders:this.responseHeaders},!1),e.responseType){case"text":return[3,1];case"status_code":return[3,2];case"blob":return[3,3];case"json":return[3,4];case"blob_url":return[3,8]}return[3,9];case 1:return[2,t.text().then((function(e){return e.replace(/^"/g,"").replace(/\"$/g,"")}))];case 2:return[2,t.status];case 3:return[2,t.blob()];case 4:return n.trys.push([4,6,,8]),[4,t.clone().json()];case 5:return[2,n.sent()];case 6:return r=n.sent(),o=Error,c="\n[request url: ".concat(t.url,", request status code: ").concat(t.status,"] \n"),u=(i="unexpected error: ".concat(r," \nresponse body: \n")).concat,[4,t.clone().text()];case 7:return s=o.apply(void 0,[c+u.apply(i,[n.sent(),"\n"])]),[2,Promise.reject(s)];case 8:return[2,t.blob().then((function(e){return URL.createObjectURL(e)}))];case 9:return[2,t.text()]}}))}))})).then((function(t){return e.error=null,e.response=t,u.response=t,e._onSuccess(),e.response})).catch((function(t){"AbortError"===t.name||(e.error=t,u.error=t,e._onError(),console.error(t))})).finally((function(){u._requestPending=!1}))}return[2,e._currentFetch||Promise.resolve(null)]}))}))},t.prototype.updateParams=function(e){if(!c.a.isEmptyString(e.url)&&e.url.toLowerCase().startsWith("http")){var t=o.Maybe.maybe(e);this.enabled=t.bind((function(e){return c.a.maybeGet((function(){return e.enabled}))})).valueOr(this.enabled),this.headers=t.bind((function(e){return c.a.maybeGet((function(){return e.headers}))})).valueOr(this.headers),this.request=t.bind((function(e){return c.a.maybeGet((function(){return e.request}))})).valueOr(this.request),this.requests=t.bind((function(e){return c.a.maybeGet((function(){return e.requests}))})).valueOr(this.requests),this.responseType=t.bind((function(e){return c.a.maybeGet((function(){return e.responseType}))})).valueOr(this.responseType),this.method=t.bind((function(e){return c.a.maybeGet((function(){return e.method}))})).valueOr(this.method),this.url=t.bind((function(e){return c.a.maybeGet((function(){return e.url}))})).valueOr(this.url),this.responses=[],this._onSuccess=c.a.functionWrapperConstructor(e.onSuccess),this._onError=c.a.functionWrapperConstructor(e.onError)}},t.prototype.updateParamsAsync=function(t){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(r){switch(r.label){case 0:return[4,e.prototype.updateParamsAsync.call(this,t)];case 1:return r.sent(),this._lockList=o.Maybe.maybe(t).bind((function(e){return c.a.maybeGet((function(){return e.lock}))})).map((function(e){return c.a.ensureArray(e)})).valueOr(this._lockList),this._isLoaded||(this.getInitialParamsResolved(),this._isLoaded=!0),[2,this._doFetchDebounce()]}}))}))},t.prototype.exportWidgetData=function(e){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(e){return[2,{response:this.response,responses:this.responses,headers:this.headers,status:this.statusCode}]}))}))},t.prototype.restoreWidgetFromData=function(e,t){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(t){switch(t.label){case 0:return e?(this.response=e.response,this.responses=e.responses,this.headers=e.headers,this.statusCode=e.status,[4,this.emitChange({response:this.response,responses:this.responses,headers:this.headers,statusCode:this.statusCode},!1)]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.showPreloader=function(e){var t=this;(this._lockList||[]).forEach((function(r){var n="main"===r?t.auWizard:t.auWizard.scope.$[r]||t.jsonParamsFetcher.scope[r]||t.jsonParamsFetcher.scope.$[r];n&&n.showPreloader(e)}))},t.prototype._doFetchDebounce=function(){var e=this,t=null;this.requestPromise=new Promise((function(e){t=e}));var r=new Promise((function(t){null!==e._fetchTimer&&(window.clearTimeout(e._fetchTimer),e._currentAbortController&&e._currentAbortController.abort()),e._fetchTimer=window.setTimeout((function(){return Object(n.b)(e,void 0,void 0,(function(){return Object(n.e)(this,(function(e){switch(e.label){case 0:return[4,this._doFetch(t)];case 1:return e.sent(),[2]}}))}))}),e._fetchDelay)}));return r.then((function(){setTimeout((function(){setTimeout((function(){setTimeout((function(){setTimeout((function(){setTimeout((function(){t()}),100)}),100)}),100)}),100)}),100)})),r},Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Object)],t.prototype,"request",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Boolean)],t.prototype,"enabled",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Array)],t.prototype,"requests",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Object)],t.prototype,"headers",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",String)],t.prototype,"method",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",String)],t.prototype,"url",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Object)],t.prototype,"response",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Object)],t.prototype,"responses",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Object)],t.prototype,"error",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Number)],t.prototype,"statusCode",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Headers)],t.prototype,"responseHeaders",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",String)],t.prototype,"responseType",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Promise)],t.prototype,"requestPromise",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Boolean)],t.prototype,"_requestPending",void 0),Object(n.c)([Object(s.b)("_requestPending"),Object(n.g)("design:type",Function),Object(n.g)("design:paramtypes",[Object]),Object(n.g)("design:returntype",void 0)],t.prototype,"requestPendingObserver",null),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Function)],t.prototype,"_onSuccess",void 0),Object(n.c)([Object(s.c)(),Object(n.g)("design:type",Function)],t.prototype,"_onError",void 0),Object(n.c)([Object(s.a)("au-widget-ajax")],t)}(r(160).a)}}]);