@7365admin1/layer-common 4.21.4-staging.345 → 4.21.4-staging.347

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.
@@ -433,7 +433,10 @@ const {
433
433
  bulkPhysicalAccessCard: _bulkPhysicalAccessCard,
434
434
  getBlockLevelUnitList: _getBlockLevelUnitList,
435
435
  } = useAccessManagement();
436
- const { getBySiteId: _getEntryPassSettings } = useSiteEntryPassSettings();
436
+ const {
437
+ getBySiteId: _getEntryPassSettings,
438
+ getEncryptedAcmUrl: _getEncryptedAcmUrl,
439
+ } = useSiteEntryPassSettings();
437
440
  const { getFileUrl } = useFile();
438
441
 
439
442
  const config = useRuntimeConfig();
@@ -588,9 +591,7 @@ watch(uploadMode, (mode) => {
588
591
 
589
592
  onMounted(async () => {
590
593
  try {
591
- const { encrypted: acmUrl } = await $fetch<{ encrypted: string }>(
592
- "/api/encrypt-acm-url"
593
- );
594
+ const acmUrl = await _getEncryptedAcmUrl(siteId);
594
595
  encryptedAcmUrl.value = acmUrl;
595
596
  const [doorLevels, liftLevels, groups] = await Promise.all([
596
597
  _getDoorAccessLevels(acmUrl),
@@ -203,6 +203,7 @@ const {
203
203
  getBlockLevelUnitList: _getBlockLevelUnitList,
204
204
  } = useAccessManagement();
205
205
  const { requiredRule } = useUtils();
206
+ const { getEncryptedAcmUrl } = useSiteEntryPassSettings();
206
207
 
207
208
  const route = useRoute();
208
209
  const siteId = computed(() => props.siteId || (route.params.site as string));
@@ -294,7 +295,7 @@ onMounted(async () => {
294
295
 
295
296
  const [blockLevelResult, acmResult] = await Promise.allSettled([
296
297
  _getBlockLevelUnitList(siteId.value),
297
- $fetch<{ encrypted: string }>("/api/encrypt-acm-url"),
298
+ getEncryptedAcmUrl(siteId.value),
298
299
  ]);
299
300
 
300
301
  // Blocks / Levels / Units
@@ -309,7 +310,7 @@ onMounted(async () => {
309
310
 
310
311
  // ACM levels (door + lift)
311
312
  if (acmResult.status === "fulfilled") {
312
- const acmUrl = acmResult.value.encrypted;
313
+ const acmUrl = acmResult.value;
313
314
  try {
314
315
  const [doorLevels, liftLevels] = await Promise.all([
315
316
  _getDoorAccessLevels(acmUrl),
@@ -403,6 +403,7 @@ const emit = defineEmits<{
403
403
  }>();
404
404
 
405
405
  const { getResidents, assignUser } = useAccessManagement();
406
+ const { getEncryptedAcmUrl } = useSiteEntryPassSettings();
406
407
 
407
408
  const historyDialog = ref(false);
408
409
  const showAssignForm = ref(false);
@@ -475,12 +476,12 @@ async function openAssignForm() {
475
476
  if (!props.unit?._id || !props.orgId || !props.siteId) return;
476
477
  peopleLoading.value = true;
477
478
  try {
478
- const [residentsRes, acmRes] = await Promise.all([
479
+ const [residentsRes, acmUrl] = await Promise.all([
479
480
  getResidents({ orgId: props.orgId, siteId: props.siteId, unitId: props.unit._id }),
480
- $fetch<{ encrypted: string }>("/api/encrypt-acm-url"),
481
+ getEncryptedAcmUrl(props.siteId),
481
482
  ]);
482
483
  peopleItems.value = residentsRes?.data ?? [];
483
- encryptedAcmUrl.value = acmRes?.encrypted ?? "";
484
+ encryptedAcmUrl.value = acmUrl ?? "";
484
485
  } catch {
485
486
  peopleItems.value = [];
486
487
  } finally {
@@ -586,9 +586,31 @@
586
586
  :disabled="Boolean(contactForm.id)"
587
587
  />
588
588
  <FieldLabel text="Name" required />
589
- <AppField v-model="contactForm.name" placeholder="Name shown on calls" class="my-3" />
589
+ <!-- The name is picked from the site's SIP accounts (`hid-sip-accounts`)
590
+ rather than typed, so a contact always names a person who holds an
591
+ extension. The model stays the plain name string the reader stores,
592
+ so `saveContact` is unchanged; an existing contact whose name is not
593
+ in the list still displays it (AppSelect falls back to the raw value). -->
594
+ <AppSelect
595
+ v-model="contactForm.name"
596
+ :items="sipAccountOptions"
597
+ :disabled="sipAccountsLoading"
598
+ :placeholder="sipAccountsLoading ? 'Loading SIP accounts…' : 'Name shown on calls'"
599
+ class="my-3"
600
+ @update:model-value="applySipAccountToContact"
601
+ />
602
+ <p v-if="sipAccountsError" class="field-hint field-hint--error">{{ sipAccountsError }}</p>
603
+ <p v-else-if="!sipAccountsLoading && !sipAccounts.length" class="field-hint">
604
+ No SIP accounts on this site yet. An account is created the first time a user opens Web Call.
605
+ </p>
590
606
  <FieldLabel text="Address" required />
591
- <AppField v-model="contactForm.serverAddress" :placeholder="contactAddressPlaceholder" />
607
+ <!-- Always read-only: it shows the extension of the chosen SIP account
608
+ and is never typed into. -->
609
+ <AppField
610
+ v-model="contactForm.serverAddress"
611
+ :placeholder="contactAddressPlaceholder"
612
+ disabled
613
+ />
592
614
  <p class="field-hint">{{ contactAddressHint }}</p>
593
615
  </v-card-text>
594
616
  <v-card-actions class="dialog-actions pa-0">
@@ -633,6 +655,8 @@
633
655
  </template>
634
656
 
635
657
  <script setup lang="ts">
658
+ import type { HidSipAccountListItem } from "../composables/useHidAmico";
659
+
636
660
  const props = defineProps({
637
661
  org: {
638
662
  type: String,
@@ -729,6 +753,7 @@ const {
729
753
  makeIntercomCall,
730
754
  finalizeIntercomCall,
731
755
  ensureSipAccount,
756
+ getSipAccounts,
732
757
  notifyIntercomCall,
733
758
  } = useHidAmico();
734
759
 
@@ -758,6 +783,11 @@ const webPhoneActionLoading = ref(false);
758
783
  const sipAccount = ref<SipAccount | null>(null);
759
784
  const sipAccountLoading = ref(false);
760
785
  const sipAccountError = ref("");
786
+ // The site's SIP account list for the contact dialog's name picker. Distinct
787
+ // from `sipAccount` above, which is the CALLER's own account for the web phone.
788
+ const sipAccounts = ref<HidSipAccountListItem[]>([]);
789
+ const sipAccountsLoading = ref(false);
790
+ const sipAccountsError = ref("");
761
791
  const remoteVideoEl = ref<HTMLVideoElement | null>(null);
762
792
  const remoteAudioEl = ref<HTMLAudioElement | null>(null);
763
793
  const webPhone = useSipWebPhone();
@@ -862,6 +892,31 @@ const readerOptions = computed(() => readers.value.map((reader) => ({
862
892
  value: reader._id,
863
893
  })));
864
894
 
895
+ /**
896
+ * The contact name picker. `value` is the bare name because that is what the
897
+ * reader stores and what `saveContact` sends; the extension goes into the
898
+ * Address field, not the label. A name that already sits on the contact being
899
+ * edited but is no longer in the SIP list is kept as an option so the picker
900
+ * does not silently drop it.
901
+ */
902
+ const sipAccountOptions = computed(() => {
903
+ const options: Array<{ title: string; value: string }> = sipAccounts.value
904
+ .filter((account: HidSipAccountListItem) => account.name)
905
+ .map((account: HidSipAccountListItem) => ({ title: account.name, value: account.name }));
906
+ const current = contactForm.name.trim();
907
+ if (current && !options.some((option) => option.value === current)) {
908
+ options.unshift({ title: current, value: current });
909
+ }
910
+ return options;
911
+ });
912
+
913
+ /** The SIP account behind the picked name, or null for a legacy / unpicked name. */
914
+ const selectedSipAccount = computed(() => {
915
+ const name = contactForm.name.trim();
916
+ const match = sipAccounts.value.find((account: HidSipAccountListItem) => account.name === name);
917
+ return (match ?? null) as HidSipAccountListItem | null;
918
+ });
919
+
865
920
  const visibleRows = computed(() => activeTab.value === "intercom" ? filteredIntercomRows.value : filteredContacts.value);
866
921
  const pages = computed(() => Math.max(1, Math.ceil(visibleRows.value.length / limit)));
867
922
  const pageRange = computed(() => {
@@ -974,14 +1029,11 @@ const contactReaderRow = computed(() =>
974
1029
  );
975
1030
  const isContactReaderPeerToPeer = computed(() => contactReaderRow.value?.operatingMode === "Peer-to-Peer");
976
1031
  const contactAddressPlaceholder = computed(() => (isContactReaderPeerToPeer.value ? "192.168.0.129" : "7100"));
977
- const contactAddressHint = computed(() => {
978
- if (!contactReaderRow.value) {
979
- return "Extension number (SIP Client) or local IP address (Peer-to-Peer), depending on the reader's operating mode.";
980
- }
981
- return isContactReaderPeerToPeer.value
982
- ? "Peer-to-Peer mode: enter the contact's local IP address."
983
- : "SIP Client mode: enter the contact's extension number.";
984
- });
1032
+ const contactAddressHint = computed(() => (
1033
+ selectedSipAccount.value
1034
+ ? "Extension of the selected SIP account."
1035
+ : "Filled from the SIP account of the name selected above."
1036
+ ));
985
1037
  const areSipCredentialFieldsDisabled = computed(() => !sipForm.enabled || isPeerToPeerMode.value);
986
1038
  const intercomDetailSections = computed(() => {
987
1039
  const row = selectedRow.value;
@@ -1397,6 +1449,37 @@ async function loadSipAccount() {
1397
1449
  }
1398
1450
  }
1399
1451
 
1452
+ async function loadSipAccounts() {
1453
+ if (!props.org || !props.site) return;
1454
+
1455
+ sipAccountsLoading.value = true;
1456
+ sipAccountsError.value = "";
1457
+ try {
1458
+ const response = await getSipAccounts(props.site, props.org);
1459
+ const rows = toRecord(response).data;
1460
+ sipAccounts.value = Array.isArray(rows) ? rows as HidSipAccountListItem[] : [];
1461
+ // An existing contact opened before the list arrived: once its name is
1462
+ // matched to an account, show that account's extension in the locked field.
1463
+ applySipAccountToContact(contactForm.name.trim());
1464
+ } catch (error: unknown) {
1465
+ sipAccounts.value = [];
1466
+ sipAccountsError.value = getErrorMessage(error);
1467
+ } finally {
1468
+ sipAccountsLoading.value = false;
1469
+ }
1470
+ }
1471
+
1472
+ /**
1473
+ * Picking a SIP account sets the address to its extension. The Address field
1474
+ * is always disabled, so this is the only way it gets a value; a name that is
1475
+ * not an account (a legacy contact) leaves whatever address it already had.
1476
+ */
1477
+ function applySipAccountToContact(name: string) {
1478
+ const account = sipAccounts.value.find((item: HidSipAccountListItem) => item.name === name);
1479
+ if (!account) return;
1480
+ contactForm.serverAddress = account.extension;
1481
+ }
1482
+
1400
1483
  async function connectWebPhone() {
1401
1484
  const account = sipAccount.value;
1402
1485
  if (!account) {
@@ -1552,6 +1635,9 @@ function openContactDialog(contact?: ContactRow) {
1552
1635
  contactForm.location = contact?.location === "N/A" ? "" : contact?.location || selectedReader?.location || "";
1553
1636
  contactForm.serverAddress = contact?.serverAddress === "N/A" ? "" : contact?.serverAddress || "";
1554
1637
  contactDialog.value = true;
1638
+ // Fetched on every open, not cached: an account is provisioned the first
1639
+ // time a user opens Web Call, so the list can grow between two dialogs.
1640
+ void loadSipAccounts();
1555
1641
  }
1556
1642
 
1557
1643
  function openContactView(contact: ContactRow) {
@@ -2140,6 +2226,10 @@ export default {
2140
2226
  line-height: 1.4;
2141
2227
  }
2142
2228
 
2229
+ .field-hint--error {
2230
+ color: var(--err);
2231
+ }
2232
+
2143
2233
  .sip-settings-dialog .field-label {
2144
2234
  margin-top: 14px;
2145
2235
  }
@@ -155,6 +155,18 @@ export type HidSipAccountData = {
155
155
  provisionedAt: string;
156
156
  };
157
157
 
158
+ /** One row of the site's SIP account list - who owns the extension, never its password. */
159
+ export type HidSipAccountListItem = {
160
+ _id: string;
161
+ userId: string;
162
+ name: string;
163
+ email: string;
164
+ extension: string;
165
+ username: string;
166
+ status: string;
167
+ provisionedAt: string;
168
+ };
169
+
158
170
  /**
159
171
  * True only for the specific validation error an API that predates core #1878
160
172
  * returns when the discover body carries `site`. Deliberately narrow: after
@@ -541,6 +553,13 @@ export default function useHidAmico() {
541
553
  );
542
554
  }
543
555
 
556
+ function getSipAccounts(siteId: string, orgId: string) {
557
+ return useNuxtApp().$api<{ data: HidSipAccountListItem[] }>(
558
+ `${basePath}/sites/${siteId}/intercom/sip-accounts`,
559
+ { method: "GET", query: { orgId } },
560
+ );
561
+ }
562
+
544
563
  /**
545
564
  * Wake the resident's phone for a call the web phone has just placed.
546
565
  *
@@ -636,6 +655,7 @@ export default function useHidAmico() {
636
655
  makeIntercomCall,
637
656
  finalizeIntercomCall,
638
657
  ensureSipAccount,
658
+ getSipAccounts,
639
659
  notifyIntercomCall,
640
660
  getSitePermissions,
641
661
  getPermissionCandidates,
@@ -27,9 +27,35 @@ export default function useSiteEntryPassSettings() {
27
27
  );
28
28
  }
29
29
 
30
+ /**
31
+ * The encrypted ACM URL the access-card screens hand to API-core, which
32
+ * decrypts it and sends the ACM commands to that host.
33
+ *
34
+ * Resolves the site's own "Enter entrypass URL" setting first, the way
35
+ * `VisitorForm` does for contractor passes. The access-card forms used to
36
+ * call `/api/encrypt-acm-url` with no `url`, so every site's door/lift
37
+ * levels and access groups came from the route's hardcoded default host
38
+ * whatever the site had configured. A site with no URL set, or whose
39
+ * settings cannot be read, still gets that default.
40
+ */
41
+ async function getEncryptedAcmUrl(siteId: string): Promise<string> {
42
+ let rawUrl = "";
43
+ try {
44
+ const settings: any = await getBySiteId(siteId);
45
+ rawUrl = String(settings?.data?.settings?.url ?? "").trim();
46
+ } catch {
47
+ // No entry pass settings for this site yet - the default host applies.
48
+ }
49
+ const { encrypted } = await $fetch<{ encrypted: string }>(
50
+ `/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
51
+ );
52
+ return encrypted;
53
+ }
54
+
30
55
  return {
31
56
  getBySiteId,
32
57
  getById,
33
58
  save,
59
+ getEncryptedAcmUrl,
34
60
  };
35
61
  }
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.21.4-staging.345",
5
+ "version": "4.21.4-staging.347",
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.",