@danidoble/webserial 4.2.1 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/webserial.js +321 -312
- package/dist/webserial.umd.cjs +3 -2
- package/package.json +1 -1
package/dist/webserial.umd.cjs
CHANGED
|
@@ -32,7 +32,7 @@ version: 2.9.0
|
|
|
32
32
|
`+s.map(er).join(`
|
|
33
33
|
`):" "+er(s[0]):"as no adapter specified";throw new A("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return e},adapters:mn};function wn(r){if(r.cancelToken&&r.cancelToken.throwIfRequested(),r.signal&&r.signal.aborted)throw new Xt(null,r)}function ir(r){return wn(r),r.headers=at.from(r.headers),r.data=yn.call(r,r.transformRequest),["post","put","patch"].indexOf(r.method)!==-1&&r.headers.setContentType("application/x-www-form-urlencoded",!1),nr.getAdapter(r.adapter||ae.adapter)(r).then(function(e){return wn(r),e.data=yn.call(r,r.transformResponse,e),e.headers=at.from(e.headers),e},function(e){return Ki(e)||(wn(r),e&&e.response&&(e.response.data=yn.call(r,r.transformResponse,e.response),e.response.headers=at.from(e.response.headers))),Promise.reject(e)})}const rr="1.8.4",Be={};["object","boolean","number","function","string","symbol"].forEach((r,n)=>{Be[r]=function(e){return typeof e===r||"a"+(n<1?"n ":" ")+r}});const sr={};Be.transitional=function(n,t,e){function i(s,a){return"[Axios v"+rr+"] Transitional option '"+s+"'"+a+(e?". "+e:"")}return(s,a,c)=>{if(n===!1)throw new A(i(a," has been removed"+(t?" in "+t:"")),A.ERR_DEPRECATED);return t&&!sr[a]&&(sr[a]=!0,console.warn(i(a," has been deprecated since v"+t+" and will be removed in the near future"))),n?n(s,a,c):!0}},Be.spelling=function(n){return(t,e)=>(console.warn(`${e} is likely a misspelling of ${n}`),!0)};function kc(r,n,t){if(typeof r!="object")throw new A("options must be an object",A.ERR_BAD_OPTION_VALUE);const e=Object.keys(r);let i=e.length;for(;i-- >0;){const s=e[i],a=n[s];if(a){const c=r[s],l=c===void 0||a(c,s,r);if(l!==!0)throw new A("option "+s+" must be "+l,A.ERR_BAD_OPTION_VALUE);continue}if(t!==!0)throw new A("Unknown option "+s,A.ERR_BAD_OPTION)}}const Me={assertOptions:kc,validators:Be},Pt=Me.validators;let Ft=class{constructor(n){this.defaults=n,this.interceptors={request:new Vi,response:new Vi}}async request(n,t){try{return await this._request(n,t)}catch(e){if(e instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{e.stack?s&&!String(e.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(e.stack+=`
|
|
34
34
|
`+s):e.stack=s}catch{}}throw e}}_request(n,t){typeof n=="string"?(t=t||{},t.url=n):t=n||{},t=Mt(this.defaults,t);const{transitional:e,paramsSerializer:i,headers:s}=t;e!==void 0&&Me.assertOptions(e,{silentJSONParsing:Pt.transitional(Pt.boolean),forcedJSONParsing:Pt.transitional(Pt.boolean),clarifyTimeoutError:Pt.transitional(Pt.boolean)},!1),i!=null&&(y.isFunction(i)?t.paramsSerializer={serialize:i}:Me.assertOptions(i,{encode:Pt.function,serialize:Pt.function},!0)),t.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?t.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:t.allowAbsoluteUrls=!0),Me.assertOptions(t,{baseUrl:Pt.spelling("baseURL"),withXsrfToken:Pt.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let a=s&&y.merge(s.common,s[t.method]);s&&y.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),t.headers=at.concat(a,s);const c=[];let l=!0;this.interceptors.request.forEach(function(S){typeof S.runWhen=="function"&&S.runWhen(t)===!1||(l=l&&S.synchronous,c.unshift(S.fulfilled,S.rejected))});const h=[];this.interceptors.response.forEach(function(S){h.push(S.fulfilled,S.rejected)});let _,f=0,b;if(!l){const v=[ir.bind(this),void 0];for(v.unshift.apply(v,c),v.push.apply(v,h),b=v.length,_=Promise.resolve(t);f<b;)_=_.then(v[f++],v[f++]);return _}b=c.length;let E=t;for(f=0;f<b;){const v=c[f++],S=c[f++];try{E=v(E)}catch(C){S.call(this,C);break}}try{_=ir.call(this,E)}catch(v){return Promise.reject(v)}for(f=0,b=h.length;f<b;)_=_.then(h[f++],h[f++]);return _}getUri(n){n=Mt(this.defaults,n);const t=Gi(n.baseURL,n.url,n.allowAbsoluteUrls);return Li(t,n.params,n.paramsSerializer)}};y.forEach(["delete","get","head","options"],function(n){Ft.prototype[n]=function(t,e){return this.request(Mt(e||{},{method:n,url:t,data:(e||{}).data}))}}),y.forEach(["post","put","patch"],function(n){function t(e){return function(s,a,c){return this.request(Mt(c||{},{method:n,headers:e?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}Ft.prototype[n]=t(),Ft.prototype[n+"Form"]=t(!0)});let xc=class gr{constructor(n){if(typeof n!="function")throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(s){t=s});const e=this;this.promise.then(i=>{if(!e._listeners)return;let s=e._listeners.length;for(;s-- >0;)e._listeners[s](i);e._listeners=null}),this.promise.then=i=>{let s;const a=new Promise(c=>{e.subscribe(c),s=c}).then(i);return a.cancel=function(){e.unsubscribe(s)},a},n(function(s,a,c){e.reason||(e.reason=new Xt(s,a,c),t(e.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(n){if(this.reason){n(this.reason);return}this._listeners?this._listeners.push(n):this._listeners=[n]}unsubscribe(n){if(!this._listeners)return;const t=this._listeners.indexOf(n);t!==-1&&this._listeners.splice(t,1)}toAbortSignal(){const n=new AbortController,t=e=>{n.abort(e)};return this.subscribe(t),n.signal.unsubscribe=()=>this.unsubscribe(t),n.signal}static source(){let n;return{token:new gr(function(i){n=i}),cancel:n}}};function Ac(r){return function(t){return r.apply(null,t)}}function Dc(r){return y.isObject(r)&&r.isAxiosError===!0}const vn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(vn).forEach(([r,n])=>{vn[n]=r});function ar(r){const n=new Ft(r),t=Ci(Ft.prototype.request,n);return y.extend(t,Ft.prototype,n,{allOwnKeys:!0}),y.extend(t,n,null,{allOwnKeys:!0}),t.create=function(i){return ar(Mt(r,i))},t}const K=ar(ae);K.Axios=Ft,K.CanceledError=Xt,K.CancelToken=xc,K.isCancel=Ki,K.VERSION=rr,K.toFormData=De,K.AxiosError=A,K.Cancel=K.CanceledError,K.all=function(n){return Promise.all(n)},K.spread=Ac,K.isAxiosError=Dc,K.mergeConfig=Mt,K.AxiosHeaders=at,K.formToJSON=r=>Hi(y.isHTMLForm(r)?new FormData(r):r),K.getAdapter=nr.getAdapter,K.HttpStatusCode=vn,K.default=K;const{Axios:zc,AxiosError:Gc,CanceledError:Xc,isCancel:Jc,CancelToken:Qc,VERSION:Zc,all:Yc,Cancel:tl,isAxiosError:el,spread:nl,toFormData:il,AxiosHeaders:rl,HttpStatusCode:sl,formToJSON:al,getAdapter:ol,mergeConfig:cl}=K;class Rc extends xt{constructor({filters:t=null,config_port:e={baudRate:19200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:i=1,device_listen_on_channel:s=1,username:a=null,password:c=null,environment:l="production"}={filters:null,config_port:{baudRate:19200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1,username:null,password:null,environment:"production"}){super({filters:t,config_port:e,no_device:i,device_listen_on_channel:s});Q(this,p);_t(this,"__pinPad__",{buffer:null,about:{EMV:null,model:null,serial:null,brand:null,appVersion:null,printer:null,hasCashback:!1,supportInjection:!1,supportSign:!1,supportContactlessCollisionCard:!1,supportContactless:!1,supportDUKPT:"",injectedValues:!1,pp:null},config:{defaultEnvironment:"production",environment:"production",currency:"MXN",currencyCode:"0484",timeoutPinPad:"100",signSupport:"1",CTLSSupport:"1",userTRX:"userPinpadWeb",tp_operation:"29",requireCVVAmex:"1",forceOnline:"00",emvCard:"0",validateQPS:"1",username:null,password:null,country:null,idBranch:null,idCompany:null,latitude:null,longitude:null,publicKeyRSA:null,publicIP:null,internal:{stTokenization:!1,qpsDomestic:"",qpsInternational:"",cvmlVMCDomestic:"",cvmlVMCInternational:"",cvmlAmex:"",translimitCTLSVMC:"",translimitCTLSAmex:"",emv:{}},terminal:{},loginResponse:null,otherLogin:{},RC4Key:"KEY CREDIT CARD KEY",read:{EMV:"",PIN:"",POSEM:"",AppId:"",AppIdLabel:"",Arqc:"",Chip:"",ChipName:"",ChipNameEnc:"",ReadCTLS:"",NB_Data:"",NB_ksn:"",Tags:"",Type:""},tokenizeTRX:!1},constants:{appVersion:"1.0.16",appName:"pinpapWebApp ",STX:"",ETX:"",FS:"",getNULL:"\0",appChannel:"3",typeChannel:"11",urls:{development:"https://fcdev.mitec.com.mx",qa:"https://fcqa.mitec.com.mx",production:"https://m.mit.com.mx",productionAlternative:"https://m2.mit.com.mx"},uris:{login:"/pinpadWeb/login",RSAKey:"/pinpadWeb/getDataCrypt",merchant:"/pinpadWeb/getAfiliaciones",consult:"/pinpadWeb/queryTrx",keysDUKPT:"/pinpadWeb/getKeysDUKPT",reverse:"/pinpadWeb/executeBackSale",rePrint:"/pinpadWeb/reprint",checkInMoto:"/pinpadWeb/checkin",checkOutMoto:"/pinpadWeb/checkout",reAuthorizationMoto:"/pinpadWeb/reAuthorization",cancellation:"/pinpadWeb/executeVoid",sale:"/pinpadWeb/executeSale"}},operation:{amount:0,reference:null,folio:null,authorization:null,errors:0,last_error:null,commerceVoucher:"",clientVoucher:"",consultDate:null,ignore:{counter:!1,counterSale:!1,isError92TRX:!1,C93Global:!1,error:""},finalResult:{},moto:{ccType:"",ccName:"",ccNumber:"",ccExpMonth:"",ccExpYear:"",ccCvvCsc:"",txRoom:""},bin:"",bin8:"",hasQPS:!1,onlyMerchant:"",merchant:null,typeOperation:"29",typeResponse:"",responseMit:{},applyReverse:!1},finishCommand:{A:"",B:"",C:"",D:"",E:"",F:"",G:"",H:"",I:"",J:"",K:""},waiting:{statusAboutWaiting:null,statusInjectWaiting:null,statusReadCardWaiting:null,statusSecondGenerateWaiting:null}});if(this.__internal__.device.type="pinpad",!Ea())throw new Error("Crypto not supported in this browser");if(k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=3e3,this.__internal__.time.response_general=5e3,this.__internal__.serial.delay_first_connection=1e3,this.environment=l,a&&(this.username=a),c&&(this.password=c),o(this,p,br).call(this),o(this,p,yr).call(this)}async timeout(t,e){await super.timeout(t,e),this.__pinPad__.waiting.statusAboutWaiting&&e==="about"?this.__pinPad__.waiting.statusAboutWaiting="rejected":this.__pinPad__.waiting.statusInjectWaiting&&e==="inject"?this.__pinPad__.waiting.statusInjectWaiting="rejected":this.__pinPad__.waiting.statusinitDUKPTWaiting&&e==="init-dukpt"?this.__pinPad__.waiting.statusinitDUKPTWaiting="rejected":this.__pinPad__.waiting.statuswritingDUKPTWaiting&&e==="dukpt"?this.__pinPad__.waiting.statuswritingDUKPTWaiting="rejected":this.__pinPad__.waiting.statusReadCardWaiting&&e==="read-card"?this.__pinPad__.waiting.statusReadCardWaiting="rejected":this.__pinPad__.waiting.statusSecondGenerateWaiting&&e==="second-generate"&&(this.__pinPad__.waiting.statusSecondGenerateWaiting="rejected")}serialMessage(t){const e={original_code:t,code:null,name:null,description:null,request:this.lastAction,no_code:0,parsed:null},i=this.parseHexToUint8(t),s=this.parseUint8ArrayToString(i);let a=o(this,p,mr).call(this,s);switch(this.__pinPad__.buffer=s,e.parsed=a,e.code=s,e.request){case"connect":e.name="connected",e.description="Connection established",e.no_code=100,o(this,p,kn).call(this,a,s);break;case"about":e.name="About PinPad",e.description="Response of about",e.no_code=101,o(this,p,kn).call(this,a,s);break;case"inject":e.name="Inject",e.description="Response of inject values",e.no_code=102,o(this,p,wr).call(this,a,s);break;case"init-dukpt":e.name="Init DUKPT",e.description="Response of init DUKPT",e.no_code=103,o(this,p,vr).call(this,a,s);break;case"dukpt":e.name="Write DUKPT",e.description="Response of write DUKPT",e.no_code=104,o(this,p,Er).call(this,a,s);break;case"read-card":e.name="read card",e.description="response of read card",e.no_code=105,o(this,p,Pr).call(this,a,s);break;case"second-generate":e.name="second generate",e.description="response of second generate",e.no_code=106,o(this,p,Tr).call(this,a,s);break;case"cancel":e.name="cancel pinpad",e.description="response of cancel",e.no_code=107;break;case"print":o(this,p,kr).call(this,a,s),e.name="print voucher",e.description="response of print",e.no_code=108;break;case"cancel-read-card":o(this,p,Sr).call(this,a,s),e.name="cancel read card",e.description="response of cancel read card",e.no_code=109;break;case"code93":o(this,p,xr).call(this,a,s),e.name="code 93",e.description="response of code 93",e.no_code=110;break;case"finish-emv-end":o(this,p,Ar).call(this,a,s),e.name="Finish EMV End",e.description="response of finish EMV End",e.no_code=111;break;default:e.name="unknown",e.description="Unknown command",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){const e="",i="";let s="C56AABOUT";s=e+s.length.toString().padStart(3,"0")+s+i;let a=0;for(let l=0;l<s.length;l++)a^=s.charCodeAt(l);s=s+String.fromCharCode(a);const c=this.parseStringToBytes(s,"");return this.add0x(c)}async sendCustomCode({code:t=""}={}){if(typeof t!="string")throw new Error("Invalid string");const e=this.parseStringToBytes(t);await this.appendToQueue(e,"custom")}set username(t){this.__pinPad__.config.username=t}get username(){return this.__pinPad__.config.username}set password(t){if(typeof t!="string")throw new Error("Invalid password");this.__pinPad__.config.password=t.toUpperCase()}get password(){return this.__pinPad__.config.password}set amount(t){if(t=parseFloat(t),isNaN(t)||t<=0)throw new Error("Invalid amount");this.__pinPad__.operation.amount=t.toFixed(2).toString()}get amount(){return parseFloat(this.__pinPad__.operation.amount)||0}set reference(t){if(!o(this,p,Rn).call(this,t.trim()))throw new Error("Invalid reference");this.__pinPad__.operation.reference=t.trim().toString().replaceAll(" ","").toUpperCase()}get reference(){return this.__pinPad__.operation.reference}get url(){const t=this.environment;return this.__pinPad__.constants.urls[t]}get version(){return{name:this.__pinPad__.constants.appName,version:this.__pinPad__.constants.appVersion,environment:this.environment,type:this.typeDevice}}set environment(t){const e=["development","qa","production","productionAlternative"];if(typeof t!="string"||!e.includes(t.toLowerCase()))throw new Error("The environment must be a string, in: "+e.join(", "));this.__pinPad__.config.defaultEnvironment=t.toLowerCase(),this.__pinPad__.config.environment=t.toLowerCase()}get defaultEnvironment(){return this.__pinPad__.config.defaultEnvironment}get environment(){return this.__pinPad__.config.environment}get latitudeLongitude(){return{latitude:this.__pinPad__.config.latitude,longitude:this.__pinPad__.config.longitude}}set timeoutPinPad(t){if(t=parseInt(t),isNaN(t)||t<=10||t>=300)throw new Error("Invalid timeout please use a number between 10 and 300 seconds");this.__pinPad__.config.timeoutPinPad=t.toString()}get timeoutPinPad(){return parseInt(this.__pinPad__.config.timeoutPinPad)}async login({force:t=!1}={}){return await o(this,p,Nr).call(this,t)}clearSession(){localStorage.removeItem("ppLoginResponse"),localStorage.removeItem("ppRSAKey"),localStorage.removeItem("ppPublicIP")}async checkPositionPermission(){if(!te())throw new Error("Geolocation not supported");return new Promise((t,e)=>{navigator.permissions.query({name:"geolocation"}).then(i=>{i.state==="granted"?t(!0):t(!1)}).catch(()=>e(!1))})}async cancelReadCard(){let t="012VXVCANCELl";this.__pinPad__.about.model.toLowerCase()==="ingenico"&&(t="029C50AOPERACION CANCELADA");const e=this.parseStringToBytes(t,"");await this.appendToQueue(e,"cancel-read-card")}async print(t="client"){this.__pinPad__.operation.errors=0;const e=this.__pinPad__.constants.STX,i=this.__pinPad__.constants.ETX;this.__pinPad__.operation.commerceVoucher.includes(":")||(this.__pinPad__.operation.commerceVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,this.__pinPad__.operation.commerceVoucher)),this.__pinPad__.operation.clientVoucher.includes(":")||(this.__pinPad__.operation.clientVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,this.__pinPad__.operation.clientVoucher));let s=t==="client"?this.__pinPad__.operation.clientVoucher:this.__pinPad__.operation.commerceVoucher;if(s.length===0){this.dispatch("pp:print",{error:!0,code:"001",message:"Without information to print"});return}s=o(this,p,Ir).call(this,s),s=o(this,p,Or).call(this,s,this.__pinPad__.constants.appName+this.__pinPad__.constants.appVersion);let a="C59A"+s;a=e+o(this,p,wt).call(this,a)+a+i,a=a+o(this,p,vt).call(this,a),t==="client"?this.__pinPad__.operation.clientVoucher="":t==="commerce"&&(this.__pinPad__.operation.commerceVoucher="");const c=this.parseStringToBytes(a,"");await this.appendToQueue(c,"print")}getClientVoucher(){return this.__pinPad__.operation.clientVoucher}getCommerceVoucher(){return this.__pinPad__.operation.commerceVoucher}async consult({reference:t=null}){return t||(t=this.reference),kt(t)&&(t="--",this.reference=t),o(this,p,Ur).call(this,this.reference),this.__pinPad__.operation.consultDate=new Date().toLocaleDateString("en-GB"),await o(this,p,_e).call(this,{Ambiente:this.environment,User:this.username,Pwd:this.password,IdBranch:this.__pinPad__.config.idBranch,IdCompany:this.__pinPad__.config.idCompany,Country:this.__pinPad__.config.country,Tx_Date:this.__pinPad__.operation.consultDate}),o(this,p,Yt).call(this,this.url+this.__pinPad__.constants.uris.consult,{user:this.username.toUpperCase(),pwd:this.password.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),date:this.__pinPad__.operation.consultDate,reference:this.reference})}async rePrint({folio:t=null}={}){t===null&&(t=this.__pinPad__.operation.folio||""),o(this,p,On).call(this,t),await o(this,p,_e).call(this,{Ambiente:this.environment,User:this.username,Pwd:this.password,IdBranch:this.__pinPad__.config.idBranch,IdCompany:this.__pinPad__.config.idCompany,Country:this.__pinPad__.config.country,Tx_OperationNumber:t});const e=await o(this,p,Yt).call(this,this.url+this.__pinPad__.constants.uris.rePrint,{REPRINTVOUCHER:{business:{country:this.__pinPad__.config.country.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),pwd:this.password.toUpperCase(),user:this.username.toUpperCase()},no_operacion:t,crypto:"2"}});let i=e.voucher_comercio;return this.__pinPad__.operation.commerceVoucher="",i&&(e.voucher_comercio.includes(":")?this.__pinPad__.operation.commerceVoucher=e.voucher_comercio:this.__pinPad__.operation.commerceVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,e.voucher_comercio)),i=e.voucher_cliente,this.__pinPad__.operation.clientVoucher="",i&&(e.voucher_cliente.includes(":")?this.__pinPad__.operation.clientVoucher=e.voucher_cliente:this.__pinPad__.operation.clientVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,e.voucher_cliente)),e}async cancelPurchase({amount:t=0,authorization:e="",folio:i=""}={}){if(!o(this,p,In).call(this,t))throw new Error("Invalid amount");if(!o(this,p,Qr).call(this,e))throw new Error("Invalid authorization");if(!o(this,p,On).call(this,i))throw new Error("Invalid folio");t=o(this,p,Un).call(this,t,2);const s={Ambiente:this.environment,User:this.username,Pwd:this.password,IdBranch:this.__pinPad__.config.idBranch,IdCompany:this.__pinPad__.config.idCompany,Country:this.__pinPad__.config.country,UserTRX:"userPinpadWeb",Tx_OperationNumber:i,Tx_Auth:e,Amount:t};await o(this,p,_e).call(this,s);const a=o(this,p,Yt).call(this,this.url+this.__pinPad__.constants.uris.cancellation,{VMCAMEXMCANCELACION:{business:{country:this.__pinPad__.config.country.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),pwd:this.password.toUpperCase(),user:this.username.toUpperCase()},transacction:{amount:t,auth:e.toUpperCase(),crypto:"2",no_operacion:i,usrtransacction:this.username.toUpperCase(),version:this.__pinPad__.constants.appName+this.__pinPad__.constants.appVersion}}});return this.__pinPad__.operation.commerceVoucher="",a.voucher_comercio&&(a.voucher_comercio.includes(":")?this.__pinPad__.operation.commerceVoucher=a.voucher_comercio:this.__pinPad__.operation.commerceVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,a.voucher_comercio)),this.__pinPad__.operation.clientVoucher="",a.voucher_cliente&&(a.voucher_cliente.includes(":")?this.__pinPad__.operation.clientVoucher=a.voucher_cliente:this.__pinPad__.operation.clientVoucher=o(this,p,qt).call(this,this.__pinPad__.config.RC4Key,a.voucher_cliente)),JSON.stringify(a)}async makeSale({amount:t=0,reference:e=null}={}){if(t=parseFloat(t.toString()),isNaN(t)||t<=0)throw new Error("Amount is required and must be greater than 0");if(this.amount=t,!e||kt(e)||!o(this,p,Rn).call(this,e))throw new Error("Reference is required and must be alphanumeric");if(this.reference=e,/^[A-Z-a-z\s]+$/g.test(this.__pinPad__.config.currency)===!1)throw new Error("Invalid currency");let i={error:!1,message:null,approved:!1,object:{}};try{return await this.login(),await o(this,p,$r).call(this),!await o(this,p,zr).call(this)||!await o(this,p,jr).call(this)?i:await o(this,p,Yr).call(this)}catch(s){console.warn(s),i.error=!0,i.message=s.message,i.approved=!1,i.object=s}return i}}p=new WeakSet,yr=function(){k.add(this)},br=function(){const t=["pp:processing-card","pp:read-card","pp:error","pp:print","pp:merchant-moto","pp:dukpt","pp:finish-emv","pp:response"];for(const e of t)this.serialRegisterAvailableListener(e)},mr=function(t){const e=this.__pinPad__.constants.STX,i=this.__pinPad__.constants.ETX,s=this.__pinPad__.constants.FS,a=this.__pinPad__.constants.getNULL;t=t.replace(new RegExp(e,"g"),"");const c=t.split(i);t=c[0];const l=t.split(s);l.push(...c[1].split(s));const h={};return l.map((_,f)=>{const b=f>0?_.substring(0,1):"A",E=f>0?_.substring(1):_;return{[b]:E.replace(new RegExp(a,"g"),"")}}).forEach(_=>Object.assign(h,_)),h},kn=function(t,e){const i=this.__pinPad__.constants.ETX,s=e.substring(e.indexOf("D")+2,e.indexOf("E"));let a=0;const c=e.indexOf("N")>0,l=e.substring(e.indexOf("A00")+3,e.indexOf("B"));if(l&&l!=="undefined"&&l.toUpperCase()==="VERIFONE"){const _=s.replace("MITP_1.00.","").replace("MITP_01.00.","").replace("MITD_1.00.","").replace("MITD_01.00.","");a=parseInt(_),a>=15&&(this.__pinPad__.about.hasCashback=!0)}this.__pinPad__.about.supportInjection=c,e.indexOf("M")>0?(this.__pinPad__.about.supportSign=e.substring(e.indexOf("L")+2,e.indexOf("M")),this.__pinPad__.about.supportInjection?this.__pinPad__.about.supportContactlessCollisionCard=e.substring(e.indexOf("M")+2,e.indexOf("N")):(this.__pinPad__.about.supportContactlessCollisionCard=e.substring(e.indexOf("M")+2,e.indexOf(i)),this.__pinPad__.about.supportContactless=!0)):(this.__pinPad__.about.supportSign=e.substring(e.indexOf("L")+2,e.indexOf(i)),this.__pinPad__.about.supportContactless=!1),this.__pinPad__.about.supportDUKPT=e.substring(e.indexOf("J")+2,e.indexOf("K")),this.__pinPad__.about.EMV=e.substring(e.indexOf("E")+2,e.indexOf("F")),this.__pinPad__.about.serial=e.substring(e.indexOf("C")+2,e.indexOf("D")),this.__pinPad__.about.printer=e.substring(e.indexOf("F")+2,e.indexOf("G")),this.__pinPad__.about.model=e.substring(e.indexOf("B")+2,e.indexOf("C")),this.__pinPad__.about.brand=l,this.__pinPad__.about.appVersion=s;const h=e.substring(e.indexOf("K")+2,e.indexOf("L"));this.__pinPad__.about.pp={brand:l,appVersion:s,versionInt:a,hasCashback:this.__pinPad__.about.hasCashback,supportInjection:this.__pinPad__.about.supportInjection,supportSign:this.__pinPad__.about.supportSign,supportContactlessCollisionCard:this.__pinPad__.about.supportContactlessCollisionCard,supportContactless:this.__pinPad__.about.supportContactless,supportDUKPT:this.__pinPad__.about.supportDUKPT,hasDUKPTKeys:h,EMV:this.__pinPad__.about.EMV,serial:this.__pinPad__.about.serial,printer:this.__pinPad__.about.printer,model:this.__pinPad__.about.model},this.__pinPad__.waiting.statusAboutWaiting&&(this.__pinPad__.waiting.statusAboutWaiting="resolved")},wr=function(t,e){this.__pinPad__.waiting.statusInjectWaiting="resolved"},vr=function(t,e){e=e.replace("010P93A00B01t036P81AACERQUE, INSERTE CHIP O DESLICE*",""),this.__pinPad__.config.terminal={nb_kcv:e.substring(e.indexOf("E")+2,e.indexOf("F")),nb_marca_terminal:e.substring(e.indexOf("P91A")+4,e.indexOf("B")),nb_modelo_terminal:e.substring(e.indexOf("B")+2,e.indexOf("C")),nb_serie_lector:e.substring(e.indexOf("C")+2,e.indexOf("D")),nb_tk:e.substring(e.indexOf("F")+2,e.length-2),nb_version_terminal:e.substring(e.indexOf("D")+2,e.indexOf("E"))},this.__pinPad__.waiting.statusinitDUKPTWaiting="resolved"},Er=function(t,e){this.__pinPad__.waiting.statuswritingDUKPTWaiting="resolved"},Pr=function(t,e){const i=this.__pinPad__.about.brand.toLowerCase(),s=this.__pinPad__.about.model.toLowerCase(),a=i==="ingenico"&&s==="ipp320"?500:350;if(e.length<a){e=e.replace("006P93A00.","").replace("006P93A00,",""),e.includes("E93")?this.__pinPad__.operation.ignore.error=e.substring(e.indexOf("E93")+3,e.indexOf("E93")+6):e.includes("E71")&&(this.__pinPad__.operation.ignore.error=e.substring(e.indexOf("E71")+3,e.indexOf("E71")+6)),this.__pinPad__.operation.ignore.error!==""&&e.indexOf("OPERACION CANCELADA")===-1&&e.indexOf("TIEMPO EXCEDIDO")===-1&&this.__pinPad__.operation.ignore.error.length===3&&(this.__pinPad__.operation.last_error=o(this,p,Vn).call(this,this.__pinPad__.operation.ignore.error),this.__pinPad__.waiting.statusReadCardWaiting="rejected");return}if(e.includes("M1")||e.includes("M0")||e.includes("M1")||e.includes("N1")||e.includes("N1")||e.includes("P93A022")&&e.substring(e.length-24).includes("I")&&e.substring(e.length-1).includes("")||e.includes("P93A800")&&e.substring(e.length-24).includes("I")&&e.substring(e.length-1).includes("")||e.includes("P93A022")&&e.length>=406&&s==="vx820"||e.includes("P93A022")&&e.length>=406&&s==="vx520"||e.includes("P93A800")&&e.length>=406&&s==="vx520"||e.includes("P93A800")&&e.length>=406&&s==="vx820"||e.includes("P93A022")&&e.length>=406&&s==="p400"||e.includes("P93A800")&&e.length>=406&&s==="p400"||e.includes("P93A022")&&e.length>=406&&s==="v205c"||e.includes("P93A800")&&e.length>=406&&s==="v205c"||e.includes("P93A022")&&e.length>=406&&s==="move2500"||e.includes("P93A800")&&e.length>=406&&s==="move2500"||e.includes("P93A022")&&e.length>=406&&s==="lane3000"||e.includes("P93A800")&&e.length>=406&&s==="lane3000"){let c=e;i==="verifone"&&(c=e.replace("006P93A00.","").substring(e.indexOf("P93A"),e.indexOf("P93A")+7)),e.includes("P81APROCESANDO, NO RETIRE TARJETA")||e.includes("P81APROCESANDO TARJETA")||c.includes("P93A022")||c.includes("P81AINSERTE CHIP O DESLICE TARJETA")||c.includes("ACERQUE, INSERTE CHIP O DESLICE")||c.includes("P81AACERQUE, INSERTE CHIP O DESLICE TARJETA")?this.dispatch("pp:processing-card",{waiting:!0}):e.length>a&&o(this,p,Cr).call(this,e)}},Tr=function(t,e){const i=this.__pinPad__.constants.ETX;let s=e.replace("023P81AFAVOR RETIRAR TARJ.","").replace("020P81A DECLINADA EMV ","").replace("020P81A DECLINADA EMV ","");s=s.substring(s.indexOf("B")+2,s.indexOf(i)),s.includes("006E93A16")&&(s="01"),this.__pinPad__.operation.applyReverse=s==="01"&&this.__pinPad__.operation.responseMit._approved&&this.__pinPad__.config.otherLogin.executeReverse==="1",this.__pinPad__.waiting.statusSecondGenerateWaiting="resolved"},Cr=function(t){const e=this.__pinPad__.constants.ETX,i=this.__pinPad__.about.brand.toLowerCase();let s,a,c,l,h;i==="verifone"?t=t.replace("006P93A00.","").replace("009P93A00","").replace("010P93A00B01v",""):t=t.replace("006P93A00,",""),this.__pinPad__.config.read.POSEM=t.substring(t.indexOf("P93A")+4,t.indexOf("B"));const _=this.__pinPad__.config.read.POSEM;if(_==="051"||_==="071"){if(this.__pinPad__.config.read.Chip="1",this.__pinPad__.config.read.PIN=t.substring(t.indexOf("C")+2,t.indexOf("D")),this.__pinPad__.config.read.AppId=t.substring(t.indexOf("G")+2,t.indexOf("H")),this.__pinPad__.config.read.AppIdLabel=t.substring(t.indexOf("H")+2,t.indexOf("I")),this.__pinPad__.config.read.Arqc=t.substring(t.indexOf("F")+2,t.indexOf("G")),t.includes("O")){const f=t.substring(t.indexOf("P93A"));this.__pinPad__.config.read.ReadCTLS=f.substring(f.indexOf("M")+2,f.indexOf("N")),this.__pinPad__.operation.hasQPS=f.substring(f.indexOf("N")+2,f.indexOf("O"))==="1",this.__pinPad__.operation.bin8=f.substring(f.indexOf("O")+2,f.indexOf(e))}else if(t.includes("N")){const f=t.substring(t.indexOf("P93A"));this.__pinPad__.config.read.ReadCTLS=f.substring(f.indexOf("M")+2,f.indexOf("N")),this.__pinPad__.operation.hasQPS=f.substring(f.indexOf("N")+2,f.indexOf(e))==="1"}else{const f=t.substring(t.indexOf("P93A"),t.indexOf("M")+5);this.__pinPad__.config.read.ReadCTLS=f.substring(f.indexOf("M")+2,f.indexOf(e)),this.__pinPad__.operation.hasQPS=!1}this.__pinPad__.config.read.Tags=t.substring(t.indexOf("B")+2,t.indexOf("C")),this.__pinPad__.config.read.NB_ksn=t.substring(t.indexOf("K")+2,t.indexOf("M")),this.__pinPad__.config.read.NB_Data=t.substring(t.indexOf("D")+2,t.indexOf("E")),a=t.substring(t.indexOf("I")+2,t.indexOf("J")),c=t.substring(t.indexOf("E")+2,t.indexOf("F")),this.__pinPad__.config.read.ChipName=c,s=t.substring(t.indexOf("J")+2,t.indexOf("K"))}else{let f;if(this.__pinPad__.config.read.Chip="0",this.__pinPad__.config.read.PIN="",this.__pinPad__.config.read.AppId="",this.__pinPad__.config.read.Arqc="",this.__pinPad__.config.read.ReadCTLS="0",this.__pinPad__.config.read.AppIdLabel=t.substring(t.indexOf("H")+2,t.indexOf("I")),this.__pinPad__.config.read.Tags=t.substring(t.indexOf("B")+2,t.indexOf("C")),_==="022")if(t.includes("O")){const b=t.substring(t.indexOf("P93A"));this.__pinPad__.operation.bin8=b.substring(b.indexOf("O")+2,b.indexOf(e)),f=t.substring(t.indexOf("P93A022"),t.indexOf("I")+23),f=f.substring(f.indexOf("I")+2,f.lastIndexOf(""))}else f=t.substring(t.indexOf("P93A022"),t.indexOf("I")+23),f=f.substring(f.indexOf("I")+2,f.indexOf(e));else f=t.substring(t.indexOf("P93A800"),t.indexOf("I")+23),f=f.substring(f.indexOf("I")+2,f.indexOf(e));this.__pinPad__.config.read.NB_ksn=f,this.__pinPad__.config.read.NB_Data=t.substring(t.indexOf("B")+2,t.indexOf("C")),a=t.substring(t.indexOf("F")+2,t.indexOf("G")),s=t.substring(t.indexOf("G")+2,t.indexOf("H")),this.__pinPad__.about.model.toLowerCase()==="vx520"?(c=t.substring(t.indexOf("H")+2,t.indexOf("I")),this.__pinPad__.config.read.ChipName=c):(c=t.substring(t.indexOf("H")+2,t.indexOf("I")),this.__pinPad__.config.read.ChipName=c)}s.includes("/")&&(s=s.replace("/","")),s.toString().length===4?(h=s.toString().substring(0,2),l=s.toString().substring(2)):(h="",l=""),this.__pinPad__.config.read.Chip==="1"?(this.__pinPad__.config.read.EMV="3",this.__pinPad__.config.read.ChipNameEnc="1"):(this.__pinPad__.config.read.ChipNameEnc="",this.__pinPad__.config.read.EMV="2"),this.__pinPad__.config.read.AppIdLabel.toLowerCase().includes("american")||this.__pinPad__.config.read.AppIdLabel.toLowerCase().includes("amex")?this.__pinPad__.config.read.Type="AMEX":this.__pinPad__.config.read.Type="V/MC",this.__pinPad__.operation.bin=a,a.length>6&&(this.__pinPad__.operation.bin=a.substring(0,6)),this.__pinPad__.waiting.statusReadCardWaiting="resolved",this.dispatch("pp:read-card",{ERROR:"",maskPan:a,name:c,month:h,year:l})},Sr=function(t,e){e.length>10&&e.includes("E93A10")&&(this.__pinPad__.waiting.statusReadCardWaiting==="pending"&&(this.__pinPad__.waiting.statusReadCardWaiting="rejected"),this.dispatch("pp:error",{message:"Operation cancelled by user."}))},kr=function(t,e){const i=this;if(this.__pinPad__.about.model.toLowerCase()==="vx520"){if(e.length>11)if(e.includes("P59A00"))this.__pinPad__.operation.clientVoucher!==""?setTimeout(function(){i.print("client").then(()=>{}).catch(s=>{console.error(s)})},1e3):this.dispatch("pp:print",{type:"success"});else{const s=e.includes("E17")||e.includes("A17")?{type:"warning",message:"printer without paper"}:{type:"error",message:"The voucher could not be printed"};this.dispatch("pp:print",s)}}else if(e.includes("P59A00"))this.__pinPad__.operation.clientVoucher!==""?setTimeout(function(){i.print("client").then(()=>{}).catch(s=>{console.error(s)})},1e3):this.dispatch("pp:print",{type:"success"});else{const s=e.includes("E17")||e.includes("A17")?{type:"warning",message:"printer without paper"}:{type:"error",message:"The voucher could not be printed"};this.dispatch("pp:print",s)}},xr=function(t,e){},Ar=function(t,e){},he=function(t,e){const i=new ao;return i.setPublicKey(t),i.encrypt(e)},ue=function(t){const e="0123456789ABCDEF";let i="";for(let s=0;s<t;s++){const a=Math.floor(Math.random()*e.length);i+=e.substring(a,a+1)}return i},Dr=function(t){const e="0123456789abcdef",i=[],s=[];for(let a=0;a<256;a++)i[a]=e.charAt(a>>4)+e.charAt(a&15);for(let a=0;a<t.length;a++)s[a]=i[t.charCodeAt(a)];return s.join("")},de=async function(t,e){const i=new Uint8Array(t.match(/.{1,2}/g).map(b=>parseInt(b,16))),s=crypto.getRandomValues(new Uint8Array(16)),c=new TextEncoder().encode(e),l=await crypto.subtle.importKey("raw",i,{name:"AES-CBC"},!1,["encrypt"]),h=await crypto.subtle.encrypt({name:"AES-CBC",iv:s},l,c),_=btoa(String.fromCharCode(...s)),f=btoa(String.fromCharCode(...new Uint8Array(h)));return _+f},Rr=function(t,e,i=!1){const s=[];for(let _=0;_<256;_++)s[_]=_;let a=0;for(let _=0;_<256;_++)a=(a+s[_]+t.charCodeAt(_%t.length))%256,[s[_],s[a]]=[s[a],s[_]];let c=0,l=0,h="";for(const _ of e){c=(c+1)%256,l=(l+s[c])%256,[s[c],s[l]]=[s[l],s[c]];let f=s[(s[c]+s[l])%256];h+=String.fromCharCode(_.charCodeAt(0)^f)}return i?o(this,p,Dr).call(this,h).toUpperCase():h},qt=function(t,e){return o(this,p,Rr).call(this,t,this.hexToAscii(e))},Ir=function(t){return t.replaceAll("Á","A"),t.replaceAll("É","E"),t.replaceAll("Í","I"),t.replaceAll("Ó","O"),t.replaceAll("Ú","U"),t.replaceAll("á","a"),t.replaceAll("é","e"),t.replaceAll("í","i"),t.replaceAll("ó","o"),t.replaceAll("ú","u"),t.replaceAll("ñ","n"),t.replaceAll("Ñ","N"),t.replaceAll('Electr?a"',"Electronica"),t},J=function(t,e,i){if(t=t.replace("@cnb logo_cpagos",e),t=t.replace("@cnn ver_app",i),t=t.replace(/@/g," @"),t=t.replace(/ {2}@/g," @"),t=t.replace(/ {3}@/g," @"),t=t.replace(/\r/g,""),t=t.replace(/\n/g,""),t.includes("@lsn POR ESTE PAGARE ME OBLIGO INCONDI")){const s=t.indexOf("@lsn POR ESTE PAGARE ME OBLIGO INCONDI");t=t.substring(0,s)}return t.trim()+"@br @br @br @br @br"},Or=function(t,e){const i="@logo3 @br",s="@cnn "+e;return t.includes("@cnb Santander")?(t=t.replace("@cnb Santander","@logo1@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb American Express")?(t=t.replace("@cnb American Express","@logo2@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb HSBC")?(t=t.replace("@cnb HSBC","@logo7@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb IXE")?(t=t.replace("@cnb IXE","@logo11@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb MULTIVA")?(t=t.replace("@cnb MULTIVA","@logo15@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb Multiva")?(t=t.replace("@cnb Multiva","@logo15@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb SCOTIA BANK")?(t=t.replace("@cnb SCOTIA BANK","@logo16@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb SCOTIABANK")?(t=t.replace("@cnb SCOTIABANK","@logo16@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb BANCOMER")?(t=t.replace("@cnb BANCOMER","@logo17@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb Bancomer")?(t=t.replace("@cnb Bancomer","@logo17@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb BBVA")?(t=t.replace("@cnb BBVA","@logo17@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb BANORTE")?(t=t.replace("@cnb BANORTE","@logo18@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb Banorte")?(t=t.replace("@cnb Banorte","@logo18@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb BANREGIO")?(t=t.replace("@cnb BANREGIO","@logo19@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb Banregio")?(t=t.replace("@cnb Banregio","@logo19@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb GETNET")?(t=t.replace("@cnb GETNET","@logo20@br"),o(this,p,J).call(this,t,i,s)):t.includes("@cnb GetNET")?(t=t.replace("@cnb GetNET","@logo20@br"),o(this,p,J).call(this,t,i,s)):o(this,p,J).call(this,t,i,s)},Nr=async function(t=!1){if(o(this,p,Mr).call(this),this.__pinPad__.config.loginResponse&&!t)return await o(this,p,xn).call(this);const e=this.url+this.__pinPad__.constants.uris.login,i={usuario:this.username,password:this.password,crypto:"",version:this.__pinPad__.constants.appVersion,serieLector:"",canal:this.__pinPad__.constants.appChannel};if(await o(this,p,pe).call(this),o(this,p,An).call(this))throw new Error("Empty RSA Key");const s=o(this,p,ue).call(this,32),a=o(this,p,he).call(this,this.__pinPad__.config.publicKeyRSA,s),c=await o(this,p,de).call(this,s,JSON.stringify(i)),l=await K.post(e,c,{headers:{"Content-Type":"application/json","cache-control":"no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0",data:a||""}}).catch(_=>{var f;throw new Error(`Error in request, verify internet connection: ${(f=_.response)==null?void 0:f.status} ${_.message}`)});let h=o(this,p,Nn).call(this,JSON.stringify(l.data));if(typeof h=="string"&&(h=JSON.parse(h)),!h)throw new Error("Invalid response JSON");if(h.RESPUESTA==="error")throw new Error(h);return this.__pinPad__.config.loginResponse=h,localStorage.setItem("ppLoginResponse",JSON.stringify({timestamp:new Date().getTime(),data:h})),await o(this,p,xn).call(this)},xn=async function(){await o(this,p,qr).call(this);try{await o(this,p,Vr).call(this)}catch(t){console.log("Error getting position",t)}return this.__pinPad__.config.otherLogin={},o(this,p,Br).call(this,this.__pinPad__.config.loginResponse),this.__pinPad__.config.otherLogin},Br=function(t){var a,c,l,h,_,f;let e="",i="";(c=(a=t.xml)==null?void 0:a.ventaspropias)!=null&&c.merchant_currencyb&&(e=t.xml.ventaspropias.merchant_currencyb),(h=(l=t.xml)==null?void 0:l.ventaspropias)!=null&&h.merchant_currencym&&(i=t.xml.ventaspropias.merchant_currencym);let s=(_=t.xml)==null?void 0:_.emvReverso;s||(s="0"),this.__pinPad__.config.internal.stTokenization=(f=t.xml)==null?void 0:f.st_tokenizacion,!this.__pinPad__.config.internal.stTokenization||this.__pinPad__.config.internal.stTokenization==="false"||this.__pinPad__.config.internal.stTokenization==="0"?this.__pinPad__.config.internal.stTokenization=!1:this.__pinPad__.config.internal.stTokenization&&(this.__pinPad__.config.internal.stTokenization=!0),this.__pinPad__.config.internal.emv=t.xml.importesPGS,this.__pinPad__.config.internal.qpsDomestic=this.__pinPad__.config.internal.emv.qps_dom,this.__pinPad__.config.internal.qpsInternational=this.__pinPad__.config.internal.emv.qps_il,this.__pinPad__.config.internal.cvmlVMCDomestic=this.__pinPad__.config.internal.emv.cvml_vm_dom,this.__pinPad__.config.internal.cvmlVMCInternational=this.__pinPad__.config.internal.emv.cvml_vm_il,this.__pinPad__.config.internal.cvmlAmex=this.__pinPad__.config.internal.emv.cvml_amex,this.__pinPad__.config.internal.translimitCTLSVMC=this.__pinPad__.config.internal.emv.tl_mc,this.__pinPad__.config.internal.translimitCTLSAmex=this.__pinPad__.config.internal.emv.tl_amex,this.__pinPad__.config.country=t.country.toUpperCase(),this.__pinPad__.config.idBranch=t.id_branch.toUpperCase(),this.__pinPad__.config.idCompany=t.id_company.toUpperCase(),this.__pinPad__.config.otherLogin={bsUser:t.user,nbUser:t.nb_user,bsCompany:t.id_company,nbCompany:t.nb_company,nbStreetCompany:t.nb_companystreet,bsBranch:t.id_branch,nbBranch:t.nb_branch,bsCountry:t.country,coins:e,coinsMOTO:i,executeReverse:s}},Mr=function(){let t=localStorage.getItem("ppLoginResponse");t&&(t=JSON.parse(t),this.__pinPad__.config.loginResponse||(this.__pinPad__.config.loginResponse=t.data),new Date().getTime()-t.timestamp>=864e5&&(this.__pinPad__.config.loginResponse=null))},Fr=async function(){const t=this.url+this.__pinPad__.constants.uris.RSAKey,e=await K.get(t).catch(i=>{throw new Error(`Error in request, verify internet connection: ${i.response.status} ${i.message}`)});if(e.headers.get("content-type").indexOf("application/json")===-1)throw new Error("Fail to fetch RSA public key");return this.__pinPad__.config.publicKeyRSA=e.data.key_public,localStorage.setItem("ppRSAKey",JSON.stringify({timestamp:new Date().getTime(),data:e.data.key_public})),this.__pinPad__.config.publicKeyRSA},An=function(){let t=localStorage.getItem("ppRSAKey");return!t||(t=JSON.parse(t),this.__pinPad__.config.publicKeyRSA=t.data,new Date().getTime()-t.timestamp>=864e5)?!0:!this.__pinPad__.config.publicKeyRSA},Dn=async function(){return o(this,p,An).call(this)?await o(this,p,Fr).call(this):this.__pinPad__.config.publicKeyRSA},pe=async function(){if(!await o(this,p,Dn).call(this))throw new Error("RSA public key is empty")},Rn=function(t){return/^[A-Z-a-z0-9\s]+$/g.test(t)},Ur=function(t){if(kt(t))return!0;const e=/^[A-Z-a-z0-9\s]+$/g.test(t)===!0;if(!e)throw new Error("Invalid reference");return e},wt=function(t){return t.length.toString().padStart(3,"0")},vt=function(t){let e=0;for(let i=0;i<t.length;i++)e^=t.charCodeAt(i);return String.fromCharCode(e)},je=function(t,e=0){return t=parseFloat(t.toString().replace(/[^0-9.-]/g,"")),isNaN(t)?0 .toFixed(e):t.toFixed(e).replace(/,/g,"")},In=function(t){return t=parseFloat(t.toString()),!(isNaN(t)||t<0)},_e=async function(t){for(const e in t)if(typeof t[e]>"u"||t[e]===null||t[e]==="")throw new Error("Object incomplete to process");return t},On=function(t){if(!t||isNaN(parseInt(t))||t.toString().length!==9)throw new Error("Number of operation must be number of 9 digits");return t},Nn=function(t){if(typeof t!="string")throw new Error("Invalid string");return!t||/<html(?:\s+lang=["'][^"']*["'])?>/i.test(t)||(t=t.replace(/aaa/g,"á"),t=t.replace(/eee/g,"é"),t=t.replace(/iii/g,"í"),t=t.replace(/ooo/g,"ó"),t=t.replace(/uuu/g,"ú"),t=t.replace(/NNN/g,"Ñ"),t=t.replace(/nnn/g,"ñ"),t=t.replace(/á/g,"á")),t},Lr=async function(){const t=this.__pinPad__.constants.STX,e=this.__pinPad__.constants.ETX;let i="C55ACANCEL";i=t+o(this,p,wt).call(this,i)+i+e,i=i+o(this,p,vt).call(this,i);const s=this.parseStringToBytes(i,"");await this.appendToQueue(s,"cancel")},Bn=function(){const t=new Date,e=t.getDate().toString().padStart(2,"0"),i=(t.getMonth()+1).toString().padStart(2,"0"),s=t.getFullYear().toString().substring(2);return e+i+s},Mn=function(){const t=new Date,e=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0");return e+i},Vr=async function(){return this.__pinPad__.config.latitude&&this.__pinPad__.config.longitude?this.latitudeLongitude:(this.__pinPad__.config.latitude=null,this.__pinPad__.config.longitude=null,te()?new Promise(t=>{navigator.geolocation.getCurrentPosition(e=>{this.__pinPad__.config.latitude=e.coords.latitude,this.__pinPad__.config.longitude=e.coords.longitude,t(this.latitudeLongitude)},()=>{t(this.latitudeLongitude)})}):this.latitudeLongitude)},qr=async function(){let t=localStorage.getItem("ppPublicIP");if(t&&(t=JSON.parse(t),this.__pinPad__.config.publicIP=t.data,new Date().getTime()-t.timestamp>=864e5&&(this.__pinPad__.config.publicIP=null)),this.__pinPad__.config.publicIP)return this.__pinPad__.config.publicIP;this.__pinPad__.config.publicIP=null;let e=!1;const i=await K.get("https://api.ipify.org?format=json").catch(()=>e=!0);return e?null:(this.__pinPad__.config.publicIP=i.data.ip||null,localStorage.setItem("ppPublicIP",JSON.stringify({timestamp:new Date().getTime(),data:i.data.ip})),this.__pinPad__.config.publicIP)},Yt=async function(t,e){await o(this,p,pe).call(this);const i=o(this,p,ue).call(this,32);let s=o(this,p,he).call(this,this.__pinPad__.config.publicKeyRSA,i),a=await o(this,p,de).call(this,i,JSON.stringify(e));return(await K.post(t,a,{headers:{"Content-Type":"application/json","cache-control":"no-cache",data:s||""}}).catch(l=>{var h;throw l.response.data.includes("Ha ocurrido un error al procesar su solicitud.")?new Error("It was not possible to obtain the affiliations."):l.response.status>=500&&l.response.status<=599?new Error(`Service Temporarily Unavailable ${l.message}`):new Error(`Error in request, verify internet connection: ${(h=l.response)==null?void 0:h.status} ${l.message}`)})).data},Fn=async function({data:t,url:e,cancelable:i=!1}={}){await o(this,p,pe).call(this);const s=o(this,p,ue).call(this,32),a=o(this,p,he).call(this,this.__pinPad__.config.publicKeyRSA,s),c=await o(this,p,de).call(this,s,JSON.stringify(t)),l=this;return(await K.post(e,c,{headers:{"Content-Type":"application/json","cache-control":"no-cache",data:a||""}}).catch(async _=>{var b;let f=`Error in request, verify internet connection: ${_.status} ${_.message}`;throw _.response.status>=500&&_.response.status<=599?f="Service Temporarily Unavailable":_.response.status>=400&&_.response.status<=499&&(f="Bad Request"),i&&await o(b=l,p,Lr).call(b),new Error(f)})).data},Hr=async function(){const t=this.__pinPad__.constants.FS,e=this.__pinPad__.constants.ETX,i=this.__pinPad__.constants.STX;let s="C57A"+this.__pinPad__.config.internal.qpsDomestic;if(s=s+t+"B"+this.__pinPad__.config.internal.qpsInternational,s=s+t+"C"+this.__pinPad__.config.internal.cvmlVMCDomestic,s=s+t+"D"+this.__pinPad__.config.internal.cvmlVMCInternational,s=s+t+"E"+this.__pinPad__.config.internal.cvmlAmex,s=s+t+"F"+this.__pinPad__.config.internal.translimitCTLSVMC,s=s+t+"G"+this.__pinPad__.config.internal.translimitCTLSAmex,s=i+o(this,p,wt).call(this,s)+s+e,s=s+o(this,p,vt).call(this,s),!this.__pinPad__.about.injectedValues){const a=this.parseStringToBytes(s,"");await this.appendToQueue(a,"inject")}},jr=async function(){this.__pinPad__.operation.bin8&&(this.__pinPad__.operation.bin=this.__pinPad__.operation.bin8),this.__pinPad__.operation.bin8="";const t=await o(this,p,Fn).call(this,{data:{accion:"tipoPagoInfo",cc_num:this.__pinPad__.operation.bin,usuario:this.username.toUpperCase(),canal:this.__pinPad__.constants.typeChannel,tp_canal:"1",tp_moneda:this.__pinPad__.config.currency.toUpperCase()},url:this.url+this.__pinPad__.constants.uris.merchant,cancelable:!0});if(!t.respuesta||t.respuesta==="0"){let e="C55ACANCEL";const i=this.__pinPad__.constants.STX,s=this.__pinPad__.constants.ETX;e=i+o(this,p,wt).call(this,e)+e+s,e=e+o(this,p,vt).call(this,e);const a=this.parseStringToBytes(e,"");return await this.appendToQueue(a,"cancel"),!1}return this.__pinPad__.operation.merchant=t,this.__pinPad__.operation.onlyMerchant=t.contado.af.length>1?t.contado.af[0].merchant:t.contado.af.merchant,!0},Kr=async function(t=null){if(this.__pinPad__.waiting.statusAboutWaiting)throw new Error("AboutPP is already running");const e=this.__pinPad__.constants.STX,i=this.__pinPad__.constants.ETX;let s="C56AABOUT";if(s=e+o(this,p,wt).call(this,s)+s+i,s=s+o(this,p,vt).call(this,s),kt(this.__pinPad__.about.pp)){this.__pinPad__.waiting.statusAboutWaiting="pending";const l=this.parseStringToBytes(s,"");await this.appendToQueue(l,"about")}else return t?t(this.__pinPad__.about.pp.supportDUKPT,this.__pinPad__.about.pp.hasDUKPTKeys):!0;const a=this;let c=0;return new Promise((l,h)=>{c=setInterval(()=>{if(a.__pinPad__.waiting.statusAboutWaiting==="resolved"){if(clearInterval(c),a.__pinPad__.waiting.statusAboutWaiting=null,kt(a.__pinPad__.about.pp))return;t||l(!0),l(t(a.__pinPad__.about.pp.supportDUKPT,a.__pinPad__.about.pp.hasDUKPTKeys))}else a.__pinPad__.waiting.statusAboutWaiting==="rejected"&&(clearInterval(c),a.__pinPad__.waiting.statusAboutWaiting=null,h("Error"))},500)})},Ke=async function(t,e){if(t=t?t.toString():"",e=e?e.toString():"",kt(t)||t==="0"){this.dispatch("pp:dukpt",{status:"unsupported",already:!1});return}if(kt(e)||e==="1"){this.dispatch("pp:dukpt",{status:"charged",already:!0});return}const i=o(this,p,Bn).call(this),s=o(this,p,Mn).call(this),a=this.__pinPad__.constants.FS,c=this.__pinPad__.constants.ETX,l=this.__pinPad__.constants.STX;let h="C91A"+i+a+"B"+s;h=l+o(this,p,wt).call(this,h)+h+c,h=h+o(this,p,vt).call(this,h);const _=this.parseStringToBytes(h,"");await this.appendToQueue(_,"init-dukpt");let f=0;this.__pinPad__.waiting.statusinitDUKPTWaiting="pending";const b=this;return new Promise((E,v)=>{f=setInterval(async()=>{var S;b.__pinPad__.waiting.statusinitDUKPTWaiting==="resolved"?(clearInterval(f),b.__pinPad__.waiting.statusinitDUKPTWaiting=null,b.dispatch("pp:dukpt",{status:"charged",already:!1}),await o(S=b,p,Wr).call(S),E(!0)):b.__pinPad__.waiting.statusinitDUKPTWaiting==="rejected"&&(clearInterval(f),b.__pinPad__.waiting.statusinitDUKPTWaiting=null,v("Error"))},500)})},Wr=async function(){const t={IPEK_REQUESTType:{business:{country:this.__pinPad__.config.country.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),pwd:this.password.toUpperCase(),user:this.username.toUpperCase()},terminal:this.__pinPad__.config.terminal}},e=await o(this,p,Fn).call(this,{data:t,url:this.url+this.__pinPad__.constants.uris.keysDUKPT});await o(this,p,is).call(this,e)},$r=async function(){if(!await o(this,p,Dn).call(this))throw new Error("RSA public key is empty");const e=this;await o(this,p,Kr).call(this,async function(s,a){var l,h;if(e.__pinPad__.about.supportInjection&&e.__pinPad__.config.internal.emv&&e.__pinPad__.about.injectedValues)return await o(l=e,p,Ke).call(l,s,a),!0;let c=0;return e.__pinPad__.waiting.statusInjectWaiting="pending",await o(h=e,p,Hr).call(h),new Promise((_,f)=>{c=setInterval(async()=>{var b;e.__pinPad__.waiting.statusInjectWaiting==="resolved"?(clearInterval(c),e.__pinPad__.waiting.statusInjectWaiting=null,await o(b=e,p,Ke).call(b,s,a),_(!0)):e.__pinPad__.waiting.statusInjectWaiting==="rejected"&&(clearInterval(c),e.__pinPad__.waiting.statusInjectWaiting=null,f("Error"))},500)})})},Un=function(t,e=0){if(t=parseFloat(t.toString().replace(/[^0-9.-]/g,"")),isNaN(t)||t===0)return parseFloat("0").toFixed(e);t=t.toFixed(e);let i=t.split(".");return i[0]=i[0].replace(/\B(?=(\d{3})+(?!\d))/g,""),i.join(".")},zr=async function(){this.__pinPad__.operation.errors=0;let t="ACERQUE, INSERTE CHIP O DESLICE TARJETA";if(this.__pinPad__.about.supportContactless||(t="INSERTE CHIP O DESLICE TARJETA"),this.__pinPad__.about.model.toUpperCase().includes("UX300")&&(t="ACERQUE O INSERTE TARJETA"),kt(this.amount)||this.amount<=0)throw new Error("Amount required");if(o(this,p,In).call(this,this.amount)===!1)throw new Error("Invalid amount required");if(o(this,p,je).call(this,this.amount,2)<=0)throw new Error("Amount must be greater than 0");const e=this.__pinPad__.constants.FS,i=this.__pinPad__.constants.STX,s=this.__pinPad__.constants.ETX;let a="C93A"+t;a=a+e+"B"+o(this,p,Bn).call(this),a=a+e+"C"+o(this,p,Mn).call(this),a=a+e+"D"+o(this,p,je).call(this,this.amount,2),a=a+e+"E0.00",a=a+e+"F"+this.__pinPad__.config.currencyCode,this.__pinPad__.about.supportDUKPT&&this.__pinPad__.about.supportDUKPT!=="0"&&this.__pinPad__.about.supportDUKPT!=="false"&&(this.__pinPad__.about.supportContactless?(a=a+e+"G"+this.timeoutPinPad,a=a+e+"HTAGS",a=a+e+"I"+this.__pinPad__.config.requireCVVAmex,a=a+e+"J"+this.__pinPad__.config.forceOnline,a=a+e+"K"+this.__pinPad__.about.supportContactless,a=a+e+"L"+this.__pinPad__.config.emvCard,this.__pinPad__.about.hasCashback&&(a=a+e+"M0",a=a+e+"N00")):(a=a+e+"G"+this.timeoutPinPad,a=a+e+"HTAGS",a=a+e+"I"+this.__pinPad__.config.requireCVVAmex,a=a+e+"L"+this.__pinPad__.config.emvCard),this.__pinPad__.about.supportInjection&&(a=a+e+"O"+this.__pinPad__.config.validateQPS)),a=i+o(this,p,wt).call(this,a)+a+s,a=a+o(this,p,vt).call(this,a),o(this,p,rs).call(this);const c=this.parseStringToBytes(a,"");await this.appendToQueue(c,"read-card");let l=0;const h=this;return this.__pinPad__.waiting.statusReadCardWaiting="pending",new Promise((_,f)=>{l=setInterval(()=>{if(h.__pinPad__.waiting.statusReadCardWaiting==="resolved")clearInterval(l),h.__pinPad__.waiting.statusReadCardWaiting=null,_(!0);else if(h.__pinPad__.waiting.statusReadCardWaiting==="rejected"){clearInterval(l),h.__pinPad__.waiting.statusReadCardWaiting=null;const b=h.__pinPad__.operation.last_error;f(b??"Error reading card")}},500)})},Gr=async function(t){return await N(t*1e3)},Xr=async function(t){let e=this.url+this.__pinPad__.constants.uris.consult;return t>1&&this.environment==="production"&&(e=e.replace(this.__pinPad__.constants.urls.production,this.__pinPad__.constants.urls.productionAlternative)),this.__pinPad__.operation.consultDate=new Date().toLocaleDateString("en-GB"),await o(this,p,Yt).call(this,e,{user:this.username.toUpperCase(),pwd:this.password.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),date:this.__pinPad__.operation.consultDate,reference:this.reference})},Jr=async function(t="",e={}){let i=1,s=null;do{i>1&&this.environment==="production"&&(t=t.replace(this.__pinPad__.constants.urls.production,this.__pinPad__.constants.urls.productionAlternative),await o(this,p,Gr).call(this,5)),await o(this,p,pe).call(this);const a=o(this,p,ue).call(this,32),c=o(this,p,he).call(this,this.__pinPad__.config.publicKeyRSA,a),l=await o(this,p,de).call(this,a,JSON.stringify(e));let h=!1;const _=await K.post(t,l,{headers:{"Content-Type":"application/json",data:c||""}}).catch(async f=>{let b=`Error in request, verify internet connection: ${f.status} ${f.message}`;f.response.status>=500&&f.response.status<=599?b="Service Temporarily Unavailable":f.response.status>=400&&f.response.status<=499&&(b="Bad Request"),console.warn(f),s=b;const E=await o(this,p,Xr).call(this,i);E&&E!=="{}"&&!E.includes('"transacciones":""')&&E.includes("nu_operaion")&&(i=5,s="EE32"),h=!0});if(!h)return _.data}while(i++<=3);return s?Promise.reject(s):Promise.reject("Communication error with CDP. IL/MTY")},Qr=function(t){if(kt(t))throw new Error("Number of authorization invalid");if(/^[A-Za-z0-9]+$/g.test(t)!==!0)throw new Error("Number of authorization invalid");if(t.length!==6)throw new Error("Number of authorization invalid");return!0},Zr=function(t){var s,a;const e=this;this.__pinPad__.operation.responseMit._approved=t.response==="approved",this.__pinPad__.operation.responseMit._status=t.response,this.__pinPad__.operation.responseMit._originalToken=t.number_tkn??"",this.__pinPad__.operation.folio=t.foliocpagos,this.__pinPad__.operation.authorization=t.auth;let i=(s=t.cd_response)==null?void 0:s.toUpperCase();return i.toUpperCase()==="0C"||this.__pinPad__.operation.responseMit._approved?i="00":(i!=="Z3"&&i!=="05"||t.cd_error==="92")&&(i="01"),this.__pinPad__.operation.responseMit._cdResponse=i,this.__pinPad__.finishCommand.A=i,this.__pinPad__.finishCommand.B="",this.__pinPad__.finishCommand.C="",this.__pinPad__.finishCommand.D="",this.__pinPad__.finishCommand.E=t.emv_key_date?t.emv_key_date:"",this.__pinPad__.finishCommand.F=t.icc_csn?t.icc_csn:"",this.__pinPad__.finishCommand.G=t.icc_atc?t.icc_atc:"",this.__pinPad__.finishCommand.H=t.icc_arpc?t.icc_arpc:"",this.__pinPad__.finishCommand.I=t.icc_issuer_script?t.icc_issuer_script:"",this.__pinPad__.finishCommand.J=t.authorized_amount?t.authorized_amount:"",this.__pinPad__.finishCommand.K=t.account_balance_1?t.account_balance_1:"",{reference:t.reference,response:t.response,foliocpagos:t.foliocpagos,auth:t.auth,cd_response:i,cd_error:t.cd_error,nb_error:o(a=e,p,Nn).call(a,t.nb_error??""),time:t.time,date:t.date,nb_company:t.nb_company,nb_merchant:t.nb_merchant,nb_street:t.nb_street,cc_type:t.cc_type,tp_operation:t.tp_operation,cc_name:t.cc_name,cc_number:t.cc_number,cc_expmonth:t.cc_expmonth,cc_expyear:t.cc_expyear,amount:t.amount,voucher_comercio:t.voucher_comercio,voucher_cliente:t.voucher_cliente,friendly_response:t.friendly_response,appid:t.appid,appidlabel:t.appidlabel,arqc:t.arqc}},Yr=async function(){var s,a;const t=this;this.__pinPad__.operation.errors=0,this.__pinPad__.operation.ignore.counterSale=!1;const e=this.__pinPad__.operation.onlyMerchant;if(/^[0-9]+$/.test(e)===!1)throw new Error("Invalid merchant");this.__pinPad__.operation.typeOperation="29";let i={error:!1,message:null,approved:!1,object:{}};try{const c=await o(this,p,Un).call(this,this.amount,2);await o(this,p,_e).call(this,{Ambiente:this.environment,Country:this.__pinPad__.config.country,IdBranch:this.__pinPad__.config.idBranch,IdCompany:this.__pinPad__.config.idCompany,pwd:this.password,User:this.username,UserTRX:"userPinpadWeb",EMV:this.__pinPad__.config.read.EMV,ModeloTerminal:this.__pinPad__.about.model,SerieTerminal:this.__pinPad__.about.serial,Contactless:this.__pinPad__.about.supportContactless,Printer:this.__pinPad__.about.printer,VersionTerminal:this.__pinPad__.about.appVersion,TpOperation:this.__pinPad__.operation.typeOperation,Reference:this.reference,Amount:c,Currency:this.__pinPad__.config.currency,Merchant:e,Reverse:this.__pinPad__.config.otherLogin.executeReverse});const l=this.__pinPad__.about.supportContactless&&this.__pinPad__.about.supportContactless!=="0"?"1":"0",h=await o(this,p,Jr).call(this,this.url+this.__pinPad__.constants.uris.sale,{VMCAMEXB:{business:{country:this.__pinPad__.config.country.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),id_company:this.__pinPad__.config.idCompany.toUpperCase(),pwd:this.password.toUpperCase(),user:this.username.toUpperCase()},dcc:{dcc_amount:"0",dcc_status:"0"},transacction:{amount:c,creditcard:{appid:this.__pinPad__.config.read.AppId,appidlabel:this.__pinPad__.config.read.AppIdLabel,arqc:this.__pinPad__.config.read.Arqc,chip:this.__pinPad__.config.read.Chip,chipname:this.__pinPad__.config.read.ChipName,chipnameenc:this.__pinPad__.config.read.ChipNameEnc,contactless:this.__pinPad__.config.read.ReadCTLS,crypto:"4",dukpt:{nb_data:this.__pinPad__.config.read.NB_Data,nb_ksn:this.__pinPad__.config.read.NB_ksn,tp_dukpt:"1"},pin:this.__pinPad__.config.read.PIN,posentrymode:this.__pinPad__.config.read.POSEM,tags:this.__pinPad__.config.read.Tags,type:this.__pinPad__.config.read.Type},currency:this.__pinPad__.config.currency.toUpperCase(),emv:this.__pinPad__.config.read.EMV,merchant:this.__pinPad__.operation.onlyMerchant,modelo_terminal:this.__pinPad__.about.model,reference:this.reference,serie:this.__pinPad__.about.serial,terminal:{display:"1",is_contactless:l,is_mobile:"0",printer:this.__pinPad__.about.printer},tp_operation:this.__pinPad__.operation.typeOperation,tp_resp:this.__pinPad__.operation.typeResponse,usrtransacction:this.username.toUpperCase(),version:this.__pinPad__.constants.appName+this.__pinPad__.constants.appVersion,version_terminal:this.__pinPad__.about.appVersion},geolocation:{latitude:this.__pinPad__.config.latitude,longitude:this.__pinPad__.config.longitude,ip:this.__pinPad__.config.publicIP}}});h.response==="error"&&(i.error=!0,i.message=h.nb_error||"Error in response");const _=o(this,p,Zr).call(this,h);return i.object=_,await o(this,p,ts).call(this,_),i.approved=this.__pinPad__.operation.responseMit._approved,this.__pinPad__.operation.finalResult=_,i}catch(c){throw t.__pinPad__.finishCommand.A="01",t.__pinPad__.finishCommand.B="",t.__pinPad__.finishCommand.C="",t.__pinPad__.finishCommand.D="",t.__pinPad__.finishCommand.E="",t.__pinPad__.finishCommand.F="",t.__pinPad__.finishCommand.G="",t.__pinPad__.finishCommand.H="",t.__pinPad__.finishCommand.I="",t.__pinPad__.finishCommand.J="",t.__pinPad__.finishCommand.K="",await o(a=t,p,ns).call(a,o(s=t,p,Vn).call(s,c)),c}},ts=async function(t){if(this.__pinPad__.config.read.POSEM==="022"||this.__pinPad__.config.read.POSEM==="800"||this.__pinPad__.config.read.ReadCTLS==="1")return this.dispatch("pp:finish-emv",t),!0;const e=this.__pinPad__.constants.FS,i=this.__pinPad__.constants.STX,s=this.__pinPad__.constants.ETX;let a="C93A"+this.__pinPad__.finishCommand.A;a=a+e+"B"+this.__pinPad__.finishCommand.B,a=a+e+"C"+this.__pinPad__.finishCommand.C,a=a+e+"D"+this.__pinPad__.finishCommand.D,a=a+e+"E"+this.__pinPad__.finishCommand.E,a=a+e+"F"+this.__pinPad__.finishCommand.F,a=a+e+"G"+this.__pinPad__.finishCommand.G,a=a+e+"H"+this.__pinPad__.finishCommand.H,a=a+e+"I"+this.__pinPad__.finishCommand.I,a=a+e+"J"+this.__pinPad__.finishCommand.J,a=a+e+"K"+this.__pinPad__.finishCommand.K,a=i+o(this,p,wt).call(this,a)+a+s,a=a+o(this,p,vt).call(this,a);const c=this.parseStringToBytes(a,"");this.__pinPad__.waiting.statusSecondGenerateWaiting="pending",await this.appendToQueue(c,"second-generate");let l=0;const h=this;return new Promise((_,f)=>{l=setInterval(async()=>{var b,E;if(h.__pinPad__.waiting.statusSecondGenerateWaiting==="resolved"){if(clearInterval(l),h.__pinPad__.waiting.statusSecondGenerateWaiting=null,h.__pinPad__.operation.applyReverse){const v=await o(b=h,p,Yt).call(b,h.url+h.__pinPad__.constants.uris.reverse,{VMCAMEXMREVERSO:{business:{id_company:this.__pinPad__.config.idCompany.toUpperCase(),id_branch:this.__pinPad__.config.idBranch.toUpperCase(),country:this.__pinPad__.config.country.toUpperCase(),user:this.username.toUpperCase(),pwd:this.password.toUpperCase()},transacction:{amount:o(this,p,je).call(this,this.amount,2),no_operacion:this.__pinPad__.operation.folio,auth:this.__pinPad__.operation.authorization.toUpperCase(),tracks:"",usrtransacction:this.username.toUpperCase(),crypto:"2",version:this.__pinPad__.constants.appName+this.__pinPad__.constants.appVersion}}}),S=JSON.parse(v);let C;S.response==="approved"?C={message:"Transaction rejected by PinPad."}:C={message:"No communication, please check your report."},h.__pinPad__.operation.ignore.counterSale||(h.dispatch("pp:finish-emv",C),h.__pinPad__.operation.ignore.counterSale=!0)}else h.__pinPad__.operation.ignore.counterSale||(h.dispatch("pp:finish-emv",t),h.__pinPad__.operation.ignore.counterSale=!0);t.cd_error==="92"&&await o(E=h,p,es).call(E,t,a),_(!0)}else h.__pinPad__.waiting.statusSecondGenerateWaiting==="rejected"&&(clearInterval(l),h.__pinPad__.waiting.statusSecondGenerateWaiting=null,f("There is no response from the reader, check that it is connected."))},500)})},es=async function(t,e){this.__pinPad__.operation.ignore.responseGlobal=t,this.__pinPad__.operation.ignore.C93Global=e,this.__pinPad__.operation.ignore.isError92TRX=!0,await o(this,p,Ke).call(this,1,0)},Ln=async function(){if(this.__pinPad__.operation.ignore.isError92TRX=!1,this.__pinPad__.config.read.POSEM==="022"||this.__pinPad__.config.read.POSEM==="800"||this.__pinPad__.config.read.ReadCTLS==="1")this.dispatch("pp:response",this.__pinPad__.operation.ignore.responseGlobal);else{const t=this.parseStringToBytes(this.__pinPad__.operation.ignore.C93Global,"");await this.appendToQueue(t,"code93"),await N(1400),this.dispatch("pp:response",this.__pinPad__.operation.ignore.responseGlobal)}},Vn=function(t){const e={PPE02:"Importe Incorrecto.",A02:"Importe Incorrecto.",PPE03:"No hay respuesta del lector, verifique que se encuentra conectado.",A03:"No hay respuesta del lector, verifique que se encuentra conectado.",PP18:"Sin comunicación, por favor verifique su reporte.",PP24:"Transacción declinada por la PinPad.",A01:"Tarjeta Ilegible.",A04:"No hay planes de pago para esta tarjeta, por favor cambie la tarjeta.",A10:"Operación cancelada por el usuario.",A11:"Proceso cancelado por timeout.",A12:"Lectura errónea de banda/chip.",A13:"Carga de llave fallida.",A14:"Error de lectura de PIN.",A15:"Tarjeta Vencida.",A16:"Problemas al leer el chip.",A17:"Impresora sin Papel.",E17:"Impresora sin Papel.",A21:"Información no almacenada correctamente.",A22:"Tarjeta bloqueada.",A23:"Sin llave de cifrado DUKPT.",A28:"Fallback no soportado.",EE19:"Error de conexión, verifique su reporte.",EE21:"Ha ocurrido un error al procesar su solicitud.",EE22:"Ha ocurrido un error de conexión al servidor.",EE23:"El número de operación no puede ir vacío.",EE24:"El número de operación debe ser de 9 dígitos.",EE25:"El número de operación debe ser numérico.",EE26:"La información enviada al servicio está incompleta.",EE27:"La referencia contiene caracteres inválidos o está vacía.",EE28:"Número de autorización inválido.",EE29:"Importe inválido.",EE30:"La información enviada al servicio no es válida.",EE31:"No fue posible obtener las afiliaciones.",EE32:"Error de conexión, existe una o más transacciones en el servidor , Favor de validar su reporte y en su caso reimprimir el voucher.",EE33:"Error de comunicacion con CDP. IL/MTY",EE20:"La Referencia contiene caracteres inválidos",EE99:"Error código 99."};let i=e[t]?{error:t,message:e[t]}:{error:t,message:"Error desconocido"};return this.dispatch("pp:error",i),i},ns=async function(t){const e=this.__pinPad__.constants.FS,i=this.__pinPad__.constants.STX,s=this.__pinPad__.constants.ETX;let a="C93A"+this.__pinPad__.finishCommand.A;if(a=a+e+"B"+this.__pinPad__.finishCommand.B,a=a+e+"C"+this.__pinPad__.finishCommand.C,a=a+e+"D"+this.__pinPad__.finishCommand.D,a=a+e+"E"+this.__pinPad__.finishCommand.E,a=a+e+"F"+this.__pinPad__.finishCommand.F,a=a+e+"G"+this.__pinPad__.finishCommand.G,a=a+e+"H"+this.__pinPad__.finishCommand.H,a=a+e+"I"+this.__pinPad__.finishCommand.I,a=a+e+"J"+this.__pinPad__.finishCommand.J,a=a+e+"K"+this.__pinPad__.finishCommand.K,a=i+o(this,p,wt).call(this,a)+a+s,a=a+o(this,p,vt).call(this,a),this.__pinPad__.config.read.POSEM==="022"||this.__pinPad__.config.read.POSEM==="800"||this.__pinPad__.config.read.ReadCTLS==="1"){this.dispatch("pp:finish-emv",t);return}const c=this.parseStringToBytes(a,"");await this.appendToQueue(c,"finish-emv-end")},is=async function(t){if(t.cd_estatus=t.cd_estatus?t.cd_estatus:"0",t.cd_estatus!=="1"){this.__pinPad__.operation.ignore.isError92TRX&&await o(this,p,Ln).call(this);return}const e=this.__pinPad__.constants.FS,i=this.__pinPad__.constants.ETX,s=this.__pinPad__.constants.STX,a=t.nb_ksn,c=t.nb_kcv||"",l=t.nb_ipek||"";let h="C92A"+a+e+"B"+c+e+"C"+l;h=s+o(this,p,wt).call(this,h)+h+i,h=h+o(this,p,vt).call(this,h);const _=this.parseStringToBytes(h,"");await this.appendToQueue(_,"dukpt");let f=0;this.__pinPad__.waiting.statuswritingDUKPTWaiting="pending";const b=this;return new Promise((E,v)=>{f=setInterval(async()=>{var S;b.__pinPad__.waiting.statuswritingDUKPTWaiting==="resolved"?(clearInterval(f),b.__pinPad__.waiting.statuswritingDUKPTWaiting=null,this.__pinPad__.operation.ignore.isError92TRX&&await o(S=b,p,Ln).call(S),E(!0)):b.__pinPad__.waiting.statuswritingDUKPTWaiting==="rejected"&&(clearInterval(f),b.__pinPad__.waiting.statuswritingDUKPTWaiting=null,v("Error writing DUKPT keys"))},500)})},rs=function(){this.__pinPad__.config.read.AppId="",this.__pinPad__.config.read.AppIdLabel="",this.__pinPad__.config.read.Arqc="",this.__pinPad__.config.read.ChipName="",this.__pinPad__.config.read.ReadCTLS="",this.__pinPad__.config.read.NB_Data="",this.__pinPad__.config.read.NB_ksn="",this.__pinPad__.config.read.PIN="",this.__pinPad__.config.read.POSEM="",this.__pinPad__.config.read.Tags="",this.__pinPad__.config.read.Type="",this.__pinPad__.config.read.Chip="",this.__pinPad__.config.read.ChipNameEnc="",this.__pinPad__.operation.ignore.error="",this.__pinPad__.operation.ignore.C93Global="",this.__pinPad__.operation.folio="",this.__pinPad__.operation.authorization="",this.__pinPad__.config.tokenizeTRX=!1};class Ic extends xt{constructor({filters:t=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:i=1,device_listen_on_channel:s=1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1}){super({filters:t,config_port:e,no_device:i,device_listen_on_channel:s});Q(this,st);_t(this,"__pinpax__",{server:"DEV",bussinessId:null,encriptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1}});if(this.__internal__.device.type="pinpax",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=3e3,this.__internal__.serial.delay_first_connection=1e3,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
|
|
35
|
-
`,o(this,st,as).call(this),o(this,st,ss).call(this),this.getResponseAsString()}set bussinessId(t){this.__pinpax__.bussinessId=t}get bussinessId(){return this.__pinpax__.bussinessId}set encriptionKey(t){this.__pinpax__.encriptionKey=t}get encriptionKey(){return this.__pinpax__.encriptionKey}set apiKey(t){this.__pinpax__.apiKey=t}get apiKey(){return this.__pinpax__.apiKey}set server(t){this.__pinpax__.server=t}get server(){return this.__pinpax__.server}serialMessage(t){let e=null;try{e=JSON.parse(t)}catch(i){console.error("Error parsing response",i),this.dispatch("serial:message",t);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{status:"started"}),o(this,st,ls).call(this).then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{status:"connected"});break;case"LOGIN":this.dispatch("login",e);break;case"LASTVOUCHER":this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{status:"accepted"});break;case"GETCONFIG":this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{hidden:!1});break;case"PAYMENT_PROCESS":this.dispatch("payment",{status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{status:"insert card"});break;case"CARD_DATA":this.dispatch("payment",{status:"card data",amount:e.amount,cardHolderName:e.cardHolderName,ccMark:e.ccMark,ccType:e.ccType,currency:e.currency,maskedPan:e.maskedPan,readingType:e.readingType});break;case"MERCHANT":this.dispatch("payment",{status:"merchant",afiliation:e.afiliation,alias:e.alias,amountCashBackCommission:e.amountCashBackCommission,currency:e.currency,description:e.description,hasCashBack:e.hasCashBack,limitCashBackAmount:e.limitCashBackAmount,merchant:e.merchant,months:e.months,name:e.name});break;case"TRANSACTION_RESULT":o(this,st,os).call(this,{status:"result",approved:e.approved,acquirer:e.acquirer,address:e.address,amount:e.amount,amountCashback:e.amountCashback,appIDLabel:e.appIDLabel,appId:e.appId,arqc:e.arqc,auth:e.auth,ccBin:e.ccBin,ccExpirationDate:e.ccExpirationDate,ccName:e.ccName,ccNumber:e.ccNumber,ccType:e.ccType,comissionCashback:e.comissionCashback,currency:e.currency,date:e.date,errorCode:e.errorCode,errorDescription:e.errorDescription,folio:e.folio,id:e.id,merchantName:e.merchantName,msiLabel:e.msiLabel,operation:e.operation,pin:e.pin,qps:e.qps,reference:e.reference,response:e.response,source:e.source,sourceLabel:e.sourceLabel,time:e.time});break;case"ERROR":this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{status:"error",response:e}),this.dispatch("payment",{status:"error",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){const e=JSON.stringify({action:"CONNECT"});return this.add0x(this.parseStringToBytes(e,`\r
|
|
35
|
+
`,o(this,st,as).call(this),o(this,st,ss).call(this),this.getResponseAsString()}set bussinessId(t){this.__pinpax__.bussinessId=t}get bussinessId(){return this.__pinpax__.bussinessId}set encriptionKey(t){this.__pinpax__.encriptionKey=t}get encriptionKey(){return this.__pinpax__.encriptionKey}set apiKey(t){this.__pinpax__.apiKey=t}get apiKey(){return this.__pinpax__.apiKey}set server(t){this.__pinpax__.server=t}get server(){return this.__pinpax__.server}serialMessage(t){let e=null;try{e=JSON.parse(t)}catch(i){console.error("Error parsing response",i),this.dispatch("serial:message",t);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{status:"started"}),o(this,st,ls).call(this).then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{status:"connected"});break;case"LOGIN":this.dispatch("login",e);break;case"LASTVOUCHER":this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{status:"accepted"});break;case"GETCONFIG":this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{hidden:!1});break;case"PAYMENT_PROCESS":this.dispatch("payment",{status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{status:"insert card"});break;case"CARD_DATA":this.dispatch("payment",{status:"card data",amount:e.amount,cardHolderName:e.cardHolderName,ccMark:e.ccMark,ccType:e.ccType,currency:e.currency,maskedPan:e.maskedPan,readingType:e.readingType});break;case"MERCHANT":this.dispatch("payment",{status:"merchant",afiliation:e.afiliation,alias:e.alias,amountCashBackCommission:e.amountCashBackCommission,currency:e.currency,description:e.description,hasCashBack:e.hasCashBack,limitCashBackAmount:e.limitCashBackAmount,merchant:e.merchant,months:e.months,name:e.name});break;case"TRANSACTION_RESULT":o(this,st,os).call(this,{status:"result",approved:e.approved,acquirer:e.acquirer,address:e.address,amount:e.amount,amountCashback:e.amountCashback,appIDLabel:e.appIDLabel,appId:e.appId,arqc:e.arqc,auth:e.auth,ccBin:e.ccBin,ccExpirationDate:e.ccExpirationDate,ccName:e.ccName,ccNumber:e.ccNumber,ccType:e.ccType,comissionCashback:e.comissionCashback,currency:e.currency,date:e.date,errorCode:e.errorCode,errorDescription:e.errorDescription,folio:e.folio,id:e.id,merchantName:e.merchantName,msiLabel:e.msiLabel,operation:e.operation,pin:e.pin,qps:e.qps,reference:e.reference,response:e.response,source:e.source,sourceLabel:e.sourceLabel,time:e.time});break;case"ERROR":this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{status:"error",response:e}),this.dispatch("payment",{status:"error",response:e});break;case"REFUND":this.dispatch("refund",{status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){const e=JSON.stringify({action:"CONNECT"});return this.add0x(this.parseStringToBytes(e,`\r
|
|
36
36
|
`))}softReload(){super.softReload(),this.__pinpax__.waiting.sale=!1,this.__pinpax__.waiting.voucher=!1,this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.asyncResponses.voucher=null}async sendCustomCode({code:t=""}={}){if(typeof t!="string")throw new Error("Invalid string");const e=this.parseStringToBytes(t,`\r
|
|
37
37
|
`);await this.appendToQueue(e,"custom")}async connectMessage(){const t=JSON.stringify({action:"CONNECT"}),e=this.parseStringToBytes(t,`\r
|
|
38
38
|
`);await this.appendToQueue(e,"connect:message")}async login(){if(!this.apiKey||!this.bussinessId||!this.encriptionKey||!this.server)throw new Error("Invalid data to login check apiKey, bussinessId, encriptionKey, server");const t=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,bussiness_id:this.__pinpax__.bussinessId,encription_key:this.__pinpax__.encriptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(t,`\r
|
|
@@ -45,7 +45,8 @@ version: 2.9.0
|
|
|
45
45
|
`);await this.appendToQueue(e,"get-config")}async hideButtons(){const t=JSON.stringify({action:"HIDEBUTTONS"}),e=this.parseStringToBytes(t,`\r
|
|
46
46
|
`);await this.appendToQueue(e,"hide-buttons")}async showButtons(){const t=JSON.stringify({action:"SHOWBUTTONS"}),e=this.parseStringToBytes(t,`\r
|
|
47
47
|
`);await this.appendToQueue(e,"show-buttons")}async demo(){console.warn("RUNNING DEMO APP BE CAREFUL");const t=JSON.stringify({action:"DEMO"}),e=this.parseStringToBytes(t,`\r
|
|
48
|
-
`);await this.appendToQueue(e,"demo")}}st=new WeakSet,ss=function(){k.add(this)},as=function(){const t=["buttons-status","init-app","connectMessage","login","voucher","info","keep-alive","reset-app","get-config","payment","error"];for(const e of t)this.serialRegisterAvailableListener(e)},os=function(t){this.dispatch("payment",t),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=t)},cs=function(t){return/^[A-Z-a-z0-9_\s]+$/g.test(t)},qn=async function(){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.queue.length===0)return!0;const t=this;return new Promise(e=>{let i=setInterval(()=>{t.queue.length===0&&(clearInterval(i),e(!0))},500)})},ls=async function(){await this.connectMessage(),await this.login(),await this.hideButtons()};class Oc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1,device_listen_on_port:s=1,type:a="esplus",support_cart:c=!0}={}){super({filters:t,config_port:e,no_device:i,device_listen_on_port:s});Q(this,g);_t(this,"__device",{type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}});if(this.__internal__.device.type="jofemar",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=a,this.supportCart=c,o(this,g,hs).call(this),o(this,g,ds).call(this),o(this,g,us).call(this)}set startChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid start channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=e}set endChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid end channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=e}set listenOnChannel(t){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t),this.__internal__.device.hex_number=(128+t).toString(16)}set listenOnPort(t){this.listenOnChannel=t}set deviceType(t){if(typeof t!="string")throw new Error("Invalid device type, must be a string");this.__device.type=t}set supportCart(t){if(typeof t!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=t}serialJofemarMakeBytes(t){let e=this.hexToDec(this.sumHex(t)),i=this.calcCheckSums(e.toString());for(let s=0;s<2;s++)t.push(this.hexMaker(i[s]));return t.push("03"),this.add0x(t)}calcCheckSums(t){t=this.add0x([this.decToHex(parseInt(t).toString())]);let e=[];return e.push((t&255|240).toString(16).toUpperCase()),e.push((t&255|15).toString(16).toUpperCase()),e}serialSetConnectionConstant(t=1){let e=["02","30","30",(128+t).toString(16),"53","FF","FF"],i=[];return e.forEach(s=>{i.push(this.hexMaker(s))}),this.serialJofemarMakeBytes(i)}serialMessage(t){let i={code:t,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(t[0]){case"02":i=o(this,g,Us).call(this,t,i,128);break;case"06":i=o(this,g,Ls).call(this,t,i);break;case"15":i.name="Checksum error",i.description="The calculated checksum does not match the received checksum",i.no_code=38,o(this,g,tt).call(this);break;default:i.name="unknown",i.description="The message received is unknown",i.no_code=404;break}this.dispatch("serial:message",i)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:t=1,cart:e=!1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>130)throw new Error("Invalid selection");const{channel:i,tray:s}=o(this,g,Vs).call(this,t);this.__internal__.dispense.backup_dispense={selection:t,cart:e,channel:i,tray:s};let c=["02","30","30",this.__internal__.device.hex_number,"56",s,i];e&&(c[4]="4D"),c=o(this,g,We).call(this,c);let l;do l=await this.internalDispense(c),o(this,g,qs).call(this),l.error==="elevator-locked"?await o(this,g,ps).call(this):l.error==="no-response"&&await N(1e3);while(["elevator-locked","no-response"].includes(l.error));return this.__internal__.dispense.backup_dispense={},l}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(t=>t.type!=="status"))}async endDispense(){let e=["02","30","30",this.__internal__.device.hex_number,"4D","80","80"];return e=o(this,g,We).call(this,e),await this.internalDispense(e)}async collect(){const t=["02","30","30","81","4E","FF","FF"];return await o(this,g,lt).call(this,t,"collect")}async resetSoldOutErrors(){return await o(this,g,fe).call(this,"80")}async resetWaitingProductRemovedError(){return await o(this,g,fe).call(this,"81")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(o(this,g,Hn).call(this),await o(this,g,fe).call(this,"FF")):new Promise(t=>{const e=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(e),await o(this,g,fe).call(this,"FF"),o(this,g,Hn).call(this),t(!0))},100)})}async resetAllErrors(){return await this.resetSoldOutErrors(),await N(100),await this.resetWaitingProductRemovedError(),await N(100),await this.resetMachineErrors()}async status(){const t=["02","30","30","81","53","FF","FF"];return await o(this,g,lt).call(this,t,"status")}async lightsOn(){return await o(this,g,jn).call(this,"81")}async lightsOff(){return await o(this,g,jn).call(this,"80")}async program(t,e){const i=["02","30","30","81","50",t,e];return await o(this,g,lt).call(this,i,"program")}async programDisplayLanguage({language:t="spanish"}={}){const e={spanish:"30",english:"31",french:"32"};if(!e[t])throw new Error("Invalid language");return await this.program("49",e[t])}async programBeeper({enable:t=!0}={}){const e=t?"31":"30";return await this.program("5A",e)}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.program("54","80")}async programDisableThermometer(){return await this.programDisableWorkingTemperature()}async programWorkingTemperature({degrees:t=.5}={}){t=parseFloat(t);const e=this.__device.type==="iceplus"?6.5:32,i=this.__device.type==="iceplus"?-25:.5;if(isNaN(t)||t<i||t>e||t%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let s=t*2+128;return this.__device.type==="iceplus"&&(s+=51),s=Math.ceil(s),await this.program("54",s.toString(16))}async programIsolationTray({tray:t=0}={}){if(t=parseInt(t),isNaN(t)||t<0||t>12)throw new Error("Invalid tray, valid range is 0 to 12");const e=t===0?"80":(t+139).toString(16);return this.program("42",e)}async programTimeToStandbyAfterCollect({seconds:t=15}={}){if(t=parseInt(t),isNaN(t)||t<15||t>120)throw new Error("Invalid seconds, valid range is 15 to 120");const e=(128+t).toString(16);return await this.program("46",e)}async programTimeToStandbyWithoutCollect({minutes:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>10)throw new Error("Invalid minutes, valid range is 1 to 10");const e=(128+t).toString(16);return await this.program("48",e)}async programElevatorSpeed({speed:t="high"}={}){const e={high:"31",low:"30"};if(!e[t])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return await this.program("76",e[t])}async programTemperatureExpiration({enable:t=!1}={}){const e=t?"31":"30";return await this.program("63",e)}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid address, valid range is 1 to 31");const e=(128+t).toString(16);return await this.program("64",e)}async programTemperatureBeforeExpiration({degrees:t=.5}={}){if(t=parseFloat(t),isNaN(t)||t<.5||t>30||t%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const e=(128+t*2).toString(16);return await this.program("65",e)}async programTimeBeforeExpirationByTemperature({minutes:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>120)throw new Error("Invalid minutes, valid range is 1 to 120");const e=(128+t).toString(16);return await this.program("66",e)}async programTemperatureScale({scale:t="c"}={}){const e={c:"43",f:"46"};if(!e[t])throw new Error("Invalid scale, valid scales are 'c' for celsius and 'f' for fahrenheit");return await this.program("67",e[t])}async programVoltageEngine({selection:t=1,voltage:e=5}={}){if(e=parseFloat(e),t=parseInt(t),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(e)||e<5||e>9.5||e%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const i=109+t,a=(128+(e-5)*2).toString(16),c=["02","30","30","81","47",i,a];return await o(this,g,lt).call(this,c,"voltage-engine")}async programPushOverProducts({selection:t=1,enable:e=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);const a=["02","30","30","81","4F",109+t,e?"31":"30"];return await o(this,g,lt).call(this,a,"push-over-products")}async programChannelRunningAfterDispense({selection:t=1,seconds:e=0}={}){if(t=parseInt(t),e=parseFloat(e),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(e)||e<0||e>10||e%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const i=109+t;e=e.toFixed(1);const s=128+e*10,a=["02","30","30","81","45",i,s];return await o(this,g,lt).call(this,a,"channel-running-after-dispense")}async checkData(t,e="FF"){const i=["02","30","30","81","43",t,e];return await o(this,g,lt).call(this,i,"check-data")}async getDisplayLanguage(){return await this.checkData("49")}async getBeeper(){return await this.checkData("5A")}async getWorkingTemperature(){return await this.checkData("54")}async getIsolationTray(){return await this.checkData("42")}async getProgramVersion(){return await this.checkData("50")}async getFaults(){return await this.checkData("53")}async getMachineId(){return await this.checkData("4E")}async getCurrentTemperature(){return await this.checkData("74")}async getTimeToStandbyAfterCollect(){return await this.checkData("46")}async getTimeToStandbyWithoutCollect(){return await this.checkData("48")}async getElevatorSpeed(){return await this.checkData("76")}async getTemperatureExpiration(){return await this.checkData("63")}async getTemperatureBeforeExpiration(){return await this.checkData("65")}async getTimeBeforeExpirationByTemperature(){return await this.checkData("66")}async getTemperatureScale(){return await this.checkData("67")}async getClockRegisters(){return await this.checkData("72")}async getMachineActivity(){return await this.checkData("41")}async getVoltageEngine({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("47",e)}async getChannelPresence({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("43",e)}async getPushOverProducts({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("4F",e)}async getChannelRunningAfterDispense({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("45",e)}async setDisplayStandbyMessage({message:t=""}={}){t=t.substring(0,32);const e=o(this,g,Ge).call(this,t);return await o(this,g,ze).call(this,"80",e)}async setDisplayMessageTemporarily({message:t="",seconds:e=1}){if(t=t.substring(0,32),e=parseInt(e),isNaN(e)||e<1||e>125)throw new Error("Invalid seconds, valid range is 1 to 125");const i=o(this,g,Ge).call(this,t),s=(128+e).toString(16);return await o(this,g,ze).call(this,s,i)}async setDisplayMessageUnlimited({message:t=""}){t=t.substring(0,32);const e=o(this,g,Ge).call(this,t);return await o(this,g,ze).call(this,"FF",e)}async programClock({date:t=new Date}={}){if(!(t instanceof Date))throw new Error("Invalid date, must be an instance of Date");const e=["02","30","30","81","72",...o(this,g,js).call(this,t)];return await o(this,g,lt).call(this,e,"clock")}async eventsConfig({event:t=null,enable:e=!0}={}){if(t===null)throw new Error("Invalid event");const s=["02","30","30","81","41",t,e?"31":"30"];return await o(this,g,lt).call(this,s,"events-config")}async eventEnable({event:t=null}={}){if(t===null)throw new Error("Invalid event");const e=parseInt(t,16);if(isNaN(e)||e<38||e>100)throw new Error("Invalid event");return await this.eventsConfig({event:t,enable:!0})}async eventDisable({event:t=null}={}){if(t===null)throw new Error("Invalid event");const e=parseInt(t,16);if(isNaN(e)||e<38||e>100)throw new Error("Invalid event");return await this.eventsConfig({event:t,enable:!1})}async sendCustomCode({code:t=[]}={}){if(t.length<5)throw new Error("Invalid code, minimum length is 5");return await o(this,g,lt).call(this,t,"custom")}async assignChannels(){const t=this.__device.channels.verification.start,e=this.__device.channels.verification.end;if(t>e)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let i=t;i<=e;i++)this.__device.channels.verification.current=i,await this.getChannelPresence({selection:i});return new Promise(i=>{let s=setInterval(()=>{this.__device.channels.verification.channels.length===e-t+1&&(clearInterval(s),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),i(!0))},500)})}}g=new WeakSet,hs=function(){const t=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channel:status","machine:status"];for(const e of t)this.serialRegisterAvailableListener(e)},us=function(){this.on("internal:dispense:running",o(this,g,Hs).bind(this))},ds=function(){k.add(this)},lt=function(t,e){return t[3]=this.__internal__.device.hex_number,this.appendToQueue(o(this,g,We).call(this,t),e)},We=function(t){let e=this.hexToDec(this.sumHex(t)),i=this.calcCheckSums(e.toString());for(let s=0;s<2;s++)t.push(this.hexMaker(i[s]));return t.push("03"),t},ps=async function(){if(this.__internal__.dispense.elevator.locking_interval)return;this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await N(500));const t=this;return this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(e=>{t.__internal__.dispense.elevator.locking_interval=setInterval(()=>{t.dispatch("dispensing:withdrawal",{elevator:!0,seconds:t.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),t.__internal__.dispense.elevator.locking_time-=1,t.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(t.__internal__.dispense.elevator.locking_interval),t.__internal__.dispense.elevator.locking_interval=0,e(!0))},1e3)})},_s=function(t,e){return e.name="ok",e.description="The last command was executed successfully",e.no_code=1,this.dispatch("command-executed",e),e},fs=function(t,e){e.additional={hex:t,dec:this.hexToDec(t),ascii:null};const i={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"};return e.additional.ascii=i[t]??null,e.name="Key pressed",e.description=`The key ${e.additional.ascii} was pressed`,e.no_code=2,this.dispatch("keyboard:pressed",e.additional),e},gs=function(t,e){return e.additional={open:!1},e.no_code=3,t==="4f"?(e.name="door open",e.description="The door was opened",e.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",e.additional)):t==="43"?(e.name="door close",e.description="The door was closed",e.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",e.additional)):(e.name="door event",e.description="The door event received is unknown",this.dispatch("door:event",{open:e.additional.open,message:e})),e},ys=function(t,e){e.no_code=404;let i=t[5]??null;return i&&this.listenOnChannel>1&&(i=this.hexToDec(i)-this.listenOnChannel+1,i=this.decToHex(i)),i&&(i==="FD"?(e.no_code=4,e.name="channel disconnected",e.description="The channel is disconnected",e.additional={active:!1}):i==="FC"?(e.no_code=5,e.name="channel connected",e.description="The channel is connected",e.additional={active:!0}):(e.no_code=6,e.name="channel sold out",e.description="The channel is empty",e.additional={active:!0}),this.__device.channels.verification.running&&(this.__device.channels.verification.channels.push({selection:this.__device.channels.verification.current,active:e.additional.active}),e.additional.selection=this.__device.channels.verification.current),this.dispatch("channel:status",e.additional)),e},bs=function(t,e){e.no_code=39,e.name="Program version";const i=t.slice(4,12),s=i.map(a=>String.fromCharCode(this.hexToDec(a))).join("");return e.additional={version:s,hex:i},e.description=`The program version is ${s}`,this.dispatch("program:version",e.additional),e},ms=function(t,e){e.no_code=39,e.name="Machine faults",e.description="No faults detected",e.additional={no_faults:0,faults:[]};const i=t.slice(4,-3);if(i.length>1&&i[0]!=="30"){e.description="Machine has faults";const s={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const a of i)s[a]&&(e.additional.faults.push(s[a]),e.additional.no_faults++)}return this.dispatch("machine:faults",e.additional),e},ws=function(t,e){e.no_code=40,e.name="Clock registers",e.description="Clock registers";const i=t.slice(4,-3),s=i.map(v=>String.fromCharCode(this.hexToDec(v))).join(""),[a,c]=s.split(" "),[l,h]=a.split(":"),[_,f,b]=c.split("-"),E=new Date(2e3+parseInt(b),parseInt(f)-1,parseInt(_),parseInt(l),parseInt(h));return e.additional={day:_,month:f,year:b,hours:l,minutes:h,formatted:s,date:E,hex:i},this.dispatch("clock:registers",e.additional),e},vs=function(t,e){e.no_code=41,e.name="Machine activity",e.description="Events from read machine activity";const i=String.fromCharCode(this.hexToDec(t[4]));if(i!=="0"){const s=t.slice(5,-3);if(i==="T"&&s.length===4){const a=String.fromCharCode(this.hexToDec(s[0])),c=String.fromCharCode(this.hexToDec(s[1])),l=String.fromCharCode(this.hexToDec(s[3]));e.additional={ascii:i,type:"DU.d",dozens:a,units:c,decimals:l,time:parseFloat(`${a}${c}.${l}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(i)&&s.length===3){const a=String.fromCharCode(this.hexToDec(s[0])),c=String.fromCharCode(this.hexToDec(s[1])),l=String.fromCharCode(this.hexToDec(s[2])),h=parseInt(`${a}${c}${l}`),_={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};e.additional={type:"HDU",hundreds:a,dozens:c,decimals:l,channel:h,selection:h-109,ascii:i,meaning:_[i]??"Unknown"}}else if(s.length===13){const a=s.map(S=>String.fromCharCode(this.hexToDec(S))).join(""),c=parseInt(a.slice(0,2)),l=parseInt(a.slice(2,4)),h=parseInt(a.slice(4,6)),_=parseInt(a.slice(7,9)),f=parseInt(a.slice(9,11))-1,b=2e3+parseInt(a.slice(11,13)),E=new Date(b,f,_,c,l,h),v={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};e.additional={type:"hhmmssWddMMAA",date:E,hex:s,formatted:E.toLocaleString(),ascii:i,meaning:v[i]??"Unknown"}}}return this.dispatch("machine:activity",e.additional),e},Es=function(t,e){const i={30:"Spanish",31:"English",32:"French"};return e.no_code=42,e.name="Language",e.description=`The language is ${i[t]??"unknown"}`,e.additional={hex:t,language:i[t]??"unknown"},this.dispatch("check:language",e.additional),e},Ps=function(t,e){return e.no_code=43,e.name="Beeper",e.description=`The beeper is ${t==="30"?"on":"off"}`,e.additional={hex:t,beeper:t==="30"},this.dispatch("check:beeper",e.additional),e},Ts=function(t,e){e.no_code=44,e.name="Isolation tray",e.description="Isolation tray";const i=this.hexToDec(t)-139;return e.additional={hex:t,tray:i},this.dispatch("check:isolation-tray",e.additional),e},Cs=function(t,e){e.no_code=45,e.name="Engine voltage",e.description="Engine voltage";const i=(this.hexToDec(t)-128)/2+5;return e.additional={hex:t,voltage:i},this.dispatch("check:engine-voltage",e.additional),e},Ss=function(t,e){e.no_code=46,e.name="Push over",e.description="Push over";const i=t==="30";return e.additional={hex:t,push:i},this.dispatch("check:push-over",e.additional),e},ks=function(t,e){e.no_code=47,e.name="Extractor after dispense",e.description="Extractor after dispense";const i=(this.hexToDec(t)-128)/10;return e.additional={hex:t,seconds:i},this.dispatch("check:extractor-after-dispense",e.additional),e},xs=function(t,e){e.no_code=48,e.name="Standby after collect",e.description="Time to standby after collect product";const i=this.hexToDec(t)-128;return e.additional={hex:t,seconds:i},this.dispatch("check:standby-after-collect",e.additional),e},As=function(t,e){e.no_code=49,e.name="Standby without collect",e.description="Time to standby when product delivery is not collected";const i=this.hexToDec(t)-128;return e.additional={hex:t,minutes:i},this.dispatch("check:standby-without-collect",e.additional),e},Ds=function(t,e){e.no_code=50,e.name="Elevator speed",e.description="Elevator speed";const i=t==="30"?"low":"high";return e.additional={hex:t,speed:i},this.dispatch("check:elevator-speed",e.additional),e},Rs=function(t,e){e.no_code=51,e.name="Temperature expiration",e.description="Temperature expiration";const i=t==="31";return e.additional={hex:t,enabled:i},this.dispatch("check:expiration-by-temperature",e.additional),e},Is=function(t,e){e.no_code=52,e.name="Temperature before expiration",e.description="Temperature before expiration";const i=(this.hexToDec(t)-128)/2;return e.additional={hex:t,temperature:i},this.dispatch("check:temperature-before-expiration",e.additional),e},Os=function(t,e){e.no_code=53,e.name="Time before expiration",e.description="Time before expiration";const i=this.hexToDec(t)-128;return e.additional={hex:t,minutes:i},this.dispatch("check:expiration-after",e.additional),e},Ns=function(t,e){e.no_code=54,e.name="Temperature scale",e.description="Temperature scale";const i=t==="43"?"Celsius":"Fahrenheit";return e.additional={hex:t,scale:i},this.dispatch("check:temperature-scale",e.additional),e},Bs=function(t,e){return e.no_code=54,e.name="Machine ID",e.description="Machine ID",e.additional={hex:t[4],full_hex:t},this.dispatch("check:machine-id",e.additional),e},Ms=function(t,e){return e.no_code=7,e.name="working temperature",e.description=`The working temperature is ${t}`,e.additional={hex:t,temperature:{traditional:(this.hexToDec(t)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(t)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",e.additional),e},Fs=function(t,e){return e.no_code=8,e.name="current temperature",e.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:t[7]==="2e"?".":null,degrees:t[9]==="7f"?"°":null,error:null},t[4]==="2b"?e.additional.sign=t[4]="+":["2e","2d"].includes(t[4])?e.additional.sign=t[4]="-":t[4]==="20"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[5])>=48&&this.hexToDec(t[5])<=57?e.additional.tens=this.hexToDec(t[5])-48:t[5]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[6])>=48&&this.hexToDec(t[6])<=57?e.additional.units=this.hexToDec(t[6])-48:t[6]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[8])>=48&&this.hexToDec(t[8])<=57?e.additional.decimals=this.hexToDec(t[8])-48:t[8]==="2a"&&(e.additional.error="Error in thermometer"),t[10]==="43"?e.additional.type_degrees="C":t[10]==="46"&&(e.additional.type_degrees="F"),e.additional.error==="Error in thermometer"?(e.additional.formatted="Error in thermometer",e.description="The current temperature cannot be read because there is an error in the thermometer"):(e.additional.formatted=(e.additional.sign??"")+(e.additional.tens??"")+(e.additional.units??"")+(e.additional.decimal_point??"")+(e.additional.decimals??"")+(e.additional.degrees??"")+(e.additional.type_degrees??""),e.description=`The current temperature is ${e.additional.formatted}`),this.dispatch("temperature:current",e.additional),e},Us=function(t,e,i=128){if(t[1]&&(e.additional.machine.hex=t[1],e.additional.machine.dec=this.hexToDec(t[1])-i),!(t[1]&&t[2]))e=o(this,g,_s).call(this,t,e);else switch(t[2]){case"54":e.request="--automatic",e=o(this,g,fs).call(this,t[3],e);break;case"50":e.request="--automatic",e=o(this,g,gs).call(this,t[3],e);break;case"43":switch(e.request="check-data",t[3]){case"41":e=o(this,g,vs).call(this,t,e);break;case"43":e.request="channel-status",e=o(this,g,ys).call(this,t,e);break;case"50":e=o(this,g,bs).call(this,t,e);break;case"53":e=o(this,g,ms).call(this,t,e);break;case"54":e.request="working-temperature",e=o(this,g,Ms).call(this,t[4],e);break;case"72":e=o(this,g,ws).call(this,t,e);break;case"74":e.request="current-temperature",e=o(this,g,Fs).call(this,t,e);break;case"49":e=o(this,g,Es).call(this,t[4],e);break;case"5a":e=o(this,g,Ps).call(this,t[4],e);break;case"42":e=o(this,g,Ts).call(this,t[4],e);break;case"47":e=o(this,g,Cs).call(this,t[4],e);break;case"4e":e=o(this,g,Bs).call(this,t,e);break;case"4f":e=o(this,g,Ss).call(this,t[4],e);break;case"45":e=o(this,g,ks).call(this,t[4],e);break;case"46":e=o(this,g,xs).call(this,t[4],e);break;case"48":e=o(this,g,As).call(this,t[4],e);break;case"76":e=o(this,g,Ds).call(this,t[4],e);break;case"63":e=o(this,g,Rs).call(this,t[4],e);break;case"65":e=o(this,g,Is).call(this,t[4],e);break;case"66":e=o(this,g,Os).call(this,t[4],e);break;case"67":e=o(this,g,Ns).call(this,t[4],e);break}break}return e},gt=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},tt=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)},$e=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")},et=function({type:t=null,severity:e="low"}={}){this.dispatch("jofemar:warning",{type:t,severity:e})},Et=function({type:t=null,severity:e="high"}={}){this.dispatch("jofemar:error",{type:t,severity:e})},Ls=function(t,e){if(e.request="status",t[1]&&!t[2]){switch(t[1]){case"30":e.name="Machine ready",e.description="The machine is ready for instructions",e.no_code=9,o(this,g,gt).call(this);break;case"31":e.name="Machine busy",e.description="The machine is busy right now",e.no_code=10;break;case"32":e.name="Invalid tray",e.description="The tray requested is invalid",e.no_code=11,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"invalid-tray"});break;case"33":e.name="Invalid channel",e.description="The channel requested is invalid",e.no_code=12,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"invalid-channel"});break;case"34":e.name="Empty channel",e.description="The channel requested is empty",e.no_code=13,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"empty-channel"});break;case"35":e.name="Jam",e.description="Jam in elevator engine",e.no_code=14,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"jam"});break;case"36":e.name="Malfunction",e.description="Malfunction in the elevator belt or product detector",e.no_code=15,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"malfunction"});break;case"37":e.name="Photo transistors",e.description="Failure in one of the photo transistors in the cabinet",e.no_code=16,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"photo-transistors"});break;case"38":e.name="Without channels",e.description="No channels detected",e.no_code=17,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"without-channels"});break;case"39":e.name="Product detector fault",e.description="Product detector fault",e.no_code=18,o(this,g,$e).call(this),o(this,g,et).call(this,{type:"fault-product-detector"});break;case"41":e.name="Fault in 485 BUS",e.description="Machine display is disconnected",e.no_code=19,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"display-disconnected"});break;case"42":e.name="Product under elevator",e.description="Product alarm under elevator",e.no_code=20,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"product-under-elevator"});break;case"43":e.name="Error when elevator approaching to a position",e.description="Error when elevator approaching to a position",e.no_code=21,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"error-approaching-position",severity:"high"});break;case"44":e.name="Fault in keyboard",e.description="Fault in keyboard",e.no_code=22,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"fault-keyboard"});break;case"45":e.name="Eeprom writing error",e.description="Eeprom writing error",e.no_code=23,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"eeprom-writing-error",severity:"critical"});break;case"46":e.name="Fault communicating with temperature control",e.description="Fault communicating with temperature control",e.no_code=24,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"fault-temperature-control"});break;case"47":e.name="Thermometer disconnected",e.description="The thermometer is disconnected",e.no_code=25,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-disconnected"});break;case"48":e.name="Thermometer programming lost",e.description="Thermometer programming lost",e.no_code=26,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-programming-lost"});break;case"49":e.name="Thermometer faulty",e.description="Thermometer faulty",e.no_code=27,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-faulty"});break;case"4a":e.name="Channels power consumption detector faulty",e.description="Channels power consumption detector faulty",e.no_code=28,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":e.name="Elevator does not find channel or tray",e.description="Elevator does not find channel or tray",e.no_code=29,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"elevator-not-find-channel-tray"});break;case"4c":e.name="Elevator does not find delivery product position",e.description="Elevator does not find delivery product position",e.no_code=30,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"elevator-not-find-delivery-position"});break;case"4d":e.name="Interior of elevator blocked",e.description="Interior of elevator blocked",e.no_code=31,o(this,g,$e).call(this),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),o(this,g,Et).call(this,{type:"interior-elevator-blocked",severity:"low"});break;case"4e":e.name="Error in tester of product detector",e.description="Error in tester of product detector",e.no_code=32,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"error-tester-product-detector"});break;case"4f":e.name="Waiting for product to be removed",e.description="Waiting for product to be removed",e.no_code=33,o(this,g,$e).call(this);break;case"50":e.name="Product expired by temperature reasons",e.description="Product expired by temperature reasons",e.no_code=34,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"product-expired-temperature"});break;case"51":e.name="Automatic door faulty",e.description="Automatic door faulty",e.no_code=35,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(e.name="Product is expired",e.description="Product is expired",e.additional={nsf_alarm:1},t[1]){case"5a":e.additional.nsf_alarm=2;break;case"61":e.additional.nsf_alarm=3;break;case"62":e.additional.nsf_alarm=4;break;case"63":e.additional.nsf_alarm=5;break}e.no_code=36,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"product-expired"});break;case"64":e.name="Product detector didn't change during its verification test",e.description="Product detector didn't change during its verification test",e.no_code=37,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"automatic-door-faulty"});break}this.dispatch("machine:status",e)}else e.name="executed",e.description="The last command was executed successfully",e.no_code=8,!t[1]&&this.__internal__.dispense.dispensing&&o(this,g,tt).call(this);return e},Vs=function(t){if(t=parseInt(t)+109,t=t.toString(),t.length!==3)throw new Error("Invalid selection");const e=(parseInt(t.substring(0,2))+128).toString(16).padStart(2,"0");return{channel:(parseInt(t.substring(2,3))+128).toString(16).padStart(2,"0"),tray:e}},qs=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0},Hs=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval);const t=this;t.__internal__.dispense.timeout=setTimeout(()=>{t.__internal__.dispense.interval=setInterval(()=>{t.status().then(()=>{})},t.__internal__.dispense.interval_time)},t.__internal__.dispense.timeout_time)},fe=async function(t){const e=["02","30","30","81","52",t,"FF"];return await o(this,g,lt).call(this,e,"reset")},Hn=function(){const t=this.__device.type==="iceplus"?Ze(40):Ze(25),e=new Date,i=1e3*t+e.getTime(),s=new Date(i);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:t,started_at:e,finished_at:s})},jn=async function(t){const e=["02","30","30","81","4C",t,"FF"];return await o(this,g,lt).call(this,e,"lights")},ze=async function(t="80",e=[]){const i=["02","30","30","81","44",t,...e];return await o(this,g,lt).call(this,i,"display")},Ge=function(t=""){t=t.padEnd(32," ");const e=[];for(let i=0;i<32;i++)e.push(t.charCodeAt(i).toString(16));return e},js=function(t){if(!(t instanceof Date))throw new Error("Invalid date, must be an instance of Date");const e=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0"),a=(t.getMonth()+1).toString().padStart(2,"0"),c=t.getFullYear().toString().substring(2,4),l=`${e}:${i} ${s}-${a}-${c}`,h=[];for(let _=0;_<14;_++)h.push(l.charCodeAt(_).toString(16));return h};class Nc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});Q(this,w);_t(this,"__coin_purse",{available:!0});_t(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});_t(this,"__sale",{price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}});_t(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});_t(this,"coins",{tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0});_t(this,"banknotes",{stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0});_t(this,"card_reader",{available:!1,max_pre_credit:0});Q(this,Jt,!1);Q(this,Ut,0);Q(this,Qt,0);if(this.__internal__.device.type="boardroid",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},o(this,w,Ks).call(this),o(this,w,Ws).call(this)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(t){this.__banknote_purse.isRecycler=t}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(t){this.__banknote_purse.recycler.ict=t}set banknoteICT(t){if(![20,50,100,200,500].includes(t))throw new Error(`Invalid banknote value: ${t}`);t=[20,50,100,200,500].indexOf(t),this.__banknote_purse.recycler.banknote=t}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(t){if(typeof t!="boolean")throw new Error(`Invalid value: ${t}`);this.__coin_purse.available=t}set price(t){let e=parseFloat(t);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}serialBoardroidSumHex(t){let e=0;return t.forEach((i,s)=>{s!==0&&s!==11&&(e+=parseInt(i,16))}),e.toString(16).toUpperCase()}serialMessage(t){let e={code:t,name:null,description:null,request:null,no_code:0};const i=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(t[1]){case i:e.request="connect",e=o(this,w,zs).call(this,e);break;case"a0":e.request="--automatic",e=o(this,w,ta).call(this,t,e);break;case"b0":e.request="--automatic",e=o(this,w,ea).call(this,t,e);break;case"d0":e.request="coin-purse:config",e=o(this,w,na).call(this,t[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=o(this,w,ia).call(this,t,e);break;case"d2":e.request="coin-purse:read-tubes",e=o(this,w,ra).call(this,t,e);break;case"d3":e.request="banknote-purse:read-recycler",e=o(this,w,sa).call(this,t,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=o(this,w,aa).call(this,t[2],e);break;case"d5":e.request="banknote-purse:dispense",e=o(this,w,oa).call(this,t,e);break;case"d6":e.request="coin-purse:dispense",e=o(this,w,ca).call(this,t,e);break;case"d7":e.request="dispense",e=o(this,w,la).call(this,t[5],e);break;case"d8":e.request="--automatic",e=o(this,w,ha).call(this,t[13],e);break;case"d9":e.request="status:temperature",e=o(this,w,ua).call(this,t,e);break;case"da":e.request="status:relay",e=o(this,w,da).call(this,t[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",o(this,w,pa).call(this,t,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){let e=["F1","06","00","00","00","00","00","00","00","00","F2","F8"];return e[1]=this.hexMaker(this.decToHex((5+t).toString())),e[11]=this.serialBoardroidSumHex(e),this.add0x(e)}async coinPurseConfigure({enable:t=!1,high:e="FF",low:i="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");const a=["F1","C1",t?"01":"00",e,i,"00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,a,"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:t=0,$_1:e=0,$_2:i=0,$_5:s=0,$_10:a=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");if([t,e,i,s,a].some(l=>isNaN(l)||typeof l=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&i<1&&s<1&&a<1)throw new Error("No coins to dispense");[t,e,i,s,a]=[this.decToHex(t),this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a)];let c=["F1","C6",t,e,i,s,a,"00","00","00","F2","00"];await o(this,w,ht).call(this,c,"coin-purse:dispense")}async coinPurseReadTubes(){const t=["F1","C2","00","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"coin-purse:read-tubes")}async banknotePurseConfigure({enable:t=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let i;return o(this,w,Xe).call(this)?i=o(this,w,_a).call(this,{enable:t,scrow:e}):i=o(this,w,fa).call(this,{enable:t,scrow:e}),await o(this,w,ht).call(this,i,"banknote-purse:config")}async banknotePurseDispense({$_20:t=0,$_50:e=0,$_100:i=0,$_200:s=0,$_500:a=0,$_1000:c=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let l;if(o(this,w,Xe).call(this)){const h=[t,e,i,s,a];l=o(this,w,ga).call(this,h[this.__banknote_purse.recycler.banknote])}else l=o(this,w,ya).call(this,{$_20:t,$_50:e,$_100:i,$_200:s,$_500:a,$_1000:c});await o(this,w,ht).call(this,l,"banknote-purse:dispense")}async banknotePurseEnable({scrow:t=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:t})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","01","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","00","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:t=null,$_20:e=null,$_50:i=null,$_100:s=null,$_200:a=null,$_500:c=null,$_1000:l=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(t===null||e===null||i===null||s===null||a===null||c===null||l===null)throw new Error("One of the values is not defined");const h=["F1","C8",this.decToHex(t),"00",this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a),this.decToHex(c),this.decToHex(l),"F2","00"];await o(this,w,ht).call(this,h,"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");const t=["F1","C3","00","00","00","00","00","00","00","00","F2","B5"];return await o(this,w,ht).call(this,t,"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");const t=["F1","CD","00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,t,"card-reader:disable")}async cardReaderDispense({channel:t=1,second_channel:e=null,sensor:i=!0,seconds:s=null,price:a=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if(isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)throw new Error("Card reader pre-credit not configured");if(isNaN(a)||a<=0)throw new Error("Price must be greater than 0");if(a>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!i&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");const c=this.decToHex(a/256),l=this.decToHex(a%256),h=this.decToHex(t+9);let _="00";e&&(_=this.decToHex(e+9));let f="00";i||(f=this.decToHex(s*10));const b=["F1","CD","01",h,_,f,c,l,"00","00","F2","00"];await o(this,w,ht).call(this,b,"card-reader:dispense")}async paymentPursesDisable({coin:t=!0,banknote:e=!0,cardReader:i=!1}={}){t&&await this.coinPurseDisable(),e&&await this.banknotePurseDisable(),i&&await this.cardReaderDisable()}async paymentPursesEnable({coin:t=!0,banknote:e=!0,scrowBanknote:i=!1}={}){t&&await this.coinPurseEnable(),e&&await this.banknotePurseEnable({scrow:i})}async coolingRelayConfigure({enable:t=!1}={}){const i=["F1","CC",t?"01":"00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,i,"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){const t=["F1","CB","00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,t,"status:temperature")}async dispense({selection:t=1,second_selection:e=null,sensor:i=!0,seconds:s=null,retry:a=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===t))throw new Error("Invalid second channel number");if(!i&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");a&&(this.__internal__.dispense.backup_dispense={selection:t,second_selection:e,sensor:i,seconds:s}),t+=9;const c=this.decToHex(t);let l="00";e&&(e+=9,l=this.decToHex(e));let h="00";i||(h=this.decToHex(Math.round(s*6.2)),this.__internal__.dispense.custom_limit_counter=s);const _=o(this,w,Je).call(this,["F1","C7",c,l,h,"00","00","00","00","00","F2","00"]);let f=await this.internalDispense(_);return!f.dispensed&&a&&(f=await this.internalDispense(_)),this.__internal__.dispense.custom_limit_counter=null,f}async testEngines({singleEngine:t=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(O(this,Jt))throw new Error("Another test is running");o(this,w,Wn).call(this),L(this,Jt,!0);const e=[];o(this,w,Qe).call(this);for(let i=1;i<=80;i++){const s=await this.dispense({selection:i,second_selection:t?null:i+1,sensor:!1,seconds:.4,retry:!1});e.push(s),L(this,Ut,i),o(this,w,Qe).call(this),t||i++}L(this,Ut,80),o(this,w,Qe).call(this,{dispensed:e}),o(this,w,Wn).call(this)}async sendCustomCode({code:t=[]}={}){if(t.length===0)throw new Error("Invalid code");const e=o(this,w,Je).call(this,t);await this.appendToQueue(e,"custom")}hasToReturnChange(t=0){let e=t;return e<=0?!0:(e=o(this,w,$n).call(this,e).pending,e=o(this,w,zn).call(this,e).pending,!(e>0))}async returnChange(){return await o(this,w,Gn).call(this)}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await o(this,w,Gn).call(this,this.__money_session.inserted)}async serialCorruptMessage(t,e){this.dispatch("corrupt:message",{data:t,message:e})}}Jt=new WeakMap,Ut=new WeakMap,Qt=new WeakMap,w=new WeakSet,Ks=function(){const t=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature"];for(const e of t)this.serialRegisterAvailableListener(e)},Ws=function(){k.add(this)},Xe=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},$s=function(){return this.hasCoinPurse||this.hasRecycler},zs=function(t){return t.name="Connection with the serial device completed.",t.description="Your connection with the serial device was successfully completed.",t.no_code=1,this.dispatch("run:default-load",{}),t},Gs=function(t){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let i=null;for(let a in e)if(e[a].includes(t)){i=a;break}return i?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[i],i]:[`Undefined value: ¿${t}?`,null]},Xs=function(t){return["g50","c50","p1","p2","p5","p10","p20"].includes(t)},Js=function(t){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let i=null;for(let a in e)if(e[a].includes(t)){i=a;break}return i?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[i],i]:[`Undefined value: ¿${t}?`,null]},Qs=function(t){return["p20","p50","p100","p200","p500","p1000"].includes(t)},Zs=function(t){return["r20","r50","r100"].includes(t)},Ys=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},Kn=function(t,e,i){if(!t)return;let s=!0;if(o(this,w,Xs).call(this,t)&&i==="coin"){if(typeof this.coins.tubes[t]>"u")return;e==="tube"?this.coins.tubes[t]+=1:e==="box"&&(this.coins.box[t]+=1);let a=0;["g50","c50"].includes(t)?a=.5:a+=parseInt(t.slice(1)),this.coins.totals[t]+=a,this.__money_session.inserted+=a,this.coins.total+=a}else if(o(this,w,Qs).call(this,t)&&i==="banknote"){if(typeof this.banknotes.recycler[t]>"u")return;e==="recycler"?this.banknotes.recycler[t]+=1:e==="stacker"&&(this.banknotes.stacker[t]+=1);let a=parseInt(t.slice(1));this.banknotes.totals[t]+=a,this.__money_session.inserted+=a,this.banknotes.total+=a}else if(o(this,w,Zs).call(this,t)&&e==="out"&&i==="banknote"){if(typeof this.banknotes.out[t.replace("r","p")]>"u")return;this.banknotes.out[t.replace("r","p")]+=1;let a=parseInt(t.slice(1));this.__money_session.retired+=a,this.banknotes.recycler[t.replace("r","p")]-=1,this.banknotes.total-=a,s=!1,this.dispatch("session:money-dispensed",{type_money:t,retired:a,finish:!1,type:"banknotes"})}s&&this.dispatch("session:money-request",{})},ta=function(t,e){const i=parseInt(t[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},i===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):i===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):i>=64&&i<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):i>=80&&i<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):i>=96&&i<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):i>=112&&i<=127?(e.name="Coin rejected",e.additional.where="rejected"):i>=144&&i<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${t[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),i===1||i===2||i>=160||i>=128&&i<=143||([e.description,e.additional.coin]=o(this,w,Gs).call(this,t[2]),e.no_code=38+i,o(this,w,Kn).call(this,e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e},ea=function(t,e){const i=parseInt(t[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},i===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=o(this,w,Ys).call(this),e.additional.where="out",e.no_code=200):i>=128&&i<=143?(e.name="Banknote inserted",e.additional.where="stacker"):i>=144&&i<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):i>=160&&i<=175?(e.name="Banknote rejected",e.additional.where="nothing"):i>=176&&i<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),i>=128&&i<=191&&([e.description,e.additional.banknote]=o(this,w,Js).call(this,t[2]),e.no_code=74+i),o(this,w,Kn).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},na=function(t,e){const i=parseInt(t,16);return i===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):i===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:i===1}),e},ia=function(t,e){const i=parseInt(t[2],16),s=parseInt(t[3],16);return i===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):i===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),s===0?e.additional.scrow="Scrow disabled, banknote received automatic":s===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:i===1,scrow:s===1}),e},ra=function(t,e){e.no_code=6;const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={coins:{g50:i,c50:s,p1:a,p2:c,p5:l,p10:h}},this.coins.tubes.g50=i,this.coins.tubes.c50=s,this.coins.tubes.p1=a,this.coins.tubes.p2=c,this.coins.tubes.p5=l,this.coins.tubes.p10=h,this.coins.totals.g50=(this.coins.box.g50+i)*.5,this.coins.totals.c50=(this.coins.box.c50+s)*.5,this.coins.totals.p1=this.coins.box.p1+a,this.coins.totals.p2=(this.coins.box.p2+c)*2,this.coins.totals.p5=(this.coins.box.p5+l)*5,this.coins.totals.p10=(this.coins.box.p10+h)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e},sa=function(t,e){e.no_code=7;const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={banknotes:{b20:i,b50:s,b100:a,b200:c,b500:l,b1000:h}},this.banknotes.recycler.p20=i,this.banknotes.recycler.p50=s,this.banknotes.recycler.p100=a,this.banknotes.recycler.p200=c,this.banknotes.recycler.p500=l,this.banknotes.recycler.p1000=h,this.banknotes.totals.p20=(this.banknotes.stacker.p20+i)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+s)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+a)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+c)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+l)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+h)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e},aa=function(t,e){const i=parseInt(t,16);return i===1?e.name="Banknote accepted":i===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:i===1}),e},oa=function(t,e){const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)],_=i*20+s*50+a*100+c*200+l*500+h*1e3;return e.name="Banknotes dispensed",e.description=_>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:i,b50:s,b100:a,b200:c,b500:l,b1000:h},total_dispensed:_},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},ca=function(t,e){return e.name="Coins dispensed",e.no_code=10,e.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change,this.dispatchAsync("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"coins"},500),e},la=function(t,e){const i=parseInt(t,16);return i===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):i===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e},ha=function(t,e){let i="closed";return t==="db"?(e.name="Door closed",e.no_code=13):t==="dc"?(e.name="Door open",e.no_code=14,i="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,i="unknown"),this.__internal__.device.door_open=i==="open",this.dispatch("event:door",{open:i==="open"}),this.dispatch("door:event",{open:i==="open"}),e},ua=function(t,e){const i=parseInt(t[2],16)*255,s=parseInt(t[3],16),a=(i+s)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${a}`,e.additional={high:i,low:s,temperature:parseFloat(a.toString())},this.dispatch("status:temperature",e.additional),e},da=function(t,e){const i=parseInt(t,16);let s="unknown";return i===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,s="on"):i===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,s="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:s==="on"}),e},pa=function(t,e){const i=parseInt(t[2],16);if(e.no_code=20+i,e.name="Status unknown",e.description="The status of card reader does not identified correctly",i===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(i===1||i===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(i===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(i===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(i===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(i===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(i===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(i===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(i===10){const s=parseInt(t[8],16);s===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):s===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e},ht=function(t,e){return this.appendToQueue(o(this,w,Je).call(this,t),e)},Je=function(t){return t[11]=this.serialBoardroidSumHex(t),t.map((e,i)=>{t[i]=this.hexMaker(e)}),t},_a=function({enable:t=!1,scrow:e=!1}={}){const i=t?"FF":"00",s=e?"FF":"00";return["F1","C0",i,i,s,s,"00","00","00","00","F2","00"]},fa=function({enable:t=!1,scrow:e=!1}={}){return["F1","C0",t?"01":"00",e?"01":"00","00","00","00","00","00","00","F2","00"]},ga=function(t=1){if(t<1)throw new Error("No banknotes to dispense");return t=this.decToHex(t),["F1","C5",this.decToHex(this.__banknote_purse.recycler.banknote.toString()),t,"00","00","00","00","00","00","F2","00"]},ya=function({$_20:t=0,$_50:e=0,$_100:i=0,$_200:s=0,$_500:a=0,$_1000:c=0}={}){if([t,e,i,s,a,c].some(l=>isNaN(l)||typeof l=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&i<1&&s<1&&a<1&&c<1)throw new Error("No banknotes to dispense");return[t,e,i,s,a,c]=[this.decToHex(t),this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a),this.decToHex(c)],["F1","C5",t,e,i,s,a,c,"00","00","F2","00"]},Wn=function(){L(this,Jt,!1),L(this,Ut,0),L(this,Qt,0)},Qe=function({dispensed:t=null,limit:e=80}={}){L(this,Qt,Math.round(O(this,Ut)*100/e)),this.dispatch("percentage:test",{percentage:O(this,Qt),dispensed:t})},ba=function(t){const e=["20","50","100","200","500"],i=this.__banknote_purse.recycler.banknote,s="$_"+e[i],a=parseInt(e[i]),c=this.banknotes.recycler[`p${e[i]}`],l=Math.min(Math.floor(t/a),c),h={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:l>0};return this.totalInRecycler===0||l<1||t===0||(h.banknotes[s]=l,h.pending=parseFloat((t-l*a).toFixed(2))),h},ma=function(t){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1};if(this.totalInRecycler===0||t===0)return e;const i=(s,a)=>{if(this.banknotes.recycler[a]>0){const c=Math.floor(e.pending/s),l=Math.min(c,this.banknotes.recycler[a]);e.banknotes[`$_${s}`]=l,e.pending=parseFloat((e.pending-l*s).toFixed(2))}};return i(1e3,"p1000"),i(500,"p500"),i(200,"p200"),i(100,"p100"),i(50,"p50"),i(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(s=>s>0),e},$n=function(t){return this.hasRecycler?o(this,w,Xe).call(this)?o(this,w,ba).call(this,t):o(this,w,ma).call(this,t):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1}},zn=function(t){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:t,will_dispense:!1};if(!this.hasCoinPurse||t<=0||this.totalInTubes===0)return e;const i=(s,a,c=null)=>{if(this.coins.tubes[a]>0){c===null&&(c="$_"+s);const l=Math.floor(e.pending/s),h=Math.min(l,this.coins.tubes[a]);e.coins[c]=h,e.pending=parseFloat((e.pending-h*s).toFixed(2))}};return i(10,"p10"),i(5,"p5"),i(2,"p2"),i(1,"p1"),i(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(s=>s>0),e},Gn=async function(t=null){if(!o(this,w,$s).call(this))throw new Error("Change not available");let e=this.change,i=this.change;if(t!==null&&(e=t,i=t),i<=0)return!1;const s=o(this,w,$n).call(this,i);i=s.pending;const a=o(this,w,zn).call(this,i);return i=a.pending,i>0&&this.dispatch("change:pending",{pending:i}),this.dispatch("change:dispense",{recycler:s.banknotes,coins:a.coins,pending:i,delivery:e-i}),i===e?!1:(s.will_dispense&&await this.banknotePurseDispense(s.banknotes),a.will_dispense&&await this.coinPurseDispense(a.coins),!0)};class Bc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});Q(this,Zt);if(this.__internal__.device.type="arduino",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,o(this,Zt,va).call(this),o(this,Zt,wa).call(this),this.getResponseAsString()}serialMessage(t){const e=this.stringToArrayHex(t),i=this.stringToArrayBuffer(t),s={original_code:e,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(s.code=t,t){case"connected":s.name="connected",s.description="Connection established",s.request="connect",s.no_code=100;break;case"created by danidoble":s.name="thanks",s.description="thanks for using this software",s.request="credits",s.no_code=101;break;case"hello there":s.name="hello there",s.description="hi human",s.request="hi",s.no_code=102;break;case"ara ara":s.name="ara ara",s.description="troll",s.request="ara ara",s.no_code=404;break;default:s.name="unknown",s.description="Unknown command",s.request="unknown",s.no_code=400;break}this.dispatch("serial:message",s)}serialSetConnectionConstant(t=1){return this.add0x(this.parseStringToBytes("CONNECT"))}async sayCredits(){const t=this.parseStringToBytes("CREDITS");await this.appendToQueue(t,"credits")}async sayHi(){const t=this.parseStringToBytes("HI");await this.appendToQueue(t,"hi")}async sayAra(){const t=this.parseStringToBytes("OTHER");await this.appendToQueue(t,"ara")}async sendCustomCode({code:t=""}={}){if(typeof t!="string")throw new Error("Invalid string");const e=this.parseStringToBytes(t);await this.appendToQueue(e,"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}Zt=new WeakSet,wa=function(){k.add(this)},va=function(){};/**
|
|
48
|
+
`);await this.appendToQueue(e,"demo")}async refund({amount:t=0,folio:e=null,auth:i=null}={}){const s=JSON.stringify({action:"REFUND",amount:t,folio:e,auth:i}),a=this.parseStringToBytes(s,`\r
|
|
49
|
+
`);await this.appendToQueue(a,"refund")}}st=new WeakSet,ss=function(){k.add(this)},as=function(){const t=["buttons-status","init-app","connectMessage","login","voucher","info","keep-alive","reset-app","get-config","payment","error","refund"];for(const e of t)this.serialRegisterAvailableListener(e)},os=function(t){this.dispatch("payment",t),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=t)},cs=function(t){return/^[A-Z-a-z0-9_\s]+$/g.test(t)},qn=async function(){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.queue.length===0)return!0;const t=this;return new Promise(e=>{let i=setInterval(()=>{t.queue.length===0&&(clearInterval(i),e(!0))},500)})},ls=async function(){await this.connectMessage(),await this.login(),await this.hideButtons()};class Oc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1,device_listen_on_port:s=1,type:a="esplus",support_cart:c=!0}={}){super({filters:t,config_port:e,no_device:i,device_listen_on_port:s});Q(this,g);_t(this,"__device",{type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}});if(this.__internal__.device.type="jofemar",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=a,this.supportCart=c,o(this,g,hs).call(this),o(this,g,ds).call(this),o(this,g,us).call(this)}set startChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid start channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=e}set endChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid end channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=e}set listenOnChannel(t){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t),this.__internal__.device.hex_number=(128+t).toString(16)}set listenOnPort(t){this.listenOnChannel=t}set deviceType(t){if(typeof t!="string")throw new Error("Invalid device type, must be a string");this.__device.type=t}set supportCart(t){if(typeof t!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=t}serialJofemarMakeBytes(t){let e=this.hexToDec(this.sumHex(t)),i=this.calcCheckSums(e.toString());for(let s=0;s<2;s++)t.push(this.hexMaker(i[s]));return t.push("03"),this.add0x(t)}calcCheckSums(t){t=this.add0x([this.decToHex(parseInt(t).toString())]);let e=[];return e.push((t&255|240).toString(16).toUpperCase()),e.push((t&255|15).toString(16).toUpperCase()),e}serialSetConnectionConstant(t=1){let e=["02","30","30",(128+t).toString(16),"53","FF","FF"],i=[];return e.forEach(s=>{i.push(this.hexMaker(s))}),this.serialJofemarMakeBytes(i)}serialMessage(t){let i={code:t,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(t[0]){case"02":i=o(this,g,Us).call(this,t,i,128);break;case"06":i=o(this,g,Ls).call(this,t,i);break;case"15":i.name="Checksum error",i.description="The calculated checksum does not match the received checksum",i.no_code=38,o(this,g,tt).call(this);break;default:i.name="unknown",i.description="The message received is unknown",i.no_code=404;break}this.dispatch("serial:message",i)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:t=1,cart:e=!1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>130)throw new Error("Invalid selection");const{channel:i,tray:s}=o(this,g,Vs).call(this,t);this.__internal__.dispense.backup_dispense={selection:t,cart:e,channel:i,tray:s};let c=["02","30","30",this.__internal__.device.hex_number,"56",s,i];e&&(c[4]="4D"),c=o(this,g,We).call(this,c);let l;do l=await this.internalDispense(c),o(this,g,qs).call(this),l.error==="elevator-locked"?await o(this,g,ps).call(this):l.error==="no-response"&&await N(1e3);while(["elevator-locked","no-response"].includes(l.error));return this.__internal__.dispense.backup_dispense={},l}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(t=>t.type!=="status"))}async endDispense(){let e=["02","30","30",this.__internal__.device.hex_number,"4D","80","80"];return e=o(this,g,We).call(this,e),await this.internalDispense(e)}async collect(){const t=["02","30","30","81","4E","FF","FF"];return await o(this,g,lt).call(this,t,"collect")}async resetSoldOutErrors(){return await o(this,g,fe).call(this,"80")}async resetWaitingProductRemovedError(){return await o(this,g,fe).call(this,"81")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(o(this,g,Hn).call(this),await o(this,g,fe).call(this,"FF")):new Promise(t=>{const e=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(e),await o(this,g,fe).call(this,"FF"),o(this,g,Hn).call(this),t(!0))},100)})}async resetAllErrors(){return await this.resetSoldOutErrors(),await N(100),await this.resetWaitingProductRemovedError(),await N(100),await this.resetMachineErrors()}async status(){const t=["02","30","30","81","53","FF","FF"];return await o(this,g,lt).call(this,t,"status")}async lightsOn(){return await o(this,g,jn).call(this,"81")}async lightsOff(){return await o(this,g,jn).call(this,"80")}async program(t,e){const i=["02","30","30","81","50",t,e];return await o(this,g,lt).call(this,i,"program")}async programDisplayLanguage({language:t="spanish"}={}){const e={spanish:"30",english:"31",french:"32"};if(!e[t])throw new Error("Invalid language");return await this.program("49",e[t])}async programBeeper({enable:t=!0}={}){const e=t?"31":"30";return await this.program("5A",e)}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.program("54","80")}async programDisableThermometer(){return await this.programDisableWorkingTemperature()}async programWorkingTemperature({degrees:t=.5}={}){t=parseFloat(t);const e=this.__device.type==="iceplus"?6.5:32,i=this.__device.type==="iceplus"?-25:.5;if(isNaN(t)||t<i||t>e||t%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let s=t*2+128;return this.__device.type==="iceplus"&&(s+=51),s=Math.ceil(s),await this.program("54",s.toString(16))}async programIsolationTray({tray:t=0}={}){if(t=parseInt(t),isNaN(t)||t<0||t>12)throw new Error("Invalid tray, valid range is 0 to 12");const e=t===0?"80":(t+139).toString(16);return this.program("42",e)}async programTimeToStandbyAfterCollect({seconds:t=15}={}){if(t=parseInt(t),isNaN(t)||t<15||t>120)throw new Error("Invalid seconds, valid range is 15 to 120");const e=(128+t).toString(16);return await this.program("46",e)}async programTimeToStandbyWithoutCollect({minutes:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>10)throw new Error("Invalid minutes, valid range is 1 to 10");const e=(128+t).toString(16);return await this.program("48",e)}async programElevatorSpeed({speed:t="high"}={}){const e={high:"31",low:"30"};if(!e[t])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return await this.program("76",e[t])}async programTemperatureExpiration({enable:t=!1}={}){const e=t?"31":"30";return await this.program("63",e)}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid address, valid range is 1 to 31");const e=(128+t).toString(16);return await this.program("64",e)}async programTemperatureBeforeExpiration({degrees:t=.5}={}){if(t=parseFloat(t),isNaN(t)||t<.5||t>30||t%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const e=(128+t*2).toString(16);return await this.program("65",e)}async programTimeBeforeExpirationByTemperature({minutes:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>120)throw new Error("Invalid minutes, valid range is 1 to 120");const e=(128+t).toString(16);return await this.program("66",e)}async programTemperatureScale({scale:t="c"}={}){const e={c:"43",f:"46"};if(!e[t])throw new Error("Invalid scale, valid scales are 'c' for celsius and 'f' for fahrenheit");return await this.program("67",e[t])}async programVoltageEngine({selection:t=1,voltage:e=5}={}){if(e=parseFloat(e),t=parseInt(t),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(e)||e<5||e>9.5||e%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const i=109+t,a=(128+(e-5)*2).toString(16),c=["02","30","30","81","47",i,a];return await o(this,g,lt).call(this,c,"voltage-engine")}async programPushOverProducts({selection:t=1,enable:e=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);const a=["02","30","30","81","4F",109+t,e?"31":"30"];return await o(this,g,lt).call(this,a,"push-over-products")}async programChannelRunningAfterDispense({selection:t=1,seconds:e=0}={}){if(t=parseInt(t),e=parseFloat(e),isNaN(t)||t<1||t>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(e)||e<0||e>10||e%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const i=109+t;e=e.toFixed(1);const s=128+e*10,a=["02","30","30","81","45",i,s];return await o(this,g,lt).call(this,a,"channel-running-after-dispense")}async checkData(t,e="FF"){const i=["02","30","30","81","43",t,e];return await o(this,g,lt).call(this,i,"check-data")}async getDisplayLanguage(){return await this.checkData("49")}async getBeeper(){return await this.checkData("5A")}async getWorkingTemperature(){return await this.checkData("54")}async getIsolationTray(){return await this.checkData("42")}async getProgramVersion(){return await this.checkData("50")}async getFaults(){return await this.checkData("53")}async getMachineId(){return await this.checkData("4E")}async getCurrentTemperature(){return await this.checkData("74")}async getTimeToStandbyAfterCollect(){return await this.checkData("46")}async getTimeToStandbyWithoutCollect(){return await this.checkData("48")}async getElevatorSpeed(){return await this.checkData("76")}async getTemperatureExpiration(){return await this.checkData("63")}async getTemperatureBeforeExpiration(){return await this.checkData("65")}async getTimeBeforeExpirationByTemperature(){return await this.checkData("66")}async getTemperatureScale(){return await this.checkData("67")}async getClockRegisters(){return await this.checkData("72")}async getMachineActivity(){return await this.checkData("41")}async getVoltageEngine({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("47",e)}async getChannelPresence({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("43",e)}async getPushOverProducts({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("4F",e)}async getChannelRunningAfterDispense({selection:t=1}={}){if(t=parseInt(t),isNaN(t)||t<1||t>126)throw new Error("Invalid selection, valid range is 1 to 126");const e=(109+t).toString(16);return await this.checkData("45",e)}async setDisplayStandbyMessage({message:t=""}={}){t=t.substring(0,32);const e=o(this,g,Ge).call(this,t);return await o(this,g,ze).call(this,"80",e)}async setDisplayMessageTemporarily({message:t="",seconds:e=1}){if(t=t.substring(0,32),e=parseInt(e),isNaN(e)||e<1||e>125)throw new Error("Invalid seconds, valid range is 1 to 125");const i=o(this,g,Ge).call(this,t),s=(128+e).toString(16);return await o(this,g,ze).call(this,s,i)}async setDisplayMessageUnlimited({message:t=""}){t=t.substring(0,32);const e=o(this,g,Ge).call(this,t);return await o(this,g,ze).call(this,"FF",e)}async programClock({date:t=new Date}={}){if(!(t instanceof Date))throw new Error("Invalid date, must be an instance of Date");const e=["02","30","30","81","72",...o(this,g,js).call(this,t)];return await o(this,g,lt).call(this,e,"clock")}async eventsConfig({event:t=null,enable:e=!0}={}){if(t===null)throw new Error("Invalid event");const s=["02","30","30","81","41",t,e?"31":"30"];return await o(this,g,lt).call(this,s,"events-config")}async eventEnable({event:t=null}={}){if(t===null)throw new Error("Invalid event");const e=parseInt(t,16);if(isNaN(e)||e<38||e>100)throw new Error("Invalid event");return await this.eventsConfig({event:t,enable:!0})}async eventDisable({event:t=null}={}){if(t===null)throw new Error("Invalid event");const e=parseInt(t,16);if(isNaN(e)||e<38||e>100)throw new Error("Invalid event");return await this.eventsConfig({event:t,enable:!1})}async sendCustomCode({code:t=[]}={}){if(t.length<5)throw new Error("Invalid code, minimum length is 5");return await o(this,g,lt).call(this,t,"custom")}async assignChannels(){const t=this.__device.channels.verification.start,e=this.__device.channels.verification.end;if(t>e)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let i=t;i<=e;i++)this.__device.channels.verification.current=i,await this.getChannelPresence({selection:i});return new Promise(i=>{let s=setInterval(()=>{this.__device.channels.verification.channels.length===e-t+1&&(clearInterval(s),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),i(!0))},500)})}}g=new WeakSet,hs=function(){const t=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channel:status","machine:status"];for(const e of t)this.serialRegisterAvailableListener(e)},us=function(){this.on("internal:dispense:running",o(this,g,Hs).bind(this))},ds=function(){k.add(this)},lt=function(t,e){return t[3]=this.__internal__.device.hex_number,this.appendToQueue(o(this,g,We).call(this,t),e)},We=function(t){let e=this.hexToDec(this.sumHex(t)),i=this.calcCheckSums(e.toString());for(let s=0;s<2;s++)t.push(this.hexMaker(i[s]));return t.push("03"),t},ps=async function(){if(this.__internal__.dispense.elevator.locking_interval)return;this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await N(500));const t=this;return this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(e=>{t.__internal__.dispense.elevator.locking_interval=setInterval(()=>{t.dispatch("dispensing:withdrawal",{elevator:!0,seconds:t.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),t.__internal__.dispense.elevator.locking_time-=1,t.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(t.__internal__.dispense.elevator.locking_interval),t.__internal__.dispense.elevator.locking_interval=0,e(!0))},1e3)})},_s=function(t,e){return e.name="ok",e.description="The last command was executed successfully",e.no_code=1,this.dispatch("command-executed",e),e},fs=function(t,e){e.additional={hex:t,dec:this.hexToDec(t),ascii:null};const i={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"};return e.additional.ascii=i[t]??null,e.name="Key pressed",e.description=`The key ${e.additional.ascii} was pressed`,e.no_code=2,this.dispatch("keyboard:pressed",e.additional),e},gs=function(t,e){return e.additional={open:!1},e.no_code=3,t==="4f"?(e.name="door open",e.description="The door was opened",e.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",e.additional)):t==="43"?(e.name="door close",e.description="The door was closed",e.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",e.additional)):(e.name="door event",e.description="The door event received is unknown",this.dispatch("door:event",{open:e.additional.open,message:e})),e},ys=function(t,e){e.no_code=404;let i=t[5]??null;return i&&this.listenOnChannel>1&&(i=this.hexToDec(i)-this.listenOnChannel+1,i=this.decToHex(i)),i&&(i==="FD"?(e.no_code=4,e.name="channel disconnected",e.description="The channel is disconnected",e.additional={active:!1}):i==="FC"?(e.no_code=5,e.name="channel connected",e.description="The channel is connected",e.additional={active:!0}):(e.no_code=6,e.name="channel sold out",e.description="The channel is empty",e.additional={active:!0}),this.__device.channels.verification.running&&(this.__device.channels.verification.channels.push({selection:this.__device.channels.verification.current,active:e.additional.active}),e.additional.selection=this.__device.channels.verification.current),this.dispatch("channel:status",e.additional)),e},bs=function(t,e){e.no_code=39,e.name="Program version";const i=t.slice(4,12),s=i.map(a=>String.fromCharCode(this.hexToDec(a))).join("");return e.additional={version:s,hex:i},e.description=`The program version is ${s}`,this.dispatch("program:version",e.additional),e},ms=function(t,e){e.no_code=39,e.name="Machine faults",e.description="No faults detected",e.additional={no_faults:0,faults:[]};const i=t.slice(4,-3);if(i.length>1&&i[0]!=="30"){e.description="Machine has faults";const s={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const a of i)s[a]&&(e.additional.faults.push(s[a]),e.additional.no_faults++)}return this.dispatch("machine:faults",e.additional),e},ws=function(t,e){e.no_code=40,e.name="Clock registers",e.description="Clock registers";const i=t.slice(4,-3),s=i.map(v=>String.fromCharCode(this.hexToDec(v))).join(""),[a,c]=s.split(" "),[l,h]=a.split(":"),[_,f,b]=c.split("-"),E=new Date(2e3+parseInt(b),parseInt(f)-1,parseInt(_),parseInt(l),parseInt(h));return e.additional={day:_,month:f,year:b,hours:l,minutes:h,formatted:s,date:E,hex:i},this.dispatch("clock:registers",e.additional),e},vs=function(t,e){e.no_code=41,e.name="Machine activity",e.description="Events from read machine activity";const i=String.fromCharCode(this.hexToDec(t[4]));if(i!=="0"){const s=t.slice(5,-3);if(i==="T"&&s.length===4){const a=String.fromCharCode(this.hexToDec(s[0])),c=String.fromCharCode(this.hexToDec(s[1])),l=String.fromCharCode(this.hexToDec(s[3]));e.additional={ascii:i,type:"DU.d",dozens:a,units:c,decimals:l,time:parseFloat(`${a}${c}.${l}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(i)&&s.length===3){const a=String.fromCharCode(this.hexToDec(s[0])),c=String.fromCharCode(this.hexToDec(s[1])),l=String.fromCharCode(this.hexToDec(s[2])),h=parseInt(`${a}${c}${l}`),_={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};e.additional={type:"HDU",hundreds:a,dozens:c,decimals:l,channel:h,selection:h-109,ascii:i,meaning:_[i]??"Unknown"}}else if(s.length===13){const a=s.map(S=>String.fromCharCode(this.hexToDec(S))).join(""),c=parseInt(a.slice(0,2)),l=parseInt(a.slice(2,4)),h=parseInt(a.slice(4,6)),_=parseInt(a.slice(7,9)),f=parseInt(a.slice(9,11))-1,b=2e3+parseInt(a.slice(11,13)),E=new Date(b,f,_,c,l,h),v={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};e.additional={type:"hhmmssWddMMAA",date:E,hex:s,formatted:E.toLocaleString(),ascii:i,meaning:v[i]??"Unknown"}}}return this.dispatch("machine:activity",e.additional),e},Es=function(t,e){const i={30:"Spanish",31:"English",32:"French"};return e.no_code=42,e.name="Language",e.description=`The language is ${i[t]??"unknown"}`,e.additional={hex:t,language:i[t]??"unknown"},this.dispatch("check:language",e.additional),e},Ps=function(t,e){return e.no_code=43,e.name="Beeper",e.description=`The beeper is ${t==="30"?"on":"off"}`,e.additional={hex:t,beeper:t==="30"},this.dispatch("check:beeper",e.additional),e},Ts=function(t,e){e.no_code=44,e.name="Isolation tray",e.description="Isolation tray";const i=this.hexToDec(t)-139;return e.additional={hex:t,tray:i},this.dispatch("check:isolation-tray",e.additional),e},Cs=function(t,e){e.no_code=45,e.name="Engine voltage",e.description="Engine voltage";const i=(this.hexToDec(t)-128)/2+5;return e.additional={hex:t,voltage:i},this.dispatch("check:engine-voltage",e.additional),e},Ss=function(t,e){e.no_code=46,e.name="Push over",e.description="Push over";const i=t==="30";return e.additional={hex:t,push:i},this.dispatch("check:push-over",e.additional),e},ks=function(t,e){e.no_code=47,e.name="Extractor after dispense",e.description="Extractor after dispense";const i=(this.hexToDec(t)-128)/10;return e.additional={hex:t,seconds:i},this.dispatch("check:extractor-after-dispense",e.additional),e},xs=function(t,e){e.no_code=48,e.name="Standby after collect",e.description="Time to standby after collect product";const i=this.hexToDec(t)-128;return e.additional={hex:t,seconds:i},this.dispatch("check:standby-after-collect",e.additional),e},As=function(t,e){e.no_code=49,e.name="Standby without collect",e.description="Time to standby when product delivery is not collected";const i=this.hexToDec(t)-128;return e.additional={hex:t,minutes:i},this.dispatch("check:standby-without-collect",e.additional),e},Ds=function(t,e){e.no_code=50,e.name="Elevator speed",e.description="Elevator speed";const i=t==="30"?"low":"high";return e.additional={hex:t,speed:i},this.dispatch("check:elevator-speed",e.additional),e},Rs=function(t,e){e.no_code=51,e.name="Temperature expiration",e.description="Temperature expiration";const i=t==="31";return e.additional={hex:t,enabled:i},this.dispatch("check:expiration-by-temperature",e.additional),e},Is=function(t,e){e.no_code=52,e.name="Temperature before expiration",e.description="Temperature before expiration";const i=(this.hexToDec(t)-128)/2;return e.additional={hex:t,temperature:i},this.dispatch("check:temperature-before-expiration",e.additional),e},Os=function(t,e){e.no_code=53,e.name="Time before expiration",e.description="Time before expiration";const i=this.hexToDec(t)-128;return e.additional={hex:t,minutes:i},this.dispatch("check:expiration-after",e.additional),e},Ns=function(t,e){e.no_code=54,e.name="Temperature scale",e.description="Temperature scale";const i=t==="43"?"Celsius":"Fahrenheit";return e.additional={hex:t,scale:i},this.dispatch("check:temperature-scale",e.additional),e},Bs=function(t,e){return e.no_code=54,e.name="Machine ID",e.description="Machine ID",e.additional={hex:t[4],full_hex:t},this.dispatch("check:machine-id",e.additional),e},Ms=function(t,e){return e.no_code=7,e.name="working temperature",e.description=`The working temperature is ${t}`,e.additional={hex:t,temperature:{traditional:(this.hexToDec(t)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(t)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",e.additional),e},Fs=function(t,e){return e.no_code=8,e.name="current temperature",e.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:t[7]==="2e"?".":null,degrees:t[9]==="7f"?"°":null,error:null},t[4]==="2b"?e.additional.sign=t[4]="+":["2e","2d"].includes(t[4])?e.additional.sign=t[4]="-":t[4]==="20"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[5])>=48&&this.hexToDec(t[5])<=57?e.additional.tens=this.hexToDec(t[5])-48:t[5]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[6])>=48&&this.hexToDec(t[6])<=57?e.additional.units=this.hexToDec(t[6])-48:t[6]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[8])>=48&&this.hexToDec(t[8])<=57?e.additional.decimals=this.hexToDec(t[8])-48:t[8]==="2a"&&(e.additional.error="Error in thermometer"),t[10]==="43"?e.additional.type_degrees="C":t[10]==="46"&&(e.additional.type_degrees="F"),e.additional.error==="Error in thermometer"?(e.additional.formatted="Error in thermometer",e.description="The current temperature cannot be read because there is an error in the thermometer"):(e.additional.formatted=(e.additional.sign??"")+(e.additional.tens??"")+(e.additional.units??"")+(e.additional.decimal_point??"")+(e.additional.decimals??"")+(e.additional.degrees??"")+(e.additional.type_degrees??""),e.description=`The current temperature is ${e.additional.formatted}`),this.dispatch("temperature:current",e.additional),e},Us=function(t,e,i=128){if(t[1]&&(e.additional.machine.hex=t[1],e.additional.machine.dec=this.hexToDec(t[1])-i),!(t[1]&&t[2]))e=o(this,g,_s).call(this,t,e);else switch(t[2]){case"54":e.request="--automatic",e=o(this,g,fs).call(this,t[3],e);break;case"50":e.request="--automatic",e=o(this,g,gs).call(this,t[3],e);break;case"43":switch(e.request="check-data",t[3]){case"41":e=o(this,g,vs).call(this,t,e);break;case"43":e.request="channel-status",e=o(this,g,ys).call(this,t,e);break;case"50":e=o(this,g,bs).call(this,t,e);break;case"53":e=o(this,g,ms).call(this,t,e);break;case"54":e.request="working-temperature",e=o(this,g,Ms).call(this,t[4],e);break;case"72":e=o(this,g,ws).call(this,t,e);break;case"74":e.request="current-temperature",e=o(this,g,Fs).call(this,t,e);break;case"49":e=o(this,g,Es).call(this,t[4],e);break;case"5a":e=o(this,g,Ps).call(this,t[4],e);break;case"42":e=o(this,g,Ts).call(this,t[4],e);break;case"47":e=o(this,g,Cs).call(this,t[4],e);break;case"4e":e=o(this,g,Bs).call(this,t,e);break;case"4f":e=o(this,g,Ss).call(this,t[4],e);break;case"45":e=o(this,g,ks).call(this,t[4],e);break;case"46":e=o(this,g,xs).call(this,t[4],e);break;case"48":e=o(this,g,As).call(this,t[4],e);break;case"76":e=o(this,g,Ds).call(this,t[4],e);break;case"63":e=o(this,g,Rs).call(this,t[4],e);break;case"65":e=o(this,g,Is).call(this,t[4],e);break;case"66":e=o(this,g,Os).call(this,t[4],e);break;case"67":e=o(this,g,Ns).call(this,t[4],e);break}break}return e},gt=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},tt=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)},$e=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")},et=function({type:t=null,severity:e="low"}={}){this.dispatch("jofemar:warning",{type:t,severity:e})},Et=function({type:t=null,severity:e="high"}={}){this.dispatch("jofemar:error",{type:t,severity:e})},Ls=function(t,e){if(e.request="status",t[1]&&!t[2]){switch(t[1]){case"30":e.name="Machine ready",e.description="The machine is ready for instructions",e.no_code=9,o(this,g,gt).call(this);break;case"31":e.name="Machine busy",e.description="The machine is busy right now",e.no_code=10;break;case"32":e.name="Invalid tray",e.description="The tray requested is invalid",e.no_code=11,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"invalid-tray"});break;case"33":e.name="Invalid channel",e.description="The channel requested is invalid",e.no_code=12,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"invalid-channel"});break;case"34":e.name="Empty channel",e.description="The channel requested is empty",e.no_code=13,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"empty-channel"});break;case"35":e.name="Jam",e.description="Jam in elevator engine",e.no_code=14,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"jam"});break;case"36":e.name="Malfunction",e.description="Malfunction in the elevator belt or product detector",e.no_code=15,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"malfunction"});break;case"37":e.name="Photo transistors",e.description="Failure in one of the photo transistors in the cabinet",e.no_code=16,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"photo-transistors"});break;case"38":e.name="Without channels",e.description="No channels detected",e.no_code=17,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"without-channels"});break;case"39":e.name="Product detector fault",e.description="Product detector fault",e.no_code=18,o(this,g,$e).call(this),o(this,g,et).call(this,{type:"fault-product-detector"});break;case"41":e.name="Fault in 485 BUS",e.description="Machine display is disconnected",e.no_code=19,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"display-disconnected"});break;case"42":e.name="Product under elevator",e.description="Product alarm under elevator",e.no_code=20,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"product-under-elevator"});break;case"43":e.name="Error when elevator approaching to a position",e.description="Error when elevator approaching to a position",e.no_code=21,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"error-approaching-position",severity:"high"});break;case"44":e.name="Fault in keyboard",e.description="Fault in keyboard",e.no_code=22,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"fault-keyboard"});break;case"45":e.name="Eeprom writing error",e.description="Eeprom writing error",e.no_code=23,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"eeprom-writing-error",severity:"critical"});break;case"46":e.name="Fault communicating with temperature control",e.description="Fault communicating with temperature control",e.no_code=24,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"fault-temperature-control"});break;case"47":e.name="Thermometer disconnected",e.description="The thermometer is disconnected",e.no_code=25,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-disconnected"});break;case"48":e.name="Thermometer programming lost",e.description="Thermometer programming lost",e.no_code=26,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-programming-lost"});break;case"49":e.name="Thermometer faulty",e.description="Thermometer faulty",e.no_code=27,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"thermometer-faulty"});break;case"4a":e.name="Channels power consumption detector faulty",e.description="Channels power consumption detector faulty",e.no_code=28,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":e.name="Elevator does not find channel or tray",e.description="Elevator does not find channel or tray",e.no_code=29,o(this,g,tt).call(this),o(this,g,et).call(this,{type:"elevator-not-find-channel-tray"});break;case"4c":e.name="Elevator does not find delivery product position",e.description="Elevator does not find delivery product position",e.no_code=30,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"elevator-not-find-delivery-position"});break;case"4d":e.name="Interior of elevator blocked",e.description="Interior of elevator blocked",e.no_code=31,o(this,g,$e).call(this),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),o(this,g,Et).call(this,{type:"interior-elevator-blocked",severity:"low"});break;case"4e":e.name="Error in tester of product detector",e.description="Error in tester of product detector",e.no_code=32,o(this,g,tt).call(this),o(this,g,Et).call(this,{type:"error-tester-product-detector"});break;case"4f":e.name="Waiting for product to be removed",e.description="Waiting for product to be removed",e.no_code=33,o(this,g,$e).call(this);break;case"50":e.name="Product expired by temperature reasons",e.description="Product expired by temperature reasons",e.no_code=34,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"product-expired-temperature"});break;case"51":e.name="Automatic door faulty",e.description="Automatic door faulty",e.no_code=35,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(e.name="Product is expired",e.description="Product is expired",e.additional={nsf_alarm:1},t[1]){case"5a":e.additional.nsf_alarm=2;break;case"61":e.additional.nsf_alarm=3;break;case"62":e.additional.nsf_alarm=4;break;case"63":e.additional.nsf_alarm=5;break}e.no_code=36,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"product-expired"});break;case"64":e.name="Product detector didn't change during its verification test",e.description="Product detector didn't change during its verification test",e.no_code=37,o(this,g,gt).call(this),o(this,g,et).call(this,{type:"automatic-door-faulty"});break}this.dispatch("machine:status",e)}else e.name="executed",e.description="The last command was executed successfully",e.no_code=8,!t[1]&&this.__internal__.dispense.dispensing&&o(this,g,tt).call(this);return e},Vs=function(t){if(t=parseInt(t)+109,t=t.toString(),t.length!==3)throw new Error("Invalid selection");const e=(parseInt(t.substring(0,2))+128).toString(16).padStart(2,"0");return{channel:(parseInt(t.substring(2,3))+128).toString(16).padStart(2,"0"),tray:e}},qs=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0},Hs=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval);const t=this;t.__internal__.dispense.timeout=setTimeout(()=>{t.__internal__.dispense.interval=setInterval(()=>{t.status().then(()=>{})},t.__internal__.dispense.interval_time)},t.__internal__.dispense.timeout_time)},fe=async function(t){const e=["02","30","30","81","52",t,"FF"];return await o(this,g,lt).call(this,e,"reset")},Hn=function(){const t=this.__device.type==="iceplus"?Ze(40):Ze(25),e=new Date,i=1e3*t+e.getTime(),s=new Date(i);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:t,started_at:e,finished_at:s})},jn=async function(t){const e=["02","30","30","81","4C",t,"FF"];return await o(this,g,lt).call(this,e,"lights")},ze=async function(t="80",e=[]){const i=["02","30","30","81","44",t,...e];return await o(this,g,lt).call(this,i,"display")},Ge=function(t=""){t=t.padEnd(32," ");const e=[];for(let i=0;i<32;i++)e.push(t.charCodeAt(i).toString(16));return e},js=function(t){if(!(t instanceof Date))throw new Error("Invalid date, must be an instance of Date");const e=t.getHours().toString().padStart(2,"0"),i=t.getMinutes().toString().padStart(2,"0"),s=t.getDate().toString().padStart(2,"0"),a=(t.getMonth()+1).toString().padStart(2,"0"),c=t.getFullYear().toString().substring(2,4),l=`${e}:${i} ${s}-${a}-${c}`,h=[];for(let _=0;_<14;_++)h.push(l.charCodeAt(_).toString(16));return h};class Nc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});Q(this,w);_t(this,"__coin_purse",{available:!0});_t(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});_t(this,"__sale",{price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}});_t(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});_t(this,"coins",{tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0});_t(this,"banknotes",{stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0});_t(this,"card_reader",{available:!1,max_pre_credit:0});Q(this,Jt,!1);Q(this,Ut,0);Q(this,Qt,0);if(this.__internal__.device.type="boardroid",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},o(this,w,Ks).call(this),o(this,w,Ws).call(this)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(t){this.__banknote_purse.isRecycler=t}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(t){this.__banknote_purse.recycler.ict=t}set banknoteICT(t){if(![20,50,100,200,500].includes(t))throw new Error(`Invalid banknote value: ${t}`);t=[20,50,100,200,500].indexOf(t),this.__banknote_purse.recycler.banknote=t}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(t){if(typeof t!="boolean")throw new Error(`Invalid value: ${t}`);this.__coin_purse.available=t}set price(t){let e=parseFloat(t);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}serialBoardroidSumHex(t){let e=0;return t.forEach((i,s)=>{s!==0&&s!==11&&(e+=parseInt(i,16))}),e.toString(16).toUpperCase()}serialMessage(t){let e={code:t,name:null,description:null,request:null,no_code:0};const i=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(t[1]){case i:e.request="connect",e=o(this,w,zs).call(this,e);break;case"a0":e.request="--automatic",e=o(this,w,ta).call(this,t,e);break;case"b0":e.request="--automatic",e=o(this,w,ea).call(this,t,e);break;case"d0":e.request="coin-purse:config",e=o(this,w,na).call(this,t[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=o(this,w,ia).call(this,t,e);break;case"d2":e.request="coin-purse:read-tubes",e=o(this,w,ra).call(this,t,e);break;case"d3":e.request="banknote-purse:read-recycler",e=o(this,w,sa).call(this,t,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=o(this,w,aa).call(this,t[2],e);break;case"d5":e.request="banknote-purse:dispense",e=o(this,w,oa).call(this,t,e);break;case"d6":e.request="coin-purse:dispense",e=o(this,w,ca).call(this,t,e);break;case"d7":e.request="dispense",e=o(this,w,la).call(this,t[5],e);break;case"d8":e.request="--automatic",e=o(this,w,ha).call(this,t[13],e);break;case"d9":e.request="status:temperature",e=o(this,w,ua).call(this,t,e);break;case"da":e.request="status:relay",e=o(this,w,da).call(this,t[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",o(this,w,pa).call(this,t,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){let e=["F1","06","00","00","00","00","00","00","00","00","F2","F8"];return e[1]=this.hexMaker(this.decToHex((5+t).toString())),e[11]=this.serialBoardroidSumHex(e),this.add0x(e)}async coinPurseConfigure({enable:t=!1,high:e="FF",low:i="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");const a=["F1","C1",t?"01":"00",e,i,"00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,a,"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:t=0,$_1:e=0,$_2:i=0,$_5:s=0,$_10:a=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");if([t,e,i,s,a].some(l=>isNaN(l)||typeof l=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&i<1&&s<1&&a<1)throw new Error("No coins to dispense");[t,e,i,s,a]=[this.decToHex(t),this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a)];let c=["F1","C6",t,e,i,s,a,"00","00","00","F2","00"];await o(this,w,ht).call(this,c,"coin-purse:dispense")}async coinPurseReadTubes(){const t=["F1","C2","00","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"coin-purse:read-tubes")}async banknotePurseConfigure({enable:t=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let i;return o(this,w,Xe).call(this)?i=o(this,w,_a).call(this,{enable:t,scrow:e}):i=o(this,w,fa).call(this,{enable:t,scrow:e}),await o(this,w,ht).call(this,i,"banknote-purse:config")}async banknotePurseDispense({$_20:t=0,$_50:e=0,$_100:i=0,$_200:s=0,$_500:a=0,$_1000:c=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let l;if(o(this,w,Xe).call(this)){const h=[t,e,i,s,a];l=o(this,w,ga).call(this,h[this.__banknote_purse.recycler.banknote])}else l=o(this,w,ya).call(this,{$_20:t,$_50:e,$_100:i,$_200:s,$_500:a,$_1000:c});await o(this,w,ht).call(this,l,"banknote-purse:dispense")}async banknotePurseEnable({scrow:t=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:t})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","01","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","00","00","00","00","00","00","00","00","F2","00"];await o(this,w,ht).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:t=null,$_20:e=null,$_50:i=null,$_100:s=null,$_200:a=null,$_500:c=null,$_1000:l=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(t===null||e===null||i===null||s===null||a===null||c===null||l===null)throw new Error("One of the values is not defined");const h=["F1","C8",this.decToHex(t),"00",this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a),this.decToHex(c),this.decToHex(l),"F2","00"];await o(this,w,ht).call(this,h,"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");const t=["F1","C3","00","00","00","00","00","00","00","00","F2","B5"];return await o(this,w,ht).call(this,t,"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");const t=["F1","CD","00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,t,"card-reader:disable")}async cardReaderDispense({channel:t=1,second_channel:e=null,sensor:i=!0,seconds:s=null,price:a=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if(isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)throw new Error("Card reader pre-credit not configured");if(isNaN(a)||a<=0)throw new Error("Price must be greater than 0");if(a>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!i&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");const c=this.decToHex(a/256),l=this.decToHex(a%256),h=this.decToHex(t+9);let _="00";e&&(_=this.decToHex(e+9));let f="00";i||(f=this.decToHex(s*10));const b=["F1","CD","01",h,_,f,c,l,"00","00","F2","00"];await o(this,w,ht).call(this,b,"card-reader:dispense")}async paymentPursesDisable({coin:t=!0,banknote:e=!0,cardReader:i=!1}={}){t&&await this.coinPurseDisable(),e&&await this.banknotePurseDisable(),i&&await this.cardReaderDisable()}async paymentPursesEnable({coin:t=!0,banknote:e=!0,scrowBanknote:i=!1}={}){t&&await this.coinPurseEnable(),e&&await this.banknotePurseEnable({scrow:i})}async coolingRelayConfigure({enable:t=!1}={}){const i=["F1","CC",t?"01":"00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,i,"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){const t=["F1","CB","00","00","00","00","00","00","00","00","F2","00"];return await o(this,w,ht).call(this,t,"status:temperature")}async dispense({selection:t=1,second_selection:e=null,sensor:i=!0,seconds:s=null,retry:a=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===t))throw new Error("Invalid second channel number");if(!i&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");a&&(this.__internal__.dispense.backup_dispense={selection:t,second_selection:e,sensor:i,seconds:s}),t+=9;const c=this.decToHex(t);let l="00";e&&(e+=9,l=this.decToHex(e));let h="00";i||(h=this.decToHex(Math.round(s*6.2)),this.__internal__.dispense.custom_limit_counter=s);const _=o(this,w,Je).call(this,["F1","C7",c,l,h,"00","00","00","00","00","F2","00"]);let f=await this.internalDispense(_);return!f.dispensed&&a&&(f=await this.internalDispense(_)),this.__internal__.dispense.custom_limit_counter=null,f}async testEngines({singleEngine:t=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(O(this,Jt))throw new Error("Another test is running");o(this,w,Wn).call(this),L(this,Jt,!0);const e=[];o(this,w,Qe).call(this);for(let i=1;i<=80;i++){const s=await this.dispense({selection:i,second_selection:t?null:i+1,sensor:!1,seconds:.4,retry:!1});e.push(s),L(this,Ut,i),o(this,w,Qe).call(this),t||i++}L(this,Ut,80),o(this,w,Qe).call(this,{dispensed:e}),o(this,w,Wn).call(this)}async sendCustomCode({code:t=[]}={}){if(t.length===0)throw new Error("Invalid code");const e=o(this,w,Je).call(this,t);await this.appendToQueue(e,"custom")}hasToReturnChange(t=0){let e=t;return e<=0?!0:(e=o(this,w,$n).call(this,e).pending,e=o(this,w,zn).call(this,e).pending,!(e>0))}async returnChange(){return await o(this,w,Gn).call(this)}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await o(this,w,Gn).call(this,this.__money_session.inserted)}async serialCorruptMessage(t,e){this.dispatch("corrupt:message",{data:t,message:e})}}Jt=new WeakMap,Ut=new WeakMap,Qt=new WeakMap,w=new WeakSet,Ks=function(){const t=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature"];for(const e of t)this.serialRegisterAvailableListener(e)},Ws=function(){k.add(this)},Xe=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},$s=function(){return this.hasCoinPurse||this.hasRecycler},zs=function(t){return t.name="Connection with the serial device completed.",t.description="Your connection with the serial device was successfully completed.",t.no_code=1,this.dispatch("run:default-load",{}),t},Gs=function(t){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let i=null;for(let a in e)if(e[a].includes(t)){i=a;break}return i?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[i],i]:[`Undefined value: ¿${t}?`,null]},Xs=function(t){return["g50","c50","p1","p2","p5","p10","p20"].includes(t)},Js=function(t){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let i=null;for(let a in e)if(e[a].includes(t)){i=a;break}return i?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[i],i]:[`Undefined value: ¿${t}?`,null]},Qs=function(t){return["p20","p50","p100","p200","p500","p1000"].includes(t)},Zs=function(t){return["r20","r50","r100"].includes(t)},Ys=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},Kn=function(t,e,i){if(!t)return;let s=!0;if(o(this,w,Xs).call(this,t)&&i==="coin"){if(typeof this.coins.tubes[t]>"u")return;e==="tube"?this.coins.tubes[t]+=1:e==="box"&&(this.coins.box[t]+=1);let a=0;["g50","c50"].includes(t)?a=.5:a+=parseInt(t.slice(1)),this.coins.totals[t]+=a,this.__money_session.inserted+=a,this.coins.total+=a}else if(o(this,w,Qs).call(this,t)&&i==="banknote"){if(typeof this.banknotes.recycler[t]>"u")return;e==="recycler"?this.banknotes.recycler[t]+=1:e==="stacker"&&(this.banknotes.stacker[t]+=1);let a=parseInt(t.slice(1));this.banknotes.totals[t]+=a,this.__money_session.inserted+=a,this.banknotes.total+=a}else if(o(this,w,Zs).call(this,t)&&e==="out"&&i==="banknote"){if(typeof this.banknotes.out[t.replace("r","p")]>"u")return;this.banknotes.out[t.replace("r","p")]+=1;let a=parseInt(t.slice(1));this.__money_session.retired+=a,this.banknotes.recycler[t.replace("r","p")]-=1,this.banknotes.total-=a,s=!1,this.dispatch("session:money-dispensed",{type_money:t,retired:a,finish:!1,type:"banknotes"})}s&&this.dispatch("session:money-request",{})},ta=function(t,e){const i=parseInt(t[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},i===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):i===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):i>=64&&i<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):i>=80&&i<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):i>=96&&i<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):i>=112&&i<=127?(e.name="Coin rejected",e.additional.where="rejected"):i>=144&&i<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${t[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),i===1||i===2||i>=160||i>=128&&i<=143||([e.description,e.additional.coin]=o(this,w,Gs).call(this,t[2]),e.no_code=38+i,o(this,w,Kn).call(this,e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e},ea=function(t,e){const i=parseInt(t[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},i===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=o(this,w,Ys).call(this),e.additional.where="out",e.no_code=200):i>=128&&i<=143?(e.name="Banknote inserted",e.additional.where="stacker"):i>=144&&i<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):i>=160&&i<=175?(e.name="Banknote rejected",e.additional.where="nothing"):i>=176&&i<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),i>=128&&i<=191&&([e.description,e.additional.banknote]=o(this,w,Js).call(this,t[2]),e.no_code=74+i),o(this,w,Kn).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},na=function(t,e){const i=parseInt(t,16);return i===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):i===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:i===1}),e},ia=function(t,e){const i=parseInt(t[2],16),s=parseInt(t[3],16);return i===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):i===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),s===0?e.additional.scrow="Scrow disabled, banknote received automatic":s===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:i===1,scrow:s===1}),e},ra=function(t,e){e.no_code=6;const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={coins:{g50:i,c50:s,p1:a,p2:c,p5:l,p10:h}},this.coins.tubes.g50=i,this.coins.tubes.c50=s,this.coins.tubes.p1=a,this.coins.tubes.p2=c,this.coins.tubes.p5=l,this.coins.tubes.p10=h,this.coins.totals.g50=(this.coins.box.g50+i)*.5,this.coins.totals.c50=(this.coins.box.c50+s)*.5,this.coins.totals.p1=this.coins.box.p1+a,this.coins.totals.p2=(this.coins.box.p2+c)*2,this.coins.totals.p5=(this.coins.box.p5+l)*5,this.coins.totals.p10=(this.coins.box.p10+h)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e},sa=function(t,e){e.no_code=7;const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={banknotes:{b20:i,b50:s,b100:a,b200:c,b500:l,b1000:h}},this.banknotes.recycler.p20=i,this.banknotes.recycler.p50=s,this.banknotes.recycler.p100=a,this.banknotes.recycler.p200=c,this.banknotes.recycler.p500=l,this.banknotes.recycler.p1000=h,this.banknotes.totals.p20=(this.banknotes.stacker.p20+i)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+s)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+a)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+c)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+l)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+h)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e},aa=function(t,e){const i=parseInt(t,16);return i===1?e.name="Banknote accepted":i===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:i===1}),e},oa=function(t,e){const[i,s,a,c,l,h]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)],_=i*20+s*50+a*100+c*200+l*500+h*1e3;return e.name="Banknotes dispensed",e.description=_>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:i,b50:s,b100:a,b200:c,b500:l,b1000:h},total_dispensed:_},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},ca=function(t,e){return e.name="Coins dispensed",e.no_code=10,e.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change,this.dispatchAsync("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"coins"},500),e},la=function(t,e){const i=parseInt(t,16);return i===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):i===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e},ha=function(t,e){let i="closed";return t==="db"?(e.name="Door closed",e.no_code=13):t==="dc"?(e.name="Door open",e.no_code=14,i="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,i="unknown"),this.__internal__.device.door_open=i==="open",this.dispatch("event:door",{open:i==="open"}),this.dispatch("door:event",{open:i==="open"}),e},ua=function(t,e){const i=parseInt(t[2],16)*255,s=parseInt(t[3],16),a=(i+s)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${a}`,e.additional={high:i,low:s,temperature:parseFloat(a.toString())},this.dispatch("status:temperature",e.additional),e},da=function(t,e){const i=parseInt(t,16);let s="unknown";return i===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,s="on"):i===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,s="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:s==="on"}),e},pa=function(t,e){const i=parseInt(t[2],16);if(e.no_code=20+i,e.name="Status unknown",e.description="The status of card reader does not identified correctly",i===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(i===1||i===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(i===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(i===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(i===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(i===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(i===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(i===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(i===10){const s=parseInt(t[8],16);s===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):s===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e},ht=function(t,e){return this.appendToQueue(o(this,w,Je).call(this,t),e)},Je=function(t){return t[11]=this.serialBoardroidSumHex(t),t.map((e,i)=>{t[i]=this.hexMaker(e)}),t},_a=function({enable:t=!1,scrow:e=!1}={}){const i=t?"FF":"00",s=e?"FF":"00";return["F1","C0",i,i,s,s,"00","00","00","00","F2","00"]},fa=function({enable:t=!1,scrow:e=!1}={}){return["F1","C0",t?"01":"00",e?"01":"00","00","00","00","00","00","00","F2","00"]},ga=function(t=1){if(t<1)throw new Error("No banknotes to dispense");return t=this.decToHex(t),["F1","C5",this.decToHex(this.__banknote_purse.recycler.banknote.toString()),t,"00","00","00","00","00","00","F2","00"]},ya=function({$_20:t=0,$_50:e=0,$_100:i=0,$_200:s=0,$_500:a=0,$_1000:c=0}={}){if([t,e,i,s,a,c].some(l=>isNaN(l)||typeof l=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&i<1&&s<1&&a<1&&c<1)throw new Error("No banknotes to dispense");return[t,e,i,s,a,c]=[this.decToHex(t),this.decToHex(e),this.decToHex(i),this.decToHex(s),this.decToHex(a),this.decToHex(c)],["F1","C5",t,e,i,s,a,c,"00","00","F2","00"]},Wn=function(){L(this,Jt,!1),L(this,Ut,0),L(this,Qt,0)},Qe=function({dispensed:t=null,limit:e=80}={}){L(this,Qt,Math.round(O(this,Ut)*100/e)),this.dispatch("percentage:test",{percentage:O(this,Qt),dispensed:t})},ba=function(t){const e=["20","50","100","200","500"],i=this.__banknote_purse.recycler.banknote,s="$_"+e[i],a=parseInt(e[i]),c=this.banknotes.recycler[`p${e[i]}`],l=Math.min(Math.floor(t/a),c),h={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:l>0};return this.totalInRecycler===0||l<1||t===0||(h.banknotes[s]=l,h.pending=parseFloat((t-l*a).toFixed(2))),h},ma=function(t){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1};if(this.totalInRecycler===0||t===0)return e;const i=(s,a)=>{if(this.banknotes.recycler[a]>0){const c=Math.floor(e.pending/s),l=Math.min(c,this.banknotes.recycler[a]);e.banknotes[`$_${s}`]=l,e.pending=parseFloat((e.pending-l*s).toFixed(2))}};return i(1e3,"p1000"),i(500,"p500"),i(200,"p200"),i(100,"p100"),i(50,"p50"),i(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(s=>s>0),e},$n=function(t){return this.hasRecycler?o(this,w,Xe).call(this)?o(this,w,ba).call(this,t):o(this,w,ma).call(this,t):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1}},zn=function(t){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:t,will_dispense:!1};if(!this.hasCoinPurse||t<=0||this.totalInTubes===0)return e;const i=(s,a,c=null)=>{if(this.coins.tubes[a]>0){c===null&&(c="$_"+s);const l=Math.floor(e.pending/s),h=Math.min(l,this.coins.tubes[a]);e.coins[c]=h,e.pending=parseFloat((e.pending-h*s).toFixed(2))}};return i(10,"p10"),i(5,"p5"),i(2,"p2"),i(1,"p1"),i(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(s=>s>0),e},Gn=async function(t=null){if(!o(this,w,$s).call(this))throw new Error("Change not available");let e=this.change,i=this.change;if(t!==null&&(e=t,i=t),i<=0)return!1;const s=o(this,w,$n).call(this,i);i=s.pending;const a=o(this,w,zn).call(this,i);return i=a.pending,i>0&&this.dispatch("change:pending",{pending:i}),this.dispatch("change:dispense",{recycler:s.banknotes,coins:a.coins,pending:i,delivery:e-i}),i===e?!1:(s.will_dispense&&await this.banknotePurseDispense(s.banknotes),a.will_dispense&&await this.coinPurseDispense(a.coins),!0)};class Bc extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});Q(this,Zt);if(this.__internal__.device.type="arduino",k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,o(this,Zt,va).call(this),o(this,Zt,wa).call(this),this.getResponseAsString()}serialMessage(t){const e=this.stringToArrayHex(t),i=this.stringToArrayBuffer(t),s={original_code:e,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(s.code=t,t){case"connected":s.name="connected",s.description="Connection established",s.request="connect",s.no_code=100;break;case"created by danidoble":s.name="thanks",s.description="thanks for using this software",s.request="credits",s.no_code=101;break;case"hello there":s.name="hello there",s.description="hi human",s.request="hi",s.no_code=102;break;case"ara ara":s.name="ara ara",s.description="troll",s.request="ara ara",s.no_code=404;break;default:s.name="unknown",s.description="Unknown command",s.request="unknown",s.no_code=400;break}this.dispatch("serial:message",s)}serialSetConnectionConstant(t=1){return this.add0x(this.parseStringToBytes("CONNECT"))}async sayCredits(){const t=this.parseStringToBytes("CREDITS");await this.appendToQueue(t,"credits")}async sayHi(){const t=this.parseStringToBytes("HI");await this.appendToQueue(t,"hi")}async sayAra(){const t=this.parseStringToBytes("OTHER");await this.appendToQueue(t,"ara")}async sendCustomCode({code:t=""}={}){if(typeof t!="string")throw new Error("Invalid string");const e=this.parseStringToBytes(t);await this.appendToQueue(e,"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}Zt=new WeakSet,wa=function(){k.add(this)},va=function(){};/**
|
|
49
50
|
* @license Webserial
|
|
50
51
|
* webserial
|
|
51
52
|
*
|