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