tango-app-api-audit 3.4.8 → 3.4.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.8",
3
+ "version": "3.4.9",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -4733,6 +4733,7 @@ export async function auditViewLogs( req, res ) {
4733
4733
  return res.sendError( 'Please give valid modueType', 400 );
4734
4734
  }
4735
4735
  }
4736
+ logger.info( { query: logsQuery, message: 'unattended' } );
4736
4737
  const logs = await getOpenSearchData( parsedOpenSearch.auditLog, logsQuery );
4737
4738
  logger.info( { logs: logs.body.hits, inputData: inputData, auditLog: parsedOpenSearch.auditLog } );
4738
4739
  if ( logs.body.hits.hits.length > 0 ) {
@@ -4763,36 +4764,32 @@ export async function auditViewLogs( req, res ) {
4763
4764
  }
4764
4765
  }
4765
4766
 
4766
- export async function convertTimestampToDateTime( timestamp ) {
4767
- // Check if the timestamp is too large (nanoseconds), then convert it to milliseconds
4768
- if ( timestamp > 9999999999999 ) {
4769
- timestamp = Math.floor( timestamp / 1000 ); // Convert to milliseconds if needed
4770
- }
4771
-
4772
- // Add 5 hours and 30 minutes in milliseconds
4773
- const timeOffset = ( 5 * 60 * 60 * 1000 ) + ( 30 * 60 * 1000 );
4774
4767
 
4775
- // Ensure the timestamp is valid by adding the offset correctly
4776
- const adjustedTimestamp = timestamp + timeOffset;
4777
-
4778
- // Create a new Date object using the adjusted timestamp
4779
- const date = new Date( adjustedTimestamp );
4780
-
4781
- // Ensure the date is valid (timestamp may be invalid)
4782
- if ( isNaN( date.getTime() ) ) {
4783
- throw new Error( 'Invalid timestamp provided' );
4768
+ export async function convertTimestampToDateTime( timestamp ) {
4769
+ let date;
4770
+ if ( typeof timestamp === 'string' ) {
4771
+ date = new Date( timestamp );
4772
+ if ( isNaN( date.getTime() ) ) {
4773
+ throw new Error( 'Invalid ISO string timestamp provided' );
4774
+ }
4775
+ } else if ( typeof timestamp === 'number' ) { // Handle Unix timestamp input (e.g., 1727785440597)
4776
+ if ( timestamp.toString().length <= 10 ) {
4777
+ timestamp *= 1000; // Convert seconds to milliseconds
4778
+ }
4779
+ date = new Date( timestamp );
4780
+ } else { // Handle invalid input type
4781
+ throw new Error( 'Invalid input: Timestamp must be a valid ISO string or number' );
4784
4782
  }
4785
-
4786
- // Format the date and time components
4787
- const year = date.getFullYear();
4788
- const month = ( '0' + ( date.getMonth() + 1 ) ).slice( -2 ); // Months are zero-based
4789
- const day = ( '0' + date.getDate() ).slice( -2 );
4790
-
4791
- const hours = ( '0' + date.getHours() ).slice( -2 );
4792
- const minutes = ( '0' + date.getMinutes() ).slice( -2 );
4793
- const seconds = ( '0' + date.getSeconds() ).slice( -2 );
4794
-
4795
- // Return formatted date and time string
4783
+ const timeOffset = ( 5 * 60 * 60 * 1000 ) + ( 30 * 60 * 1000 ); // 5 hours and 30 minutes in milliseconds
4784
+ const adjustedTimestamp = date.getTime() + timeOffset;
4785
+ const adjustedDate = new Date( adjustedTimestamp );
4786
+ const year = adjustedDate.getFullYear();
4787
+ const month = ( '0' + ( adjustedDate.getMonth() + 1 ) ).slice( -2 ); // Months are zero-based
4788
+ const day = ( '0' + adjustedDate.getDate() ).slice( -2 );
4789
+
4790
+ const hours = ( '0' + adjustedDate.getHours() ).slice( -2 );
4791
+ const minutes = ( '0' + adjustedDate.getMinutes() ).slice( -2 );
4792
+ const seconds = ( '0' + adjustedDate.getSeconds() ).slice( -2 );
4796
4793
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
4797
4794
  }
4798
4795