module twilio-labs import debug from 'debug' ; import { LogApiResource , LogList , Sid , LogFilters } from '../types' ; import { TwilioServerlessApiClient } from '../client' ; import { getPaginatedResource } from './utils/pagination' ; import { ClientApiError } from '../utils/error' ; const log = debug ( 'twilio-serverless-api:logs' ) ; param { Sid } environmentSid param { Sid } serviceSid param { TwilioServerlessApiClient } client returns { Promise < LogApiResource [ ] > } export async function listLogResources ( environmentSid , serviceSid , client ) { try { return getPaginatedResource < LogList , LogApiResource > ( client , `Services/${ serviceSid }/Environments/${ environmentSid }/Logs` ) ; } catch ( err ) { log ( '%O' , new ClientApiError ( err ) ) ; throw err ; } } param { Sid } environmentSid param { Sid } serviceSid param { TwilioServerlessApiClient } client returns { Promise < LogApiResource [ ] > } export async function listOnePageLogResources ( environmentSid , serviceSid , client , filters ) { const pageSize = filters . pageSize || 50 ; const { functionSid , startDate , endDate , pageToken } = filters ; try { let url = `Services/${ serviceSid }/Environments/${ environmentSid }/Logs?PageSize=${ pageSize }` ; if ( typeof functionSid !== 'undefined' ) { url += `&FunctionSid=${ functionSid }` ; } if ( typeof startDate !== 'undefined' ) { url += `&StartDate=${ startDate instanceof Date ? startDate . toISOString ( ) : startDate }` ; } if ( typeof endDate !== 'undefined' ) { url += `&EndDate=${ endDate instanceof Date ? endDate . toISOString ( ) : endDate }` ; } if ( typeof pageToken !== 'undefined' ) { url += `&PageToken=${ pageToken }` ; } const resp = await client . request ( 'get' , url ) ; const content = ( resp . body as unknown ) as LogList ; return content . logs as LogApiResource [ ] ; } catch ( err ) { log ( '%O' , new ClientApiError ( err ) ) ; throw err ; } } param { Sid } logSid param { Sid } environmentSid param { Sid } serviceSid param { TwilioServerlessApiClient } client returns { Promise < LogApiResource > } export async function getLog ( logSid , environmentSid , serviceSid , client ) { try { const resp = await client . request ( 'get' , `Services/${ serviceSid }/Environments/${ environmentSid }/Logs/${ logSid }` ) ; return ( resp . body as unknown ) as LogApiResource ; } catch ( err ) { log ( '%O' , new ClientApiError ( err ) ) ; throw err ; } }