@dyrected/core 2.13.4 → 2.13.5
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/index.cjs +13 -11
- package/dist/index.js +13 -11
- package/dist/server.cjs +39 -15
- package/dist/server.d.cts +13 -5
- package/dist/server.d.ts +13 -5
- package/dist/server.js +39 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2085,7 +2085,7 @@ function publicMetadata(meta) {
|
|
|
2085
2085
|
}
|
|
2086
2086
|
function workflowCapabilities(workflow, user) {
|
|
2087
2087
|
const capabilities = new Set(Array.isArray(user?.capabilities) ? user.capabilities : []);
|
|
2088
|
-
const roles = Array.isArray(user?.roles) ? user.roles : [];
|
|
2088
|
+
const roles = Array.isArray(user?.roles) ? user.roles : typeof user?.role === "string" ? [user.role] : [];
|
|
2089
2089
|
for (const mapping of workflow.roles ?? []) {
|
|
2090
2090
|
if (roles.includes(mapping.role)) mapping.capabilities.forEach((capability) => capabilities.add(capability));
|
|
2091
2091
|
}
|
|
@@ -2476,10 +2476,12 @@ function getAdminRoleForCollection(collection) {
|
|
|
2476
2476
|
return "admin";
|
|
2477
2477
|
}
|
|
2478
2478
|
function isUserAdmin(user, collection) {
|
|
2479
|
-
if (!user
|
|
2479
|
+
if (!user) return false;
|
|
2480
|
+
const roles = Array.isArray(user.roles) ? user.roles : typeof user.role === "string" ? [user.role] : [];
|
|
2481
|
+
if (roles.length === 0) return false;
|
|
2480
2482
|
const configuredRole = getAdminRoleForCollection(collection);
|
|
2481
|
-
if (
|
|
2482
|
-
return
|
|
2483
|
+
if (roles.includes(configuredRole)) return true;
|
|
2484
|
+
return roles.includes("admin") || roles.includes("super_admin");
|
|
2483
2485
|
}
|
|
2484
2486
|
|
|
2485
2487
|
// src/utils/block-references.ts
|
|
@@ -3705,7 +3707,7 @@ function normalizeConfig(config) {
|
|
|
3705
3707
|
}
|
|
3706
3708
|
];
|
|
3707
3709
|
}
|
|
3708
|
-
if (!existingFieldNames.has("roles")) {
|
|
3710
|
+
if (!existingFieldNames.has("roles") && !existingFieldNames.has("role")) {
|
|
3709
3711
|
fields = [
|
|
3710
3712
|
...fields,
|
|
3711
3713
|
{
|
|
@@ -3719,7 +3721,7 @@ function normalizeConfig(config) {
|
|
|
3719
3721
|
{ value: "viewer", label: "Viewer" }
|
|
3720
3722
|
],
|
|
3721
3723
|
access: {
|
|
3722
|
-
update: "user.roles && 'admin' in user.roles"
|
|
3724
|
+
update: "user.role == 'admin' || (user.roles != null && 'admin' in user.roles)"
|
|
3723
3725
|
}
|
|
3724
3726
|
}
|
|
3725
3727
|
];
|
|
@@ -3737,10 +3739,10 @@ function normalizeConfig(config) {
|
|
|
3737
3739
|
{ value: "pending", label: "Pending" }
|
|
3738
3740
|
],
|
|
3739
3741
|
access: {
|
|
3740
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3742
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3741
3743
|
},
|
|
3742
3744
|
admin: {
|
|
3743
|
-
condition: `!(data.roles && "admin" in data.roles)`
|
|
3745
|
+
condition: `!(data.roles && "admin" in data.roles) && data.role != "admin"`
|
|
3744
3746
|
}
|
|
3745
3747
|
}
|
|
3746
3748
|
];
|
|
@@ -3774,13 +3776,13 @@ function normalizeConfig(config) {
|
|
|
3774
3776
|
}
|
|
3775
3777
|
};
|
|
3776
3778
|
}
|
|
3777
|
-
if (field.name === "roles") {
|
|
3779
|
+
if (field.name === "roles" || field.name === "role") {
|
|
3778
3780
|
return {
|
|
3779
3781
|
...field,
|
|
3780
3782
|
access: {
|
|
3781
3783
|
...field.access || {},
|
|
3782
3784
|
// Must be an admin; cannot edit own roles (no self-elevation).
|
|
3783
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3785
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3784
3786
|
}
|
|
3785
3787
|
};
|
|
3786
3788
|
}
|
|
@@ -3789,7 +3791,7 @@ function normalizeConfig(config) {
|
|
|
3789
3791
|
...field,
|
|
3790
3792
|
access: {
|
|
3791
3793
|
...field.access || {},
|
|
3792
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3794
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3793
3795
|
}
|
|
3794
3796
|
};
|
|
3795
3797
|
}
|
package/dist/index.js
CHANGED
|
@@ -1911,7 +1911,7 @@ function publicMetadata(meta) {
|
|
|
1911
1911
|
}
|
|
1912
1912
|
function workflowCapabilities(workflow, user) {
|
|
1913
1913
|
const capabilities = new Set(Array.isArray(user?.capabilities) ? user.capabilities : []);
|
|
1914
|
-
const roles = Array.isArray(user?.roles) ? user.roles : [];
|
|
1914
|
+
const roles = Array.isArray(user?.roles) ? user.roles : typeof user?.role === "string" ? [user.role] : [];
|
|
1915
1915
|
for (const mapping of workflow.roles ?? []) {
|
|
1916
1916
|
if (roles.includes(mapping.role)) mapping.capabilities.forEach((capability) => capabilities.add(capability));
|
|
1917
1917
|
}
|
|
@@ -2302,10 +2302,12 @@ function getAdminRoleForCollection(collection) {
|
|
|
2302
2302
|
return "admin";
|
|
2303
2303
|
}
|
|
2304
2304
|
function isUserAdmin(user, collection) {
|
|
2305
|
-
if (!user
|
|
2305
|
+
if (!user) return false;
|
|
2306
|
+
const roles = Array.isArray(user.roles) ? user.roles : typeof user.role === "string" ? [user.role] : [];
|
|
2307
|
+
if (roles.length === 0) return false;
|
|
2306
2308
|
const configuredRole = getAdminRoleForCollection(collection);
|
|
2307
|
-
if (
|
|
2308
|
-
return
|
|
2309
|
+
if (roles.includes(configuredRole)) return true;
|
|
2310
|
+
return roles.includes("admin") || roles.includes("super_admin");
|
|
2309
2311
|
}
|
|
2310
2312
|
|
|
2311
2313
|
// src/utils/block-references.ts
|
|
@@ -3531,7 +3533,7 @@ function normalizeConfig(config) {
|
|
|
3531
3533
|
}
|
|
3532
3534
|
];
|
|
3533
3535
|
}
|
|
3534
|
-
if (!existingFieldNames.has("roles")) {
|
|
3536
|
+
if (!existingFieldNames.has("roles") && !existingFieldNames.has("role")) {
|
|
3535
3537
|
fields = [
|
|
3536
3538
|
...fields,
|
|
3537
3539
|
{
|
|
@@ -3545,7 +3547,7 @@ function normalizeConfig(config) {
|
|
|
3545
3547
|
{ value: "viewer", label: "Viewer" }
|
|
3546
3548
|
],
|
|
3547
3549
|
access: {
|
|
3548
|
-
update: "user.roles && 'admin' in user.roles"
|
|
3550
|
+
update: "user.role == 'admin' || (user.roles != null && 'admin' in user.roles)"
|
|
3549
3551
|
}
|
|
3550
3552
|
}
|
|
3551
3553
|
];
|
|
@@ -3563,10 +3565,10 @@ function normalizeConfig(config) {
|
|
|
3563
3565
|
{ value: "pending", label: "Pending" }
|
|
3564
3566
|
],
|
|
3565
3567
|
access: {
|
|
3566
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3568
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3567
3569
|
},
|
|
3568
3570
|
admin: {
|
|
3569
|
-
condition: `!(data.roles && "admin" in data.roles)`
|
|
3571
|
+
condition: `!(data.roles && "admin" in data.roles) && data.role != "admin"`
|
|
3570
3572
|
}
|
|
3571
3573
|
}
|
|
3572
3574
|
];
|
|
@@ -3600,13 +3602,13 @@ function normalizeConfig(config) {
|
|
|
3600
3602
|
}
|
|
3601
3603
|
};
|
|
3602
3604
|
}
|
|
3603
|
-
if (field.name === "roles") {
|
|
3605
|
+
if (field.name === "roles" || field.name === "role") {
|
|
3604
3606
|
return {
|
|
3605
3607
|
...field,
|
|
3606
3608
|
access: {
|
|
3607
3609
|
...field.access || {},
|
|
3608
3610
|
// Must be an admin; cannot edit own roles (no self-elevation).
|
|
3609
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3611
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3610
3612
|
}
|
|
3611
3613
|
};
|
|
3612
3614
|
}
|
|
@@ -3615,7 +3617,7 @@ function normalizeConfig(config) {
|
|
|
3615
3617
|
...field,
|
|
3616
3618
|
access: {
|
|
3617
3619
|
...field.access || {},
|
|
3618
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
3620
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
3619
3621
|
}
|
|
3620
3622
|
};
|
|
3621
3623
|
}
|
package/dist/server.cjs
CHANGED
|
@@ -6190,10 +6190,12 @@ function getAdminRoleForCollection(collection) {
|
|
|
6190
6190
|
return "admin";
|
|
6191
6191
|
}
|
|
6192
6192
|
function isUserAdmin(user, collection) {
|
|
6193
|
-
if (!user
|
|
6193
|
+
if (!user) return false;
|
|
6194
|
+
const roles = Array.isArray(user.roles) ? user.roles : typeof user.role === "string" ? [user.role] : [];
|
|
6195
|
+
if (roles.length === 0) return false;
|
|
6194
6196
|
const configuredRole = getAdminRoleForCollection(collection);
|
|
6195
|
-
if (
|
|
6196
|
-
return
|
|
6197
|
+
if (roles.includes(configuredRole)) return true;
|
|
6198
|
+
return roles.includes("admin") || roles.includes("super_admin");
|
|
6197
6199
|
}
|
|
6198
6200
|
|
|
6199
6201
|
// src/utils/collection-search.ts
|
|
@@ -6449,7 +6451,7 @@ function publicMetadata(meta) {
|
|
|
6449
6451
|
}
|
|
6450
6452
|
function workflowCapabilities(workflow, user) {
|
|
6451
6453
|
const capabilities = new Set(Array.isArray(user?.capabilities) ? user.capabilities : []);
|
|
6452
|
-
const roles = Array.isArray(user?.roles) ? user.roles : [];
|
|
6454
|
+
const roles = Array.isArray(user?.roles) ? user.roles : typeof user?.role === "string" ? [user.role] : [];
|
|
6453
6455
|
for (const mapping of workflow.roles ?? []) {
|
|
6454
6456
|
if (roles.includes(mapping.role)) mapping.capabilities.forEach((capability) => capabilities.add(capability));
|
|
6455
6457
|
}
|
|
@@ -9526,7 +9528,14 @@ var AuthController = class {
|
|
|
9526
9528
|
lockedUntil: _lockedUntil,
|
|
9527
9529
|
...safeUser
|
|
9528
9530
|
} = user;
|
|
9529
|
-
|
|
9531
|
+
const roles = Array.isArray(safeUser.roles) ? safeUser.roles : typeof safeUser.role === "string" ? [safeUser.role] : [];
|
|
9532
|
+
const role = typeof safeUser.role === "string" ? safeUser.role : roles[0];
|
|
9533
|
+
return {
|
|
9534
|
+
...safeUser,
|
|
9535
|
+
collection: safeUser.collection || this.collection.slug,
|
|
9536
|
+
...role !== void 0 ? { role } : {},
|
|
9537
|
+
roles
|
|
9538
|
+
};
|
|
9530
9539
|
}
|
|
9531
9540
|
hasField(name) {
|
|
9532
9541
|
return (this.collection.fields || []).some((field) => field.name === name);
|
|
@@ -9654,13 +9663,16 @@ var AuthController = class {
|
|
|
9654
9663
|
}
|
|
9655
9664
|
}
|
|
9656
9665
|
}
|
|
9666
|
+
const hasRoleField = this.collection.fields?.some((f) => f.name === "role");
|
|
9667
|
+
const hasRolesField = this.collection.fields?.some((f) => f.name === "roles");
|
|
9668
|
+
const rolePayload = hasRoleField && !hasRolesField ? { role: initialRole } : { roles: [initialRole] };
|
|
9657
9669
|
const hashedPassword = await hashPassword(body.password);
|
|
9658
9670
|
const user = await db.create({
|
|
9659
9671
|
collection: this.collection.slug,
|
|
9660
9672
|
data: {
|
|
9661
9673
|
...body,
|
|
9662
9674
|
password: hashedPassword,
|
|
9663
|
-
|
|
9675
|
+
...rolePayload
|
|
9664
9676
|
}
|
|
9665
9677
|
});
|
|
9666
9678
|
const token = await issueAuthSessionToken({
|
|
@@ -9828,7 +9840,10 @@ var AuthController = class {
|
|
|
9828
9840
|
return c.json({ error: true, message: "User not found." }, 404);
|
|
9829
9841
|
}
|
|
9830
9842
|
const safeUser = this.sanitizeUser(user);
|
|
9831
|
-
return c.json(
|
|
9843
|
+
return c.json({
|
|
9844
|
+
...safeUser,
|
|
9845
|
+
collection: this.collection.slug
|
|
9846
|
+
});
|
|
9832
9847
|
}
|
|
9833
9848
|
// ---------------------------------------------------------------------------
|
|
9834
9849
|
// POST /refresh-token
|
|
@@ -12054,8 +12069,12 @@ async function resolveUser(payload, config) {
|
|
|
12054
12069
|
return null;
|
|
12055
12070
|
}
|
|
12056
12071
|
const { password: _password, ...safe } = doc;
|
|
12072
|
+
const roles = Array.isArray(safe.roles) ? safe.roles : typeof safe.role === "string" ? [safe.role] : [];
|
|
12073
|
+
const role = typeof safe.role === "string" ? safe.role : roles[0];
|
|
12057
12074
|
return {
|
|
12058
12075
|
...safe,
|
|
12076
|
+
...role !== void 0 ? { role } : {},
|
|
12077
|
+
roles,
|
|
12059
12078
|
sub: payload.sub,
|
|
12060
12079
|
email: payload.email ?? safe.email,
|
|
12061
12080
|
collection: payload.collection
|
|
@@ -12137,7 +12156,12 @@ function optionalAuth(config) {
|
|
|
12137
12156
|
c.set("user", user);
|
|
12138
12157
|
}
|
|
12139
12158
|
c.set("authTokenPayload", resolved.payload);
|
|
12140
|
-
} catch {
|
|
12159
|
+
} catch (err) {
|
|
12160
|
+
getConfigLogger(config ?? c.get("config"), "auth").warn({
|
|
12161
|
+
err,
|
|
12162
|
+
msg: "optionalAuth failed to resolve token",
|
|
12163
|
+
path: c.req.path
|
|
12164
|
+
});
|
|
12141
12165
|
}
|
|
12142
12166
|
}
|
|
12143
12167
|
await next();
|
|
@@ -14638,7 +14662,7 @@ function normalizeConfig(config) {
|
|
|
14638
14662
|
}
|
|
14639
14663
|
];
|
|
14640
14664
|
}
|
|
14641
|
-
if (!existingFieldNames.has("roles")) {
|
|
14665
|
+
if (!existingFieldNames.has("roles") && !existingFieldNames.has("role")) {
|
|
14642
14666
|
fields = [
|
|
14643
14667
|
...fields,
|
|
14644
14668
|
{
|
|
@@ -14652,7 +14676,7 @@ function normalizeConfig(config) {
|
|
|
14652
14676
|
{ value: "viewer", label: "Viewer" }
|
|
14653
14677
|
],
|
|
14654
14678
|
access: {
|
|
14655
|
-
update: "user.roles && 'admin' in user.roles"
|
|
14679
|
+
update: "user.role == 'admin' || (user.roles != null && 'admin' in user.roles)"
|
|
14656
14680
|
}
|
|
14657
14681
|
}
|
|
14658
14682
|
];
|
|
@@ -14670,10 +14694,10 @@ function normalizeConfig(config) {
|
|
|
14670
14694
|
{ value: "pending", label: "Pending" }
|
|
14671
14695
|
],
|
|
14672
14696
|
access: {
|
|
14673
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14697
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14674
14698
|
},
|
|
14675
14699
|
admin: {
|
|
14676
|
-
condition: `!(data.roles && "admin" in data.roles)`
|
|
14700
|
+
condition: `!(data.roles && "admin" in data.roles) && data.role != "admin"`
|
|
14677
14701
|
}
|
|
14678
14702
|
}
|
|
14679
14703
|
];
|
|
@@ -14707,13 +14731,13 @@ function normalizeConfig(config) {
|
|
|
14707
14731
|
}
|
|
14708
14732
|
};
|
|
14709
14733
|
}
|
|
14710
|
-
if (field.name === "roles") {
|
|
14734
|
+
if (field.name === "roles" || field.name === "role") {
|
|
14711
14735
|
return {
|
|
14712
14736
|
...field,
|
|
14713
14737
|
access: {
|
|
14714
14738
|
...field.access || {},
|
|
14715
14739
|
// Must be an admin; cannot edit own roles (no self-elevation).
|
|
14716
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14740
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14717
14741
|
}
|
|
14718
14742
|
};
|
|
14719
14743
|
}
|
|
@@ -14722,7 +14746,7 @@ function normalizeConfig(config) {
|
|
|
14722
14746
|
...field,
|
|
14723
14747
|
access: {
|
|
14724
14748
|
...field.access || {},
|
|
14725
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14749
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14726
14750
|
}
|
|
14727
14751
|
};
|
|
14728
14752
|
}
|
package/dist/server.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as
|
|
|
2
2
|
export { cV as DyrectedObservabilityRuntime, cW as RequestBodyCapture, cX as RequestTraceContext, cY as ResolvedObservabilityConfig, cZ as attachRequestMetrics, c_ as bindObservabilityRuntime, c$ as buildRequestLogger, d0 as captureRequestBody, d1 as createDyrectedApp, d2 as createObservabilityRuntime, d3 as createRequestSpan, d4 as endRequestSpan, d5 as getConfigLogger, d6 as getObservabilityRuntime, d7 as getRequestLogger, d8 as redactBody, d9 as redactHeaders, da as renderPrometheusMetrics, db as resolveObservabilityConfig, dc as shouldSampleRequest } from './app-De-3eNn1.cjs';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { Hono, Context, Next } from 'hono';
|
|
5
|
-
import * as hono_utils_types from 'hono/utils/types';
|
|
6
5
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
6
|
+
import * as hono_utils_types from 'hono/utils/types';
|
|
7
7
|
import { LanguageModel, EmbeddingModel } from 'ai';
|
|
8
8
|
import 'hono/types';
|
|
9
9
|
import 'pino';
|
|
@@ -63,7 +63,9 @@ declare class AuthController {
|
|
|
63
63
|
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
64
64
|
token: string;
|
|
65
65
|
user: {
|
|
66
|
-
|
|
66
|
+
roles: any[];
|
|
67
|
+
role?: any;
|
|
68
|
+
collection: string;
|
|
67
69
|
};
|
|
68
70
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
69
71
|
login(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
@@ -84,7 +86,9 @@ declare class AuthController {
|
|
|
84
86
|
}, 429, "json">) | (Response & hono.TypedResponse<{
|
|
85
87
|
token: string;
|
|
86
88
|
user: {
|
|
87
|
-
|
|
89
|
+
roles: any[];
|
|
90
|
+
role?: any;
|
|
91
|
+
collection: string;
|
|
88
92
|
};
|
|
89
93
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
90
94
|
logout(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
@@ -103,7 +107,9 @@ declare class AuthController {
|
|
|
103
107
|
error: true;
|
|
104
108
|
message: string;
|
|
105
109
|
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
106
|
-
|
|
110
|
+
collection: string;
|
|
111
|
+
roles: any[];
|
|
112
|
+
role?: any;
|
|
107
113
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
108
114
|
refreshToken(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
109
115
|
error: true;
|
|
@@ -160,7 +166,9 @@ declare class AuthController {
|
|
|
160
166
|
}, 409, "json">) | (Response & hono.TypedResponse<{
|
|
161
167
|
token: string;
|
|
162
168
|
user: {
|
|
163
|
-
|
|
169
|
+
roles: any[];
|
|
170
|
+
role?: any;
|
|
171
|
+
collection: string;
|
|
164
172
|
};
|
|
165
173
|
}, 201, "json">)>;
|
|
166
174
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as
|
|
|
2
2
|
export { cV as DyrectedObservabilityRuntime, cW as RequestBodyCapture, cX as RequestTraceContext, cY as ResolvedObservabilityConfig, cZ as attachRequestMetrics, c_ as bindObservabilityRuntime, c$ as buildRequestLogger, d0 as captureRequestBody, d1 as createDyrectedApp, d2 as createObservabilityRuntime, d3 as createRequestSpan, d4 as endRequestSpan, d5 as getConfigLogger, d6 as getObservabilityRuntime, d7 as getRequestLogger, d8 as redactBody, d9 as redactHeaders, da as renderPrometheusMetrics, db as resolveObservabilityConfig, dc as shouldSampleRequest } from './app-De-3eNn1.js';
|
|
3
3
|
import * as hono from 'hono';
|
|
4
4
|
import { Hono, Context, Next } from 'hono';
|
|
5
|
-
import * as hono_utils_types from 'hono/utils/types';
|
|
6
5
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
6
|
+
import * as hono_utils_types from 'hono/utils/types';
|
|
7
7
|
import { LanguageModel, EmbeddingModel } from 'ai';
|
|
8
8
|
import 'hono/types';
|
|
9
9
|
import 'pino';
|
|
@@ -63,7 +63,9 @@ declare class AuthController {
|
|
|
63
63
|
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
64
64
|
token: string;
|
|
65
65
|
user: {
|
|
66
|
-
|
|
66
|
+
roles: any[];
|
|
67
|
+
role?: any;
|
|
68
|
+
collection: string;
|
|
67
69
|
};
|
|
68
70
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
69
71
|
login(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
@@ -84,7 +86,9 @@ declare class AuthController {
|
|
|
84
86
|
}, 429, "json">) | (Response & hono.TypedResponse<{
|
|
85
87
|
token: string;
|
|
86
88
|
user: {
|
|
87
|
-
|
|
89
|
+
roles: any[];
|
|
90
|
+
role?: any;
|
|
91
|
+
collection: string;
|
|
88
92
|
};
|
|
89
93
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
90
94
|
logout(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
@@ -103,7 +107,9 @@ declare class AuthController {
|
|
|
103
107
|
error: true;
|
|
104
108
|
message: string;
|
|
105
109
|
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
106
|
-
|
|
110
|
+
collection: string;
|
|
111
|
+
roles: any[];
|
|
112
|
+
role?: any;
|
|
107
113
|
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
108
114
|
refreshToken(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
109
115
|
error: true;
|
|
@@ -160,7 +166,9 @@ declare class AuthController {
|
|
|
160
166
|
}, 409, "json">) | (Response & hono.TypedResponse<{
|
|
161
167
|
token: string;
|
|
162
168
|
user: {
|
|
163
|
-
|
|
169
|
+
roles: any[];
|
|
170
|
+
role?: any;
|
|
171
|
+
collection: string;
|
|
164
172
|
};
|
|
165
173
|
}, 201, "json">)>;
|
|
166
174
|
}
|
package/dist/server.js
CHANGED
|
@@ -6154,10 +6154,12 @@ function getAdminRoleForCollection(collection) {
|
|
|
6154
6154
|
return "admin";
|
|
6155
6155
|
}
|
|
6156
6156
|
function isUserAdmin(user, collection) {
|
|
6157
|
-
if (!user
|
|
6157
|
+
if (!user) return false;
|
|
6158
|
+
const roles = Array.isArray(user.roles) ? user.roles : typeof user.role === "string" ? [user.role] : [];
|
|
6159
|
+
if (roles.length === 0) return false;
|
|
6158
6160
|
const configuredRole = getAdminRoleForCollection(collection);
|
|
6159
|
-
if (
|
|
6160
|
-
return
|
|
6161
|
+
if (roles.includes(configuredRole)) return true;
|
|
6162
|
+
return roles.includes("admin") || roles.includes("super_admin");
|
|
6161
6163
|
}
|
|
6162
6164
|
|
|
6163
6165
|
// src/utils/collection-search.ts
|
|
@@ -6413,7 +6415,7 @@ function publicMetadata(meta) {
|
|
|
6413
6415
|
}
|
|
6414
6416
|
function workflowCapabilities(workflow, user) {
|
|
6415
6417
|
const capabilities = new Set(Array.isArray(user?.capabilities) ? user.capabilities : []);
|
|
6416
|
-
const roles = Array.isArray(user?.roles) ? user.roles : [];
|
|
6418
|
+
const roles = Array.isArray(user?.roles) ? user.roles : typeof user?.role === "string" ? [user.role] : [];
|
|
6417
6419
|
for (const mapping of workflow.roles ?? []) {
|
|
6418
6420
|
if (roles.includes(mapping.role)) mapping.capabilities.forEach((capability) => capabilities.add(capability));
|
|
6419
6421
|
}
|
|
@@ -9490,7 +9492,14 @@ var AuthController = class {
|
|
|
9490
9492
|
lockedUntil: _lockedUntil,
|
|
9491
9493
|
...safeUser
|
|
9492
9494
|
} = user;
|
|
9493
|
-
|
|
9495
|
+
const roles = Array.isArray(safeUser.roles) ? safeUser.roles : typeof safeUser.role === "string" ? [safeUser.role] : [];
|
|
9496
|
+
const role = typeof safeUser.role === "string" ? safeUser.role : roles[0];
|
|
9497
|
+
return {
|
|
9498
|
+
...safeUser,
|
|
9499
|
+
collection: safeUser.collection || this.collection.slug,
|
|
9500
|
+
...role !== void 0 ? { role } : {},
|
|
9501
|
+
roles
|
|
9502
|
+
};
|
|
9494
9503
|
}
|
|
9495
9504
|
hasField(name) {
|
|
9496
9505
|
return (this.collection.fields || []).some((field) => field.name === name);
|
|
@@ -9618,13 +9627,16 @@ var AuthController = class {
|
|
|
9618
9627
|
}
|
|
9619
9628
|
}
|
|
9620
9629
|
}
|
|
9630
|
+
const hasRoleField = this.collection.fields?.some((f) => f.name === "role");
|
|
9631
|
+
const hasRolesField = this.collection.fields?.some((f) => f.name === "roles");
|
|
9632
|
+
const rolePayload = hasRoleField && !hasRolesField ? { role: initialRole } : { roles: [initialRole] };
|
|
9621
9633
|
const hashedPassword = await hashPassword(body.password);
|
|
9622
9634
|
const user = await db.create({
|
|
9623
9635
|
collection: this.collection.slug,
|
|
9624
9636
|
data: {
|
|
9625
9637
|
...body,
|
|
9626
9638
|
password: hashedPassword,
|
|
9627
|
-
|
|
9639
|
+
...rolePayload
|
|
9628
9640
|
}
|
|
9629
9641
|
});
|
|
9630
9642
|
const token = await issueAuthSessionToken({
|
|
@@ -9792,7 +9804,10 @@ var AuthController = class {
|
|
|
9792
9804
|
return c.json({ error: true, message: "User not found." }, 404);
|
|
9793
9805
|
}
|
|
9794
9806
|
const safeUser = this.sanitizeUser(user);
|
|
9795
|
-
return c.json(
|
|
9807
|
+
return c.json({
|
|
9808
|
+
...safeUser,
|
|
9809
|
+
collection: this.collection.slug
|
|
9810
|
+
});
|
|
9796
9811
|
}
|
|
9797
9812
|
// ---------------------------------------------------------------------------
|
|
9798
9813
|
// POST /refresh-token
|
|
@@ -12023,8 +12038,12 @@ async function resolveUser(payload, config) {
|
|
|
12023
12038
|
return null;
|
|
12024
12039
|
}
|
|
12025
12040
|
const { password: _password, ...safe } = doc;
|
|
12041
|
+
const roles = Array.isArray(safe.roles) ? safe.roles : typeof safe.role === "string" ? [safe.role] : [];
|
|
12042
|
+
const role = typeof safe.role === "string" ? safe.role : roles[0];
|
|
12026
12043
|
return {
|
|
12027
12044
|
...safe,
|
|
12045
|
+
...role !== void 0 ? { role } : {},
|
|
12046
|
+
roles,
|
|
12028
12047
|
sub: payload.sub,
|
|
12029
12048
|
email: payload.email ?? safe.email,
|
|
12030
12049
|
collection: payload.collection
|
|
@@ -12106,7 +12125,12 @@ function optionalAuth(config) {
|
|
|
12106
12125
|
c.set("user", user);
|
|
12107
12126
|
}
|
|
12108
12127
|
c.set("authTokenPayload", resolved.payload);
|
|
12109
|
-
} catch {
|
|
12128
|
+
} catch (err) {
|
|
12129
|
+
getConfigLogger(config ?? c.get("config"), "auth").warn({
|
|
12130
|
+
err,
|
|
12131
|
+
msg: "optionalAuth failed to resolve token",
|
|
12132
|
+
path: c.req.path
|
|
12133
|
+
});
|
|
12110
12134
|
}
|
|
12111
12135
|
}
|
|
12112
12136
|
await next();
|
|
@@ -14607,7 +14631,7 @@ function normalizeConfig(config) {
|
|
|
14607
14631
|
}
|
|
14608
14632
|
];
|
|
14609
14633
|
}
|
|
14610
|
-
if (!existingFieldNames.has("roles")) {
|
|
14634
|
+
if (!existingFieldNames.has("roles") && !existingFieldNames.has("role")) {
|
|
14611
14635
|
fields = [
|
|
14612
14636
|
...fields,
|
|
14613
14637
|
{
|
|
@@ -14621,7 +14645,7 @@ function normalizeConfig(config) {
|
|
|
14621
14645
|
{ value: "viewer", label: "Viewer" }
|
|
14622
14646
|
],
|
|
14623
14647
|
access: {
|
|
14624
|
-
update: "user.roles && 'admin' in user.roles"
|
|
14648
|
+
update: "user.role == 'admin' || (user.roles != null && 'admin' in user.roles)"
|
|
14625
14649
|
}
|
|
14626
14650
|
}
|
|
14627
14651
|
];
|
|
@@ -14639,10 +14663,10 @@ function normalizeConfig(config) {
|
|
|
14639
14663
|
{ value: "pending", label: "Pending" }
|
|
14640
14664
|
],
|
|
14641
14665
|
access: {
|
|
14642
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14666
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14643
14667
|
},
|
|
14644
14668
|
admin: {
|
|
14645
|
-
condition: `!(data.roles && "admin" in data.roles)`
|
|
14669
|
+
condition: `!(data.roles && "admin" in data.roles) && data.role != "admin"`
|
|
14646
14670
|
}
|
|
14647
14671
|
}
|
|
14648
14672
|
];
|
|
@@ -14676,13 +14700,13 @@ function normalizeConfig(config) {
|
|
|
14676
14700
|
}
|
|
14677
14701
|
};
|
|
14678
14702
|
}
|
|
14679
|
-
if (field.name === "roles") {
|
|
14703
|
+
if (field.name === "roles" || field.name === "role") {
|
|
14680
14704
|
return {
|
|
14681
14705
|
...field,
|
|
14682
14706
|
access: {
|
|
14683
14707
|
...field.access || {},
|
|
14684
14708
|
// Must be an admin; cannot edit own roles (no self-elevation).
|
|
14685
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14709
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14686
14710
|
}
|
|
14687
14711
|
};
|
|
14688
14712
|
}
|
|
@@ -14691,7 +14715,7 @@ function normalizeConfig(config) {
|
|
|
14691
14715
|
...field,
|
|
14692
14716
|
access: {
|
|
14693
14717
|
...field.access || {},
|
|
14694
|
-
update: "user.roles && 'admin' in user.roles && user.id != id"
|
|
14718
|
+
update: "(user.role == 'admin' || (user.roles != null && 'admin' in user.roles)) && user.id != id"
|
|
14695
14719
|
}
|
|
14696
14720
|
};
|
|
14697
14721
|
}
|