@authhero/multi-tenancy 14.22.0 → 14.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/multi-tenancy.mjs
CHANGED
|
@@ -1,1377 +1,861 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
console.error(
|
|
216
|
-
`Failed to delete entity "${s}" from tenant "${m}":`,
|
|
217
|
-
w
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
afterCreate: async (s, d) => {
|
|
225
|
-
s.tenantId === n && r(d) && await l(d);
|
|
226
|
-
},
|
|
227
|
-
afterUpdate: async (s, d, m) => {
|
|
228
|
-
s.tenantId === n && r(m) && await l(m);
|
|
229
|
-
},
|
|
230
|
-
beforeDelete: async (s, d) => {
|
|
231
|
-
if (s.tenantId !== n) return;
|
|
232
|
-
const w = await t(s.adapters).get(s.tenantId, d);
|
|
233
|
-
w && r(w) && c.set(d, w);
|
|
234
|
-
},
|
|
235
|
-
afterDelete: async (s, d) => {
|
|
236
|
-
if (s.tenantId !== n) return;
|
|
237
|
-
const m = c.get(d);
|
|
238
|
-
m && (c.delete(d), await u(m.name));
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
function W(e, t, r = () => !0) {
|
|
243
|
-
const { controlPlaneTenantId: n, getControlPlaneAdapters: a, getAdapters: o } = e;
|
|
244
|
-
return {
|
|
245
|
-
async afterCreate(c, i) {
|
|
246
|
-
if (i.id !== n)
|
|
247
|
-
try {
|
|
248
|
-
const l = await a(), u = await o(i.id), s = t(l), d = t(u), m = await q(
|
|
249
|
-
(w) => s.listPaginated(n, w),
|
|
250
|
-
s.listKey,
|
|
251
|
-
{ cursorField: "id", pageSize: 100 }
|
|
252
|
-
);
|
|
253
|
-
await Promise.all(
|
|
254
|
-
m.filter((w) => r(w)).map(async (w) => {
|
|
255
|
-
try {
|
|
256
|
-
const f = s.transform(w);
|
|
257
|
-
await d.create(i.id, {
|
|
258
|
-
...f,
|
|
259
|
-
is_system: !0
|
|
260
|
-
});
|
|
261
|
-
} catch (f) {
|
|
262
|
-
console.error(
|
|
263
|
-
`Failed to sync entity to new tenant "${i.id}":`,
|
|
264
|
-
f
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
);
|
|
269
|
-
} catch (l) {
|
|
270
|
-
console.error(
|
|
271
|
-
`Failed to sync entities to new tenant "${i.id}":`,
|
|
272
|
-
l
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
const L = (e) => ({
|
|
279
|
-
list: async (t, r) => (await e.resourceServers.list(t, r)).resource_servers,
|
|
280
|
-
listPaginated: (t, r) => e.resourceServers.list(t, r),
|
|
281
|
-
get: (t, r) => e.resourceServers.get(t, r),
|
|
282
|
-
create: (t, r) => e.resourceServers.create(t, r),
|
|
283
|
-
update: (t, r, n) => e.resourceServers.update(t, r, n),
|
|
284
|
-
remove: (t, r) => e.resourceServers.remove(t, r),
|
|
285
|
-
listKey: "resource_servers",
|
|
286
|
-
getId: (t) => t.id,
|
|
287
|
-
transform: (t) => ({
|
|
288
|
-
id: t.id,
|
|
289
|
-
name: t.name,
|
|
290
|
-
identifier: t.identifier,
|
|
291
|
-
scopes: t.scopes,
|
|
292
|
-
signing_alg: t.signing_alg,
|
|
293
|
-
token_lifetime: t.token_lifetime,
|
|
294
|
-
token_lifetime_for_web: t.token_lifetime_for_web
|
|
295
|
-
})
|
|
296
|
-
}), K = (e) => ({
|
|
297
|
-
list: async (t, r) => (await e.roles.list(t, r)).roles,
|
|
298
|
-
listPaginated: (t, r) => e.roles.list(t, r),
|
|
299
|
-
get: (t, r) => e.roles.get(t, r),
|
|
300
|
-
create: (t, r) => e.roles.create(t, r),
|
|
301
|
-
update: (t, r, n) => e.roles.update(t, r, n),
|
|
302
|
-
remove: (t, r) => e.roles.remove(t, r),
|
|
303
|
-
listKey: "roles",
|
|
304
|
-
getId: (t) => t.id,
|
|
305
|
-
transform: (t) => ({
|
|
306
|
-
id: t.id,
|
|
307
|
-
name: t.name,
|
|
308
|
-
description: t.description
|
|
309
|
-
})
|
|
1
|
+
import { Hono as e } from "hono";
|
|
2
|
+
import { MANAGEMENT_API_AUDIENCE as t, MANAGEMENT_API_SCOPES as n, auth0QuerySchema as r, connectionOptionsSchema as i, connectionSchema as a, deepMergePatch as o, fetchAll as s, init as c, tenantInsertSchema as l, tenantSchema as u } from "authhero";
|
|
3
|
+
import { OpenAPIHono as d, createRoute as f, z as p } from "@hono/zod-openapi";
|
|
4
|
+
//#region src/hooks/access-control.ts
|
|
5
|
+
function m(e) {
|
|
6
|
+
let { controlPlaneTenantId: t, requireOrganizationMatch: n = !0 } = e;
|
|
7
|
+
return { async onTenantAccessValidation(e, r) {
|
|
8
|
+
if (r === t) return !0;
|
|
9
|
+
if (n) {
|
|
10
|
+
let t = e.var.org_name, n = e.var.organization_id, i = t || n;
|
|
11
|
+
return i ? i.toLowerCase() === r.toLowerCase() : !1;
|
|
12
|
+
}
|
|
13
|
+
return !0;
|
|
14
|
+
} };
|
|
15
|
+
}
|
|
16
|
+
function h(e, t, n, r) {
|
|
17
|
+
if (t === n) return !0;
|
|
18
|
+
let i = r || e;
|
|
19
|
+
return i ? i.toLowerCase() === t.toLowerCase() : !1;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/hooks/database.ts
|
|
23
|
+
function g(e) {
|
|
24
|
+
return { async resolveDataAdapters(t) {
|
|
25
|
+
try {
|
|
26
|
+
return await e.getAdapters(t);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error(`Failed to resolve data adapters for tenant ${t}:`, e);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/hooks/provisioning.ts
|
|
35
|
+
function _(e) {
|
|
36
|
+
return `urn:authhero:tenant:${e.toLowerCase()}`;
|
|
37
|
+
}
|
|
38
|
+
function v(e) {
|
|
39
|
+
return {
|
|
40
|
+
async beforeCreate(e, t) {
|
|
41
|
+
return !t.audience && t.id ? {
|
|
42
|
+
...t,
|
|
43
|
+
audience: _(t.id)
|
|
44
|
+
} : t;
|
|
45
|
+
},
|
|
46
|
+
async afterCreate(t, n) {
|
|
47
|
+
let { accessControl: r, databaseIsolation: i } = e;
|
|
48
|
+
r && t.ctx && await y(t, n, r), i?.onProvision && await i.onProvision(n.id);
|
|
49
|
+
},
|
|
50
|
+
async beforeDelete(t, n) {
|
|
51
|
+
let { accessControl: r, databaseIsolation: i } = e;
|
|
52
|
+
if (r) try {
|
|
53
|
+
let e = (await t.adapters.organizations.list(r.controlPlaneTenantId)).organizations.find((e) => e.name === n);
|
|
54
|
+
e && await t.adapters.organizations.remove(r.controlPlaneTenantId, e.id);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.warn(`Failed to remove organization for tenant ${n}:`, e);
|
|
57
|
+
}
|
|
58
|
+
if (i?.onDeprovision) try {
|
|
59
|
+
await i.onDeprovision(n);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.warn(`Failed to deprovision database for tenant ${n}:`, e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function y(e, t, n) {
|
|
67
|
+
let { controlPlaneTenantId: r, defaultPermissions: i, defaultRoles: a, issuer: o, adminRoleName: s = "Tenant Admin", adminRoleDescription: c = "Full access to all tenant management operations", addCreatorToOrganization: l = !0 } = n, u = await e.adapters.organizations.create(r, {
|
|
68
|
+
name: t.id,
|
|
69
|
+
display_name: t.friendly_name || t.id
|
|
70
|
+
}), d;
|
|
71
|
+
if (o && (d = await x(e, r, s, c)), l && e.ctx) {
|
|
72
|
+
let t = e.ctx.var.user;
|
|
73
|
+
if (t?.sub && !await b(e, r, t.sub)) try {
|
|
74
|
+
await e.adapters.userOrganizations.create(r, {
|
|
75
|
+
user_id: t.sub,
|
|
76
|
+
organization_id: u.id
|
|
77
|
+
}), d && await e.adapters.userRoles.create(r, t.sub, d, u.id);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.warn(`Failed to add creator ${t.sub} to organization ${u.id}:`, e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
a && a.length > 0 && console.log(`Would assign roles ${a.join(", ")} to organization ${u.id}`), i && i.length > 0 && console.log(`Would grant permissions ${i.join(", ")} to organization ${u.id}`);
|
|
83
|
+
}
|
|
84
|
+
async function b(e, t, n) {
|
|
85
|
+
let r = await e.adapters.userRoles.list(t, n, void 0, "");
|
|
86
|
+
for (let n of r) if ((await e.adapters.rolePermissions.list(t, n.id, { per_page: 1e3 })).some((e) => e.permission_name === "admin:organizations")) return !0;
|
|
87
|
+
return !1;
|
|
88
|
+
}
|
|
89
|
+
async function x(e, r, i, a) {
|
|
90
|
+
let o = (await e.adapters.roles.list(r, {})).roles.find((e) => e.name === i);
|
|
91
|
+
if (o) return o.id;
|
|
92
|
+
let s = await e.adapters.roles.create(r, {
|
|
93
|
+
name: i,
|
|
94
|
+
description: a
|
|
95
|
+
}), c = t, l = n.map((e) => ({
|
|
96
|
+
role_id: s.id,
|
|
97
|
+
resource_server_identifier: c,
|
|
98
|
+
permission_name: e.value
|
|
99
|
+
}));
|
|
100
|
+
return await e.adapters.rolePermissions.assign(r, s.id, l), s.id;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/hooks/sync.ts
|
|
104
|
+
function S(e, t, n = () => !0) {
|
|
105
|
+
let { controlPlaneTenantId: r, getChildTenantIds: i, getAdapters: a } = e, o = /* @__PURE__ */ new Map();
|
|
106
|
+
async function s(e, n, r) {
|
|
107
|
+
return (await t(e).list(n, {
|
|
108
|
+
q: `name:${r}`,
|
|
109
|
+
per_page: 1
|
|
110
|
+
}))[0] ?? null;
|
|
111
|
+
}
|
|
112
|
+
async function c(e) {
|
|
113
|
+
let n = await i(), o = t(await a(r));
|
|
114
|
+
await Promise.all(n.map(async (n) => {
|
|
115
|
+
try {
|
|
116
|
+
let r = await a(n), i = t(r), c = {
|
|
117
|
+
...o.transform(e),
|
|
118
|
+
is_system: !0
|
|
119
|
+
}, l = await s(r, n, e.name), u = l ? i.getId(l) : void 0;
|
|
120
|
+
if (l && u) {
|
|
121
|
+
let e = i.preserveOnUpdate ? i.preserveOnUpdate(l, c) : c;
|
|
122
|
+
await i.update(n, u, e);
|
|
123
|
+
} else await i.create(n, c);
|
|
124
|
+
} catch (t) {
|
|
125
|
+
console.error(`Failed to sync ${o.listKey} "${e.name}" to tenant "${n}":`, t);
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
async function l(e) {
|
|
130
|
+
let n = await i();
|
|
131
|
+
await Promise.all(n.map(async (n) => {
|
|
132
|
+
try {
|
|
133
|
+
let r = await a(n), i = t(r), o = await s(r, n, e), c = o ? i.getId(o) : void 0;
|
|
134
|
+
o && c && await i.remove(n, c);
|
|
135
|
+
} catch (t) {
|
|
136
|
+
console.error(`Failed to delete entity "${e}" from tenant "${n}":`, t);
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
afterCreate: async (e, t) => {
|
|
142
|
+
e.tenantId === r && n(t) && await c(t);
|
|
143
|
+
},
|
|
144
|
+
afterUpdate: async (e, t, i) => {
|
|
145
|
+
e.tenantId === r && n(i) && await c(i);
|
|
146
|
+
},
|
|
147
|
+
beforeDelete: async (e, i) => {
|
|
148
|
+
if (e.tenantId !== r) return;
|
|
149
|
+
let a = await t(e.adapters).get(e.tenantId, i);
|
|
150
|
+
a && n(a) && o.set(i, a);
|
|
151
|
+
},
|
|
152
|
+
afterDelete: async (e, t) => {
|
|
153
|
+
if (e.tenantId !== r) return;
|
|
154
|
+
let n = o.get(t);
|
|
155
|
+
n && (o.delete(t), await l(n.name));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function C(e, t, n = () => !0) {
|
|
160
|
+
let { controlPlaneTenantId: r, getControlPlaneAdapters: i, getAdapters: a } = e;
|
|
161
|
+
return { async afterCreate(e, o) {
|
|
162
|
+
if (o.id !== r) try {
|
|
163
|
+
let e = await i(), c = await a(o.id), l = t(e), u = t(c), d = await s((e) => l.listPaginated(r, e), l.listKey, {
|
|
164
|
+
cursorField: "id",
|
|
165
|
+
pageSize: 100
|
|
166
|
+
});
|
|
167
|
+
await Promise.all(d.filter((e) => n(e)).map(async (e) => {
|
|
168
|
+
try {
|
|
169
|
+
let t = l.transform(e);
|
|
170
|
+
await u.create(o.id, {
|
|
171
|
+
...t,
|
|
172
|
+
is_system: !0
|
|
173
|
+
});
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.error(`Failed to sync entity to new tenant "${o.id}":`, e);
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.error(`Failed to sync entities to new tenant "${o.id}":`, e);
|
|
180
|
+
}
|
|
181
|
+
} };
|
|
182
|
+
}
|
|
183
|
+
var w = (e) => ({
|
|
184
|
+
list: async (t, n) => (await e.resourceServers.list(t, n)).resource_servers,
|
|
185
|
+
listPaginated: (t, n) => e.resourceServers.list(t, n),
|
|
186
|
+
get: (t, n) => e.resourceServers.get(t, n),
|
|
187
|
+
create: (t, n) => e.resourceServers.create(t, n),
|
|
188
|
+
update: (t, n, r) => e.resourceServers.update(t, n, r),
|
|
189
|
+
remove: (t, n) => e.resourceServers.remove(t, n),
|
|
190
|
+
listKey: "resource_servers",
|
|
191
|
+
getId: (e) => e.id,
|
|
192
|
+
transform: (e) => ({
|
|
193
|
+
id: e.id,
|
|
194
|
+
name: e.name,
|
|
195
|
+
identifier: e.identifier,
|
|
196
|
+
scopes: e.scopes,
|
|
197
|
+
signing_alg: e.signing_alg,
|
|
198
|
+
token_lifetime: e.token_lifetime,
|
|
199
|
+
token_lifetime_for_web: e.token_lifetime_for_web
|
|
200
|
+
})
|
|
201
|
+
}), T = (e) => ({
|
|
202
|
+
list: async (t, n) => (await e.roles.list(t, n)).roles,
|
|
203
|
+
listPaginated: (t, n) => e.roles.list(t, n),
|
|
204
|
+
get: (t, n) => e.roles.get(t, n),
|
|
205
|
+
create: (t, n) => e.roles.create(t, n),
|
|
206
|
+
update: (t, n, r) => e.roles.update(t, n, r),
|
|
207
|
+
remove: (t, n) => e.roles.remove(t, n),
|
|
208
|
+
listKey: "roles",
|
|
209
|
+
getId: (e) => e.id,
|
|
210
|
+
transform: (e) => ({
|
|
211
|
+
id: e.id,
|
|
212
|
+
name: e.name,
|
|
213
|
+
description: e.description
|
|
214
|
+
})
|
|
310
215
|
});
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
} catch (h) {
|
|
386
|
-
console.error(
|
|
387
|
-
`Failed to sync role permissions to tenant "${g.id}":`,
|
|
388
|
-
h
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
} : void 0;
|
|
394
|
-
async function m(f, g, _) {
|
|
395
|
-
return (await f.roles.list(g, {
|
|
396
|
-
q: `name:${_}`,
|
|
397
|
-
per_page: 1
|
|
398
|
-
})).roles[0] ?? null;
|
|
399
|
-
}
|
|
400
|
-
return {
|
|
401
|
-
entityHooks: {
|
|
402
|
-
resourceServers: i,
|
|
403
|
-
roles: l
|
|
404
|
-
},
|
|
405
|
-
tenantHooks: {
|
|
406
|
-
async afterCreate(f, g) {
|
|
407
|
-
const _ = [
|
|
408
|
-
u == null ? void 0 : u.afterCreate,
|
|
409
|
-
(d == null ? void 0 : d.afterCreate) ?? (s == null ? void 0 : s.afterCreate)
|
|
410
|
-
], h = [];
|
|
411
|
-
for (const T of _)
|
|
412
|
-
if (T)
|
|
413
|
-
try {
|
|
414
|
-
await T(f, g);
|
|
415
|
-
} catch (b) {
|
|
416
|
-
h.push(b instanceof Error ? b : new Error(String(b)));
|
|
417
|
-
}
|
|
418
|
-
if (h.length === 1) throw h[0];
|
|
419
|
-
if (h.length > 1)
|
|
420
|
-
throw new AggregateError(
|
|
421
|
-
h,
|
|
422
|
-
h.map((T) => T.message).join("; ")
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
var P = class extends Error {
|
|
429
|
-
/**
|
|
430
|
-
* Creates an instance of `HTTPException`.
|
|
431
|
-
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
432
|
-
* @param options - Additional options for the exception.
|
|
433
|
-
*/
|
|
434
|
-
constructor(t = 500, r) {
|
|
435
|
-
super(r == null ? void 0 : r.message, { cause: r == null ? void 0 : r.cause });
|
|
436
|
-
E(this, "res");
|
|
437
|
-
E(this, "status");
|
|
438
|
-
this.res = r == null ? void 0 : r.res, this.status = t;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Returns the response object associated with the exception.
|
|
442
|
-
* If a response object is not provided, a new response is created with the error message and status code.
|
|
443
|
-
* @returns The response object.
|
|
444
|
-
*/
|
|
445
|
-
getResponse() {
|
|
446
|
-
return this.res ? new Response(this.res.body, {
|
|
447
|
-
status: this.status,
|
|
448
|
-
headers: this.res.headers
|
|
449
|
-
}) : new Response(this.message, {
|
|
450
|
-
status: this.status
|
|
451
|
-
});
|
|
452
|
-
}
|
|
216
|
+
function E(e) {
|
|
217
|
+
return e.metadata?.sync !== !1;
|
|
218
|
+
}
|
|
219
|
+
function D(e) {
|
|
220
|
+
let { sync: t = {}, filters: n = {} } = e, r = t.resourceServers ?? !0, i = t.roles ?? !0, a = (e) => E(e) ? n.resourceServers ? n.resourceServers(e) : !0 : !1, o = (e) => E(e) ? n.roles ? n.roles(e) : !0 : !1, c = r ? S(e, w, a) : void 0, l = i ? S(e, T, o) : void 0, u = r ? C(e, w, a) : void 0, d = i ? C(e, T, o) : void 0, f = i ? { async afterCreate(t, r) {
|
|
221
|
+
if (r.id !== e.controlPlaneTenantId) {
|
|
222
|
+
await d?.afterCreate?.(t, r);
|
|
223
|
+
try {
|
|
224
|
+
let t = await e.getControlPlaneAdapters(), i = await e.getAdapters(r.id), a = await s((n) => t.roles.list(e.controlPlaneTenantId, n), "roles", {
|
|
225
|
+
cursorField: "id",
|
|
226
|
+
pageSize: 100
|
|
227
|
+
}), o = /* @__PURE__ */ new Map();
|
|
228
|
+
for (let e of a.filter((e) => n.roles?.(e) ?? !0)) {
|
|
229
|
+
let t = await p(i, r.id, e.name);
|
|
230
|
+
t && o.set(e.name, t.id);
|
|
231
|
+
}
|
|
232
|
+
for (let s of a.filter((e) => n.roles?.(e) ?? !0)) {
|
|
233
|
+
let n = o.get(s.name);
|
|
234
|
+
if (n) try {
|
|
235
|
+
let a = await t.rolePermissions.list(e.controlPlaneTenantId, s.id, {});
|
|
236
|
+
a.length > 0 && await i.rolePermissions.assign(r.id, n, a.map((e) => ({
|
|
237
|
+
role_id: n,
|
|
238
|
+
resource_server_identifier: e.resource_server_identifier,
|
|
239
|
+
permission_name: e.permission_name
|
|
240
|
+
})));
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error(`Failed to sync permissions for role "${s.name}" to tenant "${r.id}":`, e);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
} catch (e) {
|
|
246
|
+
console.error(`Failed to sync role permissions to tenant "${r.id}":`, e);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} } : void 0;
|
|
250
|
+
async function p(e, t, n) {
|
|
251
|
+
return (await e.roles.list(t, {
|
|
252
|
+
q: `name:${n}`,
|
|
253
|
+
per_page: 1
|
|
254
|
+
})).roles[0] ?? null;
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
entityHooks: {
|
|
258
|
+
resourceServers: c,
|
|
259
|
+
roles: l
|
|
260
|
+
},
|
|
261
|
+
tenantHooks: { async afterCreate(e, t) {
|
|
262
|
+
let n = [u?.afterCreate, f?.afterCreate ?? d?.afterCreate], r = [];
|
|
263
|
+
for (let i of n) if (i) try {
|
|
264
|
+
await i(e, t);
|
|
265
|
+
} catch (e) {
|
|
266
|
+
r.push(e instanceof Error ? e : Error(String(e)));
|
|
267
|
+
}
|
|
268
|
+
if (r.length === 1) throw r[0];
|
|
269
|
+
if (r.length > 1) throw AggregateError(r, r.map((e) => e.message).join("; "));
|
|
270
|
+
} }
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region ../../node_modules/.pnpm/hono@4.12.25/node_modules/hono/dist/http-exception.js
|
|
275
|
+
var O = class extends Error {
|
|
276
|
+
res;
|
|
277
|
+
status;
|
|
278
|
+
constructor(e = 500, t) {
|
|
279
|
+
super(t?.message, { cause: t?.cause }), this.res = t?.res, this.status = e;
|
|
280
|
+
}
|
|
281
|
+
getResponse() {
|
|
282
|
+
return this.res ? new Response(this.res.body, {
|
|
283
|
+
status: this.status,
|
|
284
|
+
headers: this.res.headers
|
|
285
|
+
}) : new Response(this.message, { status: this.status });
|
|
286
|
+
}
|
|
453
287
|
};
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}
|
|
726
|
-
],
|
|
727
|
-
responses: {
|
|
728
|
-
200: {
|
|
729
|
-
content: {
|
|
730
|
-
"application/json": {
|
|
731
|
-
schema: D
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
description: "Updated tenant settings"
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}),
|
|
738
|
-
async (n) => {
|
|
739
|
-
const a = n.req.valid("json"), { id: o, ...c } = a, i = await n.env.data.tenants.get(n.var.tenant_id);
|
|
740
|
-
if (!i)
|
|
741
|
-
throw new P(404, {
|
|
742
|
-
message: "Tenant not found"
|
|
743
|
-
});
|
|
744
|
-
const l = ie(i, c);
|
|
745
|
-
await n.env.data.tenants.update(n.var.tenant_id, l);
|
|
746
|
-
const u = await n.env.data.tenants.get(n.var.tenant_id);
|
|
747
|
-
if (!u)
|
|
748
|
-
throw new P(500, {
|
|
749
|
-
message: "Failed to retrieve updated tenant"
|
|
750
|
-
});
|
|
751
|
-
return n.json(u);
|
|
752
|
-
}
|
|
753
|
-
), r;
|
|
754
|
-
}
|
|
755
|
-
function _e(e) {
|
|
756
|
-
const t = [
|
|
757
|
-
{
|
|
758
|
-
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
759
|
-
type: "resource_server"
|
|
760
|
-
},
|
|
761
|
-
{ pattern: /\/api\/v2\/roles\/([^/]+)$/, type: "role" },
|
|
762
|
-
{ pattern: /\/api\/v2\/connections\/([^/]+)$/, type: "connection" }
|
|
763
|
-
];
|
|
764
|
-
for (const { pattern: r, type: n } of t) {
|
|
765
|
-
const a = e.match(r);
|
|
766
|
-
if (a && a[1])
|
|
767
|
-
return { type: n, id: a[1] };
|
|
768
|
-
}
|
|
769
|
-
return null;
|
|
770
|
-
}
|
|
771
|
-
async function Te(e, t, r) {
|
|
772
|
-
try {
|
|
773
|
-
switch (r.type) {
|
|
774
|
-
case "resource_server": {
|
|
775
|
-
const n = await e.resourceServers.get(t, r.id);
|
|
776
|
-
return (n == null ? void 0 : n.is_system) === !0;
|
|
777
|
-
}
|
|
778
|
-
case "role": {
|
|
779
|
-
const n = await e.roles.get(t, r.id);
|
|
780
|
-
return (n == null ? void 0 : n.is_system) === !0;
|
|
781
|
-
}
|
|
782
|
-
case "connection": {
|
|
783
|
-
const n = await e.connections.get(t, r.id);
|
|
784
|
-
return (n == null ? void 0 : n.is_system) === !0;
|
|
785
|
-
}
|
|
786
|
-
default:
|
|
787
|
-
return !1;
|
|
788
|
-
}
|
|
789
|
-
} catch {
|
|
790
|
-
return !1;
|
|
791
|
-
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/routes/tenants.ts
|
|
290
|
+
function k(e, t) {
|
|
291
|
+
let n = new d();
|
|
292
|
+
return n.openapi(f({
|
|
293
|
+
tags: ["tenants"],
|
|
294
|
+
method: "get",
|
|
295
|
+
path: "/",
|
|
296
|
+
request: { query: r },
|
|
297
|
+
security: [{ Bearer: [] }],
|
|
298
|
+
responses: { 200: {
|
|
299
|
+
content: { "application/json": { schema: p.object({
|
|
300
|
+
tenants: p.array(u),
|
|
301
|
+
start: p.number().optional(),
|
|
302
|
+
limit: p.number().optional(),
|
|
303
|
+
length: p.number().optional()
|
|
304
|
+
}) } },
|
|
305
|
+
description: "List of tenants"
|
|
306
|
+
} }
|
|
307
|
+
}), async (t) => {
|
|
308
|
+
let { page: n, per_page: r, include_totals: i, q: a } = t.req.valid("query"), o = t.var.user, c = o?.permissions || [];
|
|
309
|
+
if (!(o?.org_id ?? t.var.organization_id) && c.includes("admin:organizations")) {
|
|
310
|
+
let e = await t.env.data.tenants.list({
|
|
311
|
+
page: n,
|
|
312
|
+
per_page: r,
|
|
313
|
+
include_totals: i,
|
|
314
|
+
q: a
|
|
315
|
+
});
|
|
316
|
+
return i ? t.json({
|
|
317
|
+
tenants: e.tenants,
|
|
318
|
+
start: e.totals?.start ?? 0,
|
|
319
|
+
limit: e.totals?.limit ?? r,
|
|
320
|
+
length: e.tenants.length
|
|
321
|
+
}) : t.json({ tenants: e.tenants });
|
|
322
|
+
}
|
|
323
|
+
let l = e.accessControl?.controlPlaneTenantId ?? t.env.data.multiTenancyConfig?.controlPlaneTenantId;
|
|
324
|
+
if (l && !o?.sub) throw new O(403, { message: "Access denied: token has no subject" });
|
|
325
|
+
if (l && o?.sub) {
|
|
326
|
+
let e = (await s((e) => t.env.data.userOrganizations.listUserOrganizations(l, o.sub, e), "organizations")).map((e) => e.name);
|
|
327
|
+
if (e.length === 0) return i ? t.json({
|
|
328
|
+
tenants: [],
|
|
329
|
+
start: 0,
|
|
330
|
+
limit: r ?? 50,
|
|
331
|
+
length: 0
|
|
332
|
+
}) : t.json({ tenants: [] });
|
|
333
|
+
let c = e.length, u = n ?? 0, d = r ?? 50, f = u * d, p = e.slice(f, f + d);
|
|
334
|
+
if (p.length === 0) return i ? t.json({
|
|
335
|
+
tenants: [],
|
|
336
|
+
start: f,
|
|
337
|
+
limit: d,
|
|
338
|
+
length: c
|
|
339
|
+
}) : t.json({ tenants: [] });
|
|
340
|
+
let m = p.map((e) => `id:${e}`).join(" OR "), h = a ? `(${m}) AND (${a})` : m, g = await t.env.data.tenants.list({
|
|
341
|
+
q: h,
|
|
342
|
+
per_page: d,
|
|
343
|
+
include_totals: !1
|
|
344
|
+
});
|
|
345
|
+
return i ? t.json({
|
|
346
|
+
tenants: g.tenants,
|
|
347
|
+
start: f,
|
|
348
|
+
limit: d,
|
|
349
|
+
length: c
|
|
350
|
+
}) : t.json({ tenants: g.tenants });
|
|
351
|
+
}
|
|
352
|
+
let u = await t.env.data.tenants.list({
|
|
353
|
+
page: n,
|
|
354
|
+
per_page: r,
|
|
355
|
+
include_totals: i,
|
|
356
|
+
q: a
|
|
357
|
+
});
|
|
358
|
+
return i ? t.json({
|
|
359
|
+
tenants: u.tenants,
|
|
360
|
+
start: u.totals?.start ?? 0,
|
|
361
|
+
limit: u.totals?.limit ?? r,
|
|
362
|
+
length: u.tenants.length
|
|
363
|
+
}) : t.json({ tenants: u.tenants });
|
|
364
|
+
}), n.openapi(f({
|
|
365
|
+
tags: ["tenants"],
|
|
366
|
+
method: "post",
|
|
367
|
+
path: "/",
|
|
368
|
+
request: { body: { content: { "application/json": { schema: l } } } },
|
|
369
|
+
security: [{ Bearer: [] }],
|
|
370
|
+
responses: {
|
|
371
|
+
201: {
|
|
372
|
+
content: { "application/json": { schema: u } },
|
|
373
|
+
description: "Tenant created"
|
|
374
|
+
},
|
|
375
|
+
400: { description: "Validation error" },
|
|
376
|
+
409: { description: "Tenant with this ID already exists" }
|
|
377
|
+
}
|
|
378
|
+
}), async (e) => {
|
|
379
|
+
if (!e.var.user?.sub) throw new O(401, { message: "Authentication required to create tenants" });
|
|
380
|
+
let n = e.req.valid("json"), r = {
|
|
381
|
+
adapters: e.env.data,
|
|
382
|
+
ctx: e
|
|
383
|
+
};
|
|
384
|
+
t.tenants?.beforeCreate && (n = await t.tenants.beforeCreate(r, n));
|
|
385
|
+
let i = await e.env.data.tenants.create(n);
|
|
386
|
+
return t.tenants?.afterCreate && await t.tenants.afterCreate(r, i), e.json(i, 201);
|
|
387
|
+
}), n.openapi(f({
|
|
388
|
+
tags: ["tenants"],
|
|
389
|
+
method: "delete",
|
|
390
|
+
path: "/{id}",
|
|
391
|
+
request: { params: p.object({ id: p.string() }) },
|
|
392
|
+
security: [{ Bearer: ["delete:tenants"] }],
|
|
393
|
+
responses: {
|
|
394
|
+
204: { description: "Tenant deleted" },
|
|
395
|
+
403: { description: "Access denied or cannot delete the control plane" },
|
|
396
|
+
404: { description: "Tenant not found" }
|
|
397
|
+
}
|
|
398
|
+
}), async (n) => {
|
|
399
|
+
let { id: r } = n.req.valid("param"), i = e.accessControl?.controlPlaneTenantId ?? n.env.data.multiTenancyConfig?.controlPlaneTenantId;
|
|
400
|
+
if (i) {
|
|
401
|
+
let e = n.var.user;
|
|
402
|
+
if (!e?.sub) throw new O(401, { message: "Authentication required" });
|
|
403
|
+
if (r === i) throw new O(403, { message: "Cannot delete the control plane" });
|
|
404
|
+
let t = n.var.org_name, a = r.toLowerCase(), o = !!t && t.toLowerCase() === a;
|
|
405
|
+
if (o ||= (await s((t) => n.env.data.userOrganizations.listUserOrganizations(i, e.sub, t), "organizations")).some((e) => e.name?.toLowerCase() === a), !o) throw new O(403, { message: "Access denied to this tenant" });
|
|
406
|
+
}
|
|
407
|
+
if (!await n.env.data.tenants.get(r)) throw new O(404, { message: "Tenant not found" });
|
|
408
|
+
let a = {
|
|
409
|
+
adapters: n.env.data,
|
|
410
|
+
ctx: n
|
|
411
|
+
};
|
|
412
|
+
return t.tenants?.beforeDelete && await t.tenants.beforeDelete(a, r), await n.env.data.tenants.remove(r), t.tenants?.afterDelete && await t.tenants.afterDelete(a, r), n.body(null, 204);
|
|
413
|
+
}), n.openapi(f({
|
|
414
|
+
tags: ["tenants", "settings"],
|
|
415
|
+
method: "get",
|
|
416
|
+
path: "/settings",
|
|
417
|
+
request: { headers: p.object({ "tenant-id": p.string().optional() }) },
|
|
418
|
+
security: [{ Bearer: ["read:tenants"] }],
|
|
419
|
+
responses: { 200: {
|
|
420
|
+
content: { "application/json": { schema: u } },
|
|
421
|
+
description: "Current tenant settings"
|
|
422
|
+
} }
|
|
423
|
+
}), async (e) => {
|
|
424
|
+
let t = await e.env.data.tenants.get(e.var.tenant_id);
|
|
425
|
+
if (!t) throw new O(404, { message: "Tenant not found" });
|
|
426
|
+
return e.json(t);
|
|
427
|
+
}), n.openapi(f({
|
|
428
|
+
tags: ["tenants", "settings"],
|
|
429
|
+
method: "patch",
|
|
430
|
+
path: "/settings",
|
|
431
|
+
request: {
|
|
432
|
+
headers: p.object({ "tenant-id": p.string().optional() }),
|
|
433
|
+
body: { content: { "application/json": { schema: p.object(l.shape).partial() } } }
|
|
434
|
+
},
|
|
435
|
+
security: [{ Bearer: ["update:tenants"] }],
|
|
436
|
+
responses: { 200: {
|
|
437
|
+
content: { "application/json": { schema: u } },
|
|
438
|
+
description: "Updated tenant settings"
|
|
439
|
+
} }
|
|
440
|
+
}), async (e) => {
|
|
441
|
+
let { id: t, ...n } = e.req.valid("json"), r = await e.env.data.tenants.get(e.var.tenant_id);
|
|
442
|
+
if (!r) throw new O(404, { message: "Tenant not found" });
|
|
443
|
+
let i = o(r, n);
|
|
444
|
+
await e.env.data.tenants.update(e.var.tenant_id, i);
|
|
445
|
+
let a = await e.env.data.tenants.get(e.var.tenant_id);
|
|
446
|
+
if (!a) throw new O(500, { message: "Failed to retrieve updated tenant" });
|
|
447
|
+
return e.json(a);
|
|
448
|
+
}), n;
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/middleware/protect-synced.ts
|
|
452
|
+
function A(e) {
|
|
453
|
+
for (let { pattern: t, type: n } of [
|
|
454
|
+
{
|
|
455
|
+
pattern: /\/api\/v2\/resource-servers\/([^/]+)$/,
|
|
456
|
+
type: "resource_server"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
pattern: /\/api\/v2\/roles\/([^/]+)$/,
|
|
460
|
+
type: "role"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
pattern: /\/api\/v2\/connections\/([^/]+)$/,
|
|
464
|
+
type: "connection"
|
|
465
|
+
}
|
|
466
|
+
]) {
|
|
467
|
+
let r = e.match(t);
|
|
468
|
+
if (r && r[1]) return {
|
|
469
|
+
type: n,
|
|
470
|
+
id: r[1]
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
async function j(e, t, n) {
|
|
476
|
+
try {
|
|
477
|
+
switch (n.type) {
|
|
478
|
+
case "resource_server": return (await e.resourceServers.get(t, n.id))?.is_system === !0;
|
|
479
|
+
case "role": return (await e.roles.get(t, n.id))?.is_system === !0;
|
|
480
|
+
case "connection": return (await e.connections.get(t, n.id))?.is_system === !0;
|
|
481
|
+
default: return !1;
|
|
482
|
+
}
|
|
483
|
+
} catch {
|
|
484
|
+
return !1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function M(e) {
|
|
488
|
+
return {
|
|
489
|
+
resource_server: "resource server",
|
|
490
|
+
role: "role",
|
|
491
|
+
connection: "connection"
|
|
492
|
+
}[e];
|
|
493
|
+
}
|
|
494
|
+
function N() {
|
|
495
|
+
return async (e, t) => {
|
|
496
|
+
if (![
|
|
497
|
+
"PATCH",
|
|
498
|
+
"PUT",
|
|
499
|
+
"DELETE"
|
|
500
|
+
].includes(e.req.method)) return t();
|
|
501
|
+
let n = A(e.req.path);
|
|
502
|
+
if (!n) return t();
|
|
503
|
+
let r = e.var.tenant_id || e.req.header("x-tenant-id") || e.req.header("tenant-id");
|
|
504
|
+
if (!r) return t();
|
|
505
|
+
if (await j(e.env.data, r, n)) throw new O(403, { message: `This ${M(n.type)} is a system resource and cannot be modified. Make changes in the control plane instead.` });
|
|
506
|
+
return t();
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/middleware/settings-inheritance.ts
|
|
511
|
+
function P(e, t) {
|
|
512
|
+
let n = t.find((t) => t.strategy === e.strategy);
|
|
513
|
+
if (!n?.options) return e;
|
|
514
|
+
let r = a.passthrough().parse({
|
|
515
|
+
...n,
|
|
516
|
+
...e
|
|
517
|
+
});
|
|
518
|
+
return r.options = i.passthrough().parse({
|
|
519
|
+
...n.options || {},
|
|
520
|
+
...e.options
|
|
521
|
+
}), r;
|
|
522
|
+
}
|
|
523
|
+
function F(e, t) {
|
|
524
|
+
let n = [...t || [], ...e || []];
|
|
525
|
+
return [...new Set(n)];
|
|
526
|
+
}
|
|
527
|
+
function I(e, t) {
|
|
528
|
+
if (!t?.length) return e || [];
|
|
529
|
+
if (!e?.length) return t;
|
|
530
|
+
let n = /* @__PURE__ */ new Map();
|
|
531
|
+
for (let e of t) n.set(e.value, e);
|
|
532
|
+
for (let t of e) n.set(t.value, t);
|
|
533
|
+
return Array.from(n.values());
|
|
534
|
+
}
|
|
535
|
+
function L(e, t) {
|
|
536
|
+
return t ? {
|
|
537
|
+
...e,
|
|
538
|
+
scopes: I(e.scopes, t.scopes)
|
|
539
|
+
} : e;
|
|
540
|
+
}
|
|
541
|
+
function R(e, t) {
|
|
542
|
+
return t ? {
|
|
543
|
+
...e,
|
|
544
|
+
callbacks: F(e.callbacks, t.callbacks),
|
|
545
|
+
web_origins: F(e.web_origins, t.web_origins),
|
|
546
|
+
allowed_logout_urls: F(e.allowed_logout_urls, t.allowed_logout_urls),
|
|
547
|
+
allowed_origins: F(e.allowed_origins, t.allowed_origins)
|
|
548
|
+
} : e;
|
|
549
|
+
}
|
|
550
|
+
function z(e) {
|
|
551
|
+
let { controlPlaneTenantId: t, controlPlaneClientId: n, resolveControlPlane: r } = e;
|
|
552
|
+
if (r) return async (e) => r({ tenant_id: e });
|
|
553
|
+
if (!t) return async () => void 0;
|
|
554
|
+
let i = {
|
|
555
|
+
tenantId: t,
|
|
556
|
+
clientId: n
|
|
557
|
+
};
|
|
558
|
+
return async () => i;
|
|
792
559
|
}
|
|
793
|
-
function
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
(a) => a.strategy === e.strategy
|
|
820
|
-
);
|
|
821
|
-
if (!(r != null && r.options))
|
|
822
|
-
return e;
|
|
823
|
-
const n = ce.passthrough().parse({
|
|
824
|
-
...r,
|
|
825
|
-
...e
|
|
826
|
-
});
|
|
827
|
-
return n.options = le.passthrough().parse({
|
|
828
|
-
...r.options || {},
|
|
829
|
-
...e.options
|
|
830
|
-
}), n;
|
|
831
|
-
}
|
|
832
|
-
function O(e, t) {
|
|
833
|
-
const r = [...t || [], ...e || []];
|
|
834
|
-
return [...new Set(r)];
|
|
835
|
-
}
|
|
836
|
-
function be(e, t) {
|
|
837
|
-
if (!(t != null && t.length))
|
|
838
|
-
return e || [];
|
|
839
|
-
if (!(e != null && e.length))
|
|
840
|
-
return t;
|
|
841
|
-
const r = /* @__PURE__ */ new Map();
|
|
842
|
-
for (const n of t)
|
|
843
|
-
r.set(n.value, n);
|
|
844
|
-
for (const n of e)
|
|
845
|
-
r.set(n.value, n);
|
|
846
|
-
return Array.from(r.values());
|
|
560
|
+
function B(e, t) {
|
|
561
|
+
return {
|
|
562
|
+
...e.resourceServers,
|
|
563
|
+
get: async (n, r) => {
|
|
564
|
+
let i = await e.resourceServers.get(n, r);
|
|
565
|
+
if (!i) return i;
|
|
566
|
+
let a = await t(n);
|
|
567
|
+
return !a || n === a.tenantId || !i.is_system ? i : L(i, await e.resourceServers.get(a.tenantId, r));
|
|
568
|
+
},
|
|
569
|
+
list: async (n, r) => {
|
|
570
|
+
let i = await e.resourceServers.list(n, r), a = await t(n);
|
|
571
|
+
if (!a || n === a.tenantId) return i;
|
|
572
|
+
let o = a.tenantId, s = i.resource_servers.filter((e) => !!(e.is_system && e.id)).map((e) => e.id);
|
|
573
|
+
if (s.length === 0) return i;
|
|
574
|
+
let c = /* @__PURE__ */ new Map();
|
|
575
|
+
await Promise.all(s.map(async (t) => {
|
|
576
|
+
let n = await e.resourceServers.get(o, t);
|
|
577
|
+
n && c.set(t, n);
|
|
578
|
+
}));
|
|
579
|
+
let l = i.resource_servers.map((e) => e.is_system && e.id ? L(e, c.get(e.id) ?? null) : e);
|
|
580
|
+
return {
|
|
581
|
+
...i,
|
|
582
|
+
resource_servers: l
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
};
|
|
847
586
|
}
|
|
848
587
|
function V(e, t) {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
588
|
+
let n = z({
|
|
589
|
+
controlPlaneTenantId: t.controlPlaneTenantId,
|
|
590
|
+
resolveControlPlane: t.resolveControlPlane
|
|
591
|
+
});
|
|
592
|
+
return {
|
|
593
|
+
...e,
|
|
594
|
+
resourceServers: B(e, n)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function H(e, t) {
|
|
598
|
+
let { controlPlaneTenantId: n, controlPlaneClientId: r, resolveControlPlane: i } = t, a = z({
|
|
599
|
+
controlPlaneTenantId: n,
|
|
600
|
+
controlPlaneClientId: r,
|
|
601
|
+
resolveControlPlane: i
|
|
602
|
+
});
|
|
603
|
+
return {
|
|
604
|
+
...e,
|
|
605
|
+
multiTenancyConfig: {
|
|
606
|
+
controlPlaneTenantId: n,
|
|
607
|
+
controlPlaneClientId: r,
|
|
608
|
+
resolveControlPlane: i
|
|
609
|
+
},
|
|
610
|
+
connections: {
|
|
611
|
+
...e.connections,
|
|
612
|
+
get: async (t, n) => {
|
|
613
|
+
let r = await e.connections.get(t, n);
|
|
614
|
+
if (!r) return r;
|
|
615
|
+
let i = await a(t);
|
|
616
|
+
return !i || t === i.tenantId ? r : P(r, (await e.connections.list(i.tenantId)).connections || []);
|
|
617
|
+
},
|
|
618
|
+
list: async (t, n) => {
|
|
619
|
+
let r = await e.connections.list(t, n), i = await a(t);
|
|
620
|
+
if (!i || t === i.tenantId) return r;
|
|
621
|
+
let o = await e.connections.list(i.tenantId), s = r.connections.map((e) => P(e, o.connections || []));
|
|
622
|
+
return {
|
|
623
|
+
...r,
|
|
624
|
+
connections: s
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
clientConnections: {
|
|
629
|
+
...e.clientConnections,
|
|
630
|
+
listByClient: async (t, n) => {
|
|
631
|
+
let r = await e.clientConnections.listByClient(t, n);
|
|
632
|
+
r.length === 0 && (r = (await e.connections.list(t)).connections || []);
|
|
633
|
+
let i = await a(t);
|
|
634
|
+
if (!i || t === i.tenantId) return r;
|
|
635
|
+
let o = await e.connections.list(i.tenantId);
|
|
636
|
+
return r.map((e) => P(e, o.connections || []));
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
emailProviders: {
|
|
640
|
+
...e.emailProviders,
|
|
641
|
+
get: async (t) => {
|
|
642
|
+
let n = await e.emailProviders.get(t);
|
|
643
|
+
if (n) return n;
|
|
644
|
+
let r = await a(t);
|
|
645
|
+
return !r || t === r.tenantId ? null : e.emailProviders.get(r.tenantId);
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
resourceServers: B(e, a),
|
|
649
|
+
hooks: W(e, a)
|
|
650
|
+
};
|
|
856
651
|
}
|
|
857
|
-
function
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
a,
|
|
907
|
-
c
|
|
908
|
-
);
|
|
909
|
-
},
|
|
910
|
-
list: async (r, n) => {
|
|
911
|
-
const a = await e.resourceServers.list(r, n), o = await t(r);
|
|
912
|
-
if (!o || r === o.tenantId)
|
|
913
|
-
return a;
|
|
914
|
-
const c = o.tenantId, i = a.resource_servers.filter(
|
|
915
|
-
(s) => !!(s.is_system && s.id)
|
|
916
|
-
).map((s) => s.id);
|
|
917
|
-
if (i.length === 0)
|
|
918
|
-
return a;
|
|
919
|
-
const l = /* @__PURE__ */ new Map();
|
|
920
|
-
await Promise.all(
|
|
921
|
-
i.map(async (s) => {
|
|
922
|
-
const d = await e.resourceServers.get(c, s);
|
|
923
|
-
d && l.set(s, d);
|
|
924
|
-
})
|
|
925
|
-
);
|
|
926
|
-
const u = a.resource_servers.map(
|
|
927
|
-
(s) => s.is_system && s.id ? V(
|
|
928
|
-
s,
|
|
929
|
-
l.get(s.id) ?? null
|
|
930
|
-
) : s
|
|
931
|
-
);
|
|
932
|
-
return {
|
|
933
|
-
...a,
|
|
934
|
-
resource_servers: u
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
function Ie(e, t) {
|
|
940
|
-
const r = Z({
|
|
941
|
-
controlPlaneTenantId: t.controlPlaneTenantId,
|
|
942
|
-
resolveControlPlane: t.resolveControlPlane
|
|
943
|
-
});
|
|
944
|
-
return {
|
|
945
|
-
...e,
|
|
946
|
-
resourceServers: x(
|
|
947
|
-
e,
|
|
948
|
-
r
|
|
949
|
-
)
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
function Ae(e, t) {
|
|
953
|
-
const { controlPlaneTenantId: r, controlPlaneClientId: n, resolveControlPlane: a } = t, o = Z({
|
|
954
|
-
controlPlaneTenantId: r,
|
|
955
|
-
controlPlaneClientId: n,
|
|
956
|
-
resolveControlPlane: a
|
|
957
|
-
});
|
|
958
|
-
return {
|
|
959
|
-
...e,
|
|
960
|
-
// Store the static config for use by tenants route access control.
|
|
961
|
-
// Per-tenant inheritance overrides do NOT affect access-control values —
|
|
962
|
-
// those intentionally use a single global control plane id. The resolver
|
|
963
|
-
// is exposed here so runtime helpers (e.g. `getEnrichedClient`) can
|
|
964
|
-
// consult it before merging control-plane URLs.
|
|
965
|
-
multiTenancyConfig: {
|
|
966
|
-
controlPlaneTenantId: r,
|
|
967
|
-
controlPlaneClientId: n,
|
|
968
|
-
resolveControlPlane: a
|
|
969
|
-
},
|
|
970
|
-
connections: {
|
|
971
|
-
...e.connections,
|
|
972
|
-
get: async (c, i) => {
|
|
973
|
-
const l = await e.connections.get(
|
|
974
|
-
c,
|
|
975
|
-
i
|
|
976
|
-
);
|
|
977
|
-
if (!l)
|
|
978
|
-
return l;
|
|
979
|
-
const u = await o(c);
|
|
980
|
-
if (!u || c === u.tenantId)
|
|
981
|
-
return l;
|
|
982
|
-
const s = await e.connections.list(
|
|
983
|
-
u.tenantId
|
|
984
|
-
);
|
|
985
|
-
return N(
|
|
986
|
-
l,
|
|
987
|
-
s.connections || []
|
|
988
|
-
);
|
|
989
|
-
},
|
|
990
|
-
list: async (c, i) => {
|
|
991
|
-
const l = await e.connections.list(c, i), u = await o(c);
|
|
992
|
-
if (!u || c === u.tenantId)
|
|
993
|
-
return l;
|
|
994
|
-
const s = await e.connections.list(
|
|
995
|
-
u.tenantId
|
|
996
|
-
), d = l.connections.map(
|
|
997
|
-
(m) => N(
|
|
998
|
-
m,
|
|
999
|
-
s.connections || []
|
|
1000
|
-
)
|
|
1001
|
-
);
|
|
1002
|
-
return {
|
|
1003
|
-
...l,
|
|
1004
|
-
connections: d
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
clientConnections: {
|
|
1009
|
-
...e.clientConnections,
|
|
1010
|
-
listByClient: async (c, i) => {
|
|
1011
|
-
let l = await e.clientConnections.listByClient(
|
|
1012
|
-
c,
|
|
1013
|
-
i
|
|
1014
|
-
);
|
|
1015
|
-
l.length === 0 && (l = (await e.connections.list(c)).connections || []);
|
|
1016
|
-
const u = await o(c);
|
|
1017
|
-
if (!u || c === u.tenantId)
|
|
1018
|
-
return l;
|
|
1019
|
-
const s = await e.connections.list(
|
|
1020
|
-
u.tenantId
|
|
1021
|
-
);
|
|
1022
|
-
return l.map(
|
|
1023
|
-
(d) => N(
|
|
1024
|
-
d,
|
|
1025
|
-
s.connections || []
|
|
1026
|
-
)
|
|
1027
|
-
);
|
|
1028
|
-
}
|
|
1029
|
-
},
|
|
1030
|
-
// Note: clients.get / getByClientId are intentionally NOT wrapped here.
|
|
1031
|
-
// Storage reads must return the tenant's own stored URLs so that the
|
|
1032
|
-
// management API and DCR don't echo control-plane callbacks back on
|
|
1033
|
-
// update. Runtime URL merging for auth flows happens in
|
|
1034
|
-
// `getEnrichedClient` (packages/authhero/src/helpers/client.ts).
|
|
1035
|
-
emailProviders: {
|
|
1036
|
-
...e.emailProviders,
|
|
1037
|
-
get: async (c) => {
|
|
1038
|
-
const i = await e.emailProviders.get(c);
|
|
1039
|
-
if (i)
|
|
1040
|
-
return i;
|
|
1041
|
-
const l = await o(c);
|
|
1042
|
-
return !l || c === l.tenantId ? null : e.emailProviders.get(l.tenantId);
|
|
1043
|
-
}
|
|
1044
|
-
},
|
|
1045
|
-
resourceServers: x(
|
|
1046
|
-
e,
|
|
1047
|
-
o
|
|
1048
|
-
),
|
|
1049
|
-
hooks: Se(e, o)
|
|
1050
|
-
// Note: Additional adapters can be extended here for runtime fallback:
|
|
1051
|
-
// - promptSettings: Fall back to control plane prompts
|
|
1052
|
-
// - branding: Fall back to control plane branding/themes
|
|
1053
|
-
};
|
|
652
|
+
function U(e) {
|
|
653
|
+
if (!e || typeof e != "object") return !1;
|
|
654
|
+
let t = e.metadata;
|
|
655
|
+
return !t || typeof t != "object" ? !1 : t.inheritable === !0;
|
|
656
|
+
}
|
|
657
|
+
function W(e, t) {
|
|
658
|
+
return {
|
|
659
|
+
...e.hooks,
|
|
660
|
+
list: async (n, r) => {
|
|
661
|
+
let i = await e.hooks.list(n, r), a = await t(n);
|
|
662
|
+
if (!a || n === a.tenantId) return i;
|
|
663
|
+
let o = ((await e.hooks.list(a.tenantId, r)).hooks || []).filter(U);
|
|
664
|
+
if (o.length === 0) return i;
|
|
665
|
+
let s = new Set((i.hooks || []).map((e) => e.hook_id)), c = o.filter((e) => !s.has(e.hook_id));
|
|
666
|
+
return {
|
|
667
|
+
...i,
|
|
668
|
+
hooks: [...i.hooks || [], ...c],
|
|
669
|
+
length: typeof i.length == "number" ? i.length + c.length : i.length
|
|
670
|
+
};
|
|
671
|
+
},
|
|
672
|
+
get: async (n, r) => {
|
|
673
|
+
let i = await e.hooks.get(n, r);
|
|
674
|
+
if (i) return i;
|
|
675
|
+
let a = await t(n);
|
|
676
|
+
if (!a || n === a.tenantId) return i;
|
|
677
|
+
let o = await e.hooks.get(a.tenantId, r);
|
|
678
|
+
return o && U(o) ? o : null;
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function G(e, t) {
|
|
683
|
+
return H(e, t);
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/middleware/index.ts
|
|
687
|
+
function K(e) {
|
|
688
|
+
return async (t, n) => {
|
|
689
|
+
let r = t.var.user;
|
|
690
|
+
return r?.tenant_id === e && r.org_name && t.set("tenant_id", r.org_name), n();
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function q(e) {
|
|
694
|
+
return async (n, r) => {
|
|
695
|
+
if (!e.accessControl) return r();
|
|
696
|
+
let { controlPlaneTenantId: i } = e.accessControl, a = n.var.org_name, o = n.var.organization_id, s = a || o, c = n.var.tenant_id, l = n.var.user, u = (l?.aud ? Array.isArray(l.aud) ? l.aud : [l.aud] : []).includes(t);
|
|
697
|
+
if (!c && s && u && (n.set("tenant_id", s), c = s), !c) throw new O(400, { message: "Tenant ID not found in request" });
|
|
698
|
+
if (!h(o, c, i, a)) throw new O(403, { message: `Access denied to tenant ${c}` });
|
|
699
|
+
return r();
|
|
700
|
+
};
|
|
1054
701
|
}
|
|
1055
702
|
function J(e) {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
703
|
+
return async (t, n) => {
|
|
704
|
+
if (!e.subdomainRouting) return n();
|
|
705
|
+
let { baseDomain: r, reservedSubdomains: i = [], resolveSubdomain: a } = e.subdomainRouting, o = t.req.header("x-forwarded-host") || t.req.header("host") || "", s = null;
|
|
706
|
+
if (o.endsWith(r)) {
|
|
707
|
+
let e = o.slice(0, -(r.length + 1));
|
|
708
|
+
e && !e.includes(".") && (s = e);
|
|
709
|
+
}
|
|
710
|
+
if (s && i.includes(s) && (s = null), !s) return e.accessControl && t.set("tenant_id", e.accessControl.controlPlaneTenantId), n();
|
|
711
|
+
let c = null;
|
|
712
|
+
if (a) c = await a(s);
|
|
713
|
+
else if (e.subdomainRouting.useOrganizations !== !1 && e.accessControl) try {
|
|
714
|
+
let n = await t.env.data.organizations.get(e.accessControl.controlPlaneTenantId, s);
|
|
715
|
+
n && (c = n.id);
|
|
716
|
+
} catch {}
|
|
717
|
+
if (!c) throw new O(404, { message: `Tenant not found for subdomain: ${s}` });
|
|
718
|
+
return t.set("tenant_id", c), n();
|
|
719
|
+
};
|
|
1059
720
|
}
|
|
1060
|
-
function
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
721
|
+
function Y(e) {
|
|
722
|
+
return async (t, n) => {
|
|
723
|
+
if (!e.databaseIsolation) return n();
|
|
724
|
+
let r = t.var.tenant_id;
|
|
725
|
+
if (!r) throw new O(400, { message: "Tenant ID not found in request" });
|
|
726
|
+
try {
|
|
727
|
+
let n = await e.databaseIsolation.getAdapters(r);
|
|
728
|
+
t.env.data = n;
|
|
729
|
+
} catch (e) {
|
|
730
|
+
throw console.error(`Failed to resolve database for tenant ${r}:`, e), new O(500, { message: "Failed to resolve tenant database" });
|
|
731
|
+
}
|
|
732
|
+
return n();
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function X(e) {
|
|
736
|
+
let t = J(e), n = q(e), r = Y(e);
|
|
737
|
+
return async (e, i) => (await t(e, async () => {}), await n(e, async () => {}), await r(e, async () => {}), i());
|
|
738
|
+
}
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/init.ts
|
|
741
|
+
function Z(e) {
|
|
742
|
+
let { dataAdapter: t, controlPlane: n, controlPlane: { tenantId: r = "control_plane", clientId: i } = {}, resolveControlPlane: a, sync: o = {
|
|
743
|
+
resourceServers: !0,
|
|
744
|
+
roles: !0
|
|
745
|
+
}, defaultPermissions: l = ["tenant:admin"], requireOrganizationMatch: u = !1, managementApiExtensions: d = [], entityHooks: f, getChildTenantIds: p, getAdapters: m, ...h } = e;
|
|
746
|
+
if (a && !n) throw Error("initMultiTenant: `resolveControlPlane` requires `controlPlane` to be set. The static `controlPlane.tenantId` is used for access control, sync direction, and tenant management routing; the resolver only overrides per-tenant runtime inheritance lookups on top of it.");
|
|
747
|
+
let g = t, _ = t;
|
|
748
|
+
n && (g = G(t, {
|
|
749
|
+
controlPlaneTenantId: r,
|
|
750
|
+
controlPlaneClientId: i,
|
|
751
|
+
resolveControlPlane: a
|
|
752
|
+
}), _ = {
|
|
753
|
+
...V(t, {
|
|
754
|
+
controlPlaneTenantId: r,
|
|
755
|
+
resolveControlPlane: a
|
|
756
|
+
}),
|
|
757
|
+
multiTenancyConfig: {
|
|
758
|
+
controlPlaneTenantId: r,
|
|
759
|
+
controlPlaneClientId: i,
|
|
760
|
+
resolveControlPlane: a
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
let y = o !== !1, b = y ? {
|
|
764
|
+
resourceServers: o.resourceServers ?? !0,
|
|
765
|
+
roles: o.roles ?? !0
|
|
766
|
+
} : {
|
|
767
|
+
resourceServers: !1,
|
|
768
|
+
roles: !1
|
|
769
|
+
}, { entityHooks: x, tenantHooks: S } = D({
|
|
770
|
+
controlPlaneTenantId: r,
|
|
771
|
+
getChildTenantIds: p ?? (async () => (await s((e) => g.tenants.list(e), "tenants", {
|
|
772
|
+
cursorField: "id",
|
|
773
|
+
pageSize: 100
|
|
774
|
+
})).filter((e) => e.id !== r).map((e) => e.id)),
|
|
775
|
+
getAdapters: m ?? (async () => g),
|
|
776
|
+
getControlPlaneAdapters: async () => g,
|
|
777
|
+
sync: b
|
|
778
|
+
}), C = {
|
|
779
|
+
resourceServers: [x.resourceServers, ...f?.resourceServers ?? []],
|
|
780
|
+
roles: [x.roles, ...f?.roles ?? []],
|
|
781
|
+
connections: f?.connections ?? [],
|
|
782
|
+
tenants: f?.tenants ?? [],
|
|
783
|
+
rolePermissions: f?.rolePermissions ?? []
|
|
784
|
+
}, w = v({ accessControl: {
|
|
785
|
+
controlPlaneTenantId: r,
|
|
786
|
+
requireOrganizationMatch: u,
|
|
787
|
+
defaultPermissions: l
|
|
788
|
+
} }), T = k({ accessControl: {
|
|
789
|
+
controlPlaneTenantId: r,
|
|
790
|
+
requireOrganizationMatch: u,
|
|
791
|
+
defaultPermissions: l
|
|
792
|
+
} }, { tenants: {
|
|
793
|
+
async beforeCreate(e, t) {
|
|
794
|
+
return w.beforeCreate && (t = await w.beforeCreate(e, t)), S.beforeCreate && (t = await S.beforeCreate(e, t)), t;
|
|
795
|
+
},
|
|
796
|
+
async afterCreate(e, t) {
|
|
797
|
+
await w.afterCreate?.(e, t), await S.afterCreate?.(e, t);
|
|
798
|
+
},
|
|
799
|
+
async beforeDelete(e, t) {
|
|
800
|
+
await w.beforeDelete?.(e, t), await S.beforeDelete?.(e, t);
|
|
801
|
+
}
|
|
802
|
+
} }), { app: E } = c({
|
|
803
|
+
dataAdapter: g,
|
|
804
|
+
managementDataAdapter: _,
|
|
805
|
+
...h,
|
|
806
|
+
entityHooks: C,
|
|
807
|
+
managementApiExtensions: [...d, {
|
|
808
|
+
path: "/tenants",
|
|
809
|
+
router: T
|
|
810
|
+
}]
|
|
811
|
+
});
|
|
812
|
+
return E.use("/api/v2/*", K(r)), y && E.use("/api/v2/*", N()), {
|
|
813
|
+
app: E,
|
|
814
|
+
controlPlaneTenantId: r
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
//#endregion
|
|
818
|
+
//#region src/plugin.ts
|
|
819
|
+
function ee(e) {
|
|
820
|
+
let t = Q(e);
|
|
821
|
+
return {
|
|
822
|
+
name: "multi-tenancy",
|
|
823
|
+
middleware: X(e),
|
|
824
|
+
hooks: t,
|
|
825
|
+
routes: [{
|
|
826
|
+
path: "/management",
|
|
827
|
+
handler: k(e, t)
|
|
828
|
+
}],
|
|
829
|
+
onRegister: async () => {
|
|
830
|
+
console.log("Multi-tenancy plugin registered"), e.accessControl && console.log(` - Access control enabled (control plane: ${e.accessControl.controlPlaneTenantId})`), e.subdomainRouting && console.log(` - Subdomain routing enabled (base domain: ${e.subdomainRouting.baseDomain})`), e.databaseIsolation && console.log(" - Database isolation enabled");
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/index.ts
|
|
836
|
+
function Q(e) {
|
|
837
|
+
let t = e.accessControl ? m(e.accessControl) : {}, n = e.databaseIsolation ? g(e.databaseIsolation) : {}, r = v(e);
|
|
838
|
+
return {
|
|
839
|
+
...t,
|
|
840
|
+
...n,
|
|
841
|
+
tenants: r
|
|
842
|
+
};
|
|
1162
843
|
}
|
|
1163
|
-
function
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
return r();
|
|
1167
|
-
const n = t.var.tenant_id;
|
|
1168
|
-
if (!n)
|
|
1169
|
-
throw new P(400, {
|
|
1170
|
-
message: "Tenant ID not found in request"
|
|
1171
|
-
});
|
|
1172
|
-
try {
|
|
1173
|
-
const a = await e.databaseIsolation.getAdapters(n);
|
|
1174
|
-
t.env.data = a;
|
|
1175
|
-
} catch (a) {
|
|
1176
|
-
throw console.error(
|
|
1177
|
-
`Failed to resolve database for tenant ${n}:`,
|
|
1178
|
-
a
|
|
1179
|
-
), new P(500, {
|
|
1180
|
-
message: "Failed to resolve tenant database"
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
return r();
|
|
1184
|
-
};
|
|
844
|
+
function $(t) {
|
|
845
|
+
let n = new e(), r = Q(t);
|
|
846
|
+
return n.route("/tenants", k(t, r)), n;
|
|
1185
847
|
}
|
|
1186
848
|
function te(e) {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
} = {},
|
|
1201
|
-
resolveControlPlane: o,
|
|
1202
|
-
sync: c = { resourceServers: !0, roles: !0 },
|
|
1203
|
-
defaultPermissions: i = ["tenant:admin"],
|
|
1204
|
-
requireOrganizationMatch: l = !1,
|
|
1205
|
-
managementApiExtensions: u = [],
|
|
1206
|
-
entityHooks: s,
|
|
1207
|
-
getChildTenantIds: d,
|
|
1208
|
-
getAdapters: m,
|
|
1209
|
-
...w
|
|
1210
|
-
} = e;
|
|
1211
|
-
if (o && !r)
|
|
1212
|
-
throw new Error(
|
|
1213
|
-
"initMultiTenant: `resolveControlPlane` requires `controlPlane` to be set. The static `controlPlane.tenantId` is used for access control, sync direction, and tenant management routing; the resolver only overrides per-tenant runtime inheritance lookups on top of it."
|
|
1214
|
-
);
|
|
1215
|
-
let f = t, g = t;
|
|
1216
|
-
r && (f = ee(t, {
|
|
1217
|
-
controlPlaneTenantId: n,
|
|
1218
|
-
controlPlaneClientId: a,
|
|
1219
|
-
resolveControlPlane: o
|
|
1220
|
-
}), g = {
|
|
1221
|
-
...Ie(t, {
|
|
1222
|
-
controlPlaneTenantId: n,
|
|
1223
|
-
resolveControlPlane: o
|
|
1224
|
-
}),
|
|
1225
|
-
multiTenancyConfig: {
|
|
1226
|
-
controlPlaneTenantId: n,
|
|
1227
|
-
controlPlaneClientId: a,
|
|
1228
|
-
resolveControlPlane: o
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
const _ = c !== !1, h = _ ? {
|
|
1232
|
-
resourceServers: c.resourceServers ?? !0,
|
|
1233
|
-
roles: c.roles ?? !0
|
|
1234
|
-
} : { resourceServers: !1, roles: !1 }, z = {
|
|
1235
|
-
controlPlaneTenantId: n,
|
|
1236
|
-
getChildTenantIds: d ?? (async () => (await q(
|
|
1237
|
-
(y) => f.tenants.list(y),
|
|
1238
|
-
"tenants",
|
|
1239
|
-
{ cursorField: "id", pageSize: 100 }
|
|
1240
|
-
)).filter((y) => y.id !== n).map((y) => y.id)),
|
|
1241
|
-
getAdapters: m ?? (async () => f),
|
|
1242
|
-
getControlPlaneAdapters: async () => f,
|
|
1243
|
-
sync: h
|
|
1244
|
-
}, { entityHooks: v, tenantHooks: p } = ve(z), C = {
|
|
1245
|
-
resourceServers: [
|
|
1246
|
-
v.resourceServers,
|
|
1247
|
-
...(s == null ? void 0 : s.resourceServers) ?? []
|
|
1248
|
-
],
|
|
1249
|
-
roles: [v.roles, ...(s == null ? void 0 : s.roles) ?? []],
|
|
1250
|
-
connections: (s == null ? void 0 : s.connections) ?? [],
|
|
1251
|
-
tenants: (s == null ? void 0 : s.tenants) ?? [],
|
|
1252
|
-
rolePermissions: (s == null ? void 0 : s.rolePermissions) ?? []
|
|
1253
|
-
}, I = Y({
|
|
1254
|
-
accessControl: {
|
|
1255
|
-
controlPlaneTenantId: n,
|
|
1256
|
-
requireOrganizationMatch: l,
|
|
1257
|
-
defaultPermissions: i
|
|
1258
|
-
}
|
|
1259
|
-
}), k = B(
|
|
1260
|
-
{
|
|
1261
|
-
accessControl: {
|
|
1262
|
-
controlPlaneTenantId: n,
|
|
1263
|
-
requireOrganizationMatch: l,
|
|
1264
|
-
defaultPermissions: i
|
|
1265
|
-
}
|
|
1266
|
-
},
|
|
1267
|
-
{ tenants: {
|
|
1268
|
-
async beforeCreate(A, y) {
|
|
1269
|
-
return I.beforeCreate && (y = await I.beforeCreate(A, y)), p.beforeCreate && (y = await p.beforeCreate(A, y)), y;
|
|
1270
|
-
},
|
|
1271
|
-
async afterCreate(A, y) {
|
|
1272
|
-
var $, R;
|
|
1273
|
-
await (($ = I.afterCreate) == null ? void 0 : $.call(I, A, y)), await ((R = p.afterCreate) == null ? void 0 : R.call(p, A, y));
|
|
1274
|
-
},
|
|
1275
|
-
async beforeDelete(A, y) {
|
|
1276
|
-
var $, R;
|
|
1277
|
-
await (($ = I.beforeDelete) == null ? void 0 : $.call(I, A, y)), await ((R = p.beforeDelete) == null ? void 0 : R.call(p, A, y));
|
|
1278
|
-
}
|
|
1279
|
-
} }
|
|
1280
|
-
), { app: F } = ue({
|
|
1281
|
-
dataAdapter: f,
|
|
1282
|
-
managementDataAdapter: g,
|
|
1283
|
-
...w,
|
|
1284
|
-
entityHooks: C,
|
|
1285
|
-
managementApiExtensions: [
|
|
1286
|
-
...u,
|
|
1287
|
-
{ path: "/tenants", router: k }
|
|
1288
|
-
]
|
|
1289
|
-
});
|
|
1290
|
-
return F.use(
|
|
1291
|
-
"/api/v2/*",
|
|
1292
|
-
Re(n)
|
|
1293
|
-
), _ && F.use("/api/v2/*", Pe()), { app: F, controlPlaneTenantId: n };
|
|
1294
|
-
}
|
|
1295
|
-
function Ne(e) {
|
|
1296
|
-
const t = U(e);
|
|
1297
|
-
return {
|
|
1298
|
-
name: "multi-tenancy",
|
|
1299
|
-
// Apply multi-tenancy middleware for subdomain routing, database resolution, etc.
|
|
1300
|
-
middleware: te(e),
|
|
1301
|
-
// Provide lifecycle hooks
|
|
1302
|
-
hooks: t,
|
|
1303
|
-
// Mount tenant management routes
|
|
1304
|
-
routes: [
|
|
1305
|
-
{
|
|
1306
|
-
path: "/management",
|
|
1307
|
-
handler: B(e, t)
|
|
1308
|
-
}
|
|
1309
|
-
],
|
|
1310
|
-
// Called when plugin is registered
|
|
1311
|
-
onRegister: async () => {
|
|
1312
|
-
console.log("Multi-tenancy plugin registered"), e.accessControl && console.log(
|
|
1313
|
-
` - Access control enabled (control plane: ${e.accessControl.controlPlaneTenantId})`
|
|
1314
|
-
), e.subdomainRouting && console.log(
|
|
1315
|
-
` - Subdomain routing enabled (base domain: ${e.subdomainRouting.baseDomain})`
|
|
1316
|
-
), e.databaseIsolation && console.log(" - Database isolation enabled");
|
|
1317
|
-
}
|
|
1318
|
-
};
|
|
1319
|
-
}
|
|
1320
|
-
function U(e) {
|
|
1321
|
-
const t = e.accessControl ? fe(e.accessControl) : {}, r = e.databaseIsolation ? ge(e.databaseIsolation) : {}, n = Y(e);
|
|
1322
|
-
return {
|
|
1323
|
-
...t,
|
|
1324
|
-
...r,
|
|
1325
|
-
tenants: n
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
function ke(e) {
|
|
1329
|
-
const t = new ae(), r = U(e);
|
|
1330
|
-
return t.route("/tenants", B(e, r)), t;
|
|
1331
|
-
}
|
|
1332
|
-
function Be(e) {
|
|
1333
|
-
return {
|
|
1334
|
-
hooks: U(e),
|
|
1335
|
-
middleware: te(e),
|
|
1336
|
-
app: ke(e),
|
|
1337
|
-
config: e,
|
|
1338
|
-
/**
|
|
1339
|
-
* Wraps data adapters with runtime fallback from the control plane.
|
|
1340
|
-
* Uses the controlPlaneTenantId from the multi-tenancy config.
|
|
1341
|
-
*
|
|
1342
|
-
* @param adapters - Base data adapters to wrap
|
|
1343
|
-
* @param additionalConfig - Additional config (controlPlaneClientId, etc.)
|
|
1344
|
-
* @returns Wrapped adapters with runtime fallback
|
|
1345
|
-
*/
|
|
1346
|
-
wrapAdapters: (t, r) => {
|
|
1347
|
-
var n;
|
|
1348
|
-
return ee(t, {
|
|
1349
|
-
controlPlaneTenantId: (n = e.accessControl) == null ? void 0 : n.controlPlaneTenantId,
|
|
1350
|
-
controlPlaneClientId: r == null ? void 0 : r.controlPlaneClientId
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
|
-
export {
|
|
1356
|
-
fe as createAccessControlHooks,
|
|
1357
|
-
ze as createAccessControlMiddleware,
|
|
1358
|
-
Re as createControlPlaneTenantMiddleware,
|
|
1359
|
-
ge as createDatabaseHooks,
|
|
1360
|
-
je as createDatabaseMiddleware,
|
|
1361
|
-
ke as createMultiTenancy,
|
|
1362
|
-
U as createMultiTenancyHooks,
|
|
1363
|
-
te as createMultiTenancyMiddleware,
|
|
1364
|
-
Ne as createMultiTenancyPlugin,
|
|
1365
|
-
Pe as createProtectSyncedMiddleware,
|
|
1366
|
-
Y as createProvisioningHooks,
|
|
1367
|
-
Ae as createRuntimeFallbackAdapter,
|
|
1368
|
-
$e as createSubdomainMiddleware,
|
|
1369
|
-
ve as createSyncHooks,
|
|
1370
|
-
B as createTenantsOpenAPIRouter,
|
|
1371
|
-
Ee as initMultiTenant,
|
|
1372
|
-
Oe as mergeClientWithFallback,
|
|
1373
|
-
Be as setupMultiTenancy,
|
|
1374
|
-
me as validateTenantAccess,
|
|
1375
|
-
ee as withRuntimeFallback,
|
|
1376
|
-
Ie as withSystemResourceServerInheritance
|
|
1377
|
-
};
|
|
849
|
+
return {
|
|
850
|
+
hooks: Q(e),
|
|
851
|
+
middleware: X(e),
|
|
852
|
+
app: $(e),
|
|
853
|
+
config: e,
|
|
854
|
+
wrapAdapters: (t, n) => G(t, {
|
|
855
|
+
controlPlaneTenantId: e.accessControl?.controlPlaneTenantId,
|
|
856
|
+
controlPlaneClientId: n?.controlPlaneClientId
|
|
857
|
+
})
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
//#endregion
|
|
861
|
+
export { m as createAccessControlHooks, q as createAccessControlMiddleware, K as createControlPlaneTenantMiddleware, g as createDatabaseHooks, Y as createDatabaseMiddleware, $ as createMultiTenancy, Q as createMultiTenancyHooks, X as createMultiTenancyMiddleware, ee as createMultiTenancyPlugin, N as createProtectSyncedMiddleware, v as createProvisioningHooks, H as createRuntimeFallbackAdapter, J as createSubdomainMiddleware, D as createSyncHooks, k as createTenantsOpenAPIRouter, Z as initMultiTenant, R as mergeClientWithFallback, te as setupMultiTenancy, h as validateTenantAccess, G as withRuntimeFallback, V as withSystemResourceServerInheritance };
|