@7365admin1/core 3.125.0 → 3.126.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 +12 -0
- package/dist/index.d.ts +101 -2
- package/dist/index.js +655 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +710 -117
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/test/e2e/harness.mjs +2 -0
- package/test/e2e/service-provider-subcontract.e2e.test.mjs +389 -0
- package/test/e2e/visitor-search.e2e.test.mjs +107 -0
- package/test/invite-org-scope.test.mjs +11 -7
- package/test/service-provider-subcontract.test.mjs +125 -0
- package/test/visitor-search.test.mjs +122 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
decideServiceProviderInvite,
|
|
6
|
+
serviceProviderInviteScope,
|
|
7
|
+
serviceProviderInviterKind,
|
|
8
|
+
SUBCONTRACT_SITE_REFUSAL,
|
|
9
|
+
SUBCONTRACT_ADMIN_REFUSAL,
|
|
10
|
+
} from "./.build/utils/service-provider-invite.util.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Service providers inviting other service providers (owner request
|
|
14
|
+
* 2026-09-28): a provider may bring in a subcontractor only for a site it is
|
|
15
|
+
* itself engaged on, only its owner/admin may do it, and the invitation waits
|
|
16
|
+
* for the Seven365 super admin exactly like a property manager's.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const base = {
|
|
20
|
+
isStaff: false,
|
|
21
|
+
siteOwnerOrg: "pm",
|
|
22
|
+
inviterOrg: "pm",
|
|
23
|
+
callerInInviterOrg: true,
|
|
24
|
+
inviterEngagedOnSite: false,
|
|
25
|
+
callerRunsInviterOrg: false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test("the site's own organisation invites as the client, unchanged", () => {
|
|
29
|
+
assert.deepEqual(serviceProviderInviteScope(base), { ok: true, sender: "client" });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("a provider engaged on the site, run by the caller, invites a subcontractor", () => {
|
|
33
|
+
assert.deepEqual(
|
|
34
|
+
serviceProviderInviteScope({
|
|
35
|
+
...base,
|
|
36
|
+
inviterOrg: "aigle",
|
|
37
|
+
inviterEngagedOnSite: true,
|
|
38
|
+
callerRunsInviterOrg: true,
|
|
39
|
+
}),
|
|
40
|
+
{ ok: true, sender: "subcontract" },
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("a provider NOT on the site is refused", () => {
|
|
45
|
+
const r = serviceProviderInviteScope({
|
|
46
|
+
...base,
|
|
47
|
+
inviterOrg: "aigle",
|
|
48
|
+
inviterEngagedOnSite: false,
|
|
49
|
+
callerRunsInviterOrg: true,
|
|
50
|
+
});
|
|
51
|
+
assert.equal(r.ok, false);
|
|
52
|
+
assert.equal(r.reason, SUBCONTRACT_SITE_REFUSAL);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a guard of an engaged provider (not owner/admin) is refused", () => {
|
|
56
|
+
const r = serviceProviderInviteScope({
|
|
57
|
+
...base,
|
|
58
|
+
inviterOrg: "aigle",
|
|
59
|
+
inviterEngagedOnSite: true,
|
|
60
|
+
callerRunsInviterOrg: false,
|
|
61
|
+
});
|
|
62
|
+
assert.equal(r.ok, false);
|
|
63
|
+
assert.equal(r.reason, SUBCONTRACT_ADMIN_REFUSAL);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("nobody invites for an organisation they are not in", () => {
|
|
67
|
+
const r = serviceProviderInviteScope({ ...base, callerInInviterOrg: false });
|
|
68
|
+
assert.equal(r.ok, false);
|
|
69
|
+
assert.match(r.reason, /your own organisation/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("Seven365 staff are not asked", () => {
|
|
73
|
+
assert.deepEqual(
|
|
74
|
+
serviceProviderInviteScope({ ...base, isStaff: true, callerInInviterOrg: false }),
|
|
75
|
+
{ ok: true, sender: "staff" },
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("a provider's invitation waits for Seven365, like a property manager's", () => {
|
|
80
|
+
const facts = {
|
|
81
|
+
hasUser: true,
|
|
82
|
+
hasProviderOrg: true,
|
|
83
|
+
engagedOnSite: false,
|
|
84
|
+
invitePending: false,
|
|
85
|
+
};
|
|
86
|
+
assert.equal(
|
|
87
|
+
decideServiceProviderInvite({ ...facts, inviterIsServiceProvider: true }).requiresApproval,
|
|
88
|
+
true,
|
|
89
|
+
);
|
|
90
|
+
assert.equal(
|
|
91
|
+
decideServiceProviderInvite({ ...facts, inviterIsPropertyManagement: true }).requiresApproval,
|
|
92
|
+
true,
|
|
93
|
+
);
|
|
94
|
+
assert.equal(decideServiceProviderInvite(facts).requiresApproval, false);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("who sent it, in words", () => {
|
|
98
|
+
assert.equal(serviceProviderInviterKind("pm", "pm"), "property-management");
|
|
99
|
+
assert.equal(serviceProviderInviterKind("aigle", "pm"), "service-provider");
|
|
100
|
+
assert.equal(serviceProviderInviterKind("pm", ""), "property-management");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
import {
|
|
104
|
+
serviceTypeLabel,
|
|
105
|
+
filterSiteProviderMembers,
|
|
106
|
+
} from "./.build/utils/service-provider-invite.util.mjs";
|
|
107
|
+
|
|
108
|
+
test("service types read in words", () => {
|
|
109
|
+
assert.equal(serviceTypeLabel("security_agency"), "Security");
|
|
110
|
+
assert.equal(serviceTypeLabel("cleaning_services"), "Cleaning");
|
|
111
|
+
assert.equal(serviceTypeLabel(""), "Other");
|
|
112
|
+
assert.equal(serviceTypeLabel("drone_services"), "drone services");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("members filters: type, company, search - one rule for screen and export", () => {
|
|
116
|
+
const items = [
|
|
117
|
+
{ name: "Gus Guard", email: "g@a.com", company: "Aigle Security", companyId: "a", type: "security_agency", role: "Guard" },
|
|
118
|
+
{ name: "Casey Cleaner", email: "c@s.com", company: "Sparkle", companyId: "s", type: "cleaning_services", role: "Cleaner", invitedVia: "Aigle Security" },
|
|
119
|
+
];
|
|
120
|
+
assert.deepEqual(filterSiteProviderMembers(items, { type: "security_agency" }).map((m) => m.name), ["Gus Guard"]);
|
|
121
|
+
assert.deepEqual(filterSiteProviderMembers(items, { company: "s" }).map((m) => m.name), ["Casey Cleaner"]);
|
|
122
|
+
assert.deepEqual(filterSiteProviderMembers(items, { search: "aigle" }).map((m) => m.name), ["Gus Guard", "Casey Cleaner"]);
|
|
123
|
+
assert.deepEqual(filterSiteProviderMembers(items, { search: "CLEANER" }).map((m) => m.name), ["Casey Cleaner"]);
|
|
124
|
+
assert.equal(filterSiteProviderMembers(items, {}).length, 2);
|
|
125
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
visitorRowSearchOr,
|
|
8
|
+
escapeRegex,
|
|
9
|
+
normaliseVisitorSearch,
|
|
10
|
+
VISITOR_SEARCH_MAX_LENGTH,
|
|
11
|
+
} from "./.build/utils/visitor-search.util.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Visitor Management search (production) matched `name` only, with the typed
|
|
15
|
+
* text used as a raw pattern: plates, phones, NRIC and company always came back
|
|
16
|
+
* empty and "(" was a 500. These cases evaluate the row-field `$or` against
|
|
17
|
+
* rows shaped like production's, with the regex semantics Mongo applies.
|
|
18
|
+
* Block / level / unit and pass / key matching live in `buildSearchStages`
|
|
19
|
+
* and are covered by test/e2e/visitor-search.e2e.test.mjs.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function valuesAt(doc, path) {
|
|
23
|
+
return path
|
|
24
|
+
.split(".")
|
|
25
|
+
.reduce(
|
|
26
|
+
(vals, key) =>
|
|
27
|
+
vals
|
|
28
|
+
.flatMap((v) => (Array.isArray(v) ? v : [v]))
|
|
29
|
+
.map((v) => (v == null ? undefined : v[key]))
|
|
30
|
+
.filter((v) => v !== undefined),
|
|
31
|
+
[doc],
|
|
32
|
+
)
|
|
33
|
+
.flatMap((v) => (Array.isArray(v) ? v : [v]));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const matches = (doc, or) =>
|
|
37
|
+
or.some((clause) =>
|
|
38
|
+
Object.entries(clause).some(([path, cond]) =>
|
|
39
|
+
valuesAt(doc, path).some(
|
|
40
|
+
(v) => typeof v === "string" && new RegExp(cond.$regex, cond.$options).test(v),
|
|
41
|
+
),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const rows = [
|
|
46
|
+
{ _id: 1, name: "Dion", contact: "+6591177963", plateNumber: "SLM1189Y", company: "Asia", nric: "S1234963A" },
|
|
47
|
+
{ _id: 2, name: "Oh", contact: "+6586836992", plateNumber: "GBC 1706B", company: "Samsung", purpose: "Aircon servicing" },
|
|
48
|
+
{ _id: 3, name: "", contact: "", plateNumber: "SHD5861H", deliveryType: "Parcel-Delivery" },
|
|
49
|
+
{ _id: 4, name: "Lead", members: [{ name: "Priya Nair", nric: "T0000123Z", contact: "+65 8123 4567", plateNumber: "sjx-42k" }] },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const search = (q) => {
|
|
53
|
+
const or = visitorRowSearchOr(q);
|
|
54
|
+
return or.length ? rows.filter((r) => matches(r, or)).map((r) => r._id) : rows.map((r) => r._id);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
test("name: case-insensitive, partial", () => {
|
|
58
|
+
assert.deepEqual(search("dio"), [1]);
|
|
59
|
+
assert.deepEqual(search("DION"), [1]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("plate: ignores spaces, hyphens and case, both ways round", () => {
|
|
63
|
+
assert.deepEqual(search("SLM1189Y"), [1]);
|
|
64
|
+
assert.deepEqual(search("slm 1189-y"), [1]);
|
|
65
|
+
assert.deepEqual(search("gbc1706b"), [2], "typed without the space it was saved with");
|
|
66
|
+
assert.deepEqual(search("1189"), [1]);
|
|
67
|
+
assert.deepEqual(search("SJX42K"), [4], "a group member's plate");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("phone: by digits, however it is typed or stored", () => {
|
|
71
|
+
assert.deepEqual(search("6591177963"), [1]);
|
|
72
|
+
assert.deepEqual(search("+65 9117 7963"), [1]);
|
|
73
|
+
assert.deepEqual(search("9117-7963"), [1]);
|
|
74
|
+
assert.deepEqual(search("81234567"), [4], "a member's spaced number");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("NRIC last four, company, purpose, delivery type, member name", () => {
|
|
78
|
+
assert.deepEqual(search("963a"), [1]);
|
|
79
|
+
assert.deepEqual(search("samsung"), [2]);
|
|
80
|
+
assert.deepEqual(search("aircon"), [2]);
|
|
81
|
+
assert.deepEqual(search("parcel"), [3]);
|
|
82
|
+
assert.deepEqual(search("priya"), [4]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("typed text is a literal: regex characters cannot break or widen the query", () => {
|
|
86
|
+
for (const q of ["(", "+", "a.*", "[", "\\", "?", "$^"]) {
|
|
87
|
+
assert.doesNotThrow(() => search(q), q);
|
|
88
|
+
}
|
|
89
|
+
assert.deepEqual(search(".*"), [], "'.*' is not 'everything'");
|
|
90
|
+
assert.equal(escapeRegex("a.b(c)"), "a\\.b\\(c\\)");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("empty / blank / non-string search means no filter", () => {
|
|
94
|
+
assert.deepEqual(visitorRowSearchOr(""), []);
|
|
95
|
+
assert.deepEqual(visitorRowSearchOr(" "), []);
|
|
96
|
+
assert.deepEqual(visitorRowSearchOr(undefined), []);
|
|
97
|
+
assert.deepEqual(visitorRowSearchOr(["x"]), []);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("search is trimmed, collapsed and capped (old clients send it raw)", () => {
|
|
101
|
+
assert.equal(normaliseVisitorSearch(" Dion Tan "), "Dion Tan");
|
|
102
|
+
assert.equal(normaliseVisitorSearch("x".repeat(500)).length, VISITOR_SEARCH_MAX_LENGTH);
|
|
103
|
+
assert.deepEqual(search(" dion "), [1]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("phone matcher only for phone-shaped input; plate matcher needs 2 chars", () => {
|
|
107
|
+
const fields = (q) => visitorRowSearchOr(q).flatMap(Object.keys);
|
|
108
|
+
assert.ok(!fields("Dion").includes("contact"));
|
|
109
|
+
assert.ok(fields("9117").includes("contact"));
|
|
110
|
+
assert.ok(!fields("a").includes("plateNumber"));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("repository wiring: the search box goes through the util, after the site/date/status $match", () => {
|
|
114
|
+
const repo = readFileSync(
|
|
115
|
+
fileURLToPath(new URL("../src/repositories/visitor-transaction.repo.ts", import.meta.url)),
|
|
116
|
+
"utf8",
|
|
117
|
+
);
|
|
118
|
+
assert.ok(!/name: \{ \$regex: search/.test(repo), "raw name-only regex is gone");
|
|
119
|
+
assert.match(repo, /const text = normaliseVisitorSearch\(search\);/);
|
|
120
|
+
assert.match(repo, /\.\.\.visitorRowSearchOr\(text\),/);
|
|
121
|
+
assert.match(repo, /\{ \$match: query \},\s*\.\.\.buildSearchStages\(search\),/);
|
|
122
|
+
});
|