@authhero/multi-tenancy 14.13.0 → 14.15.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 +330 -312
- package/dist/types/init.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 Z = Object.defineProperty;
|
|
2
|
+
var x = (e, t, n) => t in e ? Z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var q = (e, t, n) => x(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { Hono as ee } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as te, MANAGEMENT_API_AUDIENCE as V, fetchAll as M, auth0QuerySchema as ne, tenantSchema as B, tenantInsertSchema as re, connectionSchema as ae, connectionOptionsSchema as se, init as oe } from "authhero";
|
|
6
|
+
import { OpenAPIHono as ie, createRoute as j, z } from "@hono/zod-openapi";
|
|
7
|
+
function ce(e) {
|
|
8
8
|
const { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
9
9
|
return {
|
|
10
|
-
async onTenantAccessValidation(r,
|
|
11
|
-
if (
|
|
10
|
+
async onTenantAccessValidation(r, a) {
|
|
11
|
+
if (a === t)
|
|
12
12
|
return !0;
|
|
13
13
|
if (n) {
|
|
14
|
-
const
|
|
15
|
-
return i ? i.toLowerCase() ===
|
|
14
|
+
const s = r.var.org_name, o = r.var.organization_id, i = s || o;
|
|
15
|
+
return i ? i.toLowerCase() === a.toLowerCase() : !1;
|
|
16
16
|
}
|
|
17
17
|
return !0;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function le(e, t, n, r) {
|
|
22
22
|
if (t === n)
|
|
23
23
|
return !0;
|
|
24
|
-
const
|
|
25
|
-
return
|
|
24
|
+
const a = r || e;
|
|
25
|
+
return a ? a.toLowerCase() === t.toLowerCase() : !1;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function ue(e) {
|
|
28
28
|
return {
|
|
29
29
|
async resolveDataAdapters(t) {
|
|
30
30
|
try {
|
|
@@ -39,23 +39,23 @@ function le(e) {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function de(e) {
|
|
43
43
|
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function J(e) {
|
|
46
46
|
return {
|
|
47
47
|
async beforeCreate(t, n) {
|
|
48
48
|
return !n.audience && n.id ? {
|
|
49
49
|
...n,
|
|
50
|
-
audience:
|
|
50
|
+
audience: de(n.id)
|
|
51
51
|
} : n;
|
|
52
52
|
},
|
|
53
53
|
async afterCreate(t, n) {
|
|
54
|
-
const { accessControl: r, databaseIsolation:
|
|
55
|
-
r && t.ctx && await fe(t, n, r),
|
|
54
|
+
const { accessControl: r, databaseIsolation: a } = e;
|
|
55
|
+
r && t.ctx && await fe(t, n, r), a != null && a.onProvision && await a.onProvision(n.id);
|
|
56
56
|
},
|
|
57
57
|
async beforeDelete(t, n) {
|
|
58
|
-
const { accessControl: r, databaseIsolation:
|
|
58
|
+
const { accessControl: r, databaseIsolation: a } = e;
|
|
59
59
|
if (r)
|
|
60
60
|
try {
|
|
61
61
|
const o = (await t.adapters.organizations.list(
|
|
@@ -65,19 +65,19 @@ function de(e) {
|
|
|
65
65
|
r.controlPlaneTenantId,
|
|
66
66
|
o.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
|
-
if (
|
|
74
|
+
if (a != null && a.onDeprovision)
|
|
75
75
|
try {
|
|
76
|
-
await
|
|
77
|
-
} catch (
|
|
76
|
+
await a.onDeprovision(n);
|
|
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
|
}
|
|
@@ -86,8 +86,8 @@ function de(e) {
|
|
|
86
86
|
async function fe(e, t, n) {
|
|
87
87
|
const {
|
|
88
88
|
controlPlaneTenantId: r,
|
|
89
|
-
defaultPermissions:
|
|
90
|
-
defaultRoles:
|
|
89
|
+
defaultPermissions: a,
|
|
90
|
+
defaultRoles: s,
|
|
91
91
|
issuer: o,
|
|
92
92
|
adminRoleName: i = "Tenant Admin",
|
|
93
93
|
adminRoleDescription: u = "Full access to all tenant management operations",
|
|
@@ -130,10 +130,10 @@ async function fe(e, t, n) {
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
`Would assign roles ${
|
|
135
|
-
),
|
|
136
|
-
`Would grant permissions ${
|
|
133
|
+
s && s.length > 0 && console.log(
|
|
134
|
+
`Would assign roles ${s.join(", ")} to organization ${l.id}`
|
|
135
|
+
), a && a.length > 0 && console.log(
|
|
136
|
+
`Would grant permissions ${a.join(", ")} to organization ${l.id}`
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
async function me(e, t, n) {
|
|
@@ -144,10 +144,10 @@ async function me(e, t, n) {
|
|
|
144
144
|
""
|
|
145
145
|
// Empty string for global roles
|
|
146
146
|
);
|
|
147
|
-
for (const
|
|
147
|
+
for (const a of r)
|
|
148
148
|
if ((await e.adapters.rolePermissions.list(
|
|
149
149
|
t,
|
|
150
|
-
|
|
150
|
+
a.id,
|
|
151
151
|
{ per_page: 1e3 }
|
|
152
152
|
)).some(
|
|
153
153
|
(i) => i.permission_name === "admin:organizations"
|
|
@@ -156,13 +156,13 @@ async function me(e, t, n) {
|
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
158
|
async function ge(e, t, n, r) {
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
return
|
|
159
|
+
const s = (await e.adapters.roles.list(t, {})).roles.find((c) => c.name === n);
|
|
160
|
+
if (s)
|
|
161
|
+
return s.id;
|
|
162
162
|
const o = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}), i =
|
|
165
|
+
}), i = V, u = te.map((c) => ({
|
|
166
166
|
role_id: o.id,
|
|
167
167
|
resource_server_identifier: i,
|
|
168
168
|
permission_name: c.value
|
|
@@ -173,8 +173,8 @@ async function ge(e, t, n, r) {
|
|
|
173
173
|
u
|
|
174
174
|
), o.id;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
const { controlPlaneTenantId: r, getChildTenantIds:
|
|
176
|
+
function G(e, t, n = () => !0) {
|
|
177
|
+
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e, o = /* @__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 H(e, t, n = () => !0) {
|
|
|
182
182
|
}))[0] ?? null;
|
|
183
183
|
}
|
|
184
184
|
async function u(l) {
|
|
185
|
-
const g = 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), h = {
|
|
190
190
|
...d.transform(l),
|
|
191
191
|
is_system: !0
|
|
192
|
-
},
|
|
193
|
-
if (
|
|
194
|
-
const
|
|
195
|
-
await w.update(f,
|
|
192
|
+
}, _ = await i(m, f, l.name), P = _ ? w.getId(_) : void 0;
|
|
193
|
+
if (_ && P) {
|
|
194
|
+
const b = w.preserveOnUpdate ? w.preserveOnUpdate(_, h) : h;
|
|
195
|
+
await w.update(f, P, b);
|
|
196
196
|
} else
|
|
197
|
-
await w.create(f,
|
|
197
|
+
await w.create(f, h);
|
|
198
198
|
} catch (m) {
|
|
199
199
|
console.error(
|
|
200
200
|
`Failed to sync ${d.listKey} "${l.name}" to tenant "${f}":`,
|
|
@@ -205,12 +205,12 @@ function H(e, t, n = () => !0) {
|
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
207
|
async function c(l) {
|
|
208
|
-
const g = await
|
|
208
|
+
const g = await a();
|
|
209
209
|
await Promise.all(
|
|
210
210
|
g.map(async (d) => {
|
|
211
211
|
try {
|
|
212
|
-
const f = await
|
|
213
|
-
w &&
|
|
212
|
+
const f = await s(d), m = t(f), w = await i(f, d, l), C = w ? m.getId(w) : void 0;
|
|
213
|
+
w && C && await m.remove(d, C);
|
|
214
214
|
} catch (f) {
|
|
215
215
|
console.error(
|
|
216
216
|
`Failed to delete entity "${l}" from tenant "${d}":`,
|
|
@@ -239,13 +239,13 @@ function H(e, t, n = () => !0) {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
const { controlPlaneTenantId: r, getControlPlaneAdapters:
|
|
242
|
+
function U(e, t, n = () => !0) {
|
|
243
|
+
const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: s } = e;
|
|
244
244
|
return {
|
|
245
245
|
async afterCreate(o, i) {
|
|
246
246
|
if (i.id !== r)
|
|
247
247
|
try {
|
|
248
|
-
const u = await
|
|
248
|
+
const u = await a(), c = await s(i.id), l = t(u), g = t(c), d = await M(
|
|
249
249
|
(f) => l.listPaginated(r, f),
|
|
250
250
|
l.listKey,
|
|
251
251
|
{ cursorField: "id", pageSize: 100 }
|
|
@@ -275,7 +275,7 @@ function B(e, t, n = () => !0) {
|
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
}
|
|
278
|
-
const
|
|
278
|
+
const L = (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 G = (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),
|
|
@@ -308,92 +308,92 @@ const G = (e) => ({
|
|
|
308
308
|
description: t.description
|
|
309
309
|
})
|
|
310
310
|
});
|
|
311
|
-
function
|
|
311
|
+
function W(e) {
|
|
312
312
|
var t;
|
|
313
313
|
return ((t = e.metadata) == null ? void 0 : t.sync) !== !1;
|
|
314
314
|
}
|
|
315
315
|
function we(e) {
|
|
316
|
-
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0,
|
|
316
|
+
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, a = t.roles ?? !0, s = (m) => W(m) ? n.resourceServers ? n.resourceServers(m) : !0 : !1, o = (m) => W(m) ? n.roles ? n.roles(m) : !0 : !1, i = r ? G(
|
|
317
317
|
e,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
) : void 0, u =
|
|
318
|
+
L,
|
|
319
|
+
s
|
|
320
|
+
) : void 0, u = a ? G(e, H, o) : void 0, c = r ? U(
|
|
321
321
|
e,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
) : void 0, l =
|
|
322
|
+
L,
|
|
323
|
+
s
|
|
324
|
+
) : void 0, l = a ? U(
|
|
325
325
|
e,
|
|
326
|
-
|
|
326
|
+
H,
|
|
327
327
|
o
|
|
328
|
-
) : void 0, g =
|
|
328
|
+
) : void 0, g = a ? {
|
|
329
329
|
async afterCreate(m, w) {
|
|
330
|
-
var
|
|
330
|
+
var C;
|
|
331
331
|
if (w.id !== e.controlPlaneTenantId) {
|
|
332
|
-
await ((
|
|
332
|
+
await ((C = l == null ? void 0 : l.afterCreate) == null ? void 0 : C.call(l, m, w));
|
|
333
333
|
try {
|
|
334
|
-
const
|
|
335
|
-
(
|
|
334
|
+
const h = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), P = await M(
|
|
335
|
+
(p) => h.roles.list(
|
|
336
336
|
e.controlPlaneTenantId,
|
|
337
|
-
|
|
337
|
+
p
|
|
338
338
|
),
|
|
339
339
|
"roles",
|
|
340
340
|
{ cursorField: "id", pageSize: 100 }
|
|
341
|
-
),
|
|
342
|
-
for (const
|
|
343
|
-
(
|
|
344
|
-
var
|
|
345
|
-
return ((
|
|
341
|
+
), b = /* @__PURE__ */ new Map();
|
|
342
|
+
for (const p of P.filter(
|
|
343
|
+
(T) => {
|
|
344
|
+
var y;
|
|
345
|
+
return ((y = n.roles) == null ? void 0 : y.call(n, T)) ?? !0;
|
|
346
346
|
}
|
|
347
347
|
)) {
|
|
348
|
-
const
|
|
349
|
-
|
|
348
|
+
const T = await d(
|
|
349
|
+
_,
|
|
350
350
|
w.id,
|
|
351
|
-
|
|
351
|
+
p.name
|
|
352
352
|
);
|
|
353
|
-
|
|
353
|
+
T && b.set(p.name, T.id);
|
|
354
354
|
}
|
|
355
|
-
for (const
|
|
356
|
-
(
|
|
357
|
-
var
|
|
358
|
-
return ((
|
|
355
|
+
for (const p of P.filter(
|
|
356
|
+
(T) => {
|
|
357
|
+
var y;
|
|
358
|
+
return ((y = n.roles) == null ? void 0 : y.call(n, T)) ?? !0;
|
|
359
359
|
}
|
|
360
360
|
)) {
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
361
|
+
const T = b.get(p.name);
|
|
362
|
+
if (T)
|
|
363
363
|
try {
|
|
364
|
-
const
|
|
364
|
+
const y = await h.rolePermissions.list(
|
|
365
365
|
e.controlPlaneTenantId,
|
|
366
|
-
|
|
366
|
+
p.id,
|
|
367
367
|
{}
|
|
368
368
|
);
|
|
369
|
-
|
|
369
|
+
y.length > 0 && await _.rolePermissions.assign(
|
|
370
370
|
w.id,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
role_id:
|
|
374
|
-
resource_server_identifier:
|
|
375
|
-
permission_name:
|
|
371
|
+
T,
|
|
372
|
+
y.map((R) => ({
|
|
373
|
+
role_id: T,
|
|
374
|
+
resource_server_identifier: R.resource_server_identifier,
|
|
375
|
+
permission_name: R.permission_name
|
|
376
376
|
}))
|
|
377
377
|
);
|
|
378
|
-
} catch (
|
|
378
|
+
} catch (y) {
|
|
379
379
|
console.error(
|
|
380
|
-
`Failed to sync permissions for role "${
|
|
381
|
-
|
|
380
|
+
`Failed to sync permissions for role "${p.name}" to tenant "${w.id}":`,
|
|
381
|
+
y
|
|
382
382
|
);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
} catch (
|
|
385
|
+
} catch (h) {
|
|
386
386
|
console.error(
|
|
387
387
|
`Failed to sync role permissions to tenant "${w.id}":`,
|
|
388
|
-
|
|
388
|
+
h
|
|
389
389
|
);
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
} : void 0;
|
|
394
|
-
async function d(m, w,
|
|
394
|
+
async function d(m, w, C) {
|
|
395
395
|
return (await m.roles.list(w, {
|
|
396
|
-
q: `name:${
|
|
396
|
+
q: `name:${C}`,
|
|
397
397
|
per_page: 1
|
|
398
398
|
})).roles[0] ?? null;
|
|
399
399
|
}
|
|
@@ -404,28 +404,28 @@ function we(e) {
|
|
|
404
404
|
},
|
|
405
405
|
tenantHooks: {
|
|
406
406
|
async afterCreate(m, w) {
|
|
407
|
-
const
|
|
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
|
-
],
|
|
411
|
-
for (const
|
|
412
|
-
if (
|
|
410
|
+
], h = [];
|
|
411
|
+
for (const _ of C)
|
|
412
|
+
if (_)
|
|
413
413
|
try {
|
|
414
|
-
await
|
|
415
|
-
} catch (
|
|
416
|
-
|
|
414
|
+
await _(m, w);
|
|
415
|
+
} catch (P) {
|
|
416
|
+
h.push(P instanceof Error ? P : new Error(String(P)));
|
|
417
417
|
}
|
|
418
|
-
if (
|
|
419
|
-
if (
|
|
418
|
+
if (h.length === 1) throw h[0];
|
|
419
|
+
if (h.length > 1)
|
|
420
420
|
throw new AggregateError(
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
h,
|
|
422
|
+
h.map((_) => _.message).join("; ")
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
|
-
var
|
|
428
|
+
var S = 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 b = 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
|
+
q(this, "res");
|
|
437
|
+
q(this, "status");
|
|
438
438
|
this.res = n == null ? void 0 : n.res, this.status = t;
|
|
439
439
|
}
|
|
440
440
|
/**
|
|
@@ -451,15 +451,15 @@ var b = class extends Error {
|
|
|
451
451
|
});
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
|
-
function
|
|
455
|
-
const n = new
|
|
454
|
+
function k(e, t) {
|
|
455
|
+
const n = new ie();
|
|
456
456
|
return n.openapi(
|
|
457
|
-
|
|
457
|
+
j({
|
|
458
458
|
tags: ["tenants"],
|
|
459
459
|
method: "get",
|
|
460
460
|
path: "/",
|
|
461
461
|
request: {
|
|
462
|
-
query:
|
|
462
|
+
query: ne
|
|
463
463
|
},
|
|
464
464
|
security: [
|
|
465
465
|
{
|
|
@@ -470,11 +470,11 @@ function q(e, t) {
|
|
|
470
470
|
200: {
|
|
471
471
|
content: {
|
|
472
472
|
"application/json": {
|
|
473
|
-
schema:
|
|
474
|
-
tenants:
|
|
475
|
-
start:
|
|
476
|
-
limit:
|
|
477
|
-
length:
|
|
473
|
+
schema: z.object({
|
|
474
|
+
tenants: z.array(B),
|
|
475
|
+
start: z.number().optional(),
|
|
476
|
+
limit: z.number().optional(),
|
|
477
|
+
length: z.number().optional()
|
|
478
478
|
})
|
|
479
479
|
}
|
|
480
480
|
},
|
|
@@ -483,75 +483,75 @@ function q(e, t) {
|
|
|
483
483
|
}
|
|
484
484
|
}),
|
|
485
485
|
async (r) => {
|
|
486
|
-
var m, w,
|
|
487
|
-
const
|
|
486
|
+
var m, w, C, h, _, P;
|
|
487
|
+
const a = r.req.valid("query"), { page: s, per_page: o, include_totals: i, q: u } = a, c = r.var.user, l = (c == null ? void 0 : c.permissions) || [];
|
|
488
488
|
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
489
|
-
const
|
|
490
|
-
page:
|
|
489
|
+
const b = await r.env.data.tenants.list({
|
|
490
|
+
page: s,
|
|
491
491
|
per_page: o,
|
|
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: b.tenants,
|
|
497
|
+
start: ((m = b.totals) == null ? void 0 : m.start) ?? 0,
|
|
498
|
+
limit: ((w = b.totals) == null ? void 0 : w.limit) ?? o,
|
|
499
|
+
length: b.tenants.length
|
|
500
|
+
}) : r.json({ tenants: b.tenants });
|
|
501
501
|
}
|
|
502
|
-
const d = ((
|
|
502
|
+
const d = ((C = e.accessControl) == null ? void 0 : C.controlPlaneTenantId) ?? ((h = r.env.data.multiTenancyConfig) == null ? void 0 : h.controlPlaneTenantId);
|
|
503
503
|
if (d && (c != null && c.sub)) {
|
|
504
|
-
const
|
|
505
|
-
(
|
|
504
|
+
const p = (await M(
|
|
505
|
+
(I) => r.env.data.userOrganizations.listUserOrganizations(
|
|
506
506
|
d,
|
|
507
507
|
c.sub,
|
|
508
|
-
|
|
508
|
+
I
|
|
509
509
|
),
|
|
510
510
|
"organizations"
|
|
511
|
-
)).map((
|
|
512
|
-
if (
|
|
511
|
+
)).map((I) => I.name);
|
|
512
|
+
if (p.length === 0)
|
|
513
513
|
return i ? r.json({
|
|
514
514
|
tenants: [],
|
|
515
515
|
start: 0,
|
|
516
516
|
limit: o ?? 50,
|
|
517
517
|
length: 0
|
|
518
518
|
}) : r.json({ tenants: [] });
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
519
|
+
const T = p.length, y = s ?? 0, R = o ?? 50, F = y * R, D = p.slice(F, F + R);
|
|
520
|
+
if (D.length === 0)
|
|
521
521
|
return i ? r.json({
|
|
522
522
|
tenants: [],
|
|
523
|
-
start:
|
|
524
|
-
limit:
|
|
525
|
-
length:
|
|
523
|
+
start: F,
|
|
524
|
+
limit: R,
|
|
525
|
+
length: T
|
|
526
526
|
}) : r.json({ tenants: [] });
|
|
527
|
-
const
|
|
528
|
-
q:
|
|
529
|
-
per_page:
|
|
527
|
+
const A = D.map((I) => `id:${I}`).join(" OR "), v = u ? `(${A}) AND (${u})` : A, $ = await r.env.data.tenants.list({
|
|
528
|
+
q: v,
|
|
529
|
+
per_page: R,
|
|
530
530
|
include_totals: !1
|
|
531
531
|
// We calculate totals from accessibleTenantIds
|
|
532
532
|
});
|
|
533
533
|
return i ? r.json({
|
|
534
|
-
tenants:
|
|
535
|
-
start:
|
|
536
|
-
limit:
|
|
537
|
-
length:
|
|
538
|
-
}) : r.json({ tenants:
|
|
534
|
+
tenants: $.tenants,
|
|
535
|
+
start: F,
|
|
536
|
+
limit: R,
|
|
537
|
+
length: T
|
|
538
|
+
}) : r.json({ tenants: $.tenants });
|
|
539
539
|
}
|
|
540
540
|
const f = await r.env.data.tenants.list({
|
|
541
|
-
page:
|
|
541
|
+
page: s,
|
|
542
542
|
per_page: o,
|
|
543
543
|
include_totals: i,
|
|
544
544
|
q: u
|
|
545
545
|
});
|
|
546
546
|
return i ? r.json({
|
|
547
547
|
tenants: f.tenants,
|
|
548
|
-
start: ((
|
|
549
|
-
limit: ((
|
|
548
|
+
start: ((_ = f.totals) == null ? void 0 : _.start) ?? 0,
|
|
549
|
+
limit: ((P = f.totals) == null ? void 0 : P.limit) ?? o,
|
|
550
550
|
length: f.tenants.length
|
|
551
551
|
}) : r.json({ tenants: f.tenants });
|
|
552
552
|
}
|
|
553
553
|
), n.openapi(
|
|
554
|
-
|
|
554
|
+
j({
|
|
555
555
|
tags: ["tenants"],
|
|
556
556
|
method: "post",
|
|
557
557
|
path: "/",
|
|
@@ -559,7 +559,7 @@ function q(e, t) {
|
|
|
559
559
|
body: {
|
|
560
560
|
content: {
|
|
561
561
|
"application/json": {
|
|
562
|
-
schema:
|
|
562
|
+
schema: re
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
}
|
|
@@ -573,7 +573,7 @@ function q(e, t) {
|
|
|
573
573
|
201: {
|
|
574
574
|
content: {
|
|
575
575
|
"application/json": {
|
|
576
|
-
schema:
|
|
576
|
+
schema: B
|
|
577
577
|
}
|
|
578
578
|
},
|
|
579
579
|
description: "Tenant created"
|
|
@@ -588,28 +588,28 @@ function q(e, t) {
|
|
|
588
588
|
}),
|
|
589
589
|
async (r) => {
|
|
590
590
|
var u, c;
|
|
591
|
-
const
|
|
592
|
-
if (!(
|
|
593
|
-
throw new
|
|
591
|
+
const a = r.var.user;
|
|
592
|
+
if (!(a != null && a.sub))
|
|
593
|
+
throw new S(401, {
|
|
594
594
|
message: "Authentication required to create tenants"
|
|
595
595
|
});
|
|
596
|
-
let
|
|
596
|
+
let s = r.req.valid("json");
|
|
597
597
|
const o = {
|
|
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(
|
|
601
|
+
(u = t.tenants) != null && u.beforeCreate && (s = await t.tenants.beforeCreate(o, s));
|
|
602
|
+
const i = await r.env.data.tenants.create(s);
|
|
603
603
|
return (c = t.tenants) != null && c.afterCreate && await t.tenants.afterCreate(o, i), r.json(i, 201);
|
|
604
604
|
}
|
|
605
605
|
), n.openapi(
|
|
606
|
-
|
|
606
|
+
j({
|
|
607
607
|
tags: ["tenants"],
|
|
608
608
|
method: "delete",
|
|
609
609
|
path: "/{id}",
|
|
610
610
|
request: {
|
|
611
|
-
params:
|
|
612
|
-
id:
|
|
611
|
+
params: z.object({
|
|
612
|
+
id: z.string()
|
|
613
613
|
})
|
|
614
614
|
},
|
|
615
615
|
security: [
|
|
@@ -631,38 +631,38 @@ function q(e, t) {
|
|
|
631
631
|
}),
|
|
632
632
|
async (r) => {
|
|
633
633
|
var u, c, l, g;
|
|
634
|
-
const { id:
|
|
635
|
-
if (
|
|
634
|
+
const { id: a } = r.req.valid("param"), s = ((u = e.accessControl) == null ? void 0 : u.controlPlaneTenantId) ?? ((c = r.env.data.multiTenancyConfig) == null ? void 0 : c.controlPlaneTenantId);
|
|
635
|
+
if (s) {
|
|
636
636
|
const d = r.var.user;
|
|
637
637
|
if (!(d != null && d.sub))
|
|
638
|
-
throw new
|
|
638
|
+
throw new S(401, {
|
|
639
639
|
message: "Authentication required"
|
|
640
640
|
});
|
|
641
|
-
if (
|
|
642
|
-
throw new
|
|
641
|
+
if (a === s)
|
|
642
|
+
throw new S(403, {
|
|
643
643
|
message: "Cannot delete the control plane"
|
|
644
644
|
});
|
|
645
|
-
if (!(await
|
|
645
|
+
if (!(await M(
|
|
646
646
|
(w) => r.env.data.userOrganizations.listUserOrganizations(
|
|
647
|
-
|
|
647
|
+
s,
|
|
648
648
|
d.sub,
|
|
649
649
|
w
|
|
650
650
|
),
|
|
651
651
|
"organizations"
|
|
652
|
-
)).some((w) => w.name ===
|
|
653
|
-
throw new
|
|
652
|
+
)).some((w) => w.name === a))
|
|
653
|
+
throw new S(403, {
|
|
654
654
|
message: "Access denied to this tenant"
|
|
655
655
|
});
|
|
656
656
|
}
|
|
657
|
-
if (!await r.env.data.tenants.get(
|
|
658
|
-
throw new
|
|
657
|
+
if (!await r.env.data.tenants.get(a))
|
|
658
|
+
throw new S(404, {
|
|
659
659
|
message: "Tenant not found"
|
|
660
660
|
});
|
|
661
661
|
const i = {
|
|
662
662
|
adapters: r.env.data,
|
|
663
663
|
ctx: r
|
|
664
664
|
};
|
|
665
|
-
return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(i,
|
|
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
667
|
), n;
|
|
668
668
|
}
|
|
@@ -676,9 +676,9 @@ function pe(e) {
|
|
|
676
676
|
{ pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
|
|
677
677
|
];
|
|
678
678
|
for (const { pattern: n, type: r } of t) {
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
return { type: r, id:
|
|
679
|
+
const a = e.match(n);
|
|
680
|
+
if (a && a[1])
|
|
681
|
+
return { type: r, id: a[1] };
|
|
682
682
|
}
|
|
683
683
|
return null;
|
|
684
684
|
}
|
|
@@ -722,19 +722,19 @@ function ve() {
|
|
|
722
722
|
if (!r)
|
|
723
723
|
return t();
|
|
724
724
|
if (await ye(e.env.data, r, n))
|
|
725
|
-
throw new
|
|
725
|
+
throw new S(403, {
|
|
726
726
|
message: `This ${he(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
727
727
|
});
|
|
728
728
|
return t();
|
|
729
729
|
};
|
|
730
730
|
}
|
|
731
|
-
function
|
|
731
|
+
function E(e, t) {
|
|
732
732
|
const n = t.find(
|
|
733
|
-
(
|
|
733
|
+
(a) => a.strategy === e.strategy
|
|
734
734
|
);
|
|
735
735
|
if (!(n != null && n.options))
|
|
736
736
|
return e;
|
|
737
|
-
const r =
|
|
737
|
+
const r = ae.passthrough().parse({
|
|
738
738
|
...n,
|
|
739
739
|
...e
|
|
740
740
|
});
|
|
@@ -743,7 +743,7 @@ function D(e, t) {
|
|
|
743
743
|
...e.options
|
|
744
744
|
}), r;
|
|
745
745
|
}
|
|
746
|
-
function
|
|
746
|
+
function O(e, t) {
|
|
747
747
|
const n = [...t || [], ...e || []];
|
|
748
748
|
return [...new Set(n)];
|
|
749
749
|
}
|
|
@@ -759,7 +759,7 @@ function _e(e, t) {
|
|
|
759
759
|
n.set(r.value, r);
|
|
760
760
|
return Array.from(n.values());
|
|
761
761
|
}
|
|
762
|
-
function
|
|
762
|
+
function K(e, t) {
|
|
763
763
|
return t ? {
|
|
764
764
|
...e,
|
|
765
765
|
scopes: _e(
|
|
@@ -768,25 +768,25 @@ function W(e, t) {
|
|
|
768
768
|
)
|
|
769
769
|
} : e;
|
|
770
770
|
}
|
|
771
|
-
function
|
|
771
|
+
function Q(e, t) {
|
|
772
772
|
return t ? {
|
|
773
773
|
...e,
|
|
774
|
-
callbacks:
|
|
775
|
-
web_origins:
|
|
774
|
+
callbacks: O(e.callbacks, t.callbacks),
|
|
775
|
+
web_origins: O(
|
|
776
776
|
e.web_origins,
|
|
777
777
|
t.web_origins
|
|
778
778
|
),
|
|
779
|
-
allowed_logout_urls:
|
|
779
|
+
allowed_logout_urls: O(
|
|
780
780
|
e.allowed_logout_urls,
|
|
781
781
|
t.allowed_logout_urls
|
|
782
782
|
),
|
|
783
|
-
allowed_origins:
|
|
783
|
+
allowed_origins: O(
|
|
784
784
|
e.allowed_origins,
|
|
785
785
|
t.allowed_origins
|
|
786
786
|
)
|
|
787
787
|
} : e;
|
|
788
788
|
}
|
|
789
|
-
function
|
|
789
|
+
function Ce(e, t) {
|
|
790
790
|
const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
|
|
791
791
|
return {
|
|
792
792
|
...e,
|
|
@@ -797,25 +797,25 @@ function Te(e, t) {
|
|
|
797
797
|
},
|
|
798
798
|
connections: {
|
|
799
799
|
...e.connections,
|
|
800
|
-
get: async (
|
|
800
|
+
get: async (a, s) => {
|
|
801
801
|
const o = await e.connections.get(
|
|
802
|
-
|
|
803
|
-
|
|
802
|
+
a,
|
|
803
|
+
s
|
|
804
804
|
);
|
|
805
|
-
if (!o || !n ||
|
|
805
|
+
if (!o || !n || a === n)
|
|
806
806
|
return o;
|
|
807
807
|
const i = await e.connections.list(n);
|
|
808
|
-
return
|
|
808
|
+
return E(
|
|
809
809
|
o,
|
|
810
810
|
i.connections || []
|
|
811
811
|
);
|
|
812
812
|
},
|
|
813
|
-
list: async (
|
|
814
|
-
const o = await e.connections.list(
|
|
815
|
-
if (!n ||
|
|
813
|
+
list: async (a, s) => {
|
|
814
|
+
const o = await e.connections.list(a, s);
|
|
815
|
+
if (!n || a === n)
|
|
816
816
|
return o;
|
|
817
817
|
const i = await e.connections.list(n), u = o.connections.map(
|
|
818
|
-
(c) =>
|
|
818
|
+
(c) => E(
|
|
819
819
|
c,
|
|
820
820
|
i.connections || []
|
|
821
821
|
)
|
|
@@ -828,16 +828,16 @@ function Te(e, t) {
|
|
|
828
828
|
},
|
|
829
829
|
clientConnections: {
|
|
830
830
|
...e.clientConnections,
|
|
831
|
-
listByClient: async (
|
|
831
|
+
listByClient: async (a, s) => {
|
|
832
832
|
let o = await e.clientConnections.listByClient(
|
|
833
|
-
|
|
834
|
-
|
|
833
|
+
a,
|
|
834
|
+
s
|
|
835
835
|
);
|
|
836
|
-
if (o.length === 0 && (o = (await e.connections.list(
|
|
836
|
+
if (o.length === 0 && (o = (await e.connections.list(a)).connections || []), !n || a === n)
|
|
837
837
|
return o;
|
|
838
838
|
const i = await e.connections.list(n);
|
|
839
839
|
return o.map(
|
|
840
|
-
(u) =>
|
|
840
|
+
(u) => E(
|
|
841
841
|
u,
|
|
842
842
|
i.connections || []
|
|
843
843
|
)
|
|
@@ -846,70 +846,70 @@ function Te(e, t) {
|
|
|
846
846
|
},
|
|
847
847
|
clients: {
|
|
848
848
|
...e.clients,
|
|
849
|
-
get: async (
|
|
850
|
-
const o = await e.clients.get(
|
|
849
|
+
get: async (a, s) => {
|
|
850
|
+
const o = await e.clients.get(a, s);
|
|
851
851
|
if (!o)
|
|
852
852
|
return null;
|
|
853
|
-
if (!n || !r ||
|
|
853
|
+
if (!n || !r || a === n && s === r)
|
|
854
854
|
return o;
|
|
855
855
|
const i = await e.clients.get(
|
|
856
856
|
n,
|
|
857
857
|
r
|
|
858
858
|
);
|
|
859
|
-
return
|
|
859
|
+
return Q(o, i);
|
|
860
860
|
},
|
|
861
|
-
getByClientId: async (
|
|
862
|
-
const
|
|
863
|
-
if (!
|
|
861
|
+
getByClientId: async (a) => {
|
|
862
|
+
const s = await e.clients.getByClientId(a);
|
|
863
|
+
if (!s)
|
|
864
864
|
return null;
|
|
865
|
-
if (!n || !r ||
|
|
866
|
-
return
|
|
865
|
+
if (!n || !r || s.tenant_id === n && s.client_id === r)
|
|
866
|
+
return s;
|
|
867
867
|
const o = await e.clients.get(
|
|
868
868
|
n,
|
|
869
869
|
r
|
|
870
870
|
);
|
|
871
871
|
return {
|
|
872
|
-
...
|
|
873
|
-
tenant_id:
|
|
872
|
+
...Q(s, o),
|
|
873
|
+
tenant_id: s.tenant_id
|
|
874
874
|
};
|
|
875
875
|
}
|
|
876
876
|
},
|
|
877
877
|
emailProviders: {
|
|
878
878
|
...e.emailProviders,
|
|
879
|
-
get: async (
|
|
880
|
-
const
|
|
881
|
-
return
|
|
879
|
+
get: async (a) => {
|
|
880
|
+
const s = await e.emailProviders.get(a);
|
|
881
|
+
return s || (!n || a === n ? null : e.emailProviders.get(n));
|
|
882
882
|
}
|
|
883
883
|
},
|
|
884
884
|
resourceServers: {
|
|
885
885
|
...e.resourceServers,
|
|
886
|
-
get: async (
|
|
886
|
+
get: async (a, s) => {
|
|
887
887
|
const o = await e.resourceServers.get(
|
|
888
|
-
|
|
889
|
-
|
|
888
|
+
a,
|
|
889
|
+
s
|
|
890
890
|
);
|
|
891
|
-
if (!o || !n ||
|
|
891
|
+
if (!o || !n || a === n)
|
|
892
892
|
return o;
|
|
893
893
|
const u = (await e.resourceServers.list(
|
|
894
894
|
n,
|
|
895
895
|
{ q: `identifier:${o.identifier}`, per_page: 1 }
|
|
896
896
|
)).resource_servers[0] ?? null;
|
|
897
|
-
return
|
|
897
|
+
return K(
|
|
898
898
|
o,
|
|
899
899
|
u
|
|
900
900
|
);
|
|
901
901
|
},
|
|
902
|
-
list: async (
|
|
902
|
+
list: async (a, s) => {
|
|
903
903
|
const o = await e.resourceServers.list(
|
|
904
|
-
|
|
905
|
-
|
|
904
|
+
a,
|
|
905
|
+
s
|
|
906
906
|
);
|
|
907
|
-
if (!n ||
|
|
907
|
+
if (!n || a === n)
|
|
908
908
|
return o;
|
|
909
909
|
const i = await e.resourceServers.list(n), u = new Map(
|
|
910
910
|
i.resource_servers.map((l) => [l.identifier, l])
|
|
911
911
|
), c = o.resource_servers.map(
|
|
912
|
-
(l) =>
|
|
912
|
+
(l) => K(
|
|
913
913
|
l,
|
|
914
914
|
u.get(l.identifier) ?? null
|
|
915
915
|
)
|
|
@@ -925,10 +925,10 @@ function Te(e, t) {
|
|
|
925
925
|
// - branding: Fall back to control plane branding/themes
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
|
-
function
|
|
929
|
-
return
|
|
928
|
+
function X(e, t) {
|
|
929
|
+
return Ce(e, t);
|
|
930
930
|
}
|
|
931
|
-
function
|
|
931
|
+
function Te(e) {
|
|
932
932
|
return async (t, n) => {
|
|
933
933
|
const r = t.var.user;
|
|
934
934
|
return (r == null ? void 0 : r.tenant_id) === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
@@ -938,44 +938,44 @@ function Pe(e) {
|
|
|
938
938
|
return async (t, n) => {
|
|
939
939
|
if (!e.accessControl)
|
|
940
940
|
return n();
|
|
941
|
-
const { controlPlaneTenantId: r } = e.accessControl,
|
|
941
|
+
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id, o = a || s;
|
|
942
942
|
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(
|
|
943
|
+
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(V);
|
|
944
944
|
if (!i && o && l && (t.set("tenant_id", o), i = o), !i)
|
|
945
|
-
throw new
|
|
945
|
+
throw new S(400, {
|
|
946
946
|
message: "Tenant ID not found in request"
|
|
947
947
|
});
|
|
948
|
-
if (!
|
|
949
|
-
|
|
948
|
+
if (!le(
|
|
949
|
+
s,
|
|
950
950
|
i,
|
|
951
951
|
r,
|
|
952
|
-
|
|
952
|
+
a
|
|
953
953
|
))
|
|
954
|
-
throw new
|
|
954
|
+
throw new S(403, {
|
|
955
955
|
message: `Access denied to tenant ${i}`
|
|
956
956
|
});
|
|
957
957
|
return n();
|
|
958
958
|
};
|
|
959
959
|
}
|
|
960
|
-
function
|
|
960
|
+
function be(e) {
|
|
961
961
|
return async (t, n) => {
|
|
962
962
|
if (!e.subdomainRouting)
|
|
963
963
|
return n();
|
|
964
964
|
const {
|
|
965
965
|
baseDomain: r,
|
|
966
|
-
reservedSubdomains:
|
|
967
|
-
resolveSubdomain:
|
|
966
|
+
reservedSubdomains: a = [],
|
|
967
|
+
resolveSubdomain: s
|
|
968
968
|
} = e.subdomainRouting, o = t.req.header("host") || "";
|
|
969
969
|
let i = null;
|
|
970
970
|
if (o.endsWith(r)) {
|
|
971
971
|
const c = o.slice(0, -(r.length + 1));
|
|
972
972
|
c && !c.includes(".") && (i = c);
|
|
973
973
|
}
|
|
974
|
-
if (i &&
|
|
974
|
+
if (i && a.includes(i) && (i = null), !i)
|
|
975
975
|
return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
976
976
|
let u = null;
|
|
977
|
-
if (
|
|
978
|
-
u = await
|
|
977
|
+
if (s)
|
|
978
|
+
u = await s(i);
|
|
979
979
|
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
|
|
980
980
|
try {
|
|
981
981
|
const c = await t.env.data.organizations.get(
|
|
@@ -986,41 +986,41 @@ function Ae(e) {
|
|
|
986
986
|
} catch {
|
|
987
987
|
}
|
|
988
988
|
if (!u)
|
|
989
|
-
throw new
|
|
989
|
+
throw new S(404, {
|
|
990
990
|
message: `Tenant not found for subdomain: ${i}`
|
|
991
991
|
});
|
|
992
992
|
return t.set("tenant_id", u), n();
|
|
993
993
|
};
|
|
994
994
|
}
|
|
995
|
-
function
|
|
995
|
+
function Ae(e) {
|
|
996
996
|
return async (t, n) => {
|
|
997
997
|
if (!e.databaseIsolation)
|
|
998
998
|
return n();
|
|
999
999
|
const r = t.var.tenant_id;
|
|
1000
1000
|
if (!r)
|
|
1001
|
-
throw new
|
|
1001
|
+
throw new S(400, {
|
|
1002
1002
|
message: "Tenant ID not found in request"
|
|
1003
1003
|
});
|
|
1004
1004
|
try {
|
|
1005
|
-
const
|
|
1006
|
-
t.env.data =
|
|
1007
|
-
} catch (
|
|
1005
|
+
const a = await e.databaseIsolation.getAdapters(r);
|
|
1006
|
+
t.env.data = a;
|
|
1007
|
+
} catch (a) {
|
|
1008
1008
|
throw console.error(
|
|
1009
1009
|
`Failed to resolve database for tenant ${r}:`,
|
|
1010
|
-
|
|
1011
|
-
), new
|
|
1010
|
+
a
|
|
1011
|
+
), new S(500, {
|
|
1012
1012
|
message: "Failed to resolve tenant database"
|
|
1013
1013
|
});
|
|
1014
1014
|
}
|
|
1015
1015
|
return n();
|
|
1016
1016
|
};
|
|
1017
1017
|
}
|
|
1018
|
-
function
|
|
1019
|
-
const t =
|
|
1020
|
-
return async (
|
|
1021
|
-
}), await n(
|
|
1022
|
-
}), await r(
|
|
1023
|
-
}),
|
|
1018
|
+
function Y(e) {
|
|
1019
|
+
const t = be(e), n = Pe(e), r = Ae(e);
|
|
1020
|
+
return async (a, s) => (await t(a, async () => {
|
|
1021
|
+
}), await n(a, async () => {
|
|
1022
|
+
}), await r(a, async () => {
|
|
1023
|
+
}), s());
|
|
1024
1024
|
}
|
|
1025
1025
|
function Fe(e) {
|
|
1026
1026
|
const {
|
|
@@ -1028,9 +1028,9 @@ function Fe(e) {
|
|
|
1028
1028
|
controlPlane: n,
|
|
1029
1029
|
controlPlane: {
|
|
1030
1030
|
tenantId: r = "control_plane",
|
|
1031
|
-
clientId:
|
|
1031
|
+
clientId: a
|
|
1032
1032
|
} = {},
|
|
1033
|
-
sync:
|
|
1033
|
+
sync: s = { resourceServers: !0, roles: !0 },
|
|
1034
1034
|
defaultPermissions: o = ["tenant:admin"],
|
|
1035
1035
|
requireOrganizationMatch: i = !1,
|
|
1036
1036
|
managementApiExtensions: u = [],
|
|
@@ -1040,39 +1040,45 @@ function Fe(e) {
|
|
|
1040
1040
|
...d
|
|
1041
1041
|
} = e;
|
|
1042
1042
|
let f = t, m = t;
|
|
1043
|
-
n && (f =
|
|
1043
|
+
n && (f = X(t, {
|
|
1044
1044
|
controlPlaneTenantId: r,
|
|
1045
|
-
controlPlaneClientId:
|
|
1045
|
+
controlPlaneClientId: a
|
|
1046
1046
|
}), m = {
|
|
1047
1047
|
...t,
|
|
1048
1048
|
multiTenancyConfig: {
|
|
1049
1049
|
controlPlaneTenantId: r,
|
|
1050
|
-
controlPlaneClientId:
|
|
1050
|
+
controlPlaneClientId: a
|
|
1051
1051
|
}
|
|
1052
1052
|
});
|
|
1053
|
-
const w =
|
|
1054
|
-
resourceServers:
|
|
1055
|
-
roles:
|
|
1056
|
-
} : { resourceServers: !1, roles: !1 },
|
|
1053
|
+
const w = s !== !1, C = w ? {
|
|
1054
|
+
resourceServers: s.resourceServers ?? !0,
|
|
1055
|
+
roles: s.roles ?? !0
|
|
1056
|
+
} : { resourceServers: !1, roles: !1 }, P = {
|
|
1057
1057
|
controlPlaneTenantId: r,
|
|
1058
|
-
getChildTenantIds: l ?? (async () => (await
|
|
1059
|
-
(
|
|
1058
|
+
getChildTenantIds: l ?? (async () => (await M(
|
|
1059
|
+
(v) => f.tenants.list(v),
|
|
1060
1060
|
"tenants",
|
|
1061
1061
|
{ cursorField: "id", pageSize: 100 }
|
|
1062
|
-
)).filter((
|
|
1062
|
+
)).filter((v) => v.id !== r).map((v) => v.id)),
|
|
1063
1063
|
getAdapters: g ?? (async () => f),
|
|
1064
1064
|
getControlPlaneAdapters: async () => f,
|
|
1065
|
-
sync:
|
|
1066
|
-
}, { entityHooks:
|
|
1065
|
+
sync: C
|
|
1066
|
+
}, { entityHooks: b, tenantHooks: p } = we(P), T = {
|
|
1067
1067
|
resourceServers: [
|
|
1068
|
-
|
|
1068
|
+
b.resourceServers,
|
|
1069
1069
|
...(c == null ? void 0 : c.resourceServers) ?? []
|
|
1070
1070
|
],
|
|
1071
|
-
roles: [
|
|
1071
|
+
roles: [b.roles, ...(c == null ? void 0 : c.roles) ?? []],
|
|
1072
1072
|
connections: (c == null ? void 0 : c.connections) ?? [],
|
|
1073
1073
|
tenants: (c == null ? void 0 : c.tenants) ?? [],
|
|
1074
1074
|
rolePermissions: (c == null ? void 0 : c.rolePermissions) ?? []
|
|
1075
|
-
},
|
|
1075
|
+
}, y = J({
|
|
1076
|
+
accessControl: {
|
|
1077
|
+
controlPlaneTenantId: r,
|
|
1078
|
+
requireOrganizationMatch: i,
|
|
1079
|
+
defaultPermissions: o
|
|
1080
|
+
}
|
|
1081
|
+
}), F = k(
|
|
1076
1082
|
{
|
|
1077
1083
|
accessControl: {
|
|
1078
1084
|
controlPlaneTenantId: r,
|
|
@@ -1080,35 +1086,47 @@ function Fe(e) {
|
|
|
1080
1086
|
defaultPermissions: o
|
|
1081
1087
|
}
|
|
1082
1088
|
},
|
|
1083
|
-
{ tenants:
|
|
1084
|
-
|
|
1089
|
+
{ tenants: {
|
|
1090
|
+
async beforeCreate(A, v) {
|
|
1091
|
+
return y.beforeCreate && (v = await y.beforeCreate(A, v)), p.beforeCreate && (v = await p.beforeCreate(A, v)), v;
|
|
1092
|
+
},
|
|
1093
|
+
async afterCreate(A, v) {
|
|
1094
|
+
var $, I;
|
|
1095
|
+
await (($ = y.afterCreate) == null ? void 0 : $.call(y, A, v)), await ((I = p.afterCreate) == null ? void 0 : I.call(p, A, v));
|
|
1096
|
+
},
|
|
1097
|
+
async beforeDelete(A, v) {
|
|
1098
|
+
var $, I;
|
|
1099
|
+
await (($ = y.beforeDelete) == null ? void 0 : $.call(y, A, v)), await ((I = p.beforeDelete) == null ? void 0 : I.call(p, A, v));
|
|
1100
|
+
}
|
|
1101
|
+
} }
|
|
1102
|
+
), { app: D } = oe({
|
|
1085
1103
|
dataAdapter: f,
|
|
1086
1104
|
managementDataAdapter: m,
|
|
1087
1105
|
...d,
|
|
1088
|
-
entityHooks:
|
|
1106
|
+
entityHooks: T,
|
|
1089
1107
|
managementApiExtensions: [
|
|
1090
1108
|
...u,
|
|
1091
|
-
{ path: "/tenants", router:
|
|
1109
|
+
{ path: "/tenants", router: F }
|
|
1092
1110
|
]
|
|
1093
1111
|
});
|
|
1094
|
-
return
|
|
1112
|
+
return D.use(
|
|
1095
1113
|
"/api/v2/*",
|
|
1096
|
-
|
|
1097
|
-
), w &&
|
|
1114
|
+
Te(r)
|
|
1115
|
+
), w && D.use("/api/v2/*", ve()), { app: D, controlPlaneTenantId: r };
|
|
1098
1116
|
}
|
|
1099
|
-
function
|
|
1100
|
-
const t =
|
|
1117
|
+
function De(e) {
|
|
1118
|
+
const t = N(e);
|
|
1101
1119
|
return {
|
|
1102
1120
|
name: "multi-tenancy",
|
|
1103
1121
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1104
|
-
middleware:
|
|
1122
|
+
middleware: Y(e),
|
|
1105
1123
|
// Provide lifecycle hooks
|
|
1106
1124
|
hooks: t,
|
|
1107
1125
|
// Mount tenant management routes
|
|
1108
1126
|
routes: [
|
|
1109
1127
|
{
|
|
1110
1128
|
path: "/management",
|
|
1111
|
-
handler:
|
|
1129
|
+
handler: k(e, t)
|
|
1112
1130
|
}
|
|
1113
1131
|
],
|
|
1114
1132
|
// Called when plugin is registered
|
|
@@ -1121,8 +1139,8 @@ function Me(e) {
|
|
|
1121
1139
|
}
|
|
1122
1140
|
};
|
|
1123
1141
|
}
|
|
1124
|
-
function
|
|
1125
|
-
const t = e.accessControl ?
|
|
1142
|
+
function N(e) {
|
|
1143
|
+
const t = e.accessControl ? ce(e.accessControl) : {}, n = e.databaseIsolation ? ue(e.databaseIsolation) : {}, r = J(e);
|
|
1126
1144
|
return {
|
|
1127
1145
|
...t,
|
|
1128
1146
|
...n,
|
|
@@ -1130,13 +1148,13 @@ function j(e) {
|
|
|
1130
1148
|
};
|
|
1131
1149
|
}
|
|
1132
1150
|
function Ie(e) {
|
|
1133
|
-
const t = new
|
|
1134
|
-
return t.route("/tenants",
|
|
1151
|
+
const t = new ee(), n = N(e);
|
|
1152
|
+
return t.route("/tenants", k(e, n)), t;
|
|
1135
1153
|
}
|
|
1136
|
-
function
|
|
1154
|
+
function Me(e) {
|
|
1137
1155
|
return {
|
|
1138
|
-
hooks:
|
|
1139
|
-
middleware:
|
|
1156
|
+
hooks: N(e),
|
|
1157
|
+
middleware: Y(e),
|
|
1140
1158
|
app: Ie(e),
|
|
1141
1159
|
config: e,
|
|
1142
1160
|
/**
|
|
@@ -1149,7 +1167,7 @@ function Oe(e) {
|
|
|
1149
1167
|
*/
|
|
1150
1168
|
wrapAdapters: (t, n) => {
|
|
1151
1169
|
var r;
|
|
1152
|
-
return
|
|
1170
|
+
return X(t, {
|
|
1153
1171
|
controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
|
|
1154
1172
|
controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
|
|
1155
1173
|
});
|
|
@@ -1157,23 +1175,23 @@ function Oe(e) {
|
|
|
1157
1175
|
};
|
|
1158
1176
|
}
|
|
1159
1177
|
export {
|
|
1160
|
-
|
|
1178
|
+
ce as createAccessControlHooks,
|
|
1161
1179
|
Pe as createAccessControlMiddleware,
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1180
|
+
Te as createControlPlaneTenantMiddleware,
|
|
1181
|
+
ue as createDatabaseHooks,
|
|
1182
|
+
Ae as createDatabaseMiddleware,
|
|
1165
1183
|
Ie as createMultiTenancy,
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1184
|
+
N as createMultiTenancyHooks,
|
|
1185
|
+
Y as createMultiTenancyMiddleware,
|
|
1186
|
+
De as createMultiTenancyPlugin,
|
|
1169
1187
|
ve as createProtectSyncedMiddleware,
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1188
|
+
J as createProvisioningHooks,
|
|
1189
|
+
Ce as createRuntimeFallbackAdapter,
|
|
1190
|
+
be as createSubdomainMiddleware,
|
|
1173
1191
|
we as createSyncHooks,
|
|
1174
|
-
|
|
1192
|
+
k as createTenantsOpenAPIRouter,
|
|
1175
1193
|
Fe as initMultiTenant,
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1194
|
+
Me as setupMultiTenancy,
|
|
1195
|
+
le as validateTenantAccess,
|
|
1196
|
+
X as withRuntimeFallback
|
|
1179
1197
|
};
|