(function(k,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(k=typeof globalThis<"u"?globalThis:k||self,f(k["browserstack-client"]={}))})(this,function(k){"use strict";var wt=Object.defineProperty;var yt=(k,f,_)=>f in k?wt(k,f,{enumerable:!0,configurable:!0,writable:!0,value:_}):k[f]=_;var U=(k,f,_)=>(yt(k,typeof f!="symbol"?f+"":f,_),_);const f=globalThis.process??{env:{},versions:{}},_={...f==null?void 0:f.env},Be={node:"unknown",...f==null?void 0:f.versions};f==null||f.platform,f==null||f.arch;class h extends Error{constructor(t,s){super(t);U(this,"code");U(this,"stack");U(this,"context");this.context=s,s instanceof Error&&(this.name=s.name,this.stack=s.stack,"code"in s&&typeof s.code=="string"&&(this.code=s.code))}}const Ee=[{url:"{scheme}://{host}{basePath}",variables:{scheme:{default:"https"},host:{default:"api.browserstack.com"},basePath:{default:"/5"}}},{url:"{scheme}://{host}",variables:{scheme:{default:"https"},host:{default:"api-cloud.browserstack.com"}}}],R={name:"browserstack-client",version:"3.5.5",description:"BrowserStack APIs client library for node.js",type:"module",main:"./dist/browserstack-client.umd.cjs",bin:{"browserstack-local":"./dist/node/browserstack-local.cjs","browserstack-app-automate":"./dist/node/browserstack-app-automate.cjs"},module:"./dist/browserstack-client.js",types:"./dist/types/index.d.ts",exports:{".":{types:"./dist/types/index.d.ts",import:"./dist/browserstack-client.js",require:"./dist/browserstack-client.umd.cjs"},"./node":{types:"./dist/types/index.node.d.ts",import:"./dist/node/browserstack-client.js",require:"./dist/node/browserstack-client.cjs"},"./package.json":"./package.json","./*":"./dist/*"},scripts:{prebuild:"node build.mjs && npm run lint",build:"tsc && vite build && vite build --config vite.config.node.ts",test:"vitest run --typecheck","test-watch":"vitest --typecheck",coverage:"vitest run --coverage.enabled --coverage.include=src --coverage.exclude=src/generated",lint:"eslint . --ext .ts","predocs:dev":"typedoc","docs:dev":"vitepress dev docs","predocs:build":"typedoc","docs:build":"vitepress build docs","docs:preview":"vitepress preview docs","generate:java":"npx @openapitools/openapi-generator-cli generate --generator-key java","generate:kotlin":"npx @openapitools/openapi-generator-cli generate --generator-key kotlin","generate:csharp":"npx @openapitools/openapi-generator-cli generate --generator-key csharp","generate:ruby":"npx @openapitools/openapi-generator-cli generate --generator-key ruby"},author:"Shirish Kamath",license:"MIT",files:["dist/**/*","*.d.ts"],engines:{node:">=18.0.0"},devDependencies:{"@apidevtools/swagger-parser":"^10.1.0","@types/node":"^20.11.19","@typescript-eslint/eslint-plugin":"^7.0.1","@typescript-eslint/parser":"^7.0.1","@vitest/coverage-v8":"1.2.1",eslint:"^8.56.0","openapi-typescript":"^7.0.0-next.7","openapi-typescript-helpers":"^0.0.7",typedoc:"^0.25.9","typedoc-plugin-markdown":"^4.0.0-next.43","typedoc-vitepress-theme":"^1.0.0-next.9",typescript:"^5.3.3",vite:"^5.1.4","vite-plugin-dts":"^3.7.3",vitepress:"^1.0.0-rc.44",vitest:"1.2.1"},dependencies:{fflate:"^0.8.2","openapi-fetch":"0.9.2","signal-exit":"^4.1.0"},repository:{type:"git",url:"git://github.com/shirish87/browserstack-client.git"},homepage:"https://shirish87.github.io/browserstack-client/",bugs:{url:"https://github.com/shirish87/browserstack-client/issues"},keywords:["browserstack","api","client","node","javascript","typescript","esm"]},Ue=[R==null?void 0:R.name,R==null?void 0:R.version].filter(Boolean).join("/"),Fe=["node",Be.node].filter(Boolean).join("/"),ze=[Ue,Fe].filter(Boolean).join(" "),$e={name:R==null?void 0:R.name,version:R==null?void 0:R.version,userAgent:ze},Le={"Content-Type":"application/json"},Oe=/\{[^{}]+\}/g;function ce(a){let{baseUrl:e="",fetch:t=globalThis.fetch,querySerializer:s,bodySerializer:r,headers:n,...i}={...a};e.endsWith("/")&&(e=e.substring(0,e.length-1)),n=he(Le,n);const u=[];async function c(l,p){let{fetch:o=t,headers:m,params:g={},parseAs:j="json",querySerializer:S,bodySerializer:T=r??Me,...x}=p||{},F=typeof s=="function"?s:fe(s);S&&(F=typeof S=="function"?S:fe({...typeof s=="object"?s:{},...S}));const w={redirect:"follow",...i,...x,headers:he(n,m,g.header)};w.body&&(w.body=T(w.body)),w.body instanceof FormData&&w.headers.delete("Content-Type");let C=new Request(He(l,{baseUrl:e,params:g,querySerializer:F}),w);const L={baseUrl:e,fetch:o,parseAs:j,querySerializer:F,bodySerializer:T};for(const D of u)if(D&&typeof D=="object"&&typeof D.onRequest=="function"){C.schemaPath=l,C.params=g;const y=await D.onRequest(C,L);if(y){if(!(y instanceof Request))throw new Error("Middleware must return new Request() when modifying the request");C=y}}let v=await o(C);for(let D=u.length-1;D>=0;D--){const y=u[D];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){const z=await y.onResponse(v,L);if(z){if(!(z instanceof Response))throw new Error("Middleware must return new Response() when modifying the response");v=z}}}if(v.status===204||v.headers.get("Content-Length")==="0")return v.ok?{data:{},response:v}:{error:{},response:v};if(v.ok)return j==="stream"?{data:v.body,response:v}:{data:await v[j](),response:v};let O=await v.text();try{O=JSON.parse(O)}catch{}return{error:O,response:v}}return{async GET(l,p){return c(l,{...p,method:"GET"})},async PUT(l,p){return c(l,{...p,method:"PUT"})},async POST(l,p){return c(l,{...p,method:"POST"})},async DELETE(l,p){return c(l,{...p,method:"DELETE"})},async OPTIONS(l,p){return c(l,{...p,method:"OPTIONS"})},async HEAD(l,p){return c(l,{...p,method:"HEAD"})},async PATCH(l,p){return c(l,{...p,method:"PATCH"})},async TRACE(l,p){return c(l,{...p,method:"TRACE"})},use(...l){for(const p of l)if(p){if(typeof p!="object"||!("onRequest"in p||"onResponse"in p))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");u.push(p)}},eject(...l){for(const p of l){const o=u.indexOf(p);o!==-1&&u.splice(o,1)}}}}function V(a,e,t){if(e==null)return"";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${a}=${(t==null?void 0:t.allowReserved)===!0?e:encodeURIComponent(e)}`}function me(a,e,t){if(!e||typeof e!="object")return"";const s=[],r={simple:",",label:".",matrix:";"}[t.style]||"&";if(t.style!=="deepObject"&&t.explode===!1){for(const u in e)s.push(u,t.allowReserved===!0?e[u]:encodeURIComponent(e[u]));const i=s.join(",");switch(t.style){case"form":return`${a}=${i}`;case"label":return`.${i}`;case"matrix":return`;${a}=${i}`;default:return i}}for(const i in e){const u=t.style==="deepObject"?`${a}[${i}]`:i;s.push(V(u,e[i],t))}const n=s.join(r);return t.style==="label"||t.style==="matrix"?`${r}${n}`:n}function de(a,e,t){if(!Array.isArray(e))return"";if(t.explode===!1){const n={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[t.style]||",",i=(t.allowReserved===!0?e:e.map(u=>encodeURIComponent(u))).join(n);switch(t.style){case"simple":return i;case"label":return`.${i}`;case"matrix":return`;${a}=${i}`;case"spaceDelimited":case"pipeDelimited":default:return`${a}=${i}`}}const s={simple:",",label:".",matrix:";"}[t.style]||"&",r=[];for(const n of e)t.style==="simple"||t.style==="label"?r.push(t.allowReserved===!0?n:encodeURIComponent(n)):r.push(V(a,n,t));return t.style==="label"||t.style==="matrix"?`${s}${r.join(s)}`:r.join(s)}function fe(a){return function(t){const s=[];if(t&&typeof t=="object")for(const r in t){const n=t[r];if(n!=null){if(Array.isArray(n)){s.push(de(r,n,{style:"form",explode:!0,...a==null?void 0:a.array,allowReserved:(a==null?void 0:a.allowReserved)||!1}));continue}if(typeof n=="object"){s.push(me(r,n,{style:"deepObject",explode:!0,...a==null?void 0:a.object,allowReserved:(a==null?void 0:a.allowReserved)||!1}));continue}s.push(V(r,n,a))}}return s.join("&")}}function We(a,e){let t=a;for(const s of a.match(Oe)??[]){let r=s.substring(1,s.length-1),n=!1,i="simple";if(r.endsWith("*")&&(n=!0,r=r.substring(0,r.length-1)),r.startsWith(".")?(i="label",r=r.substring(1)):r.startsWith(";")&&(i="matrix",r=r.substring(1)),!e||e[r]===void 0||e[r]===null)continue;const u=e[r];if(Array.isArray(u)){t=t.replace(s,de(r,u,{style:i,explode:n}));continue}if(typeof u=="object"){t=t.replace(s,me(r,u,{style:i,explode:n}));continue}if(i==="matrix"){t=t.replace(s,`;${V(r,u)}`);continue}t=t.replace(s,i==="label"?`.${u}`:u)}return t}function Me(a){return JSON.stringify(a)}function He(a,e){var r;let t=`${e.baseUrl}${a}`;(r=e.params)!=null&&r.path&&(t=We(t,e.params.path));let s=e.querySerializer(e.params.query??{});return s.startsWith("?")&&(s=s.substring(1)),s&&(t+=`?${s}`),t}function he(...a){const e=new Headers;for(const t of a){if(!t||typeof t!="object")continue;const s=t instanceof Headers?t.entries():Object.entries(t);for(const[r,n]of s)if(n===null)e.delete(r);else if(Array.isArray(n))for(const i of n)e.append(r,i);else n!==void 0&&e.set(r,n)}return e}const[{variables:X},{variables:Q}]=Ee??[],Je=`${X.scheme.default}://${X.host.default}${X.basePath?X.basePath.default:""}`,Ke=`${Q.scheme.default}://${Q.host.default}${Q.basePath?Q.basePath.default:""}`;class H{constructor(e){U(this,"sdk");U(this,"sdkCloud");const t=e.username??_.BROWSERSTACK_USERNAME;if(e.usernameOptional!==!0&&(typeof t!="string"||!t.trim().length))throw new h("Missing options.username");const s=e.key??_.BROWSERSTACK_KEY;if(typeof s!="string"||!s.trim().length)throw new h("Missing options.key");const r={...e,baseUrl:e.baseUrl??Je,headers:{...e.headers,Authorization:t?`Basic ${btoa(`${t}:${s}`)}`:void 0,"User-Agent":$e.userAgent}};this.sdk=ce(r),this.sdkCloud=ce({...r,baseUrl:Ke})}async makeGetRequest(e,...t){const s=await this.sdk.GET(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makePostRequest(e,...t){const s=await this.sdk.POST(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makeCloudGetRequest(e,...t){const s=await this.sdkCloud.GET(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makeCloudPostRequest(e,...t){const s=await this.sdkCloud.POST(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makePutRequest(e,...t){const s=await this.sdk.PUT(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makePatchRequest(e,...t){const s=await this.sdk.PATCH(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}async makeDeleteRequest(e,...t){const s=await this.sdk.DELETE(e,...t);if(s.error||!s.data)throw new h("Request failed",{path:e,response:s,...t});return s.data}}class ge extends H{constructor(e){super({...e,baseUrl:(e==null?void 0:e.baseUrl)??"https://api.browserstack.com"})}getPlan(e){return this.makeGetRequest("/app-automate/plan.json",e)}getDevices(e){return this.makeGetRequest("/app-automate/devices.json",e)}getProjects(e){return this.makeGetRequest("/app-automate/projects.json",e)}getProject(e,t){return this.makeGetRequest("/app-automate/projects/{projectId}.json",{...t,params:{path:{projectId:e}}}).then(s=>s.project)}updateProject(e,t,s){return this.makePutRequest("/app-automate/projects/{projectId}.json",{...s,params:{path:{projectId:e}},body:t})}deleteProject(e,t){return this.makeDeleteRequest("/app-automate/projects/{projectId}.json",{...t,params:{path:{projectId:e}}})}getBadgeKey(e,t){return this.makeGetRequest("/app-automate/projects/{projectId}/badge_key",{...t,params:{path:{projectId:e}},parseAs:"text"})}getBuilds(e,t){return this.makeGetRequest("/app-automate/builds.json",{...t,params:{query:e}}).then(s=>s.map(r=>r.automation_build))}getBuild(e,t){return this.makeGetRequest("/app-automate/builds/{buildId}.json",{...t,params:{path:{buildId:e}}}).then(s=>({...s.build.automation_build,sessions:s.build.sessions.map(r=>r.automation_session)}))}updateBuild(e,t,s){return this.makePutRequest("/app-automate/builds/{buildId}.json",{...s,body:t,params:{path:{buildId:e}}}).then(r=>{if("error"in r)throw new h(r.error,{response:r});return r.automation_build})}deleteBuild(e,t){return this.makeDeleteRequest("/app-automate/builds/{buildId}.json",{...t,params:{path:{buildId:e}}})}uploadBuildTerminalLogs(e,t,s){return this.makeCloudPostRequest("/app-automate/builds/{buildId}/terminallogs",{...s,body:t,bodySerializer:r=>{const n=new FormData;return n.append("file",r.file,t.filename),n},params:{path:{buildId:e}}})}uploadSessionTerminalLogs(e,t,s){return this.makeCloudPostRequest("/app-automate/sessions/{sessionId}/terminallogs",{...s,body:t,bodySerializer:r=>{const n=new FormData;return n.append("file",r.file,t.filename),n},params:{path:{sessionId:e}}})}getSession(e,t){return this.makeGetRequest("/app-automate/sessions/{sessionId}.json",{...t,params:{path:{sessionId:e}}}).then(s=>s.automation_session)}updateSessionStatus(e,t,s){return this.makePutRequest("/app-automate/sessions/{sessionId}.json",{...s,body:t,params:{path:{sessionId:e}}}).then(r=>r.automation_session)}deleteSession(e,t){return this.makeDeleteRequest("/app-automate/sessions/{sessionId}.json",{...t,params:{path:{sessionId:e}}})}getSessionLogs(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/logs",{...s,params:{path:{buildId:e,sessionId:t}},parseAs:"text"})}getSessionDeviceLogs(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/devicelogs",{...s,params:{path:{buildId:e,sessionId:t}},parseAs:"text"})}getSessionAppiumLogs(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/appiumlogs",{...s,params:{path:{buildId:e,sessionId:t}},parseAs:"text"})}getSessionNetworkLogs(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/networklogs",{...s,params:{path:{buildId:e,sessionId:t}}})}getSessionAppProfilingDataV1(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/appprofiling",{...s,params:{path:{buildId:e,sessionId:t}}})}getSessionAppProfilingDataV2(e,t,s){return this.makeGetRequest("/app-automate/builds/{buildId}/sessions/{sessionId}/appprofiling/v2",{...s,params:{path:{buildId:e,sessionId:t}}})}uploadMediaFile(e,t){return this.makePostRequest("/app-automate/upload-media",{...t,body:e,bodySerializer:s=>{const r=new FormData;return r.append("file",s.file,e.filename),s.custom_id&&r.append("custom_id",s.custom_id),r}})}getMediaFiles(e){return this.makeGetRequest("/app-automate/recent_media_files",e).then(t=>"message"in t?[]:t)}getMediaFilesByCustomId(e,t){return this.makeGetRequest("/app-automate/recent_media_files/{customId}",{...t,params:{path:{customId:e}}}).then(s=>"message"in s?[]:s)}getGroupMediaFiles(e){return this.makeGetRequest("/app-automate/recent_group_media",e).then(t=>"message"in t?[]:t)}deleteMediaFile(e,t){return this.makeDeleteRequest("/app-automate/custom_media/delete/{mediaId}",{...t,params:{path:{mediaId:e}}})}uploadAppiumApp(e,t){return this.makePostRequest("/app-automate/upload",{...t,body:e,bodySerializer:s=>{const r=new FormData;return"file"in s?r.append("file",s.file,e.filename):r.append("url",s.url),s.custom_id&&r.append("custom_id",s.custom_id),r}})}getAppiumApps(e){return this.makeGetRequest("/app-automate/recent_apps",e).then(t=>"message"in t?[]:t)}getAppiumAppsByCustomId(e,t){return this.makeGetRequest("/app-automate/recent_apps/{customId}",{...t,params:{path:{customId:e}}}).then(s=>"message"in s?[]:s)}getAppiumGroupApps(e){return this.makeGetRequest("/app-automate/recent_group_apps",e).then(t=>"message"in t?[]:t)}deleteAppiumApp(e,t){return this.makeDeleteRequest("/app-automate/app/delete/{appId}",{...t,params:{path:{appId:e}}})}uploadFlutterApp(e,t,s){return this.makePostRequest(e==="android"?"/app-automate/flutter-integration-tests/v2/android/app":"/app-automate/flutter-integration-tests/v2/ios/test-package",{...s,body:t,bodySerializer:r=>{const n=new FormData;return"file"in r?n.append("file",r.file,t.filename):n.append("url",r.url),r.custom_id&&n.append("custom_id",r.custom_id),n}})}getFlutterApps(e,t){return this.makeGetRequest(e==="android"?"/app-automate/flutter-integration-tests/v2/android/apps":"/app-automate/flutter-integration-tests/v2/ios/test-packages",t).then(s=>"apps"in s?s.apps:"test_packages"in s?s.test_packages:[])}getFlutterApp(e,t,s){return this.makeGetRequest(e==="android"?"/app-automate/flutter-integration-tests/v2/android/apps/{appId}":"/app-automate/flutter-integration-tests/v2/ios/test-package/{appId}",{...s,params:{path:{appId:t}}}).then(r=>"app"in r?r.app:r.test_package)}deleteFlutterApp(e,t,s){return this.makeDeleteRequest(e==="android"?"/app-automate/flutter-integration-tests/v2/android/apps/{appId}":"/app-automate/flutter-integration-tests/v2/ios/test-package/{appId}",{...s,params:{path:{appId:t}}})}uploadEspressoApp(e,t){return this.makePostRequest("/app-automate/espresso/v2/app",{...t,body:e,bodySerializer:s=>{const r=new FormData;return"file"in s?r.append("file",s.file,e.filename):r.append("url",s.url),s.custom_id&&r.append("custom_id",s.custom_id),r}})}getEspressoApps(e){return this.makeGetRequest("/app-automate/espresso/v2/apps",e).then(t=>"apps"in t?t.apps:[])}getEspressoApp(e,t){return this.makeGetRequest("/app-automate/espresso/v2/apps/{appId}",{...t,params:{path:{appId:e}}}).then(s=>s.app)}deleteEspressoApp(e,t){return this.makeDeleteRequest("/app-automate/espresso/v2/apps/{appId}",{...t,params:{path:{appId:e}}})}uploadXCUITestApp(e,t){return this.makePostRequest("/app-automate/xcuitest/v2/app",{...t,body:e,bodySerializer:s=>{const r=new FormData;return"file"in s?r.append("file",s.file,e.filename):r.append("url",s.url),s.custom_id&&r.append("custom_id",s.custom_id),r}})}getXCUITestApps(e){return this.makeGetRequest("/app-automate/xcuitest/v2/apps",e).then(t=>"apps"in t?t.apps:[])}getXCUITestApp(e,t){return this.makeGetRequest("/app-automate/xcuitest/v2/apps/{appId}",{...t,params:{path:{appId:e}}}).then(s=>s.app)}deleteXCUITestApp(e,t){return this.makeDeleteRequest("/app-automate/xcuitest/v2/apps/{appId}",{...t,params:{path:{appId:e}}})}uploadDetoxAndroidApp(e,t,s){return this.makePostRequest(e?"/app-automate/detox/v2/android/app":"/app-automate/detox/v2/android/app-client",{...s,body:t,bodySerializer:r=>{const n=new FormData;return"file"in r?n.append("file",r.file,t.filename):n.append("url",r.url),r.custom_id&&n.append("custom_id",r.custom_id),n}})}}var ke=(a=>(a.android="android",a.ios="ios",a))(ke||{});class ve extends H{constructor(e){super({...e,baseUrl:(e==null?void 0:e.baseUrl)??"https://api.browserstack.com"})}recycleKey(e){return this.makePutRequest("/automate/recycle_key.json",e)}getPlan(e){return this.makeGetRequest("/automate/plan.json",e)}getBrowsers(e){return this.makeGetRequest("/automate/browsers.json",e)}getProjects(e){return this.makeGetRequest("/automate/projects.json",e)}getProject(e,t){return this.makeGetRequest("/automate/projects/{projectId}.json",{...t,params:{path:{projectId:e}}}).then(s=>s.project)}updateProject(e,t,s){return this.makePutRequest("/automate/projects/{projectId}.json",{...s,body:t,params:{path:{projectId:e}}})}deleteProject(e,t){return this.makeDeleteRequest("/automate/projects/{projectId}.json",{...t,params:{path:{projectId:e}}})}getBadgeKey(e,t){return this.makeGetRequest("/automate/projects/{projectId}/badge_key",{...t,params:{path:{projectId:e}},parseAs:"text"})}getBuilds(e,t){return this.makeGetRequest("/automate/builds.json",{...t,params:{query:e}}).then(s=>s.map(r=>r.automation_build))}getBuild(e,t){return this.makeGetRequest("/automate/builds/{buildId}.json",{...t,params:{path:{buildId:e}}}).then(s=>({...s.build.automation_build,sessions:s.build.sessions.map(r=>r.automation_session)}))}updateBuild(e,t,s){return this.makePutRequest("/automate/builds/{buildId}.json",{...s,body:t,params:{path:{buildId:e}}}).then(r=>{if("error"in r)throw new h(r.error,{response:r});return r.automation_build})}deleteBuild(e,t){return this.makeDeleteRequest("/automate/builds/{buildId}.json",{...t,params:{path:{buildId:e}}})}deleteBuilds(e,t){return this.makeDeleteRequest("/automate/builds",{...t,params:{query:{"buildId[]":e}}})}getSessions(e,t,s){return this.makeGetRequest("/automate/builds/{buildId}/sessions.json",{...s,params:{path:{buildId:e},query:t}}).then(r=>r.map(n=>n.automation_session))}getSession(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}.json",{...t,params:{path:{sessionId:e}}}).then(s=>s.automation_session)}updateSession(e,t,s){return this.makePutRequest("/automate/sessions/{sessionId}.json",{...s,body:t,params:{path:{sessionId:e}}}).then(r=>r.automation_session)}deleteSession(e,t){return this.makeDeleteRequest("/automate/sessions/{sessionId}.json",{...t,params:{path:{sessionId:e}}})}deleteSessions(e,t){return this.makeDeleteRequest("/automate/sessions",{...t,params:{query:{"sessionId[]":e}}})}uploadBuildTerminalLogs(e,t,s){return this.makeCloudPostRequest("/automate/builds/{buildId}/terminallogs",{...s,body:t,bodySerializer:r=>{const n=new FormData;return n.append("file",r.file,t.filename),n},params:{path:{buildId:e}}})}uploadSessionTerminalLogs(e,t,s){return this.makeCloudPostRequest("/automate/sessions/{sessionId}/terminallogs",{...s,body:t,bodySerializer:r=>{const n=new FormData;return n.append("file",r.file,t.filename),n},params:{path:{sessionId:e}}})}getSessionLogs(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}/logs",{...t,params:{path:{sessionId:e}},parseAs:"text"})}getSessionNetworkLogs(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}/networklogs",{...t,params:{path:{sessionId:e}}})}getSessionConsoleLogs(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}/consolelogs",{...t,params:{path:{sessionId:e}},parseAs:"text"})}getSessionSeleniumLogs(e,t){return this.makeCloudGetRequest("/automate/sessions/{sessionId}/seleniumlogs",{...t,params:{path:{sessionId:e}},parseAs:"text"})}getSessionAppiumLogs(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}/appiumlogs",{...t,params:{path:{sessionId:e}},parseAs:"text"})}getSessionTelemetryLogs(e,t){return this.makeGetRequest("/automate/sessions/{sessionId}/telemetrylogs",{...t,params:{path:{sessionId:e}}})}uploadMediaFile(e,t){return this.makePostRequest("/automate/upload-media",{...t,body:e,bodySerializer:s=>{const r=new FormData;return r.append("file",s.file,e.filename),r}})}getMediaFiles(e){return this.makeGetRequest("/automate/recent_media_files",e)}deleteMediaFile(e,t){return this.makeDeleteRequest("/automate/custom_media/delete/{mediaId}",{...t,params:{path:{mediaId:e}}})}}class te extends H{constructor(e){super({...e,baseUrl:(e==null?void 0:e.baseUrl)??"https://api.browserstack.com/5"})}getAccountStatus(){return this.makeGetRequest("/status")}getBrowsers(e,t){return this.makeGetRequest("/browsers",{...t,params:{query:{...e,flat:typeof(e==null?void 0:e.flat)=="boolean"?e.flat:!0}}})}createWorker(e,t){return this.makePostRequest("/worker",{...t,body:e})}getWorkers(e){return this.makeGetRequest("/workers",e)}getWorker(e,t){return this.makeGetRequest("/worker/{workerId}",{...t,params:{path:{workerId:e}}})}deleteWorker(e,t){return this.makeDeleteRequest("/worker/{workerId}",{...t,params:{path:{workerId:e}}})}updateWorkerURL(e,t,s){return this.makePutRequest("/worker/{workerId}/url.json",{...s,params:{path:{workerId:e}},body:t})}getWorkerScreenshot(e,t,s){return this.makeGetRequest("/worker/{workerId}/screenshot.{format}",{...s,params:{path:{workerId:e,format:t??"png"}},parseAs:t==="json"?"json":t==="xml"?"text":"arrayBuffer"})}ensureWorkerRunning(e,t,s=1e4){return new Promise((r,n)=>{let i;const u=(l,p)=>{var o;clearInterval(c),(o=i==null?void 0:i.abort)==null||o.call(i),l?n(l instanceof h?l:new h(l.message,l)):p&&r(p)},c=setInterval(async()=>{i=t!=null&&t.signal?void 0:new AbortController;const l=await this.getWorker(e,{...t,signal:(t==null?void 0:t.signal)??(i==null?void 0:i.signal)}).catch(u);l&&(l.id?l.status==="running"&&u(void 0,l):u(new h(`Worker ${e} is no longer running`)))},s)})}async launch(e,t){const{pollInterval:s,...r}=t??{},{id:n}=await this.createWorker(e,r),i=await this.ensureWorkerRunning(n,void 0,s),u={...i,updateURL:c=>this.updateWorkerURL(i.id,{url:c}),getScreenshot:()=>this.getWorkerScreenshot(i.id,"png"),getScreenshotURL:()=>this.getWorkerScreenshot(i.id,"json").then(c=>c.url),terminate:async()=>this.deleteWorker(i.id).then(c=>(u.status=void 0,c))};return u}}var b=Uint8Array,$=Uint16Array,Ne=Int32Array,we=new b([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ye=new b([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ve=new b([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),be=function(a,e){for(var t=new $(31),s=0;s<31;++s)t[s]=e+=1<>1|(d&21845)<<1;B=(B&52428)>>2|(B&13107)<<2,B=(B&61680)>>4|(B&3855)<<4,se[d]=((B&65280)>>8|(B&255)<<8)>>1}for(var J=function(a,e,t){for(var s=a.length,r=0,n=new $(e);r>c]=l}else for(u=new $(s),r=0;r>15-a[r]);return u},K=new b(288),d=0;d<144;++d)K[d]=8;for(var d=144;d<256;++d)K[d]=9;for(var d=256;d<280;++d)K[d]=7;for(var d=280;d<288;++d)K[d]=8;for(var je=new b(32),d=0;d<32;++d)je[d]=5;var Ze=J(K,9,1),et=J(je,5,1),re=function(a){for(var e=a[0],t=1;te&&(e=a[t]);return e},A=function(a,e,t){var s=e/8|0;return(a[s]|a[s+1]<<8)>>(e&7)&t},ae=function(a,e){var t=e/8|0;return(a[t]|a[t+1]<<8|a[t+2]<<16)>>(e&7)},tt=function(a){return(a+7)/8|0},ne=function(a,e,t){return(e==null||e<0)&&(e=0),(t==null||t>a.length)&&(t=a.length),new b(a.subarray(e,t))},st=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],q=function(a,e,t){var s=new Error(e||st[a]);if(s.code=a,Error.captureStackTrace&&Error.captureStackTrace(s,q),!t)throw s;return s},rt=function(a,e,t,s){var r=a.length,n=s?s.length:0;if(!r||e.f&&!e.l)return t||new b(0);var i=!t,u=i||e.i!=2,c=e.i;i&&(t=new b(r*3));var l=function(xe){var _e=t.length;if(xe>_e){var Ce=new b(Math.max(_e*2,xe));Ce.set(t),t=Ce}},p=e.f||0,o=e.p||0,m=e.b||0,g=e.l,j=e.d,S=e.m,T=e.n,x=r*8;do{if(!g){p=A(a,o,1);var F=A(a,o+1,3);if(o+=3,F)if(F==1)g=Ze,j=et,S=9,T=5;else if(F==2){var v=A(a,o,31)+257,O=A(a,o+10,15)+4,D=v+A(a,o+5,31)+1;o+=14;for(var y=new b(D),z=new b(19),I=0;I>4;if(w<16)y[I++]=w;else{var W=0,ee=0;for(w==16?(ee=3+A(a,o,3),o+=2,W=y[I-1]):w==17?(ee=3+A(a,o,7),o+=3):w==18&&(ee=11+A(a,o,127),o+=7);ee--;)y[I++]=W}}var Pe=y.subarray(0,v),E=y.subarray(v);S=re(Pe),T=re(E),g=J(Pe,S,1),j=J(E,T,1)}else q(1);else{var w=tt(o)+4,C=a[w-4]|a[w-3]<<8,L=w+C;if(L>r){c&&q(0);break}u&&l(m+C),t.set(a.subarray(w,L),m),e.b=m+=C,e.p=o=L*8,e.f=p;continue}if(o>x){c&&q(0);break}}u&&l(m+131072);for(var gt=(1<>4;if(o+=W&15,o>x){c&&q(0);break}if(W||q(2),M<256)t[m++]=M;else if(M==256){ue=o,g=null;break}else{var De=M-254;if(M>264){var I=M-257,N=we[I];De=A(a,o,(1<>4;le||q(3),o+=le&15;var E=Ye[pe];if(pe>3){var N=ye[pe];E+=ae(a,o)&(1<x){c&&q(0);break}u&&l(m+131072);var Ge=m+De;if(m>>0},ie=function(a,e){return P(a,e)+P(a,e+4)*4294967296};function nt(a,e){return rt(a,{i:2},e&&e.out,e&&e.dictionary)}var oe=typeof TextDecoder<"u"&&new TextDecoder,it=0;try{oe.decode(at,{stream:!0}),it=1}catch{}var ot=function(a){for(var e="",t=0;;){var s=a[t++],r=(s>127)+(s>223)+(s>239);if(t+r>a.length)return{s:e,r:ne(a,t-1)};r?r==3?(s=((s&15)<<18|(a[t++]&63)<<12|(a[t++]&63)<<6|a[t++]&63)-65536,e+=String.fromCharCode(55296|s>>10,56320|s&1023)):r&1?e+=String.fromCharCode((s&31)<<6|a[t++]&63):e+=String.fromCharCode((s&15)<<12|(a[t++]&63)<<6|a[t++]&63):e+=String.fromCharCode(s)}};function ut(a,e){if(e){for(var t="",s=0;s65558)&&q(13);var r=G(a,s+8);if(!r)return{};var n=P(a,s+16),i=n==4294967295||r==65535;if(i){var u=P(a,s-12);i=P(a,u)==101075792,i&&(r=P(a,u+32),n=P(a,u+48))}for(var c=e&&e.filter,l=0;lr.instances)}getBinaryInstance(t,s,r){return this.makeGetRequest("/local/v1/{localInstanceId}",{...r,params:{path:{localInstanceId:t},query:{...s,auth_token:this.authToken}}}).then(n=>{if(!n.instances.length)throw new h(`No Local binary instance found with id "${t}"`);return n.instances[0]})}disconnectBinaryInstance(t,s,r){return this.makeDeleteRequest("/local/v1/{localInstanceId}",{...r,params:{path:{localInstanceId:t},query:{...s,auth_token:this.authToken}}}).then(n=>n.message)}downloadBinary(t,s="BrowserStackLocal",r){return this.sdk.GET("/browserstack-local/BrowserStackLocal-{osArch}.zip",{...r,params:{path:{osArch:t}},parseAs:"arrayBuffer"}).then(({data:n})=>{if(!n)throw new h(`Failed to download BrowserStackLocal-${t}.zip: Unexpected response.`);const i=mt(new Uint8Array(n),{filter:l=>l.name.startsWith(s)}),u=Object.keys(i);if(!u.length)throw new h(`Local binary not found in BrowserStackLocal-${t}.zip`);return{content:i[u[0]],filename:u[0]}}).catch(n=>{throw n instanceof h?n:new h(`Failed to write local binary to disk: ${n.message}: ${n.stack}`)})}}const Z=class Z extends H{constructor(e){super({...e,baseUrl:(e==null?void 0:e.baseUrl)??"https://www.browserstack.com"})}getBrowsers(e){return this.makeGetRequest("/screenshots/browsers.json",e)}createJob(e,t){return this.makePostRequest("/screenshots",{...t,body:e}).then(s=>({...s,id:s.job_id}))}getJob(e,t){return this.makeGetRequest("/screenshots/{jobId}.json",{...t,params:{path:{jobId:e}}}).then(s=>({...s,id:s.id??s.job_id}))}trackJob(e,t,s,r=1e4){return new Promise((n,i)=>{const u=new Map;let c;const l=o=>{var m;clearInterval(p),(m=c==null?void 0:c.abort)==null||m.call(c),o?i(o instanceof h?o:new h(o.message,o)):n(Array.from(u.values()))},p=setInterval(async()=>{c=s!=null&&s.signal?void 0:new AbortController;const o=await this.getJob(e,{...s,signal:(s==null?void 0:s.signal)??(c==null?void 0:c.signal)}).catch(l);if(!o)return;const m=o.screenshots??[];for(const g of m)Z.jobCompleteStates.includes(g.state)&&(u.has(g.id)||u.set(g.id,g),await(t==null?void 0:t(g)));(o.state==="done"||m.length===u.size)&&l()},r)})}async launch(e,t,s){const{pollInterval:r,...n}=s??{},{id:i}=await this.createJob(e,n);return this.trackJob(i,t,void 0,r)}};U(Z,"jobCompleteStates",["done","error"]);let Y=Z;const dt={AutomateClient:ve,ScreenshotsClient:Y,AppAutomateClient:ge,JSTestingClient:te,Client:te,LocalTestingClient:Se};k.AppAutomateClient=ge,k.AutomateClient=ve,k.BrowserStack=dt,k.FlutterPlatform=ke,k.JSTestingClient=te,k.LocalTestingClient=Se,k.ScreenshotsClient=Y,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});