@terreno/api 57.1.0 → 57.2.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/adminTypes.d.ts +26 -0
- package/dist/rbac/statements.d.ts +10 -0
- package/dist/rbac/statements.js +13 -2
- package/package.json +4 -4
- package/src/adminTypes.ts +23 -0
- package/src/rbac/statements.test.ts +2 -0
- package/src/rbac/statements.ts +12 -1
package/dist/adminTypes.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type express from "express";
|
|
2
2
|
import type { Model } from "mongoose";
|
|
3
|
+
import type { User } from "./auth";
|
|
3
4
|
import type { PermissionMethod, RESTPermissions } from "./permissions";
|
|
4
5
|
import type { PopulatePath } from "./populate";
|
|
5
6
|
import type { ScriptArgDef, ScriptRunner } from "./scriptRunner";
|
|
@@ -62,6 +63,25 @@ export interface AdminModelPermissions {
|
|
|
62
63
|
delete?: boolean;
|
|
63
64
|
update?: boolean;
|
|
64
65
|
}
|
|
66
|
+
export interface AdminAccessContext {
|
|
67
|
+
action: string;
|
|
68
|
+
instance?: unknown;
|
|
69
|
+
user?: User;
|
|
70
|
+
}
|
|
71
|
+
export interface AdminAccessConfig {
|
|
72
|
+
/**
|
|
73
|
+
* RBAC resource for the standard read/write/writeOwned controls. Defaults to
|
|
74
|
+
* `admin<ModelName>` when that statement exists, then the legacy camel-cased model name.
|
|
75
|
+
*/
|
|
76
|
+
resource?: string;
|
|
77
|
+
/** Determines whether the current user owns an instance for writeOwned access. */
|
|
78
|
+
isOwned?: (args: {
|
|
79
|
+
instance: unknown;
|
|
80
|
+
user: User;
|
|
81
|
+
}) => boolean | Promise<boolean>;
|
|
82
|
+
/** Completely replaces the standard RBAC decision for this model. */
|
|
83
|
+
authorize?: (args: AdminAccessContext) => boolean | Promise<boolean>;
|
|
84
|
+
}
|
|
65
85
|
export interface AdminConfig {
|
|
66
86
|
displayName: string;
|
|
67
87
|
group?: string;
|
|
@@ -88,6 +108,8 @@ export interface AdminConfig {
|
|
|
88
108
|
read: PermissionMethod<unknown>[];
|
|
89
109
|
update: PermissionMethod<unknown>[];
|
|
90
110
|
}>;
|
|
111
|
+
/** Fine-grained admin RBAC and optional ownership/custom authorization. */
|
|
112
|
+
adminAccess?: AdminAccessConfig;
|
|
91
113
|
adminFilter?: (req: express.Request) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
92
114
|
actions?: AdminAction[];
|
|
93
115
|
/** When true, scrubbed `admin:model.changed` events fire after mutations (no socket transport). */
|
|
@@ -108,6 +130,10 @@ export interface AdminCustomScreen {
|
|
|
108
130
|
group?: string;
|
|
109
131
|
icon?: string;
|
|
110
132
|
name: string;
|
|
133
|
+
/** RBAC or custom authorization for exposing this screen in admin metadata/navigation. */
|
|
134
|
+
adminAccess?: Pick<AdminAccessConfig, "authorize" | "resource"> & {
|
|
135
|
+
action?: string;
|
|
136
|
+
};
|
|
111
137
|
}
|
|
112
138
|
export interface AdminHomeSlots {
|
|
113
139
|
contentTop?: string[];
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
export declare const ADMIN_MODEL_ACCESS: readonly ["read", "write", "writeOwned"];
|
|
2
|
+
/** Resource/action that opens the admin panel. Other admin permissions do not grant entry. */
|
|
3
|
+
export declare const ADMIN_PAGE_RESOURCE: "admin";
|
|
4
|
+
export declare const ADMIN_PAGE_ACTION: "access";
|
|
5
|
+
export declare const ADMIN_PAGE_PERMISSION: {
|
|
6
|
+
readonly admin: readonly ["access"];
|
|
7
|
+
};
|
|
1
8
|
export declare const terrenoStatements: {
|
|
2
9
|
readonly admin: readonly ["access", "runScripts", "viewBackgroundTasks"];
|
|
10
|
+
readonly adminConsentForm: readonly ["read", "write", "writeOwned"];
|
|
11
|
+
readonly adminConsentResponse: readonly ["read", "write", "writeOwned"];
|
|
12
|
+
readonly adminFeatureFlag: readonly ["read", "write", "writeOwned"];
|
|
3
13
|
readonly configuration: readonly ["read", "update"];
|
|
4
14
|
readonly consentForm: readonly ["create", "list", "read", "update", "delete"];
|
|
5
15
|
readonly consentResponse: readonly ["list", "read"];
|
package/dist/rbac/statements.js
CHANGED
|
@@ -46,11 +46,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
46
46
|
}
|
|
47
47
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
48
|
};
|
|
49
|
+
var _a;
|
|
49
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.expandRolePermissions = exports.mergeStatements = exports.READ_ONLY_ROLE_PERMISSIONS = exports.READ_ACTIONS = exports.terrenoStatements = void 0;
|
|
51
|
+
exports.expandRolePermissions = exports.mergeStatements = exports.READ_ONLY_ROLE_PERMISSIONS = exports.READ_ACTIONS = exports.terrenoStatements = exports.ADMIN_PAGE_PERMISSION = exports.ADMIN_PAGE_ACTION = exports.ADMIN_PAGE_RESOURCE = exports.ADMIN_MODEL_ACCESS = void 0;
|
|
51
52
|
var MODEL_CRUD = ["create", "list", "read", "update", "delete"];
|
|
53
|
+
exports.ADMIN_MODEL_ACCESS = ["read", "write", "writeOwned"];
|
|
54
|
+
/** Resource/action that opens the admin panel. Other admin permissions do not grant entry. */
|
|
55
|
+
exports.ADMIN_PAGE_RESOURCE = "admin";
|
|
56
|
+
exports.ADMIN_PAGE_ACTION = "access";
|
|
57
|
+
exports.ADMIN_PAGE_PERMISSION = (_a = {},
|
|
58
|
+
_a[exports.ADMIN_PAGE_RESOURCE] = [exports.ADMIN_PAGE_ACTION],
|
|
59
|
+
_a);
|
|
52
60
|
exports.terrenoStatements = {
|
|
53
|
-
admin: [
|
|
61
|
+
admin: [exports.ADMIN_PAGE_ACTION, "runScripts", "viewBackgroundTasks"],
|
|
62
|
+
adminConsentForm: exports.ADMIN_MODEL_ACCESS,
|
|
63
|
+
adminConsentResponse: exports.ADMIN_MODEL_ACCESS,
|
|
64
|
+
adminFeatureFlag: exports.ADMIN_MODEL_ACCESS,
|
|
54
65
|
configuration: ["read", "update"],
|
|
55
66
|
consentForm: MODEL_CRUD,
|
|
56
67
|
consentResponse: ["list", "read"],
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
10
10
|
"@sentry/bun": "^10.39.0",
|
|
11
11
|
"@sentry/profiling-node": "^10.25.0",
|
|
12
|
-
"@terreno/test": "57.
|
|
12
|
+
"@terreno/test": "57.2.0",
|
|
13
13
|
"@thream/socketio-jwt": "^3.1.4",
|
|
14
14
|
"@types/qs": "^6.14.0",
|
|
15
15
|
"ajv": "8.20.0",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@biomejs/biome": "^2.3.6",
|
|
52
52
|
"@modelcontextprotocol/client": "^2.0.0",
|
|
53
|
-
"@terreno/syncdb": "57.
|
|
53
|
+
"@terreno/syncdb": "57.2.0",
|
|
54
54
|
"@types/bcrypt": "^6.0.0",
|
|
55
|
-
"@types/bun": "^1.
|
|
55
|
+
"@types/bun": "^1.4.0",
|
|
56
56
|
"@types/cors": "^2.8.17",
|
|
57
57
|
"@types/cron": "^2.4.3",
|
|
58
58
|
"@types/express": "^5.0.6",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"updateSnapshot": "bun test --update-snapshots"
|
|
128
128
|
},
|
|
129
129
|
"types": "dist/index.d.ts",
|
|
130
|
-
"version": "57.
|
|
130
|
+
"version": "57.2.0"
|
|
131
131
|
}
|
package/src/adminTypes.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type express from "express";
|
|
2
2
|
import type {Model} from "mongoose";
|
|
3
3
|
|
|
4
|
+
import type {User} from "./auth";
|
|
4
5
|
import type {PermissionMethod, RESTPermissions} from "./permissions";
|
|
5
6
|
import type {PopulatePath} from "./populate";
|
|
6
7
|
import type {ScriptArgDef, ScriptRunner} from "./scriptRunner";
|
|
@@ -78,6 +79,24 @@ export interface AdminModelPermissions {
|
|
|
78
79
|
update?: boolean;
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
export interface AdminAccessContext {
|
|
83
|
+
action: string;
|
|
84
|
+
instance?: unknown;
|
|
85
|
+
user?: User;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface AdminAccessConfig {
|
|
89
|
+
/**
|
|
90
|
+
* RBAC resource for the standard read/write/writeOwned controls. Defaults to
|
|
91
|
+
* `admin<ModelName>` when that statement exists, then the legacy camel-cased model name.
|
|
92
|
+
*/
|
|
93
|
+
resource?: string;
|
|
94
|
+
/** Determines whether the current user owns an instance for writeOwned access. */
|
|
95
|
+
isOwned?: (args: {instance: unknown; user: User}) => boolean | Promise<boolean>;
|
|
96
|
+
/** Completely replaces the standard RBAC decision for this model. */
|
|
97
|
+
authorize?: (args: AdminAccessContext) => boolean | Promise<boolean>;
|
|
98
|
+
}
|
|
99
|
+
|
|
81
100
|
export interface AdminConfig {
|
|
82
101
|
displayName: string;
|
|
83
102
|
group?: string;
|
|
@@ -104,6 +123,8 @@ export interface AdminConfig {
|
|
|
104
123
|
read: PermissionMethod<unknown>[];
|
|
105
124
|
update: PermissionMethod<unknown>[];
|
|
106
125
|
}>;
|
|
126
|
+
/** Fine-grained admin RBAC and optional ownership/custom authorization. */
|
|
127
|
+
adminAccess?: AdminAccessConfig;
|
|
107
128
|
adminFilter?: (
|
|
108
129
|
req: express.Request
|
|
109
130
|
) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
@@ -128,6 +149,8 @@ export interface AdminCustomScreen {
|
|
|
128
149
|
group?: string;
|
|
129
150
|
icon?: string;
|
|
130
151
|
name: string;
|
|
152
|
+
/** RBAC or custom authorization for exposing this screen in admin metadata/navigation. */
|
|
153
|
+
adminAccess?: Pick<AdminAccessConfig, "authorize" | "resource"> & {action?: string};
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
export interface AdminHomeSlots {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
ADMIN_PAGE_PERMISSION,
|
|
4
5
|
expandRolePermissions,
|
|
5
6
|
mergeStatements,
|
|
6
7
|
READ_ACTIONS,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
describe("rbac statements", () => {
|
|
12
13
|
it("exports terreno default vocabulary", () => {
|
|
13
14
|
expect(terrenoStatements.admin).toContain("access");
|
|
15
|
+
expect(ADMIN_PAGE_PERMISSION).toEqual({admin: ["access"]});
|
|
14
16
|
expect(terrenoStatements.rbac).toContain("manageRoles");
|
|
15
17
|
expect(terrenoStatements.user).toContain("read");
|
|
16
18
|
expect(terrenoStatements.configuration).toContain("update");
|
package/src/rbac/statements.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
const MODEL_CRUD = ["create", "list", "read", "update", "delete"] as const;
|
|
2
|
+
export const ADMIN_MODEL_ACCESS = ["read", "write", "writeOwned"] as const;
|
|
3
|
+
|
|
4
|
+
/** Resource/action that opens the admin panel. Other admin permissions do not grant entry. */
|
|
5
|
+
export const ADMIN_PAGE_RESOURCE = "admin" as const;
|
|
6
|
+
export const ADMIN_PAGE_ACTION = "access" as const;
|
|
7
|
+
export const ADMIN_PAGE_PERMISSION = {
|
|
8
|
+
[ADMIN_PAGE_RESOURCE]: [ADMIN_PAGE_ACTION],
|
|
9
|
+
} as const;
|
|
2
10
|
|
|
3
11
|
export const terrenoStatements = {
|
|
4
|
-
admin: [
|
|
12
|
+
admin: [ADMIN_PAGE_ACTION, "runScripts", "viewBackgroundTasks"],
|
|
13
|
+
adminConsentForm: ADMIN_MODEL_ACCESS,
|
|
14
|
+
adminConsentResponse: ADMIN_MODEL_ACCESS,
|
|
15
|
+
adminFeatureFlag: ADMIN_MODEL_ACCESS,
|
|
5
16
|
configuration: ["read", "update"],
|
|
6
17
|
consentForm: MODEL_CRUD,
|
|
7
18
|
consentResponse: ["list", "read"],
|