@7365admin1/core 3.142.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
@@ -4818,6 +4818,100 @@ import { ObjectId as ObjectId17 } from "mongodb";
4818
4818
  // src/utils/super-admin.util.ts
4819
4819
  import { useAtlas as useAtlas10 } from "@7365admin1/node-server-utils";
4820
4820
  import { ObjectId as ObjectId16 } from "mongodb";
4821
+
4822
+ // src/utils/console-permission.util.ts
4823
+ var CONSOLE_PERMISSIONS = Object.freeze({
4824
+ organizations: Object.freeze([
4825
+ "see-all-organizations",
4826
+ "see-organization-details"
4827
+ ]),
4828
+ "promo-codes": Object.freeze([
4829
+ "create-promo-code",
4830
+ "see-promo-code-details",
4831
+ "edit-promo-code-details",
4832
+ "change-promo-code-status",
4833
+ "delete-promo-code"
4834
+ ]),
4835
+ users: Object.freeze(["see-all-users", "see-user-details"]),
4836
+ invitations: Object.freeze([
4837
+ "create-invitation",
4838
+ "view-invitations",
4839
+ "cancel-invitation"
4840
+ ]),
4841
+ subscriptions: Object.freeze([
4842
+ "see-all-subscriptions",
4843
+ "see-subscription-details",
4844
+ "manage-subscription"
4845
+ ]),
4846
+ "sp-approvals": Object.freeze([
4847
+ "see-all-sp-approvals",
4848
+ "approve-sp",
4849
+ "reject-sp",
4850
+ "delete-sp-approval"
4851
+ ]),
4852
+ "marketplace-vendors": Object.freeze([
4853
+ "see-all-marketplace-vendors",
4854
+ "see-marketplace-vendor-details"
4855
+ ]),
4856
+ "platform-terms": Object.freeze([
4857
+ "see-platform-terms",
4858
+ "edit-platform-terms"
4859
+ ]),
4860
+ "activity-history": Object.freeze(["see-activity-history"]),
4861
+ members: Object.freeze([
4862
+ "view-members",
4863
+ "assign-member-role",
4864
+ "suspend-member",
4865
+ "activate-member",
4866
+ "delete-member"
4867
+ ]),
4868
+ "roles-and-permissions": Object.freeze([
4869
+ "add-role",
4870
+ "see-all-roles",
4871
+ "see-role-details",
4872
+ "update-role",
4873
+ "delete-role"
4874
+ ])
4875
+ });
4876
+ var RESOURCE_SPELLINGS = Object.freeze({
4877
+ "roles-and-permissions": Object.freeze([
4878
+ "roles-and-permissions",
4879
+ "roles"
4880
+ ]),
4881
+ roles: Object.freeze(["roles", "roles-and-permissions"])
4882
+ });
4883
+ function consoleSpellings(resource, action) {
4884
+ const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
4885
+ return resources.map((name2) => `${name2}:${action}`);
4886
+ }
4887
+ function consoleRoleAllowsAll(held) {
4888
+ if (!Array.isArray(held) || held.length === 0)
4889
+ return true;
4890
+ return held.includes("*");
4891
+ }
4892
+ function consoleRoleAllows(held, resource, action) {
4893
+ if (consoleRoleAllowsAll(held))
4894
+ return true;
4895
+ const actions = CONSOLE_PERMISSIONS[resource];
4896
+ if (!actions?.length)
4897
+ return false;
4898
+ const wanted = action ? actions.includes(action) ? [action] : [] : actions;
4899
+ return wanted.some(
4900
+ (name2) => consoleSpellings(resource, name2).some(
4901
+ (spelling) => held.includes(spelling)
4902
+ )
4903
+ );
4904
+ }
4905
+ var CROSS_CLIENT_GRANT = {
4906
+ resource: "organizations"
4907
+ };
4908
+ function staffMayBypass(actor, grant = CROSS_CLIENT_GRANT) {
4909
+ if (!actor.isSuperAdmin)
4910
+ return false;
4911
+ return consoleRoleAllows(actor.staffPermissions, grant.resource, grant.action);
4912
+ }
4913
+
4914
+ // src/utils/super-admin.util.ts
4821
4915
  var LIVE_ROLE = { status: { $ne: "deleted" } };
4822
4916
  async function resolveStaffRole(userId) {
4823
4917
  const id = userId?.toString() ?? "";
@@ -4857,6 +4951,13 @@ async function isSuperAdmin(userId) {
4857
4951
  async function isPlatformOwner(userId) {
4858
4952
  return (await resolveStaffRole(userId))?.default === true;
4859
4953
  }
4954
+ async function staffReachesEveryClient(userId) {
4955
+ const role = await resolveStaffRole(userId);
4956
+ if (!role)
4957
+ return false;
4958
+ return consoleRoleAllows(role.permissions, "organizations");
4959
+ }
4960
+ var STAFF_CLIENT_PERMISSIONS = Object.freeze(["*"]);
4860
4961
 
4861
4962
  // src/utils/org-suspension.util.ts
4862
4963
  var ORG_SUSPENDED_MESSAGE = "Your organisation's access is currently suspended. Please contact your administrator.";
@@ -5031,11 +5132,11 @@ function useAuthService() {
5031
5132
  "Refresh token already used. Please log in again."
5032
5133
  );
5033
5134
  }
5034
- const client2 = useAtlas12.getClient();
5035
- if (!client2) {
5135
+ const client3 = useAtlas12.getClient();
5136
+ if (!client3) {
5036
5137
  throw new InternalServerError7("Unable to connect to server.");
5037
5138
  }
5038
- const dbSession = client2.startSession();
5139
+ const dbSession = client3.startSession();
5039
5140
  let newRefreshToken;
5040
5141
  try {
5041
5142
  dbSession.startTransaction();
@@ -8151,7 +8252,7 @@ var SP_INVITE_TYPES = [
8151
8252
  function escapeRegex(value) {
8152
8253
  return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8153
8254
  }
8154
- function relationshipMatch(org, relationship, client2) {
8255
+ function relationshipMatch(org, relationship, client3) {
8155
8256
  const self = [org, String(org)];
8156
8257
  const match = {};
8157
8258
  const and = [];
@@ -8160,9 +8261,9 @@ function relationshipMatch(org, relationship, client2) {
8160
8261
  } else if (relationship === "served") {
8161
8262
  and.push({ siteOrg: { $nin: [...self, null, ""] } });
8162
8263
  }
8163
- if (client2) {
8264
+ if (client3) {
8164
8265
  and.push(
8165
- { siteOrg: { $in: [client2, String(client2)] } },
8266
+ { siteOrg: { $in: [client3, String(client3)] } },
8166
8267
  { siteOrg: { $nin: self } }
8167
8268
  );
8168
8269
  }
@@ -8325,7 +8426,7 @@ function useCustomerSiteRepo() {
8325
8426
  status = "active",
8326
8427
  siteScope = null,
8327
8428
  relationship = "",
8328
- client: client2 = "",
8429
+ client: client3 = "",
8329
8430
  category = ""
8330
8431
  }, session) {
8331
8432
  page2 = page2 > 0 ? page2 - 1 : 0;
@@ -8339,9 +8440,9 @@ function useCustomerSiteRepo() {
8339
8440
  status
8340
8441
  };
8341
8442
  let clientId = null;
8342
- if (client2) {
8443
+ if (client3) {
8343
8444
  try {
8344
- clientId = new ObjectId26(client2);
8445
+ clientId = new ObjectId26(client3);
8345
8446
  } catch (error) {
8346
8447
  throw new BadRequestError24("Invalid client ID format.");
8347
8448
  }
@@ -8364,8 +8465,8 @@ function useCustomerSiteRepo() {
8364
8465
  }
8365
8466
  if (relationship)
8366
8467
  cacheOptions.relationship = relationship;
8367
- if (client2)
8368
- cacheOptions.client = client2;
8468
+ if (client3)
8469
+ cacheOptions.client = client3;
8369
8470
  if (category)
8370
8471
  cacheOptions.category = category;
8371
8472
  const cacheKey = makeCacheKey10(namespace_collection3, cacheOptions);
@@ -11218,98 +11319,6 @@ async function recordConsoleAction(entry) {
11218
11319
  }
11219
11320
  }
11220
11321
 
11221
- // src/utils/console-permission.util.ts
11222
- var CONSOLE_PERMISSIONS = Object.freeze({
11223
- organizations: Object.freeze([
11224
- "see-all-organizations",
11225
- "see-organization-details"
11226
- ]),
11227
- "promo-codes": Object.freeze([
11228
- "create-promo-code",
11229
- "see-promo-code-details",
11230
- "edit-promo-code-details",
11231
- "change-promo-code-status",
11232
- "delete-promo-code"
11233
- ]),
11234
- users: Object.freeze(["see-all-users", "see-user-details"]),
11235
- invitations: Object.freeze([
11236
- "create-invitation",
11237
- "view-invitations",
11238
- "cancel-invitation"
11239
- ]),
11240
- subscriptions: Object.freeze([
11241
- "see-all-subscriptions",
11242
- "see-subscription-details",
11243
- "manage-subscription"
11244
- ]),
11245
- "sp-approvals": Object.freeze([
11246
- "see-all-sp-approvals",
11247
- "approve-sp",
11248
- "reject-sp",
11249
- "delete-sp-approval"
11250
- ]),
11251
- "marketplace-vendors": Object.freeze([
11252
- "see-all-marketplace-vendors",
11253
- "see-marketplace-vendor-details"
11254
- ]),
11255
- "platform-terms": Object.freeze([
11256
- "see-platform-terms",
11257
- "edit-platform-terms"
11258
- ]),
11259
- "activity-history": Object.freeze(["see-activity-history"]),
11260
- members: Object.freeze([
11261
- "view-members",
11262
- "assign-member-role",
11263
- "suspend-member",
11264
- "activate-member",
11265
- "delete-member"
11266
- ]),
11267
- "roles-and-permissions": Object.freeze([
11268
- "add-role",
11269
- "see-all-roles",
11270
- "see-role-details",
11271
- "update-role",
11272
- "delete-role"
11273
- ])
11274
- });
11275
- var RESOURCE_SPELLINGS = Object.freeze({
11276
- "roles-and-permissions": Object.freeze([
11277
- "roles-and-permissions",
11278
- "roles"
11279
- ]),
11280
- roles: Object.freeze(["roles", "roles-and-permissions"])
11281
- });
11282
- function consoleSpellings(resource, action) {
11283
- const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
11284
- return resources.map((name2) => `${name2}:${action}`);
11285
- }
11286
- function consoleRoleAllowsAll(held) {
11287
- if (!Array.isArray(held) || held.length === 0)
11288
- return true;
11289
- return held.includes("*");
11290
- }
11291
- function consoleRoleAllows(held, resource, action) {
11292
- if (consoleRoleAllowsAll(held))
11293
- return true;
11294
- const actions = CONSOLE_PERMISSIONS[resource];
11295
- if (!actions?.length)
11296
- return false;
11297
- const wanted = action ? actions.includes(action) ? [action] : [] : actions;
11298
- return wanted.some(
11299
- (name2) => consoleSpellings(resource, name2).some(
11300
- (spelling) => held.includes(spelling)
11301
- )
11302
- );
11303
- }
11304
- var CROSS_CLIENT_GRANT = {
11305
- resource: "organizations"
11306
- };
11307
- function staffMayBypass(actor, grant = CROSS_CLIENT_GRANT) {
11308
- if (!actor.isSuperAdmin)
11309
- return false;
11310
- return consoleRoleAllows(actor.staffPermissions, grant.resource, grant.action);
11311
- }
11312
-
11313
11322
  // src/services/module-gate.service.ts
11314
11323
  var idOf4 = (v) => v == null ? "" : String(v?._id ?? v).toLowerCase();
11315
11324
  var isId = (v) => /^[0-9a-f]{24}$/i.test(v);
@@ -18090,6 +18099,76 @@ function useVehicleRepo() {
18090
18099
  };
18091
18100
  }
18092
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
+
18093
18172
  // src/repositories/file.repo.ts
18094
18173
  import {
18095
18174
  BadRequestError as BadRequestError41,
@@ -18277,7 +18356,7 @@ function useFileService() {
18277
18356
  deleteFileById,
18278
18357
  getAllDraftedFiles
18279
18358
  } = useFileRepo();
18280
- const s32 = new useS3({
18359
+ const s33 = new useS3({
18281
18360
  accessKeyId: SPACES_ACCESS_KEY,
18282
18361
  secretAccessKey: SPACES_SECRET_KEY,
18283
18362
  endpoint: SPACES_ENDPOINT,
@@ -18296,7 +18375,7 @@ function useFileService() {
18296
18375
  };
18297
18376
  try {
18298
18377
  const id = await _createFile(file, session);
18299
- await s32.uploadObject({
18378
+ await putSpacesObject({
18300
18379
  key: `${folder}/${id}`,
18301
18380
  body: value.buffer,
18302
18381
  contentType: value.mimetype
@@ -18315,7 +18394,7 @@ function useFileService() {
18315
18394
  session?.startTransaction();
18316
18395
  try {
18317
18396
  await deleteFileById(id, session);
18318
- await s32.deleteObject(id);
18397
+ await s33.deleteObject(id);
18319
18398
  await session?.commitTransaction();
18320
18399
  return "File deleted successfully.";
18321
18400
  } catch (error) {
@@ -22270,6 +22349,9 @@ async function getUserPermissions(params) {
22270
22349
  if (!db3) {
22271
22350
  return [];
22272
22351
  }
22352
+ if (await staffReachesEveryClient(user)) {
22353
+ return [...STAFF_CLIENT_PERMISSIONS];
22354
+ }
22273
22355
  let roleId = grantingRole;
22274
22356
  let memberSite = params.memberSite;
22275
22357
  let memberId;
@@ -22410,6 +22492,12 @@ function useCameraViewService() {
22410
22492
  engagedOrgs,
22411
22493
  prefer: params.prefer
22412
22494
  });
22495
+ if (!grant && await staffReachesEveryClient(params.userId)) {
22496
+ return {
22497
+ memberships,
22498
+ grant: { org: params.site?.orgId ?? params.site?.org, siteId: params.siteObjectId }
22499
+ };
22500
+ }
22413
22501
  return { memberships, grant };
22414
22502
  }
22415
22503
  async function permissionsForGrant(userId, grant, memberships) {
@@ -25259,7 +25347,7 @@ function useServiceProviderInviteService() {
25259
25347
  const runs = ObjectId57.isValid(id) && actor.memberships.some(
25260
25348
  (m) => m.org === id && (m.companyWideRole === true || !m.siteId && m.orgLevelRole === true)
25261
25349
  );
25262
- if (!runs) {
25350
+ if (!runs && !staffMayBypass(actor)) {
25263
25351
  throw new UnauthorizedError4(
25264
25352
  "Only an administrator of that company can answer this invitation for it."
25265
25353
  );
@@ -26273,7 +26361,7 @@ function useUserService() {
26273
26361
  session?.endSession();
26274
26362
  }
26275
26363
  }
26276
- const s32 = new useS32({
26364
+ const s33 = new useS32({
26277
26365
  accessKeyId: SPACES_ACCESS_KEY,
26278
26366
  secretAccessKey: SPACES_SECRET_KEY,
26279
26367
  endpoint: SPACES_ENDPOINT,
@@ -26294,14 +26382,14 @@ function useUserService() {
26294
26382
  };
26295
26383
  try {
26296
26384
  const id = await createFile(_file, session);
26297
- await s32.uploadObject({
26385
+ await putSpacesObject({
26298
26386
  key: id,
26299
26387
  body: file.buffer,
26300
26388
  contentType: file.mimetype
26301
26389
  });
26302
26390
  if (previousProfile) {
26303
26391
  await deleteFileById(previousProfile, session);
26304
- await s32.deleteObject(previousProfile);
26392
+ await s33.deleteObject(previousProfile);
26305
26393
  }
26306
26394
  await _updateUserFieldById(
26307
26395
  { _id: user, field: "profile", value: id },
@@ -30432,10 +30520,38 @@ function useFileController() {
30432
30520
  next(error2);
30433
30521
  }
30434
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
+ }
30435
30550
  return {
30436
30551
  upload,
30437
30552
  deleteFile,
30438
- getFileById
30553
+ getFileById,
30554
+ viewObject
30439
30555
  };
30440
30556
  }
30441
30557
 
@@ -36687,8 +36803,8 @@ function useServiceProviderController() {
36687
36803
  if (siteId)
36688
36804
  await requireSiteReach(req, siteId);
36689
36805
  const engagements = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId;
36690
- const client2 = engagements ? await isSiteClient(req, siteId) : false;
36691
- 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 ? (
36692
36808
  // A provider's own Service Providers page: the subcontractors it
36693
36809
  // brought onto this site, never the client's other contractors,
36694
36810
  // plus the stored rows it already saw here.
@@ -46433,7 +46549,7 @@ function useCustomerSiteController() {
46433
46549
  const org = req.query.org ?? "";
46434
46550
  const status = req.query.status ?? "active";
46435
46551
  const relationship = req.query.relationship || "";
46436
- const client2 = req.query.client || "";
46552
+ const client3 = req.query.client || "";
46437
46553
  const category = req.query.category || "";
46438
46554
  const sortObj = {};
46439
46555
  const sortFields = String(req.query.sort).split(",");
@@ -46456,7 +46572,7 @@ function useCustomerSiteController() {
46456
46572
  status,
46457
46573
  siteScope,
46458
46574
  relationship,
46459
- client: client2,
46575
+ client: client3,
46460
46576
  category
46461
46577
  });
46462
46578
  res.json(data);
@@ -47772,15 +47888,15 @@ function useAttendanceService() {
47772
47888
 
47773
47889
  // src/services/attendance-photo.service.ts
47774
47890
  import {
47775
- GetObjectCommand,
47776
- PutObjectCommand,
47777
- S3Client
47891
+ GetObjectCommand as GetObjectCommand2,
47892
+ PutObjectCommand as PutObjectCommand2,
47893
+ S3Client as S3Client2
47778
47894
  } from "@aws-sdk/client-s3";
47779
47895
  var ATTENDANCE_PHOTO_FOLDER = "attendance-private";
47780
- var client = null;
47781
- function s3() {
47782
- if (!client) {
47783
- client = new S3Client({
47896
+ var client2 = null;
47897
+ function s32() {
47898
+ if (!client2) {
47899
+ client2 = new S3Client2({
47784
47900
  endpoint: SPACES_ENDPOINT,
47785
47901
  region: SPACES_REGION,
47786
47902
  credentials: {
@@ -47790,12 +47906,12 @@ function s3() {
47790
47906
  forcePathStyle: true
47791
47907
  });
47792
47908
  }
47793
- return client;
47909
+ return client2;
47794
47910
  }
47795
47911
  var s3AttendancePhotoStore = {
47796
47912
  async put(key2, body, contentType) {
47797
- await s3().send(
47798
- new PutObjectCommand({
47913
+ await s32().send(
47914
+ new PutObjectCommand2({
47799
47915
  Bucket: SPACES_BUCKET,
47800
47916
  Key: key2,
47801
47917
  Body: body,
@@ -47806,8 +47922,8 @@ var s3AttendancePhotoStore = {
47806
47922
  );
47807
47923
  },
47808
47924
  async get(key2) {
47809
- const res = await s3().send(
47810
- new GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 })
47925
+ const res = await s32().send(
47926
+ new GetObjectCommand2({ Bucket: SPACES_BUCKET, Key: key2 })
47811
47927
  );
47812
47928
  const bytes = await res.Body.transformToByteArray();
47813
47929
  return { body: Buffer.from(bytes), contentType: res.ContentType };
@@ -52403,20 +52519,20 @@ function createVisitorQrCredential(visitorId, readerId, qrValue) {
52403
52519
  const token = qrValue || `VIS${crypto6.randomBytes(12).toString("hex").toUpperCase()}`;
52404
52520
  return { credentialId, object: "qrcodes", value: token, qrValue: token };
52405
52521
  }
52406
- async function configureVisitorQrReader(client2) {
52522
+ async function configureVisitorQrReader(client3) {
52407
52523
  const requestedConfiguration = {
52408
52524
  general: ["online", "local_identification"],
52409
52525
  face_id: ["qrcode_legacy_mode_enabled"],
52410
52526
  identifier: ["qrcode_identification_enabled", "multi_factor_authentication"]
52411
52527
  };
52412
- const currentConfiguration = await client2.getConfiguration(requestedConfiguration);
52528
+ const currentConfiguration = await client3.getConfiguration(requestedConfiguration);
52413
52529
  const current = isUnknownRecord2(currentConfiguration) ? currentConfiguration : {};
52414
52530
  const currentGeneral = isUnknownRecord2(current.general) ? current.general : {};
52415
52531
  const currentFaceId = isUnknownRecord2(current.face_id) ? current.face_id : {};
52416
52532
  const currentIdentifier = isUnknownRecord2(current.identifier) ? current.identifier : {};
52417
52533
  let changed = false;
52418
52534
  if (String(currentGeneral.online ?? "") !== "0" || String(currentGeneral.local_identification ?? "") !== "1") {
52419
- await client2.setConfiguration({
52535
+ await client3.setConfiguration({
52420
52536
  general: {
52421
52537
  online: "0",
52422
52538
  local_identification: "1"
@@ -52425,13 +52541,13 @@ async function configureVisitorQrReader(client2) {
52425
52541
  changed = true;
52426
52542
  }
52427
52543
  if (String(currentFaceId.qrcode_legacy_mode_enabled ?? "") !== VISITOR_QR_FORMAT) {
52428
- await client2.setConfiguration({
52544
+ await client3.setConfiguration({
52429
52545
  face_id: { qrcode_legacy_mode_enabled: VISITOR_QR_FORMAT }
52430
52546
  });
52431
52547
  changed = true;
52432
52548
  }
52433
52549
  if (String(currentIdentifier.qrcode_identification_enabled ?? "") !== "1" || String(currentIdentifier.multi_factor_authentication ?? "") !== "0") {
52434
- await client2.setConfiguration({
52550
+ await client3.setConfiguration({
52435
52551
  identifier: {
52436
52552
  qrcode_identification_enabled: "1",
52437
52553
  // A visitor pass is a single QR credential. Leaving MFA enabled makes
@@ -52441,7 +52557,7 @@ async function configureVisitorQrReader(client2) {
52441
52557
  });
52442
52558
  changed = true;
52443
52559
  }
52444
- const configuration = await client2.getConfiguration(requestedConfiguration);
52560
+ const configuration = await client3.getConfiguration(requestedConfiguration);
52445
52561
  const savedConfiguration = isUnknownRecord2(configuration) ? configuration : {};
52446
52562
  const general = isUnknownRecord2(savedConfiguration.general) ? savedConfiguration.general : {};
52447
52563
  const faceId = isUnknownRecord2(savedConfiguration.face_id) ? savedConfiguration.face_id : {};
@@ -52453,7 +52569,7 @@ async function configureVisitorQrReader(client2) {
52453
52569
  }
52454
52570
  return changed;
52455
52571
  }
52456
- async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUserId, scope = "visitor") {
52572
+ async function ensureVisitorAccessAuthorization(client3, readerId, reader, hidUserId, scope = "visitor") {
52457
52573
  const accessLabel = scope === "visitor" ? "Visitor" : "Facial";
52458
52574
  const accessRuleId = createStableHidId(`${scope}-access-rule:${readerId}`);
52459
52575
  const timeZoneId = createStableHidId(`${scope}-time-zone:${readerId}`);
@@ -52463,25 +52579,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52463
52579
  type: 1,
52464
52580
  priority: 0
52465
52581
  };
52466
- const existingRuleResponse = await client2.loadObjects({
52582
+ const existingRuleResponse = await client3.loadObjects({
52467
52583
  object: "access_rules",
52468
52584
  where: { access_rules: { id: accessRuleId } },
52469
52585
  limit: 1,
52470
52586
  offset: 0
52471
52587
  });
52472
52588
  if (getHidObjectRows(existingRuleResponse, "access_rules").length) {
52473
- await client2.modifyObjects({
52589
+ await client3.modifyObjects({
52474
52590
  object: "access_rules",
52475
52591
  where: { access_rules: { id: accessRuleId } },
52476
52592
  values: accessRuleValues
52477
52593
  });
52478
52594
  } else {
52479
- await client2.createObjects({
52595
+ await client3.createObjects({
52480
52596
  object: "access_rules",
52481
52597
  values: [{ id: accessRuleId, ...accessRuleValues }]
52482
52598
  });
52483
52599
  }
52484
- const verifiedAccessRuleResponse = await client2.loadObjects({
52600
+ const verifiedAccessRuleResponse = await client3.loadObjects({
52485
52601
  object: "access_rules",
52486
52602
  where: { access_rules: { id: accessRuleId } },
52487
52603
  limit: 1,
@@ -52495,20 +52611,20 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52495
52611
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
52496
52612
  );
52497
52613
  }
52498
- const existingTimeZoneResponse = await client2.loadObjects({
52614
+ const existingTimeZoneResponse = await client3.loadObjects({
52499
52615
  object: "time_zones",
52500
52616
  where: { time_zones: { id: timeZoneId } },
52501
52617
  limit: 1,
52502
52618
  offset: 0
52503
52619
  });
52504
52620
  if (getHidObjectRows(existingTimeZoneResponse, "time_zones").length) {
52505
- await client2.modifyObjects({
52621
+ await client3.modifyObjects({
52506
52622
  object: "time_zones",
52507
52623
  where: { time_zones: { id: timeZoneId } },
52508
52624
  values: { name: `iService365 ${accessLabel} Schedule` }
52509
52625
  });
52510
52626
  } else {
52511
- await client2.createObjects({
52627
+ await client3.createObjects({
52512
52628
  object: "time_zones",
52513
52629
  values: [{ id: timeZoneId, name: `iService365 ${accessLabel} Schedule` }]
52514
52630
  });
@@ -52528,25 +52644,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52528
52644
  hol2: 1,
52529
52645
  hol3: 1
52530
52646
  };
52531
- const existingTimeSpanResponse = await client2.loadObjects({
52647
+ const existingTimeSpanResponse = await client3.loadObjects({
52532
52648
  object: "time_spans",
52533
52649
  where: { time_spans: { id: timeSpanId } },
52534
52650
  limit: 1,
52535
52651
  offset: 0
52536
52652
  });
52537
52653
  if (getHidObjectRows(existingTimeSpanResponse, "time_spans").length) {
52538
- await client2.modifyObjects({
52654
+ await client3.modifyObjects({
52539
52655
  object: "time_spans",
52540
52656
  where: { time_spans: { id: timeSpanId } },
52541
52657
  values: visitorTimeSpan
52542
52658
  });
52543
52659
  } else {
52544
- await client2.createObjects({
52660
+ await client3.createObjects({
52545
52661
  object: "time_spans",
52546
52662
  values: [{ id: timeSpanId, ...visitorTimeSpan }]
52547
52663
  });
52548
52664
  }
52549
- const verifiedTimeZoneResponse = await client2.loadObjects({
52665
+ const verifiedTimeZoneResponse = await client3.loadObjects({
52550
52666
  object: "time_zones",
52551
52667
  where: { time_zones: { id: timeZoneId } },
52552
52668
  limit: 1,
@@ -52560,7 +52676,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52560
52676
  "The HID reader did not save the visitor access schedule."
52561
52677
  );
52562
52678
  }
52563
- const verifiedTimeSpanResponse = await client2.loadObjects({
52679
+ const verifiedTimeSpanResponse = await client3.loadObjects({
52564
52680
  object: "time_spans",
52565
52681
  where: { time_spans: { id: timeSpanId } },
52566
52682
  limit: 1,
@@ -52578,7 +52694,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52578
52694
  access_rule_id: accessRuleId,
52579
52695
  time_zone_id: timeZoneId
52580
52696
  };
52581
- const accessRuleTimeZoneResponse = await client2.loadObjects({
52697
+ const accessRuleTimeZoneResponse = await client3.loadObjects({
52582
52698
  object: "access_rule_time_zones",
52583
52699
  where: {
52584
52700
  access_rule_time_zones: {
@@ -52592,12 +52708,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52592
52708
  getHidObjectRows(accessRuleTimeZoneResponse, "access_rule_time_zones"),
52593
52709
  accessRuleTimeZoneValues
52594
52710
  )) {
52595
- await client2.createObjects({
52711
+ await client3.createObjects({
52596
52712
  object: "access_rule_time_zones",
52597
52713
  values: [accessRuleTimeZoneValues]
52598
52714
  });
52599
52715
  }
52600
- const verifiedAccessRuleTimeZoneResponse = await client2.loadObjects({
52716
+ const verifiedAccessRuleTimeZoneResponse = await client3.loadObjects({
52601
52717
  object: "access_rule_time_zones",
52602
52718
  where: { access_rule_time_zones: { access_rule_id: accessRuleId } },
52603
52719
  limit: 100,
@@ -52611,7 +52727,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52611
52727
  "The HID reader did not save the visitor access schedule. Try issuing the QR code again."
52612
52728
  );
52613
52729
  }
52614
- const portalsResponse = await client2.loadObjects({
52730
+ const portalsResponse = await client3.loadObjects({
52615
52731
  object: "portals",
52616
52732
  limit: 100,
52617
52733
  offset: 0
@@ -52648,7 +52764,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52648
52764
  user_id: hidUserId,
52649
52765
  access_rule_id: accessRuleId
52650
52766
  };
52651
- const userAccessRulesResponse = await client2.loadObjects({
52767
+ const userAccessRulesResponse = await client3.loadObjects({
52652
52768
  object: "user_access_rules",
52653
52769
  where: { user_access_rules: { user_id: hidUserId } },
52654
52770
  limit: 100,
@@ -52658,12 +52774,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52658
52774
  getHidObjectRows(userAccessRulesResponse, "user_access_rules"),
52659
52775
  userAccessRuleValues
52660
52776
  )) {
52661
- await client2.createObjects({
52777
+ await client3.createObjects({
52662
52778
  object: "user_access_rules",
52663
52779
  values: [userAccessRuleValues]
52664
52780
  });
52665
52781
  }
52666
- const verifiedUserAccessRulesResponse = await client2.loadObjects({
52782
+ const verifiedUserAccessRulesResponse = await client3.loadObjects({
52667
52783
  object: "user_access_rules",
52668
52784
  where: { user_access_rules: { user_id: hidUserId } },
52669
52785
  limit: 100,
@@ -52677,7 +52793,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52677
52793
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
52678
52794
  );
52679
52795
  }
52680
- const portalAccessRulesResponse = await client2.loadObjects({
52796
+ const portalAccessRulesResponse = await client3.loadObjects({
52681
52797
  object: "portal_access_rules",
52682
52798
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
52683
52799
  limit: 100,
@@ -52688,7 +52804,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52688
52804
  );
52689
52805
  const stalePortalIds = [...linkedPortalIds].filter((portalId) => !portalIds.includes(portalId));
52690
52806
  for (const portalId of stalePortalIds) {
52691
- await client2.destroyObjects({
52807
+ await client3.destroyObjects({
52692
52808
  object: "portal_access_rules",
52693
52809
  where: { portal_access_rules: { access_rule_id: accessRuleId, portal_id: portalId } }
52694
52810
  });
@@ -52696,12 +52812,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
52696
52812
  }
52697
52813
  const missingPortalLinks = portalIds.filter((portalId) => !linkedPortalIds.has(portalId)).map((portalId) => ({ portal_id: portalId, access_rule_id: accessRuleId }));
52698
52814
  if (missingPortalLinks.length) {
52699
- await client2.createObjects({
52815
+ await client3.createObjects({
52700
52816
  object: "portal_access_rules",
52701
52817
  values: missingPortalLinks
52702
52818
  });
52703
52819
  }
52704
- const verifiedPortalAccessRulesResponse = await client2.loadObjects({
52820
+ const verifiedPortalAccessRulesResponse = await client3.loadObjects({
52705
52821
  object: "portal_access_rules",
52706
52822
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
52707
52823
  limit: 100,
@@ -52725,19 +52841,19 @@ function getHidPortals(response) {
52725
52841
  areaToId: Number(portal.area_to_id)
52726
52842
  })).filter((portal) => Number.isSafeInteger(portal.id) && portal.id > 0 && portal.name);
52727
52843
  }
52728
- async function upsertHidObject(client2, object, id, values) {
52729
- const existing = await client2.loadObjects({
52844
+ async function upsertHidObject(client3, object, id, values) {
52845
+ const existing = await client3.loadObjects({
52730
52846
  object,
52731
52847
  where: { [object]: { id } },
52732
52848
  limit: 1,
52733
52849
  offset: 0
52734
52850
  });
52735
52851
  if (getHidObjectRows(existing, object).length) {
52736
- await client2.modifyObjects({ object, where: { [object]: { id } }, values });
52852
+ await client3.modifyObjects({ object, where: { [object]: { id } }, values });
52737
52853
  } else {
52738
- await client2.createObjects({ object, values: [{ id, ...values }] });
52854
+ await client3.createObjects({ object, values: [{ id, ...values }] });
52739
52855
  }
52740
- const verified = await client2.loadObjects({
52856
+ const verified = await client3.loadObjects({
52741
52857
  object,
52742
52858
  where: { [object]: { id } },
52743
52859
  limit: 1,
@@ -52747,17 +52863,17 @@ async function upsertHidObject(client2, object, id, values) {
52747
52863
  throw new BadRequestError126(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
52748
52864
  }
52749
52865
  }
52750
- async function ensureHidRelation(client2, object, values) {
52751
- const response = await client2.loadObjects({
52866
+ async function ensureHidRelation(client3, object, values) {
52867
+ const response = await client3.loadObjects({
52752
52868
  object,
52753
52869
  where: { [object]: values },
52754
52870
  limit: 100,
52755
52871
  offset: 0
52756
52872
  });
52757
52873
  if (!hasHidObjectValues(getHidObjectRows(response, object), values)) {
52758
- await client2.createObjects({ object, values: [values] });
52874
+ await client3.createObjects({ object, values: [values] });
52759
52875
  }
52760
- const verified = await client2.loadObjects({
52876
+ const verified = await client3.loadObjects({
52761
52877
  object,
52762
52878
  where: { [object]: values },
52763
52879
  limit: 100,
@@ -52767,8 +52883,8 @@ async function ensureHidRelation(client2, object, values) {
52767
52883
  throw new BadRequestError126(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
52768
52884
  }
52769
52885
  }
52770
- async function reconcileHidRelation(client2, object, scope, values) {
52771
- const response = await client2.loadObjects({
52886
+ async function reconcileHidRelation(client3, object, scope, values) {
52887
+ const response = await client3.loadObjects({
52772
52888
  object,
52773
52889
  where: { [object]: scope },
52774
52890
  limit: 1e3,
@@ -52780,11 +52896,11 @@ async function reconcileHidRelation(client2, object, scope, values) {
52780
52896
  const staleValues = Object.fromEntries(
52781
52897
  Object.keys(values).map((key2) => [key2, row[key2]])
52782
52898
  );
52783
- await client2.destroyObjects({ object, where: { [object]: staleValues } });
52899
+ await client3.destroyObjects({ object, where: { [object]: staleValues } });
52784
52900
  }
52785
52901
  }
52786
- await ensureHidRelation(client2, object, values);
52787
- const verified = await client2.loadObjects({
52902
+ await ensureHidRelation(client3, object, values);
52903
+ const verified = await client3.loadObjects({
52788
52904
  object,
52789
52905
  where: { [object]: scope },
52790
52906
  limit: 1e3,
@@ -52795,21 +52911,21 @@ async function reconcileHidRelation(client2, object, scope, values) {
52795
52911
  throw new BadRequestError126(`The HID reader did not reconcile ${object.replace(/_/g, " ")}.`);
52796
52912
  }
52797
52913
  }
52798
- async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userIds) {
52914
+ async function reconcileStandaloneGroupAccess(client3, readerId, portalId, userIds) {
52799
52915
  const groupId = createStableHidId(`permission-group:${readerId}`);
52800
52916
  const accessRuleId = createStableHidId(`permission-access-rule:${readerId}`);
52801
52917
  const timeZoneId = createStableHidId(`permission-time-zone:${readerId}`);
52802
52918
  const timeSpanId = createStableHidId(`permission-time-span:${readerId}`);
52803
- await upsertHidObject(client2, "groups", groupId, { name: "iService365 Assigned Access" });
52804
- await upsertHidObject(client2, "access_rules", accessRuleId, {
52919
+ await upsertHidObject(client3, "groups", groupId, { name: "iService365 Assigned Access" });
52920
+ await upsertHidObject(client3, "access_rules", accessRuleId, {
52805
52921
  name: "iService365 Assigned Access",
52806
52922
  type: 1,
52807
52923
  priority: 0
52808
52924
  });
52809
- await upsertHidObject(client2, "time_zones", timeZoneId, {
52925
+ await upsertHidObject(client3, "time_zones", timeZoneId, {
52810
52926
  name: "iService365 Assigned Schedule"
52811
52927
  });
52812
- await upsertHidObject(client2, "time_spans", timeSpanId, {
52928
+ await upsertHidObject(client3, "time_spans", timeSpanId, {
52813
52929
  time_zone_id: timeZoneId,
52814
52930
  start: 0,
52815
52931
  end: 86399,
@@ -52824,19 +52940,19 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52824
52940
  hol2: 1,
52825
52941
  hol3: 1
52826
52942
  });
52827
- await reconcileHidRelation(client2, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
52943
+ await reconcileHidRelation(client3, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
52828
52944
  access_rule_id: accessRuleId,
52829
52945
  time_zone_id: timeZoneId
52830
52946
  });
52831
- await reconcileHidRelation(client2, "group_access_rules", { access_rule_id: accessRuleId }, {
52947
+ await reconcileHidRelation(client3, "group_access_rules", { access_rule_id: accessRuleId }, {
52832
52948
  group_id: groupId,
52833
52949
  access_rule_id: accessRuleId
52834
52950
  });
52835
- await reconcileHidRelation(client2, "portal_access_rules", { access_rule_id: accessRuleId }, {
52951
+ await reconcileHidRelation(client3, "portal_access_rules", { access_rule_id: accessRuleId }, {
52836
52952
  portal_id: portalId,
52837
52953
  access_rule_id: accessRuleId
52838
52954
  });
52839
- const currentResponse = await client2.loadObjects({
52955
+ const currentResponse = await client3.loadObjects({
52840
52956
  object: "user_groups",
52841
52957
  where: { user_groups: { group_id: groupId } },
52842
52958
  limit: 2e5,
@@ -52847,7 +52963,7 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52847
52963
  for (const row of currentRows) {
52848
52964
  const userId = String(row.user_id ?? "");
52849
52965
  if (userId && !desired.has(userId)) {
52850
- await client2.destroyObjects({
52966
+ await client3.destroyObjects({
52851
52967
  object: "user_groups",
52852
52968
  where: { user_groups: { group_id: groupId, user_id: Number(userId) } }
52853
52969
  });
@@ -52856,13 +52972,13 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
52856
52972
  const current = new Set(currentRows.map((row) => String(row.user_id ?? "")));
52857
52973
  for (const userId of userIds) {
52858
52974
  if (!current.has(String(userId))) {
52859
- await client2.createObjects({
52975
+ await client3.createObjects({
52860
52976
  object: "user_groups",
52861
52977
  values: [{ group_id: groupId, user_id: userId }]
52862
52978
  });
52863
52979
  }
52864
52980
  }
52865
- const verification = await client2.loadObjects({
52981
+ const verification = await client3.loadObjects({
52866
52982
  object: "user_groups",
52867
52983
  where: { user_groups: { group_id: groupId } },
52868
52984
  limit: 2e5,
@@ -53365,10 +53481,10 @@ var HidAmicoClient = class {
53365
53481
  return res.data;
53366
53482
  }
53367
53483
  };
53368
- async function configureMonitor(client2, callbackToken) {
53484
+ async function configureMonitor(client3, callbackToken) {
53369
53485
  const expected = getMonitorConfiguration(callbackToken);
53370
- await client2.setConfiguration({ monitor: expected });
53371
- const response = await client2.getConfiguration({
53486
+ await client3.setConfiguration({ monitor: expected });
53487
+ const response = await client3.getConfiguration({
53372
53488
  monitor: ["request_timeout", "hostname", "port", "path"]
53373
53489
  });
53374
53490
  const root = isUnknownRecord2(response) ? response : {};
@@ -53378,9 +53494,9 @@ async function configureMonitor(client2, callbackToken) {
53378
53494
  }
53379
53495
  return expected;
53380
53496
  }
53381
- async function configureOperatingMode(client2, mode) {
53497
+ async function configureOperatingMode(client3, mode) {
53382
53498
  const expectedOnline = mode === "online" ? "1" : "0";
53383
- await client2.setConfiguration({
53499
+ await client3.setConfiguration({
53384
53500
  general: {
53385
53501
  online: expectedOnline,
53386
53502
  // HID documents Online mode as both flags enabled. Keeping local
@@ -53388,7 +53504,7 @@ async function configureOperatingMode(client2, mode) {
53388
53504
  local_identification: "1"
53389
53505
  }
53390
53506
  });
53391
- const response = await client2.getConfiguration({
53507
+ const response = await client3.getConfiguration({
53392
53508
  general: ["online", "local_identification"]
53393
53509
  });
53394
53510
  const root = isUnknownRecord2(response) ? response : {};
@@ -53772,8 +53888,8 @@ function useHidAmicoService() {
53772
53888
  return requestedType;
53773
53889
  return mode === "csn_for_mifare" ? "unknown" : mode;
53774
53890
  }
53775
- async function assertHidUserExists(client2, hidUserId) {
53776
- const response = await client2.loadObjects({
53891
+ async function assertHidUserExists(client3, hidUserId) {
53892
+ const response = await client3.loadObjects({
53777
53893
  object: "users",
53778
53894
  where: { users: { id: hidUserId } },
53779
53895
  limit: 1,
@@ -53783,18 +53899,18 @@ function useHidAmicoService() {
53783
53899
  throw new BadRequestError126("HID user must exist before assigning a physical HID card.");
53784
53900
  }
53785
53901
  }
53786
- async function ensurePhysicalCardIdentification(client2) {
53787
- const before = await client2.getConfiguration({
53902
+ async function ensurePhysicalCardIdentification(client3) {
53903
+ const before = await client3.getConfiguration({
53788
53904
  identifier: ["card_identification_enabled"]
53789
53905
  });
53790
53906
  const root = isUnknownRecord2(before) ? before : {};
53791
53907
  const identifier = isUnknownRecord2(root.identifier) ? root.identifier : {};
53792
53908
  if (String(identifier.card_identification_enabled ?? "") !== "1") {
53793
- await client2.setConfiguration({
53909
+ await client3.setConfiguration({
53794
53910
  identifier: { card_identification_enabled: "1" }
53795
53911
  });
53796
53912
  }
53797
- const verifiedResponse = await client2.getConfiguration({
53913
+ const verifiedResponse = await client3.getConfiguration({
53798
53914
  identifier: ["card_identification_enabled"]
53799
53915
  });
53800
53916
  const verifiedRoot = isUnknownRecord2(verifiedResponse) ? verifiedResponse : {};
@@ -53805,8 +53921,8 @@ function useHidAmicoService() {
53805
53921
  );
53806
53922
  }
53807
53923
  }
53808
- async function loadPhysicalCardRows(client2, hidUserId) {
53809
- const response = await client2.loadObjects({
53924
+ async function loadPhysicalCardRows(client3, hidUserId) {
53925
+ const response = await client3.loadObjects({
53810
53926
  object: "cards",
53811
53927
  where: { cards: { user_id: hidUserId } },
53812
53928
  limit: 100,
@@ -53904,15 +54020,15 @@ function useHidAmicoService() {
53904
54020
  const refusal = discoveryUrlRefusalReason(value.baseUrl);
53905
54021
  if (refusal)
53906
54022
  throw new BadRequestError126(refusal);
53907
- const client2 = new HidAmicoClient({
54023
+ const client3 = new HidAmicoClient({
53908
54024
  ...value,
53909
54025
  baseUrl: normalizeHidReaderBaseUrl(value.baseUrl)
53910
54026
  });
53911
54027
  try {
53912
- await client2.login();
54028
+ await client3.login();
53913
54029
  const [systemResponse, portalsResponse] = await Promise.all([
53914
- client2.getSystemInformation(),
53915
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54030
+ client3.getSystemInformation(),
54031
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
53916
54032
  ]);
53917
54033
  const system = getHidSystemInformation(systemResponse);
53918
54034
  const deviceId = isUnknownRecord2(system) ? String(system.device_id || "").trim() : "";
@@ -53942,7 +54058,7 @@ function useHidAmicoService() {
53942
54058
  portals
53943
54059
  };
53944
54060
  } finally {
53945
- await client2.logout();
54061
+ await client3.logout();
53946
54062
  }
53947
54063
  }
53948
54064
  async function createReader(value) {
@@ -53972,11 +54088,11 @@ function useHidAmicoService() {
53972
54088
  const readerId = String(reader._id);
53973
54089
  if (value.enabled === false)
53974
54090
  return reader;
53975
- const client2 = new HidAmicoClient(value);
54091
+ const client3 = new HidAmicoClient(value);
53976
54092
  try {
53977
- await client2.login();
54093
+ await client3.login();
53978
54094
  if (!monitorEnabled) {
53979
- await configureOperatingMode(client2, "standalone");
54095
+ await configureOperatingMode(client3, "standalone");
53980
54096
  return repo.updateById(readerId, {
53981
54097
  monitorStatus: "disabled",
53982
54098
  monitorPath: "",
@@ -53985,8 +54101,8 @@ function useHidAmicoService() {
53985
54101
  lastSyncMessage: "Monitor callbacks are disabled; Standalone mode configured."
53986
54102
  });
53987
54103
  }
53988
- const monitor = await configureMonitor(client2, callbackToken);
53989
- await configureOperatingMode(client2, "standalone");
54104
+ const monitor = await configureMonitor(client3, callbackToken);
54105
+ await configureOperatingMode(client3, "standalone");
53990
54106
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
53991
54107
  return repo.updateById(readerId, {
53992
54108
  monitorPath: publicMonitor.path,
@@ -54012,7 +54128,7 @@ function useHidAmicoService() {
54012
54128
  });
54013
54129
  return { ...failed, monitorWarning: message };
54014
54130
  } finally {
54015
- await client2.logout();
54131
+ await client3.logout();
54016
54132
  }
54017
54133
  }
54018
54134
  async function updateReader(id, value) {
@@ -54052,10 +54168,10 @@ function useHidAmicoService() {
54052
54168
  }
54053
54169
  if (payload.portalId && current) {
54054
54170
  const candidate = { ...current, ...payload };
54055
- const client2 = new HidAmicoClient(candidate);
54171
+ const client3 = new HidAmicoClient(candidate);
54056
54172
  try {
54057
- await client2.login();
54058
- const portals = getHidPortals(await client2.loadObjects({
54173
+ await client3.login();
54174
+ const portals = getHidPortals(await client3.loadObjects({
54059
54175
  object: "portals",
54060
54176
  limit: 100,
54061
54177
  offset: 0
@@ -54066,7 +54182,7 @@ function useHidAmicoService() {
54066
54182
  }
54067
54183
  payload.portalName = portal.name;
54068
54184
  } finally {
54069
- await client2.logout();
54185
+ await client3.logout();
54070
54186
  }
54071
54187
  }
54072
54188
  return repo.updateById(id, payload);
@@ -54084,12 +54200,12 @@ function useHidAmicoService() {
54084
54200
  monitorStatus: "unconfigured"
54085
54201
  });
54086
54202
  }
54087
- const client2 = new HidAmicoClient(reader);
54203
+ const client3 = new HidAmicoClient(reader);
54088
54204
  try {
54089
- await client2.login();
54205
+ await client3.login();
54090
54206
  const [systemResponse, portalsResponse] = await Promise.all([
54091
- client2.getSystemInformation(),
54092
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54207
+ client3.getSystemInformation(),
54208
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
54093
54209
  ]);
54094
54210
  const system = getHidSystemInformation(systemResponse);
54095
54211
  const serial = isUnknownRecord2(system) ? String(system.serial || "") : "";
@@ -54106,9 +54222,9 @@ function useHidAmicoService() {
54106
54222
  "The saved portal no longer exists on this HID reader. Edit the reader and select a valid portal."
54107
54223
  );
54108
54224
  }
54109
- const monitor = await configureMonitor(client2, callbackToken);
54225
+ const monitor = await configureMonitor(client3, callbackToken);
54110
54226
  const mode = reader.operatingMode === "online" ? "online" : "standalone";
54111
- await configureOperatingMode(client2, mode);
54227
+ await configureOperatingMode(client3, mode);
54112
54228
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
54113
54229
  await repo.updateById(id, {
54114
54230
  serial,
@@ -54131,17 +54247,17 @@ function useHidAmicoService() {
54131
54247
  });
54132
54248
  throw error;
54133
54249
  } finally {
54134
- await client2.logout();
54250
+ await client3.logout();
54135
54251
  }
54136
54252
  }
54137
54253
  async function setReaderMonitor(id, enabled) {
54138
54254
  if (enabled)
54139
54255
  return configureReaderIntegration(id);
54140
54256
  const reader = await getActiveReader(id);
54141
- const client2 = new HidAmicoClient(reader);
54257
+ const client3 = new HidAmicoClient(reader);
54142
54258
  try {
54143
- await client2.login();
54144
- await configureOperatingMode(client2, "standalone");
54259
+ await client3.login();
54260
+ await configureOperatingMode(client3, "standalone");
54145
54261
  await repo.updateById(id, {
54146
54262
  monitorStatus: "disabled",
54147
54263
  monitorPath: "",
@@ -54158,7 +54274,7 @@ function useHidAmicoService() {
54158
54274
  });
54159
54275
  return { enabled: false, mode: "standalone", verified: true };
54160
54276
  } finally {
54161
- await client2.logout();
54277
+ await client3.logout();
54162
54278
  }
54163
54279
  }
54164
54280
  async function setOperatingMode(id, mode) {
@@ -54168,10 +54284,10 @@ function useHidAmicoService() {
54168
54284
  "Configure and verify the HID Monitor callback before enabling Online mode."
54169
54285
  );
54170
54286
  }
54171
- const client2 = new HidAmicoClient(reader);
54287
+ const client3 = new HidAmicoClient(reader);
54172
54288
  try {
54173
- await client2.login();
54174
- const result = await configureOperatingMode(client2, mode);
54289
+ await client3.login();
54290
+ const result = await configureOperatingMode(client3, mode);
54175
54291
  await repo.updateById(id, {
54176
54292
  operatingMode: mode,
54177
54293
  lastSyncStatus: "completed",
@@ -54186,7 +54302,7 @@ function useHidAmicoService() {
54186
54302
  });
54187
54303
  return sanitizeHidPayload(result);
54188
54304
  } finally {
54189
- await client2.logout();
54305
+ await client3.logout();
54190
54306
  }
54191
54307
  }
54192
54308
  async function listReaders(value) {
@@ -54241,12 +54357,12 @@ function useHidAmicoService() {
54241
54357
  }
54242
54358
  async function testReader(id) {
54243
54359
  const reader = await repo.getById(id, { includePassword: true });
54244
- const client2 = new HidAmicoClient(reader);
54360
+ const client3 = new HidAmicoClient(reader);
54245
54361
  try {
54246
- await client2.login();
54362
+ await client3.login();
54247
54363
  const [valid, systemResponse] = await Promise.all([
54248
- client2.sessionIsValid(),
54249
- client2.getSystemInformation()
54364
+ client3.sessionIsValid(),
54365
+ client3.getSystemInformation()
54250
54366
  ]);
54251
54367
  const system = getHidSystemInformation(systemResponse);
54252
54368
  const firmwareVersion = getHidFirmwareVersion(systemResponse);
@@ -54300,19 +54416,19 @@ function useHidAmicoService() {
54300
54416
  await repo.addEvent({ reader: id, site: reader.site, type: "test_failed", payload: { message } });
54301
54417
  throw error;
54302
54418
  } finally {
54303
- await client2.logout();
54419
+ await client3.logout();
54304
54420
  }
54305
54421
  }
54306
54422
  async function syncReader(id, payload) {
54307
54423
  const reader = await getActiveReader(id);
54308
54424
  const batches = normalizeBatches(payload);
54309
- const client2 = new HidAmicoClient(reader);
54425
+ const client3 = new HidAmicoClient(reader);
54310
54426
  const results = [];
54311
54427
  await repo.updateById(id, { lastSyncStatus: "running", lastSyncMessage: "Sync started." });
54312
54428
  try {
54313
- await client2.login();
54429
+ await client3.login();
54314
54430
  for (const batch of batches) {
54315
- const result = await client2.createObjects(batch);
54431
+ const result = await client3.createObjects(batch);
54316
54432
  results.push({
54317
54433
  object: batch.object,
54318
54434
  count: batch.values.length,
@@ -54340,7 +54456,7 @@ function useHidAmicoService() {
54340
54456
  await repo.addEvent({ reader: id, site: reader.site, type: "sync_failed", payload: { message } });
54341
54457
  throw error;
54342
54458
  } finally {
54343
- await client2.logout();
54459
+ await client3.logout();
54344
54460
  }
54345
54461
  }
54346
54462
  async function isIdentityAssignedToReader(reader, identity, requestedPortalId) {
@@ -54456,9 +54572,9 @@ function useHidAmicoService() {
54456
54572
  async function listReaderUsers(readerId, page2 = 1, limit = 10, search = "", status = "", includeVisitors = false, userType = "all") {
54457
54573
  const reader = await getActiveReader(readerId);
54458
54574
  const offset = (page2 - 1) * limit;
54459
- const client2 = new HidAmicoClient(reader);
54575
+ const client3 = new HidAmicoClient(reader);
54460
54576
  try {
54461
- await client2.login();
54577
+ await client3.login();
54462
54578
  const normalizedSearch = search.trim();
54463
54579
  const numericSearch = /^\d{1,15}$/.test(normalizedSearch) ? Number(normalizedSearch) : null;
54464
54580
  const userWhere = {};
@@ -54470,7 +54586,7 @@ function useHidAmicoService() {
54470
54586
  let rows = [];
54471
54587
  let reportedTotal = null;
54472
54588
  let hasMore = false;
54473
- const response = await client2.loadObjects({
54589
+ const response = await client3.loadObjects({
54474
54590
  object: "users",
54475
54591
  where: { users: userWhere },
54476
54592
  limit: 500,
@@ -54490,7 +54606,7 @@ function useHidAmicoService() {
54490
54606
  const userId = Number(row.id);
54491
54607
  if (!Number.isSafeInteger(userId) || userId <= 0)
54492
54608
  return false;
54493
- const roleResponse = await client2.loadObjects({
54609
+ const roleResponse = await client3.loadObjects({
54494
54610
  object: "user_roles",
54495
54611
  where: { user_roles: { user_id: userId, role: 1 } },
54496
54612
  limit: 1,
@@ -54498,7 +54614,7 @@ function useHidAmicoService() {
54498
54614
  });
54499
54615
  return getHidObjectRows(roleResponse, "user_roles").length > 0;
54500
54616
  })),
54501
- readerSupportsFacial(reader) ? client2.listUserImageIds().catch(() => []) : Promise.resolve([])
54617
+ readerSupportsFacial(reader) ? client3.listUserImageIds().catch(() => []) : Promise.resolve([])
54502
54618
  ]);
54503
54619
  const facialUserIdSet = new Set(facialUserIds.map(String));
54504
54620
  const items = rows.map((row, index) => {
@@ -54528,15 +54644,15 @@ function useHidAmicoService() {
54528
54644
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${reportedTotal ?? `${offset + items.length}${hasMore ? "+" : ""}`}` : "0-0 of 0"
54529
54645
  };
54530
54646
  } finally {
54531
- await client2.logout();
54647
+ await client3.logout();
54532
54648
  }
54533
54649
  }
54534
54650
  async function listReaderAccessLogs(readerId, page2 = 1, limit = 10, search = "", status = "", method = "", tab = "all") {
54535
54651
  const reader = await getActiveReader(readerId);
54536
54652
  const offset = (page2 - 1) * limit;
54537
- const client2 = new HidAmicoClient(reader);
54653
+ const client3 = new HidAmicoClient(reader);
54538
54654
  try {
54539
- await client2.login();
54655
+ await client3.login();
54540
54656
  const where = {};
54541
54657
  if (status === "authorized")
54542
54658
  where.event = 7;
@@ -54557,7 +54673,7 @@ function useHidAmicoService() {
54557
54673
  const userIds = [...new Set(rows.map((row) => toPositiveInteger(row.user_id ?? row.userId)).filter((value) => value !== null))];
54558
54674
  const [identities, roleResponse, userResponse] = await Promise.all([
54559
54675
  repo.findIdentitiesByHidUserIds(readerId, userIds.map(String)),
54560
- userIds.length ? client2.loadObjects({
54676
+ userIds.length ? client3.loadObjects({
54561
54677
  object: "user_roles",
54562
54678
  where: {
54563
54679
  user_roles: {
@@ -54568,7 +54684,7 @@ function useHidAmicoService() {
54568
54684
  limit: Math.max(1, userIds.length),
54569
54685
  offset: 0
54570
54686
  }) : Promise.resolve({ user_roles: [] }),
54571
- userIds.length ? client2.loadObjects({
54687
+ userIds.length ? client3.loadObjects({
54572
54688
  object: "users",
54573
54689
  where: {
54574
54690
  users: {
@@ -54640,7 +54756,7 @@ function useHidAmicoService() {
54640
54756
  let deviceOffset = 0;
54641
54757
  let exhausted = false;
54642
54758
  while (!exhausted && matchedItems.length < targetCount) {
54643
- const response = await client2.loadObjects({
54759
+ const response = await client3.loadObjects({
54644
54760
  object: "access_logs",
54645
54761
  ...Object.keys(where).length ? { where: { access_logs: where } } : {},
54646
54762
  limit: chunkSize,
@@ -54667,7 +54783,7 @@ function useHidAmicoService() {
54667
54783
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${offset + items.length}${hasMore ? "+" : ""}` : "0-0 of 0"
54668
54784
  };
54669
54785
  } finally {
54670
- await client2.logout();
54786
+ await client3.logout();
54671
54787
  }
54672
54788
  }
54673
54789
  async function createIdentity(readerId, value) {
@@ -54759,18 +54875,18 @@ function useHidAmicoService() {
54759
54875
  async function runObjectOperation(id, operation, payload) {
54760
54876
  const reader = await getActiveReader(id);
54761
54877
  assertAllowedHidObject(payload.object, operation);
54762
- const client2 = new HidAmicoClient(reader);
54878
+ const client3 = new HidAmicoClient(reader);
54763
54879
  try {
54764
- await client2.login();
54880
+ await client3.login();
54765
54881
  let result;
54766
54882
  if (operation === "load") {
54767
- result = await client2.loadObjects(payload);
54883
+ result = await client3.loadObjects(payload);
54768
54884
  } else if (operation === "create") {
54769
- result = await client2.createObjects(payload);
54885
+ result = await client3.createObjects(payload);
54770
54886
  } else if (operation === "modify") {
54771
- result = await client2.modifyObjects(payload);
54887
+ result = await client3.modifyObjects(payload);
54772
54888
  } else {
54773
- result = await client2.destroyObjects(payload);
54889
+ result = await client3.destroyObjects(payload);
54774
54890
  }
54775
54891
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
54776
54892
  const safeRequest = sanitizeHidObjectPayload(payload.object, payload);
@@ -54794,7 +54910,7 @@ function useHidAmicoService() {
54794
54910
  });
54795
54911
  throw error;
54796
54912
  } finally {
54797
- await client2.logout();
54913
+ await client3.logout();
54798
54914
  }
54799
54915
  }
54800
54916
  async function issueVisitorQrAtReader(readerId, value) {
@@ -54825,10 +54941,10 @@ function useHidAmicoService() {
54825
54941
  const hidUserId = createStableHidId(`visitor:${readerId}:${value.visitorId}`);
54826
54942
  const registration = `VIS-${value.visitorId.slice(-12).toUpperCase()}`;
54827
54943
  const credential = createVisitorQrCredential(value.visitorId, readerId, value.qrValue);
54828
- const client2 = new HidAmicoClient(reader);
54944
+ const client3 = new HidAmicoClient(reader);
54829
54945
  try {
54830
- await client2.login();
54831
- const readerConfigurationChanged = await configureVisitorQrReader(client2);
54946
+ await client3.login();
54947
+ const readerConfigurationChanged = await configureVisitorQrReader(client3);
54832
54948
  if (readerConfigurationChanged) {
54833
54949
  await repo.addEvent({
54834
54950
  reader: readerId,
@@ -54842,7 +54958,7 @@ function useHidAmicoService() {
54842
54958
  }
54843
54959
  });
54844
54960
  }
54845
- const existingUserResponse = await client2.loadObjects({
54961
+ const existingUserResponse = await client3.loadObjects({
54846
54962
  object: "users",
54847
54963
  where: { users: { id: hidUserId } },
54848
54964
  limit: 1,
@@ -54863,18 +54979,18 @@ function useHidAmicoService() {
54863
54979
  );
54864
54980
  }
54865
54981
  if (existingUsers.length) {
54866
- await client2.modifyObjects({
54982
+ await client3.modifyObjects({
54867
54983
  object: "users",
54868
54984
  where: { users: { id: hidUserId } },
54869
54985
  values: user
54870
54986
  });
54871
54987
  } else {
54872
- await client2.createObjects({
54988
+ await client3.createObjects({
54873
54989
  object: "users",
54874
54990
  values: [{ id: hidUserId, ...user }]
54875
54991
  });
54876
54992
  }
54877
- const savedUserResponse = await client2.loadObjects({
54993
+ const savedUserResponse = await client3.loadObjects({
54878
54994
  object: "users",
54879
54995
  where: { users: { id: hidUserId } },
54880
54996
  limit: 1,
@@ -54889,12 +55005,12 @@ function useHidAmicoService() {
54889
55005
  );
54890
55006
  }
54891
55007
  const authorization = await ensureVisitorAccessAuthorization(
54892
- client2,
55008
+ client3,
54893
55009
  readerId,
54894
55010
  reader,
54895
55011
  hidUserId
54896
55012
  );
54897
- const existingQrResponse = await client2.loadObjects({
55013
+ const existingQrResponse = await client3.loadObjects({
54898
55014
  object: credential.object,
54899
55015
  where: { [credential.object]: { user_id: hidUserId } },
54900
55016
  limit: 100,
@@ -54903,18 +55019,18 @@ function useHidAmicoService() {
54903
55019
  const existingQrs = getHidObjectRows(existingQrResponse, credential.object);
54904
55020
  const credentialValues = { value: credential.value, user_id: hidUserId };
54905
55021
  if (existingQrs.some((row) => String(row.id) === String(credential.credentialId))) {
54906
- await client2.modifyObjects({
55022
+ await client3.modifyObjects({
54907
55023
  object: credential.object,
54908
55024
  where: { [credential.object]: { id: credential.credentialId } },
54909
55025
  values: credentialValues
54910
55026
  });
54911
55027
  } else {
54912
- await client2.createObjects({
55028
+ await client3.createObjects({
54913
55029
  object: credential.object,
54914
55030
  values: [{ id: credential.credentialId, ...credentialValues }]
54915
55031
  });
54916
55032
  }
54917
- const savedCredentialResponse = await client2.loadObjects({
55033
+ const savedCredentialResponse = await client3.loadObjects({
54918
55034
  object: credential.object,
54919
55035
  where: { [credential.object]: { id: credential.credentialId } },
54920
55036
  limit: 1,
@@ -54932,20 +55048,20 @@ function useHidAmicoService() {
54932
55048
  for (const staleQr of existingQrs) {
54933
55049
  const staleId = Number(staleQr.id);
54934
55050
  if (Number.isSafeInteger(staleId) && staleId > 0 && staleId !== credential.credentialId) {
54935
- await client2.destroyObjects({
55051
+ await client3.destroyObjects({
54936
55052
  object: credential.object,
54937
55053
  where: { [credential.object]: { id: staleId } }
54938
55054
  });
54939
55055
  }
54940
55056
  }
54941
- const existingCardsResponse = await client2.loadObjects({
55057
+ const existingCardsResponse = await client3.loadObjects({
54942
55058
  object: "cards",
54943
55059
  where: { cards: { user_id: hidUserId } },
54944
55060
  limit: 100,
54945
55061
  offset: 0
54946
55062
  });
54947
55063
  if (getHidObjectRows(existingCardsResponse, "cards").length) {
54948
- await client2.destroyObjects({
55064
+ await client3.destroyObjects({
54949
55065
  object: "cards",
54950
55066
  where: { cards: { user_id: hidUserId } }
54951
55067
  });
@@ -55026,7 +55142,7 @@ function useHidAmicoService() {
55026
55142
  });
55027
55143
  throw error;
55028
55144
  } finally {
55029
- await client2.logout();
55145
+ await client3.logout();
55030
55146
  }
55031
55147
  }
55032
55148
  async function resolveVisitorQrGateReaders(siteId, callerId5, fallbackReaderId, issuer) {
@@ -55144,10 +55260,10 @@ function useHidAmicoService() {
55144
55260
  const enrolledAt = /* @__PURE__ */ new Date();
55145
55261
  const timestamp = options.timestamp || Math.floor(enrolledAt.getTime() / 1e3);
55146
55262
  const match = options.match ?? true;
55147
- const client2 = new HidAmicoClient(reader);
55263
+ const client3 = new HidAmicoClient(reader);
55148
55264
  try {
55149
- await client2.login();
55150
- const existingUserResponse = await client2.loadObjects({
55265
+ await client3.login();
55266
+ const existingUserResponse = await client3.loadObjects({
55151
55267
  object: "users",
55152
55268
  where: { users: { id: context.hidUserId } },
55153
55269
  limit: 1,
@@ -55158,18 +55274,18 @@ function useHidAmicoService() {
55158
55274
  registration: context.registration
55159
55275
  };
55160
55276
  if (getHidObjectRows(existingUserResponse, "users").length) {
55161
- await client2.modifyObjects({
55277
+ await client3.modifyObjects({
55162
55278
  object: "users",
55163
55279
  where: { users: { id: context.hidUserId } },
55164
55280
  values: hidUser
55165
55281
  });
55166
55282
  } else {
55167
- await client2.createObjects({
55283
+ await client3.createObjects({
55168
55284
  object: "users",
55169
55285
  values: [{ id: context.hidUserId, ...hidUser }]
55170
55286
  });
55171
55287
  }
55172
- const result = await client2.setUserImage(context.hidUserId, image, timestamp, match);
55288
+ const result = await client3.setUserImage(context.hidUserId, image, timestamp, match);
55173
55289
  const existingIdentity = context.profileIdentity || await repo.findExistingIdentity({
55174
55290
  reader: readerId,
55175
55291
  hidUserId: context.hidUserId
@@ -55234,25 +55350,25 @@ function useHidAmicoService() {
55234
55350
  });
55235
55351
  throw error;
55236
55352
  } finally {
55237
- await client2.logout();
55353
+ await client3.logout();
55238
55354
  }
55239
55355
  }
55240
55356
  async function getUserImage(readerId, hidUserId) {
55241
55357
  const reader = await getActiveReader(readerId);
55242
55358
  assertReaderCapability(reader, "facial");
55243
- const client2 = new HidAmicoClient(reader);
55359
+ const client3 = new HidAmicoClient(reader);
55244
55360
  try {
55245
- await client2.login();
55246
- return await client2.getUserImage(hidUserId);
55361
+ await client3.login();
55362
+ return await client3.getUserImage(hidUserId);
55247
55363
  } finally {
55248
- await client2.logout();
55364
+ await client3.logout();
55249
55365
  }
55250
55366
  }
55251
- async function getReaderFacialUserIds(client2) {
55367
+ async function getReaderFacialUserIds(client3) {
55252
55368
  try {
55253
- return await client2.listUserImageIds();
55369
+ return await client3.listUserImageIds();
55254
55370
  } catch {
55255
- const usersResponse = await client2.loadObjects({
55371
+ const usersResponse = await client3.loadObjects({
55256
55372
  object: "users",
55257
55373
  where: { users: {} },
55258
55374
  limit: 500,
@@ -55266,7 +55382,7 @@ function useHidAmicoService() {
55266
55382
  const batch = userIds.slice(offset, offset + batchSize);
55267
55383
  const results = await Promise.all(batch.map(async (userId) => {
55268
55384
  try {
55269
- const image = await client2.getUserImage(userId);
55385
+ const image = await client3.getUserImage(userId);
55270
55386
  return image.base64 ? userId : null;
55271
55387
  } catch {
55272
55388
  return null;
@@ -55280,10 +55396,10 @@ function useHidAmicoService() {
55280
55396
  async function syncReaderFacialData(readerId) {
55281
55397
  const reader = await getActiveReader(readerId);
55282
55398
  assertReaderCapability(reader, "facial");
55283
- const client2 = new HidAmicoClient(reader);
55399
+ const client3 = new HidAmicoClient(reader);
55284
55400
  try {
55285
- await client2.login();
55286
- const facialUserIds = await getReaderFacialUserIds(client2);
55401
+ await client3.login();
55402
+ const facialUserIds = await getReaderFacialUserIds(client3);
55287
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.";
55288
55404
  await repo.updateById(readerId, { status: "active", lastSeenAt: /* @__PURE__ */ new Date() });
55289
55405
  await repo.addEvent({
@@ -55315,7 +55431,7 @@ function useHidAmicoService() {
55315
55431
  });
55316
55432
  throw error;
55317
55433
  } finally {
55318
- await client2.logout();
55434
+ await client3.logout();
55319
55435
  }
55320
55436
  }
55321
55437
  async function setVisitorImage(readerId, visitorId, image, options = {}) {
@@ -55334,10 +55450,10 @@ function useHidAmicoService() {
55334
55450
  );
55335
55451
  const timestamp = options.timestamp || Math.floor(issuedAt.getTime() / 1e3);
55336
55452
  const match = options.match ?? true;
55337
- const client2 = new HidAmicoClient(reader);
55453
+ const client3 = new HidAmicoClient(reader);
55338
55454
  try {
55339
- await client2.login();
55340
- const existingUserResponse = await client2.loadObjects({
55455
+ await client3.login();
55456
+ const existingUserResponse = await client3.loadObjects({
55341
55457
  object: "users",
55342
55458
  where: { users: { id: hidUserId } },
55343
55459
  limit: 1,
@@ -55351,24 +55467,24 @@ function useHidAmicoService() {
55351
55467
  end_time: Math.floor(expiresAt.getTime() / 1e3)
55352
55468
  };
55353
55469
  if (getHidObjectRows(existingUserResponse, "users").length) {
55354
- await client2.modifyObjects({
55470
+ await client3.modifyObjects({
55355
55471
  object: "users",
55356
55472
  where: { users: { id: hidUserId } },
55357
55473
  values: user
55358
55474
  });
55359
55475
  } else {
55360
- await client2.createObjects({
55476
+ await client3.createObjects({
55361
55477
  object: "users",
55362
55478
  values: [{ id: hidUserId, ...user }]
55363
55479
  });
55364
55480
  }
55365
55481
  const authorization = await ensureVisitorAccessAuthorization(
55366
- client2,
55482
+ client3,
55367
55483
  readerId,
55368
55484
  reader,
55369
55485
  hidUserId
55370
55486
  );
55371
- const result = await client2.setUserImage(hidUserId, image, timestamp, match);
55487
+ const result = await client3.setUserImage(hidUserId, image, timestamp, match);
55372
55488
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
55373
55489
  const existingMetadata = existingIdentity && isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
55374
55490
  const identityPayload = {
@@ -55434,17 +55550,17 @@ function useHidAmicoService() {
55434
55550
  });
55435
55551
  throw error;
55436
55552
  } finally {
55437
- await client2.logout();
55553
+ await client3.logout();
55438
55554
  }
55439
55555
  }
55440
55556
  async function deleteVisitorImage(readerId, visitorId) {
55441
55557
  const reader = await getActiveReader(readerId);
55442
55558
  assertReaderCapability(reader, "facial");
55443
55559
  const { hidUserId } = await getVisitorEnrollmentContext(readerId, reader, visitorId);
55444
- const client2 = new HidAmicoClient(reader);
55560
+ const client3 = new HidAmicoClient(reader);
55445
55561
  try {
55446
- await client2.login();
55447
- const result = await client2.deleteUserImage(hidUserId);
55562
+ await client3.login();
55563
+ const result = await client3.deleteUserImage(hidUserId);
55448
55564
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
55449
55565
  if (existingIdentity?._id) {
55450
55566
  const existingMetadata = isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
@@ -55473,7 +55589,7 @@ function useHidAmicoService() {
55473
55589
  });
55474
55590
  throw error;
55475
55591
  } finally {
55476
- await client2.logout();
55592
+ await client3.logout();
55477
55593
  }
55478
55594
  }
55479
55595
  async function listUserCards(readerId, hidUserIdValue) {
@@ -55481,19 +55597,19 @@ function useHidAmicoService() {
55481
55597
  assertReaderCapability(reader, "card");
55482
55598
  const cardType = reader.cardReadingMode === "pacs" || reader.cardReadingMode === "csn" ? reader.cardReadingMode : "unknown";
55483
55599
  const hidUserId = Number(hidUserIdValue);
55484
- const client2 = new HidAmicoClient(reader);
55600
+ const client3 = new HidAmicoClient(reader);
55485
55601
  try {
55486
- await client2.login();
55487
- await assertHidUserExists(client2, hidUserId);
55602
+ await client3.login();
55603
+ await assertHidUserExists(client3, hidUserId);
55488
55604
  const [rows, identity] = await Promise.all([
55489
- loadPhysicalCardRows(client2, hidUserId),
55605
+ loadPhysicalCardRows(client3, hidUserId),
55490
55606
  repo.findExistingIdentity({ reader: readerId, hidUserId })
55491
55607
  ]);
55492
55608
  const metadataRows = getIdentityPhysicalCards(identity);
55493
55609
  const cards = rows.map((row) => toHidPhysicalCard(row, metadataRows, cardType)).filter((card) => Boolean(card));
55494
55610
  return { readerId, hidUserId, cards };
55495
55611
  } finally {
55496
- await client2.logout();
55612
+ await client3.logout();
55497
55613
  }
55498
55614
  }
55499
55615
  async function assignUserCard(readerId, hidUserIdValue, input) {
@@ -55507,12 +55623,12 @@ function useHidAmicoService() {
55507
55623
  } catch (error) {
55508
55624
  throw new BadRequestError126(getErrorMessage2(error));
55509
55625
  }
55510
- const client2 = new HidAmicoClient(reader);
55626
+ const client3 = new HidAmicoClient(reader);
55511
55627
  try {
55512
- await client2.login();
55513
- await assertHidUserExists(client2, hidUserId);
55514
- await ensurePhysicalCardIdentification(client2);
55515
- const collisionResponse = await client2.loadObjects({
55628
+ await client3.login();
55629
+ await assertHidUserExists(client3, hidUserId);
55630
+ await ensurePhysicalCardIdentification(client3);
55631
+ const collisionResponse = await client3.loadObjects({
55516
55632
  object: "cards",
55517
55633
  where: { cards: { value: hidRawUint64(cardValue) } },
55518
55634
  limit: 10,
@@ -55530,11 +55646,11 @@ function useHidAmicoService() {
55530
55646
  );
55531
55647
  if (!savedRow) {
55532
55648
  const credentialId = createStableHidId(`physical-card:${readerId}:${cardValue}`);
55533
- await client2.createObjects({
55649
+ await client3.createObjects({
55534
55650
  object: "cards",
55535
55651
  values: [{ id: credentialId, value: hidRawUint64(cardValue), user_id: hidUserId }]
55536
55652
  });
55537
- const verifiedResponse = await client2.loadObjects({
55653
+ const verifiedResponse = await client3.loadObjects({
55538
55654
  object: "cards",
55539
55655
  where: { cards: { id: credentialId } },
55540
55656
  limit: 1,
@@ -55575,7 +55691,7 @@ function useHidAmicoService() {
55575
55691
  });
55576
55692
  throw error;
55577
55693
  } finally {
55578
- await client2.logout();
55694
+ await client3.logout();
55579
55695
  }
55580
55696
  }
55581
55697
  async function enrollUserCard(readerId, hidUserIdValue, cardType, timeoutSeconds) {
@@ -55583,17 +55699,17 @@ function useHidAmicoService() {
55583
55699
  assertReaderCapability(reader, "card");
55584
55700
  assertReaderCardProfile(reader, cardType);
55585
55701
  const hidUserId = Number(hidUserIdValue);
55586
- const client2 = new HidAmicoClient(reader);
55702
+ const client3 = new HidAmicoClient(reader);
55587
55703
  const lockOwner = crypto6.randomUUID();
55588
55704
  const acquired = await repo.acquireEnrollmentLock(readerId, lockOwner, timeoutSeconds + 30);
55589
55705
  if (!acquired) {
55590
55706
  throw new BadRequestError126("Another physical HID card enrollment is already running on this reader.");
55591
55707
  }
55592
55708
  try {
55593
- await client2.login();
55594
- await assertHidUserExists(client2, hidUserId);
55595
- await ensurePhysicalCardIdentification(client2);
55596
- 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);
55597
55713
  const beforeValues = new Set(beforeRows.map((row) => String(row.value ?? "")));
55598
55714
  await repo.addEvent({
55599
55715
  reader: readerId,
@@ -55602,7 +55718,7 @@ function useHidAmicoService() {
55602
55718
  payload: { hidUserId, cardType, timeoutSeconds }
55603
55719
  });
55604
55720
  const startedAt = Date.now();
55605
- const response = await client2.remoteEnrollCard(hidUserId, timeoutSeconds);
55721
+ const response = await client3.remoteEnrollCard(hidUserId, timeoutSeconds);
55606
55722
  const responseRecord = isUnknownRecord2(response) ? response : {};
55607
55723
  const responseData = isUnknownRecord2(responseRecord.data) ? responseRecord.data : responseRecord;
55608
55724
  if (responseData.success === false) {
@@ -55619,7 +55735,7 @@ function useHidAmicoService() {
55619
55735
  const deadline = startedAt + timeoutSeconds * 1e3;
55620
55736
  let savedRow;
55621
55737
  do {
55622
- const rows = await loadPhysicalCardRows(client2, hidUserId);
55738
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
55623
55739
  savedRow = responseValue === null ? rows.find((row) => !beforeValues.has(String(row.value ?? ""))) : rows.find((row) => String(row.value ?? "") === String(responseValue));
55624
55740
  if (savedRow || Date.now() >= deadline)
55625
55741
  break;
@@ -55652,7 +55768,7 @@ function useHidAmicoService() {
55652
55768
  return { readerId, hidUserId, card, verified: true };
55653
55769
  } catch (error) {
55654
55770
  try {
55655
- await client2.cancelRemoteEnrollment();
55771
+ await client3.cancelRemoteEnrollment();
55656
55772
  } catch {
55657
55773
  }
55658
55774
  await repo.addEvent({
@@ -55665,15 +55781,15 @@ function useHidAmicoService() {
55665
55781
  throw error;
55666
55782
  } finally {
55667
55783
  await repo.releaseEnrollmentLock(readerId, lockOwner);
55668
- await client2.logout();
55784
+ await client3.logout();
55669
55785
  }
55670
55786
  }
55671
55787
  async function cancelUserCardEnrollment(readerId) {
55672
55788
  const reader = await getActiveReader(readerId);
55673
- const client2 = new HidAmicoClient(reader);
55789
+ const client3 = new HidAmicoClient(reader);
55674
55790
  try {
55675
- await client2.login();
55676
- await client2.cancelRemoteEnrollment();
55791
+ await client3.login();
55792
+ await client3.cancelRemoteEnrollment();
55677
55793
  const enrollmentWasRunning = await repo.releaseEnrollmentLock(readerId);
55678
55794
  await repo.addEvent({
55679
55795
  reader: readerId,
@@ -55683,27 +55799,27 @@ function useHidAmicoService() {
55683
55799
  });
55684
55800
  return { readerId, cancelled: true };
55685
55801
  } finally {
55686
- await client2.logout();
55802
+ await client3.logout();
55687
55803
  }
55688
55804
  }
55689
55805
  async function deleteUserCard(readerId, hidUserIdValue, cardIdValue) {
55690
55806
  const reader = await getActiveReader(readerId);
55691
55807
  const hidUserId = Number(hidUserIdValue);
55692
55808
  const cardId = Number(cardIdValue);
55693
- const client2 = new HidAmicoClient(reader);
55809
+ const client3 = new HidAmicoClient(reader);
55694
55810
  try {
55695
- await client2.login();
55696
- const rows = await loadPhysicalCardRows(client2, hidUserId);
55811
+ await client3.login();
55812
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
55697
55813
  const cardRow = rows.find((row) => String(row.id ?? "") === String(cardId));
55698
55814
  if (!cardRow) {
55699
55815
  throw new BadRequestError126("Physical HID card was not found for this HID user.");
55700
55816
  }
55701
55817
  const cardValue = String(normalizeHidCardValue(cardRow.value));
55702
- await client2.destroyObjects({
55818
+ await client3.destroyObjects({
55703
55819
  object: "cards",
55704
55820
  where: { cards: { id: cardId } }
55705
55821
  });
55706
- const verifiedRows = await loadPhysicalCardRows(client2, hidUserId);
55822
+ const verifiedRows = await loadPhysicalCardRows(client3, hidUserId);
55707
55823
  if (verifiedRows.some((row) => String(row.id ?? "") === String(cardId))) {
55708
55824
  throw new BadRequestError126("The HID reader did not remove the physical card.");
55709
55825
  }
@@ -55726,17 +55842,17 @@ function useHidAmicoService() {
55726
55842
  });
55727
55843
  throw error;
55728
55844
  } finally {
55729
- await client2.logout();
55845
+ await client3.logout();
55730
55846
  }
55731
55847
  }
55732
55848
  async function getUserPinStatus(readerId, hidUserIdValue) {
55733
55849
  const reader = await getActiveReader(readerId);
55734
55850
  assertReaderCapability(reader, "pin");
55735
55851
  const hidUserId = Number(hidUserIdValue);
55736
- const client2 = new HidAmicoClient(reader);
55852
+ const client3 = new HidAmicoClient(reader);
55737
55853
  try {
55738
- await client2.login();
55739
- const response = await client2.loadObjects({
55854
+ await client3.login();
55855
+ const response = await client3.loadObjects({
55740
55856
  object: "pins",
55741
55857
  where: { pins: { user_id: hidUserId } },
55742
55858
  limit: 1,
@@ -55744,7 +55860,7 @@ function useHidAmicoService() {
55744
55860
  });
55745
55861
  return { readerId, hidUserId, pinEnrolled: getHidObjectRows(response, "pins").length > 0 };
55746
55862
  } finally {
55747
- await client2.logout();
55863
+ await client3.logout();
55748
55864
  }
55749
55865
  }
55750
55866
  async function setUserPin(readerId, hidUserIdValue, pin) {
@@ -55752,10 +55868,10 @@ function useHidAmicoService() {
55752
55868
  assertReaderCapability(reader, "pin");
55753
55869
  const hidUserId = Number(hidUserIdValue);
55754
55870
  const credentialId = createStableHidId(`user-pin:${readerId}:${hidUserId}`);
55755
- const client2 = new HidAmicoClient(reader);
55871
+ const client3 = new HidAmicoClient(reader);
55756
55872
  try {
55757
- await client2.login();
55758
- const userResponse = await client2.loadObjects({
55873
+ await client3.login();
55874
+ const userResponse = await client3.loadObjects({
55759
55875
  object: "users",
55760
55876
  where: { users: { id: hidUserId } },
55761
55877
  limit: 1,
@@ -55765,13 +55881,13 @@ function useHidAmicoService() {
55765
55881
  throw new BadRequestError126("HID user must exist before assigning an access PIN.");
55766
55882
  }
55767
55883
  const [byUserResponse, byValueResponse] = await Promise.all([
55768
- client2.loadObjects({
55884
+ client3.loadObjects({
55769
55885
  object: "pins",
55770
55886
  where: { pins: { user_id: hidUserId } },
55771
55887
  limit: 10,
55772
55888
  offset: 0
55773
55889
  }),
55774
- client2.loadObjects({
55890
+ client3.loadObjects({
55775
55891
  object: "pins",
55776
55892
  where: { pins: { value: pin } },
55777
55893
  limit: 10,
@@ -55787,18 +55903,18 @@ function useHidAmicoService() {
55787
55903
  }
55788
55904
  const existingPin = existingPins[0];
55789
55905
  if (existingPin) {
55790
- await client2.modifyObjects({
55906
+ await client3.modifyObjects({
55791
55907
  object: "pins",
55792
55908
  where: { pins: { id: existingPin.id } },
55793
55909
  values: { value: pin, user_id: hidUserId }
55794
55910
  });
55795
55911
  } else {
55796
- await client2.createObjects({
55912
+ await client3.createObjects({
55797
55913
  object: "pins",
55798
55914
  values: [{ id: credentialId, value: pin, user_id: hidUserId }]
55799
55915
  });
55800
55916
  }
55801
- const savedResponse = await client2.loadObjects({
55917
+ const savedResponse = await client3.loadObjects({
55802
55918
  object: "pins",
55803
55919
  where: { pins: { user_id: hidUserId } },
55804
55920
  limit: 1,
@@ -55808,7 +55924,7 @@ function useHidAmicoService() {
55808
55924
  if (!savedPin || String(savedPin.value) !== pin) {
55809
55925
  throw new BadRequestError126("The HID reader did not retain the access PIN.");
55810
55926
  }
55811
- await client2.setConfiguration({
55927
+ await client3.setConfiguration({
55812
55928
  identifier: {
55813
55929
  pin_identification_enabled: "1",
55814
55930
  multi_factor_authentication: "0"
@@ -55832,17 +55948,17 @@ function useHidAmicoService() {
55832
55948
  });
55833
55949
  throw error;
55834
55950
  } finally {
55835
- await client2.logout();
55951
+ await client3.logout();
55836
55952
  }
55837
55953
  }
55838
55954
  async function deleteUserPin(readerId, hidUserIdValue) {
55839
55955
  const reader = await getActiveReader(readerId);
55840
55956
  assertReaderCapability(reader, "pin");
55841
55957
  const hidUserId = Number(hidUserIdValue);
55842
- const client2 = new HidAmicoClient(reader);
55958
+ const client3 = new HidAmicoClient(reader);
55843
55959
  try {
55844
- await client2.login();
55845
- await client2.destroyObjects({
55960
+ await client3.login();
55961
+ await client3.destroyObjects({
55846
55962
  object: "pins",
55847
55963
  where: { pins: { user_id: hidUserId } }
55848
55964
  });
@@ -55864,7 +55980,7 @@ function useHidAmicoService() {
55864
55980
  });
55865
55981
  throw error;
55866
55982
  } finally {
55867
- await client2.logout();
55983
+ await client3.logout();
55868
55984
  }
55869
55985
  }
55870
55986
  async function revokeVisitorQr(readerId, visitorId) {
@@ -55876,44 +55992,44 @@ function useHidAmicoService() {
55876
55992
  "The generated HID user ID is assigned to another visitor."
55877
55993
  );
55878
55994
  }
55879
- const client2 = new HidAmicoClient(reader);
55995
+ const client3 = new HidAmicoClient(reader);
55880
55996
  try {
55881
- await client2.login();
55882
- const existingUserResponse = await client2.loadObjects({
55997
+ await client3.login();
55998
+ const existingUserResponse = await client3.loadObjects({
55883
55999
  object: "users",
55884
56000
  where: { users: { id: hidUserId } },
55885
56001
  limit: 1,
55886
56002
  offset: 0
55887
56003
  });
55888
56004
  const deviceUserExists = getHidObjectRows(existingUserResponse, "users").length > 0;
55889
- await client2.destroyObjects({
56005
+ await client3.destroyObjects({
55890
56006
  object: "qrcodes",
55891
56007
  where: { qrcodes: { user_id: hidUserId } }
55892
56008
  });
55893
- await client2.destroyObjects({
56009
+ await client3.destroyObjects({
55894
56010
  object: "cards",
55895
56011
  where: { cards: { user_id: hidUserId } }
55896
56012
  });
55897
56013
  if (reader.capabilities?.pin === true) {
55898
- await client2.destroyObjects({
56014
+ await client3.destroyObjects({
55899
56015
  object: "pins",
55900
56016
  where: { pins: { user_id: hidUserId } }
55901
56017
  });
55902
56018
  }
55903
- await client2.destroyObjects({
56019
+ await client3.destroyObjects({
55904
56020
  object: "user_access_rules",
55905
56021
  where: { user_access_rules: { user_id: hidUserId } }
55906
56022
  });
55907
- await client2.destroyObjects({
56023
+ await client3.destroyObjects({
55908
56024
  object: "user_groups",
55909
56025
  where: { user_groups: { user_id: hidUserId } }
55910
56026
  });
55911
56027
  const metadata = identity && isUnknownRecord2(identity.metadata) ? identity.metadata : {};
55912
56028
  if (deviceUserExists && metadata.facialEnrolled === true) {
55913
- await client2.deleteUserImage(hidUserId);
56029
+ await client3.deleteUserImage(hidUserId);
55914
56030
  }
55915
56031
  if (deviceUserExists) {
55916
- await client2.modifyObjects({
56032
+ await client3.modifyObjects({
55917
56033
  object: "users",
55918
56034
  where: { users: { id: hidUserId } },
55919
56035
  values: { end_time: Math.floor(Date.now() / 1e3) }
@@ -55924,7 +56040,7 @@ function useHidAmicoService() {
55924
56040
  if (reader.capabilities?.pin === true)
55925
56041
  credentialObjects.push("pins");
55926
56042
  for (const object of credentialObjects) {
55927
- const response = await client2.loadObjects({
56043
+ const response = await client3.loadObjects({
55928
56044
  object,
55929
56045
  where: { [object]: { user_id: hidUserId } },
55930
56046
  limit: 1,
@@ -55932,7 +56048,7 @@ function useHidAmicoService() {
55932
56048
  });
55933
56049
  credentialRemains || (credentialRemains = getHidObjectRows(response, object).length > 0);
55934
56050
  }
55935
- const savedUser = await client2.loadObjects({
56051
+ const savedUser = await client3.loadObjects({
55936
56052
  object: "users",
55937
56053
  where: { users: { id: hidUserId } },
55938
56054
  limit: 1,
@@ -55970,7 +56086,7 @@ function useHidAmicoService() {
55970
56086
  });
55971
56087
  throw error;
55972
56088
  } finally {
55973
- await client2.logout();
56089
+ await client3.logout();
55974
56090
  }
55975
56091
  }
55976
56092
  async function queueVisitorQrJob(readerId, visitorId, operation) {
@@ -56080,16 +56196,16 @@ function useHidAmicoService() {
56080
56196
  const reader = await getActiveReader(readerId);
56081
56197
  assertReaderCapability(reader, "facial");
56082
56198
  assertReaderPortal(reader, "enrolling facial recognition");
56083
- const client2 = new HidAmicoClient(reader);
56199
+ const client3 = new HidAmicoClient(reader);
56084
56200
  const timestamp = options.timestamp || Math.floor(Date.now() / 1e3);
56085
56201
  const match = options.match ?? true;
56086
56202
  try {
56087
- await client2.login();
56203
+ await client3.login();
56088
56204
  const numericUserId = Number(hidUserId);
56089
56205
  if (!Number.isSafeInteger(numericUserId) || numericUserId <= 0) {
56090
56206
  throw new BadRequestError126("A valid HID user ID is required for facial enrollment.");
56091
56207
  }
56092
- const result = await client2.setUserImage(numericUserId, image, timestamp, match);
56208
+ const result = await client3.setUserImage(numericUserId, image, timestamp, match);
56093
56209
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56094
56210
  await repo.addEvent({
56095
56211
  reader: readerId,
@@ -56113,16 +56229,16 @@ function useHidAmicoService() {
56113
56229
  });
56114
56230
  throw error;
56115
56231
  } finally {
56116
- await client2.logout();
56232
+ await client3.logout();
56117
56233
  }
56118
56234
  }
56119
56235
  async function deleteUserImage(readerId, hidUserId) {
56120
56236
  const reader = await getActiveReader(readerId);
56121
56237
  assertReaderCapability(reader, "facial");
56122
- const client2 = new HidAmicoClient(reader);
56238
+ const client3 = new HidAmicoClient(reader);
56123
56239
  try {
56124
- await client2.login();
56125
- const result = await client2.deleteUserImage(hidUserId);
56240
+ await client3.login();
56241
+ const result = await client3.deleteUserImage(hidUserId);
56126
56242
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56127
56243
  await repo.addEvent({
56128
56244
  reader: readerId,
@@ -56140,28 +56256,28 @@ function useHidAmicoService() {
56140
56256
  });
56141
56257
  throw error;
56142
56258
  } finally {
56143
- await client2.logout();
56259
+ await client3.logout();
56144
56260
  }
56145
56261
  }
56146
56262
  async function getDoorState(id) {
56147
56263
  const reader = await getActiveReader(id);
56148
- const client2 = new HidAmicoClient(reader);
56264
+ const client3 = new HidAmicoClient(reader);
56149
56265
  try {
56150
- await client2.login();
56151
- const state = await client2.doorState();
56266
+ await client3.login();
56267
+ const state = await client3.doorState();
56152
56268
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56153
56269
  await repo.addEvent({ reader: id, site: reader.site, type: "door_state", payload: state });
56154
56270
  return state;
56155
56271
  } finally {
56156
- await client2.logout();
56272
+ await client3.logout();
56157
56273
  }
56158
56274
  }
56159
56275
  async function executeActions(id, actions) {
56160
56276
  const reader = await getActiveReader(id);
56161
- const client2 = new HidAmicoClient(reader);
56277
+ const client3 = new HidAmicoClient(reader);
56162
56278
  try {
56163
- await client2.login();
56164
- const result = await client2.executeActions(actions);
56279
+ await client3.login();
56280
+ const result = await client3.executeActions(actions);
56165
56281
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56166
56282
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions", payload: { actions, result } });
56167
56283
  return result;
@@ -56169,16 +56285,16 @@ function useHidAmicoService() {
56169
56285
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions_failed", payload: { actions, message: getErrorMessage2(error) } });
56170
56286
  throw error;
56171
56287
  } finally {
56172
- await client2.logout();
56288
+ await client3.logout();
56173
56289
  }
56174
56290
  }
56175
56291
  async function getConfiguration(id, payload) {
56176
56292
  assertAllowedHidConfigurationRead(payload);
56177
56293
  const reader = await getActiveReader(id);
56178
- const client2 = new HidAmicoClient(reader);
56294
+ const client3 = new HidAmicoClient(reader);
56179
56295
  try {
56180
- await client2.login();
56181
- const result = await client2.getConfiguration(payload);
56296
+ await client3.login();
56297
+ const result = await client3.getConfiguration(payload);
56182
56298
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56183
56299
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration", payload: { request: payload, result } });
56184
56300
  return sanitizeHidPayload(result);
@@ -56186,7 +56302,7 @@ function useHidAmicoService() {
56186
56302
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56187
56303
  throw error;
56188
56304
  } finally {
56189
- await client2.logout();
56305
+ await client3.logout();
56190
56306
  }
56191
56307
  }
56192
56308
  async function setConfiguration(id, payload) {
@@ -56198,10 +56314,10 @@ function useHidAmicoService() {
56198
56314
  );
56199
56315
  }
56200
56316
  assertAllowedHidConfiguration(payload);
56201
- const client2 = new HidAmicoClient(reader);
56317
+ const client3 = new HidAmicoClient(reader);
56202
56318
  try {
56203
- await client2.login();
56204
- const result = await client2.setConfiguration(payload);
56319
+ await client3.login();
56320
+ const result = await client3.setConfiguration(payload);
56205
56321
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56206
56322
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration", payload: { request: payload, result } });
56207
56323
  return sanitizeHidPayload(result);
@@ -56209,23 +56325,23 @@ function useHidAmicoService() {
56209
56325
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56210
56326
  throw error;
56211
56327
  } finally {
56212
- await client2.logout();
56328
+ await client3.logout();
56213
56329
  }
56214
56330
  }
56215
56331
  async function getIntercomStatus(id) {
56216
56332
  const reader = await getActiveReader(id);
56217
56333
  assertReaderCapability(reader, "intercom");
56218
- const client2 = new HidAmicoClient(reader);
56334
+ const client3 = new HidAmicoClient(reader);
56219
56335
  try {
56220
- await client2.login();
56336
+ await client3.login();
56221
56337
  let result;
56222
56338
  try {
56223
- result = await client2.getSipStatus();
56339
+ result = await client3.getSipStatus();
56224
56340
  } catch (error) {
56225
56341
  if (!isSipStatusUnavailable(error)) {
56226
56342
  throw error;
56227
56343
  }
56228
- const configuration = await client2.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
56344
+ const configuration = await client3.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
56229
56345
  result = buildSipStatusFallback(configuration, error);
56230
56346
  }
56231
56347
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
@@ -56236,16 +56352,16 @@ function useHidAmicoService() {
56236
56352
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_status_failed", payload: { message: getErrorMessage2(error) } });
56237
56353
  throw error;
56238
56354
  } finally {
56239
- await client2.logout();
56355
+ await client3.logout();
56240
56356
  }
56241
56357
  }
56242
56358
  async function makeIntercomCall(id, target) {
56243
56359
  const reader = await getActiveReader(id);
56244
56360
  assertReaderCapability(reader, "intercom");
56245
- const client2 = new HidAmicoClient(reader);
56361
+ const client3 = new HidAmicoClient(reader);
56246
56362
  try {
56247
- await client2.login();
56248
- const result = await client2.makeSipCall(target);
56363
+ await client3.login();
56364
+ const result = await client3.makeSipCall(target);
56249
56365
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56250
56366
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call", payload: { target, result } });
56251
56367
  return result;
@@ -56253,16 +56369,16 @@ function useHidAmicoService() {
56253
56369
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call_failed", payload: { target, message: getErrorMessage2(error) } });
56254
56370
  throw error;
56255
56371
  } finally {
56256
- await client2.logout();
56372
+ await client3.logout();
56257
56373
  }
56258
56374
  }
56259
56375
  async function finalizeIntercomCall(id) {
56260
56376
  const reader = await getActiveReader(id);
56261
56377
  assertReaderCapability(reader, "intercom");
56262
- const client2 = new HidAmicoClient(reader);
56378
+ const client3 = new HidAmicoClient(reader);
56263
56379
  try {
56264
- await client2.login();
56265
- const result = await client2.finalizeSipCall();
56380
+ await client3.login();
56381
+ const result = await client3.finalizeSipCall();
56266
56382
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56267
56383
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup", payload: result || {} });
56268
56384
  return result;
@@ -56270,7 +56386,7 @@ function useHidAmicoService() {
56270
56386
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup_failed", payload: { message: getErrorMessage2(error) } });
56271
56387
  throw error;
56272
56388
  } finally {
56273
- await client2.logout();
56389
+ await client3.logout();
56274
56390
  }
56275
56391
  }
56276
56392
  function normalizePermissionLocation(value) {
@@ -56327,7 +56443,7 @@ function useHidAmicoService() {
56327
56443
  return "contractor";
56328
56444
  return "staff";
56329
56445
  }
56330
- async function provisionPermissionUser(client2, reader, binding) {
56446
+ async function provisionPermissionUser(client3, reader, binding) {
56331
56447
  const readerId = String(reader._id);
56332
56448
  const existingProfile = await repo.findProfileIdentity(readerId, binding.userId);
56333
56449
  const hidUserId = toPositiveInteger(existingProfile?.hidUserId) ?? createStableHidId(`profile:${readerId}:${binding.userId}`);
@@ -56343,7 +56459,7 @@ function useHidAmicoService() {
56343
56459
  throw new BadRequestError126("The reader already uses this HID user ID for an unmanaged Amico user.");
56344
56460
  }
56345
56461
  const name2 = String(binding.name || "iService365 User").trim() || "iService365 User";
56346
- const existingUser = await client2.loadObjects({
56462
+ const existingUser = await client3.loadObjects({
56347
56463
  object: "users",
56348
56464
  where: { users: { id: hidUserId } },
56349
56465
  limit: 1,
@@ -56351,13 +56467,13 @@ function useHidAmicoService() {
56351
56467
  });
56352
56468
  const userValues = { name: name2, registration };
56353
56469
  if (getHidObjectRows(existingUser, "users").length) {
56354
- await client2.modifyObjects({
56470
+ await client3.modifyObjects({
56355
56471
  object: "users",
56356
56472
  where: { users: { id: hidUserId } },
56357
56473
  values: userValues
56358
56474
  });
56359
56475
  } else {
56360
- await client2.createObjects({
56476
+ await client3.createObjects({
56361
56477
  object: "users",
56362
56478
  values: [{ id: hidUserId, ...userValues }]
56363
56479
  });
@@ -56397,14 +56513,14 @@ function useHidAmicoService() {
56397
56513
  const uniqueBindings = [...new Map(
56398
56514
  bindings.map((binding) => [String(binding.userId), binding])
56399
56515
  ).values()];
56400
- const client2 = new HidAmicoClient(reader);
56516
+ const client3 = new HidAmicoClient(reader);
56401
56517
  try {
56402
- await client2.login();
56518
+ await client3.login();
56403
56519
  const uniqueUserIds = await Promise.all(
56404
- uniqueBindings.map((binding) => provisionPermissionUser(client2, reader, binding))
56520
+ uniqueBindings.map((binding) => provisionPermissionUser(client3, reader, binding))
56405
56521
  );
56406
56522
  const result = await reconcileStandaloneGroupAccess(
56407
- client2,
56523
+ client3,
56408
56524
  readerId,
56409
56525
  Number(reader.portalId),
56410
56526
  uniqueUserIds
@@ -56427,7 +56543,7 @@ function useHidAmicoService() {
56427
56543
  });
56428
56544
  throw error;
56429
56545
  } finally {
56430
- await client2.logout();
56546
+ await client3.logout();
56431
56547
  }
56432
56548
  }
56433
56549
  async function reconcileStoredReaderPermissions(readerId) {
@@ -68019,11 +68135,11 @@ function buildingInPlanFrame(building) {
68019
68135
  lifts
68020
68136
  };
68021
68137
  }
68022
- function openRmfDoorDriver(client2, doorName) {
68138
+ function openRmfDoorDriver(client3, doorName) {
68023
68139
  return {
68024
68140
  name: doorName,
68025
68141
  async read() {
68026
- const s = await client2.doorState(doorName).catch((e) => {
68142
+ const s = await client3.doorState(doorName).catch((e) => {
68027
68143
  if (/HTTP 404/.test(String(e?.message)))
68028
68144
  return null;
68029
68145
  throw e;
@@ -68041,13 +68157,13 @@ function openRmfDoorDriver(client2, doorName) {
68041
68157
  if (request2.requestedMode !== DOOR_MODE.OPEN && request2.requestedMode !== DOOR_MODE.CLOSED) {
68042
68158
  throw new OpenRmfError("A door can only be asked to open or close.");
68043
68159
  }
68044
- await client2.doorRequest(doorName, request2.requestedMode);
68160
+ await client3.doorRequest(doorName, request2.requestedMode);
68045
68161
  }
68046
68162
  };
68047
68163
  }
68048
- function openRmfLiftDriver(client2, liftName) {
68164
+ function openRmfLiftDriver(client3, liftName) {
68049
68165
  const destinations = /* @__PURE__ */ new Map();
68050
- const send2 = (requestType, sessionId, destination, doorState) => client2.liftRequest(liftName, {
68166
+ const send2 = (requestType, sessionId, destination, doorState) => client3.liftRequest(liftName, {
68051
68167
  request_type: requestType,
68052
68168
  door_mode: doorState,
68053
68169
  destination,
@@ -68056,7 +68172,7 @@ function openRmfLiftDriver(client2, liftName) {
68056
68172
  return {
68057
68173
  name: liftName,
68058
68174
  async read() {
68059
- const s = await client2.liftState(liftName).catch((e) => {
68175
+ const s = await client3.liftState(liftName).catch((e) => {
68060
68176
  if (/HTTP 404/.test(String(e?.message)))
68061
68177
  return null;
68062
68178
  throw e;
@@ -68092,18 +68208,18 @@ function openRmfLiftDriver(client2, liftName) {
68092
68208
  };
68093
68209
  }
68094
68210
  function createOpenRmfAdapter(options) {
68095
- const client2 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68211
+ const client3 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68096
68212
  fetch: options?.fetch,
68097
68213
  timeoutMs: options?.timeoutMs
68098
68214
  });
68099
68215
  async function states() {
68100
- 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)]);
68101
68217
  return { fleets: fleets ?? [], building };
68102
68218
  }
68103
68219
  async function openInterruptions(taskId) {
68104
68220
  if (!taskId)
68105
68221
  return [];
68106
- const t = await client2.taskState(taskId).catch(() => null);
68222
+ const t = await client3.taskState(taskId).catch(() => null);
68107
68223
  return Object.entries(t?.interruptions ?? {}).filter(([, v]) => !v?.resumed_by).map(([token]) => token);
68108
68224
  }
68109
68225
  async function find(robotSn) {
@@ -68115,7 +68231,7 @@ function createOpenRmfAdapter(options) {
68115
68231
  return s ? { key: key2, s, building } : null;
68116
68232
  }
68117
68233
  return {
68118
- client: client2,
68234
+ client: client3,
68119
68235
  brand: OPEN_RMF_BRAND,
68120
68236
  displayName: OPEN_RMF_DISPLAY_NAME,
68121
68237
  capabilities: OPEN_RMF_CAPABILITIES,
@@ -68142,9 +68258,9 @@ function createOpenRmfAdapter(options) {
68142
68258
  const tokens = await openInterruptions(taskId);
68143
68259
  if (!tokens.length)
68144
68260
  throw new OpenRmfError("This robot's task is not paused.");
68145
- res2 = await client2.resumeTask(taskId, tokens);
68261
+ res2 = await client3.resumeTask(taskId, tokens);
68146
68262
  } else {
68147
- 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);
68148
68264
  }
68149
68265
  if (res2 && res2.success === false)
68150
68266
  throw new OpenRmfError(`The fleet server refused to ${command.kind} the task.`);
@@ -68152,7 +68268,7 @@ function createOpenRmfAdapter(options) {
68152
68268
  }
68153
68269
  const wp = waypointsFor(hit.building, hit.s.location);
68154
68270
  const request2 = taskRequestFor(command, wp.cleaningZones.length ? "cleaning" : "security", wp);
68155
- 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);
68156
68272
  if (!res?.success)
68157
68273
  throw new OpenRmfError("The fleet server did not accept the task.");
68158
68274
  },
@@ -68168,7 +68284,7 @@ function createOpenRmfAdapter(options) {
68168
68284
  const taskId = hit?.s.task_id;
68169
68285
  if (!hit || !taskId)
68170
68286
  return none;
68171
- const t = await client2.taskState(taskId).catch(() => null);
68287
+ const t = await client3.taskState(taskId).catch(() => null);
68172
68288
  if (!t || !/^patrol$/i.test(String(t.category ?? "")))
68173
68289
  return none;
68174
68290
  const level2 = hit.building?.levels.find((l) => l.name === hit.s.location?.map);
@@ -69263,10 +69379,10 @@ function fetchPadbotMqttCredentials(credentials) {
69263
69379
  return createPadbotClient(credentials).call(PADBOT_PATHS.mqttCredentials, {});
69264
69380
  }
69265
69381
  async function listPadbotAlarmsSince(credentials, serials, startTime) {
69266
- const client2 = createPadbotClient(credentials);
69382
+ const client3 = createPadbotClient(credentials);
69267
69383
  const out = [];
69268
69384
  for (let p = 1; p <= 3; p++) {
69269
- 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 });
69270
69386
  out.push(...asList(d));
69271
69387
  if (p >= (Number(d?.totalPages) || 0))
69272
69388
  break;
@@ -74473,16 +74589,16 @@ function useRobotMapController(deps) {
74473
74589
  const config2 = openRmfConfig();
74474
74590
  if (!config2)
74475
74591
  throw new NotFoundError46("Fleet Core is not configured on this server.");
74476
- const client2 = createOpenRmfClient(config2);
74592
+ const client3 = createOpenRmfClient(config2);
74477
74593
  if (value.format === "rmf") {
74478
- const rmf = rmfFromFleetCore(await client2.buildingMap());
74594
+ const rmf = rmfFromFleetCore(await client3.buildingMap());
74479
74595
  res.json({ source: "fleet-core", rmf, summary: rmfSummary(rmf) });
74480
74596
  return;
74481
74597
  }
74482
- const building = buildingInPlanFrame(await client2.buildingMap());
74598
+ const building = buildingInPlanFrame(await client3.buildingMap());
74483
74599
  const [doorStates, liftStates] = await Promise.all([
74484
- Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client2, d.name).read().catch(() => null))),
74485
- 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)))
74486
74602
  ]);
74487
74603
  res.json({
74488
74604
  source: "fleet-core",
@@ -100965,11 +101081,11 @@ function useAuthServiceV2() {
100965
101081
  "Refresh token already used. Please log in again."
100966
101082
  );
100967
101083
  }
100968
- const client2 = useAtlas146.getClient();
100969
- if (!client2) {
101084
+ const client3 = useAtlas146.getClient();
101085
+ if (!client3) {
100970
101086
  throw new InternalServerError86("Unable to connect to server.");
100971
101087
  }
100972
- const dbSession = client2.startSession();
101088
+ const dbSession = client3.startSession();
100973
101089
  let newRefreshToken;
100974
101090
  try {
100975
101091
  dbSession.startTransaction();
@@ -102708,7 +102824,7 @@ function useUserServiceV2() {
102708
102824
  session?.endSession();
102709
102825
  }
102710
102826
  }
102711
- const s32 = new useS33({
102827
+ const s33 = new useS33({
102712
102828
  accessKeyId: SPACES_ACCESS_KEY,
102713
102829
  secretAccessKey: SPACES_SECRET_KEY,
102714
102830
  endpoint: SPACES_ENDPOINT,
@@ -102729,14 +102845,14 @@ function useUserServiceV2() {
102729
102845
  };
102730
102846
  try {
102731
102847
  const id = await createFile(_file, session);
102732
- await s32.uploadObject({
102848
+ await putSpacesObject({
102733
102849
  key: id,
102734
102850
  body: file.buffer,
102735
102851
  contentType: file.mimetype
102736
102852
  });
102737
102853
  if (previousProfile) {
102738
102854
  await deleteFileById(previousProfile, session);
102739
- await s32.deleteObject(previousProfile);
102855
+ await s33.deleteObject(previousProfile);
102740
102856
  }
102741
102857
  await _updateUserFieldById(
102742
102858
  { _id: user, field: "profile", value: id },
@@ -105669,10 +105785,10 @@ function useChatPrelovedService() {
105669
105785
  const { add: _addChat } = useChatPrelovedRepo();
105670
105786
  const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
105671
105787
  async function add(value) {
105672
- const client2 = useAtlas158.getClient();
105673
- if (!client2)
105788
+ const client3 = useAtlas158.getClient();
105789
+ if (!client3)
105674
105790
  throw new InternalServerError96("Unable to connect to server.");
105675
- const session = client2.startSession();
105791
+ const session = client3.startSession();
105676
105792
  session.startTransaction();
105677
105793
  try {
105678
105794
  let channelId = value.channelId;
@@ -106133,14 +106249,14 @@ function useBidPrelovedService() {
106133
106249
  const { add: _addChat } = useChatPrelovedRepo();
106134
106250
  const { updateStatus } = usePostPrelovedRepo();
106135
106251
  async function createBid(value) {
106136
- const client2 = useAtlas161.getClient();
106137
- if (!client2)
106252
+ const client3 = useAtlas161.getClient();
106253
+ if (!client3)
106138
106254
  throw new InternalServerError99("Unable to connect to server.");
106139
106255
  const buyerId = value.buyerId;
106140
106256
  const receiverId = value.receiverId;
106141
106257
  const postId = value.postId;
106142
106258
  const messageText = value.message || "";
106143
- const session = client2.startSession();
106259
+ const session = client3.startSession();
106144
106260
  session.startTransaction();
106145
106261
  try {
106146
106262
  const bidId = await _addBid(value, session);
@@ -108433,8 +108549,8 @@ async function staffOnly(req) {
108433
108549
  }
108434
108550
  async function clientAndSites(org) {
108435
108551
  const d = db2();
108436
- const client2 = await d.collection("organizations").findOne({ _id: new ObjectId201(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
108437
- 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)
108438
108554
  throw new NotFoundError100("Client not found.");
108439
108555
  const own = await d.collection("sites").find({ orgId: both3(org), status: { $ne: "deleted" } }, { projection: { name: 1 } }).toArray();
108440
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();
@@ -108447,7 +108563,7 @@ async function clientAndSites(org) {
108447
108563
  sites.set(id, String(s.name ?? ""));
108448
108564
  }
108449
108565
  return {
108450
- client: { _id: org, name: String(client2.name ?? ""), nature: String(client2.nature ?? "") },
108566
+ client: { _id: org, name: String(client3.name ?? ""), nature: String(client3.nature ?? "") },
108451
108567
  sites: [...sites].map(([_id, name2]) => ({ _id, name: name2 })).sort((a, b) => a.name.localeCompare(b.name))
108452
108568
  };
108453
108569
  }
@@ -108515,14 +108631,14 @@ function useStaffAccessController() {
108515
108631
  const sid = getSessionIdFromRequest(req);
108516
108632
  if (!sid)
108517
108633
  throw new UnauthorizedError28("Not authorized.");
108518
- const { client: client2, sites: list } = await clientAndSites(value.org);
108634
+ const { client: client3, sites: list } = await clientAndSites(value.org);
108519
108635
  const site = value.site ? list.find((s) => s._id === value.site) : null;
108520
108636
  if (value.site && !site)
108521
108637
  throw new BadRequestError273("That site does not belong to this client.");
108522
108638
  const view = {
108523
108639
  user: actor,
108524
- org: client2._id,
108525
- orgName: client2.name,
108640
+ org: client3._id,
108641
+ orgName: client3.name,
108526
108642
  site: site?._id ?? "",
108527
108643
  siteName: site?.name ?? "",
108528
108644
  app: value.app,
@@ -108532,8 +108648,8 @@ function useStaffAccessController() {
108532
108648
  await recordConsoleAction({
108533
108649
  action: "staff-view.entered" /* STAFF_VIEW_ENTERED */,
108534
108650
  actor,
108535
- org: client2._id,
108536
- target: view.site || client2._id,
108651
+ org: client3._id,
108652
+ target: view.site || client3._id,
108537
108653
  targetType: view.site ? "site" /* SITE */ : "organization" /* ORGANIZATION */,
108538
108654
  after: pickAuditFields("staff-view.entered" /* STAFF_VIEW_ENTERED */, { ...view, reason: value.reason }) ?? null
108539
108655
  });
@@ -109809,6 +109925,7 @@ export {
109809
109925
  SERVICE_TYPE_LABELS,
109810
109926
  SITE_STATES_MAX,
109811
109927
  SOFTWARE_VERSION_ENDPOINT,
109928
+ STAFF_CLIENT_PERMISSIONS,
109812
109929
  STAFF_VIEW_APPS,
109813
109930
  STAFF_VIEW_HISTORY_ACTIONS,
109814
109931
  SUBCONTRACT_ADMIN_REFUSAL,
@@ -110424,6 +110541,7 @@ export {
110424
110541
  snapshotRefusalReason,
110425
110542
  splitRobotSn,
110426
110543
  staffMayBypass,
110544
+ staffReachesEveryClient,
110427
110545
  staffViewWriteAudit,
110428
110546
  startDemoTracking,
110429
110547
  startPadbotDrive,