@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.js CHANGED
@@ -344,6 +344,7 @@ __export(src_exports, {
344
344
  SERVICE_TYPE_LABELS: () => SERVICE_TYPE_LABELS,
345
345
  SITE_STATES_MAX: () => SITE_STATES_MAX,
346
346
  SOFTWARE_VERSION_ENDPOINT: () => SOFTWARE_VERSION_ENDPOINT,
347
+ STAFF_CLIENT_PERMISSIONS: () => STAFF_CLIENT_PERMISSIONS,
347
348
  STAFF_VIEW_APPS: () => STAFF_VIEW_APPS,
348
349
  STAFF_VIEW_HISTORY_ACTIONS: () => STAFF_VIEW_HISTORY_ACTIONS,
349
350
  SUBCONTRACT_ADMIN_REFUSAL: () => SUBCONTRACT_ADMIN_REFUSAL,
@@ -959,6 +960,7 @@ __export(src_exports, {
959
960
  snapshotRefusalReason: () => snapshotRefusalReason,
960
961
  splitRobotSn: () => splitRobotSn,
961
962
  staffMayBypass: () => staffMayBypass,
963
+ staffReachesEveryClient: () => staffReachesEveryClient,
962
964
  staffViewWriteAudit: () => staffViewWriteAudit,
963
965
  startDemoTracking: () => startDemoTracking,
964
966
  startPadbotDrive: () => startPadbotDrive,
@@ -5999,6 +6001,100 @@ var import_mongodb17 = require("mongodb");
5999
6001
  // src/utils/super-admin.util.ts
6000
6002
  var import_node_server_utils17 = require("@7365admin1/node-server-utils");
6001
6003
  var import_mongodb16 = require("mongodb");
6004
+
6005
+ // src/utils/console-permission.util.ts
6006
+ var CONSOLE_PERMISSIONS = Object.freeze({
6007
+ organizations: Object.freeze([
6008
+ "see-all-organizations",
6009
+ "see-organization-details"
6010
+ ]),
6011
+ "promo-codes": Object.freeze([
6012
+ "create-promo-code",
6013
+ "see-promo-code-details",
6014
+ "edit-promo-code-details",
6015
+ "change-promo-code-status",
6016
+ "delete-promo-code"
6017
+ ]),
6018
+ users: Object.freeze(["see-all-users", "see-user-details"]),
6019
+ invitations: Object.freeze([
6020
+ "create-invitation",
6021
+ "view-invitations",
6022
+ "cancel-invitation"
6023
+ ]),
6024
+ subscriptions: Object.freeze([
6025
+ "see-all-subscriptions",
6026
+ "see-subscription-details",
6027
+ "manage-subscription"
6028
+ ]),
6029
+ "sp-approvals": Object.freeze([
6030
+ "see-all-sp-approvals",
6031
+ "approve-sp",
6032
+ "reject-sp",
6033
+ "delete-sp-approval"
6034
+ ]),
6035
+ "marketplace-vendors": Object.freeze([
6036
+ "see-all-marketplace-vendors",
6037
+ "see-marketplace-vendor-details"
6038
+ ]),
6039
+ "platform-terms": Object.freeze([
6040
+ "see-platform-terms",
6041
+ "edit-platform-terms"
6042
+ ]),
6043
+ "activity-history": Object.freeze(["see-activity-history"]),
6044
+ members: Object.freeze([
6045
+ "view-members",
6046
+ "assign-member-role",
6047
+ "suspend-member",
6048
+ "activate-member",
6049
+ "delete-member"
6050
+ ]),
6051
+ "roles-and-permissions": Object.freeze([
6052
+ "add-role",
6053
+ "see-all-roles",
6054
+ "see-role-details",
6055
+ "update-role",
6056
+ "delete-role"
6057
+ ])
6058
+ });
6059
+ var RESOURCE_SPELLINGS = Object.freeze({
6060
+ "roles-and-permissions": Object.freeze([
6061
+ "roles-and-permissions",
6062
+ "roles"
6063
+ ]),
6064
+ roles: Object.freeze(["roles", "roles-and-permissions"])
6065
+ });
6066
+ function consoleSpellings(resource, action) {
6067
+ const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
6068
+ return resources.map((name2) => `${name2}:${action}`);
6069
+ }
6070
+ function consoleRoleAllowsAll(held) {
6071
+ if (!Array.isArray(held) || held.length === 0)
6072
+ return true;
6073
+ return held.includes("*");
6074
+ }
6075
+ function consoleRoleAllows(held, resource, action) {
6076
+ if (consoleRoleAllowsAll(held))
6077
+ return true;
6078
+ const actions = CONSOLE_PERMISSIONS[resource];
6079
+ if (!actions?.length)
6080
+ return false;
6081
+ const wanted = action ? actions.includes(action) ? [action] : [] : actions;
6082
+ return wanted.some(
6083
+ (name2) => consoleSpellings(resource, name2).some(
6084
+ (spelling) => held.includes(spelling)
6085
+ )
6086
+ );
6087
+ }
6088
+ var CROSS_CLIENT_GRANT = {
6089
+ resource: "organizations"
6090
+ };
6091
+ function staffMayBypass(actor, grant = CROSS_CLIENT_GRANT) {
6092
+ if (!actor.isSuperAdmin)
6093
+ return false;
6094
+ return consoleRoleAllows(actor.staffPermissions, grant.resource, grant.action);
6095
+ }
6096
+
6097
+ // src/utils/super-admin.util.ts
6002
6098
  var LIVE_ROLE = { status: { $ne: "deleted" } };
6003
6099
  async function resolveStaffRole(userId) {
6004
6100
  const id = userId?.toString() ?? "";
@@ -6038,6 +6134,13 @@ async function isSuperAdmin(userId) {
6038
6134
  async function isPlatformOwner(userId) {
6039
6135
  return (await resolveStaffRole(userId))?.default === true;
6040
6136
  }
6137
+ async function staffReachesEveryClient(userId) {
6138
+ const role = await resolveStaffRole(userId);
6139
+ if (!role)
6140
+ return false;
6141
+ return consoleRoleAllows(role.permissions, "organizations");
6142
+ }
6143
+ var STAFF_CLIENT_PERMISSIONS = Object.freeze(["*"]);
6041
6144
 
6042
6145
  // src/utils/org-suspension.util.ts
6043
6146
  var ORG_SUSPENDED_MESSAGE = "Your organisation's access is currently suspended. Please contact your administrator.";
@@ -6212,11 +6315,11 @@ function useAuthService() {
6212
6315
  "Refresh token already used. Please log in again."
6213
6316
  );
6214
6317
  }
6215
- const client2 = import_node_server_utils19.useAtlas.getClient();
6216
- if (!client2) {
6318
+ const client3 = import_node_server_utils19.useAtlas.getClient();
6319
+ if (!client3) {
6217
6320
  throw new import_node_server_utils19.InternalServerError("Unable to connect to server.");
6218
6321
  }
6219
- const dbSession = client2.startSession();
6322
+ const dbSession = client3.startSession();
6220
6323
  let newRefreshToken;
6221
6324
  try {
6222
6325
  dbSession.startTransaction();
@@ -9273,7 +9376,7 @@ var SP_INVITE_TYPES = [
9273
9376
  function escapeRegex(value) {
9274
9377
  return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9275
9378
  }
9276
- function relationshipMatch(org, relationship, client2) {
9379
+ function relationshipMatch(org, relationship, client3) {
9277
9380
  const self = [org, String(org)];
9278
9381
  const match = {};
9279
9382
  const and = [];
@@ -9282,9 +9385,9 @@ function relationshipMatch(org, relationship, client2) {
9282
9385
  } else if (relationship === "served") {
9283
9386
  and.push({ siteOrg: { $nin: [...self, null, ""] } });
9284
9387
  }
9285
- if (client2) {
9388
+ if (client3) {
9286
9389
  and.push(
9287
- { siteOrg: { $in: [client2, String(client2)] } },
9390
+ { siteOrg: { $in: [client3, String(client3)] } },
9288
9391
  { siteOrg: { $nin: self } }
9289
9392
  );
9290
9393
  }
@@ -9447,7 +9550,7 @@ function useCustomerSiteRepo() {
9447
9550
  status = "active",
9448
9551
  siteScope = null,
9449
9552
  relationship = "",
9450
- client: client2 = "",
9553
+ client: client3 = "",
9451
9554
  category = ""
9452
9555
  }, session) {
9453
9556
  page2 = page2 > 0 ? page2 - 1 : 0;
@@ -9461,9 +9564,9 @@ function useCustomerSiteRepo() {
9461
9564
  status
9462
9565
  };
9463
9566
  let clientId = null;
9464
- if (client2) {
9567
+ if (client3) {
9465
9568
  try {
9466
- clientId = new import_mongodb26.ObjectId(client2);
9569
+ clientId = new import_mongodb26.ObjectId(client3);
9467
9570
  } catch (error) {
9468
9571
  throw new import_node_server_utils28.BadRequestError("Invalid client ID format.");
9469
9572
  }
@@ -9486,8 +9589,8 @@ function useCustomerSiteRepo() {
9486
9589
  }
9487
9590
  if (relationship)
9488
9591
  cacheOptions.relationship = relationship;
9489
- if (client2)
9490
- cacheOptions.client = client2;
9592
+ if (client3)
9593
+ cacheOptions.client = client3;
9491
9594
  if (category)
9492
9595
  cacheOptions.category = category;
9493
9596
  const cacheKey = (0, import_node_server_utils28.makeCacheKey)(namespace_collection3, cacheOptions);
@@ -12311,98 +12414,6 @@ async function recordConsoleAction(entry) {
12311
12414
  }
12312
12415
  }
12313
12416
 
12314
- // src/utils/console-permission.util.ts
12315
- var CONSOLE_PERMISSIONS = Object.freeze({
12316
- organizations: Object.freeze([
12317
- "see-all-organizations",
12318
- "see-organization-details"
12319
- ]),
12320
- "promo-codes": Object.freeze([
12321
- "create-promo-code",
12322
- "see-promo-code-details",
12323
- "edit-promo-code-details",
12324
- "change-promo-code-status",
12325
- "delete-promo-code"
12326
- ]),
12327
- users: Object.freeze(["see-all-users", "see-user-details"]),
12328
- invitations: Object.freeze([
12329
- "create-invitation",
12330
- "view-invitations",
12331
- "cancel-invitation"
12332
- ]),
12333
- subscriptions: Object.freeze([
12334
- "see-all-subscriptions",
12335
- "see-subscription-details",
12336
- "manage-subscription"
12337
- ]),
12338
- "sp-approvals": Object.freeze([
12339
- "see-all-sp-approvals",
12340
- "approve-sp",
12341
- "reject-sp",
12342
- "delete-sp-approval"
12343
- ]),
12344
- "marketplace-vendors": Object.freeze([
12345
- "see-all-marketplace-vendors",
12346
- "see-marketplace-vendor-details"
12347
- ]),
12348
- "platform-terms": Object.freeze([
12349
- "see-platform-terms",
12350
- "edit-platform-terms"
12351
- ]),
12352
- "activity-history": Object.freeze(["see-activity-history"]),
12353
- members: Object.freeze([
12354
- "view-members",
12355
- "assign-member-role",
12356
- "suspend-member",
12357
- "activate-member",
12358
- "delete-member"
12359
- ]),
12360
- "roles-and-permissions": Object.freeze([
12361
- "add-role",
12362
- "see-all-roles",
12363
- "see-role-details",
12364
- "update-role",
12365
- "delete-role"
12366
- ])
12367
- });
12368
- var RESOURCE_SPELLINGS = Object.freeze({
12369
- "roles-and-permissions": Object.freeze([
12370
- "roles-and-permissions",
12371
- "roles"
12372
- ]),
12373
- roles: Object.freeze(["roles", "roles-and-permissions"])
12374
- });
12375
- function consoleSpellings(resource, action) {
12376
- const resources = RESOURCE_SPELLINGS[resource] ?? [resource];
12377
- return resources.map((name2) => `${name2}:${action}`);
12378
- }
12379
- function consoleRoleAllowsAll(held) {
12380
- if (!Array.isArray(held) || held.length === 0)
12381
- return true;
12382
- return held.includes("*");
12383
- }
12384
- function consoleRoleAllows(held, resource, action) {
12385
- if (consoleRoleAllowsAll(held))
12386
- return true;
12387
- const actions = CONSOLE_PERMISSIONS[resource];
12388
- if (!actions?.length)
12389
- return false;
12390
- const wanted = action ? actions.includes(action) ? [action] : [] : actions;
12391
- return wanted.some(
12392
- (name2) => consoleSpellings(resource, name2).some(
12393
- (spelling) => held.includes(spelling)
12394
- )
12395
- );
12396
- }
12397
- var CROSS_CLIENT_GRANT = {
12398
- resource: "organizations"
12399
- };
12400
- function staffMayBypass(actor, grant = CROSS_CLIENT_GRANT) {
12401
- if (!actor.isSuperAdmin)
12402
- return false;
12403
- return consoleRoleAllows(actor.staffPermissions, grant.resource, grant.action);
12404
- }
12405
-
12406
12417
  // src/services/module-gate.service.ts
12407
12418
  var idOf4 = (v) => v == null ? "" : String(v?._id ?? v).toLowerCase();
12408
12419
  var isId = (v) => /^[0-9a-f]{24}$/i.test(v);
@@ -19119,6 +19130,76 @@ function useVehicleRepo() {
19119
19130
  };
19120
19131
  }
19121
19132
 
19133
+ // src/services/spaces-object.service.ts
19134
+ var import_client_s3 = require("@aws-sdk/client-s3");
19135
+
19136
+ // src/utils/spaces-object.util.ts
19137
+ function spacesUploadAcl(key2, setting = process.env.SPACES_PRIVATE_PREFIXES ?? "") {
19138
+ const prefixes = String(setting).split(",").map((p) => p.trim()).filter(Boolean);
19139
+ if (prefixes.includes("*"))
19140
+ return "private";
19141
+ return prefixes.some((p) => String(key2).startsWith(p)) ? "private" : "public-read";
19142
+ }
19143
+ var KEY = /^(?:[A-Za-z0-9_-]{1,64}\/){0,4}[a-f0-9]{24}$/;
19144
+ function isServableObjectKey(key2) {
19145
+ return typeof key2 === "string" && KEY.test(key2);
19146
+ }
19147
+ function anprSiteOfKey(key2) {
19148
+ const m = /^anpr\/([a-f0-9]{24})\//.exec(key2);
19149
+ return m ? m[1] : null;
19150
+ }
19151
+ var INLINE_TYPES = /^(image\/(jpeg|png|gif|webp|heic|heif|bmp)|application\/pdf|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|webm|ogg))$/;
19152
+ function servedObjectHeaders(contentType) {
19153
+ const type = String(contentType ?? "").split(";")[0].trim().toLowerCase();
19154
+ const inline = INLINE_TYPES.test(type);
19155
+ return {
19156
+ "Content-Type": inline ? type : "application/octet-stream",
19157
+ "Content-Disposition": inline ? "inline" : "attachment",
19158
+ "X-Content-Type-Options": "nosniff",
19159
+ "Content-Security-Policy": "default-src 'none'; sandbox",
19160
+ "Cache-Control": "private, max-age=300"
19161
+ };
19162
+ }
19163
+
19164
+ // src/services/spaces-object.service.ts
19165
+ var client = null;
19166
+ function s3() {
19167
+ if (!client) {
19168
+ client = new import_client_s3.S3Client({
19169
+ endpoint: SPACES_ENDPOINT,
19170
+ region: SPACES_REGION,
19171
+ credentials: { accessKeyId: SPACES_ACCESS_KEY, secretAccessKey: SPACES_SECRET_KEY },
19172
+ forcePathStyle: true
19173
+ });
19174
+ }
19175
+ return client;
19176
+ }
19177
+ async function putSpacesObject({
19178
+ key: key2,
19179
+ body,
19180
+ contentType
19181
+ }) {
19182
+ await s3().send(
19183
+ new import_client_s3.PutObjectCommand({
19184
+ Bucket: SPACES_BUCKET,
19185
+ Key: key2,
19186
+ Body: body,
19187
+ ACL: spacesUploadAcl(key2),
19188
+ ContentType: contentType,
19189
+ ContentLength: body.length
19190
+ })
19191
+ );
19192
+ return "Successfully uploaded file.";
19193
+ }
19194
+ async function getSpacesObject(key2) {
19195
+ const res = await s3().send(new import_client_s3.GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 }));
19196
+ return {
19197
+ body: res.Body,
19198
+ contentType: res.ContentType,
19199
+ contentLength: res.ContentLength
19200
+ };
19201
+ }
19202
+
19122
19203
  // src/repositories/file.repo.ts
19123
19204
  var import_node_server_utils52 = require("@7365admin1/node-server-utils");
19124
19205
 
@@ -19298,7 +19379,7 @@ function useFileService() {
19298
19379
  deleteFileById,
19299
19380
  getAllDraftedFiles
19300
19381
  } = useFileRepo();
19301
- const s32 = new import_node_server_utils53.useS3({
19382
+ const s33 = new import_node_server_utils53.useS3({
19302
19383
  accessKeyId: SPACES_ACCESS_KEY,
19303
19384
  secretAccessKey: SPACES_SECRET_KEY,
19304
19385
  endpoint: SPACES_ENDPOINT,
@@ -19317,7 +19398,7 @@ function useFileService() {
19317
19398
  };
19318
19399
  try {
19319
19400
  const id = await _createFile(file, session);
19320
- await s32.uploadObject({
19401
+ await putSpacesObject({
19321
19402
  key: `${folder}/${id}`,
19322
19403
  body: value.buffer,
19323
19404
  contentType: value.mimetype
@@ -19336,7 +19417,7 @@ function useFileService() {
19336
19417
  session?.startTransaction();
19337
19418
  try {
19338
19419
  await deleteFileById(id, session);
19339
- await s32.deleteObject(id);
19420
+ await s33.deleteObject(id);
19340
19421
  await session?.commitTransaction();
19341
19422
  return "File deleted successfully.";
19342
19423
  } catch (error) {
@@ -23291,6 +23372,9 @@ async function getUserPermissions(params) {
23291
23372
  if (!db3) {
23292
23373
  return [];
23293
23374
  }
23375
+ if (await staffReachesEveryClient(user)) {
23376
+ return [...STAFF_CLIENT_PERMISSIONS];
23377
+ }
23294
23378
  let roleId = grantingRole;
23295
23379
  let memberSite = params.memberSite;
23296
23380
  let memberId;
@@ -23431,6 +23515,12 @@ function useCameraViewService() {
23431
23515
  engagedOrgs,
23432
23516
  prefer: params.prefer
23433
23517
  });
23518
+ if (!grant && await staffReachesEveryClient(params.userId)) {
23519
+ return {
23520
+ memberships,
23521
+ grant: { org: params.site?.orgId ?? params.site?.org, siteId: params.siteObjectId }
23522
+ };
23523
+ }
23434
23524
  return { memberships, grant };
23435
23525
  }
23436
23526
  async function permissionsForGrant(userId, grant, memberships) {
@@ -26272,7 +26362,7 @@ function useServiceProviderInviteService() {
26272
26362
  const runs = import_mongodb57.ObjectId.isValid(id) && actor.memberships.some(
26273
26363
  (m) => m.org === id && (m.companyWideRole === true || !m.siteId && m.orgLevelRole === true)
26274
26364
  );
26275
- if (!runs) {
26365
+ if (!runs && !staffMayBypass(actor)) {
26276
26366
  throw new import_node_server_utils62.UnauthorizedError(
26277
26367
  "Only an administrator of that company can answer this invitation for it."
26278
26368
  );
@@ -27277,7 +27367,7 @@ function useUserService() {
27277
27367
  session?.endSession();
27278
27368
  }
27279
27369
  }
27280
- const s32 = new import_node_server_utils64.useS3({
27370
+ const s33 = new import_node_server_utils64.useS3({
27281
27371
  accessKeyId: SPACES_ACCESS_KEY,
27282
27372
  secretAccessKey: SPACES_SECRET_KEY,
27283
27373
  endpoint: SPACES_ENDPOINT,
@@ -27298,14 +27388,14 @@ function useUserService() {
27298
27388
  };
27299
27389
  try {
27300
27390
  const id = await createFile(_file, session);
27301
- await s32.uploadObject({
27391
+ await putSpacesObject({
27302
27392
  key: id,
27303
27393
  body: file.buffer,
27304
27394
  contentType: file.mimetype
27305
27395
  });
27306
27396
  if (previousProfile) {
27307
27397
  await deleteFileById(previousProfile, session);
27308
- await s32.deleteObject(previousProfile);
27398
+ await s33.deleteObject(previousProfile);
27309
27399
  }
27310
27400
  await _updateUserFieldById(
27311
27401
  { _id: user, field: "profile", value: id },
@@ -31409,10 +31499,38 @@ function useFileController() {
31409
31499
  next(error2);
31410
31500
  }
31411
31501
  }
31502
+ async function viewObject(req, res, next) {
31503
+ const key2 = String(req.params?.[0] ?? "");
31504
+ if (!isServableObjectKey(key2)) {
31505
+ res.status(404).json({ message: "File not found." });
31506
+ return;
31507
+ }
31508
+ try {
31509
+ const site = anprSiteOfKey(key2);
31510
+ if (site)
31511
+ await requireSiteReach(req, site);
31512
+ const object = await getSpacesObject(key2);
31513
+ res.set(servedObjectHeaders(object.contentType));
31514
+ if (object.contentLength)
31515
+ res.set("Content-Length", String(object.contentLength));
31516
+ object.body.pipe(res);
31517
+ return;
31518
+ } catch (error) {
31519
+ const status = error?.$metadata?.httpStatusCode ?? error?.statusCode ?? error?.status;
31520
+ if (status === 404 || status === 403 || error?.name === "NoSuchKey" || error?.name === "NotFoundError") {
31521
+ res.status(404).json({ message: "File not found." });
31522
+ return;
31523
+ }
31524
+ import_node_server_utils78.logger.log({ level: "error", message: error?.message });
31525
+ next(error);
31526
+ return;
31527
+ }
31528
+ }
31412
31529
  return {
31413
31530
  upload,
31414
31531
  deleteFile,
31415
- getFileById
31532
+ getFileById,
31533
+ viewObject
31416
31534
  };
31417
31535
  }
31418
31536
 
@@ -37572,8 +37690,8 @@ function useServiceProviderController() {
37572
37690
  if (siteId)
37573
37691
  await requireSiteReach(req, siteId);
37574
37692
  const engagements = req.query.include === "engagements" && siteId && status === "active" && !orgId && !serviceProviderOrgId;
37575
- const client2 = engagements ? await isSiteClient(req, siteId) : false;
37576
- const data = client2 ? await _getServiceProvidersForSite({ search, page: page2, limit, siteId }) : engagements ? (
37693
+ const client3 = engagements ? await isSiteClient(req, siteId) : false;
37694
+ const data = client3 ? await _getServiceProvidersForSite({ search, page: page2, limit, siteId }) : engagements ? (
37577
37695
  // A provider's own Service Providers page: the subcontractors it
37578
37696
  // brought onto this site, never the client's other contractors,
37579
37697
  // plus the stored rows it already saw here.
@@ -47235,7 +47353,7 @@ function useCustomerSiteController() {
47235
47353
  const org = req.query.org ?? "";
47236
47354
  const status = req.query.status ?? "active";
47237
47355
  const relationship = req.query.relationship || "";
47238
- const client2 = req.query.client || "";
47356
+ const client3 = req.query.client || "";
47239
47357
  const category = req.query.category || "";
47240
47358
  const sortObj = {};
47241
47359
  const sortFields = String(req.query.sort).split(",");
@@ -47258,7 +47376,7 @@ function useCustomerSiteController() {
47258
47376
  status,
47259
47377
  siteScope,
47260
47378
  relationship,
47261
- client: client2,
47379
+ client: client3,
47262
47380
  category
47263
47381
  });
47264
47382
  res.json(data);
@@ -48547,12 +48665,12 @@ function useAttendanceService() {
48547
48665
  }
48548
48666
 
48549
48667
  // src/services/attendance-photo.service.ts
48550
- var import_client_s3 = require("@aws-sdk/client-s3");
48668
+ var import_client_s32 = require("@aws-sdk/client-s3");
48551
48669
  var ATTENDANCE_PHOTO_FOLDER = "attendance-private";
48552
- var client = null;
48553
- function s3() {
48554
- if (!client) {
48555
- client = new import_client_s3.S3Client({
48670
+ var client2 = null;
48671
+ function s32() {
48672
+ if (!client2) {
48673
+ client2 = new import_client_s32.S3Client({
48556
48674
  endpoint: SPACES_ENDPOINT,
48557
48675
  region: SPACES_REGION,
48558
48676
  credentials: {
@@ -48562,12 +48680,12 @@ function s3() {
48562
48680
  forcePathStyle: true
48563
48681
  });
48564
48682
  }
48565
- return client;
48683
+ return client2;
48566
48684
  }
48567
48685
  var s3AttendancePhotoStore = {
48568
48686
  async put(key2, body, contentType) {
48569
- await s3().send(
48570
- new import_client_s3.PutObjectCommand({
48687
+ await s32().send(
48688
+ new import_client_s32.PutObjectCommand({
48571
48689
  Bucket: SPACES_BUCKET,
48572
48690
  Key: key2,
48573
48691
  Body: body,
@@ -48578,8 +48696,8 @@ var s3AttendancePhotoStore = {
48578
48696
  );
48579
48697
  },
48580
48698
  async get(key2) {
48581
- const res = await s3().send(
48582
- new import_client_s3.GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 })
48699
+ const res = await s32().send(
48700
+ new import_client_s32.GetObjectCommand({ Bucket: SPACES_BUCKET, Key: key2 })
48583
48701
  );
48584
48702
  const bytes = await res.Body.transformToByteArray();
48585
48703
  return { body: Buffer.from(bytes), contentType: res.ContentType };
@@ -53140,20 +53258,20 @@ function createVisitorQrCredential(visitorId, readerId, qrValue) {
53140
53258
  const token = qrValue || `VIS${import_crypto4.default.randomBytes(12).toString("hex").toUpperCase()}`;
53141
53259
  return { credentialId, object: "qrcodes", value: token, qrValue: token };
53142
53260
  }
53143
- async function configureVisitorQrReader(client2) {
53261
+ async function configureVisitorQrReader(client3) {
53144
53262
  const requestedConfiguration = {
53145
53263
  general: ["online", "local_identification"],
53146
53264
  face_id: ["qrcode_legacy_mode_enabled"],
53147
53265
  identifier: ["qrcode_identification_enabled", "multi_factor_authentication"]
53148
53266
  };
53149
- const currentConfiguration = await client2.getConfiguration(requestedConfiguration);
53267
+ const currentConfiguration = await client3.getConfiguration(requestedConfiguration);
53150
53268
  const current = isUnknownRecord2(currentConfiguration) ? currentConfiguration : {};
53151
53269
  const currentGeneral = isUnknownRecord2(current.general) ? current.general : {};
53152
53270
  const currentFaceId = isUnknownRecord2(current.face_id) ? current.face_id : {};
53153
53271
  const currentIdentifier = isUnknownRecord2(current.identifier) ? current.identifier : {};
53154
53272
  let changed = false;
53155
53273
  if (String(currentGeneral.online ?? "") !== "0" || String(currentGeneral.local_identification ?? "") !== "1") {
53156
- await client2.setConfiguration({
53274
+ await client3.setConfiguration({
53157
53275
  general: {
53158
53276
  online: "0",
53159
53277
  local_identification: "1"
@@ -53162,13 +53280,13 @@ async function configureVisitorQrReader(client2) {
53162
53280
  changed = true;
53163
53281
  }
53164
53282
  if (String(currentFaceId.qrcode_legacy_mode_enabled ?? "") !== VISITOR_QR_FORMAT) {
53165
- await client2.setConfiguration({
53283
+ await client3.setConfiguration({
53166
53284
  face_id: { qrcode_legacy_mode_enabled: VISITOR_QR_FORMAT }
53167
53285
  });
53168
53286
  changed = true;
53169
53287
  }
53170
53288
  if (String(currentIdentifier.qrcode_identification_enabled ?? "") !== "1" || String(currentIdentifier.multi_factor_authentication ?? "") !== "0") {
53171
- await client2.setConfiguration({
53289
+ await client3.setConfiguration({
53172
53290
  identifier: {
53173
53291
  qrcode_identification_enabled: "1",
53174
53292
  // A visitor pass is a single QR credential. Leaving MFA enabled makes
@@ -53178,7 +53296,7 @@ async function configureVisitorQrReader(client2) {
53178
53296
  });
53179
53297
  changed = true;
53180
53298
  }
53181
- const configuration = await client2.getConfiguration(requestedConfiguration);
53299
+ const configuration = await client3.getConfiguration(requestedConfiguration);
53182
53300
  const savedConfiguration = isUnknownRecord2(configuration) ? configuration : {};
53183
53301
  const general = isUnknownRecord2(savedConfiguration.general) ? savedConfiguration.general : {};
53184
53302
  const faceId = isUnknownRecord2(savedConfiguration.face_id) ? savedConfiguration.face_id : {};
@@ -53190,7 +53308,7 @@ async function configureVisitorQrReader(client2) {
53190
53308
  }
53191
53309
  return changed;
53192
53310
  }
53193
- async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUserId, scope = "visitor") {
53311
+ async function ensureVisitorAccessAuthorization(client3, readerId, reader, hidUserId, scope = "visitor") {
53194
53312
  const accessLabel = scope === "visitor" ? "Visitor" : "Facial";
53195
53313
  const accessRuleId = createStableHidId(`${scope}-access-rule:${readerId}`);
53196
53314
  const timeZoneId = createStableHidId(`${scope}-time-zone:${readerId}`);
@@ -53200,25 +53318,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53200
53318
  type: 1,
53201
53319
  priority: 0
53202
53320
  };
53203
- const existingRuleResponse = await client2.loadObjects({
53321
+ const existingRuleResponse = await client3.loadObjects({
53204
53322
  object: "access_rules",
53205
53323
  where: { access_rules: { id: accessRuleId } },
53206
53324
  limit: 1,
53207
53325
  offset: 0
53208
53326
  });
53209
53327
  if (getHidObjectRows(existingRuleResponse, "access_rules").length) {
53210
- await client2.modifyObjects({
53328
+ await client3.modifyObjects({
53211
53329
  object: "access_rules",
53212
53330
  where: { access_rules: { id: accessRuleId } },
53213
53331
  values: accessRuleValues
53214
53332
  });
53215
53333
  } else {
53216
- await client2.createObjects({
53334
+ await client3.createObjects({
53217
53335
  object: "access_rules",
53218
53336
  values: [{ id: accessRuleId, ...accessRuleValues }]
53219
53337
  });
53220
53338
  }
53221
- const verifiedAccessRuleResponse = await client2.loadObjects({
53339
+ const verifiedAccessRuleResponse = await client3.loadObjects({
53222
53340
  object: "access_rules",
53223
53341
  where: { access_rules: { id: accessRuleId } },
53224
53342
  limit: 1,
@@ -53232,20 +53350,20 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53232
53350
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
53233
53351
  );
53234
53352
  }
53235
- const existingTimeZoneResponse = await client2.loadObjects({
53353
+ const existingTimeZoneResponse = await client3.loadObjects({
53236
53354
  object: "time_zones",
53237
53355
  where: { time_zones: { id: timeZoneId } },
53238
53356
  limit: 1,
53239
53357
  offset: 0
53240
53358
  });
53241
53359
  if (getHidObjectRows(existingTimeZoneResponse, "time_zones").length) {
53242
- await client2.modifyObjects({
53360
+ await client3.modifyObjects({
53243
53361
  object: "time_zones",
53244
53362
  where: { time_zones: { id: timeZoneId } },
53245
53363
  values: { name: `iService365 ${accessLabel} Schedule` }
53246
53364
  });
53247
53365
  } else {
53248
- await client2.createObjects({
53366
+ await client3.createObjects({
53249
53367
  object: "time_zones",
53250
53368
  values: [{ id: timeZoneId, name: `iService365 ${accessLabel} Schedule` }]
53251
53369
  });
@@ -53265,25 +53383,25 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53265
53383
  hol2: 1,
53266
53384
  hol3: 1
53267
53385
  };
53268
- const existingTimeSpanResponse = await client2.loadObjects({
53386
+ const existingTimeSpanResponse = await client3.loadObjects({
53269
53387
  object: "time_spans",
53270
53388
  where: { time_spans: { id: timeSpanId } },
53271
53389
  limit: 1,
53272
53390
  offset: 0
53273
53391
  });
53274
53392
  if (getHidObjectRows(existingTimeSpanResponse, "time_spans").length) {
53275
- await client2.modifyObjects({
53393
+ await client3.modifyObjects({
53276
53394
  object: "time_spans",
53277
53395
  where: { time_spans: { id: timeSpanId } },
53278
53396
  values: visitorTimeSpan
53279
53397
  });
53280
53398
  } else {
53281
- await client2.createObjects({
53399
+ await client3.createObjects({
53282
53400
  object: "time_spans",
53283
53401
  values: [{ id: timeSpanId, ...visitorTimeSpan }]
53284
53402
  });
53285
53403
  }
53286
- const verifiedTimeZoneResponse = await client2.loadObjects({
53404
+ const verifiedTimeZoneResponse = await client3.loadObjects({
53287
53405
  object: "time_zones",
53288
53406
  where: { time_zones: { id: timeZoneId } },
53289
53407
  limit: 1,
@@ -53297,7 +53415,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53297
53415
  "The HID reader did not save the visitor access schedule."
53298
53416
  );
53299
53417
  }
53300
- const verifiedTimeSpanResponse = await client2.loadObjects({
53418
+ const verifiedTimeSpanResponse = await client3.loadObjects({
53301
53419
  object: "time_spans",
53302
53420
  where: { time_spans: { id: timeSpanId } },
53303
53421
  limit: 1,
@@ -53315,7 +53433,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53315
53433
  access_rule_id: accessRuleId,
53316
53434
  time_zone_id: timeZoneId
53317
53435
  };
53318
- const accessRuleTimeZoneResponse = await client2.loadObjects({
53436
+ const accessRuleTimeZoneResponse = await client3.loadObjects({
53319
53437
  object: "access_rule_time_zones",
53320
53438
  where: {
53321
53439
  access_rule_time_zones: {
@@ -53329,12 +53447,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53329
53447
  getHidObjectRows(accessRuleTimeZoneResponse, "access_rule_time_zones"),
53330
53448
  accessRuleTimeZoneValues
53331
53449
  )) {
53332
- await client2.createObjects({
53450
+ await client3.createObjects({
53333
53451
  object: "access_rule_time_zones",
53334
53452
  values: [accessRuleTimeZoneValues]
53335
53453
  });
53336
53454
  }
53337
- const verifiedAccessRuleTimeZoneResponse = await client2.loadObjects({
53455
+ const verifiedAccessRuleTimeZoneResponse = await client3.loadObjects({
53338
53456
  object: "access_rule_time_zones",
53339
53457
  where: { access_rule_time_zones: { access_rule_id: accessRuleId } },
53340
53458
  limit: 100,
@@ -53348,7 +53466,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53348
53466
  "The HID reader did not save the visitor access schedule. Try issuing the QR code again."
53349
53467
  );
53350
53468
  }
53351
- const portalsResponse = await client2.loadObjects({
53469
+ const portalsResponse = await client3.loadObjects({
53352
53470
  object: "portals",
53353
53471
  limit: 100,
53354
53472
  offset: 0
@@ -53385,7 +53503,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53385
53503
  user_id: hidUserId,
53386
53504
  access_rule_id: accessRuleId
53387
53505
  };
53388
- const userAccessRulesResponse = await client2.loadObjects({
53506
+ const userAccessRulesResponse = await client3.loadObjects({
53389
53507
  object: "user_access_rules",
53390
53508
  where: { user_access_rules: { user_id: hidUserId } },
53391
53509
  limit: 100,
@@ -53395,12 +53513,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53395
53513
  getHidObjectRows(userAccessRulesResponse, "user_access_rules"),
53396
53514
  userAccessRuleValues
53397
53515
  )) {
53398
- await client2.createObjects({
53516
+ await client3.createObjects({
53399
53517
  object: "user_access_rules",
53400
53518
  values: [userAccessRuleValues]
53401
53519
  });
53402
53520
  }
53403
- const verifiedUserAccessRulesResponse = await client2.loadObjects({
53521
+ const verifiedUserAccessRulesResponse = await client3.loadObjects({
53404
53522
  object: "user_access_rules",
53405
53523
  where: { user_access_rules: { user_id: hidUserId } },
53406
53524
  limit: 100,
@@ -53414,7 +53532,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53414
53532
  "The HID reader did not save the visitor access rule. Try issuing the QR code again."
53415
53533
  );
53416
53534
  }
53417
- const portalAccessRulesResponse = await client2.loadObjects({
53535
+ const portalAccessRulesResponse = await client3.loadObjects({
53418
53536
  object: "portal_access_rules",
53419
53537
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
53420
53538
  limit: 100,
@@ -53425,7 +53543,7 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53425
53543
  );
53426
53544
  const stalePortalIds = [...linkedPortalIds].filter((portalId) => !portalIds.includes(portalId));
53427
53545
  for (const portalId of stalePortalIds) {
53428
- await client2.destroyObjects({
53546
+ await client3.destroyObjects({
53429
53547
  object: "portal_access_rules",
53430
53548
  where: { portal_access_rules: { access_rule_id: accessRuleId, portal_id: portalId } }
53431
53549
  });
@@ -53433,12 +53551,12 @@ async function ensureVisitorAccessAuthorization(client2, readerId, reader, hidUs
53433
53551
  }
53434
53552
  const missingPortalLinks = portalIds.filter((portalId) => !linkedPortalIds.has(portalId)).map((portalId) => ({ portal_id: portalId, access_rule_id: accessRuleId }));
53435
53553
  if (missingPortalLinks.length) {
53436
- await client2.createObjects({
53554
+ await client3.createObjects({
53437
53555
  object: "portal_access_rules",
53438
53556
  values: missingPortalLinks
53439
53557
  });
53440
53558
  }
53441
- const verifiedPortalAccessRulesResponse = await client2.loadObjects({
53559
+ const verifiedPortalAccessRulesResponse = await client3.loadObjects({
53442
53560
  object: "portal_access_rules",
53443
53561
  where: { portal_access_rules: { access_rule_id: accessRuleId } },
53444
53562
  limit: 100,
@@ -53462,19 +53580,19 @@ function getHidPortals(response) {
53462
53580
  areaToId: Number(portal.area_to_id)
53463
53581
  })).filter((portal) => Number.isSafeInteger(portal.id) && portal.id > 0 && portal.name);
53464
53582
  }
53465
- async function upsertHidObject(client2, object, id, values) {
53466
- const existing = await client2.loadObjects({
53583
+ async function upsertHidObject(client3, object, id, values) {
53584
+ const existing = await client3.loadObjects({
53467
53585
  object,
53468
53586
  where: { [object]: { id } },
53469
53587
  limit: 1,
53470
53588
  offset: 0
53471
53589
  });
53472
53590
  if (getHidObjectRows(existing, object).length) {
53473
- await client2.modifyObjects({ object, where: { [object]: { id } }, values });
53591
+ await client3.modifyObjects({ object, where: { [object]: { id } }, values });
53474
53592
  } else {
53475
- await client2.createObjects({ object, values: [{ id, ...values }] });
53593
+ await client3.createObjects({ object, values: [{ id, ...values }] });
53476
53594
  }
53477
- const verified = await client2.loadObjects({
53595
+ const verified = await client3.loadObjects({
53478
53596
  object,
53479
53597
  where: { [object]: { id } },
53480
53598
  limit: 1,
@@ -53484,17 +53602,17 @@ async function upsertHidObject(client2, object, id, values) {
53484
53602
  throw new import_node_server_utils149.BadRequestError(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
53485
53603
  }
53486
53604
  }
53487
- async function ensureHidRelation(client2, object, values) {
53488
- const response = await client2.loadObjects({
53605
+ async function ensureHidRelation(client3, object, values) {
53606
+ const response = await client3.loadObjects({
53489
53607
  object,
53490
53608
  where: { [object]: values },
53491
53609
  limit: 100,
53492
53610
  offset: 0
53493
53611
  });
53494
53612
  if (!hasHidObjectValues(getHidObjectRows(response, object), values)) {
53495
- await client2.createObjects({ object, values: [values] });
53613
+ await client3.createObjects({ object, values: [values] });
53496
53614
  }
53497
- const verified = await client2.loadObjects({
53615
+ const verified = await client3.loadObjects({
53498
53616
  object,
53499
53617
  where: { [object]: values },
53500
53618
  limit: 100,
@@ -53504,8 +53622,8 @@ async function ensureHidRelation(client2, object, values) {
53504
53622
  throw new import_node_server_utils149.BadRequestError(`The HID reader did not retain ${object.replace(/_/g, " ")}.`);
53505
53623
  }
53506
53624
  }
53507
- async function reconcileHidRelation(client2, object, scope, values) {
53508
- const response = await client2.loadObjects({
53625
+ async function reconcileHidRelation(client3, object, scope, values) {
53626
+ const response = await client3.loadObjects({
53509
53627
  object,
53510
53628
  where: { [object]: scope },
53511
53629
  limit: 1e3,
@@ -53517,11 +53635,11 @@ async function reconcileHidRelation(client2, object, scope, values) {
53517
53635
  const staleValues = Object.fromEntries(
53518
53636
  Object.keys(values).map((key2) => [key2, row[key2]])
53519
53637
  );
53520
- await client2.destroyObjects({ object, where: { [object]: staleValues } });
53638
+ await client3.destroyObjects({ object, where: { [object]: staleValues } });
53521
53639
  }
53522
53640
  }
53523
- await ensureHidRelation(client2, object, values);
53524
- const verified = await client2.loadObjects({
53641
+ await ensureHidRelation(client3, object, values);
53642
+ const verified = await client3.loadObjects({
53525
53643
  object,
53526
53644
  where: { [object]: scope },
53527
53645
  limit: 1e3,
@@ -53532,21 +53650,21 @@ async function reconcileHidRelation(client2, object, scope, values) {
53532
53650
  throw new import_node_server_utils149.BadRequestError(`The HID reader did not reconcile ${object.replace(/_/g, " ")}.`);
53533
53651
  }
53534
53652
  }
53535
- async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userIds) {
53653
+ async function reconcileStandaloneGroupAccess(client3, readerId, portalId, userIds) {
53536
53654
  const groupId = createStableHidId(`permission-group:${readerId}`);
53537
53655
  const accessRuleId = createStableHidId(`permission-access-rule:${readerId}`);
53538
53656
  const timeZoneId = createStableHidId(`permission-time-zone:${readerId}`);
53539
53657
  const timeSpanId = createStableHidId(`permission-time-span:${readerId}`);
53540
- await upsertHidObject(client2, "groups", groupId, { name: "iService365 Assigned Access" });
53541
- await upsertHidObject(client2, "access_rules", accessRuleId, {
53658
+ await upsertHidObject(client3, "groups", groupId, { name: "iService365 Assigned Access" });
53659
+ await upsertHidObject(client3, "access_rules", accessRuleId, {
53542
53660
  name: "iService365 Assigned Access",
53543
53661
  type: 1,
53544
53662
  priority: 0
53545
53663
  });
53546
- await upsertHidObject(client2, "time_zones", timeZoneId, {
53664
+ await upsertHidObject(client3, "time_zones", timeZoneId, {
53547
53665
  name: "iService365 Assigned Schedule"
53548
53666
  });
53549
- await upsertHidObject(client2, "time_spans", timeSpanId, {
53667
+ await upsertHidObject(client3, "time_spans", timeSpanId, {
53550
53668
  time_zone_id: timeZoneId,
53551
53669
  start: 0,
53552
53670
  end: 86399,
@@ -53561,19 +53679,19 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
53561
53679
  hol2: 1,
53562
53680
  hol3: 1
53563
53681
  });
53564
- await reconcileHidRelation(client2, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
53682
+ await reconcileHidRelation(client3, "access_rule_time_zones", { access_rule_id: accessRuleId }, {
53565
53683
  access_rule_id: accessRuleId,
53566
53684
  time_zone_id: timeZoneId
53567
53685
  });
53568
- await reconcileHidRelation(client2, "group_access_rules", { access_rule_id: accessRuleId }, {
53686
+ await reconcileHidRelation(client3, "group_access_rules", { access_rule_id: accessRuleId }, {
53569
53687
  group_id: groupId,
53570
53688
  access_rule_id: accessRuleId
53571
53689
  });
53572
- await reconcileHidRelation(client2, "portal_access_rules", { access_rule_id: accessRuleId }, {
53690
+ await reconcileHidRelation(client3, "portal_access_rules", { access_rule_id: accessRuleId }, {
53573
53691
  portal_id: portalId,
53574
53692
  access_rule_id: accessRuleId
53575
53693
  });
53576
- const currentResponse = await client2.loadObjects({
53694
+ const currentResponse = await client3.loadObjects({
53577
53695
  object: "user_groups",
53578
53696
  where: { user_groups: { group_id: groupId } },
53579
53697
  limit: 2e5,
@@ -53584,7 +53702,7 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
53584
53702
  for (const row of currentRows) {
53585
53703
  const userId = String(row.user_id ?? "");
53586
53704
  if (userId && !desired.has(userId)) {
53587
- await client2.destroyObjects({
53705
+ await client3.destroyObjects({
53588
53706
  object: "user_groups",
53589
53707
  where: { user_groups: { group_id: groupId, user_id: Number(userId) } }
53590
53708
  });
@@ -53593,13 +53711,13 @@ async function reconcileStandaloneGroupAccess(client2, readerId, portalId, userI
53593
53711
  const current = new Set(currentRows.map((row) => String(row.user_id ?? "")));
53594
53712
  for (const userId of userIds) {
53595
53713
  if (!current.has(String(userId))) {
53596
- await client2.createObjects({
53714
+ await client3.createObjects({
53597
53715
  object: "user_groups",
53598
53716
  values: [{ group_id: groupId, user_id: userId }]
53599
53717
  });
53600
53718
  }
53601
53719
  }
53602
- const verification = await client2.loadObjects({
53720
+ const verification = await client3.loadObjects({
53603
53721
  object: "user_groups",
53604
53722
  where: { user_groups: { group_id: groupId } },
53605
53723
  limit: 2e5,
@@ -54102,10 +54220,10 @@ var HidAmicoClient = class {
54102
54220
  return res.data;
54103
54221
  }
54104
54222
  };
54105
- async function configureMonitor(client2, callbackToken) {
54223
+ async function configureMonitor(client3, callbackToken) {
54106
54224
  const expected = getMonitorConfiguration(callbackToken);
54107
- await client2.setConfiguration({ monitor: expected });
54108
- const response = await client2.getConfiguration({
54225
+ await client3.setConfiguration({ monitor: expected });
54226
+ const response = await client3.getConfiguration({
54109
54227
  monitor: ["request_timeout", "hostname", "port", "path"]
54110
54228
  });
54111
54229
  const root = isUnknownRecord2(response) ? response : {};
@@ -54115,9 +54233,9 @@ async function configureMonitor(client2, callbackToken) {
54115
54233
  }
54116
54234
  return expected;
54117
54235
  }
54118
- async function configureOperatingMode(client2, mode) {
54236
+ async function configureOperatingMode(client3, mode) {
54119
54237
  const expectedOnline = mode === "online" ? "1" : "0";
54120
- await client2.setConfiguration({
54238
+ await client3.setConfiguration({
54121
54239
  general: {
54122
54240
  online: expectedOnline,
54123
54241
  // HID documents Online mode as both flags enabled. Keeping local
@@ -54125,7 +54243,7 @@ async function configureOperatingMode(client2, mode) {
54125
54243
  local_identification: "1"
54126
54244
  }
54127
54245
  });
54128
- const response = await client2.getConfiguration({
54246
+ const response = await client3.getConfiguration({
54129
54247
  general: ["online", "local_identification"]
54130
54248
  });
54131
54249
  const root = isUnknownRecord2(response) ? response : {};
@@ -54509,8 +54627,8 @@ function useHidAmicoService() {
54509
54627
  return requestedType;
54510
54628
  return mode === "csn_for_mifare" ? "unknown" : mode;
54511
54629
  }
54512
- async function assertHidUserExists(client2, hidUserId) {
54513
- const response = await client2.loadObjects({
54630
+ async function assertHidUserExists(client3, hidUserId) {
54631
+ const response = await client3.loadObjects({
54514
54632
  object: "users",
54515
54633
  where: { users: { id: hidUserId } },
54516
54634
  limit: 1,
@@ -54520,18 +54638,18 @@ function useHidAmicoService() {
54520
54638
  throw new import_node_server_utils149.BadRequestError("HID user must exist before assigning a physical HID card.");
54521
54639
  }
54522
54640
  }
54523
- async function ensurePhysicalCardIdentification(client2) {
54524
- const before = await client2.getConfiguration({
54641
+ async function ensurePhysicalCardIdentification(client3) {
54642
+ const before = await client3.getConfiguration({
54525
54643
  identifier: ["card_identification_enabled"]
54526
54644
  });
54527
54645
  const root = isUnknownRecord2(before) ? before : {};
54528
54646
  const identifier = isUnknownRecord2(root.identifier) ? root.identifier : {};
54529
54647
  if (String(identifier.card_identification_enabled ?? "") !== "1") {
54530
- await client2.setConfiguration({
54648
+ await client3.setConfiguration({
54531
54649
  identifier: { card_identification_enabled: "1" }
54532
54650
  });
54533
54651
  }
54534
- const verifiedResponse = await client2.getConfiguration({
54652
+ const verifiedResponse = await client3.getConfiguration({
54535
54653
  identifier: ["card_identification_enabled"]
54536
54654
  });
54537
54655
  const verifiedRoot = isUnknownRecord2(verifiedResponse) ? verifiedResponse : {};
@@ -54542,8 +54660,8 @@ function useHidAmicoService() {
54542
54660
  );
54543
54661
  }
54544
54662
  }
54545
- async function loadPhysicalCardRows(client2, hidUserId) {
54546
- const response = await client2.loadObjects({
54663
+ async function loadPhysicalCardRows(client3, hidUserId) {
54664
+ const response = await client3.loadObjects({
54547
54665
  object: "cards",
54548
54666
  where: { cards: { user_id: hidUserId } },
54549
54667
  limit: 100,
@@ -54641,15 +54759,15 @@ function useHidAmicoService() {
54641
54759
  const refusal = discoveryUrlRefusalReason(value.baseUrl);
54642
54760
  if (refusal)
54643
54761
  throw new import_node_server_utils149.BadRequestError(refusal);
54644
- const client2 = new HidAmicoClient({
54762
+ const client3 = new HidAmicoClient({
54645
54763
  ...value,
54646
54764
  baseUrl: normalizeHidReaderBaseUrl(value.baseUrl)
54647
54765
  });
54648
54766
  try {
54649
- await client2.login();
54767
+ await client3.login();
54650
54768
  const [systemResponse, portalsResponse] = await Promise.all([
54651
- client2.getSystemInformation(),
54652
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54769
+ client3.getSystemInformation(),
54770
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
54653
54771
  ]);
54654
54772
  const system = getHidSystemInformation(systemResponse);
54655
54773
  const deviceId = isUnknownRecord2(system) ? String(system.device_id || "").trim() : "";
@@ -54679,7 +54797,7 @@ function useHidAmicoService() {
54679
54797
  portals
54680
54798
  };
54681
54799
  } finally {
54682
- await client2.logout();
54800
+ await client3.logout();
54683
54801
  }
54684
54802
  }
54685
54803
  async function createReader(value) {
@@ -54709,11 +54827,11 @@ function useHidAmicoService() {
54709
54827
  const readerId = String(reader._id);
54710
54828
  if (value.enabled === false)
54711
54829
  return reader;
54712
- const client2 = new HidAmicoClient(value);
54830
+ const client3 = new HidAmicoClient(value);
54713
54831
  try {
54714
- await client2.login();
54832
+ await client3.login();
54715
54833
  if (!monitorEnabled) {
54716
- await configureOperatingMode(client2, "standalone");
54834
+ await configureOperatingMode(client3, "standalone");
54717
54835
  return repo.updateById(readerId, {
54718
54836
  monitorStatus: "disabled",
54719
54837
  monitorPath: "",
@@ -54722,8 +54840,8 @@ function useHidAmicoService() {
54722
54840
  lastSyncMessage: "Monitor callbacks are disabled; Standalone mode configured."
54723
54841
  });
54724
54842
  }
54725
- const monitor = await configureMonitor(client2, callbackToken);
54726
- await configureOperatingMode(client2, "standalone");
54843
+ const monitor = await configureMonitor(client3, callbackToken);
54844
+ await configureOperatingMode(client3, "standalone");
54727
54845
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
54728
54846
  return repo.updateById(readerId, {
54729
54847
  monitorPath: publicMonitor.path,
@@ -54749,7 +54867,7 @@ function useHidAmicoService() {
54749
54867
  });
54750
54868
  return { ...failed, monitorWarning: message };
54751
54869
  } finally {
54752
- await client2.logout();
54870
+ await client3.logout();
54753
54871
  }
54754
54872
  }
54755
54873
  async function updateReader(id, value) {
@@ -54789,10 +54907,10 @@ function useHidAmicoService() {
54789
54907
  }
54790
54908
  if (payload.portalId && current) {
54791
54909
  const candidate = { ...current, ...payload };
54792
- const client2 = new HidAmicoClient(candidate);
54910
+ const client3 = new HidAmicoClient(candidate);
54793
54911
  try {
54794
- await client2.login();
54795
- const portals = getHidPortals(await client2.loadObjects({
54912
+ await client3.login();
54913
+ const portals = getHidPortals(await client3.loadObjects({
54796
54914
  object: "portals",
54797
54915
  limit: 100,
54798
54916
  offset: 0
@@ -54803,7 +54921,7 @@ function useHidAmicoService() {
54803
54921
  }
54804
54922
  payload.portalName = portal.name;
54805
54923
  } finally {
54806
- await client2.logout();
54924
+ await client3.logout();
54807
54925
  }
54808
54926
  }
54809
54927
  return repo.updateById(id, payload);
@@ -54821,12 +54939,12 @@ function useHidAmicoService() {
54821
54939
  monitorStatus: "unconfigured"
54822
54940
  });
54823
54941
  }
54824
- const client2 = new HidAmicoClient(reader);
54942
+ const client3 = new HidAmicoClient(reader);
54825
54943
  try {
54826
- await client2.login();
54944
+ await client3.login();
54827
54945
  const [systemResponse, portalsResponse] = await Promise.all([
54828
- client2.getSystemInformation(),
54829
- client2.loadObjects({ object: "portals", limit: 100, offset: 0 })
54946
+ client3.getSystemInformation(),
54947
+ client3.loadObjects({ object: "portals", limit: 100, offset: 0 })
54830
54948
  ]);
54831
54949
  const system = getHidSystemInformation(systemResponse);
54832
54950
  const serial = isUnknownRecord2(system) ? String(system.serial || "") : "";
@@ -54843,9 +54961,9 @@ function useHidAmicoService() {
54843
54961
  "The saved portal no longer exists on this HID reader. Edit the reader and select a valid portal."
54844
54962
  );
54845
54963
  }
54846
- const monitor = await configureMonitor(client2, callbackToken);
54964
+ const monitor = await configureMonitor(client3, callbackToken);
54847
54965
  const mode = reader.operatingMode === "online" ? "online" : "standalone";
54848
- await configureOperatingMode(client2, mode);
54966
+ await configureOperatingMode(client3, mode);
54849
54967
  const publicMonitor = getPublicMonitorConfiguration(monitor, callbackToken);
54850
54968
  await repo.updateById(id, {
54851
54969
  serial,
@@ -54868,17 +54986,17 @@ function useHidAmicoService() {
54868
54986
  });
54869
54987
  throw error;
54870
54988
  } finally {
54871
- await client2.logout();
54989
+ await client3.logout();
54872
54990
  }
54873
54991
  }
54874
54992
  async function setReaderMonitor(id, enabled) {
54875
54993
  if (enabled)
54876
54994
  return configureReaderIntegration(id);
54877
54995
  const reader = await getActiveReader(id);
54878
- const client2 = new HidAmicoClient(reader);
54996
+ const client3 = new HidAmicoClient(reader);
54879
54997
  try {
54880
- await client2.login();
54881
- await configureOperatingMode(client2, "standalone");
54998
+ await client3.login();
54999
+ await configureOperatingMode(client3, "standalone");
54882
55000
  await repo.updateById(id, {
54883
55001
  monitorStatus: "disabled",
54884
55002
  monitorPath: "",
@@ -54895,7 +55013,7 @@ function useHidAmicoService() {
54895
55013
  });
54896
55014
  return { enabled: false, mode: "standalone", verified: true };
54897
55015
  } finally {
54898
- await client2.logout();
55016
+ await client3.logout();
54899
55017
  }
54900
55018
  }
54901
55019
  async function setOperatingMode(id, mode) {
@@ -54905,10 +55023,10 @@ function useHidAmicoService() {
54905
55023
  "Configure and verify the HID Monitor callback before enabling Online mode."
54906
55024
  );
54907
55025
  }
54908
- const client2 = new HidAmicoClient(reader);
55026
+ const client3 = new HidAmicoClient(reader);
54909
55027
  try {
54910
- await client2.login();
54911
- const result = await configureOperatingMode(client2, mode);
55028
+ await client3.login();
55029
+ const result = await configureOperatingMode(client3, mode);
54912
55030
  await repo.updateById(id, {
54913
55031
  operatingMode: mode,
54914
55032
  lastSyncStatus: "completed",
@@ -54923,7 +55041,7 @@ function useHidAmicoService() {
54923
55041
  });
54924
55042
  return sanitizeHidPayload(result);
54925
55043
  } finally {
54926
- await client2.logout();
55044
+ await client3.logout();
54927
55045
  }
54928
55046
  }
54929
55047
  async function listReaders(value) {
@@ -54978,12 +55096,12 @@ function useHidAmicoService() {
54978
55096
  }
54979
55097
  async function testReader(id) {
54980
55098
  const reader = await repo.getById(id, { includePassword: true });
54981
- const client2 = new HidAmicoClient(reader);
55099
+ const client3 = new HidAmicoClient(reader);
54982
55100
  try {
54983
- await client2.login();
55101
+ await client3.login();
54984
55102
  const [valid, systemResponse] = await Promise.all([
54985
- client2.sessionIsValid(),
54986
- client2.getSystemInformation()
55103
+ client3.sessionIsValid(),
55104
+ client3.getSystemInformation()
54987
55105
  ]);
54988
55106
  const system = getHidSystemInformation(systemResponse);
54989
55107
  const firmwareVersion = getHidFirmwareVersion(systemResponse);
@@ -55037,19 +55155,19 @@ function useHidAmicoService() {
55037
55155
  await repo.addEvent({ reader: id, site: reader.site, type: "test_failed", payload: { message } });
55038
55156
  throw error;
55039
55157
  } finally {
55040
- await client2.logout();
55158
+ await client3.logout();
55041
55159
  }
55042
55160
  }
55043
55161
  async function syncReader(id, payload) {
55044
55162
  const reader = await getActiveReader(id);
55045
55163
  const batches = normalizeBatches(payload);
55046
- const client2 = new HidAmicoClient(reader);
55164
+ const client3 = new HidAmicoClient(reader);
55047
55165
  const results = [];
55048
55166
  await repo.updateById(id, { lastSyncStatus: "running", lastSyncMessage: "Sync started." });
55049
55167
  try {
55050
- await client2.login();
55168
+ await client3.login();
55051
55169
  for (const batch of batches) {
55052
- const result = await client2.createObjects(batch);
55170
+ const result = await client3.createObjects(batch);
55053
55171
  results.push({
55054
55172
  object: batch.object,
55055
55173
  count: batch.values.length,
@@ -55077,7 +55195,7 @@ function useHidAmicoService() {
55077
55195
  await repo.addEvent({ reader: id, site: reader.site, type: "sync_failed", payload: { message } });
55078
55196
  throw error;
55079
55197
  } finally {
55080
- await client2.logout();
55198
+ await client3.logout();
55081
55199
  }
55082
55200
  }
55083
55201
  async function isIdentityAssignedToReader(reader, identity, requestedPortalId) {
@@ -55193,9 +55311,9 @@ function useHidAmicoService() {
55193
55311
  async function listReaderUsers(readerId, page2 = 1, limit = 10, search = "", status = "", includeVisitors = false, userType = "all") {
55194
55312
  const reader = await getActiveReader(readerId);
55195
55313
  const offset = (page2 - 1) * limit;
55196
- const client2 = new HidAmicoClient(reader);
55314
+ const client3 = new HidAmicoClient(reader);
55197
55315
  try {
55198
- await client2.login();
55316
+ await client3.login();
55199
55317
  const normalizedSearch = search.trim();
55200
55318
  const numericSearch = /^\d{1,15}$/.test(normalizedSearch) ? Number(normalizedSearch) : null;
55201
55319
  const userWhere = {};
@@ -55207,7 +55325,7 @@ function useHidAmicoService() {
55207
55325
  let rows = [];
55208
55326
  let reportedTotal = null;
55209
55327
  let hasMore = false;
55210
- const response = await client2.loadObjects({
55328
+ const response = await client3.loadObjects({
55211
55329
  object: "users",
55212
55330
  where: { users: userWhere },
55213
55331
  limit: 500,
@@ -55227,7 +55345,7 @@ function useHidAmicoService() {
55227
55345
  const userId = Number(row.id);
55228
55346
  if (!Number.isSafeInteger(userId) || userId <= 0)
55229
55347
  return false;
55230
- const roleResponse = await client2.loadObjects({
55348
+ const roleResponse = await client3.loadObjects({
55231
55349
  object: "user_roles",
55232
55350
  where: { user_roles: { user_id: userId, role: 1 } },
55233
55351
  limit: 1,
@@ -55235,7 +55353,7 @@ function useHidAmicoService() {
55235
55353
  });
55236
55354
  return getHidObjectRows(roleResponse, "user_roles").length > 0;
55237
55355
  })),
55238
- readerSupportsFacial(reader) ? client2.listUserImageIds().catch(() => []) : Promise.resolve([])
55356
+ readerSupportsFacial(reader) ? client3.listUserImageIds().catch(() => []) : Promise.resolve([])
55239
55357
  ]);
55240
55358
  const facialUserIdSet = new Set(facialUserIds.map(String));
55241
55359
  const items = rows.map((row, index) => {
@@ -55265,15 +55383,15 @@ function useHidAmicoService() {
55265
55383
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${reportedTotal ?? `${offset + items.length}${hasMore ? "+" : ""}`}` : "0-0 of 0"
55266
55384
  };
55267
55385
  } finally {
55268
- await client2.logout();
55386
+ await client3.logout();
55269
55387
  }
55270
55388
  }
55271
55389
  async function listReaderAccessLogs(readerId, page2 = 1, limit = 10, search = "", status = "", method = "", tab = "all") {
55272
55390
  const reader = await getActiveReader(readerId);
55273
55391
  const offset = (page2 - 1) * limit;
55274
- const client2 = new HidAmicoClient(reader);
55392
+ const client3 = new HidAmicoClient(reader);
55275
55393
  try {
55276
- await client2.login();
55394
+ await client3.login();
55277
55395
  const where = {};
55278
55396
  if (status === "authorized")
55279
55397
  where.event = 7;
@@ -55294,7 +55412,7 @@ function useHidAmicoService() {
55294
55412
  const userIds = [...new Set(rows.map((row) => toPositiveInteger(row.user_id ?? row.userId)).filter((value) => value !== null))];
55295
55413
  const [identities, roleResponse, userResponse] = await Promise.all([
55296
55414
  repo.findIdentitiesByHidUserIds(readerId, userIds.map(String)),
55297
- userIds.length ? client2.loadObjects({
55415
+ userIds.length ? client3.loadObjects({
55298
55416
  object: "user_roles",
55299
55417
  where: {
55300
55418
  user_roles: {
@@ -55305,7 +55423,7 @@ function useHidAmicoService() {
55305
55423
  limit: Math.max(1, userIds.length),
55306
55424
  offset: 0
55307
55425
  }) : Promise.resolve({ user_roles: [] }),
55308
- userIds.length ? client2.loadObjects({
55426
+ userIds.length ? client3.loadObjects({
55309
55427
  object: "users",
55310
55428
  where: {
55311
55429
  users: {
@@ -55377,7 +55495,7 @@ function useHidAmicoService() {
55377
55495
  let deviceOffset = 0;
55378
55496
  let exhausted = false;
55379
55497
  while (!exhausted && matchedItems.length < targetCount) {
55380
- const response = await client2.loadObjects({
55498
+ const response = await client3.loadObjects({
55381
55499
  object: "access_logs",
55382
55500
  ...Object.keys(where).length ? { where: { access_logs: where } } : {},
55383
55501
  limit: chunkSize,
@@ -55404,7 +55522,7 @@ function useHidAmicoService() {
55404
55522
  pageRange: items.length ? `${offset + 1}-${offset + items.length} of ${offset + items.length}${hasMore ? "+" : ""}` : "0-0 of 0"
55405
55523
  };
55406
55524
  } finally {
55407
- await client2.logout();
55525
+ await client3.logout();
55408
55526
  }
55409
55527
  }
55410
55528
  async function createIdentity(readerId, value) {
@@ -55496,18 +55614,18 @@ function useHidAmicoService() {
55496
55614
  async function runObjectOperation(id, operation, payload) {
55497
55615
  const reader = await getActiveReader(id);
55498
55616
  assertAllowedHidObject(payload.object, operation);
55499
- const client2 = new HidAmicoClient(reader);
55617
+ const client3 = new HidAmicoClient(reader);
55500
55618
  try {
55501
- await client2.login();
55619
+ await client3.login();
55502
55620
  let result;
55503
55621
  if (operation === "load") {
55504
- result = await client2.loadObjects(payload);
55622
+ result = await client3.loadObjects(payload);
55505
55623
  } else if (operation === "create") {
55506
- result = await client2.createObjects(payload);
55624
+ result = await client3.createObjects(payload);
55507
55625
  } else if (operation === "modify") {
55508
- result = await client2.modifyObjects(payload);
55626
+ result = await client3.modifyObjects(payload);
55509
55627
  } else {
55510
- result = await client2.destroyObjects(payload);
55628
+ result = await client3.destroyObjects(payload);
55511
55629
  }
55512
55630
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
55513
55631
  const safeRequest = sanitizeHidObjectPayload(payload.object, payload);
@@ -55531,7 +55649,7 @@ function useHidAmicoService() {
55531
55649
  });
55532
55650
  throw error;
55533
55651
  } finally {
55534
- await client2.logout();
55652
+ await client3.logout();
55535
55653
  }
55536
55654
  }
55537
55655
  async function issueVisitorQrAtReader(readerId, value) {
@@ -55562,10 +55680,10 @@ function useHidAmicoService() {
55562
55680
  const hidUserId = createStableHidId(`visitor:${readerId}:${value.visitorId}`);
55563
55681
  const registration = `VIS-${value.visitorId.slice(-12).toUpperCase()}`;
55564
55682
  const credential = createVisitorQrCredential(value.visitorId, readerId, value.qrValue);
55565
- const client2 = new HidAmicoClient(reader);
55683
+ const client3 = new HidAmicoClient(reader);
55566
55684
  try {
55567
- await client2.login();
55568
- const readerConfigurationChanged = await configureVisitorQrReader(client2);
55685
+ await client3.login();
55686
+ const readerConfigurationChanged = await configureVisitorQrReader(client3);
55569
55687
  if (readerConfigurationChanged) {
55570
55688
  await repo.addEvent({
55571
55689
  reader: readerId,
@@ -55579,7 +55697,7 @@ function useHidAmicoService() {
55579
55697
  }
55580
55698
  });
55581
55699
  }
55582
- const existingUserResponse = await client2.loadObjects({
55700
+ const existingUserResponse = await client3.loadObjects({
55583
55701
  object: "users",
55584
55702
  where: { users: { id: hidUserId } },
55585
55703
  limit: 1,
@@ -55600,18 +55718,18 @@ function useHidAmicoService() {
55600
55718
  );
55601
55719
  }
55602
55720
  if (existingUsers.length) {
55603
- await client2.modifyObjects({
55721
+ await client3.modifyObjects({
55604
55722
  object: "users",
55605
55723
  where: { users: { id: hidUserId } },
55606
55724
  values: user
55607
55725
  });
55608
55726
  } else {
55609
- await client2.createObjects({
55727
+ await client3.createObjects({
55610
55728
  object: "users",
55611
55729
  values: [{ id: hidUserId, ...user }]
55612
55730
  });
55613
55731
  }
55614
- const savedUserResponse = await client2.loadObjects({
55732
+ const savedUserResponse = await client3.loadObjects({
55615
55733
  object: "users",
55616
55734
  where: { users: { id: hidUserId } },
55617
55735
  limit: 1,
@@ -55626,12 +55744,12 @@ function useHidAmicoService() {
55626
55744
  );
55627
55745
  }
55628
55746
  const authorization = await ensureVisitorAccessAuthorization(
55629
- client2,
55747
+ client3,
55630
55748
  readerId,
55631
55749
  reader,
55632
55750
  hidUserId
55633
55751
  );
55634
- const existingQrResponse = await client2.loadObjects({
55752
+ const existingQrResponse = await client3.loadObjects({
55635
55753
  object: credential.object,
55636
55754
  where: { [credential.object]: { user_id: hidUserId } },
55637
55755
  limit: 100,
@@ -55640,18 +55758,18 @@ function useHidAmicoService() {
55640
55758
  const existingQrs = getHidObjectRows(existingQrResponse, credential.object);
55641
55759
  const credentialValues = { value: credential.value, user_id: hidUserId };
55642
55760
  if (existingQrs.some((row) => String(row.id) === String(credential.credentialId))) {
55643
- await client2.modifyObjects({
55761
+ await client3.modifyObjects({
55644
55762
  object: credential.object,
55645
55763
  where: { [credential.object]: { id: credential.credentialId } },
55646
55764
  values: credentialValues
55647
55765
  });
55648
55766
  } else {
55649
- await client2.createObjects({
55767
+ await client3.createObjects({
55650
55768
  object: credential.object,
55651
55769
  values: [{ id: credential.credentialId, ...credentialValues }]
55652
55770
  });
55653
55771
  }
55654
- const savedCredentialResponse = await client2.loadObjects({
55772
+ const savedCredentialResponse = await client3.loadObjects({
55655
55773
  object: credential.object,
55656
55774
  where: { [credential.object]: { id: credential.credentialId } },
55657
55775
  limit: 1,
@@ -55669,20 +55787,20 @@ function useHidAmicoService() {
55669
55787
  for (const staleQr of existingQrs) {
55670
55788
  const staleId = Number(staleQr.id);
55671
55789
  if (Number.isSafeInteger(staleId) && staleId > 0 && staleId !== credential.credentialId) {
55672
- await client2.destroyObjects({
55790
+ await client3.destroyObjects({
55673
55791
  object: credential.object,
55674
55792
  where: { [credential.object]: { id: staleId } }
55675
55793
  });
55676
55794
  }
55677
55795
  }
55678
- const existingCardsResponse = await client2.loadObjects({
55796
+ const existingCardsResponse = await client3.loadObjects({
55679
55797
  object: "cards",
55680
55798
  where: { cards: { user_id: hidUserId } },
55681
55799
  limit: 100,
55682
55800
  offset: 0
55683
55801
  });
55684
55802
  if (getHidObjectRows(existingCardsResponse, "cards").length) {
55685
- await client2.destroyObjects({
55803
+ await client3.destroyObjects({
55686
55804
  object: "cards",
55687
55805
  where: { cards: { user_id: hidUserId } }
55688
55806
  });
@@ -55763,7 +55881,7 @@ function useHidAmicoService() {
55763
55881
  });
55764
55882
  throw error;
55765
55883
  } finally {
55766
- await client2.logout();
55884
+ await client3.logout();
55767
55885
  }
55768
55886
  }
55769
55887
  async function resolveVisitorQrGateReaders(siteId, callerId5, fallbackReaderId, issuer) {
@@ -55881,10 +55999,10 @@ function useHidAmicoService() {
55881
55999
  const enrolledAt = /* @__PURE__ */ new Date();
55882
56000
  const timestamp = options.timestamp || Math.floor(enrolledAt.getTime() / 1e3);
55883
56001
  const match = options.match ?? true;
55884
- const client2 = new HidAmicoClient(reader);
56002
+ const client3 = new HidAmicoClient(reader);
55885
56003
  try {
55886
- await client2.login();
55887
- const existingUserResponse = await client2.loadObjects({
56004
+ await client3.login();
56005
+ const existingUserResponse = await client3.loadObjects({
55888
56006
  object: "users",
55889
56007
  where: { users: { id: context.hidUserId } },
55890
56008
  limit: 1,
@@ -55895,18 +56013,18 @@ function useHidAmicoService() {
55895
56013
  registration: context.registration
55896
56014
  };
55897
56015
  if (getHidObjectRows(existingUserResponse, "users").length) {
55898
- await client2.modifyObjects({
56016
+ await client3.modifyObjects({
55899
56017
  object: "users",
55900
56018
  where: { users: { id: context.hidUserId } },
55901
56019
  values: hidUser
55902
56020
  });
55903
56021
  } else {
55904
- await client2.createObjects({
56022
+ await client3.createObjects({
55905
56023
  object: "users",
55906
56024
  values: [{ id: context.hidUserId, ...hidUser }]
55907
56025
  });
55908
56026
  }
55909
- const result = await client2.setUserImage(context.hidUserId, image, timestamp, match);
56027
+ const result = await client3.setUserImage(context.hidUserId, image, timestamp, match);
55910
56028
  const existingIdentity = context.profileIdentity || await repo.findExistingIdentity({
55911
56029
  reader: readerId,
55912
56030
  hidUserId: context.hidUserId
@@ -55971,25 +56089,25 @@ function useHidAmicoService() {
55971
56089
  });
55972
56090
  throw error;
55973
56091
  } finally {
55974
- await client2.logout();
56092
+ await client3.logout();
55975
56093
  }
55976
56094
  }
55977
56095
  async function getUserImage(readerId, hidUserId) {
55978
56096
  const reader = await getActiveReader(readerId);
55979
56097
  assertReaderCapability(reader, "facial");
55980
- const client2 = new HidAmicoClient(reader);
56098
+ const client3 = new HidAmicoClient(reader);
55981
56099
  try {
55982
- await client2.login();
55983
- return await client2.getUserImage(hidUserId);
56100
+ await client3.login();
56101
+ return await client3.getUserImage(hidUserId);
55984
56102
  } finally {
55985
- await client2.logout();
56103
+ await client3.logout();
55986
56104
  }
55987
56105
  }
55988
- async function getReaderFacialUserIds(client2) {
56106
+ async function getReaderFacialUserIds(client3) {
55989
56107
  try {
55990
- return await client2.listUserImageIds();
56108
+ return await client3.listUserImageIds();
55991
56109
  } catch {
55992
- const usersResponse = await client2.loadObjects({
56110
+ const usersResponse = await client3.loadObjects({
55993
56111
  object: "users",
55994
56112
  where: { users: {} },
55995
56113
  limit: 500,
@@ -56003,7 +56121,7 @@ function useHidAmicoService() {
56003
56121
  const batch = userIds.slice(offset, offset + batchSize);
56004
56122
  const results = await Promise.all(batch.map(async (userId) => {
56005
56123
  try {
56006
- const image = await client2.getUserImage(userId);
56124
+ const image = await client3.getUserImage(userId);
56007
56125
  return image.base64 ? userId : null;
56008
56126
  } catch {
56009
56127
  return null;
@@ -56017,10 +56135,10 @@ function useHidAmicoService() {
56017
56135
  async function syncReaderFacialData(readerId) {
56018
56136
  const reader = await getActiveReader(readerId);
56019
56137
  assertReaderCapability(reader, "facial");
56020
- const client2 = new HidAmicoClient(reader);
56138
+ const client3 = new HidAmicoClient(reader);
56021
56139
  try {
56022
- await client2.login();
56023
- const facialUserIds = await getReaderFacialUserIds(client2);
56140
+ await client3.login();
56141
+ const facialUserIds = await getReaderFacialUserIds(client3);
56024
56142
  const message = facialUserIds.length ? `Found ${facialUserIds.length} Amico user(s) with facial data. Facial status and images are read directly from the reader.` : "No facial enrollments found on the HID reader.";
56025
56143
  await repo.updateById(readerId, { status: "active", lastSeenAt: /* @__PURE__ */ new Date() });
56026
56144
  await repo.addEvent({
@@ -56052,7 +56170,7 @@ function useHidAmicoService() {
56052
56170
  });
56053
56171
  throw error;
56054
56172
  } finally {
56055
- await client2.logout();
56173
+ await client3.logout();
56056
56174
  }
56057
56175
  }
56058
56176
  async function setVisitorImage(readerId, visitorId, image, options = {}) {
@@ -56071,10 +56189,10 @@ function useHidAmicoService() {
56071
56189
  );
56072
56190
  const timestamp = options.timestamp || Math.floor(issuedAt.getTime() / 1e3);
56073
56191
  const match = options.match ?? true;
56074
- const client2 = new HidAmicoClient(reader);
56192
+ const client3 = new HidAmicoClient(reader);
56075
56193
  try {
56076
- await client2.login();
56077
- const existingUserResponse = await client2.loadObjects({
56194
+ await client3.login();
56195
+ const existingUserResponse = await client3.loadObjects({
56078
56196
  object: "users",
56079
56197
  where: { users: { id: hidUserId } },
56080
56198
  limit: 1,
@@ -56088,24 +56206,24 @@ function useHidAmicoService() {
56088
56206
  end_time: Math.floor(expiresAt.getTime() / 1e3)
56089
56207
  };
56090
56208
  if (getHidObjectRows(existingUserResponse, "users").length) {
56091
- await client2.modifyObjects({
56209
+ await client3.modifyObjects({
56092
56210
  object: "users",
56093
56211
  where: { users: { id: hidUserId } },
56094
56212
  values: user
56095
56213
  });
56096
56214
  } else {
56097
- await client2.createObjects({
56215
+ await client3.createObjects({
56098
56216
  object: "users",
56099
56217
  values: [{ id: hidUserId, ...user }]
56100
56218
  });
56101
56219
  }
56102
56220
  const authorization = await ensureVisitorAccessAuthorization(
56103
- client2,
56221
+ client3,
56104
56222
  readerId,
56105
56223
  reader,
56106
56224
  hidUserId
56107
56225
  );
56108
- const result = await client2.setUserImage(hidUserId, image, timestamp, match);
56226
+ const result = await client3.setUserImage(hidUserId, image, timestamp, match);
56109
56227
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
56110
56228
  const existingMetadata = existingIdentity && isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
56111
56229
  const identityPayload = {
@@ -56171,17 +56289,17 @@ function useHidAmicoService() {
56171
56289
  });
56172
56290
  throw error;
56173
56291
  } finally {
56174
- await client2.logout();
56292
+ await client3.logout();
56175
56293
  }
56176
56294
  }
56177
56295
  async function deleteVisitorImage(readerId, visitorId) {
56178
56296
  const reader = await getActiveReader(readerId);
56179
56297
  assertReaderCapability(reader, "facial");
56180
56298
  const { hidUserId } = await getVisitorEnrollmentContext(readerId, reader, visitorId);
56181
- const client2 = new HidAmicoClient(reader);
56299
+ const client3 = new HidAmicoClient(reader);
56182
56300
  try {
56183
- await client2.login();
56184
- const result = await client2.deleteUserImage(hidUserId);
56301
+ await client3.login();
56302
+ const result = await client3.deleteUserImage(hidUserId);
56185
56303
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
56186
56304
  if (existingIdentity?._id) {
56187
56305
  const existingMetadata = isUnknownRecord2(existingIdentity.metadata) ? existingIdentity.metadata : {};
@@ -56210,7 +56328,7 @@ function useHidAmicoService() {
56210
56328
  });
56211
56329
  throw error;
56212
56330
  } finally {
56213
- await client2.logout();
56331
+ await client3.logout();
56214
56332
  }
56215
56333
  }
56216
56334
  async function listUserCards(readerId, hidUserIdValue) {
@@ -56218,19 +56336,19 @@ function useHidAmicoService() {
56218
56336
  assertReaderCapability(reader, "card");
56219
56337
  const cardType = reader.cardReadingMode === "pacs" || reader.cardReadingMode === "csn" ? reader.cardReadingMode : "unknown";
56220
56338
  const hidUserId = Number(hidUserIdValue);
56221
- const client2 = new HidAmicoClient(reader);
56339
+ const client3 = new HidAmicoClient(reader);
56222
56340
  try {
56223
- await client2.login();
56224
- await assertHidUserExists(client2, hidUserId);
56341
+ await client3.login();
56342
+ await assertHidUserExists(client3, hidUserId);
56225
56343
  const [rows, identity] = await Promise.all([
56226
- loadPhysicalCardRows(client2, hidUserId),
56344
+ loadPhysicalCardRows(client3, hidUserId),
56227
56345
  repo.findExistingIdentity({ reader: readerId, hidUserId })
56228
56346
  ]);
56229
56347
  const metadataRows = getIdentityPhysicalCards(identity);
56230
56348
  const cards = rows.map((row) => toHidPhysicalCard(row, metadataRows, cardType)).filter((card) => Boolean(card));
56231
56349
  return { readerId, hidUserId, cards };
56232
56350
  } finally {
56233
- await client2.logout();
56351
+ await client3.logout();
56234
56352
  }
56235
56353
  }
56236
56354
  async function assignUserCard(readerId, hidUserIdValue, input) {
@@ -56244,12 +56362,12 @@ function useHidAmicoService() {
56244
56362
  } catch (error) {
56245
56363
  throw new import_node_server_utils149.BadRequestError(getErrorMessage2(error));
56246
56364
  }
56247
- const client2 = new HidAmicoClient(reader);
56365
+ const client3 = new HidAmicoClient(reader);
56248
56366
  try {
56249
- await client2.login();
56250
- await assertHidUserExists(client2, hidUserId);
56251
- await ensurePhysicalCardIdentification(client2);
56252
- const collisionResponse = await client2.loadObjects({
56367
+ await client3.login();
56368
+ await assertHidUserExists(client3, hidUserId);
56369
+ await ensurePhysicalCardIdentification(client3);
56370
+ const collisionResponse = await client3.loadObjects({
56253
56371
  object: "cards",
56254
56372
  where: { cards: { value: hidRawUint64(cardValue) } },
56255
56373
  limit: 10,
@@ -56267,11 +56385,11 @@ function useHidAmicoService() {
56267
56385
  );
56268
56386
  if (!savedRow) {
56269
56387
  const credentialId = createStableHidId(`physical-card:${readerId}:${cardValue}`);
56270
- await client2.createObjects({
56388
+ await client3.createObjects({
56271
56389
  object: "cards",
56272
56390
  values: [{ id: credentialId, value: hidRawUint64(cardValue), user_id: hidUserId }]
56273
56391
  });
56274
- const verifiedResponse = await client2.loadObjects({
56392
+ const verifiedResponse = await client3.loadObjects({
56275
56393
  object: "cards",
56276
56394
  where: { cards: { id: credentialId } },
56277
56395
  limit: 1,
@@ -56312,7 +56430,7 @@ function useHidAmicoService() {
56312
56430
  });
56313
56431
  throw error;
56314
56432
  } finally {
56315
- await client2.logout();
56433
+ await client3.logout();
56316
56434
  }
56317
56435
  }
56318
56436
  async function enrollUserCard(readerId, hidUserIdValue, cardType, timeoutSeconds) {
@@ -56320,17 +56438,17 @@ function useHidAmicoService() {
56320
56438
  assertReaderCapability(reader, "card");
56321
56439
  assertReaderCardProfile(reader, cardType);
56322
56440
  const hidUserId = Number(hidUserIdValue);
56323
- const client2 = new HidAmicoClient(reader);
56441
+ const client3 = new HidAmicoClient(reader);
56324
56442
  const lockOwner = import_crypto4.default.randomUUID();
56325
56443
  const acquired = await repo.acquireEnrollmentLock(readerId, lockOwner, timeoutSeconds + 30);
56326
56444
  if (!acquired) {
56327
56445
  throw new import_node_server_utils149.BadRequestError("Another physical HID card enrollment is already running on this reader.");
56328
56446
  }
56329
56447
  try {
56330
- await client2.login();
56331
- await assertHidUserExists(client2, hidUserId);
56332
- await ensurePhysicalCardIdentification(client2);
56333
- const beforeRows = await loadPhysicalCardRows(client2, hidUserId);
56448
+ await client3.login();
56449
+ await assertHidUserExists(client3, hidUserId);
56450
+ await ensurePhysicalCardIdentification(client3);
56451
+ const beforeRows = await loadPhysicalCardRows(client3, hidUserId);
56334
56452
  const beforeValues = new Set(beforeRows.map((row) => String(row.value ?? "")));
56335
56453
  await repo.addEvent({
56336
56454
  reader: readerId,
@@ -56339,7 +56457,7 @@ function useHidAmicoService() {
56339
56457
  payload: { hidUserId, cardType, timeoutSeconds }
56340
56458
  });
56341
56459
  const startedAt = Date.now();
56342
- const response = await client2.remoteEnrollCard(hidUserId, timeoutSeconds);
56460
+ const response = await client3.remoteEnrollCard(hidUserId, timeoutSeconds);
56343
56461
  const responseRecord = isUnknownRecord2(response) ? response : {};
56344
56462
  const responseData = isUnknownRecord2(responseRecord.data) ? responseRecord.data : responseRecord;
56345
56463
  if (responseData.success === false) {
@@ -56356,7 +56474,7 @@ function useHidAmicoService() {
56356
56474
  const deadline = startedAt + timeoutSeconds * 1e3;
56357
56475
  let savedRow;
56358
56476
  do {
56359
- const rows = await loadPhysicalCardRows(client2, hidUserId);
56477
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
56360
56478
  savedRow = responseValue === null ? rows.find((row) => !beforeValues.has(String(row.value ?? ""))) : rows.find((row) => String(row.value ?? "") === String(responseValue));
56361
56479
  if (savedRow || Date.now() >= deadline)
56362
56480
  break;
@@ -56389,7 +56507,7 @@ function useHidAmicoService() {
56389
56507
  return { readerId, hidUserId, card, verified: true };
56390
56508
  } catch (error) {
56391
56509
  try {
56392
- await client2.cancelRemoteEnrollment();
56510
+ await client3.cancelRemoteEnrollment();
56393
56511
  } catch {
56394
56512
  }
56395
56513
  await repo.addEvent({
@@ -56402,15 +56520,15 @@ function useHidAmicoService() {
56402
56520
  throw error;
56403
56521
  } finally {
56404
56522
  await repo.releaseEnrollmentLock(readerId, lockOwner);
56405
- await client2.logout();
56523
+ await client3.logout();
56406
56524
  }
56407
56525
  }
56408
56526
  async function cancelUserCardEnrollment(readerId) {
56409
56527
  const reader = await getActiveReader(readerId);
56410
- const client2 = new HidAmicoClient(reader);
56528
+ const client3 = new HidAmicoClient(reader);
56411
56529
  try {
56412
- await client2.login();
56413
- await client2.cancelRemoteEnrollment();
56530
+ await client3.login();
56531
+ await client3.cancelRemoteEnrollment();
56414
56532
  const enrollmentWasRunning = await repo.releaseEnrollmentLock(readerId);
56415
56533
  await repo.addEvent({
56416
56534
  reader: readerId,
@@ -56420,27 +56538,27 @@ function useHidAmicoService() {
56420
56538
  });
56421
56539
  return { readerId, cancelled: true };
56422
56540
  } finally {
56423
- await client2.logout();
56541
+ await client3.logout();
56424
56542
  }
56425
56543
  }
56426
56544
  async function deleteUserCard(readerId, hidUserIdValue, cardIdValue) {
56427
56545
  const reader = await getActiveReader(readerId);
56428
56546
  const hidUserId = Number(hidUserIdValue);
56429
56547
  const cardId = Number(cardIdValue);
56430
- const client2 = new HidAmicoClient(reader);
56548
+ const client3 = new HidAmicoClient(reader);
56431
56549
  try {
56432
- await client2.login();
56433
- const rows = await loadPhysicalCardRows(client2, hidUserId);
56550
+ await client3.login();
56551
+ const rows = await loadPhysicalCardRows(client3, hidUserId);
56434
56552
  const cardRow = rows.find((row) => String(row.id ?? "") === String(cardId));
56435
56553
  if (!cardRow) {
56436
56554
  throw new import_node_server_utils149.BadRequestError("Physical HID card was not found for this HID user.");
56437
56555
  }
56438
56556
  const cardValue = String(normalizeHidCardValue(cardRow.value));
56439
- await client2.destroyObjects({
56557
+ await client3.destroyObjects({
56440
56558
  object: "cards",
56441
56559
  where: { cards: { id: cardId } }
56442
56560
  });
56443
- const verifiedRows = await loadPhysicalCardRows(client2, hidUserId);
56561
+ const verifiedRows = await loadPhysicalCardRows(client3, hidUserId);
56444
56562
  if (verifiedRows.some((row) => String(row.id ?? "") === String(cardId))) {
56445
56563
  throw new import_node_server_utils149.BadRequestError("The HID reader did not remove the physical card.");
56446
56564
  }
@@ -56463,17 +56581,17 @@ function useHidAmicoService() {
56463
56581
  });
56464
56582
  throw error;
56465
56583
  } finally {
56466
- await client2.logout();
56584
+ await client3.logout();
56467
56585
  }
56468
56586
  }
56469
56587
  async function getUserPinStatus(readerId, hidUserIdValue) {
56470
56588
  const reader = await getActiveReader(readerId);
56471
56589
  assertReaderCapability(reader, "pin");
56472
56590
  const hidUserId = Number(hidUserIdValue);
56473
- const client2 = new HidAmicoClient(reader);
56591
+ const client3 = new HidAmicoClient(reader);
56474
56592
  try {
56475
- await client2.login();
56476
- const response = await client2.loadObjects({
56593
+ await client3.login();
56594
+ const response = await client3.loadObjects({
56477
56595
  object: "pins",
56478
56596
  where: { pins: { user_id: hidUserId } },
56479
56597
  limit: 1,
@@ -56481,7 +56599,7 @@ function useHidAmicoService() {
56481
56599
  });
56482
56600
  return { readerId, hidUserId, pinEnrolled: getHidObjectRows(response, "pins").length > 0 };
56483
56601
  } finally {
56484
- await client2.logout();
56602
+ await client3.logout();
56485
56603
  }
56486
56604
  }
56487
56605
  async function setUserPin(readerId, hidUserIdValue, pin) {
@@ -56489,10 +56607,10 @@ function useHidAmicoService() {
56489
56607
  assertReaderCapability(reader, "pin");
56490
56608
  const hidUserId = Number(hidUserIdValue);
56491
56609
  const credentialId = createStableHidId(`user-pin:${readerId}:${hidUserId}`);
56492
- const client2 = new HidAmicoClient(reader);
56610
+ const client3 = new HidAmicoClient(reader);
56493
56611
  try {
56494
- await client2.login();
56495
- const userResponse = await client2.loadObjects({
56612
+ await client3.login();
56613
+ const userResponse = await client3.loadObjects({
56496
56614
  object: "users",
56497
56615
  where: { users: { id: hidUserId } },
56498
56616
  limit: 1,
@@ -56502,13 +56620,13 @@ function useHidAmicoService() {
56502
56620
  throw new import_node_server_utils149.BadRequestError("HID user must exist before assigning an access PIN.");
56503
56621
  }
56504
56622
  const [byUserResponse, byValueResponse] = await Promise.all([
56505
- client2.loadObjects({
56623
+ client3.loadObjects({
56506
56624
  object: "pins",
56507
56625
  where: { pins: { user_id: hidUserId } },
56508
56626
  limit: 10,
56509
56627
  offset: 0
56510
56628
  }),
56511
- client2.loadObjects({
56629
+ client3.loadObjects({
56512
56630
  object: "pins",
56513
56631
  where: { pins: { value: pin } },
56514
56632
  limit: 10,
@@ -56524,18 +56642,18 @@ function useHidAmicoService() {
56524
56642
  }
56525
56643
  const existingPin = existingPins[0];
56526
56644
  if (existingPin) {
56527
- await client2.modifyObjects({
56645
+ await client3.modifyObjects({
56528
56646
  object: "pins",
56529
56647
  where: { pins: { id: existingPin.id } },
56530
56648
  values: { value: pin, user_id: hidUserId }
56531
56649
  });
56532
56650
  } else {
56533
- await client2.createObjects({
56651
+ await client3.createObjects({
56534
56652
  object: "pins",
56535
56653
  values: [{ id: credentialId, value: pin, user_id: hidUserId }]
56536
56654
  });
56537
56655
  }
56538
- const savedResponse = await client2.loadObjects({
56656
+ const savedResponse = await client3.loadObjects({
56539
56657
  object: "pins",
56540
56658
  where: { pins: { user_id: hidUserId } },
56541
56659
  limit: 1,
@@ -56545,7 +56663,7 @@ function useHidAmicoService() {
56545
56663
  if (!savedPin || String(savedPin.value) !== pin) {
56546
56664
  throw new import_node_server_utils149.BadRequestError("The HID reader did not retain the access PIN.");
56547
56665
  }
56548
- await client2.setConfiguration({
56666
+ await client3.setConfiguration({
56549
56667
  identifier: {
56550
56668
  pin_identification_enabled: "1",
56551
56669
  multi_factor_authentication: "0"
@@ -56569,17 +56687,17 @@ function useHidAmicoService() {
56569
56687
  });
56570
56688
  throw error;
56571
56689
  } finally {
56572
- await client2.logout();
56690
+ await client3.logout();
56573
56691
  }
56574
56692
  }
56575
56693
  async function deleteUserPin(readerId, hidUserIdValue) {
56576
56694
  const reader = await getActiveReader(readerId);
56577
56695
  assertReaderCapability(reader, "pin");
56578
56696
  const hidUserId = Number(hidUserIdValue);
56579
- const client2 = new HidAmicoClient(reader);
56697
+ const client3 = new HidAmicoClient(reader);
56580
56698
  try {
56581
- await client2.login();
56582
- await client2.destroyObjects({
56699
+ await client3.login();
56700
+ await client3.destroyObjects({
56583
56701
  object: "pins",
56584
56702
  where: { pins: { user_id: hidUserId } }
56585
56703
  });
@@ -56601,7 +56719,7 @@ function useHidAmicoService() {
56601
56719
  });
56602
56720
  throw error;
56603
56721
  } finally {
56604
- await client2.logout();
56722
+ await client3.logout();
56605
56723
  }
56606
56724
  }
56607
56725
  async function revokeVisitorQr(readerId, visitorId) {
@@ -56613,44 +56731,44 @@ function useHidAmicoService() {
56613
56731
  "The generated HID user ID is assigned to another visitor."
56614
56732
  );
56615
56733
  }
56616
- const client2 = new HidAmicoClient(reader);
56734
+ const client3 = new HidAmicoClient(reader);
56617
56735
  try {
56618
- await client2.login();
56619
- const existingUserResponse = await client2.loadObjects({
56736
+ await client3.login();
56737
+ const existingUserResponse = await client3.loadObjects({
56620
56738
  object: "users",
56621
56739
  where: { users: { id: hidUserId } },
56622
56740
  limit: 1,
56623
56741
  offset: 0
56624
56742
  });
56625
56743
  const deviceUserExists = getHidObjectRows(existingUserResponse, "users").length > 0;
56626
- await client2.destroyObjects({
56744
+ await client3.destroyObjects({
56627
56745
  object: "qrcodes",
56628
56746
  where: { qrcodes: { user_id: hidUserId } }
56629
56747
  });
56630
- await client2.destroyObjects({
56748
+ await client3.destroyObjects({
56631
56749
  object: "cards",
56632
56750
  where: { cards: { user_id: hidUserId } }
56633
56751
  });
56634
56752
  if (reader.capabilities?.pin === true) {
56635
- await client2.destroyObjects({
56753
+ await client3.destroyObjects({
56636
56754
  object: "pins",
56637
56755
  where: { pins: { user_id: hidUserId } }
56638
56756
  });
56639
56757
  }
56640
- await client2.destroyObjects({
56758
+ await client3.destroyObjects({
56641
56759
  object: "user_access_rules",
56642
56760
  where: { user_access_rules: { user_id: hidUserId } }
56643
56761
  });
56644
- await client2.destroyObjects({
56762
+ await client3.destroyObjects({
56645
56763
  object: "user_groups",
56646
56764
  where: { user_groups: { user_id: hidUserId } }
56647
56765
  });
56648
56766
  const metadata = identity && isUnknownRecord2(identity.metadata) ? identity.metadata : {};
56649
56767
  if (deviceUserExists && metadata.facialEnrolled === true) {
56650
- await client2.deleteUserImage(hidUserId);
56768
+ await client3.deleteUserImage(hidUserId);
56651
56769
  }
56652
56770
  if (deviceUserExists) {
56653
- await client2.modifyObjects({
56771
+ await client3.modifyObjects({
56654
56772
  object: "users",
56655
56773
  where: { users: { id: hidUserId } },
56656
56774
  values: { end_time: Math.floor(Date.now() / 1e3) }
@@ -56661,7 +56779,7 @@ function useHidAmicoService() {
56661
56779
  if (reader.capabilities?.pin === true)
56662
56780
  credentialObjects.push("pins");
56663
56781
  for (const object of credentialObjects) {
56664
- const response = await client2.loadObjects({
56782
+ const response = await client3.loadObjects({
56665
56783
  object,
56666
56784
  where: { [object]: { user_id: hidUserId } },
56667
56785
  limit: 1,
@@ -56669,7 +56787,7 @@ function useHidAmicoService() {
56669
56787
  });
56670
56788
  credentialRemains || (credentialRemains = getHidObjectRows(response, object).length > 0);
56671
56789
  }
56672
- const savedUser = await client2.loadObjects({
56790
+ const savedUser = await client3.loadObjects({
56673
56791
  object: "users",
56674
56792
  where: { users: { id: hidUserId } },
56675
56793
  limit: 1,
@@ -56707,7 +56825,7 @@ function useHidAmicoService() {
56707
56825
  });
56708
56826
  throw error;
56709
56827
  } finally {
56710
- await client2.logout();
56828
+ await client3.logout();
56711
56829
  }
56712
56830
  }
56713
56831
  async function queueVisitorQrJob(readerId, visitorId, operation) {
@@ -56817,16 +56935,16 @@ function useHidAmicoService() {
56817
56935
  const reader = await getActiveReader(readerId);
56818
56936
  assertReaderCapability(reader, "facial");
56819
56937
  assertReaderPortal(reader, "enrolling facial recognition");
56820
- const client2 = new HidAmicoClient(reader);
56938
+ const client3 = new HidAmicoClient(reader);
56821
56939
  const timestamp = options.timestamp || Math.floor(Date.now() / 1e3);
56822
56940
  const match = options.match ?? true;
56823
56941
  try {
56824
- await client2.login();
56942
+ await client3.login();
56825
56943
  const numericUserId = Number(hidUserId);
56826
56944
  if (!Number.isSafeInteger(numericUserId) || numericUserId <= 0) {
56827
56945
  throw new import_node_server_utils149.BadRequestError("A valid HID user ID is required for facial enrollment.");
56828
56946
  }
56829
- const result = await client2.setUserImage(numericUserId, image, timestamp, match);
56947
+ const result = await client3.setUserImage(numericUserId, image, timestamp, match);
56830
56948
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56831
56949
  await repo.addEvent({
56832
56950
  reader: readerId,
@@ -56850,16 +56968,16 @@ function useHidAmicoService() {
56850
56968
  });
56851
56969
  throw error;
56852
56970
  } finally {
56853
- await client2.logout();
56971
+ await client3.logout();
56854
56972
  }
56855
56973
  }
56856
56974
  async function deleteUserImage(readerId, hidUserId) {
56857
56975
  const reader = await getActiveReader(readerId);
56858
56976
  assertReaderCapability(reader, "facial");
56859
- const client2 = new HidAmicoClient(reader);
56977
+ const client3 = new HidAmicoClient(reader);
56860
56978
  try {
56861
- await client2.login();
56862
- const result = await client2.deleteUserImage(hidUserId);
56979
+ await client3.login();
56980
+ const result = await client3.deleteUserImage(hidUserId);
56863
56981
  await repo.updateById(readerId, { lastSeenAt: /* @__PURE__ */ new Date() });
56864
56982
  await repo.addEvent({
56865
56983
  reader: readerId,
@@ -56877,28 +56995,28 @@ function useHidAmicoService() {
56877
56995
  });
56878
56996
  throw error;
56879
56997
  } finally {
56880
- await client2.logout();
56998
+ await client3.logout();
56881
56999
  }
56882
57000
  }
56883
57001
  async function getDoorState(id) {
56884
57002
  const reader = await getActiveReader(id);
56885
- const client2 = new HidAmicoClient(reader);
57003
+ const client3 = new HidAmicoClient(reader);
56886
57004
  try {
56887
- await client2.login();
56888
- const state = await client2.doorState();
57005
+ await client3.login();
57006
+ const state = await client3.doorState();
56889
57007
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56890
57008
  await repo.addEvent({ reader: id, site: reader.site, type: "door_state", payload: state });
56891
57009
  return state;
56892
57010
  } finally {
56893
- await client2.logout();
57011
+ await client3.logout();
56894
57012
  }
56895
57013
  }
56896
57014
  async function executeActions(id, actions) {
56897
57015
  const reader = await getActiveReader(id);
56898
- const client2 = new HidAmicoClient(reader);
57016
+ const client3 = new HidAmicoClient(reader);
56899
57017
  try {
56900
- await client2.login();
56901
- const result = await client2.executeActions(actions);
57018
+ await client3.login();
57019
+ const result = await client3.executeActions(actions);
56902
57020
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56903
57021
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions", payload: { actions, result } });
56904
57022
  return result;
@@ -56906,16 +57024,16 @@ function useHidAmicoService() {
56906
57024
  await repo.addEvent({ reader: id, site: reader.site, type: "execute_actions_failed", payload: { actions, message: getErrorMessage2(error) } });
56907
57025
  throw error;
56908
57026
  } finally {
56909
- await client2.logout();
57027
+ await client3.logout();
56910
57028
  }
56911
57029
  }
56912
57030
  async function getConfiguration(id, payload) {
56913
57031
  assertAllowedHidConfigurationRead(payload);
56914
57032
  const reader = await getActiveReader(id);
56915
- const client2 = new HidAmicoClient(reader);
57033
+ const client3 = new HidAmicoClient(reader);
56916
57034
  try {
56917
- await client2.login();
56918
- const result = await client2.getConfiguration(payload);
57035
+ await client3.login();
57036
+ const result = await client3.getConfiguration(payload);
56919
57037
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56920
57038
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration", payload: { request: payload, result } });
56921
57039
  return sanitizeHidPayload(result);
@@ -56923,7 +57041,7 @@ function useHidAmicoService() {
56923
57041
  await repo.addEvent({ reader: id, site: reader.site, type: "configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56924
57042
  throw error;
56925
57043
  } finally {
56926
- await client2.logout();
57044
+ await client3.logout();
56927
57045
  }
56928
57046
  }
56929
57047
  async function setConfiguration(id, payload) {
@@ -56935,10 +57053,10 @@ function useHidAmicoService() {
56935
57053
  );
56936
57054
  }
56937
57055
  assertAllowedHidConfiguration(payload);
56938
- const client2 = new HidAmicoClient(reader);
57056
+ const client3 = new HidAmicoClient(reader);
56939
57057
  try {
56940
- await client2.login();
56941
- const result = await client2.setConfiguration(payload);
57058
+ await client3.login();
57059
+ const result = await client3.setConfiguration(payload);
56942
57060
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56943
57061
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration", payload: { request: payload, result } });
56944
57062
  return sanitizeHidPayload(result);
@@ -56946,23 +57064,23 @@ function useHidAmicoService() {
56946
57064
  await repo.addEvent({ reader: id, site: reader.site, type: "set_configuration_failed", payload: { request: payload, message: getErrorMessage2(error) } });
56947
57065
  throw error;
56948
57066
  } finally {
56949
- await client2.logout();
57067
+ await client3.logout();
56950
57068
  }
56951
57069
  }
56952
57070
  async function getIntercomStatus(id) {
56953
57071
  const reader = await getActiveReader(id);
56954
57072
  assertReaderCapability(reader, "intercom");
56955
- const client2 = new HidAmicoClient(reader);
57073
+ const client3 = new HidAmicoClient(reader);
56956
57074
  try {
56957
- await client2.login();
57075
+ await client3.login();
56958
57076
  let result;
56959
57077
  try {
56960
- result = await client2.getSipStatus();
57078
+ result = await client3.getSipStatus();
56961
57079
  } catch (error) {
56962
57080
  if (!isSipStatusUnavailable(error)) {
56963
57081
  throw error;
56964
57082
  }
56965
- const configuration = await client2.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
57083
+ const configuration = await client3.getConfiguration({ pjsip: PJSIP_PUBLIC_CONFIGURATION_KEYS });
56966
57084
  result = buildSipStatusFallback(configuration, error);
56967
57085
  }
56968
57086
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
@@ -56973,16 +57091,16 @@ function useHidAmicoService() {
56973
57091
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_status_failed", payload: { message: getErrorMessage2(error) } });
56974
57092
  throw error;
56975
57093
  } finally {
56976
- await client2.logout();
57094
+ await client3.logout();
56977
57095
  }
56978
57096
  }
56979
57097
  async function makeIntercomCall(id, target) {
56980
57098
  const reader = await getActiveReader(id);
56981
57099
  assertReaderCapability(reader, "intercom");
56982
- const client2 = new HidAmicoClient(reader);
57100
+ const client3 = new HidAmicoClient(reader);
56983
57101
  try {
56984
- await client2.login();
56985
- const result = await client2.makeSipCall(target);
57102
+ await client3.login();
57103
+ const result = await client3.makeSipCall(target);
56986
57104
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
56987
57105
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call", payload: { target, result } });
56988
57106
  return result;
@@ -56990,16 +57108,16 @@ function useHidAmicoService() {
56990
57108
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_call_failed", payload: { target, message: getErrorMessage2(error) } });
56991
57109
  throw error;
56992
57110
  } finally {
56993
- await client2.logout();
57111
+ await client3.logout();
56994
57112
  }
56995
57113
  }
56996
57114
  async function finalizeIntercomCall(id) {
56997
57115
  const reader = await getActiveReader(id);
56998
57116
  assertReaderCapability(reader, "intercom");
56999
- const client2 = new HidAmicoClient(reader);
57117
+ const client3 = new HidAmicoClient(reader);
57000
57118
  try {
57001
- await client2.login();
57002
- const result = await client2.finalizeSipCall();
57119
+ await client3.login();
57120
+ const result = await client3.finalizeSipCall();
57003
57121
  await repo.updateById(id, { lastSeenAt: /* @__PURE__ */ new Date() });
57004
57122
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup", payload: result || {} });
57005
57123
  return result;
@@ -57007,7 +57125,7 @@ function useHidAmicoService() {
57007
57125
  await repo.addEvent({ reader: id, site: reader.site, type: "intercom_hangup_failed", payload: { message: getErrorMessage2(error) } });
57008
57126
  throw error;
57009
57127
  } finally {
57010
- await client2.logout();
57128
+ await client3.logout();
57011
57129
  }
57012
57130
  }
57013
57131
  function normalizePermissionLocation(value) {
@@ -57064,7 +57182,7 @@ function useHidAmicoService() {
57064
57182
  return "contractor";
57065
57183
  return "staff";
57066
57184
  }
57067
- async function provisionPermissionUser(client2, reader, binding) {
57185
+ async function provisionPermissionUser(client3, reader, binding) {
57068
57186
  const readerId = String(reader._id);
57069
57187
  const existingProfile = await repo.findProfileIdentity(readerId, binding.userId);
57070
57188
  const hidUserId = toPositiveInteger(existingProfile?.hidUserId) ?? createStableHidId(`profile:${readerId}:${binding.userId}`);
@@ -57080,7 +57198,7 @@ function useHidAmicoService() {
57080
57198
  throw new import_node_server_utils149.BadRequestError("The reader already uses this HID user ID for an unmanaged Amico user.");
57081
57199
  }
57082
57200
  const name2 = String(binding.name || "iService365 User").trim() || "iService365 User";
57083
- const existingUser = await client2.loadObjects({
57201
+ const existingUser = await client3.loadObjects({
57084
57202
  object: "users",
57085
57203
  where: { users: { id: hidUserId } },
57086
57204
  limit: 1,
@@ -57088,13 +57206,13 @@ function useHidAmicoService() {
57088
57206
  });
57089
57207
  const userValues = { name: name2, registration };
57090
57208
  if (getHidObjectRows(existingUser, "users").length) {
57091
- await client2.modifyObjects({
57209
+ await client3.modifyObjects({
57092
57210
  object: "users",
57093
57211
  where: { users: { id: hidUserId } },
57094
57212
  values: userValues
57095
57213
  });
57096
57214
  } else {
57097
- await client2.createObjects({
57215
+ await client3.createObjects({
57098
57216
  object: "users",
57099
57217
  values: [{ id: hidUserId, ...userValues }]
57100
57218
  });
@@ -57134,14 +57252,14 @@ function useHidAmicoService() {
57134
57252
  const uniqueBindings = [...new Map(
57135
57253
  bindings.map((binding) => [String(binding.userId), binding])
57136
57254
  ).values()];
57137
- const client2 = new HidAmicoClient(reader);
57255
+ const client3 = new HidAmicoClient(reader);
57138
57256
  try {
57139
- await client2.login();
57257
+ await client3.login();
57140
57258
  const uniqueUserIds = await Promise.all(
57141
- uniqueBindings.map((binding) => provisionPermissionUser(client2, reader, binding))
57259
+ uniqueBindings.map((binding) => provisionPermissionUser(client3, reader, binding))
57142
57260
  );
57143
57261
  const result = await reconcileStandaloneGroupAccess(
57144
- client2,
57262
+ client3,
57145
57263
  readerId,
57146
57264
  Number(reader.portalId),
57147
57265
  uniqueUserIds
@@ -57164,7 +57282,7 @@ function useHidAmicoService() {
57164
57282
  });
57165
57283
  throw error;
57166
57284
  } finally {
57167
- await client2.logout();
57285
+ await client3.logout();
57168
57286
  }
57169
57287
  }
57170
57288
  async function reconcileStoredReaderPermissions(readerId) {
@@ -68735,11 +68853,11 @@ function buildingInPlanFrame(building) {
68735
68853
  lifts
68736
68854
  };
68737
68855
  }
68738
- function openRmfDoorDriver(client2, doorName) {
68856
+ function openRmfDoorDriver(client3, doorName) {
68739
68857
  return {
68740
68858
  name: doorName,
68741
68859
  async read() {
68742
- const s = await client2.doorState(doorName).catch((e) => {
68860
+ const s = await client3.doorState(doorName).catch((e) => {
68743
68861
  if (/HTTP 404/.test(String(e?.message)))
68744
68862
  return null;
68745
68863
  throw e;
@@ -68757,13 +68875,13 @@ function openRmfDoorDriver(client2, doorName) {
68757
68875
  if (request2.requestedMode !== DOOR_MODE.OPEN && request2.requestedMode !== DOOR_MODE.CLOSED) {
68758
68876
  throw new OpenRmfError("A door can only be asked to open or close.");
68759
68877
  }
68760
- await client2.doorRequest(doorName, request2.requestedMode);
68878
+ await client3.doorRequest(doorName, request2.requestedMode);
68761
68879
  }
68762
68880
  };
68763
68881
  }
68764
- function openRmfLiftDriver(client2, liftName) {
68882
+ function openRmfLiftDriver(client3, liftName) {
68765
68883
  const destinations = /* @__PURE__ */ new Map();
68766
- const send2 = (requestType, sessionId, destination, doorState) => client2.liftRequest(liftName, {
68884
+ const send2 = (requestType, sessionId, destination, doorState) => client3.liftRequest(liftName, {
68767
68885
  request_type: requestType,
68768
68886
  door_mode: doorState,
68769
68887
  destination,
@@ -68772,7 +68890,7 @@ function openRmfLiftDriver(client2, liftName) {
68772
68890
  return {
68773
68891
  name: liftName,
68774
68892
  async read() {
68775
- const s = await client2.liftState(liftName).catch((e) => {
68893
+ const s = await client3.liftState(liftName).catch((e) => {
68776
68894
  if (/HTTP 404/.test(String(e?.message)))
68777
68895
  return null;
68778
68896
  throw e;
@@ -68808,18 +68926,18 @@ function openRmfLiftDriver(client2, liftName) {
68808
68926
  };
68809
68927
  }
68810
68928
  function createOpenRmfAdapter(options) {
68811
- const client2 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68929
+ const client3 = createOpenRmfClient(options && "config" in options ? options.config ?? null : openRmfConfig(), {
68812
68930
  fetch: options?.fetch,
68813
68931
  timeoutMs: options?.timeoutMs
68814
68932
  });
68815
68933
  async function states() {
68816
- const [fleets, building] = await Promise.all([client2.fleets(), client2.buildingMap().catch(() => null)]);
68934
+ const [fleets, building] = await Promise.all([client3.fleets(), client3.buildingMap().catch(() => null)]);
68817
68935
  return { fleets: fleets ?? [], building };
68818
68936
  }
68819
68937
  async function openInterruptions(taskId) {
68820
68938
  if (!taskId)
68821
68939
  return [];
68822
- const t = await client2.taskState(taskId).catch(() => null);
68940
+ const t = await client3.taskState(taskId).catch(() => null);
68823
68941
  return Object.entries(t?.interruptions ?? {}).filter(([, v]) => !v?.resumed_by).map(([token]) => token);
68824
68942
  }
68825
68943
  async function find(robotSn) {
@@ -68831,7 +68949,7 @@ function createOpenRmfAdapter(options) {
68831
68949
  return s ? { key: key2, s, building } : null;
68832
68950
  }
68833
68951
  return {
68834
- client: client2,
68952
+ client: client3,
68835
68953
  brand: OPEN_RMF_BRAND,
68836
68954
  displayName: OPEN_RMF_DISPLAY_NAME,
68837
68955
  capabilities: OPEN_RMF_CAPABILITIES,
@@ -68858,9 +68976,9 @@ function createOpenRmfAdapter(options) {
68858
68976
  const tokens = await openInterruptions(taskId);
68859
68977
  if (!tokens.length)
68860
68978
  throw new OpenRmfError("This robot's task is not paused.");
68861
- res2 = await client2.resumeTask(taskId, tokens);
68979
+ res2 = await client3.resumeTask(taskId, tokens);
68862
68980
  } else {
68863
- res2 = command.kind === "pause" ? await client2.interruptTask(taskId) : await client2.cancelTask(taskId);
68981
+ res2 = command.kind === "pause" ? await client3.interruptTask(taskId) : await client3.cancelTask(taskId);
68864
68982
  }
68865
68983
  if (res2 && res2.success === false)
68866
68984
  throw new OpenRmfError(`The fleet server refused to ${command.kind} the task.`);
@@ -68868,7 +68986,7 @@ function createOpenRmfAdapter(options) {
68868
68986
  }
68869
68987
  const wp = waypointsFor(hit.building, hit.s.location);
68870
68988
  const request2 = taskRequestFor(command, wp.cleaningZones.length ? "cleaning" : "security", wp);
68871
- const res = await client2.robotTask(hit.key.fleet, hit.key.robot, request2);
68989
+ const res = await client3.robotTask(hit.key.fleet, hit.key.robot, request2);
68872
68990
  if (!res?.success)
68873
68991
  throw new OpenRmfError("The fleet server did not accept the task.");
68874
68992
  },
@@ -68884,7 +69002,7 @@ function createOpenRmfAdapter(options) {
68884
69002
  const taskId = hit?.s.task_id;
68885
69003
  if (!hit || !taskId)
68886
69004
  return none;
68887
- const t = await client2.taskState(taskId).catch(() => null);
69005
+ const t = await client3.taskState(taskId).catch(() => null);
68888
69006
  if (!t || !/^patrol$/i.test(String(t.category ?? "")))
68889
69007
  return none;
68890
69008
  const level2 = hit.building?.levels.find((l) => l.name === hit.s.location?.map);
@@ -69979,10 +70097,10 @@ function fetchPadbotMqttCredentials(credentials) {
69979
70097
  return createPadbotClient(credentials).call(PADBOT_PATHS.mqttCredentials, {});
69980
70098
  }
69981
70099
  async function listPadbotAlarmsSince(credentials, serials, startTime) {
69982
- const client2 = createPadbotClient(credentials);
70100
+ const client3 = createPadbotClient(credentials);
69983
70101
  const out = [];
69984
70102
  for (let p = 1; p <= 3; p++) {
69985
- const d = await client2.call(PADBOT_PATHS.alarms, { serialNumbers: serials.slice(0, 100), startTime, pageNumber: p, pageSize: 100 });
70103
+ const d = await client3.call(PADBOT_PATHS.alarms, { serialNumbers: serials.slice(0, 100), startTime, pageNumber: p, pageSize: 100 });
69986
70104
  out.push(...asList(d));
69987
70105
  if (p >= (Number(d?.totalPages) || 0))
69988
70106
  break;
@@ -75182,16 +75300,16 @@ function useRobotMapController(deps) {
75182
75300
  const config2 = openRmfConfig();
75183
75301
  if (!config2)
75184
75302
  throw new import_node_server_utils175.NotFoundError("Fleet Core is not configured on this server.");
75185
- const client2 = createOpenRmfClient(config2);
75303
+ const client3 = createOpenRmfClient(config2);
75186
75304
  if (value.format === "rmf") {
75187
- const rmf = rmfFromFleetCore(await client2.buildingMap());
75305
+ const rmf = rmfFromFleetCore(await client3.buildingMap());
75188
75306
  res.json({ source: "fleet-core", rmf, summary: rmfSummary(rmf) });
75189
75307
  return;
75190
75308
  }
75191
- const building = buildingInPlanFrame(await client2.buildingMap());
75309
+ const building = buildingInPlanFrame(await client3.buildingMap());
75192
75310
  const [doorStates, liftStates] = await Promise.all([
75193
- Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client2, d.name).read().catch(() => null))),
75194
- Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(client2, l.name).read().catch(() => null)))
75311
+ Promise.all(building.doors.slice(0, 100).map((d) => openRmfDoorDriver(client3, d.name).read().catch(() => null))),
75312
+ Promise.all(building.lifts.slice(0, 20).map((l) => openRmfLiftDriver(client3, l.name).read().catch(() => null)))
75195
75313
  ]);
75196
75314
  res.json({
75197
75315
  source: "fleet-core",
@@ -101278,11 +101396,11 @@ function useAuthServiceV2() {
101278
101396
  "Refresh token already used. Please log in again."
101279
101397
  );
101280
101398
  }
101281
- const client2 = import_node_server_utils292.useAtlas.getClient();
101282
- if (!client2) {
101399
+ const client3 = import_node_server_utils292.useAtlas.getClient();
101400
+ if (!client3) {
101283
101401
  throw new import_node_server_utils292.InternalServerError("Unable to connect to server.");
101284
101402
  }
101285
- const dbSession = client2.startSession();
101403
+ const dbSession = client3.startSession();
101286
101404
  let newRefreshToken;
101287
101405
  try {
101288
101406
  dbSession.startTransaction();
@@ -103013,7 +103131,7 @@ function useUserServiceV2() {
103013
103131
  session?.endSession();
103014
103132
  }
103015
103133
  }
103016
- const s32 = new import_node_server_utils296.useS3({
103134
+ const s33 = new import_node_server_utils296.useS3({
103017
103135
  accessKeyId: SPACES_ACCESS_KEY,
103018
103136
  secretAccessKey: SPACES_SECRET_KEY,
103019
103137
  endpoint: SPACES_ENDPOINT,
@@ -103034,14 +103152,14 @@ function useUserServiceV2() {
103034
103152
  };
103035
103153
  try {
103036
103154
  const id = await createFile(_file, session);
103037
- await s32.uploadObject({
103155
+ await putSpacesObject({
103038
103156
  key: id,
103039
103157
  body: file.buffer,
103040
103158
  contentType: file.mimetype
103041
103159
  });
103042
103160
  if (previousProfile) {
103043
103161
  await deleteFileById(previousProfile, session);
103044
- await s32.deleteObject(previousProfile);
103162
+ await s33.deleteObject(previousProfile);
103045
103163
  }
103046
103164
  await _updateUserFieldById(
103047
103165
  { _id: user, field: "profile", value: id },
@@ -105938,10 +106056,10 @@ function useChatPrelovedService() {
105938
106056
  const { add: _addChat } = useChatPrelovedRepo();
105939
106057
  const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
105940
106058
  async function add(value) {
105941
- const client2 = import_node_server_utils314.useAtlas.getClient();
105942
- if (!client2)
106059
+ const client3 = import_node_server_utils314.useAtlas.getClient();
106060
+ if (!client3)
105943
106061
  throw new import_node_server_utils314.InternalServerError("Unable to connect to server.");
105944
- const session = client2.startSession();
106062
+ const session = client3.startSession();
105945
106063
  session.startTransaction();
105946
106064
  try {
105947
106065
  let channelId = value.channelId;
@@ -106394,14 +106512,14 @@ function useBidPrelovedService() {
106394
106512
  const { add: _addChat } = useChatPrelovedRepo();
106395
106513
  const { updateStatus } = usePostPrelovedRepo();
106396
106514
  async function createBid(value) {
106397
- const client2 = import_node_server_utils320.useAtlas.getClient();
106398
- if (!client2)
106515
+ const client3 = import_node_server_utils320.useAtlas.getClient();
106516
+ if (!client3)
106399
106517
  throw new import_node_server_utils320.InternalServerError("Unable to connect to server.");
106400
106518
  const buyerId = value.buyerId;
106401
106519
  const receiverId = value.receiverId;
106402
106520
  const postId = value.postId;
106403
106521
  const messageText = value.message || "";
106404
- const session = client2.startSession();
106522
+ const session = client3.startSession();
106405
106523
  session.startTransaction();
106406
106524
  try {
106407
106525
  const bidId = await _addBid(value, session);
@@ -108668,8 +108786,8 @@ async function staffOnly(req) {
108668
108786
  }
108669
108787
  async function clientAndSites(org) {
108670
108788
  const d = db2();
108671
- const client2 = await d.collection("organizations").findOne({ _id: new import_mongodb201.ObjectId(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
108672
- if (!client2)
108789
+ const client3 = await d.collection("organizations").findOne({ _id: new import_mongodb201.ObjectId(org), status: { $ne: "deleted" } }, { projection: { name: 1, nature: 1, status: 1 } });
108790
+ if (!client3)
108673
108791
  throw new import_node_server_utils330.NotFoundError("Client not found.");
108674
108792
  const own = await d.collection("sites").find({ orgId: both3(org), status: { $ne: "deleted" } }, { projection: { name: 1 } }).toArray();
108675
108793
  const served = await d.collection("customer.sites").find({ org: both3(org), status: { $ne: "deleted" }, site: { $exists: true, $nin: [null, ""] } }, { projection: { name: 1, site: 1 } }).toArray();
@@ -108682,7 +108800,7 @@ async function clientAndSites(org) {
108682
108800
  sites.set(id, String(s.name ?? ""));
108683
108801
  }
108684
108802
  return {
108685
- client: { _id: org, name: String(client2.name ?? ""), nature: String(client2.nature ?? "") },
108803
+ client: { _id: org, name: String(client3.name ?? ""), nature: String(client3.nature ?? "") },
108686
108804
  sites: [...sites].map(([_id, name2]) => ({ _id, name: name2 })).sort((a, b) => a.name.localeCompare(b.name))
108687
108805
  };
108688
108806
  }
@@ -108750,14 +108868,14 @@ function useStaffAccessController() {
108750
108868
  const sid = getSessionIdFromRequest(req);
108751
108869
  if (!sid)
108752
108870
  throw new import_node_server_utils330.UnauthorizedError("Not authorized.");
108753
- const { client: client2, sites: list } = await clientAndSites(value.org);
108871
+ const { client: client3, sites: list } = await clientAndSites(value.org);
108754
108872
  const site = value.site ? list.find((s) => s._id === value.site) : null;
108755
108873
  if (value.site && !site)
108756
108874
  throw new import_node_server_utils330.BadRequestError("That site does not belong to this client.");
108757
108875
  const view = {
108758
108876
  user: actor,
108759
- org: client2._id,
108760
- orgName: client2.name,
108877
+ org: client3._id,
108878
+ orgName: client3.name,
108761
108879
  site: site?._id ?? "",
108762
108880
  siteName: site?.name ?? "",
108763
108881
  app: value.app,
@@ -108767,8 +108885,8 @@ function useStaffAccessController() {
108767
108885
  await recordConsoleAction({
108768
108886
  action: "staff-view.entered" /* STAFF_VIEW_ENTERED */,
108769
108887
  actor,
108770
- org: client2._id,
108771
- target: view.site || client2._id,
108888
+ org: client3._id,
108889
+ target: view.site || client3._id,
108772
108890
  targetType: view.site ? "site" /* SITE */ : "organization" /* ORGANIZATION */,
108773
108891
  after: pickAuditFields("staff-view.entered" /* STAFF_VIEW_ENTERED */, { ...view, reason: value.reason }) ?? null
108774
108892
  });
@@ -110031,6 +110149,7 @@ function usePersonalEmergencyChainController() {
110031
110149
  SERVICE_TYPE_LABELS,
110032
110150
  SITE_STATES_MAX,
110033
110151
  SOFTWARE_VERSION_ENDPOINT,
110152
+ STAFF_CLIENT_PERMISSIONS,
110034
110153
  STAFF_VIEW_APPS,
110035
110154
  STAFF_VIEW_HISTORY_ACTIONS,
110036
110155
  SUBCONTRACT_ADMIN_REFUSAL,
@@ -110646,6 +110765,7 @@ function usePersonalEmergencyChainController() {
110646
110765
  snapshotRefusalReason,
110647
110766
  splitRobotSn,
110648
110767
  staffMayBypass,
110768
+ staffReachesEveryClient,
110649
110769
  staffViewWriteAudit,
110650
110770
  startDemoTracking,
110651
110771
  startPadbotDrive,