@7365admin1/core 3.92.1-staging.359 → 3.92.1-staging.360
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/index.d.ts +5 -0
- package/dist/index.js +96 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/scripts/hid-duplicate-reader-report.mjs +89 -0
- package/test/hid-duplicate-registration.test.mjs +220 -0
package/dist/index.d.ts
CHANGED
|
@@ -16439,6 +16439,11 @@ declare function useHidAmicoRepo(): {
|
|
|
16439
16439
|
getByDeviceId: (deviceIdValue: string | number, options?: {
|
|
16440
16440
|
includePassword?: boolean;
|
|
16441
16441
|
}) => Promise<mongodb.WithId<bson.Document> | PublicHidReader>;
|
|
16442
|
+
findDuplicateByIdentity: (value: {
|
|
16443
|
+
deviceId?: unknown;
|
|
16444
|
+
serial?: unknown;
|
|
16445
|
+
excludeId?: string | ObjectId;
|
|
16446
|
+
}) => Promise<PublicHidReader | null>;
|
|
16442
16447
|
getByCallbackTokenHash: {
|
|
16443
16448
|
(callbackTokenHash: string, options: {
|
|
16444
16449
|
includeCallbackTokenHash: true;
|
package/dist/index.js
CHANGED
|
@@ -47083,6 +47083,30 @@ function hidFirmwareAtLeast(value, required) {
|
|
|
47083
47083
|
return true;
|
|
47084
47084
|
}
|
|
47085
47085
|
|
|
47086
|
+
// src/utils/hid-duplicate.util.ts
|
|
47087
|
+
var HID_LIVE_READER_STATUSES = ["active", "offline"];
|
|
47088
|
+
function hidIdentityConditions(discovered) {
|
|
47089
|
+
const conditions = [];
|
|
47090
|
+
const deviceId = readIdentityValue(discovered.deviceId);
|
|
47091
|
+
const serial = readIdentityValue(discovered.serial);
|
|
47092
|
+
if (deviceId)
|
|
47093
|
+
conditions.push({ deviceId });
|
|
47094
|
+
if (serial)
|
|
47095
|
+
conditions.push({ serial });
|
|
47096
|
+
return conditions;
|
|
47097
|
+
}
|
|
47098
|
+
function duplicateReaderMessage(readerName, siteName) {
|
|
47099
|
+
const reader = readIdentityValue(readerName) || "another reader";
|
|
47100
|
+
const site = readIdentityValue(siteName);
|
|
47101
|
+
const where = site ? ` at ${site}` : "";
|
|
47102
|
+
return `This HID reader is already registered as '${reader}'${where}. Delete or deactivate that reader before registering it again.`;
|
|
47103
|
+
}
|
|
47104
|
+
function readIdentityValue(value) {
|
|
47105
|
+
if (value === null || value === void 0)
|
|
47106
|
+
return "";
|
|
47107
|
+
return String(value).trim();
|
|
47108
|
+
}
|
|
47109
|
+
|
|
47086
47110
|
// src/repositories/hid-amico.repo.ts
|
|
47087
47111
|
function isUnknownRecord(value) {
|
|
47088
47112
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -47269,6 +47293,20 @@ function useHidAmicoRepo() {
|
|
|
47269
47293
|
}
|
|
47270
47294
|
return options.includePassword ? reader : hideSecret(reader);
|
|
47271
47295
|
}
|
|
47296
|
+
async function findDuplicateByIdentity(value) {
|
|
47297
|
+
const conditions = hidIdentityConditions(value);
|
|
47298
|
+
if (!conditions.length)
|
|
47299
|
+
return null;
|
|
47300
|
+
const query2 = {
|
|
47301
|
+
status: { $in: [...HID_LIVE_READER_STATUSES] },
|
|
47302
|
+
$or: conditions
|
|
47303
|
+
};
|
|
47304
|
+
if (value.excludeId) {
|
|
47305
|
+
query2._id = { $ne: toId4(value.excludeId, "reader ID") };
|
|
47306
|
+
}
|
|
47307
|
+
const reader = await readers().findOne(query2);
|
|
47308
|
+
return reader ? hideSecret(reader) : null;
|
|
47309
|
+
}
|
|
47272
47310
|
async function getByCallbackTokenHash(callbackTokenHash, options = {}) {
|
|
47273
47311
|
const reader = await readers().findOne({
|
|
47274
47312
|
callbackTokenHash,
|
|
@@ -48123,6 +48161,7 @@ function useHidAmicoRepo() {
|
|
|
48123
48161
|
list,
|
|
48124
48162
|
getById,
|
|
48125
48163
|
getByDeviceId,
|
|
48164
|
+
findDuplicateByIdentity,
|
|
48126
48165
|
getByCallbackTokenHash,
|
|
48127
48166
|
updateById,
|
|
48128
48167
|
markDeleted,
|
|
@@ -50407,8 +50446,35 @@ function useHidAmicoService() {
|
|
|
50407
50446
|
await client.logout();
|
|
50408
50447
|
}
|
|
50409
50448
|
}
|
|
50449
|
+
async function assertReaderNotRegistered(discovered, attempt) {
|
|
50450
|
+
const existing = await repo.findDuplicateByIdentity({
|
|
50451
|
+
deviceId: discovered.deviceId,
|
|
50452
|
+
serial: discovered.serial,
|
|
50453
|
+
excludeId: attempt.excludeId
|
|
50454
|
+
});
|
|
50455
|
+
if (!existing)
|
|
50456
|
+
return;
|
|
50457
|
+
let siteName = "";
|
|
50458
|
+
try {
|
|
50459
|
+
const site = await siteRepo.getSiteById(String(existing.site || ""));
|
|
50460
|
+
siteName = String(site?.name || "");
|
|
50461
|
+
} catch {
|
|
50462
|
+
}
|
|
50463
|
+
await repo.addEvent({
|
|
50464
|
+
reader: String(existing._id),
|
|
50465
|
+
site: String(existing.site || ""),
|
|
50466
|
+
type: "reader_duplicate_registration_blocked",
|
|
50467
|
+
status: "processed",
|
|
50468
|
+
payload: {
|
|
50469
|
+
attemptedBaseUrl: String(attempt.baseUrl || ""),
|
|
50470
|
+
siteId: String(attempt.site || "")
|
|
50471
|
+
}
|
|
50472
|
+
});
|
|
50473
|
+
throw new import_node_server_utils143.BadRequestError(duplicateReaderMessage(existing.name, siteName));
|
|
50474
|
+
}
|
|
50410
50475
|
async function createReader(value) {
|
|
50411
50476
|
const discovered = await discoverReader(value);
|
|
50477
|
+
await assertReaderNotRegistered(discovered, { baseUrl: value.baseUrl, site: value.site });
|
|
50412
50478
|
const portal = discovered.portals.find((candidate) => candidate.id === Number(value.portalId));
|
|
50413
50479
|
if (!portal) {
|
|
50414
50480
|
throw new import_node_server_utils143.BadRequestError("Select a portal returned by the connected HID reader.");
|
|
@@ -50503,13 +50569,41 @@ function useHidAmicoService() {
|
|
|
50503
50569
|
delete payload.password;
|
|
50504
50570
|
}
|
|
50505
50571
|
let current = null;
|
|
50506
|
-
if (payload.readerModel || payload.portalId) {
|
|
50572
|
+
if (payload.readerModel || payload.portalId || payload.baseUrl) {
|
|
50507
50573
|
current = await repo.getById(id, { includePassword: true });
|
|
50508
50574
|
}
|
|
50575
|
+
if (payload.baseUrl && current && payload.baseUrl !== current.baseUrl) {
|
|
50576
|
+
const rediscovered = await discoverReader({
|
|
50577
|
+
baseUrl: payload.baseUrl,
|
|
50578
|
+
username: String(payload.username || current.username || ""),
|
|
50579
|
+
password: payload.password ? String(value.password || "") : decryptSecret(String(current.password || "")),
|
|
50580
|
+
readerModel: payload.readerModel || current.readerModel
|
|
50581
|
+
});
|
|
50582
|
+
const previousDeviceId = String(current.deviceId || "").trim();
|
|
50583
|
+
const nextDeviceId = String(rediscovered.deviceId || "").trim();
|
|
50584
|
+
if (previousDeviceId && nextDeviceId !== previousDeviceId) {
|
|
50585
|
+
await assertReaderNotRegistered(rediscovered, {
|
|
50586
|
+
baseUrl: payload.baseUrl,
|
|
50587
|
+
site: current.site,
|
|
50588
|
+
excludeId: id
|
|
50589
|
+
});
|
|
50590
|
+
await repo.addEvent({
|
|
50591
|
+
reader: id,
|
|
50592
|
+
site: String(current.site || ""),
|
|
50593
|
+
type: "reader_device_identity_changed",
|
|
50594
|
+
status: "processed",
|
|
50595
|
+
payload: { from: previousDeviceId, to: nextDeviceId }
|
|
50596
|
+
});
|
|
50597
|
+
}
|
|
50598
|
+
payload.deviceId = rediscovered.deviceId;
|
|
50599
|
+
payload.serial = rediscovered.serial;
|
|
50600
|
+
payload.firmwareVersion = rediscovered.firmwareVersion;
|
|
50601
|
+
payload.capabilities = rediscovered.capabilities;
|
|
50602
|
+
}
|
|
50509
50603
|
if (payload.readerModel && current) {
|
|
50510
50604
|
payload.capabilities = getReaderCapabilities(
|
|
50511
50605
|
payload.readerModel,
|
|
50512
|
-
String(current.firmwareVersion || "")
|
|
50606
|
+
String(payload.firmwareVersion || current.firmwareVersion || "")
|
|
50513
50607
|
);
|
|
50514
50608
|
}
|
|
50515
50609
|
if (payload.portalId && current) {
|