File tree Expand file tree Collapse file tree 4 files changed +66
-67
lines changed
Expand file tree Collapse file tree 4 files changed +66
-67
lines changed Original file line number Diff line number Diff line change 11import sharp from "sharp" ;
22
3- export interface LogResponse {
4- logs ?: any [ ] ;
5- message ?: string ;
6- }
7-
8- export interface HarFile {
9- log : {
10- entries : HarEntry [ ] ;
11- } ;
12- }
13-
14- export interface HarEntry {
15- startedDateTime : string ;
16- request : {
17- method : string ;
18- url : string ;
19- queryString ?: { name : string ; value : string } [ ] ;
20- } ;
21- response : {
22- status : number ;
23- statusText ?: string ;
24- _error ?: string ;
25- } ;
26- serverIPAddress ?: string ;
27- time ?: number ;
28- }
29-
30- export function validateResponse (
31- response : Response ,
32- logType : string ,
33- ) : LogResponse | null {
34- if ( ! response . ok ) {
35- if ( response . status === 404 ) {
36- return { message : `No ${ logType } available for this session` } ;
37- }
38- if ( response . status === 401 || response . status === 403 ) {
39- return {
40- message : `Unable to access ${ logType } - please check your credentials` ,
41- } ;
42- }
43- return { message : `Unable to fetch ${ logType } at this time` } ;
44- }
45- return null ;
46- }
47-
483export function sanitizeUrlParam ( param : string ) : string {
494 // Remove any characters that could be used for command injection
505 return param . replace ( / [ ; & | ` $ ( ) { } [ \] < > ] / g, "" ) ;
@@ -79,15 +34,3 @@ export async function assertOkResponse(response: Response, action: string) {
7934 ) ;
8035 }
8136}
82-
83- export function filterLinesByKeywords (
84- logText : string ,
85- keywords : string [ ] ,
86- ) : string [ ] {
87- return logText
88- . split ( / \r ? \n / )
89- . map ( ( line ) => line . trim ( ) )
90- . filter ( ( line ) =>
91- keywords . some ( ( keyword ) => line . toLowerCase ( ) . includes ( keyword ) ) ,
92- ) ;
93- }
Original file line number Diff line number Diff line change 11import config from "../../config.js" ;
22import {
33 filterLinesByKeywords ,
4- validateResponse ,
4+ validateLogResponse ,
55 LogResponse ,
6- } from "../../lib /utils.js" ;
6+ } from "./utils.js" ;
77
88const auth = Buffer . from (
99 `${ config . browserstackUsername } :${ config . browserstackAccessKey } ` ,
@@ -23,7 +23,7 @@ export async function retrieveDeviceLogs(
2323 } ,
2424 } ) ;
2525
26- const validationResult = validateResponse ( response , "device logs" ) ;
26+ const validationResult = validateLogResponse ( response , "device logs" ) ;
2727 if ( validationResult ) return validationResult ;
2828
2929 const logText = await response . text ( ) ;
@@ -44,7 +44,7 @@ export async function retrieveAppiumLogs(
4444 } ,
4545 } ) ;
4646
47- const validationResult = validateResponse ( response , "Appium logs" ) ;
47+ const validationResult = validateLogResponse ( response , "Appium logs" ) ;
4848 if ( validationResult ) return validationResult ;
4949
5050 const logText = await response . text ( ) ;
@@ -65,7 +65,7 @@ export async function retrieveCrashLogs(
6565 } ,
6666 } ) ;
6767
68- const validationResult = validateResponse ( response , "crash logs" ) ;
68+ const validationResult = validateLogResponse ( response , "crash logs" ) ;
6969 if ( validationResult ) return validationResult ;
7070
7171 const logText = await response . text ( ) ;
Original file line number Diff line number Diff line change 33 HarEntry ,
44 HarFile ,
55 filterLinesByKeywords ,
6- validateResponse ,
6+ validateLogResponse ,
77 LogResponse ,
8- } from "../../lib /utils.js" ;
8+ } from "./utils.js" ;
99
1010const auth = Buffer . from (
1111 `${ config . browserstackUsername } :${ config . browserstackAccessKey } ` ,
@@ -25,7 +25,7 @@ export async function retrieveNetworkFailures(
2525 } ,
2626 } ) ;
2727
28- const validationResult = validateResponse ( response , "network logs" ) ;
28+ const validationResult = validateLogResponse ( response , "network logs" ) ;
2929 if ( validationResult ) return validationResult ;
3030
3131 const networklogs : HarFile = await response . json ( ) ;
@@ -73,7 +73,7 @@ export async function retrieveSessionFailures(
7373 } ,
7474 } ) ;
7575
76- const validationResult = validateResponse ( response , "session logs" ) ;
76+ const validationResult = validateLogResponse ( response , "session logs" ) ;
7777 if ( validationResult ) return validationResult ;
7878
7979 const logText = await response . text ( ) ;
@@ -93,7 +93,7 @@ export async function retrieveConsoleFailures(
9393 } ,
9494 } ) ;
9595
96- const validationResult = validateResponse ( response , "console logs" ) ;
96+ const validationResult = validateLogResponse ( response , "console logs" ) ;
9797 if ( validationResult ) return validationResult ;
9898
9999 const logText = await response . text ( ) ;
Original file line number Diff line number Diff line change 1+ export interface LogResponse {
2+ logs ?: any [ ] ;
3+ message ?: string ;
4+ }
5+
6+ export interface HarFile {
7+ log : {
8+ entries : HarEntry [ ] ;
9+ } ;
10+ }
11+
12+ export interface HarEntry {
13+ startedDateTime : string ;
14+ request : {
15+ method : string ;
16+ url : string ;
17+ queryString ?: { name : string ; value : string } [ ] ;
18+ } ;
19+ response : {
20+ status : number ;
21+ statusText ?: string ;
22+ _error ?: string ;
23+ } ;
24+ serverIPAddress ?: string ;
25+ time ?: number ;
26+ }
27+
28+ export function validateLogResponse (
29+ response : Response ,
30+ logType : string ,
31+ ) : LogResponse | null {
32+ if ( ! response . ok ) {
33+ if ( response . status === 404 ) {
34+ return { message : `No ${ logType } available for this session` } ;
35+ }
36+ if ( response . status === 401 || response . status === 403 ) {
37+ return {
38+ message : `Unable to access ${ logType } - please check your credentials` ,
39+ } ;
40+ }
41+ return { message : `Unable to fetch ${ logType } at this time` } ;
42+ }
43+ return null ;
44+ }
45+
46+ export function filterLinesByKeywords (
47+ logText : string ,
48+ keywords : string [ ] ,
49+ ) : string [ ] {
50+ return logText
51+ . split ( / \r ? \n / )
52+ . map ( ( line ) => line . trim ( ) )
53+ . filter ( ( line ) =>
54+ keywords . some ( ( keyword ) => line . toLowerCase ( ) . includes ( keyword ) ) ,
55+ ) ;
56+ }
You can’t perform that action at this time.
0 commit comments