@authhero/multi-tenancy 14.24.1 → 14.25.1
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 +287 -212
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rollout/defaults-projection.d.ts +47 -1
- package/dist/types/rollout/defaults-projection.d.ts.map +1 -1
- package/dist/types/rollout/index.d.ts +3 -1
- package/dist/types/rollout/index.d.ts.map +1 -1
- package/dist/types/rollout/payload.d.ts +91 -0
- package/dist/types/rollout/payload.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Hono as e } from "hono";
|
|
2
|
-
import { MANAGEMENT_API_AUDIENCE as t, MANAGEMENT_API_SCOPES as n, auth0QuerySchema as r,
|
|
3
|
-
import { OpenAPIHono as
|
|
4
|
-
import { HTTPException as
|
|
2
|
+
import { MANAGEMENT_API_AUDIENCE as t, MANAGEMENT_API_SCOPES as n, auth0QuerySchema as r, brandingSchema as i, connectionInsertSchema as a, connectionOptionsSchema as o, connectionSchema as s, deepMergePatch as c, emailProviderSchema as l, fetchAll as u, hookInsertSchema as d, init as f, listControlPlaneKeys as p, promptSettingSchema as m, resourceServerInsertSchema as h, tenantInsertSchema as g, tenantSchema as _ } from "authhero";
|
|
3
|
+
import { OpenAPIHono as v, createRoute as y, z as b } from "@hono/zod-openapi";
|
|
4
|
+
import { HTTPException as x } from "hono/http-exception";
|
|
5
5
|
//#region src/hooks/access-control.ts
|
|
6
|
-
function
|
|
6
|
+
function S(e) {
|
|
7
7
|
let { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
8
8
|
return { async onTenantAccessValidation(e, r) {
|
|
9
9
|
if (r === t) return !0;
|
|
@@ -14,14 +14,14 @@ function v(e) {
|
|
|
14
14
|
return !0;
|
|
15
15
|
} };
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function C(e, t, n, r) {
|
|
18
18
|
if (t === n) return !0;
|
|
19
19
|
let i = r || e;
|
|
20
20
|
return i ? i.toLowerCase() === t.toLowerCase() : !1;
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/hooks/database.ts
|
|
24
|
-
function
|
|
24
|
+
function w(e) {
|
|
25
25
|
return { async resolveDataAdapters(t) {
|
|
26
26
|
try {
|
|
27
27
|
return await e.getAdapters(t);
|
|
@@ -33,20 +33,20 @@ function b(e) {
|
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/hooks/provisioning.ts
|
|
36
|
-
function
|
|
36
|
+
function T(e) {
|
|
37
37
|
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function E(e) {
|
|
40
40
|
return {
|
|
41
41
|
async beforeCreate(e, t) {
|
|
42
42
|
return !t.audience && t.id ? {
|
|
43
43
|
...t,
|
|
44
|
-
audience:
|
|
44
|
+
audience: T(t.id)
|
|
45
45
|
} : t;
|
|
46
46
|
},
|
|
47
47
|
async afterCreate(t, n) {
|
|
48
48
|
let { accessControl: r, databaseIsolation: i } = e;
|
|
49
|
-
r && t.ctx && await
|
|
49
|
+
r && t.ctx && await ee(t, n, r), i?.onProvision && await i.onProvision(n.id);
|
|
50
50
|
},
|
|
51
51
|
async beforeDelete(t, n) {
|
|
52
52
|
let { accessControl: r, databaseIsolation: i } = e;
|
|
@@ -64,14 +64,14 @@ function S(e) {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
async function
|
|
67
|
+
async function ee(e, t, n) {
|
|
68
68
|
let { controlPlaneTenantId: r, defaultPermissions: i, defaultRoles: a, issuer: o, adminRoleName: s = "Tenant Admin", adminRoleDescription: c = "Full access to all tenant management operations", addCreatorToOrganization: l = !0 } = n, u = await e.adapters.organizations.create(r, {
|
|
69
69
|
name: t.id,
|
|
70
70
|
display_name: t.friendly_name || t.id
|
|
71
71
|
}), d;
|
|
72
|
-
if (o && (d = await
|
|
72
|
+
if (o && (d = await ne(e, r, s, c)), l && e.ctx) {
|
|
73
73
|
let t = e.ctx.var.user;
|
|
74
|
-
if (t?.sub && !await
|
|
74
|
+
if (t?.sub && !await te(e, r, t.sub)) try {
|
|
75
75
|
await e.adapters.userOrganizations.create(r, {
|
|
76
76
|
user_id: t.sub,
|
|
77
77
|
organization_id: u.id
|
|
@@ -82,12 +82,12 @@ async function C(e, t, n) {
|
|
|
82
82
|
}
|
|
83
83
|
a && a.length > 0 && console.log(`Would assign roles ${a.join(", ")} to organization ${u.id}`), i && i.length > 0 && console.log(`Would grant permissions ${i.join(", ")} to organization ${u.id}`);
|
|
84
84
|
}
|
|
85
|
-
async function
|
|
85
|
+
async function te(e, t, n) {
|
|
86
86
|
let r = await e.adapters.userRoles.list(t, n, void 0, "");
|
|
87
87
|
for (let n of r) if ((await e.adapters.rolePermissions.list(t, n.id, { per_page: 1e3 })).some((e) => e.permission_name === "admin:organizations")) return !0;
|
|
88
88
|
return !1;
|
|
89
89
|
}
|
|
90
|
-
async function
|
|
90
|
+
async function ne(e, r, i, a) {
|
|
91
91
|
let o = (await e.adapters.roles.list(r, {})).roles.find((e) => e.name === i);
|
|
92
92
|
if (o) return o.id;
|
|
93
93
|
let s = await e.adapters.roles.create(r, {
|
|
@@ -102,7 +102,7 @@ async function T(e, r, i, a) {
|
|
|
102
102
|
}
|
|
103
103
|
//#endregion
|
|
104
104
|
//#region src/hooks/sync.ts
|
|
105
|
-
function
|
|
105
|
+
function D(e, t, n = () => !0) {
|
|
106
106
|
let { controlPlaneTenantId: r, getChildTenantIds: i, getAdapters: a } = e, o = /* @__PURE__ */ new Map();
|
|
107
107
|
async function s(e, n, r) {
|
|
108
108
|
return (await t(e).list(n, {
|
|
@@ -157,18 +157,18 @@ function E(e, t, n = () => !0) {
|
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function O(e, t, n = () => !0) {
|
|
161
161
|
let { controlPlaneTenantId: r, getControlPlaneAdapters: i, getAdapters: a } = e;
|
|
162
162
|
return { async afterCreate(e, o) {
|
|
163
163
|
if (o.id !== r) try {
|
|
164
|
-
let e = await i(), s = await a(o.id),
|
|
164
|
+
let e = await i(), s = await a(o.id), c = t(e), l = t(s), d = await u((e) => c.listPaginated(r, e), c.listKey, {
|
|
165
165
|
cursorField: "id",
|
|
166
166
|
pageSize: 100
|
|
167
167
|
});
|
|
168
168
|
await Promise.all(d.filter((e) => n(e)).map(async (e) => {
|
|
169
169
|
try {
|
|
170
|
-
let t =
|
|
171
|
-
await
|
|
170
|
+
let t = c.transform(e);
|
|
171
|
+
await l.create(o.id, {
|
|
172
172
|
...t,
|
|
173
173
|
is_system: !0
|
|
174
174
|
});
|
|
@@ -181,7 +181,7 @@ function D(e, t, n = () => !0) {
|
|
|
181
181
|
}
|
|
182
182
|
} };
|
|
183
183
|
}
|
|
184
|
-
var
|
|
184
|
+
var k = (e) => ({
|
|
185
185
|
list: async (t, n) => (await e.resourceServers.list(t, n)).resource_servers,
|
|
186
186
|
listPaginated: (t, n) => e.resourceServers.list(t, n),
|
|
187
187
|
get: (t, n) => e.resourceServers.get(t, n),
|
|
@@ -199,7 +199,7 @@ var O = (e) => ({
|
|
|
199
199
|
token_lifetime: e.token_lifetime,
|
|
200
200
|
token_lifetime_for_web: e.token_lifetime_for_web
|
|
201
201
|
})
|
|
202
|
-
}),
|
|
202
|
+
}), A = (e) => ({
|
|
203
203
|
list: async (t, n) => (await e.roles.list(t, n)).roles,
|
|
204
204
|
listPaginated: (t, n) => e.roles.list(t, n),
|
|
205
205
|
get: (t, n) => e.roles.get(t, n),
|
|
@@ -214,15 +214,15 @@ var O = (e) => ({
|
|
|
214
214
|
description: e.description
|
|
215
215
|
})
|
|
216
216
|
});
|
|
217
|
-
function
|
|
217
|
+
function j(e) {
|
|
218
218
|
return e.metadata?.sync !== !1;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
let { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, i = t.roles ?? !0, a = (e) =>
|
|
220
|
+
function re(e) {
|
|
221
|
+
let { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, i = t.roles ?? !0, a = (e) => j(e) ? n.resourceServers ? n.resourceServers(e) : !0 : !1, o = (e) => j(e) ? n.roles ? n.roles(e) : !0 : !1, s = r ? D(e, k, a) : void 0, c = i ? D(e, A, o) : void 0, l = r ? O(e, k, a) : void 0, d = i ? O(e, A, o) : void 0, f = i ? { async afterCreate(t, r) {
|
|
222
222
|
if (r.id !== e.controlPlaneTenantId) {
|
|
223
223
|
await d?.afterCreate?.(t, r);
|
|
224
224
|
try {
|
|
225
|
-
let t = await e.getControlPlaneAdapters(), i = await e.getAdapters(r.id), a = await
|
|
225
|
+
let t = await e.getControlPlaneAdapters(), i = await e.getAdapters(r.id), a = await u((n) => t.roles.list(e.controlPlaneTenantId, n), "roles", {
|
|
226
226
|
cursorField: "id",
|
|
227
227
|
pageSize: 100
|
|
228
228
|
}), o = /* @__PURE__ */ new Map();
|
|
@@ -257,10 +257,10 @@ function j(e) {
|
|
|
257
257
|
return {
|
|
258
258
|
entityHooks: {
|
|
259
259
|
resourceServers: s,
|
|
260
|
-
roles:
|
|
260
|
+
roles: c
|
|
261
261
|
},
|
|
262
262
|
tenantHooks: { async afterCreate(e, t) {
|
|
263
|
-
let n = [
|
|
263
|
+
let n = [l?.afterCreate, f?.afterCreate ?? d?.afterCreate], r = [];
|
|
264
264
|
for (let i of n) if (i) try {
|
|
265
265
|
await i(e, t);
|
|
266
266
|
} catch (e) {
|
|
@@ -273,35 +273,35 @@ function j(e) {
|
|
|
273
273
|
}
|
|
274
274
|
//#endregion
|
|
275
275
|
//#region src/routes/tenants.ts
|
|
276
|
-
var
|
|
277
|
-
sub:
|
|
278
|
-
tenant_id:
|
|
279
|
-
org_id:
|
|
280
|
-
scope:
|
|
281
|
-
permissions:
|
|
276
|
+
var ie = b.object({
|
|
277
|
+
sub: b.string(),
|
|
278
|
+
tenant_id: b.string().optional(),
|
|
279
|
+
org_id: b.string().optional(),
|
|
280
|
+
scope: b.string().optional(),
|
|
281
|
+
permissions: b.array(b.string()).optional()
|
|
282
282
|
}).passthrough();
|
|
283
|
-
function
|
|
284
|
-
let t =
|
|
283
|
+
function ae(e) {
|
|
284
|
+
let t = ie.safeParse(e);
|
|
285
285
|
return t.success ? t.data : void 0;
|
|
286
286
|
}
|
|
287
|
-
function
|
|
287
|
+
function oe(e) {
|
|
288
288
|
let t = e.permissions ?? [], n = e.scope ? e.scope.split(" ").filter(Boolean) : [], r = new Set([...t, ...n]);
|
|
289
289
|
return r.has("delete:tenants") || r.has("admin:organizations");
|
|
290
290
|
}
|
|
291
291
|
function M(e, t) {
|
|
292
|
-
let n = new
|
|
293
|
-
return n.openapi(
|
|
292
|
+
let n = new v();
|
|
293
|
+
return n.openapi(y({
|
|
294
294
|
tags: ["tenants"],
|
|
295
295
|
method: "get",
|
|
296
296
|
path: "/",
|
|
297
297
|
request: { query: r },
|
|
298
298
|
security: [{ Bearer: [] }],
|
|
299
299
|
responses: { 200: {
|
|
300
|
-
content: { "application/json": { schema:
|
|
301
|
-
tenants:
|
|
302
|
-
start:
|
|
303
|
-
limit:
|
|
304
|
-
length:
|
|
300
|
+
content: { "application/json": { schema: b.object({
|
|
301
|
+
tenants: b.array(_),
|
|
302
|
+
start: b.number().optional(),
|
|
303
|
+
limit: b.number().optional(),
|
|
304
|
+
length: b.number().optional()
|
|
305
305
|
}) } },
|
|
306
306
|
description: "List of tenants"
|
|
307
307
|
} }
|
|
@@ -321,17 +321,17 @@ function M(e, t) {
|
|
|
321
321
|
length: e.tenants.length
|
|
322
322
|
}) : t.json({ tenants: e.tenants });
|
|
323
323
|
}
|
|
324
|
-
let
|
|
325
|
-
if (
|
|
326
|
-
if (
|
|
327
|
-
let e = (await
|
|
324
|
+
let c = e.accessControl?.controlPlaneTenantId ?? t.env.data.multiTenancyConfig?.controlPlaneTenantId;
|
|
325
|
+
if (c && !o?.sub) throw new x(403, { message: "Access denied: token has no subject" });
|
|
326
|
+
if (c && o?.sub) {
|
|
327
|
+
let e = (await u((e) => t.env.data.userOrganizations.listUserOrganizations(c, o.sub, e), "organizations")).map((e) => e.name);
|
|
328
328
|
if (e.length === 0) return i ? t.json({
|
|
329
329
|
tenants: [],
|
|
330
330
|
start: 0,
|
|
331
331
|
limit: r ?? 50,
|
|
332
332
|
length: 0
|
|
333
333
|
}) : t.json({ tenants: [] });
|
|
334
|
-
let s = e.length,
|
|
334
|
+
let s = e.length, l = n ?? 0, d = r ?? 50, f = l * d, p = e.slice(f, f + d);
|
|
335
335
|
if (p.length === 0) return i ? t.json({
|
|
336
336
|
tenants: [],
|
|
337
337
|
start: f,
|
|
@@ -350,34 +350,34 @@ function M(e, t) {
|
|
|
350
350
|
length: s
|
|
351
351
|
}) : t.json({ tenants: g.tenants });
|
|
352
352
|
}
|
|
353
|
-
let
|
|
353
|
+
let l = await t.env.data.tenants.list({
|
|
354
354
|
page: n,
|
|
355
355
|
per_page: r,
|
|
356
356
|
include_totals: i,
|
|
357
357
|
q: a
|
|
358
358
|
});
|
|
359
359
|
return i ? t.json({
|
|
360
|
-
tenants:
|
|
361
|
-
start:
|
|
362
|
-
limit:
|
|
363
|
-
length:
|
|
364
|
-
}) : t.json({ tenants:
|
|
365
|
-
}), n.openapi(
|
|
360
|
+
tenants: l.tenants,
|
|
361
|
+
start: l.totals?.start ?? 0,
|
|
362
|
+
limit: l.totals?.limit ?? r,
|
|
363
|
+
length: l.tenants.length
|
|
364
|
+
}) : t.json({ tenants: l.tenants });
|
|
365
|
+
}), n.openapi(y({
|
|
366
366
|
tags: ["tenants"],
|
|
367
367
|
method: "post",
|
|
368
368
|
path: "/",
|
|
369
|
-
request: { body: { content: { "application/json": { schema:
|
|
369
|
+
request: { body: { content: { "application/json": { schema: g } } } },
|
|
370
370
|
security: [{ Bearer: [] }],
|
|
371
371
|
responses: {
|
|
372
372
|
201: {
|
|
373
|
-
content: { "application/json": { schema:
|
|
373
|
+
content: { "application/json": { schema: _ } },
|
|
374
374
|
description: "Tenant created"
|
|
375
375
|
},
|
|
376
376
|
400: { description: "Validation error" },
|
|
377
377
|
409: { description: "Tenant with this ID already exists" }
|
|
378
378
|
}
|
|
379
379
|
}), async (e) => {
|
|
380
|
-
if (!e.var.user?.sub) throw new
|
|
380
|
+
if (!e.var.user?.sub) throw new x(401, { message: "Authentication required to create tenants" });
|
|
381
381
|
let n = e.req.valid("json"), r = {
|
|
382
382
|
adapters: e.env.data,
|
|
383
383
|
ctx: e
|
|
@@ -385,11 +385,11 @@ function M(e, t) {
|
|
|
385
385
|
t.tenants?.beforeCreate && (n = await t.tenants.beforeCreate(r, n));
|
|
386
386
|
let i = await e.env.data.tenants.create(n);
|
|
387
387
|
return t.tenants?.afterCreate && await t.tenants.afterCreate(r, i), e.json(i, 201);
|
|
388
|
-
}), n.openapi(
|
|
388
|
+
}), n.openapi(y({
|
|
389
389
|
tags: ["tenants"],
|
|
390
390
|
method: "delete",
|
|
391
391
|
path: "/{id}",
|
|
392
|
-
request: { params:
|
|
392
|
+
request: { params: b.object({ id: b.string() }) },
|
|
393
393
|
security: [{ Bearer: ["delete:tenants"] }],
|
|
394
394
|
responses: {
|
|
395
395
|
204: { description: "Tenant deleted" },
|
|
@@ -399,62 +399,62 @@ function M(e, t) {
|
|
|
399
399
|
}), async (n) => {
|
|
400
400
|
let { id: r } = n.req.valid("param"), i = e.accessControl?.controlPlaneTenantId ?? n.env.data.multiTenancyConfig?.controlPlaneTenantId;
|
|
401
401
|
if (i) {
|
|
402
|
-
let e =
|
|
403
|
-
if (!e?.sub) throw new
|
|
404
|
-
if (r === i) throw new
|
|
402
|
+
let e = ae(n.var.user);
|
|
403
|
+
if (!e?.sub) throw new x(401, { message: "Authentication required" });
|
|
404
|
+
if (r === i) throw new x(403, { message: "Cannot delete the control plane" });
|
|
405
405
|
let t = n.var.org_name, a = r.toLowerCase(), o = !!t && t.toLowerCase() === a;
|
|
406
406
|
if (!o) {
|
|
407
407
|
let r = !!(e.org_id ?? n.var.organization_id ?? t), a = !e.tenant_id || e.tenant_id === i;
|
|
408
|
-
!r && a &&
|
|
408
|
+
!r && a && oe(e) && (o = !0);
|
|
409
409
|
}
|
|
410
|
-
if (o ||= (await
|
|
410
|
+
if (o ||= (await u((t) => n.env.data.userOrganizations.listUserOrganizations(i, e.sub, t), "organizations")).some((e) => e.name?.toLowerCase() === a), !o) throw new x(403, { message: "Access denied to this tenant" });
|
|
411
411
|
}
|
|
412
|
-
if (!await n.env.data.tenants.get(r)) throw new
|
|
412
|
+
if (!await n.env.data.tenants.get(r)) throw new x(404, { message: "Tenant not found" });
|
|
413
413
|
let a = {
|
|
414
414
|
adapters: n.env.data,
|
|
415
415
|
ctx: n
|
|
416
416
|
};
|
|
417
417
|
return t.tenants?.beforeDelete && await t.tenants.beforeDelete(a, r), await n.env.data.tenants.remove(r), t.tenants?.afterDelete && await t.tenants.afterDelete(a, r), n.body(null, 204);
|
|
418
|
-
}), n.openapi(
|
|
418
|
+
}), n.openapi(y({
|
|
419
419
|
tags: ["tenants", "settings"],
|
|
420
420
|
method: "get",
|
|
421
421
|
path: "/settings",
|
|
422
|
-
request: { headers:
|
|
422
|
+
request: { headers: b.object({ "tenant-id": b.string().optional() }) },
|
|
423
423
|
security: [{ Bearer: ["read:tenants"] }],
|
|
424
424
|
responses: { 200: {
|
|
425
|
-
content: { "application/json": { schema:
|
|
425
|
+
content: { "application/json": { schema: _ } },
|
|
426
426
|
description: "Current tenant settings"
|
|
427
427
|
} }
|
|
428
428
|
}), async (e) => {
|
|
429
429
|
let t = await e.env.data.tenants.get(e.var.tenant_id);
|
|
430
|
-
if (!t) throw new
|
|
430
|
+
if (!t) throw new x(404, { message: "Tenant not found" });
|
|
431
431
|
return e.json(t);
|
|
432
|
-
}), n.openapi(
|
|
432
|
+
}), n.openapi(y({
|
|
433
433
|
tags: ["tenants", "settings"],
|
|
434
434
|
method: "patch",
|
|
435
435
|
path: "/settings",
|
|
436
436
|
request: {
|
|
437
|
-
headers:
|
|
438
|
-
body: { content: { "application/json": { schema:
|
|
437
|
+
headers: b.object({ "tenant-id": b.string().optional() }),
|
|
438
|
+
body: { content: { "application/json": { schema: b.object(g.shape).partial() } } }
|
|
439
439
|
},
|
|
440
440
|
security: [{ Bearer: ["update:tenants"] }],
|
|
441
441
|
responses: { 200: {
|
|
442
|
-
content: { "application/json": { schema:
|
|
442
|
+
content: { "application/json": { schema: _ } },
|
|
443
443
|
description: "Updated tenant settings"
|
|
444
444
|
} }
|
|
445
445
|
}), async (e) => {
|
|
446
446
|
let { id: t, ...n } = e.req.valid("json"), r = await e.env.data.tenants.get(e.var.tenant_id);
|
|
447
|
-
if (!r) throw new
|
|
448
|
-
let i =
|
|
447
|
+
if (!r) throw new x(404, { message: "Tenant not found" });
|
|
448
|
+
let i = c(r, n);
|
|
449
449
|
await e.env.data.tenants.update(e.var.tenant_id, i);
|
|
450
450
|
let a = await e.env.data.tenants.get(e.var.tenant_id);
|
|
451
|
-
if (!a) throw new
|
|
451
|
+
if (!a) throw new x(500, { message: "Failed to retrieve updated tenant" });
|
|
452
452
|
return e.json(a);
|
|
453
453
|
}), n;
|
|
454
454
|
}
|
|
455
455
|
//#endregion
|
|
456
456
|
//#region src/middleware/protect-synced.ts
|
|
457
|
-
function
|
|
457
|
+
function se(e) {
|
|
458
458
|
for (let { pattern: t, type: n } of [
|
|
459
459
|
{
|
|
460
460
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -477,7 +477,7 @@ function N(e) {
|
|
|
477
477
|
}
|
|
478
478
|
return null;
|
|
479
479
|
}
|
|
480
|
-
async function
|
|
480
|
+
async function ce(e, t, n) {
|
|
481
481
|
try {
|
|
482
482
|
switch (n.type) {
|
|
483
483
|
case "resource_server": return (await e.resourceServers.get(t, n.id))?.is_system === !0;
|
|
@@ -489,47 +489,47 @@ async function re(e, t, n) {
|
|
|
489
489
|
return !1;
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
|
-
function
|
|
492
|
+
function le(e) {
|
|
493
493
|
return {
|
|
494
494
|
resource_server: "resource server",
|
|
495
495
|
role: "role",
|
|
496
496
|
connection: "connection"
|
|
497
497
|
}[e];
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function N() {
|
|
500
500
|
return async (e, t) => {
|
|
501
501
|
if (![
|
|
502
502
|
"PATCH",
|
|
503
503
|
"PUT",
|
|
504
504
|
"DELETE"
|
|
505
505
|
].includes(e.req.method)) return t();
|
|
506
|
-
let n =
|
|
506
|
+
let n = se(e.req.path);
|
|
507
507
|
if (!n) return t();
|
|
508
508
|
let r = e.var.tenant_id || e.req.header("x-tenant-id") || e.req.header("tenant-id");
|
|
509
509
|
if (!r) return t();
|
|
510
|
-
if (await
|
|
510
|
+
if (await ce(e.env.data, r, n)) throw new x(403, { message: `This ${le(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.` });
|
|
511
511
|
return t();
|
|
512
512
|
};
|
|
513
513
|
}
|
|
514
514
|
//#endregion
|
|
515
515
|
//#region src/middleware/settings-inheritance.ts
|
|
516
|
-
function
|
|
516
|
+
function P(e, t) {
|
|
517
517
|
let n = t.find((t) => t.strategy === e.strategy);
|
|
518
518
|
if (!n?.options) return e;
|
|
519
|
-
let r =
|
|
519
|
+
let r = s.passthrough().parse({
|
|
520
520
|
...n,
|
|
521
521
|
...e
|
|
522
522
|
});
|
|
523
|
-
return r.options =
|
|
523
|
+
return r.options = o.passthrough().parse({
|
|
524
524
|
...n.options || {},
|
|
525
525
|
...e.options
|
|
526
526
|
}), r;
|
|
527
527
|
}
|
|
528
|
-
function
|
|
528
|
+
function F(e, t) {
|
|
529
529
|
let n = [...t || [], ...e || []];
|
|
530
530
|
return [...new Set(n)];
|
|
531
531
|
}
|
|
532
|
-
function
|
|
532
|
+
function ue(e, t) {
|
|
533
533
|
if (!t?.length) return e || [];
|
|
534
534
|
if (!e?.length) return t;
|
|
535
535
|
let n = /* @__PURE__ */ new Map();
|
|
@@ -537,22 +537,22 @@ function ae(e, t) {
|
|
|
537
537
|
for (let t of e) n.set(t.value, t);
|
|
538
538
|
return Array.from(n.values());
|
|
539
539
|
}
|
|
540
|
-
function
|
|
540
|
+
function I(e, t) {
|
|
541
541
|
return t ? {
|
|
542
542
|
...e,
|
|
543
|
-
scopes:
|
|
543
|
+
scopes: ue(e.scopes, t.scopes)
|
|
544
544
|
} : e;
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function de(e, t) {
|
|
547
547
|
return t ? {
|
|
548
548
|
...e,
|
|
549
|
-
callbacks:
|
|
550
|
-
web_origins:
|
|
551
|
-
allowed_logout_urls:
|
|
552
|
-
allowed_origins:
|
|
549
|
+
callbacks: F(e.callbacks, t.callbacks),
|
|
550
|
+
web_origins: F(e.web_origins, t.web_origins),
|
|
551
|
+
allowed_logout_urls: F(e.allowed_logout_urls, t.allowed_logout_urls),
|
|
552
|
+
allowed_origins: F(e.allowed_origins, t.allowed_origins)
|
|
553
553
|
} : e;
|
|
554
554
|
}
|
|
555
|
-
function
|
|
555
|
+
function L(e) {
|
|
556
556
|
let { controlPlaneTenantId: t, controlPlaneClientId: n, resolveControlPlane: r } = e;
|
|
557
557
|
if (r) return async (e) => r({ tenant_id: e });
|
|
558
558
|
if (!t) return async () => void 0;
|
|
@@ -562,14 +562,14 @@ function R(e) {
|
|
|
562
562
|
};
|
|
563
563
|
return async () => i;
|
|
564
564
|
}
|
|
565
|
-
function
|
|
565
|
+
function R(e, t) {
|
|
566
566
|
return {
|
|
567
567
|
...e.resourceServers,
|
|
568
568
|
get: async (n, r) => {
|
|
569
569
|
let i = await e.resourceServers.get(n, r);
|
|
570
570
|
if (!i) return i;
|
|
571
571
|
let a = await t(n);
|
|
572
|
-
return !a || n === a.tenantId || !i.is_system ? i :
|
|
572
|
+
return !a || n === a.tenantId || !i.is_system ? i : I(i, await e.resourceServers.get(a.tenantId, r));
|
|
573
573
|
},
|
|
574
574
|
list: async (n, r) => {
|
|
575
575
|
let i = await e.resourceServers.list(n, r), a = await t(n);
|
|
@@ -581,7 +581,7 @@ function z(e, t) {
|
|
|
581
581
|
let n = await e.resourceServers.get(o, t);
|
|
582
582
|
n && c.set(t, n);
|
|
583
583
|
}));
|
|
584
|
-
let l = i.resource_servers.map((e) => e.is_system && e.id ?
|
|
584
|
+
let l = i.resource_servers.map((e) => e.is_system && e.id ? I(e, c.get(e.id) ?? null) : e);
|
|
585
585
|
return {
|
|
586
586
|
...i,
|
|
587
587
|
resource_servers: l
|
|
@@ -589,18 +589,18 @@ function z(e, t) {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
}
|
|
592
|
-
function
|
|
593
|
-
let n =
|
|
592
|
+
function z(e, t) {
|
|
593
|
+
let n = L({
|
|
594
594
|
controlPlaneTenantId: t.controlPlaneTenantId,
|
|
595
595
|
resolveControlPlane: t.resolveControlPlane
|
|
596
596
|
});
|
|
597
597
|
return {
|
|
598
598
|
...e,
|
|
599
|
-
resourceServers:
|
|
599
|
+
resourceServers: R(e, n)
|
|
600
600
|
};
|
|
601
601
|
}
|
|
602
|
-
function
|
|
603
|
-
let { controlPlaneTenantId: n, controlPlaneClientId: r, resolveControlPlane: i } = t, a =
|
|
602
|
+
function B(e, t) {
|
|
603
|
+
let { controlPlaneTenantId: n, controlPlaneClientId: r, resolveControlPlane: i } = t, a = L({
|
|
604
604
|
controlPlaneTenantId: n,
|
|
605
605
|
controlPlaneClientId: r,
|
|
606
606
|
resolveControlPlane: i
|
|
@@ -618,12 +618,12 @@ function V(e, t) {
|
|
|
618
618
|
let r = await e.connections.get(t, n);
|
|
619
619
|
if (!r) return r;
|
|
620
620
|
let i = await a(t);
|
|
621
|
-
return !i || t === i.tenantId ? r :
|
|
621
|
+
return !i || t === i.tenantId ? r : P(r, (await e.connections.list(i.tenantId)).connections || []);
|
|
622
622
|
},
|
|
623
623
|
list: async (t, n) => {
|
|
624
624
|
let r = await e.connections.list(t, n), i = await a(t);
|
|
625
625
|
if (!i || t === i.tenantId) return r;
|
|
626
|
-
let o = await e.connections.list(i.tenantId), s = r.connections.map((e) =>
|
|
626
|
+
let o = await e.connections.list(i.tenantId), s = r.connections.map((e) => P(e, o.connections || []));
|
|
627
627
|
return {
|
|
628
628
|
...r,
|
|
629
629
|
connections: s
|
|
@@ -638,7 +638,7 @@ function V(e, t) {
|
|
|
638
638
|
let i = await a(t);
|
|
639
639
|
if (!i || t === i.tenantId) return r;
|
|
640
640
|
let o = await e.connections.list(i.tenantId);
|
|
641
|
-
return r.map((e) =>
|
|
641
|
+
return r.map((e) => P(e, o.connections || []));
|
|
642
642
|
}
|
|
643
643
|
},
|
|
644
644
|
emailProviders: {
|
|
@@ -650,22 +650,22 @@ function V(e, t) {
|
|
|
650
650
|
return !r || t === r.tenantId ? null : e.emailProviders.get(r.tenantId);
|
|
651
651
|
}
|
|
652
652
|
},
|
|
653
|
-
resourceServers:
|
|
654
|
-
hooks:
|
|
653
|
+
resourceServers: R(e, a),
|
|
654
|
+
hooks: fe(e, a)
|
|
655
655
|
};
|
|
656
656
|
}
|
|
657
|
-
function
|
|
657
|
+
function V(e) {
|
|
658
658
|
if (!e || typeof e != "object") return !1;
|
|
659
659
|
let t = e.metadata;
|
|
660
660
|
return !t || typeof t != "object" ? !1 : t.inheritable === !0;
|
|
661
661
|
}
|
|
662
|
-
function
|
|
662
|
+
function fe(e, t) {
|
|
663
663
|
return {
|
|
664
664
|
...e.hooks,
|
|
665
665
|
list: async (n, r) => {
|
|
666
666
|
let i = await e.hooks.list(n, r), a = await t(n);
|
|
667
667
|
if (!a || n === a.tenantId) return i;
|
|
668
|
-
let o = ((await e.hooks.list(a.tenantId, r)).hooks || []).filter(
|
|
668
|
+
let o = ((await e.hooks.list(a.tenantId, r)).hooks || []).filter(V);
|
|
669
669
|
if (o.length === 0) return i;
|
|
670
670
|
let s = new Set((i.hooks || []).map((e) => e.hook_id)), c = o.filter((e) => !s.has(e.hook_id));
|
|
671
671
|
return {
|
|
@@ -680,31 +680,31 @@ function se(e, t) {
|
|
|
680
680
|
let a = await t(n);
|
|
681
681
|
if (!a || n === a.tenantId) return i;
|
|
682
682
|
let o = await e.hooks.get(a.tenantId, r);
|
|
683
|
-
return o &&
|
|
683
|
+
return o && V(o) ? o : null;
|
|
684
684
|
}
|
|
685
685
|
};
|
|
686
686
|
}
|
|
687
|
-
function
|
|
688
|
-
return
|
|
687
|
+
function H(e, t) {
|
|
688
|
+
return B(e, t);
|
|
689
689
|
}
|
|
690
690
|
//#endregion
|
|
691
691
|
//#region src/middleware/index.ts
|
|
692
|
-
function
|
|
692
|
+
function U(e) {
|
|
693
693
|
return async (t, n) => {
|
|
694
694
|
let r = t.var.user;
|
|
695
695
|
return r?.tenant_id === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
696
696
|
};
|
|
697
697
|
}
|
|
698
|
-
function
|
|
698
|
+
function W(e) {
|
|
699
699
|
return async (n, r) => {
|
|
700
700
|
if (!e.accessControl) return r();
|
|
701
701
|
let { controlPlaneTenantId: i } = e.accessControl, a = n.var.org_name, o = n.var.organization_id, s = a || o, c = n.var.tenant_id, l = n.var.user, u = (l?.aud ? Array.isArray(l.aud) ? l.aud : [l.aud] : []).includes(t);
|
|
702
|
-
if (!c && s && u && (n.set("tenant_id", s), c = s), !c) throw new
|
|
703
|
-
if (!
|
|
702
|
+
if (!c && s && u && (n.set("tenant_id", s), c = s), !c) throw new x(400, { message: "Tenant ID not found in request" });
|
|
703
|
+
if (!C(o, c, i, a)) throw new x(403, { message: `Access denied to tenant ${c}` });
|
|
704
704
|
return r();
|
|
705
705
|
};
|
|
706
706
|
}
|
|
707
|
-
function
|
|
707
|
+
function G(e) {
|
|
708
708
|
return async (t, n) => {
|
|
709
709
|
if (!e.subdomainRouting) return n();
|
|
710
710
|
let { baseDomain: r, reservedSubdomains: i = [], resolveSubdomain: a } = e.subdomainRouting, o = t.req.header("x-forwarded-host") || t.req.header("host") || "", s = null;
|
|
@@ -719,43 +719,43 @@ function K(e) {
|
|
|
719
719
|
let n = await t.env.data.organizations.get(e.accessControl.controlPlaneTenantId, s);
|
|
720
720
|
n && (c = n.id);
|
|
721
721
|
} catch {}
|
|
722
|
-
if (!c) throw new
|
|
722
|
+
if (!c) throw new x(404, { message: `Tenant not found for subdomain: ${s}` });
|
|
723
723
|
return t.set("tenant_id", c), n();
|
|
724
724
|
};
|
|
725
725
|
}
|
|
726
|
-
function
|
|
726
|
+
function K(e) {
|
|
727
727
|
return async (t, n) => {
|
|
728
728
|
if (!e.databaseIsolation) return n();
|
|
729
729
|
let r = t.var.tenant_id;
|
|
730
|
-
if (!r) throw new
|
|
730
|
+
if (!r) throw new x(400, { message: "Tenant ID not found in request" });
|
|
731
731
|
try {
|
|
732
732
|
let n = await e.databaseIsolation.getAdapters(r);
|
|
733
733
|
t.env.data = n;
|
|
734
734
|
} catch (e) {
|
|
735
|
-
throw console.error(`Failed to resolve database for tenant ${r}:`, e), new
|
|
735
|
+
throw console.error(`Failed to resolve database for tenant ${r}:`, e), new x(500, { message: "Failed to resolve tenant database" });
|
|
736
736
|
}
|
|
737
737
|
return n();
|
|
738
738
|
};
|
|
739
739
|
}
|
|
740
|
-
function
|
|
741
|
-
let t =
|
|
740
|
+
function q(e) {
|
|
741
|
+
let t = G(e), n = W(e), r = K(e);
|
|
742
742
|
return async (e, i) => (await t(e, async () => {}), await n(e, async () => {}), await r(e, async () => {}), i());
|
|
743
743
|
}
|
|
744
744
|
//#endregion
|
|
745
745
|
//#region src/init.ts
|
|
746
|
-
function
|
|
746
|
+
function pe(e) {
|
|
747
747
|
let { dataAdapter: t, controlPlane: n, controlPlane: { tenantId: r = "control_plane", clientId: i } = {}, resolveControlPlane: a, sync: o = {
|
|
748
748
|
resourceServers: !0,
|
|
749
749
|
roles: !0
|
|
750
|
-
}, defaultPermissions: s = ["tenant:admin"], requireOrganizationMatch:
|
|
750
|
+
}, defaultPermissions: s = ["tenant:admin"], requireOrganizationMatch: c = !1, managementApiExtensions: l = [], entityHooks: d, getChildTenantIds: p, getAdapters: m, ...h } = e;
|
|
751
751
|
if (a && !n) throw Error("initMultiTenant: `resolveControlPlane` requires `controlPlane` to be set. The static `controlPlane.tenantId` is used for access control, sync direction, and tenant management routing; the resolver only overrides per-tenant runtime inheritance lookups on top of it.");
|
|
752
752
|
let g = t, _ = t;
|
|
753
|
-
n && (g =
|
|
753
|
+
n && (g = H(t, {
|
|
754
754
|
controlPlaneTenantId: r,
|
|
755
755
|
controlPlaneClientId: i,
|
|
756
756
|
resolveControlPlane: a
|
|
757
757
|
}), _ = {
|
|
758
|
-
...
|
|
758
|
+
...z(t, {
|
|
759
759
|
controlPlaneTenantId: r,
|
|
760
760
|
resolveControlPlane: a
|
|
761
761
|
}),
|
|
@@ -771,63 +771,84 @@ function ce(e) {
|
|
|
771
771
|
} : {
|
|
772
772
|
resourceServers: !1,
|
|
773
773
|
roles: !1
|
|
774
|
-
}, { entityHooks: b, tenantHooks: x } =
|
|
774
|
+
}, { entityHooks: b, tenantHooks: x } = re({
|
|
775
775
|
controlPlaneTenantId: r,
|
|
776
|
-
getChildTenantIds: p ?? (async () => (await
|
|
776
|
+
getChildTenantIds: p ?? (async () => (await u((e) => g.tenants.list(e), "tenants", {
|
|
777
777
|
cursorField: "id",
|
|
778
778
|
pageSize: 100
|
|
779
779
|
})).filter((e) => e.id !== r).map((e) => e.id)),
|
|
780
780
|
getAdapters: m ?? (async () => g),
|
|
781
781
|
getControlPlaneAdapters: async () => g,
|
|
782
782
|
sync: y
|
|
783
|
-
}),
|
|
784
|
-
resourceServers: [b.resourceServers, ...
|
|
785
|
-
roles: [b.roles, ...
|
|
786
|
-
connections:
|
|
787
|
-
tenants:
|
|
788
|
-
rolePermissions:
|
|
789
|
-
},
|
|
783
|
+
}), S = {
|
|
784
|
+
resourceServers: [b.resourceServers, ...d?.resourceServers ?? []],
|
|
785
|
+
roles: [b.roles, ...d?.roles ?? []],
|
|
786
|
+
connections: d?.connections ?? [],
|
|
787
|
+
tenants: d?.tenants ?? [],
|
|
788
|
+
rolePermissions: d?.rolePermissions ?? []
|
|
789
|
+
}, C = E({ accessControl: {
|
|
790
790
|
controlPlaneTenantId: r,
|
|
791
|
-
requireOrganizationMatch:
|
|
791
|
+
requireOrganizationMatch: c,
|
|
792
792
|
defaultPermissions: s
|
|
793
|
-
} }),
|
|
793
|
+
} }), w = M({ accessControl: {
|
|
794
794
|
controlPlaneTenantId: r,
|
|
795
|
-
requireOrganizationMatch:
|
|
795
|
+
requireOrganizationMatch: c,
|
|
796
796
|
defaultPermissions: s
|
|
797
797
|
} }, { tenants: {
|
|
798
798
|
async beforeCreate(e, t) {
|
|
799
|
-
return
|
|
799
|
+
return C.beforeCreate && (t = await C.beforeCreate(e, t)), x.beforeCreate && (t = await x.beforeCreate(e, t)), t;
|
|
800
800
|
},
|
|
801
801
|
async afterCreate(e, t) {
|
|
802
|
-
await
|
|
802
|
+
await C.afterCreate?.(e, t), await x.afterCreate?.(e, t);
|
|
803
803
|
},
|
|
804
804
|
async beforeDelete(e, t) {
|
|
805
|
-
await
|
|
805
|
+
await C.beforeDelete?.(e, t), await x.beforeDelete?.(e, t);
|
|
806
806
|
}
|
|
807
|
-
} }), { app:
|
|
807
|
+
} }), { app: T } = f({
|
|
808
808
|
dataAdapter: g,
|
|
809
809
|
managementDataAdapter: _,
|
|
810
810
|
...h,
|
|
811
|
-
entityHooks:
|
|
812
|
-
managementApiExtensions: [...
|
|
811
|
+
entityHooks: S,
|
|
812
|
+
managementApiExtensions: [...l, {
|
|
813
813
|
path: "/tenants",
|
|
814
|
-
router:
|
|
814
|
+
router: w
|
|
815
815
|
}]
|
|
816
816
|
});
|
|
817
|
-
return
|
|
818
|
-
app:
|
|
817
|
+
return T.use("/api/v2/*", U(r)), v && T.use("/api/v2/*", N()), {
|
|
818
|
+
app: T,
|
|
819
819
|
controlPlaneTenantId: r
|
|
820
820
|
};
|
|
821
821
|
}
|
|
822
822
|
//#endregion
|
|
823
823
|
//#region src/rollout/defaults-projection.ts
|
|
824
|
+
function J(e = {}) {
|
|
825
|
+
return {
|
|
826
|
+
connections: e.connections ?? !0,
|
|
827
|
+
resourceServers: e.resourceServers ?? !0,
|
|
828
|
+
hooks: e.hooks ?? !0,
|
|
829
|
+
emailProvider: e.emailProvider ?? !0,
|
|
830
|
+
branding: e.branding ?? !0,
|
|
831
|
+
promptSettings: e.promptSettings ?? !0
|
|
832
|
+
};
|
|
833
|
+
}
|
|
824
834
|
function Y() {
|
|
825
835
|
return {
|
|
826
836
|
upserted: 0,
|
|
827
837
|
errors: []
|
|
828
838
|
};
|
|
829
839
|
}
|
|
830
|
-
function
|
|
840
|
+
function me(e) {
|
|
841
|
+
return {
|
|
842
|
+
tenantId: e,
|
|
843
|
+
connections: Y(),
|
|
844
|
+
resourceServers: Y(),
|
|
845
|
+
hooks: Y(),
|
|
846
|
+
emailProvider: Y(),
|
|
847
|
+
branding: Y(),
|
|
848
|
+
promptSettings: Y()
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function he(e) {
|
|
831
852
|
let t = e.metadata;
|
|
832
853
|
return !!(t && t.inheritable === !0);
|
|
833
854
|
}
|
|
@@ -840,70 +861,124 @@ async function X(e, t, n, r) {
|
|
|
840
861
|
e.errors.push(i);
|
|
841
862
|
}
|
|
842
863
|
}
|
|
843
|
-
async function
|
|
844
|
-
|
|
845
|
-
connections:
|
|
846
|
-
resourceServers: o.resourceServers ?? !0,
|
|
847
|
-
hooks: o.hooks ?? !0,
|
|
848
|
-
emailProvider: o.emailProvider ?? !0,
|
|
849
|
-
branding: o.branding ?? !0,
|
|
850
|
-
promptSettings: o.promptSettings ?? !0
|
|
851
|
-
}, f = await r(), p = await a(t), m = {
|
|
852
|
-
tenantId: t,
|
|
853
|
-
connections: Y(),
|
|
854
|
-
resourceServers: Y(),
|
|
855
|
-
hooks: Y(),
|
|
856
|
-
emailProvider: Y(),
|
|
857
|
-
branding: Y(),
|
|
858
|
-
promptSettings: Y()
|
|
859
|
-
};
|
|
860
|
-
if (u.connections) {
|
|
861
|
-
let e = await c((e) => f.connections.list(n, e), "connections", {
|
|
864
|
+
async function ge(e, t, n) {
|
|
865
|
+
return {
|
|
866
|
+
connections: n.connections ? await u((n) => e.connections.list(t, n), "connections", {
|
|
862
867
|
cursorField: "id",
|
|
863
868
|
pageSize: 100
|
|
864
|
-
})
|
|
865
|
-
|
|
866
|
-
let e = t.id;
|
|
867
|
-
e && await X(m.connections, `connection ${e}`, s, async () => {
|
|
868
|
-
let r = i.parse(t);
|
|
869
|
-
await p.connections.get(n, e) ? await p.connections.update(n, e, r) : await p.connections.create(n, r), m.connections.upserted += 1;
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
if (u.resourceServers) {
|
|
874
|
-
let e = await c((e) => f.resourceServers.list(n, e), "resource_servers", {
|
|
869
|
+
}) : [],
|
|
870
|
+
resourceServers: n.resourceServers ? await u((n) => e.resourceServers.list(t, n), "resource_servers", {
|
|
875
871
|
cursorField: "id",
|
|
876
872
|
pageSize: 100
|
|
877
|
-
})
|
|
878
|
-
|
|
879
|
-
let e = d.parse(t);
|
|
880
|
-
await p.resourceServers.get(n, t.id) ? await p.resourceServers.update(n, t.id, e) : await p.resourceServers.create(n, e), m.resourceServers.upserted += 1;
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
if (u.hooks) {
|
|
884
|
-
let e = await c((e) => f.hooks.list(n, e), "hooks", {
|
|
873
|
+
}) : [],
|
|
874
|
+
hooks: n.hooks ? await u((n) => e.hooks.list(t, n), "hooks", {
|
|
885
875
|
cursorField: "hook_id",
|
|
886
876
|
pageSize: 100
|
|
877
|
+
}) : [],
|
|
878
|
+
emailProvider: n.emailProvider ? await e.emailProviders.get(t) ?? null : null,
|
|
879
|
+
branding: n.branding ? await e.branding.get(t) ?? null : null,
|
|
880
|
+
promptSettings: n.promptSettings ? await e.promptSettings.get(t) ?? null : null
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
async function _e(e, t, n, r, i, o) {
|
|
884
|
+
if (r.connections) for (let r of e.connections) {
|
|
885
|
+
let e = r.id;
|
|
886
|
+
e && await X(o.connections, `connection ${e}`, i, async () => {
|
|
887
|
+
let i = a.parse(r);
|
|
888
|
+
await t.connections.get(n, e) ? await t.connections.update(n, e, i) : await t.connections.create(n, i), o.connections.upserted += 1;
|
|
887
889
|
});
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
890
|
+
}
|
|
891
|
+
if (r.resourceServers) for (let r of e.resourceServers) !r.is_system || !r.id || await X(o.resourceServers, `resource_server ${r.id}`, i, async () => {
|
|
892
|
+
let e = h.parse(r);
|
|
893
|
+
await t.resourceServers.get(n, r.id) ? await t.resourceServers.update(n, r.id, e) : await t.resourceServers.create(n, e), o.resourceServers.upserted += 1;
|
|
894
|
+
});
|
|
895
|
+
if (r.hooks) for (let r of e.hooks) !he(r) || !r.hook_id || await X(o.hooks, `hook ${r.hook_id}`, i, async () => {
|
|
896
|
+
let e = d.parse(r);
|
|
897
|
+
await t.hooks.get(n, r.hook_id) ? await t.hooks.update(n, r.hook_id, e) : await t.hooks.create(n, e), o.hooks.upserted += 1;
|
|
898
|
+
});
|
|
899
|
+
r.emailProvider && e.emailProvider && await X(o.emailProvider, "email_provider", i, async () => {
|
|
900
|
+
let r = e.emailProvider;
|
|
901
|
+
await t.emailProviders.get(n) ? await t.emailProviders.update(n, r) : await t.emailProviders.create(n, r), o.emailProvider.upserted += 1;
|
|
902
|
+
}), r.branding && e.branding && await X(o.branding, "branding", i, async () => {
|
|
903
|
+
await t.branding.set(n, e.branding), o.branding.upserted += 1;
|
|
904
|
+
}), r.promptSettings && e.promptSettings && await X(o.promptSettings, "prompt_settings", i, async () => {
|
|
905
|
+
await t.promptSettings.set(n, e.promptSettings), o.promptSettings.upserted += 1;
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
async function Z(e, t) {
|
|
909
|
+
let { controlPlaneTenantId: n, getControlPlaneAdapters: r, getAdapters: i, entities: a, continueOnError: o = !1 } = e, s = J(a), c = await ge(await r(), n, s), l = await i(t), u = me(t);
|
|
910
|
+
return await _e(c, l, n, s, o, u), u;
|
|
911
|
+
}
|
|
912
|
+
//#endregion
|
|
913
|
+
//#region src/rollout/payload.ts
|
|
914
|
+
function ve(e) {
|
|
915
|
+
let { pkcs7: t, tenant_id: n, ...r } = e;
|
|
916
|
+
return r;
|
|
917
|
+
}
|
|
918
|
+
async function ye(e, t, n = {}, r) {
|
|
919
|
+
let i = J(n), a = n.signingKeys ?? !0, o = n.tenants ?? !0, s = await ge(e, t, i), c = a ? (await p(e.keys)).map(ve) : [], l = o ? await be(e, t, r) : [];
|
|
920
|
+
return {
|
|
921
|
+
connections: s.connections,
|
|
922
|
+
resourceServers: s.resourceServers.filter((e) => e.is_system),
|
|
923
|
+
hooks: s.hooks.filter(he),
|
|
924
|
+
emailProvider: s.emailProvider,
|
|
925
|
+
branding: s.branding,
|
|
926
|
+
promptSettings: s.promptSettings,
|
|
927
|
+
signingKeys: c,
|
|
928
|
+
tenants: l
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
async function be(e, t, n) {
|
|
932
|
+
let r = n && n !== t ? [t, n] : [t], i = [];
|
|
933
|
+
for (let t of r) {
|
|
934
|
+
let n = await e.tenants.get(t);
|
|
935
|
+
i.push({
|
|
936
|
+
id: t,
|
|
937
|
+
friendly_name: n?.friendly_name || t
|
|
891
938
|
});
|
|
892
939
|
}
|
|
893
|
-
return
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
let e =
|
|
901
|
-
e
|
|
902
|
-
})
|
|
940
|
+
return i;
|
|
941
|
+
}
|
|
942
|
+
async function xe(e, t, n) {
|
|
943
|
+
let r = Y();
|
|
944
|
+
if (e.length === 0) return r;
|
|
945
|
+
let i = await p(t.keys), a = new Set(i.map((e) => e.kid));
|
|
946
|
+
for (let i of e) await X(r, `signing_key ${i.kid}`, n, async () => {
|
|
947
|
+
let e = ve(i);
|
|
948
|
+
a.has(e.kid) || (await t.keys.create(e), a.add(e.kid), r.upserted += 1);
|
|
949
|
+
});
|
|
950
|
+
return r;
|
|
951
|
+
}
|
|
952
|
+
async function Se(e, t, n) {
|
|
953
|
+
let r = Y();
|
|
954
|
+
for (let i of e) await X(r, `tenant ${i.id}`, n, async () => {
|
|
955
|
+
await t.tenants.get(i.id) || (await t.tenants.create({
|
|
956
|
+
id: i.id,
|
|
957
|
+
friendly_name: i.friendly_name
|
|
958
|
+
}), r.upserted += 1);
|
|
959
|
+
});
|
|
960
|
+
return r;
|
|
961
|
+
}
|
|
962
|
+
async function Ce(e, t, n, r = {}) {
|
|
963
|
+
let a = r.continueOnError ?? !1, o = J(r.entities), s = r.entities?.signingKeys ?? !0, c = r.entities?.tenants ?? !0, u = {
|
|
964
|
+
connections: e.connections,
|
|
965
|
+
resourceServers: e.resourceServers,
|
|
966
|
+
hooks: e.hooks,
|
|
967
|
+
emailProvider: e.emailProvider ? l.parse(e.emailProvider) : null,
|
|
968
|
+
branding: e.branding ? i.parse(e.branding) : null,
|
|
969
|
+
promptSettings: e.promptSettings ? m.parse(e.promptSettings) : null
|
|
970
|
+
}, d = c ? await Se(e.tenants ?? [], t, a) : Y(), f = me(n);
|
|
971
|
+
await _e(u, t, n, o, a, f);
|
|
972
|
+
let p = s ? await xe(e.signingKeys, t, a) : Y();
|
|
973
|
+
return {
|
|
974
|
+
...f,
|
|
975
|
+
signingKeys: p,
|
|
976
|
+
tenants: d
|
|
977
|
+
};
|
|
903
978
|
}
|
|
904
979
|
//#endregion
|
|
905
980
|
//#region src/rollout/index.ts
|
|
906
|
-
function
|
|
981
|
+
function we(e) {
|
|
907
982
|
return {
|
|
908
983
|
syncDefaults: (t) => Z(e, t),
|
|
909
984
|
syncDefaultsToTenants: async (t) => {
|
|
@@ -915,11 +990,11 @@ function ue(e) {
|
|
|
915
990
|
}
|
|
916
991
|
//#endregion
|
|
917
992
|
//#region src/plugin.ts
|
|
918
|
-
function
|
|
993
|
+
function Te(e) {
|
|
919
994
|
let t = Q(e);
|
|
920
995
|
return {
|
|
921
996
|
name: "multi-tenancy",
|
|
922
|
-
middleware:
|
|
997
|
+
middleware: q(e),
|
|
923
998
|
hooks: t,
|
|
924
999
|
routes: [{
|
|
925
1000
|
path: "/management",
|
|
@@ -933,7 +1008,7 @@ function de(e) {
|
|
|
933
1008
|
//#endregion
|
|
934
1009
|
//#region src/index.ts
|
|
935
1010
|
function Q(e) {
|
|
936
|
-
let t = e.accessControl ?
|
|
1011
|
+
let t = e.accessControl ? S(e.accessControl) : {}, n = e.databaseIsolation ? w(e.databaseIsolation) : {}, r = E(e);
|
|
937
1012
|
return {
|
|
938
1013
|
...t,
|
|
939
1014
|
...n,
|
|
@@ -944,17 +1019,17 @@ function $(t) {
|
|
|
944
1019
|
let n = new e(), r = Q(t);
|
|
945
1020
|
return n.route("/tenants", M(t, r)), n;
|
|
946
1021
|
}
|
|
947
|
-
function
|
|
1022
|
+
function Ee(e) {
|
|
948
1023
|
return {
|
|
949
1024
|
hooks: Q(e),
|
|
950
|
-
middleware:
|
|
1025
|
+
middleware: q(e),
|
|
951
1026
|
app: $(e),
|
|
952
1027
|
config: e,
|
|
953
|
-
wrapAdapters: (t, n) =>
|
|
1028
|
+
wrapAdapters: (t, n) => H(t, {
|
|
954
1029
|
controlPlaneTenantId: e.accessControl?.controlPlaneTenantId,
|
|
955
1030
|
controlPlaneClientId: n?.controlPlaneClientId
|
|
956
1031
|
})
|
|
957
1032
|
};
|
|
958
1033
|
}
|
|
959
1034
|
//#endregion
|
|
960
|
-
export {
|
|
1035
|
+
export { Ce as applyControlPlaneDefaultsPayload, ye as buildControlPlaneDefaultsPayload, S as createAccessControlHooks, W as createAccessControlMiddleware, U as createControlPlaneTenantMiddleware, w as createDatabaseHooks, K as createDatabaseMiddleware, we as createDirectRolloutAdapter, $ as createMultiTenancy, Q as createMultiTenancyHooks, q as createMultiTenancyMiddleware, Te as createMultiTenancyPlugin, N as createProtectSyncedMiddleware, E as createProvisioningHooks, B as createRuntimeFallbackAdapter, G as createSubdomainMiddleware, re as createSyncHooks, M as createTenantsOpenAPIRouter, pe as initMultiTenant, de as mergeClientWithFallback, Z as projectControlPlaneDefaults, Ee as setupMultiTenancy, C as validateTenantAccess, H as withRuntimeFallback, z as withSystemResourceServerInheritance };
|