@authhero/multi-tenancy 14.20.1 → 14.20.2
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.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { MANAGEMENT_API_SCOPES as
|
|
6
|
-
import { OpenAPIHono as
|
|
7
|
-
function
|
|
1
|
+
var ne = Object.defineProperty;
|
|
2
|
+
var re = (e, t, n) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var E = (e, t, n) => re(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { Hono as ae } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as se, MANAGEMENT_API_AUDIENCE as Y, fetchAll as D, auth0QuerySchema as oe, tenantSchema as O, tenantInsertSchema as G, deepMergePatch as ie, connectionSchema as ce, connectionOptionsSchema as le, init as ue } from "authhero";
|
|
6
|
+
import { OpenAPIHono as de, createRoute as k, z as A } from "@hono/zod-openapi";
|
|
7
|
+
function fe(e) {
|
|
8
8
|
const { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
9
9
|
return {
|
|
10
10
|
async onTenantAccessValidation(r, a) {
|
|
@@ -18,13 +18,13 @@ function de(e) {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function me(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 ge(e) {
|
|
28
28
|
return {
|
|
29
29
|
async resolveDataAdapters(t) {
|
|
30
30
|
try {
|
|
@@ -39,20 +39,20 @@ function me(e) {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function we(e) {
|
|
43
43
|
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function Z(e) {
|
|
46
46
|
return {
|
|
47
47
|
async beforeCreate(t, n) {
|
|
48
48
|
return !n.audience && n.id ? {
|
|
49
49
|
...n,
|
|
50
|
-
audience:
|
|
50
|
+
audience: we(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 he(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;
|
|
@@ -83,7 +83,7 @@ function Y(e) {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
async function
|
|
86
|
+
async function he(e, t, n) {
|
|
87
87
|
const {
|
|
88
88
|
controlPlaneTenantId: r,
|
|
89
89
|
defaultPermissions: a,
|
|
@@ -100,14 +100,14 @@ async function we(e, t, n) {
|
|
|
100
100
|
}
|
|
101
101
|
);
|
|
102
102
|
let g;
|
|
103
|
-
if (i && (g = await
|
|
103
|
+
if (i && (g = await ye(
|
|
104
104
|
e,
|
|
105
105
|
r,
|
|
106
106
|
c,
|
|
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 pe(
|
|
111
111
|
e,
|
|
112
112
|
r,
|
|
113
113
|
d.sub
|
|
@@ -123,10 +123,10 @@ async function we(e, t, n) {
|
|
|
123
123
|
l.id
|
|
124
124
|
// organizationId
|
|
125
125
|
);
|
|
126
|
-
} catch (
|
|
126
|
+
} catch (f) {
|
|
127
127
|
console.warn(
|
|
128
128
|
`Failed to add creator ${d.sub} to organization ${l.id}:`,
|
|
129
|
-
|
|
129
|
+
f
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -136,7 +136,7 @@ async function we(e, t, n) {
|
|
|
136
136
|
`Would grant permissions ${a.join(", ")} to organization ${l.id}`
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
|
-
async function
|
|
139
|
+
async function pe(e, t, n) {
|
|
140
140
|
const r = await e.adapters.userRoles.list(
|
|
141
141
|
t,
|
|
142
142
|
n,
|
|
@@ -155,14 +155,14 @@ async function he(e, t, n) {
|
|
|
155
155
|
return !0;
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
|
-
async function
|
|
158
|
+
async function ye(e, t, n, r) {
|
|
159
159
|
const s = (await e.adapters.roles.list(t, {})).roles.find((o) => o.name === n);
|
|
160
160
|
if (s)
|
|
161
161
|
return s.id;
|
|
162
162
|
const i = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}), c =
|
|
165
|
+
}), c = Y, u = se.map((o) => ({
|
|
166
166
|
role_id: i.id,
|
|
167
167
|
resource_server_identifier: c,
|
|
168
168
|
permission_name: o.value
|
|
@@ -173,7 +173,7 @@ async function pe(e, t, n, r) {
|
|
|
173
173
|
u
|
|
174
174
|
), i.id;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function H(e, t, n = () => !0) {
|
|
177
177
|
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e, i = /* @__PURE__ */ new Map();
|
|
178
178
|
async function c(l, g, d) {
|
|
179
179
|
return (await t(l).list(g, {
|
|
@@ -184,21 +184,21 @@ function G(e, t, n = () => !0) {
|
|
|
184
184
|
async function u(l) {
|
|
185
185
|
const g = await a(), d = t(await s(r));
|
|
186
186
|
await Promise.all(
|
|
187
|
-
g.map(async (
|
|
187
|
+
g.map(async (m) => {
|
|
188
188
|
try {
|
|
189
|
-
const
|
|
189
|
+
const f = await s(m), w = t(f), y = {
|
|
190
190
|
...d.transform(l),
|
|
191
191
|
is_system: !0
|
|
192
|
-
}, _ = await c(
|
|
192
|
+
}, _ = await c(f, m, l.name), b = _ ? w.getId(_) : void 0;
|
|
193
193
|
if (_ && b) {
|
|
194
|
-
const
|
|
195
|
-
await w.update(
|
|
194
|
+
const I = w.preserveOnUpdate ? w.preserveOnUpdate(_, y) : y;
|
|
195
|
+
await w.update(m, b, I);
|
|
196
196
|
} else
|
|
197
|
-
await w.create(
|
|
198
|
-
} catch (
|
|
197
|
+
await w.create(m, y);
|
|
198
|
+
} catch (f) {
|
|
199
199
|
console.error(
|
|
200
|
-
`Failed to sync ${d.listKey} "${l.name}" to tenant "${
|
|
201
|
-
|
|
200
|
+
`Failed to sync ${d.listKey} "${l.name}" to tenant "${m}":`,
|
|
201
|
+
f
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
})
|
|
@@ -209,12 +209,12 @@ function G(e, t, n = () => !0) {
|
|
|
209
209
|
await Promise.all(
|
|
210
210
|
g.map(async (d) => {
|
|
211
211
|
try {
|
|
212
|
-
const
|
|
213
|
-
w &&
|
|
214
|
-
} catch (
|
|
212
|
+
const m = await s(d), f = t(m), w = await c(m, d, l), T = w ? f.getId(w) : void 0;
|
|
213
|
+
w && T && await f.remove(d, T);
|
|
214
|
+
} catch (m) {
|
|
215
215
|
console.error(
|
|
216
216
|
`Failed to delete entity "${l}" from tenant "${d}":`,
|
|
217
|
-
|
|
217
|
+
m
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
})
|
|
@@ -229,8 +229,8 @@ function G(e, t, n = () => !0) {
|
|
|
229
229
|
},
|
|
230
230
|
beforeDelete: async (l, g) => {
|
|
231
231
|
if (l.tenantId !== r) return;
|
|
232
|
-
const
|
|
233
|
-
|
|
232
|
+
const m = await t(l.adapters).get(l.tenantId, g);
|
|
233
|
+
m && n(m) && i.set(g, m);
|
|
234
234
|
},
|
|
235
235
|
afterDelete: async (l, g) => {
|
|
236
236
|
if (l.tenantId !== r) return;
|
|
@@ -239,29 +239,29 @@ function G(e, t, n = () => !0) {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
function
|
|
242
|
+
function W(e, t, n = () => !0) {
|
|
243
243
|
const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: s } = e;
|
|
244
244
|
return {
|
|
245
245
|
async afterCreate(i, c) {
|
|
246
246
|
if (c.id !== r)
|
|
247
247
|
try {
|
|
248
248
|
const u = await a(), o = await s(c.id), l = t(u), g = t(o), d = await D(
|
|
249
|
-
(
|
|
249
|
+
(m) => l.listPaginated(r, m),
|
|
250
250
|
l.listKey,
|
|
251
251
|
{ cursorField: "id", pageSize: 100 }
|
|
252
252
|
);
|
|
253
253
|
await Promise.all(
|
|
254
|
-
d.filter((
|
|
254
|
+
d.filter((m) => n(m)).map(async (m) => {
|
|
255
255
|
try {
|
|
256
|
-
const
|
|
256
|
+
const f = l.transform(m);
|
|
257
257
|
await g.create(c.id, {
|
|
258
|
-
...
|
|
258
|
+
...f,
|
|
259
259
|
is_system: !0
|
|
260
260
|
});
|
|
261
|
-
} catch (
|
|
261
|
+
} catch (f) {
|
|
262
262
|
console.error(
|
|
263
263
|
`Failed to sync entity to new tenant "${c.id}":`,
|
|
264
|
-
|
|
264
|
+
f
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
})
|
|
@@ -275,7 +275,7 @@ function H(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 W = (e) => ({
|
|
|
293
293
|
token_lifetime: t.token_lifetime,
|
|
294
294
|
token_lifetime_for_web: t.token_lifetime_for_web
|
|
295
295
|
})
|
|
296
|
-
}),
|
|
296
|
+
}), K = (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,28 +308,28 @@ const W = (e) => ({
|
|
|
308
308
|
description: t.description
|
|
309
309
|
})
|
|
310
310
|
});
|
|
311
|
-
function
|
|
311
|
+
function Q(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, s = (
|
|
315
|
+
function ve(e) {
|
|
316
|
+
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, a = t.roles ?? !0, s = (f) => Q(f) ? n.resourceServers ? n.resourceServers(f) : !0 : !1, i = (f) => Q(f) ? n.roles ? n.roles(f) : !0 : !1, c = r ? H(
|
|
317
317
|
e,
|
|
318
|
-
|
|
318
|
+
L,
|
|
319
319
|
s
|
|
320
|
-
) : void 0, u = a ?
|
|
320
|
+
) : void 0, u = a ? H(e, K, i) : void 0, o = r ? W(
|
|
321
321
|
e,
|
|
322
|
-
|
|
322
|
+
L,
|
|
323
323
|
s
|
|
324
|
-
) : void 0, l = a ?
|
|
324
|
+
) : void 0, l = a ? W(
|
|
325
325
|
e,
|
|
326
|
-
|
|
326
|
+
K,
|
|
327
327
|
i
|
|
328
328
|
) : void 0, g = a ? {
|
|
329
|
-
async afterCreate(
|
|
330
|
-
var
|
|
329
|
+
async afterCreate(f, w) {
|
|
330
|
+
var T;
|
|
331
331
|
if (w.id !== e.controlPlaneTenantId) {
|
|
332
|
-
await ((
|
|
332
|
+
await ((T = l == null ? void 0 : l.afterCreate) == null ? void 0 : T.call(l, f, w));
|
|
333
333
|
try {
|
|
334
334
|
const y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), b = await D(
|
|
335
335
|
(h) => y.roles.list(
|
|
@@ -338,28 +338,28 @@ function ye(e) {
|
|
|
338
338
|
),
|
|
339
339
|
"roles",
|
|
340
340
|
{ cursorField: "id", pageSize: 100 }
|
|
341
|
-
),
|
|
341
|
+
), I = /* @__PURE__ */ new Map();
|
|
342
342
|
for (const h of b.filter(
|
|
343
|
-
(
|
|
343
|
+
(C) => {
|
|
344
344
|
var p;
|
|
345
|
-
return ((p = n.roles) == null ? void 0 : p.call(n,
|
|
345
|
+
return ((p = n.roles) == null ? void 0 : p.call(n, C)) ?? !0;
|
|
346
346
|
}
|
|
347
347
|
)) {
|
|
348
|
-
const
|
|
348
|
+
const C = await d(
|
|
349
349
|
_,
|
|
350
350
|
w.id,
|
|
351
351
|
h.name
|
|
352
352
|
);
|
|
353
|
-
|
|
353
|
+
C && I.set(h.name, C.id);
|
|
354
354
|
}
|
|
355
355
|
for (const h of b.filter(
|
|
356
|
-
(
|
|
356
|
+
(C) => {
|
|
357
357
|
var p;
|
|
358
|
-
return ((p = n.roles) == null ? void 0 : p.call(n,
|
|
358
|
+
return ((p = n.roles) == null ? void 0 : p.call(n, C)) ?? !0;
|
|
359
359
|
}
|
|
360
360
|
)) {
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
361
|
+
const C = I.get(h.name);
|
|
362
|
+
if (C)
|
|
363
363
|
try {
|
|
364
364
|
const p = await y.rolePermissions.list(
|
|
365
365
|
e.controlPlaneTenantId,
|
|
@@ -368,11 +368,11 @@ function ye(e) {
|
|
|
368
368
|
);
|
|
369
369
|
p.length > 0 && await _.rolePermissions.assign(
|
|
370
370
|
w.id,
|
|
371
|
-
|
|
372
|
-
p.map((
|
|
373
|
-
role_id:
|
|
374
|
-
resource_server_identifier:
|
|
375
|
-
permission_name:
|
|
371
|
+
C,
|
|
372
|
+
p.map((F) => ({
|
|
373
|
+
role_id: C,
|
|
374
|
+
resource_server_identifier: F.resource_server_identifier,
|
|
375
|
+
permission_name: F.permission_name
|
|
376
376
|
}))
|
|
377
377
|
);
|
|
378
378
|
} catch (p) {
|
|
@@ -391,9 +391,9 @@ function ye(e) {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
} : void 0;
|
|
394
|
-
async function d(
|
|
395
|
-
return (await
|
|
396
|
-
q: `name:${
|
|
394
|
+
async function d(f, w, T) {
|
|
395
|
+
return (await f.roles.list(w, {
|
|
396
|
+
q: `name:${T}`,
|
|
397
397
|
per_page: 1
|
|
398
398
|
})).roles[0] ?? null;
|
|
399
399
|
}
|
|
@@ -403,15 +403,15 @@ function ye(e) {
|
|
|
403
403
|
roles: u
|
|
404
404
|
},
|
|
405
405
|
tenantHooks: {
|
|
406
|
-
async afterCreate(
|
|
407
|
-
const
|
|
406
|
+
async afterCreate(f, w) {
|
|
407
|
+
const T = [
|
|
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
|
-
for (const _ of
|
|
411
|
+
for (const _ of T)
|
|
412
412
|
if (_)
|
|
413
413
|
try {
|
|
414
|
-
await _(
|
|
414
|
+
await _(f, w);
|
|
415
415
|
} catch (b) {
|
|
416
416
|
y.push(b instanceof Error ? b : new Error(String(b)));
|
|
417
417
|
}
|
|
@@ -425,7 +425,7 @@ function ye(e) {
|
|
|
425
425
|
}
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
|
-
var
|
|
428
|
+
var P = 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 A = 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
|
/**
|
|
@@ -452,29 +452,29 @@ var A = class extends Error {
|
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
454
|
function N(e, t) {
|
|
455
|
-
const n = new
|
|
455
|
+
const n = new de();
|
|
456
456
|
return n.openapi(
|
|
457
|
-
|
|
457
|
+
k({
|
|
458
458
|
tags: ["tenants"],
|
|
459
459
|
method: "get",
|
|
460
460
|
path: "/",
|
|
461
461
|
request: {
|
|
462
|
-
query:
|
|
462
|
+
query: oe
|
|
463
463
|
},
|
|
464
464
|
security: [
|
|
465
465
|
{
|
|
466
|
-
Bearer: []
|
|
466
|
+
Bearer: ["read:tenants", "auth:read"]
|
|
467
467
|
}
|
|
468
468
|
],
|
|
469
469
|
responses: {
|
|
470
470
|
200: {
|
|
471
471
|
content: {
|
|
472
472
|
"application/json": {
|
|
473
|
-
schema:
|
|
474
|
-
tenants:
|
|
475
|
-
start:
|
|
476
|
-
limit:
|
|
477
|
-
length:
|
|
473
|
+
schema: A.object({
|
|
474
|
+
tenants: A.array(O),
|
|
475
|
+
start: A.number().optional(),
|
|
476
|
+
limit: A.number().optional(),
|
|
477
|
+
length: A.number().optional()
|
|
478
478
|
})
|
|
479
479
|
}
|
|
480
480
|
},
|
|
@@ -483,59 +483,59 @@ function N(e, t) {
|
|
|
483
483
|
}
|
|
484
484
|
}),
|
|
485
485
|
async (r) => {
|
|
486
|
-
var
|
|
486
|
+
var w, T, y, _, b, I;
|
|
487
487
|
const a = r.req.valid("query"), { page: s, per_page: i, include_totals: c, q: u } = a, o = r.var.user, l = (o == null ? void 0 : o.permissions) || [];
|
|
488
|
-
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
489
|
-
const
|
|
488
|
+
if (!!!((o == null ? void 0 : o.org_id) ?? r.var.organization_id) && (l.includes("auth:read") || l.includes("admin:organizations"))) {
|
|
489
|
+
const h = await r.env.data.tenants.list({
|
|
490
490
|
page: s,
|
|
491
491
|
per_page: i,
|
|
492
492
|
include_totals: c,
|
|
493
493
|
q: u
|
|
494
494
|
});
|
|
495
495
|
return c ? r.json({
|
|
496
|
-
tenants:
|
|
497
|
-
start: ((
|
|
498
|
-
limit: ((
|
|
499
|
-
length:
|
|
500
|
-
}) : r.json({ tenants:
|
|
496
|
+
tenants: h.tenants,
|
|
497
|
+
start: ((w = h.totals) == null ? void 0 : w.start) ?? 0,
|
|
498
|
+
limit: ((T = h.totals) == null ? void 0 : T.limit) ?? i,
|
|
499
|
+
length: h.tenants.length
|
|
500
|
+
}) : r.json({ tenants: h.tenants });
|
|
501
501
|
}
|
|
502
|
-
const
|
|
503
|
-
if (
|
|
504
|
-
const
|
|
505
|
-
(
|
|
506
|
-
|
|
502
|
+
const m = ((y = e.accessControl) == null ? void 0 : y.controlPlaneTenantId) ?? ((_ = r.env.data.multiTenancyConfig) == null ? void 0 : _.controlPlaneTenantId);
|
|
503
|
+
if (m && (o != null && o.sub)) {
|
|
504
|
+
const C = (await D(
|
|
505
|
+
(M) => r.env.data.userOrganizations.listUserOrganizations(
|
|
506
|
+
m,
|
|
507
507
|
o.sub,
|
|
508
|
-
|
|
508
|
+
M
|
|
509
509
|
),
|
|
510
510
|
"organizations"
|
|
511
|
-
)).map((
|
|
512
|
-
if (
|
|
511
|
+
)).map((M) => M.name);
|
|
512
|
+
if (C.length === 0)
|
|
513
513
|
return c ? r.json({
|
|
514
514
|
tenants: [],
|
|
515
515
|
start: 0,
|
|
516
516
|
limit: i ?? 50,
|
|
517
517
|
length: 0
|
|
518
518
|
}) : r.json({ tenants: [] });
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
519
|
+
const p = C.length, F = s ?? 0, $ = i ?? 50, R = F * $, S = C.slice(R, R + $);
|
|
520
|
+
if (S.length === 0)
|
|
521
521
|
return c ? r.json({
|
|
522
522
|
tenants: [],
|
|
523
|
-
start:
|
|
524
|
-
limit:
|
|
525
|
-
length:
|
|
523
|
+
start: R,
|
|
524
|
+
limit: $,
|
|
525
|
+
length: p
|
|
526
526
|
}) : r.json({ tenants: [] });
|
|
527
|
-
const
|
|
528
|
-
q:
|
|
529
|
-
per_page:
|
|
527
|
+
const v = S.map((M) => `id:${M}`).join(" OR "), j = u ? `(${v}) AND (${u})` : v, z = await r.env.data.tenants.list({
|
|
528
|
+
q: j,
|
|
529
|
+
per_page: $,
|
|
530
530
|
include_totals: !1
|
|
531
531
|
// We calculate totals from accessibleTenantIds
|
|
532
532
|
});
|
|
533
533
|
return c ? r.json({
|
|
534
|
-
tenants:
|
|
535
|
-
start:
|
|
536
|
-
limit:
|
|
537
|
-
length:
|
|
538
|
-
}) : r.json({ tenants:
|
|
534
|
+
tenants: z.tenants,
|
|
535
|
+
start: R,
|
|
536
|
+
limit: $,
|
|
537
|
+
length: p
|
|
538
|
+
}) : r.json({ tenants: z.tenants });
|
|
539
539
|
}
|
|
540
540
|
const f = await r.env.data.tenants.list({
|
|
541
541
|
page: s,
|
|
@@ -545,13 +545,13 @@ function N(e, t) {
|
|
|
545
545
|
});
|
|
546
546
|
return c ? r.json({
|
|
547
547
|
tenants: f.tenants,
|
|
548
|
-
start: ((
|
|
549
|
-
limit: ((
|
|
548
|
+
start: ((b = f.totals) == null ? void 0 : b.start) ?? 0,
|
|
549
|
+
limit: ((I = f.totals) == null ? void 0 : I.limit) ?? i,
|
|
550
550
|
length: f.tenants.length
|
|
551
551
|
}) : r.json({ tenants: f.tenants });
|
|
552
552
|
}
|
|
553
553
|
), n.openapi(
|
|
554
|
-
|
|
554
|
+
k({
|
|
555
555
|
tags: ["tenants"],
|
|
556
556
|
method: "post",
|
|
557
557
|
path: "/",
|
|
@@ -559,7 +559,7 @@ function N(e, t) {
|
|
|
559
559
|
body: {
|
|
560
560
|
content: {
|
|
561
561
|
"application/json": {
|
|
562
|
-
schema:
|
|
562
|
+
schema: G
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
}
|
|
@@ -573,7 +573,7 @@ function N(e, t) {
|
|
|
573
573
|
201: {
|
|
574
574
|
content: {
|
|
575
575
|
"application/json": {
|
|
576
|
-
schema:
|
|
576
|
+
schema: O
|
|
577
577
|
}
|
|
578
578
|
},
|
|
579
579
|
description: "Tenant created"
|
|
@@ -590,7 +590,7 @@ function N(e, t) {
|
|
|
590
590
|
var u, o;
|
|
591
591
|
const a = r.var.user;
|
|
592
592
|
if (!(a != null && a.sub))
|
|
593
|
-
throw new
|
|
593
|
+
throw new P(401, {
|
|
594
594
|
message: "Authentication required to create tenants"
|
|
595
595
|
});
|
|
596
596
|
let s = r.req.valid("json");
|
|
@@ -603,13 +603,13 @@ function N(e, t) {
|
|
|
603
603
|
return (o = t.tenants) != null && o.afterCreate && await t.tenants.afterCreate(i, c), r.json(c, 201);
|
|
604
604
|
}
|
|
605
605
|
), n.openapi(
|
|
606
|
-
|
|
606
|
+
k({
|
|
607
607
|
tags: ["tenants"],
|
|
608
608
|
method: "delete",
|
|
609
609
|
path: "/{id}",
|
|
610
610
|
request: {
|
|
611
|
-
params:
|
|
612
|
-
id:
|
|
611
|
+
params: A.object({
|
|
612
|
+
id: A.string()
|
|
613
613
|
})
|
|
614
614
|
},
|
|
615
615
|
security: [
|
|
@@ -635,11 +635,11 @@ function N(e, t) {
|
|
|
635
635
|
if (s) {
|
|
636
636
|
const d = r.var.user;
|
|
637
637
|
if (!(d != null && d.sub))
|
|
638
|
-
throw new
|
|
638
|
+
throw new P(401, {
|
|
639
639
|
message: "Authentication required"
|
|
640
640
|
});
|
|
641
641
|
if (a === s)
|
|
642
|
-
throw new
|
|
642
|
+
throw new P(403, {
|
|
643
643
|
message: "Cannot delete the control plane"
|
|
644
644
|
});
|
|
645
645
|
if (!(await D(
|
|
@@ -650,12 +650,12 @@ function N(e, t) {
|
|
|
650
650
|
),
|
|
651
651
|
"organizations"
|
|
652
652
|
)).some((w) => w.name === a))
|
|
653
|
-
throw new
|
|
653
|
+
throw new P(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 P(404, {
|
|
659
659
|
message: "Tenant not found"
|
|
660
660
|
});
|
|
661
661
|
const c = {
|
|
@@ -665,13 +665,13 @@ function N(e, t) {
|
|
|
665
665
|
return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(c, a), await r.env.data.tenants.remove(a), (g = t.tenants) != null && g.afterDelete && await t.tenants.afterDelete(c, a), r.body(null, 204);
|
|
666
666
|
}
|
|
667
667
|
), n.openapi(
|
|
668
|
-
|
|
668
|
+
k({
|
|
669
669
|
tags: ["tenants", "settings"],
|
|
670
670
|
method: "get",
|
|
671
671
|
path: "/settings",
|
|
672
672
|
request: {
|
|
673
|
-
headers:
|
|
674
|
-
"tenant-id":
|
|
673
|
+
headers: A.object({
|
|
674
|
+
"tenant-id": A.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: O
|
|
687
687
|
}
|
|
688
688
|
},
|
|
689
689
|
description: "Current tenant settings"
|
|
@@ -693,24 +693,24 @@ function N(e, t) {
|
|
|
693
693
|
async (r) => {
|
|
694
694
|
const a = await r.env.data.tenants.get(r.var.tenant_id);
|
|
695
695
|
if (!a)
|
|
696
|
-
throw new
|
|
696
|
+
throw new P(404, {
|
|
697
697
|
message: "Tenant not found"
|
|
698
698
|
});
|
|
699
699
|
return r.json(a);
|
|
700
700
|
}
|
|
701
701
|
), n.openapi(
|
|
702
|
-
|
|
702
|
+
k({
|
|
703
703
|
tags: ["tenants", "settings"],
|
|
704
704
|
method: "patch",
|
|
705
705
|
path: "/settings",
|
|
706
706
|
request: {
|
|
707
|
-
headers:
|
|
708
|
-
"tenant-id":
|
|
707
|
+
headers: A.object({
|
|
708
|
+
"tenant-id": A.string().optional()
|
|
709
709
|
}),
|
|
710
710
|
body: {
|
|
711
711
|
content: {
|
|
712
712
|
"application/json": {
|
|
713
|
-
schema:
|
|
713
|
+
schema: A.object(G.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: O
|
|
728
728
|
}
|
|
729
729
|
},
|
|
730
730
|
description: "Updated tenant settings"
|
|
@@ -734,21 +734,21 @@ function N(e, t) {
|
|
|
734
734
|
async (r) => {
|
|
735
735
|
const a = r.req.valid("json"), { id: s, ...i } = a, c = await r.env.data.tenants.get(r.var.tenant_id);
|
|
736
736
|
if (!c)
|
|
737
|
-
throw new
|
|
737
|
+
throw new P(404, {
|
|
738
738
|
message: "Tenant not found"
|
|
739
739
|
});
|
|
740
|
-
const u =
|
|
740
|
+
const u = ie(c, i);
|
|
741
741
|
await r.env.data.tenants.update(r.var.tenant_id, u);
|
|
742
742
|
const o = await r.env.data.tenants.get(r.var.tenant_id);
|
|
743
743
|
if (!o)
|
|
744
|
-
throw new
|
|
744
|
+
throw new P(500, {
|
|
745
745
|
message: "Failed to retrieve updated tenant"
|
|
746
746
|
});
|
|
747
747
|
return r.json(o);
|
|
748
748
|
}
|
|
749
749
|
), n;
|
|
750
750
|
}
|
|
751
|
-
function
|
|
751
|
+
function _e(e) {
|
|
752
752
|
const t = [
|
|
753
753
|
{
|
|
754
754
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -764,7 +764,7 @@ function ve(e) {
|
|
|
764
764
|
}
|
|
765
765
|
return null;
|
|
766
766
|
}
|
|
767
|
-
async function
|
|
767
|
+
async function Ce(e, t, n) {
|
|
768
768
|
try {
|
|
769
769
|
switch (n.type) {
|
|
770
770
|
case "resource_server": {
|
|
@@ -786,50 +786,50 @@ async function _e(e, t, n) {
|
|
|
786
786
|
return !1;
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
|
-
function
|
|
789
|
+
function Te(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 be() {
|
|
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 = _e(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
|
|
807
|
-
throw new
|
|
808
|
-
message: `This ${
|
|
806
|
+
if (await Ce(e.env.data, r, n))
|
|
807
|
+
throw new P(403, {
|
|
808
|
+
message: `This ${Te(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
|
};
|
|
812
812
|
}
|
|
813
|
-
function
|
|
813
|
+
function B(e, t) {
|
|
814
814
|
const n = t.find(
|
|
815
815
|
(a) => a.strategy === e.strategy
|
|
816
816
|
);
|
|
817
817
|
if (!(n != null && n.options))
|
|
818
818
|
return e;
|
|
819
|
-
const r =
|
|
819
|
+
const r = ce.passthrough().parse({
|
|
820
820
|
...n,
|
|
821
821
|
...e
|
|
822
822
|
});
|
|
823
|
-
return r.options =
|
|
823
|
+
return r.options = le.passthrough().parse({
|
|
824
824
|
...n.options || {},
|
|
825
825
|
...e.options
|
|
826
826
|
}), r;
|
|
827
827
|
}
|
|
828
|
-
function
|
|
828
|
+
function q(e, t) {
|
|
829
829
|
const n = [...t || [], ...e || []];
|
|
830
830
|
return [...new Set(n)];
|
|
831
831
|
}
|
|
832
|
-
function
|
|
832
|
+
function Pe(e, t) {
|
|
833
833
|
if (!(t != null && t.length))
|
|
834
834
|
return e || [];
|
|
835
835
|
if (!(e != null && e.length))
|
|
@@ -841,34 +841,34 @@ function be(e, t) {
|
|
|
841
841
|
n.set(r.value, r);
|
|
842
842
|
return Array.from(n.values());
|
|
843
843
|
}
|
|
844
|
-
function
|
|
844
|
+
function V(e, t) {
|
|
845
845
|
return t ? {
|
|
846
846
|
...e,
|
|
847
|
-
scopes:
|
|
847
|
+
scopes: Pe(
|
|
848
848
|
e.scopes,
|
|
849
849
|
t.scopes
|
|
850
850
|
)
|
|
851
851
|
} : e;
|
|
852
852
|
}
|
|
853
|
-
function
|
|
853
|
+
function J(e, t) {
|
|
854
854
|
return t ? {
|
|
855
855
|
...e,
|
|
856
|
-
callbacks:
|
|
857
|
-
web_origins:
|
|
856
|
+
callbacks: q(e.callbacks, t.callbacks),
|
|
857
|
+
web_origins: q(
|
|
858
858
|
e.web_origins,
|
|
859
859
|
t.web_origins
|
|
860
860
|
),
|
|
861
|
-
allowed_logout_urls:
|
|
861
|
+
allowed_logout_urls: q(
|
|
862
862
|
e.allowed_logout_urls,
|
|
863
863
|
t.allowed_logout_urls
|
|
864
864
|
),
|
|
865
|
-
allowed_origins:
|
|
865
|
+
allowed_origins: q(
|
|
866
866
|
e.allowed_origins,
|
|
867
867
|
t.allowed_origins
|
|
868
868
|
)
|
|
869
869
|
} : e;
|
|
870
870
|
}
|
|
871
|
-
function
|
|
871
|
+
function x(e, t) {
|
|
872
872
|
return {
|
|
873
873
|
...e.resourceServers,
|
|
874
874
|
get: async (n, r) => {
|
|
@@ -882,7 +882,7 @@ function Z(e, t) {
|
|
|
882
882
|
t,
|
|
883
883
|
r
|
|
884
884
|
);
|
|
885
|
-
return
|
|
885
|
+
return V(
|
|
886
886
|
a,
|
|
887
887
|
s
|
|
888
888
|
);
|
|
@@ -904,7 +904,7 @@ function Z(e, t) {
|
|
|
904
904
|
})
|
|
905
905
|
);
|
|
906
906
|
const u = a.resource_servers.map(
|
|
907
|
-
(o) => o.is_system && o.id ?
|
|
907
|
+
(o) => o.is_system && o.id ? V(
|
|
908
908
|
o,
|
|
909
909
|
c.get(o.id) ?? null
|
|
910
910
|
) : o
|
|
@@ -916,10 +916,10 @@ function Z(e, t) {
|
|
|
916
916
|
}
|
|
917
917
|
};
|
|
918
918
|
}
|
|
919
|
-
function
|
|
919
|
+
function Se(e, t) {
|
|
920
920
|
return {
|
|
921
921
|
...e,
|
|
922
|
-
resourceServers:
|
|
922
|
+
resourceServers: x(
|
|
923
923
|
e,
|
|
924
924
|
t.controlPlaneTenantId
|
|
925
925
|
)
|
|
@@ -944,7 +944,7 @@ function Ae(e, t) {
|
|
|
944
944
|
if (!i || !n || a === n)
|
|
945
945
|
return i;
|
|
946
946
|
const c = await e.connections.list(n);
|
|
947
|
-
return
|
|
947
|
+
return B(
|
|
948
948
|
i,
|
|
949
949
|
c.connections || []
|
|
950
950
|
);
|
|
@@ -954,7 +954,7 @@ function Ae(e, t) {
|
|
|
954
954
|
if (!n || a === n)
|
|
955
955
|
return i;
|
|
956
956
|
const c = await e.connections.list(n), u = i.connections.map(
|
|
957
|
-
(o) =>
|
|
957
|
+
(o) => B(
|
|
958
958
|
o,
|
|
959
959
|
c.connections || []
|
|
960
960
|
)
|
|
@@ -976,7 +976,7 @@ function Ae(e, t) {
|
|
|
976
976
|
return i;
|
|
977
977
|
const c = await e.connections.list(n);
|
|
978
978
|
return i.map(
|
|
979
|
-
(u) =>
|
|
979
|
+
(u) => B(
|
|
980
980
|
u,
|
|
981
981
|
c.connections || []
|
|
982
982
|
)
|
|
@@ -995,7 +995,7 @@ function Ae(e, t) {
|
|
|
995
995
|
n,
|
|
996
996
|
r
|
|
997
997
|
);
|
|
998
|
-
return
|
|
998
|
+
return J(i, c);
|
|
999
999
|
},
|
|
1000
1000
|
getByClientId: async (a) => {
|
|
1001
1001
|
const s = await e.clients.getByClientId(a);
|
|
@@ -1008,7 +1008,7 @@ function Ae(e, t) {
|
|
|
1008
1008
|
r
|
|
1009
1009
|
);
|
|
1010
1010
|
return {
|
|
1011
|
-
...
|
|
1011
|
+
...J(s, i),
|
|
1012
1012
|
tenant_id: s.tenant_id
|
|
1013
1013
|
};
|
|
1014
1014
|
}
|
|
@@ -1020,22 +1020,22 @@ function Ae(e, t) {
|
|
|
1020
1020
|
return s || (!n || a === n ? null : e.emailProviders.get(n));
|
|
1021
1021
|
}
|
|
1022
1022
|
},
|
|
1023
|
-
resourceServers:
|
|
1023
|
+
resourceServers: x(
|
|
1024
1024
|
e,
|
|
1025
1025
|
n
|
|
1026
1026
|
),
|
|
1027
|
-
hooks:
|
|
1027
|
+
hooks: Ie(e, n)
|
|
1028
1028
|
// Note: Additional adapters can be extended here for runtime fallback:
|
|
1029
1029
|
// - promptSettings: Fall back to control plane prompts
|
|
1030
1030
|
// - branding: Fall back to control plane branding/themes
|
|
1031
1031
|
};
|
|
1032
1032
|
}
|
|
1033
|
-
function
|
|
1033
|
+
function X(e) {
|
|
1034
1034
|
if (!e || typeof e != "object") return !1;
|
|
1035
1035
|
const t = e.metadata;
|
|
1036
1036
|
return !t || typeof t != "object" ? !1 : t.inheritable === !0;
|
|
1037
1037
|
}
|
|
1038
|
-
function
|
|
1038
|
+
function Ie(e, t) {
|
|
1039
1039
|
return {
|
|
1040
1040
|
...e.hooks,
|
|
1041
1041
|
list: async (n, r) => {
|
|
@@ -1046,13 +1046,11 @@ function Se(e, t) {
|
|
|
1046
1046
|
t,
|
|
1047
1047
|
r
|
|
1048
1048
|
)).hooks || []).filter(
|
|
1049
|
-
|
|
1049
|
+
X
|
|
1050
1050
|
);
|
|
1051
1051
|
if (i.length === 0)
|
|
1052
1052
|
return a;
|
|
1053
|
-
const c = new Set(
|
|
1054
|
-
(a.hooks || []).map((o) => o.hook_id)
|
|
1055
|
-
), u = i.filter((o) => !c.has(o.hook_id));
|
|
1053
|
+
const c = new Set((a.hooks || []).map((o) => o.hook_id)), u = i.filter((o) => !c.has(o.hook_id));
|
|
1056
1054
|
return {
|
|
1057
1055
|
...a,
|
|
1058
1056
|
hooks: [...a.hooks || [], ...u],
|
|
@@ -1067,43 +1065,43 @@ function Se(e, t) {
|
|
|
1067
1065
|
t,
|
|
1068
1066
|
r
|
|
1069
1067
|
);
|
|
1070
|
-
return s &&
|
|
1068
|
+
return s && X(s) ? s : null;
|
|
1071
1069
|
}
|
|
1072
1070
|
};
|
|
1073
1071
|
}
|
|
1074
|
-
function
|
|
1072
|
+
function ee(e, t) {
|
|
1075
1073
|
return Ae(e, t);
|
|
1076
1074
|
}
|
|
1077
|
-
function
|
|
1075
|
+
function Re(e) {
|
|
1078
1076
|
return async (t, n) => {
|
|
1079
1077
|
const r = t.var.user;
|
|
1080
1078
|
return (r == null ? void 0 : r.tenant_id) === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
1081
1079
|
};
|
|
1082
1080
|
}
|
|
1083
|
-
function
|
|
1081
|
+
function ze(e) {
|
|
1084
1082
|
return async (t, n) => {
|
|
1085
1083
|
if (!e.accessControl)
|
|
1086
1084
|
return n();
|
|
1087
1085
|
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id, i = a || s;
|
|
1088
1086
|
let c = t.var.tenant_id;
|
|
1089
|
-
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(
|
|
1087
|
+
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(Y);
|
|
1090
1088
|
if (!c && i && l && (t.set("tenant_id", i), c = i), !c)
|
|
1091
|
-
throw new
|
|
1089
|
+
throw new P(400, {
|
|
1092
1090
|
message: "Tenant ID not found in request"
|
|
1093
1091
|
});
|
|
1094
|
-
if (!
|
|
1092
|
+
if (!me(
|
|
1095
1093
|
s,
|
|
1096
1094
|
c,
|
|
1097
1095
|
r,
|
|
1098
1096
|
a
|
|
1099
1097
|
))
|
|
1100
|
-
throw new
|
|
1098
|
+
throw new P(403, {
|
|
1101
1099
|
message: `Access denied to tenant ${c}`
|
|
1102
1100
|
});
|
|
1103
1101
|
return n();
|
|
1104
1102
|
};
|
|
1105
1103
|
}
|
|
1106
|
-
function
|
|
1104
|
+
function $e(e) {
|
|
1107
1105
|
return async (t, n) => {
|
|
1108
1106
|
if (!e.subdomainRouting)
|
|
1109
1107
|
return n();
|
|
@@ -1132,19 +1130,19 @@ function ze(e) {
|
|
|
1132
1130
|
} catch {
|
|
1133
1131
|
}
|
|
1134
1132
|
if (!u)
|
|
1135
|
-
throw new
|
|
1133
|
+
throw new P(404, {
|
|
1136
1134
|
message: `Tenant not found for subdomain: ${c}`
|
|
1137
1135
|
});
|
|
1138
1136
|
return t.set("tenant_id", u), n();
|
|
1139
1137
|
};
|
|
1140
1138
|
}
|
|
1141
|
-
function
|
|
1139
|
+
function je(e) {
|
|
1142
1140
|
return async (t, n) => {
|
|
1143
1141
|
if (!e.databaseIsolation)
|
|
1144
1142
|
return n();
|
|
1145
1143
|
const r = t.var.tenant_id;
|
|
1146
1144
|
if (!r)
|
|
1147
|
-
throw new
|
|
1145
|
+
throw new P(400, {
|
|
1148
1146
|
message: "Tenant ID not found in request"
|
|
1149
1147
|
});
|
|
1150
1148
|
try {
|
|
@@ -1154,21 +1152,21 @@ function $e(e) {
|
|
|
1154
1152
|
throw console.error(
|
|
1155
1153
|
`Failed to resolve database for tenant ${r}:`,
|
|
1156
1154
|
a
|
|
1157
|
-
), new
|
|
1155
|
+
), new P(500, {
|
|
1158
1156
|
message: "Failed to resolve tenant database"
|
|
1159
1157
|
});
|
|
1160
1158
|
}
|
|
1161
1159
|
return n();
|
|
1162
1160
|
};
|
|
1163
1161
|
}
|
|
1164
|
-
function
|
|
1165
|
-
const t =
|
|
1162
|
+
function te(e) {
|
|
1163
|
+
const t = $e(e), n = ze(e), r = je(e);
|
|
1166
1164
|
return async (a, s) => (await t(a, async () => {
|
|
1167
1165
|
}), await n(a, async () => {
|
|
1168
1166
|
}), await r(a, async () => {
|
|
1169
1167
|
}), s());
|
|
1170
1168
|
}
|
|
1171
|
-
function
|
|
1169
|
+
function qe(e) {
|
|
1172
1170
|
const {
|
|
1173
1171
|
dataAdapter: t,
|
|
1174
1172
|
controlPlane: n,
|
|
@@ -1185,12 +1183,12 @@ function ke(e) {
|
|
|
1185
1183
|
getAdapters: g,
|
|
1186
1184
|
...d
|
|
1187
1185
|
} = e;
|
|
1188
|
-
let
|
|
1189
|
-
n && (
|
|
1186
|
+
let m = t, f = t;
|
|
1187
|
+
n && (m = ee(t, {
|
|
1190
1188
|
controlPlaneTenantId: r,
|
|
1191
1189
|
controlPlaneClientId: a
|
|
1192
|
-
}),
|
|
1193
|
-
...
|
|
1190
|
+
}), f = {
|
|
1191
|
+
...Se(t, {
|
|
1194
1192
|
controlPlaneTenantId: r
|
|
1195
1193
|
}),
|
|
1196
1194
|
multiTenancyConfig: {
|
|
@@ -1198,35 +1196,35 @@ function ke(e) {
|
|
|
1198
1196
|
controlPlaneClientId: a
|
|
1199
1197
|
}
|
|
1200
1198
|
});
|
|
1201
|
-
const w = s !== !1,
|
|
1199
|
+
const w = s !== !1, T = w ? {
|
|
1202
1200
|
resourceServers: s.resourceServers ?? !0,
|
|
1203
1201
|
roles: s.roles ?? !0
|
|
1204
1202
|
} : { resourceServers: !1, roles: !1 }, b = {
|
|
1205
1203
|
controlPlaneTenantId: r,
|
|
1206
1204
|
getChildTenantIds: l ?? (async () => (await D(
|
|
1207
|
-
(v) =>
|
|
1205
|
+
(v) => m.tenants.list(v),
|
|
1208
1206
|
"tenants",
|
|
1209
1207
|
{ cursorField: "id", pageSize: 100 }
|
|
1210
1208
|
)).filter((v) => v.id !== r).map((v) => v.id)),
|
|
1211
|
-
getAdapters: g ?? (async () =>
|
|
1212
|
-
getControlPlaneAdapters: async () =>
|
|
1213
|
-
sync:
|
|
1214
|
-
}, { entityHooks:
|
|
1209
|
+
getAdapters: g ?? (async () => m),
|
|
1210
|
+
getControlPlaneAdapters: async () => m,
|
|
1211
|
+
sync: T
|
|
1212
|
+
}, { entityHooks: I, tenantHooks: h } = ve(b), C = {
|
|
1215
1213
|
resourceServers: [
|
|
1216
|
-
|
|
1214
|
+
I.resourceServers,
|
|
1217
1215
|
...(o == null ? void 0 : o.resourceServers) ?? []
|
|
1218
1216
|
],
|
|
1219
|
-
roles: [
|
|
1217
|
+
roles: [I.roles, ...(o == null ? void 0 : o.roles) ?? []],
|
|
1220
1218
|
connections: (o == null ? void 0 : o.connections) ?? [],
|
|
1221
1219
|
tenants: (o == null ? void 0 : o.tenants) ?? [],
|
|
1222
1220
|
rolePermissions: (o == null ? void 0 : o.rolePermissions) ?? []
|
|
1223
|
-
}, p =
|
|
1221
|
+
}, p = Z({
|
|
1224
1222
|
accessControl: {
|
|
1225
1223
|
controlPlaneTenantId: r,
|
|
1226
1224
|
requireOrganizationMatch: c,
|
|
1227
1225
|
defaultPermissions: i
|
|
1228
1226
|
}
|
|
1229
|
-
}),
|
|
1227
|
+
}), $ = N(
|
|
1230
1228
|
{
|
|
1231
1229
|
accessControl: {
|
|
1232
1230
|
controlPlaneTenantId: r,
|
|
@@ -1239,35 +1237,35 @@ function ke(e) {
|
|
|
1239
1237
|
return p.beforeCreate && (v = await p.beforeCreate(S, v)), h.beforeCreate && (v = await h.beforeCreate(S, v)), v;
|
|
1240
1238
|
},
|
|
1241
1239
|
async afterCreate(S, v) {
|
|
1242
|
-
var
|
|
1243
|
-
await ((
|
|
1240
|
+
var j, z;
|
|
1241
|
+
await ((j = p.afterCreate) == null ? void 0 : j.call(p, S, v)), await ((z = h.afterCreate) == null ? void 0 : z.call(h, S, v));
|
|
1244
1242
|
},
|
|
1245
1243
|
async beforeDelete(S, v) {
|
|
1246
|
-
var
|
|
1247
|
-
await ((
|
|
1244
|
+
var j, z;
|
|
1245
|
+
await ((j = p.beforeDelete) == null ? void 0 : j.call(p, S, v)), await ((z = h.beforeDelete) == null ? void 0 : z.call(h, S, v));
|
|
1248
1246
|
}
|
|
1249
1247
|
} }
|
|
1250
|
-
), { app:
|
|
1251
|
-
dataAdapter:
|
|
1252
|
-
managementDataAdapter:
|
|
1248
|
+
), { app: R } = ue({
|
|
1249
|
+
dataAdapter: m,
|
|
1250
|
+
managementDataAdapter: f,
|
|
1253
1251
|
...d,
|
|
1254
|
-
entityHooks:
|
|
1252
|
+
entityHooks: C,
|
|
1255
1253
|
managementApiExtensions: [
|
|
1256
1254
|
...u,
|
|
1257
|
-
{ path: "/tenants", router:
|
|
1255
|
+
{ path: "/tenants", router: $ }
|
|
1258
1256
|
]
|
|
1259
1257
|
});
|
|
1260
|
-
return
|
|
1258
|
+
return R.use(
|
|
1261
1259
|
"/api/v2/*",
|
|
1262
|
-
|
|
1263
|
-
), w &&
|
|
1260
|
+
Re(r)
|
|
1261
|
+
), w && R.use("/api/v2/*", be()), { app: R, controlPlaneTenantId: r };
|
|
1264
1262
|
}
|
|
1265
|
-
function
|
|
1266
|
-
const t =
|
|
1263
|
+
function Ee(e) {
|
|
1264
|
+
const t = U(e);
|
|
1267
1265
|
return {
|
|
1268
1266
|
name: "multi-tenancy",
|
|
1269
1267
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1270
|
-
middleware:
|
|
1268
|
+
middleware: te(e),
|
|
1271
1269
|
// Provide lifecycle hooks
|
|
1272
1270
|
hooks: t,
|
|
1273
1271
|
// Mount tenant management routes
|
|
@@ -1287,23 +1285,23 @@ function Oe(e) {
|
|
|
1287
1285
|
}
|
|
1288
1286
|
};
|
|
1289
1287
|
}
|
|
1290
|
-
function
|
|
1291
|
-
const t = e.accessControl ?
|
|
1288
|
+
function U(e) {
|
|
1289
|
+
const t = e.accessControl ? fe(e.accessControl) : {}, n = e.databaseIsolation ? ge(e.databaseIsolation) : {}, r = Z(e);
|
|
1292
1290
|
return {
|
|
1293
1291
|
...t,
|
|
1294
1292
|
...n,
|
|
1295
1293
|
tenants: r
|
|
1296
1294
|
};
|
|
1297
1295
|
}
|
|
1298
|
-
function
|
|
1299
|
-
const t = new
|
|
1296
|
+
function Fe(e) {
|
|
1297
|
+
const t = new ae(), n = U(e);
|
|
1300
1298
|
return t.route("/tenants", N(e, n)), t;
|
|
1301
1299
|
}
|
|
1302
|
-
function
|
|
1300
|
+
function Be(e) {
|
|
1303
1301
|
return {
|
|
1304
|
-
hooks:
|
|
1305
|
-
middleware:
|
|
1306
|
-
app:
|
|
1302
|
+
hooks: U(e),
|
|
1303
|
+
middleware: te(e),
|
|
1304
|
+
app: Fe(e),
|
|
1307
1305
|
config: e,
|
|
1308
1306
|
/**
|
|
1309
1307
|
* Wraps data adapters with runtime fallback from the control plane.
|
|
@@ -1315,7 +1313,7 @@ function Ee(e) {
|
|
|
1315
1313
|
*/
|
|
1316
1314
|
wrapAdapters: (t, n) => {
|
|
1317
1315
|
var r;
|
|
1318
|
-
return
|
|
1316
|
+
return ee(t, {
|
|
1319
1317
|
controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
|
|
1320
1318
|
controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
|
|
1321
1319
|
});
|
|
@@ -1323,24 +1321,24 @@ function Ee(e) {
|
|
|
1323
1321
|
};
|
|
1324
1322
|
}
|
|
1325
1323
|
export {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1324
|
+
fe as createAccessControlHooks,
|
|
1325
|
+
ze as createAccessControlMiddleware,
|
|
1326
|
+
Re as createControlPlaneTenantMiddleware,
|
|
1327
|
+
ge as createDatabaseHooks,
|
|
1328
|
+
je as createDatabaseMiddleware,
|
|
1329
|
+
Fe as createMultiTenancy,
|
|
1330
|
+
U as createMultiTenancyHooks,
|
|
1331
|
+
te as createMultiTenancyMiddleware,
|
|
1332
|
+
Ee as createMultiTenancyPlugin,
|
|
1333
|
+
be as createProtectSyncedMiddleware,
|
|
1334
|
+
Z as createProvisioningHooks,
|
|
1337
1335
|
Ae as createRuntimeFallbackAdapter,
|
|
1338
|
-
|
|
1339
|
-
|
|
1336
|
+
$e as createSubdomainMiddleware,
|
|
1337
|
+
ve as createSyncHooks,
|
|
1340
1338
|
N as createTenantsOpenAPIRouter,
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1339
|
+
qe as initMultiTenant,
|
|
1340
|
+
Be as setupMultiTenancy,
|
|
1341
|
+
me as validateTenantAccess,
|
|
1342
|
+
ee as withRuntimeFallback,
|
|
1343
|
+
Se as withSystemResourceServerInheritance
|
|
1346
1344
|
};
|