@@ -6,17 +6,26 @@ const CACHE_DIR = path.join(os.homedir(), ".browserstack", "combined_cache");
6
6
const CACHE_FILE = path . join ( CACHE_DIR , "data.json" ) ;
7
7
const TTL_MS = 24 * 60 * 60 * 1000 ; // 1 day
8
8
9
- const URLS = {
10
- live : "https://www.browserstack.com/list-of-browsers-and-platforms/live.json" ,
11
- app_live :
9
+ export enum BrowserStackProducts {
10
+ LIVE = "live" ,
11
+ APP_LIVE = "app_live" ,
12
+ APP_AUTOMATE = "app_automate" ,
13
+ }
14
+
15
+ const URLS : Record < BrowserStackProducts , string > = {
16
+ [ BrowserStackProducts . LIVE ] :
17
+ "https://www.browserstack.com/list-of-browsers-and-platforms/live.json" ,
18
+ [ BrowserStackProducts . APP_LIVE ] :
12
19
"https://www.browserstack.com/list-of-browsers-and-platforms/app_live.json" ,
20
+ [ BrowserStackProducts . APP_AUTOMATE ] :
21
+ "https://www.browserstack.com/list-of-browsers-and-platforms/app_automate.json" ,
13
22
} ;
14
23
15
24
/**
16
- * Fetches and caches both BrowserStack datasets (live + app_live) with a shared TTL.
25
+ * Fetches and caches BrowserStack datasets (live + app_live + app_automate ) with a shared TTL.
17
26
*/
18
27
export async function getDevicesAndBrowsers (
19
- type : "live" | "app_live" ,
28
+ type : BrowserStackProducts ,
20
29
) : Promise < any > {
21
30
if ( ! fs . existsSync ( CACHE_DIR ) ) {
22
31
fs . mkdirSync ( CACHE_DIR , { recursive : true } ) ;
@@ -29,31 +38,29 @@ export async function getDevicesAndBrowsers(
29
38
if ( Date . now ( ) - stats . mtimeMs < TTL_MS ) {
30
39
try {
31
40
cache = JSON . parse ( fs . readFileSync ( CACHE_FILE , "utf8" ) ) ;
32
- return cache [ type ] ;
41
+ if ( cache [ type ] ) {
42
+ return cache [ type ] ;
43
+ }
33
44
} catch ( error ) {
34
45
console . error ( "Error parsing cache file:" , error ) ;
35
46
// Continue with fetching fresh data
36
47
}
37
48
}
38
49
}
39
50
40
- const [ liveRes , appLiveRes ] = await Promise . all ( [
41
- fetch ( URLS . live ) ,
42
- fetch ( URLS . app_live ) ,
43
- ] ) ;
51
+ const liveRes = await fetch ( URLS [ type ] ) ;
44
52
45
- if ( ! liveRes . ok || ! appLiveRes . ok ) {
53
+ if ( ! liveRes . ok ) {
46
54
throw new Error (
47
- `Failed to fetch configuration from BrowserStack : live= ${ liveRes . statusText } , app_live =${ appLiveRes . statusText } ` ,
55
+ `Failed to fetch configuration from BrowserStack : ${ type } =${ liveRes . statusText } ` ,
48
56
) ;
49
57
}
50
58
51
- const [ liveData , appLiveData ] = await Promise . all ( [
52
- liveRes . json ( ) ,
53
- appLiveRes . json ( ) ,
54
- ] ) ;
59
+ const data = await liveRes . json ( ) ;
55
60
56
- cache = { live : liveData , app_live : appLiveData } ;
61
+ cache = {
62
+ [ type ] : data ,
63
+ } ;
57
64
fs . writeFileSync ( CACHE_FILE , JSON . stringify ( cache ) , "utf8" ) ;
58
65
59
66
return cache [ type ] ;
0 commit comments