@7365admin1/layer-common 4.10.3 → 4.11.1-staging.313

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 (33) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/components/CameraForm.vue +460 -3
  3. package/components/CameraMain.vue +118 -1
  4. package/components/CameraPlateSyncDialog.vue +626 -0
  5. package/components/DocumentForm.vue +407 -112
  6. package/components/DocumentManagement.vue +213 -12
  7. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  8. package/components/Facility/BookingSetup.vue +63 -0
  9. package/components/HidIntercomManagement.vue +193 -43
  10. package/components/HidProfileQrCode.vue +323 -0
  11. package/components/HidReaderUserRoster.vue +32 -2
  12. package/components/HidUserEnrollment.vue +771 -212
  13. package/components/InvitationClientForm.vue +19 -1
  14. package/components/Layout/Header.vue +26 -0
  15. package/components/NotificationBell.vue +321 -0
  16. package/components/VehicleForm.vue +11 -3
  17. package/components/VisitorManagement.vue +267 -5
  18. package/composables/useDocument.ts +7 -0
  19. package/composables/useFacility.ts +11 -0
  20. package/composables/useHidAmico.ts +97 -0
  21. package/composables/useHidNavigation.ts +25 -1
  22. package/composables/useNotification.ts +78 -0
  23. package/composables/usePeople.ts +19 -0
  24. package/composables/useSiteSettings.ts +114 -2
  25. package/composables/useWebUsb.ts +14 -11
  26. package/package.json +1 -1
  27. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  28. package/types/document.d.ts +14 -0
  29. package/types/facility.d.ts +4 -0
  30. package/types/people.d.ts +4 -1
  31. package/utils/anpr-direction.ts +70 -0
  32. package/utils/camera-plate-sync.ts +141 -0
  33. package/utils/materialSymbols.ts +3 -0
@@ -48,7 +48,22 @@ export default function () {
48
48
  }
49
49
  );
50
50
  }
51
- async function addCamera(camera: TSiteCamera & TCameraByRecorder) {
51
+ async function addCamera(
52
+ camera: TSiteCamera &
53
+ TCameraByRecorder & {
54
+ /**
55
+ * Clear the new ANPR camera's allowed list and blocklist on the device
56
+ * before the site's vehicles are added. Absent means keep them.
57
+ */
58
+ clearCameraLists?: boolean;
59
+ /**
60
+ * The add-camera screen has already cleared and filled the camera
61
+ * itself (`clearNewCamera` / `addNewCameraPlate`), so saving must not
62
+ * touch the device again.
63
+ */
64
+ skipPlateSync?: boolean;
65
+ }
66
+ ) {
52
67
  return await useNuxtApp().$api<Record<string, any>>(`/api/site-cameras`, {
53
68
  method: "POST",
54
69
  body: camera,
@@ -85,6 +100,83 @@ export default function () {
85
100
  * Try an address before saving it. Read-only, and it runs on the server —
86
101
  * the browser never touches a recorder and never sees a credential.
87
102
  */
103
+ /* ---- filling a NEW ANPR camera, before it is saved ---- */
104
+
105
+ type TNewCameraDevice = {
106
+ host: string;
107
+ username: string;
108
+ password: string;
109
+ name?: string;
110
+ direction: string;
111
+ };
112
+
113
+ /** The plates a new camera of this type receives, blocked ones first. */
114
+ async function getNewCameraPlates(
115
+ siteId: string,
116
+ query: { host: string; direction: string }
117
+ ) {
118
+ return await useNuxtApp().$api<{ items: Array<Record<string, any>> }>(
119
+ `/api/site-cameras/site/${siteId}/new-camera/plates`,
120
+ { method: "GET", query }
121
+ );
122
+ }
123
+
124
+ /** Empty the new camera's allowed list and blocklist on the device. */
125
+ async function clearNewCamera(siteId: string, device: TNewCameraDevice) {
126
+ return await useNuxtApp().$api<Record<string, any>>(
127
+ `/api/site-cameras/site/${siteId}/new-camera/clear`,
128
+ { method: "POST", body: device }
129
+ );
130
+ }
131
+
132
+ /**
133
+ * Write ONE vehicle's plate to the new camera. Answers `{ ok: false, reason,
134
+ * kind }` when the camera refuses it.
135
+ */
136
+ async function addNewCameraPlate(
137
+ siteId: string,
138
+ device: TNewCameraDevice,
139
+ plate: { vehicle: string; list: "allowed" | "blocked"; onlyIfMissing?: boolean }
140
+ ) {
141
+ return await useNuxtApp().$api<{ ok: boolean; reason?: string; kind?: string }>(
142
+ `/api/site-cameras/site/${siteId}/new-camera/plate`,
143
+ { method: "POST", body: { ...device, ...plate } }
144
+ );
145
+ }
146
+
147
+ /* ---- "Sync vehicles": filling a camera that is already saved ---- */
148
+
149
+ /** The plates this saved camera receives, blocked ones first. */
150
+ async function getCameraPlates(cameraId: string) {
151
+ return await useNuxtApp().$api<{ items: Array<Record<string, any>> }>(
152
+ `/api/site-cameras/id/${cameraId}/plates`,
153
+ { method: "GET" }
154
+ );
155
+ }
156
+
157
+ /** Empty the saved camera's allowed list and blocklist on the device. */
158
+ async function clearCamera(cameraId: string) {
159
+ return await useNuxtApp().$api<Record<string, any>>(
160
+ `/api/site-cameras/id/${cameraId}/clear`,
161
+ { method: "POST" }
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Write ONE vehicle's plate to the saved camera. The server uses the
167
+ * camera's stored login. Answers `{ ok: false, reason, kind }` when the
168
+ * camera refuses it.
169
+ */
170
+ async function addCameraPlate(
171
+ cameraId: string,
172
+ plate: { vehicle: string; list: "allowed" | "blocked"; onlyIfMissing?: boolean }
173
+ ) {
174
+ return await useNuxtApp().$api<{ ok: boolean; reason?: string; kind?: string }>(
175
+ `/api/site-cameras/id/${cameraId}/plate`,
176
+ { method: "POST", body: plate }
177
+ );
178
+ }
179
+
88
180
  async function testSiteCamera(
89
181
  siteId: string,
90
182
  payload: { host?: string } & TCameraByRecorder
@@ -112,7 +204,21 @@ export default function () {
112
204
  | "status"
113
205
  >
114
206
  > &
115
- TCameraByRecorder
207
+ TCameraByRecorder & {
208
+ /**
209
+ * The person confirmed that this type change clears the camera's
210
+ * plate lists on the camera itself (to Exit: allowed list and
211
+ * blocklist; Entry / Both / Residents to Visitors: allowed list).
212
+ * Without it the API refuses that change.
213
+ */
214
+ confirmClearCameraLists?: boolean;
215
+ /**
216
+ * Save a type change that would fill the camera (to Entry / Both /
217
+ * Residents, or Exit to Visitors) without filling it: the vehicles
218
+ * are added afterwards with "Sync vehicles", or not now.
219
+ */
220
+ skipPlateSync?: boolean;
221
+ }
116
222
  ) {
117
223
  return await useNuxtApp().$api<Record<string, any>>(
118
224
  `/api/site-cameras/id/${id}`,
@@ -303,6 +409,12 @@ export default function () {
303
409
  updateSite,
304
410
  addCamera,
305
411
  testSiteCamera,
412
+ getNewCameraPlates,
413
+ clearNewCamera,
414
+ addNewCameraPlate,
415
+ getCameraPlates,
416
+ clearCamera,
417
+ addCameraPlate,
306
418
  getAllSiteCameras,
307
419
  bulkImportSiteCameras,
308
420
  getSiteWall,
@@ -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.10.3",
5
+ "version": "4.11.1-staging.313",
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>
@@ -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"
@@ -0,0 +1,70 @@
1
+ /**
2
+ * ANPR camera types ("direction") that carry whitelist and season pass plates.
3
+ *
4
+ * Mirrors `ALLOW_CAMERA_DIRECTIONS` in iservice365-core
5
+ * (`src/utils/anpr-plate.util.ts`): an allowed plate is written to every Entry,
6
+ * Both Entry and Exit, and Residents camera, and never to Visitors or Exit.
7
+ */
8
+ export const ALLOW_CAMERA_DIRECTIONS = ["entry", "both", "residents"];
9
+
10
+ export const isAllowCameraDirection = (direction: unknown): boolean =>
11
+ ALLOW_CAMERA_DIRECTIONS.includes(
12
+ String(direction ?? "").trim().toLowerCase(),
13
+ );
14
+
15
+ /** ANPR camera types that carry blocked plates: every type except Exit. */
16
+ export const BLOCK_CAMERA_DIRECTIONS = ["entry", "both", "residents", "visitors"];
17
+
18
+ export const isBlockCameraDirection = (direction: unknown): boolean =>
19
+ BLOCK_CAMERA_DIRECTIONS.includes(
20
+ String(direction ?? "").trim().toLowerCase(),
21
+ );
22
+
23
+ /**
24
+ * Which of a camera's plate lists are FILLED with the site's vehicles when it
25
+ * is added (`from` empty) or its type changes - the lists the new type holds
26
+ * and the old one did not. Mirrors `listsFilledByDirectionChange` in
27
+ * iservice365-core. Nothing to confirm (nothing is removed), but saving takes
28
+ * longer, so the form says so.
29
+ */
30
+ export const listsFilledByDirectionChange = (
31
+ from: unknown,
32
+ to: unknown,
33
+ ): { allow: boolean; block: boolean } => {
34
+ const before = String(from ?? "").trim().toLowerCase();
35
+ const after = String(to ?? "").trim().toLowerCase();
36
+
37
+ if (!after || after === before) return { allow: false, block: false };
38
+
39
+ return {
40
+ allow: isAllowCameraDirection(after) && !isAllowCameraDirection(before),
41
+ block: isBlockCameraDirection(after) && !isBlockCameraDirection(before),
42
+ };
43
+ };
44
+
45
+ /**
46
+ * Which of a camera's plate lists a type change empties, on the camera itself
47
+ * - every plate on the list, including ones added directly on the camera.
48
+ * Mirrors `listsClearedByDirectionChange` in iservice365-core, which refuses
49
+ * the change unless it is confirmed, so the form asks first.
50
+ *
51
+ * - To Exit: the allowed list and the blocklist.
52
+ * - Entry / Both / Residents to Visitors: the allowed list.
53
+ * - Anything else: nothing.
54
+ */
55
+ export const listsClearedByDirectionChange = (
56
+ from: unknown,
57
+ to: unknown,
58
+ ): { allow: boolean; block: boolean } => {
59
+ const before = String(from ?? "").trim().toLowerCase();
60
+ const after = String(to ?? "").trim().toLowerCase();
61
+
62
+ if (!after || after === before) return { allow: false, block: false };
63
+
64
+ if (after === "exit") return { allow: true, block: true };
65
+
66
+ return {
67
+ allow: isAllowCameraDirection(before) && !isAllowCameraDirection(after),
68
+ block: false,
69
+ };
70
+ };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Writing a new ANPR camera's plates one at a time from the add-camera screen.
3
+ *
4
+ * The screen shows every plate the camera will receive with its own progress -
5
+ * pending, adding, added, failed - and lets the person retry. The rules for
6
+ * WHEN to stop live here, apart from the component, so they can be tested:
7
+ *
8
+ * - between plates, when the person presses Stop;
9
+ * - at once, when the camera refuses the LOGIN or the permission. Every further
10
+ * attempt would be another failed login, and a Dahua unit locks the account
11
+ * for 30 minutes after 3 failed logins in 30 seconds;
12
+ * - after 3 plates in a row fail for any other reason - the camera has most
13
+ * likely gone away, and each attempt waits for a timeout.
14
+ *
15
+ * Whatever is not attempted stays "pending", and Retry carries on with the
16
+ * failed and pending plates.
17
+ */
18
+
19
+ export type PlateSyncStatus = "pending" | "adding" | "added" | "failed";
20
+
21
+ export type PlateSyncRow = {
22
+ id: string;
23
+ vehicle: string;
24
+ list: "allowed" | "blocked";
25
+ plateNumber: string;
26
+ name: string;
27
+ block: string;
28
+ level: string;
29
+ unit: string;
30
+ kind: string;
31
+ status: PlateSyncStatus;
32
+ error?: string;
33
+ };
34
+
35
+ /** What writing one plate answered. `kind` as the API classifies a refusal. */
36
+ export type PlateWriteAnswer = {
37
+ ok: boolean;
38
+ reason?: string;
39
+ kind?: string;
40
+ };
41
+
42
+ export type PlateQueueStop = "done" | "requested" | "login" | "failures";
43
+
44
+ export const MAX_FAILURES_IN_A_ROW = 3;
45
+
46
+ export function plateSyncCounts(rows: PlateSyncRow[]) {
47
+ let added = 0;
48
+ let failed = 0;
49
+ let pending = 0;
50
+ for (const row of rows) {
51
+ if (row.status === "added") added++;
52
+ else if (row.status === "failed") failed++;
53
+ else pending++;
54
+ }
55
+ return { total: rows.length, added, failed, pending };
56
+ }
57
+
58
+ export type PlateSyncCounts = ReturnType<typeof plateSyncCounts>;
59
+
60
+ /**
61
+ * The same counts, kept apart for the allowed list (whitelist, season pass)
62
+ * and the blocklist - a failed blocked plate is a car that can still get in,
63
+ * which is not the same as a resident who cannot.
64
+ */
65
+ export function plateSyncCountsByList(rows: PlateSyncRow[]): {
66
+ allowed: PlateSyncCounts;
67
+ blocked: PlateSyncCounts;
68
+ } {
69
+ return {
70
+ allowed: plateSyncCounts(rows.filter((row) => row.list !== "blocked")),
71
+ blocked: plateSyncCounts(rows.filter((row) => row.list === "blocked")),
72
+ };
73
+ }
74
+
75
+ /** The plates Retry carries on with: every failed one and every pending one. */
76
+ export function rowsToRetry(rows: PlateSyncRow[]): PlateSyncRow[] {
77
+ return rows.filter((row) => row.status === "failed" || row.status === "pending");
78
+ }
79
+
80
+ /**
81
+ * Write `targets` one at a time, in order, updating each row's `status` (and
82
+ * `error`) in place. `write` may answer `{ ok: false }` or throw - both mark
83
+ * the row failed. Returns why it stopped, and the sentence to show for it.
84
+ */
85
+ export async function runPlateQueue(
86
+ targets: PlateSyncRow[],
87
+ write: (row: PlateSyncRow) => Promise<PlateWriteAnswer>,
88
+ options: { shouldStop?: () => boolean } = {},
89
+ ): Promise<{ stopped: PlateQueueStop; message: string }> {
90
+ let failuresInARow = 0;
91
+
92
+ for (const row of targets) {
93
+ if (options.shouldStop?.()) {
94
+ return {
95
+ stopped: "requested",
96
+ message: "Stopped. Press Retry to carry on with the pending and failed plates.",
97
+ };
98
+ }
99
+
100
+ row.status = "adding";
101
+ row.error = "";
102
+
103
+ let answer: PlateWriteAnswer;
104
+ try {
105
+ answer = await write(row);
106
+ } catch (error: any) {
107
+ answer = { ok: false, reason: String(error?.message ?? error ?? "") };
108
+ }
109
+
110
+ if (answer?.ok) {
111
+ row.status = "added";
112
+ failuresInARow = 0;
113
+ continue;
114
+ }
115
+
116
+ row.status = "failed";
117
+ row.error = answer?.reason || "The plate could not be added.";
118
+ failuresInARow++;
119
+
120
+ if (answer?.kind === "challenge" || answer?.kind === "rejected") {
121
+ return {
122
+ stopped: "login",
123
+ message:
124
+ `Stopped: ${row.error.replace(/\.\s*$/, "")}. Check the camera's ` +
125
+ `username and password, then press Retry.`,
126
+ };
127
+ }
128
+
129
+ if (failuresInARow >= MAX_FAILURES_IN_A_ROW) {
130
+ return {
131
+ stopped: "failures",
132
+ message:
133
+ `Stopped after ${MAX_FAILURES_IN_A_ROW} plates in a row could not ` +
134
+ `be added. Check that the camera is switched on and reachable, then ` +
135
+ `press Retry.`,
136
+ };
137
+ }
138
+ }
139
+
140
+ return { stopped: "done", message: "" };
141
+ }
@@ -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