@7365admin1/core 3.143.0 → 3.144.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 +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +455 -357
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +457 -359
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/spaces-object.test.mjs +55 -0
package/dist/index.js
CHANGED
|
@@ -6315,11 +6315,11 @@ function useAuthService() {
|
|
|
6315
6315
|
"Refresh token already used. Please log in again."
|
|
6316
6316
|
);
|
|
6317
6317
|
}
|
|
6318
|
-
const
|
|
6319
|
-
if (!
|
|
6318
|
+
const client3 = import_node_server_utils19.useAtlas.getClient();
|
|
6319
|
+
if (!client3) {
|
|
6320
6320
|
throw new import_node_server_utils19.InternalServerError("Unable to connect to server.");
|
|
6321
6321
|
}
|
|
6322
|
-
const dbSession =
|
|
6322
|
+
const dbSession = client3.startSession();
|
|
6323
6323
|
let newRefreshToken;
|
|
6324
6324
|
try {
|
|
6325
6325
|
dbSession.startTransaction();
|
|
@@ -9376,7 +9376,7 @@ var SP_INVITE_TYPES = [
|
|
|
9376
9376
|
function escapeRegex(value) {
|
|
9377
9377
|
return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9378
9378
|
}
|
|
9379
|
-
function relationshipMatch(org, relationship,
|
|
9379
|
+
function relationshipMatch(org, relationship, client3) {
|
|
9380
9380
|
const self = [org, String(org)];
|
|
9381
9381
|
const match = {};
|
|
9382
9382
|
const and = [];
|
|
@@ -9385,9 +9385,9 @@ function relationshipMatch(org, relationship, client2) {
|
|
|
9385
9385
|
} else if (relationship === "served") {
|
|
9386
9386
|
and.push({ siteOrg: { $nin: [...self, null, ""] } });
|
|
9387
9387
|
}
|
|
9388
|
-
if (
|
|
9388
|
+
if (client3) {
|
|
9389
9389
|
and.push(
|
|
9390
|
-
{ siteOrg: { $in: [
|
|
9390
|
+
{ siteOrg: { $in: [client3, String(client3)] } },
|
|
9391
9391
|
{ siteOrg: { $nin: self } }
|
|
9392
9392
|
);
|
|
9393
9393
|
}
|
|
@@ -9550,7 +9550,7 @@ function useCustomerSiteRepo() {
|
|
|
9550
9550
|
status = "active",
|
|
9551
9551
|
siteScope = null,
|
|
9552
9552
|
relationship = "",
|
|
9553
|
-
client:
|
|
9553
|
+
client: client3 = "",
|
|
9554
9554
|
category = ""
|
|
9555
9555
|
}, session) {
|
|
9556
9556
|
page2 = page2 > 0 ? page2 - 1 : 0;
|
|
@@ -9564,9 +9564,9 @@ function useCustomerSiteRepo() {
|
|
|
9564
9564
|
status
|
|
9565
9565
|
};
|
|
9566
9566
|
let clientId = null;
|
|
9567
|
-
if (
|
|
9567
|
+
if (client3) {
|
|
9568
9568
|
try {
|
|
9569
|
-
clientId = new import_mongodb26.ObjectId(
|
|
9569
|
+
clientId = new import_mongodb26.ObjectId(client3);
|
|
9570
9570
|
} catch (error) {
|
|
9571
9571
|
throw new import_node_server_utils28.BadRequestError("Invalid client ID format.");
|
|
9572
9572
|
}
|
|
@@ -9589,8 +9589,8 @@ function useCustomerSiteRepo() {
|
|
|
9589
9589
|
}
|
|
9590
9590
|
if (relationship)
|
|
9591
9591
|
cacheOptions.relationship = relationship;
|
|
9592
|
-
if (
|
|
9593
|
-
cacheOptions.client =
|
|
9592
|
+
if (client3)
|
|
9593
|
+
cacheOptions.client = client3;
|
|
9594
9594
|
if (category)
|
|
9595
9595
|
cacheOptions.category = category;
|
|
9596
9596
|
const cacheKey = (0, import_node_server_utils28.makeCacheKey)(namespace_collection3, cacheOptions);
|
|
@@ -19130,6 +19130,76 @@ function useVehicleRepo() {
|
|
|
19130
19130
|
};
|
|
19131
19131
|
}
|
|
19132
19132
|
|
|
19133
|
+
// src/services/spaces-object.service.ts
|
|
19134
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
19135
|
+
|
|
19136
|
+
// src/utils/spaces-object.util.ts
|
|
19137
|
+
function spacesUploadAcl(key2, setting = process.env.SPACES_PRIVATE_PREFIXES ?? "") {
|
|
19138
|
+
const prefixes = String(setting).split(",").map((p) => p.trim()).filter(Boolean);
|
|
19139
|
+
if (prefixes.includes("*"))
|
|
19140
|
+
return "private";
|
|
19141
|
+
return prefixes.some((p) => String(key2).startsWith(p)) ? "private" : "public-read";
|
|
19142
|
+
}
|
|
19143
|
+
var KEY = /^(?:[A-Za-z0-9_-]{1,64}\/){0,4}[a-f0-9]{24}$/;
|
|
19144
|
+
function isServableObjectKey(key2) {
|
|
19145
|
+
return typeof key2 === "string" && KEY.test(key2);
|
|
19146
|
+
}
|
|
19147
|
+
function anprSiteOfKey(key2) {
|
|
19148
|
+
const m = /^anpr\/([a-f0-9]{24})\//.exec(key2);
|
|
19149
|
+
return m ? m[1] : null;
|
|
19150
|
+
}
|
|
19151
|
+
var INLINE_TYPES = /^(image\/(jpeg|png|gif|webp|heic|heif|bmp)|application\/pdf|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|webm|ogg))$/;
|
|
19152
|
+
function servedObjectHeaders(contentType) {
|
|
19153
|
+
const type = String(contentType ?? "").split(";")[0].trim().toLowerCase();
|
|
19154
|
+
const inline = INLINE_TYPES.test(type);
|
|
19155
|
+
return {
|
|
19156
|
+
"Content-Type": inline ? type : "application/octet-stream",
|
|
19157
|
+
"Content-Disposition": inline ? "inline" : "attachment",
|
|
19158
|
+
"X-Content-Type-Options": "nosniff",
|
|
19159
|
+
"Content-Security-Policy": "default-src 'none'; sandbox",
|
|
19160
|
+
"Cache-Control": "private, max-age=300"
|
|
19161
|
+
};
|
|
19162
|
+
}
|
|
19163
|
+
|
|
19164
|
+
// src/services/spaces-object.service.ts
|
|
19165
|
+
var client = null;
|
|
19166
|
+
function s3() {
|
|
19167
|
+
if (!client) {
|
|
19168
|
+
client = new import_client_s3.S3Client({
|
|
19169
|
+
endpoint: SPACES_ENDPOINT,
|
|
19170
|
+
region: SPACES_REGION,
|
|
19171
|
+
credentials: { accessKeyId: SPACES_ACCESS_KEY, secretAccessKey: SPACES_SECRET_KEY },
|
|
19172
|
+
forcePathStyle: true
|
|
19173
|
+
});
|
|
19174
|
+
}
|
|
19175
|
+
return client;
|
|
19176
|
+
}
|
|
19177
|
+
async function putSpacesObject({
|
|
19178
|
+
key: key2,
|
|
19179
|
+
body,
|
|
19180
|
+
contentType
|
|
19181
|
+
}) {
|
|
19182
|
+
await s3().send(
|
|
19183
|
+
new import_client_s3.PutObjectCommand({
|
|
19184
|
+
Bucket: SPACES_BUCKET,
|
|
19185
|
+
Key: key2,
|
|
19186
|
+
Body: body,
|
|
19187
|
+
ACL: spacesUploadAcl(key2),
|
|
19188
|
+
ContentType: contentType,
|
|
19189
|
+
ContentLength: body.length
|
|
19190
|
+
})
|
|
19191
|
+
);
|
|
19192
|
+
return "Successfully uploaded file.";
|
|
19193
|
+
}
|
|
19194
|
+
async function getSpacesObject(key2) {
|
|
19195
|
+
const res = await s3().send(new import_client_s3.GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 }));
|
|
19196
|
+
return {
|
|
19197
|
+
body: res.Body,
|
|
19198
|
+
contentType: res.ContentType,
|
|
19199
|
+
contentLength: res.ContentLength
|
|
19200
|
+
};
|
|
19201
|
+
}
|
|
19202
|
+
|
|
19133
19203
|
// src/repositories/file.repo.ts
|
|
19134
19204
|
var import_node_server_utils52 = require("@7365admin1/node-server-utils");
|
|
19135
19205
|
|
|
@@ -19309,7 +19379,7 @@ function useFileService() {
|
|
|
19309
19379
|
deleteFileById,
|
|
19310
19380
|
getAllDraftedFiles
|
|
19311
19381
|
} = useFileRepo();
|
|
19312
|
-
const
|
|
19382
|
+
const s33 = new import_node_server_utils53.useS3({
|
|
19313
19383
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
19314
19384
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
19315
19385
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -19328,7 +19398,7 @@ function useFileService() {
|
|
|
19328
19398
|
};
|
|
19329
19399
|
try {
|
|
19330
19400
|
const id = await _createFile(file, session);
|
|
19331
|
-
await
|
|
19401
|
+
await putSpacesObject({
|
|
19332
19402
|
key: `${folder}/${id}`,
|
|
19333
19403
|
body: value.buffer,
|
|
19334
19404
|
contentType: value.mimetype
|
|
@@ -19347,7 +19417,7 @@ function useFileService() {
|
|
|
19347
19417
|
session?.startTransaction();
|
|
19348
19418
|
try {
|
|
19349
19419
|
await deleteFileById(id, session);
|
|
19350
|
-
await
|
|
19420
|
+
await s33.deleteObject(id);
|
|
19351
19421
|
await session?.commitTransaction();
|
|
19352
19422
|
return "File deleted successfully.";
|
|
19353
19423
|
} catch (error) {
|
|
@@ -27297,7 +27367,7 @@ function useUserService() {
|
|
|
27297
27367
|
session?.endSession();
|
|
27298
27368
|
}
|
|
27299
27369
|
}
|
|
27300
|
-
const
|
|
27370
|
+
const s33 = new import_node_server_utils64.useS3({
|
|
27301
27371
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
27302
27372
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
27303
27373
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -27318,14 +27388,14 @@ function useUserService() {
|
|
|
27318
27388
|
};
|
|
27319
27389
|
try {
|
|
27320
27390
|
const id = await createFile(_file, session);
|
|
27321
|
-
await
|
|
27391
|
+
await putSpacesObject({
|
|
27322
27392
|
key: id,
|
|
27323
27393
|
body: file.buffer,
|
|
27324
27394
|
contentType: file.mimetype
|
|
27325
27395
|
});
|
|
27326
27396
|
if (previousProfile) {
|
|
27327
27397
|
await deleteFileById(previousProfile, session);
|
|
27328
|
-
await
|
|
27398
|
+
await s33.deleteObject(previousProfile);
|
|
27329
27399
|
}
|
|
27330
27400
|
await _updateUserFieldById(
|
|
27331
27401
|
{ _id: user, field: "profile", value: id },
|
|
@@ -31429,10 +31499,38 @@ function useFileController() {
|
|
|
31429
31499
|
next(error2);
|
|
31430
31500
|
}
|
|
31431
31501
|
}
|
|
31502
|
+
async function viewObject(req, res, next) {
|
|
31503
|
+
const key2 = String(req.params?.[0] ?? "");
|
|
31504
|
+
if (!isServableObjectKey(key2)) {
|
|
31505
|
+
res.status(404).json({ message: "File not found." });
|
|
31506
|
+
return;
|
|
31507
|
+
}
|
|
31508
|
+
try {
|
|
31509
|
+
const site = anprSiteOfKey(key2);
|
|
31510
|
+
if (site)
|
|
31511
|
+
await requireSiteReach(req, site);
|
|
31512
|
+
const object = await getSpacesObject(key2);
|
|
31513
|
+
res.set(servedObjectHeaders(object.contentType));
|
|
31514
|
+
if (object.contentLength)
|
|
31515
|
+
res.set("Content-Length", String(object.contentLength));
|
|
31516
|
+
object.body.pipe(res);
|
|
31517
|
+
return;
|
|
31518
|
+
} catch (error) {
|
|
31519
|
+
const status = error?.$metadata?.httpStatusCode ?? error?.statusCode ?? error?.status;
|
|
31520
|
+
if (status === 404 || status === 403 || error?.name === "NoSuchKey" || error?.name === "NotFoundError") {
|
|
31521
|
+
res.status(404).json({ message: "File not found." });
|
|
31522
|
+
return;
|
|
31523
|
+
}
|
|
31524
|
+
import_node_server_utils78.logger.log({ level: "error", message: error?.message });
|
|
31525
|
+
next(error);
|
|
31526
|
+
return;
|
|
31527
|
+
}
|
|
31528
|
+
}
|
|
31432
31529
|
return {
|
|
31433
31530
|
upload,
|
|
31434
31531
|
deleteFile,
|
|
31435
|
-
getFileById
|
|
31532
|
+
getFileById,
|
|
31533
|
+
viewObject
|
|
31436
31534
|
};
|
|
31437
31535
|
}
|
|
31438
31536
|
|
|
@@ -37592,8 +37690,8 @@ function useServiceProviderController() {
|
|
|
37592
37690
|
if (siteId)
|
|
37593
37691
|
await requireSiteReach(req, siteId);
|
|
37594
37692
|
const engagements = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId;
|
|
37595
|
-
const
|
|
37596
|
-
const data =
|
|
37693
|
+
const client3 = engagements ? await isSiteClient(req, siteId) : false;
|
|
37694
|
+
const data = client3 ? await _getServiceProvidersForSite({ search, page: page2, limit, siteId }) : engagements ? (
|
|
37597
37695
|
// A provider's own Service Providers page: the subcontractors it
|
|
37598
37696
|
// brought onto this site, never the client's other contractors,
|
|
37599
37697
|
// plus the stored rows it already saw here.
|
|
@@ -47255,7 +47353,7 @@ function useCustomerSiteController() {
|
|
|
47255
47353
|
const org = req.query.org ?? "";
|
|
47256
47354
|
const status = req.query.status ?? "active";
|
|
47257
47355
|
const relationship = req.query.relationship || "";
|
|
47258
|
-
const
|
|
47356
|
+
const client3 = req.query.client || "";
|
|
47259
47357
|
const category = req.query.category || "";
|
|
47260
47358
|
const sortObj = {};
|
|
47261
47359
|
const sortFields = String(req.query.sort).split(",");
|
|
@@ -47278,7 +47376,7 @@ function useCustomerSiteController() {
|
|
|
47278
47376
|
status,
|
|
47279
47377
|
siteScope,
|
|
47280
47378
|
relationship,
|
|
47281
|
-
client:
|
|
47379
|
+
client: client3,
|
|
47282
47380
|
category
|
|
47283
47381
|
});
|
|
47284
47382
|
res.json(data);
|
|
@@ -48567,12 +48665,12 @@ function useAttendanceService() {
|
|
|
48567
48665
|
}
|
|
48568
48666
|
|
|
48569
48667
|
// src/services/attendance-photo.service.ts
|
|
48570
|
-
var
|
|
48668
|
+
var import_client_s32 = require("@aws-sdk/client-s3");
|
|
48571
48669
|
var ATTENDANCE_PHOTO_FOLDER = "attendance-private";
|
|
48572
|
-
var
|
|
48573
|
-
function
|
|
48574
|
-
if (!
|
|
48575
|
-
|
|
48670
|
+
var client2 = null;
|
|
48671
|
+
function s32() {
|
|
48672
|
+
if (!client2) {
|
|
48673
|
+
client2 = new import_client_s32.S3Client({
|
|
48576
48674
|
endpoint: SPACES_ENDPOINT,
|
|
48577
48675
|
region: SPACES_REGION,
|
|
48578
48676
|
credentials: {
|
|
@@ -48582,12 +48680,12 @@ function s3() {
|
|
|
48582
48680
|
forcePathStyle: true
|
|
48583
48681
|
});
|
|
48584
48682
|
}
|
|
48585
|
-
return
|
|
48683
|
+
return client2;
|
|
48586
48684
|
}
|
|
48587
48685
|
var s3AttendancePhotoStore = {
|
|
48588
48686
|
async put(key2, body, contentType) {
|
|
48589
|
-
await
|
|
48590
|
-
new
|
|
48687
|
+
await s32().send(
|
|
48688
|
+
new import_client_s32.PutObjectCommand({
|
|
48591
48689
|
Bucket: SPACES_BUCKET,
|
|
48592
48690
|
Key: key2,
|
|
48593
48691
|
Body: body,
|
|
@@ -48598,8 +48696,8 @@ var s3AttendancePhotoStore = {
|
|
|
48598
48696
|
);
|
|
48599
48697
|
},
|
|
48600
48698
|
async get(key2) {
|
|
48601
|
-
const res = await
|
|
48602
|
-
new
|
|
48699
|
+
const res = await s32().send(
|
|
48700
|
+
new import_client_s32.GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 })
|
|
48603
48701
|
);
|
|
48604
48702
|
const bytes = await res.Body.transformToByteArray();
|
|
48605
48703
|
return { body: Buffer.from(bytes), contentType: res.ContentType };
|
|
@@ -53160,20 +53258,20 @@ function createVisitorQrCredential(visitorId, readerId, qrValue) {
|
|
|
53160
53258
|
const token = qrValue || `VIS${import_crypto4.default.randomBytes(12).toString("hex").toUpperCase()}`;
|
|
53161
53259
|
return { credentialId, object: "qrcodes", value: token, qrValue: token };
|
|
53162
53260
|
}
|
|
53163
|
-
async function configureVisitorQrReader(
|
|
53261
|
+
async function configureVisitorQrReader(client3) {
|
|
53164
53262
|
const requestedConfiguration = {
|
|
53165
53263
|
general: ["online", "local_identification"],
|
|
53166
53264
|
face_id: ["qrcode_legacy_mode_enabled"],
|
|
53167
53265
|
identifier: ["qrcode_identification_enabled", "multi_factor_authentication"]
|
|
53168
53266
|
};
|
|
53169
|
-
const currentConfiguration = await
|
|
53267
|
+
const currentConfiguration = await client3.getConfiguration(requestedConfiguration);
|
|
53170
53268
|
const current = isUnknownRecord2(currentConfiguration) ? currentConfiguration : {};
|
|
53171
53269
|
const currentGeneral = isUnknownRecord2(current.general) ? current.general : {};
|
|
53172
53270
|
const currentFaceId = isUnknownRecord2(current.face_id) ? current.face_id : {};
|
|
53173
53271
|
const currentIdentifier = isUnknownRecord2(current.identifier) ? current.identifier : {};
|
|
53174
53272
|
let changed = false;
|
|
53175
53273
|
if (String(currentGeneral.online ?? "") !== "0" || String(currentGeneral.local_identification ?? "") !== "1") {
|
|
53176
|
-
await
|
|
53274
|
+
await client3.setConfiguration({
|
|
53177
53275
|
general: {
|
|
53178
53276
|
online: "0",
|
|
53179
53277
|
local_identification: "1"
|
|
@@ -53182,13 +53280,13 @@ async function configureVisitorQrReader(client2) {
|
|
|
53182
53280
|
changed = true;
|
|
53183
53281
|
}
|
|
53184
53282
|
if (String(currentFaceId.qrcode_legacy_mode_enabled ?? "") !== VISITOR_QR_FORMAT) {
|
|
53185
|
-
await
|
|
53283
|
+
await client3.setConfiguration({
|
|
53186
53284
|
face_id: { qrcode_legacy_mode_enabled: VISITOR_QR_FORMAT }
|
|
53187
53285
|
});
|
|
53188
53286
|
changed = true;
|
|
53189
53287
|
}
|
|
53190
53288
|
if (String(currentIdentifier.qrcode_identification_enabled ?? "") !== "1" || String(currentIdentifier.multi_factor_authentication ?? "") !== "0") {
|
|
53191
|
-
await
|
|
53289
|
+
await client3.setConfiguration({
|
|
53192
53290
|
identifier: {
|
|
53193
53291
|
qrcode_identification_enabled: "1",
|
|
53194
53292
|
// A visitor pass is a single QR credential. Leaving MFA enabled makes
|
|
@@ -53198,7 +53296,7 @@ async function configureVisitorQrReader(client2) {
|
|
|
53198
53296
|
});
|
|
53199
53297
|
changed = true;
|
|
53200
53298
|
}
|
|
53201
|
-
const configuration = await
|
|
53299
|
+
const configuration = await client3.getConfiguration(requestedConfiguration);
|
|
53202
53300
|
const savedConfiguration = isUnknownRecord2(configuration) ? configuration : {};
|
|
53203
53301
|
const general = isUnknownRecord2(savedConfiguration.general) ? savedConfiguration.general : {};
|
|
53204
53302
|
const faceId = isUnknownRecord2(savedConfiguration.face_id) ? savedConfiguration.face_id : {};
|
|
@@ -53210,7 +53308,7 @@ async function configureVisitorQrReader(client2) {
|
|
|
53210
53308
|
}
|
|
53211
53309
|
return changed;
|
|
53212
53310
|
}
|
|
53213
|
-
async function ensureVisitorAccessAuthorization(
|
|
53311
|
+
async function ensureVisitorAccessAuthorization(client3, readerId, reader, hidUserId, scope = "visitor") {
|
|
53214
53312
|
const accessLabel = scope === "visitor" ? "Visitor" : "Facial";
|
|
53215
53313
|
const accessRuleId = createStableHidId(`${scope}-access-rule:${readerId}`);
|
|
53216
53314
|
const timeZoneId = createStableHidId(`${scope}-time-zone:${readerId}`);
|
|
@@ -53220,25 +53318,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53220
53318
|
type: 1,
|
|
53221
53319
|
priority: 0
|
|
53222
53320
|
};
|
|
53223
|
-
const existingRuleResponse = await
|
|
53321
|
+
const existingRuleResponse = await client3.loadObjects({
|
|
53224
53322
|
object: "access_rules",
|
|
53225
53323
|
where: { access_rules: { id: accessRuleId } },
|
|
53226
53324
|
limit: 1,
|
|
53227
53325
|
offset: 0
|
|
53228
53326
|
});
|
|
53229
53327
|
if (getHidObjectRows(existingRuleResponse, "access_rules").length) {
|
|
53230
|
-
await
|
|
53328
|
+
await client3.modifyObjects({
|
|
53231
53329
|
object: "access_rules",
|
|
53232
53330
|
where: { access_rules: { id: accessRuleId } },
|
|
53233
53331
|
values: accessRuleValues
|
|
53234
53332
|
});
|
|
53235
53333
|
} else {
|
|
53236
|
-
await
|
|
53334
|
+
await client3.createObjects({
|
|
53237
53335
|
object: "access_rules",
|
|
53238
53336
|
values: [{ id: accessRuleId, ...accessRuleValues }]
|
|
53239
53337
|
});
|
|
53240
53338
|
}
|
|
53241
|
-
const verifiedAccessRuleResponse = await
|
|
53339
|
+
const verifiedAccessRuleResponse = await client3.loadObjects({
|
|
53242
53340
|
object: "access_rules",
|
|
53243
53341
|
where: { access_rules: { id: accessRuleId } },
|
|
53244
53342
|
limit: 1,
|
|
@@ -53252,20 +53350,20 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53252
53350
|
"The HID reader did not save the visitor access rule. Try issuing the QR code again."
|
|
53253
53351
|
);
|
|
53254
53352
|
}
|
|
53255
|
-
const existingTimeZoneResponse = await
|
|
53353
|
+
const existingTimeZoneResponse = await client3.loadObjects({
|
|
53256
53354
|
object: "time_zones",
|
|
53257
53355
|
where: { time_zones: { id: timeZoneId } },
|
|
53258
53356
|
limit: 1,
|
|
53259
53357
|
offset: 0
|
|
53260
53358
|
});
|
|
53261
53359
|
if (getHidObjectRows(existingTimeZoneResponse, "time_zones").length) {
|
|
53262
|
-
await
|
|
53360
|
+
await client3.modifyObjects({
|
|
53263
53361
|
object: "time_zones",
|
|
53264
53362
|
where: { time_zones: { id: timeZoneId } },
|
|
53265
53363
|
values: { name: `iService365 ${accessLabel} Schedule` }
|
|
53266
53364
|
});
|
|
53267
53365
|
} else {
|
|
53268
|
-
await
|
|
53366
|
+
await client3.createObjects({
|
|
53269
53367
|
object: "time_zones",
|
|
53270
53368
|
values: [{ id: timeZoneId, name: `iService365 ${accessLabel} Schedule` }]
|
|
53271
53369
|
});
|
|
@@ -53285,25 +53383,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53285
53383
|
hol2: 1,
|
|
53286
53384
|
hol3: 1
|
|
53287
53385
|
};
|
|
53288
|
-
const existingTimeSpanResponse = await
|
|
53386
|
+
const existingTimeSpanResponse = await client3.loadObjects({
|
|
53289
53387
|
object: "time_spans",
|
|
53290
53388
|
where: { time_spans: { id: timeSpanId } },
|
|
53291
53389
|
limit: 1,
|
|
53292
53390
|
offset: 0
|
|
53293
53391
|
});
|
|
53294
53392
|
if (getHidObjectRows(existingTimeSpanResponse, "time_spans").length) {
|
|
53295
|
-
await
|
|
53393
|
+
await client3.modifyObjects({
|
|
53296
53394
|
object: "time_spans",
|
|
53297
53395
|
where: { time_spans: { id: timeSpanId } },
|
|
53298
53396
|
values: visitorTimeSpan
|
|
53299
53397
|
});
|
|
53300
53398
|
} else {
|
|
53301
|
-
await
|
|
53399
|
+
await client3.createObjects({
|
|
53302
53400
|
object: "time_spans",
|
|
53303
53401
|
values: [{ id: timeSpanId, ...visitorTimeSpan }]
|
|
53304
53402
|
});
|
|
53305
53403
|
}
|
|
53306
|
-
const verifiedTimeZoneResponse = await
|
|
53404
|
+
const verifiedTimeZoneResponse = await client3.loadObjects({
|
|
53307
53405
|
object: "time_zones",
|
|
53308
53406
|
where: { time_zones: { id: timeZoneId } },
|
|
53309
53407
|
limit: 1,
|
|
@@ -53317,7 +53415,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53317
53415
|
"The HID reader did not save the visitor access schedule."
|
|
53318
53416
|
);
|
|
53319
53417
|
}
|
|
53320
|
-
const verifiedTimeSpanResponse = await
|
|
53418
|
+
const verifiedTimeSpanResponse = await client3.loadObjects({
|
|
53321
53419
|
object: "time_spans",
|
|
53322
53420
|
where: { time_spans: { id: timeSpanId } },
|
|
53323
53421
|
limit: 1,
|
|
@@ -53335,7 +53433,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53335
53433
|
access_rule_id: accessRuleId,
|
|
53336
53434
|
time_zone_id: timeZoneId
|
|
53337
53435
|
};
|
|
53338
|
-
const accessRuleTimeZoneResponse = await
|
|
53436
|
+
const accessRuleTimeZoneResponse = await client3.loadObjects({
|
|
53339
53437
|
object: "access_rule_time_zones",
|
|
53340
53438
|
where: {
|
|
53341
53439
|
access_rule_time_zones: {
|
|
@@ -53349,12 +53447,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53349
53447
|
getHidObjectRows(accessRuleTimeZoneResponse, "access_rule_time_zones"),
|
|
53350
53448
|
accessRuleTimeZoneValues
|
|
53351
53449
|
)) {
|
|
53352
|
-
await
|
|
53450
|
+
await client3.createObjects({
|
|
53353
53451
|
object: "access_rule_time_zones",
|
|
53354
53452
|
values: [accessRuleTimeZoneValues]
|
|
53355
53453
|
});
|
|
53356
53454
|
}
|
|
53357
|
-
const verifiedAccessRuleTimeZoneResponse = await
|
|
53455
|
+
const verifiedAccessRuleTimeZoneResponse = await client3.loadObjects({
|
|
53358
53456
|
object: "access_rule_time_zones",
|
|
53359
53457
|
where: { access_rule_time_zones: { access_rule_id: accessRuleId } },
|
|
53360
53458
|
limit: 100,
|
|
@@ -53368,7 +53466,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53368
53466
|
"The HID reader did not save the visitor access schedule. Try issuing the QR code again."
|
|
53369
53467
|
);
|
|
53370
53468
|
}
|
|
53371
|
-
const portalsResponse = await
|
|
53469
|
+
const portalsResponse = await client3.loadObjects({
|
|
53372
53470
|
object: "portals",
|
|
53373
53471
|
limit: 100,
|
|
53374
53472
|
offset: 0
|
|
@@ -53405,7 +53503,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53405
53503
|
user_id: hidUserId,
|
|
53406
53504
|
access_rule_id: accessRuleId
|
|
53407
53505
|
};
|
|
53408
|
-
const userAccessRulesResponse = await
|
|
53506
|
+
const userAccessRulesResponse = await client3.loadObjects({
|
|
53409
53507
|
object: "user_access_rules",
|
|
53410
53508
|
where: { user_access_rules: { user_id: hidUserId } },
|
|
53411
53509
|
limit: 100,
|
|
@@ -53415,12 +53513,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53415
53513
|
getHidObjectRows(userAccessRulesResponse, "user_access_rules"),
|
|
53416
53514
|
userAccessRuleValues
|
|
53417
53515
|
)) {
|
|
53418
|
-
await
|
|
53516
|
+
await client3.createObjects({
|
|
53419
53517
|
object: "user_access_rules",
|
|
53420
53518
|
values: [userAccessRuleValues]
|
|
53421
53519
|
});
|
|
53422
53520
|
}
|
|
53423
|
-
const verifiedUserAccessRulesResponse = await
|
|
53521
|
+
const verifiedUserAccessRulesResponse = await client3.loadObjects({
|
|
53424
53522
|
object: "user_access_rules",
|
|
53425
53523
|
where: { user_access_rules: { user_id: hidUserId } },
|
|
53426
53524
|
limit: 100,
|
|
@@ -53434,7 +53532,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53434
53532
|
"The HID reader did not save the visitor access rule. Try issuing the QR code again."
|
|
53435
53533
|
);
|
|
53436
53534
|
}
|
|
53437
|
-
const portalAccessRulesResponse = await
|
|
53535
|
+
const portalAccessRulesResponse = await client3.loadObjects({
|
|
53438
53536
|
object: "portal_access_rules",
|
|
53439
53537
|
where: { portal_access_rules: { access_rule_id: accessRuleId } },
|
|
53440
53538
|
limit: 100,
|
|
@@ -53445,7 +53543,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53445
53543
|
);
|
|
53446
53544
|
const stalePortalIds = [...linkedPortalIds].filter((portalId) => !portalIds.includes(portalId));
|
|
53447
53545
|
for (const portalId of stalePortalIds) {
|
|
53448
|
-
await
|
|
53546
|
+
await client3.destroyObjects({
|
|
53449
53547
|
object: "portal_access_rules",
|
|
53450
53548
|
where: { portal_access_rules: { access_rule_id: accessRuleId, portal_id: portalId } }
|
|
53451
53549
|
});
|
|
@@ -53453,12 +53551,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
|
|
|
53453
53551
|
}
|
|
53454
53552
|
const missingPortalLinks = portalIds.filter((portalId) => !linkedPortalIds.has(portalId)).map((portalId) => ({ portal_id: portalId, access_rule_id: accessRuleId }));
|
|
53455
53553
|
if (missingPortalLinks.length) {
|
|
53456
|
-
await
|
|
53554
|
+
await client3.createObjects({
|
|
53457
53555
|
object: "portal_access_rules",
|
|
53458
53556
|
values: missingPortalLinks
|
|
53459
53557
|
});
|
|
53460
53558
|
}
|
|
53461
|
-
const verifiedPortalAccessRulesResponse = await
|
|
53559
|
+
const verifiedPortalAccessRulesResponse = await client3.loadObjects({
|
|
53462
53560
|
object: "portal_access_rules",
|
|
53463
53561
|
where: { portal_access_rules: { access_rule_id: accessRuleId } },
|
|
53464
53562
|
limit: 100,
|
|
@@ -53482,19 +53580,19 @@ function getHidPortals(response) {
|
|
|
53482
53580
|
areaToId: Number(portal.area_to_id)
|
|
53483
53581
|
})).filter((portal) => Number.isSafeInteger(portal.id) && portal.id > 0 && portal.name);
|
|
53484
53582
|
}
|
|
53485
|
-
async function upsertHidObject(
|
|
53486
|
-
const existing = await
|
|
53583
|
+
async function upsertHidObject(client3, object, id, values) {
|
|
53584
|
+
const existing = await client3.loadObjects({
|
|
53487
53585
|
object,
|
|
53488
53586
|
where: { [object]: { id } },
|
|
53489
53587
|
limit: 1,
|
|
53490
53588
|
offset: 0
|
|
53491
53589
|
});
|
|
53492
53590
|
if (getHidObjectRows(existing, object).length) {
|
|
53493
|
-
await
|
|
53591
|
+
await client3.modifyObjects({ object, where: { [object]: { id } }, values });
|
|
53494
53592
|
} else {
|
|
53495
|
-
await
|
|
53593
|
+
await client3.createObjects({ object, values: [{ id, ...values }] });
|
|
53496
53594
|
}
|
|
53497
|
-
const verified = await
|
|
53595
|
+
const verified = await client3.loadObjects({
|
|
53498
53596
|
object,
|
|
53499
53597
|
where: { [object]: { id } },
|
|
53500
53598
|
limit: 1,
|
|
@@ -53504,17 +53602,17 @@ async function upsertHidObject(client2, object, id, values) {
|
|
|
53504
53602
|
throw new import_node_server_utils149.BadRequestError(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
|
|
53505
53603
|
}
|
|
53506
53604
|
}
|
|
53507
|
-
async function ensureHidRelation(
|
|
53508
|
-
const response = await
|
|
53605
|
+
async function ensureHidRelation(client3, object, values) {
|
|
53606
|
+
const response = await client3.loadObjects({
|
|
53509
53607
|
object,
|
|
53510
53608
|
where: { [object]: values },
|
|
53511
53609
|
limit: 100,
|
|
53512
53610
|
offset: 0
|
|
53513
53611
|
});
|
|
53514
53612
|
if (!hasHidObjectValues(getHidObjectRows(response, object), values)) {
|
|
53515
|
-
await
|
|
53613
|
+
await client3.createObjects({ object, values: [values] });
|
|
53516
53614
|
}
|
|
53517
|
-
const verified = await
|
|
53615
|
+
const verified = await client3.loadObjects({
|
|
53518
53616
|
object,
|
|
53519
53617
|
where: { [object]: values },
|
|
53520
53618
|
limit: 100,
|
|
@@ -53524,8 +53622,8 @@ async function ensureHidRelation(client2, object, values) {
|
|
|
53524
53622
|
throw new import_node_server_utils149.BadRequestError(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
|
|
53525
53623
|
}
|
|
53526
53624
|
}
|
|
53527
|
-
async function reconcileHidRelation(
|
|
53528
|
-
const response = await
|
|
53625
|
+
async function reconcileHidRelation(client3, object, scope, values) {
|
|
53626
|
+
const response = await client3.loadObjects({
|
|
53529
53627
|
object,
|
|
53530
53628
|
where: { [object]: scope },
|
|
53531
53629
|
limit: 1e3,
|
|
@@ -53537,11 +53635,11 @@ async function reconcileHidRelation(client2, object, scope, values) {
|
|
|
53537
53635
|
const staleValues = Object.fromEntries(
|
|
53538
53636
|
Object.keys(values).map((key2) => [key2, row[key2]])
|
|
53539
53637
|
);
|
|
53540
|
-
await
|
|
53638
|
+
await client3.destroyObjects({ object, where: { [object]: staleValues } });
|
|
53541
53639
|
}
|
|
53542
53640
|
}
|
|
53543
|
-
await ensureHidRelation(
|
|
53544
|
-
const verified = await
|
|
53641
|
+
await ensureHidRelation(client3, object, values);
|
|
53642
|
+
const verified = await client3.loadObjects({
|
|
53545
53643
|
object,
|
|
53546
53644
|
where: { [object]: scope },
|
|
53547
53645
|
limit: 1e3,
|
|
@@ -53552,21 +53650,21 @@ async function reconcileHidRelation(client2, object, scope, values) {
|
|
|
53552
53650
|
throw new import_node_server_utils149.BadRequestError(`The HID reader did not reconcile ${object.replace(/_/g, " ")}.`);
|
|
53553
53651
|
}
|
|
53554
53652
|
}
|
|
53555
|
-
async function reconcileStandaloneGroupAccess(
|
|
53653
|
+
async function reconcileStandaloneGroupAccess(client3, readerId, portalId, userIds) {
|
|
53556
53654
|
const groupId = createStableHidId(`permission-group:${readerId}`);
|
|
53557
53655
|
const accessRuleId = createStableHidId(`permission-access-rule:${readerId}`);
|
|
53558
53656
|
const timeZoneId = createStableHidId(`permission-time-zone:${readerId}`);
|
|
53559
53657
|
const timeSpanId = createStableHidId(`permission-time-span:${readerId}`);
|
|
53560
|
-
await upsertHidObject(
|
|
53561
|
-
await upsertHidObject(
|
|
53658
|
+
await upsertHidObject(client3, "groups", groupId, { name: "iService365 Assigned Access" });
|
|
53659
|
+
await upsertHidObject(client3, "access_rules", accessRuleId, {
|
|
53562
53660
|
name: "iService365 Assigned Access",
|
|
53563
53661
|
type: 1,
|
|
53564
53662
|
priority: 0
|
|
53565
53663
|
});
|
|
53566
|
-
await upsertHidObject(
|
|
53664
|
+
await upsertHidObject(client3, "time_zones", timeZoneId, {
|
|
53567
53665
|
name: "iService365 Assigned Schedule"
|
|
53568
53666
|
});
|
|
53569
|
-
await upsertHidObject(
|
|
53667
|
+
await upsertHidObject(client3, "time_spans", timeSpanId, {
|
|
53570
53668
|
time_zone_id: timeZoneId,
|
|
53571
53669
|
start: 0,
|
|
53572
53670
|
end: 86399,
|
|
@@ -53581,19 +53679,19 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
|
|
|
53581
53679
|
hol2: 1,
|
|
53582
53680
|
hol3: 1
|
|
53583
53681
|
});
|
|
53584
|
-
await reconcileHidRelation(
|
|
53682
|
+
await reconcileHidRelation(client3, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
|
|
53585
53683
|
access_rule_id: accessRuleId,
|
|
53586
53684
|
time_zone_id: timeZoneId
|
|
53587
53685
|
});
|
|
53588
|
-
await reconcileHidRelation(
|
|
53686
|
+
await reconcileHidRelation(client3, "group_access_rules", { access_rule_id: accessRuleId }, {
|
|
53589
53687
|
group_id: groupId,
|
|
53590
53688
|
access_rule_id: accessRuleId
|
|
53591
53689
|
});
|
|
53592
|
-
await reconcileHidRelation(
|
|
53690
|
+
await reconcileHidRelation(client3, "portal_access_rules", { access_rule_id: accessRuleId }, {
|
|
53593
53691
|
portal_id: portalId,
|
|
53594
53692
|
access_rule_id: accessRuleId
|
|
53595
53693
|
});
|
|
53596
|
-
const currentResponse = await
|
|
53694
|
+
const currentResponse = await client3.loadObjects({
|
|
53597
53695
|
object: "user_groups",
|
|
53598
53696
|
where: { user_groups: { group_id: groupId } },
|
|
53599
53697
|
limit: 2e5,
|
|
@@ -53604,7 +53702,7 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
|
|
|
53604
53702
|
for (const row of currentRows) {
|
|
53605
53703
|
const userId = String(row.user_id ?? "");
|
|
53606
53704
|
if (userId && !desired.has(userId)) {
|
|
53607
|
-
await
|
|
53705
|
+
await client3.destroyObjects({
|
|
53608
53706
|
object: "user_groups",
|
|
53609
53707
|
where: { user_groups: { group_id: groupId, user_id: Number(userId) } }
|
|
53610
53708
|
});
|
|
@@ -53613,13 +53711,13 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
|
|
|
53613
53711
|
const current = new Set(currentRows.map((row) => String(row.user_id ?? "")));
|
|
53614
53712
|
for (const userId of userIds) {
|
|
53615
53713
|
if (!current.has(String(userId))) {
|
|
53616
|
-
await
|
|
53714
|
+
await client3.createObjects({
|
|
53617
53715
|
object: "user_groups",
|
|
53618
53716
|
values: [{ group_id: groupId, user_id: userId }]
|
|
53619
53717
|
});
|
|
53620
53718
|
}
|
|
53621
53719
|
}
|
|
53622
|
-
const verification = await
|
|
53720
|
+
const verification = await client3.loadObjects({
|
|
53623
53721
|
object: "user_groups",
|
|
53624
53722
|
where: { user_groups: { group_id: groupId } },
|
|
53625
53723
|
limit: 2e5,
|
|
@@ -54122,10 +54220,10 @@ var HidAmicoClient = class {
|
|
|
54122
54220
|
return res.data;
|
|
54123
54221
|
}
|
|
54124
54222
|
};
|
|
54125
|
-
async function configureMonitor(
|
|
54223
|
+
async function configureMonitor(client3, callbackToken) {
|
|
54126
54224
|
const expected = getMonitorConfiguration(callbackToken);
|
|
54127
|
-
await
|
|
54128
|
-
const response = await
|
|
54225
|
+
await client3.setConfiguration({ monitor: expected });
|
|
54226
|
+
const response = await client3.getConfiguration({
|
|
54129
54227
|
monitor: ["request_timeout", "hostname", "port", "path"]
|
|
54130
54228
|
});
|
|
54131
54229
|
const root = isUnknownRecord2(response) ? response : {};
|
|
@@ -54135,9 +54233,9 @@ async function configureMonitor(client2, callbackToken) {
|
|
|
54135
54233
|
}
|
|
54136
54234
|
return expected;
|
|
54137
54235
|
}
|
|
54138
|
-
async function configureOperatingMode(
|
|
54236
|
+
async function configureOperatingMode(client3, mode) {
|
|
54139
54237
|
const expectedOnline = mode === "online" ? "1" : "0";
|
|
54140
|
-
await
|
|
54238
|
+
await client3.setConfiguration({
|
|
54141
54239
|
general: {
|
|
54142
54240
|
online: expectedOnline,
|
|
54143
54241
|
// HID documents Online mode as both flags enabled. Keeping local
|
|
@@ -54145,7 +54243,7 @@ async function configureOperatingMode(client2, mode) {
|
|
|
54145
54243
|
local_identification: "1"
|
|
54146
54244
|
}
|
|
54147
54245
|
});
|
|
54148
|
-
const response = await
|
|
54246
|
+
const response = await client3.getConfiguration({
|
|
54149
54247
|
general: ["online", "local_identification"]
|
|
54150
54248
|
});
|
|
54151
54249
|
const root = isUnknownRecord2(response) ? response : {};
|
|
@@ -54529,8 +54627,8 @@ function useHidAmicoService() {
|
|
|
54529
54627
|
return requestedType;
|
|
54530
54628
|
return mode === "csn_for_mifare" ? "unknown" : mode;
|
|
54531
54629
|
}
|
|
54532
|
-
async function assertHidUserExists(
|
|
54533
|
-
const response = await
|
|
54630
|
+
async function assertHidUserExists(client3, hidUserId) {
|
|
54631
|
+
const response = await client3.loadObjects({
|
|
54534
54632
|
object: "users",
|
|
54535
54633
|
where: { users: { id: hidUserId } },
|
|
54536
54634
|
limit: 1,
|
|
@@ -54540,18 +54638,18 @@ function useHidAmicoService() {
|
|
|
54540
54638
|
throw new import_node_server_utils149.BadRequestError("HID user must exist before assigning a physical HID card.");
|
|
54541
54639
|
}
|
|
54542
54640
|
}
|
|
54543
|
-
async function ensurePhysicalCardIdentification(
|
|
54544
|
-
const before = await
|
|
54641
|
+
async function ensurePhysicalCardIdentification(client3) {
|
|
54642
|
+
const before = await client3.getConfiguration({
|
|
54545
54643
|
identifier: ["card_identification_enabled"]
|
|
54546
54644
|
});
|
|
54547
54645
|
const root = isUnknownRecord2(before) ? before : {};
|
|
54548
54646
|
const identifier = isUnknownRecord2(root.identifier) ? root.identifier : {};
|
|
54549
54647
|
if (String(identifier.card_identification_enabled ?? "") !== "1") {
|
|
54550
|
-
await
|
|
54648
|
+
await client3.setConfiguration({
|
|
54551
54649
|
identifier: { card_identification_enabled: "1" }
|
|
54552
54650
|
});
|
|
54553
54651
|
}
|
|
54554
|
-
const verifiedResponse = await
|
|
54652
|
+
const verifiedResponse = await client3.getConfiguration({
|
|
54555
54653
|
identifier: ["card_identification_enabled"]
|
|
54556
54654
|
});
|
|
54557
54655
|
const verifiedRoot = isUnknownRecord2(verifiedResponse) ? verifiedResponse : {};
|
|
@@ -54562,8 +54660,8 @@ function useHidAmicoService() {
|
|
|
54562
54660
|
);
|
|
54563
54661
|
}
|
|
54564
54662
|
}
|
|
54565
|
-
async function loadPhysicalCardRows(
|
|
54566
|
-
const response = await
|
|
54663
|
+
async function loadPhysicalCardRows(client3, hidUserId) {
|
|
54664
|
+
const response = await client3.loadObjects({
|
|
54567
54665
|
object: "cards",
|
|
54568
54666
|
where: { cards: { user_id: hidUserId } },
|
|
54569
54667
|
limit: 100,
|
|
@@ -54661,15 +54759,15 @@ function useHidAmicoService() {
|
|
|
54661
54759
|
const refusal = discoveryUrlRefusalReason(value.baseUrl);
|
|
54662
54760
|
if (refusal)
|
|
54663
54761
|
throw new import_node_server_utils149.BadRequestError(refusal);
|
|
54664
|
-
const
|
|
54762
|
+
const client3 = new HidAmicoClient({
|
|
54665
54763
|
...value,
|
|
54666
54764
|
baseUrl: normalizeHidReaderBaseUrl(value.baseUrl)
|
|
54667
54765
|
});
|
|
54668
54766
|
try {
|
|
54669
|
-
await
|
|
54767
|
+
await client3.login();
|
|
54670
54768
|
const [systemResponse, portalsResponse] = await Promise.all([
|
|
54671
|
-
|
|
54672
|
-
|
|
54769
|
+
client3.getSystemInformation(),
|
|
54770
|
+
client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
|
|
54673
54771
|
]);
|
|
54674
54772
|
const system = getHidSystemInformation(systemResponse);
|
|
54675
54773
|
const deviceId = isUnknownRecord2(system) ? String(system.device_id || "").trim() : "";
|
|
@@ -54699,7 +54797,7 @@ function useHidAmicoService() {
|
|
|
54699
54797
|
portals
|
|
54700
54798
|
};
|
|
54701
54799
|
} finally {
|
|
54702
|
-
await
|
|
54800
|
+
await client3.logout();
|
|
54703
54801
|
}
|
|
54704
54802
|
}
|
|
54705
54803
|
async function createReader(value) {
|
|
@@ -54729,11 +54827,11 @@ function useHidAmicoService() {
|
|
|
54729
54827
|
const readerId = String(reader._id);
|
|
54730
54828
|
if (value.enabled === false)
|
|
54731
54829
|
return reader;
|
|
54732
|
-
const
|
|
54830
|
+
const client3 = new HidAmicoClient(value);
|
|
54733
54831
|
try {
|
|
54734
|
-
await
|
|
54832
|
+
await client3.login();
|
|
54735
54833
|
if (!monitorEnabled) {
|
|
54736
|
-
await configureOperatingMode(
|
|
54834
|
+
await configureOperatingMode(client3, "standalone");
|
|
54737
54835
|
return repo.updateById(readerId, {
|
|
54738
54836
|
monitorStatus: "disabled",
|
|
54739
54837
|
monitorPath: "",
|
|
@@ -54742,8 +54840,8 @@ function useHidAmicoService() {
|
|
|
54742
54840
|
lastSyncMessage: "Monitor callbacks are disabled; Standalone mode configured."
|
|
54743
54841
|
});
|
|
54744
54842
|
}
|
|
54745
|
-
const monitor = await configureMonitor(
|
|
54746
|
-
await configureOperatingMode(
|
|
54843
|
+
const monitor = await configureMonitor(client3, callbackToken);
|
|
54844
|
+
await configureOperatingMode(client3, "standalone");
|
|
54747
54845
|
const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
|
|
54748
54846
|
return repo.updateById(readerId, {
|
|
54749
54847
|
monitorPath: publicMonitor.path,
|
|
@@ -54769,7 +54867,7 @@ function useHidAmicoService() {
|
|
|
54769
54867
|
});
|
|
54770
54868
|
return { ...failed, monitorWarning: message };
|
|
54771
54869
|
} finally {
|
|
54772
|
-
await
|
|
54870
|
+
await client3.logout();
|
|
54773
54871
|
}
|
|
54774
54872
|
}
|
|
54775
54873
|
async function updateReader(id, value) {
|
|
@@ -54809,10 +54907,10 @@ function useHidAmicoService() {
|
|
|
54809
54907
|
}
|
|
54810
54908
|
if (payload.portalId && current) {
|
|
54811
54909
|
const candidate = { ...current, ...payload };
|
|
54812
|
-
const
|
|
54910
|
+
const client3 = new HidAmicoClient(candidate);
|
|
54813
54911
|
try {
|
|
54814
|
-
await
|
|
54815
|
-
const portals = getHidPortals(await
|
|
54912
|
+
await client3.login();
|
|
54913
|
+
const portals = getHidPortals(await client3.loadObjects({
|
|
54816
54914
|
object: "portals",
|
|
54817
54915
|
limit: 100,
|
|
54818
54916
|
offset: 0
|
|
@@ -54823,7 +54921,7 @@ function useHidAmicoService() {
|
|
|
54823
54921
|
}
|
|
54824
54922
|
payload.portalName = portal.name;
|
|
54825
54923
|
} finally {
|
|
54826
|
-
await
|
|
54924
|
+
await client3.logout();
|
|
54827
54925
|
}
|
|
54828
54926
|
}
|
|
54829
54927
|
return repo.updateById(id, payload);
|
|
@@ -54841,12 +54939,12 @@ function useHidAmicoService() {
|
|
|
54841
54939
|
monitorStatus: "unconfigured"
|
|
54842
54940
|
});
|
|
54843
54941
|
}
|
|
54844
|
-
const
|
|
54942
|
+
const client3 = new HidAmicoClient(reader);
|
|
54845
54943
|
try {
|
|
54846
|
-
await
|
|
54944
|
+
await client3.login();
|
|
54847
54945
|
const [systemResponse, portalsResponse] = await Promise.all([
|
|
54848
|
-
|
|
54849
|
-
|
|
54946
|
+
client3.getSystemInformation(),
|
|
54947
|
+
client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
|
|
54850
54948
|
]);
|
|
54851
54949
|
const system = getHidSystemInformation(systemResponse);
|
|
54852
54950
|
const serial = isUnknownRecord2(system) ? String(system.serial || "") : "";
|
|
@@ -54863,9 +54961,9 @@ function useHidAmicoService() {
|
|
|
54863
54961
|
"The saved portal no longer exists on this HID reader. Edit the reader and select a valid portal."
|
|
54864
54962
|
);
|
|
54865
54963
|
}
|
|
54866
|
-
const monitor = await configureMonitor(
|
|
54964
|
+
const monitor = await configureMonitor(client3, callbackToken);
|
|
54867
54965
|
const mode = reader.operatingMode === "online" ? "online" : "standalone";
|
|
54868
|
-
await configureOperatingMode(
|
|
54966
|
+
await configureOperatingMode(client3, mode);
|
|
54869
54967
|
const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
|
|
54870
54968
|
await repo.updateById(id, {
|
|
54871
54969
|
serial,
|
|
@@ -54888,17 +54986,17 @@ function useHidAmicoService() {
|
|
|
54888
54986
|
});
|
|
54889
54987
|
throw error;
|
|
54890
54988
|
} finally {
|
|
54891
|
-
await
|
|
54989
|
+
await client3.logout();
|
|
54892
54990
|
}
|
|
54893
54991
|
}
|
|
54894
54992
|
async function setReaderMonitor(id, enabled) {
|
|
54895
54993
|
if (enabled)
|
|
54896
54994
|
return configureReaderIntegration(id);
|
|
54897
54995
|
const reader = await getActiveReader(id);
|
|
54898
|
-
const
|
|
54996
|
+
const client3 = new HidAmicoClient(reader);
|
|
54899
54997
|
try {
|
|
54900
|
-
await
|
|
54901
|
-
await configureOperatingMode(
|
|
54998
|
+
await client3.login();
|
|
54999
|
+
await configureOperatingMode(client3, "standalone");
|
|
54902
55000
|
await repo.updateById(id, {
|
|
54903
55001
|
monitorStatus: "disabled",
|
|
54904
55002
|
monitorPath: "",
|
|
@@ -54915,7 +55013,7 @@ function useHidAmicoService() {
|
|
|
54915
55013
|
});
|
|
54916
55014
|
return { enabled: false, mode: "standalone", verified: true };
|
|
54917
55015
|
} finally {
|
|
54918
|
-
await
|
|
55016
|
+
await client3.logout();
|
|
54919
55017
|
}
|
|
54920
55018
|
}
|
|
54921
55019
|
async function setOperatingMode(id, mode) {
|
|
@@ -54925,10 +55023,10 @@ function useHidAmicoService() {
|
|
|
54925
55023
|
"Configure and verify the HID Monitor callback before enabling Online mode."
|
|
54926
55024
|
);
|
|
54927
55025
|
}
|
|
54928
|
-
const
|
|
55026
|
+
const client3 = new HidAmicoClient(reader);
|
|
54929
55027
|
try {
|
|
54930
|
-
await
|
|
54931
|
-
const result = await configureOperatingMode(
|
|
55028
|
+
await client3.login();
|
|
55029
|
+
const result = await configureOperatingMode(client3, mode);
|
|
54932
55030
|
await repo.updateById(id, {
|
|
54933
55031
|
operatingMode: mode,
|
|
54934
55032
|
lastSyncStatus: "completed",
|
|
@@ -54943,7 +55041,7 @@ function useHidAmicoService() {
|
|
|
54943
55041
|
});
|
|
54944
55042
|
return sanitizeHidPayload(result);
|
|
54945
55043
|
} finally {
|
|
54946
|
-
await
|
|
55044
|
+
await client3.logout();
|
|
54947
55045
|
}
|
|
54948
55046
|
}
|
|
54949
55047
|
async function listReaders(value) {
|
|
@@ -54998,12 +55096,12 @@ function useHidAmicoService() {
|
|
|
54998
55096
|
}
|
|
54999
55097
|
async function testReader(id) {
|
|
55000
55098
|
const reader = await repo.getById(id, { includePassword: true });
|
|
55001
|
-
const
|
|
55099
|
+
const client3 = new HidAmicoClient(reader);
|
|
55002
55100
|
try {
|
|
55003
|
-
await
|
|
55101
|
+
await client3.login();
|
|
55004
55102
|
const [valid, systemResponse] = await Promise.all([
|
|
55005
|
-
|
|
55006
|
-
|
|
55103
|
+
client3.sessionIsValid(),
|
|
55104
|
+
client3.getSystemInformation()
|
|
55007
55105
|
]);
|
|
55008
55106
|
const system = getHidSystemInformation(systemResponse);
|
|
55009
55107
|
const firmwareVersion = getHidFirmwareVersion(systemResponse);
|
|
@@ -55057,19 +55155,19 @@ function useHidAmicoService() {
|
|
|
55057
55155
|
await repo.addEvent({ reader: id, site: reader.site, type: "test_failed", payload: { message } });
|
|
55058
55156
|
throw error;
|
|
55059
55157
|
} finally {
|
|
55060
|
-
await
|
|
55158
|
+
await client3.logout();
|
|
55061
55159
|
}
|
|
55062
55160
|
}
|
|
55063
55161
|
async function syncReader(id, payload) {
|
|
55064
55162
|
const reader = await getActiveReader(id);
|
|
55065
55163
|
const batches = normalizeBatches(payload);
|
|
55066
|
-
const
|
|
55164
|
+
const client3 = new HidAmicoClient(reader);
|
|
55067
55165
|
const results = [];
|
|
55068
55166
|
await repo.updateById(id, { lastSyncStatus: "running", lastSyncMessage: "Sync started." });
|
|
55069
55167
|
try {
|
|
55070
|
-
await
|
|
55168
|
+
await client3.login();
|
|
55071
55169
|
for (const batch of batches) {
|
|
55072
|
-
const result = await
|
|
55170
|
+
const result = await client3.createObjects(batch);
|
|
55073
55171
|
results.push({
|
|
55074
55172
|
object: batch.object,
|
|
55075
55173
|
count: batch.values.length,
|
|
@@ -55097,7 +55195,7 @@ function useHidAmicoService() {
|
|
|
55097
55195
|
await repo.addEvent({ reader: id, site: reader.site, type: "sync_failed", payload: { message } });
|
|
55098
55196
|
throw error;
|
|
55099
55197
|
} finally {
|
|
55100
|
-
await
|
|
55198
|
+
await client3.logout();
|
|
55101
55199
|
}
|
|
55102
55200
|
}
|
|
55103
55201
|
async function isIdentityAssignedToReader(reader, identity, requestedPortalId) {
|
|
@@ -55213,9 +55311,9 @@ function useHidAmicoService() {
|
|
|
55213
55311
|
async function listReaderUsers(readerId, page2 = 1, limit = 10, search = "", status = "", includeVisitors = false, userType = "all") {
|
|
55214
55312
|
const reader = await getActiveReader(readerId);
|
|
55215
55313
|
const offset = (page2 - 1) * limit;
|
|
55216
|
-
const
|
|
55314
|
+
const client3 = new HidAmicoClient(reader);
|
|
55217
55315
|
try {
|
|
55218
|
-
await
|
|
55316
|
+
await client3.login();
|
|
55219
55317
|
const normalizedSearch = search.trim();
|
|
55220
55318
|
const numericSearch = /^\d{1,15}$/.test(normalizedSearch) ? Number(normalizedSearch) : null;
|
|
55221
55319
|
const userWhere = {};
|
|
@@ -55227,7 +55325,7 @@ function useHidAmicoService() {
|
|
|
55227
55325
|
let rows = [];
|
|
55228
55326
|
let reportedTotal = null;
|
|
55229
55327
|
let hasMore = false;
|
|
55230
|
-
const response = await
|
|
55328
|
+
const response = await client3.loadObjects({
|
|
55231
55329
|
object: "users",
|
|
55232
55330
|
where: { users: userWhere },
|
|
55233
55331
|
limit: 500,
|
|
@@ -55247,7 +55345,7 @@ function useHidAmicoService() {
|
|
|
55247
55345
|
const userId = Number(row.id);
|
|
55248
55346
|
if (!Number.isSafeInteger(userId) || userId <= 0)
|
|
55249
55347
|
return false;
|
|
55250
|
-
const roleResponse = await
|
|
55348
|
+
const roleResponse = await client3.loadObjects({
|
|
55251
55349
|
object: "user_roles",
|
|
55252
55350
|
where: { user_roles: { user_id: userId, role: 1 } },
|
|
55253
55351
|
limit: 1,
|
|
@@ -55255,7 +55353,7 @@ function useHidAmicoService() {
|
|
|
55255
55353
|
});
|
|
55256
55354
|
return getHidObjectRows(roleResponse, "user_roles").length > 0;
|
|
55257
55355
|
})),
|
|
55258
|
-
readerSupportsFacial(reader) ?
|
|
55356
|
+
readerSupportsFacial(reader) ? client3.listUserImageIds().catch(() => []) : Promise.resolve([])
|
|
55259
55357
|
]);
|
|
55260
55358
|
const facialUserIdSet = new Set(facialUserIds.map(String));
|
|
55261
55359
|
const items = rows.map((row, index) => {
|
|
@@ -55285,15 +55383,15 @@ function useHidAmicoService() {
|
|
|
55285
55383
|
pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${reportedTotal ?? `${offset + items.length}${hasMore ? "+" : ""}`}` : "0-0 of 0"
|
|
55286
55384
|
};
|
|
55287
55385
|
} finally {
|
|
55288
|
-
await
|
|
55386
|
+
await client3.logout();
|
|
55289
55387
|
}
|
|
55290
55388
|
}
|
|
55291
55389
|
async function listReaderAccessLogs(readerId, page2 = 1, limit = 10, search = "", status = "", method = "", tab = "all") {
|
|
55292
55390
|
const reader = await getActiveReader(readerId);
|
|
55293
55391
|
const offset = (page2 - 1) * limit;
|
|
55294
|
-
const
|
|
55392
|
+
const client3 = new HidAmicoClient(reader);
|
|
55295
55393
|
try {
|
|
55296
|
-
await
|
|
55394
|
+
await client3.login();
|
|
55297
55395
|
const where = {};
|
|
55298
55396
|
if (status === "authorized")
|
|
55299
55397
|
where.event = 7;
|
|
@@ -55314,7 +55412,7 @@ function useHidAmicoService() {
|
|
|
55314
55412
|
const userIds = [...new Set(rows.map((row) => toPositiveInteger(row.user_id ?? row.userId)).filter((value) => value !== null))];
|
|
55315
55413
|
const [identities, roleResponse, userResponse] = await Promise.all([
|
|
55316
55414
|
repo.findIdentitiesByHidUserIds(readerId, userIds.map(String)),
|
|
55317
|
-
userIds.length ?
|
|
55415
|
+
userIds.length ? client3.loadObjects({
|
|
55318
55416
|
object: "user_roles",
|
|
55319
55417
|
where: {
|
|
55320
55418
|
user_roles: {
|
|
@@ -55325,7 +55423,7 @@ function useHidAmicoService() {
|
|
|
55325
55423
|
limit: Math.max(1, userIds.length),
|
|
55326
55424
|
offset: 0
|
|
55327
55425
|
}) : Promise.resolve({ user_roles: [] }),
|
|
55328
|
-
userIds.length ?
|
|
55426
|
+
userIds.length ? client3.loadObjects({
|
|
55329
55427
|
object: "users",
|
|
55330
55428
|
where: {
|
|
55331
55429
|
users: {
|
|
@@ -55397,7 +55495,7 @@ function useHidAmicoService() {
|
|
|
55397
55495
|
let deviceOffset = 0;
|
|
55398
55496
|
let exhausted = false;
|
|
55399
55497
|
while (!exhausted && matchedItems.length < targetCount) {
|
|
55400
|
-
const response = await
|
|
55498
|
+
const response = await client3.loadObjects({
|
|
55401
55499
|
object: "access_logs",
|
|
55402
55500
|
...Object.keys(where).length ? { where: { access_logs: where } } : {},
|
|
55403
55501
|
limit: chunkSize,
|
|
@@ -55424,7 +55522,7 @@ function useHidAmicoService() {
|
|
|
55424
55522
|
pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${offset + items.length}${hasMore ? "+" : ""}` : "0-0 of 0"
|
|
55425
55523
|
};
|
|
55426
55524
|
} finally {
|
|
55427
|
-
await
|
|
55525
|
+
await client3.logout();
|
|
55428
55526
|
}
|
|
55429
55527
|
}
|
|
55430
55528
|
async function createIdentity(readerId, value) {
|
|
@@ -55516,18 +55614,18 @@ function useHidAmicoService() {
|
|
|
55516
55614
|
async function runObjectOperation(id, operation, payload) {
|
|
55517
55615
|
const reader = await getActiveReader(id);
|
|
55518
55616
|
assertAllowedHidObject(payload.object, operation);
|
|
55519
|
-
const
|
|
55617
|
+
const client3 = new HidAmicoClient(reader);
|
|
55520
55618
|
try {
|
|
55521
|
-
await
|
|
55619
|
+
await client3.login();
|
|
55522
55620
|
let result;
|
|
55523
55621
|
if (operation === "load") {
|
|
55524
|
-
result = await
|
|
55622
|
+
result = await client3.loadObjects(payload);
|
|
55525
55623
|
} else if (operation === "create") {
|
|
55526
|
-
result = await
|
|
55624
|
+
result = await client3.createObjects(payload);
|
|
55527
55625
|
} else if (operation === "modify") {
|
|
55528
|
-
result = await
|
|
55626
|
+
result = await client3.modifyObjects(payload);
|
|
55529
55627
|
} else {
|
|
55530
|
-
result = await
|
|
55628
|
+
result = await client3.destroyObjects(payload);
|
|
55531
55629
|
}
|
|
55532
55630
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
55533
55631
|
const safeRequest = sanitizeHidObjectPayload(payload.object, payload);
|
|
@@ -55551,7 +55649,7 @@ function useHidAmicoService() {
|
|
|
55551
55649
|
});
|
|
55552
55650
|
throw error;
|
|
55553
55651
|
} finally {
|
|
55554
|
-
await
|
|
55652
|
+
await client3.logout();
|
|
55555
55653
|
}
|
|
55556
55654
|
}
|
|
55557
55655
|
async function issueVisitorQrAtReader(readerId, value) {
|
|
@@ -55582,10 +55680,10 @@ function useHidAmicoService() {
|
|
|
55582
55680
|
const hidUserId = createStableHidId(`visitor:${readerId}:${value.visitorId}`);
|
|
55583
55681
|
const registration = `VIS-${value.visitorId.slice(-12).toUpperCase()}`;
|
|
55584
55682
|
const credential = createVisitorQrCredential(value.visitorId, readerId, value.qrValue);
|
|
55585
|
-
const
|
|
55683
|
+
const client3 = new HidAmicoClient(reader);
|
|
55586
55684
|
try {
|
|
55587
|
-
await
|
|
55588
|
-
const readerConfigurationChanged = await configureVisitorQrReader(
|
|
55685
|
+
await client3.login();
|
|
55686
|
+
const readerConfigurationChanged = await configureVisitorQrReader(client3);
|
|
55589
55687
|
if (readerConfigurationChanged) {
|
|
55590
55688
|
await repo.addEvent({
|
|
55591
55689
|
reader: readerId,
|
|
@@ -55599,7 +55697,7 @@ function useHidAmicoService() {
|
|
|
55599
55697
|
}
|
|
55600
55698
|
});
|
|
55601
55699
|
}
|
|
55602
|
-
const existingUserResponse = await
|
|
55700
|
+
const existingUserResponse = await client3.loadObjects({
|
|
55603
55701
|
object: "users",
|
|
55604
55702
|
where: { users: { id: hidUserId } },
|
|
55605
55703
|
limit: 1,
|
|
@@ -55620,18 +55718,18 @@ function useHidAmicoService() {
|
|
|
55620
55718
|
);
|
|
55621
55719
|
}
|
|
55622
55720
|
if (existingUsers.length) {
|
|
55623
|
-
await
|
|
55721
|
+
await client3.modifyObjects({
|
|
55624
55722
|
object: "users",
|
|
55625
55723
|
where: { users: { id: hidUserId } },
|
|
55626
55724
|
values: user
|
|
55627
55725
|
});
|
|
55628
55726
|
} else {
|
|
55629
|
-
await
|
|
55727
|
+
await client3.createObjects({
|
|
55630
55728
|
object: "users",
|
|
55631
55729
|
values: [{ id: hidUserId, ...user }]
|
|
55632
55730
|
});
|
|
55633
55731
|
}
|
|
55634
|
-
const savedUserResponse = await
|
|
55732
|
+
const savedUserResponse = await client3.loadObjects({
|
|
55635
55733
|
object: "users",
|
|
55636
55734
|
where: { users: { id: hidUserId } },
|
|
55637
55735
|
limit: 1,
|
|
@@ -55646,12 +55744,12 @@ function useHidAmicoService() {
|
|
|
55646
55744
|
);
|
|
55647
55745
|
}
|
|
55648
55746
|
const authorization = await ensureVisitorAccessAuthorization(
|
|
55649
|
-
|
|
55747
|
+
client3,
|
|
55650
55748
|
readerId,
|
|
55651
55749
|
reader,
|
|
55652
55750
|
hidUserId
|
|
55653
55751
|
);
|
|
55654
|
-
const existingQrResponse = await
|
|
55752
|
+
const existingQrResponse = await client3.loadObjects({
|
|
55655
55753
|
object: credential.object,
|
|
55656
55754
|
where: { [credential.object]: { user_id: hidUserId } },
|
|
55657
55755
|
limit: 100,
|
|
@@ -55660,18 +55758,18 @@ function useHidAmicoService() {
|
|
|
55660
55758
|
const existingQrs = getHidObjectRows(existingQrResponse, credential.object);
|
|
55661
55759
|
const credentialValues = { value: credential.value, user_id: hidUserId };
|
|
55662
55760
|
if (existingQrs.some((row) => String(row.id) === String(credential.credentialId))) {
|
|
55663
|
-
await
|
|
55761
|
+
await client3.modifyObjects({
|
|
55664
55762
|
object: credential.object,
|
|
55665
55763
|
where: { [credential.object]: { id: credential.credentialId } },
|
|
55666
55764
|
values: credentialValues
|
|
55667
55765
|
});
|
|
55668
55766
|
} else {
|
|
55669
|
-
await
|
|
55767
|
+
await client3.createObjects({
|
|
55670
55768
|
object: credential.object,
|
|
55671
55769
|
values: [{ id: credential.credentialId, ...credentialValues }]
|
|
55672
55770
|
});
|
|
55673
55771
|
}
|
|
55674
|
-
const savedCredentialResponse = await
|
|
55772
|
+
const savedCredentialResponse = await client3.loadObjects({
|
|
55675
55773
|
object: credential.object,
|
|
55676
55774
|
where: { [credential.object]: { id: credential.credentialId } },
|
|
55677
55775
|
limit: 1,
|
|
@@ -55689,20 +55787,20 @@ function useHidAmicoService() {
|
|
|
55689
55787
|
for (const staleQr of existingQrs) {
|
|
55690
55788
|
const staleId = Number(staleQr.id);
|
|
55691
55789
|
if (Number.isSafeInteger(staleId) && staleId > 0 && staleId !== credential.credentialId) {
|
|
55692
|
-
await
|
|
55790
|
+
await client3.destroyObjects({
|
|
55693
55791
|
object: credential.object,
|
|
55694
55792
|
where: { [credential.object]: { id: staleId } }
|
|
55695
55793
|
});
|
|
55696
55794
|
}
|
|
55697
55795
|
}
|
|
55698
|
-
const existingCardsResponse = await
|
|
55796
|
+
const existingCardsResponse = await client3.loadObjects({
|
|
55699
55797
|
object: "cards",
|
|
55700
55798
|
where: { cards: { user_id: hidUserId } },
|
|
55701
55799
|
limit: 100,
|
|
55702
55800
|
offset: 0
|
|
55703
55801
|
});
|
|
55704
55802
|
if (getHidObjectRows(existingCardsResponse, "cards").length) {
|
|
55705
|
-
await
|
|
55803
|
+
await client3.destroyObjects({
|
|
55706
55804
|
object: "cards",
|
|
55707
55805
|
where: { cards: { user_id: hidUserId } }
|
|
55708
55806
|
});
|
|
@@ -55783,7 +55881,7 @@ function useHidAmicoService() {
|
|
|
55783
55881
|
});
|
|
55784
55882
|
throw error;
|
|
55785
55883
|
} finally {
|
|
55786
|
-
await
|
|
55884
|
+
await client3.logout();
|
|
55787
55885
|
}
|
|
55788
55886
|
}
|
|
55789
55887
|
async function resolveVisitorQrGateReaders(siteId, callerId5, fallbackReaderId, issuer) {
|
|
@@ -55901,10 +55999,10 @@ function useHidAmicoService() {
|
|
|
55901
55999
|
const enrolledAt = /* @__PURE__ */ new Date();
|
|
55902
56000
|
const timestamp = options.timestamp || Math.floor(enrolledAt.getTime() / 1e3);
|
|
55903
56001
|
const match = options.match ?? true;
|
|
55904
|
-
const
|
|
56002
|
+
const client3 = new HidAmicoClient(reader);
|
|
55905
56003
|
try {
|
|
55906
|
-
await
|
|
55907
|
-
const existingUserResponse = await
|
|
56004
|
+
await client3.login();
|
|
56005
|
+
const existingUserResponse = await client3.loadObjects({
|
|
55908
56006
|
object: "users",
|
|
55909
56007
|
where: { users: { id: context.hidUserId } },
|
|
55910
56008
|
limit: 1,
|
|
@@ -55915,18 +56013,18 @@ function useHidAmicoService() {
|
|
|
55915
56013
|
registration: context.registration
|
|
55916
56014
|
};
|
|
55917
56015
|
if (getHidObjectRows(existingUserResponse, "users").length) {
|
|
55918
|
-
await
|
|
56016
|
+
await client3.modifyObjects({
|
|
55919
56017
|
object: "users",
|
|
55920
56018
|
where: { users: { id: context.hidUserId } },
|
|
55921
56019
|
values: hidUser
|
|
55922
56020
|
});
|
|
55923
56021
|
} else {
|
|
55924
|
-
await
|
|
56022
|
+
await client3.createObjects({
|
|
55925
56023
|
object: "users",
|
|
55926
56024
|
values: [{ id: context.hidUserId, ...hidUser }]
|
|
55927
56025
|
});
|
|
55928
56026
|
}
|
|
55929
|
-
const result = await
|
|
56027
|
+
const result = await client3.setUserImage(context.hidUserId, image, timestamp, match);
|
|
55930
56028
|
const existingIdentity = context.profileIdentity || await repo.findExistingIdentity({
|
|
55931
56029
|
reader: readerId,
|
|
55932
56030
|
hidUserId: context.hidUserId
|
|
@@ -55991,25 +56089,25 @@ function useHidAmicoService() {
|
|
|
55991
56089
|
});
|
|
55992
56090
|
throw error;
|
|
55993
56091
|
} finally {
|
|
55994
|
-
await
|
|
56092
|
+
await client3.logout();
|
|
55995
56093
|
}
|
|
55996
56094
|
}
|
|
55997
56095
|
async function getUserImage(readerId, hidUserId) {
|
|
55998
56096
|
const reader = await getActiveReader(readerId);
|
|
55999
56097
|
assertReaderCapability(reader, "facial");
|
|
56000
|
-
const
|
|
56098
|
+
const client3 = new HidAmicoClient(reader);
|
|
56001
56099
|
try {
|
|
56002
|
-
await
|
|
56003
|
-
return await
|
|
56100
|
+
await client3.login();
|
|
56101
|
+
return await client3.getUserImage(hidUserId);
|
|
56004
56102
|
} finally {
|
|
56005
|
-
await
|
|
56103
|
+
await client3.logout();
|
|
56006
56104
|
}
|
|
56007
56105
|
}
|
|
56008
|
-
async function getReaderFacialUserIds(
|
|
56106
|
+
async function getReaderFacialUserIds(client3) {
|
|
56009
56107
|
try {
|
|
56010
|
-
return await
|
|
56108
|
+
return await client3.listUserImageIds();
|
|
56011
56109
|
} catch {
|
|
56012
|
-
const usersResponse = await
|
|
56110
|
+
const usersResponse = await client3.loadObjects({
|
|
56013
56111
|
object: "users",
|
|
56014
56112
|
where: { users: {} },
|
|
56015
56113
|
limit: 500,
|
|
@@ -56023,7 +56121,7 @@ function useHidAmicoService() {
|
|
|
56023
56121
|
const batch = userIds.slice(offset, offset + batchSize);
|
|
56024
56122
|
const results = await Promise.all(batch.map(async (userId) => {
|
|
56025
56123
|
try {
|
|
56026
|
-
const image = await
|
|
56124
|
+
const image = await client3.getUserImage(userId);
|
|
56027
56125
|
return image.base64 ? userId : null;
|
|
56028
56126
|
} catch {
|
|
56029
56127
|
return null;
|
|
@@ -56037,10 +56135,10 @@ function useHidAmicoService() {
|
|
|
56037
56135
|
async function syncReaderFacialData(readerId) {
|
|
56038
56136
|
const reader = await getActiveReader(readerId);
|
|
56039
56137
|
assertReaderCapability(reader, "facial");
|
|
56040
|
-
const
|
|
56138
|
+
const client3 = new HidAmicoClient(reader);
|
|
56041
56139
|
try {
|
|
56042
|
-
await
|
|
56043
|
-
const facialUserIds = await getReaderFacialUserIds(
|
|
56140
|
+
await client3.login();
|
|
56141
|
+
const facialUserIds = await getReaderFacialUserIds(client3);
|
|
56044
56142
|
const message = facialUserIds.length ? `Found ${facialUserIds.length} Amico user(s) with facial data. Facial status and images are read directly from the reader.` : "No facial enrollments found on the HID reader.";
|
|
56045
56143
|
await repo.updateById(readerId, { status: "active", lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56046
56144
|
await repo.addEvent({
|
|
@@ -56072,7 +56170,7 @@ function useHidAmicoService() {
|
|
|
56072
56170
|
});
|
|
56073
56171
|
throw error;
|
|
56074
56172
|
} finally {
|
|
56075
|
-
await
|
|
56173
|
+
await client3.logout();
|
|
56076
56174
|
}
|
|
56077
56175
|
}
|
|
56078
56176
|
async function setVisitorImage(readerId, visitorId, image, options = {}) {
|
|
@@ -56091,10 +56189,10 @@ function useHidAmicoService() {
|
|
|
56091
56189
|
);
|
|
56092
56190
|
const timestamp = options.timestamp || Math.floor(issuedAt.getTime() / 1e3);
|
|
56093
56191
|
const match = options.match ?? true;
|
|
56094
|
-
const
|
|
56192
|
+
const client3 = new HidAmicoClient(reader);
|
|
56095
56193
|
try {
|
|
56096
|
-
await
|
|
56097
|
-
const existingUserResponse = await
|
|
56194
|
+
await client3.login();
|
|
56195
|
+
const existingUserResponse = await client3.loadObjects({
|
|
56098
56196
|
object: "users",
|
|
56099
56197
|
where: { users: { id: hidUserId } },
|
|
56100
56198
|
limit: 1,
|
|
@@ -56108,24 +56206,24 @@ function useHidAmicoService() {
|
|
|
56108
56206
|
end_time: Math.floor(expiresAt.getTime() / 1e3)
|
|
56109
56207
|
};
|
|
56110
56208
|
if (getHidObjectRows(existingUserResponse, "users").length) {
|
|
56111
|
-
await
|
|
56209
|
+
await client3.modifyObjects({
|
|
56112
56210
|
object: "users",
|
|
56113
56211
|
where: { users: { id: hidUserId } },
|
|
56114
56212
|
values: user
|
|
56115
56213
|
});
|
|
56116
56214
|
} else {
|
|
56117
|
-
await
|
|
56215
|
+
await client3.createObjects({
|
|
56118
56216
|
object: "users",
|
|
56119
56217
|
values: [{ id: hidUserId, ...user }]
|
|
56120
56218
|
});
|
|
56121
56219
|
}
|
|
56122
56220
|
const authorization = await ensureVisitorAccessAuthorization(
|
|
56123
|
-
|
|
56221
|
+
client3,
|
|
56124
56222
|
readerId,
|
|
56125
56223
|
reader,
|
|
56126
56224
|
hidUserId
|
|
56127
56225
|
);
|
|
56128
|
-
const result = await
|
|
56226
|
+
const result = await client3.setUserImage(hidUserId, image, timestamp, match);
|
|
56129
56227
|
const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
|
|
56130
56228
|
const existingMetadata = existingIdentity && isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
|
|
56131
56229
|
const identityPayload = {
|
|
@@ -56191,17 +56289,17 @@ function useHidAmicoService() {
|
|
|
56191
56289
|
});
|
|
56192
56290
|
throw error;
|
|
56193
56291
|
} finally {
|
|
56194
|
-
await
|
|
56292
|
+
await client3.logout();
|
|
56195
56293
|
}
|
|
56196
56294
|
}
|
|
56197
56295
|
async function deleteVisitorImage(readerId, visitorId) {
|
|
56198
56296
|
const reader = await getActiveReader(readerId);
|
|
56199
56297
|
assertReaderCapability(reader, "facial");
|
|
56200
56298
|
const { hidUserId } = await getVisitorEnrollmentContext(readerId, reader, visitorId);
|
|
56201
|
-
const
|
|
56299
|
+
const client3 = new HidAmicoClient(reader);
|
|
56202
56300
|
try {
|
|
56203
|
-
await
|
|
56204
|
-
const result = await
|
|
56301
|
+
await client3.login();
|
|
56302
|
+
const result = await client3.deleteUserImage(hidUserId);
|
|
56205
56303
|
const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
|
|
56206
56304
|
if (existingIdentity?._id) {
|
|
56207
56305
|
const existingMetadata = isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
|
|
@@ -56230,7 +56328,7 @@ function useHidAmicoService() {
|
|
|
56230
56328
|
});
|
|
56231
56329
|
throw error;
|
|
56232
56330
|
} finally {
|
|
56233
|
-
await
|
|
56331
|
+
await client3.logout();
|
|
56234
56332
|
}
|
|
56235
56333
|
}
|
|
56236
56334
|
async function listUserCards(readerId, hidUserIdValue) {
|
|
@@ -56238,19 +56336,19 @@ function useHidAmicoService() {
|
|
|
56238
56336
|
assertReaderCapability(reader, "card");
|
|
56239
56337
|
const cardType = reader.cardReadingMode === "pacs" || reader.cardReadingMode === "csn" ? reader.cardReadingMode : "unknown";
|
|
56240
56338
|
const hidUserId = Number(hidUserIdValue);
|
|
56241
|
-
const
|
|
56339
|
+
const client3 = new HidAmicoClient(reader);
|
|
56242
56340
|
try {
|
|
56243
|
-
await
|
|
56244
|
-
await assertHidUserExists(
|
|
56341
|
+
await client3.login();
|
|
56342
|
+
await assertHidUserExists(client3, hidUserId);
|
|
56245
56343
|
const [rows, identity] = await Promise.all([
|
|
56246
|
-
loadPhysicalCardRows(
|
|
56344
|
+
loadPhysicalCardRows(client3, hidUserId),
|
|
56247
56345
|
repo.findExistingIdentity({ reader: readerId, hidUserId })
|
|
56248
56346
|
]);
|
|
56249
56347
|
const metadataRows = getIdentityPhysicalCards(identity);
|
|
56250
56348
|
const cards = rows.map((row) => toHidPhysicalCard(row, metadataRows, cardType)).filter((card) => Boolean(card));
|
|
56251
56349
|
return { readerId, hidUserId, cards };
|
|
56252
56350
|
} finally {
|
|
56253
|
-
await
|
|
56351
|
+
await client3.logout();
|
|
56254
56352
|
}
|
|
56255
56353
|
}
|
|
56256
56354
|
async function assignUserCard(readerId, hidUserIdValue, input) {
|
|
@@ -56264,12 +56362,12 @@ function useHidAmicoService() {
|
|
|
56264
56362
|
} catch (error) {
|
|
56265
56363
|
throw new import_node_server_utils149.BadRequestError(getErrorMessage2(error));
|
|
56266
56364
|
}
|
|
56267
|
-
const
|
|
56365
|
+
const client3 = new HidAmicoClient(reader);
|
|
56268
56366
|
try {
|
|
56269
|
-
await
|
|
56270
|
-
await assertHidUserExists(
|
|
56271
|
-
await ensurePhysicalCardIdentification(
|
|
56272
|
-
const collisionResponse = await
|
|
56367
|
+
await client3.login();
|
|
56368
|
+
await assertHidUserExists(client3, hidUserId);
|
|
56369
|
+
await ensurePhysicalCardIdentification(client3);
|
|
56370
|
+
const collisionResponse = await client3.loadObjects({
|
|
56273
56371
|
object: "cards",
|
|
56274
56372
|
where: { cards: { value: hidRawUint64(cardValue) } },
|
|
56275
56373
|
limit: 10,
|
|
@@ -56287,11 +56385,11 @@ function useHidAmicoService() {
|
|
|
56287
56385
|
);
|
|
56288
56386
|
if (!savedRow) {
|
|
56289
56387
|
const credentialId = createStableHidId(`physical-card:${readerId}:${cardValue}`);
|
|
56290
|
-
await
|
|
56388
|
+
await client3.createObjects({
|
|
56291
56389
|
object: "cards",
|
|
56292
56390
|
values: [{ id: credentialId, value: hidRawUint64(cardValue), user_id: hidUserId }]
|
|
56293
56391
|
});
|
|
56294
|
-
const verifiedResponse = await
|
|
56392
|
+
const verifiedResponse = await client3.loadObjects({
|
|
56295
56393
|
object: "cards",
|
|
56296
56394
|
where: { cards: { id: credentialId } },
|
|
56297
56395
|
limit: 1,
|
|
@@ -56332,7 +56430,7 @@ function useHidAmicoService() {
|
|
|
56332
56430
|
});
|
|
56333
56431
|
throw error;
|
|
56334
56432
|
} finally {
|
|
56335
|
-
await
|
|
56433
|
+
await client3.logout();
|
|
56336
56434
|
}
|
|
56337
56435
|
}
|
|
56338
56436
|
async function enrollUserCard(readerId, hidUserIdValue, cardType, timeoutSeconds) {
|
|
@@ -56340,17 +56438,17 @@ function useHidAmicoService() {
|
|
|
56340
56438
|
assertReaderCapability(reader, "card");
|
|
56341
56439
|
assertReaderCardProfile(reader, cardType);
|
|
56342
56440
|
const hidUserId = Number(hidUserIdValue);
|
|
56343
|
-
const
|
|
56441
|
+
const client3 = new HidAmicoClient(reader);
|
|
56344
56442
|
const lockOwner = import_crypto4.default.randomUUID();
|
|
56345
56443
|
const acquired = await repo.acquireEnrollmentLock(readerId, lockOwner, timeoutSeconds + 30);
|
|
56346
56444
|
if (!acquired) {
|
|
56347
56445
|
throw new import_node_server_utils149.BadRequestError("Another physical HID card enrollment is already running on this reader.");
|
|
56348
56446
|
}
|
|
56349
56447
|
try {
|
|
56350
|
-
await
|
|
56351
|
-
await assertHidUserExists(
|
|
56352
|
-
await ensurePhysicalCardIdentification(
|
|
56353
|
-
const beforeRows = await loadPhysicalCardRows(
|
|
56448
|
+
await client3.login();
|
|
56449
|
+
await assertHidUserExists(client3, hidUserId);
|
|
56450
|
+
await ensurePhysicalCardIdentification(client3);
|
|
56451
|
+
const beforeRows = await loadPhysicalCardRows(client3, hidUserId);
|
|
56354
56452
|
const beforeValues = new Set(beforeRows.map((row) => String(row.value ?? "")));
|
|
56355
56453
|
await repo.addEvent({
|
|
56356
56454
|
reader: readerId,
|
|
@@ -56359,7 +56457,7 @@ function useHidAmicoService() {
|
|
|
56359
56457
|
payload: { hidUserId, cardType, timeoutSeconds }
|
|
56360
56458
|
});
|
|
56361
56459
|
const startedAt = Date.now();
|
|
56362
|
-
const response = await
|
|
56460
|
+
const response = await client3.remoteEnrollCard(hidUserId, timeoutSeconds);
|
|
56363
56461
|
const responseRecord = isUnknownRecord2(response) ? response : {};
|
|
56364
56462
|
const responseData = isUnknownRecord2(responseRecord.data) ? responseRecord.data : responseRecord;
|
|
56365
56463
|
if (responseData.success === false) {
|
|
@@ -56376,7 +56474,7 @@ function useHidAmicoService() {
|
|
|
56376
56474
|
const deadline = startedAt + timeoutSeconds * 1e3;
|
|
56377
56475
|
let savedRow;
|
|
56378
56476
|
do {
|
|
56379
|
-
const rows = await loadPhysicalCardRows(
|
|
56477
|
+
const rows = await loadPhysicalCardRows(client3, hidUserId);
|
|
56380
56478
|
savedRow = responseValue === null ? rows.find((row) => !beforeValues.has(String(row.value ?? ""))) : rows.find((row) => String(row.value ?? "") === String(responseValue));
|
|
56381
56479
|
if (savedRow || Date.now() >= deadline)
|
|
56382
56480
|
break;
|
|
@@ -56409,7 +56507,7 @@ function useHidAmicoService() {
|
|
|
56409
56507
|
return { readerId, hidUserId, card, verified: true };
|
|
56410
56508
|
} catch (error) {
|
|
56411
56509
|
try {
|
|
56412
|
-
await
|
|
56510
|
+
await client3.cancelRemoteEnrollment();
|
|
56413
56511
|
} catch {
|
|
56414
56512
|
}
|
|
56415
56513
|
await repo.addEvent({
|
|
@@ -56422,15 +56520,15 @@ function useHidAmicoService() {
|
|
|
56422
56520
|
throw error;
|
|
56423
56521
|
} finally {
|
|
56424
56522
|
await repo.releaseEnrollmentLock(readerId, lockOwner);
|
|
56425
|
-
await
|
|
56523
|
+
await client3.logout();
|
|
56426
56524
|
}
|
|
56427
56525
|
}
|
|
56428
56526
|
async function cancelUserCardEnrollment(readerId) {
|
|
56429
56527
|
const reader = await getActiveReader(readerId);
|
|
56430
|
-
const
|
|
56528
|
+
const client3 = new HidAmicoClient(reader);
|
|
56431
56529
|
try {
|
|
56432
|
-
await
|
|
56433
|
-
await
|
|
56530
|
+
await client3.login();
|
|
56531
|
+
await client3.cancelRemoteEnrollment();
|
|
56434
56532
|
const enrollmentWasRunning = await repo.releaseEnrollmentLock(readerId);
|
|
56435
56533
|
await repo.addEvent({
|
|
56436
56534
|
reader: readerId,
|
|
@@ -56440,27 +56538,27 @@ function useHidAmicoService() {
|
|
|
56440
56538
|
});
|
|
56441
56539
|
return { readerId, cancelled: true };
|
|
56442
56540
|
} finally {
|
|
56443
|
-
await
|
|
56541
|
+
await client3.logout();
|
|
56444
56542
|
}
|
|
56445
56543
|
}
|
|
56446
56544
|
async function deleteUserCard(readerId, hidUserIdValue, cardIdValue) {
|
|
56447
56545
|
const reader = await getActiveReader(readerId);
|
|
56448
56546
|
const hidUserId = Number(hidUserIdValue);
|
|
56449
56547
|
const cardId = Number(cardIdValue);
|
|
56450
|
-
const
|
|
56548
|
+
const client3 = new HidAmicoClient(reader);
|
|
56451
56549
|
try {
|
|
56452
|
-
await
|
|
56453
|
-
const rows = await loadPhysicalCardRows(
|
|
56550
|
+
await client3.login();
|
|
56551
|
+
const rows = await loadPhysicalCardRows(client3, hidUserId);
|
|
56454
56552
|
const cardRow = rows.find((row) => String(row.id ?? "") === String(cardId));
|
|
56455
56553
|
if (!cardRow) {
|
|
56456
56554
|
throw new import_node_server_utils149.BadRequestError("Physical HID card was not found for this HID user.");
|
|
56457
56555
|
}
|
|
56458
56556
|
const cardValue = String(normalizeHidCardValue(cardRow.value));
|
|
56459
|
-
await
|
|
56557
|
+
await client3.destroyObjects({
|
|
56460
56558
|
object: "cards",
|
|
56461
56559
|
where: { cards: { id: cardId } }
|
|
56462
56560
|
});
|
|
56463
|
-
const verifiedRows = await loadPhysicalCardRows(
|
|
56561
|
+
const verifiedRows = await loadPhysicalCardRows(client3, hidUserId);
|
|
56464
56562
|
if (verifiedRows.some((row) => String(row.id ?? "") === String(cardId))) {
|
|
56465
56563
|
throw new import_node_server_utils149.BadRequestError("The HID reader did not remove the physical card.");
|
|
56466
56564
|
}
|
|
@@ -56483,17 +56581,17 @@ function useHidAmicoService() {
|
|
|
56483
56581
|
});
|
|
56484
56582
|
throw error;
|
|
56485
56583
|
} finally {
|
|
56486
|
-
await
|
|
56584
|
+
await client3.logout();
|
|
56487
56585
|
}
|
|
56488
56586
|
}
|
|
56489
56587
|
async function getUserPinStatus(readerId, hidUserIdValue) {
|
|
56490
56588
|
const reader = await getActiveReader(readerId);
|
|
56491
56589
|
assertReaderCapability(reader, "pin");
|
|
56492
56590
|
const hidUserId = Number(hidUserIdValue);
|
|
56493
|
-
const
|
|
56591
|
+
const client3 = new HidAmicoClient(reader);
|
|
56494
56592
|
try {
|
|
56495
|
-
await
|
|
56496
|
-
const response = await
|
|
56593
|
+
await client3.login();
|
|
56594
|
+
const response = await client3.loadObjects({
|
|
56497
56595
|
object: "pins",
|
|
56498
56596
|
where: { pins: { user_id: hidUserId } },
|
|
56499
56597
|
limit: 1,
|
|
@@ -56501,7 +56599,7 @@ function useHidAmicoService() {
|
|
|
56501
56599
|
});
|
|
56502
56600
|
return { readerId, hidUserId, pinEnrolled: getHidObjectRows(response, "pins").length > 0 };
|
|
56503
56601
|
} finally {
|
|
56504
|
-
await
|
|
56602
|
+
await client3.logout();
|
|
56505
56603
|
}
|
|
56506
56604
|
}
|
|
56507
56605
|
async function setUserPin(readerId, hidUserIdValue, pin) {
|
|
@@ -56509,10 +56607,10 @@ function useHidAmicoService() {
|
|
|
56509
56607
|
assertReaderCapability(reader, "pin");
|
|
56510
56608
|
const hidUserId = Number(hidUserIdValue);
|
|
56511
56609
|
const credentialId = createStableHidId(`user-pin:${readerId}:${hidUserId}`);
|
|
56512
|
-
const
|
|
56610
|
+
const client3 = new HidAmicoClient(reader);
|
|
56513
56611
|
try {
|
|
56514
|
-
await
|
|
56515
|
-
const userResponse = await
|
|
56612
|
+
await client3.login();
|
|
56613
|
+
const userResponse = await client3.loadObjects({
|
|
56516
56614
|
object: "users",
|
|
56517
56615
|
where: { users: { id: hidUserId } },
|
|
56518
56616
|
limit: 1,
|
|
@@ -56522,13 +56620,13 @@ function useHidAmicoService() {
|
|
|
56522
56620
|
throw new import_node_server_utils149.BadRequestError("HID user must exist before assigning an access PIN.");
|
|
56523
56621
|
}
|
|
56524
56622
|
const [byUserResponse, byValueResponse] = await Promise.all([
|
|
56525
|
-
|
|
56623
|
+
client3.loadObjects({
|
|
56526
56624
|
object: "pins",
|
|
56527
56625
|
where: { pins: { user_id: hidUserId } },
|
|
56528
56626
|
limit: 10,
|
|
56529
56627
|
offset: 0
|
|
56530
56628
|
}),
|
|
56531
|
-
|
|
56629
|
+
client3.loadObjects({
|
|
56532
56630
|
object: "pins",
|
|
56533
56631
|
where: { pins: { value: pin } },
|
|
56534
56632
|
limit: 10,
|
|
@@ -56544,18 +56642,18 @@ function useHidAmicoService() {
|
|
|
56544
56642
|
}
|
|
56545
56643
|
const existingPin = existingPins[0];
|
|
56546
56644
|
if (existingPin) {
|
|
56547
|
-
await
|
|
56645
|
+
await client3.modifyObjects({
|
|
56548
56646
|
object: "pins",
|
|
56549
56647
|
where: { pins: { id: existingPin.id } },
|
|
56550
56648
|
values: { value: pin, user_id: hidUserId }
|
|
56551
56649
|
});
|
|
56552
56650
|
} else {
|
|
56553
|
-
await
|
|
56651
|
+
await client3.createObjects({
|
|
56554
56652
|
object: "pins",
|
|
56555
56653
|
values: [{ id: credentialId, value: pin, user_id: hidUserId }]
|
|
56556
56654
|
});
|
|
56557
56655
|
}
|
|
56558
|
-
const savedResponse = await
|
|
56656
|
+
const savedResponse = await client3.loadObjects({
|
|
56559
56657
|
object: "pins",
|
|
56560
56658
|
where: { pins: { user_id: hidUserId } },
|
|
56561
56659
|
limit: 1,
|
|
@@ -56565,7 +56663,7 @@ function useHidAmicoService() {
|
|
|
56565
56663
|
if (!savedPin || String(savedPin.value) !== pin) {
|
|
56566
56664
|
throw new import_node_server_utils149.BadRequestError("The HID reader did not retain the access PIN.");
|
|
56567
56665
|
}
|
|
56568
|
-
await
|
|
56666
|
+
await client3.setConfiguration({
|
|
56569
56667
|
identifier: {
|
|
56570
56668
|
pin_identification_enabled: "1",
|
|
56571
56669
|
multi_factor_authentication: "0"
|
|
@@ -56589,17 +56687,17 @@ function useHidAmicoService() {
|
|
|
56589
56687
|
});
|
|
56590
56688
|
throw error;
|
|
56591
56689
|
} finally {
|
|
56592
|
-
await
|
|
56690
|
+
await client3.logout();
|
|
56593
56691
|
}
|
|
56594
56692
|
}
|
|
56595
56693
|
async function deleteUserPin(readerId, hidUserIdValue) {
|
|
56596
56694
|
const reader = await getActiveReader(readerId);
|
|
56597
56695
|
assertReaderCapability(reader, "pin");
|
|
56598
56696
|
const hidUserId = Number(hidUserIdValue);
|
|
56599
|
-
const
|
|
56697
|
+
const client3 = new HidAmicoClient(reader);
|
|
56600
56698
|
try {
|
|
56601
|
-
await
|
|
56602
|
-
await
|
|
56699
|
+
await client3.login();
|
|
56700
|
+
await client3.destroyObjects({
|
|
56603
56701
|
object: "pins",
|
|
56604
56702
|
where: { pins: { user_id: hidUserId } }
|
|
56605
56703
|
});
|
|
@@ -56621,7 +56719,7 @@ function useHidAmicoService() {
|
|
|
56621
56719
|
});
|
|
56622
56720
|
throw error;
|
|
56623
56721
|
} finally {
|
|
56624
|
-
await
|
|
56722
|
+
await client3.logout();
|
|
56625
56723
|
}
|
|
56626
56724
|
}
|
|
56627
56725
|
async function revokeVisitorQr(readerId, visitorId) {
|
|
@@ -56633,44 +56731,44 @@ function useHidAmicoService() {
|
|
|
56633
56731
|
"The generated HID user ID is assigned to another visitor."
|
|
56634
56732
|
);
|
|
56635
56733
|
}
|
|
56636
|
-
const
|
|
56734
|
+
const client3 = new HidAmicoClient(reader);
|
|
56637
56735
|
try {
|
|
56638
|
-
await
|
|
56639
|
-
const existingUserResponse = await
|
|
56736
|
+
await client3.login();
|
|
56737
|
+
const existingUserResponse = await client3.loadObjects({
|
|
56640
56738
|
object: "users",
|
|
56641
56739
|
where: { users: { id: hidUserId } },
|
|
56642
56740
|
limit: 1,
|
|
56643
56741
|
offset: 0
|
|
56644
56742
|
});
|
|
56645
56743
|
const deviceUserExists = getHidObjectRows(existingUserResponse, "users").length > 0;
|
|
56646
|
-
await
|
|
56744
|
+
await client3.destroyObjects({
|
|
56647
56745
|
object: "qrcodes",
|
|
56648
56746
|
where: { qrcodes: { user_id: hidUserId } }
|
|
56649
56747
|
});
|
|
56650
|
-
await
|
|
56748
|
+
await client3.destroyObjects({
|
|
56651
56749
|
object: "cards",
|
|
56652
56750
|
where: { cards: { user_id: hidUserId } }
|
|
56653
56751
|
});
|
|
56654
56752
|
if (reader.capabilities?.pin === true) {
|
|
56655
|
-
await
|
|
56753
|
+
await client3.destroyObjects({
|
|
56656
56754
|
object: "pins",
|
|
56657
56755
|
where: { pins: { user_id: hidUserId } }
|
|
56658
56756
|
});
|
|
56659
56757
|
}
|
|
56660
|
-
await
|
|
56758
|
+
await client3.destroyObjects({
|
|
56661
56759
|
object: "user_access_rules",
|
|
56662
56760
|
where: { user_access_rules: { user_id: hidUserId } }
|
|
56663
56761
|
});
|
|
56664
|
-
await
|
|
56762
|
+
await client3.destroyObjects({
|
|
56665
56763
|
object: "user_groups",
|
|
56666
56764
|
where: { user_groups: { user_id: hidUserId } }
|
|
56667
56765
|
});
|
|
56668
56766
|
const metadata = identity && isUnknownRecord2(identity.metadata) ? identity.metadata : {};
|
|
56669
56767
|
if (deviceUserExists && metadata.facialEnrolled === true) {
|
|
56670
|
-
await
|
|
56768
|
+
await client3.deleteUserImage(hidUserId);
|
|
56671
56769
|
}
|
|
56672
56770
|
if (deviceUserExists) {
|
|
56673
|
-
await
|
|
56771
|
+
await client3.modifyObjects({
|
|
56674
56772
|
object: "users",
|
|
56675
56773
|
where: { users: { id: hidUserId } },
|
|
56676
56774
|
values: { end_time: Math.floor(Date.now() / 1e3) }
|
|
@@ -56681,7 +56779,7 @@ function useHidAmicoService() {
|
|
|
56681
56779
|
if (reader.capabilities?.pin === true)
|
|
56682
56780
|
credentialObjects.push("pins");
|
|
56683
56781
|
for (const object of credentialObjects) {
|
|
56684
|
-
const response = await
|
|
56782
|
+
const response = await client3.loadObjects({
|
|
56685
56783
|
object,
|
|
56686
56784
|
where: { [object]: { user_id: hidUserId } },
|
|
56687
56785
|
limit: 1,
|
|
@@ -56689,7 +56787,7 @@ function useHidAmicoService() {
|
|
|
56689
56787
|
});
|
|
56690
56788
|
credentialRemains || (credentialRemains = getHidObjectRows(response, object).length > 0);
|
|
56691
56789
|
}
|
|
56692
|
-
const savedUser = await
|
|
56790
|
+
const savedUser = await client3.loadObjects({
|
|
56693
56791
|
object: "users",
|
|
56694
56792
|
where: { users: { id: hidUserId } },
|
|
56695
56793
|
limit: 1,
|
|
@@ -56727,7 +56825,7 @@ function useHidAmicoService() {
|
|
|
56727
56825
|
});
|
|
56728
56826
|
throw error;
|
|
56729
56827
|
} finally {
|
|
56730
|
-
await
|
|
56828
|
+
await client3.logout();
|
|
56731
56829
|
}
|
|
56732
56830
|
}
|
|
56733
56831
|
async function queueVisitorQrJob(readerId, visitorId, operation) {
|
|
@@ -56837,16 +56935,16 @@ function useHidAmicoService() {
|
|
|
56837
56935
|
const reader = await getActiveReader(readerId);
|
|
56838
56936
|
assertReaderCapability(reader, "facial");
|
|
56839
56937
|
assertReaderPortal(reader, "enrolling facial recognition");
|
|
56840
|
-
const
|
|
56938
|
+
const client3 = new HidAmicoClient(reader);
|
|
56841
56939
|
const timestamp = options.timestamp || Math.floor(Date.now() / 1e3);
|
|
56842
56940
|
const match = options.match ?? true;
|
|
56843
56941
|
try {
|
|
56844
|
-
await
|
|
56942
|
+
await client3.login();
|
|
56845
56943
|
const numericUserId = Number(hidUserId);
|
|
56846
56944
|
if (!Number.isSafeInteger(numericUserId) || numericUserId <= 0) {
|
|
56847
56945
|
throw new import_node_server_utils149.BadRequestError("A valid HID user ID is required for facial enrollment.");
|
|
56848
56946
|
}
|
|
56849
|
-
const result = await
|
|
56947
|
+
const result = await client3.setUserImage(numericUserId, image, timestamp, match);
|
|
56850
56948
|
await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56851
56949
|
await repo.addEvent({
|
|
56852
56950
|
reader: readerId,
|
|
@@ -56870,16 +56968,16 @@ function useHidAmicoService() {
|
|
|
56870
56968
|
});
|
|
56871
56969
|
throw error;
|
|
56872
56970
|
} finally {
|
|
56873
|
-
await
|
|
56971
|
+
await client3.logout();
|
|
56874
56972
|
}
|
|
56875
56973
|
}
|
|
56876
56974
|
async function deleteUserImage(readerId, hidUserId) {
|
|
56877
56975
|
const reader = await getActiveReader(readerId);
|
|
56878
56976
|
assertReaderCapability(reader, "facial");
|
|
56879
|
-
const
|
|
56977
|
+
const client3 = new HidAmicoClient(reader);
|
|
56880
56978
|
try {
|
|
56881
|
-
await
|
|
56882
|
-
const result = await
|
|
56979
|
+
await client3.login();
|
|
56980
|
+
const result = await client3.deleteUserImage(hidUserId);
|
|
56883
56981
|
await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56884
56982
|
await repo.addEvent({
|
|
56885
56983
|
reader: readerId,
|
|
@@ -56897,28 +56995,28 @@ function useHidAmicoService() {
|
|
|
56897
56995
|
});
|
|
56898
56996
|
throw error;
|
|
56899
56997
|
} finally {
|
|
56900
|
-
await
|
|
56998
|
+
await client3.logout();
|
|
56901
56999
|
}
|
|
56902
57000
|
}
|
|
56903
57001
|
async function getDoorState(id) {
|
|
56904
57002
|
const reader = await getActiveReader(id);
|
|
56905
|
-
const
|
|
57003
|
+
const client3 = new HidAmicoClient(reader);
|
|
56906
57004
|
try {
|
|
56907
|
-
await
|
|
56908
|
-
const state = await
|
|
57005
|
+
await client3.login();
|
|
57006
|
+
const state = await client3.doorState();
|
|
56909
57007
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56910
57008
|
await repo.addEvent({ reader: id, site: reader.site, type: "door_state", payload: state });
|
|
56911
57009
|
return state;
|
|
56912
57010
|
} finally {
|
|
56913
|
-
await
|
|
57011
|
+
await client3.logout();
|
|
56914
57012
|
}
|
|
56915
57013
|
}
|
|
56916
57014
|
async function executeActions(id, actions) {
|
|
56917
57015
|
const reader = await getActiveReader(id);
|
|
56918
|
-
const
|
|
57016
|
+
const client3 = new HidAmicoClient(reader);
|
|
56919
57017
|
try {
|
|
56920
|
-
await
|
|
56921
|
-
const result = await
|
|
57018
|
+
await client3.login();
|
|
57019
|
+
const result = await client3.executeActions(actions);
|
|
56922
57020
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56923
57021
|
await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions", payload: { actions, result } });
|
|
56924
57022
|
return result;
|
|
@@ -56926,16 +57024,16 @@ function useHidAmicoService() {
|
|
|
56926
57024
|
await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions_failed", payload: { actions, message: getErrorMessage2(error) } });
|
|
56927
57025
|
throw error;
|
|
56928
57026
|
} finally {
|
|
56929
|
-
await
|
|
57027
|
+
await client3.logout();
|
|
56930
57028
|
}
|
|
56931
57029
|
}
|
|
56932
57030
|
async function getConfiguration(id, payload) {
|
|
56933
57031
|
assertAllowedHidConfigurationRead(payload);
|
|
56934
57032
|
const reader = await getActiveReader(id);
|
|
56935
|
-
const
|
|
57033
|
+
const client3 = new HidAmicoClient(reader);
|
|
56936
57034
|
try {
|
|
56937
|
-
await
|
|
56938
|
-
const result = await
|
|
57035
|
+
await client3.login();
|
|
57036
|
+
const result = await client3.getConfiguration(payload);
|
|
56939
57037
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56940
57038
|
await repo.addEvent({ reader: id, site: reader.site, type: "configuration", payload: { request: payload, result } });
|
|
56941
57039
|
return sanitizeHidPayload(result);
|
|
@@ -56943,7 +57041,7 @@ function useHidAmicoService() {
|
|
|
56943
57041
|
await repo.addEvent({ reader: id, site: reader.site, type: "configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
|
|
56944
57042
|
throw error;
|
|
56945
57043
|
} finally {
|
|
56946
|
-
await
|
|
57044
|
+
await client3.logout();
|
|
56947
57045
|
}
|
|
56948
57046
|
}
|
|
56949
57047
|
async function setConfiguration(id, payload) {
|
|
@@ -56955,10 +57053,10 @@ function useHidAmicoService() {
|
|
|
56955
57053
|
);
|
|
56956
57054
|
}
|
|
56957
57055
|
assertAllowedHidConfiguration(payload);
|
|
56958
|
-
const
|
|
57056
|
+
const client3 = new HidAmicoClient(reader);
|
|
56959
57057
|
try {
|
|
56960
|
-
await
|
|
56961
|
-
const result = await
|
|
57058
|
+
await client3.login();
|
|
57059
|
+
const result = await client3.setConfiguration(payload);
|
|
56962
57060
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
56963
57061
|
await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration", payload: { request: payload, result } });
|
|
56964
57062
|
return sanitizeHidPayload(result);
|
|
@@ -56966,23 +57064,23 @@ function useHidAmicoService() {
|
|
|
56966
57064
|
await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
|
|
56967
57065
|
throw error;
|
|
56968
57066
|
} finally {
|
|
56969
|
-
await
|
|
57067
|
+
await client3.logout();
|
|
56970
57068
|
}
|
|
56971
57069
|
}
|
|
56972
57070
|
async function getIntercomStatus(id) {
|
|
56973
57071
|
const reader = await getActiveReader(id);
|
|
56974
57072
|
assertReaderCapability(reader, "intercom");
|
|
56975
|
-
const
|
|
57073
|
+
const client3 = new HidAmicoClient(reader);
|
|
56976
57074
|
try {
|
|
56977
|
-
await
|
|
57075
|
+
await client3.login();
|
|
56978
57076
|
let result;
|
|
56979
57077
|
try {
|
|
56980
|
-
result = await
|
|
57078
|
+
result = await client3.getSipStatus();
|
|
56981
57079
|
} catch (error) {
|
|
56982
57080
|
if (!isSipStatusUnavailable(error)) {
|
|
56983
57081
|
throw error;
|
|
56984
57082
|
}
|
|
56985
|
-
const configuration = await
|
|
57083
|
+
const configuration = await client3.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
|
|
56986
57084
|
result = buildSipStatusFallback(configuration, error);
|
|
56987
57085
|
}
|
|
56988
57086
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
@@ -56993,16 +57091,16 @@ function useHidAmicoService() {
|
|
|
56993
57091
|
await repo.addEvent({ reader: id, site: reader.site, type: "intercom_status_failed", payload: { message: getErrorMessage2(error) } });
|
|
56994
57092
|
throw error;
|
|
56995
57093
|
} finally {
|
|
56996
|
-
await
|
|
57094
|
+
await client3.logout();
|
|
56997
57095
|
}
|
|
56998
57096
|
}
|
|
56999
57097
|
async function makeIntercomCall(id, target) {
|
|
57000
57098
|
const reader = await getActiveReader(id);
|
|
57001
57099
|
assertReaderCapability(reader, "intercom");
|
|
57002
|
-
const
|
|
57100
|
+
const client3 = new HidAmicoClient(reader);
|
|
57003
57101
|
try {
|
|
57004
|
-
await
|
|
57005
|
-
const result = await
|
|
57102
|
+
await client3.login();
|
|
57103
|
+
const result = await client3.makeSipCall(target);
|
|
57006
57104
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
57007
57105
|
await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call", payload: { target, result } });
|
|
57008
57106
|
return result;
|
|
@@ -57010,16 +57108,16 @@ function useHidAmicoService() {
|
|
|
57010
57108
|
await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call_failed", payload: { target, message: getErrorMessage2(error) } });
|
|
57011
57109
|
throw error;
|
|
57012
57110
|
} finally {
|
|
57013
|
-
await
|
|
57111
|
+
await client3.logout();
|
|
57014
57112
|
}
|
|
57015
57113
|
}
|
|
57016
57114
|
async function finalizeIntercomCall(id) {
|
|
57017
57115
|
const reader = await getActiveReader(id);
|
|
57018
57116
|
assertReaderCapability(reader, "intercom");
|
|
57019
|
-
const
|
|
57117
|
+
const client3 = new HidAmicoClient(reader);
|
|
57020
57118
|
try {
|
|
57021
|
-
await
|
|
57022
|
-
const result = await
|
|
57119
|
+
await client3.login();
|
|
57120
|
+
const result = await client3.finalizeSipCall();
|
|
57023
57121
|
await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
|
|
57024
57122
|
await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup", payload: result || {} });
|
|
57025
57123
|
return result;
|
|
@@ -57027,7 +57125,7 @@ function useHidAmicoService() {
|
|
|
57027
57125
|
await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup_failed", payload: { message: getErrorMessage2(error) } });
|
|
57028
57126
|
throw error;
|
|
57029
57127
|
} finally {
|
|
57030
|
-
await
|
|
57128
|
+
await client3.logout();
|
|
57031
57129
|
}
|
|
57032
57130
|
}
|
|
57033
57131
|
function normalizePermissionLocation(value) {
|
|
@@ -57084,7 +57182,7 @@ function useHidAmicoService() {
|
|
|
57084
57182
|
return "contractor";
|
|
57085
57183
|
return "staff";
|
|
57086
57184
|
}
|
|
57087
|
-
async function provisionPermissionUser(
|
|
57185
|
+
async function provisionPermissionUser(client3, reader, binding) {
|
|
57088
57186
|
const readerId = String(reader._id);
|
|
57089
57187
|
const existingProfile = await repo.findProfileIdentity(readerId, binding.userId);
|
|
57090
57188
|
const hidUserId = toPositiveInteger(existingProfile?.hidUserId) ?? createStableHidId(`profile:${readerId}:${binding.userId}`);
|
|
@@ -57100,7 +57198,7 @@ function useHidAmicoService() {
|
|
|
57100
57198
|
throw new import_node_server_utils149.BadRequestError("The reader already uses this HID user ID for an unmanaged Amico user.");
|
|
57101
57199
|
}
|
|
57102
57200
|
const name2 = String(binding.name || "iService365 User").trim() || "iService365 User";
|
|
57103
|
-
const existingUser = await
|
|
57201
|
+
const existingUser = await client3.loadObjects({
|
|
57104
57202
|
object: "users",
|
|
57105
57203
|
where: { users: { id: hidUserId } },
|
|
57106
57204
|
limit: 1,
|
|
@@ -57108,13 +57206,13 @@ function useHidAmicoService() {
|
|
|
57108
57206
|
});
|
|
57109
57207
|
const userValues = { name: name2, registration };
|
|
57110
57208
|
if (getHidObjectRows(existingUser, "users").length) {
|
|
57111
|
-
await
|
|
57209
|
+
await client3.modifyObjects({
|
|
57112
57210
|
object: "users",
|
|
57113
57211
|
where: { users: { id: hidUserId } },
|
|
57114
57212
|
values: userValues
|
|
57115
57213
|
});
|
|
57116
57214
|
} else {
|
|
57117
|
-
await
|
|
57215
|
+
await client3.createObjects({
|
|
57118
57216
|
object: "users",
|
|
57119
57217
|
values: [{ id: hidUserId, ...userValues }]
|
|
57120
57218
|
});
|
|
@@ -57154,14 +57252,14 @@ function useHidAmicoService() {
|
|
|
57154
57252
|
const uniqueBindings = [...new Map(
|
|
57155
57253
|
bindings.map((binding) => [String(binding.userId), binding])
|
|
57156
57254
|
).values()];
|
|
57157
|
-
const
|
|
57255
|
+
const client3 = new HidAmicoClient(reader);
|
|
57158
57256
|
try {
|
|
57159
|
-
await
|
|
57257
|
+
await client3.login();
|
|
57160
57258
|
const uniqueUserIds = await Promise.all(
|
|
57161
|
-
uniqueBindings.map((binding) => provisionPermissionUser(
|
|
57259
|
+
uniqueBindings.map((binding) => provisionPermissionUser(client3, reader, binding))
|
|
57162
57260
|
);
|
|
57163
57261
|
const result = await reconcileStandaloneGroupAccess(
|
|
57164
|
-
|
|
57262
|
+
client3,
|
|
57165
57263
|
readerId,
|
|
57166
57264
|
Number(reader.portalId),
|
|
57167
57265
|
uniqueUserIds
|
|
@@ -57184,7 +57282,7 @@ function useHidAmicoService() {
|
|
|
57184
57282
|
});
|
|
57185
57283
|
throw error;
|
|
57186
57284
|
} finally {
|
|
57187
|
-
await
|
|
57285
|
+
await client3.logout();
|
|
57188
57286
|
}
|
|
57189
57287
|
}
|
|
57190
57288
|
async function reconcileStoredReaderPermissions(readerId) {
|
|
@@ -68755,11 +68853,11 @@ function buildingInPlanFrame(building) {
|
|
|
68755
68853
|
lifts
|
|
68756
68854
|
};
|
|
68757
68855
|
}
|
|
68758
|
-
function openRmfDoorDriver(
|
|
68856
|
+
function openRmfDoorDriver(client3, doorName) {
|
|
68759
68857
|
return {
|
|
68760
68858
|
name: doorName,
|
|
68761
68859
|
async read() {
|
|
68762
|
-
const s = await
|
|
68860
|
+
const s = await client3.doorState(doorName).catch((e) => {
|
|
68763
68861
|
if (/HTTP 404/.test(String(e?.message)))
|
|
68764
68862
|
return null;
|
|
68765
68863
|
throw e;
|
|
@@ -68777,13 +68875,13 @@ function openRmfDoorDriver(client2, doorName) {
|
|
|
68777
68875
|
if (request2.requestedMode !== DOOR_MODE.OPEN && request2.requestedMode !== DOOR_MODE.CLOSED) {
|
|
68778
68876
|
throw new OpenRmfError("A door can only be asked to open or close.");
|
|
68779
68877
|
}
|
|
68780
|
-
await
|
|
68878
|
+
await client3.doorRequest(doorName, request2.requestedMode);
|
|
68781
68879
|
}
|
|
68782
68880
|
};
|
|
68783
68881
|
}
|
|
68784
|
-
function openRmfLiftDriver(
|
|
68882
|
+
function openRmfLiftDriver(client3, liftName) {
|
|
68785
68883
|
const destinations = /* @__PURE__ */ new Map();
|
|
68786
|
-
const send2 = (requestType, sessionId, destination, doorState) =>
|
|
68884
|
+
const send2 = (requestType, sessionId, destination, doorState) => client3.liftRequest(liftName, {
|
|
68787
68885
|
request_type: requestType,
|
|
68788
68886
|
door_mode: doorState,
|
|
68789
68887
|
destination,
|
|
@@ -68792,7 +68890,7 @@ function openRmfLiftDriver(client2, liftName) {
|
|
|
68792
68890
|
return {
|
|
68793
68891
|
name: liftName,
|
|
68794
68892
|
async read() {
|
|
68795
|
-
const s = await
|
|
68893
|
+
const s = await client3.liftState(liftName).catch((e) => {
|
|
68796
68894
|
if (/HTTP 404/.test(String(e?.message)))
|
|
68797
68895
|
return null;
|
|
68798
68896
|
throw e;
|
|
@@ -68828,18 +68926,18 @@ function openRmfLiftDriver(client2, liftName) {
|
|
|
68828
68926
|
};
|
|
68829
68927
|
}
|
|
68830
68928
|
function createOpenRmfAdapter(options) {
|
|
68831
|
-
const
|
|
68929
|
+
const client3 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
|
|
68832
68930
|
fetch: options?.fetch,
|
|
68833
68931
|
timeoutMs: options?.timeoutMs
|
|
68834
68932
|
});
|
|
68835
68933
|
async function states() {
|
|
68836
|
-
const [fleets, building] = await Promise.all([
|
|
68934
|
+
const [fleets, building] = await Promise.all([client3.fleets(), client3.buildingMap().catch(() => null)]);
|
|
68837
68935
|
return { fleets: fleets ?? [], building };
|
|
68838
68936
|
}
|
|
68839
68937
|
async function openInterruptions(taskId) {
|
|
68840
68938
|
if (!taskId)
|
|
68841
68939
|
return [];
|
|
68842
|
-
const t = await
|
|
68940
|
+
const t = await client3.taskState(taskId).catch(() => null);
|
|
68843
68941
|
return Object.entries(t?.interruptions ?? {}).filter(([, v]) => !v?.resumed_by).map(([token]) => token);
|
|
68844
68942
|
}
|
|
68845
68943
|
async function find(robotSn) {
|
|
@@ -68851,7 +68949,7 @@ function createOpenRmfAdapter(options) {
|
|
|
68851
68949
|
return s ? { key: key2, s, building } : null;
|
|
68852
68950
|
}
|
|
68853
68951
|
return {
|
|
68854
|
-
client:
|
|
68952
|
+
client: client3,
|
|
68855
68953
|
brand: OPEN_RMF_BRAND,
|
|
68856
68954
|
displayName: OPEN_RMF_DISPLAY_NAME,
|
|
68857
68955
|
capabilities: OPEN_RMF_CAPABILITIES,
|
|
@@ -68878,9 +68976,9 @@ function createOpenRmfAdapter(options) {
|
|
|
68878
68976
|
const tokens = await openInterruptions(taskId);
|
|
68879
68977
|
if (!tokens.length)
|
|
68880
68978
|
throw new OpenRmfError("This robot's task is not paused.");
|
|
68881
|
-
res2 = await
|
|
68979
|
+
res2 = await client3.resumeTask(taskId, tokens);
|
|
68882
68980
|
} else {
|
|
68883
|
-
res2 = command.kind === "pause" ? await
|
|
68981
|
+
res2 = command.kind === "pause" ? await client3.interruptTask(taskId) : await client3.cancelTask(taskId);
|
|
68884
68982
|
}
|
|
68885
68983
|
if (res2 && res2.success === false)
|
|
68886
68984
|
throw new OpenRmfError(`The fleet server refused to ${command.kind} the task.`);
|
|
@@ -68888,7 +68986,7 @@ function createOpenRmfAdapter(options) {
|
|
|
68888
68986
|
}
|
|
68889
68987
|
const wp = waypointsFor(hit.building, hit.s.location);
|
|
68890
68988
|
const request2 = taskRequestFor(command, wp.cleaningZones.length ? "cleaning" : "security", wp);
|
|
68891
|
-
const res = await
|
|
68989
|
+
const res = await client3.robotTask(hit.key.fleet, hit.key.robot, request2);
|
|
68892
68990
|
if (!res?.success)
|
|
68893
68991
|
throw new OpenRmfError("The fleet server did not accept the task.");
|
|
68894
68992
|
},
|
|
@@ -68904,7 +69002,7 @@ function createOpenRmfAdapter(options) {
|
|
|
68904
69002
|
const taskId = hit?.s.task_id;
|
|
68905
69003
|
if (!hit || !taskId)
|
|
68906
69004
|
return none;
|
|
68907
|
-
const t = await
|
|
69005
|
+
const t = await client3.taskState(taskId).catch(() => null);
|
|
68908
69006
|
if (!t || !/^patrol$/i.test(String(t.category ?? "")))
|
|
68909
69007
|
return none;
|
|
68910
69008
|
const level2 = hit.building?.levels.find((l) => l.name === hit.s.location?.map);
|
|
@@ -69999,10 +70097,10 @@ function fetchPadbotMqttCredentials(credentials) {
|
|
|
69999
70097
|
return createPadbotClient(credentials).call(PADBOT_PATHS.mqttCredentials, {});
|
|
70000
70098
|
}
|
|
70001
70099
|
async function listPadbotAlarmsSince(credentials, serials, startTime) {
|
|
70002
|
-
const
|
|
70100
|
+
const client3 = createPadbotClient(credentials);
|
|
70003
70101
|
const out = [];
|
|
70004
70102
|
for (let p = 1; p <= 3; p++) {
|
|
70005
|
-
const d = await
|
|
70103
|
+
const d = await client3.call(PADBOT_PATHS.alarms, { serialNumbers: serials.slice(0, 100), startTime, pageNumber: p, pageSize: 100 });
|
|
70006
70104
|
out.push(...asList(d));
|
|
70007
70105
|
if (p >= (Number(d?.totalPages) || 0))
|
|
70008
70106
|
break;
|
|
@@ -75202,16 +75300,16 @@ function useRobotMapController(deps) {
|
|
|
75202
75300
|
const config2 = openRmfConfig();
|
|
75203
75301
|
if (!config2)
|
|
75204
75302
|
throw new import_node_server_utils175.NotFoundError("Fleet Core is not configured on this server.");
|
|
75205
|
-
const
|
|
75303
|
+
const client3 = createOpenRmfClient(config2);
|
|
75206
75304
|
if (value.format === "rmf") {
|
|
75207
|
-
const rmf = rmfFromFleetCore(await
|
|
75305
|
+
const rmf = rmfFromFleetCore(await client3.buildingMap());
|
|
75208
75306
|
res.json({ source: "fleet-core", rmf, summary: rmfSummary(rmf) });
|
|
75209
75307
|
return;
|
|
75210
75308
|
}
|
|
75211
|
-
const building = buildingInPlanFrame(await
|
|
75309
|
+
const building = buildingInPlanFrame(await client3.buildingMap());
|
|
75212
75310
|
const [doorStates, liftStates] = await Promise.all([
|
|
75213
|
-
Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(
|
|
75214
|
-
Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(
|
|
75311
|
+
Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client3, d.name).read().catch(() => null))),
|
|
75312
|
+
Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(client3, l.name).read().catch(() => null)))
|
|
75215
75313
|
]);
|
|
75216
75314
|
res.json({
|
|
75217
75315
|
source: "fleet-core",
|
|
@@ -101298,11 +101396,11 @@ function useAuthServiceV2() {
|
|
|
101298
101396
|
"Refresh token already used. Please log in again."
|
|
101299
101397
|
);
|
|
101300
101398
|
}
|
|
101301
|
-
const
|
|
101302
|
-
if (!
|
|
101399
|
+
const client3 = import_node_server_utils292.useAtlas.getClient();
|
|
101400
|
+
if (!client3) {
|
|
101303
101401
|
throw new import_node_server_utils292.InternalServerError("Unable to connect to server.");
|
|
101304
101402
|
}
|
|
101305
|
-
const dbSession =
|
|
101403
|
+
const dbSession = client3.startSession();
|
|
101306
101404
|
let newRefreshToken;
|
|
101307
101405
|
try {
|
|
101308
101406
|
dbSession.startTransaction();
|
|
@@ -103033,7 +103131,7 @@ function useUserServiceV2() {
|
|
|
103033
103131
|
session?.endSession();
|
|
103034
103132
|
}
|
|
103035
103133
|
}
|
|
103036
|
-
const
|
|
103134
|
+
const s33 = new import_node_server_utils296.useS3({
|
|
103037
103135
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
103038
103136
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
103039
103137
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -103054,14 +103152,14 @@ function useUserServiceV2() {
|
|
|
103054
103152
|
};
|
|
103055
103153
|
try {
|
|
103056
103154
|
const id = await createFile(_file, session);
|
|
103057
|
-
await
|
|
103155
|
+
await putSpacesObject({
|
|
103058
103156
|
key: id,
|
|
103059
103157
|
body: file.buffer,
|
|
103060
103158
|
contentType: file.mimetype
|
|
103061
103159
|
});
|
|
103062
103160
|
if (previousProfile) {
|
|
103063
103161
|
await deleteFileById(previousProfile, session);
|
|
103064
|
-
await
|
|
103162
|
+
await s33.deleteObject(previousProfile);
|
|
103065
103163
|
}
|
|
103066
103164
|
await _updateUserFieldById(
|
|
103067
103165
|
{ _id: user, field: "profile", value: id },
|
|
@@ -105958,10 +106056,10 @@ function useChatPrelovedService() {
|
|
|
105958
106056
|
const { add: _addChat } = useChatPrelovedRepo();
|
|
105959
106057
|
const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
|
|
105960
106058
|
async function add(value) {
|
|
105961
|
-
const
|
|
105962
|
-
if (!
|
|
106059
|
+
const client3 = import_node_server_utils314.useAtlas.getClient();
|
|
106060
|
+
if (!client3)
|
|
105963
106061
|
throw new import_node_server_utils314.InternalServerError("Unable to connect to server.");
|
|
105964
|
-
const session =
|
|
106062
|
+
const session = client3.startSession();
|
|
105965
106063
|
session.startTransaction();
|
|
105966
106064
|
try {
|
|
105967
106065
|
let channelId = value.channelId;
|
|
@@ -106414,14 +106512,14 @@ function useBidPrelovedService() {
|
|
|
106414
106512
|
const { add: _addChat } = useChatPrelovedRepo();
|
|
106415
106513
|
const { updateStatus } = usePostPrelovedRepo();
|
|
106416
106514
|
async function createBid(value) {
|
|
106417
|
-
const
|
|
106418
|
-
if (!
|
|
106515
|
+
const client3 = import_node_server_utils320.useAtlas.getClient();
|
|
106516
|
+
if (!client3)
|
|
106419
106517
|
throw new import_node_server_utils320.InternalServerError("Unable to connect to server.");
|
|
106420
106518
|
const buyerId = value.buyerId;
|
|
106421
106519
|
const receiverId = value.receiverId;
|
|
106422
106520
|
const postId = value.postId;
|
|
106423
106521
|
const messageText = value.message || "";
|
|
106424
|
-
const session =
|
|
106522
|
+
const session = client3.startSession();
|
|
106425
106523
|
session.startTransaction();
|
|
106426
106524
|
try {
|
|
106427
106525
|
const bidId = await _addBid(value, session);
|
|
@@ -108688,8 +108786,8 @@ async function staffOnly(req) {
|
|
|
108688
108786
|
}
|
|
108689
108787
|
async function clientAndSites(org) {
|
|
108690
108788
|
const d = db2();
|
|
108691
|
-
const
|
|
108692
|
-
if (!
|
|
108789
|
+
const client3 = await d.collection("organizations").findOne({ _id: new import_mongodb201.ObjectId(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
|
|
108790
|
+
if (!client3)
|
|
108693
108791
|
throw new import_node_server_utils330.NotFoundError("Client not found.");
|
|
108694
108792
|
const own = await d.collection("sites").find({ orgId: both3(org), status: { $ne: "deleted" } }, { projection: { name: 1 } }).toArray();
|
|
108695
108793
|
const served = await d.collection("customer.sites").find({ org: both3(org), status: { $ne: "deleted" }, site: { $exists: true, $nin: [null, ""] } }, { projection: { name: 1, site: 1 } }).toArray();
|
|
@@ -108702,7 +108800,7 @@ async function clientAndSites(org) {
|
|
|
108702
108800
|
sites.set(id, String(s.name ?? ""));
|
|
108703
108801
|
}
|
|
108704
108802
|
return {
|
|
108705
|
-
client: { _id: org, name: String(
|
|
108803
|
+
client: { _id: org, name: String(client3.name ?? ""), nature: String(client3.nature ?? "") },
|
|
108706
108804
|
sites: [...sites].map(([_id, name2]) => ({ _id, name: name2 })).sort((a, b) => a.name.localeCompare(b.name))
|
|
108707
108805
|
};
|
|
108708
108806
|
}
|
|
@@ -108770,14 +108868,14 @@ function useStaffAccessController() {
|
|
|
108770
108868
|
const sid = getSessionIdFromRequest(req);
|
|
108771
108869
|
if (!sid)
|
|
108772
108870
|
throw new import_node_server_utils330.UnauthorizedError("Not authorized.");
|
|
108773
|
-
const { client:
|
|
108871
|
+
const { client: client3, sites: list } = await clientAndSites(value.org);
|
|
108774
108872
|
const site = value.site ? list.find((s) => s._id === value.site) : null;
|
|
108775
108873
|
if (value.site && !site)
|
|
108776
108874
|
throw new import_node_server_utils330.BadRequestError("That site does not belong to this client.");
|
|
108777
108875
|
const view = {
|
|
108778
108876
|
user: actor,
|
|
108779
|
-
org:
|
|
108780
|
-
orgName:
|
|
108877
|
+
org: client3._id,
|
|
108878
|
+
orgName: client3.name,
|
|
108781
108879
|
site: site?._id ?? "",
|
|
108782
108880
|
siteName: site?.name ?? "",
|
|
108783
108881
|
app: value.app,
|
|
@@ -108787,8 +108885,8 @@ function useStaffAccessController() {
|
|
|
108787
108885
|
await recordConsoleAction({
|
|
108788
108886
|
action: "staff-view.entered" /* STAFF_VIEW_ENTERED */,
|
|
108789
108887
|
actor,
|
|
108790
|
-
org:
|
|
108791
|
-
target: view.site ||
|
|
108888
|
+
org: client3._id,
|
|
108889
|
+
target: view.site || client3._id,
|
|
108792
108890
|
targetType: view.site ? "site" /* SITE */ : "organization" /* ORGANIZATION */,
|
|
108793
108891
|
after: pickAuditFields("staff-view.entered" /* STAFF_VIEW_ENTERED */, { ...view, reason: value.reason }) ?? null
|
|
108794
108892
|
});
|