@authhero/multi-tenancy 13.15.0 → 13.16.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.d.ts +346 -502
- package/dist/multi-tenancy.mjs +312 -313
- package/package.json +4 -4
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var U = (t, e, n) =>
|
|
4
|
-
import { Hono as
|
|
5
|
-
import { getTenantAudience as
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var se = (t, e, n) => e in t ? ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var U = (t, e, n) => se(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { Hono as ee } from "hono";
|
|
5
|
+
import { getTenantAudience as oe, MANAGEMENT_API_SCOPES as ie, MANAGEMENT_API_AUDIENCE as ce, fetchAll as F, init as le } from "authhero";
|
|
6
6
|
export * from "authhero";
|
|
7
|
-
import { OpenAPIHono as
|
|
8
|
-
import { auth0QuerySchema as
|
|
7
|
+
import { OpenAPIHono as de, createRoute as B, z } from "@hono/zod-openapi";
|
|
8
|
+
import { auth0QuerySchema as ue, tenantSchema as E, tenantInsertSchema as me, connectionSchema as G, connectionOptionsSchema as K } from "@authhero/adapter-interfaces";
|
|
9
9
|
var S = class extends Error {
|
|
10
10
|
/**
|
|
11
11
|
* Creates an instance of `HTTPException`.
|
|
@@ -32,27 +32,27 @@ var S = class extends Error {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
function
|
|
35
|
+
function pe(t) {
|
|
36
36
|
const { controlPlaneTenantId: e, requireOrganizationMatch: n = !0 } = t;
|
|
37
37
|
return {
|
|
38
|
-
async onTenantAccessValidation(
|
|
39
|
-
if (
|
|
38
|
+
async onTenantAccessValidation(r, a) {
|
|
39
|
+
if (a === e)
|
|
40
40
|
return !0;
|
|
41
41
|
if (n) {
|
|
42
|
-
const
|
|
43
|
-
return i ? i ===
|
|
42
|
+
const c = r.var.org_name, s = r.var.organization_id, i = c || s;
|
|
43
|
+
return i ? i === a : !1;
|
|
44
44
|
}
|
|
45
45
|
return !0;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function fe(t, e, n, r) {
|
|
50
50
|
if (e === n)
|
|
51
51
|
return !0;
|
|
52
|
-
const
|
|
53
|
-
return
|
|
52
|
+
const a = r || t;
|
|
53
|
+
return a ? a === e : !1;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function we(t) {
|
|
56
56
|
return {
|
|
57
57
|
async resolveDataAdapters(e) {
|
|
58
58
|
try {
|
|
@@ -67,112 +67,112 @@ function ge(t) {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function ge(t) {
|
|
71
71
|
return {
|
|
72
72
|
async beforeCreate(e, n) {
|
|
73
73
|
return !n.audience && n.id ? {
|
|
74
74
|
...n,
|
|
75
|
-
audience:
|
|
75
|
+
audience: oe(n.id)
|
|
76
76
|
} : n;
|
|
77
77
|
},
|
|
78
78
|
async afterCreate(e, n) {
|
|
79
|
-
const { accessControl:
|
|
80
|
-
|
|
79
|
+
const { accessControl: r, databaseIsolation: a } = t;
|
|
80
|
+
r && e.ctx && await he(e, n, r), a != null && a.onProvision && await a.onProvision(n.id);
|
|
81
81
|
},
|
|
82
82
|
async beforeDelete(e, n) {
|
|
83
|
-
const { accessControl:
|
|
84
|
-
if (
|
|
83
|
+
const { accessControl: r, databaseIsolation: a } = t;
|
|
84
|
+
if (r)
|
|
85
85
|
try {
|
|
86
86
|
const s = (await e.adapters.organizations.list(
|
|
87
|
-
|
|
87
|
+
r.controlPlaneTenantId
|
|
88
88
|
)).organizations.find((i) => i.name === n);
|
|
89
89
|
s && await e.adapters.organizations.remove(
|
|
90
|
-
|
|
90
|
+
r.controlPlaneTenantId,
|
|
91
91
|
s.id
|
|
92
92
|
);
|
|
93
|
-
} catch (
|
|
93
|
+
} catch (c) {
|
|
94
94
|
console.warn(
|
|
95
95
|
`Failed to remove organization for tenant ${n}:`,
|
|
96
|
-
|
|
96
|
+
c
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
|
-
if (
|
|
99
|
+
if (a != null && a.onDeprovision)
|
|
100
100
|
try {
|
|
101
|
-
await
|
|
102
|
-
} catch (
|
|
101
|
+
await a.onDeprovision(n);
|
|
102
|
+
} catch (c) {
|
|
103
103
|
console.warn(
|
|
104
104
|
`Failed to deprovision database for tenant ${n}:`,
|
|
105
|
-
|
|
105
|
+
c
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
async function
|
|
111
|
+
async function he(t, e, n) {
|
|
112
112
|
const {
|
|
113
|
-
controlPlaneTenantId:
|
|
114
|
-
defaultPermissions:
|
|
115
|
-
defaultRoles:
|
|
113
|
+
controlPlaneTenantId: r,
|
|
114
|
+
defaultPermissions: a,
|
|
115
|
+
defaultRoles: c,
|
|
116
116
|
issuer: s,
|
|
117
117
|
adminRoleName: i = "Tenant Admin",
|
|
118
118
|
adminRoleDescription: p = "Full access to all tenant management operations",
|
|
119
119
|
addCreatorToOrganization: o = !0
|
|
120
|
-
} = n,
|
|
121
|
-
|
|
120
|
+
} = n, l = await t.adapters.organizations.create(
|
|
121
|
+
r,
|
|
122
122
|
{
|
|
123
123
|
name: e.id,
|
|
124
124
|
display_name: e.friendly_name || e.id
|
|
125
125
|
}
|
|
126
126
|
);
|
|
127
127
|
let u;
|
|
128
|
-
if (s && (u = await
|
|
128
|
+
if (s && (u = await _e(
|
|
129
129
|
t,
|
|
130
|
-
|
|
130
|
+
r,
|
|
131
131
|
i,
|
|
132
132
|
p
|
|
133
133
|
)), o && t.ctx) {
|
|
134
134
|
const d = t.ctx.var.user;
|
|
135
|
-
if (d != null && d.sub && !await
|
|
135
|
+
if (d != null && d.sub && !await ve(
|
|
136
136
|
t,
|
|
137
|
-
|
|
137
|
+
r,
|
|
138
138
|
d.sub
|
|
139
139
|
))
|
|
140
140
|
try {
|
|
141
|
-
await t.adapters.userOrganizations.create(
|
|
141
|
+
await t.adapters.userOrganizations.create(r, {
|
|
142
142
|
user_id: d.sub,
|
|
143
|
-
organization_id:
|
|
143
|
+
organization_id: l.id
|
|
144
144
|
}), u && await t.adapters.userRoles.create(
|
|
145
|
-
|
|
145
|
+
r,
|
|
146
146
|
d.sub,
|
|
147
147
|
u,
|
|
148
|
-
|
|
148
|
+
l.id
|
|
149
149
|
// organizationId
|
|
150
150
|
);
|
|
151
151
|
} catch (f) {
|
|
152
152
|
console.warn(
|
|
153
|
-
`Failed to add creator ${d.sub} to organization ${
|
|
153
|
+
`Failed to add creator ${d.sub} to organization ${l.id}:`,
|
|
154
154
|
f
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
`Would assign roles ${
|
|
160
|
-
),
|
|
161
|
-
`Would grant permissions ${
|
|
158
|
+
c && c.length > 0 && console.log(
|
|
159
|
+
`Would assign roles ${c.join(", ")} to organization ${l.id}`
|
|
160
|
+
), a && a.length > 0 && console.log(
|
|
161
|
+
`Would grant permissions ${a.join(", ")} to organization ${l.id}`
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
-
async function
|
|
165
|
-
const
|
|
164
|
+
async function ve(t, e, n) {
|
|
165
|
+
const r = await t.adapters.userRoles.list(
|
|
166
166
|
e,
|
|
167
167
|
n,
|
|
168
168
|
void 0,
|
|
169
169
|
""
|
|
170
170
|
// Empty string for global roles
|
|
171
171
|
);
|
|
172
|
-
for (const
|
|
172
|
+
for (const a of r)
|
|
173
173
|
if ((await t.adapters.rolePermissions.list(
|
|
174
174
|
e,
|
|
175
|
-
|
|
175
|
+
a.id,
|
|
176
176
|
{ per_page: 1e3 }
|
|
177
177
|
)).some(
|
|
178
178
|
(i) => i.permission_name === "admin:organizations"
|
|
@@ -180,14 +180,14 @@ async function _e(t, e, n) {
|
|
|
180
180
|
return !0;
|
|
181
181
|
return !1;
|
|
182
182
|
}
|
|
183
|
-
async function
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
return
|
|
183
|
+
async function _e(t, e, n, r) {
|
|
184
|
+
const c = (await t.adapters.roles.list(e, {})).roles.find((o) => o.name === n);
|
|
185
|
+
if (c)
|
|
186
|
+
return c.id;
|
|
187
187
|
const s = await t.adapters.roles.create(e, {
|
|
188
188
|
name: n,
|
|
189
|
-
description:
|
|
190
|
-
}), i =
|
|
189
|
+
description: r
|
|
190
|
+
}), i = ce, p = ie.map((o) => ({
|
|
191
191
|
role_id: s.id,
|
|
192
192
|
resource_server_identifier: i,
|
|
193
193
|
permission_name: o.value
|
|
@@ -198,7 +198,7 @@ async function ye(t, e, n, a) {
|
|
|
198
198
|
p
|
|
199
199
|
), s.id;
|
|
200
200
|
}
|
|
201
|
-
const
|
|
201
|
+
const ye = [
|
|
202
202
|
"client_id",
|
|
203
203
|
"client_secret",
|
|
204
204
|
"app_secret",
|
|
@@ -208,22 +208,22 @@ const be = [
|
|
|
208
208
|
"twilio_token"
|
|
209
209
|
];
|
|
210
210
|
function L(t, e, n = () => !0) {
|
|
211
|
-
const { controlPlaneTenantId:
|
|
212
|
-
async function i(
|
|
213
|
-
return (await e(
|
|
211
|
+
const { controlPlaneTenantId: r, getChildTenantIds: a, getAdapters: c } = t, s = /* @__PURE__ */ new Map();
|
|
212
|
+
async function i(l, u, d) {
|
|
213
|
+
return (await e(l).list(u, {
|
|
214
214
|
q: `name:${d}`,
|
|
215
215
|
per_page: 1
|
|
216
216
|
}))[0] ?? null;
|
|
217
217
|
}
|
|
218
|
-
async function p(
|
|
219
|
-
const u = await
|
|
218
|
+
async function p(l) {
|
|
219
|
+
const u = await a(), d = e(await c(r));
|
|
220
220
|
await Promise.all(
|
|
221
221
|
u.map(async (m) => {
|
|
222
222
|
try {
|
|
223
|
-
const f = await
|
|
224
|
-
...d.transform(
|
|
223
|
+
const f = await c(m), w = e(f), h = {
|
|
224
|
+
...d.transform(l),
|
|
225
225
|
is_system: !0
|
|
226
|
-
}, v = await i(f, m,
|
|
226
|
+
}, v = await i(f, m, l.name), _ = v ? w.getId(v) : void 0;
|
|
227
227
|
if (v && _) {
|
|
228
228
|
const A = w.preserveOnUpdate ? w.preserveOnUpdate(v, h) : h;
|
|
229
229
|
await w.update(m, _, A);
|
|
@@ -231,23 +231,23 @@ function L(t, e, n = () => !0) {
|
|
|
231
231
|
await w.create(m, h);
|
|
232
232
|
} catch (f) {
|
|
233
233
|
console.error(
|
|
234
|
-
`Failed to sync ${d.listKey} "${
|
|
234
|
+
`Failed to sync ${d.listKey} "${l.name}" to tenant "${m}":`,
|
|
235
235
|
f
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
})
|
|
239
239
|
);
|
|
240
240
|
}
|
|
241
|
-
async function o(
|
|
242
|
-
const u = await
|
|
241
|
+
async function o(l) {
|
|
242
|
+
const u = await a();
|
|
243
243
|
await Promise.all(
|
|
244
244
|
u.map(async (d) => {
|
|
245
245
|
try {
|
|
246
|
-
const m = await
|
|
246
|
+
const m = await c(d), f = e(m), w = await i(m, d, l), g = w ? f.getId(w) : void 0;
|
|
247
247
|
w && g && await f.remove(d, g);
|
|
248
248
|
} catch (m) {
|
|
249
249
|
console.error(
|
|
250
|
-
`Failed to delete entity "${
|
|
250
|
+
`Failed to delete entity "${l}" from tenant "${d}":`,
|
|
251
251
|
m
|
|
252
252
|
);
|
|
253
253
|
}
|
|
@@ -255,39 +255,39 @@ function L(t, e, n = () => !0) {
|
|
|
255
255
|
);
|
|
256
256
|
}
|
|
257
257
|
return {
|
|
258
|
-
afterCreate: async (
|
|
259
|
-
|
|
258
|
+
afterCreate: async (l, u) => {
|
|
259
|
+
l.tenantId === r && n(u) && await p(u);
|
|
260
260
|
},
|
|
261
|
-
afterUpdate: async (
|
|
262
|
-
|
|
261
|
+
afterUpdate: async (l, u, d) => {
|
|
262
|
+
l.tenantId === r && n(d) && await p(d);
|
|
263
263
|
},
|
|
264
|
-
beforeDelete: async (
|
|
265
|
-
if (
|
|
266
|
-
const m = await e(
|
|
264
|
+
beforeDelete: async (l, u) => {
|
|
265
|
+
if (l.tenantId !== r) return;
|
|
266
|
+
const m = await e(l.adapters).get(l.tenantId, u);
|
|
267
267
|
m && n(m) && s.set(u, m);
|
|
268
268
|
},
|
|
269
|
-
afterDelete: async (
|
|
270
|
-
if (
|
|
269
|
+
afterDelete: async (l, u) => {
|
|
270
|
+
if (l.tenantId !== r) return;
|
|
271
271
|
const d = s.get(u);
|
|
272
272
|
d && (s.delete(u), await o(d.name));
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
function V(t, e, n = () => !0) {
|
|
277
|
-
const { controlPlaneTenantId:
|
|
277
|
+
const { controlPlaneTenantId: r, getControlPlaneAdapters: a, getAdapters: c } = t;
|
|
278
278
|
return {
|
|
279
279
|
async afterCreate(s, i) {
|
|
280
|
-
if (i.id !==
|
|
280
|
+
if (i.id !== r)
|
|
281
281
|
try {
|
|
282
|
-
const p = await
|
|
283
|
-
(m) =>
|
|
284
|
-
|
|
282
|
+
const p = await a(), o = await c(i.id), l = e(p), u = e(o), d = await F(
|
|
283
|
+
(m) => l.listPaginated(r, m),
|
|
284
|
+
l.listKey,
|
|
285
285
|
{ cursorField: "id", pageSize: 100 }
|
|
286
286
|
);
|
|
287
287
|
await Promise.all(
|
|
288
288
|
d.filter((m) => n(m)).map(async (m) => {
|
|
289
289
|
try {
|
|
290
|
-
const f =
|
|
290
|
+
const f = l.transform(m);
|
|
291
291
|
await u.create(i.id, {
|
|
292
292
|
...f,
|
|
293
293
|
is_system: !0
|
|
@@ -309,16 +309,17 @@ function V(t, e, n = () => !0) {
|
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
|
-
const
|
|
312
|
+
const k = (t) => ({
|
|
313
313
|
list: async (e, n) => (await t.resourceServers.list(e, n)).resource_servers,
|
|
314
314
|
listPaginated: (e, n) => t.resourceServers.list(e, n),
|
|
315
315
|
get: (e, n) => t.resourceServers.get(e, n),
|
|
316
316
|
create: (e, n) => t.resourceServers.create(e, n),
|
|
317
|
-
update: (e, n,
|
|
317
|
+
update: (e, n, r) => t.resourceServers.update(e, n, r),
|
|
318
318
|
remove: (e, n) => t.resourceServers.remove(e, n),
|
|
319
319
|
listKey: "resource_servers",
|
|
320
320
|
getId: (e) => e.id,
|
|
321
321
|
transform: (e) => ({
|
|
322
|
+
id: e.id,
|
|
322
323
|
name: e.name,
|
|
323
324
|
identifier: e.identifier,
|
|
324
325
|
scopes: e.scopes,
|
|
@@ -326,33 +327,35 @@ const H = (t) => ({
|
|
|
326
327
|
token_lifetime: e.token_lifetime,
|
|
327
328
|
token_lifetime_for_web: e.token_lifetime_for_web
|
|
328
329
|
})
|
|
329
|
-
}),
|
|
330
|
+
}), H = (t) => ({
|
|
330
331
|
list: async (e, n) => (await t.roles.list(e, n)).roles,
|
|
331
332
|
listPaginated: (e, n) => t.roles.list(e, n),
|
|
332
333
|
get: (e, n) => t.roles.get(e, n),
|
|
333
334
|
create: (e, n) => t.roles.create(e, n),
|
|
334
|
-
update: (e, n,
|
|
335
|
+
update: (e, n, r) => t.roles.update(e, n, r),
|
|
335
336
|
remove: (e, n) => t.roles.remove(e, n),
|
|
336
337
|
listKey: "roles",
|
|
337
338
|
getId: (e) => e.id,
|
|
338
339
|
transform: (e) => ({
|
|
340
|
+
id: e.id,
|
|
339
341
|
name: e.name,
|
|
340
342
|
description: e.description
|
|
341
343
|
})
|
|
342
|
-
}),
|
|
344
|
+
}), x = (t) => ({
|
|
343
345
|
list: async (e, n) => (await t.connections.list(e, n)).connections,
|
|
344
346
|
listPaginated: (e, n) => t.connections.list(e, n),
|
|
345
347
|
get: (e, n) => t.connections.get(e, n),
|
|
346
348
|
create: (e, n) => t.connections.create(e, n),
|
|
347
|
-
update: (e, n,
|
|
349
|
+
update: (e, n, r) => t.connections.update(e, n, r),
|
|
348
350
|
remove: (e, n) => t.connections.remove(e, n),
|
|
349
351
|
listKey: "connections",
|
|
350
352
|
getId: (e) => e.id,
|
|
351
353
|
transform: (e) => {
|
|
352
354
|
const n = e.options ? { ...e.options } : {};
|
|
353
|
-
for (const
|
|
354
|
-
delete n[
|
|
355
|
+
for (const r of ye)
|
|
356
|
+
delete n[r];
|
|
355
357
|
return {
|
|
358
|
+
id: e.id,
|
|
356
359
|
name: e.name,
|
|
357
360
|
display_name: e.display_name,
|
|
358
361
|
strategy: e.strategy,
|
|
@@ -365,52 +368,52 @@ const H = (t) => ({
|
|
|
365
368
|
};
|
|
366
369
|
},
|
|
367
370
|
preserveOnUpdate: (e, n) => {
|
|
368
|
-
const
|
|
371
|
+
const r = e.options || {};
|
|
369
372
|
return {
|
|
370
373
|
...n,
|
|
371
374
|
options: {
|
|
372
375
|
...n.options,
|
|
373
|
-
client_id:
|
|
374
|
-
client_secret:
|
|
375
|
-
app_secret:
|
|
376
|
-
kid:
|
|
377
|
-
team_id:
|
|
378
|
-
twilio_sid:
|
|
379
|
-
twilio_token:
|
|
376
|
+
client_id: r.client_id,
|
|
377
|
+
client_secret: r.client_secret,
|
|
378
|
+
app_secret: r.app_secret,
|
|
379
|
+
kid: r.kid,
|
|
380
|
+
team_id: r.team_id,
|
|
381
|
+
twilio_sid: r.twilio_sid,
|
|
382
|
+
twilio_token: r.twilio_token
|
|
380
383
|
}
|
|
381
384
|
};
|
|
382
385
|
}
|
|
383
386
|
});
|
|
384
|
-
function
|
|
385
|
-
const { sync: e = {}, filters: n = {} } = t,
|
|
387
|
+
function be(t) {
|
|
388
|
+
const { sync: e = {}, filters: n = {} } = t, r = e.resourceServers ?? !0, a = e.roles ?? !0, c = e.connections ?? !0, s = r ? L(
|
|
386
389
|
t,
|
|
387
|
-
|
|
390
|
+
k,
|
|
388
391
|
n.resourceServers
|
|
389
|
-
) : void 0, i =
|
|
392
|
+
) : void 0, i = a ? L(
|
|
390
393
|
t,
|
|
391
|
-
|
|
394
|
+
H,
|
|
392
395
|
n.roles
|
|
393
|
-
) : void 0, p =
|
|
396
|
+
) : void 0, p = c ? L(
|
|
394
397
|
t,
|
|
395
|
-
|
|
398
|
+
x,
|
|
396
399
|
n.connections
|
|
397
|
-
) : void 0, o =
|
|
400
|
+
) : void 0, o = r ? V(
|
|
398
401
|
t,
|
|
399
|
-
|
|
402
|
+
k,
|
|
400
403
|
n.resourceServers
|
|
401
|
-
) : void 0,
|
|
404
|
+
) : void 0, l = a ? V(
|
|
402
405
|
t,
|
|
403
|
-
|
|
406
|
+
H,
|
|
404
407
|
n.roles
|
|
405
|
-
) : void 0, u =
|
|
408
|
+
) : void 0, u = c ? V(
|
|
406
409
|
t,
|
|
407
|
-
|
|
410
|
+
x,
|
|
408
411
|
n.connections
|
|
409
|
-
) : void 0, d =
|
|
412
|
+
) : void 0, d = a ? {
|
|
410
413
|
async afterCreate(w, g) {
|
|
411
414
|
var h;
|
|
412
415
|
if (g.id !== t.controlPlaneTenantId) {
|
|
413
|
-
await ((h =
|
|
416
|
+
await ((h = l == null ? void 0 : l.afterCreate) == null ? void 0 : h.call(l, w, g));
|
|
414
417
|
try {
|
|
415
418
|
const v = await t.getControlPlaneAdapters(), _ = await t.getAdapters(g.id), A = await F(
|
|
416
419
|
(b) => v.roles.list(
|
|
@@ -488,7 +491,7 @@ function Ce(t) {
|
|
|
488
491
|
async afterCreate(w, g) {
|
|
489
492
|
const h = [
|
|
490
493
|
o == null ? void 0 : o.afterCreate,
|
|
491
|
-
(d == null ? void 0 : d.afterCreate) ?? (
|
|
494
|
+
(d == null ? void 0 : d.afterCreate) ?? (l == null ? void 0 : l.afterCreate),
|
|
492
495
|
u == null ? void 0 : u.afterCreate
|
|
493
496
|
], v = [];
|
|
494
497
|
for (const _ of h)
|
|
@@ -509,14 +512,14 @@ function Ce(t) {
|
|
|
509
512
|
};
|
|
510
513
|
}
|
|
511
514
|
function W(t, e) {
|
|
512
|
-
const n = new
|
|
515
|
+
const n = new de();
|
|
513
516
|
return n.openapi(
|
|
514
517
|
B({
|
|
515
518
|
tags: ["tenants"],
|
|
516
519
|
method: "get",
|
|
517
520
|
path: "/",
|
|
518
521
|
request: {
|
|
519
|
-
query:
|
|
522
|
+
query: ue
|
|
520
523
|
},
|
|
521
524
|
security: [
|
|
522
525
|
{
|
|
@@ -528,7 +531,7 @@ function W(t, e) {
|
|
|
528
531
|
content: {
|
|
529
532
|
"application/json": {
|
|
530
533
|
schema: z.object({
|
|
531
|
-
tenants: z.array(
|
|
534
|
+
tenants: z.array(E),
|
|
532
535
|
start: z.number().optional(),
|
|
533
536
|
limit: z.number().optional(),
|
|
534
537
|
length: z.number().optional()
|
|
@@ -539,26 +542,26 @@ function W(t, e) {
|
|
|
539
542
|
}
|
|
540
543
|
}
|
|
541
544
|
}),
|
|
542
|
-
async (
|
|
545
|
+
async (r) => {
|
|
543
546
|
var m, f, w, g;
|
|
544
|
-
const
|
|
545
|
-
if (
|
|
546
|
-
const h = await
|
|
547
|
-
page:
|
|
547
|
+
const a = r.req.valid("query"), { page: c, per_page: s, include_totals: i, q: p } = a, o = r.var.user, l = (o == null ? void 0 : o.permissions) || [];
|
|
548
|
+
if (l.includes("auth:read") || l.includes("admin:organizations")) {
|
|
549
|
+
const h = await r.env.data.tenants.list({
|
|
550
|
+
page: c,
|
|
548
551
|
per_page: s,
|
|
549
552
|
include_totals: i,
|
|
550
553
|
q: p
|
|
551
554
|
});
|
|
552
|
-
return i ?
|
|
555
|
+
return i ? r.json({
|
|
553
556
|
tenants: h.tenants,
|
|
554
557
|
start: ((m = h.totals) == null ? void 0 : m.start) ?? 0,
|
|
555
558
|
limit: ((f = h.totals) == null ? void 0 : f.limit) ?? s,
|
|
556
559
|
length: h.tenants.length
|
|
557
|
-
}) :
|
|
560
|
+
}) : r.json({ tenants: h.tenants });
|
|
558
561
|
}
|
|
559
562
|
if (t.accessControl && (o != null && o.sub)) {
|
|
560
563
|
const h = t.accessControl.controlPlaneTenantId, _ = (await F(
|
|
561
|
-
(D) =>
|
|
564
|
+
(D) => r.env.data.userOrganizations.listUserOrganizations(
|
|
562
565
|
h,
|
|
563
566
|
o.sub,
|
|
564
567
|
D
|
|
@@ -566,45 +569,45 @@ function W(t, e) {
|
|
|
566
569
|
"organizations"
|
|
567
570
|
)).map((D) => D.name);
|
|
568
571
|
if (_.length === 0)
|
|
569
|
-
return i ?
|
|
572
|
+
return i ? r.json({
|
|
570
573
|
tenants: [],
|
|
571
574
|
start: 0,
|
|
572
575
|
limit: s ?? 50,
|
|
573
576
|
length: 0
|
|
574
|
-
}) :
|
|
575
|
-
const A = _.length, $ =
|
|
577
|
+
}) : r.json({ tenants: [] });
|
|
578
|
+
const A = _.length, $ = c ?? 0, b = s ?? 50, y = $ * b, C = _.slice(y, y + b);
|
|
576
579
|
if (C.length === 0)
|
|
577
|
-
return i ?
|
|
580
|
+
return i ? r.json({
|
|
578
581
|
tenants: [],
|
|
579
582
|
start: y,
|
|
580
583
|
limit: b,
|
|
581
584
|
length: A
|
|
582
|
-
}) :
|
|
583
|
-
const P = C.map((D) => `id:${D}`).join(" OR "), q = p ? `(${P}) AND (${p})` : P, R = await
|
|
585
|
+
}) : r.json({ tenants: [] });
|
|
586
|
+
const P = C.map((D) => `id:${D}`).join(" OR "), q = p ? `(${P}) AND (${p})` : P, R = await r.env.data.tenants.list({
|
|
584
587
|
q,
|
|
585
588
|
per_page: b,
|
|
586
589
|
include_totals: !1
|
|
587
590
|
// We calculate totals from accessibleTenantIds
|
|
588
591
|
});
|
|
589
|
-
return i ?
|
|
592
|
+
return i ? r.json({
|
|
590
593
|
tenants: R.tenants,
|
|
591
594
|
start: y,
|
|
592
595
|
limit: b,
|
|
593
596
|
length: A
|
|
594
|
-
}) :
|
|
597
|
+
}) : r.json({ tenants: R.tenants });
|
|
595
598
|
}
|
|
596
|
-
const d = await
|
|
597
|
-
page:
|
|
599
|
+
const d = await r.env.data.tenants.list({
|
|
600
|
+
page: c,
|
|
598
601
|
per_page: s,
|
|
599
602
|
include_totals: i,
|
|
600
603
|
q: p
|
|
601
604
|
});
|
|
602
|
-
return i ?
|
|
605
|
+
return i ? r.json({
|
|
603
606
|
tenants: d.tenants,
|
|
604
607
|
start: ((w = d.totals) == null ? void 0 : w.start) ?? 0,
|
|
605
608
|
limit: ((g = d.totals) == null ? void 0 : g.limit) ?? s,
|
|
606
609
|
length: d.tenants.length
|
|
607
|
-
}) :
|
|
610
|
+
}) : r.json({ tenants: d.tenants });
|
|
608
611
|
}
|
|
609
612
|
), n.openapi(
|
|
610
613
|
B({
|
|
@@ -615,7 +618,7 @@ function W(t, e) {
|
|
|
615
618
|
body: {
|
|
616
619
|
content: {
|
|
617
620
|
"application/json": {
|
|
618
|
-
schema:
|
|
621
|
+
schema: me
|
|
619
622
|
}
|
|
620
623
|
}
|
|
621
624
|
}
|
|
@@ -629,7 +632,7 @@ function W(t, e) {
|
|
|
629
632
|
201: {
|
|
630
633
|
content: {
|
|
631
634
|
"application/json": {
|
|
632
|
-
schema:
|
|
635
|
+
schema: E
|
|
633
636
|
}
|
|
634
637
|
},
|
|
635
638
|
description: "Tenant created"
|
|
@@ -642,21 +645,21 @@ function W(t, e) {
|
|
|
642
645
|
}
|
|
643
646
|
}
|
|
644
647
|
}),
|
|
645
|
-
async (
|
|
648
|
+
async (r) => {
|
|
646
649
|
var p, o;
|
|
647
|
-
const
|
|
648
|
-
if (!(
|
|
650
|
+
const a = r.var.user;
|
|
651
|
+
if (!(a != null && a.sub))
|
|
649
652
|
throw new S(401, {
|
|
650
653
|
message: "Authentication required to create tenants"
|
|
651
654
|
});
|
|
652
|
-
let
|
|
655
|
+
let c = r.req.valid("json");
|
|
653
656
|
const s = {
|
|
654
|
-
adapters:
|
|
655
|
-
ctx:
|
|
657
|
+
adapters: r.env.data,
|
|
658
|
+
ctx: r
|
|
656
659
|
};
|
|
657
|
-
(p = e.tenants) != null && p.beforeCreate && (
|
|
658
|
-
const i = await
|
|
659
|
-
return (o = e.tenants) != null && o.afterCreate && await e.tenants.afterCreate(s, i),
|
|
660
|
+
(p = e.tenants) != null && p.beforeCreate && (c = await e.tenants.beforeCreate(s, c));
|
|
661
|
+
const i = await r.env.data.tenants.create(c);
|
|
662
|
+
return (o = e.tenants) != null && o.afterCreate && await e.tenants.afterCreate(s, i), r.json(i, 201);
|
|
660
663
|
}
|
|
661
664
|
), n.openapi(
|
|
662
665
|
B({
|
|
@@ -685,44 +688,44 @@ function W(t, e) {
|
|
|
685
688
|
}
|
|
686
689
|
}
|
|
687
690
|
}),
|
|
688
|
-
async (
|
|
691
|
+
async (r) => {
|
|
689
692
|
var i, p;
|
|
690
|
-
const { id:
|
|
693
|
+
const { id: a } = r.req.valid("param");
|
|
691
694
|
if (t.accessControl) {
|
|
692
|
-
const o =
|
|
695
|
+
const o = r.var.user, l = t.accessControl.controlPlaneTenantId;
|
|
693
696
|
if (!(o != null && o.sub))
|
|
694
697
|
throw new S(401, {
|
|
695
698
|
message: "Authentication required"
|
|
696
699
|
});
|
|
697
|
-
if (
|
|
700
|
+
if (a === l)
|
|
698
701
|
throw new S(403, {
|
|
699
702
|
message: "Cannot delete the control plane"
|
|
700
703
|
});
|
|
701
704
|
if (!(await F(
|
|
702
|
-
(m) =>
|
|
703
|
-
|
|
705
|
+
(m) => r.env.data.userOrganizations.listUserOrganizations(
|
|
706
|
+
l,
|
|
704
707
|
o.sub,
|
|
705
708
|
m
|
|
706
709
|
),
|
|
707
710
|
"organizations"
|
|
708
|
-
)).some((m) => m.name ===
|
|
711
|
+
)).some((m) => m.name === a))
|
|
709
712
|
throw new S(403, {
|
|
710
713
|
message: "Access denied to this tenant"
|
|
711
714
|
});
|
|
712
715
|
}
|
|
713
|
-
if (!await
|
|
716
|
+
if (!await r.env.data.tenants.get(a))
|
|
714
717
|
throw new S(404, {
|
|
715
718
|
message: "Tenant not found"
|
|
716
719
|
});
|
|
717
720
|
const s = {
|
|
718
|
-
adapters:
|
|
719
|
-
ctx:
|
|
721
|
+
adapters: r.env.data,
|
|
722
|
+
ctx: r
|
|
720
723
|
};
|
|
721
|
-
return (i = e.tenants) != null && i.beforeDelete && await e.tenants.beforeDelete(s,
|
|
724
|
+
return (i = e.tenants) != null && i.beforeDelete && await e.tenants.beforeDelete(s, a), await r.env.data.tenants.remove(a), (p = e.tenants) != null && p.afterDelete && await e.tenants.afterDelete(s, a), r.body(null, 204);
|
|
722
725
|
}
|
|
723
726
|
), n;
|
|
724
727
|
}
|
|
725
|
-
function
|
|
728
|
+
function Ce(t) {
|
|
726
729
|
const e = [
|
|
727
730
|
{
|
|
728
731
|
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
@@ -731,27 +734,27 @@ function Ae(t) {
|
|
|
731
734
|
{ pattern: /\/api\/v2\/roles\/([^/]+)$/, type: "role" },
|
|
732
735
|
{ pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
|
|
733
736
|
];
|
|
734
|
-
for (const { pattern: n, type:
|
|
735
|
-
const
|
|
736
|
-
if (
|
|
737
|
-
return { type:
|
|
737
|
+
for (const { pattern: n, type: r } of e) {
|
|
738
|
+
const a = t.match(n);
|
|
739
|
+
if (a && a[1])
|
|
740
|
+
return { type: r, id: a[1] };
|
|
738
741
|
}
|
|
739
742
|
return null;
|
|
740
743
|
}
|
|
741
|
-
async function
|
|
744
|
+
async function Ae(t, e, n) {
|
|
742
745
|
try {
|
|
743
746
|
switch (n.type) {
|
|
744
747
|
case "resource_server": {
|
|
745
|
-
const
|
|
746
|
-
return (
|
|
748
|
+
const r = await t.resourceServers.get(e, n.id);
|
|
749
|
+
return (r == null ? void 0 : r.is_system) === !0;
|
|
747
750
|
}
|
|
748
751
|
case "role": {
|
|
749
|
-
const
|
|
750
|
-
return (
|
|
752
|
+
const r = await t.roles.get(e, n.id);
|
|
753
|
+
return (r == null ? void 0 : r.is_system) === !0;
|
|
751
754
|
}
|
|
752
755
|
case "connection": {
|
|
753
|
-
const
|
|
754
|
-
return (
|
|
756
|
+
const r = await t.connections.get(e, n.id);
|
|
757
|
+
return (r == null ? void 0 : r.is_system) === !0;
|
|
755
758
|
}
|
|
756
759
|
default:
|
|
757
760
|
return !1;
|
|
@@ -760,43 +763,43 @@ async function Te(t, e, n) {
|
|
|
760
763
|
return !1;
|
|
761
764
|
}
|
|
762
765
|
}
|
|
763
|
-
function
|
|
766
|
+
function Te(t) {
|
|
764
767
|
return {
|
|
765
768
|
resource_server: "resource server",
|
|
766
769
|
role: "role",
|
|
767
770
|
connection: "connection"
|
|
768
771
|
}[t];
|
|
769
772
|
}
|
|
770
|
-
function
|
|
773
|
+
function Se() {
|
|
771
774
|
return async (t, e) => {
|
|
772
775
|
if (!["PATCH", "PUT", "DELETE"].includes(t.req.method))
|
|
773
776
|
return e();
|
|
774
|
-
const n =
|
|
777
|
+
const n = Ce(t.req.path);
|
|
775
778
|
if (!n)
|
|
776
779
|
return e();
|
|
777
|
-
const
|
|
778
|
-
if (!
|
|
780
|
+
const r = t.var.tenant_id || t.req.header("x-tenant-id") || t.req.header("tenant-id");
|
|
781
|
+
if (!r)
|
|
779
782
|
return e();
|
|
780
|
-
if (await
|
|
783
|
+
if (await Ae(t.env.data, r, n))
|
|
781
784
|
throw new S(403, {
|
|
782
|
-
message: `This ${
|
|
785
|
+
message: `This ${Te(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.`
|
|
783
786
|
});
|
|
784
787
|
return e();
|
|
785
788
|
};
|
|
786
789
|
}
|
|
787
|
-
function
|
|
788
|
-
const { controlPlaneTenantId: n, controlPlaneClientId:
|
|
790
|
+
function te(t, e) {
|
|
791
|
+
const { controlPlaneTenantId: n, controlPlaneClientId: r } = e;
|
|
789
792
|
return {
|
|
790
793
|
...t,
|
|
791
794
|
legacyClients: {
|
|
792
795
|
...t.legacyClients,
|
|
793
|
-
get: async (
|
|
796
|
+
get: async (a) => {
|
|
794
797
|
var u;
|
|
795
|
-
const
|
|
796
|
-
if (!
|
|
798
|
+
const c = await t.legacyClients.get(a);
|
|
799
|
+
if (!c)
|
|
797
800
|
return null;
|
|
798
|
-
const s =
|
|
799
|
-
|
|
801
|
+
const s = r ? await t.legacyClients.get(r) : void 0, i = await t.connections.list(
|
|
802
|
+
c.tenant.id
|
|
800
803
|
), p = n ? await t.connections.list(n) : { connections: [] }, o = i.connections.map((d) => {
|
|
801
804
|
var w;
|
|
802
805
|
const m = (w = p.connections) == null ? void 0 : w.find(
|
|
@@ -812,41 +815,41 @@ function ne(t, e) {
|
|
|
812
815
|
...m.options || {},
|
|
813
816
|
...d.options
|
|
814
817
|
}), f;
|
|
815
|
-
}).filter((d) => d),
|
|
818
|
+
}).filter((d) => d), l = {
|
|
816
819
|
...(s == null ? void 0 : s.tenant) || {},
|
|
817
|
-
...
|
|
820
|
+
...c.tenant
|
|
818
821
|
};
|
|
819
|
-
return !
|
|
820
|
-
...
|
|
822
|
+
return !c.tenant.audience && ((u = s == null ? void 0 : s.tenant) != null && u.audience) && (l.audience = s.tenant.audience), {
|
|
823
|
+
...c,
|
|
821
824
|
web_origins: [
|
|
822
825
|
...(s == null ? void 0 : s.web_origins) || [],
|
|
823
|
-
...
|
|
826
|
+
...c.web_origins || []
|
|
824
827
|
],
|
|
825
828
|
allowed_logout_urls: [
|
|
826
829
|
...(s == null ? void 0 : s.allowed_logout_urls) || [],
|
|
827
|
-
...
|
|
830
|
+
...c.allowed_logout_urls || []
|
|
828
831
|
],
|
|
829
832
|
callbacks: [
|
|
830
833
|
...(s == null ? void 0 : s.callbacks) || [],
|
|
831
|
-
...
|
|
834
|
+
...c.callbacks || []
|
|
832
835
|
],
|
|
833
836
|
connections: o,
|
|
834
|
-
tenant:
|
|
837
|
+
tenant: l
|
|
835
838
|
};
|
|
836
839
|
}
|
|
837
840
|
},
|
|
838
841
|
connections: {
|
|
839
842
|
...t.connections,
|
|
840
|
-
get: async (
|
|
843
|
+
get: async (a, c) => {
|
|
841
844
|
const s = await t.connections.get(
|
|
842
|
-
|
|
843
|
-
|
|
845
|
+
a,
|
|
846
|
+
c
|
|
844
847
|
);
|
|
845
848
|
if (!s || !n)
|
|
846
849
|
return s;
|
|
847
850
|
const i = await t.connections.get(
|
|
848
851
|
n,
|
|
849
|
-
|
|
852
|
+
c
|
|
850
853
|
);
|
|
851
854
|
if (!i)
|
|
852
855
|
return s;
|
|
@@ -859,23 +862,23 @@ function ne(t, e) {
|
|
|
859
862
|
...s.options
|
|
860
863
|
}), p;
|
|
861
864
|
},
|
|
862
|
-
list: async (
|
|
863
|
-
const s = await t.connections.list(
|
|
864
|
-
if (!n ||
|
|
865
|
+
list: async (a, c) => {
|
|
866
|
+
const s = await t.connections.list(a, c);
|
|
867
|
+
if (!n || a === n)
|
|
865
868
|
return s;
|
|
866
869
|
const i = await t.connections.list(n), p = s.connections.map((o) => {
|
|
867
870
|
var d;
|
|
868
|
-
const
|
|
871
|
+
const l = (d = i.connections) == null ? void 0 : d.find(
|
|
869
872
|
(m) => m.name === o.name
|
|
870
873
|
);
|
|
871
|
-
if (!(
|
|
874
|
+
if (!(l != null && l.options))
|
|
872
875
|
return o;
|
|
873
876
|
const u = G.parse({
|
|
874
|
-
...
|
|
877
|
+
...l,
|
|
875
878
|
...o
|
|
876
879
|
});
|
|
877
880
|
return u.options = K.parse({
|
|
878
|
-
...
|
|
881
|
+
...l.options || {},
|
|
879
882
|
...o.options
|
|
880
883
|
}), u;
|
|
881
884
|
});
|
|
@@ -894,49 +897,49 @@ function ne(t, e) {
|
|
|
894
897
|
// They remain part of ...baseAdapters and can be properly wrapped by caching.
|
|
895
898
|
};
|
|
896
899
|
}
|
|
897
|
-
function
|
|
898
|
-
return
|
|
900
|
+
function Ie(t, e) {
|
|
901
|
+
return te(t, e);
|
|
899
902
|
}
|
|
900
|
-
const
|
|
901
|
-
function
|
|
903
|
+
const Me = te, Ne = Ie;
|
|
904
|
+
function Pe(t) {
|
|
902
905
|
return async (e, n) => {
|
|
903
906
|
if (!t.accessControl)
|
|
904
907
|
return n();
|
|
905
|
-
const
|
|
906
|
-
if (!
|
|
908
|
+
const r = e.var.tenant_id, a = e.var.organization_id;
|
|
909
|
+
if (!r)
|
|
907
910
|
throw new S(400, {
|
|
908
911
|
message: "Tenant ID not found in request"
|
|
909
912
|
});
|
|
910
|
-
if (!
|
|
911
|
-
r,
|
|
913
|
+
if (!fe(
|
|
912
914
|
a,
|
|
915
|
+
r,
|
|
913
916
|
t.accessControl.controlPlaneTenantId
|
|
914
917
|
))
|
|
915
918
|
throw new S(403, {
|
|
916
|
-
message: `Access denied to tenant ${
|
|
919
|
+
message: `Access denied to tenant ${r}`
|
|
917
920
|
});
|
|
918
921
|
return n();
|
|
919
922
|
};
|
|
920
923
|
}
|
|
921
|
-
function
|
|
924
|
+
function De(t) {
|
|
922
925
|
return async (e, n) => {
|
|
923
926
|
if (!t.subdomainRouting)
|
|
924
927
|
return n();
|
|
925
928
|
const {
|
|
926
|
-
baseDomain:
|
|
927
|
-
reservedSubdomains:
|
|
928
|
-
resolveSubdomain:
|
|
929
|
+
baseDomain: r,
|
|
930
|
+
reservedSubdomains: a = [],
|
|
931
|
+
resolveSubdomain: c
|
|
929
932
|
} = t.subdomainRouting, s = e.req.header("host") || "";
|
|
930
933
|
let i = null;
|
|
931
|
-
if (s.endsWith(
|
|
932
|
-
const o = s.slice(0, -(
|
|
934
|
+
if (s.endsWith(r)) {
|
|
935
|
+
const o = s.slice(0, -(r.length + 1));
|
|
933
936
|
o && !o.includes(".") && (i = o);
|
|
934
937
|
}
|
|
935
|
-
if (i &&
|
|
938
|
+
if (i && a.includes(i) && (i = null), !i)
|
|
936
939
|
return t.accessControl && e.set("tenant_id", t.accessControl.controlPlaneTenantId), n();
|
|
937
940
|
let p = null;
|
|
938
|
-
if (
|
|
939
|
-
p = await
|
|
941
|
+
if (c)
|
|
942
|
+
p = await c(i);
|
|
940
943
|
else if (t.subdomainRouting.useOrganizations !== !1 && t.accessControl)
|
|
941
944
|
try {
|
|
942
945
|
const o = await e.env.data.organizations.get(
|
|
@@ -953,22 +956,22 @@ function $e(t) {
|
|
|
953
956
|
return e.set("tenant_id", p), n();
|
|
954
957
|
};
|
|
955
958
|
}
|
|
956
|
-
function
|
|
959
|
+
function $e(t) {
|
|
957
960
|
return async (e, n) => {
|
|
958
961
|
if (!t.databaseIsolation)
|
|
959
962
|
return n();
|
|
960
|
-
const
|
|
961
|
-
if (!
|
|
963
|
+
const r = e.var.tenant_id;
|
|
964
|
+
if (!r)
|
|
962
965
|
throw new S(400, {
|
|
963
966
|
message: "Tenant ID not found in request"
|
|
964
967
|
});
|
|
965
968
|
try {
|
|
966
|
-
const
|
|
967
|
-
e.env.data =
|
|
968
|
-
} catch (
|
|
969
|
+
const a = await t.databaseIsolation.getAdapters(r);
|
|
970
|
+
e.env.data = a;
|
|
971
|
+
} catch (a) {
|
|
969
972
|
throw console.error(
|
|
970
|
-
`Failed to resolve database for tenant ${
|
|
971
|
-
|
|
973
|
+
`Failed to resolve database for tenant ${r}:`,
|
|
974
|
+
a
|
|
972
975
|
), new S(500, {
|
|
973
976
|
message: "Failed to resolve tenant database"
|
|
974
977
|
});
|
|
@@ -976,19 +979,19 @@ function ze(t) {
|
|
|
976
979
|
return n();
|
|
977
980
|
};
|
|
978
981
|
}
|
|
979
|
-
function
|
|
980
|
-
const e =
|
|
981
|
-
return async (
|
|
982
|
-
}), await n(
|
|
983
|
-
}), await a
|
|
984
|
-
}),
|
|
982
|
+
function ne(t) {
|
|
983
|
+
const e = De(t), n = Pe(t), r = $e(t);
|
|
984
|
+
return async (a, c) => (await e(a, async () => {
|
|
985
|
+
}), await n(a, async () => {
|
|
986
|
+
}), await r(a, async () => {
|
|
987
|
+
}), c());
|
|
985
988
|
}
|
|
986
|
-
function
|
|
989
|
+
function Ue(t) {
|
|
987
990
|
const e = j(t);
|
|
988
991
|
return {
|
|
989
992
|
name: "multi-tenancy",
|
|
990
993
|
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
991
|
-
middleware:
|
|
994
|
+
middleware: ne(t),
|
|
992
995
|
// Provide lifecycle hooks
|
|
993
996
|
hooks: e,
|
|
994
997
|
// Mount tenant management routes
|
|
@@ -1009,42 +1012,42 @@ function Be(t) {
|
|
|
1009
1012
|
};
|
|
1010
1013
|
}
|
|
1011
1014
|
function j(t) {
|
|
1012
|
-
const e = t.accessControl ?
|
|
1015
|
+
const e = t.accessControl ? pe(t.accessControl) : {}, n = t.databaseIsolation ? we(t.databaseIsolation) : {}, r = ge(t);
|
|
1013
1016
|
return {
|
|
1014
1017
|
...e,
|
|
1015
1018
|
...n,
|
|
1016
|
-
tenants:
|
|
1019
|
+
tenants: r
|
|
1017
1020
|
};
|
|
1018
1021
|
}
|
|
1019
|
-
function
|
|
1020
|
-
const e = new
|
|
1022
|
+
function ze(t) {
|
|
1023
|
+
const e = new ee(), n = j(t);
|
|
1021
1024
|
return e.route("/tenants", W(t, n)), e;
|
|
1022
1025
|
}
|
|
1023
|
-
function
|
|
1026
|
+
function Be(t) {
|
|
1024
1027
|
return {
|
|
1025
1028
|
hooks: j(t),
|
|
1026
|
-
middleware:
|
|
1027
|
-
app:
|
|
1029
|
+
middleware: ne(t),
|
|
1030
|
+
app: ze(t),
|
|
1028
1031
|
config: t
|
|
1029
1032
|
};
|
|
1030
1033
|
}
|
|
1031
|
-
function
|
|
1032
|
-
var A, $, b, y, C, P, q, R, D, Q, J, X, Y, Z
|
|
1034
|
+
function Ge(t) {
|
|
1035
|
+
var A, $, b, y, C, P, q, R, D, Q, J, X, Y, Z;
|
|
1033
1036
|
const {
|
|
1034
1037
|
controlPlaneTenantId: e = "control_plane",
|
|
1035
1038
|
sync: n,
|
|
1036
|
-
multiTenancy:
|
|
1037
|
-
entityHooks:
|
|
1038
|
-
...
|
|
1039
|
+
multiTenancy: r,
|
|
1040
|
+
entityHooks: a,
|
|
1041
|
+
...c
|
|
1039
1042
|
} = t, s = {
|
|
1040
|
-
...
|
|
1043
|
+
...r,
|
|
1041
1044
|
accessControl: {
|
|
1042
1045
|
controlPlaneTenantId: e,
|
|
1043
1046
|
requireOrganizationMatch: !1,
|
|
1044
1047
|
defaultPermissions: ["tenant:admin"],
|
|
1045
|
-
...
|
|
1048
|
+
...r == null ? void 0 : r.accessControl
|
|
1046
1049
|
}
|
|
1047
|
-
}, i = j(s), p = ((A =
|
|
1050
|
+
}, i = j(s), p = ((A = r == null ? void 0 : r.databaseIsolation) == null ? void 0 : A.getAdapters) ?? (async () => t.dataAdapter), { entityHooks: o, tenantHooks: l } = be({
|
|
1048
1051
|
controlPlaneTenantId: e,
|
|
1049
1052
|
getChildTenantIds: async () => (await F(
|
|
1050
1053
|
(T) => t.dataAdapter.tenants.list(T),
|
|
@@ -1057,11 +1060,11 @@ function Ke(t) {
|
|
|
1057
1060
|
});
|
|
1058
1061
|
function u(I, T) {
|
|
1059
1062
|
if (!(!I && !T))
|
|
1060
|
-
return I ? T ? async (...
|
|
1063
|
+
return I ? T ? async (...re) => {
|
|
1061
1064
|
const O = [];
|
|
1062
1065
|
for (const M of [I, T])
|
|
1063
1066
|
try {
|
|
1064
|
-
await M(...
|
|
1067
|
+
await M(...re);
|
|
1065
1068
|
} catch (N) {
|
|
1066
1069
|
O.push(N instanceof Error ? N : new Error(String(N)));
|
|
1067
1070
|
}
|
|
@@ -1074,92 +1077,88 @@ function Ke(t) {
|
|
|
1074
1077
|
} : I : T;
|
|
1075
1078
|
}
|
|
1076
1079
|
const d = {
|
|
1077
|
-
...
|
|
1080
|
+
...a,
|
|
1078
1081
|
resourceServers: o != null && o.resourceServers ? {
|
|
1079
|
-
...
|
|
1082
|
+
...a == null ? void 0 : a.resourceServers,
|
|
1080
1083
|
afterCreate: u(
|
|
1081
|
-
($ =
|
|
1084
|
+
($ = a == null ? void 0 : a.resourceServers) == null ? void 0 : $.afterCreate,
|
|
1082
1085
|
o.resourceServers.afterCreate
|
|
1083
1086
|
),
|
|
1084
1087
|
afterUpdate: u(
|
|
1085
|
-
(b =
|
|
1088
|
+
(b = a == null ? void 0 : a.resourceServers) == null ? void 0 : b.afterUpdate,
|
|
1086
1089
|
o.resourceServers.afterUpdate
|
|
1087
1090
|
),
|
|
1088
1091
|
beforeDelete: u(
|
|
1089
|
-
(y =
|
|
1092
|
+
(y = a == null ? void 0 : a.resourceServers) == null ? void 0 : y.beforeDelete,
|
|
1090
1093
|
o.resourceServers.beforeDelete
|
|
1091
1094
|
),
|
|
1092
1095
|
afterDelete: u(
|
|
1093
|
-
(C =
|
|
1096
|
+
(C = a == null ? void 0 : a.resourceServers) == null ? void 0 : C.afterDelete,
|
|
1094
1097
|
o.resourceServers.afterDelete
|
|
1095
1098
|
)
|
|
1096
|
-
} :
|
|
1099
|
+
} : a == null ? void 0 : a.resourceServers,
|
|
1097
1100
|
roles: o != null && o.roles ? {
|
|
1098
|
-
...
|
|
1101
|
+
...a == null ? void 0 : a.roles,
|
|
1099
1102
|
afterCreate: u(
|
|
1100
|
-
(P =
|
|
1103
|
+
(P = a == null ? void 0 : a.roles) == null ? void 0 : P.afterCreate,
|
|
1101
1104
|
o.roles.afterCreate
|
|
1102
1105
|
),
|
|
1103
1106
|
afterUpdate: u(
|
|
1104
|
-
(q =
|
|
1107
|
+
(q = a == null ? void 0 : a.roles) == null ? void 0 : q.afterUpdate,
|
|
1105
1108
|
o.roles.afterUpdate
|
|
1106
1109
|
),
|
|
1107
1110
|
beforeDelete: u(
|
|
1108
|
-
(R =
|
|
1111
|
+
(R = a == null ? void 0 : a.roles) == null ? void 0 : R.beforeDelete,
|
|
1109
1112
|
o.roles.beforeDelete
|
|
1110
1113
|
),
|
|
1111
1114
|
afterDelete: u(
|
|
1112
|
-
(D =
|
|
1115
|
+
(D = a == null ? void 0 : a.roles) == null ? void 0 : D.afterDelete,
|
|
1113
1116
|
o.roles.afterDelete
|
|
1114
1117
|
)
|
|
1115
|
-
} :
|
|
1118
|
+
} : a == null ? void 0 : a.roles,
|
|
1116
1119
|
connections: o != null && o.connections ? {
|
|
1117
|
-
...
|
|
1120
|
+
...a == null ? void 0 : a.connections,
|
|
1118
1121
|
afterCreate: u(
|
|
1119
|
-
(Q =
|
|
1122
|
+
(Q = a == null ? void 0 : a.connections) == null ? void 0 : Q.afterCreate,
|
|
1120
1123
|
o.connections.afterCreate
|
|
1121
1124
|
),
|
|
1122
1125
|
afterUpdate: u(
|
|
1123
|
-
(J =
|
|
1126
|
+
(J = a == null ? void 0 : a.connections) == null ? void 0 : J.afterUpdate,
|
|
1124
1127
|
o.connections.afterUpdate
|
|
1125
1128
|
),
|
|
1126
1129
|
beforeDelete: u(
|
|
1127
|
-
(X =
|
|
1130
|
+
(X = a == null ? void 0 : a.connections) == null ? void 0 : X.beforeDelete,
|
|
1128
1131
|
o.connections.beforeDelete
|
|
1129
1132
|
),
|
|
1130
1133
|
afterDelete: u(
|
|
1131
|
-
(Y =
|
|
1134
|
+
(Y = a == null ? void 0 : a.connections) == null ? void 0 : Y.afterDelete,
|
|
1132
1135
|
o.connections.afterDelete
|
|
1133
1136
|
)
|
|
1134
|
-
} :
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
(Z = r == null ? void 0 : r.tenants) == null ? void 0 : Z.afterCreate,
|
|
1139
|
-
c.afterCreate
|
|
1140
|
-
)
|
|
1141
|
-
} : r == null ? void 0 : r.tenants
|
|
1137
|
+
} : a == null ? void 0 : a.connections,
|
|
1138
|
+
// Note: tenant sync hooks are only attached to combinedTenantHooks (for router use)
|
|
1139
|
+
// to avoid duplicate execution. The entityHooks.tenants doesn't need the sync hook.
|
|
1140
|
+
tenants: a == null ? void 0 : a.tenants
|
|
1142
1141
|
}, m = {
|
|
1143
1142
|
...i,
|
|
1144
|
-
tenants:
|
|
1143
|
+
tenants: l ? {
|
|
1145
1144
|
...i.tenants,
|
|
1146
1145
|
afterCreate: u(
|
|
1147
|
-
(
|
|
1148
|
-
|
|
1146
|
+
(Z = i.tenants) == null ? void 0 : Z.afterCreate,
|
|
1147
|
+
l.afterCreate
|
|
1149
1148
|
)
|
|
1150
1149
|
} : i.tenants
|
|
1151
1150
|
}, f = W(
|
|
1152
1151
|
s,
|
|
1153
1152
|
m
|
|
1154
|
-
), w =
|
|
1155
|
-
...
|
|
1153
|
+
), w = le({
|
|
1154
|
+
...c,
|
|
1156
1155
|
entityHooks: d,
|
|
1157
1156
|
managementApiExtensions: [
|
|
1158
|
-
...
|
|
1157
|
+
...c.managementApiExtensions || [],
|
|
1159
1158
|
{ path: "/tenants", router: f }
|
|
1160
1159
|
]
|
|
1161
|
-
}), { app: g, managementApp: h, ...v } = w, _ = new
|
|
1162
|
-
return _.onError((I, T) => I instanceof S ? I.getResponse() : (console.error(I), T.json({ message: "Internal Server Error" }, 500))), _.use("/api/v2/*",
|
|
1160
|
+
}), { app: g, managementApp: h, ...v } = w, _ = new ee();
|
|
1161
|
+
return _.onError((I, T) => I instanceof S ? I.getResponse() : (console.error(I), T.json({ message: "Internal Server Error" }, 500))), _.use("/api/v2/*", Se()), _.route("/", g), {
|
|
1163
1162
|
app: _,
|
|
1164
1163
|
managementApp: h,
|
|
1165
1164
|
...v,
|
|
@@ -1168,24 +1167,24 @@ function Ke(t) {
|
|
|
1168
1167
|
};
|
|
1169
1168
|
}
|
|
1170
1169
|
export {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1170
|
+
pe as createAccessControlHooks,
|
|
1171
|
+
Pe as createAccessControlMiddleware,
|
|
1172
|
+
we as createDatabaseHooks,
|
|
1173
|
+
$e as createDatabaseMiddleware,
|
|
1174
|
+
ze as createMultiTenancy,
|
|
1176
1175
|
j as createMultiTenancyHooks,
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1176
|
+
ne as createMultiTenancyMiddleware,
|
|
1177
|
+
Ue as createMultiTenancyPlugin,
|
|
1178
|
+
Se as createProtectSyncedMiddleware,
|
|
1179
|
+
ge as createProvisioningHooks,
|
|
1180
|
+
te as createRuntimeFallbackAdapter,
|
|
1181
|
+
Me as createSettingsInheritanceAdapter,
|
|
1182
|
+
De as createSubdomainMiddleware,
|
|
1183
|
+
be as createSyncHooks,
|
|
1185
1184
|
W as createTenantsOpenAPIRouter,
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1185
|
+
Ge as init,
|
|
1186
|
+
Be as setupMultiTenancy,
|
|
1187
|
+
fe as validateTenantAccess,
|
|
1188
|
+
Ie as withRuntimeFallback,
|
|
1189
|
+
Ne as withSettingsInheritance
|
|
1191
1190
|
};
|