@7365admin1/core 3.96.1-staging.365 → 3.96.1-staging.367
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/.changeset/hid-sip-account-unit-label.md +40 -0
- package/dist/index.d.ts +104 -15
- package/dist/index.js +284 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +284 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/hid-identification-drift.test.mjs +363 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@7365admin1/core": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Return the owner's block, level and unit with each HID SIP account.
|
|
6
|
+
|
|
7
|
+
`listSipAccounts` answered a name, email and extension per account, which is
|
|
8
|
+
enough to say who holds an extension but not which home it reaches. Two
|
|
9
|
+
residents called Harris were indistinguishable in the intercom contact picker,
|
|
10
|
+
and the contact saved onto the reader carried no address at all — so the door
|
|
11
|
+
panel's contact list named a person without saying whose unit was being rung.
|
|
12
|
+
|
|
13
|
+
Each row now carries `unitLabel`, the readable `Blk 1/Level 1/Unit 1`. The three
|
|
14
|
+
stored values are ObjectIds into `buildings`, `building-levels` and
|
|
15
|
+
`building-units`, so every one is resolved to its name; joining the raw values
|
|
16
|
+
would stamp `665f.../665f.../665f...` onto the reader. A block carries both a
|
|
17
|
+
number and an optional descriptive name and the short number wins, because the
|
|
18
|
+
label is read off a door panel.
|
|
19
|
+
|
|
20
|
+
The address comes from `site.people` first — where it is edited, and the source
|
|
21
|
+
`loadPermissionSubjects` already trusts for a resident's subtitle — and falls
|
|
22
|
+
back to the copy `person.service` keeps on `users`, for an account whose owner
|
|
23
|
+
has no active person row on the site.
|
|
24
|
+
|
|
25
|
+
An owner with neither does not live here, so `unitLabel` carries their
|
|
26
|
+
membership type instead — "Security Agency" rather than nothing — read from a
|
|
27
|
+
live `members` row on the SAME site. A user can hold several memberships (the
|
|
28
|
+
unique index is `org_1_siteId_1_user_1_type_1`), so a non-organization row is
|
|
29
|
+
preferred: "organization" names the company that employs them, not what they are
|
|
30
|
+
at this door. It is still used when it is the only membership there is. A `type`
|
|
31
|
+
of 24 hex characters is dropped rather than printed — `MMember` accepts an
|
|
32
|
+
organisation id in that field, and stamping one onto the reader's contact list
|
|
33
|
+
would be the same defect as joining the raw block and level ids.
|
|
34
|
+
|
|
35
|
+
`""` only when the site knows neither, which the picker reads as "no suffix" and
|
|
36
|
+
leaves the bare name.
|
|
37
|
+
|
|
38
|
+
Four id-keyed lookups for the whole list, not one per row, and the `members`
|
|
39
|
+
read is skipped entirely when every owner already has an address. The response
|
|
40
|
+
still never contains a SIP password.
|
package/dist/index.d.ts
CHANGED
|
@@ -14300,7 +14300,7 @@ declare function useHrmLabsAttendanceSrvc(): {
|
|
|
14300
14300
|
pages: number;
|
|
14301
14301
|
pageRange: string;
|
|
14302
14302
|
success?: undefined;
|
|
14303
|
-
message?: undefined;
|
|
14303
|
+
readonly message?: undefined;
|
|
14304
14304
|
count?: undefined;
|
|
14305
14305
|
} | {
|
|
14306
14306
|
success: boolean;
|
|
@@ -14330,7 +14330,7 @@ declare function useHrmLabsAttendanceSrvc(): {
|
|
|
14330
14330
|
};
|
|
14331
14331
|
};
|
|
14332
14332
|
success?: undefined;
|
|
14333
|
-
message?: undefined;
|
|
14333
|
+
readonly message?: undefined;
|
|
14334
14334
|
} | {
|
|
14335
14335
|
success: boolean;
|
|
14336
14336
|
message: any;
|
|
@@ -14404,7 +14404,7 @@ declare function useHrmLabsAttendanceSrvc(): {
|
|
|
14404
14404
|
totalCount: number;
|
|
14405
14405
|
};
|
|
14406
14406
|
success?: undefined;
|
|
14407
|
-
message?: undefined;
|
|
14407
|
+
readonly message?: undefined;
|
|
14408
14408
|
count?: undefined;
|
|
14409
14409
|
} | {
|
|
14410
14410
|
success: boolean;
|
|
@@ -14440,7 +14440,7 @@ declare function useHrmLabsAttendanceSrvc(): {
|
|
|
14440
14440
|
normal: number;
|
|
14441
14441
|
}[];
|
|
14442
14442
|
success?: undefined;
|
|
14443
|
-
message?: undefined;
|
|
14443
|
+
readonly message?: undefined;
|
|
14444
14444
|
items?: undefined;
|
|
14445
14445
|
pages?: undefined;
|
|
14446
14446
|
pageRange?: undefined;
|
|
@@ -15056,7 +15056,7 @@ declare function useVerificationServiceV2(): {
|
|
|
15056
15056
|
status: string;
|
|
15057
15057
|
attemptsLeft: number;
|
|
15058
15058
|
message: string;
|
|
15059
|
-
reason?: undefined;
|
|
15059
|
+
readonly reason?: undefined;
|
|
15060
15060
|
expiredAt?: undefined;
|
|
15061
15061
|
verificationId?: undefined;
|
|
15062
15062
|
type?: undefined;
|
|
@@ -15067,7 +15067,7 @@ declare function useVerificationServiceV2(): {
|
|
|
15067
15067
|
type: string;
|
|
15068
15068
|
email: string;
|
|
15069
15069
|
message: string;
|
|
15070
|
-
reason?: undefined;
|
|
15070
|
+
readonly reason?: undefined;
|
|
15071
15071
|
expiredAt?: undefined;
|
|
15072
15072
|
attemptsLeft?: undefined;
|
|
15073
15073
|
}>;
|
|
@@ -16261,6 +16261,14 @@ type THidAmicoReader = {
|
|
|
16261
16261
|
* not be doing what the record says.
|
|
16262
16262
|
*/
|
|
16263
16263
|
identificationMethodsAppliedAt?: Date | string;
|
|
16264
|
+
/**
|
|
16265
|
+
* When the reader was last READ to see whether its settings still match.
|
|
16266
|
+
*
|
|
16267
|
+
* Not the same as applied: a check finding no drift updates both, a check
|
|
16268
|
+
* that could not reach the reader updates neither. It also throttles the
|
|
16269
|
+
* check on the callback path, which must never make a door event wait.
|
|
16270
|
+
*/
|
|
16271
|
+
identificationMethodsCheckedAt?: Date | string;
|
|
16264
16272
|
portalId?: number;
|
|
16265
16273
|
portalName?: string;
|
|
16266
16274
|
monitorPath?: string;
|
|
@@ -16595,6 +16603,7 @@ declare function useHidAmicoRepo(): {
|
|
|
16595
16603
|
serial?: unknown;
|
|
16596
16604
|
excludeId?: string | ObjectId;
|
|
16597
16605
|
}) => Promise<PublicHidReader | null>;
|
|
16606
|
+
listLiveReaderIdentities: () => Promise<mongodb.WithId<bson.Document>[]>;
|
|
16598
16607
|
getByCallbackTokenHash: {
|
|
16599
16608
|
(callbackTokenHash: string, options: {
|
|
16600
16609
|
includeCallbackTokenHash: true;
|
|
@@ -16756,6 +16765,7 @@ declare function useHidAmicoRepo(): {
|
|
|
16756
16765
|
userId: string;
|
|
16757
16766
|
name: string;
|
|
16758
16767
|
email: string;
|
|
16768
|
+
unitLabel: string;
|
|
16759
16769
|
extension: string;
|
|
16760
16770
|
username: string;
|
|
16761
16771
|
status: string;
|
|
@@ -16919,6 +16929,7 @@ declare function useHidAmicoService(): {
|
|
|
16919
16929
|
firmwareVersion?: string | undefined;
|
|
16920
16930
|
readerModel?: "unknown" | "VL35LF" | "VL70LF" | undefined;
|
|
16921
16931
|
identificationMethodsAppliedAt?: string | Date | undefined;
|
|
16932
|
+
identificationMethodsCheckedAt?: string | Date | undefined;
|
|
16922
16933
|
portalId?: number | undefined;
|
|
16923
16934
|
portalName?: string | undefined;
|
|
16924
16935
|
monitorPath?: string | undefined;
|
|
@@ -16945,17 +16956,52 @@ declare function useHidAmicoService(): {
|
|
|
16945
16956
|
passwordSet: boolean;
|
|
16946
16957
|
}>;
|
|
16947
16958
|
testReader: (id: string) => Promise<{
|
|
16948
|
-
|
|
16949
|
-
|
|
16950
|
-
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16954
|
-
|
|
16959
|
+
identificationMethods: {
|
|
16960
|
+
readonly readerId: string;
|
|
16961
|
+
readonly status: "skipped";
|
|
16962
|
+
readonly reason: "not_found";
|
|
16963
|
+
readonly duplicateReaderId?: undefined;
|
|
16964
|
+
drifted?: undefined;
|
|
16965
|
+
checkedAt?: undefined;
|
|
16966
|
+
readonly message?: undefined;
|
|
16967
|
+
} | {
|
|
16968
|
+
readonly readerId: string;
|
|
16969
|
+
readonly status: "skipped";
|
|
16970
|
+
readonly reason: "not_configured";
|
|
16971
|
+
readonly duplicateReaderId?: undefined;
|
|
16972
|
+
drifted?: undefined;
|
|
16973
|
+
checkedAt?: undefined;
|
|
16974
|
+
readonly message?: undefined;
|
|
16975
|
+
} | {
|
|
16976
|
+
readonly readerId: string;
|
|
16977
|
+
readonly status: "skipped";
|
|
16978
|
+
readonly reason: "duplicate_reader";
|
|
16979
|
+
readonly duplicateReaderId: string;
|
|
16980
|
+
drifted?: undefined;
|
|
16981
|
+
checkedAt?: undefined;
|
|
16982
|
+
readonly message?: undefined;
|
|
16983
|
+
} | {
|
|
16984
|
+
readerId: string;
|
|
16985
|
+
status: string;
|
|
16986
|
+
drifted: string[];
|
|
16987
|
+
checkedAt: Date;
|
|
16988
|
+
readonly reason?: undefined;
|
|
16989
|
+
readonly duplicateReaderId?: undefined;
|
|
16990
|
+
readonly message?: undefined;
|
|
16991
|
+
} | {
|
|
16992
|
+
readonly readerId: string;
|
|
16993
|
+
readonly status: "failed";
|
|
16994
|
+
readonly message: string;
|
|
16995
|
+
readonly reason?: undefined;
|
|
16996
|
+
readonly duplicateReaderId?: undefined;
|
|
16997
|
+
drifted?: undefined;
|
|
16998
|
+
checkedAt?: undefined;
|
|
16955
16999
|
};
|
|
16956
|
-
|
|
16957
|
-
valid: boolean;
|
|
17000
|
+
valid: unknown;
|
|
16958
17001
|
message: string;
|
|
17002
|
+
firmwareVersion?: string | undefined;
|
|
17003
|
+
readerModel: THidAmicoReader["readerModel"];
|
|
17004
|
+
capabilities: THidAmicoReader["capabilities"];
|
|
16959
17005
|
}>;
|
|
16960
17006
|
syncReader: (id: string, payload: unknown) => Promise<{
|
|
16961
17007
|
message: string;
|
|
@@ -17001,6 +17047,47 @@ declare function useHidAmicoService(): {
|
|
|
17001
17047
|
};
|
|
17002
17048
|
appliedAt: Date;
|
|
17003
17049
|
}>;
|
|
17050
|
+
reconcileIdentificationMethods: (readerId: string) => Promise<{
|
|
17051
|
+
readonly readerId: string;
|
|
17052
|
+
readonly status: "skipped";
|
|
17053
|
+
readonly reason: "not_found";
|
|
17054
|
+
readonly duplicateReaderId?: undefined;
|
|
17055
|
+
drifted?: undefined;
|
|
17056
|
+
checkedAt?: undefined;
|
|
17057
|
+
readonly message?: undefined;
|
|
17058
|
+
} | {
|
|
17059
|
+
readonly readerId: string;
|
|
17060
|
+
readonly status: "skipped";
|
|
17061
|
+
readonly reason: "not_configured";
|
|
17062
|
+
readonly duplicateReaderId?: undefined;
|
|
17063
|
+
drifted?: undefined;
|
|
17064
|
+
checkedAt?: undefined;
|
|
17065
|
+
readonly message?: undefined;
|
|
17066
|
+
} | {
|
|
17067
|
+
readonly readerId: string;
|
|
17068
|
+
readonly status: "skipped";
|
|
17069
|
+
readonly reason: "duplicate_reader";
|
|
17070
|
+
readonly duplicateReaderId: string;
|
|
17071
|
+
drifted?: undefined;
|
|
17072
|
+
checkedAt?: undefined;
|
|
17073
|
+
readonly message?: undefined;
|
|
17074
|
+
} | {
|
|
17075
|
+
readerId: string;
|
|
17076
|
+
status: string;
|
|
17077
|
+
drifted: string[];
|
|
17078
|
+
checkedAt: Date;
|
|
17079
|
+
readonly reason?: undefined;
|
|
17080
|
+
readonly duplicateReaderId?: undefined;
|
|
17081
|
+
readonly message?: undefined;
|
|
17082
|
+
} | {
|
|
17083
|
+
readonly readerId: string;
|
|
17084
|
+
readonly status: "failed";
|
|
17085
|
+
readonly message: string;
|
|
17086
|
+
readonly reason?: undefined;
|
|
17087
|
+
readonly duplicateReaderId?: undefined;
|
|
17088
|
+
drifted?: undefined;
|
|
17089
|
+
checkedAt?: undefined;
|
|
17090
|
+
}>;
|
|
17004
17091
|
receiveNotification: (callbackToken: string, type: string, payload: UnknownRecord) => Promise<{
|
|
17005
17092
|
event: null;
|
|
17006
17093
|
response: null;
|
|
@@ -17408,6 +17495,7 @@ declare function useHidAmicoService(): {
|
|
|
17408
17495
|
userId: string;
|
|
17409
17496
|
name: string;
|
|
17410
17497
|
email: string;
|
|
17498
|
+
unitLabel: string;
|
|
17411
17499
|
extension: string;
|
|
17412
17500
|
username: string;
|
|
17413
17501
|
status: string;
|
|
@@ -17433,6 +17521,7 @@ declare function useHidAmicoController(): {
|
|
|
17433
17521
|
configureReaderIntegration: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17434
17522
|
setReaderMonitor: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17435
17523
|
setReaderIdentificationMethods: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17524
|
+
reconcileReaderIdentificationMethods: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17436
17525
|
setOperatingMode: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17437
17526
|
listLogs: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
17438
17527
|
listIdentities: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -46576,6 +46576,7 @@ var schemaHidAmicoReader = import_joi67.default.object({
|
|
|
46576
46576
|
credentialMode: import_joi67.default.string().valid("pin", "idPassword").required()
|
|
46577
46577
|
}).optional(),
|
|
46578
46578
|
identificationMethodsAppliedAt: import_joi67.default.date().optional(),
|
|
46579
|
+
identificationMethodsCheckedAt: import_joi67.default.date().optional(),
|
|
46579
46580
|
portalId: import_joi67.default.number().integer().positive().required(),
|
|
46580
46581
|
portalName: import_joi67.default.string().trim().allow("").optional(),
|
|
46581
46582
|
monitorPath: import_joi67.default.string().allow(null, "").optional(),
|
|
@@ -46627,6 +46628,7 @@ var schemaUpdateHidAmicoReader = import_joi67.default.object({
|
|
|
46627
46628
|
credentialMode: import_joi67.default.string().valid("pin", "idPassword").required()
|
|
46628
46629
|
}).optional(),
|
|
46629
46630
|
identificationMethodsAppliedAt: import_joi67.default.date().optional(),
|
|
46631
|
+
identificationMethodsCheckedAt: import_joi67.default.date().optional(),
|
|
46630
46632
|
portalId: import_joi67.default.number().integer().positive().optional(),
|
|
46631
46633
|
portalName: import_joi67.default.string().trim().optional(),
|
|
46632
46634
|
monitorPath: import_joi67.default.string().allow(null, "").optional(),
|
|
@@ -47293,6 +47295,16 @@ function hidFirmwareAtLeast(value, required) {
|
|
|
47293
47295
|
|
|
47294
47296
|
// src/utils/hid-duplicate.util.ts
|
|
47295
47297
|
var HID_LIVE_READER_STATUSES = ["active", "offline"];
|
|
47298
|
+
function isSameHidDevice(existing, discovered) {
|
|
47299
|
+
const existingDeviceId = readIdentityValue(existing.deviceId);
|
|
47300
|
+
const discoveredDeviceId = readIdentityValue(discovered.deviceId);
|
|
47301
|
+
if (existingDeviceId && discoveredDeviceId && existingDeviceId === discoveredDeviceId) {
|
|
47302
|
+
return true;
|
|
47303
|
+
}
|
|
47304
|
+
const existingSerial = readIdentityValue(existing.serial);
|
|
47305
|
+
const discoveredSerial = readIdentityValue(discovered.serial);
|
|
47306
|
+
return Boolean(existingSerial) && existingSerial === discoveredSerial;
|
|
47307
|
+
}
|
|
47296
47308
|
function hidIdentityConditions(discovered) {
|
|
47297
47309
|
const conditions = [];
|
|
47298
47310
|
const deviceId = readIdentityValue(discovered.deviceId);
|
|
@@ -47314,6 +47326,27 @@ function readIdentityValue(value) {
|
|
|
47314
47326
|
return "";
|
|
47315
47327
|
return String(value).trim();
|
|
47316
47328
|
}
|
|
47329
|
+
function normalizeHidHost(baseUrl) {
|
|
47330
|
+
const raw = String(baseUrl ?? "").trim();
|
|
47331
|
+
if (!raw)
|
|
47332
|
+
return "";
|
|
47333
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `http://${raw}`;
|
|
47334
|
+
try {
|
|
47335
|
+
return new URL(withScheme).hostname.toLowerCase();
|
|
47336
|
+
} catch {
|
|
47337
|
+
return "";
|
|
47338
|
+
}
|
|
47339
|
+
}
|
|
47340
|
+
function findDuplicateReaderRecord(candidates, target) {
|
|
47341
|
+
const others = (Array.isArray(candidates) ? candidates : []).filter((candidate) => String(candidate?._id ?? "") !== String(target._id ?? ""));
|
|
47342
|
+
const byIdentity = others.find((candidate) => isSameHidDevice(candidate, target));
|
|
47343
|
+
if (byIdentity)
|
|
47344
|
+
return byIdentity;
|
|
47345
|
+
const host = normalizeHidHost(target.baseUrl);
|
|
47346
|
+
if (!host)
|
|
47347
|
+
return null;
|
|
47348
|
+
return others.find((candidate) => normalizeHidHost(candidate.baseUrl) === host) ?? null;
|
|
47349
|
+
}
|
|
47317
47350
|
|
|
47318
47351
|
// src/repositories/hid-amico.repo.ts
|
|
47319
47352
|
function isUnknownRecord(value) {
|
|
@@ -47501,6 +47534,12 @@ function useHidAmicoRepo() {
|
|
|
47501
47534
|
}
|
|
47502
47535
|
return options.includePassword ? reader : hideSecret(reader);
|
|
47503
47536
|
}
|
|
47537
|
+
async function listLiveReaderIdentities() {
|
|
47538
|
+
return readers().find(
|
|
47539
|
+
{ status: { $in: [...HID_LIVE_READER_STATUSES] } },
|
|
47540
|
+
{ projection: { _id: 1, name: 1, site: 1, deviceId: 1, serial: 1, baseUrl: 1, status: 1 } }
|
|
47541
|
+
).toArray();
|
|
47542
|
+
}
|
|
47504
47543
|
async function findDuplicateByIdentity(value) {
|
|
47505
47544
|
const conditions = hidIdentityConditions(value);
|
|
47506
47545
|
if (!conditions.length)
|
|
@@ -47852,10 +47891,104 @@ function useHidAmicoRepo() {
|
|
|
47852
47891
|
status: { $ne: "disabled" }
|
|
47853
47892
|
});
|
|
47854
47893
|
}
|
|
47894
|
+
function memberTypeLabel(value) {
|
|
47895
|
+
const type = String(value ?? "").trim();
|
|
47896
|
+
if (!type || /^[a-fA-F0-9]{24}$/.test(type))
|
|
47897
|
+
return "";
|
|
47898
|
+
return type.split(/[_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
47899
|
+
}
|
|
47900
|
+
function isOrganizationMemberType(value) {
|
|
47901
|
+
return String(value ?? "").trim().toLowerCase() === "organization";
|
|
47902
|
+
}
|
|
47903
|
+
async function loadUnitLabels(siteId, userIds, userMap) {
|
|
47904
|
+
const labels = /* @__PURE__ */ new Map();
|
|
47905
|
+
if (!userIds.length)
|
|
47906
|
+
return labels;
|
|
47907
|
+
const people = await db2().collection("site.people").find({
|
|
47908
|
+
site: siteId,
|
|
47909
|
+
user: { $in: userIds },
|
|
47910
|
+
status: "active"
|
|
47911
|
+
}, {
|
|
47912
|
+
projection: { user: 1, block: 1, level: 1, unit: 1, unitName: 1 }
|
|
47913
|
+
}).toArray();
|
|
47914
|
+
const peopleMap = new Map(people.map((row) => [String(row.user), row]));
|
|
47915
|
+
const addressOf = (key) => {
|
|
47916
|
+
const person = peopleMap.get(key);
|
|
47917
|
+
if (person) {
|
|
47918
|
+
return {
|
|
47919
|
+
block: optionalObjectId2(person.block),
|
|
47920
|
+
level: optionalObjectId2(person.level),
|
|
47921
|
+
unit: optionalObjectId2(person.unit),
|
|
47922
|
+
unitName: String(person.unitName || "")
|
|
47923
|
+
};
|
|
47924
|
+
}
|
|
47925
|
+
const user = userMap.get(key);
|
|
47926
|
+
return {
|
|
47927
|
+
block: optionalObjectId2(user?.block),
|
|
47928
|
+
level: optionalObjectId2(user?.level),
|
|
47929
|
+
unit: optionalObjectId2(user?.unitId),
|
|
47930
|
+
unitName: String(user?.unitName || "")
|
|
47931
|
+
};
|
|
47932
|
+
};
|
|
47933
|
+
const addresses = new Map(userIds.map((userId) => {
|
|
47934
|
+
const key = String(userId);
|
|
47935
|
+
return [key, addressOf(key)];
|
|
47936
|
+
}));
|
|
47937
|
+
const collect = (pick) => {
|
|
47938
|
+
const seen2 = /* @__PURE__ */ new Map();
|
|
47939
|
+
for (const address of addresses.values()) {
|
|
47940
|
+
const id = pick(address);
|
|
47941
|
+
if (id)
|
|
47942
|
+
seen2.set(String(id), id);
|
|
47943
|
+
}
|
|
47944
|
+
return [...seen2.values()];
|
|
47945
|
+
};
|
|
47946
|
+
const lookup = async (collection, ids2, projection) => {
|
|
47947
|
+
if (!ids2.length)
|
|
47948
|
+
return /* @__PURE__ */ new Map();
|
|
47949
|
+
const rows = await db2().collection(collection).find(
|
|
47950
|
+
{ _id: { $in: ids2 } },
|
|
47951
|
+
{ projection }
|
|
47952
|
+
).toArray();
|
|
47953
|
+
return new Map(rows.map((row) => [String(row._id), row]));
|
|
47954
|
+
};
|
|
47955
|
+
const [blocks, levels, units] = await Promise.all([
|
|
47956
|
+
lookup("buildings", collect((address) => address.block), { block: 1, name: 1 }),
|
|
47957
|
+
lookup("building-levels", collect((address) => address.level), { name: 1 }),
|
|
47958
|
+
lookup("building-units", collect((address) => address.unit), { name: 1 })
|
|
47959
|
+
]);
|
|
47960
|
+
for (const [key, address] of addresses) {
|
|
47961
|
+
const blockRow = address.block ? blocks.get(String(address.block)) : void 0;
|
|
47962
|
+
const blockLabel = blockRow ? blockRow.block ? `Blk ${String(blockRow.block)}` : String(blockRow.name || "") : "";
|
|
47963
|
+
const levelLabel = address.level ? String(levels.get(String(address.level))?.name || "") : "";
|
|
47964
|
+
const unitLabel = (address.unit ? String(units.get(String(address.unit))?.name || "") : "") || address.unitName;
|
|
47965
|
+
labels.set(key, [blockLabel, levelLabel, unitLabel].filter(Boolean).join("/"));
|
|
47966
|
+
}
|
|
47967
|
+
const withoutAddress = userIds.filter((userId) => !labels.get(String(userId)));
|
|
47968
|
+
if (!withoutAddress.length)
|
|
47969
|
+
return labels;
|
|
47970
|
+
const members = await db2().collection("members").find({
|
|
47971
|
+
siteId,
|
|
47972
|
+
user: { $in: withoutAddress },
|
|
47973
|
+
status: "active"
|
|
47974
|
+
}, {
|
|
47975
|
+
projection: { user: 1, type: 1 }
|
|
47976
|
+
}).toArray();
|
|
47977
|
+
const ordered = [...members].sort((left, right) => Number(isOrganizationMemberType(left.type)) - Number(isOrganizationMemberType(right.type)));
|
|
47978
|
+
for (const member of ordered) {
|
|
47979
|
+
const key = String(member.user);
|
|
47980
|
+
const label2 = memberTypeLabel(member.type);
|
|
47981
|
+
if (!label2 || labels.get(key))
|
|
47982
|
+
continue;
|
|
47983
|
+
labels.set(key, label2);
|
|
47984
|
+
}
|
|
47985
|
+
return labels;
|
|
47986
|
+
}
|
|
47855
47987
|
async function listSipAccounts(orgIdValue, siteValue) {
|
|
47988
|
+
const siteId = toId4(siteValue, "site ID");
|
|
47856
47989
|
const accounts = await sipAccounts().find({
|
|
47857
47990
|
orgId: toId4(orgIdValue, "organization ID"),
|
|
47858
|
-
site:
|
|
47991
|
+
site: siteId,
|
|
47859
47992
|
status: { $ne: "disabled" }
|
|
47860
47993
|
}, {
|
|
47861
47994
|
projection: { user: 1, extension: 1, username: 1, status: 1, provisionedAt: 1 }
|
|
@@ -47863,9 +47996,10 @@ function useHidAmicoRepo() {
|
|
|
47863
47996
|
const userIds = accounts.map((account) => optionalObjectId2(account.user)).filter((value) => Boolean(value));
|
|
47864
47997
|
const users = userIds.length ? await db2().collection("users").find(
|
|
47865
47998
|
{ _id: { $in: userIds } },
|
|
47866
|
-
{ projection: { name: 1, email: 1 } }
|
|
47999
|
+
{ projection: { name: 1, email: 1, block: 1, level: 1, unitId: 1, unitName: 1 } }
|
|
47867
48000
|
).toArray() : [];
|
|
47868
48001
|
const userMap = new Map(users.map((user) => [String(user._id), user]));
|
|
48002
|
+
const unitLabels = await loadUnitLabels(siteId, userIds, userMap);
|
|
47869
48003
|
return accounts.map((account) => {
|
|
47870
48004
|
const user = userMap.get(String(account.user));
|
|
47871
48005
|
return {
|
|
@@ -47873,6 +48007,7 @@ function useHidAmicoRepo() {
|
|
|
47873
48007
|
userId: String(account.user),
|
|
47874
48008
|
name: String(user?.name || user?.email || ""),
|
|
47875
48009
|
email: String(user?.email || ""),
|
|
48010
|
+
unitLabel: unitLabels.get(String(account.user)) || "",
|
|
47876
48011
|
extension: String(account.extension || ""),
|
|
47877
48012
|
username: String(account.username || ""),
|
|
47878
48013
|
status: String(account.status || ""),
|
|
@@ -48370,6 +48505,7 @@ function useHidAmicoRepo() {
|
|
|
48370
48505
|
getById,
|
|
48371
48506
|
getByDeviceId,
|
|
48372
48507
|
findDuplicateByIdentity,
|
|
48508
|
+
listLiveReaderIdentities,
|
|
48373
48509
|
getByCallbackTokenHash,
|
|
48374
48510
|
updateById,
|
|
48375
48511
|
markDeleted,
|
|
@@ -48591,6 +48727,38 @@ function buildIdentifierPayload(methods) {
|
|
|
48591
48727
|
multi_factor_authentication: "0"
|
|
48592
48728
|
};
|
|
48593
48729
|
}
|
|
48730
|
+
function readIdentifierFlag(value) {
|
|
48731
|
+
if (value === true)
|
|
48732
|
+
return "1";
|
|
48733
|
+
if (value === false)
|
|
48734
|
+
return "0";
|
|
48735
|
+
return String(value ?? "").trim();
|
|
48736
|
+
}
|
|
48737
|
+
function driftedIdentifierFields(methods, liveIdentifier) {
|
|
48738
|
+
const expected = buildIdentifierPayload(methods);
|
|
48739
|
+
const live = liveIdentifier && typeof liveIdentifier === "object" ? liveIdentifier : {};
|
|
48740
|
+
const drifted = [];
|
|
48741
|
+
let comparable = 0;
|
|
48742
|
+
for (const [field, value] of Object.entries(expected)) {
|
|
48743
|
+
const reported = live[field];
|
|
48744
|
+
if (reported === void 0 || reported === null)
|
|
48745
|
+
continue;
|
|
48746
|
+
comparable += 1;
|
|
48747
|
+
if (readIdentifierFlag(reported) !== value)
|
|
48748
|
+
drifted.push(field);
|
|
48749
|
+
}
|
|
48750
|
+
return { comparable, drifted };
|
|
48751
|
+
}
|
|
48752
|
+
function identificationDriftCheckDue(checkedAt, throttleMs, now = Date.now()) {
|
|
48753
|
+
if (checkedAt === null || checkedAt === void 0 || checkedAt === "")
|
|
48754
|
+
return true;
|
|
48755
|
+
const last = checkedAt instanceof Date ? checkedAt.getTime() : new Date(String(checkedAt)).getTime();
|
|
48756
|
+
if (!Number.isFinite(last))
|
|
48757
|
+
return true;
|
|
48758
|
+
if (last > now)
|
|
48759
|
+
return true;
|
|
48760
|
+
return now - last >= throttleMs;
|
|
48761
|
+
}
|
|
48594
48762
|
|
|
48595
48763
|
// src/utils/hid-json.util.ts
|
|
48596
48764
|
var import_node_crypto5 = __toESM(require("crypto"));
|
|
@@ -51009,6 +51177,93 @@ function useHidAmicoService() {
|
|
|
51009
51177
|
await client.logout();
|
|
51010
51178
|
}
|
|
51011
51179
|
}
|
|
51180
|
+
const IDENTIFICATION_DRIFT_THROTTLE_MS = 15 * 60 * 1e3;
|
|
51181
|
+
async function reconcileIdentificationMethods(readerId) {
|
|
51182
|
+
const id = String(readerId);
|
|
51183
|
+
let reader = null;
|
|
51184
|
+
try {
|
|
51185
|
+
reader = await repo.getById(id, { includePassword: true });
|
|
51186
|
+
if (!reader)
|
|
51187
|
+
return { readerId: id, status: "skipped", reason: "not_found" };
|
|
51188
|
+
const stored = reader.identificationMethods;
|
|
51189
|
+
if (!stored) {
|
|
51190
|
+
return { readerId: id, status: "skipped", reason: "not_configured" };
|
|
51191
|
+
}
|
|
51192
|
+
const duplicate = findDuplicateReaderRecord(
|
|
51193
|
+
await repo.listLiveReaderIdentities(),
|
|
51194
|
+
{ _id: reader._id, deviceId: reader.deviceId, serial: reader.serial, baseUrl: reader.baseUrl }
|
|
51195
|
+
);
|
|
51196
|
+
if (duplicate) {
|
|
51197
|
+
await repo.addEvent({
|
|
51198
|
+
reader: id,
|
|
51199
|
+
site: String(reader.site || ""),
|
|
51200
|
+
type: "reader_duplicate_registration_detected",
|
|
51201
|
+
status: "failed",
|
|
51202
|
+
payload: {
|
|
51203
|
+
duplicateReaderId: String(duplicate._id ?? ""),
|
|
51204
|
+
duplicateReaderName: String(duplicate.name ?? ""),
|
|
51205
|
+
duplicateSiteId: String(duplicate.site ?? "")
|
|
51206
|
+
}
|
|
51207
|
+
});
|
|
51208
|
+
return {
|
|
51209
|
+
readerId: id,
|
|
51210
|
+
status: "skipped",
|
|
51211
|
+
reason: "duplicate_reader",
|
|
51212
|
+
duplicateReaderId: String(duplicate._id ?? "")
|
|
51213
|
+
};
|
|
51214
|
+
}
|
|
51215
|
+
let liveIdentifier = {};
|
|
51216
|
+
const client = new HidAmicoClient(reader);
|
|
51217
|
+
try {
|
|
51218
|
+
await client.login();
|
|
51219
|
+
const live = await client.getConfiguration({
|
|
51220
|
+
identifier: Object.keys(buildIdentifierPayload(stored))
|
|
51221
|
+
});
|
|
51222
|
+
const liveRoot = isUnknownRecord2(live) ? live : {};
|
|
51223
|
+
liveIdentifier = isUnknownRecord2(liveRoot.identifier) ? liveRoot.identifier : {};
|
|
51224
|
+
} finally {
|
|
51225
|
+
await client.logout();
|
|
51226
|
+
}
|
|
51227
|
+
const { comparable, drifted } = driftedIdentifierFields(stored, liveIdentifier);
|
|
51228
|
+
if (!comparable) {
|
|
51229
|
+
throw new import_node_server_utils143.BadRequestError("The HID reader did not report its identification settings.");
|
|
51230
|
+
}
|
|
51231
|
+
if (!drifted.length) {
|
|
51232
|
+
const checkedAt2 = /* @__PURE__ */ new Date();
|
|
51233
|
+
await repo.updateById(id, {
|
|
51234
|
+
identificationMethodsCheckedAt: checkedAt2,
|
|
51235
|
+
// A confirmed match IS a confirmation, so both move.
|
|
51236
|
+
identificationMethodsAppliedAt: checkedAt2
|
|
51237
|
+
});
|
|
51238
|
+
return { readerId: id, status: "in_sync", drifted: [], checkedAt: checkedAt2 };
|
|
51239
|
+
}
|
|
51240
|
+
const before = {};
|
|
51241
|
+
for (const field of drifted)
|
|
51242
|
+
before[field] = liveIdentifier[field];
|
|
51243
|
+
await setReaderIdentificationMethods(id, stored);
|
|
51244
|
+
const checkedAt = /* @__PURE__ */ new Date();
|
|
51245
|
+
await repo.updateById(id, { identificationMethodsCheckedAt: checkedAt });
|
|
51246
|
+
await repo.addEvent({
|
|
51247
|
+
reader: id,
|
|
51248
|
+
site: String(reader.site || ""),
|
|
51249
|
+
type: "reader_identification_methods_drift_corrected",
|
|
51250
|
+
status: "processed",
|
|
51251
|
+
payload: { before, after: stored, fields: drifted }
|
|
51252
|
+
});
|
|
51253
|
+
return { readerId: id, status: "drift_corrected", drifted, checkedAt };
|
|
51254
|
+
} catch (error) {
|
|
51255
|
+
const message = getErrorMessage2(error);
|
|
51256
|
+
import_node_server_utils143.logger.log({ level: "error", message: `HID drift check failed for ${id}: ${message}` });
|
|
51257
|
+
await repo.addEvent({
|
|
51258
|
+
reader: id,
|
|
51259
|
+
site: String(reader?.site || ""),
|
|
51260
|
+
type: "reader_identification_methods_drift_check_failed",
|
|
51261
|
+
status: "failed",
|
|
51262
|
+
payload: { message }
|
|
51263
|
+
}).catch(() => void 0);
|
|
51264
|
+
return { readerId: id, status: "failed", message };
|
|
51265
|
+
}
|
|
51266
|
+
}
|
|
51012
51267
|
async function listReaders(value) {
|
|
51013
51268
|
return repo.list(value);
|
|
51014
51269
|
}
|
|
@@ -51062,6 +51317,7 @@ function useHidAmicoService() {
|
|
|
51062
51317
|
async function testReader(id) {
|
|
51063
51318
|
const reader = await repo.getById(id, { includePassword: true });
|
|
51064
51319
|
const client = new HidAmicoClient(reader);
|
|
51320
|
+
let result;
|
|
51065
51321
|
try {
|
|
51066
51322
|
await client.login();
|
|
51067
51323
|
const [valid, systemResponse] = await Promise.all([
|
|
@@ -51102,7 +51358,7 @@ function useHidAmicoService() {
|
|
|
51102
51358
|
capabilities
|
|
51103
51359
|
}
|
|
51104
51360
|
});
|
|
51105
|
-
|
|
51361
|
+
result = {
|
|
51106
51362
|
valid,
|
|
51107
51363
|
message: firmwareVersion ? `HID Amico connection test succeeded. Firmware ${firmwareVersion}.` : "HID Amico connection test succeeded.",
|
|
51108
51364
|
...firmwareVersion ? { firmwareVersion } : {},
|
|
@@ -51122,6 +51378,8 @@ function useHidAmicoService() {
|
|
|
51122
51378
|
} finally {
|
|
51123
51379
|
await client.logout();
|
|
51124
51380
|
}
|
|
51381
|
+
const identificationMethods = await reconcileIdentificationMethods(id);
|
|
51382
|
+
return { ...result, identificationMethods };
|
|
51125
51383
|
}
|
|
51126
51384
|
async function syncReader(id, payload) {
|
|
51127
51385
|
const reader = await getActiveReader(id);
|
|
@@ -51210,6 +51468,12 @@ function useHidAmicoService() {
|
|
|
51210
51468
|
throw new import_node_server_utils143.BadRequestError("The HID callback device ID does not match the registered reader.");
|
|
51211
51469
|
}
|
|
51212
51470
|
const readerId = String(reader._id);
|
|
51471
|
+
if (identificationDriftCheckDue(
|
|
51472
|
+
reader.identificationMethodsCheckedAt,
|
|
51473
|
+
IDENTIFICATION_DRIFT_THROTTLE_MS
|
|
51474
|
+
)) {
|
|
51475
|
+
void reconcileIdentificationMethods(readerId).catch(() => void 0);
|
|
51476
|
+
}
|
|
51213
51477
|
const objectChanges = Array.isArray(payload.object_changes) ? payload.object_changes : [];
|
|
51214
51478
|
const accessLogChange = objectChanges.find((change) => isUnknownRecord2(change) && change.object === "access_logs" && change.type !== "deleted" && isUnknownRecord2(change.values));
|
|
51215
51479
|
const accessLogValues = isUnknownRecord2(accessLogChange) && isUnknownRecord2(accessLogChange.values) ? accessLogChange.values : {};
|
|
@@ -53810,6 +54074,7 @@ function useHidAmicoService() {
|
|
|
53810
54074
|
setReaderMonitor,
|
|
53811
54075
|
setOperatingMode,
|
|
53812
54076
|
setReaderIdentificationMethods,
|
|
54077
|
+
reconcileIdentificationMethods,
|
|
53813
54078
|
receiveNotification,
|
|
53814
54079
|
listLogs,
|
|
53815
54080
|
listIdentities,
|
|
@@ -98596,6 +98861,21 @@ function useHidAmicoController() {
|
|
|
98596
98861
|
next(error);
|
|
98597
98862
|
}
|
|
98598
98863
|
}
|
|
98864
|
+
async function reconcileReaderIdentificationMethods(req, res, next) {
|
|
98865
|
+
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
98866
|
+
if (params.error) {
|
|
98867
|
+
next(new import_node_server_utils313.BadRequestError(params.error.message));
|
|
98868
|
+
return;
|
|
98869
|
+
}
|
|
98870
|
+
try {
|
|
98871
|
+
await authorizeReaderAccess(req, params.value.readerId, "manage");
|
|
98872
|
+
res.json({
|
|
98873
|
+
data: await service.reconcileIdentificationMethods(params.value.readerId)
|
|
98874
|
+
});
|
|
98875
|
+
} catch (error) {
|
|
98876
|
+
next(error);
|
|
98877
|
+
}
|
|
98878
|
+
}
|
|
98599
98879
|
async function setOperatingMode(req, res, next) {
|
|
98600
98880
|
const params = schemaHidAmicoReaderIdParams.validate(req.params);
|
|
98601
98881
|
const body = schemaHidAmicoOperatingMode.validate(req.body);
|
|
@@ -99251,6 +99531,7 @@ function useHidAmicoController() {
|
|
|
99251
99531
|
configureReaderIntegration,
|
|
99252
99532
|
setReaderMonitor,
|
|
99253
99533
|
setReaderIdentificationMethods,
|
|
99534
|
+
reconcileReaderIdentificationMethods,
|
|
99254
99535
|
setOperatingMode,
|
|
99255
99536
|
listLogs,
|
|
99256
99537
|
listIdentities,
|