@danidoble/webserial 4.3.13 → 4.4.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boardroid.cjs +1 -1
- package/dist/boardroid.js +4 -4
- package/dist/hopper.cjs +2 -2
- package/dist/hopper.js +24 -22
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +5 -4
- package/dist/{kernel-CxSXwsm6.js → kernel-CXM5xoJD.js} +1 -1
- package/dist/{kernel-chJkQxDD.cjs → kernel-Dizfdw3M.cjs} +1 -1
- package/dist/kernel.cjs +2 -2
- package/dist/kernel.js +5 -5
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +6 -6
- package/dist/pinpad.cjs +15 -15
- package/dist/pinpad.js +1131 -1095
- package/dist/pinpax.cjs +2 -2
- package/dist/pinpax.js +7 -5
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +11 -11
- package/dist/webserial-core-D3luFguv.js +3325 -0
- package/dist/webserial-core-YjdXyVOx.cjs +4 -0
- package/dist/webserial.cjs +2 -2
- package/dist/webserial.js +20 -19
- package/package.json +8 -8
- package/dist/webserial-core-BNx2y6fr.cjs +0 -4
- package/dist/webserial-core-l5v2UEyv.js +0 -837
package/dist/pinpax.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./kernel-
|
|
2
|
-
`,this.#t(),c.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./kernel-Dizfdw3M.cjs"),a=require("./relay-E3NCcSjS.cjs"),c=require("./webserial-core-YjdXyVOx.cjs");class h extends u.Kernel{__pinpax__={server:"DEV",businessId:null,encryptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1}};constructor({filters:s=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:t=1,device_listen_on_channel:i=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:s,config_port:e,no_device:t,device_listen_on_channel:i,socket:n}),this.__internal__.device.type="pinpax",c.a.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
|
+
`,this.#t(),c.a.add(this),this.getResponseAsString()}#t(){const s=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund","login"];for(const e of s)this.serialRegisterAvailableListener(e)}set businessId(s){this.__pinpax__.businessId=s}get businessId(){return this.__pinpax__.businessId}set encryptionKey(s){this.__pinpax__.encryptionKey=s}get encryptionKey(){return this.__pinpax__.encryptionKey}set apiKey(s){this.__pinpax__.apiKey=s}get apiKey(){return this.__pinpax__.apiKey}set server(s){this.__pinpax__.server=s}get server(){return this.__pinpax__.server}serialMessage(s){let e=null;try{e=JSON.parse(s),e.request||(e.request=this.lastAction),e.name||(e.name=this.lastAction)}catch(t){console.error("Error parsing response",t,s),this.dispatch("serial:message",s);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{name:"INITAPP",request:this.lastAction,status:"started"}),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.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(s=1){return a.s.connection(s)}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(s={}){if(typeof s!="object")throw new Error("Invalid object");if(s.constructor!==Object)throw new Error("Invalid object");if(Object.keys(s).length===0)throw new Error("Empty object");if(s.action===void 0||s.action===null)throw new Error("Invalid object add action");const e=JSON.stringify(s),t=this.parseStringToBytes(e,`\r
|
|
3
3
|
`);await this.appendToQueue(this.stringArrayToUint8Array(t),"custom")}async connectMessage(){await this.appendToQueue(a.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.queue.length===0)return!0;const s=this;return new Promise(e=>{let t=setInterval(()=>{s.queue.length===0&&(clearInterval(t),e(!0))},500)})}async#s({type:s="production"}={}){const e=a.s.readQR({type:s});return await this.appendToQueue(e,"read-qr")}async#a(){await this.appendToQueue(a.s.forceHide(),"force-hide")}async#i(){await this.appendToQueue(a.s.forceShow(),"force-show")}async#n(){await this.connectMessage()}async#r(){await this.hideButtons()}#o(s){this.dispatch("payment",s),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=s)}async makeSale({amount:s=0,reference:e=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=a.s.makeSale({amount:s,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e();const i=this;return await this.appendToQueue(t,"make-sale"),new Promise(n=>{const r=setInterval(()=>{if(i.__pinpax__.asyncResponses.sale){const o=i.__pinpax__.asyncResponses.sale;i.__pinpax__.asyncResponses.sale=null,i.__pinpax__.waiting.sale=!1,clearInterval(r),n(o.approved)}},100)})}async getVoucher({folio:s=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!s)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=a.s.getVoucher({folio:s});this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher");const t=this;return new Promise((i,n)=>{const r=setTimeout(()=>{t.__pinpax__.waiting.voucher=!1,n("Timeout")},1e4),o=setInterval(()=>{if(t.__pinpax__.asyncResponses.voucher){const p=t.__pinpax__.asyncResponses.voucher;t.__pinpax__.asyncResponses.voucher=null,t.__pinpax__.waiting.voucher=!1,clearInterval(o),clearTimeout(r),i(p.voucher)}},100)})}async info(){await this.appendToQueue(a.s.info(),"info")}async keepAlive(){await this.appendToQueue(a.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(a.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(a.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(a.s.hideButtons(),"hide-buttons"),await this.#a()}async showButtons(){return await this.appendToQueue(a.s.showButtons(),"show-buttons"),await this.#i()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(a.s.demo(),"demo")}async refund({amount:s=0,folio:e=null,auth:t=null}={}){return await this.appendToQueue(a.s.refund({amount:s,folio:e,auth:t}),"refund")}async readProductionQR(){return await this.#s({type:"production"})}async readQualityAssuranceQR(){return this.#s({type:"QA"})}async exit(){return await this.appendToQueue(a.s.exit(),"exit-app")}async init(){await this.appendToQueue(a.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 s=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(s,`\r
|
|
4
4
|
`);await this.appendToQueue(e,"login")}}exports.PinPax=h;
|
package/dist/pinpax.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { K as h } from "./kernel-
|
|
1
|
+
import { K as h } from "./kernel-CXM5xoJD.js";
|
|
2
2
|
import { s as a } from "./relay-DP8PLsDP.js";
|
|
3
|
-
import {
|
|
3
|
+
import { a as c } from "./webserial-core-D3luFguv.js";
|
|
4
4
|
class m extends h {
|
|
5
5
|
__pinpax__ = {
|
|
6
6
|
server: "DEV",
|
|
@@ -27,7 +27,8 @@ class m extends h {
|
|
|
27
27
|
flowControl: "none"
|
|
28
28
|
},
|
|
29
29
|
no_device: t = 1,
|
|
30
|
-
device_listen_on_channel: i = 1
|
|
30
|
+
device_listen_on_channel: i = 1,
|
|
31
|
+
socket: n = !1
|
|
31
32
|
} = {
|
|
32
33
|
filters: null,
|
|
33
34
|
config_port: {
|
|
@@ -39,9 +40,10 @@ class m extends h {
|
|
|
39
40
|
flowControl: "none"
|
|
40
41
|
},
|
|
41
42
|
no_device: 1,
|
|
42
|
-
device_listen_on_channel: 1
|
|
43
|
+
device_listen_on_channel: 1,
|
|
44
|
+
socket: !1
|
|
43
45
|
}) {
|
|
44
|
-
if (super({ filters: s, config_port: e, no_device: t, device_listen_on_channel: i }), this.__internal__.device.type = "pinpax", c.getCustom(this.typeDevice, t))
|
|
46
|
+
if (super({ filters: s, config_port: e, no_device: t, device_listen_on_channel: i, socket: n }), this.__internal__.device.type = "pinpax", c.getCustom(this.typeDevice, t))
|
|
45
47
|
throw new Error(`Device ${this.typeDevice} ${t} already exists`);
|
|
46
48
|
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
|
|
47
49
|
`, this.#t(), c.add(this), this.getResponseAsString();
|
package/dist/relay.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./kernel-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./kernel-Dizfdw3M.cjs"),r=require("./relay-E3NCcSjS.cjs"),i=require("./webserial-core-YjdXyVOx.cjs");class l extends s.Kernel{constructor({filters:t=null,config_port:e=null,no_device:n=1,socket:a=!1}={}){if(super({filters:t,config_port:e,no_device:n,socket:a}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],i.a.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);i.a.add(this)}serialMessage(t){t=this.fixHexArray(t);const e={code:t,name:null,description:null,request:null,no_code:0};t[0]==="a0"&&t[2]=="00"?(e.name="Relay turned off",e.description="The relay has been turned off successfully.",e.request=this.lastAction,e.no_code=101):t[0]==="a0"&&t[2]=="01"?(e.name="Relay turned on",e.description="The relay has been turned on successfully.",e.request=this.lastAction,e.no_code=102):(e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400),this.dispatch("serial:message",e)}serialRelaySumHex(t){let e=0;return t.forEach((n,a)=>{a!==3&&(e+=n)}),e}serialSetConnectionConstant(t=1){return r.e.connection(t)}async turnOn(){const t=r.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=r.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await s.wait(e),await this.turnOff();return}await this.turnOff(),await s.wait(e),await this.turnOn()}}exports.Relay=l;
|
package/dist/relay.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { K as o, w as
|
|
1
|
+
import { K as o, w as i } from "./kernel-CXM5xoJD.js";
|
|
2
2
|
import { e as s } from "./relay-DP8PLsDP.js";
|
|
3
|
-
import {
|
|
4
|
-
class
|
|
5
|
-
constructor({ filters: t = null, config_port: e = null, no_device: n = 1 } = {}) {
|
|
6
|
-
if (super({ filters: t, config_port: e, no_device: n }), this.__internal__.device.type = "relay", this.__internal__.auto_response = !1,
|
|
3
|
+
import { a as r } from "./webserial-core-D3luFguv.js";
|
|
4
|
+
class d extends o {
|
|
5
|
+
constructor({ filters: t = null, config_port: e = null, no_device: n = 1, socket: a = !1 } = {}) {
|
|
6
|
+
if (super({ filters: t, config_port: e, no_device: n, socket: a }), this.__internal__.device.type = "relay", this.__internal__.auto_response = !1, this.__internal__.serial.auto_response = [2, 6, 221, 221, 240, 207, 3], r.getCustom(this.typeDevice, n))
|
|
7
7
|
throw new Error(`Device ${this.typeDevice} ${n} already exists`);
|
|
8
|
-
|
|
8
|
+
r.add(this);
|
|
9
9
|
}
|
|
10
10
|
serialMessage(t) {
|
|
11
11
|
t = this.fixHexArray(t);
|
|
@@ -20,8 +20,8 @@ class h extends o {
|
|
|
20
20
|
}
|
|
21
21
|
serialRelaySumHex(t) {
|
|
22
22
|
let e = 0;
|
|
23
|
-
return t.forEach((n,
|
|
24
|
-
|
|
23
|
+
return t.forEach((n, a) => {
|
|
24
|
+
a !== 3 && (e += n);
|
|
25
25
|
}), e;
|
|
26
26
|
}
|
|
27
27
|
serialSetConnectionConstant(t = 1) {
|
|
@@ -37,12 +37,12 @@ class h extends o {
|
|
|
37
37
|
}
|
|
38
38
|
async toggle({ inverse: t = !1, ms: e = 300 } = {}) {
|
|
39
39
|
if (!t) {
|
|
40
|
-
await this.turnOn(), await
|
|
40
|
+
await this.turnOn(), await i(e), await this.turnOff();
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
await this.turnOff(), await
|
|
43
|
+
await this.turnOff(), await i(e), await this.turnOn();
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
47
|
-
|
|
47
|
+
d as Relay
|
|
48
48
|
};
|