|
| 1 | +--- |
| 2 | +title: Tenant |
| 3 | +description: Tenant protocol schemas |
| 4 | +--- |
| 5 | + |
| 6 | +{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs go in content/docs/guides/. */} |
| 7 | + |
| 8 | +Multi-Tenant Architecture Schema |
| 9 | + |
| 10 | +Defines the schema for managing multi-tenant architecture with: |
| 11 | + |
| 12 | +- Global control plane: Single database for auth, org management, tenant registry |
| 13 | + |
| 14 | +- Tenant data plane: Isolated databases per organization (UUID-based naming) |
| 15 | + |
| 16 | +Design decisions: |
| 17 | + |
| 18 | +- Database naming: \{uuid\}.turso.io (not org-slug, since slugs can be modified) |
| 19 | + |
| 20 | +- Each tenant has its own Turso database for complete data isolation |
| 21 | + |
| 22 | +- Global database stores user auth, organizations, and tenant metadata |
| 23 | + |
| 24 | +<Callout type="info"> |
| 25 | +**Source:** `packages/spec/src/cloud/tenant.zod.ts` |
| 26 | +</Callout> |
| 27 | + |
| 28 | +## TypeScript Usage |
| 29 | + |
| 30 | +```typescript |
| 31 | +import { PackageInstallation, PackageInstallationStatus, ProvisionTenantRequest, ProvisionTenantResponse, TenantContext, TenantDatabase, TenantDatabaseStatus, TenantIdentificationSource, TenantRoutingConfig } from '@objectstack/spec/cloud'; |
| 32 | +import type { PackageInstallation, PackageInstallationStatus, ProvisionTenantRequest, ProvisionTenantResponse, TenantContext, TenantDatabase, TenantDatabaseStatus, TenantIdentificationSource, TenantRoutingConfig } from '@objectstack/spec/cloud'; |
| 33 | + |
| 34 | +// Validate data |
| 35 | +const result = PackageInstallation.parse(data); |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## PackageInstallation |
| 41 | + |
| 42 | +### Properties |
| 43 | + |
| 44 | +| Property | Type | Required | Description | |
| 45 | +| :--- | :--- | :--- | :--- | |
| 46 | +| **id** | `string` | ✅ | Unique installation identifier | |
| 47 | +| **tenantId** | `string` | ✅ | Tenant database ID | |
| 48 | +| **packageId** | `string` | ✅ | Package identifier | |
| 49 | +| **version** | `string` | ✅ | Installed package version | |
| 50 | +| **status** | `Enum<'installing' \| 'active' \| 'disabled' \| 'uninstalling' \| 'failed'>` | ✅ | Installation status | |
| 51 | +| **installedAt** | `string` | ✅ | Installation timestamp | |
| 52 | +| **installedBy** | `string` | ✅ | User ID who installed the package | |
| 53 | +| **config** | `Record<string, any>` | optional | Package-specific configuration | |
| 54 | +| **updatedAt** | `string` | ✅ | Last update timestamp | |
| 55 | + |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## PackageInstallationStatus |
| 60 | + |
| 61 | +### Allowed Values |
| 62 | + |
| 63 | +* `installing` |
| 64 | +* `active` |
| 65 | +* `disabled` |
| 66 | +* `uninstalling` |
| 67 | +* `failed` |
| 68 | + |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## ProvisionTenantRequest |
| 73 | + |
| 74 | +### Properties |
| 75 | + |
| 76 | +| Property | Type | Required | Description | |
| 77 | +| :--- | :--- | :--- | :--- | |
| 78 | +| **organizationId** | `string` | ✅ | Organization ID | |
| 79 | +| **region** | `string` | optional | Deployment region preference | |
| 80 | +| **plan** | `Enum<'free' \| 'starter' \| 'pro' \| 'enterprise' \| 'custom'>` | ✅ | Tenant plan tier | |
| 81 | +| **storageLimitMb** | `integer` | optional | Storage limit in megabytes | |
| 82 | +| **metadata** | `Record<string, any>` | optional | Custom tenant metadata | |
| 83 | + |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## ProvisionTenantResponse |
| 88 | + |
| 89 | +### Properties |
| 90 | + |
| 91 | +| Property | Type | Required | Description | |
| 92 | +| :--- | :--- | :--- | :--- | |
| 93 | +| **tenant** | `Object` | ✅ | Provisioned tenant database | |
| 94 | +| **durationMs** | `number` | ✅ | Provisioning duration in milliseconds | |
| 95 | +| **warnings** | `string[]` | optional | Provisioning warnings | |
| 96 | + |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## TenantContext |
| 101 | + |
| 102 | +### Properties |
| 103 | + |
| 104 | +| Property | Type | Required | Description | |
| 105 | +| :--- | :--- | :--- | :--- | |
| 106 | +| **tenantId** | `string` | ✅ | Current tenant database ID | |
| 107 | +| **organizationId** | `string` | ✅ | Current organization ID | |
| 108 | +| **organizationSlug** | `string` | optional | Organization slug | |
| 109 | +| **databaseUrl** | `string` | ✅ | Tenant database URL | |
| 110 | +| **plan** | `Enum<'free' \| 'starter' \| 'pro' \| 'enterprise' \| 'custom'>` | ✅ | Tenant plan tier | |
| 111 | +| **metadata** | `Record<string, any>` | optional | Custom tenant metadata | |
| 112 | + |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## TenantDatabase |
| 117 | + |
| 118 | +### Properties |
| 119 | + |
| 120 | +| Property | Type | Required | Description | |
| 121 | +| :--- | :--- | :--- | :--- | |
| 122 | +| **id** | `string` | ✅ | Unique tenant database identifier (UUID) | |
| 123 | +| **organizationId** | `string` | ✅ | Organization ID (foreign key to sys_organization) | |
| 124 | +| **databaseName** | `string` | ✅ | Database name (UUID-based) | |
| 125 | +| **databaseUrl** | `string` | ✅ | Full database URL | |
| 126 | +| **authToken** | `string` | ✅ | Encrypted tenant-specific auth token | |
| 127 | +| **status** | `Enum<'provisioning' \| 'active' \| 'suspended' \| 'archived' \| 'failed'>` | ✅ | Database status | |
| 128 | +| **region** | `string` | ✅ | Deployment region | |
| 129 | +| **plan** | `Enum<'free' \| 'starter' \| 'pro' \| 'enterprise' \| 'custom'>` | ✅ | Tenant plan tier | |
| 130 | +| **storageLimitMb** | `integer` | ✅ | Storage limit in megabytes | |
| 131 | +| **createdAt** | `string` | ✅ | Database creation timestamp | |
| 132 | +| **updatedAt** | `string` | ✅ | Last update timestamp | |
| 133 | +| **lastAccessedAt** | `string` | optional | Last accessed timestamp | |
| 134 | +| **metadata** | `Record<string, any>` | optional | Custom tenant configuration | |
| 135 | + |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## TenantDatabaseStatus |
| 140 | + |
| 141 | +### Allowed Values |
| 142 | + |
| 143 | +* `provisioning` |
| 144 | +* `active` |
| 145 | +* `suspended` |
| 146 | +* `archived` |
| 147 | +* `failed` |
| 148 | + |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## TenantIdentificationSource |
| 153 | + |
| 154 | +### Allowed Values |
| 155 | + |
| 156 | +* `subdomain` |
| 157 | +* `custom_domain` |
| 158 | +* `header` |
| 159 | +* `jwt_claim` |
| 160 | +* `session` |
| 161 | +* `default` |
| 162 | + |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## TenantRoutingConfig |
| 167 | + |
| 168 | +### Properties |
| 169 | + |
| 170 | +| Property | Type | Required | Description | |
| 171 | +| :--- | :--- | :--- | :--- | |
| 172 | +| **enabled** | `boolean` | ✅ | Enable multi-tenant mode | |
| 173 | +| **identificationSources** | `Enum<'subdomain' \| 'custom_domain' \| 'header' \| 'jwt_claim' \| 'session' \| 'default'>[]` | ✅ | Tenant identification strategy (in order of precedence) | |
| 174 | +| **defaultTenantId** | `string` | optional | Default tenant ID | |
| 175 | +| **subdomainPattern** | `string` | optional | Subdomain pattern for tenant extraction | |
| 176 | +| **customDomainMapping** | `Record<string, string>` | optional | Custom domain to tenant ID mapping | |
| 177 | +| **tenantHeaderName** | `string` | ✅ | Header name for tenant ID | |
| 178 | +| **jwtOrganizationClaim** | `string` | ✅ | JWT claim name for organization ID | |
| 179 | + |
| 180 | + |
| 181 | +--- |
| 182 | + |
0 commit comments