@authhero/multi-tenancy 13.6.0 → 13.8.0
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/dist/multi-tenancy.cjs +1 -1
- package/dist/multi-tenancy.d.ts +281 -65
- package/dist/multi-tenancy.mjs +1118 -554
- package/package.json +3 -3
package/dist/multi-tenancy.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { z } from '@hono/zod-openapi';
|
|
3
|
+
import { OpenAPIHono, z } from '@hono/zod-openapi';
|
|
4
4
|
import { Context, Hono, MiddlewareHandler } from 'hono';
|
|
5
5
|
import { FC } from 'hono/jsx';
|
|
6
6
|
import { CountryCode } from 'libphonenumber-js';
|
|
@@ -9262,6 +9262,8 @@ export type Variables = {
|
|
|
9262
9262
|
sub: string;
|
|
9263
9263
|
tenant_id: string;
|
|
9264
9264
|
};
|
|
9265
|
+
organization_id?: string;
|
|
9266
|
+
org_name?: string;
|
|
9265
9267
|
loginSession?: LoginSession;
|
|
9266
9268
|
auth0_client?: Auth0Client$1;
|
|
9267
9269
|
useragent?: string;
|
|
@@ -9543,6 +9545,22 @@ export interface EntityHooksConfig {
|
|
|
9543
9545
|
connections?: EntityHooks<Connection, ConnectionInsert>;
|
|
9544
9546
|
tenants?: EntityHooks<Tenant, CreateTenantParams>;
|
|
9545
9547
|
}
|
|
9548
|
+
/**
|
|
9549
|
+
* Route extension for the management API.
|
|
9550
|
+
*
|
|
9551
|
+
* Allows registering additional OpenAPI routes that go through the full
|
|
9552
|
+
* middleware chain (caching, tenant resolution, auth, entity hooks).
|
|
9553
|
+
*/
|
|
9554
|
+
export interface ManagementApiExtension {
|
|
9555
|
+
/** The path prefix for the routes (e.g., "/tenants") */
|
|
9556
|
+
path: string;
|
|
9557
|
+
/**
|
|
9558
|
+
* The OpenAPI router to mount at the path.
|
|
9559
|
+
* Use `any` to allow routers with extended Bindings/Variables types
|
|
9560
|
+
* (e.g., from multi-tenancy package).
|
|
9561
|
+
*/
|
|
9562
|
+
router: OpenAPIHono<any, any, any>;
|
|
9563
|
+
}
|
|
9546
9564
|
export interface AuthHeroConfig {
|
|
9547
9565
|
dataAdapter: DataAdapters;
|
|
9548
9566
|
allowedOrigins?: string[];
|
|
@@ -9562,6 +9580,31 @@ export interface AuthHeroConfig {
|
|
|
9562
9580
|
* Use these to implement cross-tenant sync, audit logging, webhooks, etc.
|
|
9563
9581
|
*/
|
|
9564
9582
|
entityHooks?: EntityHooksConfig;
|
|
9583
|
+
/**
|
|
9584
|
+
* Additional routes to mount on the management API.
|
|
9585
|
+
*
|
|
9586
|
+
* These routes go through the full middleware chain:
|
|
9587
|
+
* - CORS
|
|
9588
|
+
* - Data hooks & caching
|
|
9589
|
+
* - Client info extraction
|
|
9590
|
+
* - Tenant resolution
|
|
9591
|
+
* - Authentication (reads OpenAPI security definitions)
|
|
9592
|
+
* - Entity hooks
|
|
9593
|
+
*
|
|
9594
|
+
* @example
|
|
9595
|
+
* ```typescript
|
|
9596
|
+
* import { init } from "authhero";
|
|
9597
|
+
* import { createTenantsOpenAPIRouter } from "@authhero/multi-tenancy";
|
|
9598
|
+
*
|
|
9599
|
+
* const { app } = init({
|
|
9600
|
+
* dataAdapter,
|
|
9601
|
+
* managementApiExtensions: [
|
|
9602
|
+
* { path: "/tenants", router: createTenantsOpenAPIRouter(config, hooks) }
|
|
9603
|
+
* ]
|
|
9604
|
+
* });
|
|
9605
|
+
* ```
|
|
9606
|
+
*/
|
|
9607
|
+
managementApiExtensions?: ManagementApiExtension[];
|
|
9565
9608
|
}
|
|
9566
9609
|
export type SendEmailParams = {
|
|
9567
9610
|
emailProvider: EmailProvider;
|
|
@@ -9684,9 +9727,17 @@ export interface SeedOptions {
|
|
|
9684
9727
|
*/
|
|
9685
9728
|
tenantName?: string;
|
|
9686
9729
|
/**
|
|
9687
|
-
* The audience URL for the tenant
|
|
9730
|
+
* The audience URL for the tenant.
|
|
9731
|
+
* For the main/management tenant, defaults to `urn:authhero:management`.
|
|
9732
|
+
* For child tenants, use `getTenantAudience(tenantId)` to generate `urn:authhero:tenant:{tenantId}`.
|
|
9688
9733
|
*/
|
|
9689
9734
|
audience?: string;
|
|
9735
|
+
/**
|
|
9736
|
+
* Whether this is the main/management tenant.
|
|
9737
|
+
* If true, the audience will default to `urn:authhero:management`.
|
|
9738
|
+
* @default true
|
|
9739
|
+
*/
|
|
9740
|
+
isMainTenant?: boolean;
|
|
9690
9741
|
/**
|
|
9691
9742
|
* The default client ID (defaults to "default")
|
|
9692
9743
|
*/
|
|
@@ -18964,6 +19015,7 @@ export interface MultiTenancyBindings {
|
|
|
18964
19015
|
export interface MultiTenancyVariables {
|
|
18965
19016
|
tenant_id: string;
|
|
18966
19017
|
organization_id?: string;
|
|
19018
|
+
org_name?: string;
|
|
18967
19019
|
user?: {
|
|
18968
19020
|
sub: string;
|
|
18969
19021
|
tenant_id: string;
|
|
@@ -18981,33 +19033,33 @@ export type MultiTenancyContext = Context<{
|
|
|
18981
19033
|
* Configuration for organization-based tenant access control.
|
|
18982
19034
|
*
|
|
18983
19035
|
* This enables a model where:
|
|
18984
|
-
* - A "
|
|
18985
|
-
* - Organizations on the
|
|
19036
|
+
* - A "control plane" tenant manages all other tenants
|
|
19037
|
+
* - Organizations on the control plane correspond to child tenants
|
|
18986
19038
|
* - Tokens with an org claim can access the matching tenant
|
|
18987
|
-
* - Tokens without an org claim can only access the
|
|
19039
|
+
* - Tokens without an org claim can only access the control plane
|
|
18988
19040
|
*/
|
|
18989
19041
|
export interface AccessControlConfig {
|
|
18990
19042
|
/**
|
|
18991
|
-
* The
|
|
18992
|
-
* This is the
|
|
19043
|
+
* The control plane tenant ID.
|
|
19044
|
+
* This is the tenant that manages all other tenants.
|
|
18993
19045
|
* Tokens without an organization claim can access this tenant.
|
|
18994
19046
|
*/
|
|
18995
|
-
|
|
19047
|
+
controlPlaneTenantId: string;
|
|
18996
19048
|
/**
|
|
18997
19049
|
* If true, tokens must have an organization claim matching the target tenant ID
|
|
18998
|
-
* (except for
|
|
19050
|
+
* (except for control plane access where no org is required).
|
|
18999
19051
|
* @default true
|
|
19000
19052
|
*/
|
|
19001
19053
|
requireOrganizationMatch?: boolean;
|
|
19002
19054
|
/**
|
|
19003
19055
|
* Permissions to automatically grant when creating an organization
|
|
19004
|
-
* for a new tenant on the
|
|
19056
|
+
* for a new tenant on the control plane.
|
|
19005
19057
|
* @example ["tenant:admin", "tenant:read", "tenant:write"]
|
|
19006
19058
|
*/
|
|
19007
19059
|
defaultPermissions?: string[];
|
|
19008
19060
|
/**
|
|
19009
19061
|
* Roles to automatically assign to the organization when created.
|
|
19010
|
-
* These roles should exist on the
|
|
19062
|
+
* These roles should exist on the control plane.
|
|
19011
19063
|
*/
|
|
19012
19064
|
defaultRoles?: string[];
|
|
19013
19065
|
/**
|
|
@@ -19085,18 +19137,18 @@ export interface DatabaseIsolationConfig {
|
|
|
19085
19137
|
/**
|
|
19086
19138
|
* Configuration for tenant settings inheritance.
|
|
19087
19139
|
*
|
|
19088
|
-
* This enables child tenants to inherit default settings from the
|
|
19140
|
+
* This enables child tenants to inherit default settings from the control plane,
|
|
19089
19141
|
* reducing configuration overhead and ensuring consistency.
|
|
19090
19142
|
*/
|
|
19091
19143
|
export interface SettingsInheritanceConfig {
|
|
19092
19144
|
/**
|
|
19093
|
-
* If true, new tenants will inherit settings from the
|
|
19145
|
+
* If true, new tenants will inherit settings from the control plane
|
|
19094
19146
|
* as their default configuration.
|
|
19095
19147
|
* @default true
|
|
19096
19148
|
*/
|
|
19097
|
-
|
|
19149
|
+
inheritFromControlPlane?: boolean;
|
|
19098
19150
|
/**
|
|
19099
|
-
* Specific settings keys to inherit from the
|
|
19151
|
+
* Specific settings keys to inherit from the control plane.
|
|
19100
19152
|
* If not provided, all settings are inherited.
|
|
19101
19153
|
*/
|
|
19102
19154
|
inheritedKeys?: (keyof Tenant$1)[];
|
|
@@ -19108,13 +19160,13 @@ export interface SettingsInheritanceConfig {
|
|
|
19108
19160
|
/**
|
|
19109
19161
|
* Custom function to transform inherited settings before applying.
|
|
19110
19162
|
*/
|
|
19111
|
-
transformSettings?: (
|
|
19163
|
+
transformSettings?: (controlPlaneSettings: Partial<Tenant$1>, newTenantId: string) => Partial<Tenant$1>;
|
|
19112
19164
|
}
|
|
19113
19165
|
/**
|
|
19114
19166
|
* Configuration for subdomain-based tenant routing.
|
|
19115
19167
|
*
|
|
19116
19168
|
* This enables using subdomains to route requests to different tenants,
|
|
19117
|
-
* where the subdomain matches an organization ID on the
|
|
19169
|
+
* where the subdomain matches an organization ID on the control plane.
|
|
19118
19170
|
*/
|
|
19119
19171
|
export interface SubdomainRoutingConfig {
|
|
19120
19172
|
/**
|
|
@@ -19124,7 +19176,7 @@ export interface SubdomainRoutingConfig {
|
|
|
19124
19176
|
baseDomain: string;
|
|
19125
19177
|
/**
|
|
19126
19178
|
* If true, use organizations to resolve subdomains to tenants.
|
|
19127
|
-
* The subdomain will be matched against organization IDs on the
|
|
19179
|
+
* The subdomain will be matched against organization IDs on the control plane.
|
|
19128
19180
|
* @default true
|
|
19129
19181
|
*/
|
|
19130
19182
|
useOrganizations?: boolean;
|
|
@@ -19146,13 +19198,13 @@ export interface SubdomainRoutingConfig {
|
|
|
19146
19198
|
*
|
|
19147
19199
|
* - **accessControl**: Organization-based tenant access validation
|
|
19148
19200
|
* - **databaseIsolation**: Per-tenant database instances
|
|
19149
|
-
* - **settingsInheritance**: Inherit settings from
|
|
19201
|
+
* - **settingsInheritance**: Inherit settings from control plane
|
|
19150
19202
|
* - **subdomainRouting**: Route requests via subdomains
|
|
19151
19203
|
*/
|
|
19152
19204
|
export interface MultiTenancyConfig {
|
|
19153
19205
|
/**
|
|
19154
19206
|
* Organization-based access control configuration.
|
|
19155
|
-
* Links organizations on the
|
|
19207
|
+
* Links organizations on the control plane to tenant access.
|
|
19156
19208
|
*/
|
|
19157
19209
|
accessControl?: AccessControlConfig;
|
|
19158
19210
|
/**
|
|
@@ -19189,7 +19241,7 @@ export interface TenantHookContext {
|
|
|
19189
19241
|
* ```typescript
|
|
19190
19242
|
* const tenantHooks: TenantEntityHooks = {
|
|
19191
19243
|
* afterCreate: async (ctx, tenant) => {
|
|
19192
|
-
* // Copy resource servers from
|
|
19244
|
+
* // Copy resource servers from the control plane
|
|
19193
19245
|
* await syncResourceServersToNewTenant(ctx, tenant);
|
|
19194
19246
|
* },
|
|
19195
19247
|
* beforeDelete: async (ctx, tenantId) => {
|
|
@@ -19279,8 +19331,10 @@ export interface TokenWithOrg {
|
|
|
19279
19331
|
* Creates hooks for organization-based tenant access control.
|
|
19280
19332
|
*
|
|
19281
19333
|
* This implements the following access model:
|
|
19282
|
-
* -
|
|
19334
|
+
* - Control plane: Accessible without an organization claim
|
|
19283
19335
|
* - Child tenants: Require an organization claim matching the tenant ID
|
|
19336
|
+
* - org_name (organization name) takes precedence and should match tenant ID
|
|
19337
|
+
* - org_id (organization ID) is checked as fallback
|
|
19284
19338
|
*
|
|
19285
19339
|
* @param config - Access control configuration
|
|
19286
19340
|
* @returns Hooks for access validation
|
|
@@ -19290,11 +19344,12 @@ export declare function createAccessControlHooks(config: AccessControlConfig): P
|
|
|
19290
19344
|
* Validates that a token can access a specific tenant based on its organization claim.
|
|
19291
19345
|
*
|
|
19292
19346
|
* @param organizationId - The organization ID from the token (may be undefined)
|
|
19347
|
+
* @param orgName - The organization name from the token (may be undefined, takes precedence)
|
|
19293
19348
|
* @param targetTenantId - The tenant ID being accessed
|
|
19294
|
-
* @param
|
|
19349
|
+
* @param controlPlaneTenantId - The control plane/management tenant ID
|
|
19295
19350
|
* @returns true if access is allowed
|
|
19296
19351
|
*/
|
|
19297
|
-
export declare function validateTenantAccess(organizationId: string | undefined, targetTenantId: string,
|
|
19352
|
+
export declare function validateTenantAccess(organizationId: string | undefined, targetTenantId: string, controlPlaneTenantId: string, orgName?: string): boolean;
|
|
19298
19353
|
/**
|
|
19299
19354
|
* Creates hooks for per-tenant database resolution.
|
|
19300
19355
|
*
|
|
@@ -19331,7 +19386,8 @@ export interface DatabaseFactory {
|
|
|
19331
19386
|
* Creates hooks for tenant provisioning and deprovisioning.
|
|
19332
19387
|
*
|
|
19333
19388
|
* This handles:
|
|
19334
|
-
* -
|
|
19389
|
+
* - Setting the correct audience for new tenants (urn:authhero:tenant:{id})
|
|
19390
|
+
* - Creating organizations on the control plane when a new tenant is created
|
|
19335
19391
|
* - Provisioning databases for new tenants
|
|
19336
19392
|
* - Cleaning up organizations and databases when tenants are deleted
|
|
19337
19393
|
*
|
|
@@ -19344,12 +19400,12 @@ export declare function createProvisioningHooks(config: MultiTenancyConfig): Ten
|
|
|
19344
19400
|
*/
|
|
19345
19401
|
export interface ResourceServerSyncConfig {
|
|
19346
19402
|
/**
|
|
19347
|
-
* The
|
|
19403
|
+
* The control plane tenant ID from which resource servers are synced
|
|
19348
19404
|
*/
|
|
19349
|
-
|
|
19405
|
+
controlPlaneTenantId: string;
|
|
19350
19406
|
/**
|
|
19351
19407
|
* Function to get the list of all tenant IDs to sync to.
|
|
19352
|
-
* Called when a resource server is created/updated/deleted on the
|
|
19408
|
+
* Called when a resource server is created/updated/deleted on the control plane.
|
|
19353
19409
|
*/
|
|
19354
19410
|
getChildTenantIds: () => Promise<string[]>;
|
|
19355
19411
|
/**
|
|
@@ -19382,9 +19438,9 @@ export interface ResourceServerEntityHooks {
|
|
|
19382
19438
|
afterDelete?: (ctx: EntityHookContext$1, id: string) => Promise<void>;
|
|
19383
19439
|
}
|
|
19384
19440
|
/**
|
|
19385
|
-
* Creates entity hooks for syncing resource servers from the
|
|
19441
|
+
* Creates entity hooks for syncing resource servers from the control plane to all child tenants.
|
|
19386
19442
|
*
|
|
19387
|
-
* When a resource server is created, updated, or deleted on the
|
|
19443
|
+
* When a resource server is created, updated, or deleted on the control plane,
|
|
19388
19444
|
* the change is automatically propagated to all child tenants.
|
|
19389
19445
|
*
|
|
19390
19446
|
* @param config - Resource server sync configuration
|
|
@@ -19395,7 +19451,7 @@ export interface ResourceServerEntityHooks {
|
|
|
19395
19451
|
* import { createResourceServerSyncHooks } from "@authhero/multi-tenancy";
|
|
19396
19452
|
*
|
|
19397
19453
|
* const resourceServerHooks = createResourceServerSyncHooks({
|
|
19398
|
-
*
|
|
19454
|
+
* controlPlaneTenantId: "main",
|
|
19399
19455
|
* getChildTenantIds: async () => {
|
|
19400
19456
|
* const tenants = await db.tenants.list();
|
|
19401
19457
|
* return tenants.filter(t => t.id !== "main").map(t => t.id);
|
|
@@ -19420,14 +19476,14 @@ export declare function createResourceServerSyncHooks(config: ResourceServerSync
|
|
|
19420
19476
|
*/
|
|
19421
19477
|
export interface TenantResourceServerSyncConfig {
|
|
19422
19478
|
/**
|
|
19423
|
-
* The
|
|
19479
|
+
* The control plane tenant ID from which resource servers are copied
|
|
19424
19480
|
*/
|
|
19425
|
-
|
|
19481
|
+
controlPlaneTenantId: string;
|
|
19426
19482
|
/**
|
|
19427
|
-
* Function to get adapters for the
|
|
19483
|
+
* Function to get adapters for the control plane.
|
|
19428
19484
|
* Used to read existing resource servers.
|
|
19429
19485
|
*/
|
|
19430
|
-
|
|
19486
|
+
getControlPlaneAdapters: () => Promise<DataAdapters$1>;
|
|
19431
19487
|
/**
|
|
19432
19488
|
* Function to get adapters for the new tenant.
|
|
19433
19489
|
* Used to write resource servers to the new tenant.
|
|
@@ -19446,7 +19502,7 @@ export interface TenantResourceServerSyncConfig {
|
|
|
19446
19502
|
transformForSync?: (resourceServer: ResourceServer$1, targetTenantId: string) => ResourceServerInsert$1;
|
|
19447
19503
|
}
|
|
19448
19504
|
/**
|
|
19449
|
-
* Creates a tenant afterCreate hook that copies all resource servers from the
|
|
19505
|
+
* Creates a tenant afterCreate hook that copies all resource servers from the control plane
|
|
19450
19506
|
* to a newly created tenant.
|
|
19451
19507
|
*
|
|
19452
19508
|
* This should be used with the MultiTenancyHooks.tenants.afterCreate hook.
|
|
@@ -19459,8 +19515,8 @@ export interface TenantResourceServerSyncConfig {
|
|
|
19459
19515
|
* import { createTenantResourceServerSyncHooks } from "@authhero/multi-tenancy";
|
|
19460
19516
|
*
|
|
19461
19517
|
* const resourceServerSyncHooks = createTenantResourceServerSyncHooks({
|
|
19462
|
-
*
|
|
19463
|
-
*
|
|
19518
|
+
* controlPlaneTenantId: "main",
|
|
19519
|
+
* getControlPlaneAdapters: async () => controlPlaneAdapters,
|
|
19464
19520
|
* getAdapters: async (tenantId) => createAdaptersForTenant(tenantId),
|
|
19465
19521
|
* });
|
|
19466
19522
|
*
|
|
@@ -19472,13 +19528,151 @@ export interface TenantResourceServerSyncConfig {
|
|
|
19472
19528
|
* ```
|
|
19473
19529
|
*/
|
|
19474
19530
|
export declare function createTenantResourceServerSyncHooks(config: TenantResourceServerSyncConfig): TenantEntityHooks;
|
|
19531
|
+
/**
|
|
19532
|
+
* Configuration for role synchronization
|
|
19533
|
+
*/
|
|
19534
|
+
export interface RoleSyncConfig {
|
|
19535
|
+
/**
|
|
19536
|
+
* The control plane tenant ID from which roles are synced
|
|
19537
|
+
*/
|
|
19538
|
+
controlPlaneTenantId: string;
|
|
19539
|
+
/**
|
|
19540
|
+
* Function to get the list of all tenant IDs to sync to.
|
|
19541
|
+
* Called when a role is created/updated/deleted on the control plane.
|
|
19542
|
+
*/
|
|
19543
|
+
getChildTenantIds: () => Promise<string[]>;
|
|
19544
|
+
/**
|
|
19545
|
+
* Function to get adapters for a specific tenant.
|
|
19546
|
+
* Used to write roles to child tenants.
|
|
19547
|
+
*/
|
|
19548
|
+
getAdapters: (tenantId: string) => Promise<DataAdapters$1>;
|
|
19549
|
+
/**
|
|
19550
|
+
* Optional: Filter function to determine if a role should be synced.
|
|
19551
|
+
* Return true to sync, false to skip.
|
|
19552
|
+
* @default All roles are synced
|
|
19553
|
+
*/
|
|
19554
|
+
shouldSync?: (role: Role$1) => boolean;
|
|
19555
|
+
/**
|
|
19556
|
+
* Optional: Transform the role before syncing to child tenants.
|
|
19557
|
+
* Useful for modifying names or removing sensitive data.
|
|
19558
|
+
*/
|
|
19559
|
+
transformForSync?: (role: Role$1, targetTenantId: string) => RoleInsert$1;
|
|
19560
|
+
}
|
|
19561
|
+
interface EntityHookContext$2 {
|
|
19562
|
+
tenantId: string;
|
|
19563
|
+
adapters: DataAdapters$1;
|
|
19564
|
+
}
|
|
19565
|
+
/**
|
|
19566
|
+
* Entity hooks for role CRUD operations
|
|
19567
|
+
*/
|
|
19568
|
+
export interface RoleEntityHooks {
|
|
19569
|
+
afterCreate?: (ctx: EntityHookContext$2, entity: Role$1) => Promise<void>;
|
|
19570
|
+
afterUpdate?: (ctx: EntityHookContext$2, id: string, entity: Role$1) => Promise<void>;
|
|
19571
|
+
afterDelete?: (ctx: EntityHookContext$2, id: string) => Promise<void>;
|
|
19572
|
+
}
|
|
19573
|
+
/**
|
|
19574
|
+
* Creates entity hooks for syncing roles from the control plane to all child tenants.
|
|
19575
|
+
*
|
|
19576
|
+
* When a role is created, updated, or deleted on the control plane,
|
|
19577
|
+
* the change is automatically propagated to all child tenants.
|
|
19578
|
+
*
|
|
19579
|
+
* @param config - Role sync configuration
|
|
19580
|
+
* @returns Entity hooks for role synchronization
|
|
19581
|
+
*
|
|
19582
|
+
* @example
|
|
19583
|
+
* ```typescript
|
|
19584
|
+
* import { createRoleSyncHooks } from "@authhero/multi-tenancy";
|
|
19585
|
+
*
|
|
19586
|
+
* const roleHooks = createRoleSyncHooks({
|
|
19587
|
+
* controlPlaneTenantId: "main",
|
|
19588
|
+
* getChildTenantIds: async () => {
|
|
19589
|
+
* const tenants = await db.tenants.list();
|
|
19590
|
+
* return tenants.filter(t => t.id !== "main").map(t => t.id);
|
|
19591
|
+
* },
|
|
19592
|
+
* getAdapters: async (tenantId) => {
|
|
19593
|
+
* return createAdaptersForTenant(tenantId);
|
|
19594
|
+
* },
|
|
19595
|
+
* });
|
|
19596
|
+
*
|
|
19597
|
+
* // Use with AuthHero config
|
|
19598
|
+
* const config: AuthHeroConfig = {
|
|
19599
|
+
* dataAdapter,
|
|
19600
|
+
* entityHooks: {
|
|
19601
|
+
* roles: roleHooks,
|
|
19602
|
+
* },
|
|
19603
|
+
* };
|
|
19604
|
+
* ```
|
|
19605
|
+
*/
|
|
19606
|
+
export declare function createRoleSyncHooks(config: RoleSyncConfig): RoleEntityHooks;
|
|
19607
|
+
/**
|
|
19608
|
+
* Configuration for syncing roles to new tenants
|
|
19609
|
+
*/
|
|
19610
|
+
export interface TenantRoleSyncConfig {
|
|
19611
|
+
/**
|
|
19612
|
+
* The control plane tenant ID from which roles are copied
|
|
19613
|
+
*/
|
|
19614
|
+
controlPlaneTenantId: string;
|
|
19615
|
+
/**
|
|
19616
|
+
* Function to get adapters for the control plane.
|
|
19617
|
+
* Used to read existing roles.
|
|
19618
|
+
*/
|
|
19619
|
+
getControlPlaneAdapters: () => Promise<DataAdapters$1>;
|
|
19620
|
+
/**
|
|
19621
|
+
* Function to get adapters for the new tenant.
|
|
19622
|
+
* Used to write roles to the new tenant.
|
|
19623
|
+
*/
|
|
19624
|
+
getAdapters: (tenantId: string) => Promise<DataAdapters$1>;
|
|
19625
|
+
/**
|
|
19626
|
+
* Optional: Filter function to determine if a role should be synced.
|
|
19627
|
+
* Return true to sync, false to skip.
|
|
19628
|
+
* @default All roles are synced
|
|
19629
|
+
*/
|
|
19630
|
+
shouldSync?: (role: Role$1) => boolean;
|
|
19631
|
+
/**
|
|
19632
|
+
* Optional: Transform the role before syncing to the new tenant.
|
|
19633
|
+
* Useful for modifying names or removing sensitive data.
|
|
19634
|
+
*/
|
|
19635
|
+
transformForSync?: (role: Role$1, targetTenantId: string) => RoleInsert$1;
|
|
19636
|
+
/**
|
|
19637
|
+
* Whether to also sync role permissions (scopes from resource servers).
|
|
19638
|
+
* @default true
|
|
19639
|
+
*/
|
|
19640
|
+
syncPermissions?: boolean;
|
|
19641
|
+
}
|
|
19642
|
+
/**
|
|
19643
|
+
* Creates a tenant afterCreate hook that copies all roles from the control plane
|
|
19644
|
+
* to a newly created tenant.
|
|
19645
|
+
*
|
|
19646
|
+
* This should be used with the MultiTenancyHooks.tenants.afterCreate hook.
|
|
19647
|
+
*
|
|
19648
|
+
* @param config - Configuration for tenant role sync
|
|
19649
|
+
* @returns A TenantEntityHooks object with afterCreate implemented
|
|
19650
|
+
*
|
|
19651
|
+
* @example
|
|
19652
|
+
* ```typescript
|
|
19653
|
+
* import { createTenantRoleSyncHooks } from "@authhero/multi-tenancy";
|
|
19654
|
+
*
|
|
19655
|
+
* const roleSyncHooks = createTenantRoleSyncHooks({
|
|
19656
|
+
* controlPlaneTenantId: "main",
|
|
19657
|
+
* getControlPlaneAdapters: async () => controlPlaneAdapters,
|
|
19658
|
+
* getAdapters: async (tenantId) => createAdaptersForTenant(tenantId),
|
|
19659
|
+
* });
|
|
19660
|
+
*
|
|
19661
|
+
* const multiTenancyHooks: MultiTenancyHooks = {
|
|
19662
|
+
* tenants: {
|
|
19663
|
+
* afterCreate: roleSyncHooks.afterCreate,
|
|
19664
|
+
* },
|
|
19665
|
+
* };
|
|
19666
|
+
* ```
|
|
19667
|
+
*/
|
|
19668
|
+
export declare function createTenantRoleSyncHooks(config: TenantRoleSyncConfig): TenantEntityHooks;
|
|
19475
19669
|
/**
|
|
19476
19670
|
* Creates the tenant management routes.
|
|
19477
19671
|
*
|
|
19478
19672
|
* These routes handle CRUD operations for tenants and should be mounted
|
|
19479
19673
|
* on a management API path (e.g., /management/tenants).
|
|
19480
19674
|
*
|
|
19481
|
-
* Access to these routes should be restricted to the
|
|
19675
|
+
* Access to these routes should be restricted to the control plane.
|
|
19482
19676
|
*
|
|
19483
19677
|
* @param config - Multi-tenancy configuration
|
|
19484
19678
|
* @param hooks - Multi-tenancy hooks for lifecycle events
|
|
@@ -19504,10 +19698,10 @@ export interface ProtectSystemVariables {
|
|
|
19504
19698
|
* Creates middleware to protect system resources from modification.
|
|
19505
19699
|
*
|
|
19506
19700
|
* This middleware intercepts write operations (PATCH, PUT, DELETE) on
|
|
19507
|
-
* entities that are marked as system entities from the
|
|
19701
|
+
* entities that are marked as system entities from the control plane and returns a 403
|
|
19508
19702
|
* error if modification is attempted.
|
|
19509
19703
|
*
|
|
19510
|
-
* System resources can only be modified in the
|
|
19704
|
+
* System resources can only be modified in the control plane, and changes
|
|
19511
19705
|
* will be propagated to child tenants automatically.
|
|
19512
19706
|
*
|
|
19513
19707
|
* @returns Hono middleware handler
|
|
@@ -19530,7 +19724,7 @@ export declare function createProtectSyncedMiddleware(): MiddlewareHandler<{
|
|
|
19530
19724
|
* This middleware checks that the token's organization claim matches
|
|
19531
19725
|
* the target tenant ID, implementing the access control model where:
|
|
19532
19726
|
*
|
|
19533
|
-
* -
|
|
19727
|
+
* - Control plane: Accessible without an organization claim
|
|
19534
19728
|
* - Child tenants: Require an organization claim matching the tenant ID
|
|
19535
19729
|
*
|
|
19536
19730
|
* @param config - Multi-tenancy configuration
|
|
@@ -19542,7 +19736,7 @@ export declare function createProtectSyncedMiddleware(): MiddlewareHandler<{
|
|
|
19542
19736
|
*
|
|
19543
19737
|
* const middleware = createAccessControlMiddleware({
|
|
19544
19738
|
* accessControl: {
|
|
19545
|
-
*
|
|
19739
|
+
* controlPlaneTenantId: "main",
|
|
19546
19740
|
* },
|
|
19547
19741
|
* });
|
|
19548
19742
|
*
|
|
@@ -19557,7 +19751,7 @@ export declare function createAccessControlMiddleware(config: MultiTenancyConfig
|
|
|
19557
19751
|
* Creates middleware for resolving tenants from subdomains.
|
|
19558
19752
|
*
|
|
19559
19753
|
* This middleware extracts the subdomain from the request host and
|
|
19560
|
-
* resolves it to a tenant ID using organizations on the
|
|
19754
|
+
* resolves it to a tenant ID using organizations on the control plane.
|
|
19561
19755
|
*
|
|
19562
19756
|
* @param config - Multi-tenancy configuration
|
|
19563
19757
|
* @returns Hono middleware handler
|
|
@@ -19572,7 +19766,7 @@ export declare function createAccessControlMiddleware(config: MultiTenancyConfig
|
|
|
19572
19766
|
* reservedSubdomains: ["www", "api", "admin"],
|
|
19573
19767
|
* },
|
|
19574
19768
|
* accessControl: {
|
|
19575
|
-
*
|
|
19769
|
+
* controlPlaneTenantId: "main",
|
|
19576
19770
|
* },
|
|
19577
19771
|
* });
|
|
19578
19772
|
*
|
|
@@ -19718,7 +19912,7 @@ export interface AuthHeroPlugin {
|
|
|
19718
19912
|
* plugins: [
|
|
19719
19913
|
* createMultiTenancyPlugin({
|
|
19720
19914
|
* accessControl: {
|
|
19721
|
-
*
|
|
19915
|
+
* controlPlaneTenantId: "main",
|
|
19722
19916
|
* defaultPermissions: ["tenant:admin"],
|
|
19723
19917
|
* },
|
|
19724
19918
|
* subdomainRouting: {
|
|
@@ -19745,7 +19939,7 @@ export declare function createMultiTenancyPlugin(config: MultiTenancyConfig): Au
|
|
|
19745
19939
|
*
|
|
19746
19940
|
* const hooks = createMultiTenancyHooks({
|
|
19747
19941
|
* accessControl: {
|
|
19748
|
-
*
|
|
19942
|
+
* controlPlaneTenantId: "main",
|
|
19749
19943
|
* defaultPermissions: ["tenant:admin"],
|
|
19750
19944
|
* },
|
|
19751
19945
|
* databaseIsolation: {
|
|
@@ -19773,7 +19967,7 @@ export declare function createMultiTenancyHooks(config: MultiTenancyConfig): Mul
|
|
|
19773
19967
|
*
|
|
19774
19968
|
* const multiTenancyApp = createMultiTenancy({
|
|
19775
19969
|
* accessControl: {
|
|
19776
|
-
*
|
|
19970
|
+
* controlPlaneTenantId: "main",
|
|
19777
19971
|
* },
|
|
19778
19972
|
* });
|
|
19779
19973
|
*
|
|
@@ -19800,7 +19994,7 @@ export declare function createMultiTenancy(config: MultiTenancyConfig): Hono<{
|
|
|
19800
19994
|
*
|
|
19801
19995
|
* const multiTenancy = setupMultiTenancy({
|
|
19802
19996
|
* accessControl: {
|
|
19803
|
-
*
|
|
19997
|
+
* controlPlaneTenantId: "main",
|
|
19804
19998
|
* },
|
|
19805
19999
|
* subdomainRouting: {
|
|
19806
20000
|
* baseDomain: "auth.example.com",
|
|
@@ -19834,38 +20028,50 @@ export declare function setupMultiTenancy(config: MultiTenancyConfig): {
|
|
|
19834
20028
|
/**
|
|
19835
20029
|
* Configuration for multi-tenant AuthHero initialization.
|
|
19836
20030
|
*/
|
|
19837
|
-
export interface MultiTenantAuthHeroConfig extends Omit<AuthHeroConfig, "entityHooks"> {
|
|
20031
|
+
export interface MultiTenantAuthHeroConfig extends Omit<AuthHeroConfig, "entityHooks" | "managementApiExtensions"> {
|
|
19838
20032
|
/**
|
|
19839
|
-
* The
|
|
20033
|
+
* The control plane tenant ID that manages all other tenants.
|
|
19840
20034
|
* This tenant can create, update, and delete other tenants.
|
|
19841
20035
|
* @default "main"
|
|
19842
20036
|
*/
|
|
19843
|
-
|
|
20037
|
+
controlPlaneTenantId?: string;
|
|
19844
20038
|
/**
|
|
19845
|
-
* Whether to sync resource servers from the
|
|
19846
|
-
* When enabled, resource servers created on the
|
|
20039
|
+
* Whether to sync resource servers from the control plane to child tenants.
|
|
20040
|
+
* When enabled, resource servers created on the control plane are automatically
|
|
19847
20041
|
* copied to all other tenants.
|
|
19848
20042
|
* @default true
|
|
19849
20043
|
*/
|
|
19850
20044
|
syncResourceServers?: boolean;
|
|
20045
|
+
/**
|
|
20046
|
+
* Whether to sync roles from the control plane to child tenants.
|
|
20047
|
+
* When enabled, roles created on the control plane are automatically
|
|
20048
|
+
* copied to all other tenants (including their permissions).
|
|
20049
|
+
* @default true
|
|
20050
|
+
*/
|
|
20051
|
+
syncRoles?: boolean;
|
|
19851
20052
|
/**
|
|
19852
20053
|
* Additional multi-tenancy configuration options.
|
|
19853
20054
|
*/
|
|
19854
20055
|
multiTenancy?: Omit<MultiTenancyConfig, "accessControl"> & {
|
|
19855
|
-
accessControl?: Omit<NonNullable<MultiTenancyConfig["accessControl"]>, "
|
|
20056
|
+
accessControl?: Omit<NonNullable<MultiTenancyConfig["accessControl"]>, "controlPlaneTenantId">;
|
|
19856
20057
|
};
|
|
19857
20058
|
/**
|
|
19858
20059
|
* Entity hooks configuration.
|
|
19859
20060
|
* Resource server and tenant hooks will be merged with the sync hooks.
|
|
19860
20061
|
*/
|
|
19861
20062
|
entityHooks?: AuthHeroConfig["entityHooks"];
|
|
20063
|
+
/**
|
|
20064
|
+
* Additional routes to mount on the management API.
|
|
20065
|
+
* Note: The tenant CRUD routes are automatically added by multi-tenancy.
|
|
20066
|
+
*/
|
|
20067
|
+
managementApiExtensions?: ManagementApiExtension[];
|
|
19862
20068
|
}
|
|
19863
20069
|
/**
|
|
19864
20070
|
* Initializes a multi-tenant AuthHero server.
|
|
19865
20071
|
*
|
|
19866
20072
|
* This wraps the standard AuthHero `init()` function and adds:
|
|
19867
20073
|
* - Tenant CRUD routes (list, create, update, delete) at /api/v2/tenants
|
|
19868
|
-
* - Resource server synchronization from
|
|
20074
|
+
* - Resource server synchronization from control plane to child tenants
|
|
19869
20075
|
* - Tenant creation hooks to copy resource servers to new tenants
|
|
19870
20076
|
*
|
|
19871
20077
|
* @param config - Multi-tenant AuthHero configuration
|
|
@@ -19880,7 +20086,7 @@ export interface MultiTenantAuthHeroConfig extends Omit<AuthHeroConfig, "entityH
|
|
|
19880
20086
|
*
|
|
19881
20087
|
* const { app } = init({
|
|
19882
20088
|
* dataAdapter,
|
|
19883
|
-
*
|
|
20089
|
+
* controlPlaneTenantId: "main",
|
|
19884
20090
|
* syncResourceServers: true,
|
|
19885
20091
|
* });
|
|
19886
20092
|
*
|
|
@@ -20385,6 +20591,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20385
20591
|
grant_type: "client_credentials";
|
|
20386
20592
|
scope?: string | undefined;
|
|
20387
20593
|
audience?: string | undefined;
|
|
20594
|
+
organization?: string | undefined;
|
|
20388
20595
|
client_id?: string | undefined;
|
|
20389
20596
|
client_secret?: string | undefined;
|
|
20390
20597
|
} | {
|
|
@@ -20419,6 +20626,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20419
20626
|
grant_type: "client_credentials";
|
|
20420
20627
|
scope?: string | undefined;
|
|
20421
20628
|
audience?: string | undefined;
|
|
20629
|
+
organization?: string | undefined;
|
|
20422
20630
|
client_id?: string | undefined;
|
|
20423
20631
|
client_secret?: string | undefined;
|
|
20424
20632
|
} | {
|
|
@@ -20458,6 +20666,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20458
20666
|
grant_type: "client_credentials";
|
|
20459
20667
|
scope?: string | undefined;
|
|
20460
20668
|
audience?: string | undefined;
|
|
20669
|
+
organization?: string | undefined;
|
|
20461
20670
|
client_id?: string | undefined;
|
|
20462
20671
|
client_secret?: string | undefined;
|
|
20463
20672
|
} | {
|
|
@@ -20492,6 +20701,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20492
20701
|
grant_type: "client_credentials";
|
|
20493
20702
|
scope?: string | undefined;
|
|
20494
20703
|
audience?: string | undefined;
|
|
20704
|
+
organization?: string | undefined;
|
|
20495
20705
|
client_id?: string | undefined;
|
|
20496
20706
|
client_secret?: string | undefined;
|
|
20497
20707
|
} | {
|
|
@@ -20539,6 +20749,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20539
20749
|
grant_type: "client_credentials";
|
|
20540
20750
|
scope?: string | undefined;
|
|
20541
20751
|
audience?: string | undefined;
|
|
20752
|
+
organization?: string | undefined;
|
|
20542
20753
|
client_id?: string | undefined;
|
|
20543
20754
|
client_secret?: string | undefined;
|
|
20544
20755
|
} | {
|
|
@@ -20573,6 +20784,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20573
20784
|
grant_type: "client_credentials";
|
|
20574
20785
|
scope?: string | undefined;
|
|
20575
20786
|
audience?: string | undefined;
|
|
20787
|
+
organization?: string | undefined;
|
|
20576
20788
|
client_id?: string | undefined;
|
|
20577
20789
|
client_secret?: string | undefined;
|
|
20578
20790
|
} | {
|
|
@@ -20615,6 +20827,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20615
20827
|
grant_type: "client_credentials";
|
|
20616
20828
|
scope?: string | undefined;
|
|
20617
20829
|
audience?: string | undefined;
|
|
20830
|
+
organization?: string | undefined;
|
|
20618
20831
|
client_id?: string | undefined;
|
|
20619
20832
|
client_secret?: string | undefined;
|
|
20620
20833
|
} | {
|
|
@@ -20649,6 +20862,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20649
20862
|
grant_type: "client_credentials";
|
|
20650
20863
|
scope?: string | undefined;
|
|
20651
20864
|
audience?: string | undefined;
|
|
20865
|
+
organization?: string | undefined;
|
|
20652
20866
|
client_id?: string | undefined;
|
|
20653
20867
|
client_secret?: string | undefined;
|
|
20654
20868
|
} | {
|
|
@@ -20691,6 +20905,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20691
20905
|
grant_type: "client_credentials";
|
|
20692
20906
|
scope?: string | undefined;
|
|
20693
20907
|
audience?: string | undefined;
|
|
20908
|
+
organization?: string | undefined;
|
|
20694
20909
|
client_id?: string | undefined;
|
|
20695
20910
|
client_secret?: string | undefined;
|
|
20696
20911
|
} | {
|
|
@@ -20725,6 +20940,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
20725
20940
|
grant_type: "client_credentials";
|
|
20726
20941
|
scope?: string | undefined;
|
|
20727
20942
|
audience?: string | undefined;
|
|
20943
|
+
organization?: string | undefined;
|
|
20728
20944
|
client_id?: string | undefined;
|
|
20729
20945
|
client_secret?: string | undefined;
|
|
20730
20946
|
} | {
|
|
@@ -22663,7 +22879,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22663
22879
|
};
|
|
22664
22880
|
} & {
|
|
22665
22881
|
header: {
|
|
22666
|
-
"tenant-id"
|
|
22882
|
+
"tenant-id"?: string | undefined;
|
|
22667
22883
|
};
|
|
22668
22884
|
};
|
|
22669
22885
|
output: {
|
|
@@ -22699,7 +22915,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22699
22915
|
};
|
|
22700
22916
|
} & {
|
|
22701
22917
|
header: {
|
|
22702
|
-
"tenant-id"
|
|
22918
|
+
"tenant-id"?: string | undefined;
|
|
22703
22919
|
};
|
|
22704
22920
|
};
|
|
22705
22921
|
output: {
|
|
@@ -22719,7 +22935,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22719
22935
|
$post: {
|
|
22720
22936
|
input: {
|
|
22721
22937
|
header: {
|
|
22722
|
-
"tenant-id"
|
|
22938
|
+
"tenant-id"?: string | undefined;
|
|
22723
22939
|
};
|
|
22724
22940
|
} & {
|
|
22725
22941
|
json: {
|
|
@@ -22749,7 +22965,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22749
22965
|
};
|
|
22750
22966
|
} & {
|
|
22751
22967
|
header: {
|
|
22752
|
-
"tenant-id"
|
|
22968
|
+
"tenant-id"?: string | undefined;
|
|
22753
22969
|
};
|
|
22754
22970
|
} & {
|
|
22755
22971
|
json: {
|
|
@@ -22779,7 +22995,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22779
22995
|
};
|
|
22780
22996
|
} & {
|
|
22781
22997
|
header: {
|
|
22782
|
-
"tenant-id"
|
|
22998
|
+
"tenant-id"?: string | undefined;
|
|
22783
22999
|
};
|
|
22784
23000
|
};
|
|
22785
23001
|
output: {};
|
|
@@ -22804,7 +23020,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22804
23020
|
};
|
|
22805
23021
|
} & {
|
|
22806
23022
|
header: {
|
|
22807
|
-
"tenant-id"
|
|
23023
|
+
"tenant-id"?: string | undefined;
|
|
22808
23024
|
};
|
|
22809
23025
|
};
|
|
22810
23026
|
output: {
|
|
@@ -22826,7 +23042,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22826
23042
|
};
|
|
22827
23043
|
} & {
|
|
22828
23044
|
header: {
|
|
22829
|
-
"tenant-id"
|
|
23045
|
+
"tenant-id"?: string | undefined;
|
|
22830
23046
|
};
|
|
22831
23047
|
} & {
|
|
22832
23048
|
json: {
|
|
@@ -22850,7 +23066,7 @@ export declare function init(config: MultiTenantAuthHeroConfig): {
|
|
|
22850
23066
|
};
|
|
22851
23067
|
} & {
|
|
22852
23068
|
header: {
|
|
22853
|
-
"tenant-id"
|
|
23069
|
+
"tenant-id"?: string | undefined;
|
|
22854
23070
|
};
|
|
22855
23071
|
} & {
|
|
22856
23072
|
json: {
|