@terreno/admin-backend 57.4.0 → 57.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/adminApp.js +1219 -1936
- package/dist/adminConfigIdentity.js +26 -50
- package/dist/adminMigrations.js +83 -168
- package/dist/adminScriptJob.js +142 -300
- package/dist/adminTextSearch.js +21 -78
- package/dist/adminUiV2.js +49 -146
- package/dist/aggregateAdmin.js +102 -227
- package/dist/documentStorageApp.js +184 -325
- package/dist/enrichAdminListFilters.js +4 -15
- package/dist/filterParser.js +158 -238
- package/dist/legacy.js +21 -25
- package/dist/resolvedAdminModel.js +22 -78
- package/dist/routePath.js +3 -3
- package/dist/scriptCli.js +161 -307
- package/dist/tests/bunSetup.js +1 -1
- package/package.json +7 -7
- package/src/adminApp.models.test.ts +89 -3
- package/src/adminApp.ts +31 -8
- package/tsconfig.json +6 -21
|
@@ -94,6 +94,22 @@ const priorityTodoSchema = new mongoose.Schema({
|
|
|
94
94
|
const PriorityTodoModel =
|
|
95
95
|
mongoose.models.AdminPriorityTodo ?? mongoose.model("AdminPriorityTodo", priorityTodoSchema);
|
|
96
96
|
|
|
97
|
+
const frameworkRefHolderSchema = new mongoose.Schema({
|
|
98
|
+
organizationId: {
|
|
99
|
+
ref: "TerrenoOrganization",
|
|
100
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
101
|
+
},
|
|
102
|
+
organizationIds: [
|
|
103
|
+
{
|
|
104
|
+
ref: "TerrenoOrganization",
|
|
105
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
const FrameworkRefHolderModel =
|
|
110
|
+
mongoose.models.AdminFrameworkRefHolder ??
|
|
111
|
+
mongoose.model("AdminFrameworkRefHolder", frameworkRefHolderSchema);
|
|
112
|
+
|
|
97
113
|
describe("getArrayEmbeddedSchemaType", () => {
|
|
98
114
|
it("supports the legacy Mongoose 8 caster property", () => {
|
|
99
115
|
const embeddedSchemaType = new mongoose.Schema({value: String}).path("value");
|
|
@@ -332,6 +348,36 @@ describe("AdminApp /admin/config", () => {
|
|
|
332
348
|
expect(foodMeta.fields.eatenBy.itemRef).toBe("User");
|
|
333
349
|
});
|
|
334
350
|
|
|
351
|
+
it("keeps framework model refs aligned with public admin config names", async () => {
|
|
352
|
+
const refApp = buildApp([
|
|
353
|
+
{
|
|
354
|
+
displayName: "Organizations",
|
|
355
|
+
listFields: ["name"],
|
|
356
|
+
model: Organization,
|
|
357
|
+
routePath: "/organizations",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
displayName: "Framework ref holders",
|
|
361
|
+
listFields: ["organizationId", "organizationIds"],
|
|
362
|
+
model: FrameworkRefHolderModel,
|
|
363
|
+
routePath: "/framework-ref-holders",
|
|
364
|
+
},
|
|
365
|
+
]);
|
|
366
|
+
const refAgent = await authAsUser(refApp, "admin");
|
|
367
|
+
const res = await refAgent.get("/admin/config").expect(200);
|
|
368
|
+
const organizationMeta = res.body.models.find(
|
|
369
|
+
(model: {routePath: string}) => model.routePath === "/admin/organizations"
|
|
370
|
+
);
|
|
371
|
+
const holderMeta = res.body.models.find(
|
|
372
|
+
(model: {routePath: string}) => model.routePath === "/admin/framework-ref-holders"
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
assert.equal(organizationMeta?.name, "Organization");
|
|
376
|
+
assert.equal(holderMeta?.fields.organizationId.ref, "Organization");
|
|
377
|
+
assert.equal(holderMeta?.fields.organizationIds.ref, "Organization");
|
|
378
|
+
assert.equal(holderMeta?.fields.organizationIds.itemRef, "Organization");
|
|
379
|
+
});
|
|
380
|
+
|
|
335
381
|
it("returns 403 for non-admin users", async () => {
|
|
336
382
|
const res = await notAdminAgent.get("/admin/config").expect(403);
|
|
337
383
|
expect(res.body.title).toInclude("Admin access required");
|
|
@@ -1636,8 +1682,8 @@ describe("AdminApp onAdminAudit is best-effort", () => {
|
|
|
1636
1682
|
});
|
|
1637
1683
|
|
|
1638
1684
|
const deleteAuditEventModel = (): void => {
|
|
1639
|
-
if (mongoose.connection.models.
|
|
1640
|
-
mongoose.connection.deleteModel("
|
|
1685
|
+
if (mongoose.connection.models.TerrenoAuditEvent) {
|
|
1686
|
+
mongoose.connection.deleteModel("TerrenoAuditEvent");
|
|
1641
1687
|
}
|
|
1642
1688
|
};
|
|
1643
1689
|
|
|
@@ -1726,7 +1772,7 @@ describe("AdminApp AuditEvent auto-write", () => {
|
|
|
1726
1772
|
|
|
1727
1773
|
it("returns 201 on POST when AuditEvent persistence throws", async () => {
|
|
1728
1774
|
const localApp = buildAppWithAuditPlugin();
|
|
1729
|
-
const AuditEvent = mongoose.connection.models.
|
|
1775
|
+
const AuditEvent = mongoose.connection.models.TerrenoAuditEvent;
|
|
1730
1776
|
const createSpy = spyOn(AuditEvent, "create").mockImplementation(() => {
|
|
1731
1777
|
throw new Error("recorder boom");
|
|
1732
1778
|
});
|
|
@@ -1767,6 +1813,7 @@ describe("AdminApp AuditEvent auto-write", () => {
|
|
|
1767
1813
|
auditMeta,
|
|
1768
1814
|
JSON.stringify(config.body.models.map((model: {name: string}) => model.name))
|
|
1769
1815
|
);
|
|
1816
|
+
assert.equal(auditMeta?.name, "AuditEvent");
|
|
1770
1817
|
assert.deepEqual(auditMeta.permissions, {create: false, delete: false, update: false});
|
|
1771
1818
|
const create = await agent.post("/admin/audit-events").send({
|
|
1772
1819
|
modelName: "Todo",
|
|
@@ -1777,6 +1824,44 @@ describe("AdminApp AuditEvent auto-write", () => {
|
|
|
1777
1824
|
assert.equal(create.status, 405, JSON.stringify(create.body));
|
|
1778
1825
|
});
|
|
1779
1826
|
|
|
1827
|
+
it("keeps AuditEvent admin name and adminAuditEvent RBAC after Mongoose rename", async () => {
|
|
1828
|
+
const auditPlugin = new AuditApp();
|
|
1829
|
+
const terrenoApp = {
|
|
1830
|
+
getPlugins: () => [auditPlugin],
|
|
1831
|
+
getRegistrations: () => [],
|
|
1832
|
+
} as unknown as TerrenoApp;
|
|
1833
|
+
const accessControl = createAccess({
|
|
1834
|
+
connection: mongoose.connection,
|
|
1835
|
+
resolvePermissions: async () => ({
|
|
1836
|
+
admin: ["access"],
|
|
1837
|
+
adminAuditEvent: ["list", "read"],
|
|
1838
|
+
}),
|
|
1839
|
+
statements: {
|
|
1840
|
+
...terrenoStatements,
|
|
1841
|
+
adminAuditEvent: ["list", "read"],
|
|
1842
|
+
},
|
|
1843
|
+
});
|
|
1844
|
+
const app = getBaseServer();
|
|
1845
|
+
setupAuth(app, UserModel as unknown as UserModelType);
|
|
1846
|
+
addAuthRoutes(app, UserModel as unknown as UserModelType);
|
|
1847
|
+
auditPlugin.register(app);
|
|
1848
|
+
new AdminApp({
|
|
1849
|
+
accessControl,
|
|
1850
|
+
basePath: "/admin",
|
|
1851
|
+
models: [foodModelConfig],
|
|
1852
|
+
}).register(app, undefined, terrenoApp);
|
|
1853
|
+
app.use(apiUnauthorizedMiddleware);
|
|
1854
|
+
app.use(apiErrorMiddleware);
|
|
1855
|
+
const agent = await authAsUser(app, "admin");
|
|
1856
|
+
const config = await agent.get("/admin/config").expect(200);
|
|
1857
|
+
const auditMeta = (config.body.models as Array<{name: string; routePath: string}>).find(
|
|
1858
|
+
(model) => model.routePath.includes("audit-events")
|
|
1859
|
+
);
|
|
1860
|
+
assert.equal(auditMeta?.name, "AuditEvent");
|
|
1861
|
+
const list = await agent.get("/admin/audit-events").expect(200);
|
|
1862
|
+
assert.isArray(list.body.data);
|
|
1863
|
+
});
|
|
1864
|
+
|
|
1780
1865
|
it("lists AuditEvent without an organization even when organizations is enabled", async () => {
|
|
1781
1866
|
const auditPlugin = new AuditApp();
|
|
1782
1867
|
const terrenoApp = {
|
|
@@ -1803,6 +1888,7 @@ describe("AdminApp AuditEvent auto-write", () => {
|
|
|
1803
1888
|
auditMeta,
|
|
1804
1889
|
JSON.stringify(config.body.models.map((model: {name: string}) => model.name))
|
|
1805
1890
|
);
|
|
1891
|
+
assert.equal(auditMeta?.name, "AuditEvent");
|
|
1806
1892
|
assert.strictEqual(auditMeta?.organizationScoped, false);
|
|
1807
1893
|
const list = await agent.get("/admin/audit-events").expect(200);
|
|
1808
1894
|
assert.isArray(list.body.data);
|
package/src/adminApp.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type PermissionMethod,
|
|
28
28
|
Permissions,
|
|
29
29
|
type PopulatePath,
|
|
30
|
+
publicFrameworkModelName,
|
|
30
31
|
registerAdminBroadcastScope,
|
|
31
32
|
registerAdminWindowMutationScope,
|
|
32
33
|
type ScriptArgDef,
|
|
@@ -75,6 +76,8 @@ import {parseAdminListFilters} from "./filterParser";
|
|
|
75
76
|
import type {ResolvedAdminModel} from "./resolvedAdminModel";
|
|
76
77
|
import {RESERVED_SCRIPT_FLAGS} from "./scriptCli";
|
|
77
78
|
|
|
79
|
+
const AUDIT_EVENT_MODEL_NAMES = new Set(["AuditEvent", "TerrenoAuditEvent"]);
|
|
80
|
+
|
|
78
81
|
/**
|
|
79
82
|
* Configuration for a single model in the admin panel.
|
|
80
83
|
*/
|
|
@@ -262,6 +265,21 @@ interface AdminFieldMeta {
|
|
|
262
265
|
itemRef?: string;
|
|
263
266
|
}
|
|
264
267
|
|
|
268
|
+
const publicFrameworkFieldMeta = (field: AdminFieldMeta): AdminFieldMeta => {
|
|
269
|
+
return {
|
|
270
|
+
...field,
|
|
271
|
+
...(field.ref ? {ref: publicFrameworkModelName(field.ref)} : {}),
|
|
272
|
+
...(field.itemRef ? {itemRef: publicFrameworkModelName(field.itemRef)} : {}),
|
|
273
|
+
...(field.items
|
|
274
|
+
? {
|
|
275
|
+
items: Object.fromEntries(
|
|
276
|
+
Object.entries(field.items).map(([key, item]) => [key, publicFrameworkFieldMeta(item)])
|
|
277
|
+
),
|
|
278
|
+
}
|
|
279
|
+
: {}),
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
|
|
265
283
|
interface AdminModelMeta {
|
|
266
284
|
actions: AdminActionInput[];
|
|
267
285
|
bulkPatchAllowlist: string[];
|
|
@@ -554,7 +572,11 @@ const extractFieldMetaFromDescription = (
|
|
|
554
572
|
const hiddenFieldSet = new Set(hiddenFields);
|
|
555
573
|
const description = describeModel(model);
|
|
556
574
|
const fields = modelDescriptionToAdminFields(description);
|
|
557
|
-
return Object.fromEntries(
|
|
575
|
+
return Object.fromEntries(
|
|
576
|
+
Object.entries(fields)
|
|
577
|
+
.filter(([key]) => !hiddenFieldSet.has(key))
|
|
578
|
+
.map(([key, field]) => [key, publicFrameworkFieldMeta(field)])
|
|
579
|
+
);
|
|
558
580
|
};
|
|
559
581
|
|
|
560
582
|
const asMiddlewareList = (
|
|
@@ -629,7 +651,7 @@ export class AdminApp {
|
|
|
629
651
|
}
|
|
630
652
|
// Platform audit rows may omit organizationId. Requiring a selected org hides
|
|
631
653
|
// those events and skips Recent Activity / the AuditEvent changelist.
|
|
632
|
-
if (config.model.modelName
|
|
654
|
+
if (AUDIT_EVENT_MODEL_NAMES.has(config.model.modelName)) {
|
|
633
655
|
return false;
|
|
634
656
|
}
|
|
635
657
|
return Boolean(config.model.schema.path("organizationId"));
|
|
@@ -706,11 +728,12 @@ export class AdminApp {
|
|
|
706
728
|
if (explicit) {
|
|
707
729
|
return explicit;
|
|
708
730
|
}
|
|
709
|
-
const
|
|
731
|
+
const publicName = publicFrameworkModelName(config.model.modelName);
|
|
732
|
+
const standard = `admin${publicName}`;
|
|
710
733
|
if (accessControl?.statements[standard]) {
|
|
711
734
|
return standard;
|
|
712
735
|
}
|
|
713
|
-
return `${
|
|
736
|
+
return `${publicName.charAt(0).toLowerCase()}${publicName.slice(1)}`;
|
|
714
737
|
}
|
|
715
738
|
|
|
716
739
|
private async isAdminModelOwned(
|
|
@@ -835,7 +858,7 @@ export class AdminApp {
|
|
|
835
858
|
request: express.Request;
|
|
836
859
|
verb: AdminAuditEvent["verb"];
|
|
837
860
|
}): Promise<void> => {
|
|
838
|
-
if (modelName
|
|
861
|
+
if (AUDIT_EVENT_MODEL_NAMES.has(modelName)) {
|
|
839
862
|
return;
|
|
840
863
|
}
|
|
841
864
|
void maybeRecordAdminAudit({
|
|
@@ -852,7 +875,7 @@ export class AdminApp {
|
|
|
852
875
|
// Build config response with field metadata from Mongoose schemas
|
|
853
876
|
const configNames = assignUniqueAdminConfigNames(
|
|
854
877
|
modelConfigs.map((config) => ({
|
|
855
|
-
modelName: config.model.modelName,
|
|
878
|
+
modelName: publicFrameworkModelName(config.model.modelName),
|
|
856
879
|
routePath: config.routePath,
|
|
857
880
|
source: config.source,
|
|
858
881
|
}))
|
|
@@ -907,7 +930,7 @@ export class AdminApp {
|
|
|
907
930
|
listDisplay,
|
|
908
931
|
listDisplayLinks: config.listDisplayLinks ?? [],
|
|
909
932
|
listFields,
|
|
910
|
-
name: configNames[configIndex] ?? config.model.modelName,
|
|
933
|
+
name: configNames[configIndex] ?? publicFrameworkModelName(config.model.modelName),
|
|
911
934
|
organizationScoped: isOrgScopedModel,
|
|
912
935
|
pageSize: config.pageSize,
|
|
913
936
|
permissions: {
|
|
@@ -1545,7 +1568,7 @@ export class AdminApp {
|
|
|
1545
1568
|
const bulkPatchOpenApi = openApiMw
|
|
1546
1569
|
? createOpenApiBuilder({openApi: openApiMw})
|
|
1547
1570
|
.withTags(["admin"])
|
|
1548
|
-
.withSummary(`Bulk patch ${config.model.modelName} documents`)
|
|
1571
|
+
.withSummary(`Bulk patch ${publicFrameworkModelName(config.model.modelName)} documents`)
|
|
1549
1572
|
.withRequestBody<{ids: string[]; patch: Record<string, unknown>}>({
|
|
1550
1573
|
ids: {
|
|
1551
1574
|
description: "Document ids to update",
|
package/tsconfig.json
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"allowJs": true,
|
|
4
|
-
"allowSyntheticDefaultImports": true,
|
|
5
|
-
"baseUrl": "./",
|
|
6
3
|
"declaration": true,
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"ignoreDeprecations": "6.0",
|
|
11
|
-
"jsx": "react",
|
|
12
|
-
"lib": ["es2017", "dom", "es2017.object"],
|
|
13
|
-
"module": "commonjs",
|
|
14
|
-
"moduleResolution": "node",
|
|
15
|
-
"noEmit": false,
|
|
4
|
+
"isolatedModules": true,
|
|
5
|
+
"lib": ["es2023"],
|
|
6
|
+
"module": "nodenext",
|
|
16
7
|
"noImplicitAny": false,
|
|
17
8
|
"noImplicitReturns": true,
|
|
18
|
-
"noImplicitThis": true,
|
|
19
|
-
"noUnusedLocals": false,
|
|
20
|
-
"noUnusedParameters": false,
|
|
21
9
|
"outDir": "./dist",
|
|
22
10
|
"rootDir": "./src",
|
|
23
|
-
"preserveConstEnums": true,
|
|
24
|
-
"removeComments": false,
|
|
25
11
|
"skipLibCheck": true,
|
|
26
12
|
"strict": true,
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"target": "es5"
|
|
13
|
+
"target": "es2023",
|
|
14
|
+
"types": ["node"]
|
|
30
15
|
},
|
|
31
16
|
"exclude": ["node_modules", "**/*.test.ts"],
|
|
32
|
-
"include": ["src
|
|
17
|
+
"include": ["src"]
|
|
33
18
|
}
|