feat: Mimecast multi-tenant held mail viewer

- migration 062: mimecast_tenants table (company_id, client_id/secret, account_code)
- Seed Wulf (CUSA13A95) + Seubert (CUSA96A181) tenants
- MimecastClient.getHeldMessages(): full pagination via meta.pagination.next cursor
  (API always returns 10/page regardless of pageSize param, totalCount in meta)
- getMimecastClientForTenant() factory for per-tenant instantiation
- GET /api/mimecast/held?tenantId=&recipient= — fetches all tenants in parallel,
  merges + sorts by date, returns per-tenant counts + combined messages[]
- Held Mail tab on /admin/sync/mimecast (on-demand load, recipient filter,
  tenant badges, policy filter dropdown, DMARC/impersonation highlighted red)
This commit is contained in:
lorentz 2026-03-31 22:38:22 -04:00
parent a98c0daf15
commit fcdec8e38b
12 changed files with 2208 additions and 27 deletions

View file

@ -6,18 +6,20 @@ export async function POST(request: NextRequest) {
try {
console.log('Starting classification icons sync...');
// Fetch classification icons from Autotask API
// Fetch classification picklist from Companies field info
const autotaskClient = getAutotaskClient();
const classifications = await autotaskClient.getClassificationIcons();
if (!classifications || classifications.length === 0) {
const fields = await autotaskClient.getFieldInfo('Companies');
const classificationField = fields.find((f: any) => f.name === 'classification');
if (!classificationField || !classificationField.picklistValues?.length) {
return NextResponse.json(
{ error: 'No classifications found in Autotask' },
{ error: 'No classification picklist found in Companies field info' },
{ status: 404 }
);
}
console.log(`Fetched ${classifications.length} classification icons from Autotask`);
const classifications = classificationField.picklistValues;
console.log(`Fetched ${classifications.length} classification values from Autotask`);
let inserted = 0;
let updated = 0;
@ -26,16 +28,16 @@ export async function POST(request: NextRequest) {
for (const classification of classifications) {
const result = await postgresClient.query(
`INSERT INTO company_classifications (
classification_id,
name,
description,
classification_id,
name,
description,
is_active,
is_system,
updated_at,
synced_at
) VALUES ($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
ON CONFLICT (classification_id)
DO UPDATE SET
ON CONFLICT (classification_id)
DO UPDATE SET
name = EXCLUDED.name,
description = EXCLUDED.description,
is_active = EXCLUDED.is_active,
@ -44,9 +46,9 @@ export async function POST(request: NextRequest) {
synced_at = CURRENT_TIMESTAMP
RETURNING (xmax = 0) AS inserted`,
[
classification.id,
classification.name,
classification.description || null,
parseInt(String(classification.value)),
classification.label,
null,
classification.isActive !== false,
classification.isSystem || false
]
@ -66,7 +68,7 @@ export async function POST(request: NextRequest) {
total: classifications.length,
inserted,
updated,
message: `Synced ${classifications.length} classification icons`
message: `Synced ${classifications.length} classifications from Companies field info`
});
} catch (error) {