@7365admin1/layer-common 4.82.0 → 4.82.1-staging.469

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 (48) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/assets/css/primitives.css +57 -0
  3. package/assets/css/screens.css +8 -4
  4. package/components/AccessCardDetailsDialog.vue +57 -4
  5. package/components/AccessCardPreviewDialog.vue +291 -50
  6. package/components/AppSelect.vue +143 -4
  7. package/components/BuildingUnitFormEdit.vue +6 -0
  8. package/components/BuildingUnitManagement.vue +298 -0
  9. package/components/Dialog/UpdateMoreAction.vue +11 -1
  10. package/components/DocumentForm.vue +407 -112
  11. package/components/DocumentManagement.vue +213 -12
  12. package/components/Facility/BookingSetup.vue +63 -0
  13. package/components/HidAccessLogDashboard.vue +74 -17
  14. package/components/HidAccessPermissions.vue +424 -0
  15. package/components/HidIntercomManagement.vue +183 -14
  16. package/components/HidProfileQrCode.vue +332 -0
  17. package/components/HidQrCodeConfiguration.vue +17 -195
  18. package/components/HidReaderManagement.vue +398 -0
  19. package/components/HidReaderUserRoster.vue +44 -3
  20. package/components/HidUserEnrollment.vue +1521 -248
  21. package/components/InvitationClientForm.vue +19 -1
  22. package/components/TableMain.vue +22 -7
  23. package/components/VisitorForm.vue +12 -0
  24. package/components/VisitorManagement.vue +267 -5
  25. package/composables/useDocument.ts +7 -0
  26. package/composables/useFacility.ts +11 -0
  27. package/composables/useHidAmico.ts +165 -0
  28. package/composables/useHidNavigation.ts +25 -1
  29. package/composables/useHidReaderSelection.ts +50 -0
  30. package/composables/useMember.ts +12 -0
  31. package/composables/usePeople.ts +19 -0
  32. package/composables/useServiceProvider.ts +40 -2
  33. package/composables/useSiteCategory.ts +45 -0
  34. package/package.json +1 -1
  35. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  36. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  37. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  38. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  39. package/types/document.d.ts +14 -0
  40. package/types/facility.d.ts +4 -0
  41. package/types/member.d.ts +4 -0
  42. package/types/people.d.ts +28 -1
  43. package/types/service-provider.d.ts +5 -0
  44. package/utils/hid-enrolment-subject.ts +144 -0
  45. package/utils/hid-permission-assignments.ts +190 -0
  46. package/utils/hid-reader-selection.ts +52 -0
  47. package/utils/occupancy-role.ts +109 -0
  48. package/utils/service-type.ts +30 -0
@@ -46,9 +46,33 @@ export default function useHidNavigation() {
46
46
  },
47
47
  },
48
48
  {
49
+ // "HID Reader Users" now points at `access-mgmt/administrator`, not at
50
+ // `access-mgmt/hid-users`.
51
+ //
52
+ // Both routes mount a roster of the reader's users, but only this one
53
+ // can act on them. `administrator` renders HidUserEnrollment WITHOUT
54
+ // `card-management`, and that prop is what gates the Enroll action:
55
+ // <template v-if="!props.cardManagement" #actions>
56
+ // `hid-users` renders HidReaderUserRoster, which is read-only apart
57
+ // from PIN management. So the menu entry with this name used to lead
58
+ // to the screen that cannot enrol, while the screen that can was
59
+ // reachable only by typing the URL.
60
+ //
61
+ // `hid-users` is left in place and simply unlisted - the same state
62
+ // `administrator` was in - so any existing link to it still resolves.
49
63
  title: "HID Reader Users",
50
64
  route: {
51
- name: "org-site-access-mgmt-hid-users",
65
+ name: "org-site-access-mgmt-administrator",
66
+ params: { org, site },
67
+ },
68
+ },
69
+ {
70
+ // The signed-in member's own pass, not somebody else's. Every other
71
+ // entry in this group acts on a resident or a visitor; this one has
72
+ // no subject but the caller.
73
+ title: "HID QR Code",
74
+ route: {
75
+ name: "org-site-access-mgmt-hid-qr-code",
52
76
  params: { org, site },
53
77
  },
54
78
  },
@@ -0,0 +1,50 @@
1
+ import {
2
+ EMPTY_HID_READER_CHOICE,
3
+ resolveHidReaderId,
4
+ type HidReaderChoice,
5
+ } from "../utils/hid-reader-selection";
6
+
7
+ /**
8
+ * ONE HID READER CHOICE, SHARED BY EVERY HID SCREEN.
9
+ *
10
+ * Declared at MODULE scope on purpose. Each screen held its own `ref("")`, and
11
+ * because the HID screens are separate pages the ref was rebuilt on every
12
+ * navigation — HID Reader Users, HID Cards, Access Logs and HID QR Code each
13
+ * reset to the first reader no matter what had just been picked next door.
14
+ *
15
+ * A module-scoped ref is enough because moving between those pages is a ROUTE
16
+ * change, not a page load: the menu's items carry a `route` and
17
+ * `NavigationItem.vue` renders them through `:to`, so vue-router handles them
18
+ * and this module is never re-evaluated.
19
+ *
20
+ * Deliberately NOT persisted. `localStorage` would carry the choice through a
21
+ * hard refresh as well, which is a real but much smaller benefit than the
22
+ * navigation case, and it is worth adding only once somebody has felt the
23
+ * absence. See `utils/hid-reader-selection.ts` for the staleness rule that
24
+ * would have to hold either way.
25
+ *
26
+ * Intercom keeps its own reader and is not wired to this. Its question is which
27
+ * panel you are calling, not which door you are administering, and joining them
28
+ * would mean switching reader on Access Logs changed who you would dial.
29
+ */
30
+ const choice = ref<HidReaderChoice>({ ...EMPTY_HID_READER_CHOICE });
31
+
32
+ export default function useHidReaderSelection() {
33
+ /** Remember a choice. The site travels with it; an id alone means nothing. */
34
+ function selectHidReader(siteId: string, readerId: string) {
35
+ choice.value = { siteId: String(siteId ?? ""), readerId: String(readerId ?? "") };
36
+ }
37
+
38
+ /**
39
+ * The reader this screen should show, given the readers it just loaded.
40
+ *
41
+ * Call it after the reader list arrives, and write the answer back with
42
+ * `selectHidReader` so the screens agree on what "current" means even when
43
+ * one of them had to fall back to the first reader.
44
+ */
45
+ function resolveForSite(siteId: string, readers: readonly { _id?: unknown }[]) {
46
+ return resolveHidReaderId(siteId, readers, choice.value);
47
+ }
48
+
49
+ return { choice, selectHidReader, resolveForSite };
50
+ }
@@ -70,6 +70,8 @@ export default function useMember() {
70
70
  status = "active",
71
71
  siteId = "",
72
72
  roleState = "",
73
+ /** A building unit id, or "none": members on no unit yet. */
74
+ unit = "",
73
75
  people = false,
74
76
  } = {}) {
75
77
  const query: Record<string, any> = { page, limit, type, status };
@@ -83,6 +85,7 @@ export default function useMember() {
83
85
  if (user) query.user = user;
84
86
  if (org) query.org = org;
85
87
  if (siteId) query.siteId = siteId;
88
+ if (unit) query.unit = unit;
86
89
  return useNuxtApp().$api<Record<string, any>>("/api/members", {
87
90
  method: "GET",
88
91
  query,
@@ -158,6 +161,14 @@ export default function useMember() {
158
161
  });
159
162
  }
160
163
 
164
+ /** Attach a member to a building unit, or detach them (`unit` ""). */
165
+ function updateMemberUnit(id: string, unit: string) {
166
+ return useNuxtApp().$api<Record<string, any>>("/api/members/unit", {
167
+ method: "PUT",
168
+ body: { id, unit },
169
+ });
170
+ }
171
+
161
172
  function getByUserTypeOrg(user: string, type: string, org: string) {
162
173
  return useNuxtApp().$api<TMember>(
163
174
  `/api/members/user/${user}/app/${type}/org`,
@@ -226,6 +237,7 @@ export default function useMember() {
226
237
  undoCrossSiteRoleFix,
227
238
  getSiteAccess,
228
239
  saveSiteAccess,
240
+ updateMemberUnit,
229
241
  members,
230
242
  member,
231
243
  page,
@@ -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,
@@ -15,6 +15,16 @@ export type TSiteProviderMember = {
15
15
  lastLoginAt?: string | null;
16
16
  /** a subcontractor: the provider that brought its company onto the site */
17
17
  invitedVia?: string;
18
+ /** The building unit this person is attached to (a unit's Management tab). */
19
+ unit?: string | null;
20
+ unitName?: string;
21
+ /**
22
+ * The person's user account. NOT yet returned by the endpoint — the
23
+ * repository projects it but the service layer drops it. Anything acting on
24
+ * the PERSON (assigning an access card writes it onto the card as `userId`)
25
+ * needs this rather than `_id`, which identifies the membership.
26
+ */
27
+ user?: string | null;
18
28
  };
19
29
 
20
30
  export type TSiteProviderCompany = {
@@ -90,6 +100,8 @@ export default function useServiceProvider() {
90
100
  status = "",
91
101
  /** "engagements": also providers engaged through an accepted invitation. */
92
102
  include = "",
103
+ /** A building unit id, or "none": providers on no unit yet. */
104
+ unit = "",
93
105
  } = {}) {
94
106
  return useNuxtApp().$api<Record<string, any>>("/api/service-providers", {
95
107
  method: "GET",
@@ -102,6 +114,7 @@ export default function useServiceProvider() {
102
114
  siteId,
103
115
  ...(status ? { status } : {}),
104
116
  ...(include ? { include } : {}),
117
+ ...(unit ? { unit } : {}),
105
118
  },
106
119
  });
107
120
  }
@@ -269,6 +282,17 @@ export default function useServiceProvider() {
269
282
  );
270
283
  }
271
284
 
285
+ /** Attach a provider to a building unit, or detach it (`unit` ""). */
286
+ async function updateUnit(id: string, unit: string) {
287
+ return useNuxtApp().$api<Record<string, any>>(
288
+ `/api/service-providers/${id}/unit`,
289
+ {
290
+ method: "PATCH",
291
+ body: { unit },
292
+ }
293
+ );
294
+ }
295
+
272
296
  async function getByEmail({
273
297
  email = "",
274
298
  orgId = "",
@@ -293,17 +317,29 @@ export default function useServiceProvider() {
293
317
  * Members > Service Providers: the provider people with access to this
294
318
  * site, and one entry per provider company with its head count. The
295
319
  * site's own organisation only - the server refuses anyone else.
320
+ * `unit`: a building unit id, or "none" (people on no unit yet).
296
321
  */
297
- function getSiteMembers(siteId: string): Promise<{
322
+ function getSiteMembers(siteId: string, unit = ""): Promise<{
298
323
  items: TSiteProviderMember[];
299
324
  companies: TSiteProviderCompany[];
300
325
  }> {
301
326
  return useNuxtApp().$api("/api/service-providers/site-members", {
302
327
  method: "GET",
303
- query: { siteId },
328
+ query: { siteId, ...(unit ? { unit } : {}) },
304
329
  });
305
330
  }
306
331
 
332
+ /** Attach one of those people to a building unit, or detach them (`unit` ""). */
333
+ function updateSiteMemberUnit(id: string, unit: string) {
334
+ return useNuxtApp().$api<Record<string, any>>(
335
+ `/api/service-providers/site-members/${id}/unit`,
336
+ {
337
+ method: "PATCH",
338
+ body: { unit },
339
+ }
340
+ );
341
+ }
342
+
307
343
  /** The same list as an Excel file, under the same filters. */
308
344
  function exportSiteMembers(
309
345
  siteId: string,
@@ -320,6 +356,7 @@ export default function useServiceProvider() {
320
356
 
321
357
  return {
322
358
  getSiteMembers,
359
+ updateSiteMemberUnit,
323
360
  exportSiteMembers,
324
361
  serviceProviders,
325
362
  serviceProvider,
@@ -338,6 +375,7 @@ export default function useServiceProvider() {
338
375
  add,
339
376
  addViaInvite,
340
377
  updateStatus,
378
+ updateUnit,
341
379
  getByEmail,
342
380
  };
343
381
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * THE CATEGORY OF THE SITE THE USER IS CURRENTLY IN.
3
+ *
4
+ * One shared answer, published once by the application's layout from the site
5
+ * it already loaded for the switcher, and read by anything that has to behave
6
+ * differently on a commercial or industrial site - the business Add Tenant
7
+ * form, the tenant list. Publishing it rather than re-fetching it per
8
+ * component means no two screens can disagree about which site this is.
9
+ *
10
+ * READ FROM THE CUSTOMER-SITE RECORD, NOT THE SITE RECORD. Both carry a
11
+ * `category` and `customer-site.service` keeps them equal (it writes the site
12
+ * on create and on update), but `siteSchema` DEFAULTS the site's own copy to
13
+ * `commercial` - so a site created without an explicit category reads back as
14
+ * commercial there even when it is a residential estate. The customer-site
15
+ * copy has no default: it is either the category somebody chose or nothing.
16
+ *
17
+ * An empty category means "not published yet" or "never set", and every
18
+ * caller must behave as it did before this existed - never assume commercial
19
+ * from silence.
20
+ */
21
+ const BUSINESS_SITE_CATEGORIES: string[] = ["commercial", "industrial"];
22
+
23
+ export default function useSiteCategory() {
24
+ const siteCategory = useState<string>("current-site-category", () => "");
25
+
26
+ function setSiteCategory(value?: string | null) {
27
+ siteCategory.value = typeof value === "string" ? value : "";
28
+ }
29
+
30
+ /**
31
+ * The categories whose units are LET TO A BUSINESS rather than lived in.
32
+ *
33
+ * These are the sites where a unit has an owner, an occupier and often a
34
+ * person in charge who is neither, so they are the sites that ask for a
35
+ * tenant's standing and print it back (see `OCCUPANCY_ROLE_OPTIONS`).
36
+ *
37
+ * The category never changes what the APPLICATION is called: the rail says
38
+ * Property Management on every site it serves.
39
+ */
40
+ const isBusinessSite = computed(() =>
41
+ BUSINESS_SITE_CATEGORIES.includes(siteCategory.value),
42
+ );
43
+
44
+ return { siteCategory, isBusinessSite, setSiteCategory };
45
+ }
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.82.0",
5
+ "version": "4.82.1-staging.469",
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.",
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing HID users."
7
7
  >
8
- <HidUserEnrollment :site="siteId" />
8
+ <HidUserEnrollment :site="siteId" :org="orgId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing physical HID cards."
7
7
  >
8
- <HidUserEnrollment :site="siteId" card-management />
8
+ <HidUserEnrollment :site="siteId" :org="orgId" card-management />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -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>
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing HID readers."
7
7
  >
8
- <HidReaderManagement :site="siteId" />
8
+ <HidReaderManagement :site="siteId" :org="orgId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -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/member.d.ts CHANGED
@@ -10,6 +10,10 @@ declare type TMember = {
10
10
  customerOrgId?: string;
11
11
  customerSiteId?: string;
12
12
  status?: string;
13
+ email?: string;
14
+ /** The building unit this member manages (a unit's Management tab). */
15
+ unit?: string | null;
16
+ unitName?: string;
13
17
  createdAt?: string;
14
18
  updatedAt?: string;
15
19
  deletedAt?: string;
package/types/people.d.ts CHANGED
@@ -22,11 +22,38 @@ declare type TPeople = {
22
22
  email?: string;
23
23
  files?: { name: string, id: string }[];
24
24
  isOwner?: boolean;
25
+ /**
26
+ * Owner / occupant / person-in-charge, as the BUSINESS people form asks it.
27
+ * Absent on everyone else - `isOwner` is still the flag that decides unit
28
+ * ownership, and the server derives it from this when it is sent. See
29
+ * `OccupancyRoles` in core's `person.model.ts`.
30
+ */
31
+ occupancyRole?: TOccupancyRole;
32
+ // Link to this person's `users` row. Empty for the person types that carry
33
+ // no login, and empty for a resident whose account was never written.
34
+ user?: string;
35
+ };
36
+
37
+ declare type TOccupancyRole = "owner" | "occupant" | "person-in-charge";
38
+
39
+ /** One standing and everything the product says about it. See `utils/occupancy-role.ts`. */
40
+ declare type TOccupancyRoleOption = {
41
+ value: TOccupancyRole;
42
+ /** The label a stored role is printed with. */
43
+ title: string;
44
+ /** The row menu's wording. */
45
+ action: string;
46
+ /** The confirmation's heading and its sentence. */
47
+ prompt: string;
48
+ description: string;
25
49
  };
26
50
 
27
51
  declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
28
52
 
29
53
 
30
- declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string }
54
+ // `""` is the FORM's "nothing picked yet" - it is stripped from the payload
55
+ // before it is sent, because absence is what the server reads as "never
56
+ // asked". See `PeopleFormMgmt.vue`.
57
+ 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; occupancyRole?: TOccupancyRole | "" }
31
58
 
32
59
  declare type TPeopleType = "guest" | "resident" | "tenant"
@@ -7,6 +7,11 @@ declare type TServiceProvider = {
7
7
  serviceProviderOrgId: string;
8
8
  type: string;
9
9
  nature: string;
10
+ status?: string;
11
+ email?: string;
12
+ /** The building unit this provider serves (a unit's Management tab). */
13
+ unit?: string | null;
14
+ unitName?: string;
10
15
  };
11
16
 
12
17
  declare type TServiceProviderName = {
@@ -0,0 +1,144 @@
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
+ export type HidEnrolmentSubject = "resident" | "property_management";
12
+
13
+ /**
14
+ * The dropdown's options, in the order they are drawn.
15
+ *
16
+ * `title`/`value` because `AppSelect` takes that shape. A service-provider
17
+ * option is expected next; adding it here is most of the work, since the write
18
+ * path already maps `service_provider` onto `serviceProvider`.
19
+ */
20
+ export const HID_ENROLMENT_SUBJECTS: ReadonlyArray<{
21
+ title: string;
22
+ value: HidEnrolmentSubject;
23
+ }> = [
24
+ { title: "Resident", value: "resident" },
25
+ { title: "Member", value: "property_management" },
26
+ ];
27
+
28
+ /**
29
+ * What an EDIT calls the subject it is already attached to.
30
+ *
31
+ * Wider than the dropdown on purpose. An identity's category cannot change after
32
+ * it is created, so an edit states it rather than offering it — and the records
33
+ * in the wild include `service_provider`, which the dropdown does not offer yet
34
+ * but `openEdit` does resolve. Falling back to the first option would label a
35
+ * contractor "Resident", which is worse than saying nothing useful.
36
+ */
37
+ export function subjectCategoryLabel(category: unknown): string {
38
+ const labels: Record<string, string> = {
39
+ resident: "Resident",
40
+ property_management: "Member",
41
+ service_provider: "Service provider",
42
+ visitor: "Visitor",
43
+ };
44
+ return labels[String(category ?? "")] ?? "Unknown";
45
+ }
46
+
47
+ /**
48
+ * One page of `GET /api/members`, read defensively.
49
+ *
50
+ * `paginate` puts `{ items, pages }` at the root, but `items` sits under `data`
51
+ * on some of this product's endpoints, so both are read — the same allowance
52
+ * `readCandidatePage` makes. A response that carries neither is an empty page
53
+ * rather than a thrown error: an empty staff picker with a placeholder beats a
54
+ * broken dialog.
55
+ */
56
+ export function readMemberPage(response: unknown): {
57
+ items: Record<string, unknown>[];
58
+ pages: number;
59
+ total: number;
60
+ } {
61
+ const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
62
+ const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
63
+ const raw = Array.isArray(source.items)
64
+ ? source.items
65
+ : Array.isArray(nested.items)
66
+ ? nested.items
67
+ : [];
68
+ const pages = Number(source.pages ?? nested.pages ?? 1);
69
+ const items = raw.filter((row): row is Record<string, unknown> => Boolean(row) && typeof row === "object");
70
+ /*
71
+ * `total` drives "showing 10 of 23" and the Load more button. It falls back to
72
+ * the page's own length, not to zero, so a response without it simply reads as
73
+ * "this is everything" — a missing count must never make the button offer a
74
+ * page that is not there.
75
+ */
76
+ const total = Number(source.total ?? nested.total ?? items.length);
77
+ return {
78
+ items,
79
+ pages: Number.isFinite(pages) && pages > 0 ? Math.floor(pages) : 1,
80
+ total: Number.isFinite(total) && total >= 0 ? Math.floor(total) : items.length,
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Can this member actually be enrolled?
86
+ *
87
+ * Reader access is bound by USER id — `resolvePermissionUserBindings` in
88
+ * `iservice365-core` drops every subject without one — so a member with no app
89
+ * account cannot be given access and is not a candidate. The id arrives as a
90
+ * string from JSON but may be an object if a caller passes a raw document, so
91
+ * both are read rather than trusting the shape.
92
+ */
93
+ export function memberHasAccount(row: Record<string, unknown> | null | undefined): boolean {
94
+ const user = row?.user;
95
+ if (!user) return false;
96
+ if (typeof user === "object") {
97
+ const id = (user as { _id?: unknown; toString?: () => string })._id ?? user;
98
+ return Boolean(String(id ?? "").trim());
99
+ }
100
+ return Boolean(String(user).trim());
101
+ }
102
+
103
+ /**
104
+ * How a member reads in the picker: their name, and their role beneath it.
105
+ *
106
+ * THE ACCOUNT'S NAME FIRST, then the membership's. The two diverge — a
107
+ * membership is created with whatever name was typed at invite time, and the
108
+ * person may have set their own on the account since — and the account name is
109
+ * the one they are known by. `userName` comes from the members endpoint's own
110
+ * lookup into `users`; a member with no account has none, but such a row is not
111
+ * a candidate anyway (`memberHasAccount`).
112
+ *
113
+ * Every step falls back, because a row with no name at all still has to be
114
+ * selectable rather than blank, or it cannot be told apart from the next one.
115
+ */
116
+ export function memberCandidateOf(row: Record<string, unknown>): {
117
+ subjectId: string;
118
+ name: string;
119
+ subtitle: string;
120
+ } {
121
+ const text = (value: unknown) => String(value ?? "").trim();
122
+ return {
123
+ subjectId: text(row._id),
124
+ name: text(row.userName) || text(row.name) || text(row.email) || "Member",
125
+ subtitle: text(row.roleName) || text(row.email) || "",
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Why somebody the operator can see elsewhere is not in this list.
131
+ *
132
+ * Left unexplained, an absence reads as a broken screen — the same reason the
133
+ * resident cascade carries `unitResidentNote`. Returns "" when there is nothing
134
+ * to say, so the caller can render it unconditionally.
135
+ */
136
+ export function hiddenSubjectNote(count: number, noun: "resident" | "member"): string {
137
+ if (!Number.isFinite(count) || count <= 0) return "";
138
+ const whole = Math.floor(count);
139
+ const subject = whole === 1 ? `1 ${noun}` : `${whole} ${noun}s`;
140
+ const verb = whole === 1 ? "is" : "are";
141
+ const holder = whole === 1 ? "that person has" : "they have";
142
+ return `${subject} at this site ${verb} not listed:`
143
+ + ` HID enrollment needs an app account, and ${holder} none yet.`;
144
+ }