@authhero/multi-tenancy 14.15.0 → 14.16.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,30 +1,30 @@
1
- var Z = Object.defineProperty;
2
- var x = (e, t, n) => t in e ? Z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var q = (e, t, n) => x(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { Hono as ee } from "hono";
5
- import { MANAGEMENT_API_SCOPES as te, MANAGEMENT_API_AUDIENCE as V, fetchAll as M, auth0QuerySchema as ne, tenantSchema as B, tenantInsertSchema as re, connectionSchema as ae, connectionOptionsSchema as se, init as oe } from "authhero";
6
- import { OpenAPIHono as ie, createRoute as j, z } from "@hono/zod-openapi";
7
- function ce(e) {
1
+ var x = Object.defineProperty;
2
+ var ee = (e, t, n) => t in e ? x(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var E = (e, t, n) => ee(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { Hono as te } from "hono";
5
+ import { MANAGEMENT_API_SCOPES as ne, MANAGEMENT_API_AUDIENCE as J, fetchAll as D, auth0QuerySchema as re, tenantSchema as q, tenantInsertSchema as U, deepMergePatch as ae, connectionSchema as se, connectionOptionsSchema as oe, init as ie } from "authhero";
6
+ import { OpenAPIHono as ce, createRoute as M, z as S } from "@hono/zod-openapi";
7
+ function le(e) {
8
8
  const { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
9
9
  return {
10
10
  async onTenantAccessValidation(r, a) {
11
11
  if (a === t)
12
12
  return !0;
13
13
  if (n) {
14
- const s = r.var.org_name, o = r.var.organization_id, i = s || o;
14
+ const o = r.var.org_name, s = r.var.organization_id, i = o || s;
15
15
  return i ? i.toLowerCase() === a.toLowerCase() : !1;
16
16
  }
17
17
  return !0;
18
18
  }
19
19
  };
20
20
  }
21
- function le(e, t, n, r) {
21
+ function ue(e, t, n, r) {
22
22
  if (t === n)
23
23
  return !0;
24
24
  const a = r || e;
25
25
  return a ? a.toLowerCase() === t.toLowerCase() : !1;
26
26
  }
27
- function ue(e) {
27
+ function de(e) {
28
28
  return {
29
29
  async resolveDataAdapters(t) {
30
30
  try {
@@ -39,56 +39,56 @@ function ue(e) {
39
39
  }
40
40
  };
41
41
  }
42
- function de(e) {
42
+ function fe(e) {
43
43
  return `urn:authhero:tenant:${e.toLowerCase()}`;
44
44
  }
45
- function J(e) {
45
+ function X(e) {
46
46
  return {
47
47
  async beforeCreate(t, n) {
48
48
  return !n.audience && n.id ? {
49
49
  ...n,
50
- audience: de(n.id)
50
+ audience: fe(n.id)
51
51
  } : n;
52
52
  },
53
53
  async afterCreate(t, n) {
54
54
  const { accessControl: r, databaseIsolation: a } = e;
55
- r && t.ctx && await fe(t, n, r), a != null && a.onProvision && await a.onProvision(n.id);
55
+ r && t.ctx && await me(t, n, r), a != null && a.onProvision && await a.onProvision(n.id);
56
56
  },
57
57
  async beforeDelete(t, n) {
58
58
  const { accessControl: r, databaseIsolation: a } = e;
59
59
  if (r)
60
60
  try {
61
- const o = (await t.adapters.organizations.list(
61
+ const s = (await t.adapters.organizations.list(
62
62
  r.controlPlaneTenantId
63
63
  )).organizations.find((i) => i.name === n);
64
- o && await t.adapters.organizations.remove(
64
+ s && await t.adapters.organizations.remove(
65
65
  r.controlPlaneTenantId,
66
- o.id
66
+ s.id
67
67
  );
68
- } catch (s) {
68
+ } catch (o) {
69
69
  console.warn(
70
70
  `Failed to remove organization for tenant ${n}:`,
71
- s
71
+ o
72
72
  );
73
73
  }
74
74
  if (a != null && a.onDeprovision)
75
75
  try {
76
76
  await a.onDeprovision(n);
77
- } catch (s) {
77
+ } catch (o) {
78
78
  console.warn(
79
79
  `Failed to deprovision database for tenant ${n}:`,
80
- s
80
+ o
81
81
  );
82
82
  }
83
83
  }
84
84
  };
85
85
  }
86
- async function fe(e, t, n) {
86
+ async function me(e, t, n) {
87
87
  const {
88
88
  controlPlaneTenantId: r,
89
89
  defaultPermissions: a,
90
- defaultRoles: s,
91
- issuer: o,
90
+ defaultRoles: o,
91
+ issuer: s,
92
92
  adminRoleName: i = "Tenant Admin",
93
93
  adminRoleDescription: u = "Full access to all tenant management operations",
94
94
  addCreatorToOrganization: c = !0
@@ -100,14 +100,14 @@ async function fe(e, t, n) {
100
100
  }
101
101
  );
102
102
  let g;
103
- if (o && (g = await ge(
103
+ if (s && (g = await we(
104
104
  e,
105
105
  r,
106
106
  i,
107
107
  u
108
108
  )), c && e.ctx) {
109
109
  const d = e.ctx.var.user;
110
- if (d != null && d.sub && !await me(
110
+ if (d != null && d.sub && !await ge(
111
111
  e,
112
112
  r,
113
113
  d.sub
@@ -130,13 +130,13 @@ async function fe(e, t, n) {
130
130
  );
131
131
  }
132
132
  }
133
- s && s.length > 0 && console.log(
134
- `Would assign roles ${s.join(", ")} to organization ${l.id}`
133
+ o && o.length > 0 && console.log(
134
+ `Would assign roles ${o.join(", ")} to organization ${l.id}`
135
135
  ), a && a.length > 0 && console.log(
136
136
  `Would grant permissions ${a.join(", ")} to organization ${l.id}`
137
137
  );
138
138
  }
139
- async function me(e, t, n) {
139
+ async function ge(e, t, n) {
140
140
  const r = await e.adapters.userRoles.list(
141
141
  t,
142
142
  n,
@@ -155,26 +155,26 @@ async function me(e, t, n) {
155
155
  return !0;
156
156
  return !1;
157
157
  }
158
- async function ge(e, t, n, r) {
159
- const s = (await e.adapters.roles.list(t, {})).roles.find((c) => c.name === n);
160
- if (s)
161
- return s.id;
162
- const o = await e.adapters.roles.create(t, {
158
+ async function we(e, t, n, r) {
159
+ const o = (await e.adapters.roles.list(t, {})).roles.find((c) => c.name === n);
160
+ if (o)
161
+ return o.id;
162
+ const s = await e.adapters.roles.create(t, {
163
163
  name: n,
164
164
  description: r
165
- }), i = V, u = te.map((c) => ({
166
- role_id: o.id,
165
+ }), i = J, u = ne.map((c) => ({
166
+ role_id: s.id,
167
167
  resource_server_identifier: i,
168
168
  permission_name: c.value
169
169
  }));
170
170
  return await e.adapters.rolePermissions.assign(
171
171
  t,
172
- o.id,
172
+ s.id,
173
173
  u
174
- ), o.id;
174
+ ), s.id;
175
175
  }
176
176
  function G(e, t, n = () => !0) {
177
- const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e, o = /* @__PURE__ */ new Map();
177
+ const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: o } = e, s = /* @__PURE__ */ new Map();
178
178
  async function i(l, g, d) {
179
179
  return (await t(l).list(g, {
180
180
  q: `name:${d}`,
@@ -182,19 +182,19 @@ function G(e, t, n = () => !0) {
182
182
  }))[0] ?? null;
183
183
  }
184
184
  async function u(l) {
185
- const g = await a(), d = t(await s(r));
185
+ const g = await a(), d = t(await o(r));
186
186
  await Promise.all(
187
187
  g.map(async (f) => {
188
188
  try {
189
- const m = await s(f), w = t(m), h = {
189
+ const m = await o(f), w = t(m), y = {
190
190
  ...d.transform(l),
191
191
  is_system: !0
192
- }, _ = await i(m, f, l.name), P = _ ? w.getId(_) : void 0;
193
- if (_ && P) {
194
- const b = w.preserveOnUpdate ? w.preserveOnUpdate(_, h) : h;
195
- await w.update(f, P, b);
192
+ }, _ = await i(m, f, l.name), b = _ ? w.getId(_) : void 0;
193
+ if (_ && b) {
194
+ const P = w.preserveOnUpdate ? w.preserveOnUpdate(_, y) : y;
195
+ await w.update(f, b, P);
196
196
  } else
197
- await w.create(f, h);
197
+ await w.create(f, y);
198
198
  } catch (m) {
199
199
  console.error(
200
200
  `Failed to sync ${d.listKey} "${l.name}" to tenant "${f}":`,
@@ -209,7 +209,7 @@ function G(e, t, n = () => !0) {
209
209
  await Promise.all(
210
210
  g.map(async (d) => {
211
211
  try {
212
- const f = await s(d), m = t(f), w = await i(f, d, l), C = w ? m.getId(w) : void 0;
212
+ const f = await o(d), m = t(f), w = await i(f, d, l), C = w ? m.getId(w) : void 0;
213
213
  w && C && await m.remove(d, C);
214
214
  } catch (f) {
215
215
  console.error(
@@ -230,22 +230,22 @@ function G(e, t, n = () => !0) {
230
230
  beforeDelete: async (l, g) => {
231
231
  if (l.tenantId !== r) return;
232
232
  const f = await t(l.adapters).get(l.tenantId, g);
233
- f && n(f) && o.set(g, f);
233
+ f && n(f) && s.set(g, f);
234
234
  },
235
235
  afterDelete: async (l, g) => {
236
236
  if (l.tenantId !== r) return;
237
- const d = o.get(g);
238
- d && (o.delete(g), await c(d.name));
237
+ const d = s.get(g);
238
+ d && (s.delete(g), await c(d.name));
239
239
  }
240
240
  };
241
241
  }
242
- function U(e, t, n = () => !0) {
243
- const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: s } = e;
242
+ function L(e, t, n = () => !0) {
243
+ const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: o } = e;
244
244
  return {
245
- async afterCreate(o, i) {
245
+ async afterCreate(s, i) {
246
246
  if (i.id !== r)
247
247
  try {
248
- const u = await a(), c = await s(i.id), l = t(u), g = t(c), d = await M(
248
+ const u = await a(), c = await o(i.id), l = t(u), g = t(c), d = await D(
249
249
  (f) => l.listPaginated(r, f),
250
250
  l.listKey,
251
251
  { cursorField: "id", pageSize: 100 }
@@ -275,7 +275,7 @@ function U(e, t, n = () => !0) {
275
275
  }
276
276
  };
277
277
  }
278
- const L = (e) => ({
278
+ const H = (e) => ({
279
279
  list: async (t, n) => (await e.resourceServers.list(t, n)).resource_servers,
280
280
  listPaginated: (t, n) => e.resourceServers.list(t, n),
281
281
  get: (t, n) => e.resourceServers.get(t, n),
@@ -293,7 +293,7 @@ const L = (e) => ({
293
293
  token_lifetime: t.token_lifetime,
294
294
  token_lifetime_for_web: t.token_lifetime_for_web
295
295
  })
296
- }), H = (e) => ({
296
+ }), W = (e) => ({
297
297
  list: async (t, n) => (await e.roles.list(t, n)).roles,
298
298
  listPaginated: (t, n) => e.roles.list(t, n),
299
299
  get: (t, n) => e.roles.get(t, n),
@@ -308,41 +308,41 @@ const L = (e) => ({
308
308
  description: t.description
309
309
  })
310
310
  });
311
- function W(e) {
311
+ function K(e) {
312
312
  var t;
313
313
  return ((t = e.metadata) == null ? void 0 : t.sync) !== !1;
314
314
  }
315
- function we(e) {
316
- const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, a = t.roles ?? !0, s = (m) => W(m) ? n.resourceServers ? n.resourceServers(m) : !0 : !1, o = (m) => W(m) ? n.roles ? n.roles(m) : !0 : !1, i = r ? G(
317
- e,
318
- L,
319
- s
320
- ) : void 0, u = a ? G(e, H, o) : void 0, c = r ? U(
315
+ function pe(e) {
316
+ const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, a = t.roles ?? !0, o = (m) => K(m) ? n.resourceServers ? n.resourceServers(m) : !0 : !1, s = (m) => K(m) ? n.roles ? n.roles(m) : !0 : !1, i = r ? G(
321
317
  e,
322
- L,
323
- s
324
- ) : void 0, l = a ? U(
318
+ H,
319
+ o
320
+ ) : void 0, u = a ? G(e, W, s) : void 0, c = r ? L(
325
321
  e,
326
322
  H,
327
323
  o
324
+ ) : void 0, l = a ? L(
325
+ e,
326
+ W,
327
+ s
328
328
  ) : void 0, g = a ? {
329
329
  async afterCreate(m, w) {
330
330
  var C;
331
331
  if (w.id !== e.controlPlaneTenantId) {
332
332
  await ((C = l == null ? void 0 : l.afterCreate) == null ? void 0 : C.call(l, m, w));
333
333
  try {
334
- const h = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), P = await M(
335
- (p) => h.roles.list(
334
+ const y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), b = await D(
335
+ (p) => y.roles.list(
336
336
  e.controlPlaneTenantId,
337
337
  p
338
338
  ),
339
339
  "roles",
340
340
  { cursorField: "id", pageSize: 100 }
341
- ), b = /* @__PURE__ */ new Map();
342
- for (const p of P.filter(
341
+ ), P = /* @__PURE__ */ new Map();
342
+ for (const p of b.filter(
343
343
  (T) => {
344
- var y;
345
- return ((y = n.roles) == null ? void 0 : y.call(n, T)) ?? !0;
344
+ var h;
345
+ return ((h = n.roles) == null ? void 0 : h.call(n, T)) ?? !0;
346
346
  }
347
347
  )) {
348
348
  const T = await d(
@@ -350,42 +350,42 @@ function we(e) {
350
350
  w.id,
351
351
  p.name
352
352
  );
353
- T && b.set(p.name, T.id);
353
+ T && P.set(p.name, T.id);
354
354
  }
355
- for (const p of P.filter(
355
+ for (const p of b.filter(
356
356
  (T) => {
357
- var y;
358
- return ((y = n.roles) == null ? void 0 : y.call(n, T)) ?? !0;
357
+ var h;
358
+ return ((h = n.roles) == null ? void 0 : h.call(n, T)) ?? !0;
359
359
  }
360
360
  )) {
361
- const T = b.get(p.name);
361
+ const T = P.get(p.name);
362
362
  if (T)
363
363
  try {
364
- const y = await h.rolePermissions.list(
364
+ const h = await y.rolePermissions.list(
365
365
  e.controlPlaneTenantId,
366
366
  p.id,
367
367
  {}
368
368
  );
369
- y.length > 0 && await _.rolePermissions.assign(
369
+ h.length > 0 && await _.rolePermissions.assign(
370
370
  w.id,
371
371
  T,
372
- y.map((R) => ({
372
+ h.map(($) => ({
373
373
  role_id: T,
374
- resource_server_identifier: R.resource_server_identifier,
375
- permission_name: R.permission_name
374
+ resource_server_identifier: $.resource_server_identifier,
375
+ permission_name: $.permission_name
376
376
  }))
377
377
  );
378
- } catch (y) {
378
+ } catch (h) {
379
379
  console.error(
380
380
  `Failed to sync permissions for role "${p.name}" to tenant "${w.id}":`,
381
- y
381
+ h
382
382
  );
383
383
  }
384
384
  }
385
- } catch (h) {
385
+ } catch (y) {
386
386
  console.error(
387
387
  `Failed to sync role permissions to tenant "${w.id}":`,
388
- h
388
+ y
389
389
  );
390
390
  }
391
391
  }
@@ -407,25 +407,25 @@ function we(e) {
407
407
  const C = [
408
408
  c == null ? void 0 : c.afterCreate,
409
409
  (g == null ? void 0 : g.afterCreate) ?? (l == null ? void 0 : l.afterCreate)
410
- ], h = [];
410
+ ], y = [];
411
411
  for (const _ of C)
412
412
  if (_)
413
413
  try {
414
414
  await _(m, w);
415
- } catch (P) {
416
- h.push(P instanceof Error ? P : new Error(String(P)));
415
+ } catch (b) {
416
+ y.push(b instanceof Error ? b : new Error(String(b)));
417
417
  }
418
- if (h.length === 1) throw h[0];
419
- if (h.length > 1)
418
+ if (y.length === 1) throw y[0];
419
+ if (y.length > 1)
420
420
  throw new AggregateError(
421
- h,
422
- h.map((_) => _.message).join("; ")
421
+ y,
422
+ y.map((_) => _.message).join("; ")
423
423
  );
424
424
  }
425
425
  }
426
426
  };
427
427
  }
428
- var S = class extends Error {
428
+ var A = class extends Error {
429
429
  /**
430
430
  * Creates an instance of `HTTPException`.
431
431
  * @param status - HTTP status code for the exception. Defaults to 500.
@@ -433,8 +433,8 @@ var S = class extends Error {
433
433
  */
434
434
  constructor(t = 500, n) {
435
435
  super(n == null ? void 0 : n.message, { cause: n == null ? void 0 : n.cause });
436
- q(this, "res");
437
- q(this, "status");
436
+ E(this, "res");
437
+ E(this, "status");
438
438
  this.res = n == null ? void 0 : n.res, this.status = t;
439
439
  }
440
440
  /**
@@ -451,15 +451,15 @@ var S = class extends Error {
451
451
  });
452
452
  }
453
453
  };
454
- function k(e, t) {
455
- const n = new ie();
454
+ function N(e, t) {
455
+ const n = new ce();
456
456
  return n.openapi(
457
- j({
457
+ M({
458
458
  tags: ["tenants"],
459
459
  method: "get",
460
460
  path: "/",
461
461
  request: {
462
- query: ne
462
+ query: re
463
463
  },
464
464
  security: [
465
465
  {
@@ -470,11 +470,11 @@ function k(e, t) {
470
470
  200: {
471
471
  content: {
472
472
  "application/json": {
473
- schema: z.object({
474
- tenants: z.array(B),
475
- start: z.number().optional(),
476
- limit: z.number().optional(),
477
- length: z.number().optional()
473
+ schema: S.object({
474
+ tenants: S.array(q),
475
+ start: S.number().optional(),
476
+ limit: S.number().optional(),
477
+ length: S.number().optional()
478
478
  })
479
479
  }
480
480
  },
@@ -483,75 +483,75 @@ function k(e, t) {
483
483
  }
484
484
  }),
485
485
  async (r) => {
486
- var m, w, C, h, _, P;
487
- const a = r.req.valid("query"), { page: s, per_page: o, include_totals: i, q: u } = a, c = r.var.user, l = (c == null ? void 0 : c.permissions) || [];
486
+ var m, w, C, y, _, b;
487
+ const a = r.req.valid("query"), { page: o, per_page: s, include_totals: i, q: u } = a, c = r.var.user, l = (c == null ? void 0 : c.permissions) || [];
488
488
  if (l.includes("auth:read") || l.includes("admin:organizations")) {
489
- const b = await r.env.data.tenants.list({
490
- page: s,
491
- per_page: o,
489
+ const P = await r.env.data.tenants.list({
490
+ page: o,
491
+ per_page: s,
492
492
  include_totals: i,
493
493
  q: u
494
494
  });
495
495
  return i ? r.json({
496
- tenants: b.tenants,
497
- start: ((m = b.totals) == null ? void 0 : m.start) ?? 0,
498
- limit: ((w = b.totals) == null ? void 0 : w.limit) ?? o,
499
- length: b.tenants.length
500
- }) : r.json({ tenants: b.tenants });
496
+ tenants: P.tenants,
497
+ start: ((m = P.totals) == null ? void 0 : m.start) ?? 0,
498
+ limit: ((w = P.totals) == null ? void 0 : w.limit) ?? s,
499
+ length: P.tenants.length
500
+ }) : r.json({ tenants: P.tenants });
501
501
  }
502
- const d = ((C = e.accessControl) == null ? void 0 : C.controlPlaneTenantId) ?? ((h = r.env.data.multiTenancyConfig) == null ? void 0 : h.controlPlaneTenantId);
502
+ const d = ((C = e.accessControl) == null ? void 0 : C.controlPlaneTenantId) ?? ((y = r.env.data.multiTenancyConfig) == null ? void 0 : y.controlPlaneTenantId);
503
503
  if (d && (c != null && c.sub)) {
504
- const p = (await M(
505
- (I) => r.env.data.userOrganizations.listUserOrganizations(
504
+ const p = (await D(
505
+ (R) => r.env.data.userOrganizations.listUserOrganizations(
506
506
  d,
507
507
  c.sub,
508
- I
508
+ R
509
509
  ),
510
510
  "organizations"
511
- )).map((I) => I.name);
511
+ )).map((R) => R.name);
512
512
  if (p.length === 0)
513
513
  return i ? r.json({
514
514
  tenants: [],
515
515
  start: 0,
516
- limit: o ?? 50,
516
+ limit: s ?? 50,
517
517
  length: 0
518
518
  }) : r.json({ tenants: [] });
519
- const T = p.length, y = s ?? 0, R = o ?? 50, F = y * R, D = p.slice(F, F + R);
520
- if (D.length === 0)
519
+ const T = p.length, h = o ?? 0, $ = s ?? 50, F = h * $, j = p.slice(F, F + $);
520
+ if (j.length === 0)
521
521
  return i ? r.json({
522
522
  tenants: [],
523
523
  start: F,
524
- limit: R,
524
+ limit: $,
525
525
  length: T
526
526
  }) : r.json({ tenants: [] });
527
- const A = D.map((I) => `id:${I}`).join(" OR "), v = u ? `(${A}) AND (${u})` : A, $ = await r.env.data.tenants.list({
527
+ const I = j.map((R) => `id:${R}`).join(" OR "), v = u ? `(${I}) AND (${u})` : I, z = await r.env.data.tenants.list({
528
528
  q: v,
529
- per_page: R,
529
+ per_page: $,
530
530
  include_totals: !1
531
531
  // We calculate totals from accessibleTenantIds
532
532
  });
533
533
  return i ? r.json({
534
- tenants: $.tenants,
534
+ tenants: z.tenants,
535
535
  start: F,
536
- limit: R,
536
+ limit: $,
537
537
  length: T
538
- }) : r.json({ tenants: $.tenants });
538
+ }) : r.json({ tenants: z.tenants });
539
539
  }
540
540
  const f = await r.env.data.tenants.list({
541
- page: s,
542
- per_page: o,
541
+ page: o,
542
+ per_page: s,
543
543
  include_totals: i,
544
544
  q: u
545
545
  });
546
546
  return i ? r.json({
547
547
  tenants: f.tenants,
548
548
  start: ((_ = f.totals) == null ? void 0 : _.start) ?? 0,
549
- limit: ((P = f.totals) == null ? void 0 : P.limit) ?? o,
549
+ limit: ((b = f.totals) == null ? void 0 : b.limit) ?? s,
550
550
  length: f.tenants.length
551
551
  }) : r.json({ tenants: f.tenants });
552
552
  }
553
553
  ), n.openapi(
554
- j({
554
+ M({
555
555
  tags: ["tenants"],
556
556
  method: "post",
557
557
  path: "/",
@@ -559,7 +559,7 @@ function k(e, t) {
559
559
  body: {
560
560
  content: {
561
561
  "application/json": {
562
- schema: re
562
+ schema: U
563
563
  }
564
564
  }
565
565
  }
@@ -573,7 +573,7 @@ function k(e, t) {
573
573
  201: {
574
574
  content: {
575
575
  "application/json": {
576
- schema: B
576
+ schema: q
577
577
  }
578
578
  },
579
579
  description: "Tenant created"
@@ -590,26 +590,26 @@ function k(e, t) {
590
590
  var u, c;
591
591
  const a = r.var.user;
592
592
  if (!(a != null && a.sub))
593
- throw new S(401, {
593
+ throw new A(401, {
594
594
  message: "Authentication required to create tenants"
595
595
  });
596
- let s = r.req.valid("json");
597
- const o = {
596
+ let o = r.req.valid("json");
597
+ const s = {
598
598
  adapters: r.env.data,
599
599
  ctx: r
600
600
  };
601
- (u = t.tenants) != null && u.beforeCreate && (s = await t.tenants.beforeCreate(o, s));
602
- const i = await r.env.data.tenants.create(s);
603
- return (c = t.tenants) != null && c.afterCreate && await t.tenants.afterCreate(o, i), r.json(i, 201);
601
+ (u = t.tenants) != null && u.beforeCreate && (o = await t.tenants.beforeCreate(s, o));
602
+ const i = await r.env.data.tenants.create(o);
603
+ return (c = t.tenants) != null && c.afterCreate && await t.tenants.afterCreate(s, i), r.json(i, 201);
604
604
  }
605
605
  ), n.openapi(
606
- j({
606
+ M({
607
607
  tags: ["tenants"],
608
608
  method: "delete",
609
609
  path: "/{id}",
610
610
  request: {
611
- params: z.object({
612
- id: z.string()
611
+ params: S.object({
612
+ id: S.string()
613
613
  })
614
614
  },
615
615
  security: [
@@ -631,31 +631,31 @@ function k(e, t) {
631
631
  }),
632
632
  async (r) => {
633
633
  var u, c, l, g;
634
- const { id: a } = r.req.valid("param"), s = ((u = e.accessControl) == null ? void 0 : u.controlPlaneTenantId) ?? ((c = r.env.data.multiTenancyConfig) == null ? void 0 : c.controlPlaneTenantId);
635
- if (s) {
634
+ const { id: a } = r.req.valid("param"), o = ((u = e.accessControl) == null ? void 0 : u.controlPlaneTenantId) ?? ((c = r.env.data.multiTenancyConfig) == null ? void 0 : c.controlPlaneTenantId);
635
+ if (o) {
636
636
  const d = r.var.user;
637
637
  if (!(d != null && d.sub))
638
- throw new S(401, {
638
+ throw new A(401, {
639
639
  message: "Authentication required"
640
640
  });
641
- if (a === s)
642
- throw new S(403, {
641
+ if (a === o)
642
+ throw new A(403, {
643
643
  message: "Cannot delete the control plane"
644
644
  });
645
- if (!(await M(
645
+ if (!(await D(
646
646
  (w) => r.env.data.userOrganizations.listUserOrganizations(
647
- s,
647
+ o,
648
648
  d.sub,
649
649
  w
650
650
  ),
651
651
  "organizations"
652
652
  )).some((w) => w.name === a))
653
- throw new S(403, {
653
+ throw new A(403, {
654
654
  message: "Access denied to this tenant"
655
655
  });
656
656
  }
657
657
  if (!await r.env.data.tenants.get(a))
658
- throw new S(404, {
658
+ throw new A(404, {
659
659
  message: "Tenant not found"
660
660
  });
661
661
  const i = {
@@ -664,9 +664,91 @@ function k(e, t) {
664
664
  };
665
665
  return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(i, a), await r.env.data.tenants.remove(a), (g = t.tenants) != null && g.afterDelete && await t.tenants.afterDelete(i, a), r.body(null, 204);
666
666
  }
667
+ ), n.openapi(
668
+ M({
669
+ tags: ["tenants", "settings"],
670
+ method: "get",
671
+ path: "/settings",
672
+ request: {
673
+ headers: S.object({
674
+ "tenant-id": S.string().optional()
675
+ })
676
+ },
677
+ security: [
678
+ {
679
+ Bearer: ["read:tenants", "auth:read"]
680
+ }
681
+ ],
682
+ responses: {
683
+ 200: {
684
+ content: {
685
+ "application/json": {
686
+ schema: q
687
+ }
688
+ },
689
+ description: "Current tenant settings"
690
+ }
691
+ }
692
+ }),
693
+ async (r) => {
694
+ const a = await r.env.data.tenants.get(r.var.tenant_id);
695
+ if (!a)
696
+ throw new A(404, {
697
+ message: "Tenant not found"
698
+ });
699
+ return r.json(a);
700
+ }
701
+ ), n.openapi(
702
+ M({
703
+ tags: ["tenants", "settings"],
704
+ method: "patch",
705
+ path: "/settings",
706
+ request: {
707
+ headers: S.object({
708
+ "tenant-id": S.string().optional()
709
+ }),
710
+ body: {
711
+ content: {
712
+ "application/json": {
713
+ schema: S.object(U.shape).partial()
714
+ }
715
+ }
716
+ }
717
+ },
718
+ security: [
719
+ {
720
+ Bearer: ["update:tenants", "auth:write"]
721
+ }
722
+ ],
723
+ responses: {
724
+ 200: {
725
+ content: {
726
+ "application/json": {
727
+ schema: q
728
+ }
729
+ },
730
+ description: "Updated tenant settings"
731
+ }
732
+ }
733
+ }),
734
+ async (r) => {
735
+ const a = r.req.valid("json"), { id: o, ...s } = a, i = await r.env.data.tenants.get(r.var.tenant_id);
736
+ if (!i)
737
+ throw new A(404, {
738
+ message: "Tenant not found"
739
+ });
740
+ const u = ae(i, s);
741
+ await r.env.data.tenants.update(r.var.tenant_id, u);
742
+ const c = await r.env.data.tenants.get(r.var.tenant_id);
743
+ if (!c)
744
+ throw new A(500, {
745
+ message: "Failed to retrieve updated tenant"
746
+ });
747
+ return r.json(c);
748
+ }
667
749
  ), n;
668
750
  }
669
- function pe(e) {
751
+ function he(e) {
670
752
  const t = [
671
753
  {
672
754
  pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
@@ -704,41 +786,41 @@ async function ye(e, t, n) {
704
786
  return !1;
705
787
  }
706
788
  }
707
- function he(e) {
789
+ function ve(e) {
708
790
  return {
709
791
  resource_server: "resource server",
710
792
  role: "role",
711
793
  connection: "connection"
712
794
  }[e];
713
795
  }
714
- function ve() {
796
+ function _e() {
715
797
  return async (e, t) => {
716
798
  if (!["PATCH", "PUT", "DELETE"].includes(e.req.method))
717
799
  return t();
718
- const n = pe(e.req.path);
800
+ const n = he(e.req.path);
719
801
  if (!n)
720
802
  return t();
721
803
  const r = e.var.tenant_id || e.req.header("x-tenant-id") || e.req.header("tenant-id");
722
804
  if (!r)
723
805
  return t();
724
806
  if (await ye(e.env.data, r, n))
725
- throw new S(403, {
726
- message: `This ${he(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
807
+ throw new A(403, {
808
+ message: `This ${ve(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
727
809
  });
728
810
  return t();
729
811
  };
730
812
  }
731
- function E(e, t) {
813
+ function k(e, t) {
732
814
  const n = t.find(
733
815
  (a) => a.strategy === e.strategy
734
816
  );
735
817
  if (!(n != null && n.options))
736
818
  return e;
737
- const r = ae.passthrough().parse({
819
+ const r = se.passthrough().parse({
738
820
  ...n,
739
821
  ...e
740
822
  });
741
- return r.options = se.passthrough().parse({
823
+ return r.options = oe.passthrough().parse({
742
824
  ...n.options || {},
743
825
  ...e.options
744
826
  }), r;
@@ -747,7 +829,7 @@ function O(e, t) {
747
829
  const n = [...t || [], ...e || []];
748
830
  return [...new Set(n)];
749
831
  }
750
- function _e(e, t) {
832
+ function Ce(e, t) {
751
833
  if (!(t != null && t.length))
752
834
  return e || [];
753
835
  if (!(e != null && e.length))
@@ -759,16 +841,16 @@ function _e(e, t) {
759
841
  n.set(r.value, r);
760
842
  return Array.from(n.values());
761
843
  }
762
- function K(e, t) {
844
+ function Q(e, t) {
763
845
  return t ? {
764
846
  ...e,
765
- scopes: _e(
847
+ scopes: Ce(
766
848
  e.scopes,
767
849
  t.scopes
768
850
  )
769
851
  } : e;
770
852
  }
771
- function Q(e, t) {
853
+ function V(e, t) {
772
854
  return t ? {
773
855
  ...e,
774
856
  callbacks: O(e.callbacks, t.callbacks),
@@ -786,7 +868,7 @@ function Q(e, t) {
786
868
  )
787
869
  } : e;
788
870
  }
789
- function Ce(e, t) {
871
+ function Te(e, t) {
790
872
  const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
791
873
  return {
792
874
  ...e,
@@ -797,47 +879,47 @@ function Ce(e, t) {
797
879
  },
798
880
  connections: {
799
881
  ...e.connections,
800
- get: async (a, s) => {
801
- const o = await e.connections.get(
882
+ get: async (a, o) => {
883
+ const s = await e.connections.get(
802
884
  a,
803
- s
885
+ o
804
886
  );
805
- if (!o || !n || a === n)
806
- return o;
887
+ if (!s || !n || a === n)
888
+ return s;
807
889
  const i = await e.connections.list(n);
808
- return E(
809
- o,
890
+ return k(
891
+ s,
810
892
  i.connections || []
811
893
  );
812
894
  },
813
- list: async (a, s) => {
814
- const o = await e.connections.list(a, s);
895
+ list: async (a, o) => {
896
+ const s = await e.connections.list(a, o);
815
897
  if (!n || a === n)
816
- return o;
817
- const i = await e.connections.list(n), u = o.connections.map(
818
- (c) => E(
898
+ return s;
899
+ const i = await e.connections.list(n), u = s.connections.map(
900
+ (c) => k(
819
901
  c,
820
902
  i.connections || []
821
903
  )
822
904
  );
823
905
  return {
824
- ...o,
906
+ ...s,
825
907
  connections: u
826
908
  };
827
909
  }
828
910
  },
829
911
  clientConnections: {
830
912
  ...e.clientConnections,
831
- listByClient: async (a, s) => {
832
- let o = await e.clientConnections.listByClient(
913
+ listByClient: async (a, o) => {
914
+ let s = await e.clientConnections.listByClient(
833
915
  a,
834
- s
916
+ o
835
917
  );
836
- if (o.length === 0 && (o = (await e.connections.list(a)).connections || []), !n || a === n)
837
- return o;
918
+ if (s.length === 0 && (s = (await e.connections.list(a)).connections || []), !n || a === n)
919
+ return s;
838
920
  const i = await e.connections.list(n);
839
- return o.map(
840
- (u) => E(
921
+ return s.map(
922
+ (u) => k(
841
923
  u,
842
924
  i.connections || []
843
925
  )
@@ -846,76 +928,76 @@ function Ce(e, t) {
846
928
  },
847
929
  clients: {
848
930
  ...e.clients,
849
- get: async (a, s) => {
850
- const o = await e.clients.get(a, s);
851
- if (!o)
931
+ get: async (a, o) => {
932
+ const s = await e.clients.get(a, o);
933
+ if (!s)
852
934
  return null;
853
- if (!n || !r || a === n && s === r)
854
- return o;
935
+ if (!n || !r || a === n && o === r)
936
+ return s;
855
937
  const i = await e.clients.get(
856
938
  n,
857
939
  r
858
940
  );
859
- return Q(o, i);
941
+ return V(s, i);
860
942
  },
861
943
  getByClientId: async (a) => {
862
- const s = await e.clients.getByClientId(a);
863
- if (!s)
944
+ const o = await e.clients.getByClientId(a);
945
+ if (!o)
864
946
  return null;
865
- if (!n || !r || s.tenant_id === n && s.client_id === r)
866
- return s;
867
- const o = await e.clients.get(
947
+ if (!n || !r || o.tenant_id === n && o.client_id === r)
948
+ return o;
949
+ const s = await e.clients.get(
868
950
  n,
869
951
  r
870
952
  );
871
953
  return {
872
- ...Q(s, o),
873
- tenant_id: s.tenant_id
954
+ ...V(o, s),
955
+ tenant_id: o.tenant_id
874
956
  };
875
957
  }
876
958
  },
877
959
  emailProviders: {
878
960
  ...e.emailProviders,
879
961
  get: async (a) => {
880
- const s = await e.emailProviders.get(a);
881
- return s || (!n || a === n ? null : e.emailProviders.get(n));
962
+ const o = await e.emailProviders.get(a);
963
+ return o || (!n || a === n ? null : e.emailProviders.get(n));
882
964
  }
883
965
  },
884
966
  resourceServers: {
885
967
  ...e.resourceServers,
886
- get: async (a, s) => {
887
- const o = await e.resourceServers.get(
968
+ get: async (a, o) => {
969
+ const s = await e.resourceServers.get(
888
970
  a,
889
- s
971
+ o
890
972
  );
891
- if (!o || !n || a === n)
892
- return o;
973
+ if (!s || !n || a === n)
974
+ return s;
893
975
  const u = (await e.resourceServers.list(
894
976
  n,
895
- { q: `identifier:${o.identifier}`, per_page: 1 }
977
+ { q: `identifier:${s.identifier}`, per_page: 1 }
896
978
  )).resource_servers[0] ?? null;
897
- return K(
898
- o,
979
+ return Q(
980
+ s,
899
981
  u
900
982
  );
901
983
  },
902
- list: async (a, s) => {
903
- const o = await e.resourceServers.list(
984
+ list: async (a, o) => {
985
+ const s = await e.resourceServers.list(
904
986
  a,
905
- s
987
+ o
906
988
  );
907
989
  if (!n || a === n)
908
- return o;
990
+ return s;
909
991
  const i = await e.resourceServers.list(n), u = new Map(
910
992
  i.resource_servers.map((l) => [l.identifier, l])
911
- ), c = o.resource_servers.map(
912
- (l) => K(
993
+ ), c = s.resource_servers.map(
994
+ (l) => Q(
913
995
  l,
914
996
  u.get(l.identifier) ?? null
915
997
  )
916
998
  );
917
999
  return {
918
- ...o,
1000
+ ...s,
919
1001
  resource_servers: c
920
1002
  };
921
1003
  }
@@ -925,10 +1007,10 @@ function Ce(e, t) {
925
1007
  // - branding: Fall back to control plane branding/themes
926
1008
  };
927
1009
  }
928
- function X(e, t) {
929
- return Ce(e, t);
1010
+ function Y(e, t) {
1011
+ return Te(e, t);
930
1012
  }
931
- function Te(e) {
1013
+ function be(e) {
932
1014
  return async (t, n) => {
933
1015
  const r = t.var.user;
934
1016
  return (r == null ? void 0 : r.tenant_id) === e && r.org_name && t.set("tenant_id", r.org_name), n();
@@ -938,44 +1020,44 @@ function Pe(e) {
938
1020
  return async (t, n) => {
939
1021
  if (!e.accessControl)
940
1022
  return n();
941
- const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id, o = a || s;
1023
+ const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, o = t.var.organization_id, s = a || o;
942
1024
  let i = t.var.tenant_id;
943
- const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(V);
944
- if (!i && o && l && (t.set("tenant_id", o), i = o), !i)
945
- throw new S(400, {
1025
+ const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(J);
1026
+ if (!i && s && l && (t.set("tenant_id", s), i = s), !i)
1027
+ throw new A(400, {
946
1028
  message: "Tenant ID not found in request"
947
1029
  });
948
- if (!le(
949
- s,
1030
+ if (!ue(
1031
+ o,
950
1032
  i,
951
1033
  r,
952
1034
  a
953
1035
  ))
954
- throw new S(403, {
1036
+ throw new A(403, {
955
1037
  message: `Access denied to tenant ${i}`
956
1038
  });
957
1039
  return n();
958
1040
  };
959
1041
  }
960
- function be(e) {
1042
+ function Ae(e) {
961
1043
  return async (t, n) => {
962
1044
  if (!e.subdomainRouting)
963
1045
  return n();
964
1046
  const {
965
1047
  baseDomain: r,
966
1048
  reservedSubdomains: a = [],
967
- resolveSubdomain: s
968
- } = e.subdomainRouting, o = t.req.header("host") || "";
1049
+ resolveSubdomain: o
1050
+ } = e.subdomainRouting, s = t.req.header("host") || "";
969
1051
  let i = null;
970
- if (o.endsWith(r)) {
971
- const c = o.slice(0, -(r.length + 1));
1052
+ if (s.endsWith(r)) {
1053
+ const c = s.slice(0, -(r.length + 1));
972
1054
  c && !c.includes(".") && (i = c);
973
1055
  }
974
1056
  if (i && a.includes(i) && (i = null), !i)
975
1057
  return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
976
1058
  let u = null;
977
- if (s)
978
- u = await s(i);
1059
+ if (o)
1060
+ u = await o(i);
979
1061
  else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
980
1062
  try {
981
1063
  const c = await t.env.data.organizations.get(
@@ -986,19 +1068,19 @@ function be(e) {
986
1068
  } catch {
987
1069
  }
988
1070
  if (!u)
989
- throw new S(404, {
1071
+ throw new A(404, {
990
1072
  message: `Tenant not found for subdomain: ${i}`
991
1073
  });
992
1074
  return t.set("tenant_id", u), n();
993
1075
  };
994
1076
  }
995
- function Ae(e) {
1077
+ function Ie(e) {
996
1078
  return async (t, n) => {
997
1079
  if (!e.databaseIsolation)
998
1080
  return n();
999
1081
  const r = t.var.tenant_id;
1000
1082
  if (!r)
1001
- throw new S(400, {
1083
+ throw new A(400, {
1002
1084
  message: "Tenant ID not found in request"
1003
1085
  });
1004
1086
  try {
@@ -1008,21 +1090,21 @@ function Ae(e) {
1008
1090
  throw console.error(
1009
1091
  `Failed to resolve database for tenant ${r}:`,
1010
1092
  a
1011
- ), new S(500, {
1093
+ ), new A(500, {
1012
1094
  message: "Failed to resolve tenant database"
1013
1095
  });
1014
1096
  }
1015
1097
  return n();
1016
1098
  };
1017
1099
  }
1018
- function Y(e) {
1019
- const t = be(e), n = Pe(e), r = Ae(e);
1020
- return async (a, s) => (await t(a, async () => {
1100
+ function Z(e) {
1101
+ const t = Ae(e), n = Pe(e), r = Ie(e);
1102
+ return async (a, o) => (await t(a, async () => {
1021
1103
  }), await n(a, async () => {
1022
1104
  }), await r(a, async () => {
1023
- }), s());
1105
+ }), o());
1024
1106
  }
1025
- function Fe(e) {
1107
+ function je(e) {
1026
1108
  const {
1027
1109
  dataAdapter: t,
1028
1110
  controlPlane: n,
@@ -1030,8 +1112,8 @@ function Fe(e) {
1030
1112
  tenantId: r = "control_plane",
1031
1113
  clientId: a
1032
1114
  } = {},
1033
- sync: s = { resourceServers: !0, roles: !0 },
1034
- defaultPermissions: o = ["tenant:admin"],
1115
+ sync: o = { resourceServers: !0, roles: !0 },
1116
+ defaultPermissions: s = ["tenant:admin"],
1035
1117
  requireOrganizationMatch: i = !1,
1036
1118
  managementApiExtensions: u = [],
1037
1119
  entityHooks: c,
@@ -1040,7 +1122,7 @@ function Fe(e) {
1040
1122
  ...d
1041
1123
  } = e;
1042
1124
  let f = t, m = t;
1043
- n && (f = X(t, {
1125
+ n && (f = Y(t, {
1044
1126
  controlPlaneTenantId: r,
1045
1127
  controlPlaneClientId: a
1046
1128
  }), m = {
@@ -1050,12 +1132,12 @@ function Fe(e) {
1050
1132
  controlPlaneClientId: a
1051
1133
  }
1052
1134
  });
1053
- const w = s !== !1, C = w ? {
1054
- resourceServers: s.resourceServers ?? !0,
1055
- roles: s.roles ?? !0
1056
- } : { resourceServers: !1, roles: !1 }, P = {
1135
+ const w = o !== !1, C = w ? {
1136
+ resourceServers: o.resourceServers ?? !0,
1137
+ roles: o.roles ?? !0
1138
+ } : { resourceServers: !1, roles: !1 }, b = {
1057
1139
  controlPlaneTenantId: r,
1058
- getChildTenantIds: l ?? (async () => (await M(
1140
+ getChildTenantIds: l ?? (async () => (await D(
1059
1141
  (v) => f.tenants.list(v),
1060
1142
  "tenants",
1061
1143
  { cursorField: "id", pageSize: 100 }
@@ -1063,43 +1145,43 @@ function Fe(e) {
1063
1145
  getAdapters: g ?? (async () => f),
1064
1146
  getControlPlaneAdapters: async () => f,
1065
1147
  sync: C
1066
- }, { entityHooks: b, tenantHooks: p } = we(P), T = {
1148
+ }, { entityHooks: P, tenantHooks: p } = pe(b), T = {
1067
1149
  resourceServers: [
1068
- b.resourceServers,
1150
+ P.resourceServers,
1069
1151
  ...(c == null ? void 0 : c.resourceServers) ?? []
1070
1152
  ],
1071
- roles: [b.roles, ...(c == null ? void 0 : c.roles) ?? []],
1153
+ roles: [P.roles, ...(c == null ? void 0 : c.roles) ?? []],
1072
1154
  connections: (c == null ? void 0 : c.connections) ?? [],
1073
1155
  tenants: (c == null ? void 0 : c.tenants) ?? [],
1074
1156
  rolePermissions: (c == null ? void 0 : c.rolePermissions) ?? []
1075
- }, y = J({
1157
+ }, h = X({
1076
1158
  accessControl: {
1077
1159
  controlPlaneTenantId: r,
1078
1160
  requireOrganizationMatch: i,
1079
- defaultPermissions: o
1161
+ defaultPermissions: s
1080
1162
  }
1081
- }), F = k(
1163
+ }), F = N(
1082
1164
  {
1083
1165
  accessControl: {
1084
1166
  controlPlaneTenantId: r,
1085
1167
  requireOrganizationMatch: i,
1086
- defaultPermissions: o
1168
+ defaultPermissions: s
1087
1169
  }
1088
1170
  },
1089
1171
  { tenants: {
1090
- async beforeCreate(A, v) {
1091
- return y.beforeCreate && (v = await y.beforeCreate(A, v)), p.beforeCreate && (v = await p.beforeCreate(A, v)), v;
1172
+ async beforeCreate(I, v) {
1173
+ return h.beforeCreate && (v = await h.beforeCreate(I, v)), p.beforeCreate && (v = await p.beforeCreate(I, v)), v;
1092
1174
  },
1093
- async afterCreate(A, v) {
1094
- var $, I;
1095
- await (($ = y.afterCreate) == null ? void 0 : $.call(y, A, v)), await ((I = p.afterCreate) == null ? void 0 : I.call(p, A, v));
1175
+ async afterCreate(I, v) {
1176
+ var z, R;
1177
+ await ((z = h.afterCreate) == null ? void 0 : z.call(h, I, v)), await ((R = p.afterCreate) == null ? void 0 : R.call(p, I, v));
1096
1178
  },
1097
- async beforeDelete(A, v) {
1098
- var $, I;
1099
- await (($ = y.beforeDelete) == null ? void 0 : $.call(y, A, v)), await ((I = p.beforeDelete) == null ? void 0 : I.call(p, A, v));
1179
+ async beforeDelete(I, v) {
1180
+ var z, R;
1181
+ await ((z = h.beforeDelete) == null ? void 0 : z.call(h, I, v)), await ((R = p.beforeDelete) == null ? void 0 : R.call(p, I, v));
1100
1182
  }
1101
1183
  } }
1102
- ), { app: D } = oe({
1184
+ ), { app: j } = ie({
1103
1185
  dataAdapter: f,
1104
1186
  managementDataAdapter: m,
1105
1187
  ...d,
@@ -1109,24 +1191,24 @@ function Fe(e) {
1109
1191
  { path: "/tenants", router: F }
1110
1192
  ]
1111
1193
  });
1112
- return D.use(
1194
+ return j.use(
1113
1195
  "/api/v2/*",
1114
- Te(r)
1115
- ), w && D.use("/api/v2/*", ve()), { app: D, controlPlaneTenantId: r };
1196
+ be(r)
1197
+ ), w && j.use("/api/v2/*", _e()), { app: j, controlPlaneTenantId: r };
1116
1198
  }
1117
- function De(e) {
1118
- const t = N(e);
1199
+ function Me(e) {
1200
+ const t = B(e);
1119
1201
  return {
1120
1202
  name: "multi-tenancy",
1121
1203
  // Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
1122
- middleware: Y(e),
1204
+ middleware: Z(e),
1123
1205
  // Provide lifecycle hooks
1124
1206
  hooks: t,
1125
1207
  // Mount tenant management routes
1126
1208
  routes: [
1127
1209
  {
1128
1210
  path: "/management",
1129
- handler: k(e, t)
1211
+ handler: N(e, t)
1130
1212
  }
1131
1213
  ],
1132
1214
  // Called when plugin is registered
@@ -1139,23 +1221,23 @@ function De(e) {
1139
1221
  }
1140
1222
  };
1141
1223
  }
1142
- function N(e) {
1143
- const t = e.accessControl ? ce(e.accessControl) : {}, n = e.databaseIsolation ? ue(e.databaseIsolation) : {}, r = J(e);
1224
+ function B(e) {
1225
+ const t = e.accessControl ? le(e.accessControl) : {}, n = e.databaseIsolation ? de(e.databaseIsolation) : {}, r = X(e);
1144
1226
  return {
1145
1227
  ...t,
1146
1228
  ...n,
1147
1229
  tenants: r
1148
1230
  };
1149
1231
  }
1150
- function Ie(e) {
1151
- const t = new ee(), n = N(e);
1152
- return t.route("/tenants", k(e, n)), t;
1232
+ function Se(e) {
1233
+ const t = new te(), n = B(e);
1234
+ return t.route("/tenants", N(e, n)), t;
1153
1235
  }
1154
- function Me(e) {
1236
+ function De(e) {
1155
1237
  return {
1156
- hooks: N(e),
1157
- middleware: Y(e),
1158
- app: Ie(e),
1238
+ hooks: B(e),
1239
+ middleware: Z(e),
1240
+ app: Se(e),
1159
1241
  config: e,
1160
1242
  /**
1161
1243
  * Wraps data adapters with runtime fallback from the control plane.
@@ -1167,7 +1249,7 @@ function Me(e) {
1167
1249
  */
1168
1250
  wrapAdapters: (t, n) => {
1169
1251
  var r;
1170
- return X(t, {
1252
+ return Y(t, {
1171
1253
  controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
1172
1254
  controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
1173
1255
  });
@@ -1175,23 +1257,23 @@ function Me(e) {
1175
1257
  };
1176
1258
  }
1177
1259
  export {
1178
- ce as createAccessControlHooks,
1260
+ le as createAccessControlHooks,
1179
1261
  Pe as createAccessControlMiddleware,
1180
- Te as createControlPlaneTenantMiddleware,
1181
- ue as createDatabaseHooks,
1182
- Ae as createDatabaseMiddleware,
1183
- Ie as createMultiTenancy,
1184
- N as createMultiTenancyHooks,
1185
- Y as createMultiTenancyMiddleware,
1186
- De as createMultiTenancyPlugin,
1187
- ve as createProtectSyncedMiddleware,
1188
- J as createProvisioningHooks,
1189
- Ce as createRuntimeFallbackAdapter,
1190
- be as createSubdomainMiddleware,
1191
- we as createSyncHooks,
1192
- k as createTenantsOpenAPIRouter,
1193
- Fe as initMultiTenant,
1194
- Me as setupMultiTenancy,
1195
- le as validateTenantAccess,
1196
- X as withRuntimeFallback
1262
+ be as createControlPlaneTenantMiddleware,
1263
+ de as createDatabaseHooks,
1264
+ Ie as createDatabaseMiddleware,
1265
+ Se as createMultiTenancy,
1266
+ B as createMultiTenancyHooks,
1267
+ Z as createMultiTenancyMiddleware,
1268
+ Me as createMultiTenancyPlugin,
1269
+ _e as createProtectSyncedMiddleware,
1270
+ X as createProvisioningHooks,
1271
+ Te as createRuntimeFallbackAdapter,
1272
+ Ae as createSubdomainMiddleware,
1273
+ pe as createSyncHooks,
1274
+ N as createTenantsOpenAPIRouter,
1275
+ je as initMultiTenant,
1276
+ De as setupMultiTenancy,
1277
+ ue as validateTenantAccess,
1278
+ Y as withRuntimeFallback
1197
1279
  };