@7365admin1/layer-common 4.15.1 → 4.15.3-staging.326

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/components/ClientDetailForm.vue +3 -0
  3. package/components/DocumentForm.vue +407 -112
  4. package/components/DocumentManagement.vue +213 -12
  5. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  6. package/components/EntryPassInformation.vue +119 -24
  7. package/components/Facility/BookingSetup.vue +63 -0
  8. package/components/HidIntercomManagement.vue +193 -43
  9. package/components/HidProfileQrCode.vue +323 -0
  10. package/components/HidReaderUserRoster.vue +32 -2
  11. package/components/HidUserEnrollment.vue +771 -212
  12. package/components/InvitationClientForm.vue +19 -1
  13. package/components/Layout/Header.vue +26 -0
  14. package/components/NotificationBell.vue +321 -0
  15. package/components/VehicleAddSelection.vue +7 -2
  16. package/components/VehicleBulkAddForm.vue +1392 -0
  17. package/components/VehicleManagement.vue +31 -3
  18. package/components/VisitorManagement.vue +267 -5
  19. package/composables/useAccessManagement.ts +5 -0
  20. package/composables/useAppLinks.ts +4 -2
  21. package/composables/useDocument.ts +7 -0
  22. package/composables/useFacility.ts +11 -0
  23. package/composables/useHidAmico.ts +97 -0
  24. package/composables/useHidNavigation.ts +25 -1
  25. package/composables/useMember.ts +12 -2
  26. package/composables/useNotification.ts +78 -0
  27. package/composables/usePeople.ts +19 -0
  28. package/composables/useVehicle.ts +35 -0
  29. package/composables/useWebUsb.ts +14 -11
  30. package/package.json +1 -1
  31. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  32. package/plugins/secure-member.client.ts +68 -14
  33. package/types/document.d.ts +14 -0
  34. package/types/facility.d.ts +4 -0
  35. package/types/people.d.ts +4 -1
  36. package/utils/materialSymbols.ts +3 -0
  37. package/utils/vehicle-bulk-rows.ts +534 -0
  38. package/utils/vehicle-bulk-sheet.ts +361 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The web client for the in-app notification feed.
3
+ *
4
+ * The feed itself is not new - it has been written to for a while and read by
5
+ * the MA mobile app. Nothing on the web ever read it, which is why this is the
6
+ * first composable for it.
7
+ *
8
+ * `appSlug` is deliberately never sent. The inbox query applies that filter only
9
+ * when it is given one, so omitting it returns the rows written for the web
10
+ * (which carry no slug) alongside anything else addressed to this user, while a
11
+ * mobile client asking for its own slug still sees only its own.
12
+ */
13
+ export default function useNotification() {
14
+ function getAll({
15
+ page = 1,
16
+ limit = 10,
17
+ siteId = "",
18
+ hasRead,
19
+ search = "",
20
+ user = "",
21
+ }: {
22
+ page?: number;
23
+ limit?: number;
24
+ siteId?: string;
25
+ hasRead?: boolean;
26
+ search?: string;
27
+ user?: string;
28
+ } = {}) {
29
+ const query: Record<string, any> = { page, limit, search };
30
+
31
+ // Sent only when set. The list schema rejects a malformed id rather than
32
+ // ignoring it, and `hasRead` false is a real filter that `||` would drop.
33
+ if (siteId) query.siteId = siteId;
34
+ if (user) query.user = user;
35
+ if (hasRead !== undefined) query.hasRead = hasRead;
36
+
37
+ return useNuxtApp().$api<Record<string, any>>("/api/notifications", {
38
+ method: "GET",
39
+ query,
40
+ });
41
+ }
42
+
43
+ function getUnreadCount(user: string) {
44
+ return useNuxtApp().$api<Record<string, any>>(
45
+ "/api/notifications/unread-count",
46
+ {
47
+ method: "GET",
48
+ query: { user },
49
+ },
50
+ );
51
+ }
52
+
53
+ function markAsRead(id: string, user: string) {
54
+ return useNuxtApp().$api<Record<string, any>>(
55
+ `/api/notifications/${id}/${user}/read`,
56
+ {
57
+ method: "PATCH",
58
+ },
59
+ );
60
+ }
61
+
62
+ function markAllAsRead(user: string) {
63
+ return useNuxtApp().$api<Record<string, any>>(
64
+ "/api/notifications/read-all",
65
+ {
66
+ method: "PATCH",
67
+ query: { user },
68
+ },
69
+ );
70
+ }
71
+
72
+ return {
73
+ getAll,
74
+ getUnreadCount,
75
+ markAsRead,
76
+ markAllAsRead,
77
+ };
78
+ }
@@ -115,6 +115,24 @@ export default function () {
115
115
  });
116
116
  }
117
117
 
118
+ /**
119
+ * The blocks, levels and units at a site that actually have an occupant.
120
+ * The other half of the unit picker: this narrows the cascade, then
121
+ * `getPeopleByUnit` answers "which person in this unit?".
122
+ */
123
+ async function getOccupiedStructure(
124
+ site: string,
125
+ { type = "", status = "active", block = "", level = "" } = {}
126
+ ) {
127
+ return await useNuxtApp().$api<Record<string, any>>(
128
+ `/api/people/site/${site}/occupied-structure`,
129
+ {
130
+ method: "GET",
131
+ query: { type, status, block, level },
132
+ }
133
+ );
134
+ }
135
+
118
136
  async function getPeopleByUnit(
119
137
  _id: string,
120
138
  { status = "active", type = "" } = {}
@@ -148,6 +166,7 @@ export default function () {
148
166
  findPersonByPlateNumberMultipleResult,
149
167
  findPersonByContact,
150
168
  getPeopleByUnit,
169
+ getOccupiedStructure,
151
170
  searchCompanyList,
152
171
  findUsersByPlateNumber,
153
172
  reviewResidentPerson,
@@ -27,6 +27,40 @@ export default function useVehicle() {
27
27
  });
28
28
  }
29
29
 
30
+ /**
31
+ * The Whitelist (Bulk) sheet: many vehicles in one request.
32
+ *
33
+ * Every row carries its own `id`, and the answer hands that id back with
34
+ * `ok` and a sentence, so the sheet can mark each row and send only the ones
35
+ * that did not go on. The server adds each row exactly as `addVehicle` adds
36
+ * one - same status rule, same ANPR cameras.
37
+ */
38
+ async function addVehiclesBulk(payload: {
39
+ site: string;
40
+ org: string;
41
+ category?: string;
42
+ rows: Array<{
43
+ id: string;
44
+ block: string;
45
+ level: string;
46
+ unit: string;
47
+ name: string;
48
+ plateNumber: string;
49
+ nric?: string;
50
+ phoneNumber?: string;
51
+ }>;
52
+ }) {
53
+ return await useNuxtApp().$api<{
54
+ message: string;
55
+ added: number;
56
+ failed: number;
57
+ results: Array<{ id: string; ok: boolean; message: string }>;
58
+ }>("/api/vehicles/bulk", {
59
+ method: "POST",
60
+ body: payload,
61
+ });
62
+ }
63
+
30
64
  async function updateVehicle(id: string, payload: Partial<TVehiclePayload>) {
31
65
  return await useNuxtApp().$api<Record<string, any>>(`/api/vehicles/id/${id}`, {
32
66
  method: "PUT",
@@ -147,6 +181,7 @@ function getSpecificVehicleById(id: string){
147
181
  return {
148
182
  getVehicles,
149
183
  addVehicle,
184
+ addVehiclesBulk,
150
185
  getCustomSeasonPassTypes,
151
186
  getVehicleById,
152
187
  updateVehicle,
@@ -345,16 +345,19 @@ export default function useWebUsb() {
345
345
  70,
346
346
  );
347
347
 
348
- const qrSmall = 140;
349
- const qrCenter = 250;
350
- const margin = 20;
351
- const qrCanvas = await QRCode.toCanvas(qrUrlImage, { width: qrCenter });
348
+ // The pass used to print five copies of the same QR - four 140px ones at
349
+ // the corners around a 250px centre - so a strip could be cut apart. It now
350
+ // prints a single large QR filling that same band (y 90 to 440, above the
351
+ // company name at y 470), which scans far more reliably on a thermal print.
352
+ // Generated at the size it is drawn at: the old corner copies were
353
+ // downscaled from the 250px canvas, which softened their modules.
354
+ const qrSize = 350;
355
+ const qrCanvas = await QRCode.toCanvas(qrUrlImage, {
356
+ width: qrSize,
357
+ margin: 1,
358
+ });
352
359
 
353
- ctx.drawImage(qrCanvas, margin, 90, qrSmall, qrSmall);
354
- ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 90, qrSmall, qrSmall);
355
- ctx.drawImage(qrCanvas, (canvas.width - qrCenter) / 2, 110, qrCenter, qrCenter);
356
- ctx.drawImage(qrCanvas, margin, 300, qrSmall, qrSmall);
357
- ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 300, qrSmall, qrSmall);
360
+ ctx.drawImage(qrCanvas, (canvas.width - qrSize) / 2, 90, qrSize, qrSize);
358
361
 
359
362
  ctx.font = "25px Arial";
360
363
  ctx.fillText(companyName || "", canvas.width / 2, 470);
@@ -401,8 +404,8 @@ export default function useWebUsb() {
401
404
  /**
402
405
  * The self-service onboarding QR: one large QR code, a "SCAN QR CODE"-style
403
406
  * subtext, and a dark site-name banner along the bottom - a single-purpose
404
- * gate sign, not the multi-copy visitor-pass receipt `createReceiptLayout`
405
- * produces (that one prints several QRs to be cut apart and handed out).
407
+ * gate sign, not the visitor-pass receipt `createReceiptLayout` produces
408
+ * (that one pairs its QR with company, date, access and instruction lines).
406
409
  */
407
410
  async function createOnboardingQrLayout(
408
411
  qrUrlImage: string,
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.15.1",
5
+ "version": "4.15.3-staging.326",
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.",
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <v-container fluid>
3
+ <HidEnabledGate
4
+ :site="siteId"
5
+ :org="orgId"
6
+ message="Enable HID as a service for this site before generating a QR code."
7
+ >
8
+ <HidProfileQrCode :site="siteId" />
9
+ </HidEnabledGate>
10
+ </v-container>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ definePageMeta({
15
+ layout: "default",
16
+ middleware: ["01-auth", "02-org"],
17
+ memberOnly: true,
18
+ });
19
+
20
+ const route = useRoute();
21
+ const siteId = computed(() => String(route.params.site ?? ""));
22
+ const orgId = computed(() => String(route.params.org ?? ""));
23
+ </script>
@@ -18,6 +18,26 @@ function statusOf(error: any) {
18
18
  */
19
19
  export const LOOKUP_TIMEOUT_MS = 5000;
20
20
 
21
+ /*
22
+ * Q16 (owner, 2026-09-11): a person's role FOLLOWS THE SITE -- someone can hold
23
+ * a different role at each site, and the app must use the role of the site they
24
+ * are on. The server half has been live since core 3.64.x; this sends the site
25
+ * the route is on so it can answer.
26
+ *
27
+ * HELD OFF behind this switch, exactly as the mobile half is (`SEND_SITE` in
28
+ * the fleet apps' `src/actions/member.ts`), because a site role can be NARROWER
29
+ * than the organisation-wide one: measured read-only on staging 2026-09-16,
30
+ * 5 users' effective role changes (4 narrow, 2 widen, 2 same size).
31
+ *
32
+ * The switch gates ONE thing -- whether `site` is sent. The role is resolved
33
+ * per site either way (the same split the mobile half makes), so while this is
34
+ * false a site switch re-asks and the server answers exactly as it does today.
35
+ *
36
+ * ponytail: rollout control. Flip to true on the owner's word, then delete the
37
+ * constant and the `SEND_SITE ?` below.
38
+ */
39
+ export const SEND_SITE = false;
40
+
21
41
  function bounded<T>(request: Promise<T>): Promise<T> {
22
42
  let timer: ReturnType<typeof setTimeout> | undefined;
23
43
  const timeout = new Promise<never>((_, reject) => {
@@ -45,8 +65,13 @@ export default defineNuxtPlugin(() => {
45
65
 
46
66
  // Resolved once per signed-in session, not once per navigation. Keyed by the
47
67
  // user cookie so signing in as somebody else re-resolves.
68
+ // Keyed by user AND the site the role was resolved AT, so switching site
69
+ // re-resolves the role instead of keeping the first site's one. Off a site
70
+ // (and in the apps that have no site in their routes) the site half is "",
71
+ // which is the old key.
48
72
  let resolvedFor: string | null = null;
49
73
  let inFlight: Promise<void> | null = null;
74
+ let inFlightKey: string | null = null;
50
75
  let hasMemberDocument = false;
51
76
 
52
77
  // The client's module list is decided per org|site, so it has its own key.
@@ -62,39 +87,66 @@ export default defineNuxtPlugin(() => {
62
87
  // both do -- and that is a real answer ("no organisation role"), not an error.
63
88
  // Treating it as an error is what would bounce those accounts off their own
64
89
  // pages; leaving it unanswered is what let gates fail open.
65
- async function resolveAppRole(userId: string) {
66
- if (resolvedFor === userId) return;
67
- if (inFlight) return inFlight;
90
+ async function resolveAppRole(userId: string, site: string) {
91
+ const key = `${userId}|${site}`;
92
+ if (resolvedFor === key) return;
93
+ if (inFlight) {
94
+ // A lookup for the SAME key is the one we want: await it and stop, which
95
+ // is what this did before there was a key. One for another site is not,
96
+ // so let it finish and then resolve ours.
97
+ const same = inFlightKey === key;
98
+ await inFlight;
99
+ if (same || resolvedFor === key) return;
100
+ }
68
101
 
69
- userAppRoleStatus.value = "loading";
70
- inFlight = run(userId).finally(() => {
102
+ // Gates read this status and a drop to "loading" hides them, so only drop
103
+ // it when the answer can actually DIFFER: the first resolution, or a site
104
+ // change while Q16 is on. While Q16 is held a site change re-asks the same
105
+ // question, so the resolved role stays on screen and nothing flickers.
106
+ if (resolvedFor === null || SEND_SITE) userAppRoleStatus.value = "loading";
107
+ inFlightKey = key;
108
+ inFlight = run(userId, site).finally(() => {
71
109
  inFlight = null;
72
110
  });
73
111
  return inFlight;
74
112
  }
75
113
 
76
- async function run(userId: string) {
114
+ async function run(userId: string, site: string) {
77
115
  const APP = useRuntimeConfig().public.APP;
78
116
 
79
117
  try {
80
- // The org query is not sent: the endpoint keys on user + app type only, so
81
- // the role does not depend on which organisation is in the current route.
82
- const member = await bounded(getByUserType(userId, APP));
118
+ // The org query is not sent: without it the server's site rule answers
119
+ // with the membership pinned to `site` or, failing that, with exactly the
120
+ // membership it has always answered with -- so the only behaviour this
121
+ // adds is Q16 itself. Sending `org` as well would change the fallback
122
+ // too, and that is a separate change.
123
+ const member = await bounded(
124
+ getByUserType(userId, APP, undefined, SEND_SITE && site ? site : undefined),
125
+ );
83
126
  hasMemberDocument = true;
84
127
  id.value = member.org ?? "";
85
128
  userAppRole.value = member.role ? await bounded(getRoleById(member.role)) : null;
86
129
  } catch (error) {
87
- userAppRole.value = null;
88
- hasMemberDocument = false;
89
130
  // Anything that is not a 404 is transient. Stay unresolved so the next
90
131
  // navigation tries again rather than denying for the rest of the session.
91
132
  if (statusOf(error) !== 404) {
133
+ // A RE-resolve (a site change) that blips must not blank a role that is
134
+ // already on screen -- that would close every gate on a working page
135
+ // over a network hiccup. Keep the last-known role, which is the rule
136
+ // the mobile half uses (Q11), and let the next navigation retry. Only a
137
+ // first resolution has nothing to fall back to.
138
+ if (resolvedFor !== null) return;
139
+ userAppRole.value = null;
140
+ hasMemberDocument = false;
92
141
  userAppRoleStatus.value = "idle";
93
142
  return;
94
143
  }
144
+ // A 404 is a real answer: this account holds no member document.
145
+ userAppRole.value = null;
146
+ hasMemberDocument = false;
95
147
  }
96
148
 
97
- resolvedFor = userId;
149
+ resolvedFor = `${userId}|${site}`;
98
150
  userAppRoleStatus.value = "resolved";
99
151
  }
100
152
 
@@ -139,8 +191,10 @@ export default defineNuxtPlugin(() => {
139
191
  // ran there the role stayed null for the life of the page: gates that
140
192
  // default open granted everything, gates that fail closed denied everything.
141
193
  // Awaited, so no gate is ever evaluated against an unresolved role.
142
- if (userId) await resolveAppRole(userId);
143
- if (userId) await resolveDenied(userId, idParam(to.params.site));
194
+ const site = idParam(to.params.site);
195
+
196
+ if (userId) await resolveAppRole(userId, site);
197
+ if (userId) await resolveDenied(userId, site);
144
198
  else if (userAppModulesDenied.value.length) {
145
199
  // Signed out: never carry the previous person's list.
146
200
  deniedFor = deniedWanted = null;
@@ -3,4 +3,18 @@ declare type TDocument = {
3
3
  name: string;
4
4
  attachment: string;
5
5
  type: string;
6
+ /**
7
+ * Set at upload or renewal, absent when the document never expires.
8
+ *
9
+ * An ISO instant on the way out of the API and a `YYYY-MM-DD` string on the
10
+ * way back in, which is what `InputDatePicker` binds to - hence the loose
11
+ * type rather than `string`.
12
+ */
13
+ expiryDate?: string | Date | null;
14
+ remarks?: string;
15
+ size?: number;
16
+ parentId?: string | null;
17
+ createdAt?: string | Date;
18
+ updatedAt?: string | Date;
19
+ status?: string;
6
20
  };
@@ -73,6 +73,10 @@ declare type TFacility = {
73
73
  hourInterval?: number;
74
74
  isBookingFeeEnabled: boolean;
75
75
  isGuestEnabled: boolean;
76
+ /** Residents may complete this facility's checklist themselves. */
77
+ isResidentChecklistEnabled?: boolean;
78
+ /** Security may complete it. Mutually exclusive with the above. */
79
+ isSecurityChecklistEnabled?: boolean;
76
80
  bookingAmount: number | null;
77
81
  peakBookingFeeAmount?: number | null;
78
82
  bookingFeeGuestAmount?: number | null;
package/types/people.d.ts CHANGED
@@ -22,11 +22,14 @@ declare type TPeople = {
22
22
  email?: string;
23
23
  files?: { name: string, id: string }[];
24
24
  isOwner?: boolean;
25
+ // Link to this person's `users` row. Empty for the person types that carry
26
+ // no login, and empty for a resident whose account was never written.
27
+ user?: string;
25
28
  };
26
29
 
27
30
  declare type TPlateNumber = { plateNumber: string, recNo: string, _id?: string, status: "active" | "deleted" | "pending", type: TVehicleType };
28
31
 
29
32
 
30
- declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string }
33
+ declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string; user?: string }
31
34
 
32
35
  declare type TPeopleType = "guest" | "resident" | "tenant"
@@ -242,6 +242,9 @@ export const MDI_TO_SYMBOL: Record<string, string> = {
242
242
  "mdi-link-variant": "link",
243
243
  "mdi-lan-connect": "lan",
244
244
  "mdi-lan-disconnect": "link_off", // NEAREST: no disconnected-LAN glyph
245
+ "mdi-lan-check": "network_check",
246
+ "mdi-dialpad": "dialpad",
247
+ "mdi-headset": "headset_mic",
245
248
  "mdi-bluetooth": "bluetooth",
246
249
  "mdi-nfc": "nfc",
247
250