@7365admin1/layer-common 4.17.1-staging.332 → 4.17.1-staging.334

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.
@@ -401,7 +401,10 @@ const exportForm = reactive({
401
401
  });
402
402
 
403
403
  const statusOptions = ["Authorized", "Not Authorized", "Unknown"];
404
- const accessMethodFilterOptions = ["Facial", "QR Code", "ID and Password", "PIN", "Card"];
404
+ const accessMethodFilterOptions = ["Facial", "QR Code", "ID and Password", "PIN", "Card", "Intercom"];
405
+
406
+ /** The persisted event the resident app records when it opens a door on a call. */
407
+ const INTERCOM_DOOR_OPEN_EVENT = "intercom_door_open";
405
408
  const accessMethodOptions = ["All", ...accessMethodFilterOptions];
406
409
 
407
410
  const readerOptions = computed(() =>
@@ -606,7 +609,7 @@ async function loadDashboard() {
606
609
  resetDashboardData();
607
610
  try {
608
611
  const isVisitorTab = activeTab.value === "visitor";
609
- const [logResponse, hidAccessLogResponse, visitorResponse, readerUserResponse] = await Promise.all([
612
+ const [logResponse, intercomLogResponse, hidAccessLogResponse, visitorResponse, readerUserResponse] = await Promise.all([
610
613
  loadDashboardSource(
611
614
  getLogs(selectedReaderId.value, {
612
615
  page: page.value,
@@ -615,6 +618,20 @@ async function loadDashboard() {
615
618
  null,
616
619
  "persisted access logs",
617
620
  ),
621
+ // Door opens from the resident app during an intercom call. The reader
622
+ // never logs a DTMF door open, so these exist only as persisted events
623
+ // and are fetched by type: the general page above is shared with every
624
+ // other event the reader emits and is dropped whenever the reader has
625
+ // live logs, which it always has.
626
+ loadDashboardSource(
627
+ getLogs(selectedReaderId.value, {
628
+ page: page.value,
629
+ limit,
630
+ type: INTERCOM_DOOR_OPEN_EVENT,
631
+ }),
632
+ null,
633
+ "intercom door-open logs",
634
+ ),
618
635
  loadDashboardSource(
619
636
  getReaderAccessLogs(selectedReaderId.value, {
620
637
  page: page.value,
@@ -681,9 +698,14 @@ async function loadDashboard() {
681
698
  // identity metadata here: it can contain a stale photo from another user.
682
699
  allIdentities.value = readerUsers;
683
700
  identities.value = readerUsers;
684
- logs.value = liveItems.length
685
- ? []
686
- : logResponse?.items ?? logResponse?.data?.items ?? logResponse?.data?.logs ?? [];
701
+ const intercomItems = intercomLogResponse?.items ?? intercomLogResponse?.data?.items ?? intercomLogResponse?.data?.logs ?? [];
702
+ logs.value = [
703
+ ...(liveItems.length
704
+ ? []
705
+ : logResponse?.items ?? logResponse?.data?.items ?? logResponse?.data?.logs ?? []),
706
+ // Always kept: the reader has no live counterpart for these.
707
+ ...intercomItems,
708
+ ];
687
709
  liveAccessLogs.value = liveItems;
688
710
  serverPages.value = Number(hidAccessLogResponse?.pages ?? hidAccessLogResponse?.data?.pages ?? 1);
689
711
  serverPageRange.value = String(
@@ -819,6 +841,8 @@ function getAccessMethod(identity: HidAccessRecord, log?: HidAccessRecord) {
819
841
  id_password: "ID and Password",
820
842
  pin: "PIN",
821
843
  card: "Card",
844
+ // Set by the API on intercom_door_open events; no reader field implies it.
845
+ intercom: "Intercom",
822
846
  };
823
847
  const normalizedMethod = String(payload.normalizedMethod || "");
824
848
  if (normalizedMethodLabels[normalizedMethod]) return normalizedMethodLabels[normalizedMethod];
@@ -559,22 +559,50 @@
559
559
  />
560
560
  </template>
561
561
 
562
- <!-- Cards are assigned by entering the value. Reading one at the
563
- reader was removed with its own progress alert and Cancel
564
- button, which existed only to narrate that wait. The endpoints
565
- behind it are untouched and still served by the API. -->
562
+ <v-alert
563
+ v-if="enrollingCard"
564
+ type="info"
565
+ variant="tonal"
566
+ density="compact"
567
+ class="mt-4"
568
+ >
569
+ Present the physical card to the selected Amico reader. The request will time out after 30 seconds.
570
+ </v-alert>
571
+
572
+ <!-- Reading the card at the reader is the primary way in: it is the
573
+ only one that does not require knowing the facility code and card
574
+ number up front, which are printed on nothing the operator holds.
575
+ Assigning by hand stays for the cards whose values are already
576
+ known. -->
566
577
  <div class="hid-card-actions mt-4">
567
578
  <AppButton
568
579
  variant="secondary"
569
- :disabled="savingCard || !cardProfileConfigured"
580
+ :disabled="savingCard || enrollingCard || !cardProfileConfigured"
570
581
  @click="assignPhysicalCard"
571
582
  >
572
583
  Assign Manually
573
584
  </AppButton>
585
+ <AppButton
586
+ icon="mdi-contactless-payment"
587
+ :disabled="savingCard || enrollingCard || !cardProfileConfigured"
588
+ @click="enrollPhysicalCard"
589
+ >
590
+ Read at Reader
591
+ </AppButton>
592
+ <AppButton
593
+ v-if="enrollingCard"
594
+ variant="ghost"
595
+ :disabled="cancellingCard"
596
+ @click="cancelPhysicalCardEnrollment"
597
+ >
598
+ {{ cancellingCard ? "Cancelling…" : "Cancel Reading" }}
599
+ </AppButton>
574
600
  </div>
575
601
  </v-card-text>
576
602
  <v-card-actions class="screen-modal__footer">
577
- <AppButton variant="ghost" @click="cardDialog = false">
603
+ <!-- Closing mid-read would leave the reader listening with nothing
604
+ to receive the card it reads. -->
605
+ <AppButton variant="ghost" :disabled="enrollingCard" @click="cardDialog = false">
578
606
  Close
579
607
  </AppButton>
580
608
  </v-card-actions>
@@ -644,6 +672,8 @@ const {
644
672
  deleteUserImage,
645
673
  getUserCards,
646
674
  assignUserCard,
675
+ enrollUserCard,
676
+ cancelUserCardEnrollment,
647
677
  deleteUserCard,
648
678
  getUserPinStatus,
649
679
  setUserPin,
@@ -742,6 +772,15 @@ const physicalCardsByUserId = ref<Record<string, HidCard[]>>({});
742
772
  const physicalCardErrorsByUserId = ref<Record<string, string>>({});
743
773
  const loadingCards = ref(false);
744
774
  const savingCard = ref(false);
775
+ const enrollingCard = ref(false);
776
+ /*
777
+ * Cancelling makes the in-flight enrol REJECT, and that rejection is expected
778
+ * rather than a failure. Without this flag the cancel raises an error toast on
779
+ * top of the one confirming it, which reads as the cancel having gone wrong.
780
+ */
781
+ const cardEnrollmentCancelled = ref(false);
782
+ /** The cancel's own round trip to the reader — a second or two, not the enrol's. */
783
+ const cancellingCard = ref(false);
745
784
  const deletingCardId = ref("");
746
785
  const showPin = ref(false);
747
786
  const pinEnrolled = ref(false);
@@ -2165,6 +2204,82 @@ async function assignPhysicalCard() {
2165
2204
  }
2166
2205
  }
2167
2206
 
2207
+ /**
2208
+ * Read a physical card by presenting it to the reader.
2209
+ *
2210
+ * The way most cards get assigned, because it is the only one that does not
2211
+ * require knowing the facility code and card number in advance - neither is
2212
+ * printed on the card, and an operator holding a blank fob has no way to look
2213
+ * them up. The reader listens for 30 seconds and reports what it read.
2214
+ */
2215
+ async function enrollPhysicalCard() {
2216
+ const { readerId, hidUserId } = getCardReaderAndUser();
2217
+ if (!readerId || !hidUserId) return;
2218
+
2219
+ enrollingCard.value = true;
2220
+ cardEnrollmentCancelled.value = false;
2221
+ try {
2222
+ await enrollUserCard(readerId, hidUserId, cardForm.cardType, 30);
2223
+ await loadPhysicalCards();
2224
+ await loadUsers();
2225
+ showToast("Physical HID card read and enrolled on the reader.");
2226
+ } catch (error: unknown) {
2227
+ // Cancelling rejects the request above. That is the operator getting what
2228
+ // they asked for, so it must not also be reported as a failure.
2229
+ if (!cardEnrollmentCancelled.value) {
2230
+ showToast(getHidErrorMessage(error), "error");
2231
+ }
2232
+ } finally {
2233
+ enrollingCard.value = false;
2234
+ }
2235
+ }
2236
+
2237
+ /**
2238
+ * Stop the reader listening.
2239
+ *
2240
+ * Told to the DEVICE, not just the screen: abandoning the request on this side
2241
+ * would leave the reader waiting out its 30 seconds and enrolling whatever card
2242
+ * was presented in the meantime.
2243
+ */
2244
+ /**
2245
+ * Stop the reader listening, and hand the dialog straight back.
2246
+ *
2247
+ * Told to the DEVICE, not just the screen: abandoning the request on this side
2248
+ * would leave the reader waiting out its remaining seconds and enrolling
2249
+ * whatever card was presented in the meantime.
2250
+ *
2251
+ * The part worth understanding is what the ENROL request does next. The server
2252
+ * cannot tell a cancelled read from a failed one - the reader simply reports no
2253
+ * card - so the enrol that is still in flight ends as a 400, seconds after the
2254
+ * cancel. Waiting for it was the bug: Cancel appeared to do nothing until that
2255
+ * rejection finally arrived.
2256
+ *
2257
+ * So the dialog is released as soon as the DEVICE confirms it has stopped, and
2258
+ * the doomed enrol is left to land on its own. `cardEnrollmentCancelled` is set
2259
+ * before anything is awaited, which is what keeps its 400 silent.
2260
+ */
2261
+ async function cancelPhysicalCardEnrollment() {
2262
+ const { readerId } = getCardReaderAndUser();
2263
+ if (!readerId) return;
2264
+ // Set first, awaited second: the enrol can reject at any point from here.
2265
+ cardEnrollmentCancelled.value = true;
2266
+ cancellingCard.value = true;
2267
+ try {
2268
+ await cancelUserCardEnrollment(readerId);
2269
+ // Only now, because the enrollment lock is released by the call above.
2270
+ // Re-enabling Read at Reader any earlier invites a second attempt that
2271
+ // the reader refuses with "already running".
2272
+ enrollingCard.value = false;
2273
+ showToast("Physical HID card reading cancelled.");
2274
+ } catch (error: unknown) {
2275
+ // The cancel itself failing is real and worth saying: the reader may still
2276
+ // be listening, so the dialog stays in its reading state.
2277
+ showToast(getHidErrorMessage(error), "error");
2278
+ } finally {
2279
+ cancellingCard.value = false;
2280
+ }
2281
+ }
2282
+
2168
2283
  async function removePhysicalCard(card: HidCard) {
2169
2284
  if (!window.confirm(`Remove physical HID card ${formatPhysicalCard(card)}?`)) return;
2170
2285
  const { readerId, hidUserId } = getCardReaderAndUser();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.17.1-staging.332",
5
+ "version": "4.17.1-staging.334",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",