@authhero/multi-tenancy 14.20.0 → 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,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var E = (e, t, n) =>
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { MANAGEMENT_API_SCOPES as
|
|
6
|
-
import { OpenAPIHono as
|
|
7
|
-
function
|
|
1
|
+
var 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) {
|
|
11
11
|
if (a === t)
|
|
12
12
|
return !0;
|
|
13
13
|
if (n) {
|
|
14
|
-
const s = r.var.org_name,
|
|
15
|
-
return
|
|
14
|
+
const s = r.var.org_name, i = r.var.organization_id, c = s || i;
|
|
15
|
+
return c ? c.toLowerCase() === a.toLowerCase() : !1;
|
|
16
16
|
}
|
|
17
17
|
return !0;
|
|
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,31 +39,31 @@ function fe(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;
|
|
59
59
|
if (r)
|
|
60
60
|
try {
|
|
61
|
-
const
|
|
61
|
+
const i = (await t.adapters.organizations.list(
|
|
62
62
|
r.controlPlaneTenantId
|
|
63
|
-
)).organizations.find((
|
|
64
|
-
|
|
63
|
+
)).organizations.find((c) => c.name === n);
|
|
64
|
+
i && await t.adapters.organizations.remove(
|
|
65
65
|
r.controlPlaneTenantId,
|
|
66
|
-
|
|
66
|
+
i.id
|
|
67
67
|
);
|
|
68
68
|
} catch (s) {
|
|
69
69
|
console.warn(
|
|
@@ -83,13 +83,13 @@ function X(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,
|
|
90
90
|
defaultRoles: s,
|
|
91
|
-
issuer:
|
|
92
|
-
adminRoleName:
|
|
91
|
+
issuer: i,
|
|
92
|
+
adminRoleName: c = "Tenant Admin",
|
|
93
93
|
adminRoleDescription: u = "Full access to all tenant management operations",
|
|
94
94
|
addCreatorToOrganization: o = !0
|
|
95
95
|
} = n, l = await e.adapters.organizations.create(
|
|
@@ -100,14 +100,14 @@ async function ge(e, t, n) {
|
|
|
100
100
|
}
|
|
101
101
|
);
|
|
102
102
|
let g;
|
|
103
|
-
if (
|
|
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 ge(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 ge(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,
|
|
@@ -150,32 +150,32 @@ async function we(e, t, n) {
|
|
|
150
150
|
a.id,
|
|
151
151
|
{ per_page: 1e3 }
|
|
152
152
|
)).some(
|
|
153
|
-
(
|
|
153
|
+
(c) => c.permission_name === "admin:organizations"
|
|
154
154
|
))
|
|
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
|
-
const
|
|
162
|
+
const i = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}),
|
|
166
|
-
role_id:
|
|
167
|
-
resource_server_identifier:
|
|
165
|
+
}), c = Y, u = se.map((o) => ({
|
|
166
|
+
role_id: i.id,
|
|
167
|
+
resource_server_identifier: c,
|
|
168
168
|
permission_name: o.value
|
|
169
169
|
}));
|
|
170
170
|
return await e.adapters.rolePermissions.assign(
|
|
171
171
|
t,
|
|
172
|
-
|
|
172
|
+
i.id,
|
|
173
173
|
u
|
|
174
|
-
),
|
|
174
|
+
), i.id;
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e,
|
|
178
|
-
async function
|
|
176
|
+
function H(e, t, n = () => !0) {
|
|
177
|
+
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: s } = e, i = /* @__PURE__ */ new Map();
|
|
178
|
+
async function c(l, g, d) {
|
|
179
179
|
return (await t(l).list(g, {
|
|
180
180
|
q: `name:${d}`,
|
|
181
181
|
per_page: 1
|
|
@@ -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
|
|
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,53 +229,53 @@ 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;
|
|
237
|
-
const d =
|
|
238
|
-
d && (
|
|
237
|
+
const d = i.get(g);
|
|
238
|
+
d && (i.delete(g), await o(d.name));
|
|
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
|
-
async afterCreate(
|
|
246
|
-
if (
|
|
245
|
+
async afterCreate(i, c) {
|
|
246
|
+
if (c.id !== r)
|
|
247
247
|
try {
|
|
248
|
-
const u = await a(), o = await s(
|
|
249
|
-
(
|
|
248
|
+
const u = await a(), o = await s(c.id), l = t(u), g = t(o), d = await D(
|
|
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
|
|
257
|
-
await g.create(
|
|
258
|
-
...
|
|
256
|
+
const f = l.transform(m);
|
|
257
|
+
await g.create(c.id, {
|
|
258
|
+
...f,
|
|
259
259
|
is_system: !0
|
|
260
260
|
});
|
|
261
|
-
} catch (
|
|
261
|
+
} catch (f) {
|
|
262
262
|
console.error(
|
|
263
|
-
`Failed to sync entity to new tenant "${
|
|
264
|
-
|
|
263
|
+
`Failed to sync entity to new tenant "${c.id}":`,
|
|
264
|
+
f
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
})
|
|
268
268
|
);
|
|
269
269
|
} catch (u) {
|
|
270
270
|
console.error(
|
|
271
|
-
`Failed to sync entities to new tenant "${
|
|
271
|
+
`Failed to sync entities to new tenant "${c.id}":`,
|
|
272
272
|
u
|
|
273
273
|
);
|
|
274
274
|
}
|
|
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,77 +308,77 @@ 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
|
-
|
|
327
|
-
|
|
326
|
+
K,
|
|
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(
|
|
336
336
|
e.controlPlaneTenantId,
|
|
337
|
-
|
|
337
|
+
h
|
|
338
338
|
),
|
|
339
339
|
"roles",
|
|
340
340
|
{ cursorField: "id", pageSize: 100 }
|
|
341
|
-
),
|
|
342
|
-
for (const
|
|
343
|
-
(
|
|
344
|
-
var
|
|
345
|
-
return ((
|
|
341
|
+
), I = /* @__PURE__ */ new Map();
|
|
342
|
+
for (const h of b.filter(
|
|
343
|
+
(C) => {
|
|
344
|
+
var p;
|
|
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
|
-
for (const
|
|
356
|
-
(
|
|
357
|
-
var
|
|
358
|
-
return ((
|
|
355
|
+
for (const h of b.filter(
|
|
356
|
+
(C) => {
|
|
357
|
+
var p;
|
|
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
|
-
const
|
|
364
|
+
const p = await y.rolePermissions.list(
|
|
365
365
|
e.controlPlaneTenantId,
|
|
366
|
-
|
|
366
|
+
h.id,
|
|
367
367
|
{}
|
|
368
368
|
);
|
|
369
|
-
|
|
369
|
+
p.length > 0 && await _.rolePermissions.assign(
|
|
370
370
|
w.id,
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
} catch (
|
|
378
|
+
} catch (p) {
|
|
379
379
|
console.error(
|
|
380
|
-
`Failed to sync permissions for role "${
|
|
381
|
-
|
|
380
|
+
`Failed to sync permissions for role "${h.name}" to tenant "${w.id}":`,
|
|
381
|
+
p
|
|
382
382
|
);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
@@ -391,27 +391,27 @@ function he(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
|
}
|
|
400
400
|
return {
|
|
401
401
|
entityHooks: {
|
|
402
|
-
resourceServers:
|
|
402
|
+
resourceServers: c,
|
|
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 he(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.
|
|
@@ -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,75 +483,75 @@ function N(e, t) {
|
|
|
483
483
|
}
|
|
484
484
|
}),
|
|
485
485
|
async (r) => {
|
|
486
|
-
var
|
|
487
|
-
const a = r.req.valid("query"), { page: s, per_page:
|
|
488
|
-
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
489
|
-
const
|
|
486
|
+
var w, T, y, _, b, I;
|
|
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 (!!!((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
|
-
per_page:
|
|
492
|
-
include_totals:
|
|
491
|
+
per_page: i,
|
|
492
|
+
include_totals: c,
|
|
493
493
|
q: u
|
|
494
494
|
});
|
|
495
|
-
return
|
|
496
|
-
tenants:
|
|
497
|
-
start: ((
|
|
498
|
-
limit: ((
|
|
499
|
-
length:
|
|
500
|
-
}) : r.json({ tenants:
|
|
495
|
+
return c ? r.json({
|
|
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 (
|
|
513
|
-
return
|
|
511
|
+
)).map((M) => M.name);
|
|
512
|
+
if (C.length === 0)
|
|
513
|
+
return c ? r.json({
|
|
514
514
|
tenants: [],
|
|
515
515
|
start: 0,
|
|
516
|
-
limit:
|
|
516
|
+
limit: i ?? 50,
|
|
517
517
|
length: 0
|
|
518
518
|
}) : r.json({ tenants: [] });
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
521
|
-
return
|
|
519
|
+
const p = C.length, F = s ?? 0, $ = i ?? 50, R = F * $, S = C.slice(R, R + $);
|
|
520
|
+
if (S.length === 0)
|
|
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
|
-
return
|
|
534
|
-
tenants:
|
|
535
|
-
start:
|
|
536
|
-
limit:
|
|
537
|
-
length:
|
|
538
|
-
}) : r.json({ tenants:
|
|
533
|
+
return c ? r.json({
|
|
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,
|
|
542
|
-
per_page:
|
|
543
|
-
include_totals:
|
|
542
|
+
per_page: i,
|
|
543
|
+
include_totals: c,
|
|
544
544
|
q: u
|
|
545
545
|
});
|
|
546
|
-
return
|
|
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,26 +590,26 @@ 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");
|
|
597
|
-
const
|
|
597
|
+
const i = {
|
|
598
598
|
adapters: r.env.data,
|
|
599
599
|
ctx: r
|
|
600
600
|
};
|
|
601
|
-
(u = t.tenants) != null && u.beforeCreate && (s = await t.tenants.beforeCreate(
|
|
602
|
-
const
|
|
603
|
-
return (o = t.tenants) != null && o.afterCreate && await t.tenants.afterCreate(
|
|
601
|
+
(u = t.tenants) != null && u.beforeCreate && (s = await t.tenants.beforeCreate(i, s));
|
|
602
|
+
const c = await r.env.data.tenants.create(s);
|
|
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,28 +650,28 @@ 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
|
-
const
|
|
661
|
+
const c = {
|
|
662
662
|
adapters: r.env.data,
|
|
663
663
|
ctx: r
|
|
664
664
|
};
|
|
665
|
-
return (l = t.tenants) != null && l.beforeDelete && await t.tenants.beforeDelete(
|
|
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"
|
|
@@ -732,23 +732,23 @@ function N(e, t) {
|
|
|
732
732
|
}
|
|
733
733
|
}),
|
|
734
734
|
async (r) => {
|
|
735
|
-
const a = r.req.valid("json"), { id: s, ...
|
|
736
|
-
if (!
|
|
737
|
-
throw new
|
|
735
|
+
const a = r.req.valid("json"), { id: s, ...i } = a, c = await r.env.data.tenants.get(r.var.tenant_id);
|
|
736
|
+
if (!c)
|
|
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 ye(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 ve(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 Te(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 Y(e, t) {
|
|
|
882
882
|
t,
|
|
883
883
|
r
|
|
884
884
|
);
|
|
885
|
-
return
|
|
885
|
+
return V(
|
|
886
886
|
a,
|
|
887
887
|
s
|
|
888
888
|
);
|
|
@@ -891,22 +891,22 @@ function Y(e, t) {
|
|
|
891
891
|
const a = await e.resourceServers.list(n, r);
|
|
892
892
|
if (!t || n === t)
|
|
893
893
|
return a;
|
|
894
|
-
const s = t,
|
|
894
|
+
const s = t, i = a.resource_servers.filter(
|
|
895
895
|
(o) => !!(o.is_system && o.id)
|
|
896
896
|
).map((o) => o.id);
|
|
897
|
-
if (
|
|
897
|
+
if (i.length === 0)
|
|
898
898
|
return a;
|
|
899
|
-
const
|
|
899
|
+
const c = /* @__PURE__ */ new Map();
|
|
900
900
|
await Promise.all(
|
|
901
|
-
|
|
901
|
+
i.map(async (o) => {
|
|
902
902
|
const l = await e.resourceServers.get(s, o);
|
|
903
|
-
l &&
|
|
903
|
+
l && c.set(o, l);
|
|
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
|
|
911
911
|
);
|
|
912
912
|
return {
|
|
@@ -916,16 +916,16 @@ function Y(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
|
)
|
|
926
926
|
};
|
|
927
927
|
}
|
|
928
|
-
function
|
|
928
|
+
function Ae(e, t) {
|
|
929
929
|
const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
|
|
930
930
|
return {
|
|
931
931
|
...e,
|
|
@@ -937,30 +937,30 @@ function Pe(e, t) {
|
|
|
937
937
|
connections: {
|
|
938
938
|
...e.connections,
|
|
939
939
|
get: async (a, s) => {
|
|
940
|
-
const
|
|
940
|
+
const i = await e.connections.get(
|
|
941
941
|
a,
|
|
942
942
|
s
|
|
943
943
|
);
|
|
944
|
-
if (!
|
|
945
|
-
return
|
|
946
|
-
const
|
|
947
|
-
return
|
|
948
|
-
|
|
949
|
-
|
|
944
|
+
if (!i || !n || a === n)
|
|
945
|
+
return i;
|
|
946
|
+
const c = await e.connections.list(n);
|
|
947
|
+
return B(
|
|
948
|
+
i,
|
|
949
|
+
c.connections || []
|
|
950
950
|
);
|
|
951
951
|
},
|
|
952
952
|
list: async (a, s) => {
|
|
953
|
-
const
|
|
953
|
+
const i = await e.connections.list(a, s);
|
|
954
954
|
if (!n || a === n)
|
|
955
|
-
return
|
|
956
|
-
const
|
|
957
|
-
(o) =>
|
|
955
|
+
return i;
|
|
956
|
+
const c = await e.connections.list(n), u = i.connections.map(
|
|
957
|
+
(o) => B(
|
|
958
958
|
o,
|
|
959
|
-
|
|
959
|
+
c.connections || []
|
|
960
960
|
)
|
|
961
961
|
);
|
|
962
962
|
return {
|
|
963
|
-
...
|
|
963
|
+
...i,
|
|
964
964
|
connections: u
|
|
965
965
|
};
|
|
966
966
|
}
|
|
@@ -968,17 +968,17 @@ function Pe(e, t) {
|
|
|
968
968
|
clientConnections: {
|
|
969
969
|
...e.clientConnections,
|
|
970
970
|
listByClient: async (a, s) => {
|
|
971
|
-
let
|
|
971
|
+
let i = await e.clientConnections.listByClient(
|
|
972
972
|
a,
|
|
973
973
|
s
|
|
974
974
|
);
|
|
975
|
-
if (
|
|
976
|
-
return
|
|
977
|
-
const
|
|
978
|
-
return
|
|
979
|
-
(u) =>
|
|
975
|
+
if (i.length === 0 && (i = (await e.connections.list(a)).connections || []), !n || a === n)
|
|
976
|
+
return i;
|
|
977
|
+
const c = await e.connections.list(n);
|
|
978
|
+
return i.map(
|
|
979
|
+
(u) => B(
|
|
980
980
|
u,
|
|
981
|
-
|
|
981
|
+
c.connections || []
|
|
982
982
|
)
|
|
983
983
|
);
|
|
984
984
|
}
|
|
@@ -986,16 +986,16 @@ function Pe(e, t) {
|
|
|
986
986
|
clients: {
|
|
987
987
|
...e.clients,
|
|
988
988
|
get: async (a, s) => {
|
|
989
|
-
const
|
|
990
|
-
if (!
|
|
989
|
+
const i = await e.clients.get(a, s);
|
|
990
|
+
if (!i)
|
|
991
991
|
return null;
|
|
992
992
|
if (!n || !r || a === n && s === r)
|
|
993
|
-
return
|
|
994
|
-
const
|
|
993
|
+
return i;
|
|
994
|
+
const c = await e.clients.get(
|
|
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);
|
|
@@ -1003,12 +1003,12 @@ function Pe(e, t) {
|
|
|
1003
1003
|
return null;
|
|
1004
1004
|
if (!n || !r || s.tenant_id === n && s.client_id === r)
|
|
1005
1005
|
return s;
|
|
1006
|
-
const
|
|
1006
|
+
const i = await e.clients.get(
|
|
1007
1007
|
n,
|
|
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,48 +1020,88 @@ function Pe(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: Ie(e, n)
|
|
1027
1028
|
// Note: Additional adapters can be extended here for runtime fallback:
|
|
1028
1029
|
// - promptSettings: Fall back to control plane prompts
|
|
1029
1030
|
// - branding: Fall back to control plane branding/themes
|
|
1030
1031
|
};
|
|
1031
1032
|
}
|
|
1032
|
-
function
|
|
1033
|
-
|
|
1033
|
+
function X(e) {
|
|
1034
|
+
if (!e || typeof e != "object") return !1;
|
|
1035
|
+
const t = e.metadata;
|
|
1036
|
+
return !t || typeof t != "object" ? !1 : t.inheritable === !0;
|
|
1037
|
+
}
|
|
1038
|
+
function Ie(e, t) {
|
|
1039
|
+
return {
|
|
1040
|
+
...e.hooks,
|
|
1041
|
+
list: async (n, r) => {
|
|
1042
|
+
const a = await e.hooks.list(n, r);
|
|
1043
|
+
if (!t || n === t)
|
|
1044
|
+
return a;
|
|
1045
|
+
const i = ((await e.hooks.list(
|
|
1046
|
+
t,
|
|
1047
|
+
r
|
|
1048
|
+
)).hooks || []).filter(
|
|
1049
|
+
X
|
|
1050
|
+
);
|
|
1051
|
+
if (i.length === 0)
|
|
1052
|
+
return a;
|
|
1053
|
+
const c = new Set((a.hooks || []).map((o) => o.hook_id)), u = i.filter((o) => !c.has(o.hook_id));
|
|
1054
|
+
return {
|
|
1055
|
+
...a,
|
|
1056
|
+
hooks: [...a.hooks || [], ...u],
|
|
1057
|
+
length: typeof a.length == "number" ? a.length + u.length : a.length
|
|
1058
|
+
};
|
|
1059
|
+
},
|
|
1060
|
+
get: async (n, r) => {
|
|
1061
|
+
const a = await e.hooks.get(n, r);
|
|
1062
|
+
if (a || !t || n === t)
|
|
1063
|
+
return a;
|
|
1064
|
+
const s = await e.hooks.get(
|
|
1065
|
+
t,
|
|
1066
|
+
r
|
|
1067
|
+
);
|
|
1068
|
+
return s && X(s) ? s : null;
|
|
1069
|
+
}
|
|
1070
|
+
};
|
|
1034
1071
|
}
|
|
1035
|
-
function
|
|
1072
|
+
function ee(e, t) {
|
|
1073
|
+
return Ae(e, t);
|
|
1074
|
+
}
|
|
1075
|
+
function Re(e) {
|
|
1036
1076
|
return async (t, n) => {
|
|
1037
1077
|
const r = t.var.user;
|
|
1038
1078
|
return (r == null ? void 0 : r.tenant_id) === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
1039
1079
|
};
|
|
1040
1080
|
}
|
|
1041
|
-
function
|
|
1081
|
+
function ze(e) {
|
|
1042
1082
|
return async (t, n) => {
|
|
1043
1083
|
if (!e.accessControl)
|
|
1044
1084
|
return n();
|
|
1045
|
-
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id,
|
|
1046
|
-
let
|
|
1047
|
-
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(
|
|
1048
|
-
if (!
|
|
1049
|
-
throw new
|
|
1085
|
+
const { controlPlaneTenantId: r } = e.accessControl, a = t.var.org_name, s = t.var.organization_id, i = a || s;
|
|
1086
|
+
let c = t.var.tenant_id;
|
|
1087
|
+
const u = t.var.user, l = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(Y);
|
|
1088
|
+
if (!c && i && l && (t.set("tenant_id", i), c = i), !c)
|
|
1089
|
+
throw new P(400, {
|
|
1050
1090
|
message: "Tenant ID not found in request"
|
|
1051
1091
|
});
|
|
1052
|
-
if (!
|
|
1092
|
+
if (!me(
|
|
1053
1093
|
s,
|
|
1054
|
-
|
|
1094
|
+
c,
|
|
1055
1095
|
r,
|
|
1056
1096
|
a
|
|
1057
1097
|
))
|
|
1058
|
-
throw new
|
|
1059
|
-
message: `Access denied to tenant ${
|
|
1098
|
+
throw new P(403, {
|
|
1099
|
+
message: `Access denied to tenant ${c}`
|
|
1060
1100
|
});
|
|
1061
1101
|
return n();
|
|
1062
1102
|
};
|
|
1063
1103
|
}
|
|
1064
|
-
function
|
|
1104
|
+
function $e(e) {
|
|
1065
1105
|
return async (t, n) => {
|
|
1066
1106
|
if (!e.subdomainRouting)
|
|
1067
1107
|
return n();
|
|
@@ -1069,40 +1109,40 @@ function Ie(e) {
|
|
|
1069
1109
|
baseDomain: r,
|
|
1070
1110
|
reservedSubdomains: a = [],
|
|
1071
1111
|
resolveSubdomain: s
|
|
1072
|
-
} = e.subdomainRouting,
|
|
1073
|
-
let
|
|
1074
|
-
if (
|
|
1075
|
-
const o =
|
|
1076
|
-
o && !o.includes(".") && (
|
|
1112
|
+
} = e.subdomainRouting, i = t.req.header("x-forwarded-host") || t.req.header("host") || "";
|
|
1113
|
+
let c = null;
|
|
1114
|
+
if (i.endsWith(r)) {
|
|
1115
|
+
const o = i.slice(0, -(r.length + 1));
|
|
1116
|
+
o && !o.includes(".") && (c = o);
|
|
1077
1117
|
}
|
|
1078
|
-
if (
|
|
1118
|
+
if (c && a.includes(c) && (c = null), !c)
|
|
1079
1119
|
return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
1080
1120
|
let u = null;
|
|
1081
1121
|
if (s)
|
|
1082
|
-
u = await s(
|
|
1122
|
+
u = await s(c);
|
|
1083
1123
|
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
|
|
1084
1124
|
try {
|
|
1085
1125
|
const o = await t.env.data.organizations.get(
|
|
1086
1126
|
e.accessControl.controlPlaneTenantId,
|
|
1087
|
-
|
|
1127
|
+
c
|
|
1088
1128
|
);
|
|
1089
1129
|
o && (u = o.id);
|
|
1090
1130
|
} catch {
|
|
1091
1131
|
}
|
|
1092
1132
|
if (!u)
|
|
1093
|
-
throw new
|
|
1094
|
-
message: `Tenant not found for subdomain: ${
|
|
1133
|
+
throw new P(404, {
|
|
1134
|
+
message: `Tenant not found for subdomain: ${c}`
|
|
1095
1135
|
});
|
|
1096
1136
|
return t.set("tenant_id", u), n();
|
|
1097
1137
|
};
|
|
1098
1138
|
}
|
|
1099
|
-
function
|
|
1139
|
+
function je(e) {
|
|
1100
1140
|
return async (t, n) => {
|
|
1101
1141
|
if (!e.databaseIsolation)
|
|
1102
1142
|
return n();
|
|
1103
1143
|
const r = t.var.tenant_id;
|
|
1104
1144
|
if (!r)
|
|
1105
|
-
throw new
|
|
1145
|
+
throw new P(400, {
|
|
1106
1146
|
message: "Tenant ID not found in request"
|
|
1107
1147
|
});
|
|
1108
1148
|
try {
|
|
@@ -1112,21 +1152,21 @@ function Re(e) {
|
|
|
1112
1152
|
throw console.error(
|
|
1113
1153
|
`Failed to resolve database for tenant ${r}:`,
|
|
1114
1154
|
a
|
|
1115
|
-
), new
|
|
1155
|
+
), new P(500, {
|
|
1116
1156
|
message: "Failed to resolve tenant database"
|
|
1117
1157
|
});
|
|
1118
1158
|
}
|
|
1119
1159
|
return n();
|
|
1120
1160
|
};
|
|
1121
1161
|
}
|
|
1122
|
-
function
|
|
1123
|
-
const t =
|
|
1162
|
+
function te(e) {
|
|
1163
|
+
const t = $e(e), n = ze(e), r = je(e);
|
|
1124
1164
|
return async (a, s) => (await t(a, async () => {
|
|
1125
1165
|
}), await n(a, async () => {
|
|
1126
1166
|
}), await r(a, async () => {
|
|
1127
1167
|
}), s());
|
|
1128
1168
|
}
|
|
1129
|
-
function
|
|
1169
|
+
function qe(e) {
|
|
1130
1170
|
const {
|
|
1131
1171
|
dataAdapter: t,
|
|
1132
1172
|
controlPlane: n,
|
|
@@ -1135,20 +1175,20 @@ function De(e) {
|
|
|
1135
1175
|
clientId: a
|
|
1136
1176
|
} = {},
|
|
1137
1177
|
sync: s = { resourceServers: !0, roles: !0 },
|
|
1138
|
-
defaultPermissions:
|
|
1139
|
-
requireOrganizationMatch:
|
|
1178
|
+
defaultPermissions: i = ["tenant:admin"],
|
|
1179
|
+
requireOrganizationMatch: c = !1,
|
|
1140
1180
|
managementApiExtensions: u = [],
|
|
1141
1181
|
entityHooks: o,
|
|
1142
1182
|
getChildTenantIds: l,
|
|
1143
1183
|
getAdapters: g,
|
|
1144
1184
|
...d
|
|
1145
1185
|
} = e;
|
|
1146
|
-
let
|
|
1147
|
-
n && (
|
|
1186
|
+
let m = t, f = t;
|
|
1187
|
+
n && (m = ee(t, {
|
|
1148
1188
|
controlPlaneTenantId: r,
|
|
1149
1189
|
controlPlaneClientId: a
|
|
1150
|
-
}),
|
|
1151
|
-
...
|
|
1190
|
+
}), f = {
|
|
1191
|
+
...Se(t, {
|
|
1152
1192
|
controlPlaneTenantId: r
|
|
1153
1193
|
}),
|
|
1154
1194
|
multiTenancyConfig: {
|
|
@@ -1156,76 +1196,76 @@ function De(e) {
|
|
|
1156
1196
|
controlPlaneClientId: a
|
|
1157
1197
|
}
|
|
1158
1198
|
});
|
|
1159
|
-
const w = s !== !1,
|
|
1199
|
+
const w = s !== !1, T = w ? {
|
|
1160
1200
|
resourceServers: s.resourceServers ?? !0,
|
|
1161
1201
|
roles: s.roles ?? !0
|
|
1162
1202
|
} : { resourceServers: !1, roles: !1 }, b = {
|
|
1163
1203
|
controlPlaneTenantId: r,
|
|
1164
1204
|
getChildTenantIds: l ?? (async () => (await D(
|
|
1165
|
-
(v) =>
|
|
1205
|
+
(v) => m.tenants.list(v),
|
|
1166
1206
|
"tenants",
|
|
1167
1207
|
{ cursorField: "id", pageSize: 100 }
|
|
1168
1208
|
)).filter((v) => v.id !== r).map((v) => v.id)),
|
|
1169
|
-
getAdapters: g ?? (async () =>
|
|
1170
|
-
getControlPlaneAdapters: async () =>
|
|
1171
|
-
sync:
|
|
1172
|
-
}, { entityHooks:
|
|
1209
|
+
getAdapters: g ?? (async () => m),
|
|
1210
|
+
getControlPlaneAdapters: async () => m,
|
|
1211
|
+
sync: T
|
|
1212
|
+
}, { entityHooks: I, tenantHooks: h } = ve(b), C = {
|
|
1173
1213
|
resourceServers: [
|
|
1174
|
-
|
|
1214
|
+
I.resourceServers,
|
|
1175
1215
|
...(o == null ? void 0 : o.resourceServers) ?? []
|
|
1176
1216
|
],
|
|
1177
|
-
roles: [
|
|
1217
|
+
roles: [I.roles, ...(o == null ? void 0 : o.roles) ?? []],
|
|
1178
1218
|
connections: (o == null ? void 0 : o.connections) ?? [],
|
|
1179
1219
|
tenants: (o == null ? void 0 : o.tenants) ?? [],
|
|
1180
1220
|
rolePermissions: (o == null ? void 0 : o.rolePermissions) ?? []
|
|
1181
|
-
},
|
|
1221
|
+
}, p = Z({
|
|
1182
1222
|
accessControl: {
|
|
1183
1223
|
controlPlaneTenantId: r,
|
|
1184
|
-
requireOrganizationMatch:
|
|
1185
|
-
defaultPermissions:
|
|
1224
|
+
requireOrganizationMatch: c,
|
|
1225
|
+
defaultPermissions: i
|
|
1186
1226
|
}
|
|
1187
|
-
}),
|
|
1227
|
+
}), $ = N(
|
|
1188
1228
|
{
|
|
1189
1229
|
accessControl: {
|
|
1190
1230
|
controlPlaneTenantId: r,
|
|
1191
|
-
requireOrganizationMatch:
|
|
1192
|
-
defaultPermissions:
|
|
1231
|
+
requireOrganizationMatch: c,
|
|
1232
|
+
defaultPermissions: i
|
|
1193
1233
|
}
|
|
1194
1234
|
},
|
|
1195
1235
|
{ tenants: {
|
|
1196
1236
|
async beforeCreate(S, v) {
|
|
1197
|
-
return
|
|
1237
|
+
return p.beforeCreate && (v = await p.beforeCreate(S, v)), h.beforeCreate && (v = await h.beforeCreate(S, v)), v;
|
|
1198
1238
|
},
|
|
1199
1239
|
async afterCreate(S, v) {
|
|
1200
|
-
var
|
|
1201
|
-
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));
|
|
1202
1242
|
},
|
|
1203
1243
|
async beforeDelete(S, v) {
|
|
1204
|
-
var
|
|
1205
|
-
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));
|
|
1206
1246
|
}
|
|
1207
1247
|
} }
|
|
1208
|
-
), { app:
|
|
1209
|
-
dataAdapter:
|
|
1210
|
-
managementDataAdapter:
|
|
1248
|
+
), { app: R } = ue({
|
|
1249
|
+
dataAdapter: m,
|
|
1250
|
+
managementDataAdapter: f,
|
|
1211
1251
|
...d,
|
|
1212
|
-
entityHooks:
|
|
1252
|
+
entityHooks: C,
|
|
1213
1253
|
managementApiExtensions: [
|
|
1214
1254
|
...u,
|
|
1215
|
-
{ path: "/tenants", router:
|
|
1255
|
+
{ path: "/tenants", router: $ }
|
|
1216
1256
|
]
|
|
1217
1257
|
});
|
|
1218
|
-
return
|
|
1258
|
+
return R.use(
|
|
1219
1259
|
"/api/v2/*",
|
|
1220
|
-
|
|
1221
|
-
), w &&
|
|
1260
|
+
Re(r)
|
|
1261
|
+
), w && R.use("/api/v2/*", be()), { app: R, controlPlaneTenantId: r };
|
|
1222
1262
|
}
|
|
1223
|
-
function
|
|
1224
|
-
const t =
|
|
1263
|
+
function Ee(e) {
|
|
1264
|
+
const t = U(e);
|
|
1225
1265
|
return {
|
|
1226
1266
|
name: "multi-tenancy",
|
|
1227
1267
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1228
|
-
middleware:
|
|
1268
|
+
middleware: te(e),
|
|
1229
1269
|
// Provide lifecycle hooks
|
|
1230
1270
|
hooks: t,
|
|
1231
1271
|
// Mount tenant management routes
|
|
@@ -1245,23 +1285,23 @@ function qe(e) {
|
|
|
1245
1285
|
}
|
|
1246
1286
|
};
|
|
1247
1287
|
}
|
|
1248
|
-
function
|
|
1249
|
-
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);
|
|
1250
1290
|
return {
|
|
1251
1291
|
...t,
|
|
1252
1292
|
...n,
|
|
1253
1293
|
tenants: r
|
|
1254
1294
|
};
|
|
1255
1295
|
}
|
|
1256
|
-
function
|
|
1257
|
-
const t = new
|
|
1296
|
+
function Fe(e) {
|
|
1297
|
+
const t = new ae(), n = U(e);
|
|
1258
1298
|
return t.route("/tenants", N(e, n)), t;
|
|
1259
1299
|
}
|
|
1260
|
-
function
|
|
1300
|
+
function Be(e) {
|
|
1261
1301
|
return {
|
|
1262
|
-
hooks:
|
|
1263
|
-
middleware:
|
|
1264
|
-
app:
|
|
1302
|
+
hooks: U(e),
|
|
1303
|
+
middleware: te(e),
|
|
1304
|
+
app: Fe(e),
|
|
1265
1305
|
config: e,
|
|
1266
1306
|
/**
|
|
1267
1307
|
* Wraps data adapters with runtime fallback from the control plane.
|
|
@@ -1273,7 +1313,7 @@ function Oe(e) {
|
|
|
1273
1313
|
*/
|
|
1274
1314
|
wrapAdapters: (t, n) => {
|
|
1275
1315
|
var r;
|
|
1276
|
-
return
|
|
1316
|
+
return ee(t, {
|
|
1277
1317
|
controlPlaneTenantId: (r = e.accessControl) == null ? void 0 : r.controlPlaneTenantId,
|
|
1278
1318
|
controlPlaneClientId: n == null ? void 0 : n.controlPlaneClientId
|
|
1279
1319
|
});
|
|
@@ -1281,24 +1321,24 @@ function Oe(e) {
|
|
|
1281
1321
|
};
|
|
1282
1322
|
}
|
|
1283
1323
|
export {
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
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,
|
|
1335
|
+
Ae as createRuntimeFallbackAdapter,
|
|
1336
|
+
$e as createSubdomainMiddleware,
|
|
1337
|
+
ve as createSyncHooks,
|
|
1298
1338
|
N as createTenantsOpenAPIRouter,
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1339
|
+
qe as initMultiTenant,
|
|
1340
|
+
Be as setupMultiTenancy,
|
|
1341
|
+
me as validateTenantAccess,
|
|
1342
|
+
ee as withRuntimeFallback,
|
|
1343
|
+
Se as withSystemResourceServerInheritance
|
|
1304
1344
|
};
|