mobitru-mobile-cli 1.0.0-beta.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  `).join(`
5
5
  `+s),t.push(o+"m+"+Ki.exports.humanize(this.diff)+"\x1B[0m")}else t[0]=Eh()+e+" "+t[0]}function Eh(){return K.inspectOpts.hideDate?"":new Date().toISOString()+" "}function Th(...t){return process.stderr.write(Gi.formatWithOptions(K.inspectOpts,...t)+`
6
6
  `)}function kh(t){t?process.env.DEBUG=t:delete process.env.DEBUG}function Ch(){return process.env.DEBUG}function Ph(t){t.inspectOpts={};let e=Object.keys(K.inspectOpts);for(let i=0;i<e.length;i++)t.inspectOpts[e[i]]=K.inspectOpts[e[i]]}Ki.exports=mo()(K);var{formatters:qc}=Ki.exports;qc.o=function(t){return this.inspectOpts.colors=this.useColors,Gi.inspect(t,this.inspectOpts).split(`
7
- `).map(e=>e.trim()).join(" ")};qc.O=function(t){return this.inspectOpts.colors=this.useColors,Gi.inspect(t,this.inspectOpts)}});var Mc=T((Db,go)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?go.exports=Nc():go.exports=Dc()});var Jc=T((Mb,zc)=>{var Zt;zc.exports=function(){if(!Zt){try{Zt=Mc()("follow-redirects")}catch{}typeof Zt!="function"&&(Zt=function(){})}Zt.apply(null,arguments)}});var Kc=T((zb,Ro)=>{var ei=require("url"),Qt=ei.URL,Rh=require("http"),Ah=require("https"),wo=require("stream").Writable,So=require("assert"),Hc=Jc();(function(){var e=typeof process<"u",i=typeof window<"u"&&typeof document<"u",n=Qe(Error.captureStackTrace);!e&&(i||!n)&&console.warn("The follow-redirects package should be excluded from browser builds.")})();var Eo=!1;try{So(new Qt(""))}catch(t){Eo=t.code==="ERR_INVALID_URL"}var Oh=["auth","host","hostname","href","path","pathname","port","protocol","query","search","hash"],To=["abort","aborted","connect","error","socket","timeout"],ko=Object.create(null);To.forEach(function(t){ko[t]=function(e,i,n){this._redirectable.emit(t,e,i,n)}});var vo=ti("ERR_INVALID_URL","Invalid URL",TypeError),bo=ti("ERR_FR_REDIRECTION_FAILURE","Redirected request failed"),Ih=ti("ERR_FR_TOO_MANY_REDIRECTS","Maximum number of redirects exceeded",bo),_h=ti("ERR_FR_MAX_BODY_LENGTH_EXCEEDED","Request body larger than maxBodyLength limit"),$h=ti("ERR_STREAM_WRITE_AFTER_END","write after end"),Nh=wo.prototype.destroy||Wc;function ae(t,e){wo.call(this),this._sanitizeOptions(t),this._options=t,this._ended=!1,this._ending=!1,this._redirectCount=0,this._redirects=[],this._requestBodyLength=0,this._requestBodyBuffers=[],e&&this.on("response",e);var i=this;this._onNativeResponse=function(n){try{i._processResponse(n)}catch(o){i.emit("error",o instanceof bo?o:new bo({cause:o}))}},this._performRequest()}ae.prototype=Object.create(wo.prototype);ae.prototype.abort=function(){Po(this._currentRequest),this._currentRequest.abort(),this.emit("abort")};ae.prototype.destroy=function(t){return Po(this._currentRequest,t),Nh.call(this,t),this};ae.prototype.write=function(t,e,i){if(this._ending)throw new $h;if(!Ze(t)&&!Uh(t))throw new TypeError("data should be a string, Buffer or Uint8Array");if(Qe(e)&&(i=e,e=null),t.length===0){i&&i();return}this._requestBodyLength+t.length<=this._options.maxBodyLength?(this._requestBodyLength+=t.length,this._requestBodyBuffers.push({data:t,encoding:e}),this._currentRequest.write(t,e,i)):(this.emit("error",new _h),this.abort())};ae.prototype.end=function(t,e,i){if(Qe(t)?(i=t,t=e=null):Qe(e)&&(i=e,e=null),!t)this._ended=this._ending=!0,this._currentRequest.end(null,null,i);else{var n=this,o=this._currentRequest;this.write(t,e,function(){n._ended=!0,o.end(null,null,i)}),this._ending=!0}};ae.prototype.setHeader=function(t,e){this._options.headers[t]=e,this._currentRequest.setHeader(t,e)};ae.prototype.removeHeader=function(t){delete this._options.headers[t],this._currentRequest.removeHeader(t)};ae.prototype.setTimeout=function(t,e){var i=this;function n(a){a.setTimeout(t),a.removeListener("timeout",a.destroy),a.addListener("timeout",a.destroy)}function o(a){i._timeout&&clearTimeout(i._timeout),i._timeout=setTimeout(function(){i.emit("timeout"),s()},t),n(a)}function s(){i._timeout&&(clearTimeout(i._timeout),i._timeout=null),i.removeListener("abort",s),i.removeListener("error",s),i.removeListener("response",s),i.removeListener("close",s),e&&i.removeListener("timeout",e),i.socket||i._currentRequest.removeListener("socket",o)}return e&&this.on("timeout",e),this.socket?o(this.socket):this._currentRequest.once("socket",o),this.on("socket",n),this.on("abort",s),this.on("error",s),this.on("response",s),this.on("close",s),this};["flushHeaders","getHeader","setNoDelay","setSocketKeepAlive"].forEach(function(t){ae.prototype[t]=function(e,i){return this._currentRequest[t](e,i)}});["aborted","connection","socket"].forEach(function(t){Object.defineProperty(ae.prototype,t,{get:function(){return this._currentRequest[t]}})});ae.prototype._sanitizeOptions=function(t){if(t.headers||(t.headers={}),t.host&&(t.hostname||(t.hostname=t.host),delete t.host),!t.pathname&&t.path){var e=t.path.indexOf("?");e<0?t.pathname=t.path:(t.pathname=t.path.substring(0,e),t.search=t.path.substring(e))}};ae.prototype._performRequest=function(){var t=this._options.protocol,e=this._options.nativeProtocols[t];if(!e)throw new TypeError("Unsupported protocol "+t);if(this._options.agents){var i=t.slice(0,-1);this._options.agent=this._options.agents[i]}var n=this._currentRequest=e.request(this._options,this._onNativeResponse);n._redirectable=this;for(var o of To)n.on(o,ko[o]);if(this._currentUrl=/^\//.test(this._options.path)?ei.format(this._options):this._options.path,this._isRedirect){var s=0,a=this,r=this._requestBodyBuffers;(function p(l){if(n===a._currentRequest)if(l)a.emit("error",l);else if(s<r.length){var c=r[s++];n.finished||n.write(c.data,c.encoding,p)}else a._ended&&n.end()})()}};ae.prototype._processResponse=function(t){var e=t.statusCode;this._options.trackRedirects&&this._redirects.push({url:this._currentUrl,headers:t.headers,statusCode:e});var i=t.headers.location;if(!i||this._options.followRedirects===!1||e<300||e>=400){t.responseUrl=this._currentUrl,t.redirects=this._redirects,this.emit("response",t),this._requestBodyBuffers=[];return}if(Po(this._currentRequest),t.destroy(),++this._redirectCount>this._options.maxRedirects)throw new Ih;var n,o=this._options.beforeRedirect;o&&(n=Object.assign({Host:t.req.getHeader("host")},this._options.headers));var s=this._options.method;((e===301||e===302)&&this._options.method==="POST"||e===303&&!/^(?:GET|HEAD)$/.test(this._options.method))&&(this._options.method="GET",this._requestBodyBuffers=[],xo(/^content-/i,this._options.headers));var a=xo(/^host$/i,this._options.headers),r=Co(this._currentUrl),p=a||r.host,l=/^\w+:/.test(i)?this._currentUrl:ei.format(Object.assign(r,{host:p})),c=Fh(i,l);if(Hc("redirecting to",c.href),this._isRedirect=!0,yo(c,this._options),(c.protocol!==r.protocol&&c.protocol!=="https:"||c.host!==p&&!jh(c.host,p))&&xo(/^(?:(?:proxy-)?authorization|cookie)$/i,this._options.headers),Qe(o)){var d={headers:t.headers,statusCode:e},f={url:l,method:s,headers:n};o(this._options,d,f),this._sanitizeOptions(this._options)}this._performRequest()};function Vc(t){var e={maxRedirects:21,maxBodyLength:10485760},i={};return Object.keys(t).forEach(function(n){var o=n+":",s=i[o]=t[n],a=e[n]=Object.create(s);function r(l,c,d){return Bh(l)?l=yo(l):Ze(l)?l=yo(Co(l)):(d=c,c=Gc(l),l={protocol:o}),Qe(c)&&(d=c,c=null),c=Object.assign({maxRedirects:e.maxRedirects,maxBodyLength:e.maxBodyLength},l,c),c.nativeProtocols=i,!Ze(c.host)&&!Ze(c.hostname)&&(c.hostname="::1"),So.equal(c.protocol,o,"protocol mismatch"),Hc("options",c),new ae(c,d)}function p(l,c,d){var f=a.request(l,c,d);return f.end(),f}Object.defineProperties(a,{request:{value:r,configurable:!0,enumerable:!0,writable:!0},get:{value:p,configurable:!0,enumerable:!0,writable:!0}})}),e}function Wc(){}function Co(t){var e;if(Eo)e=new Qt(t);else if(e=Gc(ei.parse(t)),!Ze(e.protocol))throw new vo({input:t});return e}function Fh(t,e){return Eo?new Qt(t,e):Co(ei.resolve(e,t))}function Gc(t){if(/^\[/.test(t.hostname)&&!/^\[[:0-9a-f]+\]$/i.test(t.hostname))throw new vo({input:t.href||t});if(/^\[/.test(t.host)&&!/^\[[:0-9a-f]+\](:\d+)?$/i.test(t.host))throw new vo({input:t.href||t});return t}function yo(t,e){var i=e||{};for(var n of Oh)i[n]=t[n];return i.hostname.startsWith("[")&&(i.hostname=i.hostname.slice(1,-1)),i.port!==""&&(i.port=Number(i.port)),i.path=i.search?i.pathname+i.search:i.pathname,i}function xo(t,e){var i;for(var n in e)t.test(n)&&(i=e[n],delete e[n]);return i===null||typeof i>"u"?void 0:String(i).trim()}function ti(t,e,i){function n(o){Qe(Error.captureStackTrace)&&Error.captureStackTrace(this,this.constructor),Object.assign(this,o||{}),this.code=t,this.message=this.cause?e+": "+this.cause.message:e}return n.prototype=new(i||Error),Object.defineProperties(n.prototype,{constructor:{value:n,enumerable:!1},name:{value:"Error ["+t+"]",enumerable:!1}}),n}function Po(t,e){for(var i of To)t.removeListener(i,ko[i]);t.on("error",Wc),t.destroy(e)}function jh(t,e){So(Ze(t)&&Ze(e));var i=t.length-e.length-1;return i>0&&t[i]==="."&&t.endsWith(e)}function Ze(t){return typeof t=="string"||t instanceof String}function Qe(t){return typeof t=="function"}function Uh(t){return typeof t=="object"&&"length"in t}function Bh(t){return Qt&&t instanceof Qt}Ro.exports=Vc({http:Rh,https:Ah});Ro.exports.wrap=Vc});var Nu=require("commander");var gn=require("commander");var rl=require("child_process"),cl=C(require("net")),pl=C(require("fs"));var As=C(require("fs")),kn=C(require("os")),Ue=C(require("path")),Os=C(require("crypto")),Is=Ue.default.join(kn.default.homedir(),".mobitru-cli","mobile"),zu="default",_s=Ue.default.join(Is,"sessions"),Se=Ue.default.join(Is,"appium-runtime"),Ju=t=>Os.default.createHash("sha1").update(`${kn.default.homedir()}\0${t}`,"utf-8").digest("hex").slice(0,8),He=t=>Ue.default.join(_s,t),Re=t=>process.platform==="win32"?String.raw`\\.\pipe\mobitru-cli-mobile-${Ju(t)}`:Ue.default.join(He(t),"daemon.sock"),$s=t=>Ue.default.join(He(t),"daemon.lock"),Ns=t=>Ue.default.join(He(t),"daemon.log"),Hu=t=>{if(!/^[a-zA-Z0-9_-]{1,32}$/.test(t))throw new Error(`Invalid session name "${t}": use only letters, digits, hyphen, or underscore (1-32 characters).`)},Fs=t=>{let e=t??process.env.MOBITRU_CLI_SESSION;return e?(Hu(e),e):zu},Ae=()=>{let t=process.env.MOBITRU_CLI_SESSION;if(!t)throw new Error("Session not resolved.");return t},Ei=()=>{try{return As.default.readdirSync(_s,{withFileTypes:!0}).filter(t=>t.isDirectory()).map(t=>t.name)}catch{return[]}};var il=C(require("fs")),hn=require("commander");var Ys=C(require("fastify")),$e=C(require("fs")),Zs=C(require("path"));var Ti=C(require("fs"));var js=C(require("os")),Cn=C(require("path")),Vu=process.env.MOBITRU_CLI_HOME||Cn.default.join(js.default.homedir(),".mobitru-cli"),ie=Cn.default.join(Vu,"config.json"),Us="1.0.0-beta.1";var Lt=class extends Error{constructor(){super(["Mobitru credentials not configured.","","Set environment variables:"," DEVICE_FARM_BASE_URL"," DEVICE_FARM_BROWSER_HUB_BASE_URL"," DEVICE_FARM_API_KEY"," DEVICE_FARM_SLUG",' DEVICE_FARM_WID (optional, default "0")',"",`Or create ${ie} with shape:`," {",' "baseUrl": "app.mobitru.com",',' "browserHubBaseUrl": "https://browserhub-us.mobitru.com",',' "apiKey": "...",',' "slug": "...",',' "wid": "0"'," }"].join(`
7
+ `).map(e=>e.trim()).join(" ")};qc.O=function(t){return this.inspectOpts.colors=this.useColors,Gi.inspect(t,this.inspectOpts)}});var Mc=T((Db,go)=>{typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?go.exports=Nc():go.exports=Dc()});var Jc=T((Mb,zc)=>{var Zt;zc.exports=function(){if(!Zt){try{Zt=Mc()("follow-redirects")}catch{}typeof Zt!="function"&&(Zt=function(){})}Zt.apply(null,arguments)}});var Kc=T((zb,Ro)=>{var ei=require("url"),Qt=ei.URL,Rh=require("http"),Ah=require("https"),wo=require("stream").Writable,So=require("assert"),Hc=Jc();(function(){var e=typeof process<"u",i=typeof window<"u"&&typeof document<"u",n=Qe(Error.captureStackTrace);!e&&(i||!n)&&console.warn("The follow-redirects package should be excluded from browser builds.")})();var Eo=!1;try{So(new Qt(""))}catch(t){Eo=t.code==="ERR_INVALID_URL"}var Oh=["auth","host","hostname","href","path","pathname","port","protocol","query","search","hash"],To=["abort","aborted","connect","error","socket","timeout"],ko=Object.create(null);To.forEach(function(t){ko[t]=function(e,i,n){this._redirectable.emit(t,e,i,n)}});var vo=ti("ERR_INVALID_URL","Invalid URL",TypeError),bo=ti("ERR_FR_REDIRECTION_FAILURE","Redirected request failed"),Ih=ti("ERR_FR_TOO_MANY_REDIRECTS","Maximum number of redirects exceeded",bo),_h=ti("ERR_FR_MAX_BODY_LENGTH_EXCEEDED","Request body larger than maxBodyLength limit"),$h=ti("ERR_STREAM_WRITE_AFTER_END","write after end"),Nh=wo.prototype.destroy||Wc;function ae(t,e){wo.call(this),this._sanitizeOptions(t),this._options=t,this._ended=!1,this._ending=!1,this._redirectCount=0,this._redirects=[],this._requestBodyLength=0,this._requestBodyBuffers=[],e&&this.on("response",e);var i=this;this._onNativeResponse=function(n){try{i._processResponse(n)}catch(o){i.emit("error",o instanceof bo?o:new bo({cause:o}))}},this._performRequest()}ae.prototype=Object.create(wo.prototype);ae.prototype.abort=function(){Po(this._currentRequest),this._currentRequest.abort(),this.emit("abort")};ae.prototype.destroy=function(t){return Po(this._currentRequest,t),Nh.call(this,t),this};ae.prototype.write=function(t,e,i){if(this._ending)throw new $h;if(!Ze(t)&&!Uh(t))throw new TypeError("data should be a string, Buffer or Uint8Array");if(Qe(e)&&(i=e,e=null),t.length===0){i&&i();return}this._requestBodyLength+t.length<=this._options.maxBodyLength?(this._requestBodyLength+=t.length,this._requestBodyBuffers.push({data:t,encoding:e}),this._currentRequest.write(t,e,i)):(this.emit("error",new _h),this.abort())};ae.prototype.end=function(t,e,i){if(Qe(t)?(i=t,t=e=null):Qe(e)&&(i=e,e=null),!t)this._ended=this._ending=!0,this._currentRequest.end(null,null,i);else{var n=this,o=this._currentRequest;this.write(t,e,function(){n._ended=!0,o.end(null,null,i)}),this._ending=!0}};ae.prototype.setHeader=function(t,e){this._options.headers[t]=e,this._currentRequest.setHeader(t,e)};ae.prototype.removeHeader=function(t){delete this._options.headers[t],this._currentRequest.removeHeader(t)};ae.prototype.setTimeout=function(t,e){var i=this;function n(a){a.setTimeout(t),a.removeListener("timeout",a.destroy),a.addListener("timeout",a.destroy)}function o(a){i._timeout&&clearTimeout(i._timeout),i._timeout=setTimeout(function(){i.emit("timeout"),s()},t),n(a)}function s(){i._timeout&&(clearTimeout(i._timeout),i._timeout=null),i.removeListener("abort",s),i.removeListener("error",s),i.removeListener("response",s),i.removeListener("close",s),e&&i.removeListener("timeout",e),i.socket||i._currentRequest.removeListener("socket",o)}return e&&this.on("timeout",e),this.socket?o(this.socket):this._currentRequest.once("socket",o),this.on("socket",n),this.on("abort",s),this.on("error",s),this.on("response",s),this.on("close",s),this};["flushHeaders","getHeader","setNoDelay","setSocketKeepAlive"].forEach(function(t){ae.prototype[t]=function(e,i){return this._currentRequest[t](e,i)}});["aborted","connection","socket"].forEach(function(t){Object.defineProperty(ae.prototype,t,{get:function(){return this._currentRequest[t]}})});ae.prototype._sanitizeOptions=function(t){if(t.headers||(t.headers={}),t.host&&(t.hostname||(t.hostname=t.host),delete t.host),!t.pathname&&t.path){var e=t.path.indexOf("?");e<0?t.pathname=t.path:(t.pathname=t.path.substring(0,e),t.search=t.path.substring(e))}};ae.prototype._performRequest=function(){var t=this._options.protocol,e=this._options.nativeProtocols[t];if(!e)throw new TypeError("Unsupported protocol "+t);if(this._options.agents){var i=t.slice(0,-1);this._options.agent=this._options.agents[i]}var n=this._currentRequest=e.request(this._options,this._onNativeResponse);n._redirectable=this;for(var o of To)n.on(o,ko[o]);if(this._currentUrl=/^\//.test(this._options.path)?ei.format(this._options):this._options.path,this._isRedirect){var s=0,a=this,r=this._requestBodyBuffers;(function p(l){if(n===a._currentRequest)if(l)a.emit("error",l);else if(s<r.length){var c=r[s++];n.finished||n.write(c.data,c.encoding,p)}else a._ended&&n.end()})()}};ae.prototype._processResponse=function(t){var e=t.statusCode;this._options.trackRedirects&&this._redirects.push({url:this._currentUrl,headers:t.headers,statusCode:e});var i=t.headers.location;if(!i||this._options.followRedirects===!1||e<300||e>=400){t.responseUrl=this._currentUrl,t.redirects=this._redirects,this.emit("response",t),this._requestBodyBuffers=[];return}if(Po(this._currentRequest),t.destroy(),++this._redirectCount>this._options.maxRedirects)throw new Ih;var n,o=this._options.beforeRedirect;o&&(n=Object.assign({Host:t.req.getHeader("host")},this._options.headers));var s=this._options.method;((e===301||e===302)&&this._options.method==="POST"||e===303&&!/^(?:GET|HEAD)$/.test(this._options.method))&&(this._options.method="GET",this._requestBodyBuffers=[],xo(/^content-/i,this._options.headers));var a=xo(/^host$/i,this._options.headers),r=Co(this._currentUrl),p=a||r.host,l=/^\w+:/.test(i)?this._currentUrl:ei.format(Object.assign(r,{host:p})),c=Fh(i,l);if(Hc("redirecting to",c.href),this._isRedirect=!0,yo(c,this._options),(c.protocol!==r.protocol&&c.protocol!=="https:"||c.host!==p&&!jh(c.host,p))&&xo(/^(?:(?:proxy-)?authorization|cookie)$/i,this._options.headers),Qe(o)){var d={headers:t.headers,statusCode:e},f={url:l,method:s,headers:n};o(this._options,d,f),this._sanitizeOptions(this._options)}this._performRequest()};function Vc(t){var e={maxRedirects:21,maxBodyLength:10485760},i={};return Object.keys(t).forEach(function(n){var o=n+":",s=i[o]=t[n],a=e[n]=Object.create(s);function r(l,c,d){return Bh(l)?l=yo(l):Ze(l)?l=yo(Co(l)):(d=c,c=Gc(l),l={protocol:o}),Qe(c)&&(d=c,c=null),c=Object.assign({maxRedirects:e.maxRedirects,maxBodyLength:e.maxBodyLength},l,c),c.nativeProtocols=i,!Ze(c.host)&&!Ze(c.hostname)&&(c.hostname="::1"),So.equal(c.protocol,o,"protocol mismatch"),Hc("options",c),new ae(c,d)}function p(l,c,d){var f=a.request(l,c,d);return f.end(),f}Object.defineProperties(a,{request:{value:r,configurable:!0,enumerable:!0,writable:!0},get:{value:p,configurable:!0,enumerable:!0,writable:!0}})}),e}function Wc(){}function Co(t){var e;if(Eo)e=new Qt(t);else if(e=Gc(ei.parse(t)),!Ze(e.protocol))throw new vo({input:t});return e}function Fh(t,e){return Eo?new Qt(t,e):Co(ei.resolve(e,t))}function Gc(t){if(/^\[/.test(t.hostname)&&!/^\[[:0-9a-f]+\]$/i.test(t.hostname))throw new vo({input:t.href||t});if(/^\[/.test(t.host)&&!/^\[[:0-9a-f]+\](:\d+)?$/i.test(t.host))throw new vo({input:t.href||t});return t}function yo(t,e){var i=e||{};for(var n of Oh)i[n]=t[n];return i.hostname.startsWith("[")&&(i.hostname=i.hostname.slice(1,-1)),i.port!==""&&(i.port=Number(i.port)),i.path=i.search?i.pathname+i.search:i.pathname,i}function xo(t,e){var i;for(var n in e)t.test(n)&&(i=e[n],delete e[n]);return i===null||typeof i>"u"?void 0:String(i).trim()}function ti(t,e,i){function n(o){Qe(Error.captureStackTrace)&&Error.captureStackTrace(this,this.constructor),Object.assign(this,o||{}),this.code=t,this.message=this.cause?e+": "+this.cause.message:e}return n.prototype=new(i||Error),Object.defineProperties(n.prototype,{constructor:{value:n,enumerable:!1},name:{value:"Error ["+t+"]",enumerable:!1}}),n}function Po(t,e){for(var i of To)t.removeListener(i,ko[i]);t.on("error",Wc),t.destroy(e)}function jh(t,e){So(Ze(t)&&Ze(e));var i=t.length-e.length-1;return i>0&&t[i]==="."&&t.endsWith(e)}function Ze(t){return typeof t=="string"||t instanceof String}function Qe(t){return typeof t=="function"}function Uh(t){return typeof t=="object"&&"length"in t}function Bh(t){return Qt&&t instanceof Qt}Ro.exports=Vc({http:Rh,https:Ah});Ro.exports.wrap=Vc});var Nu=require("commander");var gn=require("commander");var rl=require("child_process"),cl=C(require("net")),pl=C(require("fs"));var As=C(require("fs")),kn=C(require("os")),Ue=C(require("path")),Os=C(require("crypto")),Is=Ue.default.join(kn.default.homedir(),".mobitru-cli","mobile"),zu="default",_s=Ue.default.join(Is,"sessions"),Se=Ue.default.join(Is,"appium-runtime"),Ju=t=>Os.default.createHash("sha1").update(`${kn.default.homedir()}\0${t}`,"utf-8").digest("hex").slice(0,8),He=t=>Ue.default.join(_s,t),Re=t=>process.platform==="win32"?String.raw`\\.\pipe\mobitru-cli-mobile-${Ju(t)}`:Ue.default.join(He(t),"daemon.sock"),$s=t=>Ue.default.join(He(t),"daemon.lock"),Ns=t=>Ue.default.join(He(t),"daemon.log"),Hu=t=>{if(!/^[a-zA-Z0-9_-]{1,32}$/.test(t))throw new Error(`Invalid session name "${t}": use only letters, digits, hyphen, or underscore (1-32 characters).`)},Fs=t=>{let e=t??process.env.MOBITRU_CLI_SESSION;return e?(Hu(e),e):zu},Ae=()=>{let t=process.env.MOBITRU_CLI_SESSION;if(!t)throw new Error("Session not resolved.");return t},Ei=()=>{try{return As.default.readdirSync(_s,{withFileTypes:!0}).filter(t=>t.isDirectory()).map(t=>t.name)}catch{return[]}};var il=C(require("fs")),hn=require("commander");var Ys=C(require("fastify")),$e=C(require("fs")),Zs=C(require("path"));var Ti=C(require("fs"));var js=C(require("os")),Cn=C(require("path")),Vu=process.env.MOBITRU_CLI_HOME||Cn.default.join(js.default.homedir(),".mobitru-cli"),ie=Cn.default.join(Vu,"config.json"),Us="1.0.0";var Lt=class extends Error{constructor(){super(["Mobitru credentials not configured.","","Set environment variables:"," DEVICE_FARM_BASE_URL"," DEVICE_FARM_BROWSER_HUB_BASE_URL"," DEVICE_FARM_API_KEY"," DEVICE_FARM_SLUG",' DEVICE_FARM_WID (optional, default "0")',"",`Or create ${ie} with shape:`," {",' "baseUrl": "app.mobitru.com",',' "browserHubBaseUrl": "https://browserhub-us.mobitru.com",',' "apiKey": "...",',' "slug": "...",',' "wid": "0"'," }"].join(`
8
8
  `)),this.name="MissingCredentialsError"}};function Oe(t){return typeof t=="string"&&t.length>0}function Wu(){let t=process.env.DEVICE_FARM_BASE_URL,e=process.env.DEVICE_FARM_BROWSER_HUB_BASE_URL,i=process.env.DEVICE_FARM_API_KEY,n=process.env.DEVICE_FARM_SLUG,o=process.env.DEVICE_FARM_WID||"0";return Oe(t)&&Oe(e)&&Oe(i)&&Oe(n)?{baseUrl:t,browserHubBaseUrl:e,apiKey:i,slug:n,wid:o}:null}function Gu(t){if(process.platform!=="win32")try{Ti.default.statSync(t).mode&63&&process.stderr.write(`warn: ${t} is readable by other users. Run: chmod 600 ${t}
9
9
  `)}catch{}}function Ku(){if(!Ti.default.existsSync(ie))return null;Gu(ie);let t=Ti.default.readFileSync(ie,"utf8"),e=JSON.parse(t);return Oe(e.baseUrl)&&Oe(e.browserHubBaseUrl)&&Oe(e.apiKey)&&Oe(e.slug)?{config:{baseUrl:e.baseUrl,browserHubBaseUrl:e.browserHubBaseUrl,apiKey:e.apiKey,slug:e.slug,wid:Oe(e.wid)?e.wid:"0"},path:ie}:null}function Pn(){let t=Wu();if(t)return{config:t,source:"env"};let e=Ku();if(e)return{config:e.config,source:"file",path:e.path};throw new Lt}function Xu(t){return`****${t.slice(-4)}`}function Bs(){let t=Pn();return{source:t.source,...t.path?{path:t.path}:{},config:{baseUrl:t.config.baseUrl,browserHubBaseUrl:t.config.browserHubBaseUrl,apiKey:Xu(t.config.apiKey),slug:t.config.slug,wid:t.config.wid}}}var I=class extends Error{constructor(i,n){super(i);this.statusCode=n;this.name="CloudApiError"}};var Rn=["up","down","left","right"];function Ls(t){return Rn.includes(t)}var An=["HOME","BACK","VOLUME_UP","VOLUME_DOWN","ENTER","DPAD_CENTER","DPAD_UP","DPAD_DOWN","DPAD_LEFT","DPAD_RIGHT"];function qs(t){return An.includes(t)}var H=class extends Error{constructor(e){super(e)}},On=["portrait","landscape"];function Ds(t){return On.includes(t)}var ki=class{busy=!1;tryAcquire(){return this.busy?!1:(this.busy=!0,!0)}release(){this.busy=!1}};var Ri=require("child_process"),ce=C(require("fs")),Ie=C(require("path")),Vs=require("util");var ge=C(require("fs")),Ms=C(require("path")),Yu=1e4;async function Ci(t,e=Yu){let i=Ms.default.dirname(t);for(ge.default.existsSync(i)||ge.default.mkdirSync(i,{recursive:!0});;)try{let n=ge.default.openSync(t,ge.default.constants.O_CREAT|ge.default.constants.O_EXCL|ge.default.constants.O_WRONLY);ge.default.closeSync(n);return}catch(n){if(n.code!=="EEXIST")throw n;try{let o=ge.default.statSync(t);if(Date.now()-o.mtimeMs>e){ge.default.unlinkSync(t);continue}}catch{continue}await Zu(50)}}function Pi(t){try{ge.default.unlinkSync(t)}catch{}}var Zu=t=>new Promise(e=>setTimeout(e,t));var Ee=class{constructor(e){this.config=e;this.baseUrl=`https://${e.baseUrl}`,this.headers={Authorization:`Bearer ${e.apiKey}`,"Content-Type":"application/json"}}baseUrl;headers;async findDevice(e){let{platform:i,type:n,manufacturer:o,model:s,version:a,web:r,owner:p,dc:l}=e,c=new URLSearchParams;n&&c.append("type",n),o&&c.append("manufacturer",o),s&&c.append("model",s),a&&c.append("version",a),r&&c.append("web",r),p&&c.append("owner",p),l&&c.append("dc",l);let d=c.toString()?`?${c.toString()}`:"",f=`${this.baseUrl}/billing/unit/${this.config.slug}/workspace/${this.config.wid}/automation/api/device/${i}${d}`,w=await fetch(f,{method:"GET",headers:this.headers});if(!w.ok)throw new I(`Failed to find device: ${w.status} ${w.statusText}`,w.status);return await w.json()}async getDeviceInfo(e){let i=`${this.baseUrl}/billing/unit/${this.config.slug}/workspace/${this.config.wid}/automation/api/device/${e}`,n=await fetch(i,{method:"GET",headers:this.headers});if(!n.ok)throw new I(`Failed to get device info: ${n.status} ${n.statusText}`,n.status);return await n.json()}async takeDeviceBySerial(e,i=180){let n=`${this.baseUrl}/billing/unit/${this.config.slug}/workspace/${this.config.wid}/automation/api/device/${e}?duration=${i}`,o=await fetch(n,{method:"POST",headers:this.headers,body:"{}"});if(!o.ok)throw new I(`Failed to take device: ${o.status} ${o.statusText}`,o.status);return await o.json()}async takeDeviceByCapabilities(e,i=30){let n=`${this.baseUrl}/billing/unit/${this.config.slug}/workspace/${this.config.wid}/automation/api/device`,o=await fetch(n,{method:"POST",headers:this.headers,body:JSON.stringify({duration:i,desiredCapabilities:e})});if(!o.ok)throw new I(`Failed to take device: ${o.status} ${o.statusText}`,o.status);return await o.json()}async releaseDevice(e){let i=`${this.baseUrl}/billing/unit/${this.config.slug}/workspace/${this.config.wid}/automation/api/device/${e}`,n=await fetch(i,{method:"DELETE",headers:this.headers});if(!n.ok)throw new I(`Failed to release device: ${n.status} ${n.statusText}`,n.status);return await n.json()}};var Qu=(0,Vs.promisify)(Ri.execFile);function _e(t){return t.status==="running"}var ed=1200*1e3,Ws=5e3,Gs=process.env.MOBILE_CLI_WEBDRIVERIO_VERSION||"9.27.1",Ks=process.env.MOBILE_CLI_MOCHA_VERSION||"11.7.5",td=6e4,id=t=>`spec-${t}.js`,zs=Ie.default.join(Se,".install.lock"),nd=300*1e3,od=process.platform==="win32"?"npm.cmd":"npm",sd=process.platform==="win32"?"npx.cmd":"npx";function ad(t){let e=new Date(t),i=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${i(e.getMonth()+1)}-${i(e.getDate())}T${i(e.getHours())}-${i(e.getMinutes())}-${i(e.getSeconds())}`}function rd(t){return t.replace(/[^A-Za-z0-9_-]/g,"_")}function cd(t,e,i){return Ie.default.join(t,"appium-runs",`${ad(i)}_${rd(e)}.log`)}function Js(t){try{let e=Ie.default.join(Se,"node_modules",t,"package.json");return JSON.parse(ce.default.readFileSync(e,"utf8")).version}catch{return null}}function Hs(){return Js("webdriverio")===Gs&&Js("mocha")===Ks}async function pd(){try{await Qu(od,["install","--loglevel=error","--no-audit","--no-fund",`webdriverio@${Gs}`,`mocha@${Ks}`],{cwd:Se,maxBuffer:10*1024*1024})}catch(t){let e=t,i=`${e.stdout??""}${e.stderr??""}`.trim();throw new Error(`npm install exited ${e.code}${i?`
10
10
  ${i.slice(-2048)}`:""}`)}}async function ld(){if(ce.default.mkdirSync(Se,{recursive:!0}),!Hs()){await Ci(zs,nd);try{if(Hs())return;ce.default.rmSync(Ie.default.join(Se,"node_modules"),{recursive:!0,force:!0}),ce.default.rmSync(Ie.default.join(Se,"package-lock.json"),{force:!0}),ce.default.rmSync(Ie.default.join(Se,"package.json"),{force:!0}),await pd()}finally{Pi(zs)}}}function ud(t){let e=Buffer.from(`${t.slug}:${t.apiKey}`).toString("base64");return`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobitru-mobile-cli",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0",
4
4
  "description": "Mobitru CLI (mobile) — command-line tool for AI agents to automate mobile testing on Mobitru cloud (Appium-backed)",
5
5
  "keywords": [
6
6
  "mobitru",