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