@agenticmail/enterprise 0.5.229 → 0.5.230

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/src/server.ts CHANGED
@@ -11,6 +11,7 @@ import type { AppEnv } from './types/hono-env.js';
11
11
  import { cors } from 'hono/cors';
12
12
  import { serve } from '@hono/node-server';
13
13
  import { readFileSync, existsSync } from 'fs';
14
+ import { homedir } from 'os';
14
15
  import { fileURLToPath } from 'url';
15
16
  import { dirname, join } from 'path';
16
17
  import { createRequire } from 'module';
@@ -438,6 +439,15 @@ export function createServer(config: ServerConfig): ServerInstance {
438
439
  html = html.replace('</head>', injection + '</head>');
439
440
  }
440
441
 
442
+ // Inject branding config
443
+ try {
444
+ const settings0 = await config.db.getSettings();
445
+ if (settings0?.branding) {
446
+ const brandScript = `<script>window.__EM_BRANDING__=${JSON.stringify(settings0.branding)};</script>`;
447
+ html = html.replace('</head>', brandScript + '</head>');
448
+ }
449
+ } catch { /* non-blocking */ }
450
+
441
451
  // Inject domain verification status (informational, does not block)
442
452
  try {
443
453
  const settings = await config.db.getSettings();
@@ -456,6 +466,21 @@ export function createServer(config: ServerConfig): ServerInstance {
456
466
  return c.html(html);
457
467
  }
458
468
 
469
+ // Serve branding assets from ~/.agenticmail/branding/
470
+ app.get('/branding/*', (c) => {
471
+ const reqPath = c.req.path.replace('/branding/', '');
472
+ if (reqPath.includes('..')) return c.json({ error: 'Forbidden' }, 403);
473
+ const ext = reqPath.substring(reqPath.lastIndexOf('.'));
474
+ const mimeMap: Record<string, string> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.gif': 'image/gif', '.webp': 'image/webp' };
475
+ const mime = mimeMap[ext];
476
+ if (!mime) return c.json({ error: 'Not found' }, 404);
477
+ const brandDir = join(homedir(), '.agenticmail', 'branding');
478
+ const filePath = join(brandDir, reqPath);
479
+ if (!filePath.startsWith(brandDir) || !existsSync(filePath)) return c.json({ error: 'Not found' }, 404);
480
+ const content = readFileSync(filePath);
481
+ return new Response(content, { status: 200, headers: { 'Content-Type': mime, 'Cache-Control': 'public, max-age=3600' } });
482
+ });
483
+
459
484
  app.get('/', (c) => c.redirect('/dashboard'));
460
485
  app.get('/dashboard', serveDashboard);
461
486