@authhero/multi-tenancy 14.20.2 → 14.20.3
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 +289 -285
- package/dist/types/routes/tenants.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
var ne = Object.defineProperty;
|
|
2
2
|
var re = (e, t, n) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var E = (e, t, n) => re(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { MANAGEMENT_API_SCOPES as
|
|
6
|
-
import { OpenAPIHono as de, createRoute as
|
|
4
|
+
import { Hono as se } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as ae, 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 M, z as S } from "@hono/zod-openapi";
|
|
7
7
|
function fe(e) {
|
|
8
8
|
const { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
9
9
|
return {
|
|
10
|
-
async onTenantAccessValidation(r,
|
|
11
|
-
if (
|
|
10
|
+
async onTenantAccessValidation(r, s) {
|
|
11
|
+
if (s === t)
|
|
12
12
|
return !0;
|
|
13
13
|
if (n) {
|
|
14
|
-
const
|
|
15
|
-
return c ? c.toLowerCase() ===
|
|
14
|
+
const o = r.var.org_name, i = r.var.organization_id, c = o || i;
|
|
15
|
+
return c ? c.toLowerCase() === s.toLowerCase() : !1;
|
|
16
16
|
}
|
|
17
17
|
return !0;
|
|
18
18
|
}
|
|
@@ -21,8 +21,8 @@ function fe(e) {
|
|
|
21
21
|
function me(e, t, n, r) {
|
|
22
22
|
if (t === n)
|
|
23
23
|
return !0;
|
|
24
|
-
const
|
|
25
|
-
return
|
|
24
|
+
const s = r || e;
|
|
25
|
+
return s ? s.toLowerCase() === t.toLowerCase() : !1;
|
|
26
26
|
}
|
|
27
27
|
function ge(e) {
|
|
28
28
|
return {
|
|
@@ -51,11 +51,11 @@ function Z(e) {
|
|
|
51
51
|
} : n;
|
|
52
52
|
},
|
|
53
53
|
async afterCreate(t, n) {
|
|
54
|
-
const { accessControl: r, databaseIsolation:
|
|
55
|
-
r && t.ctx && await he(t, n, r),
|
|
54
|
+
const { accessControl: r, databaseIsolation: s } = e;
|
|
55
|
+
r && t.ctx && await he(t, n, r), s != null && s.onProvision && await s.onProvision(n.id);
|
|
56
56
|
},
|
|
57
57
|
async beforeDelete(t, n) {
|
|
58
|
-
const { accessControl: r, databaseIsolation:
|
|
58
|
+
const { accessControl: r, databaseIsolation: s } = e;
|
|
59
59
|
if (r)
|
|
60
60
|
try {
|
|
61
61
|
const i = (await t.adapters.organizations.list(
|
|
@@ -65,19 +65,19 @@ function Z(e) {
|
|
|
65
65
|
r.controlPlaneTenantId,
|
|
66
66
|
i.id
|
|
67
67
|
);
|
|
68
|
-
} catch (
|
|
68
|
+
} catch (o) {
|
|
69
69
|
console.warn(
|
|
70
70
|
`Failed to remove organization for tenant ${n}:`,
|
|
71
|
-
|
|
71
|
+
o
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
|
-
if (
|
|
74
|
+
if (s != null && s.onDeprovision)
|
|
75
75
|
try {
|
|
76
|
-
await
|
|
77
|
-
} catch (
|
|
76
|
+
await s.onDeprovision(n);
|
|
77
|
+
} catch (o) {
|
|
78
78
|
console.warn(
|
|
79
79
|
`Failed to deprovision database for tenant ${n}:`,
|
|
80
|
-
|
|
80
|
+
o
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -86,13 +86,13 @@ function Z(e) {
|
|
|
86
86
|
async function he(e, t, n) {
|
|
87
87
|
const {
|
|
88
88
|
controlPlaneTenantId: r,
|
|
89
|
-
defaultPermissions:
|
|
90
|
-
defaultRoles:
|
|
89
|
+
defaultPermissions: s,
|
|
90
|
+
defaultRoles: o,
|
|
91
91
|
issuer: i,
|
|
92
92
|
adminRoleName: c = "Tenant Admin",
|
|
93
|
-
adminRoleDescription:
|
|
94
|
-
addCreatorToOrganization:
|
|
95
|
-
} = n,
|
|
93
|
+
adminRoleDescription: l = "Full access to all tenant management operations",
|
|
94
|
+
addCreatorToOrganization: a = !0
|
|
95
|
+
} = n, u = await e.adapters.organizations.create(
|
|
96
96
|
r,
|
|
97
97
|
{
|
|
98
98
|
name: t.id,
|
|
@@ -104,8 +104,8 @@ async function he(e, t, n) {
|
|
|
104
104
|
e,
|
|
105
105
|
r,
|
|
106
106
|
c,
|
|
107
|
-
|
|
108
|
-
)),
|
|
107
|
+
l
|
|
108
|
+
)), a && e.ctx) {
|
|
109
109
|
const d = e.ctx.var.user;
|
|
110
110
|
if (d != null && d.sub && !await pe(
|
|
111
111
|
e,
|
|
@@ -115,25 +115,25 @@ async function he(e, t, n) {
|
|
|
115
115
|
try {
|
|
116
116
|
await e.adapters.userOrganizations.create(r, {
|
|
117
117
|
user_id: d.sub,
|
|
118
|
-
organization_id:
|
|
118
|
+
organization_id: u.id
|
|
119
119
|
}), g && await e.adapters.userRoles.create(
|
|
120
120
|
r,
|
|
121
121
|
d.sub,
|
|
122
122
|
g,
|
|
123
|
-
|
|
123
|
+
u.id
|
|
124
124
|
// organizationId
|
|
125
125
|
);
|
|
126
126
|
} catch (f) {
|
|
127
127
|
console.warn(
|
|
128
|
-
`Failed to add creator ${d.sub} to organization ${
|
|
128
|
+
`Failed to add creator ${d.sub} to organization ${u.id}:`,
|
|
129
129
|
f
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
`Would assign roles ${
|
|
135
|
-
),
|
|
136
|
-
`Would grant permissions ${
|
|
133
|
+
o && o.length > 0 && console.log(
|
|
134
|
+
`Would assign roles ${o.join(", ")} to organization ${u.id}`
|
|
135
|
+
), s && s.length > 0 && console.log(
|
|
136
|
+
`Would grant permissions ${s.join(", ")} to organization ${u.id}`
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
async function pe(e, t, n) {
|
|
@@ -144,10 +144,10 @@ async function pe(e, t, n) {
|
|
|
144
144
|
""
|
|
145
145
|
// Empty string for global roles
|
|
146
146
|
);
|
|
147
|
-
for (const
|
|
147
|
+
for (const s of r)
|
|
148
148
|
if ((await e.adapters.rolePermissions.list(
|
|
149
149
|
t,
|
|
150
|
-
|
|
150
|
+
s.id,
|
|
151
151
|
{ per_page: 1e3 }
|
|
152
152
|
)).some(
|
|
153
153
|
(c) => c.permission_name === "admin:organizations"
|
|
@@ -156,64 +156,64 @@ async function pe(e, t, n) {
|
|
|
156
156
|
return !1;
|
|
157
157
|
}
|
|
158
158
|
async function ye(e, t, n, r) {
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
return
|
|
159
|
+
const o = (await e.adapters.roles.list(t, {})).roles.find((a) => a.name === n);
|
|
160
|
+
if (o)
|
|
161
|
+
return o.id;
|
|
162
162
|
const i = await e.adapters.roles.create(t, {
|
|
163
163
|
name: n,
|
|
164
164
|
description: r
|
|
165
|
-
}), c = Y,
|
|
165
|
+
}), c = Y, l = ae.map((a) => ({
|
|
166
166
|
role_id: i.id,
|
|
167
167
|
resource_server_identifier: c,
|
|
168
|
-
permission_name:
|
|
168
|
+
permission_name: a.value
|
|
169
169
|
}));
|
|
170
170
|
return await e.adapters.rolePermissions.assign(
|
|
171
171
|
t,
|
|
172
172
|
i.id,
|
|
173
|
-
|
|
173
|
+
l
|
|
174
174
|
), i.id;
|
|
175
175
|
}
|
|
176
176
|
function H(e, t, n = () => !0) {
|
|
177
|
-
const { controlPlaneTenantId: r, getChildTenantIds:
|
|
178
|
-
async function c(
|
|
179
|
-
return (await t(
|
|
177
|
+
const { controlPlaneTenantId: r, getChildTenantIds: s, getAdapters: o } = e, i = /* @__PURE__ */ new Map();
|
|
178
|
+
async function c(u, g, d) {
|
|
179
|
+
return (await t(u).list(g, {
|
|
180
180
|
q: `name:${d}`,
|
|
181
181
|
per_page: 1
|
|
182
182
|
}))[0] ?? null;
|
|
183
183
|
}
|
|
184
|
-
async function u
|
|
185
|
-
const g = await
|
|
184
|
+
async function l(u) {
|
|
185
|
+
const g = await s(), d = t(await o(r));
|
|
186
186
|
await Promise.all(
|
|
187
187
|
g.map(async (m) => {
|
|
188
188
|
try {
|
|
189
|
-
const f = await
|
|
190
|
-
...d.transform(
|
|
189
|
+
const f = await o(m), w = t(f), y = {
|
|
190
|
+
...d.transform(u),
|
|
191
191
|
is_system: !0
|
|
192
|
-
}, _ = await c(f, m,
|
|
193
|
-
if (_ &&
|
|
192
|
+
}, _ = await c(f, m, u.name), P = _ ? w.getId(_) : void 0;
|
|
193
|
+
if (_ && P) {
|
|
194
194
|
const I = w.preserveOnUpdate ? w.preserveOnUpdate(_, y) : y;
|
|
195
|
-
await w.update(m,
|
|
195
|
+
await w.update(m, P, I);
|
|
196
196
|
} else
|
|
197
197
|
await w.create(m, y);
|
|
198
198
|
} catch (f) {
|
|
199
199
|
console.error(
|
|
200
|
-
`Failed to sync ${d.listKey} "${
|
|
200
|
+
`Failed to sync ${d.listKey} "${u.name}" to tenant "${m}":`,
|
|
201
201
|
f
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
})
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
|
-
async function
|
|
208
|
-
const g = await
|
|
207
|
+
async function a(u) {
|
|
208
|
+
const g = await s();
|
|
209
209
|
await Promise.all(
|
|
210
210
|
g.map(async (d) => {
|
|
211
211
|
try {
|
|
212
|
-
const m = await
|
|
212
|
+
const m = await o(d), f = t(m), w = await c(m, d, u), T = w ? f.getId(w) : void 0;
|
|
213
213
|
w && T && await f.remove(d, T);
|
|
214
214
|
} catch (m) {
|
|
215
215
|
console.error(
|
|
216
|
-
`Failed to delete entity "${
|
|
216
|
+
`Failed to delete entity "${u}" from tenant "${d}":`,
|
|
217
217
|
m
|
|
218
218
|
);
|
|
219
219
|
}
|
|
@@ -221,39 +221,39 @@ function H(e, t, n = () => !0) {
|
|
|
221
221
|
);
|
|
222
222
|
}
|
|
223
223
|
return {
|
|
224
|
-
afterCreate: async (
|
|
225
|
-
|
|
224
|
+
afterCreate: async (u, g) => {
|
|
225
|
+
u.tenantId === r && n(g) && await l(g);
|
|
226
226
|
},
|
|
227
|
-
afterUpdate: async (
|
|
228
|
-
|
|
227
|
+
afterUpdate: async (u, g, d) => {
|
|
228
|
+
u.tenantId === r && n(d) && await l(d);
|
|
229
229
|
},
|
|
230
|
-
beforeDelete: async (
|
|
231
|
-
if (
|
|
232
|
-
const m = await t(
|
|
230
|
+
beforeDelete: async (u, g) => {
|
|
231
|
+
if (u.tenantId !== r) return;
|
|
232
|
+
const m = await t(u.adapters).get(u.tenantId, g);
|
|
233
233
|
m && n(m) && i.set(g, m);
|
|
234
234
|
},
|
|
235
|
-
afterDelete: async (
|
|
236
|
-
if (
|
|
235
|
+
afterDelete: async (u, g) => {
|
|
236
|
+
if (u.tenantId !== r) return;
|
|
237
237
|
const d = i.get(g);
|
|
238
|
-
d && (i.delete(g), await
|
|
238
|
+
d && (i.delete(g), await a(d.name));
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
242
|
function W(e, t, n = () => !0) {
|
|
243
|
-
const { controlPlaneTenantId: r, getControlPlaneAdapters:
|
|
243
|
+
const { controlPlaneTenantId: r, getControlPlaneAdapters: s, getAdapters: o } = e;
|
|
244
244
|
return {
|
|
245
245
|
async afterCreate(i, c) {
|
|
246
246
|
if (c.id !== r)
|
|
247
247
|
try {
|
|
248
|
-
const
|
|
249
|
-
(m) =>
|
|
250
|
-
|
|
248
|
+
const l = await s(), a = await o(c.id), u = t(l), g = t(a), d = await D(
|
|
249
|
+
(m) => u.listPaginated(r, m),
|
|
250
|
+
u.listKey,
|
|
251
251
|
{ cursorField: "id", pageSize: 100 }
|
|
252
252
|
);
|
|
253
253
|
await Promise.all(
|
|
254
254
|
d.filter((m) => n(m)).map(async (m) => {
|
|
255
255
|
try {
|
|
256
|
-
const f =
|
|
256
|
+
const f = u.transform(m);
|
|
257
257
|
await g.create(c.id, {
|
|
258
258
|
...f,
|
|
259
259
|
is_system: !0
|
|
@@ -266,10 +266,10 @@ function W(e, t, n = () => !0) {
|
|
|
266
266
|
}
|
|
267
267
|
})
|
|
268
268
|
);
|
|
269
|
-
} catch (
|
|
269
|
+
} catch (l) {
|
|
270
270
|
console.error(
|
|
271
271
|
`Failed to sync entities to new tenant "${c.id}":`,
|
|
272
|
-
|
|
272
|
+
l
|
|
273
273
|
);
|
|
274
274
|
}
|
|
275
275
|
}
|
|
@@ -313,25 +313,25 @@ function Q(e) {
|
|
|
313
313
|
return ((t = e.metadata) == null ? void 0 : t.sync) !== !1;
|
|
314
314
|
}
|
|
315
315
|
function ve(e) {
|
|
316
|
-
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0,
|
|
316
|
+
const { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, s = t.roles ?? !0, o = (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
|
-
|
|
320
|
-
) : void 0,
|
|
319
|
+
o
|
|
320
|
+
) : void 0, l = s ? H(e, K, i) : void 0, a = r ? W(
|
|
321
321
|
e,
|
|
322
322
|
L,
|
|
323
|
-
|
|
324
|
-
) : void 0,
|
|
323
|
+
o
|
|
324
|
+
) : void 0, u = s ? W(
|
|
325
325
|
e,
|
|
326
326
|
K,
|
|
327
327
|
i
|
|
328
|
-
) : void 0, g =
|
|
328
|
+
) : void 0, g = s ? {
|
|
329
329
|
async afterCreate(f, w) {
|
|
330
330
|
var T;
|
|
331
331
|
if (w.id !== e.controlPlaneTenantId) {
|
|
332
|
-
await ((T =
|
|
332
|
+
await ((T = u == null ? void 0 : u.afterCreate) == null ? void 0 : T.call(u, f, w));
|
|
333
333
|
try {
|
|
334
|
-
const y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id),
|
|
334
|
+
const y = await e.getControlPlaneAdapters(), _ = await e.getAdapters(w.id), P = await D(
|
|
335
335
|
(h) => y.roles.list(
|
|
336
336
|
e.controlPlaneTenantId,
|
|
337
337
|
h
|
|
@@ -339,7 +339,7 @@ function ve(e) {
|
|
|
339
339
|
"roles",
|
|
340
340
|
{ cursorField: "id", pageSize: 100 }
|
|
341
341
|
), I = /* @__PURE__ */ new Map();
|
|
342
|
-
for (const h of
|
|
342
|
+
for (const h of P.filter(
|
|
343
343
|
(C) => {
|
|
344
344
|
var p;
|
|
345
345
|
return ((p = n.roles) == null ? void 0 : p.call(n, C)) ?? !0;
|
|
@@ -352,7 +352,7 @@ function ve(e) {
|
|
|
352
352
|
);
|
|
353
353
|
C && I.set(h.name, C.id);
|
|
354
354
|
}
|
|
355
|
-
for (const h of
|
|
355
|
+
for (const h of P.filter(
|
|
356
356
|
(C) => {
|
|
357
357
|
var p;
|
|
358
358
|
return ((p = n.roles) == null ? void 0 : p.call(n, C)) ?? !0;
|
|
@@ -400,20 +400,20 @@ function ve(e) {
|
|
|
400
400
|
return {
|
|
401
401
|
entityHooks: {
|
|
402
402
|
resourceServers: c,
|
|
403
|
-
roles:
|
|
403
|
+
roles: l
|
|
404
404
|
},
|
|
405
405
|
tenantHooks: {
|
|
406
406
|
async afterCreate(f, w) {
|
|
407
407
|
const T = [
|
|
408
|
-
|
|
409
|
-
(g == null ? void 0 : g.afterCreate) ?? (
|
|
408
|
+
a == null ? void 0 : a.afterCreate,
|
|
409
|
+
(g == null ? void 0 : g.afterCreate) ?? (u == null ? void 0 : u.afterCreate)
|
|
410
410
|
], y = [];
|
|
411
411
|
for (const _ of T)
|
|
412
412
|
if (_)
|
|
413
413
|
try {
|
|
414
414
|
await _(f, w);
|
|
415
|
-
} catch (
|
|
416
|
-
y.push(
|
|
415
|
+
} catch (P) {
|
|
416
|
+
y.push(P instanceof Error ? P : new Error(String(P)));
|
|
417
417
|
}
|
|
418
418
|
if (y.length === 1) throw y[0];
|
|
419
419
|
if (y.length > 1)
|
|
@@ -425,7 +425,7 @@ function ve(e) {
|
|
|
425
425
|
}
|
|
426
426
|
};
|
|
427
427
|
}
|
|
428
|
-
var
|
|
428
|
+
var b = 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.
|
|
@@ -454,7 +454,7 @@ var P = class extends Error {
|
|
|
454
454
|
function N(e, t) {
|
|
455
455
|
const n = new de();
|
|
456
456
|
return n.openapi(
|
|
457
|
-
|
|
457
|
+
M({
|
|
458
458
|
tags: ["tenants"],
|
|
459
459
|
method: "get",
|
|
460
460
|
path: "/",
|
|
@@ -463,18 +463,18 @@ function N(e, t) {
|
|
|
463
463
|
},
|
|
464
464
|
security: [
|
|
465
465
|
{
|
|
466
|
-
Bearer: [
|
|
466
|
+
Bearer: []
|
|
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: S.object({
|
|
474
|
+
tenants: S.array(O),
|
|
475
|
+
start: S.number().optional(),
|
|
476
|
+
limit: S.number().optional(),
|
|
477
|
+
length: S.number().optional()
|
|
478
478
|
})
|
|
479
479
|
}
|
|
480
480
|
},
|
|
@@ -483,14 +483,14 @@ function N(e, t) {
|
|
|
483
483
|
}
|
|
484
484
|
}),
|
|
485
485
|
async (r) => {
|
|
486
|
-
var w, T, y, _,
|
|
487
|
-
const
|
|
488
|
-
if (!!!((
|
|
486
|
+
var w, T, y, _, P, I;
|
|
487
|
+
const s = r.req.valid("query"), { page: o, per_page: i, include_totals: c, q: l } = s, a = r.var.user, u = (a == null ? void 0 : a.permissions) || [];
|
|
488
|
+
if (!!!((a == null ? void 0 : a.org_id) ?? r.var.organization_id) && u.includes("admin:organizations")) {
|
|
489
489
|
const h = await r.env.data.tenants.list({
|
|
490
|
-
page:
|
|
490
|
+
page: o,
|
|
491
491
|
per_page: i,
|
|
492
492
|
include_totals: c,
|
|
493
|
-
q:
|
|
493
|
+
q: l
|
|
494
494
|
});
|
|
495
495
|
return c ? r.json({
|
|
496
496
|
tenants: h.tenants,
|
|
@@ -500,15 +500,19 @@ function N(e, t) {
|
|
|
500
500
|
}) : r.json({ tenants: h.tenants });
|
|
501
501
|
}
|
|
502
502
|
const m = ((y = e.accessControl) == null ? void 0 : y.controlPlaneTenantId) ?? ((_ = r.env.data.multiTenancyConfig) == null ? void 0 : _.controlPlaneTenantId);
|
|
503
|
-
if (m && (
|
|
503
|
+
if (m && !(a != null && a.sub))
|
|
504
|
+
throw new b(403, {
|
|
505
|
+
message: "Access denied: token has no subject"
|
|
506
|
+
});
|
|
507
|
+
if (m && (a != null && a.sub)) {
|
|
504
508
|
const C = (await D(
|
|
505
|
-
(
|
|
509
|
+
(k) => r.env.data.userOrganizations.listUserOrganizations(
|
|
506
510
|
m,
|
|
507
|
-
|
|
508
|
-
|
|
511
|
+
a.sub,
|
|
512
|
+
k
|
|
509
513
|
),
|
|
510
514
|
"organizations"
|
|
511
|
-
)).map((
|
|
515
|
+
)).map((k) => k.name);
|
|
512
516
|
if (C.length === 0)
|
|
513
517
|
return c ? r.json({
|
|
514
518
|
tenants: [],
|
|
@@ -516,15 +520,15 @@ function N(e, t) {
|
|
|
516
520
|
limit: i ?? 50,
|
|
517
521
|
length: 0
|
|
518
522
|
}) : r.json({ tenants: [] });
|
|
519
|
-
const p = C.length, F =
|
|
520
|
-
if (
|
|
523
|
+
const p = C.length, F = o ?? 0, $ = i ?? 50, R = F * $, A = C.slice(R, R + $);
|
|
524
|
+
if (A.length === 0)
|
|
521
525
|
return c ? r.json({
|
|
522
526
|
tenants: [],
|
|
523
527
|
start: R,
|
|
524
528
|
limit: $,
|
|
525
529
|
length: p
|
|
526
530
|
}) : r.json({ tenants: [] });
|
|
527
|
-
const v =
|
|
531
|
+
const v = A.map((k) => `id:${k}`).join(" OR "), j = l ? `(${v}) AND (${l})` : v, z = await r.env.data.tenants.list({
|
|
528
532
|
q: j,
|
|
529
533
|
per_page: $,
|
|
530
534
|
include_totals: !1
|
|
@@ -538,20 +542,20 @@ function N(e, t) {
|
|
|
538
542
|
}) : r.json({ tenants: z.tenants });
|
|
539
543
|
}
|
|
540
544
|
const f = await r.env.data.tenants.list({
|
|
541
|
-
page:
|
|
545
|
+
page: o,
|
|
542
546
|
per_page: i,
|
|
543
547
|
include_totals: c,
|
|
544
|
-
q:
|
|
548
|
+
q: l
|
|
545
549
|
});
|
|
546
550
|
return c ? r.json({
|
|
547
551
|
tenants: f.tenants,
|
|
548
|
-
start: ((
|
|
552
|
+
start: ((P = f.totals) == null ? void 0 : P.start) ?? 0,
|
|
549
553
|
limit: ((I = f.totals) == null ? void 0 : I.limit) ?? i,
|
|
550
554
|
length: f.tenants.length
|
|
551
555
|
}) : r.json({ tenants: f.tenants });
|
|
552
556
|
}
|
|
553
557
|
), n.openapi(
|
|
554
|
-
|
|
558
|
+
M({
|
|
555
559
|
tags: ["tenants"],
|
|
556
560
|
method: "post",
|
|
557
561
|
path: "/",
|
|
@@ -587,29 +591,29 @@ function N(e, t) {
|
|
|
587
591
|
}
|
|
588
592
|
}),
|
|
589
593
|
async (r) => {
|
|
590
|
-
var
|
|
591
|
-
const
|
|
592
|
-
if (!(
|
|
593
|
-
throw new
|
|
594
|
+
var l, a;
|
|
595
|
+
const s = r.var.user;
|
|
596
|
+
if (!(s != null && s.sub))
|
|
597
|
+
throw new b(401, {
|
|
594
598
|
message: "Authentication required to create tenants"
|
|
595
599
|
});
|
|
596
|
-
let
|
|
600
|
+
let o = r.req.valid("json");
|
|
597
601
|
const i = {
|
|
598
602
|
adapters: r.env.data,
|
|
599
603
|
ctx: r
|
|
600
604
|
};
|
|
601
|
-
(
|
|
602
|
-
const c = await r.env.data.tenants.create(
|
|
603
|
-
return (
|
|
605
|
+
(l = t.tenants) != null && l.beforeCreate && (o = await t.tenants.beforeCreate(i, o));
|
|
606
|
+
const c = await r.env.data.tenants.create(o);
|
|
607
|
+
return (a = t.tenants) != null && a.afterCreate && await t.tenants.afterCreate(i, c), r.json(c, 201);
|
|
604
608
|
}
|
|
605
609
|
), n.openapi(
|
|
606
|
-
|
|
610
|
+
M({
|
|
607
611
|
tags: ["tenants"],
|
|
608
612
|
method: "delete",
|
|
609
613
|
path: "/{id}",
|
|
610
614
|
request: {
|
|
611
|
-
params:
|
|
612
|
-
id:
|
|
615
|
+
params: S.object({
|
|
616
|
+
id: S.string()
|
|
613
617
|
})
|
|
614
618
|
},
|
|
615
619
|
security: [
|
|
@@ -630,48 +634,48 @@ function N(e, t) {
|
|
|
630
634
|
}
|
|
631
635
|
}),
|
|
632
636
|
async (r) => {
|
|
633
|
-
var
|
|
634
|
-
const { id:
|
|
635
|
-
if (
|
|
637
|
+
var l, a, u, g;
|
|
638
|
+
const { id: s } = r.req.valid("param"), o = ((l = e.accessControl) == null ? void 0 : l.controlPlaneTenantId) ?? ((a = r.env.data.multiTenancyConfig) == null ? void 0 : a.controlPlaneTenantId);
|
|
639
|
+
if (o) {
|
|
636
640
|
const d = r.var.user;
|
|
637
641
|
if (!(d != null && d.sub))
|
|
638
|
-
throw new
|
|
642
|
+
throw new b(401, {
|
|
639
643
|
message: "Authentication required"
|
|
640
644
|
});
|
|
641
|
-
if (
|
|
642
|
-
throw new
|
|
645
|
+
if (s === o)
|
|
646
|
+
throw new b(403, {
|
|
643
647
|
message: "Cannot delete the control plane"
|
|
644
648
|
});
|
|
645
649
|
if (!(await D(
|
|
646
650
|
(w) => r.env.data.userOrganizations.listUserOrganizations(
|
|
647
|
-
|
|
651
|
+
o,
|
|
648
652
|
d.sub,
|
|
649
653
|
w
|
|
650
654
|
),
|
|
651
655
|
"organizations"
|
|
652
|
-
)).some((w) => w.name ===
|
|
653
|
-
throw new
|
|
656
|
+
)).some((w) => w.name === s))
|
|
657
|
+
throw new b(403, {
|
|
654
658
|
message: "Access denied to this tenant"
|
|
655
659
|
});
|
|
656
660
|
}
|
|
657
|
-
if (!await r.env.data.tenants.get(
|
|
658
|
-
throw new
|
|
661
|
+
if (!await r.env.data.tenants.get(s))
|
|
662
|
+
throw new b(404, {
|
|
659
663
|
message: "Tenant not found"
|
|
660
664
|
});
|
|
661
665
|
const c = {
|
|
662
666
|
adapters: r.env.data,
|
|
663
667
|
ctx: r
|
|
664
668
|
};
|
|
665
|
-
return (
|
|
669
|
+
return (u = t.tenants) != null && u.beforeDelete && await t.tenants.beforeDelete(c, s), await r.env.data.tenants.remove(s), (g = t.tenants) != null && g.afterDelete && await t.tenants.afterDelete(c, s), r.body(null, 204);
|
|
666
670
|
}
|
|
667
671
|
), n.openapi(
|
|
668
|
-
|
|
672
|
+
M({
|
|
669
673
|
tags: ["tenants", "settings"],
|
|
670
674
|
method: "get",
|
|
671
675
|
path: "/settings",
|
|
672
676
|
request: {
|
|
673
|
-
headers:
|
|
674
|
-
"tenant-id":
|
|
677
|
+
headers: S.object({
|
|
678
|
+
"tenant-id": S.string().optional()
|
|
675
679
|
})
|
|
676
680
|
},
|
|
677
681
|
security: [
|
|
@@ -691,26 +695,26 @@ function N(e, t) {
|
|
|
691
695
|
}
|
|
692
696
|
}),
|
|
693
697
|
async (r) => {
|
|
694
|
-
const
|
|
695
|
-
if (!
|
|
696
|
-
throw new
|
|
698
|
+
const s = await r.env.data.tenants.get(r.var.tenant_id);
|
|
699
|
+
if (!s)
|
|
700
|
+
throw new b(404, {
|
|
697
701
|
message: "Tenant not found"
|
|
698
702
|
});
|
|
699
|
-
return r.json(
|
|
703
|
+
return r.json(s);
|
|
700
704
|
}
|
|
701
705
|
), n.openapi(
|
|
702
|
-
|
|
706
|
+
M({
|
|
703
707
|
tags: ["tenants", "settings"],
|
|
704
708
|
method: "patch",
|
|
705
709
|
path: "/settings",
|
|
706
710
|
request: {
|
|
707
|
-
headers:
|
|
708
|
-
"tenant-id":
|
|
711
|
+
headers: S.object({
|
|
712
|
+
"tenant-id": S.string().optional()
|
|
709
713
|
}),
|
|
710
714
|
body: {
|
|
711
715
|
content: {
|
|
712
716
|
"application/json": {
|
|
713
|
-
schema:
|
|
717
|
+
schema: S.object(G.shape).partial()
|
|
714
718
|
}
|
|
715
719
|
}
|
|
716
720
|
}
|
|
@@ -732,19 +736,19 @@ function N(e, t) {
|
|
|
732
736
|
}
|
|
733
737
|
}),
|
|
734
738
|
async (r) => {
|
|
735
|
-
const
|
|
739
|
+
const s = r.req.valid("json"), { id: o, ...i } = s, c = await r.env.data.tenants.get(r.var.tenant_id);
|
|
736
740
|
if (!c)
|
|
737
|
-
throw new
|
|
741
|
+
throw new b(404, {
|
|
738
742
|
message: "Tenant not found"
|
|
739
743
|
});
|
|
740
|
-
const
|
|
741
|
-
await r.env.data.tenants.update(r.var.tenant_id,
|
|
742
|
-
const
|
|
743
|
-
if (!
|
|
744
|
-
throw new
|
|
744
|
+
const l = ie(c, i);
|
|
745
|
+
await r.env.data.tenants.update(r.var.tenant_id, l);
|
|
746
|
+
const a = await r.env.data.tenants.get(r.var.tenant_id);
|
|
747
|
+
if (!a)
|
|
748
|
+
throw new b(500, {
|
|
745
749
|
message: "Failed to retrieve updated tenant"
|
|
746
750
|
});
|
|
747
|
-
return r.json(
|
|
751
|
+
return r.json(a);
|
|
748
752
|
}
|
|
749
753
|
), n;
|
|
750
754
|
}
|
|
@@ -758,9 +762,9 @@ function _e(e) {
|
|
|
758
762
|
{ pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
|
|
759
763
|
];
|
|
760
764
|
for (const { pattern: n, type: r } of t) {
|
|
761
|
-
const
|
|
762
|
-
if (
|
|
763
|
-
return { type: r, id:
|
|
765
|
+
const s = e.match(n);
|
|
766
|
+
if (s && s[1])
|
|
767
|
+
return { type: r, id: s[1] };
|
|
764
768
|
}
|
|
765
769
|
return null;
|
|
766
770
|
}
|
|
@@ -804,7 +808,7 @@ function be() {
|
|
|
804
808
|
if (!r)
|
|
805
809
|
return t();
|
|
806
810
|
if (await Ce(e.env.data, r, n))
|
|
807
|
-
throw new
|
|
811
|
+
throw new b(403, {
|
|
808
812
|
message: `This ${Te(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
809
813
|
});
|
|
810
814
|
return t();
|
|
@@ -812,7 +816,7 @@ function be() {
|
|
|
812
816
|
}
|
|
813
817
|
function B(e, t) {
|
|
814
818
|
const n = t.find(
|
|
815
|
-
(
|
|
819
|
+
(s) => s.strategy === e.strategy
|
|
816
820
|
);
|
|
817
821
|
if (!(n != null && n.options))
|
|
818
822
|
return e;
|
|
@@ -872,51 +876,51 @@ function x(e, t) {
|
|
|
872
876
|
return {
|
|
873
877
|
...e.resourceServers,
|
|
874
878
|
get: async (n, r) => {
|
|
875
|
-
const
|
|
879
|
+
const s = await e.resourceServers.get(
|
|
876
880
|
n,
|
|
877
881
|
r
|
|
878
882
|
);
|
|
879
|
-
if (!
|
|
880
|
-
return
|
|
881
|
-
const
|
|
883
|
+
if (!s || !t || n === t || !s.is_system)
|
|
884
|
+
return s;
|
|
885
|
+
const o = await e.resourceServers.get(
|
|
882
886
|
t,
|
|
883
887
|
r
|
|
884
888
|
);
|
|
885
889
|
return V(
|
|
886
|
-
|
|
887
|
-
|
|
890
|
+
s,
|
|
891
|
+
o
|
|
888
892
|
);
|
|
889
893
|
},
|
|
890
894
|
list: async (n, r) => {
|
|
891
|
-
const
|
|
895
|
+
const s = await e.resourceServers.list(n, r);
|
|
892
896
|
if (!t || n === t)
|
|
893
|
-
return
|
|
894
|
-
const
|
|
895
|
-
(
|
|
896
|
-
).map((
|
|
897
|
+
return s;
|
|
898
|
+
const o = t, i = s.resource_servers.filter(
|
|
899
|
+
(a) => !!(a.is_system && a.id)
|
|
900
|
+
).map((a) => a.id);
|
|
897
901
|
if (i.length === 0)
|
|
898
|
-
return
|
|
902
|
+
return s;
|
|
899
903
|
const c = /* @__PURE__ */ new Map();
|
|
900
904
|
await Promise.all(
|
|
901
|
-
i.map(async (
|
|
902
|
-
const
|
|
903
|
-
|
|
905
|
+
i.map(async (a) => {
|
|
906
|
+
const u = await e.resourceServers.get(o, a);
|
|
907
|
+
u && c.set(a, u);
|
|
904
908
|
})
|
|
905
909
|
);
|
|
906
|
-
const
|
|
907
|
-
(
|
|
908
|
-
|
|
909
|
-
c.get(
|
|
910
|
-
) :
|
|
910
|
+
const l = s.resource_servers.map(
|
|
911
|
+
(a) => a.is_system && a.id ? V(
|
|
912
|
+
a,
|
|
913
|
+
c.get(a.id) ?? null
|
|
914
|
+
) : a
|
|
911
915
|
);
|
|
912
916
|
return {
|
|
913
|
-
...
|
|
914
|
-
resource_servers:
|
|
917
|
+
...s,
|
|
918
|
+
resource_servers: l
|
|
915
919
|
};
|
|
916
920
|
}
|
|
917
921
|
};
|
|
918
922
|
}
|
|
919
|
-
function
|
|
923
|
+
function Ae(e, t) {
|
|
920
924
|
return {
|
|
921
925
|
...e,
|
|
922
926
|
resourceServers: x(
|
|
@@ -925,7 +929,7 @@ function Se(e, t) {
|
|
|
925
929
|
)
|
|
926
930
|
};
|
|
927
931
|
}
|
|
928
|
-
function
|
|
932
|
+
function Se(e, t) {
|
|
929
933
|
const { controlPlaneTenantId: n, controlPlaneClientId: r } = t;
|
|
930
934
|
return {
|
|
931
935
|
...e,
|
|
@@ -936,12 +940,12 @@ function Ae(e, t) {
|
|
|
936
940
|
},
|
|
937
941
|
connections: {
|
|
938
942
|
...e.connections,
|
|
939
|
-
get: async (
|
|
943
|
+
get: async (s, o) => {
|
|
940
944
|
const i = await e.connections.get(
|
|
941
|
-
|
|
942
|
-
|
|
945
|
+
s,
|
|
946
|
+
o
|
|
943
947
|
);
|
|
944
|
-
if (!i || !n ||
|
|
948
|
+
if (!i || !n || s === n)
|
|
945
949
|
return i;
|
|
946
950
|
const c = await e.connections.list(n);
|
|
947
951
|
return B(
|
|
@@ -949,35 +953,35 @@ function Ae(e, t) {
|
|
|
949
953
|
c.connections || []
|
|
950
954
|
);
|
|
951
955
|
},
|
|
952
|
-
list: async (
|
|
953
|
-
const i = await e.connections.list(
|
|
954
|
-
if (!n ||
|
|
956
|
+
list: async (s, o) => {
|
|
957
|
+
const i = await e.connections.list(s, o);
|
|
958
|
+
if (!n || s === n)
|
|
955
959
|
return i;
|
|
956
|
-
const c = await e.connections.list(n),
|
|
957
|
-
(
|
|
958
|
-
|
|
960
|
+
const c = await e.connections.list(n), l = i.connections.map(
|
|
961
|
+
(a) => B(
|
|
962
|
+
a,
|
|
959
963
|
c.connections || []
|
|
960
964
|
)
|
|
961
965
|
);
|
|
962
966
|
return {
|
|
963
967
|
...i,
|
|
964
|
-
connections:
|
|
968
|
+
connections: l
|
|
965
969
|
};
|
|
966
970
|
}
|
|
967
971
|
},
|
|
968
972
|
clientConnections: {
|
|
969
973
|
...e.clientConnections,
|
|
970
|
-
listByClient: async (
|
|
974
|
+
listByClient: async (s, o) => {
|
|
971
975
|
let i = await e.clientConnections.listByClient(
|
|
972
|
-
|
|
973
|
-
|
|
976
|
+
s,
|
|
977
|
+
o
|
|
974
978
|
);
|
|
975
|
-
if (i.length === 0 && (i = (await e.connections.list(
|
|
979
|
+
if (i.length === 0 && (i = (await e.connections.list(s)).connections || []), !n || s === n)
|
|
976
980
|
return i;
|
|
977
981
|
const c = await e.connections.list(n);
|
|
978
982
|
return i.map(
|
|
979
|
-
(
|
|
980
|
-
|
|
983
|
+
(l) => B(
|
|
984
|
+
l,
|
|
981
985
|
c.connections || []
|
|
982
986
|
)
|
|
983
987
|
);
|
|
@@ -985,11 +989,11 @@ function Ae(e, t) {
|
|
|
985
989
|
},
|
|
986
990
|
clients: {
|
|
987
991
|
...e.clients,
|
|
988
|
-
get: async (
|
|
989
|
-
const i = await e.clients.get(
|
|
992
|
+
get: async (s, o) => {
|
|
993
|
+
const i = await e.clients.get(s, o);
|
|
990
994
|
if (!i)
|
|
991
995
|
return null;
|
|
992
|
-
if (!n || !r ||
|
|
996
|
+
if (!n || !r || s === n && o === r)
|
|
993
997
|
return i;
|
|
994
998
|
const c = await e.clients.get(
|
|
995
999
|
n,
|
|
@@ -997,27 +1001,27 @@ function Ae(e, t) {
|
|
|
997
1001
|
);
|
|
998
1002
|
return J(i, c);
|
|
999
1003
|
},
|
|
1000
|
-
getByClientId: async (
|
|
1001
|
-
const
|
|
1002
|
-
if (!
|
|
1004
|
+
getByClientId: async (s) => {
|
|
1005
|
+
const o = await e.clients.getByClientId(s);
|
|
1006
|
+
if (!o)
|
|
1003
1007
|
return null;
|
|
1004
|
-
if (!n || !r ||
|
|
1005
|
-
return
|
|
1008
|
+
if (!n || !r || o.tenant_id === n && o.client_id === r)
|
|
1009
|
+
return o;
|
|
1006
1010
|
const i = await e.clients.get(
|
|
1007
1011
|
n,
|
|
1008
1012
|
r
|
|
1009
1013
|
);
|
|
1010
1014
|
return {
|
|
1011
|
-
...J(
|
|
1012
|
-
tenant_id:
|
|
1015
|
+
...J(o, i),
|
|
1016
|
+
tenant_id: o.tenant_id
|
|
1013
1017
|
};
|
|
1014
1018
|
}
|
|
1015
1019
|
},
|
|
1016
1020
|
emailProviders: {
|
|
1017
1021
|
...e.emailProviders,
|
|
1018
|
-
get: async (
|
|
1019
|
-
const
|
|
1020
|
-
return
|
|
1022
|
+
get: async (s) => {
|
|
1023
|
+
const o = await e.emailProviders.get(s);
|
|
1024
|
+
return o || (!n || s === n ? null : e.emailProviders.get(n));
|
|
1021
1025
|
}
|
|
1022
1026
|
},
|
|
1023
1027
|
resourceServers: x(
|
|
@@ -1039,9 +1043,9 @@ function Ie(e, t) {
|
|
|
1039
1043
|
return {
|
|
1040
1044
|
...e.hooks,
|
|
1041
1045
|
list: async (n, r) => {
|
|
1042
|
-
const
|
|
1046
|
+
const s = await e.hooks.list(n, r);
|
|
1043
1047
|
if (!t || n === t)
|
|
1044
|
-
return
|
|
1048
|
+
return s;
|
|
1045
1049
|
const i = ((await e.hooks.list(
|
|
1046
1050
|
t,
|
|
1047
1051
|
r
|
|
@@ -1049,28 +1053,28 @@ function Ie(e, t) {
|
|
|
1049
1053
|
X
|
|
1050
1054
|
);
|
|
1051
1055
|
if (i.length === 0)
|
|
1052
|
-
return
|
|
1053
|
-
const c = new Set((
|
|
1056
|
+
return s;
|
|
1057
|
+
const c = new Set((s.hooks || []).map((a) => a.hook_id)), l = i.filter((a) => !c.has(a.hook_id));
|
|
1054
1058
|
return {
|
|
1055
|
-
...
|
|
1056
|
-
hooks: [...
|
|
1057
|
-
length: typeof
|
|
1059
|
+
...s,
|
|
1060
|
+
hooks: [...s.hooks || [], ...l],
|
|
1061
|
+
length: typeof s.length == "number" ? s.length + l.length : s.length
|
|
1058
1062
|
};
|
|
1059
1063
|
},
|
|
1060
1064
|
get: async (n, r) => {
|
|
1061
|
-
const
|
|
1062
|
-
if (
|
|
1063
|
-
return
|
|
1064
|
-
const
|
|
1065
|
+
const s = await e.hooks.get(n, r);
|
|
1066
|
+
if (s || !t || n === t)
|
|
1067
|
+
return s;
|
|
1068
|
+
const o = await e.hooks.get(
|
|
1065
1069
|
t,
|
|
1066
1070
|
r
|
|
1067
1071
|
);
|
|
1068
|
-
return
|
|
1072
|
+
return o && X(o) ? o : null;
|
|
1069
1073
|
}
|
|
1070
1074
|
};
|
|
1071
1075
|
}
|
|
1072
1076
|
function ee(e, t) {
|
|
1073
|
-
return
|
|
1077
|
+
return Se(e, t);
|
|
1074
1078
|
}
|
|
1075
1079
|
function Re(e) {
|
|
1076
1080
|
return async (t, n) => {
|
|
@@ -1082,20 +1086,20 @@ function ze(e) {
|
|
|
1082
1086
|
return async (t, n) => {
|
|
1083
1087
|
if (!e.accessControl)
|
|
1084
1088
|
return n();
|
|
1085
|
-
const { controlPlaneTenantId: r } = e.accessControl,
|
|
1089
|
+
const { controlPlaneTenantId: r } = e.accessControl, s = t.var.org_name, o = t.var.organization_id, i = s || o;
|
|
1086
1090
|
let c = t.var.tenant_id;
|
|
1087
|
-
const
|
|
1088
|
-
if (!c && i &&
|
|
1089
|
-
throw new
|
|
1091
|
+
const l = t.var.user, u = (l != null && l.aud ? Array.isArray(l.aud) ? l.aud : [l.aud] : []).includes(Y);
|
|
1092
|
+
if (!c && i && u && (t.set("tenant_id", i), c = i), !c)
|
|
1093
|
+
throw new b(400, {
|
|
1090
1094
|
message: "Tenant ID not found in request"
|
|
1091
1095
|
});
|
|
1092
1096
|
if (!me(
|
|
1093
|
-
|
|
1097
|
+
o,
|
|
1094
1098
|
c,
|
|
1095
1099
|
r,
|
|
1096
|
-
|
|
1100
|
+
s
|
|
1097
1101
|
))
|
|
1098
|
-
throw new
|
|
1102
|
+
throw new b(403, {
|
|
1099
1103
|
message: `Access denied to tenant ${c}`
|
|
1100
1104
|
});
|
|
1101
1105
|
return n();
|
|
@@ -1107,33 +1111,33 @@ function $e(e) {
|
|
|
1107
1111
|
return n();
|
|
1108
1112
|
const {
|
|
1109
1113
|
baseDomain: r,
|
|
1110
|
-
reservedSubdomains:
|
|
1111
|
-
resolveSubdomain:
|
|
1114
|
+
reservedSubdomains: s = [],
|
|
1115
|
+
resolveSubdomain: o
|
|
1112
1116
|
} = e.subdomainRouting, i = t.req.header("x-forwarded-host") || t.req.header("host") || "";
|
|
1113
1117
|
let c = null;
|
|
1114
1118
|
if (i.endsWith(r)) {
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1119
|
+
const a = i.slice(0, -(r.length + 1));
|
|
1120
|
+
a && !a.includes(".") && (c = a);
|
|
1117
1121
|
}
|
|
1118
|
-
if (c &&
|
|
1122
|
+
if (c && s.includes(c) && (c = null), !c)
|
|
1119
1123
|
return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
1120
|
-
let
|
|
1121
|
-
if (
|
|
1122
|
-
|
|
1124
|
+
let l = null;
|
|
1125
|
+
if (o)
|
|
1126
|
+
l = await o(c);
|
|
1123
1127
|
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl)
|
|
1124
1128
|
try {
|
|
1125
|
-
const
|
|
1129
|
+
const a = await t.env.data.organizations.get(
|
|
1126
1130
|
e.accessControl.controlPlaneTenantId,
|
|
1127
1131
|
c
|
|
1128
1132
|
);
|
|
1129
|
-
|
|
1133
|
+
a && (l = a.id);
|
|
1130
1134
|
} catch {
|
|
1131
1135
|
}
|
|
1132
|
-
if (!
|
|
1133
|
-
throw new
|
|
1136
|
+
if (!l)
|
|
1137
|
+
throw new b(404, {
|
|
1134
1138
|
message: `Tenant not found for subdomain: ${c}`
|
|
1135
1139
|
});
|
|
1136
|
-
return t.set("tenant_id",
|
|
1140
|
+
return t.set("tenant_id", l), n();
|
|
1137
1141
|
};
|
|
1138
1142
|
}
|
|
1139
1143
|
function je(e) {
|
|
@@ -1142,17 +1146,17 @@ function je(e) {
|
|
|
1142
1146
|
return n();
|
|
1143
1147
|
const r = t.var.tenant_id;
|
|
1144
1148
|
if (!r)
|
|
1145
|
-
throw new
|
|
1149
|
+
throw new b(400, {
|
|
1146
1150
|
message: "Tenant ID not found in request"
|
|
1147
1151
|
});
|
|
1148
1152
|
try {
|
|
1149
|
-
const
|
|
1150
|
-
t.env.data =
|
|
1151
|
-
} catch (
|
|
1153
|
+
const s = await e.databaseIsolation.getAdapters(r);
|
|
1154
|
+
t.env.data = s;
|
|
1155
|
+
} catch (s) {
|
|
1152
1156
|
throw console.error(
|
|
1153
1157
|
`Failed to resolve database for tenant ${r}:`,
|
|
1154
|
-
|
|
1155
|
-
), new
|
|
1158
|
+
s
|
|
1159
|
+
), new b(500, {
|
|
1156
1160
|
message: "Failed to resolve tenant database"
|
|
1157
1161
|
});
|
|
1158
1162
|
}
|
|
@@ -1161,10 +1165,10 @@ function je(e) {
|
|
|
1161
1165
|
}
|
|
1162
1166
|
function te(e) {
|
|
1163
1167
|
const t = $e(e), n = ze(e), r = je(e);
|
|
1164
|
-
return async (
|
|
1165
|
-
}), await n(
|
|
1166
|
-
}), await r(
|
|
1167
|
-
}),
|
|
1168
|
+
return async (s, o) => (await t(s, async () => {
|
|
1169
|
+
}), await n(s, async () => {
|
|
1170
|
+
}), await r(s, async () => {
|
|
1171
|
+
}), o());
|
|
1168
1172
|
}
|
|
1169
1173
|
function qe(e) {
|
|
1170
1174
|
const {
|
|
@@ -1172,36 +1176,36 @@ function qe(e) {
|
|
|
1172
1176
|
controlPlane: n,
|
|
1173
1177
|
controlPlane: {
|
|
1174
1178
|
tenantId: r = "control_plane",
|
|
1175
|
-
clientId:
|
|
1179
|
+
clientId: s
|
|
1176
1180
|
} = {},
|
|
1177
|
-
sync:
|
|
1181
|
+
sync: o = { resourceServers: !0, roles: !0 },
|
|
1178
1182
|
defaultPermissions: i = ["tenant:admin"],
|
|
1179
1183
|
requireOrganizationMatch: c = !1,
|
|
1180
|
-
managementApiExtensions:
|
|
1181
|
-
entityHooks:
|
|
1182
|
-
getChildTenantIds:
|
|
1184
|
+
managementApiExtensions: l = [],
|
|
1185
|
+
entityHooks: a,
|
|
1186
|
+
getChildTenantIds: u,
|
|
1183
1187
|
getAdapters: g,
|
|
1184
1188
|
...d
|
|
1185
1189
|
} = e;
|
|
1186
1190
|
let m = t, f = t;
|
|
1187
1191
|
n && (m = ee(t, {
|
|
1188
1192
|
controlPlaneTenantId: r,
|
|
1189
|
-
controlPlaneClientId:
|
|
1193
|
+
controlPlaneClientId: s
|
|
1190
1194
|
}), f = {
|
|
1191
|
-
...
|
|
1195
|
+
...Ae(t, {
|
|
1192
1196
|
controlPlaneTenantId: r
|
|
1193
1197
|
}),
|
|
1194
1198
|
multiTenancyConfig: {
|
|
1195
1199
|
controlPlaneTenantId: r,
|
|
1196
|
-
controlPlaneClientId:
|
|
1200
|
+
controlPlaneClientId: s
|
|
1197
1201
|
}
|
|
1198
1202
|
});
|
|
1199
|
-
const w =
|
|
1200
|
-
resourceServers:
|
|
1201
|
-
roles:
|
|
1202
|
-
} : { resourceServers: !1, roles: !1 },
|
|
1203
|
+
const w = o !== !1, T = w ? {
|
|
1204
|
+
resourceServers: o.resourceServers ?? !0,
|
|
1205
|
+
roles: o.roles ?? !0
|
|
1206
|
+
} : { resourceServers: !1, roles: !1 }, P = {
|
|
1203
1207
|
controlPlaneTenantId: r,
|
|
1204
|
-
getChildTenantIds:
|
|
1208
|
+
getChildTenantIds: u ?? (async () => (await D(
|
|
1205
1209
|
(v) => m.tenants.list(v),
|
|
1206
1210
|
"tenants",
|
|
1207
1211
|
{ cursorField: "id", pageSize: 100 }
|
|
@@ -1209,15 +1213,15 @@ function qe(e) {
|
|
|
1209
1213
|
getAdapters: g ?? (async () => m),
|
|
1210
1214
|
getControlPlaneAdapters: async () => m,
|
|
1211
1215
|
sync: T
|
|
1212
|
-
}, { entityHooks: I, tenantHooks: h } = ve(
|
|
1216
|
+
}, { entityHooks: I, tenantHooks: h } = ve(P), C = {
|
|
1213
1217
|
resourceServers: [
|
|
1214
1218
|
I.resourceServers,
|
|
1215
|
-
...(
|
|
1219
|
+
...(a == null ? void 0 : a.resourceServers) ?? []
|
|
1216
1220
|
],
|
|
1217
|
-
roles: [I.roles, ...(
|
|
1218
|
-
connections: (
|
|
1219
|
-
tenants: (
|
|
1220
|
-
rolePermissions: (
|
|
1221
|
+
roles: [I.roles, ...(a == null ? void 0 : a.roles) ?? []],
|
|
1222
|
+
connections: (a == null ? void 0 : a.connections) ?? [],
|
|
1223
|
+
tenants: (a == null ? void 0 : a.tenants) ?? [],
|
|
1224
|
+
rolePermissions: (a == null ? void 0 : a.rolePermissions) ?? []
|
|
1221
1225
|
}, p = Z({
|
|
1222
1226
|
accessControl: {
|
|
1223
1227
|
controlPlaneTenantId: r,
|
|
@@ -1233,16 +1237,16 @@ function qe(e) {
|
|
|
1233
1237
|
}
|
|
1234
1238
|
},
|
|
1235
1239
|
{ tenants: {
|
|
1236
|
-
async beforeCreate(
|
|
1237
|
-
return p.beforeCreate && (v = await p.beforeCreate(
|
|
1240
|
+
async beforeCreate(A, v) {
|
|
1241
|
+
return p.beforeCreate && (v = await p.beforeCreate(A, v)), h.beforeCreate && (v = await h.beforeCreate(A, v)), v;
|
|
1238
1242
|
},
|
|
1239
|
-
async afterCreate(
|
|
1243
|
+
async afterCreate(A, v) {
|
|
1240
1244
|
var j, z;
|
|
1241
|
-
await ((j = p.afterCreate) == null ? void 0 : j.call(p,
|
|
1245
|
+
await ((j = p.afterCreate) == null ? void 0 : j.call(p, A, v)), await ((z = h.afterCreate) == null ? void 0 : z.call(h, A, v));
|
|
1242
1246
|
},
|
|
1243
|
-
async beforeDelete(
|
|
1247
|
+
async beforeDelete(A, v) {
|
|
1244
1248
|
var j, z;
|
|
1245
|
-
await ((j = p.beforeDelete) == null ? void 0 : j.call(p,
|
|
1249
|
+
await ((j = p.beforeDelete) == null ? void 0 : j.call(p, A, v)), await ((z = h.beforeDelete) == null ? void 0 : z.call(h, A, v));
|
|
1246
1250
|
}
|
|
1247
1251
|
} }
|
|
1248
1252
|
), { app: R } = ue({
|
|
@@ -1251,7 +1255,7 @@ function qe(e) {
|
|
|
1251
1255
|
...d,
|
|
1252
1256
|
entityHooks: C,
|
|
1253
1257
|
managementApiExtensions: [
|
|
1254
|
-
...
|
|
1258
|
+
...l,
|
|
1255
1259
|
{ path: "/tenants", router: $ }
|
|
1256
1260
|
]
|
|
1257
1261
|
});
|
|
@@ -1294,7 +1298,7 @@ function U(e) {
|
|
|
1294
1298
|
};
|
|
1295
1299
|
}
|
|
1296
1300
|
function Fe(e) {
|
|
1297
|
-
const t = new
|
|
1301
|
+
const t = new se(), n = U(e);
|
|
1298
1302
|
return t.route("/tenants", N(e, n)), t;
|
|
1299
1303
|
}
|
|
1300
1304
|
function Be(e) {
|
|
@@ -1332,7 +1336,7 @@ export {
|
|
|
1332
1336
|
Ee as createMultiTenancyPlugin,
|
|
1333
1337
|
be as createProtectSyncedMiddleware,
|
|
1334
1338
|
Z as createProvisioningHooks,
|
|
1335
|
-
|
|
1339
|
+
Se as createRuntimeFallbackAdapter,
|
|
1336
1340
|
$e as createSubdomainMiddleware,
|
|
1337
1341
|
ve as createSyncHooks,
|
|
1338
1342
|
N as createTenantsOpenAPIRouter,
|
|
@@ -1340,5 +1344,5 @@ export {
|
|
|
1340
1344
|
Be as setupMultiTenancy,
|
|
1341
1345
|
me as validateTenantAccess,
|
|
1342
1346
|
ee as withRuntimeFallback,
|
|
1343
|
-
|
|
1347
|
+
Ae as withSystemResourceServerInheritance
|
|
1344
1348
|
};
|