@7365admin1/layer-common 4.21.3 → 4.21.4-staging.340

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 (39) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/components/AnprCameraBadge.vue +220 -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/HidAccessLogDashboard.vue +29 -5
  9. package/components/HidAccessPermissions.vue +424 -0
  10. package/components/HidIntercomManagement.vue +48 -1
  11. package/components/HidProfileQrCode.vue +323 -0
  12. package/components/HidReaderManagement.vue +26 -0
  13. package/components/HidReaderUserRoster.vue +32 -2
  14. package/components/HidUserEnrollment.vue +833 -152
  15. package/components/Input/NRICNumber.vue +14 -2
  16. package/components/InvitationClientForm.vue +19 -1
  17. package/components/PlateNumberDisplay.vue +105 -1
  18. package/components/VehicleForm.vue +324 -3
  19. package/components/VehicleManagement.vue +346 -51
  20. package/components/VisitorManagement.vue +434 -5
  21. package/composables/useAccessManagement.ts +5 -0
  22. package/composables/useDocument.ts +7 -0
  23. package/composables/useFacility.ts +11 -0
  24. package/composables/useHidAmico.ts +97 -0
  25. package/composables/useHidNavigation.ts +25 -1
  26. package/composables/usePeople.ts +19 -0
  27. package/composables/useVehicle.ts +101 -1
  28. package/composables/useWebUsb.ts +14 -11
  29. package/package.json +1 -1
  30. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  31. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  32. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  33. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  34. package/types/document.d.ts +14 -0
  35. package/types/facility.d.ts +4 -0
  36. package/types/people.d.ts +5 -2
  37. package/types/vehicle.d.ts +57 -2
  38. package/utils/hid-permission-assignments.ts +190 -0
  39. package/utils/vehicle-actions.ts +45 -17
@@ -0,0 +1,190 @@
1
+ /**
2
+ * WHO IS ASSIGNED TO A HID READER — the editing model behind the permissions
3
+ * dialog.
4
+ *
5
+ * This is the step that actually grants access. Enrolling a person gives the
6
+ * reader a face, a card or a PIN it can RECOGNISE; it puts nobody in the group
7
+ * the access rule is attached to, so a recognised person is still refused at
8
+ * the door (access log event 6). `PUT /sites/:siteId/permissions` is the only
9
+ * call in the system that writes that group membership.
10
+ *
11
+ * Two contracts make this file necessary rather than inlining the logic in the
12
+ * component:
13
+ *
14
+ * 1. **The PUT REPLACES the whole assignment set for the reader.** The server
15
+ * keeps other readers' rows and overwrites this reader's with exactly what
16
+ * is sent. The candidate list, however, is fetched ONE CATEGORY AT A TIME.
17
+ * Saving from the tab in front of you while sending only that tab's people
18
+ * would silently revoke every resident if you were looking at the service
19
+ * providers tab. So the edit state is held for the whole reader and the
20
+ * payload is always built from all of it.
21
+ *
22
+ * 2. **The body schema accepts three keys and nothing else.**
23
+ * `hidPermissionAssignmentSchema` is `{ subjectId, category, intercom }`,
24
+ * and Joi rejects unknown keys rather than stripping them. The candidate
25
+ * rows carry `name`, `subtitle`, `location` and friends for display, so the
26
+ * payload has to be narrowed deliberately — passing a candidate straight
27
+ * through is a 400.
28
+ */
29
+
30
+ /** The three real categories. `intercom` is a candidate FILTER, never a category. */
31
+ export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
32
+ "resident",
33
+ "property_management",
34
+ "service_provider",
35
+ ];
36
+
37
+ export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
38
+
39
+ /** Body row for `updateSitePermissions` — exactly the keys Joi allows. */
40
+ export type HidAssignmentPayload = {
41
+ subjectId: string;
42
+ category: THidPermissionCategory;
43
+ intercom: boolean;
44
+ };
45
+
46
+ function isRealCategory(value: unknown): value is THidPermissionCategory {
47
+ return HID_PERMISSION_CATEGORIES.includes(value as THidPermissionCategory);
48
+ }
49
+
50
+ /**
51
+ * The reader's CURRENT assignments, as the edit state.
52
+ *
53
+ * Seeded from `getSitePermissions`, which returns every category at once —
54
+ * that is what makes a whole-reader payload possible from a one-category view.
55
+ * Rows with an unrecognised category are dropped rather than carried: sending
56
+ * one back fails the enum check and takes the entire save with it.
57
+ */
58
+ export function seedAssignments(
59
+ assignments: readonly THidPermissionAssignment[] | undefined | null,
60
+ ): HidAssignmentState {
61
+ const state: HidAssignmentState = new Map();
62
+ if (!Array.isArray(assignments)) return state;
63
+ for (const assignment of assignments) {
64
+ const subjectId = String(assignment?.subjectId ?? "");
65
+ if (!subjectId || !isRealCategory(assignment?.category)) continue;
66
+ state.set(subjectId, {
67
+ category: assignment.category,
68
+ intercom: assignment.intercom === true,
69
+ });
70
+ }
71
+ return state;
72
+ }
73
+
74
+ /**
75
+ * Add or remove one person.
76
+ *
77
+ * `saved` is the state the dialog opened with, and it is consulted for one
78
+ * reason: the `intercom` flag. Nothing here edits that flag, but
79
+ * `userHasSiteIntercomPermission` reads it off these same rows, so it must
80
+ * survive a round trip through the checkbox.
81
+ *
82
+ * - **Untick then save** drops it, which is right — an unassigned person
83
+ * holding a dangling intercom right would keep answering the door panel
84
+ * after losing the door.
85
+ * - **Untick then re-tick, without saving** must restore it. Removing from the
86
+ * draft forgets the flag, so re-adding recovers it from `saved`; otherwise a
87
+ * misclick corrected a second later would silently revoke intercom on the
88
+ * next save, with nothing on screen to show it had happened.
89
+ */
90
+ export function setAssignment(
91
+ state: HidAssignmentState,
92
+ saved: HidAssignmentState,
93
+ subjectId: string,
94
+ category: THidPermissionCategory,
95
+ selected: boolean,
96
+ ): HidAssignmentState {
97
+ const next: HidAssignmentState = new Map(state);
98
+ const id = String(subjectId ?? "");
99
+ if (!id || !isRealCategory(category)) return next;
100
+ if (!selected) {
101
+ next.delete(id);
102
+ return next;
103
+ }
104
+ const intercom = next.get(id)?.intercom ?? saved.get(id)?.intercom ?? false;
105
+ next.set(id, { category, intercom: intercom === true });
106
+ return next;
107
+ }
108
+
109
+ /** The whole reader's assignments, narrowed to the three keys the API accepts. */
110
+ export function toAssignmentPayload(state: HidAssignmentState): HidAssignmentPayload[] {
111
+ return [...state.entries()].map(([subjectId, value]) => ({
112
+ subjectId,
113
+ category: value.category,
114
+ intercom: value.intercom === true,
115
+ }));
116
+ }
117
+
118
+ /**
119
+ * The server sends `selected` with each candidate, describing what is SAVED.
120
+ * Once the dialog is open the local edit state is the truth, so the flag is
121
+ * recomputed rather than trusted — otherwise paging or searching would redraw
122
+ * a row with the saved value and quietly discard an unsaved tick.
123
+ */
124
+ export function applySelection(
125
+ candidates: readonly THidPermissionCandidate[] | undefined | null,
126
+ state: HidAssignmentState,
127
+ ): THidPermissionCandidate[] {
128
+ if (!Array.isArray(candidates)) return [];
129
+ return candidates.map((candidate) => ({
130
+ ...candidate,
131
+ selected: state.has(String(candidate?.subjectId ?? "")),
132
+ }));
133
+ }
134
+
135
+ /** Per-category totals for the dialog header, counted over the whole reader. */
136
+ export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
137
+ const counts = { resident: 0, property_management: 0, service_provider: 0 } as Record<
138
+ THidPermissionCategory,
139
+ number
140
+ >;
141
+ for (const value of state.values()) counts[value.category] += 1;
142
+ return counts;
143
+ }
144
+
145
+ /** Has anything changed since the dialog opened? Drives the Save button. */
146
+ export function hasChanges(saved: HidAssignmentState, draft: HidAssignmentState): boolean {
147
+ if (saved.size !== draft.size) return true;
148
+ for (const [subjectId, value] of draft) {
149
+ const before = saved.get(subjectId);
150
+ if (!before) return true;
151
+ if (before.category !== value.category) return true;
152
+ if (before.intercom !== value.intercom) return true;
153
+ }
154
+ return false;
155
+ }
156
+
157
+ /**
158
+ * What a listing response tells us: the rows, and how many pages exist.
159
+ *
160
+ * It deliberately does NOT return the current page, and the caller must keep
161
+ * owning that. `paginate` in `@7365admin1/node-server-utils` returns only
162
+ * `{ items, pages, pageRange }` — it never echoes the page it was asked for. A
163
+ * caller that read one back therefore got a default on every fetch and pinned
164
+ * itself to page one, so the pager moved and the rows never did.
165
+ *
166
+ * `items` sits at the root on some of these endpoints and under `data` on
167
+ * others, so both are read.
168
+ */
169
+ export function readCandidatePage(response: unknown): {
170
+ items: THidPermissionCandidate[];
171
+ pages: number;
172
+ pageRange: string;
173
+ } {
174
+ const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
175
+ const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
176
+ const items = Array.isArray(source.items)
177
+ ? source.items
178
+ : Array.isArray(nested.items)
179
+ ? nested.items
180
+ : [];
181
+ const pages = Number(source.pages ?? nested.pages ?? 1);
182
+ // `paginate` builds this ("1-10 of 37") and the table renders it verbatim.
183
+ // Without it the pager draws its placeholder, "-- - -- of --".
184
+ const pageRange = String(source.pageRange ?? nested.pageRange ?? "");
185
+ return {
186
+ items: items as THidPermissionCandidate[],
187
+ pages: Number.isFinite(pages) && pages > 0 ? pages : 1,
188
+ pageRange,
189
+ };
190
+ }
@@ -19,7 +19,8 @@ export type VehicleActionKey =
19
19
  | "edit"
20
20
  | "approve"
21
21
  | "restore"
22
- | "toggle-type"
22
+ | "block"
23
+ | "unblock"
23
24
  | "delete";
24
25
 
25
26
  export type VehicleActionPermissions = {
@@ -44,11 +45,22 @@ export type VehicleActionPlate = {
44
45
  };
45
46
 
46
47
  /**
47
- * `inactive` is the status a blocked vehicle carries, and `deleted` is a
48
- * soft-deleted one. Both are "not currently working, and someone should be
49
- * able to put it back".
48
+ * The statuses, as the server now writes them:
49
+ *
50
+ * - active whitelisted, on the cameras' allowed list
51
+ * - temporary a season pass - whitelisted until its end date
52
+ * - blocked on every camera's blocklist (category "Block Listed")
53
+ * - unblocked off every blocklist and on no allowed list; the record stays
54
+ * - pending waiting for approval
55
+ * - deleted soft-deleted
56
+ * - inactive / rejected older records, restorable
57
+ *
58
+ * A site holds a plate ONCE whatever its status, so a vehicle that is not
59
+ * working any more is put back from its own record (Restore / Block) rather
60
+ * than added again.
50
61
  */
51
- const RESTORABLE = new Set(["inactive", "deleted", "rejected"]);
62
+ const LIVE_ALLOWED = new Set(["active", "temporary"]);
63
+ const RESTORABLE = new Set(["deleted", "inactive", "rejected"]);
52
64
 
53
65
  export function vehiclePlateActions(
54
66
  plate: VehicleActionPlate | null | undefined,
@@ -59,14 +71,19 @@ export function vehiclePlateActions(
59
71
  const status = String(plate.status ?? "").toLowerCase();
60
72
  const type = String(plate.type ?? "").toLowerCase();
61
73
 
62
- const isActive = status === "active";
74
+ // Records written before the new statuses carried "active" on a blocklist
75
+ // vehicle; they are blocked on the cameras all the same.
76
+ const isBlocked =
77
+ status === "blocked" || (status === "active" && type === "blocklist");
78
+ const isAllowed = LIVE_ALLOWED.has(status) && !isBlocked;
63
79
  const isPending = status === "pending";
80
+ const isUnblocked = status === "unblocked";
64
81
  const isRestorable = RESTORABLE.has(status);
65
- const isTogglableType = type === "whitelist" || type === "blocklist";
66
82
 
83
+ const canUpdate = !!permissions.canUpdateVehicle;
67
84
  const actions: VehicleAction[] = [];
68
85
 
69
- if (permissions.canUpdateVehicle && isActive) {
86
+ if (canUpdate && (isAllowed || isBlocked)) {
70
87
  actions.push({ key: "edit", title: "Edit Vehicle", icon: "mdi-pencil" });
71
88
  }
72
89
 
@@ -80,27 +97,38 @@ export function vehiclePlateActions(
80
97
  }
81
98
 
82
99
  // Restore is deliberately NOT gated on `canUpdateVehicle`: it was ungated
83
- // before this change and narrowing a gate is a separate, role-data decision.
84
- // What changes is that a blocked vehicle now offers it at all.
100
+ // before and narrowing a gate is a separate, role-data decision.
85
101
  if (isRestorable) {
86
102
  actions.push({
87
103
  key: "restore",
88
- title: status === "inactive" ? "Unblock" : "Restore",
104
+ title: "Restore",
89
105
  icon: "mdi-restore",
90
106
  color: "warning",
91
107
  });
92
108
  }
93
109
 
94
- if (permissions.canUpdateVehicle && isTogglableType && isActive) {
110
+ // Any record that is not already blocked (and is not waiting for approval)
111
+ // can be blocked - including an unblocked or deleted one, which is how the
112
+ // same plate is blocked again without a second record.
113
+ if (canUpdate && (isAllowed || isUnblocked || isRestorable)) {
114
+ actions.push({
115
+ key: "block",
116
+ title: "Block",
117
+ icon: "mdi-cancel",
118
+ color: "error",
119
+ });
120
+ }
121
+
122
+ if (canUpdate && isBlocked) {
95
123
  actions.push({
96
- key: "toggle-type",
97
- title: type === "blocklist" ? "Unblock" : "Block",
98
- icon: "mdi-swap-horizontal",
99
- color: type === "blocklist" ? "primary" : "error",
124
+ key: "unblock",
125
+ title: "Unblock",
126
+ icon: "mdi-lock-open-variant",
127
+ color: "primary",
100
128
  });
101
129
  }
102
130
 
103
- if (permissions.canDeleteVehicle && isActive) {
131
+ if (permissions.canDeleteVehicle && (isAllowed || isBlocked)) {
104
132
  actions.push({
105
133
  key: "delete",
106
134
  title: "Delete",