@openinc/parse-server-opendash 4.39.0 → 4.40.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/features/config/helper/customOptions.js +9 -0
- package/dist/features/openservice/alarms/alarmIdentity.d.ts +2 -0
- package/dist/features/openservice/alarms/alarmIdentity.js +4 -1
- package/dist/features/openservice/alarms/schedule/AlarmScheduleTypes.d.ts +4 -21
- package/dist/hooks/Tenant.js +68 -10
- package/package.json +11 -11
- package/pnpm-workspace.yaml +1 -1
|
@@ -117,6 +117,15 @@ exports.customoptions = {
|
|
|
117
117
|
default: "false",
|
|
118
118
|
description: "If set to true, users must be verified by a tenant admin before they can log in.",
|
|
119
119
|
},
|
|
120
|
+
TENANT_ACCESS_PERMISSION_ENABLE: {
|
|
121
|
+
env: "OPENINC_PARSE_TENANT_ACCESS_PERMISSION_ENABLE",
|
|
122
|
+
type: "boolean",
|
|
123
|
+
required: false,
|
|
124
|
+
secret: false,
|
|
125
|
+
public: false,
|
|
126
|
+
default: "false",
|
|
127
|
+
description: "If set to true, saving a tenant creates an open.WARE AccessPermission that gives the tenant admin role read/write/delete on all data sources whose tag starts with the tenant's tag prefix.",
|
|
128
|
+
},
|
|
120
129
|
AUTH_ALLOW_USERNAME: {
|
|
121
130
|
env: "OPENINC_PARSE_AUTH_ALLOW_USERNAME",
|
|
122
131
|
type: "boolean",
|
|
@@ -21,6 +21,8 @@ export declare function alarmKey(event: AlarmEvent): string | undefined;
|
|
|
21
21
|
* A free-form, greppable string that says where a record came from and can be
|
|
22
22
|
* queried back (`equalTo("origin", …)`) — the same idea as the schedule
|
|
23
23
|
* plugin's `schedule:<id>:<occurrence>`. Stable across firings of one alarm.
|
|
24
|
+
* Spelled by `@opendash/openservice-shared`, whose `isAlarmOrigin` the
|
|
25
|
+
* frontend reads it back with.
|
|
24
26
|
*/
|
|
25
27
|
export declare function alarmOrigin(event: AlarmEvent): string;
|
|
26
28
|
/** When the alarm fired — never when we happened to receive the call. */
|
|
@@ -7,6 +7,7 @@ exports.sensorLabel = sensorLabel;
|
|
|
7
7
|
exports.formatValue = formatValue;
|
|
8
8
|
exports.renderTitleTemplate = renderTitleTemplate;
|
|
9
9
|
exports.alarmDetailLines = alarmDetailLines;
|
|
10
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
10
11
|
/**
|
|
11
12
|
* Identity and text rendering for a fired alarm — pure, so the `origin` marker
|
|
12
13
|
* and the wording can be checked without a database.
|
|
@@ -38,9 +39,11 @@ function alarmKey(event) {
|
|
|
38
39
|
* A free-form, greppable string that says where a record came from and can be
|
|
39
40
|
* queried back (`equalTo("origin", …)`) — the same idea as the schedule
|
|
40
41
|
* plugin's `schedule:<id>:<occurrence>`. Stable across firings of one alarm.
|
|
42
|
+
* Spelled by `@opendash/openservice-shared`, whose `isAlarmOrigin` the
|
|
43
|
+
* frontend reads it back with.
|
|
41
44
|
*/
|
|
42
45
|
function alarmOrigin(event) {
|
|
43
|
-
return
|
|
46
|
+
return (0, openservice_shared_1.alarmOrigin)(String(alarmKey(event)));
|
|
44
47
|
}
|
|
45
48
|
/** When the alarm fired — never when we happened to receive the call. */
|
|
46
49
|
function firedAt(event) {
|
|
@@ -65,26 +65,9 @@ export interface AlarmScheduleParams {
|
|
|
65
65
|
/**
|
|
66
66
|
* The alarm that produced a plan, recorded on `Schedule.asset.alarm`.
|
|
67
67
|
*
|
|
68
|
-
* A plan has no
|
|
68
|
+
* A plan has no room for the firing in its title, so the context would
|
|
69
69
|
* otherwise be lost between the title and the `origin` marker. Structured
|
|
70
|
-
* rather than prose because the trigger overview reads it back. The
|
|
71
|
-
*
|
|
72
|
-
* with `alarmOrigin` / `isAlarmOrigin`); this copy has to match it until the
|
|
73
|
-
* server depends on a release of that package which contains it.
|
|
70
|
+
* rather than prose because the trigger overview reads it back. The shape
|
|
71
|
+
* lives in `@opendash/openservice-shared`, where the frontend reads it too.
|
|
74
72
|
*/
|
|
75
|
-
export
|
|
76
|
-
/** `OD3_Alarm.objectId`, when the executor reported one. */
|
|
77
|
-
alarmId?: string;
|
|
78
|
-
/** The alarm's name at the time it fired. */
|
|
79
|
-
name?: string;
|
|
80
|
-
/** `source/id [dimension]` — the sensor, as shown to a human. */
|
|
81
|
-
sensor?: string;
|
|
82
|
-
/** The value that broke the rule. */
|
|
83
|
-
value?: number | string | boolean;
|
|
84
|
-
/** Human-readable rule, e.g. `> 80`. */
|
|
85
|
-
condition?: string;
|
|
86
|
-
/** ISO timestamp of the firing. */
|
|
87
|
-
firedAt: string;
|
|
88
|
-
/** Which action row created the plan. */
|
|
89
|
-
actionId: string;
|
|
90
|
-
}
|
|
73
|
+
export type { ScheduleAlarmContext } from "@opendash/openservice-shared";
|
package/dist/hooks/Tenant.js
CHANGED
|
@@ -5,14 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const index_js_1 = require("../features/
|
|
8
|
+
const index_js_1 = require("../features/config/index.js");
|
|
9
|
+
const index_js_2 = require("../features/schema/index.js");
|
|
9
10
|
const openinc_rmq_create_tenant_js_1 = require("../functions/openinc-rmq-create-tenant.js");
|
|
10
|
-
const
|
|
11
|
+
const index_js_3 = require("../types/index.js");
|
|
11
12
|
async function init() {
|
|
12
|
-
(0,
|
|
13
|
+
(0, index_js_2.beforeSaveHook)(index_js_3.Tenant, async (request) => {
|
|
13
14
|
const { object, original, user } = request;
|
|
14
|
-
await (0,
|
|
15
|
-
await (0,
|
|
15
|
+
await (0, index_js_2.defaultHandler)(request);
|
|
16
|
+
await (0, index_js_2.immutableField)(request, "tagPrefix", "opendash:tenant:change-tag-prefix");
|
|
16
17
|
if (object.id) {
|
|
17
18
|
object.setACL(new node_1.default.ACL({
|
|
18
19
|
[`role:od-tenant-user-${object.id}`]: {
|
|
@@ -34,10 +35,10 @@ async function init() {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
|
-
(0,
|
|
38
|
+
(0, index_js_2.afterSaveHook)(index_js_3.Tenant, async ({ object, original, user }) => {
|
|
38
39
|
// Handle Data Source
|
|
39
40
|
if (object.id && !original?.get("dataSource")) {
|
|
40
|
-
const rootSource = await new node_1.default.Query(
|
|
41
|
+
const rootSource = await new node_1.default.Query(index_js_3.Source)
|
|
41
42
|
.equalTo("tag", "tenant-root-source")
|
|
42
43
|
.first({ useMasterKey: true });
|
|
43
44
|
const sourceACL = new node_1.default.ACL({
|
|
@@ -47,7 +48,7 @@ async function init() {
|
|
|
47
48
|
});
|
|
48
49
|
let dataSource = object.get("dataSource");
|
|
49
50
|
if (!dataSource) {
|
|
50
|
-
dataSource = new
|
|
51
|
+
dataSource = new index_js_3.Source();
|
|
51
52
|
}
|
|
52
53
|
dataSource.setACL(sourceACL);
|
|
53
54
|
if (rootSource) {
|
|
@@ -60,10 +61,10 @@ async function init() {
|
|
|
60
61
|
object.set("dataSource", dataSource);
|
|
61
62
|
await object.save(null, { useMasterKey: true });
|
|
62
63
|
}
|
|
63
|
-
await (0,
|
|
64
|
+
await (0, index_js_2.ensureRole)(`od-tenant-admin-${object.id}`, {
|
|
64
65
|
label: `${object.get("label")} (Admin)`,
|
|
65
66
|
});
|
|
66
|
-
await (0,
|
|
67
|
+
await (0, index_js_2.ensureRole)(`od-tenant-user-${object.id}`, {
|
|
67
68
|
label: object.get("label"),
|
|
68
69
|
acl: new node_1.default.ACL({
|
|
69
70
|
[`role:od-tenant-user-${object.id}`]: {
|
|
@@ -71,6 +72,10 @@ async function init() {
|
|
|
71
72
|
},
|
|
72
73
|
}),
|
|
73
74
|
});
|
|
75
|
+
if (object.id &&
|
|
76
|
+
index_js_1.ConfigInstance.getInstance().getBoolean("TENANT_ACCESS_PERMISSION_ENABLE")) {
|
|
77
|
+
await ensureTenantAccessPermission(object);
|
|
78
|
+
}
|
|
74
79
|
if (!original && object.id && process.env.OPENINC_PARSE_CLOUD_RMQ_HOST) {
|
|
75
80
|
try {
|
|
76
81
|
await (0, openinc_rmq_create_tenant_js_1.createRabbitMQTenant)(object.id);
|
|
@@ -87,4 +92,57 @@ async function init() {
|
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
});
|
|
95
|
+
(0, index_js_2.beforeDeleteHook)(index_js_3.Tenant, async ({ object }) => {
|
|
96
|
+
try {
|
|
97
|
+
const permissions = await new node_1.default.Query(ACCESS_PERMISSIONS)
|
|
98
|
+
.equalTo("tenant", object)
|
|
99
|
+
.find({ useMasterKey: true });
|
|
100
|
+
await node_1.default.Object.destroyAll(permissions, { useMasterKey: true });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`[@openinc/parse-server-opendash][Tenant] Could not delete open.WARE AccessPermissions of tenant ${object.id}:`, error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** open.WARE class, not an OD3_* class — there is no generated type for it. */
|
|
108
|
+
const ACCESS_PERMISSIONS = "AccessPermissions";
|
|
109
|
+
function escapeRegex(value) {
|
|
110
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Keeps one open.WARE `AccessPermissions` row per tenant that gives the tenant
|
|
114
|
+
* admin role read/write/delete on every data source whose tag starts with the
|
|
115
|
+
* tenant's tag prefix (`ownerGroup: true`, `owner` is a regex).
|
|
116
|
+
*
|
|
117
|
+
* The row is found again by its `tenant` pointer, so repeated saves update it
|
|
118
|
+
* instead of adding a new one — e.g. when the tag prefix is set after creation.
|
|
119
|
+
* Visible to od-admin (read/write); the tenant admin role reads it, which is
|
|
120
|
+
* what grants the access in open.WARE.
|
|
121
|
+
*/
|
|
122
|
+
async function ensureTenantAccessPermission(tenant) {
|
|
123
|
+
try {
|
|
124
|
+
const prefix = tenant.get("tagPrefix") || `tenant-${tenant.id}-`;
|
|
125
|
+
const permission = (await new node_1.default.Query(ACCESS_PERMISSIONS)
|
|
126
|
+
.equalTo("tenant", tenant)
|
|
127
|
+
.first({ useMasterKey: true })) ?? new node_1.default.Object(ACCESS_PERMISSIONS);
|
|
128
|
+
permission.set("tenant", tenant);
|
|
129
|
+
permission.set("owner", `^${escapeRegex(prefix)}.*`);
|
|
130
|
+
permission.set("ownerGroup", true);
|
|
131
|
+
permission.set("read", ".*");
|
|
132
|
+
permission.set("write", ".*");
|
|
133
|
+
permission.set("delete", ".*");
|
|
134
|
+
permission.setACL(new node_1.default.ACL({
|
|
135
|
+
[`role:od-tenant-admin-${tenant.id}`]: {
|
|
136
|
+
read: true,
|
|
137
|
+
},
|
|
138
|
+
[`role:od-admin`]: {
|
|
139
|
+
read: true,
|
|
140
|
+
write: true,
|
|
141
|
+
},
|
|
142
|
+
}));
|
|
143
|
+
await permission.save(null, { useMasterKey: true });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`[@openinc/parse-server-opendash][Tenant] open.WARE AccessPermissions for tenant ${tenant.id} were not saved:`, error);
|
|
147
|
+
}
|
|
90
148
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openinc/parse-server-opendash",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "Parse Server Cloud Code for open.INC Stack.",
|
|
5
|
-
"packageManager": "pnpm@12.
|
|
5
|
+
"packageManager": "pnpm@12.21.0",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"parse",
|
|
8
8
|
"opendash"
|
|
@@ -75,26 +75,26 @@
|
|
|
75
75
|
"seed:v1": "node dist/scripts/seed-v1-testdata.js"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@opendash/openservice-shared": "0.2.0-nightly.
|
|
78
|
+
"@opendash/openservice-shared": "0.2.0-nightly.7",
|
|
79
79
|
"@opendash/ruleset-core": "nightly",
|
|
80
80
|
"@opendash/schedule": "1.2.0-nightly.24",
|
|
81
81
|
"@openinc/parse-server-schema": "^4.1.8",
|
|
82
82
|
"amqplib": "^0.10.9",
|
|
83
83
|
"cron": "^4.4.0",
|
|
84
84
|
"dayjs": "^1.11.23",
|
|
85
|
-
"dotenv": "^18.0.
|
|
86
|
-
"fast-equals": "^6.
|
|
87
|
-
"i18next": "^26.7.
|
|
88
|
-
"i18next-fs-backend": "^2.
|
|
85
|
+
"dotenv": "^18.0.10",
|
|
86
|
+
"fast-equals": "^6.4.0",
|
|
87
|
+
"i18next": "^26.7.2",
|
|
88
|
+
"i18next-fs-backend": "^2.7.0",
|
|
89
89
|
"jsonwebtoken": "^9.0.3",
|
|
90
90
|
"jwks-rsa": "^4.1.0",
|
|
91
|
-
"nodemailer": "^10.
|
|
91
|
+
"nodemailer": "^10.6.0",
|
|
92
92
|
"nunjucks": "^3.2.4",
|
|
93
93
|
"parse": "8.6.2",
|
|
94
94
|
"parse-server": "9.10.7",
|
|
95
95
|
"pdf-img-convert": "2.0.0",
|
|
96
96
|
"rimraf": "^6.1.4",
|
|
97
|
-
"table": "^6.
|
|
97
|
+
"table": "^6.10.1",
|
|
98
98
|
"web-push": "^3.6.7",
|
|
99
99
|
"winston": "^3.19.0"
|
|
100
100
|
},
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"@types/nunjucks": "^3.2.6",
|
|
106
106
|
"@types/safe-timers": "^1.1.2",
|
|
107
107
|
"@types/web-push": "^3.6.4",
|
|
108
|
-
"concurrently": "^10.0.
|
|
109
|
-
"prettier": "^3.
|
|
108
|
+
"concurrently": "^10.0.7",
|
|
109
|
+
"prettier": "^3.10.1",
|
|
110
110
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
111
111
|
"ts-node": "^10.9.2",
|
|
112
112
|
"typedoc": "^0.28.20",
|