@iotize/device-com-ble.cordova 3.7.2 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/package.json +7 -21
  3. package/plugin.cjs +35 -0
  4. package/plugin.js +35 -0
  5. package/plugin.xml +8 -3
  6. package/src/android/build.gradle +2 -11
  7. package/src/android/libs/iotize-device-com-ble-1.0.0-alpha.9.aar +0 -0
  8. package/{lib → src/lib}/ble-com-protocol.d.ts +20 -20
  9. package/{lib → src/lib}/cordova-ble-error.d.ts +29 -29
  10. package/{lib → src/lib}/cordova-interface.d.ts +5 -5
  11. package/{lib → src/lib}/cordova-service-adapter.d.ts +58 -58
  12. package/{lib → src/lib}/definitions.d.ts +43 -43
  13. package/{lib → src/lib}/iotize-ble-cordova-plugin.d.ts +27 -27
  14. package/src/lib/logger.d.ts +2 -0
  15. package/{lib → src/lib}/scanner.d.ts +55 -55
  16. package/{lib → src/lib}/utility.d.ts +6 -6
  17. package/src/plugin.d.ts +8 -0
  18. package/src/windows/iotize-ble-com.js +11 -11
  19. package/LICENSE +0 -23
  20. package/README.md +0 -174
  21. package/bundles/iotize-device-com-ble.cordova.umd.js +0 -1418
  22. package/bundles/iotize-device-com-ble.cordova.umd.js.map +0 -1
  23. package/bundles/iotize-device-com-ble.cordova.umd.min.js +0 -2
  24. package/bundles/iotize-device-com-ble.cordova.umd.min.js.map +0 -1
  25. package/esm2015/iotize-device-com-ble.cordova.js +0 -6
  26. package/esm2015/iotize-device-com-ble.cordova.js.map +0 -1
  27. package/esm2015/iotize-device-com-ble.cordova.metadata.json +0 -1
  28. package/esm2015/iotize-device-com-ble.cordova.ngsummary.json +0 -1
  29. package/esm2015/lib/ble-com-protocol.js +0 -76
  30. package/esm2015/lib/ble-com-protocol.js.map +0 -1
  31. package/esm2015/lib/ble-com-protocol.metadata.json +0 -1
  32. package/esm2015/lib/ble-com-protocol.ngsummary.json +0 -1
  33. package/esm2015/lib/cordova-ble-error.js +0 -36
  34. package/esm2015/lib/cordova-ble-error.js.map +0 -1
  35. package/esm2015/lib/cordova-ble-error.metadata.json +0 -1
  36. package/esm2015/lib/cordova-ble-error.ngsummary.json +0 -1
  37. package/esm2015/lib/cordova-interface.js +0 -2
  38. package/esm2015/lib/cordova-interface.js.map +0 -1
  39. package/esm2015/lib/cordova-interface.metadata.json +0 -1
  40. package/esm2015/lib/cordova-interface.ngsummary.json +0 -1
  41. package/esm2015/lib/cordova-service-adapter.js +0 -214
  42. package/esm2015/lib/cordova-service-adapter.js.map +0 -1
  43. package/esm2015/lib/cordova-service-adapter.metadata.json +0 -1
  44. package/esm2015/lib/cordova-service-adapter.ngsummary.json +0 -1
  45. package/esm2015/lib/definitions.js +0 -2
  46. package/esm2015/lib/definitions.js.map +0 -1
  47. package/esm2015/lib/definitions.metadata.json +0 -1
  48. package/esm2015/lib/definitions.ngsummary.json +0 -1
  49. package/esm2015/lib/iotize-ble-cordova-plugin.js +0 -170
  50. package/esm2015/lib/iotize-ble-cordova-plugin.js.map +0 -1
  51. package/esm2015/lib/iotize-ble-cordova-plugin.metadata.json +0 -1
  52. package/esm2015/lib/iotize-ble-cordova-plugin.ngsummary.json +0 -1
  53. package/esm2015/lib/logger.js +0 -3
  54. package/esm2015/lib/logger.js.map +0 -1
  55. package/esm2015/lib/logger.metadata.json +0 -1
  56. package/esm2015/lib/logger.ngsummary.json +0 -1
  57. package/esm2015/lib/scanner.js +0 -151
  58. package/esm2015/lib/scanner.js.map +0 -1
  59. package/esm2015/lib/scanner.metadata.json +0 -1
  60. package/esm2015/lib/scanner.ngsummary.json +0 -1
  61. package/esm2015/lib/utility.js +0 -26
  62. package/esm2015/lib/utility.js.map +0 -1
  63. package/esm2015/lib/utility.metadata.json +0 -1
  64. package/esm2015/lib/utility.ngsummary.json +0 -1
  65. package/esm2015/public_api.js +0 -5
  66. package/esm2015/public_api.js.map +0 -1
  67. package/esm2015/public_api.metadata.json +0 -1
  68. package/esm2015/public_api.ngsummary.json +0 -1
  69. package/fesm2015/iotize-device-com-ble.cordova.js +0 -660
  70. package/fesm2015/iotize-device-com-ble.cordova.js.map +0 -1
  71. package/iotize-device-com-ble.cordova.d.ts +0 -6
  72. package/iotize-device-com-ble.cordova.metadata.json +0 -1
  73. package/lib/logger.d.ts +0 -1
  74. package/public_api.d.ts +0 -5
  75. package/src/android/.gradle/4.8.1/fileChanges/last-build.bin +0 -0
  76. package/src/android/.gradle/4.8.1/fileHashes/fileHashes.bin +0 -0
  77. package/src/android/.gradle/4.8.1/fileHashes/fileHashes.lock +0 -0
  78. package/src/android/.gradle/6.8.2/fileChanges/last-build.bin +0 -0
  79. package/src/android/.gradle/6.8.2/fileHashes/fileHashes.lock +0 -0
  80. package/src/android/.gradle/6.8.2/gc.properties +0 -0
  81. package/src/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  82. package/src/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  83. package/src/android/.gradle/checksums/checksums.lock +0 -0
  84. package/src/android/.gradle/configuration-cache/gc.properties +0 -0
  85. package/src/android/.gradle/vcs-1/gc.properties +0 -0
  86. package/src/android/.gradle/vcsWorkingDirs/gc.properties +0 -0
  87. package/src/android/.idea/android.iml +0 -9
  88. package/src/android/.idea/gradle.xml +0 -16
  89. package/src/android/.idea/modules.xml +0 -8
  90. package/src/android/.idea/vcs.xml +0 -6
  91. package/www/plugin.js +0 -2
  92. package/www/plugin.js.LICENSE.txt +0 -14
package/CHANGELOG.md ADDED
@@ -0,0 +1,143 @@
1
+ ## 3.5.2 (2024-01-02)
2
+
3
+ ### Bug Fixes
4
+
5
+ - fix ble connection status after `connect()` method successful. 28642ac
6
+
7
+ ## 3.5.1 (2023-11-21)
8
+
9
+ ### Bug Fixes
10
+
11
+ - android.permission.ACCESS_FINE_LOCATION for maxSdkVersion 32 399971d
12
+
13
+ # 3.5.0 (2023-11-21)
14
+
15
+ ### Features
16
+
17
+ - added support for rxjs@7 98c7a3b
18
+
19
+ ## 3.4.2 (2023-07-17)
20
+
21
+ ### Bug Fixes
22
+
23
+ - fix android `BLECom.close()` method on Android 11 and below 8375e49
24
+
25
+ # 3.4.1 (2023-02-20)
26
+
27
+ ### Bug Fixes
28
+
29
+ - added check permission before attempting BLE tap connect (**Android only**) 66b7418
30
+ - detect ble disconnection error during send requests and remove peripheral from cache to allow reconnection de556ca
31
+
32
+ ### Others
33
+
34
+ - Updated dependency `org.apache.commons:commons-collections4:4.1` to `org.apache.commons:commons-collections4:4.4`
35
+
36
+ # 3.4.0 (2022-11-23)
37
+
38
+ ### Features
39
+
40
+ - Support for android target sdk 31 (Android 11)
41
+
42
+ ## 3.3.2 (2022-09-12)
43
+
44
+ ### Bug Fixes
45
+
46
+ - changed default connection priority to CONNECTION_PRIORITY_BALANCED (to work with TAP WB) 0e38fc6
47
+ - fix des problèmes de build auto sur iOS 15
48
+
49
+ ## 3.3.1 (2022-03-22)
50
+
51
+ ### Bug Fixes
52
+
53
+ - added gradle option allowInsecureProtocol = true 4111e89
54
+
55
+ # 3.3.0 (2022-01-11)
56
+
57
+ ### Features
58
+
59
+ - added additional `CordovaBLEError.Code` error 0e123b5
60
+ - ask user to enable ble on connect if it's currently disabled 7da5d14
61
+
62
+ ## 3.2.1 (2022-01-11)
63
+
64
+ ### Features
65
+
66
+ - added `close()` exposed method def9d79
67
+ - added `requestEnableBle()` method f5453e4
68
+
69
+ ## 3.1.0 (2021-09-30)
70
+
71
+ - Changed plugin identifier from `cordova-plugin-iotize-device-com-ble` to `@iotize/device-com-ble.cordova` (requires cordova >= 10)
72
+
73
+ ### Features
74
+
75
+ - added functions to `IoTizeBleCordovaPlugin`:
76
+ - `requestMTU`
77
+ - `characteristicStartNotification`
78
+ - `characteristicStopNotification`
79
+ - `characteristicReadValue`
80
+ - `characteristicWrite`
81
+ - `characteristicWriteWithoutResponse`
82
+
83
+ ## 3.0.2 (2021-03-02)
84
+
85
+ - fix optional constructor parameter for `BLEScanner`
86
+
87
+ ## 3.0.1 (2021-03-02)
88
+
89
+ ### Bug Fixes
90
+
91
+ - lazy reference to iotizeBLE. iotizeBLE variable will not be referenced until it's required. bf783c7
92
+
93
+ <a name="3.0.0"></a>
94
+
95
+ # [3.0.0](https://bitbucket.org/iotize-solutions/tap-workspace/compare/v3.0.0-alpha.1...v3.0.0) (2021-02-19)
96
+
97
+ <a name="3.0.0-alpha.1"></a>
98
+
99
+ # [3.0.0-alpha.1](https://bitbucket.org/iotize-solutions/tap-workspace/compare/v2.0.0-alpha.5...v3.0.0-alpha.1) (2020-12-11)
100
+
101
+ - Migrated to `@iotize/tap@2.0.0` APIs
102
+
103
+ <a name="2.0.0-alpha.5"></a>
104
+
105
+ # [2.0.0-alpha.5] (2020-08-28)
106
+
107
+ ### Bug Fixes
108
+
109
+ - changed background thread in iOS swift plugin 4d61ef4
110
+ - `checkState` waits for an update only if BLE state is unknown. 5260298
111
+ - Scan no longer needs active location to work fb2b469
112
+ - **scanner:** fix "ble" spelling to "BLE" ce6c3cb
113
+
114
+ ### Features
115
+
116
+ - renamed interface `DiscoveredDeviceType` into `CordovaBLEScanResult` 3ed0259
117
+
118
+ <a name="1.1.0-alpha.30"></a>
119
+
120
+ - Improved BLE device Scanner
121
+
122
+ <a name="1.1.0-alpha.23"></a>
123
+
124
+ - fix: iOS : CheckAvailable now uses actual bluetooth manager state
125
+
126
+ <a name="1.1.0-alpha.21"></a>
127
+
128
+ # [1.1.0-alpha.21](2019-04-04)
129
+
130
+ - fix: Scan no longer needs active location to work
131
+
132
+ <a name="1.1.0-alpha.20"></a>
133
+
134
+ # [1.1.0-alpha.20](2019-03-06)
135
+
136
+ ## Breaking changes :
137
+
138
+ - Added minified files
139
+ - non minified js and typescript declaration files now imported from '@iotize/cordova-device-iotize-ble' (used to be '@iotize/cordova-device-iotize-ble/dist')
140
+
141
+ <a name="1.1.0-alpha.18"></a>
142
+
143
+ # [1.1.0-alpha.18](2019-03-06)
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "author": "IoTize <contact@iotize.com>",
3
3
  "license": "MIT",
4
+ "homepage": "http://developer.iotize.com",
4
5
  "name": "@iotize/device-com-ble.cordova",
5
- "version": "3.7.2",
6
+ "version": "4.0.0-alpha.2",
7
+ "main": "plugin.js",
8
+ "types": "packages/device-com-ble.cordova/src/plugin.d.ts",
6
9
  "cordova": {
7
10
  "id": "@iotize/device-com-ble.cordova",
8
11
  "platforms": [
@@ -12,12 +15,7 @@
12
15
  ]
13
16
  },
14
17
  "description": "Bluetooth Low Energy (BLE) for IoTize modules Plugin",
15
- "peerDependencies": {
16
- "@iotize/common": "^2.0.0",
17
- "@iotize/tap": "^2.8.0",
18
- "debug": "^4.1.0",
19
- "rxjs": "^6.0.0 || ^7.0.0"
20
- },
18
+ "peerDependencies": {},
21
19
  "keywords": [
22
20
  "bluetooth",
23
21
  "BLE",
@@ -34,17 +32,5 @@
34
32
  "cordova-android",
35
33
  "cordova-windows",
36
34
  "cordova-ios"
37
- ],
38
- "homepage": "http://developer.iotize.com",
39
- "main": "bundles/iotize-device-com-ble.cordova.umd.js",
40
- "module": "fesm2015/iotize-device-com-ble.cordova.js",
41
- "es2015": "fesm2015/iotize-device-com-ble.cordova.js",
42
- "esm2015": "esm2015/iotize-device-com-ble.cordova.js",
43
- "fesm2015": "fesm2015/iotize-device-com-ble.cordova.js",
44
- "typings": "iotize-device-com-ble.cordova.d.ts",
45
- "metadata": "iotize-device-com-ble.cordova.metadata.json",
46
- "sideEffects": false,
47
- "dependencies": {
48
- "tslib": "^2.2.0"
49
- }
50
- }
35
+ ]
36
+ }
package/plugin.cjs ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";var ci=Object.create;var yr=Object.defineProperty;var ui=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var li=Object.getPrototypeOf,fi=Object.prototype.hasOwnProperty;var Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),mi=(t,e)=>{for(var r in e)yr(t,r,{get:e[r],enumerable:!0})},Yt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pi(e))!fi.call(t,i)&&i!==r&&yr(t,i,{get:()=>e[i],enumerable:!(n=ui(e,i))||n.enumerable});return t};var xr=(t,e,r)=>(r=t!=null?ci(li(t)):{},Yt(e||!t||!t.__esModule?yr(r,"default",{value:t,enumerable:!0}):r,t)),di=t=>Yt(yr({},"__esModule",{value:!0}),t);var In=Me((Tp,Rn)=>{"use strict";var Ge=1e3,He=Ge*60,Ke=He*60,Se=Ke*24,Li=Se*7,ki=Se*365.25;Rn.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return Di(t);if(r==="number"&&isFinite(t))return e.long?qi(t):Ni(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Di(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*ki;case"weeks":case"week":case"w":return r*Li;case"days":case"day":case"d":return r*Se;case"hours":case"hour":case"hrs":case"hr":case"h":return r*Ke;case"minutes":case"minute":case"mins":case"min":case"m":return r*He;case"seconds":case"second":case"secs":case"sec":case"s":return r*Ge;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function Ni(t){var e=Math.abs(t);return e>=Se?Math.round(t/Se)+"d":e>=Ke?Math.round(t/Ke)+"h":e>=He?Math.round(t/He)+"m":e>=Ge?Math.round(t/Ge)+"s":t+"ms"}function qi(t){var e=Math.abs(t);return e>=Se?$r(t,e,Se,"day"):e>=Ke?$r(t,e,Ke,"hour"):e>=He?$r(t,e,He,"minute"):e>=Ge?$r(t,e,Ge,"second"):t+" ms"}function $r(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});var Bn=Me((Cp,_n)=>{"use strict";function Mi(t){r.debug=r,r.default=r,r.coerce=u,r.disable=a,r.enable=i,r.enabled=s,r.humanize=In(),r.destroy=l,Object.keys(t).forEach(p=>{r[p]=t[p]}),r.names=[],r.skips=[],r.formatters={};function e(p){let d=0;for(let h=0;h<p.length;h++)d=(d<<5)-d+p.charCodeAt(h),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=e;function r(p){let d,h=null,c,f;function b(...y){if(!b.enabled)return;let x=b,R=Number(new Date),C=R-(d||R);x.diff=C,x.prev=d,x.curr=R,d=R,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let Q=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(X,ut)=>{if(X==="%%")return"%";Q++;let Kt=r.formatters[ut];if(typeof Kt=="function"){let si=y[Q];X=Kt.call(x,si),y.splice(Q,1),Q--}return X}),r.formatArgs.call(x,y),(x.log||r.log).apply(x,y)}return b.namespace=p,b.useColors=r.useColors(),b.color=r.selectColor(p),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>h!==null?h:(c!==r.namespaces&&(c=r.namespaces,f=r.enabled(p)),f),set:y=>{h=y}}),typeof r.init=="function"&&r.init(b),b}function n(p,d){let h=r(this.namespace+(typeof d=="undefined"?":":d)+p);return h.log=this.log,h}function i(p){r.save(p),r.namespaces=p,r.names=[],r.skips=[];let d=(typeof p=="string"?p:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let h of d)h[0]==="-"?r.skips.push(h.slice(1)):r.names.push(h)}function o(p,d){let h=0,c=0,f=-1,b=0;for(;h<p.length;)if(c<d.length&&(d[c]===p[h]||d[c]==="*"))d[c]==="*"?(f=c,b=h,c++):(h++,c++);else if(f!==-1)c=f+1,b++,h=b;else return!1;for(;c<d.length&&d[c]==="*";)c++;return c===d.length}function a(){let p=[...r.names,...r.skips.map(d=>"-"+d)].join(",");return r.enable(""),p}function s(p){for(let d of r.skips)if(o(p,d))return!1;for(let d of r.names)if(o(p,d))return!0;return!1}function u(p){return p instanceof Error?p.stack||p.message:p}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}_n.exports=Mi});var Pn=Me((N,Wr)=>{"use strict";N.formatArgs=$i;N.save=Wi;N.load=ji;N.useColors=zi;N.storage=Vi();N.destroy=(()=>{let t=!1;return()=>{t||(t=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();N.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function zi(){if(typeof window!="undefined"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let t;return typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&(t=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(t[1],10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function $i(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Wr.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}N.log=console.debug||console.log||(()=>{});function Wi(t){try{t?N.storage.setItem("debug",t):N.storage.removeItem("debug")}catch(e){}}function ji(){let t;try{t=N.storage.getItem("debug")||N.storage.getItem("DEBUG")}catch(e){}return!t&&typeof process!="undefined"&&"env"in process&&(t=process.env.DEBUG),t}function Vi(){try{return localStorage}catch(t){}}Wr.exports=Bn()(N);var{formatters:Gi}=Wr.exports;Gi.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var qn=Me(Qr=>{"use strict";Qr.byteLength=Ji;Qr.toByteArray=eo;Qr.fromByteArray=no;var oe=[],K=[],Xi=typeof Uint8Array!="undefined"?Uint8Array:Array,Tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(_e=0,Dn=Tt.length;_e<Dn;++_e)oe[_e]=Tt[_e],K[Tt.charCodeAt(_e)]=_e;var _e,Dn;K[45]=62;K[95]=63;function Nn(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function Ji(t){var e=Nn(t),r=e[0],n=e[1];return(r+n)*3/4-n}function Zi(t,e,r){return(e+r)*3/4-r}function eo(t){var e,r=Nn(t),n=r[0],i=r[1],o=new Xi(Zi(t,n,i)),a=0,s=i>0?n-4:n,u;for(u=0;u<s;u+=4)e=K[t.charCodeAt(u)]<<18|K[t.charCodeAt(u+1)]<<12|K[t.charCodeAt(u+2)]<<6|K[t.charCodeAt(u+3)],o[a++]=e>>16&255,o[a++]=e>>8&255,o[a++]=e&255;return i===2&&(e=K[t.charCodeAt(u)]<<2|K[t.charCodeAt(u+1)]>>4,o[a++]=e&255),i===1&&(e=K[t.charCodeAt(u)]<<10|K[t.charCodeAt(u+1)]<<4|K[t.charCodeAt(u+2)]>>2,o[a++]=e>>8&255,o[a++]=e&255),o}function ro(t){return oe[t>>18&63]+oe[t>>12&63]+oe[t>>6&63]+oe[t&63]}function to(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(ro(n));return i.join("")}function no(t){for(var e,r=t.length,n=r%3,i=[],o=16383,a=0,s=r-n;a<s;a+=o)i.push(to(t,a,a+o>s?s:a+o));return n===1?(e=t[r-1],i.push(oe[e>>2]+oe[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],i.push(oe[e>>10]+oe[e>>4&63]+oe[e<<2&63]+"=")),i.join("")}});var Mn=Me(Ct=>{"use strict";Ct.read=function(t,e,r,n,i){var o,a,s=i*8-n-1,u=(1<<s)-1,l=u>>1,p=-7,d=r?i-1:0,h=r?-1:1,c=t[e+d];for(d+=h,o=c&(1<<-p)-1,c>>=-p,p+=s;p>0;o=o*256+t[e+d],d+=h,p-=8);for(a=o&(1<<-p)-1,o>>=-p,p+=n;p>0;a=a*256+t[e+d],d+=h,p-=8);if(o===0)o=1-l;else{if(o===u)return a?NaN:(c?-1:1)*(1/0);a=a+Math.pow(2,n),o=o-l}return(c?-1:1)*a*Math.pow(2,o-n)};Ct.write=function(t,e,r,n,i,o){var a,s,u,l=o*8-i-1,p=(1<<l)-1,d=p>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,c=n?0:o-1,f=n?1:-1,b=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=p):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),a+d>=1?e+=h/u:e+=h*Math.pow(2,1-d),e*u>=2&&(a++,u/=2),a+d>=p?(s=0,a=p):a+d>=1?(s=(e*u-1)*Math.pow(2,i),a=a+d):(s=e*Math.pow(2,d-1)*Math.pow(2,i),a=0));i>=8;t[r+c]=s&255,c+=f,s/=256,i-=8);for(a=a<<i|s,l+=i;l>0;t[r+c]=a&255,c+=f,a/=256,l-=8);t[r+c-f]|=b*128}});var Zr=Me(Xe=>{"use strict";var At=qn(),Qe=Mn(),zn=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Xe.Buffer=m;Xe.SlowBuffer=uo;Xe.INSPECT_MAX_BYTES=50;var Xr=2147483647;Xe.kMaxLength=Xr;m.TYPED_ARRAY_SUPPORT=io();!m.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function io(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch(r){return!1}}Object.defineProperty(m.prototype,"parent",{enumerable:!0,get:function(){if(m.isBuffer(this))return this.buffer}});Object.defineProperty(m.prototype,"offset",{enumerable:!0,get:function(){if(m.isBuffer(this))return this.byteOffset}});function le(t){if(t>Xr)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,m.prototype),e}function m(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Rt(t)}return jn(t,e,r)}m.poolSize=8192;function jn(t,e,r){if(typeof t=="string")return ao(t,e);if(ArrayBuffer.isView(t))return so(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(ae(t,ArrayBuffer)||t&&ae(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(ae(t,SharedArrayBuffer)||t&&ae(t.buffer,SharedArrayBuffer)))return Ot(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return m.from(n,e,r);var i=co(t);if(i)return i;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return m.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}m.from=function(t,e,r){return jn(t,e,r)};Object.setPrototypeOf(m.prototype,Uint8Array.prototype);Object.setPrototypeOf(m,Uint8Array);function Vn(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function oo(t,e,r){return Vn(t),t<=0?le(t):e!==void 0?typeof r=="string"?le(t).fill(e,r):le(t).fill(e):le(t)}m.alloc=function(t,e,r){return oo(t,e,r)};function Rt(t){return Vn(t),le(t<0?0:It(t)|0)}m.allocUnsafe=function(t){return Rt(t)};m.allocUnsafeSlow=function(t){return Rt(t)};function ao(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!m.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=Gn(t,e)|0,n=le(r),i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function St(t){for(var e=t.length<0?0:It(t.length)|0,r=le(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function so(t){if(ae(t,Uint8Array)){var e=new Uint8Array(t);return Ot(e.buffer,e.byteOffset,e.byteLength)}return St(t)}function Ot(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,m.prototype),n}function co(t){if(m.isBuffer(t)){var e=It(t.length)|0,r=le(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||_t(t.length)?le(0):St(t);if(t.type==="Buffer"&&Array.isArray(t.data))return St(t.data)}function It(t){if(t>=Xr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Xr.toString(16)+" bytes");return t|0}function uo(t){return+t!=t&&(t=0),m.alloc(+t)}m.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==m.prototype};m.compare=function(e,r){if(ae(e,Uint8Array)&&(e=m.from(e,e.offset,e.byteLength)),ae(r,Uint8Array)&&(r=m.from(r,r.offset,r.byteLength)),!m.isBuffer(e)||!m.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,i=r.length,o=0,a=Math.min(n,i);o<a;++o)if(e[o]!==r[o]){n=e[o],i=r[o];break}return n<i?-1:i<n?1:0};m.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};m.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return m.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var i=m.allocUnsafe(r),o=0;for(n=0;n<e.length;++n){var a=e[n];if(ae(a,Uint8Array))o+a.length>i.length?m.from(a).copy(i,o):Uint8Array.prototype.set.call(i,a,o);else if(m.isBuffer(a))a.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=a.length}return i};function Gn(t,e){if(m.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||ae(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Ut(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Jn(t).length;default:if(i)return n?-1:Ut(t).length;e=(""+e).toLowerCase(),i=!0}}m.byteLength=Gn;function po(t,e,r){var n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return wo(this,e,r);case"utf8":case"utf-8":return Kn(this,e,r);case"ascii":return vo(this,e,r);case"latin1":case"binary":return go(this,e,r);case"base64":return yo(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Eo(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}m.prototype._isBuffer=!0;function Be(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}m.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<e;r+=2)Be(this,r,r+1);return this};m.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<e;r+=4)Be(this,r,r+3),Be(this,r+1,r+2);return this};m.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<e;r+=8)Be(this,r,r+7),Be(this,r+1,r+6),Be(this,r+2,r+5),Be(this,r+3,r+4);return this};m.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?Kn(this,0,e):po.apply(this,arguments)};m.prototype.toLocaleString=m.prototype.toString;m.prototype.equals=function(e){if(!m.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:m.compare(this,e)===0};m.prototype.inspect=function(){var e="",r=Xe.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};zn&&(m.prototype[zn]=m.prototype.inspect);m.prototype.compare=function(e,r,n,i,o){if(ae(e,Uint8Array)&&(e=m.from(e,e.offset,e.byteLength)),!m.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),r<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&r>=n)return 0;if(i>=o)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;for(var a=o-i,s=n-r,u=Math.min(a,s),l=this.slice(i,o),p=e.slice(r,n),d=0;d<u;++d)if(l[d]!==p[d]){a=l[d],s=p[d];break}return a<s?-1:s<a?1:0};function Hn(t,e,r,n,i){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,_t(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof e=="string"&&(e=m.from(e,n)),m.isBuffer(e))return e.length===0?-1:$n(t,e,r,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):$n(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function $n(t,e,r,n,i){var o=1,a=t.length,s=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,a/=2,s/=2,r/=2}function u(c,f){return o===1?c[f]:c.readUInt16BE(f*o)}var l;if(i){var p=-1;for(l=r;l<a;l++)if(u(t,l)===u(e,p===-1?0:l-p)){if(p===-1&&(p=l),l-p+1===s)return p*o}else p!==-1&&(l-=l-p),p=-1}else for(r+s>a&&(r=a-s),l=r;l>=0;l--){for(var d=!0,h=0;h<s;h++)if(u(t,l+h)!==u(e,h)){d=!1;break}if(d)return l}return-1}m.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};m.prototype.indexOf=function(e,r,n){return Hn(this,e,r,n,!0)};m.prototype.lastIndexOf=function(e,r,n){return Hn(this,e,r,n,!1)};function lo(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=e.length;n>o/2&&(n=o/2);for(var a=0;a<n;++a){var s=parseInt(e.substr(a*2,2),16);if(_t(s))return a;t[r+a]=s}return a}function fo(t,e,r,n){return Jr(Ut(e,t.length-r),t,r,n)}function mo(t,e,r,n){return Jr(Ao(e),t,r,n)}function ho(t,e,r,n){return Jr(Jn(e),t,r,n)}function bo(t,e,r,n){return Jr(So(e,t.length-r),t,r,n)}m.prototype.write=function(e,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var o=this.length-r;if((n===void 0||n>o)&&(n=o),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var a=!1;;)switch(i){case"hex":return lo(this,e,r,n);case"utf8":case"utf-8":return fo(this,e,r,n);case"ascii":case"latin1":case"binary":return mo(this,e,r,n);case"base64":return ho(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return bo(this,e,r,n);default:if(a)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),a=!0}};m.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function yo(t,e,r){return e===0&&r===t.length?At.fromByteArray(t):At.fromByteArray(t.slice(e,r))}function Kn(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o=t[i],a=null,s=o>239?4:o>223?3:o>191?2:1;if(i+s<=r){var u,l,p,d;switch(s){case 1:o<128&&(a=o);break;case 2:u=t[i+1],(u&192)===128&&(d=(o&31)<<6|u&63,d>127&&(a=d));break;case 3:u=t[i+1],l=t[i+2],(u&192)===128&&(l&192)===128&&(d=(o&15)<<12|(u&63)<<6|l&63,d>2047&&(d<55296||d>57343)&&(a=d));break;case 4:u=t[i+1],l=t[i+2],p=t[i+3],(u&192)===128&&(l&192)===128&&(p&192)===128&&(d=(o&15)<<18|(u&63)<<12|(l&63)<<6|p&63,d>65535&&d<1114112&&(a=d))}}a===null?(a=65533,s=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|a&1023),n.push(a),i+=s}return xo(n)}var Wn=4096;function xo(t){var e=t.length;if(e<=Wn)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Wn));return r}function vo(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]&127);return n}function go(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function wo(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=Oo[t[o]];return i}function Eo(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}m.prototype.slice=function(e,r){var n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);var i=this.subarray(e,r);return Object.setPrototypeOf(i,m.prototype),i};function P(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}m.prototype.readUintLE=m.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||P(e,r,this.length);for(var i=this[e],o=1,a=0;++a<r&&(o*=256);)i+=this[e+a]*o;return i};m.prototype.readUintBE=m.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||P(e,r,this.length);for(var i=this[e+--r],o=1;r>0&&(o*=256);)i+=this[e+--r]*o;return i};m.prototype.readUint8=m.prototype.readUInt8=function(e,r){return e=e>>>0,r||P(e,1,this.length),this[e]};m.prototype.readUint16LE=m.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||P(e,2,this.length),this[e]|this[e+1]<<8};m.prototype.readUint16BE=m.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||P(e,2,this.length),this[e]<<8|this[e+1]};m.prototype.readUint32LE=m.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||P(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};m.prototype.readUint32BE=m.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||P(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};m.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||P(e,r,this.length);for(var i=this[e],o=1,a=0;++a<r&&(o*=256);)i+=this[e+a]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*r)),i};m.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||P(e,r,this.length);for(var i=r,o=1,a=this[e+--i];i>0&&(o*=256);)a+=this[e+--i]*o;return o*=128,a>=o&&(a-=Math.pow(2,8*r)),a};m.prototype.readInt8=function(e,r){return e=e>>>0,r||P(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};m.prototype.readInt16LE=function(e,r){e=e>>>0,r||P(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};m.prototype.readInt16BE=function(e,r){e=e>>>0,r||P(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};m.prototype.readInt32LE=function(e,r){return e=e>>>0,r||P(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};m.prototype.readInt32BE=function(e,r){return e=e>>>0,r||P(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};m.prototype.readFloatLE=function(e,r){return e=e>>>0,r||P(e,4,this.length),Qe.read(this,e,!0,23,4)};m.prototype.readFloatBE=function(e,r){return e=e>>>0,r||P(e,4,this.length),Qe.read(this,e,!1,23,4)};m.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||P(e,8,this.length),Qe.read(this,e,!0,52,8)};m.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||P(e,8,this.length),Qe.read(this,e,!1,52,8)};function q(t,e,r,n,i,o){if(!m.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}m.prototype.writeUintLE=m.prototype.writeUIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;q(this,e,r,n,o,0)}var a=1,s=0;for(this[r]=e&255;++s<n&&(a*=256);)this[r+s]=e/a&255;return r+n};m.prototype.writeUintBE=m.prototype.writeUIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;q(this,e,r,n,o,0)}var a=n-1,s=1;for(this[r+a]=e&255;--a>=0&&(s*=256);)this[r+a]=e/s&255;return r+n};m.prototype.writeUint8=m.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,1,255,0),this[r]=e&255,r+1};m.prototype.writeUint16LE=m.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};m.prototype.writeUint16BE=m.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};m.prototype.writeUint32LE=m.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};m.prototype.writeUint32BE=m.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};m.prototype.writeIntLE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);q(this,e,r,n,o-1,-o)}var a=0,s=1,u=0;for(this[r]=e&255;++a<n&&(s*=256);)e<0&&u===0&&this[r+a-1]!==0&&(u=1),this[r+a]=(e/s>>0)-u&255;return r+n};m.prototype.writeIntBE=function(e,r,n,i){if(e=+e,r=r>>>0,!i){var o=Math.pow(2,8*n-1);q(this,e,r,n,o-1,-o)}var a=n-1,s=1,u=0;for(this[r+a]=e&255;--a>=0&&(s*=256);)e<0&&u===0&&this[r+a+1]!==0&&(u=1),this[r+a]=(e/s>>0)-u&255;return r+n};m.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};m.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};m.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};m.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};m.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||q(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function Yn(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Qn(t,e,r,n,i){return e=+e,r=r>>>0,i||Yn(t,e,r,4,34028234663852886e22,-34028234663852886e22),Qe.write(t,e,r,n,23,4),r+4}m.prototype.writeFloatLE=function(e,r,n){return Qn(this,e,r,!0,n)};m.prototype.writeFloatBE=function(e,r,n){return Qn(this,e,r,!1,n)};function Xn(t,e,r,n,i){return e=+e,r=r>>>0,i||Yn(t,e,r,8,17976931348623157e292,-17976931348623157e292),Qe.write(t,e,r,n,52,8),r+8}m.prototype.writeDoubleLE=function(e,r,n){return Xn(this,e,r,!0,n)};m.prototype.writeDoubleBE=function(e,r,n){return Xn(this,e,r,!1,n)};m.prototype.copy=function(e,r,n,i){if(!m.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),r>=e.length&&(r=e.length),r||(r=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-r<i-n&&(i=e.length-r+n);var o=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),r),o};m.prototype.fill=function(e,r,n,i){if(typeof e=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!m.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){var o=e.charCodeAt(0);(i==="utf8"&&o<128||i==="latin1")&&(e=o)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var a;if(typeof e=="number")for(a=r;a<n;++a)this[a]=e;else{var s=m.isBuffer(e)?e:m.from(e,i),u=s.length;if(u===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-r;++a)this[a+r]=s[a%u]}return this};var To=/[^+/0-9A-Za-z-_]/g;function Co(t){if(t=t.split("=")[0],t=t.trim().replace(To,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Ut(t,e){e=e||1/0;for(var r,n=t.length,i=null,o=[],a=0;a<n;++a){if(r=t.charCodeAt(a),r>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(a+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function Ao(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function So(t,e){for(var r,n,i,o=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,i=r%256,o.push(i),o.push(n);return o}function Jn(t){return At.toByteArray(Co(t))}function Jr(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function ae(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function _t(t){return t!==t}var Oo=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=r*16,i=0;i<16;++i)e[n+i]=t[r]+t[i];return e}()});var qo={};mi(qo,{BLEComProtocol:()=>Yr,BLEScanner:()=>ct,CordovaCharacteristicAdapter:()=>nr,CordovaPeripheralAdapter:()=>st,CordovaServiceAdapter:()=>qe,IoTizeBleCordovaPlugin:()=>br,getIoTizeBleCordovaPlugin:()=>be,getScanRecordsFromBytes:()=>Ln,iotizeBLE:()=>ai});module.exports=di(qo);var D=(i=>(i[i.DISCONNECTED=0]="DISCONNECTED",i[i.CONNECTING=1]="CONNECTING",i[i.CONNECTED=2]="CONNECTED",i[i.DISCONNECTING=3]="DISCONNECTING",i))(D||{});var G;(r=>{class t extends Error{constructor(o,a){super(a);this.code=o}static operationCanceled(){return new t("OperationCancelled","Communication protocol operation cancelled")}static notConnected(o){return new t("ProtocolNotConnected","Communication protocol is not connected")}static timeoutError(o){return new t("TimeoutError",o.msg||"Communication protocol timeout")}static operationInProgress(o){return new t("ComProtocolOperationInProgress",o)}static unknownError(){return new t("UnknownError","Unnown communication protocol error")}}r.Errors=t;let e;(u=>(u.ProtocolNotConnected="ProtocolNotConnected",u.TimeoutError="TimeoutError",u.UnknownError="UnknownError",u.OperationCancelled="OperationCancelled",u.OperationInProgress="ComProtocolOperationInProgress"))(e=r.ErrorCode||(r.ErrorCode={}))})(G||(G={}));var pt=function(t,e){return pt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(r[i]=n[i])},pt(t,e)};function _(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");pt(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}function Qt(t,e,r,n){function i(o){return o instanceof r?o:new r(function(a){a(o)})}return new(r||(r=Promise))(function(o,a){function s(p){try{l(n.next(p))}catch(d){a(d)}}function u(p){try{l(n.throw(p))}catch(d){a(d)}}function l(p){p.done?o(p.value):i(p.value).then(s,u)}l((n=n.apply(t,e||[])).next())})}function vr(t,e){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function s(l){return function(p){return u([l,p])}}function u(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(r=0)),r;)try{if(n=1,i&&(o=l[0]&2?i.return:l[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,l[1])).done)return o;switch(i=0,o&&(l=[l[0]&2,o.value]),l[0]){case 0:case 1:o=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,i=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(o=r.trys,!(o=o.length>0&&o[o.length-1])&&(l[0]===6||l[0]===2)){r=0;continue}if(l[0]===3&&(!o||l[1]>o[0]&&l[1]<o[3])){r.label=l[1];break}if(l[0]===6&&r.label<o[1]){r.label=o[1],o=l;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(l);break}o[2]&&r.ops.pop(),r.trys.pop();continue}l=e.call(t,r)}catch(p){l=[6,p],i=0}finally{n=o=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function pe(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function J(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,o=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(s){a={error:s}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return o}function Z(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,o;n<i;n++)(o||!(n in e))&&(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return t.concat(o||Array.prototype.slice.call(e))}function ve(t){return this instanceof ve?(this.v=t,this):new ve(t)}function Xt(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",a),i[Symbol.asyncIterator]=function(){return this},i;function a(c){return function(f){return Promise.resolve(f).then(c,d)}}function s(c,f){n[c]&&(i[c]=function(b){return new Promise(function(y,x){o.push([c,b,y,x])>1||u(c,b)})},f&&(i[c]=f(i[c])))}function u(c,f){try{l(n[c](f))}catch(b){h(o[0][3],b)}}function l(c){c.value instanceof ve?Promise.resolve(c.value.v).then(p,d):h(o[0][2],c)}function p(c){u("next",c)}function d(c){u("throw",c)}function h(c,f){c(f),o.shift(),o.length&&u(o[0][0],o[0][1])}}function Jt(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof pe=="function"?pe(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(a){return new Promise(function(s,u){a=t[o](a),i(s,u,a.done,a.value)})}}function i(o,a,s,u){Promise.resolve(u).then(function(l){o({value:l,done:s})},a)}}function g(t){return typeof t=="function"}function fe(t){var e=function(n){Error.call(n),n.stack=new Error().stack},r=t(e);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var gr=fe(function(t){return function(r){t(this),this.message=r?r.length+` errors occurred during unsubscription:
2
+ `+r.map(function(n,i){return i+1+") "+n.toString()}).join(`
3
+ `):"",this.name="UnsubscriptionError",this.errors=r}});function ge(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}var me=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,r,n,i,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var s=pe(a),u=s.next();!u.done;u=s.next()){var l=u.value;l.remove(this)}}catch(b){e={error:b}}finally{try{u&&!u.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}else a.remove(this);var p=this.initialTeardown;if(g(p))try{p()}catch(b){o=b instanceof gr?b.errors:[b]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var h=pe(d),c=h.next();!c.done;c=h.next()){var f=c.value;try{Zt(f)}catch(b){o=o!=null?o:[],b instanceof gr?o=Z(Z([],J(o)),J(b.errors)):o.push(b)}}}catch(b){n={error:b}}finally{try{c&&!c.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}if(o)throw new gr(o)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)Zt(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(e)}},t.prototype._hasParent=function(e){var r=this._parentage;return r===e||Array.isArray(r)&&r.includes(e)},t.prototype._addParent=function(e){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(e),r):r?[r,e]:e},t.prototype._removeParent=function(e){var r=this._parentage;r===e?this._parentage=null:Array.isArray(r)&&ge(r,e)},t.prototype.remove=function(e){var r=this._finalizers;r&&ge(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var lt=me.EMPTY;function wr(t){return t instanceof me||t&&"closed"in t&&g(t.remove)&&g(t.add)&&g(t.unsubscribe)}function Zt(t){g(t)?t():t.unsubscribe()}var ee={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var ze={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ze.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,Z([t,e],J(r))):setTimeout.apply(void 0,Z([t,e],J(r)))},clearTimeout:function(t){var e=ze.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function Er(t){ze.setTimeout(function(){var e=ee.onUnhandledError;if(e)e(t);else throw t})}function ft(){}var en=function(){return mt("C",void 0,void 0)}();function rn(t){return mt("E",void 0,t)}function tn(t){return mt("N",t,void 0)}function mt(t,e,r){return{kind:t,value:e,error:r}}var we=null;function $e(t){if(ee.useDeprecatedSynchronousErrorHandling){var e=!we;if(e&&(we={errorThrown:!1,error:null}),t(),e){var r=we,n=r.errorThrown,i=r.error;if(we=null,n)throw i}}else t()}function nn(t){ee.useDeprecatedSynchronousErrorHandling&&we&&(we.errorThrown=!0,we.error=t)}var ir=function(t){_(e,t);function e(r){var n=t.call(this)||this;return n.isStopped=!1,r?(n.destination=r,wr(r)&&r.add(n)):n.destination=xi,n}return e.create=function(r,n,i){return new Ee(r,n,i)},e.prototype.next=function(r){this.isStopped?ht(tn(r),this):this._next(r)},e.prototype.error=function(r){this.isStopped?ht(rn(r),this):(this.isStopped=!0,this._error(r))},e.prototype.complete=function(){this.isStopped?ht(en,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(r){this.destination.next(r)},e.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(me);var hi=Function.prototype.bind;function dt(t,e){return hi.call(t,e)}var bi=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var r=this.partialObserver;if(r.next)try{r.next(e)}catch(n){Tr(n)}},t.prototype.error=function(e){var r=this.partialObserver;if(r.error)try{r.error(e)}catch(n){Tr(n)}else Tr(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(r){Tr(r)}},t}(),Ee=function(t){_(e,t);function e(r,n,i){var o=t.call(this)||this,a;if(g(r)||!r)a={next:r!=null?r:void 0,error:n!=null?n:void 0,complete:i!=null?i:void 0};else{var s;o&&ee.useDeprecatedNextContext?(s=Object.create(r),s.unsubscribe=function(){return o.unsubscribe()},a={next:r.next&&dt(r.next,s),error:r.error&&dt(r.error,s),complete:r.complete&&dt(r.complete,s)}):a=r}return o.destination=new bi(a),o}return e}(ir);function Tr(t){ee.useDeprecatedSynchronousErrorHandling?nn(t):Er(t)}function yi(t){throw t}function ht(t,e){var r=ee.onStoppedNotification;r&&ze.setTimeout(function(){return r(t,e)})}var xi={closed:!0,next:ft,error:yi,complete:ft};var We=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function de(t){return t}function on(t){return t.length===0?de:t.length===1?t[0]:function(r){return t.reduce(function(n,i){return i(n)},r)}}var A=function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(e,r,n){var i=this,o=gi(e)?e:new Ee(e,r,n);return $e(function(){var a=i,s=a.operator,u=a.source;o.add(s?s.call(o,u):u?i._subscribe(o):i._trySubscribe(o))}),o},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(r){e.error(r)}},t.prototype.forEach=function(e,r){var n=this;return r=an(r),new r(function(i,o){var a=new Ee({next:function(s){try{e(s)}catch(u){o(u),a.unsubscribe()}},error:o,complete:i});n.subscribe(a)})},t.prototype._subscribe=function(e){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(e)},t.prototype[We]=function(){return this},t.prototype.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return on(e)(this)},t.prototype.toPromise=function(e){var r=this;return e=an(e),new e(function(n,i){var o;r.subscribe(function(a){return o=a},function(a){return i(a)},function(){return n(o)})})},t.create=function(e){return new t(e)},t}();function an(t){var e;return(e=t!=null?t:ee.Promise)!==null&&e!==void 0?e:Promise}function vi(t){return t&&g(t.next)&&g(t.error)&&g(t.complete)}function gi(t){return t&&t instanceof ir||vi(t)&&wr(t)}function wi(t){return g(t==null?void 0:t.lift)}function E(t){return function(e){if(wi(e))return e.lift(function(r){try{return t(r,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function S(t,e,r,n,i){return new Ei(t,e,r,n,i)}var Ei=function(t){_(e,t);function e(r,n,i,o,a,s){var u=t.call(this,r)||this;return u.onFinalize=a,u.shouldUnsubscribe=s,u._next=n?function(l){try{n(l)}catch(p){r.error(p)}}:t.prototype._next,u._error=o?function(l){try{o(l)}catch(p){r.error(p)}finally{this.unsubscribe()}}:t.prototype._error,u._complete=i?function(){try{i()}catch(l){r.error(l)}finally{this.unsubscribe()}}:t.prototype._complete,u}return e.prototype.unsubscribe=function(){var r;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;t.prototype.unsubscribe.call(this),!n&&((r=this.onFinalize)===null||r===void 0||r.call(this))}},e}(ir);var sn=fe(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var B=function(t){_(e,t);function e(){var r=t.call(this)||this;return r.closed=!1,r.currentObservers=null,r.observers=[],r.isStopped=!1,r.hasError=!1,r.thrownError=null,r}return e.prototype.lift=function(r){var n=new cn(this,this);return n.operator=r,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new sn},e.prototype.next=function(r){var n=this;$e(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var a=pe(n.currentObservers),s=a.next();!s.done;s=a.next()){var u=s.value;u.next(r)}}catch(l){i={error:l}}finally{try{s&&!s.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}}})},e.prototype.error=function(r){var n=this;$e(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=r;for(var i=n.observers;i.length;)i.shift().error(r)}})},e.prototype.complete=function(){var r=this;$e(function(){if(r._throwIfClosed(),!r.isStopped){r.isStopped=!0;for(var n=r.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var r;return((r=this.observers)===null||r===void 0?void 0:r.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(r){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,r)},e.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},e.prototype._innerSubscribe=function(r){var n=this,i=this,o=i.hasError,a=i.isStopped,s=i.observers;return o||a?lt:(this.currentObservers=null,s.push(r),new me(function(){n.currentObservers=null,ge(s,r)}))},e.prototype._checkFinalizedStatuses=function(r){var n=this,i=n.hasError,o=n.thrownError,a=n.isStopped;i?r.error(o):a&&r.complete()},e.prototype.asObservable=function(){var r=new A;return r.source=this,r},e.create=function(r,n){return new cn(r,n)},e}(A);var cn=function(t){_(e,t);function e(r,n){var i=t.call(this)||this;return i.destination=r,i.source=n,i}return e.prototype.next=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,r)},e.prototype.error=function(r){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,r)},e.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},e.prototype._subscribe=function(r){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&i!==void 0?i:lt},e}(B);var je=function(t){_(e,t);function e(r){var n=t.call(this)||this;return n._value=r,n}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(r){var n=t.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},e.prototype.getValue=function(){var r=this,n=r.hasError,i=r.thrownError,o=r._value;if(n)throw i;return this._throwIfClosed(),o},e.prototype.next=function(r){t.prototype.next.call(this,this._value=r)},e}(B);var or={now:function(){return(or.delegate||Date).now()},delegate:void 0};var un=function(t){_(e,t);function e(r,n,i){r===void 0&&(r=1/0),n===void 0&&(n=1/0),i===void 0&&(i=or);var o=t.call(this)||this;return o._bufferSize=r,o._windowTime=n,o._timestampProvider=i,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=n===1/0,o._bufferSize=Math.max(1,r),o._windowTime=Math.max(1,n),o}return e.prototype.next=function(r){var n=this,i=n.isStopped,o=n._buffer,a=n._infiniteTimeWindow,s=n._timestampProvider,u=n._windowTime;i||(o.push(r),!a&&o.push(s.now()+u)),this._trimBuffer(),t.prototype.next.call(this,r)},e.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(r),i=this,o=i._infiniteTimeWindow,a=i._buffer,s=a.slice(),u=0;u<s.length&&!r.closed;u+=o?1:2)r.next(s[u]);return this._checkFinalizedStatuses(r),n},e.prototype._trimBuffer=function(){var r=this,n=r._bufferSize,i=r._timestampProvider,o=r._buffer,a=r._infiniteTimeWindow,s=(a?1:2)*n;if(n<1/0&&s<o.length&&o.splice(0,o.length-s),!a){for(var u=i.now(),l=0,p=1;p<o.length&&o[p]<=u;p+=2)l=p;l&&o.splice(0,l+1)}},e}(B);var pn=function(t){_(e,t);function e(r,n){return t.call(this)||this}return e.prototype.schedule=function(r,n){return n===void 0&&(n=0),this},e}(me);var ar={setInterval:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ar.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,Z([t,e],J(r))):setInterval.apply(void 0,Z([t,e],J(r)))},clearInterval:function(t){var e=ar.delegate;return((e==null?void 0:e.clearInterval)||clearInterval)(t)},delegate:void 0};var ln=function(t){_(e,t);function e(r,n){var i=t.call(this,r,n)||this;return i.scheduler=r,i.work=n,i.pending=!1,i}return e.prototype.schedule=function(r,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=r;var o=this.id,a=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(a,o,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(a,this.id,n),this},e.prototype.requestAsyncId=function(r,n,i){return i===void 0&&(i=0),ar.setInterval(r.flush.bind(r,this),i)},e.prototype.recycleAsyncId=function(r,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&ar.clearInterval(n)},e.prototype.execute=function(r,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(r,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(r,n){var i=!1,o;try{this.work(r)}catch(a){i=!0,o=a||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),o},e.prototype.unsubscribe=function(){if(!this.closed){var r=this,n=r.id,i=r.scheduler,o=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,ge(o,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},e}(pn);var bt=function(){function t(e,r){r===void 0&&(r=t.now),this.schedulerActionCtor=e,this.now=r}return t.prototype.schedule=function(e,r,n){return r===void 0&&(r=0),new this.schedulerActionCtor(this,e).schedule(n,r)},t.now=or.now,t}();var fn=function(t){_(e,t);function e(r,n){n===void 0&&(n=bt.now);var i=t.call(this,r,n)||this;return i.actions=[],i._active=!1,i}return e.prototype.flush=function(r){var n=this.actions;if(this._active){n.push(r);return}var i;this._active=!0;do if(i=r.execute(r.state,r.delay))break;while(r=n.shift());if(this._active=!1,i){for(;r=n.shift();)r.unsubscribe();throw i}},e}(bt);var yt=new fn(ln),mn=yt;var dn=new A(function(t){return t.complete()});function hn(t){return t&&g(t.schedule)}function Ti(t){return t[t.length-1]}function bn(t){return hn(Ti(t))?t.pop():void 0}var Cr=function(t){return t&&typeof t.length=="number"&&typeof t!="function"};function Ar(t){return g(t==null?void 0:t.then)}function Sr(t){return g(t[We])}function Or(t){return Symbol.asyncIterator&&g(t==null?void 0:t[Symbol.asyncIterator])}function Ur(t){return new TypeError("You provided "+(t!==null&&typeof t=="object"?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Ci(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Rr=Ci();function Ir(t){return g(t==null?void 0:t[Rr])}function _r(t){return Xt(this,arguments,function(){var r,n,i,o;return vr(this,function(a){switch(a.label){case 0:r=t.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,ve(r.read())];case 3:return n=a.sent(),i=n.value,o=n.done,o?[4,ve(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,ve(i)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function Br(t){return g(t==null?void 0:t.getReader)}function F(t){if(t instanceof A)return t;if(t!=null){if(Sr(t))return Ai(t);if(Cr(t))return Si(t);if(Ar(t))return Oi(t);if(Or(t))return yn(t);if(Ir(t))return Ui(t);if(Br(t))return Ri(t)}throw Ur(t)}function Ai(t){return new A(function(e){var r=t[We]();if(g(r.subscribe))return r.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Si(t){return new A(function(e){for(var r=0;r<t.length&&!e.closed;r++)e.next(t[r]);e.complete()})}function Oi(t){return new A(function(e){t.then(function(r){e.closed||(e.next(r),e.complete())},function(r){return e.error(r)}).then(null,Er)})}function Ui(t){return new A(function(e){var r,n;try{for(var i=pe(t),o=i.next();!o.done;o=i.next()){var a=o.value;if(e.next(a),e.closed)return}}catch(s){r={error:s}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.complete()})}function yn(t){return new A(function(e){Ii(t,e).catch(function(r){return e.error(r)})})}function Ri(t){return yn(_r(t))}function Ii(t,e){var r,n,i,o;return Qt(this,void 0,void 0,function(){var a,s;return vr(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),r=Jt(t),u.label=1;case 1:return[4,r.next()];case 2:if(n=u.sent(),!!n.done)return[3,4];if(a=n.value,e.next(a),e.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return s=u.sent(),i={error:s},[3,11];case 6:return u.trys.push([6,,9,10]),n&&!n.done&&(o=r.return)?[4,o.call(r)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}})})}function H(t,e,r,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=e.schedule(function(){r(),i?t.add(this.schedule(null,n)):this.unsubscribe()},n);if(t.add(o),!i)return o}function Pr(t,e){return e===void 0&&(e=0),E(function(r,n){r.subscribe(S(n,function(i){return H(n,t,function(){return n.next(i)},e)},function(){return H(n,t,function(){return n.complete()},e)},function(i){return H(n,t,function(){return n.error(i)},e)}))})}function Fr(t,e){return e===void 0&&(e=0),E(function(r,n){n.add(t.schedule(function(){return r.subscribe(n)},e))})}function xn(t,e){return F(t).pipe(Fr(e),Pr(e))}function vn(t,e){return F(t).pipe(Fr(e),Pr(e))}function gn(t,e){return new A(function(r){var n=0;return e.schedule(function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())})})}function wn(t,e){return new A(function(r){var n;return H(r,e,function(){n=t[Rr](),H(r,e,function(){var i,o,a;try{i=n.next(),o=i.value,a=i.done}catch(s){r.error(s);return}a?r.complete():r.next(o)},0,!0)}),function(){return g(n==null?void 0:n.return)&&n.return()}})}function Lr(t,e){if(!t)throw new Error("Iterable cannot be null");return new A(function(r){H(r,e,function(){var n=t[Symbol.asyncIterator]();H(r,e,function(){n.next().then(function(i){i.done?r.complete():r.next(i.value)})},0,!0)})})}function En(t,e){return Lr(_r(t),e)}function Tn(t,e){if(t!=null){if(Sr(t))return xn(t,e);if(Cr(t))return gn(t,e);if(Ar(t))return vn(t,e);if(Or(t))return Lr(t,e);if(Ir(t))return wn(t,e);if(Br(t))return En(t,e)}throw Ur(t)}function Cn(t,e){return e?Tn(t,e):F(t)}function kr(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=bn(t);return Cn(t,r)}function he(t,e){var r=g(t)?t:function(){return t},n=function(i){return i.error(r())};return new A(e?function(i){return e.schedule(n,0,i)}:n)}var Dr=fe(function(t){return function(){t(this),this.name="EmptyError",this.message="no elements in sequence"}});function Nr(t){return t instanceof Date&&!isNaN(t)}var _i=fe(function(t){return function(r){r===void 0&&(r=null),t(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=r}});function An(t,e){var r=Nr(t)?{first:t}:typeof t=="number"?{each:t}:t,n=r.first,i=r.each,o=r.with,a=o===void 0?Bi:o,s=r.scheduler,u=s===void 0?e!=null?e:yt:s,l=r.meta,p=l===void 0?null:l;if(n==null&&i==null)throw new TypeError("No timeout provided.");return E(function(d,h){var c,f,b=null,y=0,x=function(R){f=H(h,u,function(){try{c.unsubscribe(),F(a({meta:p,lastValue:b,seen:y})).subscribe(h)}catch(C){h.error(C)}},R)};c=d.subscribe(S(h,function(R){f==null||f.unsubscribe(),y++,h.next(b=R),i>0&&x(i)},void 0,void 0,function(){f!=null&&f.closed||f==null||f.unsubscribe(),b=null})),!y&&x(n!=null?typeof n=="number"?n:+n-u.now():i)})}function Bi(t){throw new _i(t)}function Te(t,e){return E(function(r,n){var i=0;r.subscribe(S(n,function(o){n.next(t.call(e,o,i++))}))})}function ne(t){return new A(function(e){F(t()).subscribe(e)})}function Ce(t,e){return E(function(r,n){var i=0;r.subscribe(S(n,function(o){return t.call(e,o,i++)&&n.next(o)}))})}function qr(t){return E(function(e,r){var n=null,i=!1,o;n=e.subscribe(S(r,void 0,void 0,function(a){o=F(t(a,qr(t)(e))),n?(n.unsubscribe(),n=null,o.subscribe(r)):i=!0})),i&&(n.unsubscribe(),n=null,o.subscribe(r))})}function Sn(t){return E(function(e,r){var n=!1;e.subscribe(S(r,function(i){n=!0,r.next(i)},function(){n||r.next(t),r.complete()}))})}function On(t){return t<=0?function(){return dn}:E(function(e,r){var n=0;e.subscribe(S(r,function(i){++n<=t&&(r.next(i),t<=n&&r.complete())}))})}function xt(t,e){return e===void 0&&(e=de),t=t!=null?t:Pi,E(function(r,n){var i,o=!0;r.subscribe(S(n,function(a){var s=e(a);(o||!t(i,s))&&(o=!1,i=s,n.next(a))}))})}function Pi(t,e){return t===e}function Un(t){return t===void 0&&(t=Fi),E(function(e,r){var n=!1;e.subscribe(S(r,function(i){n=!0,r.next(i)},function(){return n?r.complete():r.error(t())}))})}function Fi(){return new Dr}function Mr(t){return E(function(e,r){try{e.subscribe(r)}finally{r.add(t)}})}function sr(t,e){var r=arguments.length>=2;return function(n){return n.pipe(t?Ce(function(i,o){return t(i,o,n)}):de,On(1),r?Sn(e):Un(function(){return new Dr}))}}function ie(t){t===void 0&&(t={});var e=t.connector,r=e===void 0?function(){return new B}:e,n=t.resetOnError,i=n===void 0?!0:n,o=t.resetOnComplete,a=o===void 0?!0:o,s=t.resetOnRefCountZero,u=s===void 0?!0:s;return function(l){var p,d,h,c=0,f=!1,b=!1,y=function(){d==null||d.unsubscribe(),d=void 0},x=function(){y(),p=h=void 0,f=b=!1},R=function(){var C=p;x(),C==null||C.unsubscribe()};return E(function(C,Q){c++,!b&&!f&&y();var z=h=h!=null?h:r();Q.add(function(){c--,c===0&&!b&&!f&&(d=vt(R,u))}),z.subscribe(Q),!p&&c>0&&(p=new Ee({next:function(X){return z.next(X)},error:function(X){b=!0,y(),d=vt(x,i,X),z.error(X)},complete:function(){f=!0,y(),d=vt(x,a),z.complete()}}),F(C).subscribe(p))})(l)}}function vt(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];if(e===!0){t();return}if(e!==!1){var i=new Ee({next:function(){i.unsubscribe(),t()}});return F(e.apply(void 0,Z([],J(r)))).subscribe(i)}}function gt(t,e,r){var n,i,o,a,s=!1;return t&&typeof t=="object"?(n=t.bufferSize,a=n===void 0?1/0:n,i=t.windowTime,e=i===void 0?1/0:i,o=t.refCount,s=o===void 0?!1:o,r=t.scheduler):a=t!=null?t:1/0,ie({connector:function(){return new un(a,e,r)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:s})}function Ve(t,e){return E(function(r,n){var i=null,o=0,a=!1,s=function(){return a&&!i&&n.complete()};r.subscribe(S(n,function(u){i==null||i.unsubscribe();var l=0,p=o++;F(t(u,p)).subscribe(i=S(n,function(d){return n.next(e?e(u,d,p,l++):d)},function(){i=null,s()}))},function(){a=!0,s()}))})}function Ae(t,e,r){var n=g(t)||e||r?{next:t,error:e,complete:r}:t;return n?E(function(i,o){var a;(a=n.subscribe)===null||a===void 0||a.call(n);var s=!0;i.subscribe(S(o,function(u){var l;(l=n.next)===null||l===void 0||l.call(n,u),o.next(u)},function(){var u;s=!1,(u=n.complete)===null||u===void 0||u.call(n),o.complete()},function(u){var l;s=!1,(l=n.error)===null||l===void 0||l.call(n,u),o.error(u)},function(){var u,l;s&&((u=n.unsubscribe)===null||u===void 0||u.call(n)),(l=n.finalize)===null||l===void 0||l.call(n)}))}):de}function zr(t,e,r){var n,i,o;if(r=r!=null?r:mn,Nr(t)?n=t:typeof t=="number"&&(i=t),e)o=function(){return e};else throw new TypeError("No observable provided to switch to");if(n==null&&i==null)throw new TypeError("No timeout provided.");return An({first:n,each:i,scheduler:r,with:o})}var $=xr(Pn());var Hi="@iotize/tap/protocol/common",Oe=(0,$.default)(Hi);var Ki="ComProtocol",jr=class{get options(){return this._options}set options(e){this._options=e}constructor(){this.connectionState=0,this._options={connect:{timeout:1e3},disconnect:{timeout:1e3},send:{timeout:500}}}getConnectionState(){return this.connectionState}isConnected(){return this.connectionState==2}setConnectionState(e){Oe(Ki,"setConnectionState",D[e],"Old: ",D[this.connectionState]);let r={newState:e,oldState:this.connectionState};return this.connectionState=e,this._connectionStateChange&&this._connectionStateChange.next(r),this}receiveStream(){throw new Error("Method not implemented.")}onConnectionStateChange(){return this._connectionStateChange||(this._connectionStateChange=new B),this._connectionStateChange}};function Vr(t,e){return t.reduce((r,n,i)=>r.then(()=>e(n,i)),Promise.resolve())}function wt(t,e,r=()=>new Error(`Timeout after ${t}ms`)){let n=new Date;if(t<=0){let o=r({timeout:t,startTime:n});return Promise.reject(o)}let i=new Promise((o,a)=>{let s=setTimeout(()=>{clearTimeout(s);let u=r({timeout:t,startTime:n});a(u)},t)});return Promise.race([e,i])}var Ue=class t extends Error{constructor(r,n){super(n);this.code=r}static operationCancelled(r){return new t(t.Code.TASK_OPERATION_CANCELLED,"Operation cancelled")}};(e=>{let t;(n=>n.TASK_OPERATION_CANCELLED="TASK_OPERATION_CANCELLED")(t=e.Code||(e.Code={}))})(Ue||(Ue={}));var Yi="@iotize/common:task-manager",O=(0,$.default)(Yi);var W="StepOperations",cr=class t{constructor(e){this.operationContainers=e;this._state=t.State.PENDING;this._events=new B}get isCancelled(){return this._state===t.State.CANCELED}get isCompleted(){return this._state===t.State.COMPLETED}get state(){return this._state}get events(){return this._events.asObservable()}set taskErrorHandler(e){this._taskErrorHandler=e}get operations(){return this.operationContainers.map(e=>e.operation)}static createSequentialContainers(e){return e.map((r,n)=>{if(typeof r=="function"){let i=r;r=new class{perform(o,a){return i(o,a)}}}else if(r instanceof A){let i=r.pipe(ie());r=new class{async perform(o,a){return await i.pipe(Ae(s=>{o.next(s)})).toPromise()}}}return{operation:r,index:n}})}static sequential(e){let r=t.createSequentialContainers(e);return new t(r)}runEvents(){return this._currentExecutionEvents||(this._currentExecutionEvents=new B),this._currentExecutionEvents.asObservable()}reset(){return O(W,"reset()"),this.operationContainers.forEach(e=>{e.operation.onReset&&e.operation.onReset()}),this._currentExecutionEvents=void 0,this.operationContainers.forEach(e=>{e.done=void 0,e.error=void 0,e.result=void 0}),this._state=t.State.PENDING,this}retry(){return O(W,"retry()"),this._state=t.State.PENDING,this.operationContainers.forEach(e=>{e.operation.onRetry&&e.operation.onRetry()}),this.run()}run(){switch(O(W,"run()"),this._currentExecutionEvents||(O(W,"create _currentExecutionEvents"),this._currentExecutionEvents=new B,this._currentExecutionEvents.subscribe({next:e=>{this._events.next({type:"event",event:e})},error:e=>{this._events.next({type:"error",event:e})},complete:()=>{this._events.next({type:"complete"})}})),this._state){case t.State.PENDING:this._start(this._currentExecutionEvents);break}return this._currentExecutionEvents.asObservable()}cancel(){O(W,"cancel()"),this._state=t.State.CANCELED}asObservable(){return new A(e=>(O(W,"StepOperation converted to observable has been subscribed"),this.run().subscribe(e),()=>{this._state===t.State.RUNNING&&(O(W,"StepOperation converted to observable has been cancelled"),this.cancel())})).pipe(ie())}checkIsCancelled(){if(this.isCancelled)throw Re.cancel()}checkIsRunning(){if(this.checkIsCancelled(),this._state!==t.State.RUNNING)throw Re.unknown("Operation should not have been executed")}_onTaskError(e,r){if(this._taskErrorHandler)O("custom error handler"),this._taskErrorHandler.handle(e,r);else throw e}async _start(e){this._state=t.State.RUNNING;let r=this.operationContainers.filter(n=>n.done!==!0);O(W,"_start",`operation number: ${r.length}`);try{let n={};await Vr(r,async(i,o)=>{let a={position:o,total:r.length,index:i.index,prevOperation:o>0?this.operationContainers[o-1]:void 0,data:n};try{this.checkIsRunning(),O(W,`Task n\xB0${i.index+1} (${o+1}/${r.length}): Start processing...`);let s=await i.operation.perform(e,a);return i.done=!0,i.result=s,O(W,`Task n\xB0${i.index+1} (${o+1}/${r.length}): DONE!`),s}catch(s){let u=s;i.error=u,O(W,`Task n\xB0${i.index+1} (${o+1}/${r.length}): error: ${u.message}`),this._onTaskError(u,a)}}),O(W,"complete"),this.onComplete(e)}catch(n){this.onError(n,e)}}onComplete(e){e.complete(),this._state=t.State.COMPLETED}onError(e,r){O(W,"error ",e.message),this._state=t.State.ERRORED,r.error(e),this._currentExecutionEvents=void 0}},Re=class t extends Error{constructor(r,n){super(n);this.code=r}static cancel(){return new t(t.Code.STEP_OPERATION_CANCEL,"Operation cancel by user")}static unknown(r){return new t(t.Code.UNKNOWN_ERROR,r)}};(e=>{let t;(i=>(i.UNKNOWN_ERROR="STEP_OPERATION_UNKNOWN_ERROR",i.STEP_OPERATION_CANCEL="STEP_OPERATION_CANCEL"))(t=e.Code||(e.Code={}))})(Re||(Re={}));(e=>{let t;(s=>(s.PENDING="PENDING",s.RUNNING="RUNNING",s.COMPLETED="COMPLETED",s.CANCELED="CANCELED",s.ERRORED="ERRORED"))(t=e.State||(e.State={}))})(cr||(cr={}));var Qi="CancelableTask",Gr=class{constructor(e){this.operation=e;this._subject=new B,this._canceled=!1,this._executed=!1}get isCanceled(){return this._canceled}cancel(e){if(!this._canceled){O(Qi,"Canceling operation"),this._canceled=!0;let r=e||Ue.operationCancelled(this);this._subject.error(r)}}execute(){return!this._executed&&!this._canceled&&(this._executed=!0,O("Start operation execution..."),this.operation().subscribe({next:e=>{this._subject.next(e)},error:e=>{this._subject.error(e)},complete:()=>{this._subject.complete()}})),this._subject}toObservable(){return this._subject}};var Fn="TaskQueue",Hr=class{set workingState(e){this._subscription=e,this._subscription===void 0&&(this.processNext(),this.currentTask=void 0)}constructor(){this.tasks=[]}addExecutor(e){return this.addTask(new Gr(e))}addTask(e){return this.tasks.push(e),this.processNext(),e.toObservable()}cancelAll(e){this.currentTask&&this.currentTask.cancel(e);let r=this.tasks.shift();for(;r;)r.cancel(e),r=this.tasks.shift()}processNext(){if(this._subscription===void 0){let e=this.tasks.shift();if(e){this.currentTask=e;let r=!1,i=e.execute().subscribe({next:()=>{this.workingState=void 0,r=!0},error:o=>{O(Fn,"Task done with error!",o),this.workingState=void 0,r=!0}});r||(this.workingState=i)}}else O(Fn,"addTask... there is already a process running...")}};var Kr="ComProtocol",Ie=class extends jr{_send(e,r){return ne(async()=>{if(!this.isConnected())throw G.Errors.notConnected({protocol:this});let n=new Date;await wt(r.timeout,this.write(e),s=>G.Errors.timeoutError({msg:`Communication timeout. Send request to device device timeout (${s.timeout}ms).`,protocol:this,timeout:s.timeout,startTime:s.startTime}));let i=new Date().getTime()-n.getTime(),o=r.timeout-i;return await wt(o,this.read(),s=>G.Errors.timeoutError({msg:`Communication timeout. Read response from device timeout (${o}ms).`,protocol:this,timeout:o,startTime:s.startTime}))}).pipe(ie())}constructor(){super(),this._jobQueue=new Hr}cancel(){Oe(Kr,"Canceling operations"),this._jobQueue.cancelAll(G.Errors.operationCanceled())}send(e,r){return e=e.slice(0),this._jobQueue.addExecutor(()=>{let n=r?r.timeout:this._options.send.timeout;return this._send(e,{timeout:n})})}connect(e){if(this.connectionState===2)return Oe(Kr,"QueueComProtocol is already connected"),kr(null);if(this._connect$)return Oe(Kr,"QueueComProtocol is already connecting..."),this._connect$;if(this._disconnect$)return he(G.Errors.operationInProgress("Failed to connect as disconnection is in progress"));let r=e?e.timeout:this._options.connect.timeout;return this._connect$=ne(()=>{this.setConnectionState(1);let n=new Date;return this._connect(e).pipe(zr(r,he(G.Errors.timeoutError({msg:"Protocol connection timeout",protocol:this,timeout:r,startTime:n}))))}).pipe(Ae({complete:()=>{this.setConnectionState(2)},error:()=>{this.setConnectionState(0)}}),Mr(()=>{this._connect$=void 0}),ie()),this._connect$}disconnect(e){if(this.connectionState===0)return Oe(Kr,"QueueComProtocol is already disconnected"),kr();if(this._disconnect$)return this._disconnect$;if(this._connect$)return he(G.Errors.operationInProgress("Failed to disconnect as connection is in progress"));let r=e?e.timeout:this._options.disconnect.timeout;return this._disconnect$=ne(async()=>{this.setConnectionState(3)}).pipe(Ve(()=>{let n=new Date;return this._disconnect(e).pipe(zr(r,he(G.Errors.timeoutError({msg:"Protocol disconnection timeout",protocol:this,timeout:r,startTime:n}))),Mr(()=>{this.setConnectionState(0),this._disconnect$=void 0}))}),ie()),this._disconnect$}};var ur=class extends Error{constructor(e){super(e),Object.defineProperty(this,"name",{get:()=>this.constructor.name,set:()=>{}}),typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,this.constructor)}};var re=class extends ur{constructor(r,n){super(r);this.code=n}};var L=class t extends re{static invalidErrorResult(e){return new t("Internal error: ble cordova plugin returned an unexpected error object",t.Code.InternalError)}static invalidErrorCode(e){return new t(`Internal error: ble cordova plugin returned an invalid error code ${e.code} with message ${e.message}`,t.Code.InternalError)}static invalidNativeCallResult(e,r){return new t(`Internal error: native call returned an invalid data type. ${r.message}`,t.Code.InternalError)}static isValidErrorCode(e){return e in t.Code}static iotizeBLEMissing(){return new t("iotizeBLE global variable does not exist. Are you sure app is running inside a Cordova application ?",t.Code.InternalError)}};(e=>{let t;(c=>(c.InternalError="CordovaBLEErrorInternalError",c.IllegalArgument="CordovaBLEErrorIllegalArgument",c.BLENotAvailable="CordovaBLEErrorBLENotAvailable",c.InvalidMacAddress="InvalidMacAddressInvalidMacAddress",c.ConnectionError="CordovaBLEErrorConnectionError",c.RequestError="CordovaBLEErrorRequestError",c.LocationServiceDisabled="CordovaBLEErrorLocationServiceDisabled",c.DisconnectError="CordovaBLEErrorDisconnectError",c.IllegalAction="CordovaBLEErrorIllegalAction",c.NotConnectedError="CordovaBLEErrorNotConnectedError",c.StatusCodeError="CordovaBLEErrorStatusCodeError"))(t=e.Code||(e.Code={}))})(L||(L={}));var te=(0,$.default)("@iotize/device-com-ble.cordova");function be(){if(typeof iotizeBLE!="object")throw L.iotizeBLEMissing();return iotizeBLE}function Ln(t){let e=[];for(let r=0;r<t.length;r++){let n=t[r];if(n==0)break;let i=t[r+1];e.push({type:i,data:t.slice(r+2,r+n+1)}),r+=n}return e}var Yr=class extends Ie{constructor(r,n,i){super();this.deviceId=r;this.cordovaInterfaceOverwrite=i;n?this.options=n:this.options.connect.timeout=6e4}get pluginInterface(){return this.cordovaInterfaceOverwrite||be()}_connect(r){return te("_connect",r),this.pluginInterface.connectAndDiscoverTapServices(this.deviceId).pipe(Ae(n=>{this.setConnectionState(n)}),Ce(n=>n===2),sr())}_disconnect(r){return te("_disconnect",r),ne(()=>this.pluginInterface.disConnect(this.deviceId))}async write(r){throw new Error("Method not implemented.")}async read(){throw new Error("Method not implemented.")}send(r,n){return ne(()=>this.pluginInterface.send(this.deviceId,r)).pipe(qr(i=>((i==null?void 0:i.code)===L.Code.NotConnectedError&&this.setConnectionState(0),he(i))))}};var Et={maxPacketLengthWithoutOffset:19,services:{upgrade:{service:"9e5d1e47-5c13-43a0-8635-82ad38a1386f",charac:"347f7608-2e2d-47eb-913b-75d4edc4de3b"},lwm2m:{service:"6c7b16c2-2a5b-8c9f-cf42-d31425470e7b",charac:"cc5c5491-b3be-9287-cb42-f7a6a29a50d5"},fastLwm2m:{service:"7c7b16c2-2a5b-8c9f-cf42-d31425470e7b",charac:"dc5c5491-b3be-9287-cb42-f7a6a29a50d5"},standardClientConfig:{service:"00002902-0000-1000-8000-00805f9b34fb"}}};function Ye(t){return t.buffer.slice(t.byteOffset,t.byteLength+t.byteOffset)}function U(t){return t?Array.prototype.map.call(t,r=>("00"+r.toString(16)).slice(-2)).join("").toUpperCase():""}function kn(t){let e;t=t.trim();let r=t.startsWith("0x")?2:0,n=[];for(;r<t.length;r++)switch(t[r]){case" ":case" ":continue;default:if(e!==void 0){let i=parseInt(e+t[r],16);if(isNaN(i))throw new Error(`Invalid hexadecimal string format for input string "${t}"`);n.push(i),e=void 0}else e=t[r]}return e!==void 0&&n.push(parseInt(e,16)),Uint8Array.from(n)}var Zn=xr(Zr());var pr=class pr{constructor(e,r=0,n=!0){this._bitsLeft=8;this._byteLength=0;this._byteOffset=r,e instanceof ArrayBuffer||e&&e.constructor.name==="SharedArrayBuffer"?this.buffer=e:typeof e=="object"?(this.dataView=e,r&&(this._byteOffset+=r)):this.buffer=new ArrayBuffer(e||1),this._isBigEndian=n,this._pos=0,this.alignToByte()}get byteLeft(){return this.size-this._pos}set pos(e){this._pos=e,this.alignToByte()}get pos(){return this._pos}get buffer(){return this._trimAlloc(),this._buffer}get toBytes(){let e=this._dataView.byteLength;this._bitsLeft<8&&(e+=1);let r=new Uint8Array(e);for(let n=0;n<e;n++)r[n]=this._dataView.getUint8(n);return r}set buffer(e){this._buffer=e,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}get isBigEndian(){return this._isBigEndian}get isLittleEndian(){return!this._isBigEndian}get byteOffset(){return this._byteOffset}set byteOffset(e){this._byteOffset=e,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}get dataView(){return this._dataView}set dataView(e){this._byteOffset=e.byteOffset,this._buffer=e.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+e.byteLength}get size(){return this._byteLength-this._byteOffset}get bitsLeft(){return this._bitsLeft}get bits(){return this._getBitsFromCurrentPosition()}static bytesStripRight(e,r){let n=e.length;for(;e[n-1]===r;)n--;return e.slice(0,n)}static bytesTerminate(e,r,n=!1){let i=0,o=e.length;for(;i<o&&e[i]!==r;)i++;return n&&i<o&&i++,e.slice(0,i)}static bytesToStr(e,r){if(r==null||r.toLowerCase()==="ascii")return pr.createStringFromArray(e);if(typeof TextDecoder=="function")return new TextDecoder(r).decode(e);{let n=Uo(r);return Zn.Buffer.from(e).toString(n)}}static mod(e,r){if(r<=0)throw new Error("mod divisor <= 0");let n=e%r;return n<0&&(n+=r),n}static arrayMin(e){let r=e[0],n;for(let i=1,o=e.length;i<o;++i)n=e[i],n<r&&(r=n);return r}static arrayMax(e){let r=e[0],n;for(let i=1,o=e.length;i<o;++i)n=e[i],n>r&&(r=n);return r}static byteArrayCompare(e,r){if(e===r)return 0;let n=e.length,i=r.length,o=n<i?n:i;for(let a=0;a<o;a++){let s=e[a]-r[a];if(s!==0)return s}return n===i?0:n-i}static createStringFromArray(e){let n=[];for(let i=0;i<e.length;i+=32768)n.push(String.fromCharCode.apply(null,e.subarray(i,i+32768)));return n.join("")}static processXorOne(e,r){let n=new Uint8Array(e.length),i=e.length;for(let o=0;o<i;o++)n[o]=e[o]^r;return n}static processXorMany(e,r){let n=new Uint8Array(e.length),i=e.length,o=r.length,a=0;for(let s=0;s<e.length;s++)n[s]=e[s]^r[a],a++,a>=o&&(a=0);return n}static processRotateLeft(e,r,n){if(n!==1)throw new Error("unable to rotate group of "+n+" bytes yet");let i=n*8-1,o=-r&i,a=new Uint8Array(e.length);for(let s=0;s<e.length;s++)a[s]=e[s]<<r&255|e[s]>>o;return a}getStreamSize(){return this._buffer.byteLength}alignToByte(){this._bitsLeft=8}_getBitsFromCurrentPosition(){return this._pos<this._byteLength?this._dataView.getUint8(this._pos):0}_decreaseBitsLeft(e){e<0&&(e=0),this._bitsLeft-=e,this._bitsLeft<=0&&this.pos++}_trimAlloc(){if(this._byteLength===this._buffer.byteLength)return;let e=new ArrayBuffer(this._byteLength),r=new Uint8Array(e),n=new Uint8Array(this._buffer,0,r.length);r.set(n),this.buffer=e}isEof(){return this.pos>=this.size}forward(e){return this.seek(this.pos+e),this}seek(e){let r=Math.max(0,Math.min(this.size,e));this.pos=isNaN(r)||!isFinite(r)?0:r}forwardBits(e){let r=Math.floor(e/8),n=e%8,i=this._bitsLeft-n;return i<=0?(this.pos+=r+1,this._bitsLeft=8+i):(this.pos+=r,this._bitsLeft=i),this}setBitPosition(e){e=Math.max(0,e);let r=Math.floor(e/8);this.pos=r,this.forwardBits(e%8)}getBitPosition(){return this.pos*8+(8-this._bitsLeft)}mapUint8Array(e){if(e|=0,this.pos+e>this.size)throw new Bt(e,this.size-this.pos);let r=new Uint8Array(this._buffer,this.byteOffset+this.pos,e);return this._pos+=e,r}};pr.depUrls={zlib:void 0},pr.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0;var Je=pr,Bt=class extends Error{constructor(r,n){super("requested "+r+" bytes, but only "+n+" bytes available");this.bytesReq=r;this.bytesAvail=n}},lr=class extends Error{constructor(r,n){super("expected ["+r+"], but got ["+n+"]");this.expected=r;this.actual=n}};function Uo(t){switch(t=t.toLowerCase(),t){case"utf8":case"utf-8":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t;default:throw new Error(`Unsupported encoding: ${t}`)}}function Ro(t,e){return t*Math.pow(2,e)}var et=class t extends Je{static fromArray(e){let r=Ye(e);return new t(r)}static create(e){return e instanceof Uint8Array?t.fromArray(e):e}constructor(e,r=0,n=!0){super(e,r,n)}readS(e){return this.read("s",e*8)}readSigned(e){return this.read("s",e*8)}read(e,r,n=this.isLittleEndian){e!=="b"&&(r/=8);let i=`read${e.toUpperCase()}${e!=="b"?r:""}${r>1&&e!=="b"?n?"le":"be":""}`;if(!(i in this))throw new Error(`Invalid read type: type=${e}, size=${r}, le=${n}. Method name: ${i}`);return this[i](r)}readS1(){let e=this._dataView.getInt8(this.pos);return this.pos+=1,e}readS2be(){let e=this._dataView.getInt16(this.pos);return this.pos+=2,e}readS4be(){let e=this._dataView.getInt32(this.pos);return this.pos+=4,e}readS8be(){let e=this.readU4be(),r=this.readU4be();return e&2147483648?-(4294967296*(e^4294967295)+(r^4294967295))-1:4294967296*e+r}readS2le(){let e=this._dataView.getInt16(this.pos,!0);return this.pos+=2,e}readS4le(){let e=this._dataView.getInt32(this.pos,!0);return this.pos+=4,e}readS8le(){let e=this.readU4le(),r=this.readU4le();return r&2147483648?-(4294967296*(r^4294967295)+(e^4294967295))-1:4294967296*r+e}readU(e){return this.read("u",e*8)}readUnsigned(e){return this.read("u",e*8)}readU1(){let e=this._dataView.getUint8(this.pos);return this.pos+=1,e}readU2be(){let e=this._dataView.getUint16(this.pos);return this.pos+=2,e}readU4be(){let e=this._dataView.getUint32(this.pos);return this.pos+=4,e}readU8be(){let e=this.readU4be(),r=this.readU4be();return 4294967296*e+r}readU2le(){let e=this._dataView.getUint16(this.pos,!0);return this.pos+=2,e}readU4le(){let e=this._dataView.getUint32(this.pos,!0);return this.pos+=4,e}readU8le(){let e=this.readU4le();return 4294967296*this.readU4le()+e}readF(e){return this.read("f",e*8)}readFloat(e){return this.read("f",e*8)}readF4be(){let e=this._dataView.getFloat32(this.pos);return this.pos+=4,e}readF8be(){let e=this._dataView.getFloat64(this.pos);return this.pos+=8,e}readF4le(){let e=this._dataView.getFloat32(this.pos,!0);return this.pos+=4,e}readF8le(){let e=this._dataView.getFloat64(this.pos,!0);return this.pos+=8,e}readBitsBoolean(e){return this.readBitsInt(e)!==0}readB(e){return this.readBitsInt(e)}readBits(e){return this.readBitsInt(e)}readBoolean(e){return this.readBitsBoolean(e)}readBitsInt(e){if(e>52)throw new Error(`readBitsInt: the maximum supported bit length is 52 (tried to read ${e} bits)`);let r=0,n=e;for(;n>0;){let i=Math.min(this._bitsLeft,n),o=this._bitsLeft-i,s=this._getBitsFromCurrentPosition()&(1<<this._bitsLeft)-1;s=s>>o,r=Ro(r,i)+s,n-=i,n>0?this.pos++:this._decreaseBitsLeft(i)}return r}readBytes(e){return e===void 0?this.mapUint8Array(this.size-this.pos):(e<0&&(e=this.byteLeft+e),this.mapUint8Array(e))}readBytesFull(){return this.mapUint8Array(this.size-this.pos)}readBytesTerm(e,{include:r,consume:n,eosError:i}={}){let o=this.size-this.pos,a=new Uint8Array(this._buffer,this._byteOffset+this.pos),s;for(s=0;s<o&&a[s]!==e;s++);if(s===o){if(i)throw new Error("End of stream reached, but no terminator "+e+" found");return this.mapUint8Array(s)}else{let u;return r?u=this.mapUint8Array(s+1):u=this.mapUint8Array(s),n&&(this.pos+=1),u}}ensureFixedContents(e){let r=this.readBytes(e.length);if(r.length!==e.length)throw new lr(e,r);let n=r.length;for(let i=0;i<n;i++)if(r[i]!==e[i])throw new lr(e,r);return r}};function Pt(t,e){var r=2147483648,n=2147483647,i=~~(t/r),o=~~(e/r),a=t&n,s=e&n,u=i&o,l=a&s;return u*r+l}var Ze=class t extends Je{constructor(r,n=0,i=!0,o={checkValueSize:!1}){super(r,n,i);this.options=o}static mergeArrays(...r){let n=r.reduce((o,a)=>o+a.length,0),i=t.create(n);for(let o of r)i.writeBytes(o);return i.toBytes}static create(r){return new t(new ArrayBuffer(r))}get toBytes(){let r=this.pos,n=this.pos;this._bitsLeft<8&&n++;let i=new Uint8Array(n),o=0;for(;o<r;o++)i[o]=this._dataView.getUint8(o);return this._bitsLeft<8&&(i[n-1]=this._getBitsFromCurrentPosition()),i}write(r,n,i){this._checkSize(i);let o=`write${n.toUpperCase()}`;if(n!=="b"?i/=8:r=r===!0?1:r===!1?0:r,!(o in this))throw new Error(`Invalid write type: type=${n}. Method name: ${o}`);return this[o](r,i)}writeByte(r){return this._checkSize(1),this._dataView.setInt8(this.pos,r),this.pos++,this}writeU(r,n){if(this._checkSize(n),this.options.checkValueSize){let i=Math.pow(2,n*8)-1;if(r>i)throw new Error(`Cannt write unsigned ${r} on ${n} byte(s). Maximum value is ${i}`)}switch(n){case 4:this._dataView.setUint32(this.pos,r,this.isLittleEndian);break;case 2:this._dataView.setUint16(this.pos,r,this.isLittleEndian);break;case 1:this._dataView.setUint8(this.pos,r);break;default:throw new Error(`Unsupported unsigned size: ${n}`)}return this.pos+=n,this}writeF(r,n){switch(this._checkSize(n),n){case 4:this._dataView.setFloat32(this.pos,r,this.isLittleEndian);break;case 8:this._dataView.setFloat64(this.pos,r,this.isLittleEndian);break;default:throw new Error(`Illegal float size: ${n}`)}return this.pos+=n,this}writeS(r,n){switch(this._checkSize(n),n){case 4:this._dataView.setInt32(this.pos,r,this.isLittleEndian);break;case 2:this._dataView.setInt16(this.pos,r,this.isLittleEndian);break;case 1:this._dataView.setInt8(this.pos,r);break;default:throw new Error(`Illegal int size: ${n}`)}return this.pos+=n,this}flushBits(){}_setBitsAtCurrentPosition(r){this.dataView.setUint8(this.pos,r)}_setBit(r){let n=1<<this._bitsLeft-1,i=this._getBitsFromCurrentPosition();return r?i|=n:i&=~n,this._setBitsAtCurrentPosition(i),this._decreaseBitsLeft(1),this}writeB(r,n=1){r=r===!0?1:r===!1?0:r;for(let i=n-1;i>=0;i--){let o=Math.pow(2,i);this._setBit(!!Pt(r,o))}return this}forwardBit(){this.forwardBits(1)}writeBitsBoolean(r,n){return this.writeB(r,n)}writeBytes(r,n=r.length){this._checkSize(n);for(let i=0;i<n;i++)this._dataView.setInt8(this.pos,r[i]),this.pos++;return this}_checkSize(r){if(this.byteLeft<r){let i=this._dataView.byteLength+(Math.max(this._dataView.byteLength,r*1.1)-this.byteLeft);this.resize(i)}}resize(r){let n=new Uint8Array(r),i=this.toBytes;n.set(i),this.buffer=n.buffer}};var Io="@iotize/tap/client/impl",rt=(0,$.default)(Io);var k=class t extends re{constructor(r,n,i){super(n,r);this.cause=i}static unexpectedBufferSize(r,n){return new t(t.Code.UnexpectedBufferSizeError,"Expected buffer of "+r+" byte(s) but found only "+n.length+" byte(s)")}static nullBufferError(r){return new t(t.Code.NullBufferError,r)}static valueTooBigError(r,n){return new t(t.Code.ValueTooBigError,`Value ${r} is not acceptable. Maximum authorized value is ${n}.`)}};(e=>{let t;(o=>(o.UnexpectedBufferSizeError="UnexpectedBufferSizeError",o.NullBufferError="NullBufferError",o.ValueTooBigError="ConverterErrorValueTooBigError"))(t=e.Code||(e.Code={}))})(k||(k={}));var Y=class t{constructor(e){this.options=e}static uint8(e=!1){return new t({signed:!1,sizeOf:8,leastSignificantBitFirst:e})}static uint16(e=!1){return new t({signed:!1,sizeOf:16,leastSignificantBitFirst:e})}static uint32(e=!1){return new t({signed:!1,sizeOf:32,leastSignificantBitFirst:e})}static int8(e=!1){return new t({signed:!0,sizeOf:8,leastSignificantBitFirst:e})}static int16(e=!1){return new t({signed:!0,sizeOf:16,leastSignificantBitFirst:e})}static int32(e=!1){return new t({signed:!0,sizeOf:32,leastSignificantBitFirst:e})}decode(e){if(e.length*8<this.options.sizeOf)throw k.unexpectedBufferSize(this.options.sizeOf/8,e);return t.fromBytes(e,this.options.sizeOf/8,this.options.signed,this.options.leastSignificantBitFirst)}encode(e){let r=Math.pow(2,this.options.sizeOf)-1;if(e>r)throw k.valueTooBigError(e,r);let n=new Uint8Array(this.options.sizeOf>>3);for(var i=0;i<n.length;i++){let o=(n.length-i-1)*8;n[i]=e>>o&255}return this.options.leastSignificantBitFirst&&n.reverse(),n}static toOpaqueMsb(e,r){let n=Math.pow(2,r)-1;if(e>n)throw k.valueTooBigError(e,n);if(r===8)return new Uint8Array([e&255]);if(r===16)return new Uint8Array([e>>8&255,e&255]);if(r===32)return new Uint8Array([e>>24&255,e>>16&255,e>>8&255,e&255]);throw new Error(`Invalid size ${r}. Must be 8, 16 or 32`)}static fromOpaqueMsb(e,r){if(r||(r=e.length*8),r===8)return e[0]&255;if(r===16)return(e[1]&255)+((e[0]&255)<<8);if(r===32)return(e[3]&255)+((e[2]&255)<<8)+((e[1]&255)<<16)+((e[0]&255)<<24);throw new Error(`Invalid size ${r}. Must be 8, 16 or 32`)}static fromBytes(e,r,n,i){i&&(e=e.reverse());for(var o=0,a=0,s,u=0;u<r;u++){if(s=(r-u-1)*8,o+=(e[u]&255)<<s>>>0,a>o&&!n)throw new Error("Overflow. Last value: "+a+" but new is "+o);a=o}return n&&(e[0]&128)===128&&(o=-(Math.pow(2,8*r)-o)),o}};var Ft,I=class I{constructor(e){this.polynomial=e}static mpeg2(){return Ft||(Ft=new I(I.POLYNOMIAL_CRC32_MPEG2)),Ft}compute(e,r=I.FIRST_VALUE){return e instanceof Uint32Array?I.fromWord(e,r,this.polynomial):I.fromBytes(e,r,this.polynomial)}static fromBytes(e,r=I.FIRST_VALUE,n=I.POLYNOMIAL_CRC32_MPEG2){if(e.length%I.MODULO!==0)throw new Error(`Cannot compute CRC, input size must be a multiple of 4. Length is ${e.length} % ${I.MODULO} = ${e.length%I.MODULO}`);let i=new Uint32Array(e.length/4);for(let o=0;o<i.byteLength;o++)i[o]=Y.fromOpaqueMsb(e.slice(o*4,(o+1)*4),32);return I.fromWord(i,r,n)}static fromWord(e,r=I.FIRST_VALUE,n=I.POLYNOMIAL_CRC32_MPEG2){if(!e)throw new Error("Buffer is null");if(e.byteLength>16*1024*1024)throw new Error("Buffers larger than 16MB");let i;for(let o=0;o<e.length;o++)i=e[o],r=I.appendCrcNumber(r,i,n);return r}static appendCrcNumber(e,r,n){e=e^r;for(let i=0;i<32;i++)e&2147483648?e=(e<<1^n)>>>0:e=e<<1>>>0;return e}};I.POLYNOMIAL_CRC32_MPEG2=79764919,I.MODULO=4,I.FIRST_VALUE=4294967295;var fr=I;function Lt(t,e){return typeof t=="string"?e[t]:t}var w=class t extends et{static fromArray(e){let r=Ye(e);return new t(r)}static create(e){return e instanceof Uint8Array?t.fromArray(e):e}readStr(e){return String.fromCharCode.apply(null,this.readBytes(e))}readString(e=this.byteLeft){return this.readStr(e)}readStringTerminator(e){let r="";for(;;){let n=this.readU1(),i=String.fromCharCode(n);if(i!==e)r+=i;else break}return r}readU2(){return this._isBigEndian?this.readU2be():this.readU2le()}readU4(){return this._isBigEndian?this.readU4be():this.readU4le()}readF4(){return this._isBigEndian?this.readF4be():this.readF4le()}subStream(e){return t.fromArray(this.readBytes(e))}},T=class t extends Ze{constructor(e=512,r,n=!0){typeof e=="number"&&(e=new ArrayBuffer(e)),super(e,r,n)}static create(e){return new t(new ArrayBuffer(e))}writeFunction(e,r,n,i){switch(e){case"crc32":return this.addCRC(r);case"padding":if(n)return rt("Padding is already set"),this.writeBytes(n);if(i===void 0)throw new Error(`Padding function expect padding size as a second argument. Args: ${JSON.stringify({type:e,options:r,fieldValue:n,fieldSize:i})}`);return this.addPadding(i);default:throw new Error(`Invalid writer function type: ${e}`)}}addPadding(e){return this.writeBytes(new Uint8Array(e)),this}addCRC(e){let r=this.toBytes;e&&e.offset&&(r=r.slice(e.offset));let n=fr.fromBytes(r);return this.writeU4(n),this}writeUnsigned(e,r){return this.writeU(e,r),this}writeU4(e){return this.writeU(e,4),this}writeU2(e){return this.writeU(e,2),this}writeU1(e){return this.writeU(e,1),this}writeF4(e){return this.writeF(e,4),this}writeFloat(e,r){return this.writeF(e,r),this}writeSigned(e,r){return this.writeSigned(e,r),this}writeString(e,r=(e==null?void 0:e.length)||0){return this.writeStr(e||"",r)}writeStr(e,r=e.length){let n=1,i=Math.min(e.length,r);for(;n<=i;n++)this.writeByte(e.charCodeAt(n-1));let o=r-i;return o>0&&this.writeBytes(new Uint8Array(o)),this}writeBitsInt(e,r){return this.writeB(e,r),this}writeBits(e,r){return this.writeB(e,r),this}writeBoolean(e,r){return this.writeBits(e?1:0,r),this}};var v=class{};v.OK=0,v.CREATED=65,v.DELETED=66,v.CHANGED=68,v.CONTENT=69,v.BUSY=70,v.BAD_REQUEST=128,v.UNAUTHORIZED=129,v.NOT_FOUND=132,v.METHOD_NOT_ALLOWED=133,v.NOT_ACCEPTABLE=134,v.RESOURCE_LOCKED=135,v.INTERNAL_SERVER_ERROR=160,v.NOT_IMPLEMENTED=161,v.SERVICE_UNAVAILABLE=163,v.NVM_ERROR=164,v.UNABLE_TO_CONNECT_TO_TARGET=165,v.TARGET_POWER_FAILURE=166,v.NVM_FULL=167,v.DEVICE_UNAVAILABLE=168,v.RESPONSE_TOO_LARGE=169,v.TARGET_PROTOCOL_ERROR=176,v.TARGET_PROTOCOL_BUSY=177,v.TARGET_PROTOCOL_REAL=178,v.TARGET_PROTOCOL_WRONG_PARAM=179,v.TARGET_PROTOCOL_FORBIDDEN=180,v.TARGET_PROTOCOL_DATA=181,v.TARGET_PROTOCOL_COM=182,v.TARGET_PROTOCOL_LOST_COM=183,v.TARGET_PROTOCOL_PARAM=184,v.TARGET_PROTOCOL_INT=185,v.TARGET_PROTOCOL_ABORT=186,v.TARGET_PROTOCOL_NOT_IMPLEMENTED=187;var Pe;(e=>{let t;(n=>n[n.OK=36864]="OK")(t=e.Status||(e.Status={}))})(Pe||(Pe={}));var er;(r=>{let t;(o=>(o[o.GET=202]="GET",o[o.PUT_OR_POST=218]="PUT_OR_POST"))(t=r.MethodType||(r.MethodType={}));let e;(i=>i[i.CLA=162]="CLA")(e=r.Default||(r.Default={}))})(er||(er={}));var M;(e=>{let t;(o=>(o[o.GET=1]="GET",o[o.POST=2]="POST",o[o.PUT=3]="PUT"))(t=e.MethodType||(e.MethodType={}))})(M||(M={}));w.prototype.readApduRequest=function(){let t={};return t.header=this.readApduRequestHeader(),t.data=this.readBytes(t.header.lc),t};w.prototype.readApduRequestHeader=function(){let t={};return t.cla=this.readUnsigned(1),t.ins=this.readUnsigned(1),t.p1=this.readUnsigned(1),t.p2=this.readUnsigned(1),t.lc=this.readUnsigned(1),t};w.prototype.readApduResponse=function(){let t={};return t.data=this.readBytes(this.getStreamSize()-2),t.status=this.readUnsigned(2),t};w.prototype.readTapRequestEncrypted=function(){let t={};return t.header=this.readApduRequestHeader(),t.request=this.readTapRequestFrame(),t};w.prototype.readTapApduRequest=function(){return{}};w.prototype.readTapEncryptedFrame=function(){let t={};return t.id=this.readUnsigned(2),t.len=this.readUnsigned(2),t.payload=this.readBytes(t.len),t.padding=this.readBytes((16-(4+(t.len===void 0?0:t.len)+4)%16)%16),t.crc=this.readUnsigned(4),t};w.prototype.readTapRequestFrame=function(){let t={};return t.header=this.readTapRequestFrameHeader(),t.payload=this.readBytes(),t};w.prototype.readTapRequestFrameHeader=function(){let t={};return t.methodType=this.readUnsigned(1),t.path=this.readTapRequestFramePath(),t};w.prototype.readTapRequestFramePath=function(){let t={};return t.objectId=this.readUnsigned(2),t.objectInstanceId=this.readUnsigned(2),t.resourceId=this.readUnsigned(2),t};w.prototype.readTapResponseFrame=function(){let t={};return t.status=this.readUnsigned(1),t.data=this.readBytes(),t};T.prototype.writeApduRequest=function(t){return this.writeApduRequestHeader(t.header),this.writeBytes(t.data,t.header.lc),this};T.prototype.writeApduRequestHeader=function(t){return this.writeUnsigned(t.cla,1),this.writeUnsigned(t.ins,1),this.writeUnsigned(t.p1,1),this.writeUnsigned(t.p2,1),this.writeUnsigned(t.lc,1),this};T.prototype.writeApduResponse=function(t){return this.writeBytes(t.data,void 0),this.writeUnsigned(t.status,2),this};T.prototype.writeTapRequestEncrypted=function(t){return this.writeApduRequestHeader(t.header),this.writeTapRequestFrame(t.request),this};T.prototype.writeTapApduRequest=function(t){return this};T.prototype.writeTapEncryptedFrame=function(t){return this.writeUnsigned(t.id,2),this.writeUnsigned(t.len,2),this.writeBytes(t.payload,t.len),this.writeFunction("padding",void 0,t.padding,(16-(4+(t.len===void 0?0:t.len)+4)%16)%16),this.writeFunction("crc32",void 0,t.crc,4),this};T.prototype.writeTapRequestFrame=function(t){return this.writeTapRequestFrameHeader(t.header),this.writeBytes(t.payload),this};T.prototype.writeTapRequestFrameHeader=function(t){return this.writeBitsInt(Lt(t.methodType,M.MethodType),8),this.writeTapRequestFramePath(t.path),this};T.prototype.writeTapRequestFramePath=function(t){return this.writeUnsigned(t.objectId,2),this.writeUnsigned(t.objectInstanceId,2),this.writeUnsigned(t.resourceId,2),this};T.prototype.writeTapResponseFrame=function(t){return this.writeUnsigned(t.status,1),this.writeBytes(t.data),this};var tt=class{encode(e,r=new T){return r.writeTapRequestFrame(e),r.toBytes}decode(e){return(e instanceof w?e:w.create(e)).readTapRequestFrame()}};var _o=T.prototype.writeApduRequestHeader;T.prototype.writeApduRequestHeader=function(t){return t.lc>255?(this.writeUnsigned(t.cla,1),this.writeUnsigned(t.ins,1),this.writeUnsigned(t.p1,1),this.writeUnsigned(t.p2,1),this.writeUnsigned(0,1),this.writeUnsigned(t.lc,2),this):_o.apply(this,[t])};function kt(t){let e=new tt().encode(t),r;switch(t.header.methodType){case M.MethodType.GET:r=er.MethodType.GET;break;case M.MethodType.PUT:case M.MethodType.POST:r=er.MethodType.PUT_OR_POST;break;default:throw new Error(`Internal error: request type "${t.header.methodType}" is invalid`)}return{header:{cla:er.Default.CLA,ins:r,p1:0,p2:0,lc:e.length},data:e}}var se=class se{static parsePath(e){if(!e||e.length===0)throw new Error("Missing LWM2M path, it must not be empty");e=e.trim();let r=e.match(se.PATH_EXPRESSION);if(!r||r.length===0)throw new Error(`Invalid LWM2M path "${e}", it does not match expected format`);let n={objectId:this.validateId(parseInt(r[1])),objectInstanceId:r[2]?parseInt(r[2]):65535,resourceId:parseInt(r[3])};return r[4]&&(n.resourceInstanceId=parseInt(r[4],10)),n}static GET(e,r){return se.create(M.MethodType.GET,e,r)}static PUT(e,r){return se.create(M.MethodType.PUT,e,r)}static POST(e,r){return se.create(M.MethodType.POST,e,r)}static create(e,r,n){return{header:{path:se.parsePath(r),methodType:e},payload:n||new Uint8Array(0)}}static validateId(e){if(e<0||e>se.MAX_ID)throw new Error(`Invalid identifier "${e}". It must be a number between ${e} and ${se.MAX_ID}`);return e}};se.MAX_ID=65535;var ye=se;(e=>e.PATH_EXPRESSION=/^\/?([0-9]+)\/([0-9]+)?\/([0-9]+)\/?([0-9]+)?$/)(ye||(ye={}));var rr=class t{static toString(e,r){let n=`${M.MethodType[e.header.methodType]} ${t.pathToString(e.header.path,r)}`;return e.payload&&e.payload.length>0&&(n+=` 0x${U(e.payload)}`),n}static pathToString(e,r){let n=e.resourceInstanceId;return"/"+e.objectId+"/"+(e.objectInstanceId===ye.MAX_ID?r!=null&&r.printMaxId?e.objectInstanceId:"":e.objectInstanceId)+"/"+e.resourceId+(n?"/"+n:"")}};var j=class t extends re{constructor(r,n,i){super(n,r);this.cause=i}static illegalArgument(r){return new t(t.Code.IllegalArgumentError,r)}static illegalStateError(r){return new t(t.Code.IllegalStateError,r)}static encodeRequestError(r,n){return new t(t.Code.EncodeRequestError,"Cannot encode this request: "+r+". Cause: "+n,n)}static decodeResponseError(r,n){return new t(t.Code.DecodeResponseError,`Cannot decode response to command ${n instanceof Uint8Array?`0x${U(n)}`:rr.toString(n)}. Cause: `+r,r)}static notConnectedError(){return new t(t.Code.NotConnectedError,"Trying to execute command but device is not connected")}static cannotDecodeResponseError(r,n){return new t(t.Code.UnexpectedTapResponse,`Received from device an unexpected response that cannot be decoded (${r.message}). Frame: 0x${U(n)}`)}static unexpectedApduStatusCode(r){return new t(t.Code.UnexpectedApduResponseStatus,`Received from device an unexpected response with an invalid APDU status code 0x${r.status.toString(16)}
4
+ but expecting 0x${Pe.Status.OK.toString(16)}`)}static cannotEncodeRequest(r,n){return new t(t.Code.CannotEncodeRequest,`Cannot encode request ${n}: ${r.message}`)}};(e=>{let t;(d=>(d.NotConnectedError="TapClientErrorNotConnected",d.EncodeRequestError="TapClientErrorEncodeRequest",d.IllegalArgumentError="TapClientErrorIllegalArgument",d.IllegalStateError="TapClientErrorIllegalState",d.DecodeResponseError="TapClientErrorDecodeResponse",d.UnexpectedTapResponse="TapClientErrorUnexpectedTapResponse",d.UnexpectedApduResponseStatus="TapClientErrorUnexpectedApduResponseStatus",d.CannotEncodeRequest="TapClientErrorCannotEncodeRequest",d.TapClientResponseStatusError="TapClientErrorResponseStatus"))(t=e.Code||(e.Code={}))})(j||(j={}));var nt=class{encode(e){try{let r=new T(6+e.payload.length+1);return r.writeApduRequest(kt(e)),r.toBytes}catch(r){throw r instanceof j?r:j.cannotEncodeRequest(r,e)}}decode(e){let r=e instanceof w?e:w.create(e),n=r.readApduRequestHeader();return r.readTapRequestFrame()}},it=class{encode(e){let r=new T,n=new T;return n.writeTapResponseFrame(e),r.writeApduResponse({data:n.toBytes,status:Pe.Status.OK}),r.toBytes}decode(e){try{let n=(e instanceof w?e:w.create(e)).readApduResponse();if(n.status!==Pe.Status.OK)throw j.unexpectedApduStatusCode(n);return w.fromArray(n.data).readTapResponseFrame()}catch(r){throw r instanceof j?r:j.cannotDecodeResponseError(r,e instanceof w?e.toBytes:e)}}},ri=new nt,ti=new it;var ce=class ce{constructor(e=1){this._mask=e}decode(e){var r=Y.fromBytes(e,e.length,!1,ce.IS_LEAST_SIGNIFICANT_BIT_FIRST);return ce.decodeFromNumber(this._mask,r)}encode(e){return Uint8Array.from([e?this._mask:0])}static decodeFromNumber(e,r){return e==0&&r==0||(r&e)!=0}static instanceBit0(){return ce._instance||(ce._instance=new ce(1)),ce._instance}};ce.IS_LEAST_SIGNIFICANT_BIT_FIRST=!0,ce._instance=void 0;var Dt=ce;var ue=class ue{constructor(e){this.options=e}encode(e){return Y.toOpaqueMsb(ue.toArray(e),32)}decode(e){return ue.toFloat(e)}static toArray(e){var s=+e,r=s!==s||s==-1/0||s==1/0?s:0,n=0,i=281,o=new Array(i),a=(s=r!==0?0:s)<0,s=Math.abs(s),u=Math.floor(s),l=s-u,p,d,h,c,f;if(r!==0){if(s!==s)return 2143289344;if(s===1/0)return 2139095040;if(s===-1/0)return 4286578688}for(p=i;p;)o[--p]=0;for(p=129;u&&p;)o[--p]=u%2,u=Math.floor(u/2);for(p=128;l>0&&p;)(o[++p]=(l*=2)>=1?1:0)&&--l;for(p=-1;++p<i&&!o[p];);if(o[(d=22+(p=(n=128-p)>=-126&&n<=127?p+1:128-(n=-127)))+1]){if(!(h=o[d]))for(c=d+2;!h&&c<i;)h=o[c++];for(c=d+1;h&&--c>=0;)(o[c]=!o[c]-0)&&(h=0)}for(p=p-2<0?-1:p-3;++p<i&&!o[p];);for((n=128-p)>=-126&&n<=127?++p:n<-126&&(p=255,n=-127),(u||r!==0)&&(n=128,p=129,r==-1/0?a=!0:r!==r&&(o[p]=1)),s=Math.abs(n+127),f=0,c=0;c<8;)f+=s%2<<c,s>>=1,c++;var b=0;for(s=p+23;p<s;p++)b=(b<<1)+o[p];return(a?2147483648:0)+(f<<23)+b|0}static toFloat(e){return ue.numberToFloat(Y.fromOpaqueMsb(e,32))}static numberToFloat(e){var r=1*e,n=r&2147483648?-1:1,i=(r&2139095040)>>23,o=r&8388607;o|=8388608;var a=1*(n*o*Math.pow(2,i-150));return parseFloat(a.toFixed(5))}static instance32(){return ue._instance32||(ue._instance32=new ue),ue._instance32}};ue._instance32=void 0;var Nt=ue;var Fe=class Fe{decode(e){return U(e)}encode(e){if(!e||e.length==0)return new Uint8Array(0);e.length%2>0&&(e="0"+e);for(var r=[],n=0,i=e.length;n<i;n+=2)r.push(parseInt(e.substr(n,2),16));return new Uint8Array(r)}static instance(){return Fe._instance||(Fe._instance=new Fe),Fe._instance}};Fe._instance=void 0;var qt=Fe;var Le=class Le{decode(e){if(e==null||e.length!=4)throw k.unexpectedBufferSize(4,e);var r="",n=Array.from(e);for(var i of n)r+=i.toString()+".";return r.substr(0,r.length-1)}encode(e){var r=e.split(".");if(r.length!=4)throw new Error("Invalid ip format. Should be x.x.x.x");var n=new Uint8Array(4);return r.map((i,o)=>{n[o]=parseInt(i)&255}),n}static instance(){return Le._instance||(Le._instance=new Le),Le._instance}};Le._instance=void 0;var Mt=Le;var zt=6,ke=class ke{decode(e){if(!e||e.length!==zt)throw k.unexpectedBufferSize(zt,e);let r="";for(var n=e.length-1;n>=0;n--){let i=e.slice(n,n+1);r+=U(i).toUpperCase()+":"}return r.substring(0,r.length-1)}encode(e){let r=e.split(":").map(n=>parseInt(n,16)&255).reverse();if(r.length!==zt)throw new Error("Invalid mac address format: "+e);return Uint8Array.from(r)}static instance(){return ke._instance||(ke._instance=new ke),ke._instance}};ke._instance=void 0;var $t=ke;var Wt=xr(Zr()),De=class De{constructor(e="ascii",r={stripEndOfStringCharacter:!0,replaceEmptyStringWithEndOfLineChar:!1,addEndOfStringCharacter:!1}){this.encoding=e;this.options=r}encode(e){if(typeof e=="number"&&(e=e.toString()),typeof e!="string"&&(e=""),this.options.addEndOfStringCharacter)e+="\0";else if(!e&&this.options.replaceEmptyStringWithEndOfLineChar)return Uint8Array.from([0]);let r=Wt.Buffer.from(e,this.encoding);return Uint8Array.from(r)}decode(e){let r=Wt.Buffer.from(e).toString(this.encoding);if(this.options.stripEndOfStringCharacter){let n=r.indexOf("\0");n>=0&&(r=r.substring(0,n))}return r}static ascii(){return De._ascii||(De._ascii=new De("ascii",{replaceEmptyStringWithEndOfLineChar:!0,stripEndOfStringCharacter:!0})),De._ascii}};De._ascii=void 0;var jt=De;var tr=xr(Zr());var Po="@iotize/common:tlv",ni=(0,$.default)(Po);var Fo="TLV",ot;(d=>{let t={String:function(h,c,f){return h.toString("utf8",c,c+f)},Integer:function(h,c,f){return h.readIntBE(c,f)},Float:function(h,c,f){switch(f){case 4:return h.readFloatBE(c);case 8:return h.readDoubleBE(c);default:throw new Error(`Invalid length for float: ${f}`)}},Boolean:function(h,c,f){return!!h.readUInt8(c)},Opaque:function(h,c,f){if(h.length<c+f)throw new Error(`Buffer too small. Expecting ${f} bytes but only ${h.length-c} avaiable(s). Offset of ${c}`);let b=tr.Buffer.alloc(f);return h.copy(b,0,c,c+f),b},Time:function(h,c,f){let b=h.readIntBE(c,f);return new Date(b*1e3)}},e;(C=>(C.String="String",C.Integer="Integer",C.Float="Float",C.Boolean="Boolean",C.Opaque="Opaque",C.Time="Time",C.Array="Array"))(e=d.DataType||(d.DataType={}));let r;(y=>(y[y.OBJECT_INSTANCE=0]="OBJECT_INSTANCE",y[y.RESOURCE_INSTANCE=1]="RESOURCE_INSTANCE",y[y.MULTIPLE_RESOURCE=2]="MULTIPLE_RESOURCE",y[y.RESOURCE_VALUE=3]="RESOURCE_VALUE"))(r=d.IdentifierType||(d.IdentifierType={}));function n(h,c,f){let b=h<<6;return c>255&&(b|=32),f<8?b|=f:b|=p(f)<<3,b}d.tlvType=n;class i{constructor(c){if(this.position=0,this.schema=c,this.schema)throw new Error("Schema are not supported yet")}readHeader(){let c,f,b=this.buffer.readUInt8(this.position);this.position+=1;let y=b>>>6;if(b&32?(c=this.buffer.readUInt16BE(this.position),this.position+=2):(c=this.buffer.readUInt8(this.position),this.position+=1),f=b&7,!f)switch((b&24)>>>3){case 1:f=this.buffer.readUInt8(this.position),this.position+=1;break;case 2:f=this.buffer.readUInt16BE(this.position),this.position+=2;break;case 3:f=this.buffer.readUInt16BE(this.position),f=this.buffer.readUInt8(this.position),this.position+=3;break}let x={id:c,type:y,len:f};return this.debug(" -Found header: ",x),x}readNextRecord(){let c=this.readHeader(),f=c.id.toString();if(c.type===3||c.type===1){this.debug(" -Resource value readRecords with",c);let b=tr.Buffer.alloc(c.len);return this.buffer.copy(b,0,this.position,this.position+c.len),this.position+=c.len,{header:c,payload:b}}else{this.debug(` -Multiple resources found! readRecords with key ${f}`);let b=this.readAllRecords(this.position+c.len);return{header:c,children:b}}}append(c,f){if(this.debug(` -Append ${f} header=`,c),!(f in t))throw new Error(`Decoder type ${f} not found`);let b=t[f](this.buffer,this.position,c.len);return this.debug(" -Appending value",b),this.position+=c.len,b}readAllRecords(c){let f=[];for(this.debug(`Parsing records until position ${c}`);this.position<c;)f.push(this.readNextRecord());return f}parse(c){return this.position=0,this.buffer=tr.Buffer.from(Ye(c)),this.readNextRecord()}debug(...c){ni(Fo,...c,`[pos=${this.position}/${this.buffer.length-1}, remaining buffer=${U(this.buffer.slice(this.position))}]`)}}d.Parser=i;class o{serialize(c,f){if(f=f||new Ze,this.writeHeader(f,c.header.type,c.header.id,c.header.len),c.payload&&f.writeBytes(c.payload),c.children)for(let b of c.children)this.serialize(b,f);return f.toBytes}writeHeader(c,f,b,y){let x=n(f,b,y);if(c.writeU(x,1),x&32?c.writeU(b,2):c.writeU(b,1),x&24)switch(p(y)){case 3:c.writeU(y>>>16&255,1);case 2:c.writeU(y>>>8&255,1);case 1:c.writeU(y&255,1);break;default:throw new Error("Invalid resource `"+b+"`")}}serializeObj(c,f){let b=tr.Buffer.alloc(16384),y=Object.keys(c);f&&f.validate(c);let x=0;for(let R=0;R<y.length;++R){let C=y[R];!f||!f.resources[C]||(x=u(c,b,x,C))}return b.slice(0,x)}}d.Serializer=o;function a(h,c,f,b,y){let x=n(f,b,y);if(h.writeUInt8(x,c),c+=1,x&32?(h.writeUInt16BE(b,c),c+=2):(h.writeUInt8(b,c),c+=1),x&24)switch(p(y)){case 3:h.writeUInt8(y>>>16&255,c),c+=1;case 2:h.writeUInt8(y>>>8&255,c),c+=1;case 1:h.writeUInt8(y&255,c),c+=1;break;default:throw new Error("Invalid resource `"+b+"`")}return c}function s(h,c,f,b,y){let x={String:function(){return h.write(b,c,h.length-c,"utf8"),c+=f},Integer:function(){return h.writeIntBE(b,c,f),c+=f},Float:function(){return h.writeDoubleBE(b,c),c+=f},Boolean:function(){return h.writeInt8(b,c),c+=f},Opaque:function(){return b.copy(h,c),c+=f},Time:function(){let R=b.getTime()/1e3>>0;return h.writeIntBE(R,c,f),c+=f},Array:function(){return c}};return y&&y in x?x[y]():c}function u(h,c,f,b,y){if(!y)return f;let x=y.resources[b];if(!x)return f;let R=h[b],C;if(x&&Array.isArray(x.type)){let Q=tr.Buffer.alloc(1024),z=0;R.forEach(function(X,ut){C=p(X),z=a(Q,z,1,ut,C),z=s(Q,z,C,X,x.type[0])}),f=a(c,f,2,parseInt(x.id,10),z),Q.copy(c,f,0,z),f+=z}else C=p(R),f=a(c,f,3,parseInt(x.id,10),C),f=s(c,f,C,R,x.type);return f}function l(h){return h<2?1:Math.ceil(Math.log(h)*Math.LOG2E/8)}function p(h){function c(b){let y=l(b);return y--,y|=y>>>1,y|=y>>>2,y++,y}switch(Object.prototype.toString.call(h).slice(8,-1)){case"Number":return h%1===0?c(h):8;case"String":case"Uint8Array":case"Buffer":return h.length;case"Boolean":return 1;case"Date":return c(h.getTime()/1e3>>0);default:return 0}}})(ot||(ot={}));var Ne=class{static compute(e){let r=0;for(let n=0;n<e.length;n++)r=r+e[n];return r}};var mr=class{constructor(e){this.bufferOffset=0,this.dataLength=0,this.data=new Uint8Array(e),this.reset()}append(e){if(!(!e||e.length<2)){if(this.bufferOffset=(e[0]&255)-1,this.bufferOffset+e.length>this.data.length)throw new Error(`Buffer size exceeded. Maximum size is ${this.data.length} byte(s).`);for(let r=1;r<e.length;r++)this.data[this.bufferOffset+r]=e[r];this.dataLength+=e.length-1}}reset(){this.dataLength=0,this.bufferOffset=0}hasAllChunks(){return this.bufferOffset===-1}isChecksumValid(){let e=this.getComputedChecksum();return this.getExpectedChecksum()===e}getComputedChecksum(){return Ne.compute(this.data.subarray(0,this.dataLength-1))&255}getExpectedChecksum(){return this.data[this.dataLength-1]}getData(){return this.data.slice(0,this.dataLength-1)}getBuffer(){return this.data}};var dr=class t{constructor(e,r){if(this.lastPacketSize=0,this.maxPacketSize=0,this.currentPacketIndex=0,r<1)throw new Error("Packet size must be greater than 0");this.data=e,this.maxPacketSize=r,this.currentPacketIndex=this.getTotalNumberOfPacket()-1,this.lastPacketSize=this.getLastPacketSize()}static wrapWithChecksum(e,r){var n=t.computeChecksum(e),i=new Uint8Array(e.length+1);return i.set(e),i.set([n&255],e.length),new t(i,r)}getTotalNumberOfPacket(){return(this.data.length/this.maxPacketSize|0)+(this.data.length%this.maxPacketSize===0?0:1)}getLastPacketSize(){let e=this.data.length%this.maxPacketSize;return e===0&&(e=this.maxPacketSize),e}getPackets(){let e=[];for(;this.hasNextPacket();)e.push(this.getNextPacket());return e}getNextPacket(){let e,r;this.currentPacketIndex>0?(r=this.lastPacketSize+(this.currentPacketIndex-1)*this.maxPacketSize,e=this.maxPacketSize):(r=0,e=this.lastPacketSize);let n=new Uint8Array(e+1);n[0]=r|0;for(let i=0;i<e;i++)n[i+1]=this.data[r+i];return this.currentPacketIndex--,n}hasNextPacket(){return this.currentPacketIndex>=0}static computeChecksum(e){return Ne.compute(e)&255}getTotalSize(){return this.data.length}};var Do="@iotize/tap/protocol/ble",xe=(0,$.default)(Do);var V=class t extends re{static invalidBleChunkChecksum(e){return hr.create(e)}static writeSizeAboveMTU(e,r){return new t(t.Code.BleWriteSizeAboveMTU,`Cannot write ${e.length} bytes as it's more than the Maximal Transfert Unit (${r})`)}static serviceNotFound(e){return new t(t.Code.BleGattServiceNotFound,`Bluetooth service with id ${e} not found`)}static charcacteristicNotFound(e){return new t(t.Code.BleGattCharacteristicNotFound,`Bluetooth characteristic with id ${e} not found`)}static bleNotAvailable(e="BLE is not available on your device"){return new t(t.Code.NotAvailable,e)}static gattServerNotAvailable(){return new t(t.Code.GATTServerNotAvailable,"Generic Attribute Profile (GATT) server is not available")}static gattServerConnectionFailed(){return new t(t.Code.GATTServerConnectionFailed,"Gatt server connection failed")}constructor(e,r){super(r,e)}},hr=class t extends V{constructor(r){super(V.Code.InvalidChecksum,"Invalid checksum");this.packetBuilder=r}static create(r){return new t(r)}};(e=>{let t;(l=>(l.InvalidChecksum="InvalidChecksum",l.BleGattServiceNotFound="BleGattServiceNotFound",l.BleGattCharacteristicNotFound="BleGattCharacteristicNotFound",l.BleWriteSizeAboveMTU="BleWriteSizeAboveMTU",l.GATTServerNotAvailable="BleComErrorGATTServerNotAvailable",l.GATTServerConnectionFailed="BleComErrorGATTServerConnectionFailed",l.NotAvailable="BleComErrorNotAvailable"))(t=e.Code||(e.Code={}))})(V||(V={}));var at=class at extends Ie{constructor(r={mtu:Et.maxPacketLengthWithoutOffset+1}){super();this.bleOptions=r}onNewLwm2mMessage(r){this._readResolve?(xe("onNewLwm2mMessage()",U(r)),this._readResolve(r)):(console.warn(`No listener for new message... 0x${U(r)}`),this._pendingRead=r)}onNewLwm2mMessageError(r){console.error("Error lwm2m response...",r)}onLwm2mDataChunkError(r){this._readReject?this._readReject(r):console.warn("No listener for read message error...",r)}getLwm2mResponsePromise(){if(xe("getLwm2mResponsePromise"),this._pendingRead){let r=this._pendingRead;return this._pendingRead=void 0,Promise.resolve(r)}return this._readPromise||this.createLwm2mResponsePromise(),this._readPromise}createLwm2mResponsePromise(){return xe("createLwm2mResponsePromise"),this._readPromise=new Promise((r,n)=>{this._readResolve=r,this._readReject=n}),this._readPromise}read(){if(xe("read()..."),this.packetBuilder){if(this.packetBuilder.hasAllChunks()){let r=this.packetBuilder.getData();return this.packetBuilder=void 0,Promise.resolve(r)}console.warn("AbstractBleProtocol::read() There is already a read operation in progress but a new call to ::read has been made.")}return this.getLwm2mResponsePromise().then(r=>(this.packetBuilder=void 0,r)).catch(r=>{throw this.packetBuilder=void 0,r})}async write(r){this.packetSplitter!=null&&console.warn("BLEProtocol","write","There are already data being sent but a new call to ::write has been made"),this.packetSplitter=dr.wrapWithChecksum(r,this.bleOptions.mtu-1);let n=this.packetSplitter.getPackets(),i;return this._pendingRead=void 0,this.packetBuilder=new mr(at.RECEIVED_BUFFER_LENGTH),n.length>0?i=Vr(n,(o,a)=>this.writeLwm2mPacketChunk(o).then(s=>(xe(`Done sending packet ${a+1}/${n.length}`),s))):(console.warn("BLEProtocol","write","Nothing to write..."),i=Promise.resolve()),i.then(()=>{this.packetSplitter=void 0}).catch(o=>{throw this.packetSplitter=void 0,o})}onNewLwm2mPacket(r){if(!this.packetBuilder){xe(`Ignoring lwm2m packet 0x${U(r)} as not request has been made yet`);return}if(this.packetBuilder.append(r),this.packetBuilder.hasAllChunks())if(this.packetBuilder.isChecksumValid())this.onNewLwm2mMessage(this.packetBuilder.getData());else{let n=hr.create(this.packetBuilder);this.onLwm2mDataChunkError(n)}}};at.RECEIVED_BUFFER_LENGTH=255;var ii=at;var st=class{constructor(e,r=be()){this.deviceId=e;this.cordovaPlugin=r;this._stateChange=new je(0)}get stateChange(){return this._stateChange.asObservable().pipe(xt())}get name(){return this.id}get id(){return this.deviceId}get state(){return D[this._stateChange.value]}async discoverServices(e){this.serviceListCache=await this.cordovaPlugin.discoverServices(this.deviceId);let r={};if(e)for(let n of e){let i=this.serviceListCache.find(o=>o.uuid===n);i&&(r[n]=new qe(i,this))}else for(let n of this.serviceListCache)r[n.uuid]=new qe(n,this);return r}async connect(){var r;(r=this.connectionStateSubscription)==null||r.unsubscribe();let e=this.cordovaPlugin.connect(this.deviceId).pipe(gt());this.connectionStateSubscription=e.subscribe(n=>{this._stateChange.next(n)}),await e.pipe(Ce(n=>n===2),sr()).toPromise()}async disconnect(){var e;await this.cordovaPlugin.disConnect(this.deviceId),this._stateChange.next(0),(e=this.connectionStateSubscription)==null||e.unsubscribe()}async close(){var e;await this.cordovaPlugin.close(this.deviceId),this._stateChange.next(0),(e=this.connectionStateSubscription)==null||e.unsubscribe()}async getService(e){this.serviceListCache||await this.discoverServices([e]);let r=this.serviceListCache.find(n=>n.uuid===e);if(!r)throw V.serviceNotFound(e);return new qe(r,this)}},qe=class{constructor(e,r){this.config=e;this.peripheral=r}get uuid(){return this.config.uuid}async getCharacteristic(e){var n;let r=(n=this.config.characteristics)==null?void 0:n.find(i=>i.uuid===e);if(!r)throw V.charcacteristicNotFound(e);return new nr(this,r)}async getCharacteristics(){return this.config.characteristics?this.config.characteristics.map(e=>new nr(this,e)):[]}},nr=class{constructor(e,r){this.service=e;this.config=r}get uuid(){return this.config.uuid}get properties(){return this.config.properties}get data(){return this.setupDataStreamIfRequired().pipe(Te(e=>({data:e,isNotification:!0})))}get deviceId(){return this.service.peripheral.deviceId}get pluginInterface(){return this.service.peripheral.cordovaPlugin}async read(){return this.pluginInterface.characteristicReadValue(this.deviceId,this.service.uuid,this.uuid)}async getDescriptor(){throw new Error("Not implemented yet")}async getDescriptors(){return this.config.descriptors?this.config.descriptors.map(e=>new Vt(e,this)):[]}async write(e,r){return r?await this.pluginInterface.characteristicWriteWithoutResponse(this.deviceId,this.service.uuid,this.uuid,e):await this.pluginInterface.characteristicWrite(this.deviceId,this.service.uuid,this.uuid,e),e}async enableNotifications(e){e?(this.setupDataStreamIfRequired(),await this.pluginInterface.characteristicStartNotification(this.deviceId,this.service.uuid,this.uuid)):await this.pluginInterface.characteristicStopNotification(this.deviceId,this.service.uuid,this.uuid)}setupDataStreamIfRequired(){return this._dataStream||(this._dataStream=this.pluginInterface.characteristicChanged(this.deviceId,this.service.uuid,this.uuid)),this._dataStream}},Vt=class{constructor(e,r){this.config=e;this.characteristic=r}get uuid(){return this.config.uuid}async readValue(){throw new Error("Reading descriptor value is not implemented yet")}async writeValue(e){throw new Error("Writing descriptor value is not implemented yet")}};var ct=class{constructor(e,r){this.cordovaInterfaceOverwrite=e;this.requestDeviceOptions=r;this._results=new je([]);this._scanning$=new je(!1)}get cordovaInterface(){return this.cordovaInterfaceOverwrite||be()}get scanning(){return this._scanning$.asObservable()}get isScanning(){return this._scanning$.value}get results(){return this._results.asObservable()}async start(e){var n;if((n=this.scanSubscription)==null||n.unsubscribe(),this.scanSubscription=void 0,this.clearResults(),!await this.checkAvailable())throw V.bleNotAvailable("BLE is not available. Make sure that BLE is enabled on your device");return te("Start Scanning ..."),this._scanning$.next(!0),new Promise((i,o)=>{this.scanSubscription=this.cordovaInterface.startScan(this.requestDeviceOptions).subscribe(a=>{if(a=="Ok"){i();return}this.addOrRefreshDevice(a)},a=>{te("Start scan failed with error: ",a),this.cordovaInterface.getLastError().then(s=>{te("Last BLE error "+s)}).catch(s=>{te("Cannot get last BLE error: ",s)}),o(a),this._scanning$.next(!1)})})}async stop(){var e;te("Stop Scanning ...");try{(e=this.scanSubscription)==null||e.unsubscribe(),this.scanSubscription=void 0,await this.cordovaInterface.stopScan(),this._scanning$.next(!1);return}catch(r){throw this._scanning$.next(!1),r}}checkAvailable(){return this.cordovaInterface.checkAvailable()}get devices(){return this._results.value}clearResults(){this._results.next([])}addOrRefreshDevice(e){let r=this.devices.findIndex(n=>n.address==e.address);if(r>=0){let n=this.devices[r];(n.name!=e.name||n.rssi!=e.rssi)&&(te(`Updating device at index ${r}, name=${n.name} with rssi=${n.rssi}`),this.devices[r]=e,this._results.next(this.devices))}else te(`Adding new device name=${e.name} with rssi=${e.rssi}`),this.devices.push(e),this._results.next(this.devices)}};function Gt(t,e){if(!(e in t))throw new Error(`Enum key "${e==null?void 0:e.toString()}" does not exist`);return t[e]}function Ht(t){try{return kn(t)}catch(e){throw L.invalidNativeCallResult(t,e)}}var br=class{checkAvailable(){return this.execSingleResult("checkAvailable",[])}requestEnableBle(){return this.execSingleResult("enable",[])}startScan(e){return this.execMultipleResult("startScan",[JSON.stringify(e)])}stopScan(){return this.execSingleResult("stopScan",[])}connect(e,r=!0){return this.askBleEnable(r).pipe(Ve(()=>this.execMultipleResult("connect",[e]).pipe(Te(n=>(n in D||console.warn(`Plugin native code returned an invalid connection state: "${n}".`),Gt(D,n))))))}askBleEnable(e){return ne(async()=>{e&&(await this.checkAvailable()||await this.requestEnableBle())})}requestMTU(e,r){return this.execSingleResult("requestMTU",[e,r])}connectAndDiscoverTapServices(e,r=!0){return this.askBleEnable(r).pipe(Ve(()=>this.execMultipleResult("connectAndDiscoverTapServices",[e]).pipe(Te(n=>(n in D||console.warn(`Plugin native code returned an invalid connection state: "${n}".`),Gt(D,n))))))}disConnect(e){return this.execSingleResult("disConnect",[e])}close(e){return this.execSingleResult("close",[e])}isConnected(e){return this.execSingleResult("isConnected",[e])}async send(e,r){let n=await this.execSingleResult("sendRequest",[e,U(r)]);return Ht(n)}getLastError(){return this.execSingleResult("getLastError",[])}characteristicStartNotification(e,r,n){return this.execSingleResult("characteristicStartNotification",[e,r,n])}characteristicChanged(e,r,n){return this.execMultipleResult("characteristicChanged",[e,r,n]).pipe(Te(i=>Ht(i)))}characteristicStopNotification(e,r,n){return this.execSingleResult("characteristicStopNotification",[e,r,n])}async characteristicReadValue(e,r,n){let i=await this.execSingleResult("characteristicRead",[e,r,n]);return Ht(i)}characteristicWrite(e,r,n,i){return this.execSingleResult("characteristicWrite",[e,r,n,U(i)])}characteristicWriteWithoutResponse(e,r,n,i){return this.execSingleResult("characteristicWriteWithoutResponse",[e,r,n,U(i)])}async discoverServices(e){return await this.execSingleResult("discoverServices",[e])}execSingleResult(e,r){return new Promise((n,i)=>{cordova.exec(n,o=>{i(oi(o))},"BLECom",e,r)})}execMultipleResult(e,r){let n=new B;return cordova.exec(i=>{n.next(i)},i=>{n.error(oi(i))},"BLECom",e,r),n.asObservable()}};function oi(t){return typeof t!="object"||!t.code||!t.message?L.invalidErrorResult(t):L.isValidErrorCode(t.code)?new L(t.message,L.Code[t.code]):L.invalidErrorCode(t)}var ai=new br;window.iotizeBLE=ai;
5
+ /**
6
+ * KaitaiStream is an implementation of Kaitai Struct API for JavaScript.
7
+ *
8
+ * It's based on KaitaiStream.js - https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/master/KaitaiStream.js that comes with the following license
9
+ *
10
+ * @license Copyright 2012-2016 Ilmari Heikkinen Copyright 2016-2020 Kaitai Project licensed under Apache License, Version 2.0 (the "License");
11
+ *
12
+ * Implementation has been translated to Typescript and modified to fit our needs
13
+ */
14
+ /**
15
+ * KaitaiStreamReader is an implementation of Kaitai Struct API for JavaScript.
16
+ *
17
+ * Some functions are based on KaitaiStream.js - https://github.com/kaitai-io/kaitai_struct_javascript_runtime/blob/master/KaitaiStream.js that comes with the following license
18
+ *
19
+ * @license Copyright 2012-2016 Ilmari Heikkinen Copyright 2016-2020 Kaitai Project licensed under Apache License, Version 2.0 (the "License");
20
+ *
21
+ * Implementation has been translated to Typescript and modified to fit our needs
22
+ */
23
+ /*! Bundled license information:
24
+
25
+ ieee754/index.js:
26
+ (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
27
+
28
+ buffer/index.js:
29
+ (*!
30
+ * The buffer module from node.js, for the browser.
31
+ *
32
+ * @author Feross Aboukhadijeh <https://feross.org>
33
+ * @license MIT
34
+ *)
35
+ */