@authhero/multi-tenancy 13.20.0 → 14.0.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.
@@ -1,17 +1,17 @@
1
- var V = Object.defineProperty;
2
- var W = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var O = (n, e, t) => W(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { Hono as Q } from "hono";
5
- import { getTenantAudience as J, MANAGEMENT_API_SCOPES as X, MANAGEMENT_API_AUDIENCE as Y, fetchAll as $, init as Z } from "authhero";
6
- import { OpenAPIHono as x, createRoute as R, z as I } from "@hono/zod-openapi";
7
- import { auth0QuerySchema as ee, tenantSchema as N, tenantInsertSchema as te, connectionSchema as D, connectionOptionsSchema as F } from "@authhero/adapter-interfaces";
8
- function ne(n) {
9
- const { controlPlaneTenantId: e, requireOrganizationMatch: t = !0 } = n;
1
+ var W = Object.defineProperty;
2
+ var Q = (t, e, n) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var O = (t, e, n) => Q(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { Hono as J } from "hono";
5
+ import { MANAGEMENT_API_SCOPES as X, MANAGEMENT_API_AUDIENCE as U, fetchAll as z, init as Y } from "authhero";
6
+ import { OpenAPIHono as Z, createRoute as R, z as I } from "@hono/zod-openapi";
7
+ import { auth0QuerySchema as x, tenantSchema as N, tenantInsertSchema as ee, connectionSchema as D, connectionOptionsSchema as F } from "@authhero/adapter-interfaces";
8
+ function te(t) {
9
+ const { controlPlaneTenantId: e, requireOrganizationMatch: n = !0 } = t;
10
10
  return {
11
11
  async onTenantAccessValidation(s, r) {
12
12
  if (r === e)
13
13
  return !0;
14
- if (t) {
14
+ if (n) {
15
15
  const i = s.var.org_name, o = s.var.organization_id, a = i || o;
16
16
  return a ? a.toLowerCase() === r.toLowerCase() : !1;
17
17
  }
@@ -19,105 +19,108 @@ function ne(n) {
19
19
  }
20
20
  };
21
21
  }
22
- function se(n, e, t, s) {
23
- if (e === t)
22
+ function ne(t, e, n, s) {
23
+ if (e === n)
24
24
  return !0;
25
- const r = s || n;
25
+ const r = s || t;
26
26
  return r ? r.toLowerCase() === e.toLowerCase() : !1;
27
27
  }
28
- function re(n) {
28
+ function se(t) {
29
29
  return {
30
30
  async resolveDataAdapters(e) {
31
31
  try {
32
- return await n.getAdapters(e);
33
- } catch (t) {
32
+ return await t.getAdapters(e);
33
+ } catch (n) {
34
34
  console.error(
35
35
  `Failed to resolve data adapters for tenant ${e}:`,
36
- t
36
+ n
37
37
  );
38
38
  return;
39
39
  }
40
40
  }
41
41
  };
42
42
  }
43
- function ae(n) {
43
+ function ae(t) {
44
+ return `urn:authhero:tenant:${t.toLowerCase()}`;
45
+ }
46
+ function re(t) {
44
47
  return {
45
- async beforeCreate(e, t) {
46
- return !t.audience && t.id ? {
47
- ...t,
48
- audience: J(t.id)
49
- } : t;
48
+ async beforeCreate(e, n) {
49
+ return !n.audience && n.id ? {
50
+ ...n,
51
+ audience: ae(n.id)
52
+ } : n;
50
53
  },
51
- async afterCreate(e, t) {
52
- const { accessControl: s, databaseIsolation: r } = n;
53
- s && e.ctx && await oe(e, t, s), r != null && r.onProvision && await r.onProvision(t.id);
54
+ async afterCreate(e, n) {
55
+ const { accessControl: s, databaseIsolation: r } = t;
56
+ s && e.ctx && await oe(e, n, s), r != null && r.onProvision && await r.onProvision(n.id);
54
57
  },
55
- async beforeDelete(e, t) {
56
- const { accessControl: s, databaseIsolation: r } = n;
58
+ async beforeDelete(e, n) {
59
+ const { accessControl: s, databaseIsolation: r } = t;
57
60
  if (s)
58
61
  try {
59
62
  const o = (await e.adapters.organizations.list(
60
63
  s.controlPlaneTenantId
61
- )).organizations.find((a) => a.name === t);
64
+ )).organizations.find((a) => a.name === n);
62
65
  o && await e.adapters.organizations.remove(
63
66
  s.controlPlaneTenantId,
64
67
  o.id
65
68
  );
66
69
  } catch (i) {
67
70
  console.warn(
68
- `Failed to remove organization for tenant ${t}:`,
71
+ `Failed to remove organization for tenant ${n}:`,
69
72
  i
70
73
  );
71
74
  }
72
75
  if (r != null && r.onDeprovision)
73
76
  try {
74
- await r.onDeprovision(t);
77
+ await r.onDeprovision(n);
75
78
  } catch (i) {
76
79
  console.warn(
77
- `Failed to deprovision database for tenant ${t}:`,
80
+ `Failed to deprovision database for tenant ${n}:`,
78
81
  i
79
82
  );
80
83
  }
81
84
  }
82
85
  };
83
86
  }
84
- async function oe(n, e, t) {
87
+ async function oe(t, e, n) {
85
88
  const {
86
89
  controlPlaneTenantId: s,
87
90
  defaultPermissions: r,
88
91
  defaultRoles: i,
89
92
  issuer: o,
90
93
  adminRoleName: a = "Tenant Admin",
91
- adminRoleDescription: m = "Full access to all tenant management operations",
94
+ adminRoleDescription: u = "Full access to all tenant management operations",
92
95
  addCreatorToOrganization: d = !0
93
- } = t, c = await n.adapters.organizations.create(
96
+ } = n, c = await t.adapters.organizations.create(
94
97
  s,
95
98
  {
96
99
  name: e.id,
97
100
  display_name: e.friendly_name || e.id
98
101
  }
99
102
  );
100
- let p;
101
- if (o && (p = await ce(
102
- n,
103
+ let f;
104
+ if (o && (f = await ce(
105
+ t,
103
106
  s,
104
107
  a,
105
- m
106
- )), d && n.ctx) {
107
- const l = n.ctx.var.user;
108
+ u
109
+ )), d && t.ctx) {
110
+ const l = t.ctx.var.user;
108
111
  if (l != null && l.sub && !await ie(
109
- n,
112
+ t,
110
113
  s,
111
114
  l.sub
112
115
  ))
113
116
  try {
114
- await n.adapters.userOrganizations.create(s, {
117
+ await t.adapters.userOrganizations.create(s, {
115
118
  user_id: l.sub,
116
119
  organization_id: c.id
117
- }), p && await n.adapters.userRoles.create(
120
+ }), f && await t.adapters.userRoles.create(
118
121
  s,
119
122
  l.sub,
120
- p,
123
+ f,
121
124
  c.id
122
125
  // organizationId
123
126
  );
@@ -134,16 +137,16 @@ async function oe(n, e, t) {
134
137
  `Would grant permissions ${r.join(", ")} to organization ${c.id}`
135
138
  );
136
139
  }
137
- async function ie(n, e, t) {
138
- const s = await n.adapters.userRoles.list(
140
+ async function ie(t, e, n) {
141
+ const s = await t.adapters.userRoles.list(
139
142
  e,
140
- t,
143
+ n,
141
144
  void 0,
142
145
  ""
143
146
  // Empty string for global roles
144
147
  );
145
148
  for (const r of s)
146
- if ((await n.adapters.rolePermissions.list(
149
+ if ((await t.adapters.rolePermissions.list(
147
150
  e,
148
151
  r.id,
149
152
  { per_page: 1e3 }
@@ -153,22 +156,22 @@ async function ie(n, e, t) {
153
156
  return !0;
154
157
  return !1;
155
158
  }
156
- async function ce(n, e, t, s) {
157
- const i = (await n.adapters.roles.list(e, {})).roles.find((d) => d.name === t);
159
+ async function ce(t, e, n, s) {
160
+ const i = (await t.adapters.roles.list(e, {})).roles.find((d) => d.name === n);
158
161
  if (i)
159
162
  return i.id;
160
- const o = await n.adapters.roles.create(e, {
161
- name: t,
163
+ const o = await t.adapters.roles.create(e, {
164
+ name: n,
162
165
  description: s
163
- }), a = Y, m = X.map((d) => ({
166
+ }), a = U, u = X.map((d) => ({
164
167
  role_id: o.id,
165
168
  resource_server_identifier: a,
166
169
  permission_name: d.value
167
170
  }));
168
- return await n.adapters.rolePermissions.assign(
171
+ return await t.adapters.rolePermissions.assign(
169
172
  e,
170
173
  o.id,
171
- m
174
+ u
172
175
  ), o.id;
173
176
  }
174
177
  const le = [
@@ -180,31 +183,31 @@ const le = [
180
183
  "twilio_sid",
181
184
  "twilio_token"
182
185
  ];
183
- function q(n, e, t = () => !0) {
184
- const { controlPlaneTenantId: s, getChildTenantIds: r, getAdapters: i } = n, o = /* @__PURE__ */ new Map();
185
- async function a(c, p, l) {
186
- return (await e(c).list(p, {
186
+ function M(t, e, n = () => !0) {
187
+ const { controlPlaneTenantId: s, getChildTenantIds: r, getAdapters: i } = t, o = /* @__PURE__ */ new Map();
188
+ async function a(c, f, l) {
189
+ return (await e(c).list(f, {
187
190
  q: `name:${l}`,
188
191
  per_page: 1
189
192
  }))[0] ?? null;
190
193
  }
191
- async function m(c) {
192
- const p = await r(), l = e(await i(s));
194
+ async function u(c) {
195
+ const f = await r(), l = e(await i(s));
193
196
  await Promise.all(
194
- p.map(async (u) => {
197
+ f.map(async (m) => {
195
198
  try {
196
- const w = await i(u), g = e(w), h = {
199
+ const w = await i(m), g = e(w), h = {
197
200
  ...l.transform(c),
198
201
  is_system: !0
199
- }, y = await a(w, u, c.name), v = y ? g.getId(y) : void 0;
202
+ }, y = await a(w, m, c.name), v = y ? g.getId(y) : void 0;
200
203
  if (y && v) {
201
204
  const b = g.preserveOnUpdate ? g.preserveOnUpdate(y, h) : h;
202
- await g.update(u, v, b);
205
+ await g.update(m, v, b);
203
206
  } else
204
- await g.create(u, h);
207
+ await g.create(m, h);
205
208
  } catch (w) {
206
209
  console.error(
207
- `Failed to sync ${l.listKey} "${c.name}" to tenant "${u}":`,
210
+ `Failed to sync ${l.listKey} "${c.name}" to tenant "${m}":`,
208
211
  w
209
212
  );
210
213
  }
@@ -212,56 +215,56 @@ function q(n, e, t = () => !0) {
212
215
  );
213
216
  }
214
217
  async function d(c) {
215
- const p = await r();
218
+ const f = await r();
216
219
  await Promise.all(
217
- p.map(async (l) => {
220
+ f.map(async (l) => {
218
221
  try {
219
- const u = await i(l), w = e(u), g = await a(u, l, c), f = g ? w.getId(g) : void 0;
220
- g && f && await w.remove(l, f);
221
- } catch (u) {
222
+ const m = await i(l), w = e(m), g = await a(m, l, c), p = g ? w.getId(g) : void 0;
223
+ g && p && await w.remove(l, p);
224
+ } catch (m) {
222
225
  console.error(
223
226
  `Failed to delete entity "${c}" from tenant "${l}":`,
224
- u
227
+ m
225
228
  );
226
229
  }
227
230
  })
228
231
  );
229
232
  }
230
233
  return {
231
- afterCreate: async (c, p) => {
232
- c.tenantId === s && t(p) && await m(p);
234
+ afterCreate: async (c, f) => {
235
+ c.tenantId === s && n(f) && await u(f);
233
236
  },
234
- afterUpdate: async (c, p, l) => {
235
- c.tenantId === s && t(l) && await m(l);
237
+ afterUpdate: async (c, f, l) => {
238
+ c.tenantId === s && n(l) && await u(l);
236
239
  },
237
- beforeDelete: async (c, p) => {
240
+ beforeDelete: async (c, f) => {
238
241
  if (c.tenantId !== s) return;
239
- const u = await e(c.adapters).get(c.tenantId, p);
240
- u && t(u) && o.set(p, u);
242
+ const m = await e(c.adapters).get(c.tenantId, f);
243
+ m && n(m) && o.set(f, m);
241
244
  },
242
- afterDelete: async (c, p) => {
245
+ afterDelete: async (c, f) => {
243
246
  if (c.tenantId !== s) return;
244
- const l = o.get(p);
245
- l && (o.delete(p), await d(l.name));
247
+ const l = o.get(f);
248
+ l && (o.delete(f), await d(l.name));
246
249
  }
247
250
  };
248
251
  }
249
- function M(n, e, t = () => !0) {
250
- const { controlPlaneTenantId: s, getControlPlaneAdapters: r, getAdapters: i } = n;
252
+ function q(t, e, n = () => !0) {
253
+ const { controlPlaneTenantId: s, getControlPlaneAdapters: r, getAdapters: i } = t;
251
254
  return {
252
255
  async afterCreate(o, a) {
253
256
  if (a.id !== s)
254
257
  try {
255
- const m = await r(), d = await i(a.id), c = e(m), p = e(d), l = await $(
256
- (u) => c.listPaginated(s, u),
258
+ const u = await r(), d = await i(a.id), c = e(u), f = e(d), l = await z(
259
+ (m) => c.listPaginated(s, m),
257
260
  c.listKey,
258
261
  { cursorField: "id", pageSize: 100 }
259
262
  );
260
263
  await Promise.all(
261
- l.filter((u) => t(u)).map(async (u) => {
264
+ l.filter((m) => n(m)).map(async (m) => {
262
265
  try {
263
- const w = c.transform(u);
264
- await p.create(a.id, {
266
+ const w = c.transform(m);
267
+ await f.create(a.id, {
265
268
  ...w,
266
269
  is_system: !0
267
270
  });
@@ -273,22 +276,22 @@ function M(n, e, t = () => !0) {
273
276
  }
274
277
  })
275
278
  );
276
- } catch (m) {
279
+ } catch (u) {
277
280
  console.error(
278
281
  `Failed to sync entities to new tenant "${a.id}":`,
279
- m
282
+ u
280
283
  );
281
284
  }
282
285
  }
283
286
  };
284
287
  }
285
- const H = (n) => ({
286
- list: async (e, t) => (await n.resourceServers.list(e, t)).resource_servers,
287
- listPaginated: (e, t) => n.resourceServers.list(e, t),
288
- get: (e, t) => n.resourceServers.get(e, t),
289
- create: (e, t) => n.resourceServers.create(e, t),
290
- update: (e, t, s) => n.resourceServers.update(e, t, s),
291
- remove: (e, t) => n.resourceServers.remove(e, t),
288
+ const H = (t) => ({
289
+ list: async (e, n) => (await t.resourceServers.list(e, n)).resource_servers,
290
+ listPaginated: (e, n) => t.resourceServers.list(e, n),
291
+ get: (e, n) => t.resourceServers.get(e, n),
292
+ create: (e, n) => t.resourceServers.create(e, n),
293
+ update: (e, n, s) => t.resourceServers.update(e, n, s),
294
+ remove: (e, n) => t.resourceServers.remove(e, n),
292
295
  listKey: "resource_servers",
293
296
  getId: (e) => e.id,
294
297
  transform: (e) => ({
@@ -300,13 +303,13 @@ const H = (n) => ({
300
303
  token_lifetime: e.token_lifetime,
301
304
  token_lifetime_for_web: e.token_lifetime_for_web
302
305
  })
303
- }), G = (n) => ({
304
- list: async (e, t) => (await n.roles.list(e, t)).roles,
305
- listPaginated: (e, t) => n.roles.list(e, t),
306
- get: (e, t) => n.roles.get(e, t),
307
- create: (e, t) => n.roles.create(e, t),
308
- update: (e, t, s) => n.roles.update(e, t, s),
309
- remove: (e, t) => n.roles.remove(e, t),
306
+ }), G = (t) => ({
307
+ list: async (e, n) => (await t.roles.list(e, n)).roles,
308
+ listPaginated: (e, n) => t.roles.list(e, n),
309
+ get: (e, n) => t.roles.get(e, n),
310
+ create: (e, n) => t.roles.create(e, n),
311
+ update: (e, n, s) => t.roles.update(e, n, s),
312
+ remove: (e, n) => t.roles.remove(e, n),
310
313
  listKey: "roles",
311
314
  getId: (e) => e.id,
312
315
  transform: (e) => ({
@@ -314,25 +317,25 @@ const H = (n) => ({
314
317
  name: e.name,
315
318
  description: e.description
316
319
  })
317
- }), U = (n) => ({
318
- list: async (e, t) => (await n.connections.list(e, t)).connections,
319
- listPaginated: (e, t) => n.connections.list(e, t),
320
- get: (e, t) => n.connections.get(e, t),
321
- create: (e, t) => n.connections.create(e, t),
322
- update: (e, t, s) => n.connections.update(e, t, s),
323
- remove: (e, t) => n.connections.remove(e, t),
320
+ }), L = (t) => ({
321
+ list: async (e, n) => (await t.connections.list(e, n)).connections,
322
+ listPaginated: (e, n) => t.connections.list(e, n),
323
+ get: (e, n) => t.connections.get(e, n),
324
+ create: (e, n) => t.connections.create(e, n),
325
+ update: (e, n, s) => t.connections.update(e, n, s),
326
+ remove: (e, n) => t.connections.remove(e, n),
324
327
  listKey: "connections",
325
328
  getId: (e) => e.id,
326
329
  transform: (e) => {
327
- const t = e.options ? { ...e.options } : {};
330
+ const n = e.options ? { ...e.options } : {};
328
331
  for (const s of le)
329
- delete t[s];
332
+ delete n[s];
330
333
  return {
331
334
  id: e.id,
332
335
  name: e.name,
333
336
  display_name: e.display_name,
334
337
  strategy: e.strategy,
335
- options: t,
338
+ options: n,
336
339
  response_type: e.response_type,
337
340
  response_mode: e.response_mode,
338
341
  is_domain_connection: e.is_domain_connection,
@@ -340,12 +343,12 @@ const H = (n) => ({
340
343
  metadata: e.metadata
341
344
  };
342
345
  },
343
- preserveOnUpdate: (e, t) => {
346
+ preserveOnUpdate: (e, n) => {
344
347
  const s = e.options || {};
345
348
  return {
346
- ...t,
349
+ ...n,
347
350
  options: {
348
- ...t.options,
351
+ ...n.options,
349
352
  client_id: s.client_id,
350
353
  client_secret: s.client_secret,
351
354
  app_secret: s.app_secret,
@@ -357,40 +360,40 @@ const H = (n) => ({
357
360
  };
358
361
  }
359
362
  });
360
- function de(n) {
361
- const { sync: e = {}, filters: t = {} } = n, s = e.resourceServers ?? !0, r = e.roles ?? !0, i = e.connections ?? !0, o = s ? q(
362
- n,
363
+ function de(t) {
364
+ const { sync: e = {}, filters: n = {} } = t, s = e.resourceServers ?? !0, r = e.roles ?? !0, i = e.connections ?? !0, o = s ? M(
365
+ t,
363
366
  H,
364
- t.resourceServers
365
- ) : void 0, a = r ? q(
366
- n,
367
+ n.resourceServers
368
+ ) : void 0, a = r ? M(
369
+ t,
367
370
  G,
368
- t.roles
369
- ) : void 0, m = i ? q(
370
- n,
371
- U,
372
- t.connections
373
- ) : void 0, d = s ? M(
374
- n,
371
+ n.roles
372
+ ) : void 0, u = i ? M(
373
+ t,
374
+ L,
375
+ n.connections
376
+ ) : void 0, d = s ? q(
377
+ t,
375
378
  H,
376
- t.resourceServers
377
- ) : void 0, c = r ? M(
378
- n,
379
+ n.resourceServers
380
+ ) : void 0, c = r ? q(
381
+ t,
379
382
  G,
380
- t.roles
381
- ) : void 0, p = i ? M(
382
- n,
383
- U,
384
- t.connections
383
+ n.roles
384
+ ) : void 0, f = i ? q(
385
+ t,
386
+ L,
387
+ n.connections
385
388
  ) : void 0, l = r ? {
386
- async afterCreate(g, f) {
389
+ async afterCreate(g, p) {
387
390
  var h;
388
- if (f.id !== n.controlPlaneTenantId) {
389
- await ((h = c == null ? void 0 : c.afterCreate) == null ? void 0 : h.call(c, g, f));
391
+ if (p.id !== t.controlPlaneTenantId) {
392
+ await ((h = c == null ? void 0 : c.afterCreate) == null ? void 0 : h.call(c, g, p));
390
393
  try {
391
- const y = await n.getControlPlaneAdapters(), v = await n.getAdapters(f.id), b = await $(
394
+ const y = await t.getControlPlaneAdapters(), v = await t.getAdapters(p.id), b = await z(
392
395
  (_) => y.roles.list(
393
- n.controlPlaneTenantId,
396
+ t.controlPlaneTenantId,
394
397
  _
395
398
  ),
396
399
  "roles",
@@ -399,12 +402,12 @@ function de(n) {
399
402
  for (const _ of b.filter(
400
403
  (T) => {
401
404
  var A;
402
- return ((A = t.roles) == null ? void 0 : A.call(t, T)) ?? !0;
405
+ return ((A = n.roles) == null ? void 0 : A.call(n, T)) ?? !0;
403
406
  }
404
407
  )) {
405
- const T = await u(
408
+ const T = await m(
406
409
  v,
407
- f.id,
410
+ p.id,
408
411
  _.name
409
412
  );
410
413
  T && S.set(_.name, T.id);
@@ -412,19 +415,19 @@ function de(n) {
412
415
  for (const _ of b.filter(
413
416
  (T) => {
414
417
  var A;
415
- return ((A = t.roles) == null ? void 0 : A.call(t, T)) ?? !0;
418
+ return ((A = n.roles) == null ? void 0 : A.call(n, T)) ?? !0;
416
419
  }
417
420
  )) {
418
421
  const T = S.get(_.name);
419
422
  if (T)
420
423
  try {
421
424
  const A = await y.rolePermissions.list(
422
- n.controlPlaneTenantId,
425
+ t.controlPlaneTenantId,
423
426
  _.id,
424
427
  {}
425
428
  );
426
429
  A.length > 0 && await v.rolePermissions.assign(
427
- f.id,
430
+ p.id,
428
431
  T,
429
432
  A.map((P) => ({
430
433
  role_id: T,
@@ -434,22 +437,22 @@ function de(n) {
434
437
  );
435
438
  } catch (A) {
436
439
  console.error(
437
- `Failed to sync permissions for role "${_.name}" to tenant "${f.id}":`,
440
+ `Failed to sync permissions for role "${_.name}" to tenant "${p.id}":`,
438
441
  A
439
442
  );
440
443
  }
441
444
  }
442
445
  } catch (y) {
443
446
  console.error(
444
- `Failed to sync role permissions to tenant "${f.id}":`,
447
+ `Failed to sync role permissions to tenant "${p.id}":`,
445
448
  y
446
449
  );
447
450
  }
448
451
  }
449
452
  }
450
453
  } : void 0;
451
- async function u(g, f, h) {
452
- return (await g.roles.list(f, {
454
+ async function m(g, p, h) {
455
+ return (await g.roles.list(p, {
453
456
  q: `name:${h}`,
454
457
  per_page: 1
455
458
  })).roles[0] ?? null;
@@ -458,19 +461,19 @@ function de(n) {
458
461
  entityHooks: {
459
462
  resourceServers: o,
460
463
  roles: a,
461
- connections: m
464
+ connections: u
462
465
  },
463
466
  tenantHooks: {
464
- async afterCreate(g, f) {
467
+ async afterCreate(g, p) {
465
468
  const h = [
466
469
  d == null ? void 0 : d.afterCreate,
467
470
  (l == null ? void 0 : l.afterCreate) ?? (c == null ? void 0 : c.afterCreate),
468
- p == null ? void 0 : p.afterCreate
471
+ f == null ? void 0 : f.afterCreate
469
472
  ], y = [];
470
473
  for (const v of h)
471
474
  if (v)
472
475
  try {
473
- await v(g, f);
476
+ await v(g, p);
474
477
  } catch (b) {
475
478
  y.push(b instanceof Error ? b : new Error(String(b)));
476
479
  }
@@ -490,11 +493,11 @@ var C = class extends Error {
490
493
  * @param status - HTTP status code for the exception. Defaults to 500.
491
494
  * @param options - Additional options for the exception.
492
495
  */
493
- constructor(e = 500, t) {
494
- super(t == null ? void 0 : t.message, { cause: t == null ? void 0 : t.cause });
496
+ constructor(e = 500, n) {
497
+ super(n == null ? void 0 : n.message, { cause: n == null ? void 0 : n.cause });
495
498
  O(this, "res");
496
499
  O(this, "status");
497
- this.res = t == null ? void 0 : t.res, this.status = e;
500
+ this.res = n == null ? void 0 : n.res, this.status = e;
498
501
  }
499
502
  /**
500
503
  * Returns the response object associated with the exception.
@@ -510,15 +513,15 @@ var C = class extends Error {
510
513
  });
511
514
  }
512
515
  };
513
- function k(n, e) {
514
- const t = new x();
515
- return t.openapi(
516
+ function k(t, e) {
517
+ const n = new Z();
518
+ return n.openapi(
516
519
  R({
517
520
  tags: ["tenants"],
518
521
  method: "get",
519
522
  path: "/",
520
523
  request: {
521
- query: ee
524
+ query: x
522
525
  },
523
526
  security: [
524
527
  {
@@ -542,31 +545,31 @@ function k(n, e) {
542
545
  }
543
546
  }),
544
547
  async (s) => {
545
- var u, w, g, f;
546
- const r = s.req.valid("query"), { page: i, per_page: o, include_totals: a, q: m } = r, d = s.var.user, c = (d == null ? void 0 : d.permissions) || [];
548
+ var m, w, g, p;
549
+ const r = s.req.valid("query"), { page: i, per_page: o, include_totals: a, q: u } = r, d = s.var.user, c = (d == null ? void 0 : d.permissions) || [];
547
550
  if (c.includes("auth:read") || c.includes("admin:organizations")) {
548
551
  const h = await s.env.data.tenants.list({
549
552
  page: i,
550
553
  per_page: o,
551
554
  include_totals: a,
552
- q: m
555
+ q: u
553
556
  });
554
557
  return a ? s.json({
555
558
  tenants: h.tenants,
556
- start: ((u = h.totals) == null ? void 0 : u.start) ?? 0,
559
+ start: ((m = h.totals) == null ? void 0 : m.start) ?? 0,
557
560
  limit: ((w = h.totals) == null ? void 0 : w.limit) ?? o,
558
561
  length: h.tenants.length
559
562
  }) : s.json({ tenants: h.tenants });
560
563
  }
561
- if (n.accessControl && (d != null && d.sub)) {
562
- const h = n.accessControl.controlPlaneTenantId, v = (await $(
563
- (z) => s.env.data.userOrganizations.listUserOrganizations(
564
+ if (t.accessControl && (d != null && d.sub)) {
565
+ const h = t.accessControl.controlPlaneTenantId, v = (await z(
566
+ ($) => s.env.data.userOrganizations.listUserOrganizations(
564
567
  h,
565
568
  d.sub,
566
- z
569
+ $
567
570
  ),
568
571
  "organizations"
569
- )).map((z) => z.name);
572
+ )).map(($) => $.name);
570
573
  if (v.length === 0)
571
574
  return a ? s.json({
572
575
  tenants: [],
@@ -582,8 +585,8 @@ function k(n, e) {
582
585
  limit: _,
583
586
  length: b
584
587
  }) : s.json({ tenants: [] });
585
- const P = A.map((z) => `id:${z}`).join(" OR "), K = m ? `(${P}) AND (${m})` : P, E = await s.env.data.tenants.list({
586
- q: K,
588
+ const P = A.map(($) => `id:${$}`).join(" OR "), V = u ? `(${P}) AND (${u})` : P, E = await s.env.data.tenants.list({
589
+ q: V,
587
590
  per_page: _,
588
591
  include_totals: !1
589
592
  // We calculate totals from accessibleTenantIds
@@ -599,16 +602,16 @@ function k(n, e) {
599
602
  page: i,
600
603
  per_page: o,
601
604
  include_totals: a,
602
- q: m
605
+ q: u
603
606
  });
604
607
  return a ? s.json({
605
608
  tenants: l.tenants,
606
609
  start: ((g = l.totals) == null ? void 0 : g.start) ?? 0,
607
- limit: ((f = l.totals) == null ? void 0 : f.limit) ?? o,
610
+ limit: ((p = l.totals) == null ? void 0 : p.limit) ?? o,
608
611
  length: l.tenants.length
609
612
  }) : s.json({ tenants: l.tenants });
610
613
  }
611
- ), t.openapi(
614
+ ), n.openapi(
612
615
  R({
613
616
  tags: ["tenants"],
614
617
  method: "post",
@@ -617,7 +620,7 @@ function k(n, e) {
617
620
  body: {
618
621
  content: {
619
622
  "application/json": {
620
- schema: te
623
+ schema: ee
621
624
  }
622
625
  }
623
626
  }
@@ -645,7 +648,7 @@ function k(n, e) {
645
648
  }
646
649
  }),
647
650
  async (s) => {
648
- var m, d;
651
+ var u, d;
649
652
  const r = s.var.user;
650
653
  if (!(r != null && r.sub))
651
654
  throw new C(401, {
@@ -656,11 +659,11 @@ function k(n, e) {
656
659
  adapters: s.env.data,
657
660
  ctx: s
658
661
  };
659
- (m = e.tenants) != null && m.beforeCreate && (i = await e.tenants.beforeCreate(o, i));
662
+ (u = e.tenants) != null && u.beforeCreate && (i = await e.tenants.beforeCreate(o, i));
660
663
  const a = await s.env.data.tenants.create(i);
661
664
  return (d = e.tenants) != null && d.afterCreate && await e.tenants.afterCreate(o, a), s.json(a, 201);
662
665
  }
663
- ), t.openapi(
666
+ ), n.openapi(
664
667
  R({
665
668
  tags: ["tenants"],
666
669
  method: "delete",
@@ -688,10 +691,10 @@ function k(n, e) {
688
691
  }
689
692
  }),
690
693
  async (s) => {
691
- var a, m;
694
+ var a, u;
692
695
  const { id: r } = s.req.valid("param");
693
- if (n.accessControl) {
694
- const d = s.var.user, c = n.accessControl.controlPlaneTenantId;
696
+ if (t.accessControl) {
697
+ const d = s.var.user, c = t.accessControl.controlPlaneTenantId;
695
698
  if (!(d != null && d.sub))
696
699
  throw new C(401, {
697
700
  message: "Authentication required"
@@ -700,14 +703,14 @@ function k(n, e) {
700
703
  throw new C(403, {
701
704
  message: "Cannot delete the control plane"
702
705
  });
703
- if (!(await $(
704
- (u) => s.env.data.userOrganizations.listUserOrganizations(
706
+ if (!(await z(
707
+ (m) => s.env.data.userOrganizations.listUserOrganizations(
705
708
  c,
706
709
  d.sub,
707
- u
710
+ m
708
711
  ),
709
712
  "organizations"
710
- )).some((u) => u.name === r))
713
+ )).some((m) => m.name === r))
711
714
  throw new C(403, {
712
715
  message: "Access denied to this tenant"
713
716
  });
@@ -720,11 +723,11 @@ function k(n, e) {
720
723
  adapters: s.env.data,
721
724
  ctx: s
722
725
  };
723
- return (a = e.tenants) != null && a.beforeDelete && await e.tenants.beforeDelete(o, r), await s.env.data.tenants.remove(r), (m = e.tenants) != null && m.afterDelete && await e.tenants.afterDelete(o, r), s.body(null, 204);
726
+ return (a = e.tenants) != null && a.beforeDelete && await e.tenants.beforeDelete(o, r), await s.env.data.tenants.remove(r), (u = e.tenants) != null && u.afterDelete && await e.tenants.afterDelete(o, r), s.body(null, 204);
724
727
  }
725
- ), t;
728
+ ), n;
726
729
  }
727
- function ue(n) {
730
+ function ue(t) {
728
731
  const e = [
729
732
  {
730
733
  pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
@@ -733,26 +736,26 @@ function ue(n) {
733
736
  { pattern: /\/api\/v2\/roles\/([^/]+)$/, type: "role" },
734
737
  { pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
735
738
  ];
736
- for (const { pattern: t, type: s } of e) {
737
- const r = n.match(t);
739
+ for (const { pattern: n, type: s } of e) {
740
+ const r = t.match(n);
738
741
  if (r && r[1])
739
742
  return { type: s, id: r[1] };
740
743
  }
741
744
  return null;
742
745
  }
743
- async function me(n, e, t) {
746
+ async function me(t, e, n) {
744
747
  try {
745
- switch (t.type) {
748
+ switch (n.type) {
746
749
  case "resource_server": {
747
- const s = await n.resourceServers.get(e, t.id);
750
+ const s = await t.resourceServers.get(e, n.id);
748
751
  return (s == null ? void 0 : s.is_system) === !0;
749
752
  }
750
753
  case "role": {
751
- const s = await n.roles.get(e, t.id);
754
+ const s = await t.roles.get(e, n.id);
752
755
  return (s == null ? void 0 : s.is_system) === !0;
753
756
  }
754
757
  case "connection": {
755
- const s = await n.connections.get(e, t.id);
758
+ const s = await t.connections.get(e, n.id);
756
759
  return (s == null ? void 0 : s.is_system) === !0;
757
760
  }
758
761
  default:
@@ -762,63 +765,63 @@ async function me(n, e, t) {
762
765
  return !1;
763
766
  }
764
767
  }
765
- function pe(n) {
768
+ function fe(t) {
766
769
  return {
767
770
  resource_server: "resource server",
768
771
  role: "role",
769
772
  connection: "connection"
770
- }[n];
773
+ }[t];
771
774
  }
772
- function fe() {
773
- return async (n, e) => {
774
- if (!["PATCH", "PUT", "DELETE"].includes(n.req.method))
775
+ function pe() {
776
+ return async (t, e) => {
777
+ if (!["PATCH", "PUT", "DELETE"].includes(t.req.method))
775
778
  return e();
776
- const t = ue(n.req.path);
777
- if (!t)
779
+ const n = ue(t.req.path);
780
+ if (!n)
778
781
  return e();
779
- const s = n.var.tenant_id || n.req.header("x-tenant-id") || n.req.header("tenant-id");
782
+ const s = t.var.tenant_id || t.req.header("x-tenant-id") || t.req.header("tenant-id");
780
783
  if (!s)
781
784
  return e();
782
- if (await me(n.env.data, s, t))
785
+ if (await me(t.env.data, s, n))
783
786
  throw new C(403, {
784
- message: `This ${pe(t.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
787
+ message: `This ${fe(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
785
788
  });
786
789
  return e();
787
790
  };
788
791
  }
789
- function L(n, e) {
790
- const { controlPlaneTenantId: t, controlPlaneClientId: s } = e;
792
+ function B(t, e) {
793
+ const { controlPlaneTenantId: n, controlPlaneClientId: s } = e;
791
794
  return {
792
- ...n,
795
+ ...t,
793
796
  legacyClients: {
794
- ...n.legacyClients,
797
+ ...t.legacyClients,
795
798
  get: async (r) => {
796
- var p;
797
- const i = await n.legacyClients.get(r);
799
+ var f;
800
+ const i = await t.legacyClients.get(r);
798
801
  if (!i)
799
802
  return null;
800
- const o = s ? await n.legacyClients.get(s) : void 0, a = await n.connections.list(
803
+ const o = s ? await t.legacyClients.get(s) : void 0, a = await t.connections.list(
801
804
  i.tenant.id
802
- ), m = t ? await n.connections.list(t) : { connections: [] }, d = a.connections.map((l) => {
805
+ ), u = n ? await t.connections.list(n) : { connections: [] }, d = a.connections.map((l) => {
803
806
  var g;
804
- const u = (g = m.connections) == null ? void 0 : g.find(
805
- (f) => f.name === l.name
807
+ const m = (g = u.connections) == null ? void 0 : g.find(
808
+ (p) => p.name === l.name
806
809
  );
807
- if (!(u != null && u.options))
810
+ if (!(m != null && m.options))
808
811
  return l;
809
812
  const w = D.parse({
810
- ...u || {},
813
+ ...m || {},
811
814
  ...l
812
815
  });
813
816
  return w.options = F.parse({
814
- ...u.options || {},
817
+ ...m.options || {},
815
818
  ...l.options
816
819
  }), w;
817
820
  }).filter((l) => l), c = {
818
821
  ...(o == null ? void 0 : o.tenant) || {},
819
822
  ...i.tenant
820
823
  };
821
- return !i.tenant.audience && ((p = o == null ? void 0 : o.tenant) != null && p.audience) && (c.audience = o.tenant.audience), {
824
+ return !i.tenant.audience && ((f = o == null ? void 0 : o.tenant) != null && f.audience) && (c.audience = o.tenant.audience), {
822
825
  ...i,
823
826
  web_origins: [
824
827
  ...(o == null ? void 0 : o.web_origins) || [],
@@ -838,52 +841,52 @@ function L(n, e) {
838
841
  }
839
842
  },
840
843
  connections: {
841
- ...n.connections,
844
+ ...t.connections,
842
845
  get: async (r, i) => {
843
- const o = await n.connections.get(
846
+ const o = await t.connections.get(
844
847
  r,
845
848
  i
846
849
  );
847
- if (!o || !t)
850
+ if (!o || !n)
848
851
  return o;
849
- const a = await n.connections.get(
850
- t,
852
+ const a = await t.connections.get(
853
+ n,
851
854
  i
852
855
  );
853
856
  if (!a)
854
857
  return o;
855
- const m = D.parse({
858
+ const u = D.parse({
856
859
  ...a,
857
860
  ...o
858
861
  });
859
- return m.options = F.parse({
862
+ return u.options = F.parse({
860
863
  ...a.options || {},
861
864
  ...o.options
862
- }), m;
865
+ }), u;
863
866
  },
864
867
  list: async (r, i) => {
865
- const o = await n.connections.list(r, i);
866
- if (!t || r === t)
868
+ const o = await t.connections.list(r, i);
869
+ if (!n || r === n)
867
870
  return o;
868
- const a = await n.connections.list(t), m = o.connections.map((d) => {
871
+ const a = await t.connections.list(n), u = o.connections.map((d) => {
869
872
  var l;
870
873
  const c = (l = a.connections) == null ? void 0 : l.find(
871
- (u) => u.name === d.name
874
+ (m) => m.name === d.name
872
875
  );
873
876
  if (!(c != null && c.options))
874
877
  return d;
875
- const p = D.parse({
878
+ const f = D.parse({
876
879
  ...c,
877
880
  ...d
878
881
  });
879
- return p.options = F.parse({
882
+ return f.options = F.parse({
880
883
  ...c.options || {},
881
884
  ...d.options
882
- }), p;
885
+ }), f;
883
886
  });
884
887
  return {
885
888
  ...o,
886
- connections: m
889
+ connections: u
887
890
  };
888
891
  }
889
892
  }
@@ -896,76 +899,79 @@ function L(n, e) {
896
899
  // They remain part of ...baseAdapters and can be properly wrapped by caching.
897
900
  };
898
901
  }
899
- function ge(n, e) {
900
- return L(n, e);
902
+ function ge(t, e) {
903
+ return B(t, e);
901
904
  }
902
- const Ie = L, Se = ge;
903
- function we(n) {
904
- return async (e, t) => {
905
- if (!n.accessControl)
906
- return t();
907
- const s = e.var.tenant_id, r = e.var.organization_id;
908
- if (!s)
905
+ const Ie = B, Se = ge;
906
+ function we(t) {
907
+ return async (e, n) => {
908
+ if (!t.accessControl)
909
+ return n();
910
+ const { controlPlaneTenantId: s } = t.accessControl, r = e.var.org_name, i = e.var.organization_id, o = r || i;
911
+ let a = e.var.tenant_id;
912
+ const u = e.var.user, c = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(U);
913
+ if (!a && o && c && (e.set("tenant_id", o), a = o), !a)
909
914
  throw new C(400, {
910
915
  message: "Tenant ID not found in request"
911
916
  });
912
- if (!se(
913
- r,
917
+ if (!ne(
918
+ i,
919
+ a,
914
920
  s,
915
- n.accessControl.controlPlaneTenantId
921
+ r
916
922
  ))
917
923
  throw new C(403, {
918
- message: `Access denied to tenant ${s}`
924
+ message: `Access denied to tenant ${a}`
919
925
  });
920
- return t();
926
+ return n();
921
927
  };
922
928
  }
923
- function he(n) {
924
- return async (e, t) => {
925
- if (!n.subdomainRouting)
926
- return t();
929
+ function he(t) {
930
+ return async (e, n) => {
931
+ if (!t.subdomainRouting)
932
+ return n();
927
933
  const {
928
934
  baseDomain: s,
929
935
  reservedSubdomains: r = [],
930
936
  resolveSubdomain: i
931
- } = n.subdomainRouting, o = e.req.header("host") || "";
937
+ } = t.subdomainRouting, o = e.req.header("host") || "";
932
938
  let a = null;
933
939
  if (o.endsWith(s)) {
934
940
  const d = o.slice(0, -(s.length + 1));
935
941
  d && !d.includes(".") && (a = d);
936
942
  }
937
943
  if (a && r.includes(a) && (a = null), !a)
938
- return n.accessControl && e.set("tenant_id", n.accessControl.controlPlaneTenantId), t();
939
- let m = null;
944
+ return t.accessControl && e.set("tenant_id", t.accessControl.controlPlaneTenantId), n();
945
+ let u = null;
940
946
  if (i)
941
- m = await i(a);
942
- else if (n.subdomainRouting.useOrganizations !== !1 && n.accessControl)
947
+ u = await i(a);
948
+ else if (t.subdomainRouting.useOrganizations !== !1 && t.accessControl)
943
949
  try {
944
950
  const d = await e.env.data.organizations.get(
945
- n.accessControl.controlPlaneTenantId,
951
+ t.accessControl.controlPlaneTenantId,
946
952
  a
947
953
  );
948
- d && (m = d.id);
954
+ d && (u = d.id);
949
955
  } catch {
950
956
  }
951
- if (!m)
957
+ if (!u)
952
958
  throw new C(404, {
953
959
  message: `Tenant not found for subdomain: ${a}`
954
960
  });
955
- return e.set("tenant_id", m), t();
961
+ return e.set("tenant_id", u), n();
956
962
  };
957
963
  }
958
- function ye(n) {
959
- return async (e, t) => {
960
- if (!n.databaseIsolation)
961
- return t();
964
+ function ye(t) {
965
+ return async (e, n) => {
966
+ if (!t.databaseIsolation)
967
+ return n();
962
968
  const s = e.var.tenant_id;
963
969
  if (!s)
964
970
  throw new C(400, {
965
971
  message: "Tenant ID not found in request"
966
972
  });
967
973
  try {
968
- const r = await n.databaseIsolation.getAdapters(s);
974
+ const r = await t.databaseIsolation.getAdapters(s);
969
975
  e.env.data = r;
970
976
  } catch (r) {
971
977
  throw console.error(
@@ -975,50 +981,50 @@ function ye(n) {
975
981
  message: "Failed to resolve tenant database"
976
982
  });
977
983
  }
978
- return t();
984
+ return n();
979
985
  };
980
986
  }
981
- function B(n) {
982
- const e = he(n), t = we(n), s = ye(n);
987
+ function K(t) {
988
+ const e = he(t), n = we(t), s = ye(t);
983
989
  return async (r, i) => (await e(r, async () => {
984
- }), await t(r, async () => {
990
+ }), await n(r, async () => {
985
991
  }), await s(r, async () => {
986
992
  }), i());
987
993
  }
988
- function Pe(n) {
994
+ function Pe(t) {
989
995
  const {
990
996
  dataAdapter: e,
991
- controlPlaneTenantId: t = "control_plane",
997
+ controlPlaneTenantId: n = "control_plane",
992
998
  sync: s = { resourceServers: !0, roles: !0, connections: !0 },
993
999
  defaultPermissions: r = ["tenant:admin"],
994
1000
  requireOrganizationMatch: i = !1,
995
1001
  managementApiExtensions: o = [],
996
1002
  entityHooks: a,
997
- getChildTenantIds: m,
1003
+ getChildTenantIds: u,
998
1004
  getAdapters: d,
999
1005
  ...c
1000
- } = n, p = s !== !1, l = p ? {
1006
+ } = t, f = s !== !1, l = f ? {
1001
1007
  resourceServers: s.resourceServers ?? !0,
1002
1008
  roles: s.roles ?? !0,
1003
1009
  connections: s.connections ?? !0
1004
1010
  } : { resourceServers: !1, roles: !1, connections: !1 }, g = {
1005
- controlPlaneTenantId: t,
1006
- getChildTenantIds: m ?? (async () => (await $(
1011
+ controlPlaneTenantId: n,
1012
+ getChildTenantIds: u ?? (async () => (await z(
1007
1013
  (_) => e.tenants.list(_),
1008
1014
  "tenants",
1009
1015
  { cursorField: "id", pageSize: 100 }
1010
- )).filter((_) => _.id !== t).map((_) => _.id)),
1016
+ )).filter((_) => _.id !== n).map((_) => _.id)),
1011
1017
  getAdapters: d ?? (async () => e),
1012
1018
  getControlPlaneAdapters: async () => e,
1013
1019
  sync: l
1014
- }, { entityHooks: f, tenantHooks: h } = de(g), y = {
1020
+ }, { entityHooks: p, tenantHooks: h } = de(g), y = {
1015
1021
  resourceServers: [
1016
- f.resourceServers,
1022
+ p.resourceServers,
1017
1023
  ...(a == null ? void 0 : a.resourceServers) ?? []
1018
1024
  ],
1019
- roles: [f.roles, ...(a == null ? void 0 : a.roles) ?? []],
1025
+ roles: [p.roles, ...(a == null ? void 0 : a.roles) ?? []],
1020
1026
  connections: [
1021
- f.connections,
1027
+ p.connections,
1022
1028
  ...(a == null ? void 0 : a.connections) ?? []
1023
1029
  ],
1024
1030
  tenants: (a == null ? void 0 : a.tenants) ?? [],
@@ -1026,13 +1032,13 @@ function Pe(n) {
1026
1032
  }, v = k(
1027
1033
  {
1028
1034
  accessControl: {
1029
- controlPlaneTenantId: t,
1035
+ controlPlaneTenantId: n,
1030
1036
  requireOrganizationMatch: i,
1031
1037
  defaultPermissions: r
1032
1038
  }
1033
1039
  },
1034
1040
  { tenants: h }
1035
- ), { app: b } = Z({
1041
+ ), { app: b } = Y({
1036
1042
  dataAdapter: e,
1037
1043
  ...c,
1038
1044
  entityHooks: y,
@@ -1041,72 +1047,72 @@ function Pe(n) {
1041
1047
  { path: "/tenants", router: v }
1042
1048
  ]
1043
1049
  });
1044
- return p && b.use("/api/v2/*", fe()), { app: b, controlPlaneTenantId: t };
1050
+ return f && b.use("/api/v2/*", pe()), { app: b, controlPlaneTenantId: n };
1045
1051
  }
1046
- function ze(n) {
1047
- const e = j(n);
1052
+ function $e(t) {
1053
+ const e = j(t);
1048
1054
  return {
1049
1055
  name: "multi-tenancy",
1050
1056
  // Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
1051
- middleware: B(n),
1057
+ middleware: K(t),
1052
1058
  // Provide lifecycle hooks
1053
1059
  hooks: e,
1054
1060
  // Mount tenant management routes
1055
1061
  routes: [
1056
1062
  {
1057
1063
  path: "/management",
1058
- handler: k(n, e)
1064
+ handler: k(t, e)
1059
1065
  }
1060
1066
  ],
1061
1067
  // Called when plugin is registered
1062
1068
  onRegister: async () => {
1063
- console.log("Multi-tenancy plugin registered"), n.accessControl && console.log(
1064
- ` - Access control enabled (control plane: ${n.accessControl.controlPlaneTenantId})`
1065
- ), n.subdomainRouting && console.log(
1066
- ` - Subdomain routing enabled (base domain: ${n.subdomainRouting.baseDomain})`
1067
- ), n.databaseIsolation && console.log(" - Database isolation enabled");
1069
+ console.log("Multi-tenancy plugin registered"), t.accessControl && console.log(
1070
+ ` - Access control enabled (control plane: ${t.accessControl.controlPlaneTenantId})`
1071
+ ), t.subdomainRouting && console.log(
1072
+ ` - Subdomain routing enabled (base domain: ${t.subdomainRouting.baseDomain})`
1073
+ ), t.databaseIsolation && console.log(" - Database isolation enabled");
1068
1074
  }
1069
1075
  };
1070
1076
  }
1071
- function j(n) {
1072
- const e = n.accessControl ? ne(n.accessControl) : {}, t = n.databaseIsolation ? re(n.databaseIsolation) : {}, s = ae(n);
1077
+ function j(t) {
1078
+ const e = t.accessControl ? te(t.accessControl) : {}, n = t.databaseIsolation ? se(t.databaseIsolation) : {}, s = re(t);
1073
1079
  return {
1074
1080
  ...e,
1075
- ...t,
1081
+ ...n,
1076
1082
  tenants: s
1077
1083
  };
1078
1084
  }
1079
- function _e(n) {
1080
- const e = new Q(), t = j(n);
1081
- return e.route("/tenants", k(n, t)), e;
1085
+ function _e(t) {
1086
+ const e = new J(), n = j(t);
1087
+ return e.route("/tenants", k(t, n)), e;
1082
1088
  }
1083
- function $e(n) {
1089
+ function ze(t) {
1084
1090
  return {
1085
- hooks: j(n),
1086
- middleware: B(n),
1087
- app: _e(n),
1088
- config: n
1091
+ hooks: j(t),
1092
+ middleware: K(t),
1093
+ app: _e(t),
1094
+ config: t
1089
1095
  };
1090
1096
  }
1091
1097
  export {
1092
- ne as createAccessControlHooks,
1098
+ te as createAccessControlHooks,
1093
1099
  we as createAccessControlMiddleware,
1094
- re as createDatabaseHooks,
1100
+ se as createDatabaseHooks,
1095
1101
  ye as createDatabaseMiddleware,
1096
1102
  _e as createMultiTenancy,
1097
1103
  j as createMultiTenancyHooks,
1098
- B as createMultiTenancyMiddleware,
1099
- ze as createMultiTenancyPlugin,
1100
- fe as createProtectSyncedMiddleware,
1101
- ae as createProvisioningHooks,
1102
- L as createRuntimeFallbackAdapter,
1104
+ K as createMultiTenancyMiddleware,
1105
+ $e as createMultiTenancyPlugin,
1106
+ pe as createProtectSyncedMiddleware,
1107
+ re as createProvisioningHooks,
1108
+ B as createRuntimeFallbackAdapter,
1103
1109
  Ie as createSettingsInheritanceAdapter,
1104
1110
  he as createSubdomainMiddleware,
1105
1111
  de as createSyncHooks,
1106
1112
  k as createTenantsOpenAPIRouter,
1107
1113
  Pe as initMultiTenant,
1108
- $e as setupMultiTenancy,
1109
- se as validateTenantAccess,
1114
+ ze as setupMultiTenancy,
1115
+ ne as validateTenantAccess,
1110
1116
  ge as withRuntimeFallback,
1111
1117
  Se as withSettingsInheritance
1112
1118
  };