@dyrected/core 2.13.0 → 2.13.3

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/server.cjs CHANGED
@@ -6182,6 +6182,19 @@ function humanizeProviderName(id, type) {
6182
6182
  if (!cleaned) return type.toUpperCase();
6183
6183
  return cleaned.replace(/\b\w/g, (char) => char.toUpperCase());
6184
6184
  }
6185
+ function getAdminRoleForCollection(collection) {
6186
+ if (!collection?.auth) return "admin";
6187
+ if (typeof collection.auth === "object" && collection.auth.adminRole) {
6188
+ return collection.auth.adminRole;
6189
+ }
6190
+ return "admin";
6191
+ }
6192
+ function isUserAdmin(user, collection) {
6193
+ if (!user || !Array.isArray(user.roles)) return false;
6194
+ const configuredRole = getAdminRoleForCollection(collection);
6195
+ if (user.roles.includes(configuredRole)) return true;
6196
+ return user.roles.includes("admin") || user.roles.includes("super_admin");
6197
+ }
6185
6198
 
6186
6199
  // src/utils/collection-search.ts
6187
6200
  var DEFAULT_SEARCHABLE_NAMES = /* @__PURE__ */ new Set([
@@ -8001,7 +8014,7 @@ var CollectionController = class {
8001
8014
  if (newPassword.length < 8) {
8002
8015
  return c.json({ message: "Password must be at least 8 characters" }, 400);
8003
8016
  }
8004
- const isAdmin = Array.isArray(user.roles) && user.roles.includes("admin");
8017
+ const isAdmin = isUserAdmin(user, this.collection);
8005
8018
  const isSelf = user.sub === id;
8006
8019
  if (!isAdmin && !isSelf) {
8007
8020
  return c.json(
@@ -9625,14 +9638,29 @@ var AuthController = class {
9625
9638
  400
9626
9639
  );
9627
9640
  }
9641
+ let initialRole = getAdminRoleForCollection(this.collection);
9642
+ const rolesField = this.collection.fields?.find((f) => f.name === "roles");
9643
+ if (rolesField && Array.isArray(rolesField.options) && rolesField.options.length > 0) {
9644
+ const optionValues = rolesField.options.map(
9645
+ (opt) => typeof opt === "string" ? opt : opt?.value
9646
+ );
9647
+ if (!optionValues.includes(initialRole)) {
9648
+ if (optionValues.includes("super_admin")) {
9649
+ initialRole = "super_admin";
9650
+ } else if (optionValues.includes("admin")) {
9651
+ initialRole = "admin";
9652
+ } else {
9653
+ initialRole = optionValues[0];
9654
+ }
9655
+ }
9656
+ }
9628
9657
  const hashedPassword = await hashPassword(body.password);
9629
9658
  const user = await db.create({
9630
9659
  collection: this.collection.slug,
9631
9660
  data: {
9632
9661
  ...body,
9633
9662
  password: hashedPassword,
9634
- roles: ["admin"]
9635
- // Default first user to admin
9663
+ roles: [initialRole]
9636
9664
  }
9637
9665
  });
9638
9666
  const token = await issueAuthSessionToken({
@@ -13903,8 +13931,8 @@ function registerRoutes(app, config) {
13903
13931
  }))
13904
13932
  );
13905
13933
  const effectiveAi = requestConfig.ai;
13906
- const aiEnabled = effectiveAi?.enabled !== false;
13907
- const aiProvider = effectiveAi?.provider || (process.env.AGENTROUTER_API_KEY ? "agentrouter" : process.env.OPENROUTER_API_KEY ? "openrouter" : process.env.OPENAI_API_KEY && !process.env.GEMINI_API_KEY ? "openai" : "google");
13934
+ const aiEnabled = Boolean(effectiveAi && effectiveAi.enabled !== false);
13935
+ const aiProvider = aiEnabled ? effectiveAi?.provider || (process.env.AGENTROUTER_API_KEY ? "agentrouter" : process.env.OPENROUTER_API_KEY ? "openrouter" : process.env.OPENAI_API_KEY && !process.env.GEMINI_API_KEY ? "openai" : "google") : void 0;
13908
13936
  return c.json({
13909
13937
  blocks: requestConfig.blocks?.map(serializeBlockForApi),
13910
13938
  collections: filteredCollections,
@@ -14099,7 +14127,8 @@ function registerRoutes(app, config) {
14099
14127
  if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
14100
14128
  const body = await c.req.json().catch(() => ({}));
14101
14129
  if (scope === "global") {
14102
- const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
14130
+ const userCol = config.collections?.find((col) => col.slug === user?.collection);
14131
+ const isAdminUser = isUserAdmin(user, userCol);
14103
14132
  if (!isAdminUser) {
14104
14133
  return c.json(
14105
14134
  {
@@ -14147,7 +14176,8 @@ function registerRoutes(app, config) {
14147
14176
  if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
14148
14177
  if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
14149
14178
  if (scope === "global") {
14150
- const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
14179
+ const userCol = config.collections?.find((col) => col.slug === user?.collection);
14180
+ const isAdminUser = isUserAdmin(user, userCol);
14151
14181
  if (!isAdminUser) {
14152
14182
  return c.json(
14153
14183
  {
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bf as DatabaseAdapter, b as AuthenticatedUser, bt as DyrectedAIContext, al as AIThread, ah as AIMessage, ck as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-D_ODsBWA.cjs';
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-D_ODsBWA.cjs';
1
+ import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bf as DatabaseAdapter, b as AuthenticatedUser, bt as DyrectedAIContext, al as AIThread, ah as AIMessage, ck as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-De-3eNn1.cjs';
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
5
  import * as hono_utils_types from 'hono/utils/types';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bf as DatabaseAdapter, b as AuthenticatedUser, bt as DyrectedAIContext, al as AIThread, ah as AIMessage, ck as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-D_ODsBWA.js';
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-D_ODsBWA.js';
1
+ import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bf as DatabaseAdapter, b as AuthenticatedUser, bt as DyrectedAIContext, al as AIThread, ah as AIMessage, ck as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-De-3eNn1.js';
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
5
  import * as hono_utils_types from 'hono/utils/types';