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