@authhero/multi-tenancy 13.20.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/multi-tenancy.cjs +1 -1
- package/dist/multi-tenancy.mjs +327 -321
- package/package.json +3 -3
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var O = (
|
|
4
|
-
import { Hono as
|
|
5
|
-
import {
|
|
6
|
-
import { OpenAPIHono as
|
|
7
|
-
import { auth0QuerySchema as
|
|
8
|
-
function
|
|
9
|
-
const { controlPlaneTenantId: e, requireOrganizationMatch:
|
|
1
|
+
var W = Object.defineProperty;
|
|
2
|
+
var Q = (t, e, n) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var O = (t, e, n) => Q(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { Hono as J } from "hono";
|
|
5
|
+
import { MANAGEMENT_API_SCOPES as X, MANAGEMENT_API_AUDIENCE as U, fetchAll as z, init as Y } from "authhero";
|
|
6
|
+
import { OpenAPIHono as Z, createRoute as R, z as I } from "@hono/zod-openapi";
|
|
7
|
+
import { auth0QuerySchema as x, tenantSchema as N, tenantInsertSchema as ee, connectionSchema as D, connectionOptionsSchema as F } from "@authhero/adapter-interfaces";
|
|
8
|
+
function te(t) {
|
|
9
|
+
const { controlPlaneTenantId: e, requireOrganizationMatch: n = !0 } = t;
|
|
10
10
|
return {
|
|
11
11
|
async onTenantAccessValidation(s, r) {
|
|
12
12
|
if (r === e)
|
|
13
13
|
return !0;
|
|
14
|
-
if (
|
|
14
|
+
if (n) {
|
|
15
15
|
const i = s.var.org_name, o = s.var.organization_id, a = i || o;
|
|
16
16
|
return a ? a.toLowerCase() === r.toLowerCase() : !1;
|
|
17
17
|
}
|
|
@@ -19,105 +19,108 @@ function ne(n) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
if (e ===
|
|
22
|
+
function ne(t, e, n, s) {
|
|
23
|
+
if (e === n)
|
|
24
24
|
return !0;
|
|
25
|
-
const r = s ||
|
|
25
|
+
const r = s || t;
|
|
26
26
|
return r ? r.toLowerCase() === e.toLowerCase() : !1;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function se(t) {
|
|
29
29
|
return {
|
|
30
30
|
async resolveDataAdapters(e) {
|
|
31
31
|
try {
|
|
32
|
-
return await
|
|
33
|
-
} catch (
|
|
32
|
+
return await t.getAdapters(e);
|
|
33
|
+
} catch (n) {
|
|
34
34
|
console.error(
|
|
35
35
|
`Failed to resolve data adapters for tenant ${e}:`,
|
|
36
|
-
|
|
36
|
+
n
|
|
37
37
|
);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
function ae(
|
|
43
|
+
function ae(t) {
|
|
44
|
+
return `urn:authhero:tenant:${t.toLowerCase()}`;
|
|
45
|
+
}
|
|
46
|
+
function re(t) {
|
|
44
47
|
return {
|
|
45
|
-
async beforeCreate(e,
|
|
46
|
-
return !
|
|
47
|
-
...
|
|
48
|
-
audience:
|
|
49
|
-
} :
|
|
48
|
+
async beforeCreate(e, n) {
|
|
49
|
+
return !n.audience && n.id ? {
|
|
50
|
+
...n,
|
|
51
|
+
audience: ae(n.id)
|
|
52
|
+
} : n;
|
|
50
53
|
},
|
|
51
|
-
async afterCreate(e,
|
|
52
|
-
const { accessControl: s, databaseIsolation: r } =
|
|
53
|
-
s && e.ctx && await oe(e,
|
|
54
|
+
async afterCreate(e, n) {
|
|
55
|
+
const { accessControl: s, databaseIsolation: r } = t;
|
|
56
|
+
s && e.ctx && await oe(e, n, s), r != null && r.onProvision && await r.onProvision(n.id);
|
|
54
57
|
},
|
|
55
|
-
async beforeDelete(e,
|
|
56
|
-
const { accessControl: s, databaseIsolation: r } =
|
|
58
|
+
async beforeDelete(e, n) {
|
|
59
|
+
const { accessControl: s, databaseIsolation: r } = t;
|
|
57
60
|
if (s)
|
|
58
61
|
try {
|
|
59
62
|
const o = (await e.adapters.organizations.list(
|
|
60
63
|
s.controlPlaneTenantId
|
|
61
|
-
)).organizations.find((a) => a.name ===
|
|
64
|
+
)).organizations.find((a) => a.name === n);
|
|
62
65
|
o && await e.adapters.organizations.remove(
|
|
63
66
|
s.controlPlaneTenantId,
|
|
64
67
|
o.id
|
|
65
68
|
);
|
|
66
69
|
} catch (i) {
|
|
67
70
|
console.warn(
|
|
68
|
-
`Failed to remove organization for tenant ${
|
|
71
|
+
`Failed to remove organization for tenant ${n}:`,
|
|
69
72
|
i
|
|
70
73
|
);
|
|
71
74
|
}
|
|
72
75
|
if (r != null && r.onDeprovision)
|
|
73
76
|
try {
|
|
74
|
-
await r.onDeprovision(
|
|
77
|
+
await r.onDeprovision(n);
|
|
75
78
|
} catch (i) {
|
|
76
79
|
console.warn(
|
|
77
|
-
`Failed to deprovision database for tenant ${
|
|
80
|
+
`Failed to deprovision database for tenant ${n}:`,
|
|
78
81
|
i
|
|
79
82
|
);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
};
|
|
83
86
|
}
|
|
84
|
-
async function oe(
|
|
87
|
+
async function oe(t, e, n) {
|
|
85
88
|
const {
|
|
86
89
|
controlPlaneTenantId: s,
|
|
87
90
|
defaultPermissions: r,
|
|
88
91
|
defaultRoles: i,
|
|
89
92
|
issuer: o,
|
|
90
93
|
adminRoleName: a = "Tenant Admin",
|
|
91
|
-
adminRoleDescription:
|
|
94
|
+
adminRoleDescription: u = "Full access to all tenant management operations",
|
|
92
95
|
addCreatorToOrganization: d = !0
|
|
93
|
-
} =
|
|
96
|
+
} = n, c = await t.adapters.organizations.create(
|
|
94
97
|
s,
|
|
95
98
|
{
|
|
96
99
|
name: e.id,
|
|
97
100
|
display_name: e.friendly_name || e.id
|
|
98
101
|
}
|
|
99
102
|
);
|
|
100
|
-
let
|
|
101
|
-
if (o && (
|
|
102
|
-
|
|
103
|
+
let f;
|
|
104
|
+
if (o && (f = await ce(
|
|
105
|
+
t,
|
|
103
106
|
s,
|
|
104
107
|
a,
|
|
105
|
-
|
|
106
|
-
)), d &&
|
|
107
|
-
const l =
|
|
108
|
+
u
|
|
109
|
+
)), d && t.ctx) {
|
|
110
|
+
const l = t.ctx.var.user;
|
|
108
111
|
if (l != null && l.sub && !await ie(
|
|
109
|
-
|
|
112
|
+
t,
|
|
110
113
|
s,
|
|
111
114
|
l.sub
|
|
112
115
|
))
|
|
113
116
|
try {
|
|
114
|
-
await
|
|
117
|
+
await t.adapters.userOrganizations.create(s, {
|
|
115
118
|
user_id: l.sub,
|
|
116
119
|
organization_id: c.id
|
|
117
|
-
}),
|
|
120
|
+
}), f && await t.adapters.userRoles.create(
|
|
118
121
|
s,
|
|
119
122
|
l.sub,
|
|
120
|
-
|
|
123
|
+
f,
|
|
121
124
|
c.id
|
|
122
125
|
// organizationId
|
|
123
126
|
);
|
|
@@ -134,16 +137,16 @@ async function oe(n, e, t) {
|
|
|
134
137
|
`Would grant permissions ${r.join(", ")} to organization ${c.id}`
|
|
135
138
|
);
|
|
136
139
|
}
|
|
137
|
-
async function ie(
|
|
138
|
-
const s = await
|
|
140
|
+
async function ie(t, e, n) {
|
|
141
|
+
const s = await t.adapters.userRoles.list(
|
|
139
142
|
e,
|
|
140
|
-
|
|
143
|
+
n,
|
|
141
144
|
void 0,
|
|
142
145
|
""
|
|
143
146
|
// Empty string for global roles
|
|
144
147
|
);
|
|
145
148
|
for (const r of s)
|
|
146
|
-
if ((await
|
|
149
|
+
if ((await t.adapters.rolePermissions.list(
|
|
147
150
|
e,
|
|
148
151
|
r.id,
|
|
149
152
|
{ per_page: 1e3 }
|
|
@@ -153,22 +156,22 @@ async function ie(n, e, t) {
|
|
|
153
156
|
return !0;
|
|
154
157
|
return !1;
|
|
155
158
|
}
|
|
156
|
-
async function ce(
|
|
157
|
-
const i = (await
|
|
159
|
+
async function ce(t, e, n, s) {
|
|
160
|
+
const i = (await t.adapters.roles.list(e, {})).roles.find((d) => d.name === n);
|
|
158
161
|
if (i)
|
|
159
162
|
return i.id;
|
|
160
|
-
const o = await
|
|
161
|
-
name:
|
|
163
|
+
const o = await t.adapters.roles.create(e, {
|
|
164
|
+
name: n,
|
|
162
165
|
description: s
|
|
163
|
-
}), a =
|
|
166
|
+
}), a = U, u = X.map((d) => ({
|
|
164
167
|
role_id: o.id,
|
|
165
168
|
resource_server_identifier: a,
|
|
166
169
|
permission_name: d.value
|
|
167
170
|
}));
|
|
168
|
-
return await
|
|
171
|
+
return await t.adapters.rolePermissions.assign(
|
|
169
172
|
e,
|
|
170
173
|
o.id,
|
|
171
|
-
|
|
174
|
+
u
|
|
172
175
|
), o.id;
|
|
173
176
|
}
|
|
174
177
|
const le = [
|
|
@@ -180,31 +183,31 @@ const le = [
|
|
|
180
183
|
"twilio_sid",
|
|
181
184
|
"twilio_token"
|
|
182
185
|
];
|
|
183
|
-
function
|
|
184
|
-
const { controlPlaneTenantId: s, getChildTenantIds: r, getAdapters: i } =
|
|
185
|
-
async function a(c,
|
|
186
|
-
return (await e(c).list(
|
|
186
|
+
function M(t, e, n = () => !0) {
|
|
187
|
+
const { controlPlaneTenantId: s, getChildTenantIds: r, getAdapters: i } = t, o = /* @__PURE__ */ new Map();
|
|
188
|
+
async function a(c, f, l) {
|
|
189
|
+
return (await e(c).list(f, {
|
|
187
190
|
q: `name:${l}`,
|
|
188
191
|
per_page: 1
|
|
189
192
|
}))[0] ?? null;
|
|
190
193
|
}
|
|
191
|
-
async function
|
|
192
|
-
const
|
|
194
|
+
async function u(c) {
|
|
195
|
+
const f = await r(), l = e(await i(s));
|
|
193
196
|
await Promise.all(
|
|
194
|
-
|
|
197
|
+
f.map(async (m) => {
|
|
195
198
|
try {
|
|
196
|
-
const w = await i(
|
|
199
|
+
const w = await i(m), g = e(w), h = {
|
|
197
200
|
...l.transform(c),
|
|
198
201
|
is_system: !0
|
|
199
|
-
}, y = await a(w,
|
|
202
|
+
}, y = await a(w, m, c.name), v = y ? g.getId(y) : void 0;
|
|
200
203
|
if (y && v) {
|
|
201
204
|
const b = g.preserveOnUpdate ? g.preserveOnUpdate(y, h) : h;
|
|
202
|
-
await g.update(
|
|
205
|
+
await g.update(m, v, b);
|
|
203
206
|
} else
|
|
204
|
-
await g.create(
|
|
207
|
+
await g.create(m, h);
|
|
205
208
|
} catch (w) {
|
|
206
209
|
console.error(
|
|
207
|
-
`Failed to sync ${l.listKey} "${c.name}" to tenant "${
|
|
210
|
+
`Failed to sync ${l.listKey} "${c.name}" to tenant "${m}":`,
|
|
208
211
|
w
|
|
209
212
|
);
|
|
210
213
|
}
|
|
@@ -212,56 +215,56 @@ function q(n, e, t = () => !0) {
|
|
|
212
215
|
);
|
|
213
216
|
}
|
|
214
217
|
async function d(c) {
|
|
215
|
-
const
|
|
218
|
+
const f = await r();
|
|
216
219
|
await Promise.all(
|
|
217
|
-
|
|
220
|
+
f.map(async (l) => {
|
|
218
221
|
try {
|
|
219
|
-
const
|
|
220
|
-
g &&
|
|
221
|
-
} catch (
|
|
222
|
+
const m = await i(l), w = e(m), g = await a(m, l, c), p = g ? w.getId(g) : void 0;
|
|
223
|
+
g && p && await w.remove(l, p);
|
|
224
|
+
} catch (m) {
|
|
222
225
|
console.error(
|
|
223
226
|
`Failed to delete entity "${c}" from tenant "${l}":`,
|
|
224
|
-
|
|
227
|
+
m
|
|
225
228
|
);
|
|
226
229
|
}
|
|
227
230
|
})
|
|
228
231
|
);
|
|
229
232
|
}
|
|
230
233
|
return {
|
|
231
|
-
afterCreate: async (c,
|
|
232
|
-
c.tenantId === s &&
|
|
234
|
+
afterCreate: async (c, f) => {
|
|
235
|
+
c.tenantId === s && n(f) && await u(f);
|
|
233
236
|
},
|
|
234
|
-
afterUpdate: async (c,
|
|
235
|
-
c.tenantId === s &&
|
|
237
|
+
afterUpdate: async (c, f, l) => {
|
|
238
|
+
c.tenantId === s && n(l) && await u(l);
|
|
236
239
|
},
|
|
237
|
-
beforeDelete: async (c,
|
|
240
|
+
beforeDelete: async (c, f) => {
|
|
238
241
|
if (c.tenantId !== s) return;
|
|
239
|
-
const
|
|
240
|
-
|
|
242
|
+
const m = await e(c.adapters).get(c.tenantId, f);
|
|
243
|
+
m && n(m) && o.set(f, m);
|
|
241
244
|
},
|
|
242
|
-
afterDelete: async (c,
|
|
245
|
+
afterDelete: async (c, f) => {
|
|
243
246
|
if (c.tenantId !== s) return;
|
|
244
|
-
const l = o.get(
|
|
245
|
-
l && (o.delete(
|
|
247
|
+
const l = o.get(f);
|
|
248
|
+
l && (o.delete(f), await d(l.name));
|
|
246
249
|
}
|
|
247
250
|
};
|
|
248
251
|
}
|
|
249
|
-
function
|
|
250
|
-
const { controlPlaneTenantId: s, getControlPlaneAdapters: r, getAdapters: i } =
|
|
252
|
+
function q(t, e, n = () => !0) {
|
|
253
|
+
const { controlPlaneTenantId: s, getControlPlaneAdapters: r, getAdapters: i } = t;
|
|
251
254
|
return {
|
|
252
255
|
async afterCreate(o, a) {
|
|
253
256
|
if (a.id !== s)
|
|
254
257
|
try {
|
|
255
|
-
const
|
|
256
|
-
(
|
|
258
|
+
const u = await r(), d = await i(a.id), c = e(u), f = e(d), l = await z(
|
|
259
|
+
(m) => c.listPaginated(s, m),
|
|
257
260
|
c.listKey,
|
|
258
261
|
{ cursorField: "id", pageSize: 100 }
|
|
259
262
|
);
|
|
260
263
|
await Promise.all(
|
|
261
|
-
l.filter((
|
|
264
|
+
l.filter((m) => n(m)).map(async (m) => {
|
|
262
265
|
try {
|
|
263
|
-
const w = c.transform(
|
|
264
|
-
await
|
|
266
|
+
const w = c.transform(m);
|
|
267
|
+
await f.create(a.id, {
|
|
265
268
|
...w,
|
|
266
269
|
is_system: !0
|
|
267
270
|
});
|
|
@@ -273,22 +276,22 @@ function M(n, e, t = () => !0) {
|
|
|
273
276
|
}
|
|
274
277
|
})
|
|
275
278
|
);
|
|
276
|
-
} catch (
|
|
279
|
+
} catch (u) {
|
|
277
280
|
console.error(
|
|
278
281
|
`Failed to sync entities to new tenant "${a.id}":`,
|
|
279
|
-
|
|
282
|
+
u
|
|
280
283
|
);
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
};
|
|
284
287
|
}
|
|
285
|
-
const H = (
|
|
286
|
-
list: async (e,
|
|
287
|
-
listPaginated: (e,
|
|
288
|
-
get: (e,
|
|
289
|
-
create: (e,
|
|
290
|
-
update: (e,
|
|
291
|
-
remove: (e,
|
|
288
|
+
const H = (t) => ({
|
|
289
|
+
list: async (e, n) => (await t.resourceServers.list(e, n)).resource_servers,
|
|
290
|
+
listPaginated: (e, n) => t.resourceServers.list(e, n),
|
|
291
|
+
get: (e, n) => t.resourceServers.get(e, n),
|
|
292
|
+
create: (e, n) => t.resourceServers.create(e, n),
|
|
293
|
+
update: (e, n, s) => t.resourceServers.update(e, n, s),
|
|
294
|
+
remove: (e, n) => t.resourceServers.remove(e, n),
|
|
292
295
|
listKey: "resource_servers",
|
|
293
296
|
getId: (e) => e.id,
|
|
294
297
|
transform: (e) => ({
|
|
@@ -300,13 +303,13 @@ const H = (n) => ({
|
|
|
300
303
|
token_lifetime: e.token_lifetime,
|
|
301
304
|
token_lifetime_for_web: e.token_lifetime_for_web
|
|
302
305
|
})
|
|
303
|
-
}), G = (
|
|
304
|
-
list: async (e,
|
|
305
|
-
listPaginated: (e,
|
|
306
|
-
get: (e,
|
|
307
|
-
create: (e,
|
|
308
|
-
update: (e,
|
|
309
|
-
remove: (e,
|
|
306
|
+
}), G = (t) => ({
|
|
307
|
+
list: async (e, n) => (await t.roles.list(e, n)).roles,
|
|
308
|
+
listPaginated: (e, n) => t.roles.list(e, n),
|
|
309
|
+
get: (e, n) => t.roles.get(e, n),
|
|
310
|
+
create: (e, n) => t.roles.create(e, n),
|
|
311
|
+
update: (e, n, s) => t.roles.update(e, n, s),
|
|
312
|
+
remove: (e, n) => t.roles.remove(e, n),
|
|
310
313
|
listKey: "roles",
|
|
311
314
|
getId: (e) => e.id,
|
|
312
315
|
transform: (e) => ({
|
|
@@ -314,25 +317,25 @@ const H = (n) => ({
|
|
|
314
317
|
name: e.name,
|
|
315
318
|
description: e.description
|
|
316
319
|
})
|
|
317
|
-
}),
|
|
318
|
-
list: async (e,
|
|
319
|
-
listPaginated: (e,
|
|
320
|
-
get: (e,
|
|
321
|
-
create: (e,
|
|
322
|
-
update: (e,
|
|
323
|
-
remove: (e,
|
|
320
|
+
}), L = (t) => ({
|
|
321
|
+
list: async (e, n) => (await t.connections.list(e, n)).connections,
|
|
322
|
+
listPaginated: (e, n) => t.connections.list(e, n),
|
|
323
|
+
get: (e, n) => t.connections.get(e, n),
|
|
324
|
+
create: (e, n) => t.connections.create(e, n),
|
|
325
|
+
update: (e, n, s) => t.connections.update(e, n, s),
|
|
326
|
+
remove: (e, n) => t.connections.remove(e, n),
|
|
324
327
|
listKey: "connections",
|
|
325
328
|
getId: (e) => e.id,
|
|
326
329
|
transform: (e) => {
|
|
327
|
-
const
|
|
330
|
+
const n = e.options ? { ...e.options } : {};
|
|
328
331
|
for (const s of le)
|
|
329
|
-
delete
|
|
332
|
+
delete n[s];
|
|
330
333
|
return {
|
|
331
334
|
id: e.id,
|
|
332
335
|
name: e.name,
|
|
333
336
|
display_name: e.display_name,
|
|
334
337
|
strategy: e.strategy,
|
|
335
|
-
options:
|
|
338
|
+
options: n,
|
|
336
339
|
response_type: e.response_type,
|
|
337
340
|
response_mode: e.response_mode,
|
|
338
341
|
is_domain_connection: e.is_domain_connection,
|
|
@@ -340,12 +343,12 @@ const H = (n) => ({
|
|
|
340
343
|
metadata: e.metadata
|
|
341
344
|
};
|
|
342
345
|
},
|
|
343
|
-
preserveOnUpdate: (e,
|
|
346
|
+
preserveOnUpdate: (e, n) => {
|
|
344
347
|
const s = e.options || {};
|
|
345
348
|
return {
|
|
346
|
-
...
|
|
349
|
+
...n,
|
|
347
350
|
options: {
|
|
348
|
-
...
|
|
351
|
+
...n.options,
|
|
349
352
|
client_id: s.client_id,
|
|
350
353
|
client_secret: s.client_secret,
|
|
351
354
|
app_secret: s.app_secret,
|
|
@@ -357,40 +360,40 @@ const H = (n) => ({
|
|
|
357
360
|
};
|
|
358
361
|
}
|
|
359
362
|
});
|
|
360
|
-
function de(
|
|
361
|
-
const { sync: e = {}, filters:
|
|
362
|
-
|
|
363
|
+
function de(t) {
|
|
364
|
+
const { sync: e = {}, filters: n = {} } = t, s = e.resourceServers ?? !0, r = e.roles ?? !0, i = e.connections ?? !0, o = s ? M(
|
|
365
|
+
t,
|
|
363
366
|
H,
|
|
364
|
-
|
|
365
|
-
) : void 0, a = r ?
|
|
366
|
-
|
|
367
|
+
n.resourceServers
|
|
368
|
+
) : void 0, a = r ? M(
|
|
369
|
+
t,
|
|
367
370
|
G,
|
|
368
|
-
|
|
369
|
-
) : void 0,
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
) : void 0, d = s ?
|
|
374
|
-
|
|
371
|
+
n.roles
|
|
372
|
+
) : void 0, u = i ? M(
|
|
373
|
+
t,
|
|
374
|
+
L,
|
|
375
|
+
n.connections
|
|
376
|
+
) : void 0, d = s ? q(
|
|
377
|
+
t,
|
|
375
378
|
H,
|
|
376
|
-
|
|
377
|
-
) : void 0, c = r ?
|
|
378
|
-
|
|
379
|
+
n.resourceServers
|
|
380
|
+
) : void 0, c = r ? q(
|
|
381
|
+
t,
|
|
379
382
|
G,
|
|
380
|
-
|
|
381
|
-
) : void 0,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
n.roles
|
|
384
|
+
) : void 0, f = i ? q(
|
|
385
|
+
t,
|
|
386
|
+
L,
|
|
387
|
+
n.connections
|
|
385
388
|
) : void 0, l = r ? {
|
|
386
|
-
async afterCreate(g,
|
|
389
|
+
async afterCreate(g, p) {
|
|
387
390
|
var h;
|
|
388
|
-
if (
|
|
389
|
-
await ((h = c == null ? void 0 : c.afterCreate) == null ? void 0 : h.call(c, g,
|
|
391
|
+
if (p.id !== t.controlPlaneTenantId) {
|
|
392
|
+
await ((h = c == null ? void 0 : c.afterCreate) == null ? void 0 : h.call(c, g, p));
|
|
390
393
|
try {
|
|
391
|
-
const y = await
|
|
394
|
+
const y = await t.getControlPlaneAdapters(), v = await t.getAdapters(p.id), b = await z(
|
|
392
395
|
(_) => y.roles.list(
|
|
393
|
-
|
|
396
|
+
t.controlPlaneTenantId,
|
|
394
397
|
_
|
|
395
398
|
),
|
|
396
399
|
"roles",
|
|
@@ -399,12 +402,12 @@ function de(n) {
|
|
|
399
402
|
for (const _ of b.filter(
|
|
400
403
|
(T) => {
|
|
401
404
|
var A;
|
|
402
|
-
return ((A =
|
|
405
|
+
return ((A = n.roles) == null ? void 0 : A.call(n, T)) ?? !0;
|
|
403
406
|
}
|
|
404
407
|
)) {
|
|
405
|
-
const T = await
|
|
408
|
+
const T = await m(
|
|
406
409
|
v,
|
|
407
|
-
|
|
410
|
+
p.id,
|
|
408
411
|
_.name
|
|
409
412
|
);
|
|
410
413
|
T && S.set(_.name, T.id);
|
|
@@ -412,19 +415,19 @@ function de(n) {
|
|
|
412
415
|
for (const _ of b.filter(
|
|
413
416
|
(T) => {
|
|
414
417
|
var A;
|
|
415
|
-
return ((A =
|
|
418
|
+
return ((A = n.roles) == null ? void 0 : A.call(n, T)) ?? !0;
|
|
416
419
|
}
|
|
417
420
|
)) {
|
|
418
421
|
const T = S.get(_.name);
|
|
419
422
|
if (T)
|
|
420
423
|
try {
|
|
421
424
|
const A = await y.rolePermissions.list(
|
|
422
|
-
|
|
425
|
+
t.controlPlaneTenantId,
|
|
423
426
|
_.id,
|
|
424
427
|
{}
|
|
425
428
|
);
|
|
426
429
|
A.length > 0 && await v.rolePermissions.assign(
|
|
427
|
-
|
|
430
|
+
p.id,
|
|
428
431
|
T,
|
|
429
432
|
A.map((P) => ({
|
|
430
433
|
role_id: T,
|
|
@@ -434,22 +437,22 @@ function de(n) {
|
|
|
434
437
|
);
|
|
435
438
|
} catch (A) {
|
|
436
439
|
console.error(
|
|
437
|
-
`Failed to sync permissions for role "${_.name}" to tenant "${
|
|
440
|
+
`Failed to sync permissions for role "${_.name}" to tenant "${p.id}":`,
|
|
438
441
|
A
|
|
439
442
|
);
|
|
440
443
|
}
|
|
441
444
|
}
|
|
442
445
|
} catch (y) {
|
|
443
446
|
console.error(
|
|
444
|
-
`Failed to sync role permissions to tenant "${
|
|
447
|
+
`Failed to sync role permissions to tenant "${p.id}":`,
|
|
445
448
|
y
|
|
446
449
|
);
|
|
447
450
|
}
|
|
448
451
|
}
|
|
449
452
|
}
|
|
450
453
|
} : void 0;
|
|
451
|
-
async function
|
|
452
|
-
return (await g.roles.list(
|
|
454
|
+
async function m(g, p, h) {
|
|
455
|
+
return (await g.roles.list(p, {
|
|
453
456
|
q: `name:${h}`,
|
|
454
457
|
per_page: 1
|
|
455
458
|
})).roles[0] ?? null;
|
|
@@ -458,19 +461,19 @@ function de(n) {
|
|
|
458
461
|
entityHooks: {
|
|
459
462
|
resourceServers: o,
|
|
460
463
|
roles: a,
|
|
461
|
-
connections:
|
|
464
|
+
connections: u
|
|
462
465
|
},
|
|
463
466
|
tenantHooks: {
|
|
464
|
-
async afterCreate(g,
|
|
467
|
+
async afterCreate(g, p) {
|
|
465
468
|
const h = [
|
|
466
469
|
d == null ? void 0 : d.afterCreate,
|
|
467
470
|
(l == null ? void 0 : l.afterCreate) ?? (c == null ? void 0 : c.afterCreate),
|
|
468
|
-
|
|
471
|
+
f == null ? void 0 : f.afterCreate
|
|
469
472
|
], y = [];
|
|
470
473
|
for (const v of h)
|
|
471
474
|
if (v)
|
|
472
475
|
try {
|
|
473
|
-
await v(g,
|
|
476
|
+
await v(g, p);
|
|
474
477
|
} catch (b) {
|
|
475
478
|
y.push(b instanceof Error ? b : new Error(String(b)));
|
|
476
479
|
}
|
|
@@ -490,11 +493,11 @@ var C = class extends Error {
|
|
|
490
493
|
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
491
494
|
* @param options - Additional options for the exception.
|
|
492
495
|
*/
|
|
493
|
-
constructor(e = 500,
|
|
494
|
-
super(
|
|
496
|
+
constructor(e = 500, n) {
|
|
497
|
+
super(n == null ? void 0 : n.message, { cause: n == null ? void 0 : n.cause });
|
|
495
498
|
O(this, "res");
|
|
496
499
|
O(this, "status");
|
|
497
|
-
this.res =
|
|
500
|
+
this.res = n == null ? void 0 : n.res, this.status = e;
|
|
498
501
|
}
|
|
499
502
|
/**
|
|
500
503
|
* Returns the response object associated with the exception.
|
|
@@ -510,15 +513,15 @@ var C = class extends Error {
|
|
|
510
513
|
});
|
|
511
514
|
}
|
|
512
515
|
};
|
|
513
|
-
function k(
|
|
514
|
-
const
|
|
515
|
-
return
|
|
516
|
+
function k(t, e) {
|
|
517
|
+
const n = new Z();
|
|
518
|
+
return n.openapi(
|
|
516
519
|
R({
|
|
517
520
|
tags: ["tenants"],
|
|
518
521
|
method: "get",
|
|
519
522
|
path: "/",
|
|
520
523
|
request: {
|
|
521
|
-
query:
|
|
524
|
+
query: x
|
|
522
525
|
},
|
|
523
526
|
security: [
|
|
524
527
|
{
|
|
@@ -542,31 +545,31 @@ function k(n, e) {
|
|
|
542
545
|
}
|
|
543
546
|
}),
|
|
544
547
|
async (s) => {
|
|
545
|
-
var
|
|
546
|
-
const r = s.req.valid("query"), { page: i, per_page: o, include_totals: a, q:
|
|
548
|
+
var m, w, g, p;
|
|
549
|
+
const r = s.req.valid("query"), { page: i, per_page: o, include_totals: a, q: u } = r, d = s.var.user, c = (d == null ? void 0 : d.permissions) || [];
|
|
547
550
|
if (c.includes("auth:read") || c.includes("admin:organizations")) {
|
|
548
551
|
const h = await s.env.data.tenants.list({
|
|
549
552
|
page: i,
|
|
550
553
|
per_page: o,
|
|
551
554
|
include_totals: a,
|
|
552
|
-
q:
|
|
555
|
+
q: u
|
|
553
556
|
});
|
|
554
557
|
return a ? s.json({
|
|
555
558
|
tenants: h.tenants,
|
|
556
|
-
start: ((
|
|
559
|
+
start: ((m = h.totals) == null ? void 0 : m.start) ?? 0,
|
|
557
560
|
limit: ((w = h.totals) == null ? void 0 : w.limit) ?? o,
|
|
558
561
|
length: h.tenants.length
|
|
559
562
|
}) : s.json({ tenants: h.tenants });
|
|
560
563
|
}
|
|
561
|
-
if (
|
|
562
|
-
const h =
|
|
563
|
-
(
|
|
564
|
+
if (t.accessControl && (d != null && d.sub)) {
|
|
565
|
+
const h = t.accessControl.controlPlaneTenantId, v = (await z(
|
|
566
|
+
($) => s.env.data.userOrganizations.listUserOrganizations(
|
|
564
567
|
h,
|
|
565
568
|
d.sub,
|
|
566
|
-
|
|
569
|
+
$
|
|
567
570
|
),
|
|
568
571
|
"organizations"
|
|
569
|
-
)).map((
|
|
572
|
+
)).map(($) => $.name);
|
|
570
573
|
if (v.length === 0)
|
|
571
574
|
return a ? s.json({
|
|
572
575
|
tenants: [],
|
|
@@ -582,8 +585,8 @@ function k(n, e) {
|
|
|
582
585
|
limit: _,
|
|
583
586
|
length: b
|
|
584
587
|
}) : s.json({ tenants: [] });
|
|
585
|
-
const P = A.map((
|
|
586
|
-
q:
|
|
588
|
+
const P = A.map(($) => `id:${$}`).join(" OR "), V = u ? `(${P}) AND (${u})` : P, E = await s.env.data.tenants.list({
|
|
589
|
+
q: V,
|
|
587
590
|
per_page: _,
|
|
588
591
|
include_totals: !1
|
|
589
592
|
// We calculate totals from accessibleTenantIds
|
|
@@ -599,16 +602,16 @@ function k(n, e) {
|
|
|
599
602
|
page: i,
|
|
600
603
|
per_page: o,
|
|
601
604
|
include_totals: a,
|
|
602
|
-
q:
|
|
605
|
+
q: u
|
|
603
606
|
});
|
|
604
607
|
return a ? s.json({
|
|
605
608
|
tenants: l.tenants,
|
|
606
609
|
start: ((g = l.totals) == null ? void 0 : g.start) ?? 0,
|
|
607
|
-
limit: ((
|
|
610
|
+
limit: ((p = l.totals) == null ? void 0 : p.limit) ?? o,
|
|
608
611
|
length: l.tenants.length
|
|
609
612
|
}) : s.json({ tenants: l.tenants });
|
|
610
613
|
}
|
|
611
|
-
),
|
|
614
|
+
), n.openapi(
|
|
612
615
|
R({
|
|
613
616
|
tags: ["tenants"],
|
|
614
617
|
method: "post",
|
|
@@ -617,7 +620,7 @@ function k(n, e) {
|
|
|
617
620
|
body: {
|
|
618
621
|
content: {
|
|
619
622
|
"application/json": {
|
|
620
|
-
schema:
|
|
623
|
+
schema: ee
|
|
621
624
|
}
|
|
622
625
|
}
|
|
623
626
|
}
|
|
@@ -645,7 +648,7 @@ function k(n, e) {
|
|
|
645
648
|
}
|
|
646
649
|
}),
|
|
647
650
|
async (s) => {
|
|
648
|
-
var
|
|
651
|
+
var u, d;
|
|
649
652
|
const r = s.var.user;
|
|
650
653
|
if (!(r != null && r.sub))
|
|
651
654
|
throw new C(401, {
|
|
@@ -656,11 +659,11 @@ function k(n, e) {
|
|
|
656
659
|
adapters: s.env.data,
|
|
657
660
|
ctx: s
|
|
658
661
|
};
|
|
659
|
-
(
|
|
662
|
+
(u = e.tenants) != null && u.beforeCreate && (i = await e.tenants.beforeCreate(o, i));
|
|
660
663
|
const a = await s.env.data.tenants.create(i);
|
|
661
664
|
return (d = e.tenants) != null && d.afterCreate && await e.tenants.afterCreate(o, a), s.json(a, 201);
|
|
662
665
|
}
|
|
663
|
-
),
|
|
666
|
+
), n.openapi(
|
|
664
667
|
R({
|
|
665
668
|
tags: ["tenants"],
|
|
666
669
|
method: "delete",
|
|
@@ -688,10 +691,10 @@ function k(n, e) {
|
|
|
688
691
|
}
|
|
689
692
|
}),
|
|
690
693
|
async (s) => {
|
|
691
|
-
var a,
|
|
694
|
+
var a, u;
|
|
692
695
|
const { id: r } = s.req.valid("param");
|
|
693
|
-
if (
|
|
694
|
-
const d = s.var.user, c =
|
|
696
|
+
if (t.accessControl) {
|
|
697
|
+
const d = s.var.user, c = t.accessControl.controlPlaneTenantId;
|
|
695
698
|
if (!(d != null && d.sub))
|
|
696
699
|
throw new C(401, {
|
|
697
700
|
message: "Authentication required"
|
|
@@ -700,14 +703,14 @@ function k(n, e) {
|
|
|
700
703
|
throw new C(403, {
|
|
701
704
|
message: "Cannot delete the control plane"
|
|
702
705
|
});
|
|
703
|
-
if (!(await
|
|
704
|
-
(
|
|
706
|
+
if (!(await z(
|
|
707
|
+
(m) => s.env.data.userOrganizations.listUserOrganizations(
|
|
705
708
|
c,
|
|
706
709
|
d.sub,
|
|
707
|
-
|
|
710
|
+
m
|
|
708
711
|
),
|
|
709
712
|
"organizations"
|
|
710
|
-
)).some((
|
|
713
|
+
)).some((m) => m.name === r))
|
|
711
714
|
throw new C(403, {
|
|
712
715
|
message: "Access denied to this tenant"
|
|
713
716
|
});
|
|
@@ -720,11 +723,11 @@ function k(n, e) {
|
|
|
720
723
|
adapters: s.env.data,
|
|
721
724
|
ctx: s
|
|
722
725
|
};
|
|
723
|
-
return (a = e.tenants) != null && a.beforeDelete && await e.tenants.beforeDelete(o, r), await s.env.data.tenants.remove(r), (
|
|
726
|
+
return (a = e.tenants) != null && a.beforeDelete && await e.tenants.beforeDelete(o, r), await s.env.data.tenants.remove(r), (u = e.tenants) != null && u.afterDelete && await e.tenants.afterDelete(o, r), s.body(null, 204);
|
|
724
727
|
}
|
|
725
|
-
),
|
|
728
|
+
), n;
|
|
726
729
|
}
|
|
727
|
-
function ue(
|
|
730
|
+
function ue(t) {
|
|
728
731
|
const e = [
|
|
729
732
|
{
|
|
730
733
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -733,26 +736,26 @@ function ue(n) {
|
|
|
733
736
|
{ pattern: /\/api\/v2\/roles\/([^/]+)$/, type: "role" },
|
|
734
737
|
{ pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
|
|
735
738
|
];
|
|
736
|
-
for (const { pattern:
|
|
737
|
-
const r =
|
|
739
|
+
for (const { pattern: n, type: s } of e) {
|
|
740
|
+
const r = t.match(n);
|
|
738
741
|
if (r && r[1])
|
|
739
742
|
return { type: s, id: r[1] };
|
|
740
743
|
}
|
|
741
744
|
return null;
|
|
742
745
|
}
|
|
743
|
-
async function me(
|
|
746
|
+
async function me(t, e, n) {
|
|
744
747
|
try {
|
|
745
|
-
switch (
|
|
748
|
+
switch (n.type) {
|
|
746
749
|
case "resource_server": {
|
|
747
|
-
const s = await
|
|
750
|
+
const s = await t.resourceServers.get(e, n.id);
|
|
748
751
|
return (s == null ? void 0 : s.is_system) === !0;
|
|
749
752
|
}
|
|
750
753
|
case "role": {
|
|
751
|
-
const s = await
|
|
754
|
+
const s = await t.roles.get(e, n.id);
|
|
752
755
|
return (s == null ? void 0 : s.is_system) === !0;
|
|
753
756
|
}
|
|
754
757
|
case "connection": {
|
|
755
|
-
const s = await
|
|
758
|
+
const s = await t.connections.get(e, n.id);
|
|
756
759
|
return (s == null ? void 0 : s.is_system) === !0;
|
|
757
760
|
}
|
|
758
761
|
default:
|
|
@@ -762,63 +765,63 @@ async function me(n, e, t) {
|
|
|
762
765
|
return !1;
|
|
763
766
|
}
|
|
764
767
|
}
|
|
765
|
-
function
|
|
768
|
+
function fe(t) {
|
|
766
769
|
return {
|
|
767
770
|
resource_server: "resource server",
|
|
768
771
|
role: "role",
|
|
769
772
|
connection: "connection"
|
|
770
|
-
}[
|
|
773
|
+
}[t];
|
|
771
774
|
}
|
|
772
|
-
function
|
|
773
|
-
return async (
|
|
774
|
-
if (!["PATCH", "PUT", "DELETE"].includes(
|
|
775
|
+
function pe() {
|
|
776
|
+
return async (t, e) => {
|
|
777
|
+
if (!["PATCH", "PUT", "DELETE"].includes(t.req.method))
|
|
775
778
|
return e();
|
|
776
|
-
const
|
|
777
|
-
if (!
|
|
779
|
+
const n = ue(t.req.path);
|
|
780
|
+
if (!n)
|
|
778
781
|
return e();
|
|
779
|
-
const s =
|
|
782
|
+
const s = t.var.tenant_id || t.req.header("x-tenant-id") || t.req.header("tenant-id");
|
|
780
783
|
if (!s)
|
|
781
784
|
return e();
|
|
782
|
-
if (await me(
|
|
785
|
+
if (await me(t.env.data, s, n))
|
|
783
786
|
throw new C(403, {
|
|
784
|
-
message: `This ${
|
|
787
|
+
message: `This ${fe(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
785
788
|
});
|
|
786
789
|
return e();
|
|
787
790
|
};
|
|
788
791
|
}
|
|
789
|
-
function
|
|
790
|
-
const { controlPlaneTenantId:
|
|
792
|
+
function B(t, e) {
|
|
793
|
+
const { controlPlaneTenantId: n, controlPlaneClientId: s } = e;
|
|
791
794
|
return {
|
|
792
|
-
...
|
|
795
|
+
...t,
|
|
793
796
|
legacyClients: {
|
|
794
|
-
...
|
|
797
|
+
...t.legacyClients,
|
|
795
798
|
get: async (r) => {
|
|
796
|
-
var
|
|
797
|
-
const i = await
|
|
799
|
+
var f;
|
|
800
|
+
const i = await t.legacyClients.get(r);
|
|
798
801
|
if (!i)
|
|
799
802
|
return null;
|
|
800
|
-
const o = s ? await
|
|
803
|
+
const o = s ? await t.legacyClients.get(s) : void 0, a = await t.connections.list(
|
|
801
804
|
i.tenant.id
|
|
802
|
-
),
|
|
805
|
+
), u = n ? await t.connections.list(n) : { connections: [] }, d = a.connections.map((l) => {
|
|
803
806
|
var g;
|
|
804
|
-
const
|
|
805
|
-
(
|
|
807
|
+
const m = (g = u.connections) == null ? void 0 : g.find(
|
|
808
|
+
(p) => p.name === l.name
|
|
806
809
|
);
|
|
807
|
-
if (!(
|
|
810
|
+
if (!(m != null && m.options))
|
|
808
811
|
return l;
|
|
809
812
|
const w = D.parse({
|
|
810
|
-
...
|
|
813
|
+
...m || {},
|
|
811
814
|
...l
|
|
812
815
|
});
|
|
813
816
|
return w.options = F.parse({
|
|
814
|
-
...
|
|
817
|
+
...m.options || {},
|
|
815
818
|
...l.options
|
|
816
819
|
}), w;
|
|
817
820
|
}).filter((l) => l), c = {
|
|
818
821
|
...(o == null ? void 0 : o.tenant) || {},
|
|
819
822
|
...i.tenant
|
|
820
823
|
};
|
|
821
|
-
return !i.tenant.audience && ((
|
|
824
|
+
return !i.tenant.audience && ((f = o == null ? void 0 : o.tenant) != null && f.audience) && (c.audience = o.tenant.audience), {
|
|
822
825
|
...i,
|
|
823
826
|
web_origins: [
|
|
824
827
|
...(o == null ? void 0 : o.web_origins) || [],
|
|
@@ -838,52 +841,52 @@ function L(n, e) {
|
|
|
838
841
|
}
|
|
839
842
|
},
|
|
840
843
|
connections: {
|
|
841
|
-
...
|
|
844
|
+
...t.connections,
|
|
842
845
|
get: async (r, i) => {
|
|
843
|
-
const o = await
|
|
846
|
+
const o = await t.connections.get(
|
|
844
847
|
r,
|
|
845
848
|
i
|
|
846
849
|
);
|
|
847
|
-
if (!o || !
|
|
850
|
+
if (!o || !n)
|
|
848
851
|
return o;
|
|
849
|
-
const a = await
|
|
850
|
-
|
|
852
|
+
const a = await t.connections.get(
|
|
853
|
+
n,
|
|
851
854
|
i
|
|
852
855
|
);
|
|
853
856
|
if (!a)
|
|
854
857
|
return o;
|
|
855
|
-
const
|
|
858
|
+
const u = D.parse({
|
|
856
859
|
...a,
|
|
857
860
|
...o
|
|
858
861
|
});
|
|
859
|
-
return
|
|
862
|
+
return u.options = F.parse({
|
|
860
863
|
...a.options || {},
|
|
861
864
|
...o.options
|
|
862
|
-
}),
|
|
865
|
+
}), u;
|
|
863
866
|
},
|
|
864
867
|
list: async (r, i) => {
|
|
865
|
-
const o = await
|
|
866
|
-
if (!
|
|
868
|
+
const o = await t.connections.list(r, i);
|
|
869
|
+
if (!n || r === n)
|
|
867
870
|
return o;
|
|
868
|
-
const a = await
|
|
871
|
+
const a = await t.connections.list(n), u = o.connections.map((d) => {
|
|
869
872
|
var l;
|
|
870
873
|
const c = (l = a.connections) == null ? void 0 : l.find(
|
|
871
|
-
(
|
|
874
|
+
(m) => m.name === d.name
|
|
872
875
|
);
|
|
873
876
|
if (!(c != null && c.options))
|
|
874
877
|
return d;
|
|
875
|
-
const
|
|
878
|
+
const f = D.parse({
|
|
876
879
|
...c,
|
|
877
880
|
...d
|
|
878
881
|
});
|
|
879
|
-
return
|
|
882
|
+
return f.options = F.parse({
|
|
880
883
|
...c.options || {},
|
|
881
884
|
...d.options
|
|
882
|
-
}),
|
|
885
|
+
}), f;
|
|
883
886
|
});
|
|
884
887
|
return {
|
|
885
888
|
...o,
|
|
886
|
-
connections:
|
|
889
|
+
connections: u
|
|
887
890
|
};
|
|
888
891
|
}
|
|
889
892
|
}
|
|
@@ -896,76 +899,79 @@ function L(n, e) {
|
|
|
896
899
|
// They remain part of ...baseAdapters and can be properly wrapped by caching.
|
|
897
900
|
};
|
|
898
901
|
}
|
|
899
|
-
function ge(
|
|
900
|
-
return
|
|
902
|
+
function ge(t, e) {
|
|
903
|
+
return B(t, e);
|
|
901
904
|
}
|
|
902
|
-
const Ie =
|
|
903
|
-
function we(
|
|
904
|
-
return async (e,
|
|
905
|
-
if (!
|
|
906
|
-
return
|
|
907
|
-
const s = e.var.
|
|
908
|
-
|
|
905
|
+
const Ie = B, Se = ge;
|
|
906
|
+
function we(t) {
|
|
907
|
+
return async (e, n) => {
|
|
908
|
+
if (!t.accessControl)
|
|
909
|
+
return n();
|
|
910
|
+
const { controlPlaneTenantId: s } = t.accessControl, r = e.var.org_name, i = e.var.organization_id, o = r || i;
|
|
911
|
+
let a = e.var.tenant_id;
|
|
912
|
+
const u = e.var.user, c = (u != null && u.aud ? Array.isArray(u.aud) ? u.aud : [u.aud] : []).includes(U);
|
|
913
|
+
if (!a && o && c && (e.set("tenant_id", o), a = o), !a)
|
|
909
914
|
throw new C(400, {
|
|
910
915
|
message: "Tenant ID not found in request"
|
|
911
916
|
});
|
|
912
|
-
if (!
|
|
913
|
-
|
|
917
|
+
if (!ne(
|
|
918
|
+
i,
|
|
919
|
+
a,
|
|
914
920
|
s,
|
|
915
|
-
|
|
921
|
+
r
|
|
916
922
|
))
|
|
917
923
|
throw new C(403, {
|
|
918
|
-
message: `Access denied to tenant ${
|
|
924
|
+
message: `Access denied to tenant ${a}`
|
|
919
925
|
});
|
|
920
|
-
return
|
|
926
|
+
return n();
|
|
921
927
|
};
|
|
922
928
|
}
|
|
923
|
-
function he(
|
|
924
|
-
return async (e,
|
|
925
|
-
if (!
|
|
926
|
-
return
|
|
929
|
+
function he(t) {
|
|
930
|
+
return async (e, n) => {
|
|
931
|
+
if (!t.subdomainRouting)
|
|
932
|
+
return n();
|
|
927
933
|
const {
|
|
928
934
|
baseDomain: s,
|
|
929
935
|
reservedSubdomains: r = [],
|
|
930
936
|
resolveSubdomain: i
|
|
931
|
-
} =
|
|
937
|
+
} = t.subdomainRouting, o = e.req.header("host") || "";
|
|
932
938
|
let a = null;
|
|
933
939
|
if (o.endsWith(s)) {
|
|
934
940
|
const d = o.slice(0, -(s.length + 1));
|
|
935
941
|
d && !d.includes(".") && (a = d);
|
|
936
942
|
}
|
|
937
943
|
if (a && r.includes(a) && (a = null), !a)
|
|
938
|
-
return
|
|
939
|
-
let
|
|
944
|
+
return t.accessControl && e.set("tenant_id", t.accessControl.controlPlaneTenantId), n();
|
|
945
|
+
let u = null;
|
|
940
946
|
if (i)
|
|
941
|
-
|
|
942
|
-
else if (
|
|
947
|
+
u = await i(a);
|
|
948
|
+
else if (t.subdomainRouting.useOrganizations !== !1 && t.accessControl)
|
|
943
949
|
try {
|
|
944
950
|
const d = await e.env.data.organizations.get(
|
|
945
|
-
|
|
951
|
+
t.accessControl.controlPlaneTenantId,
|
|
946
952
|
a
|
|
947
953
|
);
|
|
948
|
-
d && (
|
|
954
|
+
d && (u = d.id);
|
|
949
955
|
} catch {
|
|
950
956
|
}
|
|
951
|
-
if (!
|
|
957
|
+
if (!u)
|
|
952
958
|
throw new C(404, {
|
|
953
959
|
message: `Tenant not found for subdomain: ${a}`
|
|
954
960
|
});
|
|
955
|
-
return e.set("tenant_id",
|
|
961
|
+
return e.set("tenant_id", u), n();
|
|
956
962
|
};
|
|
957
963
|
}
|
|
958
|
-
function ye(
|
|
959
|
-
return async (e,
|
|
960
|
-
if (!
|
|
961
|
-
return
|
|
964
|
+
function ye(t) {
|
|
965
|
+
return async (e, n) => {
|
|
966
|
+
if (!t.databaseIsolation)
|
|
967
|
+
return n();
|
|
962
968
|
const s = e.var.tenant_id;
|
|
963
969
|
if (!s)
|
|
964
970
|
throw new C(400, {
|
|
965
971
|
message: "Tenant ID not found in request"
|
|
966
972
|
});
|
|
967
973
|
try {
|
|
968
|
-
const r = await
|
|
974
|
+
const r = await t.databaseIsolation.getAdapters(s);
|
|
969
975
|
e.env.data = r;
|
|
970
976
|
} catch (r) {
|
|
971
977
|
throw console.error(
|
|
@@ -975,50 +981,50 @@ function ye(n) {
|
|
|
975
981
|
message: "Failed to resolve tenant database"
|
|
976
982
|
});
|
|
977
983
|
}
|
|
978
|
-
return
|
|
984
|
+
return n();
|
|
979
985
|
};
|
|
980
986
|
}
|
|
981
|
-
function
|
|
982
|
-
const e = he(
|
|
987
|
+
function K(t) {
|
|
988
|
+
const e = he(t), n = we(t), s = ye(t);
|
|
983
989
|
return async (r, i) => (await e(r, async () => {
|
|
984
|
-
}), await
|
|
990
|
+
}), await n(r, async () => {
|
|
985
991
|
}), await s(r, async () => {
|
|
986
992
|
}), i());
|
|
987
993
|
}
|
|
988
|
-
function Pe(
|
|
994
|
+
function Pe(t) {
|
|
989
995
|
const {
|
|
990
996
|
dataAdapter: e,
|
|
991
|
-
controlPlaneTenantId:
|
|
997
|
+
controlPlaneTenantId: n = "control_plane",
|
|
992
998
|
sync: s = { resourceServers: !0, roles: !0, connections: !0 },
|
|
993
999
|
defaultPermissions: r = ["tenant:admin"],
|
|
994
1000
|
requireOrganizationMatch: i = !1,
|
|
995
1001
|
managementApiExtensions: o = [],
|
|
996
1002
|
entityHooks: a,
|
|
997
|
-
getChildTenantIds:
|
|
1003
|
+
getChildTenantIds: u,
|
|
998
1004
|
getAdapters: d,
|
|
999
1005
|
...c
|
|
1000
|
-
} =
|
|
1006
|
+
} = t, f = s !== !1, l = f ? {
|
|
1001
1007
|
resourceServers: s.resourceServers ?? !0,
|
|
1002
1008
|
roles: s.roles ?? !0,
|
|
1003
1009
|
connections: s.connections ?? !0
|
|
1004
1010
|
} : { resourceServers: !1, roles: !1, connections: !1 }, g = {
|
|
1005
|
-
controlPlaneTenantId:
|
|
1006
|
-
getChildTenantIds:
|
|
1011
|
+
controlPlaneTenantId: n,
|
|
1012
|
+
getChildTenantIds: u ?? (async () => (await z(
|
|
1007
1013
|
(_) => e.tenants.list(_),
|
|
1008
1014
|
"tenants",
|
|
1009
1015
|
{ cursorField: "id", pageSize: 100 }
|
|
1010
|
-
)).filter((_) => _.id !==
|
|
1016
|
+
)).filter((_) => _.id !== n).map((_) => _.id)),
|
|
1011
1017
|
getAdapters: d ?? (async () => e),
|
|
1012
1018
|
getControlPlaneAdapters: async () => e,
|
|
1013
1019
|
sync: l
|
|
1014
|
-
}, { entityHooks:
|
|
1020
|
+
}, { entityHooks: p, tenantHooks: h } = de(g), y = {
|
|
1015
1021
|
resourceServers: [
|
|
1016
|
-
|
|
1022
|
+
p.resourceServers,
|
|
1017
1023
|
...(a == null ? void 0 : a.resourceServers) ?? []
|
|
1018
1024
|
],
|
|
1019
|
-
roles: [
|
|
1025
|
+
roles: [p.roles, ...(a == null ? void 0 : a.roles) ?? []],
|
|
1020
1026
|
connections: [
|
|
1021
|
-
|
|
1027
|
+
p.connections,
|
|
1022
1028
|
...(a == null ? void 0 : a.connections) ?? []
|
|
1023
1029
|
],
|
|
1024
1030
|
tenants: (a == null ? void 0 : a.tenants) ?? [],
|
|
@@ -1026,13 +1032,13 @@ function Pe(n) {
|
|
|
1026
1032
|
}, v = k(
|
|
1027
1033
|
{
|
|
1028
1034
|
accessControl: {
|
|
1029
|
-
controlPlaneTenantId:
|
|
1035
|
+
controlPlaneTenantId: n,
|
|
1030
1036
|
requireOrganizationMatch: i,
|
|
1031
1037
|
defaultPermissions: r
|
|
1032
1038
|
}
|
|
1033
1039
|
},
|
|
1034
1040
|
{ tenants: h }
|
|
1035
|
-
), { app: b } =
|
|
1041
|
+
), { app: b } = Y({
|
|
1036
1042
|
dataAdapter: e,
|
|
1037
1043
|
...c,
|
|
1038
1044
|
entityHooks: y,
|
|
@@ -1041,72 +1047,72 @@ function Pe(n) {
|
|
|
1041
1047
|
{ path: "/tenants", router: v }
|
|
1042
1048
|
]
|
|
1043
1049
|
});
|
|
1044
|
-
return
|
|
1050
|
+
return f && b.use("/api/v2/*", pe()), { app: b, controlPlaneTenantId: n };
|
|
1045
1051
|
}
|
|
1046
|
-
function
|
|
1047
|
-
const e = j(
|
|
1052
|
+
function $e(t) {
|
|
1053
|
+
const e = j(t);
|
|
1048
1054
|
return {
|
|
1049
1055
|
name: "multi-tenancy",
|
|
1050
1056
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1051
|
-
middleware:
|
|
1057
|
+
middleware: K(t),
|
|
1052
1058
|
// Provide lifecycle hooks
|
|
1053
1059
|
hooks: e,
|
|
1054
1060
|
// Mount tenant management routes
|
|
1055
1061
|
routes: [
|
|
1056
1062
|
{
|
|
1057
1063
|
path: "/management",
|
|
1058
|
-
handler: k(
|
|
1064
|
+
handler: k(t, e)
|
|
1059
1065
|
}
|
|
1060
1066
|
],
|
|
1061
1067
|
// Called when plugin is registered
|
|
1062
1068
|
onRegister: async () => {
|
|
1063
|
-
console.log("Multi-tenancy plugin registered"),
|
|
1064
|
-
` - Access control enabled (control plane: ${
|
|
1065
|
-
),
|
|
1066
|
-
` - Subdomain routing enabled (base domain: ${
|
|
1067
|
-
),
|
|
1069
|
+
console.log("Multi-tenancy plugin registered"), t.accessControl && console.log(
|
|
1070
|
+
` - Access control enabled (control plane: ${t.accessControl.controlPlaneTenantId})`
|
|
1071
|
+
), t.subdomainRouting && console.log(
|
|
1072
|
+
` - Subdomain routing enabled (base domain: ${t.subdomainRouting.baseDomain})`
|
|
1073
|
+
), t.databaseIsolation && console.log(" - Database isolation enabled");
|
|
1068
1074
|
}
|
|
1069
1075
|
};
|
|
1070
1076
|
}
|
|
1071
|
-
function j(
|
|
1072
|
-
const e =
|
|
1077
|
+
function j(t) {
|
|
1078
|
+
const e = t.accessControl ? te(t.accessControl) : {}, n = t.databaseIsolation ? se(t.databaseIsolation) : {}, s = re(t);
|
|
1073
1079
|
return {
|
|
1074
1080
|
...e,
|
|
1075
|
-
...
|
|
1081
|
+
...n,
|
|
1076
1082
|
tenants: s
|
|
1077
1083
|
};
|
|
1078
1084
|
}
|
|
1079
|
-
function _e(
|
|
1080
|
-
const e = new
|
|
1081
|
-
return e.route("/tenants", k(
|
|
1085
|
+
function _e(t) {
|
|
1086
|
+
const e = new J(), n = j(t);
|
|
1087
|
+
return e.route("/tenants", k(t, n)), e;
|
|
1082
1088
|
}
|
|
1083
|
-
function
|
|
1089
|
+
function ze(t) {
|
|
1084
1090
|
return {
|
|
1085
|
-
hooks: j(
|
|
1086
|
-
middleware:
|
|
1087
|
-
app: _e(
|
|
1088
|
-
config:
|
|
1091
|
+
hooks: j(t),
|
|
1092
|
+
middleware: K(t),
|
|
1093
|
+
app: _e(t),
|
|
1094
|
+
config: t
|
|
1089
1095
|
};
|
|
1090
1096
|
}
|
|
1091
1097
|
export {
|
|
1092
|
-
|
|
1098
|
+
te as createAccessControlHooks,
|
|
1093
1099
|
we as createAccessControlMiddleware,
|
|
1094
|
-
|
|
1100
|
+
se as createDatabaseHooks,
|
|
1095
1101
|
ye as createDatabaseMiddleware,
|
|
1096
1102
|
_e as createMultiTenancy,
|
|
1097
1103
|
j as createMultiTenancyHooks,
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1104
|
+
K as createMultiTenancyMiddleware,
|
|
1105
|
+
$e as createMultiTenancyPlugin,
|
|
1106
|
+
pe as createProtectSyncedMiddleware,
|
|
1107
|
+
re as createProvisioningHooks,
|
|
1108
|
+
B as createRuntimeFallbackAdapter,
|
|
1103
1109
|
Ie as createSettingsInheritanceAdapter,
|
|
1104
1110
|
he as createSubdomainMiddleware,
|
|
1105
1111
|
de as createSyncHooks,
|
|
1106
1112
|
k as createTenantsOpenAPIRouter,
|
|
1107
1113
|
Pe as initMultiTenant,
|
|
1108
|
-
|
|
1109
|
-
|
|
1114
|
+
ze as setupMultiTenancy,
|
|
1115
|
+
ne as validateTenantAccess,
|
|
1110
1116
|
ge as withRuntimeFallback,
|
|
1111
1117
|
Se as withSettingsInheritance
|
|
1112
1118
|
};
|