@terreno/admin-backend 57.20.0 → 58.0.0-beta.1
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/AGENTS.md +20 -18
- package/CHANGELOG.md +93 -0
- package/biome.jsonc +1 -0
- package/dist/adminApp.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -1
- package/dist/mcpAdmin.d.ts +42 -0
- package/dist/mcpAdmin.js +213 -0
- package/e2e/smoke.ts +246 -0
- package/package.json +10 -7
- package/src/adminApp.migrations.test.ts +3 -2
- package/src/adminApp.models.test.ts +6 -3
- package/src/adminApp.test.ts +2 -2
- package/src/adminApp.ts +2 -0
- package/src/adminScriptJob.test.ts +10 -3
- package/src/adminSyncMutationAuthMismatch.test.ts +3 -2
- package/src/aggregateAdmin.test.ts +9 -5
- package/src/enrichAdminListFilters.test.ts +1 -1
- package/src/index.ts +8 -0
- package/src/mcpAdmin.test.ts +176 -0
- package/src/mcpAdmin.ts +237 -0
- package/tsconfig.typecheck.json +18 -0
package/e2e/smoke.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Real-process smoke for @terreno/admin-backend. Run `bun e2e/smoke.ts` after `bun run compile`.
|
|
3
|
+
*
|
|
4
|
+
* The smoke re-runs this file with `serve` as a child process: a minimal TerrenoApp from the
|
|
5
|
+
* compiled `@terreno/api` with one `modelRouter` model that declares `admin:`, and the compiled
|
|
6
|
+
* `AdminApp`, on a free port, against `smokeMongoUri()`. The child seeds one admin user, because
|
|
7
|
+
* signup never grants admin. The parent then checks over real HTTP that the admin reads the admin
|
|
8
|
+
* config and lists the model's documents, and that a signed-up non-admin is denied both. Exits
|
|
9
|
+
* non-zero on the first failed check.
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
freePort,
|
|
13
|
+
type SpawnedProcess,
|
|
14
|
+
smokeMongoUri,
|
|
15
|
+
spawnUntilReady,
|
|
16
|
+
stopSmokeMongo,
|
|
17
|
+
} from "@terreno/test";
|
|
18
|
+
import type express from "express";
|
|
19
|
+
import {DateTime} from "luxon";
|
|
20
|
+
import type {Schema} from "mongoose";
|
|
21
|
+
|
|
22
|
+
const SERVE_ARG = "serve";
|
|
23
|
+
const PASSWORD = "admin-backend-smoke-password-1";
|
|
24
|
+
const WIDGET_DISPLAY_NAME = "Smoke widgets";
|
|
25
|
+
/** AdminApp mounts a model at `basePath` + its modelRouter path; the app also serves `/widgets`. */
|
|
26
|
+
const ADMIN_WIDGETS_PATH = "/admin/widgets";
|
|
27
|
+
|
|
28
|
+
interface AdminConfigModel {
|
|
29
|
+
displayName: string;
|
|
30
|
+
name: string;
|
|
31
|
+
routePath: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface SmokeWidget {
|
|
35
|
+
_id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Child: the compiled API with auth, one admin-enabled model, the compiled AdminApp, and a health
|
|
41
|
+
* plugin. Both packages are imported here, not at the top, so the parent process never loads
|
|
42
|
+
* them.
|
|
43
|
+
*/
|
|
44
|
+
const serve = async (): Promise<void> => {
|
|
45
|
+
const {createdUpdatedPlugin, logger, modelRouter, Permissions, TerrenoApp} = await import(
|
|
46
|
+
"@terreno/api"
|
|
47
|
+
);
|
|
48
|
+
const {AdminApp} = await import("@terreno/admin-backend");
|
|
49
|
+
const {default: mongoose} = await import("mongoose");
|
|
50
|
+
const {default: passportLocalMongoose} = await import("passport-local-mongoose");
|
|
51
|
+
|
|
52
|
+
const userSchema = new mongoose.Schema({
|
|
53
|
+
admin: {default: false, description: "Whether the user is an admin", type: Boolean},
|
|
54
|
+
email: {description: "Sign-in email", type: String},
|
|
55
|
+
name: {description: "Display name", type: String},
|
|
56
|
+
});
|
|
57
|
+
userSchema.plugin(passportLocalMongoose as unknown as (schema: Schema, options: object) => void, {
|
|
58
|
+
usernameCaseInsensitive: true,
|
|
59
|
+
usernameField: "email",
|
|
60
|
+
});
|
|
61
|
+
userSchema.plugin(createdUpdatedPlugin);
|
|
62
|
+
const User = mongoose.model("User", userSchema);
|
|
63
|
+
|
|
64
|
+
const widgetSchema = new mongoose.Schema({
|
|
65
|
+
name: {description: "Widget name", required: true, type: String},
|
|
66
|
+
});
|
|
67
|
+
widgetSchema.plugin(createdUpdatedPlugin);
|
|
68
|
+
const Widget = mongoose.model("Widget", widgetSchema);
|
|
69
|
+
|
|
70
|
+
const widgetRouter = modelRouter("/widgets", Widget, {
|
|
71
|
+
admin: {displayName: WIDGET_DISPLAY_NAME, listFields: ["name", "created"]},
|
|
72
|
+
permissions: {
|
|
73
|
+
create: [Permissions.IsAdmin],
|
|
74
|
+
delete: [Permissions.IsAdmin],
|
|
75
|
+
list: [Permissions.IsAdmin],
|
|
76
|
+
read: [Permissions.IsAdmin],
|
|
77
|
+
update: [Permissions.IsAdmin],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const healthPlugin = {
|
|
82
|
+
register: (app: express.Application): void => {
|
|
83
|
+
app.get("/health", (_req, res) => {
|
|
84
|
+
res.json({healthy: mongoose.connection.readyState === 1});
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
await mongoose.connect(process.env.MONGO_URI as string);
|
|
90
|
+
await (
|
|
91
|
+
User as unknown as {register: (user: object, password: string) => Promise<unknown>}
|
|
92
|
+
).register(
|
|
93
|
+
{admin: true, email: process.env.SMOKE_ADMIN_EMAIL, name: "Smoke admin"},
|
|
94
|
+
process.env.SMOKE_ADMIN_PASSWORD as string
|
|
95
|
+
);
|
|
96
|
+
await Widget.create({name: process.env.SMOKE_WIDGET_NAME});
|
|
97
|
+
|
|
98
|
+
const app = new TerrenoApp({
|
|
99
|
+
loggingOptions: {logRequests: false},
|
|
100
|
+
userModel: User as unknown as ConstructorParameters<typeof TerrenoApp>[0]["userModel"],
|
|
101
|
+
})
|
|
102
|
+
.register(widgetRouter)
|
|
103
|
+
.register(new AdminApp({}))
|
|
104
|
+
.register(healthPlugin);
|
|
105
|
+
app.start();
|
|
106
|
+
await app.whenReady();
|
|
107
|
+
logger.info(`[adminBackendSmoke] serving on port ${process.env.PORT}`);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const expectStatus = async (res: Response, status: number, step: string): Promise<unknown> => {
|
|
111
|
+
const body = await res.text();
|
|
112
|
+
if (res.status !== status) {
|
|
113
|
+
throw new Error(`${step}: expected ${status}, got ${res.status}: ${body}`);
|
|
114
|
+
}
|
|
115
|
+
return body ? JSON.parse(body) : undefined;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const bearer = (token: string): Record<string, string> => ({
|
|
119
|
+
Authorization: `Bearer ${token}`,
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const signIn = async (
|
|
124
|
+
baseUrl: string,
|
|
125
|
+
route: "login" | "signup",
|
|
126
|
+
email: string
|
|
127
|
+
): Promise<string> => {
|
|
128
|
+
const res = (await expectStatus(
|
|
129
|
+
await fetch(`${baseUrl}/auth/${route}`, {
|
|
130
|
+
body: JSON.stringify({email, password: PASSWORD}),
|
|
131
|
+
headers: {"Content-Type": "application/json"},
|
|
132
|
+
method: "POST",
|
|
133
|
+
}),
|
|
134
|
+
200,
|
|
135
|
+
`POST /auth/${route}`
|
|
136
|
+
)) as {data: {token: string}};
|
|
137
|
+
return res.data.token;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** Parent: boots the child and walks the admin read path and the non-admin denial over HTTP. */
|
|
141
|
+
const run = async (): Promise<void> => {
|
|
142
|
+
const startedAt = DateTime.now();
|
|
143
|
+
const runId = startedAt.toMillis();
|
|
144
|
+
const adminEmail = `admin-backend-smoke-admin-${runId}@example.com`;
|
|
145
|
+
const widgetName = `Smoke widget ${runId}`;
|
|
146
|
+
const port = await freePort();
|
|
147
|
+
const baseUrl = `http://127.0.0.1:${port}`;
|
|
148
|
+
let server: SpawnedProcess | undefined;
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
server = await spawnUntilReady({
|
|
152
|
+
cmd: [process.execPath, __filename, SERVE_ARG],
|
|
153
|
+
env: {
|
|
154
|
+
MONGO_URI: await smokeMongoUri({databaseName: "adminBackendSmoke"}),
|
|
155
|
+
PORT: String(port),
|
|
156
|
+
REFRESH_TOKEN_SECRET: "admin-backend-smoke-refresh-secret",
|
|
157
|
+
SESSION_SECRET: "admin-backend-smoke-session-secret",
|
|
158
|
+
SMOKE_ADMIN_EMAIL: adminEmail,
|
|
159
|
+
SMOKE_ADMIN_PASSWORD: PASSWORD,
|
|
160
|
+
SMOKE_WIDGET_NAME: widgetName,
|
|
161
|
+
TOKEN_ISSUER: "admin-backend-smoke",
|
|
162
|
+
TOKEN_SECRET: "admin-backend-smoke-token-secret",
|
|
163
|
+
},
|
|
164
|
+
timeoutMs: 30000,
|
|
165
|
+
url: `${baseUrl}/health`,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const adminToken = await signIn(baseUrl, "login", adminEmail);
|
|
169
|
+
console.info("✅ POST /auth/login signs in the seeded admin");
|
|
170
|
+
|
|
171
|
+
const config = (await expectStatus(
|
|
172
|
+
await fetch(`${baseUrl}/admin/config`, {headers: bearer(adminToken)}),
|
|
173
|
+
200,
|
|
174
|
+
"GET /admin/config as admin"
|
|
175
|
+
)) as {models: AdminConfigModel[]};
|
|
176
|
+
const widgetModel = config.models.find((model) => model.displayName === WIDGET_DISPLAY_NAME);
|
|
177
|
+
if (!widgetModel) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`GET /admin/config: the "${WIDGET_DISPLAY_NAME}" model is missing: ${JSON.stringify(config.models)}`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (widgetModel.routePath !== ADMIN_WIDGETS_PATH) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`GET /admin/config: expected routePath ${ADMIN_WIDGETS_PATH}, got ${widgetModel.routePath}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
console.info(`✅ GET /admin/config lists the ${widgetModel.name} model`);
|
|
188
|
+
|
|
189
|
+
const list = (await expectStatus(
|
|
190
|
+
await fetch(`${baseUrl}${ADMIN_WIDGETS_PATH}`, {headers: bearer(adminToken)}),
|
|
191
|
+
200,
|
|
192
|
+
`GET ${ADMIN_WIDGETS_PATH} as admin`
|
|
193
|
+
)) as {data: SmokeWidget[]};
|
|
194
|
+
if (!list.data.some((widget) => widget.name === widgetName)) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`GET ${ADMIN_WIDGETS_PATH}: the seeded widget is missing: ${JSON.stringify(list.data)}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
console.info(`✅ GET ${ADMIN_WIDGETS_PATH} lists the seeded widget`);
|
|
200
|
+
|
|
201
|
+
const userToken = await signIn(
|
|
202
|
+
baseUrl,
|
|
203
|
+
"signup",
|
|
204
|
+
`admin-backend-smoke-user-${runId}@example.com`
|
|
205
|
+
);
|
|
206
|
+
console.info("✅ POST /auth/signup signs in a non-admin user");
|
|
207
|
+
|
|
208
|
+
await expectStatus(
|
|
209
|
+
await fetch(`${baseUrl}/admin/config`, {headers: bearer(userToken)}),
|
|
210
|
+
403,
|
|
211
|
+
"GET /admin/config as non-admin"
|
|
212
|
+
);
|
|
213
|
+
console.info("✅ GET /admin/config returns 403 for the non-admin");
|
|
214
|
+
|
|
215
|
+
// modelRouter answers a permission denial on a CRUD route with 405, not 403.
|
|
216
|
+
await expectStatus(
|
|
217
|
+
await fetch(`${baseUrl}${ADMIN_WIDGETS_PATH}`, {headers: bearer(userToken)}),
|
|
218
|
+
405,
|
|
219
|
+
`GET ${ADMIN_WIDGETS_PATH} as non-admin`
|
|
220
|
+
);
|
|
221
|
+
console.info(`✅ GET ${ADMIN_WIDGETS_PATH} returns 405 for the non-admin`);
|
|
222
|
+
} catch (error: unknown) {
|
|
223
|
+
if (server) {
|
|
224
|
+
console.error(`--- server output ---\n${server.output()}`);
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
} finally {
|
|
228
|
+
await server?.stop();
|
|
229
|
+
await stopSmokeMongo();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
console.info(`admin-backend smoke passed in ${DateTime.now().diff(startedAt).toMillis()} ms`);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const main = process.argv[2] === SERVE_ARG ? serve : run;
|
|
236
|
+
main().then(
|
|
237
|
+
() => {
|
|
238
|
+
if (main === run) {
|
|
239
|
+
process.exit(0);
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
(error: unknown) => {
|
|
243
|
+
console.error(`❌ ${error instanceof Error ? error.message : String(error)}`);
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
);
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@google-cloud/storage": "^7.15.0",
|
|
8
|
-
"@terreno/api": "
|
|
9
|
-
"@terreno/jobs": "
|
|
8
|
+
"@terreno/api": "58.0.0-beta.1",
|
|
9
|
+
"@terreno/jobs": "58.0.0-beta.1",
|
|
10
10
|
"express": "^5.2.1",
|
|
11
11
|
"luxon": "^3.7.2",
|
|
12
12
|
"multer": "2.2.0"
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
"description": "Admin panel backend plugin for @terreno/api — part of Terreno, the batteries-included TypeScript framework for universal apps.",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@biomejs/biome": "^2.3.6",
|
|
17
|
-
"@terreno/test": "
|
|
17
|
+
"@terreno/test": "58.0.0-beta.1",
|
|
18
18
|
"@types/bun": "^1.4.0",
|
|
19
19
|
"@types/express": "^5.0.6",
|
|
20
20
|
"@types/luxon": "^3.7.1",
|
|
21
21
|
"@types/multer": "^1.4.12",
|
|
22
22
|
"@types/supertest": "^7.2.0",
|
|
23
|
+
"passport-local-mongoose": "^9.0.1",
|
|
23
24
|
"supertest": "^7.2.2",
|
|
24
25
|
"typescript": "~6.0.3"
|
|
25
26
|
},
|
|
@@ -47,13 +48,15 @@
|
|
|
47
48
|
"compile": "node ../.github/scripts/compile-workspace-deps.js && bun tsc",
|
|
48
49
|
"compile:watch": "bun tsc -w",
|
|
49
50
|
"dev": "bun tsc -w",
|
|
50
|
-
"lint": "biome check ./src",
|
|
51
|
-
"lint:fix": "biome check --write ./src",
|
|
51
|
+
"lint": "biome check ./src ./e2e",
|
|
52
|
+
"lint:fix": "biome check --write ./src ./e2e",
|
|
53
|
+
"smoke": "bun e2e/smoke.ts",
|
|
52
54
|
"test": "bun test --timeout=120000",
|
|
53
55
|
"test:agent": "AGENT=1 bun test --only-failures --timeout=120000",
|
|
54
56
|
"test:ci": "bun test --timeout=120000",
|
|
55
|
-
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
57
|
+
"test:coverage": "bun run ../scripts/check-coverage.ts",
|
|
58
|
+
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
56
59
|
},
|
|
57
60
|
"types": "dist/index.d.ts",
|
|
58
|
-
"version": "
|
|
61
|
+
"version": "58.0.0-beta.1"
|
|
59
62
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
createAccess,
|
|
12
12
|
MIGRATION_LOCK_ID,
|
|
13
13
|
MIGRATIONS_COLLECTION,
|
|
14
|
+
type MigrationStoreDoc,
|
|
14
15
|
setupAuth,
|
|
15
16
|
terrenoStatements,
|
|
16
17
|
type UserModel as UserModelType,
|
|
@@ -22,7 +23,7 @@ import type TestAgent from "supertest/lib/agent";
|
|
|
22
23
|
|
|
23
24
|
import {AdminApp} from "./adminApp";
|
|
24
25
|
|
|
25
|
-
const fixturesDir = join(
|
|
26
|
+
const fixturesDir = join(__dirname, "../../api/src/migrations/fixtures/valid");
|
|
26
27
|
|
|
27
28
|
const buildApp = ({
|
|
28
29
|
accessControl,
|
|
@@ -52,7 +53,7 @@ const waitForTask = (): Promise<void> => {
|
|
|
52
53
|
|
|
53
54
|
const appliedIds = async (): Promise<string[]> => {
|
|
54
55
|
const docs = await mongoose.connection
|
|
55
|
-
.collection(MIGRATIONS_COLLECTION)
|
|
56
|
+
.collection<MigrationStoreDoc>(MIGRATIONS_COLLECTION)
|
|
56
57
|
.find({_id: {$ne: MIGRATION_LOCK_ID}})
|
|
57
58
|
.project({id: 1})
|
|
58
59
|
.toArray();
|
|
@@ -34,13 +34,16 @@ import {
|
|
|
34
34
|
} from "@terreno/api/testing";
|
|
35
35
|
import {assert} from "chai";
|
|
36
36
|
import type express from "express";
|
|
37
|
-
import mongoose from "mongoose";
|
|
37
|
+
import mongoose, {type Model} from "mongoose";
|
|
38
38
|
import supertest from "supertest";
|
|
39
39
|
import type TestAgent from "supertest/lib/agent";
|
|
40
40
|
|
|
41
41
|
import type {AdminAuditEvent, AdminModelConfig, AdminOptions} from "./adminApp";
|
|
42
42
|
import {AdminApp, getArrayEmbeddedSchemaType} from "./adminApp";
|
|
43
43
|
|
|
44
|
+
/** Plugin contributions take `Model<unknown>`; the shared Food fixture keys `_id` as a string. */
|
|
45
|
+
const contributedFoodModel = FoodModel as unknown as Model<unknown>;
|
|
46
|
+
|
|
44
47
|
const buildApp = (
|
|
45
48
|
models: AdminModelConfig[] = [],
|
|
46
49
|
adminOverrides?: Partial<AdminOptions>
|
|
@@ -175,7 +178,7 @@ describe("AdminApp /admin/config", () => {
|
|
|
175
178
|
models: [
|
|
176
179
|
{
|
|
177
180
|
admin: {displayName: "Flags", listFields: ["key"]},
|
|
178
|
-
model:
|
|
181
|
+
model: contributedFoodModel,
|
|
179
182
|
routePath: "/feature-flags",
|
|
180
183
|
},
|
|
181
184
|
],
|
|
@@ -2219,7 +2222,7 @@ describe("AdminApp adminPermissions methods", () => {
|
|
|
2219
2222
|
listFields: ["name", "calories"],
|
|
2220
2223
|
searchFields: ["name"],
|
|
2221
2224
|
},
|
|
2222
|
-
model:
|
|
2225
|
+
model: contributedFoodModel,
|
|
2223
2226
|
routePath: "/locked-foods",
|
|
2224
2227
|
},
|
|
2225
2228
|
],
|
package/src/adminApp.test.ts
CHANGED
|
@@ -18,7 +18,7 @@ import mongoose from "mongoose";
|
|
|
18
18
|
import supertest from "supertest";
|
|
19
19
|
import type TestAgent from "supertest/lib/agent";
|
|
20
20
|
|
|
21
|
-
import {AdminApp} from "./adminApp";
|
|
21
|
+
import {AdminApp, type AdminScriptConfig} from "./adminApp";
|
|
22
22
|
|
|
23
23
|
const createTestScript = (overrides?: {
|
|
24
24
|
runner?: ScriptRunner;
|
|
@@ -53,7 +53,7 @@ const createFailingScript = () => ({
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const buildApp = (
|
|
56
|
-
scripts = [createTestScript()],
|
|
56
|
+
scripts: AdminScriptConfig[] = [createTestScript()],
|
|
57
57
|
accessControl?: AnyTerrenoAccess
|
|
58
58
|
): express.Application => {
|
|
59
59
|
const app = getBaseServer();
|
package/src/adminApp.ts
CHANGED
|
@@ -123,6 +123,8 @@ export interface AdminModelConfig {
|
|
|
123
123
|
fieldOrder?: string[];
|
|
124
124
|
/** Fields to hide from admin forms/responses (e.g., password hash fields). */
|
|
125
125
|
hiddenFields?: string[];
|
|
126
|
+
/** Fields stripped from admin create and update bodies. */
|
|
127
|
+
excludeFields?: string[];
|
|
126
128
|
/** Optional sidebar / nav grouping label for schema v2 shells */
|
|
127
129
|
group?: string;
|
|
128
130
|
/** Changelist columns (defaults to listFields) */
|
|
@@ -4,12 +4,19 @@ import {
|
|
|
4
4
|
apiErrorMiddleware,
|
|
5
5
|
apiUnauthorizedMiddleware,
|
|
6
6
|
BackgroundTask,
|
|
7
|
+
createScopedLogger,
|
|
7
8
|
createScriptArgs,
|
|
8
9
|
setupAuth,
|
|
9
10
|
type UserModel as UserModelType,
|
|
10
11
|
} from "@terreno/api";
|
|
11
12
|
import {getBaseServer, setupDb, UserModel} from "@terreno/api/testing";
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Job,
|
|
15
|
+
type JobDefinition,
|
|
16
|
+
type JobHandlerContext,
|
|
17
|
+
JobsApp,
|
|
18
|
+
unregisterJobsService,
|
|
19
|
+
} from "@terreno/jobs";
|
|
13
20
|
|
|
14
21
|
import {
|
|
15
22
|
ADMIN_SCRIPT_JOB_NAME,
|
|
@@ -38,9 +45,9 @@ const getAdminScriptHandler = (
|
|
|
38
45
|
return handler;
|
|
39
46
|
};
|
|
40
47
|
|
|
41
|
-
const mockJobContext = {
|
|
42
|
-
attempt: 1,
|
|
48
|
+
const mockJobContext: JobHandlerContext = {
|
|
43
49
|
jobId: "job-test",
|
|
50
|
+
log: createScopedLogger({prefix: "job-test"}),
|
|
44
51
|
signal: new AbortController().signal,
|
|
45
52
|
};
|
|
46
53
|
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
Membership,
|
|
17
17
|
Organization,
|
|
18
18
|
orgScopedPlugin,
|
|
19
|
+
type PermissionSet,
|
|
19
20
|
Permissions,
|
|
20
21
|
registerSync,
|
|
21
22
|
SyncApp,
|
|
@@ -116,7 +117,7 @@ const buildHarness = ({
|
|
|
116
117
|
if (productHookTracker) {
|
|
117
118
|
productHookTracker.preCreateCalls++;
|
|
118
119
|
}
|
|
119
|
-
return productSyncOptions.preCreate(body, req);
|
|
120
|
+
return productSyncOptions.preCreate(body as Record<string, unknown>, req);
|
|
120
121
|
},
|
|
121
122
|
preUpdate: (body, _req) => {
|
|
122
123
|
if (productHookTracker) {
|
|
@@ -522,7 +523,7 @@ const buildOrgWindowHarness = (): express.Application => {
|
|
|
522
523
|
const accessControl = createAccess({
|
|
523
524
|
connection: mongoose.connection,
|
|
524
525
|
organizations: true,
|
|
525
|
-
resolvePermissions: async ({user}) => {
|
|
526
|
+
resolvePermissions: async ({user}): Promise<PermissionSet> => {
|
|
526
527
|
if (user?.admin) {
|
|
527
528
|
return {admin: ["access"], adminWindowOrgTodo: ["read", "write"]};
|
|
528
529
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
-
import type {AdminConfig, AdminContribution, TerrenoPlugin} from "@terreno/api";
|
|
2
|
+
import type {AdminConfig, AdminContribution, ScriptResult, TerrenoPlugin} from "@terreno/api";
|
|
3
3
|
import {modelRouter, Permissions} from "@terreno/api";
|
|
4
4
|
import {FoodModel} from "@terreno/api/testing";
|
|
5
5
|
import {assert} from "chai";
|
|
6
|
+
import type {Model} from "mongoose";
|
|
6
7
|
|
|
7
8
|
import type {AdminModelConfig} from "./adminApp";
|
|
8
9
|
import {
|
|
@@ -14,6 +15,9 @@ import {
|
|
|
14
15
|
import {resetLegacyDeprecationWarningsForTests} from "./legacy";
|
|
15
16
|
import {normalizeAdminRoutePath} from "./routePath";
|
|
16
17
|
|
|
18
|
+
/** Plugin contributions take `Model<unknown>`; the shared Food fixture keys `_id` as a string. */
|
|
19
|
+
const contributedFoodModel = FoodModel as unknown as Model<unknown>;
|
|
20
|
+
|
|
17
21
|
const foodAdmin: AdminConfig = {
|
|
18
22
|
displayName: "Foods",
|
|
19
23
|
listFields: ["name"],
|
|
@@ -42,7 +46,7 @@ describe("aggregateAdminContributions", () => {
|
|
|
42
46
|
models: [
|
|
43
47
|
{
|
|
44
48
|
admin: {displayName: "Plugin Users", listFields: ["email"]},
|
|
45
|
-
model:
|
|
49
|
+
model: contributedFoodModel,
|
|
46
50
|
routePath: "/users",
|
|
47
51
|
},
|
|
48
52
|
],
|
|
@@ -98,7 +102,7 @@ describe("aggregateAdminContributions", () => {
|
|
|
98
102
|
});
|
|
99
103
|
|
|
100
104
|
it("merges unique scripts, screens, and widget ids and skips duplicates", () => {
|
|
101
|
-
const runner = async (): Promise<
|
|
105
|
+
const runner = async (): Promise<ScriptResult> => ({results: [], success: true});
|
|
102
106
|
const aggregated = aggregateAdminContributions({
|
|
103
107
|
pluginContributions: [
|
|
104
108
|
{
|
|
@@ -134,7 +138,7 @@ describe("aggregateAdminContributions", () => {
|
|
|
134
138
|
models: [
|
|
135
139
|
{
|
|
136
140
|
admin: {displayName: "Foods", listFields: ["name"]},
|
|
137
|
-
model:
|
|
141
|
+
model: contributedFoodModel,
|
|
138
142
|
populatePaths: [{fields: ["email"], path: "ownerId"}],
|
|
139
143
|
routePath: "/foods",
|
|
140
144
|
},
|
|
@@ -239,7 +243,7 @@ describe("aggregateFromTerrenoApp", () => {
|
|
|
239
243
|
models: [
|
|
240
244
|
{
|
|
241
245
|
admin: {displayName: "Flags", listFields: ["key"]},
|
|
242
|
-
model:
|
|
246
|
+
model: contributedFoodModel,
|
|
243
247
|
routePath: "/feature-flags",
|
|
244
248
|
},
|
|
245
249
|
],
|
|
@@ -26,7 +26,7 @@ describe("enrichAdminListFilters", () => {
|
|
|
26
26
|
},
|
|
27
27
|
];
|
|
28
28
|
const enriched = enrichAdminListFilters(filters, PriorityModel);
|
|
29
|
-
expect(enriched?.[0]).toEqual({...filters[0], allowEmpty: true});
|
|
29
|
+
expect<unknown>(enriched?.[0]).toEqual({...filters[0], allowEmpty: true});
|
|
30
30
|
expect(enriched?.[1]).toEqual(filters[1]);
|
|
31
31
|
});
|
|
32
32
|
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,14 @@ export {DocumentStorageApp} from "./documentStorageApp";
|
|
|
48
48
|
export type {ParseAdminListFiltersResult} from "./filterParser";
|
|
49
49
|
export {parseAdminListFilters} from "./filterParser";
|
|
50
50
|
export {convertLegacyModelConfig, resetLegacyDeprecationWarningsForTests} from "./legacy";
|
|
51
|
+
export {
|
|
52
|
+
MCP_ADMIN_GROUP,
|
|
53
|
+
type McpAdminModelsOptions,
|
|
54
|
+
mcpAdminModels,
|
|
55
|
+
mcpAdminScripts,
|
|
56
|
+
mcpAdminStatements,
|
|
57
|
+
mcpSignOutEverywhere,
|
|
58
|
+
} from "./mcpAdmin";
|
|
51
59
|
export type {AdminModelSource, ResolvedAdminModel} from "./resolvedAdminModel";
|
|
52
60
|
export {resolvedModelFromAdminConfig} from "./resolvedAdminModel";
|
|
53
61
|
export {normalizeAdminRoutePath} from "./routePath";
|