@authhero/multi-tenancy 13.15.0 → 13.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,11 +1,11 @@
1
- var se = Object.defineProperty;
2
- var oe = (t, e, n) => e in t ? se(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var U = (t, e, n) => oe(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { Hono as te } from "hono";
5
- import { getTenantAudience as ie, MANAGEMENT_API_SCOPES as ce, MANAGEMENT_API_AUDIENCE as le, fetchAll as F, init as de } from "authhero";
1
+ var ae = Object.defineProperty;
2
+ var se = (t, e, n) => e in t ? ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var U = (t, e, n) => se(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { Hono as ee } from "hono";
5
+ import { getTenantAudience as oe, MANAGEMENT_API_SCOPES as ie, MANAGEMENT_API_AUDIENCE as ce, fetchAll as F, init as le } from "authhero";
6
6
  export * from "authhero";
7
- import { OpenAPIHono as ue, createRoute as B, z } from "@hono/zod-openapi";
8
- import { auth0QuerySchema as me, tenantSchema as k, tenantInsertSchema as pe, connectionSchema as G, connectionOptionsSchema as K } from "@authhero/adapter-interfaces";
7
+ import { OpenAPIHono as de, createRoute as B, z } from "@hono/zod-openapi";
8
+ import { auth0QuerySchema as ue, tenantSchema as E, tenantInsertSchema as me, connectionSchema as G, connectionOptionsSchema as K } from "@authhero/adapter-interfaces";
9
9
  var S = class extends Error {
10
10
  /**
11
11
  * Creates an instance of `HTTPException`.
@@ -32,27 +32,27 @@ var S = class extends Error {
32
32
  });
33
33
  }
34
34
  };
35
- function fe(t) {
35
+ function pe(t) {
36
36
  const { controlPlaneTenantId: e, requireOrganizationMatch: n = !0 } = t;
37
37
  return {
38
- async onTenantAccessValidation(a, r) {
39
- if (r === e)
38
+ async onTenantAccessValidation(r, a) {
39
+ if (a === e)
40
40
  return !0;
41
41
  if (n) {
42
- const l = a.var.org_name, s = a.var.organization_id, i = l || s;
43
- return i ? i === r : !1;
42
+ const c = r.var.org_name, s = r.var.organization_id, i = c || s;
43
+ return i ? i === a : !1;
44
44
  }
45
45
  return !0;
46
46
  }
47
47
  };
48
48
  }
49
- function we(t, e, n, a) {
49
+ function fe(t, e, n, r) {
50
50
  if (e === n)
51
51
  return !0;
52
- const r = a || t;
53
- return r ? r === e : !1;
52
+ const a = r || t;
53
+ return a ? a === e : !1;
54
54
  }
55
- function ge(t) {
55
+ function we(t) {
56
56
  return {
57
57
  async resolveDataAdapters(e) {
58
58
  try {
@@ -67,112 +67,112 @@ function ge(t) {
67
67
  }
68
68
  };
69
69
  }
70
- function he(t) {
70
+ function ge(t) {
71
71
  return {
72
72
  async beforeCreate(e, n) {
73
73
  return !n.audience && n.id ? {
74
74
  ...n,
75
- audience: ie(n.id)
75
+ audience: oe(n.id)
76
76
  } : n;
77
77
  },
78
78
  async afterCreate(e, n) {
79
- const { accessControl: a, databaseIsolation: r } = t;
80
- a && e.ctx && await ve(e, n, a), r != null && r.onProvision && await r.onProvision(n.id);
79
+ const { accessControl: r, databaseIsolation: a } = t;
80
+ r && e.ctx && await he(e, n, r), a != null && a.onProvision && await a.onProvision(n.id);
81
81
  },
82
82
  async beforeDelete(e, n) {
83
- const { accessControl: a, databaseIsolation: r } = t;
84
- if (a)
83
+ const { accessControl: r, databaseIsolation: a } = t;
84
+ if (r)
85
85
  try {
86
86
  const s = (await e.adapters.organizations.list(
87
- a.controlPlaneTenantId
87
+ r.controlPlaneTenantId
88
88
  )).organizations.find((i) => i.name === n);
89
89
  s && await e.adapters.organizations.remove(
90
- a.controlPlaneTenantId,
90
+ r.controlPlaneTenantId,
91
91
  s.id
92
92
  );
93
- } catch (l) {
93
+ } catch (c) {
94
94
  console.warn(
95
95
  `Failed to remove organization for tenant ${n}:`,
96
- l
96
+ c
97
97
  );
98
98
  }
99
- if (r != null && r.onDeprovision)
99
+ if (a != null && a.onDeprovision)
100
100
  try {
101
- await r.onDeprovision(n);
102
- } catch (l) {
101
+ await a.onDeprovision(n);
102
+ } catch (c) {
103
103
  console.warn(
104
104
  `Failed to deprovision database for tenant ${n}:`,
105
- l
105
+ c
106
106
  );
107
107
  }
108
108
  }
109
109
  };
110
110
  }
111
- async function ve(t, e, n) {
111
+ async function he(t, e, n) {
112
112
  const {
113
- controlPlaneTenantId: a,
114
- defaultPermissions: r,
115
- defaultRoles: l,
113
+ controlPlaneTenantId: r,
114
+ defaultPermissions: a,
115
+ defaultRoles: c,
116
116
  issuer: s,
117
117
  adminRoleName: i = "Tenant Admin",
118
118
  adminRoleDescription: p = "Full access to all tenant management operations",
119
119
  addCreatorToOrganization: o = !0
120
- } = n, c = await t.adapters.organizations.create(
121
- a,
120
+ } = n, l = await t.adapters.organizations.create(
121
+ r,
122
122
  {
123
123
  name: e.id,
124
124
  display_name: e.friendly_name || e.id
125
125
  }
126
126
  );
127
127
  let u;
128
- if (s && (u = await ye(
128
+ if (s && (u = await _e(
129
129
  t,
130
- a,
130
+ r,
131
131
  i,
132
132
  p
133
133
  )), o && t.ctx) {
134
134
  const d = t.ctx.var.user;
135
- if (d != null && d.sub && !await _e(
135
+ if (d != null && d.sub && !await ve(
136
136
  t,
137
- a,
137
+ r,
138
138
  d.sub
139
139
  ))
140
140
  try {
141
- await t.adapters.userOrganizations.create(a, {
141
+ await t.adapters.userOrganizations.create(r, {
142
142
  user_id: d.sub,
143
- organization_id: c.id
143
+ organization_id: l.id
144
144
  }), u && await t.adapters.userRoles.create(
145
- a,
145
+ r,
146
146
  d.sub,
147
147
  u,
148
- c.id
148
+ l.id
149
149
  // organizationId
150
150
  );
151
151
  } catch (f) {
152
152
  console.warn(
153
- `Failed to add creator ${d.sub} to organization ${c.id}:`,
153
+ `Failed to add creator ${d.sub} to organization ${l.id}:`,
154
154
  f
155
155
  );
156
156
  }
157
157
  }
158
- l && l.length > 0 && console.log(
159
- `Would assign roles ${l.join(", ")} to organization ${c.id}`
160
- ), r && r.length > 0 && console.log(
161
- `Would grant permissions ${r.join(", ")} to organization ${c.id}`
158
+ c && c.length > 0 && console.log(
159
+ `Would assign roles ${c.join(", ")} to organization ${l.id}`
160
+ ), a && a.length > 0 && console.log(
161
+ `Would grant permissions ${a.join(", ")} to organization ${l.id}`
162
162
  );
163
163
  }
164
- async function _e(t, e, n) {
165
- const a = await t.adapters.userRoles.list(
164
+ async function ve(t, e, n) {
165
+ const r = await t.adapters.userRoles.list(
166
166
  e,
167
167
  n,
168
168
  void 0,
169
169
  ""
170
170
  // Empty string for global roles
171
171
  );
172
- for (const r of a)
172
+ for (const a of r)
173
173
  if ((await t.adapters.rolePermissions.list(
174
174
  e,
175
- r.id,
175
+ a.id,
176
176
  { per_page: 1e3 }
177
177
  )).some(
178
178
  (i) => i.permission_name === "admin:organizations"
@@ -180,14 +180,14 @@ async function _e(t, e, n) {
180
180
  return !0;
181
181
  return !1;
182
182
  }
183
- async function ye(t, e, n, a) {
184
- const l = (await t.adapters.roles.list(e, {})).roles.find((o) => o.name === n);
185
- if (l)
186
- return l.id;
183
+ async function _e(t, e, n, r) {
184
+ const c = (await t.adapters.roles.list(e, {})).roles.find((o) => o.name === n);
185
+ if (c)
186
+ return c.id;
187
187
  const s = await t.adapters.roles.create(e, {
188
188
  name: n,
189
- description: a
190
- }), i = le, p = ce.map((o) => ({
189
+ description: r
190
+ }), i = ce, p = ie.map((o) => ({
191
191
  role_id: s.id,
192
192
  resource_server_identifier: i,
193
193
  permission_name: o.value
@@ -198,7 +198,7 @@ async function ye(t, e, n, a) {
198
198
  p
199
199
  ), s.id;
200
200
  }
201
- const be = [
201
+ const ye = [
202
202
  "client_id",
203
203
  "client_secret",
204
204
  "app_secret",
@@ -208,22 +208,22 @@ const be = [
208
208
  "twilio_token"
209
209
  ];
210
210
  function L(t, e, n = () => !0) {
211
- const { controlPlaneTenantId: a, getChildTenantIds: r, getAdapters: l } = t, s = /* @__PURE__ */ new Map();
212
- async function i(c, u, d) {
213
- return (await e(c).list(u, {
211
+ const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: c } = t, s = /* @__PURE__ */ new Map();
212
+ async function i(l, u, d) {
213
+ return (await e(l).list(u, {
214
214
  q: `name:${d}`,
215
215
  per_page: 1
216
216
  }))[0] ?? null;
217
217
  }
218
- async function p(c) {
219
- const u = await r(), d = e(await l(a));
218
+ async function p(l) {
219
+ const u = await a(), d = e(await c(r));
220
220
  await Promise.all(
221
221
  u.map(async (m) => {
222
222
  try {
223
- const f = await l(m), w = e(f), h = {
224
- ...d.transform(c),
223
+ const f = await c(m), w = e(f), h = {
224
+ ...d.transform(l),
225
225
  is_system: !0
226
- }, v = await i(f, m, c.name), _ = v ? w.getId(v) : void 0;
226
+ }, v = await i(f, m, l.name), _ = v ? w.getId(v) : void 0;
227
227
  if (v && _) {
228
228
  const A = w.preserveOnUpdate ? w.preserveOnUpdate(v, h) : h;
229
229
  await w.update(m, _, A);
@@ -231,23 +231,23 @@ function L(t, e, n = () => !0) {
231
231
  await w.create(m, h);
232
232
  } catch (f) {
233
233
  console.error(
234
- `Failed to sync ${d.listKey} "${c.name}" to tenant "${m}":`,
234
+ `Failed to sync ${d.listKey} "${l.name}" to tenant "${m}":`,
235
235
  f
236
236
  );
237
237
  }
238
238
  })
239
239
  );
240
240
  }
241
- async function o(c) {
242
- const u = await r();
241
+ async function o(l) {
242
+ const u = await a();
243
243
  await Promise.all(
244
244
  u.map(async (d) => {
245
245
  try {
246
- const m = await l(d), f = e(m), w = await i(m, d, c), g = w ? f.getId(w) : void 0;
246
+ const m = await c(d), f = e(m), w = await i(m, d, l), g = w ? f.getId(w) : void 0;
247
247
  w && g && await f.remove(d, g);
248
248
  } catch (m) {
249
249
  console.error(
250
- `Failed to delete entity "${c}" from tenant "${d}":`,
250
+ `Failed to delete entity "${l}" from tenant "${d}":`,
251
251
  m
252
252
  );
253
253
  }
@@ -255,39 +255,39 @@ function L(t, e, n = () => !0) {
255
255
  );
256
256
  }
257
257
  return {
258
- afterCreate: async (c, u) => {
259
- c.tenantId === a && n(u) && await p(u);
258
+ afterCreate: async (l, u) => {
259
+ l.tenantId === r && n(u) && await p(u);
260
260
  },
261
- afterUpdate: async (c, u, d) => {
262
- c.tenantId === a && n(d) && await p(d);
261
+ afterUpdate: async (l, u, d) => {
262
+ l.tenantId === r && n(d) && await p(d);
263
263
  },
264
- beforeDelete: async (c, u) => {
265
- if (c.tenantId !== a) return;
266
- const m = await e(c.adapters).get(c.tenantId, u);
264
+ beforeDelete: async (l, u) => {
265
+ if (l.tenantId !== r) return;
266
+ const m = await e(l.adapters).get(l.tenantId, u);
267
267
  m && n(m) && s.set(u, m);
268
268
  },
269
- afterDelete: async (c, u) => {
270
- if (c.tenantId !== a) return;
269
+ afterDelete: async (l, u) => {
270
+ if (l.tenantId !== r) return;
271
271
  const d = s.get(u);
272
272
  d && (s.delete(u), await o(d.name));
273
273
  }
274
274
  };
275
275
  }
276
276
  function V(t, e, n = () => !0) {
277
- const { controlPlaneTenantId: a, getControlPlaneAdapters: r, getAdapters: l } = t;
277
+ const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: c } = t;
278
278
  return {
279
279
  async afterCreate(s, i) {
280
- if (i.id !== a)
280
+ if (i.id !== r)
281
281
  try {
282
- const p = await r(), o = await l(i.id), c = e(p), u = e(o), d = await F(
283
- (m) => c.listPaginated(a, m),
284
- c.listKey,
282
+ const p = await a(), o = await c(i.id), l = e(p), u = e(o), d = await F(
283
+ (m) => l.listPaginated(r, m),
284
+ l.listKey,
285
285
  { cursorField: "id", pageSize: 100 }
286
286
  );
287
287
  await Promise.all(
288
288
  d.filter((m) => n(m)).map(async (m) => {
289
289
  try {
290
- const f = c.transform(m);
290
+ const f = l.transform(m);
291
291
  await u.create(i.id, {
292
292
  ...f,
293
293
  is_system: !0
@@ -309,16 +309,17 @@ function V(t, e, n = () => !0) {
309
309
  }
310
310
  };
311
311
  }
312
- const H = (t) => ({
312
+ const k = (t) => ({
313
313
  list: async (e, n) => (await t.resourceServers.list(e, n)).resource_servers,
314
314
  listPaginated: (e, n) => t.resourceServers.list(e, n),
315
315
  get: (e, n) => t.resourceServers.get(e, n),
316
316
  create: (e, n) => t.resourceServers.create(e, n),
317
- update: (e, n, a) => t.resourceServers.update(e, n, a),
317
+ update: (e, n, r) => t.resourceServers.update(e, n, r),
318
318
  remove: (e, n) => t.resourceServers.remove(e, n),
319
319
  listKey: "resource_servers",
320
320
  getId: (e) => e.id,
321
321
  transform: (e) => ({
322
+ id: e.id,
322
323
  name: e.name,
323
324
  identifier: e.identifier,
324
325
  scopes: e.scopes,
@@ -326,33 +327,35 @@ const H = (t) => ({
326
327
  token_lifetime: e.token_lifetime,
327
328
  token_lifetime_for_web: e.token_lifetime_for_web
328
329
  })
329
- }), x = (t) => ({
330
+ }), H = (t) => ({
330
331
  list: async (e, n) => (await t.roles.list(e, n)).roles,
331
332
  listPaginated: (e, n) => t.roles.list(e, n),
332
333
  get: (e, n) => t.roles.get(e, n),
333
334
  create: (e, n) => t.roles.create(e, n),
334
- update: (e, n, a) => t.roles.update(e, n, a),
335
+ update: (e, n, r) => t.roles.update(e, n, r),
335
336
  remove: (e, n) => t.roles.remove(e, n),
336
337
  listKey: "roles",
337
338
  getId: (e) => e.id,
338
339
  transform: (e) => ({
340
+ id: e.id,
339
341
  name: e.name,
340
342
  description: e.description
341
343
  })
342
- }), ee = (t) => ({
344
+ }), x = (t) => ({
343
345
  list: async (e, n) => (await t.connections.list(e, n)).connections,
344
346
  listPaginated: (e, n) => t.connections.list(e, n),
345
347
  get: (e, n) => t.connections.get(e, n),
346
348
  create: (e, n) => t.connections.create(e, n),
347
- update: (e, n, a) => t.connections.update(e, n, a),
349
+ update: (e, n, r) => t.connections.update(e, n, r),
348
350
  remove: (e, n) => t.connections.remove(e, n),
349
351
  listKey: "connections",
350
352
  getId: (e) => e.id,
351
353
  transform: (e) => {
352
354
  const n = e.options ? { ...e.options } : {};
353
- for (const a of be)
354
- delete n[a];
355
+ for (const r of ye)
356
+ delete n[r];
355
357
  return {
358
+ id: e.id,
356
359
  name: e.name,
357
360
  display_name: e.display_name,
358
361
  strategy: e.strategy,
@@ -365,52 +368,52 @@ const H = (t) => ({
365
368
  };
366
369
  },
367
370
  preserveOnUpdate: (e, n) => {
368
- const a = e.options || {};
371
+ const r = e.options || {};
369
372
  return {
370
373
  ...n,
371
374
  options: {
372
375
  ...n.options,
373
- client_id: a.client_id,
374
- client_secret: a.client_secret,
375
- app_secret: a.app_secret,
376
- kid: a.kid,
377
- team_id: a.team_id,
378
- twilio_sid: a.twilio_sid,
379
- twilio_token: a.twilio_token
376
+ client_id: r.client_id,
377
+ client_secret: r.client_secret,
378
+ app_secret: r.app_secret,
379
+ kid: r.kid,
380
+ team_id: r.team_id,
381
+ twilio_sid: r.twilio_sid,
382
+ twilio_token: r.twilio_token
380
383
  }
381
384
  };
382
385
  }
383
386
  });
384
- function Ce(t) {
385
- const { sync: e = {}, filters: n = {} } = t, a = e.resourceServers ?? !0, r = e.roles ?? !0, l = e.connections ?? !0, s = a ? L(
387
+ function be(t) {
388
+ const { sync: e = {}, filters: n = {} } = t, r = e.resourceServers ?? !0, a = e.roles ?? !0, c = e.connections ?? !0, s = r ? L(
386
389
  t,
387
- H,
390
+ k,
388
391
  n.resourceServers
389
- ) : void 0, i = r ? L(
392
+ ) : void 0, i = a ? L(
390
393
  t,
391
- x,
394
+ H,
392
395
  n.roles
393
- ) : void 0, p = l ? L(
396
+ ) : void 0, p = c ? L(
394
397
  t,
395
- ee,
398
+ x,
396
399
  n.connections
397
- ) : void 0, o = a ? V(
400
+ ) : void 0, o = r ? V(
398
401
  t,
399
- H,
402
+ k,
400
403
  n.resourceServers
401
- ) : void 0, c = r ? V(
404
+ ) : void 0, l = a ? V(
402
405
  t,
403
- x,
406
+ H,
404
407
  n.roles
405
- ) : void 0, u = l ? V(
408
+ ) : void 0, u = c ? V(
406
409
  t,
407
- ee,
410
+ x,
408
411
  n.connections
409
- ) : void 0, d = r ? {
412
+ ) : void 0, d = a ? {
410
413
  async afterCreate(w, g) {
411
414
  var h;
412
415
  if (g.id !== t.controlPlaneTenantId) {
413
- await ((h = c == null ? void 0 : c.afterCreate) == null ? void 0 : h.call(c, w, g));
416
+ await ((h = l == null ? void 0 : l.afterCreate) == null ? void 0 : h.call(l, w, g));
414
417
  try {
415
418
  const v = await t.getControlPlaneAdapters(), _ = await t.getAdapters(g.id), A = await F(
416
419
  (b) => v.roles.list(
@@ -488,7 +491,7 @@ function Ce(t) {
488
491
  async afterCreate(w, g) {
489
492
  const h = [
490
493
  o == null ? void 0 : o.afterCreate,
491
- (d == null ? void 0 : d.afterCreate) ?? (c == null ? void 0 : c.afterCreate),
494
+ (d == null ? void 0 : d.afterCreate) ?? (l == null ? void 0 : l.afterCreate),
492
495
  u == null ? void 0 : u.afterCreate
493
496
  ], v = [];
494
497
  for (const _ of h)
@@ -509,14 +512,14 @@ function Ce(t) {
509
512
  };
510
513
  }
511
514
  function W(t, e) {
512
- const n = new ue();
515
+ const n = new de();
513
516
  return n.openapi(
514
517
  B({
515
518
  tags: ["tenants"],
516
519
  method: "get",
517
520
  path: "/",
518
521
  request: {
519
- query: me
522
+ query: ue
520
523
  },
521
524
  security: [
522
525
  {
@@ -528,7 +531,7 @@ function W(t, e) {
528
531
  content: {
529
532
  "application/json": {
530
533
  schema: z.object({
531
- tenants: z.array(k),
534
+ tenants: z.array(E),
532
535
  start: z.number().optional(),
533
536
  limit: z.number().optional(),
534
537
  length: z.number().optional()
@@ -539,26 +542,26 @@ function W(t, e) {
539
542
  }
540
543
  }
541
544
  }),
542
- async (a) => {
545
+ async (r) => {
543
546
  var m, f, w, g;
544
- const r = a.req.valid("query"), { page: l, per_page: s, include_totals: i, q: p } = r, o = a.var.user, c = (o == null ? void 0 : o.permissions) || [];
545
- if (c.includes("auth:read") || c.includes("admin:organizations")) {
546
- const h = await a.env.data.tenants.list({
547
- page: l,
547
+ const a = r.req.valid("query"), { page: c, per_page: s, include_totals: i, q: p } = a, o = r.var.user, l = (o == null ? void 0 : o.permissions) || [];
548
+ if (l.includes("auth:read") || l.includes("admin:organizations")) {
549
+ const h = await r.env.data.tenants.list({
550
+ page: c,
548
551
  per_page: s,
549
552
  include_totals: i,
550
553
  q: p
551
554
  });
552
- return i ? a.json({
555
+ return i ? r.json({
553
556
  tenants: h.tenants,
554
557
  start: ((m = h.totals) == null ? void 0 : m.start) ?? 0,
555
558
  limit: ((f = h.totals) == null ? void 0 : f.limit) ?? s,
556
559
  length: h.tenants.length
557
- }) : a.json({ tenants: h.tenants });
560
+ }) : r.json({ tenants: h.tenants });
558
561
  }
559
562
  if (t.accessControl && (o != null && o.sub)) {
560
563
  const h = t.accessControl.controlPlaneTenantId, _ = (await F(
561
- (D) => a.env.data.userOrganizations.listUserOrganizations(
564
+ (D) => r.env.data.userOrganizations.listUserOrganizations(
562
565
  h,
563
566
  o.sub,
564
567
  D
@@ -566,45 +569,45 @@ function W(t, e) {
566
569
  "organizations"
567
570
  )).map((D) => D.name);
568
571
  if (_.length === 0)
569
- return i ? a.json({
572
+ return i ? r.json({
570
573
  tenants: [],
571
574
  start: 0,
572
575
  limit: s ?? 50,
573
576
  length: 0
574
- }) : a.json({ tenants: [] });
575
- const A = _.length, $ = l ?? 0, b = s ?? 50, y = $ * b, C = _.slice(y, y + b);
577
+ }) : r.json({ tenants: [] });
578
+ const A = _.length, $ = c ?? 0, b = s ?? 50, y = $ * b, C = _.slice(y, y + b);
576
579
  if (C.length === 0)
577
- return i ? a.json({
580
+ return i ? r.json({
578
581
  tenants: [],
579
582
  start: y,
580
583
  limit: b,
581
584
  length: A
582
- }) : a.json({ tenants: [] });
583
- const P = C.map((D) => `id:${D}`).join(" OR "), q = p ? `(${P}) AND (${p})` : P, R = await a.env.data.tenants.list({
585
+ }) : r.json({ tenants: [] });
586
+ const P = C.map((D) => `id:${D}`).join(" OR "), q = p ? `(${P}) AND (${p})` : P, R = await r.env.data.tenants.list({
584
587
  q,
585
588
  per_page: b,
586
589
  include_totals: !1
587
590
  // We calculate totals from accessibleTenantIds
588
591
  });
589
- return i ? a.json({
592
+ return i ? r.json({
590
593
  tenants: R.tenants,
591
594
  start: y,
592
595
  limit: b,
593
596
  length: A
594
- }) : a.json({ tenants: R.tenants });
597
+ }) : r.json({ tenants: R.tenants });
595
598
  }
596
- const d = await a.env.data.tenants.list({
597
- page: l,
599
+ const d = await r.env.data.tenants.list({
600
+ page: c,
598
601
  per_page: s,
599
602
  include_totals: i,
600
603
  q: p
601
604
  });
602
- return i ? a.json({
605
+ return i ? r.json({
603
606
  tenants: d.tenants,
604
607
  start: ((w = d.totals) == null ? void 0 : w.start) ?? 0,
605
608
  limit: ((g = d.totals) == null ? void 0 : g.limit) ?? s,
606
609
  length: d.tenants.length
607
- }) : a.json({ tenants: d.tenants });
610
+ }) : r.json({ tenants: d.tenants });
608
611
  }
609
612
  ), n.openapi(
610
613
  B({
@@ -615,7 +618,7 @@ function W(t, e) {
615
618
  body: {
616
619
  content: {
617
620
  "application/json": {
618
- schema: pe
621
+ schema: me
619
622
  }
620
623
  }
621
624
  }
@@ -629,7 +632,7 @@ function W(t, e) {
629
632
  201: {
630
633
  content: {
631
634
  "application/json": {
632
- schema: k
635
+ schema: E
633
636
  }
634
637
  },
635
638
  description: "Tenant created"
@@ -642,21 +645,21 @@ function W(t, e) {
642
645
  }
643
646
  }
644
647
  }),
645
- async (a) => {
648
+ async (r) => {
646
649
  var p, o;
647
- const r = a.var.user;
648
- if (!(r != null && r.sub))
650
+ const a = r.var.user;
651
+ if (!(a != null && a.sub))
649
652
  throw new S(401, {
650
653
  message: "Authentication required to create tenants"
651
654
  });
652
- let l = a.req.valid("json");
655
+ let c = r.req.valid("json");
653
656
  const s = {
654
- adapters: a.env.data,
655
- ctx: a
657
+ adapters: r.env.data,
658
+ ctx: r
656
659
  };
657
- (p = e.tenants) != null && p.beforeCreate && (l = await e.tenants.beforeCreate(s, l));
658
- const i = await a.env.data.tenants.create(l);
659
- return (o = e.tenants) != null && o.afterCreate && await e.tenants.afterCreate(s, i), a.json(i, 201);
660
+ (p = e.tenants) != null && p.beforeCreate && (c = await e.tenants.beforeCreate(s, c));
661
+ const i = await r.env.data.tenants.create(c);
662
+ return (o = e.tenants) != null && o.afterCreate && await e.tenants.afterCreate(s, i), r.json(i, 201);
660
663
  }
661
664
  ), n.openapi(
662
665
  B({
@@ -685,44 +688,44 @@ function W(t, e) {
685
688
  }
686
689
  }
687
690
  }),
688
- async (a) => {
691
+ async (r) => {
689
692
  var i, p;
690
- const { id: r } = a.req.valid("param");
693
+ const { id: a } = r.req.valid("param");
691
694
  if (t.accessControl) {
692
- const o = a.var.user, c = t.accessControl.controlPlaneTenantId;
695
+ const o = r.var.user, l = t.accessControl.controlPlaneTenantId;
693
696
  if (!(o != null && o.sub))
694
697
  throw new S(401, {
695
698
  message: "Authentication required"
696
699
  });
697
- if (r === c)
700
+ if (a === l)
698
701
  throw new S(403, {
699
702
  message: "Cannot delete the control plane"
700
703
  });
701
704
  if (!(await F(
702
- (m) => a.env.data.userOrganizations.listUserOrganizations(
703
- c,
705
+ (m) => r.env.data.userOrganizations.listUserOrganizations(
706
+ l,
704
707
  o.sub,
705
708
  m
706
709
  ),
707
710
  "organizations"
708
- )).some((m) => m.name === r))
711
+ )).some((m) => m.name === a))
709
712
  throw new S(403, {
710
713
  message: "Access denied to this tenant"
711
714
  });
712
715
  }
713
- if (!await a.env.data.tenants.get(r))
716
+ if (!await r.env.data.tenants.get(a))
714
717
  throw new S(404, {
715
718
  message: "Tenant not found"
716
719
  });
717
720
  const s = {
718
- adapters: a.env.data,
719
- ctx: a
721
+ adapters: r.env.data,
722
+ ctx: r
720
723
  };
721
- return (i = e.tenants) != null && i.beforeDelete && await e.tenants.beforeDelete(s, r), await a.env.data.tenants.remove(r), (p = e.tenants) != null && p.afterDelete && await e.tenants.afterDelete(s, r), a.body(null, 204);
724
+ return (i = e.tenants) != null && i.beforeDelete && await e.tenants.beforeDelete(s, a), await r.env.data.tenants.remove(a), (p = e.tenants) != null && p.afterDelete && await e.tenants.afterDelete(s, a), r.body(null, 204);
722
725
  }
723
726
  ), n;
724
727
  }
725
- function Ae(t) {
728
+ function Ce(t) {
726
729
  const e = [
727
730
  {
728
731
  pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
@@ -731,27 +734,27 @@ function Ae(t) {
731
734
  { pattern: /\/api\/v2\/roles\/([^/]+)$/, type: "role" },
732
735
  { pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
733
736
  ];
734
- for (const { pattern: n, type: a } of e) {
735
- const r = t.match(n);
736
- if (r && r[1])
737
- return { type: a, id: r[1] };
737
+ for (const { pattern: n, type: r } of e) {
738
+ const a = t.match(n);
739
+ if (a && a[1])
740
+ return { type: r, id: a[1] };
738
741
  }
739
742
  return null;
740
743
  }
741
- async function Te(t, e, n) {
744
+ async function Ae(t, e, n) {
742
745
  try {
743
746
  switch (n.type) {
744
747
  case "resource_server": {
745
- const a = await t.resourceServers.get(e, n.id);
746
- return (a == null ? void 0 : a.is_system) === !0;
748
+ const r = await t.resourceServers.get(e, n.id);
749
+ return (r == null ? void 0 : r.is_system) === !0;
747
750
  }
748
751
  case "role": {
749
- const a = await t.roles.get(e, n.id);
750
- return (a == null ? void 0 : a.is_system) === !0;
752
+ const r = await t.roles.get(e, n.id);
753
+ return (r == null ? void 0 : r.is_system) === !0;
751
754
  }
752
755
  case "connection": {
753
- const a = await t.connections.get(e, n.id);
754
- return (a == null ? void 0 : a.is_system) === !0;
756
+ const r = await t.connections.get(e, n.id);
757
+ return (r == null ? void 0 : r.is_system) === !0;
755
758
  }
756
759
  default:
757
760
  return !1;
@@ -760,43 +763,43 @@ async function Te(t, e, n) {
760
763
  return !1;
761
764
  }
762
765
  }
763
- function Se(t) {
766
+ function Te(t) {
764
767
  return {
765
768
  resource_server: "resource server",
766
769
  role: "role",
767
770
  connection: "connection"
768
771
  }[t];
769
772
  }
770
- function Ie() {
773
+ function Se() {
771
774
  return async (t, e) => {
772
775
  if (!["PATCH", "PUT", "DELETE"].includes(t.req.method))
773
776
  return e();
774
- const n = Ae(t.req.path);
777
+ const n = Ce(t.req.path);
775
778
  if (!n)
776
779
  return e();
777
- const a = t.var.tenant_id || t.req.header("x-tenant-id") || t.req.header("tenant-id");
778
- if (!a)
780
+ const r = t.var.tenant_id || t.req.header("x-tenant-id") || t.req.header("tenant-id");
781
+ if (!r)
779
782
  return e();
780
- if (await Te(t.env.data, a, n))
783
+ if (await Ae(t.env.data, r, n))
781
784
  throw new S(403, {
782
- message: `This ${Se(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
785
+ message: `This ${Te(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
783
786
  });
784
787
  return e();
785
788
  };
786
789
  }
787
- function ne(t, e) {
788
- const { controlPlaneTenantId: n, controlPlaneClientId: a } = e;
790
+ function te(t, e) {
791
+ const { controlPlaneTenantId: n, controlPlaneClientId: r } = e;
789
792
  return {
790
793
  ...t,
791
794
  legacyClients: {
792
795
  ...t.legacyClients,
793
- get: async (r) => {
796
+ get: async (a) => {
794
797
  var u;
795
- const l = await t.legacyClients.get(r);
796
- if (!l)
798
+ const c = await t.legacyClients.get(a);
799
+ if (!c)
797
800
  return null;
798
- const s = a ? await t.legacyClients.get(a) : void 0, i = await t.connections.list(
799
- l.tenant.id
801
+ const s = r ? await t.legacyClients.get(r) : void 0, i = await t.connections.list(
802
+ c.tenant.id
800
803
  ), p = n ? await t.connections.list(n) : { connections: [] }, o = i.connections.map((d) => {
801
804
  var w;
802
805
  const m = (w = p.connections) == null ? void 0 : w.find(
@@ -812,41 +815,41 @@ function ne(t, e) {
812
815
  ...m.options || {},
813
816
  ...d.options
814
817
  }), f;
815
- }).filter((d) => d), c = {
818
+ }).filter((d) => d), l = {
816
819
  ...(s == null ? void 0 : s.tenant) || {},
817
- ...l.tenant
820
+ ...c.tenant
818
821
  };
819
- return !l.tenant.audience && ((u = s == null ? void 0 : s.tenant) != null && u.audience) && (c.audience = s.tenant.audience), {
820
- ...l,
822
+ return !c.tenant.audience && ((u = s == null ? void 0 : s.tenant) != null && u.audience) && (l.audience = s.tenant.audience), {
823
+ ...c,
821
824
  web_origins: [
822
825
  ...(s == null ? void 0 : s.web_origins) || [],
823
- ...l.web_origins || []
826
+ ...c.web_origins || []
824
827
  ],
825
828
  allowed_logout_urls: [
826
829
  ...(s == null ? void 0 : s.allowed_logout_urls) || [],
827
- ...l.allowed_logout_urls || []
830
+ ...c.allowed_logout_urls || []
828
831
  ],
829
832
  callbacks: [
830
833
  ...(s == null ? void 0 : s.callbacks) || [],
831
- ...l.callbacks || []
834
+ ...c.callbacks || []
832
835
  ],
833
836
  connections: o,
834
- tenant: c
837
+ tenant: l
835
838
  };
836
839
  }
837
840
  },
838
841
  connections: {
839
842
  ...t.connections,
840
- get: async (r, l) => {
843
+ get: async (a, c) => {
841
844
  const s = await t.connections.get(
842
- r,
843
- l
845
+ a,
846
+ c
844
847
  );
845
848
  if (!s || !n)
846
849
  return s;
847
850
  const i = await t.connections.get(
848
851
  n,
849
- l
852
+ c
850
853
  );
851
854
  if (!i)
852
855
  return s;
@@ -859,23 +862,23 @@ function ne(t, e) {
859
862
  ...s.options
860
863
  }), p;
861
864
  },
862
- list: async (r, l) => {
863
- const s = await t.connections.list(r, l);
864
- if (!n || r === n)
865
+ list: async (a, c) => {
866
+ const s = await t.connections.list(a, c);
867
+ if (!n || a === n)
865
868
  return s;
866
869
  const i = await t.connections.list(n), p = s.connections.map((o) => {
867
870
  var d;
868
- const c = (d = i.connections) == null ? void 0 : d.find(
871
+ const l = (d = i.connections) == null ? void 0 : d.find(
869
872
  (m) => m.name === o.name
870
873
  );
871
- if (!(c != null && c.options))
874
+ if (!(l != null && l.options))
872
875
  return o;
873
876
  const u = G.parse({
874
- ...c,
877
+ ...l,
875
878
  ...o
876
879
  });
877
880
  return u.options = K.parse({
878
- ...c.options || {},
881
+ ...l.options || {},
879
882
  ...o.options
880
883
  }), u;
881
884
  });
@@ -894,49 +897,49 @@ function ne(t, e) {
894
897
  // They remain part of ...baseAdapters and can be properly wrapped by caching.
895
898
  };
896
899
  }
897
- function Pe(t, e) {
898
- return ne(t, e);
900
+ function Ie(t, e) {
901
+ return te(t, e);
899
902
  }
900
- const Ne = ne, Ue = Pe;
901
- function De(t) {
903
+ const Me = te, Ne = Ie;
904
+ function Pe(t) {
902
905
  return async (e, n) => {
903
906
  if (!t.accessControl)
904
907
  return n();
905
- const a = e.var.tenant_id, r = e.var.organization_id;
906
- if (!a)
908
+ const r = e.var.tenant_id, a = e.var.organization_id;
909
+ if (!r)
907
910
  throw new S(400, {
908
911
  message: "Tenant ID not found in request"
909
912
  });
910
- if (!we(
911
- r,
913
+ if (!fe(
912
914
  a,
915
+ r,
913
916
  t.accessControl.controlPlaneTenantId
914
917
  ))
915
918
  throw new S(403, {
916
- message: `Access denied to tenant ${a}`
919
+ message: `Access denied to tenant ${r}`
917
920
  });
918
921
  return n();
919
922
  };
920
923
  }
921
- function $e(t) {
924
+ function De(t) {
922
925
  return async (e, n) => {
923
926
  if (!t.subdomainRouting)
924
927
  return n();
925
928
  const {
926
- baseDomain: a,
927
- reservedSubdomains: r = [],
928
- resolveSubdomain: l
929
+ baseDomain: r,
930
+ reservedSubdomains: a = [],
931
+ resolveSubdomain: c
929
932
  } = t.subdomainRouting, s = e.req.header("host") || "";
930
933
  let i = null;
931
- if (s.endsWith(a)) {
932
- const o = s.slice(0, -(a.length + 1));
934
+ if (s.endsWith(r)) {
935
+ const o = s.slice(0, -(r.length + 1));
933
936
  o && !o.includes(".") && (i = o);
934
937
  }
935
- if (i && r.includes(i) && (i = null), !i)
938
+ if (i && a.includes(i) && (i = null), !i)
936
939
  return t.accessControl && e.set("tenant_id", t.accessControl.controlPlaneTenantId), n();
937
940
  let p = null;
938
- if (l)
939
- p = await l(i);
941
+ if (c)
942
+ p = await c(i);
940
943
  else if (t.subdomainRouting.useOrganizations !== !1 && t.accessControl)
941
944
  try {
942
945
  const o = await e.env.data.organizations.get(
@@ -953,22 +956,22 @@ function $e(t) {
953
956
  return e.set("tenant_id", p), n();
954
957
  };
955
958
  }
956
- function ze(t) {
959
+ function $e(t) {
957
960
  return async (e, n) => {
958
961
  if (!t.databaseIsolation)
959
962
  return n();
960
- const a = e.var.tenant_id;
961
- if (!a)
963
+ const r = e.var.tenant_id;
964
+ if (!r)
962
965
  throw new S(400, {
963
966
  message: "Tenant ID not found in request"
964
967
  });
965
968
  try {
966
- const r = await t.databaseIsolation.getAdapters(a);
967
- e.env.data = r;
968
- } catch (r) {
969
+ const a = await t.databaseIsolation.getAdapters(r);
970
+ e.env.data = a;
971
+ } catch (a) {
969
972
  throw console.error(
970
- `Failed to resolve database for tenant ${a}:`,
971
- r
973
+ `Failed to resolve database for tenant ${r}:`,
974
+ a
972
975
  ), new S(500, {
973
976
  message: "Failed to resolve tenant database"
974
977
  });
@@ -976,19 +979,19 @@ function ze(t) {
976
979
  return n();
977
980
  };
978
981
  }
979
- function re(t) {
980
- const e = $e(t), n = De(t), a = ze(t);
981
- return async (r, l) => (await e(r, async () => {
982
- }), await n(r, async () => {
983
- }), await a(r, async () => {
984
- }), l());
982
+ function ne(t) {
983
+ const e = De(t), n = Pe(t), r = $e(t);
984
+ return async (a, c) => (await e(a, async () => {
985
+ }), await n(a, async () => {
986
+ }), await r(a, async () => {
987
+ }), c());
985
988
  }
986
- function Be(t) {
989
+ function Ue(t) {
987
990
  const e = j(t);
988
991
  return {
989
992
  name: "multi-tenancy",
990
993
  // Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
991
- middleware: re(t),
994
+ middleware: ne(t),
992
995
  // Provide lifecycle hooks
993
996
  hooks: e,
994
997
  // Mount tenant management routes
@@ -1009,42 +1012,42 @@ function Be(t) {
1009
1012
  };
1010
1013
  }
1011
1014
  function j(t) {
1012
- const e = t.accessControl ? fe(t.accessControl) : {}, n = t.databaseIsolation ? ge(t.databaseIsolation) : {}, a = he(t);
1015
+ const e = t.accessControl ? pe(t.accessControl) : {}, n = t.databaseIsolation ? we(t.databaseIsolation) : {}, r = ge(t);
1013
1016
  return {
1014
1017
  ...e,
1015
1018
  ...n,
1016
- tenants: a
1019
+ tenants: r
1017
1020
  };
1018
1021
  }
1019
- function Oe(t) {
1020
- const e = new te(), n = j(t);
1022
+ function ze(t) {
1023
+ const e = new ee(), n = j(t);
1021
1024
  return e.route("/tenants", W(t, n)), e;
1022
1025
  }
1023
- function Ge(t) {
1026
+ function Be(t) {
1024
1027
  return {
1025
1028
  hooks: j(t),
1026
- middleware: re(t),
1027
- app: Oe(t),
1029
+ middleware: ne(t),
1030
+ app: ze(t),
1028
1031
  config: t
1029
1032
  };
1030
1033
  }
1031
- function Ke(t) {
1032
- var A, $, b, y, C, P, q, R, D, Q, J, X, Y, Z, E;
1034
+ function Ge(t) {
1035
+ var A, $, b, y, C, P, q, R, D, Q, J, X, Y, Z;
1033
1036
  const {
1034
1037
  controlPlaneTenantId: e = "control_plane",
1035
1038
  sync: n,
1036
- multiTenancy: a,
1037
- entityHooks: r,
1038
- ...l
1039
+ multiTenancy: r,
1040
+ entityHooks: a,
1041
+ ...c
1039
1042
  } = t, s = {
1040
- ...a,
1043
+ ...r,
1041
1044
  accessControl: {
1042
1045
  controlPlaneTenantId: e,
1043
1046
  requireOrganizationMatch: !1,
1044
1047
  defaultPermissions: ["tenant:admin"],
1045
- ...a == null ? void 0 : a.accessControl
1048
+ ...r == null ? void 0 : r.accessControl
1046
1049
  }
1047
- }, i = j(s), p = ((A = a == null ? void 0 : a.databaseIsolation) == null ? void 0 : A.getAdapters) ?? (async () => t.dataAdapter), { entityHooks: o, tenantHooks: c } = Ce({
1050
+ }, i = j(s), p = ((A = r == null ? void 0 : r.databaseIsolation) == null ? void 0 : A.getAdapters) ?? (async () => t.dataAdapter), { entityHooks: o, tenantHooks: l } = be({
1048
1051
  controlPlaneTenantId: e,
1049
1052
  getChildTenantIds: async () => (await F(
1050
1053
  (T) => t.dataAdapter.tenants.list(T),
@@ -1057,11 +1060,11 @@ function Ke(t) {
1057
1060
  });
1058
1061
  function u(I, T) {
1059
1062
  if (!(!I && !T))
1060
- return I ? T ? async (...ae) => {
1063
+ return I ? T ? async (...re) => {
1061
1064
  const O = [];
1062
1065
  for (const M of [I, T])
1063
1066
  try {
1064
- await M(...ae);
1067
+ await M(...re);
1065
1068
  } catch (N) {
1066
1069
  O.push(N instanceof Error ? N : new Error(String(N)));
1067
1070
  }
@@ -1074,92 +1077,88 @@ function Ke(t) {
1074
1077
  } : I : T;
1075
1078
  }
1076
1079
  const d = {
1077
- ...r,
1080
+ ...a,
1078
1081
  resourceServers: o != null && o.resourceServers ? {
1079
- ...r == null ? void 0 : r.resourceServers,
1082
+ ...a == null ? void 0 : a.resourceServers,
1080
1083
  afterCreate: u(
1081
- ($ = r == null ? void 0 : r.resourceServers) == null ? void 0 : $.afterCreate,
1084
+ ($ = a == null ? void 0 : a.resourceServers) == null ? void 0 : $.afterCreate,
1082
1085
  o.resourceServers.afterCreate
1083
1086
  ),
1084
1087
  afterUpdate: u(
1085
- (b = r == null ? void 0 : r.resourceServers) == null ? void 0 : b.afterUpdate,
1088
+ (b = a == null ? void 0 : a.resourceServers) == null ? void 0 : b.afterUpdate,
1086
1089
  o.resourceServers.afterUpdate
1087
1090
  ),
1088
1091
  beforeDelete: u(
1089
- (y = r == null ? void 0 : r.resourceServers) == null ? void 0 : y.beforeDelete,
1092
+ (y = a == null ? void 0 : a.resourceServers) == null ? void 0 : y.beforeDelete,
1090
1093
  o.resourceServers.beforeDelete
1091
1094
  ),
1092
1095
  afterDelete: u(
1093
- (C = r == null ? void 0 : r.resourceServers) == null ? void 0 : C.afterDelete,
1096
+ (C = a == null ? void 0 : a.resourceServers) == null ? void 0 : C.afterDelete,
1094
1097
  o.resourceServers.afterDelete
1095
1098
  )
1096
- } : r == null ? void 0 : r.resourceServers,
1099
+ } : a == null ? void 0 : a.resourceServers,
1097
1100
  roles: o != null && o.roles ? {
1098
- ...r == null ? void 0 : r.roles,
1101
+ ...a == null ? void 0 : a.roles,
1099
1102
  afterCreate: u(
1100
- (P = r == null ? void 0 : r.roles) == null ? void 0 : P.afterCreate,
1103
+ (P = a == null ? void 0 : a.roles) == null ? void 0 : P.afterCreate,
1101
1104
  o.roles.afterCreate
1102
1105
  ),
1103
1106
  afterUpdate: u(
1104
- (q = r == null ? void 0 : r.roles) == null ? void 0 : q.afterUpdate,
1107
+ (q = a == null ? void 0 : a.roles) == null ? void 0 : q.afterUpdate,
1105
1108
  o.roles.afterUpdate
1106
1109
  ),
1107
1110
  beforeDelete: u(
1108
- (R = r == null ? void 0 : r.roles) == null ? void 0 : R.beforeDelete,
1111
+ (R = a == null ? void 0 : a.roles) == null ? void 0 : R.beforeDelete,
1109
1112
  o.roles.beforeDelete
1110
1113
  ),
1111
1114
  afterDelete: u(
1112
- (D = r == null ? void 0 : r.roles) == null ? void 0 : D.afterDelete,
1115
+ (D = a == null ? void 0 : a.roles) == null ? void 0 : D.afterDelete,
1113
1116
  o.roles.afterDelete
1114
1117
  )
1115
- } : r == null ? void 0 : r.roles,
1118
+ } : a == null ? void 0 : a.roles,
1116
1119
  connections: o != null && o.connections ? {
1117
- ...r == null ? void 0 : r.connections,
1120
+ ...a == null ? void 0 : a.connections,
1118
1121
  afterCreate: u(
1119
- (Q = r == null ? void 0 : r.connections) == null ? void 0 : Q.afterCreate,
1122
+ (Q = a == null ? void 0 : a.connections) == null ? void 0 : Q.afterCreate,
1120
1123
  o.connections.afterCreate
1121
1124
  ),
1122
1125
  afterUpdate: u(
1123
- (J = r == null ? void 0 : r.connections) == null ? void 0 : J.afterUpdate,
1126
+ (J = a == null ? void 0 : a.connections) == null ? void 0 : J.afterUpdate,
1124
1127
  o.connections.afterUpdate
1125
1128
  ),
1126
1129
  beforeDelete: u(
1127
- (X = r == null ? void 0 : r.connections) == null ? void 0 : X.beforeDelete,
1130
+ (X = a == null ? void 0 : a.connections) == null ? void 0 : X.beforeDelete,
1128
1131
  o.connections.beforeDelete
1129
1132
  ),
1130
1133
  afterDelete: u(
1131
- (Y = r == null ? void 0 : r.connections) == null ? void 0 : Y.afterDelete,
1134
+ (Y = a == null ? void 0 : a.connections) == null ? void 0 : Y.afterDelete,
1132
1135
  o.connections.afterDelete
1133
1136
  )
1134
- } : r == null ? void 0 : r.connections,
1135
- tenants: c ? {
1136
- ...r == null ? void 0 : r.tenants,
1137
- afterCreate: u(
1138
- (Z = r == null ? void 0 : r.tenants) == null ? void 0 : Z.afterCreate,
1139
- c.afterCreate
1140
- )
1141
- } : r == null ? void 0 : r.tenants
1137
+ } : a == null ? void 0 : a.connections,
1138
+ // Note: tenant sync hooks are only attached to combinedTenantHooks (for router use)
1139
+ // to avoid duplicate execution. The entityHooks.tenants doesn't need the sync hook.
1140
+ tenants: a == null ? void 0 : a.tenants
1142
1141
  }, m = {
1143
1142
  ...i,
1144
- tenants: c ? {
1143
+ tenants: l ? {
1145
1144
  ...i.tenants,
1146
1145
  afterCreate: u(
1147
- (E = i.tenants) == null ? void 0 : E.afterCreate,
1148
- c.afterCreate
1146
+ (Z = i.tenants) == null ? void 0 : Z.afterCreate,
1147
+ l.afterCreate
1149
1148
  )
1150
1149
  } : i.tenants
1151
1150
  }, f = W(
1152
1151
  s,
1153
1152
  m
1154
- ), w = de({
1155
- ...l,
1153
+ ), w = le({
1154
+ ...c,
1156
1155
  entityHooks: d,
1157
1156
  managementApiExtensions: [
1158
- ...l.managementApiExtensions || [],
1157
+ ...c.managementApiExtensions || [],
1159
1158
  { path: "/tenants", router: f }
1160
1159
  ]
1161
- }), { app: g, managementApp: h, ...v } = w, _ = new te();
1162
- return _.onError((I, T) => I instanceof S ? I.getResponse() : (console.error(I), T.json({ message: "Internal Server Error" }, 500))), _.use("/api/v2/*", Ie()), _.route("/", g), {
1160
+ }), { app: g, managementApp: h, ...v } = w, _ = new ee();
1161
+ return _.onError((I, T) => I instanceof S ? I.getResponse() : (console.error(I), T.json({ message: "Internal Server Error" }, 500))), _.use("/api/v2/*", Se()), _.route("/", g), {
1163
1162
  app: _,
1164
1163
  managementApp: h,
1165
1164
  ...v,
@@ -1168,24 +1167,24 @@ function Ke(t) {
1168
1167
  };
1169
1168
  }
1170
1169
  export {
1171
- fe as createAccessControlHooks,
1172
- De as createAccessControlMiddleware,
1173
- ge as createDatabaseHooks,
1174
- ze as createDatabaseMiddleware,
1175
- Oe as createMultiTenancy,
1170
+ pe as createAccessControlHooks,
1171
+ Pe as createAccessControlMiddleware,
1172
+ we as createDatabaseHooks,
1173
+ $e as createDatabaseMiddleware,
1174
+ ze as createMultiTenancy,
1176
1175
  j as createMultiTenancyHooks,
1177
- re as createMultiTenancyMiddleware,
1178
- Be as createMultiTenancyPlugin,
1179
- Ie as createProtectSyncedMiddleware,
1180
- he as createProvisioningHooks,
1181
- ne as createRuntimeFallbackAdapter,
1182
- Ne as createSettingsInheritanceAdapter,
1183
- $e as createSubdomainMiddleware,
1184
- Ce as createSyncHooks,
1176
+ ne as createMultiTenancyMiddleware,
1177
+ Ue as createMultiTenancyPlugin,
1178
+ Se as createProtectSyncedMiddleware,
1179
+ ge as createProvisioningHooks,
1180
+ te as createRuntimeFallbackAdapter,
1181
+ Me as createSettingsInheritanceAdapter,
1182
+ De as createSubdomainMiddleware,
1183
+ be as createSyncHooks,
1185
1184
  W as createTenantsOpenAPIRouter,
1186
- Ke as init,
1187
- Ge as setupMultiTenancy,
1188
- we as validateTenantAccess,
1189
- Pe as withRuntimeFallback,
1190
- Ue as withSettingsInheritance
1185
+ Ge as init,
1186
+ Be as setupMultiTenancy,
1187
+ fe as validateTenantAccess,
1188
+ Ie as withRuntimeFallback,
1189
+ Ne as withSettingsInheritance
1191
1190
  };