@danidoble/webserial 4.2.1 → 4.2.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.
@@ -0,0 +1,20 @@
1
+ "use strict";var C=Object.defineProperty;var y=n=>{throw TypeError(n)};var O=(n,a,s)=>a in n?C(n,a,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[a]=s;var g=(n,a,s)=>O(n,typeof a!="symbol"?a+"":a,s),B=(n,a,s)=>a.has(n)||y("Cannot "+s);var f=(n,a,s)=>a.has(n)?y("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(n):a.set(n,s);var r=(n,a,s)=>(B(n,a,"access private method"),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./kernel-CtyQRsMI.cjs");var t,m,w,_,d,T,S,E,v,N,R;class k extends l.Kernel{constructor({filters:s=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:i=1,device_listen_on_channel:o=1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1}){super({filters:s,config_port:e,no_device:i,device_listen_on_channel:o});f(this,t);g(this,"__pinpax__",{asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1}});if(this.__internal__.device.type="pinpax",l.c.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} 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
+ `,r(this,t,w).call(this),r(this,t,m).call(this),this.getResponseAsString()}serialMessage(s){let e=null;try{e=JSON.parse(s)}catch(i){console.error("Error parsing response",i,s),this.dispatch("serial:message",s);return}switch(e.response){case"INITAPP":this.dispatch("init-app",{status:"started"}),r(this,t,E).call(this).then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{status:"connected"}),r(this,t,v).call(this).then(()=>{});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":r(this,t,N).call(this,{status:"result",approved:e.approved,acquirer:e.acquirer,address:e.address,amount:e.amount,amountCashback:e.amountCashback,appIDLabel:e.appIDLabel,appId:e.appId,arqc:e.arqc,auth:e.auth,ccBin:e.ccBin,ccExpirationDate:e.ccExpirationDate,ccName:e.ccName,ccNumber:e.ccNumber,ccType:e.ccType,comissionCashback:e.comissionCashback,currency:e.currency,date:e.date,errorCode:e.errorCode,errorDescription:e.errorDescription,folio:e.folio,id:e.id,merchantName:e.merchantName,msiLabel:e.msiLabel,operation:e.operation,pin:e.pin,qps:e.qps,reference:e.reference,response:e.response,source:e.source,sourceLabel:e.sourceLabel,time:e.time});break;case"ERROR":this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{status:"error",response:e}),this.dispatch("payment",{status:"error",response:e});break;case"REFUND":this.dispatch("refund",{status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(s=1){const e=JSON.stringify({action:"CONNECT"});return this.add0x(this.parseStringToBytes(e,`\r
3
+ `))}softReload(){super.softReload(),this.__pinpax__.waiting.sale=!1,this.__pinpax__.waiting.voucher=!1,this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.asyncResponses.voucher=null}async sendCustomCode({code:s=""}={}){if(typeof s!="string")throw new Error("Invalid string");const e=this.parseStringToBytes(s,`\r
4
+ `);await this.appendToQueue(e,"custom")}async connectMessage(){const s=JSON.stringify({action:"CONNECT"}),e=this.parseStringToBytes(s,`\r
5
+ `);await this.appendToQueue(e,"connect:message")}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");if(s<=0)throw new Error("Invalid amount");if(s=parseFloat(s),isNaN(s))throw new Error("Invalid amount");if(!e&&!r(this,t,R).call(this,e))throw new Error("Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null");s=s.toFixed(2);const i=JSON.stringify({action:"PAYMENT",amount:s,reference:e}),o=this.parseStringToBytes(i,`\r
6
+ `);this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await r(this,t,_).call(this);const c=this;return await this.appendToQueue(o,"make-sale"),new Promise(p=>{const h=setInterval(()=>{if(c.__pinpax__.asyncResponses.sale){const u=c.__pinpax__.asyncResponses.sale;c.__pinpax__.asyncResponses.sale=null,c.__pinpax__.waiting.sale=!1,clearInterval(h),p(u.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=JSON.stringify({action:"GETVOUCHER",folio:s}),i=this.parseStringToBytes(e,`\r
7
+ `);this.queue.length>0&&await r(this,t,_).call(this),await this.appendToQueue(i,"get-voucher");const o=this;return new Promise((c,p)=>{const h=setTimeout(()=>{o.__pinpax__.waiting.voucher=!1,p("Timeout")},1e4),u=setInterval(()=>{if(o.__pinpax__.asyncResponses.voucher){const b=o.__pinpax__.asyncResponses.voucher;o.__pinpax__.asyncResponses.voucher=null,o.__pinpax__.waiting.voucher=!1,clearInterval(u),clearTimeout(h),c(b.voucher)}},100)})}async info(){const s=JSON.stringify({action:"DEVICEINFO"}),e=this.parseStringToBytes(s,`\r
8
+ `);await this.appendToQueue(e,"info")}async keepAlive(){const s=JSON.stringify({action:"KEEPALIVE"}),e=this.parseStringToBytes(s,`\r
9
+ `);await this.appendToQueue(e,"keep-alive")}async restartApp(){const s=JSON.stringify({action:"RESETAPP"}),e=this.parseStringToBytes(s,`\r
10
+ `);await this.appendToQueue(e,"reset-app")}async getConfig(){const s=JSON.stringify({action:"GETCONFIG"}),e=this.parseStringToBytes(s,`\r
11
+ `);return await this.appendToQueue(e,"get-config")}async hideButtons(){const s=JSON.stringify({action:"HIDEBUTTONS"}),e=this.parseStringToBytes(s,`\r
12
+ `);return await this.appendToQueue(e,"hide-buttons"),await r(this,t,T).call(this)}async showButtons(){const s=JSON.stringify({action:"SHOWBUTTONS"}),e=this.parseStringToBytes(s,`\r
13
+ `);return await this.appendToQueue(e,"show-buttons"),await r(this,t,S).call(this)}async demo(){console.warn("RUNNING DEMO APP BE CAREFUL");const s=JSON.stringify({action:"DEMO"}),e=this.parseStringToBytes(s,`\r
14
+ `);return await this.appendToQueue(e,"demo")}async refund({amount:s=0,folio:e=null,auth:i=null}={}){const o=JSON.stringify({action:"REFUND",amount:s,folio:e,auth:i}),c=this.parseStringToBytes(o,`\r
15
+ `);return await this.appendToQueue(c,"refund")}async readProductionQR(){return await r(this,t,d).call(this,{type:"production"})}async readQualityAssuranceQR(){return r(this,t,d).call(this,{type:"QA"})}async exit(){const s=JSON.stringify({action:"EXIT"}),e=this.parseStringToBytes(s,`\r
16
+ `);return await this.appendToQueue(e,"exit-app")}async init(){const s=JSON.stringify({action:"INIT"}),e=this.parseStringToBytes(s,`\r
17
+ `);await this.appendToQueue(e,"init-app")}}t=new WeakSet,m=function(){l.c.add(this)},w=function(){const s=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund"];for(const e of s)this.serialRegisterAvailableListener(e)},_=async function(){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.queue.length===0)return!0;const s=this;return new Promise(e=>{let i=setInterval(()=>{s.queue.length===0&&(clearInterval(i),e(!0))},500)})},d=async function({type:s="production"}={}){const e=JSON.stringify({action:"READQR",server:s==="production"?"PROD":"QA"}),i=this.parseStringToBytes(e,`\r
18
+ `);return await this.appendToQueue(i,"read-qr")},T=async function(){const s=JSON.stringify({action:"FORCEHIDE"}),e=this.parseStringToBytes(s,`\r
19
+ `);await this.appendToQueue(e,"force-hide")},S=async function(){const s=JSON.stringify({action:"FORCESHOW"}),e=this.parseStringToBytes(s,`\r
20
+ `);await this.appendToQueue(e,"force-show")},E=async function(){await this.connectMessage()},v=async function(){await this.hideButtons()},N=function(s){this.dispatch("payment",s),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=s)},R=function(s){return/^[A-Z-a-z0-9_\s]+$/g.test(s)};exports.PinPax=k;
package/dist/pinpax.js ADDED
@@ -0,0 +1,355 @@
1
+ var O = Object.defineProperty;
2
+ var d = (n) => {
3
+ throw TypeError(n);
4
+ };
5
+ var b = (n, a, s) => a in n ? O(n, a, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[a] = s;
6
+ var y = (n, a, s) => b(n, typeof a != "symbol" ? a + "" : a, s), B = (n, a, s) => a.has(n) || d("Cannot " + s);
7
+ var g = (n, a, s) => a.has(n) ? d("Cannot add the same private member more than once") : a instanceof WeakSet ? a.add(n) : a.set(n, s);
8
+ var r = (n, a, s) => (B(n, a, "access private method"), s);
9
+ import { K as x, c as f } from "./kernel-B15wfB2x.js";
10
+ var t, m, w, l, _, T, E, S, N, v, R;
11
+ class A extends x {
12
+ constructor({
13
+ filters: s = null,
14
+ config_port: e = {
15
+ baudRate: 115200,
16
+ dataBits: 8,
17
+ stopBits: 1,
18
+ parity: "none",
19
+ bufferSize: 32768,
20
+ flowControl: "none"
21
+ },
22
+ no_device: i = 1,
23
+ device_listen_on_channel: o = 1
24
+ } = {
25
+ filters: null,
26
+ config_port: {
27
+ baudRate: 115200,
28
+ dataBits: 8,
29
+ stopBits: 1,
30
+ parity: "none",
31
+ bufferSize: 32768,
32
+ flowControl: "none"
33
+ },
34
+ no_device: 1,
35
+ device_listen_on_channel: 1
36
+ }) {
37
+ super({ filters: s, config_port: e, no_device: i, device_listen_on_channel: o });
38
+ g(this, t);
39
+ y(this, "__pinpax__", {
40
+ asyncResponses: {
41
+ voucher: null,
42
+ sale: null
43
+ },
44
+ waiting: {
45
+ voucher: !1,
46
+ sale: !1
47
+ }
48
+ });
49
+ if (this.__internal__.device.type = "pinpax", f.getCustom(this.typeDevice, i))
50
+ throw new Error(`Device ${this.typeDevice} ${i} already exists`);
51
+ 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
52
+ `, r(this, t, w).call(this), r(this, t, m).call(this), this.getResponseAsString();
53
+ }
54
+ serialMessage(s) {
55
+ let e = null;
56
+ try {
57
+ e = JSON.parse(s);
58
+ } catch (i) {
59
+ console.error("Error parsing response", i, s), this.dispatch("serial:message", s);
60
+ return;
61
+ }
62
+ switch (e.response) {
63
+ case "INITAPP":
64
+ this.dispatch("init-app", { status: "started" }), r(this, t, S).call(this).then(() => {
65
+ });
66
+ break;
67
+ case "CONNECT":
68
+ this.dispatch("connectMessage", { status: "connected" }), r(this, t, N).call(this).then(() => {
69
+ });
70
+ break;
71
+ case "LASTVOUCHER":
72
+ this.dispatch("voucher", e), this.__pinpax__.waiting.voucher && (this.__pinpax__.asyncResponses.voucher = e, this.__pinpax__.waiting.voucher = !1);
73
+ break;
74
+ case "DEVICEINFO":
75
+ this.dispatch("info", e);
76
+ break;
77
+ case "KEEPALIVE":
78
+ this.dispatch("keep-alive", { status: "alive" });
79
+ break;
80
+ case "RESETAPP":
81
+ this.dispatch("reset-app", { status: "accepted" });
82
+ break;
83
+ case "GETCONFIG":
84
+ this.dispatch("get-config", e);
85
+ break;
86
+ case "HIDEBUTTONS":
87
+ this.dispatch("buttons-status", { hidden: !0 });
88
+ break;
89
+ case "SHOWBUTTONS":
90
+ this.dispatch("buttons-status", { hidden: !1 });
91
+ break;
92
+ case "PAYMENT_PROCESS":
93
+ this.dispatch("payment", {
94
+ status: "starting",
95
+ amount: e.amount,
96
+ reference: e.referecence
97
+ });
98
+ break;
99
+ case "INSERT_CARD":
100
+ this.dispatch("payment", { status: "insert card" });
101
+ break;
102
+ case "CARD_DATA":
103
+ this.dispatch("payment", {
104
+ status: "card data",
105
+ amount: e.amount,
106
+ cardHolderName: e.cardHolderName,
107
+ ccMark: e.ccMark,
108
+ ccType: e.ccType,
109
+ currency: e.currency,
110
+ maskedPan: e.maskedPan,
111
+ readingType: e.readingType
112
+ });
113
+ break;
114
+ case "MERCHANT":
115
+ this.dispatch("payment", {
116
+ status: "merchant",
117
+ afiliation: e.afiliation,
118
+ alias: e.alias,
119
+ amountCashBackCommission: e.amountCashBackCommission,
120
+ currency: e.currency,
121
+ description: e.description,
122
+ hasCashBack: e.hasCashBack,
123
+ limitCashBackAmount: e.limitCashBackAmount,
124
+ merchant: e.merchant,
125
+ months: e.months,
126
+ name: e.name
127
+ });
128
+ break;
129
+ case "TRANSACTION_RESULT":
130
+ r(this, t, v).call(this, {
131
+ status: "result",
132
+ approved: e.approved,
133
+ acquirer: e.acquirer,
134
+ address: e.address,
135
+ amount: e.amount,
136
+ amountCashback: e.amountCashback,
137
+ appIDLabel: e.appIDLabel,
138
+ appId: e.appId,
139
+ arqc: e.arqc,
140
+ auth: e.auth,
141
+ ccBin: e.ccBin,
142
+ ccExpirationDate: e.ccExpirationDate,
143
+ ccName: e.ccName,
144
+ ccNumber: e.ccNumber,
145
+ ccType: e.ccType,
146
+ comissionCashback: e.comissionCashback,
147
+ currency: e.currency,
148
+ date: e.date,
149
+ errorCode: e.errorCode,
150
+ errorDescription: e.errorDescription,
151
+ folio: e.folio,
152
+ id: e.id,
153
+ merchantName: e.merchantName,
154
+ msiLabel: e.msiLabel,
155
+ operation: e.operation,
156
+ pin: e.pin,
157
+ qps: e.qps,
158
+ reference: e.reference,
159
+ response: e.response,
160
+ source: e.source,
161
+ sourceLabel: e.sourceLabel,
162
+ time: e.time
163
+ });
164
+ break;
165
+ case "ERROR":
166
+ this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = {
167
+ status: "error",
168
+ approved: !1,
169
+ response: e
170
+ }), this.dispatch("error", {
171
+ status: "error",
172
+ response: e
173
+ }), this.dispatch("payment", {
174
+ status: "error",
175
+ response: e
176
+ });
177
+ break;
178
+ case "REFUND":
179
+ this.dispatch("refund", { status: "refund", response: e });
180
+ break;
181
+ }
182
+ this.dispatch("serial:message", e);
183
+ }
184
+ // eslint-disable-next-line no-unused-vars
185
+ serialSetConnectionConstant(s = 1) {
186
+ const e = JSON.stringify({ action: "CONNECT" });
187
+ return this.add0x(this.parseStringToBytes(e, `\r
188
+ `));
189
+ }
190
+ softReload() {
191
+ super.softReload(), this.__pinpax__.waiting.sale = !1, this.__pinpax__.waiting.voucher = !1, this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.asyncResponses.voucher = null;
192
+ }
193
+ async sendCustomCode({ code: s = "" } = {}) {
194
+ if (typeof s != "string") throw new Error("Invalid string");
195
+ const e = this.parseStringToBytes(s, `\r
196
+ `);
197
+ await this.appendToQueue(e, "custom");
198
+ }
199
+ async connectMessage() {
200
+ const s = JSON.stringify({ action: "CONNECT" }), e = this.parseStringToBytes(s, `\r
201
+ `);
202
+ await this.appendToQueue(e, "connect:message");
203
+ }
204
+ async makeSale({ amount: s = 0, reference: e = null } = {}) {
205
+ if (this.isDisconnected) throw new Error("Device is disconnected");
206
+ if (this.__pinpax__.waiting.sale) throw new Error("Already waiting for sale response");
207
+ if (s <= 0) throw new Error("Invalid amount");
208
+ if (s = parseFloat(s), isNaN(s)) throw new Error("Invalid amount");
209
+ if (!e && !r(this, t, R).call(this, e))
210
+ throw new Error(
211
+ "Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null"
212
+ );
213
+ s = s.toFixed(2);
214
+ const i = JSON.stringify({ action: "PAYMENT", amount: s, reference: e }), o = this.parseStringToBytes(i, `\r
215
+ `);
216
+ this.__pinpax__.waiting.sale = !0, this.__pinpax__.asyncResponses.sale = null, this.queue.length > 0 && await r(this, t, l).call(this);
217
+ const c = this;
218
+ return await this.appendToQueue(o, "make-sale"), new Promise((p) => {
219
+ const h = setInterval(() => {
220
+ if (c.__pinpax__.asyncResponses.sale) {
221
+ const u = c.__pinpax__.asyncResponses.sale;
222
+ c.__pinpax__.asyncResponses.sale = null, c.__pinpax__.waiting.sale = !1, clearInterval(h), p(u.approved);
223
+ }
224
+ }, 100);
225
+ });
226
+ }
227
+ async getVoucher({ folio: s = null } = {}) {
228
+ if (this.isDisconnected) throw new Error("Device is disconnected");
229
+ if (this.__pinpax__.waiting.voucher) throw new Error("Already waiting for voucher");
230
+ if (!s) throw new Error("Folio is required");
231
+ this.__pinpax__.waiting.voucher = !0, this.__pinpax__.asyncResponses.voucher = null;
232
+ const e = JSON.stringify({ action: "GETVOUCHER", folio: s }), i = this.parseStringToBytes(e, `\r
233
+ `);
234
+ this.queue.length > 0 && await r(this, t, l).call(this), await this.appendToQueue(i, "get-voucher");
235
+ const o = this;
236
+ return new Promise((c, p) => {
237
+ const h = setTimeout(() => {
238
+ o.__pinpax__.waiting.voucher = !1, p("Timeout");
239
+ }, 1e4), u = setInterval(() => {
240
+ if (o.__pinpax__.asyncResponses.voucher) {
241
+ const C = o.__pinpax__.asyncResponses.voucher;
242
+ o.__pinpax__.asyncResponses.voucher = null, o.__pinpax__.waiting.voucher = !1, clearInterval(u), clearTimeout(h), c(C.voucher);
243
+ }
244
+ }, 100);
245
+ });
246
+ }
247
+ async info() {
248
+ const s = JSON.stringify({ action: "DEVICEINFO" }), e = this.parseStringToBytes(s, `\r
249
+ `);
250
+ await this.appendToQueue(e, "info");
251
+ }
252
+ async keepAlive() {
253
+ const s = JSON.stringify({ action: "KEEPALIVE" }), e = this.parseStringToBytes(s, `\r
254
+ `);
255
+ await this.appendToQueue(e, "keep-alive");
256
+ }
257
+ async restartApp() {
258
+ const s = JSON.stringify({ action: "RESETAPP" }), e = this.parseStringToBytes(s, `\r
259
+ `);
260
+ await this.appendToQueue(e, "reset-app");
261
+ }
262
+ async getConfig() {
263
+ const s = JSON.stringify({ action: "GETCONFIG" }), e = this.parseStringToBytes(s, `\r
264
+ `);
265
+ return await this.appendToQueue(e, "get-config");
266
+ }
267
+ async hideButtons() {
268
+ const s = JSON.stringify({ action: "HIDEBUTTONS" }), e = this.parseStringToBytes(s, `\r
269
+ `);
270
+ return await this.appendToQueue(e, "hide-buttons"), await r(this, t, T).call(this);
271
+ }
272
+ async showButtons() {
273
+ const s = JSON.stringify({ action: "SHOWBUTTONS" }), e = this.parseStringToBytes(s, `\r
274
+ `);
275
+ return await this.appendToQueue(e, "show-buttons"), await r(this, t, E).call(this);
276
+ }
277
+ async demo() {
278
+ console.warn("RUNNING DEMO APP BE CAREFUL");
279
+ const s = JSON.stringify({ action: "DEMO" }), e = this.parseStringToBytes(s, `\r
280
+ `);
281
+ return await this.appendToQueue(e, "demo");
282
+ }
283
+ async refund({ amount: s = 0, folio: e = null, auth: i = null } = {}) {
284
+ const o = JSON.stringify({ action: "REFUND", amount: s, folio: e, auth: i }), c = this.parseStringToBytes(o, `\r
285
+ `);
286
+ return await this.appendToQueue(c, "refund");
287
+ }
288
+ async readProductionQR() {
289
+ return await r(this, t, _).call(this, { type: "production" });
290
+ }
291
+ async readQualityAssuranceQR() {
292
+ return r(this, t, _).call(this, { type: "QA" });
293
+ }
294
+ async exit() {
295
+ const s = JSON.stringify({ action: "EXIT" }), e = this.parseStringToBytes(s, `\r
296
+ `);
297
+ return await this.appendToQueue(e, "exit-app");
298
+ }
299
+ async init() {
300
+ const s = JSON.stringify({ action: "INIT" }), e = this.parseStringToBytes(s, `\r
301
+ `);
302
+ await this.appendToQueue(e, "init-app");
303
+ }
304
+ }
305
+ t = new WeakSet(), m = function() {
306
+ f.add(this);
307
+ }, w = function() {
308
+ const s = [
309
+ "buttons-status",
310
+ "init-app",
311
+ "connectMessage",
312
+ "voucher",
313
+ "info",
314
+ "keep-alive",
315
+ "reset-app",
316
+ "get-config",
317
+ "payment",
318
+ "error",
319
+ "refund"
320
+ ];
321
+ for (const e of s)
322
+ this.serialRegisterAvailableListener(e);
323
+ }, l = async function() {
324
+ if (this.isDisconnected) throw new Error("Device is disconnected");
325
+ if (this.queue.length === 0) return !0;
326
+ const s = this;
327
+ return new Promise((e) => {
328
+ let i = setInterval(() => {
329
+ s.queue.length === 0 && (clearInterval(i), e(!0));
330
+ }, 500);
331
+ });
332
+ }, _ = async function({ type: s = "production" } = {}) {
333
+ const e = JSON.stringify({ action: "READQR", server: s === "production" ? "PROD" : "QA" }), i = this.parseStringToBytes(e, `\r
334
+ `);
335
+ return await this.appendToQueue(i, "read-qr");
336
+ }, T = async function() {
337
+ const s = JSON.stringify({ action: "FORCEHIDE" }), e = this.parseStringToBytes(s, `\r
338
+ `);
339
+ await this.appendToQueue(e, "force-hide");
340
+ }, E = async function() {
341
+ const s = JSON.stringify({ action: "FORCESHOW" }), e = this.parseStringToBytes(s, `\r
342
+ `);
343
+ await this.appendToQueue(e, "force-show");
344
+ }, S = async function() {
345
+ await this.connectMessage();
346
+ }, N = async function() {
347
+ await this.hideButtons();
348
+ }, v = function(s) {
349
+ this.dispatch("payment", s), this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = s);
350
+ }, R = function(s) {
351
+ return /^[A-Z-a-z0-9_\s]+$/g.test(s);
352
+ };
353
+ export {
354
+ A as PinPax
355
+ };
package/dist/relay.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var u=a=>{throw TypeError(a)};var d=(a,s,e)=>s.has(a)||u("Cannot "+e);var c=(a,s,e)=>(d(a,s,"read from private field"),e?e.call(a):s.get(a)),l=(a,s,e)=>s.has(a)?u("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(a):s.set(a,e);var h=(a,s,e)=>(d(a,s,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./kernel-CtyQRsMI.cjs");var r,o,p;class f extends n.Kernel{constructor({filters:e=null,config_port:t=null,no_device:i=1}={}){super({filters:e,config_port:t,no_device:i});l(this,o);l(this,r,{activate:["A0","01","01","A2"],deactivate:["A0","01","00","A1"]});if(this.__internal__.device.type="relay",this.__internal__.auto_response=!0,n.c.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);h(this,o,p).call(this)}serialMessage(e){const t={code:e,name:null,description:null,request:null,no_code:0};switch(e[1].toString()){case"dd":t.name="Connection with the serial device completed.",t.description="Your connection with the serial device was successfully completed.",t.request="connect",t.no_code=100;break;case"de":break;default:t.name="Unrecognized response",t.description="The response of application was received, but dont identify with any of current parameters",t.request="undefined",t.no_code=400;break}this.dispatch("serial:message",t)}serialRelaySumHex(e){let t=0;return e.forEach((i,y)=>{y!==3&&(t+=parseInt(i,16))}),t.toString(16).toUpperCase()}serialSetConnectionConstant(e=1){const t=["A0","01","00","A1"];return t[1]=this.hexMaker(this.decToHex(e.toString())),t[3]=this.serialRelaySumHex(t),this.add0x(t)}async turnOn(){const e=c(this,r).activate;e[3]=this.serialRelaySumHex(e),await this.appendToQueue(e,"relay:turn-on")}async turnOff(){const e=c(this,r).deactivate;e[3]=this.serialRelaySumHex(e),await this.appendToQueue(e,"relay:turn-off")}async toggle({inverse:e=!1,ms:t=300}={}){const i=this;e?(await i.turnOff(),await n.wait(t),await i.turnOn()):(await i.turnOn(),await n.wait(t),await i.turnOff())}}r=new WeakMap,o=new WeakSet,p=function(){n.c.add(this)};exports.Relay=f;
package/dist/relay.js ADDED
@@ -0,0 +1,69 @@
1
+ var l = (a) => {
2
+ throw TypeError(a);
3
+ };
4
+ var u = (a, s, e) => s.has(a) || l("Cannot " + e);
5
+ var o = (a, s, e) => (u(a, s, "read from private field"), e ? e.call(a) : s.get(a)), c = (a, s, e) => s.has(a) ? l("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(a) : s.set(a, e);
6
+ var d = (a, s, e) => (u(a, s, "access private method"), e);
7
+ import { K as y, c as h, w as p } from "./kernel-B15wfB2x.js";
8
+ var n, r, f;
9
+ class g extends y {
10
+ constructor({ filters: e = null, config_port: t = null, no_device: i = 1 } = {}) {
11
+ super({ filters: e, config_port: t, no_device: i });
12
+ c(this, r);
13
+ c(this, n, {
14
+ activate: ["A0", "01", "01", "A2"],
15
+ deactivate: ["A0", "01", "00", "A1"]
16
+ });
17
+ if (this.__internal__.device.type = "relay", this.__internal__.auto_response = !0, h.getCustom(this.typeDevice, i))
18
+ throw new Error(`Device ${this.typeDevice} ${i} already exists`);
19
+ d(this, r, f).call(this);
20
+ }
21
+ serialMessage(e) {
22
+ const t = {
23
+ code: e,
24
+ name: null,
25
+ description: null,
26
+ request: null,
27
+ no_code: 0
28
+ };
29
+ switch (e[1].toString()) {
30
+ case "dd":
31
+ t.name = "Connection with the serial device completed.", t.description = "Your connection with the serial device was successfully completed.", t.request = "connect", t.no_code = 100;
32
+ break;
33
+ case "de":
34
+ break;
35
+ default:
36
+ t.name = "Unrecognized response", t.description = "The response of application was received, but dont identify with any of current parameters", t.request = "undefined", t.no_code = 400;
37
+ break;
38
+ }
39
+ this.dispatch("serial:message", t);
40
+ }
41
+ serialRelaySumHex(e) {
42
+ let t = 0;
43
+ return e.forEach((i, w) => {
44
+ w !== 3 && (t += parseInt(i, 16));
45
+ }), t.toString(16).toUpperCase();
46
+ }
47
+ serialSetConnectionConstant(e = 1) {
48
+ const t = ["A0", "01", "00", "A1"];
49
+ return t[1] = this.hexMaker(this.decToHex(e.toString())), t[3] = this.serialRelaySumHex(t), this.add0x(t);
50
+ }
51
+ async turnOn() {
52
+ const e = o(this, n).activate;
53
+ e[3] = this.serialRelaySumHex(e), await this.appendToQueue(e, "relay:turn-on");
54
+ }
55
+ async turnOff() {
56
+ const e = o(this, n).deactivate;
57
+ e[3] = this.serialRelaySumHex(e), await this.appendToQueue(e, "relay:turn-off");
58
+ }
59
+ async toggle({ inverse: e = !1, ms: t = 300 } = {}) {
60
+ const i = this;
61
+ e ? (await i.turnOff(), await p(t), await i.turnOn()) : (await i.turnOn(), await p(t), await i.turnOff());
62
+ }
63
+ }
64
+ n = new WeakMap(), r = new WeakSet(), f = function() {
65
+ h.add(this);
66
+ };
67
+ export {
68
+ g as Relay
69
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./kernel-CtyQRsMI.cjs"),r=require("./relay.cjs"),o=require("./locker.cjs"),i=require("./pinpad.cjs"),n=require("./pinpax.cjs"),t=require("./jofemar.cjs"),a=require("./boardroid.cjs"),s=require("./arduino.cjs");/**
2
+ * @license Webserial
3
+ * webserial
4
+ *
5
+ * Created by (c) Danidoble.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */const u={wait:e.wait,getSeconds:e.getSeconds,supportWebSerial:e.supportWebSerial},c="4.1.9";exports.Devices=e.c;exports.Emulator=e.Emulator;exports.Kernel=e.Kernel;exports.Relay=r.Relay;exports.Locker=o.Locker;exports.PinPad=i.PinPad;exports.PinPax=n.PinPax;exports.Jofemar=t.Jofemar;exports.Boardroid=a.Boardroid;exports.Arduino=s.Arduino;exports.utils=u;exports.version=c;