UNPKG

@apicart/store-sdk

Version:

Apicart SDK for integrating store into any web application

22 lines (19 loc) 59 kB
/** * Utils.js v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk"],e):(t=t||self).Apicart=e(t.Apicart)}(this,(function(t){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function e(t,e,r,n){return new(r||(r=Promise))((function(i,a){function o(t){try{u(n.next(t))}catch(t){a(t)}}function s(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,s)}u((n=n.apply(t,e||[])).next())}))}function r(t,e){var r,n,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var n=function(){function t(t){this._code=t}return t.prototype.getCode=function(){return this._code},t.prototype.setCode=function(t){this._code=t},t.CODE_ACTIVE="active",t.CODE_MERGED="merged",t.CODE_FINISHED="finished",t}(),i=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),a=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),o=function(){function e(e,r,n,i,a,o){var s=this;void 0===o&&(o=[]),this._parameters=[],this._externalId=e,this._name=r,this._price=n,this._taxRate=i,this._dataUrl=a,t.Utils.Loops.forEach(o,(function(t){s.addParameter(t)}))}return e.prototype.getExternalId=function(){return this._externalId},e.prototype.getName=function(){return this._name},e.prototype.getPrice=function(){return this._price},e.prototype.getTaxRate=function(){return this._taxRate},e.prototype.getDataUrl=function(){return this._dataUrl},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),void(r=!0)})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){t.getKey()===e&&delete r._parameters[n]}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){t.getKey()===e&&(n=t.getValue())})),n},e.prototype.serialize=function(){var e={externalId:this.getExternalId(),dataUrl:this.getDataUrl(),name:this.getName(),parameters:[],taxRate:this.getTaxRate(),price:this.getPrice()};return t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.prototype.serializeForGraphQL=function(){var t=this.serialize();return delete t.price,t},e.deserialize=function(r){t.Utils.Loops.forEach(["externalId","name","taxRate","dataUrl"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'Item: Missing required parameter: "'+e+'".'}));var n=new e(r.externalId,r.name,r.price,r.taxRate,r.dataUrl);return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new a(t.key,t.value||null))})),n},e}(),s=function(){function e(e,r,n,i){var a=this;void 0===i&&(i=[]),this._parameters=[],this._quantity=e,this._totalPrice=r,this._item=n,t.Utils.Loops.forEach(i,(function(t){a.addParameter(t)}))}return e.prototype.getQuantity=function(){return this._quantity},e.prototype.increaseQuantity=function(t){void 0===t&&(t=1),this._quantity+=t},e.prototype.decreaseQuantity=function(t){if(void 0===t&&(t=1),this.getQuantity()-t<=0)throw"Product quantity cannot be decreased to zero.";this._quantity-=t},e.prototype.getTotalPrice=function(){return this._totalPrice},e.prototype.getItem=function(){return this._item},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),void(r=!0)})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){t.getKey()===e&&delete r._parameters[n]}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){t.getKey()===e&&(n=t.getValue())})),n},e.prototype.getExternalId=function(){return this.getItem().getExternalId()},e.prototype.serialize=function(){var e={dataUrl:this.getItem().getDataUrl(),quantity:this.getQuantity(),parameters:[],totalPrice:this.getTotalPrice(),item:this.getItem().serialize()};return t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.prototype.serializeForGraphQL=function(){return this.serialize()},e.deserialize=function(r){t.Utils.Loops.forEach(["quantity","totalPrice","item"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'CartItem: Missing required parameter: "'+e+'".'}));var n=new e(r.quantity,r.totalPrice,o.deserialize(r.item));return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new i(t.key,t.value||null))})),n},e}(),u=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),c=function(){function t(t){this._code=t}return t.prototype.getCode=function(){return this._code},t.prototype.setCode=function(t){this._code=t},t.CODE_ACTIVE="active",t.CODE_DISABLE="disable",t}(),h=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),p=function(){function e(e,r,n,i,a){var o=this;void 0===a&&(a=[]),this._parameters=[],this._createdAt=e,this._updatedAt=r,this._hash=n,this.setCustomerState(i),t.Utils.Loops.forEach(a,(function(t){o.addParameter(t)}))}return e.prototype.getCreatedAt=function(){return this._createdAt},e.prototype.getUpdatedAt=function(){return this._updatedAt},e.prototype.getHash=function(){return this._hash},e.prototype.getCustomerState=function(){return this._customerState},e.prototype.setCustomerState=function(t){this._customerState=t},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){t.getKey()===e.getKey()&&(t.setValue(e.getValue()),r=!0)})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.prototype.getExternalId=function(){var t=this.getParameterValue("externalId");return["string","number"].includes(typeof t)||null===t||(t=null),t},e.prototype.serialize=function(){var e={createdAt:this.getCreatedAt(),updatedAt:this.getUpdatedAt(),hash:this.getHash(),state:{code:this.getCustomerState().getCode()},parameters:[]};return t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.prototype.serializeForGraphQL=function(){var t=this.serialize();return{hash:t.hash,state:t.state.code,parameters:t.parameters}},e.deserialize=function(r){t.Utils.Loops.forEach(["createdAt","updatedAt","hash","state"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'Customer: Missing required parameter: "'+e+'".'}));var n=new e(new Date(r.createdAt),new Date(r.updatedAt),r.hash,new c(r.state.code));return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new h(t.key,t.value||null))})),n},e}(),d=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),l=function(){function e(e,r,n,i,a,o,s,u,c,h){var p=this;void 0===c&&(c=null),void 0===h&&(h=[]),this._uid=null,this._enabled=!1,this._parameters=[],this._id=e,this._uid=c,this._name=r,this._description=n,this._image=i,this._type=a,this._price=o,this._sort=s,this._enabled=u,t.Utils.Loops.forEach(h,(function(t){p.addParameter(t)}))}return e.prototype.getId=function(){return this._id},e.prototype.getUid=function(){return this._uid},e.prototype.getName=function(){return this._name},e.prototype.getDescription=function(){return this._description},e.prototype.getImage=function(){return this._image},e.prototype.getType=function(){return this._type},e.prototype.getPrice=function(){return this._price},e.prototype.getSort=function(){return this._sort},e.prototype.isEnabled=function(){return this._enabled},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),r=!0,!1})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.prototype.serialize=function(){var e={id:this.getId(),uid:this.getUid(),name:this.getName(),description:this.getDescription(),image:this.getImage(),type:this.getType(),price:this.getPrice(),sort:this.getSort(),enabled:this.isEnabled(),parameters:[]};return t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.deserialize=function(r){t.Utils.Loops.forEach(["id","name","image","type","price","sort","enabled"],(function(t){if(!(t in r))throw'PaymentMethod: Missing required parameter: "'+t+'".'}));var n=new e(r.id,r.name,r.description,r.image,r.type,r.price,r.sort,r.enabled,r.uid);return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new d(t.key,t.value||null))})),n},e.TYPE_APICART_PAYMENT_ADYEN="apicart-payment-adyen",e.TYPE_APICART_PAYMENT_BRAINTREE="apicart-payment-braintree",e.TYPE_APICART_PAYMENT_PAY_U="apicart-payment-pay_u",e.TYPE_APICART_PAYMENT_STRIPE="apicart-payment-stripe",e.TYPE_BANK_TRANSFER="bank-transfer",e.TYPE_CASH="cash",e.TYPE_CASH_ON_DELIVERY="cash-on-delivery",e.TYPE_CUSTOM="custom",e}(),f=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),m=function(){function e(e,r,n,i,a,o,s,u,c){var h=this;void 0===u&&(u=null),void 0===c&&(c=[]),this._uid=null,this._enabled=!1,this._parameters=[],this._id=e,this._uid=u,this._name=r,this._description=n,this._image=i,this._price=a,this._sort=o,this._enabled=s,t.Utils.Loops.forEach(c,(function(t){h.addParameter(t)}))}return e.prototype.getId=function(){return this._id},e.prototype.getUid=function(){return this._uid},e.prototype.getName=function(){return this._name},e.prototype.getDescription=function(){return this._description},e.prototype.getImage=function(){return this._image},e.prototype.getPrice=function(){return this._price},e.prototype.getSort=function(){return this._sort},e.prototype.isEnabled=function(){return this._enabled},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),r=!0,!1})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.prototype.serialize=function(){var e={id:this.getId(),uid:this.getUid(),name:this.getName(),description:this.getDescription(),image:this.getImage(),price:this.getPrice(),sort:this.getSort(),enabled:this.isEnabled(),parameters:[]};return t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.deserialize=function(r){t.Utils.Loops.forEach(["id","name","image","price","sort","enabled"],(function(t){if(!(t in r))throw'ShippingMethod: Missing required parameter: "'+t+'".'}));var n=new e(r.id,r.name,r.description,r.image,r.price,r.sort,r.enabled,r.uid);return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new f(t.key,t.value||null))})),n},e}(),y=function(){function e(e,r,n,i,a,o,s,u,c,h){var p=this;void 0===s&&(s=null),void 0===u&&(u=null),void 0===c&&(c=[]),void 0===h&&(h=[]),this._items=[],this._parameters=[],this._shippingMethod=null,this._paymentMethod=null,this._createdAt=e,this._updatedAt=r,this._hash=n,this._totalPrice=i,this._paymentMethod=s,this._shippingMethod=u,this.setCartState(a),this.setCustomer(o),t.Utils.Loops.forEach(c,(function(t){p.addItem(t)})),t.Utils.Loops.forEach(h,(function(t){p.addParameter(t)}))}return e.prototype.getCreatedAt=function(){return this._createdAt},e.prototype.getUpdatedAt=function(){return this._updatedAt},e.prototype.getHash=function(){return this._hash},e.prototype.getTotalPrice=function(){return this._totalPrice},e.prototype.getCartState=function(){return this._cartState},e.prototype.setCartState=function(t){this._cartState=t},e.prototype.getCustomer=function(){return this._customer},e.prototype.setCustomer=function(t){this._customer=t},e.prototype.getItems=function(){return this._items},e.prototype.getTotalItemsQuantity=function(){var e=0;return t.Utils.Loops.forEach(this.getItems(),(function(t){e+=t.getQuantity()})),e},e.prototype.addItem=function(t){this._items.push(t)},e.prototype.removeItemByExternalId=function(e){var r=this;t.Utils.Loops.forEach(this.getItems(),(function(t,n){if(t.getExternalId()===e)return delete r._items[n],!1}))},e.prototype.removeItemByDataUrl=function(e){var r=this;t.Utils.Loops.forEach(this.getItems(),(function(t,n){if(t.getItem().getDataUrl()===e)return delete r._items[n],!1}))},e.prototype.findItemByExternalId=function(e){var r=null;return t.Utils.Loops.forEach(this.getItems(),(function(t){if(t.getItem().getExternalId()===e)return r=t,!1})),r},e.prototype.findItemByDataUrl=function(e){var r=null;return t.Utils.Loops.forEach(this.getItems(),(function(t){if(t.getItem().getDataUrl()===e)return r=t,!1})),r},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),r=!0,!1})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getPaymentMethod=function(){return this._paymentMethod},e.prototype.getShippingMethod=function(){return this._shippingMethod},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.prototype.getExternalId=function(){var t=this.getParameterValue("externalId");return["string","number"].includes(typeof t)||null===t||(t=null),t},e.prototype.serialize=function(){var e={createdAt:this.getCreatedAt(),updatedAt:this.getUpdatedAt(),hash:this.getHash(),totalPrice:this.getTotalPrice(),state:{code:this.getCartState().getCode()},customer:this.getCustomer().serialize(),items:[],parameters:[],paymentMethod:null,shippingMethod:null},r=this.getPaymentMethod(),n=this.getShippingMethod();return r&&(e.paymentMethod=r.serialize()),n&&(e.shippingMethod=n.serialize()),t.Utils.Loops.forEach(this.getItems(),(function(t){e.items.push(t.serialize())})),t.Utils.Loops.forEach(this.getParameters(),(function(t){e.parameters.push({key:t.getKey(),value:t.getValue()})})),e},e.prototype.serializeForGraphQL=function(){var t=this.serialize();return{hash:t.hash,state:t.state.code,customerHash:t.customer.hash,items:t.items,parameters:t.parameters}},e.deserialize=function(r){t.Utils.Loops.forEach(["createdAt","updatedAt","hash","totalPrice","state.code","customer.hash","customer.state"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'Cart: Missing required parameter: "'+e+'".'}));var i=new e(new Date(r.createdAt),new Date(r.updatedAt),r.hash,r.totalPrice,new n(r.state.code),p.deserialize(r.customer),r.paymentMethod?l.deserialize(r.paymentMethod):null,r.shippingMethod?m.deserialize(r.shippingMethod):null);return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&i.addParameter(new u(t.key,t.value||null))})),"items"in r&&Array.isArray(r.items)&&t.Utils.Loops.forEach(r.items,(function(t){i.addItem(s.deserialize(t))})),i},e}(),g=function(){function t(t){this._code=t}return t.prototype.getCode=function(){return this._code},t.prototype.setCode=function(t){this._code=t},t.CODE_NEW="new",t.CODE_WAITING_FOR_PAYMENT="waitingForPayment",t.CODE_PAID="paid",t.CODE_DISTRIBUTED="distributed",t.CODE_CANCELED="canceled",t}(),v=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),_=function(){function t(t,e){this._key=t,this._value=e}return t.prototype.getKey=function(){return this._key},t.prototype.getValue=function(){return this._value},t.prototype.setValue=function(t){this._value=t},t}(),P=function(){function e(e,r,n,i,a,o,s){var u=this;void 0===s&&(s=[]),this._parameters=[],this._quantity=e,this._externalId=r,this._name=n,this._price=i,this._totalPrice=a,this._item=o,t.Utils.Loops.forEach(s,(function(t){u.addParameter(t)}))}return e.prototype.getQuantity=function(){return this._quantity},e.prototype.getExternalId=function(){return this._externalId},e.prototype.getName=function(){return this._name},e.prototype.getPrice=function(){return this._price},e.prototype.getTotalPrice=function(){return this._totalPrice},e.prototype.getItem=function(){return this._item},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),r=!0,!1})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.deserialize=function(r){t.Utils.Loops.forEach(["quantity","externalId","name","price","totalPrice","item"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'Orderitem: Missing required parameter: "'+e+'".'}));var n=o.deserialize(r.item),i=new e(r.quantity,r.externalId,r.name,r.price,r.totalPrice,n);return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&i.addParameter(new _(t.key,t.value||null))})),i},e}(),E=function(){function e(e,r,n,i,a,o,s,u,c,h){var p=this;void 0===c&&(c=[]),void 0===h&&(h=[]),this._items=[],this._parameters=[],this._createdAt=e,this._updatedAt=r,this._hash=n,this._variableSymbol=i,this._totalPrice=a,this.setOrderState(o),this.setCart(s),this.setCustomer(u),t.Utils.Loops.forEach(c,(function(t){p.addItem(t)})),t.Utils.Loops.forEach(h,(function(t){p.addParameter(t)}))}return e.prototype.getCreatedAt=function(){return this._createdAt},e.prototype.getUpdatedAt=function(){return this._updatedAt},e.prototype.getHash=function(){return this._hash},e.prototype.getVariableSymbol=function(){return this._variableSymbol},e.prototype.getTotalPrice=function(){return this._totalPrice},e.prototype.getOrderState=function(){return this._orderState},e.prototype.setOrderState=function(t){this._orderState=t},e.prototype.getCart=function(){return this._cart},e.prototype.setCart=function(t){this._cart=t},e.prototype.getCustomer=function(){return this._customer},e.prototype.setCustomer=function(t){this._customer=t},e.prototype.getItems=function(){return this._items},e.prototype.addItem=function(t){this._items.push(t)},e.prototype.removeItemByExternalId=function(e){var r=this;t.Utils.Loops.forEach(this.getItems(),(function(t,n){if(t.getExternalId()===e)return delete r._items[n],!1}))},e.prototype.findItemByExternalId=function(e){var r=null;return t.Utils.Loops.forEach(this.getItems(),(function(t){if(t.getExternalId()===e)return r=t,!1})),r},e.prototype.getParameters=function(){return this._parameters},e.prototype.addParameter=function(e){var r=!1;t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e.getKey())return t.setValue(e.getValue()),r=!0,!1})),r||this._parameters.push(e)},e.prototype.removeParameter=function(e){var r=this;t.Utils.Loops.forEach(this.getParameters(),(function(t,n){if(t.getKey()===e)return delete r._parameters[n],!1}))},e.prototype.getParameterValue=function(e,r){void 0===r&&(r=null);var n=r;return t.Utils.Loops.forEach(this.getParameters(),(function(t){if(t.getKey()===e)return n=t.getValue(),!1})),n},e.prototype.getExternalId=function(){var t=this.getParameterValue("externalId");return["string","number"].includes(typeof t)||null===t||(t=null),t},e.deserialize=function(r){t.Utils.Loops.forEach(["createdAt","updatedAt","hash","variableSymbol","totalPrice","state.code","cart.hash","customer.hash","customer.state"],(function(e){if(!t.Utils.Objects.keyExists(r,e))throw'Order: Missing required parameter: "'+e+'".'}));var n=new e(new Date(r.createdAt),new Date(r.updatedAt),r.hash,r.variableSymbol,r.totalPrice,new g(r.state.code),y.deserialize(r.cart),p.deserialize(r.customer));return"parameters"in r&&Array.isArray(r.parameters)&&t.Utils.Loops.forEach(r.parameters,(function(t){"key"in t&&n.addParameter(new v(t.key,t.value||null))})),"items"in r&&Array.isArray(r.items)&&t.Utils.Loops.forEach(r.items,(function(t){n.addItem(P.deserialize(t))})),n},e}(),C=function(){function n(e,r){if(void 0===r&&(r={}),this._parameters={},!t.Utils.Objects.keyExists(r,"url"))throw'Parameter "dataSource.url" is missing.';this._token=e,this._parameters=r}return n.prototype.findCart=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findCart($input: FindCartQueryInput!){\n\t\t\t\tfindCart(input: $input) {\n\t\t\t\t\tcart {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findCart($input: FindCartQueryInput!){\n\t\t\t\tfindCart(input: $input) {\n\t\t\t\t\tcart {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"findCart.cart.all"))?y.deserialize(n):null]}}))}))},n.prototype.fullCartSynchronization=function(t){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation fullCartSynchronization($input: FullCartSynchronizationMutationInput!){\n\t\t\t\tfullCartSynchronization(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation fullCartSynchronization($input: FullCartSynchronizationMutationInput!){\n\t\t\t\tfullCartSynchronization(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",{input:{cart:t.serializeForGraphQL()}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"fullCartSynchronization")]}}))}))},n.prototype.addCartItem=function(n,i,a,o){return void 0===a&&(a=1),void 0===o&&(o=[]),e(this,void 0,void 0,(function(){var e,s;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation addCartItems($input: AddCartItemsMutationInput!){\n\t\t\t\taddCartItems(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",e={},t.Utils.Loops.forEach(o,(function(t){e[t.getKey()]=t.getValue()})),[4,this.call("\n\t\t\tmutation addCartItems($input: AddCartItemsMutationInput!){\n\t\t\t\taddCartItems(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:n,items:[{dataUrl:i,quantity:a,parameters:e}]}})];case 1:return s=r.sent(),[2,this.isSuccessResult(s,"addCartItems")]}}))}))},n.prototype.removeCartItem=function(t,n,i){return void 0===i&&(i=null),e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation removeCartItems($input: RemoveCartItemsMutationInput!){\n\t\t\t\tremoveCartItems(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation removeCartItems($input: RemoveCartItemsMutationInput!){\n\t\t\t\tremoveCartItems(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:t,items:[{dataUrl:n,quantity:i}]}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"removeCartItems")]}}))}))},n.prototype.addCartParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation addCartParameters($input: AddCartParametersMutationInput!){\n\t\t\t\taddCartParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation addCartParameters($input: AddCartParametersMutationInput!){\n\t\t\t\taddCartParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:t,parameters:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"addCartParameters")]}}))}))},n.prototype.removeCartParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation removeCartParameters($input: RemoveCartParametersMutationInput!){\n\t\t\t\tremoveCartParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation removeCartParameters($input: RemoveCartParametersMutationInput!){\n\t\t\t\tremoveCartParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:t,parameters:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"removeCartParameters")]}}))}))},n.prototype.finishCart=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation finishCart($input: FinishCartMutationInput!){\n\t\t\t\tfinishCart(input: $input) {\n\t\t\t\t\torder {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation finishCart($input: FinishCartMutationInput!){\n\t\t\t\tfinishCart(input: $input) {\n\t\t\t\t\torder {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{cartHash:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"finishCart.order.all"))?E.deserialize(n):null]}}))}))},n.prototype.findCustomer=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findCustomer($input: FindCustomerQueryInput!){\n\t\t\t\tfindCustomer(input: $input) {\n\t\t\t\t\tcustomer {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findCustomer($input: FindCustomerQueryInput!){\n\t\t\t\tfindCustomer(input: $input) {\n\t\t\t\t\tcustomer {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{customerHash:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"findCustomer.customer.all"))?p.deserialize(n):null]}}))}))},n.prototype.fullCustomerSynchronization=function(t){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation fullCustomerSynchronization($input: FullCustomerSynchronizationMutationInput!){\n\t\t\t\tfullCustomerSynchronization(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation fullCustomerSynchronization($input: FullCustomerSynchronizationMutationInput!){\n\t\t\t\tfullCustomerSynchronization(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",{input:{customer:t.serializeForGraphQL()}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"fullCustomerSynchronization")]}}))}))},n.prototype.addCustomerParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation addCustomerParameters($input: AddCustomerParametersMutationInput!){\n\t\t\t\taddCustomerParameters(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation addCustomerParameters($input: AddCustomerParametersMutationInput!){\n\t\t\t\taddCustomerParameters(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",{input:{customerHash:t,parameters:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"addCustomerParameters")]}}))}))},n.prototype.removeCustomerParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation removeCustomerParameters($input: RemoveCustomerParametersMutationInput!){\n\t\t\t\tremoveCustomerParameters(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation removeCustomerParameters($input: RemoveCustomerParametersMutationInput!){\n\t\t\t\tremoveCustomerParameters(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}",{input:{customerHash:t,parameters:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"removeCustomerParameters")]}}))}))},n.prototype.findOrder=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findOrder($input: FindOrderQueryInput!){\n\t\t\t\tfindOrder(input: $input) {\n\t\t\t\t\torder {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findOrder($input: FindOrderQueryInput!){\n\t\t\t\tfindOrder(input: $input) {\n\t\t\t\t\torder {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{orderHash:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"findOrder.order.all"))?E.deserialize(n):null]}}))}))},n.prototype.changeOrderState=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation changeOrderState($input: ChangeOrderStateMutationInput!){\n\t\t\t\tchangeOrderState(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}\n\t\t",[4,this.call("\n\t\t\tmutation changeOrderState($input: ChangeOrderStateMutationInput!){\n\t\t\t\tchangeOrderState(input: $input) {\n\t\t\t\t\tresult\n\t\t\t\t}\n\t\t\t}\n\t\t",{input:{orderHash:t,orderStateCode:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"changeOrderState")]}}))}))},n.prototype.addOrderParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation addOrderParameters($input: AddOrderParametersMutationInput!){\n\t\t\t\taddOrderParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation addOrderParameters($input: AddOrderParametersMutationInput!){\n\t\t\t\taddOrderParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{orderHash:t,orderStateCode:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"addOrderParameters")]}}))}))},n.prototype.removeOrderParameters=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tmutation removeOrderParameters($input: RemoveOrderParametersMutationInput!){\n\t\t\t\tremoveOrderParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tmutation removeOrderParameters($input: RemoveOrderParametersMutationInput!){\n\t\t\t\tremoveOrderParameters(input: $input) {\n\t\t\t\t\tmessage, result\n\t\t\t\t}\n\t\t\t}",{input:{orderHash:t,orderStateCode:n}})];case 1:return e=r.sent(),[2,this.isSuccessResult(e,"removeOrderParameters")]}}))}))},n.prototype.findPaymentMethod=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findPaymentMethods($input: FindPaymentMethodsQueryInput!){\n\t\t\t\tfindPaymentMethods(input: $input) {\n\t\t\t\t\tpaymentMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findPaymentMethods($input: FindPaymentMethodsQueryInput!){\n\t\t\t\tfindPaymentMethods(input: $input) {\n\t\t\t\t\tpaymentMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{id:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"findPaymentMethods.paymentMethods.0"))?l.deserialize(n):null]}}))}))},n.prototype.findPaymentMethods=function(n){return e(this,void 0,void 0,(function(){var e,i,a;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findPaymentMethods($input: FindPaymentMethodsQueryInput!){\n\t\t\t\tfindPaymentMethods(input: $input) {\n\t\t\t\t\tpaymentMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findPaymentMethods($input: FindPaymentMethodsQueryInput!){\n\t\t\t\tfindPaymentMethods(input: $input) {\n\t\t\t\t\tpaymentMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{onlyEnabled:n}})];case 1:return e=r.sent(),(i=this.getResponseData(e,"findPaymentMethods.paymentMethods"))?(a=[],t.Utils.Loops.forEach(i,(function(t){a.push(l.deserialize(t.all))})),[2,a]):[2,null]}}))}))},n.prototype.findShippingMethod=function(t){return e(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findShippingMethods($input: FindShippingMethodsQueryInput!){\n\t\t\t\tfindShippingMethods(input: $input) {\n\t\t\t\t\tshippingMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findShippingMethods($input: FindShippingMethodsQueryInput!){\n\t\t\t\tfindShippingMethods(input: $input) {\n\t\t\t\t\tshippingMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{id:t}})];case 1:return e=r.sent(),[2,(n=this.getResponseData(e,"findShippingMethods.shippingMethods.all"))?m.deserialize(n):null]}}))}))},n.prototype.findShippingMethods=function(n){return e(this,void 0,void 0,(function(){var e,i,a;return r(this,(function(r){switch(r.label){case 0:return"\n\t\t\tquery findShippingMethods($input: FindShippingMethodsQueryInput!){\n\t\t\t\tfindShippingMethods(input: $input) {\n\t\t\t\t\tshippingMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",[4,this.call("\n\t\t\tquery findShippingMethods($input: FindShippingMethodsQueryInput!){\n\t\t\t\tfindShippingMethods(input: $input) {\n\t\t\t\t\tshippingMethods {\n\t\t\t\t\t\tall\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}",{input:{onlyEnabled:n}})];case 1:return e=r.sent(),(i=this.getResponseData(e,"findShippingMethods.shippingMethods"))?(a=[],t.Utils.Loops.forEach(i,(function(t){a.push(m.deserialize(t.all))})),[2,a]):[2,null]}}))}))},n.prototype.call=function(e,r){return r.input.token=this._token,t.ApiCommunicator.call(this._parameters.url,e,r,this._parameters.connectTimeout,this._parameters.withCredentials)},n.prototype.getResponseData=function(e,r){return t.Utils.Objects.find(e,"data.data."+r)},n.prototype.isSuccessResult=function(e,r,n){return void 0===e&&(e=null),void 0===n&&(n=!0),t.ApiCommunicator.isSuccessResult(e,r,n)},n}(),I=function(){function t(){}return t.HASH_CHANGED="apicart:customer:hash-changed",t.PARAMETER_ADDED="apicart:customer:parameter-added",t.PARAMETER_REMOVED="apicart:customer:parameter-removed",t.MERGED="apicart:customer:merged",t.SYNCHRONIZED="apicart:customer:synchronized",t.UPDATED="apicart:customer:updated",t}(),S=function(){function n(t,e){void 0===e&&(e=null),this._customer=null,this._customerPromise=null,this._dataSource=t,this._hash=e}return n.prototype.getEntity=function(n){return void 0===n&&(n=!1),e(this,void 0,void 0,(function(){var e,i=this;return r(this,(function(r){switch(r.label){case 0:return this._customerPromise||null!==this._customer&&!n?[3,2]:(e=this._customer,this._customerPromise=this.callDataSource((function(){return i._dataSource.findCustomer(i.getHash())})),[4,this._customerPromise]);case 1:e=r.sent(),this._customerPromise=null,null===e&&this.getHash()?t.Utils.Console.error('Customer entity with hash "'+this.getHash()+'" not found.'):(this._customer=e,this._hash=e.getHash(),t.Utils.EventDispatcher.dispatchEvent(I.UPDATED,this)),r.label=2;case 2:return this._customerPromise?[4,this._customerPromise]:[3,4];case 3:r.sent(),this._customerPromise=null,r.label=4;case 4:return[2,this._customer]}}))}))},n.prototype.getHash=function(){return this._hash},n.prototype.getCreatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getCreatedAt()]}}))}))},n.prototype.getUpdatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getUpdatedAt()]}}))}))},n.prototype.addParameter=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){return(e={})[t]=n,[2,this.addParameters(e)]}))}))},n.prototype.addParameters=function(n){return e(this,void 0,void 0,(function(){var e,i=this;return r(this,(function(r){return e=this.callDataSource((function(){return i._dataSource.addCustomerParameters(i.getHash(),n)}),!0),t.Utils.EventDispatcher.dispatchEvent(I,n),[2,e]}))}))},n.prototype.removeParameter=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,this.removeParameters([t])]}))}))},n.prototype.removeParameters=function(t){return e(this,void 0,void 0,(function(){var e=this;return r(this,(function(r){return[2,this.callDataSource((function(){return e._dataSource.removeCustomerParameters(e.getHash(),t)}),!0)]}))}))},n.prototype.getParameters=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getParameters()]}}))}))},n.prototype.getParameterValue=function(t,n){return void 0===n&&(n=null),e(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return[2,e.sent().getParameterValue(t,n)]}}))}))},n.prototype.callDataSource=function(t,n){return void 0===n&&(n=!1),e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return[4,t.call(this)];case 1:return e=r.sent(),n?[4,this.getEntity(!0)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2,e]}}))}))},n}(),b=function(){function n(t,e){this._order=null,this._orderPromise=null,this._dataSource=t,this._hash=e}return n.prototype.getEntity=function(){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return this._orderPromise||null!==this._order?[3,2]:(this._orderPromise=this._dataSource.findOrder(this.getHash()),[4,this._orderPromise]);case 1:null===(e=r.sent())?t.Utils.Console.error('Order entity with hash "'+this.getHash()+'" not found.'):this._order=e,r.label=2;case 2:return this._orderPromise?[4,this._orderPromise]:[3,4];case 3:r.sent(),this._orderPromise=null,r.label=4;case 4:return[2,this._order]}}))}))},n.prototype.getHash=function(){return this._hash},n.prototype.getCreatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getCreatedAt()]}}))}))},n.prototype.getUpdatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getUpdatedAt()]}}))}))},n.prototype.getVariableSymbol=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getVariableSymbol()]}}))}))},n.prototype.getTotalPrice=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getTotalPrice()]}}))}))},n.prototype.getOrderState=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getOrderState()]}}))}))},n.prototype.getCart=function(){return e(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return t=e.sent().getCart(),[2,new U(this._dataSource,t.getHash())]}}))}))},n.prototype.getCustomer=function(){return e(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return t=e.sent().getCustomer(),[2,new S(this._dataSource,t.getHash())]}}))}))},n.prototype.getItems=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getItems()]}}))}))},n.prototype.addParameter=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){return(e={})[t]=n,[2,this.addParameters([e])]}))}))},n.prototype.addParameters=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){return this.clearCachedEntity(),[2,this._dataSource.addOrderParameters(this.getHash(),t)]}))}))},n.prototype.removeParameter=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,this.removeParameters([t])]}))}))},n.prototype.removeParameters=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){return this.clearCachedEntity(),[2,this._dataSource.removeOrderParameters(this.getHash(),t)]}))}))},n.prototype.getParameters=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getParameters()]}}))}))},n.prototype.getParameterValue=function(t,n){return void 0===n&&(n=null),e(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return[2,e.sent().getParameterValue(t,n)]}}))}))},n.prototype.changeState=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){return this.clearCachedEntity(),[2,this._dataSource.changeOrderState(this.getHash(),t)]}))}))},n.prototype.clearCachedEntity=function(){this._order=null},n}(),M=function(){function t(){}return t.ITEM_ADDED="apicart:cart:item:added",t.ITEM_UPDATED="apicart:cart:item:updated",t.ITEM_REMOVED="apicart:cart:item:removed",t.ITEM_QUANTITY_INCREASED="apicart:cart:item:quantity:increased",t.ITEM_QUANTITY_DECREASED="apicart:cart:item:quantity:decreased",t.PARAMETER_ADDED="apicart:cart:parameter:added",t.PARAMETER_REMOVED="apicart:cart:parameter:removed",t.MERGED="apicart:cart:merged",t.SYNCHRONIZED="apicart:cart:synchronized",t.UPDATED="apicart:cart:updated",t.FINISHED="apicart:cart:finished",t}(),U=function(){function n(t,e){void 0===e&&(e=null),this._hash=null,this._cart=null,this._cartPromise=null,this._dataSource=t,this._hash=e}return n.prototype.getEntity=function(n){return void 0===n&&(n=!1),e(this,void 0,void 0,(function(){var e,i=this;return r(this,(function(r){switch(r.label){case 0:return this._cartPromise||null!==this._cart&&!n?[3,2]:(e=this._cart,this._cartPromise=this.callDataSource((function(){return i._dataSource.findCart(i.getHash())})),[4,this._cartPromise]);case 1:null===(e=r.sent())&&this.getHash()?t.Utils.Console.error('Cart entity with hash "'+this.getHash()+'" not found.'):(this._cart=e,this._hash=e.getHash(),t.Utils.EventDispatcher.dispatchEvent(M.UPDATED,this)),r.label=2;case 2:return this._cartPromise?[4,this._cartPromise]:[3,4];case 3:r.sent(),this._cartPromise=null,r.label=4;case 4:return[2,this._cart]}}))}))},n.prototype.getHash=function(){return this._hash},n.prototype.getCreatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getCreatedAt()]}}))}))},n.prototype.getUpdatedAt=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getUpdatedAt()]}}))}))},n.prototype.getTotalPrice=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getTotalPrice()]}}))}))},n.prototype.getCartState=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getCartState()]}}))}))},n.prototype.getCustomer=function(){return e(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return t=e.sent().getCustomer().getHash(),[2,new S(this._dataSource,t)]}}))}))},n.prototype.finish=function(){return e(this,void 0,void 0,(function(){var n,i=this;return r(this,(function(a){switch(a.label){case 0:return[4,this.callDataSource((function(){return e(i,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this._dataSource.finishCart(this.getHash())];case 1:return[2,null===(t=e.sent())?null:new b(this._dataSource,t.getHash())]}}))}))}))];case 1:return n=a.sent(),t.Utils.EventDispatcher.dispatchEvent(M.FINISHED,n),[2,n]}}))}))},n.prototype.addItem=function(n,a,o){return void 0===a&&(a=1),void 0===o&&(o={}),e(this,void 0,void 0,(function(){var s,u,c,h,p,d=this;return r(this,(function(l){switch(l.label){case 0:return s=[],t.Utils.Loops.forEach(o,(function(t,e){t instanceof i?s.push(t):s.push(new i(e,t))})),[4,this.findItemByDataUrl(n)];case 1:return u=l.sent(),[4,this.callDataSource((function(){return e(d,void 0,void 0,(function(){return r(this,(function(t){return[2,this._dataSource.addCartItem(this.getHash(),n,a,s)]}))}))}),!0)];case 2:return c=l.sent(),[4,this.findItemByDataUrl(n)];case 3:return h=l.sent(),p=[u?M.ITEM_UPDATED:M.ITEM_ADDED],u&&p.push(u.getQuantity>h.getQuantity?M.ITEM_QUANTITY_DECREASED:M.ITEM_QUANTITY_INCREASED),t.Utils.EventDispatcher.dispatchEvent(p,h),[2,c]}}))}))},n.prototype.removeItem=function(n,i){return void 0===i&&(i=null),e(this,void 0,void 0,(function(){var e,a,o,s=this;return r(this,(function(r){switch(r.label){case 0:return[4,this.callDataSource((function(){return s._dataSource.removeCartItem(s.getHash(),n,i)}),!0)];case 1:return e=r.sent(),[4,this.findItemByDataUrl(n)];case 2:return a=r.sent(),o=Boolean(a),t.Utils.EventDispatcher.dispatchEvent(o?M.ITEM_UPDATED:M.ITEM_REMOVED,a),[2,e]}}))}))},n.prototype.findItemByDataUrl=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.getEntity()];case 1:return[2,e.sent().findItemByDataUrl(t)]}}))}))},n.prototype.getItems=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.getEntity()];case 1:return[2,t.sent().getItems()]}}))}))},n.prototype.addParameter=function(t,n){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){return(e={})[t]=n,[2,this.addParameters(e)]}))}))},n.prototype.addParameters=function(n){return e(this,void 0,void 0,(function(){var e,i=this;return r(this,(function(r){switch(r