@7365admin1/layer-common 4.90.2-staging.490 → 4.90.2

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 (67) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/assets/css/primitives.css +0 -57
  3. package/assets/css/screens.css +4 -8
  4. package/components/AccessCardDetailsDialog.vue +6 -59
  5. package/components/AccessCardPreviewDialog.vue +53 -371
  6. package/components/AppSelect.vue +4 -143
  7. package/components/BuildingUnitFormEdit.vue +0 -6
  8. package/components/Dialog/UpdateMoreAction.vue +1 -11
  9. package/components/DocumentForm.vue +112 -407
  10. package/components/DocumentManagement.vue +12 -213
  11. package/components/Facility/BookingSetup.vue +0 -63
  12. package/components/HidAccessLogDashboard.vue +17 -74
  13. package/components/HidIntercomManagement.vue +14 -183
  14. package/components/HidQrCodeConfiguration.vue +195 -17
  15. package/components/HidReaderManagement.vue +0 -398
  16. package/components/HidReaderUserRoster.vue +3 -44
  17. package/components/HidUserEnrollment.vue +292 -2255
  18. package/components/InvitationClientForm.vue +1 -19
  19. package/components/InvitationForm.vue +4 -31
  20. package/components/InvitationMain.vue +22 -124
  21. package/components/MemberInformation.vue +4 -4
  22. package/components/PassInformation.vue +2 -2
  23. package/components/SiteSettings.vue +0 -48
  24. package/components/TableMain.vue +7 -22
  25. package/components/VehicleManagement.vue +5 -80
  26. package/components/VisitorForm.vue +19 -65
  27. package/components/VisitorManagement.vue +5 -267
  28. package/composables/useAccessManagement.ts +1 -17
  29. package/composables/useDocument.ts +0 -7
  30. package/composables/useFacility.ts +0 -11
  31. package/composables/useHidAmico.ts +0 -165
  32. package/composables/useHidNavigation.ts +1 -25
  33. package/composables/useMember.ts +0 -12
  34. package/composables/useNFCPatrolReportFilters.ts +3 -21
  35. package/composables/useNFCPatrolRoute.ts +1 -8
  36. package/composables/usePeople.ts +0 -19
  37. package/composables/useServiceProvider.ts +2 -45
  38. package/composables/useSettingsPermission.ts +0 -14
  39. package/composables/useUser.ts +2 -6
  40. package/composables/useVehicle.ts +1 -40
  41. package/composables/useVerification.ts +0 -3
  42. package/middleware/01.auth.ts +7 -3
  43. package/package.json +1 -1
  44. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  45. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  46. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  47. package/types/document.d.ts +0 -14
  48. package/types/facility.d.ts +0 -4
  49. package/types/member.d.ts +0 -4
  50. package/types/people.d.ts +1 -28
  51. package/types/service-provider.d.ts +0 -5
  52. package/types/site.d.ts +1 -7
  53. package/components/BuildingUnitManagement.vue +0 -298
  54. package/components/HidAccessPermissions.vue +0 -424
  55. package/components/HidProfileQrCode.vue +0 -332
  56. package/components/VehicleQrStickerDialog.vue +0 -249
  57. package/composables/useHidReaderSelection.ts +0 -50
  58. package/composables/useSiteCategory.ts +0 -45
  59. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  60. package/utils/hid-enrolment-subject.ts +0 -344
  61. package/utils/hid-permission-assignments.ts +0 -198
  62. package/utils/hid-reader-selection.ts +0 -52
  63. package/utils/invite-group.ts +0 -61
  64. package/utils/invite-sites.ts +0 -25
  65. package/utils/occupancy-role.ts +0 -109
  66. package/utils/service-type.ts +0 -30
  67. package/utils/vehicle-qr-sticker.ts +0 -184
@@ -1,23 +0,0 @@
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>
@@ -1,344 +0,0 @@
1
- /**
2
- * WHO A HID ENROLMENT IS FOR — the pure decisions behind the subject picker.
3
- *
4
- * `HidUserEnrollment.vue` can enrol a resident or a staff member. The write path
5
- * always carried both (`subjectLink` maps them onto `person` or `member`); what
6
- * was missing was a way to choose. These are the parts of that choice worth
7
- * testing on their own, kept here because a `.vue` component has no test harness
8
- * in this repo.
9
- */
10
-
11
- /**
12
- * What the ENROLLING dropdown offers. Three of these four are the server's own
13
- * permission categories; `service_provider_staff` is this screen's own value
14
- * and deliberately not one of them - see `subjectLinkOf`.
15
- */
16
- export type HidEnrolmentSubject =
17
- | "resident"
18
- | "property_management"
19
- | "service_provider_staff";
20
-
21
- /**
22
- * The dropdown's options, in the order they are drawn.
23
- *
24
- * `title`/`value` because `AppSelect` takes that shape.
25
- */
26
- export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
27
- title: string;
28
- value: HidEnrolmentSubject;
29
- }> = [
30
- { title: "Resident", value: "resident" },
31
- { title: "Member", value: "property_management" },
32
- { title: "Service provider", value: "service_provider_staff" },
33
- ];
34
-
35
- /**
36
- * What an EDIT calls the subject it is already attached to.
37
- *
38
- * Wider than the dropdown on purpose. An identity's category cannot change after
39
- * it is created, so an edit states it rather than offering it — and the records
40
- * in the wild include `service_provider`, which the dropdown does not offer yet
41
- * but `openEdit` does resolve. Falling back to the first option would label a
42
- * contractor "Resident", which is worse than saying nothing useful.
43
- */
44
- export function subjectCategoryLabel(category: unknown): string {
45
- const labels: Record<string, string> = {
46
- resident: "Resident",
47
- property_management: "Member",
48
- // The dropdown's own value: ONE PERSON from a provider company.
49
- service_provider_staff: "Service provider",
50
- // The server's category, which names a COMPANY. Records in the wild carry
51
- // it, and an edit must not call such a row a resident.
52
- service_provider: "Service provider",
53
- visitor: "Visitor",
54
- };
55
- return labels[String(category ?? "")] ?? "Unknown";
56
- }
57
-
58
- /**
59
- * One page of `GET /api/members`, read defensively.
60
- *
61
- * `paginate` puts `{ items, pages }` at the root, but `items` sits under `data`
62
- * on some of this product's endpoints, so both are read — the same allowance
63
- * `readCandidatePage` makes. A response that carries neither is an empty page
64
- * rather than a thrown error: an empty staff picker with a placeholder beats a
65
- * broken dialog.
66
- */
67
- export function readMemberPage(response: unknown): {
68
- items: Record<string, unknown>[];
69
- pages: number;
70
- total: number;
71
- } {
72
- const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
73
- const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
74
- const raw = Array.isArray(source.items)
75
- ? source.items
76
- : Array.isArray(nested.items)
77
- ? nested.items
78
- : [];
79
- const pages = Number(source.pages ?? nested.pages ?? 1);
80
- const items = raw.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === "object");
81
- /*
82
- * `total` drives "showing 10 of 23" and the Load more button. It falls back to
83
- * the page's own length, not to zero, so a response without it simply reads as
84
- * "this is everything" — a missing count must never make the button offer a
85
- * page that is not there.
86
- */
87
- const total = Number(source.total ?? nested.total ?? items.length);
88
- return {
89
- items,
90
- pages: Number.isFinite(pages) && pages > 0 ? Math.floor(pages) : 1,
91
- total: Number.isFinite(total) && total >= 0 ? Math.floor(total) : items.length,
92
- };
93
- }
94
-
95
- /**
96
- * Can this member actually be enrolled?
97
- *
98
- * Reader access is bound by USER id — `resolvePermissionUserBindings` in
99
- * `iservice365-core` drops every subject without one — so a member with no app
100
- * account cannot be given access and is not a candidate. The id arrives as a
101
- * string from JSON but may be an object if a caller passes a raw document, so
102
- * both are read rather than trusting the shape.
103
- */
104
- export function memberHasAccount(row: Record<string, unknown> | null | undefined): boolean {
105
- const user = row?.user;
106
- if (!user) return false;
107
- if (typeof user === "object") {
108
- const id = (user as { _id?: unknown; toString?: () => string })._id ?? user;
109
- return Boolean(String(id ?? "").trim());
110
- }
111
- return Boolean(String(user).trim());
112
- }
113
-
114
- /**
115
- * How a member reads in the picker: their name, and their role beneath it.
116
- *
117
- * THE ACCOUNT'S NAME FIRST, then the membership's. The two diverge — a
118
- * membership is created with whatever name was typed at invite time, and the
119
- * person may have set their own on the account since — and the account name is
120
- * the one they are known by. `userName` comes from the members endpoint's own
121
- * lookup into `users`; a member with no account has none, but such a row is not
122
- * a candidate anyway (`memberHasAccount`).
123
- *
124
- * Every step falls back, because a row with no name at all still has to be
125
- * selectable rather than blank, or it cannot be told apart from the next one.
126
- */
127
- export function memberCandidateOf(row: Record<string, unknown>): {
128
- subjectId: string;
129
- name: string;
130
- subtitle: string;
131
- } {
132
- const text = (value: unknown) => String(value ?? "").trim();
133
- return {
134
- subjectId: text(row._id),
135
- name: text(row.userName) || text(row.name) || text(row.email) || "Member",
136
- subtitle: text(row.roleName) || text(row.email) || "",
137
- };
138
- }
139
-
140
- /**
141
- * Why somebody the operator can see elsewhere is not in this list.
142
- *
143
- * Left unexplained, an absence reads as a broken screen — the same reason the
144
- * resident cascade carries `unitResidentNote`. Returns "" when there is nothing
145
- * to say, so the caller can render it unconditionally.
146
- */
147
- export function hiddenSubjectNote(count: number, noun: "resident" | "member"): string {
148
- if (!Number.isFinite(count) || count <= 0) return "";
149
- const whole = Math.floor(count);
150
- const subject = whole === 1 ? `1 ${noun}` : `${whole} ${noun}s`;
151
- const verb = whole === 1 ? "is" : "are";
152
- const holder = whole === 1 ? "that person has" : "they have";
153
- return `${subject} at this site ${verb} not listed:`
154
- + ` HID enrollment needs an app account, and ${holder} none yet.`;
155
- }
156
-
157
- /* ── THE LINK THAT REACHES THE DEVICE ──────────────────────────────────── */
158
-
159
- /**
160
- * WHICH SUBJECT FIELD AN ENROLMENT WRITES, and what the identity is called.
161
- *
162
- * This is the one decision in the dialog that changes who a door lets in, so it
163
- * lives here with tests rather than inline in the template's script.
164
- *
165
- * `service_provider_staff` links through `member`, NOT `serviceProvider`, and
166
- * that is the whole design:
167
- *
168
- * - `serviceProvider` names a `site.service-providers` row, which is a COMPANY.
169
- * `resolvePermissionUserBindings` expands one into every active member of
170
- * that organisation with NO site filter, so granting it puts a 200-person
171
- * firm on a door that eight of them attend.
172
- * - A provider employee's membership lives in `members` with `siteId` set to
173
- * this site - `members` carries a unique index on `{org, siteId, user, type}`,
174
- * so it cannot exist there without one. That makes the person site-scoped by
175
- * construction, which is the whole point.
176
- *
177
- * The identity `type` is `"contractor"` rather than `"staff"`, and it is load
178
- * bearing on the server as well as here: core's `permissionSubjectOfIdentity`
179
- * reads it to tell a contractor's `member` link from a property-management one,
180
- * and files the grant under `service_provider_member` or `property_management`
181
- * accordingly. It is also what the Access Permissions tabs filter on.
182
- *
183
- * An earlier version filed provider staff under `property_management`, since that
184
- * category's subject list already accepts these rows. It worked for access and
185
- * failed for identity: `permissionIdentityType` derives the identity's type from
186
- * the category, so every contractor came back as `staff` - and because the
187
- * reconcile rewrites the identity it finds, the `"contractor"` written here was
188
- * overwritten seconds later.
189
- *
190
- * An empty `subjectId` returns `{}` ON PURPOSE. Sending `person: ""` is not
191
- * "leave this alone", it is "clear it": the server reads an empty string as the
192
- * link being removed and then refuses the write for having no subject at all.
193
- */
194
- export function subjectLinkOf(
195
- category: unknown,
196
- subjectId: unknown,
197
- ): {
198
- person?: string;
199
- member?: string;
200
- serviceProvider?: string;
201
- type?: "resident" | "staff" | "contractor";
202
- } {
203
- const id = String(subjectId ?? "").trim();
204
- if (!id) return {};
205
- const of = (
206
- field: "person" | "member" | "serviceProvider",
207
- type: "resident" | "staff" | "contractor",
208
- ) => ({
209
- person: field === "person" ? id : "",
210
- member: field === "member" ? id : "",
211
- serviceProvider: field === "serviceProvider" ? id : "",
212
- type,
213
- });
214
- switch (String(category ?? "")) {
215
- case "resident":
216
- return of("person", "resident");
217
- case "service_provider_staff":
218
- return of("member", "contractor");
219
- case "service_provider":
220
- return of("serviceProvider", "contractor");
221
- default:
222
- return of("member", "staff");
223
- }
224
- }
225
-
226
- /**
227
- * Which PERMISSION CATEGORY an enrolment's access grant is stored under.
228
- *
229
- * Mirrors `permissionSubjectOfIdentity` in core, which reads the stored links
230
- * rather than this dropdown: a `member` link resolves to `property_management`
231
- * whatever the identity's `type` says. Provider staff therefore share the staff
232
- * category, which is correct - they are validated against the same subject list
233
- * - and the identity `type` is what tells them apart on screen.
234
- */
235
- export function permissionCategoryOf(category: unknown): string {
236
- const value = String(category ?? "");
237
- if (value === "resident") return "resident";
238
- if (value === "service_provider") return "service_provider";
239
- if (value === "service_provider_staff") return "service_provider_member";
240
- return "property_management";
241
- }
242
-
243
- /* ── PROVIDER STAFF AS PICKER ROWS ─────────────────────────────────────── */
244
-
245
- /**
246
- * Can this provider employee be enrolled?
247
- *
248
- * Two conditions, and both have to be checked here rather than trusted from the
249
- * list. An app account, because reader access is bound by user id
250
- * (`memberHasAccount`). And an ACTIVE membership: `getProviderMembersBySite`
251
- * returns everyone who is not deleted, so a suspended person is in the list the
252
- * Members screen draws - marked, deliberately, so the property manager can see
253
- * them. Offering a suspended person a door is a different matter.
254
- */
255
- export function providerCanEnrol(
256
- row: Record<string, unknown> | null | undefined,
257
- ): boolean {
258
- if (!memberHasAccount(row)) return false;
259
- return String(row?.status ?? "").trim() === "active";
260
- }
261
-
262
- /**
263
- * How a provider employee reads in the picker: their name, their company and
264
- * the service beneath it.
265
- *
266
- * The company comes FIRST in the subtitle. Two contractors with the same first
267
- * name are common, and which firm somebody belongs to is what the property
268
- * manager actually recognises them by - the service type alone ("Security")
269
- * describes half the list.
270
- */
271
- export function providerCandidateOf(row: Record<string, unknown>): {
272
- subjectId: string;
273
- name: string;
274
- subtitle: string;
275
- } {
276
- const text = (value: unknown) => String(value ?? "").trim();
277
- const parts = [text(row.company), text(row.typeLabel)].filter(Boolean);
278
- return {
279
- subjectId: text(row._id),
280
- name: text(row.name) || text(row.email) || "Service provider",
281
- subtitle: parts.join(" · ") || text(row.role) || text(row.email) || "",
282
- };
283
- }
284
-
285
- /**
286
- * Does this list tell us who has an app account?
287
- *
288
- * `GET /api/service-providers/site-members` only began returning `user` in core
289
- * 3.130; before that the service layer dropped it even though the repository
290
- * projected it. Frontend and backend deploy separately, so this screen can run
291
- * against either. Asked of the ROWS rather than of a version number: the key is
292
- * present on every row or on none.
293
- *
294
- * It matters because the answer flips a filter from "cannot be bound to a door"
295
- * to "unknown", and a screen that silently reports NOBODY can be enrolled is
296
- * worse than one that offers somebody the server then refuses by name.
297
- */
298
- export function providerAccountsKnown(
299
- rows: ReadonlyArray<Record<string, unknown>>,
300
- ): boolean {
301
- return rows.some((row) => Boolean(row) && typeof row === "object" && "user" in row);
302
- }
303
-
304
- /**
305
- * Who may be offered a door, from whatever the endpoint returned.
306
- *
307
- * With accounts known, both conditions apply (`providerCanEnrol`). Without them,
308
- * active membership is all that can be checked here — the server still refuses
309
- * anyone it cannot bind, with a message naming them, which is a better failure
310
- * than an empty picker.
311
- */
312
- export function providerEnrollableRows<T extends Record<string, unknown>>(
313
- rows: ReadonlyArray<T>,
314
- ): T[] {
315
- const known = providerAccountsKnown(rows);
316
- return rows.filter((row) =>
317
- known ? providerCanEnrol(row) : String(row?.status ?? "").trim() === "active",
318
- );
319
- }
320
-
321
- /* ── THE SERVICE FILTER'S "ALL" ────────────────────────────────────────── */
322
-
323
- /**
324
- * WHY "ALL SERVICES" CANNOT BE THE EMPTY STRING HERE.
325
- *
326
- * `filterProviderMembers` reads an empty `type` as "do not filter", and the
327
- * Members screen's own filter uses `value: ""` for All services - but that screen
328
- * draws a Vuetify `v-select`, which renders an empty value perfectly well.
329
- *
330
- * `AppSelect` does not. Its `hasSingleValue` is false for `""`, so the field
331
- * falls back to the placeholder, draws in the placeholder's grey, and the option
332
- * is never marked as the chosen one in the menu. The filter worked; it just
333
- * looked like nothing was selected and like only the real services existed.
334
- *
335
- * So the option carries a real value here and is translated on the way to the
336
- * filter. Changing `AppSelect` instead would touch every one of its callers.
337
- */
338
- export const HID_ALL_SERVICES = "all";
339
-
340
- /** The `type` to filter by: "" for All services, the service code otherwise. */
341
- export function serviceFilterOf(selected: unknown): string {
342
- const value = String(selected ?? "").trim();
343
- return value === HID_ALL_SERVICES ? "" : value;
344
- }
@@ -1,198 +0,0 @@
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
- /**
31
- * The real categories. `intercom` is a candidate FILTER, never a category.
32
- *
33
- * Mirrors `HID_PERMISSION_CATEGORIES` in core, and has to: `seedAssignments`
34
- * DROPS a row whose category is not in this list, so a category missing here
35
- * silently loses that grant from the edit state - and the save that follows,
36
- * being a whole-reader replace, would revoke it.
37
- */
38
- export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
39
- "resident",
40
- "property_management",
41
- "service_provider",
42
- "service_provider_member",
43
- ];
44
-
45
- export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
46
-
47
- /** Body row for `updateSitePermissions` — exactly the keys Joi allows. */
48
- export type HidAssignmentPayload = {
49
- subjectId: string;
50
- category: THidPermissionCategory;
51
- intercom: boolean;
52
- };
53
-
54
- function isRealCategory(value: unknown): value is THidPermissionCategory {
55
- return HID_PERMISSION_CATEGORIES.includes(value as THidPermissionCategory);
56
- }
57
-
58
- /**
59
- * The reader's CURRENT assignments, as the edit state.
60
- *
61
- * Seeded from `getSitePermissions`, which returns every category at once —
62
- * that is what makes a whole-reader payload possible from a one-category view.
63
- * Rows with an unrecognised category are dropped rather than carried: sending
64
- * one back fails the enum check and takes the entire save with it.
65
- */
66
- export function seedAssignments(
67
- assignments: readonly THidPermissionAssignment[] | undefined | null,
68
- ): HidAssignmentState {
69
- const state: HidAssignmentState = new Map();
70
- if (!Array.isArray(assignments)) return state;
71
- for (const assignment of assignments) {
72
- const subjectId = String(assignment?.subjectId ?? "");
73
- if (!subjectId || !isRealCategory(assignment?.category)) continue;
74
- state.set(subjectId, {
75
- category: assignment.category,
76
- intercom: assignment.intercom === true,
77
- });
78
- }
79
- return state;
80
- }
81
-
82
- /**
83
- * Add or remove one person.
84
- *
85
- * `saved` is the state the dialog opened with, and it is consulted for one
86
- * reason: the `intercom` flag. Nothing here edits that flag, but
87
- * `userHasSiteIntercomPermission` reads it off these same rows, so it must
88
- * survive a round trip through the checkbox.
89
- *
90
- * - **Untick then save** drops it, which is right — an unassigned person
91
- * holding a dangling intercom right would keep answering the door panel
92
- * after losing the door.
93
- * - **Untick then re-tick, without saving** must restore it. Removing from the
94
- * draft forgets the flag, so re-adding recovers it from `saved`; otherwise a
95
- * misclick corrected a second later would silently revoke intercom on the
96
- * next save, with nothing on screen to show it had happened.
97
- */
98
- export function setAssignment(
99
- state: HidAssignmentState,
100
- saved: HidAssignmentState,
101
- subjectId: string,
102
- category: THidPermissionCategory,
103
- selected: boolean,
104
- ): HidAssignmentState {
105
- const next: HidAssignmentState = new Map(state);
106
- const id = String(subjectId ?? "");
107
- if (!id || !isRealCategory(category)) return next;
108
- if (!selected) {
109
- next.delete(id);
110
- return next;
111
- }
112
- const intercom = next.get(id)?.intercom ?? saved.get(id)?.intercom ?? false;
113
- next.set(id, { category, intercom: intercom === true });
114
- return next;
115
- }
116
-
117
- /** The whole reader's assignments, narrowed to the three keys the API accepts. */
118
- export function toAssignmentPayload(state: HidAssignmentState): HidAssignmentPayload[] {
119
- return [...state.entries()].map(([subjectId, value]) => ({
120
- subjectId,
121
- category: value.category,
122
- intercom: value.intercom === true,
123
- }));
124
- }
125
-
126
- /**
127
- * The server sends `selected` with each candidate, describing what is SAVED.
128
- * Once the dialog is open the local edit state is the truth, so the flag is
129
- * recomputed rather than trusted — otherwise paging or searching would redraw
130
- * a row with the saved value and quietly discard an unsaved tick.
131
- */
132
- export function applySelection(
133
- candidates: readonly THidPermissionCandidate[] | undefined | null,
134
- state: HidAssignmentState,
135
- ): THidPermissionCandidate[] {
136
- if (!Array.isArray(candidates)) return [];
137
- return candidates.map((candidate) => ({
138
- ...candidate,
139
- selected: state.has(String(candidate?.subjectId ?? "")),
140
- }));
141
- }
142
-
143
- /** Per-category totals for the dialog header, counted over the whole reader. */
144
- export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
145
- const counts = { resident: 0, property_management: 0, service_provider: 0 } as Record<
146
- THidPermissionCategory,
147
- number
148
- >;
149
- for (const value of state.values()) counts[value.category] += 1;
150
- return counts;
151
- }
152
-
153
- /** Has anything changed since the dialog opened? Drives the Save button. */
154
- export function hasChanges(saved: HidAssignmentState, draft: HidAssignmentState): boolean {
155
- if (saved.size !== draft.size) return true;
156
- for (const [subjectId, value] of draft) {
157
- const before = saved.get(subjectId);
158
- if (!before) return true;
159
- if (before.category !== value.category) return true;
160
- if (before.intercom !== value.intercom) return true;
161
- }
162
- return false;
163
- }
164
-
165
- /**
166
- * What a listing response tells us: the rows, and how many pages exist.
167
- *
168
- * It deliberately does NOT return the current page, and the caller must keep
169
- * owning that. `paginate` in `@7365admin1/node-server-utils` returns only
170
- * `{ items, pages, pageRange }` — it never echoes the page it was asked for. A
171
- * caller that read one back therefore got a default on every fetch and pinned
172
- * itself to page one, so the pager moved and the rows never did.
173
- *
174
- * `items` sits at the root on some of these endpoints and under `data` on
175
- * others, so both are read.
176
- */
177
- export function readCandidatePage(response: unknown): {
178
- items: THidPermissionCandidate[];
179
- pages: number;
180
- pageRange: string;
181
- } {
182
- const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
183
- const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
184
- const items = Array.isArray(source.items)
185
- ? source.items
186
- : Array.isArray(nested.items)
187
- ? nested.items
188
- : [];
189
- const pages = Number(source.pages ?? nested.pages ?? 1);
190
- // `paginate` builds this ("1-10 of 37") and the table renders it verbatim.
191
- // Without it the pager draws its placeholder, "-- - -- of --".
192
- const pageRange = String(source.pageRange ?? nested.pageRange ?? "");
193
- return {
194
- items: items as THidPermissionCandidate[],
195
- pages: Number.isFinite(pages) && pages > 0 ? pages : 1,
196
- pageRange,
197
- };
198
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * WHICH HID READER THE OPERATOR IS WORKING ON — the one rule behind it.
3
- *
4
- * Every HID screen used to hold its own `ref("")` and default it to
5
- * `readers[0]`, so picking HID 2 on HID Reader Users and clicking through to
6
- * HID Cards put you back on HID 1. They are separate PAGES, so the component
7
- * unmounted and the ref was rebuilt from scratch every time — there was no way
8
- * to make a choice stick. "I am working on HID 2" is a mode, not a per-screen
9
- * preference.
10
- *
11
- * Navigation between those pages is a route change rather than a page load
12
- * (`NavigationItem.vue` renders the menu's `route` through `:to`), so the
13
- * module-scoped ref in `useHidReaderSelection` survives it. This file holds the
14
- * part worth testing: deciding whether a remembered choice may still be used.
15
- */
16
-
17
- export type HidReaderChoice = { siteId: string; readerId: string };
18
-
19
- /** Anything with an id — the four screens all carry a different reader shape. */
20
- type ReaderLike = { _id?: unknown };
21
-
22
- export const EMPTY_HID_READER_CHOICE: HidReaderChoice = { siteId: "", readerId: "" };
23
-
24
- /**
25
- * The reader a screen should show, given what this site actually has.
26
- *
27
- * A remembered id is honoured ONLY when it belongs to this site and is still in
28
- * the list. That single condition covers every way it goes stale:
29
- *
30
- * - the operator switched site, so the id belongs to a site they have left
31
- * - the reader was deleted or deactivated since they chose it
32
- * - nothing has been chosen yet
33
- *
34
- * In all three the first reader is returned instead. The alternative — using
35
- * the id anyway — sends requests for a reader the site does not own, which come
36
- * back empty and read on screen as a reader with no users, no cards and no
37
- * logs, rather than as the mistake it is.
38
- */
39
- export function resolveHidReaderId(
40
- siteId: string,
41
- readers: readonly ReaderLike[] | null | undefined,
42
- choice: HidReaderChoice = EMPTY_HID_READER_CHOICE,
43
- ): string {
44
- const ids = (Array.isArray(readers) ? readers : [])
45
- .map((reader) => String(reader?._id ?? ""))
46
- .filter(Boolean);
47
-
48
- if (choice.siteId === String(siteId ?? "") && ids.includes(choice.readerId)) {
49
- return choice.readerId;
50
- }
51
- return ids[0] ?? "";
52
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Invitations list, multi-site invitations (owner request 2026-10-02): the
3
- * server (`GET /api/verifications?group=true`) returns ONE entry per invitation
4
- * group with its `sites`; an old single-site invitation is a group of one.
5
- */
6
- export type InviteSiteRow = {
7
- _id: string;
8
- siteId?: string;
9
- siteName?: string;
10
- status?: string;
11
- };
12
-
13
- export type InviteEntry = {
14
- _id?: string;
15
- email?: string;
16
- metadata?: Record<string, any>;
17
- sites?: InviteSiteRow[];
18
- siteCount?: number;
19
- };
20
-
21
- export function siteCountOf(item: InviteEntry): number {
22
- return item.siteCount ?? item.sites?.length ?? 1;
23
- }
24
-
25
- /** "LakeGarden" for one site, "21 sites" for a group (details list them all). */
26
- export function siteLabel(item: InviteEntry): string {
27
- const n = siteCountOf(item);
28
- if (n > 1) return `${n} sites`;
29
- return item.sites?.[0]?.siteName || item.metadata?.siteName || "";
30
- }
31
-
32
- /** Every verification id the entry stands for (Cancel all). */
33
- export function groupIds(item: InviteEntry): string[] {
34
- const ids = item.sites?.length
35
- ? item.sites.map((s) => s._id)
36
- : [item._id ?? ""];
37
- return ids.filter(Boolean).map(String);
38
- }
39
-
40
- /**
41
- * Arguments of `inviteMemberClient` that re-send the invitation: ONE request,
42
- * so ONE e-mail for the whole group. `null` when it cannot be rebuilt (no org).
43
- */
44
- export function resendArgs(item: InviteEntry) {
45
- const m = item.metadata ?? {};
46
- if (!item.email || !m.org) return null;
47
- const sites = (item.sites ?? [])
48
- .map((s) => s.siteId)
49
- .filter(Boolean)
50
- .map(String);
51
- return {
52
- email: item.email,
53
- app: m.app ?? "",
54
- role: m.role ? String(m.role) : "",
55
- name: m.name ?? "",
56
- org: String(m.org),
57
- sites: sites.length > 1 ? sites : [],
58
- site: sites.length === 1 ? sites[0] : m.siteId ? String(m.siteId) : "",
59
- siteName: item.sites?.[0]?.siteName || m.siteName || "",
60
- };
61
- }