@dyrected/core 2.13.4 → 2.13.6
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/{app-De-3eNn1.d.cts → app-phLVsEOM.d.cts} +221 -63
- package/dist/{app-De-3eNn1.d.ts → app-phLVsEOM.d.ts} +221 -63
- package/dist/index.cjs +59 -16
- package/dist/index.d.cts +139 -25
- package/dist/index.d.ts +139 -25
- package/dist/index.js +53 -16
- package/dist/server.cjs +40 -16
- package/dist/server.d.cts +15 -7
- package/dist/server.d.ts +15 -7
- package/dist/server.js +40 -16
- package/package.json +1 -1
package/dist/server.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bj as DatabaseAdapter, b as AuthenticatedUser, bE as DyrectedAIContext, al as AIThread, ah as AIMessage, cu as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-phLVsEOM.cjs';
|
|
2
|
+
export { d8 as DyrectedObservabilityRuntime, d9 as RequestBodyCapture, da as RequestTraceContext, db as ResolvedObservabilityConfig, dc as attachRequestMetrics, dd as bindObservabilityRuntime, de as buildRequestLogger, df as captureRequestBody, dg as createDyrectedApp, dh as createObservabilityRuntime, di as createRequestSpan, dj as endRequestSpan, dk as getConfigLogger, dl as getObservabilityRuntime, dm as getRequestLogger, dn as redactBody, dp as redactHeaders, dq as renderPrometheusMetrics, dr as resolveObservabilityConfig, ds as shouldSampleRequest } from './app-phLVsEOM.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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig,
|
|
2
|
-
export {
|
|
1
|
+
import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bj as DatabaseAdapter, b as AuthenticatedUser, bE as DyrectedAIContext, al as AIThread, ah as AIMessage, cu as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-phLVsEOM.js';
|
|
2
|
+
export { d8 as DyrectedObservabilityRuntime, d9 as RequestBodyCapture, da as RequestTraceContext, db as ResolvedObservabilityConfig, dc as attachRequestMetrics, dd as bindObservabilityRuntime, de as buildRequestLogger, df as captureRequestBody, dg as createDyrectedApp, dh as createObservabilityRuntime, di as createRequestSpan, dj as endRequestSpan, dk as getConfigLogger, dl as getObservabilityRuntime, dm as getRequestLogger, dn as redactBody, dp as redactHeaders, dq as renderPrometheusMetrics, dr as resolveObservabilityConfig, ds as shouldSampleRequest } from './app-phLVsEOM.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,21 +14631,21 @@ 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
|
{
|
|
14614
14638
|
name: "roles",
|
|
14615
14639
|
type: "select",
|
|
14616
14640
|
label: "Roles",
|
|
14617
|
-
defaultValue:
|
|
14641
|
+
defaultValue: "viewer",
|
|
14618
14642
|
options: [
|
|
14619
14643
|
{ value: "admin", label: "Admin" },
|
|
14620
14644
|
{ value: "editor", label: "Editor" },
|
|
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
|
}
|