@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/dist/index.mjs CHANGED
@@ -5132,11 +5132,11 @@ function useAuthService() {
5132
5132
  "Refresh token already used. Please log in again."
5133
5133
  );
5134
5134
  }
5135
- const client2 = useAtlas12.getClient();
5136
- if (!client2) {
5135
+ const client3 = useAtlas12.getClient();
5136
+ if (!client3) {
5137
5137
  throw new InternalServerError7("Unable to connect to server.");
5138
5138
  }
5139
- const dbSession = client2.startSession();
5139
+ const dbSession = client3.startSession();
5140
5140
  let newRefreshToken;
5141
5141
  try {
5142
5142
  dbSession.startTransaction();
@@ -8252,7 +8252,7 @@ var SP_INVITE_TYPES = [
8252
8252
  function escapeRegex(value) {
8253
8253
  return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8254
8254
  }
8255
- function relationshipMatch(org, relationship, client2) {
8255
+ function relationshipMatch(org, relationship, client3) {
8256
8256
  const self = [org, String(org)];
8257
8257
  const match = {};
8258
8258
  const and = [];
@@ -8261,9 +8261,9 @@ function relationshipMatch(org, relationship, client2) {
8261
8261
  } else if (relationship === "served") {
8262
8262
  and.push({ siteOrg: { $nin: [...self, null, ""] } });
8263
8263
  }
8264
- if (client2) {
8264
+ if (client3) {
8265
8265
  and.push(
8266
- { siteOrg: { $in: [client2, String(client2)] } },
8266
+ { siteOrg: { $in: [client3, String(client3)] } },
8267
8267
  { siteOrg: { $nin: self } }
8268
8268
  );
8269
8269
  }
@@ -8426,7 +8426,7 @@ function useCustomerSiteRepo() {
8426
8426
  status = "active",
8427
8427
  siteScope = null,
8428
8428
  relationship = "",
8429
- client: client2 = "",
8429
+ client: client3 = "",
8430
8430
  category = ""
8431
8431
  }, session) {
8432
8432
  page2 = page2 > 0 ? page2 - 1 : 0;
@@ -8440,9 +8440,9 @@ function useCustomerSiteRepo() {
8440
8440
  status
8441
8441
  };
8442
8442
  let clientId = null;
8443
- if (client2) {
8443
+ if (client3) {
8444
8444
  try {
8445
- clientId = new ObjectId26(client2);
8445
+ clientId = new ObjectId26(client3);
8446
8446
  } catch (error) {
8447
8447
  throw new BadRequestError24("Invalid client ID format.");
8448
8448
  }
@@ -8465,8 +8465,8 @@ function useCustomerSiteRepo() {
8465
8465
  }
8466
8466
  if (relationship)
8467
8467
  cacheOptions.relationship = relationship;
8468
- if (client2)
8469
- cacheOptions.client = client2;
8468
+ if (client3)
8469
+ cacheOptions.client = client3;
8470
8470
  if (category)
8471
8471
  cacheOptions.category = category;
8472
8472
  const cacheKey = makeCacheKey10(namespace_collection3, cacheOptions);
@@ -18099,6 +18099,76 @@ function useVehicleRepo() {
18099
18099
  };
18100
18100
  }
18101
18101
 
18102
+ // src/services/spaces-object.service.ts
18103
+ import { GetObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
18104
+
18105
+ // src/utils/spaces-object.util.ts
18106
+ function spacesUploadAcl(key2, setting = process.env.SPACES_PRIVATE_PREFIXES ?? "") {
18107
+ const prefixes = String(setting).split(",").map((p) => p.trim()).filter(Boolean);
18108
+ if (prefixes.includes("*"))
18109
+ return "private";
18110
+ return prefixes.some((p) => String(key2).startsWith(p)) ? "private" : "public-read";
18111
+ }
18112
+ var KEY = /^(?:[A-Za-z0-9_-]{1,64}\/){0,4}[a-f0-9]{24}$/;
18113
+ function isServableObjectKey(key2) {
18114
+ return typeof key2 === "string" && KEY.test(key2);
18115
+ }
18116
+ function anprSiteOfKey(key2) {
18117
+ const m = /^anpr\/([a-f0-9]{24})\//.exec(key2);
18118
+ return m ? m[1] : null;
18119
+ }
18120
+ var INLINE_TYPES = /^(image\/(jpeg|png|gif|webp|heic|heif|bmp)|application\/pdf|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|webm|ogg))$/;
18121
+ function servedObjectHeaders(contentType) {
18122
+ const type = String(contentType ?? "").split(";")[0].trim().toLowerCase();
18123
+ const inline = INLINE_TYPES.test(type);
18124
+ return {
18125
+ "Content-Type": inline ? type : "application/octet-stream",
18126
+ "Content-Disposition": inline ? "inline" : "attachment",
18127
+ "X-Content-Type-Options": "nosniff",
18128
+ "Content-Security-Policy": "default-src 'none'; sandbox",
18129
+ "Cache-Control": "private, max-age=300"
18130
+ };
18131
+ }
18132
+
18133
+ // src/services/spaces-object.service.ts
18134
+ var client = null;
18135
+ function s3() {
18136
+ if (!client) {
18137
+ client = new S3Client({
18138
+ endpoint: SPACES_ENDPOINT,
18139
+ region: SPACES_REGION,
18140
+ credentials: { accessKeyId: SPACES_ACCESS_KEY, secretAccessKey: SPACES_SECRET_KEY },
18141
+ forcePathStyle: true
18142
+ });
18143
+ }
18144
+ return client;
18145
+ }
18146
+ async function putSpacesObject({
18147
+ key: key2,
18148
+ body,
18149
+ contentType
18150
+ }) {
18151
+ await s3().send(
18152
+ new PutObjectCommand({
18153
+ Bucket: SPACES_BUCKET,
18154
+ Key: key2,
18155
+ Body: body,
18156
+ ACL: spacesUploadAcl(key2),
18157
+ ContentType: contentType,
18158
+ ContentLength: body.length
18159
+ })
18160
+ );
18161
+ return "Successfully uploaded file.";
18162
+ }
18163
+ async function getSpacesObject(key2) {
18164
+ const res = await s3().send(new GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 }));
18165
+ return {
18166
+ body: res.Body,
18167
+ contentType: res.ContentType,
18168
+ contentLength: res.ContentLength
18169
+ };
18170
+ }
18171
+
18102
18172
  // src/repositories/file.repo.ts
18103
18173
  import {
18104
18174
  BadRequestError as BadRequestError41,
@@ -18286,7 +18356,7 @@ function useFileService() {
18286
18356
  deleteFileById,
18287
18357
  getAllDraftedFiles
18288
18358
  } = useFileRepo();
18289
- const s32 = new useS3({
18359
+ const s33 = new useS3({
18290
18360
  accessKeyId: SPACES_ACCESS_KEY,
18291
18361
  secretAccessKey: SPACES_SECRET_KEY,
18292
18362
  endpoint: SPACES_ENDPOINT,
@@ -18305,7 +18375,7 @@ function useFileService() {
18305
18375
  };
18306
18376
  try {
18307
18377
  const id = await _createFile(file, session);
18308
- await s32.uploadObject({
18378
+ await putSpacesObject({
18309
18379
  key: `${folder}/${id}`,
18310
18380
  body: value.buffer,
18311
18381
  contentType: value.mimetype
@@ -18324,7 +18394,7 @@ function useFileService() {
18324
18394
  session?.startTransaction();
18325
18395
  try {
18326
18396
  await deleteFileById(id, session);
18327
- await s32.deleteObject(id);
18397
+ await s33.deleteObject(id);
18328
18398
  await session?.commitTransaction();
18329
18399
  return "File deleted successfully.";
18330
18400
  } catch (error) {
@@ -26291,7 +26361,7 @@ function useUserService() {
26291
26361
  session?.endSession();
26292
26362
  }
26293
26363
  }
26294
- const s32 = new useS32({
26364
+ const s33 = new useS32({
26295
26365
  accessKeyId: SPACES_ACCESS_KEY,
26296
26366
  secretAccessKey: SPACES_SECRET_KEY,
26297
26367
  endpoint: SPACES_ENDPOINT,
@@ -26312,14 +26382,14 @@ function useUserService() {
26312
26382
  };
26313
26383
  try {
26314
26384
  const id = await createFile(_file, session);
26315
- await s32.uploadObject({
26385
+ await putSpacesObject({
26316
26386
  key: id,
26317
26387
  body: file.buffer,
26318
26388
  contentType: file.mimetype
26319
26389
  });
26320
26390
  if (previousProfile) {
26321
26391
  await deleteFileById(previousProfile, session);
26322
- await s32.deleteObject(previousProfile);
26392
+ await s33.deleteObject(previousProfile);
26323
26393
  }
26324
26394
  await _updateUserFieldById(
26325
26395
  { _id: user, field: "profile", value: id },
@@ -30450,10 +30520,38 @@ function useFileController() {
30450
30520
  next(error2);
30451
30521
  }
30452
30522
  }
30523
+ async function viewObject(req, res, next) {
30524
+ const key2 = String(req.params?.[0] ?? "");
30525
+ if (!isServableObjectKey(key2)) {
30526
+ res.status(404).json({ message: "File not found." });
30527
+ return;
30528
+ }
30529
+ try {
30530
+ const site = anprSiteOfKey(key2);
30531
+ if (site)
30532
+ await requireSiteReach(req, site);
30533
+ const object = await getSpacesObject(key2);
30534
+ res.set(servedObjectHeaders(object.contentType));
30535
+ if (object.contentLength)
30536
+ res.set("Content-Length", String(object.contentLength));
30537
+ object.body.pipe(res);
30538
+ return;
30539
+ } catch (error) {
30540
+ const status = error?.$metadata?.httpStatusCode ?? error?.statusCode ?? error?.status;
30541
+ if (status === 404 || status === 403 || error?.name === "NoSuchKey" || error?.name === "NotFoundError") {
30542
+ res.status(404).json({ message: "File not found." });
30543
+ return;
30544
+ }
30545
+ logger46.log({ level: "error", message: error?.message });
30546
+ next(error);
30547
+ return;
30548
+ }
30549
+ }
30453
30550
  return {
30454
30551
  upload,
30455
30552
  deleteFile,
30456
- getFileById
30553
+ getFileById,
30554
+ viewObject
30457
30555
  };
30458
30556
  }
30459
30557
 
@@ -36705,8 +36803,8 @@ function useServiceProviderController() {
36705
36803
  if (siteId)
36706
36804
  await requireSiteReach(req, siteId);
36707
36805
  const engagements = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId;
36708
- const client2 = engagements ? await isSiteClient(req, siteId) : false;
36709
- const data = client2 ? await _getServiceProvidersForSite({ search, page: page2, limit, siteId }) : engagements ? (
36806
+ const client3 = engagements ? await isSiteClient(req, siteId) : false;
36807
+ const data = client3 ? await _getServiceProvidersForSite({ search, page: page2, limit, siteId }) : engagements ? (
36710
36808
  // A provider's own Service Providers page: the subcontractors it
36711
36809
  // brought onto this site, never the client's other contractors,
36712
36810
  // plus the stored rows it already saw here.
@@ -46451,7 +46549,7 @@ function useCustomerSiteController() {
46451
46549
  const org = req.query.org ?? "";
46452
46550
  const status = req.query.status ?? "active";
46453
46551
  const relationship = req.query.relationship || "";
46454
- const client2 = req.query.client || "";
46552
+ const client3 = req.query.client || "";
46455
46553
  const category = req.query.category || "";
46456
46554
  const sortObj = {};
46457
46555
  const sortFields = String(req.query.sort).split(",");
@@ -46474,7 +46572,7 @@ function useCustomerSiteController() {
46474
46572
  status,
46475
46573
  siteScope,
46476
46574
  relationship,
46477
- client: client2,
46575
+ client: client3,
46478
46576
  category
46479
46577
  });
46480
46578
  res.json(data);
@@ -47790,15 +47888,15 @@ function useAttendanceService() {
47790
47888
 
47791
47889
  // src/services/attendance-photo.service.ts
47792
47890
  import {
47793
- GetObjectCommand,
47794
- PutObjectCommand,
47795
- S3Client
47891
+ GetObjectCommand as GetObjectCommand2,
47892
+ PutObjectCommand as PutObjectCommand2,
47893
+ S3Client as S3Client2
47796
47894
  } from "@aws-sdk/client-s3";
47797
47895
  var ATTENDANCE_PHOTO_FOLDER = "attendance-private";
47798
- var client = null;
47799
- function s3() {
47800
- if (!client) {
47801
- client = new S3Client({
47896
+ var client2 = null;
47897
+ function s32() {
47898
+ if (!client2) {
47899
+ client2 = new S3Client2({
47802
47900
  endpoint: SPACES_ENDPOINT,
47803
47901
  region: SPACES_REGION,
47804
47902
  credentials: {
@@ -47808,12 +47906,12 @@ function s3() {
47808
47906
  forcePathStyle: true
47809
47907
  });
47810
47908
  }
47811
- return client;
47909
+ return client2;
47812
47910
  }
47813
47911
  var s3AttendancePhotoStore = {
47814
47912
  async put(key2, body, contentType) {
47815
- await s3().send(
47816
- new PutObjectCommand({
47913
+ await s32().send(
47914
+ new PutObjectCommand2({
47817
47915
  Bucket: SPACES_BUCKET,
47818
47916
  Key: key2,
47819
47917
  Body: body,
@@ -47824,8 +47922,8 @@ var s3AttendancePhotoStore = {
47824
47922
  );
47825
47923
  },
47826
47924
  async get(key2) {
47827
- const res = await s3().send(
47828
- new GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 })
47925
+ const res = await s32().send(
47926
+ new GetObjectCommand2({ Bucket: SPACES_BUCKET, Key: key2 })
47829
47927
  );
47830
47928
  const bytes = await res.Body.transformToByteArray();
47831
47929
  return { body: Buffer.from(bytes), contentType: res.ContentType };
@@ -52421,20 +52519,20 @@ function createVisitorQrCredential(visitorId, readerId, qrValue) {
52421
52519
  const token = qrValue || `VIS${crypto6.randomBytes(12).toString("hex").toUpperCase()}`;
52422
52520
  return { credentialId, object: "qrcodes", value: token, qrValue: token };
52423
52521
  }
52424
- async function configureVisitorQrReader(client2) {
52522
+ async function configureVisitorQrReader(client3) {
52425
52523
  const requestedConfiguration = {
52426
52524
  general: ["online", "local_identification"],
52427
52525
  face_id: ["qrcode_legacy_mode_enabled"],
52428
52526
  identifier: ["qrcode_identification_enabled", "multi_factor_authentication"]
52429
52527
  };
52430
- const currentConfiguration = await client2.getConfiguration(requestedConfiguration);
52528
+ const currentConfiguration = await client3.getConfiguration(requestedConfiguration);
52431
52529
  const current = isUnknownRecord2(currentConfiguration) ? currentConfiguration : {};
52432
52530
  const currentGeneral = isUnknownRecord2(current.general) ? current.general : {};
52433
52531
  const currentFaceId = isUnknownRecord2(current.face_id) ? current.face_id : {};
52434
52532
  const currentIdentifier = isUnknownRecord2(current.identifier) ? current.identifier : {};
52435
52533
  let changed = false;
52436
52534
  if (String(currentGeneral.online ?? "") !== "0" || String(currentGeneral.local_identification ?? "") !== "1") {
52437
- await client2.setConfiguration({
52535
+ await client3.setConfiguration({
52438
52536
  general: {
52439
52537
  online: "0",
52440
52538
  local_identification: "1"
@@ -52443,13 +52541,13 @@ async function configureVisitorQrReader(client2) {
52443
52541
  changed = true;
52444
52542
  }
52445
52543
  if (String(currentFaceId.qrcode_legacy_mode_enabled ?? "") !== VISITOR_QR_FORMAT) {
52446
- await client2.setConfiguration({
52544
+ await client3.setConfiguration({
52447
52545
  face_id: { qrcode_legacy_mode_enabled: VISITOR_QR_FORMAT }
52448
52546
  });
52449
52547
  changed = true;
52450
52548
  }
52451
52549
  if (String(currentIdentifier.qrcode_identification_enabled ?? "") !== "1" || String(currentIdentifier.multi_factor_authentication ?? "") !== "0") {
52452
- await client2.setConfiguration({
52550
+ await client3.setConfiguration({
52453
52551
  identifier: {
52454
52552
  qrcode_identification_enabled: "1",
52455
52553
  // A visitor pass is a single QR credential. Leaving MFA enabled makes
@@ -52459,7 +52557,7 @@ async function configureVisitorQrReader(client2) {
52459
52557
  });
52460
52558
  changed = true;
52461
52559
  }
52462
- const configuration = await client2.getConfiguration(requestedConfiguration);
52560
+ const configuration = await client3.getConfiguration(requestedConfiguration);
52463
52561
  const savedConfiguration = isUnknownRecord2(configuration) ? configuration : {};
52464
52562
  const general = isUnknownRecord2(savedConfiguration.general) ? savedConfiguration.general : {};
52465
52563
  const faceId = isUnknownRecord2(savedConfiguration.face_id) ? savedConfiguration.face_id : {};
@@ -52471,7 +52569,7 @@ async function configureVisitorQrReader(client2) {
52471
52569
  }
52472
52570
  return changed;
52473
52571
  }
52474
- async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUserId, scope = "visitor") {
52572
+ async function ensureVisitorAccessAuthorization(client3, readerId, reader, hidUserId, scope = "visitor") {
52475
52573
  const accessLabel = scope === "visitor" ? "Visitor" : "Facial";
52476
52574
  const accessRuleId = createStableHidId(`${scope}-access-rule:${readerId}`);
52477
52575
  const timeZoneId = createStableHidId(`${scope}-time-zone:${readerId}`);
@@ -52481,25 +52579,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52481
52579
  type: 1,
52482
52580
  priority: 0
52483
52581
  };
52484
- const existingRuleResponse = await client2.loadObjects({
52582
+ const existingRuleResponse = await client3.loadObjects({
52485
52583
  object: "access_rules",
52486
52584
  where: { access_rules: { id: accessRuleId } },
52487
52585
  limit: 1,
52488
52586
  offset: 0
52489
52587
  });
52490
52588
  if (getHidObjectRows(existingRuleResponse, "access_rules").length) {
52491
- await client2.modifyObjects({
52589
+ await client3.modifyObjects({
52492
52590
  object: "access_rules",
52493
52591
  where: { access_rules: { id: accessRuleId } },
52494
52592
  values: accessRuleValues
52495
52593
  });
52496
52594
  } else {
52497
- await client2.createObjects({
52595
+ await client3.createObjects({
52498
52596
  object: "access_rules",
52499
52597
  values: [{ id: accessRuleId, ...accessRuleValues }]
52500
52598
  });
52501
52599
  }
52502
- const verifiedAccessRuleResponse = await client2.loadObjects({
52600
+ const verifiedAccessRuleResponse = await client3.loadObjects({
52503
52601
  object: "access_rules",
52504
52602
  where: { access_rules: { id: accessRuleId } },
52505
52603
  limit: 1,
@@ -52513,20 +52611,20 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52513
52611
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
52514
52612
  );
52515
52613
  }
52516
- const existingTimeZoneResponse = await client2.loadObjects({
52614
+ const existingTimeZoneResponse = await client3.loadObjects({
52517
52615
  object: "time_zones",
52518
52616
  where: { time_zones: { id: timeZoneId } },
52519
52617
  limit: 1,
52520
52618
  offset: 0
52521
52619
  });
52522
52620
  if (getHidObjectRows(existingTimeZoneResponse, "time_zones").length) {
52523
- await client2.modifyObjects({
52621
+ await client3.modifyObjects({
52524
52622
  object: "time_zones",
52525
52623
  where: { time_zones: { id: timeZoneId } },
52526
52624
  values: { name: `iService365 ${accessLabel} Schedule` }
52527
52625
  });
52528
52626
  } else {
52529
- await client2.createObjects({
52627
+ await client3.createObjects({
52530
52628
  object: "time_zones",
52531
52629
  values: [{ id: timeZoneId, name: `iService365 ${accessLabel} Schedule` }]
52532
52630
  });
@@ -52546,25 +52644,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52546
52644
  hol2: 1,
52547
52645
  hol3: 1
52548
52646
  };
52549
- const existingTimeSpanResponse = await client2.loadObjects({
52647
+ const existingTimeSpanResponse = await client3.loadObjects({
52550
52648
  object: "time_spans",
52551
52649
  where: { time_spans: { id: timeSpanId } },
52552
52650
  limit: 1,
52553
52651
  offset: 0
52554
52652
  });
52555
52653
  if (getHidObjectRows(existingTimeSpanResponse, "time_spans").length) {
52556
- await client2.modifyObjects({
52654
+ await client3.modifyObjects({
52557
52655
  object: "time_spans",
52558
52656
  where: { time_spans: { id: timeSpanId } },
52559
52657
  values: visitorTimeSpan
52560
52658
  });
52561
52659
  } else {
52562
- await client2.createObjects({
52660
+ await client3.createObjects({
52563
52661
  object: "time_spans",
52564
52662
  values: [{ id: timeSpanId, ...visitorTimeSpan }]
52565
52663
  });
52566
52664
  }
52567
- const verifiedTimeZoneResponse = await client2.loadObjects({
52665
+ const verifiedTimeZoneResponse = await client3.loadObjects({
52568
52666
  object: "time_zones",
52569
52667
  where: { time_zones: { id: timeZoneId } },
52570
52668
  limit: 1,
@@ -52578,7 +52676,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52578
52676
  "The HID reader did not save the visitor access schedule."
52579
52677
  );
52580
52678
  }
52581
- const verifiedTimeSpanResponse = await client2.loadObjects({
52679
+ const verifiedTimeSpanResponse = await client3.loadObjects({
52582
52680
  object: "time_spans",
52583
52681
  where: { time_spans: { id: timeSpanId } },
52584
52682
  limit: 1,
@@ -52596,7 +52694,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52596
52694
  access_rule_id: accessRuleId,
52597
52695
  time_zone_id: timeZoneId
52598
52696
  };
52599
- const accessRuleTimeZoneResponse = await client2.loadObjects({
52697
+ const accessRuleTimeZoneResponse = await client3.loadObjects({
52600
52698
  object: "access_rule_time_zones",
52601
52699
  where: {
52602
52700
  access_rule_time_zones: {
@@ -52610,12 +52708,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52610
52708
  getHidObjectRows(accessRuleTimeZoneResponse, "access_rule_time_zones"),
52611
52709
  accessRuleTimeZoneValues
52612
52710
  )) {
52613
- await client2.createObjects({
52711
+ await client3.createObjects({
52614
52712
  object: "access_rule_time_zones",
52615
52713
  values: [accessRuleTimeZoneValues]
52616
52714
  });
52617
52715
  }
52618
- const verifiedAccessRuleTimeZoneResponse = await client2.loadObjects({
52716
+ const verifiedAccessRuleTimeZoneResponse = await client3.loadObjects({
52619
52717
  object: "access_rule_time_zones",
52620
52718
  where: { access_rule_time_zones: { access_rule_id: accessRuleId } },
52621
52719
  limit: 100,
@@ -52629,7 +52727,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52629
52727
  "The HID reader did not save the visitor access schedule. Try issuing the QR code again."
52630
52728
  );
52631
52729
  }
52632
- const portalsResponse = await client2.loadObjects({
52730
+ const portalsResponse = await client3.loadObjects({
52633
52731
  object: "portals",
52634
52732
  limit: 100,
52635
52733
  offset: 0
@@ -52666,7 +52764,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52666
52764
  user_id: hidUserId,
52667
52765
  access_rule_id: accessRuleId
52668
52766
  };
52669
- const userAccessRulesResponse = await client2.loadObjects({
52767
+ const userAccessRulesResponse = await client3.loadObjects({
52670
52768
  object: "user_access_rules",
52671
52769
  where: { user_access_rules: { user_id: hidUserId } },
52672
52770
  limit: 100,
@@ -52676,12 +52774,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52676
52774
  getHidObjectRows(userAccessRulesResponse, "user_access_rules"),
52677
52775
  userAccessRuleValues
52678
52776
  )) {
52679
- await client2.createObjects({
52777
+ await client3.createObjects({
52680
52778
  object: "user_access_rules",
52681
52779
  values: [userAccessRuleValues]
52682
52780
  });
52683
52781
  }
52684
- const verifiedUserAccessRulesResponse = await client2.loadObjects({
52782
+ const verifiedUserAccessRulesResponse = await client3.loadObjects({
52685
52783
  object: "user_access_rules",
52686
52784
  where: { user_access_rules: { user_id: hidUserId } },
52687
52785
  limit: 100,
@@ -52695,7 +52793,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52695
52793
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
52696
52794
  );
52697
52795
  }
52698
- const portalAccessRulesResponse = await client2.loadObjects({
52796
+ const portalAccessRulesResponse = await client3.loadObjects({
52699
52797
  object: "portal_access_rules",
52700
52798
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
52701
52799
  limit: 100,
@@ -52706,7 +52804,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52706
52804
  );
52707
52805
  const stalePortalIds = [...linkedPortalIds].filter((portalId) => !portalIds.includes(portalId));
52708
52806
  for (const portalId of stalePortalIds) {
52709
- await client2.destroyObjects({
52807
+ await client3.destroyObjects({
52710
52808
  object: "portal_access_rules",
52711
52809
  where: { portal_access_rules: { access_rule_id: accessRuleId, portal_id: portalId } }
52712
52810
  });
@@ -52714,12 +52812,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52714
52812
  }
52715
52813
  const missingPortalLinks = portalIds.filter((portalId) => !linkedPortalIds.has(portalId)).map((portalId) => ({ portal_id: portalId, access_rule_id: accessRuleId }));
52716
52814
  if (missingPortalLinks.length) {
52717
- await client2.createObjects({
52815
+ await client3.createObjects({
52718
52816
  object: "portal_access_rules",
52719
52817
  values: missingPortalLinks
52720
52818
  });
52721
52819
  }
52722
- const verifiedPortalAccessRulesResponse = await client2.loadObjects({
52820
+ const verifiedPortalAccessRulesResponse = await client3.loadObjects({
52723
52821
  object: "portal_access_rules",
52724
52822
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
52725
52823
  limit: 100,
@@ -52743,19 +52841,19 @@ function getHidPortals(response) {
52743
52841
  areaToId: Number(portal.area_to_id)
52744
52842
  })).filter((portal) => Number.isSafeInteger(portal.id) && portal.id > 0 && portal.name);
52745
52843
  }
52746
- async function upsertHidObject(client2, object, id, values) {
52747
- const existing = await client2.loadObjects({
52844
+ async function upsertHidObject(client3, object, id, values) {
52845
+ const existing = await client3.loadObjects({
52748
52846
  object,
52749
52847
  where: { [object]: { id } },
52750
52848
  limit: 1,
52751
52849
  offset: 0
52752
52850
  });
52753
52851
  if (getHidObjectRows(existing, object).length) {
52754
- await client2.modifyObjects({ object, where: { [object]: { id } }, values });
52852
+ await client3.modifyObjects({ object, where: { [object]: { id } }, values });
52755
52853
  } else {
52756
- await client2.createObjects({ object, values: [{ id, ...values }] });
52854
+ await client3.createObjects({ object, values: [{ id, ...values }] });
52757
52855
  }
52758
- const verified = await client2.loadObjects({
52856
+ const verified = await client3.loadObjects({
52759
52857
  object,
52760
52858
  where: { [object]: { id } },
52761
52859
  limit: 1,
@@ -52765,17 +52863,17 @@ async function upsertHidObject(client2, object, id, values) {
52765
52863
  throw new BadRequestError126(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
52766
52864
  }
52767
52865
  }
52768
- async function ensureHidRelation(client2, object, values) {
52769
- const response = await client2.loadObjects({
52866
+ async function ensureHidRelation(client3, object, values) {
52867
+ const response = await client3.loadObjects({
52770
52868
  object,
52771
52869
  where: { [object]: values },
52772
52870
  limit: 100,
52773
52871
  offset: 0
52774
52872
  });
52775
52873
  if (!hasHidObjectValues(getHidObjectRows(response, object), values)) {
52776
- await client2.createObjects({ object, values: [values] });
52874
+ await client3.createObjects({ object, values: [values] });
52777
52875
  }
52778
- const verified = await client2.loadObjects({
52876
+ const verified = await client3.loadObjects({
52779
52877
  object,
52780
52878
  where: { [object]: values },
52781
52879
  limit: 100,
@@ -52785,8 +52883,8 @@ async function ensureHidRelation(client2, object, values) {
52785
52883
  throw new BadRequestError126(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
52786
52884
  }
52787
52885
  }
52788
- async function reconcileHidRelation(client2, object, scope, values) {
52789
- const response = await client2.loadObjects({
52886
+ async function reconcileHidRelation(client3, object, scope, values) {
52887
+ const response = await client3.loadObjects({
52790
52888
  object,
52791
52889
  where: { [object]: scope },
52792
52890
  limit: 1e3,
@@ -52798,11 +52896,11 @@ async function reconcileHidRelation(client2, object, scope, values) {
52798
52896
  const staleValues = Object.fromEntries(
52799
52897
  Object.keys(values).map((key2) => [key2, row[key2]])
52800
52898
  );
52801
- await client2.destroyObjects({ object, where: { [object]: staleValues } });
52899
+ await client3.destroyObjects({ object, where: { [object]: staleValues } });
52802
52900
  }
52803
52901
  }
52804
- await ensureHidRelation(client2, object, values);
52805
- const verified = await client2.loadObjects({
52902
+ await ensureHidRelation(client3, object, values);
52903
+ const verified = await client3.loadObjects({
52806
52904
  object,
52807
52905
  where: { [object]: scope },
52808
52906
  limit: 1e3,
@@ -52813,21 +52911,21 @@ async function reconcileHidRelation(client2, object, scope, values) {
52813
52911
  throw new BadRequestError126(`The HID reader did not reconcile ${object.replace(/_/g, " ")}.`);
52814
52912
  }
52815
52913
  }
52816
- async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userIds) {
52914
+ async function reconcileStandaloneGroupAccess(client3, readerId, portalId, userIds) {
52817
52915
  const groupId = createStableHidId(`permission-group:${readerId}`);
52818
52916
  const accessRuleId = createStableHidId(`permission-access-rule:${readerId}`);
52819
52917
  const timeZoneId = createStableHidId(`permission-time-zone:${readerId}`);
52820
52918
  const timeSpanId = createStableHidId(`permission-time-span:${readerId}`);
52821
- await upsertHidObject(client2, "groups", groupId, { name: "iService365 Assigned Access" });
52822
- await upsertHidObject(client2, "access_rules", accessRuleId, {
52919
+ await upsertHidObject(client3, "groups", groupId, { name: "iService365 Assigned Access" });
52920
+ await upsertHidObject(client3, "access_rules", accessRuleId, {
52823
52921
  name: "iService365 Assigned Access",
52824
52922
  type: 1,
52825
52923
  priority: 0
52826
52924
  });
52827
- await upsertHidObject(client2, "time_zones", timeZoneId, {
52925
+ await upsertHidObject(client3, "time_zones", timeZoneId, {
52828
52926
  name: "iService365 Assigned Schedule"
52829
52927
  });
52830
- await upsertHidObject(client2, "time_spans", timeSpanId, {
52928
+ await upsertHidObject(client3, "time_spans", timeSpanId, {
52831
52929
  time_zone_id: timeZoneId,
52832
52930
  start: 0,
52833
52931
  end: 86399,
@@ -52842,19 +52940,19 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52842
52940
  hol2: 1,
52843
52941
  hol3: 1
52844
52942
  });
52845
- await reconcileHidRelation(client2, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
52943
+ await reconcileHidRelation(client3, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
52846
52944
  access_rule_id: accessRuleId,
52847
52945
  time_zone_id: timeZoneId
52848
52946
  });
52849
- await reconcileHidRelation(client2, "group_access_rules", { access_rule_id: accessRuleId }, {
52947
+ await reconcileHidRelation(client3, "group_access_rules", { access_rule_id: accessRuleId }, {
52850
52948
  group_id: groupId,
52851
52949
  access_rule_id: accessRuleId
52852
52950
  });
52853
- await reconcileHidRelation(client2, "portal_access_rules", { access_rule_id: accessRuleId }, {
52951
+ await reconcileHidRelation(client3, "portal_access_rules", { access_rule_id: accessRuleId }, {
52854
52952
  portal_id: portalId,
52855
52953
  access_rule_id: accessRuleId
52856
52954
  });
52857
- const currentResponse = await client2.loadObjects({
52955
+ const currentResponse = await client3.loadObjects({
52858
52956
  object: "user_groups",
52859
52957
  where: { user_groups: { group_id: groupId } },
52860
52958
  limit: 2e5,
@@ -52865,7 +52963,7 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52865
52963
  for (const row of currentRows) {
52866
52964
  const userId = String(row.user_id ?? "");
52867
52965
  if (userId && !desired.has(userId)) {
52868
- await client2.destroyObjects({
52966
+ await client3.destroyObjects({
52869
52967
  object: "user_groups",
52870
52968
  where: { user_groups: { group_id: groupId, user_id: Number(userId) } }
52871
52969
  });
@@ -52874,13 +52972,13 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52874
52972
  const current = new Set(currentRows.map((row) => String(row.user_id ?? "")));
52875
52973
  for (const userId of userIds) {
52876
52974
  if (!current.has(String(userId))) {
52877
- await client2.createObjects({
52975
+ await client3.createObjects({
52878
52976
  object: "user_groups",
52879
52977
  values: [{ group_id: groupId, user_id: userId }]
52880
52978
  });
52881
52979
  }
52882
52980
  }
52883
- const verification = await client2.loadObjects({
52981
+ const verification = await client3.loadObjects({
52884
52982
  object: "user_groups",
52885
52983
  where: { user_groups: { group_id: groupId } },
52886
52984
  limit: 2e5,
@@ -53383,10 +53481,10 @@ var HidAmicoClient = class {
53383
53481
  return res.data;
53384
53482
  }
53385
53483
  };
53386
- async function configureMonitor(client2, callbackToken) {
53484
+ async function configureMonitor(client3, callbackToken) {
53387
53485
  const expected = getMonitorConfiguration(callbackToken);
53388
- await client2.setConfiguration({ monitor: expected });
53389
- const response = await client2.getConfiguration({
53486
+ await client3.setConfiguration({ monitor: expected });
53487
+ const response = await client3.getConfiguration({
53390
53488
  monitor: ["request_timeout", "hostname", "port", "path"]
53391
53489
  });
53392
53490
  const root = isUnknownRecord2(response) ? response : {};
@@ -53396,9 +53494,9 @@ async function configureMonitor(client2, callbackToken) {
53396
53494
  }
53397
53495
  return expected;
53398
53496
  }
53399
- async function configureOperatingMode(client2, mode) {
53497
+ async function configureOperatingMode(client3, mode) {
53400
53498
  const expectedOnline = mode === "online" ? "1" : "0";
53401
- await client2.setConfiguration({
53499
+ await client3.setConfiguration({
53402
53500
  general: {
53403
53501
  online: expectedOnline,
53404
53502
  // HID documents Online mode as both flags enabled. Keeping local
@@ -53406,7 +53504,7 @@ async function configureOperatingMode(client2, mode) {
53406
53504
  local_identification: "1"
53407
53505
  }
53408
53506
  });
53409
- const response = await client2.getConfiguration({
53507
+ const response = await client3.getConfiguration({
53410
53508
  general: ["online", "local_identification"]
53411
53509
  });
53412
53510
  const root = isUnknownRecord2(response) ? response : {};
@@ -53790,8 +53888,8 @@ function useHidAmicoService() {
53790
53888
  return requestedType;
53791
53889
  return mode === "csn_for_mifare" ? "unknown" : mode;
53792
53890
  }
53793
- async function assertHidUserExists(client2, hidUserId) {
53794
- const response = await client2.loadObjects({
53891
+ async function assertHidUserExists(client3, hidUserId) {
53892
+ const response = await client3.loadObjects({
53795
53893
  object: "users",
53796
53894
  where: { users: { id: hidUserId } },
53797
53895
  limit: 1,
@@ -53801,18 +53899,18 @@ function useHidAmicoService() {
53801
53899
  throw new BadRequestError126("HID user must exist before assigning a physical HID card.");
53802
53900
  }
53803
53901
  }
53804
- async function ensurePhysicalCardIdentification(client2) {
53805
- const before = await client2.getConfiguration({
53902
+ async function ensurePhysicalCardIdentification(client3) {
53903
+ const before = await client3.getConfiguration({
53806
53904
  identifier: ["card_identification_enabled"]
53807
53905
  });
53808
53906
  const root = isUnknownRecord2(before) ? before : {};
53809
53907
  const identifier = isUnknownRecord2(root.identifier) ? root.identifier : {};
53810
53908
  if (String(identifier.card_identification_enabled ?? "") !== "1") {
53811
- await client2.setConfiguration({
53909
+ await client3.setConfiguration({
53812
53910
  identifier: { card_identification_enabled: "1" }
53813
53911
  });
53814
53912
  }
53815
- const verifiedResponse = await client2.getConfiguration({
53913
+ const verifiedResponse = await client3.getConfiguration({
53816
53914
  identifier: ["card_identification_enabled"]
53817
53915
  });
53818
53916
  const verifiedRoot = isUnknownRecord2(verifiedResponse) ? verifiedResponse : {};
@@ -53823,8 +53921,8 @@ function useHidAmicoService() {
53823
53921
  );
53824
53922
  }
53825
53923
  }
53826
- async function loadPhysicalCardRows(client2, hidUserId) {
53827
- const response = await client2.loadObjects({
53924
+ async function loadPhysicalCardRows(client3, hidUserId) {
53925
+ const response = await client3.loadObjects({
53828
53926
  object: "cards",
53829
53927
  where: { cards: { user_id: hidUserId } },
53830
53928
  limit: 100,
@@ -53922,15 +54020,15 @@ function useHidAmicoService() {
53922
54020
  const refusal = discoveryUrlRefusalReason(value.baseUrl);
53923
54021
  if (refusal)
53924
54022
  throw new BadRequestError126(refusal);
53925
- const client2 = new HidAmicoClient({
54023
+ const client3 = new HidAmicoClient({
53926
54024
  ...value,
53927
54025
  baseUrl: normalizeHidReaderBaseUrl(value.baseUrl)
53928
54026
  });
53929
54027
  try {
53930
- await client2.login();
54028
+ await client3.login();
53931
54029
  const [systemResponse, portalsResponse] = await Promise.all([
53932
- client2.getSystemInformation(),
53933
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54030
+ client3.getSystemInformation(),
54031
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
53934
54032
  ]);
53935
54033
  const system = getHidSystemInformation(systemResponse);
53936
54034
  const deviceId = isUnknownRecord2(system) ? String(system.device_id || "").trim() : "";
@@ -53960,7 +54058,7 @@ function useHidAmicoService() {
53960
54058
  portals
53961
54059
  };
53962
54060
  } finally {
53963
- await client2.logout();
54061
+ await client3.logout();
53964
54062
  }
53965
54063
  }
53966
54064
  async function createReader(value) {
@@ -53990,11 +54088,11 @@ function useHidAmicoService() {
53990
54088
  const readerId = String(reader._id);
53991
54089
  if (value.enabled === false)
53992
54090
  return reader;
53993
- const client2 = new HidAmicoClient(value);
54091
+ const client3 = new HidAmicoClient(value);
53994
54092
  try {
53995
- await client2.login();
54093
+ await client3.login();
53996
54094
  if (!monitorEnabled) {
53997
- await configureOperatingMode(client2, "standalone");
54095
+ await configureOperatingMode(client3, "standalone");
53998
54096
  return repo.updateById(readerId, {
53999
54097
  monitorStatus: "disabled",
54000
54098
  monitorPath: "",
@@ -54003,8 +54101,8 @@ function useHidAmicoService() {
54003
54101
  lastSyncMessage: "Monitor callbacks are disabled; Standalone mode configured."
54004
54102
  });
54005
54103
  }
54006
- const monitor = await configureMonitor(client2, callbackToken);
54007
- await configureOperatingMode(client2, "standalone");
54104
+ const monitor = await configureMonitor(client3, callbackToken);
54105
+ await configureOperatingMode(client3, "standalone");
54008
54106
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
54009
54107
  return repo.updateById(readerId, {
54010
54108
  monitorPath: publicMonitor.path,
@@ -54030,7 +54128,7 @@ function useHidAmicoService() {
54030
54128
  });
54031
54129
  return { ...failed, monitorWarning: message };
54032
54130
  } finally {
54033
- await client2.logout();
54131
+ await client3.logout();
54034
54132
  }
54035
54133
  }
54036
54134
  async function updateReader(id, value) {
@@ -54070,10 +54168,10 @@ function useHidAmicoService() {
54070
54168
  }
54071
54169
  if (payload.portalId && current) {
54072
54170
  const candidate = { ...current, ...payload };
54073
- const client2 = new HidAmicoClient(candidate);
54171
+ const client3 = new HidAmicoClient(candidate);
54074
54172
  try {
54075
- await client2.login();
54076
- const portals = getHidPortals(await client2.loadObjects({
54173
+ await client3.login();
54174
+ const portals = getHidPortals(await client3.loadObjects({
54077
54175
  object: "portals",
54078
54176
  limit: 100,
54079
54177
  offset: 0
@@ -54084,7 +54182,7 @@ function useHidAmicoService() {
54084
54182
  }
54085
54183
  payload.portalName = portal.name;
54086
54184
  } finally {
54087
- await client2.logout();
54185
+ await client3.logout();
54088
54186
  }
54089
54187
  }
54090
54188
  return repo.updateById(id, payload);
@@ -54102,12 +54200,12 @@ function useHidAmicoService() {
54102
54200
  monitorStatus: "unconfigured"
54103
54201
  });
54104
54202
  }
54105
- const client2 = new HidAmicoClient(reader);
54203
+ const client3 = new HidAmicoClient(reader);
54106
54204
  try {
54107
- await client2.login();
54205
+ await client3.login();
54108
54206
  const [systemResponse, portalsResponse] = await Promise.all([
54109
- client2.getSystemInformation(),
54110
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54207
+ client3.getSystemInformation(),
54208
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
54111
54209
  ]);
54112
54210
  const system = getHidSystemInformation(systemResponse);
54113
54211
  const serial = isUnknownRecord2(system) ? String(system.serial || "") : "";
@@ -54124,9 +54222,9 @@ function useHidAmicoService() {
54124
54222
  "The saved portal no longer exists on this HID reader. Edit the reader and select a valid portal."
54125
54223
  );
54126
54224
  }
54127
- const monitor = await configureMonitor(client2, callbackToken);
54225
+ const monitor = await configureMonitor(client3, callbackToken);
54128
54226
  const mode = reader.operatingMode === "online" ? "online" : "standalone";
54129
- await configureOperatingMode(client2, mode);
54227
+ await configureOperatingMode(client3, mode);
54130
54228
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
54131
54229
  await repo.updateById(id, {
54132
54230
  serial,
@@ -54149,17 +54247,17 @@ function useHidAmicoService() {
54149
54247
  });
54150
54248
  throw error;
54151
54249
  } finally {
54152
- await client2.logout();
54250
+ await client3.logout();
54153
54251
  }
54154
54252
  }
54155
54253
  async function setReaderMonitor(id, enabled) {
54156
54254
  if (enabled)
54157
54255
  return configureReaderIntegration(id);
54158
54256
  const reader = await getActiveReader(id);
54159
- const client2 = new HidAmicoClient(reader);
54257
+ const client3 = new HidAmicoClient(reader);
54160
54258
  try {
54161
- await client2.login();
54162
- await configureOperatingMode(client2, "standalone");
54259
+ await client3.login();
54260
+ await configureOperatingMode(client3, "standalone");
54163
54261
  await repo.updateById(id, {
54164
54262
  monitorStatus: "disabled",
54165
54263
  monitorPath: "",
@@ -54176,7 +54274,7 @@ function useHidAmicoService() {
54176
54274
  });
54177
54275
  return { enabled: false, mode: "standalone", verified: true };
54178
54276
  } finally {
54179
- await client2.logout();
54277
+ await client3.logout();
54180
54278
  }
54181
54279
  }
54182
54280
  async function setOperatingMode(id, mode) {
@@ -54186,10 +54284,10 @@ function useHidAmicoService() {
54186
54284
  "Configure and verify the HID Monitor callback before enabling Online mode."
54187
54285
  );
54188
54286
  }
54189
- const client2 = new HidAmicoClient(reader);
54287
+ const client3 = new HidAmicoClient(reader);
54190
54288
  try {
54191
- await client2.login();
54192
- const result = await configureOperatingMode(client2, mode);
54289
+ await client3.login();
54290
+ const result = await configureOperatingMode(client3, mode);
54193
54291
  await repo.updateById(id, {
54194
54292
  operatingMode: mode,
54195
54293
  lastSyncStatus: "completed",
@@ -54204,7 +54302,7 @@ function useHidAmicoService() {
54204
54302
  });
54205
54303
  return sanitizeHidPayload(result);
54206
54304
  } finally {
54207
- await client2.logout();
54305
+ await client3.logout();
54208
54306
  }
54209
54307
  }
54210
54308
  async function listReaders(value) {
@@ -54259,12 +54357,12 @@ function useHidAmicoService() {
54259
54357
  }
54260
54358
  async function testReader(id) {
54261
54359
  const reader = await repo.getById(id, { includePassword: true });
54262
- const client2 = new HidAmicoClient(reader);
54360
+ const client3 = new HidAmicoClient(reader);
54263
54361
  try {
54264
- await client2.login();
54362
+ await client3.login();
54265
54363
  const [valid, systemResponse] = await Promise.all([
54266
- client2.sessionIsValid(),
54267
- client2.getSystemInformation()
54364
+ client3.sessionIsValid(),
54365
+ client3.getSystemInformation()
54268
54366
  ]);
54269
54367
  const system = getHidSystemInformation(systemResponse);
54270
54368
  const firmwareVersion = getHidFirmwareVersion(systemResponse);
@@ -54318,19 +54416,19 @@ function useHidAmicoService() {
54318
54416
  await repo.addEvent({ reader: id, site: reader.site, type: "test_failed", payload: { message } });
54319
54417
  throw error;
54320
54418
  } finally {
54321
- await client2.logout();
54419
+ await client3.logout();
54322
54420
  }
54323
54421
  }
54324
54422
  async function syncReader(id, payload) {
54325
54423
  const reader = await getActiveReader(id);
54326
54424
  const batches = normalizeBatches(payload);
54327
- const client2 = new HidAmicoClient(reader);
54425
+ const client3 = new HidAmicoClient(reader);
54328
54426
  const results = [];
54329
54427
  await repo.updateById(id, { lastSyncStatus: "running", lastSyncMessage: "Sync started." });
54330
54428
  try {
54331
- await client2.login();
54429
+ await client3.login();
54332
54430
  for (const batch of batches) {
54333
- const result = await client2.createObjects(batch);
54431
+ const result = await client3.createObjects(batch);
54334
54432
  results.push({
54335
54433
  object: batch.object,
54336
54434
  count: batch.values.length,
@@ -54358,7 +54456,7 @@ function useHidAmicoService() {
54358
54456
  await repo.addEvent({ reader: id, site: reader.site, type: "sync_failed", payload: { message } });
54359
54457
  throw error;
54360
54458
  } finally {
54361
- await client2.logout();
54459
+ await client3.logout();
54362
54460
  }
54363
54461
  }
54364
54462
  async function isIdentityAssignedToReader(reader, identity, requestedPortalId) {
@@ -54474,9 +54572,9 @@ function useHidAmicoService() {
54474
54572
  async function listReaderUsers(readerId, page2 = 1, limit = 10, search = "", status = "", includeVisitors = false, userType = "all") {
54475
54573
  const reader = await getActiveReader(readerId);
54476
54574
  const offset = (page2 - 1) * limit;
54477
- const client2 = new HidAmicoClient(reader);
54575
+ const client3 = new HidAmicoClient(reader);
54478
54576
  try {
54479
- await client2.login();
54577
+ await client3.login();
54480
54578
  const normalizedSearch = search.trim();
54481
54579
  const numericSearch = /^\d{1,15}$/.test(normalizedSearch) ? Number(normalizedSearch) : null;
54482
54580
  const userWhere = {};
@@ -54488,7 +54586,7 @@ function useHidAmicoService() {
54488
54586
  let rows = [];
54489
54587
  let reportedTotal = null;
54490
54588
  let hasMore = false;
54491
- const response = await client2.loadObjects({
54589
+ const response = await client3.loadObjects({
54492
54590
  object: "users",
54493
54591
  where: { users: userWhere },
54494
54592
  limit: 500,
@@ -54508,7 +54606,7 @@ function useHidAmicoService() {
54508
54606
  const userId = Number(row.id);
54509
54607
  if (!Number.isSafeInteger(userId) || userId <= 0)
54510
54608
  return false;
54511
- const roleResponse = await client2.loadObjects({
54609
+ const roleResponse = await client3.loadObjects({
54512
54610
  object: "user_roles",
54513
54611
  where: { user_roles: { user_id: userId, role: 1 } },
54514
54612
  limit: 1,
@@ -54516,7 +54614,7 @@ function useHidAmicoService() {
54516
54614
  });
54517
54615
  return getHidObjectRows(roleResponse, "user_roles").length > 0;
54518
54616
  })),
54519
- readerSupportsFacial(reader) ? client2.listUserImageIds().catch(() => []) : Promise.resolve([])
54617
+ readerSupportsFacial(reader) ? client3.listUserImageIds().catch(() => []) : Promise.resolve([])
54520
54618
  ]);
54521
54619
  const facialUserIdSet = new Set(facialUserIds.map(String));
54522
54620
  const items = rows.map((row, index) => {
@@ -54546,15 +54644,15 @@ function useHidAmicoService() {
54546
54644
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${reportedTotal ?? `${offset + items.length}${hasMore ? "+" : ""}`}` : "0-0 of 0"
54547
54645
  };
54548
54646
  } finally {
54549
- await client2.logout();
54647
+ await client3.logout();
54550
54648
  }
54551
54649
  }
54552
54650
  async function listReaderAccessLogs(readerId, page2 = 1, limit = 10, search = "", status = "", method = "", tab = "all") {
54553
54651
  const reader = await getActiveReader(readerId);
54554
54652
  const offset = (page2 - 1) * limit;
54555
- const client2 = new HidAmicoClient(reader);
54653
+ const client3 = new HidAmicoClient(reader);
54556
54654
  try {
54557
- await client2.login();
54655
+ await client3.login();
54558
54656
  const where = {};
54559
54657
  if (status === "authorized")
54560
54658
  where.event = 7;
@@ -54575,7 +54673,7 @@ function useHidAmicoService() {
54575
54673
  const userIds = [...new Set(rows.map((row) => toPositiveInteger(row.user_id ?? row.userId)).filter((value) => value !== null))];
54576
54674
  const [identities, roleResponse, userResponse] = await Promise.all([
54577
54675
  repo.findIdentitiesByHidUserIds(readerId, userIds.map(String)),
54578
- userIds.length ? client2.loadObjects({
54676
+ userIds.length ? client3.loadObjects({
54579
54677
  object: "user_roles",
54580
54678
  where: {
54581
54679
  user_roles: {
@@ -54586,7 +54684,7 @@ function useHidAmicoService() {
54586
54684
  limit: Math.max(1, userIds.length),
54587
54685
  offset: 0
54588
54686
  }) : Promise.resolve({ user_roles: [] }),
54589
- userIds.length ? client2.loadObjects({
54687
+ userIds.length ? client3.loadObjects({
54590
54688
  object: "users",
54591
54689
  where: {
54592
54690
  users: {
@@ -54658,7 +54756,7 @@ function useHidAmicoService() {
54658
54756
  let deviceOffset = 0;
54659
54757
  let exhausted = false;
54660
54758
  while (!exhausted && matchedItems.length < targetCount) {
54661
- const response = await client2.loadObjects({
54759
+ const response = await client3.loadObjects({
54662
54760
  object: "access_logs",
54663
54761
  ...Object.keys(where).length ? { where: { access_logs: where } } : {},
54664
54762
  limit: chunkSize,
@@ -54685,7 +54783,7 @@ function useHidAmicoService() {
54685
54783
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${offset + items.length}${hasMore ? "+" : ""}` : "0-0 of 0"
54686
54784
  };
54687
54785
  } finally {
54688
- await client2.logout();
54786
+ await client3.logout();
54689
54787
  }
54690
54788
  }
54691
54789
  async function createIdentity(readerId, value) {
@@ -54777,18 +54875,18 @@ function useHidAmicoService() {
54777
54875
  async function runObjectOperation(id, operation, payload) {
54778
54876
  const reader = await getActiveReader(id);
54779
54877
  assertAllowedHidObject(payload.object, operation);
54780
- const client2 = new HidAmicoClient(reader);
54878
+ const client3 = new HidAmicoClient(reader);
54781
54879
  try {
54782
- await client2.login();
54880
+ await client3.login();
54783
54881
  let result;
54784
54882
  if (operation === "load") {
54785
- result = await client2.loadObjects(payload);
54883
+ result = await client3.loadObjects(payload);
54786
54884
  } else if (operation === "create") {
54787
- result = await client2.createObjects(payload);
54885
+ result = await client3.createObjects(payload);
54788
54886
  } else if (operation === "modify") {
54789
- result = await client2.modifyObjects(payload);
54887
+ result = await client3.modifyObjects(payload);
54790
54888
  } else {
54791
- result = await client2.destroyObjects(payload);
54889
+ result = await client3.destroyObjects(payload);
54792
54890
  }
54793
54891
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
54794
54892
  const safeRequest = sanitizeHidObjectPayload(payload.object, payload);
@@ -54812,7 +54910,7 @@ function useHidAmicoService() {
54812
54910
  });
54813
54911
  throw error;
54814
54912
  } finally {
54815
- await client2.logout();
54913
+ await client3.logout();
54816
54914
  }
54817
54915
  }
54818
54916
  async function issueVisitorQrAtReader(readerId, value) {
@@ -54843,10 +54941,10 @@ function useHidAmicoService() {
54843
54941
  const hidUserId = createStableHidId(`visitor:${readerId}:${value.visitorId}`);
54844
54942
  const registration = `VIS-${value.visitorId.slice(-12).toUpperCase()}`;
54845
54943
  const credential = createVisitorQrCredential(value.visitorId, readerId, value.qrValue);
54846
- const client2 = new HidAmicoClient(reader);
54944
+ const client3 = new HidAmicoClient(reader);
54847
54945
  try {
54848
- await client2.login();
54849
- const readerConfigurationChanged = await configureVisitorQrReader(client2);
54946
+ await client3.login();
54947
+ const readerConfigurationChanged = await configureVisitorQrReader(client3);
54850
54948
  if (readerConfigurationChanged) {
54851
54949
  await repo.addEvent({
54852
54950
  reader: readerId,
@@ -54860,7 +54958,7 @@ function useHidAmicoService() {
54860
54958
  }
54861
54959
  });
54862
54960
  }
54863
- const existingUserResponse = await client2.loadObjects({
54961
+ const existingUserResponse = await client3.loadObjects({
54864
54962
  object: "users",
54865
54963
  where: { users: { id: hidUserId } },
54866
54964
  limit: 1,
@@ -54881,18 +54979,18 @@ function useHidAmicoService() {
54881
54979
  );
54882
54980
  }
54883
54981
  if (existingUsers.length) {
54884
- await client2.modifyObjects({
54982
+ await client3.modifyObjects({
54885
54983
  object: "users",
54886
54984
  where: { users: { id: hidUserId } },
54887
54985
  values: user
54888
54986
  });
54889
54987
  } else {
54890
- await client2.createObjects({
54988
+ await client3.createObjects({
54891
54989
  object: "users",
54892
54990
  values: [{ id: hidUserId, ...user }]
54893
54991
  });
54894
54992
  }
54895
- const savedUserResponse = await client2.loadObjects({
54993
+ const savedUserResponse = await client3.loadObjects({
54896
54994
  object: "users",
54897
54995
  where: { users: { id: hidUserId } },
54898
54996
  limit: 1,
@@ -54907,12 +55005,12 @@ function useHidAmicoService() {
54907
55005
  );
54908
55006
  }
54909
55007
  const authorization = await ensureVisitorAccessAuthorization(
54910
- client2,
55008
+ client3,
54911
55009
  readerId,
54912
55010
  reader,
54913
55011
  hidUserId
54914
55012
  );
54915
- const existingQrResponse = await client2.loadObjects({
55013
+ const existingQrResponse = await client3.loadObjects({
54916
55014
  object: credential.object,
54917
55015
  where: { [credential.object]: { user_id: hidUserId } },
54918
55016
  limit: 100,
@@ -54921,18 +55019,18 @@ function useHidAmicoService() {
54921
55019
  const existingQrs = getHidObjectRows(existingQrResponse, credential.object);
54922
55020
  const credentialValues = { value: credential.value, user_id: hidUserId };
54923
55021
  if (existingQrs.some((row) => String(row.id) === String(credential.credentialId))) {
54924
- await client2.modifyObjects({
55022
+ await client3.modifyObjects({
54925
55023
  object: credential.object,
54926
55024
  where: { [credential.object]: { id: credential.credentialId } },
54927
55025
  values: credentialValues
54928
55026
  });
54929
55027
  } else {
54930
- await client2.createObjects({
55028
+ await client3.createObjects({
54931
55029
  object: credential.object,
54932
55030
  values: [{ id: credential.credentialId, ...credentialValues }]
54933
55031
  });
54934
55032
  }
54935
- const savedCredentialResponse = await client2.loadObjects({
55033
+ const savedCredentialResponse = await client3.loadObjects({
54936
55034
  object: credential.object,
54937
55035
  where: { [credential.object]: { id: credential.credentialId } },
54938
55036
  limit: 1,
@@ -54950,20 +55048,20 @@ function useHidAmicoService() {
54950
55048
  for (const staleQr of existingQrs) {
54951
55049
  const staleId = Number(staleQr.id);
54952
55050
  if (Number.isSafeInteger(staleId) && staleId > 0 && staleId !== credential.credentialId) {
54953
- await client2.destroyObjects({
55051
+ await client3.destroyObjects({
54954
55052
  object: credential.object,
54955
55053
  where: { [credential.object]: { id: staleId } }
54956
55054
  });
54957
55055
  }
54958
55056
  }
54959
- const existingCardsResponse = await client2.loadObjects({
55057
+ const existingCardsResponse = await client3.loadObjects({
54960
55058
  object: "cards",
54961
55059
  where: { cards: { user_id: hidUserId } },
54962
55060
  limit: 100,
54963
55061
  offset: 0
54964
55062
  });
54965
55063
  if (getHidObjectRows(existingCardsResponse, "cards").length) {
54966
- await client2.destroyObjects({
55064
+ await client3.destroyObjects({
54967
55065
  object: "cards",
54968
55066
  where: { cards: { user_id: hidUserId } }
54969
55067
  });
@@ -55044,7 +55142,7 @@ function useHidAmicoService() {
55044
55142
  });
55045
55143
  throw error;
55046
55144
  } finally {
55047
- await client2.logout();
55145
+ await client3.logout();
55048
55146
  }
55049
55147
  }
55050
55148
  async function resolveVisitorQrGateReaders(siteId, callerId5, fallbackReaderId, issuer) {
@@ -55162,10 +55260,10 @@ function useHidAmicoService() {
55162
55260
  const enrolledAt = /* @__PURE__ */ new Date();
55163
55261
  const timestamp = options.timestamp || Math.floor(enrolledAt.getTime() / 1e3);
55164
55262
  const match = options.match ?? true;
55165
- const client2 = new HidAmicoClient(reader);
55263
+ const client3 = new HidAmicoClient(reader);
55166
55264
  try {
55167
- await client2.login();
55168
- const existingUserResponse = await client2.loadObjects({
55265
+ await client3.login();
55266
+ const existingUserResponse = await client3.loadObjects({
55169
55267
  object: "users",
55170
55268
  where: { users: { id: context.hidUserId } },
55171
55269
  limit: 1,
@@ -55176,18 +55274,18 @@ function useHidAmicoService() {
55176
55274
  registration: context.registration
55177
55275
  };
55178
55276
  if (getHidObjectRows(existingUserResponse, "users").length) {
55179
- await client2.modifyObjects({
55277
+ await client3.modifyObjects({
55180
55278
  object: "users",
55181
55279
  where: { users: { id: context.hidUserId } },
55182
55280
  values: hidUser
55183
55281
  });
55184
55282
  } else {
55185
- await client2.createObjects({
55283
+ await client3.createObjects({
55186
55284
  object: "users",
55187
55285
  values: [{ id: context.hidUserId, ...hidUser }]
55188
55286
  });
55189
55287
  }
55190
- const result = await client2.setUserImage(context.hidUserId, image, timestamp, match);
55288
+ const result = await client3.setUserImage(context.hidUserId, image, timestamp, match);
55191
55289
  const existingIdentity = context.profileIdentity || await repo.findExistingIdentity({
55192
55290
  reader: readerId,
55193
55291
  hidUserId: context.hidUserId
@@ -55252,25 +55350,25 @@ function useHidAmicoService() {
55252
55350
  });
55253
55351
  throw error;
55254
55352
  } finally {
55255
- await client2.logout();
55353
+ await client3.logout();
55256
55354
  }
55257
55355
  }
55258
55356
  async function getUserImage(readerId, hidUserId) {
55259
55357
  const reader = await getActiveReader(readerId);
55260
55358
  assertReaderCapability(reader, "facial");
55261
- const client2 = new HidAmicoClient(reader);
55359
+ const client3 = new HidAmicoClient(reader);
55262
55360
  try {
55263
- await client2.login();
55264
- return await client2.getUserImage(hidUserId);
55361
+ await client3.login();
55362
+ return await client3.getUserImage(hidUserId);
55265
55363
  } finally {
55266
- await client2.logout();
55364
+ await client3.logout();
55267
55365
  }
55268
55366
  }
55269
- async function getReaderFacialUserIds(client2) {
55367
+ async function getReaderFacialUserIds(client3) {
55270
55368
  try {
55271
- return await client2.listUserImageIds();
55369
+ return await client3.listUserImageIds();
55272
55370
  } catch {
55273
- const usersResponse = await client2.loadObjects({
55371
+ const usersResponse = await client3.loadObjects({
55274
55372
  object: "users",
55275
55373
  where: { users: {} },
55276
55374
  limit: 500,
@@ -55284,7 +55382,7 @@ function useHidAmicoService() {
55284
55382
  const batch = userIds.slice(offset, offset + batchSize);
55285
55383
  const results = await Promise.all(batch.map(async (userId) => {
55286
55384
  try {
55287
- const image = await client2.getUserImage(userId);
55385
+ const image = await client3.getUserImage(userId);
55288
55386
  return image.base64 ? userId : null;
55289
55387
  } catch {
55290
55388
  return null;
@@ -55298,10 +55396,10 @@ function useHidAmicoService() {
55298
55396
  async function syncReaderFacialData(readerId) {
55299
55397
  const reader = await getActiveReader(readerId);
55300
55398
  assertReaderCapability(reader, "facial");
55301
- const client2 = new HidAmicoClient(reader);
55399
+ const client3 = new HidAmicoClient(reader);
55302
55400
  try {
55303
- await client2.login();
55304
- const facialUserIds = await getReaderFacialUserIds(client2);
55401
+ await client3.login();
55402
+ const facialUserIds = await getReaderFacialUserIds(client3);
55305
55403
  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.";
55306
55404
  await repo.updateById(readerId, { status: "active", lastSeenAt: /* @__PURE__ */ new Date() });
55307
55405
  await repo.addEvent({
@@ -55333,7 +55431,7 @@ function useHidAmicoService() {
55333
55431
  });
55334
55432
  throw error;
55335
55433
  } finally {
55336
- await client2.logout();
55434
+ await client3.logout();
55337
55435
  }
55338
55436
  }
55339
55437
  async function setVisitorImage(readerId, visitorId, image, options = {}) {
@@ -55352,10 +55450,10 @@ function useHidAmicoService() {
55352
55450
  );
55353
55451
  const timestamp = options.timestamp || Math.floor(issuedAt.getTime() / 1e3);
55354
55452
  const match = options.match ?? true;
55355
- const client2 = new HidAmicoClient(reader);
55453
+ const client3 = new HidAmicoClient(reader);
55356
55454
  try {
55357
- await client2.login();
55358
- const existingUserResponse = await client2.loadObjects({
55455
+ await client3.login();
55456
+ const existingUserResponse = await client3.loadObjects({
55359
55457
  object: "users",
55360
55458
  where: { users: { id: hidUserId } },
55361
55459
  limit: 1,
@@ -55369,24 +55467,24 @@ function useHidAmicoService() {
55369
55467
  end_time: Math.floor(expiresAt.getTime() / 1e3)
55370
55468
  };
55371
55469
  if (getHidObjectRows(existingUserResponse, "users").length) {
55372
- await client2.modifyObjects({
55470
+ await client3.modifyObjects({
55373
55471
  object: "users",
55374
55472
  where: { users: { id: hidUserId } },
55375
55473
  values: user
55376
55474
  });
55377
55475
  } else {
55378
- await client2.createObjects({
55476
+ await client3.createObjects({
55379
55477
  object: "users",
55380
55478
  values: [{ id: hidUserId, ...user }]
55381
55479
  });
55382
55480
  }
55383
55481
  const authorization = await ensureVisitorAccessAuthorization(
55384
- client2,
55482
+ client3,
55385
55483
  readerId,
55386
55484
  reader,
55387
55485
  hidUserId
55388
55486
  );
55389
- const result = await client2.setUserImage(hidUserId, image, timestamp, match);
55487
+ const result = await client3.setUserImage(hidUserId, image, timestamp, match);
55390
55488
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
55391
55489
  const existingMetadata = existingIdentity && isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
55392
55490
  const identityPayload = {
@@ -55452,17 +55550,17 @@ function useHidAmicoService() {
55452
55550
  });
55453
55551
  throw error;
55454
55552
  } finally {
55455
- await client2.logout();
55553
+ await client3.logout();
55456
55554
  }
55457
55555
  }
55458
55556
  async function deleteVisitorImage(readerId, visitorId) {
55459
55557
  const reader = await getActiveReader(readerId);
55460
55558
  assertReaderCapability(reader, "facial");
55461
55559
  const { hidUserId } = await getVisitorEnrollmentContext(readerId, reader, visitorId);
55462
- const client2 = new HidAmicoClient(reader);
55560
+ const client3 = new HidAmicoClient(reader);
55463
55561
  try {
55464
- await client2.login();
55465
- const result = await client2.deleteUserImage(hidUserId);
55562
+ await client3.login();
55563
+ const result = await client3.deleteUserImage(hidUserId);
55466
55564
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
55467
55565
  if (existingIdentity?._id) {
55468
55566
  const existingMetadata = isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
@@ -55491,7 +55589,7 @@ function useHidAmicoService() {
55491
55589
  });
55492
55590
  throw error;
55493
55591
  } finally {
55494
- await client2.logout();
55592
+ await client3.logout();
55495
55593
  }
55496
55594
  }
55497
55595
  async function listUserCards(readerId, hidUserIdValue) {
@@ -55499,19 +55597,19 @@ function useHidAmicoService() {
55499
55597
  assertReaderCapability(reader, "card");
55500
55598
  const cardType = reader.cardReadingMode === "pacs" || reader.cardReadingMode === "csn" ? reader.cardReadingMode : "unknown";
55501
55599
  const hidUserId = Number(hidUserIdValue);
55502
- const client2 = new HidAmicoClient(reader);
55600
+ const client3 = new HidAmicoClient(reader);
55503
55601
  try {
55504
- await client2.login();
55505
- await assertHidUserExists(client2, hidUserId);
55602
+ await client3.login();
55603
+ await assertHidUserExists(client3, hidUserId);
55506
55604
  const [rows, identity] = await Promise.all([
55507
- loadPhysicalCardRows(client2, hidUserId),
55605
+ loadPhysicalCardRows(client3, hidUserId),
55508
55606
  repo.findExistingIdentity({ reader: readerId, hidUserId })
55509
55607
  ]);
55510
55608
  const metadataRows = getIdentityPhysicalCards(identity);
55511
55609
  const cards = rows.map((row) => toHidPhysicalCard(row, metadataRows, cardType)).filter((card) => Boolean(card));
55512
55610
  return { readerId, hidUserId, cards };
55513
55611
  } finally {
55514
- await client2.logout();
55612
+ await client3.logout();
55515
55613
  }
55516
55614
  }
55517
55615
  async function assignUserCard(readerId, hidUserIdValue, input) {
@@ -55525,12 +55623,12 @@ function useHidAmicoService() {
55525
55623
  } catch (error) {
55526
55624
  throw new BadRequestError126(getErrorMessage2(error));
55527
55625
  }
55528
- const client2 = new HidAmicoClient(reader);
55626
+ const client3 = new HidAmicoClient(reader);
55529
55627
  try {
55530
- await client2.login();
55531
- await assertHidUserExists(client2, hidUserId);
55532
- await ensurePhysicalCardIdentification(client2);
55533
- const collisionResponse = await client2.loadObjects({
55628
+ await client3.login();
55629
+ await assertHidUserExists(client3, hidUserId);
55630
+ await ensurePhysicalCardIdentification(client3);
55631
+ const collisionResponse = await client3.loadObjects({
55534
55632
  object: "cards",
55535
55633
  where: { cards: { value: hidRawUint64(cardValue) } },
55536
55634
  limit: 10,
@@ -55548,11 +55646,11 @@ function useHidAmicoService() {
55548
55646
  );
55549
55647
  if (!savedRow) {
55550
55648
  const credentialId = createStableHidId(`physical-card:${readerId}:${cardValue}`);
55551
- await client2.createObjects({
55649
+ await client3.createObjects({
55552
55650
  object: "cards",
55553
55651
  values: [{ id: credentialId, value: hidRawUint64(cardValue), user_id: hidUserId }]
55554
55652
  });
55555
- const verifiedResponse = await client2.loadObjects({
55653
+ const verifiedResponse = await client3.loadObjects({
55556
55654
  object: "cards",
55557
55655
  where: { cards: { id: credentialId } },
55558
55656
  limit: 1,
@@ -55593,7 +55691,7 @@ function useHidAmicoService() {
55593
55691
  });
55594
55692
  throw error;
55595
55693
  } finally {
55596
- await client2.logout();
55694
+ await client3.logout();
55597
55695
  }
55598
55696
  }
55599
55697
  async function enrollUserCard(readerId, hidUserIdValue, cardType, timeoutSeconds) {
@@ -55601,17 +55699,17 @@ function useHidAmicoService() {
55601
55699
  assertReaderCapability(reader, "card");
55602
55700
  assertReaderCardProfile(reader, cardType);
55603
55701
  const hidUserId = Number(hidUserIdValue);
55604
- const client2 = new HidAmicoClient(reader);
55702
+ const client3 = new HidAmicoClient(reader);
55605
55703
  const lockOwner = crypto6.randomUUID();
55606
55704
  const acquired = await repo.acquireEnrollmentLock(readerId, lockOwner, timeoutSeconds + 30);
55607
55705
  if (!acquired) {
55608
55706
  throw new BadRequestError126("Another physical HID card enrollment is already running on this reader.");
55609
55707
  }
55610
55708
  try {
55611
- await client2.login();
55612
- await assertHidUserExists(client2, hidUserId);
55613
- await ensurePhysicalCardIdentification(client2);
55614
- const beforeRows = await loadPhysicalCardRows(client2, hidUserId);
55709
+ await client3.login();
55710
+ await assertHidUserExists(client3, hidUserId);
55711
+ await ensurePhysicalCardIdentification(client3);
55712
+ const beforeRows = await loadPhysicalCardRows(client3, hidUserId);
55615
55713
  const beforeValues = new Set(beforeRows.map((row) => String(row.value ?? "")));
55616
55714
  await repo.addEvent({
55617
55715
  reader: readerId,
@@ -55620,7 +55718,7 @@ function useHidAmicoService() {
55620
55718
  payload: { hidUserId, cardType, timeoutSeconds }
55621
55719
  });
55622
55720
  const startedAt = Date.now();
55623
- const response = await client2.remoteEnrollCard(hidUserId, timeoutSeconds);
55721
+ const response = await client3.remoteEnrollCard(hidUserId, timeoutSeconds);
55624
55722
  const responseRecord = isUnknownRecord2(response) ? response : {};
55625
55723
  const responseData = isUnknownRecord2(responseRecord.data) ? responseRecord.data : responseRecord;
55626
55724
  if (responseData.success === false) {
@@ -55637,7 +55735,7 @@ function useHidAmicoService() {
55637
55735
  const deadline = startedAt + timeoutSeconds * 1e3;
55638
55736
  let savedRow;
55639
55737
  do {
55640
- const rows = await loadPhysicalCardRows(client2, hidUserId);
55738
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
55641
55739
  savedRow = responseValue === null ? rows.find((row) => !beforeValues.has(String(row.value ?? ""))) : rows.find((row) => String(row.value ?? "") === String(responseValue));
55642
55740
  if (savedRow || Date.now() >= deadline)
55643
55741
  break;
@@ -55670,7 +55768,7 @@ function useHidAmicoService() {
55670
55768
  return { readerId, hidUserId, card, verified: true };
55671
55769
  } catch (error) {
55672
55770
  try {
55673
- await client2.cancelRemoteEnrollment();
55771
+ await client3.cancelRemoteEnrollment();
55674
55772
  } catch {
55675
55773
  }
55676
55774
  await repo.addEvent({
@@ -55683,15 +55781,15 @@ function useHidAmicoService() {
55683
55781
  throw error;
55684
55782
  } finally {
55685
55783
  await repo.releaseEnrollmentLock(readerId, lockOwner);
55686
- await client2.logout();
55784
+ await client3.logout();
55687
55785
  }
55688
55786
  }
55689
55787
  async function cancelUserCardEnrollment(readerId) {
55690
55788
  const reader = await getActiveReader(readerId);
55691
- const client2 = new HidAmicoClient(reader);
55789
+ const client3 = new HidAmicoClient(reader);
55692
55790
  try {
55693
- await client2.login();
55694
- await client2.cancelRemoteEnrollment();
55791
+ await client3.login();
55792
+ await client3.cancelRemoteEnrollment();
55695
55793
  const enrollmentWasRunning = await repo.releaseEnrollmentLock(readerId);
55696
55794
  await repo.addEvent({
55697
55795
  reader: readerId,
@@ -55701,27 +55799,27 @@ function useHidAmicoService() {
55701
55799
  });
55702
55800
  return { readerId, cancelled: true };
55703
55801
  } finally {
55704
- await client2.logout();
55802
+ await client3.logout();
55705
55803
  }
55706
55804
  }
55707
55805
  async function deleteUserCard(readerId, hidUserIdValue, cardIdValue) {
55708
55806
  const reader = await getActiveReader(readerId);
55709
55807
  const hidUserId = Number(hidUserIdValue);
55710
55808
  const cardId = Number(cardIdValue);
55711
- const client2 = new HidAmicoClient(reader);
55809
+ const client3 = new HidAmicoClient(reader);
55712
55810
  try {
55713
- await client2.login();
55714
- const rows = await loadPhysicalCardRows(client2, hidUserId);
55811
+ await client3.login();
55812
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
55715
55813
  const cardRow = rows.find((row) => String(row.id ?? "") === String(cardId));
55716
55814
  if (!cardRow) {
55717
55815
  throw new BadRequestError126("Physical HID card was not found for this HID user.");
55718
55816
  }
55719
55817
  const cardValue = String(normalizeHidCardValue(cardRow.value));
55720
- await client2.destroyObjects({
55818
+ await client3.destroyObjects({
55721
55819
  object: "cards",
55722
55820
  where: { cards: { id: cardId } }
55723
55821
  });
55724
- const verifiedRows = await loadPhysicalCardRows(client2, hidUserId);
55822
+ const verifiedRows = await loadPhysicalCardRows(client3, hidUserId);
55725
55823
  if (verifiedRows.some((row) => String(row.id ?? "") === String(cardId))) {
55726
55824
  throw new BadRequestError126("The HID reader did not remove the physical card.");
55727
55825
  }
@@ -55744,17 +55842,17 @@ function useHidAmicoService() {
55744
55842
  });
55745
55843
  throw error;
55746
55844
  } finally {
55747
- await client2.logout();
55845
+ await client3.logout();
55748
55846
  }
55749
55847
  }
55750
55848
  async function getUserPinStatus(readerId, hidUserIdValue) {
55751
55849
  const reader = await getActiveReader(readerId);
55752
55850
  assertReaderCapability(reader, "pin");
55753
55851
  const hidUserId = Number(hidUserIdValue);
55754
- const client2 = new HidAmicoClient(reader);
55852
+ const client3 = new HidAmicoClient(reader);
55755
55853
  try {
55756
- await client2.login();
55757
- const response = await client2.loadObjects({
55854
+ await client3.login();
55855
+ const response = await client3.loadObjects({
55758
55856
  object: "pins",
55759
55857
  where: { pins: { user_id: hidUserId } },
55760
55858
  limit: 1,
@@ -55762,7 +55860,7 @@ function useHidAmicoService() {
55762
55860
  });
55763
55861
  return { readerId, hidUserId, pinEnrolled: getHidObjectRows(response, "pins").length > 0 };
55764
55862
  } finally {
55765
- await client2.logout();
55863
+ await client3.logout();
55766
55864
  }
55767
55865
  }
55768
55866
  async function setUserPin(readerId, hidUserIdValue, pin) {
@@ -55770,10 +55868,10 @@ function useHidAmicoService() {
55770
55868
  assertReaderCapability(reader, "pin");
55771
55869
  const hidUserId = Number(hidUserIdValue);
55772
55870
  const credentialId = createStableHidId(`user-pin:${readerId}:${hidUserId}`);
55773
- const client2 = new HidAmicoClient(reader);
55871
+ const client3 = new HidAmicoClient(reader);
55774
55872
  try {
55775
- await client2.login();
55776
- const userResponse = await client2.loadObjects({
55873
+ await client3.login();
55874
+ const userResponse = await client3.loadObjects({
55777
55875
  object: "users",
55778
55876
  where: { users: { id: hidUserId } },
55779
55877
  limit: 1,
@@ -55783,13 +55881,13 @@ function useHidAmicoService() {
55783
55881
  throw new BadRequestError126("HID user must exist before assigning an access PIN.");
55784
55882
  }
55785
55883
  const [byUserResponse, byValueResponse] = await Promise.all([
55786
- client2.loadObjects({
55884
+ client3.loadObjects({
55787
55885
  object: "pins",
55788
55886
  where: { pins: { user_id: hidUserId } },
55789
55887
  limit: 10,
55790
55888
  offset: 0
55791
55889
  }),
55792
- client2.loadObjects({
55890
+ client3.loadObjects({
55793
55891
  object: "pins",
55794
55892
  where: { pins: { value: pin } },
55795
55893
  limit: 10,
@@ -55805,18 +55903,18 @@ function useHidAmicoService() {
55805
55903
  }
55806
55904
  const existingPin = existingPins[0];
55807
55905
  if (existingPin) {
55808
- await client2.modifyObjects({
55906
+ await client3.modifyObjects({
55809
55907
  object: "pins",
55810
55908
  where: { pins: { id: existingPin.id } },
55811
55909
  values: { value: pin, user_id: hidUserId }
55812
55910
  });
55813
55911
  } else {
55814
- await client2.createObjects({
55912
+ await client3.createObjects({
55815
55913
  object: "pins",
55816
55914
  values: [{ id: credentialId, value: pin, user_id: hidUserId }]
55817
55915
  });
55818
55916
  }
55819
- const savedResponse = await client2.loadObjects({
55917
+ const savedResponse = await client3.loadObjects({
55820
55918
  object: "pins",
55821
55919
  where: { pins: { user_id: hidUserId } },
55822
55920
  limit: 1,
@@ -55826,7 +55924,7 @@ function useHidAmicoService() {
55826
55924
  if (!savedPin || String(savedPin.value) !== pin) {
55827
55925
  throw new BadRequestError126("The HID reader did not retain the access PIN.");
55828
55926
  }
55829
- await client2.setConfiguration({
55927
+ await client3.setConfiguration({
55830
55928
  identifier: {
55831
55929
  pin_identification_enabled: "1",
55832
55930
  multi_factor_authentication: "0"
@@ -55850,17 +55948,17 @@ function useHidAmicoService() {
55850
55948
  });
55851
55949
  throw error;
55852
55950
  } finally {
55853
- await client2.logout();
55951
+ await client3.logout();
55854
55952
  }
55855
55953
  }
55856
55954
  async function deleteUserPin(readerId, hidUserIdValue) {
55857
55955
  const reader = await getActiveReader(readerId);
55858
55956
  assertReaderCapability(reader, "pin");
55859
55957
  const hidUserId = Number(hidUserIdValue);
55860
- const client2 = new HidAmicoClient(reader);
55958
+ const client3 = new HidAmicoClient(reader);
55861
55959
  try {
55862
- await client2.login();
55863
- await client2.destroyObjects({
55960
+ await client3.login();
55961
+ await client3.destroyObjects({
55864
55962
  object: "pins",
55865
55963
  where: { pins: { user_id: hidUserId } }
55866
55964
  });
@@ -55882,7 +55980,7 @@ function useHidAmicoService() {
55882
55980
  });
55883
55981
  throw error;
55884
55982
  } finally {
55885
- await client2.logout();
55983
+ await client3.logout();
55886
55984
  }
55887
55985
  }
55888
55986
  async function revokeVisitorQr(readerId, visitorId) {
@@ -55894,44 +55992,44 @@ function useHidAmicoService() {
55894
55992
  "The generated HID user ID is assigned to another visitor."
55895
55993
  );
55896
55994
  }
55897
- const client2 = new HidAmicoClient(reader);
55995
+ const client3 = new HidAmicoClient(reader);
55898
55996
  try {
55899
- await client2.login();
55900
- const existingUserResponse = await client2.loadObjects({
55997
+ await client3.login();
55998
+ const existingUserResponse = await client3.loadObjects({
55901
55999
  object: "users",
55902
56000
  where: { users: { id: hidUserId } },
55903
56001
  limit: 1,
55904
56002
  offset: 0
55905
56003
  });
55906
56004
  const deviceUserExists = getHidObjectRows(existingUserResponse, "users").length > 0;
55907
- await client2.destroyObjects({
56005
+ await client3.destroyObjects({
55908
56006
  object: "qrcodes",
55909
56007
  where: { qrcodes: { user_id: hidUserId } }
55910
56008
  });
55911
- await client2.destroyObjects({
56009
+ await client3.destroyObjects({
55912
56010
  object: "cards",
55913
56011
  where: { cards: { user_id: hidUserId } }
55914
56012
  });
55915
56013
  if (reader.capabilities?.pin === true) {
55916
- await client2.destroyObjects({
56014
+ await client3.destroyObjects({
55917
56015
  object: "pins",
55918
56016
  where: { pins: { user_id: hidUserId } }
55919
56017
  });
55920
56018
  }
55921
- await client2.destroyObjects({
56019
+ await client3.destroyObjects({
55922
56020
  object: "user_access_rules",
55923
56021
  where: { user_access_rules: { user_id: hidUserId } }
55924
56022
  });
55925
- await client2.destroyObjects({
56023
+ await client3.destroyObjects({
55926
56024
  object: "user_groups",
55927
56025
  where: { user_groups: { user_id: hidUserId } }
55928
56026
  });
55929
56027
  const metadata = identity && isUnknownRecord2(identity.metadata) ? identity.metadata : {};
55930
56028
  if (deviceUserExists && metadata.facialEnrolled === true) {
55931
- await client2.deleteUserImage(hidUserId);
56029
+ await client3.deleteUserImage(hidUserId);
55932
56030
  }
55933
56031
  if (deviceUserExists) {
55934
- await client2.modifyObjects({
56032
+ await client3.modifyObjects({
55935
56033
  object: "users",
55936
56034
  where: { users: { id: hidUserId } },
55937
56035
  values: { end_time: Math.floor(Date.now() / 1e3) }
@@ -55942,7 +56040,7 @@ function useHidAmicoService() {
55942
56040
  if (reader.capabilities?.pin === true)
55943
56041
  credentialObjects.push("pins");
55944
56042
  for (const object of credentialObjects) {
55945
- const response = await client2.loadObjects({
56043
+ const response = await client3.loadObjects({
55946
56044
  object,
55947
56045
  where: { [object]: { user_id: hidUserId } },
55948
56046
  limit: 1,
@@ -55950,7 +56048,7 @@ function useHidAmicoService() {
55950
56048
  });
55951
56049
  credentialRemains || (credentialRemains = getHidObjectRows(response, object).length > 0);
55952
56050
  }
55953
- const savedUser = await client2.loadObjects({
56051
+ const savedUser = await client3.loadObjects({
55954
56052
  object: "users",
55955
56053
  where: { users: { id: hidUserId } },
55956
56054
  limit: 1,
@@ -55988,7 +56086,7 @@ function useHidAmicoService() {
55988
56086
  });
55989
56087
  throw error;
55990
56088
  } finally {
55991
- await client2.logout();
56089
+ await client3.logout();
55992
56090
  }
55993
56091
  }
55994
56092
  async function queueVisitorQrJob(readerId, visitorId, operation) {
@@ -56098,16 +56196,16 @@ function useHidAmicoService() {
56098
56196
  const reader = await getActiveReader(readerId);
56099
56197
  assertReaderCapability(reader, "facial");
56100
56198
  assertReaderPortal(reader, "enrolling facial recognition");
56101
- const client2 = new HidAmicoClient(reader);
56199
+ const client3 = new HidAmicoClient(reader);
56102
56200
  const timestamp = options.timestamp || Math.floor(Date.now() / 1e3);
56103
56201
  const match = options.match ?? true;
56104
56202
  try {
56105
- await client2.login();
56203
+ await client3.login();
56106
56204
  const numericUserId = Number(hidUserId);
56107
56205
  if (!Number.isSafeInteger(numericUserId) || numericUserId <= 0) {
56108
56206
  throw new BadRequestError126("A valid HID user ID is required for facial enrollment.");
56109
56207
  }
56110
- const result = await client2.setUserImage(numericUserId, image, timestamp, match);
56208
+ const result = await client3.setUserImage(numericUserId, image, timestamp, match);
56111
56209
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56112
56210
  await repo.addEvent({
56113
56211
  reader: readerId,
@@ -56131,16 +56229,16 @@ function useHidAmicoService() {
56131
56229
  });
56132
56230
  throw error;
56133
56231
  } finally {
56134
- await client2.logout();
56232
+ await client3.logout();
56135
56233
  }
56136
56234
  }
56137
56235
  async function deleteUserImage(readerId, hidUserId) {
56138
56236
  const reader = await getActiveReader(readerId);
56139
56237
  assertReaderCapability(reader, "facial");
56140
- const client2 = new HidAmicoClient(reader);
56238
+ const client3 = new HidAmicoClient(reader);
56141
56239
  try {
56142
- await client2.login();
56143
- const result = await client2.deleteUserImage(hidUserId);
56240
+ await client3.login();
56241
+ const result = await client3.deleteUserImage(hidUserId);
56144
56242
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56145
56243
  await repo.addEvent({
56146
56244
  reader: readerId,
@@ -56158,28 +56256,28 @@ function useHidAmicoService() {
56158
56256
  });
56159
56257
  throw error;
56160
56258
  } finally {
56161
- await client2.logout();
56259
+ await client3.logout();
56162
56260
  }
56163
56261
  }
56164
56262
  async function getDoorState(id) {
56165
56263
  const reader = await getActiveReader(id);
56166
- const client2 = new HidAmicoClient(reader);
56264
+ const client3 = new HidAmicoClient(reader);
56167
56265
  try {
56168
- await client2.login();
56169
- const state = await client2.doorState();
56266
+ await client3.login();
56267
+ const state = await client3.doorState();
56170
56268
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56171
56269
  await repo.addEvent({ reader: id, site: reader.site, type: "door_state", payload: state });
56172
56270
  return state;
56173
56271
  } finally {
56174
- await client2.logout();
56272
+ await client3.logout();
56175
56273
  }
56176
56274
  }
56177
56275
  async function executeActions(id, actions) {
56178
56276
  const reader = await getActiveReader(id);
56179
- const client2 = new HidAmicoClient(reader);
56277
+ const client3 = new HidAmicoClient(reader);
56180
56278
  try {
56181
- await client2.login();
56182
- const result = await client2.executeActions(actions);
56279
+ await client3.login();
56280
+ const result = await client3.executeActions(actions);
56183
56281
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56184
56282
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions", payload: { actions, result } });
56185
56283
  return result;
@@ -56187,16 +56285,16 @@ function useHidAmicoService() {
56187
56285
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions_failed", payload: { actions, message: getErrorMessage2(error) } });
56188
56286
  throw error;
56189
56287
  } finally {
56190
- await client2.logout();
56288
+ await client3.logout();
56191
56289
  }
56192
56290
  }
56193
56291
  async function getConfiguration(id, payload) {
56194
56292
  assertAllowedHidConfigurationRead(payload);
56195
56293
  const reader = await getActiveReader(id);
56196
- const client2 = new HidAmicoClient(reader);
56294
+ const client3 = new HidAmicoClient(reader);
56197
56295
  try {
56198
- await client2.login();
56199
- const result = await client2.getConfiguration(payload);
56296
+ await client3.login();
56297
+ const result = await client3.getConfiguration(payload);
56200
56298
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56201
56299
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration", payload: { request: payload, result } });
56202
56300
  return sanitizeHidPayload(result);
@@ -56204,7 +56302,7 @@ function useHidAmicoService() {
56204
56302
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56205
56303
  throw error;
56206
56304
  } finally {
56207
- await client2.logout();
56305
+ await client3.logout();
56208
56306
  }
56209
56307
  }
56210
56308
  async function setConfiguration(id, payload) {
@@ -56216,10 +56314,10 @@ function useHidAmicoService() {
56216
56314
  );
56217
56315
  }
56218
56316
  assertAllowedHidConfiguration(payload);
56219
- const client2 = new HidAmicoClient(reader);
56317
+ const client3 = new HidAmicoClient(reader);
56220
56318
  try {
56221
- await client2.login();
56222
- const result = await client2.setConfiguration(payload);
56319
+ await client3.login();
56320
+ const result = await client3.setConfiguration(payload);
56223
56321
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56224
56322
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration", payload: { request: payload, result } });
56225
56323
  return sanitizeHidPayload(result);
@@ -56227,23 +56325,23 @@ function useHidAmicoService() {
56227
56325
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56228
56326
  throw error;
56229
56327
  } finally {
56230
- await client2.logout();
56328
+ await client3.logout();
56231
56329
  }
56232
56330
  }
56233
56331
  async function getIntercomStatus(id) {
56234
56332
  const reader = await getActiveReader(id);
56235
56333
  assertReaderCapability(reader, "intercom");
56236
- const client2 = new HidAmicoClient(reader);
56334
+ const client3 = new HidAmicoClient(reader);
56237
56335
  try {
56238
- await client2.login();
56336
+ await client3.login();
56239
56337
  let result;
56240
56338
  try {
56241
- result = await client2.getSipStatus();
56339
+ result = await client3.getSipStatus();
56242
56340
  } catch (error) {
56243
56341
  if (!isSipStatusUnavailable(error)) {
56244
56342
  throw error;
56245
56343
  }
56246
- const configuration = await client2.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
56344
+ const configuration = await client3.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
56247
56345
  result = buildSipStatusFallback(configuration, error);
56248
56346
  }
56249
56347
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
@@ -56254,16 +56352,16 @@ function useHidAmicoService() {
56254
56352
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_status_failed", payload: { message: getErrorMessage2(error) } });
56255
56353
  throw error;
56256
56354
  } finally {
56257
- await client2.logout();
56355
+ await client3.logout();
56258
56356
  }
56259
56357
  }
56260
56358
  async function makeIntercomCall(id, target) {
56261
56359
  const reader = await getActiveReader(id);
56262
56360
  assertReaderCapability(reader, "intercom");
56263
- const client2 = new HidAmicoClient(reader);
56361
+ const client3 = new HidAmicoClient(reader);
56264
56362
  try {
56265
- await client2.login();
56266
- const result = await client2.makeSipCall(target);
56363
+ await client3.login();
56364
+ const result = await client3.makeSipCall(target);
56267
56365
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56268
56366
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call", payload: { target, result } });
56269
56367
  return result;
@@ -56271,16 +56369,16 @@ function useHidAmicoService() {
56271
56369
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call_failed", payload: { target, message: getErrorMessage2(error) } });
56272
56370
  throw error;
56273
56371
  } finally {
56274
- await client2.logout();
56372
+ await client3.logout();
56275
56373
  }
56276
56374
  }
56277
56375
  async function finalizeIntercomCall(id) {
56278
56376
  const reader = await getActiveReader(id);
56279
56377
  assertReaderCapability(reader, "intercom");
56280
- const client2 = new HidAmicoClient(reader);
56378
+ const client3 = new HidAmicoClient(reader);
56281
56379
  try {
56282
- await client2.login();
56283
- const result = await client2.finalizeSipCall();
56380
+ await client3.login();
56381
+ const result = await client3.finalizeSipCall();
56284
56382
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56285
56383
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup", payload: result || {} });
56286
56384
  return result;
@@ -56288,7 +56386,7 @@ function useHidAmicoService() {
56288
56386
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup_failed", payload: { message: getErrorMessage2(error) } });
56289
56387
  throw error;
56290
56388
  } finally {
56291
- await client2.logout();
56389
+ await client3.logout();
56292
56390
  }
56293
56391
  }
56294
56392
  function normalizePermissionLocation(value) {
@@ -56345,7 +56443,7 @@ function useHidAmicoService() {
56345
56443
  return "contractor";
56346
56444
  return "staff";
56347
56445
  }
56348
- async function provisionPermissionUser(client2, reader, binding) {
56446
+ async function provisionPermissionUser(client3, reader, binding) {
56349
56447
  const readerId = String(reader._id);
56350
56448
  const existingProfile = await repo.findProfileIdentity(readerId, binding.userId);
56351
56449
  const hidUserId = toPositiveInteger(existingProfile?.hidUserId) ?? createStableHidId(`profile:${readerId}:${binding.userId}`);
@@ -56361,7 +56459,7 @@ function useHidAmicoService() {
56361
56459
  throw new BadRequestError126("The reader already uses this HID user ID for an unmanaged Amico user.");
56362
56460
  }
56363
56461
  const name2 = String(binding.name || "iService365 User").trim() || "iService365 User";
56364
- const existingUser = await client2.loadObjects({
56462
+ const existingUser = await client3.loadObjects({
56365
56463
  object: "users",
56366
56464
  where: { users: { id: hidUserId } },
56367
56465
  limit: 1,
@@ -56369,13 +56467,13 @@ function useHidAmicoService() {
56369
56467
  });
56370
56468
  const userValues = { name: name2, registration };
56371
56469
  if (getHidObjectRows(existingUser, "users").length) {
56372
- await client2.modifyObjects({
56470
+ await client3.modifyObjects({
56373
56471
  object: "users",
56374
56472
  where: { users: { id: hidUserId } },
56375
56473
  values: userValues
56376
56474
  });
56377
56475
  } else {
56378
- await client2.createObjects({
56476
+ await client3.createObjects({
56379
56477
  object: "users",
56380
56478
  values: [{ id: hidUserId, ...userValues }]
56381
56479
  });
@@ -56415,14 +56513,14 @@ function useHidAmicoService() {
56415
56513
  const uniqueBindings = [...new Map(
56416
56514
  bindings.map((binding) => [String(binding.userId), binding])
56417
56515
  ).values()];
56418
- const client2 = new HidAmicoClient(reader);
56516
+ const client3 = new HidAmicoClient(reader);
56419
56517
  try {
56420
- await client2.login();
56518
+ await client3.login();
56421
56519
  const uniqueUserIds = await Promise.all(
56422
- uniqueBindings.map((binding) => provisionPermissionUser(client2, reader, binding))
56520
+ uniqueBindings.map((binding) => provisionPermissionUser(client3, reader, binding))
56423
56521
  );
56424
56522
  const result = await reconcileStandaloneGroupAccess(
56425
- client2,
56523
+ client3,
56426
56524
  readerId,
56427
56525
  Number(reader.portalId),
56428
56526
  uniqueUserIds
@@ -56445,7 +56543,7 @@ function useHidAmicoService() {
56445
56543
  });
56446
56544
  throw error;
56447
56545
  } finally {
56448
- await client2.logout();
56546
+ await client3.logout();
56449
56547
  }
56450
56548
  }
56451
56549
  async function reconcileStoredReaderPermissions(readerId) {
@@ -68037,11 +68135,11 @@ function buildingInPlanFrame(building) {
68037
68135
  lifts
68038
68136
  };
68039
68137
  }
68040
- function openRmfDoorDriver(client2, doorName) {
68138
+ function openRmfDoorDriver(client3, doorName) {
68041
68139
  return {
68042
68140
  name: doorName,
68043
68141
  async read() {
68044
- const s = await client2.doorState(doorName).catch((e) => {
68142
+ const s = await client3.doorState(doorName).catch((e) => {
68045
68143
  if (/HTTP 404/.test(String(e?.message)))
68046
68144
  return null;
68047
68145
  throw e;
@@ -68059,13 +68157,13 @@ function openRmfDoorDriver(client2, doorName) {
68059
68157
  if (request2.requestedMode !== DOOR_MODE.OPEN && request2.requestedMode !== DOOR_MODE.CLOSED) {
68060
68158
  throw new OpenRmfError("A door can only be asked to open or close.");
68061
68159
  }
68062
- await client2.doorRequest(doorName, request2.requestedMode);
68160
+ await client3.doorRequest(doorName, request2.requestedMode);
68063
68161
  }
68064
68162
  };
68065
68163
  }
68066
- function openRmfLiftDriver(client2, liftName) {
68164
+ function openRmfLiftDriver(client3, liftName) {
68067
68165
  const destinations = /* @__PURE__ */ new Map();
68068
- const send2 = (requestType, sessionId, destination, doorState) => client2.liftRequest(liftName, {
68166
+ const send2 = (requestType, sessionId, destination, doorState) => client3.liftRequest(liftName, {
68069
68167
  request_type: requestType,
68070
68168
  door_mode: doorState,
68071
68169
  destination,
@@ -68074,7 +68172,7 @@ function openRmfLiftDriver(client2, liftName) {
68074
68172
  return {
68075
68173
  name: liftName,
68076
68174
  async read() {
68077
- const s = await client2.liftState(liftName).catch((e) => {
68175
+ const s = await client3.liftState(liftName).catch((e) => {
68078
68176
  if (/HTTP 404/.test(String(e?.message)))
68079
68177
  return null;
68080
68178
  throw e;
@@ -68110,18 +68208,18 @@ function openRmfLiftDriver(client2, liftName) {
68110
68208
  };
68111
68209
  }
68112
68210
  function createOpenRmfAdapter(options) {
68113
- const client2 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68211
+ const client3 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68114
68212
  fetch: options?.fetch,
68115
68213
  timeoutMs: options?.timeoutMs
68116
68214
  });
68117
68215
  async function states() {
68118
- const [fleets, building] = await Promise.all([client2.fleets(), client2.buildingMap().catch(() => null)]);
68216
+ const [fleets, building] = await Promise.all([client3.fleets(), client3.buildingMap().catch(() => null)]);
68119
68217
  return { fleets: fleets ?? [], building };
68120
68218
  }
68121
68219
  async function openInterruptions(taskId) {
68122
68220
  if (!taskId)
68123
68221
  return [];
68124
- const t = await client2.taskState(taskId).catch(() => null);
68222
+ const t = await client3.taskState(taskId).catch(() => null);
68125
68223
  return Object.entries(t?.interruptions ?? {}).filter(([, v]) => !v?.resumed_by).map(([token]) => token);
68126
68224
  }
68127
68225
  async function find(robotSn) {
@@ -68133,7 +68231,7 @@ function createOpenRmfAdapter(options) {
68133
68231
  return s ? { key: key2, s, building } : null;
68134
68232
  }
68135
68233
  return {
68136
- client: client2,
68234
+ client: client3,
68137
68235
  brand: OPEN_RMF_BRAND,
68138
68236
  displayName: OPEN_RMF_DISPLAY_NAME,
68139
68237
  capabilities: OPEN_RMF_CAPABILITIES,
@@ -68160,9 +68258,9 @@ function createOpenRmfAdapter(options) {
68160
68258
  const tokens = await openInterruptions(taskId);
68161
68259
  if (!tokens.length)
68162
68260
  throw new OpenRmfError("This robot's task is not paused.");
68163
- res2 = await client2.resumeTask(taskId, tokens);
68261
+ res2 = await client3.resumeTask(taskId, tokens);
68164
68262
  } else {
68165
- res2 = command.kind === "pause" ? await client2.interruptTask(taskId) : await client2.cancelTask(taskId);
68263
+ res2 = command.kind === "pause" ? await client3.interruptTask(taskId) : await client3.cancelTask(taskId);
68166
68264
  }
68167
68265
  if (res2 && res2.success === false)
68168
68266
  throw new OpenRmfError(`The fleet server refused to ${command.kind} the task.`);
@@ -68170,7 +68268,7 @@ function createOpenRmfAdapter(options) {
68170
68268
  }
68171
68269
  const wp = waypointsFor(hit.building, hit.s.location);
68172
68270
  const request2 = taskRequestFor(command, wp.cleaningZones.length ? "cleaning" : "security", wp);
68173
- const res = await client2.robotTask(hit.key.fleet, hit.key.robot, request2);
68271
+ const res = await client3.robotTask(hit.key.fleet, hit.key.robot, request2);
68174
68272
  if (!res?.success)
68175
68273
  throw new OpenRmfError("The fleet server did not accept the task.");
68176
68274
  },
@@ -68186,7 +68284,7 @@ function createOpenRmfAdapter(options) {
68186
68284
  const taskId = hit?.s.task_id;
68187
68285
  if (!hit || !taskId)
68188
68286
  return none;
68189
- const t = await client2.taskState(taskId).catch(() => null);
68287
+ const t = await client3.taskState(taskId).catch(() => null);
68190
68288
  if (!t || !/^patrol$/i.test(String(t.category ?? "")))
68191
68289
  return none;
68192
68290
  const level2 = hit.building?.levels.find((l) => l.name === hit.s.location?.map);
@@ -69281,10 +69379,10 @@ function fetchPadbotMqttCredentials(credentials) {
69281
69379
  return createPadbotClient(credentials).call(PADBOT_PATHS.mqttCredentials, {});
69282
69380
  }
69283
69381
  async function listPadbotAlarmsSince(credentials, serials, startTime) {
69284
- const client2 = createPadbotClient(credentials);
69382
+ const client3 = createPadbotClient(credentials);
69285
69383
  const out = [];
69286
69384
  for (let p = 1; p <= 3; p++) {
69287
- const d = await client2.call(PADBOT_PATHS.alarms, { serialNumbers: serials.slice(0, 100), startTime, pageNumber: p, pageSize: 100 });
69385
+ const d = await client3.call(PADBOT_PATHS.alarms, { serialNumbers: serials.slice(0, 100), startTime, pageNumber: p, pageSize: 100 });
69288
69386
  out.push(...asList(d));
69289
69387
  if (p >= (Number(d?.totalPages) || 0))
69290
69388
  break;
@@ -74491,16 +74589,16 @@ function useRobotMapController(deps) {
74491
74589
  const config2 = openRmfConfig();
74492
74590
  if (!config2)
74493
74591
  throw new NotFoundError46("Fleet Core is not configured on this server.");
74494
- const client2 = createOpenRmfClient(config2);
74592
+ const client3 = createOpenRmfClient(config2);
74495
74593
  if (value.format === "rmf") {
74496
- const rmf = rmfFromFleetCore(await client2.buildingMap());
74594
+ const rmf = rmfFromFleetCore(await client3.buildingMap());
74497
74595
  res.json({ source: "fleet-core", rmf, summary: rmfSummary(rmf) });
74498
74596
  return;
74499
74597
  }
74500
- const building = buildingInPlanFrame(await client2.buildingMap());
74598
+ const building = buildingInPlanFrame(await client3.buildingMap());
74501
74599
  const [doorStates, liftStates] = await Promise.all([
74502
- Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client2, d.name).read().catch(() => null))),
74503
- Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(client2, l.name).read().catch(() => null)))
74600
+ Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client3, d.name).read().catch(() => null))),
74601
+ Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(client3, l.name).read().catch(() => null)))
74504
74602
  ]);
74505
74603
  res.json({
74506
74604
  source: "fleet-core",
@@ -100983,11 +101081,11 @@ function useAuthServiceV2() {
100983
101081
  "Refresh token already used. Please log in again."
100984
101082
  );
100985
101083
  }
100986
- const client2 = useAtlas146.getClient();
100987
- if (!client2) {
101084
+ const client3 = useAtlas146.getClient();
101085
+ if (!client3) {
100988
101086
  throw new InternalServerError86("Unable to connect to server.");
100989
101087
  }
100990
- const dbSession = client2.startSession();
101088
+ const dbSession = client3.startSession();
100991
101089
  let newRefreshToken;
100992
101090
  try {
100993
101091
  dbSession.startTransaction();
@@ -102726,7 +102824,7 @@ function useUserServiceV2() {
102726
102824
  session?.endSession();
102727
102825
  }
102728
102826
  }
102729
- const s32 = new useS33({
102827
+ const s33 = new useS33({
102730
102828
  accessKeyId: SPACES_ACCESS_KEY,
102731
102829
  secretAccessKey: SPACES_SECRET_KEY,
102732
102830
  endpoint: SPACES_ENDPOINT,
@@ -102747,14 +102845,14 @@ function useUserServiceV2() {
102747
102845
  };
102748
102846
  try {
102749
102847
  const id = await createFile(_file, session);
102750
- await s32.uploadObject({
102848
+ await putSpacesObject({
102751
102849
  key: id,
102752
102850
  body: file.buffer,
102753
102851
  contentType: file.mimetype
102754
102852
  });
102755
102853
  if (previousProfile) {
102756
102854
  await deleteFileById(previousProfile, session);
102757
- await s32.deleteObject(previousProfile);
102855
+ await s33.deleteObject(previousProfile);
102758
102856
  }
102759
102857
  await _updateUserFieldById(
102760
102858
  { _id: user, field: "profile", value: id },
@@ -105687,10 +105785,10 @@ function useChatPrelovedService() {
105687
105785
  const { add: _addChat } = useChatPrelovedRepo();
105688
105786
  const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
105689
105787
  async function add(value) {
105690
- const client2 = useAtlas158.getClient();
105691
- if (!client2)
105788
+ const client3 = useAtlas158.getClient();
105789
+ if (!client3)
105692
105790
  throw new InternalServerError96("Unable to connect to server.");
105693
- const session = client2.startSession();
105791
+ const session = client3.startSession();
105694
105792
  session.startTransaction();
105695
105793
  try {
105696
105794
  let channelId = value.channelId;
@@ -106151,14 +106249,14 @@ function useBidPrelovedService() {
106151
106249
  const { add: _addChat } = useChatPrelovedRepo();
106152
106250
  const { updateStatus } = usePostPrelovedRepo();
106153
106251
  async function createBid(value) {
106154
- const client2 = useAtlas161.getClient();
106155
- if (!client2)
106252
+ const client3 = useAtlas161.getClient();
106253
+ if (!client3)
106156
106254
  throw new InternalServerError99("Unable to connect to server.");
106157
106255
  const buyerId = value.buyerId;
106158
106256
  const receiverId = value.receiverId;
106159
106257
  const postId = value.postId;
106160
106258
  const messageText = value.message || "";
106161
- const session = client2.startSession();
106259
+ const session = client3.startSession();
106162
106260
  session.startTransaction();
106163
106261
  try {
106164
106262
  const bidId = await _addBid(value, session);
@@ -108451,8 +108549,8 @@ async function staffOnly(req) {
108451
108549
  }
108452
108550
  async function clientAndSites(org) {
108453
108551
  const d = db2();
108454
- const client2 = await d.collection("organizations").findOne({ _id: new ObjectId201(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
108455
- if (!client2)
108552
+ const client3 = await d.collection("organizations").findOne({ _id: new ObjectId201(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
108553
+ if (!client3)
108456
108554
  throw new NotFoundError100("Client not found.");
108457
108555
  const own = await d.collection("sites").find({ orgId: both3(org), status: { $ne: "deleted" } }, { projection: { name: 1 } }).toArray();
108458
108556
  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();
@@ -108465,7 +108563,7 @@ async function clientAndSites(org) {
108465
108563
  sites.set(id, String(s.name ?? ""));
108466
108564
  }
108467
108565
  return {
108468
- client: { _id: org, name: String(client2.name ?? ""), nature: String(client2.nature ?? "") },
108566
+ client: { _id: org, name: String(client3.name ?? ""), nature: String(client3.nature ?? "") },
108469
108567
  sites: [...sites].map(([_id, name2]) => ({ _id, name: name2 })).sort((a, b) => a.name.localeCompare(b.name))
108470
108568
  };
108471
108569
  }
@@ -108533,14 +108631,14 @@ function useStaffAccessController() {
108533
108631
  const sid = getSessionIdFromRequest(req);
108534
108632
  if (!sid)
108535
108633
  throw new UnauthorizedError28("Not authorized.");
108536
- const { client: client2, sites: list } = await clientAndSites(value.org);
108634
+ const { client: client3, sites: list } = await clientAndSites(value.org);
108537
108635
  const site = value.site ? list.find((s) => s._id === value.site) : null;
108538
108636
  if (value.site && !site)
108539
108637
  throw new BadRequestError273("That site does not belong to this client.");
108540
108638
  const view = {
108541
108639
  user: actor,
108542
- org: client2._id,
108543
- orgName: client2.name,
108640
+ org: client3._id,
108641
+ orgName: client3.name,
108544
108642
  site: site?._id ?? "",
108545
108643
  siteName: site?.name ?? "",
108546
108644
  app: value.app,
@@ -108550,8 +108648,8 @@ function useStaffAccessController() {
108550
108648
  await recordConsoleAction({
108551
108649
  action: "staff-view.entered" /* STAFF_VIEW_ENTERED */,
108552
108650
  actor,
108553
- org: client2._id,
108554
- target: view.site || client2._id,
108651
+ org: client3._id,
108652
+ target: view.site || client3._id,
108555
108653
  targetType: view.site ? "site" /* SITE */ : "organization" /* ORGANIZATION */,
108556
108654
  after: pickAuditFields("staff-view.entered" /* STAFF_VIEW_ENTERED */, { ...view, reason: value.reason }) ?? null
108557
108655
  });