@terreno/api 57.6.1 → 57.8.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/dist/actions.d.ts +1 -0
- package/dist/actions.js +1 -1
- package/package.json +3 -3
- package/src/actions.test.ts +19 -0
- package/src/actions.ts +2 -1
package/dist/actions.d.ts
CHANGED
package/dist/actions.js
CHANGED
|
@@ -317,7 +317,7 @@ const buildActionMiddleware = (model, options, registered) => {
|
|
|
317
317
|
(0, exports.wrapActionResponse)(result, action, res);
|
|
318
318
|
});
|
|
319
319
|
const chain = [
|
|
320
|
-
(0, auth_1.authenticateMiddleware)(options.allowAnonymous),
|
|
320
|
+
(0, auth_1.authenticateMiddleware)(action.allowAnonymous ?? options.allowAnonymous),
|
|
321
321
|
(0, exports.createActionOpenApiMiddleware)({ action, actionName, model, options, scope }),
|
|
322
322
|
preDocPermissions,
|
|
323
323
|
];
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"@modelcontextprotocol/node": "^2.0.0",
|
|
12
12
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
13
13
|
"@sentry/bun": "^10.39.0",
|
|
14
|
-
"@terreno/test": "57.
|
|
14
|
+
"@terreno/test": "57.8.0",
|
|
15
15
|
"@thream/socketio-jwt": "^3.1.4",
|
|
16
16
|
"@types/qs": "^6.14.0",
|
|
17
17
|
"ajv": "8.20.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@biomejs/biome": "^2.3.6",
|
|
50
50
|
"@modelcontextprotocol/client": "^2.0.0",
|
|
51
|
-
"@terreno/syncdb": "57.
|
|
51
|
+
"@terreno/syncdb": "57.8.0",
|
|
52
52
|
"@types/bun": "^1.4.0",
|
|
53
53
|
"@types/cors": "^2.8.17",
|
|
54
54
|
"@types/express": "^5.0.6",
|
|
@@ -132,5 +132,5 @@
|
|
|
132
132
|
"updateSnapshot": "bun test --update-snapshots"
|
|
133
133
|
},
|
|
134
134
|
"types": "dist/index.d.ts",
|
|
135
|
-
"version": "57.
|
|
135
|
+
"version": "57.8.0"
|
|
136
136
|
}
|
package/src/actions.test.ts
CHANGED
|
@@ -367,6 +367,25 @@ describe("modelRouter actions", () => {
|
|
|
367
367
|
expect(res.body.title).toBe("Unauthorized");
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
+
it("allows one anonymous action without making the model router anonymous", async () => {
|
|
371
|
+
mountFoodRouter({
|
|
372
|
+
allowAnonymous: false,
|
|
373
|
+
collectionActions: {
|
|
374
|
+
ingest: {
|
|
375
|
+
allowAnonymous: true,
|
|
376
|
+
handler: async () => ({ok: true}),
|
|
377
|
+
method: "POST",
|
|
378
|
+
permissions: [Permissions.IsAny],
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
permissions: allPermissions,
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const actionResponse = await server.post("/food/ingest").send({}).expect(200);
|
|
385
|
+
expect(actionResponse.body.data).toEqual({ok: true});
|
|
386
|
+
await server.get("/food").expect(401);
|
|
387
|
+
});
|
|
388
|
+
|
|
370
389
|
it("returns 405 for collection action when pre-doc permission denied", async () => {
|
|
371
390
|
mountFoodRouter({
|
|
372
391
|
collectionActions: {
|
package/src/actions.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface ActionContext<TDoc, TBody, TQuery> {
|
|
|
26
26
|
|
|
27
27
|
interface BaseActionConfig<TBody, TQuery, TResponse> {
|
|
28
28
|
method: "GET" | "POST";
|
|
29
|
+
allowAnonymous?: boolean;
|
|
29
30
|
permissions?: PermissionMethod<unknown>[];
|
|
30
31
|
access?: {resource: string; action: string};
|
|
31
32
|
body?: ZodSchema<TBody>;
|
|
@@ -468,7 +469,7 @@ const buildActionMiddleware = <T>(
|
|
|
468
469
|
});
|
|
469
470
|
|
|
470
471
|
const chain: express.RequestHandler[] = [
|
|
471
|
-
authenticateMiddleware(options.allowAnonymous),
|
|
472
|
+
authenticateMiddleware(action.allowAnonymous ?? options.allowAnonymous),
|
|
472
473
|
createActionOpenApiMiddleware({action, actionName, model, options, scope}),
|
|
473
474
|
preDocPermissions,
|
|
474
475
|
];
|