@7365admin1/core 3.102.2 → 3.106.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/CHANGELOG.md +24 -0
- package/dist/index.d.ts +461 -31
- package/dist/index.js +8170 -6388
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5574 -3829
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/e2e/harness.mjs +24 -3
- package/test/e2e/invite-role-site-scope.e2e.test.mjs +117 -0
- package/test/e2e/notification-email.e2e.test.mjs +331 -0
- package/test/e2e/notification-matrix.e2e.test.mjs +5 -9
- package/test/e2e/notification-preference.e2e.test.mjs +3 -9
- package/test/e2e/robot-creds-rmf-floorplans.e2e.test.mjs +387 -0
- package/test/e2e/safety-notification.e2e.test.mjs +5 -8
- package/test/e2e/site-edit-owner-only.e2e.test.mjs +215 -0
- package/test/invite-org-scope.test.mjs +1 -1
- package/test/invite-role-scope.test.mjs +85 -16
- package/test/member-staff-gate.test.mjs +1 -1
- package/test/notification-category.util.test.mjs +12 -19
- package/test/notification-email.util.test.mjs +140 -0
- package/test/resident-app-modules.test.mjs +1 -1
- package/test/rmf-building.test.mjs +220 -0
- package/test/robot-credentials.test.mjs +110 -0
- package/test/site-owner-edit.test.mjs +52 -0
- package/test/staff-platform-notifications.test.mjs +2 -2
|
@@ -75,6 +75,68 @@ test("an ObjectId-shaped org is compared by value, not by identity", () => {
|
|
|
75
75
|
);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// REFUSED since 2026-09-25 — the Invite member dropdown's wrong options
|
|
80
|
+
// (owner report: Wing Tai / Winsland House I listed "Org Owner", "Org - Admin
|
|
81
|
+
// Doan623"...). Each was accepted before this change.
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
const SITE_B = "6a7bd4c3d62595d5b572a2a5";
|
|
85
|
+
|
|
86
|
+
test("an org-less TEMPLATE role is refused on an invitation that names an organisation", () => {
|
|
87
|
+
for (const role of [{ type: "organization", org: "" }, { type: "organization" }]) {
|
|
88
|
+
assert.equal(
|
|
89
|
+
roleInvitable(role, CLIENT_A, ["property_management_agency"], SITE_A),
|
|
90
|
+
"That role is a shared template, not one of this organisation's roles.",
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("a deleted role is refused", () => {
|
|
96
|
+
assert.equal(
|
|
97
|
+
roleInvitable(
|
|
98
|
+
{ type: "property_management_agency", org: CLIENT_A, status: "deleted" },
|
|
99
|
+
CLIENT_A,
|
|
100
|
+
["property_management_agency"],
|
|
101
|
+
),
|
|
102
|
+
"That role has been deleted.",
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("another application's role is refused", () => {
|
|
107
|
+
assert.equal(
|
|
108
|
+
roleInvitable(
|
|
109
|
+
{ type: "cleaning_services", org: CLIENT_A },
|
|
110
|
+
CLIENT_A,
|
|
111
|
+
["property_management_agency"],
|
|
112
|
+
),
|
|
113
|
+
"That role belongs to a different application.",
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a role pinned to another site is refused, and so is a site role on an org-wide invite", () => {
|
|
118
|
+
const role = { type: "property_management_agency", org: CLIENT_A, site: SITE_A };
|
|
119
|
+
for (const site of [SITE_B, "", null, undefined]) {
|
|
120
|
+
assert.equal(
|
|
121
|
+
roleInvitable(role, CLIENT_A, ["property_management_agency"], site),
|
|
122
|
+
"That role belongs to a different site.",
|
|
123
|
+
`site=${site}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("CONTROL: the same role on its own site is allowed", () => {
|
|
129
|
+
assert.equal(
|
|
130
|
+
roleInvitable(
|
|
131
|
+
{ type: "property_management_agency", org: CLIENT_A, site: SITE_A },
|
|
132
|
+
CLIENT_A,
|
|
133
|
+
["property_management_agency"],
|
|
134
|
+
SITE_A,
|
|
135
|
+
),
|
|
136
|
+
null,
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
78
140
|
// ---------------------------------------------------------------------------
|
|
79
141
|
// ALLOWED — the zero-lockout proof. Every legitimate shape that reaches the
|
|
80
142
|
// invitation endpoints today, and still must.
|
|
@@ -82,16 +144,29 @@ test("an ObjectId-shaped org is compared by value, not by identity", () => {
|
|
|
82
144
|
|
|
83
145
|
const LEGITIMATE = [
|
|
84
146
|
[
|
|
85
|
-
"
|
|
147
|
+
"Invite Client with a TEMPLATE role names no organisation (~340 live rows)",
|
|
86
148
|
{ type: "organization", org: "" },
|
|
149
|
+
"",
|
|
150
|
+
["property_management_agency"],
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"the org-wide 'organization' role on a property-management invite (onboarding Invite Member)",
|
|
154
|
+
{ type: "organization", org: CLIENT_A, site: "" },
|
|
87
155
|
CLIENT_A,
|
|
88
156
|
["property_management_agency"],
|
|
89
157
|
],
|
|
90
158
|
[
|
|
91
|
-
"
|
|
92
|
-
{ type: "
|
|
159
|
+
"a SITE-PINNED role invited into THAT site",
|
|
160
|
+
{ type: "security_agency", org: CLIENT_A, site: SITE_A, status: "active" },
|
|
93
161
|
CLIENT_A,
|
|
94
162
|
["security_agency"],
|
|
163
|
+
SITE_A,
|
|
164
|
+
],
|
|
165
|
+
[
|
|
166
|
+
"real_estate_developer role on a property-management invite (type alias)",
|
|
167
|
+
{ type: "real_estate_developer", org: CLIENT_A },
|
|
168
|
+
CLIENT_A,
|
|
169
|
+
["property_management_agency"],
|
|
95
170
|
],
|
|
96
171
|
[
|
|
97
172
|
"org admin invites a member with the organisation OWN role (the majority)",
|
|
@@ -111,12 +186,6 @@ const LEGITIMATE = [
|
|
|
111
186
|
CLIENT_A,
|
|
112
187
|
["property_management_agency"],
|
|
113
188
|
],
|
|
114
|
-
[
|
|
115
|
-
"a SITE-PINNED role invited into another site of the SAME org (36 live rows)",
|
|
116
|
-
{ type: "property_management_agency", org: CLIENT_A, site: SITE_A },
|
|
117
|
-
CLIENT_A,
|
|
118
|
-
["property_management_agency"],
|
|
119
|
-
],
|
|
120
189
|
[
|
|
121
190
|
"an invitation that names no organisation at all (2 live rows)",
|
|
122
191
|
{ type: "property_management_agency", org: CLIENT_A },
|
|
@@ -155,10 +224,10 @@ const LEGITIMATE = [
|
|
|
155
224
|
],
|
|
156
225
|
];
|
|
157
226
|
|
|
158
|
-
for (const [name, role, org, apps] of LEGITIMATE) {
|
|
227
|
+
for (const [name, role, org, apps, site] of LEGITIMATE) {
|
|
159
228
|
test(`ALLOWED: ${name}`, () => {
|
|
160
229
|
assert.equal(
|
|
161
|
-
roleInvitable(role, org, apps),
|
|
230
|
+
roleInvitable(role, org, apps, site),
|
|
162
231
|
null,
|
|
163
232
|
"this invitation works today and must keep working",
|
|
164
233
|
);
|
|
@@ -178,7 +247,7 @@ test("requireInviteReach runs the role check, and runs it last", () => {
|
|
|
178
247
|
|
|
179
248
|
assert.match(
|
|
180
249
|
authz,
|
|
181
|
-
/const refusal = roleInvitable\(stored, org, apps\);\n\s*if \(refusal\) throw new BadRequestError\(refusal\);/,
|
|
250
|
+
/const refusal = roleInvitable\(stored, org, apps, site\);\n\s*if \(refusal\) throw new BadRequestError\(refusal\);/,
|
|
182
251
|
"the refusal must be raised as a 4xx, not swallowed",
|
|
183
252
|
);
|
|
184
253
|
|
|
@@ -187,7 +256,7 @@ test("requireInviteReach runs the role check, and runs it last", () => {
|
|
|
187
256
|
|
|
188
257
|
assert.match(
|
|
189
258
|
body,
|
|
190
|
-
/await requireRoleInvitable\(role, org, apps\);/,
|
|
259
|
+
/await requireRoleInvitable\(role, org, apps, site\);/,
|
|
191
260
|
"requireInviteReach must run the role check",
|
|
192
261
|
);
|
|
193
262
|
|
|
@@ -207,7 +276,7 @@ test("the role is only ever read from the STORED role, never from the request",
|
|
|
207
276
|
);
|
|
208
277
|
|
|
209
278
|
assert.match(body, /collection\("roles"\)/);
|
|
210
|
-
assert.match(body, /projection: \{ org: 1, type: 1 \}/);
|
|
279
|
+
assert.match(body, /projection: \{ org: 1, type: 1, site: 1, status: 1 \}/);
|
|
211
280
|
assert.doesNotMatch(
|
|
212
281
|
body,
|
|
213
282
|
/req\.body|req\.query/,
|
|
@@ -229,8 +298,8 @@ test("every invite handler hands its role to the gate", () => {
|
|
|
229
298
|
for (const call of calls) {
|
|
230
299
|
assert.match(
|
|
231
300
|
call,
|
|
232
|
-
/, role\)$/,
|
|
233
|
-
`${call} must pass the role it is about to write`,
|
|
301
|
+
/, role, siteId\)$/,
|
|
302
|
+
`${call} must pass the role and the site it is about to write`,
|
|
234
303
|
);
|
|
235
304
|
}
|
|
236
305
|
});
|
|
@@ -121,7 +121,7 @@ test("createUserInvite refuses a staff invitation from a non-staff caller", () =
|
|
|
121
121
|
// yourself as staff, then accept your own invitation.
|
|
122
122
|
const body = fn(verificationController, "createUserInvite");
|
|
123
123
|
|
|
124
|
-
assert.match(body, /await requireInviteReach\(req, org, app, role\)/);
|
|
124
|
+
assert.match(body, /await requireInviteReach\(req, org, app, role, siteId\)/);
|
|
125
125
|
|
|
126
126
|
const gate = body.indexOf("requireInviteReach");
|
|
127
127
|
const write = body.indexOf("_createUserInvite(");
|
|
@@ -164,12 +164,12 @@ describe("notification categories", () => {
|
|
|
164
164
|
assert.deepEqual(categoriesForPermissions({}), []);
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
it("
|
|
168
|
-
const
|
|
169
|
-
(c) => c.channels.email,
|
|
167
|
+
it("every rendered category offers email (owner request 2026-09-25; opt-in, verified-only)", () => {
|
|
168
|
+
const noEmail = NOTIFICATION_CATEGORIES.filter(
|
|
169
|
+
(c) => c.rendered && !c.channels.email,
|
|
170
170
|
).map((c) => c.key);
|
|
171
171
|
|
|
172
|
-
assert.deepEqual(
|
|
172
|
+
assert.deepEqual(noEmail, []);
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
it("every channel a category cannot use explains itself in plain words", () => {
|
|
@@ -199,8 +199,8 @@ describe("notification categories", () => {
|
|
|
199
199
|
|
|
200
200
|
it("channel support is a fact about the category, not a preference", () => {
|
|
201
201
|
assert.equal(categorySupportsChannel("workOrder", "push"), true);
|
|
202
|
-
assert.equal(categorySupportsChannel("workOrder", "email"),
|
|
203
|
-
assert.equal(categorySupportsChannel("serviceProviderInvite", "email"),
|
|
202
|
+
assert.equal(categorySupportsChannel("workOrder", "email"), true);
|
|
203
|
+
assert.equal(categorySupportsChannel("serviceProviderInvite", "email"), true);
|
|
204
204
|
assert.equal(categorySupportsChannel("not-a-module", "push"), false);
|
|
205
205
|
});
|
|
206
206
|
|
|
@@ -210,19 +210,12 @@ describe("notification categories", () => {
|
|
|
210
210
|
// `email: true`, and `emergencyContact` was offered with no sender at all.
|
|
211
211
|
// -------------------------------------------------------------------------
|
|
212
212
|
|
|
213
|
-
it("no
|
|
214
|
-
// `
|
|
215
|
-
//
|
|
213
|
+
it("Email no longer carries an apology: it is a real, opt-in switch", () => {
|
|
214
|
+
// `notification-email.service.ts` reads `emailOn` + a verified address, so
|
|
215
|
+
// the switch governs real mail. Opt-in is enforced there, not here.
|
|
216
216
|
for (const category of NOTIFICATION_CATEGORIES) {
|
|
217
|
-
assert.equal(
|
|
218
|
-
|
|
219
|
-
false,
|
|
220
|
-
`${category.key} offers a live Email switch that no sender consults`,
|
|
221
|
-
);
|
|
222
|
-
assert.ok(
|
|
223
|
-
category.channelNote?.email,
|
|
224
|
-
`${category.key} dims Email without saying why`,
|
|
225
|
-
);
|
|
217
|
+
assert.equal(category.channels.email, true, category.key);
|
|
218
|
+
assert.equal(category.channelNote?.email, undefined, category.key);
|
|
226
219
|
}
|
|
227
220
|
});
|
|
228
221
|
|
|
@@ -498,7 +491,7 @@ describe("existing categories are untouched by the marketplace addition", () =>
|
|
|
498
491
|
for (const category of NOTIFICATION_CATEGORIES) {
|
|
499
492
|
if (NEW_KEYS.includes(category.key)) continue;
|
|
500
493
|
|
|
501
|
-
assert.equal(category.channels.email,
|
|
494
|
+
assert.equal(category.channels.email, true, category.key);
|
|
502
495
|
assert.equal(category.channels.inApp, true, category.key);
|
|
503
496
|
assert.equal(category.channels.push, true, category.key);
|
|
504
497
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Notification emails — the pure rules: who may be emailed, the one-click
|
|
2
|
+
// turn-off token, the verification code, and what the email says.
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_EMAIL_ALLOWLIST,
|
|
8
|
+
EMAIL_PER_MODULE_PER_HOUR,
|
|
9
|
+
codeMatches,
|
|
10
|
+
emailOpenToEveryone,
|
|
11
|
+
escapeHtml,
|
|
12
|
+
hashCode,
|
|
13
|
+
isEmailAllowed,
|
|
14
|
+
newCode,
|
|
15
|
+
notificationEmail,
|
|
16
|
+
offLink,
|
|
17
|
+
offPage,
|
|
18
|
+
offToken,
|
|
19
|
+
offTokenMatches,
|
|
20
|
+
openLink,
|
|
21
|
+
verificationEmail,
|
|
22
|
+
} from "./.build/utils/notification-email.util.mjs";
|
|
23
|
+
|
|
24
|
+
const U = "65f1a2b3c4d5e6f708192a3b";
|
|
25
|
+
const SECRET = "a".repeat(64);
|
|
26
|
+
|
|
27
|
+
describe("allow-list (staging shares the production mailer)", () => {
|
|
28
|
+
it("fails closed: unset means only Seven365's own domain", () => {
|
|
29
|
+
assert.equal(DEFAULT_EMAIL_ALLOWLIST, "*@seven365.com.sg");
|
|
30
|
+
assert.equal(isEmailAllowed("security@seven365.com.sg", undefined), true);
|
|
31
|
+
assert.equal(isEmailAllowed("Harris@Seven365.com.sg", ""), true);
|
|
32
|
+
assert.equal(isEmailAllowed("someone@gmail.com", undefined), false);
|
|
33
|
+
assert.equal(isEmailAllowed("x@evil-seven365.com.sg", undefined), false);
|
|
34
|
+
assert.equal(isEmailAllowed("x@seven365.com.sg.evil.com", undefined), false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("an explicit list replaces the default", () => {
|
|
38
|
+
const list = "*@example.org, qa@test.io @other.net";
|
|
39
|
+
assert.equal(isEmailAllowed("a@example.org", list), true);
|
|
40
|
+
assert.equal(isEmailAllowed("qa@test.io", list), true);
|
|
41
|
+
assert.equal(isEmailAllowed("b@test.io", list), false);
|
|
42
|
+
assert.equal(isEmailAllowed("c@other.net", list), true);
|
|
43
|
+
assert.equal(isEmailAllowed("security@seven365.com.sg", list), false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("only '*' opens it to everyone", () => {
|
|
47
|
+
assert.equal(isEmailAllowed("anyone@gmail.com", "*"), true);
|
|
48
|
+
assert.equal(emailOpenToEveryone("*"), true);
|
|
49
|
+
assert.equal(emailOpenToEveryone(undefined), false);
|
|
50
|
+
assert.equal(emailOpenToEveryone("*@seven365.com.sg"), false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("garbage is never allowed", () => {
|
|
54
|
+
for (const bad of ["", null, undefined, "no-at-sign", 42]) {
|
|
55
|
+
assert.equal(isEmailAllowed(bad, "*"), false, String(bad));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("turn-off token (no sign-in, tamper-proof)", () => {
|
|
61
|
+
const t = offToken(U, "feedback", SECRET);
|
|
62
|
+
|
|
63
|
+
it("matches only the same person, module and secret", () => {
|
|
64
|
+
assert.equal(offTokenMatches(U, "feedback", t, SECRET), true);
|
|
65
|
+
assert.equal(offTokenMatches(U, "workOrder", t, SECRET), false, "re-aimed at another module");
|
|
66
|
+
assert.equal(offTokenMatches("65f1a2b3c4d5e6f708192a3c", "feedback", t, SECRET), false, "another person");
|
|
67
|
+
assert.equal(offTokenMatches(U, "feedback", t, "b".repeat(64)), false, "another secret");
|
|
68
|
+
assert.equal(offTokenMatches(U, "feedback", t.slice(0, -1) + (t.endsWith("A") ? "B" : "A"), SECRET), false);
|
|
69
|
+
assert.equal(offTokenMatches(U, "feedback", t, undefined), false, "no secret stored");
|
|
70
|
+
assert.equal(offTokenMatches(U, "feedback", "", SECRET), false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("the link carries person, module and token", () => {
|
|
74
|
+
const url = new URL(offLink("https://account.example", U, "feedback", SECRET));
|
|
75
|
+
assert.equal(url.pathname, "/api/notification-preferences/email/off");
|
|
76
|
+
assert.equal(url.searchParams.get("u"), U);
|
|
77
|
+
assert.equal(url.searchParams.get("c"), "feedback");
|
|
78
|
+
assert.equal(url.searchParams.get("t"), t);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("verification code", () => {
|
|
83
|
+
it("is six digits and only its hash, bound to the person, is compared", () => {
|
|
84
|
+
for (let i = 0; i < 50; i++) assert.match(newCode(), /^\d{6}$/);
|
|
85
|
+
const h = hashCode(U, "123456");
|
|
86
|
+
assert.equal(codeMatches(U, "123456", h), true);
|
|
87
|
+
assert.equal(codeMatches(U, " 123456 ", h), true);
|
|
88
|
+
assert.equal(codeMatches(U, "123457", h), false);
|
|
89
|
+
assert.equal(codeMatches("65f1a2b3c4d5e6f708192a3c", "123456", h), false);
|
|
90
|
+
assert.equal(codeMatches(U, "123456", ""), false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("the email says what to do in plain words", () => {
|
|
94
|
+
const m = verificationEmail("042917");
|
|
95
|
+
assert.match(m.subject, /email code/i);
|
|
96
|
+
assert.match(m.html, /042917/);
|
|
97
|
+
assert.match(m.text, /ignore this email/);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("the notification email", () => {
|
|
102
|
+
const base = {
|
|
103
|
+
title: "Work order <updated>",
|
|
104
|
+
body: 'Status is now "Done" & closed',
|
|
105
|
+
moduleLabel: "Work Orders",
|
|
106
|
+
openUrl: openLink("https://acc", { kind: "workOrder", id: "abc", site: "s1", org: "o1" }),
|
|
107
|
+
offUrl: "https://acc/api/notification-preferences/email/off?u=1&c=workOrder&t=x",
|
|
108
|
+
settingsUrl: "https://acc/notification-settings",
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
it("has the button, why, one-click turn-off and settings", () => {
|
|
112
|
+
const m = notificationEmail(base);
|
|
113
|
+
assert.equal(m.subject, base.title);
|
|
114
|
+
assert.match(m.html, /Open in iService365/);
|
|
115
|
+
assert.match(m.html, /Why am I getting this\?/);
|
|
116
|
+
assert.match(m.html, /Turn off email for Work Orders/);
|
|
117
|
+
assert.match(m.html, /Notification settings/);
|
|
118
|
+
assert.match(m.text, /notifications\/open\?kind=workOrder&id=abc&site=s1&org=o1/);
|
|
119
|
+
assert.doesNotMatch(m.html, /hold|for up to an hour/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("escapes what a user typed", () => {
|
|
123
|
+
const m = notificationEmail(base);
|
|
124
|
+
assert.doesNotMatch(m.html, /<updated>/);
|
|
125
|
+
assert.match(m.html, /<updated>/);
|
|
126
|
+
assert.match(m.html, /"Done" & closed/);
|
|
127
|
+
assert.equal(escapeHtml(`<a href="x">'`), "<a href="x">'");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("the last one this hour says the rest are held", () => {
|
|
131
|
+
const m = notificationEmail({ ...base, lastThisHour: true });
|
|
132
|
+
assert.match(m.text, new RegExp(`${EMAIL_PER_MODULE_PER_HOUR} Work Orders emails in the last hour`));
|
|
133
|
+
assert.match(m.text, /still arrives in the app/);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("the turn-off page is plain", () => {
|
|
137
|
+
assert.match(offPage(true, "Feedback", "https://acc/notification-settings"), /Email for Feedback is off/);
|
|
138
|
+
assert.match(offPage(false, "Other", "x"), /This link does not work/);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -202,7 +202,7 @@ test("the site read returns the EFFECTIVE set as a second field", () => {
|
|
|
202
202
|
* indistinguishable from a failed save.
|
|
203
203
|
*/
|
|
204
204
|
assert.match(SITE_CONTROLLER, /residentAppModulesEffective: effectiveResidentAppModules\(/);
|
|
205
|
-
assert.match(SITE_CONTROLLER, /res\.json\(await withResidentAppCeiling\(site
|
|
205
|
+
assert.match(SITE_CONTROLLER, /res\.json\(await withResidentAppCeiling\(site(, detailsEditable)?\)\)/);
|
|
206
206
|
// CONTROL: the saved field is still returned untouched alongside it.
|
|
207
207
|
assert.match(SITE_CONTROLLER, /\.\.\.\(site\.metadata \?\? \{\}\)/);
|
|
208
208
|
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_PLAN_FRAME,
|
|
6
|
+
fromPlan,
|
|
7
|
+
legacyFromRmf,
|
|
8
|
+
mergeLegacyIntoRmf,
|
|
9
|
+
rmfFromFleetCore,
|
|
10
|
+
rmfProblem,
|
|
11
|
+
rmfSummary,
|
|
12
|
+
toBuildingYaml,
|
|
13
|
+
toNavGraphs,
|
|
14
|
+
toPlan,
|
|
15
|
+
} from "./.build/utils/rmf-building.util.mjs";
|
|
16
|
+
import { rmfBuildingSchema, buildingMapBodySchema } from "./.build/models/robot-building-map.model.mjs";
|
|
17
|
+
|
|
18
|
+
// A BuildingMap.msg as the fleet server returns it: two levels, walls, a hinged
|
|
19
|
+
// and a double-sliding door, one nav graph with a charger and a bidirectional +
|
|
20
|
+
// a one-way lane (speed limit, mutex), and a lift with one cabin door.
|
|
21
|
+
const MSG = {
|
|
22
|
+
name: "tower",
|
|
23
|
+
levels: [
|
|
24
|
+
{
|
|
25
|
+
name: "L1",
|
|
26
|
+
elevation: 0,
|
|
27
|
+
doors: [
|
|
28
|
+
{ name: "main", v1_x: 4, v1_y: -1, v2_x: 6, v2_y: -1, door_type: 6, motion_range: Math.PI / 2, motion_direction: -1 },
|
|
29
|
+
{ name: "slide", v1_x: 10, v1_y: -5, v2_x: 10, v2_y: -7, door_type: 2 },
|
|
30
|
+
],
|
|
31
|
+
nav_graphs: [
|
|
32
|
+
{
|
|
33
|
+
name: "0",
|
|
34
|
+
vertices: [
|
|
35
|
+
{ x: 5, y: 0, name: "entry", params: [{ name: "is_holding_point" }] },
|
|
36
|
+
{ x: 5, y: -4, name: "hall", params: [] },
|
|
37
|
+
{ x: 12, y: -4, name: "dock", params: [{ name: "is_charger", type: 4, value_bool: true }, { name: "dock_name", type: 1, value_string: "dock1" }] },
|
|
38
|
+
],
|
|
39
|
+
edges: [
|
|
40
|
+
{ v1_idx: 0, v2_idx: 1, edge_type: 0, params: [] },
|
|
41
|
+
{ v1_idx: 1, v2_idx: 2, edge_type: 1, params: [{ name: "speed_limit", type: 3, value_float: 0.5 }, { name: "mutex", type: 1, value_string: "corridor" }] },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
wall_graph: {
|
|
46
|
+
name: "WallGraph",
|
|
47
|
+
vertices: [{ x: 0, y: 0 }, { x: 20, y: 0 }, { x: 20, y: -10 }, { x: 0, y: -10 }],
|
|
48
|
+
edges: [{ v1_idx: 0, v2_idx: 1 }, { v1_idx: 1, v2_idx: 2 }, { v1_idx: 2, v2_idx: 3 }, { v1_idx: 3, v2_idx: 0 }],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{ name: "L2", elevation: 4, doors: [], nav_graphs: [{ name: "0", vertices: [{ x: 1, y: -1, name: "top" }, { x: 3, y: -1, name: "" }], edges: [{ v1_idx: 0, v2_idx: 1, edge_type: 0 }] }], wall_graph: { vertices: [], edges: [] } },
|
|
52
|
+
],
|
|
53
|
+
lifts: [
|
|
54
|
+
{
|
|
55
|
+
name: "Lift1",
|
|
56
|
+
levels: ["L1", "L2"],
|
|
57
|
+
ref_x: 15,
|
|
58
|
+
ref_y: -8,
|
|
59
|
+
ref_yaw: 0,
|
|
60
|
+
width: 2,
|
|
61
|
+
depth: 2,
|
|
62
|
+
doors: [{ name: "cabin", v1_x: 16, v1_y: -8.6, v2_x: 16, v2_y: -7.4, door_type: 2 }],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
test("import: levels, walls, door types, lanes + params, graphs, lift cabin doors", () => {
|
|
68
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
69
|
+
assert.equal(rmf.source, "fleet-core");
|
|
70
|
+
assert.equal(rmf.levels.length, 2);
|
|
71
|
+
const l1 = rmf.levels[0];
|
|
72
|
+
assert.equal(l1.floorNo, 1);
|
|
73
|
+
assert.equal(l1.walls.length, 4);
|
|
74
|
+
assert.deepEqual(l1.doors.map((d) => d.type), ["double_hinged", "double_sliding"]);
|
|
75
|
+
assert.equal(l1.doors[0].motionDegrees, 90);
|
|
76
|
+
assert.equal(l1.doors[0].motionDirection, -1);
|
|
77
|
+
assert.equal(l1.lanes.length, 2);
|
|
78
|
+
assert.equal(l1.lanes[0].bidirectional, true);
|
|
79
|
+
assert.deepEqual({ b: l1.lanes[1].bidirectional, s: l1.lanes[1].speedLimit, m: l1.lanes[1].mutex }, { b: false, s: 0.5, m: "corridor" });
|
|
80
|
+
const dock = l1.vertices.find((v) => v.name === "dock");
|
|
81
|
+
assert.deepEqual(dock.params, { is_charger: true, dock_name: "dock1" });
|
|
82
|
+
assert.deepEqual(l1.vertices.find((v) => v.name === "entry").params, { is_holding_point: true });
|
|
83
|
+
assert.deepEqual(rmf.graphs, [{ idx: 0, name: "Graph 0", brands: ["fleet-core"] }]);
|
|
84
|
+
const lift = rmf.lifts[0];
|
|
85
|
+
assert.equal(lift.doors.length, 1);
|
|
86
|
+
assert.deepEqual({ x: lift.doors[0].x, y: lift.doors[0].y, w: lift.doors[0].widthM }, { x: 1, y: 0, w: 1.2 });
|
|
87
|
+
assert.deepEqual(lift.levelDoors, [{ level: "L1", doors: ["cabin"] }, { level: "L2", doors: ["cabin"] }]);
|
|
88
|
+
assert.equal(rmfProblem(rmf), null);
|
|
89
|
+
const { error } = rmfBuildingSchema.validate(rmf);
|
|
90
|
+
assert.equal(error, undefined, error?.message);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("plan frame: the import frame is the robots' planShareOf extent; toPlan/fromPlan invert", () => {
|
|
94
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
95
|
+
const f = rmf.levels[0].planFrame;
|
|
96
|
+
// nav vertices x 5..12, doors 4..10 -> 4..12 padded 3; y -7..0 padded 3
|
|
97
|
+
assert.deepEqual(f, { minX: 1, maxX: 15, minY: -10, maxY: 3 });
|
|
98
|
+
const p = { x: 7.5, y: -2.25 };
|
|
99
|
+
assert.deepEqual(fromPlan(f, toPlan(f, p)), p);
|
|
100
|
+
assert.deepEqual(toPlan(DEFAULT_PLAN_FRAME, { x: 10, y: -5 }), { x: 10, y: 5 });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("legacy derived from rmf is valid for every existing reader", () => {
|
|
104
|
+
const legacy = legacyFromRmf(rmfFromFleetCore(MSG));
|
|
105
|
+
assert.deepEqual(legacy.doors.map((d) => d.type), ["hinged", "sliding"]);
|
|
106
|
+
assert.equal(legacy.levels[0].walls.length, 4);
|
|
107
|
+
assert.deepEqual(legacy.lifts[0].floors, [1, 2]);
|
|
108
|
+
const { error } = buildingMapBodySchema.validate({ name: "x", ...legacy });
|
|
109
|
+
assert.equal(error, undefined, error?.message);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a legacy save folds into rmf: lanes, waypoints, door motion and cabin doors survive", () => {
|
|
113
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
114
|
+
const legacy = legacyFromRmf(rmf);
|
|
115
|
+
// The person moves one wall end, renames nothing, and adds a new door + a new lift.
|
|
116
|
+
legacy.levels[0].walls[0].end = { x: legacy.levels[0].walls[0].end.x - 1, y: legacy.levels[0].walls[0].end.y };
|
|
117
|
+
legacy.doors.push({ name: "new", floorNo: 2, type: "sliding", start: { x: 1, y: 1 }, end: { x: 2, y: 1 } });
|
|
118
|
+
legacy.lifts.push({ name: "Lift2", x: 30, y: 20, widthM: 2, depthM: 2, floors: [1, 2] });
|
|
119
|
+
const merged = mergeLegacyIntoRmf(rmf, legacy);
|
|
120
|
+
assert.equal(rmfProblem(merged), null);
|
|
121
|
+
const l1 = merged.levels[0];
|
|
122
|
+
assert.equal(l1.lanes.length, 2, "lanes kept");
|
|
123
|
+
assert.ok(l1.vertices.find((v) => v.name === "dock")?.params?.is_charger, "waypoint params kept");
|
|
124
|
+
assert.equal(l1.doors.find((d) => d.name === "main").type, "double_hinged", "door kept its RMF type");
|
|
125
|
+
assert.equal(l1.doors.find((d) => d.name === "main").motionDirection, -1);
|
|
126
|
+
assert.equal(merged.levels[1].doors[0].name, "new");
|
|
127
|
+
assert.equal(merged.lifts[0].doors[0].name, "cabin", "cabin door kept");
|
|
128
|
+
assert.equal(merged.lifts[1].doors.length, 1, "a new lift gets a default cabin door");
|
|
129
|
+
assert.deepEqual(merged.lifts[1].levelDoors.map((x) => x.level), ["L1", "L2"]);
|
|
130
|
+
// And it is stable: deriving again gives the same legacy walls.
|
|
131
|
+
const again = legacyFromRmf(merged);
|
|
132
|
+
assert.deepEqual(again.levels[0].walls, legacy.levels[0].walls);
|
|
133
|
+
const { error } = rmfBuildingSchema.validate(merged);
|
|
134
|
+
assert.equal(error, undefined, error?.message);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("a door that changed kind drops its old RMF type; a removed wall's plain vertex is pruned", () => {
|
|
138
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
139
|
+
const legacy = legacyFromRmf(rmf);
|
|
140
|
+
legacy.doors[0].type = "sliding";
|
|
141
|
+
legacy.levels[0].walls = legacy.levels[0].walls.slice(1);
|
|
142
|
+
const merged = mergeLegacyIntoRmf(rmf, legacy);
|
|
143
|
+
assert.equal(merged.levels[0].doors[0].type, "sliding");
|
|
144
|
+
assert.equal(merged.levels[0].walls.length, 3);
|
|
145
|
+
assert.equal(rmfProblem(merged), null);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("a map drawn natively exports: default frame, y flipped up", () => {
|
|
149
|
+
const rmf = mergeLegacyIntoRmf(null, {
|
|
150
|
+
levels: [{ floorNo: 1, walls: [{ start: { x: 0, y: 0 }, end: { x: 10, y: 0 } }], zones: [] }],
|
|
151
|
+
doors: [],
|
|
152
|
+
lifts: [{ name: "L", x: 5, y: 5, widthM: 2, depthM: 2, floors: [1, 2] }],
|
|
153
|
+
});
|
|
154
|
+
assert.deepEqual(rmf.levels[0].planFrame, DEFAULT_PLAN_FRAME);
|
|
155
|
+
assert.deepEqual(rmf.levels[0].vertices.map((v) => [v.x, v.y]), [[0, 0], [10, 0]]);
|
|
156
|
+
assert.deepEqual([rmf.lifts[0].x, rmf.lifts[0].y], [5, -5]);
|
|
157
|
+
assert.equal(rmf.levels.length, 2, "a floor served only by a lift becomes a level");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("references are checked", () => {
|
|
161
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
162
|
+
rmf.levels[0].lanes.push({ v1: "v1", v2: "nope", graphIdx: 0, bidirectional: true });
|
|
163
|
+
assert.match(rmfProblem(rmf), /does not exist/);
|
|
164
|
+
const r2 = rmfFromFleetCore(MSG);
|
|
165
|
+
r2.levels[1].doors.push({ ...r2.levels[0].doors[0], v1: r2.levels[1].vertices[0].id, v2: r2.levels[1].vertices[1].id });
|
|
166
|
+
assert.match(rmfProblem(r2), /unique/);
|
|
167
|
+
const r3 = rmfFromFleetCore(MSG);
|
|
168
|
+
r3.levels[0].lanes[0].graphIdx = 5;
|
|
169
|
+
assert.match(rmfProblem(r3), /route graph/);
|
|
170
|
+
const r4 = rmfFromFleetCore(MSG);
|
|
171
|
+
r4.lifts[0].levelDoors[0].doors = ["ghost"];
|
|
172
|
+
assert.match(rmfProblem(r4), /cabin door/);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test("building.yaml export: cartesian metres, [type, value] params, lifts with level_doors", () => {
|
|
176
|
+
const y = JSON.parse(toBuildingYaml("tower", rmfFromFleetCore(MSG)));
|
|
177
|
+
assert.equal(y.coordinate_system, "cartesian_meters");
|
|
178
|
+
const l1 = y.levels.L1;
|
|
179
|
+
const dock = l1.vertices.find((v) => v[3] === "dock");
|
|
180
|
+
assert.deepEqual(dock[4], { is_charger: [4, true], dock_name: [1, "dock1"] });
|
|
181
|
+
assert.equal(l1.walls.length, 4);
|
|
182
|
+
assert.deepEqual(l1.doors[0][2].type, [1, "double_hinged"]);
|
|
183
|
+
assert.deepEqual(l1.lanes[1][2].speed_limit, [3, 0.5]);
|
|
184
|
+
assert.deepEqual(l1.lanes[0][2].graph_idx, [2, 0]);
|
|
185
|
+
assert.deepEqual(y.lifts.Lift1.level_doors, { L1: ["cabin"], L2: ["cabin"] });
|
|
186
|
+
assert.equal(y.lifts.Lift1.doors.cabin.door_type, 2);
|
|
187
|
+
assert.equal(y.lifts.Lift1.lowest_floor, "L1");
|
|
188
|
+
assert.equal(y.lifts.Lift1.highest_floor, "L2");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("nav graph export: bidirectional split, dock/undock, door_name on a crossing lane, lift on a cabin vertex", () => {
|
|
192
|
+
const rmf = rmfFromFleetCore(MSG);
|
|
193
|
+
// A lane through the "main" door (4..6 at y=-1) and a vertex inside Lift1's cabin (15,-8 +-1).
|
|
194
|
+
const l1 = rmf.levels[0];
|
|
195
|
+
l1.vertices.push({ id: "vx1", x: 5, y: 2 }, { id: "vx2", x: 15, y: -8, name: "lift_stop" });
|
|
196
|
+
l1.lanes.push({ v1: "vx1", v2: l1.vertices.find((v) => v.name === "hall").id, graphIdx: 0, bidirectional: false });
|
|
197
|
+
l1.lanes.push({ v1: l1.vertices.find((v) => v.name === "dock").id, v2: "vx2", graphIdx: 0, bidirectional: true });
|
|
198
|
+
const g = JSON.parse(toNavGraphs("tower", rmf)[0]);
|
|
199
|
+
const L1 = g.levels.L1;
|
|
200
|
+
// entry<->hall bidirectional = 2 lanes; hall->dock one way; vx1->hall one way (crosses the door); dock<->vx2 = 2 lanes
|
|
201
|
+
assert.equal(L1.lanes.length, 6);
|
|
202
|
+
const name = (i) => L1.vertices[i][2].name;
|
|
203
|
+
const hallDock = L1.lanes.find((l) => name(l[0]) === "hall" && name(l[1]) === "dock");
|
|
204
|
+
assert.deepEqual(hallDock[2], { speed_limit: 0.5, mutex: "corridor", dock_name: "dock1" });
|
|
205
|
+
const fromDock = L1.lanes.find((l) => name(l[0]) === "dock" && name(l[1]) === "lift_stop");
|
|
206
|
+
assert.equal(fromDock[2].undock_name, "dock1");
|
|
207
|
+
const toDock = L1.lanes.find((l) => name(l[0]) === "lift_stop" && name(l[1]) === "dock");
|
|
208
|
+
assert.equal(toDock[2].dock_name, "dock1");
|
|
209
|
+
const throughDoor = L1.lanes.find((l) => L1.vertices[l[0]][1] === 2);
|
|
210
|
+
assert.equal(throughDoor[2].door_name, "main");
|
|
211
|
+
assert.equal(L1.vertices.find((v) => v[2].name === "lift_stop")[2].lift, "Lift1");
|
|
212
|
+
assert.deepEqual(g.lifts.Lift1, { position: [15, -8, 0], dims: [2, 2] });
|
|
213
|
+
assert.deepEqual(g.doors.main.map, "L1");
|
|
214
|
+
assert.equal(toNavGraphs("tower", { ...rmf, levels: rmf.levels.map((l) => ({ ...l, lanes: [] })) })[0], undefined, "empty graphs are skipped");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("summary counts", () => {
|
|
218
|
+
assert.deepEqual(rmfSummary(rmfFromFleetCore(MSG)), { source: "fleet-core", levels: 2, lanes: 3, waypoints: 4, doors: 2, lifts: 1, graphs: 1 });
|
|
219
|
+
assert.equal(rmfSummary(null), null);
|
|
220
|
+
});
|