@7365admin1/layer-common 4.35.1-staging.372 → 4.35.1-staging.374

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.
@@ -210,6 +210,23 @@
210
210
  Confirmed on the reader:
211
211
  <strong>{{ formatDate(selectedReader?.identificationMethodsAppliedAt) }}</strong>
212
212
  </p>
213
+
214
+ <!--
215
+ Its own action, not a save. A reader's settings can change without
216
+ us — a firmware update, its own touchscreen, a restore, a reset —
217
+ and saving only writes what is on screen. This reads the device
218
+ first and reports what had moved.
219
+ -->
220
+ <div class="dialog-actions-inline">
221
+ <AppButton
222
+ variant="ghost"
223
+ icon="mdi-sync"
224
+ :disabled="identificationReconciling || identificationSaving || !selectedReader?.identificationMethods"
225
+ @click="reapplyIdentificationMethods"
226
+ >
227
+ {{ identificationReconciling ? "Checking reader..." : "Re-apply settings" }}
228
+ </AppButton>
229
+ </div>
213
230
  </v-card-text>
214
231
 
215
232
  <v-card-text v-else class="reader-action-content">
@@ -229,14 +246,14 @@
229
246
  <v-spacer />
230
247
  <AppButton
231
248
  variant="ghost"
232
- :disabled="identificationSaving"
249
+ :disabled="identificationSaving || identificationReconciling"
233
250
  @click="identificationStage === 'confirm' ? (identificationStage = 'edit') : (identificationDialog = false)"
234
251
  >
235
252
  {{ identificationStage === "confirm" ? "Back" : "Cancel" }}
236
253
  </AppButton>
237
254
  <AppButton
238
255
  v-if="identificationStage === 'edit'"
239
- :disabled="!identificationChanged"
256
+ :disabled="!identificationChanged || identificationReconciling"
240
257
  @click="identificationStage = 'confirm'"
241
258
  >
242
259
  Save
@@ -472,6 +489,7 @@ const {
472
489
  setReaderMonitor,
473
490
  setReaderOperatingMode,
474
491
  setReaderIdentificationMethods,
492
+ reconcileReaderIdentificationMethods,
475
493
  getReaderUsers,
476
494
  } = useHidAmico();
477
495
 
@@ -493,6 +511,7 @@ const identificationDialog = ref(false);
493
511
  so it is never one click away. */
494
512
  const identificationStage = ref<"edit" | "confirm">("edit");
495
513
  const identificationSaving = ref(false);
514
+ const identificationReconciling = ref(false);
496
515
  const identificationForm = ref<{
497
516
  facial: boolean;
498
517
  card: boolean;
@@ -714,6 +733,79 @@ const identificationBeingDisabled = computed(() => {
714
733
  * reader would not take, and the controls must go back to what the device
715
734
  * actually holds rather than keeping the rejected choice on screen.
716
735
  */
736
+ /*
737
+ * What the device is actually holding, put back to what we hold for it.
738
+ *
739
+ * Worth a button of its own because drift has causes nobody here controls — a
740
+ * firmware update, somebody using the reader's own touchscreen, a restore, a
741
+ * reset. Saving the dialog only writes what is on screen; this reads the
742
+ * device first and reports what had moved.
743
+ */
744
+ async function reapplyIdentificationMethods() {
745
+ const readerId = String(selectedReader.value?._id || "");
746
+ if (!readerId) return;
747
+
748
+ const readerName = String(selectedReader.value?.name || "HID Reader");
749
+ identificationReconciling.value = true;
750
+ try {
751
+ const response = await reconcileReaderIdentificationMethods(readerId);
752
+ const result = (response?.data || response || {}) as HidRecord;
753
+ identificationDialog.value = false;
754
+ await loadReaders();
755
+ selectedReader.value = readers.value.find((reader) => String(reader._id) === readerId) || null;
756
+
757
+ const status = String(result.status || "");
758
+ const drifted = Array.isArray(result.drifted) ? result.drifted.map(String) : [];
759
+ if (status === "drift_corrected") {
760
+ showResult(
761
+ true,
762
+ "Settings Re-applied",
763
+ `${readerName} had drifted and has been put back. Corrected: ${drifted.map(identificationFieldLabel).join(", ")}.`,
764
+ { readerName },
765
+ );
766
+ } else if (status === "in_sync") {
767
+ showResult(true, "Settings Already Correct", `${readerName} matches what iService365 holds for it.`, { readerName });
768
+ } else if (status === "skipped" && result.reason === "duplicate_reader") {
769
+ // Not a failure to retry: the device is registered twice, and until a
770
+ // person removes one record both would fight over its configuration.
771
+ showResult(
772
+ false,
773
+ "Duplicate HID Reader",
774
+ `${readerName} shares a device with another registered reader. Remove or deactivate one of them before re-applying settings.`,
775
+ { readerName },
776
+ );
777
+ } else if (status === "skipped") {
778
+ showResult(
779
+ false,
780
+ "Nothing to Re-apply",
781
+ `No identification methods have been set for ${readerName} yet.`,
782
+ { readerName },
783
+ );
784
+ } else {
785
+ showResult(false, "Could Not Re-apply Settings", String(result.message || "The HID reader could not be reached."), { readerName });
786
+ }
787
+ } catch (error: unknown) {
788
+ console.error("Unable to reconcile HID identification methods:", error);
789
+ identificationDialog.value = false;
790
+ await loadReaders();
791
+ showResult(false, "Could Not Re-apply Settings", getFriendlyHidError(error), { readerName });
792
+ } finally {
793
+ identificationReconciling.value = false;
794
+ }
795
+ }
796
+
797
+ /** The reader's own field names, as the person in front of the door knows them. */
798
+ function identificationFieldLabel(field: string) {
799
+ const labels: Record<string, string> = {
800
+ face_identification_enabled: "Facial",
801
+ card_identification_enabled: "Card",
802
+ qrcode_identification_enabled: "QR code",
803
+ pin_identification_enabled: "Credential entry",
804
+ multi_factor_authentication: "Multi-factor",
805
+ };
806
+ return labels[field] || field;
807
+ }
808
+
717
809
  async function saveIdentificationMethods() {
718
810
  const readerId = String(selectedReader.value?._id || "");
719
811
  if (!readerId) return;
@@ -134,7 +134,7 @@ import {
134
134
  timeAgo,
135
135
  type TInboxItem,
136
136
  } from "../utils/notification-inbox";
137
- import { notificationTarget } from "../utils/notification-target";
137
+ import { externalTargetUrl, notificationTarget } from "../utils/notification-target";
138
138
 
139
139
  /**
140
140
  * The top-bar notification feed for the web, in every signed-in app.
@@ -168,6 +168,7 @@ const { getAll, getUnreadCount, markAsRead, markAllAsRead } = useNotification();
168
168
  const { currentUser } = useLocalAuth();
169
169
  const route = useRoute();
170
170
  const router = useRouter();
171
+ const appConfig = useRuntimeConfig();
171
172
 
172
173
  const open = ref(false);
173
174
  const loading = ref(false);
@@ -305,14 +306,24 @@ function markRead(item: Record<string, any>) {
305
306
  */
306
307
  async function goToSubject(item: Record<string, any>) {
307
308
  const target = notificationTarget(item as any, {
308
- organization: String(route.params?.organization ?? ""),
309
+ // The org app nests under `organization`; the service apps under `org`.
310
+ organization: String(route.params?.organization ?? route.params?.org ?? ""),
309
311
  });
310
312
  if (!target) return;
311
- if (typeof router.hasRoute !== "function" || !router.hasRoute(target.name)) return;
313
+
314
+ if (typeof router.hasRoute !== "function" || !router.hasRoute(target.name)) {
315
+ // The page lives in another web app (the invitation is answered in the
316
+ // organisation app): go there by URL, or stay put if it is not configured.
317
+ const href = externalTargetUrl(target, { org: String(appConfig?.public?.APP_ORG ?? "") });
318
+ if (!href) return;
319
+ open.value = false;
320
+ window.location.assign(href);
321
+ return;
322
+ }
312
323
 
313
324
  open.value = false;
314
325
  try {
315
- await router.push(target);
326
+ await router.push({ name: target.name, params: target.params, query: target.query });
316
327
  } catch {
317
328
  // A cancelled or duplicate navigation is not worth an error in the top bar.
318
329
  }
@@ -57,6 +57,11 @@
57
57
  :label="invitation.statusLabel"
58
58
  />
59
59
  </div>
60
+
61
+ <!-- An accept or decline that failed: said on the card, not swallowed. -->
62
+ <div v-if="error" class="px-4 pb-4 text-error sp-invite-prompt__body" role="alert">
63
+ {{ error }}
64
+ </div>
60
65
  </AppCard>
61
66
 
62
67
  <AppCard v-else-if="error">
@@ -82,8 +87,8 @@ const props = defineProps({
82
87
 
83
88
  const emit = defineEmits<{ (e: "answered", status: string): void }>();
84
89
 
85
- const { getInvitation, declineInvitation } = useServiceProviderInvitation();
86
- const { addViaInvite } = useCustomerSite();
90
+ const { getInvitation, declineInvitation, acceptInvitation } =
91
+ useServiceProviderInvitation();
87
92
 
88
93
  const invitation = ref<any>(null);
89
94
  const error = ref("");
@@ -112,9 +117,10 @@ async function load() {
112
117
  }
113
118
 
114
119
  async function accept() {
120
+ error.value = "";
115
121
  working.value = "accept";
116
122
  try {
117
- await addViaInvite(props.invitationId);
123
+ await acceptInvitation(props.invitationId);
118
124
  await load();
119
125
  emit("answered", "complete");
120
126
  } catch (err: any) {
@@ -125,6 +131,7 @@ async function accept() {
125
131
  }
126
132
 
127
133
  async function decline() {
134
+ error.value = "";
128
135
  working.value = "decline";
129
136
  try {
130
137
  await declineInvitation(props.invitationId);
@@ -0,0 +1,113 @@
1
+ <template>
2
+ <!-- Nothing to answer and nothing linked: the section stays out of the way. -->
3
+ <section v-if="ids.length" class="sp-received mb-4" aria-labelledby="sp-received-title">
4
+ <div class="mb-2">
5
+ <div id="sp-received-title" class="screen-card-title">
6
+ Invitations from other organisations
7
+ </div>
8
+ <div class="screen-hint">
9
+ Another organisation has asked your company to provide services at one
10
+ of its sites. Accept to add the site to your Sites list, or decline.
11
+ </div>
12
+ </div>
13
+
14
+ <div class="d-flex flex-column ga-3">
15
+ <div
16
+ v-for="id in ids"
17
+ :key="id"
18
+ :class="{ 'sp-received__linked': id === linked }"
19
+ >
20
+ <Suspense>
21
+ <ServiceProviderInvitationPrompt
22
+ :invitation-id="id"
23
+ @answered="(status: string) => onAnswered(id, status)"
24
+ />
25
+ </Suspense>
26
+
27
+ <div v-if="answered[id] === 'complete'" class="sp-received__done mt-2">
28
+ {{ doneLine(id) }}
29
+ <NuxtLink v-if="sitesLink(id)" :to="sitesLink(id)">Open Sites</NuxtLink>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </section>
34
+ </template>
35
+
36
+ <script setup lang="ts">
37
+ /**
38
+ * "Invitations from other organisations" — where a service provider answers an
39
+ * invitation another organisation sent it (owner report 2026-09-24: the bell
40
+ * said "Open the invitation to accept or decline" and there was nowhere to do
41
+ * either).
42
+ *
43
+ * The list comes from the server keyed on the signed-in account, so it is the
44
+ * same whichever organisation is on screen. The row the bell linked to
45
+ * (`?invite=<id>`) is always shown — even once answered or expired, so the
46
+ * person sees what happened to it — and is outlined.
47
+ */
48
+ import type { TReceivedServiceProviderInvitation } from "../composables/useServiceProviderInvitation";
49
+
50
+ const route = useRoute();
51
+ const { getReceivedInvitations } = useServiceProviderInvitation();
52
+
53
+ const items = ref<TReceivedServiceProviderInvitation[]>([]);
54
+ const answered = reactive<Record<string, string>>({});
55
+
56
+ const linked = computed(() => {
57
+ const value = String(route.query?.invite ?? "").trim();
58
+ return /^[a-f0-9]{24}$/i.test(value) ? value : "";
59
+ });
60
+
61
+ const ids = computed(() => {
62
+ const listed = items.value.map((i) => String(i._id));
63
+ return linked.value && !listed.includes(linked.value)
64
+ ? [linked.value, ...listed]
65
+ : listed;
66
+ });
67
+
68
+ function itemFor(id: string) {
69
+ return items.value.find((i) => String(i._id) === id);
70
+ }
71
+
72
+ function doneLine(id: string) {
73
+ const item = itemFor(id);
74
+ const whose = item?.providerOrgName ? `${item.providerOrgName}'s` : "your";
75
+ return item?.siteName
76
+ ? `${item.siteName} is now on ${whose} Sites list.`
77
+ : `The site is now on ${whose} Sites list.`;
78
+ }
79
+
80
+ function sitesLink(id: string) {
81
+ const org = itemFor(id)?.providerOrgId || String(route.params?.organization ?? "");
82
+ return org ? `/org/${org}/sites` : "";
83
+ }
84
+
85
+ function onAnswered(id: string, status: string) {
86
+ answered[id] = status;
87
+ }
88
+
89
+ async function load() {
90
+ try {
91
+ const res = await getReceivedInvitations();
92
+ items.value = Array.isArray(res?.items) ? res.items : [];
93
+ } catch {
94
+ // The section is an addition to the Invitations page; if it cannot load,
95
+ // the rest of the page must still work. A linked row still renders and
96
+ // reports its own error.
97
+ items.value = [];
98
+ }
99
+ }
100
+
101
+ await load();
102
+ </script>
103
+
104
+ <style scoped>
105
+ .sp-received__linked :deep(.app-card) {
106
+ outline: 2px solid rgb(var(--v-theme-primary));
107
+ outline-offset: 2px;
108
+ }
109
+
110
+ .sp-received__done {
111
+ font-size: var(--fs-cell);
112
+ }
113
+ </style>
@@ -331,6 +331,20 @@ export default function useHidAmico() {
331
331
  );
332
332
  }
333
333
 
334
+ /**
335
+ * Put a reader back to the settings iService holds for it.
336
+ *
337
+ * A POST rather than a GET because it WRITES: reading the reader's
338
+ * configuration is only the first half, and anything that drifted is
339
+ * re-applied before this returns.
340
+ */
341
+ function reconcileReaderIdentificationMethods(readerId: string) {
342
+ return useNuxtApp().$api<HidApiRecord>(
343
+ `${basePath}/readers/${readerId}/identification-methods/reconcile`,
344
+ { method: "POST" },
345
+ );
346
+ }
347
+
334
348
  function getIdentities(readerId: string, query: HidApiRecord = {}) {
335
349
  return useNuxtApp().$api<HidApiRecord>(`${basePath}/readers/${readerId}/identities`, {
336
350
  method: "GET",
@@ -648,6 +662,7 @@ export default function useHidAmico() {
648
662
  getReaderConfiguration,
649
663
  setReaderConfiguration,
650
664
  setReaderIdentificationMethods,
665
+ reconcileReaderIdentificationMethods,
651
666
  getLogs,
652
667
  setUserImage,
653
668
  deleteUserImage,
@@ -26,6 +26,19 @@ export type TServiceProviderInvitation = {
26
26
  }>;
27
27
  };
28
28
 
29
+ /** One row of "Invitations from other organisations". */
30
+ export type TReceivedServiceProviderInvitation = {
31
+ _id: string;
32
+ orgName: string;
33
+ siteName: string;
34
+ status: string;
35
+ statusLabel: string;
36
+ expireAt?: string;
37
+ /** The invited company's own organisation (the one whose list gains the site). */
38
+ providerOrgId?: string;
39
+ providerOrgName?: string;
40
+ };
41
+
29
42
  /** The words on screen. Kept beside the server's own list on purpose — a
30
43
  * status the server invents must never render as a raw stored value. */
31
44
  export const SERVICE_PROVIDER_INVITE_LABELS: Record<string, string> = {
@@ -130,6 +143,23 @@ export default function useServiceProviderInvitation() {
130
143
  });
131
144
  }
132
145
 
146
+ /** Adds the site to the invited company's list. The invited account only. */
147
+ function acceptInvitation(id: string) {
148
+ return useNuxtApp().$api<{ message: string }>(`${base}/${id}/accept`, {
149
+ method: "PUT",
150
+ });
151
+ }
152
+
153
+ /**
154
+ * Invitations from other organisations still waiting for the signed-in
155
+ * account's answer — keyed on the account, not on the organisation on screen.
156
+ */
157
+ function getReceivedInvitations(): Promise<{
158
+ items: TReceivedServiceProviderInvitation[];
159
+ }> {
160
+ return useNuxtApp().$api(`${base}/received`, { method: "GET" });
161
+ }
162
+
133
163
  return {
134
164
  getInvitations,
135
165
  cancelInvitation,
@@ -141,5 +171,7 @@ export default function useServiceProviderInvitation() {
141
171
  rejectInvitation,
142
172
  getInvitation,
143
173
  declineInvitation,
174
+ acceptInvitation,
175
+ getReceivedInvitations,
144
176
  };
145
177
  }
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.35.1-staging.372",
5
+ "version": "4.35.1-staging.374",
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.",
@@ -31,7 +31,8 @@
31
31
  /** Only the fields a destination is decided from. */
32
32
  export type TTargetRow = {
33
33
  module?: string;
34
- params?: { id?: string } | null;
34
+ screen?: string;
35
+ params?: { id?: string; org?: string } | null;
35
36
  };
36
37
 
37
38
  /** What the surrounding app knows that the stored row does not. */
@@ -43,6 +44,13 @@ export type TTargetContext = {
43
44
  export type TNotificationTarget = {
44
45
  name: string;
45
46
  params: Record<string, string>;
47
+ query?: Record<string, string>;
48
+ /**
49
+ * Set when the page lives in another web app. The bell opens
50
+ * `<that app's URL><path>` when its own router has no route by `name`.
51
+ */
52
+ app?: "org";
53
+ path?: string;
46
54
  };
47
55
 
48
56
  /** Nuxt's generated names for `pages/org/[organization]/marketplace/orders/`. */
@@ -52,12 +60,42 @@ export const ORDER_DETAIL_ROUTE = "org-organization-marketplace-orders-id";
52
60
  /** The stored `module` tag on a row sent to a vendor's staff. */
53
61
  export const VENDOR_ORDER_MODULE = "marketplace-vendor-order";
54
62
 
63
+ /**
64
+ * "<Company> has invited you to <site>" — core `serviceProviderInvited` stores
65
+ * `module: "other"` (the apps route on it; it never changes) with this
66
+ * `screen`, the invitation id in `params.id`, and, since 2026-09-24, the
67
+ * invited company's own organisation in `params.org`.
68
+ *
69
+ * It opens the organisation app's Invitations page, where "Invitations from
70
+ * other organisations" lists it with Accept / Decline. Only the organisation
71
+ * app has that page; every other app sends the click there by URL.
72
+ */
73
+ export const SP_INVITATION_SCREEN = "/service-provider-invitation";
74
+ export const INVITATIONS_ROUTE = "org-organization-invitations-status-status";
75
+
55
76
  export function notificationTarget(
56
77
  item: TTargetRow | null | undefined,
57
78
  context: TTargetContext = {},
58
79
  ): TNotificationTarget | null {
59
80
  const organization = String(context.organization ?? "").trim();
60
81
 
82
+ if (String(item?.screen ?? "") === SP_INVITATION_SCREEN) {
83
+ // The invited company's organisation when the row names it (the invitation
84
+ // belongs there), otherwise the one on screen. The list on that page is
85
+ // keyed on the signed-in account, so either shows the invitation.
86
+ const org = String(item?.params?.org ?? "").trim() || organization;
87
+ if (!org) return null;
88
+ const id = String(item?.params?.id ?? "").trim();
89
+ const query: Record<string, string> = id ? { invite: id } : {};
90
+ return {
91
+ name: INVITATIONS_ROUTE,
92
+ params: { organization: org, status: "pending" },
93
+ query,
94
+ app: "org",
95
+ path: `/org/${encodeURIComponent(org)}/invitations/status/pending`,
96
+ };
97
+ }
98
+
61
99
  if (String(item?.module ?? "") !== VENDOR_ORDER_MODULE) return null;
62
100
 
63
101
  // Every order route is nested under the organization. Without one there is no
@@ -73,3 +111,18 @@ export function notificationTarget(
73
111
 
74
112
  return { name: ORDER_DETAIL_ROUTE, params: { organization, id } };
75
113
  }
114
+
115
+ /**
116
+ * The full URL for a target whose page lives in another web app, or "" when
117
+ * there is none to build (no path, or that app's URL is not configured).
118
+ */
119
+ export function externalTargetUrl(
120
+ target: TNotificationTarget | null | undefined,
121
+ appUrls: { org?: string } = {},
122
+ ): string {
123
+ if (!target?.app || !target.path) return "";
124
+ const base = String(appUrls[target.app] ?? "").trim().replace(/\/+$/, "");
125
+ if (!base) return "";
126
+ const qs = new URLSearchParams(target.query ?? {}).toString();
127
+ return `${base}${target.path}${qs ? `?${qs}` : ""}`;
128
+ }