@authhero/multi-tenancy 14.4.0 → 14.5.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.mjs +378 -354
- package/dist/types/index.d.ts +18 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/init.d.ts +35 -7
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/middleware/settings-inheritance.d.ts.map +1 -1
- package/dist/types/routes/tenants.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Hono } from "hono";
|
|
|
2
2
|
import { MultiTenancyConfig, MultiTenancyHooks, MultiTenancyBindings, MultiTenancyVariables } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export { initMultiTenant } from "./init";
|
|
5
|
-
export type { MultiTenantConfig, MultiTenantResult } from "./init";
|
|
5
|
+
export type { MultiTenantConfig, MultiTenantResult, ControlPlaneConfig, } from "./init";
|
|
6
6
|
export { createSyncHooks } from "./hooks/sync";
|
|
7
7
|
export type { EntitySyncConfig, SyncHooksResult } from "./hooks/sync";
|
|
8
8
|
export { createTenantsOpenAPIRouter } from "./routes";
|
|
@@ -75,7 +75,7 @@ export declare function createMultiTenancy(config: MultiTenancyConfig): Hono<{
|
|
|
75
75
|
* integrate multi-tenancy into an AuthHero application.
|
|
76
76
|
*
|
|
77
77
|
* @param config - Multi-tenancy configuration
|
|
78
|
-
* @returns Object with hooks, middleware, and
|
|
78
|
+
* @returns Object with hooks, middleware, routes, and wrapAdapters helper
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
81
|
* ```typescript
|
|
@@ -90,6 +90,11 @@ export declare function createMultiTenancy(config: MultiTenancyConfig): Hono<{
|
|
|
90
90
|
* },
|
|
91
91
|
* });
|
|
92
92
|
*
|
|
93
|
+
* // Wrap your adapters with runtime fallback (uses same controlPlaneTenantId)
|
|
94
|
+
* const dataAdapter = multiTenancy.wrapAdapters(baseAdapters, {
|
|
95
|
+
* controlPlaneClientId: "default_client", // optional additional config
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
93
98
|
* // Use the middleware
|
|
94
99
|
* app.use("*", multiTenancy.middleware);
|
|
95
100
|
*
|
|
@@ -113,5 +118,16 @@ export declare function setupMultiTenancy(config: MultiTenancyConfig): {
|
|
|
113
118
|
Variables: MultiTenancyVariables;
|
|
114
119
|
}, import("hono/types").BlankSchema, "/">;
|
|
115
120
|
config: MultiTenancyConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Wraps data adapters with runtime fallback from the control plane.
|
|
123
|
+
* Uses the controlPlaneTenantId from the multi-tenancy config.
|
|
124
|
+
*
|
|
125
|
+
* @param adapters - Base data adapters to wrap
|
|
126
|
+
* @param additionalConfig - Additional config (controlPlaneClientId, etc.)
|
|
127
|
+
* @returns Wrapped adapters with runtime fallback
|
|
128
|
+
*/
|
|
129
|
+
wrapAdapters: (adapters: import("authhero").DataAdapters, additionalConfig?: {
|
|
130
|
+
controlPlaneClientId?: string;
|
|
131
|
+
}) => import("authhero").DataAdapters;
|
|
116
132
|
};
|
|
117
133
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAajB,cAAc,SAAS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;;;;;OAOG;6BAES,OAAO,UAAU,EAAE,YAAY,qBACtB;QAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAE;EAOzD"}
|
package/dist/types/init.d.ts
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { init, AuthHeroConfig, DataAdapters } from "authhero";
|
|
2
|
+
/**
|
|
3
|
+
* Control plane configuration for multi-tenancy.
|
|
4
|
+
*/
|
|
5
|
+
export interface ControlPlaneConfig {
|
|
6
|
+
/**
|
|
7
|
+
* The control plane tenant ID - the tenant that manages all other tenants.
|
|
8
|
+
*/
|
|
9
|
+
tenantId: string;
|
|
10
|
+
/**
|
|
11
|
+
* The control plane client ID used for fallback client settings.
|
|
12
|
+
* This client's configuration (web_origins, callbacks, etc.) will
|
|
13
|
+
* be merged with child tenant clients at runtime.
|
|
14
|
+
*/
|
|
15
|
+
clientId: string;
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Configuration for multi-tenant AuthHero initialization.
|
|
4
19
|
*/
|
|
5
20
|
export interface MultiTenantConfig extends Omit<AuthHeroConfig, "entityHooks" | "managementApiExtensions"> {
|
|
6
21
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
22
|
+
* Control plane configuration. If provided, enables:
|
|
23
|
+
* - Runtime fallback for connections, clients, and tenant settings
|
|
24
|
+
* - Organization-based access control for the tenants API
|
|
25
|
+
* - Automatic organization creation when tenants are created
|
|
9
26
|
*/
|
|
10
|
-
|
|
27
|
+
controlPlane?: ControlPlaneConfig;
|
|
11
28
|
/**
|
|
12
29
|
* Control which entities to sync from control plane to child tenants.
|
|
13
30
|
* Set to `false` to disable all syncing.
|
|
@@ -65,12 +82,13 @@ export interface MultiTenantResult {
|
|
|
65
82
|
* - Creates sync hooks for resource servers and roles
|
|
66
83
|
* - Mounts the tenants management API at `/tenants`
|
|
67
84
|
* - Adds middleware to protect synced entities on child tenants
|
|
68
|
-
* - Sets up organization-based access control
|
|
85
|
+
* - Sets up organization-based access control (when controlPlane is configured)
|
|
86
|
+
* - Wraps adapters with runtime fallback from control plane
|
|
69
87
|
*
|
|
70
88
|
* @param config - Multi-tenant configuration
|
|
71
89
|
* @returns The configured app and control plane tenant ID
|
|
72
90
|
*
|
|
73
|
-
* @example
|
|
91
|
+
* @example Basic setup
|
|
74
92
|
* ```typescript
|
|
75
93
|
* import { initMultiTenant } from "@authhero/multi-tenancy";
|
|
76
94
|
* import createAdapters from "@authhero/kysely-adapter";
|
|
@@ -79,7 +97,10 @@ export interface MultiTenantResult {
|
|
|
79
97
|
*
|
|
80
98
|
* const { app } = initMultiTenant({
|
|
81
99
|
* dataAdapter,
|
|
82
|
-
*
|
|
100
|
+
* controlPlane: {
|
|
101
|
+
* tenantId: "main",
|
|
102
|
+
* clientId: "default_client",
|
|
103
|
+
* },
|
|
83
104
|
* });
|
|
84
105
|
*
|
|
85
106
|
* export default app;
|
|
@@ -89,7 +110,10 @@ export interface MultiTenantResult {
|
|
|
89
110
|
* ```typescript
|
|
90
111
|
* const { app } = initMultiTenant({
|
|
91
112
|
* dataAdapter,
|
|
92
|
-
*
|
|
113
|
+
* controlPlane: {
|
|
114
|
+
* tenantId: "main",
|
|
115
|
+
* clientId: "default_client",
|
|
116
|
+
* },
|
|
93
117
|
* sync: {
|
|
94
118
|
* resourceServers: true,
|
|
95
119
|
* roles: false, // Don't sync roles
|
|
@@ -102,6 +126,10 @@ export interface MultiTenantResult {
|
|
|
102
126
|
* ```typescript
|
|
103
127
|
* const { app } = initMultiTenant({
|
|
104
128
|
* dataAdapter,
|
|
129
|
+
* controlPlane: {
|
|
130
|
+
* tenantId: "main",
|
|
131
|
+
* clientId: "default_client",
|
|
132
|
+
* },
|
|
105
133
|
* sync: false, // Each tenant manages their own entities
|
|
106
134
|
* });
|
|
107
135
|
* ```
|
package/dist/types/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"m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AAoB,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CA6G5E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings-inheritance.d.ts","sourceRoot":"","sources":["../../../src/middleware/settings-inheritance.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,qBAAqB,GAC5B,YAAY,
|
|
1
|
+
{"version":3,"file":"settings-inheritance.d.ts","sourceRoot":"","sources":["../../../src/middleware/settings-inheritance.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,qBAAqB,GAC5B,YAAY,CAmMd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,qBAAqB,GAC5B,YAAY,CAEd;AAGD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,gCAAgC,qCAA+B,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,uBAAuB,4BAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../../../src/routes/tenants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAQhE,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,iBAAiB;cAGZ,oBAAoB;eACnB,qBAAqB;
|
|
1
|
+
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../../../src/routes/tenants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAQhE,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,iBAAiB;cAGZ,oBAAoB;eACnB,qBAAqB;YAgWnC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
13
|
},
|
|
14
|
-
"version": "14.
|
|
14
|
+
"version": "14.5.0",
|
|
15
15
|
"description": "Multi-tenancy support for AuthHero with organization-based access control and per-tenant database isolation",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"typescript": "^5.6.0",
|
|
37
37
|
"vite": "^6.0.0",
|
|
38
38
|
"vitest": "^2.1.0",
|
|
39
|
-
"@authhero/kysely-adapter": "10.80.
|
|
40
|
-
"authhero": "4.
|
|
41
|
-
"@authhero/adapter-interfaces": "0.
|
|
39
|
+
"@authhero/kysely-adapter": "10.80.1",
|
|
40
|
+
"authhero": "4.9.1",
|
|
41
|
+
"@authhero/adapter-interfaces": "0.122.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"zod": "^3.24.0"
|