@danidoble/webserial 4.3.5 → 4.3.6

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/pinpax.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./kernel-D8A562gb.cjs"),a=require("./relay-DGFymXOw.cjs"),c=require("./webserial-core-N14HUamr.cjs");class u extends h.Kernel{__pinpax__={server:"DEV",bussinessId:null,encriptionKey: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}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1}){if(super({filters:s,config_port:e,no_device:t,device_listen_on_channel:i}),this.__internal__.device.type="pinpax",c.h.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.h.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 bussinessId(s){this.__pinpax__.bussinessId=s}get bussinessId(){return this.__pinpax__.bussinessId}set encriptionKey(s){this.__pinpax__.encriptionKey=s}get encriptionKey(){return this.__pinpax__.encriptionKey}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)}catch(t){console.error("Error parsing response",t,s),this.dispatch("serial:message",s);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{status:"started"}),this.#n().then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{status:"connected"}),this.#r().then(()=>{});break;case"LOGIN":this.dispatch("login",e);break;case"LASTVOUCHER":this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{status:"accepted"});break;case"GETCONFIG":this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{hidden:!1});break;case"PAYMENT_PROCESS":this.dispatch("payment",{status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{status:"insert card"});break;case"CARD_DATA":this.dispatch("payment",{status:"card data",amount:e.amount,cardHolderName:e.cardHolderName,ccMark:e.ccMark,ccType:e.ccType,currency:e.currency,maskedPan:e.maskedPan,readingType:e.readingType});break;case"MERCHANT":this.dispatch("payment",{status:"merchant",afiliation:e.afiliation,alias:e.alias,amountCashBackCommission:e.amountCashBackCommission,currency:e.currency,description:e.description,hasCashBack:e.hasCashBack,limitCashBackAmount:e.limitCashBackAmount,merchant:e.merchant,months:e.months,name:e.name});break;case"TRANSACTION_RESULT":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":this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{status:"error",response:e}),this.dispatch("payment",{status:"error",response:e});break;case"REFUND":this.dispatch("refund",{status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(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
2
+ `,this.#t(),c.h.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 bussinessId(s){this.__pinpax__.bussinessId=s}get bussinessId(){return this.__pinpax__.bussinessId}set encriptionKey(s){this.__pinpax__.encriptionKey=s}get encriptionKey(){return this.__pinpax__.encriptionKey}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.bussinessId||!this.encriptionKey||!this.server)throw new Error("Invalid data to login check apiKey, bussinessId, encriptionKey, server");const s=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,bussiness_id:this.__pinpax__.bussinessId,encription_key:this.__pinpax__.encriptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(s,`\r
4
4
  `);await this.appendToQueue(e,"login")}}exports.PinPax=u;
package/dist/pinpax.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { K as h } from "./kernel-DAtdBEi3.js";
2
2
  import { s as a } from "./relay-CsdB0FSa.js";
3
3
  import { h as c } from "./webserial-core-BjytHor1.js";
4
- class y extends h {
4
+ class m extends h {
5
5
  __pinpax__ = {
6
6
  server: "DEV",
7
7
  bussinessId: null,
@@ -91,56 +91,60 @@ class y extends h {
91
91
  serialMessage(s) {
92
92
  let e = null;
93
93
  try {
94
- e = JSON.parse(s);
94
+ e = JSON.parse(s), e.request || (e.request = this.lastAction), e.name || (e.name = this.lastAction);
95
95
  } catch (t) {
96
96
  console.error("Error parsing response", t, s), this.dispatch("serial:message", s);
97
97
  return;
98
98
  }
99
99
  switch (e.response) {
100
100
  case "INITAPP":
101
- this.dispatch("init-app", { status: "started" }), this.#n().then(() => {
101
+ this.dispatch("init-app", { name: "INITAPP", request: this.lastAction, status: "started" }), this.#n().then(() => {
102
102
  });
103
103
  break;
104
104
  case "CONNECT":
105
- this.dispatch("connectMessage", { status: "connected" }), this.#r().then(() => {
105
+ this.dispatch("connectMessage", { name: "CONNECT", request: this.lastAction, status: "connected" }), this.#r().then(() => {
106
106
  });
107
107
  break;
108
108
  case "LOGIN":
109
- this.dispatch("login", e);
109
+ e.name || (e.name = "LOGIN"), this.dispatch("login", e);
110
110
  break;
111
111
  case "LASTVOUCHER":
112
- this.dispatch("voucher", e), this.__pinpax__.waiting.voucher && (this.__pinpax__.asyncResponses.voucher = e, this.__pinpax__.waiting.voucher = !1);
112
+ e.name || (e.name = "LASTVOUCHER"), this.dispatch("voucher", e), this.__pinpax__.waiting.voucher && (this.__pinpax__.asyncResponses.voucher = e, this.__pinpax__.waiting.voucher = !1);
113
113
  break;
114
114
  case "DEVICEINFO":
115
- this.dispatch("info", e);
115
+ e.name || (e.name = "DEVICEINFO"), this.dispatch("info", e);
116
116
  break;
117
117
  case "KEEPALIVE":
118
- this.dispatch("keep-alive", { status: "alive" });
118
+ this.dispatch("keep-alive", { name: "KEEPALIVE", request: this.lastAction, status: "alive" });
119
119
  break;
120
120
  case "RESETAPP":
121
- this.dispatch("reset-app", { status: "accepted" });
121
+ this.dispatch("reset-app", { name: "RESETAPP", request: this.lastAction, status: "accepted" });
122
122
  break;
123
123
  case "GETCONFIG":
124
- this.dispatch("get-config", e);
124
+ e.name || (e.name = "GETCONFIG"), this.dispatch("get-config", e);
125
125
  break;
126
126
  case "HIDEBUTTONS":
127
- this.dispatch("buttons-status", { hidden: !0 });
127
+ this.dispatch("buttons-status", { name: "HIDEBUTTONS", request: this.lastAction, hidden: !0 });
128
128
  break;
129
129
  case "SHOWBUTTONS":
130
- this.dispatch("buttons-status", { hidden: !1 });
130
+ this.dispatch("buttons-status", { name: "SHOWBUTTONS", request: this.lastAction, hidden: !1 });
131
131
  break;
132
132
  case "PAYMENT_PROCESS":
133
- this.dispatch("payment", {
133
+ e.name || (e.name = "PAYMENT_PROCESS"), this.dispatch("payment", {
134
+ name: "PAYMENT_PROCESS",
135
+ request: this.lastAction,
134
136
  status: "starting",
135
137
  amount: e.amount,
136
138
  reference: e.referecence
137
139
  });
138
140
  break;
139
141
  case "INSERT_CARD":
140
- this.dispatch("payment", { status: "insert card" });
142
+ this.dispatch("payment", { name: "INSERT_CARD", request: this.lastAction, status: "insert card" });
141
143
  break;
142
144
  case "CARD_DATA":
143
- this.dispatch("payment", {
145
+ e.name || (e.name = "CARD_DATA"), this.dispatch("payment", {
146
+ name: "CARD_DATA",
147
+ request: this.lastAction,
144
148
  status: "card data",
145
149
  amount: e.amount,
146
150
  cardHolderName: e.cardHolderName,
@@ -152,7 +156,8 @@ class y extends h {
152
156
  });
153
157
  break;
154
158
  case "MERCHANT":
155
- this.dispatch("payment", {
159
+ e.name || (e.name = "MERCHANT"), this.dispatch("payment", {
160
+ request: this.lastAction,
156
161
  status: "merchant",
157
162
  afiliation: e.afiliation,
158
163
  alias: e.alias,
@@ -167,7 +172,7 @@ class y extends h {
167
172
  });
168
173
  break;
169
174
  case "TRANSACTION_RESULT":
170
- this.#o({
175
+ e.name || (e.name = "TRANSACTION_RESULT"), this.#o({
171
176
  status: "result",
172
177
  approved: e.approved,
173
178
  acquirer: e.acquirer,
@@ -203,20 +208,14 @@ class y extends h {
203
208
  });
204
209
  break;
205
210
  case "ERROR":
206
- this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = {
211
+ e.name || (e.name = "ERROR"), this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = {
207
212
  status: "error",
208
213
  approved: !1,
209
214
  response: e
210
- }), this.dispatch("error", {
211
- status: "error",
212
- response: e
213
- }), this.dispatch("payment", {
214
- status: "error",
215
- response: e
216
- });
215
+ }), this.dispatch("error", { name: "ERROR", request: this.lastAction, status: "error", response: e }), this.dispatch("payment", { name: "ERROR", request: this.lastAction, status: "error", response: e });
217
216
  break;
218
217
  case "REFUND":
219
- this.dispatch("refund", { status: "refund", response: e });
218
+ this.dispatch("refund", { name: "ERROR", request: this.lastAction, status: "refund", response: e });
220
219
  break;
221
220
  }
222
221
  this.dispatch("serial:message", e);
@@ -360,5 +359,5 @@ class y extends h {
360
359
  }
361
360
  }
362
361
  export {
363
- y as PinPax
362
+ m as PinPax
364
363
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danidoble/webserial",
3
- "version": "4.3.5",
3
+ "version": "4.3.6",
4
4
  "author": "danidoble",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,10 +11,10 @@
11
11
  "devDependencies": {
12
12
  "@danidoble/webserial-vending-commands": "^1.0.1",
13
13
  "@eslint/eslintrc": "^3.3.1",
14
- "@eslint/js": "^9.30.0",
14
+ "@eslint/js": "^9.30.1",
15
15
  "autoprefixer": "^10.4.21",
16
16
  "axios": "^1.10.0",
17
- "eslint": "^9.30.0",
17
+ "eslint": "^9.30.1",
18
18
  "globals": "^15.15.0",
19
19
  "jsencrypt": "^3.3.2",
20
20
  "postcss": "^8.5.6",