@7365admin1/core 3.32.2-staging.73 → 3.32.2-staging.74

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
@@ -75089,6 +75089,91 @@ async function configureVisitorQrReader(client, qrFormat) {
75089
75089
  identifier: { qrcode_identification_enabled: "1" }
75090
75090
  });
75091
75091
  }
75092
+ async function ensureVisitorAccessAuthorization(client, readerId, readerLocation, hidUserId) {
75093
+ const accessRuleId = createStableHidId(`visitor-access-rule:${readerId}`);
75094
+ const existingRuleResponse = await client.loadObjects({
75095
+ object: "access_rules",
75096
+ where: { access_rules: { id: accessRuleId } },
75097
+ limit: 1,
75098
+ offset: 0
75099
+ });
75100
+ if (getHidObjectRows(existingRuleResponse, "access_rules").length) {
75101
+ await client.modifyObjects({
75102
+ object: "access_rules",
75103
+ where: { access_rules: { id: accessRuleId } },
75104
+ values: {
75105
+ name: "iService365 Visitor Access",
75106
+ type: 1,
75107
+ priority: 0
75108
+ }
75109
+ });
75110
+ } else {
75111
+ await client.createObjects({
75112
+ object: "access_rules",
75113
+ values: [{
75114
+ id: accessRuleId,
75115
+ name: "iService365 Visitor Access",
75116
+ type: 1,
75117
+ priority: 0
75118
+ }]
75119
+ });
75120
+ }
75121
+ const portalsResponse = await client.loadObjects({
75122
+ object: "portals",
75123
+ limit: 100,
75124
+ offset: 0
75125
+ });
75126
+ const portals = getHidObjectRows(portalsResponse, "portals").map((portal) => ({
75127
+ id: Number(portal.id),
75128
+ name: String(portal.name || "").trim()
75129
+ })).filter((portal) => Number.isSafeInteger(portal.id) && portal.id > 0);
75130
+ if (!portals.length) {
75131
+ throw new import_node_server_utils266.BadRequestError(
75132
+ "The HID reader has no portal configured for visitor access."
75133
+ );
75134
+ }
75135
+ const normalizedLocation = String(readerLocation || "").trim().toLowerCase();
75136
+ const locationMatches = normalizedLocation ? portals.filter((portal) => {
75137
+ const portalName = portal.name.toLowerCase();
75138
+ return portalName === normalizedLocation || portalName.includes(normalizedLocation) || normalizedLocation.includes(portalName);
75139
+ }) : [];
75140
+ const selectedPortals = locationMatches.length === 1 ? locationMatches : portals.length === 1 ? portals : [];
75141
+ if (!selectedPortals.length) {
75142
+ throw new import_node_server_utils266.BadRequestError(
75143
+ "The HID reader has multiple portals. Match the reader location to one portal before issuing visitor access."
75144
+ );
75145
+ }
75146
+ const portalIds = selectedPortals.map((portal) => portal.id);
75147
+ const userAccessRulesResponse = await client.loadObjects({
75148
+ object: "user_access_rules",
75149
+ where: { user_access_rules: { user_id: hidUserId, access_rule_id: accessRuleId } },
75150
+ limit: 1,
75151
+ offset: 0
75152
+ });
75153
+ if (!getHidObjectRows(userAccessRulesResponse, "user_access_rules").length) {
75154
+ await client.createObjects({
75155
+ object: "user_access_rules",
75156
+ values: [{ user_id: hidUserId, access_rule_id: accessRuleId }]
75157
+ });
75158
+ }
75159
+ const portalAccessRulesResponse = await client.loadObjects({
75160
+ object: "portal_access_rules",
75161
+ where: { portal_access_rules: { access_rule_id: accessRuleId } },
75162
+ limit: 100,
75163
+ offset: 0
75164
+ });
75165
+ const linkedPortalIds = new Set(
75166
+ getHidObjectRows(portalAccessRulesResponse, "portal_access_rules").map((relation) => Number(relation.portal_id)).filter((portalId) => Number.isSafeInteger(portalId) && portalId > 0)
75167
+ );
75168
+ const missingPortalLinks = portalIds.filter((portalId) => !linkedPortalIds.has(portalId)).map((portalId) => ({ portal_id: portalId, access_rule_id: accessRuleId }));
75169
+ if (missingPortalLinks.length) {
75170
+ await client.createObjects({
75171
+ object: "portal_access_rules",
75172
+ values: missingPortalLinks
75173
+ });
75174
+ }
75175
+ return { accessRuleId, portalIds };
75176
+ }
75092
75177
  function getRelayAuth() {
75093
75178
  const username = process.env.HID_AMICO_RELAY_USERNAME;
75094
75179
  const password = process.env.HID_AMICO_RELAY_PASSWORD;
@@ -75712,6 +75797,12 @@ function useHidAmicoService() {
75712
75797
  values: [{ id: hidUserId, ...user }]
75713
75798
  });
75714
75799
  }
75800
+ const authorization = await ensureVisitorAccessAuthorization(
75801
+ client,
75802
+ readerId,
75803
+ reader.location,
75804
+ hidUserId
75805
+ );
75715
75806
  for (const object of ["qrcodes", "cards"]) {
75716
75807
  const existingCredentialResponse = await client.loadObjects({
75717
75808
  object,
@@ -75761,6 +75852,8 @@ function useHidAmicoService() {
75761
75852
  qrFormat: value.qrFormat,
75762
75853
  credentialObject: credential.object,
75763
75854
  credentialId: credential.credentialId,
75855
+ accessRuleId: authorization.accessRuleId,
75856
+ portalIds: authorization.portalIds,
75764
75857
  issuedAt: issuedAt.toISOString(),
75765
75858
  expiresAt: expiresAt.toISOString()
75766
75859
  }
@@ -75784,6 +75877,8 @@ function useHidAmicoService() {
75784
75877
  visitor: value.visitorId,
75785
75878
  hidUserId,
75786
75879
  credentialObject: credential.object,
75880
+ accessRuleId: authorization.accessRuleId,
75881
+ portalIds: authorization.portalIds,
75787
75882
  issuedAt: issuedAt.toISOString(),
75788
75883
  expiresAt: expiresAt.toISOString()
75789
75884
  }
@@ -75975,6 +76070,12 @@ function useHidAmicoService() {
75975
76070
  values: [{ id: hidUserId, ...user }]
75976
76071
  });
75977
76072
  }
76073
+ const authorization = await ensureVisitorAccessAuthorization(
76074
+ client,
76075
+ readerId,
76076
+ reader.location,
76077
+ hidUserId
76078
+ );
75978
76079
  const result = await client.setUserImage(hidUserId, image, timestamp, match);
75979
76080
  const existingIdentity = await repo.findExistingIdentity({ reader: readerId, hidUserId });
75980
76081
  const existingMetadata = existingIdentity && isUnknownRecord(existingIdentity.metadata) ? existingIdentity.metadata : {};
@@ -75990,6 +76091,8 @@ function useHidAmicoService() {
75990
76091
  temporary: true,
75991
76092
  facialEnrolled: true,
75992
76093
  facialEnrolledAt: issuedAt.toISOString(),
76094
+ accessRuleId: authorization.accessRuleId,
76095
+ portalIds: authorization.portalIds,
75993
76096
  expiresAt: expiresAt.toISOString()
75994
76097
  }
75995
76098
  };
@@ -76011,6 +76114,8 @@ function useHidAmicoService() {
76011
76114
  visitor: visitorId,
76012
76115
  hidUserId,
76013
76116
  imageBytes: image.length,
76117
+ accessRuleId: authorization.accessRuleId,
76118
+ portalIds: authorization.portalIds,
76014
76119
  issuedAt: issuedAt.toISOString(),
76015
76120
  expiresAt: expiresAt.toISOString(),
76016
76121
  result: summarizeUserImageResult(result)