@agenticmail/enterprise 0.5.17 → 0.5.18

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/db/adapter.ts CHANGED
@@ -175,6 +175,7 @@ export interface SsoConfig {
175
175
 
176
176
  export interface CompanySettings {
177
177
  id: string;
178
+ orgId?: string;
178
179
  name: string;
179
180
  domain?: string;
180
181
  subdomain: string; // <subdomain>.agenticmail.io
@@ -97,6 +97,10 @@ export class PostgresAdapter extends DatabaseAdapter {
97
97
  INSERT INTO retention_policy (id) VALUES ('default')
98
98
  ON CONFLICT (id) DO NOTHING
99
99
  `);
100
+ // Add org_id column if missing
101
+ await client.query(`
102
+ ALTER TABLE company_settings ADD COLUMN IF NOT EXISTS org_id TEXT
103
+ `).catch(() => {});
100
104
  await client.query('COMMIT');
101
105
  } catch (err) {
102
106
  await client.query('ROLLBACK');
@@ -126,7 +130,7 @@ export class PostgresAdapter extends DatabaseAdapter {
126
130
  const values: any[] = [];
127
131
  let i = 1;
128
132
  const map: Record<string, string> = {
129
- name: 'name', domain: 'domain', subdomain: 'subdomain',
133
+ name: 'name', orgId: 'org_id', domain: 'domain', subdomain: 'subdomain',
130
134
  smtpHost: 'smtp_host', smtpPort: 'smtp_port', smtpUser: 'smtp_user',
131
135
  smtpPass: 'smtp_pass', dkimPrivateKey: 'dkim_private_key',
132
136
  logoUrl: 'logo_url', primaryColor: 'primary_color', plan: 'plan',
@@ -526,7 +530,7 @@ export class PostgresAdapter extends DatabaseAdapter {
526
530
 
527
531
  private mapSettings(r: any): CompanySettings {
528
532
  return {
529
- id: r.id, name: r.name, domain: r.domain, subdomain: r.subdomain,
533
+ id: r.id, orgId: r.org_id || undefined, name: r.name, domain: r.domain, subdomain: r.subdomain,
530
534
  smtpHost: r.smtp_host, smtpPort: r.smtp_port, smtpUser: r.smtp_user, smtpPass: r.smtp_pass,
531
535
  dkimPrivateKey: r.dkim_private_key, logoUrl: r.logo_url, primaryColor: r.primary_color,
532
536
  ssoConfig: r.sso_config ? (typeof r.sso_config === 'string' ? JSON.parse(r.sso_config) : r.sso_config) : undefined,
@@ -6,8 +6,17 @@
6
6
  * after all prompts are collected.
7
7
  */
8
8
 
9
- import { randomUUID } from 'crypto';
9
+ import { randomUUID, randomBytes } from 'crypto';
10
10
  import type { DatabaseAdapter } from '../db/adapter.js';
11
+
12
+ /** Generate a unique 10-char org ID like "BKSID30HKS" */
13
+ function generateOrgId(): string {
14
+ const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
15
+ const bytes = randomBytes(10);
16
+ let id = '';
17
+ for (let i = 0; i < 10; i++) id += chars[bytes[i] % chars.length];
18
+ return id;
19
+ }
11
20
  import type { CompanyInfo } from './company.js';
12
21
  import type { DatabaseSelection } from './database.js';
13
22
  import type { DeployTarget } from './deployment.js';
@@ -72,12 +81,14 @@ export async function provision(
72
81
 
73
82
  // ─── Company Settings ──────────────────────────
74
83
  spinner.start('Creating company...');
84
+ const orgId = generateOrgId();
75
85
  await db.updateSettings({
76
86
  name: config.company.companyName,
77
87
  subdomain: config.company.subdomain,
78
88
  domain: config.domain.customDomain,
79
- });
80
- spinner.succeed('Company created');
89
+ orgId,
90
+ } as any);
91
+ spinner.succeed(`Company created (org: ${orgId})`);
81
92
 
82
93
  // ─── Domain Registration ─────────────────────────
83
94
  if (config.registration?.registered) {