@authhero/multi-tenancy 14.19.0 → 14.20.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 +306 -281
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/middleware/index.d.ts +1 -1
- package/dist/types/middleware/index.d.ts.map +1 -1
- package/dist/types/middleware/settings-inheritance.d.ts +12 -2
- 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 E = (e, t, n) =>
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { MANAGEMENT_API_SCOPES as
|
|
6
|
-
import { OpenAPIHono as
|
|
7
|
-
function
|
|
1
|
+
var ee = Object.defineProperty;
|
|
2
|
+
var te = (e, t, n) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var E = (e, t, n) => te(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { Hono as ne } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as re, MANAGEMENT_API_AUDIENCE as J, fetchAll as D, auth0QuerySchema as ae, tenantSchema as q, tenantInsertSchema as U, deepMergePatch as se, connectionSchema as oe, connectionOptionsSchema as ie, init as ce } from "authhero";
|
|
6
|
+
import { OpenAPIHono as le, createRoute as M, z as I } from "@hono/zod-openapi";
|
|
7
|
+
function ue(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
|
|
14
|
+
const s = r.var.org_name, c = r.var.organization_id, i = s || c;
|
|
15
15
|
return i ? i.toLowerCase() === a.toLowerCase() : !1;
|
|
16
16
|
}
|
|
17
17
|
return !0;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function de(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
|
|
27
|
+
function fe(e) {
|
|
28
28
|
return {
|
|
29
29
|
async resolveDataAdapters(t) {
|
|
30
30
|
try {
|
|
@@ -39,7 +39,7 @@ function de(e) {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function me(e) {
|
|
43
43
|
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
44
44
|
}
|
|
45
45
|
function X(e) {
|
|
@@ -47,51 +47,51 @@ function X(e) {
|
|
|
47
47
|
async beforeCreate(t, n) {
|
|
48
48
|
return !n.audience && n.id ? {
|
|
49
49
|
...n,
|
|
50
|
-
audience:
|
|
50
|
+
audience: me(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
|
|
55
|
+
r && t.ctx && await ge(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
|
|
61
|
+
const c = (await t.adapters.organizations.list(
|
|
62
62
|
r.controlPlaneTenantId
|
|
63
63
|
)).organizations.find((i) => i.name === n);
|
|
64
|
-
|
|
64
|
+
c && await t.adapters.organizations.remove(
|
|
65
65
|
r.controlPlaneTenantId,
|
|
66
|
-
|
|
66
|
+
c.id
|
|
67
67
|
);
|
|
68
|
-
} catch (
|
|
68
|
+
} catch (s) {
|
|
69
69
|
console.warn(
|
|
70
70
|
`Failed to remove organization for tenant ${n}:`,
|
|
71
|
-
|
|
71
|
+
s
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
if (a != null && a.onDeprovision)
|
|
75
75
|
try {
|
|
76
76
|
await a.onDeprovision(n);
|
|
77
|
-
} catch (
|
|
77
|
+
} catch (s) {
|
|
78
78
|
console.warn(
|
|
79
79
|
`Failed to deprovision database for tenant ${n}:`,
|
|
80
|
-
|
|
80
|
+
s
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
async function
|
|
86
|
+
async function ge(e, t, n) {
|
|
87
87
|
const {
|
|
88
88
|
controlPlaneTenantId: r,
|
|
89
89
|
defaultPermissions: a,
|
|
90
|
-
defaultRoles:
|
|
91
|
-
issuer:
|
|
90
|
+
defaultRoles: s,
|
|
91
|
+
issuer: c,
|
|
92
92
|
adminRoleName: i = "Tenant Admin",
|
|
93
93
|
adminRoleDescription: u = "Full access to all tenant management operations",
|
|
94
|
-
addCreatorToOrganization:
|
|
94
|
+
addCreatorToOrganization: o = !0
|
|
95
95
|
} = n, l = await e.adapters.organizations.create(
|
|
96
96
|
r,
|
|
97
97
|
{
|
|
@@ -100,14 +100,14 @@ async function me(e, t, n) {
|
|
|
100
100
|
}
|
|
101
101
|
);
|
|
102
102
|
let g;
|
|
103
|
-
if (
|
|
103
|
+
if (c && (g = await pe(
|
|
104
104
|
e,
|
|
105
105
|
r,
|
|
106
106
|
i,
|
|
107
107
|
u
|
|
108
|
-
)),
|
|
108
|
+
)), o && e.ctx) {
|
|
109
109
|
const d = e.ctx.var.user;
|
|
110
|
-
if (d != null && d.sub && !await
|
|
110
|
+
if (d != null && d.sub && !await we(
|
|
111
111
|
e,
|
|
112
112
|
r,
|
|
113
113
|
d.sub
|
|
@@ -130,13 +130,13 @@ async function me(e, t, n) {
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
`Would assign roles ${
|
|
133
|
+
s && s.length > 0 && console.log(
|
|
134
|
+
`Would assign roles ${s.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
|
|
139
|
+
async function we(e, t, n) {
|
|
140
140
|
const r = await e.adapters.userRoles.list(
|
|
141
141
|
t,
|
|
142
142
|
n,
|
|
@@ -155,26 +155,26 @@ async function ge(e, t, n) {
|
|
|
155
155
|
return !0;
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
|
-
async function
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
return
|
|
162
|
-
const
|
|
158
|
+
async function pe(e, t, n, r) {
|
|
159
|
+
const s = (await e.adapters.roles.list(t, {})).roles.find((o) => o.name === n);
|
|
160
|
+
if (s)
|
|
161
|
+
return s.id;
|
|
162
|
+
const c = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}), i = J, u =
|
|
166
|
-
role_id:
|
|
165
|
+
}), i = J, u = re.map((o) => ({
|
|
166
|
+
role_id: c.id,
|
|
167
167
|
resource_server_identifier: i,
|
|
168
|
-
permission_name:
|
|
168
|
+
permission_name: o.value
|
|
169
169
|
}));
|
|
170
170
|
return await e.adapters.rolePermissions.assign(
|
|
171
171
|
t,
|
|
172
|
-
|
|
172
|
+
c.id,
|
|
173
173
|
u
|
|
174
|
-
),
|
|
174
|
+
), c.id;
|
|
175
175
|
}
|
|
176
176
|
function G(e, t, n = () => !0) {
|
|
177
|
-
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters:
|
|
177
|
+
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e, c = /* @__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,11 +182,11 @@ 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
|
|
185
|
+
const g = await a(), d = t(await s(r));
|
|
186
186
|
await Promise.all(
|
|
187
187
|
g.map(async (f) => {
|
|
188
188
|
try {
|
|
189
|
-
const m = await
|
|
189
|
+
const m = await s(f), w = t(m), y = {
|
|
190
190
|
...d.transform(l),
|
|
191
191
|
is_system: !0
|
|
192
192
|
}, _ = await i(m, f, l.name), b = _ ? w.getId(_) : void 0;
|
|
@@ -204,12 +204,12 @@ function G(e, t, n = () => !0) {
|
|
|
204
204
|
})
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
|
-
async function
|
|
207
|
+
async function o(l) {
|
|
208
208
|
const g = await a();
|
|
209
209
|
await Promise.all(
|
|
210
210
|
g.map(async (d) => {
|
|
211
211
|
try {
|
|
212
|
-
const f = await
|
|
212
|
+
const f = await s(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) &&
|
|
233
|
+
f && n(f) && c.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 = c.get(g);
|
|
238
|
+
d && (c.delete(g), await o(d.name));
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
242
|
function L(e, t, n = () => !0) {
|
|
243
|
-
const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters:
|
|
243
|
+
const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: s } = e;
|
|
244
244
|
return {
|
|
245
|
-
async afterCreate(
|
|
245
|
+
async afterCreate(c, i) {
|
|
246
246
|
if (i.id !== r)
|
|
247
247
|
try {
|
|
248
|
-
const u = await a(),
|
|
248
|
+
const u = await a(), o = await s(i.id), l = t(u), g = t(o), 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 L(e, t, n = () => !0) {
|
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
|
-
const
|
|
278
|
+
const W = (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 H = (e) => ({
|
|
|
293
293
|
token_lifetime: t.token_lifetime,
|
|
294
294
|
token_lifetime_for_web: t.token_lifetime_for_web
|
|
295
295
|
})
|
|
296
|
-
}),
|
|
296
|
+
}), H = (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),
|
|
@@ -312,26 +312,26 @@ function K(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, a = t.roles ?? !0,
|
|
317
|
-
e,
|
|
318
|
-
H,
|
|
319
|
-
o
|
|
320
|
-
) : void 0, u = a ? G(e, W, s) : void 0, c = r ? L(
|
|
315
|
+
function he(e) {
|
|
316
|
+
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, a = t.roles ?? !0, s = (m) => K(m) ? n.resourceServers ? n.resourceServers(m) : !0 : !1, c = (m) => K(m) ? n.roles ? n.roles(m) : !0 : !1, i = r ? G(
|
|
321
317
|
e,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
) : void 0,
|
|
318
|
+
W,
|
|
319
|
+
s
|
|
320
|
+
) : void 0, u = a ? G(e, H, c) : void 0, o = r ? L(
|
|
325
321
|
e,
|
|
326
322
|
W,
|
|
327
323
|
s
|
|
324
|
+
) : void 0, l = a ? L(
|
|
325
|
+
e,
|
|
326
|
+
H,
|
|
327
|
+
c
|
|
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 y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), b = await
|
|
334
|
+
const y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), b = await D(
|
|
335
335
|
(p) => y.roles.list(
|
|
336
336
|
e.controlPlaneTenantId,
|
|
337
337
|
p
|
|
@@ -369,10 +369,10 @@ function pe(e) {
|
|
|
369
369
|
h.length > 0 && await _.rolePermissions.assign(
|
|
370
370
|
w.id,
|
|
371
371
|
T,
|
|
372
|
-
h.map((
|
|
372
|
+
h.map((z) => ({
|
|
373
373
|
role_id: T,
|
|
374
|
-
resource_server_identifier:
|
|
375
|
-
permission_name:
|
|
374
|
+
resource_server_identifier: z.resource_server_identifier,
|
|
375
|
+
permission_name: z.permission_name
|
|
376
376
|
}))
|
|
377
377
|
);
|
|
378
378
|
} catch (h) {
|
|
@@ -405,7 +405,7 @@ function pe(e) {
|
|
|
405
405
|
tenantHooks: {
|
|
406
406
|
async afterCreate(m, w) {
|
|
407
407
|
const C = [
|
|
408
|
-
|
|
408
|
+
o == null ? void 0 : o.afterCreate,
|
|
409
409
|
(g == null ? void 0 : g.afterCreate) ?? (l == null ? void 0 : l.afterCreate)
|
|
410
410
|
], y = [];
|
|
411
411
|
for (const _ of C)
|
|
@@ -452,14 +452,14 @@ var A = class extends Error {
|
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
454
|
function N(e, t) {
|
|
455
|
-
const n = new
|
|
455
|
+
const n = new le();
|
|
456
456
|
return n.openapi(
|
|
457
457
|
M({
|
|
458
458
|
tags: ["tenants"],
|
|
459
459
|
method: "get",
|
|
460
460
|
path: "/",
|
|
461
461
|
request: {
|
|
462
|
-
query:
|
|
462
|
+
query: ae
|
|
463
463
|
},
|
|
464
464
|
security: [
|
|
465
465
|
{
|
|
@@ -470,11 +470,11 @@ function N(e, t) {
|
|
|
470
470
|
200: {
|
|
471
471
|
content: {
|
|
472
472
|
"application/json": {
|
|
473
|
-
schema:
|
|
474
|
-
tenants:
|
|
475
|
-
start:
|
|
476
|
-
limit:
|
|
477
|
-
length:
|
|
473
|
+
schema: I.object({
|
|
474
|
+
tenants: I.array(q),
|
|
475
|
+
start: I.number().optional(),
|
|
476
|
+
limit: I.number().optional(),
|
|
477
|
+
length: I.number().optional()
|
|
478
478
|
})
|
|
479
479
|
}
|
|
480
480
|
},
|
|
@@ -484,27 +484,27 @@ function N(e, t) {
|
|
|
484
484
|
}),
|
|
485
485
|
async (r) => {
|
|
486
486
|
var m, w, C, y, _, b;
|
|
487
|
-
const a = r.req.valid("query"), { page:
|
|
487
|
+
const a = r.req.valid("query"), { page: s, per_page: c, include_totals: i, q: u } = a, o = r.var.user, l = (o == null ? void 0 : o.permissions) || [];
|
|
488
488
|
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
489
489
|
const P = await r.env.data.tenants.list({
|
|
490
|
-
page:
|
|
491
|
-
per_page:
|
|
490
|
+
page: s,
|
|
491
|
+
per_page: c,
|
|
492
492
|
include_totals: i,
|
|
493
493
|
q: u
|
|
494
494
|
});
|
|
495
495
|
return i ? r.json({
|
|
496
496
|
tenants: P.tenants,
|
|
497
497
|
start: ((m = P.totals) == null ? void 0 : m.start) ?? 0,
|
|
498
|
-
limit: ((w = P.totals) == null ? void 0 : w.limit) ??
|
|
498
|
+
limit: ((w = P.totals) == null ? void 0 : w.limit) ?? c,
|
|
499
499
|
length: P.tenants.length
|
|
500
500
|
}) : r.json({ tenants: P.tenants });
|
|
501
501
|
}
|
|
502
502
|
const d = ((C = e.accessControl) == null ? void 0 : C.controlPlaneTenantId) ?? ((y = r.env.data.multiTenancyConfig) == null ? void 0 : y.controlPlaneTenantId);
|
|
503
|
-
if (d && (
|
|
504
|
-
const p = (await
|
|
503
|
+
if (d && (o != null && o.sub)) {
|
|
504
|
+
const p = (await D(
|
|
505
505
|
(R) => r.env.data.userOrganizations.listUserOrganizations(
|
|
506
506
|
d,
|
|
507
|
-
|
|
507
|
+
o.sub,
|
|
508
508
|
R
|
|
509
509
|
),
|
|
510
510
|
"organizations"
|
|
@@ -513,40 +513,40 @@ function N(e, t) {
|
|
|
513
513
|
return i ? r.json({
|
|
514
514
|
tenants: [],
|
|
515
515
|
start: 0,
|
|
516
|
-
limit:
|
|
516
|
+
limit: c ?? 50,
|
|
517
517
|
length: 0
|
|
518
518
|
}) : r.json({ tenants: [] });
|
|
519
|
-
const T = p.length, h =
|
|
519
|
+
const T = p.length, h = s ?? 0, z = c ?? 50, F = h * z, j = p.slice(F, F + z);
|
|
520
520
|
if (j.length === 0)
|
|
521
521
|
return i ? r.json({
|
|
522
522
|
tenants: [],
|
|
523
523
|
start: F,
|
|
524
|
-
limit:
|
|
524
|
+
limit: z,
|
|
525
525
|
length: T
|
|
526
526
|
}) : r.json({ tenants: [] });
|
|
527
|
-
const
|
|
527
|
+
const S = j.map((R) => `id:${R}`).join(" OR "), v = u ? `(${S}) AND (${u})` : S, $ = await r.env.data.tenants.list({
|
|
528
528
|
q: v,
|
|
529
|
-
per_page:
|
|
529
|
+
per_page: z,
|
|
530
530
|
include_totals: !1
|
|
531
531
|
// We calculate totals from accessibleTenantIds
|
|
532
532
|
});
|
|
533
533
|
return i ? r.json({
|
|
534
|
-
tenants:
|
|
534
|
+
tenants: $.tenants,
|
|
535
535
|
start: F,
|
|
536
|
-
limit:
|
|
536
|
+
limit: z,
|
|
537
537
|
length: T
|
|
538
|
-
}) : r.json({ tenants:
|
|
538
|
+
}) : r.json({ tenants: $.tenants });
|
|
539
539
|
}
|
|
540
540
|
const f = await r.env.data.tenants.list({
|
|
541
|
-
page:
|
|
542
|
-
per_page:
|
|
541
|
+
page: s,
|
|
542
|
+
per_page: c,
|
|
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: ((b = f.totals) == null ? void 0 : b.limit) ??
|
|
549
|
+
limit: ((b = f.totals) == null ? void 0 : b.limit) ?? c,
|
|
550
550
|
length: f.tenants.length
|
|
551
551
|
}) : r.json({ tenants: f.tenants });
|
|
552
552
|
}
|
|
@@ -573,7 +573,7 @@ function N(e, t) {
|
|
|
573
573
|
201: {
|
|
574
574
|
content: {
|
|
575
575
|
"application/json": {
|
|
576
|
-
schema:
|
|
576
|
+
schema: q
|
|
577
577
|
}
|
|
578
578
|
},
|
|
579
579
|
description: "Tenant created"
|
|
@@ -587,20 +587,20 @@ function N(e, t) {
|
|
|
587
587
|
}
|
|
588
588
|
}),
|
|
589
589
|
async (r) => {
|
|
590
|
-
var u,
|
|
590
|
+
var u, o;
|
|
591
591
|
const a = r.var.user;
|
|
592
592
|
if (!(a != null && a.sub))
|
|
593
593
|
throw new A(401, {
|
|
594
594
|
message: "Authentication required to create tenants"
|
|
595
595
|
});
|
|
596
|
-
let
|
|
597
|
-
const
|
|
596
|
+
let s = r.req.valid("json");
|
|
597
|
+
const c = {
|
|
598
598
|
adapters: r.env.data,
|
|
599
599
|
ctx: r
|
|
600
600
|
};
|
|
601
|
-
(u = t.tenants) != null && u.beforeCreate && (
|
|
602
|
-
const i = await r.env.data.tenants.create(
|
|
603
|
-
return (
|
|
601
|
+
(u = t.tenants) != null && u.beforeCreate && (s = await t.tenants.beforeCreate(c, s));
|
|
602
|
+
const i = await r.env.data.tenants.create(s);
|
|
603
|
+
return (o = t.tenants) != null && o.afterCreate && await t.tenants.afterCreate(c, i), r.json(i, 201);
|
|
604
604
|
}
|
|
605
605
|
), n.openapi(
|
|
606
606
|
M({
|
|
@@ -608,8 +608,8 @@ function N(e, t) {
|
|
|
608
608
|
method: "delete",
|
|
609
609
|
path: "/{id}",
|
|
610
610
|
request: {
|
|
611
|
-
params:
|
|
612
|
-
id:
|
|
611
|
+
params: I.object({
|
|
612
|
+
id: I.string()
|
|
613
613
|
})
|
|
614
614
|
},
|
|
615
615
|
security: [
|
|
@@ -630,21 +630,21 @@ function N(e, t) {
|
|
|
630
630
|
}
|
|
631
631
|
}),
|
|
632
632
|
async (r) => {
|
|
633
|
-
var u,
|
|
634
|
-
const { id: a } = r.req.valid("param"),
|
|
635
|
-
if (
|
|
633
|
+
var u, o, l, g;
|
|
634
|
+
const { id: a } = r.req.valid("param"), s = ((u = e.accessControl) == null ? void 0 : u.controlPlaneTenantId) ?? ((o = r.env.data.multiTenancyConfig) == null ? void 0 : o.controlPlaneTenantId);
|
|
635
|
+
if (s) {
|
|
636
636
|
const d = r.var.user;
|
|
637
637
|
if (!(d != null && d.sub))
|
|
638
638
|
throw new A(401, {
|
|
639
639
|
message: "Authentication required"
|
|
640
640
|
});
|
|
641
|
-
if (a ===
|
|
641
|
+
if (a === s)
|
|
642
642
|
throw new A(403, {
|
|
643
643
|
message: "Cannot delete the control plane"
|
|
644
644
|
});
|
|
645
|
-
if (!(await
|
|
645
|
+
if (!(await D(
|
|
646
646
|
(w) => r.env.data.userOrganizations.listUserOrganizations(
|
|
647
|
-
|
|
647
|
+
s,
|
|
648
648
|
d.sub,
|
|
649
649
|
w
|
|
650
650
|
),
|
|
@@ -670,8 +670,8 @@ function N(e, t) {
|
|
|
670
670
|
method: "get",
|
|
671
671
|
path: "/settings",
|
|
672
672
|
request: {
|
|
673
|
-
headers:
|
|
674
|
-
"tenant-id":
|
|
673
|
+
headers: I.object({
|
|
674
|
+
"tenant-id": I.string().optional()
|
|
675
675
|
})
|
|
676
676
|
},
|
|
677
677
|
security: [
|
|
@@ -683,7 +683,7 @@ function N(e, t) {
|
|
|
683
683
|
200: {
|
|
684
684
|
content: {
|
|
685
685
|
"application/json": {
|
|
686
|
-
schema:
|
|
686
|
+
schema: q
|
|
687
687
|
}
|
|
688
688
|
},
|
|
689
689
|
description: "Current tenant settings"
|
|
@@ -704,13 +704,13 @@ function N(e, t) {
|
|
|
704
704
|
method: "patch",
|
|
705
705
|
path: "/settings",
|
|
706
706
|
request: {
|
|
707
|
-
headers:
|
|
708
|
-
"tenant-id":
|
|
707
|
+
headers: I.object({
|
|
708
|
+
"tenant-id": I.string().optional()
|
|
709
709
|
}),
|
|
710
710
|
body: {
|
|
711
711
|
content: {
|
|
712
712
|
"application/json": {
|
|
713
|
-
schema:
|
|
713
|
+
schema: I.object(U.shape).partial()
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
}
|
|
@@ -724,7 +724,7 @@ function N(e, t) {
|
|
|
724
724
|
200: {
|
|
725
725
|
content: {
|
|
726
726
|
"application/json": {
|
|
727
|
-
schema:
|
|
727
|
+
schema: q
|
|
728
728
|
}
|
|
729
729
|
},
|
|
730
730
|
description: "Updated tenant settings"
|
|
@@ -732,23 +732,23 @@ function N(e, t) {
|
|
|
732
732
|
}
|
|
733
733
|
}),
|
|
734
734
|
async (r) => {
|
|
735
|
-
const a = r.req.valid("json"), { id:
|
|
735
|
+
const a = r.req.valid("json"), { id: s, ...c } = a, i = await r.env.data.tenants.get(r.var.tenant_id);
|
|
736
736
|
if (!i)
|
|
737
737
|
throw new A(404, {
|
|
738
738
|
message: "Tenant not found"
|
|
739
739
|
});
|
|
740
|
-
const u =
|
|
740
|
+
const u = se(i, c);
|
|
741
741
|
await r.env.data.tenants.update(r.var.tenant_id, u);
|
|
742
|
-
const
|
|
743
|
-
if (!
|
|
742
|
+
const o = await r.env.data.tenants.get(r.var.tenant_id);
|
|
743
|
+
if (!o)
|
|
744
744
|
throw new A(500, {
|
|
745
745
|
message: "Failed to retrieve updated tenant"
|
|
746
746
|
});
|
|
747
|
-
return r.json(
|
|
747
|
+
return r.json(o);
|
|
748
748
|
}
|
|
749
749
|
), n;
|
|
750
750
|
}
|
|
751
|
-
function
|
|
751
|
+
function ye(e) {
|
|
752
752
|
const t = [
|
|
753
753
|
{
|
|
754
754
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -764,7 +764,7 @@ function he(e) {
|
|
|
764
764
|
}
|
|
765
765
|
return null;
|
|
766
766
|
}
|
|
767
|
-
async function
|
|
767
|
+
async function ve(e, t, n) {
|
|
768
768
|
try {
|
|
769
769
|
switch (n.type) {
|
|
770
770
|
case "resource_server": {
|
|
@@ -786,26 +786,26 @@ async function ye(e, t, n) {
|
|
|
786
786
|
return !1;
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
|
-
function
|
|
789
|
+
function _e(e) {
|
|
790
790
|
return {
|
|
791
791
|
resource_server: "resource server",
|
|
792
792
|
role: "role",
|
|
793
793
|
connection: "connection"
|
|
794
794
|
}[e];
|
|
795
795
|
}
|
|
796
|
-
function
|
|
796
|
+
function Ce() {
|
|
797
797
|
return async (e, t) => {
|
|
798
798
|
if (!["PATCH", "PUT", "DELETE"].includes(e.req.method))
|
|
799
799
|
return t();
|
|
800
|
-
const n =
|
|
800
|
+
const n = ye(e.req.path);
|
|
801
801
|
if (!n)
|
|
802
802
|
return t();
|
|
803
803
|
const r = e.var.tenant_id || e.req.header("x-tenant-id") || e.req.header("tenant-id");
|
|
804
804
|
if (!r)
|
|
805
805
|
return t();
|
|
806
|
-
if (await
|
|
806
|
+
if (await ve(e.env.data, r, n))
|
|
807
807
|
throw new A(403, {
|
|
808
|
-
message: `This ${
|
|
808
|
+
message: `This ${_e(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
809
809
|
});
|
|
810
810
|
return t();
|
|
811
811
|
};
|
|
@@ -816,11 +816,11 @@ function k(e, t) {
|
|
|
816
816
|
);
|
|
817
817
|
if (!(n != null && n.options))
|
|
818
818
|
return e;
|
|
819
|
-
const r =
|
|
819
|
+
const r = oe.passthrough().parse({
|
|
820
820
|
...n,
|
|
821
821
|
...e
|
|
822
822
|
});
|
|
823
|
-
return r.options =
|
|
823
|
+
return r.options = ie.passthrough().parse({
|
|
824
824
|
...n.options || {},
|
|
825
825
|
...e.options
|
|
826
826
|
}), r;
|
|
@@ -829,7 +829,7 @@ function O(e, t) {
|
|
|
829
829
|
const n = [...t || [], ...e || []];
|
|
830
830
|
return [...new Set(n)];
|
|
831
831
|
}
|
|
832
|
-
function
|
|
832
|
+
function Te(e, t) {
|
|
833
833
|
if (!(t != null && t.length))
|
|
834
834
|
return e || [];
|
|
835
835
|
if (!(e != null && e.length))
|
|
@@ -844,7 +844,7 @@ function Ce(e, t) {
|
|
|
844
844
|
function Q(e, t) {
|
|
845
845
|
return t ? {
|
|
846
846
|
...e,
|
|
847
|
-
scopes:
|
|
847
|
+
scopes: Te(
|
|
848
848
|
e.scopes,
|
|
849
849
|
t.scopes
|
|
850
850
|
)
|
|
@@ -868,7 +868,64 @@ function V(e, t) {
|
|
|
868
868
|
)
|
|
869
869
|
} : e;
|
|
870
870
|
}
|
|
871
|
-
function
|
|
871
|
+
function Y(e, t) {
|
|
872
|
+
return {
|
|
873
|
+
...e.resourceServers,
|
|
874
|
+
get: async (n, r) => {
|
|
875
|
+
const a = await e.resourceServers.get(
|
|
876
|
+
n,
|
|
877
|
+
r
|
|
878
|
+
);
|
|
879
|
+
if (!a || !t || n === t || !a.is_system)
|
|
880
|
+
return a;
|
|
881
|
+
const s = await e.resourceServers.get(
|
|
882
|
+
t,
|
|
883
|
+
r
|
|
884
|
+
);
|
|
885
|
+
return Q(
|
|
886
|
+
a,
|
|
887
|
+
s
|
|
888
|
+
);
|
|
889
|
+
},
|
|
890
|
+
list: async (n, r) => {
|
|
891
|
+
const a = await e.resourceServers.list(n, r);
|
|
892
|
+
if (!t || n === t)
|
|
893
|
+
return a;
|
|
894
|
+
const s = t, c = a.resource_servers.filter(
|
|
895
|
+
(o) => !!(o.is_system && o.id)
|
|
896
|
+
).map((o) => o.id);
|
|
897
|
+
if (c.length === 0)
|
|
898
|
+
return a;
|
|
899
|
+
const i = /* @__PURE__ */ new Map();
|
|
900
|
+
await Promise.all(
|
|
901
|
+
c.map(async (o) => {
|
|
902
|
+
const l = await e.resourceServers.get(s, o);
|
|
903
|
+
l && i.set(o, l);
|
|
904
|
+
})
|
|
905
|
+
);
|
|
906
|
+
const u = a.resource_servers.map(
|
|
907
|
+
(o) => o.is_system && o.id ? Q(
|
|
908
|
+
o,
|
|
909
|
+
i.get(o.id) ?? null
|
|
910
|
+
) : o
|
|
911
|
+
);
|
|
912
|
+
return {
|
|
913
|
+
...a,
|
|
914
|
+
resource_servers: u
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
function be(e, t) {
|
|
920
|
+
return {
|
|
921
|
+
...e,
|
|
922
|
+
resourceServers: Y(
|
|
923
|
+
e,
|
|
924
|
+
t.controlPlaneTenantId
|
|
925
|
+
)
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
function Pe(e, t) {
|
|
872
929
|
const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
|
|
873
930
|
return {
|
|
874
931
|
...e,
|
|
@@ -879,46 +936,46 @@ function Te(e, t) {
|
|
|
879
936
|
},
|
|
880
937
|
connections: {
|
|
881
938
|
...e.connections,
|
|
882
|
-
get: async (a,
|
|
883
|
-
const
|
|
939
|
+
get: async (a, s) => {
|
|
940
|
+
const c = await e.connections.get(
|
|
884
941
|
a,
|
|
885
|
-
|
|
942
|
+
s
|
|
886
943
|
);
|
|
887
|
-
if (!
|
|
888
|
-
return
|
|
944
|
+
if (!c || !n || a === n)
|
|
945
|
+
return c;
|
|
889
946
|
const i = await e.connections.list(n);
|
|
890
947
|
return k(
|
|
891
|
-
|
|
948
|
+
c,
|
|
892
949
|
i.connections || []
|
|
893
950
|
);
|
|
894
951
|
},
|
|
895
|
-
list: async (a,
|
|
896
|
-
const
|
|
952
|
+
list: async (a, s) => {
|
|
953
|
+
const c = await e.connections.list(a, s);
|
|
897
954
|
if (!n || a === n)
|
|
898
|
-
return
|
|
899
|
-
const i = await e.connections.list(n), u =
|
|
900
|
-
(
|
|
901
|
-
|
|
955
|
+
return c;
|
|
956
|
+
const i = await e.connections.list(n), u = c.connections.map(
|
|
957
|
+
(o) => k(
|
|
958
|
+
o,
|
|
902
959
|
i.connections || []
|
|
903
960
|
)
|
|
904
961
|
);
|
|
905
962
|
return {
|
|
906
|
-
...
|
|
963
|
+
...c,
|
|
907
964
|
connections: u
|
|
908
965
|
};
|
|
909
966
|
}
|
|
910
967
|
},
|
|
911
968
|
clientConnections: {
|
|
912
969
|
...e.clientConnections,
|
|
913
|
-
listByClient: async (a,
|
|
914
|
-
let
|
|
970
|
+
listByClient: async (a, s) => {
|
|
971
|
+
let c = await e.clientConnections.listByClient(
|
|
915
972
|
a,
|
|
916
|
-
|
|
973
|
+
s
|
|
917
974
|
);
|
|
918
|
-
if (
|
|
919
|
-
return
|
|
975
|
+
if (c.length === 0 && (c = (await e.connections.list(a)).connections || []), !n || a === n)
|
|
976
|
+
return c;
|
|
920
977
|
const i = await e.connections.list(n);
|
|
921
|
-
return
|
|
978
|
+
return c.map(
|
|
922
979
|
(u) => k(
|
|
923
980
|
u,
|
|
924
981
|
i.connections || []
|
|
@@ -928,107 +985,72 @@ function Te(e, t) {
|
|
|
928
985
|
},
|
|
929
986
|
clients: {
|
|
930
987
|
...e.clients,
|
|
931
|
-
get: async (a,
|
|
932
|
-
const
|
|
933
|
-
if (!
|
|
988
|
+
get: async (a, s) => {
|
|
989
|
+
const c = await e.clients.get(a, s);
|
|
990
|
+
if (!c)
|
|
934
991
|
return null;
|
|
935
|
-
if (!n || !r || a === n &&
|
|
936
|
-
return
|
|
992
|
+
if (!n || !r || a === n && s === r)
|
|
993
|
+
return c;
|
|
937
994
|
const i = await e.clients.get(
|
|
938
995
|
n,
|
|
939
996
|
r
|
|
940
997
|
);
|
|
941
|
-
return V(
|
|
998
|
+
return V(c, i);
|
|
942
999
|
},
|
|
943
1000
|
getByClientId: async (a) => {
|
|
944
|
-
const
|
|
945
|
-
if (!
|
|
1001
|
+
const s = await e.clients.getByClientId(a);
|
|
1002
|
+
if (!s)
|
|
946
1003
|
return null;
|
|
947
|
-
if (!n || !r ||
|
|
948
|
-
return
|
|
949
|
-
const
|
|
1004
|
+
if (!n || !r || s.tenant_id === n && s.client_id === r)
|
|
1005
|
+
return s;
|
|
1006
|
+
const c = await e.clients.get(
|
|
950
1007
|
n,
|
|
951
1008
|
r
|
|
952
1009
|
);
|
|
953
1010
|
return {
|
|
954
|
-
...V(
|
|
955
|
-
tenant_id:
|
|
1011
|
+
...V(s, c),
|
|
1012
|
+
tenant_id: s.tenant_id
|
|
956
1013
|
};
|
|
957
1014
|
}
|
|
958
1015
|
},
|
|
959
1016
|
emailProviders: {
|
|
960
1017
|
...e.emailProviders,
|
|
961
1018
|
get: async (a) => {
|
|
962
|
-
const
|
|
963
|
-
return
|
|
1019
|
+
const s = await e.emailProviders.get(a);
|
|
1020
|
+
return s || (!n || a === n ? null : e.emailProviders.get(n));
|
|
964
1021
|
}
|
|
965
1022
|
},
|
|
966
|
-
resourceServers:
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
a,
|
|
971
|
-
o
|
|
972
|
-
);
|
|
973
|
-
if (!s || !n || a === n)
|
|
974
|
-
return s;
|
|
975
|
-
const u = (await e.resourceServers.list(
|
|
976
|
-
n,
|
|
977
|
-
{ q: `identifier:${s.identifier}`, per_page: 1 }
|
|
978
|
-
)).resource_servers[0] ?? null;
|
|
979
|
-
return Q(
|
|
980
|
-
s,
|
|
981
|
-
u
|
|
982
|
-
);
|
|
983
|
-
},
|
|
984
|
-
list: async (a, o) => {
|
|
985
|
-
const s = await e.resourceServers.list(
|
|
986
|
-
a,
|
|
987
|
-
o
|
|
988
|
-
);
|
|
989
|
-
if (!n || a === n)
|
|
990
|
-
return s;
|
|
991
|
-
const i = await e.resourceServers.list(n), u = new Map(
|
|
992
|
-
i.resource_servers.map((l) => [l.identifier, l])
|
|
993
|
-
), c = s.resource_servers.map(
|
|
994
|
-
(l) => Q(
|
|
995
|
-
l,
|
|
996
|
-
u.get(l.identifier) ?? null
|
|
997
|
-
)
|
|
998
|
-
);
|
|
999
|
-
return {
|
|
1000
|
-
...s,
|
|
1001
|
-
resource_servers: c
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1023
|
+
resourceServers: Y(
|
|
1024
|
+
e,
|
|
1025
|
+
n
|
|
1026
|
+
)
|
|
1005
1027
|
// Note: Additional adapters can be extended here for runtime fallback:
|
|
1006
1028
|
// - promptSettings: Fall back to control plane prompts
|
|
1007
1029
|
// - branding: Fall back to control plane branding/themes
|
|
1008
1030
|
};
|
|
1009
1031
|
}
|
|
1010
|
-
function
|
|
1011
|
-
return
|
|
1032
|
+
function Z(e, t) {
|
|
1033
|
+
return Pe(e, t);
|
|
1012
1034
|
}
|
|
1013
|
-
function
|
|
1035
|
+
function Ae(e) {
|
|
1014
1036
|
return async (t, n) => {
|
|
1015
1037
|
const r = t.var.user;
|
|
1016
1038
|
return (r == null ? void 0 : r.tenant_id) === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
1017
1039
|
};
|
|
1018
1040
|
}
|
|
1019
|
-
function
|
|
1041
|
+
function Se(e) {
|
|
1020
1042
|
return async (t, n) => {
|
|
1021
1043
|
if (!e.accessControl)
|
|
1022
1044
|
return n();
|
|
1023
|
-
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name,
|
|
1045
|
+
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id, c = a || s;
|
|
1024
1046
|
let i = t.var.tenant_id;
|
|
1025
1047
|
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(J);
|
|
1026
|
-
if (!i &&
|
|
1048
|
+
if (!i && c && l && (t.set("tenant_id", c), i = c), !i)
|
|
1027
1049
|
throw new A(400, {
|
|
1028
1050
|
message: "Tenant ID not found in request"
|
|
1029
1051
|
});
|
|
1030
|
-
if (!
|
|
1031
|
-
|
|
1052
|
+
if (!de(
|
|
1053
|
+
s,
|
|
1032
1054
|
i,
|
|
1033
1055
|
r,
|
|
1034
1056
|
a
|
|
@@ -1039,32 +1061,32 @@ function Pe(e) {
|
|
|
1039
1061
|
return n();
|
|
1040
1062
|
};
|
|
1041
1063
|
}
|
|
1042
|
-
function
|
|
1064
|
+
function Ie(e) {
|
|
1043
1065
|
return async (t, n) => {
|
|
1044
1066
|
if (!e.subdomainRouting)
|
|
1045
1067
|
return n();
|
|
1046
1068
|
const {
|
|
1047
1069
|
baseDomain: r,
|
|
1048
1070
|
reservedSubdomains: a = [],
|
|
1049
|
-
resolveSubdomain:
|
|
1050
|
-
} = e.subdomainRouting,
|
|
1071
|
+
resolveSubdomain: s
|
|
1072
|
+
} = e.subdomainRouting, c = t.req.header("x-forwarded-host") || t.req.header("host") || "";
|
|
1051
1073
|
let i = null;
|
|
1052
|
-
if (
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1074
|
+
if (c.endsWith(r)) {
|
|
1075
|
+
const o = c.slice(0, -(r.length + 1));
|
|
1076
|
+
o && !o.includes(".") && (i = o);
|
|
1055
1077
|
}
|
|
1056
1078
|
if (i && a.includes(i) && (i = null), !i)
|
|
1057
1079
|
return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
1058
1080
|
let u = null;
|
|
1059
|
-
if (
|
|
1060
|
-
u = await
|
|
1081
|
+
if (s)
|
|
1082
|
+
u = await s(i);
|
|
1061
1083
|
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
|
|
1062
1084
|
try {
|
|
1063
|
-
const
|
|
1085
|
+
const o = await t.env.data.organizations.get(
|
|
1064
1086
|
e.accessControl.controlPlaneTenantId,
|
|
1065
1087
|
i
|
|
1066
1088
|
);
|
|
1067
|
-
|
|
1089
|
+
o && (u = o.id);
|
|
1068
1090
|
} catch {
|
|
1069
1091
|
}
|
|
1070
1092
|
if (!u)
|
|
@@ -1074,7 +1096,7 @@ function Ae(e) {
|
|
|
1074
1096
|
return t.set("tenant_id", u), n();
|
|
1075
1097
|
};
|
|
1076
1098
|
}
|
|
1077
|
-
function
|
|
1099
|
+
function Re(e) {
|
|
1078
1100
|
return async (t, n) => {
|
|
1079
1101
|
if (!e.databaseIsolation)
|
|
1080
1102
|
return n();
|
|
@@ -1097,14 +1119,14 @@ function Ie(e) {
|
|
|
1097
1119
|
return n();
|
|
1098
1120
|
};
|
|
1099
1121
|
}
|
|
1100
|
-
function
|
|
1101
|
-
const t =
|
|
1102
|
-
return async (a,
|
|
1122
|
+
function x(e) {
|
|
1123
|
+
const t = Ie(e), n = Se(e), r = Re(e);
|
|
1124
|
+
return async (a, s) => (await t(a, async () => {
|
|
1103
1125
|
}), await n(a, async () => {
|
|
1104
1126
|
}), await r(a, async () => {
|
|
1105
|
-
}),
|
|
1127
|
+
}), s());
|
|
1106
1128
|
}
|
|
1107
|
-
function
|
|
1129
|
+
function De(e) {
|
|
1108
1130
|
const {
|
|
1109
1131
|
dataAdapter: t,
|
|
1110
1132
|
controlPlane: n,
|
|
@@ -1112,32 +1134,34 @@ function je(e) {
|
|
|
1112
1134
|
tenantId: r = "control_plane",
|
|
1113
1135
|
clientId: a
|
|
1114
1136
|
} = {},
|
|
1115
|
-
sync:
|
|
1116
|
-
defaultPermissions:
|
|
1137
|
+
sync: s = { resourceServers: !0, roles: !0 },
|
|
1138
|
+
defaultPermissions: c = ["tenant:admin"],
|
|
1117
1139
|
requireOrganizationMatch: i = !1,
|
|
1118
1140
|
managementApiExtensions: u = [],
|
|
1119
|
-
entityHooks:
|
|
1141
|
+
entityHooks: o,
|
|
1120
1142
|
getChildTenantIds: l,
|
|
1121
1143
|
getAdapters: g,
|
|
1122
1144
|
...d
|
|
1123
1145
|
} = e;
|
|
1124
1146
|
let f = t, m = t;
|
|
1125
|
-
n && (f =
|
|
1147
|
+
n && (f = Z(t, {
|
|
1126
1148
|
controlPlaneTenantId: r,
|
|
1127
1149
|
controlPlaneClientId: a
|
|
1128
1150
|
}), m = {
|
|
1129
|
-
...t,
|
|
1151
|
+
...be(t, {
|
|
1152
|
+
controlPlaneTenantId: r
|
|
1153
|
+
}),
|
|
1130
1154
|
multiTenancyConfig: {
|
|
1131
1155
|
controlPlaneTenantId: r,
|
|
1132
1156
|
controlPlaneClientId: a
|
|
1133
1157
|
}
|
|
1134
1158
|
});
|
|
1135
|
-
const w =
|
|
1136
|
-
resourceServers:
|
|
1137
|
-
roles:
|
|
1159
|
+
const w = s !== !1, C = w ? {
|
|
1160
|
+
resourceServers: s.resourceServers ?? !0,
|
|
1161
|
+
roles: s.roles ?? !0
|
|
1138
1162
|
} : { resourceServers: !1, roles: !1 }, b = {
|
|
1139
1163
|
controlPlaneTenantId: r,
|
|
1140
|
-
getChildTenantIds: l ?? (async () => (await
|
|
1164
|
+
getChildTenantIds: l ?? (async () => (await D(
|
|
1141
1165
|
(v) => f.tenants.list(v),
|
|
1142
1166
|
"tenants",
|
|
1143
1167
|
{ cursorField: "id", pageSize: 100 }
|
|
@@ -1145,43 +1169,43 @@ function je(e) {
|
|
|
1145
1169
|
getAdapters: g ?? (async () => f),
|
|
1146
1170
|
getControlPlaneAdapters: async () => f,
|
|
1147
1171
|
sync: C
|
|
1148
|
-
}, { entityHooks: P, tenantHooks: p } =
|
|
1172
|
+
}, { entityHooks: P, tenantHooks: p } = he(b), T = {
|
|
1149
1173
|
resourceServers: [
|
|
1150
1174
|
P.resourceServers,
|
|
1151
|
-
...(
|
|
1175
|
+
...(o == null ? void 0 : o.resourceServers) ?? []
|
|
1152
1176
|
],
|
|
1153
|
-
roles: [P.roles, ...(
|
|
1154
|
-
connections: (
|
|
1155
|
-
tenants: (
|
|
1156
|
-
rolePermissions: (
|
|
1177
|
+
roles: [P.roles, ...(o == null ? void 0 : o.roles) ?? []],
|
|
1178
|
+
connections: (o == null ? void 0 : o.connections) ?? [],
|
|
1179
|
+
tenants: (o == null ? void 0 : o.tenants) ?? [],
|
|
1180
|
+
rolePermissions: (o == null ? void 0 : o.rolePermissions) ?? []
|
|
1157
1181
|
}, h = X({
|
|
1158
1182
|
accessControl: {
|
|
1159
1183
|
controlPlaneTenantId: r,
|
|
1160
1184
|
requireOrganizationMatch: i,
|
|
1161
|
-
defaultPermissions:
|
|
1185
|
+
defaultPermissions: c
|
|
1162
1186
|
}
|
|
1163
1187
|
}), F = N(
|
|
1164
1188
|
{
|
|
1165
1189
|
accessControl: {
|
|
1166
1190
|
controlPlaneTenantId: r,
|
|
1167
1191
|
requireOrganizationMatch: i,
|
|
1168
|
-
defaultPermissions:
|
|
1192
|
+
defaultPermissions: c
|
|
1169
1193
|
}
|
|
1170
1194
|
},
|
|
1171
1195
|
{ tenants: {
|
|
1172
|
-
async beforeCreate(
|
|
1173
|
-
return h.beforeCreate && (v = await h.beforeCreate(
|
|
1196
|
+
async beforeCreate(S, v) {
|
|
1197
|
+
return h.beforeCreate && (v = await h.beforeCreate(S, v)), p.beforeCreate && (v = await p.beforeCreate(S, v)), v;
|
|
1174
1198
|
},
|
|
1175
|
-
async afterCreate(
|
|
1176
|
-
var
|
|
1177
|
-
await ((
|
|
1199
|
+
async afterCreate(S, v) {
|
|
1200
|
+
var $, R;
|
|
1201
|
+
await (($ = h.afterCreate) == null ? void 0 : $.call(h, S, v)), await ((R = p.afterCreate) == null ? void 0 : R.call(p, S, v));
|
|
1178
1202
|
},
|
|
1179
|
-
async beforeDelete(
|
|
1180
|
-
var
|
|
1181
|
-
await ((
|
|
1203
|
+
async beforeDelete(S, v) {
|
|
1204
|
+
var $, R;
|
|
1205
|
+
await (($ = h.beforeDelete) == null ? void 0 : $.call(h, S, v)), await ((R = p.beforeDelete) == null ? void 0 : R.call(p, S, v));
|
|
1182
1206
|
}
|
|
1183
1207
|
} }
|
|
1184
|
-
), { app: j } =
|
|
1208
|
+
), { app: j } = ce({
|
|
1185
1209
|
dataAdapter: f,
|
|
1186
1210
|
managementDataAdapter: m,
|
|
1187
1211
|
...d,
|
|
@@ -1193,15 +1217,15 @@ function je(e) {
|
|
|
1193
1217
|
});
|
|
1194
1218
|
return j.use(
|
|
1195
1219
|
"/api/v2/*",
|
|
1196
|
-
|
|
1197
|
-
), w && j.use("/api/v2/*",
|
|
1220
|
+
Ae(r)
|
|
1221
|
+
), w && j.use("/api/v2/*", Ce()), { app: j, controlPlaneTenantId: r };
|
|
1198
1222
|
}
|
|
1199
|
-
function
|
|
1223
|
+
function qe(e) {
|
|
1200
1224
|
const t = B(e);
|
|
1201
1225
|
return {
|
|
1202
1226
|
name: "multi-tenancy",
|
|
1203
1227
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1204
|
-
middleware:
|
|
1228
|
+
middleware: x(e),
|
|
1205
1229
|
// Provide lifecycle hooks
|
|
1206
1230
|
hooks: t,
|
|
1207
1231
|
// Mount tenant management routes
|
|
@@ -1222,22 +1246,22 @@ function Me(e) {
|
|
|
1222
1246
|
};
|
|
1223
1247
|
}
|
|
1224
1248
|
function B(e) {
|
|
1225
|
-
const t = e.accessControl ?
|
|
1249
|
+
const t = e.accessControl ? ue(e.accessControl) : {}, n = e.databaseIsolation ? fe(e.databaseIsolation) : {}, r = X(e);
|
|
1226
1250
|
return {
|
|
1227
1251
|
...t,
|
|
1228
1252
|
...n,
|
|
1229
1253
|
tenants: r
|
|
1230
1254
|
};
|
|
1231
1255
|
}
|
|
1232
|
-
function
|
|
1233
|
-
const t = new
|
|
1256
|
+
function ze(e) {
|
|
1257
|
+
const t = new ne(), n = B(e);
|
|
1234
1258
|
return t.route("/tenants", N(e, n)), t;
|
|
1235
1259
|
}
|
|
1236
|
-
function
|
|
1260
|
+
function Oe(e) {
|
|
1237
1261
|
return {
|
|
1238
1262
|
hooks: B(e),
|
|
1239
|
-
middleware:
|
|
1240
|
-
app:
|
|
1263
|
+
middleware: x(e),
|
|
1264
|
+
app: ze(e),
|
|
1241
1265
|
config: e,
|
|
1242
1266
|
/**
|
|
1243
1267
|
* Wraps data adapters with runtime fallback from the control plane.
|
|
@@ -1249,7 +1273,7 @@ function qe(e) {
|
|
|
1249
1273
|
*/
|
|
1250
1274
|
wrapAdapters: (t, n) => {
|
|
1251
1275
|
var r;
|
|
1252
|
-
return
|
|
1276
|
+
return Z(t, {
|
|
1253
1277
|
controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
|
|
1254
1278
|
controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
|
|
1255
1279
|
});
|
|
@@ -1257,23 +1281,24 @@ function qe(e) {
|
|
|
1257
1281
|
};
|
|
1258
1282
|
}
|
|
1259
1283
|
export {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1284
|
+
ue as createAccessControlHooks,
|
|
1285
|
+
Se as createAccessControlMiddleware,
|
|
1286
|
+
Ae as createControlPlaneTenantMiddleware,
|
|
1287
|
+
fe as createDatabaseHooks,
|
|
1288
|
+
Re as createDatabaseMiddleware,
|
|
1289
|
+
ze as createMultiTenancy,
|
|
1266
1290
|
B as createMultiTenancyHooks,
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1291
|
+
x as createMultiTenancyMiddleware,
|
|
1292
|
+
qe as createMultiTenancyPlugin,
|
|
1293
|
+
Ce as createProtectSyncedMiddleware,
|
|
1270
1294
|
X as createProvisioningHooks,
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1295
|
+
Pe as createRuntimeFallbackAdapter,
|
|
1296
|
+
Ie as createSubdomainMiddleware,
|
|
1297
|
+
he as createSyncHooks,
|
|
1274
1298
|
N as createTenantsOpenAPIRouter,
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1299
|
+
De as initMultiTenant,
|
|
1300
|
+
Oe as setupMultiTenancy,
|
|
1301
|
+
de as validateTenantAccess,
|
|
1302
|
+
Z as withRuntimeFallback,
|
|
1303
|
+
be as withSystemResourceServerInheritance
|
|
1279
1304
|
};
|