sshclient-wasm 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ [{"name":"metadata.json","path":"dist/metadata.json","internal_type":35,"type":"Metadata"},{"name":"sshclient.wasm","path":"dist/sshclient.wasm","goos":"js","goarch":"wasm","target":"js_wasm","internal_type":4,"type":"Binary","extra":{"Binary":"sshclient","Builder":"go","Ext":".wasm","ID":"sshclient"}}]
@@ -0,0 +1,95 @@
1
+ import { Transport } from './transport';
2
+ import * as protobuf from "./aws-iot-tunnel/protobuf-messages";
3
+ export type TunnelMessage = protobuf.com.amazonaws.iot.securedtunneling.IProtocolV1Message | protobuf.com.amazonaws.iot.securedtunneling.IProtocolV2Message | protobuf.com.amazonaws.iot.securedtunneling.IProtocolV3Message;
4
+ export declare const TunnelMessageType: {
5
+ readonly UNKNOWN: 0;
6
+ readonly DATA: 1;
7
+ readonly STREAM_START: 2;
8
+ readonly STREAM_RESET: 3;
9
+ readonly SESSION_RESET: 4;
10
+ readonly SERVICE_IDS: 5;
11
+ readonly CONNECTION_START: 6;
12
+ readonly CONNECTION_RESET: 7;
13
+ };
14
+ export type TunnelMessageTypeEnum = (typeof TunnelMessageType)[keyof typeof TunnelMessageType];
15
+ export interface SecureTunnelConfig {
16
+ region: string;
17
+ accessToken: string;
18
+ clientMode: "source" | "destination";
19
+ serviceId?: string;
20
+ protocol?: "V1" | "V2" | "V3";
21
+ }
22
+ /**
23
+ * AWS IoT Secure Tunnel Transport implementation
24
+ * Handles the WebSocket connection to AWS IoT Secure Tunneling service
25
+ * and manages the protocol-specific message framing
26
+ */
27
+ export declare class SecureTunnelTransport implements Transport {
28
+ private ws;
29
+ private config;
30
+ private streamId;
31
+ private connectionId;
32
+ private isConnected;
33
+ private tunnelReady;
34
+ private messageQueue;
35
+ private receiveBuffer;
36
+ private messageClass;
37
+ id: string;
38
+ onData?: (data: Uint8Array) => void;
39
+ onError?: (error: Error) => void;
40
+ onClose?: () => void;
41
+ constructor(id: string, config: SecureTunnelConfig);
42
+ /**
43
+ * Connect to AWS IoT Secure Tunnel WebSocket endpoint
44
+ */
45
+ connect(): Promise<void>;
46
+ /**
47
+ * Disconnect from the tunnel
48
+ */
49
+ disconnect(): Promise<void>;
50
+ /**
51
+ * Send data through the tunnel
52
+ */
53
+ send(data: Uint8Array): Promise<void>;
54
+ /**
55
+ * Process queued messages once tunnel is ready
56
+ */
57
+ private processQueuedMessages;
58
+ /**
59
+ * Build the WebSocket URL for AWS IoT Secure Tunneling
60
+ */
61
+ private buildWebSocketUrl;
62
+ /**
63
+ * Send a control message through the tunnel
64
+ */
65
+ private sendControlMessage;
66
+ /**
67
+ * Send a data frame through the tunnel
68
+ */
69
+ private sendDataFrame;
70
+ /**
71
+ * Send a frame with length prefix
72
+ */
73
+ private sendFrame;
74
+ /**
75
+ * Handle incoming WebSocket data
76
+ */
77
+ private handleIncomingData;
78
+ /**
79
+ * Handle a decoded tunnel message
80
+ */
81
+ private handleMessage;
82
+ /**
83
+ * Encode a message using protobufjs
84
+ */
85
+ private encodeMessage;
86
+ /**
87
+ * Decode a message using protobufjs
88
+ */
89
+ private decodeMessage;
90
+ /**
91
+ * Get message type name for logging
92
+ */
93
+ private getMessageTypeName;
94
+ }
95
+ //# sourceMappingURL=aws-iot-tunnel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-iot-tunnel.d.ts","sourceRoot":"","sources":["../lib/aws-iot-tunnel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAW/D,MAAM,MAAM,aAAa,GACrB,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,kBAAkB,GAC9D,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,kBAAkB,GAC9D,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,kBAAkB,CAAC;AAGnE,eAAO,MAAM,iBAAiB;;;;;;;;;CASpB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAC/B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAG7D,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,QAAQ,GAAG,aAAa,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,SAAS;IACrD,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,YAAY,CAGS;IAEtB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;gBAEhB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB;IAuBlD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAoF9B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAcjC;;OAEG;IACG,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB3C;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAU7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAwBzB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAqCrB;;OAEG;IACH,OAAO,CAAC,SAAS;IA4BjB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA2C1B;;OAEG;IACH,OAAO,CAAC,aAAa;IAwErB;;OAEG;IACH,OAAO,CAAC,aAAa;IASrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAa3B"}
@@ -0,0 +1,145 @@
1
+ version: 2
2
+ project_name: sshclient-wasm
3
+ release:
4
+ github:
5
+ owner: VerdigrisTech
6
+ name: sshclient-wasm
7
+ prerelease: auto
8
+ name_template: '{{.Tag}}'
9
+ builds:
10
+ - id: sshclient
11
+ goos:
12
+ - js
13
+ goarch:
14
+ - wasm
15
+ goamd64:
16
+ - v1
17
+ go386:
18
+ - sse2
19
+ goarm:
20
+ - "6"
21
+ goarm64:
22
+ - v8.0
23
+ gomips:
24
+ - hardfloat
25
+ goppc64:
26
+ - power8
27
+ goriscv64:
28
+ - rva20u64
29
+ targets:
30
+ - js_wasm
31
+ dir: .
32
+ main: ./main.go
33
+ binary: sshclient
34
+ hooks:
35
+ post:
36
+ - cmd: sh -c 'cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" dist/wasm_exec.js'
37
+ - cmd: pnpm build:ts
38
+ builder: go
39
+ tool: go
40
+ command: build
41
+ no_unique_dist_dir: "true"
42
+ ldflags:
43
+ - -s -w
44
+ env:
45
+ - CGO_ENABLED=0
46
+ archives:
47
+ - id: wasm-archive
48
+ builds_info:
49
+ mode: 493
50
+ name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
51
+ formats:
52
+ - tar.gz
53
+ files:
54
+ - src: dist/sshclient.wasm
55
+ - src: dist/wasm_exec.js
56
+ - src: lib/**/*
57
+ - src: package.json
58
+ - src: README.md
59
+ - src: LICENSE
60
+ snapshot:
61
+ version_template: '{{ incpatch .Version }}-next'
62
+ checksum:
63
+ name_template: checksums.txt
64
+ algorithm: sha256
65
+ docker_digest:
66
+ name_template: digests.txt
67
+ changelog:
68
+ disable: "true"
69
+ format: '{{ .SHA }} {{ .Message }}'
70
+ dist: dist
71
+ env_files:
72
+ github_token: ~/.config/goreleaser/github_token
73
+ gitlab_token: ~/.config/goreleaser/gitlab_token
74
+ gitea_token: ~/.config/goreleaser/gitea_token
75
+ before:
76
+ hooks:
77
+ - go mod tidy
78
+ - go mod download
79
+ source:
80
+ name_template: '{{ .ProjectName }}-{{ .Version }}'
81
+ format: tar.gz
82
+ gomod:
83
+ gobinary: go
84
+ announce:
85
+ twitter:
86
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
87
+ mastodon:
88
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
89
+ server: ""
90
+ reddit:
91
+ title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
92
+ url_template: '{{ .ReleaseURL }}'
93
+ slack:
94
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
95
+ username: GoReleaser
96
+ discord:
97
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
98
+ author: GoReleaser
99
+ color: "3888754"
100
+ icon_url: https://goreleaser.com/static/avatar.png
101
+ teams:
102
+ title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
103
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
104
+ color: '#2D313E'
105
+ icon_url: https://goreleaser.com/static/avatar.png
106
+ smtp:
107
+ subject_template: '{{ .ProjectName }} {{ .Tag }} is out!'
108
+ body_template: 'You can view details from: {{ .ReleaseURL }}'
109
+ mattermost:
110
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
111
+ title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
112
+ username: GoReleaser
113
+ linkedin:
114
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
115
+ telegram:
116
+ message_template: '{{ mdv2escape .ProjectName }} {{ mdv2escape .Tag }} is out{{ mdv2escape "!" }} Check it out at {{ mdv2escape .ReleaseURL }}'
117
+ parse_mode: MarkdownV2
118
+ webhook:
119
+ message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}'
120
+ content_type: application/json; charset=utf-8
121
+ expected_status_codes:
122
+ - 200
123
+ - 201
124
+ - 202
125
+ - 204
126
+ opencollective:
127
+ title_template: '{{ .Tag }}'
128
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out!<br/>Check it out at <a href="{{ .ReleaseURL }}">{{ .ReleaseURL }}</a>'
129
+ bluesky:
130
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
131
+ discourse:
132
+ title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
133
+ message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
134
+ username: system
135
+ git:
136
+ tag_sort: -version:refname
137
+ mcp:
138
+ name: ""
139
+ title: ""
140
+ auth:
141
+ type: none
142
+ github_urls:
143
+ download: https://github.com
144
+ gitlab_urls:
145
+ download: https://gitlab.com
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class WebSocketTransport{constructor(t,r,l){this.ws=null,this.callbacks={},this.id=t,this.url=r,this.protocols=l}async connect(){return new Promise((t,r)=>{try{this.ws=new WebSocket(this.url,this.protocols),this.ws.binaryType="arraybuffer",this.ws.onopen=()=>{t()},this.ws.onerror=l=>{const i=new Error("WebSocket error");this.onError&&this.onError(i),r(i)},this.ws.onmessage=l=>{if(l.data instanceof ArrayBuffer){const i=new Uint8Array(l.data);this.onData&&this.onData(i)}},this.ws.onclose=()=>{this.onClose&&this.onClose()}}catch(l){r(l)}})}async disconnect(){this.ws&&(this.ws.close(),this.ws=null)}async send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket is not connected");this.ws.send(t.buffer)}setCallbacks(t){this.callbacks=t}}class CustomTransport{constructor(t,r,l,i){this.isConnected=!1,this.id=t,this.connectImpl=r,this.disconnectImpl=l,this.sendImpl=i}async connect(){this.connectImpl&&await this.connectImpl(),this.isConnected=!0}async disconnect(){this.disconnectImpl&&await this.disconnectImpl(),this.isConnected=!1,this.onClose&&this.onClose()}async send(t){if(!this.isConnected)throw new Error("Transport is not connected");this.sendImpl&&await this.sendImpl(t)}injectData(t){this.onData&&this.onData(t)}}class TransportManager{constructor(){this.transports=new Map}static getInstance(){return TransportManager.instance||(TransportManager.instance=new TransportManager),TransportManager.instance}setWasmInstance(t){this.wasmInstance=t}async createTransport(t){if(!this.wasmInstance)throw new Error("WASM instance not set");console.log("Creating transport with ID:",t.id),console.log("WASM instance available:",!!this.wasmInstance),console.log("WASM createTransport function:",typeof this.wasmInstance.createTransport);const r={onWrite:l=>{t.send(l).catch(i=>{t.onError&&t.onError(i)})},onClose:()=>{t.disconnect().catch(console.error)}};try{const l=this.wasmInstance.createTransport(t.id,r);console.log("WASM createTransport result:",l)}catch(l){throw console.error("Error calling WASM createTransport:",l),l}t.onData=l=>{this.wasmInstance.injectTransportData(t.id,l)},this.transports.set(t.id,t)}async closeTransport(t){const r=this.transports.get(t);r&&(await r.disconnect(),this.wasmInstance&&this.wasmInstance.closeTransport(t),this.transports.delete(t))}getTransport(t){return this.transports.get(t)}}var commonjsGlobal=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},indexMinimal={},minimal$1={},aspromise=asPromise;function asPromise(o,t){for(var r=new Array(arguments.length-1),l=0,i=2,a=!0;i<arguments.length;)r[l++]=arguments[i++];return new Promise(function(n,s){r[l]=function(u){if(a)if(a=!1,u)s(u);else{for(var f=new Array(arguments.length-1),d=0;d<f.length;)f[d++]=arguments[d];n.apply(null,f)}};try{o.apply(t||null,r)}catch(c){a&&(a=!1,s(c))}})}var base64$1={};(function(o){var t=o;t.length=function(n){var s=n.length;if(!s)return 0;for(var c=0;--s%4>1&&n.charAt(s)==="=";)++c;return Math.ceil(n.length*3)/4-c};for(var r=new Array(64),l=new Array(123),i=0;i<64;)l[r[i]=i<26?i+65:i<52?i+71:i<62?i-4:i-59|43]=i++;t.encode=function(n,s,c){for(var u=null,f=[],d=0,p=0,h;s<c;){var y=n[s++];switch(p){case 0:f[d++]=r[y>>2],h=(y&3)<<4,p=1;break;case 1:f[d++]=r[h|y>>4],h=(y&15)<<2,p=2;break;case 2:f[d++]=r[h|y>>6],f[d++]=r[y&63],p=0;break}d>8191&&((u||(u=[])).push(String.fromCharCode.apply(String,f)),d=0)}return p&&(f[d++]=r[h],f[d++]=61,p===1&&(f[d++]=61)),u?(d&&u.push(String.fromCharCode.apply(String,f.slice(0,d))),u.join("")):String.fromCharCode.apply(String,f.slice(0,d))};var a="invalid encoding";t.decode=function(n,s,c){for(var u=c,f=0,d,p=0;p<n.length;){var h=n.charCodeAt(p++);if(h===61&&f>1)break;if((h=l[h])===void 0)throw Error(a);switch(f){case 0:d=h,f=1;break;case 1:s[c++]=d<<2|(h&48)>>4,d=h,f=2;break;case 2:s[c++]=(d&15)<<4|(h&60)>>2,d=h,f=3;break;case 3:s[c++]=(d&3)<<6|h,f=0;break}}if(f===1)throw Error(a);return c-u},t.test=function(n){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(n)}})(base64$1);var eventemitter=EventEmitter;function EventEmitter(){this._listeners={}}EventEmitter.prototype.on=function(t,r,l){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:r,ctx:l||this}),this};EventEmitter.prototype.off=function(t,r){if(t===void 0)this._listeners={};else if(r===void 0)this._listeners[t]=[];else for(var l=this._listeners[t],i=0;i<l.length;)l[i].fn===r?l.splice(i,1):++i;return this};EventEmitter.prototype.emit=function(t){var r=this._listeners[t];if(r){for(var l=[],i=1;i<arguments.length;)l.push(arguments[i++]);for(i=0;i<r.length;)r[i].fn.apply(r[i++].ctx,l)}return this};var float=factory(factory);function factory(o){return typeof Float32Array<"u"?(function(){var t=new Float32Array([-0]),r=new Uint8Array(t.buffer),l=r[3]===128;function i(s,c,u){t[0]=s,c[u]=r[0],c[u+1]=r[1],c[u+2]=r[2],c[u+3]=r[3]}function a(s,c,u){t[0]=s,c[u]=r[3],c[u+1]=r[2],c[u+2]=r[1],c[u+3]=r[0]}o.writeFloatLE=l?i:a,o.writeFloatBE=l?a:i;function e(s,c){return r[0]=s[c],r[1]=s[c+1],r[2]=s[c+2],r[3]=s[c+3],t[0]}function n(s,c){return r[3]=s[c],r[2]=s[c+1],r[1]=s[c+2],r[0]=s[c+3],t[0]}o.readFloatLE=l?e:n,o.readFloatBE=l?n:e})():(function(){function t(l,i,a,e){var n=i<0?1:0;if(n&&(i=-i),i===0)l(1/i>0?0:2147483648,a,e);else if(isNaN(i))l(2143289344,a,e);else if(i>34028234663852886e22)l((n<<31|2139095040)>>>0,a,e);else if(i<11754943508222875e-54)l((n<<31|Math.round(i/1401298464324817e-60))>>>0,a,e);else{var s=Math.floor(Math.log(i)/Math.LN2),c=Math.round(i*Math.pow(2,-s)*8388608)&8388607;l((n<<31|s+127<<23|c)>>>0,a,e)}}o.writeFloatLE=t.bind(null,writeUintLE),o.writeFloatBE=t.bind(null,writeUintBE);function r(l,i,a){var e=l(i,a),n=(e>>31)*2+1,s=e>>>23&255,c=e&8388607;return s===255?c?NaN:n*(1/0):s===0?n*1401298464324817e-60*c:n*Math.pow(2,s-150)*(c+8388608)}o.readFloatLE=r.bind(null,readUintLE),o.readFloatBE=r.bind(null,readUintBE)})(),typeof Float64Array<"u"?(function(){var t=new Float64Array([-0]),r=new Uint8Array(t.buffer),l=r[7]===128;function i(s,c,u){t[0]=s,c[u]=r[0],c[u+1]=r[1],c[u+2]=r[2],c[u+3]=r[3],c[u+4]=r[4],c[u+5]=r[5],c[u+6]=r[6],c[u+7]=r[7]}function a(s,c,u){t[0]=s,c[u]=r[7],c[u+1]=r[6],c[u+2]=r[5],c[u+3]=r[4],c[u+4]=r[3],c[u+5]=r[2],c[u+6]=r[1],c[u+7]=r[0]}o.writeDoubleLE=l?i:a,o.writeDoubleBE=l?a:i;function e(s,c){return r[0]=s[c],r[1]=s[c+1],r[2]=s[c+2],r[3]=s[c+3],r[4]=s[c+4],r[5]=s[c+5],r[6]=s[c+6],r[7]=s[c+7],t[0]}function n(s,c){return r[7]=s[c],r[6]=s[c+1],r[5]=s[c+2],r[4]=s[c+3],r[3]=s[c+4],r[2]=s[c+5],r[1]=s[c+6],r[0]=s[c+7],t[0]}o.readDoubleLE=l?e:n,o.readDoubleBE=l?n:e})():(function(){function t(l,i,a,e,n,s){var c=e<0?1:0;if(c&&(e=-e),e===0)l(0,n,s+i),l(1/e>0?0:2147483648,n,s+a);else if(isNaN(e))l(0,n,s+i),l(2146959360,n,s+a);else if(e>17976931348623157e292)l(0,n,s+i),l((c<<31|2146435072)>>>0,n,s+a);else{var u;if(e<22250738585072014e-324)u=e/5e-324,l(u>>>0,n,s+i),l((c<<31|u/4294967296)>>>0,n,s+a);else{var f=Math.floor(Math.log(e)/Math.LN2);f===1024&&(f=1023),u=e*Math.pow(2,-f),l(u*4503599627370496>>>0,n,s+i),l((c<<31|f+1023<<20|u*1048576&1048575)>>>0,n,s+a)}}}o.writeDoubleLE=t.bind(null,writeUintLE,0,4),o.writeDoubleBE=t.bind(null,writeUintBE,4,0);function r(l,i,a,e,n){var s=l(e,n+i),c=l(e,n+a),u=(c>>31)*2+1,f=c>>>20&2047,d=4294967296*(c&1048575)+s;return f===2047?d?NaN:u*(1/0):f===0?u*5e-324*d:u*Math.pow(2,f-1075)*(d+4503599627370496)}o.readDoubleLE=r.bind(null,readUintLE,0,4),o.readDoubleBE=r.bind(null,readUintBE,4,0)})(),o}function writeUintLE(o,t,r){t[r]=o&255,t[r+1]=o>>>8&255,t[r+2]=o>>>16&255,t[r+3]=o>>>24}function writeUintBE(o,t,r){t[r]=o>>>24,t[r+1]=o>>>16&255,t[r+2]=o>>>8&255,t[r+3]=o&255}function readUintLE(o,t){return(o[t]|o[t+1]<<8|o[t+2]<<16|o[t+3]<<24)>>>0}function readUintBE(o,t){return(o[t]<<24|o[t+1]<<16|o[t+2]<<8|o[t+3])>>>0}var inquire_1=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(o){}return null}var utf8$2={};(function(o){var t=o;t.length=function(l){for(var i=0,a=0,e=0;e<l.length;++e)a=l.charCodeAt(e),a<128?i+=1:a<2048?i+=2:(a&64512)===55296&&(l.charCodeAt(e+1)&64512)===56320?(++e,i+=4):i+=3;return i},t.read=function(l,i,a){var e=a-i;if(e<1)return"";for(var n=null,s=[],c=0,u;i<a;)u=l[i++],u<128?s[c++]=u:u>191&&u<224?s[c++]=(u&31)<<6|l[i++]&63:u>239&&u<365?(u=((u&7)<<18|(l[i++]&63)<<12|(l[i++]&63)<<6|l[i++]&63)-65536,s[c++]=55296+(u>>10),s[c++]=56320+(u&1023)):s[c++]=(u&15)<<12|(l[i++]&63)<<6|l[i++]&63,c>8191&&((n||(n=[])).push(String.fromCharCode.apply(String,s)),c=0);return n?(c&&n.push(String.fromCharCode.apply(String,s.slice(0,c))),n.join("")):String.fromCharCode.apply(String,s.slice(0,c))},t.write=function(l,i,a){for(var e=a,n,s,c=0;c<l.length;++c)n=l.charCodeAt(c),n<128?i[a++]=n:n<2048?(i[a++]=n>>6|192,i[a++]=n&63|128):(n&64512)===55296&&((s=l.charCodeAt(c+1))&64512)===56320?(n=65536+((n&1023)<<10)+(s&1023),++c,i[a++]=n>>18|240,i[a++]=n>>12&63|128,i[a++]=n>>6&63|128,i[a++]=n&63|128):(i[a++]=n>>12|224,i[a++]=n>>6&63|128,i[a++]=n&63|128);return a-e}})(utf8$2);var pool_1=pool;function pool(o,t,r){var l=r||8192,i=l>>>1,a=null,e=l;return function(s){if(s<1||s>i)return o(s);e+s>l&&(a=o(l),e=0);var c=t.call(a,e,e+=s);return e&7&&(e=(e|7)+1),c}}var longbits,hasRequiredLongbits;function requireLongbits(){if(hasRequiredLongbits)return longbits;hasRequiredLongbits=1,longbits=t;var o=requireMinimal();function t(a,e){this.lo=a>>>0,this.hi=e>>>0}var r=t.zero=new t(0,0);r.toNumber=function(){return 0},r.zzEncode=r.zzDecode=function(){return this},r.length=function(){return 1};var l=t.zeroHash="\0\0\0\0\0\0\0\0";t.fromNumber=function(e){if(e===0)return r;var n=e<0;n&&(e=-e);var s=e>>>0,c=(e-s)/4294967296>>>0;return n&&(c=~c>>>0,s=~s>>>0,++s>4294967295&&(s=0,++c>4294967295&&(c=0))),new t(s,c)},t.from=function(e){if(typeof e=="number")return t.fromNumber(e);if(o.isString(e))if(o.Long)e=o.Long.fromString(e);else return t.fromNumber(parseInt(e,10));return e.low||e.high?new t(e.low>>>0,e.high>>>0):r},t.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var n=~this.lo+1>>>0,s=~this.hi>>>0;return n||(s=s+1>>>0),-(n+s*4294967296)}return this.lo+this.hi*4294967296},t.prototype.toLong=function(e){return o.Long?new o.Long(this.lo|0,this.hi|0,!!e):{low:this.lo|0,high:this.hi|0,unsigned:!!e}};var i=String.prototype.charCodeAt;return t.fromHash=function(e){return e===l?r:new t((i.call(e,0)|i.call(e,1)<<8|i.call(e,2)<<16|i.call(e,3)<<24)>>>0,(i.call(e,4)|i.call(e,5)<<8|i.call(e,6)<<16|i.call(e,7)<<24)>>>0)},t.prototype.toHash=function(){return String.fromCharCode(this.lo&255,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,this.hi&255,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},t.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},t.prototype.zzDecode=function(){var e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},t.prototype.length=function(){var e=this.lo,n=(this.lo>>>28|this.hi<<4)>>>0,s=this.hi>>>24;return s===0?n===0?e<16384?e<128?1:2:e<2097152?3:4:n<16384?n<128?5:6:n<2097152?7:8:s<128?9:10},longbits}var hasRequiredMinimal;function requireMinimal(){return hasRequiredMinimal||(hasRequiredMinimal=1,(function(o){var t=o;t.asPromise=aspromise,t.base64=base64$1,t.EventEmitter=eventemitter,t.float=float,t.inquire=inquire_1,t.utf8=utf8$2,t.pool=pool_1,t.LongBits=requireLongbits(),t.isNode=!!(typeof commonjsGlobal<"u"&&commonjsGlobal&&commonjsGlobal.process&&commonjsGlobal.process.versions&&commonjsGlobal.process.versions.node),t.global=t.isNode&&commonjsGlobal||typeof window<"u"&&window||typeof self<"u"&&self||commonjsGlobal,t.emptyArray=Object.freeze?Object.freeze([]):[],t.emptyObject=Object.freeze?Object.freeze({}):{},t.isInteger=Number.isInteger||function(a){return typeof a=="number"&&isFinite(a)&&Math.floor(a)===a},t.isString=function(a){return typeof a=="string"||a instanceof String},t.isObject=function(a){return a&&typeof a=="object"},t.isset=t.isSet=function(a,e){var n=a[e];return n!=null&&a.hasOwnProperty(e)?typeof n!="object"||(Array.isArray(n)?n.length:Object.keys(n).length)>0:!1},t.Buffer=(function(){try{var i=t.inquire("buffer").Buffer;return i.prototype.utf8Write?i:null}catch{return null}})(),t._Buffer_from=null,t._Buffer_allocUnsafe=null,t.newBuffer=function(a){return typeof a=="number"?t.Buffer?t._Buffer_allocUnsafe(a):new t.Array(a):t.Buffer?t._Buffer_from(a):typeof Uint8Array>"u"?a:new Uint8Array(a)},t.Array=typeof Uint8Array<"u"?Uint8Array:Array,t.Long=t.global.dcodeIO&&t.global.dcodeIO.Long||t.global.Long||t.inquire("long"),t.key2Re=/^true|false|0|1$/,t.key32Re=/^-?(?:0|[1-9][0-9]*)$/,t.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,t.longToHash=function(a){return a?t.LongBits.from(a).toHash():t.LongBits.zeroHash},t.longFromHash=function(a,e){var n=t.LongBits.fromHash(a);return t.Long?t.Long.fromBits(n.lo,n.hi,e):n.toNumber(!!e)};function r(i,a,e){for(var n=Object.keys(a),s=0;s<n.length;++s)(i[n[s]]===void 0||!e)&&(i[n[s]]=a[n[s]]);return i}t.merge=r,t.lcFirst=function(a){return a.charAt(0).toLowerCase()+a.substring(1)};function l(i){function a(e,n){if(!(this instanceof a))return new a(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,a):Object.defineProperty(this,"stack",{value:new Error().stack||""}),n&&r(this,n)}return a.prototype=Object.create(Error.prototype,{constructor:{value:a,writable:!0,enumerable:!1,configurable:!0},name:{get:function(){return i},set:void 0,enumerable:!1,configurable:!0},toString:{value:function(){return this.name+": "+this.message},writable:!0,enumerable:!1,configurable:!0}}),a}t.newError=l,t.ProtocolError=l("ProtocolError"),t.oneOfGetter=function(a){for(var e={},n=0;n<a.length;++n)e[a[n]]=1;return function(){for(var s=Object.keys(this),c=s.length-1;c>-1;--c)if(e[s[c]]===1&&this[s[c]]!==void 0&&this[s[c]]!==null)return s[c]}},t.oneOfSetter=function(a){return function(e){for(var n=0;n<a.length;++n)a[n]!==e&&delete this[a[n]]}},t.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},t._configure=function(){var i=t.Buffer;if(!i){t._Buffer_from=t._Buffer_allocUnsafe=null;return}t._Buffer_from=i.from!==Uint8Array.from&&i.from||function(e,n){return new i(e,n)},t._Buffer_allocUnsafe=i.allocUnsafe||function(e){return new i(e)}}})(minimal$1)),minimal$1}var writer=Writer$1,util$4=requireMinimal(),BufferWriter$1,LongBits$1=util$4.LongBits,base64=util$4.base64,utf8$1=util$4.utf8;function Op(o,t,r){this.fn=o,this.len=t,this.next=void 0,this.val=r}function noop(){}function State(o){this.head=o.head,this.tail=o.tail,this.len=o.len,this.next=o.states}function Writer$1(){this.len=0,this.head=new Op(noop,0,0),this.tail=this.head,this.states=null}var create$1=function o(){return util$4.Buffer?function(){return(Writer$1.create=function(){return new BufferWriter$1})()}:function(){return new Writer$1}};Writer$1.create=create$1();Writer$1.alloc=function o(t){return new util$4.Array(t)};util$4.Array!==Array&&(Writer$1.alloc=util$4.pool(Writer$1.alloc,util$4.Array.prototype.subarray));Writer$1.prototype._push=function o(t,r,l){return this.tail=this.tail.next=new Op(t,r,l),this.len+=r,this};function writeByte(o,t,r){t[r]=o&255}function writeVarint32(o,t,r){for(;o>127;)t[r++]=o&127|128,o>>>=7;t[r]=o}function VarintOp(o,t){this.len=o,this.next=void 0,this.val=t}VarintOp.prototype=Object.create(Op.prototype);VarintOp.prototype.fn=writeVarint32;Writer$1.prototype.uint32=function o(t){return this.len+=(this.tail=this.tail.next=new VarintOp((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this};Writer$1.prototype.int32=function o(t){return t<0?this._push(writeVarint64,10,LongBits$1.fromNumber(t)):this.uint32(t)};Writer$1.prototype.sint32=function o(t){return this.uint32((t<<1^t>>31)>>>0)};function writeVarint64(o,t,r){for(;o.hi;)t[r++]=o.lo&127|128,o.lo=(o.lo>>>7|o.hi<<25)>>>0,o.hi>>>=7;for(;o.lo>127;)t[r++]=o.lo&127|128,o.lo=o.lo>>>7;t[r++]=o.lo}Writer$1.prototype.uint64=function o(t){var r=LongBits$1.from(t);return this._push(writeVarint64,r.length(),r)};Writer$1.prototype.int64=Writer$1.prototype.uint64;Writer$1.prototype.sint64=function o(t){var r=LongBits$1.from(t).zzEncode();return this._push(writeVarint64,r.length(),r)};Writer$1.prototype.bool=function o(t){return this._push(writeByte,1,t?1:0)};function writeFixed32(o,t,r){t[r]=o&255,t[r+1]=o>>>8&255,t[r+2]=o>>>16&255,t[r+3]=o>>>24}Writer$1.prototype.fixed32=function o(t){return this._push(writeFixed32,4,t>>>0)};Writer$1.prototype.sfixed32=Writer$1.prototype.fixed32;Writer$1.prototype.fixed64=function o(t){var r=LongBits$1.from(t);return this._push(writeFixed32,4,r.lo)._push(writeFixed32,4,r.hi)};Writer$1.prototype.sfixed64=Writer$1.prototype.fixed64;Writer$1.prototype.float=function o(t){return this._push(util$4.float.writeFloatLE,4,t)};Writer$1.prototype.double=function o(t){return this._push(util$4.float.writeDoubleLE,8,t)};var writeBytes=util$4.Array.prototype.set?function o(t,r,l){r.set(t,l)}:function o(t,r,l){for(var i=0;i<t.length;++i)r[l+i]=t[i]};Writer$1.prototype.bytes=function o(t){var r=t.length>>>0;if(!r)return this._push(writeByte,1,0);if(util$4.isString(t)){var l=Writer$1.alloc(r=base64.length(t));base64.decode(t,l,0),t=l}return this.uint32(r)._push(writeBytes,r,t)};Writer$1.prototype.string=function o(t){var r=utf8$1.length(t);return r?this.uint32(r)._push(utf8$1.write,r,t):this._push(writeByte,1,0)};Writer$1.prototype.fork=function o(){return this.states=new State(this),this.head=this.tail=new Op(noop,0,0),this.len=0,this};Writer$1.prototype.reset=function o(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Op(noop,0,0),this.len=0),this};Writer$1.prototype.ldelim=function o(){var t=this.head,r=this.tail,l=this.len;return this.reset().uint32(l),l&&(this.tail.next=t.next,this.tail=r,this.len+=l),this};Writer$1.prototype.finish=function o(){for(var t=this.head.next,r=this.constructor.alloc(this.len),l=0;t;)t.fn(t.val,r,l),l+=t.len,t=t.next;return r};Writer$1._configure=function(o){BufferWriter$1=o,Writer$1.create=create$1(),BufferWriter$1._configure()};var writer_buffer=BufferWriter,Writer=writer;(BufferWriter.prototype=Object.create(Writer.prototype)).constructor=BufferWriter;var util$3=requireMinimal();function BufferWriter(){Writer.call(this)}BufferWriter._configure=function(){BufferWriter.alloc=util$3._Buffer_allocUnsafe,BufferWriter.writeBytesBuffer=util$3.Buffer&&util$3.Buffer.prototype instanceof Uint8Array&&util$3.Buffer.prototype.set.name==="set"?function(t,r,l){r.set(t,l)}:function(t,r,l){if(t.copy)t.copy(r,l,0,t.length);else for(var i=0;i<t.length;)r[l++]=t[i++]}};BufferWriter.prototype.bytes=function o(t){util$3.isString(t)&&(t=util$3._Buffer_from(t,"base64"));var r=t.length>>>0;return this.uint32(r),r&&this._push(BufferWriter.writeBytesBuffer,r,t),this};function writeStringBuffer(o,t,r){o.length<40?util$3.utf8.write(o,t,r):t.utf8Write?t.utf8Write(o,r):t.write(o,r)}BufferWriter.prototype.string=function o(t){var r=util$3.Buffer.byteLength(t);return this.uint32(r),r&&this._push(writeStringBuffer,r,t),this};BufferWriter._configure();var reader=Reader$1,util$2=requireMinimal(),BufferReader$1,LongBits=util$2.LongBits,utf8=util$2.utf8;function indexOutOfRange(o,t){return RangeError("index out of range: "+o.pos+" + "+(t||1)+" > "+o.len)}function Reader$1(o){this.buf=o,this.pos=0,this.len=o.length}var create_array=typeof Uint8Array<"u"?function o(t){if(t instanceof Uint8Array||Array.isArray(t))return new Reader$1(t);throw Error("illegal buffer")}:function o(t){if(Array.isArray(t))return new Reader$1(t);throw Error("illegal buffer")},create=function o(){return util$2.Buffer?function(r){return(Reader$1.create=function(i){return util$2.Buffer.isBuffer(i)?new BufferReader$1(i):create_array(i)})(r)}:create_array};Reader$1.create=create();Reader$1.prototype._slice=util$2.Array.prototype.subarray||util$2.Array.prototype.slice;Reader$1.prototype.uint32=(function o(){var t=4294967295;return function(){if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,indexOutOfRange(this,10);return t}})();Reader$1.prototype.int32=function o(){return this.uint32()|0};Reader$1.prototype.sint32=function o(){var t=this.uint32();return t>>>1^-(t&1)|0};function readLongVarint(){var o=new LongBits(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(o.lo=(o.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return o;if(o.lo=(o.lo|(this.buf[this.pos]&127)<<28)>>>0,o.hi=(o.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return o;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw indexOutOfRange(this);if(o.lo=(o.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return o}return o.lo=(o.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,o}if(this.len-this.pos>4){for(;t<5;++t)if(o.hi=(o.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return o}else for(;t<5;++t){if(this.pos>=this.len)throw indexOutOfRange(this);if(o.hi=(o.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return o}throw Error("invalid varint encoding")}Reader$1.prototype.bool=function o(){return this.uint32()!==0};function readFixed32_end(o,t){return(o[t-4]|o[t-3]<<8|o[t-2]<<16|o[t-1]<<24)>>>0}Reader$1.prototype.fixed32=function o(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);return readFixed32_end(this.buf,this.pos+=4)};Reader$1.prototype.sfixed32=function o(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);return readFixed32_end(this.buf,this.pos+=4)|0};function readFixed64(){if(this.pos+8>this.len)throw indexOutOfRange(this,8);return new LongBits(readFixed32_end(this.buf,this.pos+=4),readFixed32_end(this.buf,this.pos+=4))}Reader$1.prototype.float=function o(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);var t=util$2.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t};Reader$1.prototype.double=function o(){if(this.pos+8>this.len)throw indexOutOfRange(this,4);var t=util$2.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t};Reader$1.prototype.bytes=function o(){var t=this.uint32(),r=this.pos,l=this.pos+t;if(l>this.len)throw indexOutOfRange(this,t);if(this.pos+=t,Array.isArray(this.buf))return this.buf.slice(r,l);if(r===l){var i=util$2.Buffer;return i?i.alloc(0):new this.buf.constructor(0)}return this._slice.call(this.buf,r,l)};Reader$1.prototype.string=function o(){var t=this.bytes();return utf8.read(t,0,t.length)};Reader$1.prototype.skip=function o(t){if(typeof t=="number"){if(this.pos+t>this.len)throw indexOutOfRange(this,t);this.pos+=t}else do if(this.pos>=this.len)throw indexOutOfRange(this);while(this.buf[this.pos++]&128);return this};Reader$1.prototype.skipType=function(o){switch(o){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(o=this.uint32()&7)!==4;)this.skipType(o);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+o+" at offset "+this.pos)}return this};Reader$1._configure=function(o){BufferReader$1=o,Reader$1.create=create(),BufferReader$1._configure();var t=util$2.Long?"toLong":"toNumber";util$2.merge(Reader$1.prototype,{int64:function(){return readLongVarint.call(this)[t](!1)},uint64:function(){return readLongVarint.call(this)[t](!0)},sint64:function(){return readLongVarint.call(this).zzDecode()[t](!1)},fixed64:function(){return readFixed64.call(this)[t](!0)},sfixed64:function(){return readFixed64.call(this)[t](!1)}})};var reader_buffer=BufferReader,Reader=reader;(BufferReader.prototype=Object.create(Reader.prototype)).constructor=BufferReader;var util$1=requireMinimal();function BufferReader(o){Reader.call(this,o)}BufferReader._configure=function(){util$1.Buffer&&(BufferReader.prototype._slice=util$1.Buffer.prototype.slice)};BufferReader.prototype.string=function o(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))};BufferReader._configure();var rpc={},service=Service,util=requireMinimal();(Service.prototype=Object.create(util.EventEmitter.prototype)).constructor=Service;function Service(o,t,r){if(typeof o!="function")throw TypeError("rpcImpl must be a function");util.EventEmitter.call(this),this.rpcImpl=o,this.requestDelimited=!!t,this.responseDelimited=!!r}Service.prototype.rpcCall=function o(t,r,l,i,a){if(!i)throw TypeError("request must be specified");var e=this;if(!a)return util.asPromise(o,e,t,r,l,i);if(!e.rpcImpl){setTimeout(function(){a(Error("already ended"))},0);return}try{return e.rpcImpl(t,r[e.requestDelimited?"encodeDelimited":"encode"](i).finish(),function(s,c){if(s)return e.emit("error",s,t),a(s);if(c===null){e.end(!0);return}if(!(c instanceof l))try{c=l[e.responseDelimited?"decodeDelimited":"decode"](c)}catch(u){return e.emit("error",u,t),a(u)}return e.emit("data",c,t),a(null,c)})}catch(n){e.emit("error",n,t),setTimeout(function(){a(n)},0);return}};Service.prototype.end=function o(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this};(function(o){var t=o;t.Service=service})(rpc);var roots={};(function(o){var t=o;t.build="minimal",t.Writer=writer,t.BufferWriter=writer_buffer,t.Reader=reader,t.BufferReader=reader_buffer,t.util=requireMinimal(),t.rpc=rpc,t.roots=roots,t.configure=r;function r(){t.util._configure(),t.Writer._configure(t.BufferWriter),t.Reader._configure(t.BufferReader)}r()})(indexMinimal);var minimal=indexMinimal;const $Reader=minimal.Reader,$Writer=minimal.Writer,$util=minimal.util,$root=minimal.roots.default||(minimal.roots.default={}),com=$root.com=(()=>{const o={};return o.amazonaws=(function(){const t={};return t.iot=(function(){const r={};return r.securedtunneling=(function(){const l={};return l.ProtocolV1Message=(function(){function i(a){if(a)for(let e=Object.keys(a),n=0;n<e.length;++n)a[e[n]]!=null&&(this[e[n]]=a[e[n]])}return i.prototype.type=0,i.prototype.streamId=0,i.prototype.ignorable=!1,i.prototype.payload=$util.newBuffer([]),i.create=function(e){return new i(e)},i.encode=function(e,n){return n||(n=$Writer.create()),e.type!=null&&Object.hasOwnProperty.call(e,"type")&&n.uint32(8).int32(e.type),e.streamId!=null&&Object.hasOwnProperty.call(e,"streamId")&&n.uint32(16).int32(e.streamId),e.ignorable!=null&&Object.hasOwnProperty.call(e,"ignorable")&&n.uint32(24).bool(e.ignorable),e.payload!=null&&Object.hasOwnProperty.call(e,"payload")&&n.uint32(34).bytes(e.payload),n},i.encodeDelimited=function(e,n){return this.encode(e,n).ldelim()},i.decode=function(e,n,s){e instanceof $Reader||(e=$Reader.create(e));let c=n===void 0?e.len:e.pos+n,u=new $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message;for(;e.pos<c;){let f=e.uint32();if(f===s)break;switch(f>>>3){case 1:{u.type=e.int32();break}case 2:{u.streamId=e.int32();break}case 3:{u.ignorable=e.bool();break}case 4:{u.payload=e.bytes();break}default:e.skipType(f&7);break}}return u},i.decodeDelimited=function(e){return e instanceof $Reader||(e=new $Reader(e)),this.decode(e,e.uint32())},i.verify=function(e){if(typeof e!="object"||e===null)return"object expected";if(e.type!=null&&e.hasOwnProperty("type"))switch(e.type){default:return"type: enum value expected";case 0:case 1:case 2:case 3:break}return e.streamId!=null&&e.hasOwnProperty("streamId")&&!$util.isInteger(e.streamId)?"streamId: integer expected":e.ignorable!=null&&e.hasOwnProperty("ignorable")&&typeof e.ignorable!="boolean"?"ignorable: boolean expected":e.payload!=null&&e.hasOwnProperty("payload")&&!(e.payload&&typeof e.payload.length=="number"||$util.isString(e.payload))?"payload: buffer expected":null},i.fromObject=function(e){if(e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message)return e;let n=new $root.com.amazonaws.iot.securedtunneling.ProtocolV1Message;switch(e.type){default:if(typeof e.type=="number"){n.type=e.type;break}break;case"UNKNOWN":case 0:n.type=0;break;case"DATA":case 1:n.type=1;break;case"STREAM_START":case 2:n.type=2;break;case"STREAM_END":case 3:n.type=3;break}return e.streamId!=null&&(n.streamId=e.streamId|0),e.ignorable!=null&&(n.ignorable=!!e.ignorable),e.payload!=null&&(typeof e.payload=="string"?$util.base64.decode(e.payload,n.payload=$util.newBuffer($util.base64.length(e.payload)),0):e.payload.length>=0&&(n.payload=e.payload)),n},i.toObject=function(e,n){n||(n={});let s={};return n.defaults&&(s.type=n.enums===String?"UNKNOWN":0,s.streamId=0,s.ignorable=!1,n.bytes===String?s.payload="":(s.payload=[],n.bytes!==Array&&(s.payload=$util.newBuffer(s.payload)))),e.type!=null&&e.hasOwnProperty("type")&&(s.type=n.enums===String?$root.com.amazonaws.iot.securedtunneling.ProtocolV1Message.Type[e.type]===void 0?e.type:$root.com.amazonaws.iot.securedtunneling.ProtocolV1Message.Type[e.type]:e.type),e.streamId!=null&&e.hasOwnProperty("streamId")&&(s.streamId=e.streamId),e.ignorable!=null&&e.hasOwnProperty("ignorable")&&(s.ignorable=e.ignorable),e.payload!=null&&e.hasOwnProperty("payload")&&(s.payload=n.bytes===String?$util.base64.encode(e.payload,0,e.payload.length):n.bytes===Array?Array.prototype.slice.call(e.payload):e.payload),s},i.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},i.getTypeUrl=function(e){return e===void 0&&(e="type.googleapis.com"),e+"/com.amazonaws.iot.securedtunneling.ProtocolV1Message"},i.Type=(function(){const a={},e=Object.create(a);return e[a[0]="UNKNOWN"]=0,e[a[1]="DATA"]=1,e[a[2]="STREAM_START"]=2,e[a[3]="STREAM_END"]=3,e})(),i})(),l.ProtocolV2Message=(function(){function i(a){if(this.availableServiceIds=[],a)for(let e=Object.keys(a),n=0;n<e.length;++n)a[e[n]]!=null&&(this[e[n]]=a[e[n]])}return i.prototype.type=0,i.prototype.streamId=0,i.prototype.ignorable=!1,i.prototype.payload=$util.newBuffer([]),i.prototype.serviceId="",i.prototype.availableServiceIds=$util.emptyArray,i.create=function(e){return new i(e)},i.encode=function(e,n){if(n||(n=$Writer.create()),e.type!=null&&Object.hasOwnProperty.call(e,"type")&&n.uint32(8).int32(e.type),e.streamId!=null&&Object.hasOwnProperty.call(e,"streamId")&&n.uint32(16).int32(e.streamId),e.ignorable!=null&&Object.hasOwnProperty.call(e,"ignorable")&&n.uint32(24).bool(e.ignorable),e.payload!=null&&Object.hasOwnProperty.call(e,"payload")&&n.uint32(34).bytes(e.payload),e.serviceId!=null&&Object.hasOwnProperty.call(e,"serviceId")&&n.uint32(42).string(e.serviceId),e.availableServiceIds!=null&&e.availableServiceIds.length)for(let s=0;s<e.availableServiceIds.length;++s)n.uint32(50).string(e.availableServiceIds[s]);return n},i.encodeDelimited=function(e,n){return this.encode(e,n).ldelim()},i.decode=function(e,n,s){e instanceof $Reader||(e=$Reader.create(e));let c=n===void 0?e.len:e.pos+n,u=new $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message;for(;e.pos<c;){let f=e.uint32();if(f===s)break;switch(f>>>3){case 1:{u.type=e.int32();break}case 2:{u.streamId=e.int32();break}case 3:{u.ignorable=e.bool();break}case 4:{u.payload=e.bytes();break}case 5:{u.serviceId=e.string();break}case 6:{u.availableServiceIds&&u.availableServiceIds.length||(u.availableServiceIds=[]),u.availableServiceIds.push(e.string());break}default:e.skipType(f&7);break}}return u},i.decodeDelimited=function(e){return e instanceof $Reader||(e=new $Reader(e)),this.decode(e,e.uint32())},i.verify=function(e){if(typeof e!="object"||e===null)return"object expected";if(e.type!=null&&e.hasOwnProperty("type"))switch(e.type){default:return"type: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:break}if(e.streamId!=null&&e.hasOwnProperty("streamId")&&!$util.isInteger(e.streamId))return"streamId: integer expected";if(e.ignorable!=null&&e.hasOwnProperty("ignorable")&&typeof e.ignorable!="boolean")return"ignorable: boolean expected";if(e.payload!=null&&e.hasOwnProperty("payload")&&!(e.payload&&typeof e.payload.length=="number"||$util.isString(e.payload)))return"payload: buffer expected";if(e.serviceId!=null&&e.hasOwnProperty("serviceId")&&!$util.isString(e.serviceId))return"serviceId: string expected";if(e.availableServiceIds!=null&&e.hasOwnProperty("availableServiceIds")){if(!Array.isArray(e.availableServiceIds))return"availableServiceIds: array expected";for(let n=0;n<e.availableServiceIds.length;++n)if(!$util.isString(e.availableServiceIds[n]))return"availableServiceIds: string[] expected"}return null},i.fromObject=function(e){if(e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message)return e;let n=new $root.com.amazonaws.iot.securedtunneling.ProtocolV2Message;switch(e.type){default:if(typeof e.type=="number"){n.type=e.type;break}break;case"UNKNOWN":case 0:n.type=0;break;case"DATA":case 1:n.type=1;break;case"STREAM_START":case 2:n.type=2;break;case"STREAM_RESET":case 3:n.type=3;break;case"SESSION_RESET":case 4:n.type=4;break;case"SERVICE_IDS":case 5:n.type=5;break}if(e.streamId!=null&&(n.streamId=e.streamId|0),e.ignorable!=null&&(n.ignorable=!!e.ignorable),e.payload!=null&&(typeof e.payload=="string"?$util.base64.decode(e.payload,n.payload=$util.newBuffer($util.base64.length(e.payload)),0):e.payload.length>=0&&(n.payload=e.payload)),e.serviceId!=null&&(n.serviceId=String(e.serviceId)),e.availableServiceIds){if(!Array.isArray(e.availableServiceIds))throw TypeError(".com.amazonaws.iot.securedtunneling.ProtocolV2Message.availableServiceIds: array expected");n.availableServiceIds=[];for(let s=0;s<e.availableServiceIds.length;++s)n.availableServiceIds[s]=String(e.availableServiceIds[s])}return n},i.toObject=function(e,n){n||(n={});let s={};if((n.arrays||n.defaults)&&(s.availableServiceIds=[]),n.defaults&&(s.type=n.enums===String?"UNKNOWN":0,s.streamId=0,s.ignorable=!1,n.bytes===String?s.payload="":(s.payload=[],n.bytes!==Array&&(s.payload=$util.newBuffer(s.payload))),s.serviceId=""),e.type!=null&&e.hasOwnProperty("type")&&(s.type=n.enums===String?$root.com.amazonaws.iot.securedtunneling.ProtocolV2Message.Type[e.type]===void 0?e.type:$root.com.amazonaws.iot.securedtunneling.ProtocolV2Message.Type[e.type]:e.type),e.streamId!=null&&e.hasOwnProperty("streamId")&&(s.streamId=e.streamId),e.ignorable!=null&&e.hasOwnProperty("ignorable")&&(s.ignorable=e.ignorable),e.payload!=null&&e.hasOwnProperty("payload")&&(s.payload=n.bytes===String?$util.base64.encode(e.payload,0,e.payload.length):n.bytes===Array?Array.prototype.slice.call(e.payload):e.payload),e.serviceId!=null&&e.hasOwnProperty("serviceId")&&(s.serviceId=e.serviceId),e.availableServiceIds&&e.availableServiceIds.length){s.availableServiceIds=[];for(let c=0;c<e.availableServiceIds.length;++c)s.availableServiceIds[c]=e.availableServiceIds[c]}return s},i.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},i.getTypeUrl=function(e){return e===void 0&&(e="type.googleapis.com"),e+"/com.amazonaws.iot.securedtunneling.ProtocolV2Message"},i.Type=(function(){const a={},e=Object.create(a);return e[a[0]="UNKNOWN"]=0,e[a[1]="DATA"]=1,e[a[2]="STREAM_START"]=2,e[a[3]="STREAM_RESET"]=3,e[a[4]="SESSION_RESET"]=4,e[a[5]="SERVICE_IDS"]=5,e})(),i})(),l.ProtocolV3Message=(function(){function i(a){if(this.availableServiceIds=[],a)for(let e=Object.keys(a),n=0;n<e.length;++n)a[e[n]]!=null&&(this[e[n]]=a[e[n]])}return i.prototype.type=0,i.prototype.streamId=0,i.prototype.ignorable=!1,i.prototype.payload=$util.newBuffer([]),i.prototype.serviceId="",i.prototype.availableServiceIds=$util.emptyArray,i.prototype.connectionId=0,i.create=function(e){return new i(e)},i.encode=function(e,n){if(n||(n=$Writer.create()),e.type!=null&&Object.hasOwnProperty.call(e,"type")&&n.uint32(8).int32(e.type),e.streamId!=null&&Object.hasOwnProperty.call(e,"streamId")&&n.uint32(16).int32(e.streamId),e.ignorable!=null&&Object.hasOwnProperty.call(e,"ignorable")&&n.uint32(24).bool(e.ignorable),e.payload!=null&&Object.hasOwnProperty.call(e,"payload")&&n.uint32(34).bytes(e.payload),e.serviceId!=null&&Object.hasOwnProperty.call(e,"serviceId")&&n.uint32(42).string(e.serviceId),e.availableServiceIds!=null&&e.availableServiceIds.length)for(let s=0;s<e.availableServiceIds.length;++s)n.uint32(50).string(e.availableServiceIds[s]);return e.connectionId!=null&&Object.hasOwnProperty.call(e,"connectionId")&&n.uint32(56).uint32(e.connectionId),n},i.encodeDelimited=function(e,n){return this.encode(e,n).ldelim()},i.decode=function(e,n,s){e instanceof $Reader||(e=$Reader.create(e));let c=n===void 0?e.len:e.pos+n,u=new $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message;for(;e.pos<c;){let f=e.uint32();if(f===s)break;switch(f>>>3){case 1:{u.type=e.int32();break}case 2:{u.streamId=e.int32();break}case 3:{u.ignorable=e.bool();break}case 4:{u.payload=e.bytes();break}case 5:{u.serviceId=e.string();break}case 6:{u.availableServiceIds&&u.availableServiceIds.length||(u.availableServiceIds=[]),u.availableServiceIds.push(e.string());break}case 7:{u.connectionId=e.uint32();break}default:e.skipType(f&7);break}}return u},i.decodeDelimited=function(e){return e instanceof $Reader||(e=new $Reader(e)),this.decode(e,e.uint32())},i.verify=function(e){if(typeof e!="object"||e===null)return"object expected";if(e.type!=null&&e.hasOwnProperty("type"))switch(e.type){default:return"type: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:break}if(e.streamId!=null&&e.hasOwnProperty("streamId")&&!$util.isInteger(e.streamId))return"streamId: integer expected";if(e.ignorable!=null&&e.hasOwnProperty("ignorable")&&typeof e.ignorable!="boolean")return"ignorable: boolean expected";if(e.payload!=null&&e.hasOwnProperty("payload")&&!(e.payload&&typeof e.payload.length=="number"||$util.isString(e.payload)))return"payload: buffer expected";if(e.serviceId!=null&&e.hasOwnProperty("serviceId")&&!$util.isString(e.serviceId))return"serviceId: string expected";if(e.availableServiceIds!=null&&e.hasOwnProperty("availableServiceIds")){if(!Array.isArray(e.availableServiceIds))return"availableServiceIds: array expected";for(let n=0;n<e.availableServiceIds.length;++n)if(!$util.isString(e.availableServiceIds[n]))return"availableServiceIds: string[] expected"}return e.connectionId!=null&&e.hasOwnProperty("connectionId")&&!$util.isInteger(e.connectionId)?"connectionId: integer expected":null},i.fromObject=function(e){if(e instanceof $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message)return e;let n=new $root.com.amazonaws.iot.securedtunneling.ProtocolV3Message;switch(e.type){default:if(typeof e.type=="number"){n.type=e.type;break}break;case"UNKNOWN":case 0:n.type=0;break;case"DATA":case 1:n.type=1;break;case"STREAM_START":case 2:n.type=2;break;case"STREAM_RESET":case 3:n.type=3;break;case"SESSION_RESET":case 4:n.type=4;break;case"SERVICE_IDS":case 5:n.type=5;break;case"CONNECTION_START":case 6:n.type=6;break;case"CONNECTION_RESET":case 7:n.type=7;break}if(e.streamId!=null&&(n.streamId=e.streamId|0),e.ignorable!=null&&(n.ignorable=!!e.ignorable),e.payload!=null&&(typeof e.payload=="string"?$util.base64.decode(e.payload,n.payload=$util.newBuffer($util.base64.length(e.payload)),0):e.payload.length>=0&&(n.payload=e.payload)),e.serviceId!=null&&(n.serviceId=String(e.serviceId)),e.availableServiceIds){if(!Array.isArray(e.availableServiceIds))throw TypeError(".com.amazonaws.iot.securedtunneling.ProtocolV3Message.availableServiceIds: array expected");n.availableServiceIds=[];for(let s=0;s<e.availableServiceIds.length;++s)n.availableServiceIds[s]=String(e.availableServiceIds[s])}return e.connectionId!=null&&(n.connectionId=e.connectionId>>>0),n},i.toObject=function(e,n){n||(n={});let s={};if((n.arrays||n.defaults)&&(s.availableServiceIds=[]),n.defaults&&(s.type=n.enums===String?"UNKNOWN":0,s.streamId=0,s.ignorable=!1,n.bytes===String?s.payload="":(s.payload=[],n.bytes!==Array&&(s.payload=$util.newBuffer(s.payload))),s.serviceId="",s.connectionId=0),e.type!=null&&e.hasOwnProperty("type")&&(s.type=n.enums===String?$root.com.amazonaws.iot.securedtunneling.ProtocolV3Message.Type[e.type]===void 0?e.type:$root.com.amazonaws.iot.securedtunneling.ProtocolV3Message.Type[e.type]:e.type),e.streamId!=null&&e.hasOwnProperty("streamId")&&(s.streamId=e.streamId),e.ignorable!=null&&e.hasOwnProperty("ignorable")&&(s.ignorable=e.ignorable),e.payload!=null&&e.hasOwnProperty("payload")&&(s.payload=n.bytes===String?$util.base64.encode(e.payload,0,e.payload.length):n.bytes===Array?Array.prototype.slice.call(e.payload):e.payload),e.serviceId!=null&&e.hasOwnProperty("serviceId")&&(s.serviceId=e.serviceId),e.availableServiceIds&&e.availableServiceIds.length){s.availableServiceIds=[];for(let c=0;c<e.availableServiceIds.length;++c)s.availableServiceIds[c]=e.availableServiceIds[c]}return e.connectionId!=null&&e.hasOwnProperty("connectionId")&&(s.connectionId=e.connectionId),s},i.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},i.getTypeUrl=function(e){return e===void 0&&(e="type.googleapis.com"),e+"/com.amazonaws.iot.securedtunneling.ProtocolV3Message"},i.Type=(function(){const a={},e=Object.create(a);return e[a[0]="UNKNOWN"]=0,e[a[1]="DATA"]=1,e[a[2]="STREAM_START"]=2,e[a[3]="STREAM_RESET"]=3,e[a[4]="SESSION_RESET"]=4,e[a[5]="SERVICE_IDS"]=5,e[a[6]="CONNECTION_START"]=6,e[a[7]="CONNECTION_RESET"]=7,e})(),i})(),l})(),r})(),t})(),o})(),ProtocolV1Message=com.amazonaws.iot.securedtunneling.ProtocolV1Message,ProtocolV2Message=com.amazonaws.iot.securedtunneling.ProtocolV2Message,ProtocolV3Message=com.amazonaws.iot.securedtunneling.ProtocolV3Message,TunnelMessageType={UNKNOWN:0,DATA:1,STREAM_START:2,STREAM_RESET:3,SESSION_RESET:4,SERVICE_IDS:5,CONNECTION_START:6,CONNECTION_RESET:7};class SecureTunnelTransport{constructor(t,r){switch(this.ws=null,this.streamId=1,this.connectionId=1,this.isConnected=!1,this.tunnelReady=!1,this.messageQueue=[],this.receiveBuffer=new Uint8Array(0),this.id=t,this.config={protocol:"V2",...r},this.config.protocol){case"V1":this.messageClass=ProtocolV1Message;break;case"V2":this.messageClass=ProtocolV2Message;break;case"V3":this.messageClass=ProtocolV3Message;break;default:this.messageClass=ProtocolV2Message}}async connect(){const t=this.buildWebSocketUrl(),i=`aws.iot.securetunneling-${(this.config.protocol||"V2").replace("V","")}.0`;return console.log(`Connecting with WebSocket subprotocol: ${i}`),new Promise((a,e)=>{try{this.ws=new WebSocket(t,i),this.ws.binaryType="arraybuffer",this.ws.onopen=()=>{console.log("AWS IoT Secure Tunnel WebSocket connected"),this.isConnected=!0,this.config.clientMode==="destination"?this.config.serviceId&&(console.log("Sending SERVICE_IDS message with serviceId:",this.config.serviceId),this.sendControlMessage(TunnelMessageType.SERVICE_IDS,{availableServiceIds:[this.config.serviceId]})):(console.log("Source mode: Sending STREAM_START with streamId:",this.streamId),this.sendControlMessage(TunnelMessageType.STREAM_START,{streamId:this.streamId,serviceId:this.config.serviceId})),console.log("Waiting for tunnel handshake to complete..."),a()},this.ws.onerror=n=>{const s=new Error("WebSocket error connecting to AWS IoT Secure Tunnel");this.onError&&this.onError(s),e(s)},this.ws.onmessage=n=>{n.data instanceof ArrayBuffer&&this.handleIncomingData(new Uint8Array(n.data))},this.ws.onclose=n=>{console.log("AWS IoT Secure Tunnel WebSocket closed",{code:n.code,reason:n.reason,wasClean:n.wasClean}),this.isConnected=!1,this.tunnelReady=!1,this.onClose&&this.onClose()}}catch(n){e(n)}})}async disconnect(){this.ws&&(this.sendControlMessage(TunnelMessageType.STREAM_RESET,{streamId:this.streamId}),this.ws.close(),this.ws=null),this.isConnected=!1,this.tunnelReady=!1}async send(t){if(!this.isConnected||!this.ws||!this.tunnelReady){console.log("Queueing message, tunnel not ready. Connected:",this.isConnected,"Ready:",this.tunnelReady),this.messageQueue.push(t);return}this.sendDataFrame(t)}processQueuedMessages(){for(console.log(`Processing ${this.messageQueue.length} queued messages`);this.messageQueue.length>0;){const t=this.messageQueue.shift();t&&this.sendDataFrame(t)}}buildWebSocketUrl(){const t=`wss://data.tunneling.iot.${this.config.region}.amazonaws.com/tunnel`;if(!this.config.accessToken)throw console.error("AWS IoT Secure Tunnel: Access token is missing or empty"),new Error("Access token is required for AWS IoT Secure Tunnel connection");const r=encodeURIComponent(this.config.accessToken),l=`${t}?local-proxy-mode=${this.config.clientMode}&access-token=${r}`;return console.log("AWS IoT Secure Tunnel URL:",l.substring(0,100)+"..."),console.log("Protocol version:",this.config.protocol||"V2"),l}sendControlMessage(t,r={}){const l={type:t,...r};console.log("Sending control message:",{type:this.getMessageTypeName(t),...r});const i=this.encodeMessage(l);console.log("Encoded message bytes:",Array.from(i).map(a=>a.toString(16).padStart(2,"0")).join(" ")),this.sendFrame(i)}sendDataFrame(t){for(let l=0;l<t.length;l+=64512){const i=t.slice(l,Math.min(l+64512,t.length)),a={type:TunnelMessageType.DATA,streamId:this.streamId,payload:i};this.config.serviceId&&this.config.protocol!=="V1"&&(a.serviceId=this.config.serviceId),this.config.protocol==="V3"&&(a.connectionId=this.connectionId),console.log("Sending DATA message with:",{type:"DATA",streamId:this.streamId,serviceId:this.config.serviceId,connectionId:this.config.protocol==="V3"?this.connectionId:void 0,payloadSize:i.length});const e=this.encodeMessage(a);this.sendFrame(e)}}sendFrame(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN){console.warn("Cannot send frame: WebSocket not open");return}const r=new Uint8Array(2+t.length);new DataView(r.buffer).setUint16(0,t.length,!1),r.set(t,2),console.log("Sending frame with length:",t.length,"Total frame size:",r.length),console.log("Frame bytes (first 20):",Array.from(r.slice(0,Math.min(20,r.length))).map(i=>i.toString(16).padStart(2,"0")).join(" ")),this.ws.send(r.buffer)}handleIncomingData(t){const r=new Uint8Array(this.receiveBuffer.length+t.length);for(r.set(this.receiveBuffer),r.set(t,this.receiveBuffer.length),this.receiveBuffer=r;this.receiveBuffer.length>=2;){const i=new DataView(this.receiveBuffer.buffer,this.receiveBuffer.byteOffset).getUint16(0,!1);if(this.receiveBuffer.length<2+i)break;const a=this.receiveBuffer.slice(2,2+i);this.receiveBuffer=this.receiveBuffer.slice(2+i),console.log("Received frame bytes:",Array.from(a).map(e=>e.toString(16).padStart(2,"0")).join(" "));try{const e=this.decodeMessage(a);this.handleMessage(e)}catch(e){console.error("Error decoding message:",e),this.onError&&this.onError(e)}}}handleMessage(t){var r;switch(console.log("Received message:",{type:this.getMessageTypeName(t.type),streamId:t.streamId,connectionId:t.connectionId,serviceId:t.serviceId,availableServiceIds:t.availableServiceIds,payloadSize:(r=t.payload)==null?void 0:r.length}),t.type){case TunnelMessageType.DATA:t.payload&&this.onData&&this.onData(t.payload);break;case TunnelMessageType.STREAM_START:console.log("Stream started:",t.streamId),this.config.clientMode==="destination"&&t.streamId!==void 0&&t.streamId!==null&&(this.streamId=t.streamId,console.log("Destination mode: Updated streamId to",this.streamId),this.tunnelReady=!0,this.processQueuedMessages());break;case TunnelMessageType.STREAM_RESET:console.log("Stream reset:",t.streamId),this.onClose&&this.onClose();break;case TunnelMessageType.SESSION_RESET:console.log("Session reset"),this.disconnect();break;case TunnelMessageType.SERVICE_IDS:console.log("Available service IDs:",t.availableServiceIds),this.config.clientMode==="source"&&(console.log("Source mode: Tunnel ready after receiving SERVICE_IDS"),this.tunnelReady=!0,this.processQueuedMessages());break;case TunnelMessageType.CONNECTION_START:console.log("Connection started:",t.connectionId);break;case TunnelMessageType.CONNECTION_RESET:console.log("Connection reset:",t.connectionId);break}}encodeMessage(t){const r=this.messageClass.create(t);return this.messageClass.encode(r).finish()}decodeMessage(t){return this.messageClass.decode(t)}getMessageTypeName(t){return{0:"UNKNOWN",1:"DATA",2:"STREAM_START",3:this.config.protocol==="V1"?"STREAM_END":"STREAM_RESET",4:"SESSION_RESET",5:"SERVICE_IDS",6:"CONNECTION_START",7:"CONNECTION_RESET"}[t]||`UNKNOWN_${t}`}}function detectFramework(){return typeof window>"u"?"generic":window.__NEXT_DATA__||window.next?"nextjs":window.__vite_plugin_react_preamble_installed__?"vite":window.__webpack_require__?"webpack":"generic"}function getAssetPaths(o){const t=detectFramework(),r=o.publicDir||"/";if(o.wasmPath&&o.wasmExecPath)return{wasmPath:o.wasmPath,wasmExecPath:o.wasmExecPath};switch(t){case"nextjs":return{wasmPath:o.wasmPath||`${r}sshclient.wasm`,wasmExecPath:o.wasmExecPath||`${r}wasm_exec.js`};case"vite":return{wasmPath:o.wasmPath||`${r}sshclient.wasm`,wasmExecPath:o.wasmExecPath||`${r}wasm_exec.js`};default:return{wasmPath:o.wasmPath||`${r}sshclient.wasm`,wasmExecPath:o.wasmExecPath||`${r}wasm_exec.js`}}}async function loadWasmExecutor(o,t=1e4){if(!(typeof window>"u")&&!window.Go)return new Promise((r,l)=>{const i=document.createElement("script");i.src=o,i.onload=()=>r(),i.onerror=()=>l(new Error(`Failed to load wasm_exec.js from ${o}`));const a=setTimeout(()=>{l(new Error(`Timeout loading wasm_exec.js from ${o}`))},t);i.onload=()=>{clearTimeout(a),r()},document.head.appendChild(i)})}async function testAssetAvailability(o,t){const r=async a=>{try{return(await fetch(a,{method:"HEAD"})).ok}catch{return!1}},[l,i]=await Promise.all([r(o),r(t)]);return{wasmAvailable:l,wasmExecAvailable:i}}const w=class w{static async initialize(t={}){var l;if(this.initialized)return;const r=typeof t=="string"?{wasmPath:t,autoDetect:!1}:{autoDetect:!0,cacheBusting:!0,timeout:1e4,...t};try{const{wasmPath:i,wasmExecPath:a}=getAssetPaths(r);if(r.autoDetect){const{wasmAvailable:d,wasmExecAvailable:p}=await testAssetAvailability(i,a);if(!d)throw new Error(`WASM file not found at ${i}. Please ensure sshclient.wasm is in your public directory.`);if(!p)throw new Error(`wasm_exec.js not found at ${a}. Please ensure wasm_exec.js is in your public directory.`)}if(await loadWasmExecutor(a,r.timeout),typeof window.Go>"u")throw new Error(`Go runtime not loaded. Failed to load wasm_exec.js from ${a}.`);const e=new window.Go;let n=i;if(r.cacheBusting){const d=`?v=${Date.now()}&t=${new Date().getTime()}`;n+=d}const s=r.cacheBusting?{cache:"no-cache",headers:{"Cache-Control":"no-cache",Pragma:"no-cache"}}:{},c=await fetch(n,s);if(!c.ok)throw new Error(`Failed to fetch WASM file: ${c.status} ${c.statusText}`);const u=await c.arrayBuffer(),f=await WebAssembly.instantiate(u,e.importObject);if(e.run(f.instance),await new Promise(d=>setTimeout(d,100)),this.wasmInstance=window.SSHClient,!this.wasmInstance)throw new Error("Failed to initialize WASM module - SSHClient not found on window. The WASM module may not have loaded correctly.");this.transportManager.setWasmInstance(this.wasmInstance),this.initialized=!0,typeof process<"u"&&((l=process.env)==null?void 0:l.NODE_ENV)==="development"&&(console.log("SSHClient WASM initialized successfully"),this.wasmInstance.version&&console.log(`Version: ${this.wasmInstance.version()}`))}catch(i){throw this.initialized=!1,i instanceof Error?new Error(`SSHClient initialization failed: ${i.message}`):new Error("SSHClient initialization failed with unknown error")}}static async connect(t,r,l){if(!this.initialized)throw new Error("SSHClient not initialized. Call initialize() first.");await this.transportManager.createTransport(r),await r.connect();const i=l?{onPacketSend:(e,n)=>{l.onPacketSend&&l.onPacketSend(e,n)},onPacketReceive:(e,n)=>{l.onPacketReceive&&l.onPacketReceive(e,n)},onStateChange:l.onStateChange}:void 0,a=await this.wasmInstance.connect(t,r.id,i);return{sessionId:a.sessionId,send:async e=>{await a.send(e)},disconnect:async()=>{await a.disconnect(),await this.transportManager.closeTransport(r.id)},resizeTerminal:async(e,n)=>{await a.resizeTerminal(e,n)}}}static async disconnect(t){if(!this.initialized)throw new Error("SSHClient not initialized");await this.wasmInstance.disconnect(t)}static async send(t,r){if(!this.initialized)throw new Error("SSHClient not initialized");await this.wasmInstance.send(t,r)}static getVersion(){if(!this.initialized)throw new Error("SSHClient not initialized");return this.wasmInstance.version()}};w.initialized=!1,w.transportManager=TransportManager.getInstance();let SSHClient=w;class PacketTransformer{static toProtobuf(t,r){return t}static fromProtobuf(t,r){return t}static toBase64(t){return btoa(String.fromCharCode(...t))}static fromBase64(t){const r=atob(t),l=new Uint8Array(r.length);for(let i=0;i<r.length;i++)l[i]=r.charCodeAt(i);return l}}const SSHClientHelpers={getAssetPaths:(o="/")=>getAssetPaths({publicDir:o}),detectFramework,testAssetAvailability,initializeForNextJS:async(o={})=>SSHClient.initialize({publicDir:"/",autoDetect:!0,cacheBusting:process.env.NODE_ENV==="development",...o}),initializeForVite:async(o={})=>{var r,l,i;let t=!1;try{t=((i=(l=(r=globalThis.import)==null?void 0:r.meta)==null?void 0:l.env)==null?void 0:i.DEV)===!0}catch{t=!1}return SSHClient.initialize({publicDir:"/",autoDetect:!0,cacheBusting:t,...o})},initializeWithDefaults:async(o={})=>{const t={autoDetect:!0,cacheBusting:!0,timeout:1e4,publicDir:"/"};return SSHClient.initialize({...t,...o})}};exports.CustomTransport=CustomTransport;exports.PacketTransformer=PacketTransformer;exports.SSHClient=SSHClient;exports.SSHClientHelpers=SSHClientHelpers;exports.SecureTunnelTransport=SecureTunnelTransport;exports.TunnelMessageType=TunnelMessageType;exports.WebSocketTransport=WebSocketTransport;exports.default=SSHClient;
2
+ //# sourceMappingURL=index.cjs.js.map