@danidoble/webserial 4.4.0-beta.4 → 4.4.0

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.
Files changed (74) hide show
  1. package/dist/boardroid.cjs +1 -1
  2. package/dist/boardroid.js +1 -1
  3. package/dist/hopper.cjs +2 -2
  4. package/dist/hopper.js +8 -8
  5. package/dist/jofemar.cjs +1 -1
  6. package/dist/jofemar.js +1 -1
  7. package/dist/{kernel-C1HLYiV1.cjs → kernel-9JeWIxgz.cjs} +1 -1
  8. package/dist/{kernel-DtXV8d8B.js → kernel-BnWXOCde.js} +1 -1
  9. package/dist/kernel.cjs +1 -1
  10. package/dist/kernel.js +1 -1
  11. package/dist/locker.cjs +1 -1
  12. package/dist/locker.js +1 -1
  13. package/dist/pinpad.cjs +7 -7
  14. package/dist/pinpad.js +33 -32
  15. package/dist/pinpax.cjs +3 -3
  16. package/dist/pinpax.js +117 -75
  17. package/dist/relay.cjs +1 -1
  18. package/dist/relay.js +1 -1
  19. package/dist/types/kernel.d.ts.map +1 -0
  20. package/dist/types/main.d.ts.map +1 -0
  21. package/dist/{serial → types/serial}/boardroid.d.ts +1 -1
  22. package/dist/types/serial/boardroid.d.ts.map +1 -0
  23. package/dist/types/serial/hopper.d.ts.map +1 -0
  24. package/dist/{serial → types/serial}/jofemar.d.ts +1 -1
  25. package/dist/types/serial/jofemar.d.ts.map +1 -0
  26. package/dist/types/serial/kernel.d.ts.map +1 -0
  27. package/dist/{serial → types/serial}/locker.d.ts +1 -1
  28. package/dist/types/serial/locker.d.ts.map +1 -0
  29. package/dist/types/serial/pinpad.d.ts.map +1 -0
  30. package/dist/{serial → types/serial}/pinpax.d.ts +8 -6
  31. package/dist/types/serial/pinpax.d.ts.map +1 -0
  32. package/dist/types/serial/relay.d.ts.map +1 -0
  33. package/dist/types/utils/devices.d.ts.map +1 -0
  34. package/dist/types/utils/dispatcher.d.ts.map +1 -0
  35. package/dist/types/utils/emulator.d.ts.map +1 -0
  36. package/dist/types/utils/utils.d.ts.map +1 -0
  37. package/dist/{webserial-core-CH2Xov2y.js → webserial-core-52yJu-0N.js} +827 -827
  38. package/dist/webserial-core-BgEbN4Gb.cjs +4 -0
  39. package/dist/webserial.cjs +2 -2
  40. package/dist/webserial.js +5 -5
  41. package/package.json +20 -20
  42. package/dist/kernel-C8ISUhzV.cjs +0 -1
  43. package/dist/kernel-CQcZ_OiG.js +0 -831
  44. package/dist/kernel-DkC7Kj3m.js +0 -841
  45. package/dist/kernel-DyNuXvtW.cjs +0 -1
  46. package/dist/kernel-aqBCxtkj.js +0 -831
  47. package/dist/kernel-pO_elWba.cjs +0 -1
  48. package/dist/kernel.d.ts.map +0 -1
  49. package/dist/main.d.ts.map +0 -1
  50. package/dist/serial/boardroid.d.ts.map +0 -1
  51. package/dist/serial/hopper.d.ts.map +0 -1
  52. package/dist/serial/jofemar.d.ts.map +0 -1
  53. package/dist/serial/kernel.d.ts.map +0 -1
  54. package/dist/serial/locker.d.ts.map +0 -1
  55. package/dist/serial/pinpad.d.ts.map +0 -1
  56. package/dist/serial/pinpax.d.ts.map +0 -1
  57. package/dist/serial/relay.d.ts.map +0 -1
  58. package/dist/utils/devices.d.ts.map +0 -1
  59. package/dist/utils/dispatcher.d.ts.map +0 -1
  60. package/dist/utils/emulator.d.ts.map +0 -1
  61. package/dist/utils/utils.d.ts.map +0 -1
  62. package/dist/webserial-core-Cj_EZjAU.cjs +0 -4
  63. package/dist/webserial-core-D3luFguv.js +0 -3325
  64. package/dist/webserial-core-YjdXyVOx.cjs +0 -4
  65. /package/dist/{kernel.d.ts → types/kernel.d.ts} +0 -0
  66. /package/dist/{main.d.ts → types/main.d.ts} +0 -0
  67. /package/dist/{serial → types/serial}/hopper.d.ts +0 -0
  68. /package/dist/{serial → types/serial}/kernel.d.ts +0 -0
  69. /package/dist/{serial → types/serial}/pinpad.d.ts +0 -0
  70. /package/dist/{serial → types/serial}/relay.d.ts +0 -0
  71. /package/dist/{utils → types/utils}/devices.d.ts +0 -0
  72. /package/dist/{utils → types/utils}/dispatcher.d.ts +0 -0
  73. /package/dist/{utils → types/utils}/emulator.d.ts +0 -0
  74. /package/dist/{utils → types/utils}/utils.d.ts +0 -0
package/dist/pinpad.js CHANGED
@@ -1,4 +1,4 @@
1
- import { K as mi, a as yi, D as le, i as z, b as fe, w as pe } from "./kernel-DtXV8d8B.js";
1
+ import { K as mi, a as yi, D as le, i as z, b as fe, w as pe } from "./kernel-BnWXOCde.js";
2
2
  var bi = "0123456789abcdefghijklmnopqrstuvwxyz";
3
3
  function G(n) {
4
4
  return bi.charAt(n);
@@ -119,7 +119,7 @@ var ct, wi = {
119
119
  }
120
120
  }, ut = 1e13, mt = (
121
121
  /** @class */
122
- (function() {
122
+ function() {
123
123
  function n(t) {
124
124
  this.buf = [+t || 0];
125
125
  }
@@ -148,14 +148,14 @@ var ct, wi = {
148
148
  var t = this.buf;
149
149
  return t.length == 1 ? t[0] : this;
150
150
  }, n;
151
- })()
151
+ }()
152
152
  ), Ke = "…", Si = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/, Ti = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
153
153
  function lt(n, t) {
154
154
  return n.length > t && (n = n.substring(0, t) + Ke), n;
155
155
  }
156
156
  var Ht = (
157
157
  /** @class */
158
- (function() {
158
+ function() {
159
159
  function n(t, e) {
160
160
  this.hexDigits = "0123456789ABCDEF", t instanceof n ? (this.enc = t.enc, this.pos = t.pos) : (this.enc = t, this.pos = e);
161
161
  }
@@ -257,10 +257,10 @@ var Ht = (
257
257
  }
258
258
  return a > 0 && (r += ".incomplete"), r;
259
259
  }, n;
260
- })()
260
+ }()
261
261
  ), Ai = (
262
262
  /** @class */
263
- (function() {
263
+ function() {
264
264
  function n(t, e, i, r, s) {
265
265
  if (!(r instanceof me))
266
266
  throw new Error("Invalid tag value.");
@@ -468,10 +468,10 @@ var Ht = (
468
468
  }
469
469
  return new n(i, o, s, r, c);
470
470
  }, n;
471
- })()
471
+ }()
472
472
  ), me = (
473
473
  /** @class */
474
- (function() {
474
+ function() {
475
475
  function n(t) {
476
476
  var e = t.get();
477
477
  if (this.tagClass = e >> 6, this.tagConstructed = (e & 32) !== 0, this.tagNumber = e & 31, this.tagNumber == 31) {
@@ -487,10 +487,10 @@ var Ht = (
487
487
  }, n.prototype.isEOC = function() {
488
488
  return this.tagClass === 0 && this.tagNumber === 0;
489
489
  }, n;
490
- })()
490
+ }()
491
491
  ), Y, Ci = 244837814094590, ye = (Ci & 16777215) == 15715070, N = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997], Ri = (1 << 26) / N[N.length - 1], P = (
492
492
  /** @class */
493
- (function() {
493
+ function() {
494
494
  function n(t, e, i) {
495
495
  t != null && (typeof t == "number" ? this.fromNumber(t, e, i) : e == null && typeof t != "string" ? this.fromString(t, 256) : this.fromString(t, e));
496
496
  }
@@ -1007,10 +1007,10 @@ var Ht = (
1007
1007
  o.length = (t >> 3) + 1, e.nextBytes(o), c > 0 ? o[0] &= (1 << c) - 1 : o[0] = 0, this.fromString(o, 256);
1008
1008
  }
1009
1009
  }, n;
1010
- })()
1010
+ }()
1011
1011
  ), Oi = (
1012
1012
  /** @class */
1013
- (function() {
1013
+ function() {
1014
1014
  function n() {
1015
1015
  }
1016
1016
  return n.prototype.convert = function(t) {
@@ -1022,10 +1022,10 @@ var Ht = (
1022
1022
  }, n.prototype.sqrTo = function(t, e) {
1023
1023
  t.squareTo(e);
1024
1024
  }, n;
1025
- })()
1025
+ }()
1026
1026
  ), be = (
1027
1027
  /** @class */
1028
- (function() {
1028
+ function() {
1029
1029
  function n(t) {
1030
1030
  this.m = t;
1031
1031
  }
@@ -1040,10 +1040,10 @@ var Ht = (
1040
1040
  }, n.prototype.sqrTo = function(t, e) {
1041
1041
  t.squareTo(e), this.reduce(e);
1042
1042
  }, n;
1043
- })()
1043
+ }()
1044
1044
  ), Pe = (
1045
1045
  /** @class */
1046
- (function() {
1046
+ function() {
1047
1047
  function n(t) {
1048
1048
  this.m = t, this.mp = t.invDigit(), this.mpl = this.mp & 32767, this.mph = this.mp >> 15, this.um = (1 << t.DB - 15) - 1, this.mt2 = 2 * t.t;
1049
1049
  }
@@ -1067,10 +1067,10 @@ var Ht = (
1067
1067
  }, n.prototype.sqrTo = function(t, e) {
1068
1068
  t.squareTo(e), this.reduce(e);
1069
1069
  }, n;
1070
- })()
1070
+ }()
1071
1071
  ), Di = (
1072
1072
  /** @class */
1073
- (function() {
1073
+ function() {
1074
1074
  function n(t) {
1075
1075
  this.m = t, this.r2 = E(), this.q3 = E(), P.ONE.dlShiftTo(2 * t.t, this.r2), this.mu = this.r2.divide(t);
1076
1076
  }
@@ -1093,7 +1093,7 @@ var Ht = (
1093
1093
  }, n.prototype.sqrTo = function(t, e) {
1094
1094
  t.squareTo(e), this.reduce(e);
1095
1095
  }, n;
1096
- })()
1096
+ }()
1097
1097
  );
1098
1098
  function E() {
1099
1099
  return new P(null);
@@ -1154,7 +1154,7 @@ P.ZERO = Q(0);
1154
1154
  P.ONE = Q(1);
1155
1155
  var Ii = (
1156
1156
  /** @class */
1157
- (function() {
1157
+ function() {
1158
1158
  function n() {
1159
1159
  this.i = 0, this.j = 0, this.S = [];
1160
1160
  }
@@ -1169,7 +1169,7 @@ var Ii = (
1169
1169
  var t;
1170
1170
  return this.i = this.i + 1 & 255, this.j = this.j + this.S[this.i] & 255, t = this.S[this.i], this.S[this.i] = this.S[this.j], this.S[this.j] = t, this.S[t + this.S[this.i] & 255];
1171
1171
  }, n;
1172
- })()
1172
+ }()
1173
1173
  );
1174
1174
  function Bi() {
1175
1175
  return new Ii();
@@ -1210,14 +1210,14 @@ function Ni() {
1210
1210
  }
1211
1211
  var Vt = (
1212
1212
  /** @class */
1213
- (function() {
1213
+ function() {
1214
1214
  function n() {
1215
1215
  }
1216
1216
  return n.prototype.nextBytes = function(t) {
1217
1217
  for (var e = 0; e < t.length; ++e)
1218
1218
  t[e] = Ni();
1219
1219
  }, n;
1220
- })()
1220
+ }()
1221
1221
  );
1222
1222
  function Qt(n) {
1223
1223
  return Vi(Ki(xi(n), n.length * 8));
@@ -1332,7 +1332,7 @@ function zi(n, t) {
1332
1332
  }
1333
1333
  var Gi = (
1334
1334
  /** @class */
1335
- (function() {
1335
+ function() {
1336
1336
  function n() {
1337
1337
  this.n = null, this.e = 0, this.d = null, this.p = null, this.q = null, this.dmp1 = null, this.dmq1 = null, this.coeff = null;
1338
1338
  }
@@ -1428,7 +1428,7 @@ var Gi = (
1428
1428
  var a = s.toString(16).replace(/^1f+00/, ""), o = Qi(a);
1429
1429
  return o == i(t).toString();
1430
1430
  }, n;
1431
- })()
1431
+ }()
1432
1432
  );
1433
1433
  function $i(n, t) {
1434
1434
  for (var e = n.toByteArray(), i = 0; i < e.length && e[i] == 0; )
@@ -1859,7 +1859,7 @@ p.asn1.DERTaggedObject = function(n) {
1859
1859
  }, typeof n < "u" && (typeof n.tag < "u" && (this.hT = n.tag), typeof n.explicit < "u" && (this.isExplicit = n.explicit), typeof n.obj < "u" && (this.asn1Object = n.obj, this.setASN1Object(this.isExplicit, this.hT, this.asn1Object)));
1860
1860
  };
1861
1861
  R(p.asn1.DERTaggedObject, p.asn1.ASN1Object);
1862
- var Zi = /* @__PURE__ */ (function() {
1862
+ var Zi = /* @__PURE__ */ function() {
1863
1863
  var n = function(t, e) {
1864
1864
  return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(i, r) {
1865
1865
  i.__proto__ = r;
@@ -1876,9 +1876,9 @@ var Zi = /* @__PURE__ */ (function() {
1876
1876
  }
1877
1877
  t.prototype = e === null ? Object.create(e) : (i.prototype = e.prototype, new i());
1878
1878
  };
1879
- })(), Te = (
1879
+ }(), Te = (
1880
1880
  /** @class */
1881
- (function(n) {
1881
+ function(n) {
1882
1882
  Zi(t, n);
1883
1883
  function t(e) {
1884
1884
  var i = n.call(this) || this;
@@ -1974,10 +1974,10 @@ var Zi = /* @__PURE__ */ (function() {
1974
1974
  }, t.prototype.parsePropertiesFrom = function(e) {
1975
1975
  this.n = e.n, this.e = e.e, e.hasOwnProperty("d") && (this.d = e.d, this.p = e.p, this.q = e.q, this.dmp1 = e.dmp1, this.dmq1 = e.dmq1, this.coeff = e.coeff);
1976
1976
  }, t;
1977
- })(Gi)
1977
+ }(Gi)
1978
1978
  ), Xt, Yi = typeof process < "u" ? (Xt = process.env) === null || Xt === void 0 ? void 0 : Xt.npm_package_version : void 0, tn = (
1979
1979
  /** @class */
1980
- (function() {
1980
+ function() {
1981
1981
  function n(t) {
1982
1982
  t === void 0 && (t = {}), this.default_key_size = t.default_key_size ? parseInt(t.default_key_size, 10) : 1024, this.default_public_exponent = t.default_public_exponent || "010001", this.log = t.log || !1, this.key = t.key || null;
1983
1983
  }
@@ -2049,7 +2049,7 @@ var Zi = /* @__PURE__ */ (function() {
2049
2049
  }, n.prototype.getPublicKeyB64 = function() {
2050
2050
  return this.getKey().getPublicBaseKeyB64();
2051
2051
  }, n.version = Yi, n;
2052
- })()
2052
+ }()
2053
2053
  );
2054
2054
  function Xe(n, t) {
2055
2055
  return function() {
@@ -4223,8 +4223,9 @@ class $r extends mi {
4223
4223
  this.dispatch("serial:message", e);
4224
4224
  }
4225
4225
  serialSetConnectionConstant() {
4226
+ const t = "", e = "";
4226
4227
  let i = "C56AABOUT";
4227
- i = "" + i.length.toString().padStart(3, "0") + i + "";
4228
+ i = t + i.length.toString().padStart(3, "0") + i + e;
4228
4229
  let r = 0;
4229
4230
  for (let a = 0; a < i.length; a++)
4230
4231
  r ^= i.charCodeAt(a);
package/dist/pinpax.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./kernel-C1HLYiV1.cjs"),t=require("./relay-E3NCcSjS.cjs");class p extends o.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:a=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:a,device_listen_on_channel:i,socket:n}),this.__internal__.device.type="pinpax",o.Devices.getCustom(this.typeDevice,a))throw new Error(`Device ${this.typeDevice} ${a} 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(),o.Devices.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(a){console.error("Error parsing response",a,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(){return t.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(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),a=this.parseStringToBytes(e,`\r
3
- `);await this.appendToQueue(this.stringArrayToUint8Array(a),"custom")}async connectMessage(){await this.appendToQueue(t.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");return this.queue.length===0?!0:new Promise(s=>{const e=setInterval(()=>{this.queue.length===0&&(clearInterval(e),s(!0))},500)})}async#s({type:s="production"}={}){const e=t.s.readQR({type:s});return await this.appendToQueue(e,"read-qr")}async#a(){await this.appendToQueue(t.s.forceHide(),"force-hide")}async#i(){await this.appendToQueue(t.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)}cancelSaleRequestInProcess(){this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:{}})}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 a=t.s.makeSale({amount:s,reference:e});return this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e(),await this.appendToQueue(a,"make-sale"),new Promise(i=>{const n=setInterval(()=>{if(this.__pinpax__.asyncResponses.sale){const r=this.__pinpax__.asyncResponses.sale;this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.waiting.sale=!1,clearInterval(n),i(r.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=t.s.getVoucher({folio:s});return this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher"),new Promise((a,i)=>{const n=setTimeout(()=>{this.__pinpax__.waiting.voucher=!1,i("Timeout")},1e4),r=setInterval(()=>{if(this.__pinpax__.asyncResponses.voucher){const c=this.__pinpax__.asyncResponses.voucher;this.__pinpax__.asyncResponses.voucher=null,this.__pinpax__.waiting.voucher=!1,clearInterval(r),clearTimeout(n),a(c.voucher)}},100)})}async info(){await this.appendToQueue(t.s.info(),"info")}async keepAlive(){await this.appendToQueue(t.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(t.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(t.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(t.s.hideButtons(),"hide-buttons"),await this.#a()}async showButtons(){return await this.appendToQueue(t.s.showButtons(),"show-buttons"),await this.#i()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(t.s.demo(),"demo")}async refund({amount:s=0,folio:e=null,auth:a=null}={}){return await this.appendToQueue(t.s.refund({amount:s,folio:e,auth:a}),"refund")}async readProductionQR(){return await this.#s({type:"production"})}async readQualityAssuranceQR(){return this.#s({type:"QA"})}async exit(){return await this.appendToQueue(t.s.exit(),"exit-app")}async init(){await this.appendToQueue(t.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
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-9JeWIxgz.cjs"),s=require("./relay-E3NCcSjS.cjs");class p extends c.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
+ `,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
4
4
  `);await this.appendToQueue(e,"login")}}exports.PinPax=p;
package/dist/pinpax.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as p, D as o } from "./kernel-DtXV8d8B.js";
2
- import { s as t } from "./relay-DP8PLsDP.js";
1
+ import { K as p, D as c } from "./kernel-BnWXOCde.js";
2
+ import { s } from "./relay-DP8PLsDP.js";
3
3
  class l extends p {
4
4
  __pinpax__ = {
5
5
  server: "DEV",
@@ -12,11 +12,13 @@ class l extends p {
12
12
  },
13
13
  waiting: {
14
14
  voucher: !1,
15
- sale: !1
15
+ sale: !1,
16
+ sale_init: "idle",
17
+ sale_login: "idle"
16
18
  }
17
19
  };
18
20
  constructor({
19
- filters: s = null,
21
+ filters: i = null,
20
22
  config_port: e = {
21
23
  baudRate: 115200,
22
24
  dataBits: 8,
@@ -25,8 +27,8 @@ class l extends p {
25
27
  bufferSize: 32768,
26
28
  flowControl: "none"
27
29
  },
28
- no_device: a = 1,
29
- device_listen_on_channel: i = 1,
30
+ no_device: t = 1,
31
+ device_listen_on_channel: a = 1,
30
32
  socket: n = !1
31
33
  } = {
32
34
  filters: null,
@@ -42,13 +44,13 @@ class l extends p {
42
44
  device_listen_on_channel: 1,
43
45
  socket: !1
44
46
  }) {
45
- if (super({ filters: s, config_port: e, no_device: a, device_listen_on_channel: i, socket: n }), this.__internal__.device.type = "pinpax", o.getCustom(this.typeDevice, a))
46
- throw new Error(`Device ${this.typeDevice} ${a} already exists`);
47
+ if (super({ filters: i, config_port: e, no_device: t, device_listen_on_channel: a, socket: n }), this.__internal__.device.type = "pinpax", c.getCustom(this.typeDevice, t))
48
+ throw new Error(`Device ${this.typeDevice} ${t} already exists`);
47
49
  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
48
- `, this.#t(), o.add(this), this.getResponseAsString();
50
+ `, this.#t(), c.add(this), this.getResponseAsString();
49
51
  }
50
52
  #t() {
51
- const s = [
53
+ const i = [
52
54
  "buttons-status",
53
55
  "init-app",
54
56
  "connectMessage",
@@ -62,44 +64,47 @@ class l extends p {
62
64
  "refund",
63
65
  "login"
64
66
  ];
65
- for (const e of s)
67
+ for (const e of i)
66
68
  this.serialRegisterAvailableListener(e);
67
69
  }
68
- set businessId(s) {
69
- this.__pinpax__.businessId = s;
70
+ set businessId(i) {
71
+ this.__pinpax__.businessId = i;
70
72
  }
71
73
  get businessId() {
72
74
  return this.__pinpax__.businessId;
73
75
  }
74
- set encryptionKey(s) {
75
- this.__pinpax__.encryptionKey = s;
76
+ set encryptionKey(i) {
77
+ this.__pinpax__.encryptionKey = i;
76
78
  }
77
79
  get encryptionKey() {
78
80
  return this.__pinpax__.encryptionKey;
79
81
  }
80
- set apiKey(s) {
81
- this.__pinpax__.apiKey = s;
82
+ set apiKey(i) {
83
+ this.__pinpax__.apiKey = i;
82
84
  }
83
85
  get apiKey() {
84
86
  return this.__pinpax__.apiKey;
85
87
  }
86
- set server(s) {
87
- this.__pinpax__.server = s;
88
+ set server(i) {
89
+ this.__pinpax__.server = i;
88
90
  }
89
91
  get server() {
90
92
  return this.__pinpax__.server;
91
93
  }
92
- serialMessage(s) {
94
+ serialMessage(i) {
93
95
  let e = null;
94
96
  try {
95
- e = JSON.parse(s), e.request || (e.request = this.lastAction), e.name || (e.name = this.lastAction);
96
- } catch (a) {
97
- console.error("Error parsing response", a, s), this.dispatch("serial:message", s);
97
+ e = JSON.parse(i), e.request || (e.request = this.lastAction), e.name || (e.name = this.lastAction);
98
+ } catch (t) {
99
+ console.error("Error parsing response", t, i), this.dispatch("serial:message", i);
98
100
  return;
99
101
  }
100
102
  switch (e.response) {
103
+ case "INIT":
104
+ this.dispatch("init", { name: "INIT", request: this.lastAction, status: "ok" }), this.__pinpax__.waiting.sale_init === "waiting" && (this.__pinpax__.waiting.sale_init = "received");
105
+ break;
101
106
  case "INITAPP":
102
- this.dispatch("init-app", { name: "INITAPP", request: this.lastAction, status: "started" }), this.#n().then(() => {
107
+ 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(() => {
103
108
  });
104
109
  break;
105
110
  case "CONNECT":
@@ -107,7 +112,7 @@ class l extends p {
107
112
  });
108
113
  break;
109
114
  case "LOGIN":
110
- e.name || (e.name = "LOGIN"), this.dispatch("login", e);
115
+ e.name || (e.name = "LOGIN"), this.__pinpax__.waiting.sale_login === "waiting" && (this.__pinpax__.waiting.sale_login = "received"), this.dispatch("login", e);
111
116
  break;
112
117
  case "LASTVOUCHER":
113
118
  e.name || (e.name = "LASTVOUCHER"), this.dispatch("voucher", e), this.__pinpax__.waiting.voucher && (this.__pinpax__.asyncResponses.voucher = e, this.__pinpax__.waiting.voucher = !1);
@@ -222,40 +227,40 @@ class l extends p {
222
227
  this.dispatch("serial:message", e);
223
228
  }
224
229
  serialSetConnectionConstant() {
225
- return t.connection();
230
+ return s.connection();
226
231
  }
227
232
  softReload() {
228
233
  super.softReload(), this.__pinpax__.waiting.sale = !1, this.__pinpax__.waiting.voucher = !1, this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.asyncResponses.voucher = null;
229
234
  }
230
- async sendCustomCode(s = {}) {
231
- if (typeof s != "object") throw new Error("Invalid object");
232
- if (s.constructor !== Object) throw new Error("Invalid object");
233
- if (Object.keys(s).length === 0) throw new Error("Empty object");
234
- if (s.action === void 0 || s.action === null) throw new Error("Invalid object add action");
235
- const e = JSON.stringify(s), a = this.parseStringToBytes(e, `\r
235
+ async sendCustomCode(i = {}) {
236
+ if (typeof i != "object") throw new Error("Invalid object");
237
+ if (i.constructor !== Object) throw new Error("Invalid object");
238
+ if (Object.keys(i).length === 0) throw new Error("Empty object");
239
+ if (i.action === void 0 || i.action === null) throw new Error("Invalid object add action");
240
+ const e = JSON.stringify(i), t = this.parseStringToBytes(e, `\r
236
241
  `);
237
- await this.appendToQueue(this.stringArrayToUint8Array(a), "custom");
242
+ await this.appendToQueue(this.stringArrayToUint8Array(t), "custom");
238
243
  }
239
244
  async connectMessage() {
240
- await this.appendToQueue(t.connect(), "connect:message");
245
+ await this.appendToQueue(s.connect(), "connect:message");
241
246
  }
242
247
  async #e() {
243
248
  if (this.isDisconnected) throw new Error("Device is disconnected");
244
- return this.queue.length === 0 ? !0 : new Promise((s) => {
249
+ return this.queue.length === 0 ? !0 : new Promise((i) => {
245
250
  const e = setInterval(() => {
246
- this.queue.length === 0 && (clearInterval(e), s(!0));
251
+ this.queue.length === 0 && (clearInterval(e), i(!0));
247
252
  }, 500);
248
253
  });
249
254
  }
250
- async #s({ type: s = "production" } = {}) {
251
- const e = t.readQR({ type: s });
255
+ async #i({ type: i = "production" } = {}) {
256
+ const e = s.readQR({ type: i });
252
257
  return await this.appendToQueue(e, "read-qr");
253
258
  }
254
- async #a() {
255
- await this.appendToQueue(t.forceHide(), "force-hide");
259
+ async #s() {
260
+ await this.appendToQueue(s.forceHide(), "force-hide");
256
261
  }
257
- async #i() {
258
- await this.appendToQueue(t.forceShow(), "force-show");
262
+ async #a() {
263
+ await this.appendToQueue(s.forceShow(), "force-show");
259
264
  }
260
265
  async #n() {
261
266
  await this.connectMessage();
@@ -263,8 +268,8 @@ class l extends p {
263
268
  async #r() {
264
269
  await this.hideButtons();
265
270
  }
266
- #o(s) {
267
- this.dispatch("payment", s), this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = s);
271
+ #o(i) {
272
+ this.dispatch("payment", i), this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = i);
268
273
  }
269
274
  cancelSaleRequestInProcess() {
270
275
  this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = {
@@ -273,89 +278,126 @@ class l extends p {
273
278
  response: {}
274
279
  });
275
280
  }
276
- async makeSale({ amount: s = 0, reference: e = null } = {}) {
281
+ async #c() {
282
+ return new Promise((i, e) => {
283
+ const t = setTimeout(() => {
284
+ this.__pinpax__.waiting.sale_login === "waiting" && (this.__pinpax__.waiting.sale_login = "timeout", e(new Error("Login timeout")));
285
+ }, 1e4), a = setInterval(() => {
286
+ this.__pinpax__.waiting.sale_login === "received" && (clearTimeout(t), clearInterval(a), i(!0));
287
+ }, 100);
288
+ });
289
+ }
290
+ async #p() {
291
+ return new Promise((i, e) => {
292
+ const t = setTimeout(() => {
293
+ this.__pinpax__.waiting.sale_init === "waiting" && (this.__pinpax__.waiting.sale_init = "timeout", e(new Error("Init timeout")));
294
+ }, 1e4), a = setInterval(() => {
295
+ this.__pinpax__.waiting.sale_init === "received" && (clearTimeout(t), clearInterval(a), i(!0));
296
+ }, 100);
297
+ });
298
+ }
299
+ async makeSale({
300
+ amount: i = 0,
301
+ reference: e = null
302
+ } = {
303
+ amount: 0,
304
+ reference: null
305
+ }) {
277
306
  if (this.isDisconnected) throw new Error("Device is disconnected");
278
307
  if (this.__pinpax__.waiting.sale) throw new Error("Already waiting for sale response");
279
- const a = t.makeSale({ amount: s, reference: e });
280
- return this.__pinpax__.waiting.sale = !0, this.__pinpax__.asyncResponses.sale = null, this.queue.length > 0 && await this.#e(), await this.appendToQueue(a, "make-sale"), new Promise((i) => {
281
- const n = setInterval(() => {
308
+ const t = s.makeSale({ amount: i, reference: e });
309
+ this.__pinpax__.waiting.sale = !0, this.__pinpax__.asyncResponses.sale = null, this.queue.length > 0 && await this.#e();
310
+ let a = !1;
311
+ try {
312
+ 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";
313
+ } catch (n) {
314
+ a = !0, this.__pinpax__.waiting.sale_login = "idle", this.__pinpax__.waiting.sale_init = "idle", this.__pinpax__.waiting.sale = !1, this.dispatch("error", {
315
+ name: "ERROR",
316
+ request: this.lastAction,
317
+ status: "error",
318
+ response: "Error during login/init before sale",
319
+ error: n
320
+ });
321
+ }
322
+ return a ? !1 : (await this.appendToQueue(t, "make-sale"), new Promise((n) => {
323
+ const r = setInterval(() => {
282
324
  if (this.__pinpax__.asyncResponses.sale) {
283
- const r = this.__pinpax__.asyncResponses.sale;
284
- this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.waiting.sale = !1, clearInterval(n), i(r.approved);
325
+ const o = this.__pinpax__.asyncResponses.sale;
326
+ this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.waiting.sale = !1, clearInterval(r), n(o.approved);
285
327
  }
286
328
  }, 100);
287
- });
329
+ }));
288
330
  }
289
- async getVoucher({ folio: s = null } = {}) {
331
+ async getVoucher({ folio: i = null } = {}) {
290
332
  if (this.isDisconnected) throw new Error("Device is disconnected");
291
333
  if (this.__pinpax__.waiting.voucher) throw new Error("Already waiting for voucher");
292
- if (!s) throw new Error("Folio is required");
334
+ if (!i) throw new Error("Folio is required");
293
335
  this.__pinpax__.waiting.voucher = !0, this.__pinpax__.asyncResponses.voucher = null;
294
- const e = t.getVoucher({ folio: s });
295
- return this.queue.length > 0 && await this.#e(), await this.appendToQueue(e, "get-voucher"), new Promise((a, i) => {
336
+ const e = s.getVoucher({ folio: i });
337
+ return this.queue.length > 0 && await this.#e(), await this.appendToQueue(e, "get-voucher"), new Promise((t, a) => {
296
338
  const n = setTimeout(() => {
297
- this.__pinpax__.waiting.voucher = !1, i("Timeout");
339
+ this.__pinpax__.waiting.voucher = !1, a("Timeout");
298
340
  }, 1e4), r = setInterval(() => {
299
341
  if (this.__pinpax__.asyncResponses.voucher) {
300
- const c = this.__pinpax__.asyncResponses.voucher;
301
- this.__pinpax__.asyncResponses.voucher = null, this.__pinpax__.waiting.voucher = !1, clearInterval(r), clearTimeout(n), a(c.voucher);
342
+ const o = this.__pinpax__.asyncResponses.voucher;
343
+ this.__pinpax__.asyncResponses.voucher = null, this.__pinpax__.waiting.voucher = !1, clearInterval(r), clearTimeout(n), t(o.voucher);
302
344
  }
303
345
  }, 100);
304
346
  });
305
347
  }
306
348
  async info() {
307
- await this.appendToQueue(t.info(), "info");
349
+ await this.appendToQueue(s.info(), "info");
308
350
  }
309
351
  async keepAlive() {
310
- await this.appendToQueue(t.keepAlive(), "keep-alive");
352
+ await this.appendToQueue(s.keepAlive(), "keep-alive");
311
353
  }
312
354
  async restartApp() {
313
- await this.appendToQueue(t.restartApp(), "reset-app");
355
+ await this.appendToQueue(s.restartApp(), "reset-app");
314
356
  }
315
357
  async getConfig() {
316
- return await this.appendToQueue(t.getConfig(), "get-config");
358
+ return await this.appendToQueue(s.getConfig(), "get-config");
317
359
  }
318
360
  async hideButtons() {
319
- return await this.appendToQueue(t.hideButtons(), "hide-buttons"), await this.#a();
361
+ return await this.appendToQueue(s.hideButtons(), "hide-buttons"), await this.#s();
320
362
  }
321
363
  async showButtons() {
322
- return await this.appendToQueue(t.showButtons(), "show-buttons"), await this.#i();
364
+ return await this.appendToQueue(s.showButtons(), "show-buttons"), await this.#a();
323
365
  }
324
366
  async demo() {
325
- return console.warn("RUNNING DEMO APP, BE CAREFUL"), await this.appendToQueue(t.demo(), "demo");
367
+ return console.warn("RUNNING DEMO APP, BE CAREFUL"), await this.appendToQueue(s.demo(), "demo");
326
368
  }
327
- async refund({ amount: s = 0, folio: e = null, auth: a = null } = {}) {
369
+ async refund({ amount: i = 0, folio: e = null, auth: t = null } = {}) {
328
370
  return await this.appendToQueue(
329
- t.refund({
330
- amount: s,
371
+ s.refund({
372
+ amount: i,
331
373
  folio: e,
332
- auth: a
374
+ auth: t
333
375
  }),
334
376
  "refund"
335
377
  );
336
378
  }
337
379
  async readProductionQR() {
338
- return await this.#s({ type: "production" });
380
+ return await this.#i({ type: "production" });
339
381
  }
340
382
  async readQualityAssuranceQR() {
341
- return this.#s({ type: "QA" });
383
+ return this.#i({ type: "QA" });
342
384
  }
343
385
  async exit() {
344
- return await this.appendToQueue(t.exit(), "exit-app");
386
+ return await this.appendToQueue(s.exit(), "exit-app");
345
387
  }
346
388
  async init() {
347
- await this.appendToQueue(t.init(), "init-app");
389
+ await this.appendToQueue(s.init(), "init-app");
348
390
  }
349
391
  async login() {
350
392
  if (!this.apiKey || !this.businessId || !this.encryptionKey || !this.server)
351
393
  throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");
352
- const s = JSON.stringify({
394
+ const i = JSON.stringify({
353
395
  action: "LOGIN_MIT",
354
396
  server: this.__pinpax__.server,
355
397
  business_id: this.__pinpax__.businessId,
356
398
  encryption_key: this.__pinpax__.encryptionKey,
357
399
  api_key: this.__pinpax__.apiKey
358
- }), e = this.parseStringToBytes(s, `\r
400
+ }), e = this.parseStringToBytes(i, `\r
359
401
  `);
360
402
  await this.appendToQueue(e, "login");
361
403
  }
package/dist/relay.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-C1HLYiV1.cjs"),a=require("./relay-E3NCcSjS.cjs");class r extends n.Kernel{constructor({filters:t=null,config_port:e,no_device:s=1,socket:i=!1}={}){if(super({filters:t,config_port:e,no_device:s,socket:i}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],n.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);n.Devices.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)}serialSetConnectionConstant(t=1){return a.e.connection(t)}async turnOn(){const t=a.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=a.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await n.wait(e),await this.turnOff();return}await this.turnOff(),await n.wait(e),await this.turnOn()}}exports.Relay=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-9JeWIxgz.cjs"),a=require("./relay-E3NCcSjS.cjs");class r extends n.Kernel{constructor({filters:t=null,config_port:e,no_device:s=1,socket:i=!1}={}){if(super({filters:t,config_port:e,no_device:s,socket:i}),this.__internal__.device.type="relay",this.__internal__.auto_response=!1,this.__internal__.serial.auto_response=[2,6,221,221,240,207,3],n.Devices.getCustom(this.typeDevice,s))throw new Error(`Device ${this.typeDevice} ${s} already exists`);n.Devices.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)}serialSetConnectionConstant(t=1){return a.e.connection(t)}async turnOn(){const t=a.e.activate();await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=a.e.deactivate();await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){if(!t){await this.turnOn(),await n.wait(e),await this.turnOff();return}await this.turnOff(),await n.wait(e),await this.turnOn()}}exports.Relay=r;