@danidoble/webserial 4.5.0-beta.1 → 4.5.0-beta.3
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/jsd.cjs +1 -1
- package/dist/jsd.js +4 -1
- package/dist/pinpax.cjs +1 -1
- package/dist/pinpax.js +19 -3
- package/dist/types/lib/commands/jsd/applications/licensing.d.ts.map +1 -1
- package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts +3 -0
- package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts.map +1 -1
- package/dist/types/lib/commands/jsd/types/jsd.types.d.ts +1 -0
- package/dist/types/lib/commands/jsd/types/jsd.types.d.ts.map +1 -1
- package/dist/types/lib/serial/pinpax.d.ts +6 -6
- package/dist/types/lib/serial/pinpax.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/jsd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./webserial-core-CrutKvJa.cjs"),N=require("./devices-CcYKrJpP.cjs");class _{static USE_BIG_ENDIAN=!0;static USE_REFLECTED=!1;static calculate(e){let t;if(this.USE_REFLECTED){t=0;for(const s of e){t^=s&255;for(let n=0;n<8;n++)t&1?t=t>>1^40961:t>>=1}}else{t=0;for(const s of e){t^=s<<8;for(let n=0;n<8;n++)t&32768?t=(t<<1^32773)&65535:t=t<<1&65535}}return this.USE_BIG_ENDIAN?[t>>8&255,t&255]:[t&255,t>>8&255]}static getConfig(){return{bigEndian:this.USE_BIG_ENDIAN,reflected:this.USE_REFLECTED}}}class b{_name="tcpip";get name(){return this._name}get packetId(){return 0}_overridePacketId(e){console.warn(`TCP/IP transport does not use packet IDs. Ignoring override to ${e}.`)}toLittleEndian(e){return[e&255,e>>8&255]}buildPacket(e,t,s){const n=t?t.split("").map(h=>h.charCodeAt(0)):[],a=6+n.length,i=this.toLittleEndian(a),c=this.toLittleEndian(s),o=this.toLittleEndian(e);return{bytes:[...i,...c,...o,...n],packetId:0}}escapeBytes(e){const t=[];for(const s of e)s===192?t.push(219,220):s===219?t.push(219,221):t.push(s);return t}buildAckPacket(e){const n=[192,2,e],[a,i]=_.calculate(n),c=[2,e,a,i];return[192,...this.escapeBytes(c),192]}}class k extends b{packetIdCounter=1;_name="rs232";get packetId(){return this.packetIdCounter}_overridePacketId(e){this.packetIdCounter=e&255}getNextPacketId(){const e=this.packetIdCounter;return this.packetIdCounter=this.packetIdCounter+1&255,this.packetIdCounter===0&&(this.packetIdCounter=1),e}buildPacket(e,t,s){const i=this.getNextPacketId(),{bytes:c}=super.buildPacket(e,t,s),o=[192,1,i,...c],[h,d]=_.calculate(o),l=[1,i,...c,h,d];return{bytes:[192,...this.escapeBytes(l),192],packetId:i}}}const r={requestMachineStatus:100,requestStatusChannel:101,requestStatusSelection:102,configureSelectionDispense:103,addChannelToSelection:104,requestMachineIdentification:105,programWorkingTemperature:106,programWaitingTimings:107,resetSoldOutChannels:108,programTimeWaitingAfterPickup:109,requestJSDVersion:110,requestFaultMachine:111,manageJSDDispensingQueue:112,defineSpecialCharacteristicsSelection:113,configurePerishableProducts:114,requestActiveFaults:115,configureExtendedDispenseStatusData:116,requestStatusTrayPositioningPhototransistors:117,dispenseFromChannel:150,dispenseFromSelection:151,controlLights:152,resetFaultsAndSelfTest:153,performCollectCycle:154,dispenseFromChannelExtended:155,restartingTheJSDKnowingThatItIsDangerous:156,responseFormatCmdWrong:200,responseMachineStatus:201,responseStatusChannel:202,responseStatusSelection:203,responseDispenseStatus:204,responseConfigurationSelectionDispense:205,responseConfigurationChannelsLinkedToSelection:206,responseMachineIdentification:207,responseCurrentTemperature:208,responseReportEventsAlarmsAndFaults:209,responseNewTimingWaitingForProductCollection:210,responsePerformingProductCollectionCycle:211,responseResetMachineSoldOutChannels:212,responseNewTimingWaitingAfterProductCollection:213,responseJSDVersion:214,responseActiveFaults:215,responseJSDDispensingQueue:216,responseSpecialCharacteristicsSelection:217,responsePerishableProducts:218,responseActiveFaultsList:219,responseJSDResetStatus:220,responseExtendedDispenseStatusData:221,responseTraysPositioningPhototransistorsStatus:222,jsdErrorLicenseTemporarilyBlocked:300,jsdErrorLicenseNotActive:301,jsdErrorCommandNotExecutable:302},C=p=>Object.keys(r).find(t=>r[t]===p)||"Unknown",f={VISION:402,LICENSING:600,MANIFESTS_AND_LOGS:601,SIMULATOR_VISION:1e4},L=p=>[f.VISION,f.SIMULATOR_VISION].includes(p),w=p=>[f.LICENSING].includes(p),F=p=>[f.MANIFESTS_AND_LOGS].includes(p);class u{transport;static APP_ID=f.VISION;constructor(e){this.transport=e}static connection({transport:e,packetId:t}){return e._overridePacketId(t||255),new u(e).requestJSDVersion()}requestMachineStatus({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestMachineStatus,t,u.APP_ID)}requestStatusChannel({machine:e,tray:t,channel:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.requestStatusChannel,n,u.APP_ID)}requestStatusSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.requestStatusSelection,t,u.APP_ID)}configureSelectionDispense({selection:e,speed:t,timePostRun:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.configureSelectionDispense,n,u.APP_ID)}getSelectionDispenseConfig({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.configureSelectionDispense,t,u.APP_ID)}addChannelToSelection({selection:e,machine:t,tray:s,channel:n}){const a=`${e},${t},${s},${n}`;return this.transport.buildPacket(r.addChannelToSelection,a,u.APP_ID)}getChannelsLinkedToSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.addChannelToSelection,t,u.APP_ID)}requestMachineIdentification({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestMachineIdentification,t,u.APP_ID)}formatTemperature(e){const t=e>=0?"+":"-",s=Math.abs(e).toFixed(1).padStart(4,"0");return`${t}${s}`}programWorkingTemperature({machine:e,temperature:t,enable:s}){const n=this.formatTemperature(t),i=`${e},${n},${s?1:0}`;return this.transport.buildPacket(r.programWorkingTemperature,i,u.APP_ID)}getWorkingTemperature({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.programWorkingTemperature,t,u.APP_ID)}programWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.programWaitingTimings,n,u.APP_ID)}getWaitingTimings(){return this.transport.buildPacket(r.programWaitingTimings,"",u.APP_ID)}resetSoldOutChannels({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.resetSoldOutChannels,t,u.APP_ID)}programTimeWaitingAfterPickup({time:e}){const t=`${e}`;return this.transport.buildPacket(r.programTimeWaitingAfterPickup,t,u.APP_ID)}getTimeWaitingAfterPickup(){return this.transport.buildPacket(r.programTimeWaitingAfterPickup,"",u.APP_ID)}requestJSDVersion(){return this.transport.buildPacket(r.requestJSDVersion,"",u.APP_ID)}requestFaultMachine({machine:e,type:t}){const n=`${e},${{"report-active":0,"report-inactive":1,"clear-inactive":2}[t]}`;return this.transport.buildPacket(r.requestFaultMachine,n,u.APP_ID)}requestReportActiveFaults(e){return this.requestFaultMachine({machine:e,type:"report-active"})}requestReportInactiveFaults(e){return this.requestFaultMachine({machine:e,type:"report-inactive"})}requestClearInactiveFaults(e){return this.requestFaultMachine({machine:e,type:"clear-inactive"})}manageJSDDispensingQueue({type:e}){const t=`${e}`;return this.transport.buildPacket(r.manageJSDDispensingQueue,t,u.APP_ID)}requestJSDDispensingQueueStatus(){return this.manageJSDDispensingQueue({type:0})}clearJSDDispensingQueue(){return this.manageJSDDispensingQueue({type:1})}defineSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a}){const d=`${e},${t?1:0},${s?1:0},${n==="lower"?0:1},${a}`;return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection,d,u.APP_ID)}getSpecialCharacteristicsSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection,t,u.APP_ID)}configurePerishableProducts({machine:e,enable:t,temperatureLimit:s,minutesToExpiry:n}){const a=t?1:0,i=this.formatTemperature(s),c=`${e},${a},${i},${n}`;return this.transport.buildPacket(r.configurePerishableProducts,c,u.APP_ID)}requestActiveFaults({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestActiveFaults,t,u.APP_ID)}configureExtendedDispenseStatusData({enable:e}){const s=`${e?1:0}`;return this.transport.buildPacket(r.configureExtendedDispenseStatusData,s,u.APP_ID)}getExtendedDispenseStatusDataConfig(){return this.transport.buildPacket(r.configureExtendedDispenseStatusData,"",u.APP_ID)}requestStatusTrayPositioningPhototransistors({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestStatusTrayPositioningPhototransistors,t,u.APP_ID)}dispenseFromChannel({token:e,machine:t,tray:s,channel:n,speed:a,timePostRun:i}){const c=`${e},${t},${s},${n},${a},${i}`;return this.transport.buildPacket(r.dispenseFromChannel,c,u.APP_ID)}getDispenseStatusFromChannel({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromChannel,t,u.APP_ID)}dispenseFromSelection({token:e,selection:t}){const s=`${e},${t}`;return this.transport.buildPacket(r.dispenseFromSelection,s,u.APP_ID)}getDispenseStatusFromSelection({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromSelection,t,u.APP_ID)}controlLights({machine:e,turnOn:t}){const n=`${e},${t?1:0}`;return this.transport.buildPacket(r.controlLights,n,u.APP_ID)}resetFaultsAndSelfTest({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.resetFaultsAndSelfTest,t,u.APP_ID)}performCollectCycle({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.performCollectCycle,t,u.APP_ID)}dispenseFromChannelExtended({token:e,machine:t,tray:s,channel:n,speed:a,timePostRun:i,fragileOrHeavy:c,typeAdjustElevator:o,timeAdjustElevator:h}){const I=`${e},${t},${s},${n},${a},${i},${c?1:0},${o==="lower"?0:1},${h}`;return this.transport.buildPacket(r.dispenseFromChannelExtended,I,u.APP_ID)}getDispenseStatusFromChannelExtended({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromChannelExtended,t,u.APP_ID)}restartingTheJSDKnowingThatItIsDangerous(){return this.transport.buildPacket(r.restartingTheJSDKnowingThatItIsDangerous,"",u.APP_ID)}}function q(p){if(p.length>5)throw new Error(`Token must be max 5 characters, got ${p.length}`);return p}function T(){let p;do{const e=new Uint8Array(2);p=parseInt(crypto.getRandomValues(e).toString().replaceAll(",","")).toString(36)}while(p.length>5);return q(p)}const E={status:"NO-CONNECTED",machineInService:!1,doorOpen:!1,availabilityToDispense:"NOT-AVAILABLE-TO-DISPENSE",hasLightsOn:!1,temperature:""};class M{_commands;jsd;APP_ID=f.VISION;_machineStatus=[{...E},{...E},{...E},{...E}];constructor(e,t){this._commands=new u(t),this.jsd=e}_performingChannelAssignment={enabled:!1,selections:[],currentSelection:1};_dispensingTokens={};async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}_getMachineIndex(e){return e-1}isAvailableToDispense({machine:e=1}={}){const t=this._getMachineIndex(e);return["ELEVATOR-COLLECTION-POSITION","AVAILABLE-TO-DISPENSE"].includes(this._machineStatus[t]?.availabilityToDispense||"")&&this._machineStatus[t]?.machineInService===!0&&this._machineStatus[t]?.doorOpen===!1&&this._machineStatus[t]?.status==="CONNECTED"}async requestMachineStatus({machine:e=1}={}){const t=this._getMachineIndex(e),s=this.cmd.requestMachineStatus({machine:t});return await this.send(s,{alias:"requestMachineStatus"})}_getTrayChannelFromSelection(e){const t=Math.floor((e-1)/10)+11,s=(e-1)%10;return{tray:t,channel:s}}_getSelectionFromTrayChannel(e,t){return(e-11)*10+t+1}async requestStatusChannel({machine:e,selection:t}){const s=this._getMachineIndex(e),{tray:n,channel:a}=this._getTrayChannelFromSelection(t),i=this.cmd.requestStatusChannel({machine:s,tray:n,channel:a});return await this.send(i,{alias:"requestStatusChannel"})}async assignChannels({machine:e}){if(this._performingChannelAssignment.enabled)throw new Error("Channel assignment already in progress");this._performingChannelAssignment.enabled=!0;for(let t=1;t<=80;t++)await this.requestStatusChannel({machine:e,selection:t});return new Promise(t=>{const s=setInterval(()=>{if(this._performingChannelAssignment.enabled)return;clearInterval(s);const n=this._performingChannelAssignment.selections;this._performingChannelAssignment.selections=[],t(n)},200)})}async requestStatusSelection({selection:e}){const t=this.cmd.requestStatusSelection({selection:e});return await this.send(t,{alias:"requestStatusSelection"})}async configureSelectionDispense({selection:e,speed:t,timePostRun:s}){const n=this.cmd.configureSelectionDispense({selection:e,speed:t,timePostRun:s});return await this.send(n,{alias:"configureSelectionDispense"})}async requestSelectionDispenseConfig({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.getSelectionDispenseConfig({machine:t});return await this.send(s,{alias:"getSelectionDispenseConfig"})}async configureAddChannelToSelection({selection:e,machine:t,tray:s,channel:n}){const a=this._getMachineIndex(t),i=this.cmd.addChannelToSelection({selection:e,machine:a,tray:s,channel:n});return await this.send(i,{alias:"addChannelToSelection"})}async requestChannelsLinkedToSelection({selection:e}){const t=this.cmd.getChannelsLinkedToSelection({selection:e});return await this.send(t,{alias:"getChannelsLinkedToSelection"})}async requestMachineIdentification({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestMachineIdentification({machine:t});return await this.send(s,{alias:"requestMachineIdentification"})}async configureWorkingTemperature({machine:e,temperature:t,enable:s}){const n=this._getMachineIndex(e),a=this.cmd.programWorkingTemperature({machine:n,temperature:t,enable:s});return await this.send(a,{alias:"programWorkingTemperature"})}async requestWorkingTemperature({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.getWorkingTemperature({machine:t});return await this.send(s,{alias:"getWorkingTemperature"})}async configureWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s}){const n=this.cmd.programWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s});return await this.send(n,{alias:"programWaitingTimings"})}async requestWaitingTimings(){const e=this.cmd.getWaitingTimings();return await this.send(e,{alias:"getWaitingTimings"})}async resetSoldOutChannels({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.resetSoldOutChannels({machine:t});return await this.send(s,{alias:"resetSoldOutChannels"})}async resetAllErrors({machine:e}){return await Promise.all([this.clearInactiveFaults({machine:e}),this.resetSoldOutChannels({machine:e}),this.resetFaultsAndSelfTest({machine:e})])}async configureTimeWaitingAfterPickup({time:e}){const t=this.cmd.programTimeWaitingAfterPickup({time:e});return await this.send(t,{alias:"programTimeWaitingAfterPickup"})}async requestTimeWaitingAfterPickup(){const e=this.cmd.getTimeWaitingAfterPickup();return await this.send(e,{alias:"getTimeWaitingAfterPickup"})}async requestJSDVersion(){const e=this.cmd.requestJSDVersion();return await this.send(e,{alias:"requestJSDVersion"})}async requestReportActiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestReportActiveFaults(t);return await this.send(s,{alias:"requestReportActiveFaults"})}async requestReportInactiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestReportInactiveFaults(t);return await this.send(s,{alias:"requestReportInactiveFaults"})}async clearInactiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestClearInactiveFaults(t);return await this.send(s,{alias:"requestClearInactiveFaults"})}async requestJSDDispensingQueueStatus(){const e=this.cmd.requestJSDDispensingQueueStatus();return await this.send(e,{alias:"requestJSDDispensingQueueStatus"})}async clearJSDDispensingQueue(){const e=this.cmd.clearJSDDispensingQueue();return await this.send(e,{alias:"clearJSDDispensingQueue"})}async configureSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a}){const i=this.cmd.defineSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a});return await this.send(i,{alias:"defineSpecialCharacteristicsSelection"})}requestSpecialCharacteristicsSelection({selection:e}){const t=this.cmd.getSpecialCharacteristicsSelection({selection:e});return this.send(t,{alias:"getSpecialCharacteristicsSelection"})}configurePerishableProducts({machine:e,enable:t,temperatureLimit:s,minutesToExpiry:n}){const a=this._getMachineIndex(e),i=this.cmd.configurePerishableProducts({machine:a,enable:t,temperatureLimit:s,minutesToExpiry:n});return this.send(i,{alias:"configurePerishableProducts"})}async requestActiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestActiveFaults({machine:t});return await this.send(s,{alias:"requestActiveFaults"})}async configureExtendedDispenseStatusData({enable:e}){const t=this.cmd.configureExtendedDispenseStatusData({enable:e});return await this.send(t,{alias:"configureExtendedDispenseStatusData"})}async requestExtendedDispenseStatusDataConfig(){const e=this.cmd.getExtendedDispenseStatusDataConfig();return await this.send(e,{alias:"getExtendedDispenseStatusDataConfig"})}async requestStatusTrayPositioningPhototransistors({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestStatusTrayPositioningPhototransistors({machine:t});return await this.send(s,{alias:"requestStatusTrayPositioningPhototransistors"})}async dispenseFromChannel({machine:e,tray:t,channel:s,speed:n,timePostRun:a,cart:i=!1}){if(!this.isAvailableToDispense({machine:e}))throw new Error(`Machine ${e} is not available to dispense`);const c=this._getMachineIndex(e),o=T(),h=this.cmd.dispenseFromChannel({token:o,machine:c,tray:t,channel:s,speed:n,timePostRun:a});return await this.send(h,{alias:"dispenseFromChannel"}),this._dispensingTokens[o]={cart:!!i,resolve:()=>{delete this._dispensingTokens[o]},reject:()=>{}},new Promise((d,l)=>{this._dispensingTokens[o].resolve=d,this._dispensingTokens[o].reject=l})}async dispense({machine:e,selection:t,speed:s,timePostRun:n,cart:a=!1}){const{tray:i,channel:c}=this._getTrayChannelFromSelection(t);return this.dispenseFromChannel({machine:e,tray:i,channel:c,speed:s||5,timePostRun:n||0,cart:!!a})}async dispenseCart(e=[]){const t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));let s=[];for(const n of t)try{const a=await Promise.all(n.map(o=>this.dispense({machine:o.machine,selection:o.selection,cart:!0}))),i=[...new Set(n.map(o=>o.machine))];await new Promise(o=>{const h=setInterval(()=>{i.every(l=>this.getMachineStatus(l)?.availabilityToDispense==="AVAILABLE-TO-DISPENSE")&&(clearInterval(h),o(!0))},300)});for(const o of i)this._machineStatus[this._getMachineIndex(o)]?.availabilityToDispense==="WAITING-COLLECTION"&&this.emit("waiting-collection",{machine:o!==null?o+1:null});const c=n.map((o,h)=>({machine:o.machine,selection:o.selection,dispensed:a[h]}));s=s.concat(c)}catch(a){console.error("Error sending dispense command:",a)}return s}async requestDispenseStatusFromChannel({token:e}){const t=this.cmd.getDispenseStatusFromChannel({token:e});return await this.send(t,{alias:"getDispenseStatusFromChannel"})}async dispenseFromSelection({selection:e,cart:t=!1}){const s=T(),n=this.cmd.dispenseFromSelection({token:s,selection:e});return await this.send(n,{alias:"dispenseFromSelection"}),this._dispensingTokens[s]={cart:!!t,resolve:()=>{},reject:()=>{}},new Promise((a,i)=>{this._dispensingTokens[s].resolve=a,this._dispensingTokens[s].reject=i})}async requestDispenseStatusFromSelection({token:e}){const t=this.cmd.getDispenseStatusFromSelection({token:e});return await this.send(t,{alias:"getDispenseStatusFromSelection"})}async _configureLights({machine:e,turnOn:t,alias:s}){const n=this._getMachineIndex(e),a=this.cmd.controlLights({machine:n,turnOn:t});return await this.send(a,{alias:s})}async lightsOn({machine:e}){return this._configureLights({machine:e,turnOn:!0,alias:"lightsOn"})}async lightsOff({machine:e}){return this._configureLights({machine:e,turnOn:!1,alias:"lightsOff"})}async resetFaultsAndSelfTest({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.resetFaultsAndSelfTest({machine:t});return await this.send(s,{alias:"resetFaultsAndSelfTest"})}async collect({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.performCollectCycle({machine:t});return await this.send(s,{alias:"performCollectCycle"})}async dispenseFromChannelExtended({machine:e,tray:t,channel:s,speed:n,timePostRun:a,fragileOrHeavy:i,typeAdjustElevator:c,timeAdjustElevator:o,cart:h=!1}){if(!this.isAvailableToDispense({machine:e}))throw new Error(`Machine ${e} is not available to dispense`);const d=this._getMachineIndex(e),l=T(),m=this.cmd.dispenseFromChannelExtended({token:l,machine:d,tray:t,channel:s,speed:n,timePostRun:a,fragileOrHeavy:i,typeAdjustElevator:c,timeAdjustElevator:o});return await this.send(m,{alias:"dispenseFromChannelExtended"}),this._dispensingTokens[l]={cart:!!h,resolve:()=>{},reject:()=>{}},new Promise((I,D)=>{this._dispensingTokens[l].resolve=I,this._dispensingTokens[l].reject=D})}async requestDispenseStatusFromChannelExtended({token:e}){const t=this.cmd.getDispenseStatusFromChannelExtended({token:e});return await this.send(t,{alias:"getDispenseStatusFromChannelExtended"})}async restartJSD(){const e=this.cmd.restartingTheJSDKnowingThatItIsDangerous();return await this.send(e,{alias:"restartingTheJSDKnowingThatItIsDangerous"})}serialMessage(e){switch(e.opcode){case r.responseFormatCmdWrong:this._responseFormatCmdWrong(e);break;case r.responseMachineStatus:this._responseMachineStatus(e);break;case r.responseStatusChannel:this._responseStatusChannel(e);break;case r.responseStatusSelection:this._responseStatusSelection(e);break;case r.responseDispenseStatus:this._responseDispenseStatus(e);break;case r.responseConfigurationSelectionDispense:this._responseConfigurationSelectionDispense(e);break;case r.responseConfigurationChannelsLinkedToSelection:this._responseConfigurationChannelsLinkedToSelection(e);break;case r.responseMachineIdentification:this._responseMachineIdentification(e);break;case r.responseCurrentTemperature:this._responseCurrentTemperature(e);break;case r.responseReportEventsAlarmsAndFaults:this._responseReportEventsAlarmsAndFaults(e);break;case r.responseNewTimingWaitingForProductCollection:this._responseNewTimingWaitingForProductCollection(e);break;case r.responsePerformingProductCollectionCycle:this._responsePerformingProductCollectionCycle(e);break;case r.responseResetMachineSoldOutChannels:this._responseResetMachineSoldOutChannels(e);break;case r.responseNewTimingWaitingAfterProductCollection:this._responseNewTimingWaitingAfterProductCollection(e);break;case r.responseJSDVersion:this._responseJSDVersion(e);break;case r.responseActiveFaults:this._responseActiveFaults(e);break;case r.responseJSDDispensingQueue:this._responseJSDDispensingQueue(e);break;case r.responseSpecialCharacteristicsSelection:this._responseSpecialCharacteristicsSelection(e);break;case r.responsePerishableProducts:this._responsePerishableProducts(e);break;case r.responseActiveFaultsList:this._responseActiveFaultsList(e);break;case r.responseJSDResetStatus:this._responseJSDResetStatus(e);break;case r.responseExtendedDispenseStatusData:this._responseExtendedDispenseStatusData(e);break;case r.responseTraysPositioningPhototransistorsStatus:this._responseTraysPositioningPhototransistorsStatus(e);break;case r.jsdErrorLicenseTemporarilyBlocked:this._responseJsdErrorLicenseTemporarilyBlocked(e);break;case r.jsdErrorLicenseNotActive:this._responseJsdErrorLicenseNotActive(e);break;case r.jsdErrorCommandNotExecutable:this._responseJsdErrorCommandNotExecutable(e);break}}emit(e,...t){this.jsd.dispatch(`vision:${e}`,...t)}_responseFormatCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=C(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}setMachineStatus(e,t){this._machineStatus[e]=t}getMachineStatus(e){const t=this._getMachineIndex(e);return this._machineStatus[t]||null}_getMachineStatusName(e){switch(e){case 0:return"NO-CONNECTED";case 1:return"CONNECTED";case 2:return"LOST"}}_responseMachineStatus(e){const[t,s,n,a,i,c,o]=e.params,h={0:"AVAILABLE-TO-DISPENSE",1:"NOT-AVAILABLE-TO-DISPENSE",2:"ALREADY-DISPENSING",3:"WAITING-COLLECTION",4:"ELEVATOR-COLLECTION-POSITION",5:"UNCOLLECTED"},d={status:this._getMachineStatusName(parseInt(s,10)),machineInService:parseInt(n,10)===1,doorOpen:parseInt(a,10)===0,availabilityToDispense:h[i]||"NOT-AVAILABLE-TO-DISPENSE",hasLightsOn:isNaN(parseInt(c,10))?!1:parseInt(c,10)===1,temperature:o||""};this.setMachineStatus(parseInt(t,10),d),this.emit("machine-status",{machine:parseInt(t,10)+1,...d}),this.emit("door",{open:d.doorOpen,machine:parseInt(t,10)+1}),this.emit("connection",{connected:d.status==="CONNECTED",machine:parseInt(t,10)+1})}_statusChannelName(e){switch(e){case 0:return"NO-CONNECTED";case 1:return"AVAILABLE";case 2:return"SOLD-OUT";case 3:return"FAULT";default:return"NO-CONNECTED"}}_responseStatusChannel(e){const[t,s,n,a]=e.params,i=this._statusChannelName(parseInt(a,10)),c=this._getSelectionFromTrayChannel(Number(s),Number(n)),o=["AVAILABLE","SOLD-OUT"].includes(i);if(this._performingChannelAssignment.enabled){this._performingChannelAssignment.selections.push({selection:c,active:o,machine:Number(t)+1}),this._performingChannelAssignment.currentSelection=this._performingChannelAssignment.selections.length;const h=this._performingChannelAssignment.currentSelection/80*100;this.emit("channels-progress",{progress:Math.min(100,Math.round(h*100)/100),current:this._performingChannelAssignment.currentSelection,verified:this._performingChannelAssignment.selections.length}),this._performingChannelAssignment.selections.length>=80&&(this.emit("channels",this._performingChannelAssignment.selections),this._performingChannelAssignment.enabled=!1)}else this.emit("channel-status",{machine:Number(t)+1,selection:c,active:o})}_statusSelectionName(e){switch(e){case 0:return"NO-CONFIGURED";case 1:return"ASSOCIATED";case 2:return"NO-ASSOCIATED";case 3:return"NO-VISION-OWNED";case 4:return"EXPIRED";default:return"NO-CONFIGURED"}}_responseStatusSelection(e){const[t,s]=e.params,n=this._statusSelectionName(parseInt(s,10));this.emit("status-selection",{selection:Number(t),status:n})}_responseDispenseStatus(e){const[t,s,n,a]=e.params,i={0:"RECEIVED",1:"IN-PROGRESS",2:"WAITING-COLLECTION",3:"COLLECTED",4:"NO-PERFORMED",5:"TOKEN-NOT-FOUND",6:"QUEUE-FULL",7:"CHANNEL-NO-CONNECTED",8:"SELECTION-UNAVAILABLE",9:"FAILED-DISPENSE",10:"UNCOLLECTED",11:"DISPENSED-CAN-MULTIPLE",12:"DISPENSE-CANCELLED",13:"PRODUCT-EXPIRED"},c=Object.values(i).filter(D=>["NO-PERFORMED","TOKEN-NOT-FOUND","QUEUE-FULL","CHANNEL-NO-CONNECTED","SELECTION-UNAVAILABLE","FAILED-DISPENSE","DISPENSE-CANCELLED","PRODUCT-EXPIRED","UNCOLLECTED"].includes(D)),o={0:"NONE",1:"DOOR-OPEN",2:"MACHINE-NOT-AVAILABLE",3:"ERROR-PHOTOSENSORS",4:"ERROR-MOTOR-POWER-CONSUMPSION-DETECTOR",5:"ALREADY-SOLD-OUT",6:"ERROR-TEST-PRODUCT-DETECTOR",7:"SOLD-OUT",8:"ELEVATOR-CANT-REACH-TRAY",9:"UNCOLLECTED",10:"MACHINE-RESET-DURING-DISPENSE",11:"MACHINE-COMMUNICATION-ERROR",12:"MACHINE-COMMUNICATION-LOST",13:"NO-VISION",14:"PRODUCT-PERISHABLE-EXPIRED",20:"DECIDE"},h=i[parseInt(s,10)]||"UNKNOWN",[d,l,m]=n&&n.trim()!==""?n.split(".").map(D=>parseInt(D,10)):[null,null,null],I=a?o[parseInt(a,10)]||"UNKNOWN":null;this._dispensingTokens[t]&&(this._dispensingTokens[t].cart===!1&&h==="WAITING-COLLECTION"?(this._dispensingTokens[t].resolve(!0),delete this._dispensingTokens[t],this.emit("waiting-collection",{machine:d!==null?d+1:null})):this._dispensingTokens[t].cart===!0&&h==="DISPENSED-CAN-MULTIPLE"?(this._dispensingTokens[t].resolve(!0),delete this._dispensingTokens[t]):c.includes(h)&&(this._dispensingTokens[t].resolve(!1),delete this._dispensingTokens[t])),h==="IN-PROGRESS"&&this.emit("dispensing",{token:t,machine:d!==null?d+1:null,tray:l!==null?l:null,channel:m!==null?m:null,selection:m!==null&&l!==null?this._getSelectionFromTrayChannel(l,m):null}),this.emit("dispense-status",{token:t,status:h,machine:d!==null?d+1:null,tray:l!==null?l:null,channel:m!==null?m:null,extendedStatus:I})}_responseConfigurationSelectionDispense(e){const[t,s,n]=e.params;this.emit("selection-dispense-config",{selection:Number(t),speed:Number(s),timePostRun:Number(n)})}_responseConfigurationChannelsLinkedToSelection(e){const[t,...s]=e.params,a=s[s.length-1].includes(":")?s.pop():null,i={0:"OK",1:"ALREADY-DEFINED",2:"OUT-OF-RANGE"},c=s.map(o=>{const[h,d,l]=o.split(":");return{machine:parseInt(h,10)+1,tray:parseInt(d,10),channel:parseInt(l,10)}});this.emit("channels-linked-to-selection",{selection:Number(t),linkedChannels:c,status:a?i[parseInt(a,10)]||"UNKNOWN":null})}_responseMachineIdentification(e){const[t,s,n,a]=e.params;this.emit("machine-id",{machine:parseInt(t,10)+1,model:s,serialNumber:n,firmwareVersion:a})}_responseCurrentTemperature(e){const[t,s,n,a,i]=e.params,c=parseInt(t,10)+1,o=parseInt(i,10)===1?"ON":"OFF";this.emit("current-temperature",{machine:c,workingTemperature:s,currentTemperatureInsideMachine:n,currentTemperatureAir:a,coolUnitStatus:o})}_responseReportEventsAlarmsAndFaults(e){const[t,s,n]=e.params,a=parseInt(t,10)+1,i={1:"Product detector",2:"None of the motors are connected. Possible control board faulty",3:"Channels jamp detector error",4:"Temperature control error",5:"Elevator faulty",6:"Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",7:"Elevator tester (flap), ES-Plus, faulty",8:"Product expired (perishable)"};this.emit("alarm-faults-events",{machine:a,event:i[parseInt(s,10)]||"UNKNOWN",status:parseInt(n,10)===1?"ACTIVE":"CLEARED"})}_responseNewTimingWaitingForProductCollection(e){const[t,s,n]=e.params;this.emit("time-waiting-for-product-collection",{minutesProductCollection:Number(t),secondsTimeBetweenDispenseManoeuvres:Number(s),secondsBetweenCollectAndStartNextDispense:Number(n)})}_responsePerformingProductCollectionCycle(e){const[t,s]=e.params,n={0:"Manoeuvre has started",1:"Wron machine number",2:"Machine no connected",3:"Wron machine model",4:"Machine cannot perform collection now",5:"Communication error with machine"};this.emit("collect",{machine:parseInt(t,10)+1,status:n[parseInt(s,10)]||"UNKNOWN"})}_responseResetMachineSoldOutChannels(e){const[t,s]=e.params,n={0:"Reset performed",1:"Wrong machine number",2:"Machine not connected",3:"Communication error with machine"};this.emit("reset-sold-out-channels",{machine:parseInt(t,10)+1,status:n[parseInt(s,10)]||"UNKNOWN"})}_responseNewTimingWaitingAfterProductCollection(e){const[t]=e.params;this.emit("time-waiting-after-product-collection",{secondsBetweenCollectAndStartNextDispense:Number(t)})}_responseJSDVersion(e){const[t,s,n,a]=e.params;this.emit("jsd-version",{name:t,compileNumber:s,compileDate:n,description:a})}_responseActiveFaults(e){const[t,s,n,a,i,c,o]=e.params;this.emit("active-faults",{machine:parseInt(t,10)+1,status:parseInt(s,10)===1?"ACTIVE":"CLEARED",fault:parseInt(n,10),appearancesNumber:parseInt(a,10),partialNumberActivated:parseInt(i,10),minutesActive:parseInt(c,10),date:o})}_responseJSDDispensingQueue(e){const[t,s,n]=e.params;this.emit("jsd-dispensing-queue",{free:parseInt(t,10),processed:parseInt(s,10),notProcessed:parseInt(n,10)})}_responseSpecialCharacteristicsSelection(e){const[t,s,n,a,i]=e.params;this.emit("special-characteristics-selection",{selection:Number(t),perishable:parseInt(s,10)===1,fragileOrHeavy:parseInt(n,10)===1,typeAdjustElevator:a==="0"?"lower":"upper",timeAdjustElevator:Number(i)})}_responsePerishableProducts(e){const[t,s,n,a,i]=e.params;this.emit("perishable-products-config",{machine:parseInt(t,10)+1,perishableActive:parseInt(s,10)===1,alarmPerisableTriggered:parseInt(n,10)===1,maxTemperature:a,minutesBeforeExpire:Number(i)})}_responseActiveFaultsList(e){const[t,...s]=e.params,n={1:"Product detector",2:"None of the motors are connected. Possible control board faulty",3:"Channels jamp detector error",4:"Temperature control error",5:"Elevator faulty",6:"Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",7:"Elevator tester (flap), ES-Plus, faulty",8:"Product expired (perishable)"},a=s.map(i=>({code:parseInt(i,10),description:n[parseInt(i,10)]||"UNKNOWN"}));this.emit("active-faults-list",{machine:parseInt(t,10)+1,faults:a,ok:s.length===0})}_responseJSDResetStatus(e){const[t]=e.params,s={0:"RESETED",1:"RECEIVED"};this.emit("jsd-status-reset",{type:s[parseInt(t,10)]||"UNKNOWN"})}_responseExtendedDispenseStatusData(e){const[t]=e.params;this.emit("extended-dispense-status-data",{enabled:parseInt(t,10)===1})}_responseTraysPositioningPhototransistorsStatus(e){const[t,s,n,a,i,c,o,h,d]=e.params,l={0:"OK",C:"SHORT-CIRCUIT",N:"TRAY-NOT-DETECTED"},m={machine:parseInt(t,10)+1,trays:{11:l[s]||null,12:l[n]||null,13:l[a]||null,14:l[i]||null,15:l[c]||null,16:l[o]||null,17:l[h]||null,18:l[d]||null}};this.emit("trays-positioning-phototransistors-status",m)}_responseJsdErrorLicenseTemporarilyBlocked(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"expired-license",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}_responseJsdErrorLicenseNotActive(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"app-number-not-licensed",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}_responseJsdErrorCommandNotExecutable(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"price-control-active-direct-dispense-not-allowed",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}}const g={requestLogsEvents:101,requestLogsByDate:102,requestForSendingManifest:110,sendManifestDataBlock:111,responseCmdWrong:200,responseLineLogEvent:201,responseManifestDataBlock:210,responseManifestCompleted:211},x=p=>Object.keys(g).find(t=>g[t]===p)||"Unknown";class P{transport;static APP_ID=f.MANIFESTS_AND_LOGS;constructor(e){this.transport=e}requestLogsEvents(e=!1){const s=`${e?"+":"0"}`;return this.transport.buildPacket(g.requestLogsEvents,s,P.APP_ID)}requestLogsByDate(e,t){const s=`${e},${t}`;return this.transport.buildPacket(g.requestLogsByDate,s,P.APP_ID)}requestForSendingManifest(e,t){const s=`${e},${t}`;return this.transport.buildPacket(g.requestForSendingManifest,s,P.APP_ID)}sendManifestDataBlock(e,t){const s=Array.from(t).map(a=>a.toString(2).padStart(8,"0")).join(" "),n=`${e},${s}`;return this.transport.buildPacket(g.sendManifestDataBlock,n,P.APP_ID)}}class R{_commands;jsd;APP_ID=f.MANIFESTS_AND_LOGS;_logs={status:"idle",data:[]};constructor(e,t){this._commands=new P(t),this.jsd=e}async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}async requestLogsEvent({previous:e}){const t=this.cmd.requestLogsEvents(e);return await this.send(t,{alias:"requestLogsEvents"})}async requestLogs(){if(["fetching","more"].includes(this._logs.status))throw new Error("Already fetching logs");return this._logs.status="fetching",this.requestLogsEvent({previous:!1}),new Promise(e=>{const t=setInterval(()=>{if(this._logs.status==="completed"){clearInterval(t);const s=this._logs.data;e(s)}else this._logs.status==="more"&&(this._logs.status="fetching",this.requestLogsEvent({previous:!0}))},100)})}async requestLogsByDate({since:e,until:t}){const s=c=>{const o=String(c.getMonth()+1).padStart(2,"0"),h=String(c.getDate()).padStart(2,"0"),d=String(c.getHours()).padStart(2,"0"),l=String(c.getMinutes()).padStart(2,"0"),m=String(c.getSeconds()).padStart(2,"0");return`${o}/${h}/${d}/${l}/${m}`},n=s(e),a=s(t),i=this.cmd.requestLogsByDate(n,a);return await this.send(i,{alias:"requestLogsByDate"})}async requestForSendingManifest({fileSizeBytes:e,crc:t}){const s=this.cmd.requestForSendingManifest(e,t);return await this.send(s,{alias:"requestForSendingManifest"})}async sendManifestDataBlock({prevBlockId:e,dataBlock:t}){const s=this.cmd.sendManifestDataBlock(e,t);return await this.send(s,{alias:"sendManifestDataBlock"})}serialMessage(e){switch(e.opcode){case g.responseCmdWrong:this._responseCmdWrong(e);break;case g.responseLineLogEvent:this._responseLineLogEvent(e);break;case g.responseManifestDataBlock:this._responseManifestDataBlock(e);break;case g.responseManifestCompleted:this._responseManifestCompleted(e);break}}emit(e,...t){this.jsd.dispatch(`manifest:${e}`,...t)}_responseCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=x(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}_responseLineLogEvent(e){const[...t]=e.params,s=t[0]==="END_LOG";if(s)this._logs.status="completed";else{const a=t.join(",");this._logs.data.push(a),this._logs.status==="fetching"&&(this._logs.status="more")}const n=s?"end":"log";this.emit("log",{type:n,log:t})}_responseManifestDataBlock(e){const[t,s,n]=e.params;this.emit("block",{blockId:parseInt(t,10),indexFile:parseInt(s,10),quantity:parseInt(n,10)})}_responseManifestCompleted(e){const[t]=e.params,s={0:"Success",1:"CRC Error",2:"Transference interrupted",3:"Reset JSD and try again"};this.emit("completed",{result:s[t]||"Unknown Result",resultKey:parseInt(t,10)})}}const S={requestFeatureStatus:100,requestTemporaryLicenseStatus:101,requestSeedData:102,requestLicenseActivation:110,responseCmdWrong:200,responseFeatureStatus:201,responseSeedData:202,responseTemporaryLicenseStatus:203},B=p=>Object.keys(S).find(t=>S[t]===p)||"Unknown";class y{transport;static APP_ID=f.LICENSING;constructor(e){this.transport=e}requestFeatureStatus(e){const t=`${e}`;return this.transport.buildPacket(S.requestFeatureStatus,t,y.APP_ID)}requestTemporaryLicenseStatus(){return this.transport.buildPacket(S.requestTemporaryLicenseStatus,"",y.APP_ID)}requestSeedData(){return this.transport.buildPacket(S.requestSeedData,"",y.APP_ID)}requestLicenseActivation(e){const t=`${e}`;return this.transport.buildPacket(S.requestLicenseActivation,t,y.APP_ID)}}class ${_commands;jsd;APP_ID=f.LICENSING;constructor(e,t){this._commands=new y(t),this.jsd=e}async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}async requestFeatureStatus({feature:e}){const t=this.cmd.requestFeatureStatus(e);return this.send(t,{alias:"requestFeatureStatus"})}async requestTemporaryLicenseStatus(){const e=this.cmd.requestTemporaryLicenseStatus();return this.send(e,{alias:"requestTemporaryLicenseStatus"})}async requestSeedData(){const e=this.cmd.requestSeedData();return this.send(e,{alias:"requestSeedData"})}async requestLicenseActivation({license:e}){const t=this._base64ToUint8Array(e),s=new TextDecoder("latin1").decode(t),n=this.cmd.requestLicenseActivation(s);return this.send(n,{alias:"requestLicenseActivation"})}_base64ToUint8Array(e){const t=atob(e),s=t.length,n=new Uint8Array(s);for(let a=0;a<s;a++)n[a]=t.charCodeAt(a);return n}serialMessage(e){switch(e.opcode){case S.responseCmdWrong:this._responseCmdWrong(e);break;case S.responseFeatureStatus:this._responseFeatureStatus(e);break;case S.responseSeedData:this._responseSeedData(e);break;case S.responseTemporaryLicenseStatus:this._responseTemporaryLicenseStatus(e);break}}emit(e,...t){this.jsd.dispatch(`licensing:${e}`,...t)}_responseCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=B(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}_responseFeatureStatus(e){const[t,s]=e.params;this.emit("feature-status",{feature:t,active:s==="1"})}_responseSeedData(e){const t=e.rawAscii||"",s=new Uint8Array([...t].map(i=>i.charCodeAt(0))),n=btoa(String.fromCharCode(...s)),a=Array.from(s).map(i=>i.toString(16).padStart(2,"0").toUpperCase()).join(" ");this.emit("seed",{seed:t,base64:n,hex:a,bytes:s})}_responseTemporaryLicenseStatus(e){const[t,s,n]=e.params,a={0:"Inactive, permanent license",1:"Active",2:"Expired",3:"Blocked up"};this.emit("temporary-license-status",{status:a[t]||"Unknown",remainingDays:parseInt(s,10),daysSinceExpiration:parseInt(n,10)})}}class j{static unescapeBytes(e){const t=[];for(let s=0;s<e.length;s++){const n=e[s];if(n===219){const a=e[s+1];a===220?(t.push(192),s++):a===221?(t.push(219),s++):t.push(n)}else t.push(n)}return t}static parseFrame(e){let t=e;t.length>0&&t[0]===192&&(t=t.slice(1)),t.length>0&&t[t.length-1]===192&&(t=t.slice(0,-1));const s=this.unescapeBytes(t);if(s.length<1)return console.error("Frame too short"),"Frame too short";const n=s[0],a=s[1],i=s.slice(2,-2),c=s[s.length-2],o=s[s.length-1],h=[192,n,a,...i],[d,l]=_.calculate(h);if(d!==c||l!==o)return console.error("CRC mismatch"),"CRC mismatch";if(n===2)return{type:"ACK",id:a};if(n===3)return{type:"NACK",id:a};if(n!==1)return console.warn("Unknown code"),"Unknown code";if(i.length<6)return console.error("JConnect header too short"),"JConnect header too short";const m=i[0]|i[1]<<8,I=i[2]|i[3]<<8,D=i[4]|i[5]<<8,v=i.slice(6),A=String.fromCharCode(...v);return{type:"DATA",opcode:D,appId:I,noBytes:m,params:A?A.split(","):[],id:a,rawAscii:A}}}class U{delimiter;buffer;constructor(e){this.delimiter=e,this.buffer=new Uint8Array(0)}transform(e,t){const s=new Uint8Array(this.buffer.length+e.length);s.set(this.buffer),s.set(e,this.buffer.length),this.buffer=s;let n;for(;(n=this.findDelimiterIndex())!==-1;){const a=this.buffer.slice(0,n);this.buffer=this.buffer.slice(n+this.delimiter.length),t.enqueue(a)}}findDelimiterIndex(){for(let e=0;e<=this.buffer.length-this.delimiter.length;e++){let t=!0;for(let s=0;s<this.delimiter.length;s++)if(this.buffer[e+s]!==this.delimiter[s]){t=!1;break}if(t)return e}return-1}flush(e){this.buffer.length>0&&(e.enqueue(this.buffer),this.buffer=new Uint8Array(0))}}class W extends O.v{_transport;vision;manifest;licensing;_queue=[];_timeoutPacketId=0;_runningQueue=!1;_lastApplicationCode=0;constructor({filters:e=null,config_port:t,no_device:s=1,socket:n=!1,transport:a="rs232"}={}){const i=new Uint8Array([192]),c=()=>new TransformStream(new U(i));if(super({filters:e,config_port:t,no_device:s,socket:n,transformStream:c}),this.__internal__.device.type="jsd",this.__internal__.time.response_general=500,this.__internal__.time.response_engines=500,N.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);N.Devices.add(this),this.#t(),this.getResponseAsUint8Array(),this._transport=a==="rs232"?new k:new b,this.vision=new M(this,this._transport),this.manifest=new R(this,this._transport),this.licensing=new $(this,this._transport),this.#e()}#e(){this.on("serial:connected",async()=>{await this.afterConnectionSetup()})}async afterConnectionSetup(){await new Promise(e=>setTimeout(e,100)),this.vision.requestMachineStatus({machine:1}),this.vision.requestMachineStatus({machine:2}),this.vision.requestMachineStatus({machine:3}),this.vision.requestMachineStatus({machine:4})}#t(){const e=["licensing:wrong-cmd","licensing:feature-status","licensing:seed","licensing:temporary-license-status","manifest:wrong-cmd","manifest:log","manifest:block","manifest:completed","vision:wrong-cmd","vision:machine-status","vision:channels-progress","vision:channels","vision:channel-status","vision:status-selection","vision:dispense-status","vision:selection-dispense-config","vision:channels-linked-to-selection","vision:machine-id","vision:current-temperature","vision:alarm-faults-events","vision:time-waiting-for-product-collection","vision:collect","vision:reset-sold-out-channels","vision:time-waiting-after-product-collection","vision:jsd-version","vision:active-faults","vision:jsd-dispensing-queue","vision:special-characteristics-selection","vision:perishable-products-config","vision:active-faults-list","vision:jsd-status-reset","vision:extended-dispense-status-data","vision:trays-positioning-phototransistors-status","vision:jsd-license-error","serial:jsd-error","serial:jsd-ack","serial:jsd-nack","serial:jsd-data"];for(const t of e)this.serialRegisterAvailableListener(t)}serialSetConnectionConstant(){const e=this._transport?this._transport:new k;let t=255;this._transport&&(t=e.packetId,this._transport._overridePacketId(t+1));const{bytes:s}=u.connection({transport:e,packetId:t});return s}send(e,t){return this.appendToQueue(e,t.alias||"unknown")}onEvent(e,t){super.on(e,t)}offEvent(e,t){super.off(e,t)}onceEvent(e,t){const s=((...n)=>{t(...n),this.offEvent(e,s)});this.onEvent(e,s)}get transport(){return this._transport.name}acknowledge(e){return this._transport.buildAckPacket(e)}ack(e){this.isConnected&&this.send(new Uint8Array(this.acknowledge(e)),{alias:"ACK Response"})}_toQueue(e,t){this._queue.push({packetId:e.packetId,data:e.bytes,alias:t?.alias||"unknown",timeout:t?.timeout||500,resendCount:0}),this._runQueue()}_runQueue(){if(this._queue.length===0||this._runningQueue)return;const e=this._queue[0];this.isConnected&&(this.appendToQueue(new Uint8Array(e.data),e.alias||"unknown"),this._runningQueue=!0,this._timeoutPacketId=setTimeout(()=>{const t=this._queue.findIndex(s=>s.packetId===e.packetId);t!==-1&&(e.resendCount<3?(this._queue[t].resendCount+=1,this._runningQueue=!1,this._runQueue()):(this.dispatch("serial:jsd-error",`No response for packet ID ${e.packetId} after 3 attempts.`),this._queue.splice(t,1),this._runningQueue=!1,this._queue.length>0&&this._runQueue()))},e.timeout))}_dequeue(e){const t=this._queue.findIndex(s=>s.packetId===e);t!==-1&&(this._queue.splice(t,1),this._timeoutPacketId&&(clearTimeout(this._timeoutPacketId),this._timeoutPacketId=0),this._runningQueue=!1,this._queue.length>0&&this._runQueue())}serialMessage(e){const t=Array.from(structuredClone(e));if(t.length===0)return;const s=j.parseFrame(t);if(typeof s=="string")this.dispatch("serial:jsd-error",s);else if(s.type==="ACK")this._queue.findIndex(a=>a.packetId===s.id)!==-1&&this._dequeue(s.id),this.dispatch("serial:jsd-ack",s);else if(s.type==="NACK")this.dispatch("serial:jsd-nack",s);else if(s.type==="DATA"){this.ack(s.id),typeof s.appId>"u"&&(s.appId=this._lastApplicationCode);const n=s.appId;L(n)&&this.vision.serialMessage(s),F(n)&&this.manifest.serialMessage(s),w(n)&&this.licensing.serialMessage(s),this.dispatch("serial:jsd-data",s)}this.dispatch("serial:message",{raw:e,parsed:s})}}exports.JSD=W;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./webserial-core-CrutKvJa.cjs"),N=require("./devices-CcYKrJpP.cjs");class _{static USE_BIG_ENDIAN=!0;static USE_REFLECTED=!1;static calculate(e){let t;if(this.USE_REFLECTED){t=0;for(const s of e){t^=s&255;for(let n=0;n<8;n++)t&1?t=t>>1^40961:t>>=1}}else{t=0;for(const s of e){t^=s<<8;for(let n=0;n<8;n++)t&32768?t=(t<<1^32773)&65535:t=t<<1&65535}}return this.USE_BIG_ENDIAN?[t>>8&255,t&255]:[t&255,t>>8&255]}static getConfig(){return{bigEndian:this.USE_BIG_ENDIAN,reflected:this.USE_REFLECTED}}}class b{_name="tcpip";get name(){return this._name}get packetId(){return 0}_overridePacketId(e){console.warn(`TCP/IP transport does not use packet IDs. Ignoring override to ${e}.`)}toLittleEndian(e){return[e&255,e>>8&255]}buildPacket(e,t,s){const n=t?t.split("").map(h=>h.charCodeAt(0)):[],a=6+n.length,i=this.toLittleEndian(a),c=this.toLittleEndian(s),o=this.toLittleEndian(e);return{bytes:[...i,...c,...o,...n],packetId:0}}escapeBytes(e){const t=[];for(const s of e)s===192?t.push(219,220):s===219?t.push(219,221):t.push(s);return t}buildAckPacket(e){const n=[192,2,e],[a,i]=_.calculate(n),c=[2,e,a,i];return[192,...this.escapeBytes(c),192]}}class k extends b{packetIdCounter=1;_name="rs232";get packetId(){return this.packetIdCounter}_overridePacketId(e){this.packetIdCounter=e&255}getNextPacketId(){const e=this.packetIdCounter;return this.packetIdCounter=this.packetIdCounter+1&255,this.packetIdCounter===0&&(this.packetIdCounter=1),e}buildPacket(e,t,s){const i=this.getNextPacketId(),{bytes:c}=super.buildPacket(e,t,s),o=[192,1,i,...c],[h,d]=_.calculate(o),l=[1,i,...c,h,d];return{bytes:[192,...this.escapeBytes(l),192],packetId:i}}}const r={requestMachineStatus:100,requestStatusChannel:101,requestStatusSelection:102,configureSelectionDispense:103,addChannelToSelection:104,requestMachineIdentification:105,programWorkingTemperature:106,programWaitingTimings:107,resetSoldOutChannels:108,programTimeWaitingAfterPickup:109,requestJSDVersion:110,requestFaultMachine:111,manageJSDDispensingQueue:112,defineSpecialCharacteristicsSelection:113,configurePerishableProducts:114,requestActiveFaults:115,configureExtendedDispenseStatusData:116,requestStatusTrayPositioningPhototransistors:117,dispenseFromChannel:150,dispenseFromSelection:151,controlLights:152,resetFaultsAndSelfTest:153,performCollectCycle:154,dispenseFromChannelExtended:155,restartingTheJSDKnowingThatItIsDangerous:156,responseFormatCmdWrong:200,responseMachineStatus:201,responseStatusChannel:202,responseStatusSelection:203,responseDispenseStatus:204,responseConfigurationSelectionDispense:205,responseConfigurationChannelsLinkedToSelection:206,responseMachineIdentification:207,responseCurrentTemperature:208,responseReportEventsAlarmsAndFaults:209,responseNewTimingWaitingForProductCollection:210,responsePerformingProductCollectionCycle:211,responseResetMachineSoldOutChannels:212,responseNewTimingWaitingAfterProductCollection:213,responseJSDVersion:214,responseActiveFaults:215,responseJSDDispensingQueue:216,responseSpecialCharacteristicsSelection:217,responsePerishableProducts:218,responseActiveFaultsList:219,responseJSDResetStatus:220,responseExtendedDispenseStatusData:221,responseTraysPositioningPhototransistorsStatus:222,jsdErrorLicenseTemporarilyBlocked:300,jsdErrorLicenseNotActive:301,jsdErrorCommandNotExecutable:302},C=p=>Object.keys(r).find(t=>r[t]===p)||"Unknown",f={VISION:402,LICENSING:600,MANIFESTS_AND_LOGS:601,SIMULATOR_VISION:1e4},L=p=>[f.VISION,f.SIMULATOR_VISION].includes(p),w=p=>[f.LICENSING].includes(p),F=p=>[f.MANIFESTS_AND_LOGS].includes(p);class u{transport;static APP_ID=f.VISION;constructor(e){this.transport=e}static connection({transport:e,packetId:t}){return e._overridePacketId(t||255),new u(e).requestJSDVersion()}requestMachineStatus({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestMachineStatus,t,u.APP_ID)}requestStatusChannel({machine:e,tray:t,channel:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.requestStatusChannel,n,u.APP_ID)}requestStatusSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.requestStatusSelection,t,u.APP_ID)}configureSelectionDispense({selection:e,speed:t,timePostRun:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.configureSelectionDispense,n,u.APP_ID)}getSelectionDispenseConfig({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.configureSelectionDispense,t,u.APP_ID)}addChannelToSelection({selection:e,machine:t,tray:s,channel:n}){const a=`${e},${t},${s},${n}`;return this.transport.buildPacket(r.addChannelToSelection,a,u.APP_ID)}getChannelsLinkedToSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.addChannelToSelection,t,u.APP_ID)}requestMachineIdentification({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestMachineIdentification,t,u.APP_ID)}formatTemperature(e){const t=e>=0?"+":"-",s=Math.abs(e).toFixed(1).padStart(4,"0");return`${t}${s}`}programWorkingTemperature({machine:e,temperature:t,enable:s}){const n=this.formatTemperature(t),i=`${e},${n},${s?1:0}`;return this.transport.buildPacket(r.programWorkingTemperature,i,u.APP_ID)}getWorkingTemperature({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.programWorkingTemperature,t,u.APP_ID)}programWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s}){const n=`${e},${t},${s}`;return this.transport.buildPacket(r.programWaitingTimings,n,u.APP_ID)}getWaitingTimings(){return this.transport.buildPacket(r.programWaitingTimings,"",u.APP_ID)}resetSoldOutChannels({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.resetSoldOutChannels,t,u.APP_ID)}programTimeWaitingAfterPickup({time:e}){const t=`${e}`;return this.transport.buildPacket(r.programTimeWaitingAfterPickup,t,u.APP_ID)}getTimeWaitingAfterPickup(){return this.transport.buildPacket(r.programTimeWaitingAfterPickup,"",u.APP_ID)}requestJSDVersion(){return this.transport.buildPacket(r.requestJSDVersion,"",u.APP_ID)}requestFaultMachine({machine:e,type:t}){const n=`${e},${{"report-active":0,"report-inactive":1,"clear-inactive":2}[t]}`;return this.transport.buildPacket(r.requestFaultMachine,n,u.APP_ID)}requestReportActiveFaults(e){return this.requestFaultMachine({machine:e,type:"report-active"})}requestReportInactiveFaults(e){return this.requestFaultMachine({machine:e,type:"report-inactive"})}requestClearInactiveFaults(e){return this.requestFaultMachine({machine:e,type:"clear-inactive"})}manageJSDDispensingQueue({type:e}){const t=`${e}`;return this.transport.buildPacket(r.manageJSDDispensingQueue,t,u.APP_ID)}requestJSDDispensingQueueStatus(){return this.manageJSDDispensingQueue({type:0})}clearJSDDispensingQueue(){return this.manageJSDDispensingQueue({type:1})}defineSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a}){const d=`${e},${t?1:0},${s?1:0},${n==="lower"?0:1},${a}`;return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection,d,u.APP_ID)}getSpecialCharacteristicsSelection({selection:e}){const t=`${e}`;return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection,t,u.APP_ID)}configurePerishableProducts({machine:e,enable:t,temperatureLimit:s,minutesToExpiry:n}){const a=t?1:0,i=this.formatTemperature(s),c=`${e},${a},${i},${n}`;return this.transport.buildPacket(r.configurePerishableProducts,c,u.APP_ID)}requestActiveFaults({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestActiveFaults,t,u.APP_ID)}configureExtendedDispenseStatusData({enable:e}){const s=`${e?1:0}`;return this.transport.buildPacket(r.configureExtendedDispenseStatusData,s,u.APP_ID)}getExtendedDispenseStatusDataConfig(){return this.transport.buildPacket(r.configureExtendedDispenseStatusData,"",u.APP_ID)}requestStatusTrayPositioningPhototransistors({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.requestStatusTrayPositioningPhototransistors,t,u.APP_ID)}dispenseFromChannel({token:e,machine:t,tray:s,channel:n,speed:a,timePostRun:i}){const c=`${e},${t},${s},${n},${a},${i}`;return this.transport.buildPacket(r.dispenseFromChannel,c,u.APP_ID)}getDispenseStatusFromChannel({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromChannel,t,u.APP_ID)}dispenseFromSelection({token:e,selection:t}){const s=`${e},${t}`;return this.transport.buildPacket(r.dispenseFromSelection,s,u.APP_ID)}getDispenseStatusFromSelection({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromSelection,t,u.APP_ID)}controlLights({machine:e,turnOn:t}){const n=`${e},${t?1:0}`;return this.transport.buildPacket(r.controlLights,n,u.APP_ID)}resetFaultsAndSelfTest({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.resetFaultsAndSelfTest,t,u.APP_ID)}performCollectCycle({machine:e}){const t=`${e}`;return this.transport.buildPacket(r.performCollectCycle,t,u.APP_ID)}dispenseFromChannelExtended({token:e,machine:t,tray:s,channel:n,speed:a,timePostRun:i,fragileOrHeavy:c,typeAdjustElevator:o,timeAdjustElevator:h}){const I=`${e},${t},${s},${n},${a},${i},${c?1:0},${o==="lower"?0:1},${h}`;return this.transport.buildPacket(r.dispenseFromChannelExtended,I,u.APP_ID)}getDispenseStatusFromChannelExtended({token:e}){const t=`${e}`;return this.transport.buildPacket(r.dispenseFromChannelExtended,t,u.APP_ID)}restartingTheJSDKnowingThatItIsDangerous(){return this.transport.buildPacket(r.restartingTheJSDKnowingThatItIsDangerous,"",u.APP_ID)}}function q(p){if(p.length>5)throw new Error(`Token must be max 5 characters, got ${p.length}`);return p}function T(){let p;do{const e=new Uint8Array(2);p=parseInt(crypto.getRandomValues(e).toString().replaceAll(",","")).toString(36)}while(p.length>5);return q(p)}const E={status:"NO-CONNECTED",machineInService:!1,doorOpen:!1,availabilityToDispense:"NOT-AVAILABLE-TO-DISPENSE",hasLightsOn:!1,temperature:""};class M{_commands;jsd;APP_ID=f.VISION;_machineStatus=[{...E},{...E},{...E},{...E}];constructor(e,t){this._commands=new u(t),this.jsd=e}_performingChannelAssignment={enabled:!1,selections:[],currentSelection:1};_dispensingTokens={};async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}_getMachineIndex(e){return e-1}isAvailableToDispense({machine:e=1}={}){const t=this._getMachineIndex(e);return["ELEVATOR-COLLECTION-POSITION","AVAILABLE-TO-DISPENSE"].includes(this._machineStatus[t]?.availabilityToDispense||"")&&this._machineStatus[t]?.machineInService===!0&&this._machineStatus[t]?.doorOpen===!1&&this._machineStatus[t]?.status==="CONNECTED"}async requestMachineStatus({machine:e=1}={}){const t=this._getMachineIndex(e),s=this.cmd.requestMachineStatus({machine:t});return await this.send(s,{alias:"requestMachineStatus"})}_getTrayChannelFromSelection(e){const t=Math.floor((e-1)/10)+11,s=(e-1)%10;return{tray:t,channel:s}}_getSelectionFromTrayChannel(e,t){return(e-11)*10+t+1}async requestStatusChannel({machine:e,selection:t}){const s=this._getMachineIndex(e),{tray:n,channel:a}=this._getTrayChannelFromSelection(t),i=this.cmd.requestStatusChannel({machine:s,tray:n,channel:a});return await this.send(i,{alias:"requestStatusChannel"})}async assignChannels({machine:e}){if(this._performingChannelAssignment.enabled)throw new Error("Channel assignment already in progress");this._performingChannelAssignment.enabled=!0;for(let t=1;t<=80;t++)await this.requestStatusChannel({machine:e,selection:t});return new Promise(t=>{const s=setInterval(()=>{if(this._performingChannelAssignment.enabled)return;clearInterval(s);const n=this._performingChannelAssignment.selections;this._performingChannelAssignment.selections=[],t(n)},200)})}async requestStatusSelection({selection:e}){const t=this.cmd.requestStatusSelection({selection:e});return await this.send(t,{alias:"requestStatusSelection"})}async configureSelectionDispense({selection:e,speed:t,timePostRun:s}){const n=this.cmd.configureSelectionDispense({selection:e,speed:t,timePostRun:s});return await this.send(n,{alias:"configureSelectionDispense"})}async requestSelectionDispenseConfig({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.getSelectionDispenseConfig({machine:t});return await this.send(s,{alias:"getSelectionDispenseConfig"})}async configureAddChannelToSelection({selection:e,machine:t,tray:s,channel:n}){const a=this._getMachineIndex(t),i=this.cmd.addChannelToSelection({selection:e,machine:a,tray:s,channel:n});return await this.send(i,{alias:"addChannelToSelection"})}async requestChannelsLinkedToSelection({selection:e}){const t=this.cmd.getChannelsLinkedToSelection({selection:e});return await this.send(t,{alias:"getChannelsLinkedToSelection"})}async requestMachineIdentification({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestMachineIdentification({machine:t});return await this.send(s,{alias:"requestMachineIdentification"})}async configureWorkingTemperature({machine:e,temperature:t,enable:s}){const n=this._getMachineIndex(e),a=this.cmd.programWorkingTemperature({machine:n,temperature:t,enable:s});return await this.send(a,{alias:"programWorkingTemperature"})}async requestWorkingTemperature({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.getWorkingTemperature({machine:t});return await this.send(s,{alias:"getWorkingTemperature"})}async configureWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s}){const n=this.cmd.programWaitingTimings({collectPosition:e,dispenseManoeuvres:t,afterPickup:s});return await this.send(n,{alias:"programWaitingTimings"})}async requestWaitingTimings(){const e=this.cmd.getWaitingTimings();return await this.send(e,{alias:"getWaitingTimings"})}async resetSoldOutChannels({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.resetSoldOutChannels({machine:t});return await this.send(s,{alias:"resetSoldOutChannels"})}async resetAllErrors({machine:e}){return await Promise.all([this.clearInactiveFaults({machine:e}),this.resetSoldOutChannels({machine:e}),this.resetFaultsAndSelfTest({machine:e})])}async configureTimeWaitingAfterPickup({time:e}){const t=this.cmd.programTimeWaitingAfterPickup({time:e});return await this.send(t,{alias:"programTimeWaitingAfterPickup"})}async requestTimeWaitingAfterPickup(){const e=this.cmd.getTimeWaitingAfterPickup();return await this.send(e,{alias:"getTimeWaitingAfterPickup"})}async requestJSDVersion(){const e=this.cmd.requestJSDVersion();return await this.send(e,{alias:"requestJSDVersion"})}async requestReportActiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestReportActiveFaults(t);return await this.send(s,{alias:"requestReportActiveFaults"})}async requestReportInactiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestReportInactiveFaults(t);return await this.send(s,{alias:"requestReportInactiveFaults"})}async clearInactiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestClearInactiveFaults(t);return await this.send(s,{alias:"requestClearInactiveFaults"})}async requestJSDDispensingQueueStatus(){const e=this.cmd.requestJSDDispensingQueueStatus();return await this.send(e,{alias:"requestJSDDispensingQueueStatus"})}async clearJSDDispensingQueue(){const e=this.cmd.clearJSDDispensingQueue();return await this.send(e,{alias:"clearJSDDispensingQueue"})}async configureSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a}){const i=this.cmd.defineSpecialCharacteristicsSelection({selection:e,perishable:t,fragileOrHeavy:s,typeAdjustElevator:n,timeAdjustElevator:a});return await this.send(i,{alias:"defineSpecialCharacteristicsSelection"})}requestSpecialCharacteristicsSelection({selection:e}){const t=this.cmd.getSpecialCharacteristicsSelection({selection:e});return this.send(t,{alias:"getSpecialCharacteristicsSelection"})}configurePerishableProducts({machine:e,enable:t,temperatureLimit:s,minutesToExpiry:n}){const a=this._getMachineIndex(e),i=this.cmd.configurePerishableProducts({machine:a,enable:t,temperatureLimit:s,minutesToExpiry:n});return this.send(i,{alias:"configurePerishableProducts"})}async requestActiveFaults({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestActiveFaults({machine:t});return await this.send(s,{alias:"requestActiveFaults"})}async configureExtendedDispenseStatusData({enable:e}){const t=this.cmd.configureExtendedDispenseStatusData({enable:e});return await this.send(t,{alias:"configureExtendedDispenseStatusData"})}async requestExtendedDispenseStatusDataConfig(){const e=this.cmd.getExtendedDispenseStatusDataConfig();return await this.send(e,{alias:"getExtendedDispenseStatusDataConfig"})}async requestStatusTrayPositioningPhototransistors({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.requestStatusTrayPositioningPhototransistors({machine:t});return await this.send(s,{alias:"requestStatusTrayPositioningPhototransistors"})}async dispenseFromChannel({machine:e,tray:t,channel:s,speed:n,timePostRun:a,cart:i=!1}){if(!this.isAvailableToDispense({machine:e}))throw new Error(`Machine ${e} is not available to dispense`);const c=this._getMachineIndex(e),o=T(),h=this.cmd.dispenseFromChannel({token:o,machine:c,tray:t,channel:s,speed:n,timePostRun:a});return await this.send(h,{alias:"dispenseFromChannel"}),this._dispensingTokens[o]={cart:!!i,resolve:()=>{delete this._dispensingTokens[o]},reject:()=>{}},new Promise((d,l)=>{this._dispensingTokens[o].resolve=d,this._dispensingTokens[o].reject=l})}async dispense({machine:e,selection:t,speed:s,timePostRun:n,cart:a=!1}){const{tray:i,channel:c}=this._getTrayChannelFromSelection(t);return this.dispenseFromChannel({machine:e,tray:i,channel:c,speed:s||5,timePostRun:n||0,cart:!!a})}async dispenseCart(e=[]){const t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));let s=[];for(const n of t)try{const a=await Promise.all(n.map(o=>this.dispense({machine:o.machine,selection:o.selection,cart:!0}))),i=[...new Set(n.map(o=>o.machine))];await new Promise(o=>{const h=setInterval(()=>{i.every(l=>this.getMachineStatus(l)?.availabilityToDispense==="AVAILABLE-TO-DISPENSE")&&(clearInterval(h),o(!0))},300)});for(const o of i)this._machineStatus[this._getMachineIndex(o)]?.availabilityToDispense==="WAITING-COLLECTION"&&this.emit("waiting-collection",{machine:o!==null?o+1:null});const c=n.map((o,h)=>({machine:o.machine,selection:o.selection,dispensed:a[h]}));s=s.concat(c)}catch(a){console.error("Error sending dispense command:",a)}return s}async requestDispenseStatusFromChannel({token:e}){const t=this.cmd.getDispenseStatusFromChannel({token:e});return await this.send(t,{alias:"getDispenseStatusFromChannel"})}async dispenseFromSelection({selection:e,cart:t=!1}){const s=T(),n=this.cmd.dispenseFromSelection({token:s,selection:e});return await this.send(n,{alias:"dispenseFromSelection"}),this._dispensingTokens[s]={cart:!!t,resolve:()=>{},reject:()=>{}},new Promise((a,i)=>{this._dispensingTokens[s].resolve=a,this._dispensingTokens[s].reject=i})}async requestDispenseStatusFromSelection({token:e}){const t=this.cmd.getDispenseStatusFromSelection({token:e});return await this.send(t,{alias:"getDispenseStatusFromSelection"})}async _configureLights({machine:e,turnOn:t,alias:s}){const n=this._getMachineIndex(e),a=this.cmd.controlLights({machine:n,turnOn:t});return await this.send(a,{alias:s})}async lightsOn({machine:e}){return this._configureLights({machine:e,turnOn:!0,alias:"lightsOn"})}async lightsOff({machine:e}){return this._configureLights({machine:e,turnOn:!1,alias:"lightsOff"})}async resetFaultsAndSelfTest({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.resetFaultsAndSelfTest({machine:t});return await this.send(s,{alias:"resetFaultsAndSelfTest"})}async collect({machine:e}){const t=this._getMachineIndex(e),s=this.cmd.performCollectCycle({machine:t});return await this.send(s,{alias:"performCollectCycle"})}async dispenseFromChannelExtended({machine:e,tray:t,channel:s,speed:n,timePostRun:a,fragileOrHeavy:i,typeAdjustElevator:c,timeAdjustElevator:o,cart:h=!1}){if(!this.isAvailableToDispense({machine:e}))throw new Error(`Machine ${e} is not available to dispense`);const d=this._getMachineIndex(e),l=T(),m=this.cmd.dispenseFromChannelExtended({token:l,machine:d,tray:t,channel:s,speed:n,timePostRun:a,fragileOrHeavy:i,typeAdjustElevator:c,timeAdjustElevator:o});return await this.send(m,{alias:"dispenseFromChannelExtended"}),this._dispensingTokens[l]={cart:!!h,resolve:()=>{},reject:()=>{}},new Promise((I,D)=>{this._dispensingTokens[l].resolve=I,this._dispensingTokens[l].reject=D})}async requestDispenseStatusFromChannelExtended({token:e}){const t=this.cmd.getDispenseStatusFromChannelExtended({token:e});return await this.send(t,{alias:"getDispenseStatusFromChannelExtended"})}async restartJSD(){const e=this.cmd.restartingTheJSDKnowingThatItIsDangerous();return await this.send(e,{alias:"restartingTheJSDKnowingThatItIsDangerous"})}serialMessage(e){switch(e.opcode){case r.responseFormatCmdWrong:this._responseFormatCmdWrong(e);break;case r.responseMachineStatus:this._responseMachineStatus(e);break;case r.responseStatusChannel:this._responseStatusChannel(e);break;case r.responseStatusSelection:this._responseStatusSelection(e);break;case r.responseDispenseStatus:this._responseDispenseStatus(e);break;case r.responseConfigurationSelectionDispense:this._responseConfigurationSelectionDispense(e);break;case r.responseConfigurationChannelsLinkedToSelection:this._responseConfigurationChannelsLinkedToSelection(e);break;case r.responseMachineIdentification:this._responseMachineIdentification(e);break;case r.responseCurrentTemperature:this._responseCurrentTemperature(e);break;case r.responseReportEventsAlarmsAndFaults:this._responseReportEventsAlarmsAndFaults(e);break;case r.responseNewTimingWaitingForProductCollection:this._responseNewTimingWaitingForProductCollection(e);break;case r.responsePerformingProductCollectionCycle:this._responsePerformingProductCollectionCycle(e);break;case r.responseResetMachineSoldOutChannels:this._responseResetMachineSoldOutChannels(e);break;case r.responseNewTimingWaitingAfterProductCollection:this._responseNewTimingWaitingAfterProductCollection(e);break;case r.responseJSDVersion:this._responseJSDVersion(e);break;case r.responseActiveFaults:this._responseActiveFaults(e);break;case r.responseJSDDispensingQueue:this._responseJSDDispensingQueue(e);break;case r.responseSpecialCharacteristicsSelection:this._responseSpecialCharacteristicsSelection(e);break;case r.responsePerishableProducts:this._responsePerishableProducts(e);break;case r.responseActiveFaultsList:this._responseActiveFaultsList(e);break;case r.responseJSDResetStatus:this._responseJSDResetStatus(e);break;case r.responseExtendedDispenseStatusData:this._responseExtendedDispenseStatusData(e);break;case r.responseTraysPositioningPhototransistorsStatus:this._responseTraysPositioningPhototransistorsStatus(e);break;case r.jsdErrorLicenseTemporarilyBlocked:this._responseJsdErrorLicenseTemporarilyBlocked(e);break;case r.jsdErrorLicenseNotActive:this._responseJsdErrorLicenseNotActive(e);break;case r.jsdErrorCommandNotExecutable:this._responseJsdErrorCommandNotExecutable(e);break}}emit(e,...t){this.jsd.dispatch(`vision:${e}`,...t)}_responseFormatCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=C(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}setMachineStatus(e,t){this._machineStatus[e]=t}getMachineStatus(e){const t=this._getMachineIndex(e);return this._machineStatus[t]||null}_getMachineStatusName(e){switch(e){case 0:return"NO-CONNECTED";case 1:return"CONNECTED";case 2:return"LOST"}}_responseMachineStatus(e){const[t,s,n,a,i,c,o]=e.params,h={0:"AVAILABLE-TO-DISPENSE",1:"NOT-AVAILABLE-TO-DISPENSE",2:"ALREADY-DISPENSING",3:"WAITING-COLLECTION",4:"ELEVATOR-COLLECTION-POSITION",5:"UNCOLLECTED"},d={status:this._getMachineStatusName(parseInt(s,10)),machineInService:parseInt(n,10)===1,doorOpen:parseInt(a,10)===0,availabilityToDispense:h[i]||"NOT-AVAILABLE-TO-DISPENSE",hasLightsOn:isNaN(parseInt(c,10))?!1:parseInt(c,10)===1,temperature:o||""};this.setMachineStatus(parseInt(t,10),d),this.emit("machine-status",{machine:parseInt(t,10)+1,...d}),this.emit("door",{open:d.doorOpen,machine:parseInt(t,10)+1}),this.emit("connection",{connected:d.status==="CONNECTED",machine:parseInt(t,10)+1})}_statusChannelName(e){switch(e){case 0:return"NO-CONNECTED";case 1:return"AVAILABLE";case 2:return"SOLD-OUT";case 3:return"FAULT";default:return"NO-CONNECTED"}}_responseStatusChannel(e){const[t,s,n,a]=e.params,i=this._statusChannelName(parseInt(a,10)),c=this._getSelectionFromTrayChannel(Number(s),Number(n)),o=["AVAILABLE","SOLD-OUT"].includes(i);if(this._performingChannelAssignment.enabled){this._performingChannelAssignment.selections.push({selection:c,active:o,machine:Number(t)+1}),this._performingChannelAssignment.currentSelection=this._performingChannelAssignment.selections.length;const h=this._performingChannelAssignment.currentSelection/80*100;this.emit("channels-progress",{progress:Math.min(100,Math.round(h*100)/100),current:this._performingChannelAssignment.currentSelection,verified:this._performingChannelAssignment.selections.length}),this._performingChannelAssignment.selections.length>=80&&(this.emit("channels",this._performingChannelAssignment.selections),this._performingChannelAssignment.enabled=!1)}else this.emit("channel-status",{machine:Number(t)+1,selection:c,active:o})}_statusSelectionName(e){switch(e){case 0:return"NO-CONFIGURED";case 1:return"ASSOCIATED";case 2:return"NO-ASSOCIATED";case 3:return"NO-VISION-OWNED";case 4:return"EXPIRED";default:return"NO-CONFIGURED"}}_responseStatusSelection(e){const[t,s]=e.params,n=this._statusSelectionName(parseInt(s,10));this.emit("status-selection",{selection:Number(t),status:n})}_responseDispenseStatus(e){const[t,s,n,a]=e.params,i={0:"RECEIVED",1:"IN-PROGRESS",2:"WAITING-COLLECTION",3:"COLLECTED",4:"NO-PERFORMED",5:"TOKEN-NOT-FOUND",6:"QUEUE-FULL",7:"CHANNEL-NO-CONNECTED",8:"SELECTION-UNAVAILABLE",9:"FAILED-DISPENSE",10:"UNCOLLECTED",11:"DISPENSED-CAN-MULTIPLE",12:"DISPENSE-CANCELLED",13:"PRODUCT-EXPIRED"},c=Object.values(i).filter(D=>["NO-PERFORMED","TOKEN-NOT-FOUND","QUEUE-FULL","CHANNEL-NO-CONNECTED","SELECTION-UNAVAILABLE","FAILED-DISPENSE","DISPENSE-CANCELLED","PRODUCT-EXPIRED","UNCOLLECTED"].includes(D)),o={0:"NONE",1:"DOOR-OPEN",2:"MACHINE-NOT-AVAILABLE",3:"ERROR-PHOTOSENSORS",4:"ERROR-MOTOR-POWER-CONSUMPSION-DETECTOR",5:"ALREADY-SOLD-OUT",6:"ERROR-TEST-PRODUCT-DETECTOR",7:"SOLD-OUT",8:"ELEVATOR-CANT-REACH-TRAY",9:"UNCOLLECTED",10:"MACHINE-RESET-DURING-DISPENSE",11:"MACHINE-COMMUNICATION-ERROR",12:"MACHINE-COMMUNICATION-LOST",13:"NO-VISION",14:"PRODUCT-PERISHABLE-EXPIRED",20:"DECIDE"},h=i[parseInt(s,10)]||"UNKNOWN",[d,l,m]=n&&n.trim()!==""?n.split(".").map(D=>parseInt(D,10)):[null,null,null],I=a?o[parseInt(a,10)]||"UNKNOWN":null;this._dispensingTokens[t]&&(this._dispensingTokens[t].cart===!1&&h==="WAITING-COLLECTION"?(this._dispensingTokens[t].resolve(!0),delete this._dispensingTokens[t],this.emit("waiting-collection",{machine:d!==null?d+1:null})):this._dispensingTokens[t].cart===!0&&h==="DISPENSED-CAN-MULTIPLE"?(this._dispensingTokens[t].resolve(!0),delete this._dispensingTokens[t]):c.includes(h)&&(this._dispensingTokens[t].resolve(!1),delete this._dispensingTokens[t])),h==="IN-PROGRESS"&&this.emit("dispensing",{token:t,machine:d!==null?d+1:null,tray:l!==null?l:null,channel:m!==null?m:null,selection:m!==null&&l!==null?this._getSelectionFromTrayChannel(l,m):null}),this.emit("dispense-status",{token:t,status:h,machine:d!==null?d+1:null,tray:l!==null?l:null,channel:m!==null?m:null,extendedStatus:I})}_responseConfigurationSelectionDispense(e){const[t,s,n]=e.params;this.emit("selection-dispense-config",{selection:Number(t),speed:Number(s),timePostRun:Number(n)})}_responseConfigurationChannelsLinkedToSelection(e){const[t,...s]=e.params,a=s[s.length-1].includes(":")?s.pop():null,i={0:"OK",1:"ALREADY-DEFINED",2:"OUT-OF-RANGE"},c=s.map(o=>{const[h,d,l]=o.split(":");return{machine:parseInt(h,10)+1,tray:parseInt(d,10),channel:parseInt(l,10)}});this.emit("channels-linked-to-selection",{selection:Number(t),linkedChannels:c,status:a?i[parseInt(a,10)]||"UNKNOWN":null})}_responseMachineIdentification(e){const[t,s,n,a]=e.params;this.emit("machine-id",{machine:parseInt(t,10)+1,model:s,serialNumber:n,firmwareVersion:a})}_responseCurrentTemperature(e){const[t,s,n,a,i]=e.params,c=parseInt(t,10)+1,o=parseInt(i,10)===1?"ON":"OFF";this.emit("current-temperature",{machine:c,workingTemperature:s,currentTemperatureInsideMachine:n,currentTemperatureAir:a,coolUnitStatus:o})}_responseReportEventsAlarmsAndFaults(e){const[t,s,n]=e.params,a=parseInt(t,10)+1,i={1:"Product detector",2:"None of the motors are connected. Possible control board faulty",3:"Channels jamp detector error",4:"Temperature control error",5:"Elevator faulty",6:"Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",7:"Elevator tester (flap), ES-Plus, faulty",8:"Product expired (perishable)"};this.emit("alarm-faults-events",{machine:a,event:i[parseInt(s,10)]||"UNKNOWN",status:parseInt(n,10)===1?"ACTIVE":"CLEARED"})}_responseNewTimingWaitingForProductCollection(e){const[t,s,n]=e.params;this.emit("time-waiting-for-product-collection",{minutesProductCollection:Number(t),secondsTimeBetweenDispenseManoeuvres:Number(s),secondsBetweenCollectAndStartNextDispense:Number(n)})}_responsePerformingProductCollectionCycle(e){const[t,s]=e.params,n={0:"Manoeuvre has started",1:"Wron machine number",2:"Machine no connected",3:"Wron machine model",4:"Machine cannot perform collection now",5:"Communication error with machine"};this.emit("collect",{machine:parseInt(t,10)+1,status:n[parseInt(s,10)]||"UNKNOWN"})}_responseResetMachineSoldOutChannels(e){const[t,s]=e.params,n={0:"Reset performed",1:"Wrong machine number",2:"Machine not connected",3:"Communication error with machine"};this.emit("reset-sold-out-channels",{machine:parseInt(t,10)+1,status:n[parseInt(s,10)]||"UNKNOWN"})}_responseNewTimingWaitingAfterProductCollection(e){const[t]=e.params;this.emit("time-waiting-after-product-collection",{secondsBetweenCollectAndStartNextDispense:Number(t)})}_responseJSDVersion(e){const[t,s,n,a]=e.params;this.emit("jsd-version",{name:t,compileNumber:s,compileDate:n,description:a})}_responseActiveFaults(e){const[t,s,n,a,i,c,o]=e.params;this.emit("active-faults",{machine:parseInt(t,10)+1,status:parseInt(s,10)===1?"ACTIVE":"CLEARED",fault:parseInt(n,10),appearancesNumber:parseInt(a,10),partialNumberActivated:parseInt(i,10),minutesActive:parseInt(c,10),date:o})}_responseJSDDispensingQueue(e){const[t,s,n]=e.params;this.emit("jsd-dispensing-queue",{free:parseInt(t,10),processed:parseInt(s,10),notProcessed:parseInt(n,10)})}_responseSpecialCharacteristicsSelection(e){const[t,s,n,a,i]=e.params;this.emit("special-characteristics-selection",{selection:Number(t),perishable:parseInt(s,10)===1,fragileOrHeavy:parseInt(n,10)===1,typeAdjustElevator:a==="0"?"lower":"upper",timeAdjustElevator:Number(i)})}_responsePerishableProducts(e){const[t,s,n,a,i]=e.params;this.emit("perishable-products-config",{machine:parseInt(t,10)+1,perishableActive:parseInt(s,10)===1,alarmPerisableTriggered:parseInt(n,10)===1,maxTemperature:a,minutesBeforeExpire:Number(i)})}_responseActiveFaultsList(e){const[t,...s]=e.params,n={1:"Product detector",2:"None of the motors are connected. Possible control board faulty",3:"Channels jamp detector error",4:"Temperature control error",5:"Elevator faulty",6:"Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",7:"Elevator tester (flap), ES-Plus, faulty",8:"Product expired (perishable)"},a=s.map(i=>({code:parseInt(i,10),description:n[parseInt(i,10)]||"UNKNOWN"}));this.emit("active-faults-list",{machine:parseInt(t,10)+1,faults:a,ok:s.length===0})}_responseJSDResetStatus(e){const[t]=e.params,s={0:"RESETED",1:"RECEIVED"};this.emit("jsd-status-reset",{type:s[parseInt(t,10)]||"UNKNOWN"})}_responseExtendedDispenseStatusData(e){const[t]=e.params;this.emit("extended-dispense-status-data",{enabled:parseInt(t,10)===1})}_responseTraysPositioningPhototransistorsStatus(e){const[t,s,n,a,i,c,o,h,d]=e.params,l={0:"OK",C:"SHORT-CIRCUIT",N:"TRAY-NOT-DETECTED"},m={machine:parseInt(t,10)+1,trays:{11:l[s]||null,12:l[n]||null,13:l[a]||null,14:l[i]||null,15:l[c]||null,16:l[o]||null,17:l[h]||null,18:l[d]||null}};this.emit("trays-positioning-phototransistors-status",m)}_responseJsdErrorLicenseTemporarilyBlocked(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"expired-license",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}_responseJsdErrorLicenseNotActive(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"app-number-not-licensed",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}_responseJsdErrorCommandNotExecutable(e){const[t,...s]=e.params;this.emit("jsd-license-error",{type:"price-control-active-direct-dispense-not-allowed",opcode:parseInt(t,10),actionName:C(parseInt(t,10)),params:s})}}const g={requestLogsEvents:101,requestLogsByDate:102,requestForSendingManifest:110,sendManifestDataBlock:111,responseCmdWrong:200,responseLineLogEvent:201,responseManifestDataBlock:210,responseManifestCompleted:211},x=p=>Object.keys(g).find(t=>g[t]===p)||"Unknown";class P{transport;static APP_ID=f.MANIFESTS_AND_LOGS;constructor(e){this.transport=e}requestLogsEvents(e=!1){const s=`${e?"+":"0"}`;return this.transport.buildPacket(g.requestLogsEvents,s,P.APP_ID)}requestLogsByDate(e,t){const s=`${e},${t}`;return this.transport.buildPacket(g.requestLogsByDate,s,P.APP_ID)}requestForSendingManifest(e,t){const s=`${e},${t}`;return this.transport.buildPacket(g.requestForSendingManifest,s,P.APP_ID)}sendManifestDataBlock(e,t){const s=Array.from(t).map(a=>a.toString(2).padStart(8,"0")).join(" "),n=`${e},${s}`;return this.transport.buildPacket(g.sendManifestDataBlock,n,P.APP_ID)}}class R{_commands;jsd;APP_ID=f.MANIFESTS_AND_LOGS;_logs={status:"idle",data:[]};constructor(e,t){this._commands=new P(t),this.jsd=e}async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}async requestLogsEvent({previous:e}){const t=this.cmd.requestLogsEvents(e);return await this.send(t,{alias:"requestLogsEvents"})}async requestLogs(){if(["fetching","more"].includes(this._logs.status))throw new Error("Already fetching logs");return this._logs.status="fetching",this.requestLogsEvent({previous:!1}),new Promise(e=>{const t=setInterval(()=>{if(this._logs.status==="completed"){clearInterval(t);const s=this._logs.data;e(s)}else this._logs.status==="more"&&(this._logs.status="fetching",this.requestLogsEvent({previous:!0}))},100)})}async requestLogsByDate({since:e,until:t}){const s=c=>{const o=String(c.getMonth()+1).padStart(2,"0"),h=String(c.getDate()).padStart(2,"0"),d=String(c.getHours()).padStart(2,"0"),l=String(c.getMinutes()).padStart(2,"0"),m=String(c.getSeconds()).padStart(2,"0");return`${o}/${h}/${d}/${l}/${m}`},n=s(e),a=s(t),i=this.cmd.requestLogsByDate(n,a);return await this.send(i,{alias:"requestLogsByDate"})}async requestForSendingManifest({fileSizeBytes:e,crc:t}){const s=this.cmd.requestForSendingManifest(e,t);return await this.send(s,{alias:"requestForSendingManifest"})}async sendManifestDataBlock({prevBlockId:e,dataBlock:t}){const s=this.cmd.sendManifestDataBlock(e,t);return await this.send(s,{alias:"sendManifestDataBlock"})}serialMessage(e){switch(e.opcode){case g.responseCmdWrong:this._responseCmdWrong(e);break;case g.responseLineLogEvent:this._responseLineLogEvent(e);break;case g.responseManifestDataBlock:this._responseManifestDataBlock(e);break;case g.responseManifestCompleted:this._responseManifestCompleted(e);break}}emit(e,...t){this.jsd.dispatch(`manifest:${e}`,...t)}_responseCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=x(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}_responseLineLogEvent(e){const[...t]=e.params,s=t[0]==="END_LOG";if(s)this._logs.status="completed";else{const a=t.join(",");this._logs.data.push(a),this._logs.status==="fetching"&&(this._logs.status="more")}const n=s?"end":"log";this.emit("log",{type:n,log:t})}_responseManifestDataBlock(e){const[t,s,n]=e.params;this.emit("block",{blockId:parseInt(t,10),indexFile:parseInt(s,10),quantity:parseInt(n,10)})}_responseManifestCompleted(e){const[t]=e.params,s={0:"Success",1:"CRC Error",2:"Transference interrupted",3:"Reset JSD and try again"};this.emit("completed",{result:s[t]||"Unknown Result",resultKey:parseInt(t,10)})}}const S={requestFeatureStatus:100,requestTemporaryLicenseStatus:101,requestSeedData:102,requestLicenseActivation:110,responseCmdWrong:200,responseFeatureStatus:201,responseSeedData:202,responseTemporaryLicenseStatus:203},B=p=>Object.keys(S).find(t=>S[t]===p)||"Unknown";class y{transport;static APP_ID=f.LICENSING;constructor(e){this.transport=e}requestFeatureStatus(e){const t=`${e}`;return this.transport.buildPacket(S.requestFeatureStatus,t,y.APP_ID)}requestTemporaryLicenseStatus(){return this.transport.buildPacket(S.requestTemporaryLicenseStatus,"",y.APP_ID)}requestSeedData(){return this.transport.buildPacket(S.requestSeedData,"",y.APP_ID)}requestLicenseActivation(e){const t=`${e}`;return this.transport.buildPacket(S.requestLicenseActivation,t,y.APP_ID)}}class ${_commands;jsd;APP_ID=f.LICENSING;constructor(e,t){this._commands=new y(t),this.jsd=e}async send(e,t){return this.jsd._lastApplicationCode=this.APP_ID,this.jsd._toQueue(e,{alias:t.alias,waitResponse:t.waitResponse||!1,timeout:t.timeout||500})}get cmd(){return this._commands}async requestFeatureStatus({feature:e}){const t=this.cmd.requestFeatureStatus(e);return this.send(t,{alias:"requestFeatureStatus"})}async requestTemporaryLicenseStatus(){const e=this.cmd.requestTemporaryLicenseStatus();return this.send(e,{alias:"requestTemporaryLicenseStatus"})}async requestSeedData(){const e=this.cmd.requestSeedData();return this.send(e,{alias:"requestSeedData"})}async requestLicenseActivation({license:e}){const t=this._base64ToUint8Array(e),s=new TextDecoder("latin1").decode(t),n=this.cmd.requestLicenseActivation(s);return this.send(n,{alias:"requestLicenseActivation"})}_base64ToUint8Array(e){const t=atob(e),s=t.length,n=new Uint8Array(s);for(let a=0;a<s;a++)n[a]=t.charCodeAt(a);return n}serialMessage(e){switch(e.opcode){case S.responseCmdWrong:this._responseCmdWrong(e);break;case S.responseFeatureStatus:this._responseFeatureStatus(e);break;case S.responseSeedData:this._responseSeedData(e);break;case S.responseTemporaryLicenseStatus:this._responseTemporaryLicenseStatus(e);break}}emit(e,...t){this.jsd.dispatch(`licensing:${e}`,...t)}_responseCmdWrong(e){const t=parseInt(e.params[0],10),s=e.params.slice(1),n=B(t);this.emit("wrong-cmd",{opcodeName:n,opcode:t,params:s})}_responseFeatureStatus(e){const[t,s]=e.params;this.emit("feature-status",{feature:t,active:s==="1"})}_responseSeedData(e){const t=e.rawAscii||"",s=new Uint8Array([...t].map(i=>i.charCodeAt(0))),n=btoa(String.fromCharCode(...s)),a=Array.from(s).map(i=>i.toString(16).padStart(2,"0").toUpperCase()).join(" ");this.emit("seed",{seed:t,base64:n,hex:a,bytes:s})}_responseTemporaryLicenseStatus(e){const[t,s,n]=e.params,a={0:"Inactive, permanent license",1:"Active",2:"Expired",3:"Blocked up"};this.emit("temporary-license-status",{status:a[t]||"Unknown",remainingDays:parseInt(s,10),daysSinceExpiration:parseInt(n,10),isPermanent:t==="0",active:t==="1"||t==="0",expired:t==="2"})}}class j{static unescapeBytes(e){const t=[];for(let s=0;s<e.length;s++){const n=e[s];if(n===219){const a=e[s+1];a===220?(t.push(192),s++):a===221?(t.push(219),s++):t.push(n)}else t.push(n)}return t}static parseFrame(e){let t=e;t.length>0&&t[0]===192&&(t=t.slice(1)),t.length>0&&t[t.length-1]===192&&(t=t.slice(0,-1));const s=this.unescapeBytes(t);if(s.length<1)return console.error("Frame too short"),"Frame too short";const n=s[0],a=s[1],i=s.slice(2,-2),c=s[s.length-2],o=s[s.length-1],h=[192,n,a,...i],[d,l]=_.calculate(h);if(d!==c||l!==o)return console.error("CRC mismatch"),"CRC mismatch";if(n===2)return{type:"ACK",id:a};if(n===3)return{type:"NACK",id:a};if(n!==1)return console.warn("Unknown code"),"Unknown code";if(i.length<6)return console.error("JConnect header too short"),"JConnect header too short";const m=i[0]|i[1]<<8,I=i[2]|i[3]<<8,D=i[4]|i[5]<<8,v=i.slice(6),A=String.fromCharCode(...v);return{type:"DATA",opcode:D,appId:I,noBytes:m,params:A?A.split(","):[],id:a,rawAscii:A}}}class U{delimiter;buffer;constructor(e){this.delimiter=e,this.buffer=new Uint8Array(0)}transform(e,t){const s=new Uint8Array(this.buffer.length+e.length);s.set(this.buffer),s.set(e,this.buffer.length),this.buffer=s;let n;for(;(n=this.findDelimiterIndex())!==-1;){const a=this.buffer.slice(0,n);this.buffer=this.buffer.slice(n+this.delimiter.length),t.enqueue(a)}}findDelimiterIndex(){for(let e=0;e<=this.buffer.length-this.delimiter.length;e++){let t=!0;for(let s=0;s<this.delimiter.length;s++)if(this.buffer[e+s]!==this.delimiter[s]){t=!1;break}if(t)return e}return-1}flush(e){this.buffer.length>0&&(e.enqueue(this.buffer),this.buffer=new Uint8Array(0))}}class W extends O.v{_transport;vision;manifest;licensing;_queue=[];_timeoutPacketId=0;_runningQueue=!1;_lastApplicationCode=0;constructor({filters:e=null,config_port:t,no_device:s=1,socket:n=!1,transport:a="rs232"}={}){const i=new Uint8Array([192]),c=()=>new TransformStream(new U(i));if(super({filters:e,config_port:t,no_device:s,socket:n,transformStream:c}),this.__internal__.device.type="jsd",this.__internal__.time.response_general=500,this.__internal__.time.response_engines=500,N.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);N.Devices.add(this),this.#t(),this.getResponseAsUint8Array(),this._transport=a==="rs232"?new k:new b,this.vision=new M(this,this._transport),this.manifest=new R(this,this._transport),this.licensing=new $(this,this._transport),this.#e()}#e(){this.on("serial:connected",async()=>{await this.afterConnectionSetup()})}async afterConnectionSetup(){await new Promise(e=>setTimeout(e,100)),this.vision.requestMachineStatus({machine:1}),this.vision.requestMachineStatus({machine:2}),this.vision.requestMachineStatus({machine:3}),this.vision.requestMachineStatus({machine:4})}#t(){const e=["licensing:wrong-cmd","licensing:feature-status","licensing:seed","licensing:temporary-license-status","manifest:wrong-cmd","manifest:log","manifest:block","manifest:completed","vision:wrong-cmd","vision:machine-status","vision:channels-progress","vision:channels","vision:channel-status","vision:status-selection","vision:dispense-status","vision:selection-dispense-config","vision:channels-linked-to-selection","vision:machine-id","vision:current-temperature","vision:alarm-faults-events","vision:time-waiting-for-product-collection","vision:collect","vision:reset-sold-out-channels","vision:time-waiting-after-product-collection","vision:jsd-version","vision:active-faults","vision:jsd-dispensing-queue","vision:special-characteristics-selection","vision:perishable-products-config","vision:active-faults-list","vision:jsd-status-reset","vision:extended-dispense-status-data","vision:trays-positioning-phototransistors-status","vision:jsd-license-error","serial:jsd-error","serial:jsd-ack","serial:jsd-nack","serial:jsd-data"];for(const t of e)this.serialRegisterAvailableListener(t)}serialSetConnectionConstant(){const e=this._transport?this._transport:new k;let t=255;this._transport&&(t=e.packetId,this._transport._overridePacketId(t+1));const{bytes:s}=u.connection({transport:e,packetId:t});return s}send(e,t){return this.appendToQueue(e,t.alias||"unknown")}onEvent(e,t){super.on(e,t)}offEvent(e,t){super.off(e,t)}onceEvent(e,t){const s=((...n)=>{t(...n),this.offEvent(e,s)});this.onEvent(e,s)}get transport(){return this._transport.name}acknowledge(e){return this._transport.buildAckPacket(e)}ack(e){this.isConnected&&this.send(new Uint8Array(this.acknowledge(e)),{alias:"ACK Response"})}_toQueue(e,t){this._queue.push({packetId:e.packetId,data:e.bytes,alias:t?.alias||"unknown",timeout:t?.timeout||500,resendCount:0}),this._runQueue()}_runQueue(){if(this._queue.length===0||this._runningQueue)return;const e=this._queue[0];this.isConnected&&(this.appendToQueue(new Uint8Array(e.data),e.alias||"unknown"),this._runningQueue=!0,this._timeoutPacketId=setTimeout(()=>{const t=this._queue.findIndex(s=>s.packetId===e.packetId);t!==-1&&(e.resendCount<3?(this._queue[t].resendCount+=1,this._runningQueue=!1,this._runQueue()):(this.dispatch("serial:jsd-error",`No response for packet ID ${e.packetId} after 3 attempts.`),this._queue.splice(t,1),this._runningQueue=!1,this._queue.length>0&&this._runQueue()))},e.timeout))}_dequeue(e){const t=this._queue.findIndex(s=>s.packetId===e);t!==-1&&(this._queue.splice(t,1),this._timeoutPacketId&&(clearTimeout(this._timeoutPacketId),this._timeoutPacketId=0),this._runningQueue=!1,this._queue.length>0&&this._runQueue())}serialMessage(e){const t=Array.from(structuredClone(e));if(t.length===0)return;const s=j.parseFrame(t);if(typeof s=="string")this.dispatch("serial:jsd-error",s);else if(s.type==="ACK")this._queue.findIndex(a=>a.packetId===s.id)!==-1&&this._dequeue(s.id),this.dispatch("serial:jsd-ack",s);else if(s.type==="NACK")this.dispatch("serial:jsd-nack",s);else if(s.type==="DATA"){this.ack(s.id),typeof s.appId>"u"&&(s.appId=this._lastApplicationCode);const n=s.appId;L(n)&&this.vision.serialMessage(s),F(n)&&this.manifest.serialMessage(s),w(n)&&this.licensing.serialMessage(s),this.dispatch("serial:jsd-data",s)}this.dispatch("serial:message",{raw:e,parsed:s})}}exports.JSD=W;
|
package/dist/jsd.js
CHANGED
|
@@ -2268,7 +2268,10 @@ class $ {
|
|
|
2268
2268
|
this.emit("temporary-license-status", {
|
|
2269
2269
|
status: a[t] || "Unknown",
|
|
2270
2270
|
remainingDays: parseInt(s, 10),
|
|
2271
|
-
daysSinceExpiration: parseInt(n, 10)
|
|
2271
|
+
daysSinceExpiration: parseInt(n, 10),
|
|
2272
|
+
isPermanent: t === "0",
|
|
2273
|
+
active: t === "1" || t === "0",
|
|
2274
|
+
expired: t === "2"
|
|
2272
2275
|
});
|
|
2273
2276
|
}
|
|
2274
2277
|
}
|
package/dist/pinpax.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./kernel-c6KuKgQ5.cjs"),c=require("./devices-CcYKrJpP.cjs"),s=require("./relay-E3NCcSjS.cjs");class _ extends p.Kernel{__pinpax__={server:"DEV",businessId:null,encryptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1,sale_init:"idle",sale_login:"idle"}};constructor({filters:i=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:t=1,device_listen_on_channel:a=1,socket:n=!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,socket:!1}){if(super({filters:i,config_port:e,no_device:t,device_listen_on_channel:a,socket:n}),this.__internal__.device.type="pinpax",c.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} already exists`);this.__internal__.time.response_connection=4e3,this.__internal__.time.response_general=3e3,this.__internal__.serial.delay_first_connection=1e3,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
|
|
2
2
|
`,this.#t(),c.Devices.add(this),this.getResponseAsString()}#t(){const i=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund","login"];for(const e of i)this.serialRegisterAvailableListener(e)}set businessId(i){this.__pinpax__.businessId=i}get businessId(){return this.__pinpax__.businessId}set encryptionKey(i){this.__pinpax__.encryptionKey=i}get encryptionKey(){return this.__pinpax__.encryptionKey}set apiKey(i){this.__pinpax__.apiKey=i}get apiKey(){return this.__pinpax__.apiKey}set server(i){this.__pinpax__.server=i}get server(){return this.__pinpax__.server}serialMessage(i){let e=null;try{e=JSON.parse(i),e.request||(e.request=this.lastAction),e.name||(e.name=this.lastAction)}catch(t){console.error("Error parsing response",t,i),this.dispatch("serial:message",i);return}switch(e.response){case"INIT":this.dispatch("init",{name:"INIT",request:this.lastAction,status:"ok"}),this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="received");break;case"INITAPP":this.dispatch("init-app",{name:"INITAPP",request:this.lastAction,status:"started"}),this.__pinpax__.waiting.sale_init==="waiting"?this.__pinpax__.waiting.sale_init="received":this.#n().then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{name:"CONNECT",request:this.lastAction,status:"connected"}),this.#r().then(()=>{});break;case"LOGIN":e.name||(e.name="LOGIN"),this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="received"),this.dispatch("login",e);break;case"LASTVOUCHER":e.name||(e.name="LASTVOUCHER"),this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":e.name||(e.name="DEVICEINFO"),this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{name:"KEEPALIVE",request:this.lastAction,status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{name:"RESETAPP",request:this.lastAction,status:"accepted"});break;case"GETCONFIG":e.name||(e.name="GETCONFIG"),this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{name:"HIDEBUTTONS",request:this.lastAction,hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{name:"SHOWBUTTONS",request:this.lastAction,hidden:!1});break;case"PAYMENT_PROCESS":e.name||(e.name="PAYMENT_PROCESS"),this.dispatch("payment",{name:"PAYMENT_PROCESS",request:this.lastAction,status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{name:"INSERT_CARD",request:this.lastAction,status:"insert card"});break;case"CARD_DATA":e.name||(e.name="CARD_DATA"),this.dispatch("payment",{name:"CARD_DATA",request:this.lastAction,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":e.name||(e.name="MERCHANT"),this.dispatch("payment",{request:this.lastAction,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":e.name||(e.name="TRANSACTION_RESULT"),this.#o({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":e.name||(e.name="ERROR"),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:e}),this.dispatch("payment",{name:"ERROR",request:this.lastAction,status:"error",response:e});break;case"REFUND":this.dispatch("refund",{name:"ERROR",request:this.lastAction,status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(){return s.s.connection()}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(i={}){if(typeof i!="object")throw new Error("Invalid object");if(i.constructor!==Object)throw new Error("Invalid object");if(Object.keys(i).length===0)throw new Error("Empty object");if(i.action===void 0||i.action===null)throw new Error("Invalid object add action");const e=JSON.stringify(i),t=this.parseStringToBytes(e,`\r
|
|
3
|
-
`);await this.appendToQueue(this.stringArrayToUint8Array(t),"custom")}async connectMessage(){await this.appendToQueue(s.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");return this.queue.length===0?!0:new Promise(i=>{const e=setInterval(()=>{this.queue.length===0&&(clearInterval(e),i(!0))},500)})}async#i({type:i="production"}={}){const e=s.s.readQR({type:i});return await this.appendToQueue(e,"read-qr")}async#s(){await this.appendToQueue(s.s.forceHide(),"force-hide")}async#a(){await this.appendToQueue(s.s.forceShow(),"force-show")}async#n(){await this.connectMessage()}async#r(){await this.hideButtons()}#o(i){this.dispatch("payment",i),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=i)}cancelSaleRequestInProcess(){this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:{}})}async#c(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="timeout",e(new Error("Login timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_login==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async#p(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="timeout",e(new Error("Init timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_init==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async makeSale({amount:i=0,reference:e=null}={amount:0,reference:null}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.sale)throw new Error("Already waiting for sale response");const t=s.s.makeSale({amount:i,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e();let a=!1;try{this.__pinpax__.waiting.sale_login="waiting",await this.login(),await this.#c(),this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="waiting",await this.init(),await this.#p(),this.__pinpax__.waiting.sale_init="idle"}catch(n){a=!0,this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="idle",this.__pinpax__.waiting.sale=!1,this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:"Error during login/init before sale",error:n})}return a?!1:(await this.appendToQueue(t,"make-sale"),new Promise(n=>{const r=setInterval(()=>{if(this.__pinpax__.asyncResponses.sale){const o=this.__pinpax__.asyncResponses.sale;this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.waiting.sale=!1,clearInterval(r),n(o.approved)}},100)}))}async getVoucher({folio:i=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!i)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=s.s.getVoucher({folio:i});return this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher"),new Promise((t,a)=>{const n=setTimeout(()=>{this.__pinpax__.waiting.voucher=!1,a("Timeout")},1e4),r=setInterval(()=>{if(this.__pinpax__.asyncResponses.voucher){const o=this.__pinpax__.asyncResponses.voucher;this.__pinpax__.asyncResponses.voucher=null,this.__pinpax__.waiting.voucher=!1,clearInterval(r),clearTimeout(n),t(o.voucher)}},100)})}async info(){await this.appendToQueue(s.s.info(),"info")}async keepAlive(){await this.appendToQueue(s.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(s.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(s.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(s.s.hideButtons(),"hide-buttons"),await this.#s()}async showButtons(){return await this.appendToQueue(s.s.showButtons(),"show-buttons"),await this.#a()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(s.s.demo(),"demo")}async refund({amount:i=0,folio:e=null,auth:t=null}={}){return await this.appendToQueue(s.s.refund({amount:i,folio:e,auth:t}),"refund")}async readProductionQR(){return await this.#i({type:"production"})}async readQualityAssuranceQR(){return this.#i({type:"QA"})}async exit(){return await this.appendToQueue(s.s.exit(),"exit-app")}async init(){await this.appendToQueue(s.s.init(),"init-app")}async login(){if(!this.apiKey||!this.businessId||!this.encryptionKey||!this.server)throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");const i=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,business_id:this.__pinpax__.businessId,encryption_key:this.__pinpax__.encryptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(i,`\r
|
|
3
|
+
`);await this.appendToQueue(this.stringArrayToUint8Array(t),"custom")}async connectMessage(){await this.appendToQueue(s.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");return this.queue.length===0?!0:new Promise(i=>{const e=setInterval(()=>{this.queue.length===0&&(clearInterval(e),i(!0))},500)})}async#i({type:i="production"}={type:"production"}){const e=s.s.readQR({type:i});return await this.appendToQueue(e,"read-qr")}async#s(){await this.appendToQueue(s.s.forceHide(),"force-hide")}async#a(){await this.appendToQueue(s.s.forceShow(),"force-show")}async#n(){await this.connectMessage()}async#r(){await this.hideButtons()}#o(i){this.dispatch("payment",i),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=i)}cancelSaleRequestInProcess(){this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:{}})}async#c(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="timeout",e(new Error("Login timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_login==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async#p(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="timeout",e(new Error("Init timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_init==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async makeSale({amount:i=0,reference:e=null}={amount:0,reference:null}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.sale)throw new Error("Already waiting for sale response");const t=s.s.makeSale({amount:i,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e();let a=!1;try{this.__pinpax__.waiting.sale_login="waiting",await this.login(),await this.#c(),this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="waiting",await this.init(),await this.#p(),this.__pinpax__.waiting.sale_init="idle"}catch(n){a=!0,this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="idle",this.__pinpax__.waiting.sale=!1,this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:"Error during login/init before sale",error:n})}return a?!1:(await this.appendToQueue(t,"make-sale"),new Promise(n=>{const r=setInterval(()=>{if(this.__pinpax__.asyncResponses.sale){const o=this.__pinpax__.asyncResponses.sale;this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.waiting.sale=!1,clearInterval(r),n(o.approved)}},100)}))}async getVoucher({folio:i=null}={folio:null}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!i)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=s.s.getVoucher({folio:i});return this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher"),new Promise((t,a)=>{const n=setTimeout(()=>{this.__pinpax__.waiting.voucher=!1,a("Timeout")},1e4),r=setInterval(()=>{if(this.__pinpax__.asyncResponses.voucher){const o=this.__pinpax__.asyncResponses.voucher;this.__pinpax__.asyncResponses.voucher=null,this.__pinpax__.waiting.voucher=!1,clearInterval(r),clearTimeout(n),t(o.voucher)}},100)})}async info(){await this.appendToQueue(s.s.info(),"info")}async keepAlive(){await this.appendToQueue(s.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(s.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(s.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(s.s.hideButtons(),"hide-buttons"),await this.#s()}async showButtons(){return await this.appendToQueue(s.s.showButtons(),"show-buttons"),await this.#a()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(s.s.demo(),"demo")}async refund({amount:i=0,folio:e=null,auth:t=null}={amount:0,folio:null,auth:null}){return await this.appendToQueue(s.s.refund({amount:i,folio:e,auth:t}),"refund")}async readProductionQR(){return await this.#i({type:"production"})}async readQualityAssuranceQR(){return this.#i({type:"QA"})}async exit(){return await this.appendToQueue(s.s.exit(),"exit-app")}async init(){await this.appendToQueue(s.s.init(),"init-app")}async login(){if(!this.apiKey||!this.businessId||!this.encryptionKey||!this.server)throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");const i=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,business_id:this.__pinpax__.businessId,encryption_key:this.__pinpax__.encryptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(i,`\r
|
|
4
4
|
`);await this.appendToQueue(e,"login")}}exports.PinPax=_;
|
package/dist/pinpax.js
CHANGED
|
@@ -253,7 +253,11 @@ class d extends p {
|
|
|
253
253
|
}, 500);
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
|
-
async #i({
|
|
256
|
+
async #i({
|
|
257
|
+
type: i = "production"
|
|
258
|
+
} = {
|
|
259
|
+
type: "production"
|
|
260
|
+
}) {
|
|
257
261
|
const e = s.readQR({ type: i });
|
|
258
262
|
return await this.appendToQueue(e, "read-qr");
|
|
259
263
|
}
|
|
@@ -329,7 +333,11 @@ class d extends p {
|
|
|
329
333
|
}, 100);
|
|
330
334
|
}));
|
|
331
335
|
}
|
|
332
|
-
async getVoucher({
|
|
336
|
+
async getVoucher({
|
|
337
|
+
folio: i = null
|
|
338
|
+
} = {
|
|
339
|
+
folio: null
|
|
340
|
+
}) {
|
|
333
341
|
if (this.isDisconnected) throw new Error("Device is disconnected");
|
|
334
342
|
if (this.__pinpax__.waiting.voucher) throw new Error("Already waiting for voucher");
|
|
335
343
|
if (!i) throw new Error("Folio is required");
|
|
@@ -367,7 +375,15 @@ class d extends p {
|
|
|
367
375
|
async demo() {
|
|
368
376
|
return console.warn("RUNNING DEMO APP, BE CAREFUL"), await this.appendToQueue(s.demo(), "demo");
|
|
369
377
|
}
|
|
370
|
-
async refund({
|
|
378
|
+
async refund({
|
|
379
|
+
amount: i = 0,
|
|
380
|
+
folio: e = null,
|
|
381
|
+
auth: t = null
|
|
382
|
+
} = {
|
|
383
|
+
amount: 0,
|
|
384
|
+
folio: null,
|
|
385
|
+
auth: null
|
|
386
|
+
}) {
|
|
371
387
|
return await this.appendToQueue(
|
|
372
388
|
s.refund({
|
|
373
389
|
amount: i,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"licensing.d.ts","sourceRoot":"","sources":["../../../../../../lib/commands/jsd/applications/licensing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAIlE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,GAAG,CAAM;IAEjB,SAAgB,MAAM,EAAE,OAAO,MAAM,CAAC,SAAS,CAAoB;gBAEvD,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,iBAAiB;YAKpC,IAAI;IAgBlB,OAAO,KAAK,GAAG,GAEd;IAED;;;;;OAKG;IACU,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI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OAGG;IACU,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7C;;;;;OAKG;IACU,wBAAwB,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtF,OAAO,CAAC,mBAAmB;IAapB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAiBlD,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,+BAA+B;CAmBxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LicensingClient.d.ts","sourceRoot":"","sources":["../../../../../../lib/commands/jsd/types/LicensingClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE;QACX,IAAI,EAAE;YACJ,UAAU,EAAE,MAAM,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,EAAE,CAAC;SAClB;KACF,CAAC;IACF,gBAAgB,EAAE;QAChB,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM,CAAC;YAChB,MAAM,EAAE,OAAO,CAAC;SACjB;KACF,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,KAAK,EAAE,UAAU,CAAC;SACnB;KACF,CAAC;IACF,0BAA0B,EAAE;QAC1B,IAAI,EAAE;YACJ,MAAM,EAAE,MAAM,CAAC;YACf,aAAa,EAAE,MAAM,CAAC;YACtB,mBAAmB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"LicensingClient.d.ts","sourceRoot":"","sources":["../../../../../../lib/commands/jsd/types/LicensingClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE;QACX,IAAI,EAAE;YACJ,UAAU,EAAE,MAAM,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,EAAE,CAAC;SAClB;KACF,CAAC;IACF,gBAAgB,EAAE;QAChB,IAAI,EAAE;YACJ,OAAO,EAAE,MAAM,CAAC;YAChB,MAAM,EAAE,OAAO,CAAC;SACjB;KACF,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC;YACf,KAAK,EAAE,UAAU,CAAC;SACnB;KACF,CAAC;IACF,0BAA0B,EAAE;QAC1B,IAAI,EAAE;YACJ,MAAM,EAAE,MAAM,CAAC;YACf,aAAa,EAAE,MAAM,CAAC;YACtB,mBAAmB,EAAE,MAAM,CAAC;YAC1B,WAAW,EAAE,OAAO,CAAC;YACrB,MAAM,EAAE,OAAO,CAAC;YAChB,OAAO,EAAE,OAAO,CAAC;SACpB;KACF,CAAC;CACH"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MachineValid, OneTo240, Range, SpeedOption, TimePostRunOption, ValidChannel, ValidTray } from './visionClient.types';
|
|
2
|
+
export type { MachineValid, OneTo240, Range, SpeedOption, TimePostRunOption, ValidChannel, ValidTray } from './visionClient.types';
|
|
2
3
|
/** Machine status names */
|
|
3
4
|
export type MachineStatusName = 'NO-CONNECTED' | 'CONNECTED' | 'LOST';
|
|
4
5
|
/** Machine status keys */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsd.types.d.ts","sourceRoot":"","sources":["../../../../../../lib/commands/jsd/types/jsd.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACV,MAA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|
reference?: string | null;
|
|
39
39
|
}): Promise<unknown>;
|
|
40
|
-
getVoucher({ folio }?: {
|
|
41
|
-
folio
|
|
40
|
+
getVoucher({ folio, }?: {
|
|
41
|
+
folio: string | null;
|
|
42
42
|
}): Promise<unknown>;
|
|
43
43
|
info(): Promise<void>;
|
|
44
44
|
keepAlive(): Promise<void>;
|
|
@@ -47,10 +47,10 @@ export declare class PinPax extends Kernel {
|
|
|
47
47
|
hideButtons(): Promise<void>;
|
|
48
48
|
showButtons(): Promise<void>;
|
|
49
49
|
demo(): Promise<void>;
|
|
50
|
-
refund({ amount, folio, auth }?: {
|
|
51
|
-
amount
|
|
52
|
-
folio
|
|
53
|
-
auth
|
|
50
|
+
refund({ amount, folio, auth, }?: {
|
|
51
|
+
amount: number;
|
|
52
|
+
folio: string | null;
|
|
53
|
+
auth: string | null;
|
|
54
54
|
}): Promise<void>;
|
|
55
55
|
readProductionQR(): Promise<void>;
|
|
56
56
|
readQualityAssuranceQR(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pinpax.d.ts","sourceRoot":"","sources":["../../../../lib/serial/pinpax.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKrD,UAAU,cAAc;IACtB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,EAAE;QACd,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;KAClB,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,OAAO,CAAC;QACd,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAA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