@authhero/multi-tenancy 14.9.0 → 14.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/multi-tenancy.cjs +1 -1
- package/dist/multi-tenancy.mjs +325 -283
- package/dist/types/hooks/resource-server-sync.d.ts +4 -0
- package/dist/types/hooks/resource-server-sync.d.ts.map +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/middleware/settings-inheritance.d.ts +2 -8
- package/dist/types/middleware/settings-inheritance.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { MANAGEMENT_API_SCOPES as
|
|
6
|
-
import { OpenAPIHono as
|
|
7
|
-
function
|
|
1
|
+
var Y = Object.defineProperty;
|
|
2
|
+
var Z = (e, t, n) => t in e ? Y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var M = (e, t, n) => Z(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { Hono as x } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as ee, MANAGEMENT_API_AUDIENCE as Q, fetchAll as z, auth0QuerySchema as te, tenantSchema as N, tenantInsertSchema as ne, connectionSchema as re, connectionOptionsSchema as se, init as ae } from "authhero";
|
|
6
|
+
import { OpenAPIHono as oe, createRoute as O, z as S } from "@hono/zod-openapi";
|
|
7
|
+
function ie(e) {
|
|
8
8
|
const { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
9
9
|
return {
|
|
10
10
|
async onTenantAccessValidation(r, s) {
|
|
11
11
|
if (s === t)
|
|
12
12
|
return !0;
|
|
13
13
|
if (n) {
|
|
14
|
-
const
|
|
15
|
-
return
|
|
14
|
+
const a = r.var.org_name, o = r.var.organization_id, i = a || o;
|
|
15
|
+
return i ? i.toLowerCase() === s.toLowerCase() : !1;
|
|
16
16
|
}
|
|
17
17
|
return !0;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function ce(e, t, n, r) {
|
|
22
22
|
if (t === n)
|
|
23
23
|
return !0;
|
|
24
24
|
const s = r || e;
|
|
25
25
|
return s ? s.toLowerCase() === t.toLowerCase() : !1;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function le(e) {
|
|
28
28
|
return {
|
|
29
29
|
async resolveDataAdapters(t) {
|
|
30
30
|
try {
|
|
@@ -39,57 +39,57 @@ function ce(e) {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function ue(e) {
|
|
43
43
|
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function de(e) {
|
|
46
46
|
return {
|
|
47
47
|
async beforeCreate(t, n) {
|
|
48
48
|
return !n.audience && n.id ? {
|
|
49
49
|
...n,
|
|
50
|
-
audience:
|
|
50
|
+
audience: ue(n.id)
|
|
51
51
|
} : n;
|
|
52
52
|
},
|
|
53
53
|
async afterCreate(t, n) {
|
|
54
54
|
const { accessControl: r, databaseIsolation: s } = e;
|
|
55
|
-
r && t.ctx && await
|
|
55
|
+
r && t.ctx && await fe(t, n, r), s != null && s.onProvision && await s.onProvision(n.id);
|
|
56
56
|
},
|
|
57
57
|
async beforeDelete(t, n) {
|
|
58
58
|
const { accessControl: r, databaseIsolation: s } = e;
|
|
59
59
|
if (r)
|
|
60
60
|
try {
|
|
61
|
-
const
|
|
61
|
+
const o = (await t.adapters.organizations.list(
|
|
62
62
|
r.controlPlaneTenantId
|
|
63
|
-
)).organizations.find((
|
|
64
|
-
|
|
63
|
+
)).organizations.find((i) => i.name === n);
|
|
64
|
+
o && await t.adapters.organizations.remove(
|
|
65
65
|
r.controlPlaneTenantId,
|
|
66
|
-
|
|
66
|
+
o.id
|
|
67
67
|
);
|
|
68
|
-
} catch (
|
|
68
|
+
} catch (a) {
|
|
69
69
|
console.warn(
|
|
70
70
|
`Failed to remove organization for tenant ${n}:`,
|
|
71
|
-
|
|
71
|
+
a
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
if (s != null && s.onDeprovision)
|
|
75
75
|
try {
|
|
76
76
|
await s.onDeprovision(n);
|
|
77
|
-
} catch (
|
|
77
|
+
} catch (a) {
|
|
78
78
|
console.warn(
|
|
79
79
|
`Failed to deprovision database for tenant ${n}:`,
|
|
80
|
-
|
|
80
|
+
a
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
async function
|
|
86
|
+
async function fe(e, t, n) {
|
|
87
87
|
const {
|
|
88
88
|
controlPlaneTenantId: r,
|
|
89
89
|
defaultPermissions: s,
|
|
90
|
-
defaultRoles:
|
|
91
|
-
issuer:
|
|
92
|
-
adminRoleName:
|
|
90
|
+
defaultRoles: a,
|
|
91
|
+
issuer: o,
|
|
92
|
+
adminRoleName: i = "Tenant Admin",
|
|
93
93
|
adminRoleDescription: u = "Full access to all tenant management operations",
|
|
94
94
|
addCreatorToOrganization: c = !0
|
|
95
95
|
} = n, l = await e.adapters.organizations.create(
|
|
@@ -100,14 +100,14 @@ async function de(e, t, n) {
|
|
|
100
100
|
}
|
|
101
101
|
);
|
|
102
102
|
let g;
|
|
103
|
-
if (
|
|
103
|
+
if (o && (g = await ge(
|
|
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
|
|
110
|
+
if (d != null && d.sub && !await me(
|
|
111
111
|
e,
|
|
112
112
|
r,
|
|
113
113
|
d.sub
|
|
@@ -130,13 +130,13 @@ async function de(e, t, n) {
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
`Would assign roles ${
|
|
133
|
+
a && a.length > 0 && console.log(
|
|
134
|
+
`Would assign roles ${a.join(", ")} to organization ${l.id}`
|
|
135
135
|
), s && s.length > 0 && console.log(
|
|
136
136
|
`Would grant permissions ${s.join(", ")} to organization ${l.id}`
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
|
-
async function
|
|
139
|
+
async function me(e, t, n) {
|
|
140
140
|
const r = await e.adapters.userRoles.list(
|
|
141
141
|
t,
|
|
142
142
|
n,
|
|
@@ -150,46 +150,46 @@ async function fe(e, t, n) {
|
|
|
150
150
|
s.id,
|
|
151
151
|
{ per_page: 1e3 }
|
|
152
152
|
)).some(
|
|
153
|
-
(
|
|
153
|
+
(i) => i.permission_name === "admin:organizations"
|
|
154
154
|
))
|
|
155
155
|
return !0;
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
|
-
async function
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
return
|
|
162
|
-
const
|
|
158
|
+
async function ge(e, t, n, r) {
|
|
159
|
+
const a = (await e.adapters.roles.list(t, {})).roles.find((c) => c.name === n);
|
|
160
|
+
if (a)
|
|
161
|
+
return a.id;
|
|
162
|
+
const o = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}),
|
|
166
|
-
role_id:
|
|
167
|
-
resource_server_identifier:
|
|
165
|
+
}), i = Q, u = ee.map((c) => ({
|
|
166
|
+
role_id: o.id,
|
|
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
|
-
|
|
172
|
+
o.id,
|
|
173
173
|
u
|
|
174
|
-
),
|
|
174
|
+
), o.id;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
const { controlPlaneTenantId: r, getChildTenantIds: s, getAdapters:
|
|
178
|
-
async function
|
|
176
|
+
function H(e, t, n = () => !0) {
|
|
177
|
+
const { controlPlaneTenantId: r, getChildTenantIds: s, getAdapters: a } = e, o = /* @__PURE__ */ new Map();
|
|
178
|
+
async function i(l, g, d) {
|
|
179
179
|
return (await t(l).list(g, {
|
|
180
180
|
q: `name:${d}`,
|
|
181
181
|
per_page: 1
|
|
182
182
|
}))[0] ?? null;
|
|
183
183
|
}
|
|
184
184
|
async function u(l) {
|
|
185
|
-
const g = await s(), d = t(await
|
|
185
|
+
const g = await s(), d = t(await a(r));
|
|
186
186
|
await Promise.all(
|
|
187
187
|
g.map(async (f) => {
|
|
188
188
|
try {
|
|
189
|
-
const m = await
|
|
189
|
+
const m = await a(f), w = t(m), p = {
|
|
190
190
|
...d.transform(l),
|
|
191
191
|
is_system: !0
|
|
192
|
-
}, y = await
|
|
192
|
+
}, y = await i(m, f, l.name), _ = y ? w.getId(y) : void 0;
|
|
193
193
|
if (y && _) {
|
|
194
194
|
const T = w.preserveOnUpdate ? w.preserveOnUpdate(y, p) : p;
|
|
195
195
|
await w.update(f, _, T);
|
|
@@ -209,7 +209,7 @@ function B(e, t, n = () => !0) {
|
|
|
209
209
|
await Promise.all(
|
|
210
210
|
g.map(async (d) => {
|
|
211
211
|
try {
|
|
212
|
-
const f = await
|
|
212
|
+
const f = await a(d), m = t(f), w = await i(f, d, l), h = w ? m.getId(w) : void 0;
|
|
213
213
|
w && h && await m.remove(d, h);
|
|
214
214
|
} catch (f) {
|
|
215
215
|
console.error(
|
|
@@ -230,22 +230,22 @@ function B(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) &&
|
|
233
|
+
f && n(f) && o.set(g, f);
|
|
234
234
|
},
|
|
235
235
|
afterDelete: async (l, g) => {
|
|
236
236
|
if (l.tenantId !== r) return;
|
|
237
|
-
const d =
|
|
238
|
-
d && (
|
|
237
|
+
const d = o.get(g);
|
|
238
|
+
d && (o.delete(g), await c(d.name));
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
const { controlPlaneTenantId: r, getControlPlaneAdapters: s, getAdapters:
|
|
242
|
+
function B(e, t, n = () => !0) {
|
|
243
|
+
const { controlPlaneTenantId: r, getControlPlaneAdapters: s, getAdapters: a } = e;
|
|
244
244
|
return {
|
|
245
|
-
async afterCreate(
|
|
246
|
-
if (
|
|
245
|
+
async afterCreate(o, i) {
|
|
246
|
+
if (i.id !== r)
|
|
247
247
|
try {
|
|
248
|
-
const u = await s(), c = await
|
|
248
|
+
const u = await s(), c = await a(i.id), l = t(u), g = t(c), d = await z(
|
|
249
249
|
(f) => l.listPaginated(r, f),
|
|
250
250
|
l.listKey,
|
|
251
251
|
{ cursorField: "id", pageSize: 100 }
|
|
@@ -254,13 +254,13 @@ function G(e, t, n = () => !0) {
|
|
|
254
254
|
d.filter((f) => n(f)).map(async (f) => {
|
|
255
255
|
try {
|
|
256
256
|
const m = l.transform(f);
|
|
257
|
-
await g.create(
|
|
257
|
+
await g.create(i.id, {
|
|
258
258
|
...m,
|
|
259
259
|
is_system: !0
|
|
260
260
|
});
|
|
261
261
|
} catch (m) {
|
|
262
262
|
console.error(
|
|
263
|
-
`Failed to sync entity to new tenant "${
|
|
263
|
+
`Failed to sync entity to new tenant "${i.id}":`,
|
|
264
264
|
m
|
|
265
265
|
);
|
|
266
266
|
}
|
|
@@ -268,14 +268,14 @@ function G(e, t, n = () => !0) {
|
|
|
268
268
|
);
|
|
269
269
|
} catch (u) {
|
|
270
270
|
console.error(
|
|
271
|
-
`Failed to sync entities to new tenant "${
|
|
271
|
+
`Failed to sync entities to new tenant "${i.id}":`,
|
|
272
272
|
u
|
|
273
273
|
);
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
|
-
const
|
|
278
|
+
const G = (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),
|
|
@@ -308,34 +308,34 @@ const L = (e) => ({
|
|
|
308
308
|
description: t.description
|
|
309
309
|
})
|
|
310
310
|
});
|
|
311
|
-
function
|
|
311
|
+
function L(e) {
|
|
312
312
|
var t;
|
|
313
313
|
return ((t = e.metadata) == null ? void 0 : t.sync) !== !1;
|
|
314
314
|
}
|
|
315
|
-
function
|
|
316
|
-
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, s = t.roles ?? !0,
|
|
315
|
+
function we(e) {
|
|
316
|
+
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, s = t.roles ?? !0, a = (m) => L(m) ? n.resourceServers ? n.resourceServers(m) : !0 : !1, o = (m) => L(m) ? n.roles ? n.roles(m) : !0 : !1, i = r ? H(
|
|
317
317
|
e,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
) : void 0, u = s ?
|
|
318
|
+
G,
|
|
319
|
+
a
|
|
320
|
+
) : void 0, u = s ? H(
|
|
321
321
|
e,
|
|
322
322
|
U,
|
|
323
|
-
i
|
|
324
|
-
) : void 0, c = r ? G(
|
|
325
|
-
e,
|
|
326
|
-
L,
|
|
327
323
|
o
|
|
328
|
-
) : void 0,
|
|
324
|
+
) : void 0, c = r ? B(
|
|
325
|
+
e,
|
|
326
|
+
G,
|
|
327
|
+
a
|
|
328
|
+
) : void 0, l = s ? B(
|
|
329
329
|
e,
|
|
330
330
|
U,
|
|
331
|
-
|
|
331
|
+
o
|
|
332
332
|
) : void 0, g = s ? {
|
|
333
333
|
async afterCreate(m, w) {
|
|
334
334
|
var h;
|
|
335
335
|
if (w.id !== e.controlPlaneTenantId) {
|
|
336
336
|
await ((h = l == null ? void 0 : l.afterCreate) == null ? void 0 : h.call(l, m, w));
|
|
337
337
|
try {
|
|
338
|
-
const p = await e.getControlPlaneAdapters(), y = await e.getAdapters(w.id), _ = await
|
|
338
|
+
const p = await e.getControlPlaneAdapters(), y = await e.getAdapters(w.id), _ = await z(
|
|
339
339
|
(C) => p.roles.list(
|
|
340
340
|
e.controlPlaneTenantId,
|
|
341
341
|
C
|
|
@@ -403,7 +403,7 @@ function ge(e) {
|
|
|
403
403
|
}
|
|
404
404
|
return {
|
|
405
405
|
entityHooks: {
|
|
406
|
-
resourceServers:
|
|
406
|
+
resourceServers: i,
|
|
407
407
|
roles: u
|
|
408
408
|
},
|
|
409
409
|
tenantHooks: {
|
|
@@ -437,8 +437,8 @@ var b = class extends Error {
|
|
|
437
437
|
*/
|
|
438
438
|
constructor(t = 500, n) {
|
|
439
439
|
super(n == null ? void 0 : n.message, { cause: n == null ? void 0 : n.cause });
|
|
440
|
-
|
|
441
|
-
|
|
440
|
+
M(this, "res");
|
|
441
|
+
M(this, "status");
|
|
442
442
|
this.res = n == null ? void 0 : n.res, this.status = t;
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
@@ -455,15 +455,15 @@ var b = class extends Error {
|
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
};
|
|
458
|
-
function
|
|
459
|
-
const n = new
|
|
458
|
+
function q(e, t) {
|
|
459
|
+
const n = new oe();
|
|
460
460
|
return n.openapi(
|
|
461
|
-
|
|
461
|
+
O({
|
|
462
462
|
tags: ["tenants"],
|
|
463
463
|
method: "get",
|
|
464
464
|
path: "/",
|
|
465
465
|
request: {
|
|
466
|
-
query:
|
|
466
|
+
query: te
|
|
467
467
|
},
|
|
468
468
|
security: [
|
|
469
469
|
{
|
|
@@ -475,7 +475,7 @@ function j(e, t) {
|
|
|
475
475
|
content: {
|
|
476
476
|
"application/json": {
|
|
477
477
|
schema: S.object({
|
|
478
|
-
tenants: S.array(
|
|
478
|
+
tenants: S.array(N),
|
|
479
479
|
start: S.number().optional(),
|
|
480
480
|
limit: S.number().optional(),
|
|
481
481
|
length: S.number().optional()
|
|
@@ -488,74 +488,74 @@ function j(e, t) {
|
|
|
488
488
|
}),
|
|
489
489
|
async (r) => {
|
|
490
490
|
var m, w, h, p, y, _;
|
|
491
|
-
const s = r.req.valid("query"), { page:
|
|
491
|
+
const s = r.req.valid("query"), { page: a, per_page: o, include_totals: i, q: u } = s, c = r.var.user, l = (c == null ? void 0 : c.permissions) || [];
|
|
492
492
|
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
493
493
|
const T = await r.env.data.tenants.list({
|
|
494
|
-
page:
|
|
495
|
-
per_page:
|
|
496
|
-
include_totals:
|
|
494
|
+
page: a,
|
|
495
|
+
per_page: o,
|
|
496
|
+
include_totals: i,
|
|
497
497
|
q: u
|
|
498
498
|
});
|
|
499
|
-
return
|
|
499
|
+
return i ? r.json({
|
|
500
500
|
tenants: T.tenants,
|
|
501
501
|
start: ((m = T.totals) == null ? void 0 : m.start) ?? 0,
|
|
502
|
-
limit: ((w = T.totals) == null ? void 0 : w.limit) ??
|
|
502
|
+
limit: ((w = T.totals) == null ? void 0 : w.limit) ?? o,
|
|
503
503
|
length: T.tenants.length
|
|
504
504
|
}) : r.json({ tenants: T.tenants });
|
|
505
505
|
}
|
|
506
506
|
const d = ((h = e.accessControl) == null ? void 0 : h.controlPlaneTenantId) ?? ((p = r.env.data.multiTenancyConfig) == null ? void 0 : p.controlPlaneTenantId);
|
|
507
507
|
if (d && (c != null && c.sub)) {
|
|
508
|
-
const C = (await
|
|
509
|
-
(
|
|
508
|
+
const C = (await z(
|
|
509
|
+
($) => r.env.data.userOrganizations.listUserOrganizations(
|
|
510
510
|
d,
|
|
511
511
|
c.sub,
|
|
512
|
-
|
|
512
|
+
$
|
|
513
513
|
),
|
|
514
514
|
"organizations"
|
|
515
|
-
)).map((
|
|
515
|
+
)).map(($) => $.name);
|
|
516
516
|
if (C.length === 0)
|
|
517
|
-
return
|
|
517
|
+
return i ? r.json({
|
|
518
518
|
tenants: [],
|
|
519
519
|
start: 0,
|
|
520
|
-
limit:
|
|
520
|
+
limit: o ?? 50,
|
|
521
521
|
length: 0
|
|
522
522
|
}) : r.json({ tenants: [] });
|
|
523
|
-
const v = C.length, P =
|
|
523
|
+
const v = C.length, P = a ?? 0, A = o ?? 50, R = P * A, I = C.slice(R, R + A);
|
|
524
524
|
if (I.length === 0)
|
|
525
|
-
return
|
|
525
|
+
return i ? r.json({
|
|
526
526
|
tenants: [],
|
|
527
|
-
start:
|
|
527
|
+
start: R,
|
|
528
528
|
limit: A,
|
|
529
529
|
length: v
|
|
530
530
|
}) : r.json({ tenants: [] });
|
|
531
|
-
const
|
|
532
|
-
q:
|
|
531
|
+
const k = I.map(($) => `id:${$}`).join(" OR "), X = u ? `(${k}) AND (${u})` : k, E = await r.env.data.tenants.list({
|
|
532
|
+
q: X,
|
|
533
533
|
per_page: A,
|
|
534
534
|
include_totals: !1
|
|
535
535
|
// We calculate totals from accessibleTenantIds
|
|
536
536
|
});
|
|
537
|
-
return
|
|
538
|
-
tenants:
|
|
539
|
-
start:
|
|
537
|
+
return i ? r.json({
|
|
538
|
+
tenants: E.tenants,
|
|
539
|
+
start: R,
|
|
540
540
|
limit: A,
|
|
541
541
|
length: v
|
|
542
|
-
}) : r.json({ tenants:
|
|
542
|
+
}) : r.json({ tenants: E.tenants });
|
|
543
543
|
}
|
|
544
544
|
const f = await r.env.data.tenants.list({
|
|
545
|
-
page:
|
|
546
|
-
per_page:
|
|
547
|
-
include_totals:
|
|
545
|
+
page: a,
|
|
546
|
+
per_page: o,
|
|
547
|
+
include_totals: i,
|
|
548
548
|
q: u
|
|
549
549
|
});
|
|
550
|
-
return
|
|
550
|
+
return i ? r.json({
|
|
551
551
|
tenants: f.tenants,
|
|
552
552
|
start: ((y = f.totals) == null ? void 0 : y.start) ?? 0,
|
|
553
|
-
limit: ((_ = f.totals) == null ? void 0 : _.limit) ??
|
|
553
|
+
limit: ((_ = f.totals) == null ? void 0 : _.limit) ?? o,
|
|
554
554
|
length: f.tenants.length
|
|
555
555
|
}) : r.json({ tenants: f.tenants });
|
|
556
556
|
}
|
|
557
557
|
), n.openapi(
|
|
558
|
-
|
|
558
|
+
O({
|
|
559
559
|
tags: ["tenants"],
|
|
560
560
|
method: "post",
|
|
561
561
|
path: "/",
|
|
@@ -563,7 +563,7 @@ function j(e, t) {
|
|
|
563
563
|
body: {
|
|
564
564
|
content: {
|
|
565
565
|
"application/json": {
|
|
566
|
-
schema:
|
|
566
|
+
schema: ne
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
}
|
|
@@ -577,7 +577,7 @@ function j(e, t) {
|
|
|
577
577
|
201: {
|
|
578
578
|
content: {
|
|
579
579
|
"application/json": {
|
|
580
|
-
schema:
|
|
580
|
+
schema: N
|
|
581
581
|
}
|
|
582
582
|
},
|
|
583
583
|
description: "Tenant created"
|
|
@@ -597,17 +597,17 @@ function j(e, t) {
|
|
|
597
597
|
throw new b(401, {
|
|
598
598
|
message: "Authentication required to create tenants"
|
|
599
599
|
});
|
|
600
|
-
let
|
|
601
|
-
const
|
|
600
|
+
let a = r.req.valid("json");
|
|
601
|
+
const o = {
|
|
602
602
|
adapters: r.env.data,
|
|
603
603
|
ctx: r
|
|
604
604
|
};
|
|
605
|
-
(u = t.tenants) != null && u.beforeCreate && (
|
|
606
|
-
const
|
|
607
|
-
return (c = t.tenants) != null && c.afterCreate && await t.tenants.afterCreate(
|
|
605
|
+
(u = t.tenants) != null && u.beforeCreate && (a = await t.tenants.beforeCreate(o, a));
|
|
606
|
+
const i = await r.env.data.tenants.create(a);
|
|
607
|
+
return (c = t.tenants) != null && c.afterCreate && await t.tenants.afterCreate(o, i), r.json(i, 201);
|
|
608
608
|
}
|
|
609
609
|
), n.openapi(
|
|
610
|
-
|
|
610
|
+
O({
|
|
611
611
|
tags: ["tenants"],
|
|
612
612
|
method: "delete",
|
|
613
613
|
path: "/{id}",
|
|
@@ -635,20 +635,20 @@ function j(e, t) {
|
|
|
635
635
|
}),
|
|
636
636
|
async (r) => {
|
|
637
637
|
var u, c, l, g;
|
|
638
|
-
const { id: s } = r.req.valid("param"),
|
|
639
|
-
if (
|
|
638
|
+
const { id: s } = r.req.valid("param"), a = ((u = e.accessControl) == null ? void 0 : u.controlPlaneTenantId) ?? ((c = r.env.data.multiTenancyConfig) == null ? void 0 : c.controlPlaneTenantId);
|
|
639
|
+
if (a) {
|
|
640
640
|
const d = r.var.user;
|
|
641
641
|
if (!(d != null && d.sub))
|
|
642
642
|
throw new b(401, {
|
|
643
643
|
message: "Authentication required"
|
|
644
644
|
});
|
|
645
|
-
if (s ===
|
|
645
|
+
if (s === a)
|
|
646
646
|
throw new b(403, {
|
|
647
647
|
message: "Cannot delete the control plane"
|
|
648
648
|
});
|
|
649
|
-
if (!(await
|
|
649
|
+
if (!(await z(
|
|
650
650
|
(w) => r.env.data.userOrganizations.listUserOrganizations(
|
|
651
|
-
|
|
651
|
+
a,
|
|
652
652
|
d.sub,
|
|
653
653
|
w
|
|
654
654
|
),
|
|
@@ -662,15 +662,15 @@ function j(e, t) {
|
|
|
662
662
|
throw new b(404, {
|
|
663
663
|
message: "Tenant not found"
|
|
664
664
|
});
|
|
665
|
-
const
|
|
665
|
+
const i = {
|
|
666
666
|
adapters: r.env.data,
|
|
667
667
|
ctx: r
|
|
668
668
|
};
|
|
669
|
-
return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(
|
|
669
|
+
return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(i, s), await r.env.data.tenants.remove(s), (g = t.tenants) != null && g.afterDelete && await t.tenants.afterDelete(i, s), r.body(null, 204);
|
|
670
670
|
}
|
|
671
671
|
), n;
|
|
672
672
|
}
|
|
673
|
-
function
|
|
673
|
+
function pe(e) {
|
|
674
674
|
const t = [
|
|
675
675
|
{
|
|
676
676
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -686,7 +686,7 @@ function we(e) {
|
|
|
686
686
|
}
|
|
687
687
|
return null;
|
|
688
688
|
}
|
|
689
|
-
async function
|
|
689
|
+
async function ye(e, t, n) {
|
|
690
690
|
try {
|
|
691
691
|
switch (n.type) {
|
|
692
692
|
case "resource_server": {
|
|
@@ -708,88 +708,93 @@ async function pe(e, t, n) {
|
|
|
708
708
|
return !1;
|
|
709
709
|
}
|
|
710
710
|
}
|
|
711
|
-
function
|
|
711
|
+
function he(e) {
|
|
712
712
|
return {
|
|
713
713
|
resource_server: "resource server",
|
|
714
714
|
role: "role",
|
|
715
715
|
connection: "connection"
|
|
716
716
|
}[e];
|
|
717
717
|
}
|
|
718
|
-
function
|
|
718
|
+
function ve() {
|
|
719
719
|
return async (e, t) => {
|
|
720
720
|
if (!["PATCH", "PUT", "DELETE"].includes(e.req.method))
|
|
721
721
|
return t();
|
|
722
|
-
const n =
|
|
722
|
+
const n = pe(e.req.path);
|
|
723
723
|
if (!n)
|
|
724
724
|
return t();
|
|
725
725
|
const r = e.var.tenant_id || e.req.header("x-tenant-id") || e.req.header("tenant-id");
|
|
726
726
|
if (!r)
|
|
727
727
|
return t();
|
|
728
|
-
if (await
|
|
728
|
+
if (await ye(e.env.data, r, n))
|
|
729
729
|
throw new b(403, {
|
|
730
|
-
message: `This ${
|
|
730
|
+
message: `This ${he(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
731
731
|
});
|
|
732
732
|
return t();
|
|
733
733
|
};
|
|
734
734
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
"twilio_token"
|
|
739
|
-
];
|
|
740
|
-
function _e(e) {
|
|
741
|
-
if (!e) return e;
|
|
742
|
-
const t = { ...e };
|
|
743
|
-
for (const n of ve)
|
|
744
|
-
delete t[n];
|
|
745
|
-
return t;
|
|
746
|
-
}
|
|
747
|
-
function M(e, t, n) {
|
|
748
|
-
const r = t.find(
|
|
749
|
-
(i) => i.strategy === e.strategy
|
|
735
|
+
function D(e, t) {
|
|
736
|
+
const n = t.find(
|
|
737
|
+
(s) => s.strategy === e.strategy
|
|
750
738
|
);
|
|
751
|
-
if (!(
|
|
739
|
+
if (!(n != null && n.options))
|
|
752
740
|
return e;
|
|
753
|
-
const
|
|
754
|
-
...
|
|
741
|
+
const r = re.passthrough().parse({
|
|
742
|
+
...n,
|
|
755
743
|
...e
|
|
756
|
-
})
|
|
757
|
-
return
|
|
758
|
-
...
|
|
744
|
+
});
|
|
745
|
+
return r.options = se.passthrough().parse({
|
|
746
|
+
...n.options || {},
|
|
759
747
|
...e.options
|
|
760
|
-
}),
|
|
748
|
+
}), r;
|
|
761
749
|
}
|
|
762
|
-
function
|
|
750
|
+
function F(e, t) {
|
|
763
751
|
const n = [
|
|
764
752
|
...t || [],
|
|
765
753
|
...e || []
|
|
766
754
|
];
|
|
767
755
|
return [...new Set(n)];
|
|
768
756
|
}
|
|
757
|
+
function _e(e, t) {
|
|
758
|
+
if (!(t != null && t.length))
|
|
759
|
+
return e || [];
|
|
760
|
+
if (!(e != null && e.length))
|
|
761
|
+
return t;
|
|
762
|
+
const n = /* @__PURE__ */ new Map();
|
|
763
|
+
for (const r of t)
|
|
764
|
+
n.set(r.value, r);
|
|
765
|
+
for (const r of e)
|
|
766
|
+
n.set(r.value, r);
|
|
767
|
+
return Array.from(n.values());
|
|
768
|
+
}
|
|
769
|
+
function W(e, t) {
|
|
770
|
+
return t ? {
|
|
771
|
+
...e,
|
|
772
|
+
scopes: _e(
|
|
773
|
+
e.scopes,
|
|
774
|
+
t.scopes
|
|
775
|
+
)
|
|
776
|
+
} : e;
|
|
777
|
+
}
|
|
769
778
|
function K(e, t) {
|
|
770
779
|
return t ? {
|
|
771
780
|
...e,
|
|
772
|
-
callbacks:
|
|
773
|
-
web_origins:
|
|
781
|
+
callbacks: F(e.callbacks, t.callbacks),
|
|
782
|
+
web_origins: F(
|
|
774
783
|
e.web_origins,
|
|
775
784
|
t.web_origins
|
|
776
785
|
),
|
|
777
|
-
allowed_logout_urls:
|
|
786
|
+
allowed_logout_urls: F(
|
|
778
787
|
e.allowed_logout_urls,
|
|
779
788
|
t.allowed_logout_urls
|
|
780
789
|
),
|
|
781
|
-
allowed_origins:
|
|
790
|
+
allowed_origins: F(
|
|
782
791
|
e.allowed_origins,
|
|
783
792
|
t.allowed_origins
|
|
784
793
|
)
|
|
785
794
|
} : e;
|
|
786
795
|
}
|
|
787
796
|
function Te(e, t) {
|
|
788
|
-
const {
|
|
789
|
-
controlPlaneTenantId: n,
|
|
790
|
-
controlPlaneClientId: r,
|
|
791
|
-
excludeSensitiveFields: s = !1
|
|
792
|
-
} = t;
|
|
797
|
+
const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
|
|
793
798
|
return {
|
|
794
799
|
...e,
|
|
795
800
|
// Store config for use by tenants route access control
|
|
@@ -799,91 +804,126 @@ function Te(e, t) {
|
|
|
799
804
|
},
|
|
800
805
|
connections: {
|
|
801
806
|
...e.connections,
|
|
802
|
-
get: async (
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
|
|
807
|
+
get: async (s, a) => {
|
|
808
|
+
const o = await e.connections.get(
|
|
809
|
+
s,
|
|
810
|
+
a
|
|
806
811
|
);
|
|
807
|
-
if (!
|
|
808
|
-
return
|
|
809
|
-
const
|
|
810
|
-
return
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
s
|
|
812
|
+
if (!o || !n || s === n)
|
|
813
|
+
return o;
|
|
814
|
+
const i = await e.connections.list(n);
|
|
815
|
+
return D(
|
|
816
|
+
o,
|
|
817
|
+
i.connections || []
|
|
814
818
|
);
|
|
815
819
|
},
|
|
816
|
-
list: async (
|
|
817
|
-
const
|
|
818
|
-
if (!n ||
|
|
819
|
-
return
|
|
820
|
-
const
|
|
821
|
-
(
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
s
|
|
820
|
+
list: async (s, a) => {
|
|
821
|
+
const o = await e.connections.list(s, a);
|
|
822
|
+
if (!n || s === n)
|
|
823
|
+
return o;
|
|
824
|
+
const i = await e.connections.list(n), u = o.connections.map(
|
|
825
|
+
(c) => D(
|
|
826
|
+
c,
|
|
827
|
+
i.connections || []
|
|
825
828
|
)
|
|
826
829
|
);
|
|
827
830
|
return {
|
|
828
|
-
...
|
|
829
|
-
connections:
|
|
831
|
+
...o,
|
|
832
|
+
connections: u
|
|
830
833
|
};
|
|
831
834
|
}
|
|
832
835
|
},
|
|
833
836
|
clientConnections: {
|
|
834
837
|
...e.clientConnections,
|
|
835
|
-
listByClient: async (
|
|
836
|
-
let
|
|
837
|
-
|
|
838
|
-
|
|
838
|
+
listByClient: async (s, a) => {
|
|
839
|
+
let o = await e.clientConnections.listByClient(
|
|
840
|
+
s,
|
|
841
|
+
a
|
|
839
842
|
);
|
|
840
|
-
if (
|
|
841
|
-
return
|
|
842
|
-
const
|
|
843
|
-
return
|
|
844
|
-
(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
s
|
|
843
|
+
if (o.length === 0 && (o = (await e.connections.list(s)).connections || []), !n || s === n)
|
|
844
|
+
return o;
|
|
845
|
+
const i = await e.connections.list(n);
|
|
846
|
+
return o.map(
|
|
847
|
+
(u) => D(
|
|
848
|
+
u,
|
|
849
|
+
i.connections || []
|
|
848
850
|
)
|
|
849
851
|
);
|
|
850
852
|
}
|
|
851
853
|
},
|
|
852
854
|
clients: {
|
|
853
855
|
...e.clients,
|
|
854
|
-
get: async (
|
|
855
|
-
const
|
|
856
|
-
if (!
|
|
856
|
+
get: async (s, a) => {
|
|
857
|
+
const o = await e.clients.get(s, a);
|
|
858
|
+
if (!o)
|
|
857
859
|
return null;
|
|
858
|
-
if (!n || !r ||
|
|
859
|
-
return
|
|
860
|
-
const
|
|
860
|
+
if (!n || !r || s === n && a === r)
|
|
861
|
+
return o;
|
|
862
|
+
const i = await e.clients.get(
|
|
861
863
|
n,
|
|
862
864
|
r
|
|
863
865
|
);
|
|
864
|
-
return K(
|
|
866
|
+
return K(o, i);
|
|
865
867
|
},
|
|
866
|
-
getByClientId: async (
|
|
867
|
-
const
|
|
868
|
-
if (!
|
|
868
|
+
getByClientId: async (s) => {
|
|
869
|
+
const a = await e.clients.getByClientId(s);
|
|
870
|
+
if (!a)
|
|
869
871
|
return null;
|
|
870
|
-
if (!n || !r ||
|
|
871
|
-
return
|
|
872
|
-
const
|
|
872
|
+
if (!n || !r || a.tenant_id === n && a.client_id === r)
|
|
873
|
+
return a;
|
|
874
|
+
const o = await e.clients.get(
|
|
873
875
|
n,
|
|
874
876
|
r
|
|
875
877
|
);
|
|
876
878
|
return {
|
|
877
|
-
...K(
|
|
878
|
-
tenant_id:
|
|
879
|
+
...K(a, o),
|
|
880
|
+
tenant_id: a.tenant_id
|
|
879
881
|
};
|
|
880
882
|
}
|
|
881
883
|
},
|
|
882
884
|
emailProviders: {
|
|
883
885
|
...e.emailProviders,
|
|
884
|
-
get: async (
|
|
885
|
-
const
|
|
886
|
-
return
|
|
886
|
+
get: async (s) => {
|
|
887
|
+
const a = await e.emailProviders.get(s);
|
|
888
|
+
return a || (!n || s === n ? null : e.emailProviders.get(n));
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
resourceServers: {
|
|
892
|
+
...e.resourceServers,
|
|
893
|
+
get: async (s, a) => {
|
|
894
|
+
const o = await e.resourceServers.get(
|
|
895
|
+
s,
|
|
896
|
+
a
|
|
897
|
+
);
|
|
898
|
+
if (!o || !n || s === n)
|
|
899
|
+
return o;
|
|
900
|
+
const u = (await e.resourceServers.list(
|
|
901
|
+
n,
|
|
902
|
+
{ q: `identifier:${o.identifier}`, per_page: 1 }
|
|
903
|
+
)).resource_servers[0] ?? null;
|
|
904
|
+
return W(
|
|
905
|
+
o,
|
|
906
|
+
u
|
|
907
|
+
);
|
|
908
|
+
},
|
|
909
|
+
list: async (s, a) => {
|
|
910
|
+
const o = await e.resourceServers.list(s, a);
|
|
911
|
+
if (!n || s === n)
|
|
912
|
+
return o;
|
|
913
|
+
const i = await e.resourceServers.list(
|
|
914
|
+
n
|
|
915
|
+
), u = new Map(
|
|
916
|
+
i.resource_servers.map((l) => [l.identifier, l])
|
|
917
|
+
), c = o.resource_servers.map(
|
|
918
|
+
(l) => W(
|
|
919
|
+
l,
|
|
920
|
+
u.get(l.identifier) ?? null
|
|
921
|
+
)
|
|
922
|
+
);
|
|
923
|
+
return {
|
|
924
|
+
...o,
|
|
925
|
+
resource_servers: c
|
|
926
|
+
};
|
|
887
927
|
}
|
|
888
928
|
}
|
|
889
929
|
// Note: Additional adapters can be extended here for runtime fallback:
|
|
@@ -891,7 +931,7 @@ function Te(e, t) {
|
|
|
891
931
|
// - branding: Fall back to control plane branding/themes
|
|
892
932
|
};
|
|
893
933
|
}
|
|
894
|
-
function
|
|
934
|
+
function V(e, t) {
|
|
895
935
|
return Te(e, t);
|
|
896
936
|
}
|
|
897
937
|
function Ce(e) {
|
|
@@ -904,21 +944,21 @@ function Pe(e) {
|
|
|
904
944
|
return async (t, n) => {
|
|
905
945
|
if (!e.accessControl)
|
|
906
946
|
return n();
|
|
907
|
-
const { controlPlaneTenantId: r } = e.accessControl, s = t.var.org_name,
|
|
908
|
-
let
|
|
909
|
-
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(
|
|
910
|
-
if (!
|
|
947
|
+
const { controlPlaneTenantId: r } = e.accessControl, s = t.var.org_name, a = t.var.organization_id, o = s || a;
|
|
948
|
+
let i = t.var.tenant_id;
|
|
949
|
+
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(Q);
|
|
950
|
+
if (!i && o && l && (t.set("tenant_id", o), i = o), !i)
|
|
911
951
|
throw new b(400, {
|
|
912
952
|
message: "Tenant ID not found in request"
|
|
913
953
|
});
|
|
914
|
-
if (!
|
|
915
|
-
o,
|
|
954
|
+
if (!ce(
|
|
916
955
|
a,
|
|
956
|
+
i,
|
|
917
957
|
r,
|
|
918
958
|
s
|
|
919
959
|
))
|
|
920
960
|
throw new b(403, {
|
|
921
|
-
message: `Access denied to tenant ${
|
|
961
|
+
message: `Access denied to tenant ${i}`
|
|
922
962
|
});
|
|
923
963
|
return n();
|
|
924
964
|
};
|
|
@@ -930,30 +970,30 @@ function Ae(e) {
|
|
|
930
970
|
const {
|
|
931
971
|
baseDomain: r,
|
|
932
972
|
reservedSubdomains: s = [],
|
|
933
|
-
resolveSubdomain:
|
|
934
|
-
} = e.subdomainRouting,
|
|
935
|
-
let
|
|
936
|
-
if (
|
|
937
|
-
const c =
|
|
938
|
-
c && !c.includes(".") && (
|
|
973
|
+
resolveSubdomain: a
|
|
974
|
+
} = e.subdomainRouting, o = t.req.header("host") || "";
|
|
975
|
+
let i = null;
|
|
976
|
+
if (o.endsWith(r)) {
|
|
977
|
+
const c = o.slice(0, -(r.length + 1));
|
|
978
|
+
c && !c.includes(".") && (i = c);
|
|
939
979
|
}
|
|
940
|
-
if (
|
|
980
|
+
if (i && s.includes(i) && (i = null), !i)
|
|
941
981
|
return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
942
982
|
let u = null;
|
|
943
|
-
if (
|
|
944
|
-
u = await
|
|
983
|
+
if (a)
|
|
984
|
+
u = await a(i);
|
|
945
985
|
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
|
|
946
986
|
try {
|
|
947
987
|
const c = await t.env.data.organizations.get(
|
|
948
988
|
e.accessControl.controlPlaneTenantId,
|
|
949
|
-
|
|
989
|
+
i
|
|
950
990
|
);
|
|
951
991
|
c && (u = c.id);
|
|
952
992
|
} catch {
|
|
953
993
|
}
|
|
954
994
|
if (!u)
|
|
955
995
|
throw new b(404, {
|
|
956
|
-
message: `Tenant not found for subdomain: ${
|
|
996
|
+
message: `Tenant not found for subdomain: ${i}`
|
|
957
997
|
});
|
|
958
998
|
return t.set("tenant_id", u), n();
|
|
959
999
|
};
|
|
@@ -981,14 +1021,14 @@ function be(e) {
|
|
|
981
1021
|
return n();
|
|
982
1022
|
};
|
|
983
1023
|
}
|
|
984
|
-
function
|
|
1024
|
+
function J(e) {
|
|
985
1025
|
const t = Ae(e), n = Pe(e), r = be(e);
|
|
986
|
-
return async (s,
|
|
1026
|
+
return async (s, a) => (await t(s, async () => {
|
|
987
1027
|
}), await n(s, async () => {
|
|
988
1028
|
}), await r(s, async () => {
|
|
989
|
-
}),
|
|
1029
|
+
}), a());
|
|
990
1030
|
}
|
|
991
|
-
function
|
|
1031
|
+
function Fe(e) {
|
|
992
1032
|
const {
|
|
993
1033
|
dataAdapter: t,
|
|
994
1034
|
controlPlane: n,
|
|
@@ -996,9 +1036,9 @@ function Oe(e) {
|
|
|
996
1036
|
tenantId: r = "control_plane",
|
|
997
1037
|
clientId: s
|
|
998
1038
|
} = {},
|
|
999
|
-
sync:
|
|
1000
|
-
defaultPermissions:
|
|
1001
|
-
requireOrganizationMatch:
|
|
1039
|
+
sync: a = { resourceServers: !0, roles: !0 },
|
|
1040
|
+
defaultPermissions: o = ["tenant:admin"],
|
|
1041
|
+
requireOrganizationMatch: i = !1,
|
|
1002
1042
|
managementApiExtensions: u = [],
|
|
1003
1043
|
entityHooks: c,
|
|
1004
1044
|
getChildTenantIds: l,
|
|
@@ -1006,20 +1046,22 @@ function Oe(e) {
|
|
|
1006
1046
|
...d
|
|
1007
1047
|
} = e;
|
|
1008
1048
|
let f = t, m = t;
|
|
1009
|
-
n && (f =
|
|
1049
|
+
n && (f = V(t, {
|
|
1010
1050
|
controlPlaneTenantId: r,
|
|
1011
1051
|
controlPlaneClientId: s
|
|
1012
|
-
}), m =
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1052
|
+
}), m = {
|
|
1053
|
+
...t,
|
|
1054
|
+
multiTenancyConfig: {
|
|
1055
|
+
controlPlaneTenantId: r,
|
|
1056
|
+
controlPlaneClientId: s
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
const w = a !== !1, h = w ? {
|
|
1060
|
+
resourceServers: a.resourceServers ?? !0,
|
|
1061
|
+
roles: a.roles ?? !0
|
|
1020
1062
|
} : { resourceServers: !1, roles: !1 }, _ = {
|
|
1021
1063
|
controlPlaneTenantId: r,
|
|
1022
|
-
getChildTenantIds: l ?? (async () => (await
|
|
1064
|
+
getChildTenantIds: l ?? (async () => (await z(
|
|
1023
1065
|
(I) => f.tenants.list(I),
|
|
1024
1066
|
"tenants",
|
|
1025
1067
|
{ cursorField: "id", pageSize: 100 }
|
|
@@ -1027,7 +1069,7 @@ function Oe(e) {
|
|
|
1027
1069
|
getAdapters: g ?? (async () => f),
|
|
1028
1070
|
getControlPlaneAdapters: async () => f,
|
|
1029
1071
|
sync: h
|
|
1030
|
-
}, { entityHooks: T, tenantHooks: C } =
|
|
1072
|
+
}, { entityHooks: T, tenantHooks: C } = we(_), v = {
|
|
1031
1073
|
resourceServers: [
|
|
1032
1074
|
T.resourceServers,
|
|
1033
1075
|
...(c == null ? void 0 : c.resourceServers) ?? []
|
|
@@ -1036,12 +1078,12 @@ function Oe(e) {
|
|
|
1036
1078
|
connections: (c == null ? void 0 : c.connections) ?? [],
|
|
1037
1079
|
tenants: (c == null ? void 0 : c.tenants) ?? [],
|
|
1038
1080
|
rolePermissions: (c == null ? void 0 : c.rolePermissions) ?? []
|
|
1039
|
-
}, P =
|
|
1081
|
+
}, P = q(
|
|
1040
1082
|
{
|
|
1041
1083
|
accessControl: {
|
|
1042
1084
|
controlPlaneTenantId: r,
|
|
1043
|
-
requireOrganizationMatch:
|
|
1044
|
-
defaultPermissions:
|
|
1085
|
+
requireOrganizationMatch: i,
|
|
1086
|
+
defaultPermissions: o
|
|
1045
1087
|
}
|
|
1046
1088
|
},
|
|
1047
1089
|
{ tenants: C }
|
|
@@ -1055,21 +1097,21 @@ function Oe(e) {
|
|
|
1055
1097
|
{ path: "/tenants", router: P }
|
|
1056
1098
|
]
|
|
1057
1099
|
});
|
|
1058
|
-
return A.use("/api/v2/*", Ce(r)), w && A.use("/api/v2/*",
|
|
1100
|
+
return A.use("/api/v2/*", Ce(r)), w && A.use("/api/v2/*", ve()), { app: A, controlPlaneTenantId: r };
|
|
1059
1101
|
}
|
|
1060
|
-
function
|
|
1061
|
-
const t =
|
|
1102
|
+
function Me(e) {
|
|
1103
|
+
const t = j(e);
|
|
1062
1104
|
return {
|
|
1063
1105
|
name: "multi-tenancy",
|
|
1064
1106
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1065
|
-
middleware:
|
|
1107
|
+
middleware: J(e),
|
|
1066
1108
|
// Provide lifecycle hooks
|
|
1067
1109
|
hooks: t,
|
|
1068
1110
|
// Mount tenant management routes
|
|
1069
1111
|
routes: [
|
|
1070
1112
|
{
|
|
1071
1113
|
path: "/management",
|
|
1072
|
-
handler:
|
|
1114
|
+
handler: q(e, t)
|
|
1073
1115
|
}
|
|
1074
1116
|
],
|
|
1075
1117
|
// Called when plugin is registered
|
|
@@ -1082,8 +1124,8 @@ function Re(e) {
|
|
|
1082
1124
|
}
|
|
1083
1125
|
};
|
|
1084
1126
|
}
|
|
1085
|
-
function
|
|
1086
|
-
const t = e.accessControl ?
|
|
1127
|
+
function j(e) {
|
|
1128
|
+
const t = e.accessControl ? ie(e.accessControl) : {}, n = e.databaseIsolation ? le(e.databaseIsolation) : {}, r = de(e);
|
|
1087
1129
|
return {
|
|
1088
1130
|
...t,
|
|
1089
1131
|
...n,
|
|
@@ -1091,13 +1133,13 @@ function k(e) {
|
|
|
1091
1133
|
};
|
|
1092
1134
|
}
|
|
1093
1135
|
function Ie(e) {
|
|
1094
|
-
const t = new
|
|
1095
|
-
return t.route("/tenants",
|
|
1136
|
+
const t = new x(), n = j(e);
|
|
1137
|
+
return t.route("/tenants", q(e, n)), t;
|
|
1096
1138
|
}
|
|
1097
|
-
function
|
|
1139
|
+
function Oe(e) {
|
|
1098
1140
|
return {
|
|
1099
|
-
hooks:
|
|
1100
|
-
middleware:
|
|
1141
|
+
hooks: j(e),
|
|
1142
|
+
middleware: J(e),
|
|
1101
1143
|
app: Ie(e),
|
|
1102
1144
|
config: e,
|
|
1103
1145
|
/**
|
|
@@ -1110,7 +1152,7 @@ function De(e) {
|
|
|
1110
1152
|
*/
|
|
1111
1153
|
wrapAdapters: (t, n) => {
|
|
1112
1154
|
var r;
|
|
1113
|
-
return
|
|
1155
|
+
return V(t, {
|
|
1114
1156
|
controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
|
|
1115
1157
|
controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
|
|
1116
1158
|
});
|
|
@@ -1118,23 +1160,23 @@ function De(e) {
|
|
|
1118
1160
|
};
|
|
1119
1161
|
}
|
|
1120
1162
|
export {
|
|
1121
|
-
|
|
1163
|
+
ie as createAccessControlHooks,
|
|
1122
1164
|
Pe as createAccessControlMiddleware,
|
|
1123
1165
|
Ce as createControlPlaneTenantMiddleware,
|
|
1124
|
-
|
|
1166
|
+
le as createDatabaseHooks,
|
|
1125
1167
|
be as createDatabaseMiddleware,
|
|
1126
1168
|
Ie as createMultiTenancy,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1169
|
+
j as createMultiTenancyHooks,
|
|
1170
|
+
J as createMultiTenancyMiddleware,
|
|
1171
|
+
Me as createMultiTenancyPlugin,
|
|
1172
|
+
ve as createProtectSyncedMiddleware,
|
|
1173
|
+
de as createProvisioningHooks,
|
|
1132
1174
|
Te as createRuntimeFallbackAdapter,
|
|
1133
1175
|
Ae as createSubdomainMiddleware,
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1176
|
+
we as createSyncHooks,
|
|
1177
|
+
q as createTenantsOpenAPIRouter,
|
|
1178
|
+
Fe as initMultiTenant,
|
|
1179
|
+
Oe as setupMultiTenancy,
|
|
1180
|
+
ce as validateTenantAccess,
|
|
1181
|
+
V as withRuntimeFallback
|
|
1140
1182
|
};
|