@terreno/admin-backend 57.2.0 → 57.3.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.
@@ -1,5 +1,13 @@
1
- ## Admin Panel (backend)
1
+ ## Admin panel backend
2
2
 
3
- The backend uses `@terreno/admin-backend`'s `AdminApp` for auto-generated admin CRUD endpoints.
4
- All admin routes require `IsAdmin` permission and are mounted at `/admin`.
5
- Add models to `AdminApp` in `src/server.ts` to expose them in the admin panel.
3
+ Read the architecture first:
4
+
5
+ - `docs/explanation/admin-interface.md`
6
+ - `docs/how-to/admin-add-model.md`
7
+ - `docs/how-to/build-admin-screens.md`
8
+
9
+ Put `admin` on `modelRouter`. Use plugin `adminContribution()` for plugin-owned
10
+ models and screens. `AdminApp.customScreens` `name` must match the frontend widget
11
+ key. `admin:access` opens `/admin/config`; model CRUD is not a substitute.
12
+
13
+ Agent workflow: skill `building-admin-interfaces`.
@@ -1,6 +1,21 @@
1
1
  # Terreno
2
2
 
3
- A monorepo containing shared packages for building full-stack applications with React Native and Express/Mongoose.
3
+ Terreno is Django/Rails for TypeScript — with universal app support.
4
+
5
+ Terreno is Django/Rails for TypeScript — a batteries-included, full-stack
6
+ framework where the undifferentiated 80% of an app is already written. On the
7
+ backend you get Mongoose models, auto-generated REST APIs, permissions, an admin
8
+ panel, authentication, and an AI service. On the frontend you get one universal
9
+ app — a single React Native codebase that ships to iOS, Android, and web. It is
10
+ built to be driven by AI coding agents from the first prompt to a production
11
+ deploy.
12
+
13
+ - Batteries included — auth, CRUD APIs, admin, permissions, AI, realtime,
14
+ feature flags, and consent are already built, so your code is business logic.
15
+ - Universal by default — one React Native codebase ships to iOS, Android, and
16
+ web. Not a web framework with a mobile bolt-on.
17
+ - AI-native — agents are a first-class client of the framework, not an
18
+ afterthought.
4
19
 
5
20
  ## Packages
6
21
 
@@ -151,7 +166,7 @@ import {
151
166
 
152
167
  ### @terreno/ui
153
168
 
154
- React Native component library with 88+ components:
169
+ React Native UI component library (a large component library):
155
170
 
156
171
  - **Layout**: Box, Page, SplitPage, Card
157
172
  - **Forms**: TextField, SelectField, DateTimeField, CheckBox
@@ -5,7 +5,22 @@ globs: **/*
5
5
 
6
6
  # Terreno
7
7
 
8
- A monorepo containing shared packages for building full-stack applications with React Native and Express/Mongoose.
8
+ Terreno is Django/Rails for TypeScript — with universal app support.
9
+
10
+ Terreno is Django/Rails for TypeScript — a batteries-included, full-stack
11
+ framework where the undifferentiated 80% of an app is already written. On the
12
+ backend you get Mongoose models, auto-generated REST APIs, permissions, an admin
13
+ panel, authentication, and an AI service. On the frontend you get one universal
14
+ app — a single React Native codebase that ships to iOS, Android, and web. It is
15
+ built to be driven by AI coding agents from the first prompt to a production
16
+ deploy.
17
+
18
+ - Batteries included — auth, CRUD APIs, admin, permissions, AI, realtime,
19
+ feature flags, and consent are already built, so your code is business logic.
20
+ - Universal by default — one React Native codebase ships to iOS, Android, and
21
+ web. Not a web framework with a mobile bolt-on.
22
+ - AI-native — agents are a first-class client of the framework, not an
23
+ afterthought.
9
24
 
10
25
  ## Packages
11
26
 
@@ -206,7 +221,7 @@ router.get("/yourRoute/:id", [
206
221
 
207
222
  ### @terreno/ui
208
223
 
209
- React Native component library with 88+ components:
224
+ React Native UI component library (a large component library):
210
225
 
211
226
  - **Layout**: Box, Page, SplitPage, Card
212
227
  - **Forms**: TextField, SelectField, DateTimeField, CheckBox
@@ -1,6 +1,21 @@
1
1
  # Terreno
2
2
 
3
- A monorepo containing shared packages for building full-stack applications with React Native and Express/Mongoose.
3
+ Terreno is Django/Rails for TypeScript — with universal app support.
4
+
5
+ Terreno is Django/Rails for TypeScript — a batteries-included, full-stack
6
+ framework where the undifferentiated 80% of an app is already written. On the
7
+ backend you get Mongoose models, auto-generated REST APIs, permissions, an admin
8
+ panel, authentication, and an AI service. On the frontend you get one universal
9
+ app — a single React Native codebase that ships to iOS, Android, and web. It is
10
+ built to be driven by AI coding agents from the first prompt to a production
11
+ deploy.
12
+
13
+ - Batteries included — auth, CRUD APIs, admin, permissions, AI, realtime,
14
+ feature flags, and consent are already built, so your code is business logic.
15
+ - Universal by default — one React Native codebase ships to iOS, Android, and
16
+ web. Not a web framework with a mobile bolt-on.
17
+ - AI-native — agents are a first-class client of the framework, not an
18
+ afterthought.
4
19
 
5
20
  ## Packages
6
21
 
@@ -201,7 +216,7 @@ router.get("/yourRoute/:id", [
201
216
 
202
217
  ### @terreno/ui
203
218
 
204
- React Native component library with 88+ components:
219
+ React Native UI component library (a large component library):
205
220
 
206
221
  - **Layout**: Box, Page, SplitPage, Card
207
222
  - **Forms**: TextField, SelectField, DateTimeField, CheckBox
package/AGENTS.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # Terreno
2
2
 
3
- A monorepo containing shared packages for building full-stack applications with React Native and Express/Mongoose.
3
+ Terreno is Django/Rails for TypeScript — with universal app support.
4
+
5
+ Terreno is Django/Rails for TypeScript — a batteries-included, full-stack
6
+ framework where the undifferentiated 80% of an app is already written. On the
7
+ backend you get Mongoose models, auto-generated REST APIs, permissions, an admin
8
+ panel, authentication, and an AI service. On the frontend you get one universal
9
+ app — a single React Native codebase that ships to iOS, Android, and web. It is
10
+ built to be driven by AI coding agents from the first prompt to a production
11
+ deploy.
12
+
13
+ - Batteries included — auth, CRUD APIs, admin, permissions, AI, realtime,
14
+ feature flags, and consent are already built, so your code is business logic.
15
+ - Universal by default — one React Native codebase ships to iOS, Android, and
16
+ web. Not a web framework with a mobile bolt-on.
17
+ - AI-native — agents are a first-class client of the framework, not an
18
+ afterthought.
4
19
 
5
20
  ## Packages
6
21
 
@@ -201,7 +216,7 @@ router.get("/yourRoute/:id", [
201
216
 
202
217
  ### @terreno/ui
203
218
 
204
- React Native component library with 88+ components:
219
+ React Native UI component library (a large component library):
205
220
 
206
221
  - **Layout**: Box, Page, SplitPage, Card
207
222
  - **Forms**: TextField, SelectField, DateTimeField, CheckBox
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @terreno/admin-backend
2
2
 
3
- See [Add a model to the admin](../docs/how-to/admin-add-model.md) for the recommended
3
+ Admin panel backend plugin for @terreno/api.
4
+
5
+ See [Add a model to the admin](https://github.com/flourishhealth/terreno/blob/master/docs/how-to/admin-add-model.md) for the recommended
4
6
  `modelRouter({admin: ...})` setup.
5
7
 
6
8
  Admin panel backend plugin for `@terreno/api` that auto-generates admin CRUD endpoints and metadata for Mongoose models.
package/dist/adminApp.js CHANGED
@@ -319,52 +319,14 @@ var getArrayEmbeddedSchemaType = function (schemaPath) {
319
319
  return compatiblePath.caster;
320
320
  };
321
321
  exports.getArrayEmbeddedSchemaType = getArrayEmbeddedSchemaType;
322
- var extractFieldMeta = function (properties, required) {
323
- var e_5, _a;
324
- var _b, _c, _d;
325
- var fields = {};
326
- try {
327
- for (var _e = __values(Object.entries(properties)), _f = _e.next(); !_f.done; _f = _e.next()) {
328
- var _g = __read(_f.value, 2), key = _g[0], prop = _g[1];
329
- var fieldType = (_b = prop.type) !== null && _b !== void 0 ? _b : "string";
330
- fields[key] = {
331
- default: prop.default,
332
- description: prop.description,
333
- enum: prop.enum,
334
- ref: prop.$ref ? prop.$ref.replace("#/components/schemas/", "") : undefined,
335
- required: required.includes(key),
336
- searchable: fieldType === "string" && !prop.enum,
337
- type: fieldType,
338
- };
339
- // For array fields, extract item sub-field metadata
340
- if (prop.type === "array" && ((_c = prop.items) === null || _c === void 0 ? void 0 : _c.properties)) {
341
- var itemRequired = (_d = prop.items.required) !== null && _d !== void 0 ? _d : [];
342
- fields[key].items = extractFieldMeta(prop.items.properties, itemRequired);
343
- }
344
- // For array fields of primitives, capture the item type and enum
345
- if (prop.type === "array" && prop.items && !prop.items.properties) {
346
- var itemProp = prop.items;
347
- if (itemProp.type) {
348
- fields[key].itemType = itemProp.type;
349
- }
350
- if (itemProp.enum) {
351
- fields[key].itemEnum = itemProp.enum;
352
- }
353
- }
354
- // Check for ObjectId references in the raw property
355
- if (!fields[key].ref && prop.type === "string" && prop.format === "objectid") {
356
- // mongoose-to-swagger may not preserve ref directly; we'll handle this in register()
357
- }
358
- }
359
- }
360
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
361
- finally {
362
- try {
363
- if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
364
- }
365
- finally { if (e_5) throw e_5.error; }
366
- }
367
- return fields;
322
+ var extractFieldMetaFromDescription = function (model, hiddenFields) {
323
+ var hiddenFieldSet = new Set(hiddenFields);
324
+ var description = (0, api_1.describeModel)(model);
325
+ var fields = (0, api_1.modelDescriptionToAdminFields)(description);
326
+ return Object.fromEntries(Object.entries(fields).filter(function (_a) {
327
+ var _b = __read(_a, 1), key = _b[0];
328
+ return !hiddenFieldSet.has(key);
329
+ }));
368
330
  };
369
331
  var asMiddlewareList = function (middleware) {
370
332
  if (middleware === undefined) {
@@ -474,8 +436,8 @@ var AdminApp = /** @class */ (function () {
474
436
  };
475
437
  AdminApp.prototype.canAnyResourceAction = function (user, resource, actions, instance) {
476
438
  return __awaiter(this, void 0, void 0, function () {
477
- var accessControl, actions_1, actions_1_1, action, result, e_6_1;
478
- var e_6, _a, _b;
439
+ var accessControl, actions_1, actions_1_1, action, result, e_5_1;
440
+ var e_5, _a, _b;
479
441
  return __generator(this, function (_c) {
480
442
  switch (_c.label) {
481
443
  case 0:
@@ -507,14 +469,14 @@ var AdminApp = /** @class */ (function () {
507
469
  return [3 /*break*/, 2];
508
470
  case 5: return [3 /*break*/, 8];
509
471
  case 6:
510
- e_6_1 = _c.sent();
511
- e_6 = { error: e_6_1 };
472
+ e_5_1 = _c.sent();
473
+ e_5 = { error: e_5_1 };
512
474
  return [3 /*break*/, 8];
513
475
  case 7:
514
476
  try {
515
477
  if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
516
478
  }
517
- finally { if (e_6) throw e_6.error; }
479
+ finally { if (e_5) throw e_5.error; }
518
480
  return [7 /*endfinally*/];
519
481
  case 8: return [2 /*return*/, false];
520
482
  }
@@ -621,7 +583,7 @@ var AdminApp = /** @class */ (function () {
621
583
  * @param app - The Express application instance to register with
622
584
  */
623
585
  AdminApp.prototype.register = function (app, openApi, terrenoApp) {
624
- var e_7, _a, e_8, _b;
586
+ var e_6, _a, e_7, _b;
625
587
  var _this = this;
626
588
  var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
627
589
  var basePath = (_c = this.options.basePath) !== null && _c !== void 0 ? _c : "/admin";
@@ -665,122 +627,68 @@ var AdminApp = /** @class */ (function () {
665
627
  source: config.source,
666
628
  }); }));
667
629
  var configModels = modelConfigs.map(function (config, configIndex) {
668
- var e_9, _a, e_10, _b;
669
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
670
- var _v = (0, api_1.getOpenApiSpecForModel)(config.model), properties = _v.properties, required = _v.required;
671
- var hiddenFieldSet = new Set((_c = config.hiddenFields) !== null && _c !== void 0 ? _c : []);
672
- var filteredProperties = Object.fromEntries(Object.entries(properties).filter(function (_a) {
673
- var _b = __read(_a, 1), key = _b[0];
674
- return !hiddenFieldSet.has(key);
675
- }));
676
- var filteredRequired = required.filter(function (key) { return !hiddenFieldSet.has(key); });
677
- // Extract ref information directly from the Mongoose schema
678
- var fields = extractFieldMeta(filteredProperties, filteredRequired);
679
- try {
680
- for (var _w = __values(Object.entries(fields)), _x = _w.next(); !_x.done; _x = _w.next()) {
681
- var _y = __read(_x.value, 2), key = _y[0], field = _y[1];
682
- var schemaPath = config.model.schema.path(key);
683
- if (schemaPath) {
684
- var pathOptions = schemaPath.options;
685
- if (pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.ref) {
686
- field.ref = pathOptions.ref;
687
- }
688
- // Handle array of refs (legacy: also set ref for back-compat)
689
- if (Array.isArray(pathOptions === null || pathOptions === void 0 ? void 0 : pathOptions.type) && ((_d = pathOptions.type[0]) === null || _d === void 0 ? void 0 : _d.ref)) {
690
- field.ref = pathOptions.type[0].ref;
691
- }
692
- // For arrays, use the public embedded schema type to infer the primitive item type/ref.
693
- if (schemaPath.instance === "Array") {
694
- var embeddedSchemaType = (0, exports.getArrayEmbeddedSchemaType)(schemaPath);
695
- if ((embeddedSchemaType === null || embeddedSchemaType === void 0 ? void 0 : embeddedSchemaType.instance) && !field.items) {
696
- var instanceToType = {
697
- Boolean: "boolean",
698
- Number: "number",
699
- ObjectID: "objectid",
700
- ObjectId: "objectid",
701
- SchemaObjectId: "objectid",
702
- String: "string",
703
- };
704
- var mapped = instanceToType[embeddedSchemaType.instance];
705
- if (mapped) {
706
- field.itemType = mapped;
707
- }
708
- if ((_e = embeddedSchemaType.options) === null || _e === void 0 ? void 0 : _e.ref) {
709
- field.itemRef = embeddedSchemaType.options.ref;
710
- }
711
- if (Array.isArray((_f = embeddedSchemaType.options) === null || _f === void 0 ? void 0 : _f.enum)) {
712
- field.itemEnum = embeddedSchemaType.options.enum;
713
- }
714
- }
715
- }
716
- }
717
- }
718
- }
719
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
720
- finally {
721
- try {
722
- if (_x && !_x.done && (_a = _w.return)) _a.call(_w);
723
- }
724
- finally { if (e_9) throw e_9.error; }
725
- }
630
+ var e_8, _a;
631
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
632
+ var hiddenFieldSet = new Set((_b = config.hiddenFields) !== null && _b !== void 0 ? _b : []);
633
+ var fields = extractFieldMetaFromDescription(config.model, __spreadArray([], __read(hiddenFieldSet), false));
726
634
  // Apply field overrides (e.g., widget: "markdown")
727
635
  if (config.fieldOverrides) {
728
636
  try {
729
- for (var _z = __values(Object.entries(config.fieldOverrides)), _0 = _z.next(); !_0.done; _0 = _z.next()) {
730
- var _1 = __read(_0.value, 2), key = _1[0], override = _1[1];
637
+ for (var _r = __values(Object.entries(config.fieldOverrides)), _s = _r.next(); !_s.done; _s = _r.next()) {
638
+ var _t = __read(_s.value, 2), key = _t[0], override = _t[1];
731
639
  if (fields[key] && override.widget) {
732
640
  fields[key].widget = override.widget;
733
641
  }
734
642
  }
735
643
  }
736
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
644
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
737
645
  finally {
738
646
  try {
739
- if (_0 && !_0.done && (_b = _z.return)) _b.call(_z);
647
+ if (_s && !_s.done && (_a = _r.return)) _a.call(_r);
740
648
  }
741
- finally { if (e_10) throw e_10.error; }
649
+ finally { if (e_8) throw e_8.error; }
742
650
  }
743
651
  }
744
- var readonlyFields = (_g = config.readonlyFields) !== null && _g !== void 0 ? _g : [];
652
+ var readonlyFields = (_c = config.readonlyFields) !== null && _c !== void 0 ? _c : [];
745
653
  var listFields = config.listFields.filter(function (field) { return !hiddenFieldSet.has(field); });
746
- var listDisplay = (_h = config.listDisplay) !== null && _h !== void 0 ? _h : listFields;
654
+ var listDisplay = (_d = config.listDisplay) !== null && _d !== void 0 ? _d : listFields;
747
655
  var derivedSearchFields = listFields.filter(function (field) { var _a; return (_a = fields[field]) === null || _a === void 0 ? void 0 : _a.searchable; });
748
- var searchFields = (_j = config.searchFields) !== null && _j !== void 0 ? _j : derivedSearchFields;
656
+ var searchFields = (_e = config.searchFields) !== null && _e !== void 0 ? _e : derivedSearchFields;
749
657
  var sortableFields = resolveAdminSortableFields({
750
658
  defaultSort: config.defaultSort,
751
659
  listDisplay: listDisplay,
752
660
  sortableFields: config.sortableFields,
753
661
  });
754
662
  var schemaPathKeys = new Set(Object.keys(config.model.schema.paths));
755
- var bulkPatchAllowlist = (_k = config.bulkPatchAllowlist) !== null && _k !== void 0 ? _k : (0, adminUiV2_1.defaultBulkPatchAllowlistFrom)({
663
+ var bulkPatchAllowlist = (_f = config.bulkPatchAllowlist) !== null && _f !== void 0 ? _f : (0, adminUiV2_1.defaultBulkPatchAllowlistFrom)({
756
664
  hiddenFieldSet: hiddenFieldSet,
757
665
  listFields: listFields,
758
666
  readonlyFields: readonlyFields,
759
667
  schemaPaths: schemaPathKeys,
760
668
  });
761
669
  return {
762
- actions: (_l = config.actions) !== null && _l !== void 0 ? _l : [],
670
+ actions: (_g = config.actions) !== null && _g !== void 0 ? _g : [],
763
671
  bulkPatchAllowlist: bulkPatchAllowlist,
764
- defaultSort: (_m = config.defaultSort) !== null && _m !== void 0 ? _m : "-created",
672
+ defaultSort: (_h = config.defaultSort) !== null && _h !== void 0 ? _h : "-created",
765
673
  displayName: config.displayName,
766
674
  fieldOrder: config.fieldOrder,
767
675
  fields: fields,
768
676
  fieldsets: config.fieldsets,
769
- filters: (_o = config.filters) !== null && _o !== void 0 ? _o : [],
677
+ filters: (_j = config.filters) !== null && _j !== void 0 ? _j : [],
770
678
  group: config.group,
771
679
  hiddenFields: __spreadArray([], __read(hiddenFieldSet), false),
772
680
  listDisplay: listDisplay,
773
- listDisplayLinks: (_p = config.listDisplayLinks) !== null && _p !== void 0 ? _p : [],
681
+ listDisplayLinks: (_k = config.listDisplayLinks) !== null && _k !== void 0 ? _k : [],
774
682
  listFields: listFields,
775
- name: (_q = configNames[configIndex]) !== null && _q !== void 0 ? _q : config.model.modelName,
683
+ name: (_l = configNames[configIndex]) !== null && _l !== void 0 ? _l : config.model.modelName,
776
684
  pageSize: config.pageSize,
777
685
  permissions: {
778
- create: ((_r = config.permissions) === null || _r === void 0 ? void 0 : _r.create) !== false,
779
- delete: ((_s = config.permissions) === null || _s === void 0 ? void 0 : _s.delete) !== false,
780
- update: ((_t = config.permissions) === null || _t === void 0 ? void 0 : _t.update) !== false,
686
+ create: ((_m = config.permissions) === null || _m === void 0 ? void 0 : _m.create) !== false,
687
+ delete: ((_o = config.permissions) === null || _o === void 0 ? void 0 : _o.delete) !== false,
688
+ update: ((_p = config.permissions) === null || _p === void 0 ? void 0 : _p.update) !== false,
781
689
  },
782
690
  readonlyFields: readonlyFields,
783
- realtime: (_u = config.realtime) !== null && _u !== void 0 ? _u : false,
691
+ realtime: (_q = config.realtime) !== null && _q !== void 0 ? _q : false,
784
692
  recordTitleField: config.recordTitleField,
785
693
  routePath: "".concat(basePath).concat(config.routePath),
786
694
  searchFields: searchFields,
@@ -797,14 +705,7 @@ var AdminApp = /** @class */ (function () {
797
705
  name: script.name,
798
706
  });
799
707
  });
800
- var defaultScreens = [
801
- {
802
- adminAccess: { action: "read", resource: "configuration" },
803
- displayName: "Version Config",
804
- name: "version-config",
805
- },
806
- ];
807
- var mergedScreens = __spreadArray(__spreadArray(__spreadArray([], __read(defaultScreens), false), __read(aggregated.customScreens), false), __read(((_f = this.options.customScreens) !== null && _f !== void 0 ? _f : [])), false);
708
+ var mergedScreens = __spreadArray(__spreadArray([], __read(aggregated.customScreens), false), __read(((_f = this.options.customScreens) !== null && _f !== void 0 ? _f : [])), false);
808
709
  var baseConfigResponse = {
809
710
  capabilities: {
810
711
  actions: true,
@@ -1122,7 +1023,7 @@ var AdminApp = /** @class */ (function () {
1122
1023
  }); }));
1123
1024
  app.put(versionConfigPath, (0, api_1.authenticateMiddleware)(), (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
1124
1025
  var raw, allowedFields, setFields, unsetFields, allowedFields_1, allowedFields_1_1, field, updateOp, doc;
1125
- var e_11, _a;
1026
+ var e_9, _a;
1126
1027
  return __generator(this, function (_b) {
1127
1028
  switch (_b.label) {
1128
1029
  case 0: return [4 /*yield*/, this.hasConfigurationPermission(req.user, "update")];
@@ -1153,12 +1054,12 @@ var AdminApp = /** @class */ (function () {
1153
1054
  }
1154
1055
  }
1155
1056
  }
1156
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1057
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
1157
1058
  finally {
1158
1059
  try {
1159
1060
  if (allowedFields_1_1 && !allowedFields_1_1.done && (_a = allowedFields_1.return)) _a.call(allowedFields_1);
1160
1061
  }
1161
- finally { if (e_11) throw e_11.error; }
1062
+ finally { if (e_9) throw e_9.error; }
1162
1063
  }
1163
1064
  updateOp = {};
1164
1065
  if (Object.keys(setFields).length > 0) {
@@ -1180,7 +1081,7 @@ var AdminApp = /** @class */ (function () {
1180
1081
  });
1181
1082
  }); }));
1182
1083
  var _loop_1 = function (config) {
1183
- var e_12, _t;
1084
+ var e_10, _t;
1184
1085
  // Determine searchable fields from the actual Mongoose schema type,
1185
1086
  // not the OpenAPI type (which reports ObjectId as "string")
1186
1087
  var searchableFields = [];
@@ -1188,7 +1089,7 @@ var AdminApp = /** @class */ (function () {
1188
1089
  var modelMeta = (0, adminConfigIdentity_1.findAdminModelMetaByRoutePath)(configModels, "".concat(basePath).concat(config.routePath));
1189
1090
  if (modelMeta) {
1190
1091
  try {
1191
- for (var _u = (e_12 = void 0, __values(Object.keys(modelMeta.fields))), _v = _u.next(); !_v.done; _v = _u.next()) {
1092
+ for (var _u = (e_10 = void 0, __values(Object.keys(modelMeta.fields))), _v = _u.next(); !_v.done; _v = _u.next()) {
1192
1093
  var key = _v.value;
1193
1094
  var schemaPath = config.model.schema.path(key);
1194
1095
  if (schemaPath && schemaPath.instance === "String" && !modelMeta.fields[key].enum) {
@@ -1199,12 +1100,12 @@ var AdminApp = /** @class */ (function () {
1199
1100
  }
1200
1101
  }
1201
1102
  }
1202
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1103
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1203
1104
  finally {
1204
1105
  try {
1205
1106
  if (_v && !_v.done && (_t = _u.return)) _t.call(_u);
1206
1107
  }
1207
- finally { if (e_12) throw e_12.error; }
1108
+ finally { if (e_10) throw e_10.error; }
1208
1109
  }
1209
1110
  }
1210
1111
  app.get("".concat(basePath).concat(config.routePath, "/search"), (0, api_1.authenticateMiddleware)(), (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
@@ -1284,12 +1185,12 @@ var AdminApp = /** @class */ (function () {
1284
1185
  _loop_1(config);
1285
1186
  }
1286
1187
  }
1287
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1188
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1288
1189
  finally {
1289
1190
  try {
1290
1191
  if (modelConfigs_1_1 && !modelConfigs_1_1.done && (_a = modelConfigs_1.return)) _a.call(modelConfigs_1);
1291
1192
  }
1292
- finally { if (e_7) throw e_7.error; }
1193
+ finally { if (e_6) throw e_6.error; }
1293
1194
  }
1294
1195
  var _loop_2 = function (config) {
1295
1196
  var hiddenFieldSet = new Set((_g = config.hiddenFields) !== null && _g !== void 0 ? _g : []);
@@ -1305,62 +1206,62 @@ var AdminApp = /** @class */ (function () {
1305
1206
  };
1306
1207
  var updatePermissions = this_1.resourceActionPermissions(config, "update");
1307
1208
  var stripProtectedFromBody = function (body) {
1308
- var e_13, _a, e_14, _b, e_15, _c, e_16, _d;
1209
+ var e_11, _a, e_12, _b, e_13, _c, e_14, _d;
1309
1210
  if (!body || typeof body !== "object" || Array.isArray(body)) {
1310
1211
  return {};
1311
1212
  }
1312
1213
  var next = __assign({}, body);
1313
1214
  try {
1314
- for (var readonlySet_1 = (e_13 = void 0, __values(readonlySet)), readonlySet_1_1 = readonlySet_1.next(); !readonlySet_1_1.done; readonlySet_1_1 = readonlySet_1.next()) {
1215
+ for (var readonlySet_1 = (e_11 = void 0, __values(readonlySet)), readonlySet_1_1 = readonlySet_1.next(); !readonlySet_1_1.done; readonlySet_1_1 = readonlySet_1.next()) {
1315
1216
  var key = readonlySet_1_1.value;
1316
1217
  delete next[key];
1317
1218
  }
1318
1219
  }
1319
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1220
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
1320
1221
  finally {
1321
1222
  try {
1322
1223
  if (readonlySet_1_1 && !readonlySet_1_1.done && (_a = readonlySet_1.return)) _a.call(readonlySet_1);
1323
1224
  }
1324
- finally { if (e_13) throw e_13.error; }
1225
+ finally { if (e_11) throw e_11.error; }
1325
1226
  }
1326
1227
  try {
1327
- for (var hiddenFieldSet_1 = (e_14 = void 0, __values(hiddenFieldSet)), hiddenFieldSet_1_1 = hiddenFieldSet_1.next(); !hiddenFieldSet_1_1.done; hiddenFieldSet_1_1 = hiddenFieldSet_1.next()) {
1228
+ for (var hiddenFieldSet_1 = (e_12 = void 0, __values(hiddenFieldSet)), hiddenFieldSet_1_1 = hiddenFieldSet_1.next(); !hiddenFieldSet_1_1.done; hiddenFieldSet_1_1 = hiddenFieldSet_1.next()) {
1328
1229
  var key = hiddenFieldSet_1_1.value;
1329
1230
  delete next[key];
1330
1231
  }
1331
1232
  }
1332
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1233
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
1333
1234
  finally {
1334
1235
  try {
1335
1236
  if (hiddenFieldSet_1_1 && !hiddenFieldSet_1_1.done && (_b = hiddenFieldSet_1.return)) _b.call(hiddenFieldSet_1);
1336
1237
  }
1337
- finally { if (e_14) throw e_14.error; }
1238
+ finally { if (e_12) throw e_12.error; }
1338
1239
  }
1339
1240
  try {
1340
- for (var excludeFieldSet_1 = (e_15 = void 0, __values(excludeFieldSet)), excludeFieldSet_1_1 = excludeFieldSet_1.next(); !excludeFieldSet_1_1.done; excludeFieldSet_1_1 = excludeFieldSet_1.next()) {
1241
+ for (var excludeFieldSet_1 = (e_13 = void 0, __values(excludeFieldSet)), excludeFieldSet_1_1 = excludeFieldSet_1.next(); !excludeFieldSet_1_1.done; excludeFieldSet_1_1 = excludeFieldSet_1.next()) {
1341
1242
  var key = excludeFieldSet_1_1.value;
1342
1243
  delete next[key];
1343
1244
  }
1344
1245
  }
1345
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
1246
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1346
1247
  finally {
1347
1248
  try {
1348
1249
  if (excludeFieldSet_1_1 && !excludeFieldSet_1_1.done && (_c = excludeFieldSet_1.return)) _c.call(excludeFieldSet_1);
1349
1250
  }
1350
- finally { if (e_15) throw e_15.error; }
1251
+ finally { if (e_13) throw e_13.error; }
1351
1252
  }
1352
1253
  try {
1353
- for (var SYSTEM_ADMIN_FIELDS_1 = (e_16 = void 0, __values(adminUiV2_1.SYSTEM_ADMIN_FIELDS)), SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next(); !SYSTEM_ADMIN_FIELDS_1_1.done; SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next()) {
1254
+ for (var SYSTEM_ADMIN_FIELDS_1 = (e_14 = void 0, __values(adminUiV2_1.SYSTEM_ADMIN_FIELDS)), SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next(); !SYSTEM_ADMIN_FIELDS_1_1.done; SYSTEM_ADMIN_FIELDS_1_1 = SYSTEM_ADMIN_FIELDS_1.next()) {
1354
1255
  var key = SYSTEM_ADMIN_FIELDS_1_1.value;
1355
1256
  delete next[key];
1356
1257
  }
1357
1258
  }
1358
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
1259
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1359
1260
  finally {
1360
1261
  try {
1361
1262
  if (SYSTEM_ADMIN_FIELDS_1_1 && !SYSTEM_ADMIN_FIELDS_1_1.done && (_d = SYSTEM_ADMIN_FIELDS_1.return)) _d.call(SYSTEM_ADMIN_FIELDS_1);
1362
1263
  }
1363
- finally { if (e_16) throw e_16.error; }
1264
+ finally { if (e_14) throw e_14.error; }
1364
1265
  }
1365
1266
  // Self-service never writes these fields. Admin CRUD may set `admin`.
1366
1267
  // When RBAC is enabled, `roles` must go through RoleManager.assign and
@@ -1451,7 +1352,7 @@ var AdminApp = /** @class */ (function () {
1451
1352
  };
1452
1353
  var restoreUserFieldsAfterFailedRoleAssign = function (value, prev, cleanedBody) { return __awaiter(_this, void 0, void 0, function () {
1453
1354
  var record, prevRecord, body, restore, _a, _b, key;
1454
- var e_17, _c;
1355
+ var e_15, _c;
1455
1356
  return __generator(this, function (_d) {
1456
1357
  switch (_d.label) {
1457
1358
  case 0:
@@ -1477,12 +1378,12 @@ var AdminApp = /** @class */ (function () {
1477
1378
  }
1478
1379
  }
1479
1380
  }
1480
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
1381
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1481
1382
  finally {
1482
1383
  try {
1483
1384
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
1484
1385
  }
1485
- finally { if (e_17) throw e_17.error; }
1386
+ finally { if (e_15) throw e_15.error; }
1486
1387
  }
1487
1388
  if (Object.keys(restore).length === 0) {
1488
1389
  return [2 /*return*/];
@@ -1820,8 +1721,8 @@ var AdminApp = /** @class */ (function () {
1820
1721
  modelBase.use(validateAdminSortParam((_s = modelMeta === null || modelMeta === void 0 ? void 0 : modelMeta.sortableFields) !== null && _s !== void 0 ? _s : []));
1821
1722
  modelBase.post.apply(modelBase, __spreadArray(__spreadArray(["/bulk-patch",
1822
1723
  (0, api_1.authenticateMiddleware)()], __read(asMiddlewareList(bulkPatchOpenApi)), false), [(0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
1823
- var body, ids, rawPatch, unknownKeys, patch, pendingRoles, updated, failures, actor, ids_1, ids_1_1, id, doc, previousPatch, _a, _b, key, roleError_1, err_4, message, e_18_1;
1824
- var e_18, _c, e_19, _d;
1724
+ var body, ids, rawPatch, unknownKeys, patch, pendingRoles, updated, failures, actor, ids_1, ids_1_1, id, doc, previousPatch, _a, _b, key, roleError_1, err_4, message, e_16_1;
1725
+ var e_16, _c, e_17, _d;
1825
1726
  var _e, _f;
1826
1727
  return __generator(this, function (_g) {
1827
1728
  switch (_g.label) {
@@ -1907,17 +1808,17 @@ var AdminApp = /** @class */ (function () {
1907
1808
  _g.sent();
1908
1809
  previousPatch = {};
1909
1810
  try {
1910
- for (_a = (e_19 = void 0, __values(Object.keys(patch))), _b = _a.next(); !_b.done; _b = _a.next()) {
1811
+ for (_a = (e_17 = void 0, __values(Object.keys(patch))), _b = _a.next(); !_b.done; _b = _a.next()) {
1911
1812
  key = _b.value;
1912
1813
  previousPatch[key] = doc[key];
1913
1814
  }
1914
1815
  }
1915
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
1816
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1916
1817
  finally {
1917
1818
  try {
1918
1819
  if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
1919
1820
  }
1920
- finally { if (e_19) throw e_19.error; }
1821
+ finally { if (e_17) throw e_17.error; }
1921
1822
  }
1922
1823
  if (!(Object.keys(patch).length > 0)) return [3 /*break*/, 9];
1923
1824
  return [4 /*yield*/, doc.updateOne({ $set: patch })];
@@ -1961,14 +1862,14 @@ var AdminApp = /** @class */ (function () {
1961
1862
  return [3 /*break*/, 3];
1962
1863
  case 18: return [3 /*break*/, 21];
1963
1864
  case 19:
1964
- e_18_1 = _g.sent();
1965
- e_18 = { error: e_18_1 };
1865
+ e_16_1 = _g.sent();
1866
+ e_16 = { error: e_16_1 };
1966
1867
  return [3 /*break*/, 21];
1967
1868
  case 20:
1968
1869
  try {
1969
1870
  if (ids_1_1 && !ids_1_1.done && (_c = ids_1.return)) _c.call(ids_1);
1970
1871
  }
1971
- finally { if (e_18) throw e_18.error; }
1872
+ finally { if (e_16) throw e_16.error; }
1972
1873
  return [7 /*endfinally*/];
1973
1874
  case 21: return [2 /*return*/, res.json({ failures: failures.length > 0 ? failures : undefined, updated: updated })];
1974
1875
  }
@@ -1985,12 +1886,12 @@ var AdminApp = /** @class */ (function () {
1985
1886
  _loop_2(config);
1986
1887
  }
1987
1888
  }
1988
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1889
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1989
1890
  finally {
1990
1891
  try {
1991
1892
  if (modelConfigs_2_1 && !modelConfigs_2_1.done && (_b = modelConfigs_2.return)) _b.call(modelConfigs_2);
1992
1893
  }
1993
- finally { if (e_8) throw e_8.error; }
1894
+ finally { if (e_7) throw e_7.error; }
1994
1895
  }
1995
1896
  // Mount script routes
1996
1897
  if (scriptConfigs.length > 0) {
@@ -2062,7 +1963,7 @@ var AdminApp = /** @class */ (function () {
2062
1963
  // POST /admin/scripts/:name/run — Execute a script
2063
1964
  router.post("/:name/run", (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
2064
1965
  var user, _a, script, isWetRun, argValues, _b, _c, _d, key, value, rawBody, bodyValues, _e, _f, _g, key, value, _h, args, argErrors, now, task, err_5, detail, ctx;
2065
- var e_20, _j, e_21, _k;
1966
+ var e_18, _j, e_19, _k;
2066
1967
  var _this = this;
2067
1968
  var _l, _m;
2068
1969
  return __generator(this, function (_o) {
@@ -2094,12 +1995,12 @@ var AdminApp = /** @class */ (function () {
2094
1995
  argValues[key] = value;
2095
1996
  }
2096
1997
  }
2097
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
1998
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
2098
1999
  finally {
2099
2000
  try {
2100
2001
  if (_c && !_c.done && (_j = _b.return)) _j.call(_b);
2101
2002
  }
2102
- finally { if (e_20) throw e_20.error; }
2003
+ finally { if (e_18) throw e_18.error; }
2103
2004
  }
2104
2005
  rawBody = req.body && typeof req.body === "object" && !Array.isArray(req.body)
2105
2006
  ? req.body
@@ -2116,12 +2017,12 @@ var AdminApp = /** @class */ (function () {
2116
2017
  argValues[key] = value;
2117
2018
  }
2118
2019
  }
2119
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
2020
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
2120
2021
  finally {
2121
2022
  try {
2122
2023
  if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
2123
2024
  }
2124
- finally { if (e_21) throw e_21.error; }
2025
+ finally { if (e_19) throw e_19.error; }
2125
2026
  }
2126
2027
  _h = (0, api_1.createScriptArgs)({
2127
2028
  defs: (_l = script.args) !== null && _l !== void 0 ? _l : [],
@@ -181,7 +181,10 @@ var aggregateAdminContributions = function (_a) {
181
181
  var path = registered.routePath;
182
182
  var existingRegistered = registeredByPath.get(path);
183
183
  if (existingRegistered) {
184
- throw new Error("Duplicate admin modelRouter routePath \"".concat(path, "\" (").concat(existingRegistered.sourceLabel, " and ").concat(registered.sourceLabel, ")"));
184
+ throw new api_1.APIError({
185
+ status: 500,
186
+ title: "Duplicate admin modelRouter routePath \"".concat(path, "\" (").concat(existingRegistered.sourceLabel, " and ").concat(registered.sourceLabel, ")"),
187
+ });
185
188
  }
186
189
  registeredByPath.set(path, registered);
187
190
  var existing = modelsByPath.get(path);
@@ -223,10 +223,7 @@ var DocumentStorageApp = /** @class */ (function () {
223
223
  });
224
224
  }); })], false));
225
225
  // POST basePath/ — Upload a file
226
- app.post.apply(app, __spreadArray(__spreadArray(["".concat(basePath, "/")], __read(adminGuard), false), [
227
- // noExplicitAny: multer's RequestHandler type is incompatible with Express 5's middleware signature.
228
- // biome-ignore lint/suspicious/noExplicitAny: multer's RequestHandler type is incompatible with Express 5's middleware signature.
229
- upload.single("file"),
226
+ app.post.apply(app, __spreadArray(__spreadArray(["".concat(basePath, "/")], __read(adminGuard), false), [upload.single("file"),
230
227
  (0, api_1.asyncHandler)(function (req, res) { return __awaiter(_this, void 0, void 0, function () {
231
228
  var file, targetPrefix, sanitizedFilename, gcsPath, gcsFile, documentFile;
232
229
  var _a;
package/package.json CHANGED
@@ -5,15 +5,15 @@
5
5
  },
6
6
  "dependencies": {
7
7
  "@google-cloud/storage": "^7.15.0",
8
- "@terreno/api": "57.2.0",
8
+ "@terreno/api": "57.3.0",
9
9
  "express": "^5.2.1",
10
10
  "luxon": "^3.7.2",
11
11
  "multer": "2.2.0"
12
12
  },
13
- "description": "Admin panel backend plugin for @terreno/api",
13
+ "description": "Admin panel backend plugin for @terreno/api — part of Terreno, the batteries-included TypeScript framework for universal apps.",
14
14
  "devDependencies": {
15
15
  "@biomejs/biome": "^2.3.6",
16
- "@terreno/test": "57.2.0",
16
+ "@terreno/test": "57.3.0",
17
17
  "@types/bun": "^1.4.0",
18
18
  "@types/express": "^5.0.6",
19
19
  "@types/luxon": "^3.7.1",
@@ -55,5 +55,5 @@
55
55
  "test:coverage": "bun run ../scripts/check-coverage.ts"
56
56
  },
57
57
  "types": "dist/index.d.ts",
58
- "version": "57.2.0"
58
+ "version": "57.3.0"
59
59
  }
@@ -320,11 +320,9 @@ describe("AdminApp /admin/config", () => {
320
320
  expect(res.body.models[0].defaultSort).toBe("name");
321
321
  });
322
322
 
323
- it("includes version-config custom screen", async () => {
323
+ it("does not inject version config into the custom screen navigation", async () => {
324
324
  const res = await adminAgent.get("/admin/config").expect(200);
325
- expect(res.body.customScreens).toEqual([
326
- {displayName: "Version Config", name: "version-config"},
327
- ]);
325
+ expect(res.body.customScreens).toEqual([]);
328
326
  });
329
327
 
330
328
  it("normalizes home.slots so recentActivity is last in sidebar", async () => {
package/src/adminApp.ts CHANGED
@@ -11,10 +11,11 @@ import {
11
11
  checkPermissions,
12
12
  createOpenApiBuilder,
13
13
  createScriptArgs,
14
- getOpenApiSpecForModel,
14
+ describeModel,
15
15
  type JSONValue,
16
16
  logger,
17
17
  type ModelRouterOptions,
18
+ modelDescriptionToAdminFields,
18
19
  modelRouter,
19
20
  type OpenApiMiddleware,
20
21
  type PermissionMethod,
@@ -460,23 +461,6 @@ const auditActorId = (request: express.Request): string | undefined => {
460
461
  return String(user._id);
461
462
  };
462
463
 
463
- interface OpenApiProperty {
464
- default?: unknown;
465
- description?: string;
466
- enum?: string[];
467
- $ref?: string;
468
- type?: string;
469
- format?: string;
470
- items?: {
471
- properties?: Record<string, OpenApiProperty>;
472
- required?: string[];
473
- type?: string;
474
- enum?: string[];
475
- format?: string;
476
- $ref?: string;
477
- };
478
- }
479
-
480
464
  interface ArraySchemaTypeCompatibility {
481
465
  caster?: mongoose.SchemaType;
482
466
  getEmbeddedSchemaType?: () => mongoose.SchemaType | undefined;
@@ -492,49 +476,14 @@ export const getArrayEmbeddedSchemaType = (
492
476
  return compatiblePath.caster;
493
477
  };
494
478
 
495
- const extractFieldMeta = (
496
- properties: Record<string, OpenApiProperty>,
497
- required: string[]
479
+ const extractFieldMetaFromDescription = (
480
+ model: Model<unknown>,
481
+ hiddenFields: string[]
498
482
  ): Record<string, AdminFieldMeta> => {
499
- const fields: Record<string, AdminFieldMeta> = {};
500
- for (const [key, prop] of Object.entries(properties)) {
501
- const fieldType = prop.type ?? "string";
502
- fields[key] = {
503
- default: prop.default,
504
- description: prop.description,
505
- enum: prop.enum,
506
- ref: prop.$ref ? prop.$ref.replace("#/components/schemas/", "") : undefined,
507
- required: required.includes(key),
508
- searchable: fieldType === "string" && !prop.enum,
509
- type: fieldType,
510
- };
511
-
512
- // For array fields, extract item sub-field metadata
513
- if (prop.type === "array" && prop.items?.properties) {
514
- const itemRequired: string[] = prop.items.required ?? [];
515
- fields[key].items = extractFieldMeta(
516
- prop.items.properties as Record<string, OpenApiProperty>,
517
- itemRequired
518
- );
519
- }
520
-
521
- // For array fields of primitives, capture the item type and enum
522
- if (prop.type === "array" && prop.items && !prop.items.properties) {
523
- const itemProp = prop.items as OpenApiProperty;
524
- if (itemProp.type) {
525
- fields[key].itemType = itemProp.type;
526
- }
527
- if (itemProp.enum) {
528
- fields[key].itemEnum = itemProp.enum;
529
- }
530
- }
531
-
532
- // Check for ObjectId references in the raw property
533
- if (!fields[key].ref && prop.type === "string" && prop.format === "objectid") {
534
- // mongoose-to-swagger may not preserve ref directly; we'll handle this in register()
535
- }
536
- }
537
- return fields;
483
+ const hiddenFieldSet = new Set(hiddenFields);
484
+ const description = describeModel(model);
485
+ const fields = modelDescriptionToAdminFields(description);
486
+ return Object.fromEntries(Object.entries(fields).filter(([key]) => !hiddenFieldSet.has(key)));
538
487
  };
539
488
 
540
489
  const asMiddlewareList = (
@@ -788,55 +737,8 @@ export class AdminApp {
788
737
  }))
789
738
  );
790
739
  const configModels: AdminModelMeta[] = modelConfigs.map((config, configIndex) => {
791
- const {properties, required} = getOpenApiSpecForModel(config.model) as {
792
- properties: Record<string, OpenApiProperty>;
793
- required: string[];
794
- };
795
740
  const hiddenFieldSet = new Set(config.hiddenFields ?? []);
796
- const filteredProperties = Object.fromEntries(
797
- Object.entries(properties).filter(([key]) => !hiddenFieldSet.has(key))
798
- );
799
- const filteredRequired = required.filter((key) => !hiddenFieldSet.has(key));
800
-
801
- // Extract ref information directly from the Mongoose schema
802
- const fields = extractFieldMeta(filteredProperties, filteredRequired);
803
- for (const [key, field] of Object.entries(fields)) {
804
- const schemaPath = config.model.schema.path(key);
805
- if (schemaPath) {
806
- const pathOptions = schemaPath.options;
807
- if (pathOptions?.ref) {
808
- field.ref = pathOptions.ref;
809
- }
810
- // Handle array of refs (legacy: also set ref for back-compat)
811
- if (Array.isArray(pathOptions?.type) && pathOptions.type[0]?.ref) {
812
- field.ref = pathOptions.type[0].ref;
813
- }
814
- // For arrays, use the public embedded schema type to infer the primitive item type/ref.
815
- if (schemaPath.instance === "Array") {
816
- const embeddedSchemaType = getArrayEmbeddedSchemaType(schemaPath);
817
- if (embeddedSchemaType?.instance && !field.items) {
818
- const instanceToType: Record<string, string> = {
819
- Boolean: "boolean",
820
- Number: "number",
821
- ObjectID: "objectid",
822
- ObjectId: "objectid",
823
- SchemaObjectId: "objectid",
824
- String: "string",
825
- };
826
- const mapped = instanceToType[embeddedSchemaType.instance];
827
- if (mapped) {
828
- field.itemType = mapped;
829
- }
830
- if (embeddedSchemaType.options?.ref) {
831
- field.itemRef = embeddedSchemaType.options.ref;
832
- }
833
- if (Array.isArray(embeddedSchemaType.options?.enum)) {
834
- field.itemEnum = embeddedSchemaType.options.enum;
835
- }
836
- }
837
- }
838
- }
839
- }
741
+ const fields = extractFieldMetaFromDescription(config.model, [...hiddenFieldSet]);
840
742
 
841
743
  // Apply field overrides (e.g., widget: "markdown")
842
744
  if (config.fieldOverrides) {
@@ -905,15 +807,7 @@ export class AdminApp {
905
807
  name: script.name,
906
808
  }));
907
809
 
908
- const defaultScreens: AdminCustomScreenConfig[] = [
909
- {
910
- adminAccess: {action: "read", resource: "configuration"},
911
- displayName: "Version Config",
912
- name: "version-config",
913
- },
914
- ];
915
810
  const mergedScreens: AdminCustomScreenConfig[] = [
916
- ...defaultScreens,
917
811
  ...aggregated.customScreens,
918
812
  ...(this.options.customScreens ?? []),
919
813
  ];
@@ -1,6 +1,12 @@
1
1
  import {describe, expect, it} from "bun:test";
2
2
 
3
- import {buildAdminModelQueryFields} from "./adminUiV2";
3
+ import {
4
+ buildAdminModelQueryFields,
5
+ defaultBulkPatchAllowlistFrom,
6
+ normalizeAdminHome,
7
+ normalizeSidebarRecentLast,
8
+ SYSTEM_ADMIN_FIELDS,
9
+ } from "./adminUiV2";
4
10
 
5
11
  describe("buildAdminModelQueryFields", () => {
6
12
  it("includes _id, list fields, listDisplay, searchFields, and filter fields", () => {
@@ -27,3 +33,67 @@ describe("buildAdminModelQueryFields", () => {
27
33
  expect(new Set(fields).size).toBe(fields.length);
28
34
  });
29
35
  });
36
+
37
+ describe("normalizeSidebarRecentLast", () => {
38
+ it("returns empty and missing sidebars unchanged", () => {
39
+ expect(normalizeSidebarRecentLast(undefined)).toBeUndefined();
40
+ expect(normalizeSidebarRecentLast([])).toEqual([]);
41
+ });
42
+
43
+ it("leaves a sidebar without recentActivity as-is", () => {
44
+ expect(normalizeSidebarRecentLast(["modelsGrid"])).toEqual(["modelsGrid"]);
45
+ });
46
+
47
+ it("moves recentActivity to the end", () => {
48
+ expect(normalizeSidebarRecentLast(["recentActivity", "modelsGrid"])).toEqual([
49
+ "modelsGrid",
50
+ "recentActivity",
51
+ ]);
52
+ });
53
+ });
54
+
55
+ describe("normalizeAdminHome", () => {
56
+ it("defaults to modelsGrid when home is omitted", () => {
57
+ expect(normalizeAdminHome()).toEqual({
58
+ slots: {main: ["modelsGrid"]},
59
+ title: "Administration",
60
+ });
61
+ });
62
+
63
+ it("uses provided slots and normalizes the sidebar", () => {
64
+ expect(
65
+ normalizeAdminHome({
66
+ slots: {sidebar: ["recentActivity", "nav"]},
67
+ title: "Ops",
68
+ })
69
+ ).toEqual({
70
+ slots: {sidebar: ["nav", "recentActivity"]},
71
+ title: "Ops",
72
+ });
73
+ });
74
+
75
+ it("promotes legacy widgets into main and prepends modelsGrid when missing", () => {
76
+ expect(normalizeAdminHome({widgets: ["recentActivity"]})).toEqual({
77
+ slots: {main: ["modelsGrid", "recentActivity"]},
78
+ title: "Administration",
79
+ });
80
+ expect(normalizeAdminHome({widgets: ["modelsGrid", "recentActivity"]})).toEqual({
81
+ slots: {main: ["modelsGrid", "recentActivity"]},
82
+ title: "Administration",
83
+ });
84
+ });
85
+ });
86
+
87
+ describe("defaultBulkPatchAllowlistFrom", () => {
88
+ it("keeps writable schema fields from the list", () => {
89
+ expect(
90
+ defaultBulkPatchAllowlistFrom({
91
+ hiddenFieldSet: new Set(["secret"]),
92
+ listFields: ["_id", "title", "secret", "created", "notes"],
93
+ readonlyFields: ["notes"],
94
+ schemaPaths: new Set(["title", "secret", "notes"]),
95
+ })
96
+ ).toEqual(["title"]);
97
+ expect(SYSTEM_ADMIN_FIELDS.has("_id")).toBe(true);
98
+ });
99
+ });
@@ -7,7 +7,7 @@ import type {
7
7
  TerrenoApp,
8
8
  TerrenoPlugin,
9
9
  } from "@terreno/api";
10
- import {logger} from "@terreno/api";
10
+ import {APIError, logger} from "@terreno/api";
11
11
 
12
12
  import type {AdminCustomScreenConfig, AdminModelConfig, AdminScriptConfig} from "./adminApp";
13
13
  import {convertLegacyModelConfig} from "./legacy";
@@ -133,9 +133,10 @@ export const aggregateAdminContributions = ({
133
133
  const path = registered.routePath;
134
134
  const existingRegistered = registeredByPath.get(path);
135
135
  if (existingRegistered) {
136
- throw new Error(
137
- `Duplicate admin modelRouter routePath "${path}" (${existingRegistered.sourceLabel} and ${registered.sourceLabel})`
138
- );
136
+ throw new APIError({
137
+ status: 500,
138
+ title: `Duplicate admin modelRouter routePath "${path}" (${existingRegistered.sourceLabel} and ${registered.sourceLabel})`,
139
+ });
139
140
  }
140
141
  registeredByPath.set(path, registered);
141
142
  const existing = modelsByPath.get(path);
@@ -192,9 +192,7 @@ export class DocumentStorageApp implements TerrenoPlugin {
192
192
  app.post(
193
193
  `${basePath}/`,
194
194
  ...adminGuard,
195
- // noExplicitAny: multer's RequestHandler type is incompatible with Express 5's middleware signature.
196
- // biome-ignore lint/suspicious/noExplicitAny: multer's RequestHandler type is incompatible with Express 5's middleware signature.
197
- upload.single("file") as any,
195
+ upload.single("file") as unknown as express.RequestHandler,
198
196
  asyncHandler(async (req: express.Request, res: express.Response) => {
199
197
  const file = (req as unknown as {file?: Express.Multer.File}).file;
200
198
  if (!file) {