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