config-email/sync/view-db.js

54 lines
2.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
import 'dotenv/config';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient, ScanCommand } from '@aws-sdk/lib-dynamodb';
const client = new DynamoDBClient({
region: process.env.AWS_REGION || 'us-east-2',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
const docClient = DynamoDBDocumentClient.from(client);
const TABLE_NAME = process.env.DYNAMODB_TABLE || 'email-rules';
async function viewDatabase() {
console.log('📊 DynamoDB Table:', TABLE_NAME);
console.log('🌍 Region:', process.env.AWS_REGION);
console.log('');
try {
const command = new ScanCommand({
TableName: TABLE_NAME,
});
const response = await docClient.send(command);
const rules = response.Items || [];
console.log(`✅ Found ${rules.length} email rules:\n`);
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
for (const rule of rules) {
console.log(`\n📧 Email: ${rule.email_address}`);
console.log(` OOO Active: ${rule.ooo_active ? '✅ YES' : '❌ NO'}`);
if (rule.ooo_active) {
console.log(` OOO Message: "${rule.ooo_message.substring(0, 50)}${rule.ooo_message.length > 50 ? '...' : ''}"`);
console.log(` Content Type: ${rule.ooo_content_type}`);
}
console.log(` Forwards: ${rule.forwards && rule.forwards.length > 0 ? rule.forwards.join(', ') : 'None'}`);
console.log(` Last Updated: ${rule.last_updated || 'N/A'}`);
console.log(' ─────────────────────────────────────────────────────────────────');
}
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
} catch (error) {
console.error('❌ Error fetching data:', error.message);
process.exit(1);
}
}
viewDatabase();